aboutsummaryrefslogtreecommitdiffstats
path: root/1.2-netsec
diff options
context:
space:
mode:
Diffstat (limited to '1.2-netsec')
-rw-r--r--1.2-netsec/.cleancount1
-rw-r--r--1.2-netsec/BUGS22
-rw-r--r--1.2-netsec/CHANGES127
-rw-r--r--1.2-netsec/COPYING341
-rw-r--r--1.2-netsec/CREDITS133
-rw-r--r--1.2-netsec/HARDWARE70
-rw-r--r--1.2-netsec/LICENSE56
-rw-r--r--1.2-netsec/Makefile908
-rw-r--r--1.2-netsec/README248
-rw-r--r--1.2-netsec/README.fpm8
-rw-r--r--1.2-netsec/SECURITY67
-rw-r--r--1.2-netsec/UPGRADE.txt205
-rw-r--r--1.2-netsec/acl.c355
-rw-r--r--1.2-netsec/aescrypt.c313
-rw-r--r--1.2-netsec/aeskey.c465
-rw-r--r--1.2-netsec/aesopt.h1029
-rw-r--r--1.2-netsec/aestab.c232
-rw-r--r--1.2-netsec/agi/DialAnMp3.agi82
-rw-r--r--1.2-netsec/agi/Makefile52
-rw-r--r--1.2-netsec/agi/agi-test.agi79
-rw-r--r--1.2-netsec/agi/eagi-sphinx-test.c219
-rw-r--r--1.2-netsec/agi/eagi-test.c162
-rw-r--r--1.2-netsec/agi/fastagi-test94
-rw-r--r--1.2-netsec/agi/numeralize44
-rw-r--r--1.2-netsec/alaw.c100
-rw-r--r--1.2-netsec/app.c1558
-rw-r--r--1.2-netsec/apps/Makefile133
-rw-r--r--1.2-netsec/apps/app_adsiprog.c1606
-rw-r--r--1.2-netsec/apps/app_alarmreceiver.c867
-rw-r--r--1.2-netsec/apps/app_authenticate.c232
-rw-r--r--1.2-netsec/apps/app_cdr.c97
-rw-r--r--1.2-netsec/apps/app_chanisavail.c185
-rw-r--r--1.2-netsec/apps/app_chanspy.c587
-rw-r--r--1.2-netsec/apps/app_controlplayback.c190
-rw-r--r--1.2-netsec/apps/app_curl.c256
-rw-r--r--1.2-netsec/apps/app_cut.c473
-rw-r--r--1.2-netsec/apps/app_datetime.c101
-rw-r--r--1.2-netsec/apps/app_db.c323
-rw-r--r--1.2-netsec/apps/app_dial.c1747
-rw-r--r--1.2-netsec/apps/app_dictate.c358
-rw-r--r--1.2-netsec/apps/app_directed_pickup.c169
-rw-r--r--1.2-netsec/apps/app_directory.c516
-rw-r--r--1.2-netsec/apps/app_disa.c412
-rw-r--r--1.2-netsec/apps/app_dumpchan.c192
-rw-r--r--1.2-netsec/apps/app_echo.c123
-rw-r--r--1.2-netsec/apps/app_enumlookup.c270
-rw-r--r--1.2-netsec/apps/app_eval.c127
-rw-r--r--1.2-netsec/apps/app_exec.c135
-rw-r--r--1.2-netsec/apps/app_externalivr.c583
-rw-r--r--1.2-netsec/apps/app_festival.c532
-rw-r--r--1.2-netsec/apps/app_flash.c141
-rw-r--r--1.2-netsec/apps/app_forkcdr.c131
-rw-r--r--1.2-netsec/apps/app_getcpeid.c167
-rw-r--r--1.2-netsec/apps/app_groupcount.c340
-rw-r--r--1.2-netsec/apps/app_hasnewvoicemail.c264
-rw-r--r--1.2-netsec/apps/app_ices.c225
-rw-r--r--1.2-netsec/apps/app_image.c147
-rw-r--r--1.2-netsec/apps/app_intercom.c234
-rw-r--r--1.2-netsec/apps/app_ivrdemo.c144
-rw-r--r--1.2-netsec/apps/app_lookupblacklist.c141
-rw-r--r--1.2-netsec/apps/app_lookupcidname.c120
-rw-r--r--1.2-netsec/apps/app_macro.c396
-rw-r--r--1.2-netsec/apps/app_math.c297
-rw-r--r--1.2-netsec/apps/app_md5.c205
-rw-r--r--1.2-netsec/apps/app_meetme.c2247
-rw-r--r--1.2-netsec/apps/app_milliwatt.c170
-rw-r--r--1.2-netsec/apps/app_mixmonitor.c466
-rw-r--r--1.2-netsec/apps/app_mp3.c260
-rw-r--r--1.2-netsec/apps/app_nbscat.c241
-rw-r--r--1.2-netsec/apps/app_osplookup.c375
-rw-r--r--1.2-netsec/apps/app_page.c234
-rw-r--r--1.2-netsec/apps/app_parkandannounce.c281
-rw-r--r--1.2-netsec/apps/app_playback.c180
-rw-r--r--1.2-netsec/apps/app_privacy.c254
-rw-r--r--1.2-netsec/apps/app_queue.c3872
-rw-r--r--1.2-netsec/apps/app_random.c127
-rw-r--r--1.2-netsec/apps/app_read.c235
-rw-r--r--1.2-netsec/apps/app_readfile.c143
-rw-r--r--1.2-netsec/apps/app_realtime.c262
-rw-r--r--1.2-netsec/apps/app_record.c377
-rw-r--r--1.2-netsec/apps/app_rpt.c6560
-rw-r--r--1.2-netsec/apps/app_sayunixtime.c163
-rw-r--r--1.2-netsec/apps/app_senddtmf.c129
-rw-r--r--1.2-netsec/apps/app_sendtext.c156
-rw-r--r--1.2-netsec/apps/app_setcallerid.c178
-rw-r--r--1.2-netsec/apps/app_setcdruserfield.c179
-rw-r--r--1.2-netsec/apps/app_setcidname.c132
-rw-r--r--1.2-netsec/apps/app_setcidnum.c131
-rw-r--r--1.2-netsec/apps/app_setrdnis.c132
-rw-r--r--1.2-netsec/apps/app_settransfercapability.c145
-rw-r--r--1.2-netsec/apps/app_skel.c149
-rw-r--r--1.2-netsec/apps/app_sms.c1555
-rw-r--r--1.2-netsec/apps/app_softhangup.c139
-rw-r--r--1.2-netsec/apps/app_sql_postgres.c577
-rw-r--r--1.2-netsec/apps/app_stack.c193
-rw-r--r--1.2-netsec/apps/app_system.c176
-rw-r--r--1.2-netsec/apps/app_talkdetect.c250
-rw-r--r--1.2-netsec/apps/app_test.c529
-rw-r--r--1.2-netsec/apps/app_transfer.c182
-rw-r--r--1.2-netsec/apps/app_txtcidname.c164
-rw-r--r--1.2-netsec/apps/app_url.c196
-rw-r--r--1.2-netsec/apps/app_userevent.c137
-rw-r--r--1.2-netsec/apps/app_verbose.c135
-rw-r--r--1.2-netsec/apps/app_voicemail.c6732
-rw-r--r--1.2-netsec/apps/app_waitforring.c154
-rw-r--r--1.2-netsec/apps/app_waitforsilence.c210
-rw-r--r--1.2-netsec/apps/app_while.c369
-rw-r--r--1.2-netsec/apps/app_zapateller.c138
-rw-r--r--1.2-netsec/apps/app_zapbarge.c335
-rw-r--r--1.2-netsec/apps/app_zapras.c276
-rw-r--r--1.2-netsec/apps/app_zapscan.c399
-rw-r--r--1.2-netsec/apps/enter.h287
-rw-r--r--1.2-netsec/apps/leave.h207
-rw-r--r--1.2-netsec/apps/rpt_flow.pdfbin51935 -> 0 bytes
-rw-r--r--1.2-netsec/ast_expr2.c2419
-rw-r--r--1.2-netsec/ast_expr2.fl189
-rw-r--r--1.2-netsec/ast_expr2.h109
-rw-r--r--1.2-netsec/ast_expr2.y993
-rw-r--r--1.2-netsec/ast_expr2f.c2988
-rw-r--r--1.2-netsec/asterisk.8184
-rw-r--r--1.2-netsec/asterisk.c2450
-rw-r--r--1.2-netsec/asterisk.sgml353
-rw-r--r--1.2-netsec/astmm.c422
-rw-r--r--1.2-netsec/autoservice.c168
-rwxr-xr-x1.2-netsec/build_tools/make_build_h24
-rwxr-xr-x1.2-netsec/build_tools/make_defaults_h25
-rwxr-xr-x1.2-netsec/build_tools/make_svn_branch_name50
-rwxr-xr-x1.2-netsec/build_tools/make_version_h10
-rwxr-xr-x1.2-netsec/build_tools/mkdep123
-rw-r--r--1.2-netsec/buildinfo.c32
-rw-r--r--1.2-netsec/callerid.c788
-rw-r--r--1.2-netsec/cdr.c1267
-rw-r--r--1.2-netsec/cdr/Makefile140
-rw-r--r--1.2-netsec/cdr/cdr_csv.c292
-rw-r--r--1.2-netsec/cdr/cdr_custom.c178
-rw-r--r--1.2-netsec/cdr/cdr_manager.c178
-rw-r--r--1.2-netsec/cdr/cdr_odbc.c483
-rw-r--r--1.2-netsec/cdr/cdr_pgsql.c354
-rw-r--r--1.2-netsec/cdr/cdr_sqlite.c233
-rw-r--r--1.2-netsec/cdr/cdr_tds.c522
-rw-r--r--1.2-netsec/channel.c4059
-rw-r--r--1.2-netsec/channels/DialTone.h252
-rw-r--r--1.2-netsec/channels/Makefile262
-rw-r--r--1.2-netsec/channels/adtranvofr.h105
-rw-r--r--1.2-netsec/channels/answer.h237
-rw-r--r--1.2-netsec/channels/chan_agent.c2507
-rw-r--r--1.2-netsec/channels/chan_alsa.c1140
-rw-r--r--1.2-netsec/channels/chan_features.c606
-rw-r--r--1.2-netsec/channels/chan_h323.c2471
-rw-r--r--1.2-netsec/channels/chan_iax2.c9659
-rw-r--r--1.2-netsec/channels/chan_local.c661
-rw-r--r--1.2-netsec/channels/chan_mgcp.c4409
-rw-r--r--1.2-netsec/channels/chan_misdn.c3816
-rw-r--r--1.2-netsec/channels/chan_misdn_config.c1083
-rw-r--r--1.2-netsec/channels/chan_modem.c1117
-rw-r--r--1.2-netsec/channels/chan_modem_aopen.c501
-rw-r--r--1.2-netsec/channels/chan_modem_bestdata.c613
-rw-r--r--1.2-netsec/channels/chan_modem_i4l.c743
-rw-r--r--1.2-netsec/channels/chan_nbs.c325
-rw-r--r--1.2-netsec/channels/chan_oss.c1438
-rw-r--r--1.2-netsec/channels/chan_oss_old.c1132
-rw-r--r--1.2-netsec/channels/chan_phone.c1414
-rw-r--r--1.2-netsec/channels/chan_sip.c13481
-rw-r--r--1.2-netsec/channels/chan_skinny.c3381
-rw-r--r--1.2-netsec/channels/chan_vpb.c3051
-rw-r--r--1.2-netsec/channels/chan_zap.c11089
-rw-r--r--1.2-netsec/channels/gentone-ulaw.c157
-rw-r--r--1.2-netsec/channels/gentone.c95
-rw-r--r--1.2-netsec/channels/h323/ChangeLog43
-rw-r--r--1.2-netsec/channels/h323/INSTALL.openh32318
-rw-r--r--1.2-netsec/channels/h323/Makefile41
-rw-r--r--1.2-netsec/channels/h323/README142
-rw-r--r--1.2-netsec/channels/h323/TODO14
-rw-r--r--1.2-netsec/channels/h323/ast_h323.cpp1532
-rw-r--r--1.2-netsec/channels/h323/ast_h323.h239
-rw-r--r--1.2-netsec/channels/h323/chan_h323.h232
-rw-r--r--1.2-netsec/channels/h323/h323.conf.sample123
-rw-r--r--1.2-netsec/channels/iax2-parser.c951
-rw-r--r--1.2-netsec/channels/iax2-parser.h155
-rw-r--r--1.2-netsec/channels/iax2-provision.c537
-rw-r--r--1.2-netsec/channels/iax2-provision.h53
-rw-r--r--1.2-netsec/channels/iax2.h231
-rw-r--r--1.2-netsec/channels/misdn/Makefile72
-rw-r--r--1.2-netsec/channels/misdn/chan_misdn_config.h98
-rw-r--r--1.2-netsec/channels/misdn/ie.c1621
-rw-r--r--1.2-netsec/channels/misdn/isdn_lib.c3308
-rw-r--r--1.2-netsec/channels/misdn/isdn_lib.h367
-rw-r--r--1.2-netsec/channels/misdn/isdn_lib_intern.h99
-rw-r--r--1.2-netsec/channels/misdn/isdn_msg_parser.c1356
-rw-r--r--1.2-netsec/channels/misdn/mISDN.patch2500
-rw-r--r--1.2-netsec/channels/misdn/mISDNuser.patch271
-rw-r--r--1.2-netsec/channels/misdn/portinfo.c197
-rw-r--r--1.2-netsec/channels/ring10.h1752
-rw-r--r--1.2-netsec/chanvars.c91
-rw-r--r--1.2-netsec/cli.c1386
-rw-r--r--1.2-netsec/codecs/Makefile134
-rw-r--r--1.2-netsec/codecs/adpcm_slin_ex.h25
-rw-r--r--1.2-netsec/codecs/codec_a_mu.c343
-rw-r--r--1.2-netsec/codecs/codec_adpcm.c655
-rw-r--r--1.2-netsec/codecs/codec_alaw.c428
-rw-r--r--1.2-netsec/codecs/codec_g723_1.c418
-rw-r--r--1.2-netsec/codecs/codec_g726.c1092
-rw-r--r--1.2-netsec/codecs/codec_gsm.c352
-rw-r--r--1.2-netsec/codecs/codec_ilbc.c318
-rw-r--r--1.2-netsec/codecs/codec_lpc10.c431
-rw-r--r--1.2-netsec/codecs/codec_speex.c613
-rw-r--r--1.2-netsec/codecs/codec_ulaw.c445
-rw-r--r--1.2-netsec/codecs/g723_slin_ex.h15
-rw-r--r--1.2-netsec/codecs/g726_slin_ex.h25
-rw-r--r--1.2-netsec/codecs/gsm/COPYRIGHT16
-rw-r--r--1.2-netsec/codecs/gsm/Makefile583
-rw-r--r--1.2-netsec/codecs/gsm/README37
-rw-r--r--1.2-netsec/codecs/gsm/inc/config.h51
-rw-r--r--1.2-netsec/codecs/gsm/inc/gsm.h71
-rw-r--r--1.2-netsec/codecs/gsm/inc/private.h313
-rw-r--r--1.2-netsec/codecs/gsm/inc/proto.h65
-rw-r--r--1.2-netsec/codecs/gsm/inc/unproto.h23
-rw-r--r--1.2-netsec/codecs/gsm/src/add.c235
-rw-r--r--1.2-netsec/codecs/gsm/src/code.c101
-rw-r--r--1.2-netsec/codecs/gsm/src/debug.c76
-rw-r--r--1.2-netsec/codecs/gsm/src/decode.c62
-rw-r--r--1.2-netsec/codecs/gsm/src/gsm_create.c45
-rw-r--r--1.2-netsec/codecs/gsm/src/gsm_decode.c361
-rw-r--r--1.2-netsec/codecs/gsm/src/gsm_destroy.c26
-rw-r--r--1.2-netsec/codecs/gsm/src/gsm_encode.c451
-rw-r--r--1.2-netsec/codecs/gsm/src/gsm_explode.c417
-rw-r--r--1.2-netsec/codecs/gsm/src/gsm_implode.c515
-rw-r--r--1.2-netsec/codecs/gsm/src/gsm_option.c69
-rw-r--r--1.2-netsec/codecs/gsm/src/gsm_print.c167
-rw-r--r--1.2-netsec/codecs/gsm/src/k6opt.h84
-rw-r--r--1.2-netsec/codecs/gsm/src/k6opt.s739
-rw-r--r--1.2-netsec/codecs/gsm/src/long_term.c952
-rw-r--r--1.2-netsec/codecs/gsm/src/lpc.c369
-rw-r--r--1.2-netsec/codecs/gsm/src/preprocess.c131
-rw-r--r--1.2-netsec/codecs/gsm/src/rpe.c490
-rw-r--r--1.2-netsec/codecs/gsm/src/short_term.c448
-rw-r--r--1.2-netsec/codecs/gsm/src/table.c63
-rw-r--r--1.2-netsec/codecs/gsm_slin_ex.h16
-rw-r--r--1.2-netsec/codecs/ilbc/FrameClassify.c110
-rw-r--r--1.2-netsec/codecs/ilbc/FrameClassify.h26
-rw-r--r--1.2-netsec/codecs/ilbc/LPCdecode.c152
-rw-r--r--1.2-netsec/codecs/ilbc/LPCdecode.h44
-rw-r--r--1.2-netsec/codecs/ilbc/LPCencode.c228
-rw-r--r--1.2-netsec/codecs/ilbc/LPCencode.h29
-rw-r--r--1.2-netsec/codecs/ilbc/Makefile25
-rw-r--r--1.2-netsec/codecs/ilbc/StateConstructW.c76
-rw-r--r--1.2-netsec/codecs/ilbc/StateConstructW.h27
-rw-r--r--1.2-netsec/codecs/ilbc/StateSearchW.c194
-rw-r--r--1.2-netsec/codecs/ilbc/StateSearchW.h48
-rw-r--r--1.2-netsec/codecs/ilbc/anaFilter.c71
-rw-r--r--1.2-netsec/codecs/ilbc/anaFilter.h26
-rw-r--r--1.2-netsec/codecs/ilbc/constants.c729
-rw-r--r--1.2-netsec/codecs/ilbc/constants.h74
-rw-r--r--1.2-netsec/codecs/ilbc/createCB.c216
-rw-r--r--1.2-netsec/codecs/ilbc/createCB.h56
-rw-r--r--1.2-netsec/codecs/ilbc/doCPLC.c259
-rw-r--r--1.2-netsec/codecs/ilbc/doCPLC.h32
-rw-r--r--1.2-netsec/codecs/ilbc/enhancer.c665
-rw-r--r--1.2-netsec/codecs/ilbc/enhancer.h33
-rw-r--r--1.2-netsec/codecs/ilbc/filter.c168
-rw-r--r--1.2-netsec/codecs/ilbc/filter.h73
-rw-r--r--1.2-netsec/codecs/ilbc/gainquant.c107
-rw-r--r--1.2-netsec/codecs/ilbc/gainquant.h31
-rw-r--r--1.2-netsec/codecs/ilbc/getCBvec.c181
-rw-r--r--1.2-netsec/codecs/ilbc/getCBvec.h28
-rw-r--r--1.2-netsec/codecs/ilbc/helpfun.c308
-rw-r--r--1.2-netsec/codecs/ilbc/helpfun.h101
-rw-r--r--1.2-netsec/codecs/ilbc/hpInput.c60
-rw-r--r--1.2-netsec/codecs/ilbc/hpInput.h27
-rw-r--r--1.2-netsec/codecs/ilbc/hpOutput.c59
-rw-r--r--1.2-netsec/codecs/ilbc/hpOutput.h25
-rw-r--r--1.2-netsec/codecs/ilbc/iCBConstruct.c108
-rw-r--r--1.2-netsec/codecs/ilbc/iCBConstruct.h38
-rw-r--r--1.2-netsec/codecs/ilbc/iCBSearch.c480
-rw-r--r--1.2-netsec/codecs/ilbc/iCBSearch.h35
-rw-r--r--1.2-netsec/codecs/ilbc/iLBC_decode.c619
-rw-r--r--1.2-netsec/codecs/ilbc/iLBC_decode.h40
-rw-r--r--1.2-netsec/codecs/ilbc/iLBC_define.h201
-rw-r--r--1.2-netsec/codecs/ilbc/iLBC_encode.c514
-rw-r--r--1.2-netsec/codecs/ilbc/iLBC_encode.h37
-rw-r--r--1.2-netsec/codecs/ilbc/lsf.c264
-rw-r--r--1.2-netsec/codecs/ilbc/lsf.h30
-rw-r--r--1.2-netsec/codecs/ilbc/packing.c175
-rw-r--r--1.2-netsec/codecs/ilbc/packing.h67
-rw-r--r--1.2-netsec/codecs/ilbc/syntFilter.c108
-rw-r--r--1.2-netsec/codecs/ilbc/syntFilter.h27
-rw-r--r--1.2-netsec/codecs/ilbc_slin_ex.h17
-rw-r--r--1.2-netsec/codecs/log2comp.h74
-rw-r--r--1.2-netsec/codecs/lpc10/Makefile75
-rw-r--r--1.2-netsec/codecs/lpc10/README89
-rw-r--r--1.2-netsec/codecs/lpc10/analys.c649
-rw-r--r--1.2-netsec/codecs/lpc10/bsynz.c447
-rw-r--r--1.2-netsec/codecs/lpc10/chanwr.c232
-rw-r--r--1.2-netsec/codecs/lpc10/dcbias.c107
-rw-r--r--1.2-netsec/codecs/lpc10/decode.c625
-rw-r--r--1.2-netsec/codecs/lpc10/deemp.c154
-rw-r--r--1.2-netsec/codecs/lpc10/difmag.c133
-rw-r--r--1.2-netsec/codecs/lpc10/dyptrk.c405
-rw-r--r--1.2-netsec/codecs/lpc10/encode.c373
-rw-r--r--1.2-netsec/codecs/lpc10/energy.c103
-rw-r--r--1.2-netsec/codecs/lpc10/f2c.h325
-rw-r--r--1.2-netsec/codecs/lpc10/f2clib.c85
-rw-r--r--1.2-netsec/codecs/lpc10/ham84.c126
-rw-r--r--1.2-netsec/codecs/lpc10/hp100.c169
-rw-r--r--1.2-netsec/codecs/lpc10/invert.c193
-rw-r--r--1.2-netsec/codecs/lpc10/irc2pc.c151
-rw-r--r--1.2-netsec/codecs/lpc10/ivfilt.c136
-rw-r--r--1.2-netsec/codecs/lpc10/lpc10.h248
-rw-r--r--1.2-netsec/codecs/lpc10/lpcdec.c297
-rw-r--r--1.2-netsec/codecs/lpc10/lpcenc.c181
-rw-r--r--1.2-netsec/codecs/lpc10/lpcini.c446
-rw-r--r--1.2-netsec/codecs/lpc10/lpfilt.c125
-rw-r--r--1.2-netsec/codecs/lpc10/median.c89
-rw-r--r--1.2-netsec/codecs/lpc10/mload.c163
-rw-r--r--1.2-netsec/codecs/lpc10/onset.c324
-rw-r--r--1.2-netsec/codecs/lpc10/pitsyn.c583
-rw-r--r--1.2-netsec/codecs/lpc10/placea.c242
-rw-r--r--1.2-netsec/codecs/lpc10/placev.c275
-rw-r--r--1.2-netsec/codecs/lpc10/preemp.c144
-rw-r--r--1.2-netsec/codecs/lpc10/prepro.c116
-rw-r--r--1.2-netsec/codecs/lpc10/random.c125
-rw-r--r--1.2-netsec/codecs/lpc10/rcchk.c119
-rw-r--r--1.2-netsec/codecs/lpc10/synths.c425
-rw-r--r--1.2-netsec/codecs/lpc10/tbdm.c188
-rw-r--r--1.2-netsec/codecs/lpc10/voicin.c786
-rw-r--r--1.2-netsec/codecs/lpc10/vparms.c255
-rw-r--r--1.2-netsec/codecs/lpc10_slin_ex.h13
-rw-r--r--1.2-netsec/codecs/slin_adpcm_ex.h25
-rw-r--r--1.2-netsec/codecs/slin_g723_ex.h36
-rw-r--r--1.2-netsec/codecs/slin_g726_ex.h25
-rw-r--r--1.2-netsec/codecs/slin_gsm_ex.h28
-rw-r--r--1.2-netsec/codecs/slin_ilbc_ex.h28
-rw-r--r--1.2-netsec/codecs/slin_lpc10_ex.h21
-rw-r--r--1.2-netsec/codecs/slin_speex_ex.h262
-rw-r--r--1.2-netsec/codecs/slin_ulaw_ex.h25
-rw-r--r--1.2-netsec/codecs/speex_slin_ex.h16
-rw-r--r--1.2-netsec/codecs/ulaw_slin_ex.h25
-rw-r--r--1.2-netsec/coef_in.h13
-rw-r--r--1.2-netsec/coef_out.h4
-rw-r--r--1.2-netsec/config.c1080
-rw-r--r--1.2-netsec/configs/adsi.conf.sample8
-rw-r--r--1.2-netsec/configs/adtranvofr.conf.sample39
-rw-r--r--1.2-netsec/configs/agents.conf.sample80
-rw-r--r--1.2-netsec/configs/alarmreceiver.conf.sample80
-rw-r--r--1.2-netsec/configs/alsa.conf.sample31
-rw-r--r--1.2-netsec/configs/asterisk.adsi159
-rw-r--r--1.2-netsec/configs/cdr.conf.sample51
-rw-r--r--1.2-netsec/configs/cdr_custom.conf.sample6
-rw-r--r--1.2-netsec/configs/cdr_manager.conf.sample6
-rw-r--r--1.2-netsec/configs/cdr_odbc.conf.sample12
-rw-r--r--1.2-netsec/configs/cdr_pgsql.conf.sample9
-rw-r--r--1.2-netsec/configs/cdr_tds.conf.sample9
-rw-r--r--1.2-netsec/configs/codecs.conf.sample65
-rw-r--r--1.2-netsec/configs/dnsmgr.conf.sample5
-rw-r--r--1.2-netsec/configs/dundi.conf.sample239
-rw-r--r--1.2-netsec/configs/enum.conf.sample22
-rw-r--r--1.2-netsec/configs/extconfig.conf.sample51
-rw-r--r--1.2-netsec/configs/extensions.ael.sample62
-rw-r--r--1.2-netsec/configs/extensions.conf.sample492
-rw-r--r--1.2-netsec/configs/features.conf.sample32
-rw-r--r--1.2-netsec/configs/festival.conf.sample35
-rw-r--r--1.2-netsec/configs/iax.conf.sample418
-rw-r--r--1.2-netsec/configs/iaxprov.conf.sample83
-rw-r--r--1.2-netsec/configs/indications.conf.sample611
-rw-r--r--1.2-netsec/configs/logger.conf.sample69
-rw-r--r--1.2-netsec/configs/manager.conf.sample37
-rw-r--r--1.2-netsec/configs/meetme.conf.sample21
-rw-r--r--1.2-netsec/configs/mgcp.conf.sample75
-rw-r--r--1.2-netsec/configs/misdn.conf.sample267
-rw-r--r--1.2-netsec/configs/modem.conf.sample92
-rw-r--r--1.2-netsec/configs/modules.conf.sample53
-rw-r--r--1.2-netsec/configs/musiconhold.conf.sample64
-rw-r--r--1.2-netsec/configs/osp.conf.sample64
-rw-r--r--1.2-netsec/configs/oss.conf.sample39
-rw-r--r--1.2-netsec/configs/phone.conf.sample47
-rw-r--r--1.2-netsec/configs/privacy.conf.sample3
-rw-r--r--1.2-netsec/configs/queues.conf.sample200
-rw-r--r--1.2-netsec/configs/res_odbc.conf.sample31
-rw-r--r--1.2-netsec/configs/rpt.conf.sample180
-rw-r--r--1.2-netsec/configs/rtp.conf.sample20
-rw-r--r--1.2-netsec/configs/sip.conf.sample441
-rw-r--r--1.2-netsec/configs/sip_notify.conf.sample22
-rw-r--r--1.2-netsec/configs/skinny.conf.sample55
-rw-r--r--1.2-netsec/configs/telcordia-1.adsi83
-rw-r--r--1.2-netsec/configs/voicemail.conf.sample213
-rw-r--r--1.2-netsec/configs/vpb.conf.sample108
-rw-r--r--1.2-netsec/configs/zapata.conf.sample569
-rw-r--r--1.2-netsec/contrib/README.festival47
-rw-r--r--1.2-netsec/contrib/asterisk-doxygen-header10
-rw-r--r--1.2-netsec/contrib/asterisk-ices.xml93
-rw-r--r--1.2-netsec/contrib/asterisk-ng-doxygen1228
-rw-r--r--1.2-netsec/contrib/festival-1.4.1-diff76
-rw-r--r--1.2-netsec/contrib/festival-1.4.2.diff75
-rw-r--r--1.2-netsec/contrib/festival-1.4.3.diff93
-rw-r--r--1.2-netsec/contrib/festival-1.95.diff107
-rw-r--r--1.2-netsec/contrib/firmware/iax/iaxy.binbin39402 -> 0 bytes
-rw-r--r--1.2-netsec/contrib/i18n.testsuite.conf136
-rwxr-xr-x1.2-netsec/contrib/init.d/rc.debian.asterisk85
-rwxr-xr-x1.2-netsec/contrib/init.d/rc.gentoo.asterisk17
-rwxr-xr-x1.2-netsec/contrib/init.d/rc.mandrake.asterisk183
-rwxr-xr-x1.2-netsec/contrib/init.d/rc.mandrake.zaptel98
-rwxr-xr-x1.2-netsec/contrib/init.d/rc.redhat.asterisk118
-rwxr-xr-x1.2-netsec/contrib/init.d/rc.slackware.asterisk42
-rw-r--r--1.2-netsec/contrib/scripts/README.messages-expire20
-rw-r--r--1.2-netsec/contrib/scripts/agents.php73
-rw-r--r--1.2-netsec/contrib/scripts/ast_grab_core64
-rw-r--r--1.2-netsec/contrib/scripts/astgenkey61
-rw-r--r--1.2-netsec/contrib/scripts/astgenkey.8129
-rw-r--r--1.2-netsec/contrib/scripts/astxs157
-rw-r--r--1.2-netsec/contrib/scripts/autosupport155
-rw-r--r--1.2-netsec/contrib/scripts/autosupport.841
-rw-r--r--1.2-netsec/contrib/scripts/iax-friends.sql15
-rw-r--r--1.2-netsec/contrib/scripts/loadtest.tcl148
-rw-r--r--1.2-netsec/contrib/scripts/lookup.agi90
-rw-r--r--1.2-netsec/contrib/scripts/managerproxy.pl242
-rw-r--r--1.2-netsec/contrib/scripts/messages-expire.pl96
-rw-r--r--1.2-netsec/contrib/scripts/postgres_cdr.sql33
-rw-r--r--1.2-netsec/contrib/scripts/qview.pl100
-rw-r--r--1.2-netsec/contrib/scripts/retrieve_extensions_from_mysql.pl113
-rw-r--r--1.2-netsec/contrib/scripts/retrieve_extensions_from_sql.pl158
-rw-r--r--1.2-netsec/contrib/scripts/retrieve_sip_conf_from_mysql.pl93
-rw-r--r--1.2-netsec/contrib/scripts/safe_asterisk85
-rw-r--r--1.2-netsec/contrib/scripts/safe_asterisk.862
-rw-r--r--1.2-netsec/contrib/scripts/sip-friends.sql14
-rw-r--r--1.2-netsec/contrib/scripts/vmail.cgi1099
-rw-r--r--1.2-netsec/contrib/scripts/vmdb.sql11
-rw-r--r--1.2-netsec/contrib/thirdparty/spexxilbcfix_xlite.regbin452 -> 0 bytes
-rw-r--r--1.2-netsec/contrib/thirdparty/spexxilbcfix_xpro.regbin450 -> 0 bytes
-rw-r--r--1.2-netsec/contrib/utils/README.rawplayer37
-rw-r--r--1.2-netsec/contrib/utils/rawplayer.c38
-rw-r--r--1.2-netsec/contrib/valgrind-RedHat-8.0.supp41
-rw-r--r--1.2-netsec/cryptostub.c84
-rw-r--r--1.2-netsec/cygwin/Makefile6
-rw-r--r--1.2-netsec/cygwin/cygloader.c33
-rw-r--r--1.2-netsec/db.c597
-rw-r--r--1.2-netsec/db1-ast/Makefile77
-rw-r--r--1.2-netsec/db1-ast/btree/bt_close.c182
-rw-r--r--1.2-netsec/db1-ast/btree/bt_conv.c221
-rw-r--r--1.2-netsec/db1-ast/btree/bt_debug.c329
-rw-r--r--1.2-netsec/db1-ast/btree/bt_delete.c657
-rw-r--r--1.2-netsec/db1-ast/btree/bt_get.c105
-rw-r--r--1.2-netsec/db1-ast/btree/bt_open.c458
-rw-r--r--1.2-netsec/db1-ast/btree/bt_overflow.c228
-rw-r--r--1.2-netsec/db1-ast/btree/bt_page.c100
-rw-r--r--1.2-netsec/db1-ast/btree/bt_put.c321
-rw-r--r--1.2-netsec/db1-ast/btree/bt_search.c213
-rw-r--r--1.2-netsec/db1-ast/btree/bt_seq.c460
-rw-r--r--1.2-netsec/db1-ast/btree/bt_split.c829
-rw-r--r--1.2-netsec/db1-ast/btree/bt_utils.c260
-rw-r--r--1.2-netsec/db1-ast/btree/btree.h391
-rw-r--r--1.2-netsec/db1-ast/btree/extern.h70
-rw-r--r--1.2-netsec/db1-ast/db/db.c113
-rw-r--r--1.2-netsec/db1-ast/hash/README72
-rw-r--r--1.2-netsec/db1-ast/hash/extern.h65
-rw-r--r--1.2-netsec/db1-ast/hash/hash.c1001
-rw-r--r--1.2-netsec/db1-ast/hash/hash.h293
-rw-r--r--1.2-netsec/db1-ast/hash/hash_bigkey.c668
-rw-r--r--1.2-netsec/db1-ast/hash/hash_buf.c355
-rw-r--r--1.2-netsec/db1-ast/hash/hash_func.c225
-rw-r--r--1.2-netsec/db1-ast/hash/hash_log2.c56
-rw-r--r--1.2-netsec/db1-ast/hash/hash_page.c944
-rw-r--r--1.2-netsec/db1-ast/hash/hsearch.c107
-rw-r--r--1.2-netsec/db1-ast/hash/ndbm.c235
-rw-r--r--1.2-netsec/db1-ast/hash/page.h92
-rw-r--r--1.2-netsec/db1-ast/hash/search.h51
-rw-r--r--1.2-netsec/db1-ast/include/circ-queue.h131
-rw-r--r--1.2-netsec/db1-ast/include/compat.h49
-rw-r--r--1.2-netsec/db1-ast/include/db.h250
-rw-r--r--1.2-netsec/db1-ast/include/mpool.h115
-rw-r--r--1.2-netsec/db1-ast/include/ndbm.h79
-rw-r--r--1.2-netsec/db1-ast/libdb.map11
-rw-r--r--1.2-netsec/db1-ast/mpool/README7
-rw-r--r--1.2-netsec/db1-ast/mpool/mpool.c498
-rw-r--r--1.2-netsec/db1-ast/recno/extern.h54
-rw-r--r--1.2-netsec/db1-ast/recno/rec_close.c183
-rw-r--r--1.2-netsec/db1-ast/recno/rec_delete.c197
-rw-r--r--1.2-netsec/db1-ast/recno/rec_get.c311
-rw-r--r--1.2-netsec/db1-ast/recno/rec_open.c241
-rw-r--r--1.2-netsec/db1-ast/recno/rec_put.c280
-rw-r--r--1.2-netsec/db1-ast/recno/rec_search.c126
-rw-r--r--1.2-netsec/db1-ast/recno/rec_seq.c131
-rw-r--r--1.2-netsec/db1-ast/recno/rec_utils.c122
-rw-r--r--1.2-netsec/db1-ast/recno/recno.h39
-rw-r--r--1.2-netsec/devicestate.c281
-rw-r--r--1.2-netsec/dlfcn.c1314
-rw-r--r--1.2-netsec/dns.c228
-rw-r--r--1.2-netsec/dnsmgr.c371
-rw-r--r--1.2-netsec/doc/CODING-GUIDELINES510
-rw-r--r--1.2-netsec/doc/PEERING499
-rw-r--r--1.2-netsec/doc/README.ael273
-rw-r--r--1.2-netsec/doc/README.asterisk.conf76
-rw-r--r--1.2-netsec/doc/README.backtrace187
-rw-r--r--1.2-netsec/doc/README.cdr122
-rw-r--r--1.2-netsec/doc/README.cliprompt28
-rw-r--r--1.2-netsec/doc/README.configuration180
-rw-r--r--1.2-netsec/doc/README.cygwin7
-rw-r--r--1.2-netsec/doc/README.dundi26
-rw-r--r--1.2-netsec/doc/README.enum306
-rw-r--r--1.2-netsec/doc/README.extconfig85
-rw-r--r--1.2-netsec/doc/README.externalivr109
-rw-r--r--1.2-netsec/doc/README.h32323
-rw-r--r--1.2-netsec/doc/README.iax369
-rw-r--r--1.2-netsec/doc/README.ices12
-rw-r--r--1.2-netsec/doc/README.jitterbuffer137
-rw-r--r--1.2-netsec/doc/README.math69
-rw-r--r--1.2-netsec/doc/README.misdn342
-rw-r--r--1.2-netsec/doc/README.mp319
-rw-r--r--1.2-netsec/doc/README.mysql15
-rw-r--r--1.2-netsec/doc/README.odbcstorage33
-rw-r--r--1.2-netsec/doc/README.privacy361
-rw-r--r--1.2-netsec/doc/README.realtime111
-rw-r--r--1.2-netsec/doc/README.sms147
-rw-r--r--1.2-netsec/doc/README.tds18
-rw-r--r--1.2-netsec/doc/README.variables792
-rw-r--r--1.2-netsec/doc/app_sms.html834
-rw-r--r--1.2-netsec/doc/apps.txt10
-rw-r--r--1.2-netsec/doc/cdr.txt171
-rw-r--r--1.2-netsec/doc/channel.txt40
-rw-r--r--1.2-netsec/doc/extensions.txt58
-rw-r--r--1.2-netsec/doc/iax.txt55
-rw-r--r--1.2-netsec/doc/linkedlists.README98
-rw-r--r--1.2-netsec/doc/localchannel.txt49
-rw-r--r--1.2-netsec/doc/manager.txt297
-rw-r--r--1.2-netsec/doc/model.txt15
-rw-r--r--1.2-netsec/doc/modules.txt26
-rw-r--r--1.2-netsec/doc/queuelog.txt77
-rw-r--r--1.2-netsec/dsp.c1724
-rw-r--r--1.2-netsec/ecdisa.h15
-rw-r--r--1.2-netsec/editline/CHANGES42
-rw-r--r--1.2-netsec/editline/INSTALL64
-rw-r--r--1.2-netsec/editline/Makefile.in233
-rw-r--r--1.2-netsec/editline/PLATFORMS13
-rw-r--r--1.2-netsec/editline/README11
-rw-r--r--1.2-netsec/editline/TEST/test.c268
-rw-r--r--1.2-netsec/editline/chared.c695
-rw-r--r--1.2-netsec/editline/chared.h159
-rw-r--r--1.2-netsec/editline/common.c951
-rwxr-xr-x1.2-netsec/editline/config.guess1449
-rw-r--r--1.2-netsec/editline/config.h.in21
-rwxr-xr-x1.2-netsec/editline/config.sub1412
-rwxr-xr-x1.2-netsec/editline/configure2423
-rw-r--r--1.2-netsec/editline/configure.in276
-rw-r--r--1.2-netsec/editline/editline.3646
-rw-r--r--1.2-netsec/editline/editrc.5491
-rw-r--r--1.2-netsec/editline/el.c509
-rw-r--r--1.2-netsec/editline/el.h145
-rw-r--r--1.2-netsec/editline/emacs.c488
-rw-r--r--1.2-netsec/editline/hist.c197
-rw-r--r--1.2-netsec/editline/hist.h80
-rw-r--r--1.2-netsec/editline/histedit.h197
-rw-r--r--1.2-netsec/editline/history.c875
-rwxr-xr-x1.2-netsec/editline/install-sh250
-rw-r--r--1.2-netsec/editline/key.c687
-rw-r--r--1.2-netsec/editline/key.h79
-rw-r--r--1.2-netsec/editline/makelist254
-rw-r--r--1.2-netsec/editline/map.c1418
-rw-r--r--1.2-netsec/editline/map.h79
-rw-r--r--1.2-netsec/editline/np/fgetln.c88
-rw-r--r--1.2-netsec/editline/np/strlcat.c75
-rw-r--r--1.2-netsec/editline/np/strlcpy.c75
-rw-r--r--1.2-netsec/editline/np/unvis.c322
-rw-r--r--1.2-netsec/editline/np/vis.c347
-rw-r--r--1.2-netsec/editline/np/vis.h96
-rw-r--r--1.2-netsec/editline/parse.c259
-rw-r--r--1.2-netsec/editline/parse.h52
-rw-r--r--1.2-netsec/editline/prompt.c174
-rw-r--r--1.2-netsec/editline/prompt.h62
-rw-r--r--1.2-netsec/editline/read.c555
-rw-r--r--1.2-netsec/editline/read.h55
-rw-r--r--1.2-netsec/editline/readline.c1664
-rw-r--r--1.2-netsec/editline/readline/readline.h118
-rw-r--r--1.2-netsec/editline/refresh.c1104
-rw-r--r--1.2-netsec/editline/refresh.h63
-rw-r--r--1.2-netsec/editline/search.c649
-rw-r--r--1.2-netsec/editline/search.h70
-rw-r--r--1.2-netsec/editline/sig.c198
-rw-r--r--1.2-netsec/editline/sig.h72
-rw-r--r--1.2-netsec/editline/sys.h133
-rw-r--r--1.2-netsec/editline/term.c1581
-rw-r--r--1.2-netsec/editline/term.h124
-rw-r--r--1.2-netsec/editline/tokenizer.c397
-rw-r--r--1.2-netsec/editline/tokenizer.h54
-rw-r--r--1.2-netsec/editline/tty.c1182
-rw-r--r--1.2-netsec/editline/tty.h484
-rw-r--r--1.2-netsec/editline/vi.c941
-rw-r--r--1.2-netsec/enum.c666
-rw-r--r--1.2-netsec/file.c1287
-rw-r--r--1.2-netsec/formats/Makefile68
-rw-r--r--1.2-netsec/formats/format_au.c394
-rw-r--r--1.2-netsec/formats/format_g723.c278
-rw-r--r--1.2-netsec/formats/format_g726.c516
-rw-r--r--1.2-netsec/formats/format_g729.c260
-rw-r--r--1.2-netsec/formats/format_gsm.c280
-rw-r--r--1.2-netsec/formats/format_h263.c281
-rw-r--r--1.2-netsec/formats/format_ilbc.c259
-rw-r--r--1.2-netsec/formats/format_jpeg.c144
-rw-r--r--1.2-netsec/formats/format_ogg_vorbis.c677
-rw-r--r--1.2-netsec/formats/format_pcm.c276
-rw-r--r--1.2-netsec/formats/format_pcm_alaw.c352
-rw-r--r--1.2-netsec/formats/format_sln.c247
-rw-r--r--1.2-netsec/formats/format_vox.c253
-rw-r--r--1.2-netsec/formats/format_wav.c605
-rw-r--r--1.2-netsec/formats/format_wav_gsm.c589
-rw-r--r--1.2-netsec/formats/msgsm.h687
-rw-r--r--1.2-netsec/frame.c1301
-rw-r--r--1.2-netsec/fskmodem.c302
-rw-r--r--1.2-netsec/funcs/Makefile82
-rw-r--r--1.2-netsec/funcs/func_callerid.c153
-rw-r--r--1.2-netsec/funcs/func_cdr.c108
-rw-r--r--1.2-netsec/funcs/func_db.c169
-rw-r--r--1.2-netsec/funcs/func_enum.c243
-rw-r--r--1.2-netsec/funcs/func_env.c71
-rw-r--r--1.2-netsec/funcs/func_groupcount.c192
-rw-r--r--1.2-netsec/funcs/func_language.c75
-rw-r--r--1.2-netsec/funcs/func_logic.c201
-rw-r--r--1.2-netsec/funcs/func_math.c251
-rw-r--r--1.2-netsec/funcs/func_md5.c103
-rw-r--r--1.2-netsec/funcs/func_moh.c56
-rw-r--r--1.2-netsec/funcs/func_strings.c229
-rw-r--r--1.2-netsec/funcs/func_timeout.c177
-rw-r--r--1.2-netsec/funcs/func_uri.c121
-rw-r--r--1.2-netsec/funcs/pbx_functions.c74
-rw-r--r--1.2-netsec/image.c219
-rw-r--r--1.2-netsec/images/animlogo.gifbin63968 -> 0 bytes
-rw-r--r--1.2-netsec/images/asterisk-intro.jpgbin6143 -> 0 bytes
-rw-r--r--1.2-netsec/images/play.gifbin341 -> 0 bytes
-rw-r--r--1.2-netsec/include/asterisk.h127
-rw-r--r--1.2-netsec/include/asterisk/acl.h56
-rw-r--r--1.2-netsec/include/asterisk/adsi.h353
-rw-r--r--1.2-netsec/include/asterisk/aes.h170
-rw-r--r--1.2-netsec/include/asterisk/agi.h56
-rw-r--r--1.2-netsec/include/asterisk/alaw.h43
-rw-r--r--1.2-netsec/include/asterisk/app.h351
-rw-r--r--1.2-netsec/include/asterisk/ast_expr.h32
-rw-r--r--1.2-netsec/include/asterisk/astdb.h52
-rw-r--r--1.2-netsec/include/asterisk/astmm.h79
-rw-r--r--1.2-netsec/include/asterisk/astobj.h752
-rw-r--r--1.2-netsec/include/asterisk/astosp.h48
-rw-r--r--1.2-netsec/include/asterisk/callerid.h306
-rw-r--r--1.2-netsec/include/asterisk/causes.h82
-rw-r--r--1.2-netsec/include/asterisk/cdr.h297
-rw-r--r--1.2-netsec/include/asterisk/channel.h1207
-rw-r--r--1.2-netsec/include/asterisk/chanspy.h140
-rw-r--r--1.2-netsec/include/asterisk/chanvars.h42
-rw-r--r--1.2-netsec/include/asterisk/cli.h111
-rw-r--r--1.2-netsec/include/asterisk/compat.h97
-rw-r--r--1.2-netsec/include/asterisk/compiler.h33
-rw-r--r--1.2-netsec/include/asterisk/config.h194
-rw-r--r--1.2-netsec/include/asterisk/crypto.h112
-rw-r--r--1.2-netsec/include/asterisk/devicestate.h104
-rw-r--r--1.2-netsec/include/asterisk/dlfcn-compat.h88
-rw-r--r--1.2-netsec/include/asterisk/dns.h39
-rw-r--r--1.2-netsec/include/asterisk/dnsmgr.h44
-rw-r--r--1.2-netsec/include/asterisk/doxyref.h449
-rw-r--r--1.2-netsec/include/asterisk/dsp.h111
-rw-r--r--1.2-netsec/include/asterisk/dundi.h226
-rw-r--r--1.2-netsec/include/asterisk/endian.h65
-rw-r--r--1.2-netsec/include/asterisk/enum.h57
-rw-r--r--1.2-netsec/include/asterisk/features.h95
-rw-r--r--1.2-netsec/include/asterisk/file.h318
-rw-r--r--1.2-netsec/include/asterisk/frame.h484
-rw-r--r--1.2-netsec/include/asterisk/fskmodem.h72
-rw-r--r--1.2-netsec/include/asterisk/image.h96
-rw-r--r--1.2-netsec/include/asterisk/indications.h87
-rw-r--r--1.2-netsec/include/asterisk/inline_api.h66
-rw-r--r--1.2-netsec/include/asterisk/io.h145
-rw-r--r--1.2-netsec/include/asterisk/linkedlists.h443
-rw-r--r--1.2-netsec/include/asterisk/localtime.h34
-rw-r--r--1.2-netsec/include/asterisk/lock.h660
-rw-r--r--1.2-netsec/include/asterisk/logger.h126
-rw-r--r--1.2-netsec/include/asterisk/manager.h172
-rw-r--r--1.2-netsec/include/asterisk/md5.h40
-rw-r--r--1.2-netsec/include/asterisk/module.h419
-rw-r--r--1.2-netsec/include/asterisk/monitor.h56
-rw-r--r--1.2-netsec/include/asterisk/musiconhold.h47
-rw-r--r--1.2-netsec/include/asterisk/netsock.h68
-rw-r--r--1.2-netsec/include/asterisk/options.h66
-rw-r--r--1.2-netsec/include/asterisk/pbx.h665
-rw-r--r--1.2-netsec/include/asterisk/plc.h161
-rw-r--r--1.2-netsec/include/asterisk/poll-compat.h111
-rw-r--r--1.2-netsec/include/asterisk/privacy.h46
-rw-r--r--1.2-netsec/include/asterisk/res_odbc.h62
-rw-r--r--1.2-netsec/include/asterisk/rtp.h172
-rw-r--r--1.2-netsec/include/asterisk/say.h102
-rw-r--r--1.2-netsec/include/asterisk/sched.h160
-rw-r--r--1.2-netsec/include/asterisk/slinfactory.h56
-rw-r--r--1.2-netsec/include/asterisk/srv.h47
-rw-r--r--1.2-netsec/include/asterisk/strings.h251
-rw-r--r--1.2-netsec/include/asterisk/tdd.h82
-rw-r--r--1.2-netsec/include/asterisk/term.h74
-rw-r--r--1.2-netsec/include/asterisk/time.h143
-rw-r--r--1.2-netsec/include/asterisk/transcap.h42
-rw-r--r--1.2-netsec/include/asterisk/translate.h120
-rw-r--r--1.2-netsec/include/asterisk/ulaw.h43
-rw-r--r--1.2-netsec/include/asterisk/unaligned.h102
-rw-r--r--1.2-netsec/include/asterisk/utils.h238
-rw-r--r--1.2-netsec/include/asterisk/vmodem.h184
-rw-r--r--1.2-netsec/include/solaris-compat/compat.h46
-rw-r--r--1.2-netsec/include/solaris-compat/sys/cdefs.h10
-rw-r--r--1.2-netsec/include/solaris-compat/sys/queue.h540
-rw-r--r--1.2-netsec/indications.c611
-rw-r--r--1.2-netsec/io.c376
-rw-r--r--1.2-netsec/jitterbuf.c829
-rw-r--r--1.2-netsec/jitterbuf.h160
-rw-r--r--1.2-netsec/keys/freeworlddialup.pub6
-rw-r--r--1.2-netsec/keys/iaxtel.pub6
-rw-r--r--1.2-netsec/loader.c646
-rw-r--r--1.2-netsec/logger.c968
-rw-r--r--1.2-netsec/manager.c1764
-rw-r--r--1.2-netsec/md5.c266
-rwxr-xr-x1.2-netsec/mkpkgconfig43
-rw-r--r--1.2-netsec/muted.c682
-rw-r--r--1.2-netsec/muted.conf.sample26
-rw-r--r--1.2-netsec/netsock.c221
-rw-r--r--1.2-netsec/pbx.c6487
-rw-r--r--1.2-netsec/pbx/Makefile80
-rw-r--r--1.2-netsec/pbx/dundi-parser.c832
-rw-r--r--1.2-netsec/pbx/dundi-parser.h88
-rw-r--r--1.2-netsec/pbx/pbx_ael.c1284
-rw-r--r--1.2-netsec/pbx/pbx_config.c1831
-rw-r--r--1.2-netsec/pbx/pbx_dundi.c4831
-rw-r--r--1.2-netsec/pbx/pbx_gtkconsole.c518
-rw-r--r--1.2-netsec/pbx/pbx_kdeconsole.cc61
-rw-r--r--1.2-netsec/pbx/pbx_kdeconsole.h37
-rw-r--r--1.2-netsec/pbx/pbx_kdeconsole_main.cc81
-rw-r--r--1.2-netsec/pbx/pbx_loopback.c207
-rw-r--r--1.2-netsec/pbx/pbx_realtime.c274
-rw-r--r--1.2-netsec/pbx/pbx_spool.c445
-rw-r--r--1.2-netsec/plc.c250
-rw-r--r--1.2-netsec/poll.c306
-rw-r--r--1.2-netsec/privacy.c118
-rw-r--r--1.2-netsec/redhat/asterisk.spec127
-rw-r--r--1.2-netsec/redhat/rpmmacros3
-rw-r--r--1.2-netsec/redhat/rpmrc3
-rw-r--r--1.2-netsec/res/Makefile122
-rw-r--r--1.2-netsec/res/res_adsi.c1141
-rw-r--r--1.2-netsec/res/res_agi.c2142
-rw-r--r--1.2-netsec/res/res_config_odbc.c540
-rw-r--r--1.2-netsec/res/res_crypto.c622
-rw-r--r--1.2-netsec/res/res_features.c2187
-rw-r--r--1.2-netsec/res/res_indications.c435
-rw-r--r--1.2-netsec/res/res_monitor.c592
-rw-r--r--1.2-netsec/res/res_musiconhold.c1237
-rw-r--r--1.2-netsec/res/res_odbc.c618
-rw-r--r--1.2-netsec/res/res_osp.c886
-rw-r--r--1.2-netsec/rtp.c1896
-rw-r--r--1.2-netsec/sample.call55
-rw-r--r--1.2-netsec/say.c6116
-rw-r--r--1.2-netsec/sched.c416
-rw-r--r--1.2-netsec/slinfactory.c161
-rw-r--r--1.2-netsec/sounds.txt729
-rw-r--r--1.2-netsec/sounds/agent-alreadyon.gsmbin9405 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/agent-incorrect.gsmbin7689 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/agent-loggedoff.gsmbin2640 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/agent-loginok.gsmbin2046 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/agent-newlocation.gsmbin5544 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/agent-pass.gsmbin4884 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/agent-user.gsmbin7392 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/auth-incorrect.gsmbin7524 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/auth-thankyou.gsmbin1947 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/beep.gsmbin726 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/beeperr.gsmbin594 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-adminmenu.gsmbin29634 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-enteringno.gsmbin3630 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-errormenu.gsmbin2376 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-getchannel.gsmbin5709 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-getconfno.gsmbin5511 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-getpin.gsmbin3696 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-hasjoin.gsmbin3102 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-hasleft.gsmbin2640 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-invalid.gsmbin5973 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-invalidpin.gsmbin4752 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-kicked.gsmbin3861 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-leaderhasleft.gsmbin3267 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-locked.gsmbin2805 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-lockednow.gsmbin3597 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-muted.gsmbin2178 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-noempty.gsmbin4422 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-onlyone.gsmbin5511 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-onlyperson.gsmbin5412 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-otherinparty.gsmbin3432 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-placeintoconf.gsmbin3927 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-thereare.gsmbin1947 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-unlockednow.gsmbin4290 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-unmuted.gsmbin2607 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-usermenu.gsmbin20592 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-userswilljoin.gsmbin3201 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-userwilljoin.gsmbin3135 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/conf-waitforleader.gsmbin4488 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-abouttotry.gsmbin23364 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-congrats.gsmbin45573 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-echodone.gsmbin4059 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-echotest.gsmbin31812 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-enterkeywords.gsmbin9603 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-instruct.gsmbin110913 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-moreinfo.gsmbin18810 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-nogo.gsmbin16104 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-nomatch.gsmbin6336 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/demo-thanks.gsmbin7920 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/both_help.gsmbin8415 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/enter_filename.gsmbin9339 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/forhelp.gsmbin2475 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/pause.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/paused.gsmbin1287 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/play_help.gsmbin14388 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/playback.gsmbin1386 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/playback_mode.gsmbin1848 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/record.gsmbin1386 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/record_help.gsmbin8646 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/record_mode.gsmbin1650 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dictate/truncating_audio.gsmbin2508 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/0.gsmbin1452 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/1.gsmbin957 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/10.gsmbin1023 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/11.gsmbin1617 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/12.gsmbin1683 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/13.gsmbin1782 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/14.gsmbin1881 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/15.gsmbin2013 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/16.gsmbin2178 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/17.gsmbin2244 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/18.gsmbin2046 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/19.gsmbin2244 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/2.gsmbin990 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/20.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/3.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/30.gsmbin957 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/4.gsmbin924 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/40.gsmbin990 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/5.gsmbin1023 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/50.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/6.gsmbin891 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/60.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/7.gsmbin1089 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/70.gsmbin1353 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/8.gsmbin792 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/80.gsmbin1089 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/9.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/90.gsmbin1353 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/a-m.gsmbin1848 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/at.gsmbin858 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/day-0.gsmbin1452 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/day-1.gsmbin1980 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/day-2.gsmbin1617 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/day-3.gsmbin2013 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/day-4.gsmbin1848 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/day-5.gsmbin1716 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/day-6.gsmbin1683 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/dollars.gsmbin1353 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-1.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-10.gsmbin990 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-11.gsmbin1287 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-12.gsmbin1056 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-13.gsmbin1650 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-14.gsmbin1584 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-15.gsmbin1485 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-16.gsmbin1551 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-17.gsmbin1749 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-18.gsmbin1386 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-19.gsmbin1617 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-2.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-20.gsmbin1287 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-3.gsmbin957 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-30.gsmbin1650 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-4.gsmbin1221 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-5.gsmbin1023 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-6.gsmbin1188 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-7.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-8.gsmbin1023 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/h-9.gsmbin1089 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/hundred.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/million.gsmbin1320 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/minus.gsmbin1518 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-0.gsmbin1914 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-1.gsmbin2046 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-10.gsmbin1815 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-11.gsmbin2013 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-2.gsmbin1584 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-3.gsmbin1386 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-4.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-5.gsmbin1683 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-6.gsmbin1551 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-7.gsmbin1353 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-8.gsmbin1617 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/mon-9.gsmbin1848 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/oclock.gsmbin1452 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/oh.gsmbin1188 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/p-m.gsmbin1485 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/pound.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/star.gsmbin1353 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/thousand.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/today.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/tomorrow.gsmbin1287 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/digits/yesterday.gsmbin1320 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dir-instr.gsmbin10164 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dir-intro-fn.gsmbin17424 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dir-intro.gsmbin17556 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dir-nomatch.gsmbin3960 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/dir-nomore.gsmbin4950 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/fpm-calm-river.mp3bin1939812 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/fpm-sunshine.mp3bin2582496 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/fpm-world-mix.mp3bin2217563 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/hello-world.gsmbin2838 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/hours.gsmbin1221 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/invalid.gsmbin7128 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/a.gsmbin825 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/at.gsmbin858 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/b.gsmbin990 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/c.gsmbin1023 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/d.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/dash.gsmbin1221 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/dollar.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/dot.gsmbin990 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/e.gsmbin990 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/equals.gsmbin1386 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/exclaimation-point.gsmbin2442 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/f.gsmbin957 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/g.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/h.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/i.gsmbin990 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/j.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/k.gsmbin1056 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/l.gsmbin924 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/m.gsmbin825 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/n.gsmbin792 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/o.gsmbin891 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/p.gsmbin891 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/plus.gsmbin957 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/q.gsmbin957 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/r.gsmbin924 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/s.gsmbin825 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/slash.gsmbin1353 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/space.gsmbin1320 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/t.gsmbin792 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/u.gsmbin1023 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/v.gsmbin1089 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/w.gsmbin1419 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/x.gsmbin924 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/y.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/z.gsmbin1023 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/letters/zed.gsmbin1056 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/minutes.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/pbx-invalid.gsmbin6864 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/pbx-invalidpark.gsmbin8184 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/pbx-transfer.gsmbin1551 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/9_p.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/a_p.gsmbin1089 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/b_p.gsmbin1188 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/c_p.gsmbin1089 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/d_p.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/e_p.gsmbin1056 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/f_p.gsmbin1320 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/g_p.gsmbin990 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/h_p.gsmbin1287 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/i_p.gsmbin1089 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/j_p.gsmbin1353 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/k_p.gsmbin1056 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/l_p.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/m_p.gsmbin858 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/n_p.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/o_p.gsm2
-rw-r--r--1.2-netsec/sounds/phonetic/p_p.gsmbin924 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/q_p.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/r_p.gsmbin1188 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/s_p.gsmbin1221 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/t_p.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/u_p.gsmbin1452 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/v_p.gsmbin1122 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/w_p.gsmbin1089 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/x_p.gsmbin1089 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/y_p.gsmbin1188 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/phonetic/z_p.gsmbin1188 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/priv-callee-options.gsmbin45375 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/priv-callpending.gsmbin7326 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/priv-introsaved.gsmbin6501 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/priv-recordintro.gsmbin3498 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/privacy-incorrect.gsmbin4620 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/privacy-prompt.gsmbin5973 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/privacy-thankyou.gsmbin1947 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/privacy-unident.gsmbin7029 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-callswaiting.gsmbin3366 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-holdtime.gsmbin4026 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-less-than.gsmbin1419 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-minutes.gsmbin1056 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-periodic-announce.gsmbin12474 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-reporthold.gsmbin1188 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-seconds.gsmbin1386 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-thankyou.gsmbin2739 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-thereare.gsmbin3234 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/queue-youarenext.gsmbin8283 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/screen-callee-options.gsmbin25674 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/seconds.gsmbin1386 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/spy-agent.gsmbin1320 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/spy-h323.gsmbin2706 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/spy-iax.gsmbin957 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/spy-iax2.gsmbin957 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/spy-mgcp.gsmbin2508 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/spy-sip.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/spy-skinny.gsmbin1320 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/spy-zap.gsmbin1287 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/ss-noservice.gsmbin7689 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/transfer.gsmbin3696 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/tt-allbusy.gsmbin13926 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/tt-monkeys.gsmbin26697 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/tt-monkeysintro.gsmbin4257 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/tt-somethingwrong.gsmbin2871 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/tt-weasels.gsmbin4323 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-Cust1.gsmbin2046 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-Cust2.gsmbin1914 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-Cust3.gsmbin2112 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-Cust4.gsmbin1815 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-Cust5.gsmbin2277 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-Family.gsmbin990 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-Friends.gsmbin1023 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-INBOX.gsmbin891 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-Old.gsmbin825 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-Work.gsmbin792 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-advopts.gsmbin3729 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-and.gsmbin957 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-calldiffnum.gsmbin5115 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-changeto.gsmbin2640 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-delete.gsmbin3696 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-deleted.gsmbin2112 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-dialout.gsmbin3267 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-enter-num-to-call.gsmbin3399 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-extension.gsmbin1914 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-first.gsmbin1353 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-for.gsmbin1155 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-forward.gsmbin7260 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-forwardoptions.gsmbin9702 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-from-extension.gsmbin2640 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-from-phonenumber.gsmbin2574 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-from.gsmbin759 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-goodbye.gsmbin1419 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-helpexit.gsmbin5181 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-incorrect-mailbox.gsmbin4554 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-incorrect.gsmbin2805 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-instructions.gsmbin10659 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-intro.gsmbin8844 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-isonphone.gsmbin1980 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-isunavail.gsmbin1980 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-last.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-leavemsg.gsmbin3828 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-login.gsmbin3993 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-mailboxfull.gsmbin6534 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-message.gsmbin1320 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-messages.gsmbin1452 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-minutes.gsmbin1056 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-mismatch.gsmbin8085 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-msginstruct.gsmbin22341 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-msgsaved.gsmbin3168 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-newpassword.gsmbin5214 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-newuser.gsmbin10494 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-next.gsmbin3960 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-no.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-nobodyavail.gsmbin4620 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-nobox.gsmbin6864 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-nomore.gsmbin2079 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-nonumber.gsmbin4257 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-num-i-have.gsmbin2607 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-onefor.gsmbin2244 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-options.gsmbin25245 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-opts.gsmbin11253 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-passchanged.gsmbin3366 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-password.gsmbin1551 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-press.gsmbin1320 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-prev.gsmbin3696 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-reachoper.gsmbin4950 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-rec-busy.gsmbin7095 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-rec-name.gsmbin6501 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-rec-temp.gsmbin7689 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-rec-unv.gsmbin7524 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-received.gsmbin1287 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-reenterpassword.gsmbin7821 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-repeat.gsmbin4092 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-review.gsmbin14487 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-saved.gsmbin1254 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-savedto.gsmbin1584 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-savefolder.gsmbin4125 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-savemessage.gsmbin3564 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-saveoper.gsmbin16533 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-sorry.gsmbin4686 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-star-cancel.gsmbin3102 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-starmain.gsmbin4620 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tempgreeting.gsmbin5181 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tempgreeting2.gsmbin11154 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tempremoved.gsmbin5148 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-then-pound.gsmbin2178 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-theperson.gsmbin2508 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tocallback.gsmbin6204 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tocallnum.gsmbin4554 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tocancel.gsmbin2772 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tocancelmsg.gsmbin5445 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-toenternumber.gsmbin4389 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-toforward.gsmbin4785 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tohearenv.gsmbin5346 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tomakecall.gsmbin5247 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-tooshort.gsmbin2904 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-toreply.gsmbin4422 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-torerecord.gsmbin5379 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-undelete.gsmbin4059 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-undeleted.gsmbin2310 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-unknown-caller.gsmbin2277 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-whichbox.gsmbin5247 -> 0 bytes
-rw-r--r--1.2-netsec/sounds/vm-youhave.gsmbin1320 -> 0 bytes
-rw-r--r--1.2-netsec/srv.c137
-rw-r--r--1.2-netsec/stdtime/Makefile24
-rw-r--r--1.2-netsec/stdtime/localtime.c1505
-rw-r--r--1.2-netsec/stdtime/private.h222
-rw-r--r--1.2-netsec/stdtime/test.c21
-rw-r--r--1.2-netsec/stdtime/tzfile.h189
-rw-r--r--1.2-netsec/strcompat.c57
-rw-r--r--1.2-netsec/tdd.c320
-rw-r--r--1.2-netsec/term.c279
-rw-r--r--1.2-netsec/translate.c509
-rw-r--r--1.2-netsec/ulaw.c105
-rw-r--r--1.2-netsec/utils.c905
-rw-r--r--1.2-netsec/utils/Makefile80
-rw-r--r--1.2-netsec/utils/astman.1102
-rw-r--r--1.2-netsec/utils/astman.c720
-rw-r--r--1.2-netsec/utils/check_expr.c324
-rw-r--r--1.2-netsec/utils/frame.c1034
-rw-r--r--1.2-netsec/utils/frame.h300
-rw-r--r--1.2-netsec/utils/smsq.c763
-rw-r--r--1.2-netsec/utils/stereorize.c159
-rw-r--r--1.2-netsec/utils/streamplayer.c103
1126 files changed, 0 insertions, 321092 deletions
diff --git a/1.2-netsec/.cleancount b/1.2-netsec/.cleancount
deleted file mode 100644
index 45a4fb75d..000000000
--- a/1.2-netsec/.cleancount
+++ /dev/null
@@ -1 +0,0 @@
-8
diff --git a/1.2-netsec/BUGS b/1.2-netsec/BUGS
deleted file mode 100644
index f1c6af13a..000000000
--- a/1.2-netsec/BUGS
+++ /dev/null
@@ -1,22 +0,0 @@
-Asterisk Bug Tracking Information
-=================================
-
-To learn about and report Asterisk bugs, please visit
-the official Asterisk Bug Tracker at:
-
- http://bugs.digium.com
-
-For more information on using the bug tracker, or to
-learn how you can contribute by acting as a bug marshall
-please see:
-
- http://www.digium.com/index.php?menu=bugguidelines
-
-If you would like to submit a feature request, please
-resist the temptation to post it to the bug tracker.
-Feature requests should be posted to the asterisk-dev
-mailing list, located at:
-
- http://lists.digium.com
-
-Thank you!
diff --git a/1.2-netsec/CHANGES b/1.2-netsec/CHANGES
deleted file mode 100644
index 49e14a4fa..000000000
--- a/1.2-netsec/CHANGES
+++ /dev/null
@@ -1,127 +0,0 @@
-Changes since Asterisk 1.2.0-beta2:
-
- * Cygwin build system portability
- * Optional generation of outbound silence during channel recording
-
-Changes since Asterisk 1.2.0-beta1:
-
- * Many, many bug fixes
- * Documentation and sample configuration updates
- * Vastly improved presence/subscription support in the SIP channel driver
- * A new (experimental) mISDN channel driver
- * A new monitoring application (MixMonitor)
- * More portability fixes for non-Linux platforms
- * New dialplan functions replacing old applications
- * Significant deadlock and performance upgrades for the Manager interface
- * An upgrade to the 'new' dialplan expression parser for all users
- * New Zaptel echo cancellers with improved performance
- * Support for the latest OSP toolkit from TransNexus
- * Support user-controlled volume adjustment in MeetMe application
- * More dialplan applications now return status variables instead of priority jumping
- * Much more powerful ENUM support in the dialplan
- * SIP domain support for authentication and virtual hosting
- * Many PRI protocol updates and fixes, including more complete Q.SIG support
- * New applications: Pickup() and Page()
-
-Changes since Asterisk 1.0:
-
-This list currently only containts changes made from the end of November until
-March 26, 2005.
-
- * Add new applications:
- -- AgentMonitorOutgoing
- -- Curl
- -- ExecIf
- -- ExecIfTime
- -- IAX2Provision
- -- MacroExit
- -- MacroIf
- -- PauseQueueMember
- -- ReadFile
- -- SetRDNIS
- -- SIPAddHeader
- -- SIPGetHeader
- -- StartMusicOnHold
- -- StopMusicOnHold
- -- UnpauseQueueMember
- -- WaitForSilence
- -- While / EndWhile
- * app Answer
- -- added delay option
- * app ChanIsAvail
- -- added 's' option
- * app Dial
- -- add option to specify the class for musiconhold with m option
- * app EnumLookup
- -- added "reload enum" for configuration
- * app Goto
- -- added relative priorities
- * app GotoIf
- -- added relative priorities
- * app MeetMe
- -- added 'i' option
- -- added 'r' option
- -- added 'T' option
- -- added 'P' option
- -- added 'c' option
- -- added adminpin to meetme.conf
- -- added reload command
- * app PrivacyManager
- -- add config file privacy.conf
- * app queue
- -- queues.conf
- -- added persistentmembers option to queues.conf
- -- changed music option to musiconhold
- -- added weight option
- -- added note about why agent groups probably shouldn't be used
- -- added timeoutrestart option
- * app Read
- -- added attempts parameter
- -- added timeout parameter
- * app Record
- -- added 'q' option
- * app SendDTMF
- -- add timeout option
- * app SMS
- -- document alternative syntax for queueing messages
- * app Voicemail
- -- add info about VM_CATEGORY
- -- voicemail.conf
- -- added usedirectory option
- -- added VM_CIDNUM and VM_CIDNAME in message config
- * chan IAX2
- -- new jitterbuffer
- -- added setvar option
- -- added regex to iax2 show peers/users
- -- allow multiple bindaddr lines in iax.conf
- -- added reload command
- -- added forcejitterbuffer option
- -- added note about specifying bindport before bindaddr
- -- added trunktimestamps option
- * chan Agent
- -- added agent logoff CLI command
- * chan OSS
- -- added Flash CLI command
- * chan SIP
- -- added setvar option
- -- added compactheaders option
- -- added usereqphone option
- -- added registertimeout option
- -- added externhost option
- -- added sip notify CLI command
- -- added sip_notify.conf
- -- added allowguest option
- * chan Zap
- -- added hanguponplarityswitch option
- -- added sendcalleridafter option
- -- added priresetinterval option
- -- added TON/NPI config options (the ones right above the resetinterval option)
- -- added answeronpolarityswitch option
- -- added "never" for resetinterval
- * extensions
- -- allow '*' when including files (#include "sip-*.conf")
- -- added eswitch
- * General
- -- added #exec syntax for including output from a command
- -- added show features CLI command
- -- added configuration templates for category inheritance
diff --git a/1.2-netsec/COPYING b/1.2-netsec/COPYING
deleted file mode 100644
index aa2ebac66..000000000
--- a/1.2-netsec/COPYING
+++ /dev/null
@@ -1,341 +0,0 @@
-
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) 19yy <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) 19yy name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/1.2-netsec/CREDITS b/1.2-netsec/CREDITS
deleted file mode 100644
index 8dc47d6bd..000000000
--- a/1.2-netsec/CREDITS
+++ /dev/null
@@ -1,133 +0,0 @@
-
-=== DEVELOPMENT SUPPORT ===
-We'd like to thank the following companies for helping fund development of
-Asterisk:
-
-Pilosoft, Inc. - for supporting ADSI development in Asterisk
-
-Asterlink, Inc. - for supporting broad Asterisk development
-
-GFS - for supporting ALSA development
-
-Telesthetic - for supporting SIP development
-
-Christos Ricudis - for substantial code contributions
-
-Paul Bagyenda, Digital Solutions - for initial Voicetronix driver development
-
-=== WISHLIST CONTRIBUTERS ===
-Jeremy McNamara - SpeeX support
-Nick Seraphin - RDNIS support
-Gary - Phonejack ADSI (in progress)
-Wasim - Hangup detect
-
-=== HARDWARE DONORS ===
-* Thanks to QuickNet Technologies for their donation of an Internet
-PhoneJack and Linejack card to the project. (http://www.quicknet.net)
-
-=== MISCELLANEOUS PATCHES ===
-Jim Dixon - Zapata Telephony and app_rpt
- http://www.zapatatelephony.org/app_rpt.html
-Russell Bryant - Asterisk 1.0 maintainer and misc. enhancements
- russelb@clemson.edu
-Anthony Minessale II - Countless big and small fixes, and relentless forward push
- anthmct@yahoo.com http://www.asterlink.com
-James Golovich - Innumerable contributions
- You can find him and asterisk-perl at http://asterisk.gnuinter.net
-Andre Bierwirth - Extension hints and status
-Oliver Daudey - ISDN4Linux fixes
-Pauline Middelink - ISDN4Linux patches and some general patches.
- She can be found at http://www.polyware.nl/~middelink/En/
-Jean-Denis Girard - Various contributions from the South Pacific Islands
- jd-girard@esoft.pf http://www.esoft.pf
-William Jordan / Vonage - MySQL enhancements to Voicemail
- wjordan@vonage.com
-Jac Kersing - Various fixes
-Steven Critchfield - Seek and Trunc functions for playback and recording
- critch@basesys.com
-Jefferson Noxon - app_lookupcidname, app_db, and various other contributions
-Klaus-Peter Junghanns - in-band DTMF on SIP and MGCP
-Ross Finlayson - Dynamic RTP payload support
-Mahmut Fettahlioglu - Audio recording, music-on-hold changes, alaw file
- format, and various fixes. Can be contacted at mahmut@oa.com.au
-James Dennis - Cisco SIP compatibility patches to work with SIP service
- providers. Can be contacted at asterisk@jdennis.net
-Tilghman Lesher - ast_localtime(); ast_say_date_with_format();
- GotoIfTime, Random, SayUnixTime, HasNewVoicemail applications;
- CUT, SORT, EVAL, CURL, FIELDQTY, STRFTIME, QUEUEAGENT* functions;
- and other innumerable bug fixes. http://asterisk.drunkcoder.com/
-Jayson Vantuyl - Manager protocol changes, various other bugs.
- jvantuyl@computingedge.net
-Thorsten Lockert - OpenBSD, FreeBSD ports, making MacOS X port run on 10.3,
- dialplan include verification, route lookup on OpenBSD, various other
- bugs. tholo@sigmasoft.com
-Brian West - ODBC support and Bug Marshaling
-Josh Roberson - chan_zap reload support, Advanced Voicemail Features, other misc. patches,
- and Bug Marshalling. - josh@asteriasgi.com, http://www.asteriasgi.com
-William Waites - syslog support, SIP NAT traversal for SIP-UA. ww@styx.org
-Rich Murphey - Porting to FreeBSD, NetBSD, OpenBSD, and Darwin.
- rich@whiteoaklabs.com http://whiteoaklabs.com
-Simon Lockhart - Porting to Solaris (based on work of Logan ???)
- simon@slimey.org
-Olle E. Johansson - SIP RFC compliance, documentation and testing, testing, testing
- oej@edvina.net, http://edvina.net
-Steve Kann - new jitter buffer for IAX2
- stevek@stevek.com
-Constantine Filin - major contributions to the Asterisk Realtime Architecture
-Steve Murphy - privacy support
-Claude Patry - bug fixes, feature enhancements, and bug marshalling
- cpatry@gmail.com
-
-=== OTHER CONTRIBUTIONS ===
-John Todd - Monkey sounds and associated teletorture prompt
-Michael Jerris - bug marshaling
-Leif Madsen, Jared Smith and Jim van Meggelen - the Asterisk book
- available under a Creative Commons License at http://www.asteriskdocs.org
-
-=== HOLD MUSIC ===
-Music provided by www.freeplaymusic.com
-
-=== OTHER SOURCE CODE IN ASTERISK ===
-
-Digium did not implement the codecs in Asterisk. Here is the copyright on the
-GSM source:
-
-Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann,
-Technische Universitaet Berlin
-
-Any use of this software is permitted provided that this notice is not
-removed and that neither the authors nor the Technische Universitaet Berlin
-are deemed to have made any representations as to the suitability of this
-software for any purpose nor are held responsible for any defects of
-this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
-
-As a matter of courtesy, the authors request to be informed about uses
-this software has found, about bugs in this software, and about any
-improvements that may be of general interest.
-
-Berlin, 28.11.1994
-Jutta Degener
-Carsten Bormann
-
-And the copyright on the ADPCM source:
-
-Copyright 1992 by Stichting Mathematisch Centrum, Amsterdam, The
-Netherlands.
-
- All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the names of Stichting Mathematisch
-Centrum or CWI not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-
-STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
-THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
-FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
-OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/1.2-netsec/HARDWARE b/1.2-netsec/HARDWARE
deleted file mode 100644
index 86b28bef7..000000000
--- a/1.2-netsec/HARDWARE
+++ /dev/null
@@ -1,70 +0,0 @@
-A PBX is only really useful if you can get calls into it. Of course, you
-can use Asterisk with VoIP calls (SIP, H.323, IAX), but you can also talk
-to the real PSTN through various cards.
-
-Supported Hardware is divided into two general groups: Zaptel devices and
-non-zaptel devices. The Zaptel compatible hardware supports pseudo-TDM
-conferencing and all call features through chan_zap, whereas non-zaptel
-compatible hardware may have different features.
-
-Zaptel compatible hardware
-==========================
-
--- Digium (Primary author of Asterisk)
- http://www.digium.com, http://store.yahoo.com/asteriskpbx
-
- * Wildcard X100P - Single FXO interface connects to Loopstart phone
- line
-
- * Wildcard T400P (obsolete) - Quad T1 interface connects to four T1/PRI
- interfaces. Supports RBS and PRI voice and PPP, FR, and HDLC data.
-
- * Wildcard E400P (obsolete)- Quad E1 interface connects to four E1/PRI
- (or PRA) interfaces. Supports PRA/PRI, EuroISDN voice and data.
-
- * Wildcard T100P - Single T1 interface connects to a single T1/PRI
- interface. Supports RBS and PRI voice and PPP, FR, and HDLC data.
-
- * Wildcard E100P - Single E1 interface connects to a single E1/PRI (or PRA)
- interface. Supports PRA/PRI, EuroISDN voice and PPP, FR, HDLC data.
-
- * Wildcard S100U - Single FXS interface connects to a standard analog
- telephone.
-
- * Wildcard TDM400P - Quad Modular FXS interface connects to standard
- analog telephones.
-
- * Wildcard TE410P - Quad T1/E1 switchable interface. Supports PRI and
- RBS signalling, as well as PPP, FR, and HDLC data modes.
-
-Non-zaptel compatible hardware
-==============================
-
--- QuickNet, Inc.
- http://www.quicknet.net
-
- * Internet PhoneJack - Single FXS interface. Supports Linux telephony
- interface. DSP compression built-in.
-
- * Internet LineJack - Single FXS or FXO interface. Supports Linux
- telephony interface.
-
-
-Miscellaneous other interfaces
-==============================
-
--- ISDN4Linux
- http://www.isdn4linux.de/
-
- * Any ISDN terminal adapter supported by isdn4linux should provide
- connectivity.
-
--- ALSA
- http://www.alsa-project.org
-
- * Any ALSA compatible full-duplex sound card
-
--- OSS
- http://www.opensound.com
-
- * Any OSS compatible full-duplex sound card
diff --git a/1.2-netsec/LICENSE b/1.2-netsec/LICENSE
deleted file mode 100644
index a30b79413..000000000
--- a/1.2-netsec/LICENSE
+++ /dev/null
@@ -1,56 +0,0 @@
-Asterisk is distributed under the GNU General Public License version 2
-and is also available under alternative licenses negotiated directly
-with Digium, Inc. If you obtained Asterisk under the GPL, then the GPL
-applies to all loadable Asterisk modules used on your system as well,
-except as defined below. The GPL (version 2) is included in this
-source tree in the file COPYING.
-
-Digium, Inc. (formerly Linux Support Services) holds copyright
-and/or sufficient licenses to all components of the Asterisk
-package, and therefore can grant, at its sole discretion, the ability
-for companies, individuals, or organizations to create proprietary or
-Open Source (even if not GPL) modules which may be dynamically linked at
-runtime with the portions of Asterisk which fall under our
-copyright/license umbrella, or are distributed under more flexible
-licenses than GPL.
-
-If you wish to use our code in other GPL programs, don't worry --
-there is no requirement that you provide the same exception in your
-GPL'd products (although if you've written a module for Asterisk we
-would strongly encourage you to make the same exception that we do).
-
-Specific permission is also granted to link Asterisk with OpenSSL and
-OpenH323.
-
-In addition, Asterisk implements two management/control protocols: the
-Asterisk Manager Interface (AMI) and the Asterisk Gateway Interface
-(AGI). It is our belief that applications using these protocols to
-manage or control an Asterisk instance do not have to be licensed
-under the GPL or a compatible license, as we believe these protocols
-do not create a 'derivative work' as referred to in the GPL. However,
-should any court or other judiciary body find that these protocols do
-fall under the terms of the GPL, then we hereby grant you a license to
-use these protocols in combination with Asterisk in external
-applications licensed under any license you wish.
-
-The 'Asterisk' name and logos are trademarks owned by Digium, Inc.,
-and use of them is subject to our trademark licensing policies. If you
-wish to use these trademarks for purposes other than simple
-redistribution of Asterisk source code obtained from Digium, you
-should contact our licensing department to determine the necessary
-steps you must take.
-
-If you have any questions regarding our licensing policy, please
-contact us:
-
-+1.877.546.8963 (via telephone in the USA)
-+1.256.428.6000 (via telephone outside the USA)
-+1.256.864.0464 (via FAX inside or outside the USA)
-IAX2/misery.digium.com/6000 (via IAX2)
-licensing@digium.com (via email)
-
-Digium, Inc.
-150 West Park Loop
-Suite 100
-Huntsville, AL 35806
-USA
diff --git a/1.2-netsec/Makefile b/1.2-netsec/Makefile
deleted file mode 100644
index a238a971a..000000000
--- a/1.2-netsec/Makefile
+++ /dev/null
@@ -1,908 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Top level Makefile
-#
-# Copyright (C) 1999-2005, Mark Spencer
-#
-# Mark Spencer <markster@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-.EXPORT_ALL_VARIABLES:
-
-# 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
-CC=$(CROSS_COMPILE)gcc
-HOST_CC=gcc
-# CROSS_ARCH=Linux
-# CROSS_PROC=arm
-# SUB_PROC=xscale # or maverick
-
-ifeq ($(CROSS_COMPILE),)
- OSARCH=$(shell uname -s)
- OSREV=$(shell uname -r)
-else
- OSARCH=$(CROSS_ARCH)
- OSREV=$(CROSS_REV)
-endif
-
-# Remember the MAKELEVEL at the top
-MAKETOPLEVEL?=$(MAKELEVEL)
-
-PWD=$(shell pwd)
-
-ifneq ($(findstring dont-optimize,$(MAKECMDGOALS)),dont-optimize)
-######### 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
-endif
-
-#Overwite config files on "make samples"
-OVERWRITE=y
-
-#Include debug and macro symbols in the executables (-g) and profiling info (-pg)
-DEBUG=-g3 #-pg
-
-#Set NOCRYPTO to yes if you do not want to have crypto support or
-#dependencies
-#NOCRYPTO=yes
-
-# If you are running a radio application, define RADIO_RELAX so that the DTMF
-# will be received more reliably
-#OPTIONS += -DRADIO_RELAX
-
-# If you don't have a lot of memory (e.g. embedded Asterisk), define LOW_MEMORY
-# to reduce the size of certain static buffers
-
-#ifneq ($(CROSS_COMPILE),)
-#OPTIONS += -DLOW_MEMORY
-#endif
-
-# Optional debugging parameters
-DEBUG_THREADS = #-DDUMP_SCHEDULER #-DDEBUG_SCHEDULER #-DDEBUG_THREADS #-DDO_CRASH #-DDETECT_DEADLOCKS
-
-# Uncomment next one to enable ast_frame tracing (for debugging)
-TRACE_FRAMES = #-DTRACE_FRAMES
-
-# Uncomment next one to enable malloc debugging
-# You can view malloc debugging with:
-# *CLI> show memory allocations [filename]
-# *CLI> show memory summary [filename]
-#
-MALLOC_DEBUG = #-include $(PWD)/include/asterisk/astmm.h
-
-# Where to install asterisk after compiling
-# Default -> leave empty
-INSTALL_PREFIX?=
-
-# Staging directory
-# Files are copied here temporarily during the install process
-# For example, make DESTDIR=/tmp/asterisk woud put things in
-# /tmp/asterisk/etc/asterisk
-# XXX 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
-# Inforce the detection of busy singal (get rid of false hangups)
-# Don't use together with -DBUSYDETECT_TONEONLY
-BUSYDETECT+= #-DBUSYDETECT_COMPARE_TONE_AND_SILENCE
-
-# Comment this if you want to disable MIDCOM
-MIDCOM = -DMIDCOM
-
-ifneq ($(OSARCH),SunOS)
- ASTLIBDIR=$(INSTALL_PREFIX)/usr/lib/asterisk
- ASTVARLIBDIR=$(INSTALL_PREFIX)/var/lib/asterisk
- ASTETCDIR=$(INSTALL_PREFIX)/etc/asterisk
- ASTSPOOLDIR=$(INSTALL_PREFIX)/var/spool/asterisk
- ASTLOGDIR=$(INSTALL_PREFIX)/var/log/asterisk
- ASTHEADERDIR=$(INSTALL_PREFIX)/usr/include/asterisk
- ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
- ASTBINDIR=$(INSTALL_PREFIX)/usr/bin
- ASTSBINDIR=$(INSTALL_PREFIX)/usr/sbin
- ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
- ASTMANDIR=$(INSTALL_PREFIX)/usr/share/man
- MODULES_DIR=$(ASTLIBDIR)/modules
- AGI_DIR=$(ASTVARLIBDIR)/agi-bin
-else
- ASTLIBDIR=$(INSTALL_PREFIX)/opt/asterisk/lib
- ASTVARLIBDIR=$(INSTALL_PREFIX)/var/opt/asterisk/lib
- ASTETCDIR=$(INSTALL_PREFIX)/etc/opt/asterisk
- ASTSPOOLDIR=$(INSTALL_PREFIX)/var/opt/asterisk/spool
- ASTLOGDIR=$(INSTALL_PREFIX)/var/opt/asterisk/log
- ASTHEADERDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/include/asterisk
- ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
- ASTBINDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/bin
- ASTSBINDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/sbin
- ASTVARRUNDIR=$(INSTALL_PREFIX)/var/opt/asterisk/run
- ASTMANDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/share/man
- MODULES_DIR=$(ASTLIBDIR)/modules
- AGI_DIR=$(ASTVARLIBDIR)/agi-bin
-endif
-
-ASTCFLAGS=
-
-# Pentium Pro Optimize
-#PROC=i686
-
-# Pentium & VIA processors optimize
-#PROC=i586
-
-#PROC=k6
-#PROC=ppc
-
-#Uncomment this to use the older DSP routines
-#ASTCFLAGS+=-DOLD_DSP_ROUTINES
-
-# Determine by a grep 'DocumentRoot' of your httpd.conf file
-HTTP_DOCSDIR=/var/www/html
-# Determine by a grep 'ScriptAlias' of your httpd.conf file
-HTTP_CGIDIR=/var/www/cgi-bin
-
-# If the file .asterisk.makeopts is present in your home directory, you can
-# include all of your favorite Makefile options so that every time you download
-# a new version of Asterisk, you don't have to edit the makefile to set them.
-# The file, /etc/asterisk.makeopts will also be included, but can be overridden
-# by the file in your home directory.
-
-ifneq ($(wildcard /etc/asterisk.makeopts),)
- include /etc/asterisk.makeopts
-endif
-
-ifneq ($(wildcard ~/.asterisk.makeopts),)
- include ~/.asterisk.makeopts
-endif
-
-ifeq ($(OSARCH),Linux)
- ifeq ($(CROSS_COMPILE),)
- PROC?=$(shell uname -m)
- else
- PROC=$(CROSS_PROC)
- endif
-
- ifeq ($(PROC),x86_64)
- # You must have GCC 3.4 to use k8, otherwise use athlon
- PROC=k8
- #PROC=athlon
- OPTIONS+=-m64
- endif
-
- ifeq ($(PROC),sparc64)
- #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
- #This works for even old (2.96) versions of gcc and provides a small boost either way.
- #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
- #So we go lowest common available by gcc and go a step down, still a step up from
- #the default as we now have a better instruction set to work with. - Belgarath
- PROC=ultrasparc
- OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
- OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
- OPTIONS+=-fomit-frame-pointer
- endif
-
- ifeq ($(PROC),arm)
- # The Cirrus logic is the only heavily shipping arm processor with a real floating point unit
- ifeq ($(SUB_PROC),maverick)
- OPTIONS+=-fsigned-char -mcpu=ep9312
- else
- ifeq ($(SUB_PROC),xscale)
- OPTIONS+=-fsigned-char -msoft-float -mcpu=xscale
- else
- OPTIONS+=-fsigned-char -msoft-float
- endif
- endif
- endif
- MPG123TARG=linux
-endif
-
-GREP=grep
-ID=id
-
-ifeq ($(OSARCH),SunOS)
- GREP=/usr/xpg4/bin/grep
- M4=/usr/local/bin/m4
- ID=/usr/xpg4/bin/id
-endif
-
-INCLUDE+=-Iinclude -I../include
-ASTCFLAGS+=-pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
-ASTCFLAGS+=$(OPTIMIZE)
-ASTOBJ=-o asterisk
-
-ifeq ($(findstring BSD,$(OSARCH)),BSD)
- PROC=$(shell uname -m)
- ASTCFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-ifneq ($(PROC),ultrasparc)
- ASTCFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
-endif
-
-ifeq ($(PROC),ppc)
- ASTCFLAGS+=-fsigned-char
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/osp/osp.h),)
- ASTCFLAGS+=-DOSP_SUPPORT -I$(CROSS_COMPILE_TARGET)/usr/local/include/osp
-else
- ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/osp/osp.h),)
- ASTCFLAGS+=-DOSP_SUPPORT -I$(CROSS_COMPILE_TARGET)/usr/include/osp
- endif
-endif
-
-ifeq ($(OSARCH),FreeBSD)
- BSDVERSION=$(shell make -V OSVERSION -f $(CROSS_COMPILE_TARGET)/usr/share/mk/bsd.port.subdir.mk)
- ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
- LIBS+=$(shell if test $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
- ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/spandsp),)
- ASTCFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include/spandsp
- endif
- MPG123TARG=freebsd
-
- # XXX FreeBSD paths
- PREFIX?=/usr/local
- ASTLIBDIR=$(INSTALL_PREFIX)$(PREFIX)/lib/asterisk
- ASTVARLIBDIR=$(INSTALL_PREFIX)$(PREFIX)/share/asterisk
- ASTETCDIR=$(INSTALL_PREFIX)$(PREFIX)/etc/asterisk
- ASTSPOOLDIR=$(INSTALL_PREFIX)/var/spool/asterisk
- ASTLOGDIR=$(INSTALL_PREFIX)/var/log/asterisk
- ASTHEADERDIR=$(INSTALL_PREFIX)$(PREFIX)/include/asterisk
- ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
- ASTBINDIR=$(INSTALL_PREFIX)$(PREFIX)/bin
- ASTSBINDIR=$(INSTALL_PREFIX)$(PREFIX)/sbin
- ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
- ASTMANDIR=$(INSTALL_PREFIX)$(PREFIX)/man
- # XXX end FreeBSD paths
-
-endif # FreeBSD
-
-ifeq ($(OSARCH),NetBSD)
- ASTCFLAGS+=-pthread
- INCLUDE+=-I$(CROSS_COMPILE_TARGET)/usr/pkg/include
- MPG123TARG=netbsd
-endif
-
-ifeq ($(OSARCH),OpenBSD)
- ASTCFLAGS+=-pthread
-endif
-
-ifeq ($(OSARCH),SunOS)
- ASTCFLAGS+=-Wcast-align -DSOLARIS
- INCLUDE+=-Iinclude/solaris-compat -I$(CROSS_COMPILE_TARGET)/usr/local/ssl/include
-endif
-
-ifeq ($(findstring CYGWIN,$(OSARCH)),CYGWIN)
- CYGLOADER=cygwin_a
- OSARCH=CYGWIN
- ASTOBJ=-shared -o asterisk.dll -Wl,--out-implib=libasterisk.dll.a -Wl,--export-all-symbols
- ASTLINK=
- LIBS+=-lpthread -lncurses -lm -lresolv
- ASTSBINDIR=$(MODULES_DIR)
- PROC=$(shell uname -m)
-endif
-
-ifndef WITHOUT_ZAPTEL
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/linux/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/pkg/include/zaptel.h),)
- ASTCFLAGS+=-DZAPTEL_OPTIMIZATIONS
-endif
-
-endif # WITHOUT_ZAPTEL
-
-LIBEDIT=editline/libedit.a
-
-ifneq ($(wildcard .version),)
- ASTERISKVERSION:=$(shell cat .version)
- ASTERISKVERSIONNUM:=$(shell awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version)
- RPMVERSION:=$(shell sed 's/[-\/:]/_/g' .version)
-else
- RPMVERSION=unknown
-endif
-
-# CVS mirrors of SVN have .svnrevision files showing
-# which SVN revision they are based on, and .svnbranch
-# showing the branch they are made from
-ifneq ($(wildcard .svnrevision),)
- ASTERISKVERSIONNUM=999999
- ASTERISKVERSION:=SVN-$(shell cat .svnbranch)-r$(shell cat .svnrevision)
-else
- ifneq ($(wildcard .svn),)
- ASTERISKVERSIONNUM=999999
- ASTERISKVERSION=SVN-$(shell build_tools/make_svn_branch_name)
- endif
-endif
-
-ASTCFLAGS+= $(DEBUG_THREADS)
-ASTCFLAGS+= $(TRACE_FRAMES)
-ASTCFLAGS+= $(MALLOC_DEBUG)
-ASTCFLAGS+= $(BUSYDETECT)
-ASTCFLAGS+= $(MIDCOM)
-ASTCFLAGS+= $(OPTIONS)
-ifneq ($(findstring dont-optimize,$(MAKECMDGOALS)),dont-optimize)
-ASTCFLAGS+= -fomit-frame-pointer
-endif
-SUBDIRS=res channels pbx apps codecs formats agi cdr funcs utils stdtime
-
-OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
- translate.o file.o say.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 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
-
-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)
- LIBS+=-ldl -lpthread -lncurses -lm -lresolv #-lnjamd
-else
- LIBS+=-lncurses -lm
-endif
-
-ifeq ($(OSARCH),Darwin)
- LIBS+=-lresolv
- ASTCFLAGS+=-D__Darwin__
- AUDIO_LIBS=-framework CoreAudio
- ASTLINK=-Wl,-dynamic
- SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
- OBJS+= poll.o
- ASTCFLAGS+=-DPOLLCOMPAT
-else
-#These are used for all but Darwin
- ASTLINK=-Wl,-E
- SOLINK=-shared -Xlinker -x
-endif
-
-ifeq ($(OSARCH),FreeBSD)
- LIBS+=-lcrypto
-endif
-
-ifeq ($(OSARCH),NetBSD)
- LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib -lncurses
-endif
-
-ifeq ($(OSARCH),OpenBSD)
- LIBS+=-lcrypto -lpthread -lm -lncurses
-endif
-
-ifeq ($(OSARCH),SunOS)
- LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -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+=$(ASTCFLAGS)
-endif
-
-# This is used when generating the doxygen documentation
-ifneq ($(wildcard /usr/local/bin/dot)$(wildcard /usr/bin/dot),)
- HAVEDOT=yes
-else
- HAVEDOT=no
-endif
-
-LIBS+=-lssl
-
-INSTALL=install
-
-_all: all
- @echo " +--------- Asterisk Build Complete ---------+"
- @echo " + Asterisk has successfully been built, but +"
- @echo " + cannot be run before being installed by +"
- @echo " + running: +"
- @echo " + +"
- @echo " + $(MAKE) install +"
- @echo " +-------------------------------------------+"
-
-all: cleantest depend asterisk subdirs
-
-#ifneq ($(wildcard tags),)
-ctags: tags
-#endif
-
-ifneq ($(wildcard TAGS),)
-all: TAGS
-endif
-
-noclean: depend asterisk subdirs
-
-editline/config.h:
- cd editline && unset CFLAGS LIBS && ./configure ; \
-
-editline/libedit.a: FORCE
- cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
- $(MAKE) -C editline libedit.a
-
-db1-ast/libdb1.a: FORCE
- @if [ -d db1-ast ]; then \
- $(MAKE) -C db1-ast libdb1.a ; \
- else \
- echo "You need to do a cvs update -d not just cvs update"; \
- exit 1; \
- fi
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-ifneq ($(wildcard .tags-depend),)
- include .tags-depend
-endif
-
-ast_expr2.c:
- bison -d --name-prefix=ast_yy ast_expr2.y -o ast_expr2.c
-
-ast_expr2f.c:
- flex --full ast_expr2.fl
-
-testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
- gcc -g -c -DSTANDALONE ast_expr2f.c
- gcc -g -c -DSTANDALONE ast_expr2.c
- gcc -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
-
-asterisk.pdf: asterisk.sgml
- docbook2pdf asterisk.sgml
-
-asterisk.ps: asterisk.sgml
- docbook2ps asterisk.sgml
-
-asterisk.html: asterisk.sgml
- docbook2html asterisk.sgml
- mv r1.html asterisk.html
-
-asterisk.txt: asterisk.sgml
- docbook2txt asterisk.sgml
-
-defaults.h: FORCE
- build_tools/make_defaults_h > $@.tmp
- if cmp -s $@.tmp $@ ; then echo ; else \
- mv $@.tmp $@ ; \
- fi
- rm -f $@.tmp
-
-include/asterisk/version.h: FORCE
- build_tools/make_version_h > $@.tmp
- if cmp -s $@.tmp $@ ; then echo; else \
- mv $@.tmp $@ ; \
- fi
- rm -f $@.tmp
-
-stdtime/libtime.a: FORCE
- @if [ -d stdtime ]; then \
- $(MAKE) -C stdtime libtime.a ; \
- else \
- echo "You need to do a cvs update -d not just cvs update"; \
- exit 1; \
- fi
-
-cygwin_a:
- $(MAKE) -C cygwin all
-
-asterisk: $(CYGLOADER) editline/libedit.a db1-ast/libdb1.a stdtime/libtime.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
- $(CC) $(DEBUG) $(ASTOBJ) $(ASTLINK) $(OBJS) buildinfo.o $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
-
-muted: muted.o
- $(CC) $(AUDIO_LIBS) -o muted muted.o
-
-subdirs:
- for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
-
-clean:
- for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
- rm -f *.o *.so asterisk .depend
- rm -f defaults.h
- rm -f include/asterisk/build.h
- rm -f include/asterisk/version.h
- rm -f .tags-depend .tags-sources tags TAGS
- @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
- @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
- $(MAKE) -C db1-ast clean
- $(MAKE) -C stdtime clean
-
-datafiles: all
- if [ x`$(ID) -un` = xroot ]; then sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/priv-callerintros
- for x in sounds/digits/*.gsm; do \
- if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
- else \
- echo "No description for $$x"; \
- exit 1; \
- fi; \
- done
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate
- for x in sounds/dictate/*.gsm; do \
- if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate ; \
- else \
- echo "No description for $$x"; \
- exit 1; \
- fi; \
- done
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
- for x in sounds/letters/*.gsm; do \
- if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
- else \
- echo "No description for $$x"; \
- exit 1; \
- fi; \
- done
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
- for x in sounds/phonetic/*.gsm; do \
- if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
- else \
- echo "No description for $$x"; \
- exit 1; \
- fi; \
- done
- for x in sounds/demo-* sounds/vm-* sounds/transfer* sounds/pbx-* sounds/ss-* sounds/beep* sounds/dir-* sounds/conf-* sounds/agent-* sounds/invalid* sounds/tt-* sounds/auth-* sounds/privacy-* sounds/queue-* sounds/spy-* sounds/priv-* sounds/screen-* sounds/hello-*; do \
- if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
- else \
- echo "No description for $$x"; \
- exit 1; \
- fi; \
- done
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
- for x in images/*.jpg; do \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
- done
- mkdir -p $(DESTDIR)$(AGI_DIR)
-
-update:
- @if [ -d .svn ]; then \
- echo "Updating from Subversion..." ; \
- svn update | tee update.out; \
- rm -f .version; \
- if [ `grep -c ^C update.out` -gt 0 ]; then \
- echo ; echo "The following files have conflicts:" ; \
- grep ^C update.out | cut -b4- ; \
- fi ; \
- rm -f update.out; \
- elif [ -d CVS ]; then \
- echo "Updating from CVS..." ; \
- cvs -q -z3 update -Pd | tee update.out; \
- rm -f .version; \
- if [ `grep -c ^C update.out` -gt 0 ]; then \
- echo ; echo "The following files have conflicts:" ; \
- grep ^C update.out | cut -d' ' -f2- ; \
- fi ; \
- rm -f update.out; \
- else \
- echo "Not under version control"; \
- fi
-
-NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
-OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
-
-bininstall: all
- mkdir -p $(DESTDIR)$(MODULES_DIR)
- mkdir -p $(DESTDIR)$(ASTSBINDIR)
- mkdir -p $(DESTDIR)$(ASTETCDIR)
- mkdir -p $(DESTDIR)$(ASTBINDIR)
- mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
- mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
- mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
- mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
- 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 cygwin/asterisk.exe ]; then $(INSTALL) -m 755 cygwin/asterisk.exe $(DESTDIR)$(ASTSBINDIR)/; fi
- if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi
- ln -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
- $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
- $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/
- if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
- cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
- chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
- fi
- for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
- $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
- $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
- if [ -n "$(OLDHEADERS)" ]; then \
- rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
- fi
- rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
- mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
- mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
- mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
- $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
- $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
- $(INSTALL) -m 644 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
- if [ -d contrib/firmware/iax ]; then \
- $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
- else \
- echo "You need to do cvs update -d not just cvs update" ; \
- fi
- ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds ; ln -s $(ASTSPOOLDIR)/voicemail . )
- if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
- @echo " +---- Asterisk Installation Complete -------+"
- @echo " + +"
- @echo " + YOU MUST READ THE SECURITY DOCUMENT +"
- @echo " + +"
- @echo " + Asterisk has successfully been installed. +"
- @echo " + If you would like to install the sample +"
- @echo " + configuration files (overwriting any +"
- @echo " + existing config files), run: +"
- @echo " + +"
- @echo " + $(MAKE) samples +"
- @echo " + +"
- @echo " +----------------- or ---------------------+"
- @echo " + +"
- @echo " + You can go ahead and install the asterisk +"
- @echo " + program documentation now or later run: +"
- @echo " + +"
- @echo " + $(MAKE) progdocs +"
- @echo " + +"
- @echo " + **Note** This requires that you have +"
- @echo " + doxygen installed on your local system +"
- @echo " +-------------------------------------------+"
- @$(MAKE) -s oldmodcheck
-
-NEWMODS=$(notdir $(wildcard */*.so))
-OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
-
-oldmodcheck:
- @if [ -n "$(OLDMODS)" ]; then \
- echo " WARNING WARNING WARNING" ;\
- echo "" ;\
- echo " Your Asterisk modules directory, located at" ;\
- echo " $(DESTDIR)$(MODULES_DIR)" ;\
- echo " contains modules that were not installed by this " ;\
- echo " version of Asterisk. Please ensure that these" ;\
- echo " modules are compatible with this version before" ;\
- echo " attempting to run Asterisk." ;\
- echo "" ;\
- for f in $(OLDMODS); do \
- echo " $$f" ;\
- done ;\
- echo "" ;\
- echo " WARNING WARNING WARNING" ;\
- fi
-
-install: all datafiles bininstall
- @if [ -x /usr/sbin/asterisk-post-install ]; then \
- /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
- fi
-
-upgrade: all bininstall
-
-adsi:
- mkdir -p $(DESTDIR)$(ASTETCDIR)
- for x in configs/*.adsi; do \
- if [ ! -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
- fi ; \
- done
-
-samples: adsi
- mkdir -p $(DESTDIR)$(ASTETCDIR)
- for x in configs/*.sample; do \
- if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
- if [ "$(OVERWRITE)" = "y" ]; then \
- if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
- echo "Config file $$x is unchanged"; \
- continue; \
- fi ; \
- mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
- else \
- echo "Skipping config file $$x"; \
- continue; \
- fi ;\
- fi ; \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
- done
- if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
- ( \
- echo "[directories]" ; \
- echo "astetcdir => $(ASTETCDIR)" ; \
- echo "astmoddir => $(MODULES_DIR)" ; \
- echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
- echo "astagidir => $(AGI_DIR)" ; \
- echo "astspooldir => $(ASTSPOOLDIR)" ; \
- echo "astrundir => $(ASTVARRUNDIR)" ; \
- echo "astlogdir => $(ASTLOGDIR)" ; \
- echo "" ; \
- echo "; Changing the following lines may compromise your security." ; \
- echo ";[files]" ; \
- echo ";astctlpermissions = 0660" ; \
- echo ";astctlowner = root" ; \
- echo ";astctlgroup = apache" ; \
- echo ";astctl = asterisk.ctl" ; \
- ) > $(DESTDIR)$(ASTCONFPATH) ; \
- else \
- echo "Skipping asterisk.conf creation"; \
- fi
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
- for x in sounds/demo-*; do \
- if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
- else \
- echo "No description for $$x"; \
- exit 1; \
- fi; \
- done
- mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
- for x in sounds/*.mp3; do \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
- done
- rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
- mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
- :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
- for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
- cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
- done
- :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
- for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
- cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
- done
-
-webvmail:
- @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
- @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
- $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
- mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
- for x in images/*.gif; do \
- $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
- done
- @echo " +--------- Asterisk Web Voicemail ----------+"
- @echo " + +"
- @echo " + Asterisk Web Voicemail is installed in +"
- @echo " + your cgi-bin directory: +"
- @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
- @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO +"
- @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT! +"
- @echo " + +"
- @echo " + Other static items have been stored in: +"
- @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
- @echo " + +"
- @echo " + If these paths do not match your httpd +"
- @echo " + installation, correct the definitions +"
- @echo " + in your Makefile of HTTP_CGIDIR and +"
- @echo " + HTTP_DOCSDIR +"
- @echo " + +"
- @echo " +-------------------------------------------+"
-
-spec:
- sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
-
-rpm: __rpm
-
-__rpm: include/asterisk/version.h spec
- rm -rf /tmp/asterisk ; \
- mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
- $(MAKE) DESTDIR=/tmp/asterisk install ; \
- $(MAKE) DESTDIR=/tmp/asterisk samples ; \
- mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
- cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
- rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
-
-progdocs:
- (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
- echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen -
-
-mpg123:
- @wget -V >/dev/null || (echo "You need wget" ; false )
- [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
- [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
- $(MAKE) -C mpg123-0.59r $(MPG123TARG)
-
-config:
- if [ -d /etc/rc.d/init.d ]; then \
- $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
- /sbin/chkconfig --add asterisk; \
- elif [ -d /etc/init.d ]; then \
- $(INSTALL) -m 755 init.asterisk /etc/init.d/asterisk; \
- fi
-
-dont-optimize: install
-
-valgrind: dont-optimize
-
-depend: include/asterisk/version.h .depend defaults.h
- for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
-
-.depend: include/asterisk/version.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
-
-FORCE:
-
-%_env:
- $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
-
-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
-# We can avoid this by making noclean
-
-cleantest:
- if cmp -s .cleancount .lastclean ; then echo ; else \
- $(MAKE) clean; cp -f .cleancount .lastclean;\
- fi
diff --git a/1.2-netsec/README b/1.2-netsec/README
deleted file mode 100644
index 687b7ca63..000000000
--- a/1.2-netsec/README
+++ /dev/null
@@ -1,248 +0,0 @@
-The Asterisk Open Source PBX
-by Mark Spencer <markster@digium.com>
-and the Asterisk.org developer community
-
-Copyright (C) 2001-2005 Digium, Inc.
-and other copyright holders.
-================================================================
-
-* SECURITY
- It is imperative that you read and fully understand the contents of
-the SECURITY file before you attempt to configure and run an Asterisk
-server.
-
-* WHAT IS ASTERISK ?
- Asterisk is an Open Source PBX and telephony toolkit. It is, in a
-sense, middleware between Internet and telephony channels on the bottom,
-and Internet and telephony applications at the top. For more information
-on the project itself, please visit the Asterisk home page at:
-
- http://www.asterisk.org
-
-In addition you'll find lots of information compiled by the Asterisk
-community on this Wiki:
-
- http://www.voip-info.org/wiki-Asterisk
-
-There is a book on Asterisk published by O'Reilly under the
-Creative Commons License. It is available in book stores as well
-as in a downloadable version on the http://www.asteriskdocs.org
-web site.
-
-* SUPPORTED OPERATING SYSTEMS
-
-== Linux ==
- The Asterisk Open Source PBX is developed and tested primarily on the
-GNU/Linux operating system, and is supported on every major GNU/Linux
-distribution.
-
-== Others ==
- Asterisk has also been 'ported' and reportedly runs properly on other
-operating systems as well, including Sun Solaris, Apple's Mac OS X, and
-the BSD variants.
-
-* GETTING STARTED
-
- First, be sure you've got supported hardware (but note that you don't need
-ANY special hardware, not even a soundcard) to install and run Asterisk.
-
- Supported telephony hardware includes:
-
- * All Wildcard (tm) products from Digium (www.digium.com)
- * QuickNet Internet PhoneJack and LineJack (http://www.quicknet.net)
- * any full duplex sound card supported by ALSA or OSS
- * VoiceTronix OpenLine products
-
-The are several drivers for ISDN BRI cards available from third party sources.
-Check the voip-info.org wiki for more information on chan_capi, chan_misdn and
-zaphfc.
-
-* UPGRADING FROM VERSION 1.0
-
- If you are updating from a previous version of Asterisk, make sure you
-read the UPGRADE.txt file in the source directory. There are some files
-and configuration options that you will have to change, even though we
-made every effort possible to maintain backwards compatibility.
-
- In order to discover new features to use, please check the configuration
-examples in the /configs directory of the source code distribution.
-To discover the major new features of Asterisk 1.2, please visit
-http://edvina.net/asterisk1-2/
-
-* NEW INSTALLATIONS
-
- Ensure that your system contains a compatible compiler and development
-libraries. Asterisk requires either the GNU Compiler Collection (GCC) version
-3.0 or higher, or a compiler that supports the C99 specification and some of
-the gcc language extensions. In addition, your system needs to have the C
-library headers available, and the headers and libraries for OpenSSL,
-ncurses and zlib.
-On many distributions, these files are installed by packages with names like
-'glibc-devel', 'ncurses-devel', 'openssl-devel' and 'zlib-devel' or similar.
-
- So let's proceed:
-
-1) Run "make"
-
- Assuming the build completes successfully:
-
-2) Run "make install"
-
- Each time you update or checkout from CVS, you are strongly encouraged
-to ensure all previous object files are removed to avoid internal
-inconsistency in Asterisk. Normally, this is automatically done with
-the presence of the file .cleancount, which increments each time a 'make clean'
-is required, and the file .lastclean, which contains the last .cleancount used.
-
- If this is your first time working with Asterisk, you may wish to install
-the sample PBX, with demonstration extensions, etc. If so, run:
-
-3) "make samples"
-
- Doing so will overwrite any existing config files you have.
-
- Finally, you can launch Asterisk in the foreground mode (not a daemon)
-with:
-
-# asterisk -vvvc
-
- You'll see a bunch of verbose messages fly by your screen as Asterisk
-initializes (that's the "very very verbose" mode). When it's ready, if
-you specified the "c" then you'll get a command line console, that looks
-like this:
-
-*CLI>
-
- You can type "help" at any time to get help with the system. For help
-with a specific command, type "help <command>". To start the PBX using
-your sound card, you can type "dial" to dial the PBX. Then you can use
-"answer", "hangup", and "dial" to simulate the actions of a telephone.
-Remember that if you don't have a full duplex sound card (and Asterisk
-will tell you somewhere in its verbose messages if you do/don't) then it
-won't work right (not yet).
-
- "man asterisk" at the Unix/Linux command prompt will give you detailed
-information on how to start and stop Asterisk, as well as all the command
-line options for starting Asterisk.
-
- Feel free to look over the configuration files in /etc/asterisk, where
-you'll find a lot of information about what you can do with Asterisk.
-
-* ABOUT CONFIGURATION FILES
-
- All Asterisk configuration files share a common format. Comments are
-delimited by ';' (since '#' of course, being a DTMF digit, may occur in
-many places). A configuration file is divided into sections whose names
-appear in []'s. Each section typically contains two types of statements,
-those of the form 'variable = value', and those of the form 'object =>
-parameters'. Internally the use of '=' and '=>' is exactly the same, so
-they're used only to help make the configuration file easier to
-understand, and do not affect how it is actually parsed.
-
- Entries of the form 'variable=value' set the value of some parameter in
-asterisk. For example, in zapata.conf, one might specify:
-
- switchtype=national
-
-in order to indicate to Asterisk that the switch they are connecting to is
-of the type "national". In general, the parameter will apply to
-instantiations which occur below its specification. For example, if the
-configuration file read:
-
- switchtype = national
- channel => 1-4
- channel => 10-12
- switchtype = dms100
- channel => 25-47
-
-the "national" switchtype would be applied to channels one through
-four and channels 10 through 12, whereas the "dms100" switchtype would
-apply to channels 25 through 47.
-
- The "object => parameters" instantiates an object with the given
-parameters. For example, the line "channel => 25-47" creates objects for
-the channels 25 through 47 of the card, obtaining the settings
-from the variables specified above.
-
-* NETWORK SECURITY DEVICES
-
-This release of Asterisk contains support for network security devices
-manufactured by Ranch Networks, Inc., using their MIDCOM interface
-library. You will need the companion libmidcom-0.1.0.tar.gz file to
-build the library. Contact Ranch Networks' support department for assistance
-in building and configuring MIDCOM support.
-
-* SPECIAL NOTE ON TIME
-
- Those using SIP phones should be aware that Asterisk is sensitive to
-large jumps in time. Manually changing the system time using date(1)
-(or other similar commands) may cause SIP registrations and other
-internal processes to fail. If your system cannot keep accurate time
-by itself use NTP (http://www.ntp.org/) to keep the system clock
-synchronized to "real time". NTP is designed to keep the system clock
-synchronized by speeding up or slowing down the system clock until it
-is synchronized to "real time" rather than by jumping the time and
-causing discontinuities. Most Linux distributions include precompiled
-versions of NTP. Beware of some time synchronization methods that get
-the correct real time periodically and then manually set the system
-clock.
-
- Apparent time changes due to daylight savings time are just that,
-apparent. The use of daylight savings time in a Linux system is
-purely a user interface issue and does not affect the operation of the
-Linux kernel or Asterisk. The system clock on Linux kernels operates
-on UTC. UTC does not use daylight savings time.
-
- Also note that this issue is separate from the clocking of TDM
-channels, and is known to at least affect SIP registrations.
-
-* FILE DESCRIPTORS
-
- Depending on the size of your system and your configuration,
-Asterisk can consume a large number of file descriptors. In UNIX,
-file descriptors are used for more than just files on disk. File
-descriptors are also used for handling network communication
-(e.g. SIP, IAX2, or H.323 calls) and hardware access (e.g. analog and
-digital trunk hardware). Asterisk accesses many on-disk files for
-everything from configuration information to voicemail storage.
-
- Most systems limit the number of file descriptors that Asterisk can
-have open at one time. This can limit the number of simultaneous
-calls that your system can handle. For example, if the limit is set
-at 1024 (a common default value) Asterisk can handle approxiately 150
-SIP calls simultaneously. To change the number of file descriptors
-follow the instructions for your system below:
-
-== PAM-based Linux System ==
-
- If your system uses PAM (Pluggable Authentication Modules) edit
-/etc/security/limits.conf. Add these lines to the bottom of the file:
-
-root soft nofile 4096
-root hard nofile 8196
-asterisk soft nofile 4096
-asterisk hard nofile 8196
-
-(adjust the numbers to taste). You may need to reboot the system for
-these changes to take effect.
-
-== Generic UNIX System ==
-
- If there are no instructions specifically adapted to your system
-above you can try adding the command "ulimit -n 8192" to the script
-that starts Asterisk.
-
-* MORE INFORMATION
-
- See the doc directory for more documentation on various features. Again,
-please read all the configuration samples that include documentation on
-the configuration options.
-
- Finally, you may wish to visit the web site and join the mailing list if
-you're interested in getting more information.
-
- http://www.asterisk.org/support
-
- Welcome to the growing worldwide community of Asterisk users!
-
-Mark Spencer
diff --git a/1.2-netsec/README.fpm b/1.2-netsec/README.fpm
deleted file mode 100644
index ad11c4815..000000000
--- a/1.2-netsec/README.fpm
+++ /dev/null
@@ -1,8 +0,0 @@
-About Hold Music
-================
-Digium has licensed the music included with
-the Asterisk distribution From FreePlayMusic
-for use and distribution with Asterisk. It
-is licensed ONLY for use as hold music within
-an Asterisk based PBX.
-
diff --git a/1.2-netsec/SECURITY b/1.2-netsec/SECURITY
deleted file mode 100644
index 3290cba48..000000000
--- a/1.2-netsec/SECURITY
+++ /dev/null
@@ -1,67 +0,0 @@
-==== Security Notes with Asterisk ====
-
-PLEASE READ THE FOLLOWING IMPORTANT SECURITY RELATED INFORMATION.
-IMPROPER CONFIGURATION OF ASTERISK COULD ALLOW UNAUTHORIZED USE OF YOUR
-FACILITIES, POTENTIALLY INCURRING SUBSTANTIAL CHARGES.
-
-Asterisk security involves both network security (encryption, authentication)
-as well as dialplan security (authorization - who can access services in
-your pbx). If you are setting up Asterisk in production use, please make
-sure you understand the issues involved.
-
-* NETWORK SECURITY
-
-If you install Asterisk and use the "make samples" command to install
-a demonstration configuration, Asterisk will open a few ports for accepting
-VoIP calls. Check the channel configuration files for the ports and IP addresses.
-
-If you enable the manager interface in manager.conf, please make sure that
-you access manager in a safe environment or protect it with SSH or other
-VPN solutions.
-
-For all TCP/IP connections in Asterisk, you can set ACL lists that
-will permit or deny network access to Asterisk services. Please check
-the "permit" and "deny" configuration options in manager.conf and
-the VoIP channel configurations - i.e. sip.conf and iax.conf.
-
-The IAX2 protocol supports strong RSA key authentication as well as
-AES encryption of voice and signalling. The SIP channel does not
-support encryption in this version of Asterisk.
-
-* DIALPLAN SECURITY
-
-First and foremost remember this:
-
-USE THE EXTENSION CONTEXTS TO ISOLATE OUTGOING OR TOLL SERVICES FROM ANY
-INCOMING CONNECTIONS.
-
-You should consider that if any channel, incoming line, etc can enter an
-extension context that it has the capability of accessing any extension
-within that context.
-
-Therefore, you should NOT allow access to outgoing or toll services in
-contexts that are accessible (especially without a password) from incoming
-channels, be they IAX channels, FX or other trunks, or even untrusted
-stations within you network. In particular, never ever put outgoing toll
-services in the "default" context. To make things easier, you can include
-the "default" context within other private contexts by using:
-
- include => default
-
-in the appropriate section. A well designed PBX might look like this:
-
-[longdistance]
-exten => _91NXXNXXXXXX,1,Dial(Zap/g2/${EXTEN:1})
-include => local
-
-[local]
-exten => _9NXXNXXX,1,Dial(Zap/g2/${EXTEN:1})
-include => default
-
-[default]
-exten => 6123,Dial(Zap/1)
-
-
-DON'T FORGET TO TAKE THE DEMO CONTEXT OUT OF YOUR DEFAULT CONTEXT. There
-isn't really a security reason, it just will keep people from wanting to
-play with your Asterisk setup remotely.
diff --git a/1.2-netsec/UPGRADE.txt b/1.2-netsec/UPGRADE.txt
deleted file mode 100644
index 76e557773..000000000
--- a/1.2-netsec/UPGRADE.txt
+++ /dev/null
@@ -1,205 +0,0 @@
-Information for Upgrading From Previous Asterisk Releases
-=========================================================
-
-Compiling:
-
-* The Asterisk 1.2 source code now uses C language features
- supported only by 'modern' C compilers. Generally, this means GCC
- version 3.0 or higher, although some GCC 2.96 releases will also
- work. Some non-GCC compilers that support C99 and the common GCC
- extensions (including anonymous structures and unions) will also
- work. All releases of GCC 2.95 do _not_ have the requisite feature
- support; systems using that compiler will need to be upgraded to
- a more recent compiler release.
-
-Dialplan Expressions:
-
-* The dialplan expression parser (which handles $[ ... ] constructs)
- has gone through a major upgrade, but has one incompatible change:
- spaces are no longer required around expression operators, including
- string comparisons. However, you can now use quoting to keep strings
- together for comparison. For more details, please read the
- doc/README.variables file, and check over your dialplan for possible
- problems.
-
-Agents:
-
-* The default for ackcall has been changed to "no" instead of "yes"
- because of a bug which caused the "yes" behavior to generally act like
- "no". You may need to adjust the value if your agents behave
- differently than you expect with respect to acknowledgement.
-
-* The AgentCallBackLogin application now requires a second '|' before
- specifying an extension@context. This is to distinguish the options
- string from the extension, so that they do not conflict. See
- 'show application AgentCallbackLogin' for more details.
-
-Parking:
-
-* Parking behavior has changed slightly; when a parked call times out,
- Asterisk will attempt to deliver the call back to the extension that
- parked it, rather than the 's' extension. If that extension is busy
- or unavailable, the parked call will be lost.
-
-Dialing:
-
-* The Caller*ID of the outbound leg is now the extension that was
- called, rather than the Caller*ID of the inbound leg of the call. The
- "o" flag for Dial can be used to restore the original behavior if
- desired. Note that if you are looking for the originating callerid
- from the manager event, there is a new manager event "Dial" which
- provides the source and destination channels and callerid.
-
-IAX:
-
-* The naming convention for IAX channels has changed in two ways:
- 1. The call number follows a "-" rather than a "/" character.
- 2. The name of the channel has been simplified to IAX2/peer-callno,
- rather than IAX2/peer@peer-callno or even IAX2/peer@peer/callno.
-
-SIP:
-
-* The global option "port" in 1.0.X that is used to set which port to
- bind to has been changed to "bindport" to be more consistent with
- the other channel drivers and to avoid confusion with the "port"
- option for users/peers.
-
-* The "Registry" event now uses "Username" rather than "User" for
- consistency with IAX.
-
-Applications:
-
-* With the addition of dialplan functions (which operate similarly
- to variables), the SetVar application has been renamed to Set.
-
-* The CallerPres application has been removed. Use SetCallerPres
- instead. It accepts both numeric and symbolic names.
-
-* The applications GetGroupCount, GetGroupMatchCount, SetGroup, and
- CheckGroup have been deprecated in favor of functions. Here is a
- table of their replacements:
-
- GetGroupCount([groupname][@category] GROUP_COUNT([groupname][@category]) Set(GROUPCOUNT=${GROUP_COUNT()})
- GroupMatchCount(groupmatch[@category]) GROUP_MATCH_COUNT(groupmatch[@category]) Set(GROUPCOUNT=${GROUP_MATCH_COUNT(SIP/.*)})
- SetGroup(groupname[@category]) GROUP([category])=groupname Set(GROUP()=test)
- CheckGroup(max[@category]) N/A GotoIf($[ ${GROUP_COUNT()} > 5 ]?103)
-
- Note that CheckGroup does not have a direct replacement. There is
- also a new function called GROUP_LIST() which will return a space
- separated list of all of the groups set on a channel. The GROUP()
- function can also return the name of the group set on a channel when
- used in a read environment.
-
-* The applications DBGet and DBPut have been deprecated in favor of
- functions. Here is a table of their replacements:
-
- DBGet(foo=family/key) Set(foo=${DB(family/key)})
- DBPut(family/key=${foo}) Set(DB(family/key)=${foo})
-
-* The application SetLanguage has been deprecated in favor of the
- function LANGUAGE().
-
- SetLanguage(fr) Set(LANGUAGE()=fr)
-
- The LANGUAGE function can also return the currently set language:
-
- Set(MYLANG=${LANGUAGE()})
-
-* The applications AbsoluteTimeout, DigitTimeout, and ResponseTimeout
- have been deprecated in favor of the function TIMEOUT(timeouttype):
-
- AbsoluteTimeout(300) Set(TIMEOUT(absolute)=300)
- DigitTimeout(15) Set(TIMEOUT(digit)=15)
- ResponseTimeout(15) Set(TIMEOUT(response)=15)
-
- The TIMEOUT() function can also return the currently set timeouts:
-
- Set(DTIMEOUT=${TIMEOUT(digit)})
-
-* The applications SetCIDName, SetCIDNum, and SetRDNIS have been
- deprecated in favor of the CALLERID(datatype) function:
-
- SetCIDName(Joe Cool) Set(CALLERID(name)=Joe Cool)
- SetCIDNum(2025551212) Set(CALLERID(number)=2025551212)
- SetRDNIS(2024561414) Set(CALLERID(RDNIS)=2024561414)
-
-* The application Record now uses the period to separate the filename
- from the format, rather than the colon.
-
-* The application VoiceMail now supports a 'temporary' greeting for each
- mailbox. This greeting can be recorded by using option 4 in the
- 'mailbox options' menu, and 'change your password' option has been
- moved to option 5.
-
-* The application VoiceMailMain now only matches the 'default' context if
- none is specified in the arguments. (This was the previously
- documented behavior, however, we didn't follow that behavior.) The old
- behavior can be restored by setting searchcontexts=yes in voicemail.conf.
-
-Queues:
-
-* A queue is now considered empty not only if there are no members but if
- none of the members are available (e.g. agents not logged on). To
- restore the original behavior, use "leavewhenempty=strict" or
- "joinwhenempty=strict" instead of "=yes" for those options.
-
-* It is now possible to use multi-digit extensions in the exit context
- for a queue (although you should not have overlapping extensions,
- as there is no digit timeout). This means that the EXITWITHKEY event
- in queue_log can now contain a key field with more than a single
- character in it.
-
-Extensions:
-
-* By default, there is a new option called "autofallthrough" in
- extensions.conf that is set to yes. Asterisk 1.0 (and earlier)
- behavior was to wait for an extension to be dialed after there were no
- more extensions to execute. "autofallthrough" changes this behavior
- so that the call will immediately be terminated with BUSY,
- CONGESTION, or HANGUP based on Asterisk's best guess. If you are
- writing an extension for IVR, you must use the WaitExten application
- if "autofallthrough" is set to yes.
-
-AGI:
-
-* AGI scripts did not always get SIGHUP at the end, previously. That
- behavior has been fixed. If you do not want your script to terminate
- at the end of AGI being called (e.g. on a hangup) then set SIGHUP to
- be ignored within your application.
-
-* CallerID is reported with agi_callerid and agi_calleridname instead
- of a single parameter holding both.
-
-Music On Hold:
-
-* The preferred format for musiconhold.conf has changed; please see the
- sample configuration file for the new format. The existing format
- is still supported but will generate warnings when the module is loaded.
-
-chan_modem:
-
-* All the chan_modem channel drivers (aopen, bestdata and i4l) are deprecated
- in this release, and will be removed in the next major Asterisk release.
- Please migrate to chan_misdn for ISDN interfaces; there is no upgrade
- path for aopen and bestdata modem users.
-
-MeetMe:
-
-* The conference application now allows users to increase/decrease their
- speaking volume and listening volume (independently of each other and
- other users); the 'admin' and 'user' menus have changed, and new sound
- files are included with this release. However, if a user calling in
- over a Zaptel channel that does NOT have hardware DTMF detection
- increases their speaking volume, it is likely they will no longer be
- able to enter/exit the menu or make any further adjustments, as the
- software DTMF detector will not be able to recognize the DTMF coming
- from their device.
-
-GetVar Manager Action:
-
-* Previously, the behavior of the GetVar manager action reported the value
- of a variable in the following manner:
- > name: value
- This has been changed to a manner similar to the SetVar action and is now
- > Variable: name
- > Value: value
diff --git a/1.2-netsec/acl.c b/1.2-netsec/acl.c
deleted file mode 100644
index 326cdb66d..000000000
--- a/1.2-netsec/acl.c
+++ /dev/null
@@ -1,355 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Various sorts of access control
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <sys/ioctl.h>
-
-#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
-#include <fcntl.h>
-#include <net/route.h>
-#endif
-
-#if defined(SOLARIS)
-#include <sys/sockio.h>
-#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.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#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"
-#include "asterisk/compat.h"
-
-#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
-AST_MUTEX_DEFINE_STATIC(routeseq_lock);
-#endif
-
-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 = malloc(sizeof(struct ast_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 = malloc(sizeof(struct ast_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_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_log(LOG_DEBUG,
- "##### Testing %s with %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr),
- ast_inet_ntoa(iabuf2, sizeof(iabuf2), ha->netaddr));
- /* 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;
-}
-
-int ast_str2tos(const char *value, int *tos)
-{
- int fval;
- if (sscanf(value, "%i", &fval) == 1)
- *tos = fval & 0xff;
- else 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;
- return 0;
-}
-
-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/1.2-netsec/aescrypt.c b/1.2-netsec/aescrypt.c
deleted file mode 100644
index 3406b6603..000000000
--- a/1.2-netsec/aescrypt.c
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 2003, Dr Brian Gladman <brg@gladman.me.uk>, 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
-*/
-
-#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/1.2-netsec/aeskey.c b/1.2-netsec/aeskey.c
deleted file mode 100644
index ec24e6cae..000000000
--- a/1.2-netsec/aeskey.c
+++ /dev/null
@@ -1,465 +0,0 @@
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 2003, Dr Brian Gladman <brg@gladman.me.uk>, 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.
-*/
-
-#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/1.2-netsec/aesopt.h b/1.2-netsec/aesopt.h
deleted file mode 100644
index bb4f05a0b..000000000
--- a/1.2-netsec/aesopt.h
+++ /dev/null
@@ -1,1029 +0,0 @@
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 2003, Dr Brian Gladman <brg@gladman.me.uk>, 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/1.2-netsec/aestab.c b/1.2-netsec/aestab.c
deleted file mode 100644
index c84a480af..000000000
--- a/1.2-netsec/aestab.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 2003, Dr Brian Gladman <brg@gladman.me.uk>, 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/1.2-netsec/agi/DialAnMp3.agi b/1.2-netsec/agi/DialAnMp3.agi
deleted file mode 100644
index 59a54265e..000000000
--- a/1.2-netsec/agi/DialAnMp3.agi
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/usr/bin/perl
-#
-# Simple AGI application to play mp3's selected by a user both using
-# xmms and over the phone itself.
-#
-$|=1;
-while(<STDIN>) {
- chomp;
- last unless length($_);
- if (/^agi_(\w+)\:\s+(.*)$/) {
- $AGI{$1} = $2;
- }
-}
-
-print STDERR "AGI Environment Dump:\n";
-foreach $i (sort keys %AGI) {
- print STDERR " -- $i = $AGI{$i}\n";
-}
-
-dbmopen(%DIGITS, "/var/lib/asterisk/mp3list", 0644) || die("Unable to open mp3list");;
-
-sub checkresult {
- my ($res) = @_;
- my $retval;
- $tests++;
- chomp $res;
- if ($res =~ /^200/) {
- $res =~ /result=(-?[\w\*\#]+)/;
- return $1;
- } else {
- return -1;
- }
-}
-
-#print STDERR "1. Playing beep...\n";
-#print "STREAM FILE beep \"\"\n";
-#$result = <STDIN>;
-#checkresult($result);
-
-print STDERR "2. Getting song name...\n";
-print "GET DATA demo-enterkeywords\n";
-$result = <STDIN>;
-$digitstr = checkresult($result);
-if ($digitstr < 0) {
- exit(1);
-}
-$digitstr =~ s/\*/ /g;
-
-print STDERR "Resulting songname is $digitstr\n";
-@searchwords = split (/\s+/, $digitstr);
-print STDERR "Searchwords: " . join(':', @searchwords) . "\n";
-
-foreach $key (sort keys %DIGITS) {
- @words = split(/\s+/, $DIGITS{$key});
- $match = 1;
- foreach $search (@searchwords) {
- $match = 0 unless grep(/$search/, @words);
- }
- if ($match > 0) {
- print STDERR "File $key matches\n";
- # Play a beep
- print "STREAM FILE beep \"\"\n";
- system("xmms", $key);
- $result = <STDIN>;
- if (&checkresult($result) < 0) {
- exit 0;
- }
- print "EXEC MP3Player \"$key\"\n";
-# print "WAIT FOR DIGIT 60000\n";
- $result = <STDIN>;
- if (&checkresult($result) < 0) {
- exit 0;
- }
- print STDERR "Got here...\n";
- }
-}
-
-print STDERR "4. Testing 'saynumber' of $digitstr...\n";
-print "STREAM FILE demo-nomatch\"\"\n";
-$result = <STDIN>;
-checkresult($result);
-
diff --git a/1.2-netsec/agi/Makefile b/1.2-netsec/agi/Makefile
deleted file mode 100644
index 8cea3499f..000000000
--- a/1.2-netsec/agi/Makefile
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Makefile for AGI-related stuff
-#
-# Copyright (C) 1999-2005, Digium
-#
-# Mark Spencer <markster@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-AGIS=agi-test.agi eagi-test eagi-sphinx-test
-
-CFLAGS+=
-
-LIBS=
-ifeq ($(OSARCH),SunOS)
- LIBS=-lsocket -lnsl ../strcompat.o
-endif
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-all: depend $(AGIS)
-
-install: all
- mkdir -p $(DESTDIR)$(AGI_DIR)
- for x in $(AGIS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(AGI_DIR) ; done
-
-eagi-test: eagi-test.o
- $(CC) $(CFLAGS) -o eagi-test eagi-test.o $(LIBS)
-
-eagi-sphinx-test: eagi-sphinx-test.o
- $(CC) $(CFLAGS) -o eagi-sphinx-test eagi-sphinx-test.o $(LIBS)
-
-clean:
- rm -f *.so *.o look .depend eagi-test eagi-sphinx-test
-
-%.so : %.o
- $(CC) -shared -Xlinker -x -o $@ $<
-
-ifneq ($(wildcard .depend),)
-include .depend
-endif
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
diff --git a/1.2-netsec/agi/agi-test.agi b/1.2-netsec/agi/agi-test.agi
deleted file mode 100644
index 4fc36eda8..000000000
--- a/1.2-netsec/agi/agi-test.agi
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/usr/bin/perl
-use strict;
-
-$|=1;
-
-# Setup some variables
-my %AGI; my $tests = 0; my $fail = 0; my $pass = 0;
-
-while(<STDIN>) {
- chomp;
- last unless length($_);
- if (/^agi_(\w+)\:\s+(.*)$/) {
- $AGI{$1} = $2;
- }
-}
-
-print STDERR "AGI Environment Dump:\n";
-foreach my $i (sort keys %AGI) {
- print STDERR " -- $i = $AGI{$i}\n";
-}
-
-sub checkresult {
- my ($res) = @_;
- my $retval;
- $tests++;
- chomp $res;
- if ($res =~ /^200/) {
- $res =~ /result=(-?\d+)/;
- if (!length($1)) {
- print STDERR "FAIL ($res)\n";
- $fail++;
- } else {
- print STDERR "PASS ($1)\n";
- $pass++;
- }
- } else {
- print STDERR "FAIL (unexpected result '$res')\n";
- $fail++;
- }
-}
-
-print STDERR "1. Testing 'sendfile'...";
-print "STREAM FILE beep \"\"\n";
-my $result = <STDIN>;
-&checkresult($result);
-
-print STDERR "2. Testing 'sendtext'...";
-print "SEND TEXT \"hello world\"\n";
-my $result = <STDIN>;
-&checkresult($result);
-
-print STDERR "3. Testing 'sendimage'...";
-print "SEND IMAGE asterisk-image\n";
-my $result = <STDIN>;
-&checkresult($result);
-
-print STDERR "4. Testing 'saynumber'...";
-print "SAY NUMBER 192837465 \"\"\n";
-my $result = <STDIN>;
-&checkresult($result);
-
-print STDERR "5. Testing 'waitdtmf'...";
-print "WAIT FOR DIGIT 1000\n";
-my $result = <STDIN>;
-&checkresult($result);
-
-print STDERR "6. Testing 'record'...";
-print "RECORD FILE testagi gsm 1234 3000\n";
-my $result = <STDIN>;
-&checkresult($result);
-
-print STDERR "6a. Testing 'record' playback...";
-print "STREAM FILE testagi \"\"\n";
-my $result = <STDIN>;
-&checkresult($result);
-
-print STDERR "================== Complete ======================\n";
-print STDERR "$tests tests completed, $pass passed, $fail failed\n";
-print STDERR "==================================================\n";
diff --git a/1.2-netsec/agi/eagi-sphinx-test.c b/1.2-netsec/agi/eagi-sphinx-test.c
deleted file mode 100644
index 95c47c909..000000000
--- a/1.2-netsec/agi/eagi-sphinx-test.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Extended AGI test application
- *
- * This code is released into public domain
- * without any warranty of any kind.
- *
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/select.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <asterisk/compat.h>
-
-#define AUDIO_FILENO (STDERR_FILENO + 1)
-
-#define SPHINX_HOST "192.168.1.108"
-#define SPHINX_PORT 3460
-
-static int sphinx_sock = -1;
-
-static int connect_sphinx(void)
-{
- struct hostent *hp;
- struct sockaddr_in sin;
- int res;
- hp = gethostbyname(SPHINX_HOST);
- if (!hp) {
- fprintf(stderr, "Unable to resolve '%s'\n", SPHINX_HOST);
- return -1;
- }
- sphinx_sock = socket(PF_INET, SOCK_STREAM, 0);
- if (sphinx_sock < 0) {
- fprintf(stderr, "Unable to allocate socket: %s\n", strerror(errno));
- return -1;
- }
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(SPHINX_PORT);
- memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
- if (connect(sphinx_sock, (struct sockaddr *)&sin, sizeof(sin))) {
- fprintf(stderr, "Unable to connect on socket: %s\n", strerror(errno));
- close(sphinx_sock);
- sphinx_sock = -1;
- return -1;
- }
- res = fcntl(sphinx_sock, F_GETFL);
- if ((res < 0) || (fcntl(sphinx_sock, F_SETFL, res | O_NONBLOCK) < 0)) {
- fprintf(stderr, "Unable to set flags on socket: %s\n", strerror(errno));
- close(sphinx_sock);
- sphinx_sock = -1;
- return -1;
- }
- return 0;
-}
-
-static int read_environment(void)
-{
- char buf[256];
- char *val;
- /* Read environment */
- for(;;) {
- fgets(buf, sizeof(buf), stdin);
- if (feof(stdin))
- return -1;
- buf[strlen(buf) - 1] = '\0';
- /* Check for end of environment */
- if (!strlen(buf))
- return 0;
- val = strchr(buf, ':');
- if (!val) {
- fprintf(stderr, "Invalid environment: '%s'\n", buf);
- return -1;
- }
- *val = '\0';
- val++;
- val++;
- /* Skip space */
- fprintf(stderr, "Environment: '%s' is '%s'\n", buf, val);
-
- /* Load into normal environment */
- setenv(buf, val, 1);
-
- }
- /* Never reached */
- return 0;
-}
-
-static char *wait_result(void)
-{
- fd_set fds;
- int res;
- int max;
- static char astresp[256];
- static char sphinxresp[256];
- char audiobuf[4096];
- for (;;) {
- FD_ZERO(&fds);
- FD_SET(STDIN_FILENO, &fds);
- FD_SET(AUDIO_FILENO, &fds);
- max = AUDIO_FILENO;
- if (sphinx_sock > -1) {
- FD_SET(sphinx_sock, &fds);
- if (sphinx_sock > max)
- max = sphinx_sock;
- }
- /* Wait for *some* sort of I/O */
- res = select(max + 1, &fds, NULL, NULL, NULL);
- if (res < 0) {
- fprintf(stderr, "Error in select: %s\n", strerror(errno));
- return NULL;
- }
- if (FD_ISSET(STDIN_FILENO, &fds)) {
- fgets(astresp, sizeof(astresp), stdin);
- if (feof(stdin)) {
- fprintf(stderr, "Got hungup on apparently\n");
- return NULL;
- }
- astresp[strlen(astresp) - 1] = '\0';
- fprintf(stderr, "Ooh, got a response from Asterisk: '%s'\n", astresp);
- return astresp;
- }
- if (FD_ISSET(AUDIO_FILENO, &fds)) {
- res = read(AUDIO_FILENO, audiobuf, sizeof(audiobuf));
- if (res > 0) {
- if (sphinx_sock > -1)
- write(sphinx_sock, audiobuf, res);
- }
- }
- if ((sphinx_sock > -1) && FD_ISSET(sphinx_sock, &fds)) {
- res = read(sphinx_sock, sphinxresp, sizeof(sphinxresp));
- if (res > 0) {
- fprintf(stderr, "Oooh, Sphinx found a token: '%s'\n", sphinxresp);
- return sphinxresp;
- } else if (res == 0) {
- fprintf(stderr, "Hrm, lost sphinx, guess we're on our own\n");
- close(sphinx_sock);
- sphinx_sock = -1;
- }
- }
- }
-
-}
-
-static char *run_command(char *command)
-{
- fprintf(stdout, "%s\n", command);
- return wait_result();
-}
-
-static int run_script(void)
-{
- char *res;
- res = run_command("STREAM FILE demo-enterkeywords 0123456789*#");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "1. Result is '%s'\n", res);
- res = run_command("STREAM FILE demo-nomatch 0123456789*#");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "2. Result is '%s'\n", res);
- res = run_command("SAY NUMBER 23452345 0123456789*#");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "3. Result is '%s'\n", res);
- res = run_command("GET DATA demo-enterkeywords");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "4. Result is '%s'\n", res);
- res = run_command("STREAM FILE auth-thankyou \"\"");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "5. Result is '%s'\n", res);
- return 0;
-}
-
-int main(int argc, char *argv[])
-{
- char *tmp;
- int ver = 0;
- int subver = 0;
- /* Setup stdin/stdout for line buffering */
- setlinebuf(stdin);
- setlinebuf(stdout);
- if (read_environment()) {
- fprintf(stderr, "Failed to read environment: %s\n", strerror(errno));
- exit(1);
- }
- connect_sphinx();
- tmp = getenv("agi_enhanced");
- if (tmp) {
- if (sscanf(tmp, "%d.%d", &ver, &subver) != 2)
- ver = 0;
- }
- if (ver < 1) {
- fprintf(stderr, "No enhanced AGI services available. Use EAGI, not AGI\n");
- exit(1);
- }
- if (run_script())
- return -1;
- exit(0);
-}
diff --git a/1.2-netsec/agi/eagi-test.c b/1.2-netsec/agi/eagi-test.c
deleted file mode 100644
index 5ba28f9c6..000000000
--- a/1.2-netsec/agi/eagi-test.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Extended AGI test application
- *
- * This code is released into the public domain
- * with no warranty of any kind
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/select.h>
-#include <asterisk/compat.h>
-
-#define AUDIO_FILENO (STDERR_FILENO + 1)
-
-static int read_environment(void)
-{
- char buf[256];
- char *val;
- /* Read environment */
- for(;;) {
- fgets(buf, sizeof(buf), stdin);
- if (feof(stdin))
- return -1;
- buf[strlen(buf) - 1] = '\0';
- /* Check for end of environment */
- if (!strlen(buf))
- return 0;
- val = strchr(buf, ':');
- if (!val) {
- fprintf(stderr, "Invalid environment: '%s'\n", buf);
- return -1;
- }
- *val = '\0';
- val++;
- val++;
- /* Skip space */
- fprintf(stderr, "Environment: '%s' is '%s'\n", buf, val);
-
- /* Load into normal environment */
- setenv(buf, val, 1);
-
- }
- /* Never reached */
- return 0;
-}
-
-static char *wait_result(void)
-{
- fd_set fds;
- int res;
- int bytes = 0;
- static char astresp[256];
- char audiobuf[4096];
- for (;;) {
- FD_ZERO(&fds);
- FD_SET(STDIN_FILENO, &fds);
- FD_SET(AUDIO_FILENO, &fds);
- /* Wait for *some* sort of I/O */
- res = select(AUDIO_FILENO + 1, &fds, NULL, NULL, NULL);
- if (res < 0) {
- fprintf(stderr, "Error in select: %s\n", strerror(errno));
- return NULL;
- }
- if (FD_ISSET(STDIN_FILENO, &fds)) {
- fgets(astresp, sizeof(astresp), stdin);
- if (feof(stdin)) {
- fprintf(stderr, "Got hungup on apparently\n");
- return NULL;
- }
- astresp[strlen(astresp) - 1] = '\0';
- fprintf(stderr, "Ooh, got a response from Asterisk: '%s'\n", astresp);
- return astresp;
- }
- if (FD_ISSET(AUDIO_FILENO, &fds)) {
- res = read(AUDIO_FILENO, audiobuf, sizeof(audiobuf));
- if (res > 0) {
- /* XXX Process the audio with sphinx here XXX */
-#if 0
- fprintf(stderr, "Got %d/%d bytes of audio\n", res, bytes);
-#endif
- bytes += res;
- /* Prentend we detected some audio after 3 seconds */
- if (bytes > 16000 * 3) {
- return "Sample Message";
- bytes = 0;
- }
- }
- }
- }
-
-}
-
-static char *run_command(char *command)
-{
- fprintf(stdout, "%s\n", command);
- return wait_result();
-}
-
-static int run_script(void)
-{
- char *res;
- res = run_command("STREAM FILE demo-enterkeywords 0123456789*#");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "1. Result is '%s'\n", res);
- res = run_command("STREAM FILE demo-nomatch 0123456789*#");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "2. Result is '%s'\n", res);
- res = run_command("SAY NUMBER 23452345 0123456789*#");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "3. Result is '%s'\n", res);
- res = run_command("GET DATA demo-enterkeywords");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "4. Result is '%s'\n", res);
- res = run_command("STREAM FILE auth-thankyou \"\"");
- if (!res) {
- fprintf(stderr, "Failed to execute command\n");
- return -1;
- }
- fprintf(stderr, "5. Result is '%s'\n", res);
- return 0;
-}
-
-int main(int argc, char *argv[])
-{
- char *tmp;
- int ver = 0;
- int subver = 0;
- /* Setup stdin/stdout for line buffering */
- setlinebuf(stdin);
- setlinebuf(stdout);
- if (read_environment()) {
- fprintf(stderr, "Failed to read environment: %s\n", strerror(errno));
- exit(1);
- }
- tmp = getenv("agi_enhanced");
- if (tmp) {
- if (sscanf(tmp, "%d.%d", &ver, &subver) != 2)
- ver = 0;
- }
- if (ver < 1) {
- fprintf(stderr, "No enhanced AGI services available. Use EAGI, not AGI\n");
- exit(1);
- }
- if (run_script())
- return -1;
- exit(0);
-}
diff --git a/1.2-netsec/agi/fastagi-test b/1.2-netsec/agi/fastagi-test
deleted file mode 100644
index d3f13cf6b..000000000
--- a/1.2-netsec/agi/fastagi-test
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use Socket;
-use Carp;
-use IO::Handle;
-
-my $port = 4573;
-
-$|=1;
-
-# Setup some variables
-my %AGI; my $tests = 0; my $fail = 0; my $pass = 0;
-
-sub checkresult {
- my ($res) = @_;
- my $retval;
- $tests++;
- chomp $res;
- if ($res =~ /^200/) {
- $res =~ /result=(-?\d+)/;
- if (!length($1)) {
- print STDERR "FAIL ($res)\n";
- $fail++;
- } else {
- print STDERR "PASS ($1)\n";
- $pass++;
- }
- } else {
- print STDERR "FAIL (unexpected result '$res')\n";
- $fail++;
- }
-}
-
-socket(SERVER, PF_INET, SOCK_STREAM, 0);
-setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, pack("l", 1));
-bind(SERVER, sockaddr_in($port, INADDR_ANY)) || die("can't bind\n");
-listen(SERVER, SOMAXCONN);
-
-for(;;) {
- my $raddr = accept(CLIENT, SERVER);
- my ($s, $p) = sockaddr_in($raddr);
- CLIENT->autoflush(1);
- while(<CLIENT>) {
- chomp;
- last unless length($_);
- if (/^agi_(\w+)\:\s+(.*)$/) {
- $AGI{$1} = $2;
- }
- }
- print STDERR "AGI Environment Dump from $s:$p --\n";
- foreach my $i (sort keys %AGI) {
- print STDERR " -- $i = $AGI{$i}\n";
- }
-
- print STDERR "1. Testing 'sendfile'...";
- print CLIENT "STREAM FILE beep \"\"\n";
- my $result = <CLIENT>;
- &checkresult($result);
-
- print STDERR "2. Testing 'sendtext'...";
- print CLIENT "SEND TEXT \"hello world\"\n";
- my $result = <CLIENT>;
- &checkresult($result);
-
- print STDERR "3. Testing 'sendimage'...";
- print CLIENT "SEND IMAGE asterisk-image\n";
- my $result = <CLIENT>;
- &checkresult($result);
-
- print STDERR "4. Testing 'saynumber'...";
- print CLIENT "SAY NUMBER 192837465 \"\"\n";
- my $result = <CLIENT>;
- &checkresult($result);
-
- print STDERR "5. Testing 'waitdtmf'...";
- print CLIENT "WAIT FOR DIGIT 1000\n";
- my $result = <CLIENT>;
- &checkresult($result);
-
- print STDERR "6. Testing 'record'...";
- print CLIENT "RECORD FILE testagi gsm 1234 3000\n";
- my $result = <CLIENT>;
- &checkresult($result);
-
- print STDERR "6a. Testing 'record' playback...";
- print CLIENT "STREAM FILE testagi \"\"\n";
- my $result = <CLIENT>;
- &checkresult($result);
- close(CLIENT);
- print STDERR "================== Complete ======================\n";
- print STDERR "$tests tests completed, $pass passed, $fail failed\n";
- print STDERR "==================================================\n";
-}
-
diff --git a/1.2-netsec/agi/numeralize b/1.2-netsec/agi/numeralize
deleted file mode 100644
index 5ca51913d..000000000
--- a/1.2-netsec/agi/numeralize
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/perl
-#
-# Build a database linking filenames to their numerical representations
-# using a keypad for the DialAnMp3 application
-#
-
-$mp3dir="/usr/media/mpeg3";
-
-dbmopen(%DIGITS, "/var/lib/asterisk/mp3list", 0644) || die("Unable to open mp3list");;
-sub process_dir {
- my ($dir) = @_;
- my $file;
- my $digits;
- my @entries;
- opendir(DIR, $dir);
- @entries = readdir(DIR);
- closedir(DIR);
- foreach $_ (@entries) {
- if (!/^\./) {
- $file = "$dir/$_";
- if (-d "$file") {
- process_dir("$file");
- } else {
- $digits = $_;
- $digits =~ s/[^ \w]+//g;
- $digits =~ s/\_/ /g;
- $digits =~ tr/[a-z]/[A-Z]/;
- $digits =~ tr/[A-C]/2/;
- $digits =~ tr/[D-F]/3/;
- $digits =~ tr/[G-I]/4/;
- $digits =~ tr/[J-L]/5/;
- $digits =~ tr/[M-O]/6/;
- $digits =~ tr/[P-S]/7/;
- $digits =~ tr/[T-V]/8/;
- $digits =~ tr/[W-Z]/9/;
- $digits =~ s/\s+/ /;
- print "File: $file, digits: $digits\n";
- $DIGITS{$file} = $digits;
- }
- }
- }
-}
-
-process_dir($mp3dir);
diff --git a/1.2-netsec/alaw.c b/1.2-netsec/alaw.c
deleted file mode 100644
index a85c89f3d..000000000
--- a/1.2-netsec/alaw.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief u-Law to Signed linear conversion
- *
- */
-
-#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/1.2-netsec/app.c b/1.2-netsec/app.c
deleted file mode 100644
index b7bc31fe1..000000000
--- a/1.2-netsec/app.c
+++ /dev/null
@@ -1,1558 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Convenient Application Routines
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <regex.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#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-initilized** 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); strlen(collect) < 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) {
- if (ast_exists_extension(chan, context, collect, 1, chan->cid.cid_num))
- res = 1;
- else
- res = 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;
-}
-
-int ast_app_getvoice(struct ast_channel *c, char *dest, char *dstfmt, char *prompt, int silence, int maxsec)
-{
- int res;
- struct ast_filestream *writer;
- int rfmt;
- int totalms=0, total;
-
- struct ast_frame *f;
- struct ast_dsp *sildet;
- /* Play prompt if requested */
- if (prompt) {
- res = ast_streamfile(c, prompt, c->language);
- if (res < 0)
- return res;
- res = ast_waitstream(c,"");
- if (res < 0)
- return res;
- }
- rfmt = c->readformat;
- res = ast_set_read_format(c, AST_FORMAT_SLINEAR);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
- return -1;
- }
- sildet = ast_dsp_new();
- if (!sildet) {
- ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
- return -1;
- }
- writer = ast_writefile(dest, dstfmt, "Voice file", 0, 0, 0666);
- if (!writer) {
- ast_log(LOG_WARNING, "Unable to open file '%s' in format '%s' for writing\n", dest, dstfmt);
- ast_dsp_free(sildet);
- return -1;
- }
- for(;;) {
- if ((res = ast_waitfor(c, 2000)) < 0) {
- ast_log(LOG_NOTICE, "Waitfor failed while recording file '%s' format '%s'\n", dest, dstfmt);
- break;
- }
- if (res) {
- f = ast_read(c);
- if (!f) {
- ast_log(LOG_NOTICE, "Hungup while recording file '%s' format '%s'\n", dest, dstfmt);
- break;
- }
- if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) {
- /* Ended happily with DTMF */
- ast_frfree(f);
- break;
- } else if (f->frametype == AST_FRAME_VOICE) {
- ast_dsp_silence(sildet, f, &total);
- if (total > silence) {
- /* Ended happily with silence */
- ast_frfree(f);
- break;
- }
- totalms += f->samples / 8;
- if (totalms > maxsec * 1000) {
- /* Ended happily with too much stuff */
- ast_log(LOG_NOTICE, "Constraining voice on '%s' to %d seconds\n", c->name, maxsec);
- ast_frfree(f);
- break;
- }
- res = ast_writestream(writer, f);
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to write to stream at %s!\n", dest);
- ast_frfree(f);
- break;
- }
-
- }
- ast_frfree(f);
- }
- }
- res = ast_set_read_format(c, rfmt);
- if (res)
- ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", c->name);
- ast_dsp_free(sildet);
- ast_closestream(writer);
- return 0;
-}
-
-static int (*ast_has_voicemail_func)(const char *mailbox, const char *folder) = NULL;
-static int (*ast_messagecount_func)(const char *mailbox, int *newmsgs, int *oldmsgs) = NULL;
-
-void ast_install_vm_functions(int (*has_voicemail_func)(const char *mailbox, const char *folder),
- int (*messagecount_func)(const char *mailbox, int *newmsgs, int *oldmsgs))
-{
- ast_has_voicemail_func = has_voicemail_func;
- ast_messagecount_func = messagecount_func;
-}
-
-void ast_uninstall_vm_functions(void)
-{
- ast_has_voicemail_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_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
-{
- static int warned = 0;
- if (newmsgs)
- *newmsgs = 0;
- if (oldmsgs)
- *oldmsgs = 0;
- if (ast_messagecount_func)
- return ast_messagecount_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_dtmf_stream(struct ast_channel *chan,struct ast_channel *peer,char *digits,int between)
-{
- char *ptr;
- int res = 0;
- struct ast_frame f;
- if (!between)
- between = 100;
-
- if (peer)
- res = ast_autoservice_start(peer);
-
- if (!res) {
- res = ast_waitfor(chan,100);
- if (res > -1) {
- for (ptr=digits; *ptr; ptr++) {
- if (*ptr == 'w') {
- res = ast_safe_sleep(chan, 500);
- if (res)
- break;
- continue;
- }
- memset(&f, 0, sizeof(f));
- f.frametype = AST_FRAME_DTMF;
- f.subclass = *ptr;
- f.src = "ast_dtmf_stream";
- if (strchr("0123456789*#abcdABCD",*ptr)==NULL) {
- ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n",*ptr);
- } else {
- res = ast_write(chan, &f);
- if (res)
- break;
- /* pause between digits */
- res = ast_safe_sleep(chan,between);
- if (res)
- break;
- }
- }
- }
- 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_VAR_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;
- }
- }
- lin = malloc(sizeof(struct linear_state));
- if (lin) {
- memset(lin, 0, 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;
-
-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)
-{
- int d;
- char *fmts;
- char comment[256];
- int x, fmtcnt=1, res=-1,outmsg=0;
- struct ast_frame *f;
- 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 dspsilence = 0;
- int gotsilence = 0; /* did we timeout for silence? */
- int rfmt=0;
- struct ast_silence_generator *silgen = NULL;
-
- 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 : "<None>", recordfile, fmt);
- snprintf(comment,sizeof(comment),"Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name);
-
- if (playfile) {
- d = ast_play_and_wait(chan, playfile);
- if (d > -1)
- d = ast_streamfile(chan, "beep",chan->language);
- if (!d)
- d = ast_waitstream(chan,"");
- if (d < 0)
- return -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);
- }
-
- time(&start);
- end=start; /* 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(recordfile, sfmt[x], comment, O_TRUNC, 0, 0700);
- ast_verbose( VERBOSE_PREFIX_3 "x=%d, open writing: %s format: %s, %p\n", x, 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;
- }
- }
-
- /* Request a video update */
- ast_indicate(chan, AST_CONTROL_VIDUPDATE);
-
- if (option_transmit_silence_during_record)
- 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 # or get a hangup */
- f = NULL;
- 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++) {
- res = ast_writestream(others[x], f);
- }
-
- /* Silence Detection */
- if (maxsilence > 0) {
- 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);
- ast_frfree(f);
- gotsilence = 1;
- outmsg=2;
- break;
- }
- }
- /* Exit on any error */
- if (res) {
- ast_log(LOG_WARNING, "Error writing frame\n");
- ast_frfree(f);
- break;
- }
- } else if (f->frametype == AST_FRAME_VIDEO) {
- /* Write only once */
- ast_writestream(others[0], f);
- } else if (f->frametype == AST_FRAME_DTMF) {
- if (f->subclass == '#') {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "User ended message by pressing %c\n", f->subclass);
- res = '#';
- outmsg = 2;
- ast_frfree(f);
- break;
- }
- if (f->subclass == '0') {
- /* Check for a '0' during message recording also, in case caller wants operator */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "User cancelled by pressing %c\n", f->subclass);
- res = '0';
- outmsg = 0;
- ast_frfree(f);
- break;
- }
- }
- if (maxtime) {
- time(&end);
- if (maxtime < (end - start)) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Took too long, cutting it short...\n");
- outmsg = 2;
- res = 't';
- ast_frfree(f);
- break;
- }
- }
- ast_frfree(f);
- }
- if (end == start) time(&end);
- if (!f) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "User hung up\n");
- res = -1;
- outmsg=1;
- }
- } else {
- ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]);
- }
-
- if (silgen)
- ast_channel_stop_silence_generator(chan, silgen);
-
- *duration = end - start;
-
- for (x=0;x<fmtcnt;x++) {
- if (!others[x])
- break;
- if (res > 0) {
- if (totalsilence)
- ast_stream_rewind(others[x], totalsilence-200);
- else
- ast_stream_rewind(others[x], 200);
- }
- ast_truncstream(others[x]);
- ast_closestream(others[x]);
- }
- if (rfmt) {
- if (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 > 1) {
- /* Let them know recording is stopped */
- if(!ast_streamfile(chan, "auth-thankyou", chan->language))
- ast_waitstream(chan, "");
- }
- if (sildet)
- ast_dsp_free(sildet);
- return res;
-}
-
-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)
-{
- int d = 0;
- char *fmts;
- char comment[256];
- int x, fmtcnt=1, res=-1,outmsg=0;
- struct ast_frame *f;
- struct ast_filestream *others[MAX_OTHER_FORMATS];
- struct ast_filestream *realfiles[MAX_OTHER_FORMATS];
- char *sfmt[MAX_OTHER_FORMATS];
- char *stringp=NULL;
- time_t start, end;
- struct ast_dsp *sildet; /* silence detector dsp */
- int totalsilence = 0;
- int dspsilence = 0;
- int gotsilence = 0; /* did we timeout for silence? */
- int rfmt=0;
- 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_prepend called without duration pointer\n");
- return -1;
- }
-
- ast_log(LOG_DEBUG,"play_and_prepend: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt);
- snprintf(comment,sizeof(comment),"Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name);
-
- if (playfile || beep) {
- if (!beep)
- d = ast_play_and_wait(chan, playfile);
- if (d > -1)
- d = ast_streamfile(chan, "beep",chan->language);
- if (!d)
- d = ast_waitstream(chan,"");
- if (d < 0)
- return -1;
- }
- 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);
- }
-
- time(&start);
- end=start; /* 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(prependfile, sfmt[x], comment, O_TRUNC, 0, 0700);
- ast_verbose( VERBOSE_PREFIX_3 "x=%d, open writing: %s format: %s, %p\n", x, prependfile, sfmt[x], others[x]);
- if (!others[x]) {
- break;
- }
- }
-
- 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);
-
- if (maxsilence > 0) {
- 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 (x == fmtcnt) {
- /* Loop forever, writing the packets we read to the writer(s), until
- we read a # or get a hangup */
- f = NULL;
- 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 (!others[x])
- break;
- res = ast_writestream(others[x], f);
- }
-
- /* Silence Detection */
- if (maxsilence > 0) {
- 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);
- ast_frfree(f);
- gotsilence = 1;
- outmsg=2;
- break;
- }
- }
- /* Exit on any error */
- if (res) {
- ast_log(LOG_WARNING, "Error writing frame\n");
- ast_frfree(f);
- break;
- }
- } else if (f->frametype == AST_FRAME_VIDEO) {
- /* Write only once */
- ast_writestream(others[0], f);
- } else if (f->frametype == AST_FRAME_DTMF) {
- /* 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;
- ast_frfree(f);
- break;
- }
- if (maxtime) {
- time(&end);
- if (maxtime < (end - start)) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Took too long, cutting it short...\n");
- res = 't';
- outmsg=2;
- ast_frfree(f);
- break;
- }
- }
- ast_frfree(f);
- }
- if (end == start) time(&end);
- if (!f) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "User hung up\n");
- res = -1;
- outmsg=1;
-#if 0
- /* delete all the prepend files */
- for (x=0;x<fmtcnt;x++) {
- if (!others[x])
- break;
- ast_closestream(others[x]);
- ast_filedelete(prependfile, sfmt[x]);
- }
-#endif
- }
- } else {
- ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", prependfile, sfmt[x]);
- }
- ast_dsp_free(sildet);
- *duration = end - start;
-#if 0
- if (outmsg > 1) {
-#else
- if (outmsg) {
-#endif
- 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;
- if (totalsilence)
- ast_stream_rewind(others[x], totalsilence-200);
- else
- ast_stream_rewind(others[x], 200);
- ast_truncstream(others[x]);
- /* add the original file too */
- while ((fr = ast_readframe(realfiles[x]))) {
- ast_writestream(others[x],fr);
- }
- ast_closestream(others[x]);
- ast_closestream(realfiles[x]);
- ast_filerename(prependfile, recordfile, sfmt[x]);
-#if 0
- ast_verbose("Recording Format: sfmts=%s, prependfile %s, recordfile %s\n", sfmt[x],prependfile,recordfile);
-#endif
- ast_filedelete(prependfile, sfmt[x]);
- }
- }
- if (rfmt) {
- if (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) {
- if (outmsg > 1) {
- /* Let them know it worked */
- ast_streamfile(chan, "auth-thankyou", chan->language);
- ast_waitstream(chan, "");
- }
- }
- return res;
-}
-
-/* Channel group core functions */
-
-int ast_app_group_split_group(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, 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(char *group, char *category)
-{
- struct ast_channel *chan;
- int count = 0;
- char *test;
- char cat[80];
- char *s;
-
- if (ast_strlen_zero(group))
- return 0;
-
- s = (!ast_strlen_zero(category)) ? 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_mutex_unlock(&chan->lock);
- }
-
- return count;
-}
-
-int ast_app_group_match_get_count(char *groupmatch, char *category)
-{
- regex_t regexbuf;
- struct ast_channel *chan;
- int count = 0;
- char *test;
- char cat[80];
- char *s;
-
- if (ast_strlen_zero(groupmatch))
- return 0;
-
- /* if regex compilation fails, return zero matches */
- if (regcomp(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
- return 0;
-
- s = (!ast_strlen_zero(category)) ? 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(&regexbuf, test, 0, NULL, 0))
- count++;
- ast_mutex_unlock(&chan->lock);
- }
-
- regfree(&regexbuf);
-
- return count;
-}
-
-unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen)
-{
- int argc;
- char *scan;
- int paren = 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) && !paren) {
- *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;
- time_t start;
-
- s = alloca(strlen(path) + 10);
- fs = alloca(strlen(path) + 20);
-
- if (!fs || !s) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- return AST_LOCK_FAILURE;
- }
-
- snprintf(fs, strlen(path) + 19, "%s/.lock-%08x", path, rand());
- fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, 0600);
- if (fd < 0) {
- fprintf(stderr, "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);
- time(&start);
- while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5))
- usleep(1);
- if (res) {
- ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno));
- return AST_LOCK_TIMEOUT;
- } else {
- unlink(fs);
- ast_log(LOG_DEBUG, "Locked path '%s'\n", path);
- return AST_LOCK_SUCCESS;
- }
-}
-
-int ast_unlock_path(const char *path)
-{
- char *s;
- s = alloca(strlen(path) + 10);
- if (!s)
- return -1;
- snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
- ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path);
- return unlink(s);
-}
-
-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_streamfile(chan, "vm-msgsaved", chan->language);
- ast_waitstream(chan, "");
- cmd = 't';
- return res;
- }
- case '2':
- /* Review */
- ast_verbose(VERBOSE_PREFIX_3 "Reviewing the recording\n");
- ast_streamfile(chan, recordfile, chan->language);
- cmd = ast_waitstream(chan, 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_streamfile(chan, (char *)option->adata, chan->language);
- if (!res) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- } else {
- ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata);
- res = 0;
- }
- return res;
- case AST_ACTION_PLAYBACK:
- res = ast_streamfile(chan, (char *)option->adata, chan->language);
- if (!res) {
- res = ast_waitstream(chan, "");
- } else {
- 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);
- if (c) {
- while((n = strsep(&c, ";")))
- if ((res = ast_streamfile(chan, n, chan->language)) || (res = ast_waitstream(chan, (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;
- res = ast_ivr_menu_run_internal(chan, menu, cbdata);
- /* Hide internal coding */
- if (res > 0)
- res = 0;
- return 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;
- }
- output=(char *)malloc(count);
- if (output) {
- 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;
- }
- } else
- ast_log(LOG_WARNING, "Out of memory!\n");
- 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;
- ast_set_flag(flags, options[curarg].flag);
- argloc = options[curarg].arg_index;
- if (*s == '(') {
- /* Has argument */
- arg = ++s;
- while (*s && (*s != ')'))
- 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/1.2-netsec/apps/Makefile b/1.2-netsec/apps/Makefile
deleted file mode 100644
index ca7f86e7b..000000000
--- a/1.2-netsec/apps/Makefile
+++ /dev/null
@@ -1,133 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Makefile for PBX applications
-#
-# Copyright (C) 1999-2005, Digium
-#
-# Mark Spencer <markster@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-APPS=app_dial.so app_playback.so app_voicemail.so app_directory.so app_mp3.so\
- app_system.so app_echo.so app_record.so app_image.so app_url.so app_disa.so \
- app_adsiprog.so app_getcpeid.so app_milliwatt.so \
- app_zapateller.so app_setcallerid.so app_festival.so \
- app_queue.so app_senddtmf.so app_parkandannounce.so \
- app_setcidname.so app_lookupcidname.so app_macro.so \
- app_authenticate.so app_softhangup.so app_lookupblacklist.so \
- app_waitforring.so app_privacy.so app_db.so app_chanisavail.so \
- app_enumlookup.so app_transfer.so app_setcidnum.so app_cdr.so \
- app_hasnewvoicemail.so app_sayunixtime.so app_cut.so app_read.so \
- app_setcdruserfield.so app_random.so app_ices.so app_eval.so \
- app_nbscat.so app_sendtext.so app_exec.so \
- app_groupcount.so app_txtcidname.so app_controlplayback.so \
- app_talkdetect.so app_alarmreceiver.so app_userevent.so app_verbose.so \
- app_test.so app_forkcdr.so app_math.so app_realtime.so \
- app_dumpchan.so app_waitforsilence.so app_while.so app_setrdnis.so \
- app_md5.so app_readfile.so app_chanspy.so app_settransfercapability.so \
- app_dictate.so app_externalivr.so app_directed_pickup.so \
- app_mixmonitor.so app_stack.so
-
-#
-# Obsolete things...
-#
-#APPS+=app_sql_postgres.so
-#APPS+=app_sql_odbc.so
-
-#
-# Experimental things
-#
-#APPS+=app_ivrdemo.so
-#APPS+=app_skel.so
-#APPS+=app_rpt.so
-
-ifndef WITHOUT_ZAPTEL
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/linux/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/zaptel.h),)
- APPS+=app_zapras.so app_meetme.so app_flash.so app_zapbarge.so app_zapscan.so app_page.so
-endif
-endif # WITHOUT_ZAPTEL
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/osp/osp.h $(CROSS_COMPILE_TARGET)/usr/include/osp/osp.h),)
-APPS+=app_osplookup.so
-endif
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
-CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-CURLLIBS=$(shell $(CROSS_COMPILE_BIN)curl-config --libs)
-ifneq ($(shell if [[ 0x`$(CROSS_COMPILE_BIN)curl-config --vernum` -ge 0x70907 ]]; then echo "OK" ; fi),)
- ifneq (${CURLLIBS},)
- APPS+=app_curl.so
- endif
-endif
-
-ifeq (${OSARCH},CYGWIN)
-CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
-CYGSOLIB=-L.. -L. -L../res -lasterisk.dll -lres_features.so -lres_adsi.so -lres_monitor.so
-else
-CFLAGS+=-fPIC
-APPS+=app_sms.so
-endif
-
-#
-# If you have UnixODBC you can use ODBC voicemail
-# storage
-#
-# Uncomment to use ODBC storage
-#CFLAGS+=-DUSE_ODBC_STORAGE
-# Uncomment for extended ODBC voicemail storage
-#CFLAGS+=-DEXTENDED_ODBC_STORAGE
-# See doc/README.odbcstorage for more information
-
-all: $(APPS)
-
-clean:
- rm -f *.so *.o look .depend
-
-%.so : %.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
-
-app_rpt.so : app_rpt.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -ltonezone
-
-install: all
- for x in $(APPS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
- rm -f $(DESTDIR)$(MODULES_DIR)/app_datetime.so
- rm -f $(DESTDIR)$(MODULES_DIR)/app_qcall.so
-
-app_curl.so: app_curl.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(CURLLIBS)
-
-app_sql_postgres.o: app_sql_postgres.c
- $(CC) -pipe -I$(CROSS_COMPILE_TARGET)/usr/local/pgsql/include -I$(CROSS_COMPILE_TARGET)/usr/include/postgresql $(CFLAGS) -c -o app_sql_postgres.o app_sql_postgres.c
-
-app_sql_postgres.so: app_sql_postgres.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -L/usr/local/pgsql/lib -lpq
-
-app_sql_odbc.so: app_sql_odbc.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc
-
-look: look.c
- $(CC) -pipe -O6 -g look.c -o look -lncurses
-
-ifeq (SunOS,$(shell uname))
-app_chanspy.so: app_chanspy.o
- $(CC) $(SOLINK) -o $@ $< -lrt
-endif
-
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
-
-env:
- env
diff --git a/1.2-netsec/apps/app_adsiprog.c b/1.2-netsec/apps/app_adsiprog.c
deleted file mode 100644
index 79fe30122..000000000
--- a/1.2-netsec/apps/app_adsiprog.c
+++ /dev/null
@@ -1,1606 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Program Asterisk ADSI Scripts into phone
- *
- * \ingroup applications
- */
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/adsi.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-
-static char *tdesc = "Asterisk ADSI Programming Application";
-
-static char *app = "ADSIProg";
-
-static char *synopsis = "Load Asterisk ADSI Scripts into phone";
-
-/* #define DUMP_MESSAGES */
-
-static char *descrip =
-" ADSIProg(script): This application programs an ADSI Phone with the given\n"
-"script. If nothing is specified, the default script (asterisk.adsi) is used.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-struct adsi_event {
- int id;
- char *name;
-};
-
-static struct adsi_event events[] = {
- { 1, "CALLERID" },
- { 2, "VMWI" },
- { 3, "NEARANSWER" },
- { 4, "FARANSWER" },
- { 5, "ENDOFRING" },
- { 6, "IDLE" },
- { 7, "OFFHOOK" },
- { 8, "CIDCW" },
- { 9, "BUSY" },
- { 10, "FARRING" },
- { 11, "DIALTONE" },
- { 12, "RECALL" },
- { 13, "MESSAGE" },
- { 14, "REORDER" },
- { 15, "DISTINCTIVERING" },
- { 16, "RING" },
- { 17, "REMINDERRING" },
- { 18, "SPECIALRING" },
- { 19, "CODEDRING" },
- { 20, "TIMER" },
- { 21, "INUSE" },
- { 22, "EVENT22" },
- { 23, "EVENT23" },
- { 24, "CPEID" },
-};
-
-static struct adsi_event justify[] = {
- { 0, "CENTER" },
- { 1, "RIGHT" },
- { 2, "LEFT" },
- { 3, "INDENT" },
-};
-
-#define STATE_NORMAL 0
-#define STATE_INKEY 1
-#define STATE_INSUB 2
-#define STATE_INIF 3
-
-#define MAX_RET_CODE 20
-#define MAX_SUB_LEN 255
-#define MAX_MAIN_LEN 1600
-
-#define ARG_STRING (1 << 0)
-#define ARG_NUMBER (1 << 1)
-
-struct adsi_soft_key {
- char vname[40]; /* Which "variable" is associated with it */
- int retstrlen; /* Length of return string */
- int initlen; /* initial length */
- int id;
- int defined;
- char retstr[80]; /* Return string data */
-};
-
-struct adsi_subscript {
- char vname[40];
- int id;
- int defined;
- int datalen;
- int inscount;
- int ifinscount;
- char *ifdata;
- char data[2048];
-};
-
-struct adsi_state {
- char vname[40];
- int id;
-};
-
-struct adsi_flag {
- char vname[40];
- int id;
-};
-
-struct adsi_display {
- char vname[40];
- int id;
- char data[70];
- int datalen;
-};
-
-struct adsi_script {
- int state;
- int numkeys;
- int numsubs;
- int numstates;
- int numdisplays;
- int numflags;
- struct adsi_soft_key *key;
- struct adsi_subscript *sub;
- /* Pre-defined displays */
- struct adsi_display displays[63];
- /* ADSI States 1 (initial) - 254 */
- struct adsi_state states[256];
- /* Keys 2-63 */
- struct adsi_soft_key keys[62];
- /* Subscripts 0 (main) to 127 */
- struct adsi_subscript subs[128];
- /* Flags 1-7 */
- struct adsi_flag flags[7];
-
- /* Stuff from adsi script */
- unsigned char sec[5];
- char desc[19];
- unsigned char fdn[5];
- int ver;
-};
-
-
-static int process_token(void *out, char *src, int maxlen, int argtype)
-{
- if ((strlen(src) > 1) && src[0] == '\"') {
- /* This is a quoted string */
- if (!(argtype & ARG_STRING))
- return -1;
- src++;
- /* Don't take more than what's there */
- if (maxlen > strlen(src) - 1)
- maxlen = strlen(src) - 1;
- memcpy(out, src, maxlen);
- ((char *)out)[maxlen] = '\0';
- } else if (!ast_strlen_zero(src) && (src[0] == '\\')) {
- if (!(argtype & ARG_NUMBER))
- return -1;
- /* Octal value */
- if (sscanf(src, "%o", (int *)out) != 1)
- return -1;
- if (argtype & ARG_STRING) {
- /* Convert */
- *((unsigned int *)out) = htonl(*((unsigned int *)out));
- }
- } else if ((strlen(src) > 2) && (src[0] == '0') && (tolower(src[1]) == 'x')) {
- if (!(argtype & ARG_NUMBER))
- return -1;
- /* Hex value */
- if (sscanf(src + 2, "%x", (unsigned int *)out) != 1)
- return -1;
- if (argtype & ARG_STRING) {
- /* Convert */
- *((unsigned int *)out) = htonl(*((unsigned int *)out));
- }
- } else if ((!ast_strlen_zero(src) && isdigit(src[0]))) {
- if (!(argtype & ARG_NUMBER))
- return -1;
- /* Hex value */
- if (sscanf(src, "%d", (int *)out) != 1)
- return -1;
- if (argtype & ARG_STRING) {
- /* Convert */
- *((unsigned int *)out) = htonl(*((unsigned int *)out));
- }
- } else
- return -1;
- return 0;
-}
-
-static char *get_token(char **buf, char *script, int lineno)
-{
- char *tmp = *buf;
- char *keyword;
- int quoted = 0;
- /* Advance past any white space */
- while(*tmp && (*tmp < 33))
- tmp++;
- if (!*tmp)
- return NULL;
- keyword = tmp;
- while(*tmp && ((*tmp > 32) || quoted)) {
- if (*tmp == '\"') {
- quoted = !quoted;
- }
- tmp++;
- }
- if (quoted) {
- ast_log(LOG_WARNING, "Mismatched quotes at line %d of %s\n", lineno, script);
- return NULL;
- }
- *tmp = '\0';
- tmp++;
- while(*tmp && (*tmp < 33))
- tmp++;
- /* Note where we left off */
- *buf = tmp;
- return keyword;
-}
-
-static char *validdtmf = "123456789*0#ABCD";
-
-static int send_dtmf(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char dtmfstr[80];
- char *a;
- int bytes=0;
- a = get_token(&args, script, lineno);
- if (!a) {
- ast_log(LOG_WARNING, "Expecting something to send for SENDDTMF at line %d of %s\n", lineno, script);
- return 0;
- }
- if (process_token(dtmfstr, a, sizeof(dtmfstr) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "Invalid token for SENDDTMF at line %d of %s\n", lineno, script);
- return 0;
- }
- a = dtmfstr;
- while(*a) {
- if (strchr(validdtmf, *a)) {
- *buf = *a;
- buf++;
- bytes++;
- } else
- ast_log(LOG_WARNING, "'%c' is not a valid DTMF tone at line %d of %s\n", *a, lineno, script);
- a++;
- }
- return bytes;
-}
-
-static int goto_line(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char *page;
- char *gline;
- int line;
- unsigned char cmd;
- page = get_token(&args, script, lineno);
- gline = get_token(&args, script, lineno);
- if (!page || !gline) {
- ast_log(LOG_WARNING, "Expecting page and line number for GOTOLINE at line %d of %s\n", lineno, script);
- return 0;
- }
- if (!strcasecmp(page, "INFO")) {
- cmd = 0;
- } else if (!strcasecmp(page, "COMM")) {
- cmd = 0x80;
- } else {
- ast_log(LOG_WARNING, "Expecting either 'INFO' or 'COMM' page, got got '%s' at line %d of %s\n", page, lineno, script);
- return 0;
- }
- if (process_token(&line, gline, sizeof(line), ARG_NUMBER)) {
- ast_log(LOG_WARNING, "Invalid line number '%s' at line %d of %s\n", gline, lineno, script);
- return 0;
- }
- cmd |= line;
- buf[0] = 0x8b;
- buf[1] = cmd;
- return 2;
-}
-
-static int goto_line_rel(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char *dir;
- char *gline;
- int line;
- unsigned char cmd;
- dir = get_token(&args, script, lineno);
- gline = get_token(&args, script, lineno);
- if (!dir || !gline) {
- ast_log(LOG_WARNING, "Expecting direction and number of lines for GOTOLINEREL at line %d of %s\n", lineno, script);
- return 0;
- }
- if (!strcasecmp(dir, "UP")) {
- cmd = 0;
- } else if (!strcasecmp(dir, "DOWN")) {
- cmd = 0x20;
- } else {
- ast_log(LOG_WARNING, "Expecting either 'UP' or 'DOWN' direction, got '%s' at line %d of %s\n", dir, lineno, script);
- return 0;
- }
- if (process_token(&line, gline, sizeof(line), ARG_NUMBER)) {
- ast_log(LOG_WARNING, "Invalid line number '%s' at line %d of %s\n", gline, lineno, script);
- return 0;
- }
- cmd |= line;
- buf[0] = 0x8c;
- buf[1] = cmd;
- return 2;
-}
-
-static int send_delay(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char *gtime;
- int ms;
- gtime = get_token(&args, script, lineno);
- if (!gtime) {
- ast_log(LOG_WARNING, "Expecting number of milliseconds to wait at line %d of %s\n", lineno, script);
- return 0;
- }
- if (process_token(&ms, gtime, sizeof(ms), ARG_NUMBER)) {
- ast_log(LOG_WARNING, "Invalid delay milliseconds '%s' at line %d of %s\n", gtime, lineno, script);
- return 0;
- }
- buf[0] = 0x90;
- if (id == 11)
- buf[1] = ms / 100;
- else
- buf[1] = ms / 10;
- return 2;
-}
-
-static int set_state(char *buf, char *name, int id, char *args, struct adsi_script *istate, char *script, int lineno)
-{
- char *gstate;
- int state;
- gstate = get_token(&args, script, lineno);
- if (!gstate) {
- ast_log(LOG_WARNING, "Expecting state number at line %d of %s\n", lineno, script);
- return 0;
- }
- if (process_token(&state, gstate, sizeof(state), ARG_NUMBER)) {
- ast_log(LOG_WARNING, "Invalid state number '%s' at line %d of %s\n", gstate, lineno, script);
- return 0;
- }
- buf[0] = id;
- buf[1] = state;
- return 2;
-}
-
-static int cleartimer(char *buf, char *name, int id, char *args, struct adsi_script *istate, char *script, int lineno)
-{
- char *tok;
- tok = get_token(&args, script, lineno);
- if (tok)
- ast_log(LOG_WARNING, "Clearing timer requires no arguments ('%s') at line %d of %s\n", tok, lineno, script);
-
- buf[0] = id;
- /* For some reason the clear code is different slightly */
- if (id == 7)
- buf[1] = 0x10;
- else
- buf[1] = 0x00;
- return 2;
-}
-
-static struct adsi_flag *getflagbyname(struct adsi_script *state, char *name, char *script, int lineno, int create)
-{
- int x;
- for (x=0;x<state->numflags;x++)
- if (!strcasecmp(state->flags[x].vname, name))
- return &state->flags[x];
- /* Return now if we're not allowed to create */
- if (!create)
- return NULL;
- if (state->numflags > 6) {
- ast_log(LOG_WARNING, "No more flag space at line %d of %s\n", lineno, script);
- return NULL;
- }
- ast_copy_string(state->flags[state->numflags].vname, name, sizeof(state->flags[state->numflags].vname));
- state->flags[state->numflags].id = state->numflags + 1;
- state->numflags++;
- return &state->flags[state->numflags-1];
-}
-
-static int setflag(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char *tok;
- char sname[80];
- struct adsi_flag *flag;
- tok = get_token(&args, script, lineno);
- if (!tok) {
- ast_log(LOG_WARNING, "Setting flag requires a flag number at line %d of %s\n", lineno, script);
- return 0;
- }
- if (process_token(sname, tok, sizeof(sname) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "Invalid flag '%s' at line %d of %s\n", tok, lineno, script);
- return 0;
- }
- flag = getflagbyname(state, sname, script, lineno, 0);
- if (!flag) {
- ast_log(LOG_WARNING, "Flag '%s' is undeclared at line %d of %s\n", sname, lineno, script);
- return 0;
- }
- buf[0] = id;
- buf[1] = ((flag->id & 0x7) << 4) | 1;
- return 2;
-}
-
-static int clearflag(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char *tok;
- struct adsi_flag *flag;
- char sname[80];
- tok = get_token(&args, script, lineno);
- if (!tok) {
- ast_log(LOG_WARNING, "Clearing flag requires a flag number at line %d of %s\n", lineno, script);
- return 0;
- }
- if (process_token(sname, tok, sizeof(sname) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "Invalid flag '%s' at line %d of %s\n", tok, lineno, script);
- return 0;
- }
- flag = getflagbyname(state, sname, script, lineno, 0);
- if (!flag) {
- ast_log(LOG_WARNING, "Flag '%s' is undeclared at line %d of %s\n", sname, lineno, script);
- return 0;
- }
- buf[0] = id;
- buf[1] = ((flag->id & 0x7) << 4);
- return 2;
-}
-
-static int starttimer(char *buf, char *name, int id, char *args, struct adsi_script *istate, char *script, int lineno)
-{
- char *tok;
- int secs;
- tok = get_token(&args, script, lineno);
- if (!tok) {
- ast_log(LOG_WARNING, "Missing number of seconds at line %d of %s\n", lineno, script);
- return 0;
- }
- if (process_token(&secs, tok, sizeof(secs), ARG_NUMBER)) {
- ast_log(LOG_WARNING, "Invalid number of seconds '%s' at line %d of %s\n", tok, lineno, script);
- return 0;
- }
- buf[0] = id;
- buf[1] = 0x1;
- buf[2] = secs;
- return 3;
-}
-
-static int geteventbyname(char *name)
-{
- int x;
- for (x=0;x<sizeof(events) / sizeof(events[0]); x++) {
- if (!strcasecmp(events[x].name, name))
- return events[x].id;
- }
- return 0;
-}
-
-static int getjustifybyname(char *name)
-{
- int x;
- for (x=0;x<sizeof(justify) / sizeof(justify[0]); x++) {
- if (!strcasecmp(justify[x].name, name))
- return justify[x].id;
- }
- return -1;
-}
-
-static struct adsi_soft_key *getkeybyname(struct adsi_script *state, char *name, char *script, int lineno)
-{
- int x;
- for (x=0;x<state->numkeys;x++)
- if (!strcasecmp(state->keys[x].vname, name))
- return &state->keys[x];
- if (state->numkeys > 61) {
- ast_log(LOG_WARNING, "No more key space at line %d of %s\n", lineno, script);
- return NULL;
- }
- ast_copy_string(state->keys[state->numkeys].vname, name, sizeof(state->keys[state->numkeys].vname));
- state->keys[state->numkeys].id = state->numkeys + 2;
- state->numkeys++;
- return &state->keys[state->numkeys-1];
-}
-
-static struct adsi_subscript *getsubbyname(struct adsi_script *state, char *name, char *script, int lineno)
-{
- int x;
- for (x=0;x<state->numsubs;x++)
- if (!strcasecmp(state->subs[x].vname, name))
- return &state->subs[x];
- if (state->numsubs > 127) {
- ast_log(LOG_WARNING, "No more subscript space at line %d of %s\n", lineno, script);
- return NULL;
- }
- ast_copy_string(state->subs[state->numsubs].vname, name, sizeof(state->subs[state->numsubs].vname));
- state->subs[state->numsubs].id = state->numsubs;
- state->numsubs++;
- return &state->subs[state->numsubs-1];
-}
-
-static struct adsi_state *getstatebyname(struct adsi_script *state, char *name, char *script, int lineno, int create)
-{
- int x;
- for (x=0;x<state->numstates;x++)
- if (!strcasecmp(state->states[x].vname, name))
- return &state->states[x];
- /* Return now if we're not allowed to create */
- if (!create)
- return NULL;
- if (state->numstates > 253) {
- ast_log(LOG_WARNING, "No more state space at line %d of %s\n", lineno, script);
- return NULL;
- }
- ast_copy_string(state->states[state->numstates].vname, name, sizeof(state->states[state->numstates].vname));
- state->states[state->numstates].id = state->numstates + 1;
- state->numstates++;
- return &state->states[state->numstates-1];
-}
-
-static struct adsi_display *getdisplaybyname(struct adsi_script *state, char *name, char *script, int lineno, int create)
-{
- int x;
- for (x=0;x<state->numdisplays;x++)
- if (!strcasecmp(state->displays[x].vname, name))
- return &state->displays[x];
- /* Return now if we're not allowed to create */
- if (!create)
- return NULL;
- if (state->numdisplays > 61) {
- ast_log(LOG_WARNING, "No more display space at line %d of %s\n", lineno, script);
- return NULL;
- }
- ast_copy_string(state->displays[state->numdisplays].vname, name, sizeof(state->displays[state->numdisplays].vname));
- state->displays[state->numdisplays].id = state->numdisplays + 1;
- state->numdisplays++;
- return &state->displays[state->numdisplays-1];
-}
-
-static int showkeys(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char *tok;
- char newkey[80];
- int bytes;
- unsigned char keyid[6];
- int x;
- int flagid=0;
- struct adsi_soft_key *key;
- struct adsi_flag *flag;
-
- for (x=0;x<7;x++) {
- /* Up to 6 key arguments */
- tok = get_token(&args, script, lineno);
- if (!tok)
- break;
- if (!strcasecmp(tok, "UNLESS")) {
- /* Check for trailing UNLESS flag */
- tok = get_token(&args, script, lineno);
- if (!tok) {
- ast_log(LOG_WARNING, "Missing argument for UNLESS clause at line %d of %s\n", lineno, script);
- } else if (process_token(newkey, tok, sizeof(newkey) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "Invalid flag name '%s' at line %d of %s\n", tok, lineno, script);
- } else if (!(flag = getflagbyname(state, newkey, script, lineno, 0))) {
- ast_log(LOG_WARNING, "Flag '%s' is undeclared at line %d of %s\n", newkey, lineno, script);
- } else
- flagid = flag->id;
- if ((tok = get_token(&args, script, lineno)))
- ast_log(LOG_WARNING, "Extra arguments after UNLESS clause: '%s' at line %d of %s\n", tok, lineno, script);
- break;
- }
- if (x > 5) {
- ast_log(LOG_WARNING, "Only 6 keys can be defined, ignoring '%s' at line %d of %s\n", tok, lineno, script);
- break;
- }
- if (process_token(newkey, tok, sizeof(newkey) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "Invalid token for key name: %s\n", tok);
- continue;
- }
-
- key = getkeybyname(state, newkey, script, lineno);
- if (!key)
- break;
- keyid[x] = key->id;
- }
- buf[0] = id;
- buf[1] = (flagid & 0x7) << 3 | (x & 0x7);
- for (bytes=0;bytes<x;bytes++) {
- buf[bytes + 2] = keyid[bytes];
- }
- return 2 + x;
-}
-
-static int showdisplay(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char *tok;
- char dispname[80];
- int line=0;
- int flag=0;
- int cmd = 3;
- struct adsi_display *disp;
-
- /* Get display */
- tok = get_token(&args, script, lineno);
- if (!tok || process_token(dispname, tok, sizeof(dispname) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "Invalid display name: %s at line %d of %s\n", tok ? tok : "<nothing>", lineno, script);
- return 0;
- }
- disp = getdisplaybyname(state, dispname, script, lineno, 0);
- if (!disp) {
- ast_log(LOG_WARNING, "Display '%s' is undefined at line %d of %s\n", dispname, lineno, script);
- return 0;
- }
-
- tok = get_token(&args, script, lineno);
- if (!tok || strcasecmp(tok, "AT")) {
- ast_log(LOG_WARNING, "Missing token 'AT' at line %d of %s\n", lineno, script);
- return 0;
- }
- /* Get line number */
- tok = get_token(&args, script, lineno);
- if (!tok || process_token(&line, tok, sizeof(line), ARG_NUMBER)) {
- ast_log(LOG_WARNING, "Invalid line: '%s' at line %d of %s\n", tok ? tok : "<nothing>", lineno, script);
- return 0;
- }
- tok = get_token(&args, script, lineno);
- if (tok && !strcasecmp(tok, "NOUPDATE")) {
- cmd = 1;
- tok = get_token(&args, script, lineno);
- }
- if (tok && !strcasecmp(tok, "UNLESS")) {
- /* Check for trailing UNLESS flag */
- tok = get_token(&args, script, lineno);
- if (!tok) {
- ast_log(LOG_WARNING, "Missing argument for UNLESS clause at line %d of %s\n", lineno, script);
- } else if (process_token(&flag, tok, sizeof(flag), ARG_NUMBER)) {
- ast_log(LOG_WARNING, "Invalid flag number '%s' at line %d of %s\n", tok, lineno, script);
- }
- if ((tok = get_token(&args, script, lineno)))
- ast_log(LOG_WARNING, "Extra arguments after UNLESS clause: '%s' at line %d of %s\n", tok, lineno, script);
- }
-
- buf[0] = id;
- buf[1] = (cmd << 6) | (disp->id & 0x3f);
- buf[2] = ((line & 0x1f) << 3) | (flag & 0x7);
- return 3;
-}
-
-static int cleardisplay(char *buf, char *name, int id, char *args, struct adsi_script *istate, char *script, int lineno)
-{
- char *tok;
- tok = get_token(&args, script, lineno);
- if (tok)
- ast_log(LOG_WARNING, "Clearing display requires no arguments ('%s') at line %d of %s\n", tok, lineno, script);
-
- buf[0] = id;
- buf[1] = 0x00;
- return 2;
-}
-
-static int digitdirect(char *buf, char *name, int id, char *args, struct adsi_script *istate, char *script, int lineno)
-{
- char *tok;
- tok = get_token(&args, script, lineno);
- if (tok)
- ast_log(LOG_WARNING, "Digitdirect requires no arguments ('%s') at line %d of %s\n", tok, lineno, script);
-
- buf[0] = id;
- buf[1] = 0x7;
- return 2;
-}
-
-static int clearcbone(char *buf, char *name, int id, char *args, struct adsi_script *istate, char *script, int lineno)
-{
- char *tok;
- tok = get_token(&args, script, lineno);
- if (tok)
- ast_log(LOG_WARNING, "CLEARCB1 requires no arguments ('%s') at line %d of %s\n", tok, lineno, script);
-
- buf[0] = id;
- buf[1] = 0;
- return 2;
-}
-
-static int digitcollect(char *buf, char *name, int id, char *args, struct adsi_script *istate, char *script, int lineno)
-{
- char *tok;
- tok = get_token(&args, script, lineno);
- if (tok)
- ast_log(LOG_WARNING, "Digitcollect requires no arguments ('%s') at line %d of %s\n", tok, lineno, script);
-
- buf[0] = id;
- buf[1] = 0xf;
- return 2;
-}
-
-static int subscript(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char *tok;
- char subscript[80];
- struct adsi_subscript *sub;
- tok = get_token(&args, script, lineno);
- if (!tok) {
- ast_log(LOG_WARNING, "Missing subscript to call at line %d of %s\n", lineno, script);
- return 0;
- }
- if (process_token(subscript, tok, sizeof(subscript) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "Invalid number of seconds '%s' at line %d of %s\n", tok, lineno, script);
- return 0;
- }
- sub = getsubbyname(state, subscript, script, lineno);
- if (!sub)
- return 0;
- buf[0] = 0x9d;
- buf[1] = sub->id;
- return 2;
-}
-
-static int onevent(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno)
-{
- char *tok;
- char subscript[80];
- char sname[80];
- int sawin=0;
- int event;
- int snums[8];
- int scnt = 0;
- int x;
- struct adsi_subscript *sub;
- tok = get_token(&args, script, lineno);
- if (!tok) {
- ast_log(LOG_WARNING, "Missing event for 'ONEVENT' at line %d of %s\n", lineno, script);
- return 0;
- }
- event = geteventbyname(tok);
- if (event < 1) {
- ast_log(LOG_WARNING, "'%s' is not a valid event name, at line %d of %s\n", args, lineno, script);
- return 0;
- }
- tok = get_token(&args, script, lineno);
- while ((!sawin && !strcasecmp(tok, "IN")) ||
- (sawin && !strcasecmp(tok, "OR"))) {
- sawin = 1;
- if (scnt > 7) {
- ast_log(LOG_WARNING, "No more than 8 states may be specified for inclusion at line %d of %s\n", lineno, script);
- return 0;
- }
- /* Process 'in' things */
- tok = get_token(&args, script, lineno);
- if (process_token(sname, tok, sizeof(sname), ARG_STRING)) {
- ast_log(LOG_WARNING, "'%s' is not a valid state name at line %d of %s\n", tok, lineno, script);
- return 0;
- }
- if ((snums[scnt] = getstatebyname(state, sname, script, lineno, 0) < 0)) {
- ast_log(LOG_WARNING, "State '%s' not declared at line %d of %s\n", sname, lineno, script);
- return 0;
- }
- scnt++;
- tok = get_token(&args, script, lineno);
- if (!tok)
- break;
- }
- if (!tok || strcasecmp(tok, "GOTO")) {
- if (!tok)
- tok = "<nothing>";
- if (sawin)
- ast_log(LOG_WARNING, "Got '%s' while looking for 'GOTO' or 'OR' at line %d of %s\n", tok, lineno, script);
- else
- ast_log(LOG_WARNING, "Got '%s' while looking for 'GOTO' or 'IN' at line %d of %s\n", tok, lineno, script);
- }
- tok = get_token(&args, script, lineno);
- if (!tok) {
- ast_log(LOG_WARNING, "Missing subscript to call at line %d of %s\n", lineno, script);
- return 0;
- }
- if (process_token(subscript, tok, sizeof(subscript) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "Invalid subscript '%s' at line %d of %s\n", tok, lineno, script);
- return 0;
- }
- sub = getsubbyname(state, subscript, script, lineno);
- if (!sub)
- return 0;
- buf[0] = 8;
- buf[1] = event;
- buf[2] = sub->id | 0x80;
- for (x=0;x<scnt;x++)
- buf[3 + x] = snums[x];
- return 3 + scnt;
-}
-
-struct adsi_key_cmd {
- char *name;
- int id;
- int (*add_args)(char *buf, char *name, int id, char *args, struct adsi_script *state, char *script, int lineno);
-};
-
-static struct adsi_key_cmd kcmds[] = {
- { "SENDDTMF", 0, send_dtmf },
- /* Encoded DTMF would go here */
- { "ONHOOK", 0x81 },
- { "OFFHOOK", 0x82 },
- { "FLASH", 0x83 },
- { "WAITDIALTONE", 0x84 },
- /* Send line number */
- { "BLANK", 0x86 },
- { "SENDCHARS", 0x87 },
- { "CLEARCHARS", 0x88 },
- { "BACKSPACE", 0x89 },
- /* Tab column */
- { "GOTOLINE", 0x8b, goto_line },
- { "GOTOLINEREL", 0x8c, goto_line_rel },
- { "PAGEUP", 0x8d },
- { "PAGEDOWN", 0x8e },
- /* Extended DTMF */
- { "DELAY", 0x90, send_delay },
- { "DIALPULSEONE", 0x91 },
- { "DATAMODE", 0x92 },
- { "VOICEMODE", 0x93 },
- /* Display call buffer 'n' */
- /* Clear call buffer 'n' */
- { "CLEARCB1", 0x95, clearcbone },
- { "DIGITCOLLECT", 0x96, digitcollect },
- { "DIGITDIRECT", 0x96, digitdirect },
- { "CLEAR", 0x97 },
- { "SHOWDISPLAY", 0x98, showdisplay },
- { "CLEARDISPLAY", 0x98, cleardisplay },
- { "SHOWKEYS", 0x99, showkeys },
- { "SETSTATE", 0x9a, set_state },
- { "TIMERSTART", 0x9b, starttimer },
- { "TIMERCLEAR", 0x9b, cleartimer },
- { "SETFLAG", 0x9c, setflag },
- { "CLEARFLAG", 0x9c, clearflag },
- { "GOTO", 0x9d, subscript },
- { "EVENT22", 0x9e },
- { "EVENT23", 0x9f },
- { "EXIT", 0xa0 },
-};
-
-static struct adsi_key_cmd opcmds[] = {
-
- /* 1 - Branch on event -- handled specially */
- { "SHOWKEYS", 2, showkeys },
- /* Display Control */
- { "SHOWDISPLAY", 3, showdisplay },
- { "CLEARDISPLAY", 3, cleardisplay },
- { "CLEAR", 5 },
- { "SETSTATE", 6, set_state },
- { "TIMERSTART", 7, starttimer },
- { "TIMERCLEAR", 7, cleartimer },
- { "ONEVENT", 8, onevent },
- /* 9 - Subroutine label, treated specially */
- { "SETFLAG", 10, setflag },
- { "CLEARFLAG", 10, clearflag },
- { "DELAY", 11, send_delay },
- { "EXIT", 12 },
-};
-
-
-static int process_returncode(struct adsi_soft_key *key, char *code, char *args, struct adsi_script *state, char *script, int lineno)
-{
- int x;
- char *unused;
- int res;
- for (x=0;x<sizeof(kcmds) / sizeof(kcmds[0]);x++) {
- if ((kcmds[x].id > -1) && !strcasecmp(kcmds[x].name, code)) {
- if (kcmds[x].add_args) {
- res = kcmds[x].add_args(key->retstr + key->retstrlen,
- code, kcmds[x].id, args, state, script, lineno);
- if ((key->retstrlen + res - key->initlen) <= MAX_RET_CODE)
- key->retstrlen += res;
- else
- ast_log(LOG_WARNING, "No space for '%s' code in key '%s' at line %d of %s\n", kcmds[x].name, key->vname, lineno, script);
- } else {
- if ((unused = get_token(&args, script, lineno)))
- ast_log(LOG_WARNING, "'%s' takes no arguments at line %d of %s (token is '%s')\n", kcmds[x].name, lineno, script, unused);
- if ((key->retstrlen + 1 - key->initlen) <= MAX_RET_CODE) {
- key->retstr[key->retstrlen] = kcmds[x].id;
- key->retstrlen++;
- } else
- ast_log(LOG_WARNING, "No space for '%s' code in key '%s' at line %d of %s\n", kcmds[x].name, key->vname, lineno, script);
- }
- return 0;
- }
- }
- return -1;
-}
-
-static int process_opcode(struct adsi_subscript *sub, char *code, char *args, struct adsi_script *state, char *script, int lineno)
-{
- int x;
- char *unused;
- int res;
- int max = sub->id ? MAX_SUB_LEN : MAX_MAIN_LEN;
- for (x=0;x<sizeof(opcmds) / sizeof(opcmds[0]);x++) {
- if ((opcmds[x].id > -1) && !strcasecmp(opcmds[x].name, code)) {
- if (opcmds[x].add_args) {
- res = opcmds[x].add_args(sub->data + sub->datalen,
- code, opcmds[x].id, args, state, script, lineno);
- if ((sub->datalen + res + 1) <= max)
- sub->datalen += res;
- else {
- ast_log(LOG_WARNING, "No space for '%s' code in subscript '%s' at line %d of %s\n", opcmds[x].name, sub->vname, lineno, script);
- return -1;
- }
- } else {
- if ((unused = get_token(&args, script, lineno)))
- ast_log(LOG_WARNING, "'%s' takes no arguments at line %d of %s (token is '%s')\n", opcmds[x].name, lineno, script, unused);
- if ((sub->datalen + 2) <= max) {
- sub->data[sub->datalen] = opcmds[x].id;
- sub->datalen++;
- } else {
- ast_log(LOG_WARNING, "No space for '%s' code in key '%s' at line %d of %s\n", opcmds[x].name, sub->vname, lineno, script);
- return -1;
- }
- }
- /* Separate commands with 0xff */
- sub->data[sub->datalen] = 0xff;
- sub->datalen++;
- sub->inscount++;
- return 0;
- }
- }
- return -1;
-}
-
-static int adsi_process(struct adsi_script *state, char *buf, char *script, int lineno)
-{
- char *keyword;
- char *args;
- char vname[256];
- char tmp[80];
- char tmp2[80];
- int lrci;
- int wi;
- int event;
- struct adsi_display *disp;
- struct adsi_subscript *newsub;
- /* Find the first keyword */
- keyword = get_token(&buf, script, lineno);
- if (!keyword)
- return 0;
- switch(state->state) {
- case STATE_NORMAL:
- if (!strcasecmp(keyword, "DESCRIPTION")) {
- args = get_token(&buf, script, lineno);
- if (args) {
- if (process_token(state->desc, args, sizeof(state->desc) - 1, ARG_STRING))
- ast_log(LOG_WARNING, "'%s' is not a valid token for DESCRIPTION at line %d of %s\n", args, lineno, script);
- } else
- ast_log(LOG_WARNING, "Missing argument for DESCRIPTION at line %d of %s\n", lineno, script);
- } else if (!strcasecmp(keyword, "VERSION")) {
- args = get_token(&buf, script, lineno);
- if (args) {
- if (process_token(&state->ver, args, sizeof(state->ver) - 1, ARG_NUMBER))
- ast_log(LOG_WARNING, "'%s' is not a valid token for VERSION at line %d of %s\n", args, lineno, script);
- } else
- ast_log(LOG_WARNING, "Missing argument for VERSION at line %d of %s\n", lineno, script);
- } else if (!strcasecmp(keyword, "SECURITY")) {
- args = get_token(&buf, script, lineno);
- if (args) {
- if (process_token(state->sec, args, sizeof(state->sec) - 1, ARG_STRING | ARG_NUMBER))
- ast_log(LOG_WARNING, "'%s' is not a valid token for SECURITY at line %d of %s\n", args, lineno, script);
- } else
- ast_log(LOG_WARNING, "Missing argument for SECURITY at line %d of %s\n", lineno, script);
- } else if (!strcasecmp(keyword, "FDN")) {
- args = get_token(&buf, script, lineno);
- if (args) {
- if (process_token(state->fdn, args, sizeof(state->fdn) - 1, ARG_STRING | ARG_NUMBER))
- ast_log(LOG_WARNING, "'%s' is not a valid token for FDN at line %d of %s\n", args, lineno, script);
- } else
- ast_log(LOG_WARNING, "Missing argument for FDN at line %d of %s\n", lineno, script);
- } else if (!strcasecmp(keyword, "KEY")) {
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "KEY definition missing name at line %d of %s\n", lineno, script);
- break;
- }
- if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY name at line %d of %s\n", args, lineno, script);
- break;
- }
- state->key = getkeybyname(state, vname, script, lineno);
- if (!state->key) {
- ast_log(LOG_WARNING, "Out of key space at line %d of %s\n", lineno, script);
- break;
- }
- if (state->key->defined) {
- ast_log(LOG_WARNING, "Cannot redefine key '%s' at line %d of %s\n", vname, lineno, script);
- break;
- }
- args = get_token(&buf, script, lineno);
- if (!args || strcasecmp(args, "IS")) {
- ast_log(LOG_WARNING, "Expecting 'IS', but got '%s' at line %d of %s\n", args ? args : "<nothing>", lineno, script);
- break;
- }
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "KEY definition missing short name at line %d of %s\n", lineno, script);
- break;
- }
- if (process_token(tmp, args, sizeof(tmp) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY short name at line %d of %s\n", args, lineno, script);
- break;
- }
- args = get_token(&buf, script, lineno);
- if (args) {
- if (strcasecmp(args, "OR")) {
- ast_log(LOG_WARNING, "Expecting 'OR' but got '%s' instead at line %d of %s\n", args, lineno, script);
- break;
- }
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "KEY definition missing optional long name at line %d of %s\n", lineno, script);
- break;
- }
- if (process_token(tmp2, args, sizeof(tmp2) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY long name at line %d of %s\n", args, lineno, script);
- break;
- }
- } else {
- ast_copy_string(tmp2, tmp, sizeof(tmp2));
- }
- if (strlen(tmp2) > 18) {
- ast_log(LOG_WARNING, "Truncating full name to 18 characters at line %d of %s\n", lineno, script);
- tmp2[18] = '\0';
- }
- if (strlen(tmp) > 7) {
- ast_log(LOG_WARNING, "Truncating short name to 7 bytes at line %d of %s\n", lineno, script);
- tmp[7] = '\0';
- }
- /* Setup initial stuff */
- state->key->retstr[0] = 128;
- /* 1 has the length */
- state->key->retstr[2] = state->key->id;
- /* Put the Full name in */
- memcpy(state->key->retstr + 3, tmp2, strlen(tmp2));
- /* Update length */
- state->key->retstrlen = strlen(tmp2) + 3;
- /* Put trailing 0xff */
- state->key->retstr[state->key->retstrlen++] = 0xff;
- /* Put the short name */
- memcpy(state->key->retstr + state->key->retstrlen, tmp, strlen(tmp));
- /* Update length */
- state->key->retstrlen += strlen(tmp);
- /* Put trailing 0xff */
- state->key->retstr[state->key->retstrlen++] = 0xff;
- /* Record initial length */
- state->key->initlen = state->key->retstrlen;
- state->state = STATE_INKEY;
- } else if (!strcasecmp(keyword, "SUB")) {
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "SUB definition missing name at line %d of %s\n", lineno, script);
- break;
- }
- if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY name at line %d of %s\n", args, lineno, script);
- break;
- }
- state->sub = getsubbyname(state, vname, script, lineno);
- if (!state->sub) {
- ast_log(LOG_WARNING, "Out of subroutine space at line %d of %s\n", lineno, script);
- break;
- }
- if (state->sub->defined) {
- ast_log(LOG_WARNING, "Cannot redefine subroutine '%s' at line %d of %s\n", vname, lineno, script);
- break;
- }
- /* Setup sub */
- state->sub->data[0] = 130;
- /* 1 is the length */
- state->sub->data[2] = 0x0; /* Clear extensibility bit */
- state->sub->datalen = 3;
- if (state->sub->id) {
- /* If this isn't the main subroutine, make a subroutine label for it */
- state->sub->data[3] = 9;
- state->sub->data[4] = state->sub->id;
- /* 5 is length */
- state->sub->data[6] = 0xff;
- state->sub->datalen = 7;
- }
- args = get_token(&buf, script, lineno);
- if (!args || strcasecmp(args, "IS")) {
- ast_log(LOG_WARNING, "Expecting 'IS', but got '%s' at line %d of %s\n", args ? args : "<nothing>", lineno, script);
- break;
- }
- state->state = STATE_INSUB;
- } else if (!strcasecmp(keyword, "STATE")) {
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "STATE definition missing name at line %d of %s\n", lineno, script);
- break;
- }
- if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "'%s' is not a valid token for a STATE name at line %d of %s\n", args, lineno, script);
- break;
- }
- if (getstatebyname(state, vname, script, lineno, 0)) {
- ast_log(LOG_WARNING, "State '%s' is already defined at line %d of %s\n", vname, lineno, script);
- break;
- }
- getstatebyname(state, vname, script, lineno, 1);
- } else if (!strcasecmp(keyword, "FLAG")) {
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "FLAG definition missing name at line %d of %s\n", lineno, script);
- break;
- }
- if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "'%s' is not a valid token for a FLAG name at line %d of %s\n", args, lineno, script);
- break;
- }
- if (getflagbyname(state, vname, script, lineno, 0)) {
- ast_log(LOG_WARNING, "Flag '%s' is already defined\n", vname);
- break;
- }
- getflagbyname(state, vname, script, lineno, 1);
- } else if (!strcasecmp(keyword, "DISPLAY")) {
- lrci = 0;
- wi = 0;
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "SUB definition missing name at line %d of %s\n", lineno, script);
- break;
- }
- if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY name at line %d of %s\n", args, lineno, script);
- break;
- }
- if (getdisplaybyname(state, vname, script, lineno, 0)) {
- ast_log(LOG_WARNING, "State '%s' is already defined\n", vname);
- break;
- }
- disp = getdisplaybyname(state, vname, script, lineno, 1);
- if (!disp)
- break;
- args = get_token(&buf, script, lineno);
- if (!args || strcasecmp(args, "IS")) {
- ast_log(LOG_WARNING, "Missing 'IS' at line %d of %s\n", lineno, script);
- break;
- }
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "Missing Column 1 text at line %d of %s\n", lineno, script);
- break;
- }
- if (process_token(tmp, args, sizeof(tmp) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "Token '%s' is not valid column 1 text at line %d of %s\n", args, lineno, script);
- break;
- }
- if (strlen(tmp) > 20) {
- ast_log(LOG_WARNING, "Truncating column one to 20 characters at line %d of %s\n", lineno, script);
- tmp[20] = '\0';
- }
- memcpy(disp->data + 5, tmp, strlen(tmp));
- disp->datalen = strlen(tmp) + 5;
- disp->data[disp->datalen++] = 0xff;
-
- args = get_token(&buf, script, lineno);
- if (args && !process_token(tmp, args, sizeof(tmp) - 1, ARG_STRING)) {
- /* Got a column two */
- if (strlen(tmp) > 20) {
- ast_log(LOG_WARNING, "Truncating column two to 20 characters at line %d of %s\n", lineno, script);
- tmp[20] = '\0';
- }
- memcpy(disp->data + disp->datalen, tmp, strlen(tmp));
- disp->datalen += strlen(tmp);
- args = get_token(&buf, script, lineno);
- }
- while(args) {
- if (!strcasecmp(args, "JUSTIFY")) {
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "Qualifier 'JUSTIFY' requires an argument at line %d of %s\n", lineno, script);
- break;
- }
- lrci = getjustifybyname(args);
- if (lrci < 0) {
- ast_log(LOG_WARNING, "'%s' is not a valid justification at line %d of %s\n", args, lineno, script);
- break;
- }
- } else if (!strcasecmp(args, "WRAP")) {
- wi = 0x80;
- } else {
- ast_log(LOG_WARNING, "'%s' is not a known qualifier at line %d of %s\n", args, lineno, script);
- break;
- }
- args = get_token(&buf, script, lineno);
- }
- if (args) {
- /* Something bad happened */
- break;
- }
- disp->data[0] = 129;
- disp->data[1] = disp->datalen - 2;
- disp->data[2] = ((lrci & 0x3) << 6) | disp->id;
- disp->data[3] = wi;
- disp->data[4] = 0xff;
- } else {
- ast_log(LOG_WARNING, "Invalid or Unknown keyword '%s' in PROGRAM\n", keyword);
- }
- break;
- case STATE_INKEY:
- if (process_returncode(state->key, keyword, buf, state, script, lineno)) {
- if (!strcasecmp(keyword, "ENDKEY")) {
- /* Return to normal operation and increment current key */
- state->state = STATE_NORMAL;
- state->key->defined = 1;
- state->key->retstr[1] = state->key->retstrlen - 2;
- state->key = NULL;
- } else {
- ast_log(LOG_WARNING, "Invalid or Unknown keyword '%s' in SOFTKEY definition at line %d of %s\n", keyword, lineno, script);
- }
- }
- break;
- case STATE_INIF:
- if (process_opcode(state->sub, keyword, buf, state, script, lineno)) {
- if (!strcasecmp(keyword, "ENDIF")) {
- /* Return to normal SUB operation and increment current key */
- state->state = STATE_INSUB;
- state->sub->defined = 1;
- /* Store the proper number of instructions */
- state->sub->ifdata[2] = state->sub->ifinscount;
- } else if (!strcasecmp(keyword, "GOTO")) {
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "GOTO clause missing Subscript name at line %d of %s\n", lineno, script);
- break;
- }
- if (process_token(tmp, args, sizeof(tmp) - 1, ARG_STRING)) {
- ast_log(LOG_WARNING, "'%s' is not a valid subscript name token at line %d of %s\n", args, lineno, script);
- break;
- }
- newsub = getsubbyname(state, tmp, script, lineno);
- if (!newsub)
- break;
- /* Somehow you use GOTO to go to another place */
- state->sub->data[state->sub->datalen++] = 0x8;
- state->sub->data[state->sub->datalen++] = state->sub->ifdata[1];
- state->sub->data[state->sub->datalen++] = newsub->id;
- /* Terminate */
- state->sub->data[state->sub->datalen++] = 0xff;
- /* Increment counters */
- state->sub->inscount++;
- state->sub->ifinscount++;
- } else {
- ast_log(LOG_WARNING, "Invalid or Unknown keyword '%s' in IF clause at line %d of %s\n", keyword, lineno, script);
- }
- } else
- state->sub->ifinscount++;
- break;
- case STATE_INSUB:
- if (process_opcode(state->sub, keyword, buf, state, script, lineno)) {
- if (!strcasecmp(keyword, "ENDSUB")) {
- /* Return to normal operation and increment current key */
- state->state = STATE_NORMAL;
- state->sub->defined = 1;
- /* Store the proper length */
- state->sub->data[1] = state->sub->datalen - 2;
- if (state->sub->id) {
- /* if this isn't main, store number of instructions, too */
- state->sub->data[5] = state->sub->inscount;
- }
- state->sub = NULL;
- } else if (!strcasecmp(keyword, "IFEVENT")) {
- args = get_token(&buf, script, lineno);
- if (!args) {
- ast_log(LOG_WARNING, "IFEVENT clause missing Event name at line %d of %s\n", lineno, script);
- break;
- }
- event = geteventbyname(args);
- if (event < 1) {
- ast_log(LOG_WARNING, "'%s' is not a valid event\n", args);
- break;
- }
- args = get_token(&buf, script, lineno);
- if (!args || strcasecmp(args, "THEN")) {
- ast_log(LOG_WARNING, "IFEVENT clause missing 'THEN' at line %d of %s\n", lineno, script);
- break;
- }
- state->sub->ifinscount = 0;
- state->sub->ifdata = state->sub->data +
- state->sub->datalen;
- /* Reserve header and insert op codes */
- state->sub->ifdata[0] = 0x1;
- state->sub->ifdata[1] = event;
- /* 2 is for the number of instructions */
- state->sub->ifdata[3] = 0xff;
- state->sub->datalen += 4;
- /* Update Subscript instruction count */
- state->sub->inscount++;
- state->state = STATE_INIF;
- } else {
- ast_log(LOG_WARNING, "Invalid or Unknown keyword '%s' in SUB definition at line %d of %s\n", keyword, lineno, script);
- }
- }
- break;
- default:
- ast_log(LOG_WARNING, "Can't process keyword '%s' in weird state %d\n", keyword, state->state);
- }
- return 0;
-}
-
-static struct adsi_script *compile_script(char *script)
-{
- FILE *f;
- char fn[256];
- char buf[256];
- char *c;
- int lineno=0;
- int x, err;
- struct adsi_script *scr;
- if (script[0] == '/')
- ast_copy_string(fn, script, sizeof(fn));
- else
- snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, script);
- f = fopen(fn, "r");
- if (!f) {
- ast_log(LOG_WARNING, "Can't open file '%s'\n", fn);
- return NULL;
- }
- scr = malloc(sizeof(struct adsi_script));
- if (!scr) {
- fclose(f);
- ast_log(LOG_WARNING, "Out of memory loading script '%s'\n", fn);
- return NULL;
- }
- memset(scr, 0, sizeof(struct adsi_script));
- /* Create "main" as first subroutine */
- getsubbyname(scr, "main", NULL, 0);
- while(!feof(f)) {
- fgets(buf, sizeof(buf), f);
- if (!feof(f)) {
- lineno++;
- /* Trim off trailing return */
- buf[strlen(buf) - 1] = '\0';
- c = strchr(buf, ';');
- /* Strip comments */
- if (c)
- *c = '\0';
- if (!ast_strlen_zero(buf))
- adsi_process(scr, buf, script, lineno);
- }
- }
- fclose(f);
- /* Make sure we're in the main routine again */
- switch(scr->state) {
- case STATE_NORMAL:
- break;
- case STATE_INSUB:
- ast_log(LOG_WARNING, "Missing ENDSUB at end of file %s\n", script);
- free(scr);
- return NULL;
- case STATE_INKEY:
- ast_log(LOG_WARNING, "Missing ENDKEY at end of file %s\n", script);
- free(scr);
- return NULL;
- }
- err = 0;
-
- /* Resolve all keys and record their lengths */
- for (x=0;x<scr->numkeys;x++) {
- if (!scr->keys[x].defined) {
- ast_log(LOG_WARNING, "Key '%s' referenced but never defined in file %s\n", scr->keys[x].vname, fn);
- err++;
- }
- }
-
- /* Resolve all subs */
- for (x=0;x<scr->numsubs;x++) {
- if (!scr->subs[x].defined) {
- ast_log(LOG_WARNING, "Subscript '%s' referenced but never defined in file %s\n", scr->subs[x].vname, fn);
- err++;
- }
- if (x == (scr->numsubs - 1)) {
- /* Clear out extension bit on last message */
- scr->subs[x].data[2] = 0x80;
- }
- }
-
- if (err) {
- free(scr);
- return NULL;
- }
- return scr;
-}
-
-#ifdef DUMP_MESSAGES
-static void dump_message(char *type, char *vname, unsigned char *buf, int buflen)
-{
- int x;
- printf("%s %s: [ ", type, vname);
- for (x=0;x<buflen;x++)
- printf("%02x ", buf[x]);
- printf("]\n");
-}
-#endif
-
-static int adsi_prog(struct ast_channel *chan, char *script)
-{
- struct adsi_script *scr;
- int x;
- unsigned char buf[1024];
- int bytes;
- scr = compile_script(script);
- if (!scr)
- return -1;
-
- /* Start an empty ADSI Session */
- if (adsi_load_session(chan, NULL, 0, 1) < 1)
- return -1;
-
- /* Now begin the download attempt */
- if (adsi_begin_download(chan, scr->desc, scr->fdn, scr->sec, scr->ver)) {
- /* User rejected us for some reason */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "User rejected download attempt\n");
- ast_log(LOG_NOTICE, "User rejected download on channel %s\n", chan->name);
- free(scr);
- return -1;
- }
-
- bytes = 0;
- /* Start with key definitions */
- for (x=0;x<scr->numkeys;x++) {
- if (bytes + scr->keys[x].retstrlen > 253) {
- /* Send what we've collected so far */
- if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
- ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
- return -1;
- }
- bytes =0;
- }
- memcpy(buf + bytes, scr->keys[x].retstr, scr->keys[x].retstrlen);
- bytes += scr->keys[x].retstrlen;
-#ifdef DUMP_MESSAGES
- dump_message("Key", scr->keys[x].vname, scr->keys[x].retstr, scr->keys[x].retstrlen);
-#endif
- }
- if (bytes) {
- if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
- ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
- return -1;
- }
- }
-
- bytes = 0;
- /* Continue with the display messages */
- for (x=0;x<scr->numdisplays;x++) {
- if (bytes + scr->displays[x].datalen > 253) {
- /* Send what we've collected so far */
- if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
- ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
- return -1;
- }
- bytes =0;
- }
- memcpy(buf + bytes, scr->displays[x].data, scr->displays[x].datalen);
- bytes += scr->displays[x].datalen;
-#ifdef DUMP_MESSAGES
- dump_message("Display", scr->displays[x].vname, scr->displays[x].data, scr->displays[x].datalen);
-#endif
- }
- if (bytes) {
- if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
- ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
- return -1;
- }
- }
-
- bytes = 0;
- /* Send subroutines */
- for (x=0;x<scr->numsubs;x++) {
- if (bytes + scr->subs[x].datalen > 253) {
- /* Send what we've collected so far */
- if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
- ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
- return -1;
- }
- bytes =0;
- }
- memcpy(buf + bytes, scr->subs[x].data, scr->subs[x].datalen);
- bytes += scr->subs[x].datalen;
-#ifdef DUMP_MESSAGES
- dump_message("Sub", scr->subs[x].vname, scr->subs[x].data, scr->subs[x].datalen);
-#endif
- }
- if (bytes) {
- if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
- ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
- return -1;
- }
- }
-
-
- bytes = 0;
- bytes += adsi_display(buf, ADSI_INFO_PAGE, 1, ADSI_JUST_LEFT, 0, "Download complete.", "");
- bytes += adsi_set_line(buf, ADSI_INFO_PAGE, 1);
- if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY) < 0)
- return -1;
- if (adsi_end_download(chan)) {
- /* Download failed for some reason */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Download attempt failed\n");
- ast_log(LOG_NOTICE, "Download failed on %s\n", chan->name);
- free(scr);
- return -1;
- }
- free(scr);
- adsi_unload_session(chan);
- return 0;
-}
-
-static int adsi_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
-
- LOCAL_USER_ADD(u);
-
- if (ast_strlen_zero(data))
- data = "asterisk.adsi";
-
- if (!adsi_available(chan)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "ADSI Unavailable on CPE. Not bothering to try.\n");
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "ADSI Available on CPE. Attempting Upload.\n");
- res = adsi_prog(chan, data);
- }
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, adsi_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_alarmreceiver.c b/1.2-netsec/apps/app_alarmreceiver.c
deleted file mode 100644
index 7c36b60b8..000000000
--- a/1.2-netsec/apps/app_alarmreceiver.c
+++ /dev/null
@@ -1,867 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005 Steve Rodgers
- *
- * Steve Rodgers <hwstar@rodgers.sdcoxmail.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Central Station Alarm receiver for Ademco Contact ID
- * \author Steve Rodgers <hwstar@rodgers.sdcoxmail.com>
- *
- * *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
- *
- * Use at your own risk. Please consult the GNU GPL license document included with Asterisk details. *
- *
- * *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
- *
- * \ingroup applications
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/ulaw.h"
-#include "asterisk/options.h"
-#include "asterisk/app.h"
-#include "asterisk/dsp.h"
-#include "asterisk/config.h"
-#include "asterisk/localtime.h"
-#include "asterisk/callerid.h"
-#include "asterisk/astdb.h"
-
-#define ALMRCV_CONFIG "alarmreceiver.conf"
-#define ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID"
-
-struct event_node{
- char data[17];
- struct event_node *next;
-};
-
-typedef struct event_node event_node_t;
-
-static char *tdesc = "Alarm Receiver for Asterisk";
-
-static char *app = "AlarmReceiver";
-
-static char *synopsis = "Provide support for receving alarm reports from a burglar or fire alarm panel";
-static char *descrip =
-" AlarmReceiver(): Only 1 signalling format is supported at this time: Ademco\n"
-"Contact ID. This application should be called whenever there is an alarm\n"
-"panel calling in to dump its events. The application will handshake with the\n"
-"alarm panel, and receive events, validate them, handshake them, and store them\n"
-"until the panel hangs up. Once the panel hangs up, the application will run the\n"
-"system command specified by the eventcmd setting in alarmreceiver.conf and pipe\n"
-"the events to the standard input of the application. The configuration file also\n"
-"contains settings for DTMF timing, and for the loudness of the acknowledgement\n"
-"tones.\n";
-
-/* Config Variables */
-
-static int fdtimeout = 2000;
-static int sdtimeout = 200;
-static int toneloudness = 4096;
-static int log_individual_events = 0;
-static char event_spool_dir[128] = {'\0'};
-static char event_app[128] = {'\0'};
-static char db_family[128] = {'\0'};
-static char time_stamp_format[128] = {"%a %b %d, %Y @ %H:%M:%S %Z"};
-
-
-/* Misc variables */
-
-
-static char event_file[14] = "/event-XXXXXX";
-
-
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-/*
-* Attempt to access a database variable and increment it,
-* provided that the user defined db-family in alarmreceiver.conf
-* The alarmreceiver app will write statistics to a few variables
-* in this family if it is defined. If the new key doesn't exist in the
-* family, then create it and set its value to 1.
-*/
-
-static void database_increment( char *key )
-{
- int res = 0;
- unsigned v;
- char value[16];
-
-
- if (ast_strlen_zero(db_family))
- return; /* If not defined, don't do anything */
-
- res = ast_db_get(db_family, key, value, sizeof(value) - 1);
-
- if(res){
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Creating database entry %s and setting to 1\n", key);
- /* Guess we have to create it */
- res = ast_db_put(db_family, key, "1");
- return;
- }
-
- sscanf(value, "%u", &v);
- v++;
-
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: New value for %s: %u\n", key, v);
-
- snprintf(value, sizeof(value), "%u", v);
-
- res = ast_db_put(db_family, key, value);
-
- if((res)&&(option_verbose >= 4))
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: database_increment write error");
-
- return;
-}
-
-
-/*
-* Build a MuLaw data block for a single frequency tone
-*/
-
-static void make_tone_burst(unsigned char *data, float freq, float loudness, int len, int *x)
-{
- int i;
- float val;
-
- for(i = 0; i < len; i++){
- val = loudness * sin((freq * 2.0 * M_PI * (*x)++)/8000.0);
- data[i] = AST_LIN2MU((int)val);
- }
-
- /* wrap back around from 8000 */
-
- if (*x >= 8000) *x = 0;
- return;
-}
-
-/*
-* Send a single tone burst for a specifed duration and frequency.
-* Returns 0 if successful
-*/
-
-static int send_tone_burst(struct ast_channel *chan, float freq, int duration, int tldn)
-{
- int res = 0;
- int i = 0;
- int x = 0;
- struct ast_frame *f, wf;
-
- struct {
- unsigned char offset[AST_FRIENDLY_OFFSET];
- unsigned char buf[640];
- } tone_block;
-
- for(;;)
- {
-
- if (ast_waitfor(chan, -1) < 0){
- res = -1;
- break;
- }
-
- f = ast_read(chan);
- if (!f){
- res = -1;
- break;
- }
-
- if (f->frametype == AST_FRAME_VOICE) {
- wf.frametype = AST_FRAME_VOICE;
- wf.subclass = AST_FORMAT_ULAW;
- wf.offset = AST_FRIENDLY_OFFSET;
- wf.mallocd = 0;
- wf.data = tone_block.buf;
- wf.datalen = f->datalen;
- wf.samples = wf.datalen;
-
- make_tone_burst(tone_block.buf, freq, (float) tldn, wf.datalen, &x);
-
- i += wf.datalen / 8;
- if (i > duration) {
- break;
- }
- if (ast_write(chan, &wf)){
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Failed to write frame on %s\n", chan->name);
- ast_log(LOG_WARNING, "AlarmReceiver Failed to write frame on %s\n",chan->name);
- res = -1;
- break;
- }
- }
-
- ast_frfree(f);
- }
- return res;
-}
-
-/*
-* Receive a string of DTMF digits where the length of the digit string is known in advance. Do not give preferential
-* treatment to any digit value, and allow separate time out values to be specified for the first digit and all subsequent
-* digits.
-*
-* Returns 0 if all digits successfully received.
-* Returns 1 if a digit time out occurred
-* Returns -1 if the caller hung up or there was a channel error.
-*
-*/
-
-static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int length, int fdto, int sdto)
-{
- int res = 0;
- int i = 0;
- int r;
- struct ast_frame *f;
- struct timeval lastdigittime;
-
- lastdigittime = ast_tvnow();
- for(;;){
- /* if outa time, leave */
- if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) >
- ((i > 0) ? sdto : fdto)){
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: DTMF Digit Timeout on %s\n", chan->name);
-
- ast_log(LOG_DEBUG,"AlarmReceiver: DTMF timeout on chan %s\n",chan->name);
-
- res = 1;
- break;
- }
-
- if ((r = ast_waitfor(chan, -1) < 0)) {
- ast_log(LOG_DEBUG, "Waitfor returned %d\n", r);
- continue;
- }
-
- f = ast_read(chan);
-
- if (f == NULL){
- res = -1;
- break;
- }
-
- /* If they hung up, leave */
- if ((f->frametype == AST_FRAME_CONTROL) &&
- (f->subclass == AST_CONTROL_HANGUP)){
- ast_frfree(f);
- res = -1;
- break;
- }
-
- /* if not DTMF, just do it again */
- if (f->frametype != AST_FRAME_DTMF){
- ast_frfree(f);
- continue;
- }
-
- digit_string[i++] = f->subclass; /* save digit */
-
- ast_frfree(f);
-
- /* If we have all the digits we expect, leave */
- if(i >= length)
- break;
-
- lastdigittime = ast_tvnow();
- }
-
- digit_string[i] = '\0'; /* Nul terminate the end of the digit string */
- return res;
-
-}
-
-/*
-* Write the metadata to the log file
-*/
-
-static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan)
-{
- int res = 0;
- time_t t;
- struct tm now;
- char *cl,*cn;
- char workstring[80];
- char timestamp[80];
-
- /* Extract the caller ID location */
- if (chan->cid.cid_num)
- ast_copy_string(workstring, chan->cid.cid_num, sizeof(workstring));
- workstring[sizeof(workstring) - 1] = '\0';
-
- ast_callerid_parse(workstring, &cn, &cl);
- if (cl)
- ast_shrink_phone_number(cl);
-
-
- /* Get the current time */
-
- time(&t);
- ast_localtime(&t, &now, NULL);
-
- /* Format the time */
-
- strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);
-
-
- res = fprintf(logfile, "\n\n[metadata]\n\n");
-
- if(res >= 0)
- res = fprintf(logfile, "PROTOCOL=%s\n", signalling_type);
-
- if(res >= 0)
- res = fprintf(logfile, "CALLINGFROM=%s\n", (!cl) ? "<unknown>" : cl);
-
- if(res >- 0)
- res = fprintf(logfile, "CALLERNAME=%s\n", (!cn) ? "<unknown>" : cn);
-
- if(res >= 0)
- res = fprintf(logfile, "TIMESTAMP=%s\n\n", timestamp);
-
- if(res >= 0)
- res = fprintf(logfile, "[events]\n\n");
-
- if(res < 0){
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: can't write metadata\n");
-
- ast_log(LOG_DEBUG,"AlarmReceiver: can't write metadata\n");
- }
- else
- res = 0;
-
- return res;
-}
-
-/*
-* Write a single event to the log file
-*/
-
-static int write_event( FILE *logfile, event_node_t *event)
-{
- int res = 0;
-
- if( fprintf(logfile, "%s\n", event->data) < 0)
- res = -1;
-
- return res;
-}
-
-
-/*
-* If we are configured to log events, do so here.
-*
-*/
-
-static int log_events(struct ast_channel *chan, char *signalling_type, event_node_t *event)
-{
-
- int res = 0;
- char workstring[sizeof(event_spool_dir)+sizeof(event_file)] = "";
- int fd;
- FILE *logfile;
- event_node_t *elp = event;
-
- if (!ast_strlen_zero(event_spool_dir)) {
-
- /* Make a template */
-
- ast_copy_string(workstring, event_spool_dir, sizeof(workstring));
- strncat(workstring, event_file, sizeof(workstring) - strlen(workstring) - 1);
-
- /* Make the temporary file */
-
- fd = mkstemp(workstring);
-
- if(fd == -1){
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: can't make temporary file\n");
- ast_log(LOG_DEBUG,"AlarmReceiver: can't make temporary file\n");
- res = -1;
- }
-
- if(!res){
- logfile = fdopen(fd, "w");
- if(logfile){
- /* Write the file */
- res = write_metadata(logfile, signalling_type, chan);
- if(!res)
- while((!res) && (elp != NULL)){
- res = write_event(logfile, elp);
- elp = elp->next;
- }
- if(!res){
- if(fflush(logfile) == EOF)
- res = -1;
- if(!res){
- if(fclose(logfile) == EOF)
- res = -1;
- }
- }
- }
- else
- res = -1;
- }
- }
-
- return res;
-}
-
-/*
-* This function implements the logic to receive the Ademco contact ID format.
-*
-* The function will return 0 when the caller hangs up, else a -1 if there was a problem.
-*/
-
-static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int fdto, int sdto, int tldn, event_node_t **ehead)
-{
- int i,j;
- int res = 0;
- int checksum;
- char event[17];
- event_node_t *enew, *elp;
- int got_some_digits = 0;
- int events_received = 0;
- int ack_retries = 0;
-
- static char digit_map[15] = "0123456789*#ABC";
- static unsigned char digit_weights[15] = {10,1,2,3,4,5,6,7,8,9,11,12,13,14,15};
-
- database_increment("calls-received");
-
- /* Wait for first event */
-
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Waiting for first event from panel\n");
-
- while(res >= 0){
-
- if(got_some_digits == 0){
-
- /* Send ACK tone sequence */
-
-
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Sending 1400Hz 100ms burst (ACK)\n");
-
-
- res = send_tone_burst(chan, 1400.0, 100, tldn);
-
- if(!res)
- res = ast_safe_sleep(chan, 100);
-
- if(!res){
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Sending 2300Hz 100ms burst (ACK)\n");
-
- res = send_tone_burst(chan, 2300.0, 100, tldn);
- }
-
- }
-
- if( res >= 0)
- res = receive_dtmf_digits(chan, event, sizeof(event) - 1, fdto, sdto);
-
- if (res < 0){
-
- if(events_received == 0)
- /* Hangup with no events received should be logged in the DB */
- database_increment("no-events-received");
- else{
- if(ack_retries){
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_2 "AlarmReceiver: ACK retries during this call: %d\n", ack_retries);
-
- database_increment("ack-retries");
- }
- }
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: App exiting...\n");
- res = -1;
- break;
- }
-
- if(res != 0){
- /* Didn't get all of the digits */
- if(option_verbose >= 2)
- ast_verbose(VERBOSE_PREFIX_2 "AlarmReceiver: Incomplete string: %s, trying again...\n", event);
-
- if(!got_some_digits){
- got_some_digits = (!ast_strlen_zero(event)) ? 1 : 0;
- ack_retries++;
- }
- continue;
- }
-
- got_some_digits = 1;
-
- if(option_verbose >= 2)
- ast_verbose(VERBOSE_PREFIX_2 "AlarmReceiver: Received Event %s\n", event);
- ast_log(LOG_DEBUG, "AlarmReceiver: Received event: %s\n", event);
-
- /* Calculate checksum */
-
- for(j = 0, checksum = 0; j < 16; j++){
- for(i = 0 ; i < sizeof(digit_map) ; i++){
- if(digit_map[i] == event[j])
- break;
- }
-
- if(i == 16)
- break;
-
- checksum += digit_weights[i];
- }
-
- if(i == 16){
- if(option_verbose >= 2)
- ast_verbose(VERBOSE_PREFIX_2 "AlarmReceiver: Bad DTMF character %c, trying again\n", event[j]);
- continue; /* Bad character */
- }
-
- /* Checksum is mod(15) of the total */
-
- checksum = checksum % 15;
-
- if(checksum){
- database_increment("checksum-errors");
- if(option_verbose >= 2){
- ast_verbose(VERBOSE_PREFIX_2 "AlarmReceiver: Nonzero checksum\n");
- ast_log(LOG_DEBUG, "AlarmReceiver: Nonzero checksum\n");
- continue;
- }
- }
-
- /* Check the message type for correctness */
-
- if(strncmp(event + 4, "18", 2)){
- if(strncmp(event + 4, "98", 2)){
- database_increment("format-errors");
- if(option_verbose >= 2)
- ast_verbose(VERBOSE_PREFIX_2 "AlarmReceiver: Wrong message type\n");
- ast_log(LOG_DEBUG, "AlarmReceiver: Wrong message type\n");
- continue;
- }
- }
-
- events_received++;
-
- /* Queue the Event */
-
- if((enew = malloc(sizeof(event_node_t))) == NULL){
- if(option_verbose >= 1)
- ast_verbose(VERBOSE_PREFIX_1 "AlarmReceiver: Failed to allocate memory\n");
- ast_log(LOG_WARNING, "AlarmReceiver Failed to allocate memory\n");
- res = -1;
- break;
- }
-
- memset(enew, 0, sizeof(event_node_t));
-
- enew->next = NULL;
- ast_copy_string(enew->data, event, sizeof(enew->data));
-
- /*
- * Insert event onto end of list
- */
-
- if(*ehead == NULL){
- *ehead = enew;
- }
- else{
- for(elp = *ehead; elp->next != NULL; elp = elp->next)
- ;
-
- elp->next = enew;
- }
-
- if(res > 0)
- res = 0;
-
- /* Let the user have the option of logging the single event before sending the kissoff tone */
-
- if((res == 0) && (log_individual_events))
- res = log_events(chan, ADEMCO_CONTACT_ID, enew);
-
- /* Wait 200 msec before sending kissoff */
-
- if(res == 0)
- res = ast_safe_sleep(chan, 200);
-
- /* Send the kissoff tone */
-
- if(res == 0)
- res = send_tone_burst(chan, 1400.0, 900, tldn);
- }
-
-
- return res;
-}
-
-
-/*
-* This is the main function called by Asterisk Core whenever the App is invoked in the extension logic.
-* This function will always return 0.
-*/
-
-static int alarmreceiver_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- event_node_t *elp, *efree;
- char signalling_type[64] = "";
-
- event_node_t *event_head = NULL;
-
- LOCAL_USER_ADD(u);
-
- /* Set write and read formats to ULAW */
-
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Setting read and write formats to ULAW\n");
-
- 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);
- 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);
- return -1;
- }
-
- /* Set default values for this invokation of the application */
-
- ast_copy_string(signalling_type, ADEMCO_CONTACT_ID, sizeof(signalling_type));
-
-
- /* Answer the channel if it is not already */
-
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Answering channel\n");
-
- if (chan->_state != AST_STATE_UP) {
-
- res = ast_answer(chan);
-
- if (res) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
-
- /* Wait for the connection to settle post-answer */
-
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Waiting for connection to stabilize\n");
-
- res = ast_safe_sleep(chan, 1250);
-
- /* Attempt to receive the events */
-
- if(!res){
-
- /* Determine the protocol to receive in advance */
- /* Note: Ademco contact is the only one supported at this time */
- /* Others may be added later */
-
- if(!strcmp(signalling_type, ADEMCO_CONTACT_ID))
- receive_ademco_contact_id(chan, data, fdtimeout, sdtimeout, toneloudness, &event_head);
- else
- res = -1;
- }
-
-
-
- /* Events queued by receiver, write them all out here if so configured */
-
- if((!res) && (log_individual_events == 0)){
- res = log_events(chan, signalling_type, event_head);
-
- }
-
- /*
- * Do we exec a command line at the end?
- */
-
- if((!res) && (!ast_strlen_zero(event_app)) && (event_head)){
- ast_log(LOG_DEBUG,"Alarmreceiver: executing: %s\n", event_app);
- ast_safe_system(event_app);
- }
-
- /*
- * Free up the data allocated in our linked list
- */
-
- for(elp = event_head; (elp != NULL);){
- efree = elp;
- elp = elp->next;
- free(efree);
- }
-
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-/*
-* Load the configuration from the configuration file
-*/
-
-static int load_config(void)
-{
- struct ast_config *cfg;
- char *p;
-
- /* Read in the config file */
-
- cfg = ast_config_load(ALMRCV_CONFIG);
-
- if(!cfg){
-
- if(option_verbose >= 4)
- ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: No config file\n");
- }
- else{
-
-
- p = ast_variable_retrieve(cfg, "general", "eventcmd");
-
- if(p){
- ast_copy_string(event_app, p, sizeof(event_app));
- event_app[sizeof(event_app) - 1] = '\0';
- }
-
- p = ast_variable_retrieve(cfg, "general", "loudness");
- if(p){
- toneloudness = atoi(p);
- if(toneloudness < 100)
- toneloudness = 100;
- if(toneloudness > 8192)
- toneloudness = 8192;
- }
- p = ast_variable_retrieve(cfg, "general", "fdtimeout");
- if(p){
- fdtimeout = atoi(p);
- if(fdtimeout < 1000)
- fdtimeout = 1000;
- if(fdtimeout > 10000)
- fdtimeout = 10000;
- }
-
- p = ast_variable_retrieve(cfg, "general", "sdtimeout");
- if(p){
- sdtimeout = atoi(p);
- if(sdtimeout < 110)
- sdtimeout = 110;
- if(sdtimeout > 4000)
- sdtimeout = 4000;
-
- }
-
- p = ast_variable_retrieve(cfg, "general", "logindividualevents");
- if(p){
- log_individual_events = ast_true(p);
-
- }
-
- p = ast_variable_retrieve(cfg, "general", "eventspooldir");
-
- if(p){
- ast_copy_string(event_spool_dir, p, sizeof(event_spool_dir));
- event_spool_dir[sizeof(event_spool_dir) - 1] = '\0';
- }
-
- p = ast_variable_retrieve(cfg, "general", "timestampformat");
-
- if(p){
- ast_copy_string(time_stamp_format, p, sizeof(time_stamp_format));
- time_stamp_format[sizeof(time_stamp_format) - 1] = '\0';
- }
-
- p = ast_variable_retrieve(cfg, "general", "db-family");
-
- if(p){
- ast_copy_string(db_family, p, sizeof(db_family));
- db_family[sizeof(db_family) - 1] = '\0';
- }
- ast_config_destroy(cfg);
- }
- return 0;
-
-}
-
-/*
-* These functions are required to implement an Asterisk App.
-*/
-
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- load_config();
- return ast_register_application(app, alarmreceiver_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_authenticate.c b/1.2-netsec/apps/app_authenticate.c
deleted file mode 100644
index 583c5f4d3..000000000
--- a/1.2-netsec/apps/app_authenticate.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Execute arbitrary authenticate commands
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/app.h"
-#include "asterisk/astdb.h"
-#include "asterisk/utils.h"
-
-static char *tdesc = "Authentication Application";
-
-static char *app = "Authenticate";
-
-static char *synopsis = "Authenticate a user";
-
-static char *descrip =
-" Authenticate(password[|options]): This application asks the caller to enter a\n"
-"given password in order to continue dialplan execution. If the password begins\n"
-"with the '/' character, it is interpreted as a file which contains a list of\n"
-"valid passwords, listed 1 password per line in the file.\n"
-" When using a database key, the value associated with the key can be anything.\n"
-"Users have three attempts to authenticate before the channel is hung up. If the\n"
-"passsword is invalid, the 'j' option is specified, and priority n+101 exists,\n"
-"dialplan execution will continnue at this location.\n"
-" Options:\n"
-" a - Set the channels' account code to the password that is entered\n"
-" d - Interpret the given path as database key, not a literal file\n"
-" j - Support jumping to n+101 if authentication fails\n"
-" m - Interpret the given path as a file which contains a list of account\n"
-" codes and password hashes delimited with ':', listed one per line in\n"
-" the file. When one of the passwords is matched, the channel will have\n"
-" its account code set to the corresponding account code in the file.\n"
-" r - Remove the database key upon successful entry (valid with 'd' only)\n"
-;
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int auth_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- int jump = 0;
- int retries;
- struct localuser *u;
- char password[256]="";
- char passwd[256];
- char *opts;
- char *prompt;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Authenticate requires an argument(password)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (chan->_state != AST_STATE_UP) {
- res = ast_answer(chan);
- if (res) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
-
- strncpy(password, data, sizeof(password) - 1);
- opts=strchr(password, '|');
- if (opts) {
- *opts = 0;
- opts++;
- } else
- opts = "";
- if (strchr(opts, 'j'))
- jump = 1;
- /* Start asking for password */
- prompt = "agent-pass";
- for (retries = 0; retries < 3; retries++) {
- res = ast_app_getdata(chan, prompt, passwd, sizeof(passwd) - 2, 0);
- if (res < 0)
- break;
- res = 0;
- if (password[0] == '/') {
- if (strchr(opts, 'd')) {
- char tmp[256];
- /* Compare against a database key */
- if (!ast_db_get(password + 1, passwd, tmp, sizeof(tmp))) {
- /* It's a good password */
- if (strchr(opts, 'r')) {
- ast_db_del(password + 1, passwd);
- }
- break;
- }
- } else {
- /* Compare against a file */
- FILE *f;
- f = fopen(password, "r");
- if (f) {
- char buf[256] = "";
- char md5passwd[33] = "";
- char *md5secret = NULL;
-
- while (!feof(f)) {
- fgets(buf, sizeof(buf), f);
- if (!feof(f) && !ast_strlen_zero(buf)) {
- buf[strlen(buf) - 1] = '\0';
- if (strchr(opts, 'm')) {
- md5secret = strchr(buf, ':');
- if (md5secret == NULL)
- continue;
- *md5secret = '\0';
- md5secret++;
- ast_md5_hash(md5passwd, passwd);
- if (!strcmp(md5passwd, md5secret)) {
- if (strchr(opts, 'a'))
- ast_cdr_setaccount(chan, buf);
- break;
- }
- } else {
- if (!strcmp(passwd, buf)) {
- if (strchr(opts, 'a'))
- ast_cdr_setaccount(chan, buf);
- break;
- }
- }
- }
- }
- fclose(f);
- if (!ast_strlen_zero(buf)) {
- if (strchr(opts, 'm')) {
- if (md5secret && !strcmp(md5passwd, md5secret))
- break;
- } else {
- if (!strcmp(passwd, buf))
- break;
- }
- }
- } else
- ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", password, strerror(errno));
- }
- } else {
- /* Compare against a fixed password */
- if (!strcmp(passwd, password))
- break;
- }
- prompt="auth-incorrect";
- }
- if ((retries < 3) && !res) {
- if (strchr(opts, 'a') && !strchr(opts, 'm'))
- ast_cdr_setaccount(chan, passwd);
- res = ast_streamfile(chan, "auth-thankyou", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- } else {
- if (jump && ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
- res = 0;
- } else {
- if (!ast_streamfile(chan, "vm-goodbye", chan->language))
- res = ast_waitstream(chan, "");
- res = -1;
- }
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, auth_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_cdr.c b/1.2-netsec/apps/app_cdr.c
deleted file mode 100644
index 501bfc79b..000000000
--- a/1.2-netsec/apps/app_cdr.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Martin Pycko <martinp@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Applications connected with CDR engine
- *
- * \ingroup applications
- */
-
-#include <sys/types.h>
-#include <stdlib.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-
-
-static char *tdesc = "Tell Asterisk to not maintain a CDR for the current call";
-
-static char *nocdr_descrip =
-" NoCDR(): This application will tell Asterisk not to maintain a CDR for the\n"
-"current call.\n";
-
-static char *nocdr_app = "NoCDR";
-static char *nocdr_synopsis = "Tell Asterisk to not maintain a CDR for the current call";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int nocdr_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
-
- LOCAL_USER_ADD(u);
-
- if (chan->cdr) {
- ast_cdr_free(chan->cdr);
- chan->cdr = NULL;
- }
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(nocdr_app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(nocdr_app, nocdr_exec, nocdr_synopsis, nocdr_descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_chanisavail.c b/1.2-netsec/apps/app_chanisavail.c
deleted file mode 100644
index c55bb8ecb..000000000
--- a/1.2-netsec/apps/app_chanisavail.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
-* Asterisk -- An open source telephony toolkit.
-*
-* Copyright (C) 1999 - 2005, Digium, Inc.
-*
-* Mark Spencer <markster@digium.com>
-* James Golovich <james@gnuinter.net>
-*
-* 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 Check if Channel is Available
-*
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/app.h"
-#include "asterisk/devicestate.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Check channel availability";
-
-static char *app = "ChanIsAvail";
-
-static char *synopsis = "Check channel availability";
-
-static char *descrip =
-" ChanIsAvail(Technology/resource[&Technology2/resource2...][|options]): \n"
-"This application will check to see if any of the specified channels are\n"
-"available. The following variables will be set by this application:\n"
-" ${AVAILCHAN} - the name of the available channel, if one exists\n"
-" ${AVAILORIGCHAN} - the canonical channel name that was used to create the channel\n"
-" ${AVAILSTATUS} - the status code for the available channel\n"
-" Options:\n"
-" 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";
-
-STANDARD_LOCAL_USER;
-
-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;
- char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur, *options, *stringp;
- struct ast_channel *tempchan;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "ChanIsAvail requires an argument (Zap/1&Zap/2)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- info = ast_strdupa(data);
- stringp = info;
- strsep(&stringp, "|");
- options = strsep(&stringp, "|");
- if (options) {
- if (strchr(options, 's'))
- option_state = 1;
- if (strchr(options, 'j'))
- priority_jump = 1;
- }
- peers = info;
- if (peers) {
- cur = peers;
- do {
- /* remember where to start next time */
- rest = strchr(cur, '&');
- if (rest) {
- *rest = 0;
- rest++;
- }
- tech = cur;
- number = strchr(tech, '/');
- if (!number) {
- ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- *number = '\0';
- number++;
-
- if (option_state) {
- /* If the pbx says in use then don't bother trying further.
- This is to permit testing if someone's on a call, even if the
- channel can permit more calls (ie callwaiting, sip calls, etc). */
-
- snprintf(trychan, sizeof(trychan), "%s/%s",cur,number);
- status = inuse = ast_device_state(trychan);
- }
- if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) {
- pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name);
- /* Store the originally used channel too */
- snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);
- pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp);
- snprintf(tmp, sizeof(tmp), "%d", status);
- pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp);
- ast_hangup(tempchan);
- tempchan = NULL;
- res = 1;
- break;
- } else {
- snprintf(tmp, sizeof(tmp), "%d", status);
- pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp);
- }
- cur = rest;
- } while (cur);
- }
- if (res < 1) {
- pbx_builtin_setvar_helper(chan, "AVAILCHAN", "");
- pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", "");
- if (priority_jump || option_priority_jumping) {
- if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
- }
-
- LOCAL_USER_REMOVE(u);
- return 0;
-}
-
-int unload_module(void)
-{
- int res = 0;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, chanavail_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_chanspy.c b/1.2-netsec/apps/app_chanspy.c
deleted file mode 100644
index 299c58efc..000000000
--- a/1.2-netsec/apps/app_chanspy.c
+++ /dev/null
@@ -1,587 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005 Anthony Minessale II (anthmct@yahoo.com)
- *
- * Disclaimed to Digium
- *
- * 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 ChanSpy: Listen in on any channel.
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/chanspy.h"
-#include "asterisk/features.h"
-#include "asterisk/options.h"
-#include "asterisk/app.h"
-#include "asterisk/utils.h"
-#include "asterisk/say.h"
-#include "asterisk/pbx.h"
-#include "asterisk/translate.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-
-AST_MUTEX_DEFINE_STATIC(modlock);
-
-#define AST_NAME_STRLEN 256
-#define ALL_DONE(u, ret) LOCAL_USER_REMOVE(u); return ret;
-#define get_volfactor(x) x ? ((x > 0) ? (1 << x) : ((1 << abs(x)) * -1)) : 0
-
-static const char *synopsis = "Listen to the audio of an active channel\n";
-static const char *app = "ChanSpy";
-static const char *desc =
-" ChanSpy([chanprefix][|options]): This application is used to listen to the\n"
-"audio from an active Asterisk channel. This includes the audio coming in and\n"
-"out of the channel being spied on. If the 'chanprefix' parameter is specified,\n"
-"only channels beginning with this string will be spied upon.\n"
-" While Spying, the following actions may be performed:\n"
-" - Dialing # cycles the volume level.\n"
-" - Dialing * will stop spying and look for another channel to spy on.\n"
-" - Dialing a series of digits followed by # builds a channel name to append\n"
-" to 'chanprefix'. For example, executing ChanSpy(Agent) and then dialing\n"
-" the digits '1234#' while spying will begin spying on the channel,\n"
-" 'Agent/1234'.\n"
-" Options:\n"
-" b - Only spy on channels involved in a bridged call.\n"
-" g(grp) - Match only channels where their ${SPYGROUP} variable is set to\n"
-" 'grp'.\n"
-" q - Don't play a beep when beginning to spy on a channel.\n"
-" r[(basename)] - Record the session to the monitor spool directory. An\n"
-" optional base for the filename may be specified. The\n"
-" default is 'chanspy'.\n"
-" v([value]) - Adjust the initial volume in the range from -4 to 4. A\n"
-" negative value refers to a quieter setting.\n"
-;
-
-static const char *chanspy_spy_type = "ChanSpy";
-
-enum {
- OPTION_QUIET = (1 << 0), /* Quiet, no announcement */
- OPTION_BRIDGED = (1 << 1), /* Only look at bridged calls */
- OPTION_VOLUME = (1 << 2), /* Specify initial volume */
- OPTION_GROUP = (1 << 3), /* Only look at channels in group */
- OPTION_RECORD = (1 << 4), /* Record */
-} chanspy_opt_flags;
-
-enum {
- OPT_ARG_VOLUME = 0,
- OPT_ARG_GROUP,
- OPT_ARG_RECORD,
- OPT_ARG_ARRAY_SIZE,
-} chanspy_opt_args;
-
-AST_APP_OPTIONS(chanspy_opts, {
- AST_APP_OPTION('q', OPTION_QUIET),
- AST_APP_OPTION('b', OPTION_BRIDGED),
- AST_APP_OPTION_ARG('v', OPTION_VOLUME, OPT_ARG_VOLUME),
- AST_APP_OPTION_ARG('g', OPTION_GROUP, OPT_ARG_GROUP),
- AST_APP_OPTION_ARG('r', OPTION_RECORD, OPT_ARG_RECORD),
-});
-
-STANDARD_LOCAL_USER;
-LOCAL_USER_DECL;
-
-struct chanspy_translation_helper {
- /* spy data */
- struct ast_channel_spy spy;
- int fd;
- int volfactor;
-};
-
-static struct ast_channel *local_channel_walk(struct ast_channel *chan)
-{
- struct ast_channel *ret;
- ast_mutex_lock(&modlock);
- if ((ret = ast_channel_walk_locked(chan))) {
- ast_mutex_unlock(&ret->lock);
- }
- ast_mutex_unlock(&modlock);
- return ret;
-}
-
-static struct ast_channel *local_get_channel_begin_name(char *name)
-{
- struct ast_channel *chan, *ret = NULL;
- ast_mutex_lock(&modlock);
- chan = local_channel_walk(NULL);
- while (chan) {
- if (!strncmp(chan->name, name, strlen(name))) {
- ret = chan;
- break;
- }
- chan = local_channel_walk(chan);
- }
- ast_mutex_unlock(&modlock);
-
- return ret;
-}
-
-static void *spy_alloc(struct ast_channel *chan, void *data)
-{
- /* just store the data pointer in the channel structure */
- return data;
-}
-
-static void spy_release(struct ast_channel *chan, void *data)
-{
- /* nothing to do */
-}
-
-static int spy_generate(struct ast_channel *chan, void *data, int len, int samples)
-{
- struct chanspy_translation_helper *csth = data;
- struct ast_frame *f;
-
- if (csth->spy.status != CHANSPY_RUNNING)
- /* Channel is already gone more than likely */
- return -1;
-
- ast_mutex_lock(&csth->spy.lock);
- f = ast_channel_spy_read_frame(&csth->spy, samples);
- ast_mutex_unlock(&csth->spy.lock);
-
- if (!f)
- return 0;
-
- if (ast_write(chan, f)) {
- ast_frfree(f);
- return -1;
- }
-
- if (csth->fd)
- write(csth->fd, f->data, f->datalen);
-
- ast_frfree(f);
-
- return 0;
-}
-
-
-static struct ast_generator spygen = {
- .alloc = spy_alloc,
- .release = spy_release,
- .generate = spy_generate,
-};
-
-static int start_spying(struct ast_channel *chan, struct ast_channel *spychan, struct ast_channel_spy *spy)
-{
- int res;
- struct ast_channel *peer;
-
- ast_log(LOG_NOTICE, "Attaching %s to %s\n", spychan->name, chan->name);
-
- ast_mutex_lock(&chan->lock);
- res = ast_channel_spy_add(chan, spy);
- ast_mutex_unlock(&chan->lock);
-
- if (!res && ast_test_flag(chan, AST_FLAG_NBRIDGE) && (peer = ast_bridged_channel(chan))) {
- ast_softhangup(peer, AST_SOFTHANGUP_UNBRIDGE);
- }
-
- return res;
-}
-
-static void stop_spying(struct ast_channel *chan, struct ast_channel_spy *spy)
-{
- /* If our status has changed to DONE, then the channel we're spying on is gone....
- DON'T TOUCH IT!!! RUN AWAY!!! */
- if (spy->status == CHANSPY_DONE)
- return;
-
- if (!chan)
- return;
-
- ast_mutex_lock(&chan->lock);
- ast_channel_spy_remove(chan, spy);
- ast_mutex_unlock(&chan->lock);
-};
-
-/* Map 'volume' levels from -4 through +4 into
- decibel (dB) settings for channel drivers
-*/
-static signed char volfactor_map[] = {
- -24,
- -18,
- -12,
- -6,
- 0,
- 6,
- 12,
- 18,
- 24,
-};
-
-/* attempt to set the desired gain adjustment via the channel driver;
- if successful, clear it out of the csth structure so the
- generator will not attempt to do the adjustment itself
-*/
-static void set_volume(struct ast_channel *chan, struct chanspy_translation_helper *csth)
-{
- signed char volume_adjust = volfactor_map[csth->volfactor + 4];
-
- if (!ast_channel_setoption(chan, AST_OPTION_TXGAIN, &volume_adjust, sizeof(volume_adjust), 0))
- csth->volfactor = 0;
-}
-
-static int channel_spy(struct ast_channel *chan, struct ast_channel *spyee, int *volfactor, int fd)
-{
- struct chanspy_translation_helper csth;
- int running, res = 0, x = 0;
- char inp[24];
- char *name=NULL;
- struct ast_frame *f;
-
- running = (chan && !ast_check_hangup(chan) && spyee && !ast_check_hangup(spyee));
-
- if (running) {
- memset(inp, 0, sizeof(inp));
- name = ast_strdupa(spyee->name);
- if (option_verbose >= 2)
- ast_verbose(VERBOSE_PREFIX_2 "Spying on channel %s\n", name);
-
- memset(&csth, 0, sizeof(csth));
- ast_set_flag(&csth.spy, CHANSPY_FORMAT_AUDIO);
- ast_set_flag(&csth.spy, CHANSPY_TRIGGER_NONE);
- ast_set_flag(&csth.spy, CHANSPY_MIXAUDIO);
- csth.spy.type = chanspy_spy_type;
- csth.spy.status = CHANSPY_RUNNING;
- csth.spy.read_queue.format = AST_FORMAT_SLINEAR;
- csth.spy.write_queue.format = AST_FORMAT_SLINEAR;
- ast_mutex_init(&csth.spy.lock);
- csth.volfactor = *volfactor;
- set_volume(chan, &csth);
- csth.spy.read_vol_adjustment = csth.volfactor;
- csth.spy.write_vol_adjustment = csth.volfactor;
- csth.fd = fd;
-
- if (start_spying(spyee, chan, &csth.spy))
- running = 0;
- }
-
- if (running) {
- running = 1;
- ast_activate_generator(chan, &spygen, &csth);
-
- while (csth.spy.status == CHANSPY_RUNNING &&
- chan && !ast_check_hangup(chan) &&
- spyee &&
- !ast_check_hangup(spyee) &&
- running == 1 &&
- (res = ast_waitfor(chan, -1) > -1)) {
- if ((f = ast_read(chan))) {
- res = 0;
- if (f->frametype == AST_FRAME_DTMF) {
- res = f->subclass;
- }
- ast_frfree(f);
- if (!res) {
- continue;
- }
- } else {
- break;
- }
- if (x == sizeof(inp)) {
- x = 0;
- }
- if (res < 0) {
- running = -1;
- }
- if (res == 0) {
- continue;
- } else if (res == '*') {
- running = 0;
- } else if (res == '#') {
- if (!ast_strlen_zero(inp)) {
- running = x ? atoi(inp) : -1;
- break;
- } else {
- (*volfactor)++;
- if (*volfactor > 4) {
- *volfactor = -4;
- }
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Setting spy volume on %s to %d\n", chan->name, *volfactor);
- }
- csth.volfactor = *volfactor;
- set_volume(chan, &csth);
- csth.spy.read_vol_adjustment = csth.volfactor;
- csth.spy.write_vol_adjustment = csth.volfactor;
- }
- } else if (res >= 48 && res <= 57) {
- inp[x++] = res;
- }
- }
- ast_deactivate_generator(chan);
- stop_spying(spyee, &csth.spy);
-
- if (option_verbose >= 2) {
- ast_verbose(VERBOSE_PREFIX_2 "Done Spying on channel %s\n", name);
- }
- } else {
- running = 0;
- }
-
- ast_mutex_destroy(&csth.spy.lock);
-
- return running;
-}
-
-static int chanspy_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- struct ast_channel *peer=NULL, *prev=NULL;
- char name[AST_NAME_STRLEN],
- peer_name[AST_NAME_STRLEN + 5],
- *args,
- *ptr = NULL,
- *options = NULL,
- *spec = NULL,
- *argv[5],
- *mygroup = NULL,
- *recbase = NULL;
- int res = -1,
- volfactor = 0,
- silent = 0,
- argc = 0,
- bronly = 0,
- chosen = 0,
- count=0,
- waitms = 100,
- num = 0,
- oldrf = 0,
- oldwf = 0,
- fd = 0;
- struct ast_flags flags;
- signed char zero_volume = 0;
-
- if (!(args = ast_strdupa((char *)data))) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- oldrf = chan->readformat;
- oldwf = chan->writeformat;
- if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
- ast_log(LOG_ERROR, "Could Not Set Read Format.\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
- ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- ast_answer(chan);
-
- ast_set_flag(chan, AST_FLAG_SPYING); /* so nobody can spy on us while we are spying */
-
- if ((argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
- spec = argv[0];
- if ( argc > 1) {
- options = argv[1];
- }
- if (ast_strlen_zero(spec) || !strcmp(spec, "all")) {
- spec = NULL;
- }
- }
-
- if (options) {
- char *opts[OPT_ARG_ARRAY_SIZE];
- ast_app_parse_options(chanspy_opts, &flags, opts, options);
- if (ast_test_flag(&flags, OPTION_GROUP)) {
- mygroup = opts[1];
- }
- if (ast_test_flag(&flags, OPTION_RECORD)) {
- if (!(recbase = opts[2])) {
- recbase = "chanspy";
- }
- }
- silent = ast_test_flag(&flags, OPTION_QUIET);
- bronly = ast_test_flag(&flags, OPTION_BRIDGED);
- if (ast_test_flag(&flags, OPTION_VOLUME) && opts[1]) {
- int vol;
-
- if ((sscanf(opts[0], "%d", &vol) != 1) || (vol > 4) || (vol < -4))
- ast_log(LOG_NOTICE, "Volume factor must be a number between -4 and 4\n");
- else
- volfactor = vol;
- }
- }
-
- if (recbase) {
- char filename[512];
- snprintf(filename,sizeof(filename),"%s/%s.%d.raw",ast_config_AST_MONITOR_DIR, recbase, (int)time(NULL));
- if ((fd = open(filename, O_CREAT | O_WRONLY, O_TRUNC, 0644)) <= 0) {
- ast_log(LOG_WARNING, "Cannot open %s for recording\n", filename);
- fd = 0;
- }
- }
-
- for(;;) {
- if (!silent) {
- res = ast_streamfile(chan, "beep", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- if (res < 0) {
- ast_clear_flag(chan, AST_FLAG_SPYING);
- break;
- }
- }
-
- count = 0;
- res = ast_waitfordigit(chan, waitms);
- if (res < 0) {
- ast_clear_flag(chan, AST_FLAG_SPYING);
- break;
- }
-
- peer = local_channel_walk(NULL);
- prev=NULL;
- while(peer) {
- if (peer != chan) {
- char *group = NULL;
- int igrp = 1;
-
- if (peer == prev && !chosen) {
- break;
- }
- chosen = 0;
- group = pbx_builtin_getvar_helper(peer, "SPYGROUP");
- if (mygroup) {
- if (!group || strcmp(mygroup, group)) {
- igrp = 0;
- }
- }
-
- if (igrp && (!spec || ((strlen(spec) <= strlen(peer->name) &&
- !strncasecmp(peer->name, spec, strlen(spec)))))) {
- if (peer && (!bronly || ast_bridged_channel(peer)) &&
- !ast_check_hangup(peer) && !ast_test_flag(peer, AST_FLAG_SPYING)) {
- int x = 0;
- strncpy(peer_name, "spy-", 5);
- strncpy(peer_name + strlen(peer_name), peer->name, AST_NAME_STRLEN);
- ptr = strchr(peer_name, '/');
- *ptr = '\0';
- ptr++;
- for (x = 0 ; x < strlen(peer_name) ; x++) {
- if (peer_name[x] == '/') {
- break;
- }
- peer_name[x] = tolower(peer_name[x]);
- }
-
- if (!silent) {
- if (ast_fileexists(peer_name, NULL, NULL) != -1) {
- res = ast_streamfile(chan, peer_name, chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- if (res)
- break;
- } else
- res = ast_say_character_str(chan, peer_name, "", chan->language);
- if ((num=atoi(ptr)))
- ast_say_digits(chan, atoi(ptr), "", chan->language);
- }
- count++;
- prev = peer;
- res = channel_spy(chan, peer, &volfactor, fd);
- if (res == -1) {
- break;
- } else if (res > 1 && spec) {
- snprintf(name, AST_NAME_STRLEN, "%s/%d", spec, res);
- if ((peer = local_get_channel_begin_name(name))) {
- chosen = 1;
- }
- continue;
- }
- }
- }
- }
- if ((peer = local_channel_walk(peer)) == NULL) {
- break;
- }
- }
- waitms = count ? 100 : 5000;
- }
-
-
- if (fd > 0) {
- close(fd);
- }
-
- if (oldrf && ast_set_read_format(chan, oldrf) < 0) {
- ast_log(LOG_ERROR, "Could Not Set Read Format.\n");
- }
-
- if (oldwf && ast_set_write_format(chan, oldwf) < 0) {
- ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
- }
-
- ast_clear_flag(chan, AST_FLAG_SPYING);
-
- ast_channel_setoption(chan, AST_OPTION_TXGAIN, &zero_volume, sizeof(zero_volume), 0);
-
- ALL_DONE(u, res);
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, chanspy_exec, synopsis, desc);
-}
-
-char *description(void)
-{
- return (char *) synopsis;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_controlplayback.c b/1.2-netsec/apps/app_controlplayback.c
deleted file mode 100644
index 55a46ceb5..000000000
--- a/1.2-netsec/apps/app_controlplayback.c
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Trivial application to control playback of a sound file
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/app.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/utils.h"
-#include "asterisk/options.h"
-
-static const char *tdesc = "Control Playback Application";
-
-static const char *app = "ControlPlayback";
-
-static const char *synopsis = "Play a file with fast forward and rewind";
-
-static const char *descrip =
-" ControlPlayback(file[|skipms[|ff[|rew[|stop[|pause[|restart|options]]]]]]]):\n"
-"This application will play back the given filename. By default, the '*' key\n"
-"can be used to rewind, and the '#' key can be used to fast-forward.\n"
-"Parameters:\n"
-" skipms - This is number of milliseconds to skip when rewinding or\n"
-" fast-forwarding.\n"
-" ff - Fast-forward when this DTMF digit is received.\n"
-" rew - Rewind when this DTMF digit is received.\n"
-" stop - Stop playback when this DTMF digit is received.\n"
-" pause - Pause playback when this DTMF digit is received.\n"
-" restart - Restart playback when this DTMF digit is received.\n"
-"Options:\n"
-" j - Jump to priority n+101 if the requested file is not found.\n"
-"This application sets the following channel variable upon completion:\n"
-" CPLAYBACKSTATUS - This variable contains the status of the attempt as a text\n"
-" string, one of: SUCCESS | USERSTOPPED | ERROR\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int is_on_phonepad(char key)
-{
- return key == 35 || key == 42 || (key >= 48 && key <= 57);
-}
-
-static int controlplayback_exec(struct ast_channel *chan, void *data)
-{
- int res = 0, priority_jump = 0;
- int skipms = 0;
- struct localuser *u;
- char *tmp;
- int argc;
- char *argv[8];
- enum arg_ids {
- arg_file = 0,
- arg_skip = 1,
- arg_fwd = 2,
- arg_rev = 3,
- arg_stop = 4,
- arg_pause = 5,
- arg_restart = 6,
- options = 7,
- };
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- tmp = ast_strdupa(data);
- memset(argv, 0, sizeof(argv));
-
- argc = ast_app_separate_args(tmp, '|', argv, sizeof(argv) / sizeof(argv[0]));
-
- if (argc < 1) {
- ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- skipms = argv[arg_skip] ? atoi(argv[arg_skip]) : 3000;
- if (!skipms)
- skipms = 3000;
-
- if (!argv[arg_fwd] || !is_on_phonepad(*argv[arg_fwd]))
- argv[arg_fwd] = "#";
- if (!argv[arg_rev] || !is_on_phonepad(*argv[arg_rev]))
- argv[arg_rev] = "*";
- if (argv[arg_stop] && !is_on_phonepad(*argv[arg_stop]))
- argv[arg_stop] = NULL;
- if (argv[arg_pause] && !is_on_phonepad(*argv[arg_pause]))
- argv[arg_pause] = NULL;
- if (argv[arg_restart] && !is_on_phonepad(*argv[arg_restart]))
- argv[arg_restart] = NULL;
-
- if (argv[options]) {
- if (strchr(argv[options], 'j'))
- priority_jump = 1;
- }
-
- res = ast_control_streamfile(chan, argv[arg_file], argv[arg_fwd], argv[arg_rev], argv[arg_stop], argv[arg_pause], argv[arg_restart], skipms);
-
- /* If we stopped on one of our stop keys, return 0 */
- if (argv[arg_stop] && strchr(argv[arg_stop], res)) {
- res = 0;
- pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
- } else {
- if (res < 0) {
- if (priority_jump || option_priority_jumping) {
- if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
- ast_log(LOG_WARNING, "ControlPlayback tried to jump to priority n+101 as requested, but priority didn't exist\n");
- }
- }
- res = 0;
- pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
- } else
- pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
- }
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, controlplayback_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return (char *) tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_curl.c b/1.2-netsec/apps/app_curl.c
deleted file mode 100644
index 5cf4b167d..000000000
--- a/1.2-netsec/apps/app_curl.c
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005, Tilghman Lesher
- *
- * Tilghman Lesher <curl-20050919@the-tilghman.com>
- * and Brian Wilkins <bwilkins@cfl.rr.com> (Added POST option)
- *
- * app_curl.c is distributed with no restrictions on usage or
- * redistribution.
- *
- * 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.
- *
- */
-
-/*! \file
- * \brief Curl - App to load a URL
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <curl/curl.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/cli.h"
-#include "asterisk/options.h"
-#include "asterisk/module.h"
-
-static char *tdesc = "Load external URL";
-
-static char *app = "Curl";
-
-static char *synopsis = "Load an external URL";
-
-static char *descrip =
-" Curl(URL[|postdata]): This application will request the specified URL.\n"
-"It is mainly used for signalling external applications of an event.\n"
-"Parameters:\n"
-" URL - This is the external URL to request.\n"
-" postdata - This information will be treated as POST data.\n"
-"This application will set the following variable:\n"
-" CURL - This variable will contain the resulting page.\n"
-"This application has been deprecated in favor of the CURL function.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-struct MemoryStruct {
- char *memory;
- size_t size;
-};
-
-static void *myrealloc(void *ptr, size_t size)
-{
- /* There might be a realloc() out there that doesn't like reallocing
- NULL pointers, so we take care of it here */
- if (ptr)
- return realloc(ptr, size);
- else
- return malloc(size);
-}
-
-static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
-{
- register int realsize = size * nmemb;
- struct MemoryStruct *mem = (struct MemoryStruct *)data;
-
- mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
- if (mem->memory) {
- memcpy(&(mem->memory[mem->size]), ptr, realsize);
- mem->size += realsize;
- mem->memory[mem->size] = 0;
- }
- return realsize;
-}
-
-static int curl_internal(struct MemoryStruct *chunk, char *url, char *post)
-{
- CURL *curl;
-
- curl_global_init(CURL_GLOBAL_ALL);
- curl = curl_easy_init();
-
- if (!curl) {
- return -1;
- }
-
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)chunk);
- curl_easy_setopt(curl, CURLOPT_USERAGENT, "asterisk-libcurl-agent/1.0");
-
- if (post) {
- curl_easy_setopt(curl, CURLOPT_POST, 1);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post);
- }
-
- curl_easy_perform(curl);
- curl_easy_cleanup(curl);
- return 0;
-}
-
-static int curl_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- char *info, *post_data=NULL, *url;
- struct MemoryStruct chunk = { NULL, 0 };
- static int dep_warning = 0;
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "The application Curl is deprecated. Please use the CURL() function instead.\n");
- dep_warning = 1;
- }
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Curl requires an argument (URL)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if ((info = ast_strdupa(data))) {
- url = strsep(&info, "|");
- post_data = info;
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (! curl_internal(&chunk, url, post_data)) {
- if (chunk.memory) {
- chunk.memory[chunk.size] = '\0';
- if (chunk.memory[chunk.size - 1] == 10)
- chunk.memory[chunk.size - 1] = '\0';
-
- pbx_builtin_setvar_helper(chan, "CURL", chunk.memory);
-
- free(chunk.memory);
- }
- } else {
- ast_log(LOG_ERROR, "Cannot allocate curl structure\n");
- res = -1;
- }
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static char *acf_curl_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- struct localuser *u;
- char *info, *post_data=NULL, *url;
- struct MemoryStruct chunk = { NULL, 0 };
-
- *buf = '\0';
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "CURL requires an argument (URL)\n");
- return buf;
- }
-
- LOCAL_USER_ACF_ADD(u);
-
- info = ast_strdupa(data);
- if (!info) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return buf;
- }
-
- url = strsep(&info, "|");
- post_data = info;
-
- if (! curl_internal(&chunk, url, post_data)) {
- if (chunk.memory) {
- chunk.memory[chunk.size] = '\0';
- if (chunk.memory[chunk.size - 1] == 10)
- chunk.memory[chunk.size - 1] = '\0';
-
- ast_copy_string(buf, chunk.memory, len);
- free(chunk.memory);
- }
- } else {
- ast_log(LOG_ERROR, "Cannot allocate curl structure\n");
- }
-
- LOCAL_USER_REMOVE(u);
- return buf;
-}
-
-struct ast_custom_function acf_curl = {
- .name = "CURL",
- .synopsis = "Retrieves the contents of a URL",
- .syntax = "CURL(url[|post-data])",
- .desc =
- " url - URL to retrieve\n"
- " post-data - Optional data to send as a POST (GET is default action)\n",
- .read = acf_curl_exec,
-};
-
-int unload_module(void)
-{
- int res;
-
- res = ast_custom_function_unregister(&acf_curl);
- res |= ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_custom_function_register(&acf_curl);
- res |= ast_register_application(app, curl_exec, synopsis, descrip);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_cut.c b/1.2-netsec/apps/app_cut.c
deleted file mode 100644
index 46f934b89..000000000
--- a/1.2-netsec/apps/app_cut.c
+++ /dev/null
@@ -1,473 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (c) 2003 Tilghman Lesher. All rights reserved.
- *
- * Tilghman Lesher <app_cut__v003@the-tilghman.com>
- *
- * This code is released by the author with no restrictions on usage.
- *
- * 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.
- *
- */
-
-/*! \file
- * \brief Cut application
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/app.h"
-
-/* Maximum length of any variable */
-#define MAXRESULT 1024
-
-static char *tdesc = "Cut out information from a string";
-
-static char *app_cut = "Cut";
-
-static char *cut_synopsis = "Splits a variable's contents using the specified delimiter";
-
-static char *cut_descrip =
-" Cut(newvar=varname,delimiter,fieldspec): This applicaiton will split the\n"
-"contents of a variable based on the given delimeter and store the result in\n"
-"a new variable.\n"
-"Parameters:\n"
-" newvar - new variable created from result string\n"
-" varname - variable you want cut\n"
-" delimiter - defaults to '-'\n"
-" fieldspec - number of the field you want (1-based offset)\n"
-" may also be specified as a range (with -)\n"
-" or group of ranges and fields (with &)\n"
-"This application has been deprecated in favor of the CUT function.\n";
-
-static char *app_sort = "Sort";
-static char *app_sort_synopsis = "Sorts a list of keywords and values";
-static char *app_sort_descrip =
-" Sort(newvar=key1:val1[,key2:val2[[...],keyN:valN]]): This application will\n"
-"sort the list provided in ascending order. The result will be stored in the\n"
-"specified variable name.\n"
-" This applicaiton has been deprecated in favor of the SORT function.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-struct sortable_keys {
- char *key;
- float value;
-};
-
-static int sort_subroutine(const void *arg1, const void *arg2)
-{
- const struct sortable_keys *one=arg1, *two=arg2;
- if (one->value < two->value) {
- return -1;
- } else if (one->value == two->value) {
- return 0;
- } else {
- return 1;
- }
-}
-
-#define ERROR_NOARG (-1)
-#define ERROR_NOMEM (-2)
-#define ERROR_USAGE (-3)
-
-static int sort_internal(struct ast_channel *chan, char *data, char *buffer, size_t buflen)
-{
- char *strings, *ptrkey, *ptrvalue;
- int count=1, count2, element_count=0;
- struct sortable_keys *sortable_keys;
-
- memset(buffer, 0, buflen);
-
- if (!data) {
- return ERROR_NOARG;
- }
-
- strings = ast_strdupa((char *)data);
- if (!strings) {
- return ERROR_NOMEM;
- }
-
- for (ptrkey = strings; *ptrkey; ptrkey++) {
- if (*ptrkey == '|') {
- count++;
- }
- }
-
- sortable_keys = alloca(count * sizeof(struct sortable_keys));
- if (!sortable_keys) {
- return ERROR_NOMEM;
- }
-
- memset(sortable_keys, 0, count * sizeof(struct sortable_keys));
-
- /* Parse each into a struct */
- count2 = 0;
- while ((ptrkey = strsep(&strings, "|"))) {
- ptrvalue = index(ptrkey, ':');
- if (!ptrvalue) {
- count--;
- continue;
- }
- *ptrvalue = '\0';
- ptrvalue++;
- sortable_keys[count2].key = ptrkey;
- sscanf(ptrvalue, "%f", &sortable_keys[count2].value);
- count2++;
- }
-
- /* Sort the structs */
- qsort(sortable_keys, count, sizeof(struct sortable_keys), sort_subroutine);
-
- for (count2 = 0; count2 < count; count2++) {
- int blen = strlen(buffer);
- if (element_count++) {
- strncat(buffer + blen, ",", buflen - blen - 1);
- blen++;
- }
- strncat(buffer + blen, sortable_keys[count2].key, buflen - blen - 1);
- }
-
- return 0;
-}
-
-static int cut_internal(struct ast_channel *chan, char *data, char *buffer, size_t buflen)
-{
- char *s, *args[3], *varname=NULL, *delimiter=NULL, *field=NULL;
- int args_okay = 0;
-
- memset(buffer, 0, buflen);
-
- /* Check and parse arguments */
- if (data) {
- s = ast_strdupa((char *)data);
- if (s) {
- ast_app_separate_args(s, '|', args, 3);
- varname = args[0];
- delimiter = args[1];
- field = args[2];
-
- if (field) {
- args_okay = 1;
- }
- } else {
- return ERROR_NOMEM;
- }
- }
-
- if (args_okay) {
- char d, ds[2];
- char *tmp = alloca(strlen(varname) + 4);
- char varvalue[MAXRESULT], *tmp2=varvalue;
-
- if (tmp) {
- snprintf(tmp, strlen(varname) + 4, "${%s}", varname);
- memset(varvalue, 0, sizeof(varvalue));
- } else {
- return ERROR_NOMEM;
- }
-
- if (delimiter[0])
- d = delimiter[0];
- else
- d = '-';
-
- /* String form of the delimiter, for use with strsep(3) */
- snprintf(ds, sizeof(ds), "%c", d);
-
- pbx_substitute_variables_helper(chan, tmp, tmp2, MAXRESULT - 1);
-
- if (tmp2) {
- int curfieldnum = 1;
- while ((tmp2 != NULL) && (field != NULL)) {
- char *nextgroup = strsep(&field, "&");
- int num1 = 0, num2 = MAXRESULT;
- char trashchar;
-
- if (sscanf(nextgroup, "%d-%d", &num1, &num2) == 2) {
- /* range with both start and end */
- } else if (sscanf(nextgroup, "-%d", &num2) == 1) {
- /* range with end */
- num1 = 0;
- } else if ((sscanf(nextgroup, "%d%c", &num1, &trashchar) == 2) && (trashchar == '-')) {
- /* range with start */
- num2 = MAXRESULT;
- } else if (sscanf(nextgroup, "%d", &num1) == 1) {
- /* single number */
- num2 = num1;
- } else {
- return ERROR_USAGE;
- }
-
- /* Get to start, if any */
- if (num1 > 0) {
- while ((tmp2 != (char *)NULL + 1) && (curfieldnum < num1)) {
- tmp2 = index(tmp2, d) + 1;
- curfieldnum++;
- }
- }
-
- /* Most frequent problem is the expectation of reordering fields */
- if ((num1 > 0) && (curfieldnum > num1)) {
- ast_log(LOG_WARNING, "We're already past the field you wanted?\n");
- }
-
- /* Re-null tmp2 if we added 1 to NULL */
- if (tmp2 == (char *)NULL + 1)
- tmp2 = NULL;
-
- /* Output fields until we either run out of fields or num2 is reached */
- while ((tmp2 != NULL) && (curfieldnum <= num2)) {
- char *tmp3 = strsep(&tmp2, ds);
- int curlen = strlen(buffer);
-
- if (curlen) {
- snprintf(buffer + curlen, buflen - curlen, "%c%s", d, tmp3);
- } else {
- snprintf(buffer, buflen, "%s", tmp3);
- }
-
- curfieldnum++;
- }
- }
- }
- } else {
- return ERROR_NOARG;
- }
- return 0;
-}
-
-static int sort_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *varname, *strings, result[512] = "";
- static int dep_warning=0;
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "The application Sort is deprecated. Please use the SORT() function instead.\n");
- dep_warning=1;
- }
-
- if (!data) {
- ast_log(LOG_ERROR, "Sort() requires an argument\n");
- return 0;
- }
-
- LOCAL_USER_ADD(u);
-
- strings = ast_strdupa((char *)data);
- if (!strings) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- varname = strsep(&strings, "=");
- switch (sort_internal(chan, strings, result, sizeof(result))) {
- case ERROR_NOARG:
- ast_log(LOG_ERROR, "Sort() requires an argument\n");
- res = 0;
- break;
- case ERROR_NOMEM:
- ast_log(LOG_ERROR, "Out of memory\n");
- res = -1;
- break;
- case 0:
- pbx_builtin_setvar_helper(chan, varname, result);
- res = 0;
- break;
- default:
- ast_log(LOG_ERROR, "Unknown internal error\n");
- res = -1;
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int cut_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *s, *newvar=NULL, result[512];
- static int dep_warning = 0;
-
- LOCAL_USER_ADD(u);
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "The application Cut is deprecated. Please use the CUT() function instead.\n");
- dep_warning=1;
- }
-
- /* Check and parse arguments */
- if (data) {
- s = ast_strdupa((char *)data);
- if (s) {
- newvar = strsep(&s, "=");
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
-
- switch (cut_internal(chan, s, result, sizeof(result))) {
- case ERROR_NOARG:
- ast_log(LOG_ERROR, "Cut() requires an argument\n");
- res = 0;
- break;
- case ERROR_NOMEM:
- ast_log(LOG_ERROR, "Out of memory\n");
- res = -1;
- break;
- case ERROR_USAGE:
- ast_log(LOG_ERROR, "Usage: %s\n", cut_synopsis);
- res = 0;
- break;
- case 0:
- pbx_builtin_setvar_helper(chan, newvar, result);
- res = 0;
- break;
- default:
- ast_log(LOG_ERROR, "Unknown internal error\n");
- res = -1;
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static char *acf_sort_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- struct localuser *u;
-
- LOCAL_USER_ACF_ADD(u);
-
- switch (sort_internal(chan, data, buf, len)) {
- case ERROR_NOARG:
- ast_log(LOG_ERROR, "SORT() requires an argument\n");
- break;
- case ERROR_NOMEM:
- ast_log(LOG_ERROR, "Out of memory\n");
- break;
- case 0:
- break;
- default:
- ast_log(LOG_ERROR, "Unknown internal error\n");
- }
- LOCAL_USER_REMOVE(u);
- return buf;
-}
-
-static char *acf_cut_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- struct localuser *u;
-
- LOCAL_USER_ACF_ADD(u);
-
- switch (cut_internal(chan, data, buf, len)) {
- case ERROR_NOARG:
- ast_log(LOG_ERROR, "CUT() requires an argument\n");
- break;
- case ERROR_NOMEM:
- ast_log(LOG_ERROR, "Out of memory\n");
- break;
- case ERROR_USAGE:
- ast_log(LOG_ERROR, "Usage: %s\n", cut_synopsis);
- break;
- case 0:
- break;
- default:
- ast_log(LOG_ERROR, "Unknown internal error\n");
- }
- LOCAL_USER_REMOVE(u);
- return buf;
-}
-
-struct ast_custom_function acf_sort = {
- .name = "SORT",
- .synopsis = "Sorts a list of key/vals into a list of keys, based upon the vals",
- .syntax = "SORT(key1:val1[...][,keyN:valN])",
- .desc =
-"Takes a comma-separated list of keys and values, each separated by a colon, and returns a\n"
-"comma-separated list of the keys, sorted by their values. Values will be evaluated as\n"
-"floating-point numbers.\n",
- .read = acf_sort_exec,
-};
-
-struct ast_custom_function acf_cut = {
- .name = "CUT",
- .synopsis = "Slices and dices strings, based upon a named delimiter.",
- .syntax = "CUT(<varname>,<char-delim>,<range-spec>)",
- .desc =
-" varname - variable you want cut\n"
-" char-delim - defaults to '-'\n"
-" range-spec - number of the field you want (1-based offset)\n"
-" may also be specified as a range (with -)\n"
-" or group of ranges and fields (with &)\n",
- .read = acf_cut_exec,
-};
-
-int unload_module(void)
-{
- int res;
-
- res = ast_custom_function_unregister(&acf_cut);
- res |= ast_custom_function_unregister(&acf_sort);
- res |= ast_unregister_application(app_sort);
- res |= ast_unregister_application(app_cut);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_custom_function_register(&acf_cut);
- res |= ast_custom_function_register(&acf_sort);
- res |= ast_register_application(app_sort, sort_exec, app_sort_synopsis, app_sort_descrip);
- res |= ast_register_application(app_cut, cut_exec, cut_synopsis, cut_descrip);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_datetime.c b/1.2-netsec/apps/app_datetime.c
deleted file mode 100644
index b10ad97e6..000000000
--- a/1.2-netsec/apps/app_datetime.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Time of day - Report the time of day
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/say.h"
-
-static char *tdesc = "Date and Time";
-
-static char *app = "DateTime";
-
-static char *synopsis = "Say the date and time";
-
-static char *descrip =
-" DateTime(): This application will say the current date and time.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int datetime_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- time_t t;
- struct localuser *u;
- LOCAL_USER_ADD(u);
- time(&t);
- if (chan->_state != AST_STATE_UP)
- res = ast_answer(chan);
- if (!res)
- res = ast_say_datetime(chan, t, "", chan->language);
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, datetime_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_db.c b/1.2-netsec/apps/app_db.c
deleted file mode 100644
index 245c8d3ca..000000000
--- a/1.2-netsec/apps/app_db.c
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- * Copyright (C) 2003, Jefferson Noxon
- *
- * Mark Spencer <markster@digium.com>
- * Jefferson Noxon <jeff@debian.org>
- *
- * 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 Database access functions
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/options.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/astdb.h"
-#include "asterisk/lock.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Database Access Functions";
-
-static char *g_descrip =
-" DBget(varname=family/key[|options]): This application will retrieve a value\n"
-"from the Asterisk database and store it in the given variable.\n"
-" Options:\n"
-" j - Jump to priority n+101 if the requested family/key isn't found.\n"
-" This application sets the following channel variable upon completion:\n"
-" DBGETSTATUS - This variable will contain the status of the attempt\n"
-" FOUND | NOTFOUND \n"
-" This application has been deprecated in favor of the DB function.\n";
-
-static char *p_descrip =
-" DBput(family/key=value): This application will store the given value in the\n"
-"specified location in the Asterisk database.\n"
-" This application has been deprecated in favor of the DB function.\n";
-
-static char *d_descrip =
-" DBdel(family/key): This applicaiton will delete a key from the Asterisk\n"
-"database.\n";
-
-static char *dt_descrip =
-" DBdeltree(family[/keytree]): This application will delete a family or keytree\n"
-"from the Asterisk database\n";
-
-static char *g_app = "DBget";
-static char *p_app = "DBput";
-static char *d_app = "DBdel";
-static char *dt_app = "DBdeltree";
-
-static char *g_synopsis = "Retrieve a value from the database";
-static char *p_synopsis = "Store a value in the database";
-static char *d_synopsis = "Delete a key from the database";
-static char *dt_synopsis = "Delete a family or keytree from the database";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int deltree_exec(struct ast_channel *chan, void *data)
-{
- char *argv, *family, *keytree;
- struct localuser *u;
-
- LOCAL_USER_ADD(u);
-
- argv = ast_strdupa(data);
- if (!argv) {
- ast_log(LOG_ERROR, "Memory allocation failed\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- if (strchr(argv, '/')) {
- family = strsep(&argv, "/");
- keytree = strsep(&argv, "\0");
- if (!family || !keytree) {
- ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- if (ast_strlen_zero(keytree))
- keytree = 0;
- } else {
- family = argv;
- keytree = 0;
- }
-
- if (option_verbose > 2) {
- if (keytree)
- ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: family=%s, keytree=%s\n", family, keytree);
- else
- ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: family=%s\n", family);
- }
-
- if (ast_db_deltree(family, keytree)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: Error deleting key from database.\n");
- }
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-static int del_exec(struct ast_channel *chan, void *data)
-{
- char *argv, *family, *key;
- struct localuser *u;
-
- LOCAL_USER_ADD(u);
-
- argv = ast_strdupa(data);
- if (!argv) {
- ast_log (LOG_ERROR, "Memory allocation failed\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- if (strchr(argv, '/')) {
- family = strsep(&argv, "/");
- key = strsep(&argv, "\0");
- if (!family || !key) {
- ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "DBdel: family=%s, key=%s\n", family, key);
- if (ast_db_del(family, key)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "DBdel: Error deleting key from database.\n");
- }
- } else {
- ast_log(LOG_DEBUG, "Ignoring, no parameters\n");
- }
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-static int put_exec(struct ast_channel *chan, void *data)
-{
- char *argv, *value, *family, *key;
- static int dep_warning = 0;
- struct localuser *u;
-
- LOCAL_USER_ADD(u);
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "This application has been deprecated, please use the ${DB(family/key)} function instead.\n");
- dep_warning = 1;
- }
-
- argv = ast_strdupa(data);
- if (!argv) {
- ast_log(LOG_ERROR, "Memory allocation failed\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- if (strchr(argv, '/') && strchr(argv, '=')) {
- family = strsep(&argv, "/");
- key = strsep(&argv, "=");
- value = strsep(&argv, "\0");
- if (!value || !family || !key) {
- ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "DBput: family=%s, key=%s, value=%s\n", family, key, value);
- if (ast_db_put(family, key, value)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "DBput: Error writing value to database.\n");
- }
-
- } else {
- ast_log (LOG_DEBUG, "Ignoring, no parameters\n");
- }
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-static int get_exec(struct ast_channel *chan, void *data)
-{
- char *argv, *varname, *family, *key, *options = NULL;
- char dbresult[256];
- static int dep_warning = 0;
- int priority_jump = 0;
- struct localuser *u;
-
- LOCAL_USER_ADD(u);
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "This application has been deprecated, please use the ${DB(family/key)} function instead.\n");
- dep_warning = 1;
- }
-
- argv = ast_strdupa(data);
- if (!argv) {
- ast_log(LOG_ERROR, "Memory allocation failed\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- if (strchr(argv, '=') && strchr(argv, '/')) {
- varname = strsep(&argv, "=");
- family = strsep(&argv, "/");
- if (strchr((void *)&argv, '|')) {
- key = strsep(&argv, "|");
- options = strsep(&argv, "\0");
- } else
- key = strsep(&argv, "\0");
-
- if (!varname || !family || !key) {
- ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- if (options) {
- if (strchr(options, 'j'))
- priority_jump = 1;
- }
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "DBget: varname=%s, family=%s, key=%s\n", varname, family, key);
- if (!ast_db_get(family, key, dbresult, sizeof (dbresult) - 1)) {
- pbx_builtin_setvar_helper(chan, varname, dbresult);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "DBget: set variable %s to %s\n", varname, dbresult);
- pbx_builtin_setvar_helper(chan, "DBGETSTATUS", "FOUND");
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "DBget: Value not found in database.\n");
- if (priority_jump || option_priority_jumping) {
- /* Send the call to n+101 priority, where n is the current priority */
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- }
- pbx_builtin_setvar_helper(chan, "DBGETSTATUS", "NOTFOUND");
- }
- } else {
- ast_log(LOG_DEBUG, "Ignoring, no parameters\n");
- }
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-int unload_module(void)
-{
- int retval;
-
- retval = ast_unregister_application(dt_app);
- retval |= ast_unregister_application(d_app);
- retval |= ast_unregister_application(p_app);
- retval |= ast_unregister_application(g_app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return retval;
-}
-
-int load_module(void)
-{
- int retval;
-
- retval = ast_register_application(g_app, get_exec, g_synopsis, g_descrip);
- retval |= ast_register_application(p_app, put_exec, p_synopsis, p_descrip);
- 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;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_dial.c b/1.2-netsec/apps/app_dial.c
deleted file mode 100644
index 4ef6cad83..000000000
--- a/1.2-netsec/apps/app_dial.c
+++ /dev/null
@@ -1,1747 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief dial() & retrydial() - Trivial application to dial a channel and send an URL on answer
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/signal.h>
-#include <netinet/in.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/say.h"
-#include "asterisk/config.h"
-#include "asterisk/features.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/callerid.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/causes.h"
-#include "asterisk/manager.h"
-#include "asterisk/privacy.h"
-
-static char *tdesc = "Dialing Application";
-
-static char *app = "Dial";
-
-static char *synopsis = "Place a call and connect to the current channel";
-
-static char *descrip =
-" Dial(Technology/resource[&Tech2/resource2...][|timeout][|options][|URL]):\n"
-"This applicaiton will place calls to one or more specified channels. As soon\n"
-"as one of the requested channels answers, the originating channel will be\n"
-"answered, if it has not already been answered. These two channels will then\n"
-"be active in a bridged call. All other channels that were requested will then\n"
-"be hung up.\n"
-" Unless there is a timeout specified, the Dial application will wait\n"
-"indefinitely until one of the called channels answers, the user hangs up, or\n"
-"if all of the called channels are busy or unavailable. Dialplan executing will\n"
-"continue if no requested channels can be called, or if the timeout expires.\n\n"
-" This application sets the following channel variables upon completion:\n"
-" DIALEDTIME - This is the time from dialing a channel until when it\n"
-" is disconnected.\n"
-" ANSWEREDTIME - This is the amount of time for actual call.\n"
-" DIALSTATUS - This is the status of the call:\n"
-" CHANUNAVAIL | CONGESTION | NOANSWER | BUSY | ANSWER | CANCEL\n"
-" DONTCALL | TORTURE\n"
-" For the Privacy and Screening Modes, the DIALSTATUS variable will be set to\n"
-"DONTCALL if the called party chooses to send the calling party to the 'Go Away'\n"
-"script. The DIALSTATUS variable will be set to TORTURE if the called party\n"
-"wants to send the caller to the 'torture' script.\n"
-" This application will report normal termination if the originating channel\n"
-"hangs up, or if the call is bridged and either of the parties in the bridge\n"
-"ends the call.\n"
-" The optional URL will be sent to the called party if the channel supports it.\n"
-" If the OUTBOUND_GROUP variable is set, all peer channels created by this\n"
-"application will be put into that group (as in Set(GROUP()=...).\n\n"
-" Options:\n"
-" A(x) - Play an announcement to the called party, using 'x' as the file.\n"
-" C - Reset the CDR for this call.\n"
-" d - Allow the calling user to dial a 1 digit extension while waiting for\n"
-" a call to be answered. Exit to that extension if it exists in the\n"
-" current context, or the context defined in the EXITCONTEXT variable,\n"
-" if it exists.\n"
-" D([called][:calling]) - Send the specified DTMF strings *after* the called\n"
-" party has answered, but before the call gets bridged. The 'called'\n"
-" DTMF string is sent to the called party, and the 'calling' DTMF\n"
-" string is sent to the calling party. Both parameters can be used\n"
-" alone.\n"
-" f - Force the callerid of the *calling* channel to be set as the\n"
-" extension associated with the channel using a dialplan 'hint'.\n"
-" For example, some PSTNs do not allow CallerID to be set to anything\n"
-" other than the number assigned to the caller.\n"
-" g - Proceed with dialplan execution at the current extension if the\n"
-" destination channel hangs up.\n"
-" G(context^exten^pri) - If the call is answered, transfer both parties to\n"
-" the specified priority. Optionally, an extension, or extension and\n"
-" context may be specified. Otherwise, the current extension is used.\n"
-" h - Allow the called party to hang up by sending the '*' DTMF digit.\n"
-" H - Allow the calling party to hang up by hitting the '*' DTMF digit.\n"
-" j - Jump to priority n+101 if all of the requested channels were busy.\n"
-" L(x[:y][:z]) - Limit the call to 'x' ms. Play a warning when 'y' ms are\n"
-" left. Repeat the warning every 'z' ms. The following special\n"
-" variables can be used with this option:\n"
-" * LIMIT_PLAYAUDIO_CALLER yes|no (default yes)\n"
-" Play sounds to the caller.\n"
-" * LIMIT_PLAYAUDIO_CALLEE yes|no\n"
-" Play sounds to the callee.\n"
-" * LIMIT_TIMEOUT_FILE File to play when time is up.\n"
-" * LIMIT_CONNECT_FILE File to play when call begins.\n"
-" * LIMIT_WARNING_FILE File to play as warning if 'y' is defined.\n"
-" The default is to say the time remaining.\n"
-" m([class]) - Provide hold music to the calling party until a requested\n"
-" channel answers. A specific MusicOnHold class can be\n"
-" specified.\n"
-" M(x[^arg]) - Execute the Macro for the *called* channel before connecting\n"
-" to the calling channel. Arguments can be specified to the Macro\n"
-" using '^' as a delimeter. The Macro can set the variable\n"
-" MACRO_RESULT to specify the following actions after the Macro is\n"
-" finished executing.\n"
-" * ABORT Hangup both legs of the call.\n"
-" * CONGESTION Behave as if line congestion was encountered.\n"
-" * BUSY Behave as if a busy signal was encountered. This will also\n"
-" have the application jump to priority n+101 if the\n"
-" 'j' option is set.\n"
-" * CONTINUE Hangup the called party and allow the calling party\n"
-" to continue dialplan execution at the next priority.\n"
-" * GOTO:<context>^<exten>^<priority> - Transfer the call to the\n"
-" specified priority. Optionally, an extension, or\n"
-" extension and priority can be specified.\n"
-" n - This option is a modifier for the screen/privacy mode. It specifies\n"
-" that no introductions are to be saved in the priv-callerintros\n"
-" directory.\n"
-" N - This option is a modifier for the screen/privacy mode. It specifies\n"
-" that if callerID is present, do not screen the call.\n"
-" o - Specify that the CallerID that was present on the *calling* channel\n"
-" be set as the CallerID on the *called* channel. This was the\n"
-" behavior of Asterisk 1.0 and earlier.\n"
-" p - This option enables screening mode. This is basically Privacy mode\n"
-" without memory.\n"
-" P([x]) - Enable privacy mode. Use 'x' as the family/key in the database if\n"
-" it is provided. The current extension is used if a database\n"
-" family/key is not specified.\n"
-" r - Indicate ringing to the calling party. Pass no audio to the calling\n"
-" party until the called channel has answered.\n"
-" S(x) - Hang up the call after 'x' seconds *after* the called party has\n"
-" answered the call.\n"
-" t - Allow the called party to transfer the calling party by sending the\n"
-" DTMF sequence defined in features.conf.\n"
-" T - Allow the calling party to transfer the called party by sending the\n"
-" DTMF sequence defined in features.conf.\n"
-" w - Allow the called party to enable recording of the call by sending\n"
-" the DTMF sequence defined for one-touch recording in features.conf.\n"
-" W - Allow the calling party to enable recording of the call by sending\n"
-" the DTMF sequence defined for one-touch recording in features.conf.\n";
-
-/* RetryDial App by Anthony Minessale II <anthmct@yahoo.com> Jan/2005 */
-static char *rapp = "RetryDial";
-static char *rsynopsis = "Place a call, retrying on failure allowing optional exit extension.";
-static char *rdescrip =
-" RetryDial(announce|sleep|retries|dialargs): This application will attempt to\n"
-"place a call using the normal Dial application. If no channel can be reached,\n"
-"the 'announce' file will be played. Then, it will wait 'sleep' number of\n"
-"seconds before retying the call. After 'retires' number of attempts, the\n"
-"calling channel will continue at the next priority in the dialplan. If the\n"
-"'retries' setting is set to 0, this application will retry endlessly.\n"
-" While waiting to retry a call, a 1 digit extension may be dialed. If that\n"
-"extension exists in either the context defined in ${EXITCONTEXT} or the current\n"
-"one, The call will jump to that extension immediately.\n"
-" The 'dialargs' are specified in the same format that arguments are provided\n"
-"to the Dial application.\n";
-
-enum {
- OPT_ANNOUNCE = (1 << 0),
- OPT_RESETCDR = (1 << 1),
- OPT_DTMF_EXIT = (1 << 2),
- OPT_SENDDTMF = (1 << 3),
- OPT_FORCECLID = (1 << 4),
- OPT_GO_ON = (1 << 5),
- OPT_CALLEE_HANGUP = (1 << 6),
- OPT_CALLER_HANGUP = (1 << 7),
- OPT_PRIORITY_JUMP = (1 << 8),
- OPT_DURATION_LIMIT = (1 << 9),
- OPT_MUSICBACK = (1 << 10),
- OPT_CALLEE_MACRO = (1 << 11),
- OPT_SCREEN_NOINTRO = (1 << 12),
- OPT_SCREEN_NOCLID = (1 << 13),
- OPT_ORIGINAL_CLID = (1 << 14),
- OPT_SCREENING = (1 << 15),
- OPT_PRIVACY = (1 << 16),
- OPT_RINGBACK = (1 << 17),
- OPT_DURATION_STOP = (1 << 18),
- OPT_CALLEE_TRANSFER = (1 << 19),
- OPT_CALLER_TRANSFER = (1 << 20),
- OPT_CALLEE_MONITOR = (1 << 21),
- OPT_CALLER_MONITOR = (1 << 22),
- OPT_GOTO = (1 << 23),
-} dial_exec_option_flags;
-
-#define DIAL_STILLGOING (1 << 30)
-#define DIAL_NOFORWARDHTML (1 << 31)
-
-enum {
- OPT_ARG_ANNOUNCE = 0,
- OPT_ARG_SENDDTMF,
- OPT_ARG_GOTO,
- OPT_ARG_DURATION_LIMIT,
- OPT_ARG_MUSICBACK,
- OPT_ARG_CALLEE_MACRO,
- OPT_ARG_PRIVACY,
- OPT_ARG_DURATION_STOP,
- /* note: this entry _MUST_ be the last one in the enum */
- OPT_ARG_ARRAY_SIZE,
-} dial_exec_option_args;
-
-AST_APP_OPTIONS(dial_exec_options, {
- AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE),
- AST_APP_OPTION('C', OPT_RESETCDR),
- AST_APP_OPTION('d', OPT_DTMF_EXIT),
- AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
- AST_APP_OPTION('f', OPT_FORCECLID),
- AST_APP_OPTION('g', OPT_GO_ON),
- AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
- AST_APP_OPTION('h', OPT_CALLEE_HANGUP),
- AST_APP_OPTION('H', OPT_CALLER_HANGUP),
- AST_APP_OPTION('j', OPT_PRIORITY_JUMP),
- AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
- AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK),
- AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO),
- AST_APP_OPTION('n', OPT_SCREEN_NOINTRO),
- AST_APP_OPTION('N', OPT_SCREEN_NOCLID),
- AST_APP_OPTION('o', OPT_ORIGINAL_CLID),
- AST_APP_OPTION('p', OPT_SCREENING),
- AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY),
- AST_APP_OPTION('r', OPT_RINGBACK),
- AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP),
- AST_APP_OPTION('t', OPT_CALLEE_TRANSFER),
- AST_APP_OPTION('T', OPT_CALLER_TRANSFER),
- AST_APP_OPTION('w', OPT_CALLEE_MONITOR),
- AST_APP_OPTION('W', OPT_CALLER_MONITOR),
-});
-
-/* We define a custom "local user" structure because we
- use it not only for keeping track of what is in use but
- also for keeping track of who we're dialing. */
-
-struct localuser {
- struct ast_channel *chan;
- unsigned int flags;
- int forwards;
- struct localuser *next;
-};
-
-LOCAL_USER_DECL;
-
-static void hanguptree(struct localuser *outgoing, struct ast_channel *exception)
-{
- /* Hang up a tree of stuff */
- struct localuser *oo;
- while (outgoing) {
- /* Hangup any existing lines we have open */
- if (outgoing->chan && (outgoing->chan != exception))
- ast_hangup(outgoing->chan);
- oo = outgoing;
- outgoing=outgoing->next;
- free(oo);
- }
-}
-
-#define AST_MAX_FORWARDS 8
-
-#define AST_MAX_WATCHERS 256
-
-#define HANDLE_CAUSE(cause, chan) do { \
- switch(cause) { \
- case AST_CAUSE_BUSY: \
- if (chan->cdr) \
- ast_cdr_busy(chan->cdr); \
- numbusy++; \
- break; \
- case AST_CAUSE_CONGESTION: \
- if (chan->cdr) \
- ast_cdr_failed(chan->cdr); \
- numcongestion++; \
- break; \
- case AST_CAUSE_UNREGISTERED: \
- if (chan->cdr) \
- ast_cdr_failed(chan->cdr); \
- numnochan++; \
- break; \
- default: \
- numnochan++; \
- break; \
- } \
-} while (0)
-
-
-static int onedigit_goto(struct ast_channel *chan, char *context, char exten, int pri)
-{
- char rexten[2] = { exten, '\0' };
-
- if (context) {
- if (!ast_goto_if_exists(chan, context, rexten, pri))
- return 1;
- } else {
- if (!ast_goto_if_exists(chan, chan->context, rexten, pri))
- return 1;
- else if (!ast_strlen_zero(chan->macrocontext)) {
- if (!ast_goto_if_exists(chan, chan->macrocontext, rexten, pri))
- return 1;
- }
- }
- return 0;
-}
-
-
-static char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
-{
- char *context;
- char *exten;
- if (!ast_strlen_zero(chan->macrocontext))
- context = chan->macrocontext;
- else
- context = chan->context;
-
- if (!ast_strlen_zero(chan->macroexten))
- exten = chan->macroexten;
- else
- exten = chan->exten;
-
- if (ast_get_hint(NULL, 0, name, namelen, chan, context, exten))
- return name;
- else
- return "";
-}
-
-static void senddialevent(struct ast_channel *src, struct ast_channel *dst)
-{
- manager_event(EVENT_FLAG_CALL, "Dial",
- "Source: %s\r\n"
- "Destination: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- "SrcUniqueID: %s\r\n"
- "DestUniqueID: %s\r\n",
- src->name, dst->name, src->cid.cid_num ? src->cid.cid_num : "<unknown>",
- src->cid.cid_name ? src->cid.cid_name : "<unknown>", src->uniqueid,
- dst->uniqueid);
-}
-
-static struct ast_channel *wait_for_answer(struct ast_channel *in, struct localuser *outgoing, int *to, struct ast_flags *peerflags, int *sentringing, char *status, size_t statussize, int busystart, int nochanstart, int congestionstart, int priority_jump, int *result)
-{
- struct localuser *o;
- int found;
- int numlines;
- int numbusy = busystart;
- int numcongestion = congestionstart;
- int numnochan = nochanstart;
- int prestart = busystart + congestionstart + nochanstart;
- int cause;
- int orig = *to;
- struct ast_frame *f;
- struct ast_channel *peer = NULL;
- struct ast_channel *watchers[AST_MAX_WATCHERS];
- int pos;
- int single;
- struct ast_channel *winner;
- char *context = NULL;
- char cidname[AST_MAX_EXTENSION];
-
- single = (outgoing && !outgoing->next && !ast_test_flag(outgoing, OPT_MUSICBACK | OPT_RINGBACK));
-
- if (single) {
- /* Turn off hold music, etc */
- ast_deactivate_generator(in);
- /* If we are calling a single channel, make them compatible for in-band tone purpose */
- ast_channel_make_compatible(outgoing->chan, in);
- }
-
-
- while (*to && !peer) {
- o = outgoing;
- found = -1;
- pos = 1;
- numlines = prestart;
- watchers[0] = in;
- while (o) {
- /* Keep track of important channels */
- if (ast_test_flag(o, DIAL_STILLGOING) && o->chan) {
- watchers[pos++] = o->chan;
- found = 1;
- }
- o = o->next;
- numlines++;
- }
- if (found < 0) {
- if (numlines == (numbusy + numcongestion + numnochan)) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan);
- if (numbusy)
- strcpy(status, "BUSY");
- else if (numcongestion)
- strcpy(status, "CONGESTION");
- else if (numnochan)
- strcpy(status, "CHANUNAVAIL");
- if (option_priority_jumping || priority_jump)
- ast_goto_if_exists(in, in->context, in->exten, in->priority + 101);
- } else {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_2 "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan);
- }
- *to = 0;
- return NULL;
- }
- winner = ast_waitfor_n(watchers, pos, to);
- o = outgoing;
- while (o) {
- if (ast_test_flag(o, DIAL_STILLGOING) && o->chan && (o->chan->_state == AST_STATE_UP)) {
- if (!peer) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", o->chan->name, in->name);
- peer = o->chan;
- ast_copy_flags(peerflags, o,
- OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
- OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
- OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
- DIAL_NOFORWARDHTML);
- }
- } else if (o->chan && (o->chan == winner)) {
- if (!ast_strlen_zero(o->chan->call_forward)) {
- char tmpchan[256];
- char *stuff;
- char *tech;
- ast_copy_string(tmpchan, o->chan->call_forward, sizeof(tmpchan));
- if ((stuff = strchr(tmpchan, '/'))) {
- *stuff = '\0';
- stuff++;
- tech = tmpchan;
- } else {
- snprintf(tmpchan, sizeof(tmpchan), "%s@%s", o->chan->call_forward, o->chan->context);
- stuff = tmpchan;
- tech = "Local";
- }
- /* Before processing channel, go ahead and check for forwarding */
- o->forwards++;
- if (o->forwards < AST_MAX_FORWARDS) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, o->chan->name);
- /* Setup parameters */
- o->chan = ast_request(tech, in->nativeformats, stuff, &cause);
- if (!o->chan)
- ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Too many forwards from %s\n", o->chan->name);
- cause = AST_CAUSE_CONGESTION;
- o->chan = NULL;
- }
- if (!o->chan) {
- ast_clear_flag(o, DIAL_STILLGOING);
- HANDLE_CAUSE(cause, in);
- } else {
- if (o->chan->cid.cid_num)
- free(o->chan->cid.cid_num);
- o->chan->cid.cid_num = NULL;
- if (o->chan->cid.cid_name)
- free(o->chan->cid.cid_name);
- o->chan->cid.cid_name = NULL;
-
- if (ast_test_flag(o, OPT_FORCECLID)) {
- char *newcid = NULL;
-
- if (!ast_strlen_zero(in->macroexten))
- newcid = in->macroexten;
- else
- newcid = in->exten;
- o->chan->cid.cid_num = strdup(newcid);
- ast_copy_string(o->chan->accountcode, winner->accountcode, sizeof(o->chan->accountcode));
- o->chan->cdrflags = winner->cdrflags;
- if (!o->chan->cid.cid_num)
- ast_log(LOG_WARNING, "Out of memory\n");
- } else {
- if (in->cid.cid_num) {
- o->chan->cid.cid_num = strdup(in->cid.cid_num);
- if (!o->chan->cid.cid_num)
- ast_log(LOG_WARNING, "Out of memory\n");
- }
- if (in->cid.cid_name) {
- o->chan->cid.cid_name = strdup(in->cid.cid_name);
- if (!o->chan->cid.cid_name)
- ast_log(LOG_WARNING, "Out of memory\n");
- }
- ast_copy_string(o->chan->accountcode, in->accountcode, sizeof(o->chan->accountcode));
- o->chan->cdrflags = in->cdrflags;
- }
-
- if (in->cid.cid_ani) {
- if (o->chan->cid.cid_ani)
- free(o->chan->cid.cid_ani);
- o->chan->cid.cid_ani = strdup(in->cid.cid_ani);
- if (!o->chan->cid.cid_ani)
- ast_log(LOG_WARNING, "Out of memory\n");
- }
- if (o->chan->cid.cid_rdnis)
- free(o->chan->cid.cid_rdnis);
- if (!ast_strlen_zero(in->macroexten))
- o->chan->cid.cid_rdnis = strdup(in->macroexten);
- else
- o->chan->cid.cid_rdnis = strdup(in->exten);
- if (ast_call(o->chan, tmpchan, 0)) {
- ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
- ast_clear_flag(o, DIAL_STILLGOING);
- ast_hangup(o->chan);
- o->chan = NULL;
- numnochan++;
- } else {
- senddialevent(in, o->chan);
- /* After calling, set callerid to extension */
- if (!ast_test_flag(peerflags, OPT_ORIGINAL_CLID))
- ast_set_callerid(o->chan, ast_strlen_zero(in->macroexten) ? in->exten : in->macroexten, get_cid_name(cidname, sizeof(cidname), in), NULL);
- }
- }
- /* Hangup the original channel now, in case we needed it */
- ast_hangup(winner);
- continue;
- }
- f = ast_read(winner);
- if (f) {
- if (f->frametype == AST_FRAME_CONTROL) {
- switch(f->subclass) {
- case AST_CONTROL_ANSWER:
- /* This is our guy if someone answered. */
- if (!peer) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", o->chan->name, in->name);
- peer = o->chan;
- ast_copy_flags(peerflags, o,
- OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
- OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
- OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
- DIAL_NOFORWARDHTML);
- }
- /* If call has been answered, then the eventual hangup is likely to be normal hangup */
- in->hangupcause = AST_CAUSE_NORMAL_CLEARING;
- o->chan->hangupcause = AST_CAUSE_NORMAL_CLEARING;
- break;
- case AST_CONTROL_BUSY:
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s is busy\n", o->chan->name);
- in->hangupcause = o->chan->hangupcause;
- ast_hangup(o->chan);
- o->chan = NULL;
- ast_clear_flag(o, DIAL_STILLGOING);
- HANDLE_CAUSE(AST_CAUSE_BUSY, in);
- break;
- case AST_CONTROL_CONGESTION:
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s is circuit-busy\n", o->chan->name);
- in->hangupcause = o->chan->hangupcause;
- ast_hangup(o->chan);
- o->chan = NULL;
- ast_clear_flag(o, DIAL_STILLGOING);
- HANDLE_CAUSE(AST_CAUSE_CONGESTION, in);
- break;
- case AST_CONTROL_RINGING:
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s is ringing\n", o->chan->name);
- if (!(*sentringing) && !ast_test_flag(outgoing, OPT_MUSICBACK)) {
- ast_indicate(in, AST_CONTROL_RINGING);
- (*sentringing)++;
- }
- break;
- case AST_CONTROL_PROGRESS:
- if (option_verbose > 2)
- ast_verbose ( VERBOSE_PREFIX_3 "%s is making progress passing it to %s\n", o->chan->name,in->name);
- if (!ast_test_flag(outgoing, OPT_RINGBACK))
- ast_indicate(in, AST_CONTROL_PROGRESS);
- break;
- case AST_CONTROL_VIDUPDATE:
- if (option_verbose > 2)
- ast_verbose ( VERBOSE_PREFIX_3 "%s requested a video update, passing it to %s\n", o->chan->name,in->name);
- ast_indicate(in, AST_CONTROL_VIDUPDATE);
- break;
- case AST_CONTROL_PROCEEDING:
- if (option_verbose > 2)
- ast_verbose ( VERBOSE_PREFIX_3 "%s is proceeding passing it to %s\n", o->chan->name,in->name);
- if (!ast_test_flag(outgoing, OPT_RINGBACK))
- ast_indicate(in, AST_CONTROL_PROCEEDING);
- break;
- case AST_CONTROL_HOLD:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Call on %s placed on hold\n", o->chan->name);
- ast_indicate(in, AST_CONTROL_HOLD);
- break;
- case AST_CONTROL_UNHOLD:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Call on %s left from hold\n", o->chan->name);
- ast_indicate(in, AST_CONTROL_UNHOLD);
- break;
- case AST_CONTROL_OFFHOOK:
- case AST_CONTROL_FLASH:
- /* Ignore going off hook and flash */
- break;
- case -1:
- if (!ast_test_flag(outgoing, OPT_RINGBACK | OPT_MUSICBACK)) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s stopped sounds\n", o->chan->name);
- ast_indicate(in, -1);
- (*sentringing) = 0;
- }
- break;
- default:
- ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass);
- }
- } else if (single && (f->frametype == AST_FRAME_VOICE) &&
- !(ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK))) {
- if (ast_write(in, f))
- ast_log(LOG_DEBUG, "Unable to forward frame\n");
- } else if (single && (f->frametype == AST_FRAME_IMAGE) &&
- !(ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK))) {
- if (ast_write(in, f))
- ast_log(LOG_DEBUG, "Unable to forward image\n");
- } else if (single && (f->frametype == AST_FRAME_TEXT) &&
- !(ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK))) {
- if (ast_write(in, f))
- ast_log(LOG_DEBUG, "Unable to text\n");
- } else if (single && (f->frametype == AST_FRAME_HTML) && !ast_test_flag(outgoing, DIAL_NOFORWARDHTML))
- ast_channel_sendhtml(in, f->subclass, f->data, f->datalen);
-
- ast_frfree(f);
- } else {
- in->hangupcause = o->chan->hangupcause;
- ast_hangup(o->chan);
- o->chan = NULL;
- ast_clear_flag(o, DIAL_STILLGOING);
- HANDLE_CAUSE(in->hangupcause, in);
- }
- }
- o = o->next;
- }
- if (winner == in) {
- f = ast_read(in);
-#if 0
- if (f && (f->frametype != AST_FRAME_VOICE))
- printf("Frame type: %d, %d\n", f->frametype, f->subclass);
- else if (!f || (f->frametype != AST_FRAME_VOICE))
- printf("Hangup received on %s\n", in->name);
-#endif
- if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP))) {
- /* Got hung up */
- *to=-1;
- strcpy(status, "CANCEL");
- if (f)
- ast_frfree(f);
- return NULL;
- }
-
- if (f && (f->frametype == AST_FRAME_DTMF)) {
- if (ast_test_flag(peerflags, OPT_DTMF_EXIT)) {
- context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
- if (onedigit_goto(in, context, (char) f->subclass, 1)) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass);
- *to=0;
- *result = f->subclass;
- strcpy(status, "CANCEL");
- ast_frfree(f);
- return NULL;
- }
- }
-
- if (ast_test_flag(peerflags, OPT_CALLER_HANGUP) &&
- (f->subclass == '*')) { /* hmm it it not guarenteed to be '*' anymore. */
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass);
- *to=0;
- strcpy(status, "CANCEL");
- ast_frfree(f);
- return NULL;
- }
- }
-
- /* Forward HTML stuff */
- if (single && f && (f->frametype == AST_FRAME_HTML) && !ast_test_flag(outgoing, DIAL_NOFORWARDHTML))
- ast_channel_sendhtml(outgoing->chan, f->subclass, f->data, f->datalen);
-
-
- if (single && ((f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_DTMF))) {
- if (ast_write(outgoing->chan, f))
- ast_log(LOG_WARNING, "Unable to forward voice\n");
- }
- if (single && (f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_VIDUPDATE)) {
- if (option_verbose > 2)
- ast_verbose ( VERBOSE_PREFIX_3 "%s requested a video update, passing it to %s\n", in->name,outgoing->chan->name);
- ast_indicate(outgoing->chan, AST_CONTROL_VIDUPDATE);
- }
- ast_frfree(f);
- }
- if (!*to && (option_verbose > 2))
- ast_verbose( VERBOSE_PREFIX_3 "Nobody picked up in %d ms\n", orig);
- }
-
- return peer;
-
-}
-
-static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags *peerflags)
-{
- int res=-1;
- struct localuser *u;
- char *tech, *number, *rest, *cur;
- char privcid[256];
- char privintro[1024];
- struct localuser *outgoing=NULL, *tmp;
- struct ast_channel *peer;
- int to;
- int numbusy = 0;
- int numcongestion = 0;
- int numnochan = 0;
- int cause;
- char numsubst[AST_MAX_EXTENSION];
- char restofit[AST_MAX_EXTENSION];
- char cidname[AST_MAX_EXTENSION];
- char toast[80];
- char *newnum;
- char *l;
- int privdb_val=0;
- unsigned int calldurationlimit=0;
- struct ast_bridge_config config;
- long timelimit = 0;
- long play_warning = 0;
- long warning_freq=0;
- char *warning_sound=NULL;
- char *end_sound=NULL;
- char *start_sound=NULL;
- char *dtmfcalled=NULL, *dtmfcalling=NULL;
- char *var;
- char status[256];
- int play_to_caller=0,play_to_callee=0;
- int sentringing=0, moh=0;
- char *outbound_group = NULL;
- char *macro_result = NULL, *macro_transfer_dest = NULL;
- int digit = 0, result = 0;
- time_t start_time, answer_time, end_time;
- struct ast_app *app = NULL;
-
- char *parse;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(peers);
- AST_APP_ARG(timeout);
- AST_APP_ARG(options);
- AST_APP_ARG(url);
- );
- struct ast_flags opts = { 0, };
- char *opt_args[OPT_ARG_ARRAY_SIZE];
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory allocation failure\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (!ast_strlen_zero(args.options)) {
- if (ast_app_parse_options(dial_exec_options, &opts, opt_args, args.options)) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
-
- if (ast_strlen_zero(args.peers)) {
- ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (ast_test_flag(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
- calldurationlimit = atoi(opt_args[OPT_ARG_DURATION_STOP]);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Setting call duration limit to %d seconds.\n",calldurationlimit);
- }
-
- if (ast_test_flag(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
- parse = opt_args[OPT_ARG_SENDDTMF];
- dtmfcalled = strsep(&parse, ":");
- dtmfcalling = parse;
- }
-
- if (ast_test_flag(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
- char *limit_str, *warning_str, *warnfreq_str;
-
- parse = opt_args[OPT_ARG_DURATION_LIMIT];
- limit_str = strsep(&parse, ":");
- warning_str = strsep(&parse, ":");
- warnfreq_str = parse;
-
- timelimit = atol(limit_str);
- if (warning_str)
- play_warning = atol(warning_str);
- if (warnfreq_str)
- warning_freq = atol(warnfreq_str);
-
- if (!timelimit) {
- timelimit = play_to_caller = play_to_callee = play_warning = warning_freq = 0;
- warning_sound = NULL;
- }
-
- var = pbx_builtin_getvar_helper(chan,"LIMIT_PLAYAUDIO_CALLER");
- play_to_caller = var ? ast_true(var) : 1;
-
- var = pbx_builtin_getvar_helper(chan,"LIMIT_PLAYAUDIO_CALLEE");
- play_to_callee = var ? ast_true(var) : 0;
-
- if (!play_to_caller && !play_to_callee)
- play_to_caller=1;
-
- var = pbx_builtin_getvar_helper(chan,"LIMIT_WARNING_FILE");
- warning_sound = var ? var : "timeleft";
-
- var = pbx_builtin_getvar_helper(chan,"LIMIT_TIMEOUT_FILE");
- end_sound = var ? var : NULL;
-
- var = pbx_builtin_getvar_helper(chan,"LIMIT_CONNECT_FILE");
- start_sound = var ? var : NULL;
-
- /* undo effect of S(x) in case they are both used */
- calldurationlimit = 0;
- /* more efficient do it like S(x) does since no advanced opts*/
- if (!play_warning && !start_sound && !end_sound && timelimit) {
- calldurationlimit = timelimit/1000;
- timelimit = play_to_caller = play_to_callee = play_warning = warning_freq = 0;
- } else if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Limit Data for this call:\n");
- ast_verbose(VERBOSE_PREFIX_3 "- timelimit = %ld\n", timelimit);
- ast_verbose(VERBOSE_PREFIX_3 "- play_warning = %ld\n", play_warning);
- ast_verbose(VERBOSE_PREFIX_3 "- play_to_caller= %s\n", play_to_caller ? "yes" : "no");
- ast_verbose(VERBOSE_PREFIX_3 "- play_to_callee= %s\n", play_to_callee ? "yes" : "no");
- ast_verbose(VERBOSE_PREFIX_3 "- warning_freq = %ld\n", warning_freq);
- ast_verbose(VERBOSE_PREFIX_3 "- start_sound = %s\n", start_sound ? start_sound : "UNDEF");
- ast_verbose(VERBOSE_PREFIX_3 "- warning_sound = %s\n", warning_sound ? warning_sound : "UNDEF");
- ast_verbose(VERBOSE_PREFIX_3 "- end_sound = %s\n", end_sound ? end_sound : "UNDEF");
- }
- }
-
- if (ast_test_flag(&opts, OPT_RESETCDR) && chan->cdr)
- ast_cdr_reset(chan->cdr, NULL);
- if (ast_test_flag(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
- opt_args[OPT_ARG_PRIVACY] = ast_strdupa(chan->exten);
- if (ast_test_flag(&opts, OPT_PRIVACY) || ast_test_flag(&opts, OPT_SCREENING)) {
- char callerid[60];
-
- l = chan->cid.cid_num;
- if (!ast_strlen_zero(l)) {
- ast_shrink_phone_number(l);
- if( ast_test_flag(&opts, OPT_PRIVACY) ) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Privacy DB is '%s', clid is '%s'\n",
- opt_args[OPT_ARG_PRIVACY], l);
- privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
- }
- else {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Privacy Screening, clid is '%s'\n", l);
- privdb_val = AST_PRIVACY_UNKNOWN;
- }
- } else {
- char *tnam, *tn2;
-
- tnam = ast_strdupa(chan->name);
- /* clean the channel name so slashes don't try to end up in disk file name */
- for(tn2 = tnam; *tn2; tn2++) {
- if( *tn2=='/')
- *tn2 = '='; /* any other chars to be afraid of? */
- }
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Privacy-- callerid is empty\n");
-
- snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", chan->exten, tnam);
- l = callerid;
- privdb_val = AST_PRIVACY_UNKNOWN;
- }
-
- ast_copy_string(privcid,l,sizeof(privcid));
-
- if( strncmp(privcid,"NOCALLERID",10) != 0 && ast_test_flag(&opts, OPT_SCREEN_NOCLID) ) { /* if callerid is set, and ast_test_flag(&opts, OPT_SCREEN_NOCLID) is set also */
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "CallerID set (%s); N option set; Screening should be off\n", privcid);
- privdb_val = AST_PRIVACY_ALLOW;
- }
- else if( ast_test_flag(&opts, OPT_SCREEN_NOCLID) && strncmp(privcid,"NOCALLERID",10) == 0 ) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "CallerID blank; N option set; Screening should happen; dbval is %d\n", privdb_val);
- }
-
- if( privdb_val == AST_PRIVACY_DENY ) {
- ast_verbose( VERBOSE_PREFIX_3 "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
- res=0;
- goto out;
- }
- else if( privdb_val == AST_PRIVACY_KILL ) {
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 201);
- res = 0;
- goto out; /* Is this right? */
- }
- else if( privdb_val == AST_PRIVACY_TORTURE ) {
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 301);
- res = 0;
- goto out; /* is this right??? */
-
- }
- else if( privdb_val == AST_PRIVACY_UNKNOWN ) {
- /* Get the user's intro, store it in priv-callerintros/$CID,
- unless it is already there-- this should be done before the
- call is actually dialed */
-
- /* make sure the priv-callerintros dir exists? */
-
- snprintf(privintro,sizeof(privintro),"priv-callerintros/%s", privcid);
- if( ast_fileexists(privintro,NULL,NULL ) > 0 && strncmp(privcid,"NOCALLERID",10) != 0) {
- /* the DELUX version of this code would allow this caller the
- option to hear and retape their previously recorded intro.
- */
- }
- else {
- int duration; /* for feedback from play_and_wait */
- /* the file doesn't exist yet. Let the caller submit his
- vocal intro for posterity */
- /* priv-recordintro script:
-
- "At the tone, please say your name:"
-
- */
- ast_play_and_record(chan, "priv-recordintro", privintro, 4, "gsm", &duration, 128, 2000, 0); /* NOTE: I've reduced the total time to 4 sec */
- /* don't think we'll need a lock removed, we took care of
- conflicts by naming the privintro file */
- }
- }
- }
-
- /* If a channel group has been specified, get it for use when we create peer channels */
- outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP");
-
- ast_copy_flags(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP);
- cur = args.peers;
- do {
- /* Remember where to start next time */
- rest = strchr(cur, '&');
- if (rest) {
- *rest = 0;
- rest++;
- }
- /* Get a technology/[device:]number pair */
- tech = cur;
- number = strchr(tech, '/');
- if (!number) {
- ast_log(LOG_WARNING, "Dial argument takes format (technology/[device:]number1)\n");
- goto out;
- }
- *number = '\0';
- number++;
- tmp = malloc(sizeof(struct localuser));
- if (!tmp) {
- ast_log(LOG_WARNING, "Out of memory\n");
- goto out;
- }
- memset(tmp, 0, sizeof(struct localuser));
- if (opts.flags) {
- ast_copy_flags(tmp, &opts,
- OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
- OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
- OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
- OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID);
- ast_set2_flag(tmp, args.url, DIAL_NOFORWARDHTML);
- }
- ast_copy_string(numsubst, number, sizeof(numsubst));
- /* If we're dialing by extension, look at the extension to know what to dial */
- if ((newnum = strstr(numsubst, "BYEXTENSION"))) {
- /* strlen("BYEXTENSION") == 11 */
- ast_copy_string(restofit, newnum + 11, sizeof(restofit));
- snprintf(newnum, sizeof(numsubst) - (newnum - numsubst), "%s%s", chan->exten,restofit);
- if (option_debug)
- ast_log(LOG_DEBUG, "Dialing by extension %s\n", numsubst);
- }
- /* Request the peer */
- tmp->chan = ast_request(tech, chan->nativeformats, numsubst, &cause);
- if (!tmp->chan) {
- /* If we can't, just go on to the next call */
- ast_log(LOG_NOTICE, "Unable to create channel of type '%s' (cause %d - %s)\n", tech, cause, ast_cause2str(cause));
- HANDLE_CAUSE(cause, chan);
- cur = rest;
- if (!cur)
- chan->hangupcause = cause;
- continue;
- }
- pbx_builtin_setvar_helper(tmp->chan, "DIALEDPEERNUMBER", numsubst);
- if (!ast_strlen_zero(tmp->chan->call_forward)) {
- char tmpchan[256];
- char *stuff;
- char *tech;
- ast_copy_string(tmpchan, tmp->chan->call_forward, sizeof(tmpchan));
- if ((stuff = strchr(tmpchan, '/'))) {
- *stuff = '\0';
- stuff++;
- tech = tmpchan;
- } else {
- snprintf(tmpchan, sizeof(tmpchan), "%s@%s", tmp->chan->call_forward, tmp->chan->context);
- stuff = tmpchan;
- tech = "Local";
- }
- tmp->forwards++;
- if (tmp->forwards < AST_MAX_FORWARDS) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", chan->name, tech, stuff, tmp->chan->name);
- ast_hangup(tmp->chan);
- /* Setup parameters */
- tmp->chan = ast_request(tech, chan->nativeformats, stuff, &cause);
- if (!tmp->chan)
- ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Too many forwards from %s\n", tmp->chan->name);
- ast_hangup(tmp->chan);
- tmp->chan = NULL;
- cause = AST_CAUSE_CONGESTION;
- }
- if (!tmp->chan) {
- HANDLE_CAUSE(cause, chan);
- cur = rest;
- continue;
- }
- }
-
- /* Inherit specially named variables from parent channel */
- ast_channel_inherit_variables(chan, tmp->chan);
-
- tmp->chan->appl = "AppDial";
- tmp->chan->data = "(Outgoing Line)";
- tmp->chan->whentohangup = 0;
- if (tmp->chan->cid.cid_num)
- free(tmp->chan->cid.cid_num);
- tmp->chan->cid.cid_num = NULL;
- if (tmp->chan->cid.cid_name)
- free(tmp->chan->cid.cid_name);
- tmp->chan->cid.cid_name = NULL;
- if (tmp->chan->cid.cid_ani)
- free(tmp->chan->cid.cid_ani);
- tmp->chan->cid.cid_ani = NULL;
-
- if (chan->cid.cid_num)
- tmp->chan->cid.cid_num = strdup(chan->cid.cid_num);
- if (chan->cid.cid_name)
- tmp->chan->cid.cid_name = strdup(chan->cid.cid_name);
- if (chan->cid.cid_ani)
- tmp->chan->cid.cid_ani = strdup(chan->cid.cid_ani);
-
- /* Copy language from incoming to outgoing */
- ast_copy_string(tmp->chan->language, chan->language, sizeof(tmp->chan->language));
- ast_copy_string(tmp->chan->accountcode, chan->accountcode, sizeof(tmp->chan->accountcode));
- tmp->chan->cdrflags = chan->cdrflags;
- if (ast_strlen_zero(tmp->chan->musicclass))
- ast_copy_string(tmp->chan->musicclass, chan->musicclass, sizeof(tmp->chan->musicclass));
- if (chan->cid.cid_rdnis)
- tmp->chan->cid.cid_rdnis = strdup(chan->cid.cid_rdnis);
- /* Pass callingpres setting */
- tmp->chan->cid.cid_pres = chan->cid.cid_pres;
- /* Pass type of number */
- tmp->chan->cid.cid_ton = chan->cid.cid_ton;
- /* Pass type of tns */
- tmp->chan->cid.cid_tns = chan->cid.cid_tns;
- /* Presense of ADSI CPE on outgoing channel follows ours */
- tmp->chan->adsicpe = chan->adsicpe;
- /* Pass the transfer capability */
- tmp->chan->transfercapability = chan->transfercapability;
-
- /* If we have an outbound group, set this peer channel to it */
- if (outbound_group)
- ast_app_group_set_channel(tmp->chan, outbound_group);
-
- /* Place the call, but don't wait on the answer */
- res = ast_call(tmp->chan, numsubst, 0);
-
- /* Save the info in cdr's that we called them */
- if (chan->cdr)
- ast_cdr_setdestchan(chan->cdr, tmp->chan->name);
-
- /* check the results of ast_call */
- if (res) {
- /* Again, keep going even if there's an error */
- if (option_debug)
- ast_log(LOG_DEBUG, "ast call on peer returned %d\n", res);
- else if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Couldn't call %s\n", numsubst);
- ast_hangup(tmp->chan);
- tmp->chan = NULL;
- cur = rest;
- continue;
- } else {
- senddialevent(chan, tmp->chan);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Called %s\n", numsubst);
- if (!ast_test_flag(peerflags, OPT_ORIGINAL_CLID))
- ast_set_callerid(tmp->chan, ast_strlen_zero(chan->macroexten) ? chan->exten : chan->macroexten, get_cid_name(cidname, sizeof(cidname), chan), NULL);
- }
- /* Put them in the list of outgoing thingies... We're ready now.
- XXX If we're forcibly removed, these outgoing calls won't get
- hung up XXX */
- ast_set_flag(tmp, DIAL_STILLGOING);
- tmp->next = outgoing;
- outgoing = tmp;
- /* If this line is up, don't try anybody else */
- if (outgoing->chan->_state == AST_STATE_UP)
- break;
- cur = rest;
- } while (cur);
-
- if (!ast_strlen_zero(args.timeout)) {
- to = atoi(args.timeout);
- if (to > 0)
- to *= 1000;
- else
- ast_log(LOG_WARNING, "Invalid timeout specified: '%s'\n", args.timeout);
- } else
- to = -1;
-
- if (outgoing) {
- /* Our status will at least be NOANSWER */
- strcpy(status, "NOANSWER");
- if (ast_test_flag(outgoing, OPT_MUSICBACK)) {
- moh=1;
- ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK]);
- } else if (ast_test_flag(outgoing, OPT_RINGBACK)) {
- ast_indicate(chan, AST_CONTROL_RINGING);
- sentringing++;
- }
- } else
- strcpy(status, "CHANUNAVAIL");
-
- time(&start_time);
- peer = wait_for_answer(chan, outgoing, &to, peerflags, &sentringing, status, sizeof(status), numbusy, numnochan, numcongestion, ast_test_flag(&opts, OPT_PRIORITY_JUMP), &result);
-
- if (!peer) {
- if (result) {
- res = result;
- } else if (to)
- /* Musta gotten hung up */
- res = -1;
- else
- /* Nobody answered, next please? */
- res = 0;
-
- goto out;
- }
- if (peer) {
- time(&answer_time);
-#ifdef OSP_SUPPORT
- /* Once call is answered, ditch the OSP Handle */
- pbx_builtin_setvar_helper(chan, "_OSPHANDLE", "");
-#endif
- strcpy(status, "ANSWER");
- /* Ah ha! Someone answered within the desired timeframe. Of course after this
- we will always return with -1 so that it is hung up properly after the
- conversation. */
- hanguptree(outgoing, peer);
- outgoing = NULL;
- /* If appropriate, log that we have a destination channel */
- if (chan->cdr)
- ast_cdr_setdestchan(chan->cdr, peer->name);
- if (peer->name)
- pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", peer->name);
-
- number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
- if (!number)
- number = numsubst;
- pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
- if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
- ast_log(LOG_DEBUG, "app_dial: sendurl=%s.\n", args.url);
- ast_channel_sendurl( peer, args.url );
- }
- if (ast_test_flag(&opts, OPT_PRIVACY) || ast_test_flag(&opts, OPT_SCREENING)) {
- int res2;
- int loopcount = 0;
- if( privdb_val == AST_PRIVACY_UNKNOWN ) {
-
- /* Get the user's intro, store it in priv-callerintros/$CID,
- unless it is already there-- this should be done before the
- call is actually dialed */
-
- /* all ring indications and moh for the caller has been halted as soon as the
- target extension was picked up. We are going to have to kill some
- time and make the caller believe the peer hasn't picked up yet */
-
- if (ast_test_flag(&opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
- ast_indicate(chan, -1);
- ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK]);
- } else if (ast_test_flag(&opts, OPT_RINGBACK)) {
- ast_indicate(chan, AST_CONTROL_RINGING);
- sentringing++;
- }
-
- /* Start autoservice on the other chan ?? */
- res2 = ast_autoservice_start(chan);
- /* Now Stream the File */
- if (!res2) {
- do {
- if (!res2)
- res2 = ast_play_and_wait(peer,"priv-callpending");
- if( res2 < '1' || (ast_test_flag(&opts, OPT_PRIVACY) && res2>'5') || (ast_test_flag(&opts, OPT_SCREENING) && res2 > '4') ) /* uh, interrupting with a bad answer is ... ignorable! */
- res2 = 0;
-
- /* priv-callpending script:
- "I have a caller waiting, who introduces themselves as:"
- */
- if (!res2)
- res2 = ast_play_and_wait(peer,privintro);
- if( res2 < '1' || (ast_test_flag(&opts, OPT_PRIVACY) && res2>'5') || (ast_test_flag(&opts, OPT_SCREENING) && res2 > '4') ) /* uh, interrupting with a bad answer is ... ignorable! */
- res2 = 0;
- /* now get input from the called party, as to their choice */
- if( !res2 ) {
- if( ast_test_flag(&opts, OPT_PRIVACY) )
- res2 = ast_play_and_wait(peer,"priv-callee-options");
- if( ast_test_flag(&opts, OPT_SCREENING) )
- res2 = ast_play_and_wait(peer,"screen-callee-options");
- }
- /* priv-callee-options script:
- "Dial 1 if you wish this caller to reach you directly in the future,
- and immediately connect to their incoming call
- Dial 2 if you wish to send this caller to voicemail now and
- forevermore.
- Dial 3 to send this callerr to the torture menus, now and forevermore.
- Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
- Dial 5 to allow this caller to come straight thru to you in the future,
- but right now, just this once, send them to voicemail."
- */
-
- /* screen-callee-options script:
- "Dial 1 if you wish to immediately connect to the incoming call
- Dial 2 if you wish to send this caller to voicemail.
- Dial 3 to send this callerr to the torture menus.
- Dial 4 to send this caller to a simple "go away" menu.
- */
- if( !res2 || res2 < '1' || (ast_test_flag(&opts, OPT_PRIVACY) && res2 > '5') || (ast_test_flag(&opts, OPT_SCREENING) && res2 > '4') ) {
- /* invalid option */
- res2 = ast_play_and_wait(peer,"vm-sorry");
- }
- loopcount++; /* give the callee a couple chances to make a choice */
- } while( (!res2 || res2 < '1' || (ast_test_flag(&opts, OPT_PRIVACY) && res2 > '5') || (ast_test_flag(&opts, OPT_SCREENING) && res2 > '4')) && loopcount < 2 );
- }
-
- switch(res2) {
- case '1':
- if( ast_test_flag(&opts, OPT_PRIVACY) ) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "--Set privacy database entry %s/%s to ALLOW\n",
- opt_args[OPT_ARG_PRIVACY], privcid);
- ast_privacy_set(opt_args[OPT_ARG_PRIVACY], privcid, AST_PRIVACY_ALLOW);
- }
- break;
- case '2':
- if( ast_test_flag(&opts, OPT_PRIVACY) ) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "--Set privacy database entry %s/%s to DENY\n",
- opt_args[OPT_ARG_PRIVACY], privcid);
- ast_privacy_set(opt_args[OPT_ARG_PRIVACY], privcid, AST_PRIVACY_DENY);
- }
- if (ast_test_flag(&opts, OPT_MUSICBACK)) {
- ast_moh_stop(chan);
- } else if (ast_test_flag(&opts, OPT_RINGBACK)) {
- ast_indicate(chan, -1);
- sentringing=0;
- }
- res2 = ast_autoservice_stop(chan);
- ast_hangup(peer); /* hang up on the callee -- he didn't want to talk anyway! */
- res=0;
- goto out;
- case '3':
- if( ast_test_flag(&opts, OPT_PRIVACY) ) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "--Set privacy database entry %s/%s to TORTURE\n",
- opt_args[OPT_ARG_PRIVACY], privcid);
- ast_privacy_set(opt_args[OPT_ARG_PRIVACY], privcid, AST_PRIVACY_TORTURE);
- }
- ast_copy_string(status, "TORTURE", sizeof(status));
-
- res = 0;
- if (ast_test_flag(&opts, OPT_MUSICBACK)) {
- ast_moh_stop(chan);
- } else if (ast_test_flag(&opts, OPT_RINGBACK)) {
- ast_indicate(chan, -1);
- sentringing=0;
- }
- res2 = ast_autoservice_stop(chan);
- ast_hangup(peer); /* hang up on the caller -- he didn't want to talk anyway! */
- goto out; /* Is this right? */
- case '4':
- if( ast_test_flag(&opts, OPT_PRIVACY) ) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "--Set privacy database entry %s/%s to KILL\n",
- opt_args[OPT_ARG_PRIVACY], privcid);
- ast_privacy_set(opt_args[OPT_ARG_PRIVACY], privcid, AST_PRIVACY_KILL);
- }
-
- ast_copy_string(status, "DONTCALL", sizeof(status));
- res = 0;
- if (ast_test_flag(&opts, OPT_MUSICBACK)) {
- ast_moh_stop(chan);
- } else if (ast_test_flag(&opts, OPT_RINGBACK)) {
- ast_indicate(chan, -1);
- sentringing=0;
- }
- res2 = ast_autoservice_stop(chan);
- ast_hangup(peer); /* hang up on the caller -- he didn't want to talk anyway! */
- goto out; /* Is this right? */
- case '5':
- if( ast_test_flag(&opts, OPT_PRIVACY) ) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "--Set privacy database entry %s/%s to ALLOW\n",
- opt_args[OPT_ARG_PRIVACY], privcid);
- ast_privacy_set(opt_args[OPT_ARG_PRIVACY], privcid, AST_PRIVACY_ALLOW);
- if (ast_test_flag(&opts, OPT_MUSICBACK)) {
- ast_moh_stop(chan);
- } else if (ast_test_flag(&opts, OPT_RINGBACK)) {
- ast_indicate(chan, -1);
- sentringing=0;
- }
- res2 = ast_autoservice_stop(chan);
- ast_hangup(peer); /* hang up on the caller -- he didn't want to talk anyway! */
- res=0;
- goto out;
- } /* if not privacy, then 5 is the same as "default" case */
- default:
- /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
- /* well, there seems basically two choices. Just patch the caller thru immediately,
- or,... put 'em thru to voicemail. */
- /* since the callee may have hung up, let's do the voicemail thing, no database decision */
- if (option_verbose > 2)
- ast_log(LOG_NOTICE,"privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
- if (ast_test_flag(&opts, OPT_MUSICBACK)) {
- ast_moh_stop(chan);
- } else if (ast_test_flag(&opts, OPT_RINGBACK)) {
- ast_indicate(chan, -1);
- sentringing=0;
- }
- res2 = ast_autoservice_stop(chan);
- ast_hangup(peer); /* hang up on the callee -- he didn't want to talk anyway! */
- res=0;
- goto out;
- }
- if (ast_test_flag(&opts, OPT_MUSICBACK)) {
- ast_moh_stop(chan);
- } else if (ast_test_flag(&opts, OPT_RINGBACK)) {
- ast_indicate(chan, -1);
- sentringing=0;
- }
- res2 = ast_autoservice_stop(chan);
- /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
- just clog things up, and it's not useful information, not being tied to a CID */
- if( strncmp(privcid,"NOCALLERID",10) == 0 || ast_test_flag(&opts, OPT_SCREEN_NOINTRO) ) {
- ast_filedelete(privintro, NULL);
- if( ast_fileexists(privintro,NULL,NULL ) > 0 )
- ast_log(LOG_NOTICE,"privacy: ast_filedelete didn't do its job on %s\n", privintro);
- else if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Successfully deleted %s intro file\n", privintro);
- }
- }
- }
- if (ast_test_flag(&opts, OPT_ANNOUNCE) && !ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
- /* Start autoservice on the other chan */
- res = ast_autoservice_start(chan);
- /* Now Stream the File */
- if (!res)
- res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], peer->language);
- if (!res) {
- digit = ast_waitstream(peer, AST_DIGIT_ANY);
- }
- /* Ok, done. stop autoservice */
- res = ast_autoservice_stop(chan);
- if (digit > 0 && !res)
- res = ast_senddigit(chan, digit);
- else
- res = digit;
-
- } else
- res = 0;
-
- if (chan && peer && ast_test_flag(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
- char *ch;
-
- for (ch = opt_args[OPT_ARG_GOTO]; *ch; ch++) {
- if (*ch == '^')
- *ch = '|';
- }
- ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
- ast_parseable_goto(peer, opt_args[OPT_ARG_GOTO]);
- peer->priority++;
- ast_pbx_start(peer);
- hanguptree(outgoing, NULL);
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- if (ast_test_flag(&opts, OPT_CALLEE_MACRO) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_MACRO])) {
- char *ch;
-
- res = ast_autoservice_start(chan);
- if (res) {
- ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
- res = -1;
- }
-
- app = pbx_findapp("Macro");
-
- if (app && !res) {
- for (ch = opt_args[OPT_ARG_CALLEE_MACRO]; *ch; ch++) {
- if (*ch == '^')
- *ch = '|';
- }
- res = pbx_exec(peer, app, opt_args[OPT_ARG_CALLEE_MACRO], 1);
- ast_log(LOG_DEBUG, "Macro exited with status %d\n", res);
- res = 0;
- } else {
- ast_log(LOG_ERROR, "Could not find application Macro\n");
- res = -1;
- }
-
- if (ast_autoservice_stop(chan) < 0) {
- ast_log(LOG_ERROR, "Could not stop autoservice on calling channel\n");
- res = -1;
- }
-
- if (!res) {
- if ((macro_result = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
- if (!strcasecmp(macro_result, "BUSY")) {
- ast_copy_string(status, macro_result, sizeof(status));
- if (option_priority_jumping || ast_test_flag(&opts, OPT_PRIORITY_JUMP)) {
- if (!ast_goto_if_exists(chan, NULL, NULL, chan->priority + 101)) {
- ast_set_flag(peerflags, OPT_GO_ON);
- }
- } else
- ast_set_flag(peerflags, OPT_GO_ON);
- res = -1;
- }
- else if (!strcasecmp(macro_result, "CONGESTION") || !strcasecmp(macro_result, "CHANUNAVAIL")) {
- ast_copy_string(status, macro_result, sizeof(status));
- ast_set_flag(peerflags, OPT_GO_ON);
- res = -1;
- }
- else if (!strcasecmp(macro_result, "CONTINUE")) {
- /* hangup peer and keep chan alive assuming the macro has changed
- the context / exten / priority or perhaps
- the next priority in the current exten is desired.
- */
- ast_set_flag(peerflags, OPT_GO_ON);
- res = -1;
- } else if (!strcasecmp(macro_result, "ABORT")) {
- /* Hangup both ends unless the caller has the g flag */
- res = -1;
- } else if (!strncasecmp(macro_result, "GOTO:",5) && (macro_transfer_dest = ast_strdupa(macro_result + 5))) {
- res = -1;
- /* perform a transfer to a new extension */
- if (strchr(macro_transfer_dest,'^')) { /* context^exten^priority*/
- /* no brainer mode... substitute ^ with | and feed it to builtin goto */
- for (res=0;res<strlen(macro_transfer_dest);res++)
- if (macro_transfer_dest[res] == '^')
- macro_transfer_dest[res] = '|';
-
- if (!ast_parseable_goto(chan, macro_transfer_dest))
- ast_set_flag(peerflags, OPT_GO_ON);
-
- }
- }
- }
- }
- }
-
- if (!res) {
- if (calldurationlimit > 0) {
- time_t now;
-
- time(&now);
- chan->whentohangup = now + calldurationlimit;
- }
- if (!ast_strlen_zero(dtmfcalled)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Sending DTMF '%s' to the called party.\n",dtmfcalled);
- res = ast_dtmf_stream(peer,chan,dtmfcalled,250);
- }
- if (!ast_strlen_zero(dtmfcalling)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Sending DTMF '%s' to the calling party.\n",dtmfcalling);
- res = ast_dtmf_stream(chan,peer,dtmfcalling,250);
- }
- }
-
- if (!res) {
- memset(&config,0,sizeof(struct ast_bridge_config));
- if (play_to_caller)
- ast_set_flag(&(config.features_caller), AST_FEATURE_PLAY_WARNING);
- if (play_to_callee)
- ast_set_flag(&(config.features_callee), AST_FEATURE_PLAY_WARNING);
- if (ast_test_flag(peerflags, OPT_CALLEE_TRANSFER))
- ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
- if (ast_test_flag(peerflags, OPT_CALLER_TRANSFER))
- ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
- if (ast_test_flag(peerflags, OPT_CALLEE_HANGUP))
- ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
- if (ast_test_flag(peerflags, OPT_CALLER_HANGUP))
- ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
- if (ast_test_flag(peerflags, OPT_CALLEE_MONITOR))
- ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
- if (ast_test_flag(peerflags, OPT_CALLER_MONITOR))
- ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
-
- config.timelimit = timelimit;
- config.play_warning = play_warning;
- config.warning_freq = warning_freq;
- config.warning_sound = warning_sound;
- config.end_sound = end_sound;
- config.start_sound = start_sound;
- if (moh) {
- moh = 0;
- ast_moh_stop(chan);
- } else if (sentringing) {
- sentringing = 0;
- ast_indicate(chan, -1);
- }
- /* Be sure no generators are left on it */
- ast_deactivate_generator(chan);
- /* Make sure channels are compatible */
- res = ast_channel_make_compatible(chan, peer);
- if (res < 0) {
- ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", chan->name, peer->name);
- ast_hangup(peer);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- res = ast_bridge_call(chan,peer,&config);
- time(&end_time);
- snprintf(toast, sizeof(toast), "%ld", (long)(end_time - answer_time));
- pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", toast);
-
- } else {
- time(&end_time);
- res = -1;
- }
- snprintf(toast, sizeof(toast), "%ld", (long)(end_time - start_time));
- pbx_builtin_setvar_helper(chan, "DIALEDTIME", toast);
-
- if (res != AST_PBX_NO_HANGUP_PEER) {
- if (!chan->_softhangup)
- chan->hangupcause = peer->hangupcause;
- ast_hangup(peer);
- }
- }
-out:
- if (moh) {
- moh = 0;
- ast_moh_stop(chan);
- } else if (sentringing) {
- sentringing = 0;
- ast_indicate(chan, -1);
- }
- hanguptree(outgoing, NULL);
- pbx_builtin_setvar_helper(chan, "DIALSTATUS", status);
- ast_log(LOG_DEBUG, "Exiting with DIALSTATUS=%s.\n", status);
-
- if ((ast_test_flag(peerflags, OPT_GO_ON)) && (!chan->_softhangup) && (res != AST_PBX_KEEPALIVE))
- res=0;
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-static int dial_exec(struct ast_channel *chan, void *data)
-{
- struct ast_flags peerflags;
- memset(&peerflags, 0, sizeof(peerflags));
- return dial_exec_full(chan, data, &peerflags);
-}
-
-static int retrydial_exec(struct ast_channel *chan, void *data)
-{
- char *announce = NULL, *context = NULL, *dialdata = NULL;
- int sleep = 0, loops = 0, res = 0;
- struct localuser *u;
- struct ast_flags peerflags;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- announce = ast_strdupa(data);
- if (!announce) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- memset(&peerflags, 0, sizeof(peerflags));
-
- if ((dialdata = strchr(announce, '|'))) {
- *dialdata = '\0';
- dialdata++;
- if ((sleep = atoi(dialdata))) {
- sleep *= 1000;
- } else {
- ast_log(LOG_ERROR, "%s requires the numerical argument <sleep>\n",rapp);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- if ((dialdata = strchr(dialdata, '|'))) {
- *dialdata = '\0';
- dialdata++;
- if (!(loops = atoi(dialdata))) {
- ast_log(LOG_ERROR, "%s requires the numerical argument <loops>\n",rapp);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
- }
-
- if ((dialdata = strchr(dialdata, '|'))) {
- *dialdata = '\0';
- dialdata++;
- } else {
- ast_log(LOG_ERROR, "%s requires more arguments\n",rapp);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (sleep < 1000)
- sleep = 10000;
-
- if (!loops)
- loops = -1;
-
- context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
-
- while (loops) {
- chan->data = "Retrying";
- if (ast_test_flag(chan, AST_FLAG_MOH))
- ast_moh_stop(chan);
-
- if ((res = dial_exec_full(chan, dialdata, &peerflags)) == 0) {
- if (ast_test_flag(&peerflags, OPT_DTMF_EXIT)) {
- if (!(res = ast_streamfile(chan, announce, chan->language)))
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- if (!res && sleep) {
- if (!ast_test_flag(chan, AST_FLAG_MOH))
- ast_moh_start(chan, NULL);
- res = ast_waitfordigit(chan, sleep);
- }
- } else {
- if (!(res = ast_streamfile(chan, announce, chan->language)))
- res = ast_waitstream(chan, "");
- if (sleep) {
- if (!ast_test_flag(chan, AST_FLAG_MOH))
- ast_moh_start(chan, NULL);
- if (!res)
- res = ast_waitfordigit(chan, sleep);
- }
- }
- }
-
- if (res < 0)
- break;
- else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */
- if (onedigit_goto(chan, context, (char) res, 1)) {
- res = 0;
- break;
- }
- }
- loops--;
- }
-
- if (ast_test_flag(chan, AST_FLAG_MOH))
- ast_moh_stop(chan);
-
- LOCAL_USER_REMOVE(u);
- return loops ? res : 0;
-
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
- res |= ast_unregister_application(rapp);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app, dial_exec, synopsis, descrip);
- res |= ast_register_application(rapp, retrydial_exec, rsynopsis, rdescrip);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_dictate.c b/1.2-netsec/apps/app_dictate.c
deleted file mode 100644
index 91a1650ea..000000000
--- a/1.2-netsec/apps/app_dictate.c
+++ /dev/null
@@ -1,358 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Anthony Minessale II
- *
- * Anthony Minessale II <anthmct@yahoo.com>
- *
- * Donated by Sangoma Technologies <http://www.samgoma.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Virtual Dictation Machine Application For Asterisk
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/stat.h> /* for mkdir */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/say.h"
-#include "asterisk/lock.h"
-#include "asterisk/app.h"
-
-static char *tdesc = "Virtual Dictation Machine";
-static char *app = "Dictate";
-static char *synopsis = "Virtual Dictation Machine";
-static char *desc = " Dictate([<base_dir>])\n"
-"Start dictation machine using optional base dir for files.\n";
-
-
-STANDARD_LOCAL_USER;
-LOCAL_USER_DECL;
-
-typedef enum {
- DFLAG_RECORD = (1 << 0),
- DFLAG_PLAY = (1 << 1),
- DFLAG_TRUNC = (1 << 2),
- DFLAG_PAUSE = (1 << 3),
-} dflags;
-
-typedef enum {
- DMODE_INIT,
- DMODE_RECORD,
- DMODE_PLAY
-} dmodes;
-
-#define ast_toggle_flag(it,flag) if(ast_test_flag(it, flag)) ast_clear_flag(it, flag); else ast_set_flag(it, flag)
-
-static int play_and_wait(struct ast_channel *chan, char *file, char *digits)
-{
- int res = -1;
- if (!ast_streamfile(chan, file, chan->language)) {
- res = ast_waitstream(chan, digits);
- }
- return res;
-}
-
-static int dictate_exec(struct ast_channel *chan, void *data)
-{
- char *mydata, *argv[2], *path = NULL, filein[256];
- char dftbase[256];
- char *base;
- struct ast_flags flags = {0};
- struct ast_filestream *fs;
- struct ast_frame *f = NULL;
- struct localuser *u;
- int ffactor = 320 * 80,
- res = 0,
- argc = 0,
- done = 0,
- oldr = 0,
- lastop = 0,
- samples = 0,
- speed = 1,
- digit = 0,
- len = 0,
- maxlen = 0,
- mode = 0;
-
- LOCAL_USER_ADD(u);
-
- snprintf(dftbase, sizeof(dftbase), "%s/dictate", ast_config_AST_SPOOL_DIR);
- if (!ast_strlen_zero(data) && (mydata = ast_strdupa(data))) {
- argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
- }
-
- if (argc) {
- base = argv[0];
- } else {
- base = dftbase;
- }
-
- 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);
- return -1;
- }
-
- ast_answer(chan);
- ast_safe_sleep(chan, 200);
- for(res = 0; !res;) {
- if (ast_app_getdata(chan, "dictate/enter_filename", filein, sizeof(filein), 0) ||
- ast_strlen_zero(filein)) {
- res = -1;
- break;
- }
-
- mkdir(base, 0755);
- len = strlen(base) + strlen(filein) + 2;
- if (!path || len > maxlen) {
- path = alloca(len);
- memset(path, 0, len);
- maxlen = len;
- } else {
- memset(path, 0, maxlen);
- }
-
- snprintf(path, len, "%s/%s", base, filein);
- fs = ast_writefile(path, "raw", NULL, O_CREAT|O_APPEND, 0, 0700);
- mode = DMODE_PLAY;
- memset(&flags, 0, sizeof(flags));
- ast_set_flag(&flags, DFLAG_PAUSE);
- digit = play_and_wait(chan, "dictate/forhelp", AST_DIGIT_ANY);
- done = 0;
- speed = 1;
- res = 0;
- lastop = 0;
- samples = 0;
- while (!done && ((res = ast_waitfor(chan, -1)) > -1) && fs && (f = ast_read(chan))) {
- if (digit) {
- struct ast_frame fr = {AST_FRAME_DTMF, digit};
- ast_queue_frame(chan, &fr);
- digit = 0;
- }
- if ((f->frametype == AST_FRAME_DTMF)) {
- int got = 1;
- switch(mode) {
- case DMODE_PLAY:
- switch(f->subclass) {
- case '1':
- ast_set_flag(&flags, DFLAG_PAUSE);
- mode = DMODE_RECORD;
- break;
- case '2':
- speed++;
- if (speed > 4) {
- speed = 1;
- }
- res = ast_say_number(chan, speed, AST_DIGIT_ANY, chan->language, (char *) NULL);
- break;
- case '7':
- samples -= ffactor;
- if(samples < 0) {
- samples = 0;
- }
- ast_seekstream(fs, samples, SEEK_SET);
- break;
- case '8':
- samples += ffactor;
- ast_seekstream(fs, samples, SEEK_SET);
- break;
-
- default:
- got = 0;
- }
- break;
- case DMODE_RECORD:
- switch(f->subclass) {
- case '1':
- ast_set_flag(&flags, DFLAG_PAUSE);
- mode = DMODE_PLAY;
- break;
- case '8':
- ast_toggle_flag(&flags, DFLAG_TRUNC);
- lastop = 0;
- break;
- default:
- got = 0;
- }
- break;
- default:
- got = 0;
- }
- if (!got) {
- switch(f->subclass) {
- case '#':
- done = 1;
- continue;
- break;
- case '*':
- ast_toggle_flag(&flags, DFLAG_PAUSE);
- if (ast_test_flag(&flags, DFLAG_PAUSE)) {
- digit = play_and_wait(chan, "dictate/pause", AST_DIGIT_ANY);
- } else {
- digit = play_and_wait(chan, mode == DMODE_PLAY ? "dictate/playback" : "dictate/record", AST_DIGIT_ANY);
- }
- break;
- case '0':
- ast_set_flag(&flags, DFLAG_PAUSE);
- digit = play_and_wait(chan, "dictate/paused", AST_DIGIT_ANY);
- switch(mode) {
- case DMODE_PLAY:
- digit = play_and_wait(chan, "dictate/play_help", AST_DIGIT_ANY);
- break;
- case DMODE_RECORD:
- digit = play_and_wait(chan, "dictate/record_help", AST_DIGIT_ANY);
- break;
- }
- if (digit == 0) {
- digit = play_and_wait(chan, "dictate/both_help", AST_DIGIT_ANY);
- } else if (digit < 0) {
- done = 1;
- break;
- }
- break;
- }
- }
-
- } else if (f->frametype == AST_FRAME_VOICE) {
- switch(mode) {
- struct ast_frame *fr;
- int x;
- case DMODE_PLAY:
- if (lastop != DMODE_PLAY) {
- if (ast_test_flag(&flags, DFLAG_PAUSE)) {
- digit = play_and_wait(chan, "dictate/playback_mode", AST_DIGIT_ANY);
- if (digit == 0) {
- digit = play_and_wait(chan, "dictate/paused", AST_DIGIT_ANY);
- } else if (digit < 0) {
- break;
- }
- }
- if (lastop != DFLAG_PLAY) {
- lastop = DFLAG_PLAY;
- ast_closestream(fs);
- fs = ast_openstream(chan, path, chan->language);
- ast_seekstream(fs, samples, SEEK_SET);
- chan->stream = NULL;
- }
- lastop = DMODE_PLAY;
- }
-
- if (!ast_test_flag(&flags, DFLAG_PAUSE)) {
- for (x = 0; x < speed; x++) {
- if ((fr = ast_readframe(fs))) {
- ast_write(chan, fr);
- samples += fr->samples;
- ast_frfree(fr);
- fr = NULL;
- } else {
- samples = 0;
- ast_seekstream(fs, 0, SEEK_SET);
- }
- }
- }
- break;
- case DMODE_RECORD:
- if (lastop != DMODE_RECORD) {
- int oflags = O_CREAT | O_WRONLY;
- if (ast_test_flag(&flags, DFLAG_PAUSE)) {
- digit = play_and_wait(chan, "dictate/record_mode", AST_DIGIT_ANY);
- if (digit == 0) {
- digit = play_and_wait(chan, "dictate/paused", AST_DIGIT_ANY);
- } else if (digit < 0) {
- break;
- }
- }
- lastop = DMODE_RECORD;
- ast_closestream(fs);
- if ( ast_test_flag(&flags, DFLAG_TRUNC)) {
- oflags |= O_TRUNC;
- digit = play_and_wait(chan, "dictate/truncating_audio", AST_DIGIT_ANY);
- } else {
- oflags |= O_APPEND;
- }
- fs = ast_writefile(path, "raw", NULL, oflags, 0, 0700);
- if (ast_test_flag(&flags, DFLAG_TRUNC)) {
- ast_seekstream(fs, 0, SEEK_SET);
- ast_clear_flag(&flags, DFLAG_TRUNC);
- } else {
- ast_seekstream(fs, 0, SEEK_END);
- }
- }
- if (!ast_test_flag(&flags, DFLAG_PAUSE)) {
- res = ast_writestream(fs, f);
- }
- break;
- }
-
- }
-
- ast_frfree(f);
- }
- }
- if (oldr) {
- ast_set_read_format(chan, oldr);
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, dictate_exec, synopsis, desc);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_directed_pickup.c b/1.2-netsec/apps/app_directed_pickup.c
deleted file mode 100644
index 9e7d3cc84..000000000
--- a/1.2-netsec/apps/app_directed_pickup.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Joshua Colp
- *
- * Joshua Colp <jcolp@asterlink.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Directed Call Pickup Support
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/app.h"
-
-static const char *tdesc = "Directed Call Pickup Application";
-static const char *app = "Pickup";
-static const char *synopsis = "Directed Call Pickup";
-static const char *descrip =
-" Pickup(extension[@context]): This application can pickup any ringing channel\n"
-"that is calling the specified extension. If no context is specified, the current\n"
-"context will be used.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int pickup_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u = NULL;
- struct ast_channel *origin = NULL, *target = NULL;
- char *tmp = NULL, *exten = NULL, *context = NULL;
- char workspace[256] = "";
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Pickup requires an argument (extension) !\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- /* Get the extension and context if present */
- exten = data;
- context = strchr(data, '@');
- if (context) {
- *context = '\0';
- context++;
- }
-
- /* Find a channel to pickup */
- origin = ast_get_channel_by_exten_locked(exten, context);
- if (origin && origin->cdr) {
- ast_cdr_getvar(origin->cdr, "dstchannel", &tmp, workspace,
- sizeof(workspace), 0);
- if (tmp) {
- /* We have a possible channel... now we need to find it! */
- target = ast_get_channel_by_name_locked(tmp);
- } else {
- ast_log(LOG_DEBUG, "No target channel found.\n");
- res = -1;
- }
- ast_mutex_unlock(&origin->lock);
- } else {
- if (origin)
- ast_mutex_unlock(&origin->lock);
- ast_log(LOG_DEBUG, "No originating channel found.\n");
- }
-
- if (res)
- goto out;
-
- if (target && (!target->pbx) && ((target->_state == AST_STATE_RINGING) || (target->_state == AST_STATE_RING))) {
- ast_log(LOG_DEBUG, "Call pickup on chan '%s' by '%s'\n", target->name,
- chan->name);
- res = ast_answer(chan);
- if (res) {
- ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
- res = -1;
- goto out;
- }
- res = ast_queue_control(chan, AST_CONTROL_ANSWER);
- if (res) {
- ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n",
- chan->name);
- res = -1;
- goto out;
- }
- res = ast_channel_masquerade(target, chan);
- if (res) {
- ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name);
- res = -1;
- goto out;
- }
- } else {
- ast_log(LOG_DEBUG, "No call pickup possible...\n");
- res = -1;
- }
- /* Done */
- out:
- if (target)
- ast_mutex_unlock(&target->lock);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, pickup_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return (char *) tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
-
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_directory.c b/1.2-netsec/apps/app_directory.c
deleted file mode 100644
index dc1181b6d..000000000
--- a/1.2-netsec/apps/app_directory.c
+++ /dev/null
@@ -1,516 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Provide a directory of extensions
- *
- * \ingroup applications
- */
-
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/say.h"
-#include "asterisk/utils.h"
-
-static char *tdesc = "Extension Directory";
-static char *app = "Directory";
-
-static char *synopsis = "Provide directory of voicemail extensions";
-static char *descrip =
-" Directory(vm-context[|dial-context[|options]]): This application will present\n"
-"the calling channel with a directory of extensions from which they can search\n"
-"by name. The list of names and corresponding extensions is retrieved from the\n"
-"voicemail configuration file, voicemail.conf.\n"
-" This applicaiton will immediate exit if one of the following DTMF digits are\n"
-"received and the extension to jump to exists:\n"
-" 0 - Jump to the 'o' extension, if it exists.\n"
-" * - Jump to the 'a' extension, if it exists.\n\n"
-" Parameters:\n"
-" vm-context - This is the context within voicemail.conf to use for the\n"
-" Directory.\n"
-" dial-context - This is the dialplan context to use when looking for an\n"
-" extension that the user has selected, or when jumping to the\n"
-" 'o' or 'a' extension.\n\n"
-" Options:\n"
-" f - Allow the caller to enter the first name of a user in the directory\n"
-" instead of using the last name.\n";
-
-/* For simplicity, I'm keeping the format compatible with the voicemail config,
- but i'm open to suggestions for isolating it */
-
-#define VOICEMAIL_CONFIG "voicemail.conf"
-
-/* How many digits to read in */
-#define NUMDIGITS 3
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static char *convert(char *lastname)
-{
- char *tmp;
- int lcount = 0;
- tmp = malloc(NUMDIGITS + 1);
- if (tmp) {
- while((*lastname > 32) && lcount < NUMDIGITS) {
- switch(toupper(*lastname)) {
- case '1':
- tmp[lcount++] = '1';
- break;
- case '2':
- case 'A':
- case 'B':
- case 'C':
- tmp[lcount++] = '2';
- break;
- case '3':
- case 'D':
- case 'E':
- case 'F':
- tmp[lcount++] = '3';
- break;
- case '4':
- case 'G':
- case 'H':
- case 'I':
- tmp[lcount++] = '4';
- break;
- case '5':
- case 'J':
- case 'K':
- case 'L':
- tmp[lcount++] = '5';
- break;
- case '6':
- case 'M':
- case 'N':
- case 'O':
- tmp[lcount++] = '6';
- break;
- case '7':
- case 'P':
- case 'Q':
- case 'R':
- case 'S':
- tmp[lcount++] = '7';
- break;
- case '8':
- case 'T':
- case 'U':
- case 'V':
- tmp[lcount++] = '8';
- break;
- case '9':
- case 'W':
- case 'X':
- case 'Y':
- case 'Z':
- tmp[lcount++] = '9';
- break;
- }
- lastname++;
- }
- tmp[lcount] = '\0';
- }
- return tmp;
-}
-
-/* play name of mailbox owner.
- * returns: -1 for bad or missing extension
- * '1' for selected entry from directory
- * '*' for skipped entry from directory
- */
-static int play_mailbox_owner(struct ast_channel *chan, char *context, char *dialcontext, char *ext, char *name) {
- int res = 0;
- int loop = 3;
- char fn[256];
- char fn2[256];
-
- /* Check for the VoiceMail2 greeting first */
- snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/greet",
- (char *)ast_config_AST_SPOOL_DIR, context, ext);
-
- /* Otherwise, check for an old-style Voicemail greeting */
- snprintf(fn2, sizeof(fn2), "%s/vm/%s/greet",
- (char *)ast_config_AST_SPOOL_DIR, ext);
-
- if (ast_fileexists(fn, NULL, chan->language) > 0) {
- res = ast_streamfile(chan, fn, chan->language);
- if (!res) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- }
- ast_stopstream(chan);
- } else if (ast_fileexists(fn2, NULL, chan->language) > 0) {
- res = ast_streamfile(chan, fn2, chan->language);
- if (!res) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- }
- ast_stopstream(chan);
- } else {
- res = ast_say_character_str(chan, !ast_strlen_zero(name) ? name : ext,
- AST_DIGIT_ANY, chan->language);
- }
-
- while (loop) {
- if (!res) {
- res = ast_streamfile(chan, "dir-instr", chan->language);
- }
- if (!res) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- }
- if (!res) {
- res = ast_waitfordigit(chan, 3000);
- }
- ast_stopstream(chan);
-
- if (res > -1) {
- switch (res) {
- case '1':
- /* Name selected */
- loop = 0;
- if (ast_goto_if_exists(chan, dialcontext, ext, 1)) {
- ast_log(LOG_WARNING,
- "Can't find extension '%s' in context '%s'. "
- "Did you pass the wrong context to Directory?\n",
- ext, dialcontext);
- res = -1;
- }
- break;
-
- case '*':
- /* Skip to next match in list */
- loop = 0;
- break;
-
- default:
- /* Not '1', or '*', so decrement number of tries */
- res = 0;
- loop--;
- break;
- } /* end switch */
- } /* end if */
- else {
- /* User hungup, so jump out now */
- loop = 0;
- }
- } /* end while */
-
- return(res);
-}
-
-static struct ast_config *realtime_directory(char *context)
-{
- struct ast_config *cfg;
- struct ast_config *rtdata;
- struct ast_category *cat;
- struct ast_variable *var;
- char *mailbox;
- char *fullname;
- char *hidefromdir;
- char tmp[100];
-
- /* Load flat file config. */
- cfg = ast_config_load(VOICEMAIL_CONFIG);
-
- if (!cfg) {
- /* Loading config failed. */
- ast_log(LOG_WARNING, "Loading config failed.\n");
- return NULL;
- }
-
- /* Get realtime entries, categorized by their mailbox number
- and present in the requested context */
- rtdata = ast_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", context, NULL);
-
- /* if there are no results, just return the entries from the config file */
- if (!rtdata)
- return cfg;
-
- /* Does the context exist within the config file? If not, make one */
- cat = ast_category_get(cfg, context);
- if (!cat) {
- cat = ast_category_new(context);
- if (!cat) {
- ast_log(LOG_WARNING, "Out of memory\n");
- ast_config_destroy(cfg);
- return NULL;
- }
- ast_category_append(cfg, cat);
- }
-
- mailbox = ast_category_browse(rtdata, NULL);
- while (mailbox) {
- fullname = ast_variable_retrieve(rtdata, mailbox, "fullname");
- hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir");
- snprintf(tmp, sizeof(tmp), "no-password,%s,hidefromdir=%s",
- fullname ? fullname : "",
- hidefromdir ? hidefromdir : "no");
- var = ast_variable_new(mailbox, tmp);
- if (var)
- ast_variable_append(cat, var);
- else
- ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
- mailbox = ast_category_browse(rtdata, mailbox);
- }
- ast_config_destroy(rtdata);
-
- return cfg;
-}
-
-static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *context, char *dialcontext, char digit, int last)
-{
- /* Read in the first three digits.. "digit" is the first digit, already read */
- char ext[NUMDIGITS + 1];
- char name[80] = "";
- struct ast_variable *v;
- int res;
- int found=0;
- int lastuserchoice = 0;
- char *start, *pos, *conv,*stringp=NULL;
-
- if (ast_strlen_zero(context)) {
- ast_log(LOG_WARNING,
- "Directory must be called with an argument "
- "(context in which to interpret extensions)\n");
- return -1;
- }
- if (digit == '0') {
- if (!ast_goto_if_exists(chan, chan->context, "o", 1) ||
- (!ast_strlen_zero(chan->macrocontext) &&
- !ast_goto_if_exists(chan, chan->macrocontext, "o", 1))) {
- return 0;
- } else {
- ast_log(LOG_WARNING, "Can't find extension 'o' in current context. "
- "Not Exiting the Directory!\n");
- res = 0;
- }
- }
- if (digit == '*') {
- if (!ast_goto_if_exists(chan, chan->context, "a", 1) ||
- (!ast_strlen_zero(chan->macrocontext) &&
- !ast_goto_if_exists(chan, chan->macrocontext, "a", 1))) {
- return 0;
- } else {
- ast_log(LOG_WARNING, "Can't find extension 'a' in current context. "
- "Not Exiting the Directory!\n");
- res = 0;
- }
- }
- memset(ext, 0, sizeof(ext));
- ext[0] = digit;
- res = 0;
- if (ast_readstring(chan, ext + 1, NUMDIGITS - 1, 3000, 3000, "#") < 0) res = -1;
- if (!res) {
- /* Search for all names which start with those digits */
- v = ast_variable_browse(cfg, context);
- while(v && !res) {
- /* Find all candidate extensions */
- while(v) {
- /* Find a candidate extension */
- start = strdup(v->value);
- if (start && !strcasestr(start, "hidefromdir=yes")) {
- stringp=start;
- strsep(&stringp, ",");
- pos = strsep(&stringp, ",");
- if (pos) {
- ast_copy_string(name, pos, sizeof(name));
- /* Grab the last name */
- if (last && strrchr(pos,' '))
- pos = strrchr(pos, ' ') + 1;
- conv = convert(pos);
- if (conv) {
- if (!strcmp(conv, ext)) {
- /* Match! */
- found++;
- free(conv);
- free(start);
- break;
- }
- free(conv);
- }
- }
- free(start);
- }
- v = v->next;
- }
-
- if (v) {
- /* We have a match -- play a greeting if they have it */
- res = play_mailbox_owner(chan, context, dialcontext, v->name, name);
- switch (res) {
- case -1:
- /* user pressed '1' but extension does not exist, or
- * user hungup
- */
- lastuserchoice = 0;
- break;
- case '1':
- /* user pressed '1' and extensions exists;
- play_mailbox_owner will already have done
- a goto() on the channel
- */
- lastuserchoice = res;
- break;
- case '*':
- /* user pressed '*' to skip something found */
- lastuserchoice = res;
- res = 0;
- break;
- default:
- break;
- }
- v = v->next;
- }
- }
-
- if (lastuserchoice != '1') {
- if (found)
- res = ast_streamfile(chan, "dir-nomore", chan->language);
- else
- res = ast_streamfile(chan, "dir-nomatch", chan->language);
- if (!res)
- res = 1;
- return res;
- }
- return 0;
- }
- return res;
-}
-
-static int directory_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- struct ast_config *cfg;
- int last = 1;
- char *context, *dialcontext, *dirintro, *options;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Directory requires an argument (context[,dialcontext])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- context = ast_strdupa(data);
- dialcontext = strchr(context, '|');
- if (dialcontext) {
- *dialcontext = '\0';
- dialcontext++;
- options = strchr(dialcontext, '|');
- if (options) {
- *options = '\0';
- options++;
- if (strchr(options, 'f'))
- last = 0;
- }
- } else
- dialcontext = context;
-
- cfg = realtime_directory(context);
- if (!cfg) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- dirintro = ast_variable_retrieve(cfg, context, "directoryintro");
- if (ast_strlen_zero(dirintro))
- dirintro = ast_variable_retrieve(cfg, "general", "directoryintro");
- if (ast_strlen_zero(dirintro)) {
- if (last)
- dirintro = "dir-intro";
- else
- dirintro = "dir-intro-fn";
- }
-
- if (chan->_state != AST_STATE_UP)
- res = ast_answer(chan);
-
- for (;;) {
- if (!res)
- res = ast_streamfile(chan, dirintro, chan->language);
- if (!res)
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- if (!res)
- res = ast_waitfordigit(chan, 5000);
- if (res > 0) {
- res = do_directory(chan, cfg, context, dialcontext, res, last);
- if (res > 0) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- if (res >= 0) {
- continue;
- }
- }
- }
- break;
- }
- ast_config_destroy(cfg);
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, directory_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_disa.c b/1.2-netsec/apps/app_disa.c
deleted file mode 100644
index 2ac124525..000000000
--- a/1.2-netsec/apps/app_disa.c
+++ /dev/null
@@ -1,412 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- *
- * Made only slightly more sane by Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief DISA -- Direct Inward System Access Application
- *
- * \author Jim Dixon <jim@lambdatel.com>
- *
- * \ingroup applications
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <sys/time.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/app.h"
-#include "asterisk/indications.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/ulaw.h"
-#include "asterisk/callerid.h"
-
-static char *tdesc = "DISA (Direct Inward System Access) Application";
-
-static char *app = "DISA";
-
-static char *synopsis = "DISA (Direct Inward System Access)";
-
-static char *descrip =
- "DISA(<numeric passcode>[|<context>]) or disa(<filename>)\n"
- "The DISA, Direct Inward System Access, application allows someone from \n"
- "outside the telephone switch (PBX) to obtain an \"internal\" system \n"
- "dialtone and to place calls from it as if they were placing a call from \n"
- "within the switch.\n"
- "DISA plays a dialtone. The user enters their numeric passcode, followed by\n"
- "the pound sign (#). If the passcode is correct, the user is then given\n"
- "system dialtone on which a call may be placed. Obviously, this type\n"
- "of access has SERIOUS security implications, and GREAT care must be\n"
- "taken NOT to compromise your security.\n\n"
- "There is a possibility of accessing DISA without password. Simply\n"
- "exchange your password with \"no-password\".\n\n"
- " Example: exten => s,1,DISA(no-password|local)\n\n"
- "Be aware that using this compromises the security of your PBX.\n\n"
- "The arguments to this application (in extensions.conf) allow either\n"
- "specification of a single global passcode (that everyone uses), or\n"
- "individual passcodes contained in a file. It also allow specification\n"
- "of the context on which the user will be dialing. If no context is\n"
- "specified, the DISA application defaults the context to \"disa\".\n"
- "Presumably a normal system will have a special context set up\n"
- "for DISA use with some or a lot of restrictions. \n\n"
- "The file that contains the passcodes (if used) allows specification\n"
- "of either just a passcode (defaulting to the \"disa\" context, or\n"
- "passcode|context on each line of the file. The file may contain blank\n"
- "lines, or comments starting with \"#\" or \";\". In addition, the\n"
- "above arguments may have |new-callerid-string appended to them, to\n"
- "specify a new (different) callerid to be used for this call, for\n"
- "example: numeric-passcode|context|\"My Phone\" <(234) 123-4567> or \n"
- "full-pathname-of-passcode-file|\"My Phone\" <(234) 123-4567>. Last\n"
- "but not least, |mailbox[@context] may be appended, which will cause\n"
- "a stutter-dialtone (indication \"dialrecall\") to be used, if the\n"
- "specified mailbox contains any new messages, for example:\n"
- "numeric-passcode|context||1234 (w/a changing callerid). Note that\n"
- "in the case of specifying the numeric-passcode, the context must be\n"
- "specified if the callerid is specified also.\n\n"
- "If login is successful, the application looks up the dialed number in\n"
- "the specified (or default) context, and executes it if found.\n"
- "If the user enters an invalid extension and extension \"i\" (invalid) \n"
- "exists in the context, it will be used.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static void play_dialtone(struct ast_channel *chan, char *mailbox)
-{
- const struct tone_zone_sound *ts = NULL;
- if(ast_app_has_voicemail(mailbox, NULL))
- ts = ast_get_indication_tone(chan->zone, "dialrecall");
- else
- ts = ast_get_indication_tone(chan->zone, "dial");
- if (ts)
- ast_playtones_start(chan, 0, ts->data, 0);
- else
- ast_tonepair_start(chan, 350, 440, 0, 0);
-}
-
-static int disa_exec(struct ast_channel *chan, void *data)
-{
- int i,j,k,x,did_ignore;
- int firstdigittimeout = 20000;
- int digittimeout = 10000;
- struct localuser *u;
- char *tmp, exten[AST_MAX_EXTENSION],acctcode[20]="";
- char pwline[256];
- char ourcidname[256],ourcidnum[256];
- struct ast_frame *f;
- struct timeval lastdigittime;
- int res;
- time_t rstart;
- FILE *fp;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(passcode);
- AST_APP_ARG(context);
- AST_APP_ARG(cid);
- AST_APP_ARG(mailbox);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "disa requires an argument (passcode/passcode file)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (chan->pbx) {
- firstdigittimeout = chan->pbx->rtimeout*1000;
- digittimeout = chan->pbx->dtimeout*1000;
- }
-
- 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);
- 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);
- return -1;
- }
-
- ast_log(LOG_DEBUG, "Digittimeout: %d\n", digittimeout);
- ast_log(LOG_DEBUG, "Responsetimeout: %d\n", firstdigittimeout);
-
- tmp = ast_strdupa(data);
- if (!tmp) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, tmp);
-
- if (ast_strlen_zero(args.context))
- args.context = "disa";
- if (ast_strlen_zero(args.mailbox))
- args.mailbox = "";
-
- ast_log(LOG_DEBUG, "Mailbox: %s\n",args.mailbox);
-
- if (chan->_state != AST_STATE_UP) {
- /* answer */
- ast_answer(chan);
- }
- i = k = x = 0; /* k is 0 for pswd entry, 1 for ext entry */
- did_ignore = 0;
- exten[0] = 0;
- acctcode[0] = 0;
- /* can we access DISA without password? */
-
- ast_log(LOG_DEBUG, "Context: %s\n",args.context);
-
- if (!strcasecmp(args.passcode, "no-password")) {
- k |= 1; /* We have the password */
- ast_log(LOG_DEBUG, "DISA no-password login success\n");
- }
- lastdigittime = ast_tvnow();
-
- play_dialtone(chan, args.mailbox);
-
- for (;;) {
- /* if outa time, give em reorder */
- if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) >
- ((k&2) ? digittimeout : firstdigittimeout))
- {
- ast_log(LOG_DEBUG,"DISA %s entry timeout on chan %s\n",
- ((k&1) ? "extension" : "password"),chan->name);
- break;
- }
- if ((res = ast_waitfor(chan, -1) < 0)) {
- ast_log(LOG_DEBUG, "Waitfor returned %d\n", res);
- continue;
- }
-
- f = ast_read(chan);
- if (f == NULL)
- {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- if ((f->frametype == AST_FRAME_CONTROL) &&
- (f->subclass == AST_CONTROL_HANGUP))
- {
- ast_frfree(f);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- if (f->frametype == AST_FRAME_VOICE) {
- ast_frfree(f);
- continue;
- }
- /* if not DTMF, just do it again */
- if (f->frametype != AST_FRAME_DTMF)
- {
- ast_frfree(f);
- continue;
- }
-
- j = f->subclass; /* save digit */
- ast_frfree(f);
- if (i == 0)
- {
- k|=2; /* We have the first digit */
- ast_playtones_stop(chan);
- }
- lastdigittime = ast_tvnow();
- /* got a DTMF tone */
- if (i < AST_MAX_EXTENSION) /* if still valid number of digits */
- {
- if (!(k&1)) /* if in password state */
- {
- if (j == '#') /* end of password */
- {
- /* see if this is an integer */
- if (sscanf(args.passcode,"%d",&j) < 1)
- { /* nope, it must be a filename */
- 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);
- return -1;
- }
- pwline[0] = 0;
- while(fgets(pwline,sizeof(pwline) - 1,fp))
- {
- if (!pwline[0]) continue;
- if (pwline[strlen(pwline) - 1] == '\n')
- pwline[strlen(pwline) - 1] = 0;
- if (!pwline[0]) continue;
- /* skip comments */
- if (pwline[0] == '#') continue;
- if (pwline[0] == ';') continue;
-
- AST_STANDARD_APP_ARGS(args, pwline);
-
- ast_log(LOG_DEBUG, "Mailbox: %s\n",args.mailbox);
-
- /* password must be in valid format (numeric) */
- if (sscanf(args.passcode,"%d",&j) < 1) continue;
- /* if we got it */
- if (!strcmp(exten,args.passcode)) {
- if (ast_strlen_zero(args.context))
- args.context = "disa";
- if (ast_strlen_zero(args.mailbox))
- args.mailbox = "";
- break;
- }
- }
- fclose(fp);
- }
- /* compare the two */
- if (strcmp(exten,args.passcode))
- {
- ast_log(LOG_WARNING,"DISA on chan %s got bad password %s\n",chan->name,exten);
- goto reorder;
-
- }
- /* password good, set to dial state */
- ast_log(LOG_DEBUG,"DISA on chan %s password is good\n",chan->name);
- play_dialtone(chan, args.mailbox);
-
- k|=1; /* In number mode */
- i = 0; /* re-set buffer pointer */
- exten[sizeof(acctcode)] = 0;
- ast_copy_string(acctcode, exten, sizeof(acctcode));
- exten[0] = 0;
- ast_log(LOG_DEBUG,"Successful DISA log-in on chan %s\n",chan->name);
- continue;
- }
- }
-
- exten[i++] = j; /* save digit */
- exten[i] = 0;
- if (!(k&1)) continue; /* if getting password, continue doing it */
- /* if this exists */
-
- if (ast_ignore_pattern(args.context, exten)) {
- play_dialtone(chan, "");
- did_ignore = 1;
- } else
- if (did_ignore) {
- ast_playtones_stop(chan);
- did_ignore = 0;
- }
-
- /* if can do some more, do it */
- if (!ast_matchmore_extension(chan,args.context,exten,1, chan->cid.cid_num)) {
- break;
- }
- }
- }
-
- if (k == 3) {
- int recheck = 0;
- struct ast_flags flags = { AST_CDR_FLAG_POSTED };
-
- if (!ast_exists_extension(chan, args.context, exten, 1, chan->cid.cid_num)) {
- pbx_builtin_setvar_helper(chan, "INVALID_EXTEN", exten);
- exten[0] = 'i';
- exten[1] = '\0';
- recheck = 1;
- }
- if (!recheck || ast_exists_extension(chan, args.context, exten, 1, chan->cid.cid_num)) {
- ast_playtones_stop(chan);
- /* We're authenticated and have a target extension */
- if (!ast_strlen_zero(args.cid))
- {
- ast_callerid_split(args.cid, ourcidname, sizeof(ourcidname), ourcidnum, sizeof(ourcidnum));
- ast_set_callerid(chan, ourcidnum, ourcidname, ourcidnum);
- }
-
- if (!ast_strlen_zero(acctcode))
- ast_copy_string(chan->accountcode, acctcode, sizeof(chan->accountcode));
-
- ast_cdr_reset(chan->cdr, &flags);
- ast_explicit_goto(chan, args.context, exten, 1);
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- }
-
- /* Received invalid, but no "i" extension exists in the given context */
-
-reorder:
-
- ast_indicate(chan,AST_CONTROL_CONGESTION);
- /* something is invalid, give em reorder for several seconds */
- time(&rstart);
- while(time(NULL) < rstart + 10)
- {
- if (ast_waitfor(chan, -1) < 0)
- break;
- f = ast_read(chan);
- if (!f)
- break;
- ast_frfree(f);
- }
- ast_playtones_stop(chan);
- LOCAL_USER_REMOVE(u);
- return -1;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, disa_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key(void)
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_dumpchan.c b/1.2-netsec/apps/app_dumpchan.c
deleted file mode 100644
index 4802dfee1..000000000
--- a/1.2-netsec/apps/app_dumpchan.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005, Anthony Minessale II.
- *
- * Anthony Minessale <anthmct@yahoo.com>
- *
- * disclaimed to Digium
- *
- * 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 Application to dump channel variables
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-
-static char *tdesc = "Dump Info About The Calling Channel";
-static char *app = "DumpChan";
-static char *synopsis = "Dump Info About The Calling Channel";
-static char *desc =
-" DumpChan([<min_verbose_level>])\n"
-"Displays information on channel and listing of all channel\n"
-"variables. If min_verbose_level is specified, output is only\n"
-"displayed when the verbose level is currently set to that number\n"
-"or greater. \n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int ast_serialize_showchan(struct ast_channel *c, char *buf, size_t size)
-{
- struct timeval now;
- long elapsed_seconds=0;
- int hour=0, min=0, sec=0;
- char cgrp[256];
- char pgrp[256];
-
- now = ast_tvnow();
- memset(buf,0,size);
- if (!c)
- return 0;
-
- if (c->cdr) {
- elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
- hour = elapsed_seconds / 3600;
- min = (elapsed_seconds % 3600) / 60;
- sec = elapsed_seconds % 60;
- }
-
- snprintf(buf,size,
- "Name= %s\n"
- "Type= %s\n"
- "UniqueID= %s\n"
- "CallerID= %s\n"
- "CallerIDName= %s\n"
- "DNIDDigits= %s\n"
- "State= %s (%d)\n"
- "Rings= %d\n"
- "NativeFormat= %d\n"
- "WriteFormat= %d\n"
- "ReadFormat= %d\n"
- "1stFileDescriptor= %d\n"
- "Framesin= %d %s\n"
- "Framesout= %d %s\n"
- "TimetoHangup= %ld\n"
- "ElapsedTime= %dh%dm%ds\n"
- "Context= %s\n"
- "Extension= %s\n"
- "Priority= %d\n"
- "CallGroup= %s\n"
- "PickupGroup= %s\n"
- "Application= %s\n"
- "Data= %s\n"
- "Blocking_in= %s\n",
- c->name,
- c->type,
- c->uniqueid,
- (c->cid.cid_num ? c->cid.cid_num : "(N/A)"),
- (c->cid.cid_name ? c->cid.cid_name : "(N/A)"),
- (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ),
- ast_state2str(c->_state),
- c->_state,
- c->rings,
- c->nativeformats,
- c->writeformat,
- c->readformat,
- c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
- c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
- hour,
- min,
- sec,
- c->context,
- c->exten,
- c->priority,
- ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
- ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
- ( c->appl ? c->appl : "(N/A)" ),
- ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
- (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
-
- return 0;
-}
-
-static int dumpchan_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char vars[1024];
- char info[1024];
- int level = 0;
- static char *line = "================================================================================";
-
- LOCAL_USER_ADD(u);
-
- if (!ast_strlen_zero(data)) {
- level = atoi(data);
- }
-
- pbx_builtin_serialize_variables(chan, vars, sizeof(vars));
- ast_serialize_showchan(chan, info, sizeof(info));
- 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);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, dumpchan_exec, synopsis, desc);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_echo.c b/1.2-netsec/apps/app_echo.c
deleted file mode 100644
index 2b7c20079..000000000
--- a/1.2-netsec/apps/app_echo.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Echo application -- play back what you hear to evaluate latency
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-
-static char *tdesc = "Simple Echo Application";
-
-static char *app = "Echo";
-
-static char *synopsis = "Echo audio read back to the user";
-
-static char *descrip =
-" Echo(): Echo audio read from channel back to the channel. \n"
-"User can exit the application by either pressing the '#' key, \n"
-"or hanging up.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int echo_exec(struct ast_channel *chan, void *data)
-{
- int res=-1;
- struct localuser *u;
- struct ast_frame *f;
- LOCAL_USER_ADD(u);
- ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
- ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
- /* Do our thing here */
- while(ast_waitfor(chan, -1) > -1) {
- f = ast_read(chan);
- if (!f)
- break;
- f->delivery.tv_sec = 0;
- f->delivery.tv_usec = 0;
- if (f->frametype == AST_FRAME_VOICE) {
- if (ast_write(chan, f))
- break;
- } else if (f->frametype == AST_FRAME_VIDEO) {
- if (ast_write(chan, f))
- break;
- } else if (f->frametype == AST_FRAME_DTMF) {
- if (f->subclass == '#') {
- res = 0;
- break;
- } else
- if (ast_write(chan, f))
- break;
- }
- ast_frfree(f);
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, echo_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_enumlookup.c b/1.2-netsec/apps/app_enumlookup.c
deleted file mode 100644
index bd209c47b..000000000
--- a/1.2-netsec/apps/app_enumlookup.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Enumlookup - lookup entry in ENUM
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/enum.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "ENUM Lookup";
-
-static char *app = "EnumLookup";
-
-static char *synopsis = "Lookup number in ENUM";
-
-static char *descrip =
-" EnumLookup(exten[|option]): Looks up an extension via ENUM and sets\n"
-"the variable 'ENUM'. For VoIP URIs this variable will \n"
-"look like 'TECHNOLOGY/URI' with the appropriate technology.\n"
-"Currently, the enumservices SIP, H323, IAX, IAX2 and TEL are recognized. \n"
-"\nReturns status in the ENUMSTATUS channel variable:\n"
-" ERROR Failed to do a lookup\n"
-" <tech> Technology of the successful lookup: SIP, H323, IAX, IAX2 or TEL\n"
-" BADURI Got URI Asterisk does not understand.\n"
-" The option string may contain zero or the following character:\n"
-" 'j' -- jump to +101 priority if the lookup isn't successful.\n"
-" and jump to +51 priority on a TEL entry.\n";
-
-#define ENUM_CONFIG "enum.conf"
-
-static char h323driver[80] = "";
-#define H323DRIVERDEFAULT "H323"
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-/*--- enumlookup_exec: Look up number in ENUM and return result */
-static int enumlookup_exec(struct ast_channel *chan, void *data)
-{
- int res=0,priority_jump=0;
- char tech[80];
- char dest[80];
- char tmp[256];
- char *c,*t = NULL;
- static int dep_warning=0;
- struct localuser *u;
- char *parse;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(d);
- AST_APP_ARG(o);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "EnumLookup requires an argument (extension)\n");
- return -1;
- }
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "The application EnumLookup is deprecated. Please use the ENUMLOOKUP() function instead.\n");
- dep_warning = 1;
- }
-
- LOCAL_USER_ADD(u);
-
- parse = ast_strdupa(data);
- if (!parse) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- tech[0] = '\0';
- dest[0] = '\0';
-
- if (args.o) {
- if (strchr(args.o, 'j'))
- priority_jump = 1;
- }
-
- res = ast_get_enum(chan, args.d, dest, sizeof(dest), tech, sizeof(tech), NULL, NULL);
-
- if (!res) { /* Failed to do a lookup */
- if (priority_jump || option_priority_jumping) {
- /* Look for a "busy" place */
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- }
- pbx_builtin_setvar_helper(chan, "ENUMSTATUS", "ERROR");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- pbx_builtin_setvar_helper(chan, "ENUMSTATUS", tech);
- /* Parse it out */
- if (res > 0) {
- if (!strcasecmp(tech, "SIP")) {
- c = dest;
- if (!strncmp(c, "sip:", 4))
- c += 4;
- snprintf(tmp, sizeof(tmp), "SIP/%s", c);
- pbx_builtin_setvar_helper(chan, "ENUM", tmp);
- } else if (!strcasecmp(tech, "h323")) {
- c = dest;
- if (!strncmp(c, "h323:", 5))
- c += 5;
- snprintf(tmp, sizeof(tmp), "%s/%s", h323driver, c);
-/* do a s!;.*!! on the H323 URI */
- t = strchr(c,';');
- if (t)
- *t = 0;
- pbx_builtin_setvar_helper(chan, "ENUM", tmp);
- } else if (!strcasecmp(tech, "iax")) {
- c = dest;
- if (!strncmp(c, "iax:", 4))
- c += 4;
- snprintf(tmp, sizeof(tmp), "IAX/%s", c);
- pbx_builtin_setvar_helper(chan, "ENUM", tmp);
- } else if (!strcasecmp(tech, "iax2")) {
- c = dest;
- if (!strncmp(c, "iax2:", 5))
- c += 5;
- snprintf(tmp, sizeof(tmp), "IAX2/%s", c);
- pbx_builtin_setvar_helper(chan, "ENUM", tmp);
- } else if (!strcasecmp(tech, "tel")) {
- c = dest;
- if (!strncmp(c, "tel:", 4))
- c += 4;
-
- if (c[0] != '+') {
- ast_log(LOG_NOTICE, "tel: uri must start with a \"+\" (got '%s')\n", c);
- res = 0;
- } else {
-/* now copy over the number, skipping all non-digits and stop at ; or NULL */
- t = tmp;
- while( *c && (*c != ';') && (t - tmp < (sizeof(tmp) - 1))) {
- if (isdigit(*c))
- *t++ = *c;
- c++;
- }
- *t = 0;
- pbx_builtin_setvar_helper(chan, "ENUM", tmp);
- ast_log(LOG_NOTICE, "tel: ENUM set to \"%s\"\n", tmp);
- if (priority_jump || option_priority_jumping) {
- if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 51))
- res = 0;
- }
- }
- } else if (!ast_strlen_zero(tech)) {
- ast_log(LOG_NOTICE, "Don't know how to handle technology '%s'\n", tech);
- pbx_builtin_setvar_helper(chan, "ENUMSTATUS", "BADURI");
- res = 0;
- }
- }
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-/*--- load_config: Load enum.conf and find out how to handle H.323 */
-static int load_config(void)
-{
- struct ast_config *cfg;
- char *s;
-
- cfg = ast_config_load(ENUM_CONFIG);
- if (cfg) {
- if (!(s=ast_variable_retrieve(cfg, "general", "h323driver"))) {
- strncpy(h323driver, H323DRIVERDEFAULT, sizeof(h323driver) - 1);
- } else {
- strncpy(h323driver, s, sizeof(h323driver) - 1);
- }
- ast_config_destroy(cfg);
- return 0;
- }
- ast_log(LOG_NOTICE, "No ENUM Config file, using defaults\n");
- return 0;
-}
-
-
-/*--- unload_module: Unload this application from PBX */
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-/*--- load_module: Load this application into PBX */
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app, enumlookup_exec, synopsis, descrip);
-
- if (!res)
- res = load_config();
-
- return res;
-}
-
-/*--- reload: Reload configuration file */
-int reload(void)
-{
- return load_config();
-}
-
-
-/*--- description: Describe module */
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_eval.c b/1.2-netsec/apps/app_eval.c
deleted file mode 100644
index 13ab0ddbc..000000000
--- a/1.2-netsec/apps/app_eval.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (c) 2004 - 2005, Tilghman Lesher. All rights reserved.
- *
- * Tilghman Lesher <app_eval__v001@the-tilghman.com>
- *
- * This code is released by the author with no restrictions on usage.
- *
- * 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.
- *
- */
-
-/*! \file
- * \brief Eval application
- *
- * \author Tilghman Lesher <app_eval__v001@the-tilghman.com>
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-
-/* Maximum length of any variable */
-#define MAXRESULT 1024
-
-static char *tdesc = "Reevaluates strings";
-
-static char *app_eval = "Eval";
-
-static char *eval_synopsis = "Evaluates a string";
-
-static char *eval_descrip =
-"Usage: Eval(newvar=somestring)\n"
-" Normally Asterisk evaluates variables inline. But what if you want to\n"
-"store variable offsets in a database, to be evaluated later? Eval is\n"
-"the answer, by allowing a string to be evaluated twice in the dialplan,\n"
-"the first time as part of the normal dialplan, and the second using Eval.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int eval_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *s, *newvar=NULL, tmp[MAXRESULT];
- static int dep_warning = 0;
-
- LOCAL_USER_ADD(u);
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "This application has been deprecated in favor of the dialplan function, EVAL\n");
- dep_warning = 1;
- }
-
- /* Check and parse arguments */
- if (data) {
- s = ast_strdupa((char *)data);
- if (s) {
- newvar = strsep(&s, "=");
- if (newvar && (newvar[0] != '\0')) {
- memset(tmp, 0, MAXRESULT);
- pbx_substitute_variables_helper(chan, s, tmp, MAXRESULT - 1);
- pbx_builtin_setvar_helper(chan, newvar, tmp);
- }
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- res = -1;
- }
- }
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app_eval);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app_eval, eval_exec, eval_synopsis, eval_descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_exec.c b/1.2-netsec/apps/app_exec.c
deleted file mode 100644
index 9759455ac..000000000
--- a/1.2-netsec/apps/app_exec.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (c) 2004 - 2005, Tilghman Lesher. All rights reserved.
- *
- * Tilghman Lesher <app_exec__v001@the-tilghman.com>
- *
- * This code is released by the author with no restrictions on usage.
- *
- * 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.
- *
- */
-
-/*! \file
- *
- * \brief Exec application
- *
- * \author Tilghman Lesher <app_exec__v001@the-tilghman.com>
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-
-/* Maximum length of any variable */
-#define MAXRESULT 1024
-
-static char *tdesc = "Executes applications";
-
-static char *app_exec = "Exec";
-
-static char *exec_synopsis = "Executes internal application";
-
-static char *exec_descrip =
-"Usage: Exec(appname(arguments))\n"
-" Allows an arbitrary application to be invoked even when not\n"
-"hardcoded into the dialplan. To invoke external applications\n"
-"see the application System. Returns whatever value the\n"
-"app returns or a non-zero value if the app cannot be found.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int exec_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *s, *appname, *endargs, args[MAXRESULT];
- struct ast_app *app;
-
- LOCAL_USER_ADD(u);
-
- memset(args, 0, MAXRESULT);
-
- /* Check and parse arguments */
- if (data) {
- s = ast_strdupa((char *)data);
- if (s) {
- appname = strsep(&s, "(");
- if (s) {
- endargs = strrchr(s, ')');
- if (endargs)
- *endargs = '\0';
- pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1);
- }
- if (appname) {
- app = pbx_findapp(appname);
- if (app) {
- res = pbx_exec(chan, app, args, 1);
- } else {
- ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
- res = -1;
- }
- }
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- res = -1;
- }
- }
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app_exec);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app_exec, exec_exec, exec_synopsis, exec_descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_externalivr.c b/1.2-netsec/apps/app_externalivr.c
deleted file mode 100644
index a53a59532..000000000
--- a/1.2-netsec/apps/app_externalivr.c
+++ /dev/null
@@ -1,583 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Kevin P. Fleming <kpfleming@digium.com>
- *
- * Portions taken from the file-based music-on-hold work
- * created by Anthony Minessale II in res_musiconhold.c
- *
- * 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 External IVR application interface
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/app.h"
-
-static const char *tdesc = "External IVR Interface Application";
-
-static const char *app = "ExternalIVR";
-
-static const char *synopsis = "Interfaces with an external IVR application";
-
-static const char *descrip =
-" ExternalIVR(command[|arg[|arg...]]): Forks an process to run the supplied command,\n"
-"and starts a generator on the channel. The generator's play list is\n"
-"controlled by the external application, which can add and clear entries\n"
-"via simple commands issued over its stdout. The external application\n"
-"will receive all DTMF events received on the channel, and notification\n"
-"if the channel is hung up. The application will not be forcibly terminated\n"
-"when the channel is hung up.\n"
-"See doc/README.externalivr for a protocol specification.\n";
-
-/* XXX the parser in gcc 2.95 gets confused if you don't put a space between 'name' and the comma */
-#define ast_chan_log(level, channel, format, ...) ast_log(level, "%s: " format, channel->name , ## __VA_ARGS__)
-
-struct playlist_entry {
- AST_LIST_ENTRY(playlist_entry) list;
- char filename[1];
-};
-
-struct localuser {
- struct ast_channel *chan;
- struct localuser *next;
- AST_LIST_HEAD(playlist, playlist_entry) playlist;
- AST_LIST_HEAD(finishlist, playlist_entry) finishlist;
- int abort_current_sound;
- int playing_silence;
- int option_autoclear;
-};
-
-LOCAL_USER_DECL;
-
-struct gen_state {
- struct localuser *u;
- struct ast_filestream *stream;
- struct playlist_entry *current;
- int sample_queue;
-};
-
-static void send_child_event(FILE *handle, const char event, const char *data,
- const struct ast_channel *chan)
-{
- char tmp[256];
-
- if (!data) {
- snprintf(tmp, sizeof(tmp), "%c,%10d", event, (int)time(NULL));
- } else {
- snprintf(tmp, sizeof(tmp), "%c,%10d,%s", event, (int)time(NULL), data);
- }
-
- fprintf(handle, "%s\n", tmp);
- ast_chan_log(LOG_DEBUG, chan, "sent '%s'\n", tmp);
-}
-
-static void *gen_alloc(struct ast_channel *chan, void *params)
-{
- struct localuser *u = params;
- struct gen_state *state;
-
- state = calloc(1, sizeof(*state));
-
- if (!state)
- return NULL;
-
- state->u = u;
-
- return state;
-}
-
-static void gen_closestream(struct gen_state *state)
-{
- if (!state->stream)
- return;
-
- ast_closestream(state->stream);
- state->u->chan->stream = NULL;
- state->stream = NULL;
-}
-
-static void gen_release(struct ast_channel *chan, void *data)
-{
- struct gen_state *state = data;
-
- gen_closestream(state);
- free(data);
-}
-
-/* caller has the playlist locked */
-static int gen_nextfile(struct gen_state *state)
-{
- struct localuser *u = state->u;
- char *file_to_stream;
-
- u->abort_current_sound = 0;
- u->playing_silence = 0;
- gen_closestream(state);
-
- while (!state->stream) {
- state->current = AST_LIST_REMOVE_HEAD(&u->playlist, list);
- if (state->current) {
- file_to_stream = state->current->filename;
- } else {
- file_to_stream = "silence-10";
- u->playing_silence = 1;
- }
-
- if (!(state->stream = ast_openstream_full(u->chan, file_to_stream, u->chan->language, 1))) {
- ast_chan_log(LOG_WARNING, u->chan, "File '%s' could not be opened: %s\n", file_to_stream, strerror(errno));
- if (!u->playing_silence) {
- continue;
- } else {
- break;
- }
- }
- }
-
- return (!state->stream);
-}
-
-static struct ast_frame *gen_readframe(struct gen_state *state)
-{
- struct ast_frame *f = NULL;
- struct localuser *u = state->u;
-
- if (u->abort_current_sound ||
- (u->playing_silence && AST_LIST_FIRST(&u->playlist))) {
- gen_closestream(state);
- AST_LIST_LOCK(&u->playlist);
- gen_nextfile(state);
- AST_LIST_UNLOCK(&u->playlist);
- }
-
- if (!(state->stream && (f = ast_readframe(state->stream)))) {
- if (state->current) {
- AST_LIST_LOCK(&u->finishlist);
- AST_LIST_INSERT_TAIL(&u->finishlist, state->current, list);
- AST_LIST_UNLOCK(&u->finishlist);
- state->current = NULL;
- }
- if (!gen_nextfile(state))
- f = ast_readframe(state->stream);
- }
-
- return f;
-}
-
-static int gen_generate(struct ast_channel *chan, void *data, int len, int samples)
-{
- struct gen_state *state = data;
- struct ast_frame *f = NULL;
- int res = 0;
-
- state->sample_queue += samples;
-
- while (state->sample_queue > 0) {
- if (!(f = gen_readframe(state)))
- return -1;
-
- res = ast_write(chan, f);
- ast_frfree(f);
- if (res < 0) {
- ast_chan_log(LOG_WARNING, chan, "Failed to write frame: %s\n", strerror(errno));
- return -1;
- }
- state->sample_queue -= f->samples;
- }
-
- return res;
-}
-
-static struct ast_generator gen =
-{
- alloc: gen_alloc,
- release: gen_release,
- generate: gen_generate,
-};
-
-static struct playlist_entry *make_entry(const char *filename)
-{
- struct playlist_entry *entry;
-
- entry = calloc(1, sizeof(*entry) + strlen(filename) + 10);
-
- if (!entry)
- return NULL;
-
- strcpy(entry->filename, filename);
-
- return entry;
-}
-
-static int app_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u = NULL;
- struct playlist_entry *entry;
- const char *args = data;
- int child_stdin[2] = { 0,0 };
- int child_stdout[2] = { 0,0 };
- int child_stderr[2] = { 0,0 };
- int res = -1;
- int gen_active = 0;
- int pid;
- char *argv[32];
- int argc = 1;
- char *buf, *command;
- FILE *child_commands = NULL;
- FILE *child_errors = NULL;
- FILE *child_events = NULL;
-
- LOCAL_USER_ADD(u);
-
- AST_LIST_HEAD_INIT(&u->playlist);
- AST_LIST_HEAD_INIT(&u->finishlist);
- u->abort_current_sound = 0;
-
- if (ast_strlen_zero(args)) {
- ast_log(LOG_WARNING, "ExternalIVR requires a command to execute\n");
- goto exit;
- }
-
- buf = ast_strdupa(data);
- if (!buf) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- argc = ast_app_separate_args(buf, '|', argv, sizeof(argv) / sizeof(argv[0]));
-
- if (pipe(child_stdin)) {
- ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child input: %s\n", strerror(errno));
- goto exit;
- }
-
- if (pipe(child_stdout)) {
- ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child output: %s\n", strerror(errno));
- goto exit;
- }
-
- if (pipe(child_stderr)) {
- ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child errors: %s\n", strerror(errno));
- goto exit;
- }
-
- if (chan->_state != AST_STATE_UP) {
- ast_answer(chan);
- }
-
- if (ast_activate_generator(chan, &gen, u) < 0) {
- ast_chan_log(LOG_WARNING, chan, "Failed to activate generator\n");
- goto exit;
- } else
- gen_active = 1;
-
- pid = fork();
- if (pid < 0) {
- ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno));
- goto exit;
- }
-
- if (!pid) {
- /* child process */
- int i;
-
- dup2(child_stdin[0], STDIN_FILENO);
- dup2(child_stdout[1], STDOUT_FILENO);
- dup2(child_stderr[1], STDERR_FILENO);
- for (i = STDERR_FILENO + 1; i < 1024; i++)
- close(i);
- execv(argv[0], argv);
- fprintf(stderr, "Failed to execute '%s': %s\n", argv[0], strerror(errno));
- exit(1);
- } else {
- /* parent process */
- int child_events_fd = child_stdin[1];
- int child_commands_fd = child_stdout[0];
- int child_errors_fd = child_stderr[0];
- struct ast_frame *f;
- int ms;
- int exception;
- int ready_fd;
- int waitfds[2] = { child_errors_fd, child_commands_fd };
- struct ast_channel *rchan;
-
- close(child_stdin[0]);
- child_stdin[0] = 0;
- close(child_stdout[1]);
- child_stdout[1] = 0;
- close(child_stderr[1]);
- child_stderr[1] = 0;
-
- if (!(child_events = fdopen(child_events_fd, "w"))) {
- ast_chan_log(LOG_WARNING, chan, "Could not open stream for child events\n");
- goto exit;
- }
-
- if (!(child_commands = fdopen(child_commands_fd, "r"))) {
- ast_chan_log(LOG_WARNING, chan, "Could not open stream for child commands\n");
- goto exit;
- }
-
- if (!(child_errors = fdopen(child_errors_fd, "r"))) {
- ast_chan_log(LOG_WARNING, chan, "Could not open stream for child errors\n");
- goto exit;
- }
-
- setvbuf(child_events, NULL, _IONBF, 0);
- setvbuf(child_commands, NULL, _IONBF, 0);
- setvbuf(child_errors, NULL, _IONBF, 0);
-
- res = 0;
-
- while (1) {
- if (ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
- ast_chan_log(LOG_NOTICE, chan, "Is a zombie\n");
- res = -1;
- break;
- }
-
- if (ast_check_hangup(chan)) {
- ast_chan_log(LOG_NOTICE, chan, "Got check_hangup\n");
- send_child_event(child_events, 'H', NULL, chan);
- res = -1;
- break;
- }
-
- ready_fd = 0;
- ms = 100;
- errno = 0;
- exception = 0;
-
- rchan = ast_waitfor_nandfds(&chan, 1, waitfds, 2, &exception, &ready_fd, &ms);
-
- if (!AST_LIST_EMPTY(&u->finishlist)) {
- AST_LIST_LOCK(&u->finishlist);
- while ((entry = AST_LIST_REMOVE_HEAD(&u->finishlist, list))) {
- send_child_event(child_events, 'F', entry->filename, chan);
- free(entry);
- }
- AST_LIST_UNLOCK(&u->finishlist);
- }
-
- if (rchan) {
- /* the channel has something */
- f = ast_read(chan);
- if (!f) {
- ast_chan_log(LOG_NOTICE, chan, "Returned no frame\n");
- send_child_event(child_events, 'H', NULL, chan);
- res = -1;
- break;
- }
-
- if (f->frametype == AST_FRAME_DTMF) {
- send_child_event(child_events, f->subclass, NULL, chan);
- if (u->option_autoclear) {
- if (!u->abort_current_sound && !u->playing_silence)
- send_child_event(child_events, 'T', NULL, chan);
- AST_LIST_LOCK(&u->playlist);
- while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) {
- send_child_event(child_events, 'D', entry->filename, chan);
- free(entry);
- }
- if (!u->playing_silence)
- u->abort_current_sound = 1;
- AST_LIST_UNLOCK(&u->playlist);
- }
- } else if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) {
- ast_chan_log(LOG_NOTICE, chan, "Got AST_CONTROL_HANGUP\n");
- send_child_event(child_events, 'H', NULL, chan);
- ast_frfree(f);
- res = -1;
- break;
- }
- ast_frfree(f);
- } else if (ready_fd == child_commands_fd) {
- char input[1024];
-
- if (exception || feof(child_commands)) {
- ast_chan_log(LOG_WARNING, chan, "Child process went away\n");
- res = -1;
- break;
- }
-
- if (!fgets(input, sizeof(input), child_commands))
- continue;
-
- command = ast_strip(input);
-
- ast_chan_log(LOG_DEBUG, chan, "got command '%s'\n", input);
-
- if (strlen(input) < 4)
- continue;
-
- if (input[0] == 'S') {
- if (ast_fileexists(&input[2], NULL, NULL) == -1) {
- ast_chan_log(LOG_WARNING, chan, "Unknown file requested '%s'\n", &input[2]);
- send_child_event(child_events, 'Z', NULL, chan);
- strcpy(&input[2], "exception");
- }
- if (!u->abort_current_sound && !u->playing_silence)
- send_child_event(child_events, 'T', NULL, chan);
- AST_LIST_LOCK(&u->playlist);
- while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) {
- send_child_event(child_events, 'D', entry->filename, chan);
- free(entry);
- }
- if (!u->playing_silence)
- u->abort_current_sound = 1;
- entry = make_entry(&input[2]);
- if (entry)
- AST_LIST_INSERT_TAIL(&u->playlist, entry, list);
- AST_LIST_UNLOCK(&u->playlist);
- } else if (input[0] == 'A') {
- if (ast_fileexists(&input[2], NULL, NULL) == -1) {
- ast_chan_log(LOG_WARNING, chan, "Unknown file requested '%s'\n", &input[2]);
- send_child_event(child_events, 'Z', NULL, chan);
- strcpy(&input[2], "exception");
- }
- entry = make_entry(&input[2]);
- if (entry) {
- AST_LIST_LOCK(&u->playlist);
- AST_LIST_INSERT_TAIL(&u->playlist, entry, list);
- AST_LIST_UNLOCK(&u->playlist);
- }
- } else if (input[0] == 'H') {
- ast_chan_log(LOG_NOTICE, chan, "Hanging up: %s\n", &input[2]);
- send_child_event(child_events, 'H', NULL, chan);
- break;
- } else if (input[0] == 'O') {
- if (!strcasecmp(&input[2], "autoclear"))
- u->option_autoclear = 1;
- else if (!strcasecmp(&input[2], "noautoclear"))
- u->option_autoclear = 0;
- else
- ast_chan_log(LOG_WARNING, chan, "Unknown option requested '%s'\n", &input[2]);
- }
- } else if (ready_fd == child_errors_fd) {
- char input[1024];
-
- if (exception || feof(child_errors)) {
- ast_chan_log(LOG_WARNING, chan, "Child process went away\n");
- res = -1;
- break;
- }
-
- if (fgets(input, sizeof(input), child_errors)) {
- command = ast_strip(input);
- ast_chan_log(LOG_NOTICE, chan, "stderr: %s\n", command);
- }
- } else if ((ready_fd < 0) && ms) {
- if (errno == 0 || errno == EINTR)
- continue;
-
- ast_chan_log(LOG_WARNING, chan, "Wait failed (%s)\n", strerror(errno));
- break;
- }
- }
- }
-
- exit:
- if (gen_active)
- ast_deactivate_generator(chan);
-
- if (child_events)
- fclose(child_events);
-
- if (child_commands)
- fclose(child_commands);
-
- if (child_errors)
- fclose(child_errors);
-
- if (child_stdin[0])
- close(child_stdin[0]);
-
- if (child_stdin[1])
- close(child_stdin[1]);
-
- if (child_stdout[0])
- close(child_stdout[0]);
-
- if (child_stdout[1])
- close(child_stdout[1]);
-
- if (child_stderr[0])
- close(child_stderr[0]);
-
- if (child_stderr[1])
- close(child_stderr[1]);
-
- while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list)))
- free(entry);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, app_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return (char *) tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
-
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_festival.c b/1.2-netsec/apps/app_festival.c
deleted file mode 100644
index d3bd1e9b9..000000000
--- a/1.2-netsec/apps/app_festival.c
+++ /dev/null
@@ -1,532 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2002, Christos Ricudis
- *
- * Christos Ricudis <ricudis@itc.auth.gr>
- *
- * 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 Connect to festival
- *
- * \ingroup applications
- */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdio.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/md5.h"
-#include "asterisk/config.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-
-#define FESTIVAL_CONFIG "festival.conf"
-
-static char *tdesc = "Simple Festival Interface";
-
-static char *app = "Festival";
-
-static char *synopsis = "Say text to the user";
-
-static char *descrip =
-" Festival(text[|intkeys]): Connect to Festival, send the argument, get back the waveform,"
-"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";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static char *socket_receive_file_to_buff(int fd,int *size)
-{
- /* Receive file (probably a waveform file) from socket using */
- /* Festival key stuff technique, but long winded I know, sorry */
- /* but will receive any file without closeing the stream or */
- /* using OOB data */
- static char *file_stuff_key = "ft_StUfF_key"; /* must == Festival's key */
- char *buff;
- int bufflen;
- int n,k,i;
- char c;
-
- bufflen = 1024;
- buff = (char *)malloc(bufflen);
- *size=0;
-
- for (k=0; file_stuff_key[k] != '\0';)
- {
- n = read(fd,&c,1);
- if (n==0) break; /* hit stream eof before end of file */
- if ((*size)+k+1 >= bufflen)
- { /* +1 so you can add a NULL if you want */
- bufflen += bufflen/4;
- buff = (char *)realloc(buff,bufflen);
- }
- if (file_stuff_key[k] == c)
- k++;
- else if ((c == 'X') && (file_stuff_key[k+1] == '\0'))
- { /* It looked like the key but wasn't */
- for (i=0; i < k; i++,(*size)++)
- buff[*size] = file_stuff_key[i];
- k=0;
- /* omit the stuffed 'X' */
- }
- else
- {
- for (i=0; i < k; i++,(*size)++)
- buff[*size] = file_stuff_key[i];
- k=0;
- buff[*size] = c;
- (*size)++;
- }
-
- }
-
- return buff;
-}
-
-static int send_waveform_to_fd(char *waveform, int length, int fd) {
-
- int res;
- int x;
-#ifdef __PPC__
- char c;
-#endif
-
- res = fork();
- if (res < 0)
- ast_log(LOG_WARNING, "Fork failed\n");
- if (res)
- return res;
- for (x=0;x<256;x++) {
- if (x != fd)
- close(x);
- }
-/*IAS */
-#ifdef __PPC__
- for( x=0; x<length; x+=2)
- {
- c = *(waveform+x+1);
- *(waveform+x+1)=*(waveform+x);
- *(waveform+x)=c;
- }
-#endif
-
- write(fd,waveform,length);
- close(fd);
- exit(0);
-}
-
-
-static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, int length, char *intkeys) {
- int res=0;
- int fds[2];
- int ms = -1;
- int pid = -1;
- int needed = 0;
- int owriteformat;
- struct ast_frame *f;
- struct myframe {
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET];
- char frdata[2048];
- } myf;
-
- if (pipe(fds)) {
- ast_log(LOG_WARNING, "Unable to create pipe\n");
- return -1;
- }
-
- /* Answer if it's not already going */
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
- ast_stopstream(chan);
- ast_indicate(chan, -1);
-
- owriteformat = chan->writeformat;
- 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");
- return -1;
- }
-
- res=send_waveform_to_fd(waveform,length,fds[1]);
- if (res >= 0) {
- pid = res;
- /* Order is important -- there's almost always going to be mp3... we want to prioritize the
- user */
- for (;;) {
- ms = 1000;
- res = ast_waitfor(chan, ms);
- if (res < 1) {
- res = -1;
- break;
- }
- f = ast_read(chan);
- if (!f) {
- ast_log(LOG_WARNING, "Null frame == hangup() detected\n");
- res = -1;
- break;
- }
- if (f->frametype == AST_FRAME_DTMF) {
- ast_log(LOG_DEBUG, "User pressed a key\n");
- if (intkeys && strchr(intkeys, f->subclass)) {
- res = f->subclass;
- ast_frfree(f);
- break;
- }
- }
- if (f->frametype == AST_FRAME_VOICE) {
- /* Treat as a generator */
- needed = f->samples * 2;
- if (needed > sizeof(myf.frdata)) {
- ast_log(LOG_WARNING, "Only able to deliver %d of %d requested samples\n",
- (int)sizeof(myf.frdata) / 2, needed/2);
- needed = sizeof(myf.frdata);
- }
- res = read(fds[0], myf.frdata, needed);
- if (res > 0) {
- myf.f.frametype = AST_FRAME_VOICE;
- myf.f.subclass = AST_FORMAT_SLINEAR;
- myf.f.datalen = res;
- myf.f.samples = res / 2;
- myf.f.mallocd = 0;
- myf.f.offset = AST_FRIENDLY_OFFSET;
- myf.f.src = __PRETTY_FUNCTION__;
- myf.f.data = myf.frdata;
- if (ast_write(chan, &myf.f) < 0) {
- res = -1;
- break;
- }
- if (res < needed) { /* last frame */
- ast_log(LOG_DEBUG, "Last frame\n");
- res=0;
- break;
- }
- } else {
- ast_log(LOG_DEBUG, "No more waveform\n");
- res = 0;
- }
- }
- ast_frfree(f);
- }
- }
- close(fds[0]);
- close(fds[1]);
-
-/* if (pid > -1) */
-/* kill(pid, SIGKILL); */
- if (!res && owriteformat)
- ast_set_write_format(chan, owriteformat);
- return res;
-}
-
-#define MAXLEN 180
-#define MAXFESTLEN 2048
-
-
-
-
-static int festival_exec(struct ast_channel *chan, void *vdata)
-{
- int usecache;
- int res=0;
- struct localuser *u;
- struct sockaddr_in serv_addr;
- struct hostent *serverhost;
- struct ast_hostent ahp;
- int fd;
- FILE *fs;
- char *host;
- char *cachedir;
- char *temp;
- char *festivalcommand;
- int port=1314;
- int n;
- char ack[4];
- char *waveform;
- int filesize;
- int wave;
- char bigstring[MAXFESTLEN];
- int i;
- struct MD5Context md5ctx;
- unsigned char MD5Res[16];
- char MD5Hex[33] = "";
- char koko[4] = "";
- char cachefile[MAXFESTLEN]="";
- int readcache=0;
- int writecache=0;
- int strln;
- int fdesc = -1;
- char buffer[16384];
- int seekpos = 0;
- char *data;
- char *intstr;
- struct ast_config *cfg;
-
- if (ast_strlen_zero(vdata)) {
- ast_log(LOG_WARNING, "festival requires an argument (text)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- cfg = ast_config_load(FESTIVAL_CONFIG);
- if (!cfg) {
- ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- if (!(host = ast_variable_retrieve(cfg, "general", "host"))) {
- host = "localhost";
- }
- if (!(temp = ast_variable_retrieve(cfg, "general", "port"))) {
- port = 1314;
- } else {
- port = atoi(temp);
- }
- if (!(temp = ast_variable_retrieve(cfg, "general", "usecache"))) {
- usecache=0;
- } else {
- usecache = ast_true(temp);
- }
- if (!(cachedir = ast_variable_retrieve(cfg, "general", "cachedir"))) {
- cachedir = "/tmp/";
- }
- if (!(festivalcommand = ast_variable_retrieve(cfg, "general", "festivalcommand"))) {
- festivalcommand = "(tts_textasterisk \"%s\" 'file)(quit)\n";
- }
-
- data = ast_strdupa(vdata);
- if (!data) {
- ast_log(LOG_ERROR, "Out of memery\n");
- ast_config_destroy(cfg);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- intstr = strchr(data, '|');
- if (intstr) {
- *intstr = '\0';
- intstr++;
- if (!strcasecmp(intstr, "any"))
- intstr = AST_DIGIT_ANY;
- }
-
- ast_log(LOG_DEBUG, "Text passed to festival server : %s\n",(char *)data);
- /* Connect to local festival server */
-
- fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-
- if (fd < 0) {
- ast_log(LOG_WARNING,"festival_client: can't get socket\n");
- ast_config_destroy(cfg);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- memset(&serv_addr, 0, sizeof(serv_addr));
- if ((serv_addr.sin_addr.s_addr = inet_addr(host)) == -1) {
- /* its a name rather than an ipnum */
- serverhost = ast_gethostbyname(host, &ahp);
- if (serverhost == (struct hostent *)0) {
- ast_log(LOG_WARNING,"festival_client: gethostbyname failed\n");
- ast_config_destroy(cfg);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- memmove(&serv_addr.sin_addr,serverhost->h_addr, serverhost->h_length);
- }
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_port = htons(port);
-
- 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);
- return -1;
- }
-
- /* Compute MD5 sum of string */
- MD5Init(&md5ctx);
- MD5Update(&md5ctx,(unsigned char const *)data,strlen(data));
- MD5Final(MD5Res,&md5ctx);
- MD5Hex[0] = '\0';
-
- /* Convert to HEX and look if there is any matching file in the cache
- directory */
- for (i=0;i<16;i++) {
- snprintf(koko, sizeof(koko), "%X",MD5Res[i]);
- strncat(MD5Hex, koko, sizeof(MD5Hex) - strlen(MD5Hex) - 1);
- }
- readcache=0;
- writecache=0;
- if (strlen(cachedir)+strlen(MD5Hex)+1<=MAXFESTLEN && (usecache==-1)) {
- snprintf(cachefile, sizeof(cachefile), "%s/%s", cachedir, MD5Hex);
- fdesc=open(cachefile,O_RDWR);
- if (fdesc==-1) {
- fdesc=open(cachefile,O_CREAT|O_RDWR,0777);
- if (fdesc!=-1) {
- writecache=1;
- strln=strlen((char *)data);
- ast_log(LOG_DEBUG,"line length : %d\n",strln);
- write(fdesc,&strln,sizeof(int));
- write(fdesc,data,strln);
- seekpos=lseek(fdesc,0,SEEK_CUR);
- ast_log(LOG_DEBUG,"Seek position : %d\n",seekpos);
- }
- } else {
- read(fdesc,&strln,sizeof(int));
- ast_log(LOG_DEBUG,"Cache file exists, strln=%d, strlen=%d\n",strln,(int)strlen((char *)data));
- if (strlen((char *)data)==strln) {
- ast_log(LOG_DEBUG,"Size OK\n");
- read(fdesc,&bigstring,strln);
- bigstring[strln] = 0;
- if (strcmp(bigstring,data)==0) {
- readcache=1;
- } else {
- ast_log(LOG_WARNING,"Strings do not match\n");
- }
- } else {
- ast_log(LOG_WARNING,"Size mismatch\n");
- }
- }
- }
-
- if (readcache==1) {
- close(fd);
- fd=fdesc;
- ast_log(LOG_DEBUG,"Reading from cache...\n");
- } else {
- ast_log(LOG_DEBUG,"Passing text to festival...\n");
- fs=fdopen(dup(fd),"wb");
- fprintf(fs,festivalcommand,(char *)data);
- fflush(fs);
- fclose(fs);
- }
-
- /* Write to cache and then pass it down */
- if (writecache==1) {
- ast_log(LOG_DEBUG,"Writing result to cache...\n");
- while ((strln=read(fd,buffer,16384))!=0) {
- write(fdesc,buffer,strln);
- }
- close(fd);
- close(fdesc);
- fd=open(cachefile,O_RDWR);
- lseek(fd,seekpos,SEEK_SET);
- }
-
- ast_log(LOG_DEBUG,"Passing data to channel...\n");
-
- /* Read back info from server */
- /* This assumes only one waveform will come back, also LP is unlikely */
- wave = 0;
- do {
- int read_data;
- for (n=0; n < 3; )
- {
- read_data = read(fd,ack+n,3-n);
- /* this avoids falling in infinite loop
- * in case that festival server goes down
- * */
- if ( read_data == -1 )
- {
- ast_log(LOG_WARNING,"Unable to read from cache/festival fd");
- return -1;
- }
- n += read_data;
- }
- ack[3] = '\0';
- if (strcmp(ack,"WV\n") == 0) { /* receive a waveform */
- ast_log(LOG_DEBUG,"Festival WV command\n");
- waveform = socket_receive_file_to_buff(fd,&filesize);
- res = send_waveform_to_channel(chan,waveform,filesize, intstr);
- free(waveform);
- break;
- }
- else if (strcmp(ack,"LP\n") == 0) { /* receive an s-expr */
- ast_log(LOG_DEBUG,"Festival LP command\n");
- waveform = socket_receive_file_to_buff(fd,&filesize);
- waveform[filesize]='\0';
- ast_log(LOG_WARNING,"Festival returned LP : %s\n",waveform);
- free(waveform);
- } else if (strcmp(ack,"ER\n") == 0) { /* server got an error */
- ast_log(LOG_WARNING,"Festival returned ER\n");
- res=-1;
- break;
- }
- } while (strcmp(ack,"OK\n") != 0);
- close(fd);
- ast_config_destroy(cfg);
- LOCAL_USER_REMOVE(u);
- return res;
-
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
-
- return ast_register_application(app, festival_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_flash.c b/1.2-netsec/apps/app_flash.c
deleted file mode 100644
index a9aae22b8..000000000
--- a/1.2-netsec/apps/app_flash.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief App to flash a zap trunk
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#ifdef __linux__
-#include <linux/zaptel.h>
-#else
-#include <zaptel.h>
-#endif /* __linux__ */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Flash zap trunk application";
-
-static char *app = "Flash";
-
-static char *synopsis = "Flashes a Zap Trunk";
-
-static char *descrip =
-" Flash(): Sends a flash on a zap trunk. This is only a hack for\n"
-"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";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static inline int zt_wait_event(int fd)
-{
- /* Avoid the silly zt_waitevent which ignores a bunch of events */
- int i,j=0;
- i = ZT_IOMUX_SIGEVENT;
- if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
- if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
- return j;
-}
-
-static int flash_exec(struct ast_channel *chan, void *data)
-{
- int res = -1;
- int x;
- struct localuser *u;
- struct zt_params ztp;
- LOCAL_USER_ADD(u);
- if (!strcasecmp(chan->type, "Zap")) {
- memset(&ztp, 0, sizeof(ztp));
- res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
- if (!res) {
- if (ztp.sigtype & __ZT_SIG_FXS) {
- x = ZT_FLASH;
- res = ioctl(chan->fds[0], ZT_HOOK, &x);
- if (!res || (errno == EINPROGRESS)) {
- if (res) {
- /* Wait for the event to finish */
- zt_wait_event(chan->fds[0]);
- }
- res = ast_safe_sleep(chan, 1000);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
- } else
- ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
- } else
- ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
- } else
- 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);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, flash_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_forkcdr.c b/1.2-netsec/apps/app_forkcdr.c
deleted file mode 100644
index 290c16850..000000000
--- a/1.2-netsec/apps/app_forkcdr.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Anthony Minessale anthmct@yahoo.com
- * Development of this app Sponsered/Funded by TAAN Softworks Corp
- *
- * 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 Fork CDR application
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/cdr.h"
-#include "asterisk/module.h"
-
-static char *tdesc = "Fork The CDR into 2 separate entities.";
-static char *app = "ForkCDR";
-static char *synopsis =
-"Forks the Call Data Record";
-static char *descrip =
-" ForkCDR([options]): Causes the Call Data Record to fork an additional\n"
- "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"
-"";
-
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static void ast_cdr_fork(struct ast_channel *chan)
-{
- struct ast_cdr *cdr;
- struct ast_cdr *newcdr;
- struct ast_flags flags = { AST_CDR_FLAG_KEEP_VARS };
-
- cdr = chan->cdr;
-
- while (cdr->next)
- cdr = cdr->next;
-
- if (!(newcdr = ast_cdr_dup(cdr)))
- return;
-
- ast_cdr_append(cdr, newcdr);
- ast_cdr_reset(newcdr, &flags);
-
- if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS))
- ast_cdr_free_vars(cdr, 0);
-
- ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED);
-}
-
-static int forkcdr_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
-
- if (!chan->cdr) {
- ast_log(LOG_WARNING, "Channel does not have a CDR\n");
- return 0;
- }
-
- LOCAL_USER_ADD(u);
-
- 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);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, forkcdr_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_getcpeid.c b/1.2-netsec/apps/app_getcpeid.c
deleted file mode 100644
index b2d883bc1..000000000
--- a/1.2-netsec/apps/app_getcpeid.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Get ADSI CPE ID
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/adsi.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Get ADSI CPE ID";
-
-static char *app = "GetCPEID";
-
-static char *synopsis = "Get ADSI CPE ID";
-
-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";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
-{
- int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT };
- char *tmp[5];
- int x;
- for (x=0;x<4;x++)
- tmp[x] = stuff[x];
- tmp[4] = NULL;
- return adsi_print(chan, tmp, justify, voice);
-}
-
-static int cpeid_exec(struct ast_channel *chan, void *idata)
-{
- int res=0;
- struct localuser *u;
- unsigned char cpeid[4];
- int gotgeometry = 0;
- int gotcpeid = 0;
- int width, height, buttons;
- char data[4][80];
- char *stuff[4];
-
- LOCAL_USER_ADD(u);
- stuff[0] = data[0];
- stuff[1] = data[1];
- stuff[2] = data[2];
- stuff[3] = data[3];
- memset(data, 0, sizeof(data));
- strncpy(stuff[0], "** CPE Info **", sizeof(data[0]) - 1);
- strncpy(stuff[1], "Identifying CPE...", sizeof(data[1]) - 1);
- strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1);
- res = adsi_load_session(chan, NULL, 0, 1);
- if (res > 0) {
- cpeid_setstatus(chan, stuff, 0);
- res = adsi_get_cpeid(chan, cpeid, 0);
- if (res > 0) {
- gotcpeid = 1;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n", cpeid[0], cpeid[1], cpeid[2], cpeid[3], chan->name);
- }
- if (res > -1) {
- strncpy(stuff[1], "Measuring CPE...", sizeof(data[1]) - 1);
- strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1);
- cpeid_setstatus(chan, stuff, 0);
- res = adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
- if (res > -1) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name);
- gotgeometry = 1;
- }
- }
- if (res > -1) {
- if (gotcpeid)
- snprintf(stuff[1], sizeof(data[1]), "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
- else
- strncpy(stuff[1], "CPEID Unknown", sizeof(data[1]) - 1);
- if (gotgeometry)
- snprintf(stuff[2], sizeof(data[2]), "Geom: %dx%d, %d buttons", width, height, buttons);
- else
- strncpy(stuff[2], "Geometry unknown", sizeof(data[2]) - 1);
- strncpy(stuff[3], "Press # to exit", sizeof(data[3]) - 1);
- cpeid_setstatus(chan, stuff, 1);
- for(;;) {
- res = ast_waitfordigit(chan, 1000);
- if (res < 0)
- break;
- if (res == '#') {
- res = 0;
- break;
- }
- }
- adsi_unload_session(chan);
- }
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, cpeid_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_groupcount.c b/1.2-netsec/apps/app_groupcount.c
deleted file mode 100644
index aa848c2d5..000000000
--- a/1.2-netsec/apps/app_groupcount.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Group Manipulation Applications
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <regex.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/utils.h"
-#include "asterisk/cli.h"
-#include "asterisk/app.h"
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int group_count_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- int count;
- struct localuser *u;
- char group[80] = "";
- char category[80] = "";
- char ret[80] = "";
- char *grp;
- static int deprecation_warning = 0;
-
- LOCAL_USER_ADD(u);
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "The GetGroupCount application has been deprecated, please use the GROUP_COUNT function.\n");
- deprecation_warning = 1;
- }
-
- ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
-
- if (ast_strlen_zero(group)) {
- grp = pbx_builtin_getvar_helper(chan, category);
- strncpy(group, grp, sizeof(group) - 1);
- }
-
- count = ast_app_group_get_count(group, category);
- snprintf(ret, sizeof(ret), "%d", count);
- pbx_builtin_setvar_helper(chan, "GROUPCOUNT", ret);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-static int group_match_count_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- int count;
- struct localuser *u;
- char group[80] = "";
- char category[80] = "";
- char ret[80] = "";
- static int deprecation_warning = 0;
-
- LOCAL_USER_ADD(u);
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "The GetGroupMatchCount application has been deprecated, please use the GROUP_MATCH_COUNT function.\n");
- deprecation_warning = 1;
- }
-
- ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
-
- if (!ast_strlen_zero(group)) {
- count = ast_app_group_match_get_count(group, category);
- snprintf(ret, sizeof(ret), "%d", count);
- pbx_builtin_setvar_helper(chan, "GROUPCOUNT", ret);
- }
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-static int group_set_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- static int deprecation_warning = 0;
-
- LOCAL_USER_ADD(u);
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "The SetGroup application has been deprecated, please use the GROUP() function.\n");
- deprecation_warning = 1;
- }
-
- if (ast_app_group_set_channel(chan, data))
- ast_log(LOG_WARNING, "SetGroup requires an argument (group name)\n");
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int group_check_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- int max, count;
- struct localuser *u;
- char limit[80]="";
- char category[80]="";
- static int deprecation_warning = 0;
- char *parse;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(max);
- AST_APP_ARG(options);
- );
-
- LOCAL_USER_ADD(u);
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "The CheckGroup application has been deprecated, please use a combination of the GotoIf application and the GROUP_COUNT() function.\n");
- deprecation_warning = 1;
- }
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- if (ast_strlen_zero(args.max)) {
- ast_log(LOG_WARNING, "CheckGroup requires an argument(max[@category][|options])\n");
- return res;
- }
-
- ast_app_group_split_group(args.max, limit, sizeof(limit), category, sizeof(category));
-
- if ((sscanf(limit, "%d", &max) == 1) && (max > -1)) {
- count = ast_app_group_get_count(pbx_builtin_getvar_helper(chan, category), category);
- if (count > max) {
- pbx_builtin_setvar_helper(chan, "CHECKGROUPSTATUS", "OVERMAX");
- if (priority_jump || option_priority_jumping) {
- if (!ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
- res = -1;
- }
- } else
- pbx_builtin_setvar_helper(chan, "CHECKGROUPSTATUS", "OK");
- } else
- ast_log(LOG_WARNING, "CheckGroup requires a positive integer argument (max)\n");
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int group_show_channels(int fd, int argc, char *argv[])
-{
-#define FORMAT_STRING "%-25s %-20s %-20s\n"
-
- struct ast_channel *c = NULL;
- int numchans = 0;
- struct ast_var_t *current;
- struct varshead *headp;
- regex_t regexbuf;
- int havepattern = 0;
-
- if (argc < 3 || argc > 4)
- return RESULT_SHOWUSAGE;
-
- if (argc == 4) {
- if (regcomp(&regexbuf, argv[3], REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
- havepattern = 1;
- }
-
- ast_cli(fd, FORMAT_STRING, "Channel", "Group", "Category");
- while ( (c = ast_channel_walk_locked(c)) != NULL) {
- headp=&c->varshead;
- AST_LIST_TRAVERSE(headp,current,entries) {
- if (!strncmp(ast_var_name(current), GROUP_CATEGORY_PREFIX "_", strlen(GROUP_CATEGORY_PREFIX) + 1)) {
- if (!havepattern || !regexec(&regexbuf, ast_var_value(current), 0, NULL, 0)) {
- ast_cli(fd, FORMAT_STRING, c->name, ast_var_value(current),
- (ast_var_name(current) + strlen(GROUP_CATEGORY_PREFIX) + 1));
- numchans++;
- }
- } else if (!strcmp(ast_var_name(current), GROUP_CATEGORY_PREFIX)) {
- if (!havepattern || !regexec(&regexbuf, ast_var_value(current), 0, NULL, 0)) {
- ast_cli(fd, FORMAT_STRING, c->name, ast_var_value(current), "(default)");
- numchans++;
- }
- }
- }
- numchans++;
- ast_mutex_unlock(&c->lock);
- }
-
- if (havepattern)
- regfree(&regexbuf);
-
- ast_cli(fd, "%d active channel%s\n", numchans, (numchans != 1) ? "s" : "");
- return RESULT_SUCCESS;
-#undef FORMAT_STRING
-}
-
-static char *tdesc = "Group Management Routines";
-
-static char *app_group_count = "GetGroupCount";
-static char *app_group_set = "SetGroup";
-static char *app_group_check = "CheckGroup";
-static char *app_group_match_count = "GetGroupMatchCount";
-
-static char *group_count_synopsis = "Get the channel count of a group";
-static char *group_set_synopsis = "Set the channel's group";
-static char *group_check_synopsis = "Check the channel count of a group against a limit";
-static char *group_match_count_synopsis = "Get the channel count of all groups that match a pattern";
-
-static char *group_count_descrip =
-"Usage: GetGroupCount([groupname][@category])\n"
-" Calculates the group count for the specified group, or uses\n"
-"the current channel's group if not specifed (and non-empty).\n"
-"Stores result in GROUPCOUNT. \n"
-"This application has been deprecated, please use the function\n"
-"GroupCount.\n";
-
-static char *group_set_descrip =
-"Usage: SetGroup(groupname[@category])\n"
-" Sets the channel group to the specified value. Equivalent to\n"
-"Set(GROUP=group). Always returns 0.\n";
-
-static char *group_check_descrip =
-"Usage: CheckGroup(max[@category][|options])\n"
-" Checks that the current number of total channels in the\n"
-"current channel's group does not exceed 'max'. If the number\n"
-"does not exceed 'max', we continue to the next step. \n"
-" The option string may contain zero of the following character:\n"
-" 'j' -- jump to n+101 priority if the number does in fact exceed max,\n"
-" and priority n+101 exists. Execuation then continues at that\n"
-" step, otherwise -1 is returned.\n"
-" This application sets the following channel variable upon successful completion:\n"
-" CHECKGROUPSTATUS The status of the check that the current channel's\n"
-" group does not exceed 'max'. It's value is one of\n"
-" OK | OVERMAX \n";
-
-static char *group_match_count_descrip =
-"Usage: GetGroupMatchCount(groupmatch[@category])\n"
-" Calculates the group count for all groups that match the specified\n"
-"pattern. Uses standard regular expression matching (see regex(7)).\n"
-"Stores result in GROUPCOUNT. Always returns 0.\n"
-"This application has been deprecated, please use the function\n"
-"GroupMatchCount.\n";
-
-static char show_channels_usage[] =
-"Usage: group show channels [pattern]\n"
-" Lists all currently active channels with channel group(s) specified.\n Optional regular expression pattern is matched to group names for each channel.\n";
-
-static struct ast_cli_entry cli_show_channels =
- { { "group", "show", "channels", NULL }, group_show_channels, "Show active channels with group(s)", show_channels_usage};
-
-int unload_module(void)
-{
- int res;
-
- res = ast_cli_unregister(&cli_show_channels);
- res |= ast_unregister_application(app_group_count);
- res |= ast_unregister_application(app_group_set);
- res |= ast_unregister_application(app_group_check);
- res |= ast_unregister_application(app_group_match_count);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app_group_count, group_count_exec, group_count_synopsis, group_count_descrip);
- res |= ast_register_application(app_group_set, group_set_exec, group_set_synopsis, group_set_descrip);
- res |= ast_register_application(app_group_check, group_check_exec, group_check_synopsis, group_check_descrip);
- res |= ast_register_application(app_group_match_count, group_match_count_exec, group_match_count_synopsis, group_match_count_descrip);
- res |= ast_cli_register(&cli_show_channels);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_hasnewvoicemail.c b/1.2-netsec/apps/app_hasnewvoicemail.c
deleted file mode 100644
index d5e7664f6..000000000
--- a/1.2-netsec/apps/app_hasnewvoicemail.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Changes Copyright (c) 2004 - 2005 Todd Freeman <freeman@andrews.edu>
- *
- * 95% based on HasNewVoicemail by:
- *
- * Copyright (c) 2003 Tilghman Lesher. All rights reserved.
- *
- * Tilghman Lesher <asterisk-hasnewvoicemail-app@the-tilghman.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief HasVoicemail application
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Indicator for whether a voice mailbox has messages in a given folder.";
-static char *app_hasvoicemail = "HasVoicemail";
-static char *hasvoicemail_synopsis = "Conditionally branches to priority + 101 with the right options set";
-static char *hasvoicemail_descrip =
-"HasVoicemail(vmbox[/folder][@context][|varname[|options]])\n"
-" Optionally sets <varname> to the number of messages in that folder."
-" Assumes folder of INBOX if not specified.\n"
-" The option string may contain zero or the following character:\n"
-" 'j' -- jump to priority n+101, if there is voicemail in the folder indicated.\n"
-" This application sets the following channel variable upon completion:\n"
-" HASVMSTATUS The result of the voicemail check returned as a text string as follows\n"
-" <# of messages in the folder, 0 for NONE>\n";
-
-static char *app_hasnewvoicemail = "HasNewVoicemail";
-static char *hasnewvoicemail_synopsis = "Conditionally branches to priority + 101 with the right options set";
-static char *hasnewvoicemail_descrip =
-"HasNewVoicemail(vmbox[/folder][@context][|varname[|options]])\n"
-"Assumes folder 'INBOX' if folder is not specified. Optionally sets <varname> to the number of messages\n"
-"in that folder.\n"
-" The option string may contain zero of the following character:\n"
-" 'j' -- jump to priority n+101, if there is new voicemail in folder 'folder' or INBOX\n"
-" This application sets the following channel variable upon completion:\n"
-" 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";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int hasvoicemail_internal(char *context, char *box, char *folder)
-{
- char vmpath[256];
- DIR *vmdir;
- struct dirent *vment;
- int count=0;
-
- snprintf(vmpath,sizeof(vmpath), "%s/voicemail/%s/%s/%s", (char *)ast_config_AST_SPOOL_DIR, context, box, folder);
- if ((vmdir = opendir(vmpath))) {
- /* No matter what the format of VM, there will always be a .txt file for each message. */
- while ((vment = readdir(vmdir))) {
- if (!strncmp(vment->d_name + 7, ".txt", 4)) {
- count++;
- }
- }
- closedir(vmdir);
- }
- return count;
-}
-
-static int hasvoicemail_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- char *input, *varname = NULL, *vmbox, *context = "default";
- char *vmfolder;
- int vmcount = 0;
- static int dep_warning = 0;
- int priority_jump = 0;
- char tmp[12];
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(vmbox);
- AST_APP_ARG(varname);
- AST_APP_ARG(options);
- );
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "The applications HasVoicemail and HasNewVoicemail have been deprecated. Please use the VMCOUNT() function instead.\n");
- dep_warning = 1;
- }
-
- if (!data) {
- ast_log(LOG_WARNING, "HasVoicemail requires an argument (vm-box[/folder][@context][|varname[|options]])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- input = ast_strdupa((char *)data);
- if (! input) {
- ast_log(LOG_ERROR, "Out of memory error\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, input);
-
- if ((vmbox = strsep(&args.vmbox, "@")))
- if (!ast_strlen_zero(args.vmbox))
- context = args.vmbox;
- if (!vmbox)
- vmbox = args.vmbox;
-
- vmfolder = strchr(vmbox, '/');
- if (vmfolder) {
- *vmfolder = '\0';
- vmfolder++;
- } else {
- vmfolder = "INBOX";
- }
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- vmcount = hasvoicemail_internal(context, vmbox, vmfolder);
- /* Set the count in the channel variable */
- if (varname) {
- snprintf(tmp, sizeof(tmp), "%d", vmcount);
- pbx_builtin_setvar_helper(chan, varname, tmp);
- }
-
- if (vmcount > 0) {
- /* Branch to the next extension */
- if (priority_jump || option_priority_jumping) {
- if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
- ast_log(LOG_WARNING, "VM box %s@%s has new voicemail, but extension %s, priority %d doesn't exist\n", vmbox, context, chan->exten, chan->priority + 101);
- }
- }
-
- snprintf(tmp, sizeof(tmp), "%d", vmcount);
- pbx_builtin_setvar_helper(chan, "HASVMSTATUS", tmp);
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-static char *acf_vmcount_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- struct localuser *u;
- char *args, *context, *box, *folder;
-
- LOCAL_USER_ACF_ADD(u);
-
- buf[0] = '\0';
-
- args = ast_strdupa(data);
- if (!args) {
- ast_log(LOG_ERROR, "Out of memory");
- LOCAL_USER_REMOVE(u);
- return buf;
- }
-
- box = strsep(&args, "|");
- if (strchr(box, '@')) {
- context = box;
- box = strsep(&context, "@");
- } else {
- context = "default";
- }
-
- if (args) {
- folder = args;
- } else {
- folder = "INBOX";
- }
-
- snprintf(buf, len, "%d", hasvoicemail_internal(context, box, folder));
-
- LOCAL_USER_REMOVE(u);
-
- return buf;
-}
-
-struct ast_custom_function acf_vmcount = {
- .name = "VMCOUNT",
- .synopsis = "Counts the voicemail in a specified mailbox",
- .syntax = "VMCOUNT(vmbox[@context][|folder])",
- .desc =
- " context - defaults to \"default\"\n"
- " folder - defaults to \"INBOX\"\n",
- .read = acf_vmcount_exec,
-};
-
-int unload_module(void)
-{
- int res;
-
- res = ast_custom_function_unregister(&acf_vmcount);
- res |= ast_unregister_application(app_hasvoicemail);
- res |= ast_unregister_application(app_hasnewvoicemail);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_custom_function_register(&acf_vmcount);
- res |= ast_register_application(app_hasvoicemail, hasvoicemail_exec, hasvoicemail_synopsis, hasvoicemail_descrip);
- res |= ast_register_application(app_hasnewvoicemail, hasvoicemail_exec, hasnewvoicemail_synopsis, hasnewvoicemail_descrip);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_ices.c b/1.2-netsec/apps/app_ices.c
deleted file mode 100644
index 4c1505584..000000000
--- a/1.2-netsec/apps/app_ices.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Stream to an icecast server via ICES (see contrib/asterisk-ices.xml)
- *
- * \ingroup applications
- */
-
-#include <string.h>
-#include <stdio.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/frame.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-
-#define ICES "/usr/bin/ices"
-#define LOCAL_ICES "/usr/local/bin/ices"
-
-static char *tdesc = "Encode and Stream via icecast and ices";
-
-static char *app = "ICES";
-
-static char *synopsis = "Encode and stream using 'ices'";
-
-static char *descrip =
-" ICES(config.xml) Streams to an icecast server using ices\n"
-"(available separately). A configuration file must be supplied\n"
-"for ices (see examples/asterisk-ices.conf). \n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int icesencode(char *filename, int fd)
-{
- int res;
- int x;
- res = fork();
- if (res < 0)
- ast_log(LOG_WARNING, "Fork failed\n");
- if (res)
- return res;
- dup2(fd, STDIN_FILENO);
- for (x=STDERR_FILENO + 1;x<256;x++) {
- if ((x != STDIN_FILENO) && (x != STDOUT_FILENO))
- close(x);
- }
- /* Most commonly installed in /usr/local/bin */
- execl(ICES, "ices", filename, (char *)NULL);
- /* But many places has it in /usr/bin */
- execl(LOCAL_ICES, "ices", filename, (char *)NULL);
- /* As a last-ditch effort, try to use PATH */
- execlp("ices", "ices", filename, (char *)NULL);
- ast_log(LOG_WARNING, "Execute of ices failed\n");
- return -1;
-}
-
-static int ices_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- int fds[2];
- int ms = -1;
- int pid = -1;
- int flags;
- int oreadformat;
- struct timeval last;
- struct ast_frame *f;
- char filename[256]="";
- char *c;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "ICES requires an argument (configfile.xml)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- last = ast_tv(0, 0);
-
- if (pipe(fds)) {
- ast_log(LOG_WARNING, "Unable to create pipe\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- flags = fcntl(fds[1], F_GETFL);
- fcntl(fds[1], F_SETFL, flags | O_NONBLOCK);
-
- ast_stopstream(chan);
-
- if (chan->_state != AST_STATE_UP)
- res = ast_answer(chan);
-
- if (res) {
- close(fds[0]);
- close(fds[1]);
- ast_log(LOG_WARNING, "Answer failed!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- oreadformat = chan->readformat;
- res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
- if (res < 0) {
- close(fds[0]);
- close(fds[1]);
- ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- if (((char *)data)[0] == '/')
- strncpy(filename, (char *)data, sizeof(filename) - 1);
- else
- snprintf(filename, sizeof(filename), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, (char *)data);
- /* Placeholder for options */
- c = strchr(filename, '|');
- if (c)
- *c = '\0';
- res = icesencode(filename, fds[0]);
- close(fds[0]);
- if (res >= 0) {
- pid = res;
- for (;;) {
- /* Wait for audio, and stream */
- ms = ast_waitfor(chan, -1);
- if (ms < 0) {
- ast_log(LOG_DEBUG, "Hangup detected\n");
- res = -1;
- break;
- }
- f = ast_read(chan);
- if (!f) {
- ast_log(LOG_DEBUG, "Null frame == hangup() detected\n");
- res = -1;
- break;
- }
- if (f->frametype == AST_FRAME_VOICE) {
- res = write(fds[1], f->data, f->datalen);
- if (res < 0) {
- if (errno != EAGAIN) {
- ast_log(LOG_WARNING, "Write failed to pipe: %s\n", strerror(errno));
- res = -1;
- break;
- }
- }
- }
- ast_frfree(f);
- }
- }
- close(fds[1]);
-
- if (pid > -1)
- kill(pid, SIGKILL);
- if (!res && oreadformat)
- ast_set_read_format(chan, oreadformat);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, ices_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_image.c b/1.2-netsec/apps/app_image.c
deleted file mode 100644
index e23b274a9..000000000
--- a/1.2-netsec/apps/app_image.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief App to transmit an image
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#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";
-
-static char *descrip =
-" SendImage(filename): Sends an image on a channel. \n"
-"If the channel supports image transport but the image send\n"
-"fails, the channel will be hung up. Otherwise, the dialplan\n"
-"continues execution.\n"
-"The option string may contain the following character:\n"
-" 'j' -- jump to priority n+101 if the channel doesn't support image transport\n"
-"This application sets the following channel variable upon completion:\n"
-" SENDIMAGESTATUS The status is the result of the attempt as a text string, one of\n"
-" OK | NOSUPPORT \n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int sendimage_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- char *parse;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(filename);
- AST_APP_ARG(options);
- );
-
- LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (ast_strlen_zero(args.filename)) {
- ast_log(LOG_WARNING, "SendImage requires an argument (filename[|options])\n");
- return -1;
- }
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- if (!ast_supports_images(chan)) {
- /* Does not support transport */
- if (priority_jump || option_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);
- return 0;
- }
-
- res = ast_send_image(chan, args.filename);
-
- if (!res)
- pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK");
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, sendimage_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_intercom.c b/1.2-netsec/apps/app_intercom.c
deleted file mode 100644
index 1ae78c6ab..000000000
--- a/1.2-netsec/apps/app_intercom.c
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Use /dev/dsp as an intercom.
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-
-#if defined(__linux__)
-#include <linux/soundcard.h>
-#elif defined(__FreeBSD__)
-#include <sys/soundcard.h>
-#else
-#include <soundcard.h>
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-
-#ifdef __OpenBSD__
-#define DEV_DSP "/dev/audio"
-#else
-#define DEV_DSP "/dev/dsp"
-#endif
-
-/* Number of 32 byte buffers -- each buffer is 2 ms */
-#define BUFFER_SIZE 32
-
-static char *tdesc = "Intercom using /dev/dsp for output";
-
-static char *app = "Intercom";
-
-static char *synopsis = "(Obsolete) Send to Intercom";
-static char *descrip =
-" Intercom(): Sends the user to the intercom (i.e. /dev/dsp). This program\n"
-"is generally considered obselete by the chan_oss module. User can terminate\n"with a DTMF tone, or by hangup.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-AST_MUTEX_DEFINE_STATIC(sound_lock);
-static int sound = -1;
-
-static int write_audio(short *data, int len)
-{
- int res;
- struct audio_buf_info info;
- ast_mutex_lock(&sound_lock);
- if (sound < 0) {
- ast_log(LOG_WARNING, "Sound device closed?\n");
- ast_mutex_unlock(&sound_lock);
- return -1;
- }
- if (ioctl(sound, SNDCTL_DSP_GETOSPACE, &info)) {
- ast_log(LOG_WARNING, "Unable to read output space\n");
- ast_mutex_unlock(&sound_lock);
- return -1;
- }
- res = write(sound, data, len);
- ast_mutex_unlock(&sound_lock);
- return res;
-}
-
-static int create_audio(void)
-{
- int fmt, desired, res, fd;
- fd = open(DEV_DSP, O_WRONLY);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to open %s: %s\n", DEV_DSP, strerror(errno));
- close(fd);
- return -1;
- }
- fmt = AFMT_S16_LE;
- res = ioctl(fd, SNDCTL_DSP_SETFMT, &fmt);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set format to 16-bit signed\n");
- close(fd);
- return -1;
- }
- fmt = 0;
- res = ioctl(fd, SNDCTL_DSP_STEREO, &fmt);
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
- close(fd);
- return -1;
- }
- /* 8000 Hz desired */
- desired = 8000;
- fmt = desired;
- res = ioctl(fd, SNDCTL_DSP_SPEED, &fmt);
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
- close(fd);
- return -1;
- }
- if (fmt != desired) {
- ast_log(LOG_WARNING, "Requested %d Hz, got %d Hz -- sound may be choppy\n", desired, fmt);
- }
-#if 1
- /* 2 bytes * 15 units of 2^5 = 32 bytes per buffer */
- fmt = ((BUFFER_SIZE) << 16) | (0x0005);
- res = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fmt);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set fragment size -- sound may be choppy\n");
- }
-#endif
- sound = fd;
- return 0;
-}
-
-static int intercom_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- struct ast_frame *f;
- int oreadformat;
- LOCAL_USER_ADD(u);
- /* Remember original read format */
- oreadformat = chan->readformat;
- /* Set mode to signed linear */
- res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set format to signed linear on channel %s\n", chan->name);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- /* Read packets from the channel */
- while(!res) {
- res = ast_waitfor(chan, -1);
- if (res > 0) {
- res = 0;
- f = ast_read(chan);
- if (f) {
- if (f->frametype == AST_FRAME_DTMF) {
- ast_frfree(f);
- break;
- } else {
- if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass == AST_FORMAT_SLINEAR) {
- res = write_audio(f->data, f->datalen);
- if (res > 0)
- res = 0;
- } else
- ast_log(LOG_DEBUG, "Unable to handle non-signed linear frame (%d)\n", f->subclass);
- }
- }
- ast_frfree(f);
- } else
- res = -1;
- }
- }
-
- if (!res)
- ast_set_read_format(chan, oreadformat);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- if (sound > -1)
- close(sound);
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- if (create_audio())
- return -1;
- return ast_register_application(app, intercom_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_ivrdemo.c b/1.2-netsec/apps/app_ivrdemo.c
deleted file mode 100644
index 198cfda2a..000000000
--- a/1.2-netsec/apps/app_ivrdemo.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief IVR Demo application
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/app.h"
-
-static char *tdesc = "IVR Demo Application";
-static char *app = "IVRDemo";
-static char *synopsis =
-" This is a skeleton application that shows you the basic structure to create your\n"
-"own asterisk applications and demonstrates the IVR demo.\n";
-
-static int ivr_demo_func(struct ast_channel *chan, void *data)
-{
- ast_verbose("IVR Demo, data is %s!\n", (char *)data);
- return 0;
-}
-
-AST_IVR_DECLARE_MENU(ivr_submenu, "IVR Demo Sub Menu", 0,
-{
- { "s", AST_ACTION_BACKGROUND, "demo-abouttotry" },
- { "s", AST_ACTION_WAITOPTION },
- { "1", AST_ACTION_PLAYBACK, "digits/1" },
- { "1", AST_ACTION_PLAYBACK, "digits/1" },
- { "1", AST_ACTION_RESTART },
- { "2", AST_ACTION_PLAYLIST, "digits/2;digits/3" },
- { "3", AST_ACTION_CALLBACK, ivr_demo_func },
- { "4", AST_ACTION_TRANSFER, "demo|s|1" },
- { "*", AST_ACTION_REPEAT },
- { "#", AST_ACTION_UPONE },
- { NULL }
-});
-
-AST_IVR_DECLARE_MENU(ivr_demo, "IVR Demo Main Menu", 0,
-{
- { "s", AST_ACTION_BACKGROUND, "demo-congrats" },
- { "g", AST_ACTION_BACKGROUND, "demo-instruct" },
- { "g", AST_ACTION_WAITOPTION },
- { "1", AST_ACTION_PLAYBACK, "digits/1" },
- { "1", AST_ACTION_RESTART },
- { "2", AST_ACTION_MENU, &ivr_submenu },
- { "2", AST_ACTION_RESTART },
- { "i", AST_ACTION_PLAYBACK, "invalid" },
- { "i", AST_ACTION_REPEAT, (void *)(unsigned long)2 },
- { "#", AST_ACTION_EXIT },
- { NULL },
-});
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int skel_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- /* Do our thing here */
-
- if (chan->_state != AST_STATE_UP)
- res = ast_answer(chan);
- if (!res)
- res = ast_ivr_menu_run(chan, &ivr_demo, data);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, skel_exec, tdesc, synopsis);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_lookupblacklist.c b/1.2-netsec/apps/app_lookupblacklist.c
deleted file mode 100644
index 1f7e30fd8..000000000
--- a/1.2-netsec/apps/app_lookupblacklist.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief App to lookup the callerid number, and see if it is blacklisted
- *
- * \ingroup applications
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#include "asterisk/callerid.h"
-#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";
-
-static char *descrip =
- " LookupBlacklist(options): Looks up the Caller*ID number on the active\n"
- "channel in the Asterisk database (family 'blacklist'). \n"
- "The option string may contain the following character:\n"
- " 'j' -- jump to n+101 priority if the number/name is found in the blacklist\n"
- "This application sets the following channel variable upon completion:\n"
- " LOOKUPBLSTATUS The status of the Blacklist lookup as a text string, one of\n"
- " FOUND | NOTFOUND\n"
- "Example: exten => 1234,1,LookupBlacklist()\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int
-lookupblacklist_exec (struct ast_channel *chan, void *data)
-{
- char blacklist[1];
- struct localuser *u;
- int bl = 0;
- int priority_jump = 0;
-
- LOCAL_USER_ADD(u);
-
- if (!ast_strlen_zero(data)) {
- if (strchr(data, 'j'))
- priority_jump = 1;
- }
-
- if (chan->cid.cid_num) {
- if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist))) {
- if (option_verbose > 2)
- ast_log(LOG_NOTICE, "Blacklisted number %s found\n",chan->cid.cid_num);
- bl = 1;
- }
- }
- if (chan->cid.cid_name) {
- if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist))) {
- if (option_verbose > 2)
- ast_log (LOG_NOTICE,"Blacklisted name \"%s\" found\n",chan->cid.cid_name);
- bl = 1;
- }
- }
-
- if (bl) {
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "FOUND");
- } else
- pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "NOTFOUND");
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-int unload_module (void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module (void)
-{
- return ast_register_application (app, lookupblacklist_exec, synopsis,descrip);
-}
-
-char *description (void)
-{
- return tdesc;
-}
-
-int usecount (void)
-{
- int res;
- STANDARD_USECOUNT (res);
- return res;
-}
-
-char *key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_lookupcidname.c b/1.2-netsec/apps/app_lookupcidname.c
deleted file mode 100644
index 52587b03a..000000000
--- a/1.2-netsec/apps/app_lookupcidname.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief App to set callerid name from database, based on directory number
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#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";
-
-static char *descrip =
- " LookupCIDName: Looks up the Caller*ID number on the active\n"
- "channel in the Asterisk database (family 'cidname') and sets the\n"
- "Caller*ID name. Does nothing if no Caller*ID was received on the\n"
- "channel. This is useful if you do not subscribe to Caller*ID\n"
- "name delivery, or if you want to change the names on some incoming\n"
- "calls.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int
-lookupcidname_exec (struct ast_channel *chan, void *data)
-{
- char dbname[64];
- struct localuser *u;
-
- LOCAL_USER_ADD (u);
- 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;
-}
-
-int
-unload_module (void)
-{
- int res;
-
- res = ast_unregister_application (app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int
-load_module (void)
-{
- return ast_register_application (app, lookupcidname_exec, synopsis,
- descrip);
-}
-
-char *
-description (void)
-{
- return tdesc;
-}
-
-int
-usecount (void)
-{
- int res;
- STANDARD_USECOUNT (res);
- return res;
-}
-
-char *
-key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_macro.c b/1.2-netsec/apps/app_macro.c
deleted file mode 100644
index 7e7c9141a..000000000
--- a/1.2-netsec/apps/app_macro.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Dial plan macro Implementation
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/config.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-
-#define MAX_ARGS 80
-
-/* 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-<macroname>', jumping to the 's' extension of that context and\n"
-"executing each step, then returning when the steps end. \n"
-"The calling extension, context, and priority are stored in ${MACRO_EXTEN}, \n"
-"${MACRO_CONTEXT} and ${MACRO_PRIORITY} respectively. Arguments become\n"
-"${ARG1}, ${ARG2}, etc in the macro context.\n"
-"If you Goto out of the Macro context, the Macro will terminate and control\n"
-"will be returned at the location of the Goto.\n"
-"If ${MACRO_OFFSET} is set at termination, Macro will attempt to continue\n"
-"at priority MACRO_OFFSET + N + 1 if such a step exists, and N + 1 otherwise.\n";
-
-static char *if_descrip =
-" MacroIf(<expr>?macroname_a[|arg1][:macroname_b[|arg1]])\n"
-"Executes macro defined in <macroname_a> if <expr> is true\n"
-"(otherwise <macroname_b> if provided)\n"
-"Arguments and return values as in application macro()\n";
-
-static char *exit_descrip =
-" MacroExit():\n"
-"Causes the currently running macro to exit as if it had\n"
-"ended normally by running out of priorities to execute.\n"
-"If used outside a macro, will likely cause unexpected\n"
-"behavior.\n";
-
-static char *app = "Macro";
-static char *if_app = "MacroIf";
-static char *exit_app = "MacroExit";
-
-static char *synopsis = "Macro Implementation";
-static char *if_synopsis = "Conditional Macro Implementation";
-static char *exit_synopsis = "Exit From Macro";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int macro_exec(struct ast_channel *chan, void *data)
-{
- char *tmp;
- char *cur, *rest;
- char *macro;
- char fullmacro[80];
- char varname[80];
- char *oldargs[MAX_ARGS + 1] = { NULL, };
- int argc, x;
- int res=0;
- char oldexten[256]="";
- int oldpriority;
- char pc[80], depthc[12];
- char oldcontext[AST_MAX_CONTEXT] = "";
- char *offsets;
- int offset, depth;
- int setmacrocontext=0;
- int autoloopflag, dead = 0;
-
- char *save_macro_exten;
- char *save_macro_context;
- char *save_macro_priority;
- char *save_macro_offset;
- struct localuser *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);
-
- /* Count how many levels deep the rabbit hole goes */
- tmp = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH");
- if (tmp) {
- sscanf(tmp, "%d", &depth);
- } else {
- depth = 0;
- }
-
- if (depth >= 7) {
- ast_log(LOG_ERROR, "Macro(): possible infinite loop detected. Returning early.\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- snprintf(depthc, sizeof(depthc), "%d", depth + 1);
- pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
-
- tmp = ast_strdupa(data);
- rest = tmp;
- macro = strsep(&rest, "|");
- if (ast_strlen_zero(macro)) {
- ast_log(LOG_WARNING, "Invalid macro name specified\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- snprintf(fullmacro, sizeof(fullmacro), "macro-%s", macro);
- if (!ast_exists_extension(chan, fullmacro, "s", 1, chan->cid.cid_num)) {
- if (!ast_context_find(fullmacro))
- 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);
- return 0;
- }
-
- /* Save old info */
- oldpriority = chan->priority;
- ast_copy_string(oldexten, chan->exten, sizeof(oldexten));
- ast_copy_string(oldcontext, chan->context, sizeof(oldcontext));
- if (ast_strlen_zero(chan->macrocontext)) {
- ast_copy_string(chan->macrocontext, chan->context, sizeof(chan->macrocontext));
- ast_copy_string(chan->macroexten, chan->exten, sizeof(chan->macroexten));
- chan->macropriority = chan->priority;
- setmacrocontext=1;
- }
- argc = 1;
- /* Save old macro variables */
- save_macro_exten = pbx_builtin_getvar_helper(chan, "MACRO_EXTEN");
- if (save_macro_exten)
- save_macro_exten = strdup(save_macro_exten);
- pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", oldexten);
-
- save_macro_context = pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT");
- if (save_macro_context)
- save_macro_context = strdup(save_macro_context);
- pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", oldcontext);
-
- save_macro_priority = pbx_builtin_getvar_helper(chan, "MACRO_PRIORITY");
- if (save_macro_priority)
- save_macro_priority = strdup(save_macro_priority);
- snprintf(pc, sizeof(pc), "%d", oldpriority);
- pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", pc);
-
- save_macro_offset = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET");
- if (save_macro_offset)
- save_macro_offset = strdup(save_macro_offset);
- pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", NULL);
-
- /* Setup environment for new run */
- chan->exten[0] = 's';
- chan->exten[1] = '\0';
- ast_copy_string(chan->context, fullmacro, sizeof(chan->context));
- chan->priority = 1;
-
- while((cur = strsep(&rest, "|")) && (argc < MAX_ARGS)) {
- /* Save copy of old arguments if we're overwriting some, otherwise
- let them pass through to the other macro */
- snprintf(varname, sizeof(varname), "ARG%d", argc);
- oldargs[argc] = pbx_builtin_getvar_helper(chan, varname);
- if (oldargs[argc])
- oldargs[argc] = strdup(oldargs[argc]);
- pbx_builtin_setvar_helper(chan, varname, cur);
- argc++;
- }
- autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
- ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
- while(ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
- /* Reset the macro depth, if it was changed in the last iteration */
- pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
- if ((res = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num))) {
- /* Something bad happened, or a hangup has been requested. */
- if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) ||
- (res == '*') || (res == '#')) {
- /* Just return result as to the previous application as if it had been dialed */
- ast_log(LOG_DEBUG, "Oooh, got something to jump out with ('%c')!\n", res);
- break;
- }
- switch(res) {
- case MACRO_EXIT_RESULT:
- res = 0;
- goto out;
- case AST_PBX_KEEPALIVE:
- if (option_debug)
- ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited KEEPALIVE in macro %s on '%s'\n", chan->context, chan->exten, chan->priority, macro, chan->name);
- else if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited KEEPALIVE in macro '%s' on '%s'\n", chan->context, chan->exten, chan->priority, macro, chan->name);
- goto out;
- break;
- default:
- if (option_debug)
- ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited non-zero on '%s' in macro '%s'\n", chan->context, chan->exten, chan->priority, chan->name, macro);
- else if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s' in macro '%s'\n", chan->context, chan->exten, chan->priority, chan->name, macro);
- dead = 1;
- goto out;
- }
- }
- if (strcasecmp(chan->context, fullmacro)) {
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Channel '%s' jumping out of macro '%s'\n", chan->name, macro);
- break;
- }
- /* don't stop executing extensions when we're in "h" */
- if (chan->_softhangup && strcasecmp(oldexten,"h")) {
- ast_log(LOG_DEBUG, "Extension %s, priority %d returned normally even though call was hung up\n",
- chan->exten, chan->priority);
- goto out;
- }
- chan->priority++;
- }
- out:
- /* Reset the depth back to what it was when the routine was entered (like if we called Macro recursively) */
- snprintf(depthc, sizeof(depthc), "%d", depth);
- if (!dead) {
- pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
-
- ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
- }
-
- for (x = 1; x < argc; x++) {
- /* Restore old arguments and delete ours */
- snprintf(varname, sizeof(varname), "ARG%d", x);
- if (oldargs[x]) {
- if (!dead)
- pbx_builtin_setvar_helper(chan, varname, oldargs[x]);
- free(oldargs[x]);
- } else if (!dead) {
- pbx_builtin_setvar_helper(chan, varname, NULL);
- }
- }
-
- /* Restore macro variables */
- if (!dead) {
- pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", save_macro_exten);
- pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", save_macro_context);
- pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", save_macro_priority);
- }
- if (save_macro_exten)
- free(save_macro_exten);
- if (save_macro_context)
- free(save_macro_context);
- if (save_macro_priority)
- free(save_macro_priority);
-
- if (!dead && setmacrocontext) {
- chan->macrocontext[0] = '\0';
- chan->macroexten[0] = '\0';
- chan->macropriority = 0;
- }
-
- if (!dead && !strcasecmp(chan->context, fullmacro)) {
- /* If we're leaving the macro normally, restore original information */
- chan->priority = oldpriority;
- ast_copy_string(chan->context, oldcontext, sizeof(chan->context));
- if (!(chan->_softhangup & AST_SOFTHANGUP_ASYNCGOTO)) {
- /* Copy the extension, so long as we're not in softhangup, where we could be given an asyncgoto */
- ast_copy_string(chan->exten, oldexten, sizeof(chan->exten));
- if ((offsets = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"))) {
- /* Handle macro offset if it's set by checking the availability of step n + offset + 1, otherwise continue
- normally if there is any problem */
- if (sscanf(offsets, "%d", &offset) == 1) {
- if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + offset + 1, chan->cid.cid_num)) {
- chan->priority += offset;
- }
- }
- }
- }
- }
-
- if (!dead)
- pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", save_macro_offset);
- if (save_macro_offset)
- free(save_macro_offset);
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-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;
-
- LOCAL_USER_ADD(u);
-
- expr = ast_strdupa(data);
- if (!expr) {
- ast_log(LOG_ERROR, "Out of Memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if ((label_a = strchr(expr, '?'))) {
- *label_a = '\0';
- label_a++;
- if ((label_b = strchr(label_a, ':'))) {
- *label_b = '\0';
- label_b++;
- }
- if (ast_true(expr))
- macro_exec(chan, label_a);
- else if (label_b)
- macro_exec(chan, label_b);
- } else
- ast_log(LOG_WARNING, "Invalid Syntax.\n");
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-static int macro_exit_exec(struct ast_channel *chan, void *data)
-{
- return MACRO_EXIT_RESULT;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(if_app);
- res |= ast_unregister_application(exit_app);
- res |= ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(exit_app, macro_exit_exec, exit_synopsis, exit_descrip);
- res |= ast_register_application(if_app, macroif_exec, if_synopsis, if_descrip);
- res |= ast_register_application(app, macro_exec, synopsis, descrip);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_math.c b/1.2-netsec/apps/app_math.c
deleted file mode 100644
index f1be8d4d1..000000000
--- a/1.2-netsec/apps/app_math.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005, Andy Powell
- *
- * Updated by Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief A simple math application
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <time.h>
-#include <dirent.h>
-#include <ctype.h>
-#include <sys/file.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/config.h"
-#include "asterisk/say.h"
-#include "asterisk/module.h"
-#include "asterisk/app.h"
-#include "asterisk/manager.h"
-#include "asterisk/localtime.h"
-#include "asterisk/cli.h"
-#include "asterisk/utils.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-
-static char *tdesc = "Basic Math Functions";
-
-static char *app_math = "Math";
-
-static char *math_synopsis = "Performs Mathematical Functions";
-
-static char *math_descrip =
-"Math(returnvar,<number1><op><number 2>\n\n"
-"Perform floating point calculation on number 1 to number 2 and \n"
-"store the result in returnvar. Valid ops are: \n"
-" +,-,/,*,%,<,>,>=,<=,==\n"
-"and behave as their C equivalents.\n";
-
-#define ADDFUNCTION 0
-#define DIVIDEFUNCTION 1
-#define MULTIPLYFUNCTION 2
-#define SUBTRACTFUNCTION 3
-#define MODULUSFUNCTION 4
-
-#define GTFUNCTION 5
-#define LTFUNCTION 6
-#define GTEFUNCTION 7
-#define LTEFUNCTION 8
-#define EQFUNCTION 9
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int math_exec(struct ast_channel *chan, void *data)
-{
- float fnum1;
- float fnum2;
- float ftmp = 0;
- char *op;
- int iaction=-1;
- static int deprecation_warning = 0;
-
- /* dunno, big calulations :D */
- char user_result[30];
-
- char *s;
- char *mvar, *mvalue1, *mvalue2=NULL;
-
- struct localuser *u;
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "Math() is deprecated, please use Set(var=${MATH(...)} instead.\n");
- deprecation_warning = 1;
- }
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "No parameters passed. !\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- s = ast_strdupa(data);
- if (!s) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- mvar = strsep(&s, "|");
- mvalue1 = strsep(&s, "|");
-
- if ((op = strchr(mvalue1, '+'))) {
- iaction = ADDFUNCTION;
- *op = '\0';
- } else if ((op = strchr(mvalue1, '-'))) {
- iaction = SUBTRACTFUNCTION;
- *op = '\0';
- } else if ((op = strchr(mvalue1, '*'))) {
- iaction = MULTIPLYFUNCTION;
- *op = '\0';
- } else if ((op = strchr(mvalue1, '/'))) {
- iaction = DIVIDEFUNCTION;
- *op = '\0';
- } else if ((op = strchr(mvalue1, '>'))) {
- iaction = GTFUNCTION;
- *op = '\0';
- if (*(op+1) == '=') {
- op++;
- *op = '\0';
- iaction = GTEFUNCTION;
- }
- } else if ((op = strchr(mvalue1, '<'))) {
- iaction = LTFUNCTION;
- *op = '\0';
- if (*(op+1) == '=') {
- op++;
- *op = '\0';
- iaction = LTEFUNCTION;
- }
- } else if ((op = strchr(mvalue1, '='))) {
- iaction = GTFUNCTION;
- *op = '\0';
- if (*(op+1) == '=') {
- op++;
- *op = '\0';
- iaction = EQFUNCTION;
- } else
- op = NULL;
- }
-
- if (op)
- mvalue2 = op + 1;
-
- if (!mvar || !mvalue1 || !mvalue2) {
- ast_log(LOG_WARNING, "Supply all the parameters - just this once, please\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (!strcmp(mvar,"")) {
- ast_log(LOG_WARNING, "No return variable set.\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (sscanf(mvalue1, "%f", &fnum1) != 1) {
- ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue1);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (sscanf(mvalue2, "%f", &fnum2) != 1) {
- ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue2);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- switch (iaction) {
- case ADDFUNCTION :
- ftmp = fnum1 + fnum2;
- break;
- case DIVIDEFUNCTION :
- if (fnum2 <=0)
- ftmp = 0; /* can't do a divide by 0 */
- else
- ftmp = (fnum1 / fnum2);
- break;
- case MULTIPLYFUNCTION :
- ftmp = (fnum1 * fnum2);
- break;
- case SUBTRACTFUNCTION :
- ftmp = (fnum1 - fnum2);
- break;
- case MODULUSFUNCTION : {
- int inum1 = fnum1;
- int inum2 = fnum2;
-
- ftmp = (inum1 % inum2);
-
- break;
- }
- case GTFUNCTION :
- if (fnum1 > fnum2)
- strcpy(user_result, "TRUE");
- else
- strcpy(user_result, "FALSE");
- break;
- case LTFUNCTION :
- if (fnum1 < fnum2)
- strcpy(user_result, "TRUE");
- else
- strcpy(user_result, "FALSE");
- break;
- case GTEFUNCTION :
- if (fnum1 >= fnum2)
- strcpy(user_result, "TRUE");
- else
- strcpy(user_result, "FALSE");
- break;
- case LTEFUNCTION :
- if (fnum1 <= fnum2)
- strcpy(user_result, "TRUE");
- else
- strcpy(user_result, "FALSE");
- break;
- case EQFUNCTION :
- if (fnum1 == fnum2)
- strcpy(user_result, "TRUE");
- else
- strcpy(user_result, "FALSE");
- break;
- default :
- ast_log(LOG_WARNING, "Something happened that neither of us should be proud of %d\n", iaction);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (iaction < GTFUNCTION || iaction > EQFUNCTION)
- snprintf(user_result,sizeof(user_result),"%f",ftmp);
-
- pbx_builtin_setvar_helper(chan, mvar, user_result);
-
- LOCAL_USER_REMOVE(u);
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app_math);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app_math, math_exec, math_synopsis, math_descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-/* Fading everything to black and blue... */
diff --git a/1.2-netsec/apps/app_md5.c b/1.2-netsec/apps/app_md5.c
deleted file mode 100644
index 4b018b33e..000000000
--- a/1.2-netsec/apps/app_md5.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Olle E. Johansson, Edvina.net
- *
- * 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 MD5 checksum application
- *
- * \todo Remove this deprecated application in 1.3dev
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/app.h"
-
-static char *tdesc_md5 = "MD5 checksum applications";
-static char *app_md5 = "MD5";
-static char *desc_md5 = "Calculate MD5 checksum";
-static char *synopsis_md5 =
-" MD5(<var>=<string>): Calculates a MD5 checksum on <string>.\n"
-"Returns hash value in a channel variable. \n";
-
-static char *app_md5check = "MD5Check";
-static char *desc_md5check = "Check MD5 checksum";
-static char *synopsis_md5check =
-" MD5Check(<md5hash>|<string>[|options]): Calculates a MD5 checksum on <string>\n"
-"and compares it with the hash. Returns 0 if <md5hash> is correct for <string>.\n"
-"The option string may contain zero or more of the following characters:\n"
-" 'j' -- jump to priority n+101 if the hash and string do not match \n"
-"This application sets the following channel variable upon completion:\n"
-" CHECKMD5STATUS The status of the MD5 check, one of the following\n"
-" MATCH | NOMATCH\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-/*--- md5_exec: Calculate MD5 checksum (hash) on given string and
- return it in channel variable ---*/
-static int md5_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *varname= NULL; /* Variable to set */
- char *string = NULL; /* String to calculate on */
- char retvar[50]; /* Return value */
- static int dep_warning = 0;
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "This application has been deprecated, please use the MD5 function instead.\n");
- dep_warning = 1;
- }
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Syntax: md5(<varname>=<string>) - missing argument!\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- memset(retvar,0, sizeof(retvar));
- string = ast_strdupa(data);
- varname = strsep(&string,"=");
- if (ast_strlen_zero(varname)) {
- ast_log(LOG_WARNING, "Syntax: md5(<varname>=<string>) - missing argument!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- ast_md5_hash(retvar, string);
- pbx_builtin_setvar_helper(chan, varname, retvar);
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-/*--- md5check_exec: Calculate MD5 checksum and compare it with
- existing checksum. ---*/
-static int md5check_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *string = NULL; /* String to calculate on */
- char newhash[50]; /* Return value */
- static int dep_warning = 0;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(md5hash);
- AST_APP_ARG(string);
- AST_APP_ARG(options);
- );
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "This application has been deprecated, please use the CHECK_MD5 function instead.\n");
- dep_warning = 1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (!(string = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, string);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- if (ast_strlen_zero(args.md5hash) || ast_strlen_zero(args.string)) {
- ast_log(LOG_WARNING, "Syntax: MD5Check(<md5hash>|<string>[|options]) - missing argument!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- memset(newhash,0, sizeof(newhash));
-
- ast_md5_hash(newhash, args.string);
- if (!strcmp(newhash, args.md5hash)) { /* Verification ok */
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "MD5 verified ok: %s -- %s\n", args.md5hash, args.string);
- pbx_builtin_setvar_helper(chan, "CHECKMD5STATUS", "MATCH");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "ERROR: MD5 not verified: %s -- %s\n", args.md5hash, args.string);
- pbx_builtin_setvar_helper(chan, "CHECKMD5STATUS", "NOMATCH");
- if (priority_jump || option_priority_jumping) {
- if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Can't jump to exten+101 (e%s,p%d), sorry\n", chan->exten,chan->priority+101);
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app_md5);
- res |= ast_unregister_application(app_md5check);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app_md5check, md5check_exec, desc_md5check, synopsis_md5check);
- res |= ast_register_application(app_md5, md5_exec, desc_md5, synopsis_md5);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc_md5;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_meetme.c b/1.2-netsec/apps/app_meetme.c
deleted file mode 100644
index 37d34d395..000000000
--- a/1.2-netsec/apps/app_meetme.c
+++ /dev/null
@@ -1,2247 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Meet me conference bridge
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#ifdef __linux__
-#include <linux/zaptel.h>
-#else
-#include <zaptel.h>
-#endif /* __linux__ */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/app.h"
-#include "asterisk/dsp.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/manager.h"
-#include "asterisk/options.h"
-#include "asterisk/cli.h"
-#include "asterisk/say.h"
-#include "asterisk/utils.h"
-
-static const char *tdesc = "MeetMe conference bridge";
-
-static const char *app = "MeetMe";
-static const char *app2 = "MeetMeCount";
-static const char *app3 = "MeetMeAdmin";
-
-static const char *synopsis = "MeetMe conference bridge";
-static const char *synopsis2 = "MeetMe participant count";
-static const char *synopsis3 = "MeetMe conference Administration";
-
-static const char *descrip =
-" MeetMe([confno][,[options][,pin]]): Enters the user into a specified MeetMe conference.\n"
-"If the conference number is omitted, the user will be prompted to enter\n"
-"one. \n"
-"User can exit the conference by hangup, or if the 'p' option is specified, by pressing '#'.\n"
-"Please note: A ZAPTEL INTERFACE MUST BE INSTALLED FOR CONFERENCING TO WORK!\n\n"
-
-"The option string may contain zero or more of the following characters:\n"
-" 'a' -- set admin mode\n"
-" 'A' -- set marked mode\n"
-" 'b' -- run AGI script specified in ${MEETME_AGI_BACKGROUND}\n"
-" Default: conf-background.agi\n"
-" (Note: This does not work with non-Zap channels in the same conference)\n"
-" 'c' -- announce user(s) count on joining a conference\n"
-" 'd' -- dynamically add conference\n"
-" 'D' -- dynamically add conference, prompting for a PIN\n"
-" 'e' -- select an empty conference\n"
-" 'E' -- select an empty pinless conference\n"
-" 'i' -- announce user join/leave\n"
-" 'm' -- set monitor only mode (Listen only, no talking)\n"
-" 'M' -- enable music on hold when the conference has a single caller\n"
-" 'p' -- allow user to exit the conference by pressing '#'\n"
-" 'P' -- always prompt for the pin even if it is specified\n"
-" 'q' -- quiet mode (don't play enter/leave sounds)\n"
-" 'r' -- Record conference (records as ${MEETME_RECORDINGFILE}\n"
-" using format ${MEETME_RECORDINGFORMAT}). Default filename is\n"
-" meetme-conf-rec-${CONFNO}-${UNIQUEID} and the default format is wav.\n"
-" 's' -- Present menu (user or admin) when '*' is received ('send' to menu)\n"
-" 't' -- set talk only mode. (Talk only, no listening)\n"
-" 'T' -- set talker detection (sent to manager interface and meetme list)\n"
-" 'v' -- video mode\n"
-" 'w' -- wait until the marked user enters the conference\n"
-" 'x' -- close the conference when last marked user exits\n"
-" 'X' -- allow user to exit the conference by entering a valid single\n"
-" digit extension ${MEETME_EXIT_CONTEXT} or the current context\n"
-" if that variable is not defined.\n";
-
-static const char *descrip2 =
-" MeetMeCount(confno[|var]): Plays back the number of users in the specified\n"
-"MeetMe conference. If var is specified, playback will be skipped and the value\n"
-"will be returned in the variable. Upon app completion, MeetMeCount will hangup the\n"
-"channel, unless priority n+1 exists, in which case priority progress will continue.\n"
-"A ZAPTEL INTERFACE MUST BE INSTALLED FOR CONFERENCING FUNCTIONALITY.\n";
-
-static const char *descrip3 =
-" MeetMeAdmin(confno,command[,user]): Run admin command for conference\n"
-" 'e' -- Eject last user that joined\n"
-" 'k' -- Kick one user out of conference\n"
-" 'K' -- Kick all users out of conference\n"
-" 'l' -- Unlock conference\n"
-" 'L' -- Lock conference\n"
-" 'm' -- Unmute conference\n"
-" 'M' -- Mute conference\n"
-" 'n' -- Unmute entire conference (except admin)\n"
-" 'N' -- Mute entire conference (except admin)\n"
-"";
-
-#define CONFIG_FILE_NAME "meetme.conf"
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static struct ast_conference {
- char confno[AST_MAX_EXTENSION]; /* Conference */
- struct ast_channel *chan; /* Announcements channel */
- int fd; /* Announcements fd */
- int zapconf; /* Zaptel Conf # */
- int users; /* Number of active users */
- int markedusers; /* Number of marked users */
- struct ast_conf_user *firstuser; /* Pointer to the first user struct */
- struct ast_conf_user *lastuser; /* Pointer to the last user struct */
- time_t start; /* Start time (s) */
- int recording; /* recording status */
- int isdynamic; /* Created on the fly? */
- int locked; /* Is the conference locked? */
- pthread_t recordthread; /* thread for recording */
- pthread_attr_t attr; /* thread attribute */
- char *recordingfilename; /* Filename to record the Conference into */
- char *recordingformat; /* Format to record the Conference in */
- char pin[AST_MAX_EXTENSION]; /* If protected by a PIN */
- char pinadmin[AST_MAX_EXTENSION]; /* If protected by a admin PIN */
- struct ast_conference *next;
-} *confs;
-
-struct volume {
- int desired; /* Desired volume adjustment */
- int actual; /* Actual volume adjustment (for channels that can't adjust) */
-};
-
-struct ast_conf_user {
- int user_no; /* User Number */
- struct ast_conf_user *prevuser; /* Pointer to the previous user */
- struct ast_conf_user *nextuser; /* Pointer to the next user */
- int userflags; /* Flags as set in the conference */
- int adminflags; /* Flags set by the Admin */
- struct ast_channel *chan; /* Connected channel */
- int talking; /* Is user talking */
- int zapchannel; /* Is a Zaptel channel */
- char usrvalue[50]; /* Custom User Value */
- char namerecloc[AST_MAX_EXTENSION]; /* Name Recorded file Location */
- time_t jointime; /* Time the user joined the conference */
- struct volume talk;
- struct volume listen;
-};
-
-static int audio_buffers; /* The number of audio buffers to be allocated on pseudo channels
- when in a conference
- */
-
-#define DEFAULT_AUDIO_BUFFERS 32 /* each buffer is 20ms, so this is 640ms total */
-
-#define ADMINFLAG_MUTED (1 << 1) /* User is muted */
-#define ADMINFLAG_KICKME (1 << 2) /* User is kicked */
-#define MEETME_DELAYDETECTTALK 300
-#define MEETME_DELAYDETECTENDTALK 1000
-
-enum volume_action {
- VOL_UP,
- VOL_DOWN,
-};
-
-AST_MUTEX_DEFINE_STATIC(conflock);
-
-static int admin_exec(struct ast_channel *chan, void *data);
-
-static void *recordthread(void *args);
-
-#include "enter.h"
-#include "leave.h"
-
-#define ENTER 0
-#define LEAVE 1
-
-#define MEETME_RECORD_OFF 0
-#define MEETME_RECORD_ACTIVE 1
-#define MEETME_RECORD_TERMINATE 2
-
-#define CONF_SIZE 320
-
-#define CONFFLAG_ADMIN (1 << 1) /* If set the user has admin access on the conference */
-#define CONFFLAG_MONITOR (1 << 2) /* If set the user can only receive audio from the conference */
-#define CONFFLAG_POUNDEXIT (1 << 3) /* If set asterisk will exit conference when '#' is pressed */
-#define CONFFLAG_STARMENU (1 << 4) /* If set asterisk will provide a menu to the user when '*' is pressed */
-#define CONFFLAG_TALKER (1 << 5) /* If set the use can only send audio to the conference */
-#define CONFFLAG_QUIET (1 << 6) /* If set there will be no enter or leave sounds */
-#define CONFFLAG_VIDEO (1 << 7) /* Set to enable video mode */
-#define CONFFLAG_AGI (1 << 8) /* Set to run AGI Script in Background */
-#define CONFFLAG_MOH (1 << 9) /* Set to have music on hold when user is alone in conference */
-#define CONFFLAG_MARKEDEXIT (1 << 10) /* If set the MeetMe will return if all marked with this flag left */
-#define CONFFLAG_WAITMARKED (1 << 11) /* If set, the MeetMe will wait until a marked user enters */
-#define CONFFLAG_EXIT_CONTEXT (1 << 12) /* If set, the MeetMe will exit to the specified context */
-#define CONFFLAG_MARKEDUSER (1 << 13) /* If set, the user will be marked */
-#define CONFFLAG_INTROUSER (1 << 14) /* If set, user will be ask record name on entry of conference */
-#define CONFFLAG_RECORDCONF (1<< 15) /* If set, the MeetMe will be recorded */
-#define CONFFLAG_MONITORTALKER (1 << 16) /* If set, the user will be monitored if the user is talking or not */
-#define CONFFLAG_DYNAMIC (1 << 17)
-#define CONFFLAG_DYNAMICPIN (1 << 18)
-#define CONFFLAG_EMPTY (1 << 19)
-#define CONFFLAG_EMPTYNOPIN (1 << 20)
-#define CONFFLAG_ALWAYSPROMPT (1 << 21)
-#define CONFFLAG_ANNOUNCEUSERCOUNT (1 << 22) /* If set, when user joins the conference, they will be told the number of users that are already in */
-
-
-AST_APP_OPTIONS(meetme_opts, {
- AST_APP_OPTION('a', CONFFLAG_ADMIN ),
- AST_APP_OPTION('c', CONFFLAG_ANNOUNCEUSERCOUNT ),
- AST_APP_OPTION('T', CONFFLAG_MONITORTALKER ),
- AST_APP_OPTION('i', CONFFLAG_INTROUSER ),
- AST_APP_OPTION('m', CONFFLAG_MONITOR ),
- AST_APP_OPTION('p', CONFFLAG_POUNDEXIT ),
- AST_APP_OPTION('s', CONFFLAG_STARMENU ),
- AST_APP_OPTION('t', CONFFLAG_TALKER ),
- AST_APP_OPTION('q', CONFFLAG_QUIET ),
- AST_APP_OPTION('M', CONFFLAG_MOH ),
- AST_APP_OPTION('x', CONFFLAG_MARKEDEXIT ),
- AST_APP_OPTION('X', CONFFLAG_EXIT_CONTEXT ),
- AST_APP_OPTION('A', CONFFLAG_MARKEDUSER ),
- AST_APP_OPTION('b', CONFFLAG_AGI ),
- AST_APP_OPTION('w', CONFFLAG_WAITMARKED ),
- AST_APP_OPTION('r', CONFFLAG_RECORDCONF ),
- AST_APP_OPTION('d', CONFFLAG_DYNAMIC ),
- AST_APP_OPTION('D', CONFFLAG_DYNAMICPIN ),
- AST_APP_OPTION('e', CONFFLAG_EMPTY ),
- AST_APP_OPTION('E', CONFFLAG_EMPTYNOPIN ),
- AST_APP_OPTION('P', CONFFLAG_ALWAYSPROMPT ),
-});
-
-static char *istalking(int x)
-{
- if (x > 0)
- return "(talking)";
- else if (x < 0)
- return "(unmonitored)";
- else
- return "(not talking)";
-}
-
-static int careful_write(int fd, unsigned char *data, int len, int block)
-{
- int res;
- int x;
-
- while (len) {
- if (block) {
- x = ZT_IOMUX_WRITE | ZT_IOMUX_SIGEVENT;
- res = ioctl(fd, ZT_IOMUX, &x);
- } else
- res = 0;
- if (res >= 0)
- res = write(fd, data, len);
- if (res < 1) {
- if (errno != EAGAIN) {
- ast_log(LOG_WARNING, "Failed to write audio data to conference: %s\n", strerror(errno));
- return -1;
- } else
- return 0;
- }
- len -= res;
- data += res;
- }
-
- return 0;
-}
-
-/* Map 'volume' levels from -5 through +5 into
- decibel (dB) settings for channel drivers
- Note: these are not a straight linear-to-dB
- conversion... the numbers have been modified
- to give the user a better level of adjustability
-*/
-static signed char gain_map[] = {
- -15,
- -13,
- -10,
- -6,
- 0,
- 0,
- 0,
- 6,
- 10,
- 13,
- 15,
-};
-
-static int set_talk_volume(struct ast_conf_user *user, int volume)
-{
- signed char gain_adjust;
-
- /* attempt to make the adjustment in the channel driver;
- if successful, don't adjust in the frame reading routine
- */
- gain_adjust = gain_map[volume + 5];
-
- return ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
-}
-
-static int set_listen_volume(struct ast_conf_user *user, int volume)
-{
- signed char gain_adjust;
-
- /* attempt to make the adjustment in the channel driver;
- if successful, don't adjust in the frame reading routine
- */
- gain_adjust = gain_map[volume + 5];
-
- return ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
-}
-
-static void tweak_volume(struct volume *vol, enum volume_action action)
-{
- switch (action) {
- case VOL_UP:
- switch (vol->desired) {
- case 5:
- break;
- case 0:
- vol->desired = 2;
- break;
- case -2:
- vol->desired = 0;
- break;
- default:
- vol->desired++;
- break;
- }
- break;
- case VOL_DOWN:
- switch (vol->desired) {
- case -5:
- break;
- case 2:
- vol->desired = 0;
- break;
- case 0:
- vol->desired = -2;
- break;
- default:
- vol->desired--;
- break;
- }
- }
-}
-
-static void tweak_talk_volume(struct ast_conf_user *user, enum volume_action action)
-{
- tweak_volume(&user->talk, action);
- /* attempt to make the adjustment in the channel driver;
- if successful, don't adjust in the frame reading routine
- */
- if (!set_talk_volume(user, user->talk.desired))
- user->talk.actual = 0;
- else
- user->talk.actual = user->talk.desired;
-}
-
-static void tweak_listen_volume(struct ast_conf_user *user, enum volume_action action)
-{
- tweak_volume(&user->listen, action);
- /* attempt to make the adjustment in the channel driver;
- if successful, don't adjust in the frame reading routine
- */
- if (!set_listen_volume(user, user->listen.desired))
- user->listen.actual = 0;
- else
- user->listen.actual = user->listen.desired;
-}
-
-static void reset_volumes(struct ast_conf_user *user)
-{
- signed char zero_volume = 0;
-
- ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &zero_volume, sizeof(zero_volume), 0);
- ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &zero_volume, sizeof(zero_volume), 0);
-}
-
-static void conf_play(struct ast_channel *chan, struct ast_conference *conf, int sound)
-{
- unsigned char *data;
- int len;
- int res = -1;
-
- if (!chan->_softhangup)
- res = ast_autoservice_start(chan);
-
- ast_mutex_lock(&conflock);
-
- switch(sound) {
- case ENTER:
- data = enter;
- len = sizeof(enter);
- break;
- case LEAVE:
- data = leave;
- len = sizeof(leave);
- break;
- default:
- data = NULL;
- len = 0;
- }
- if (data)
- careful_write(conf->fd, data, len, 1);
-
- ast_mutex_unlock(&conflock);
-
- if (!res)
- ast_autoservice_stop(chan);
-}
-
-static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin, int make, int dynamic)
-{
- struct ast_conference *cnf;
- struct zt_confinfo ztc;
-
- ast_mutex_lock(&conflock);
-
- for (cnf = confs; cnf; cnf = cnf->next) {
- if (!strcmp(confno, cnf->confno))
- break;
- }
-
- if (!cnf && (make || dynamic)) {
- /* Make a new one */
- cnf = calloc(1, sizeof(*cnf));
- if (cnf) {
- ast_copy_string(cnf->confno, confno, sizeof(cnf->confno));
- ast_copy_string(cnf->pin, pin, sizeof(cnf->pin));
- ast_copy_string(cnf->pinadmin, pinadmin, sizeof(cnf->pinadmin));
- cnf->markedusers = 0;
- cnf->chan = ast_request("zap", AST_FORMAT_ULAW, "pseudo", NULL);
- if (cnf->chan) {
- cnf->fd = cnf->chan->fds[0]; /* for use by conf_play() */
- } else {
- ast_log(LOG_WARNING, "Unable to open pseudo channel - trying device\n");
- cnf->fd = open("/dev/zap/pseudo", O_RDWR);
- if (cnf->fd < 0) {
- ast_log(LOG_WARNING, "Unable to open pseudo device\n");
- free(cnf);
- cnf = NULL;
- goto cnfout;
- }
- }
- memset(&ztc, 0, sizeof(ztc));
- /* Setup a new zap conference */
- ztc.chan = 0;
- ztc.confno = -1;
- ztc.confmode = ZT_CONF_CONFANN | ZT_CONF_CONFANNMON;
- if (ioctl(cnf->fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- if (cnf->chan)
- ast_hangup(cnf->chan);
- else
- close(cnf->fd);
- free(cnf);
- cnf = NULL;
- goto cnfout;
- }
- /* Fill the conference struct */
- cnf->start = time(NULL);
- cnf->zapconf = ztc.confno;
- cnf->isdynamic = dynamic;
- cnf->firstuser = NULL;
- cnf->lastuser = NULL;
- cnf->locked = 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Created MeetMe conference %d for conference '%s'\n", cnf->zapconf, cnf->confno);
- cnf->next = confs;
- confs = cnf;
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- }
- cnfout:
- ast_mutex_unlock(&conflock);
- return cnf;
-}
-
-static int confs_show(int fd, int argc, char **argv)
-{
- ast_cli(fd, "Deprecated! Please use 'meetme' instead.\n");
-
- return RESULT_SUCCESS;
-}
-
-static char show_confs_usage[] =
-"Deprecated! Please use 'meetme' instead.\n";
-
-static struct ast_cli_entry cli_show_confs = {
- { "show", "conferences", NULL }, confs_show,
- "Show status of conferences", show_confs_usage, NULL };
-
-static int conf_cmd(int fd, int argc, char **argv) {
- /* Process the command */
- struct ast_conference *cnf;
- struct ast_conf_user *user;
- int hr, min, sec;
- int i = 0, total = 0;
- time_t now;
- char *header_format = "%-14s %-14s %-10s %-8s %-8s\n";
- char *data_format = "%-12.12s %4.4d %4.4s %02d:%02d:%02d %-8s\n";
- char cmdline[1024] = "";
-
- if (argc > 8)
- ast_cli(fd, "Invalid Arguments.\n");
- /* Check for length so no buffer will overflow... */
- for (i = 0; i < argc; i++) {
- if (strlen(argv[i]) > 100)
- ast_cli(fd, "Invalid Arguments.\n");
- }
- if (argc == 1) {
- /* 'MeetMe': List all the conferences */
- now = time(NULL);
- cnf = confs;
- if (!cnf) {
- ast_cli(fd, "No active MeetMe conferences.\n");
- return RESULT_SUCCESS;
- }
- ast_cli(fd, header_format, "Conf Num", "Parties", "Marked", "Activity", "Creation");
- while(cnf) {
- if (cnf->markedusers == 0)
- strcpy(cmdline, "N/A ");
- else
- snprintf(cmdline, sizeof(cmdline), "%4.4d", cnf->markedusers);
- hr = (now - cnf->start) / 3600;
- min = ((now - cnf->start) % 3600) / 60;
- sec = (now - cnf->start) % 60;
-
- ast_cli(fd, data_format, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static");
-
- total += cnf->users;
- cnf = cnf->next;
- }
- ast_cli(fd, "* Total number of MeetMe users: %d\n", total);
- return RESULT_SUCCESS;
- }
- if (argc < 3)
- return RESULT_SHOWUSAGE;
- ast_copy_string(cmdline, argv[2], sizeof(cmdline)); /* Argv 2: conference number */
- if (strstr(argv[1], "lock")) {
- if (strcmp(argv[1], "lock") == 0) {
- /* Lock */
- strncat(cmdline, "|L", sizeof(cmdline) - strlen(cmdline) - 1);
- } else {
- /* Unlock */
- strncat(cmdline, "|l", sizeof(cmdline) - strlen(cmdline) - 1);
- }
- } else if (strstr(argv[1], "mute")) {
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- if (strcmp(argv[1], "mute") == 0) {
- /* Mute */
- if (strcmp(argv[3], "all") == 0) {
- strncat(cmdline, "|N", sizeof(cmdline) - strlen(cmdline) - 1);
- } else {
- strncat(cmdline, "|M|", sizeof(cmdline) - strlen(cmdline) - 1);
- strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
- }
- } else {
- /* Unmute */
- if (strcmp(argv[3], "all") == 0) {
- strncat(cmdline, "|n", sizeof(cmdline) - strlen(cmdline) - 1);
- } else {
- strncat(cmdline, "|m|", sizeof(cmdline) - strlen(cmdline) - 1);
- strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
- }
- }
- } else if (strcmp(argv[1], "kick") == 0) {
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- if (strcmp(argv[3], "all") == 0) {
- /* Kick all */
- strncat(cmdline, "|K", sizeof(cmdline) - strlen(cmdline) - 1);
- } else {
- /* Kick a single user */
- strncat(cmdline, "|k|", sizeof(cmdline) - strlen(cmdline) - 1);
- strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
- }
- } else if(strcmp(argv[1], "list") == 0) {
- /* List all the users in a conference */
- if (!confs) {
- ast_cli(fd, "No active conferences.\n");
- return RESULT_SUCCESS;
- }
- cnf = confs;
- /* Find the right conference */
- while(cnf) {
- if (strcmp(cnf->confno, argv[2]) == 0)
- break;
- if (cnf->next) {
- cnf = cnf->next;
- } else {
- ast_cli(fd, "No such conference: %s.\n",argv[2]);
- return RESULT_SUCCESS;
- }
- }
- /* Show all the users */
- for (user = cnf->firstuser; user; user = user->nextuser)
- ast_cli(fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s\n",
- user->user_no,
- user->chan->cid.cid_num ? user->chan->cid.cid_num : "<unknown>",
- user->chan->cid.cid_name ? user->chan->cid.cid_name : "<no name>",
- user->chan->name,
- user->userflags & CONFFLAG_ADMIN ? "(Admin)" : "",
- user->userflags & CONFFLAG_MONITOR ? "(Listen only)" : "",
- user->adminflags & ADMINFLAG_MUTED ? "(Admn Muted)" : "",
- istalking(user->talking));
- ast_cli(fd,"%d users in that conference.\n",cnf->users);
-
- return RESULT_SUCCESS;
- } else
- return RESULT_SHOWUSAGE;
- ast_log(LOG_DEBUG, "Cmdline: %s\n", cmdline);
- admin_exec(NULL, cmdline);
-
- return 0;
-}
-
-static char *complete_confcmd(char *line, char *word, int pos, int state) {
-#define CONF_COMMANDS 6
- int which = 0, x = 0;
- struct ast_conference *cnf = NULL;
- struct ast_conf_user *usr = NULL;
- char *confno = NULL;
- char usrno[50] = "";
- char cmds[CONF_COMMANDS][20] = {"lock", "unlock", "mute", "unmute", "kick", "list"};
- char *myline;
-
- if (pos == 1) {
- /* Command */
- for (x = 0;x < CONF_COMMANDS; x++) {
- if (!strncasecmp(cmds[x], word, strlen(word))) {
- if (++which > state) {
- return strdup(cmds[x]);
- }
- }
- }
- } else if (pos == 2) {
- /* Conference Number */
- ast_mutex_lock(&conflock);
- cnf = confs;
- while(cnf) {
- if (!strncasecmp(word, cnf->confno, strlen(word))) {
- if (++which > state)
- break;
- }
- cnf = cnf->next;
- }
- ast_mutex_unlock(&conflock);
- return cnf ? strdup(cnf->confno) : NULL;
- } else if (pos == 3) {
- /* User Number || Conf Command option*/
- if (strstr(line, "mute") || strstr(line, "kick")) {
- if ((state == 0) && (strstr(line, "kick") || strstr(line,"mute")) && !(strncasecmp(word, "all", strlen(word)))) {
- return strdup("all");
- }
- which++;
- ast_mutex_lock(&conflock);
-
- /* TODO: Find the conf number from the cmdline (ignore spaces) <- test this and make it fail-safe! */
- myline = ast_strdupa(line);
- if (strsep(&myline, " ") && strsep(&myline, " ") && !confno) {
- while((confno = strsep(&myline, " ")) && (strcmp(confno, " ") == 0))
- ;
- }
-
- for (cnf = confs; cnf; cnf = cnf->next) {
- if (!strcmp(confno, cnf->confno))
- break;
- }
-
- if (cnf) {
- /* Search for the user */
- for (usr = cnf->firstuser; usr; usr = usr->nextuser) {
- snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
- if (!strncasecmp(word, usrno, strlen(word))) {
- if (++which > state)
- break;
- }
- }
- }
- ast_mutex_unlock(&conflock);
- return usr ? strdup(usrno) : NULL;
- }
- }
-
- return NULL;
-}
-
-static char conf_usage[] =
-"Usage: meetme (un)lock|(un)mute|kick|list <confno> <usernumber>\n"
-" Executes a command for the conference or on a conferee\n";
-
-static struct ast_cli_entry cli_conf = {
- {"meetme", NULL, NULL }, conf_cmd,
- "Execute a command on a conference or conferee", conf_usage, complete_confcmd};
-
-static void conf_flush(int fd, struct ast_channel *chan)
-{
- int x;
-
- /* read any frames that may be waiting on the channel
- and throw them away
- */
- if (chan) {
- struct ast_frame *f;
-
- /* when no frames are available, this will wait
- for 1 millisecond maximum
- */
- while (ast_waitfor(chan, 1)) {
- f = ast_read(chan);
- if (f)
- ast_frfree(f);
- }
- }
-
- /* flush any data sitting in the pseudo channel */
- x = ZT_FLUSH_ALL;
- if (ioctl(fd, ZT_FLUSH, &x))
- ast_log(LOG_WARNING, "Error flushing channel\n");
-
-}
-
-/* Remove the conference from the list and free it.
- We assume that this was called while holding conflock. */
-static int conf_free(struct ast_conference *conf)
-{
- struct ast_conference *prev = NULL, *cur = confs;
-
- while (cur) {
- if (cur == conf) {
- if (prev)
- prev->next = conf->next;
- else
- confs = conf->next;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
-
- if (!cur)
- ast_log(LOG_WARNING, "Conference not found\n");
-
- if (conf->recording == MEETME_RECORD_ACTIVE) {
- conf->recording = MEETME_RECORD_TERMINATE;
- ast_mutex_unlock(&conflock);
- while (1) {
- ast_mutex_lock(&conflock);
- if (conf->recording == MEETME_RECORD_OFF)
- break;
- ast_mutex_unlock(&conflock);
- }
- }
-
- if (conf->chan)
- ast_hangup(conf->chan);
- else
- close(conf->fd);
-
- free(conf);
-
- return 0;
-}
-
-static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int confflags)
-{
- struct ast_conf_user *user = calloc(1, sizeof(*user));
- struct ast_conf_user *usr = NULL;
- int fd;
- struct zt_confinfo ztc, ztc_empty;
- struct ast_frame *f;
- struct ast_channel *c;
- struct ast_frame fr;
- int outfd;
- int ms;
- int nfds;
- int res;
- int flags;
- int retryzap;
- int origfd;
- int musiconhold = 0;
- int firstpass = 0;
- int lastmarked = 0;
- int currentmarked = 0;
- int ret = -1;
- int x;
- int menu_active = 0;
- int using_pseudo = 0;
- int duration=20;
- struct ast_dsp *dsp=NULL;
- struct ast_app *app;
- char *agifile;
- char *agifiledefault = "conf-background.agi";
- char meetmesecs[30] = "";
- char exitcontext[AST_MAX_CONTEXT] = "";
- char recordingtmp[AST_MAX_EXTENSION] = "";
- int dtmf;
- ZT_BUFFERINFO bi;
- char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
- char *buf = __buf + AST_FRIENDLY_OFFSET;
-
- if (!user) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return ret;
- }
-
- if (confflags & CONFFLAG_RECORDCONF && conf->recording !=MEETME_RECORD_ACTIVE) {
- conf->recordingfilename = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFILE");
- if (!conf->recordingfilename) {
- snprintf(recordingtmp, sizeof(recordingtmp), "meetme-conf-rec-%s-%s", conf->confno, chan->uniqueid);
- conf->recordingfilename = ast_strdupa(recordingtmp);
- }
- conf->recordingformat = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT");
- if (!conf->recordingformat) {
- snprintf(recordingtmp, sizeof(recordingtmp), "wav");
- conf->recordingformat = ast_strdupa(recordingtmp);
- }
- pthread_attr_init(&conf->attr);
- pthread_attr_setdetachstate(&conf->attr, PTHREAD_CREATE_DETACHED);
- ast_verbose(VERBOSE_PREFIX_4 "Starting recording of MeetMe Conference %s into file %s.%s.\n",
- conf->confno, conf->recordingfilename, conf->recordingformat);
- ast_pthread_create(&conf->recordthread, &conf->attr, recordthread, conf);
- }
-
- time(&user->jointime);
-
- if (conf->locked && (!(confflags & CONFFLAG_ADMIN))) {
- /* Sorry, but this confernce is locked! */
- if (!ast_streamfile(chan, "conf-locked", chan->language))
- ast_waitstream(chan, "");
- goto outrun;
- }
-
- if (confflags & CONFFLAG_MARKEDUSER)
- conf->markedusers++;
-
- ast_mutex_lock(&conflock);
- if (!conf->firstuser) {
- /* Fill the first new User struct */
- user->user_no = 1;
- conf->firstuser = user;
- conf->lastuser = user;
- } else {
- /* Fill the new user struct */
- user->user_no = conf->lastuser->user_no + 1;
- user->prevuser = conf->lastuser;
- if (conf->lastuser->nextuser) {
- ast_log(LOG_WARNING, "Error in User Management!\n");
- ast_mutex_unlock(&conflock);
- goto outrun;
- } else {
- conf->lastuser->nextuser = user;
- conf->lastuser = user;
- }
- }
-
- user->chan = chan;
- user->userflags = confflags;
- user->adminflags = 0;
- user->talking = -1;
- conf->users++;
- ast_mutex_unlock(&conflock);
-
- if (confflags & CONFFLAG_EXIT_CONTEXT) {
- if ((agifile = pbx_builtin_getvar_helper(chan, "MEETME_EXIT_CONTEXT")))
- ast_copy_string(exitcontext, agifile, sizeof(exitcontext));
- else if (!ast_strlen_zero(chan->macrocontext))
- ast_copy_string(exitcontext, chan->macrocontext, sizeof(exitcontext));
- else
- ast_copy_string(exitcontext, chan->context, sizeof(exitcontext));
- }
-
- if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_INTROUSER)) {
- snprintf(user->namerecloc, sizeof(user->namerecloc),
- "%s/meetme/meetme-username-%s-%d", ast_config_AST_SPOOL_DIR,
- conf->confno, user->user_no);
- ast_record_review(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL);
- }
-
- if (!(confflags & CONFFLAG_QUIET)) {
- if (conf->users == 1 && !(confflags & CONFFLAG_WAITMARKED))
- if (!ast_streamfile(chan, "conf-onlyperson", chan->language))
- ast_waitstream(chan, "");
- if ((confflags & CONFFLAG_WAITMARKED) && conf->markedusers == 0)
- if (!ast_streamfile(chan, "conf-waitforleader", chan->language))
- ast_waitstream(chan, "");
- }
-
- if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_ANNOUNCEUSERCOUNT) && conf->users > 1) {
- int keepplaying = 1;
-
- if (conf->users == 2) {
- if (!ast_streamfile(chan,"conf-onlyone",chan->language)) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- if (res > 0)
- keepplaying=0;
- else if (res == -1)
- goto outrun;
- }
- } else {
- if (!ast_streamfile(chan, "conf-thereare", chan->language)) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- if (res > 0)
- keepplaying=0;
- else if (res == -1)
- goto outrun;
- }
- if (keepplaying) {
- res = ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
- if (res > 0)
- keepplaying=0;
- else if (res == -1)
- goto outrun;
- }
- if (keepplaying && !ast_streamfile(chan, "conf-otherinparty", chan->language)) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- if (res > 0)
- keepplaying=0;
- else if (res == -1)
- goto outrun;
- }
- }
- }
-
- ast_indicate(chan, -1);
-
- if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
- ast_log(LOG_WARNING, "Unable to set '%s' to write linear mode\n", chan->name);
- goto outrun;
- }
-
- if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
- ast_log(LOG_WARNING, "Unable to set '%s' to read linear mode\n", chan->name);
- goto outrun;
- }
-
- retryzap = strcasecmp(chan->type, "Zap");
- user->zapchannel = !retryzap;
-
- zapretry:
- origfd = chan->fds[0];
- if (retryzap) {
- fd = open("/dev/zap/pseudo", O_RDWR);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
- goto outrun;
- }
- using_pseudo = 1;
- /* Make non-blocking */
- flags = fcntl(fd, F_GETFL);
- if (flags < 0) {
- ast_log(LOG_WARNING, "Unable to get flags: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
- ast_log(LOG_WARNING, "Unable to set flags: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- /* Setup buffering information */
- memset(&bi, 0, sizeof(bi));
- bi.bufsize = CONF_SIZE/2;
- bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.numbufs = audio_buffers;
- if (ioctl(fd, ZT_SET_BUFINFO, &bi)) {
- ast_log(LOG_WARNING, "Unable to set buffering information: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- x = 1;
- if (ioctl(fd, ZT_SETLINEAR, &x)) {
- ast_log(LOG_WARNING, "Unable to set linear mode: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- nfds = 1;
- } else {
- /* XXX Make sure we're not running on a pseudo channel XXX */
- fd = chan->fds[0];
- nfds = 0;
- }
- memset(&ztc, 0, sizeof(ztc));
- memset(&ztc_empty, 0, sizeof(ztc_empty));
- /* Check to see if we're in a conference... */
- ztc.chan = 0;
- if (ioctl(fd, ZT_GETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error getting conference\n");
- close(fd);
- goto outrun;
- }
- if (ztc.confmode) {
- /* Whoa, already in a conference... Retry... */
- if (!retryzap) {
- ast_log(LOG_DEBUG, "Zap channel is in a conference already, retrying with pseudo\n");
- retryzap = 1;
- goto zapretry;
- }
- }
- memset(&ztc, 0, sizeof(ztc));
- /* Add us to the conference */
- ztc.chan = 0;
- ztc.confno = conf->zapconf;
-
- ast_mutex_lock(&conflock);
-
- if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_INTROUSER) && conf->users > 1) {
- if (conf->chan && ast_fileexists(user->namerecloc, NULL, NULL)) {
- if (!ast_streamfile(conf->chan, user->namerecloc, chan->language))
- ast_waitstream(conf->chan, "");
- if (!ast_streamfile(conf->chan, "conf-hasjoin", chan->language))
- ast_waitstream(conf->chan, "");
- }
- }
-
- if (confflags & CONFFLAG_MONITOR)
- ztc.confmode = ZT_CONF_CONFMON | ZT_CONF_LISTENER;
- else if (confflags & CONFFLAG_TALKER)
- ztc.confmode = ZT_CONF_CONF | ZT_CONF_TALKER;
- else
- ztc.confmode = ZT_CONF_CONF | ZT_CONF_TALKER | ZT_CONF_LISTENER;
-
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- ast_mutex_unlock(&conflock);
- goto outrun;
- }
- ast_log(LOG_DEBUG, "Placed channel %s in ZAP conf %d\n", chan->name, conf->zapconf);
-
- manager_event(EVENT_FLAG_CALL, "MeetmeJoin",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %d\r\n",
- chan->name, chan->uniqueid, conf->confno, user->user_no);
-
- if (!firstpass && !(confflags & CONFFLAG_MONITOR) && !(confflags & CONFFLAG_ADMIN)) {
- firstpass = 1;
- if (!(confflags & CONFFLAG_QUIET))
- if (!(confflags & CONFFLAG_WAITMARKED) || (conf->markedusers >= 1))
- conf_play(chan, conf, ENTER);
- }
-
- ast_mutex_unlock(&conflock);
-
- conf_flush(fd, chan);
-
- if (confflags & CONFFLAG_AGI) {
- /* Get name of AGI file to run from $(MEETME_AGI_BACKGROUND)
- or use default filename of conf-background.agi */
-
- agifile = pbx_builtin_getvar_helper(chan, "MEETME_AGI_BACKGROUND");
- if (!agifile)
- agifile = agifiledefault;
-
- if (user->zapchannel) {
- /* Set CONFMUTE mode on Zap channel to mute DTMF tones */
- x = 1;
- ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
- }
- /* Find a pointer to the agi app and execute the script */
- app = pbx_findapp("agi");
- if (app) {
- ret = pbx_exec(chan, app, agifile, 1);
- } else {
- ast_log(LOG_WARNING, "Could not find application (agi)\n");
- ret = -2;
- }
- if (user->zapchannel) {
- /* Remove CONFMUTE mode on Zap channel */
- x = 0;
- ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
- }
- } else {
- if (user->zapchannel && (confflags & CONFFLAG_STARMENU)) {
- /* Set CONFMUTE mode on Zap channel to mute DTMF tones when the menu is enabled */
- x = 1;
- ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
- }
- if (confflags & CONFFLAG_MONITORTALKER && !(dsp = ast_dsp_new())) {
- ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
- res = -1;
- }
- for(;;) {
- int menu_was_active = 0;
-
- outfd = -1;
- ms = -1;
-
- /* if we have just exited from the menu, and the user had a channel-driver
- volume adjustment, restore it
- */
- if (!menu_active && menu_was_active && user->listen.desired && !user->listen.actual)
- set_talk_volume(user, user->listen.desired);
-
- menu_was_active = menu_active;
-
- currentmarked = conf->markedusers;
- if (!(confflags & CONFFLAG_QUIET) &&
- (confflags & CONFFLAG_MARKEDUSER) &&
- (confflags & CONFFLAG_WAITMARKED) &&
- lastmarked == 0) {
- if (currentmarked == 1 && conf->users > 1) {
- ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
- if (conf->users - 1 == 1) {
- if (!ast_streamfile(chan, "conf-userwilljoin", chan->language))
- ast_waitstream(chan, "");
- } else {
- if (!ast_streamfile(chan, "conf-userswilljoin", chan->language))
- ast_waitstream(chan, "");
- }
- }
- if (conf->users == 1 && ! (confflags & CONFFLAG_MARKEDUSER))
- if (!ast_streamfile(chan, "conf-onlyperson", chan->language))
- ast_waitstream(chan, "");
- }
-
- c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
-
- /* Update the struct with the actual confflags */
- user->userflags = confflags;
-
- if (confflags & CONFFLAG_WAITMARKED) {
- if(currentmarked == 0) {
- if (lastmarked != 0) {
- if (!(confflags & CONFFLAG_QUIET))
- if (!ast_streamfile(chan, "conf-leaderhasleft", chan->language))
- ast_waitstream(chan, "");
- if(confflags & CONFFLAG_MARKEDEXIT)
- break;
- else {
- ztc.confmode = ZT_CONF_CONF;
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- goto outrun;
- }
- }
- }
- if (musiconhold == 0 && (confflags & CONFFLAG_MOH)) {
- ast_moh_start(chan, NULL);
- musiconhold = 1;
- } else {
- ztc.confmode = ZT_CONF_CONF;
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- goto outrun;
- }
- }
- } else if(currentmarked >= 1 && lastmarked == 0) {
- if (confflags & CONFFLAG_MONITOR)
- ztc.confmode = ZT_CONF_CONFMON | ZT_CONF_LISTENER;
- else if (confflags & CONFFLAG_TALKER)
- ztc.confmode = ZT_CONF_CONF | ZT_CONF_TALKER;
- else
- ztc.confmode = ZT_CONF_CONF | ZT_CONF_TALKER | ZT_CONF_LISTENER;
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- goto outrun;
- }
- if (musiconhold && (confflags & CONFFLAG_MOH)) {
- ast_moh_stop(chan);
- musiconhold = 0;
- }
- if ( !(confflags & CONFFLAG_QUIET) && !(confflags & CONFFLAG_MARKEDUSER)) {
- if (!ast_streamfile(chan, "conf-placeintoconf", chan->language))
- ast_waitstream(chan, "");
- conf_play(chan, conf, ENTER);
- }
- }
- }
-
- /* trying to add moh for single person conf */
- if ((confflags & CONFFLAG_MOH) && !(confflags & CONFFLAG_WAITMARKED)) {
- if (conf->users == 1) {
- if (musiconhold == 0) {
- ast_moh_start(chan, NULL);
- musiconhold = 1;
- }
- } else {
- if (musiconhold) {
- ast_moh_stop(chan);
- musiconhold = 0;
- }
- }
- }
-
- /* Leave if the last marked user left */
- if (currentmarked == 0 && lastmarked != 0 && (confflags & CONFFLAG_MARKEDEXIT)) {
- ret = -1;
- break;
- }
-
- /* Check if the admin changed my modes */
- if (user->adminflags) {
- /* Set the new modes */
- if ((user->adminflags & ADMINFLAG_MUTED) && (ztc.confmode & ZT_CONF_TALKER)) {
- ztc.confmode ^= ZT_CONF_TALKER;
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
- ret = -1;
- break;
- }
- }
- if (!(user->adminflags & ADMINFLAG_MUTED) && !(confflags & CONFFLAG_MONITOR) && !(ztc.confmode & ZT_CONF_TALKER)) {
- ztc.confmode |= ZT_CONF_TALKER;
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
- ret = -1;
- break;
- }
- }
- if (user->adminflags & ADMINFLAG_KICKME) {
- /* You have been kicked. */
- if (!ast_streamfile(chan, "conf-kicked", chan->language))
- ast_waitstream(chan, "");
- ret = 0;
- break;
- }
- } else if (!(confflags & CONFFLAG_MONITOR) && !(ztc.confmode & ZT_CONF_TALKER)) {
- ztc.confmode |= ZT_CONF_TALKER;
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
- ret = -1;
- break;
- }
- }
-
- if (c) {
- if (c->fds[0] != origfd) {
- if (using_pseudo) {
- /* Kill old pseudo */
- close(fd);
- using_pseudo = 0;
- }
- ast_log(LOG_DEBUG, "Ooh, something swapped out under us, starting over\n");
- retryzap = strcasecmp(c->type, "Zap");
- user->zapchannel = !retryzap;
- goto zapretry;
- }
- f = ast_read(c);
- if (!f)
- break;
- if ((f->frametype == AST_FRAME_VOICE) && (f->subclass == AST_FORMAT_SLINEAR)) {
- if (user->talk.actual)
- ast_frame_adjust_volume(f, user->talk.actual);
-
- if (confflags & CONFFLAG_MONITORTALKER) {
- int totalsilence;
-
- if (user->talking == -1)
- user->talking = 0;
-
- res = ast_dsp_silence(dsp, f, &totalsilence);
- if (!user->talking && totalsilence < MEETME_DELAYDETECTTALK) {
- user->talking = 1;
- manager_event(EVENT_FLAG_CALL, "MeetmeTalking",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %d\r\n",
- chan->name, chan->uniqueid, conf->confno, user->user_no);
- }
- if (user->talking && totalsilence > MEETME_DELAYDETECTENDTALK) {
- user->talking = 0;
- manager_event(EVENT_FLAG_CALL, "MeetmeStopTalking",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %d\r\n",
- chan->name, chan->uniqueid, conf->confno, user->user_no);
- }
- }
- if (using_pseudo) {
- /* Absolutely do _not_ use careful_write here...
- it is important that we read data from the channel
- as fast as it arrives, and feed it into the conference.
- The buffering in the pseudo channel will take care of any
- timing differences, unless they are so drastic as to lose
- audio frames (in which case carefully writing would only
- have delayed the audio even further).
- */
- /* As it turns out, we do want to use careful write. We just
- don't want to block, but we do want to at least *try*
- to write out all the samples.
- */
- careful_write(fd, f->data, f->datalen, 0);
- }
- } else if ((f->frametype == AST_FRAME_DTMF) && (confflags & CONFFLAG_EXIT_CONTEXT)) {
- char tmp[2];
-
- tmp[0] = f->subclass;
- tmp[1] = '\0';
- if (!ast_goto_if_exists(chan, exitcontext, tmp, 1)) {
- ret = 0;
- break;
- } else if (option_debug > 1)
- ast_log(LOG_DEBUG, "Exit by single digit did not work in meetme. Extension %s does not exist in context %s\n", tmp, exitcontext);
- } else if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#') && (confflags & CONFFLAG_POUNDEXIT)) {
- ret = 0;
- break;
- } else if (((f->frametype == AST_FRAME_DTMF) && (f->subclass == '*') && (confflags & CONFFLAG_STARMENU)) || ((f->frametype == AST_FRAME_DTMF) && menu_active)) {
- if (ioctl(fd, ZT_SETCONF, &ztc_empty)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- goto outrun;
- }
-
- /* if we are entering the menu, and the user has a channel-driver
- volume adjustment, clear it
- */
- if (!menu_active && user->talk.desired && !user->talk.actual)
- set_talk_volume(user, 0);
-
- if (musiconhold) {
- ast_moh_stop(chan);
- }
- if ((confflags & CONFFLAG_ADMIN)) {
- /* Admin menu */
- if (!menu_active) {
- menu_active = 1;
- /* Record this sound! */
- if (!ast_streamfile(chan, "conf-adminmenu", chan->language)) {
- dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- } else
- dtmf = 0;
- } else
- dtmf = f->subclass;
- if (dtmf) {
- switch(dtmf) {
- case '1': /* Un/Mute */
- menu_active = 0;
- if (ztc.confmode & ZT_CONF_TALKER) {
- ztc.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER;
- confflags |= CONFFLAG_MONITOR ^ CONFFLAG_TALKER;
- } else {
- ztc.confmode = ZT_CONF_CONF | ZT_CONF_TALKER | ZT_CONF_LISTENER;
- confflags ^= CONFFLAG_MONITOR | CONFFLAG_TALKER;
- }
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
- ret = -1;
- break;
- }
- if (ztc.confmode & ZT_CONF_TALKER) {
- if (!ast_streamfile(chan, "conf-unmuted", chan->language))
- ast_waitstream(chan, "");
- } else {
- if (!ast_streamfile(chan, "conf-muted", chan->language))
- ast_waitstream(chan, "");
- }
- break;
- case '2': /* Un/Lock the Conference */
- menu_active = 0;
- if (conf->locked) {
- conf->locked = 0;
- if (!ast_streamfile(chan, "conf-unlockednow", chan->language))
- ast_waitstream(chan, "");
- } else {
- conf->locked = 1;
- if (!ast_streamfile(chan, "conf-lockednow", chan->language))
- ast_waitstream(chan, "");
- }
- break;
- case '3': /* Eject last user */
- menu_active = 0;
- usr = conf->lastuser;
- if ((usr->chan->name == chan->name)||(usr->userflags & CONFFLAG_ADMIN)) {
- if(!ast_streamfile(chan, "conf-errormenu", chan->language))
- ast_waitstream(chan, "");
- } else
- usr->adminflags |= ADMINFLAG_KICKME;
- ast_stopstream(chan);
- break;
- case '4':
- tweak_listen_volume(user, VOL_DOWN);
- break;
- case '6':
- tweak_listen_volume(user, VOL_UP);
- break;
- case '7':
- tweak_talk_volume(user, VOL_DOWN);
- break;
- case '8':
- menu_active = 0;
- break;
- case '9':
- tweak_talk_volume(user, VOL_UP);
- break;
- default:
- menu_active = 0;
- /* Play an error message! */
- if (!ast_streamfile(chan, "conf-errormenu", chan->language))
- ast_waitstream(chan, "");
- break;
- }
- }
- } else {
- /* User menu */
- if (!menu_active) {
- menu_active = 1;
- if (!ast_streamfile(chan, "conf-usermenu", chan->language)) {
- dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- } else
- dtmf = 0;
- } else
- dtmf = f->subclass;
- if (dtmf) {
- switch(dtmf) {
- case '1': /* Un/Mute */
- menu_active = 0;
- if (ztc.confmode & ZT_CONF_TALKER) {
- ztc.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER;
- confflags |= CONFFLAG_MONITOR ^ CONFFLAG_TALKER;
- } else if (!(user->adminflags & ADMINFLAG_MUTED)) {
- ztc.confmode = ZT_CONF_CONF | ZT_CONF_TALKER | ZT_CONF_LISTENER;
- confflags ^= CONFFLAG_MONITOR | CONFFLAG_TALKER;
- }
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
- ret = -1;
- break;
- }
- if (ztc.confmode & ZT_CONF_TALKER) {
- if (!ast_streamfile(chan, "conf-unmuted", chan->language))
- ast_waitstream(chan, "");
- } else {
- if (!ast_streamfile(chan, "conf-muted", chan->language))
- ast_waitstream(chan, "");
- }
- break;
- case '4':
- tweak_listen_volume(user, VOL_DOWN);
- break;
- case '6':
- tweak_listen_volume(user, VOL_UP);
- break;
- case '7':
- tweak_talk_volume(user, VOL_DOWN);
- break;
- case '8':
- menu_active = 0;
- break;
- case '9':
- tweak_talk_volume(user, VOL_UP);
- break;
- default:
- menu_active = 0;
- if (!ast_streamfile(chan, "conf-errormenu", chan->language))
- ast_waitstream(chan, "");
- break;
- }
- }
- }
- if (musiconhold)
- ast_moh_start(chan, NULL);
-
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- ast_mutex_unlock(&conflock);
- goto outrun;
- }
-
- conf_flush(fd, chan);
- } else if (option_debug) {
- ast_log(LOG_DEBUG,
- "Got unrecognized frame on channel %s, f->frametype=%d,f->subclass=%d\n",
- chan->name, f->frametype, f->subclass);
- }
- ast_frfree(f);
- } else if (outfd > -1) {
- res = read(outfd, buf, CONF_SIZE);
- if (res > 0) {
- memset(&fr, 0, sizeof(fr));
- fr.frametype = AST_FRAME_VOICE;
- fr.subclass = AST_FORMAT_SLINEAR;
- fr.datalen = res;
- fr.samples = res/2;
- fr.data = buf;
- fr.offset = AST_FRIENDLY_OFFSET;
- if (user->listen.actual)
- ast_frame_adjust_volume(&fr, user->listen.actual);
- if (ast_write(chan, &fr) < 0) {
- ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
- }
- } else
- ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
- }
- lastmarked = currentmarked;
- }
- }
-
- if (musiconhold)
- ast_moh_stop(chan);
-
- if (using_pseudo)
- close(fd);
- else {
- /* Take out of conference */
- ztc.chan = 0;
- ztc.confno = 0;
- ztc.confmode = 0;
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- }
- }
-
- reset_volumes(user);
-
- ast_mutex_lock(&conflock);
- if (!(confflags & CONFFLAG_QUIET) && !(confflags & CONFFLAG_MONITOR) && !(confflags & CONFFLAG_ADMIN))
- conf_play(chan, conf, LEAVE);
-
- if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_INTROUSER)) {
- if (ast_fileexists(user->namerecloc, NULL, NULL)) {
- if ((conf->chan) && (conf->users > 1)) {
- if (!ast_streamfile(conf->chan, user->namerecloc, chan->language))
- ast_waitstream(conf->chan, "");
- if (!ast_streamfile(conf->chan, "conf-hasleft", chan->language))
- ast_waitstream(conf->chan, "");
- }
- ast_filedelete(user->namerecloc, NULL);
- }
- }
- ast_mutex_unlock(&conflock);
-
- outrun:
- ast_mutex_lock(&conflock);
-
- if (confflags & CONFFLAG_MONITORTALKER && dsp)
- ast_dsp_free(dsp);
-
- if (user->user_no) { /* Only cleanup users who really joined! */
- manager_event(EVENT_FLAG_CALL, "MeetmeLeave",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %d\r\n",
- chan->name, chan->uniqueid, conf->confno, user->user_no);
- conf->users--;
- if (confflags & CONFFLAG_MARKEDUSER)
- conf->markedusers--;
- if (!conf->users) {
- /* No more users -- close this one out */
- conf_free(conf);
- } else {
- /* Remove the user struct */
- if (user == conf->firstuser) {
- if (user->nextuser) {
- /* There is another entry */
- user->nextuser->prevuser = NULL;
- } else {
- /* We are the only entry */
- conf->lastuser = NULL;
- }
- /* In either case */
- conf->firstuser = user->nextuser;
- } else if (user == conf->lastuser){
- if (user->prevuser)
- user->prevuser->nextuser = NULL;
- else
- ast_log(LOG_ERROR, "Bad bad bad! We're the last, not the first, but nobody before us??\n");
- conf->lastuser = user->prevuser;
- } else {
- if (user->nextuser)
- user->nextuser->prevuser = user->prevuser;
- else
- ast_log(LOG_ERROR, "Bad! Bad! Bad! user->nextuser is NULL but we're not the end!\n");
- if (user->prevuser)
- user->prevuser->nextuser = user->nextuser;
- else
- ast_log(LOG_ERROR, "Bad! Bad! Bad! user->prevuser is NULL but we're not the beginning!\n");
- }
- }
- /* Return the number of seconds the user was in the conf */
- snprintf(meetmesecs, sizeof(meetmesecs), "%d", (int) (time(NULL) - user->jointime));
- pbx_builtin_setvar_helper(chan, "MEETMESECS", meetmesecs);
- }
- free(user);
- ast_mutex_unlock(&conflock);
-
- return ret;
-}
-
-static struct ast_conference *find_conf(struct ast_channel *chan, char *confno, int make, int dynamic, char *dynamic_pin)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
- struct ast_conference *cnf;
-
- /* Check first in the conference list */
- ast_mutex_lock(&conflock);
- for (cnf = confs; cnf; cnf = cnf->next) {
- if (!strcmp(confno, cnf->confno))
- break;
- }
- ast_mutex_unlock(&conflock);
-
- if (!cnf) {
- if (dynamic) {
- /* No need to parse meetme.conf */
- ast_log(LOG_DEBUG, "Building dynamic conference '%s'\n", confno);
- if (dynamic_pin) {
- if (dynamic_pin[0] == 'q') {
- /* Query the user to enter a PIN */
- if (ast_app_getdata(chan, "conf-getpin", dynamic_pin, AST_MAX_EXTENSION - 1, 0) < 0)
- return NULL;
- }
- cnf = build_conf(confno, dynamic_pin, "", make, dynamic);
- } else {
- cnf = build_conf(confno, "", "", make, dynamic);
- }
- } else {
- /* Check the config */
- cfg = ast_config_load(CONFIG_FILE_NAME);
- if (!cfg) {
- ast_log(LOG_WARNING, "No %s file :(\n", CONFIG_FILE_NAME);
- return NULL;
- }
- var = ast_variable_browse(cfg, "rooms");
- while (var) {
- if (!strcasecmp(var->name, "conf")) {
- /* Separate the PIN */
- char *pin, *pinadmin, *conf;
-
- if ((pinadmin = ast_strdupa(var->value))) {
- conf = strsep(&pinadmin, "|,");
- pin = strsep(&pinadmin, "|,");
- if (!strcasecmp(conf, confno)) {
- /* Bingo it's a valid conference */
- if (pin)
- if (pinadmin)
- cnf = build_conf(confno, pin, pinadmin, make, dynamic);
- else
- cnf = build_conf(confno, pin, "", make, dynamic);
- else
- if (pinadmin)
- cnf = build_conf(confno, "", pinadmin, make, dynamic);
- else
- cnf = build_conf(confno, "", "", make, dynamic);
- break;
- }
- }
- }
- var = var->next;
- }
- if (!var) {
- ast_log(LOG_DEBUG, "%s isn't a valid conference\n", confno);
- }
- ast_config_destroy(cfg);
- }
- } else if (dynamic_pin) {
- /* Correct for the user selecting 'D' instead of 'd' to have
- someone join into a conference that has already been created
- with a pin. */
- if (dynamic_pin[0] == 'q')
- dynamic_pin[0] = '\0';
- }
-
- return cnf;
-}
-
-/*--- count_exec: The MeetmeCount application */
-static int count_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- int res = 0;
- struct ast_conference *conf;
- int count;
- char *confnum, *localdata;
- char val[80] = "0";
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "MeetMeCount requires an argument (conference number)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- localdata = ast_strdupa(data);
- if (!localdata) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- confnum = strsep(&localdata,"|");
- conf = find_conf(chan, confnum, 0, 0, NULL);
- if (conf)
- count = conf->users;
- else
- count = 0;
-
- if (!ast_strlen_zero(localdata)){
- /* have var so load it and exit */
- snprintf(val, sizeof(val), "%d",count);
- pbx_builtin_setvar_helper(chan, localdata, val);
- } else {
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
- res = ast_say_number(chan, count, "", chan->language, (char *) NULL); /* Needs gender */
- }
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-/*--- conf_exec: The meetme() application */
-static int conf_exec(struct ast_channel *chan, void *data)
-{
- int res=-1;
- struct localuser *u;
- char confno[AST_MAX_EXTENSION] = "";
- int allowretry = 0;
- int retrycnt = 0;
- struct ast_conference *cnf;
- struct ast_flags confflags = {0};
- int dynamic = 0;
- int empty = 0, empty_no_pin = 0;
- int always_prompt = 0;
- char *notdata, *info, *inflags = NULL, *inpin = NULL, the_pin[AST_MAX_EXTENSION] = "";
-
- LOCAL_USER_ADD(u);
-
- if (ast_strlen_zero(data)) {
- allowretry = 1;
- notdata = "";
- } else {
- notdata = data;
- }
-
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
-
- info = ast_strdupa(notdata);
-
- if (info) {
- char *tmp = strsep(&info, "|");
- ast_copy_string(confno, tmp, sizeof(confno));
- if (ast_strlen_zero(confno)) {
- allowretry = 1;
- }
- }
- if (info)
- inflags = strsep(&info, "|");
- if (info)
- inpin = strsep(&info, "|");
- if (inpin)
- ast_copy_string(the_pin, inpin, sizeof(the_pin));
-
- if (inflags) {
- ast_app_parse_options(meetme_opts, &confflags, NULL, inflags);
- dynamic = ast_test_flag(&confflags, CONFFLAG_DYNAMIC | CONFFLAG_DYNAMICPIN);
- if (ast_test_flag(&confflags, CONFFLAG_DYNAMICPIN) && !inpin)
- strcpy(the_pin, "q");
-
- empty = ast_test_flag(&confflags, CONFFLAG_EMPTY | CONFFLAG_EMPTYNOPIN);
- empty_no_pin = ast_test_flag(&confflags, CONFFLAG_EMPTYNOPIN);
- always_prompt = ast_test_flag(&confflags, CONFFLAG_ALWAYSPROMPT);
- }
-
- do {
- if (retrycnt > 3)
- allowretry = 0;
- if (empty) {
- int i, map[1024] = { 0, };
- struct ast_config *cfg;
- struct ast_variable *var;
- int confno_int;
-
- ast_mutex_lock(&conflock);
- for (cnf = confs; cnf; cnf = cnf->next) {
- if (sscanf(cnf->confno, "%d", &confno_int) == 1) {
- /* Disqualify in use conference */
- if (confno_int >= 0 && confno_int < 1024)
- map[confno_int]++;
- }
- }
- ast_mutex_unlock(&conflock);
-
- /* We only need to load the config file for static and empty_no_pin (otherwise we don't care) */
- if ((empty_no_pin) || (!dynamic)) {
- cfg = ast_config_load(CONFIG_FILE_NAME);
- if (cfg) {
- var = ast_variable_browse(cfg, "rooms");
- while (var) {
- if (!strcasecmp(var->name, "conf")) {
- char *stringp = ast_strdupa(var->value);
- if (stringp) {
- char *confno_tmp = strsep(&stringp, "|,");
- int found = 0;
- if (sscanf(confno_tmp, "%d", &confno_int) == 1) {
- if ((confno_int >= 0) && (confno_int < 1024)) {
- if (stringp && empty_no_pin) {
- map[confno_int]++;
- }
- }
- }
- if (!dynamic) {
- /* For static: run through the list and see if this conference is empty */
- ast_mutex_lock(&conflock);
- cnf = confs;
- while (cnf) {
- if (!strcmp(confno_tmp, cnf->confno)) {
- /* The conference exists, therefore it's not empty */
- found = 1;
- break;
- }
- cnf = cnf->next;
- }
- ast_mutex_unlock(&conflock);
- if (!found) {
- /* At this point, we have a confno_tmp (static conference) that is empty */
- if ((empty_no_pin && ((!stringp) || (stringp && (stringp[0] == '\0')))) || (!empty_no_pin)) {
- /* Case 1: empty_no_pin and pin is nonexistent (NULL)
- * Case 2: empty_no_pin and pin is blank (but not NULL)
- * Case 3: not empty_no_pin
- */
- ast_copy_string(confno, confno_tmp, sizeof(confno));
- break;
- /* XXX the map is not complete (but we do have a confno) */
- }
- }
- }
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- }
- }
- var = var->next;
- }
- ast_config_destroy(cfg);
- }
- }
-
- /* Select first conference number not in use */
- if (ast_strlen_zero(confno) && dynamic) {
- for (i = 0; i < sizeof(map) / sizeof(map[0]); i++) {
- if (!map[i]) {
- snprintf(confno, sizeof(confno), "%d", i);
- break;
- }
- }
- }
-
- /* Not found? */
- if (ast_strlen_zero(confno)) {
- res = ast_streamfile(chan, "conf-noempty", chan->language);
- if (!res)
- ast_waitstream(chan, "");
- } else {
- if (sscanf(confno, "%d", &confno_int) == 1) {
- res = ast_streamfile(chan, "conf-enteringno", chan->language);
- if (!res) {
- ast_waitstream(chan, "");
- res = ast_say_digits(chan, confno_int, "", chan->language);
- }
- } else {
- ast_log(LOG_ERROR, "Could not scan confno '%s'\n", confno);
- }
- }
- }
-
- while (allowretry && (ast_strlen_zero(confno)) && (++retrycnt < 4)) {
- /* Prompt user for conference number */
- res = ast_app_getdata(chan, "conf-getconfno", confno, sizeof(confno) - 1, 0);
- if (res < 0) {
- /* Don't try to validate when we catch an error */
- confno[0] = '\0';
- allowretry = 0;
- break;
- }
- }
- if (!ast_strlen_zero(confno)) {
- /* Check the validity of the conference */
- cnf = find_conf(chan, confno, 1, dynamic, the_pin);
- if (!cnf) {
- res = ast_streamfile(chan, "conf-invalid", chan->language);
- if (!res)
- ast_waitstream(chan, "");
- res = -1;
- if (allowretry)
- confno[0] = '\0';
- } else {
- if ((!ast_strlen_zero(cnf->pin) &&
- !ast_test_flag(&confflags, CONFFLAG_ADMIN)) ||
- (!ast_strlen_zero(cnf->pinadmin) &&
- ast_test_flag(&confflags, CONFFLAG_ADMIN))) {
- char pin[AST_MAX_EXTENSION]="";
- int j;
-
- /* Allow the pin to be retried up to 3 times */
- for (j = 0; j < 3; j++) {
- if (*the_pin && (always_prompt == 0)) {
- ast_copy_string(pin, the_pin, sizeof(pin));
- res = 0;
- } else {
- /* Prompt user for pin if pin is required */
- res = ast_app_getdata(chan, "conf-getpin", pin + strlen(pin), sizeof(pin) - 1 - strlen(pin), 0);
- }
- if (res >= 0) {
- if (!strcasecmp(pin, cnf->pin) ||
- (!ast_strlen_zero(cnf->pinadmin) &&
- !strcasecmp(pin, cnf->pinadmin))) {
- /* Pin correct */
- allowretry = 0;
- if (!ast_strlen_zero(cnf->pinadmin) && !strcasecmp(pin, cnf->pinadmin))
- ast_set_flag(&confflags, CONFFLAG_ADMIN);
- /* Run the conference */
- res = conf_run(chan, cnf, confflags.flags);
- break;
- } else {
- /* Pin invalid */
- res = ast_streamfile(chan, "conf-invalidpin", chan->language);
- if (!res)
- ast_waitstream(chan, AST_DIGIT_ANY);
- if (res < 0)
- break;
- pin[0] = res;
- pin[1] = '\0';
- res = -1;
- if (allowretry)
- confno[0] = '\0';
- }
- } else {
- /* failed when getting the pin */
- res = -1;
- allowretry = 0;
- /* see if we need to get rid of the conference */
- ast_mutex_lock(&conflock);
- if (!cnf->users) {
- conf_free(cnf);
- }
- ast_mutex_unlock(&conflock);
- break;
- }
-
- /* Don't retry pin with a static pin */
- if (*the_pin && (always_prompt==0)) {
- break;
- }
- }
- } else {
- /* No pin required */
- allowretry = 0;
-
- /* Run the conference */
- res = conf_run(chan, cnf, confflags.flags);
- }
- }
- }
- } while (allowretry);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-static struct ast_conf_user* find_user(struct ast_conference *conf, char *callerident) {
- struct ast_conf_user *user = NULL;
- char usrno[1024] = "";
-
- if (conf && callerident) {
- user = conf->firstuser;
- while (user) {
- snprintf(usrno, sizeof(usrno), "%d", user->user_no);
- if (strcmp(usrno, callerident) == 0)
- return user;
- user = user->nextuser;
- }
- }
- return NULL;
-}
-
-/*--- admin_exec: The MeetMeadmin application */
-/* MeetMeAdmin(confno, command, caller) */
-static int admin_exec(struct ast_channel *chan, void *data) {
- char *params, *command = NULL, *caller = NULL, *conf = NULL;
- struct ast_conference *cnf;
- struct ast_conf_user *user = NULL;
- struct localuser *u;
-
- LOCAL_USER_ADD(u);
-
- ast_mutex_lock(&conflock);
- /* The param has the conference number the user and the command to execute */
- if (!ast_strlen_zero(data)) {
- params = ast_strdupa((char *) data);
- conf = strsep(&params, "|");
- command = strsep(&params, "|");
- caller = strsep(&params, "|");
-
- if (!command) {
- ast_log(LOG_WARNING, "MeetmeAdmin requires a command!\n");
- ast_mutex_unlock(&conflock);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- for (cnf = confs; cnf; cnf = cnf->next) {
- if (!strcmp(cnf->confno, conf))
- break;
- }
-
- if (caller)
- user = find_user(cnf, caller);
-
- if (cnf) {
- switch((int) (*command)) {
- case 76: /* L: Lock */
- cnf->locked = 1;
- break;
- case 108: /* l: Unlock */
- cnf->locked = 0;
- break;
- case 75: /* K: kick all users*/
- user = cnf->firstuser;
- while(user) {
- user->adminflags |= ADMINFLAG_KICKME;
- if (user->nextuser) {
- user = user->nextuser;
- } else {
- break;
- }
- }
- break;
- case 101: /* e: Eject last user*/
- user = cnf->lastuser;
- if (!(user->userflags & CONFFLAG_ADMIN)) {
- user->adminflags |= ADMINFLAG_KICKME;
- break;
- } else
- ast_log(LOG_NOTICE, "Not kicking last user, is an Admin!\n");
- break;
- case 77: /* M: Mute */
- if (user) {
- user->adminflags |= ADMINFLAG_MUTED;
- } else {
- ast_log(LOG_NOTICE, "Specified User not found!\n");
- }
- break;
- case 78: /* N: Mute all users */
- user = cnf->firstuser;
- while(user) {
- if (user && !(user->userflags & CONFFLAG_ADMIN))
- user->adminflags |= ADMINFLAG_MUTED;
- if (user->nextuser) {
- user = user->nextuser;
- } else {
- break;
- }
- }
- break;
- case 109: /* m: Unmute */
- if (user && (user->adminflags & ADMINFLAG_MUTED)) {
- user->adminflags ^= ADMINFLAG_MUTED;
- } else {
- ast_log(LOG_NOTICE, "Specified User not found or he muted himself!");
- }
- break;
- case 110: /* n: Unmute all users */
- user = cnf->firstuser;
- while(user) {
- if (user && (user-> adminflags & ADMINFLAG_MUTED)) {
- user->adminflags ^= ADMINFLAG_MUTED;
- }
- if (user->nextuser) {
- user = user->nextuser;
- } else {
- break;
- }
- }
- break;
- case 107: /* k: Kick user */
- if (user) {
- user->adminflags |= ADMINFLAG_KICKME;
- } else {
- ast_log(LOG_NOTICE, "Specified User not found!");
- }
- break;
- }
- } else {
- ast_log(LOG_NOTICE, "Conference Number not found\n");
- }
- }
- ast_mutex_unlock(&conflock);
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-static void *recordthread(void *args)
-{
- struct ast_conference *cnf = args;
- struct ast_frame *f=NULL;
- int flags;
- struct ast_filestream *s;
- int res=0;
-
- if (!cnf || !cnf->chan) {
- pthread_exit(0);
- }
- ast_stopstream(cnf->chan);
- flags = O_CREAT|O_TRUNC|O_WRONLY;
- s = ast_writefile(cnf->recordingfilename, cnf->recordingformat, NULL, flags, 0, 0644);
-
- if (s) {
- cnf->recording = MEETME_RECORD_ACTIVE;
- while (ast_waitfor(cnf->chan, -1) > -1) {
- f = ast_read(cnf->chan);
- if (!f) {
- res = -1;
- break;
- }
- if (f->frametype == AST_FRAME_VOICE) {
- res = ast_writestream(s, f);
- if (res)
- break;
- }
- ast_frfree(f);
- if (cnf->recording == MEETME_RECORD_TERMINATE) {
- ast_mutex_lock(&conflock);
- ast_mutex_unlock(&conflock);
- break;
- }
- }
- cnf->recording = MEETME_RECORD_OFF;
- ast_closestream(s);
- }
- pthread_exit(0);
-}
-
-static void load_config(void)
-{
- struct ast_config *cfg;
- char *val;
-
- audio_buffers = DEFAULT_AUDIO_BUFFERS;
-
- if (!(cfg = ast_config_load(CONFIG_FILE_NAME)))
- return;
-
- if ((val = ast_variable_retrieve(cfg, "general", "audiobuffers"))) {
- if ((sscanf(val, "%d", &audio_buffers) != 1)) {
- ast_log(LOG_WARNING, "audiobuffers setting must be a number, not '%s'\n", val);
- audio_buffers = DEFAULT_AUDIO_BUFFERS;
- } else if ((audio_buffers < ZT_DEFAULT_NUM_BUFS) || (audio_buffers > ZT_MAX_NUM_BUFS)) {
- ast_log(LOG_WARNING, "audiobuffers setting must be between %d and %d\n",
- ZT_DEFAULT_NUM_BUFS, ZT_MAX_NUM_BUFS);
- audio_buffers = DEFAULT_AUDIO_BUFFERS;
- }
- if (audio_buffers != DEFAULT_AUDIO_BUFFERS)
- ast_log(LOG_NOTICE, "Audio buffers per channel set to %d\n", audio_buffers);
- }
-
- ast_config_destroy(cfg);
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_cli_unregister(&cli_show_confs);
- res |= ast_cli_unregister(&cli_conf);
- res |= ast_unregister_application(app3);
- res |= ast_unregister_application(app2);
- res |= ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- load_config();
-
- res = ast_cli_register(&cli_show_confs);
- res |= ast_cli_register(&cli_conf);
- res |= ast_register_application(app3, admin_exec, synopsis3, descrip3);
- res |= ast_register_application(app2, count_exec, synopsis2, descrip2);
- res |= ast_register_application(app, conf_exec, synopsis, descrip);
-
- return res;
-}
-
-int reload(void)
-{
- load_config();
-
- return 0;
-}
-
-char *description(void)
-{
- return (char *) tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
-
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_milliwatt.c b/1.2-netsec/apps/app_milliwatt.c
deleted file mode 100644
index 9c46689f4..000000000
--- a/1.2-netsec/apps/app_milliwatt.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Digital Milliwatt Test
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-
-static char *tdesc = "Digital Milliwatt (mu-law) Test Application";
-
-static char *app = "Milliwatt";
-
-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";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static char digital_milliwatt[] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} ;
-
-static void *milliwatt_alloc(struct ast_channel *chan, void *params)
-{
-int *indexp;
- indexp = malloc(sizeof(int));
- if (indexp == NULL) return(NULL);
- *indexp = 0;
- return(indexp);
-}
-
-static void milliwatt_release(struct ast_channel *chan, void *data)
-{
- free(data);
- return;
-}
-
-static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int samples)
-{
- struct ast_frame wf;
- unsigned char buf[AST_FRIENDLY_OFFSET + 640];
- int i,*indexp = (int *) data;
-
- if (len + AST_FRIENDLY_OFFSET > sizeof(buf))
- {
- ast_log(LOG_WARNING,"Only doing %d bytes (%d bytes requested)\n",(int)(sizeof(buf) - AST_FRIENDLY_OFFSET),len);
- len = sizeof(buf) - AST_FRIENDLY_OFFSET;
- }
- wf.frametype = AST_FRAME_VOICE;
- wf.subclass = AST_FORMAT_ULAW;
- wf.offset = AST_FRIENDLY_OFFSET;
- wf.mallocd = 0;
- wf.data = buf + AST_FRIENDLY_OFFSET;
- wf.datalen = len;
- wf.samples = wf.datalen;
- wf.src = "app_milliwatt";
- wf.delivery.tv_sec = 0;
- wf.delivery.tv_usec = 0;
- wf.prev = wf.next = NULL;
- /* create a buffer containing the digital milliwatt pattern */
- for(i = 0; i < len; i++)
- {
- buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++];
- *indexp &= 7;
- }
- if (ast_write(chan,&wf) < 0)
- {
- ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",chan->name,strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static struct ast_generator milliwattgen =
-{
- alloc: milliwatt_alloc,
- release: milliwatt_release,
- generate: milliwatt_generate,
-} ;
-
-static int milliwatt_exec(struct ast_channel *chan, void *data)
-{
-
- struct localuser *u;
- LOCAL_USER_ADD(u);
- ast_set_write_format(chan, AST_FORMAT_ULAW);
- ast_set_read_format(chan, AST_FORMAT_ULAW);
- if (chan->_state != AST_STATE_UP)
- {
- ast_answer(chan);
- }
- 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);
- return -1;
- }
- while(!ast_safe_sleep(chan, 10000));
- ast_deactivate_generator(chan);
- LOCAL_USER_REMOVE(u);
- return -1;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, milliwatt_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_mixmonitor.c b/1.2-netsec/apps/app_mixmonitor.c
deleted file mode 100644
index 1c3b49d99..000000000
--- a/1.2-netsec/apps/app_mixmonitor.c
+++ /dev/null
@@ -1,466 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Anthony Minessale II
- * Copyright (C) 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- * Kevin P. Fleming <kpfleming@digium.com>
- *
- * Based on app_muxmon.c provided by
- * Anthony Minessale II <anthmct@yahoo.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief MixMonitor() - Record a call and mix the audio during the recording
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/chanspy.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/cli.h"
-#include "asterisk/options.h"
-#include "asterisk/app.h"
-#include "asterisk/linkedlists.h"
-
-#define get_volfactor(x) x ? ((x > 0) ? (1 << x) : ((1 << abs(x)) * -1)) : 0
-
-static const char *tdesc = "Mixed Audio Monitoring Application";
-static const char *app = "MixMonitor";
-static const char *synopsis = "Record a call and mix the audio during the recording";
-static const char *desc = ""
-" MixMonitor(<file>.<ext>[|<options>[|<command>]])\n\n"
-"Records the audio on the current channel to the specified file.\n"
-"If the filename is an absolute path, uses that path, otherwise\n"
-"creates the file in the configured monitoring directory from\n"
-"asterisk.conf.\n\n"
-"Valid options:\n"
-" a - Append to the file instead of overwriting it.\n"
-" b - Only save audio to the file while the channel is bridged.\n"
-" Note: does not include conferences.\n"
-" v(<x>) - Adjust the heard volume by a factor of <x> (range -4 to 4)\n"
-" V(<x>) - Adjust the spoken volume by a factor of <x> (range -4 to 4)\n"
-" W(<x>) - Adjust the both heard and spoken volumes by a factor of <x>\n"
-" (range -4 to 4)\n\n"
-"<command> will be executed when the recording is over\n"
-"Any strings matching ^{X} will be unescaped to ${X} and \n"
-"all variables will be evaluated at that time.\n"
-"The variable MIXMONITOR_FILENAME will contain the filename used to record.\n"
-"";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static const char *mixmonitor_spy_type = "MixMonitor";
-
-struct mixmonitor {
- struct ast_channel *chan;
- char *filename;
- char *post_process;
- unsigned int flags;
- int readvol;
- int writevol;
-};
-
-enum {
- MUXFLAG_APPEND = (1 << 1),
- MUXFLAG_BRIDGED = (1 << 2),
- MUXFLAG_VOLUME = (1 << 3),
- MUXFLAG_READVOLUME = (1 << 4),
- MUXFLAG_WRITEVOLUME = (1 << 5),
-} mixmonitor_flags;
-
-enum {
- OPT_ARG_READVOLUME = 0,
- OPT_ARG_WRITEVOLUME,
- OPT_ARG_VOLUME,
- OPT_ARG_ARRAY_SIZE,
-} mixmonitor_args;
-
-AST_APP_OPTIONS(mixmonitor_opts, {
- AST_APP_OPTION('a', MUXFLAG_APPEND),
- AST_APP_OPTION('b', MUXFLAG_BRIDGED),
- AST_APP_OPTION_ARG('v', MUXFLAG_READVOLUME, OPT_ARG_READVOLUME),
- AST_APP_OPTION_ARG('V', MUXFLAG_WRITEVOLUME, OPT_ARG_WRITEVOLUME),
- AST_APP_OPTION_ARG('W', MUXFLAG_VOLUME, OPT_ARG_VOLUME),
-});
-
-static void stopmon(struct ast_channel *chan, struct ast_channel_spy *spy)
-{
- /* If our status has changed to DONE, then the channel we're spying on is gone....
- DON'T TOUCH IT!!! RUN AWAY!!! */
- if (spy->status == CHANSPY_DONE)
- return;
-
- if (!chan)
- return;
-
- ast_mutex_lock(&chan->lock);
- ast_channel_spy_remove(chan, spy);
- ast_mutex_unlock(&chan->lock);
-}
-
-static int startmon(struct ast_channel *chan, struct ast_channel_spy *spy)
-{
- struct ast_channel *peer;
- int res;
-
- if (!chan)
- return -1;
-
- ast_mutex_lock(&chan->lock);
- res = ast_channel_spy_add(chan, spy);
- ast_mutex_unlock(&chan->lock);
-
- if (!res && ast_test_flag(chan, AST_FLAG_NBRIDGE) && (peer = ast_bridged_channel(chan)))
- ast_softhangup(peer, AST_SOFTHANGUP_UNBRIDGE);
-
- return res;
-}
-
-#define SAMPLES_PER_FRAME 160
-
-static void *mixmonitor_thread(void *obj)
-{
- struct mixmonitor *mixmonitor = obj;
- struct ast_channel_spy spy;
- struct ast_filestream *fs = NULL;
- char *ext, *name;
- unsigned int oflags;
- struct ast_frame *f;
- char post_process[1024] = "";
-
- STANDARD_INCREMENT_USECOUNT;
-
- name = ast_strdupa(mixmonitor->chan->name);
-
- oflags = O_CREAT|O_WRONLY;
- oflags |= ast_test_flag(mixmonitor, MUXFLAG_APPEND) ? O_APPEND : O_TRUNC;
-
- if ((ext = strrchr(mixmonitor->filename, '.'))) {
- *(ext++) = '\0';
- } else {
- ext = "raw";
- }
-
- fs = ast_writefile(mixmonitor->filename, ext, NULL, oflags, 0, 0644);
- if (!fs) {
- ast_log(LOG_ERROR, "Cannot open %s.%s\n", mixmonitor->filename, ext);
- goto out;
- }
-
- if (ast_test_flag(mixmonitor, MUXFLAG_APPEND))
- ast_seekstream(fs, 0, SEEK_END);
-
- memset(&spy, 0, sizeof(spy));
- ast_set_flag(&spy, CHANSPY_FORMAT_AUDIO);
- ast_set_flag(&spy, CHANSPY_MIXAUDIO);
- spy.type = mixmonitor_spy_type;
- spy.status = CHANSPY_RUNNING;
- spy.read_queue.format = AST_FORMAT_SLINEAR;
- spy.write_queue.format = AST_FORMAT_SLINEAR;
- if (mixmonitor->readvol) {
- ast_set_flag(&spy, CHANSPY_READ_VOLADJUST);
- spy.read_vol_adjustment = mixmonitor->readvol;
- }
- if (mixmonitor->writevol) {
- ast_set_flag(&spy, CHANSPY_WRITE_VOLADJUST);
- spy.write_vol_adjustment = mixmonitor->writevol;
- }
- ast_mutex_init(&spy.lock);
-
- if (startmon(mixmonitor->chan, &spy)) {
- ast_log(LOG_WARNING, "Unable to add '%s' spy to channel '%s'\n",
- spy.type, mixmonitor->chan->name);
- goto out2;
- }
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Begin MixMonitor Recording %s\n", name);
-
- while (1) {
- struct ast_frame *next;
- int write;
-
- ast_mutex_lock(&spy.lock);
-
- ast_channel_spy_trigger_wait(&spy);
-
- if (ast_check_hangup(mixmonitor->chan) || spy.status != CHANSPY_RUNNING) {
- ast_mutex_unlock(&spy.lock);
- break;
- }
-
- while (1) {
- if (!(f = ast_channel_spy_read_frame(&spy, SAMPLES_PER_FRAME)))
- break;
-
- write = (!ast_test_flag(mixmonitor, MUXFLAG_BRIDGED) ||
- ast_bridged_channel(mixmonitor->chan));
-
- /* it is possible for ast_channel_spy_read_frame() to return a chain
- of frames if a queue flush was necessary, so process them
- */
- for (; f; f = next) {
- next = f->next;
- if (write)
- ast_writestream(fs, f);
- ast_frfree(f);
- }
- }
-
- ast_mutex_unlock(&spy.lock);
- }
-
- if (mixmonitor->post_process) {
- char *p;
-
- for (p = mixmonitor->post_process; *p ; p++) {
- if (*p == '^' && *(p+1) == '{') {
- *p = '$';
- }
- }
- pbx_substitute_variables_helper(mixmonitor->chan, mixmonitor->post_process, post_process, sizeof(post_process) - 1);
- }
-
- stopmon(mixmonitor->chan, &spy);
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "End MixMonitor Recording %s\n", name);
-
- if (!ast_strlen_zero(post_process)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_2 "Executing [%s]\n", post_process);
- ast_safe_system(post_process);
- }
-
-out2:
- ast_mutex_destroy(&spy.lock);
-
- if (fs)
- ast_closestream(fs);
-
-out:
- free(mixmonitor);
-
- STANDARD_DECREMENT_USECOUNT;
-
- return NULL;
-}
-
-static void launch_monitor_thread(struct ast_channel *chan, const char *filename, unsigned int flags,
- int readvol, int writevol, const char *post_process)
-{
- pthread_attr_t attr;
- pthread_t thread;
- struct mixmonitor *mixmonitor;
- int len;
-
- len = sizeof(*mixmonitor) + strlen(filename) + 1;
- if (!ast_strlen_zero(post_process))
- len += strlen(post_process) + 1;
-
- if (!(mixmonitor = calloc(1, len))) {
- ast_log(LOG_ERROR, "Memory Error!\n");
- return;
- }
-
- mixmonitor->chan = chan;
- mixmonitor->filename = (char *) mixmonitor + sizeof(*mixmonitor);
- strcpy(mixmonitor->filename, filename);
- if (!ast_strlen_zero(post_process)) {
- mixmonitor->post_process = mixmonitor->filename + strlen(filename) + 1;
- strcpy(mixmonitor->post_process, post_process);
- }
- mixmonitor->readvol = readvol;
- mixmonitor->writevol = writevol;
- mixmonitor->flags = flags;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&thread, &attr, mixmonitor_thread, mixmonitor);
- pthread_attr_destroy(&attr);
-}
-
-static int mixmonitor_exec(struct ast_channel *chan, void *data)
-{
- int x, readvol = 0, writevol = 0;
- struct localuser *u;
- struct ast_flags flags = {0};
- char *parse;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(filename);
- AST_APP_ARG(options);
- AST_APP_ARG(post_process);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "MixMonitor requires an argument (filename)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (ast_strlen_zero(args.filename)) {
- ast_log(LOG_WARNING, "MixMonitor requires an argument (filename)\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (args.options) {
- char *opts[OPT_ARG_ARRAY_SIZE] = { NULL, };
-
- ast_app_parse_options(mixmonitor_opts, &flags, opts, args.options);
-
- if (ast_test_flag(&flags, MUXFLAG_READVOLUME)) {
- if (ast_strlen_zero(opts[OPT_ARG_READVOLUME])) {
- ast_log(LOG_WARNING, "No volume level was provided for the heard volume ('v') option.\n");
- } else if ((sscanf(opts[OPT_ARG_READVOLUME], "%d", &x) != 1) || (x < -4) || (x > 4)) {
- ast_log(LOG_NOTICE, "Heard volume must be a number between -4 and 4, not '%s'\n", opts[OPT_ARG_READVOLUME]);
- } else {
- readvol = get_volfactor(x);
- }
- }
-
- if (ast_test_flag(&flags, MUXFLAG_WRITEVOLUME)) {
- if (ast_strlen_zero(opts[OPT_ARG_WRITEVOLUME])) {
- ast_log(LOG_WARNING, "No volume level was provided for the spoken volume ('V') option.\n");
- } else if ((sscanf(opts[OPT_ARG_WRITEVOLUME], "%d", &x) != 1) || (x < -4) || (x > 4)) {
- ast_log(LOG_NOTICE, "Spoken volume must be a number between -4 and 4, not '%s'\n", opts[OPT_ARG_WRITEVOLUME]);
- } else {
- writevol = get_volfactor(x);
- }
- }
-
- if (ast_test_flag(&flags, MUXFLAG_VOLUME)) {
- if (ast_strlen_zero(opts[OPT_ARG_VOLUME])) {
- ast_log(LOG_WARNING, "No volume level was provided for the combined volume ('W') option.\n");
- } else if ((sscanf(opts[OPT_ARG_VOLUME], "%d", &x) != 1) || (x < -4) || (x > 4)) {
- ast_log(LOG_NOTICE, "Combined volume must be a number between -4 and 4, not '%s'\n", opts[OPT_ARG_VOLUME]);
- } else {
- readvol = writevol = get_volfactor(x);
- }
- }
- }
-
- /* if not provided an absolute path, use the system-configured monitoring directory */
- if (args.filename[0] != '/') {
- char *build;
-
- build = alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(args.filename) + 3);
- sprintf(build, "%s/%s", ast_config_AST_MONITOR_DIR, args.filename);
- args.filename = build;
- }
-
- 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);
-
- return 0;
-}
-
-static int mixmonitor_cli(int fd, int argc, char **argv)
-{
- struct ast_channel *chan;
-
- if (argc < 3)
- return RESULT_SHOWUSAGE;
-
- if (!(chan = ast_get_channel_by_name_prefix_locked(argv[2], strlen(argv[2])))) {
- ast_cli(fd, "No channel matching '%s' found.\n", argv[2]);
- return RESULT_SUCCESS;
- }
-
- if (!strcasecmp(argv[1], "start"))
- mixmonitor_exec(chan, argv[3]);
- else if (!strcasecmp(argv[1], "stop"))
- ast_channel_spy_stop_by_type(chan, mixmonitor_spy_type);
-
- ast_mutex_unlock(&chan->lock);
-
- return RESULT_SUCCESS;
-}
-
-
-static struct ast_cli_entry cli_mixmonitor = {
- { "mixmonitor", NULL, NULL },
- mixmonitor_cli,
- "Execute a MixMonitor command",
- "mixmonitor <start|stop> <chan_name> [<args>]\n"
-};
-
-
-int unload_module(void)
-{
- int res;
-
- res = ast_cli_unregister(&cli_mixmonitor);
- res |= ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_cli_register(&cli_mixmonitor);
- res |= ast_register_application(app, mixmonitor_exec, synopsis, desc);
-
- return res;
-}
-
-char *description(void)
-{
- return (char *) tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
-
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_mp3.c b/1.2-netsec/apps/app_mp3.c
deleted file mode 100644
index ee78840ec..000000000
--- a/1.2-netsec/apps/app_mp3.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Silly application to play an MP3 file -- uses mpg123
- *
- * \ingroup applications
- */
-
-#include <string.h>
-#include <stdio.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/time.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/frame.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-
-#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";
-
-static char *descrip =
-" MP3Player(location) Executes mpg123 to play the given location,\n"
-"which typically would be a filename or a URL. User can exit by pressing\n"
-"any key on the dialpad, or by hanging up.";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int mp3play(char *filename, int fd)
-{
- int res;
- int x;
- res = fork();
- if (res < 0)
- ast_log(LOG_WARNING, "Fork failed\n");
- if (res)
- return res;
- dup2(fd, STDOUT_FILENO);
- for (x=0;x<256;x++) {
- if (x != STDOUT_FILENO)
- close(x);
- }
- /* Execute mpg123, but buffer if it's a net connection */
- if (!strncasecmp(filename, "http://", 7)) {
- /* Most commonly installed in /usr/local/bin */
- execl(LOCAL_MPG_123, "mpg123", "-q", "-s", "-b", "1024", "-f", "8192", "--mono", "-r", "8000", filename, (char *)NULL);
- /* But many places has it in /usr/bin */
- execl(MPG_123, "mpg123", "-q", "-s", "-b", "1024","-f", "8192", "--mono", "-r", "8000", filename, (char *)NULL);
- /* As a last-ditch effort, try to use PATH */
- execlp("mpg123", "mpg123", "-q", "-s", "-b", "1024", "-f", "8192", "--mono", "-r", "8000", filename, (char *)NULL);
- }
- else {
- /* Most commonly installed in /usr/local/bin */
- execl(MPG_123, "mpg123", "-q", "-s", "-f", "8192", "--mono", "-r", "8000", filename, (char *)NULL);
- /* But many places has it in /usr/bin */
- execl(LOCAL_MPG_123, "mpg123", "-q", "-s", "-f", "8192", "--mono", "-r", "8000", filename, (char *)NULL);
- /* As a last-ditch effort, try to use PATH */
- execlp("mpg123", "mpg123", "-q", "-s", "-f", "8192", "--mono", "-r", "8000", filename, (char *)NULL);
- }
- ast_log(LOG_WARNING, "Execute of mpg123 failed\n");
- return -1;
-}
-
-static int timed_read(int fd, void *data, int datalen, int timeout)
-{
- int res;
- struct pollfd fds[1];
- fds[0].fd = fd;
- fds[0].events = POLLIN;
- res = poll(fds, 1, timeout);
- if (res < 1) {
- ast_log(LOG_NOTICE, "Poll timed out/errored out with %d\n", res);
- return -1;
- }
- return read(fd, data, datalen);
-
-}
-
-static int mp3_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- int fds[2];
- int ms = -1;
- int pid = -1;
- int owriteformat;
- int timeout = 2000;
- struct timeval next;
- struct ast_frame *f;
- struct myframe {
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET];
- short frdata[160];
- } myf;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "MP3 Playback requires an argument (filename)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (pipe(fds)) {
- ast_log(LOG_WARNING, "Unable to create pipe\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- ast_stopstream(chan);
-
- owriteformat = chan->writeformat;
- 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);
- return -1;
- }
-
- res = mp3play((char *)data, fds[1]);
- if (!strncasecmp((char *)data, "http://", 7)) {
- timeout = 10000;
- }
- /* Wait 1000 ms first */
- next = ast_tvnow();
- next.tv_sec += 1;
- if (res >= 0) {
- pid = res;
- /* Order is important -- there's almost always going to be mp3... we want to prioritize the
- user */
- for (;;) {
- ms = ast_tvdiff_ms(next, ast_tvnow());
- if (ms <= 0) {
- res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata), timeout);
- if (res > 0) {
- myf.f.frametype = AST_FRAME_VOICE;
- myf.f.subclass = AST_FORMAT_SLINEAR;
- myf.f.datalen = res;
- myf.f.samples = res / 2;
- myf.f.mallocd = 0;
- myf.f.offset = AST_FRIENDLY_OFFSET;
- myf.f.src = __PRETTY_FUNCTION__;
- myf.f.delivery.tv_sec = 0;
- myf.f.delivery.tv_usec = 0;
- myf.f.data = myf.frdata;
- if (ast_write(chan, &myf.f) < 0) {
- res = -1;
- break;
- }
- } else {
- ast_log(LOG_DEBUG, "No more mp3\n");
- res = 0;
- break;
- }
- next = ast_tvadd(next, ast_samp2tv(myf.f.samples, 8000));
- } else {
- ms = ast_waitfor(chan, ms);
- if (ms < 0) {
- ast_log(LOG_DEBUG, "Hangup detected\n");
- res = -1;
- break;
- }
- if (ms) {
- f = ast_read(chan);
- if (!f) {
- ast_log(LOG_DEBUG, "Null frame == hangup() detected\n");
- res = -1;
- break;
- }
- if (f->frametype == AST_FRAME_DTMF) {
- ast_log(LOG_DEBUG, "User pressed a key\n");
- ast_frfree(f);
- res = 0;
- break;
- }
- ast_frfree(f);
- }
- }
- }
- }
- close(fds[0]);
- close(fds[1]);
-
- if (pid > -1)
- kill(pid, SIGKILL);
- if (!res && owriteformat)
- ast_set_write_format(chan, owriteformat);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, mp3_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_nbscat.c b/1.2-netsec/apps/app_nbscat.c
deleted file mode 100644
index e1fb921c4..000000000
--- a/1.2-netsec/apps/app_nbscat.c
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Silly application to play an NBScat file -- uses nbscat8k
- *
- * \ingroup applications
- */
-
-#include <string.h>
-#include <stdio.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/frame.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-
-#define LOCAL_NBSCAT "/usr/local/bin/nbscat8k"
-#define NBSCAT "/usr/bin/nbscat8k"
-
-#ifndef AF_LOCAL
-#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";
-
-static char *descrip =
-" NBScat: Executes nbscat to listen to the local NBS stream.\n"
-"User can exit by pressing any key\n.";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int NBScatplay(int fd)
-{
- int res;
- int x;
- res = fork();
- if (res < 0)
- ast_log(LOG_WARNING, "Fork failed\n");
- if (res)
- return res;
- dup2(fd, STDOUT_FILENO);
- for (x=0;x<256;x++) {
- if (x != STDOUT_FILENO)
- close(x);
- }
- /* Most commonly installed in /usr/local/bin */
- execl(NBSCAT, "nbscat8k", "-d", (char *)NULL);
- execl(LOCAL_NBSCAT, "nbscat8k", "-d", (char *)NULL);
- ast_log(LOG_WARNING, "Execute of nbscat8k failed\n");
- return -1;
-}
-
-static int timed_read(int fd, void *data, int datalen)
-{
- int res;
- struct pollfd fds[1];
- fds[0].fd = fd;
- fds[0].events = POLLIN;
- res = poll(fds, 1, 2000);
- if (res < 1) {
- ast_log(LOG_NOTICE, "Selected timed out/errored out with %d\n", res);
- return -1;
- }
- return read(fd, data, datalen);
-
-}
-
-static int NBScat_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- int fds[2];
- int ms = -1;
- int pid = -1;
- int owriteformat;
- struct timeval next;
- struct ast_frame *f;
- struct myframe {
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET];
- short frdata[160];
- } myf;
-
- LOCAL_USER_ADD(u);
-
- if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds)) {
- ast_log(LOG_WARNING, "Unable to create socketpair\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- ast_stopstream(chan);
-
- owriteformat = chan->writeformat;
- 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);
- return -1;
- }
-
- res = NBScatplay(fds[1]);
- /* Wait 1000 ms first */
- next = ast_tvnow();
- next.tv_sec += 1;
- if (res >= 0) {
- pid = res;
- /* Order is important -- there's almost always going to be mp3... we want to prioritize the
- user */
- for (;;) {
- ms = ast_tvdiff_ms(next, ast_tvnow());
- if (ms <= 0) {
- res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata));
- if (res > 0) {
- myf.f.frametype = AST_FRAME_VOICE;
- myf.f.subclass = AST_FORMAT_SLINEAR;
- myf.f.datalen = res;
- myf.f.samples = res / 2;
- myf.f.mallocd = 0;
- myf.f.offset = AST_FRIENDLY_OFFSET;
- myf.f.src = __PRETTY_FUNCTION__;
- myf.f.delivery.tv_sec = 0;
- myf.f.delivery.tv_usec = 0;
- myf.f.data = myf.frdata;
- if (ast_write(chan, &myf.f) < 0) {
- res = -1;
- break;
- }
- } else {
- ast_log(LOG_DEBUG, "No more mp3\n");
- res = 0;
- break;
- }
- next = ast_tvadd(next, ast_samp2tv(myf.f.samples, 8000));
- } else {
- ms = ast_waitfor(chan, ms);
- if (ms < 0) {
- ast_log(LOG_DEBUG, "Hangup detected\n");
- res = -1;
- break;
- }
- if (ms) {
- f = ast_read(chan);
- if (!f) {
- ast_log(LOG_DEBUG, "Null frame == hangup() detected\n");
- res = -1;
- break;
- }
- if (f->frametype == AST_FRAME_DTMF) {
- ast_log(LOG_DEBUG, "User pressed a key\n");
- ast_frfree(f);
- res = 0;
- break;
- }
- ast_frfree(f);
- }
- }
- }
- }
- close(fds[0]);
- close(fds[1]);
-
- if (pid > -1)
- kill(pid, SIGKILL);
- if (!res && owriteformat)
- ast_set_write_format(chan, owriteformat);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, NBScat_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_osplookup.c b/1.2-netsec/apps/app_osplookup.c
deleted file mode 100644
index 2fe2d016a..000000000
--- a/1.2-netsec/apps/app_osplookup.c
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Open Settlement Protocol Lookup
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/utils.h"
-#include "asterisk/causes.h"
-#include "asterisk/astosp.h"
-#include "asterisk/app.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "OSP Lookup";
-
-static char *app = "OSPLookup";
-static char *app2 = "OSPNext";
-static char *app3 = "OSPFinish";
-
-static char *synopsis = "Lookup number in OSP";
-static char *synopsis2 = "Lookup next OSP entry";
-static char *synopsis3 = "Record OSP entry";
-
-static char *descrip =
-" OSPLookup(exten[|provider[|options]]): Looks up an extension via OSP and sets\n"
-"the variables, where 'n' is the number of the result beginning with 1:\n"
-" ${OSPTECH}: The technology to use for the call\n"
-" ${OSPDEST}: The destination to use for the call\n"
-" ${OSPTOKEN}: The actual OSP token as a string\n"
-" ${OSPHANDLE}: The OSP Handle for anything remaining\n"
-" ${OSPRESULTS}: The number of OSP results total remaining\n"
-"\n"
-"The option string may contain the following character:\n"
-" 'j' -- jump to n+101 priority if the lookup was NOT successful\n"
-"This application sets the following channel variable upon completion:\n"
-" OSPLOOKUPSTATUS The status of the OSP Lookup attempt as a text string, one of\n"
-" SUCCESS | FAILED \n";
-
-
-static char *descrip2 =
-" OSPNext(cause[|options]): Looks up the next OSP Destination for ${OSPHANDLE}\n"
-"See OSPLookup for more information\n"
-"\n"
-"The option string may contain the following character:\n"
-" 'j' -- jump to n+101 priority if the lookup was NOT successful\n"
-"This application sets the following channel variable upon completion:\n"
-" OSPNEXTSTATUS The status of the OSP Next attempt as a text string, one of\n"
-" SUCCESS | FAILED \n";
-
-static char *descrip3 =
-" OSPFinish(status[|options]): Records call state for ${OSPHANDLE}, according to\n"
-"status, which should be one of BUSY, CONGESTION, ANSWER, NOANSWER, or CHANUNAVAIL\n"
-"or coincidentally, just what the Dial application stores in its ${DIALSTATUS}.\n"
-"\n"
-"The option string may contain the following character:\n"
-" 'j' -- jump to n+101 priority if the finish attempt was NOT successful\n"
-"This application sets the following channel variable upon completion:\n"
-" OSPFINISHSTATUS The status of the OSP Finish attempt as a text string, one of\n"
-" SUCCESS | FAILED \n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int str2cause(char *cause)
-{
- if (!strcasecmp(cause, "BUSY"))
- return AST_CAUSE_BUSY;
- if (!strcasecmp(cause, "CONGESTION"))
- return AST_CAUSE_CONGESTION;
- if (!strcasecmp(cause, "ANSWER"))
- return AST_CAUSE_NORMAL;
- if (!strcasecmp(cause, "CANCEL"))
- return AST_CAUSE_NORMAL;
- if (!strcasecmp(cause, "NOANSWER"))
- return AST_CAUSE_NOANSWER;
- if (!strcasecmp(cause, "NOCHANAVAIL"))
- return AST_CAUSE_CONGESTION;
- ast_log(LOG_WARNING, "Unknown cause '%s', using NORMAL\n", cause);
- return AST_CAUSE_NORMAL;
-}
-
-static int osplookup_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *temp;
- struct ast_osp_result result;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(extension);
- AST_APP_ARG(provider);
- AST_APP_ARG(options);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "OSPLookup requires an argument OSPLookup(exten[|provider[|options]])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- temp = ast_strdupa(data);
- if (!temp) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, temp);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- ast_log(LOG_DEBUG, "Whoo hoo, looking up OSP on '%s' via '%s'\n", args.extension, args.provider ? args.provider : "<default>");
- if ((res = ast_osp_lookup(chan, args.provider, args.extension, chan->cid.cid_num, &result)) > 0) {
- char tmp[80];
- snprintf(tmp, sizeof(tmp), "%d", result.handle);
- pbx_builtin_setvar_helper(chan, "_OSPHANDLE", tmp);
- pbx_builtin_setvar_helper(chan, "_OSPTECH", result.tech);
- pbx_builtin_setvar_helper(chan, "_OSPDEST", result.dest);
- pbx_builtin_setvar_helper(chan, "_OSPTOKEN", result.token);
- snprintf(tmp, sizeof(tmp), "%d", result.numresults);
- pbx_builtin_setvar_helper(chan, "_OSPRESULTS", tmp);
- pbx_builtin_setvar_helper(chan, "OSPLOOKUPSTATUS", "SUCCESS");
-
- } else {
- if (!res) {
- ast_log(LOG_NOTICE, "OSP Lookup failed for '%s' (provider '%s')\n", args.extension, args.provider ? args.provider : "<default>");
- pbx_builtin_setvar_helper(chan, "OSPLOOKUPSTATUS", "FAILED");
- } else
- ast_log(LOG_DEBUG, "Got hangup on '%s' while doing OSP Lookup for '%s' (provider '%s')!\n", chan->name, args.extension, args.provider ? args.provider : "<default>" );
- }
- if (!res) {
- /* Look for a "busy" place */
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- } else if (res > 0)
- res = 0;
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int ospnext_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *temp;
- int cause;
- struct ast_osp_result result;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(cause);
- AST_APP_ARG(options);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "OSPNext should have an argument (cause[|options])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- temp = ast_strdupa(data);
- if (!temp) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, temp);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- cause = str2cause(args.cause);
- temp = pbx_builtin_getvar_helper(chan, "OSPHANDLE");
- result.handle = -1;
- if (!ast_strlen_zero(temp) && (sscanf(temp, "%d", &result.handle) == 1) && (result.handle > -1)) {
- temp = pbx_builtin_getvar_helper(chan, "OSPRESULTS");
- if (ast_strlen_zero(temp) || (sscanf(temp, "%d", &result.numresults) != 1)) {
- result.numresults = 0;
- }
- if ((res = ast_osp_next(&result, cause)) > 0) {
- char tmp[80];
- snprintf(tmp, sizeof(tmp), "%d", result.handle);
- pbx_builtin_setvar_helper(chan, "_OSPHANDLE", tmp);
- pbx_builtin_setvar_helper(chan, "_OSPTECH", result.tech);
- pbx_builtin_setvar_helper(chan, "_OSPDEST", result.dest);
- pbx_builtin_setvar_helper(chan, "_OSPTOKEN", result.token);
- snprintf(tmp, sizeof(tmp), "%d", result.numresults);
- pbx_builtin_setvar_helper(chan, "_OSPRESULTS", tmp);
- pbx_builtin_setvar_helper(chan, "OSPNEXTSTATUS", "SUCCESS");
- }
- } else {
- if (!res) {
- if (result.handle < 0)
- ast_log(LOG_NOTICE, "OSP Lookup Next failed for handle '%d'\n", result.handle);
- else
- ast_log(LOG_DEBUG, "No OSP handle specified\n");
- pbx_builtin_setvar_helper(chan, "OSPNEXTSTATUS", "FAILED");
- } else
- ast_log(LOG_DEBUG, "Got hangup on '%s' while doing OSP Next!\n", chan->name);
- }
- if (!res) {
- /* Look for a "busy" place */
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- } else if (res > 0)
- res = 0;
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int ospfinished_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *temp;
- int cause;
- time_t start=0, duration=0;
- struct ast_osp_result result;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(status);
- AST_APP_ARG(options);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "OSPFinish should have an argument (status[|options])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- temp = ast_strdupa(data);
- if (!temp) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, temp);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- if (chan->cdr) {
- start = chan->cdr->answer.tv_sec;
- if (start)
- duration = time(NULL) - start;
- else
- duration = 0;
- } else
- ast_log(LOG_WARNING, "OSPFinish called on channel '%s' with no CDR!\n", chan->name);
-
- cause = str2cause(args.status);
- temp = pbx_builtin_getvar_helper(chan, "OSPHANDLE");
- result.handle = -1;
- if (!ast_strlen_zero(temp) && (sscanf(temp, "%d", &result.handle) == 1) && (result.handle > -1)) {
- if (!ast_osp_terminate(result.handle, cause, start, duration)) {
- pbx_builtin_setvar_helper(chan, "_OSPHANDLE", "");
- pbx_builtin_setvar_helper(chan, "OSPFINISHSTATUS", "SUCCESS");
- res = 1;
- }
- } else {
- if (!res) {
- if (result.handle > -1)
- ast_log(LOG_NOTICE, "OSP Finish failed for handle '%d'\n", result.handle);
- else
- ast_log(LOG_DEBUG, "No OSP handle specified\n");
- pbx_builtin_setvar_helper(chan, "OSPFINISHSTATUS", "FAILED");
- } else
- ast_log(LOG_DEBUG, "Got hangup on '%s' while doing OSP Terminate!\n", chan->name);
- }
- if (!res) {
- /* Look for a "busy" place */
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- } else if (res > 0)
- res = 0;
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app3);
- res |= ast_unregister_application(app2);
- res |= ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app, osplookup_exec, synopsis, descrip);
- res |= ast_register_application(app2, ospnext_exec, synopsis2, descrip2);
- res |= ast_register_application(app3, ospfinished_exec, synopsis3, descrip3);
-
- return res;
-}
-
-int reload(void)
-{
- return 0;
-}
-
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_page.c b/1.2-netsec/apps/app_page.c
deleted file mode 100644
index 7826d285b..000000000
--- a/1.2-netsec/apps/app_page.c
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (c) 2004 - 2005 Digium, Inc. All rights reserved.
- *
- * Mark Spencer <markster@digium.com>
- *
- * This code is released under the GNU General Public License
- * version 2.0. See LICENSE for more information.
- *
- * 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.
- *
- */
-
-/*! \file
- *
- * \brief page() - Paging application
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/options.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/file.h"
-#include "asterisk/app.h"
-#include "asterisk/chanvars.h"
-
-
-static const char *tdesc = "Page Multiple Phones";
-
-static const char *app_page= "Page";
-
-static const char *page_synopsis = "Pages phones";
-
-static const char *page_descrip =
-"Page(Technology/Resource&Technology2/Resource2[|options])\n"
-" Places outbound calls to the given technology / resource and dumps\n"
-"them into a conference bridge as muted participants. The original\n"
-"caller is dumped into the conference as a speaker and the room is\n"
-"destroyed when the original caller leaves. Valid options are:\n"
-" d - full duplex audio\n"
-" q - quiet, do not play beep to caller\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-enum {
- PAGE_DUPLEX = (1 << 0),
- PAGE_QUIET = (1 << 1),
-} page_opt_flags;
-
-AST_APP_OPTIONS(page_opts, {
- AST_APP_OPTION('d', PAGE_DUPLEX),
- AST_APP_OPTION('q', PAGE_QUIET),
-});
-
-struct calloutdata {
- char cidnum[64];
- char cidname[64];
- char tech[64];
- char resource[256];
- char meetmeopts[64];
- struct ast_variable *variables;
-};
-
-static void *page_thread(void *data)
-{
- struct calloutdata *cd = data;
- ast_pbx_outgoing_app(cd->tech, AST_FORMAT_SLINEAR, cd->resource, 30000,
- "MeetMe", cd->meetmeopts, NULL, 0, cd->cidnum, cd->cidname, cd->variables, NULL, NULL);
- free(cd);
- return NULL;
-}
-
-static void launch_page(struct ast_channel *chan, const char *meetmeopts, const char *tech, const char *resource)
-{
- struct calloutdata *cd;
- const char *varname;
- struct ast_variable *lastvar = NULL;
- struct ast_var_t *varptr;
- pthread_t t;
- pthread_attr_t attr;
- cd = malloc(sizeof(struct calloutdata));
- if (cd) {
- memset(cd, 0, sizeof(struct calloutdata));
- ast_copy_string(cd->cidnum, chan->cid.cid_num ? chan->cid.cid_num : "", sizeof(cd->cidnum));
- ast_copy_string(cd->cidname, chan->cid.cid_name ? chan->cid.cid_name : "", sizeof(cd->cidname));
- ast_copy_string(cd->tech, tech, sizeof(cd->tech));
- ast_copy_string(cd->resource, resource, sizeof(cd->resource));
- ast_copy_string(cd->meetmeopts, meetmeopts, sizeof(cd->meetmeopts));
-
- AST_LIST_TRAVERSE(&chan->varshead, varptr, entries) {
- if (!(varname = ast_var_full_name(varptr)))
- continue;
- if (varname[0] == '_') {
- struct ast_variable *newvar = NULL;
-
- if (varname[1] == '_') {
- newvar = ast_variable_new(varname, ast_var_value(varptr));
- } else {
- newvar = ast_variable_new(&varname[1], ast_var_value(varptr));
- }
-
- if (newvar) {
- if (lastvar)
- lastvar->next = newvar;
- else
- cd->variables = newvar;
- lastvar = newvar;
- }
- }
- }
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&t, &attr, page_thread, cd)) {
- ast_log(LOG_WARNING, "Unable to create paging thread: %s\n", strerror(errno));
- free(cd);
- }
- }
-}
-
-static int page_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- char *options;
- char *tech, *resource;
- char meetmeopts[80];
- struct ast_flags flags = { 0 };
- unsigned int confid = rand();
- struct ast_app *app;
- char *tmp;
- int res=0;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "This application requires at least one argument (destination(s) to page)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (!(app = pbx_findapp("MeetMe"))) {
- ast_log(LOG_WARNING, "There is no MeetMe application available!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- };
-
- options = ast_strdupa(data);
- if (!options) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- tmp = strsep(&options, "|");
- if (options)
- ast_app_parse_options(page_opts, &flags, NULL, options);
-
- snprintf(meetmeopts, sizeof(meetmeopts), "%ud|%sqxdw", confid, ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m");
- while ((tech = strsep(&tmp, "&"))) {
- if ((resource = strchr(tech, '/'))) {
- *resource++ = '\0';
- launch_page(chan, meetmeopts, tech, resource);
- } else {
- ast_log(LOG_WARNING, "Incomplete destination '%s' supplied.\n", tech);
- }
- }
- if (!ast_test_flag(&flags, PAGE_QUIET)) {
- res = ast_streamfile(chan, "beep", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- }
- if (!res) {
- snprintf(meetmeopts, sizeof(meetmeopts), "%ud|A%sqxd", confid, ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t");
- pbx_exec(chan, app, meetmeopts, 1);
- }
-
- LOCAL_USER_REMOVE(u);
-
- return -1;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app_page);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app_page, page_exec, page_synopsis, page_descrip);
-}
-
-char *description(void)
-{
- return (char *) tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
-
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_parkandannounce.c b/1.2-netsec/apps/app_parkandannounce.c
deleted file mode 100644
index bb7aa38b0..000000000
--- a/1.2-netsec/apps/app_parkandannounce.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Author: Ben Miller <bgmiller@dccinc.com>
- * With TONS of help from Mark!
- *
- * 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 ParkAndAnnounce application for Asterisk
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/features.h"
-#include "asterisk/options.h"
-#include "asterisk/logger.h"
-#include "asterisk/say.h"
-#include "asterisk/lock.h"
-
-static char *tdesc = "Call Parking and Announce Application";
-
-static char *app = "ParkAndAnnounce";
-
-static char *synopsis = "Park and Announce";
-
-static char *descrip =
-" ParkAndAnnounce(announce:template|timeout|dial|[return_context]):\n"
-"Park a call into the parkinglot and announce the call over the console.\n"
-"announce template: colon separated list of files to announce, the word PARKED\n"
-" will be replaced by a say_digits of the ext the call is parked in\n"
-"timeout: time in seconds before the call returns into the return context.\n"
-"dial: The app_dial style resource to call to make the announcement. Console/dsp calls the console.\n"
-"return_context: the goto style label to jump the call back into after timeout. default=prio+1\n";
-
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int parkandannounce_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- char *return_context;
- int l, lot, timeout = 0, dres;
- char *working, *context, *exten, *priority, *dial, *dialtech, *dialstr;
- char *template, *tpl_working, *tpl_current;
- char *tmp[100];
- int looptemp=0,i=0;
- char *s,*orig_s;
-
- struct ast_channel *dchan;
- struct outgoing_helper oh;
- int outstate;
-
- struct localuser *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);
-
- l=strlen(data)+2;
- orig_s=malloc(l);
- if(!orig_s) {
- ast_log(LOG_WARNING, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- s=orig_s;
- strncpy(s,data,l);
-
- template=strsep(&s,"|");
- if(! template) {
- ast_log(LOG_WARNING, "PARK: An announce template must be defined\n");
- free(orig_s);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if(s) {
- timeout = atoi(strsep(&s, "|"));
- timeout *= 1000;
- }
- dial=strsep(&s, "|");
- 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);
- return -1;
- } else {
- dialtech=strsep(&dial, "/");
- dialstr=dial;
- ast_verbose( VERBOSE_PREFIX_3 "Dial Tech,String: (%s,%s)\n", dialtech,dialstr);
- }
-
- return_context = s;
-
- if(return_context != NULL) {
- /* set the return context. Code borrowed from the Goto builtin */
-
- working = return_context;
- context = strsep(&working, "|");
- exten = strsep(&working, "|");
- if(!exten) {
- /* Only a priority in this one */
- priority = context;
- exten = NULL;
- context = NULL;
- } else {
- priority = strsep(&working, "|");
- if(!priority) {
- /* Only an extension and priority in this one */
- priority = exten;
- exten = context;
- context = NULL;
- }
- }
- if(atoi(priority) < 0) {
- ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", priority);
- free(orig_s);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- /* At this point we have a priority and maybe an extension and a context */
- chan->priority = atoi(priority);
- if(exten && strcasecmp(exten, "BYEXTENSION"))
- strncpy(chan->exten, exten, sizeof(chan->exten)-1);
- if(context)
- strncpy(chan->context, context, sizeof(chan->context)-1);
- } else { /* increment the priority by default*/
- chan->priority++;
- }
-
- if(option_verbose > 2) {
- ast_verbose( VERBOSE_PREFIX_3 "Return Context: (%s,%s,%d) ID: %s\n", chan->context,chan->exten, chan->priority, chan->cid.cid_num);
- if(!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
- ast_verbose( VERBOSE_PREFIX_3 "Warning: Return Context Invalid, call will return to default|s\n");
- }
- }
-
- /* we are using masq_park here to protect * from touching the channel once we park it. If the channel comes out of timeout
- before we are done announcing and the channel is messed with, Kablooeee. So we use Masq to prevent this. */
-
- ast_masq_park_call(chan, NULL, timeout, &lot);
-
- res=-1;
-
- ast_verbose( VERBOSE_PREFIX_3 "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, return_context);
-
- /* Now place the call to the extention */
-
- memset(&oh, 0, sizeof(oh));
- oh.parent_channel = chan;
- dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, dialstr,30000, &outstate, chan->cid.cid_num, chan->cid.cid_name, &oh);
-
- if(dchan) {
- if(dchan->_state == AST_STATE_UP) {
- if(option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", dchan->name);
- } else {
- if(option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", dchan->name);
- 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);
- return -1;
- }
- } else {
- ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
- free(orig_s);
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- ast_stopstream(dchan);
-
- /* now we have the call placed and are ready to play stuff to it */
-
- ast_verbose(VERBOSE_PREFIX_4 "Announce Template:%s\n", template);
-
- tpl_working = template;
- tpl_current=strsep(&tpl_working, ":");
-
- while(tpl_current && looptemp < sizeof(tmp)) {
- tmp[looptemp]=tpl_current;
- looptemp++;
- tpl_current=strsep(&tpl_working,":");
- }
-
- for(i=0; i<looptemp; i++) {
- ast_verbose(VERBOSE_PREFIX_4 "Announce:%s\n", tmp[i]);
- if(!strcmp(tmp[i], "PARKED")) {
- ast_say_digits(dchan, lot, "", dchan->language);
- } else {
- dres = ast_streamfile(dchan, tmp[i], dchan->language);
- if(!dres) {
- dres = ast_waitstream(dchan, "");
- } else {
- ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], dchan->name);
- dres = 0;
- }
- }
- }
-
- ast_stopstream(dchan);
- ast_hangup(dchan);
- free(orig_s);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- /* return ast_register_application(app, park_exec); */
- return ast_register_application(app, parkandannounce_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_playback.c b/1.2-netsec/apps/app_playback.c
deleted file mode 100644
index ed33097ab..000000000
--- a/1.2-netsec/apps/app_playback.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Trivial application to playback a sound file
- *
- * \ingroup applications
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/utils.h"
-#include "asterisk/options.h"
-#include "asterisk/app.h"
-
-static char *tdesc = "Sound File Playback Application";
-
-static char *app = "Playback";
-
-static char *synopsis = "Play a file";
-
-static char *descrip =
-" Playback(filename[&filename2...][|option]): Plays back given filenames (do not put\n"
-"extension). Options may also be included following a pipe symbol. The 'skip'\n"
-"option causes the playback of the message to be skipped if the channel\n"
-"is not in the 'up' state (i.e. it hasn't been answered yet). If 'skip' is \n"
-"specified, the application will return immediately should the channel not be\n"
-"off hook. Otherwise, unless 'noanswer' is specified, the channel will\n"
-"be answered before the sound is played. Not all channels support playing\n"
-"messages while still on hook. If 'j' is specified, the application\n"
-"will jump to priority n+101 if present when a file specified to be played\n"
-"does not exist.\n"
-"This application sets the following channel variable upon completion:\n"
-" PLAYBACKSTATUS The status of the playback attempt as a text string, one of\n"
-" SUCCESS | FAILED\n"
-;
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int playback_exec(struct ast_channel *chan, void *data)
-{
- int res = 0, mres = 0;
- struct localuser *u;
- char *tmp = NULL;
- int option_skip=0;
- int option_noanswer = 0;
- char *front = NULL, *back = NULL;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(filenames);
- AST_APP_ARG(options);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- tmp = ast_strdupa(data);
- if (!tmp) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, tmp);
-
- if (args.options) {
- if (strcasestr(args.options, "skip"))
- option_skip = 1;
- if (strcasestr(args.options, "noanswer"))
- option_noanswer = 1;
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- if (chan->_state != AST_STATE_UP) {
- if (option_skip) {
- /* At the user's option, skip if the line is not up */
- LOCAL_USER_REMOVE(u);
- return 0;
- } else if (!option_noanswer)
- /* Otherwise answer unless we're supposed to send this while on-hook */
- res = ast_answer(chan);
- }
- if (!res) {
- ast_stopstream(chan);
- front = tmp;
- while (!res && front) {
- if ((back = strchr(front, '&'))) {
- *back = '\0';
- back++;
- }
- res = ast_streamfile(chan, front, chan->language);
- if (!res) {
- res = ast_waitstream(chan, "");
- ast_stopstream(chan);
- } else {
- ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data);
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- res = 0;
- mres = 1;
- }
- front = back;
- }
- if (mres)
- pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", "FAILED");
- else
- pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", "SUCCESS");
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, playback_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_privacy.c b/1.2-netsec/apps/app_privacy.c
deleted file mode 100644
index 04ebf247b..000000000
--- a/1.2-netsec/apps/app_privacy.c
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Block all calls without Caller*ID, require phone # to be entered
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/utils.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#include "asterisk/callerid.h"
-#include "asterisk/app.h"
-#include "asterisk/config.h"
-
-#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";
-
-static char *descrip =
- " PrivacyManager([maxretries[|minlength[|options]]]): If no Caller*ID \n"
- "is sent, PrivacyManager answers the channel and asks the caller to\n"
- "enter their phone number. The caller is given 3 attempts to do so.\n"
- "The application does nothing if Caller*ID was received on the channel.\n"
- " Configuration file privacy.conf contains two variables:\n"
- " maxretries default 3 -maximum number of attempts the caller is allowed \n"
- " to input a callerid.\n"
- " minlength default 10 -minimum allowable digits in the input callerid number.\n"
- "If you don't want to use the config file and have an i/o operation with\n"
- "every call, you can also specify maxretries and minlength as application\n"
- "parameters. Doing so supercedes any values set in privacy.conf.\n"
- "The option string may contain the following character: \n"
- " 'j' -- jump to n+101 priority after <maxretries> failed attempts to collect\n"
- " the minlength number of digits.\n"
- "The application sets the following channel variable upon completion: \n"
- "PRIVACYMGRSTATUS The status of the privacy manager's attempt to collect \n"
- " a phone number from the user. A text string that is either:\n"
- " SUCCESS | FAILED \n"
-;
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-
-
-static int privacy_exec (struct ast_channel *chan, void *data)
-{
- int res=0;
- int retries;
- int maxretries = 3;
- int minlength = 10;
- int x = 0;
- char *s;
- char phone[30];
- struct localuser *u;
- struct ast_config *cfg = NULL;
- char *parse = NULL;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(maxretries);
- AST_APP_ARG(minlength);
- AST_APP_ARG(options);
- );
-
- LOCAL_USER_ADD (u);
- if (!ast_strlen_zero(chan->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose (VERBOSE_PREFIX_3 "CallerID Present: Skipping\n");
- } else {
- /*Answer the channel if it is not already*/
- if (chan->_state != AST_STATE_UP) {
- res = ast_answer(chan);
- if (res) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
-
- if (!ast_strlen_zero((char *)data))
- {
- parse = ast_strdupa(data);
- if (!parse) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (args.maxretries) {
- if (sscanf(args.maxretries, "%d", &x) == 1)
- maxretries = x;
- else
- ast_log(LOG_WARNING, "Invalid max retries argument\n");
- }
- if (args.minlength) {
- if (sscanf(args.minlength, "%d", &x) == 1)
- minlength = x;
- else
- ast_log(LOG_WARNING, "Invalid min length argument\n");
- }
- if (args.options)
- if (strchr(args.options, 'j'))
- priority_jump = 1;
-
- }
-
- if (!x)
- {
- /*Read in the config file*/
- cfg = ast_config_load(PRIV_CONFIG);
-
- if (cfg && (s = ast_variable_retrieve(cfg, "general", "maxretries"))) {
- if (sscanf(s, "%d", &x) == 1)
- maxretries = x;
- else
- ast_log(LOG_WARNING, "Invalid max retries argument\n");
- }
-
- if (cfg && (s = ast_variable_retrieve(cfg, "general", "minlength"))) {
- if (sscanf(s, "%d", &x) == 1)
- minlength = x;
- else
- ast_log(LOG_WARNING, "Invalid min length argument\n");
- }
- }
-
- /*Play unidentified call*/
- res = ast_safe_sleep(chan, 1000);
- if (!res)
- res = ast_streamfile(chan, "privacy-unident", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
-
- /*Ask for 10 digit number, give 3 attempts*/
- for (retries = 0; retries < maxretries; retries++) {
- if (!res)
- res = ast_streamfile(chan, "privacy-prompt", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
-
- if (!res )
- res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#");
-
- if (res < 0)
- break;
-
- /*Make sure we get at least digits*/
- if (strlen(phone) >= minlength )
- break;
- else {
- res = ast_streamfile(chan, "privacy-incorrect", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- }
- }
-
- /*Got a number, play sounds and send them on their way*/
- if ((retries < maxretries) && !res ) {
- res = ast_streamfile(chan, "privacy-thankyou", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- ast_set_callerid (chan, phone, "Privacy Manager", NULL);
- if (option_verbose > 2)
- ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID to %s\n",phone);
- pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
- } else {
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED");
- }
- if (cfg)
- ast_config_destroy(cfg);
- }
-
- LOCAL_USER_REMOVE (u);
- return 0;
-}
-
-int
-unload_module (void)
-{
- int res;
-
- res = ast_unregister_application (app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int
-load_module (void)
-{
- return ast_register_application (app, privacy_exec, synopsis,
- descrip);
-}
-
-char *
-description (void)
-{
- return tdesc;
-}
-
-int
-usecount (void)
-{
- int res;
- STANDARD_USECOUNT (res);
- return res;
-}
-
-char *
-key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_queue.c b/1.2-netsec/apps/app_queue.c
deleted file mode 100644
index c5aff80d0..000000000
--- a/1.2-netsec/apps/app_queue.c
+++ /dev/null
@@ -1,3872 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief True call queues with optional send URL on answer
- *
- * \arg Config in \ref Config_qu queues.conf
- *
- * \par Development notes
- * \note 2004-11-25: Persistent Dynamic Members added by:
- * NetNation Communications (www.netnation.com)
- * Kevin Lindsay <kevinl@netnation.com>
- *
- * Each dynamic agent in each queue is now stored in the astdb.
- * When asterisk is restarted, each agent will be automatically
- * readded into their recorded queues. This feature can be
- * configured with the 'persistent_members=<1|0>' setting in the
- * '[general]' category in queues.conf. The default is on.
- *
- * \note 2004-06-04: Priorities in queues added by inAccess Networks (work funded by Hellas On Line (HOL) www.hol.gr).
- *
- * \note These features added by David C. Troy <dave@toad.net>:
- * - Per-queue holdtime calculation
- * - Estimated holdtime announcement
- * - Position announcement
- * - Abandoned/completed call counters
- * - Failout timer passed as optional app parameter
- * - Optional monitoring of calls, started when call is answered
- *
- * Patch Version 1.07 2003-12-24 01
- *
- * Added servicelevel statistic by Michiel Betel <michiel@betel.nl>
- * Added Priority jumping code for adding and removing queue members by Jonathan Stanton <asterisk@doilooklikeicare.com>
- *
- * Fixed to work with CVS as of 2004-02-25 and released as 1.07a
- * by Matthew Enger <m.enger@xi.com.au>
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/signal.h>
-#include <netinet/in.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/app.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/say.h"
-#include "asterisk/features.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/cli.h"
-#include "asterisk/manager.h"
-#include "asterisk/config.h"
-#include "asterisk/monitor.h"
-#include "asterisk/utils.h"
-#include "asterisk/causes.h"
-#include "asterisk/astdb.h"
-#include "asterisk/devicestate.h"
-
-#define QUEUE_STRATEGY_RINGALL 0
-#define QUEUE_STRATEGY_ROUNDROBIN 1
-#define QUEUE_STRATEGY_LEASTRECENT 2
-#define QUEUE_STRATEGY_FEWESTCALLS 3
-#define QUEUE_STRATEGY_RANDOM 4
-#define QUEUE_STRATEGY_RRMEMORY 5
-
-static struct strategy {
- int strategy;
- char *name;
-} strategies[] = {
- { QUEUE_STRATEGY_RINGALL, "ringall" },
- { QUEUE_STRATEGY_ROUNDROBIN, "roundrobin" },
- { QUEUE_STRATEGY_LEASTRECENT, "leastrecent" },
- { QUEUE_STRATEGY_FEWESTCALLS, "fewestcalls" },
- { QUEUE_STRATEGY_RANDOM, "random" },
- { QUEUE_STRATEGY_RRMEMORY, "rrmemory" },
-};
-
-#define DEFAULT_RETRY 5
-#define DEFAULT_TIMEOUT 15
-#define RECHECK 1 /* Recheck every second to see we we're at the top yet */
-
-#define RES_OKAY 0 /* Action completed */
-#define RES_EXISTS (-1) /* Entry already exists */
-#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";
-
-static char *descrip =
-" Queue(queuename[|options[|URL][|announceoverride][|timeout]]):\n"
-"Queues an incoming call in a particular call queue as defined in queues.conf.\n"
-"This application will return to the dialplan if the queue does not exist, or\n"
-"any of the join options cause the caller to not enter the queue.\n"
-"The option string may contain zero or more of the following characters:\n"
-" 'd' -- data-quality (modem) call (minimum delay).\n"
-" 'h' -- allow callee to hang up by hitting *.\n"
-" 'H' -- allow caller to hang up by hitting *.\n"
-" 'n' -- no retries on the timeout; will exit this application and \n"
-" go to the next step.\n"
-" 'r' -- ring instead of playing MOH\n"
-" 't' -- allow the called user transfer the calling user\n"
-" 'T' -- to allow the calling user to transfer the call.\n"
-" 'w' -- allow the called user to write the conversation to disk via Monitor\n"
-" 'W' -- allow the calling user to write the conversation to disk via Monitor\n"
-" In addition to transferring the call, a call may be parked and then picked\n"
-"up by another user.\n"
-" The optional URL will be sent to the called party if the channel supports\n"
-"it.\n"
-" The timeout will cause the queue to fail out after a specified number of\n"
-"seconds, checked between each queues.conf 'timeout' and 'retry' cycle.\n"
-" This application sets the following channel variable upon completion:\n"
-" QUEUESTATUS The status of the call as a text string, one of\n"
-" TIMEOUT | FULL | JOINEMPTY | LEAVEEMPTY | JOINUNAVAIL | LEAVEUNAVAIL\n";
-
-static char *app_aqm = "AddQueueMember" ;
-static char *app_aqm_synopsis = "Dynamically adds queue members" ;
-static char *app_aqm_descrip =
-" AddQueueMember(queuename[|interface[|penalty[|options]]]):\n"
-"Dynamically adds interface to an existing queue.\n"
-"If the interface is already in the queue and there exists an n+101 priority\n"
-"then it will then jump to this priority. Otherwise it will return an error\n"
-"The option string may contain zero or more of the following characters:\n"
-" 'j' -- jump to +101 priority when appropriate.\n"
-" This application sets the following channel variable upon completion:\n"
-" AQMSTATUS The status of the attempt to add a queue member as a \n"
-" text string, one of\n"
-" ADDED | MEMBERALREADY | NOSUCHQUEUE \n"
-"Example: AddQueueMember(techsupport|SIP/3000)\n"
-"";
-
-static char *app_rqm = "RemoveQueueMember" ;
-static char *app_rqm_synopsis = "Dynamically removes queue members" ;
-static char *app_rqm_descrip =
-" RemoveQueueMember(queuename[|interface[|options]]):\n"
-"Dynamically removes interface to an existing queue\n"
-"If the interface is NOT in the queue and there exists an n+101 priority\n"
-"then it will then jump to this priority. Otherwise it will return an error\n"
-"The option string may contain zero or more of the following characters:\n"
-" 'j' -- jump to +101 priority when appropriate.\n"
-" This application sets the following channel variable upon completion:\n"
-" RQMSTATUS The status of the attempt to remove a queue member as a\n"
-" text string, one of\n"
-" REMOVED | NOTINQUEUE | NOSUCHQUEUE \n"
-"Example: RemoveQueueMember(techsupport|SIP/3000)\n"
-"";
-
-static char *app_pqm = "PauseQueueMember" ;
-static char *app_pqm_synopsis = "Pauses a queue member" ;
-static char *app_pqm_descrip =
-" PauseQueueMember([queuename]|interface[|options]):\n"
-"Pauses (blocks calls for) a queue member.\n"
-"The given interface will be paused in the given queue. This prevents\n"
-"any calls from being sent from the queue to the interface until it is\n"
-"unpaused with UnpauseQueueMember or the manager interface. If no\n"
-"queuename is given, the interface is paused in every queue it is a\n"
-"member of. If the interface is not in the named queue, or if no queue\n"
-"is given and the interface is not in any queue, it will jump to\n"
-"priority n+101, if it exists and the appropriate options are set.\n"
-"The application will fail if the interface is not found and no extension\n"
-"to jump to exists.\n"
-"The option string may contain zero or more of the following characters:\n"
-" 'j' -- jump to +101 priority when appropriate.\n"
-" This application sets the following channel variable upon completion:\n"
-" PQMSTATUS The status of the attempt to pause a queue member as a\n"
-" text string, one of\n"
-" PAUSED | NOTFOUND\n"
-"Example: PauseQueueMember(|SIP/3000)\n";
-
-static char *app_upqm = "UnpauseQueueMember" ;
-static char *app_upqm_synopsis = "Unpauses a queue member" ;
-static char *app_upqm_descrip =
-" UnpauseQueueMember([queuename]|interface[|options]):\n"
-"Unpauses (resumes calls to) a queue member.\n"
-"This is the counterpart to PauseQueueMember and operates exactly the\n"
-"same way, except it unpauses instead of pausing the given interface.\n"
-"The option string may contain zero or more of the following characters:\n"
-" 'j' -- jump to +101 priority when appropriate.\n"
-" This application sets the following channel variable upon completion:\n"
-" UPQMSTATUS The status of the attempt to unpause a queue \n"
-" member as a text string, one of\n"
-" UNPAUSED | NOTFOUND\n"
-"Example: UnpauseQueueMember(|SIP/3000)\n";
-
-/*! \brief Persistent Members astdb family */
-static const char *pm_family = "/Queue/PersistentMembers";
-/* The maximum lengh of each persistent member queue database entry */
-#define PM_MAX_LEN 2048
-
-/*! \brief queues.conf [general] option */
-static int queue_persistent_members = 0;
-
-/*! \brief queues.conf per-queue weight option */
-static int use_weight = 0;
-
-enum queue_result {
- QUEUE_UNKNOWN = 0,
- QUEUE_TIMEOUT = 1,
- QUEUE_JOINEMPTY = 2,
- QUEUE_LEAVEEMPTY = 3,
- QUEUE_JOINUNAVAIL = 4,
- QUEUE_LEAVEUNAVAIL = 5,
- QUEUE_FULL = 6,
-};
-
-const struct {
- enum queue_result id;
- char *text;
-} queue_results[] = {
- { QUEUE_UNKNOWN, "UNKNOWN" },
- { QUEUE_TIMEOUT, "TIMEOUT" },
- { QUEUE_JOINEMPTY,"JOINEMPTY" },
- { QUEUE_LEAVEEMPTY, "LEAVEEMPTY" },
- { QUEUE_JOINUNAVAIL, "JOINUNAVAIL" },
- { QUEUE_LEAVEUNAVAIL, "LEAVEUNAVAIL" },
- { QUEUE_FULL, "FULL" },
-};
-
-/*! \brief We define a custom "local user" structure because we
- use it not only for keeping track of what is in use but
- also for keeping track of who we're dialing. */
-
-struct localuser {
- struct ast_channel *chan;
- char interface[256];
- int stillgoing;
- int metric;
- int oldstatus;
- time_t lastcall;
- struct member *member;
- struct localuser *next;
-};
-
-LOCAL_USER_DECL;
-
-
-struct queue_ent {
- struct ast_call_queue *parent; /*!< What queue is our parent */
- char moh[80]; /*!< Name of musiconhold to be used */
- char announce[80]; /*!< Announcement to play for member when call is answered */
- char context[AST_MAX_CONTEXT]; /*!< Context when user exits queue */
- char digits[AST_MAX_EXTENSION]; /*!< Digits entered while in queue */
- int pos; /*!< Where we are in the queue */
- int prio; /*!< Our priority */
- int last_pos_said; /*!< Last position we told the user */
- time_t last_periodic_announce_time; /*!< The last time we played a periodic anouncement */
- time_t last_pos; /*!< Last time we told the user their position */
- int opos; /*!< Where we started in the queue */
- int handled; /*!< Whether our call was handled */
- time_t start; /*!< When we started holding */
- time_t expire; /*!< When this entry should expire (time out of queue) */
- struct ast_channel *chan; /*!< Our channel */
- struct queue_ent *next; /*!< The next queue entry */
-};
-
-struct member {
- char interface[80]; /*!< Technology/Location */
- int penalty; /*!< Are we a last resort? */
- int calls; /*!< Number of calls serviced by this member */
- int dynamic; /*!< Are we dynamically added? */
- int status; /*!< Status of queue member */
- int paused; /*!< Are we paused (not accepting calls)? */
- time_t lastcall; /*!< When last successful call was hungup */
- int dead; /*!< Used to detect members deleted in realtime */
- struct member *next; /*!< Next member */
-};
-
-/* values used in multi-bit flags in ast_call_queue */
-#define QUEUE_EMPTY_NORMAL 1
-#define QUEUE_EMPTY_STRICT 2
-#define ANNOUNCEHOLDTIME_ALWAYS 1
-#define ANNOUNCEHOLDTIME_ONCE 2
-
-struct ast_call_queue {
- ast_mutex_t lock;
- char name[80]; /*!< Name */
- char moh[80]; /*!< Music On Hold class to be used */
- char announce[80]; /*!< Announcement to play when call is answered */
- char context[AST_MAX_CONTEXT]; /*!< Exit context */
- unsigned int monjoin:1;
- unsigned int dead:1;
- unsigned int joinempty:2;
- unsigned int eventwhencalled:1;
- unsigned int leavewhenempty:2;
- unsigned int reportholdtime:1;
- unsigned int wrapped:1;
- unsigned int timeoutrestart:1;
- unsigned int announceholdtime:2;
- unsigned int strategy:3;
- unsigned int maskmemberstatus:1;
- unsigned int realtime:1;
- int announcefrequency; /*!< How often to announce their position */
- int periodicannouncefrequency; /*!< How often to play periodic announcement */
- int roundingseconds; /*!< How many seconds do we round to? */
- int holdtime; /*!< Current avg holdtime, based on recursive boxcar filter */
- int callscompleted; /*!< Number of queue calls completed */
- int callsabandoned; /*!< Number of queue calls abandoned */
- int servicelevel; /*!< seconds setting for servicelevel*/
- int callscompletedinsl; /*!< Number of calls answered with servicelevel*/
- char monfmt[8]; /*!< Format to use when recording calls */
- char sound_next[80]; /*!< Sound file: "Your call is now first in line" (def. queue-youarenext) */
- char sound_thereare[80]; /*!< Sound file: "There are currently" (def. queue-thereare) */
- char sound_calls[80]; /*!< Sound file: "calls waiting to speak to a representative." (def. queue-callswaiting)*/
- char sound_holdtime[80]; /*!< Sound file: "The current estimated total holdtime is" (def. queue-holdtime) */
- char sound_minutes[80]; /*!< Sound file: "minutes." (def. queue-minutes) */
- char sound_lessthan[80]; /*!< Sound file: "less-than" (def. queue-lessthan) */
- char sound_seconds[80]; /*!< Sound file: "seconds." (def. queue-seconds) */
- char sound_thanks[80]; /*!< Sound file: "Thank you for your patience." (def. queue-thankyou) */
- char sound_reporthold[80]; /*!< Sound file: "Hold time" (def. queue-reporthold) */
- char sound_periodicannounce[80];/*!< Sound file: Custom announce, no default */
-
- int count; /*!< How many entries */
- int maxlen; /*!< Max number of entries */
- int wrapuptime; /*!< Wrapup Time */
-
- int retry; /*!< Retry calling everyone after this amount of time */
- int timeout; /*!< How long to wait for an answer */
- int weight; /*!< Respective weight */
-
- /* Queue strategy things */
- int rrpos; /*!< Round Robin - position */
- int memberdelay; /*!< Seconds to delay connecting member to caller */
-
- struct member *members; /*!< Head of the list of members */
- struct queue_ent *head; /*!< Head of the list of callers */
- struct ast_call_queue *next; /*!< Next call queue */
-};
-
-static struct ast_call_queue *queues = NULL;
-AST_MUTEX_DEFINE_STATIC(qlock);
-
-static void set_queue_result(struct ast_channel *chan, enum queue_result res)
-{
- int i;
-
- for (i = 0; i < sizeof(queue_results) / sizeof(queue_results[0]); i++) {
- if (queue_results[i].id == res) {
- pbx_builtin_setvar_helper(chan, "QUEUESTATUS", queue_results[i].text);
- return;
- }
- }
-}
-
-static char *int2strat(int strategy)
-{
- int x;
- for (x=0;x<sizeof(strategies) / sizeof(strategies[0]);x++) {
- if (strategy == strategies[x].strategy)
- return strategies[x].name;
- }
- return "<unknown>";
-}
-
-static int strat2int(const char *strategy)
-{
- int x;
- for (x=0;x<sizeof(strategies) / sizeof(strategies[0]);x++) {
- if (!strcasecmp(strategy, strategies[x].name))
- return strategies[x].strategy;
- }
- return -1;
-}
-
-/*! \brief Insert the 'new' entry after the 'prev' entry of queue 'q' */
-static inline void insert_entry(struct ast_call_queue *q, struct queue_ent *prev, struct queue_ent *new, int *pos)
-{
- struct queue_ent *cur;
-
- if (!q || !new)
- return;
- if (prev) {
- cur = prev->next;
- prev->next = new;
- } else {
- cur = q->head;
- q->head = new;
- }
- new->next = cur;
- new->parent = q;
- new->pos = ++(*pos);
- new->opos = *pos;
-}
-
-enum queue_member_status {
- QUEUE_NO_MEMBERS,
- QUEUE_NO_REACHABLE_MEMBERS,
- QUEUE_NORMAL
-};
-
-static enum queue_member_status get_member_status(const struct ast_call_queue *q)
-{
- struct member *member;
- enum queue_member_status result = QUEUE_NO_MEMBERS;
-
- for (member = q->members; member; member = member->next) {
- switch (member->status) {
- case AST_DEVICE_INVALID:
- /* nothing to do */
- break;
- case AST_DEVICE_UNAVAILABLE:
- result = QUEUE_NO_REACHABLE_MEMBERS;
- break;
- default:
- return QUEUE_NORMAL;
- }
- }
-
- return result;
-}
-
-struct statechange {
- int state;
- char dev[0];
-};
-
-static void *changethread(void *data)
-{
- struct ast_call_queue *q;
- struct statechange *sc = data;
- struct member *cur;
- char *loc;
- char *technology;
-
- technology = ast_strdupa(sc->dev);
- loc = strchr(technology, '/');
- if (loc) {
- *loc = '\0';
- loc++;
- } else {
- free(sc);
- return NULL;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d' (%s)\n", technology, loc, sc->state, devstate2str(sc->state));
- ast_mutex_lock(&qlock);
- for (q = queues; q; q = q->next) {
- ast_mutex_lock(&q->lock);
- cur = q->members;
- while(cur) {
- if (!strcasecmp(sc->dev, cur->interface)) {
- if (cur->status != sc->state) {
- cur->status = sc->state;
- if (!q->maskmemberstatus) {
- manager_event(EVENT_FLAG_AGENT, "QueueMemberStatus",
- "Queue: %s\r\n"
- "Location: %s\r\n"
- "Membership: %s\r\n"
- "Penalty: %d\r\n"
- "CallsTaken: %d\r\n"
- "LastCall: %d\r\n"
- "Status: %d\r\n"
- "Paused: %d\r\n",
- q->name, cur->interface, cur->dynamic ? "dynamic" : "static",
- cur->penalty, cur->calls, (int)cur->lastcall, cur->status, cur->paused);
- }
- }
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&q->lock);
- }
- ast_mutex_unlock(&qlock);
- free(sc);
- return NULL;
-}
-
-static int statechange_queue(const char *dev, int state, void *ign)
-{
- /* Avoid potential for deadlocks by spawning a new thread to handle
- the event */
- struct statechange *sc;
- pthread_t t;
- pthread_attr_t attr;
-
- sc = malloc(sizeof(struct statechange) + strlen(dev) + 1);
- if (sc) {
- sc->state = state;
- strcpy(sc->dev, dev);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&t, &attr, changethread, sc)) {
- ast_log(LOG_WARNING, "Failed to create update thread!\n");
- free(sc);
- }
- }
- return 0;
-}
-
-static struct member *create_queue_member(char *interface, int penalty, int paused)
-{
- struct member *cur;
-
- /* Add a new member */
-
- cur = malloc(sizeof(struct member));
-
- if (cur) {
- memset(cur, 0, sizeof(struct member));
- cur->penalty = penalty;
- cur->paused = paused;
- ast_copy_string(cur->interface, interface, sizeof(cur->interface));
- if (!strchr(cur->interface, '/'))
- ast_log(LOG_WARNING, "No location at interface '%s'\n", interface);
- cur->status = ast_device_state(interface);
- }
-
- return cur;
-}
-
-static struct ast_call_queue *alloc_queue(const char *queuename)
-{
- struct ast_call_queue *q;
-
- q = malloc(sizeof(*q));
- if (q) {
- memset(q, 0, sizeof(*q));
- ast_mutex_init(&q->lock);
- ast_copy_string(q->name, queuename, sizeof(q->name));
- }
- return q;
-}
-
-static void init_queue(struct ast_call_queue *q)
-{
- q->dead = 0;
- q->retry = DEFAULT_RETRY;
- q->timeout = -1;
- q->maxlen = 0;
- q->announcefrequency = 0;
- q->announceholdtime = 0;
- q->roundingseconds = 0; /* Default - don't announce seconds */
- q->servicelevel = 0;
- q->moh[0] = '\0';
- q->announce[0] = '\0';
- q->context[0] = '\0';
- q->monfmt[0] = '\0';
- q->periodicannouncefrequency = 0;
- ast_copy_string(q->sound_next, "queue-youarenext", sizeof(q->sound_next));
- ast_copy_string(q->sound_thereare, "queue-thereare", sizeof(q->sound_thereare));
- ast_copy_string(q->sound_calls, "queue-callswaiting", sizeof(q->sound_calls));
- ast_copy_string(q->sound_holdtime, "queue-holdtime", sizeof(q->sound_holdtime));
- ast_copy_string(q->sound_minutes, "queue-minutes", sizeof(q->sound_minutes));
- ast_copy_string(q->sound_seconds, "queue-seconds", sizeof(q->sound_seconds));
- ast_copy_string(q->sound_thanks, "queue-thankyou", sizeof(q->sound_thanks));
- ast_copy_string(q->sound_lessthan, "queue-less-than", sizeof(q->sound_lessthan));
- ast_copy_string(q->sound_reporthold, "queue-reporthold", sizeof(q->sound_reporthold));
- ast_copy_string(q->sound_periodicannounce, "queue-periodic-announce", sizeof(q->sound_periodicannounce));
-}
-
-static void clear_queue(struct ast_call_queue *q)
-{
- q->holdtime = 0;
- q->callscompleted = 0;
- q->callsabandoned = 0;
- q->callscompletedinsl = 0;
- q->wrapuptime = 0;
-}
-
-/*! \brief Configure a queue parameter.
-\par
- For error reporting, line number is passed for .conf static configuration.
- For Realtime queues, linenum is -1.
- The failunknown flag is set for config files (and static realtime) to show
- errors for unknown parameters. It is cleared for dynamic realtime to allow
- extra fields in the tables. */
-static void queue_set_param(struct ast_call_queue *q, const char *param, const char *val, int linenum, int failunknown)
-{
- if (!strcasecmp(param, "music") || !strcasecmp(param, "musiconhold")) {
- ast_copy_string(q->moh, val, sizeof(q->moh));
- } else if (!strcasecmp(param, "announce")) {
- ast_copy_string(q->announce, val, sizeof(q->announce));
- } else if (!strcasecmp(param, "context")) {
- ast_copy_string(q->context, val, sizeof(q->context));
- } else if (!strcasecmp(param, "timeout")) {
- q->timeout = atoi(val);
- if (q->timeout < 0)
- q->timeout = DEFAULT_TIMEOUT;
- } else if (!strcasecmp(param, "monitor-join")) {
- q->monjoin = ast_true(val);
- } else if (!strcasecmp(param, "monitor-format")) {
- ast_copy_string(q->monfmt, val, sizeof(q->monfmt));
- } else if (!strcasecmp(param, "queue-youarenext")) {
- ast_copy_string(q->sound_next, val, sizeof(q->sound_next));
- } else if (!strcasecmp(param, "queue-thereare")) {
- ast_copy_string(q->sound_thereare, val, sizeof(q->sound_thereare));
- } else if (!strcasecmp(param, "queue-callswaiting")) {
- ast_copy_string(q->sound_calls, val, sizeof(q->sound_calls));
- } else if (!strcasecmp(param, "queue-holdtime")) {
- ast_copy_string(q->sound_holdtime, val, sizeof(q->sound_holdtime));
- } else if (!strcasecmp(param, "queue-minutes")) {
- ast_copy_string(q->sound_minutes, val, sizeof(q->sound_minutes));
- } else if (!strcasecmp(param, "queue-seconds")) {
- ast_copy_string(q->sound_seconds, val, sizeof(q->sound_seconds));
- } else if (!strcasecmp(param, "queue-lessthan")) {
- ast_copy_string(q->sound_lessthan, val, sizeof(q->sound_lessthan));
- } else if (!strcasecmp(param, "queue-thankyou")) {
- ast_copy_string(q->sound_thanks, val, sizeof(q->sound_thanks));
- } else if (!strcasecmp(param, "queue-reporthold")) {
- ast_copy_string(q->sound_reporthold, val, sizeof(q->sound_reporthold));
- } else if (!strcasecmp(param, "announce-frequency")) {
- q->announcefrequency = atoi(val);
- } else if (!strcasecmp(param, "announce-round-seconds")) {
- q->roundingseconds = atoi(val);
- if (q->roundingseconds>60 || q->roundingseconds<0) {
- if (linenum >= 0) {
- ast_log(LOG_WARNING, "'%s' isn't a valid value for %s "
- "using 0 instead for queue '%s' at line %d of queues.conf\n",
- val, param, q->name, linenum);
- } else {
- ast_log(LOG_WARNING, "'%s' isn't a valid value for %s "
- "using 0 instead for queue '%s'\n", val, param, q->name);
- }
- q->roundingseconds=0;
- }
- } else if (!strcasecmp(param, "announce-holdtime")) {
- if (!strcasecmp(val, "once"))
- q->announceholdtime = ANNOUNCEHOLDTIME_ONCE;
- else if (ast_true(val))
- q->announceholdtime = ANNOUNCEHOLDTIME_ALWAYS;
- else
- q->announceholdtime = 0;
- } else if (!strcasecmp(param, "periodic-announce")) {
- ast_copy_string(q->sound_periodicannounce, val, sizeof(q->sound_periodicannounce));
- } else if (!strcasecmp(param, "periodic-announce-frequency")) {
- q->periodicannouncefrequency = atoi(val);
- } else if (!strcasecmp(param, "retry")) {
- q->retry = atoi(val);
- if (q->retry < 0)
- q->retry = DEFAULT_RETRY;
- } else if (!strcasecmp(param, "wrapuptime")) {
- q->wrapuptime = atoi(val);
- } else if (!strcasecmp(param, "maxlen")) {
- q->maxlen = atoi(val);
- if (q->maxlen < 0)
- q->maxlen = 0;
- } else if (!strcasecmp(param, "servicelevel")) {
- q->servicelevel= atoi(val);
- } else if (!strcasecmp(param, "strategy")) {
- q->strategy = strat2int(val);
- if (q->strategy < 0) {
- ast_log(LOG_WARNING, "'%s' isn't a valid strategy for queue '%s', using ringall instead\n",
- val, q->name);
- q->strategy = 0;
- }
- } else if (!strcasecmp(param, "joinempty")) {
- if (!strcasecmp(val, "strict"))
- q->joinempty = QUEUE_EMPTY_STRICT;
- else if (ast_true(val))
- q->joinempty = QUEUE_EMPTY_NORMAL;
- else
- q->joinempty = 0;
- } else if (!strcasecmp(param, "leavewhenempty")) {
- if (!strcasecmp(val, "strict"))
- q->leavewhenempty = QUEUE_EMPTY_STRICT;
- else if (ast_true(val))
- q->leavewhenempty = QUEUE_EMPTY_NORMAL;
- else
- q->leavewhenempty = 0;
- } else if (!strcasecmp(param, "eventmemberstatus")) {
- q->maskmemberstatus = !ast_true(val);
- } else if (!strcasecmp(param, "eventwhencalled")) {
- q->eventwhencalled = ast_true(val);
- } else if (!strcasecmp(param, "reportholdtime")) {
- q->reportholdtime = ast_true(val);
- } else if (!strcasecmp(param, "memberdelay")) {
- q->memberdelay = atoi(val);
- } else if (!strcasecmp(param, "weight")) {
- q->weight = atoi(val);
- if (q->weight)
- use_weight++;
- /* With Realtime queues, if the last queue using weights is deleted in realtime,
- we will not see any effect on use_weight until next reload. */
- } else if (!strcasecmp(param, "timeoutrestart")) {
- q->timeoutrestart = ast_true(val);
- } else if(failunknown) {
- if (linenum >= 0) {
- ast_log(LOG_WARNING, "Unknown keyword in queue '%s': %s at line %d of queues.conf\n",
- q->name, param, linenum);
- } else {
- ast_log(LOG_WARNING, "Unknown keyword in queue '%s': %s\n", q->name, param);
- }
- }
-}
-
-static void rt_handle_member_record(struct ast_call_queue *q, char *interface, const char *penalty_str)
-{
- struct member *m, *prev_m;
- int penalty = 0;
-
- if(penalty_str) {
- penalty = atoi(penalty_str);
- if(penalty < 0)
- penalty = 0;
- }
-
- /* Find the member, or the place to put a new one. */
- prev_m = NULL;
- m = q->members;
- while (m && strcmp(m->interface, interface)) {
- prev_m = m;
- m = m->next;
- }
-
- /* Create a new one if not found, else update penalty */
- if (!m) {
- m = create_queue_member(interface, penalty, 0);
- if (m) {
- m->dead = 0;
- if (prev_m) {
- prev_m->next = m;
- } else {
- q->members = m;
- }
- }
- } else {
- m->dead = 0; /* Do not delete this one. */
- m->penalty = penalty;
- }
-}
-
-static void free_members(struct ast_call_queue *q, int all)
-{
- /* Free non-dynamic members */
- struct member *curm, *next, *prev = NULL;
-
- for (curm = q->members; curm; curm = next) {
- next = curm->next;
- if (all || !curm->dynamic) {
- if (prev)
- prev->next = next;
- else
- q->members = next;
- free(curm);
- } else
- prev = curm;
- }
-}
-
-static void destroy_queue(struct ast_call_queue *q)
-{
- free_members(q, 1);
- ast_mutex_destroy(&q->lock);
- free(q);
-}
-
-static void remove_queue(struct ast_call_queue *q)
-{
- struct ast_call_queue *cur, *prev = NULL;
-
- ast_mutex_lock(&qlock);
- for (cur = queues; cur; cur = cur->next) {
- if (cur == q) {
- if (prev)
- prev->next = cur->next;
- else
- queues = cur->next;
- } else {
- prev = cur;
- }
- }
- ast_mutex_unlock(&qlock);
-}
-
-/*!\brief Reload a single queue via realtime.
- \return Return the queue, or NULL if it doesn't exist.
- \note Should be called with the global qlock locked. */
-static struct ast_call_queue *find_queue_by_name_rt(const char *queuename, struct ast_variable *queue_vars, struct ast_config *member_config)
-{
- struct ast_variable *v;
- struct ast_call_queue *q, *prev_q = NULL;
- struct member *m, *prev_m, *next_m;
- char *interface;
- char *tmp, *tmp_name;
- char tmpbuf[64]; /* Must be longer than the longest queue param name. */
-
- /* Find the queue in the in-core list (we will create a new one if not found). */
- for (q = queues; q; q = q->next) {
- if (!strcasecmp(q->name, queuename)) {
- break;
- }
- prev_q = q;
- }
-
- /* Static queues override realtime. */
- if (q) {
- ast_mutex_lock(&q->lock);
- if (!q->realtime) {
- if (q->dead) {
- ast_mutex_unlock(&q->lock);
- return NULL;
- } else {
- ast_mutex_unlock(&q->lock);
- return q;
- }
- }
- } else if (!member_config)
- /* Not found in the list, and it's not realtime ... */
- return NULL;
-
- /* Check if queue is defined in realtime. */
- if (!queue_vars) {
- /* Delete queue from in-core list if it has been deleted in realtime. */
- if (q) {
- /*! \note Hmm, can't seem to distinguish a DB failure from a not
- found condition... So we might delete an in-core queue
- in case of DB failure. */
- ast_log(LOG_DEBUG, "Queue %s not found in realtime.\n", queuename);
-
- q->dead = 1;
- /* Delete if unused (else will be deleted when last caller leaves). */
- if (!q->count) {
- /* Delete. */
- if (!prev_q) {
- queues = q->next;
- } else {
- prev_q->next = q->next;
- }
- ast_mutex_unlock(&q->lock);
- destroy_queue(q);
- } else
- ast_mutex_unlock(&q->lock);
- }
- return NULL;
- }
-
- /* Create a new queue if an in-core entry does not exist yet. */
- if (!q) {
- q = alloc_queue(queuename);
- if (!q)
- return NULL;
- ast_mutex_lock(&q->lock);
- clear_queue(q);
- q->realtime = 1;
- q->next = queues;
- queues = q;
- }
- init_queue(q); /* Ensure defaults for all parameters not set explicitly. */
-
- v = queue_vars;
- memset(tmpbuf, 0, sizeof(tmpbuf));
- while(v) {
- /* Convert to dashes `-' from underscores `_' as the latter are more SQL friendly. */
- if((tmp = strchr(v->name, '_')) != NULL) {
- ast_copy_string(tmpbuf, v->name, sizeof(tmpbuf));
- tmp_name = tmpbuf;
- tmp = tmp_name;
- while((tmp = strchr(tmp, '_')) != NULL)
- *tmp++ = '-';
- } else
- tmp_name = v->name;
- queue_set_param(q, tmp_name, v->value, -1, 0);
- v = v->next;
- }
-
- /* Temporarily set non-dynamic members dead so we can detect deleted ones. */
- m = q->members;
- while (m) {
- if (!m->dynamic)
- m->dead = 1;
- m = m->next;
- }
-
- interface = ast_category_browse(member_config, NULL);
- while (interface) {
- rt_handle_member_record(q, interface, ast_variable_retrieve(member_config, interface, "penalty"));
- interface = ast_category_browse(member_config, interface);
- }
-
- /* Delete all realtime members that have been deleted in DB. */
- m = q->members;
- prev_m = NULL;
- while (m) {
- next_m = m->next;
- if (m->dead) {
- if (prev_m) {
- prev_m->next = next_m;
- } else {
- q->members = next_m;
- }
- free(m);
- } else {
- prev_m = m;
- }
- m = next_m;
- }
-
- ast_mutex_unlock(&q->lock);
-
- return q;
-}
-
-static struct ast_call_queue *load_realtime_queue(char *queuename)
-{
- struct ast_variable *queue_vars = NULL;
- struct ast_config *member_config = NULL;
- struct ast_call_queue *q;
-
- /* Find the queue in the in-core list first. */
- ast_mutex_lock(&qlock);
- for (q = queues; q; q = q->next) {
- if (!strcasecmp(q->name, queuename)) {
- break;
- }
- }
- ast_mutex_unlock(&qlock);
-
- if (!q) {
- /*! \note Load from realtime before taking the global qlock, to avoid blocking all
- queue operations while waiting for the DB.
-
- This will be two separate database transactions, so we might
- see queue parameters as they were before another process
- changed the queue and member list as it was after the change.
- Thus we might see an empty member list when a queue is
- deleted. In practise, this is unlikely to cause a problem. */
-
- queue_vars = ast_load_realtime("queues", "name", queuename, NULL);
- if (queue_vars) {
- member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name", queuename, NULL);
- if (!member_config) {
- ast_log(LOG_ERROR, "no queue_members defined in your config (extconfig.conf).\n");
- return NULL;
- }
- }
-
- ast_mutex_lock(&qlock);
-
- q = find_queue_by_name_rt(queuename, queue_vars, member_config);
- if (member_config)
- ast_config_destroy(member_config);
- if (queue_vars)
- ast_variables_destroy(queue_vars);
-
- ast_mutex_unlock(&qlock);
- }
- return q;
-}
-
-static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *reason)
-{
- struct ast_call_queue *q;
- struct queue_ent *cur, *prev = NULL;
- int res = -1;
- int pos = 0;
- int inserted = 0;
- enum queue_member_status stat;
-
- q = load_realtime_queue(queuename);
- if (!q)
- return res;
-
- ast_mutex_lock(&qlock);
- ast_mutex_lock(&q->lock);
-
- /* This is our one */
- stat = get_member_status(q);
- if (!q->joinempty && (stat == QUEUE_NO_MEMBERS))
- *reason = QUEUE_JOINEMPTY;
- else if ((q->joinempty == QUEUE_EMPTY_STRICT) && (stat == QUEUE_NO_REACHABLE_MEMBERS))
- *reason = QUEUE_JOINUNAVAIL;
- else if (q->maxlen && (q->count >= q->maxlen))
- *reason = QUEUE_FULL;
- else {
- /* There's space for us, put us at the right position inside
- * the queue.
- * Take into account the priority of the calling user */
- inserted = 0;
- prev = NULL;
- cur = q->head;
- while(cur) {
- /* We have higher priority than the current user, enter
- * before him, after all the other users with priority
- * higher or equal to our priority. */
- if ((!inserted) && (qe->prio > cur->prio)) {
- insert_entry(q, prev, qe, &pos);
- inserted = 1;
- }
- cur->pos = ++pos;
- prev = cur;
- cur = cur->next;
- }
- /* No luck, join at the end of the queue */
- if (!inserted)
- insert_entry(q, prev, qe, &pos);
- ast_copy_string(qe->moh, q->moh, sizeof(qe->moh));
- ast_copy_string(qe->announce, q->announce, sizeof(qe->announce));
- ast_copy_string(qe->context, q->context, sizeof(qe->context));
- q->count++;
- res = 0;
- manager_event(EVENT_FLAG_CALL, "Join",
- "Channel: %s\r\nCallerID: %s\r\nCallerIDName: %s\r\nQueue: %s\r\nPosition: %d\r\nCount: %d\r\n",
- qe->chan->name,
- qe->chan->cid.cid_num ? qe->chan->cid.cid_num : "unknown",
- qe->chan->cid.cid_name ? qe->chan->cid.cid_name : "unknown",
- q->name, qe->pos, q->count );
-#if 0
-ast_log(LOG_NOTICE, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, qe->chan->name, qe->pos );
-#endif
- }
- ast_mutex_unlock(&q->lock);
- ast_mutex_unlock(&qlock);
- return res;
-}
-
-static int play_file(struct ast_channel *chan, char *filename)
-{
- int res;
-
- ast_stopstream(chan);
- res = ast_streamfile(chan, filename, chan->language);
-
- if (!res)
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- else
- res = 0;
-
- ast_stopstream(chan);
-
- return res;
-}
-
-static int valid_exit(struct queue_ent *qe, char digit)
-{
- int digitlen = strlen(qe->digits);
-
- /* Prevent possible buffer overflow */
- if (digitlen < sizeof(qe->digits) - 2) {
- qe->digits[digitlen] = digit;
- qe->digits[digitlen + 1] = '\0';
- } else {
- qe->digits[0] = '\0';
- return 0;
- }
-
- /* If there's no context to goto, short-circuit */
- if (ast_strlen_zero(qe->context))
- return 0;
-
- /* If the extension is bad, then reset the digits to blank */
- if (!ast_canmatch_extension(qe->chan, qe->context, qe->digits, 1, qe->chan->cid.cid_num)) {
- qe->digits[0] = '\0';
- return 0;
- }
-
- /* We have an exact match */
- if (!ast_goto_if_exists(qe->chan, qe->context, qe->digits, 1)) {
- /* Return 1 on a successful goto */
- return 1;
- }
- return 0;
-}
-
-static int say_position(struct queue_ent *qe)
-{
- int res = 0, avgholdmins, avgholdsecs;
- time_t now;
-
- /* Check to see if this is ludicrous -- if we just announced position, don't do it again*/
- time(&now);
- if ( (now - qe->last_pos) < 15 )
- return 0;
-
- /* If either our position has changed, or we are over the freq timer, say position */
- if ( (qe->last_pos_said == qe->pos) && ((now - qe->last_pos) < qe->parent->announcefrequency) )
- return 0;
-
- ast_moh_stop(qe->chan);
- /* Say we're next, if we are */
- if (qe->pos == 1) {
- res = play_file(qe->chan, qe->parent->sound_next);
- if (res && valid_exit(qe, res))
- goto playout;
- else
- goto posout;
- } else {
- res = play_file(qe->chan, qe->parent->sound_thereare);
- if (res && valid_exit(qe, res))
- goto playout;
- res = ast_say_number(qe->chan, qe->pos, AST_DIGIT_ANY, qe->chan->language, (char *) NULL); /* Needs gender */
- if (res && valid_exit(qe, res))
- goto playout;
- res = play_file(qe->chan, qe->parent->sound_calls);
- if (res && valid_exit(qe, res))
- goto playout;
- }
- /* Round hold time to nearest minute */
- avgholdmins = abs(( (qe->parent->holdtime + 30) - (now - qe->start) ) / 60);
-
- /* If they have specified a rounding then round the seconds as well */
- if(qe->parent->roundingseconds) {
- avgholdsecs = (abs(( (qe->parent->holdtime + 30) - (now - qe->start) )) - 60 * avgholdmins) / qe->parent->roundingseconds;
- avgholdsecs*= qe->parent->roundingseconds;
- } else {
- avgholdsecs=0;
- }
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Hold time for %s is %d minutes %d seconds\n", qe->parent->name, avgholdmins, avgholdsecs);
-
- /* If the hold time is >1 min, if it's enabled, and if it's not
- supposed to be only once and we have already said it, say it */
- if ((avgholdmins+avgholdsecs) > 0 && (qe->parent->announceholdtime) &&
- (!(qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE) && qe->last_pos)) {
- res = play_file(qe->chan, qe->parent->sound_holdtime);
- if (res && valid_exit(qe, res))
- goto playout;
-
- if (avgholdmins>0) {
- if (avgholdmins < 2) {
- res = play_file(qe->chan, qe->parent->sound_lessthan);
- if (res && valid_exit(qe, res))
- goto playout;
-
- res = ast_say_number(qe->chan, 2, AST_DIGIT_ANY, qe->chan->language, (char *)NULL);
- if (res && valid_exit(qe, res))
- goto playout;
- } else {
- res = ast_say_number(qe->chan, avgholdmins, AST_DIGIT_ANY, qe->chan->language, (char*) NULL);
- if (res && valid_exit(qe, res))
- goto playout;
- }
-
- res = play_file(qe->chan, qe->parent->sound_minutes);
- if (res && valid_exit(qe, res))
- goto playout;
- }
- if (avgholdsecs>0) {
- res = ast_say_number(qe->chan, avgholdsecs, AST_DIGIT_ANY, qe->chan->language, (char*) NULL);
- if (res && valid_exit(qe, res))
- goto playout;
-
- res = play_file(qe->chan, qe->parent->sound_seconds);
- if (res && valid_exit(qe, res))
- goto playout;
- }
-
- }
-
- posout:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Told %s in %s their queue position (which was %d)\n",
- qe->chan->name, qe->parent->name, qe->pos);
- res = play_file(qe->chan, qe->parent->sound_thanks);
-
- playout:
- /* Set our last_pos indicators */
- qe->last_pos = now;
- qe->last_pos_said = qe->pos;
- ast_moh_start(qe->chan, qe->moh);
-
- return res;
-}
-
-static void recalc_holdtime(struct queue_ent *qe)
-{
- int oldvalue, newvalue;
-
- /* Calculate holdtime using a recursive boxcar filter */
- /* Thanks to SRT for this contribution */
- /* 2^2 (4) is the filter coefficient; a higher exponent would give old entries more weight */
-
- newvalue = time(NULL) - qe->start;
-
- ast_mutex_lock(&qe->parent->lock);
- if (newvalue <= qe->parent->servicelevel)
- qe->parent->callscompletedinsl++;
- oldvalue = qe->parent->holdtime;
- qe->parent->holdtime = (((oldvalue << 2) - oldvalue) + newvalue) >> 2;
- ast_mutex_unlock(&qe->parent->lock);
-}
-
-
-static void leave_queue(struct queue_ent *qe)
-{
- struct ast_call_queue *q;
- struct queue_ent *cur, *prev = NULL;
- int pos = 0;
-
- q = qe->parent;
- if (!q)
- return;
- ast_mutex_lock(&q->lock);
-
- prev = NULL;
- cur = q->head;
- while(cur) {
- if (cur == qe) {
- q->count--;
-
- /* Take us out of the queue */
- manager_event(EVENT_FLAG_CALL, "Leave",
- "Channel: %s\r\nQueue: %s\r\nCount: %d\r\n",
- qe->chan->name, q->name, q->count);
-#if 0
-ast_log(LOG_NOTICE, "Queue '%s' Leave, Channel '%s'\n", q->name, qe->chan->name );
-#endif
- /* Take us out of the queue */
- if (prev)
- prev->next = cur->next;
- else
- q->head = cur->next;
- } else {
- /* Renumber the people after us in the queue based on a new count */
- cur->pos = ++pos;
- prev = cur;
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&q->lock);
- if (q->dead && !q->count) {
- /* It's dead and nobody is in it, so kill it */
- remove_queue(q);
- destroy_queue(q);
- }
-}
-
-/* Hang up a list of outgoing calls */
-static void hangupcalls(struct localuser *outgoing, struct ast_channel *exception)
-{
- struct localuser *oo;
-
- while(outgoing) {
- /* Hangup any existing lines we have open */
- if (outgoing->chan && (outgoing->chan != exception))
- ast_hangup(outgoing->chan);
- oo = outgoing;
- outgoing=outgoing->next;
- free(oo);
- }
-}
-
-static int update_status(struct ast_call_queue *q, struct member *member, int status)
-{
- struct member *cur;
-
- /* Since a reload could have taken place, we have to traverse the list to
- be sure it's still valid */
- ast_mutex_lock(&q->lock);
- cur = q->members;
- while(cur) {
- if (member == cur) {
- cur->status = status;
- if (!q->maskmemberstatus) {
- manager_event(EVENT_FLAG_AGENT, "QueueMemberStatus",
- "Queue: %s\r\n"
- "Location: %s\r\n"
- "Membership: %s\r\n"
- "Penalty: %d\r\n"
- "CallsTaken: %d\r\n"
- "LastCall: %d\r\n"
- "Status: %d\r\n"
- "Paused: %d\r\n",
- q->name, cur->interface, cur->dynamic ? "dynamic" : "static",
- cur->penalty, cur->calls, (int)cur->lastcall, cur->status, cur->paused);
- }
- break;
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&q->lock);
- return 0;
-}
-
-static int update_dial_status(struct ast_call_queue *q, struct member *member, int status)
-{
- if (status == AST_CAUSE_BUSY)
- status = AST_DEVICE_BUSY;
- else if (status == AST_CAUSE_UNREGISTERED)
- status = AST_DEVICE_UNAVAILABLE;
- else if (status == AST_CAUSE_NOSUCHDRIVER)
- status = AST_DEVICE_INVALID;
- else
- status = AST_DEVICE_UNKNOWN;
- return update_status(q, member, status);
-}
-
-/* traverse all defined queues which have calls waiting and contain this member
- return 0 if no other queue has precedence (higher weight) or 1 if found */
-static int compare_weight(struct ast_call_queue *rq, struct member *member)
-{
- struct ast_call_queue *q;
- struct member *mem;
- int found = 0;
-
- /* &qlock and &rq->lock already set by try_calling()
- * to solve deadlock */
- for (q = queues; q; q = q->next) {
- if (q == rq) /* don't check myself, could deadlock */
- continue;
- ast_mutex_lock(&q->lock);
- if (q->count && q->members) {
- for (mem = q->members; mem; mem = mem->next) {
- if (!strcmp(mem->interface, member->interface)) {
- ast_log(LOG_DEBUG, "Found matching member %s in queue '%s'\n", mem->interface, q->name);
- if (q->weight > rq->weight) {
- ast_log(LOG_DEBUG, "Queue '%s' (weight %d, calls %d) is preferred over '%s' (weight %d, calls %d)\n", q->name, q->weight, q->count, rq->name, rq->weight, rq->count);
- found = 1;
- break;
- }
- }
- }
- }
- ast_mutex_unlock(&q->lock);
- if (found)
- break;
- }
- ast_mutex_unlock(&qlock);
- return found;
-}
-
-static int ring_entry(struct queue_ent *qe, struct localuser *tmp, int *busies)
-{
- int res;
- int status;
- char tech[256];
- char *location;
-
- if (qe->parent->wrapuptime && (time(NULL) - tmp->lastcall < qe->parent->wrapuptime)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Wrapuptime not yet expired for %s\n", tmp->interface);
- if (qe->chan->cdr)
- ast_cdr_busy(qe->chan->cdr);
- tmp->stillgoing = 0;
- (*busies)++;
- return 0;
- }
-
- if (tmp->member->paused) {
- if (option_debug)
- ast_log(LOG_DEBUG, "%s paused, can't receive call\n", tmp->interface);
- if (qe->chan->cdr)
- ast_cdr_busy(qe->chan->cdr);
- tmp->stillgoing = 0;
- return 0;
- }
- if (use_weight && compare_weight(qe->parent,tmp->member)) {
- ast_log(LOG_DEBUG, "Priority queue delaying call to %s:%s\n", qe->parent->name, tmp->interface);
- if (qe->chan->cdr)
- ast_cdr_busy(qe->chan->cdr);
- tmp->stillgoing = 0;
- (*busies)++;
- return 0;
- }
-
- ast_copy_string(tech, tmp->interface, sizeof(tech));
- if ((location = strchr(tech, '/')))
- *location++ = '\0';
- else
- location = "";
-
- /* Request the peer */
- tmp->chan = ast_request(tech, qe->chan->nativeformats, location, &status);
- if (!tmp->chan) { /* If we can't, just go on to the next call */
-#if 0
- ast_log(LOG_NOTICE, "Unable to create channel of type '%s' for Queue\n", cur->tech);
-#endif
- if (qe->chan->cdr)
- ast_cdr_busy(qe->chan->cdr);
- tmp->stillgoing = 0;
- update_dial_status(qe->parent, tmp->member, status);
- (*busies)++;
- return 0;
- } else if (status != tmp->oldstatus)
- update_dial_status(qe->parent, tmp->member, status);
-
- tmp->chan->appl = "AppQueue";
- tmp->chan->data = "(Outgoing Line)";
- tmp->chan->whentohangup = 0;
- if (tmp->chan->cid.cid_num)
- free(tmp->chan->cid.cid_num);
- tmp->chan->cid.cid_num = NULL;
- if (tmp->chan->cid.cid_name)
- free(tmp->chan->cid.cid_name);
- tmp->chan->cid.cid_name = NULL;
- if (tmp->chan->cid.cid_ani)
- free(tmp->chan->cid.cid_ani);
- tmp->chan->cid.cid_ani = NULL;
- if (qe->chan->cid.cid_num)
- tmp->chan->cid.cid_num = strdup(qe->chan->cid.cid_num);
- if (qe->chan->cid.cid_name)
- tmp->chan->cid.cid_name = strdup(qe->chan->cid.cid_name);
- if (qe->chan->cid.cid_ani)
- tmp->chan->cid.cid_ani = strdup(qe->chan->cid.cid_ani);
-
- /* Inherit specially named variables from parent channel */
- ast_channel_inherit_variables(qe->chan, tmp->chan);
-
- /* Presense of ADSI CPE on outgoing channel follows ours */
- tmp->chan->adsicpe = qe->chan->adsicpe;
-
- /* Place the call, but don't wait on the answer */
- res = ast_call(tmp->chan, location, 0);
- if (res) {
- /* Again, keep going even if there's an error */
- if (option_debug)
- ast_log(LOG_DEBUG, "ast call on peer returned %d\n", res);
- else if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Couldn't call %s\n", tmp->interface);
- ast_hangup(tmp->chan);
- tmp->chan = NULL;
- tmp->stillgoing = 0;
- (*busies)++;
- return 0;
- } else {
- if (qe->parent->eventwhencalled) {
- manager_event(EVENT_FLAG_AGENT, "AgentCalled",
- "AgentCalled: %s\r\n"
- "ChannelCalling: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- "Context: %s\r\n"
- "Extension: %s\r\n"
- "Priority: %d\r\n",
- tmp->interface, qe->chan->name,
- tmp->chan->cid.cid_num ? tmp->chan->cid.cid_num : "unknown",
- tmp->chan->cid.cid_name ? tmp->chan->cid.cid_name : "unknown",
- qe->chan->context, qe->chan->exten, qe->chan->priority);
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Called %s\n", tmp->interface);
- }
- return 1;
-}
-
-static int ring_one(struct queue_ent *qe, struct localuser *outgoing, int *busies)
-{
- struct localuser *cur;
- struct localuser *best;
- int bestmetric=0;
-
- do {
- best = NULL;
- cur = outgoing;
- while(cur) {
- if (cur->stillgoing && /* Not already done */
- !cur->chan && /* Isn't already going */
- (!best || (cur->metric < bestmetric))) { /* We haven't found one yet, or it's better */
- bestmetric = cur->metric;
- best = cur;
- }
- cur = cur->next;
- }
- if (best) {
- if (!qe->parent->strategy) {
- /* Ring everyone who shares this best metric (for ringall) */
- cur = outgoing;
- while(cur) {
- if (cur->stillgoing && !cur->chan && (cur->metric <= bestmetric)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "(Parallel) Trying '%s' with metric %d\n", cur->interface, cur->metric);
- ring_entry(qe, cur, busies);
- }
- cur = cur->next;
- }
- } else {
- /* Ring just the best channel */
- if (option_debug)
- ast_log(LOG_DEBUG, "Trying '%s' with metric %d\n", best->interface, best->metric);
- ring_entry(qe, best, busies);
- }
- }
- } while (best && !best->chan);
- if (!best) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Nobody left to try ringing in queue\n");
- return 0;
- }
- return 1;
-}
-
-static int store_next(struct queue_ent *qe, struct localuser *outgoing)
-{
- struct localuser *cur;
- struct localuser *best;
- int bestmetric=0;
-
- best = NULL;
- cur = outgoing;
- while(cur) {
- if (cur->stillgoing && /* Not already done */
- !cur->chan && /* Isn't already going */
- (!best || (cur->metric < bestmetric))) { /* We haven't found one yet, or it's better */
- bestmetric = cur->metric;
- best = cur;
- }
- cur = cur->next;
- }
- if (best) {
- /* Ring just the best channel */
- if (option_debug)
- ast_log(LOG_DEBUG, "Next is '%s' with metric %d\n", best->interface, best->metric);
- qe->parent->rrpos = best->metric % 1000;
- } else {
- /* Just increment rrpos */
- if (qe->parent->wrapped) {
- /* No more channels, start over */
- qe->parent->rrpos = 0;
- } else {
- /* Prioritize next entry */
- qe->parent->rrpos++;
- }
- }
- qe->parent->wrapped = 0;
- return 0;
-}
-
-static int background_file(struct queue_ent *qe, struct ast_channel *chan, char *filename)
-{
- int res;
-
- ast_stopstream(chan);
- res = ast_streamfile(chan, filename, chan->language);
-
- if (!res) {
- /* Wait for a keypress */
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- if (res <= 0 || !valid_exit(qe, res))
- res = 0;
-
- /* Stop playback */
- ast_stopstream(chan);
- } else {
- res = 0;
- }
-
- /*if (res) {
- ast_log(LOG_WARNING, "ast_streamfile failed on %s \n", chan->name);
- res = 0;
- }*/
-
- return res;
-}
-
-static int say_periodic_announcement(struct queue_ent *qe)
-{
- int res = 0;
- time_t now;
-
- /* Get the current time */
- time(&now);
-
- /* Check to see if it is time to announce */
- if ((now - qe->last_periodic_announce_time) < qe->parent->periodicannouncefrequency)
- return 0;
-
- /* Stop the music on hold so we can play our own file */
- ast_moh_stop(qe->chan);
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Playing periodic announcement\n");
-
- /* play the announcement */
- res = background_file(qe, qe->chan, qe->parent->sound_periodicannounce);
-
- /* Resume Music on Hold */
- ast_moh_start(qe->chan, qe->moh);
-
- /* update last_periodic_announce_time */
- qe->last_periodic_announce_time = now;
-
- return res;
-}
-
-static void record_abandoned(struct queue_ent *qe)
-{
- ast_mutex_lock(&qe->parent->lock);
- qe->parent->callsabandoned++;
- ast_mutex_unlock(&qe->parent->lock);
-}
-
-
-#define AST_MAX_WATCHERS 256
-
-#define BUILD_WATCHERS do { \
- o = outgoing; \
- found = -1; \
- pos = 1; \
- numlines = 0; \
- watchers[0] = in; \
- while(o) { \
- /* Keep track of important channels */ \
- if (o->stillgoing) { \
- stillgoing = 1; \
- if (o->chan) { \
- watchers[pos++] = o->chan; \
- found = 1; \
- } \
- } \
- o = o->next; \
- numlines++; \
- } \
- } while(0)
-
-static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser *outgoing, int *to, char *digit, int prebusies, int caller_disconnect)
-{
- char *queue = qe->parent->name;
- struct localuser *o;
- int found;
- int numlines;
- int status;
- int sentringing = 0;
- int numbusies = prebusies;
- int numnochan = 0;
- int stillgoing = 0;
- int orig = *to;
- struct ast_frame *f;
- struct localuser *peer = NULL;
- struct ast_channel *watchers[AST_MAX_WATCHERS];
- int pos;
- struct ast_channel *winner;
- struct ast_channel *in = qe->chan;
-
- while(*to && !peer) {
- BUILD_WATCHERS;
- if ((found < 0) && stillgoing && !qe->parent->strategy) {
- /* On "ringall" strategy we only move to the next penalty level
- when *all* ringing phones are done in the current penalty level */
- ring_one(qe, outgoing, &numbusies);
- BUILD_WATCHERS;
- }
- if (found < 0) {
- if (numlines == (numbusies + numnochan)) {
- ast_log(LOG_DEBUG, "Everyone is busy at this time\n");
- } else {
- ast_log(LOG_NOTICE, "No one is answering queue '%s' (%d/%d/%d)\n", queue, numlines, numbusies, numnochan);
- }
- *to = 0;
- return NULL;
- }
- winner = ast_waitfor_n(watchers, pos, to);
- o = outgoing;
- while(o) {
- if (o->stillgoing && (o->chan) && (o->chan->_state == AST_STATE_UP)) {
- if (!peer) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", o->chan->name, in->name);
- peer = o;
- }
- } else if (o->chan && (o->chan == winner)) {
- if (!ast_strlen_zero(o->chan->call_forward)) {
- char tmpchan[256]="";
- char *stuff;
- char *tech;
- ast_copy_string(tmpchan, o->chan->call_forward, sizeof(tmpchan));
- if ((stuff = strchr(tmpchan, '/'))) {
- *stuff = '\0';
- stuff++;
- tech = tmpchan;
- } else {
- snprintf(tmpchan, sizeof(tmpchan), "%s@%s", o->chan->call_forward, o->chan->context);
- stuff = tmpchan;
- tech = "Local";
- }
- /* Before processing channel, go ahead and check for forwarding */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, o->chan->name);
- /* Setup parameters */
- o->chan = ast_request(tech, in->nativeformats, stuff, &status);
- if (status != o->oldstatus)
- update_dial_status(qe->parent, o->member, status);
- if (!o->chan) {
- ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s'\n", tech, stuff);
- o->stillgoing = 0;
- numnochan++;
- } else {
- if (o->chan->cid.cid_num)
- free(o->chan->cid.cid_num);
- o->chan->cid.cid_num = NULL;
- if (o->chan->cid.cid_name)
- free(o->chan->cid.cid_name);
- o->chan->cid.cid_name = NULL;
-
- if (in->cid.cid_num) {
- o->chan->cid.cid_num = strdup(in->cid.cid_num);
- if (!o->chan->cid.cid_num)
- ast_log(LOG_WARNING, "Out of memory\n");
- }
- if (in->cid.cid_name) {
- o->chan->cid.cid_name = strdup(in->cid.cid_name);
- if (!o->chan->cid.cid_name)
- ast_log(LOG_WARNING, "Out of memory\n");
- }
- ast_copy_string(o->chan->accountcode, in->accountcode, sizeof(o->chan->accountcode));
- o->chan->cdrflags = in->cdrflags;
-
- if (in->cid.cid_ani) {
- if (o->chan->cid.cid_ani)
- free(o->chan->cid.cid_ani);
- o->chan->cid.cid_ani = malloc(strlen(in->cid.cid_ani) + 1);
- if (o->chan->cid.cid_ani)
- strncpy(o->chan->cid.cid_ani, in->cid.cid_ani, strlen(in->cid.cid_ani) + 1);
- else
- ast_log(LOG_WARNING, "Out of memory\n");
- }
- if (o->chan->cid.cid_rdnis)
- free(o->chan->cid.cid_rdnis);
- if (!ast_strlen_zero(in->macroexten))
- o->chan->cid.cid_rdnis = strdup(in->macroexten);
- else
- o->chan->cid.cid_rdnis = strdup(in->exten);
- if (ast_call(o->chan, tmpchan, 0)) {
- ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
- o->stillgoing = 0;
- ast_hangup(o->chan);
- o->chan = NULL;
- numnochan++;
- }
- }
- /* Hangup the original channel now, in case we needed it */
- ast_hangup(winner);
- continue;
- }
- f = ast_read(winner);
- if (f) {
- if (f->frametype == AST_FRAME_CONTROL) {
- switch(f->subclass) {
- case AST_CONTROL_ANSWER:
- /* This is our guy if someone answered. */
- if (!peer) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", o->chan->name, in->name);
- peer = o;
- }
- break;
- case AST_CONTROL_BUSY:
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s is busy\n", o->chan->name);
- o->stillgoing = 0;
- if (in->cdr)
- ast_cdr_busy(in->cdr);
- ast_hangup(o->chan);
- o->chan = NULL;
- if (qe->parent->strategy) {
- if (qe->parent->timeoutrestart)
- *to = orig;
- ring_one(qe, outgoing, &numbusies);
- }
- numbusies++;
- break;
- case AST_CONTROL_CONGESTION:
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s is circuit-busy\n", o->chan->name);
- o->stillgoing = 0;
- if (in->cdr)
- ast_cdr_busy(in->cdr);
- ast_hangup(o->chan);
- o->chan = NULL;
- if (qe->parent->strategy) {
- if (qe->parent->timeoutrestart)
- *to = orig;
- ring_one(qe, outgoing, &numbusies);
- }
- numbusies++;
- break;
- case AST_CONTROL_RINGING:
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s is ringing\n", o->chan->name);
- if (!sentringing) {
-#if 0
- ast_indicate(in, AST_CONTROL_RINGING);
-#endif
- sentringing++;
- }
- break;
- case AST_CONTROL_OFFHOOK:
- /* Ignore going off hook */
- break;
- default:
- ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass);
- }
- }
- ast_frfree(f);
- } else {
- o->stillgoing = 0;
- ast_hangup(o->chan);
- o->chan = NULL;
- if (qe->parent->strategy) {
- if (qe->parent->timeoutrestart)
- *to = orig;
- ring_one(qe, outgoing, &numbusies);
- }
- }
- }
- o = o->next;
- }
- if (winner == in) {
- f = ast_read(in);
-#if 0
- if (f && (f->frametype != AST_FRAME_VOICE))
- printf("Frame type: %d, %d\n", f->frametype, f->subclass);
- else if (!f || (f->frametype != AST_FRAME_VOICE))
- printf("Hangup received on %s\n", in->name);
-#endif
- if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP))) {
- /* Got hung up */
- *to=-1;
- if (f)
- ast_frfree(f);
- return NULL;
- }
- if ((f->frametype == AST_FRAME_DTMF) && caller_disconnect && (f->subclass == '*')) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass);
- *to=0;
- ast_frfree(f);
- return NULL;
- }
- if ((f->frametype == AST_FRAME_DTMF) && (f->subclass != '*') && valid_exit(qe, f->subclass)) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "User pressed digit: %c\n", f->subclass);
- *to=0;
- *digit=f->subclass;
- ast_frfree(f);
- return NULL;
- }
- ast_frfree(f);
- }
- if (!*to && (option_verbose > 2))
- ast_verbose( VERBOSE_PREFIX_3 "Nobody picked up in %d ms\n", orig);
- }
-
- return peer;
-
-}
-
-static int is_our_turn(struct queue_ent *qe)
-{
- struct queue_ent *ch;
- int res;
-
- /* Atomically read the parent head -- does not need a lock */
- ch = qe->parent->head;
- /* If we are now at the top of the head, break out */
- if (ch == qe) {
- if (option_debug)
- ast_log(LOG_DEBUG, "It's our turn (%s).\n", qe->chan->name);
- res = 1;
- } else {
- if (option_debug)
- ast_log(LOG_DEBUG, "It's not our turn (%s).\n", qe->chan->name);
- res = 0;
- }
- return res;
-}
-
-static int wait_our_turn(struct queue_ent *qe, int ringing, enum queue_result *reason)
-{
- int res = 0;
-
- /* This is the holding pen for callers 2 through maxlen */
- for (;;) {
- enum queue_member_status stat;
-
- if (is_our_turn(qe))
- break;
-
- /* If we have timed out, break out */
- if (qe->expire && (time(NULL) > qe->expire)) {
- *reason = QUEUE_TIMEOUT;
- ast_queue_log(qe->parent->name, qe->chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d", qe->pos);
- break;
- }
-
- stat = get_member_status(qe->parent);
-
- /* leave the queue if no agents, if enabled */
- if (qe->parent->leavewhenempty && (stat == QUEUE_NO_MEMBERS)) {
- *reason = QUEUE_LEAVEEMPTY;
- leave_queue(qe);
- break;
- }
-
- /* leave the queue if no reachable agents, if enabled */
- if ((qe->parent->leavewhenempty == QUEUE_EMPTY_STRICT) && (stat == QUEUE_NO_REACHABLE_MEMBERS)) {
- *reason = QUEUE_LEAVEUNAVAIL;
- leave_queue(qe);
- break;
- }
-
- /* Make a position announcement, if enabled */
- if (qe->parent->announcefrequency && !ringing)
- res = say_position(qe);
- if (res)
- break;
-
- /* Make a periodic announcement, if enabled */
- if (qe->parent->periodicannouncefrequency && !ringing)
- res = say_periodic_announcement(qe);
-
- /* Wait a second before checking again */
- if (!res) res = ast_waitfordigit(qe->chan, RECHECK * 1000);
- if (res)
- break;
- }
- return res;
-}
-
-static int update_queue(struct ast_call_queue *q, struct member *member)
-{
- struct member *cur;
-
- /* Since a reload could have taken place, we have to traverse the list to
- be sure it's still valid */
- ast_mutex_lock(&q->lock);
- cur = q->members;
- while(cur) {
- if (member == cur) {
- time(&cur->lastcall);
- cur->calls++;
- break;
- }
- cur = cur->next;
- }
- q->callscompleted++;
- ast_mutex_unlock(&q->lock);
- return 0;
-}
-
-static int calc_metric(struct ast_call_queue *q, struct member *mem, int pos, struct queue_ent *qe, struct localuser *tmp)
-{
- switch (q->strategy) {
- case QUEUE_STRATEGY_RINGALL:
- /* Everyone equal, except for penalty */
- tmp->metric = mem->penalty * 1000000;
- break;
- case QUEUE_STRATEGY_ROUNDROBIN:
- if (!pos) {
- if (!q->wrapped) {
- /* No more channels, start over */
- q->rrpos = 0;
- } else {
- /* Prioritize next entry */
- q->rrpos++;
- }
- q->wrapped = 0;
- }
- /* Fall through */
- case QUEUE_STRATEGY_RRMEMORY:
- if (pos < q->rrpos) {
- tmp->metric = 1000 + pos;
- } else {
- if (pos > q->rrpos)
- /* Indicate there is another priority */
- q->wrapped = 1;
- tmp->metric = pos;
- }
- tmp->metric += mem->penalty * 1000000;
- break;
- case QUEUE_STRATEGY_RANDOM:
- tmp->metric = rand() % 1000;
- tmp->metric += mem->penalty * 1000000;
- break;
- case QUEUE_STRATEGY_FEWESTCALLS:
- tmp->metric = mem->calls;
- tmp->metric += mem->penalty * 1000000;
- break;
- case QUEUE_STRATEGY_LEASTRECENT:
- if (!mem->lastcall)
- tmp->metric = 0;
- else
- tmp->metric = 1000000 - (time(NULL) - mem->lastcall);
- tmp->metric += mem->penalty * 1000000;
- break;
- default:
- ast_log(LOG_WARNING, "Can't calculate metric for unknown strategy %d\n", q->strategy);
- break;
- }
- return 0;
-}
-
-static int try_calling(struct queue_ent *qe, const char *options, char *announceoverride, const char *url, int *go_on)
-{
- struct member *cur;
- struct localuser *outgoing=NULL, *tmp = NULL;
- int to;
- char restofit[AST_MAX_EXTENSION];
- char oldexten[AST_MAX_EXTENSION]="";
- char oldcontext[AST_MAX_CONTEXT]="";
- char queuename[256]="";
- char *newnum;
- char *monitorfilename;
- struct ast_channel *peer;
- struct ast_channel *which;
- struct localuser *lpeer;
- struct member *member;
- int res = 0, bridge = 0;
- int numbusies = 0;
- int x=0;
- char *announce = NULL;
- char digit = 0;
- time_t callstart;
- time_t now = time(NULL);
- struct ast_bridge_config bridge_config;
- char nondataquality = 1;
-
- memset(&bridge_config, 0, sizeof(bridge_config));
- time(&now);
-
- for (; options && *options; options++)
- switch (*options) {
- case 't':
- ast_set_flag(&(bridge_config.features_callee), AST_FEATURE_REDIRECT);
- break;
- case 'T':
- ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_REDIRECT);
- break;
- case 'w':
- ast_set_flag(&(bridge_config.features_callee), AST_FEATURE_AUTOMON);
- break;
- case 'W':
- ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_AUTOMON);
- break;
- case 'd':
- nondataquality = 0;
- break;
- case 'h':
- ast_set_flag(&(bridge_config.features_callee), AST_FEATURE_DISCONNECT);
- break;
- case 'H':
- ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT);
- break;
- case 'n':
- if ((now - qe->start >= qe->parent->timeout))
- *go_on = 1;
- break;
- }
-
- /* Hold the lock while we setup the outgoing calls */
- if (use_weight)
- ast_mutex_lock(&qlock);
- ast_mutex_lock(&qe->parent->lock);
- if (option_debug)
- ast_log(LOG_DEBUG, "%s is trying to call a queue member.\n",
- qe->chan->name);
- ast_copy_string(queuename, qe->parent->name, sizeof(queuename));
- cur = qe->parent->members;
- if (!ast_strlen_zero(qe->announce))
- announce = qe->announce;
- if (!ast_strlen_zero(announceoverride))
- announce = announceoverride;
-
- while(cur) {
- tmp = malloc(sizeof(*tmp));
- if (!tmp) {
- ast_mutex_unlock(&qe->parent->lock);
- if (use_weight)
- ast_mutex_unlock(&qlock);
- ast_log(LOG_WARNING, "Out of memory\n");
- goto out;
- }
- memset(tmp, 0, sizeof(*tmp));
- tmp->stillgoing = -1;
- if (option_debug) {
- if (url)
- ast_log(LOG_DEBUG, "Queue with URL=%s_\n", url);
- else
- ast_log(LOG_DEBUG, "Simple queue (no URL)\n");
- }
-
- tmp->member = cur; /* Never directly dereference! Could change on reload */
- tmp->oldstatus = cur->status;
- tmp->lastcall = cur->lastcall;
- ast_copy_string(tmp->interface, cur->interface, sizeof(tmp->interface));
- /* If we're dialing by extension, look at the extension to know what to dial */
- if ((newnum = strstr(tmp->interface, "/BYEXTENSION"))) {
- newnum++;
- strncpy(restofit, newnum + strlen("BYEXTENSION"), sizeof(restofit) - 1);
- snprintf(newnum, sizeof(tmp->interface) - (newnum - tmp->interface), "%s%s", qe->chan->exten, restofit);
- if (option_debug)
- ast_log(LOG_DEBUG, "Dialing by extension %s\n", tmp->interface);
- }
- /* Special case: If we ring everyone, go ahead and ring them, otherwise
- just calculate their metric for the appropriate strategy */
- calc_metric(qe->parent, cur, x++, qe, tmp);
- /* Put them in the list of outgoing thingies... We're ready now.
- XXX If we're forcibly removed, these outgoing calls won't get
- hung up XXX */
- tmp->next = outgoing;
- outgoing = tmp;
- /* If this line is up, don't try anybody else */
- if (outgoing->chan && (outgoing->chan->_state == AST_STATE_UP))
- break;
-
- cur = cur->next;
- }
- if (qe->parent->timeout)
- to = qe->parent->timeout * 1000;
- else
- to = -1;
- ring_one(qe, outgoing, &numbusies);
- ast_mutex_unlock(&qe->parent->lock);
- if (use_weight)
- ast_mutex_unlock(&qlock);
- lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT));
- ast_mutex_lock(&qe->parent->lock);
- if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) {
- store_next(qe, outgoing);
- }
- ast_mutex_unlock(&qe->parent->lock);
- if (lpeer)
- peer = lpeer->chan;
- else
- peer = NULL;
- if (!peer) {
- if (to) {
- /* Musta gotten hung up */
- res = -1;
- } else {
- res = digit;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "%s: Nobody answered.\n", qe->chan->name);
- goto out;
- }
- if (peer) {
- /* Ah ha! Someone answered within the desired timeframe. Of course after this
- we will always return with -1 so that it is hung up properly after the
- conversation. */
- qe->handled++;
- if (!strcmp(qe->chan->type,"Zap"))
- ast_channel_setoption(qe->chan, AST_OPTION_TONE_VERIFY, &nondataquality, sizeof(nondataquality), 0);
- if (!strcmp(peer->type,"Zap"))
- ast_channel_setoption(peer, AST_OPTION_TONE_VERIFY, &nondataquality, sizeof(nondataquality), 0);
- /* Update parameters for the queue */
- recalc_holdtime(qe);
- member = lpeer->member;
- hangupcalls(outgoing, peer);
- outgoing = NULL;
- if (announce || qe->parent->reportholdtime || qe->parent->memberdelay) {
- int res2;
- res2 = ast_autoservice_start(qe->chan);
- if (!res2) {
- if (qe->parent->memberdelay) {
- ast_log(LOG_NOTICE, "Delaying member connect for %d seconds\n", qe->parent->memberdelay);
- res2 |= ast_safe_sleep(peer, qe->parent->memberdelay * 1000);
- }
- if (!res2 && announce) {
- if (play_file(peer, announce))
- ast_log(LOG_WARNING, "Announcement file '%s' is unavailable, continuing anyway...\n", announce);
- }
- if (!res2 && qe->parent->reportholdtime) {
- if (!play_file(peer, qe->parent->sound_reporthold)) {
- int holdtime;
-
- time(&now);
- holdtime = abs((now - qe->start) / 60);
- if (holdtime < 2) {
- play_file(peer, qe->parent->sound_lessthan);
- ast_say_number(peer, 2, AST_DIGIT_ANY, peer->language, NULL);
- } else
- ast_say_number(peer, holdtime, AST_DIGIT_ANY, peer->language, NULL);
- play_file(peer, qe->parent->sound_minutes);
- }
- }
- }
- res2 |= ast_autoservice_stop(qe->chan);
- if (peer->_softhangup) {
- /* Agent must have hung up */
- ast_log(LOG_WARNING, "Agent on %s hungup on the customer. They're going to be pissed.\n", peer->name);
- ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "AGENTDUMP", "%s", "");
- record_abandoned(qe);
- if (qe->parent->eventwhencalled) {
- manager_event(EVENT_FLAG_AGENT, "AgentDump",
- "Queue: %s\r\n"
- "Uniqueid: %s\r\n"
- "Channel: %s\r\n"
- "Member: %s\r\n",
- queuename, qe->chan->uniqueid, peer->name, member->interface);
- }
- ast_hangup(peer);
- goto out;
- } else if (res2) {
- /* Caller must have hung up just before being connected*/
- ast_log(LOG_NOTICE, "Caller was about to talk to agent on %s but the caller hungup.\n", peer->name);
- ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "ABANDON", "%d|%d|%ld", qe->pos, qe->opos, (long)time(NULL) - qe->start);
- record_abandoned(qe);
- ast_hangup(peer);
- return -1;
- }
- }
- /* Stop music on hold */
- ast_moh_stop(qe->chan);
- /* If appropriate, log that we have a destination channel */
- if (qe->chan->cdr)
- ast_cdr_setdestchan(qe->chan->cdr, peer->name);
- /* Make sure channels are compatible */
- res = ast_channel_make_compatible(qe->chan, peer);
- if (res < 0) {
- ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "SYSCOMPAT", "%s", "");
- ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", qe->chan->name, peer->name);
- record_abandoned(qe);
- ast_hangup(peer);
- return -1;
- }
- /* Begin Monitoring */
- if (qe->parent->monfmt && *qe->parent->monfmt) {
- monitorfilename = pbx_builtin_getvar_helper(qe->chan, "MONITOR_FILENAME");
- if (pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC") || pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC_ARGS"))
- which = qe->chan;
- else
- which = peer;
- if (monitorfilename)
- ast_monitor_start(which, qe->parent->monfmt, monitorfilename, 1 );
- else if (qe->chan->cdr)
- ast_monitor_start(which, qe->parent->monfmt, qe->chan->cdr->uniqueid, 1 );
- else {
- /* Last ditch effort -- no CDR, make up something */
- char tmpid[256];
- snprintf(tmpid, sizeof(tmpid), "chan-%x", rand());
- ast_monitor_start(which, qe->parent->monfmt, tmpid, 1 );
- }
- if (qe->parent->monjoin)
- ast_monitor_setjoinfiles(which, 1);
- }
- /* Drop out of the queue at this point, to prepare for next caller */
- leave_queue(qe);
- if (!ast_strlen_zero(url) && ast_channel_supports_html(peer)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "app_queue: sendurl=%s.\n", url);
- ast_channel_sendurl(peer, url);
- }
- ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "CONNECT", "%ld", (long)time(NULL) - qe->start);
- if (qe->parent->eventwhencalled)
- manager_event(EVENT_FLAG_AGENT, "AgentConnect",
- "Queue: %s\r\n"
- "Uniqueid: %s\r\n"
- "Channel: %s\r\n"
- "Member: %s\r\n"
- "Holdtime: %ld\r\n",
- queuename, qe->chan->uniqueid, peer->name, member->interface,
- (long)time(NULL) - qe->start);
- ast_copy_string(oldcontext, qe->chan->context, sizeof(oldcontext));
- ast_copy_string(oldexten, qe->chan->exten, sizeof(oldexten));
- time(&callstart);
-
- bridge = ast_bridge_call(qe->chan,peer, &bridge_config);
-
- if (strcasecmp(oldcontext, qe->chan->context) || strcasecmp(oldexten, qe->chan->exten)) {
- ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "TRANSFER", "%s|%s", qe->chan->exten, qe->chan->context);
- } else if (qe->chan->_softhangup) {
- ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "COMPLETECALLER", "%ld|%ld",
- (long)(callstart - qe->start), (long)(time(NULL) - callstart));
- if (qe->parent->eventwhencalled)
- manager_event(EVENT_FLAG_AGENT, "AgentComplete",
- "Queue: %s\r\n"
- "Uniqueid: %s\r\n"
- "Channel: %s\r\n"
- "Member: %s\r\n"
- "HoldTime: %ld\r\n"
- "TalkTime: %ld\r\n"
- "Reason: caller\r\n",
- queuename, qe->chan->uniqueid, peer->name, member->interface,
- (long)(callstart - qe->start), (long)(time(NULL) - callstart));
- } else {
- ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "COMPLETEAGENT", "%ld|%ld", (long)(callstart - qe->start), (long)(time(NULL) - callstart));
- if (qe->parent->eventwhencalled)
- manager_event(EVENT_FLAG_AGENT, "AgentComplete",
- "Queue: %s\r\n"
- "Uniqueid: %s\r\n"
- "Channel: %s\r\n"
- "HoldTime: %ld\r\n"
- "TalkTime: %ld\r\n"
- "Reason: agent\r\n",
- queuename, qe->chan->uniqueid, peer->name, (long)(callstart - qe->start),
- (long)(time(NULL) - callstart));
- }
-
- if(bridge != AST_PBX_NO_HANGUP_PEER)
- ast_hangup(peer);
- update_queue(qe->parent, member);
- if (bridge == 0)
- res = 1; /* JDG: bridge successfull, leave app_queue */
- else
- res = bridge; /* bridge error, stay in the queue */
- }
-out:
- hangupcalls(outgoing, NULL);
- return res;
-}
-
-static int wait_a_bit(struct queue_ent *qe)
-{
- /* Don't need to hold the lock while we setup the outgoing calls */
- int retrywait = qe->parent->retry * 1000;
-
- return ast_waitfordigit(qe->chan, retrywait);
-}
-
-static struct member * interface_exists(struct ast_call_queue *q, char *interface)
-{
- struct member *mem;
-
- if (q)
- for (mem = q->members; mem; mem = mem->next)
- if (!strcasecmp(interface, mem->interface))
- return mem;
-
- return NULL;
-}
-
-
-/* Dump all members in a specific queue to the databse
- *
- * <pm_family>/<queuename> = <interface>;<penalty>;<paused>[|...]
- *
- */
-static void dump_queue_members(struct ast_call_queue *pm_queue)
-{
- struct member *cur_member;
- char value[PM_MAX_LEN];
- int value_len = 0;
- int res;
-
- memset(value, 0, sizeof(value));
-
- if (!pm_queue)
- return;
-
- for (cur_member = pm_queue->members; cur_member; cur_member = cur_member->next) {
- if (!cur_member->dynamic)
- continue;
-
- res = snprintf(value + value_len, sizeof(value) - value_len, "%s;%d;%d%s",
- cur_member->interface, cur_member->penalty, cur_member->paused,
- cur_member->next ? "|" : "");
- if (res != strlen(value + value_len)) {
- ast_log(LOG_WARNING, "Could not create persistent member string, out of space\n");
- break;
- }
- value_len += res;
- }
-
- if (value_len && !cur_member) {
- if (ast_db_put(pm_family, pm_queue->name, value))
- ast_log(LOG_WARNING, "failed to create persistent dynamic entry!\n");
- } else
- /* Delete the entry if the queue is empty or there is an error */
- ast_db_del(pm_family, pm_queue->name);
-}
-
-static int remove_from_queue(char *queuename, char *interface)
-{
- struct ast_call_queue *q;
- struct member *last_member, *look;
- int res = RES_NOSUCHQUEUE;
-
- ast_mutex_lock(&qlock);
- for (q = queues ; q ; q = q->next) {
- ast_mutex_lock(&q->lock);
- if (!strcmp(q->name, queuename)) {
- if ((last_member = interface_exists(q, interface))) {
- if ((look = q->members) == last_member) {
- q->members = last_member->next;
- } else {
- while (look != NULL) {
- if (look->next == last_member) {
- look->next = last_member->next;
- break;
- } else {
- look = look->next;
- }
- }
- }
- manager_event(EVENT_FLAG_AGENT, "QueueMemberRemoved",
- "Queue: %s\r\n"
- "Location: %s\r\n",
- q->name, last_member->interface);
- free(last_member);
-
- if (queue_persistent_members)
- dump_queue_members(q);
-
- res = RES_OKAY;
- } else {
- res = RES_EXISTS;
- }
- ast_mutex_unlock(&q->lock);
- break;
- }
- ast_mutex_unlock(&q->lock);
- }
- ast_mutex_unlock(&qlock);
- return res;
-}
-
-static int add_to_queue(char *queuename, char *interface, int penalty, int paused, int dump)
-{
- struct ast_call_queue *q;
- struct member *new_member;
- int res = RES_NOSUCHQUEUE;
-
- /* \note Ensure the appropriate realtime queue is loaded. Note that this
- * short-circuits if the queue is already in memory. */
- q = load_realtime_queue(queuename);
-
- ast_mutex_lock(&qlock);
-
- if (q) {
- ast_mutex_lock(&q->lock);
- if (interface_exists(q, interface) == NULL) {
- new_member = create_queue_member(interface, penalty, paused);
-
- if (new_member != NULL) {
- new_member->dynamic = 1;
- new_member->next = q->members;
- q->members = new_member;
- manager_event(EVENT_FLAG_AGENT, "QueueMemberAdded",
- "Queue: %s\r\n"
- "Location: %s\r\n"
- "Membership: %s\r\n"
- "Penalty: %d\r\n"
- "CallsTaken: %d\r\n"
- "LastCall: %d\r\n"
- "Status: %d\r\n"
- "Paused: %d\r\n",
- q->name, new_member->interface, new_member->dynamic ? "dynamic" : "static",
- new_member->penalty, new_member->calls, (int)new_member->lastcall, new_member->status, new_member->paused);
-
- if (dump)
- dump_queue_members(q);
-
- res = RES_OKAY;
- } else {
- res = RES_OUTOFMEMORY;
- }
- } else {
- res = RES_EXISTS;
- }
- ast_mutex_unlock(&q->lock);
- }
- ast_mutex_unlock(&qlock);
- return res;
-}
-
-static int set_member_paused(char *queuename, char *interface, int paused)
-{
- int found = 0;
- struct ast_call_queue *q;
- struct member *mem;
-
- /* Special event for when all queues are paused - individual events still generated */
-
- if (ast_strlen_zero(queuename))
- ast_queue_log("NONE", "NONE", interface, (paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", "");
-
- ast_mutex_lock(&qlock);
- for (q = queues ; q ; q = q->next) {
- ast_mutex_lock(&q->lock);
- if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename)) {
- if ((mem = interface_exists(q, interface))) {
- found++;
- if (mem->paused == paused)
- ast_log(LOG_DEBUG, "%spausing already-%spaused queue member %s:%s\n", (paused ? "" : "un"), (paused ? "" : "un"), q->name, interface);
- mem->paused = paused;
-
- if (queue_persistent_members)
- dump_queue_members(q);
-
- ast_queue_log(q->name, "NONE", interface, (paused ? "PAUSE" : "UNPAUSE"), "%s", "");
-
- manager_event(EVENT_FLAG_AGENT, "QueueMemberPaused",
- "Queue: %s\r\n"
- "Location: %s\r\n"
- "Paused: %d\r\n",
- q->name, mem->interface, paused);
- }
- }
- ast_mutex_unlock(&q->lock);
- }
- ast_mutex_unlock(&qlock);
-
- if (found)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-/* Reload dynamic queue members persisted into the astdb */
-static void reload_queue_members(void)
-{
- char *cur_ptr;
- char *queue_name;
- char *member;
- char *interface;
- char *penalty_tok;
- int penalty = 0;
- char *paused_tok;
- int paused = 0;
- struct ast_db_entry *db_tree;
- struct ast_db_entry *entry;
- struct ast_call_queue *cur_queue;
- char queue_data[PM_MAX_LEN];
-
- ast_mutex_lock(&qlock);
-
- /* Each key in 'pm_family' is the name of a queue */
- db_tree = ast_db_gettree(pm_family, NULL);
- for (entry = db_tree; entry; entry = entry->next) {
-
- queue_name = entry->key + strlen(pm_family) + 2;
-
- cur_queue = queues;
- while (cur_queue) {
- ast_mutex_lock(&cur_queue->lock);
- if (!strcmp(queue_name, cur_queue->name))
- break;
- ast_mutex_unlock(&cur_queue->lock);
- cur_queue = cur_queue->next;
- }
-
- if (!cur_queue) {
- /* If the queue no longer exists, remove it from the
- * database */
- ast_db_del(pm_family, queue_name);
- continue;
- } else
- ast_mutex_unlock(&cur_queue->lock);
-
- if (ast_db_get(pm_family, queue_name, queue_data, PM_MAX_LEN))
- continue;
-
- cur_ptr = queue_data;
- while ((member = strsep(&cur_ptr, "|"))) {
- if (ast_strlen_zero(member))
- continue;
-
- interface = strsep(&member, ";");
- penalty_tok = strsep(&member, ";");
- paused_tok = strsep(&member, ";");
-
- if (!penalty_tok) {
- ast_log(LOG_WARNING, "Error parsing persisent member string for '%s' (penalty)\n", queue_name);
- break;
- }
- penalty = strtol(penalty_tok, NULL, 10);
- if (errno == ERANGE) {
- ast_log(LOG_WARNING, "Error converting penalty: %s: Out of range.\n", penalty_tok);
- break;
- }
-
- if (!paused_tok) {
- ast_log(LOG_WARNING, "Error parsing persistent member string for '%s' (paused)\n", queue_name);
- break;
- }
- paused = strtol(paused_tok, NULL, 10);
- if ((errno == ERANGE) || paused < 0 || paused > 1) {
- ast_log(LOG_WARNING, "Error converting paused: %s: Expected 0 or 1.\n", paused_tok);
- break;
- }
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Reload Members: Queue: %s Member: %s Penalty: %d Paused: %d\n", queue_name, interface, penalty, paused);
-
- if (add_to_queue(queue_name, interface, penalty, paused, 0) == RES_OUTOFMEMORY) {
- ast_log(LOG_ERROR, "Out of Memory when reloading persistent queue member\n");
- break;
- }
- }
- }
-
- ast_mutex_unlock(&qlock);
- if (db_tree) {
- ast_log(LOG_NOTICE, "Queue members sucessfully reloaded from database.\n");
- ast_db_freetree(db_tree);
- }
-}
-
-static int pqm_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- char *parse;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(queuename);
- AST_APP_ARG(interface);
- AST_APP_ARG(options);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "PauseQueueMember requires an argument ([queuename]|interface[|options])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- if (ast_strlen_zero(args.interface)) {
- ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface[|options])\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (set_member_paused(args.queuename, args.interface, 1)) {
- ast_log(LOG_WARNING, "Attempt to pause interface %s, not found\n", args.interface);
- if (priority_jump || option_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(u);
- return 0;
- }
- }
- LOCAL_USER_REMOVE(u);
- pbx_builtin_setvar_helper(chan, "PQMSTATUS", "NOTFOUND");
- return -1;
- }
-
- LOCAL_USER_REMOVE(u);
- pbx_builtin_setvar_helper(chan, "PQMSTATUS", "PAUSED");
- return 0;
-}
-
-static int upqm_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- char *parse;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(queuename);
- AST_APP_ARG(interface);
- AST_APP_ARG(options);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "UnpauseQueueMember requires an argument ([queuename]|interface[|options])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- if (ast_strlen_zero(args.interface)) {
- ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface[|options])\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (set_member_paused(args.queuename, args.interface, 0)) {
- ast_log(LOG_WARNING, "Attempt to unpause interface %s, not found\n", args.interface);
- if (priority_jump || option_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(u);
- return 0;
- }
- }
- LOCAL_USER_REMOVE(u);
- pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "NOTFOUND");
- return -1;
- }
-
- LOCAL_USER_REMOVE(u);
- pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "UNPAUSED");
- return 0;
-}
-
-static int rqm_exec(struct ast_channel *chan, void *data)
-{
- int res=-1;
- struct localuser *u;
- char *parse, *temppos = NULL;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(queuename);
- AST_APP_ARG(interface);
- AST_APP_ARG(options);
- );
-
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "RemoveQueueMember requires an argument (queuename[|interface[|options]])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (ast_strlen_zero(args.interface)) {
- args.interface = ast_strdupa(chan->name);
- temppos = strrchr(args.interface, '-');
- if (temppos)
- *temppos = '\0';
- }
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- switch (remove_from_queue(args.queuename, args.interface)) {
- case RES_OKAY:
- ast_log(LOG_NOTICE, "Removed interface '%s' from queue '%s'\n", args.interface, args.queuename);
- pbx_builtin_setvar_helper(chan, "RQMSTATUS", "REMOVED");
- res = 0;
- break;
- case RES_EXISTS:
- ast_log(LOG_WARNING, "Unable to remove interface '%s' from queue '%s': Not there\n", args.interface, args.queuename);
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOTINQUEUE");
- res = 0;
- break;
- case RES_NOSUCHQUEUE:
- ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': No such queue\n", args.queuename);
- pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOSUCHQUEUE");
- res = 0;
- break;
- case RES_OUTOFMEMORY:
- ast_log(LOG_ERROR, "Out of memory\n");
- break;
- }
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int aqm_exec(struct ast_channel *chan, void *data)
-{
- int res=-1;
- struct localuser *u;
- char *parse, *temppos = NULL;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(queuename);
- AST_APP_ARG(interface);
- AST_APP_ARG(penalty);
- AST_APP_ARG(options);
- );
- int penalty = 0;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename[|[interface]|[penalty][|options]])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (ast_strlen_zero(args.interface)) {
- args.interface = ast_strdupa(chan->name);
- temppos = strrchr(args.interface, '-');
- if (temppos)
- *temppos = '\0';
- }
-
- if (!ast_strlen_zero(args.penalty)) {
- if ((sscanf(args.penalty, "%d", &penalty) != 1) || penalty < 0) {
- ast_log(LOG_WARNING, "Penalty '%s' is invalid, must be an integer >= 0\n", args.penalty);
- penalty = 0;
- }
- }
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
-
- switch (add_to_queue(args.queuename, args.interface, penalty, 0, queue_persistent_members)) {
- case RES_OKAY:
- ast_log(LOG_NOTICE, "Added interface '%s' to queue '%s'\n", args.interface, args.queuename);
- pbx_builtin_setvar_helper(chan, "AQMSTATUS", "ADDED");
- res = 0;
- break;
- case RES_EXISTS:
- ast_log(LOG_WARNING, "Unable to add interface '%s' to queue '%s': Already there\n", args.interface, args.queuename);
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- pbx_builtin_setvar_helper(chan, "AQMSTATUS", "MEMBERALREADY");
- res = 0;
- break;
- case RES_NOSUCHQUEUE:
- ast_log(LOG_WARNING, "Unable to add interface to queue '%s': No such queue\n", args.queuename);
- pbx_builtin_setvar_helper(chan, "AQMSTATUS", "NOSUCHQUEUE");
- res = 0;
- break;
- case RES_OUTOFMEMORY:
- ast_log(LOG_ERROR, "Out of memory adding member %s to queue %s\n", args.interface, args.queuename);
- break;
- }
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int queue_exec(struct ast_channel *chan, void *data)
-{
- int res=-1;
- int ringing=0;
- struct localuser *u;
- char *queuename;
- char info[512];
- char *info_ptr = info;
- char *options = NULL;
- char *url = NULL;
- char *announceoverride = NULL;
- char *user_priority;
- int prio;
- char *queuetimeoutstr = NULL;
- enum queue_result reason = QUEUE_UNKNOWN;
-
- /* whether to exit Queue application after the timeout hits */
- int go_on = 0;
-
- /* Our queue entry */
- struct queue_ent qe;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Queue requires an argument: queuename[|options[|URL][|announceoverride][|timeout]]\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- /* Setup our queue entry */
- memset(&qe, 0, sizeof(qe));
- qe.start = time(NULL);
-
- /* Parse our arguments XXX Check for failure XXX */
- ast_copy_string(info, (char *) data, sizeof(info));
- queuename = strsep(&info_ptr, "|");
- options = strsep(&info_ptr, "|");
- url = strsep(&info_ptr, "|");
- announceoverride = strsep(&info_ptr, "|");
- queuetimeoutstr = info_ptr;
-
- /* set the expire time based on the supplied timeout; */
- if (queuetimeoutstr)
- qe.expire = qe.start + atoi(queuetimeoutstr);
- else
- qe.expire = 0;
-
- /* Get the priority from the variable ${QUEUE_PRIO} */
- user_priority = pbx_builtin_getvar_helper(chan, "QUEUE_PRIO");
- if (user_priority) {
- if (sscanf(user_priority, "%d", &prio) == 1) {
- if (option_debug)
- ast_log(LOG_DEBUG, "%s: Got priority %d from ${QUEUE_PRIO}.\n",
- chan->name, prio);
- } else {
- ast_log(LOG_WARNING, "${QUEUE_PRIO}: Invalid value (%s), channel %s.\n",
- user_priority, chan->name);
- prio = 0;
- }
- } else {
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "NO QUEUE_PRIO variable found. Using default.\n");
- prio = 0;
- }
-
- if (options && (strchr(options, 'r')))
- ringing = 1;
-
- if (option_debug)
- ast_log(LOG_DEBUG, "queue: %s, options: %s, url: %s, announce: %s, expires: %ld, priority: %d\n",
- queuename, options, url, announceoverride, (long)qe.expire, (int)prio);
-
- qe.chan = chan;
- qe.prio = (int)prio;
- qe.last_pos_said = 0;
- qe.last_pos = 0;
- qe.last_periodic_announce_time = time(NULL);
- if (!join_queue(queuename, &qe, &reason)) {
- ast_queue_log(queuename, chan->uniqueid, "NONE", "ENTERQUEUE", "%s|%s", url ? url : "",
- chan->cid.cid_num ? chan->cid.cid_num : "");
-check_turns:
- if (ringing) {
- ast_indicate(chan, AST_CONTROL_RINGING);
- } else {
- ast_moh_start(chan, qe.moh);
- }
- for (;;) {
- /* This is the wait loop for callers 2 through maxlen */
-
- res = wait_our_turn(&qe, ringing, &reason);
- /* If they hungup, return immediately */
- if (res < 0) {
- /* Record this abandoned call */
- record_abandoned(&qe);
- ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s while waiting their turn\n", queuename);
- res = -1;
- }
- break;
- }
- if (!res)
- break;
- if (valid_exit(&qe, res)) {
- ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
- break;
- }
- }
- if (!res) {
- int makeannouncement = 0;
- for (;;) {
- /* This is the wait loop for the head caller*/
- /* To exit, they may get their call answered; */
- /* they may dial a digit from the queue context; */
- /* or, they may timeout. */
-
- enum queue_member_status stat;
-
- /* Leave if we have exceeded our queuetimeout */
- if (qe.expire && (time(NULL) > qe.expire)) {
- record_abandoned(&qe);
- reason = QUEUE_TIMEOUT;
- res = 0;
- ast_queue_log(queuename, chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
- break;
- }
-
- if (makeannouncement) {
- /* Make a position announcement, if enabled */
- if (qe.parent->announcefrequency && !ringing)
- res = say_position(&qe);
- if (res && valid_exit(&qe, res)) {
- ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
- break;
- }
-
- }
- makeannouncement = 1;
-
- /* Make a periodic announcement, if enabled */
- if (qe.parent->periodicannouncefrequency && !ringing)
- res = say_periodic_announcement(&qe);
-
- if (res && valid_exit(&qe, res)) {
- ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos);
- break;
- }
-
- /* Try calling all queue members for 'timeout' seconds */
- res = try_calling(&qe, options, announceoverride, url, &go_on);
- if (res) {
- if (res < 0) {
- if (!qe.handled) {
- record_abandoned(&qe);
- ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
- }
- } else if (res > 0)
- ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
- break;
- }
-
- stat = get_member_status(qe.parent);
-
- /* leave the queue if no agents, if enabled */
- if (qe.parent->leavewhenempty && (stat == QUEUE_NO_MEMBERS)) {
- record_abandoned(&qe);
- reason = QUEUE_LEAVEEMPTY;
- res = 0;
- break;
- }
-
- /* leave the queue if no reachable agents, if enabled */
- if ((qe.parent->leavewhenempty == QUEUE_EMPTY_STRICT) && (stat == QUEUE_NO_REACHABLE_MEMBERS)) {
- record_abandoned(&qe);
- reason = QUEUE_LEAVEUNAVAIL;
- res = 0;
- break;
- }
-
- /* Leave if we have exceeded our queuetimeout */
- if (qe.expire && (time(NULL) > qe.expire)) {
- record_abandoned(&qe);
- reason = QUEUE_TIMEOUT;
- res = 0;
- ast_queue_log(queuename, chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
- break;
- }
-
- /* OK, we didn't get anybody; wait for 'retry' seconds; may get a digit to exit with */
- res = wait_a_bit(&qe);
- if (res < 0) {
- record_abandoned(&qe);
- ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s when they almost made it\n", queuename);
- res = -1;
- }
- break;
- }
- if (res && valid_exit(&qe, res)) {
- ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
- break;
- }
- /* exit after 'timeout' cycle if 'n' option enabled */
- if (go_on) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Exiting on time-out cycle\n");
- res = -1;
- }
- ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
- record_abandoned(&qe);
- reason = QUEUE_TIMEOUT;
- res = 0;
- break;
- }
- /* Since this is a priority queue and
- * it is not sure that we are still at the head
- * of the queue, go and check for our turn again.
- */
- if (!is_our_turn(&qe)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Darn priorities, going back in queue (%s)!\n",
- qe.chan->name);
- goto check_turns;
- }
- }
- }
- /* Don't allow return code > 0 */
- if (res >= 0 && res != AST_PBX_KEEPALIVE) {
- res = 0;
- if (ringing) {
- ast_indicate(chan, -1);
- } else {
- ast_moh_stop(chan);
- }
- ast_stopstream(chan);
- }
- leave_queue(&qe);
- if (reason != QUEUE_UNKNOWN)
- set_queue_result(chan, reason);
- } else {
- ast_log(LOG_WARNING, "Unable to join queue '%s'\n", queuename);
- set_queue_result(chan, reason);
- res = 0;
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static char *queue_function_qac(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int count = 0;
- struct ast_call_queue *q;
- struct localuser *u;
- struct member *m;
-
- LOCAL_USER_ACF_ADD(u);
-
- ast_copy_string(buf, "0", len);
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_ERROR, "QUEUEAGENTCOUNT requires an argument: queuename\n");
- LOCAL_USER_REMOVE(u);
- return buf;
- }
-
- ast_mutex_lock(&qlock);
-
- /* Find the right queue */
- for (q = queues; q; q = q->next) {
- if (!strcasecmp(q->name, data)) {
- ast_mutex_lock(&q->lock);
- break;
- }
- }
-
- ast_mutex_unlock(&qlock);
-
- if (q) {
- for (m = q->members; m; m = m->next) {
- /* Count the agents who are logged in and presently answering calls */
- if ((m->status != AST_DEVICE_UNAVAILABLE) && (m->status != AST_DEVICE_INVALID)) {
- count++;
- }
- }
- ast_mutex_unlock(&q->lock);
- }
-
- snprintf(buf, len, "%d", count);
- LOCAL_USER_REMOVE(u);
- return buf;
-}
-
-static struct ast_custom_function queueagentcount_function = {
- .name = "QUEUEAGENTCOUNT",
- .synopsis = "Count number of agents answering a queue",
- .syntax = "QUEUEAGENTCOUNT(<queuename>)",
- .read = queue_function_qac,
-};
-
-static void reload_queues(void)
-{
- struct ast_call_queue *q, *ql, *qn;
- struct ast_config *cfg;
- char *cat, *tmp;
- struct ast_variable *var;
- struct member *prev, *cur;
- int new;
- char *general_val = NULL;
- char interface[80];
- int penalty;
-
- cfg = ast_config_load("queues.conf");
- if (!cfg) {
- ast_log(LOG_NOTICE, "No call queueing config file (queues.conf), so no call queues\n");
- return;
- }
- memset(interface, 0, sizeof(interface));
- ast_mutex_lock(&qlock);
- use_weight=0;
- /* Mark all queues as dead for the moment */
- q = queues;
- while(q) {
- q->dead = 1;
- q = q->next;
- }
- /* Chug through config file */
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (!strcasecmp(cat, "general")) {
- /* Initialize global settings */
- queue_persistent_members = 0;
- if ((general_val = ast_variable_retrieve(cfg, "general", "persistentmembers")))
- queue_persistent_members = ast_true(general_val);
- } else { /* Define queue */
- /* Look for an existing one */
- q = queues;
- while(q) {
- if (!strcmp(q->name, cat))
- break;
- q = q->next;
- }
- if (!q) {
- /* Make one then */
- q = alloc_queue(cat);
- new = 1;
- } else
- new = 0;
- if (q) {
- if (!new)
- ast_mutex_lock(&q->lock);
- /* Re-initialize the queue, and clear statistics */
- init_queue(q);
- clear_queue(q);
- free_members(q, 0);
- prev = q->members;
- if (prev) {
- /* find the end of any dynamic members */
- while(prev->next)
- prev = prev->next;
- }
- var = ast_variable_browse(cfg, cat);
- while(var) {
- if (!strcasecmp(var->name, "member")) {
- /* Add a new member */
- ast_copy_string(interface, var->value, sizeof(interface));
- if ((tmp = strchr(interface, ','))) {
- *tmp = '\0';
- tmp++;
- penalty = atoi(tmp);
- if (penalty < 0) {
- penalty = 0;
- }
- } else
- penalty = 0;
- cur = create_queue_member(interface, penalty, 0);
- if (cur) {
- if (prev)
- prev->next = cur;
- else
- q->members = cur;
- prev = cur;
- }
- } else {
- queue_set_param(q, var->name, var->value, var->lineno, 1);
- }
- var = var->next;
- }
- if (!new)
- ast_mutex_unlock(&q->lock);
- if (new) {
- q->next = queues;
- queues = q;
- }
- }
- }
- cat = ast_category_browse(cfg, cat);
- }
- ast_config_destroy(cfg);
- q = queues;
- ql = NULL;
- while(q) {
- qn = q->next;
- if (q->dead) {
- if (ql)
- ql->next = q->next;
- else
- queues = q->next;
- if (!q->count) {
- destroy_queue(q);
- } else
- ast_log(LOG_WARNING, "XXX Leaking a little memory :( XXX\n");
- } else {
- for (cur = q->members; cur; cur = cur->next)
- cur->status = ast_device_state(cur->interface);
- ql = q;
- }
- q = qn;
- }
- ast_mutex_unlock(&qlock);
-}
-
-static int __queues_show(int manager, int fd, int argc, char **argv, int queue_show)
-{
- struct ast_call_queue *q;
- struct queue_ent *qe;
- struct member *mem;
- int pos;
- time_t now;
- char max_buf[80];
- char *max;
- size_t max_left;
- float sl = 0;
- char *term = manager ? "\r\n" : "\n";
-
- time(&now);
- if ((!queue_show && argc != 2) || (queue_show && argc != 3))
- return RESULT_SHOWUSAGE;
-
- /* We only want to load realtime queues when a specific queue is asked for. */
- if (queue_show)
- load_realtime_queue(argv[2]);
-
- ast_mutex_lock(&qlock);
-
- q = queues;
- if (!q) {
- ast_mutex_unlock(&qlock);
- if (queue_show)
- ast_cli(fd, "No such queue: %s.%s",argv[2], term);
- else
- ast_cli(fd, "No queues.%s", term);
- return RESULT_SUCCESS;
- }
- while (q) {
- ast_mutex_lock(&q->lock);
- if (queue_show) {
- if (strcasecmp(q->name, argv[2]) != 0) {
- ast_mutex_unlock(&q->lock);
- q = q->next;
- if (!q) {
- ast_cli(fd, "No such queue: %s.%s",argv[2], term);
- break;
- }
- continue;
- }
- }
- max_buf[0] = '\0';
- max = max_buf;
- max_left = sizeof(max_buf);
- if (q->maxlen)
- ast_build_string(&max, &max_left, "%d", q->maxlen);
- else
- ast_build_string(&max, &max_left, "unlimited");
- sl = 0;
- if(q->callscompleted > 0)
- sl = 100*((float)q->callscompletedinsl/(float)q->callscompleted);
- ast_cli(fd, "%-12.12s has %d calls (max %s) in '%s' strategy (%ds holdtime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds%s",
- q->name, q->count, max_buf, int2strat(q->strategy), q->holdtime, q->weight, q->callscompleted, q->callsabandoned,sl,q->servicelevel, term);
- if (q->members) {
- ast_cli(fd, " Members: %s", term);
- for (mem = q->members; mem; mem = mem->next) {
- max_buf[0] = '\0';
- max = max_buf;
- max_left = sizeof(max_buf);
- if (mem->penalty)
- ast_build_string(&max, &max_left, " with penalty %d", mem->penalty);
- if (mem->dynamic)
- ast_build_string(&max, &max_left, " (dynamic)");
- if (mem->paused)
- ast_build_string(&max, &max_left, " (paused)");
- ast_build_string(&max, &max_left, " (%s)", devstate2str(mem->status));
- if (mem->calls) {
- ast_build_string(&max, &max_left, " has taken %d calls (last was %ld secs ago)",
- mem->calls, (long)(time(NULL) - mem->lastcall));
- } else
- ast_build_string(&max, &max_left, " has taken no calls yet");
- ast_cli(fd, " %s%s%s", mem->interface, max_buf, term);
- }
- } else
- ast_cli(fd, " No Members%s", term);
- if (q->head) {
- pos = 1;
- ast_cli(fd, " Callers: %s", term);
- for (qe = q->head; qe; qe = qe->next)
- ast_cli(fd, " %d. %s (wait: %ld:%2.2ld, prio: %d)%s", pos++, qe->chan->name,
- (long)(now - qe->start) / 60, (long)(now - qe->start) % 60, qe->prio, term);
- } else
- ast_cli(fd, " No Callers%s", term);
- ast_cli(fd, "%s", term);
- ast_mutex_unlock(&q->lock);
- q = q->next;
- if (queue_show)
- break;
- }
- ast_mutex_unlock(&qlock);
- return RESULT_SUCCESS;
-}
-
-static int queues_show(int fd, int argc, char **argv)
-{
- return __queues_show(0, fd, argc, argv, 0);
-}
-
-static int queue_show(int fd, int argc, char **argv)
-{
- return __queues_show(0, fd, argc, argv, 1);
-}
-
-static char *complete_queue(char *line, char *word, int pos, int state)
-{
- struct ast_call_queue *q;
- int which=0;
-
- ast_mutex_lock(&qlock);
- for (q = queues; q; q = q->next) {
- if (!strncasecmp(word, q->name, strlen(word))) {
- if (++which > state)
- break;
- }
- }
- ast_mutex_unlock(&qlock);
- return q ? strdup(q->name) : NULL;
-}
-
-/*!\brief callback to display queues status in manager
- \addtogroup Group_AMI
- */
-static int manager_queues_show( struct mansession *s, struct message *m )
-{
- char *a[] = { "show", "queues" };
- __queues_show(1, s->fd, 2, a, 0);
- ast_cli(s->fd, "\r\n\r\n"); /* Properly terminate Manager output */
-
- return RESULT_SUCCESS;
-}
-
-/* Dump queue status */
-static int manager_queues_status( struct mansession *s, struct message *m )
-{
- time_t now;
- int pos;
- char *id = astman_get_header(m,"ActionID");
- char *queuefilter = astman_get_header(m,"Queue");
- char *memberfilter = astman_get_header(m,"Member");
- char idText[256] = "";
- struct ast_call_queue *q;
- struct queue_ent *qe;
- float sl = 0;
- struct member *mem;
-
- astman_send_ack(s, m, "Queue status will follow");
- time(&now);
- ast_mutex_lock(&qlock);
- if (!ast_strlen_zero(id)) {
- snprintf(idText,256,"ActionID: %s\r\n",id);
- }
- for (q = queues; q; q = q->next) {
- ast_mutex_lock(&q->lock);
-
- /* List queue properties */
- if (ast_strlen_zero(queuefilter) || !strcmp(q->name, queuefilter)) {
- if(q->callscompleted > 0)
- sl = 100*((float)q->callscompletedinsl/(float)q->callscompleted);
- ast_cli(s->fd, "Event: QueueParams\r\n"
- "Queue: %s\r\n"
- "Max: %d\r\n"
- "Calls: %d\r\n"
- "Holdtime: %d\r\n"
- "Completed: %d\r\n"
- "Abandoned: %d\r\n"
- "ServiceLevel: %d\r\n"
- "ServicelevelPerf: %2.1f\r\n"
- "Weight: %d\r\n"
- "%s"
- "\r\n",
- q->name, q->maxlen, q->count, q->holdtime, q->callscompleted,
- q->callsabandoned, q->servicelevel, sl, q->weight, idText);
- /* List Queue Members */
- for (mem = q->members; mem; mem = mem->next) {
- if (ast_strlen_zero(memberfilter) || !strcmp(mem->interface, memberfilter)) {
- ast_cli(s->fd, "Event: QueueMember\r\n"
- "Queue: %s\r\n"
- "Location: %s\r\n"
- "Membership: %s\r\n"
- "Penalty: %d\r\n"
- "CallsTaken: %d\r\n"
- "LastCall: %d\r\n"
- "Status: %d\r\n"
- "Paused: %d\r\n"
- "%s"
- "\r\n",
- q->name, mem->interface, mem->dynamic ? "dynamic" : "static",
- mem->penalty, mem->calls, (int)mem->lastcall, mem->status, mem->paused, idText);
- }
- }
- /* List Queue Entries */
- pos = 1;
- for (qe = q->head; qe; qe = qe->next) {
- ast_cli(s->fd, "Event: QueueEntry\r\n"
- "Queue: %s\r\n"
- "Position: %d\r\n"
- "Channel: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- "Wait: %ld\r\n"
- "%s"
- "\r\n",
- q->name, pos++, qe->chan->name,
- qe->chan->cid.cid_num ? qe->chan->cid.cid_num : "unknown",
- qe->chan->cid.cid_name ? qe->chan->cid.cid_name : "unknown",
- (long)(now - qe->start), idText);
- }
- }
- ast_mutex_unlock(&q->lock);
- }
- ast_mutex_unlock(&qlock);
-
- ast_cli(s->fd,
- "Event: QueueStatusComplete\r\n"
- "%s"
- "\r\n",idText);
-
-
- return RESULT_SUCCESS;
-}
-
-static int manager_add_queue_member(struct mansession *s, struct message *m)
-{
- char *queuename, *interface, *penalty_s, *paused_s;
- int paused, penalty = 0;
-
- queuename = astman_get_header(m, "Queue");
- interface = astman_get_header(m, "Interface");
- penalty_s = astman_get_header(m, "Penalty");
- paused_s = astman_get_header(m, "Paused");
-
- if (ast_strlen_zero(queuename)) {
- astman_send_error(s, m, "'Queue' not specified.");
- return 0;
- }
-
- if (ast_strlen_zero(interface)) {
- astman_send_error(s, m, "'Interface' not specified.");
- return 0;
- }
-
- if (ast_strlen_zero(penalty_s))
- penalty = 0;
- else if (sscanf(penalty_s, "%d", &penalty) != 1) {
- penalty = 0;
- }
-
- if (ast_strlen_zero(paused_s))
- paused = 0;
- else
- paused = abs(ast_true(paused_s));
-
- switch (add_to_queue(queuename, interface, penalty, paused, queue_persistent_members)) {
- case RES_OKAY:
- astman_send_ack(s, m, "Added interface to queue");
- break;
- case RES_EXISTS:
- astman_send_error(s, m, "Unable to add interface: Already there");
- break;
- case RES_NOSUCHQUEUE:
- astman_send_error(s, m, "Unable to add interface to queue: No such queue");
- break;
- case RES_OUTOFMEMORY:
- astman_send_error(s, m, "Out of memory");
- break;
- }
- return 0;
-}
-
-static int manager_remove_queue_member(struct mansession *s, struct message *m)
-{
- char *queuename, *interface;
-
- queuename = astman_get_header(m, "Queue");
- interface = astman_get_header(m, "Interface");
-
- if (ast_strlen_zero(queuename) || ast_strlen_zero(interface)) {
- astman_send_error(s, m, "Need 'Queue' and 'Interface' parameters.");
- return 0;
- }
-
- switch (remove_from_queue(queuename, interface)) {
- case RES_OKAY:
- astman_send_ack(s, m, "Removed interface from queue");
- break;
- case RES_EXISTS:
- astman_send_error(s, m, "Unable to remove interface: Not there");
- break;
- case RES_NOSUCHQUEUE:
- astman_send_error(s, m, "Unable to remove interface from queue: No such queue");
- break;
- case RES_OUTOFMEMORY:
- astman_send_error(s, m, "Out of memory");
- break;
- }
- return 0;
-}
-
-static int manager_pause_queue_member(struct mansession *s, struct message *m)
-{
- char *queuename, *interface, *paused_s;
- int paused;
-
- interface = astman_get_header(m, "Interface");
- paused_s = astman_get_header(m, "Paused");
- queuename = astman_get_header(m, "Queue"); /* Optional - if not supplied, pause the given Interface in all queues */
-
- if (ast_strlen_zero(interface) || ast_strlen_zero(paused_s)) {
- astman_send_error(s, m, "Need 'Interface' and 'Paused' parameters.");
- return 0;
- }
-
- paused = abs(ast_true(paused_s));
-
- if (set_member_paused(queuename, interface, paused))
- astman_send_error(s, m, "Interface not found");
- else
- if (paused)
- astman_send_ack(s, m, "Interface paused successfully");
- else
- astman_send_ack(s, m, "Interface unpaused successfully");
-
- return 0;
-}
-
-static int handle_add_queue_member(int fd, int argc, char *argv[])
-{
- char *queuename, *interface;
- int penalty;
-
- if ((argc != 6) && (argc != 8)) {
- return RESULT_SHOWUSAGE;
- } else if (strcmp(argv[4], "to")) {
- return RESULT_SHOWUSAGE;
- } else if ((argc == 8) && strcmp(argv[6], "penalty")) {
- return RESULT_SHOWUSAGE;
- }
-
- queuename = argv[5];
- interface = argv[3];
- if (argc == 8) {
- if (sscanf(argv[7], "%d", &penalty) == 1) {
- if (penalty < 0) {
- ast_cli(fd, "Penalty must be >= 0\n");
- penalty = 0;
- }
- } else {
- ast_cli(fd, "Penalty must be an integer >= 0\n");
- penalty = 0;
- }
- } else {
- penalty = 0;
- }
-
- switch (add_to_queue(queuename, interface, penalty, 0, queue_persistent_members)) {
- case RES_OKAY:
- ast_cli(fd, "Added interface '%s' to queue '%s'\n", interface, queuename);
- return RESULT_SUCCESS;
- case RES_EXISTS:
- ast_cli(fd, "Unable to add interface '%s' to queue '%s': Already there\n", interface, queuename);
- return RESULT_FAILURE;
- case RES_NOSUCHQUEUE:
- ast_cli(fd, "Unable to add interface to queue '%s': No such queue\n", queuename);
- return RESULT_FAILURE;
- case RES_OUTOFMEMORY:
- ast_cli(fd, "Out of memory\n");
- return RESULT_FAILURE;
- default:
- return RESULT_FAILURE;
- }
-}
-
-static char *complete_add_queue_member(char *line, char *word, int pos, int state)
-{
- /* 0 - add; 1 - queue; 2 - member; 3 - <member>; 4 - to; 5 - <queue>; 6 - penalty; 7 - <penalty> */
- switch (pos) {
- case 3:
- /* Don't attempt to complete name of member (infinite possibilities) */
- return NULL;
- case 4:
- if (state == 0) {
- return strdup("to");
- } else {
- return NULL;
- }
- case 5:
- /* No need to duplicate code */
- return complete_queue(line, word, pos, state);
- case 6:
- if (state == 0) {
- return strdup("penalty");
- } else {
- return NULL;
- }
- case 7:
- if (state < 100) { /* 0-99 */
- char *num = malloc(3);
- if (num) {
- sprintf(num, "%d", state);
- }
- return num;
- } else {
- return NULL;
- }
- default:
- return NULL;
- }
-}
-
-static int handle_remove_queue_member(int fd, int argc, char *argv[])
-{
- char *queuename, *interface;
-
- if (argc != 6) {
- return RESULT_SHOWUSAGE;
- } else if (strcmp(argv[4], "from")) {
- return RESULT_SHOWUSAGE;
- }
-
- queuename = argv[5];
- interface = argv[3];
-
- switch (remove_from_queue(queuename, interface)) {
- case RES_OKAY:
- ast_cli(fd, "Removed interface '%s' from queue '%s'\n", interface, queuename);
- return RESULT_SUCCESS;
- case RES_EXISTS:
- ast_cli(fd, "Unable to remove interface '%s' from queue '%s': Not there\n", interface, queuename);
- return RESULT_FAILURE;
- case RES_NOSUCHQUEUE:
- ast_cli(fd, "Unable to remove interface from queue '%s': No such queue\n", queuename);
- return RESULT_FAILURE;
- case RES_OUTOFMEMORY:
- ast_cli(fd, "Out of memory\n");
- return RESULT_FAILURE;
- default:
- return RESULT_FAILURE;
- }
-}
-
-static char *complete_remove_queue_member(char *line, char *word, int pos, int state)
-{
- int which = 0;
- struct ast_call_queue *q;
- struct member *m;
-
- /* 0 - add; 1 - queue; 2 - member; 3 - <member>; 4 - to; 5 - <queue> */
- if ((pos > 5) || (pos < 3)) {
- return NULL;
- }
- if (pos == 4) {
- if (state == 0) {
- return strdup("from");
- } else {
- return NULL;
- }
- }
-
- if (pos == 5) {
- /* No need to duplicate code */
- return complete_queue(line, word, pos, state);
- }
-
- if (queues != NULL) {
- for (q = queues ; q ; q = q->next) {
- ast_mutex_lock(&q->lock);
- for (m = q->members ; m ; m = m->next) {
- if (++which > state) {
- ast_mutex_unlock(&q->lock);
- return strdup(m->interface);
- }
- }
- ast_mutex_unlock(&q->lock);
- }
- }
- return NULL;
-}
-
-static char show_queues_usage[] =
-"Usage: show queues\n"
-" Provides summary information on call queues.\n";
-
-static struct ast_cli_entry cli_show_queues = {
- { "show", "queues", NULL }, queues_show,
- "Show status of queues", show_queues_usage, NULL };
-
-static char show_queue_usage[] =
-"Usage: show queue\n"
-" Provides summary information on a specified queue.\n";
-
-static struct ast_cli_entry cli_show_queue = {
- { "show", "queue", NULL }, queue_show,
- "Show status of a specified queue", show_queue_usage, complete_queue };
-
-static char aqm_cmd_usage[] =
-"Usage: add queue member <channel> to <queue> [penalty <penalty>]\n";
-
-static struct ast_cli_entry cli_add_queue_member = {
- { "add", "queue", "member", NULL }, handle_add_queue_member,
- "Add a channel to a specified queue", aqm_cmd_usage, complete_add_queue_member };
-
-static char rqm_cmd_usage[] =
-"Usage: remove queue member <channel> from <queue>\n";
-
-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 };
-
-int unload_module(void)
-{
- int res;
-
- res = ast_cli_unregister(&cli_show_queue);
- res |= ast_cli_unregister(&cli_show_queues);
- res |= ast_cli_unregister(&cli_add_queue_member);
- res |= ast_cli_unregister(&cli_remove_queue_member);
- res |= ast_manager_unregister("Queues");
- res |= ast_manager_unregister("QueueStatus");
- res |= ast_manager_unregister("QueueAdd");
- res |= ast_manager_unregister("QueueRemove");
- res |= ast_manager_unregister("QueuePause");
- ast_devstate_del(statechange_queue, NULL);
- res |= ast_unregister_application(app_aqm);
- res |= ast_unregister_application(app_rqm);
- res |= ast_unregister_application(app_pqm);
- res |= ast_unregister_application(app_upqm);
- res |= ast_custom_function_unregister(&queueagentcount_function);
- res |= ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app, queue_exec, synopsis, descrip);
- res |= ast_cli_register(&cli_show_queue);
- res |= ast_cli_register(&cli_show_queues);
- res |= ast_cli_register(&cli_add_queue_member);
- res |= ast_cli_register(&cli_remove_queue_member);
- res |= ast_devstate_add(statechange_queue, NULL);
- res |= ast_manager_register( "Queues", 0, manager_queues_show, "Queues" );
- res |= ast_manager_register( "QueueStatus", 0, manager_queues_status, "Queue Status" );
- res |= ast_manager_register( "QueueAdd", EVENT_FLAG_AGENT, manager_add_queue_member, "Add interface to queue." );
- res |= ast_manager_register( "QueueRemove", EVENT_FLAG_AGENT, manager_remove_queue_member, "Remove interface from queue." );
- res |= ast_manager_register( "QueuePause", EVENT_FLAG_AGENT, manager_pause_queue_member, "Makes a queue member temporarily unavailable" );
- res |= ast_register_application(app_aqm, aqm_exec, app_aqm_synopsis, app_aqm_descrip) ;
- res |= ast_register_application(app_rqm, rqm_exec, app_rqm_synopsis, app_rqm_descrip) ;
- res |= ast_register_application(app_pqm, pqm_exec, app_pqm_synopsis, app_pqm_descrip) ;
- res |= ast_register_application(app_upqm, upqm_exec, app_upqm_synopsis, app_upqm_descrip) ;
- res |= ast_custom_function_register(&queueagentcount_function);
-
- if (!res) {
- reload_queues();
- if (queue_persistent_members)
- reload_queue_members();
- }
-
- return res;
-}
-
-
-int reload(void)
-{
- reload_queues();
- return 0;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_random.c b/1.2-netsec/apps/app_random.c
deleted file mode 100644
index 57ef4dd32..000000000
--- a/1.2-netsec/apps/app_random.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (c) 2003 - 2005 Tilghman Lesher. All rights reserved.
- *
- * Tilghman Lesher <asterisk__app_random__200508@the-tilghman.com>
- *
- * This code is released by the author with no restrictions on usage or distribution.
- *
- * 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.
- *
- */
-
-/*! \file
- *
- * \brief Random application
- *
- * \author Tilghman Lesher <asterisk__app_random__200508@the-tilghman.com>
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-
-static char *tdesc = "Random goto";
-
-static char *app_random = "Random";
-
-static char *random_synopsis = "Conditionally branches, based upon a probability";
-
-static char *random_descrip =
-"Random([probability]:[[context|]extension|]priority)\n"
-" probability := INTEGER in the range 1 to 100\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static char random_state[256];
-
-static int random_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
-
- char *s;
- char *prob;
- int probint;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Random requires an argument ([probability]:[[context|]extension|]priority)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- s = ast_strdupa(data);
- if (!s) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- prob = strsep(&s,":");
- if ((!prob) || (sscanf(prob, "%d", &probint) != 1))
- probint = 0;
-
- if ((random() % 100) + probint > 100) {
- res = ast_parseable_goto(chan, s);
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Random branches to (%s,%s,%d)\n",
- chan->context,chan->exten, chan->priority+1);
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app_random);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- initstate((getppid() * 65535 + getpid()) % RAND_MAX, random_state, 256);
- return ast_register_application(app_random, random_exec, random_synopsis, random_descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_read.c b/1.2-netsec/apps/app_read.c
deleted file mode 100644
index 90e180fcf..000000000
--- a/1.2-netsec/apps/app_read.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Trivial application to read a variable
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/app.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-
-static char *tdesc = "Read Variable Application";
-
-static char *app = "Read";
-
-static char *synopsis = "Read a variable";
-
-static char *descrip =
-" Read(variable[|filename][|maxdigits][|option][|attempts][|timeout])\n\n"
-"Reads a #-terminated string of digits a certain number of times from the\n"
-"user in to the given variable.\n"
-" filename -- file to play before reading digits.\n"
-" maxdigits -- maximum acceptable number of digits. Stops reading after\n"
-" maxdigits have been entered (without requiring the user to\n"
-" press the '#' key).\n"
-" Defaults to 0 - no limit - wait for the user press the '#' key.\n"
-" Any value below 0 means the same. Max accepted value is 255.\n"
-" option -- may be 'skip' to return immediately if the line is not up,\n"
-" or 'noanswer' to read digits even if the line is not up.\n"
-" attempts -- if greater than 1, that many attempts will be made in the \n"
-" event no data is entered.\n"
-" timeout -- if greater than 0, that value will override the default timeout.\n\n"
-"Read should disconnect if the function fails or errors out.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-#define ast_next_data(instr,ptr,delim) if((ptr=strchr(instr,delim))) { *(ptr) = '\0' ; ptr++;}
-
-static int read_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- char tmp[256];
- char *timeout = NULL;
- char *varname = NULL;
- char *filename = NULL;
- char *loops;
- char *maxdigitstr=NULL;
- char *options=NULL;
- int option_skip = 0;
- int option_noanswer = 0;
- int maxdigits=255;
- int tries = 1;
- int to = 0;
- int x = 0;
- char *argcopy = NULL;
- char *args[8];
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Read requires an argument (variable)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- argcopy = ast_strdupa(data);
- if (!argcopy) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (ast_app_separate_args(argcopy, '|', args, sizeof(args) / sizeof(args[0])) < 1) {
- ast_log(LOG_WARNING, "Cannot Parse Arguments.\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- varname = args[x++];
- filename = args[x++];
- maxdigitstr = args[x++];
- options = args[x++];
- loops = args[x++];
- timeout = args[x++];
-
- if (options) {
- if (!strcasecmp(options, "skip"))
- option_skip = 1;
- else if (!strcasecmp(options, "noanswer"))
- option_noanswer = 1;
- else {
- if (strchr(options, 's'))
- option_skip = 1;
- if (strchr(options, 'n'))
- option_noanswer = 1;
- }
- }
-
- if(loops) {
- tries = atoi(loops);
- if(tries <= 0)
- tries = 1;
- }
-
- if(timeout) {
- to = atoi(timeout);
- if (to <= 0)
- to = 0;
- else
- to *= 1000;
- }
-
- if (ast_strlen_zero(filename))
- filename = NULL;
- if (maxdigitstr) {
- maxdigits = atoi(maxdigitstr);
- if ((maxdigits<1) || (maxdigits>255)) {
- maxdigits = 255;
- } else if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Accepting a maximum of %d digits.\n", maxdigits);
- }
- if (ast_strlen_zero(varname)) {
- ast_log(LOG_WARNING, "Invalid! Usage: Read(variable[|filename][|maxdigits][|option][|attempts][|timeout])\n\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (chan->_state != AST_STATE_UP) {
- if (option_skip) {
- /* At the user's option, skip if the line is not up */
- pbx_builtin_setvar_helper(chan, varname, "\0");
- LOCAL_USER_REMOVE(u);
- return 0;
- } else if (!option_noanswer) {
- /* Otherwise answer unless we're supposed to read while on-hook */
- res = ast_answer(chan);
- }
- }
- if (!res) {
- while(tries && !res) {
- ast_stopstream(chan);
- res = ast_app_getdata(chan, filename, tmp, maxdigits, to);
- if (res > -1) {
- pbx_builtin_setvar_helper(chan, varname, tmp);
- if (!ast_strlen_zero(tmp)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "User entered '%s'\n", tmp);
- tries = 0;
- } else {
- tries--;
- if (option_verbose > 2) {
- if (tries)
- ast_verbose(VERBOSE_PREFIX_3 "User entered nothing, %d chance%s left\n", tries, (tries != 1) ? "s" : "");
- else
- ast_verbose(VERBOSE_PREFIX_3 "User entered nothing.\n");
- }
- }
- res = 0;
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "User disconnected\n");
- }
- }
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, read_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_readfile.c b/1.2-netsec/apps/app_readfile.c
deleted file mode 100644
index 3340964b7..000000000
--- a/1.2-netsec/apps/app_readfile.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Matt O'Gorman <mogorman@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief ReadFile application -- Reads in a File for you.
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/app.h"
-#include "asterisk/module.h"
-
-static char *tdesc = "Stores output of file into a variable";
-
-static char *app_readfile = "ReadFile";
-
-static char *readfile_synopsis = "ReadFile(varname=file,length)";
-
-static char *readfile_descrip =
-"ReadFile(varname=file,length)\n"
-" Varname - Result stored here.\n"
-" File - The name of the file to read.\n"
-" Length - Maximum number of characters to capture.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-
-static int readfile_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *s, *varname=NULL, *file=NULL, *length=NULL, *returnvar=NULL;
- int len=0;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "ReadFile require an argument!\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- s = ast_strdupa(data);
- if (!s) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- varname = strsep(&s, "=");
- file = strsep(&s, "|");
- length = s;
-
- if (!varname || !file) {
- ast_log(LOG_ERROR, "No file or variable specified!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (length) {
- if ((sscanf(length, "%d", &len) != 1) || (len < 0)) {
- ast_log(LOG_WARNING, "%s is not a positive number, defaulting length to max\n", length);
- len = 0;
- }
- }
-
- returnvar = ast_read_textfile(file);
- if(len > 0){
- if(len < strlen(returnvar))
- returnvar[len]='\0';
- else
- ast_log(LOG_WARNING,"%s is longer than %d, and %d \n", file, len, (int)strlen(returnvar));
- }
- pbx_builtin_setvar_helper(chan, varname, returnvar);
- free(returnvar);
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app_readfile);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app_readfile, readfile_exec, readfile_synopsis, readfile_descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_realtime.c b/1.2-netsec/apps/app_realtime.c
deleted file mode 100644
index a731fd7c9..000000000
--- a/1.2-netsec/apps/app_realtime.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Anthony Minessale <anthmct@yahoo.com>
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief RealTime App
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/options.h"
-#include "asterisk/pbx.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/cli.h"
-
-#define next_one(var) var = var->next
-#define crop_data(str) { *(str) = '\0' ; (str)++; }
-
-static char *tdesc = "Realtime Data Lookup/Rewrite";
-static char *app = "RealTime";
-static char *uapp = "RealTimeUpdate";
-static char *synopsis = "Realtime Data Lookup";
-static char *usynopsis = "Realtime Data Rewrite";
-static char *USAGE = "RealTime(<family>|<colmatch>|<value>[|<prefix>])";
-static char *UUSAGE = "RealTimeUpdate(<family>|<colmatch>|<value>|<newcol>|<newval>)";
-static char *desc = "Use the RealTime config handler system to read data into channel variables.\n"
-"RealTime(<family>|<colmatch>|<value>[|<prefix>])\n\n"
-"All unique column names will be set as channel variables with optional prefix to the name.\n"
-"e.g. prefix of 'var_' would make the column 'name' become the variable ${var_name}\n\n";
-static char *udesc = "Use the RealTime config handler system to update a value\n"
-"RealTimeUpdate(<family>|<colmatch>|<value>|<newcol>|<newval>)\n\n"
-"The column <newcol> in 'family' matching column <colmatch>=<value> will be updated to <newval>\n";
-
-STANDARD_LOCAL_USER;
-LOCAL_USER_DECL;
-
-static int cli_load_realtime(int fd, int argc, char **argv)
-{
- char *header_format = "%30s %-30s\n";
- struct ast_variable *var=NULL;
-
- if(argc<5) {
- ast_cli(fd, "You must supply a family name, a column to match on, and a value to match to.\n");
- return RESULT_FAILURE;
- }
-
- var = ast_load_realtime(argv[2], argv[3], argv[4], NULL);
-
- if(var) {
- ast_cli(fd, header_format, "Column Name", "Column Value");
- ast_cli(fd, header_format, "--------------------", "--------------------");
- while(var) {
- ast_cli(fd, header_format, var->name, var->value);
- var = var->next;
- }
- } else {
- ast_cli(fd, "No rows found matching search criteria.\n");
- }
- return RESULT_SUCCESS;
-}
-
-static int cli_update_realtime(int fd, int argc, char **argv) {
- int res = 0;
-
- if(argc<7) {
- ast_cli(fd, "You must supply a family name, a column to update on, a new value, column to match, and value to to match.\n");
- ast_cli(fd, "Ex: realtime update sipfriends name bobsphone port 4343\n will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n");
- return RESULT_FAILURE;
- }
-
- res = ast_update_realtime(argv[2], argv[3], argv[4], argv[5], argv[6], NULL);
-
- if(res < 0) {
- ast_cli(fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
- return RESULT_SUCCESS;
- }
-
- ast_cli(fd, "Updated %d RealTime record%s.\n", res, (res != 1) ? "s" : "");
-
- return RESULT_SUCCESS;
-}
-
-static char cli_load_realtime_usage[] =
-"Usage: realtime load <family> <colmatch> <value>\n"
-" Prints out a list of variables using the RealTime driver.\n";
-
-static struct ast_cli_entry cli_load_realtime_cmd = {
- { "realtime", "load", NULL, NULL }, cli_load_realtime,
- "Used to print out RealTime variables.", cli_load_realtime_usage, NULL };
-
-static char cli_update_realtime_usage[] =
-"Usage: realtime update <family> <colmatch> <value>\n"
-" Update a single variable using the RealTime driver.\n";
-
-static struct ast_cli_entry cli_update_realtime_cmd = {
- { "realtime", "update", NULL, NULL }, cli_update_realtime,
- "Used to update RealTime variables.", cli_update_realtime_usage, NULL };
-
-static int realtime_update_exec(struct ast_channel *chan, void *data)
-{
- char *family=NULL, *colmatch=NULL, *value=NULL, *newcol=NULL, *newval=NULL;
- struct localuser *u;
- int res = 0;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_ERROR,"Invalid input: usage %s\n",UUSAGE);
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if ((family = ast_strdupa(data))) {
- if ((colmatch = strchr(family,'|'))) {
- crop_data(colmatch);
- if ((value = strchr(colmatch,'|'))) {
- crop_data(value);
- if ((newcol = strchr(value,'|'))) {
- crop_data(newcol);
- if ((newval = strchr(newcol,'|')))
- crop_data(newval);
- }
- }
- }
- }
- if (! (family && value && colmatch && newcol && newval) ) {
- ast_log(LOG_ERROR,"Invalid input: usage %s\n",UUSAGE);
- res = -1;
- } else {
- ast_update_realtime(family,colmatch,value,newcol,newval,NULL);
- }
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-
-static int realtime_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- struct ast_variable *var, *itt;
- char *family=NULL, *colmatch=NULL, *value=NULL, *prefix=NULL, *vname=NULL;
- size_t len;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_ERROR,"Invalid input: usage %s\n",USAGE);
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if ((family = ast_strdupa(data))) {
- if ((colmatch = strchr(family,'|'))) {
- crop_data(colmatch);
- if ((value = strchr(colmatch,'|'))) {
- crop_data(value);
- if ((prefix = strchr(value,'|')))
- crop_data(prefix);
- }
- }
- }
- if (! (family && value && colmatch) ) {
- ast_log(LOG_ERROR,"Invalid input: usage %s\n",USAGE);
- res = -1;
- } else {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4"Realtime Lookup: family:'%s' colmatch:'%s' value:'%s'\n",family,colmatch,value);
- if ((var = ast_load_realtime(family, colmatch, value, NULL))) {
- for (itt = var; itt; itt = itt->next) {
- if(prefix) {
- len = strlen(prefix) + strlen(itt->name) + 2;
- vname = alloca(len);
- snprintf(vname,len,"%s%s",prefix,itt->name);
-
- } else
- vname = itt->name;
-
- pbx_builtin_setvar_helper(chan, vname, itt->value);
- }
- ast_variables_destroy(var);
- } else if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4"No Realtime Matches Found.\n");
- }
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_cli_unregister(&cli_load_realtime_cmd);
- res |= ast_cli_unregister(&cli_update_realtime_cmd);
- res |= ast_unregister_application(uapp);
- res |= ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_cli_register(&cli_load_realtime_cmd);
- res |= ast_cli_register(&cli_update_realtime_cmd);
- res |= ast_register_application(uapp, realtime_update_exec, usynopsis, udesc);
- res |= ast_register_application(app, realtime_exec, synopsis, desc);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_record.c b/1.2-netsec/apps/app_record.c
deleted file mode 100644
index 85310ea70..000000000
--- a/1.2-netsec/apps/app_record.c
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Matthew Fredrickson <creslin@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Trivial application to record a sound file
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/dsp.h"
-#include "asterisk/utils.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Trivial Record Application";
-
-static char *app = "Record";
-
-static char *synopsis = "Record to a file";
-
-static char *descrip =
-" Record(filename.format|silence[|maxduration][|options])\n\n"
-"Records from the channel into a given filename. If the file exists it will\n"
-"be overwritten.\n"
-"- 'format' is the format of the file type to be recorded (wav, gsm, etc).\n"
-"- 'silence' is the number of seconds of silence to allow before returning.\n"
-"- 'maxduration' is the maximum recording duration in seconds. If missing\n"
-"or 0 there is no maximum.\n"
-"- 'options' may contain any of the following letters:\n"
-" 'a' : append to existing recording rather than replacing\n"
-" 'n' : do not answer, but record anyway if line not yet answered\n"
-" 'q' : quiet (do not play a beep tone)\n"
-" 's' : skip recording if the line is not yet answered\n"
-" 't' : use alternate '*' terminator key instead of default '#'\n"
-"\n"
-"If filename contains '%d', these characters will be replaced with a number\n"
-"incremented by one each time the file is recorded. \n\n"
-"Use 'show file formats' to see the available formats on your system\n\n"
-"User can press '#' to terminate the recording and continue to the next priority.\n\n"
-"If the user should hangup during a recording, all data will be lost and the\n"
-"application will teminate. \n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int record_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- int count = 0;
- int percentflag = 0;
- char *filename, *ext = NULL, *silstr, *maxstr, *options;
- char *vdata, *p;
- int i = 0;
- char tmp[256];
-
- struct ast_filestream *s = '\0';
- struct localuser *u;
- struct ast_frame *f = NULL;
-
- struct ast_dsp *sildet = NULL; /* silence detector dsp */
- int totalsilence = 0;
- int dspsilence = 0;
- int silence = 0; /* amount of silence to allow */
- int gotsilence = 0; /* did we timeout for silence? */
- int maxduration = 0; /* max duration of recording in milliseconds */
- int gottimeout = 0; /* did we timeout for maxduration exceeded? */
- int option_skip = 0;
- int option_noanswer = 0;
- int option_append = 0;
- int terminator = '#';
- int option_quiet = 0;
- int rfmt = 0;
- int flags;
- int waitres;
- struct ast_silence_generator *silgen = NULL;
-
- /* The next few lines of code parse out the filename and header from the input string */
- if (ast_strlen_zero(data)) { /* no data implies no filename or anything is present */
- ast_log(LOG_WARNING, "Record requires an argument (filename)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- /* Yay for strsep being easy */
- vdata = ast_strdupa(data);
- if (!vdata) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- p = vdata;
- filename = strsep(&p, "|");
- silstr = strsep(&p, "|");
- maxstr = strsep(&p, "|");
- options = strsep(&p, "|");
-
- if (filename) {
- if (strstr(filename, "%d"))
- percentflag = 1;
- ext = strrchr(filename, '.'); /* to support filename with a . in the filename, not format */
- if (!ext)
- ext = strchr(filename, ':');
- if (ext) {
- *ext = '\0';
- ext++;
- }
- }
- if (!ext) {
- ast_log(LOG_WARNING, "No extension specified to filename!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- if (silstr) {
- if ((sscanf(silstr, "%d", &i) == 1) && (i > -1)) {
- silence = i * 1000;
- } else if (!ast_strlen_zero(silstr)) {
- ast_log(LOG_WARNING, "'%s' is not a valid silence duration\n", silstr);
- }
- }
-
- if (maxstr) {
- if ((sscanf(maxstr, "%d", &i) == 1) && (i > -1))
- /* Convert duration to milliseconds */
- maxduration = i * 1000;
- else if (!ast_strlen_zero(maxstr))
- ast_log(LOG_WARNING, "'%s' is not a valid maximum duration\n", maxstr);
- }
- if (options) {
- /* Retain backwards compatibility with old style options */
- if (!strcasecmp(options, "skip"))
- option_skip = 1;
- else if (!strcasecmp(options, "noanswer"))
- option_noanswer = 1;
- else {
- if (strchr(options, 's'))
- option_skip = 1;
- if (strchr(options, 'n'))
- option_noanswer = 1;
- if (strchr(options, 'a'))
- option_append = 1;
- if (strchr(options, 't'))
- terminator = '*';
- if (strchr(options, 'q'))
- option_quiet = 1;
- }
- }
-
- /* done parsing */
-
- /* these are to allow the use of the %d in the config file for a wild card of sort to
- create a new file with the inputed name scheme */
- if (percentflag) {
- do {
- snprintf(tmp, sizeof(tmp), filename, count);
- count++;
- } while ( ast_fileexists(tmp, ext, chan->language) != -1 );
- pbx_builtin_setvar_helper(chan, "RECORDED_FILE", tmp);
- } else
- strncpy(tmp, filename, sizeof(tmp)-1);
- /* end of routine mentioned */
-
-
-
- if (chan->_state != AST_STATE_UP) {
- if (option_skip) {
- /* At the user's option, skip if the line is not up */
- LOCAL_USER_REMOVE(u);
- return 0;
- } else if (!option_noanswer) {
- /* Otherwise answer unless we're supposed to record while on-hook */
- res = ast_answer(chan);
- }
- }
-
- if (res) {
- ast_log(LOG_WARNING, "Could not answer channel '%s'\n", chan->name);
- goto out;
- }
-
- if (!option_quiet) {
- /* Some code to play a nice little beep to signify the start of the record operation */
- res = ast_streamfile(chan, "beep", chan->language);
- if (!res) {
- res = ast_waitstream(chan, "");
- } else {
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", chan->name);
- }
- ast_stopstream(chan);
- }
-
- /* The end of beep code. Now the recording starts */
-
- if (silence > 0) {
- 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");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- sildet = ast_dsp_new();
- if (!sildet) {
- ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- ast_dsp_set_threshold(sildet, 256);
- }
-
-
- flags = option_append ? O_CREAT|O_APPEND|O_WRONLY : O_CREAT|O_TRUNC|O_WRONLY;
- s = ast_writefile( tmp, ext, NULL, flags , 0, 0644);
-
- if (!s) {
- ast_log(LOG_WARNING, "Could not create file %s\n", filename);
- goto out;
- }
-
- if (option_transmit_silence_during_record)
- silgen = ast_channel_start_silence_generator(chan);
-
- /* Request a video update */
- ast_indicate(chan, AST_CONTROL_VIDUPDATE);
-
- if (maxduration <= 0)
- maxduration = -1;
-
- while ((waitres = ast_waitfor(chan, maxduration)) > -1) {
- if (maxduration > 0) {
- if (waitres == 0) {
- gottimeout = 1;
- break;
- }
- maxduration = waitres;
- }
-
- f = ast_read(chan);
- if (!f) {
- res = -1;
- break;
- }
- if (f->frametype == AST_FRAME_VOICE) {
- res = ast_writestream(s, f);
-
- if (res) {
- ast_log(LOG_WARNING, "Problem writing frame\n");
- ast_frfree(f);
- break;
- }
-
- if (silence > 0) {
- dspsilence = 0;
- ast_dsp_silence(sildet, f, &dspsilence);
- if (dspsilence) {
- totalsilence = dspsilence;
- } else {
- totalsilence = 0;
- }
- if (totalsilence > silence) {
- /* Ended happily with silence */
- ast_frfree(f);
- gotsilence = 1;
- break;
- }
- }
- } else if (f->frametype == AST_FRAME_VIDEO) {
- res = ast_writestream(s, f);
-
- if (res) {
- ast_log(LOG_WARNING, "Problem writing frame\n");
- ast_frfree(f);
- break;
- }
- } else if ((f->frametype == AST_FRAME_DTMF) &&
- (f->subclass == terminator)) {
- ast_frfree(f);
- break;
- }
- ast_frfree(f);
- }
- if (!f) {
- ast_log(LOG_DEBUG, "Got hangup\n");
- res = -1;
- }
-
- if (gotsilence) {
- ast_stream_rewind(s, silence-1000);
- ast_truncstream(s);
- } else if (!gottimeout) {
- /* Strip off the last 1/4 second of it */
- ast_stream_rewind(s, 250);
- ast_truncstream(s);
- }
- ast_closestream(s);
-
- if (silgen)
- ast_channel_stop_silence_generator(chan, silgen);
-
- out:
- if ((silence > 0) && rfmt) {
- res = ast_set_read_format(chan, rfmt);
- if (res)
- ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
- if (sildet)
- ast_dsp_free(sildet);
- }
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, record_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_rpt.c b/1.2-netsec/apps/app_rpt.c
deleted file mode 100644
index c8b10e44d..000000000
--- a/1.2-netsec/apps/app_rpt.c
+++ /dev/null
@@ -1,6560 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2002-2005, Jim Dixon, WB6NIL
- *
- * Jim Dixon, WB6NIL <jim@lambdatel.com>
- * Serious contributions by Steve RoDgers, WA6ZFT <hwstar@rodgers.sdcoxmail.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
- *
- * Radio Repeater / Remote Base program
- * version 0.37 11/3/05
- *
- * See http://www.zapatatelephony.org/app_rpt.html
- *
- *
- * Repeater / Remote Functions:
- * "Simple" Mode: * - autopatch access, # - autopatch hangup
- * Normal mode:
- * See the function list in rpt.conf
- *
- * To send an asterisk (*) while dialing or talking on phone,
- * use the autopatch acess code.
- *
- *
- * status cmds:
- *
- * 1 - Force ID
- * 2 - Give Time of Day
- * 3 - Give software Version
- *
- * cop (control operator) cmds:
- *
- * 1 - System warm boot
- * 2 - System enable
- * 3 - System disable
- * 4 - Test Tone On
- * 5 - Dump System Variables on Console (debug)
- * 6 - PTT (phone mode only)
- *
- * ilink cmds:
- *
- * 1 - Disconnect specified link
- * 2 - Connect specified link -- monitor only
- * 3 - Connect specified link -- tranceive
- * 4 - Enter command mode on specified link
- * 5 - System status
- * 6 - Disconnect all links
- *
- * remote cmds:
- *
- * 1 - Recall Memory MM (*000-*099) (Gets memory from rpt.conf)
- * 2 - Set VFO MMMMM*KKK*O (Mhz digits, Khz digits, Offset)
- * 3 - Set Rx PL Tone HHH*D*
- * 4 - Set Tx PL Tone HHH*D* (Not currently implemented with DHE RBI-1)
- * 5 - Link Status (long)
- * 6 - Set operating mode M (FM, USB, LSB, AM, etc)
- * 100 - RX PL off (Default)
- * 101 - RX PL On
- * 102 - TX PL Off (Default)
- * 103 - TX PL On
- * 104 - Low Power
- * 105 - Med Power
- * 106 - Hi Power
- * 107 - Bump Down 20 Hz
- * 108 - Bump Down 100 Hz
- * 109 - Bump Down 500 Hz
- * 110 - Bump Up 20 Hz
- * 111 - Bump Up 100 Hz
- * 112 - Bump Up 500 Hz
- * 113 - Scan Down Slow
- * 114 - Scan Down Medium
- * 115 - Scan Down Fast
- * 116 - Scan Up Slow
- * 117 - Scan Up Medium
- * 118 - Scan Up Fast
- * 119 - Transmit allowing auto-tune
- * 140 - Link Status (brief)
- *
- *
-*/
-
-/* The following is JUST GROSS!! There is some soft of underlying problem,
- probably in channel_iax2.c, that causes an IAX2 connection to sometimes
- stop transmitting randomly. We have been working for weeks to try to
- locate it and fix it, but to no avail We finally decided to put our
- tail between our legs, and just make the radio system re-connect upon
- network failure. This just shouldnt have to be done. For normal operation,
- comment-out the following line */
-#define RECONNECT_KLUDGE
-
-/* maximum digits in DTMF buffer, and seconds after * for DTMF command timeout */
-
-#define MAXDTMF 32
-#define DTMF_TIMEOUT 3
-
-#define DISC_TIME 10000 /* report disc after 10 seconds of no connect */
-#define MAX_RETRIES 5
-
-#define REDUNDANT_TX_TIME 2000
-
-#define RETRY_TIMER_MS 5000
-
-#define MAXREMSTR 15
-
-#define NODES "nodes"
-#define MEMORY "memory"
-#define FUNCTIONS "functions"
-#define TELEMETRY "telemetry"
-#define MORSE "morse"
-#define FUNCCHAR '*'
-#define ENDCHAR '#'
-
-#define DEFAULT_IOBASE 0x378
-
-#define MAXCONNECTTIME 5000
-
-#define MAXNODESTR 300
-
-#define ACTIONSIZE 32
-
-#define TELEPARAMSIZE 256
-
-#define REM_SCANTIME 100
-
-
-enum {REM_OFF,REM_MONITOR,REM_TX};
-
-enum{ID,PROC,TERM,COMPLETE,UNKEY,REMDISC,REMALREADY,REMNOTFOUND,REMGO,
- CONNECTED,CONNFAIL,STATUS,TIMEOUT,ID1, STATS_TIME,
- STATS_VERSION, IDTALKOVER, ARB_ALPHA, TEST_TONE, REV_PATCH};
-
-enum {REM_SIMPLEX,REM_MINUS,REM_PLUS};
-
-enum {REM_LOWPWR,REM_MEDPWR,REM_HIPWR};
-
-enum {DC_INDETERMINATE, DC_REQ_FLUSH, DC_ERROR, DC_COMPLETE, DC_DOKEY};
-
-enum {SOURCE_RPT, SOURCE_LNK, SOURCE_RMT, SOURCE_PHONE, SOURCE_DPHONE};
-
-enum {DLY_TELEM, DLY_ID, DLY_UNKEY, DLY_CALLTERM};
-
-enum {REM_MODE_FM,REM_MODE_USB,REM_MODE_LSB,REM_MODE_AM};
-
-enum {HF_SCAN_OFF,HF_SCAN_DOWN_SLOW,HF_SCAN_DOWN_QUICK,HF_SCAN_DOWN_FAST,HF_SCAN_UP_SLOW,HF_SCAN_UP_QUICK,HF_SCAN_UP_FAST};
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include <signal.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <search.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <dirent.h>
-#include <ctype.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <sys/io.h>
-#include <math.h>
-#include <tonezone.h>
-#include <linux/zaptel.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/callerid.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/features.h"
-#include "asterisk/options.h"
-#include "asterisk/cli.h"
-#include "asterisk/config.h"
-#include "asterisk/say.h"
-#include "asterisk/localtime.h"
-
-static char *tdesc = "Radio Repeater / Remote Base version 0.37 11/03/2005";
-
-static char *app = "Rpt";
-
-static char *synopsis = "Radio Repeater/Remote Base Control System";
-
-static char *descrip =
-" Rpt(nodename[|options]): Radio Remote Link or Remote Base Link Endpoint Process.\n"
-"\n"
-" Not specifying an option puts it in normal endpoint mode (where source\n"
-" IP and nodename are verified).\n"
-"\n"
-" Options are as follows:\n"
-"\n"
-" X - Normal endpoint mode WITHOUT security check. Only specify\n"
-" this if you have checked security already (like with an IAX2\n"
-" user/password or something).\n"
-"\n"
-" Rannounce-string[|timeout[|timeout-destination]] - Amateur Radio\n"
-" Reverse Autopatch. Caller is put on hold, and announcement (as\n"
-" specified by the 'announce-string') is played on radio system.\n"
-" Users of radio system can access autopatch, dial specified\n"
-" code, and pick up call. Announce-string is list of names of\n"
-" recordings, or \"PARKED\" to substitute code for un-parking,\n"
-" or \"NODE\" to substitute node number.\n"
-"\n"
-" P - Phone Control mode. This allows a regular phone user to have\n"
-" full control and audio access to the radio system. For the\n"
-" user to have DTMF control, the 'phone_functions' parameter\n"
-" must be specified for the node in 'rpt.conf'. An additional\n"
-" function (cop,6) must be listed so that PTT control is available.\n"
-"\n"
-" D - Dumb Phone Control mode. This allows a regular phone user to\n"
-" have full control and audio access to the radio system. In this\n"
-" mode, the PTT is activated for the entire length of the call.\n"
-" For the user to have DTMF control (not generally recomended in\n"
-" this mode), the 'dphone_functions' parameter must be specified\n"
-" for the node in 'rpt.conf'. Otherwise no DTMF control will be\n"
-" available to the phone user.\n"
-"\n";
-
-static int debug = 0; /* Set this >0 for extra debug output */
-static int nrpts = 0;
-
-char *discstr = "!!DISCONNECT!!";
-static char *remote_rig_ft897="ft897";
-static char *remote_rig_rbi="rbi";
-
-struct ast_config *cfg;
-
-STANDARD_LOCAL_USER;
-LOCAL_USER_DECL;
-
-#define MSWAIT 200
-#define HANGTIME 5000
-#define TOTIME 180000
-#define IDTIME 300000
-#define MAXRPTS 20
-#define POLITEID 30000
-#define FUNCTDELAY 1500
-
-static pthread_t rpt_master_thread;
-
-struct rpt;
-
-struct rpt_link
-{
- struct rpt_link *next;
- struct rpt_link *prev;
- char mode; /* 1 if in tx mode */
- char isremote;
- char phonemode;
- char name[MAXNODESTR]; /* identifier (routing) string */
- char lasttx;
- char lastrx;
- char connected;
- char hasconnected;
- char outbound;
- char disced;
- char killme;
- long elaptime;
- long disctime;
- long retrytimer;
- long retxtimer;
- int retries;
- struct ast_channel *chan;
- struct ast_channel *pchan;
-} ;
-
-struct rpt_tele
-{
- struct rpt_tele *next;
- struct rpt_tele *prev;
- struct rpt *rpt;
- struct ast_channel *chan;
- int mode;
- struct rpt_link mylink;
- char param[TELEPARAMSIZE];
- pthread_t threadid;
-} ;
-
-struct function_table_tag
-{
- char action[ACTIONSIZE];
- int (*function)(struct rpt *myrpt, char *param, char *digitbuf,
- int command_source, struct rpt_link *mylink);
-} ;
-
-/* Used to store the morse code patterns */
-
-struct morse_bits
-{
- int len;
- int ddcomb;
-} ;
-
-struct telem_defaults
-{
- char name[20];
- char value[80];
-} ;
-
-
-static struct rpt
-{
- char *name;
- ast_mutex_t lock;
- char *rxchanname;
- char *txchanname;
- char *ourcontext;
- char *ourcallerid;
- char *acctcode;
- char *ident;
- char *tonezone;
- char *functions;
- char *link_functions;
- char *phone_functions;
- char *dphone_functions;
- char *nodes;
- struct rpt_link links;
- int hangtime;
- int totime;
- int idtime;
- int unkeytocttimer;
- char keyed;
- char exttx;
- char localtx;
- char remoterx;
- char remotetx;
- char remoteon;
- char simple;
- char *remote;
- char tounkeyed;
- char tonotify;
- char enable;
- char dtmfbuf[MAXDTMF];
- char rem_dtmfbuf[MAXDTMF];
- char cmdnode[50];
- struct ast_channel *rxchannel,*txchannel;
- struct ast_channel *pchannel,*txpchannel, *remchannel;
- struct rpt_tele tele;
- pthread_t rpt_call_thread,rpt_thread;
- time_t rem_dtmf_time,dtmf_time_rem;
- int tailtimer,totimer,idtimer,txconf,conf,callmode,cidx,scantimer;
- int mustid;
- int politeid;
- int dtmfidx,rem_dtmfidx;
- long retxtimer;
- char mydtmf;
- int iobase;
- char exten[AST_MAX_EXTENSION];
- char freq[MAXREMSTR],rxpl[MAXREMSTR],txpl[MAXREMSTR];
- char offset;
- char powerlevel;
- char txplon;
- char rxplon;
- char remmode;
- char tunerequest;
- char hfscanmode;
- int hfscanstatus;
- char lastlinknode[MAXNODESTR];
- char funcchar;
- char endchar;
- char stopgen;
- int phone_longestfunc;
- int dphone_longestfunc;
- int link_longestfunc;
- int longestfunc;
- int longestnode;
- int threadrestarts;
- time_t disgorgetime;
- time_t lastthreadrestarttime;
- char nobusyout;
-} rpt_vars[MAXRPTS];
-
-/*
-* CLI extensions
-*/
-
-/* Debug mode */
-static int rpt_do_debug(int fd, int argc, char *argv[]);
-
-static char debug_usage[] =
-"Usage: rpt debug level {0-7}\n"
-" Enables debug messages in app_rpt\n";
-
-static struct ast_cli_entry cli_debug =
- { { "rpt", "debug", "level" }, rpt_do_debug, "Enable app_rpt debugging", debug_usage };
-
-
-
-/*
-* Telemetry defaults
-*/
-
-
-static struct telem_defaults tele_defs[] = {
- {"ct1","|t(350,0,100,3072)(500,0,100,3072)(660,0,100,3072)"},
- {"ct2","|t(660,880,150,3072)"},
- {"ct3","|t(440,0,150,3072)"},
- {"ct4","|t(550,0,150,3072)"},
- {"ct5","|t(660,0,150,3072)"},
- {"ct6","|t(880,0,150,3072)"},
- {"ct7","|t(660,440,150,3072)"},
- {"ct8","|t(700,1100,150,3072)"},
- {"remotemon","|t(1600,0,75,2048)"},
- {"remotetx","|t(2000,0,75,2048)(0,0,75,0)(1600,0,75,2048)"},
- {"cmdmode","|t(900,904,200,2048)"},
- {"functcomplete","|t(1000,0,100,2048)(0,0,100,0)(1000,0,100,2048)"}
-} ;
-
-/*
-* Forward decl's - these suppress compiler warnings when funcs coded further down the file than thier invokation
-*/
-
-static int setrbi(struct rpt *myrpt);
-
-
-
-/*
-* Define function protos for function table here
-*/
-
-static int function_ilink(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
-static int function_autopatchup(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
-static int function_autopatchdn(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
-static int function_status(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
-static int function_cop(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
-static int function_remote(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
-/*
-* Function table
-*/
-
-static struct function_table_tag function_table[] = {
- {"cop", function_cop},
- {"autopatchup", function_autopatchup},
- {"autopatchdn", function_autopatchdn},
- {"ilink", function_ilink},
- {"status", function_status},
- {"remote", function_remote}
-} ;
-
-static int myatoi(char *str)
-{
-int ret;
-
- if (str == NULL) return -1;
- /* leave this %i alone, non-base-10 input is useful here */
- if (sscanf(str,"%i",&ret) != 1) return -1;
- return ret;
-}
-
-/*
-* Enable or disable debug output at a given level at the console
-*/
-
-static int rpt_do_debug(int fd, int argc, char *argv[])
-{
- int newlevel;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- newlevel = myatoi(argv[3]);
- if((newlevel < 0) || (newlevel > 7))
- return RESULT_SHOWUSAGE;
- if(newlevel)
- ast_cli(fd, "app_rpt Debugging enabled, previous level: %d, new level: %d\n", debug, newlevel);
- else
- ast_cli(fd, "app_rpt Debugging disabled\n");
-
- debug = newlevel;
- return RESULT_SUCCESS;
-}
-
-
-
-static int play_tone_pair(struct ast_channel *chan, int f1, int f2, int duration, int amplitude)
-{
- int res;
-
- if ((res = ast_tonepair_start(chan, f1, f2, duration, amplitude)))
- return res;
-
- while(chan->generatordata) {
- if (ast_safe_sleep(chan,1)) return -1;
- }
-
- return 0;
-}
-
-static int play_tone(struct ast_channel *chan, int freq, int duration, int amplitude)
-{
- return play_tone_pair(chan, freq, 0, duration, amplitude);
-}
-
-static int play_silence(struct ast_channel *chan, int duration)
-{
- return play_tone_pair(chan, 0, 0, duration, 0);
-}
-
-
-static int send_morse(struct ast_channel *chan, char *string, int speed, int freq, int amplitude)
-{
-
-static struct morse_bits mbits[] = {
- {0, 0}, /* SPACE */
- {0, 0},
- {6, 18},/* " */
- {0, 0},
- {7, 72},/* $ */
- {0, 0},
- {0, 0},
- {6, 30},/* ' */
- {5, 13},/* ( */
- {6, 29},/* ) */
- {0, 0},
- {5, 10},/* + */
- {6, 51},/* , */
- {6, 33},/* - */
- {6, 42},/* . */
- {5, 9}, /* / */
- {5, 31},/* 0 */
- {5, 30},/* 1 */
- {5, 28},/* 2 */
- {5, 24},/* 3 */
- {5, 16},/* 4 */
- {5, 0}, /* 5 */
- {5, 1}, /* 6 */
- {5, 3}, /* 7 */
- {5, 7}, /* 8 */
- {5, 15},/* 9 */
- {6, 7}, /* : */
- {6, 21},/* ; */
- {0, 0},
- {5, 33},/* = */
- {0, 0},
- {6, 12},/* ? */
- {0, 0},
- {2, 2}, /* A */
- {4, 1}, /* B */
- {4, 5}, /* C */
- {3, 1}, /* D */
- {1, 0}, /* E */
- {4, 4}, /* F */
- {3, 3}, /* G */
- {4, 0}, /* H */
- {2, 0}, /* I */
- {4, 14},/* J */
- {3, 5}, /* K */
- {4, 2}, /* L */
- {2, 3}, /* M */
- {2, 1}, /* N */
- {3, 7}, /* O */
- {4, 6}, /* P */
- {4, 11},/* Q */
- {3, 2}, /* R */
- {3, 0}, /* S */
- {1, 1}, /* T */
- {3, 4}, /* U */
- {4, 8}, /* V */
- {3, 6}, /* W */
- {4, 9}, /* X */
- {4, 13},/* Y */
- {4, 3} /* Z */
- };
-
-
- int dottime;
- int dashtime;
- int intralettertime;
- int interlettertime;
- int interwordtime;
- int len, ddcomb;
- int res;
- int c;
- int i;
- int flags;
-
- res = 0;
-
- /* Approximate the dot time from the speed arg. */
-
- dottime = 900/speed;
-
- /* Establish timing releationships */
-
- dashtime = 3 * dottime;
- intralettertime = dottime;
- interlettertime = dottime * 4 ;
- interwordtime = dottime * 7;
-
- for(;(*string) && (!res); string++){
-
- c = *string;
-
- /* Convert lower case to upper case */
-
- if((c >= 'a') && (c <= 'z'))
- c -= 0x20;
-
- /* Can't deal with any char code greater than Z, skip it */
-
- if(c > 'Z')
- continue;
-
- /* If space char, wait the inter word time */
-
- if(c == ' '){
- if(!res)
- res = play_silence(chan, interwordtime);
- continue;
- }
-
- /* Subtract out control char offset to match our table */
-
- c -= 0x20;
-
- /* Get the character data */
-
- len = mbits[c].len;
- ddcomb = mbits[c].ddcomb;
-
- /* Send the character */
-
- for(; len ; len--){
- if(!res)
- res = play_tone(chan, freq, (ddcomb & 1) ? dashtime : dottime, amplitude);
- if(!res)
- res = play_silence(chan, intralettertime);
- ddcomb >>= 1;
- }
-
- /* Wait the interletter time */
-
- if(!res)
- res = play_silence(chan, interlettertime - intralettertime);
- }
-
- /* Wait for all the frames to be sent */
-
- if (!res)
- res = ast_waitstream(chan, "");
- ast_stopstream(chan);
-
- /*
- * Wait for the zaptel driver to physically write the tone blocks to the hardware
- */
-
- for(i = 0; i < 20 ; i++){
- flags = ZT_IOMUX_WRITEEMPTY | ZT_IOMUX_NOWAIT;
- res = ioctl(chan->fds[0], ZT_IOMUX, &flags);
- if(flags & ZT_IOMUX_WRITEEMPTY)
- break;
- if( ast_safe_sleep(chan, 50)){
- res = -1;
- break;
- }
- }
-
-
- return res;
-}
-
-static int send_tone_telemetry(struct ast_channel *chan, char *tonestring)
-{
- char *stringp;
- char *tonesubset;
- int f1,f2;
- int duration;
- int amplitude;
- int res;
- int i;
- int flags;
-
- res = 0;
-
- stringp = ast_strdupa(tonestring);
-
- for(;tonestring;){
- tonesubset = strsep(&stringp,")");
- if(!tonesubset)
- break;
- if(sscanf(tonesubset,"(%d,%d,%d,%d", &f1, &f2, &duration, &amplitude) != 4)
- break;
- res = play_tone_pair(chan, f1, f2, duration, amplitude);
- if(res)
- break;
- }
- if(!res)
- res = play_tone_pair(chan, 0, 0, 100, 0); /* This is needed to ensure the last tone segment is timed correctly */
-
- if (!res)
- res = ast_waitstream(chan, "");
- ast_stopstream(chan);
-
- /*
- * Wait for the zaptel driver to physically write the tone blocks to the hardware
- */
-
- for(i = 0; i < 20 ; i++){
- flags = ZT_IOMUX_WRITEEMPTY | ZT_IOMUX_NOWAIT;
- res = ioctl(chan->fds[0], ZT_IOMUX, &flags);
- if(flags & ZT_IOMUX_WRITEEMPTY)
- break;
- if( ast_safe_sleep(chan, 50)){
- res = -1;
- break;
- }
- }
-
- return res;
-
-}
-
-
-static int sayfile(struct ast_channel *mychannel,char *fname)
-{
-int res;
-
- res = ast_streamfile(mychannel, fname, mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- return res;
-}
-
-static int saycharstr(struct ast_channel *mychannel,char *str)
-{
-int res;
-
- res = ast_say_character_str(mychannel,str,NULL,mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- return res;
-}
-
-static int saynum(struct ast_channel *mychannel, int num)
-{
- int res;
- res = ast_say_number(mychannel, num, NULL, mychannel->language, NULL);
- if(!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- return res;
-}
-
-
-/* Retrieve an int from a config file */
-
-static int retrieve_astcfgint(char *category, char *name, int min, int max, int defl)
-{
- char *var;
- int ret;
-
- var = ast_variable_retrieve(cfg, category, name);
- if(var){
- ret = myatoi(var);
- if(ret < min)
- ret = min;
- if(ret > max)
- ret = max;
- }
- else
- ret = defl;
- return ret;
-}
-
-static int telem_any(struct ast_channel *chan, char *entry)
-{
- int res;
- char c;
-
- static int morsespeed;
- static int morsefreq;
- static int morseampl;
- static int morseidfreq = 0;
- static int morseidampl;
- static char mcat[] = MORSE;
-
- res = 0;
-
- if(!morseidfreq){ /* Get the morse parameters if not already loaded */
- morsespeed = retrieve_astcfgint( mcat, "speed", 5, 20, 20);
- morsefreq = retrieve_astcfgint( mcat, "frequency", 300, 3000, 800);
- morseampl = retrieve_astcfgint( mcat, "amplitude", 200, 8192, 4096);
- morseidampl = retrieve_astcfgint( mcat, "idamplitude", 200, 8192, 2048);
- morseidfreq = retrieve_astcfgint( mcat, "idfrequency", 300, 3000, 330);
- }
-
- /* Is it a file, or a tone sequence? */
-
- if(entry[0] == '|'){
- c = entry[1];
- if((c >= 'a')&&(c <= 'z'))
- c -= 0x20;
-
- switch(c){
- case 'I': /* Morse ID */
- res = send_morse(chan, entry + 2, morsespeed, morseidfreq, morseidampl);
- break;
-
- case 'M': /* Morse Message */
- res = send_morse(chan, entry + 2, morsespeed, morsefreq, morseampl);
- break;
-
- case 'T': /* Tone sequence */
- res = send_tone_telemetry(chan, entry + 2);
- break;
- default:
- res = -1;
- }
- }
- else
- res = sayfile(chan, entry); /* File */
- return res;
-}
-
-/*
-* This function looks up a telemetry name in the config file, and does a telemetry response as configured.
-*
-* 4 types of telemtry are handled: Morse ID, Morse Message, Tone Sequence, and a File containing a recording.
-*/
-
-static int telem_lookup(struct ast_channel *chan, char *node, char *name)
-{
-
- int res;
- int i;
- char *entry;
- char *telemetry;
- char *telemetry_save;
-
- res = 0;
- telemetry_save = NULL;
- entry = NULL;
-
-
- /* Retrieve the section name for telemetry from the node section */
-
- telemetry = ast_variable_retrieve(cfg, node, TELEMETRY);
- if(telemetry){
- telemetry_save = ast_strdupa(telemetry);
- if(!telemetry_save){
- ast_log(LOG_WARNING,"ast_strdupa() failed in telem_lookup()\n");
- return res;
- }
- entry = ast_variable_retrieve(cfg, telemetry_save, name);
- }
-
- /* Try to look up the telemetry name */
-
- if(!entry){
- /* Telemetry name wasn't found in the config file, use the default */
- for(i = 0; i < sizeof(tele_defs)/sizeof(struct telem_defaults) ; i++){
- if(!strcasecmp(tele_defs[i].name, name))
- entry = tele_defs[i].value;
- }
- }
- if(entry)
- telem_any(chan, entry);
- else{
- ast_log(LOG_WARNING, "Telemetry name not found: %s\n", name);
- res = -1;
- }
- return res;
-}
-
-/*
-* Retrieve a wait interval
-*/
-
-static int get_wait_interval(struct rpt *myrpt, int type)
-{
- int interval;
- char *wait_times;
- char *wait_times_save;
-
- wait_times_save = NULL;
- wait_times = ast_variable_retrieve(cfg, myrpt->name, "wait_times");
-
- if(wait_times){
- wait_times_save = ast_strdupa(wait_times);
- if(!wait_times_save){
- ast_log(LOG_WARNING, "Out of memory in wait_interval()\n");
- wait_times = NULL;
- }
- }
-
- switch(type){
- case DLY_TELEM:
- if(wait_times)
- interval = retrieve_astcfgint(wait_times_save, "telemwait", 500, 5000, 1000);
- else
- interval = 1000;
- break;
-
- case DLY_ID:
- if(wait_times)
- interval = retrieve_astcfgint(wait_times_save, "idwait",250,5000,500);
- else
- interval = 500;
- break;
-
- case DLY_UNKEY:
- if(wait_times)
- interval = retrieve_astcfgint(wait_times_save, "unkeywait",500,5000,1000);
- else
- interval = 1000;
- break;
-
- case DLY_CALLTERM:
- if(wait_times)
- interval = retrieve_astcfgint(wait_times_save, "calltermwait",500,5000,1500);
- else
- interval = 1500;
- break;
-
- default:
- return 0;
- }
- return interval;
-}
-
-
-/*
-* Wait a configurable interval of time
-*/
-
-
-static void wait_interval(struct rpt *myrpt, int type, struct ast_channel *chan)
-{
- int interval;
- if((interval = get_wait_interval(myrpt, type)))
- ast_safe_sleep(chan,interval);
- return;
-}
-
-
-static void *rpt_tele_thread(void *this)
-{
-ZT_CONFINFO ci; /* conference info */
-int res = 0,haslink,hastx,hasremote,imdone = 0, unkeys_queued, x;
-struct rpt_tele *mytele = (struct rpt_tele *)this;
-struct rpt_tele *tlist;
-struct rpt *myrpt;
-struct rpt_link *l,*m,linkbase;
-struct ast_channel *mychannel;
-int vmajor, vminor;
-char *p,*ct,*ct_copy,*ident, *nodename;
-time_t t;
-struct tm localtm;
-
-
- /* get a pointer to myrpt */
- myrpt = mytele->rpt;
-
- /* Snag copies of a few key myrpt variables */
- ast_mutex_lock(&myrpt->lock);
- nodename = ast_strdupa(myrpt->name);
- ident = ast_strdupa(myrpt->ident);
- ast_mutex_unlock(&myrpt->lock);
-
-
- /* allocate a pseudo-channel thru asterisk */
- mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
- if (!mychannel)
- {
- fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
- ast_mutex_lock(&myrpt->lock);
- remque((struct qelem *)mytele);
- ast_mutex_unlock(&myrpt->lock);
- free(mytele);
- pthread_exit(NULL);
- }
- ast_mutex_lock(&myrpt->lock);
- mytele->chan = mychannel; /* Save a copy of the channel so we can access it externally if need be */
- ast_mutex_unlock(&myrpt->lock);
-
- /* make a conference for the tx */
- ci.chan = 0;
- /* If there's an ID queued, only connect the ID audio to the local tx conference so
- linked systems can't hear it */
- ci.confno = (((mytele->mode == ID) || (mytele->mode == IDTALKOVER) || (mytele->mode == UNKEY)) ?
- myrpt->txconf : myrpt->conf);
- ci.confmode = ZT_CONF_CONFANN;
- /* first put the channel on the conference in announce mode */
- if (ioctl(mychannel->fds[0],ZT_SETCONF,&ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- ast_mutex_lock(&myrpt->lock);
- remque((struct qelem *)mytele);
- ast_mutex_unlock(&myrpt->lock);
- free(mytele);
- ast_hangup(mychannel);
- pthread_exit(NULL);
- }
- ast_stopstream(mychannel);
- switch(mytele->mode)
- {
- case ID:
- case ID1:
- /* wait a bit */
- wait_interval(myrpt, (mytele->mode == ID) ? DLY_ID : DLY_TELEM,mychannel);
- res = telem_any(mychannel, ident);
- imdone=1;
-
- break;
-
-
- case IDTALKOVER:
- p = ast_variable_retrieve(cfg, nodename, "idtalkover");
- if(p)
- res = telem_any(mychannel, p);
- imdone=1;
- break;
-
- case PROC:
- /* wait a little bit longer */
- wait_interval(myrpt, DLY_TELEM, mychannel);
- res = ast_streamfile(mychannel, "rpt/callproceeding", mychannel->language);
- break;
- case TERM:
- /* wait a little bit longer */
- wait_interval(myrpt, DLY_CALLTERM, mychannel);
- res = ast_streamfile(mychannel, "rpt/callterminated", mychannel->language);
- break;
- case COMPLETE:
- /* wait a little bit */
- wait_interval(myrpt, DLY_TELEM, mychannel);
- res = telem_lookup(mychannel, myrpt->name, "functcomplete");
- break;
- case UNKEY:
-
- /*
- * Reset the Unkey to CT timer
- */
-
- x = get_wait_interval(myrpt, DLY_UNKEY);
- ast_mutex_lock(&myrpt->lock);
- myrpt->unkeytocttimer = x; /* Must be protected as it is changed below */
- ast_mutex_unlock(&myrpt->lock);
-
- /*
- * If there's one already queued, don't do another
- */
-
- tlist = myrpt->tele.next;
- unkeys_queued = 0;
- if (tlist != &myrpt->tele)
- {
- ast_mutex_lock(&myrpt->lock);
- while(tlist != &myrpt->tele){
- if (tlist->mode == UNKEY) unkeys_queued++;
- tlist = tlist->next;
- }
- ast_mutex_unlock(&myrpt->lock);
- }
- if( unkeys_queued > 1){
- imdone = 1;
- break;
- }
-
- /* Wait for the telemetry timer to expire */
- /* Periodically check the timer since it can be re-initialized above */
-
- while(myrpt->unkeytocttimer)
- {
- int ctint;
- if(myrpt->unkeytocttimer > 100)
- ctint = 100;
- else
- ctint = myrpt->unkeytocttimer;
- ast_safe_sleep(mychannel, ctint);
- ast_mutex_lock(&myrpt->lock);
- if(myrpt->unkeytocttimer < ctint)
- myrpt->unkeytocttimer = 0;
- else
- myrpt->unkeytocttimer -= ctint;
- ast_mutex_unlock(&myrpt->lock);
- }
-
-
- /*
- * Now, the carrier on the rptr rx should be gone.
- * If it re-appeared, then forget about sending the CT
- */
- if(myrpt->keyed){
- imdone = 1;
- break;
- }
-
- haslink = 0;
- hastx = 0;
- hasremote = 0;
- l = myrpt->links.next;
- if (l != &myrpt->links)
- {
- ast_mutex_lock(&myrpt->lock);
- while(l != &myrpt->links)
- {
- if (l->name[0] == '0')
- {
- l = l->next;
- continue;
- }
- haslink = 1;
- if (l->mode) {
- hastx++;
- if (l->isremote) hasremote++;
- }
- l = l->next;
- }
- ast_mutex_unlock(&myrpt->lock);
- }
- if (haslink)
- {
-
- res = telem_lookup(mychannel, myrpt->name, (!hastx) ? "remotemon" : "remotetx");
- if(res)
- ast_log(LOG_WARNING, "telem_lookup:remotexx failed on %s\n", mychannel->name);
-
-
- /* if in remote cmd mode, indicate it */
- if (myrpt->cmdnode[0])
- {
- ast_safe_sleep(mychannel,200);
- res = telem_lookup(mychannel, myrpt->name, "cmdmode");
- if(res)
- ast_log(LOG_WARNING, "telem_lookup:cmdmode failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- }
- }
- else if((ct = ast_variable_retrieve(cfg, nodename, "unlinkedct"))){ /* Unlinked Courtesy Tone */
- ct_copy = ast_strdupa(ct);
- res = telem_lookup(mychannel, myrpt->name, ct_copy);
- if(res)
- ast_log(LOG_WARNING, "telem_lookup:ctx failed on %s\n", mychannel->name);
- }
-
- if (hasremote && (!myrpt->cmdnode[0]))
- {
- /* set for all to hear */
- ci.chan = 0;
- ci.confno = myrpt->conf;
- ci.confmode = ZT_CONF_CONFANN;
- /* first put the channel on the conference in announce mode */
- if (ioctl(mychannel->fds[0],ZT_SETCONF,&ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- ast_mutex_lock(&myrpt->lock);
- remque((struct qelem *)mytele);
- ast_mutex_unlock(&myrpt->lock);
- free(mytele);
- ast_hangup(mychannel);
- pthread_exit(NULL);
- }
- if((ct = ast_variable_retrieve(cfg, nodename, "remotect"))){ /* Unlinked Courtesy Tone */
- ast_safe_sleep(mychannel,200);
- ct_copy = ast_strdupa(ct);
- res = telem_lookup(mychannel, myrpt->name, ct_copy);
- if(res)
- ast_log(LOG_WARNING, "telem_lookup:ctx failed on %s\n", mychannel->name);
- }
- }
- imdone = 1;
- break;
- case REMDISC:
- /* wait a little bit */
- wait_interval(myrpt, DLY_TELEM, mychannel);
- res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- ast_say_character_str(mychannel,mytele->mylink.name,NULL,mychannel->language);
- res = ast_streamfile(mychannel, ((mytele->mylink.connected) ?
- "rpt/remote_disc" : "rpt/remote_busy"), mychannel->language);
- break;
- case REMALREADY:
- /* wait a little bit */
- wait_interval(myrpt, DLY_TELEM, mychannel);
- res = ast_streamfile(mychannel, "rpt/remote_already", mychannel->language);
- break;
- case REMNOTFOUND:
- /* wait a little bit */
- wait_interval(myrpt, DLY_TELEM, mychannel);
- res = ast_streamfile(mychannel, "rpt/remote_notfound", mychannel->language);
- break;
- case REMGO:
- /* wait a little bit */
- wait_interval(myrpt, DLY_TELEM, mychannel);
- res = ast_streamfile(mychannel, "rpt/remote_go", mychannel->language);
- break;
- case CONNECTED:
- /* wait a little bit */
- wait_interval(myrpt, DLY_TELEM, mychannel);
- res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- ast_say_character_str(mychannel,mytele->mylink.name,NULL,mychannel->language);
- res = ast_streamfile(mychannel, "rpt/connected", mychannel->language);
- break;
- case CONNFAIL:
- res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- ast_say_character_str(mychannel,mytele->mylink.name,NULL,mychannel->language);
- res = ast_streamfile(mychannel, "rpt/connection_failed", mychannel->language);
- break;
- case STATUS:
- /* wait a little bit */
- wait_interval(myrpt, DLY_TELEM, mychannel);
- hastx = 0;
- linkbase.next = &linkbase;
- linkbase.prev = &linkbase;
- ast_mutex_lock(&myrpt->lock);
- /* make our own list of links */
- l = myrpt->links.next;
- while(l != &myrpt->links)
- {
- if (l->name[0] == '0')
- {
- l = l->next;
- continue;
- }
- m = malloc(sizeof(struct rpt_link));
- if (!m)
- {
- ast_log(LOG_WARNING, "Cannot alloc memory on %s\n", mychannel->name);
- ast_mutex_lock(&myrpt->lock);
- remque((struct qelem *)mytele);
- ast_mutex_unlock(&myrpt->lock);
- free(mytele);
- ast_hangup(mychannel);
- pthread_exit(NULL);
- }
- memcpy(m,l,sizeof(struct rpt_link));
- m->next = m->prev = NULL;
- insque((struct qelem *)m,(struct qelem *)linkbase.next);
- l = l->next;
- }
- ast_mutex_unlock(&myrpt->lock);
- res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- ast_say_character_str(mychannel,myrpt->name,NULL,mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- if (myrpt->callmode)
- {
- hastx = 1;
- res = ast_streamfile(mychannel, "rpt/autopatch_on", mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- }
- l = linkbase.next;
- while(l != &linkbase)
- {
- hastx = 1;
- res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- ast_say_character_str(mychannel,l->name,NULL,mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- res = ast_streamfile(mychannel, ((l->mode) ?
- "rpt/tranceive" : "rpt/monitor"), mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- l = l->next;
- }
- if (!hastx)
- {
- res = ast_streamfile(mychannel, "rpt/repeat_only", mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- }
- /* destroy our local link queue */
- l = linkbase.next;
- while(l != &linkbase)
- {
- m = l;
- l = l->next;
- remque((struct qelem *)m);
- free(m);
- }
- imdone = 1;
- break;
- case TIMEOUT:
- res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- ast_stopstream(mychannel);
- ast_say_character_str(mychannel,myrpt->name,NULL,mychannel->language);
- res = ast_streamfile(mychannel, "rpt/timeout", mychannel->language);
- break;
-
- case STATS_TIME:
- wait_interval(myrpt, DLY_TELEM, mychannel); /* Wait a little bit */
- t = time(NULL);
- localtime_r(&t, &localtm);
- /* Say the phase of the day is before the time */
- if((localtm.tm_hour >= 0) && (localtm.tm_hour < 12))
- p = "rpt/goodmorning";
- else if((localtm.tm_hour >= 12) && (localtm.tm_hour < 18))
- p = "rpt/goodafternoon";
- else
- p = "rpt/goodevening";
- if (sayfile(mychannel,p) == -1)
- {
- imdone = 1;
- break;
- }
- /* Say the time is ... */
- if (sayfile(mychannel,"rpt/thetimeis") == -1)
- {
- imdone = 1;
- break;
- }
- /* Say the time */
- res = ast_say_time(mychannel, t, "", mychannel->language);
- if (!res)
- res = ast_waitstream(mychannel, "");
- ast_stopstream(mychannel);
- imdone = 1;
- break;
- case STATS_VERSION:
- p = strstr(tdesc, "version");
- if(!p)
- break;
- if(sscanf(p, "version %d.%d", &vmajor, &vminor) != 2)
- break;
- wait_interval(myrpt, DLY_TELEM, mychannel); /* Wait a little bit */
- /* Say "version" */
- if (sayfile(mychannel,"rpt/version") == -1)
- {
- imdone = 1;
- break;
- }
- if(!res) /* Say "X" */
- ast_say_number(mychannel, vmajor, "", mychannel->language, (char *) NULL);
- if (!res)
- res = ast_waitstream(mychannel, "");
- ast_stopstream(mychannel);
- if (saycharstr(mychannel,".") == -1)
- {
- imdone = 1;
- break;
- }
- if(!res) /* Say "Y" */
- ast_say_number(mychannel, vminor, "", mychannel->language, (char *) NULL);
- if (!res){
- res = ast_waitstream(mychannel, "");
- ast_stopstream(mychannel);
- }
- else
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- imdone = 1;
- break;
- case ARB_ALPHA:
- wait_interval(myrpt, DLY_TELEM, mychannel); /* Wait a little bit */
- if(mytele->param)
- saycharstr(mychannel, mytele->param);
- imdone = 1;
- break;
- case REV_PATCH:
- wait_interval(myrpt, DLY_TELEM, mychannel); /* Wait a little bit */
- if(mytele->param) {
-
- /* Parts of this section taken from app_parkandannounce */
- char *tpl_working, *tpl_current;
- char *tmp[100], *myparm;
- int looptemp=0,i=0, dres = 0;
-
-
- tpl_working = strdupa(mytele->param);
- myparm = strsep(&tpl_working,",");
- tpl_current=strsep(&tpl_working, ":");
-
- while(tpl_current && looptemp < sizeof(tmp)) {
- tmp[looptemp]=tpl_current;
- looptemp++;
- tpl_current=strsep(&tpl_working,":");
- }
-
- for(i=0; i<looptemp; i++) {
- if(!strcmp(tmp[i], "PARKED")) {
- ast_say_digits(mychannel, atoi(myparm), "", mychannel->language);
- } else if(!strcmp(tmp[i], "NODE")) {
- ast_say_digits(mychannel, atoi(myrpt->name), "", mychannel->language);
- } else {
- dres = ast_streamfile(mychannel, tmp[i], mychannel->language);
- if(!dres) {
- dres = ast_waitstream(mychannel, "");
- } else {
- ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], mychannel->name);
- dres = 0;
- }
- }
- }
- }
- imdone = 1;
- break;
- case TEST_TONE:
- imdone = 1;
- myrpt->stopgen = 0;
- if ((res = ast_tonepair_start(mychannel, 1004.0, 0, 99999999, 7200.0)))
- break;
- while(mychannel->generatordata && (!myrpt->stopgen)) {
- if (ast_safe_sleep(mychannel,1)) break;
- imdone = 1;
- }
- break;
- default:
- break;
- }
- myrpt->stopgen = 0;
- if (!imdone)
- {
- if (!res)
- res = ast_waitstream(mychannel, "");
- else {
- ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
- res = 0;
- }
- }
- ast_stopstream(mychannel);
- ast_mutex_lock(&myrpt->lock);
- remque((struct qelem *)mytele);
- ast_mutex_unlock(&myrpt->lock);
- free(mytele);
- ast_hangup(mychannel);
- pthread_exit(NULL);
-}
-
-static void rpt_telemetry(struct rpt *myrpt,int mode, void *data)
-{
-struct rpt_tele *tele;
-struct rpt_link *mylink = (struct rpt_link *) data;
-pthread_attr_t attr;
-
- tele = malloc(sizeof(struct rpt_tele));
- if (!tele)
- {
- ast_log(LOG_WARNING, "Unable to allocate memory\n");
- pthread_exit(NULL);
- return;
- }
- /* zero it out */
- memset((char *)tele,0,sizeof(struct rpt_tele));
- tele->rpt = myrpt;
- tele->mode = mode;
- ast_mutex_lock(&myrpt->lock);
- if((mode == CONNFAIL) || (mode == REMDISC) || (mode == CONNECTED)){
- memset(&tele->mylink,0,sizeof(struct rpt_link));
- if (mylink){
- memcpy(&tele->mylink,mylink,sizeof(struct rpt_link));
- }
- }
- else if ((mode == ARB_ALPHA) || (mode == REV_PATCH)) {
- strncpy(tele->param, (char *) data, TELEPARAMSIZE - 1);
- tele->param[TELEPARAMSIZE - 1] = 0;
- }
- insque((struct qelem *)tele,(struct qelem *)myrpt->tele.next);
- ast_mutex_unlock(&myrpt->lock);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&tele->threadid,&attr,rpt_tele_thread,(void *) tele);
- return;
-}
-
-static void *rpt_call(void *this)
-{
-ZT_CONFINFO ci; /* conference info */
-struct rpt *myrpt = (struct rpt *)this;
-int res;
-struct ast_frame wf;
-int stopped,congstarted;
-struct ast_channel *mychannel,*genchannel;
-
- myrpt->mydtmf = 0;
- /* allocate a pseudo-channel thru asterisk */
- mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
- if (!mychannel)
- {
- fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
- pthread_exit(NULL);
- }
- ci.chan = 0;
- ci.confno = myrpt->conf; /* use the pseudo conference */
- ci.confmode = ZT_CONF_REALANDPSEUDO | ZT_CONF_TALKER | ZT_CONF_LISTENER
- | ZT_CONF_PSEUDO_TALKER | ZT_CONF_PSEUDO_LISTENER;
- /* first put the channel on the conference */
- if (ioctl(mychannel->fds[0],ZT_SETCONF,&ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- ast_hangup(mychannel);
- myrpt->callmode = 0;
- pthread_exit(NULL);
- }
- /* allocate a pseudo-channel thru asterisk */
- genchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
- if (!genchannel)
- {
- fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
- ast_hangup(mychannel);
- pthread_exit(NULL);
- }
- ci.chan = 0;
- ci.confno = myrpt->conf;
- ci.confmode = ZT_CONF_REALANDPSEUDO | ZT_CONF_TALKER | ZT_CONF_LISTENER
- | ZT_CONF_PSEUDO_TALKER | ZT_CONF_PSEUDO_LISTENER;
- /* first put the channel on the conference */
- if (ioctl(genchannel->fds[0],ZT_SETCONF,&ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- ast_hangup(mychannel);
- ast_hangup(genchannel);
- myrpt->callmode = 0;
- pthread_exit(NULL);
- }
- if (myrpt->tonezone && (tone_zone_set_zone(mychannel->fds[0],myrpt->tonezone) == -1))
- {
- ast_log(LOG_WARNING, "Unable to set tone zone %s\n",myrpt->tonezone);
- ast_hangup(mychannel);
- ast_hangup(genchannel);
- myrpt->callmode = 0;
- pthread_exit(NULL);
- }
- if (myrpt->tonezone && (tone_zone_set_zone(genchannel->fds[0],myrpt->tonezone) == -1))
- {
- ast_log(LOG_WARNING, "Unable to set tone zone %s\n",myrpt->tonezone);
- ast_hangup(mychannel);
- ast_hangup(genchannel);
- myrpt->callmode = 0;
- pthread_exit(NULL);
- }
- /* start dialtone */
- if (tone_zone_play_tone(mychannel->fds[0],ZT_TONE_DIALTONE) < 0)
- {
- ast_log(LOG_WARNING, "Cannot start dialtone\n");
- ast_hangup(mychannel);
- ast_hangup(genchannel);
- myrpt->callmode = 0;
- pthread_exit(NULL);
- }
- stopped = 0;
- congstarted = 0;
- while ((myrpt->callmode == 1) || (myrpt->callmode == 4))
- {
-
- if ((myrpt->callmode == 1) && (myrpt->cidx > 0) && (!stopped))
- {
- stopped = 1;
- /* stop dial tone */
- tone_zone_play_tone(mychannel->fds[0],-1);
- }
- if ((myrpt->callmode == 4) && (!congstarted))
- {
- congstarted = 1;
- /* start congestion tone */
- tone_zone_play_tone(mychannel->fds[0],ZT_TONE_CONGESTION);
- }
- res = ast_safe_sleep(mychannel, MSWAIT);
- if (res < 0)
- {
- ast_hangup(mychannel);
- ast_hangup(genchannel);
- ast_mutex_lock(&myrpt->lock);
- myrpt->callmode = 0;
- ast_mutex_unlock(&myrpt->lock);
- pthread_exit(NULL);
- }
- }
- /* stop any tone generation */
- tone_zone_play_tone(mychannel->fds[0],-1);
- /* end if done */
- if (!myrpt->callmode)
- {
- ast_hangup(mychannel);
- ast_hangup(genchannel);
- ast_mutex_lock(&myrpt->lock);
- myrpt->callmode = 0;
- ast_mutex_unlock(&myrpt->lock);
- pthread_exit(NULL);
- }
-
- if (myrpt->ourcallerid && *myrpt->ourcallerid){
- char *name, *loc, *instr;
- instr = strdup(myrpt->ourcallerid);
- if(instr){
- ast_callerid_parse(instr, &name, &loc);
- if(loc){
- if(mychannel->cid.cid_num)
- free(mychannel->cid.cid_num);
- mychannel->cid.cid_num = strdup(loc);
- }
- if(name){
- if(mychannel->cid.cid_name)
- free(mychannel->cid.cid_name);
- mychannel->cid.cid_name = strdup(name);
- }
- free(instr);
- }
- }
-
- strncpy(mychannel->exten, myrpt->exten, sizeof(mychannel->exten) - 1);
- strncpy(mychannel->context, myrpt->ourcontext, sizeof(mychannel->context) - 1);
- if (myrpt->acctcode)
- strncpy(mychannel->accountcode, myrpt->acctcode, sizeof(mychannel->accountcode) - 1);
- mychannel->priority = 1;
- ast_channel_undefer_dtmf(mychannel);
- if (ast_pbx_start(mychannel) < 0)
- {
- ast_log(LOG_WARNING, "Unable to start PBX!!\n");
- ast_hangup(mychannel);
- ast_hangup(genchannel);
- ast_mutex_lock(&myrpt->lock);
- myrpt->callmode = 0;
- ast_mutex_unlock(&myrpt->lock);
- pthread_exit(NULL);
- }
- usleep(10000);
- ast_mutex_lock(&myrpt->lock);
- myrpt->callmode = 3;
- while(myrpt->callmode)
- {
- if ((!mychannel->pbx) && (myrpt->callmode != 4))
- {
- myrpt->callmode = 4;
- ast_mutex_unlock(&myrpt->lock);
- /* start congestion tone */
- tone_zone_play_tone(genchannel->fds[0],ZT_TONE_CONGESTION);
- ast_mutex_lock(&myrpt->lock);
- }
- if (myrpt->mydtmf)
- {
- wf.frametype = AST_FRAME_DTMF;
- wf.subclass = myrpt->mydtmf;
- wf.offset = 0;
- wf.mallocd = 0;
- wf.data = NULL;
- wf.datalen = 0;
- wf.samples = 0;
- ast_mutex_unlock(&myrpt->lock);
- ast_write(genchannel,&wf);
- ast_mutex_lock(&myrpt->lock);
- myrpt->mydtmf = 0;
- }
- ast_mutex_unlock(&myrpt->lock);
- usleep(MSWAIT * 1000);
- ast_mutex_lock(&myrpt->lock);
- }
- ast_mutex_unlock(&myrpt->lock);
- tone_zone_play_tone(genchannel->fds[0],-1);
- if (mychannel->pbx) ast_softhangup(mychannel,AST_SOFTHANGUP_DEV);
- ast_hangup(genchannel);
- ast_mutex_lock(&myrpt->lock);
- myrpt->callmode = 0;
- ast_mutex_unlock(&myrpt->lock);
- pthread_exit(NULL);
-}
-
-static void send_link_dtmf(struct rpt *myrpt,char c)
-{
-char str[300];
-struct ast_frame wf;
-struct rpt_link *l;
-
- snprintf(str, sizeof(str), "D %s %s %d %c", myrpt->cmdnode, myrpt->name, ++(myrpt->dtmfidx), c);
- wf.frametype = AST_FRAME_TEXT;
- wf.subclass = 0;
- wf.offset = 0;
- wf.mallocd = 1;
- wf.datalen = strlen(str) + 1;
- wf.samples = 0;
- l = myrpt->links.next;
- /* first, see if our dude is there */
- while(l != &myrpt->links)
- {
- if (l->name[0] == '0')
- {
- l = l->next;
- continue;
- }
- /* if we found it, write it and were done */
- if (!strcmp(l->name,myrpt->cmdnode))
- {
- wf.data = strdup(str);
- if (l->chan) ast_write(l->chan,&wf);
- return;
- }
- l = l->next;
- }
- l = myrpt->links.next;
- /* if not, give it to everyone */
- while(l != &myrpt->links)
- {
- wf.data = strdup(str);
- if (l->chan) ast_write(l->chan,&wf);
- l = l->next;
- }
- return;
-}
-
-/*
-* Internet linking function
-*/
-
-static int function_ilink(struct rpt *myrpt, char *param, char *digits, int command_source, struct rpt_link *mylink)
-{
-
- char *val, *s, *s1, *s2, *tele;
- char tmp[300], deststr[300] = "",modechange = 0;
- char digitbuf[MAXNODESTR];
- struct rpt_link *l;
- ZT_CONFINFO ci; /* conference info */
-
- if(!param)
- return DC_ERROR;
-
-
- if (!myrpt->enable)
- return DC_ERROR;
-
- strncpy(digitbuf,digits,MAXNODESTR - 1);
-
- if(debug)
- printf("@@@@ ilink param = %s, digitbuf = %s\n", (param)? param : "(null)", digitbuf);
-
- switch(myatoi(param)){
- case 1: /* Link off */
- if ((digitbuf[0] == '0') && (myrpt->lastlinknode[0]))
- strcpy(digitbuf,myrpt->lastlinknode);
- val = ast_variable_retrieve(cfg, myrpt->nodes, digitbuf);
- if (!val){
- if(strlen(digitbuf) >= myrpt->longestnode)
- return DC_ERROR;
- break;
- }
- strncpy(tmp,val,sizeof(tmp) - 1);
- s = tmp;
- s1 = strsep(&s,",");
- s2 = strsep(&s,",");
- ast_mutex_lock(&myrpt->lock);
- l = myrpt->links.next;
- /* try to find this one in queue */
- while(l != &myrpt->links){
- if (l->name[0] == '0')
- {
- l = l->next;
- continue;
- }
- /* if found matching string */
- if (!strcmp(l->name, digitbuf))
- break;
- l = l->next;
- }
- if (l != &myrpt->links){ /* if found */
- struct ast_frame wf;
-
- strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1);
- l->retries = MAX_RETRIES + 1;
- l->disced = 1;
- ast_mutex_unlock(&myrpt->lock);
- wf.frametype = AST_FRAME_TEXT;
- wf.subclass = 0;
- wf.offset = 0;
- wf.mallocd = 1;
- wf.datalen = strlen(discstr) + 1;
- wf.samples = 0;
- wf.data = strdup(discstr);
- if (l->chan)
- {
- ast_write(l->chan,&wf);
- if (ast_safe_sleep(l->chan,250) == -1) return DC_ERROR;
- ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
- }
- rpt_telemetry(myrpt, COMPLETE, NULL);
- return DC_COMPLETE;
- }
- ast_mutex_unlock(&myrpt->lock);
- return DC_COMPLETE;
- case 2: /* Link Monitor */
- if ((digitbuf[0] == '0') && (myrpt->lastlinknode[0]))
- strcpy(digitbuf,myrpt->lastlinknode);
- val = ast_variable_retrieve(cfg, myrpt->nodes, digitbuf);
- if (!val){
- if(strlen(digitbuf) >= myrpt->longestnode)
- return DC_ERROR;
- break;
- }
- strncpy(tmp,val,sizeof(tmp) - 1);
- s = tmp;
- s1 = strsep(&s,",");
- s2 = strsep(&s,",");
- ast_mutex_lock(&myrpt->lock);
- l = myrpt->links.next;
- /* try to find this one in queue */
- while(l != &myrpt->links){
- if (l->name[0] == '0')
- {
- l = l->next;
- continue;
- }
- /* if found matching string */
- if (!strcmp(l->name, digitbuf))
- break;
- l = l->next;
- }
- /* if found */
- if (l != &myrpt->links)
- {
- /* if already in this mode, just ignore */
- if ((!l->mode) || (!l->chan)) {
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt,REMALREADY,NULL);
- return DC_COMPLETE;
-
- }
- ast_mutex_unlock(&myrpt->lock);
- if (l->chan) ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
- l->retries = MAX_RETRIES + 1;
- l->disced = 2;
- modechange = 1;
- } else
- ast_mutex_unlock(&myrpt->lock);
- strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1);
- /* establish call in monitor mode */
- l = malloc(sizeof(struct rpt_link));
- if (!l){
- ast_log(LOG_WARNING, "Unable to malloc\n");
- return DC_ERROR;
- }
- /* zero the silly thing */
- memset((char *)l,0,sizeof(struct rpt_link));
- snprintf(deststr, sizeof(deststr), "IAX2/%s", s1);
- tele = strchr(deststr,'/');
- if (!tele){
- fprintf(stderr,"link2:Dial number (%s) must be in format tech/number\n",deststr);
- return DC_ERROR;
- }
- *tele++ = 0;
- l->isremote = (s && ast_true(s));
- strncpy(l->name, digitbuf, MAXNODESTR - 1);
- l->chan = ast_request(deststr,AST_FORMAT_SLINEAR,tele,NULL);
- if (modechange) l->connected = 1;
- if (l->chan){
- ast_set_read_format(l->chan,AST_FORMAT_SLINEAR);
- ast_set_write_format(l->chan,AST_FORMAT_SLINEAR);
- l->chan->whentohangup = 0;
- l->chan->appl = "Apprpt";
- l->chan->data = "(Remote Rx)";
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "rpt (remote) initiating call to %s/%s on %s\n",
- deststr,tele,l->chan->name);
- if(l->chan->cid.cid_num)
- free(l->chan->cid.cid_num);
- l->chan->cid.cid_num = strdup(myrpt->name);
- ast_call(l->chan,tele,0);
- }
- else
- {
- rpt_telemetry(myrpt,CONNFAIL,l);
- free(l);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Unable to place call to %s/%s on %s\n",
- deststr,tele,l->chan->name);
- return DC_ERROR;
- }
- /* allocate a pseudo-channel thru asterisk */
- l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
- if (!l->pchan){
- fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
- ast_hangup(l->chan);
- free(l);
- return DC_ERROR;
- }
- ast_set_read_format(l->pchan,AST_FORMAT_SLINEAR);
- ast_set_write_format(l->pchan,AST_FORMAT_SLINEAR);
- /* make a conference for the pseudo-one */
- ci.chan = 0;
- ci.confno = myrpt->conf;
- ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER | ZT_CONF_TALKER;
- /* first put the channel on the conference in proper mode */
- if (ioctl(l->pchan->fds[0],ZT_SETCONF,&ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- ast_hangup(l->chan);
- ast_hangup(l->pchan);
- free(l);
- return DC_ERROR;
- }
- ast_mutex_lock(&myrpt->lock);
- /* insert at end of queue */
- insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt,COMPLETE,NULL);
- return DC_COMPLETE;
- case 3: /* Link transceive */
- if ((digitbuf[0] == '0') && (myrpt->lastlinknode[0]))
- strcpy(digitbuf,myrpt->lastlinknode);
- val = ast_variable_retrieve(cfg, myrpt->nodes, digitbuf);
- if (!val){
- if(strlen(digitbuf) >= myrpt->longestnode)
- return DC_ERROR;
- break;
- }
- strncpy(tmp,val,sizeof(tmp) - 1);
- s = tmp;
- s1 = strsep(&s,",");
- s2 = strsep(&s,",");
- ast_mutex_lock(&myrpt->lock);
- l = myrpt->links.next;
- /* try to find this one in queue */
- while(l != &myrpt->links){
- if (l->name[0] == '0')
- {
- l = l->next;
- continue;
- }
- /* if found matching string */
- if (!strcmp(l->name, digitbuf))
- break;
- l = l->next;
- }
- /* if found */
- if (l != &myrpt->links){
- /* if already in this mode, just ignore */
- if ((l->mode) || (!l->chan)) {
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt, REMALREADY, NULL);
- return DC_COMPLETE;
- }
- ast_mutex_unlock(&myrpt->lock);
- if (l->chan) ast_softhangup(l->chan, AST_SOFTHANGUP_DEV);
- l->retries = MAX_RETRIES + 1;
- l->disced = 2;
- modechange = 1;
- } else
- ast_mutex_unlock(&myrpt->lock);
- strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1);
- /* establish call in tranceive mode */
- l = malloc(sizeof(struct rpt_link));
- if (!l){
- ast_log(LOG_WARNING, "Unable to malloc\n");
- return(DC_ERROR);
- }
- /* zero the silly thing */
- memset((char *)l,0,sizeof(struct rpt_link));
- l->mode = 1;
- l->outbound = 1;
- strncpy(l->name, digitbuf, MAXNODESTR - 1);
- l->isremote = (s && ast_true(s));
- if (modechange) l->connected = 1;
- snprintf(deststr, sizeof(deststr), "IAX2/%s", s1);
- tele = strchr(deststr, '/');
- if (!tele){
- fprintf(stderr,"link3:Dial number (%s) must be in format tech/number\n",deststr);
- free(l);
- return DC_ERROR;
- }
- *tele++ = 0;
- l->chan = ast_request(deststr, AST_FORMAT_SLINEAR, tele,NULL);
- if (l->chan){
- ast_set_read_format(l->chan, AST_FORMAT_SLINEAR);
- ast_set_write_format(l->chan, AST_FORMAT_SLINEAR);
- l->chan->whentohangup = 0;
- l->chan->appl = "Apprpt";
- l->chan->data = "(Remote Rx)";
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "rpt (remote) initiating call to %s/%s on %s\n",
- deststr, tele, l->chan->name);
- if(l->chan->cid.cid_num)
- free(l->chan->cid.cid_num);
- l->chan->cid.cid_num = strdup(myrpt->name);
- ast_call(l->chan,tele,999);
- }
- else{
- rpt_telemetry(myrpt,CONNFAIL,l);
- free(l);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Unable to place call to %s/%s on %s\n",
- deststr,tele,l->chan->name);
- return DC_ERROR;
- }
- /* allocate a pseudo-channel thru asterisk */
- l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
- if (!l->pchan){
- fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
- ast_hangup(l->chan);
- free(l);
- return DC_ERROR;
- }
- ast_set_read_format(l->pchan, AST_FORMAT_SLINEAR);
- ast_set_write_format(l->pchan, AST_FORMAT_SLINEAR);
- /* make a conference for the tx */
- ci.chan = 0;
- ci.confno = myrpt->conf;
- ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER | ZT_CONF_TALKER;
- /* first put the channel on the conference in proper mode */
- if (ioctl(l->pchan->fds[0], ZT_SETCONF, &ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- ast_hangup(l->chan);
- ast_hangup(l->pchan);
- free(l);
- return DC_ERROR;
- }
- ast_mutex_lock(&myrpt->lock);
- /* insert at end of queue */
- insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt,COMPLETE,NULL);
- return DC_COMPLETE;
- case 4: /* Enter Command Mode */
-
- /* if doesnt allow link cmd, or no links active, return */
- if (((command_source != SOURCE_RPT) && (command_source != SOURCE_PHONE) && (command_source != SOURCE_DPHONE)) || (myrpt->links.next == &myrpt->links))
- return DC_COMPLETE;
-
- /* if already in cmd mode, or selected self, fughetabahtit */
- if ((myrpt->cmdnode[0]) || (!strcmp(myrpt->name, digitbuf))){
-
- rpt_telemetry(myrpt, REMALREADY, NULL);
- return DC_COMPLETE;
- }
- if ((digitbuf[0] == '0') && (myrpt->lastlinknode[0]))
- strcpy(digitbuf,myrpt->lastlinknode);
- /* node must at least exist in list */
- val = ast_variable_retrieve(cfg, myrpt->nodes, digitbuf);
- if (!val){
- if(strlen(digitbuf) >= myrpt->longestnode)
- return DC_ERROR;
- break;
-
- }
- ast_mutex_lock(&myrpt->lock);
- strcpy(myrpt->lastlinknode,digitbuf);
- strncpy(myrpt->cmdnode, digitbuf, sizeof(myrpt->cmdnode) - 1);
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt, REMGO, NULL);
- return DC_COMPLETE;
-
- case 5: /* Status */
- rpt_telemetry(myrpt, STATUS, NULL);
- return DC_COMPLETE;
-
-
- case 6: /* All Links Off */
- l = myrpt->links.next;
-
- while(l != &myrpt->links){
- if (l->chan) ast_softhangup(l->chan, AST_SOFTHANGUP_DEV); /* Hang 'em up */
- l = l->next;
- }
- rpt_telemetry(myrpt, COMPLETE, NULL);
- break;
-
- default:
- return DC_ERROR;
-
- }
-
- return DC_INDETERMINATE;
-}
-
-/*
-* Autopatch up
-*/
-
-static int function_autopatchup(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
-{
- pthread_attr_t attr;
-
-
- if (!myrpt->enable)
- return DC_ERROR;
-
- if(debug)
- printf("@@@@ Autopatch up\n");
-
- ast_mutex_lock(&myrpt->lock);
-
- /* if on call, force * into current audio stream */
-
- if ((myrpt->callmode == 2) || (myrpt->callmode == 3)){
- myrpt->mydtmf = myrpt->funcchar;
- }
- if (myrpt->callmode){
- ast_mutex_unlock(&myrpt->lock);
- return DC_COMPLETE;
- }
- myrpt->callmode = 1;
- myrpt->cidx = 0;
- myrpt->exten[myrpt->cidx] = 0;
- ast_mutex_unlock(&myrpt->lock);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *) myrpt);
- return DC_COMPLETE;
-}
-
-/*
-* Autopatch down
-*/
-
-static int function_autopatchdn(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
-{
- if (!myrpt->enable)
- return DC_ERROR;
-
- if(debug)
- printf("@@@@ Autopatch down\n");
-
- ast_mutex_lock(&myrpt->lock);
-
- if (!myrpt->callmode){
- ast_mutex_unlock(&myrpt->lock);
- return DC_COMPLETE;
- }
-
- myrpt->callmode = 0;
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt, TERM, NULL);
- return DC_COMPLETE;
-}
-
-/*
-* Status
-*/
-
-static int function_status(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
-{
-
- if(!param)
- return DC_ERROR;
-
-
- if (!myrpt->enable)
- return DC_ERROR;
-
- if(debug)
- printf("@@@@ status param = %s, digitbuf = %s\n", (param)? param : "(null)", digitbuf);
-
- switch(myatoi(param)){
- case 1: /* System ID */
- rpt_telemetry(myrpt, ID1, NULL);
- return DC_COMPLETE;
- case 2: /* System Time */
- rpt_telemetry(myrpt, STATS_TIME, NULL);
- return DC_COMPLETE;
- case 3: /* app_rpt.c version */
- rpt_telemetry(myrpt, STATS_VERSION, NULL);
- default:
- return DC_ERROR;
- }
- return DC_INDETERMINATE;
-}
-
-/*
-* COP - Control operator
-*/
-
-static int function_cop(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
-{
- if(!param)
- return DC_ERROR;
-
- switch(myatoi(param)){
- case 1: /* System reset */
- system("killall -9 asterisk"); /* FIXME to drastic? */
- return DC_COMPLETE;
-
- case 2:
- myrpt->enable = 1;
- rpt_telemetry(myrpt, ARB_ALPHA, (void *) "RPTENA");
- return DC_COMPLETE;
-
- case 3:
- myrpt->enable = 0;
- return DC_COMPLETE;
-
- case 4: /* test tone on */
- rpt_telemetry(myrpt, TEST_TONE, NULL);
- return DC_COMPLETE;
-
- case 5: /* Disgorge variables to log for debug purposes */
- myrpt->disgorgetime = time(NULL) + 10; /* Do it 10 seconds later */
- return DC_COMPLETE;
-
- case 6: /* Simulate COR being activated (phone only) */
- if (command_source != SOURCE_PHONE) return DC_INDETERMINATE;
- return DC_DOKEY;
-
- }
- return DC_INDETERMINATE;
-}
-
-/*
-* Collect digits one by one until something matches
-*/
-
-static int collect_function_digits(struct rpt *myrpt, char *digits,
- int command_source, struct rpt_link *mylink)
-{
- int i;
- char *stringp,*action,*param,*functiondigits;
- char function_table_name[30] = "";
- char workstring[80];
-
- struct ast_variable *vp;
-
- if(debug)
- printf("@@@@ Digits collected: %s, source: %d\n", digits, command_source);
-
- if (command_source == SOURCE_DPHONE) {
- if (!myrpt->dphone_functions) return DC_INDETERMINATE;
- strncpy(function_table_name, myrpt->dphone_functions, sizeof(function_table_name) - 1);
- }
- else if (command_source == SOURCE_PHONE) {
- if (!myrpt->phone_functions) return DC_INDETERMINATE;
- strncpy(function_table_name, myrpt->phone_functions, sizeof(function_table_name) - 1);
- }
- else if (command_source == SOURCE_LNK)
- strncpy(function_table_name, myrpt->link_functions, sizeof(function_table_name) - 1);
- else
- strncpy(function_table_name, myrpt->functions, sizeof(function_table_name) - 1);
- vp = ast_variable_browse(cfg, function_table_name);
- while(vp) {
- if(!strncasecmp(vp->name, digits, strlen(vp->name)))
- break;
- vp = vp->next;
- }
- if(!vp) {
- int n;
-
- n = myrpt->longestfunc;
- if (command_source == SOURCE_LNK) n = myrpt->link_longestfunc;
- else
- if (command_source == SOURCE_PHONE) n = myrpt->phone_longestfunc;
- else
- if (command_source == SOURCE_DPHONE) n = myrpt->dphone_longestfunc;
-
- if(strlen(digits) >= n)
- return DC_ERROR;
- else
- return DC_INDETERMINATE;
- }
- /* Found a match, retrieve value part and parse */
- strncpy(workstring, vp->value, sizeof(workstring) - 1 );
- stringp = workstring;
- action = strsep(&stringp, ",");
- param = stringp;
- if(debug)
- printf("@@@@ action: %s, param = %s\n",action, (param) ? param : "(null)");
- /* Look up the action */
- for(i = 0 ; i < (sizeof(function_table)/sizeof(struct function_table_tag)); i++){
- if(!strncasecmp(action, function_table[i].action, strlen(action)))
- break;
- }
- if(debug)
- printf("@@@@ table index i = %d\n",i);
- if(i == (sizeof(function_table)/sizeof(struct function_table_tag))){
- /* Error, action not in table */
- return DC_ERROR;
- }
- if(function_table[i].function == NULL){
- /* Error, function undefined */
- if(debug)
- printf("@@@@ NULL for action: %s\n",action);
- return DC_ERROR;
- }
- functiondigits = digits + strlen(vp->name);
- return (*function_table[i].function)(myrpt, param, functiondigits, command_source, mylink);
-}
-
-
-static void handle_link_data(struct rpt *myrpt, struct rpt_link *mylink,
- char *str)
-{
-char tmp[300],cmd[300] = "",dest[300],src[300],c;
-int seq, res;
-struct rpt_link *l;
-struct ast_frame wf;
-
- wf.frametype = AST_FRAME_TEXT;
- wf.subclass = 0;
- wf.offset = 0;
- wf.mallocd = 1;
- wf.datalen = strlen(str) + 1;
- wf.samples = 0;
- /* put string in our buffer */
- strncpy(tmp,str,sizeof(tmp) - 1);
-
- if (!strcmp(tmp,discstr))
- {
- mylink->disced = 1;
- mylink->retries = MAX_RETRIES + 1;
- ast_softhangup(mylink->chan,AST_SOFTHANGUP_DEV);
- return;
- }
- if (sscanf(tmp,"%s %s %s %d %c",cmd,dest,src,&seq,&c) != 5)
- {
- ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
- return;
- }
- if (strcmp(cmd,"D"))
- {
- ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
- return;
- }
-
- if (dest[0] == '0')
- {
- strcpy(dest,myrpt->name);
- }
-
- /* if not for me, redistribute to all links */
- if (strcmp(dest,myrpt->name))
- {
- l = myrpt->links.next;
- /* see if this is one in list */
- while(l != &myrpt->links)
- {
- if (l->name[0] == '0')
- {
- l = l->next;
- continue;
- }
- /* dont send back from where it came */
- if ((l == mylink) || (!strcmp(l->name,mylink->name)))
- {
- l = l->next;
- continue;
- }
- /* if it is, send it and we're done */
- if (!strcmp(l->name,dest))
- {
- /* send, but not to src */
- if (strcmp(l->name,src)) {
- wf.data = strdup(str);
- if (l->chan) ast_write(l->chan,&wf);
- }
- return;
- }
- l = l->next;
- }
- l = myrpt->links.next;
- /* otherwise, send it to all of em */
- while(l != &myrpt->links)
- {
- if (l->name[0] == '0')
- {
- l = l->next;
- continue;
- }
- /* dont send back from where it came */
- if ((l == mylink) || (!strcmp(l->name,mylink->name)))
- {
- l = l->next;
- continue;
- }
- /* send, but not to src */
- if (strcmp(l->name,src)) {
- wf.data = strdup(str);
- if (l->chan) ast_write(l->chan,&wf);
- }
- l = l->next;
- }
- return;
- }
- ast_mutex_lock(&myrpt->lock);
- if (c == myrpt->endchar) myrpt->stopgen = 1;
- if (myrpt->callmode == 1)
- {
- myrpt->exten[myrpt->cidx++] = c;
- myrpt->exten[myrpt->cidx] = 0;
- /* if this exists */
- if (ast_exists_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
- {
- myrpt->callmode = 2;
- rpt_telemetry(myrpt,PROC,NULL);
- }
- /* if can continue, do so */
- if (!ast_canmatch_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
- {
- /* call has failed, inform user */
- myrpt->callmode = 4;
- }
- }
- if ((myrpt->callmode == 2) || (myrpt->callmode == 3))
- {
- myrpt->mydtmf = c;
- }
- if (c == myrpt->funcchar)
- {
- myrpt->rem_dtmfidx = 0;
- myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
- time(&myrpt->rem_dtmf_time);
- ast_mutex_unlock(&myrpt->lock);
- return;
- }
- else if ((c != myrpt->endchar) && (myrpt->rem_dtmfidx >= 0))
- {
- time(&myrpt->rem_dtmf_time);
- if (myrpt->rem_dtmfidx < MAXDTMF)
- {
- myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx++] = c;
- myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
-
- ast_mutex_unlock(&myrpt->lock);
- strncpy(cmd, myrpt->rem_dtmfbuf, sizeof(cmd) - 1);
- res = collect_function_digits(myrpt, cmd, SOURCE_LNK, mylink);
- ast_mutex_lock(&myrpt->lock);
-
- switch(res){
-
- case DC_INDETERMINATE:
- break;
-
- case DC_REQ_FLUSH:
- myrpt->rem_dtmfidx = 0;
- myrpt->rem_dtmfbuf[0] = 0;
- break;
-
-
- case DC_COMPLETE:
- myrpt->rem_dtmfbuf[0] = 0;
- myrpt->rem_dtmfidx = -1;
- myrpt->rem_dtmf_time = 0;
- break;
-
- case DC_ERROR:
- default:
- myrpt->rem_dtmfbuf[0] = 0;
- myrpt->rem_dtmfidx = -1;
- myrpt->rem_dtmf_time = 0;
- break;
- }
- }
-
- }
- ast_mutex_unlock(&myrpt->lock);
- return;
-}
-
-static void handle_link_phone_dtmf(struct rpt *myrpt, struct rpt_link *mylink,
- char c)
-{
-
-char cmd[300];
-int res;
-
- ast_mutex_lock(&myrpt->lock);
- if (c == myrpt->endchar)
- {
- if (mylink->lastrx)
- {
- mylink->lastrx = 0;
- ast_mutex_unlock(&myrpt->lock);
- return;
- }
- myrpt->stopgen = 1;
- if (myrpt->cmdnode[0])
- {
- myrpt->cmdnode[0] = 0;
- myrpt->dtmfidx = -1;
- myrpt->dtmfbuf[0] = 0;
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt,COMPLETE,NULL);
- ast_mutex_unlock(&myrpt->lock);
- return;
- }
- }
- if (myrpt->cmdnode[0])
- {
- ast_mutex_unlock(&myrpt->lock);
- send_link_dtmf(myrpt,c);
- return;
- }
- if (myrpt->callmode == 1)
- {
- myrpt->exten[myrpt->cidx++] = c;
- myrpt->exten[myrpt->cidx] = 0;
- /* if this exists */
- if (ast_exists_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
- {
- myrpt->callmode = 2;
- rpt_telemetry(myrpt,PROC,NULL);
- }
- /* if can continue, do so */
- if (!ast_canmatch_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
- {
- /* call has failed, inform user */
- myrpt->callmode = 4;
- }
- }
- if ((myrpt->callmode == 2) || (myrpt->callmode == 3))
- {
- myrpt->mydtmf = c;
- }
- if (c == myrpt->funcchar)
- {
- myrpt->rem_dtmfidx = 0;
- myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
- time(&myrpt->rem_dtmf_time);
- ast_mutex_unlock(&myrpt->lock);
- return;
- }
- else if ((c != myrpt->endchar) && (myrpt->rem_dtmfidx >= 0))
- {
- time(&myrpt->rem_dtmf_time);
- if (myrpt->rem_dtmfidx < MAXDTMF)
- {
- myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx++] = c;
- myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
-
- ast_mutex_unlock(&myrpt->lock);
- strncpy(cmd, myrpt->rem_dtmfbuf, sizeof(cmd) - 1);
- res = collect_function_digits(myrpt, cmd,
- ((mylink->phonemode == 2) ? SOURCE_DPHONE : SOURCE_PHONE), mylink);
- ast_mutex_lock(&myrpt->lock);
-
- switch(res){
-
- case DC_INDETERMINATE:
- break;
-
- case DC_DOKEY:
- mylink->lastrx = 1;
- break;
-
- case DC_REQ_FLUSH:
- myrpt->rem_dtmfidx = 0;
- myrpt->rem_dtmfbuf[0] = 0;
- break;
-
-
- case DC_COMPLETE:
- myrpt->rem_dtmfbuf[0] = 0;
- myrpt->rem_dtmfidx = -1;
- myrpt->rem_dtmf_time = 0;
- break;
-
- case DC_ERROR:
- default:
- myrpt->rem_dtmfbuf[0] = 0;
- myrpt->rem_dtmfidx = -1;
- myrpt->rem_dtmf_time = 0;
- break;
- }
- }
-
- }
- ast_mutex_unlock(&myrpt->lock);
- return;
-}
-
-/* Doug Hall RBI-1 serial data definitions:
- *
- * Byte 0: Expansion external outputs
- * Byte 1:
- * Bits 0-3 are BAND as follows:
- * Bits 4-5 are POWER bits as follows:
- * 00 - Low Power
- * 01 - Hi Power
- * 02 - Med Power
- * Bits 6-7 are always set
- * Byte 2:
- * Bits 0-3 MHZ in BCD format
- * Bits 4-5 are offset as follows:
- * 00 - minus
- * 01 - plus
- * 02 - simplex
- * 03 - minus minus (whatever that is)
- * Bit 6 is the 0/5 KHZ bit
- * Bit 7 is always set
- * Byte 3:
- * Bits 0-3 are 10 KHZ in BCD format
- * Bits 4-7 are 100 KHZ in BCD format
- * Byte 4: PL Tone code and encode/decode enable bits
- * Bits 0-5 are PL tone code (comspec binary codes)
- * Bit 6 is encode enable/disable
- * Bit 7 is decode enable/disable
- */
-
-/* take the frequency from the 10 mhz digits (and up) and convert it
- to a band number */
-
-static int rbi_mhztoband(char *str)
-{
-int i;
-
- i = atoi(str) / 10; /* get the 10's of mhz */
- switch(i)
- {
- case 2:
- return 10;
- case 5:
- return 11;
- case 14:
- return 2;
- case 22:
- return 3;
- case 44:
- return 4;
- case 124:
- return 0;
- case 125:
- return 1;
- case 126:
- return 8;
- case 127:
- return 5;
- case 128:
- return 6;
- case 129:
- return 7;
- default:
- break;
- }
- return -1;
-}
-
-/* take a PL frequency and turn it into a code */
-static int rbi_pltocode(char *str)
-{
-int i;
-char *s;
-
- s = strchr(str,'.');
- i = 0;
- if (s) i = atoi(s + 1);
- i += atoi(str) * 10;
- switch(i)
- {
- case 670:
- return 0;
- case 719:
- return 1;
- case 744:
- return 2;
- case 770:
- return 3;
- case 797:
- return 4;
- case 825:
- return 5;
- case 854:
- return 6;
- case 885:
- return 7;
- case 915:
- return 8;
- case 948:
- return 9;
- case 974:
- return 10;
- case 1000:
- return 11;
- case 1035:
- return 12;
- case 1072:
- return 13;
- case 1109:
- return 14;
- case 1148:
- return 15;
- case 1188:
- return 16;
- case 1230:
- return 17;
- case 1273:
- return 18;
- case 1318:
- return 19;
- case 1365:
- return 20;
- case 1413:
- return 21;
- case 1462:
- return 22;
- case 1514:
- return 23;
- case 1567:
- return 24;
- case 1622:
- return 25;
- case 1679:
- return 26;
- case 1738:
- return 27;
- case 1799:
- return 28;
- case 1862:
- return 29;
- case 1928:
- return 30;
- case 2035:
- return 31;
- case 2107:
- return 32;
- case 2181:
- return 33;
- case 2257:
- return 34;
- case 2336:
- return 35;
- case 2418:
- return 36;
- case 2503:
- return 37;
- }
- return -1;
-}
-
-/*
-* Shift out a formatted serial bit stream
-*/
-
-static void rbi_out_parallel(struct rpt *myrpt,unsigned char *data)
- {
- int i,j;
- unsigned char od,d;
- static volatile long long delayvar;
-
- for(i = 0 ; i < 5 ; i++){
- od = *data++;
- for(j = 0 ; j < 8 ; j++){
- d = od & 1;
- outb(d,myrpt->iobase);
- /* >= 15 us */
- for(delayvar = 1; delayvar < 15000; delayvar++);
- od >>= 1;
- outb(d | 2,myrpt->iobase);
- /* >= 30 us */
- for(delayvar = 1; delayvar < 30000; delayvar++);
- outb(d,myrpt->iobase);
- /* >= 10 us */
- for(delayvar = 1; delayvar < 10000; delayvar++);
- }
- }
- /* >= 50 us */
- for(delayvar = 1; delayvar < 50000; delayvar++);
- }
-
-static void rbi_out(struct rpt *myrpt,unsigned char *data)
-{
-struct zt_radio_param r;
-
- memset(&r,0,sizeof(struct zt_radio_param));
- r.radpar = ZT_RADPAR_REMMODE;
- r.data = ZT_RADPAR_REM_RBI1;
- /* if setparam ioctl fails, its probably not a pciradio card */
- if (ioctl(myrpt->rxchannel->fds[0],ZT_RADIO_SETPARAM,&r) == -1)
- {
- rbi_out_parallel(myrpt,data);
- return;
- }
- r.radpar = ZT_RADPAR_REMCOMMAND;
- memcpy(&r.data,data,5);
- if (ioctl(myrpt->rxchannel->fds[0],ZT_RADIO_SETPARAM,&r) == -1)
- {
- ast_log(LOG_WARNING,"Cannot send RBI command for channel %s\n",myrpt->rxchannel->name);
- return;
- }
-}
-
-static int serial_remote_io(struct rpt *myrpt, char *txbuf, int txbytes, char *rxbuf,
- int rxmaxbytes, int asciiflag)
-{
- int i;
- struct zt_radio_param prm;
-
- if(debug){
- printf("String output was: ");
- for(i = 0; i < txbytes; i++)
- printf("%02X ", (unsigned char ) txbuf[i]);
- printf("\n");
- }
-
- prm.radpar = ZT_RADPAR_REMMODE;
- if (asciiflag) prm.data = ZT_RADPAR_REM_SERIAL_ASCII;
- else prm.data = ZT_RADPAR_REM_SERIAL;
- if (ioctl(myrpt->rxchannel->fds[0],ZT_RADIO_SETPARAM,&prm) == -1) return -1;
- prm.radpar = ZT_RADPAR_REMCOMMAND;
- prm.data = rxmaxbytes;
- memcpy(prm.buf,txbuf,txbytes);
- prm.index = txbytes;
- if (ioctl(myrpt->rxchannel->fds[0],ZT_RADIO_SETPARAM,&prm) == -1) return -1;
- if (rxbuf)
- {
- *rxbuf = 0;
- memcpy(rxbuf,prm.buf,prm.index);
- }
- return(prm.index);
-}
-
-static int setrbi(struct rpt *myrpt)
-{
-char tmp[MAXREMSTR] = "",rbicmd[5],*s;
-int band,txoffset = 0,txpower = 0,txpl;
-
- /* must be a remote system */
- if (!myrpt->remote) return(0);
- /* must have rbi hardware */
- if (strncmp(myrpt->remote,remote_rig_rbi,3)) return(0);
- strncpy(tmp, myrpt->freq, sizeof(tmp) - 1);
- s = strchr(tmp,'.');
- /* if no decimal, is invalid */
-
- if (s == NULL){
- if(debug)
- printf("@@@@ Frequency needs a decimal\n");
- return -1;
- }
-
- *s++ = 0;
- if (strlen(tmp) < 2){
- if(debug)
- printf("@@@@ Bad MHz digits: %s\n", tmp);
- return -1;
- }
-
- if (strlen(s) < 3){
- if(debug)
- printf("@@@@ Bad KHz digits: %s\n", s);
- return -1;
- }
-
- if ((s[2] != '0') && (s[2] != '5')){
- if(debug)
- printf("@@@@ KHz must end in 0 or 5: %c\n", s[2]);
- return -1;
- }
-
- band = rbi_mhztoband(tmp);
- if (band == -1){
- if(debug)
- printf("@@@@ Bad Band: %s\n", tmp);
- return -1;
- }
-
- txpl = rbi_pltocode(myrpt->txpl);
-
- if (txpl == -1){
- if(debug)
- printf("@@@@ Bad TX PL: %s\n", myrpt->txpl);
- return -1;
- }
-
-
- switch(myrpt->offset)
- {
- case REM_MINUS:
- txoffset = 0;
- break;
- case REM_PLUS:
- txoffset = 0x10;
- break;
- case REM_SIMPLEX:
- txoffset = 0x20;
- break;
- }
- switch(myrpt->powerlevel)
- {
- case REM_LOWPWR:
- txpower = 0;
- break;
- case REM_MEDPWR:
- txpower = 0x20;
- break;
- case REM_HIPWR:
- txpower = 0x10;
- break;
- }
- rbicmd[0] = 0;
- rbicmd[1] = band | txpower | 0xc0;
- rbicmd[2] = (*(s - 2) - '0') | txoffset | 0x80;
- if (s[2] == '5') rbicmd[2] |= 0x40;
- rbicmd[3] = ((*s - '0') << 4) + (s[1] - '0');
- rbicmd[4] = txpl;
- if (myrpt->txplon) rbicmd[4] |= 0x40;
- if (myrpt->rxplon) rbicmd[4] |= 0x80;
- rbi_out(myrpt,rbicmd);
- return 0;
-}
-
-
-/* Check for valid rbi frequency */
-/* Hard coded limits now, configurable later, maybe? */
-
-static int check_freq_rbi(int m, int d, int *defmode)
-{
- int dflmd = REM_MODE_FM;
-
- if(m == 50){ /* 6 meters */
- if(d < 10100)
- return -1;
- }
- else if((m >= 51) && ( m < 54)){
- ;
- }
- else if(m == 144){ /* 2 meters */
- if(d < 10100)
- return -1;
- }
- else if((m >= 145) && (m < 148)){
- ;
- }
- else if((m >= 222) && (m < 225)){ /* 1.25 meters */
- ;
- }
- else if((m >= 430) && (m < 450)){ /* 70 centimeters */
- ;
- }
- else if((m >= 1240) && (m < 1300)){ /* 23 centimeters */
- ;
- }
- else
- return -1;
-
- if(defmode)
- *defmode = dflmd;
-
-
- return 0;
-}
-
-/*
-* Split frequency into mhz and decimals
-*/
-
-static int split_freq(char *mhz, char *decimals, char *freq)
-{
- char freq_copy[MAXREMSTR];
- char *decp;
-
- decp = strchr(strncpy(freq_copy, freq, MAXREMSTR),'.');
- if(decp){
- *decp++ = 0;
- strncpy(mhz, freq_copy, MAXREMSTR);
- strcpy(decimals, "00000");
- strncpy(decimals, decp, strlen(decp));
- decimals[5] = 0;
- return 0;
- }
- else
- return -1;
-
-}
-
-/*
-* Split ctcss frequency into hertz and decimal
-*/
-
-static int split_ctcss_freq(char *hertz, char *decimal, char *freq)
-{
- char freq_copy[MAXREMSTR];
- char *decp;
-
- decp = strchr(strncpy(freq_copy, freq, MAXREMSTR),'.');
- if(decp){
- *decp++ = 0;
- strncpy(hertz, freq_copy, MAXREMSTR);
- strncpy(decimal, decp, strlen(decp));
- decimal[strlen(decp)] = '\0';
- return 0;
- }
- else
- return -1;
-}
-
-
-
-/*
-* FT-897 I/O handlers
-*/
-
-/* Check to see that the frequency is valid */
-/* Hard coded limits now, configurable later, maybe? */
-
-
-static int check_freq_ft897(int m, int d, int *defmode)
-{
- int dflmd = REM_MODE_FM;
-
- if(m == 1){ /* 160 meters */
- dflmd = REM_MODE_LSB;
- if(d < 80001)
- return -1;
- }
- else if(m == 3){ /* 80 meters */
- dflmd = REM_MODE_LSB;
- if(d < 75001)
- return -1;
- }
- else if(m == 7){ /* 40 meters */
- dflmd = REM_MODE_LSB;
- if((d < 15001) || (d > 29999))
- return -1;
- }
- else if(m == 14){ /* 20 meters */
- dflmd = REM_MODE_USB;
- if((d < 15001) || (d > 34999))
- return -1;
- }
- else if(m == 18){ /* 17 meters */
- dflmd = REM_MODE_USB;
- if((d < 11001) || (d > 16797))
- return -1;
- }
- else if(m == 21){ /* 15 meters */
- dflmd = REM_MODE_USB;
- if((d < 20001) || (d > 44999))
- return -1;
- }
- else if(m == 24){ /* 12 meters */
- dflmd = REM_MODE_USB;
- if((d < 93001) || (d > 98999))
- return -1;
- }
- else if(m == 28){ /* 10 meters */
- dflmd = REM_MODE_USB;
- if(d < 30001)
- return -1;
- }
- else if(m == 29){
- if(d >= 51000)
- dflmd = REM_MODE_FM;
- else
- dflmd = REM_MODE_USB;
- if(d > 69999)
- return -1;
- }
- else if(m == 50){ /* 6 meters */
- if(d < 10100)
- return -1;
- if(d >= 30000)
- dflmd = REM_MODE_FM;
- else
- dflmd = REM_MODE_USB;
-
- }
- else if((m >= 51) && ( m < 54)){
- dflmd = REM_MODE_FM;
- }
- else if(m == 144){ /* 2 meters */
- if(d < 10100)
- return -1;
- if(d >= 30000)
- dflmd = REM_MODE_FM;
- else
- dflmd = REM_MODE_USB;
- }
- else if((m >= 145) && (m < 148)){
- dflmd = REM_MODE_FM;
- }
- else if((m >= 430) && (m < 450)){ /* 70 centimeters */
- if(m < 438)
- dflmd = REM_MODE_USB;
- else
- dflmd = REM_MODE_FM;
- ;
- }
- else
- return -1;
-
- if(defmode)
- *defmode = dflmd;
-
- return 0;
-}
-
-/*
-* Set a new frequency for the FT897
-*/
-
-static int set_freq_ft897(struct rpt *myrpt, char *newfreq)
-{
- char mhz[MAXREMSTR];
- char decimals[MAXREMSTR];
- unsigned char cmdstr[5];
- int fd,m,d;
-
- fd = 0;
- if(debug)
- printf("New frequency: %s\n",newfreq);
-
- if(split_freq(mhz, decimals, newfreq))
- return -1;
-
- m = atoi(mhz);
- d = atoi(decimals);
-
- /* The FT-897 likes packed BCD frequencies */
-
- cmdstr[0] = ((m / 100) << 4) + ((m % 100)/10); /* 100MHz 10Mhz */
- cmdstr[1] = ((m % 10) << 4) + (d / 10000); /* 1MHz 100KHz */
- cmdstr[2] = (((d % 10000)/1000) << 4) + ((d % 1000)/ 100); /* 10KHz 1KHz */
- cmdstr[3] = (((d % 100)/10) << 4) + (d % 10); /* 100Hz 10Hz */
- cmdstr[4] = 0x01; /* command */
-
- return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
-
-}
-
-/* ft-897 simple commands */
-
-static int simple_command_ft897(struct rpt *myrpt, char command)
-{
- unsigned char cmdstr[5];
-
- memset(cmdstr, 0, 5);
-
- cmdstr[4] = command;
-
- return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
-
-}
-
-/* ft-897 offset */
-
-static int set_offset_ft897(struct rpt *myrpt, char offset)
-{
- unsigned char cmdstr[5];
-
- memset(cmdstr, 0, 5);
-
- switch(offset){
- case REM_SIMPLEX:
- cmdstr[0] = 0x89;
- break;
-
- case REM_MINUS:
- cmdstr[0] = 0x09;
- break;
-
- case REM_PLUS:
- cmdstr[0] = 0x49;
- break;
-
- default:
- return -1;
- }
-
- cmdstr[4] = 0x09;
-
- return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
-}
-
-/* ft-897 mode */
-
-static int set_mode_ft897(struct rpt *myrpt, char newmode)
-{
- unsigned char cmdstr[5];
-
- memset(cmdstr, 0, 5);
-
- switch(newmode){
- case REM_MODE_FM:
- cmdstr[0] = 0x08;
- break;
-
- case REM_MODE_USB:
- cmdstr[0] = 0x01;
- break;
-
- case REM_MODE_LSB:
- cmdstr[0] = 0x00;
- break;
-
- case REM_MODE_AM:
- cmdstr[0] = 0x04;
- break;
-
- default:
- return -1;
- }
- cmdstr[4] = 0x07;
-
- return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
-}
-
-/* Set tone encode and decode modes */
-
-static int set_ctcss_mode_ft897(struct rpt *myrpt, char txplon, char rxplon)
-{
- unsigned char cmdstr[5];
-
- memset(cmdstr, 0, 5);
-
- if(rxplon && txplon)
- cmdstr[0] = 0x2A; /* Encode and Decode */
- else if (!rxplon && txplon)
- cmdstr[0] = 0x4A; /* Encode only */
- else if (rxplon && !txplon)
- cmdstr[0] = 0x3A; /* Encode only */
- else
- cmdstr[0] = 0x8A; /* OFF */
-
- cmdstr[4] = 0x0A;
-
- return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
-}
-
-
-/* Set transmit and receive ctcss tone frequencies */
-
-static int set_ctcss_freq_ft897(struct rpt *myrpt, char *txtone, char *rxtone)
-{
- unsigned char cmdstr[5];
- char hertz[MAXREMSTR],decimal[MAXREMSTR];
- int h,d;
-
- memset(cmdstr, 0, 5);
-
- if(split_ctcss_freq(hertz, decimal, txtone))
- return -1;
-
- h = atoi(hertz);
- d = atoi(decimal);
-
- cmdstr[0] = ((h / 100) << 4) + (h % 100)/ 10;
- cmdstr[1] = ((h % 10) << 4) + (d % 10);
-
- if(rxtone){
-
- if(split_ctcss_freq(hertz, decimal, rxtone))
- return -1;
-
- h = atoi(hertz);
- d = atoi(decimal);
-
- cmdstr[2] = ((h / 100) << 4) + (h % 100)/ 10;
- cmdstr[3] = ((h % 10) << 4) + (d % 10);
- }
- cmdstr[4] = 0x0B;
-
- return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
-}
-
-
-
-static int set_ft897(struct rpt *myrpt)
-{
- int res;
-
- if(debug)
- printf("@@@@ lock on\n");
-
- res = simple_command_ft897(myrpt, 0x00); /* LOCK on */
-
- if(debug)
- printf("@@@@ ptt off\n");
-
- if(!res)
- res = simple_command_ft897(myrpt, 0x88); /* PTT off */
-
- if(debug)
- printf("Modulation mode\n");
-
- if(!res)
- res = set_mode_ft897(myrpt, myrpt->remmode); /* Modulation mode */
-
- if(debug)
- printf("Split off\n");
-
- if(!res)
- simple_command_ft897(myrpt, 0x82); /* Split off */
-
- if(debug)
- printf("Frequency\n");
-
- if(!res)
- res = set_freq_ft897(myrpt, myrpt->freq); /* Frequency */
- if((myrpt->remmode == REM_MODE_FM)){
- if(debug)
- printf("Offset\n");
- if(!res)
- res = set_offset_ft897(myrpt, myrpt->offset); /* Offset if FM */
- if((!res)&&(myrpt->rxplon || myrpt->txplon)){
- if(debug)
- printf("CTCSS tone freqs.\n");
- res = set_ctcss_freq_ft897(myrpt, myrpt->txpl, myrpt->rxpl); /* CTCSS freqs if CTCSS is enabled */
- }
- if(!res){
- if(debug)
- printf("CTCSS mode\n");
- res = set_ctcss_mode_ft897(myrpt, myrpt->txplon, myrpt->rxplon); /* CTCSS mode */
- }
- }
- if((myrpt->remmode == REM_MODE_USB)||(myrpt->remmode == REM_MODE_LSB)){
- if(debug)
- printf("Clarifier off\n");
- simple_command_ft897(myrpt, 0x85); /* Clarifier off if LSB or USB */
- }
- return res;
-}
-
-static int closerem_ft897(struct rpt *myrpt)
-{
- simple_command_ft897(myrpt, 0x88); /* PTT off */
- return 0;
-}
-
-/*
-* Bump frequency up or down by a small amount
-* Return 0 if the new frequnecy is valid, or -1 if invalid
-* Interval is in Hz, resolution is 10Hz
-*/
-
-static int multimode_bump_freq_ft897(struct rpt *myrpt, int interval)
-{
- int m,d;
- char mhz[MAXREMSTR], decimals[MAXREMSTR];
-
- if(debug)
- printf("Before bump: %s\n", myrpt->freq);
-
- if(split_freq(mhz, decimals, myrpt->freq))
- return -1;
-
- m = atoi(mhz);
- d = atoi(decimals);
-
- d += (interval / 10); /* 10Hz resolution */
- if(d < 0){
- m--;
- d += 100000;
- }
- else if(d >= 100000){
- m++;
- d -= 100000;
- }
-
- if(check_freq_ft897(m, d, NULL)){
- if(debug)
- printf("Bump freq invalid\n");
- return -1;
- }
-
- snprintf(myrpt->freq, MAXREMSTR, "%d.%05d", m, d);
-
- if(debug)
- printf("After bump: %s\n", myrpt->freq);
-
- return set_freq_ft897(myrpt, myrpt->freq);
-}
-
-
-
-/*
-* Dispatch to correct I/O handler
-*/
-
-static int setrem(struct rpt *myrpt)
-{
- if(!strcmp(myrpt->remote, remote_rig_ft897))
- return set_ft897(myrpt);
- else if(!strcmp(myrpt->remote, remote_rig_rbi))
- return setrbi(myrpt);
- else
- return -1;
-}
-
-static int closerem(struct rpt *myrpt)
-{
- if(!strcmp(myrpt->remote, remote_rig_ft897))
- return closerem_ft897(myrpt);
- else
- return 0;
-}
-
-/*
-* Dispatch to correct frequency checker
-*/
-
-static int check_freq(struct rpt *myrpt, int m, int d, int *defmode)
-{
- if(!strcmp(myrpt->remote, remote_rig_ft897))
- return check_freq_ft897(m, d, defmode);
- else if(!strcmp(myrpt->remote, remote_rig_rbi))
- return check_freq_rbi(m, d, defmode);
- else
- return -1;
-}
-
-/*
-* Return 1 if rig is multimode capable
-*/
-
-static int multimode_capable(struct rpt *myrpt)
-{
- if(!strcmp(myrpt->remote, remote_rig_ft897))
- return 1;
- return 0;
-}
-
-/*
-* Dispatch to correct frequency bumping function
-*/
-
-static int multimode_bump_freq(struct rpt *myrpt, int interval)
-{
- if(!strcmp(myrpt->remote, remote_rig_ft897))
- return multimode_bump_freq_ft897(myrpt, interval);
- else
- return -1;
-}
-
-
-/*
-* Queue announcment that scan has been stopped
-*/
-
-static void stop_scan(struct rpt *myrpt, int flag)
-{
- myrpt->hfscanmode = 0;
- myrpt->hfscanstatus = ((flag) ? -2 : -1);
-}
-
-/*
-* This is called periodically when in scan mode
-*/
-
-
-static int service_scan(struct rpt *myrpt)
-{
- int res, interval;
- char mhz[MAXREMSTR], decimals[MAXREMSTR], k10=0i, k100=0;
-
- switch(myrpt->hfscanmode){
-
- case HF_SCAN_DOWN_SLOW:
- interval = -10; /* 100Hz /sec */
- break;
-
- case HF_SCAN_DOWN_QUICK:
- interval = -50; /* 500Hz /sec */
- break;
-
- case HF_SCAN_DOWN_FAST:
- interval = -200; /* 2KHz /sec */
- break;
-
- case HF_SCAN_UP_SLOW:
- interval = 10; /* 100Hz /sec */
- break;
-
- case HF_SCAN_UP_QUICK:
- interval = 50; /* 500 Hz/sec */
- break;
-
- case HF_SCAN_UP_FAST:
- interval = 200; /* 2KHz /sec */
- break;
-
- default:
- myrpt->hfscanmode = 0; /* Huh? */
- return -1;
- }
-
- res = split_freq(mhz, decimals, myrpt->freq);
-
- if(!res){
- k100 =decimals[0];
- k10 = decimals[1];
- res = multimode_bump_freq(myrpt, interval);
- }
-
- if(!res)
- res = split_freq(mhz, decimals, myrpt->freq);
-
-
- if(res){
- stop_scan(myrpt,1);
- return -1;
- }
-
- /* Announce 10KHz boundaries */
- if(k10 != decimals[1]){
- int myhund = (interval < 0) ? k100 : decimals[0];
- int myten = (interval < 0) ? k10 : decimals[1];
- myrpt->hfscanstatus = (myten == '0') ? (myhund - '0') * 100 : (myten - '0') * 10;
- }
- return res;
-
-}
-
-
-static int rmt_telem_start(struct rpt *myrpt, struct ast_channel *chan, int delay)
-{
- myrpt->remotetx = 0;
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
- if (!myrpt->remoterx)
- ast_indicate(chan,AST_CONTROL_RADIO_KEY);
- if (ast_safe_sleep(chan, delay) == -1)
- return -1;
- return 0;
-}
-
-
-static int rmt_telem_finish(struct rpt *myrpt, struct ast_channel *chan)
-{
-
-struct zt_params par;
-
- if (ioctl(myrpt->txchannel->fds[0],ZT_GET_PARAMS,&par) == -1)
- {
- return -1;
-
- }
- if (!par.rxisoffhook)
- {
- ast_indicate(myrpt->remchannel,AST_CONTROL_RADIO_UNKEY);
- myrpt->remoterx = 0;
- }
- else
- {
- myrpt->remoterx = 1;
- }
- return 0;
-}
-
-
-static int rmt_sayfile(struct rpt *myrpt, struct ast_channel *chan, int delay, char *filename)
-{
- int res;
-
- res = rmt_telem_start(myrpt, chan, delay);
-
- if(!res)
- res = sayfile(chan, filename);
-
- if(!res)
- res = rmt_telem_finish(myrpt, chan);
- return res;
-}
-
-static int rmt_saycharstr(struct rpt *myrpt, struct ast_channel *chan, int delay, char *charstr)
-{
- int res;
-
- res = rmt_telem_start(myrpt, chan, delay);
-
- if(!res)
- res = saycharstr(chan, charstr);
-
- if(!res)
- res = rmt_telem_finish(myrpt, chan);
- return res;
-}
-
-
-
-/*
-* Remote base function
-*/
-
-static int function_remote(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
-{
- char *s,*s1,*s2,*val;
- int i,j,ht,k,l,ls2,m,d,res,offset,offsave, modesave, defmode;
- char multimode = 0;
- char oc;
- char tmp[20], freq[20] = "", savestr[20] = "";
- char mhz[MAXREMSTR], decimals[MAXREMSTR];
- struct ast_channel *mychannel;
-
- if((!param) || (command_source == SOURCE_RPT) || (command_source == SOURCE_LNK))
- return DC_ERROR;
-
- multimode = multimode_capable(myrpt);
-
- mychannel = myrpt->remchannel;
-
-
- switch(myatoi(param)){
-
- case 1: /* retrieve memory */
- if(strlen(digitbuf) < 2) /* needs 2 digits */
- break;
-
- for(i = 0 ; i < 2 ; i++){
- if((digitbuf[i] < '0') || (digitbuf[i] > '9'))
- return DC_ERROR;
- }
-
- val = ast_variable_retrieve(cfg, MEMORY, digitbuf);
- if (!val){
- if (ast_safe_sleep(mychannel,1000) == -1)
- return DC_ERROR;
- sayfile(mychannel,"rpt/memory_notfound");
- return DC_COMPLETE;
- }
- strncpy(tmp,val,sizeof(tmp) - 1);
- s = strchr(tmp,',');
- if (!s)
- return DC_ERROR;
- *s++ = 0;
- s1 = strchr(s,',');
- if (!s1)
- return DC_ERROR;
- *s1++ = 0;
- strncpy(myrpt->freq, tmp, sizeof(myrpt->freq) - 1);
- strncpy(myrpt->rxpl, s, sizeof(myrpt->rxpl) - 1);
- strncpy(myrpt->txpl, s, sizeof(myrpt->rxpl) - 1);
- myrpt->remmode = REM_MODE_FM;
- myrpt->offset = REM_SIMPLEX;
- myrpt->powerlevel = REM_MEDPWR;
- myrpt->txplon = myrpt->rxplon = 0;
- while(*s1)
- {
- switch(*s1++){
- case 'A':
- case 'a':
- strcpy(myrpt->rxpl, "100.0");
- strcpy(myrpt->txpl, "100.0");
- myrpt->remmode = REM_MODE_AM;
- break;
-
- case 'B':
- case 'b':
- strcpy(myrpt->rxpl, "100.0");
- strcpy(myrpt->txpl, "100.0");
- myrpt->remmode = REM_MODE_LSB;
- break;
-
- case 'F':
- myrpt->remmode = REM_MODE_FM;
- break;
-
- case 'L':
- case 'l':
- myrpt->powerlevel = REM_LOWPWR;
- break;
- case 'H':
- case 'h':
- myrpt->powerlevel = REM_HIPWR;
- break;
-
- case 'M':
- case 'm':
- myrpt->powerlevel = REM_MEDPWR;
- break;
-
- case '-':
- myrpt->offset = REM_MINUS;
- break;
-
- case '+':
- myrpt->offset = REM_PLUS;
- break;
-
- case 'S':
- case 's':
- myrpt->offset = REM_SIMPLEX;
- break;
-
- case 'T':
- case 't':
- myrpt->txplon = 1;
- break;
-
- case 'R':
- case 'r':
- myrpt->rxplon = 1;
- break;
-
- case 'U':
- case 'u':
- strcpy(myrpt->rxpl, "100.0");
- strcpy(myrpt->txpl, "100.0");
- myrpt->remmode = REM_MODE_USB;
- break;
- }
- }
-
-
- if (setrem(myrpt) == -1)
- return DC_ERROR;
-
-
- return DC_COMPLETE;
-
- case 2: /* set freq and offset */
-
-
- for(i = 0, j = 0, k = 0, l = 0 ; digitbuf[i] ; i++){ /* look for M+*K+*O or M+*H+* depending on mode */
- if(digitbuf[i] == '*'){
- j++;
- continue;
- }
- if((digitbuf[i] < '0') || (digitbuf[i] > '9'))
- goto invalid_freq;
- else{
- if(j == 0)
- l++; /* # of digits before first * */
- if(j == 1)
- k++; /* # of digits after first * */
- }
- }
-
- i = strlen(digitbuf) - 1;
- if(multimode){
- if((j > 2) || (l > 3) || (k > 6))
- goto invalid_freq; /* &^@#! */
- }
- else{
- if((j > 2) || (l > 4) || (k > 3))
- goto invalid_freq; /* &^@#! */
- }
-
- /* Wait for M+*K+* */
-
- if(j < 2)
- break; /* Not yet */
-
- /* We have a frequency */
-
- strncpy(tmp, digitbuf ,sizeof(tmp) - 1);
-
- s = tmp;
- s1 = strsep(&s, "*"); /* Pick off MHz */
- s2 = strsep(&s,"*"); /* Pick off KHz and Hz */
- ls2 = strlen(s2);
-
- switch(ls2){ /* Allow partial entry of khz and hz digits for laziness support */
- case 1:
- ht = 0;
- k = 100 * atoi(s2);
- break;
-
- case 2:
- ht = 0;
- k = 10 * atoi(s2);
- break;
-
- case 3:
- if(!multimode){
- if((s2[2] != '0')&&(s2[2] != '5'))
- goto invalid_freq;
- }
- ht = 0;
- k = atoi(s2);
- break;
- case 4:
- k = atoi(s2)/10;
- ht = 10 * (atoi(s2+(ls2-1)));
- break;
-
- case 5:
- k = atoi(s2)/100;
- ht = (atoi(s2+(ls2-2)));
- break;
-
- default:
- goto invalid_freq;
- }
-
- /* Check frequency for validity and establish a default mode */
-
- snprintf(freq, sizeof(freq), "%s.%03d%02d",s1, k, ht);
-
- if(debug)
- printf("New frequency: %s\n", freq);
-
- split_freq(mhz, decimals, freq);
- m = atoi(mhz);
- d = atoi(decimals);
-
- if(check_freq(myrpt, m, d, &defmode)) /* Check to see if frequency entered is legit */
- goto invalid_freq;
-
-
- if((defmode == REM_MODE_FM) && (digitbuf[i] == '*')) /* If FM, user must enter and additional offset digit */
- break; /* Not yet */
-
-
- offset = REM_SIMPLEX; /* Assume simplex */
-
- if(defmode == REM_MODE_FM){
- oc = *s; /* Pick off offset */
-
- if (oc){
- switch(oc){
- case '1':
- offset = REM_MINUS;
- break;
-
- case '2':
- offset = REM_SIMPLEX;
- break;
-
- case '3':
- offset = REM_PLUS;
- break;
-
- default:
- goto invalid_freq;
- }
- }
- }
- offsave = myrpt->offset;
- modesave = myrpt->remmode;
- strncpy(savestr, myrpt->freq, sizeof(savestr) - 1);
- strncpy(myrpt->freq, freq, sizeof(myrpt->freq) - 1);
- myrpt->offset = offset;
- myrpt->remmode = defmode;
-
- if (setrem(myrpt) == -1){
- myrpt->offset = offsave;
- myrpt->remmode = modesave;
- strncpy(myrpt->freq, savestr, sizeof(myrpt->freq) - 1);
- goto invalid_freq;
- }
-
- return DC_COMPLETE;
-
-
- invalid_freq:
-
- rmt_sayfile(myrpt, mychannel, 1000, "rpt/invalid-freq");
-
- return DC_ERROR;
-
- case 3: /* set rx PL tone */
-
- for(i = 0, j = 0, k = 0, l = 0 ; digitbuf[i] ; i++){ /* look for N+*N */
- if(digitbuf[i] == '*'){
- j++;
- continue;
- }
- if((digitbuf[i] < '0') || (digitbuf[i] > '9'))
- return DC_ERROR;
- else{
- if(j)
- l++;
- else
- k++;
- }
- }
- if((j > 1) || (k > 3) || (l > 1))
- return DC_ERROR; /* &$@^! */
- i = strlen(digitbuf) - 1;
- if((j != 1) || (k < 2)|| (l != 1))
- break; /* Not yet */
- if(debug)
- printf("PL digits entered %s\n", digitbuf);
-
- strncpy(tmp, digitbuf, sizeof(tmp) - 1);
- /* see if we have at least 1 */
- s = strchr(tmp,'*');
- if(s)
- *s = '.';
- strncpy(savestr, myrpt->rxpl, sizeof(savestr) - 1);
- strncpy(myrpt->rxpl, tmp, sizeof(myrpt->rxpl) - 1);
-
- if (setrem(myrpt) == -1){
- strncpy(myrpt->rxpl, savestr, sizeof(myrpt->rxpl) - 1);
- return DC_ERROR;
- }
-
-
- return DC_COMPLETE;
-
- case 4: /* set tx PL tone */
-
- for(i = 0, j = 0, k = 0, l = 0 ; digitbuf[i] ; i++){ /* look for N+*N */
- if(digitbuf[i] == '*'){
- j++;
- continue;
- }
- if((digitbuf[i] < '0') || (digitbuf[i] > '9'))
- return DC_ERROR;
- else{
- if(j)
- l++;
- else
- k++;
- }
- }
- if((j > 1) || (k > 3) || (l > 1))
- return DC_ERROR; /* &$@^! */
- i = strlen(digitbuf) - 1;
- if((j != 1) || (k < 2)|| (l != 1))
- break; /* Not yet */
- if(debug)
- printf("PL digits entered %s\n", digitbuf);
-
- strncpy(tmp, digitbuf, sizeof(tmp) - 1);
- /* see if we have at least 1 */
- s = strchr(tmp,'*');
- if(s)
- *s = '.';
- strncpy(savestr, myrpt->txpl, sizeof(savestr) - 1);
- strncpy(myrpt->txpl, tmp, sizeof(myrpt->txpl) - 1);
-
- if (setrem(myrpt) == -1){
- strncpy(myrpt->txpl, savestr, sizeof(myrpt->txpl) - 1);
- return DC_ERROR;
- }
-
-
- return DC_COMPLETE;
-
-
- case 6: /* MODE (FM,USB,LSB,AM) */
- if(strlen(digitbuf) < 1)
- break;
-
- if(!multimode)
- return DC_ERROR; /* Multimode radios only */
-
- switch(*digitbuf){
- case '1':
- split_freq(mhz, decimals, myrpt->freq);
- m=atoi(mhz);
- if(m < 29) /* No FM allowed below 29MHz! */
- return DC_ERROR;
- myrpt->remmode = REM_MODE_FM;
- res = rmt_saycharstr(myrpt, mychannel, 1000,"FM");
- break;
-
- case '2':
- myrpt->remmode = REM_MODE_USB;
- res = rmt_saycharstr(myrpt, mychannel, 1000,"USB");
- break;
-
- case '3':
- myrpt->remmode = REM_MODE_LSB;
- res = rmt_saycharstr(myrpt, mychannel, 1000,"LSB");
- break;
-
- case '4':
- myrpt->remmode = REM_MODE_AM;
- res = rmt_saycharstr(myrpt, mychannel, 1000,"AM");
- break;
-
- default:
- return DC_ERROR;
- }
- if(res)
- return DC_ERROR;
-
- if(setrem(myrpt))
- return DC_ERROR;
- return DC_COMPLETE;
-
- case 100: /* other stuff */
- case 101:
- case 102:
- case 103:
- case 104:
- case 105:
- case 106:
- res = rmt_telem_start(myrpt, mychannel, 1000);
- switch(myatoi(param)){ /* Quick commands requiring a setrem call */
- case 100: /* RX PL Off */
- myrpt->rxplon = 0;
- if(!res)
- res = sayfile(mychannel, "rpt/rxpl");
- if(!res)
- sayfile(mychannel, "rpt/off");
- break;
-
- case 101: /* RX PL On */
- myrpt->rxplon = 1;
- if(!res)
- res = sayfile(mychannel, "rpt/rxpl");
- if(!res)
- sayfile(mychannel, "rpt/on");
- break;
-
-
- case 102: /* TX PL Off */
- myrpt->txplon = 0;
- if(!res)
- res = sayfile(mychannel, "rpt/txpl");
- if(!res)
- sayfile(mychannel, "rpt/off");
- break;
-
- case 103: /* TX PL On */
- myrpt->txplon = 1;
- if(!res)
- res = sayfile(mychannel, "rpt/txpl");
- if(!res)
- sayfile(mychannel, "rpt/on");
- break;
-
- case 104: /* Low Power */
- myrpt->powerlevel = REM_LOWPWR;
- if(!res)
- res = sayfile(mychannel, "rpt/lopwr");
- break;
-
- case 105: /* Medium Power */
- myrpt->powerlevel = REM_MEDPWR;
- if(!res)
- res = sayfile(mychannel, "rpt/medpwr");
- break;
-
- case 106: /* Hi Power */
- myrpt->powerlevel = REM_HIPWR;
- if(!res)
- res = sayfile(mychannel, "rpt/hipwr");
- break;
-
- default:
- if(!res)
- rmt_telem_finish(myrpt, mychannel);
- return DC_ERROR;
- }
- if(!res)
- res = rmt_telem_finish(myrpt, mychannel);
- if(res)
- return DC_ERROR;
-
- if (setrem(myrpt) == -1)
- return DC_ERROR;
- return DC_COMPLETE;
-
- case 107: /* Bump down 20Hz */
- multimode_bump_freq(myrpt, -20);
- return DC_COMPLETE;
-
- case 108: /* Bump down 100Hz */
- multimode_bump_freq(myrpt, -100);
- return DC_COMPLETE;
-
- case 109: /* Bump down 500Hz */
- multimode_bump_freq(myrpt, -500);
- return DC_COMPLETE;
-
- case 110: /* Bump up 20Hz */
- multimode_bump_freq(myrpt, 20);
- return DC_COMPLETE;
-
- case 111: /* Bump up 100Hz */
- multimode_bump_freq(myrpt, 100);
- return DC_COMPLETE;
-
- case 112: /* Bump up 500Hz */
- multimode_bump_freq(myrpt, 500);
- return DC_COMPLETE;
-
-
- case 113:
- case 114:
- case 115:
- case 116:
- case 117:
- case 118:
- myrpt->remotetx = 0;
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
- if (!myrpt->remoterx)
- ast_indicate(mychannel,AST_CONTROL_RADIO_KEY);
- if (ast_safe_sleep(mychannel,1000) == -1)
- return DC_ERROR;
-
- switch(myatoi(param)){
-
- case 113: /* Scan down slow */
- res = sayfile(mychannel,"rpt/down");
- if(!res)
- res = sayfile(mychannel, "rpt/slow");
- if(!res){
- myrpt->scantimer = REM_SCANTIME;
- myrpt->hfscanmode = HF_SCAN_DOWN_SLOW;
- }
- break;
-
- case 114: /* Scan down quick */
- res = sayfile(mychannel,"rpt/down");
- if(!res)
- res = sayfile(mychannel, "rpt/quick");
- if(!res){
- myrpt->scantimer = REM_SCANTIME;
- myrpt->hfscanmode = HF_SCAN_DOWN_QUICK;
- }
- break;
-
- case 115: /* Scan down fast */
- res = sayfile(mychannel,"rpt/down");
- if(!res)
- res = sayfile(mychannel, "rpt/fast");
- if(!res){
- myrpt->scantimer = REM_SCANTIME;
- myrpt->hfscanmode = HF_SCAN_DOWN_FAST;
- }
- break;
-
- case 116: /* Scan up slow */
- res = sayfile(mychannel,"rpt/up");
- if(!res)
- res = sayfile(mychannel, "rpt/slow");
- if(!res){
- myrpt->scantimer = REM_SCANTIME;
- myrpt->hfscanmode = HF_SCAN_UP_SLOW;
- }
- break;
-
- case 117: /* Scan up quick */
- res = sayfile(mychannel,"rpt/up");
- if(!res)
- res = sayfile(mychannel, "rpt/quick");
- if(!res){
- myrpt->scantimer = REM_SCANTIME;
- myrpt->hfscanmode = HF_SCAN_UP_QUICK;
- }
- break;
-
- case 118: /* Scan up fast */
- res = sayfile(mychannel,"rpt/up");
- if(!res)
- res = sayfile(mychannel, "rpt/fast");
- if(!res){
- myrpt->scantimer = REM_SCANTIME;
- myrpt->hfscanmode = HF_SCAN_UP_FAST;
- }
- break;
- }
- rmt_telem_finish(myrpt,mychannel);
- return DC_COMPLETE;
-
-
- case 119: /* Tune Request */
- myrpt->tunerequest = 1;
- return DC_COMPLETE;
-
- case 5: /* Long Status */
- case 140: /* Short Status */
- res = rmt_telem_start(myrpt, mychannel, 1000);
-
- res = sayfile(mychannel,"rpt/node");
- if(!res)
- res = saycharstr(mychannel, myrpt->name);
- if(!res)
- res = sayfile(mychannel,"rpt/frequency");
- if(!res)
- res = split_freq(mhz, decimals, myrpt->freq);
- if(!res){
- m = atoi(mhz);
- if(m < 100)
- res = saynum(mychannel, m);
- else
- res = saycharstr(mychannel, mhz);
- }
- if(!res)
- res = sayfile(mychannel, "letters/dot");
- if(!res)
- res = saycharstr(mychannel, decimals);
-
- if(res){
- rmt_telem_finish(myrpt,mychannel);
- return DC_ERROR;
- }
- if(myrpt->remmode == REM_MODE_FM){ /* Mode FM? */
- switch(myrpt->offset){
-
- case REM_MINUS:
- res = sayfile(mychannel,"rpt/minus");
- break;
-
- case REM_SIMPLEX:
- res = sayfile(mychannel,"rpt/simplex");
- break;
-
- case REM_PLUS:
- res = sayfile(mychannel,"rpt/plus");
- break;
-
- default:
- return DC_ERROR;
-
- }
- }
- else{ /* Must be USB, LSB, or AM */
- switch(myrpt->remmode){
-
- case REM_MODE_USB:
- res = saycharstr(mychannel, "USB");
- break;
-
- case REM_MODE_LSB:
- res = saycharstr(mychannel, "LSB");
- break;
-
- case REM_MODE_AM:
- res = saycharstr(mychannel, "AM");
- break;
-
-
- default:
- return DC_ERROR;
- }
- }
-
- if (res == -1){
- rmt_telem_finish(myrpt,mychannel);
- return DC_ERROR;
- }
-
- if(myatoi(param) == 140){ /* Short status? */
- if(!res)
- res = rmt_telem_finish(myrpt, mychannel);
- if(res)
- return DC_ERROR;
- return DC_COMPLETE;
- }
-
- switch(myrpt->powerlevel){
-
- case REM_LOWPWR:
- res = sayfile(mychannel,"rpt/lopwr") ;
- break;
-
- case REM_MEDPWR:
- res = sayfile(mychannel,"rpt/medpwr");
- break;
- case REM_HIPWR:
- res = sayfile(mychannel,"rpt/hipwr");
- break;
- }
- if (res || (sayfile(mychannel,"rpt/rxpl") == -1) ||
- (sayfile(mychannel,"rpt/frequency") == -1) ||
- (saycharstr(mychannel,myrpt->rxpl) == -1) ||
- (sayfile(mychannel,"rpt/txpl") == -1) ||
- (sayfile(mychannel,"rpt/frequency") == -1) ||
- (saycharstr(mychannel,myrpt->txpl) == -1) ||
- (sayfile(mychannel,"rpt/txpl") == -1) ||
- (sayfile(mychannel,((myrpt->txplon) ? "rpt/on" : "rpt/off")) == -1) ||
- (sayfile(mychannel,"rpt/rxpl") == -1) ||
- (sayfile(mychannel,((myrpt->rxplon) ? "rpt/on" : "rpt/off")) == -1))
- {
- rmt_telem_finish(myrpt,mychannel);
- return DC_ERROR;
- }
- if(!res)
- res = rmt_telem_finish(myrpt,mychannel);
- if(res)
- return DC_ERROR;
-
- return DC_COMPLETE;
- default:
- return DC_ERROR;
- }
-
- return DC_INDETERMINATE;
-}
-
-static int handle_remote_dtmf_digit(struct rpt *myrpt,char c, char *keyed, int phonemode)
-{
-time_t now;
-int ret,res = 0,src;
-
- /* Stop scan mode if in scan mode */
- if(myrpt->hfscanmode){
- stop_scan(myrpt,0);
- return 0;
- }
-
- time(&now);
- /* if timed-out */
- if ((myrpt->dtmf_time_rem + DTMF_TIMEOUT) < now)
- {
- myrpt->dtmfidx = -1;
- myrpt->dtmfbuf[0] = 0;
- myrpt->dtmf_time_rem = 0;
- }
- /* if decode not active */
- if (myrpt->dtmfidx == -1)
- {
- /* if not lead-in digit, dont worry */
- if (c != myrpt->funcchar) return 0;
- myrpt->dtmfidx = 0;
- myrpt->dtmfbuf[0] = 0;
- myrpt->dtmf_time_rem = now;
- return 0;
- }
- /* if too many in buffer, start over */
- if (myrpt->dtmfidx >= MAXDTMF)
- {
- myrpt->dtmfidx = 0;
- myrpt->dtmfbuf[0] = 0;
- myrpt->dtmf_time_rem = now;
- }
- if (c == myrpt->funcchar)
- {
- /* if star at beginning, or 2 together, erase buffer */
- if ((myrpt->dtmfidx < 1) ||
- (myrpt->dtmfbuf[myrpt->dtmfidx - 1] == myrpt->funcchar))
- {
- myrpt->dtmfidx = 0;
- myrpt->dtmfbuf[0] = 0;
- myrpt->dtmf_time_rem = now;
- return 0;
- }
- }
- myrpt->dtmfbuf[myrpt->dtmfidx++] = c;
- myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
- myrpt->dtmf_time_rem = now;
-
-
- src = SOURCE_RMT;
- if (phonemode > 1) src = SOURCE_DPHONE;
- else if (phonemode) src = SOURCE_PHONE;
- ret = collect_function_digits(myrpt, myrpt->dtmfbuf, src, NULL);
-
- switch(ret){
-
- case DC_INDETERMINATE:
- res = 0;
- break;
-
- case DC_DOKEY:
- if (keyed) *keyed = 1;
- res = 0;
- break;
-
- case DC_REQ_FLUSH:
- myrpt->dtmfidx = 0;
- myrpt->dtmfbuf[0] = 0;
- res = 0;
- break;
-
-
- case DC_COMPLETE:
- myrpt->dtmfbuf[0] = 0;
- myrpt->dtmfidx = -1;
- myrpt->dtmf_time_rem = 0;
- res = 1;
- break;
-
- case DC_ERROR:
- default:
- myrpt->dtmfbuf[0] = 0;
- myrpt->dtmfidx = -1;
- myrpt->dtmf_time_rem = 0;
- res = 0;
- break;
- }
-
- return res;
-}
-
-static int handle_remote_data(struct rpt *myrpt, char *str)
-{
-char tmp[300],cmd[300],dest[300],src[300],c;
-int seq,res;
-
- /* put string in our buffer */
- strncpy(tmp,str,sizeof(tmp) - 1);
- if (!strcmp(tmp,discstr)) return 0;
- if (sscanf(tmp,"%s %s %s %d %c",cmd,dest,src,&seq,&c) != 5)
- {
- ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
- return 0;
- }
- if (strcmp(cmd,"D"))
- {
- ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
- return 0;
- }
- /* if not for me, ignore */
- if (strcmp(dest,myrpt->name)) return 0;
- res = handle_remote_dtmf_digit(myrpt,c, NULL, 0);
- if (res != 1)
- return res;
- myrpt->remotetx = 0;
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
- if (!myrpt->remoterx)
- {
- ast_indicate(myrpt->remchannel,AST_CONTROL_RADIO_KEY);
- }
- if (ast_safe_sleep(myrpt->remchannel,1000) == -1) return -1;
- res = telem_lookup(myrpt->remchannel, myrpt->name, "functcomplete");
- rmt_telem_finish(myrpt,myrpt->remchannel);
- return res;
-}
-
-static int handle_remote_phone_dtmf(struct rpt *myrpt, char c, char *keyed, int phonemode)
-{
-int res;
-
-
- if (keyed && *keyed && (c == myrpt->endchar))
- {
- *keyed = 0;
- return DC_INDETERMINATE;
- }
-
- res = handle_remote_dtmf_digit(myrpt,c,keyed, phonemode);
- if (res != 1)
- return res;
- myrpt->remotetx = 0;
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
- if (!myrpt->remoterx)
- {
- ast_indicate(myrpt->remchannel,AST_CONTROL_RADIO_KEY);
- }
- if (ast_safe_sleep(myrpt->remchannel,1000) == -1) return -1;
- res = telem_lookup(myrpt->remchannel, myrpt->name, "functcomplete");
- rmt_telem_finish(myrpt,myrpt->remchannel);
- return res;
-}
-
-static int attempt_reconnect(struct rpt *myrpt, struct rpt_link *l)
-{
- char *val, *s, *s1, *s2, *tele;
- char tmp[300], deststr[300] = "";
-
- val = ast_variable_retrieve(cfg, myrpt->nodes, l->name);
- if (!val)
- {
- fprintf(stderr,"attempt_reconnect: cannot find node %s\n",l->name);
- return -1;
- }
-
- ast_mutex_lock(&myrpt->lock);
- /* remove from queue */
- remque((struct qelem *) l);
- ast_mutex_unlock(&myrpt->lock);
- strncpy(tmp,val,sizeof(tmp) - 1);
- s = tmp;
- s1 = strsep(&s,",");
- s2 = strsep(&s,",");
- snprintf(deststr, sizeof(deststr), "IAX2/%s", s1);
- tele = strchr(deststr, '/');
- if (!tele) {
- fprintf(stderr,"attempt_reconnect:Dial number (%s) must be in format tech/number\n",deststr);
- return -1;
- }
- *tele++ = 0;
- l->elaptime = 0;
- l->chan = ast_request(deststr, AST_FORMAT_SLINEAR, tele,NULL);
- if (l->chan){
- ast_set_read_format(l->chan, AST_FORMAT_SLINEAR);
- ast_set_write_format(l->chan, AST_FORMAT_SLINEAR);
- l->chan->whentohangup = 0;
- l->chan->appl = "Apprpt";
- l->chan->data = "(Remote Rx)";
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "rpt (attempt_reconnect) initiating call to %s/%s on %s\n",
- deststr, tele, l->chan->name);
- if(l->chan->cid.cid_num)
- free(l->chan->cid.cid_num);
- l->chan->cid.cid_num = strdup(myrpt->name);
- ast_call(l->chan,tele,999);
-
- }
- else
- {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Unable to place call to %s/%s on %s\n",
- deststr,tele,l->chan->name);
- return -1;
- }
- ast_mutex_lock(&myrpt->lock);
- /* put back in queue queue */
- insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
- ast_mutex_unlock(&myrpt->lock);
- ast_log(LOG_NOTICE,"Reconnect Attempt to %s in process\n",l->name);
- return 0;
-}
-
-/* single thread with one file (request) to dial */
-static void *rpt(void *this)
-{
-struct rpt *myrpt = (struct rpt *)this;
-char *tele,*idtalkover;
-int ms = MSWAIT,lasttx=0,val,remrx=0,identqueued,nonidentqueued,res;
-struct ast_channel *who;
-ZT_CONFINFO ci; /* conference info */
-time_t dtmf_time,t;
-struct rpt_link *l,*m;
-struct rpt_tele *telem;
-pthread_attr_t attr;
-char tmpstr[300];
-char cmd[MAXDTMF+1] = "";
-
-
- ast_mutex_lock(&myrpt->lock);
- strncpy(tmpstr,myrpt->rxchanname,sizeof(tmpstr) - 1);
- tele = strchr(tmpstr,'/');
- if (!tele)
- {
- fprintf(stderr,"rpt:Dial number (%s) must be in format tech/number\n",myrpt->rxchanname);
- ast_mutex_unlock(&myrpt->lock);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- *tele++ = 0;
- myrpt->rxchannel = ast_request(tmpstr,AST_FORMAT_SLINEAR,tele,NULL);
- if (myrpt->rxchannel)
- {
- if (myrpt->rxchannel->_state == AST_STATE_BUSY)
- {
- fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
- ast_set_write_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
- myrpt->rxchannel->whentohangup = 0;
- myrpt->rxchannel->appl = "Apprpt";
- myrpt->rxchannel->data = "(Repeater Rx)";
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "rpt (Rx) initiating call to %s/%s on %s\n",
- tmpstr,tele,myrpt->rxchannel->name);
- ast_call(myrpt->rxchannel,tele,999);
- if (myrpt->rxchannel->_state != AST_STATE_UP)
- {
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- }
- else
- {
- fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
- ast_mutex_unlock(&myrpt->lock);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- if (myrpt->txchanname)
- {
- strncpy(tmpstr,myrpt->txchanname,sizeof(tmpstr) - 1);
- tele = strchr(tmpstr,'/');
- if (!tele)
- {
- fprintf(stderr,"rpt:Dial number (%s) must be in format tech/number\n",myrpt->txchanname);
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- *tele++ = 0;
- myrpt->txchannel = ast_request(tmpstr,AST_FORMAT_SLINEAR,tele,NULL);
- if (myrpt->txchannel)
- {
- if (myrpt->txchannel->_state == AST_STATE_BUSY)
- {
- fprintf(stderr,"rpt:Sorry unable to obtain Tx channel\n");
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->txchannel);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
- ast_set_write_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
- myrpt->txchannel->whentohangup = 0;
- myrpt->txchannel->appl = "Apprpt";
- myrpt->txchannel->data = "(Repeater Tx)";
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "rpt (Tx) initiating call to %s/%s on %s\n",
- tmpstr,tele,myrpt->txchannel->name);
- ast_call(myrpt->txchannel,tele,999);
- if (myrpt->rxchannel->_state != AST_STATE_UP)
- {
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->rxchannel);
- ast_hangup(myrpt->txchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- }
- else
- {
- fprintf(stderr,"rpt:Sorry unable to obtain Tx channel\n");
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- }
- else
- {
- myrpt->txchannel = myrpt->rxchannel;
- }
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
- /* allocate a pseudo-channel thru asterisk */
- myrpt->pchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
- if (!myrpt->pchannel)
- {
- fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
- ast_mutex_unlock(&myrpt->lock);
- if (myrpt->txchannel != myrpt->rxchannel)
- ast_hangup(myrpt->txchannel);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- /* make a conference for the tx */
- ci.chan = 0;
- ci.confno = -1; /* make a new conf */
- ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER;
- /* first put the channel on the conference in proper mode */
- if (ioctl(myrpt->txchannel->fds[0],ZT_SETCONF,&ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->pchannel);
- if (myrpt->txchannel != myrpt->rxchannel)
- ast_hangup(myrpt->txchannel);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- /* save tx conference number */
- myrpt->txconf = ci.confno;
- /* make a conference for the pseudo */
- ci.chan = 0;
- ci.confno = -1; /* make a new conf */
- ci.confmode = ZT_CONF_CONFANNMON;
- /* first put the channel on the conference in announce mode */
- if (ioctl(myrpt->pchannel->fds[0],ZT_SETCONF,&ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->pchannel);
- if (myrpt->txchannel != myrpt->rxchannel)
- ast_hangup(myrpt->txchannel);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- /* save pseudo channel conference number */
- myrpt->conf = ci.confno;
- /* allocate a pseudo-channel thru asterisk */
- myrpt->txpchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
- if (!myrpt->txpchannel)
- {
- fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->pchannel);
- if (myrpt->txchannel != myrpt->rxchannel)
- ast_hangup(myrpt->txchannel);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- /* make a conference for the tx */
- ci.chan = 0;
- ci.confno = myrpt->txconf;
- ci.confmode = ZT_CONF_CONF | ZT_CONF_TALKER ;
- /* first put the channel on the conference in proper mode */
- if (ioctl(myrpt->txpchannel->fds[0],ZT_SETCONF,&ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->txpchannel);
- ast_hangup(myrpt->pchannel);
- if (myrpt->txchannel != myrpt->rxchannel)
- ast_hangup(myrpt->txchannel);
- ast_hangup(myrpt->rxchannel);
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- }
- /* Now, the idea here is to copy from the physical rx channel buffer
- into the pseudo tx buffer, and from the pseudo rx buffer into the
- tx channel buffer */
- myrpt->links.next = &myrpt->links;
- myrpt->links.prev = &myrpt->links;
- myrpt->tailtimer = 0;
- myrpt->totimer = 0;
- myrpt->idtimer = myrpt->politeid;
- myrpt->mustid = 0;
- myrpt->callmode = 0;
- myrpt->tounkeyed = 0;
- myrpt->tonotify = 0;
- myrpt->retxtimer = 0;
- lasttx = 0;
- myrpt->keyed = 0;
- idtalkover = ast_variable_retrieve(cfg, myrpt->name, "idtalkover");
- myrpt->dtmfidx = -1;
- myrpt->dtmfbuf[0] = 0;
- myrpt->rem_dtmfidx = -1;
- myrpt->rem_dtmfbuf[0] = 0;
- dtmf_time = 0;
- myrpt->rem_dtmf_time = 0;
- myrpt->enable = 1;
- myrpt->disgorgetime = 0;
- ast_mutex_unlock(&myrpt->lock);
- val = 0;
- ast_channel_setoption(myrpt->rxchannel,AST_OPTION_TONE_VERIFY,&val,sizeof(char),0);
- val = 1;
- ast_channel_setoption(myrpt->rxchannel,AST_OPTION_RELAXDTMF,&val,sizeof(char),0);
- while (ms >= 0)
- {
- struct ast_frame *f;
- struct ast_channel *cs[300];
- int totx=0,elap=0,n,toexit=0;
-
- /* DEBUG Dump */
- if((myrpt->disgorgetime) && (time(NULL) >= myrpt->disgorgetime)){
- struct rpt_link *zl;
- struct rpt_tele *zt;
-
- myrpt->disgorgetime = 0;
- ast_log(LOG_NOTICE,"********** Variable Dump Start (app_rpt) **********\n");
- ast_log(LOG_NOTICE,"totx = %d\n",totx);
- ast_log(LOG_NOTICE,"remrx = %d\n",remrx);
- ast_log(LOG_NOTICE,"lasttx = %d\n",lasttx);
- ast_log(LOG_NOTICE,"elap = %d\n",elap);
- ast_log(LOG_NOTICE,"toexit = %d\n",toexit);
-
- ast_log(LOG_NOTICE,"myrpt->keyed = %d\n",myrpt->keyed);
- ast_log(LOG_NOTICE,"myrpt->localtx = %d\n",myrpt->localtx);
- ast_log(LOG_NOTICE,"myrpt->callmode = %d\n",myrpt->callmode);
- ast_log(LOG_NOTICE,"myrpt->enable = %d\n",myrpt->enable);
- ast_log(LOG_NOTICE,"myrpt->mustid = %d\n",myrpt->mustid);
- ast_log(LOG_NOTICE,"myrpt->tounkeyed = %d\n",myrpt->tounkeyed);
- ast_log(LOG_NOTICE,"myrpt->tonotify = %d\n",myrpt->tonotify);
- ast_log(LOG_NOTICE,"myrpt->retxtimer = %ld\n",myrpt->retxtimer);
- ast_log(LOG_NOTICE,"myrpt->totimer = %d\n",myrpt->totimer);
- ast_log(LOG_NOTICE,"myrpt->tailtimer = %d\n",myrpt->tailtimer);
-
- zl = myrpt->links.next;
- while(zl != &myrpt->links){
- ast_log(LOG_NOTICE,"*** Link Name: %s ***\n",zl->name);
- ast_log(LOG_NOTICE," link->lasttx %d\n",zl->lasttx);
- ast_log(LOG_NOTICE," link->lastrx %d\n",zl->lastrx);
- ast_log(LOG_NOTICE," link->connected %d\n",zl->connected);
- ast_log(LOG_NOTICE," link->hasconnected %d\n",zl->hasconnected);
- ast_log(LOG_NOTICE," link->outbound %d\n",zl->outbound);
- ast_log(LOG_NOTICE," link->disced %d\n",zl->disced);
- ast_log(LOG_NOTICE," link->killme %d\n",zl->killme);
- ast_log(LOG_NOTICE," link->disctime %ld\n",zl->disctime);
- ast_log(LOG_NOTICE," link->retrytimer %ld\n",zl->retrytimer);
- ast_log(LOG_NOTICE," link->retries = %d\n",zl->retries);
-
- zl = zl->next;
- }
-
- zt = myrpt->tele.next;
- if(zt != &myrpt->tele)
- ast_log(LOG_NOTICE,"*** Telemetry Queue ***\n");
- while(zt != &myrpt->tele){
- ast_log(LOG_NOTICE," Telemetry mode: %d\n",zt->mode);
- zt = zt->next;
- }
- ast_log(LOG_NOTICE,"******* Variable Dump End (app_rpt) *******\n");
-
- }
-
-
-
-
-
- ast_mutex_lock(&myrpt->lock);
- if (ast_check_hangup(myrpt->rxchannel)) break;
- if (ast_check_hangup(myrpt->txchannel)) break;
- if (ast_check_hangup(myrpt->pchannel)) break;
- if (ast_check_hangup(myrpt->txpchannel)) break;
- myrpt->localtx = myrpt->keyed && (myrpt->dtmfidx == -1) && (!myrpt->cmdnode[0]);
-
- /* If someone's connected, and they're transmitting from their end to us, set remrx true */
-
- l = myrpt->links.next;
- remrx = 0;
- while(l != &myrpt->links)
- {
- if (l->lastrx) remrx = 1;
- l = l->next;
- }
-
- /* Create a "must_id" flag for the cleanup ID */
-
- myrpt->mustid |= (myrpt->idtimer) && (myrpt->keyed || remrx) ;
-
- /* Build a fresh totx from myrpt->keyed and autopatch activated */
-
- totx = myrpt->localtx || myrpt->callmode;
-
- /* Traverse the telemetry list to see if there's an ID queued and if there is not an ID queued */
-
- identqueued = 0;
- nonidentqueued = 0;
-
- telem = myrpt->tele.next;
- while(telem != &myrpt->tele)
- {
- if((telem->mode == ID) || (telem->mode == IDTALKOVER)){
- identqueued = 1;
- }
- else
- nonidentqueued = 1;
- telem = telem->next;
- }
-
- /* Add in any non-id telemetry */
-
- totx = totx || nonidentqueued;
-
- /* Update external transmitter PTT state with everything but ID telemetry */
-
- myrpt->exttx = totx;
-
- /* Add in ID telemetry to local transmitter */
-
- totx = totx || remrx || identqueued;
-
- if (!totx)
- {
- myrpt->totimer = myrpt->totime;
- myrpt->tounkeyed = 0;
- myrpt->tonotify = 0;
- }
- else myrpt->tailtimer = myrpt->hangtime;
- totx = totx && myrpt->totimer;
- /* if timed-out and not said already, say it */
- if ((!myrpt->totimer) && (!myrpt->tonotify))
- {
- myrpt->tonotify = 1;
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt,TIMEOUT,NULL);
- ast_mutex_lock(&myrpt->lock);
- }
- /* if wants to transmit and in phone call, but timed out,
- reset time-out timer if keyed */
- if ((!totx) && (!myrpt->totimer) && (!myrpt->tounkeyed) && (!myrpt->keyed))
- {
- myrpt->tounkeyed = 1;
- }
- if ((!totx) && (!myrpt->totimer) && myrpt->tounkeyed && myrpt->keyed)
- {
- myrpt->totimer = myrpt->totime;
- myrpt->tounkeyed = 0;
- myrpt->tonotify = 0;
- ast_mutex_unlock(&myrpt->lock);
- continue;
- }
- /* if timed-out and in circuit busy after call */
- if ((!totx) && (!myrpt->totimer) && (myrpt->callmode == 4))
- {
- myrpt->callmode = 0;
- }
- /* get rid of tail if timed out */
- if (!myrpt->totimer) myrpt->tailtimer = 0;
- /* if not timed-out, add in tail */
- if (myrpt->totimer) totx = totx || myrpt->tailtimer;
- /* If user or links key up or are keyed up over standard ID, switch to talkover ID, if one is defined */
- if (identqueued && (myrpt->keyed || remrx) && idtalkover) {
- int hasid = 0,hastalkover = 0;
-
- telem = myrpt->tele.next;
- while(telem != &myrpt->tele){
- if(telem->mode == ID){
- if (telem->chan) ast_softhangup(telem->chan, AST_SOFTHANGUP_DEV); /* Whoosh! */
- hasid = 1;
- }
- if (telem->mode == IDTALKOVER) hastalkover = 1;
- telem = telem->next;
- }
- ast_mutex_unlock(&myrpt->lock);
- if (hasid && (!hastalkover)) rpt_telemetry(myrpt, IDTALKOVER, NULL); /* Start Talkover ID */
- ast_mutex_lock(&myrpt->lock);
- }
- /* Try to be polite */
- /* If the repeater has been inactive for longer than the ID time, do an initial ID in the tail*/
- /* If within 30 seconds of the time to ID, try do it in the tail */
- /* else if at ID time limit, do it right over the top of them */
- /* Lastly, if the repeater has been keyed, and the ID timer is expired, do a clean up ID */
- if (((totx && (!myrpt->exttx) && (myrpt->idtimer <= myrpt->politeid) && myrpt->tailtimer)) ||
- (myrpt->mustid && (!myrpt->idtimer)))
- {
- myrpt->mustid = 0;
- myrpt->idtimer = myrpt->idtime; /* Reset our ID timer */
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt,ID,NULL);
- ast_mutex_lock(&myrpt->lock);
- }
- /* let telemetry transmit anyway (regardless of timeout) */
- totx = totx || (myrpt->tele.next != &myrpt->tele);
- if (totx && (!lasttx))
- {
- lasttx = 1;
- ast_mutex_unlock(&myrpt->lock);
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
- ast_mutex_lock(&myrpt->lock);
- }
- totx = totx && myrpt->enable;
- if ((!totx) && lasttx)
- {
- lasttx = 0;
- ast_mutex_unlock(&myrpt->lock);
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
- ast_mutex_lock(&myrpt->lock);
- }
- time(&t);
- /* if DTMF timeout */
- if ((!myrpt->cmdnode[0]) && (myrpt->dtmfidx >= 0) && ((dtmf_time + DTMF_TIMEOUT) < t))
- {
- myrpt->dtmfidx = -1;
- myrpt->dtmfbuf[0] = 0;
- }
- /* if remote DTMF timeout */
- if ((myrpt->rem_dtmfidx >= 0) && ((myrpt->rem_dtmf_time + DTMF_TIMEOUT) < t))
- {
- myrpt->rem_dtmfidx = -1;
- myrpt->rem_dtmfbuf[0] = 0;
- }
-
- /* Reconnect kludge */
- l = myrpt->links.next;
- while(l != &myrpt->links)
- {
- if (l->killme)
- {
- /* remove from queue */
- remque((struct qelem *) l);
- if (!strcmp(myrpt->cmdnode,l->name))
- myrpt->cmdnode[0] = 0;
- ast_mutex_unlock(&myrpt->lock);
- /* hang-up on call to device */
- if (l->chan) ast_hangup(l->chan);
- ast_hangup(l->pchan);
- free(l);
- ast_mutex_lock(&myrpt->lock);
- /* re-start link traversal */
- l = myrpt->links.next;
- continue;
- }
- l = l->next;
- }
- n = 0;
- cs[n++] = myrpt->rxchannel;
- cs[n++] = myrpt->pchannel;
- cs[n++] = myrpt->txpchannel;
- if (myrpt->txchannel != myrpt->rxchannel) cs[n++] = myrpt->txchannel;
- l = myrpt->links.next;
- while(l != &myrpt->links)
- {
- if ((!l->killme) && (!l->disctime) && l->chan)
- {
- cs[n++] = l->chan;
- cs[n++] = l->pchan;
- }
- l = l->next;
- }
- ast_mutex_unlock(&myrpt->lock);
- ms = MSWAIT;
- who = ast_waitfor_n(cs,n,&ms);
- if (who == NULL) ms = 0;
- elap = MSWAIT - ms;
- ast_mutex_lock(&myrpt->lock);
- l = myrpt->links.next;
- while(l != &myrpt->links)
- {
- if (!l->lasttx)
- {
- if ((l->retxtimer += elap) >= REDUNDANT_TX_TIME)
- {
- l->retxtimer = 0;
- if (l->chan) ast_indicate(l->chan,AST_CONTROL_RADIO_UNKEY);
- }
- } else l->retxtimer = 0;
-#ifdef RECONNECT_KLUDGE
- if (l->disctime) /* Disconnect timer active on a channel ? */
- {
- l->disctime -= elap;
- if (l->disctime <= 0) /* Disconnect timer expired on inbound channel ? */
- l->disctime = 0; /* Yep */
- }
-
- if (l->retrytimer)
- {
- l->retrytimer -= elap;
- if (l->retrytimer < 0) l->retrytimer = 0;
- }
-#endif
- /* ignore non-timing channels */
- if (l->elaptime < 0)
- {
- l = l->next;
- continue;
- }
- l->elaptime += elap;
- /* if connection has taken too long */
- if ((l->elaptime > MAXCONNECTTIME) &&
- ((!l->chan) || (l->chan->_state != AST_STATE_UP)))
- {
- l->elaptime = 0;
- ast_mutex_unlock(&myrpt->lock);
- if (l->chan) ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
-#ifndef RECONNECT_KLUDGE
- rpt_telemetry(myrpt,CONNFAIL,l);
-#endif
- ast_mutex_lock(&myrpt->lock);
- break;
- }
-#ifdef RECONNECT_KLUDGE
- if ((!l->chan) && (!l->retrytimer) && l->outbound &&
- (l->retries++ < MAX_RETRIES) && (l->hasconnected))
- {
- if (l->chan) ast_hangup(l->chan);
- ast_mutex_unlock(&myrpt->lock);
- if ((l->name[0] != '0') && (!l->isremote))
- {
- l->retrytimer = MAX_RETRIES + 1;
- }
- else
- {
- if (attempt_reconnect(myrpt,l) == -1)
- {
- l->retrytimer = RETRY_TIMER_MS;
- }
- }
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- if ((!l->chan) && (!l->retrytimer) && l->outbound &&
- (l->retries >= MAX_RETRIES))
- {
- /* remove from queue */
- remque((struct qelem *) l);
- if (!strcmp(myrpt->cmdnode,l->name))
- myrpt->cmdnode[0] = 0;
- ast_mutex_unlock(&myrpt->lock);
- if (l->name[0] != '0')
- {
- if (!l->hasconnected)
- rpt_telemetry(myrpt,CONNFAIL,l);
- else rpt_telemetry(myrpt,REMDISC,l);
- }
- /* hang-up on call to device */
- ast_hangup(l->pchan);
- free(l);
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- if ((!l->chan) && (!l->disctime) && (!l->outbound))
- {
- /* remove from queue */
- remque((struct qelem *) l);
- if (!strcmp(myrpt->cmdnode,l->name))
- myrpt->cmdnode[0] = 0;
- ast_mutex_unlock(&myrpt->lock);
- if (l->name[0] != '0')
- {
- rpt_telemetry(myrpt,REMDISC,l);
- }
- /* hang-up on call to device */
- ast_hangup(l->pchan);
- free(l);
- ast_mutex_lock(&myrpt->lock);
- break;
- }
-#endif
- l = l->next;
- }
- if (myrpt->tailtimer) myrpt->tailtimer -= elap;
- if (myrpt->tailtimer < 0) myrpt->tailtimer = 0;
- if (myrpt->totimer) myrpt->totimer -= elap;
- if (myrpt->totimer < 0) myrpt->totimer = 0;
- if (myrpt->idtimer) myrpt->idtimer -= elap;
- if (myrpt->idtimer < 0) myrpt->idtimer = 0;
- ast_mutex_unlock(&myrpt->lock);
- if (!ms) continue;
- if (who == myrpt->rxchannel) /* if it was a read from rx */
- {
- f = ast_read(myrpt->rxchannel);
- if (!f)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- break;
- }
- if (f->frametype == AST_FRAME_VOICE)
- {
- if (!myrpt->localtx)
- memset(f->data,0,f->datalen);
- ast_write(myrpt->pchannel,f);
- }
- else if (f->frametype == AST_FRAME_DTMF)
- {
- char c;
-
- c = (char) f->subclass; /* get DTMF char */
- ast_frfree(f);
- if (!myrpt->keyed) continue;
- if (c == myrpt->endchar)
- {
- /* if in simple mode, kill autopatch */
- if (myrpt->simple && myrpt->callmode)
- {
- ast_mutex_lock(&myrpt->lock);
- myrpt->callmode = 0;
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt,TERM,NULL);
- continue;
- }
- ast_mutex_lock(&myrpt->lock);
- myrpt->stopgen = 1;
- if (myrpt->cmdnode[0])
- {
- myrpt->cmdnode[0] = 0;
- myrpt->dtmfidx = -1;
- myrpt->dtmfbuf[0] = 0;
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt,COMPLETE,NULL);
- } else ast_mutex_unlock(&myrpt->lock);
- continue;
- }
- ast_mutex_lock(&myrpt->lock);
- if (myrpt->cmdnode[0])
- {
- ast_mutex_unlock(&myrpt->lock);
- send_link_dtmf(myrpt,c);
- continue;
- }
- if (!myrpt->simple)
- {
- if (c == myrpt->funcchar)
- {
- myrpt->dtmfidx = 0;
- myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
- ast_mutex_unlock(&myrpt->lock);
- time(&dtmf_time);
- continue;
- }
- else if ((c != myrpt->endchar) && (myrpt->dtmfidx >= 0))
- {
- time(&dtmf_time);
-
- if (myrpt->dtmfidx < MAXDTMF)
- {
- myrpt->dtmfbuf[myrpt->dtmfidx++] = c;
- myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
-
- strncpy(cmd, myrpt->dtmfbuf, sizeof(cmd) - 1);
-
- ast_mutex_unlock(&myrpt->lock);
- res = collect_function_digits(myrpt, cmd, SOURCE_RPT, NULL);
- ast_mutex_lock(&myrpt->lock);
-
- switch(res){
-
- case DC_INDETERMINATE:
- break;
-
- case DC_REQ_FLUSH:
- myrpt->dtmfidx = 0;
- myrpt->dtmfbuf[0] = 0;
- break;
-
-
- case DC_COMPLETE:
- myrpt->dtmfbuf[0] = 0;
- myrpt->dtmfidx = -1;
- dtmf_time = 0;
- break;
-
- case DC_ERROR:
- default:
- myrpt->dtmfbuf[0] = 0;
- myrpt->dtmfidx = -1;
- dtmf_time = 0;
- break;
- }
- if(res != DC_INDETERMINATE) {
- ast_mutex_unlock(&myrpt->lock);
- continue;
- }
- }
- }
- }
- else /* if simple */
- {
- if ((!myrpt->callmode) && (c == myrpt->funcchar))
- {
- myrpt->callmode = 1;
- myrpt->cidx = 0;
- myrpt->exten[myrpt->cidx] = 0;
- ast_mutex_unlock(&myrpt->lock);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *)myrpt);
- continue;
- }
- }
- if (myrpt->callmode == 1)
- {
- myrpt->exten[myrpt->cidx++] = c;
- myrpt->exten[myrpt->cidx] = 0;
- /* if this exists */
- if (ast_exists_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
- {
- myrpt->callmode = 2;
- ast_mutex_unlock(&myrpt->lock);
- rpt_telemetry(myrpt,PROC,NULL);
- continue;
- }
- /* if can continue, do so */
- if (!ast_canmatch_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
- {
- /* call has failed, inform user */
- myrpt->callmode = 4;
- }
- ast_mutex_unlock(&myrpt->lock);
- continue;
- }
- if ((myrpt->callmode == 2) || (myrpt->callmode == 3))
- {
- myrpt->mydtmf = c;
- }
- ast_mutex_unlock(&myrpt->lock);
- continue;
- }
- else if (f->frametype == AST_FRAME_CONTROL)
- {
- if (f->subclass == AST_CONTROL_HANGUP)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- break;
- }
- /* if RX key */
- if (f->subclass == AST_CONTROL_RADIO_KEY)
- {
- if (debug) printf("@@@@ rx key\n");
- myrpt->keyed = 1;
- }
- /* if RX un-key */
- if (f->subclass == AST_CONTROL_RADIO_UNKEY)
- {
- if (debug) printf("@@@@ rx un-key\n");
- if(myrpt->keyed) {
- rpt_telemetry(myrpt,UNKEY,NULL);
- }
- myrpt->keyed = 0;
- }
- }
- ast_frfree(f);
- continue;
- }
- if (who == myrpt->pchannel) /* if it was a read from pseudo */
- {
- f = ast_read(myrpt->pchannel);
- if (!f)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- break;
- }
- if (f->frametype == AST_FRAME_VOICE)
- {
- ast_write(myrpt->txpchannel,f);
- }
- if (f->frametype == AST_FRAME_CONTROL)
- {
- if (f->subclass == AST_CONTROL_HANGUP)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- break;
- }
- }
- ast_frfree(f);
- continue;
- }
- if (who == myrpt->txchannel) /* if it was a read from tx */
- {
- f = ast_read(myrpt->txchannel);
- if (!f)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- break;
- }
- if (f->frametype == AST_FRAME_CONTROL)
- {
- if (f->subclass == AST_CONTROL_HANGUP)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- break;
- }
- }
- ast_frfree(f);
- continue;
- }
- toexit = 0;
- ast_mutex_lock(&myrpt->lock);
- l = myrpt->links.next;
- while(l != &myrpt->links)
- {
- if (l->disctime)
- {
- l = l->next;
- continue;
- }
- if (who == l->chan) /* if it was a read from rx */
- {
- remrx = 0;
- /* see if any other links are receiving */
- m = myrpt->links.next;
- while(m != &myrpt->links)
- {
- /* if not us, count it */
- if ((m != l) && (m->lastrx)) remrx = 1;
- m = m->next;
- }
- ast_mutex_unlock(&myrpt->lock);
- totx = (((l->isremote) ? myrpt->localtx :
- myrpt->exttx) || remrx) && l->mode;
- if (l->chan && (l->lasttx != totx))
- {
- if (totx)
- {
- ast_indicate(l->chan,AST_CONTROL_RADIO_KEY);
- }
- else
- {
- ast_indicate(l->chan,AST_CONTROL_RADIO_UNKEY);
- }
- }
- l->lasttx = totx;
- f = ast_read(l->chan);
- if (!f)
- {
-#ifdef RECONNECT_KLUDGE
- if ((!l->disced) && (!l->outbound))
- {
- if ((l->name[0] == '0') || l->isremote)
- l->disctime = 1;
- else
- l->disctime = DISC_TIME;
- ast_mutex_lock(&myrpt->lock);
- ast_hangup(l->chan);
- l->chan = 0;
- break;
- }
-
- if (l->retrytimer)
- {
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- if (l->outbound && (l->retries++ < MAX_RETRIES) && (l->hasconnected))
- {
- ast_mutex_lock(&myrpt->lock);
- ast_hangup(l->chan);
- l->chan = 0;
- ast_mutex_unlock(&myrpt->lock);
- if (attempt_reconnect(myrpt,l) == -1)
- {
- l->retrytimer = RETRY_TIMER_MS;
- }
- ast_mutex_lock(&myrpt->lock);
- break;
- }
-#endif
- ast_mutex_lock(&myrpt->lock);
- /* remove from queue */
- remque((struct qelem *) l);
- if (!strcmp(myrpt->cmdnode,l->name))
- myrpt->cmdnode[0] = 0;
- ast_mutex_unlock(&myrpt->lock);
- if (!l->hasconnected)
- rpt_telemetry(myrpt,CONNFAIL,l);
- else if (l->disced != 2) rpt_telemetry(myrpt,REMDISC,l);
- /* hang-up on call to device */
- ast_hangup(l->chan);
- ast_hangup(l->pchan);
- free(l);
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- if (f->frametype == AST_FRAME_VOICE)
- {
- if (l->phonemode && (!l->lastrx))
- {
- memset(f->data,0,f->datalen);
- }
- ast_write(l->pchan,f);
- }
- if (f->frametype == AST_FRAME_TEXT)
- {
- handle_link_data(myrpt,l,f->data);
- }
- if (f->frametype == AST_FRAME_DTMF)
- {
- handle_link_phone_dtmf(myrpt,l,f->subclass);
- }
- if (f->frametype == AST_FRAME_CONTROL)
- {
- if (f->subclass == AST_CONTROL_ANSWER)
- {
- char lconnected = l->connected;
- l->connected = 1;
- l->hasconnected = 1;
- l->elaptime = -1;
- l->retries = 0;
- if (!lconnected) rpt_telemetry(myrpt,CONNECTED,l);
- }
- /* if RX key */
- if (f->subclass == AST_CONTROL_RADIO_KEY)
- {
- if (debug) printf("@@@@ rx key\n");
- l->lastrx = 1;
- }
- /* if RX un-key */
- if (f->subclass == AST_CONTROL_RADIO_UNKEY)
- {
- if (debug) printf("@@@@ rx un-key\n");
- l->lastrx = 0;
- }
- if (f->subclass == AST_CONTROL_HANGUP)
- {
- ast_frfree(f);
-#ifdef RECONNECT_KLUDGE
- if ((!l->outbound) && (!l->disced))
- {
- if ((l->name[0] == '0') || l->isremote)
- l->disctime = 1;
- else
- l->disctime = DISC_TIME;
- ast_mutex_lock(&myrpt->lock);
- ast_hangup(l->chan);
- l->chan = 0;
- break;
- }
- if (l->retrytimer)
- {
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- if (l->outbound && (l->retries++ < MAX_RETRIES) && (l->hasconnected))
- {
- ast_mutex_lock(&myrpt->lock);
- ast_hangup(l->chan);
- l->chan = 0;
- ast_mutex_unlock(&myrpt->lock);
- if (attempt_reconnect(myrpt,l) == -1)
- {
- l->retrytimer = RETRY_TIMER_MS;
- }
- ast_mutex_lock(&myrpt->lock);
- break;
- }
-#endif
- ast_mutex_lock(&myrpt->lock);
- /* remove from queue */
- remque((struct qelem *) l);
- if (!strcmp(myrpt->cmdnode,l->name))
- myrpt->cmdnode[0] = 0;
- ast_mutex_unlock(&myrpt->lock);
- if (!l->hasconnected)
- rpt_telemetry(myrpt,CONNFAIL,l);
- else if (l->disced != 2) rpt_telemetry(myrpt,REMDISC,l);
- /* hang-up on call to device */
- ast_hangup(l->chan);
- ast_hangup(l->pchan);
- free(l);
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- }
- ast_frfree(f);
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- if (who == l->pchan)
- {
- ast_mutex_unlock(&myrpt->lock);
- f = ast_read(l->pchan);
- if (!f)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- toexit = 1;
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- if (f->frametype == AST_FRAME_VOICE)
- {
- if (l->chan) ast_write(l->chan,f);
- }
- if (f->frametype == AST_FRAME_CONTROL)
- {
- if (f->subclass == AST_CONTROL_HANGUP)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- toexit = 1;
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- }
- ast_frfree(f);
- ast_mutex_lock(&myrpt->lock);
- break;
- }
- l = l->next;
- }
- ast_mutex_unlock(&myrpt->lock);
- if (toexit) break;
- if (who == myrpt->txpchannel) /* if it was a read from remote tx */
- {
- f = ast_read(myrpt->txpchannel);
- if (!f)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- break;
- }
- if (f->frametype == AST_FRAME_CONTROL)
- {
- if (f->subclass == AST_CONTROL_HANGUP)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- break;
- }
- }
- ast_frfree(f);
- continue;
- }
- }
- usleep(100000);
- ast_hangup(myrpt->pchannel);
- ast_hangup(myrpt->txpchannel);
- if (myrpt->txchannel != myrpt->rxchannel) ast_hangup(myrpt->txchannel);
- ast_hangup(myrpt->rxchannel);
- ast_mutex_lock(&myrpt->lock);
- l = myrpt->links.next;
- while(l != &myrpt->links)
- {
- struct rpt_link *ll = l;
- /* remove from queue */
- remque((struct qelem *) l);
- /* hang-up on call to device */
- if (l->chan) ast_hangup(l->chan);
- ast_hangup(l->pchan);
- l = l->next;
- free(ll);
- }
- ast_mutex_unlock(&myrpt->lock);
- if (debug) printf("@@@@ rpt:Hung up channel\n");
- myrpt->rpt_thread = AST_PTHREADT_STOP;
- pthread_exit(NULL);
- return NULL;
-}
-
-
-static void *rpt_master(void *ignore)
-{
-char *this,*val;
-struct ast_variable *vp;
-int i,j,n,longestnode;
-pthread_attr_t attr;
-
- /* start with blank config */
- memset(&rpt_vars,0,sizeof(rpt_vars));
-
- cfg = ast_config_load("rpt.conf");
- if (!cfg) {
- ast_log(LOG_NOTICE, "Unable to open radio repeater configuration rpt.conf. Radio Repeater disabled.\n");
- pthread_exit(NULL);
- }
-
- /* go thru all the specified repeaters */
- this = NULL;
- n = 0;
- while((this = ast_category_browse(cfg,this)) != NULL)
- {
-
- for(i = 0 ; i < strlen(this) ; i++){
- if((this[i] < '0') || (this[i] > '9'))
- break;
- }
- if(i != strlen(this))
- continue; /* Not a node defn */
-
- ast_log(LOG_DEBUG,"Loading config for repeater %s\n",this);
- ast_mutex_init(&rpt_vars[n].lock);
- rpt_vars[n].tele.next = &rpt_vars[n].tele;
- rpt_vars[n].tele.prev = &rpt_vars[n].tele;
- rpt_vars[n].rpt_thread = AST_PTHREADT_NULL;
- rpt_vars[n].name = this;
- rpt_vars[n].rxchanname = ast_variable_retrieve(cfg,this,"rxchannel");
- rpt_vars[n].txchanname = ast_variable_retrieve(cfg,this,"txchannel");
- rpt_vars[n].ourcontext = ast_variable_retrieve(cfg,this,"context");
- if (!rpt_vars[n].ourcontext) rpt_vars[n].ourcontext = this;
- rpt_vars[n].ourcallerid = ast_variable_retrieve(cfg,this,"callerid");
- rpt_vars[n].acctcode = ast_variable_retrieve(cfg,this,"accountcode");
- rpt_vars[n].ident = ast_variable_retrieve(cfg,this,"idrecording");
- val = ast_variable_retrieve(cfg,this,"hangtime");
- if (val) rpt_vars[n].hangtime = atoi(val);
- else rpt_vars[n].hangtime = HANGTIME;
- val = ast_variable_retrieve(cfg,this,"totime");
- if (val) rpt_vars[n].totime = atoi(val);
- else rpt_vars[n].totime = TOTIME;
-
- rpt_vars[n].idtime = retrieve_astcfgint( this, "idtime", 60000, 2400000, IDTIME); /* Enforce a min max */
- rpt_vars[n].politeid = retrieve_astcfgint( this, "politeid", 30000, 300000, POLITEID); /* Enforce a min max */
- rpt_vars[n].remote = ast_variable_retrieve(cfg,this,"remote");
- rpt_vars[n].tonezone = ast_variable_retrieve(cfg,this,"tonezone");
- val = ast_variable_retrieve(cfg,this,"iobase");
- /* do not use atoi() here, we need to be able to have
- the input specified in hex or decimal so we use
- sscanf with a %i */
- if ((!val) || (sscanf(val,"%i",&rpt_vars[n].iobase) != 1))
- rpt_vars[n].iobase = DEFAULT_IOBASE;
- rpt_vars[n].simple = 0;
- rpt_vars[n].functions = ast_variable_retrieve(cfg,this,"functions");
- if (!rpt_vars[n].functions)
- {
- rpt_vars[n].functions = FUNCTIONS;
- rpt_vars[n].simple = 1;
- }
- rpt_vars[n].link_functions = ast_variable_retrieve(cfg,this,"link_functions");
- if (!rpt_vars[n].link_functions)
- rpt_vars[n].link_functions = rpt_vars[n].functions;
- rpt_vars[n].phone_functions = ast_variable_retrieve(cfg,this,"phone_functions");
- rpt_vars[n].dphone_functions = ast_variable_retrieve(cfg,this,"dphone_functions");
- val = ast_variable_retrieve(cfg,this,"funcchar");
- if (!val) rpt_vars[n].funcchar = FUNCCHAR; else
- rpt_vars[n].funcchar = *val;
- val = ast_variable_retrieve(cfg,this,"endchar");
- if (!val) rpt_vars[n].endchar = ENDCHAR; else
- rpt_vars[n].endchar = *val;
- val = ast_variable_retrieve(cfg,this,"nobusyout");
- if (val) rpt_vars[n].nobusyout = ast_true(val);
- rpt_vars[n].nodes = ast_variable_retrieve(cfg,this,"nodes");
- if (!rpt_vars[n].nodes)
- rpt_vars[n].nodes = NODES;
- n++;
- }
- nrpts = n;
- ast_log(LOG_DEBUG, "Total of %d repeaters configured.\n",n);
- /* start em all */
- for(i = 0; i < n; i++)
- {
-
- /*
- * Go through the node list to determine the longest node
- */
- longestnode = 0;
-
- vp = ast_variable_browse(cfg, rpt_vars[i].nodes);
-
- while(vp){
- j = strlen(vp->name);
- if (j > longestnode)
- longestnode = j;
- vp = vp->next;
- }
-
-
- rpt_vars[i].longestnode = longestnode;
-
- /*
- * For this repeater, Determine the length of the longest function
- */
- rpt_vars[i].longestfunc = 0;
- vp = ast_variable_browse(cfg, rpt_vars[i].functions);
- while(vp){
- j = strlen(vp->name);
- if (j > rpt_vars[i].longestfunc)
- rpt_vars[i].longestfunc = j;
- vp = vp->next;
- }
- /*
- * For this repeater, Determine the length of the longest function
- */
- rpt_vars[i].link_longestfunc = 0;
- vp = ast_variable_browse(cfg, rpt_vars[i].link_functions);
- while(vp){
- j = strlen(vp->name);
- if (j > rpt_vars[i].link_longestfunc)
- rpt_vars[i].link_longestfunc = j;
- vp = vp->next;
- }
- rpt_vars[i].phone_longestfunc = 0;
- if (rpt_vars[i].phone_functions)
- {
- vp = ast_variable_browse(cfg, rpt_vars[i].phone_functions);
- while(vp){
- j = strlen(vp->name);
- if (j > rpt_vars[i].phone_longestfunc)
- rpt_vars[i].phone_longestfunc = j;
- vp = vp->next;
- }
- }
- rpt_vars[i].dphone_longestfunc = 0;
- if (rpt_vars[i].dphone_functions)
- {
- vp = ast_variable_browse(cfg, rpt_vars[i].dphone_functions);
- while(vp){
- j = strlen(vp->name);
- if (j > rpt_vars[i].dphone_longestfunc)
- rpt_vars[i].dphone_longestfunc = j;
- vp = vp->next;
- }
- }
- if (!rpt_vars[i].rxchanname)
- {
- ast_log(LOG_WARNING,"Did not specify rxchanname for node %s\n",rpt_vars[i].name);
- ast_config_destroy(cfg);
- pthread_exit(NULL);
- }
- /* if is a remote, dont start one for it */
- if (rpt_vars[i].remote)
- {
- strncpy(rpt_vars[i].freq, "146.580", sizeof(rpt_vars[i].freq) - 1);
- strncpy(rpt_vars[i].rxpl, "100.0", sizeof(rpt_vars[i].rxpl) - 1);
-
- strncpy(rpt_vars[i].txpl, "100.0", sizeof(rpt_vars[i].txpl) - 1);
- rpt_vars[i].remmode = REM_MODE_FM;
- rpt_vars[i].offset = REM_SIMPLEX;
- rpt_vars[i].powerlevel = REM_MEDPWR;
- continue;
- }
- if (!rpt_vars[i].ident)
- {
- ast_log(LOG_WARNING,"Did not specify ident for node %s\n",rpt_vars[i].name);
- ast_config_destroy(cfg);
- pthread_exit(NULL);
- }
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&rpt_vars[i].rpt_thread,&attr,rpt,(void *) &rpt_vars[i]);
- }
- usleep(500000);
- for(;;)
- {
- /* Now monitor each thread, and restart it if necessary */
- for(i = 0; i < n; i++)
- {
- int rv;
- if (rpt_vars[i].remote) continue;
- if (rpt_vars[i].rpt_thread == AST_PTHREADT_STOP)
- rv = -1;
- else
- rv = pthread_kill(rpt_vars[i].rpt_thread,0);
- if (rv)
- {
- if(time(NULL) - rpt_vars[i].lastthreadrestarttime <= 15)
- {
- if(rpt_vars[i].threadrestarts >= 5)
- {
- ast_log(LOG_ERROR,"Continual RPT thread restarts, killing Asterisk\n");
- exit(1); /* Stuck in a restart loop, kill Asterisk and start over */
- }
- else
- {
- ast_log(LOG_NOTICE,"RPT thread restarted on %s\n",rpt_vars[i].name);
- rpt_vars[i].threadrestarts++;
- }
- }
- else
- rpt_vars[i].threadrestarts = 0;
-
- rpt_vars[i].lastthreadrestarttime = time(NULL);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&rpt_vars[i].rpt_thread,&attr,rpt,(void *) &rpt_vars[i]);
- ast_log(LOG_WARNING, "rpt_thread restarted on node %s\n", rpt_vars[i].name);
- }
-
- }
- usleep(2000000);
- }
- ast_config_destroy(cfg);
- pthread_exit(NULL);
-}
-
-static int rpt_exec(struct ast_channel *chan, void *data)
-{
- int res=-1,i,rem_totx,n,phone_mode = 0;
- struct localuser *u;
- char tmp[256], keyed = 0;
- char *options,*stringp,*tele;
- struct rpt *myrpt;
- struct ast_frame *f;
- struct ast_channel *who;
- struct ast_channel *cs[20];
- struct rpt_link *l;
- ZT_CONFINFO ci; /* conference info */
- ZT_PARAMS par;
- int ms,elap;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Rpt requires an argument (system node)\n");
- return -1;
- }
- strncpy(tmp, (char *)data, sizeof(tmp)-1);
- stringp=tmp;
- strsep(&stringp, "|");
- options = stringp;
- myrpt = NULL;
- /* see if we can find our specified one */
- for(i = 0; i < nrpts; i++)
- {
- /* if name matches, assign it and exit loop */
- if (!strcmp(tmp,rpt_vars[i].name))
- {
- myrpt = &rpt_vars[i];
- break;
- }
- }
- if (myrpt == NULL)
- {
- ast_log(LOG_WARNING, "Cannot find specified system node %s\n",tmp);
- return -1;
- }
-
- /* if not phone access, must be an IAX connection */
- if (options && ((*options == 'P') || (*options == 'D') || (*options == 'R')))
- {
- phone_mode = 1;
- if (*options == 'D') phone_mode = 2;
- ast_set_callerid(chan,"0","app_rpt user","0");
- }
- else
- {
- if (strncmp(chan->name,"IAX2",4))
- {
- ast_log(LOG_WARNING, "We only accept links via IAX2!!\n");
- return -1;
- }
- }
- if (options && (*options == 'R'))
- {
-
- /* Parts of this section taken from app_parkandannounce */
- char *return_context;
- int l, m, lot, timeout = 0;
- char tmp[256],*template;
- char *working, *context, *exten, *priority;
- char *s,*orig_s;
-
-
- ast_mutex_lock(&myrpt->lock);
- m = myrpt->callmode;
- ast_mutex_unlock(&myrpt->lock);
-
- if ((!myrpt->nobusyout) && m)
- {
- if (chan->_state != AST_STATE_UP)
- {
- ast_indicate(chan,AST_CONTROL_BUSY);
- }
- while(ast_safe_sleep(chan,10000) != -1);
- return -1;
- }
-
- if (chan->_state != AST_STATE_UP)
- {
- ast_answer(chan);
- }
-
- l=strlen(options)+2;
- orig_s=malloc(l);
- if(!orig_s) {
- ast_log(LOG_WARNING, "Out of memory\n");
- return -1;
- }
- s=orig_s;
- strncpy(s,options,l);
-
- template=strsep(&s,"|");
- if(!template) {
- ast_log(LOG_WARNING, "An announce template must be defined\n");
- free(orig_s);
- return -1;
- }
-
- if(s) {
- timeout = atoi(strsep(&s, "|"));
- timeout *= 1000;
- }
-
- return_context = s;
-
- if(return_context != NULL) {
- /* set the return context. Code borrowed from the Goto builtin */
-
- working = return_context;
- context = strsep(&working, "|");
- exten = strsep(&working, "|");
- if(!exten) {
- /* Only a priority in this one */
- priority = context;
- exten = NULL;
- context = NULL;
- } else {
- priority = strsep(&working, "|");
- if(!priority) {
- /* Only an extension and priority in this one */
- priority = exten;
- exten = context;
- context = NULL;
- }
- }
- if(atoi(priority) < 0) {
- ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", priority);
- free(orig_s);
- return -1;
- }
- /* At this point we have a priority and maybe an extension and a context */
- chan->priority = atoi(priority);
- if(exten && strcasecmp(exten, "BYEXTENSION"))
- strncpy(chan->exten, exten, sizeof(chan->exten)-1);
- if(context)
- strncpy(chan->context, context, sizeof(chan->context)-1);
- } else { /* increment the priority by default*/
- chan->priority++;
- }
-
- if(option_verbose > 2) {
- ast_verbose( VERBOSE_PREFIX_3 "Return Context: (%s,%s,%d) ID: %s\n", chan->context,chan->exten, chan->priority, chan->cid.cid_num);
- if(!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
- ast_verbose( VERBOSE_PREFIX_3 "Warning: Return Context Invalid, call will return to default|s\n");
- }
- }
-
- /* we are using masq_park here to protect * from touching the channel once we park it. If the channel comes out of timeout
- before we are done announcing and the channel is messed with, Kablooeee. So we use Masq to prevent this. */
-
- ast_masq_park_call(chan, NULL, timeout, &lot);
-
- if (option_verbose > 2) ast_verbose( VERBOSE_PREFIX_3 "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, return_context);
-
- snprintf(tmp,sizeof(tmp) - 1,"%d,%s",lot,template + 1);
-
- rpt_telemetry(myrpt,REV_PATCH,tmp);
-
- free(orig_s);
-
- return 0;
-
- }
-
- if (!options)
- {
- struct ast_hostent ahp;
- struct hostent *hp;
- struct in_addr ia;
- char hisip[100],nodeip[100],*val, *s, *s1, *s2, *b,*b1;
-
- /* look at callerid to see what node this comes from */
- if (!chan->cid.cid_num) /* if doesn't have caller id */
- {
- ast_log(LOG_WARNING, "Doesnt have callerid on %s\n",tmp);
- return -1;
- }
-
- /* get his IP from IAX2 module */
- memset(hisip,0,sizeof(hisip));
- pbx_substitute_variables_helper(chan,"${IAXPEER(CURRENTCHANNEL)}",hisip,sizeof(hisip) - 1);
- if (!hisip[0])
- {
- ast_log(LOG_WARNING, "Link IP address cannot be determined!!\n");
- return -1;
- }
-
- ast_callerid_parse(chan->cid.cid_num,&b,&b1);
- ast_shrink_phone_number(b1);
- if (!strcmp(myrpt->name,b1))
- {
- ast_log(LOG_WARNING, "Trying to link to self!!\n");
- return -1;
- }
-
- if (*b1 < '1')
- {
- ast_log(LOG_WARNING, "Node %s Invalid for connection here!!\n",b1);
- return -1;
- }
-
-
- /* look for his reported node string */
- val = ast_variable_retrieve(cfg, myrpt->nodes, b1);
- if (!val)
- {
- ast_log(LOG_WARNING, "Reported node %s cannot be found!!\n",b1);
- return -1;
- }
- strncpy(tmp,val,sizeof(tmp) - 1);
- s = tmp;
- s1 = strsep(&s,",");
- s2 = strsep(&s,",");
- if (!s2)
- {
- ast_log(LOG_WARNING, "Reported node %s not in correct format!!\n",b1);
- return -1;
- }
- if (strcmp(s2,"NONE")) {
- hp = ast_gethostbyname(s2, &ahp);
- if (!hp)
- {
- ast_log(LOG_WARNING, "Reported node %s, name %s cannot be found!!\n",b1,s2);
- return -1;
- }
- memcpy(&ia,hp->h_addr,sizeof(in_addr_t));
- ast_inet_ntoa(nodeip,sizeof(nodeip) - 1,ia);
- if (strcmp(hisip,nodeip))
- {
- char *s3 = strchr(s1,'@');
- if (s3) s1 = s3 + 1;
- s3 = strchr(s1,'/');
- if (s3) *s3 = 0;
- hp = ast_gethostbyname(s1, &ahp);
- if (!hp)
- {
- ast_log(LOG_WARNING, "Reported node %s, name %s cannot be found!!\n",b1,s1);
- return -1;
- }
- memcpy(&ia,hp->h_addr,sizeof(in_addr_t));
- ast_inet_ntoa(nodeip,sizeof(nodeip) - 1,ia);
- if (strcmp(hisip,nodeip))
- {
- ast_log(LOG_WARNING, "Node %s IP %s does not match link IP %s!!\n",b1,nodeip,hisip);
- return -1;
- }
- }
- }
- }
-
- /* if is not a remote */
- if (!myrpt->remote)
- {
-
- char *b,*b1;
-
- /* look at callerid to see what node this comes from */
- if (!chan->cid.cid_num) /* if doesn't have caller id */
- {
- ast_log(LOG_WARNING, "Doesnt have callerid on %s\n",tmp);
- return -1;
- }
-
- ast_callerid_parse(chan->cid.cid_num,&b,&b1);
- ast_shrink_phone_number(b1);
- if (!strcmp(myrpt->name,b1))
- {
- ast_log(LOG_WARNING, "Trying to link to self!!\n");
- return -1;
- }
- ast_mutex_lock(&myrpt->lock);
- l = myrpt->links.next;
- /* try to find this one in queue */
- while(l != &myrpt->links)
- {
- if (l->name[0] == '0')
- {
- l = l->next;
- continue;
- }
- /* if found matching string */
- if (!strcmp(l->name,b1)) break;
- l = l->next;
- }
- /* if found */
- if (l != &myrpt->links)
- {
- l->killme = 1;
- l->retries = MAX_RETRIES + 1;
- l->disced = 2;
- ast_mutex_unlock(&myrpt->lock);
- usleep(500000);
- } else
- ast_mutex_unlock(&myrpt->lock);
- /* establish call in tranceive mode */
- l = malloc(sizeof(struct rpt_link));
- if (!l)
- {
- ast_log(LOG_WARNING, "Unable to malloc\n");
- pthread_exit(NULL);
- }
- /* zero the silly thing */
- memset((char *)l,0,sizeof(struct rpt_link));
- l->mode = 1;
- strncpy(l->name,b1,MAXNODESTR - 1);
- l->isremote = 0;
- l->chan = chan;
- l->connected = 1;
- l->hasconnected = 1;
- l->phonemode = phone_mode;
- ast_set_read_format(l->chan,AST_FORMAT_SLINEAR);
- ast_set_write_format(l->chan,AST_FORMAT_SLINEAR);
- /* allocate a pseudo-channel thru asterisk */
- l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
- if (!l->pchan)
- {
- fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
- pthread_exit(NULL);
- }
- ast_set_read_format(l->pchan,AST_FORMAT_SLINEAR);
- ast_set_write_format(l->pchan,AST_FORMAT_SLINEAR);
- /* make a conference for the tx */
- ci.chan = 0;
- ci.confno = myrpt->conf;
- ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER | ZT_CONF_TALKER;
- /* first put the channel on the conference in proper mode */
- if (ioctl(l->pchan->fds[0],ZT_SETCONF,&ci) == -1)
- {
- ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
- pthread_exit(NULL);
- }
- ast_mutex_lock(&myrpt->lock);
- if (phone_mode > 1) l->lastrx = 1;
- /* insert at end of queue */
- insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
- ast_mutex_unlock(&myrpt->lock);
- if (chan->_state != AST_STATE_UP) {
- ast_answer(chan);
- }
- return AST_PBX_KEEPALIVE;
- }
- ast_mutex_lock(&myrpt->lock);
- /* if remote, error if anyone else already linked */
- if (myrpt->remoteon)
- {
- ast_mutex_unlock(&myrpt->lock);
- usleep(500000);
- if (myrpt->remoteon)
- {
- ast_log(LOG_WARNING, "Trying to use busy link on %s\n",tmp);
- return -1;
- }
- ast_mutex_lock(&myrpt->lock);
- }
- myrpt->remoteon = 1;
- if (ioperm(myrpt->iobase,1,1) == -1)
- {
- ast_mutex_unlock(&myrpt->lock);
- ast_log(LOG_WARNING, "Cant get io permission on IO port %x hex\n",myrpt->iobase);
- return -1;
- }
- LOCAL_USER_ADD(u);
- tele = strchr(myrpt->rxchanname,'/');
- if (!tele)
- {
- fprintf(stderr,"rpt:Dial number must be in format tech/number\n");
- ast_mutex_unlock(&myrpt->lock);
- pthread_exit(NULL);
- }
- *tele++ = 0;
- myrpt->rxchannel = ast_request(myrpt->rxchanname,AST_FORMAT_SLINEAR,tele,NULL);
- if (myrpt->rxchannel)
- {
- ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
- ast_set_write_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
- myrpt->rxchannel->whentohangup = 0;
- myrpt->rxchannel->appl = "Apprpt";
- myrpt->rxchannel->data = "(Link Rx)";
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "rpt (Rx) initiating call to %s/%s on %s\n",
- myrpt->rxchanname,tele,myrpt->rxchannel->name);
- ast_mutex_unlock(&myrpt->lock);
- ast_call(myrpt->rxchannel,tele,999);
- ast_mutex_lock(&myrpt->lock);
- }
- else
- {
- fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
- ast_mutex_unlock(&myrpt->lock);
- pthread_exit(NULL);
- }
- *--tele = '/';
- if (myrpt->txchanname)
- {
- tele = strchr(myrpt->txchanname,'/');
- if (!tele)
- {
- fprintf(stderr,"rpt:Dial number must be in format tech/number\n");
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->rxchannel);
- pthread_exit(NULL);
- }
- *tele++ = 0;
- myrpt->txchannel = ast_request(myrpt->txchanname,AST_FORMAT_SLINEAR,tele,NULL);
- if (myrpt->txchannel)
- {
- ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
- ast_set_write_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
- myrpt->txchannel->whentohangup = 0;
- myrpt->txchannel->appl = "Apprpt";
- myrpt->txchannel->data = "(Link Tx)";
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "rpt (Tx) initiating call to %s/%s on %s\n",
- myrpt->txchanname,tele,myrpt->txchannel->name);
- ast_mutex_unlock(&myrpt->lock);
- ast_call(myrpt->txchannel,tele,999);
- ast_mutex_lock(&myrpt->lock);
- }
- else
- {
- fprintf(stderr,"rpt:Sorry unable to obtain Tx channel\n");
- ast_mutex_unlock(&myrpt->lock);
- ast_hangup(myrpt->rxchannel);
- pthread_exit(NULL);
- }
- *--tele = '/';
- }
- else
- {
- myrpt->txchannel = myrpt->rxchannel;
- }
- myrpt->remoterx = 0;
- myrpt->remotetx = 0;
- myrpt->retxtimer = 0;
- myrpt->remoteon = 1;
- myrpt->dtmfidx = -1;
- myrpt->dtmfbuf[0] = 0;
- myrpt->dtmf_time_rem = 0;
- myrpt->hfscanmode = 0;
- myrpt->hfscanstatus = 0;
- ast_mutex_unlock(&myrpt->lock);
- setrem(myrpt);
- ast_set_write_format(chan, AST_FORMAT_SLINEAR);
- ast_set_read_format(chan, AST_FORMAT_SLINEAR);
- /* if we are on 2w loop and are a remote, turn EC on */
- if (myrpt->remote && (myrpt->rxchannel == myrpt->txchannel))
- {
- i = 128;
- ioctl(myrpt->rxchannel->fds[0],ZT_ECHOCANCEL,&i);
- }
- if (chan->_state != AST_STATE_UP) {
- ast_answer(chan);
- }
-
- if (ioctl(myrpt->txchannel->fds[0],ZT_GET_PARAMS,&par) != -1)
- {
- if (par.rxisoffhook)
- {
- ast_indicate(chan,AST_CONTROL_RADIO_KEY);
- myrpt->remoterx = 1;
- }
- }
- n = 0;
- cs[n++] = chan;
- cs[n++] = myrpt->rxchannel;
- if (myrpt->rxchannel != myrpt->txchannel)
- cs[n++] = myrpt->txchannel;
- for(;;)
- {
- if (ast_check_hangup(chan)) break;
- if (ast_check_hangup(myrpt->rxchannel)) break;
- ms = MSWAIT;
- who = ast_waitfor_n(cs,n,&ms);
- if (who == NULL) ms = 0;
- elap = MSWAIT - ms;
- if (!ms) continue;
- rem_totx = keyed;
-
-
- if ((!myrpt->remoterx) && (!myrpt->remotetx))
- {
- if ((myrpt->retxtimer += elap) >= REDUNDANT_TX_TIME)
- {
- myrpt->retxtimer = 0;
- ast_indicate(chan,AST_CONTROL_RADIO_UNKEY);
- }
- } else myrpt->retxtimer = 0;
- if (rem_totx && (!myrpt->remotetx)) /* Remote base radio TX key */
- {
- myrpt->remotetx = 1;
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
- }
- if ((!rem_totx) && myrpt->remotetx) /* Remote base radio TX unkey */
- {
- myrpt->remotetx = 0;
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
- }
-
- if(myrpt->tunerequest && (!strcmp(myrpt->remote, remote_rig_ft897))){ /* ft-897 specific for now... */
- myrpt->tunerequest = 0;
- set_mode_ft897(myrpt, REM_MODE_AM);
- simple_command_ft897(myrpt, 8);
- myrpt->remotetx = 0;
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
- if (!myrpt->remoterx)
- ast_indicate(chan, AST_CONTROL_RADIO_KEY);
- if(play_tone(chan, 800, 6000, 8192) == -1)
- break;
-
- rmt_telem_finish(myrpt,chan);
- set_mode_ft897(myrpt, 0x88);
- setrem(myrpt);
- }
-
- if (myrpt->hfscanmode){
- myrpt->scantimer -= elap;
- if(myrpt->scantimer <= 0){
- myrpt->scantimer = REM_SCANTIME;
- service_scan(myrpt);
- }
- }
-
-
- if (who == chan) /* if it was a read from incomming */
- {
- f = ast_read(chan);
- if (!f)
- {
- if (debug) printf("@@@@ link:Hung Up\n");
- break;
- }
- if (f->frametype == AST_FRAME_VOICE)
- {
- /* if not transmitting, zero-out audio */
- if (!myrpt->remotetx)
- memset(f->data,0,f->datalen);
- ast_write(myrpt->txchannel,f);
- }
- if (f->frametype == AST_FRAME_DTMF)
- {
- myrpt->remchannel = chan; /* Save copy of channel */
- if (handle_remote_phone_dtmf(myrpt,f->subclass,&keyed,phone_mode) == -1)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- break;
- }
- }
- if (f->frametype == AST_FRAME_TEXT)
- {
- myrpt->remchannel = chan; /* Save copy of channel */
- if (handle_remote_data(myrpt,f->data) == -1)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- break;
- }
- }
- if (f->frametype == AST_FRAME_CONTROL)
- {
- if (f->subclass == AST_CONTROL_HANGUP)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- break;
- }
- /* if RX key */
- if (f->subclass == AST_CONTROL_RADIO_KEY)
- {
- if (debug) printf("@@@@ rx key\n");
- keyed = 1;
- }
- /* if RX un-key */
- if (f->subclass == AST_CONTROL_RADIO_UNKEY)
- {
- if (debug) printf("@@@@ rx un-key\n");
- keyed = 0;
- }
- }
- if (myrpt->hfscanstatus){
- myrpt->remchannel = chan; /* Save copy of channel */
- myrpt->remotetx = 0;
- ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
- if (!myrpt->remoterx)
- {
- ast_indicate(myrpt->remchannel,AST_CONTROL_RADIO_KEY);
- }
- if(myrpt->hfscanstatus < 0) {
- if (myrpt->hfscanstatus == -1) {
- if (ast_safe_sleep(myrpt->remchannel,1000) == -1) break;
- }
- sayfile(myrpt->remchannel, "rpt/stop");
- }
- else
- {
- saynum(myrpt->remchannel, myrpt->hfscanstatus );
- }
- rmt_telem_finish(myrpt,myrpt->remchannel);
- myrpt->hfscanstatus = 0;
- }
- ast_frfree(f);
- continue;
- }
- if (who == myrpt->rxchannel) /* if it was a read from radio */
- {
- f = ast_read(myrpt->rxchannel);
- if (!f)
- {
- if (debug) printf("@@@@ link:Hung Up\n");
- break;
- }
- if (f->frametype == AST_FRAME_VOICE)
- {
- if ((myrpt->remote) && (myrpt->remotetx))
- memset(f->data,0,f->datalen);
- ast_write(chan,f);
- }
- else if (f->frametype == AST_FRAME_CONTROL)
- {
- if (f->subclass == AST_CONTROL_HANGUP)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- break;
- }
- /* if RX key */
- if (f->subclass == AST_CONTROL_RADIO_KEY)
- {
- if (debug) printf("@@@@ remote rx key\n");
- if (!myrpt->remotetx)
- {
- ast_indicate(chan,AST_CONTROL_RADIO_KEY);
- myrpt->remoterx = 1;
- }
- }
- /* if RX un-key */
- if (f->subclass == AST_CONTROL_RADIO_UNKEY)
- {
- if (debug) printf("@@@@ remote rx un-key\n");
- if (!myrpt->remotetx)
- {
- ast_indicate(chan,AST_CONTROL_RADIO_UNKEY);
- myrpt->remoterx = 0;
- }
- }
- }
- ast_frfree(f);
- continue;
- }
- if ((myrpt->rxchannel != myrpt->txchannel) &&
- (who == myrpt->txchannel)) /* do this cuz you have to */
- {
- f = ast_read(myrpt->txchannel);
- if (!f)
- {
- if (debug) printf("@@@@ link:Hung Up\n");
- break;
- }
- if (f->frametype == AST_FRAME_CONTROL)
- {
- if (f->subclass == AST_CONTROL_HANGUP)
- {
- if (debug) printf("@@@@ rpt:Hung Up\n");
- ast_frfree(f);
- break;
- }
- }
- ast_frfree(f);
- continue;
- }
-
- }
- ast_mutex_lock(&myrpt->lock);
- if (myrpt->rxchannel != myrpt->txchannel) ast_hangup(myrpt->txchannel);
- ast_hangup(myrpt->rxchannel);
- myrpt->hfscanmode = 0;
- myrpt->hfscanstatus = 0;
- myrpt->remoteon = 0;
- ast_mutex_unlock(&myrpt->lock);
- closerem(myrpt);
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int i;
-
- STANDARD_HANGUP_LOCALUSERS;
- for(i = 0; i < nrpts; i++) {
- if (!strcmp(rpt_vars[i].name,rpt_vars[i].nodes)) continue;
- ast_mutex_destroy(&rpt_vars[i].lock);
- }
- i = ast_unregister_application(app);
-
- /* Unregister cli extensions */
- ast_cli_unregister(&cli_debug);
-
- return i;
-}
-
-int load_module(void)
-{
- ast_pthread_create(&rpt_master_thread,NULL,rpt_master,NULL);
-
- /* Register cli extensions */
- ast_cli_register(&cli_debug);
-
- return ast_register_application(app, rpt_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_sayunixtime.c b/1.2-netsec/apps/app_sayunixtime.c
deleted file mode 100644
index fc9cd25bf..000000000
--- a/1.2-netsec/apps/app_sayunixtime.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (c) 2003 Tilghman Lesher. All rights reserved.
- *
- * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
- *
- * This code is released by the author with no restrictions on usage.
- *
- * 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.
- *
- */
-
-/*! \file
- *
- * \brief SayUnixTime application
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/say.h"
-
-
-static char *tdesc = "Say time";
-
-static char *app_sayunixtime = "SayUnixTime";
-static char *app_datetime = "DateTime";
-
-static char *sayunixtime_synopsis = "Says a specified time in a custom format";
-
-static char *sayunixtime_descrip =
-"SayUnixTime([unixtime][|[timezone][|format]])\n"
-" unixtime: time, in seconds since Jan 1, 1970. May be negative.\n"
-" defaults to now.\n"
-" timezone: timezone, see /usr/share/zoneinfo for a list.\n"
-" defaults to machine default.\n"
-" format: a format the time is to be said in. See voicemail.conf.\n"
-" defaults to \"ABdY 'digits/at' IMp\"\n";
-static char *datetime_descrip =
-"DateTime([unixtime][|[timezone][|format]])\n"
-" unixtime: time, in seconds since Jan 1, 1970. May be negative.\n"
-" defaults to now.\n"
-" timezone: timezone, see /usr/share/zoneinfo for a list.\n"
-" defaults to machine default.\n"
-" format: a format the time is to be said in. See voicemail.conf.\n"
-" defaults to \"ABdY 'digits/at' IMp\"\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int sayunixtime_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- char *s,*zone=NULL,*timec,*format;
- time_t unixtime;
- struct timeval tv;
-
- LOCAL_USER_ADD(u);
-
- tv = ast_tvnow();
- unixtime = (time_t)tv.tv_sec;
-
- if( !strcasecmp(chan->language, "da" ) ) {
- format = "A dBY HMS";
- } else if ( !strcasecmp(chan->language, "de" ) ) {
- format = "A dBY HMS";
- } else {
- format = "ABdY 'digits/at' IMp";
- }
-
- if (data) {
- s = data;
- s = ast_strdupa(s);
- if (s) {
- timec = strsep(&s,"|");
- if ((timec) && (*timec != '\0')) {
- long timein;
- if (sscanf(timec,"%ld",&timein) == 1) {
- unixtime = (time_t)timein;
- }
- }
- if (s) {
- zone = strsep(&s,"|");
- if (zone && (*zone == '\0'))
- zone = NULL;
- if (s) {
- format = s;
- }
- }
- } else {
- ast_log(LOG_ERROR, "Out of memory error\n");
- }
- }
-
- if (chan->_state != AST_STATE_UP) {
- res = ast_answer(chan);
- }
- if (!res)
- res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, chan->language, format, zone);
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app_sayunixtime);
- res |= ast_unregister_application(app_datetime);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
- res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_senddtmf.c b/1.2-netsec/apps/app_senddtmf.c
deleted file mode 100644
index c2c3c765d..000000000
--- a/1.2-netsec/apps/app_senddtmf.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief App to send DTMF digits
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-
-static char *tdesc = "Send DTMF digits Application";
-
-static char *app = "SendDTMF";
-
-static char *synopsis = "Sends arbitrary DTMF digits";
-
-static char *descrip =
-" SendDTMF(digits[|timeout_ms]): Sends DTMF digits on a channel. \n"
-" Accepted digits: 0-9, *#abcd\n"
-" The application will either pass the assigned digits or terminate if it\n"
-" encounters an error.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int senddtmf_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- char *digits = NULL, *to = NULL;
- int timeout = 250;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
- return 0;
- }
-
- LOCAL_USER_ADD(u);
-
- digits = ast_strdupa(data);
- if (!digits) {
- ast_log(LOG_ERROR, "Out of Memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if ((to = strchr(digits,'|'))) {
- *to = '\0';
- to++;
- timeout = atoi(to);
- }
-
- if(timeout <= 0)
- timeout = 250;
-
- res = ast_dtmf_stream(chan,NULL,digits,timeout);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, senddtmf_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_sendtext.c b/1.2-netsec/apps/app_sendtext.c
deleted file mode 100644
index 7830ee860..000000000
--- a/1.2-netsec/apps/app_sendtext.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief App to transmit a text message
- *
- * Requires support of sending text messages from channel driver
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#include "asterisk/options.h"
-#include "asterisk/app.h"
-
-static const char *tdesc = "Send Text Applications";
-
-static const char *app = "SendText";
-
-static const char *synopsis = "Send a Text Message";
-
-static const char *descrip =
-" SendText(text[|options]): Sends text to current channel (callee).\n"
-"Result of transmission will be stored in the SENDTEXTSTATUS\n"
-"channel variable:\n"
-" SUCCESS Transmission succeeded\n"
-" FAILURE Transmission failed\n"
-" UNSUPPORTED Text transmission not supported by channel\n"
-"\n"
-"At this moment, text is supposed to be 7 bit ASCII in most channels.\n"
-"The option string many contain the following character:\n"
-"'j' -- jump to n+101 priority if the channel doesn't support\n"
-" text transport\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int sendtext_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- char *status = "UNSUPPORTED";
- char *parse = NULL;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(text);
- AST_APP_ARG(options);
- );
-
- LOCAL_USER_ADD(u);
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "SendText requires an argument (text[|options])\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- } else {
- parse = ast_strdupa(data);
- if (!parse) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- ast_mutex_lock(&chan->lock);
- if (!chan->tech->send_text) {
- ast_mutex_unlock(&chan->lock);
- /* Does not support transport */
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- status = "FAILURE";
- ast_mutex_unlock(&chan->lock);
- res = ast_sendtext(chan, args.text);
- if (!res)
- status = "SUCCESS";
- pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
- LOCAL_USER_REMOVE(u);
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, sendtext_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return (char *) tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
-
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_setcallerid.c b/1.2-netsec/apps/app_setcallerid.c
deleted file mode 100644
index 877efb533..000000000
--- a/1.2-netsec/apps/app_setcallerid.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief App to set callerid
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#include "asterisk/callerid.h"
-
-static char *app2 = "SetCallerPres";
-
-static char *synopsis2 = "Set CallerID Presentation";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static char *descrip2 =
-" SetCallerPres(presentation): Set Caller*ID presentation on a call.\n"
-" Valid presentations are:\n"
-"\n"
-" allowed_not_screened : Presentation Allowed, Not Screened\n"
-" allowed_passed_screen : Presentation Allowed, Passed Screen\n"
-" allowed_failed_screen : Presentation Allowed, Failed Screen\n"
-" allowed : Presentation Allowed, Network Number\n"
-" prohib_not_screened : Presentation Prohibited, Not Screened\n"
-" prohib_passed_screen : Presentation Prohibited, Passed Screen\n"
-" prohib_failed_screen : Presentation Prohibited, Failed Screen\n"
-" prohib : Presentation Prohibited, Network Number\n"
-" unavailable : Number Unavailable\n"
-"\n"
-;
-
-static int setcallerid_pres_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- int pres = -1;
-
- LOCAL_USER_ADD(u);
-
- pres = ast_parse_caller_presentation(data);
-
- if (pres < 0) {
- ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
- (char *) data);
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- chan->cid.cid_pres = pres;
- LOCAL_USER_REMOVE(u);
- return 0;
-}
-
-
-
-static char *tdesc = "Set CallerID Application";
-
-static char *app = "SetCallerID";
-
-static char *synopsis = "Set CallerID";
-
-static char *descrip =
-" SetCallerID(clid[|a]): Set Caller*ID on a call to a new\n"
-"value. Sets ANI as well if a flag is used. \n";
-
-static int setcallerid_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- char *tmp = NULL;
- char name[256];
- char num[256];
- struct localuser *u;
- char *opt;
- int anitoo = 0;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "SetCallerID requires an argument!\n");
- return 0;
- }
-
- LOCAL_USER_ADD(u);
-
- tmp = ast_strdupa(data);
- if (!tmp) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- opt = strchr(tmp, '|');
- if (opt) {
- *opt = '\0';
- opt++;
- if (*opt == 'a')
- anitoo = 1;
- }
-
- ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num));
- ast_set_callerid(chan, num, name, anitoo ? num : NULL);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app2);
- res |= ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app2, setcallerid_pres_exec, synopsis2, descrip2);
- res |= ast_register_application(app, setcallerid_exec, synopsis, descrip);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_setcdruserfield.c b/1.2-netsec/apps/app_setcdruserfield.c
deleted file mode 100644
index c477663dc..000000000
--- a/1.2-netsec/apps/app_setcdruserfield.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Justin Huff <jjhuff@mspin.net>
- *
- * 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 Applictions connected with CDR engine
- *
- * \ingroup applications
- */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/cdr.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/config.h"
-#include "asterisk/manager.h"
-#include "asterisk/utils.h"
-
-
-static char *tdesc = "CDR user field apps";
-
-static char *setcdruserfield_descrip =
- "[Synopsis]\n"
- "SetCDRUserField(value)\n\n"
- "[Description]\n"
- "SetCDRUserField(value): Set the CDR 'user field' to value\n"
- " The Call Data Record (CDR) user field is an extra field you\n"
- " can use for data not stored anywhere else in the record.\n"
- " CDR records can be used for billing or storing other arbitrary data\n"
- " (I.E. telephone survey responses)\n"
- " Also see AppendCDRUserField().\n";
-
-
-static char *setcdruserfield_app = "SetCDRUserField";
-static char *setcdruserfield_synopsis = "Set the CDR user field";
-
-static char *appendcdruserfield_descrip =
- "[Synopsis]\n"
- "AppendCDRUserField(value)\n\n"
- "[Description]\n"
- "AppendCDRUserField(value): Append value to the CDR user field\n"
- " The Call Data Record (CDR) user field is an extra field you\n"
- " can use for data not stored anywhere else in the record.\n"
- " CDR records can be used for billing or storing other arbitrary data\n"
- " (I.E. telephone survey responses)\n"
- " Also see SetCDRUserField().\n";
-
-static char *appendcdruserfield_app = "AppendCDRUserField";
-static char *appendcdruserfield_synopsis = "Append to the CDR user field";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int action_setcdruserfield(struct mansession *s, struct message *m)
-{
- struct ast_channel *c = NULL;
- char *userfield = astman_get_header(m, "UserField");
- char *channel = astman_get_header(m, "Channel");
- char *append = astman_get_header(m, "Append");
-
- if (ast_strlen_zero(channel)) {
- astman_send_error(s, m, "No Channel specified");
- return 0;
- }
- if (ast_strlen_zero(userfield)) {
- astman_send_error(s, m, "No UserField specified");
- return 0;
- }
- c = ast_get_channel_by_name_locked(channel);
- if (!c) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- if (ast_true(append))
- ast_cdr_appenduserfield(c, userfield);
- else
- ast_cdr_setuserfield(c, userfield);
- ast_mutex_unlock(&c->lock);
- astman_send_ack(s, m, "CDR Userfield Set");
- return 0;
-}
-
-static int setcdruserfield_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- int res = 0;
-
- LOCAL_USER_ADD(u);
-
- if (chan->cdr && data) {
- ast_cdr_setuserfield(chan, (char*)data);
- }
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-static int appendcdruserfield_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- int res = 0;
-
- LOCAL_USER_ADD(u);
-
- if (chan->cdr && data) {
- ast_cdr_appenduserfield(chan, (char*)data);
- }
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(setcdruserfield_app);
- res |= ast_unregister_application(appendcdruserfield_app);
- res |= ast_manager_unregister("SetCDRUserField");
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
- res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
- res |= ast_manager_register("SetCDRUserField", EVENT_FLAG_CALL, action_setcdruserfield, "Set the CDR UserField");
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_setcidname.c b/1.2-netsec/apps/app_setcidname.c
deleted file mode 100644
index 6906c132a..000000000
--- a/1.2-netsec/apps/app_setcidname.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief App to set callerid
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#include "asterisk/callerid.h"
-#include "asterisk/utils.h"
-
-static char *tdesc = "Set CallerID Name";
-
-static char *app = "SetCIDName";
-
-static char *synopsis = "Set CallerID Name";
-
-static char *descrip =
-" SetCIDName(cname[|a]): Set Caller*ID Name on a call to a new\n"
-"value, while preserving the original Caller*ID number. This is\n"
-"useful for providing additional information to the called\n"
-"party. \n"
-"SetCIDName has been deprecated in favor of the function\n"
-"CALLERID(name)\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int setcallerid_exec(struct ast_channel *chan, void *data)
-{
- char *tmp = NULL;
- struct localuser *u;
- char *opt;
- static int deprecation_warning = 0;
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "SetCIDName is deprecated, please use Set(CALLERID(name)=value) instead.\n");
- deprecation_warning = 1;
- }
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_ERROR, "SetCIDName requires an argument!\n");
- return 0;
- }
-
- LOCAL_USER_ADD(u);
-
- tmp = ast_strdupa(data);
- if (!tmp) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- opt = strchr(tmp, '|');
- if (opt) {
- *opt = '\0';
- }
-
- ast_set_callerid(chan, NULL, tmp, NULL);
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, setcallerid_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_setcidnum.c b/1.2-netsec/apps/app_setcidnum.c
deleted file mode 100644
index a8a7e0706..000000000
--- a/1.2-netsec/apps/app_setcidnum.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- * Oliver Daudey <traveler@xs4all.nl>
- *
- * 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 App to set callerid number
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#include "asterisk/callerid.h"
-#include "asterisk/utils.h"
-
-static char *tdesc = "Set CallerID Number";
-
-static char *app = "SetCIDNum";
-
-static char *synopsis = "Set CallerID Number";
-
-static char *descrip =
-" SetCIDNum(cnum[|a]): Set Caller*ID Number on a call to a new\n"
-"value, while preserving the original Caller*ID name. This is\n"
-"useful for providing additional information to the called\n"
-"party. Sets ANI as well if a flag is used.\n"
-"SetCIDNum has been deprecated in favor of the function\n"
-"CALLERID(number)\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int setcallerid_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- char *opt;
- int anitoo = 0;
- char *tmp = NULL;
- static int deprecation_warning = 0;
-
- LOCAL_USER_ADD(u);
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "SetCIDNum is deprecated, please use Set(CALLERID(number)=value) instead.\n");
- deprecation_warning = 1;
- }
-
- if (data)
- tmp = ast_strdupa(data);
- else
- tmp = "";
-
- opt = strchr(tmp, '|');
- if (opt) {
- *opt = '\0';
- opt++;
- if (*opt == 'a')
- anitoo = 1;
- }
-
- ast_set_callerid(chan, tmp, NULL, anitoo ? tmp : NULL);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, setcallerid_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_setrdnis.c b/1.2-netsec/apps/app_setrdnis.c
deleted file mode 100644
index 69c3ed568..000000000
--- a/1.2-netsec/apps/app_setrdnis.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- * Oliver Daudey <traveler@xs4all.nl>
- *
- * 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 App to set rdnis
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#include "asterisk/callerid.h"
-#include "asterisk/utils.h"
-
-static char *tdesc = "Set RDNIS Number";
-
-static char *app = "SetRDNIS";
-
-static char *synopsis = "Set RDNIS Number";
-
-static char *descrip =
-" SetRDNIS(cnum): Set RDNIS Number on a call to a new\n"
-"value.\n"
-"SetRDNIS has been deprecated in favor of the function\n"
-"CALLERID(rdnis)\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int setrdnis_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- char *opt, *n, *l;
- char *tmp = NULL;
- static int deprecation_warning = 0;
-
- LOCAL_USER_ADD(u);
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "SetRDNIS is deprecated, please use Set(CALLERID(rdnis)=value) instead.\n");
- deprecation_warning = 1;
- }
-
- if (data)
- tmp = ast_strdupa(data);
- else
- tmp = "";
-
- opt = strchr(tmp, '|');
- if (opt)
- *opt = '\0';
-
- n = l = NULL;
- ast_callerid_parse(tmp, &n, &l);
- if (l) {
- ast_shrink_phone_number(l);
- ast_mutex_lock(&chan->lock);
- if (chan->cid.cid_rdnis)
- free(chan->cid.cid_rdnis);
- chan->cid.cid_rdnis = (l[0]) ? strdup(l) : NULL;
- ast_mutex_unlock(&chan->lock);
- }
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, setrdnis_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_settransfercapability.c b/1.2-netsec/apps/app_settransfercapability.c
deleted file mode 100644
index 5a9614afa..000000000
--- a/1.2-netsec/apps/app_settransfercapability.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Frank Sautter, levigo holding gmbh, www.levigo.de
- *
- * Frank Sautter - asterisk+at+sautter+dot+com
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief App to set the ISDN Transfer Capability
- *
- * \ingroup applications
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/transcap.h"
-
-
-static char *app = "SetTransferCapability";
-
-static char *synopsis = "Set ISDN Transfer Capability";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static struct { int val; char *name; } transcaps[] = {
- { AST_TRANS_CAP_SPEECH, "SPEECH" },
- { AST_TRANS_CAP_DIGITAL, "DIGITAL" },
- { AST_TRANS_CAP_RESTRICTED_DIGITAL, "RESTRICTED_DIGITAL" },
- { AST_TRANS_CAP_3_1K_AUDIO, "3K1AUDIO" },
- { AST_TRANS_CAP_DIGITAL_W_TONES, "DIGITAL_W_TONES" },
- { AST_TRANS_CAP_VIDEO, "VIDEO" },
-};
-
-static char *descrip =
-" SetTransferCapability(transfercapability): Set the ISDN Transfer \n"
-"Capability of a call to a new value.\n"
-"Valid Transfer Capabilities are:\n"
-"\n"
-" SPEECH : 0x00 - Speech (default, voice calls)\n"
-" DIGITAL : 0x08 - Unrestricted digital information (data calls)\n"
-" RESTRICTED_DIGITAL : 0x09 - Restricted digital information\n"
-" 3K1AUDIO : 0x10 - 3.1kHz Audio (fax calls)\n"
-" DIGITAL_W_TONES : 0x11 - Unrestricted digital information with tones/announcements\n"
-" VIDEO : 0x18 - Video:\n"
-"\n"
-;
-
-static int settransfercapability_exec(struct ast_channel *chan, void *data)
-{
- char *tmp = NULL;
- struct localuser *u;
- int x;
- char *opts;
- int transfercapability = -1;
-
- LOCAL_USER_ADD(u);
-
- if (data)
- tmp = ast_strdupa(data);
- else
- tmp = "";
-
- opts = strchr(tmp, '|');
- if (opts)
- *opts = '\0';
-
- for (x = 0; x < (sizeof(transcaps) / sizeof(transcaps[0])); x++) {
- if (!strcasecmp(transcaps[x].name, tmp)) {
- transfercapability = transcaps[x].val;
- break;
- }
- }
- if (transfercapability < 0) {
- ast_log(LOG_WARNING, "'%s' is not a valid transfer capability (see 'show application SetTransferCapability')\n", tmp);
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- chan->transfercapability = (unsigned short)transfercapability;
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Setting transfer capability to: 0x%.2x - %s.\n", transfercapability, tmp);
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, settransfercapability_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return synopsis;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_skel.c b/1.2-netsec/apps/app_skel.c
deleted file mode 100644
index 9fb2e757a..000000000
--- a/1.2-netsec/apps/app_skel.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) <Year>, <Your Name Here>
- *
- * <Your Name Here> <<Your Email Here>>
- *
- * 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 Skeleton application
- *
- * This is a skeleton for development of an Asterisk application
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/app.h"
-
-static char *tdesc = "Trivial skeleton Application";
-static char *app = "Skel";
-static char *synopsis =
-"Skeleton application.";
-static char *descrip = "This application is a template to build other applications from.\n"
- " It shows you the basic structure to create your own Asterisk applications.\n";
-
-#define OPTION_A (1 << 0) /* Option A */
-#define OPTION_B (1 << 1) /* Option B(n) */
-#define OPTION_C (1 << 2) /* Option C(str) */
-#define OPTION_NULL (1 << 3) /* Dummy Termination */
-
-AST_DECLARE_OPTIONS(app_opts,{
- ['a'] = { OPTION_A },
- ['b'] = { OPTION_B, 1 },
- ['c'] = { OPTION_C, 2 }
-});
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int app_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct ast_flags flags;
- struct localuser *u;
- char *options=NULL;
- char *dummy = NULL;
- char *args;
- int argc = 0;
- char *opts[2];
- char *argv[2];
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "%s requires an argument (dummy|[options])\n",app);
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- /* Do our thing here */
-
- /* We need to make a copy of the input string if we are going to modify it! */
- args = ast_strdupa(data);
- if (!args) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if ((argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
- dummy = argv[0];
- options = argv[1];
- ast_parseoptions(app_opts, &flags, opts, options);
- }
-
- if (!ast_strlen_zero(dummy))
- ast_log(LOG_NOTICE, "Dummy value is : %s\n", dummy);
-
- if (ast_test_flag(&flags, OPTION_A))
- ast_log(LOG_NOTICE, "Option A is set\n");
-
- if (ast_test_flag(&flags, OPTION_B))
- ast_log(LOG_NOTICE,"Option B is set with : %s\n", opts[0] ? opts[0] : "<unspecified>");
-
- if (ast_test_flag(&flags, OPTION_C))
- ast_log(LOG_NOTICE,"Option C is set with : %s\n", opts[1] ? opts[1] : "<unspecified>");
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, app_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_sms.c b/1.2-netsec/apps/app_sms.c
deleted file mode 100644
index 4c15cc185..000000000
--- a/1.2-netsec/apps/app_sms.c
+++ /dev/null
@@ -1,1555 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005, Adrian Kennard, rights assigned to Digium
- *
- * 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 SMS application - ETSI ES 201 912 protocol 1 implimentation
- * \ingroup applications
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <dirent.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/alaw.h"
-#include "asterisk/callerid.h"
-
-/* output using Alaw rather than linear */
-/* #define OUTALAW */
-
-/* ToDo */
-/* Add full VP support */
-/* Handle status report messages (generation and reception) */
-/* Time zones on time stamps */
-/* user ref field */
-
-static volatile unsigned char message_ref; /* arbitary message ref */
-static volatile unsigned int seq; /* arbitrary message sequence number for unqiue files */
-
-static char log_file[255];
-static char spool_dir[255];
-
-static char *tdesc = "SMS/PSTN handler";
-
-static char *app = "SMS";
-
-static char *synopsis = "Communicates with SMS service centres and SMS capable analogue phones";
-
-static char *descrip =
- " SMS(name|[a][s]): SMS handles exchange of SMS data with a call to/from SMS capabale\n"
- "phone or SMS PSTN service center. Can send and/or receive SMS messages.\n"
- "Works to ETSI ES 201 912 compatible with BT SMS PSTN service in UK\n"
- "Typical usage is to use to handle called from the SMS service centre CLI,\n"
- "or to set up a call using 'outgoing' or manager interface to connect\n"
- "service centre to SMS()\n"
- "name is the name of the queue used in /var/spool/asterisk/sms\n"
- "Arguments:\n"
- " a: answer, i.e. send initial FSK packet.\n"
- " s: act as service centre talking to a phone.\n"
- "Messages are processed as per text file message queues.\n"
- "smsq (a separate software) is a command to generate message\n"
- "queues and send messages.\n";
-
-static signed short wave[] = {
- 0, 392, 782, 1167, 1545, 1913, 2270, 2612, 2939, 3247, 3536, 3802, 4045, 4263, 4455, 4619, 4755, 4862, 4938, 4985,
- 5000, 4985, 4938, 4862, 4755, 4619, 4455, 4263, 4045, 3802, 3536, 3247, 2939, 2612, 2270, 1913, 1545, 1167, 782, 392,
- 0, -392, -782, -1167,
- -1545, -1913, -2270, -2612, -2939, -3247, -3536, -3802, -4045, -4263, -4455, -4619, -4755, -4862, -4938, -4985, -5000,
- -4985, -4938, -4862,
- -4755, -4619, -4455, -4263, -4045, -3802, -3536, -3247, -2939, -2612, -2270, -1913, -1545, -1167, -782, -392
-};
-
-#ifdef OUTALAW
-static unsigned char wavea[80];
-#endif
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-/* SMS 7 bit character mapping to UCS-2 */
-static const unsigned short defaultalphabet[] = {
- 0x0040, 0x00A3, 0x0024, 0x00A5, 0x00E8, 0x00E9, 0x00F9, 0x00EC,
- 0x00F2, 0x00E7, 0x000A, 0x00D8, 0x00F8, 0x000D, 0x00C5, 0x00E5,
- 0x0394, 0x005F, 0x03A6, 0x0393, 0x039B, 0x03A9, 0x03A0, 0x03A8,
- 0x03A3, 0x0398, 0x039E, 0x00A0, 0x00C6, 0x00E6, 0x00DF, 0x00C9,
- ' ', '!', '"', '#', 164, '%', '&', 39, '(', ')', '*', '+', ',', '-', '.', '/',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
- 161, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
- 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 196, 214, 209, 220, 167,
- 191, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 228, 246, 241, 252, 224,
-};
-
-static const unsigned short escapes[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x000C, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0x005E, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0x007B, 0x007D, 0, 0, 0, 0, 0, 0x005C,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x005B, 0x007E, 0x005D, 0,
- 0x007C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0x20AC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-#define SMSLEN 160 /* max SMS length */
-
-typedef struct sms_s
-{
- unsigned char hangup; /* we are done... */
- unsigned char err; /* set for any errors */
- unsigned char smsc:1; /* we are SMSC */
- unsigned char rx:1; /* this is a received message */
- char queue[30]; /* queue name */
- char oa[20]; /* originating address */
- char da[20]; /* destination address */
- time_t scts; /* time stamp, UTC */
- unsigned char pid; /* protocol ID */
- unsigned char dcs; /* data coding scheme */
- short mr; /* message reference - actually a byte, but usde -1 for not set */
- int udl; /* user data length */
- int udhl; /* user data header length */
- unsigned char srr:1; /* Status Report request */
- unsigned char udhi:1; /* User Data Header required, even if length 0 */
- unsigned char rp:1; /* Reply Path */
- unsigned int vp; /* validity period in minutes, 0 for not set */
- unsigned short ud[SMSLEN]; /* user data (message), UCS-2 coded */
- unsigned char udh[SMSLEN]; /* user data header */
- char cli[20]; /* caller ID */
- unsigned char ophase; /* phase (0-79) for 0 and 1 frequencies (1300Hz and 2100Hz) */
- unsigned char ophasep; /* phase (0-79) for 1200 bps */
- unsigned char obyte; /* byte being sent */
- unsigned int opause; /* silent pause before sending (in sample periods) */
- unsigned char obitp; /* bit in byte */
- unsigned char osync; /* sync bits to send */
- unsigned char obytep; /* byte in data */
- unsigned char obyten; /* bytes in data */
- unsigned char omsg[256]; /* data buffer (out) */
- unsigned char imsg[200]; /* data buffer (in) */
- signed long long ims0,
- imc0,
- ims1,
- imc1; /* magnitude averages sin/cos 0/1 */
- unsigned int idle;
- unsigned short imag; /* signal level */
- unsigned char ips0,
- ips1,
- ipc0,
- ipc1; /* phase sin/cos 0/1 */
- unsigned char ibitl; /* last bit */
- unsigned char ibitc; /* bit run length count */
- unsigned char iphasep; /* bit phase (0-79) for 1200 bps */
- unsigned char ibitn; /* bit number in byte being received */
- unsigned char ibytev; /* byte value being received */
- unsigned char ibytep; /* byte pointer in messafe */
- unsigned char ibytec; /* byte checksum for message */
- unsigned char ierr; /* error flag */
- unsigned char ibith; /* history of last bits */
- unsigned char ibitt; /* total of 1's in last 3 bites */
- /* more to go here */
-} sms_t;
-
-/* different types of encoding */
-#define is7bit(dcs) (((dcs)&0xC0)?(!((dcs)&4)):(!((dcs)&12)))
-#define is8bit(dcs) (((dcs)&0xC0)?(((dcs)&4)):(((dcs)&12)==4))
-#define is16bit(dcs) (((dcs)&0xC0)?0:(((dcs)&12)==8))
-
-static void *sms_alloc (struct ast_channel *chan, void *params)
-{
- return params;
-}
-
-static void sms_release (struct ast_channel *chan, void *data)
-{
- return;
-}
-
-static void sms_messagetx (sms_t * h);
-
-/*--- numcpy: copy number, skipping non digits apart from leading + */
-static void numcpy (char *d, char *s)
-{
- if (*s == '+')
- *d++ = *s++;
- while (*s) {
- if (isdigit (*s))
- *d++ = *s;
- s++;
- }
- *d = 0;
-}
-
-/*--- isodate: static, return a date/time in ISO format */
-static char * isodate (time_t t)
-{
- static char date[20];
- strftime (date, sizeof (date), "%Y-%m-%dT%H:%M:%S", localtime (&t));
- return date;
-}
-
-/*--- utf8decode: reads next UCS character from null terminated UTF-8 string and advanced pointer */
-/* for non valid UTF-8 sequences, returns character as is */
-/* Does not advance pointer for null termination */
-static long utf8decode (unsigned char **pp)
-{
- unsigned char *p = *pp;
- if (!*p)
- return 0; /* null termination of string */
- (*pp)++;
- if (*p < 0xC0)
- return *p; /* ascii or continuation character */
- if (*p < 0xE0) {
- if (*p < 0xC2 || (p[1] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp)++;
- return ((*p & 0x1F) << 6) + (p[1] & 0x3F);
- }
- if (*p < 0xF0) {
- if ((*p == 0xE0 && p[1] < 0xA0) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp) += 2;
- return ((*p & 0x0F) << 12) + ((p[1] & 0x3F) << 6) + (p[2] & 0x3F);
- }
- if (*p < 0xF8) {
- if ((*p == 0xF0 && p[1] < 0x90) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp) += 3;
- return ((*p & 0x07) << 18) + ((p[1] & 0x3F) << 12) + ((p[2] & 0x3F) << 6) + (p[3] & 0x3F);
- }
- if (*p < 0xFC) {
- if ((*p == 0xF8 && p[1] < 0x88) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80
- || (p[4] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp) += 4;
- return ((*p & 0x03) << 24) + ((p[1] & 0x3F) << 18) + ((p[2] & 0x3F) << 12) + ((p[3] & 0x3F) << 6) + (p[4] & 0x3F);
- }
- if (*p < 0xFE) {
- if ((*p == 0xFC && p[1] < 0x84) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80
- || (p[4] & 0xC0) != 0x80 || (p[5] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp) += 5;
- return ((*p & 0x01) << 30) + ((p[1] & 0x3F) << 24) + ((p[2] & 0x3F) << 18) + ((p[3] & 0x3F) << 12) + ((p[4] & 0x3F) << 6) + (p[5] & 0x3F);
- }
- return *p; /* not sensible */
-}
-
-/*--- packsms7: takes a binary header (udhl bytes at udh) and UCS-2 message (udl characters at ud) and packs in to o using SMS 7 bit character codes */
-/* The return value is the number of septets packed in to o, which is internally limited to SMSLEN */
-/* o can be null, in which case this is used to validate or count only */
-/* if the input contains invalid characters then the return value is -1 */
-static int packsms7 (unsigned char *o, int udhl, unsigned char *udh, int udl, unsigned short *ud)
-{
- unsigned char p = 0, b = 0, n = 0;
-
- if (udhl) { /* header */
- if (o)
- o[p++] = udhl;
- b = 1;
- n = 1;
- while (udhl--) {
- if (o)
- o[p++] = *udh++;
- b += 8;
- while (b >= 7) {
- b -= 7;
- n++;
- }
- if (n >= SMSLEN)
- return n;
- }
- if (b) {
- b = 7 - b;
- if (++n >= SMSLEN)
- return n;
- }; /* filling to septet boundary */
- }
- if (o)
- o[p] = 0;
- /* message */
- while (udl--) {
- long u;
- unsigned char v;
- u = *ud++;
- for (v = 0; v < 128 && defaultalphabet[v] != u; v++);
- if (v == 128 && u && n + 1 < SMSLEN) {
- for (v = 0; v < 128 && escapes[v] != u; v++);
- if (v < 128) { /* escaped sequence */
- if (o)
- o[p] |= (27 << b);
- b += 7;
- if (b >= 8) {
- b -= 8;
- p++;
- if (o)
- o[p] = (27 >> (7 - b));
- }
- n++;
- }
- }
- if (v == 128)
- return -1; /* invalid character */
- if (o)
- o[p] |= (v << b);
- b += 7;
- if (b >= 8) {
- b -= 8;
- p++;
- if (o)
- o[p] = (v >> (7 - b));
- }
- if (++n >= SMSLEN)
- return n;
- }
- return n;
-}
-
-/*--- packsms8: takes a binary header (udhl bytes at udh) and UCS-2 message (udl characters at ud) and packs in to o using 8 bit character codes */
-/* The return value is the number of bytes packed in to o, which is internally limited to 140 */
-/* o can be null, in which case this is used to validate or count only */
-/* if the input contains invalid characters then the return value is -1 */
-static int packsms8 (unsigned char *o, int udhl, unsigned char *udh, int udl, unsigned short *ud)
-{
- unsigned char p = 0;
-
- /* header - no encoding */
- if (udhl) {
- if (o)
- o[p++] = udhl;
- while (udhl--) {
- if (o)
- o[p++] = *udh++;
- if (p >= 140)
- return p;
- }
- }
- while (udl--) {
- long u;
- u = *ud++;
- if (u < 0 || u > 0xFF)
- return -1; /* not valid */
- if (o)
- o[p++] = u;
- if (p >= 140)
- return p;
- }
- return p;
-}
-
-/*--- packsms16: takes a binary header (udhl bytes at udh) and UCS-2
- message (udl characters at ud) and packs in to o using 16 bit
- UCS-2 character codes
- The return value is the number of bytes packed in to o, which is
- internally limited to 140
- o can be null, in which case this is used to validate or count
- only if the input contains invalid characters then
- the return value is -1 */
-static int packsms16 (unsigned char *o, int udhl, unsigned char *udh, int udl, unsigned short *ud)
-{
- unsigned char p = 0;
- /* header - no encoding */
- if (udhl) {
- if (o)
- o[p++] = udhl;
- while (udhl--) {
- if (o)
- o[p++] = *udh++;
- if (p >= 140)
- return p;
- }
- }
- while (udl--) {
- long u;
- u = *ud++;
- if (o)
- o[p++] = (u >> 8);
- if (p >= 140)
- return p - 1; /* could not fit last character */
- if (o)
- o[p++] = u;
- if (p >= 140)
- return p;
- }
- return p;
-}
-
-/*--- packsms: general pack, with length and data,
- returns number of bytes of target used */
-static int packsms (unsigned char dcs, unsigned char *base, unsigned int udhl, unsigned char *udh, int udl, unsigned short *ud)
-{
- unsigned char *p = base;
- if (udl) {
- int l = 0;
- if (is7bit (dcs)) { /* 7 bit */
- l = packsms7 (p + 1, udhl, udh, udl, ud);
- if (l < 0)
- l = 0;
- *p++ = l;
- p += (l * 7 + 7) / 8;
- } else if (is8bit (dcs)) { /* 8 bit */
- l = packsms8 (p + 1, udhl, udh, udl, ud);
- if (l < 0)
- l = 0;
- *p++ = l;
- p += l;
- } else { /* UCS-2 */
- l = packsms16 (p + 1, udhl, udh, udl, ud);
- if (l < 0)
- l = 0;
- *p++ = l;
- p += l;
- }
- } else
- *p++ = 0; /* no user data */
- return p - base;
-}
-
-
-/*--- packdate: pack a date and return */
-static void packdate (unsigned char *o, time_t w)
-{
- struct tm *t = localtime (&w);
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__)
- int z = -t->tm_gmtoff / 60 / 15;
-#else
- int z = timezone / 60 / 15;
-#endif
- *o++ = ((t->tm_year % 10) << 4) + (t->tm_year % 100) / 10;
- *o++ = (((t->tm_mon + 1) % 10) << 4) + (t->tm_mon + 1) / 10;
- *o++ = ((t->tm_mday % 10) << 4) + t->tm_mday / 10;
- *o++ = ((t->tm_hour % 10) << 4) + t->tm_hour / 10;
- *o++ = ((t->tm_min % 10) << 4) + t->tm_min / 10;
- *o++ = ((t->tm_sec % 10) << 4) + t->tm_sec / 10;
- if (z < 0)
- *o++ = (((-z) % 10) << 4) + (-z) / 10 + 0x08;
- else
- *o++ = ((z % 10) << 4) + z / 10;
-}
-
-/*--- unpackdate: unpack a date and return */
-static time_t unpackdate (unsigned char *i)
-{
- struct tm t;
- t.tm_year = 100 + (i[0] & 0xF) * 10 + (i[0] >> 4);
- t.tm_mon = (i[1] & 0xF) * 10 + (i[1] >> 4) - 1;
- t.tm_mday = (i[2] & 0xF) * 10 + (i[2] >> 4);
- t.tm_hour = (i[3] & 0xF) * 10 + (i[3] >> 4);
- t.tm_min = (i[4] & 0xF) * 10 + (i[4] >> 4);
- t.tm_sec = (i[5] & 0xF) * 10 + (i[5] >> 4);
- t.tm_isdst = 0;
- if (i[6] & 0x08)
- t.tm_min += 15 * ((i[6] & 0x7) * 10 + (i[6] >> 4));
- else
- t.tm_min -= 15 * ((i[6] & 0x7) * 10 + (i[6] >> 4));
- return mktime (&t);
-}
-
-/*--- unpacksms7: unpacks bytes (7 bit encoding) at i, len l septets,
- and places in udh and ud setting udhl and udl. udh not used
- if udhi not set */
-static void unpacksms7 (unsigned char *i, unsigned char l, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
-{
- unsigned char b = 0, p = 0;
- unsigned short *o = ud;
- *udhl = 0;
- if (udhi && l) { /* header */
- int h = i[p];
- *udhl = h;
- if (h) {
- b = 1;
- p++;
- l--;
- while (h-- && l) {
- *udh++ = i[p++];
- b += 8;
- while (b >= 7) {
- b -= 7;
- l--;
- if (!l)
- break;
- }
- }
- /* adjust for fill, septets */
- if (b) {
- b = 7 - b;
- l--;
- }
- }
- }
- while (l--) {
- unsigned char v;
- if (b < 2)
- v = ((i[p] >> b) & 0x7F);
- else
- v = ((((i[p] >> b) + (i[p + 1] << (8 - b)))) & 0x7F);
- b += 7;
- if (b >= 8) {
- b -= 8;
- p++;
- }
- if (o > ud && o[-1] == 0x00A0 && escapes[v])
- o[-1] = escapes[v];
- else
- *o++ = defaultalphabet[v];
- }
- *udl = (o - ud);
-}
-
-/*--- unpacksms8: unpacks bytes (8 bit encoding) at i, len l septets,
- and places in udh and ud setting udhl and udl. udh not used
- if udhi not set */
-static void unpacksms8 (unsigned char *i, unsigned char l, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
-{
- unsigned short *o = ud;
- *udhl = 0;
- if (udhi) {
- int n = *i;
- *udhl = n;
- if (n) {
- i++;
- l--;
- while (l && n) {
- l--;
- n--;
- *udh++ = *i++;
- }
- }
- }
- while (l--)
- *o++ = *i++; /* not to UTF-8 as explicitely 8 bit coding in DCS */
- *udl = (o - ud);
-}
-
-/*--- unpacksms16: unpacks bytes (16 bit encoding) at i, len l septets,
- and places in udh and ud setting udhl and udl.
- udh not used if udhi not set */
-static void unpacksms16 (unsigned char *i, unsigned char l, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
-{
- unsigned short *o = ud;
- *udhl = 0;
- if (udhi) {
- int n = *i;
- *udhl = n;
- if (n) {
- i++;
- l--;
- while (l && n) {
- l--;
- n--;
- *udh++ = *i++;
- }
- }
- }
- while (l--) {
- int v = *i++;
- if (l--)
- v = (v << 8) + *i++;
- *o++ = v;
- }
- *udl = (o - ud);
-}
-
-/*--- unpacksms: general unpack - starts with length byte (octet or septet) and returns number of bytes used, inc length */
-static int unpacksms (unsigned char dcs, unsigned char *i, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
-{
- int l = *i++;
- if (is7bit (dcs)) {
- unpacksms7 (i, l, udh, udhl, ud, udl, udhi);
- l = (l * 7 + 7) / 8; /* adjust length to return */
- } else if (is8bit (dcs))
- unpacksms8 (i, l, udh, udhl, ud, udl, udhi);
- else
- unpacksms16 (i, l, udh, udhl, ud, udl, udhi);
- return l + 1;
-}
-
-/*--- unpackaddress: unpack an address from i, return byte length, unpack to o */
-static unsigned char unpackaddress (char *o, unsigned char *i)
-{
- unsigned char l = i[0],
- p;
- if (i[1] == 0x91)
- *o++ = '+';
- for (p = 0; p < l; p++) {
- if (p & 1)
- *o++ = (i[2 + p / 2] >> 4) + '0';
- else
- *o++ = (i[2 + p / 2] & 0xF) + '0';
- }
- *o = 0;
- return (l + 5) / 2;
-}
-
-/*--- packaddress: store an address at o, and return number of bytes used */
-static unsigned char packaddress (unsigned char *o, char *i)
-{
- unsigned char p = 2;
- o[0] = 0;
- if (*i == '+') {
- i++;
- o[1] = 0x91;
- } else
- o[1] = 0x81;
- while (*i)
- if (isdigit (*i)) {
- if (o[0] & 1)
- o[p++] |= ((*i & 0xF) << 4);
- else
- o[p] = (*i & 0xF);
- o[0]++;
- i++;
- } else
- i++;
- if (o[0] & 1)
- o[p++] |= 0xF0; /* pad */
- return p;
-}
-
-/*--- sms_log: Log the output, and remove file */
-static void sms_log (sms_t * h, char status)
-{
- if (*h->oa || *h->da) {
- int o = open (log_file, O_CREAT | O_APPEND | O_WRONLY, 0666);
- if (o >= 0) {
- char line[1000], mrs[3] = "", *p;
- unsigned char n;
-
- if (h->mr >= 0)
- snprintf (mrs, sizeof (mrs), "%02X", h->mr);
- snprintf (line, sizeof (line), "%s %c%c%c%s %s %s %s ",
- isodate (time (0)), status, h->rx ? 'I' : 'O', h->smsc ? 'S' : 'M', mrs, h->queue, *h->oa ? h->oa : "-",
- *h->da ? h->da : "-");
- p = line + strlen (line);
- for (n = 0; n < h->udl; n++)
- if (h->ud[n] == '\\') {
- *p++ = '\\';
- *p++ = '\\';
- } else if (h->ud[n] == '\n') {
- *p++ = '\\';
- *p++ = 'n';
- } else if (h->ud[n] == '\r') {
- *p++ = '\\';
- *p++ = 'r';
- } else if (h->ud[n] < 32 || h->ud[n] == 127)
- *p++ = 191;
- else
- *p++ = h->ud[n];
- *p++ = '\n';
- *p = 0;
- write (o, line, strlen (line));
- close (o);
- }
- *h->oa = *h->da = h->udl = 0;
- }
-}
-
-/*--- sms_readfile: parse and delete a file */
-static void sms_readfile (sms_t * h, char *fn)
-{
- char line[1000];
- FILE *s;
- char dcsset = 0; /* if DSC set */
- ast_log (LOG_EVENT, "Sending %s\n", fn);
- h->rx = h->udl = *h->oa = *h->da = h->pid = h->srr = h->udhi = h->rp = h->vp = h->udhl = 0;
- h->mr = -1;
- h->dcs = 0xF1; /* normal messages class 1 */
- h->scts = time (0);
- s = fopen (fn, "r");
- if (s)
- {
- if (unlink (fn))
- { /* concurrent access, we lost */
- fclose (s);
- return;
- }
- while (fgets (line, sizeof (line), s))
- { /* process line in file */
- unsigned char *p;
- for (p = line; *p && *p != '\n' && *p != '\r'; p++);
- *p = 0; /* strip eoln */
- p = line;
- if (!*p || *p == ';')
- continue; /* blank line or comment, ignore */
- while (isalnum (*p))
- {
- *p = tolower (*p);
- p++;
- }
- while (isspace (*p))
- *p++ = 0;
- if (*p == '=')
- {
- *p++ = 0;
- if (!strcmp (line, "ud"))
- { /* parse message (UTF-8) */
- unsigned char o = 0;
- while (*p && o < SMSLEN)
- h->ud[o++] = utf8decode((unsigned char **)&p);
- h->udl = o;
- if (*p)
- ast_log (LOG_WARNING, "UD too long in %s\n", fn);
- } else
- {
- while (isspace (*p))
- p++;
- if (!strcmp (line, "oa") && strlen (p) < sizeof (h->oa))
- numcpy (h->oa, p);
- else if (!strcmp (line, "da") && strlen (p) < sizeof (h->oa))
- numcpy (h->da, p);
- else if (!strcmp (line, "pid"))
- h->pid = atoi (p);
- else if (!strcmp (line, "dcs"))
- {
- h->dcs = atoi (p);
- dcsset = 1;
- } else if (!strcmp (line, "mr"))
- h->mr = atoi (p);
- else if (!strcmp (line, "srr"))
- h->srr = (atoi (p) ? 1 : 0);
- else if (!strcmp (line, "vp"))
- h->vp = atoi (p);
- else if (!strcmp (line, "rp"))
- h->rp = (atoi (p) ? 1 : 0);
- else if (!strcmp (line, "scts"))
- { /* get date/time */
- int Y,
- m,
- d,
- H,
- M,
- S;
- if (sscanf (p, "%d-%d-%dT%d:%d:%d", &Y, &m, &d, &H, &M, &S) == 6)
- {
- struct tm t;
- t.tm_year = Y - 1900;
- t.tm_mon = m - 1;
- t.tm_mday = d;
- t.tm_hour = H;
- t.tm_min = M;
- t.tm_sec = S;
- t.tm_isdst = -1;
- h->scts = mktime (&t);
- if (h->scts == (time_t) - 1)
- ast_log (LOG_WARNING, "Bad date/timein %s: %s", fn, p);
- }
- } else
- ast_log (LOG_WARNING, "Cannot parse in %s: %s=%si\n", fn, line, p);
- }
- } else if (*p == '#')
- { /* raw hex format */
- *p++ = 0;
- if (*p == '#')
- {
- p++;
- if (!strcmp (line, "ud"))
- { /* user data */
- int o = 0;
- while (*p && o < SMSLEN)
- {
- if (isxdigit (*p) && isxdigit (p[1]) && isxdigit (p[2]) && isxdigit (p[3]))
- {
- h->ud[o++] =
- (((isalpha (*p) ? 9 : 0) + (*p & 0xF)) << 12) +
- (((isalpha (p[1]) ? 9 : 0) + (p[1] & 0xF)) << 8) +
- (((isalpha (p[2]) ? 9 : 0) + (p[2] & 0xF)) << 4) + ((isalpha (p[3]) ? 9 : 0) + (p[3] & 0xF));
- p += 4;
- } else
- break;
- }
- h->udl = o;
- if (*p)
- ast_log (LOG_WARNING, "UD too long / invalid UCS-2 hex in %s\n", fn);
- } else
- ast_log (LOG_WARNING, "Only ud can use ## format, %s\n", fn);
- } else if (!strcmp (line, "ud"))
- { /* user data */
- int o = 0;
- while (*p && o < SMSLEN)
- {
- if (isxdigit (*p) && isxdigit (p[1]))
- {
- h->ud[o++] = (((isalpha (*p) ? 9 : 0) + (*p & 0xF)) << 4) + ((isalpha (p[1]) ? 9 : 0) + (p[1] & 0xF));
- p += 2;
- } else
- break;
- }
- h->udl = o;
- if (*p)
- ast_log (LOG_WARNING, "UD too long / invalid UCS-1 hex in %s\n", fn);
- } else if (!strcmp (line, "udh"))
- { /* user data header */
- unsigned char o = 0;
- h->udhi = 1;
- while (*p && o < SMSLEN)
- {
- if (isxdigit (*p) && isxdigit (p[1]))
- {
- h->udh[o] = (((isalpha (*p) ? 9 : 0) + (*p & 0xF)) << 4) + ((isalpha (p[1]) ? 9 : 0) + (p[1] & 0xF));
- o++;
- p += 2;
- } else
- break;
- }
- h->udhl = o;
- if (*p)
- ast_log (LOG_WARNING, "UDH too long / invalid hex in %s\n", fn);
- } else
- ast_log (LOG_WARNING, "Only ud and udh can use # format, %s\n", fn);
- } else
- ast_log (LOG_WARNING, "Cannot parse in %s: %s\n", fn, line);
- }
- fclose (s);
- if (!dcsset && packsms7 (0, h->udhl, h->udh, h->udl, h->ud) < 0)
- {
- if (packsms8 (0, h->udhl, h->udh, h->udl, h->ud) < 0)
- {
- if (packsms16 (0, h->udhl, h->udh, h->udl, h->ud) < 0)
- ast_log (LOG_WARNING, "Invalid UTF-8 message even for UCS-2 (%s)\n", fn);
- else
- {
- h->dcs = 0x08; /* default to 16 bit */
- ast_log (LOG_WARNING, "Sending in 16 bit format (%s)\n", fn);
- }
- } else
- {
- h->dcs = 0xF5; /* default to 8 bit */
- ast_log (LOG_WARNING, "Sending in 8 bit format (%s)\n", fn);
- }
- }
- if (is7bit (h->dcs) && packsms7 (0, h->udhl, h->udh, h->udl, h->ud) < 0)
- ast_log (LOG_WARNING, "Invalid 7 bit GSM data %s\n", fn);
- if (is8bit (h->dcs) && packsms8 (0, h->udhl, h->udh, h->udl, h->ud) < 0)
- ast_log (LOG_WARNING, "Invalid 8 bit data %s\n", fn);
- if (is16bit (h->dcs) && packsms16 (0, h->udhl, h->udh, h->udl, h->ud) < 0)
- ast_log (LOG_WARNING, "Invalid 16 bit data %s\n", fn);
- }
-}
-
-/*--- sms_writefile: white a received text message to a file */
-static void sms_writefile (sms_t * h)
-{
- char fn[200] = "", fn2[200] = "";
- FILE *o;
- ast_copy_string (fn, spool_dir, sizeof (fn));
- mkdir (fn, 0777); /* ensure it exists */
- snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/%s", h->smsc ? h->rx ? "morx" : "mttx" : h->rx ? "mtrx" : "motx");
- mkdir (fn, 0777); /* ensure it exists */
- ast_copy_string (fn2, fn, sizeof (fn2));
- snprintf (fn2 + strlen (fn2), sizeof (fn2) - strlen (fn2), "/%s.%s-%d", h->queue, isodate (h->scts), seq++);
- snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/.%s", fn2 + strlen (fn) + 1);
- o = fopen (fn, "w");
- if (o) {
- if (*h->oa)
- fprintf (o, "oa=%s\n", h->oa);
- if (*h->da)
- fprintf (o, "da=%s\n", h->da);
- if (h->udhi) {
- unsigned int p;
- fprintf (o, "udh#");
- for (p = 0; p < h->udhl; p++)
- fprintf (o, "%02X", h->udh[p]);
- fprintf (o, "\n");
- }
- if (h->udl) {
- unsigned int p;
- for (p = 0; p < h->udl && h->ud[p] >= ' '; p++);
- if (p < h->udl)
- fputc (';', o); /* cannot use ud=, but include as a comment for human readable */
- fprintf (o, "ud=");
- for (p = 0; p < h->udl; p++) {
- unsigned short v = h->ud[p];
- if (v < 32)
- fputc (191, o);
- else if (v < 0x80)
- fputc (v, o);
- else if (v < 0x800)
- {
- fputc (0xC0 + (v >> 6), o);
- fputc (0x80 + (v & 0x3F), o);
- } else
- {
- fputc (0xE0 + (v >> 12), o);
- fputc (0x80 + ((v >> 6) & 0x3F), o);
- fputc (0x80 + (v & 0x3F), o);
- }
- }
- fprintf (o, "\n");
- for (p = 0; p < h->udl && h->ud[p] >= ' '; p++);
- if (p < h->udl) {
- for (p = 0; p < h->udl && h->ud[p] < 0x100; p++);
- if (p == h->udl) { /* can write in ucs-1 hex */
- fprintf (o, "ud#");
- for (p = 0; p < h->udl; p++)
- fprintf (o, "%02X", h->ud[p]);
- fprintf (o, "\n");
- } else { /* write in UCS-2 */
- fprintf (o, "ud##");
- for (p = 0; p < h->udl; p++)
- fprintf (o, "%04X", h->ud[p]);
- fprintf (o, "\n");
- }
- }
- }
- if (h->scts)
- fprintf (o, "scts=%s\n", isodate (h->scts));
- if (h->pid)
- fprintf (o, "pid=%d\n", h->pid);
- if (h->dcs != 0xF1)
- fprintf (o, "dcs=%d\n", h->dcs);
- if (h->vp)
- fprintf (o, "vp=%d\n", h->vp);
- if (h->srr)
- fprintf (o, "srr=1\n");
- if (h->mr >= 0)
- fprintf (o, "mr=%d\n", h->mr);
- if (h->rp)
- fprintf (o, "rp=1\n");
- fclose (o);
- if (rename (fn, fn2))
- unlink (fn);
- else
- ast_log (LOG_EVENT, "Received to %s\n", fn2);
- }
-}
-
-/*--- readdirqueue: read dir skipping dot files... */
-static struct dirent *readdirqueue (DIR * d, char *queue)
-{
- struct dirent *f;
- do {
- f = readdir (d);
- } while (f && (*f->d_name == '.' || strncmp (f->d_name, queue, strlen (queue)) || f->d_name[strlen (queue)] != '.'));
- return f;
-}
-
-/*--- sms_handleincoming: handle the incoming message */
-static unsigned char sms_handleincoming (sms_t * h)
-{
- unsigned char p = 3;
- if (h->smsc) { /* SMSC */
- if ((h->imsg[2] & 3) == 1) { /* SMS-SUBMIT */
- h->udhl = h->udl = 0;
- h->vp = 0;
- h->srr = ((h->imsg[2] & 0x20) ? 1 : 0);
- h->udhi = ((h->imsg[2] & 0x40) ? 1 : 0);
- h->rp = ((h->imsg[2] & 0x80) ? 1 : 0);
- ast_copy_string (h->oa, h->cli, sizeof (h->oa));
- h->scts = time (0);
- h->mr = h->imsg[p++];
- p += unpackaddress (h->da, h->imsg + p);
- h->pid = h->imsg[p++];
- h->dcs = h->imsg[p++];
- if ((h->imsg[2] & 0x18) == 0x10) { /* relative VP */
- if (h->imsg[p] < 144)
- h->vp = (h->imsg[p] + 1) * 5;
- else if (h->imsg[p] < 168)
- h->vp = 720 + (h->imsg[p] - 143) * 30;
- else if (h->imsg[p] < 197)
- h->vp = (h->imsg[p] - 166) * 1440;
- else
- h->vp = (h->imsg[p] - 192) * 10080;
- p++;
- } else if (h->imsg[2] & 0x18)
- p += 7; /* ignore enhanced / absolute VP */
- p += unpacksms (h->dcs, h->imsg + p, h->udh, &h->udhl, h->ud, &h->udl, h->udhi);
- h->rx = 1; /* received message */
- sms_writefile (h); /* write the file */
- if (p != h->imsg[1] + 2) {
- ast_log (LOG_WARNING, "Mismatch receive unpacking %d/%d\n", p, h->imsg[1] + 2);
- return 0xFF; /* duh! */
- }
- } else {
- ast_log (LOG_WARNING, "Unknown message type %02X\n", h->imsg[2]);
- return 0xFF;
- }
- } else { /* client */
- if (!(h->imsg[2] & 3)) { /* SMS-DELIVER */
- *h->da = h->srr = h->rp = h->vp = h->udhi = h->udhl = h->udl = 0;
- h->srr = ((h->imsg[2] & 0x20) ? 1 : 0);
- h->udhi = ((h->imsg[2] & 0x40) ? 1 : 0);
- h->rp = ((h->imsg[2] & 0x80) ? 1 : 0);
- h->mr = -1;
- p += unpackaddress (h->oa, h->imsg + p);
- h->pid = h->imsg[p++];
- h->dcs = h->imsg[p++];
- h->scts = unpackdate (h->imsg + p);
- p += 7;
- p += unpacksms (h->dcs, h->imsg + p, h->udh, &h->udhl, h->ud, &h->udl, h->udhi);
- h->rx = 1; /* received message */
- sms_writefile (h); /* write the file */
- if (p != h->imsg[1] + 2) {
- ast_log (LOG_WARNING, "Mismatch receive unpacking %d/%d\n", p, h->imsg[1] + 2);
- return 0xFF; /* duh! */
- }
- } else {
- ast_log (LOG_WARNING, "Unknown message type %02X\n", h->imsg[2]);
- return 0xFF;
- }
- }
- return 0; /* no error */
-}
-
-#ifdef SOLARIS
-#define NAME_MAX 1024
-#endif
-
-/*--- sms_nextoutgoing: find and fill in next message,
- or send a REL if none waiting */
-static void sms_nextoutgoing (sms_t * h)
-{
- char fn[100 + NAME_MAX] = "";
- DIR *d;
- char more = 0;
- ast_copy_string (fn, spool_dir, sizeof (fn));
- mkdir (fn, 0777); /* ensure it exists */
- h->rx = 0; /* outgoing message */
- snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/%s", h->smsc ? "mttx" : "motx");
- mkdir (fn, 0777); /* ensure it exists */
- d = opendir (fn);
- if (d) {
- struct dirent *f = readdirqueue (d, h->queue);
- if (f) {
- snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/%s", f->d_name);
- sms_readfile (h, fn);
- if (readdirqueue (d, h->queue))
- more = 1; /* more to send */
- }
- closedir (d);
- }
- if (*h->da || *h->oa) { /* message to send */
- unsigned char p = 2;
- h->omsg[0] = 0x91; /* SMS_DATA */
- if (h->smsc) { /* deliver */
- h->omsg[p++] = (more ? 4 : 0);
- p += packaddress (h->omsg + p, h->oa);
- h->omsg[p++] = h->pid;
- h->omsg[p++] = h->dcs;
- packdate (h->omsg + p, h->scts);
- p += 7;
- p += packsms (h->dcs, h->omsg + p, h->udhl, h->udh, h->udl, h->ud);
- } else { /* submit */
- h->omsg[p++] =
- 0x01 + (more ? 4 : 0) + (h->srr ? 0x20 : 0) + (h->rp ? 0x80 : 0) + (h->vp ? 0x10 : 0) + (h->udhi ? 0x40 : 0);
- if (h->mr < 0)
- h->mr = message_ref++;
- h->omsg[p++] = h->mr;
- p += packaddress (h->omsg + p, h->da);
- h->omsg[p++] = h->pid;
- h->omsg[p++] = h->dcs;
- if (h->vp) { /* relative VP */
- if (h->vp < 720)
- h->omsg[p++] = (h->vp + 4) / 5 - 1;
- else if (h->vp < 1440)
- h->omsg[p++] = (h->vp - 720 + 29) / 30 + 143;
- else if (h->vp < 43200)
- h->omsg[p++] = (h->vp + 1439) / 1440 + 166;
- else if (h->vp < 635040)
- h->omsg[p++] = (h->vp + 10079) / 10080 + 192;
- else
- h->omsg[p++] = 255; /* max */
- }
- p += packsms (h->dcs, h->omsg + p, h->udhl, h->udh, h->udl, h->ud);
- }
- h->omsg[1] = p - 2;
- sms_messagetx (h);
- } else { /* no message */
- h->omsg[0] = 0x94; /* SMS_REL */
- h->omsg[1] = 0;
- sms_messagetx (h);
- }
-}
-
-static void sms_debug (char *dir, unsigned char *msg)
-{
- char txt[259 * 3 + 1],
- *p = txt; /* always long enough */
- int n = msg[1] + 3,
- q = 0;
- while (q < n && q < 30) {
- sprintf (p, " %02X", msg[q++]);
- p += 3;
- }
- if (q < n)
- sprintf (p, "...");
- if (option_verbose > 2)
- ast_verbose (VERBOSE_PREFIX_3 "SMS %s%s\n", dir, txt);
-}
-
-static void sms_messagerx(sms_t * h)
-{
- sms_debug ("RX", h->imsg);
- /* testing */
- switch (h->imsg[0]) {
- case 0x91: /* SMS_DATA */
- {
- unsigned char cause = sms_handleincoming (h);
- if (!cause) {
- sms_log (h, 'Y');
- h->omsg[0] = 0x95; /* SMS_ACK */
- h->omsg[1] = 0x02;
- h->omsg[2] = 0x00; /* deliver report */
- h->omsg[3] = 0x00; /* no parameters */
- } else { /* NACK */
- sms_log (h, 'N');
- h->omsg[0] = 0x96; /* SMS_NACK */
- h->omsg[1] = 3;
- h->omsg[2] = 0; /* delivery report */
- h->omsg[3] = cause; /* cause */
- h->omsg[4] = 0; /* no parameters */
- }
- sms_messagetx (h);
- }
- break;
- case 0x92: /* SMS_ERROR */
- h->err = 1;
- sms_messagetx (h); /* send whatever we sent again */
- break;
- case 0x93: /* SMS_EST */
- sms_nextoutgoing (h);
- break;
- case 0x94: /* SMS_REL */
- h->hangup = 1; /* hangup */
- break;
- case 0x95: /* SMS_ACK */
- sms_log (h, 'Y');
- sms_nextoutgoing (h);
- break;
- case 0x96: /* SMS_NACK */
- h->err = 1;
- sms_log (h, 'N');
- sms_nextoutgoing (h);
- break;
- default: /* Unknown */
- h->omsg[0] = 0x92; /* SMS_ERROR */
- h->omsg[1] = 1;
- h->omsg[2] = 3; /* unknown message type; */
- sms_messagetx (h);
- break;
- }
-}
-
-static void sms_messagetx(sms_t * h)
-{
- unsigned char c = 0, p;
- for (p = 0; p < h->omsg[1] + 2; p++)
- c += h->omsg[p];
- h->omsg[h->omsg[1] + 2] = 0 - c;
- sms_debug ("TX", h->omsg);
- h->obyte = 1;
- h->opause = 200;
- if (h->omsg[0] == 0x93)
- h->opause = 2400; /* initial message delay 300ms (for BT) */
- h->obytep = 0;
- h->obitp = 0;
- h->osync = 80;
- h->obyten = h->omsg[1] + 3;
-}
-
-static int sms_generate (struct ast_channel *chan, void *data, int len, int samples)
-{
- struct ast_frame f = { 0 };
- unsigned char waste[AST_FRIENDLY_OFFSET];
-#ifdef OUTALAW
- unsigned char buf[800];
-#else
- signed short buf[800];
-#endif
- sms_t *h = data;
- int i;
-
- if (len > sizeof (buf)) {
- ast_log (LOG_WARNING, "Only doing %d bytes (%d bytes requested)\n", (int)(sizeof (buf) / sizeof (signed short)), len);
- len = sizeof (buf);
-#ifdef OUTALAW
- samples = len;
-#else
- samples = len / 2;
-#endif
- }
- waste[0] = 0; /* make compiler happy */
- f.frametype = AST_FRAME_VOICE;
-#ifdef OUTALAW
- f.subclass = AST_FORMAT_ALAW;
- f.datalen = samples;
-#else
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = samples * 2;
-#endif
- f.offset = AST_FRIENDLY_OFFSET;
- f.mallocd = 0;
- f.data = buf;
- f.samples = samples;
- f.src = "app_sms";
- /* create a buffer containing the digital sms pattern */
- for (i = 0; i < samples; i++) {
-#ifdef OUTALAW
- buf[i] = wavea[0];
-#else
- buf[i] = wave[0];
-#endif
- if (h->opause)
- h->opause--;
- else if (h->obyten || h->osync) { /* sending data */
-#ifdef OUTALAW
- buf[i] = wavea[h->ophase];
-#else
- buf[i] = wave[h->ophase];
-#endif
- if ((h->ophase += ((h->obyte & 1) ? 13 : 21)) >= 80)
- h->ophase -= 80;
- if ((h->ophasep += 12) >= 80) { /* next bit */
- h->ophasep -= 80;
- if (h->osync)
- h->osync--; /* sending sync bits */
- else {
- h->obyte >>= 1;
- h->obitp++;
- if (h->obitp == 1)
- h->obyte = 0; /* start bit; */
- else if (h->obitp == 2)
- h->obyte = h->omsg[h->obytep];
- else if (h->obitp == 10) {
- h->obyte = 1; /* stop bit */
- h->obitp = 0;
- h->obytep++;
- if (h->obytep == h->obyten) {
- h->obytep = h->obyten = 0; /* sent */
- h->osync = 10; /* trailing marks */
- }
- }
- }
- }
- }
- }
- if (ast_write (chan, &f) < 0) {
- ast_log (LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror (errno));
- return -1;
- }
- return 0;
-}
-
-static void sms_process (sms_t * h, int samples, signed short *data)
-{
- if (h->obyten || h->osync)
- return; /* sending */
- while (samples--) {
- unsigned long long m0, m1;
- if (abs (*data) > h->imag)
- h->imag = abs (*data);
- else
- h->imag = h->imag * 7 / 8;
- if (h->imag > 500) {
- h->idle = 0;
- h->ims0 = (h->ims0 * 6 + *data * wave[h->ips0]) / 7;
- h->imc0 = (h->imc0 * 6 + *data * wave[h->ipc0]) / 7;
- h->ims1 = (h->ims1 * 6 + *data * wave[h->ips1]) / 7;
- h->imc1 = (h->imc1 * 6 + *data * wave[h->ipc1]) / 7;
- m0 = h->ims0 * h->ims0 + h->imc0 * h->imc0;
- m1 = h->ims1 * h->ims1 + h->imc1 * h->imc1;
- if ((h->ips0 += 21) >= 80)
- h->ips0 -= 80;
- if ((h->ipc0 += 21) >= 80)
- h->ipc0 -= 80;
- if ((h->ips1 += 13) >= 80)
- h->ips1 -= 80;
- if ((h->ipc1 += 13) >= 80)
- h->ipc1 -= 80;
- {
- char bit;
- h->ibith <<= 1;
- if (m1 > m0)
- h->ibith |= 1;
- if (h->ibith & 8)
- h->ibitt--;
- if (h->ibith & 1)
- h->ibitt++;
- bit = ((h->ibitt > 1) ? 1 : 0);
- if (bit != h->ibitl)
- h->ibitc = 1;
- else
- h->ibitc++;
- h->ibitl = bit;
- if (!h->ibitn && h->ibitc == 4 && !bit) {
- h->ibitn = 1;
- h->iphasep = 0;
- }
- if (bit && h->ibitc == 200) { /* sync, restart message */
- h->ierr = h->ibitn = h->ibytep = h->ibytec = 0;
- }
- if (h->ibitn) {
- h->iphasep += 12;
- if (h->iphasep >= 80) { /* next bit */
- h->iphasep -= 80;
- if (h->ibitn++ == 9) { /* end of byte */
- if (!bit) /* bad stop bit */
- h->ierr = 0xFF; /* unknown error */
- else {
- if (h->ibytep < sizeof (h->imsg)) {
- h->imsg[h->ibytep] = h->ibytev;
- h->ibytec += h->ibytev;
- h->ibytep++;
- } else if (h->ibytep == sizeof (h->imsg))
- h->ierr = 2; /* bad message length */
- if (h->ibytep > 1 && h->ibytep == 3 + h->imsg[1] && !h->ierr) {
- if (!h->ibytec)
- sms_messagerx (h);
- else
- h->ierr = 1; /* bad checksum */
- }
- }
- h->ibitn = 0;
- }
- h->ibytev = (h->ibytev >> 1) + (bit ? 0x80 : 0);
- }
- }
- }
- } else { /* lost carrier */
- if (h->idle++ == 80000) { /* nothing happening */
- ast_log (LOG_EVENT, "No data, hanging up\n");
- h->hangup = 1;
- h->err = 1;
- }
- if (h->ierr) { /* error */
- h->err = 1;
- h->omsg[0] = 0x92; /* error */
- h->omsg[1] = 1;
- h->omsg[2] = h->ierr;
- sms_messagetx (h); /* send error */
- }
- h->ierr = h->ibitn = h->ibytep = h->ibytec = 0;
- }
- data++;
- }
-}
-
-static struct ast_generator smsgen = {
- alloc:sms_alloc,
- release:sms_release,
- generate:sms_generate,
-};
-
-static int sms_exec (struct ast_channel *chan, void *data)
-{
- int res = -1;
- struct localuser *u;
- struct ast_frame *f;
- sms_t h = { 0 };
-
- LOCAL_USER_ADD(u);
-
- h.ipc0 = h.ipc1 = 20; /* phase for cosine */
- h.dcs = 0xF1; /* default */
- if (!data) {
- ast_log (LOG_ERROR, "Requires queue name at least\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if (chan->cid.cid_num)
- ast_copy_string (h.cli, chan->cid.cid_num, sizeof (h.cli));
-
- {
- unsigned char *p;
- unsigned char *d = data,
- answer = 0;
- if (!*d || *d == '|') {
- ast_log (LOG_ERROR, "Requires queue name\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- for (p = d; *p && *p != '|'; p++);
- if (p - d >= sizeof (h.queue)) {
- ast_log (LOG_ERROR, "Queue name too long\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- strncpy (h.queue, d, p - d);
- if (*p == '|')
- p++;
- d = p;
- for (p = h.queue; *p; p++)
- if (!isalnum (*p))
- *p = '-'; /* make very safe for filenames */
- while (*d && *d != '|') {
- switch (*d) {
- case 'a': /* we have to send the initial FSK sequence */
- answer = 1;
- break;
- case 's': /* we are acting as a service centre talking to a phone */
- h.smsc = 1;
- break;
- /* the following apply if there is an arg3/4 and apply to the created message file */
- case 'r':
- h.srr = 1;
- break;
- case 'o':
- h.dcs |= 4; /* octets */
- break;
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7': /* set the pid for saved local message */
- h.pid = 0x40 + (*d & 0xF);
- break;
- }
- d++;
- }
- if (*d == '|') {
- /* submitting a message, not taking call. */
- /* depricated, use smsq instead */
- d++;
- h.scts = time (0);
- for (p = d; *p && *p != '|'; p++);
- if (*p)
- *p++ = 0;
- if (strlen (d) >= sizeof (h.oa)) {
- ast_log (LOG_ERROR, "Address too long %s\n", d);
- return 0;
- }
- if (h.smsc) {
- ast_copy_string (h.oa, d, sizeof (h.oa));
- } else {
- ast_copy_string (h.da, d, sizeof (h.da));
- }
- if (!h.smsc)
- ast_copy_string (h.oa, h.cli, sizeof (h.oa));
- d = p;
- h.udl = 0;
- while (*p && h.udl < SMSLEN)
- h.ud[h.udl++] = utf8decode(&p);
- if (is7bit (h.dcs) && packsms7 (0, h.udhl, h.udh, h.udl, h.ud) < 0)
- ast_log (LOG_WARNING, "Invalid 7 bit GSM data\n");
- if (is8bit (h.dcs) && packsms8 (0, h.udhl, h.udh, h.udl, h.ud) < 0)
- ast_log (LOG_WARNING, "Invalid 8 bit data\n");
- if (is16bit (h.dcs) && packsms16 (0, h.udhl, h.udh, h.udl, h.ud) < 0)
- ast_log (LOG_WARNING, "Invalid 16 bit data\n");
- h.rx = 0; /* sent message */
- h.mr = -1;
- sms_writefile (&h);
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- if (answer) {
- /* set up SMS_EST initial message */
- h.omsg[0] = 0x93;
- h.omsg[1] = 0;
- sms_messagetx (&h);
- }
- }
-
- if (chan->_state != AST_STATE_UP)
- ast_answer (chan);
-
-#ifdef OUTALAW
- res = ast_set_write_format (chan, AST_FORMAT_ALAW);
-#else
- res = ast_set_write_format (chan, AST_FORMAT_SLINEAR);
-#endif
- if (res >= 0)
- res = ast_set_read_format (chan, AST_FORMAT_SLINEAR);
- if (res < 0) {
- ast_log (LOG_ERROR, "Unable to set to linear mode, giving up\n");
- LOCAL_USER_REMOVE (u);
- return -1;
- }
-
- if (ast_activate_generator (chan, &smsgen, &h) < 0) {
- ast_log (LOG_ERROR, "Failed to activate generator on '%s'\n", chan->name);
- LOCAL_USER_REMOVE (u);
- return -1;
- }
-
- /* Do our thing here */
- while (ast_waitfor (chan, -1) > -1 && !h.hangup)
- {
- f = ast_read (chan);
- if (!f)
- break;
- if (f->frametype == AST_FRAME_VOICE) {
- sms_process (&h, f->samples, f->data);
- }
-
- ast_frfree (f);
- }
-
- sms_log (&h, '?'); /* log incomplete message */
-
- LOCAL_USER_REMOVE (u);
- return (h.err);
-}
-
-int unload_module (void)
-{
- int res;
-
- res = ast_unregister_application (app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module (void)
-{
-#ifdef OUTALAW
- {
- int p;
- for (p = 0; p < 80; p++)
- wavea[p] = AST_LIN2A (wave[p]);
- }
-#endif
- snprintf (log_file, sizeof (log_file), "%s/sms", ast_config_AST_LOG_DIR);
- snprintf (spool_dir, sizeof (spool_dir), "%s/sms", ast_config_AST_SPOOL_DIR);
- return ast_register_application (app, sms_exec, synopsis, descrip);
-}
-
-char *description (void)
-{
- return tdesc;
-}
-
-int usecount (void)
-{
- int res;
- STANDARD_USECOUNT (res);
- return res;
-}
-
-char *key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_softhangup.c b/1.2-netsec/apps/app_softhangup.c
deleted file mode 100644
index 804a39259..000000000
--- a/1.2-netsec/apps/app_softhangup.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief SoftHangup application
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-
-static char *synopsis = "Soft Hangup Application";
-
-static char *tdesc = "Hangs up the requested channel";
-
-static char *desc = " SoftHangup(Technology/resource|options)\n"
-"Hangs up the requested channel. If there are no channels to hangup,\n"
-"the application will report it.\n"
-"- 'options' may contain the following letter:\n"
-" 'a' : hang up all channels on a specified device instead of a single resource\n";
-
-static char *app = "SoftHangup";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int softhangup_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- struct ast_channel *c=NULL;
- char *options, *cut, *cdata, *match;
- char name[AST_CHANNEL_NAME] = "";
- int all = 0;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
- return 0;
- }
-
- LOCAL_USER_ADD(u);
-
- cdata = ast_strdupa(data);
- match = strsep(&cdata, "|");
- options = strsep(&cdata, "|");
- all = options && strchr(options,'a');
- c = ast_channel_walk_locked(NULL);
- while (c) {
- strncpy(name, c->name, sizeof(name)-1);
- ast_mutex_unlock(&c->lock);
- /* XXX watch out, i think it is wrong to access c-> after unlocking! */
- if (all) {
- /* CAPI is set up like CAPI[foo/bar]/clcnt */
- if (!strcmp(c->type,"CAPI"))
- cut = strrchr(name,'/');
- /* Basically everything else is Foo/Bar-Z */
- else
- cut = strchr(name,'-');
- /* Get rid of what we've cut */
- if (cut)
- *cut = 0;
- }
- if (!strcasecmp(name, match)) {
- ast_log(LOG_WARNING, "Soft hanging %s up.\n",c->name);
- ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
- if(!all)
- break;
- }
- c = ast_channel_walk_locked(c);
- }
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, softhangup_exec, synopsis, desc);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_sql_postgres.c b/1.2-netsec/apps/app_sql_postgres.c
deleted file mode 100644
index d9ba1bfb7..000000000
--- a/1.2-netsec/apps/app_sql_postgres.c
+++ /dev/null
@@ -1,577 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2002, Christos Ricudis
- *
- * Christos Ricudis <ricudis@itc.auth.gr>
- *
- * 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 Connect to PostgreSQL
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/chanvars.h"
-#include "asterisk/lock.h"
-
-#include "libpq-fe.h"
-
-static char *tdesc = "Simple PostgreSQL Interface";
-
-static char *app = "PGSQL";
-
-static char *synopsis = "Do several SQLy things";
-
-static char *descrip =
-"PGSQL(): Do several SQLy things\n"
-"Syntax:\n"
-" PGSQL(Connect var option-string)\n"
-" Connects to a database. Option string contains standard PostgreSQL\n"
-" parameters like host=, dbname=, user=. Connection identifer returned\n"
-" in ${var}\n"
-" PGSQL(Query var ${connection_identifier} query-string)\n"
-" Executes standard SQL query contained in query-string using established\n"
-" connection identified by ${connection_identifier}. Reseult of query is\n"
-" is stored in ${var}.\n"
-" PGSQL(Fetch statusvar ${result_identifier} var1 var2 ... varn)\n"
-" Fetches a single row from a result set contained in ${result_identifier}.\n"
-" Assigns returned fields to ${var1} ... ${varn}. ${statusvar} is set TRUE\n"
-" if additional rows exist in reseult set.\n"
-" PGSQL(Clear ${result_identifier})\n"
-" Frees memory and datastructures associated with result set.\n"
-" PGSQL(Disconnect ${connection_identifier})\n"
-" Disconnects from named connection to PostgreSQL.\n" ;
-
-/*
-
-Syntax of SQL commands :
-
- Connect var option-string
-
- Connects to a database using the option-string and stores the
- connection identifier in ${var}
-
-
- Query var ${connection_identifier} query-string
-
- Submits query-string to database backend and stores the result
- identifier in ${var}
-
-
- Fetch statusvar ${result_identifier} var1 var2 var3 ... varn
-
- Fetches a row from the query and stores end-of-table status in
- ${statusvar} and columns in ${var1}..${varn}
-
-
- Clear ${result_identifier}
-
- Clears data structures associated with ${result_identifier}
-
-
- Disconnect ${connection_identifier}
-
- Disconnects from named connection
-
-
-EXAMPLES OF USE :
-
-exten => s,2,PGSQL(Connect connid host=localhost user=asterisk dbname=credit)
-exten => s,3,PGSQL(Query resultid ${connid} SELECT username,credit FROM credit WHERE callerid=${CALLERIDNUM})
-exten => s,4,PGSQL(Fetch fetchid ${resultid} datavar1 datavar2)
-exten => s,5,GotoIf(${fetchid}?6:8)
-exten => s,6,Festival("User ${datavar1} currently has credit balance of ${datavar2} dollars.")
-exten => s,7,Goto(s,4)
-exten => s,8,PGSQL(Clear ${resultid})
-exten => s,9,PGSQL(Disconnect ${connid})
-
-*/
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-#define AST_PGSQL_ID_DUMMY 0
-#define AST_PGSQL_ID_CONNID 1
-#define AST_PGSQL_ID_RESID 2
-#define AST_PGSQL_ID_FETCHID 3
-
-struct ast_PGSQL_id {
- int identifier_type; /* 0=dummy, 1=connid, 2=resultid */
- int identifier;
- void *data;
- AST_LIST_ENTRY(ast_PGSQL_id) entries;
-} *ast_PGSQL_id;
-
-AST_LIST_HEAD(PGSQLidshead,ast_PGSQL_id) PGSQLidshead;
-
-static void *find_identifier(int identifier,int identifier_type) {
- struct PGSQLidshead *headp;
- struct ast_PGSQL_id *i;
- void *res=NULL;
- int found=0;
-
- headp=&PGSQLidshead;
-
- if (AST_LIST_LOCK(headp)) {
- ast_log(LOG_WARNING,"Unable to lock identifiers list\n");
- } else {
- AST_LIST_TRAVERSE(headp,i,entries) {
- if ((i->identifier==identifier) && (i->identifier_type==identifier_type)) {
- found=1;
- res=i->data;
- break;
- }
- }
- if (!found) {
- ast_log(LOG_WARNING,"Identifier %d, identifier_type %d not found in identifier list\n",identifier,identifier_type);
- }
- AST_LIST_UNLOCK(headp);
- }
-
- return(res);
-}
-
-static int add_identifier(int identifier_type,void *data) {
- struct ast_PGSQL_id *i,*j;
- struct PGSQLidshead *headp;
- int maxidentifier=0;
-
- headp=&PGSQLidshead;
- i=NULL;
- j=NULL;
-
- if (AST_LIST_LOCK(headp)) {
- ast_log(LOG_WARNING,"Unable to lock identifiers list\n");
- return(-1);
- } else {
- i=malloc(sizeof(struct ast_PGSQL_id));
- AST_LIST_TRAVERSE(headp,j,entries) {
- if (j->identifier>maxidentifier) {
- maxidentifier=j->identifier;
- }
- }
-
- i->identifier=maxidentifier+1;
- i->identifier_type=identifier_type;
- i->data=data;
- AST_LIST_INSERT_HEAD(headp,i,entries);
- AST_LIST_UNLOCK(headp);
- }
- return(i->identifier);
-}
-
-static int del_identifier(int identifier,int identifier_type) {
- struct ast_PGSQL_id *i;
- struct PGSQLidshead *headp;
- int found=0;
-
- headp=&PGSQLidshead;
-
- if (AST_LIST_LOCK(headp)) {
- ast_log(LOG_WARNING,"Unable to lock identifiers list\n");
- } else {
- AST_LIST_TRAVERSE(headp,i,entries) {
- if ((i->identifier==identifier) &&
- (i->identifier_type==identifier_type)) {
- AST_LIST_REMOVE(headp,i,entries);
- free(i);
- found=1;
- break;
- }
- }
- AST_LIST_UNLOCK(headp);
- }
-
- if (found==0) {
- ast_log(LOG_WARNING,"Could not find identifier %d, identifier_type %d in list to delete\n",identifier,identifier_type);
- return(-1);
- } else {
- return(0);
- }
-}
-
-static int aPGSQL_connect(struct ast_channel *chan, void *data) {
-
- char *s1;
- char s[100] = "";
- char *optionstring;
- char *var;
- int l;
- int res;
- PGconn *karoto;
- int id;
- char *stringp=NULL;
-
-
- res=0;
- l=strlen(data)+2;
- s1=malloc(l);
- strncpy(s1, data, l -1);
- stringp=s1;
- strsep(&stringp," "); /* eat the first token, we already know it :P */
- var=strsep(&stringp," ");
- optionstring=strsep(&stringp,"\n");
-
- karoto = PQconnectdb(optionstring);
- if (PQstatus(karoto) == CONNECTION_BAD) {
- ast_log(LOG_WARNING,"Connection to database using '%s' failed. postgress reports : %s\n", optionstring,
- PQerrorMessage(karoto));
- res=-1;
- } else {
- ast_log(LOG_WARNING,"adding identifier\n");
- id=add_identifier(AST_PGSQL_ID_CONNID,karoto);
- snprintf(s, sizeof(s), "%d", id);
- pbx_builtin_setvar_helper(chan,var,s);
- }
-
- free(s1);
- return res;
-}
-
-static int aPGSQL_query(struct ast_channel *chan, void *data) {
-
-
- char *s1,*s2,*s3,*s4;
- char s[100] = "";
- char *querystring;
- char *var;
- int l;
- int res,nres;
- PGconn *karoto;
- PGresult *PGSQLres;
- int id,id1;
- char *stringp=NULL;
-
-
- res=0;
- l=strlen(data)+2;
- s1=malloc(l);
- s2=malloc(l);
- strncpy(s1, data, l - 1);
- stringp=s1;
- strsep(&stringp," "); /* eat the first token, we already know it :P */
- s3=strsep(&stringp," ");
- while (1) { /* ugly trick to make branches with break; */
- var=s3;
- s4=strsep(&stringp," ");
- id=atoi(s4);
- querystring=strsep(&stringp,"\n");
- if ((karoto=find_identifier(id,AST_PGSQL_ID_CONNID))==NULL) {
- ast_log(LOG_WARNING,"Invalid connection identifier %d passed in aPGSQL_query\n",id);
- res=-1;
- break;
- }
- PGSQLres=PQexec(karoto,querystring);
- if (PGSQLres==NULL) {
- ast_log(LOG_WARNING,"aPGSQL_query: Connection Error (connection identifier = %d, error message : %s)\n",id,PQerrorMessage(karoto));
- res=-1;
- break;
- }
- if (PQresultStatus(PGSQLres) == PGRES_BAD_RESPONSE ||
- PQresultStatus(PGSQLres) == PGRES_NONFATAL_ERROR ||
- PQresultStatus(PGSQLres) == PGRES_FATAL_ERROR) {
- ast_log(LOG_WARNING,"aPGSQL_query: Query Error (connection identifier : %d, error message : %s)\n",id,PQcmdStatus(PGSQLres));
- res=-1;
- break;
- }
- nres=PQnfields(PGSQLres);
- id1=add_identifier(AST_PGSQL_ID_RESID,PGSQLres);
- snprintf(s, sizeof(s), "%d", id1);
- pbx_builtin_setvar_helper(chan,var,s);
- break;
- }
-
- free(s1);
- free(s2);
-
- return(res);
-}
-
-
-static int aPGSQL_fetch(struct ast_channel *chan, void *data) {
-
- char *s1,*s2,*fetchid_var,*s4,*s5,*s6,*s7;
- char s[100];
- char *var;
- int l;
- int res;
- PGresult *PGSQLres;
- int id,id1,i,j,fnd;
- int *lalares=NULL;
- int nres;
- struct ast_var_t *variables;
- struct varshead *headp;
- char *stringp=NULL;
-
- headp=&chan->varshead;
-
- res=0;
- l=strlen(data)+2;
- s7=NULL;
- s1=malloc(l);
- s2=malloc(l);
- strncpy(s1, data, l - 1);
- stringp=s1;
- strsep(&stringp," "); /* eat the first token, we already know it :P */
- fetchid_var=strsep(&stringp," ");
- while (1) { /* ugly trick to make branches with break; */
- var=fetchid_var; /* fetchid */
- fnd=0;
-
- AST_LIST_TRAVERSE(headp,variables,entries) {
- if (strncasecmp(ast_var_name(variables),fetchid_var,strlen(fetchid_var))==0) {
- s7=ast_var_value(variables);
- fnd=1;
- break;
- }
- }
-
- if (fnd==0) {
- s7="0";
- pbx_builtin_setvar_helper(chan,fetchid_var,s7);
- }
-
- s4=strsep(&stringp," ");
- id=atoi(s4); /* resultid */
- if ((PGSQLres=find_identifier(id,AST_PGSQL_ID_RESID))==NULL) {
- ast_log(LOG_WARNING,"Invalid result identifier %d passed in aPGSQL_fetch\n",id);
- res=-1;
- break;
- }
- id=atoi(s7); /*fetchid */
- if ((lalares=find_identifier(id,AST_PGSQL_ID_FETCHID))==NULL) {
- i=0; /* fetching the very first row */
- } else {
- i=*lalares;
- free(lalares);
- del_identifier(id,AST_PGSQL_ID_FETCHID); /* will re-add it a bit later */
- }
-
- if (i<PQntuples(PGSQLres)) {
- nres=PQnfields(PGSQLres);
- ast_log(LOG_WARNING,"ast_PGSQL_fetch : nres = %d i = %d ;\n",nres,i);
- for (j=0;j<nres;j++) {
- s5=strsep(&stringp," ");
- if (s5==NULL) {
- ast_log(LOG_WARNING,"ast_PGSQL_fetch : More tuples (%d) than variables (%d)\n",nres,j);
- break;
- }
- s6=PQgetvalue(PGSQLres,i,j);
- if (s6==NULL) {
- ast_log(LOG_WARNING,"PWgetvalue(res,%d,%d) returned NULL in ast_PGSQL_fetch\n",i,j);
- break;
- }
- ast_log(LOG_WARNING,"===setting variable '%s' to '%s'\n",s5,s6);
- pbx_builtin_setvar_helper(chan,s5,s6);
- }
- lalares=malloc(sizeof(int));
- *lalares = ++i; /* advance to the next row */
- id1 = add_identifier(AST_PGSQL_ID_FETCHID,lalares);
- } else {
- ast_log(LOG_WARNING,"ast_PGSQL_fetch : EOF\n");
- id1 = 0; /* no more rows */
- }
- snprintf(s, sizeof(s), "%d", id1);
- ast_log(LOG_WARNING,"Setting var '%s' to value '%s'\n",fetchid_var,s);
- pbx_builtin_setvar_helper(chan,fetchid_var,s);
- break;
- }
-
- free(s1);
- free(s2);
- return(res);
-}
-
-static int aPGSQL_reset(struct ast_channel *chan, void *data) {
-
- char *s1,*s3;
- int l;
- PGconn *karoto;
- int id;
- char *stringp=NULL;
-
-
- l=strlen(data)+2;
- s1=malloc(l);
- strncpy(s1, data, l - 1);
- stringp=s1;
- strsep(&stringp," "); /* eat the first token, we already know it :P */
- s3=strsep(&stringp," ");
- id=atoi(s3);
- if ((karoto=find_identifier(id,AST_PGSQL_ID_CONNID))==NULL) {
- ast_log(LOG_WARNING,"Invalid connection identifier %d passed in aPGSQL_reset\n",id);
- } else {
- PQreset(karoto);
- }
- free(s1);
- return(0);
-
-}
-
-static int aPGSQL_clear(struct ast_channel *chan, void *data) {
-
- char *s1,*s3;
- int l;
- PGresult *karoto;
- int id;
- char *stringp=NULL;
-
-
- l=strlen(data)+2;
- s1=malloc(l);
- strncpy(s1, data, l - 1);
- stringp=s1;
- strsep(&stringp," "); /* eat the first token, we already know it :P */
- s3=strsep(&stringp," ");
- id=atoi(s3);
- if ((karoto=find_identifier(id,AST_PGSQL_ID_RESID))==NULL) {
- ast_log(LOG_WARNING,"Invalid result identifier %d passed in aPGSQL_clear\n",id);
- } else {
- PQclear(karoto);
- del_identifier(id,AST_PGSQL_ID_RESID);
- }
- free(s1);
- return(0);
-
-}
-
-
-
-
-static int aPGSQL_disconnect(struct ast_channel *chan, void *data) {
-
- char *s1,*s3;
- int l;
- PGconn *karoto;
- int id;
- char *stringp=NULL;
-
-
- l=strlen(data)+2;
- s1=malloc(l);
- strncpy(s1, data, l - 1);
- stringp=s1;
- strsep(&stringp," "); /* eat the first token, we already know it :P */
- s3=strsep(&stringp," ");
- id=atoi(s3);
- if ((karoto=find_identifier(id,AST_PGSQL_ID_CONNID))==NULL) {
- ast_log(LOG_WARNING,"Invalid connection identifier %d passed in aPGSQL_disconnect\n",id);
- } else {
- PQfinish(karoto);
- del_identifier(id,AST_PGSQL_ID_CONNID);
- }
- free(s1);
- return(0);
-
-}
-
-static int aPGSQL_debug(struct ast_channel *chan, void *data) {
- ast_log(LOG_WARNING,"Debug : %s\n",(char *)data);
- return(0);
-}
-
-static int PGSQL_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- int result;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "APP_PGSQL requires an argument (see manual)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- result=0;
-
- if (strncasecmp("connect",data,strlen("connect"))==0) {
- result=(aPGSQL_connect(chan,data));
- } else if (strncasecmp("query",data,strlen("query"))==0) {
- result=(aPGSQL_query(chan,data));
- } else if (strncasecmp("fetch",data,strlen("fetch"))==0) {
- result=(aPGSQL_fetch(chan,data));
- } else if (strncasecmp("reset",data,strlen("reset"))==0) {
- result=(aPGSQL_reset(chan,data));
- } else if (strncasecmp("clear",data,strlen("clear"))==0) {
- result=(aPGSQL_clear(chan,data));
- } else if (strncasecmp("debug",data,strlen("debug"))==0) {
- result=(aPGSQL_debug(chan,data));
- } else if (strncasecmp("disconnect",data,strlen("disconnect"))==0) {
- result=(aPGSQL_disconnect(chan,data));
- } else {
- ast_log(LOG_WARNING, "Unknown APP_PGSQL argument : %s\n",(char *)data);
- result=-1;
- }
-
- LOCAL_USER_REMOVE(u);
-
- return result;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- struct PGSQLidshead *headp;
-
- headp=&PGSQLidshead;
-
- AST_LIST_HEAD_INIT(headp);
- return ast_register_application(app, PGSQL_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_stack.c b/1.2-netsec/apps/app_stack.c
deleted file mode 100644
index e3c33d2e5..000000000
--- a/1.2-netsec/apps/app_stack.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (c) 2004-2005 Tilghman Lesher <app_stack_v002@the-tilghman.com>.
- *
- * This code is released by the author with no restrictions on usage.
- *
- * 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 Stack applications Gosub, Return, etc.
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk/options.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/chanvars.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-
-#define STACKVAR "~GOSUB~STACK~"
-
-static const char *tdesc = "Stack Routines";
-
-static const char *app_gosub = "Gosub";
-static const char *app_gosubif = "GosubIf";
-static const char *app_return = "Return";
-static const char *app_pop = "StackPop";
-
-static const char *gosub_synopsis = "Jump to label, saving return address";
-static const char *gosubif_synopsis = "Jump to label, saving return address";
-static const char *return_synopsis = "Return from gosub routine";
-static const char *pop_synopsis = "Remove one address from gosub stack";
-
-static const char *gosub_descrip =
-"Gosub([[context|]exten|]priority)\n"
-" Jumps to the label specified, saving the return address.\n";
-static const char *gosubif_descrip =
-"GosubIf(condition?labeliftrue[:labeliffalse])\n"
-" If the condition is true, then jump to labeliftrue. If false, jumps to\n"
-"labeliffalse, if specified. In either case, a jump saves the return point\n"
-"in the dialplan, to be returned to with a Return.\n";
-static const char *return_descrip =
-"Return()\n"
-" Jumps to the last label on the stack, removing it.\n";
-static const char *pop_descrip =
-"StackPop()\n"
-" Removes last label on the stack, discarding it.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int pop_exec(struct ast_channel *chan, void *data)
-{
- pbx_builtin_setvar_helper(chan, STACKVAR, NULL);
-
- return 0;
-}
-
-static int return_exec(struct ast_channel *chan, void *data)
-{
- char *label = pbx_builtin_getvar_helper(chan, STACKVAR);
-
- if (ast_strlen_zero(label)) {
- ast_log(LOG_ERROR, "Return without Gosub: stack is empty\n");
- return -1;
- } else if (ast_parseable_goto(chan, label)) {
- ast_log(LOG_WARNING, "No next statement after Gosub?\n");
- return -1;
- }
-
- pbx_builtin_setvar_helper(chan, STACKVAR, NULL);
- return 0;
-}
-
-static int gosub_exec(struct ast_channel *chan, void *data)
-{
- char newlabel[AST_MAX_EXTENSION * 2 + 3 + 11];
- struct localuser *u;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_ERROR, "%s requires an argument: %s([[context|]exten|]priority)\n", app_gosub, app_gosub);
- return -1;
- }
-
- LOCAL_USER_ADD(u);
- snprintf(newlabel, sizeof(newlabel), "%s|%s|%d", chan->context, chan->exten, chan->priority + 1);
-
- if (ast_parseable_goto(chan, data)) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- pbx_builtin_pushvar_helper(chan, STACKVAR, newlabel);
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-static int gosubif_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- char *condition="", *label1, *label2, *args;
- int res=0;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "GosubIf requires an argument\n");
- return 0;
- }
-
- args = ast_strdupa((char *)data);
- if (!args) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- condition = strsep(&args, "?");
- label1 = strsep(&args, ":");
- label2 = args;
-
- if (ast_true(condition)) {
- if (label1) {
- res = gosub_exec(chan, label1);
- }
- } else if (label2) {
- res = gosub_exec(chan, label2);
- }
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- ast_unregister_application(app_return);
- ast_unregister_application(app_pop);
- ast_unregister_application(app_gosubif);
- ast_unregister_application(app_gosub);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return 0;
-}
-
-int load_module(void)
-{
- ast_register_application(app_pop, pop_exec, pop_synopsis, pop_descrip);
- ast_register_application(app_return, return_exec, return_synopsis, return_descrip);
- ast_register_application(app_gosubif, gosubif_exec, gosubif_synopsis, gosubif_descrip);
- ast_register_application(app_gosub, gosub_exec, gosub_synopsis, gosub_descrip);
-
- return 0;
-}
-
-char *description(void)
-{
- return (char *) tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
-
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_system.c b/1.2-netsec/apps/app_system.c
deleted file mode 100644
index 63e9baacb..000000000
--- a/1.2-netsec/apps/app_system.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Execute arbitrary system commands
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/app.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Generic System() application";
-
-static char *app = "System";
-
-static char *app2 = "TrySystem";
-
-static char *synopsis = "Execute a system command";
-
-static char *synopsis2 = "Try executing a system command";
-
-static char *chanvar = "SYSTEMSTATUS";
-
-static char *descrip =
-" System(command): Executes a command by using system(). If the command\n"
-"fails, the console should report a fallthrough. \n"
-"Result of execution is returned in the SYSTEMSTATUS channel variable:\n"
-" FAILURE Could not execute the specified command\n"
-" SUCCESS Specified command successfully executed\n"
-"\n"
-"Old behaviour:\n"
-"If the command itself executes but is in error, and if there exists\n"
-"a priority n + 101, where 'n' is the priority of the current instance,\n"
-"then the channel will be setup to continue at that priority level.\n"
-"Note that this jump functionality has been deprecated and will only occur\n"
-"if the global priority jumping option is enabled in extensions.conf.\n";
-
-static char *descrip2 =
-" TrySystem(command): Executes a command by using system().\n"
-"on any situation.\n"
-"Result of execution is returned in the SYSTEMSTATUS channel variable:\n"
-" FAILURE Could not execute the specified command\n"
-" SUCCESS Specified command successfully executed\n"
-" APPERROR Specified command successfully executed, but returned error code\n"
-"\n"
-"Old behaviour:\nIf the command itself executes but is in error, and if\n"
-"there exists a priority n + 101, where 'n' is the priority of the current\n"
-"instance, then the channel will be setup to continue at that\n"
-"priority level. Otherwise, System will terminate.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int system_exec_helper(struct ast_channel *chan, void *data, int failmode)
-{
- int res=0;
- struct localuser *u;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "System requires an argument(command)\n");
- pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
- return failmode;
- }
-
- LOCAL_USER_ADD(u);
-
- /* Do our thing here */
- res = ast_safe_system((char *)data);
- if ((res < 0) && (errno != ECHILD)) {
- ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
- pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
- res = failmode;
- } else if (res == 127) {
- ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
- pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
- res = failmode;
- } else {
- if (res < 0)
- res = 0;
- if (option_priority_jumping && res)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
-
- if (res != 0)
- pbx_builtin_setvar_helper(chan, chanvar, "APPERROR");
- else
- pbx_builtin_setvar_helper(chan, chanvar, "SUCCESS");
- res = 0;
- }
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-static int system_exec(struct ast_channel *chan, void *data)
-{
- return system_exec_helper(chan, data, -1);
-}
-
-static int trysystem_exec(struct ast_channel *chan, void *data)
-{
- return system_exec_helper(chan, data, 0);
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
- res |= ast_unregister_application(app2);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app2, trysystem_exec, synopsis2, descrip2);
- res |= ast_register_application(app, system_exec, synopsis, descrip);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_talkdetect.c b/1.2-netsec/apps/app_talkdetect.c
deleted file mode 100644
index 11efe7068..000000000
--- a/1.2-netsec/apps/app_talkdetect.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Playback a file with audio detect
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/utils.h"
-#include "asterisk/dsp.h"
-
-static char *tdesc = "Playback with Talk Detection";
-
-static char *app = "BackgroundDetect";
-
-static char *synopsis = "Background a file with talk detect";
-
-static char *descrip =
-" BackgroundDetect(filename[|sil[|min|[max]]]): Plays back a given\n"
-"filename, waiting for interruption from a given digit (the digit must\n"
-"start the beginning of a valid extension, or it will be ignored).\n"
-"During the playback of the file, audio is monitored in the receive\n"
-"direction, and if a period of non-silence which is greater than 'min' ms\n"
-"yet less than 'max' ms is followed by silence for at least 'sil' ms then\n"
-"the audio playback is aborted and processing jumps to the 'talk' extension\n"
-"if available. If unspecified, sil, min, and max default to 1000, 100, and\n"
-"infinity respectively.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int background_detect_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- char *tmp;
- char *options;
- char *stringp;
- struct ast_frame *fr;
- int notsilent=0;
- struct timeval start = { 0, 0};
- int sil = 1000;
- int min = 100;
- int max = -1;
- int x;
- int origrformat=0;
- struct ast_dsp *dsp;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "BackgroundDetect requires an argument (filename)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- tmp = ast_strdupa(data);
- if (!tmp) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- stringp=tmp;
- strsep(&stringp, "|");
- options = strsep(&stringp, "|");
- if (options) {
- if ((sscanf(options, "%d", &x) == 1) && (x > 0))
- sil = x;
- options = strsep(&stringp, "|");
- if (options) {
- if ((sscanf(options, "%d", &x) == 1) && (x > 0))
- min = x;
- options = strsep(&stringp, "|");
- if (options) {
- if ((sscanf(options, "%d", &x) == 1) && (x > 0))
- max = x;
- }
- }
- }
- ast_log(LOG_DEBUG, "Preparing detect of '%s', sil=%d,min=%d,max=%d\n",
- tmp, sil, min, max);
- if (chan->_state != AST_STATE_UP) {
- /* Otherwise answer unless we're supposed to send this while on-hook */
- res = ast_answer(chan);
- }
- if (!res) {
- origrformat = chan->readformat;
- if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)))
- ast_log(LOG_WARNING, "Unable to set read format to linear!\n");
- }
- if (!(dsp = ast_dsp_new())) {
- ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
- res = -1;
- }
- if (!res) {
- ast_stopstream(chan);
- res = ast_streamfile(chan, tmp, chan->language);
- if (!res) {
- while(chan->stream) {
- res = ast_sched_wait(chan->sched);
- if ((res < 0) && !chan->timingfunc) {
- res = 0;
- break;
- }
- if (res < 0)
- res = 1000;
- res = ast_waitfor(chan, res);
- if (res < 0) {
- ast_log(LOG_WARNING, "Waitfor failed on %s\n", chan->name);
- break;
- } else if (res > 0) {
- fr = ast_read(chan);
- if (!fr) {
- res = -1;
- break;
- } else if (fr->frametype == AST_FRAME_DTMF) {
- char t[2];
- t[0] = fr->subclass;
- t[1] = '\0';
- if (ast_canmatch_extension(chan, chan->context, t, 1, chan->cid.cid_num)) {
- /* They entered a valid extension, or might be anyhow */
- res = fr->subclass;
- ast_frfree(fr);
- break;
- }
- } else if ((fr->frametype == AST_FRAME_VOICE) && (fr->subclass == AST_FORMAT_SLINEAR)) {
- int totalsilence;
- int ms;
- res = ast_dsp_silence(dsp, fr, &totalsilence);
- if (res && (totalsilence > sil)) {
- /* We've been quiet a little while */
- if (notsilent) {
- /* We had heard some talking */
- ms = ast_tvdiff_ms(ast_tvnow(), start);
- ms -= sil;
- if (ms < 0)
- ms = 0;
- if ((ms > min) && ((max < 0) || (ms < max))) {
- char ms_str[10];
- ast_log(LOG_DEBUG, "Found qualified token of %d ms\n", ms);
-
- /* Save detected talk time (in milliseconds) */
- sprintf(ms_str, "%d", ms );
- pbx_builtin_setvar_helper(chan, "TALK_DETECTED", ms_str);
-
- ast_goto_if_exists(chan, chan->context, "talk", 1);
- res = 0;
- ast_frfree(fr);
- break;
- } else
- ast_log(LOG_DEBUG, "Found unqualified token of %d ms\n", ms);
- notsilent = 0;
- }
- } else {
- if (!notsilent) {
- /* Heard some audio, mark the begining of the token */
- start = ast_tvnow();
- ast_log(LOG_DEBUG, "Start of voice token!\n");
- notsilent = 1;
- }
- }
-
- }
- ast_frfree(fr);
- }
- ast_sched_runq(chan->sched);
- }
- ast_stopstream(chan);
- } else {
- ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data);
- res = 0;
- }
- }
- if (res > -1) {
- if (origrformat && ast_set_read_format(chan, origrformat)) {
- ast_log(LOG_WARNING, "Failed to restore read format for %s to %s\n",
- chan->name, ast_getformatname(origrformat));
- }
- }
- if (dsp)
- ast_dsp_free(dsp);
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, background_detect_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_test.c b/1.2-netsec/apps/app_test.c
deleted file mode 100644
index dba8bcafb..000000000
--- a/1.2-netsec/apps/app_test.c
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- * Russell Bryant <russelb@clemson.edu>
- *
- * 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 Applications to test connection and produce report in text file
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/options.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/lock.h"
-#include "asterisk/app.h"
-#include "asterisk/pbx.h"
-#include "asterisk/utils.h"
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static char *tdesc = "Interface Test Application";
-
-static char *tests_descrip =
- "TestServer(): Perform test server function and write call report.\n"
- "Results stored in /var/log/asterisk/testreports/<testid>-server.txt";
-static char *tests_app = "TestServer";
-static char *tests_synopsis = "Execute Interface Test Server";
-
-static char *testc_descrip =
- "TestClient(testid): Executes test client with given testid.\n"
- "Results stored in /var/log/asterisk/testreports/<testid>-client.txt";
-
-static char *testc_app = "TestClient";
-static char *testc_synopsis = "Execute Interface Test Client";
-
-static int measurenoise(struct ast_channel *chan, int ms, char *who)
-{
- int res=0;
- int mssofar;
- int noise=0;
- int samples=0;
- int x;
- short *foo;
- struct timeval start;
- struct ast_frame *f;
- int rformat;
- rformat = chan->readformat;
- if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
- ast_log(LOG_NOTICE, "Unable to set to linear mode!\n");
- return -1;
- }
- start = ast_tvnow();
- for(;;) {
- mssofar = ast_tvdiff_ms(ast_tvnow(), start);
- if (mssofar > ms)
- break;
- res = ast_waitfor(chan, ms - mssofar);
- if (res < 1)
- break;
- f = ast_read(chan);
- if (!f) {
- res = -1;
- break;
- }
- if ((f->frametype == AST_FRAME_VOICE) && (f->subclass == AST_FORMAT_SLINEAR)) {
- foo = (short *)f->data;
- for (x=0;x<f->samples;x++) {
- noise += abs(foo[x]);
- samples++;
- }
- }
- }
-
- if (rformat) {
- if (ast_set_read_format(chan, rformat)) {
- ast_log(LOG_NOTICE, "Unable to restore original format!\n");
- return -1;
- }
- }
- if (res < 0)
- return res;
- if (!samples) {
- ast_log(LOG_NOTICE, "No samples were received from the other side!\n");
- return -1;
- }
- ast_log(LOG_DEBUG, "%s: Noise: %d, samples: %d, avg: %d\n", who, noise, samples, noise / samples);
- return (noise / samples);
-}
-
-static int sendnoise(struct ast_channel *chan, int ms)
-{
- int res;
- res = ast_tonepair_start(chan, 1537, 2195, ms, 8192);
- if (!res) {
- res = ast_waitfordigit(chan, ms);
- ast_tonepair_stop(chan);
- }
- return res;
-}
-
-static int testclient_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- int res = 0;
- char *testid=data;
- char fn[80];
- char serverver[80];
- FILE *f;
-
- /* Check for test id */
- if (ast_strlen_zero(testid)) {
- ast_log(LOG_WARNING, "TestClient requires an argument - the test id\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- if (chan->_state != AST_STATE_UP)
- res = ast_answer(chan);
-
- /* Wait a few just to be sure things get started */
- res = ast_safe_sleep(chan, 3000);
- /* Transmit client version */
- if (!res)
- res = ast_dtmf_stream(chan, NULL, "8378*1#", 0);
- if (option_debug)
- ast_log(LOG_DEBUG, "Transmit client version\n");
-
- /* Read server version */
- if (option_debug)
- ast_log(LOG_DEBUG, "Read server version\n");
- if (!res)
- res = ast_app_getdata(chan, NULL, serverver, sizeof(serverver) - 1, 0);
- if (res > 0)
- res = 0;
- if (option_debug)
- ast_log(LOG_DEBUG, "server version: %s\n", serverver);
-
- if (res > 0)
- res = 0;
-
- if (!res)
- res = ast_safe_sleep(chan, 1000);
- /* Send test id */
- if (!res)
- res = ast_dtmf_stream(chan, NULL, testid, 0);
- if (!res)
- res = ast_dtmf_stream(chan, NULL, "#", 0);
- if (option_debug)
- ast_log(LOG_DEBUG, "send test identifier: %s\n", testid);
-
- if ((res >=0) && (!ast_strlen_zero(testid))) {
- /* Make the directory to hold the test results in case it's not there */
- snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR);
- mkdir(fn, 0777);
- snprintf(fn, sizeof(fn), "%s/testresults/%s-client.txt", ast_config_AST_LOG_DIR, testid);
- if ((f = fopen(fn, "w+"))) {
- setlinebuf(f);
- fprintf(f, "CLIENTCHAN: %s\n", chan->name);
- fprintf(f, "CLIENTTEST ID: %s\n", testid);
- fprintf(f, "ANSWER: PASS\n");
- res = 0;
-
- if (!res) {
- /* Step 1: Wait for "1" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 2. Wait DTMF 1\n");
- res = ast_waitfordigit(chan, 3000);
- fprintf(f, "WAIT DTMF 1: %s\n", (res != '1') ? "FAIL" : "PASS");
- if (res == '1')
- res = 0;
- else
- res = -1;
- }
- if (!res)
- res = ast_safe_sleep(chan, 1000);
- if (!res) {
- /* Step 2: Send "2" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 2. Send DTMF 2\n");
- res = ast_dtmf_stream(chan, NULL, "2", 0);
- fprintf(f, "SEND DTMF 2: %s\n", (res < 0) ? "FAIL" : "PASS");
- if (res > 0)
- res = 0;
- }
- if (!res) {
- /* Step 3: Wait one second */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 3. Wait one second\n");
- res = ast_safe_sleep(chan, 1000);
- fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS");
- if (res > 0)
- res = 0;
- }
- if (!res) {
- /* Step 4: Measure noise */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 4. Measure noise\n");
- res = measurenoise(chan, 5000, "TestClient");
- fprintf(f, "MEASURENOISE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res);
- if (res > 0)
- res = 0;
- }
- if (!res) {
- /* Step 5: Wait for "4" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 5. Wait DTMF 4\n");
- res = ast_waitfordigit(chan, 3000);
- fprintf(f, "WAIT DTMF 4: %s\n", (res != '4') ? "FAIL" : "PASS");
- if (res == '4')
- res = 0;
- else
- res = -1;
- }
- if (!res) {
- /* Step 6: Transmit tone noise */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 6. Transmit tone\n");
- res = sendnoise(chan, 6000);
- fprintf(f, "SENDTONE: %s\n", (res < 0) ? "FAIL" : "PASS");
- }
- if (!res || (res == '5')) {
- /* Step 7: Wait for "5" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 7. Wait DTMF 5\n");
- if (!res)
- res = ast_waitfordigit(chan, 3000);
- fprintf(f, "WAIT DTMF 5: %s\n", (res != '5') ? "FAIL" : "PASS");
- if (res == '5')
- res = 0;
- else
- res = -1;
- }
- if (!res) {
- /* Step 8: Wait one second */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 8. Wait one second\n");
- res = ast_safe_sleep(chan, 1000);
- fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS");
- if (res > 0)
- res = 0;
- }
- if (!res) {
- /* Step 9: Measure noise */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 6. Measure tone\n");
- res = measurenoise(chan, 4000, "TestClient");
- fprintf(f, "MEASURETONE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res);
- if (res > 0)
- res = 0;
- }
- if (!res) {
- /* Step 10: Send "7" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 7. Send DTMF 7\n");
- res = ast_dtmf_stream(chan, NULL, "7", 0);
- fprintf(f, "SEND DTMF 7: %s\n", (res < 0) ? "FAIL" : "PASS");
- if (res > 0)
- res =0;
- }
- if (!res) {
- /* Step 11: Wait for "8" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestClient: 11. Wait DTMF 8\n");
- res = ast_waitfordigit(chan, 3000);
- fprintf(f, "WAIT DTMF 8: %s\n", (res != '8') ? "FAIL" : "PASS");
- if (res == '8')
- res = 0;
- else
- res = -1;
- }
- if (option_debug && !res ) {
- /* Step 12: Hangup! */
- ast_log(LOG_DEBUG, "TestClient: 12. Hangup\n");
- }
-
- if (option_debug)
- ast_log(LOG_DEBUG, "-- TEST COMPLETE--\n");
- fprintf(f, "-- END TEST--\n");
- fclose(f);
- res = -1;
- } else
- res = -1;
- } else {
- ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name);
- res = -1;
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int testserver_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- int res = 0;
- char testid[80]="";
- char fn[80];
- FILE *f;
- LOCAL_USER_ADD(u);
- if (chan->_state != AST_STATE_UP)
- res = ast_answer(chan);
- /* Read version */
- if (option_debug)
- ast_log(LOG_DEBUG, "Read client version\n");
- if (!res)
- res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0);
- if (res > 0)
- res = 0;
- if (option_debug) {
- ast_log(LOG_DEBUG, "client version: %s\n", testid);
- ast_log(LOG_DEBUG, "Transmit server version\n");
- }
- res = ast_safe_sleep(chan, 1000);
- if (!res)
- res = ast_dtmf_stream(chan, NULL, "8378*1#", 0);
- if (res > 0)
- res = 0;
-
- if (!res)
- res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0);
- if (option_debug)
- ast_log(LOG_DEBUG, "read test identifier: %s\n", testid);
- /* Check for sneakyness */
- if (strchr(testid, '/'))
- res = -1;
- if ((res >=0) && (!ast_strlen_zero(testid))) {
- /* Got a Test ID! Whoo hoo! */
- /* Make the directory to hold the test results in case it's not there */
- snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR);
- mkdir(fn, 0777);
- snprintf(fn, sizeof(fn), "%s/testresults/%s-server.txt", ast_config_AST_LOG_DIR, testid);
- if ((f = fopen(fn, "w+"))) {
- setlinebuf(f);
- fprintf(f, "SERVERCHAN: %s\n", chan->name);
- fprintf(f, "SERVERTEST ID: %s\n", testid);
- fprintf(f, "ANSWER: PASS\n");
- ast_log(LOG_DEBUG, "Processing Test ID '%s'\n", testid);
- res = ast_safe_sleep(chan, 1000);
- if (!res) {
- /* Step 1: Send "1" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 1. Send DTMF 1\n");
- res = ast_dtmf_stream(chan, NULL, "1", 0);
- fprintf(f, "SEND DTMF 1: %s\n", (res < 0) ? "FAIL" : "PASS");
- if (res > 0)
- res = 0;
- }
- if (!res) {
- /* Step 2: Wait for "2" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 2. Wait DTMF 2\n");
- res = ast_waitfordigit(chan, 3000);
- fprintf(f, "WAIT DTMF 2: %s\n", (res != '2') ? "FAIL" : "PASS");
- if (res == '2')
- res = 0;
- else
- res = -1;
- }
- if (!res) {
- /* Step 3: Measure noise */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 3. Measure noise\n");
- res = measurenoise(chan, 6000, "TestServer");
- fprintf(f, "MEASURENOISE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res);
- if (res > 0)
- res = 0;
- }
- if (!res) {
- /* Step 4: Send "4" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 4. Send DTMF 4\n");
- res = ast_dtmf_stream(chan, NULL, "4", 0);
- fprintf(f, "SEND DTMF 4: %s\n", (res < 0) ? "FAIL" : "PASS");
- if (res > 0)
- res = 0;
- }
-
- if (!res) {
- /* Step 5: Wait one second */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 5. Wait one second\n");
- res = ast_safe_sleep(chan, 1000);
- fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS");
- if (res > 0)
- res = 0;
- }
-
- if (!res) {
- /* Step 6: Measure noise */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 6. Measure tone\n");
- res = measurenoise(chan, 4000, "TestServer");
- fprintf(f, "MEASURETONE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res);
- if (res > 0)
- res = 0;
- }
-
- if (!res) {
- /* Step 7: Send "5" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 7. Send DTMF 5\n");
- res = ast_dtmf_stream(chan, NULL, "5", 0);
- fprintf(f, "SEND DTMF 5: %s\n", (res < 0) ? "FAIL" : "PASS");
- if (res > 0)
- res = 0;
- }
-
- if (!res) {
- /* Step 8: Transmit tone noise */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 8. Transmit tone\n");
- res = sendnoise(chan, 6000);
- fprintf(f, "SENDTONE: %s\n", (res < 0) ? "FAIL" : "PASS");
- }
-
- if (!res || (res == '7')) {
- /* Step 9: Wait for "7" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 9. Wait DTMF 7\n");
- if (!res)
- res = ast_waitfordigit(chan, 3000);
- fprintf(f, "WAIT DTMF 7: %s\n", (res != '7') ? "FAIL" : "PASS");
- if (res == '7')
- res = 0;
- else
- res = -1;
- }
- if (!res)
- res = ast_safe_sleep(chan, 1000);
- if (!res) {
- /* Step 10: Send "8" */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 10. Send DTMF 8\n");
- res = ast_dtmf_stream(chan, NULL, "8", 0);
- fprintf(f, "SEND DTMF 8: %s\n", (res < 0) ? "FAIL" : "PASS");
- if (res > 0)
- res = 0;
- }
- if (!res) {
- /* Step 11: Wait for hangup to arrive! */
- if (option_debug)
- ast_log(LOG_DEBUG, "TestServer: 11. Waiting for hangup\n");
- res = ast_safe_sleep(chan, 10000);
- fprintf(f, "WAIT HANGUP: %s\n", (res < 0) ? "PASS" : "FAIL");
- }
-
- ast_log(LOG_NOTICE, "-- TEST COMPLETE--\n");
- fprintf(f, "-- END TEST--\n");
- fclose(f);
- res = -1;
- } else
- res = -1;
- } else {
- ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name);
- res = -1;
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(testc_app);
- res |= ast_unregister_application(tests_app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(testc_app, testclient_exec, testc_synopsis, testc_descrip);
- res |= ast_register_application(tests_app, testserver_exec, tests_synopsis, tests_descrip);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key(void)
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_transfer.c b/1.2-netsec/apps/app_transfer.c
deleted file mode 100644
index aaff52be0..000000000
--- a/1.2-netsec/apps/app_transfer.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Transfer a caller
- *
- * Requires transfer support from channel driver
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/app.h"
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static const char *tdesc = "Transfer";
-
-static const char *app = "Transfer";
-
-static const char *synopsis = "Transfer caller to remote extension";
-
-static const char *descrip =
-" Transfer([Tech/]dest[|options]): Requests the remote caller be transferred\n"
-"to a given destination. If TECH (SIP, IAX2, LOCAL etc) is used, only\n"
-"an incoming call with the same channel technology will be transfered.\n"
-"Note that for SIP, if you transfer before call is setup, a 302 redirect\n"
-"SIP message will be returned to the caller.\n"
-"\nThe result of the application will be reported in the TRANSFERSTATUS\n"
-"channel variable:\n"
-" SUCCESS Transfer succeeded\n"
-" FAILURE Transfer failed\n"
-" UNSUPPORTED Transfer unsupported by channel driver\n"
-"The option string many contain the following character:\n"
-"'j' -- jump to n+101 priority if the channel transfer attempt\n"
-" fails\n";
-
-static int transfer_exec(struct ast_channel *chan, void *data)
-{
- int res;
- int len;
- struct localuser *u;
- char *slash;
- char *tech = NULL;
- char *dest = NULL;
- char *status;
- char *parse;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(dest);
- AST_APP_ARG(options);
- );
-
- LOCAL_USER_ADD(u);
-
- if (ast_strlen_zero((char *)data)) {
- ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination[|options])\n");
- LOCAL_USER_REMOVE(u);
- pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
- return 0;
- } else {
- parse = ast_strdupa(data);
- if (!parse) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- dest = args.dest;
-
- if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
- tech = dest;
- dest = slash + 1;
- /* Allow execution only if the Tech/destination agrees with the type of the channel */
- if (strncasecmp(chan->type, tech, len)) {
- pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- }
-
- /* Check if the channel supports transfer before we try it */
- if (!chan->tech->transfer) {
- pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- res = ast_transfer(chan, dest);
-
- if (res < 0) {
- status = "FAILURE";
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- res = 0;
- } else {
- status = "SUCCESS";
- res = 0;
- }
-
- pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, transfer_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return (char *) tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
-
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_txtcidname.c b/1.2-netsec/apps/app_txtcidname.c
deleted file mode 100644
index b6e365b54..000000000
--- a/1.2-netsec/apps/app_txtcidname.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Caller*id name lookup - Look up the caller's name via DNS
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/module.h"
-#include "asterisk/enum.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static char *tdesc = "TXTCIDName";
-
-static char *app = "TXTCIDName";
-
-static char *synopsis = "Lookup caller name from TXT record";
-
-static char *descrip =
-" TXTCIDName(<CallerIDNumber>[|options]): Looks up a Caller Name via DNS and sets\n"
-"the variable 'TXTCIDNAME'. TXTCIDName will either be blank\n"
-"or return the value found in the TXT record in DNS.\n"
-"The option string may contain the following character:\n"
-"'j' -- jump to n+101 priority if the lookup fails\n"
-"This application sets the following channel variable upon completion:\n"
-" TXTCIDNAMESTATUS The status of the lookup as a text string, one of\n"
-" SUCCESS | FAILED\n";
-
-static int txtcidname_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- char tech[80];
- char txt[256] = "";
- char dest[80];
- struct localuser *u;
- static int dep_warning = 0;
- char *parse = NULL;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(cidnum);
- AST_APP_ARG(options);
- );
-
- LOCAL_USER_ADD(u);
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "The TXTCIDName application has been deprecated in favor of the TXTCIDNAME dialplan function.\n");
- dep_warning = 1;
- }
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "TXTCIDName requires an argument (extension[|options])\n");
- LOCAL_USER_REMOVE(u);
- return(0);
- }
-
- parse = ast_strdupa(data);
- if (!parse) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args,parse);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- if (!res) {
- res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt, sizeof(txt));
- }
-
- /* Parse it out */
- if (res > 0) {
- if (!ast_strlen_zero(txt)) {
- pbx_builtin_setvar_helper(chan, "TXTCIDNAME", txt);
- pbx_builtin_setvar_helper(chan, "TXTCIDNAMESTATUS", "SUCCESS");
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "TXTCIDNAME got '%s'\n", txt);
- }
- }
- if (!res) {
- /* Look for a "busy" place */
- if (priority_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- pbx_builtin_setvar_helper(chan, "TXTCIDNAMESTATUS", "FAILED");
- } else if (res > 0)
- res = 0;
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, txtcidname_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_url.c b/1.2-netsec/apps/app_url.c
deleted file mode 100644
index 7f274b46a..000000000
--- a/1.2-netsec/apps/app_url.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief App to transmit a URL
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/image.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Send URL Applications";
-
-static char *app = "SendURL";
-
-static char *synopsis = "Send a URL";
-
-static char *descrip =
-" SendURL(URL[|option]): Requests client go to URL (IAX2) or sends the \n"
-"URL to the client (other channels).\n"
-"Result is returned in the SENDURLSTATUS channel variable:\n"
-" SUCCESS URL successfully sent to client\n"
-" FAILURE Failed to send URL\n"
-" NOLOAD Clien failed to load URL (wait enabled)\n"
-" UNSUPPORTED Channel does not support URL transport\n"
-"\n"
-"If the option 'wait' is specified, execution will wait for an\n"
-"acknowledgement that the URL has been loaded before continuing\n"
-"and will return -1 if the peer is unable to load the URL\n"
-"\n"
-"Old behaviour (deprecated): \n"
-" If the client does not support Asterisk \"html\" transport, \n"
-" and there exists a step with priority n + 101, then execution will\n"
-" continue at that step.\n"
-" Otherwise, execution will continue at the next priority level.\n"
-" SendURL only returns 0 if the URL was sent correctly or if\n"
-" the channel does not support HTML transport, and -1 otherwise.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int sendurl_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- char *tmp;
- char *options;
- int local_option_wait=0;
- int local_option_jump = 0;
- struct ast_frame *f;
- char *stringp=NULL;
- char *status = "FAILURE";
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
- pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- tmp = ast_strdupa(data);
- if (!tmp) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- stringp=tmp;
- strsep(&stringp, "|");
- options = strsep(&stringp, "|");
- if (options && !strcasecmp(options, "wait"))
- local_option_wait = 1;
- if (options && !strcasecmp(options, "j"))
- local_option_jump = 1;
-
- if (!ast_channel_supports_html(chan)) {
- /* Does not support transport */
- if (local_option_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- res = ast_channel_sendurl(chan, tmp);
- if (res == -1) {
- pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
- LOCAL_USER_REMOVE(u);
- return res;
- }
- status = "SUCCESS";
- if (local_option_wait) {
- for(;;) {
- /* Wait for an event */
- res = ast_waitfor(chan, -1);
- if (res < 0)
- break;
- f = ast_read(chan);
- if (!f) {
- res = -1;
- status = "FAILURE";
- break;
- }
- if (f->frametype == AST_FRAME_HTML) {
- switch(f->subclass) {
- case AST_HTML_LDCOMPLETE:
- res = 0;
- ast_frfree(f);
- status = "NOLOAD";
- goto out;
- break;
- case AST_HTML_NOSUPPORT:
- /* Does not support transport */
- status ="UNSUPPORTED";
- if (local_option_jump || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- res = 0;
- goto out;
- break;
- default:
- ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
- };
- }
- ast_frfree(f);
- }
- }
-out:
- pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, sendurl_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_userevent.c b/1.2-netsec/apps/app_userevent.c
deleted file mode 100644
index 95f5fbc84..000000000
--- a/1.2-netsec/apps/app_userevent.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * 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 UserEvent application -- send manager event
- *
- * \ingroup applications
- */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/manager.h"
-
-static char *tdesc = "Custom User Event Application";
-
-static char *app = "UserEvent";
-
-static char *synopsis = "Send an arbitrary event to the manager interface";
-
-static char *descrip =
-" UserEvent(eventname[|body]): Sends an arbitrary event to the\n"
-"manager interface, with an optional body representing additional\n"
-"arguments. The format of the event will be:\n"
-" Event: UserEvent<specified event name>\n"
-" Channel: <channel name>\n"
-" Uniqueid: <call uniqueid>\n"
-" [body]\n"
-"If the body is not specified, only Event, Channel, and Uniqueid fields\n"
-"will be present. Returns 0.";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int userevent_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- char *info;
- char eventname[512];
- char *eventbody;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "UserEvent requires an argument (eventname|optional event body)\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- info = ast_strdupa(data);
- if (!info) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- snprintf(eventname, sizeof(eventname), "UserEvent%s", info);
- eventbody = strchr(eventname, '|');
- if (eventbody) {
- *eventbody = '\0';
- eventbody++;
- }
-
- if(eventbody) {
- ast_log(LOG_DEBUG, "Sending user event: %s, %s\n", eventname, eventbody);
- manager_event(EVENT_FLAG_USER, eventname,
- "Channel: %s\r\nUniqueid: %s\r\n%s\r\n",
- chan->name, chan->uniqueid, eventbody);
- } else {
- ast_log(LOG_DEBUG, "Sending user event: %s\n", eventname);
- manager_event(EVENT_FLAG_USER, eventname,
- "Channel: %s\r\nUniqueid: %s\r\n", chan->name, chan->uniqueid);
- }
-
- LOCAL_USER_REMOVE(u);
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, userevent_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_verbose.c b/1.2-netsec/apps/app_verbose.c
deleted file mode 100644
index 6ed1e4820..000000000
--- a/1.2-netsec/apps/app_verbose.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (c) 2004 - 2005 Tilghman Lesher. All rights reserved.
- *
- * Tilghman Lesher <app_verbose_v001@the-tilghman.com>
- *
- * This code is released by the author with no restrictions on usage.
- *
- * 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.
- *
- */
-
-/*! \file
- *
- * \brief Verbose logging application
- *
- * \ingroup applications
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/options.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-
-
-static char *tdesc = "Send verbose output";
-
-static char *app_verbose = "Verbose";
-
-static char *verbose_synopsis = "Send arbitrary text to verbose output";
-
-static char *verbose_descrip =
-"Verbose([<level>|]<message>)\n"
-" level must be an integer value. If not specified, defaults to 0.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int verbose_exec(struct ast_channel *chan, void *data)
-{
- char *vtext;
- int vsize;
- struct localuser *u;
-
- LOCAL_USER_ADD(u);
-
- if (data) {
- vtext = ast_strdupa((char *)data);
- if (vtext) {
- char *tmp = strsep(&vtext, "|,");
- if (vtext) {
- if (sscanf(tmp, "%d", &vsize) != 1) {
- vsize = 0;
- ast_log(LOG_WARNING, "'%s' is not a verboser number\n", vtext);
- }
- } else {
- vtext = tmp;
- vsize = 0;
- }
- if (option_verbose >= vsize) {
- switch (vsize) {
- case 0:
- ast_verbose("%s\n", vtext);
- break;
- case 1:
- ast_verbose(VERBOSE_PREFIX_1 "%s\n", vtext);
- break;
- case 2:
- ast_verbose(VERBOSE_PREFIX_2 "%s\n", vtext);
- break;
- case 3:
- ast_verbose(VERBOSE_PREFIX_3 "%s\n", vtext);
- break;
- default:
- ast_verbose(VERBOSE_PREFIX_4 "%s\n", vtext);
- }
- }
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- }
- }
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app_verbose);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_voicemail.c b/1.2-netsec/apps/app_voicemail.c
deleted file mode 100644
index 43eb4fb66..000000000
--- a/1.2-netsec/apps/app_voicemail.c
+++ /dev/null
@@ -1,6732 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Comedian Mail - Voicemail System
- *
- * \par See also
- * \arg \ref Config_vm
- * \ingroup applications
- */
-
-/*
- * 12-16-2004 : Support for Greek added by InAccess Networks (work funded by HOL, www.hol.gr)
- * George Konstantoulakis <gkon@inaccessnetworks.com>
- *
- * 05-10-2005 : Support for Swedish and Norwegian added by Daniel Nylander, http://www.danielnylander.se/
- *
- * 05-11-2005 : An option for maximum number of messsages per mailbox added by GDS Partners (www.gdspartners.com)
- * 07-11-2005 : An issue with voicemail synchronization has been fixed by GDS Partners (www.gdspartners.com)
- * Stojan Sljivic <stojan.sljivic@gdspartners.com>
- *
- */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <time.h>
-#include <dirent.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/config.h"
-#include "asterisk/say.h"
-#include "asterisk/module.h"
-#include "asterisk/adsi.h"
-#include "asterisk/app.h"
-#include "asterisk/manager.h"
-#include "asterisk/dsp.h"
-#include "asterisk/localtime.h"
-#include "asterisk/cli.h"
-#include "asterisk/utils.h"
-#ifdef USE_ODBC_STORAGE
-#include "asterisk/res_odbc.h"
-#endif
-
-#define COMMAND_TIMEOUT 5000
-#define VOICEMAIL_DIR_MODE 0700
-#define VOICEMAIL_FILE_MODE 0600
-
-#define VOICEMAIL_CONFIG "voicemail.conf"
-#define ASTERISK_USERNAME "asterisk"
-
-/* Default mail command to mail voicemail. Change it with the
- mailcmd= command in voicemail.conf */
-#define SENDMAIL "/usr/sbin/sendmail -t"
-
-#define INTRO "vm-intro"
-
-#define MAXMSG 100
-#define MAXMSGLIMIT 9999
-
-#define BASEMAXINLINE 256
-#define BASELINELEN 72
-#define BASEMAXINLINE 256
-#define eol "\r\n"
-
-#define MAX_DATETIME_FORMAT 512
-#define MAX_NUM_CID_CONTEXTS 10
-
-#define VM_REVIEW (1 << 0)
-#define VM_OPERATOR (1 << 1)
-#define VM_SAYCID (1 << 2)
-#define VM_SVMAIL (1 << 3)
-#define VM_ENVELOPE (1 << 4)
-#define VM_SAYDURATION (1 << 5)
-#define VM_SKIPAFTERCMD (1 << 6)
-#define VM_FORCENAME (1 << 7) /*!< Have new users record their name */
-#define VM_FORCEGREET (1 << 8) /*!< Have new users record their greetings */
-#define VM_PBXSKIP (1 << 9)
-#define VM_DIRECFORWARD (1 << 10) /*!< directory_forward */
-#define VM_ATTACH (1 << 11)
-#define VM_DELETE (1 << 12)
-#define VM_ALLOCED (1 << 13)
-#define VM_SEARCH (1 << 14)
-
-#define ERROR_LOCK_PATH -100
-
-enum {
- OPT_SILENT = (1 << 0),
- OPT_BUSY_GREETING = (1 << 1),
- OPT_UNAVAIL_GREETING = (1 << 2),
- OPT_RECORDGAIN = (1 << 3),
- OPT_PREPEND_MAILBOX = (1 << 4),
- OPT_PRIORITY_JUMP = (1 << 5),
-} vm_option_flags;
-
-enum {
- OPT_ARG_RECORDGAIN = 0,
- OPT_ARG_ARRAY_SIZE = 1,
-} vm_option_args;
-
-AST_APP_OPTIONS(vm_app_options, {
- AST_APP_OPTION('s', OPT_SILENT),
- AST_APP_OPTION('b', OPT_BUSY_GREETING),
- AST_APP_OPTION('u', OPT_UNAVAIL_GREETING),
- AST_APP_OPTION_ARG('g', OPT_RECORDGAIN, OPT_ARG_RECORDGAIN),
- AST_APP_OPTION('p', OPT_PREPEND_MAILBOX),
- AST_APP_OPTION('j', OPT_PRIORITY_JUMP),
-});
-
-static int load_config(void);
-
-/*! \page vmlang Voicemail Language Syntaxes Supported
-
- \par Syntaxes supported, not really language codes.
- \arg \b en - English
- \arg \b de - German
- \arg \b es - Spanish
- \arg \b fr - French
- \arg \b it = Italian
- \arg \b nl - Dutch
- \arg \b pt - Portuguese
- \arg \b gr - Greek
- \arg \b no - Norwegian
- \arg \b se - Swedish
-
-German requires the following additional soundfile:
-\arg \b 1F einE (feminine)
-
-Spanish requires the following additional soundfile:
-\arg \b 1M un (masculine)
-
-Dutch, Portuguese & Spanish require the following additional soundfiles:
-\arg \b vm-INBOXs singular of 'new'
-\arg \b vm-Olds singular of 'old/heard/read'
-
-NB these are plural:
-\arg \b vm-INBOX nieuwe (nl)
-\arg \b vm-Old oude (nl)
-
-Swedish uses:
-\arg \b vm-nytt singular of 'new'
-\arg \b vm-nya plural of 'new'
-\arg \b vm-gammalt singular of 'old'
-\arg \b vm-gamla plural of 'old'
-\arg \b digits/ett 'one', not always same as 'digits/1'
-
-Norwegian uses:
-\arg \b vm-ny singular of 'new'
-\arg \b vm-nye plural of 'new'
-\arg \b vm-gammel singular of 'old'
-\arg \b vm-gamle plural of 'old'
-
-Dutch also uses:
-\arg \b nl-om 'at'?
-
-Spanish also uses:
-\arg \b vm-youhaveno
-
-Italian requires the following additional soundfile:
-
-For vm_intro_it:
-\arg \b vm-nuovo new
-\arg \b vm-nuovi new plural
-\arg \b vm-vecchio old
-\arg \b vm-vecchi old plural
-
-\note Don't use vm-INBOX or vm-Old, because they are the name of the INBOX and Old folders,
-spelled among others when you have to change folder. For the above reasons, vm-INBOX
-and vm-Old are spelled plural, to make them sound more as folder name than an adjective.
-
-*/
-
-struct baseio {
- int iocp;
- int iolen;
- int linelength;
- int ateof;
- unsigned char iobuf[BASEMAXINLINE];
-};
-
-/*! Structure for linked list of users */
-struct ast_vm_user {
- char context[AST_MAX_CONTEXT]; /*!< Voicemail context */
- char mailbox[AST_MAX_EXTENSION];/*!< Mailbox id, unique within vm context */
- char password[80]; /*!< Secret pin code, numbers only */
- char fullname[80]; /*!< Full name, for directory app */
- char email[80]; /*!< E-mail address */
- char pager[80]; /*!< E-mail address to pager (no attachment) */
- char serveremail[80]; /*!< From: Mail address */
- char mailcmd[160]; /*!< Configurable mail command */
- char language[MAX_LANGUAGE]; /*!< Config: Language setting */
- char zonetag[80]; /*!< Time zone */
- char callback[80];
- char dialout[80];
- char uniqueid[20]; /*!< Unique integer identifier */
- char exit[80];
- unsigned int flags; /*!< VM_ flags */
- int saydurationm;
- int maxmsg; /*!< Maximum number of msgs per folder for this mailbox */
- struct ast_vm_user *next;
-};
-
-struct vm_zone {
- char name[80];
- char timezone[80];
- char msg_format[512];
- struct vm_zone *next;
-};
-
-struct vm_state {
- char curbox[80];
- char username[80];
- char curdir[256];
- char vmbox[256];
- char fn[256];
- char fn2[256];
- int *deleted;
- int *heard;
- int curmsg;
- int lastmsg;
- int newmessages;
- int oldmessages;
- int starting;
- int repeats;
-};
-static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, int msg,
- int option, signed char record_gain);
-static int dialout(struct ast_channel *chan, struct ast_vm_user *vmu, char *num, char *outgoing_context);
-static int play_record_review(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime,
- char *fmt, int outsidecaller, struct ast_vm_user *vmu, int *duration, const char *unlockdir,
- signed char record_gain);
-static int vm_tempgreeting(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, char *fmtc, signed char record_gain);
-static int vm_play_folder_name(struct ast_channel *chan, char *mbox);
-
-static void apply_options(struct ast_vm_user *vmu, const char *options);
-
-#ifdef USE_ODBC_STORAGE
-static char odbc_database[80];
-static char odbc_table[80];
-#define RETRIEVE(a,b) retrieve_file(a,b)
-#define DISPOSE(a,b) remove_file(a,b)
-#define STORE(a,b,c,d) store_file(a,b,c,d)
-#define EXISTS(a,b,c,d) (message_exists(a,b))
-#define RENAME(a,b,c,d,e,f,g,h) (rename_file(a,b,c,d,e,f))
-#define COPY(a,b,c,d,e,f,g,h) (copy_file(a,b,c,d,e,f))
-#define DELETE(a,b,c) (delete_file(a,b))
-#else
-#define RETRIEVE(a,b)
-#define DISPOSE(a,b)
-#define STORE(a,b,c,d)
-#define EXISTS(a,b,c,d) (ast_fileexists(c,NULL,d) > 0)
-#define RENAME(a,b,c,d,e,f,g,h) (rename_file(g,h));
-#define COPY(a,b,c,d,e,f,g,h) (copy_file(g,h));
-#define DELETE(a,b,c) (vm_delete(c))
-#endif
-
-static char VM_SPOOL_DIR[AST_CONFIG_MAX_PATH];
-
-static char ext_pass_cmd[128];
-
-static char *tdesc = "Comedian Mail (Voicemail System)";
-
-static char *addesc = "Comedian Mail";
-
-static char *synopsis_vm =
-"Leave a Voicemail message";
-
-static char *descrip_vm =
-" VoiceMail(mailbox[@context][&mailbox[@context]][...][|options]): This\n"
-"application allows the calling party to leave a message for the specified\n"
-"list of mailboxes. When multiple mailboxes are specified, the greeting will\n"
-"be taken from the first mailbox specified. Dialplan execution will stop if the\n"
-"specified mailbox does not exist.\n"
-" The Voicemail application will exit if any of the following DTMF digits are\n"
-"received:\n"
-" 0 - Jump to the 'o' extension in the current dialplan context.\n"
-" * - Jump to the 'a' extension in the current dialplan context.\n"
-" This application will set the following channel variable upon completion:\n"
-" VMSTATUS - This indicates the status of the execution of the VoiceMail\n"
-" application. The possible values are:\n"
-" SUCCESS | USEREXIT | FAILED\n\n"
-" Options:\n"
-" b - Play the 'busy' greeting to the calling party.\n"
-" g(#) - Use the specified amount of gain when recording the voicemail\n"
-" message. The units are whole-number decibels (dB).\n"
-" s - Skip the playback of instructions for leaving a message to the\n"
-" calling party.\n"
-" u - Play the 'unavailble greeting.\n"
-" j - Jump to priority n+101 if the mailbox is not found or some other\n"
-" error occurs.\n";
-
-static char *synopsis_vmain =
-"Check Voicemail messages";
-
-static char *descrip_vmain =
-" VoiceMailMain([mailbox][@context][|options]): This application allows the\n"
-"calling party to check voicemail messages. A specific mailbox, and optional\n"
-"corresponding context, may be specified. If a mailbox is not provided, the\n"
-"calling party will be prompted to enter one. If a context is not specified,\n"
-"the 'default' context will be used.\n\n"
-" Options:\n"
-" p - Consider the mailbox parameter as a prefix to the mailbox that\n"
-" is entered by the caller.\n"
-" g(#) - Use the specified amount of gain when recording a voicemail\n"
-" message. The units are whole-number decibels (dB).\n"
-" s - Skip checking the passcode for the mailbox.\n";
-
-static char *synopsis_vm_box_exists =
-"Check to see if Voicemail mailbox exists";
-
-static char *descrip_vm_box_exists =
-" MailboxExists(mailbox[@context][|options]): Check to see if the specified\n"
-"mailbox exists. If no voicemail context is specified, the 'default' context\n"
-"will be used.\n"
-" This application will set the following channel variable upon completion:\n"
-" VMBOXEXISTSSTATUS - This will contain the status of the execution of the\n"
-" MailboxExists application. Possible values include:\n"
-" SUCCESS | FAILED\n\n"
-" Options:\n"
-" j - Jump to priority n+101 if the mailbox is found.\n";
-
-static char *synopsis_vmauthenticate =
-"Authenticate with Voicemail passwords";
-
-static char *descrip_vmauthenticate =
-" VMAuthenticate([mailbox][@context][|options]): This application behaves the\n"
-"same way as the Authenticate application, but the passwords are taken from\n"
-"voicemail.conf.\n"
-" If the mailbox is specified, only that mailbox's password will be considered\n"
-"valid. If the mailbox is not specified, the channel variable AUTH_MAILBOX will\n"
-"be set with the authenticated mailbox.\n\n"
-" Options:\n"
-" s - Skip playing the initial prompts.\n";
-
-/* Leave a message */
-static char *app = "VoiceMail";
-
-/* Check mail, control, etc */
-static char *app2 = "VoiceMailMain";
-
-static char *app3 = "MailboxExists";
-static char *app4 = "VMAuthenticate";
-
-AST_MUTEX_DEFINE_STATIC(vmlock);
-struct ast_vm_user *users;
-struct ast_vm_user *usersl;
-struct vm_zone *zones = NULL;
-struct vm_zone *zonesl = NULL;
-static int maxsilence;
-static int maxmsg;
-static int silencethreshold = 128;
-static char serveremail[80];
-static char mailcmd[160]; /* Configurable mail cmd */
-static char externnotify[160];
-
-static char vmfmts[80];
-static int vmminmessage;
-static int vmmaxmessage;
-static int maxgreet;
-static int skipms;
-static int maxlogins;
-
-static struct ast_flags globalflags = {0};
-
-static int saydurationminfo;
-
-static char dialcontext[AST_MAX_CONTEXT];
-static char callcontext[AST_MAX_CONTEXT];
-static char exitcontext[AST_MAX_CONTEXT];
-
-static char cidinternalcontexts[MAX_NUM_CID_CONTEXTS][64];
-
-
-static char *emailbody = NULL;
-static char *emailsubject = NULL;
-static char *pagerbody = NULL;
-static char *pagersubject = NULL;
-static char fromstring[100];
-static char pagerfromstring[100];
-static char emailtitle[100];
-static char charset[32] = "ISO-8859-1";
-
-static unsigned char adsifdn[4] = "\x00\x00\x00\x0F";
-static unsigned char adsisec[4] = "\x9B\xDB\xF7\xAC";
-static int adsiver = 1;
-static char emaildateformat[32] = "%A, %B %d, %Y at %r";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static void populate_defaults(struct ast_vm_user *vmu)
-{
- ast_copy_flags(vmu, (&globalflags), AST_FLAGS_ALL);
- if (saydurationminfo)
- vmu->saydurationm = saydurationminfo;
- if (callcontext)
- ast_copy_string(vmu->callback, callcontext, sizeof(vmu->callback));
- if (dialcontext)
- ast_copy_string(vmu->dialout, dialcontext, sizeof(vmu->dialout));
- if (exitcontext)
- ast_copy_string(vmu->exit, exitcontext, sizeof(vmu->exit));
- if (maxmsg)
- vmu->maxmsg = maxmsg;
-}
-
-static void apply_option(struct ast_vm_user *vmu, const char *var, const char *value)
-{
- int x;
- if (!strcasecmp(var, "attach")) {
- ast_set2_flag(vmu, ast_true(value), VM_ATTACH);
- } else if (!strcasecmp(var, "serveremail")) {
- ast_copy_string(vmu->serveremail, value, sizeof(vmu->serveremail));
- } else if (!strcasecmp(var, "language")) {
- ast_copy_string(vmu->language, value, sizeof(vmu->language));
- } else if (!strcasecmp(var, "tz")) {
- ast_copy_string(vmu->zonetag, value, sizeof(vmu->zonetag));
- } else if (!strcasecmp(var, "delete") || !strcasecmp(var, "deletevoicemail")) {
- ast_set2_flag(vmu, ast_true(value), VM_DELETE);
- } else if (!strcasecmp(var, "saycid")){
- ast_set2_flag(vmu, ast_true(value), VM_SAYCID);
- } else if (!strcasecmp(var,"sendvoicemail")){
- ast_set2_flag(vmu, ast_true(value), VM_SVMAIL);
- } else if (!strcasecmp(var, "review")){
- ast_set2_flag(vmu, ast_true(value), VM_REVIEW);
- } else if (!strcasecmp(var, "operator")){
- ast_set2_flag(vmu, ast_true(value), VM_OPERATOR);
- } else if (!strcasecmp(var, "envelope")){
- ast_set2_flag(vmu, ast_true(value), VM_ENVELOPE);
- } else if (!strcasecmp(var, "sayduration")){
- ast_set2_flag(vmu, ast_true(value), VM_SAYDURATION);
- } else if (!strcasecmp(var, "saydurationm")){
- if (sscanf(value, "%d", &x) == 1) {
- vmu->saydurationm = x;
- } else {
- ast_log(LOG_WARNING, "Invalid min duration for say duration\n");
- }
- } else if (!strcasecmp(var, "forcename")){
- ast_set2_flag(vmu, ast_true(value), VM_FORCENAME);
- } else if (!strcasecmp(var, "forcegreetings")){
- ast_set2_flag(vmu, ast_true(value), VM_FORCEGREET);
- } else if (!strcasecmp(var, "callback")) {
- ast_copy_string(vmu->callback, value, sizeof(vmu->callback));
- } else if (!strcasecmp(var, "dialout")) {
- ast_copy_string(vmu->dialout, value, sizeof(vmu->dialout));
- } else if (!strcasecmp(var, "exitcontext")) {
- ast_copy_string(vmu->exit, value, sizeof(vmu->exit));
- } else if (!strcasecmp(var, "maxmsg")) {
- vmu->maxmsg = atoi(value);
- if (vmu->maxmsg <= 0) {
- ast_log(LOG_WARNING, "Invalid number of messages per folder maxmsg=%s. Using default value %i\n", value, MAXMSG);
- vmu->maxmsg = MAXMSG;
- } else if (vmu->maxmsg > MAXMSGLIMIT) {
- ast_log(LOG_WARNING, "Maximum number of messages per folder is %i. Cannot accept value maxmsg=%s\n", MAXMSGLIMIT, value);
- vmu->maxmsg = MAXMSGLIMIT;
- }
- } else if (!strcasecmp(var, "options")) {
- apply_options(vmu, value);
- }
-}
-
-static int change_password_realtime(struct ast_vm_user *vmu, const char *password)
-{
- int res;
- if (!ast_strlen_zero(vmu->uniqueid)) {
- res = ast_update_realtime("voicemail", "uniqueid", vmu->uniqueid, "password", password, NULL);
- if (res > 0) {
- ast_copy_string(vmu->password, password, sizeof(vmu->password));
- res = 0;
- } else if (!res) {
- res = -1;
- }
- return res;
- }
- return -1;
-}
-
-static void apply_options(struct ast_vm_user *vmu, const char *options)
-{ /* Destructively Parse options and apply */
- char *stringp;
- char *s;
- char *var, *value;
- stringp = ast_strdupa(options);
- while ((s = strsep(&stringp, "|"))) {
- value = s;
- if ((var = strsep(&value, "=")) && value) {
- apply_option(vmu, var, value);
- }
- }
-}
-
-static struct ast_vm_user *find_user_realtime(struct ast_vm_user *ivm, const char *context, const char *mailbox)
-{
- struct ast_variable *var, *tmp;
- struct ast_vm_user *retval;
-
- if (ivm)
- retval=ivm;
- else
- retval=malloc(sizeof(struct ast_vm_user));
-
- if (retval) {
- memset(retval, 0, sizeof(struct ast_vm_user));
- if (!ivm)
- ast_set_flag(retval, VM_ALLOCED);
- if (mailbox)
- ast_copy_string(retval->mailbox, mailbox, sizeof(retval->mailbox));
- populate_defaults(retval);
- if (!context && ast_test_flag((&globalflags), VM_SEARCH))
- var = ast_load_realtime("voicemail", "mailbox", mailbox, NULL);
- else
- var = ast_load_realtime("voicemail", "mailbox", mailbox, "context", context, NULL);
- if (var) {
- tmp = var;
- while(tmp) {
- printf("%s => %s\n", tmp->name, tmp->value);
- if (!strcasecmp(tmp->name, "password")) {
- ast_copy_string(retval->password, tmp->value, sizeof(retval->password));
- } else if (!strcasecmp(tmp->name, "uniqueid")) {
- ast_copy_string(retval->uniqueid, tmp->value, sizeof(retval->uniqueid));
- } else if (!strcasecmp(tmp->name, "pager")) {
- ast_copy_string(retval->pager, tmp->value, sizeof(retval->pager));
- } else if (!strcasecmp(tmp->name, "email")) {
- ast_copy_string(retval->email, tmp->value, sizeof(retval->email));
- } else if (!strcasecmp(tmp->name, "fullname")) {
- ast_copy_string(retval->fullname, tmp->value, sizeof(retval->fullname));
- } else if (!strcasecmp(tmp->name, "context")) {
- ast_copy_string(retval->context, tmp->value, sizeof(retval->context));
- } else
- apply_option(retval, tmp->name, tmp->value);
- tmp = tmp->next;
- }
- } else {
- if (!ivm)
- free(retval);
- retval = NULL;
- }
- }
- return retval;
-}
-
-static struct ast_vm_user *find_user(struct ast_vm_user *ivm, const char *context, const char *mailbox)
-{
- /* This function could be made to generate one from a database, too */
- struct ast_vm_user *vmu=NULL, *cur;
- ast_mutex_lock(&vmlock);
- cur = users;
-
- if (!context && !ast_test_flag((&globalflags), VM_SEARCH))
- context = "default";
-
- while (cur) {
- if (ast_test_flag((&globalflags), VM_SEARCH) && !strcasecmp(mailbox, cur->mailbox))
- break;
- if (context && (!strcasecmp(context, cur->context)) && (!strcasecmp(mailbox, cur->mailbox)))
- break;
- cur=cur->next;
- }
- if (cur) {
- if (ivm)
- vmu = ivm;
- else
- /* Make a copy, so that on a reload, we have no race */
- vmu = malloc(sizeof(struct ast_vm_user));
- if (vmu) {
- memcpy(vmu, cur, sizeof(struct ast_vm_user));
- ast_set2_flag(vmu, !ivm, VM_ALLOCED);
- vmu->next = NULL;
- }
- } else
- vmu = find_user_realtime(ivm, context, mailbox);
- ast_mutex_unlock(&vmlock);
- return vmu;
-}
-
-static int reset_user_pw(const char *context, const char *mailbox, const char *newpass)
-{
- /* This function could be made to generate one from a database, too */
- struct ast_vm_user *cur;
- int res = -1;
- ast_mutex_lock(&vmlock);
- cur = users;
- while (cur) {
- if ((!context || !strcasecmp(context, cur->context)) &&
- (!strcasecmp(mailbox, cur->mailbox)))
- break;
- cur=cur->next;
- }
- if (cur) {
- ast_copy_string(cur->password, newpass, sizeof(cur->password));
- res = 0;
- }
- ast_mutex_unlock(&vmlock);
- return res;
-}
-
-static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
-{
- /* There's probably a better way of doing this. */
- /* That's why I've put the password change in a separate function. */
- /* This could also be done with a database function */
-
- FILE *configin;
- FILE *configout;
- int linenum=0;
- char inbuf[256];
- char orig[256];
- char currcontext[256] ="";
- char tmpin[AST_CONFIG_MAX_PATH];
- char tmpout[AST_CONFIG_MAX_PATH];
- struct stat statbuf;
-
- if (!change_password_realtime(vmu, newpassword))
- return;
-
- snprintf(tmpin, sizeof(tmpin), "%s/voicemail.conf", ast_config_AST_CONFIG_DIR);
- snprintf(tmpout, sizeof(tmpout), "%s/voicemail.conf.new", ast_config_AST_CONFIG_DIR);
- configin = fopen(tmpin,"r");
- if (configin)
- configout = fopen(tmpout,"w+");
- else
- configout = NULL;
- if (!configin || !configout) {
- if (configin)
- fclose(configin);
- else
- ast_log(LOG_WARNING, "Warning: Unable to open '%s' for reading: %s\n", tmpin, strerror(errno));
- if (configout)
- fclose(configout);
- else
- ast_log(LOG_WARNING, "Warning: Unable to open '%s' for writing: %s\n", tmpout, strerror(errno));
- return;
- }
-
- while (!feof(configin)) {
- char *user = NULL, *pass = NULL, *rest = NULL, *comment = NULL, *tmpctx = NULL, *tmpctxend = NULL;
-
- /* Read in the line */
- fgets(inbuf, sizeof(inbuf), configin);
- linenum++;
-
- if (ast_strlen_zero(inbuf)) {
- fprintf(configout, "\n");
- continue;
- }
-
- /* Make a backup of it */
- ast_copy_string(orig, inbuf, sizeof(orig));
-
- /*
- Read the file line by line, split each line into a comment and command section
- only parse the command portion of the line
- */
- if (inbuf[strlen(inbuf) - 1] == '\n')
- inbuf[strlen(inbuf) - 1] = '\0';
-
- if ((comment = strchr(inbuf, ';')))
- *comment++ = '\0'; /* Now inbuf is terminated just before the comment */
-
- if (ast_strlen_zero(inbuf)) {
- fprintf(configout, "%s", orig);
- continue;
- }
-
- /* Check for a context, first '[' to first ']' */
- if ((tmpctx = strchr(inbuf, '['))) {
- tmpctxend = strchr(tmpctx, ']');
- if (tmpctxend) {
- /* Valid context */
- ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx);
- fprintf(configout, "%s", orig);
- continue;
- }
- }
-
- /* This isn't a context line, check for MBX => PSWD... */
- user = inbuf;
- if ((pass = strchr(user, '='))) {
- /* We have a line in the form of aaaaa=aaaaaa */
- *pass++ = '\0';
-
- user = ast_strip(user);
-
- if (*pass == '>')
- *pass++ = '\0';
-
- pass = ast_skip_blanks(pass);
-
- /*
- Since no whitespace allowed in fields, or more correctly white space
- inside the fields is there for a purpose, we can just terminate pass
- at the comma or EOL whichever comes first.
- */
- if ((rest = strchr(pass, ',')))
- *rest++ = '\0';
- } else {
- user = NULL;
- }
-
- /* Compare user, pass AND context */
- if (!ast_strlen_zero(user) && !strcmp(user, vmu->mailbox) &&
- !ast_strlen_zero(pass) && !strcmp(pass, vmu->password) &&
- !strcasecmp(currcontext, vmu->context)) {
- /* This is the line */
- if (rest) {
- fprintf(configout, "%s => %s,%s", user, newpassword, rest);
- } else {
- fprintf(configout, "%s => %s", user, newpassword);
- }
- /* If there was a comment on the line print it out */
- if (comment) {
- fprintf(configout, ";%s\n", comment);
- } else {
- fprintf(configout, "\n");
- }
- } else {
- /* Put it back like it was */
- fprintf(configout, "%s", orig);
- }
- }
- fclose(configin);
- fclose(configout);
-
- stat(tmpin, &statbuf);
- chmod(tmpout, statbuf.st_mode);
- chown(tmpout, statbuf.st_uid, statbuf.st_gid);
- unlink(tmpin);
- rename(tmpout, tmpin);
- reset_user_pw(vmu->context, vmu->mailbox, newpassword);
- ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
-}
-
-static void vm_change_password_shell(struct ast_vm_user *vmu, char *newpassword)
-{
- char buf[255];
- snprintf(buf,255,"%s %s %s %s",ext_pass_cmd,vmu->context,vmu->mailbox,newpassword);
- if (!ast_safe_system(buf))
- ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
-}
-
-static int make_dir(char *dest, int len, char *context, char *ext, char *mailbox)
-{
- return snprintf(dest, len, "%s%s/%s/%s", VM_SPOOL_DIR, context, ext, mailbox);
-}
-
-static int make_file(char *dest, int len, char *dir, int num)
-{
- return snprintf(dest, len, "%s/msg%04d", dir, num);
-}
-
-/** basically mkdir -p $dest/$context/$ext/$mailbox
- * @dest String. base directory.
- * @context String. Ignored if is null or empty string.
- * @ext String. Ignored if is null or empty string.
- * @mailbox String. Ignored if is null or empty string.
- * @returns 0 on failure, 1 on success.
- * */
-static int create_dirpath(char *dest, int len, char *context, char *ext, char *mailbox)
-{
- mode_t mode = VOICEMAIL_DIR_MODE;
-
- if(context && context[0] != '\0') {
- make_dir(dest, len, context, "", "");
- if(mkdir(dest, mode) && errno != EEXIST) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
- return 0;
- }
- }
- if(ext && ext[0] != '\0') {
- make_dir(dest, len, context, ext, "");
- if(mkdir(dest, mode) && errno != EEXIST) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
- return 0;
- }
- }
- if(mailbox && mailbox[0] != '\0') {
- make_dir(dest, len, context, ext, mailbox);
- if(mkdir(dest, mode) && errno != EEXIST) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
- return 0;
- }
- }
- return 1;
-}
-
-/* only return failure if ast_lock_path returns 'timeout',
- not if the path does not exist or any other reason
-*/
-static int vm_lock_path(const char *path)
-{
- switch (ast_lock_path(path)) {
- case AST_LOCK_TIMEOUT:
- return -1;
- default:
- return 0;
- }
-}
-
-
-#ifdef USE_ODBC_STORAGE
-static int retrieve_file(char *dir, int msgnum)
-{
- int x = 0;
- int res;
- int fd=-1;
- size_t fdlen = 0;
- void *fdm=NULL;
- SQLSMALLINT colcount=0;
- SQLHSTMT stmt;
- char sql[256];
- char fmt[80]="";
- char *c;
- char coltitle[256];
- SQLSMALLINT collen;
- SQLSMALLINT datatype;
- SQLSMALLINT decimaldigits;
- SQLSMALLINT nullable;
- SQLULEN colsize;
- FILE *f=NULL;
- char rowdata[80];
- char fn[256];
- char full_fn[256];
- char msgnums[80];
-
- odbc_obj *obj;
- obj = fetch_odbc_obj(odbc_database, 0);
- if (obj) {
- ast_copy_string(fmt, vmfmts, sizeof(fmt));
- c = strchr(fmt, '|');
- if (c)
- *c = '\0';
- if (!strcasecmp(fmt, "wav49"))
- strcpy(fmt, "WAV");
- snprintf(msgnums, sizeof(msgnums),"%d", msgnum);
- if (msgnum > -1)
- make_file(fn, sizeof(fn), dir, msgnum);
- else
- ast_copy_string(fn, dir, sizeof(fn));
- snprintf(full_fn, sizeof(full_fn), "%s.txt", fn);
- f = fopen(full_fn, "w+");
- snprintf(full_fn, sizeof(full_fn), "%s.%s", fn, fmt);
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
- snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE dir=? AND msgnum=?",odbc_table);
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(dir), 0, (void *)dir, 0, NULL);
- SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnums), 0, (void *)msgnums, 0, NULL);
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLFetch(stmt);
- if (res == SQL_NO_DATA) {
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- else if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLNumResultCols(stmt, &colcount);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- if (f)
- fprintf(f, "[message]\n");
- for (x=0;x<colcount;x++) {
- rowdata[0] = '\0';
- collen = sizeof(coltitle);
- res = SQLDescribeCol(stmt, x + 1, coltitle, sizeof(coltitle), &collen,
- &datatype, &colsize, &decimaldigits, &nullable);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- if (!strcasecmp(coltitle, "recording")) {
- res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize);
- fdlen = colsize;
- fd = open(full_fn, O_RDWR | O_TRUNC | O_CREAT, 0770);
- if (fd > -1) {
- char tmp[1]="";
- lseek(fd, fdlen - 1, SEEK_SET);
- if (write(fd, tmp, 1) != 1) {
- close(fd);
- fd = -1;
- }
- if (fd > -1)
- fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- }
- if (fdm) {
- memset(fdm, 0, fdlen);
- res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- }
- } else {
- res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- if (strcasecmp(coltitle, "msgnum") && strcasecmp(coltitle, "dir") && f)
- fprintf(f, "%s=%s\n", coltitle, rowdata);
- }
- }
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- } else
- ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-yuck:
- if (f)
- fclose(f);
- if (fdm)
- munmap(fdm, fdlen);
- if (fd > -1)
- close(fd);
- return x - 1;
-}
-
-static int remove_file(char *dir, int msgnum)
-{
- char fn[256];
- char full_fn[256];
- char msgnums[80];
-
- if (msgnum > -1) {
- snprintf(msgnums, sizeof(msgnums), "%d", msgnum);
- make_file(fn, sizeof(fn), dir, msgnum);
- } else
- ast_copy_string(fn, dir, sizeof(fn));
- ast_filedelete(fn, NULL);
- snprintf(full_fn, sizeof(full_fn), "%s.txt", fn);
- unlink(full_fn);
- return 0;
-}
-
-static int last_message_index(struct ast_vm_user *vmu, char *dir)
-{
- int x = 0;
- int res;
- SQLHSTMT stmt;
- char sql[256];
- char rowdata[20];
-
- odbc_obj *obj;
- obj = fetch_odbc_obj(odbc_database, 0);
- if (obj) {
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
- snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=?",odbc_table);
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(dir), 0, (void *)dir, 0, NULL);
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLFetch(stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- if (sscanf(rowdata, "%d", &x) != 1)
- ast_log(LOG_WARNING, "Failed to read message count!\n");
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- } else
- ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-yuck:
- return x - 1;
-}
-
-static int message_exists(char *dir, int msgnum)
-{
- int x = 0;
- int res;
- SQLHSTMT stmt;
- char sql[256];
- char rowdata[20];
- char msgnums[20];
-
- odbc_obj *obj;
- obj = fetch_odbc_obj(odbc_database, 0);
- if (obj) {
- snprintf(msgnums, sizeof(msgnums), "%d", msgnum);
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
- snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=? AND msgnum=?",odbc_table);
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(dir), 0, (void *)dir, 0, NULL);
- SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnums), 0, (void *)msgnums, 0, NULL);
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLFetch(stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- if (sscanf(rowdata, "%d", &x) != 1)
- ast_log(LOG_WARNING, "Failed to read message count!\n");
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- } else
- ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-yuck:
- return x;
-}
-
-static int count_messages(struct ast_vm_user *vmu, char *dir)
-{
- return last_message_index(vmu, dir) + 1;
-}
-
-static void delete_file(char *sdir, int smsg)
-{
- int res;
- SQLHSTMT stmt;
- char sql[256];
- char msgnums[20];
-
- odbc_obj *obj;
- obj = fetch_odbc_obj(odbc_database, 0);
- if (obj) {
- snprintf(msgnums, sizeof(msgnums), "%d", smsg);
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
- snprintf(sql, sizeof(sql), "DELETE FROM %s WHERE dir=? AND msgnum=?",odbc_table);
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(sdir), 0, (void *)sdir, 0, NULL);
- SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnums), 0, (void *)msgnums, 0, NULL);
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- } else
- ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-yuck:
- return;
-}
-
-static void copy_file(char *sdir, int smsg, char *ddir, int dmsg, char *dmailboxuser, char *dmailboxcontext)
-{
- int res;
- SQLHSTMT stmt;
- char sql[512];
- char msgnums[20];
- char msgnumd[20];
- odbc_obj *obj;
-
- delete_file(ddir, dmsg);
- obj = fetch_odbc_obj(odbc_database, 0);
- if (obj) {
- snprintf(msgnums, sizeof(msgnums), "%d", smsg);
- snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg);
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
-#ifdef EXTENDED_ODBC_STORAGE
- snprintf(sql, sizeof(sql), "INSERT INTO %s (dir, msgnum, context, macrocontext, callerid, origtime, duration, recording, mailboxuser, mailboxcontext) SELECT ?,?,context,macrocontext,callerid,origtime,duration,recording,?,? FROM %s WHERE dir=? AND msgnum=?",odbc_table,odbc_table);
-#else
- snprintf(sql, sizeof(sql), "INSERT INTO %s (dir, msgnum, context, macrocontext, callerid, origtime, duration, recording) SELECT ?,?,context,macrocontext,callerid,origtime,duration,recording FROM %s WHERE dir=? AND msgnum=?",odbc_table,odbc_table);
-#endif
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(ddir), 0, (void *)ddir, 0, NULL);
- SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnumd), 0, (void *)msgnumd, 0, NULL);
-#ifdef EXTENDED_ODBC_STORAGE
- SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(dmailboxuser), 0, (void *)dmailboxuser, 0, NULL);
- SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(dmailboxcontext), 0, (void *)dmailboxcontext, 0, NULL);
- SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(sdir), 0, (void *)sdir, 0, NULL);
- SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnums), 0, (void *)msgnums, 0, NULL);
-#else
- SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(sdir), 0, (void *)sdir, 0, NULL);
- SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnums), 0, (void *)msgnums, 0, NULL);
-#endif
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s] (You probably don't have MySQL 4.1 or later installed)\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- } else
- ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-yuck:
- return;
-}
-
-static int store_file(char *dir, char *mailboxuser, char *mailboxcontext, int msgnum)
-{
- int x = 0;
- int res;
- int fd = -1;
- void *fdm=NULL;
- size_t fdlen = -1;
- SQLHSTMT stmt;
- SQLINTEGER len;
- char sql[256];
- char msgnums[20];
- char fn[256];
- char full_fn[256];
- char fmt[80]="";
- char *c;
- char *context="", *macrocontext="", *callerid="", *origtime="", *duration="";
- char *category = "";
- struct ast_config *cfg=NULL;
- odbc_obj *obj;
-
- delete_file(dir, msgnum);
- obj = fetch_odbc_obj(odbc_database, 0);
- if (obj) {
- ast_copy_string(fmt, vmfmts, sizeof(fmt));
- c = strchr(fmt, '|');
- if (c)
- *c = '\0';
- if (!strcasecmp(fmt, "wav49"))
- strcpy(fmt, "WAV");
- snprintf(msgnums, sizeof(msgnums),"%d", msgnum);
- if (msgnum > -1)
- make_file(fn, sizeof(fn), dir, msgnum);
- else
- ast_copy_string(fn, dir, sizeof(fn));
- snprintf(full_fn, sizeof(full_fn), "%s.txt", fn);
- cfg = ast_config_load(full_fn);
- snprintf(full_fn, sizeof(full_fn), "%s.%s", fn, fmt);
- fd = open(full_fn, O_RDWR);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Open of sound file '%s' failed: %s\n", full_fn, strerror(errno));
- goto yuck;
- }
- if (cfg) {
- context = ast_variable_retrieve(cfg, "message", "context");
- if (!context) context = "";
- macrocontext = ast_variable_retrieve(cfg, "message", "macrocontext");
- if (!macrocontext) macrocontext = "";
- callerid = ast_variable_retrieve(cfg, "message", "callerid");
- if (!callerid) callerid = "";
- origtime = ast_variable_retrieve(cfg, "message", "origtime");
- if (!origtime) origtime = "";
- duration = ast_variable_retrieve(cfg, "message", "duration");
- if (!duration) duration = "";
- category = ast_variable_retrieve(cfg, "message", "category");
- if (!category) category = "";
- }
- fdlen = lseek(fd, 0, SEEK_END);
- lseek(fd, 0, SEEK_SET);
- printf("Length is %d\n", fdlen);
- fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED,fd, 0);
- if (!fdm) {
- ast_log(LOG_WARNING, "Memory map failed!\n");
- goto yuck;
- }
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
- if (!ast_strlen_zero(category))
-#ifdef EXTENDED_ODBC_STORAGE
- snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,category) VALUES (?,?,?,?,?,?,?,?,?,?,?)",odbc_table);
-#else
- snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,category) VALUES (?,?,?,?,?,?,?,?,?)",odbc_table);
-#endif
- else
-#ifdef EXTENDED_ODBC_STORAGE
- snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext) VALUES (?,?,?,?,?,?,?,?,?,?)",odbc_table);
-#else
- snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration) VALUES (?,?,?,?,?,?,?,?)",odbc_table);
-#endif
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- len = fdlen; /* SQL_LEN_DATA_AT_EXEC(fdlen); */
- SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(dir), 0, (void *)dir, 0, NULL);
- SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnums), 0, (void *)msgnums, 0, NULL);
- SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_BINARY, fdlen, 0, (void *)fdm, fdlen, &len);
- SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(context), 0, (void *)context, 0, NULL);
- SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(macrocontext), 0, (void *)macrocontext, 0, NULL);
- SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(callerid), 0, (void *)callerid, 0, NULL);
- SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(origtime), 0, (void *)origtime, 0, NULL);
- SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(duration), 0, (void *)duration, 0, NULL);
-#ifdef EXTENDED_ODBC_STORAGE
- SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(mailboxuser), 0, (void *)mailboxuser, 0, NULL);
- SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(mailboxcontext), 0, (void *)mailboxcontext, 0, NULL);
- if (!ast_strlen_zero(category))
- SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(category), 0, (void *)category, 0, NULL);
-#else
- if (!ast_strlen_zero(category))
- SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(category), 0, (void *)category, 0, NULL);
-#endif
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- } else
- ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-yuck:
- if (cfg)
- ast_config_destroy(cfg);
- if (fdm)
- munmap(fdm, fdlen);
- if (fd > -1)
- close(fd);
- return x;
-}
-
-static void rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxcontext, char *ddir, int dmsg)
-{
- int res;
- SQLHSTMT stmt;
- char sql[256];
- char msgnums[20];
- char msgnumd[20];
- odbc_obj *obj;
-
- delete_file(ddir, dmsg);
- obj = fetch_odbc_obj(odbc_database, 0);
- if (obj) {
- snprintf(msgnums, sizeof(msgnums), "%d", smsg);
- snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg);
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
-#ifdef EXTENDED_ODBC_STORAGE
- snprintf(sql, sizeof(sql), "UPDATE %s SET dir=?, msgnum=?, mailboxuser=?, mailboxcontext=? WHERE dir=? AND msgnum=?",odbc_table);
-#else
- snprintf(sql, sizeof(sql), "UPDATE %s SET dir=?, msgnum=? WHERE dir=? AND msgnum=?",odbc_table);
-#endif
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(ddir), 0, (void *)ddir, 0, NULL);
- SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnumd), 0, (void *)msgnumd, 0, NULL);
-#ifdef EXTENDED_ODBC_STORAGE
- SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(mailboxuser), 0, (void *)mailboxuser, 0, NULL);
- SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(mailboxcontext), 0, (void *)mailboxcontext, 0, NULL);
- SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(sdir), 0, (void *)sdir, 0, NULL);
- SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnums), 0, (void *)msgnums, 0, NULL);
-#else
- SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(sdir), 0, (void *)sdir, 0, NULL);
- SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnums), 0, (void *)msgnums, 0, NULL);
-#endif
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- } else
- ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-yuck:
- return;
-}
-
-#else
-
-static int count_messages(struct ast_vm_user *vmu, char *dir)
-{
- /* Find all .txt files - even if they are not in sequence from 0000 */
-
- int vmcount = 0;
- DIR *vmdir = NULL;
- struct dirent *vment = NULL;
-
- if (vm_lock_path(dir))
- return ERROR_LOCK_PATH;
-
- if ((vmdir = opendir(dir))) {
- while ((vment = readdir(vmdir))) {
- if (strlen(vment->d_name) > 7 && !strncmp(vment->d_name + 7, ".txt", 4))
- vmcount++;
- }
- closedir(vmdir);
- }
- ast_unlock_path(dir);
-
- return vmcount;
-}
-
-static void rename_file(char *sfn, char *dfn)
-{
- char stxt[256];
- char dtxt[256];
- ast_filerename(sfn,dfn,NULL);
- snprintf(stxt, sizeof(stxt), "%s.txt", sfn);
- snprintf(dtxt, sizeof(dtxt), "%s.txt", dfn);
- rename(stxt, dtxt);
-}
-
-static int copy(char *infile, char *outfile)
-{
- int ifd;
- int ofd;
- int res;
- int len;
- char buf[4096];
-
-#ifdef HARDLINK_WHEN_POSSIBLE
- /* Hard link if possible; saves disk space & is faster */
- if (link(infile, outfile)) {
-#endif
- if ((ifd = open(infile, O_RDONLY)) < 0) {
- ast_log(LOG_WARNING, "Unable to open %s in read-only mode\n", infile);
- return -1;
- }
- if ((ofd = open(outfile, O_WRONLY | O_TRUNC | O_CREAT, VOICEMAIL_FILE_MODE)) < 0) {
- ast_log(LOG_WARNING, "Unable to open %s in write-only mode\n", outfile);
- close(ifd);
- return -1;
- }
- do {
- len = read(ifd, buf, sizeof(buf));
- if (len < 0) {
- ast_log(LOG_WARNING, "Read failed on %s: %s\n", infile, strerror(errno));
- close(ifd);
- close(ofd);
- unlink(outfile);
- }
- if (len) {
- res = write(ofd, buf, len);
- if (errno == ENOMEM || errno == ENOSPC || res != len) {
- ast_log(LOG_WARNING, "Write failed on %s (%d of %d): %s\n", outfile, res, len, strerror(errno));
- close(ifd);
- close(ofd);
- unlink(outfile);
- }
- }
- } while (len);
- close(ifd);
- close(ofd);
- return 0;
-#ifdef HARDLINK_WHEN_POSSIBLE
- } else {
- /* Hard link succeeded */
- return 0;
- }
-#endif
-}
-
-static void copy_file(char *frompath, char *topath)
-{
- char frompath2[256],topath2[256];
- ast_filecopy(frompath, topath, NULL);
- snprintf(frompath2, sizeof(frompath2), "%s.txt", frompath);
- snprintf(topath2, sizeof(topath2), "%s.txt", topath);
- copy(frompath2, topath2);
-}
-
-/*
- * A negative return value indicates an error.
- */
-static int last_message_index(struct ast_vm_user *vmu, char *dir)
-{
- int x;
- char fn[256];
-
- if (vm_lock_path(dir))
- return ERROR_LOCK_PATH;
-
- for (x = 0; x < vmu->maxmsg; x++) {
- make_file(fn, sizeof(fn), dir, x);
- if (ast_fileexists(fn, NULL, NULL) < 1)
- break;
- }
- ast_unlock_path(dir);
-
- return x - 1;
-}
-
-static int vm_delete(char *file)
-{
- char *txt;
- int txtsize = 0;
-
- txtsize = (strlen(file) + 5)*sizeof(char);
- txt = (char *)alloca(txtsize);
- /* Sprintf here would safe because we alloca'd exactly the right length,
- * but trying to eliminate all sprintf's anyhow
- */
- snprintf(txt, txtsize, "%s.txt", file);
- unlink(txt);
- return ast_filedelete(file, NULL);
-}
-
-
-#endif
-static int
-inbuf(struct baseio *bio, FILE *fi)
-{
- int l;
-
- if (bio->ateof)
- return 0;
-
- if ((l = fread(bio->iobuf,1,BASEMAXINLINE,fi)) <= 0) {
- if (ferror(fi))
- return -1;
-
- bio->ateof = 1;
- return 0;
- }
-
- bio->iolen= l;
- bio->iocp= 0;
-
- return 1;
-}
-
-static int
-inchar(struct baseio *bio, FILE *fi)
-{
- if (bio->iocp>=bio->iolen) {
- if (!inbuf(bio, fi))
- return EOF;
- }
-
- return bio->iobuf[bio->iocp++];
-}
-
-static int
-ochar(struct baseio *bio, int c, FILE *so)
-{
- if (bio->linelength>=BASELINELEN) {
- if (fputs(eol,so)==EOF)
- return -1;
-
- bio->linelength= 0;
- }
-
- if (putc(((unsigned char)c),so)==EOF)
- return -1;
-
- bio->linelength++;
-
- return 1;
-}
-
-static int base_encode(char *filename, FILE *so)
-{
- unsigned char dtable[BASEMAXINLINE];
- int i,hiteof= 0;
- FILE *fi;
- struct baseio bio;
-
- memset(&bio, 0, sizeof(bio));
- bio.iocp = BASEMAXINLINE;
-
- if (!(fi = fopen(filename, "rb"))) {
- ast_log(LOG_WARNING, "Failed to open log file: %s: %s\n", filename, strerror(errno));
- return -1;
- }
-
- for (i= 0;i<9;i++) {
- dtable[i]= 'A'+i;
- dtable[i+9]= 'J'+i;
- dtable[26+i]= 'a'+i;
- dtable[26+i+9]= 'j'+i;
- }
- for (i= 0;i<8;i++) {
- dtable[i+18]= 'S'+i;
- dtable[26+i+18]= 's'+i;
- }
- for (i= 0;i<10;i++) {
- dtable[52+i]= '0'+i;
- }
- dtable[62]= '+';
- dtable[63]= '/';
-
- while (!hiteof){
- unsigned char igroup[3],ogroup[4];
- int c,n;
-
- igroup[0]= igroup[1]= igroup[2]= 0;
-
- for (n= 0;n<3;n++) {
- if ((c = inchar(&bio, fi)) == EOF) {
- hiteof= 1;
- break;
- }
-
- igroup[n]= (unsigned char)c;
- }
-
- if (n> 0) {
- ogroup[0]= dtable[igroup[0]>>2];
- ogroup[1]= dtable[((igroup[0]&3)<<4)|(igroup[1]>>4)];
- ogroup[2]= dtable[((igroup[1]&0xF)<<2)|(igroup[2]>>6)];
- ogroup[3]= dtable[igroup[2]&0x3F];
-
- if (n<3) {
- ogroup[3]= '=';
-
- if (n<2)
- ogroup[2]= '=';
- }
-
- for (i= 0;i<4;i++)
- ochar(&bio, ogroup[i], so);
- }
- }
-
- if (fputs(eol,so)==EOF)
- return 0;
-
- fclose(fi);
-
- return 1;
-}
-
-static void prep_email_sub_vars(struct ast_channel *ast, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *dur, char *date, char *passdata, size_t passdatasize)
-{
- char callerid[256];
- /* Prepare variables for substition in email body and subject */
- pbx_builtin_setvar_helper(ast, "VM_NAME", vmu->fullname);
- pbx_builtin_setvar_helper(ast, "VM_DUR", dur);
- snprintf(passdata, passdatasize, "%d", msgnum);
- pbx_builtin_setvar_helper(ast, "VM_MSGNUM", passdata);
- pbx_builtin_setvar_helper(ast, "VM_CONTEXT", context);
- pbx_builtin_setvar_helper(ast, "VM_MAILBOX", mailbox);
- pbx_builtin_setvar_helper(ast, "VM_CALLERID", ast_callerid_merge(callerid, sizeof(callerid), cidname, cidnum, "Unknown Caller"));
- pbx_builtin_setvar_helper(ast, "VM_CIDNAME", (cidname ? cidname : "an unknown caller"));
- pbx_builtin_setvar_helper(ast, "VM_CIDNUM", (cidnum ? cidnum : "an unknown caller"));
- pbx_builtin_setvar_helper(ast, "VM_DATE", date);
-}
-
-static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail)
-{
- FILE *p=NULL;
- int pfd;
- char date[256];
- char host[MAXHOSTNAMELEN] = "";
- char who[256];
- char bound[256];
- char fname[256];
- char dur[256];
- char tmp[80] = "/tmp/astmail-XXXXXX";
- char tmp2[256];
- time_t t;
- struct tm tm;
- struct vm_zone *the_zone = NULL;
- if (vmu && ast_strlen_zero(vmu->email)) {
- ast_log(LOG_WARNING, "E-mail address missing for mailbox [%s]. E-mail will not be sent.\n", vmu->mailbox);
- return(0);
- }
- if (!strcmp(format, "wav49"))
- format = "WAV";
- ast_log(LOG_DEBUG, "Attaching file '%s', format '%s', uservm is '%d', global is %d\n", attach, format, attach_user_voicemail, ast_test_flag((&globalflags), VM_ATTACH));
- /* Make a temporary file instead of piping directly to sendmail, in case the mail
- command hangs */
- pfd = mkstemp(tmp);
- if (pfd > -1) {
- p = fdopen(pfd, "w");
- if (!p) {
- close(pfd);
- pfd = -1;
- }
- }
- if (p) {
- gethostname(host, sizeof(host)-1);
- if (strchr(srcemail, '@'))
- ast_copy_string(who, srcemail, sizeof(who));
- else {
- snprintf(who, sizeof(who), "%s@%s", srcemail, host);
- }
- snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60);
- time(&t);
-
- /* Does this user have a timezone specified? */
- if (!ast_strlen_zero(vmu->zonetag)) {
- /* Find the zone in the list */
- struct vm_zone *z;
- z = zones;
- while (z) {
- if (!strcmp(z->name, vmu->zonetag)) {
- the_zone = z;
- break;
- }
- z = z->next;
- }
- }
-
- if (the_zone)
- ast_localtime(&t,&tm,the_zone->timezone);
- else
- ast_localtime(&t,&tm,NULL);
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm);
- fprintf(p, "Date: %s\n", date);
-
- /* Set date format for voicemail mail */
- strftime(date, sizeof(date), emaildateformat, &tm);
-
- if (*fromstring) {
- struct ast_channel *ast = ast_channel_alloc(0);
- if (ast) {
- char *passdata;
- int vmlen = strlen(fromstring)*3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
- pbx_substitute_variables_helper(ast,fromstring,passdata,vmlen);
- fprintf(p, "From: %s <%s>\n",passdata,who);
- } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
- } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
- } else
- fprintf(p, "From: Asterisk PBX <%s>\n", who);
- fprintf(p, "To: %s <%s>\n", vmu->fullname, vmu->email);
-
- if (emailsubject) {
- struct ast_channel *ast = ast_channel_alloc(0);
- if (ast) {
- char *passdata;
- int vmlen = strlen(emailsubject)*3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
- pbx_substitute_variables_helper(ast,emailsubject,passdata,vmlen);
- fprintf(p, "Subject: %s\n",passdata);
- } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
- } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
- } else
- if (*emailtitle) {
- fprintf(p, emailtitle, msgnum + 1, mailbox) ;
- fprintf(p,"\n") ;
- } else if (ast_test_flag((&globalflags), VM_PBXSKIP))
- fprintf(p, "Subject: New message %d in mailbox %s\n", msgnum + 1, mailbox);
- else
- fprintf(p, "Subject: [PBX]: New message %d in mailbox %s\n", msgnum + 1, mailbox);
- fprintf(p, "Message-ID: <Asterisk-%d-%d-%s-%d@%s>\n", msgnum, (unsigned int)rand(), mailbox, getpid(), host);
- fprintf(p, "MIME-Version: 1.0\n");
- if (attach_user_voicemail) {
- /* Something unique. */
- snprintf(bound, sizeof(bound), "voicemail_%d%s%d%d", msgnum, mailbox, getpid(), (unsigned int)rand());
-
- fprintf(p, "Content-Type: multipart/mixed; boundary=\"%s\"\n\n\n", bound);
-
- fprintf(p, "--%s\n", bound);
- }
- fprintf(p, "Content-Type: text/plain; charset=%s\nContent-Transfer-Encoding: 8bit\n\n", charset);
- if (emailbody) {
- struct ast_channel *ast = ast_channel_alloc(0);
- if (ast) {
- char *passdata;
- int vmlen = strlen(emailbody)*3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
- pbx_substitute_variables_helper(ast,emailbody,passdata,vmlen);
- fprintf(p, "%s\n",passdata);
- } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
- } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
- } else {
- fprintf(p, "Dear %s:\n\n\tJust wanted to let you know you were just left a %s long message (number %d)\n"
-
- "in mailbox %s from %s, on %s so you might\n"
- "want to check it when you get a chance. Thanks!\n\n\t\t\t\t--Asterisk\n\n", vmu->fullname,
- dur, msgnum + 1, mailbox, (cidname ? cidname : (cidnum ? cidnum : "an unknown caller")), date);
- }
- if (attach_user_voicemail) {
- /* Eww. We want formats to tell us their own MIME type */
- char *ctype = "audio/x-";
- if (!strcasecmp(format, "ogg"))
- ctype = "application/";
-
- fprintf(p, "--%s\n", bound);
- fprintf(p, "Content-Type: %s%s; name=\"msg%04d.%s\"\n", ctype, format, msgnum, format);
- fprintf(p, "Content-Transfer-Encoding: base64\n");
- fprintf(p, "Content-Description: Voicemail sound attachment.\n");
- fprintf(p, "Content-Disposition: attachment; filename=\"msg%04d.%s\"\n\n", msgnum, format);
-
- snprintf(fname, sizeof(fname), "%s.%s", attach, format);
- base_encode(fname, p);
- fprintf(p, "\n\n--%s--\n.\n", bound);
- }
- fclose(p);
- snprintf(tmp2, sizeof(tmp2), "( %s < %s ; rm -f %s ) &", mailcmd, tmp, tmp);
- ast_safe_system(tmp2);
- ast_log(LOG_DEBUG, "Sent mail to %s with command '%s'\n", vmu->email, mailcmd);
- } else {
- ast_log(LOG_WARNING, "Unable to launch '%s'\n", mailcmd);
- return -1;
- }
- return 0;
-}
-
-static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, int duration, struct ast_vm_user *vmu)
-{
- FILE *p=NULL;
- int pfd;
- char date[256];
- char host[MAXHOSTNAMELEN]="";
- char who[256];
- char dur[256];
- char tmp[80] = "/tmp/astmail-XXXXXX";
- char tmp2[256];
- time_t t;
- struct tm tm;
- struct vm_zone *the_zone = NULL;
- pfd = mkstemp(tmp);
-
- if (pfd > -1) {
- p = fdopen(pfd, "w");
- if (!p) {
- close(pfd);
- pfd = -1;
- }
- }
-
- if (p) {
- gethostname(host, sizeof(host)-1);
- if (strchr(srcemail, '@'))
- ast_copy_string(who, srcemail, sizeof(who));
- else {
- snprintf(who, sizeof(who), "%s@%s", srcemail, host);
- }
- snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60);
- time(&t);
-
- /* Does this user have a timezone specified? */
- if (!ast_strlen_zero(vmu->zonetag)) {
- /* Find the zone in the list */
- struct vm_zone *z;
- z = zones;
- while (z) {
- if (!strcmp(z->name, vmu->zonetag)) {
- the_zone = z;
- break;
- }
- z = z->next;
- }
- }
-
- if (the_zone)
- ast_localtime(&t,&tm,the_zone->timezone);
- else
- ast_localtime(&t,&tm,NULL);
-
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm);
- fprintf(p, "Date: %s\n", date);
-
- if (*pagerfromstring) {
- struct ast_channel *ast = ast_channel_alloc(0);
- if (ast) {
- char *passdata;
- int vmlen = strlen(fromstring)*3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
- pbx_substitute_variables_helper(ast,pagerfromstring,passdata,vmlen);
- fprintf(p, "From: %s <%s>\n",passdata,who);
- } else
- ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
- } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
- } else
- fprintf(p, "From: Asterisk PBX <%s>\n", who);
- fprintf(p, "To: %s\n", pager);
- if (pagersubject) {
- struct ast_channel *ast = ast_channel_alloc(0);
- if (ast) {
- char *passdata;
- int vmlen = strlen(pagersubject)*3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
- pbx_substitute_variables_helper(ast,pagersubject,passdata,vmlen);
- fprintf(p, "Subject: %s\n\n",passdata);
- } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
- } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
- } else
- fprintf(p, "Subject: New VM\n\n");
- strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm);
- if (pagerbody) {
- struct ast_channel *ast = ast_channel_alloc(0);
- if (ast) {
- char *passdata;
- int vmlen = strlen(pagerbody)*3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
- pbx_substitute_variables_helper(ast,pagerbody,passdata,vmlen);
- fprintf(p, "%s\n",passdata);
- } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
- } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
- } else {
- fprintf(p, "New %s long msg in box %s\n"
- "from %s, on %s", dur, mailbox, (cidname ? cidname : (cidnum ? cidnum : "unknown")), date);
- }
- fclose(p);
- snprintf(tmp2, sizeof(tmp2), "( %s < %s ; rm -f %s ) &", mailcmd, tmp, tmp);
- ast_safe_system(tmp2);
- ast_log(LOG_DEBUG, "Sent page to %s with command '%s'\n", pager, mailcmd);
- } else {
- ast_log(LOG_WARNING, "Unable to launch '%s'\n", mailcmd);
- return -1;
- }
- return 0;
-}
-
-static int get_date(char *s, int len)
-{
- struct tm tm;
- time_t t;
- t = time(0);
- localtime_r(&t,&tm);
- return strftime(s, len, "%a %b %e %r %Z %Y", &tm);
-}
-
-static int invent_message(struct ast_channel *chan, char *context, char *ext, int busy, char *ecodes)
-{
- int res;
- char fn[256];
- snprintf(fn, sizeof(fn), "%s%s/%s/greet", VM_SPOOL_DIR, context, ext);
- RETRIEVE(fn, -1);
- if (ast_fileexists(fn, NULL, NULL) > 0) {
- res = ast_streamfile(chan, fn, chan->language);
- if (res) {
- DISPOSE(fn, -1);
- return -1;
- }
- res = ast_waitstream(chan, ecodes);
- if (res) {
- DISPOSE(fn, -1);
- return res;
- }
- } else {
- /* Dispose just in case */
- DISPOSE(fn, -1);
- res = ast_streamfile(chan, "vm-theperson", chan->language);
- if (res)
- return -1;
- res = ast_waitstream(chan, ecodes);
- if (res)
- return res;
- res = ast_say_digit_str(chan, ext, ecodes, chan->language);
- if (res)
- return res;
- }
- if (busy)
- res = ast_streamfile(chan, "vm-isonphone", chan->language);
- else
- res = ast_streamfile(chan, "vm-isunavail", chan->language);
- if (res)
- return -1;
- res = ast_waitstream(chan, ecodes);
- return res;
-}
-
-static void free_user(struct ast_vm_user *vmu)
-{
- if (ast_test_flag(vmu, VM_ALLOCED))
- free(vmu);
-}
-
-static void free_zone(struct vm_zone *z)
-{
- free(z);
-}
-
-static char *mbox(int id)
-{
- switch(id) {
- case 0:
- return "INBOX";
- case 1:
- return "Old";
- case 2:
- return "Work";
- case 3:
- return "Family";
- case 4:
- return "Friends";
- case 5:
- return "Cust1";
- case 6:
- return "Cust2";
- case 7:
- return "Cust3";
- case 8:
- return "Cust4";
- case 9:
- return "Cust5";
- default:
- return "Unknown";
- }
-}
-
-#ifdef USE_ODBC_STORAGE
-static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
-{
- int x = 0;
- int res;
- SQLHSTMT stmt;
- char sql[256];
- char rowdata[20];
- char tmp[256]="";
- char *context;
-
- if (newmsgs)
- *newmsgs = 0;
- if (oldmsgs)
- *oldmsgs = 0;
- /* If no mailbox, return immediately */
- if (ast_strlen_zero(mailbox))
- return 0;
-
- ast_copy_string(tmp, mailbox, sizeof(tmp));
-
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- } else
- context = "default";
-
- odbc_obj *obj;
- obj = fetch_odbc_obj(odbc_database, 0);
- if (obj) {
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
- snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir LIKE '%%%s/%s/%s'", odbc_table, context, tmp, "INBOX");
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLFetch(stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- *newmsgs = atoi(rowdata);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
- snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir like '%%%s/%s/%s'", odbc_table, context, tmp, "Old");
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLFetch(stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- *oldmsgs = atoi(rowdata);
- x = 1;
- } else
- ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-
-yuck:
- return x;
-}
-
-static int has_voicemail(const char *mailbox, const char *folder)
-{
- int nummsgs = 0;
- int res;
- SQLHSTMT stmt;
- char sql[256];
- char rowdata[20];
- char tmp[256]="";
- char *context;
- if (!folder)
- folder = "INBOX";
- /* If no mailbox, return immediately */
- if (ast_strlen_zero(mailbox))
- return 0;
-
- ast_copy_string(tmp, mailbox, sizeof(tmp));
-
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- } else
- context = "default";
-
- odbc_obj *obj;
- obj = fetch_odbc_obj(odbc_database, 0);
- if (obj) {
- res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- goto yuck;
- }
- snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir like '%%%s/%s/%s'", odbc_table, context, tmp, "INBOX");
- res = SQLPrepare(stmt, sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = odbc_smart_execute(obj, stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLFetch(stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- goto yuck;
- }
- nummsgs = atoi(rowdata);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- } else
- ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-
-yuck:
- if (nummsgs>=1)
- return 1;
- else
- return 0;
-}
-
-#else
-
-static int has_voicemail(const char *mailbox, const char *folder)
-{
- DIR *dir;
- struct dirent *de;
- char fn[256];
- char tmp[256]="";
- char *mb, *cur;
- char *context;
- int ret;
- if (!folder)
- folder = "INBOX";
- /* If no mailbox, return immediately */
- if (ast_strlen_zero(mailbox))
- return 0;
- if (strchr(mailbox, ',')) {
- ast_copy_string(tmp, mailbox, sizeof(tmp));
- mb = tmp;
- ret = 0;
- while((cur = strsep(&mb, ","))) {
- if (!ast_strlen_zero(cur)) {
- if (has_voicemail(cur, folder))
- return 1;
- }
- }
- return 0;
- }
- ast_copy_string(tmp, mailbox, sizeof(tmp));
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- } else
- context = "default";
- snprintf(fn, sizeof(fn), "%s/%s/%s/%s", VM_SPOOL_DIR, context, tmp, folder);
- dir = opendir(fn);
- if (!dir)
- return 0;
- while ((de = readdir(dir))) {
- if (!strncasecmp(de->d_name, "msg", 3))
- break;
- }
- closedir(dir);
- if (de)
- return 1;
- return 0;
-}
-
-
-static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
-{
- DIR *dir;
- struct dirent *de;
- char fn[256];
- char tmp[256]="";
- char *mb, *cur;
- char *context;
- int ret;
- if (newmsgs)
- *newmsgs = 0;
- if (oldmsgs)
- *oldmsgs = 0;
- /* If no mailbox, return immediately */
- if (ast_strlen_zero(mailbox))
- return 0;
- if (strchr(mailbox, ',')) {
- int tmpnew, tmpold;
- ast_copy_string(tmp, mailbox, sizeof(tmp));
- mb = tmp;
- ret = 0;
- while((cur = strsep(&mb, ", "))) {
- if (!ast_strlen_zero(cur)) {
- if (messagecount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
- return -1;
- else {
- if (newmsgs)
- *newmsgs += tmpnew;
- if (oldmsgs)
- *oldmsgs += tmpold;
- }
- }
- }
- return 0;
- }
- ast_copy_string(tmp, mailbox, sizeof(tmp));
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- } else
- context = "default";
- if (newmsgs) {
- snprintf(fn, sizeof(fn), "%s/%s/%s/INBOX", VM_SPOOL_DIR, context, tmp);
- dir = opendir(fn);
- if (dir) {
- while ((de = readdir(dir))) {
- if ((strlen(de->d_name) > 3) && !strncasecmp(de->d_name, "msg", 3) &&
- !strcasecmp(de->d_name + strlen(de->d_name) - 3, "txt"))
- (*newmsgs)++;
-
- }
- closedir(dir);
- }
- }
- if (oldmsgs) {
- snprintf(fn, sizeof(fn), "%s/%s/%s/Old", VM_SPOOL_DIR, context, tmp);
- dir = opendir(fn);
- if (dir) {
- while ((de = readdir(dir))) {
- if ((strlen(de->d_name) > 3) && !strncasecmp(de->d_name, "msg", 3) &&
- !strcasecmp(de->d_name + strlen(de->d_name) - 3, "txt"))
- (*oldmsgs)++;
-
- }
- closedir(dir);
- }
- }
- return 0;
-}
-
-#endif
-
-static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu, int msgnum, long duration, char *fmt, char *cidnum, char *cidname);
-
-static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt)
-{
- char fromdir[256], todir[256], frompath[256], topath[256];
- char *frombox = mbox(imbox);
- int recipmsgnum;
-
- ast_log(LOG_NOTICE, "Copying message from %s@%s to %s@%s\n", vmu->mailbox, vmu->context, recip->mailbox, recip->context);
-
- create_dirpath(todir, sizeof(todir), recip->context, recip->mailbox, "INBOX");
-
- make_dir(fromdir, sizeof(fromdir), vmu->context, vmu->mailbox, frombox);
- make_file(frompath, sizeof(frompath), fromdir, msgnum);
-
- if (vm_lock_path(todir))
- return ERROR_LOCK_PATH;
-
- recipmsgnum = 0;
- do {
- make_file(topath, sizeof(topath), todir, recipmsgnum);
- if (!EXISTS(todir, recipmsgnum, topath, chan->language))
- break;
- recipmsgnum++;
- } while (recipmsgnum < recip->maxmsg);
- if (recipmsgnum < recip->maxmsg) {
- COPY(fromdir, msgnum, todir, recipmsgnum, recip->mailbox, recip->context, frompath, topath);
- } else {
- ast_log(LOG_ERROR, "Recipient mailbox %s@%s is full\n", recip->mailbox, recip->context);
- }
- ast_unlock_path(todir);
- notify_new_message(chan, recip, recipmsgnum, duration, fmt, chan->cid.cid_num, chan->cid.cid_name);
-
- return 0;
-}
-
-static void run_externnotify(char *context, char *extension)
-{
- char arguments[255];
- char ext_context[256] = "";
- int newvoicemails = 0, oldvoicemails = 0;
-
- if (!ast_strlen_zero(context))
- snprintf(ext_context, sizeof(ext_context), "%s@%s", extension, context);
- else
- ast_copy_string(ext_context, extension, sizeof(ext_context));
-
- if (!ast_strlen_zero(externnotify)) {
- if (messagecount(ext_context, &newvoicemails, &oldvoicemails)) {
- ast_log(LOG_ERROR, "Problem in calculating number of voicemail messages available for extension %s\n", extension);
- } else {
- snprintf(arguments, sizeof(arguments), "%s %s %s %d&", externnotify, context, extension, newvoicemails);
- ast_log(LOG_DEBUG, "Executing %s\n", arguments);
- ast_safe_system(arguments);
- }
- }
-}
-
-struct leave_vm_options {
- unsigned int flags;
- signed char record_gain;
-};
-
-static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_options *options)
-{
- char txtfile[256];
- char callerid[256];
- FILE *txt;
- int res = 0;
- int msgnum;
- int duration = 0;
- int ausemacro = 0;
- int ousemacro = 0;
- char date[256];
- char dir[256];
- char fn[256];
- char prefile[256]="";
- char tempfile[256]="";
- char ext_context[256] = "";
- char fmt[80];
- char *context;
- char ecodes[16] = "#";
- char tmp[256] = "", *tmpptr;
- struct ast_vm_user *vmu;
- struct ast_vm_user svm;
- char *category = NULL;
-
- ast_copy_string(tmp, ext, sizeof(tmp));
- ext = tmp;
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- tmpptr = strchr(context, '&');
- } else {
- tmpptr = strchr(ext, '&');
- }
-
- if (tmpptr) {
- *tmpptr = '\0';
- tmpptr++;
- }
-
- category = pbx_builtin_getvar_helper(chan, "VM_CATEGORY");
-
- if (!(vmu = find_user(&svm, context, ext))) {
- ast_log(LOG_WARNING, "No entry in voicemail config file for '%s'\n", ext);
- if (ast_test_flag(options, OPT_PRIORITY_JUMP) || option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
- return res;
- }
-
- /* Setup pre-file if appropriate */
- if (strcmp(vmu->context, "default"))
- snprintf(ext_context, sizeof(ext_context), "%s@%s", ext, vmu->context);
- else
- ast_copy_string(ext_context, vmu->context, sizeof(ext_context));
- if (ast_test_flag(options, OPT_BUSY_GREETING))
- snprintf(prefile, sizeof(prefile), "%s%s/%s/busy", VM_SPOOL_DIR, vmu->context, ext);
- else if (ast_test_flag(options, OPT_UNAVAIL_GREETING))
- snprintf(prefile, sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, ext);
- snprintf(tempfile, sizeof(tempfile), "%s%s/%s/temp", VM_SPOOL_DIR, vmu->context, ext);
- RETRIEVE(tempfile, -1);
- if (ast_fileexists(tempfile, NULL, NULL) > 0)
- ast_copy_string(prefile, tempfile, sizeof(prefile));
- DISPOSE(tempfile, -1);
- /* It's easier just to try to make it than to check for its existence */
- create_dirpath(dir, sizeof(dir), vmu->context, ext, "INBOX");
-
- /* Check current or macro-calling context for special extensions */
- if (!ast_strlen_zero(vmu->exit)) {
- if (ast_exists_extension(chan, vmu->exit, "o", 1, chan->cid.cid_num))
- strncat(ecodes, "0", sizeof(ecodes) - strlen(ecodes) - 1);
- } else if (ast_exists_extension(chan, chan->context, "o", 1, chan->cid.cid_num))
- strncat(ecodes, "0", sizeof(ecodes) - strlen(ecodes) - 1);
- else if (!ast_strlen_zero(chan->macrocontext) && ast_exists_extension(chan, chan->macrocontext, "o", 1, chan->cid.cid_num)) {
- strncat(ecodes, "0", sizeof(ecodes) - strlen(ecodes) - 1);
- ousemacro = 1;
- }
-
- if (!ast_strlen_zero(vmu->exit)) {
- if (ast_exists_extension(chan, vmu->exit, "a", 1, chan->cid.cid_num))
- strncat(ecodes, "*", sizeof(ecodes) - strlen(ecodes) - 1);
- } else if (ast_exists_extension(chan, chan->context, "a", 1, chan->cid.cid_num))
- strncat(ecodes, "*", sizeof(ecodes) - strlen(ecodes) - 1);
- else if (!ast_strlen_zero(chan->macrocontext) && ast_exists_extension(chan, chan->macrocontext, "a", 1, chan->cid.cid_num)) {
- strncat(ecodes, "*", sizeof(ecodes) - strlen(ecodes) - 1);
- ausemacro = 1;
- }
-
- /* Play the beginning intro if desired */
- if (!ast_strlen_zero(prefile)) {
- RETRIEVE(prefile, -1);
- if (ast_fileexists(prefile, NULL, NULL) > 0) {
- if (ast_streamfile(chan, prefile, chan->language) > -1)
- res = ast_waitstream(chan, ecodes);
- } else {
- ast_log(LOG_DEBUG, "%s doesn't exist, doing what we can\n", prefile);
- res = invent_message(chan, vmu->context, ext, ast_test_flag(options, OPT_BUSY_GREETING), ecodes);
- }
- DISPOSE(prefile, -1);
- if (res < 0) {
- ast_log(LOG_DEBUG, "Hang up during prefile playback\n");
- free_user(vmu);
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
- return -1;
- }
- }
- if (res == '#') {
- /* On a '#' we skip the instructions */
- ast_set_flag(options, OPT_SILENT);
- res = 0;
- }
- if (!res && !ast_test_flag(options, OPT_SILENT)) {
- res = ast_streamfile(chan, INTRO, chan->language);
- if (!res)
- res = ast_waitstream(chan, ecodes);
- if (res == '#') {
- ast_set_flag(options, OPT_SILENT);
- res = 0;
- }
- }
- if (res > 0)
- ast_stopstream(chan);
- /* Check for a '*' here in case the caller wants to escape from voicemail to something
- other than the operator -- an automated attendant or mailbox login for example */
- if (res == '*') {
- chan->exten[0] = 'a';
- chan->exten[1] = '\0';
- if (!ast_strlen_zero(vmu->exit)) {
- ast_copy_string(chan->context, vmu->exit, sizeof(chan->context));
- } else if (ausemacro && !ast_strlen_zero(chan->macrocontext)) {
- ast_copy_string(chan->context, chan->macrocontext, sizeof(chan->context));
- }
- chan->priority = 0;
- free_user(vmu);
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "USEREXIT");
- return 0;
- }
- /* Check for a '0' here */
- if (res == '0') {
- transfer:
- if (ast_test_flag(vmu, VM_OPERATOR)) {
- chan->exten[0] = 'o';
- chan->exten[1] = '\0';
- if (!ast_strlen_zero(vmu->exit)) {
- ast_copy_string(chan->context, vmu->exit, sizeof(chan->context));
- } else if (ousemacro && !ast_strlen_zero(chan->macrocontext)) {
- ast_copy_string(chan->context, chan->macrocontext, sizeof(chan->context));
- }
- ast_play_and_wait(chan, "transfer");
- chan->priority = 0;
- free_user(vmu);
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "USEREXIT");
- return 0;
- } else {
- ast_play_and_wait(chan, "vm-sorry");
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "USEREXIT");
- return 0;
- }
- }
- if (res < 0) {
- free_user(vmu);
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
- return -1;
- }
- /* The meat of recording the message... All the announcements and beeps have been played*/
- ast_copy_string(fmt, vmfmts, sizeof(fmt));
- if (!ast_strlen_zero(fmt)) {
- msgnum = 0;
-
- if (vm_lock_path(dir)) {
- free_user(vmu);
- return ERROR_LOCK_PATH;
- }
-
- /*
- * This operation can be very expensive if done say over NFS or if the mailbox has 100+ messages
- * in the mailbox. So we should get this first so we don't cut off the first few seconds of the
- * message.
- */
- do {
- make_file(fn, sizeof(fn), dir, msgnum);
- if (!EXISTS(dir,msgnum,fn,chan->language))
- break;
- msgnum++;
- } while (msgnum < vmu->maxmsg);
-
- /* Now play the beep once we have the message number for our next message. */
- if (res >= 0) {
- /* Unless we're *really* silent, try to send the beep */
- res = ast_streamfile(chan, "beep", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- }
- if (msgnum < vmu->maxmsg) {
- /* assign a variable with the name of the voicemail file */
- pbx_builtin_setvar_helper(chan, "VM_MESSAGEFILE", fn);
-
- /* Store information */
- snprintf(txtfile, sizeof(txtfile), "%s.txt", fn);
- txt = fopen(txtfile, "w+");
- if (txt) {
- get_date(date, sizeof(date));
- fprintf(txt,
- ";\n"
- "; Message Information file\n"
- ";\n"
- "[message]\n"
- "origmailbox=%s\n"
- "context=%s\n"
- "macrocontext=%s\n"
- "exten=%s\n"
- "priority=%d\n"
- "callerchan=%s\n"
- "callerid=%s\n"
- "origdate=%s\n"
- "origtime=%ld\n"
- "category=%s\n",
- ext,
- chan->context,
- chan->macrocontext,
- chan->exten,
- chan->priority,
- chan->name,
- ast_callerid_merge(callerid, sizeof(callerid), chan->cid.cid_name, chan->cid.cid_num, "Unknown"),
- date, (long)time(NULL),
- category ? category : "");
- } else
- ast_log(LOG_WARNING, "Error opening text file for output\n");
- res = play_record_review(chan, NULL, fn, vmmaxmessage, fmt, 1, vmu, &duration, dir, options->record_gain);
- if (res == '0') {
- if (txt)
- fclose(txt);
- goto transfer;
- }
- if (res > 0)
- res = 0;
- if (txt) {
- fprintf(txt, "duration=%d\n", duration);
- fclose(txt);
- }
-
- if (duration < vmminmessage) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Recording was %d seconds long but needs to be at least %d - abandoning\n", duration, vmminmessage);
- DELETE(dir,msgnum,fn);
- /* XXX We should really give a prompt too short/option start again, with leave_vm_out called only after a timeout XXX */
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
- goto leave_vm_out;
- }
- /* Are there to be more recipients of this message? */
- while (tmpptr) {
- struct ast_vm_user recipu, *recip;
- char *exten, *context;
-
- exten = strsep(&tmpptr, "&");
- context = strchr(exten, '@');
- if (context) {
- *context = '\0';
- context++;
- }
- if ((recip = find_user(&recipu, context, exten))) {
- copy_message(chan, vmu, 0, msgnum, duration, recip, fmt);
- free_user(recip);
- }
- }
- if (ast_fileexists(fn, NULL, NULL)) {
- STORE(dir, vmu->mailbox, vmu->context, msgnum);
- notify_new_message(chan, vmu, msgnum, duration, fmt, chan->cid.cid_num, chan->cid.cid_name);
- DISPOSE(dir, msgnum);
- }
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "SUCCESS");
- } else {
- ast_unlock_path(dir);
- res = ast_streamfile(chan, "vm-mailboxfull", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- ast_log(LOG_WARNING, "No more messages possible\n");
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
- }
- } else
- ast_log(LOG_WARNING, "No format for saving voicemail?\n");
- leave_vm_out:
- free_user(vmu);
-
- return res;
-}
-
-static int resequence_mailbox(struct ast_vm_user *vmu, char *dir)
-{
- /* we know max messages, so stop process when number is hit */
-
- int x,dest;
- char sfn[256];
- char dfn[256];
-
- if (vm_lock_path(dir))
- return ERROR_LOCK_PATH;
-
- for (x = 0, dest = 0; x < vmu->maxmsg; x++) {
- make_file(sfn, sizeof(sfn), dir, x);
- if (EXISTS(dir, x, sfn, NULL)) {
-
- if(x != dest) {
- make_file(dfn, sizeof(dfn), dir, dest);
- RENAME(dir, x, vmu->mailbox, vmu->context, dir, dest, sfn, dfn);
- }
-
- dest++;
- }
- }
- ast_unlock_path(dir);
-
- return 0;
-}
-
-
-static int say_and_wait(struct ast_channel *chan, int num, char *language)
-{
- int d;
- d = ast_say_number(chan, num, AST_DIGIT_ANY, language, (char *) NULL);
- return d;
-}
-
-static int save_to_folder(struct ast_vm_user *vmu, char *dir, int msg, char *context, char *username, int box)
-{
- char sfn[256];
- char dfn[256];
- char ddir[256];
- char *dbox = mbox(box);
- int x;
- make_file(sfn, sizeof(sfn), dir, msg);
- create_dirpath(ddir, sizeof(ddir), context, username, dbox);
-
- if (vm_lock_path(ddir))
- return ERROR_LOCK_PATH;
-
- for (x = 0; x < vmu->maxmsg; x++) {
- make_file(dfn, sizeof(dfn), ddir, x);
- if (!EXISTS(ddir, x, dfn, NULL))
- break;
- }
- if (x >= vmu->maxmsg) {
- ast_unlock_path(ddir);
- return -1;
- }
- if (strcmp(sfn, dfn)) {
- COPY(dir, msg, ddir, x, username, context, sfn, dfn);
- }
- ast_unlock_path(ddir);
-
- return 0;
-}
-
-static int adsi_logo(unsigned char *buf)
-{
- int bytes = 0;
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 1, ADSI_JUST_CENT, 0, "Comedian Mail", "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 2, ADSI_JUST_CENT, 0, "(C)2002 LSS, Inc.", "");
- return bytes;
-}
-
-static int adsi_load_vmail(struct ast_channel *chan, int *useadsi)
-{
- unsigned char buf[256];
- int bytes=0;
- int x;
- char num[5];
-
- *useadsi = 0;
- bytes += adsi_data_mode(buf + bytes);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-
- bytes = 0;
- bytes += adsi_logo(buf);
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "Downloading Scripts", "");
-#ifdef DISPLAY
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_LEFT, 0, " .", "");
-#endif
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_data_mode(buf + bytes);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-
- if (adsi_begin_download(chan, addesc, adsifdn, adsisec, adsiver)) {
- bytes = 0;
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "Load Cancelled.", "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_CENT, 0, "ADSI Unavailable", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_voice_mode(buf + bytes, 0);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
- return 0;
- }
-
-#ifdef DISPLAY
- /* Add a dot */
- bytes = 0;
- bytes += adsi_logo(buf);
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "Downloading Scripts", "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_LEFT, 0, " ..", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-#endif
- bytes = 0;
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 0, "Listen", "Listen", "1", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 1, "Folder", "Folder", "2", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 2, "Advanced", "Advnced", "3", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 3, "Options", "Options", "0", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 4, "Help", "Help", "*", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 5, "Exit", "Exit", "#", 1);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD);
-
-#ifdef DISPLAY
- /* Add another dot */
- bytes = 0;
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_LEFT, 0, " ...", "");
- bytes += adsi_voice_mode(buf + bytes, 0);
-
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-#endif
-
- bytes = 0;
- /* These buttons we load but don't use yet */
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 6, "Previous", "Prev", "4", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 8, "Repeat", "Repeat", "5", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 7, "Delete", "Delete", "7", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 9, "Next", "Next", "6", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 10, "Save", "Save", "9", 1);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 11, "Undelete", "Restore", "7", 1);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD);
-
-#ifdef DISPLAY
- /* Add another dot */
- bytes = 0;
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_LEFT, 0, " ....", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-#endif
-
- bytes = 0;
- for (x=0;x<5;x++) {
- snprintf(num, sizeof(num), "%d", x);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 12 + x, mbox(x), mbox(x), num, 1);
- }
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 12 + 5, "Cancel", "Cancel", "#", 1);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD);
-
-#ifdef DISPLAY
- /* Add another dot */
- bytes = 0;
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_LEFT, 0, " .....", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-#endif
-
- if (adsi_end_download(chan)) {
- bytes = 0;
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "Download Unsuccessful.", "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_CENT, 0, "ADSI Unavailable", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_voice_mode(buf + bytes, 0);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
- return 0;
- }
- bytes = 0;
- bytes += adsi_download_disconnect(buf + bytes);
- bytes += adsi_voice_mode(buf + bytes, 0);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD);
-
- ast_log(LOG_DEBUG, "Done downloading scripts...\n");
-
-#ifdef DISPLAY
- /* Add last dot */
- bytes = 0;
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_CENT, 0, " ......", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
-#endif
- ast_log(LOG_DEBUG, "Restarting session...\n");
-
- bytes = 0;
- /* Load the session now */
- if (adsi_load_session(chan, adsifdn, adsiver, 1) == 1) {
- *useadsi = 1;
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "Scripts Loaded!", "");
- } else
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "Load Failed!", "");
-
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
- return 0;
-}
-
-static void adsi_begin(struct ast_channel *chan, int *useadsi)
-{
- int x;
- if (!adsi_available(chan))
- return;
- x = adsi_load_session(chan, adsifdn, adsiver, 1);
- if (x < 0)
- return;
- if (!x) {
- if (adsi_load_vmail(chan, useadsi)) {
- ast_log(LOG_WARNING, "Unable to upload voicemail scripts\n");
- return;
- }
- } else
- *useadsi = 1;
-}
-
-static void adsi_login(struct ast_channel *chan)
-{
- unsigned char buf[256];
- int bytes=0;
- unsigned char keys[8];
- int x;
- if (!adsi_available(chan))
- return;
-
- for (x=0;x<8;x++)
- keys[x] = 0;
- /* Set one key for next */
- keys[3] = ADSI_KEY_APPS + 3;
-
- bytes += adsi_logo(buf + bytes);
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, " ", "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_CENT, 0, " ", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_input_format(buf + bytes, 1, ADSI_DIR_FROM_LEFT, 0, "Mailbox: ******", "");
- bytes += adsi_input_control(buf + bytes, ADSI_COMM_PAGE, 4, 1, 1, ADSI_JUST_LEFT);
- bytes += adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 3, "Enter", "Enter", "#", 1);
- bytes += adsi_set_keys(buf + bytes, keys);
- bytes += adsi_voice_mode(buf + bytes, 0);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-}
-
-static void adsi_password(struct ast_channel *chan)
-{
- unsigned char buf[256];
- int bytes=0;
- unsigned char keys[8];
- int x;
- if (!adsi_available(chan))
- return;
-
- for (x=0;x<8;x++)
- keys[x] = 0;
- /* Set one key for next */
- keys[3] = ADSI_KEY_APPS + 3;
-
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_input_format(buf + bytes, 1, ADSI_DIR_FROM_LEFT, 0, "Password: ******", "");
- bytes += adsi_input_control(buf + bytes, ADSI_COMM_PAGE, 4, 0, 1, ADSI_JUST_LEFT);
- bytes += adsi_set_keys(buf + bytes, keys);
- bytes += adsi_voice_mode(buf + bytes, 0);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-}
-
-static void adsi_folders(struct ast_channel *chan, int start, char *label)
-{
- unsigned char buf[256];
- int bytes=0;
- unsigned char keys[8];
- int x,y;
-
- if (!adsi_available(chan))
- return;
-
- for (x=0;x<5;x++) {
- y = ADSI_KEY_APPS + 12 + start + x;
- if (y > ADSI_KEY_APPS + 12 + 4)
- y = 0;
- keys[x] = ADSI_KEY_SKT | y;
- }
- keys[5] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 17);
- keys[6] = 0;
- keys[7] = 0;
-
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 1, ADSI_JUST_CENT, 0, label, "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 2, ADSI_JUST_CENT, 0, " ", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_set_keys(buf + bytes, keys);
- bytes += adsi_voice_mode(buf + bytes, 0);
-
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-}
-
-static void adsi_message(struct ast_channel *chan, struct vm_state *vms)
-{
- int bytes=0;
- unsigned char buf[256];
- char buf1[256], buf2[256];
- char fn2[256];
-
- char cid[256]="";
- char *val;
- char *name, *num;
- char datetime[21]="";
- FILE *f;
-
- unsigned char keys[8];
-
- int x;
-
- if (!adsi_available(chan))
- return;
-
- /* Retrieve important info */
- snprintf(fn2, sizeof(fn2), "%s.txt", vms->fn);
- f = fopen(fn2, "r");
- if (f) {
- while (!feof(f)) {
- fgets((char *)buf, sizeof(buf), f);
- if (!feof(f)) {
- char *stringp=NULL;
- stringp = (char *)buf;
- strsep(&stringp, "=");
- val = strsep(&stringp, "=");
- if (!ast_strlen_zero(val)) {
- if (!strcmp((char *)buf, "callerid"))
- ast_copy_string(cid, val, sizeof(cid));
- if (!strcmp((char *)buf, "origdate"))
- ast_copy_string(datetime, val, sizeof(datetime));
- }
- }
- }
- fclose(f);
- }
- /* New meaning for keys */
- for (x=0;x<5;x++)
- keys[x] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 6 + x);
- keys[6] = 0x0;
- keys[7] = 0x0;
-
- if (!vms->curmsg) {
- /* No prev key, provide "Folder" instead */
- keys[0] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 1);
- }
- if (vms->curmsg >= vms->lastmsg) {
- /* If last message ... */
- if (vms->curmsg) {
- /* but not only message, provide "Folder" instead */
- keys[3] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 1);
- bytes += adsi_voice_mode(buf + bytes, 0);
-
- } else {
- /* Otherwise if only message, leave blank */
- keys[3] = 1;
- }
- }
-
- if (!ast_strlen_zero(cid)) {
- ast_callerid_parse(cid, &name, &num);
- if (!name)
- name = num;
- } else
- name = "Unknown Caller";
-
- /* If deleted, show "undeleted" */
-
- if (vms->deleted[vms->curmsg])
- keys[1] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 11);
-
- /* Except "Exit" */
- keys[5] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 5);
- snprintf(buf1, sizeof(buf1), "%s%s", vms->curbox,
- strcasecmp(vms->curbox, "INBOX") ? " Messages" : "");
- snprintf(buf2, sizeof(buf2), "Message %d of %d", vms->curmsg + 1, vms->lastmsg + 1);
-
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 1, ADSI_JUST_LEFT, 0, buf1, "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 2, ADSI_JUST_LEFT, 0, buf2, "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_LEFT, 0, name, "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_LEFT, 0, datetime, "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_set_keys(buf + bytes, keys);
- bytes += adsi_voice_mode(buf + bytes, 0);
-
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-}
-
-static void adsi_delete(struct ast_channel *chan, struct vm_state *vms)
-{
- int bytes=0;
- unsigned char buf[256];
- unsigned char keys[8];
-
- int x;
-
- if (!adsi_available(chan))
- return;
-
- /* New meaning for keys */
- for (x=0;x<5;x++)
- keys[x] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 6 + x);
-
- keys[6] = 0x0;
- keys[7] = 0x0;
-
- if (!vms->curmsg) {
- /* No prev key, provide "Folder" instead */
- keys[0] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 1);
- }
- if (vms->curmsg >= vms->lastmsg) {
- /* If last message ... */
- if (vms->curmsg) {
- /* but not only message, provide "Folder" instead */
- keys[3] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 1);
- } else {
- /* Otherwise if only message, leave blank */
- keys[3] = 1;
- }
- }
-
- /* If deleted, show "undeleted" */
- if (vms->deleted[vms->curmsg])
- keys[1] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 11);
-
- /* Except "Exit" */
- keys[5] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 5);
- bytes += adsi_set_keys(buf + bytes, keys);
- bytes += adsi_voice_mode(buf + bytes, 0);
-
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-}
-
-static void adsi_status(struct ast_channel *chan, struct vm_state *vms)
-{
- unsigned char buf[256] = "";
- char buf1[256] = "", buf2[256] = "";
- int bytes=0;
- unsigned char keys[8];
- int x;
-
- char *newm = (vms->newmessages == 1) ? "message" : "messages";
- char *oldm = (vms->oldmessages == 1) ? "message" : "messages";
- if (!adsi_available(chan))
- return;
- if (vms->newmessages) {
- snprintf(buf1, sizeof(buf1), "You have %d new", vms->newmessages);
- if (vms->oldmessages) {
- strncat(buf1, " and", sizeof(buf1) - strlen(buf1) - 1);
- snprintf(buf2, sizeof(buf2), "%d old %s.", vms->oldmessages, oldm);
- } else {
- snprintf(buf2, sizeof(buf2), "%s.", newm);
- }
- } else if (vms->oldmessages) {
- snprintf(buf1, sizeof(buf1), "You have %d old", vms->oldmessages);
- snprintf(buf2, sizeof(buf2), "%s.", oldm);
- } else {
- strcpy(buf1, "You have no messages.");
- buf2[0] = ' ';
- buf2[1] = '\0';
- }
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 1, ADSI_JUST_LEFT, 0, buf1, "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 2, ADSI_JUST_LEFT, 0, buf2, "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
-
- for (x=0;x<6;x++)
- keys[x] = ADSI_KEY_SKT | (ADSI_KEY_APPS + x);
- keys[6] = 0;
- keys[7] = 0;
-
- /* Don't let them listen if there are none */
- if (vms->lastmsg < 0)
- keys[0] = 1;
- bytes += adsi_set_keys(buf + bytes, keys);
-
- bytes += adsi_voice_mode(buf + bytes, 0);
-
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-}
-
-static void adsi_status2(struct ast_channel *chan, struct vm_state *vms)
-{
- unsigned char buf[256] = "";
- char buf1[256] = "", buf2[256] = "";
- int bytes=0;
- unsigned char keys[8];
- int x;
-
- char *mess = (vms->lastmsg == 0) ? "message" : "messages";
-
- if (!adsi_available(chan))
- return;
-
- /* Original command keys */
- for (x=0;x<6;x++)
- keys[x] = ADSI_KEY_SKT | (ADSI_KEY_APPS + x);
-
- keys[6] = 0;
- keys[7] = 0;
-
- if ((vms->lastmsg + 1) < 1)
- keys[0] = 0;
-
- snprintf(buf1, sizeof(buf1), "%s%s has", vms->curbox,
- strcasecmp(vms->curbox, "INBOX") ? " folder" : "");
-
- if (vms->lastmsg + 1)
- snprintf(buf2, sizeof(buf2), "%d %s.", vms->lastmsg + 1, mess);
- else
- strcpy(buf2, "no messages.");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 1, ADSI_JUST_LEFT, 0, buf1, "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 2, ADSI_JUST_LEFT, 0, buf2, "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_LEFT, 0, "", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_set_keys(buf + bytes, keys);
-
- bytes += adsi_voice_mode(buf + bytes, 0);
-
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-
-}
-
-/*
-static void adsi_clear(struct ast_channel *chan)
-{
- char buf[256];
- int bytes=0;
- if (!adsi_available(chan))
- return;
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_voice_mode(buf + bytes, 0);
-
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-}
-*/
-
-static void adsi_goodbye(struct ast_channel *chan)
-{
- unsigned char buf[256];
- int bytes=0;
-
- if (!adsi_available(chan))
- return;
- bytes += adsi_logo(buf + bytes);
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_LEFT, 0, " ", "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_CENT, 0, "Goodbye", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_voice_mode(buf + bytes, 0);
-
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
-}
-
-/*--- get_folder: Folder menu ---*/
-/* Plays "press 1 for INBOX messages" etc
- Should possibly be internationalized
- */
-static int get_folder(struct ast_channel *chan, int start)
-{
- int x;
- int d;
- char fn[256];
- d = ast_play_and_wait(chan, "vm-press"); /* "Press" */
- if (d)
- return d;
- for (x = start; x< 5; x++) { /* For all folders */
- if ((d = ast_say_number(chan, x, AST_DIGIT_ANY, chan->language, (char *) NULL)))
- return d;
- d = ast_play_and_wait(chan, "vm-for"); /* "for" */
- if (d)
- return d;
- snprintf(fn, sizeof(fn), "vm-%s", mbox(x)); /* Folder name */
- d = vm_play_folder_name(chan, fn);
- if (d)
- return d;
- d = ast_waitfordigit(chan, 500);
- if (d)
- return d;
- }
- d = ast_play_and_wait(chan, "vm-tocancel"); /* "or pound to cancel" */
- if (d)
- return d;
- d = ast_waitfordigit(chan, 4000);
- return d;
-}
-
-static int get_folder2(struct ast_channel *chan, char *fn, int start)
-{
- int res = 0;
- res = ast_play_and_wait(chan, fn); /* Folder name */
- while (((res < '0') || (res > '9')) &&
- (res != '#') && (res >= 0)) {
- res = get_folder(chan, 0);
- }
- return res;
-}
-
-static int vm_forwardoptions(struct ast_channel *chan, struct ast_vm_user *vmu, char *curdir, int curmsg, char *vmfts,
- char *context, signed char record_gain)
-{
- int cmd = 0;
- int retries = 0;
- int duration = 0;
- signed char zero_gain = 0;
-
- while ((cmd >= 0) && (cmd != 't') && (cmd != '*')) {
- if (cmd)
- retries = 0;
- switch (cmd) {
- case '1':
- /* prepend a message to the current message and return */
- {
- char file[200];
- snprintf(file, sizeof(file), "%s/msg%04d", curdir, curmsg);
- if (record_gain)
- ast_channel_setoption(chan, AST_OPTION_RXGAIN, &record_gain, sizeof(record_gain), 0);
- cmd = ast_play_and_prepend(chan, NULL, file, 0, vmfmts, &duration, 1, silencethreshold, maxsilence);
- if (record_gain)
- ast_channel_setoption(chan, AST_OPTION_RXGAIN, &zero_gain, sizeof(zero_gain), 0);
- break;
- }
- case '2':
- cmd = 't';
- break;
- case '*':
- cmd = '*';
- break;
- default:
- cmd = ast_play_and_wait(chan,"vm-forwardoptions");
- /* "Press 1 to prepend a message or 2 to forward the message without prepending" */
- if (!cmd)
- cmd = ast_play_and_wait(chan,"vm-starmain");
- /* "press star to return to the main menu" */
- if (!cmd)
- cmd = ast_waitfordigit(chan,6000);
- if (!cmd)
- retries++;
- if (retries > 3)
- cmd = 't';
- }
- }
- if (cmd == 't')
- cmd = 0;
- return cmd;
-}
-
-static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu, int msgnum, long duration, char *fmt, char *cidnum, char *cidname)
-{
- char todir[256], fn[256], ext_context[256], *stringp;
- int newmsgs = 0, oldmsgs = 0;
-
- make_dir(todir, sizeof(todir), vmu->context, vmu->mailbox, "INBOX");
- make_file(fn, sizeof(fn), todir, msgnum);
- snprintf(ext_context, sizeof(ext_context), "%s@%s", vmu->mailbox, vmu->context);
-
- /* Attach only the first format */
- fmt = ast_strdupa(fmt);
- if (fmt) {
- stringp = fmt;
- strsep(&stringp, "|");
-
- if (!ast_strlen_zero(vmu->email)) {
- int attach_user_voicemail = ast_test_flag((&globalflags), VM_ATTACH);
- char *myserveremail = serveremail;
- attach_user_voicemail = ast_test_flag(vmu, VM_ATTACH);
- if (!ast_strlen_zero(vmu->serveremail))
- myserveremail = vmu->serveremail;
- sendmail(myserveremail, vmu, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, fn, fmt, duration, attach_user_voicemail);
- }
-
- if (!ast_strlen_zero(vmu->pager)) {
- char *myserveremail = serveremail;
- if (!ast_strlen_zero(vmu->serveremail))
- myserveremail = vmu->serveremail;
- sendpage(myserveremail, vmu->pager, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, duration, vmu);
- }
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- }
-
- if (ast_test_flag(vmu, VM_DELETE)) {
- DELETE(todir, msgnum, fn);
- }
-
- /* Leave voicemail for someone */
- if (ast_app_has_voicemail(ext_context, NULL)) {
- ast_app_messagecount(ext_context, &newmsgs, &oldmsgs);
- }
- manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s@%s\r\nWaiting: %d\r\nNew: %d\r\nOld: %d\r\n", vmu->mailbox, vmu->context, ast_app_has_voicemail(ext_context, NULL), newmsgs, oldmsgs);
- run_externnotify(vmu->context, vmu->mailbox);
- return 0;
-}
-
-static int forward_message(struct ast_channel *chan, char *context, char *dir, int curmsg, struct ast_vm_user *sender,
- char *fmt, int flag, signed char record_gain)
-{
- char username[70]="";
- char sys[256];
- char todir[256];
- int todircount=0;
- int duration;
- struct ast_config *mif;
- char miffile[256];
- char fn[256];
- char callerid[512];
- char ext_context[256]="";
- int res = 0, cmd = 0;
- struct ast_vm_user *receiver = NULL, *extensions = NULL, *vmtmp = NULL, *vmfree;
- char tmp[256];
- char *stringp, *s;
- int saved_messages = 0, found = 0;
- int valid_extensions = 0;
-
- while (!res && !valid_extensions) {
- int use_directory = 0;
- if(ast_test_flag((&globalflags), VM_DIRECFORWARD)) {
- int done = 0;
- int retries = 0;
- cmd=0;
- while((cmd >= 0) && !done ){
- if (cmd)
- retries = 0;
- switch (cmd) {
- case '1':
- use_directory = 0;
- done = 1;
- break;
- case '2':
- use_directory = 1;
- done=1;
- break;
- case '*':
- cmd = 't';
- done = 1;
- break;
- default:
- /* Press 1 to enter an extension press 2 to use the directory */
- cmd = ast_play_and_wait(chan,"vm-forward");
- if (!cmd)
- cmd = ast_waitfordigit(chan,3000);
- if (!cmd)
- retries++;
- if (retries > 3)
- {
- cmd = 't';
- done = 1;
- }
-
- }
- }
- if( cmd<0 || cmd=='t' )
- break;
- }
-
- if (use_directory) {
- /* use app_directory */
-
- char old_context[sizeof(chan->context)];
- char old_exten[sizeof(chan->exten)];
- int old_priority;
- struct ast_app* app;
-
-
- app = pbx_findapp("Directory");
- if (app) {
- /* make mackup copies */
- memcpy(old_context, chan->context, sizeof(chan->context));
- memcpy(old_exten, chan->exten, sizeof(chan->exten));
- old_priority = chan->priority;
-
- /* call the the Directory, changes the channel */
- res = pbx_exec(chan, app, context ? context : "default", 1);
-
- ast_copy_string(username, chan->exten, sizeof(username));
-
- /* restore the old context, exten, and priority */
- memcpy(chan->context, old_context, sizeof(chan->context));
- memcpy(chan->exten, old_exten, sizeof(chan->exten));
- chan->priority = old_priority;
-
- } else {
- ast_log(LOG_WARNING, "Could not find the Directory application, disabling directory_forward\n");
- ast_clear_flag((&globalflags), VM_DIRECFORWARD);
- }
- } else {
- /* Ask for an extension */
- res = ast_streamfile(chan, "vm-extension", chan->language); /* "extension" */
- if (res)
- break;
- if ((res = ast_readstring(chan, username, sizeof(username) - 1, 2000, 10000, "#") < 0))
- break;
- }
-
- /* start all over if no username */
- if (ast_strlen_zero(username))
- continue;
- stringp = username;
- s = strsep(&stringp, "*");
- /* start optimistic */
- valid_extensions = 1;
- while (s) {
- /* find_user is going to malloc since we have a NULL as first argument */
- if ((receiver = find_user(NULL, context, s))) {
- if (!extensions)
- vmtmp = extensions = receiver;
- else {
- vmtmp->next = receiver;
- vmtmp = receiver;
- }
- found++;
- } else {
- valid_extensions = 0;
- break;
- }
- s = strsep(&stringp, "*");
- }
- /* break from the loop of reading the extensions */
- if (valid_extensions)
- break;
- /* "I am sorry, that's not a valid extension. Please try again." */
- res = ast_play_and_wait(chan, "pbx-invalid");
- }
- /* check if we're clear to proceed */
- if (!extensions || !valid_extensions)
- return res;
- vmtmp = extensions;
- if (flag==1) {
- struct leave_vm_options leave_options;
-
- /* Send VoiceMail */
- memset(&leave_options, 0, sizeof(leave_options));
- leave_options.record_gain = record_gain;
- cmd = leave_voicemail(chan, username, &leave_options);
- } else {
- /* Forward VoiceMail */
- RETRIEVE(dir, curmsg);
- cmd = vm_forwardoptions(chan, sender, dir, curmsg, vmfmts, context, record_gain);
- if (!cmd) {
- while (!res && vmtmp) {
- /* if (ast_play_and_wait(chan, "vm-savedto"))
- break;
- */
- snprintf(todir, sizeof(todir), "%s%s/%s/INBOX", VM_SPOOL_DIR, vmtmp->context, vmtmp->mailbox);
- snprintf(sys, sizeof(sys), "mkdir -p %s\n", todir);
- snprintf(ext_context, sizeof(ext_context), "%s@%s", vmtmp->mailbox, vmtmp->context);
- ast_log(LOG_DEBUG, "%s", sys);
- ast_safe_system(sys);
-
- res = count_messages(receiver, todir);
-
- if ( (res == ERROR_LOCK_PATH) || (res < 0) ) {
- if (res == ERROR_LOCK_PATH)
- ast_log(LOG_WARNING, "Unable to lock the directory %s to forward the requested vmail msg!\n", todir);
- else
- ast_log(LOG_WARNING, "Unable to determine how many msgs are in the destination folder!\n");
- break;
- }
- todircount = res;
- ast_copy_string(tmp, fmt, sizeof(tmp));
- stringp = tmp;
- while ((s = strsep(&stringp, "|"))) {
- /* XXX This is a hack -- we should use build_filename or similar XXX */
- if (!strcasecmp(s, "wav49"))
- s = "WAV";
- snprintf(sys, sizeof(sys), "cp %s/msg%04d.%s %s/msg%04d.%s\n", dir, curmsg, s, todir, todircount, s);
- ast_log(LOG_DEBUG, "%s", sys);
- ast_safe_system(sys);
- }
- snprintf(sys, sizeof(sys), "cp %s/msg%04d.txt %s/msg%04d.txt\n", dir, curmsg, todir, todircount);
- ast_log(LOG_DEBUG, "%s", sys);
- ast_safe_system(sys);
- snprintf(fn, sizeof(fn), "%s/msg%04d", todir,todircount);
-
- STORE(todir, vmtmp->mailbox, vmtmp->context, todircount);
-
- /* load the information on the source message so we can send an e-mail like a new message */
- snprintf(miffile, sizeof(miffile), "%s/msg%04d.txt", dir, curmsg);
- if ((mif=ast_config_load(miffile))) {
-
- /* set callerid and duration variables */
- snprintf(callerid, sizeof(callerid), "FWD from: %s from %s", sender->fullname, ast_variable_retrieve(mif, NULL, "callerid"));
- s = ast_variable_retrieve(mif, NULL, "duration");
- if (s)
- duration = atoi(s);
- else
- duration = 0;
- if (!ast_strlen_zero(vmtmp->email)) {
- int attach_user_voicemail = ast_test_flag((&globalflags), VM_ATTACH);
- char *myserveremail = serveremail;
- attach_user_voicemail = ast_test_flag(vmtmp, VM_ATTACH);
- if (!ast_strlen_zero(vmtmp->serveremail))
- myserveremail = vmtmp->serveremail;
- sendmail(myserveremail, vmtmp, todircount, vmtmp->context, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, fn, tmp, duration, attach_user_voicemail);
- }
-
- if (!ast_strlen_zero(vmtmp->pager)) {
- char *myserveremail = serveremail;
- if (!ast_strlen_zero(vmtmp->serveremail))
- myserveremail = vmtmp->serveremail;
- sendpage(myserveremail, vmtmp->pager, todircount, vmtmp->context, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, duration, vmtmp);
- }
-
- ast_config_destroy(mif); /* or here */
- }
- /* Leave voicemail for someone */
- manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, has_voicemail(ext_context, NULL));
- run_externnotify(vmtmp->context, vmtmp->mailbox);
-
- saved_messages++;
- vmfree = vmtmp;
- vmtmp = vmtmp->next;
- free_user(vmfree);
- }
- if (saved_messages > 0) {
- /* give confirmation that the message was saved */
- /* commented out since we can't forward batches yet
- if (saved_messages == 1)
- res = ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-messages");
- if (!res)
- res = ast_play_and_wait(chan, "vm-saved"); */
- res = ast_play_and_wait(chan, "vm-msgsaved");
- }
- }
- }
- return res ? res : cmd;
-}
-
-static int wait_file2(struct ast_channel *chan, struct vm_state *vms, char *file)
-{
- int res;
- if ((res = ast_streamfile(chan, file, chan->language)))
- ast_log(LOG_WARNING, "Unable to play message %s\n", file);
- if (!res)
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- return res;
-}
-
-static int wait_file(struct ast_channel *chan, struct vm_state *vms, char *file)
-{
- return ast_control_streamfile(chan, file, "#", "*", "1456789", "0", "2", skipms);
-}
-
-static int play_message_category(struct ast_channel *chan, char *category)
-{
- int res = 0;
-
- if (!ast_strlen_zero(category))
- res = ast_play_and_wait(chan, category);
-
- return res;
-}
-
-static int play_message_datetime(struct ast_channel *chan, struct ast_vm_user *vmu, char *origtime, char *filename)
-{
- int res = 0;
- struct vm_zone *the_zone = NULL;
- time_t t;
- long tin;
-
- if (sscanf(origtime,"%ld",&tin) < 1) {
- ast_log(LOG_WARNING, "Couldn't find origtime in %s\n", filename);
- return 0;
- }
- t = tin;
-
- /* Does this user have a timezone specified? */
- if (!ast_strlen_zero(vmu->zonetag)) {
- /* Find the zone in the list */
- struct vm_zone *z;
- z = zones;
- while (z) {
- if (!strcmp(z->name, vmu->zonetag)) {
- the_zone = z;
- break;
- }
- z = z->next;
- }
- }
-
-/* No internal variable parsing for now, so we'll comment it out for the time being */
-#if 0
- /* Set the DIFF_* variables */
- localtime_r(&t, &time_now);
- tv_now = ast_tvnow();
- tnow = tv_now.tv_sec;
- localtime_r(&tnow,&time_then);
-
- /* Day difference */
- if (time_now.tm_year == time_then.tm_year)
- snprintf(temp,sizeof(temp),"%d",time_now.tm_yday);
- else
- snprintf(temp,sizeof(temp),"%d",(time_now.tm_year - time_then.tm_year) * 365 + (time_now.tm_yday - time_then.tm_yday));
- pbx_builtin_setvar_helper(chan, "DIFF_DAY", temp);
-
- /* Can't think of how other diffs might be helpful, but I'm sure somebody will think of something. */
-#endif
- if (the_zone)
- res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, the_zone->msg_format, the_zone->timezone);
- else if(!strcasecmp(chan->language,"se")) /* SWEDISH syntax */
- res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' dB 'digits/at' k 'and' M", NULL);
- else if(!strcasecmp(chan->language,"no")) /* NORWEGIAN syntax */
- res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' Q 'digits/at' HM", NULL);
- else if(!strcasecmp(chan->language,"de")) /* GERMAN syntax */
- res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' Q 'digits/at' HM", NULL);
- else if (!strcasecmp(chan->language,"nl")) /* DUTCH syntax */
- res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' q 'digits/nl-om' HM", NULL);
- else if (!strcasecmp(chan->language,"it")) /* ITALIAN syntax */
- res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' q 'digits/at' 'digits/hours' k 'digits/e' M 'digits/minutes'", NULL);
- else if (!strcasecmp(chan->language,"gr"))
- res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' q H 'digits/kai' M ", NULL);
- else
- res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' q 'digits/at' IMp", NULL);
-#if 0
- pbx_builtin_setvar_helper(chan, "DIFF_DAY", NULL);
-#endif
- return res;
-}
-
-
-
-static int play_message_callerid(struct ast_channel *chan, struct vm_state *vms, char *cid, char *context, int callback)
-{
- int res = 0;
- int i;
- char *callerid, *name;
- char prefile[256]="";
-
-
- /* If voicemail cid is not enabled, or we didn't get cid or context from the attribute file, leave now. */
- /* BB: Still need to change this so that if this function is called by the message envelope (and someone is explicitly requesting to hear the CID), it does not check to see if CID is enabled in the config file */
- if ((cid == NULL)||(context == NULL))
- return res;
-
- /* Strip off caller ID number from name */
- ast_log(LOG_DEBUG, "VM-CID: composite caller ID received: %s, context: %s\n", cid, context);
- ast_callerid_parse(cid, &name, &callerid);
- if ((!ast_strlen_zero(callerid)) && strcmp(callerid, "Unknown")) {
- /* Check for internal contexts and only */
- /* say extension when the call didn't come from an internal context in the list */
- for (i = 0 ; i < MAX_NUM_CID_CONTEXTS ; i++){
- ast_log(LOG_DEBUG, "VM-CID: comparing internalcontext: %s\n", cidinternalcontexts[i]);
- if ((strcmp(cidinternalcontexts[i], context) == 0))
- break;
- }
- if (i != MAX_NUM_CID_CONTEXTS){ /* internal context? */
- if (!res) {
- snprintf(prefile, sizeof(prefile), "%s%s/%s/greet", VM_SPOOL_DIR, context, callerid);
- if (!ast_strlen_zero(prefile)) {
- /* See if we can find a recorded name for this person instead of their extension number */
- if (ast_fileexists(prefile, NULL, NULL) > 0) {
- ast_verbose(VERBOSE_PREFIX_3 "Playing envelope info: CID number '%s' matches mailbox number, playing recorded name\n", callerid);
- if (!callback)
- res = wait_file2(chan, vms, "vm-from");
- res = ast_streamfile(chan, prefile, chan->language) > -1;
- res = ast_waitstream(chan, "");
- } else {
- ast_verbose(VERBOSE_PREFIX_3 "Playing envelope info: message from '%s'\n", callerid);
- /* BB: Say "from extension" as one saying to sound smoother */
- if (!callback)
- res = wait_file2(chan, vms, "vm-from-extension");
- res = ast_say_digit_str(chan, callerid, "", chan->language);
- }
- }
- }
- }
-
- else if (!res){
- ast_log(LOG_DEBUG, "VM-CID: Numeric caller id: (%s)\n",callerid);
- /* BB: Since this is all nicely figured out, why not say "from phone number" in this case" */
- if (!callback)
- res = wait_file2(chan, vms, "vm-from-phonenumber");
- res = ast_say_digit_str(chan, callerid, AST_DIGIT_ANY, chan->language);
- }
- } else {
- /* Number unknown */
- ast_log(LOG_DEBUG, "VM-CID: From an unknown number\n");
- /* Say "from an unknown caller" as one phrase - it is already recorded by "the voice" anyhow */
- res = wait_file2(chan, vms, "vm-unknown-caller");
- }
- return res;
-}
-
-static int play_message_duration(struct ast_channel *chan, struct vm_state *vms, char *duration, int minduration)
-{
- int res = 0;
- int durationm;
- int durations;
- /* Verify that we have a duration for the message */
- if((duration == NULL))
- return res;
-
- /* Convert from seconds to minutes */
- durations=atoi(duration);
- durationm=(durations / 60);
-
- ast_log(LOG_DEBUG, "VM-Duration: duration is: %d seconds converted to: %d minutes\n", durations, durationm);
-
- if((!res)&&(durationm>=minduration)) {
- res = ast_say_number(chan, durationm, AST_DIGIT_ANY, chan->language, (char *) NULL);
- res = wait_file2(chan, vms, "vm-minutes");
- }
- return res;
-}
-
-static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms)
-{
- int res = 0;
- char filename[256],*origtime, *cid, *context, *duration;
- char *category;
- struct ast_config *msg_cfg;
-
- vms->starting = 0;
- make_file(vms->fn, sizeof(vms->fn), vms->curdir, vms->curmsg);
- adsi_message(chan, vms);
- if (!vms->curmsg)
- res = wait_file2(chan, vms, "vm-first"); /* "First" */
- else if (vms->curmsg == vms->lastmsg)
- res = wait_file2(chan, vms, "vm-last"); /* "last" */
- if (!res) {
- if (!strcasecmp(chan->language, "se")) { /* SWEDISH syntax */
- res = wait_file2(chan, vms, "vm-meddelandet"); /* "message" */
- }
- else {
- res = wait_file2(chan, vms, "vm-message"); /* "message" */
- }
- if (vms->curmsg && (vms->curmsg != vms->lastmsg)) {
- if (!res)
- res = ast_say_number(chan, vms->curmsg + 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
- }
- }
-
- /* Retrieve info from VM attribute file */
- make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
- snprintf(filename,sizeof(filename), "%s.txt", vms->fn2);
- RETRIEVE(vms->curdir, vms->curmsg);
- msg_cfg = ast_config_load(filename);
- if (!msg_cfg) {
- ast_log(LOG_WARNING, "No message attribute file?!! (%s)\n", filename);
- return 0;
- }
-
- if (!(origtime = ast_variable_retrieve(msg_cfg, "message", "origtime"))) {
- ast_log(LOG_WARNING, "No origtime?!\n");
- DISPOSE(vms->curdir, vms->curmsg);
- ast_config_destroy(msg_cfg);
- return 0;
- }
-
- cid = ast_variable_retrieve(msg_cfg, "message", "callerid");
- duration = ast_variable_retrieve(msg_cfg, "message", "duration");
- category = ast_variable_retrieve(msg_cfg, "message", "category");
-
- context = ast_variable_retrieve(msg_cfg, "message", "context");
- if (!strncasecmp("macro",context,5)) /* Macro names in contexts are useless for our needs */
- context = ast_variable_retrieve(msg_cfg, "message","macrocontext");
-
- if (!res)
- res = play_message_category(chan, category);
- if ((!res) && (ast_test_flag(vmu, VM_ENVELOPE)))
- res = play_message_datetime(chan, vmu, origtime, filename);
- if ((!res) && (ast_test_flag(vmu, VM_SAYCID)))
- res = play_message_callerid(chan, vms, cid, context, 0);
- if ((!res) && (ast_test_flag(vmu, VM_SAYDURATION)))
- res = play_message_duration(chan, vms, duration, vmu->saydurationm);
- /* Allow pressing '1' to skip envelope / callerid */
- if (res == '1')
- res = 0;
- ast_config_destroy(msg_cfg);
-
- if (!res) {
- make_file(vms->fn, sizeof(vms->fn), vms->curdir, vms->curmsg);
- vms->heard[vms->curmsg] = 1;
- res = wait_file(chan, vms, vms->fn);
- }
- DISPOSE(vms->curdir, vms->curmsg);
- return res;
-}
-
-static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box)
-{
- int res = 0;
- int count_msg, last_msg;
-
- ast_copy_string(vms->curbox, mbox(box), sizeof(vms->curbox));
-
- /* Rename the member vmbox HERE so that we don't try to return before
- * we know what's going on.
- */
- snprintf(vms->vmbox, sizeof(vms->vmbox), "vm-%s", vms->curbox);
-
- make_dir(vms->curdir, sizeof(vms->curdir), vmu->context, vms->username, vms->curbox);
- count_msg = count_messages(vmu, vms->curdir);
- if (count_msg < 0)
- return count_msg;
- else
- vms->lastmsg = count_msg - 1;
-
- /*
- The following test is needed in case sequencing gets messed up.
- There appears to be more than one way to mess up sequence, so
- we will not try to find all of the root causes--just fix it when
- detected.
- */
-
- last_msg = last_message_index(vmu, vms->curdir);
- if (last_msg < 0)
- return last_msg;
- else if(vms->lastmsg != last_msg)
- {
- ast_log(LOG_NOTICE, "Resequencing Mailbox: %s\n", vms->curdir);
- res = resequence_mailbox(vmu, vms->curdir);
- if (res)
- return res;
- }
-
- return 0;
-}
-
-static int close_mailbox(struct vm_state *vms, struct ast_vm_user *vmu)
-{
- int x, nummsg;
- int res = 0;
-
- if (vms->lastmsg <= -1)
- goto done;
-
- /* Get the deleted messages fixed */
- if (vm_lock_path(vms->curdir))
- return ERROR_LOCK_PATH;
-
- vms->curmsg = -1;
- for (x=0;x < vmu->maxmsg;x++) {
- if (!vms->deleted[x] && (strcasecmp(vms->curbox, "INBOX") || !vms->heard[x])) {
- /* Save this message. It's not in INBOX or hasn't been heard */
- make_file(vms->fn, sizeof(vms->fn), vms->curdir, x);
- if (!EXISTS(vms->curdir, x, vms->fn, NULL))
- break;
- vms->curmsg++;
- make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
- if (strcmp(vms->fn, vms->fn2)) {
- RENAME(vms->curdir, x, vmu->mailbox,vmu->context, vms->curdir, vms->curmsg, vms->fn, vms->fn2);
- }
- } else if (!strcasecmp(vms->curbox, "INBOX") && vms->heard[x] && !vms->deleted[x]) {
- /* Move to old folder before deleting */
- res = save_to_folder(vmu, vms->curdir, x, vmu->context, vms->username, 1);
- if (res == ERROR_LOCK_PATH) {
- /* If save failed do not delete the message */
- vms->deleted[x] = 0;
- vms->heard[x] = 0;
- --x;
- }
- }
- }
-
- /* Delete ALL remaining messages */
- nummsg = x - 1;
- for (x = vms->curmsg + 1; x <= nummsg; x++) {
- make_file(vms->fn, sizeof(vms->fn), vms->curdir, x);
- if (EXISTS(vms->curdir, x, vms->fn, NULL))
- DELETE(vms->curdir, x, vms->fn);
- }
- ast_unlock_path(vms->curdir);
-
-done:
- if (vms->deleted)
- memset(vms->deleted, 0, sizeof(vms->deleted));
- if (vms->heard)
- memset(vms->heard, 0, sizeof(vms->heard));
-
- return 0;
-}
-
-/* In Greek even though we CAN use a syntax like "friends messages"
- * ("filika mynhmata") it is not elegant. This also goes for "work/family messages"
- * ("ergasiaka/oikogeniaka mynhmata"). Therefore it is better to use a reversed
- * syntax for the above three categories which is more elegant.
-*/
-
-static int vm_play_folder_name_gr(struct ast_channel *chan, char *mbox)
-{
- int cmd;
- char *buf;
-
- buf = alloca(strlen(mbox)+2);
- strcpy(buf, mbox);
- strcat(buf,"s");
-
- if (!strcasecmp(mbox, "vm-INBOX") || !strcasecmp(mbox, "vm-Old")){
- cmd = ast_play_and_wait(chan, buf); /* "NEA / PALIA" */
- if (cmd)
- return cmd;
- return ast_play_and_wait(chan, "vm-messages"); /* "messages" -> "MYNHMATA" */
- } else {
- cmd = ast_play_and_wait(chan, "vm-messages"); /* "messages" -> "MYNHMATA" */
- if (cmd)
- return cmd;
- return ast_play_and_wait(chan, mbox); /* friends/family/work... -> "FILWN"/"OIKOGENIAS"/"DOULEIAS"*/
- }
-}
-
-static int vm_play_folder_name(struct ast_channel *chan, char *mbox)
-{
- int cmd;
-
- if (!strcasecmp(chan->language, "it") || !strcasecmp(chan->language, "es") || !strcasecmp(chan->language, "fr") || !strcasecmp(chan->language, "pt")) { /* Italian, Spanish, French or Portuguese syntax */
- cmd = ast_play_and_wait(chan, "vm-messages"); /* "messages */
- if (cmd)
- return cmd;
- return ast_play_and_wait(chan, mbox);
- } else if (!strcasecmp(chan->language, "gr")){
- return vm_play_folder_name_gr(chan, mbox);
- } else { /* Default English */
- cmd = ast_play_and_wait(chan, mbox);
- if (cmd)
- return cmd;
- return ast_play_and_wait(chan, "vm-messages"); /* "messages */
- }
-}
-
- /* GREEK SYNTAX
- In greek the plural for old/new is
- different so we need the following files
- We also need vm-denExeteMynhmata because
- this syntax is different.
-
- -> vm-Olds.wav : "Palia"
- -> vm-INBOXs.wav : "Nea"
- -> vm-denExeteMynhmata : "den exete mynhmata"
- */
-
-
-static int vm_intro_gr(struct ast_channel *chan, struct vm_state *vms)
-{
- int res = 0;
-
- if (vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-youhave");
- if (!res)
- res = ast_say_number(chan, vms->newmessages, AST_DIGIT_ANY, chan->language, NULL);
- if (!res) {
- if ((vms->newmessages == 1)) {
- res = ast_play_and_wait(chan, "vm-INBOX");
- if (!res)
- res = ast_play_and_wait(chan, "vm-message");
- } else {
- res = ast_play_and_wait(chan, "vm-INBOXs");
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- }
- }
- } else if (vms->oldmessages){
- res = ast_play_and_wait(chan, "vm-youhave");
- if (!res)
- res = ast_say_number(chan, vms->oldmessages, AST_DIGIT_ANY, chan->language, NULL);
- if ((vms->oldmessages == 1)){
- res = ast_play_and_wait(chan, "vm-Old");
- if (!res)
- res = ast_play_and_wait(chan, "vm-message");
- } else {
- res = ast_play_and_wait(chan, "vm-Olds");
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- }
- } else if (!vms->oldmessages && !vms->newmessages)
- res = ast_play_and_wait(chan, "vm-denExeteMynhmata");
- return res;
-}
-
-/* Default English syntax */
-static int vm_intro_en(struct ast_channel *chan,struct vm_state *vms)
-{
- /* Introduce messages they have */
- int res;
- res = ast_play_and_wait(chan, "vm-youhave");
- if (!res) {
- if (vms->newmessages) {
- res = say_and_wait(chan, vms->newmessages, chan->language);
- if (!res)
- res = ast_play_and_wait(chan, "vm-INBOX");
- if (vms->oldmessages && !res)
- res = ast_play_and_wait(chan, "vm-and");
- else if (!res) {
- if ((vms->newmessages == 1))
- res = ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-messages");
- }
-
- }
- if (!res && vms->oldmessages) {
- res = say_and_wait(chan, vms->oldmessages, chan->language);
- if (!res)
- res = ast_play_and_wait(chan, "vm-Old");
- if (!res) {
- if (vms->oldmessages == 1)
- res = ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-messages");
- }
- }
- if (!res) {
- if (!vms->oldmessages && !vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-no");
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- }
- }
- }
- return res;
-}
-
-/* ITALIAN syntax */
-static int vm_intro_it(struct ast_channel *chan, struct vm_state *vms)
-{
- /* Introduce messages they have */
- int res;
- if (!vms->oldmessages && !vms->newmessages)
- res = ast_play_and_wait(chan, "vm-no") ||
- ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-youhave");
- if (!res && vms->newmessages) {
- res = (vms->newmessages == 1) ?
- ast_play_and_wait(chan, "digits/un") ||
- ast_play_and_wait(chan, "vm-nuovo") ||
- ast_play_and_wait(chan, "vm-message") :
- /* 2 or more new messages */
- say_and_wait(chan, vms->newmessages, chan->language) ||
- ast_play_and_wait(chan, "vm-nuovi") ||
- ast_play_and_wait(chan, "vm-messages");
- if (!res && vms->oldmessages)
- res = ast_play_and_wait(chan, "vm-and");
- }
- if (!res && vms->oldmessages) {
- res = (vms->oldmessages == 1) ?
- ast_play_and_wait(chan, "digits/un") ||
- ast_play_and_wait(chan, "vm-vecchio") ||
- ast_play_and_wait(chan, "vm-message") :
- /* 2 or more old messages */
- say_and_wait(chan, vms->oldmessages, chan->language) ||
- ast_play_and_wait(chan, "vm-vecchi") ||
- ast_play_and_wait(chan, "vm-messages");
- }
- return res ? -1 : 0;
-}
-
-/* SWEDISH syntax */
-static int vm_intro_se(struct ast_channel *chan, struct vm_state *vms)
-{
- /* Introduce messages they have */
- int res;
-
- res = ast_play_and_wait(chan, "vm-youhave");
- if (res)
- return res;
-
- if (!vms->oldmessages && !vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-no");
- res = res ? res : ast_play_and_wait(chan, "vm-messages");
- return res;
- }
-
- if (vms->newmessages) {
- if ((vms->newmessages == 1)) {
- res = ast_play_and_wait(chan, "digits/ett");
- res = res ? res : ast_play_and_wait(chan, "vm-nytt");
- res = res ? res : ast_play_and_wait(chan, "vm-message");
- } else {
- res = say_and_wait(chan, vms->newmessages, chan->language);
- res = res ? res : ast_play_and_wait(chan, "vm-nya");
- res = res ? res : ast_play_and_wait(chan, "vm-messages");
- }
- if (!res && vms->oldmessages)
- res = ast_play_and_wait(chan, "vm-and");
- }
- if (!res && vms->oldmessages) {
- if (vms->oldmessages == 1) {
- res = ast_play_and_wait(chan, "digits/ett");
- res = res ? res : ast_play_and_wait(chan, "vm-gammalt");
- res = res ? res : ast_play_and_wait(chan, "vm-message");
- } else {
- res = say_and_wait(chan, vms->oldmessages, chan->language);
- res = res ? res : ast_play_and_wait(chan, "vm-gamla");
- res = res ? res : ast_play_and_wait(chan, "vm-messages");
- }
- }
-
- return res;
-}
-
-/* NORWEGIAN syntax */
-static int vm_intro_no(struct ast_channel *chan,struct vm_state *vms)
-{
- /* Introduce messages they have */
- int res;
-
- res = ast_play_and_wait(chan, "vm-youhave");
- if (res)
- return res;
-
- if (!vms->oldmessages && !vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-no");
- res = res ? res : ast_play_and_wait(chan, "vm-messages");
- return res;
- }
-
- if (vms->newmessages) {
- if ((vms->newmessages == 1)) {
- res = ast_play_and_wait(chan, "digits/1");
- res = res ? res : ast_play_and_wait(chan, "vm-ny");
- res = res ? res : ast_play_and_wait(chan, "vm-message");
- } else {
- res = say_and_wait(chan, vms->newmessages, chan->language);
- res = res ? res : ast_play_and_wait(chan, "vm-nye");
- res = res ? res : ast_play_and_wait(chan, "vm-messages");
- }
- if (!res && vms->oldmessages)
- res = ast_play_and_wait(chan, "vm-and");
- }
- if (!res && vms->oldmessages) {
- if (vms->oldmessages == 1) {
- res = ast_play_and_wait(chan, "digits/1");
- res = res ? res : ast_play_and_wait(chan, "vm-gamel");
- res = res ? res : ast_play_and_wait(chan, "vm-message");
- } else {
- res = say_and_wait(chan, vms->oldmessages, chan->language);
- res = res ? res : ast_play_and_wait(chan, "vm-gamle");
- res = res ? res : ast_play_and_wait(chan, "vm-messages");
- }
- }
-
- return res;
-}
-
-/* GERMAN syntax */
-static int vm_intro_de(struct ast_channel *chan,struct vm_state *vms)
-{
- /* Introduce messages they have */
- int res;
- res = ast_play_and_wait(chan, "vm-youhave");
- if (!res) {
- if (vms->newmessages) {
- if ((vms->newmessages == 1))
- res = ast_play_and_wait(chan, "digits/1F");
- else
- res = say_and_wait(chan, vms->newmessages, chan->language);
- if (!res)
- res = ast_play_and_wait(chan, "vm-INBOX");
- if (vms->oldmessages && !res)
- res = ast_play_and_wait(chan, "vm-and");
- else if (!res) {
- if ((vms->newmessages == 1))
- res = ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-messages");
- }
-
- }
- if (!res && vms->oldmessages) {
- if (vms->oldmessages == 1)
- res = ast_play_and_wait(chan, "digits/1F");
- else
- res = say_and_wait(chan, vms->oldmessages, chan->language);
- if (!res)
- res = ast_play_and_wait(chan, "vm-Old");
- if (!res) {
- if (vms->oldmessages == 1)
- res = ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-messages");
- }
- }
- if (!res) {
- if (!vms->oldmessages && !vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-no");
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- }
- }
- }
- return res;
-}
-
-/* SPANISH syntax */
-static int vm_intro_es(struct ast_channel *chan,struct vm_state *vms)
-{
- /* Introduce messages they have */
- int res;
- if (!vms->oldmessages && !vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-youhaveno");
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- } else {
- res = ast_play_and_wait(chan, "vm-youhave");
- }
- if (!res) {
- if (vms->newmessages) {
- if (!res) {
- if ((vms->newmessages == 1)) {
- res = ast_play_and_wait(chan, "digits/1M");
- if (!res)
- res = ast_play_and_wait(chan, "vm-message");
- if (!res)
- res = ast_play_and_wait(chan, "vm-INBOXs");
- } else {
- res = say_and_wait(chan, vms->newmessages, chan->language);
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- if (!res)
- res = ast_play_and_wait(chan, "vm-INBOX");
- }
- }
- if (vms->oldmessages && !res)
- res = ast_play_and_wait(chan, "vm-and");
- }
- if (vms->oldmessages) {
- if (!res) {
- if (vms->oldmessages == 1) {
- res = ast_play_and_wait(chan, "digits/1M");
- if (!res)
- res = ast_play_and_wait(chan, "vm-message");
- if (!res)
- res = ast_play_and_wait(chan, "vm-Olds");
- } else {
- res = say_and_wait(chan, vms->oldmessages, chan->language);
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- if (!res)
- res = ast_play_and_wait(chan, "vm-Old");
- }
- }
- }
- }
-return res;
-}
-
-/* FRENCH syntax */
-static int vm_intro_fr(struct ast_channel *chan,struct vm_state *vms)
-{
- /* Introduce messages they have */
- int res;
- res = ast_play_and_wait(chan, "vm-youhave");
- if (!res) {
- if (vms->newmessages) {
- res = say_and_wait(chan, vms->newmessages, chan->language);
- if (!res)
- res = ast_play_and_wait(chan, "vm-INBOX");
- if (vms->oldmessages && !res)
- res = ast_play_and_wait(chan, "vm-and");
- else if (!res) {
- if ((vms->newmessages == 1))
- res = ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-messages");
- }
-
- }
- if (!res && vms->oldmessages) {
- res = say_and_wait(chan, vms->oldmessages, chan->language);
- if (!res) {
- if (vms->oldmessages == 1)
- res = ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-messages");
- }
- if (!res)
- res = ast_play_and_wait(chan, "vm-Old");
- }
- if (!res) {
- if (!vms->oldmessages && !vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-no");
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- }
- }
- }
- return res;
-}
-
-/* DUTCH syntax */
-static int vm_intro_nl(struct ast_channel *chan,struct vm_state *vms)
-{
- /* Introduce messages they have */
- int res;
- res = ast_play_and_wait(chan, "vm-youhave");
- if (!res) {
- if (vms->newmessages) {
- res = say_and_wait(chan, vms->newmessages, chan->language);
- if (!res) {
- if (vms->oldmessages == 1)
- res = ast_play_and_wait(chan, "vm-INBOXs");
- else
- res = ast_play_and_wait(chan, "vm-INBOX");
- }
- if (vms->oldmessages && !res)
- res = ast_play_and_wait(chan, "vm-and");
- else if (!res) {
- if ((vms->newmessages == 1))
- res = ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-messages");
- }
-
- }
- if (!res && vms->oldmessages) {
- res = say_and_wait(chan, vms->oldmessages, chan->language);
- if (!res) {
- if (vms->oldmessages == 1)
- res = ast_play_and_wait(chan, "vm-Olds");
- else
- res = ast_play_and_wait(chan, "vm-Old");
- }
- if (!res) {
- if (vms->oldmessages == 1)
- res = ast_play_and_wait(chan, "vm-message");
- else
- res = ast_play_and_wait(chan, "vm-messages");
- }
- }
- if (!res) {
- if (!vms->oldmessages && !vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-no");
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- }
- }
- }
- return res;
-}
-
-/* PORTUGUESE syntax */
-static int vm_intro_pt(struct ast_channel *chan,struct vm_state *vms)
-{
- /* Introduce messages they have */
- int res;
- res = ast_play_and_wait(chan, "vm-youhave");
- if (!res) {
- if (vms->newmessages) {
- res = ast_say_number(chan, vms->newmessages, AST_DIGIT_ANY, chan->language, "f");
- if (!res) {
- if ((vms->newmessages == 1)) {
- res = ast_play_and_wait(chan, "vm-message");
- if (!res)
- res = ast_play_and_wait(chan, "vm-INBOXs");
- } else {
- res = ast_play_and_wait(chan, "vm-messages");
- if (!res)
- res = ast_play_and_wait(chan, "vm-INBOX");
- }
- }
- if (vms->oldmessages && !res)
- res = ast_play_and_wait(chan, "vm-and");
- }
- if (!res && vms->oldmessages) {
- res = ast_say_number(chan, vms->oldmessages, AST_DIGIT_ANY, chan->language, "f");
- if (!res) {
- if (vms->oldmessages == 1) {
- res = ast_play_and_wait(chan, "vm-message");
- if (!res)
- res = ast_play_and_wait(chan, "vm-Olds");
- } else {
- res = ast_play_and_wait(chan, "vm-messages");
- if (!res)
- res = ast_play_and_wait(chan, "vm-Old");
- }
- }
- }
- if (!res) {
- if (!vms->oldmessages && !vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-no");
- if (!res)
- res = ast_play_and_wait(chan, "vm-messages");
- }
- }
- }
- return res;
-}
-
-
-/* CZECH syntax */
-/* in czech there must be declension of word new and message
- * czech : english : czech : english
- * --------------------------------------------------------
- * vm-youhave : you have
- * vm-novou : one new : vm-zpravu : message
- * vm-nove : 2-4 new : vm-zpravy : messages
- * vm-novych : 5-infinite new : vm-zprav : messages
- * vm-starou : one old
- * vm-stare : 2-4 old
- * vm-starych : 5-infinite old
- * jednu : one - falling 4.
- * vm-no : no ( no messages )
- */
-
-static int vm_intro_cz(struct ast_channel *chan,struct vm_state *vms)
-{
- int res;
- res = ast_play_and_wait(chan, "vm-youhave");
- if (!res) {
- if (vms->newmessages) {
- if (vms->newmessages == 1) {
- res = ast_play_and_wait(chan, "digits/jednu");
- } else {
- res = say_and_wait(chan, vms->newmessages, chan->language);
- }
- if (!res) {
- if ((vms->newmessages == 1))
- res = ast_play_and_wait(chan, "vm-novou");
- if ((vms->newmessages) > 1 && (vms->newmessages < 5))
- res = ast_play_and_wait(chan, "vm-nove");
- if (vms->newmessages > 4)
- res = ast_play_and_wait(chan, "vm-novych");
- }
- if (vms->oldmessages && !res)
- res = ast_play_and_wait(chan, "vm-and");
- else if (!res) {
- if ((vms->newmessages == 1))
- res = ast_play_and_wait(chan, "vm-zpravu");
- if ((vms->newmessages) > 1 && (vms->newmessages < 5))
- res = ast_play_and_wait(chan, "vm-zpravy");
- if (vms->newmessages > 4)
- res = ast_play_and_wait(chan, "vm-zprav");
- }
- }
- if (!res && vms->oldmessages) {
- res = say_and_wait(chan, vms->oldmessages, chan->language);
- if (!res) {
- if ((vms->oldmessages == 1))
- res = ast_play_and_wait(chan, "vm-starou");
- if ((vms->oldmessages) > 1 && (vms->oldmessages < 5))
- res = ast_play_and_wait(chan, "vm-stare");
- if (vms->oldmessages > 4)
- res = ast_play_and_wait(chan, "vm-starych");
- }
- if (!res) {
- if ((vms->oldmessages == 1))
- res = ast_play_and_wait(chan, "vm-zpravu");
- if ((vms->oldmessages) > 1 && (vms->oldmessages < 5))
- res = ast_play_and_wait(chan, "vm-zpravy");
- if (vms->oldmessages > 4)
- res = ast_play_and_wait(chan, "vm-zprav");
- }
- }
- if (!res) {
- if (!vms->oldmessages && !vms->newmessages) {
- res = ast_play_and_wait(chan, "vm-no");
- if (!res)
- res = ast_play_and_wait(chan, "vm-zpravy");
- }
- }
- }
- return res;
-}
-
-static int vm_intro(struct ast_channel *chan,struct vm_state *vms)
-{
- /* Play voicemail intro - syntax is different for different languages */
- if (!strcasecmp(chan->language, "de")) { /* GERMAN syntax */
- return vm_intro_de(chan, vms);
- } else if (!strcasecmp(chan->language, "es")) { /* SPANISH syntax */
- return vm_intro_es(chan, vms);
- } else if (!strcasecmp(chan->language, "it")) { /* ITALIAN syntax */
- return vm_intro_it(chan, vms);
- } else if (!strcasecmp(chan->language, "fr")) { /* FRENCH syntax */
- return vm_intro_fr(chan, vms);
- } else if (!strcasecmp(chan->language, "nl")) { /* DUTCH syntax */
- return vm_intro_nl(chan, vms);
- } else if (!strcasecmp(chan->language, "pt")) { /* PORTUGUESE syntax */
- return vm_intro_pt(chan, vms);
- } else if (!strcasecmp(chan->language, "cz")) { /* CZECH syntax */
- return vm_intro_cz(chan, vms);
- } else if (!strcasecmp(chan->language, "gr")) { /* GREEK syntax */
- return vm_intro_gr(chan, vms);
- } else if (!strcasecmp(chan->language, "se")) { /* SWEDISH syntax */
- return vm_intro_se(chan, vms);
- } else if (!strcasecmp(chan->language, "no")) { /* NORWEGIAN syntax */
- return vm_intro_no(chan, vms);
- } else { /* Default to ENGLISH */
- return vm_intro_en(chan, vms);
- }
-}
-
-static int vm_instructions(struct ast_channel *chan, struct vm_state *vms, int skipadvanced)
-{
- int res = 0;
- /* Play instructions and wait for new command */
- while (!res) {
- if (vms->starting) {
- if (vms->lastmsg > -1) {
- res = ast_play_and_wait(chan, "vm-onefor");
- if (!res)
- res = vm_play_folder_name(chan, vms->vmbox);
- }
- if (!res)
- res = ast_play_and_wait(chan, "vm-opts");
- } else {
- if (vms->curmsg)
- res = ast_play_and_wait(chan, "vm-prev");
- if (!res && !skipadvanced)
- res = ast_play_and_wait(chan, "vm-advopts");
- if (!res)
- res = ast_play_and_wait(chan, "vm-repeat");
- if (!res && (vms->curmsg != vms->lastmsg))
- res = ast_play_and_wait(chan, "vm-next");
- if (!res) {
- if (!vms->deleted[vms->curmsg])
- res = ast_play_and_wait(chan, "vm-delete");
- else
- res = ast_play_and_wait(chan, "vm-undelete");
- if (!res)
- res = ast_play_and_wait(chan, "vm-toforward");
- if (!res)
- res = ast_play_and_wait(chan, "vm-savemessage");
- }
- }
- if (!res)
- res = ast_play_and_wait(chan, "vm-helpexit");
- if (!res)
- res = ast_waitfordigit(chan, 6000);
- if (!res) {
- vms->repeats++;
- if (vms->repeats > 2) {
- res = 't';
- }
- }
- }
- return res;
-}
-
-static int vm_newuser(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, char *fmtc, signed char record_gain)
-{
- int cmd = 0;
- int duration = 0;
- int tries = 0;
- char newpassword[80] = "";
- char newpassword2[80] = "";
- char prefile[256]="";
- unsigned char buf[256];
- int bytes=0;
-
- if (adsi_available(chan)) {
- bytes += adsi_logo(buf + bytes);
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "New User Setup", "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_CENT, 0, "Not Done", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_voice_mode(buf + bytes, 0);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
- }
-
- /* First, have the user change their password
- so they won't get here again */
- for (;;) {
- newpassword[1] = '\0';
- newpassword[0] = cmd = ast_play_and_wait(chan,"vm-newpassword");
- if (cmd == '#')
- newpassword[0] = '\0';
- if (cmd < 0 || cmd == 't' || cmd == '#')
- return cmd;
- cmd = ast_readstring(chan,newpassword + strlen(newpassword),sizeof(newpassword)-1,2000,10000,"#");
- if (cmd < 0 || cmd == 't' || cmd == '#')
- return cmd;
- newpassword2[1] = '\0';
- newpassword2[0] = cmd = ast_play_and_wait(chan,"vm-reenterpassword");
- if (cmd == '#')
- newpassword2[0] = '\0';
- if (cmd < 0 || cmd == 't' || cmd == '#')
- return cmd;
- cmd = ast_readstring(chan,newpassword2 + strlen(newpassword2),sizeof(newpassword2)-1,2000,10000,"#");
- if (cmd < 0 || cmd == 't' || cmd == '#')
- return cmd;
- if (!strcmp(newpassword, newpassword2))
- break;
- ast_log(LOG_NOTICE,"Password mismatch for user %s (%s != %s)\n", vms->username, newpassword, newpassword2);
- cmd = ast_play_and_wait(chan, "vm-mismatch");
- if (++tries == 3)
- return -1;
- }
- if (ast_strlen_zero(ext_pass_cmd))
- vm_change_password(vmu,newpassword);
- else
- vm_change_password_shell(vmu,newpassword);
-
- cmd = ast_play_and_wait(chan,"vm-passchanged");
-
- /* If forcename is set, have the user record their name */
- if (ast_test_flag(vmu, VM_FORCENAME)) {
- snprintf(prefile,sizeof(prefile), "%s%s/%s/greet", VM_SPOOL_DIR, vmu->context, vms->username);
- cmd = play_record_review(chan,"vm-rec-name",prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
- if (cmd < 0 || cmd == 't' || cmd == '#')
- return cmd;
- }
-
- /* If forcegreetings is set, have the user record their greetings */
- if (ast_test_flag(vmu, VM_FORCEGREET)) {
- snprintf(prefile,sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, vms->username);
- cmd = play_record_review(chan,"vm-rec-unv",prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
- if (cmd < 0 || cmd == 't' || cmd == '#')
- return cmd;
- snprintf(prefile,sizeof(prefile), "%s%s/%s/busy", VM_SPOOL_DIR, vmu->context, vms->username);
- cmd = play_record_review(chan,"vm-rec-busy",prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
- if (cmd < 0 || cmd == 't' || cmd == '#')
- return cmd;
- }
-
- return cmd;
-}
-
-static int vm_options(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, char *fmtc, signed char record_gain)
-{
- int cmd = 0;
- int retries = 0;
- int duration = 0;
- char newpassword[80] = "";
- char newpassword2[80] = "";
- char prefile[256]="";
- unsigned char buf[256];
- int bytes=0;
-
- if (adsi_available(chan))
- {
- bytes += adsi_logo(buf + bytes);
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "Options Menu", "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_CENT, 0, "Not Done", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_voice_mode(buf + bytes, 0);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
- }
- while ((cmd >= 0) && (cmd != 't')) {
- if (cmd)
- retries = 0;
- switch (cmd) {
- case '1':
- snprintf(prefile,sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, vms->username);
- cmd = play_record_review(chan,"vm-rec-unv",prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
- break;
- case '2':
- snprintf(prefile,sizeof(prefile), "%s%s/%s/busy", VM_SPOOL_DIR, vmu->context, vms->username);
- cmd = play_record_review(chan,"vm-rec-busy",prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
- break;
- case '3':
- snprintf(prefile,sizeof(prefile), "%s%s/%s/greet", VM_SPOOL_DIR, vmu->context, vms->username);
- cmd = play_record_review(chan,"vm-rec-name",prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
- break;
- case '4':
- cmd = vm_tempgreeting(chan, vmu, vms, fmtc, record_gain);
- break;
- case '5':
- if (vmu->password[0] == '-') {
- cmd = ast_play_and_wait(chan, "vm-no");
- break;
- }
- newpassword[1] = '\0';
- newpassword[0] = cmd = ast_play_and_wait(chan,"vm-newpassword");
- if (cmd == '#')
- newpassword[0] = '\0';
- else {
- if (cmd < 0)
- break;
- if ((cmd = ast_readstring(chan,newpassword + strlen(newpassword),sizeof(newpassword)-1,2000,10000,"#")) < 0) {
- break;
- }
- }
- newpassword2[1] = '\0';
- newpassword2[0] = cmd = ast_play_and_wait(chan,"vm-reenterpassword");
- if (cmd == '#')
- newpassword2[0] = '\0';
- else {
- if (cmd < 0)
- break;
-
- if ((cmd = ast_readstring(chan,newpassword2 + strlen(newpassword2),sizeof(newpassword2)-1,2000,10000,"#"))) {
- break;
- }
- }
- if (strcmp(newpassword, newpassword2)) {
- ast_log(LOG_NOTICE,"Password mismatch for user %s (%s != %s)\n", vms->username, newpassword, newpassword2);
- cmd = ast_play_and_wait(chan, "vm-mismatch");
- break;
- }
- if (ast_strlen_zero(ext_pass_cmd))
- vm_change_password(vmu,newpassword);
- else
- vm_change_password_shell(vmu,newpassword);
- ast_log(LOG_DEBUG,"User %s set password to %s of length %d\n",vms->username,newpassword,(int)strlen(newpassword));
- cmd = ast_play_and_wait(chan,"vm-passchanged");
- break;
- case '*':
- cmd = 't';
- break;
- default:
- cmd = ast_play_and_wait(chan,"vm-options");
- if (!cmd)
- cmd = ast_waitfordigit(chan,6000);
- if (!cmd)
- retries++;
- if (retries > 3)
- cmd = 't';
- }
- }
- if (cmd == 't')
- cmd = 0;
- return cmd;
-}
-
-static int vm_tempgreeting(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, char *fmtc, signed char record_gain)
-{
- int cmd = 0;
- int retries = 0;
- int duration = 0;
- char prefile[256]="";
- unsigned char buf[256];
- int bytes=0;
-
- if (adsi_available(chan))
- {
- bytes += adsi_logo(buf + bytes);
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "Temp Greeting Menu", "");
- bytes += adsi_display(buf + bytes, ADSI_COMM_PAGE, 4, ADSI_JUST_CENT, 0, "Not Done", "");
- bytes += adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- bytes += adsi_voice_mode(buf + bytes, 0);
- adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
- }
- snprintf(prefile,sizeof(prefile), "%s%s/%s/temp", VM_SPOOL_DIR, vmu->context, vms->username);
- while((cmd >= 0) && (cmd != 't')) {
- if (cmd)
- retries = 0;
- RETRIEVE(prefile, -1);
- if (ast_fileexists(prefile, NULL, NULL) > 0) {
- switch (cmd) {
- case '1':
- cmd = play_record_review(chan,"vm-rec-temp",prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
- break;
- case '2':
- DELETE(prefile, -1, prefile);
- ast_play_and_wait(chan,"vm-tempremoved");
- cmd = 't';
- break;
- case '*':
- cmd = 't';
- break;
- default:
- if (ast_fileexists(prefile, NULL, NULL) > 0) {
- cmd = ast_play_and_wait(chan,"vm-tempgreeting2");
- } else {
- cmd = ast_play_and_wait(chan,"vm-tempgreeting");
- } if (!cmd) {
- cmd = ast_waitfordigit(chan,6000);
- } if (!cmd) {
- retries++;
- } if (retries > 3) {
- cmd = 't';
- }
- }
- } else {
- play_record_review(chan,"vm-rec-temp",prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
- cmd = 't';
- }
- DISPOSE(prefile, -1);
- }
- if (cmd == 't')
- cmd = 0;
- return cmd;
-}
-
-/* GREEK SYNTAX */
-
-static int vm_browse_messages_gr(struct ast_channel *chan, struct vm_state *vms, struct ast_vm_user *vmu)
-{
- int cmd=0;
-
- if (vms->lastmsg > -1) {
- cmd = play_message(chan, vmu, vms);
- } else {
- cmd = ast_play_and_wait(chan, "vm-youhaveno");
- if (!strcasecmp(vms->vmbox, "vm-INBOX") ||!strcasecmp(vms->vmbox, "vm-Old")){
- if (!cmd) {
- snprintf(vms->fn, sizeof(vms->fn), "vm-%ss", vms->curbox);
- cmd = ast_play_and_wait(chan, vms->fn);
- }
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-messages");
- } else {
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-messages");
- if (!cmd) {
- snprintf(vms->fn, sizeof(vms->fn), "vm-%s", vms->curbox);
- cmd = ast_play_and_wait(chan, vms->fn);
- }
- }
- }
- return cmd;
-}
-
-/* Default English syntax */
-static int vm_browse_messages_en(struct ast_channel *chan, struct vm_state *vms, struct ast_vm_user *vmu)
-{
- int cmd=0;
-
- if (vms->lastmsg > -1) {
- cmd = play_message(chan, vmu, vms);
- } else {
- cmd = ast_play_and_wait(chan, "vm-youhave");
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-no");
- if (!cmd) {
- snprintf(vms->fn, sizeof(vms->fn), "vm-%s", vms->curbox);
- cmd = ast_play_and_wait(chan, vms->fn);
- }
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-messages");
- }
- return cmd;
-}
-
-/* ITALIAN syntax */
-static int vm_browse_messages_it(struct ast_channel *chan, struct vm_state *vms, struct ast_vm_user *vmu)
-{
- int cmd=0;
-
- if (vms->lastmsg > -1) {
- cmd = play_message(chan, vmu, vms);
- } else {
- cmd = ast_play_and_wait(chan, "vm-no");
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-message");
- if (!cmd) {
- snprintf(vms->fn, sizeof(vms->fn), "vm-%s", vms->curbox);
- cmd = ast_play_and_wait(chan, vms->fn);
- }
- }
- return cmd;
-}
-
-/* SPANISH syntax */
-static int vm_browse_messages_es(struct ast_channel *chan, struct vm_state *vms, struct ast_vm_user *vmu)
-{
- int cmd=0;
-
- if (vms->lastmsg > -1) {
- cmd = play_message(chan, vmu, vms);
- } else {
- cmd = ast_play_and_wait(chan, "vm-youhaveno");
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-messages");
- if (!cmd) {
- snprintf(vms->fn, sizeof(vms->fn), "vm-%s", vms->curbox);
- cmd = ast_play_and_wait(chan, vms->fn);
- }
- }
- return cmd;
-}
-
-/* PORTUGUESE syntax */
-static int vm_browse_messages_pt(struct ast_channel *chan, struct vm_state *vms, struct ast_vm_user *vmu)
-{
- int cmd=0;
-
- if (vms->lastmsg > -1) {
- cmd = play_message(chan, vmu, vms);
- } else {
- cmd = ast_play_and_wait(chan, "vm-no");
- if (!cmd) {
- snprintf(vms->fn, sizeof(vms->fn), "vm-%s", vms->curbox);
- cmd = ast_play_and_wait(chan, vms->fn);
- }
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-messages");
- }
- return cmd;
-}
-
-static int vm_browse_messages(struct ast_channel *chan, struct vm_state *vms, struct ast_vm_user *vmu)
-{
- if (!strcasecmp(chan->language, "es")) { /* SPANISH */
- return vm_browse_messages_es(chan, vms, vmu);
- } else if (!strcasecmp(chan->language, "it")) { /* ITALIAN */
- return vm_browse_messages_it(chan, vms, vmu);
- } else if (!strcasecmp(chan->language, "pt")) { /* PORTUGUESE */
- return vm_browse_messages_pt(chan, vms, vmu);
- } else if (!strcasecmp(chan->language, "gr")){
- return vm_browse_messages_gr(chan, vms, vmu); /* GREEK */
- } else { /* Default to English syntax */
- return vm_browse_messages_en(chan, vms, vmu);
- }
-}
-
-static int vm_authenticate(struct ast_channel *chan, char *mailbox, int mailbox_size,
- struct ast_vm_user *res_vmu, const char *context, const char *prefix,
- int skipuser, int maxlogins, int silent)
-{
- int useadsi=0, valid=0, logretries=0;
- char password[AST_MAX_EXTENSION]="", *passptr;
- struct ast_vm_user vmus, *vmu = NULL;
-
- /* If ADSI is supported, setup login screen */
- adsi_begin(chan, &useadsi);
- if (!skipuser && useadsi)
- adsi_login(chan);
- if (!silent && !skipuser && ast_streamfile(chan, "vm-login", chan->language)) {
- ast_log(LOG_WARNING, "Couldn't stream login file\n");
- return -1;
- }
-
- /* Authenticate them and get their mailbox/password */
-
- while (!valid && (logretries < maxlogins)) {
- /* Prompt for, and read in the username */
- if (!skipuser && ast_readstring(chan, mailbox, mailbox_size - 1, 2000, 10000, "#") < 0) {
- ast_log(LOG_WARNING, "Couldn't read username\n");
- return -1;
- }
- if (ast_strlen_zero(mailbox)) {
- if (chan->cid.cid_num) {
- ast_copy_string(mailbox, chan->cid.cid_num, mailbox_size);
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Username not entered\n");
- return -1;
- }
- }
- if (useadsi)
- adsi_password(chan);
-
- if (!ast_strlen_zero(prefix)) {
- char fullusername[80] = "";
- ast_copy_string(fullusername, prefix, sizeof(fullusername));
- strncat(fullusername, mailbox, sizeof(fullusername) - 1 - strlen(fullusername));
- ast_copy_string(mailbox, fullusername, mailbox_size);
- }
-
- vmu = find_user(&vmus, context, mailbox);
- if (vmu && (vmu->password[0] == '\0' || (vmu->password[0] == '-' && vmu->password[1] == '\0'))) {
- /* saved password is blank, so don't bother asking */
- password[0] = '\0';
- } else {
- if (ast_streamfile(chan, "vm-password", chan->language)) {
- ast_log(LOG_WARNING, "Unable to stream password file\n");
- return -1;
- }
- if (ast_readstring(chan, password, sizeof(password) - 1, 2000, 10000, "#") < 0) {
- ast_log(LOG_WARNING, "Unable to read password\n");
- return -1;
- }
- }
-
- if (vmu) {
- passptr = vmu->password;
- if (passptr[0] == '-') passptr++;
- }
- if (vmu && !strcmp(passptr, password))
- valid++;
- else {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Incorrect password '%s' for user '%s' (context = %s)\n", password, mailbox, context ? context : "default");
- if (!ast_strlen_zero(prefix))
- mailbox[0] = '\0';
- }
- logretries++;
- if (!valid) {
- if (skipuser || logretries >= maxlogins) {
- if (ast_streamfile(chan, "vm-incorrect", chan->language)) {
- ast_log(LOG_WARNING, "Unable to stream incorrect message\n");
- return -1;
- }
- } else {
- if (useadsi)
- adsi_login(chan);
- if (ast_streamfile(chan, "vm-incorrect-mailbox", chan->language)) {
- ast_log(LOG_WARNING, "Unable to stream incorrect mailbox message\n");
- return -1;
- }
- }
- if (ast_waitstream(chan, "")) /* Channel is hung up */
- return -1;
- }
- }
- if (!valid && (logretries >= maxlogins)) {
- ast_stopstream(chan);
- ast_play_and_wait(chan, "vm-goodbye");
- return -1;
- }
- if (vmu && !skipuser) {
- memcpy(res_vmu, vmu, sizeof(struct ast_vm_user));
- }
- return 0;
-}
-
-static int vm_execmain(struct ast_channel *chan, void *data)
-{
- /* XXX This is, admittedly, some pretty horrendus code. For some
- reason it just seemed a lot easier to do with GOTO's. I feel
- like I'm back in my GWBASIC days. XXX */
- int res=-1;
- int cmd=0;
- int valid = 0;
- struct localuser *u;
- char prefixstr[80] ="";
- char ext_context[256]="";
- int box;
- int useadsi = 0;
- int skipuser = 0;
- struct vm_state vms;
- struct ast_vm_user *vmu = NULL, vmus;
- char *context=NULL;
- int silentexit = 0;
- struct ast_flags flags = { 0 };
- signed char record_gain = 0;
-
- LOCAL_USER_ADD(u);
-
- memset(&vms, 0, sizeof(vms));
- vms.lastmsg = -1;
-
- memset(&vmus, 0, sizeof(vmus));
-
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
-
- if (!ast_strlen_zero(data)) {
- char *tmp;
- int argc;
- char *argv[2];
- char *opts[OPT_ARG_ARRAY_SIZE];
-
- tmp = ast_strdupa(data);
- argc = ast_app_separate_args(tmp, '|', argv, sizeof(argv) / sizeof(argv[0]));
- if (argc == 2) {
- if (ast_app_parse_options(vm_app_options, &flags, opts, argv[1])) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- if (ast_test_flag(&flags, OPT_RECORDGAIN)) {
- int gain;
-
- if (sscanf(opts[OPT_ARG_RECORDGAIN], "%d", &gain) != 1) {
- ast_log(LOG_WARNING, "Invalid value '%s' provided for record gain option\n", opts[OPT_ARG_RECORDGAIN]);
- LOCAL_USER_REMOVE(u);
- return -1;
- } else {
- record_gain = (signed char) gain;
- }
- }
- } else {
- /* old style options parsing */
- while (*argv[0]) {
- if (*argv[0] == 's') {
- ast_set_flag(&flags, OPT_SILENT);
- argv[0]++;
- } else if (*argv[0] == 'p') {
- ast_set_flag(&flags, OPT_PREPEND_MAILBOX);
- argv[0]++;
- } else
- break;
- }
-
- }
-
- valid = ast_test_flag(&flags, OPT_SILENT);
-
- if ((context = strchr(argv[0], '@')))
- *context++ = '\0';
-
- if (ast_test_flag(&flags, OPT_PREPEND_MAILBOX))
- ast_copy_string(prefixstr, argv[0], sizeof(prefixstr));
- else
- ast_copy_string(vms.username, argv[0], sizeof(vms.username));
-
- if (!ast_strlen_zero(vms.username) && (vmu = find_user(&vmus, context ,vms.username)))
- skipuser++;
- else
- valid = 0;
- }
-
- if (!valid)
- res = vm_authenticate(chan, vms.username, sizeof(vms.username), &vmus, context, prefixstr, skipuser, maxlogins, 0);
-
- if (!res) {
- valid = 1;
- if (!skipuser)
- vmu = &vmus;
- } else {
- res = 0;
- }
-
- /* If ADSI is supported, setup login screen */
- adsi_begin(chan, &useadsi);
-
- if (!valid)
- goto out;
-
- vms.deleted = calloc(vmu->maxmsg, sizeof(int));
- vms.heard = calloc(vmu->maxmsg, sizeof(int));
-
- /* Set language from config to override channel language */
- if (!ast_strlen_zero(vmu->language))
- ast_copy_string(chan->language, vmu->language, sizeof(chan->language));
- create_dirpath(vms.curdir, sizeof(vms.curdir), vmu->context, vms.username, "");
- /* Retrieve old and new message counts */
- res = open_mailbox(&vms, vmu, 1);
- if (res == ERROR_LOCK_PATH)
- goto out;
- vms.oldmessages = vms.lastmsg + 1;
- /* Start in INBOX */
- res = open_mailbox(&vms, vmu, 0);
- if (res == ERROR_LOCK_PATH)
- goto out;
- vms.newmessages = vms.lastmsg + 1;
-
- /* Select proper mailbox FIRST!! */
- if (!vms.newmessages && vms.oldmessages) {
- /* If we only have old messages start here */
- res = open_mailbox(&vms, vmu, 1);
- if (res == ERROR_LOCK_PATH)
- goto out;
- }
-
- if (useadsi)
- adsi_status(chan, &vms);
- res = 0;
-
- /* Check to see if this is a new user */
- if (!strcasecmp(vmu->mailbox, vmu->password) &&
- (ast_test_flag(vmu, VM_FORCENAME | VM_FORCEGREET))) {
- if (ast_play_and_wait(chan, "vm-newuser") == -1)
- ast_log(LOG_WARNING, "Couldn't stream new user file\n");
- cmd = vm_newuser(chan, vmu, &vms, vmfmts, record_gain);
- if ((cmd == 't') || (cmd == '#')) {
- /* Timeout */
- res = 0;
- goto out;
- } else if (cmd < 0) {
- /* Hangup */
- res = -1;
- goto out;
- }
- }
-
- cmd = vm_intro(chan, &vms);
-
- vms.repeats = 0;
- vms.starting = 1;
- while ((cmd > -1) && (cmd != 't') && (cmd != '#')) {
- /* Run main menu */
- switch(cmd) {
- case '1':
- vms.curmsg = 0;
- /* Fall through */
- case '5':
- cmd = vm_browse_messages(chan, &vms, vmu);
- break;
- case '2': /* Change folders */
- if (useadsi)
- adsi_folders(chan, 0, "Change to folder...");
- cmd = get_folder2(chan, "vm-changeto", 0);
- if (cmd == '#') {
- cmd = 0;
- } else if (cmd > 0) {
- cmd = cmd - '0';
- res = close_mailbox(&vms, vmu);
- if (res == ERROR_LOCK_PATH)
- goto out;
- res = open_mailbox(&vms, vmu, cmd);
- if (res == ERROR_LOCK_PATH)
- goto out;
- cmd = 0;
- }
- if (useadsi)
- adsi_status2(chan, &vms);
-
- if (!cmd)
- cmd = vm_play_folder_name(chan, vms.vmbox);
-
- vms.starting = 1;
- break;
- case '3': /* Advanced options */
- cmd = 0;
- vms.repeats = 0;
- while ((cmd > -1) && (cmd != 't') && (cmd != '#')) {
- switch(cmd) {
- case '1': /* Reply */
- if (vms.lastmsg > -1) {
- cmd = advanced_options(chan, vmu, &vms, vms.curmsg, 1, record_gain);
- if (cmd == ERROR_LOCK_PATH) {
- res = cmd;
- goto out;
- }
- } else
- cmd = ast_play_and_wait(chan, "vm-sorry");
- cmd = 't';
- break;
- case '2': /* Callback */
- ast_verbose( VERBOSE_PREFIX_3 "Callback Requested\n");
- if (!ast_strlen_zero(vmu->callback) && vms.lastmsg > -1) {
- cmd = advanced_options(chan, vmu, &vms, vms.curmsg, 2, record_gain);
- if (cmd == 9) {
- silentexit = 1;
- goto out;
- } else if (cmd == ERROR_LOCK_PATH) {
- res = cmd;
- goto out;
- }
- }
- else
- cmd = ast_play_and_wait(chan, "vm-sorry");
- cmd = 't';
- break;
- case '3': /* Envelope */
- if (vms.lastmsg > -1) {
- cmd = advanced_options(chan, vmu, &vms, vms.curmsg, 3, record_gain);
- if (cmd == ERROR_LOCK_PATH) {
- res = cmd;
- goto out;
- }
- } else
- cmd = ast_play_and_wait(chan, "vm-sorry");
- cmd = 't';
- break;
- case '4': /* Dialout */
- if (!ast_strlen_zero(vmu->dialout)) {
- cmd = dialout(chan, vmu, NULL, vmu->dialout);
- if (cmd == 9) {
- silentexit = 1;
- goto out;
- }
- }
- else
- cmd = ast_play_and_wait(chan, "vm-sorry");
- cmd = 't';
- break;
-
- case '5': /* Leave VoiceMail */
- if (ast_test_flag(vmu, VM_SVMAIL)) {
- cmd = forward_message(chan, context, vms.curdir, vms.curmsg, vmu, vmfmts, 1, record_gain);
- if (cmd == ERROR_LOCK_PATH) {
- res = cmd;
- goto out;
- }
- } else
- cmd = ast_play_and_wait(chan,"vm-sorry");
- cmd='t';
- break;
-
- case '*': /* Return to main menu */
- cmd = 't';
- break;
-
- default:
- cmd = 0;
- if (!vms.starting) {
- cmd = ast_play_and_wait(chan, "vm-toreply");
- }
- if (!ast_strlen_zero(vmu->callback) && !vms.starting && !cmd) {
- cmd = ast_play_and_wait(chan, "vm-tocallback");
- }
- if (!cmd && !vms.starting) {
- cmd = ast_play_and_wait(chan, "vm-tohearenv");
- }
- if (!ast_strlen_zero(vmu->dialout) && !cmd) {
- cmd = ast_play_and_wait(chan, "vm-tomakecall");
- }
- if (ast_test_flag(vmu, VM_SVMAIL) && !cmd)
- cmd=ast_play_and_wait(chan, "vm-leavemsg");
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-starmain");
- if (!cmd)
- cmd = ast_waitfordigit(chan,6000);
- if (!cmd)
- vms.repeats++;
- if (vms.repeats > 3)
- cmd = 't';
- }
- }
- if (cmd == 't') {
- cmd = 0;
- vms.repeats = 0;
- }
- break;
- case '4':
- if (vms.curmsg) {
- vms.curmsg--;
- cmd = play_message(chan, vmu, &vms);
- } else {
- cmd = ast_play_and_wait(chan, "vm-nomore");
- }
- break;
- case '6':
- if (vms.curmsg < vms.lastmsg) {
- vms.curmsg++;
- cmd = play_message(chan, vmu, &vms);
- } else {
- cmd = ast_play_and_wait(chan, "vm-nomore");
- }
- break;
- case '7':
- vms.deleted[vms.curmsg] = !vms.deleted[vms.curmsg];
- if (useadsi)
- adsi_delete(chan, &vms);
- if (vms.deleted[vms.curmsg])
- cmd = ast_play_and_wait(chan, "vm-deleted");
- else
- cmd = ast_play_and_wait(chan, "vm-undeleted");
- if (ast_test_flag((&globalflags), VM_SKIPAFTERCMD)) {
- if (vms.curmsg < vms.lastmsg) {
- vms.curmsg++;
- cmd = play_message(chan, vmu, &vms);
- } else {
- cmd = ast_play_and_wait(chan, "vm-nomore");
- }
- }
- break;
-
- case '8':
- if (vms.lastmsg > -1) {
- cmd = forward_message(chan, context, vms.curdir, vms.curmsg, vmu, vmfmts, 0, record_gain);
- if (cmd == ERROR_LOCK_PATH) {
- res = cmd;
- goto out;
- }
- } else
- cmd = ast_play_and_wait(chan, "vm-nomore");
- break;
- case '9':
- if (useadsi)
- adsi_folders(chan, 1, "Save to folder...");
- cmd = get_folder2(chan, "vm-savefolder", 1);
- box = 0; /* Shut up compiler */
- if (cmd == '#') {
- cmd = 0;
- break;
- } else if (cmd > 0) {
- box = cmd = cmd - '0';
- cmd = save_to_folder(vmu, vms.curdir, vms.curmsg, vmu->context, vms.username, cmd);
- if (cmd == ERROR_LOCK_PATH) {
- res = cmd;
- goto out;
- } else if (!cmd) {
- vms.deleted[vms.curmsg] = 1;
- } else {
- vms.deleted[vms.curmsg] = 0;
- vms.heard[vms.curmsg] = 0;
- }
- }
- make_file(vms.fn, sizeof(vms.fn), vms.curdir, vms.curmsg);
- if (useadsi)
- adsi_message(chan, &vms);
- snprintf(vms.fn, sizeof(vms.fn), "vm-%s", mbox(box));
- if (!cmd) {
- cmd = ast_play_and_wait(chan, "vm-message");
- if (!cmd)
- cmd = say_and_wait(chan, vms.curmsg + 1, chan->language);
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-savedto");
- if (!cmd)
- cmd = vm_play_folder_name(chan, vms.fn);
- } else {
- cmd = ast_play_and_wait(chan, "vm-mailboxfull");
- }
- if (ast_test_flag((&globalflags), VM_SKIPAFTERCMD)) {
- if (vms.curmsg < vms.lastmsg) {
- vms.curmsg++;
- cmd = play_message(chan, vmu, &vms);
- } else {
- cmd = ast_play_and_wait(chan, "vm-nomore");
- }
- }
- break;
- case '*':
- if (!vms.starting) {
- cmd = ast_play_and_wait(chan, "vm-onefor");
- if (!cmd)
- cmd = vm_play_folder_name(chan, vms.vmbox);
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-opts");
- if (!cmd)
- cmd = vm_instructions(chan, &vms, 1);
- } else
- cmd = 0;
- break;
- case '0':
- cmd = vm_options(chan, vmu, &vms, vmfmts, record_gain);
- if (useadsi)
- adsi_status(chan, &vms);
- break;
- default: /* Nothing */
- cmd = vm_instructions(chan, &vms, 0);
- break;
- }
- }
- if ((cmd == 't') || (cmd == '#')) {
- /* Timeout */
- res = 0;
- } else {
- /* Hangup */
- res = -1;
- }
-
-out:
- if (res > -1) {
- ast_stopstream(chan);
- adsi_goodbye(chan);
- if (valid) {
- if (silentexit)
- res = ast_play_and_wait(chan, "vm-dialout");
- else
- res = ast_play_and_wait(chan, "vm-goodbye");
- if (res > 0)
- res = 0;
- }
- if (useadsi)
- adsi_unload_session(chan);
- }
- if (vmu)
- close_mailbox(&vms, vmu);
- if (valid) {
- snprintf(ext_context, sizeof(ext_context), "%s@%s", vms.username, vmu->context);
- manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, has_voicemail(ext_context, NULL));
- run_externnotify(vmu->context, vmu->mailbox);
- }
- if (vmu)
- free_user(vmu);
- if (vms.deleted)
- free(vms.deleted);
- if (vms.heard)
- free(vms.heard);
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-static int vm_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- char tmp[256];
- struct leave_vm_options leave_options;
- int argc;
- char *argv[2];
- struct ast_flags flags = { 0 };
- char *opts[OPT_ARG_ARRAY_SIZE];
-
- LOCAL_USER_ADD(u);
-
- memset(&leave_options, 0, sizeof(leave_options));
-
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
-
- if (!ast_strlen_zero(data)) {
- ast_copy_string(tmp, data, sizeof(tmp));
- argc = ast_app_separate_args(tmp, '|', argv, sizeof(argv) / sizeof(argv[0]));
- if (argc == 2) {
- if (ast_app_parse_options(vm_app_options, &flags, opts, argv[1])) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- ast_copy_flags(&leave_options, &flags, OPT_SILENT | OPT_BUSY_GREETING | OPT_UNAVAIL_GREETING);
- if (ast_test_flag(&flags, OPT_RECORDGAIN)) {
- int gain;
-
- if (sscanf(opts[OPT_ARG_RECORDGAIN], "%d", &gain) != 1) {
- ast_log(LOG_WARNING, "Invalid value '%s' provided for record gain option\n", opts[OPT_ARG_RECORDGAIN]);
- LOCAL_USER_REMOVE(u);
- return -1;
- } else {
- leave_options.record_gain = (signed char) gain;
- }
- }
- } else {
- /* old style options parsing */
- while (*argv[0]) {
- if (*argv[0] == 's') {
- ast_set_flag(&leave_options, OPT_SILENT);
- argv[0]++;
- } else if (*argv[0] == 'b') {
- ast_set_flag(&leave_options, OPT_BUSY_GREETING);
- argv[0]++;
- } else if (*argv[0] == 'u') {
- ast_set_flag(&leave_options, OPT_UNAVAIL_GREETING);
- argv[0]++;
- } else if (*argv[0] == 'j') {
- ast_set_flag(&leave_options, OPT_PRIORITY_JUMP);
- argv[0]++;
- } else
- break;
- }
- }
- } else {
- res = ast_app_getdata(chan, "vm-whichbox", tmp, sizeof(tmp) - 1, 0);
- if (res < 0) {
- LOCAL_USER_REMOVE(u);
- return res;
- }
- if (ast_strlen_zero(tmp)) {
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- argv[0] = ast_strdupa(tmp);
- }
-
- res = leave_voicemail(chan, argv[0], &leave_options);
-
- if (res == ERROR_LOCK_PATH) {
- ast_log(LOG_ERROR, "Could not leave voicemail. The path is already locked.\n");
- /*Send the call to n+101 priority, where n is the current priority*/
- if (ast_test_flag(&leave_options, OPT_PRIORITY_JUMP) || option_priority_jumping)
- if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
- ast_log(LOG_WARNING, "Extension %s, priority %d doesn't exist.\n", chan->exten, chan->priority + 101);
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
- res = 0;
- }
-
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-static int append_mailbox(char *context, char *mbox, char *data)
-{
- /* Assumes lock is already held */
- char tmp[256] = "";
- char *stringp;
- char *s;
- struct ast_vm_user *vmu;
-
- ast_copy_string(tmp, data, sizeof(tmp));
- vmu = malloc(sizeof(struct ast_vm_user));
- if (vmu) {
- memset(vmu, 0, sizeof(struct ast_vm_user));
- ast_copy_string(vmu->context, context, sizeof(vmu->context));
- ast_copy_string(vmu->mailbox, mbox, sizeof(vmu->mailbox));
-
- populate_defaults(vmu);
-
- stringp = tmp;
- if ((s = strsep(&stringp, ",")))
- ast_copy_string(vmu->password, s, sizeof(vmu->password));
- if (stringp && (s = strsep(&stringp, ",")))
- ast_copy_string(vmu->fullname, s, sizeof(vmu->fullname));
- if (stringp && (s = strsep(&stringp, ",")))
- ast_copy_string(vmu->email, s, sizeof(vmu->email));
- if (stringp && (s = strsep(&stringp, ",")))
- ast_copy_string(vmu->pager, s, sizeof(vmu->pager));
- if (stringp && (s = strsep(&stringp, ",")))
- apply_options(vmu, s);
-
- vmu->next = NULL;
- if (usersl)
- usersl->next = vmu;
- else
- users = vmu;
- usersl = vmu;
- }
- return 0;
-}
-
-static int vm_box_exists(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- struct ast_vm_user svm;
- char *context, *box;
- int priority_jump = 0;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(mbox);
- AST_APP_ARG(options);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_ERROR, "MailboxExists requires an argument: (vmbox[@context][|options])\n");
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- box = ast_strdupa(data);
- if (!box) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, box);
-
- if (args.options) {
- if (strchr(args.options, 'j'))
- priority_jump = 1;
- }
-
- if ((context = strchr(args.mbox, '@'))) {
- *context = '\0';
- context++;
- }
-
- if (find_user(&svm, context, args.mbox)) {
- pbx_builtin_setvar_helper(chan, "VMBOXEXISTSSTATUS", "SUCCESS");
- if (priority_jump || option_priority_jumping)
- if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
- ast_log(LOG_WARNING, "VM box %s@%s exists, but extension %s, priority %d doesn't exist\n", box, context, chan->exten, chan->priority + 101);
- } else
- pbx_builtin_setvar_helper(chan, "VMBOXEXISTSSTATUS", "FAILED");
- LOCAL_USER_REMOVE(u);
- return 0;
-}
-
-static int vmauthenticate(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- char *s = data, *user=NULL, *context=NULL, mailbox[AST_MAX_EXTENSION] = "";
- struct ast_vm_user vmus;
- char *options = NULL;
- int silent = 0, skipuser = 0;
- int res = -1;
-
- LOCAL_USER_ADD(u);
-
- if (s) {
- s = ast_strdupa(s);
- if (!s) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
- user = strsep(&s, "|");
- options = strsep(&s, "|");
- if (user) {
- s = user;
- user = strsep(&s, "@");
- context = strsep(&s, "");
- if (!ast_strlen_zero(user))
- skipuser++;
- ast_copy_string(mailbox, user, sizeof(mailbox));
- }
- }
-
- if (options) {
- silent = (strchr(options, 's')) != NULL;
- }
-
- if (!vm_authenticate(chan, mailbox, sizeof(mailbox), &vmus, context, NULL, skipuser, 3, silent)) {
- pbx_builtin_setvar_helper(chan, "AUTH_MAILBOX", mailbox);
- pbx_builtin_setvar_helper(chan, "AUTH_CONTEXT", vmus.context);
- ast_play_and_wait(chan, "auth-thankyou");
- res = 0;
- }
-
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static char show_voicemail_users_help[] =
-"Usage: show voicemail users [for <context>]\n"
-" Lists all mailboxes currently set up\n";
-
-static char show_voicemail_zones_help[] =
-"Usage: show voicemail zones\n"
-" Lists zone message formats\n";
-
-static int handle_show_voicemail_users(int fd, int argc, char *argv[])
-{
- struct ast_vm_user *vmu = users;
- char *output_format = "%-10s %-5s %-25s %-10s %6s\n";
-
- if ((argc < 3) || (argc > 5) || (argc == 4)) return RESULT_SHOWUSAGE;
- else if ((argc == 5) && strcmp(argv[3],"for")) return RESULT_SHOWUSAGE;
-
- if (vmu) {
- if (argc == 3)
- ast_cli(fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
- else {
- int count = 0;
- while (vmu) {
- if (!strcmp(argv[4],vmu->context))
- count++;
- vmu = vmu->next;
- }
- if (count) {
- vmu = users;
- ast_cli(fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
- } else {
- ast_cli(fd, "No such voicemail context \"%s\"\n", argv[4]);
- return RESULT_FAILURE;
- }
- }
- while (vmu) {
- char dirname[256];
- DIR *vmdir;
- struct dirent *vment;
- int vmcount = 0;
- char count[12];
-
- if ((argc == 3) || ((argc == 5) && !strcmp(argv[4],vmu->context))) {
- make_dir(dirname, 255, vmu->context, vmu->mailbox, "INBOX");
- if ((vmdir = opendir(dirname))) {
- /* No matter what the format of VM, there will always be a .txt file for each message. */
- while ((vment = readdir(vmdir)))
- if (strlen(vment->d_name) > 7 && !strncmp(vment->d_name + 7,".txt",4))
- vmcount++;
- closedir(vmdir);
- }
- snprintf(count,sizeof(count),"%d",vmcount);
- ast_cli(fd, output_format, vmu->context, vmu->mailbox, vmu->fullname, vmu->zonetag, count);
- }
- vmu = vmu->next;
- }
- } else {
- ast_cli(fd, "There are no voicemail users currently defined\n");
- return RESULT_FAILURE;
- }
- return RESULT_SUCCESS;
-}
-
-static int handle_show_voicemail_zones(int fd, int argc, char *argv[])
-{
- struct vm_zone *zone = zones;
- char *output_format = "%-15s %-20s %-45s\n";
-
- if (argc != 3) return RESULT_SHOWUSAGE;
-
- if (zone) {
- ast_cli(fd, output_format, "Zone", "Timezone", "Message Format");
- while (zone) {
- ast_cli(fd, output_format, zone->name, zone->timezone, zone->msg_format);
- zone = zone->next;
- }
- } else {
- ast_cli(fd, "There are no voicemail zones currently defined\n");
- return RESULT_FAILURE;
- }
- return RESULT_SUCCESS;
-}
-
-static char *complete_show_voicemail_users(char *line, char *word, int pos, int state)
-{
- int which = 0;
- struct ast_vm_user *vmu = users;
- char *context = "";
-
- /* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <context> */
- if (pos > 4)
- return NULL;
- if (pos == 3) {
- if (state == 0)
- return strdup("for");
- else
- return NULL;
- }
- while (vmu) {
- if (!strncasecmp(word, vmu->context, strlen(word))) {
- if (context && strcmp(context, vmu->context)) {
- if (++which > state) {
- return strdup(vmu->context);
- }
- context = vmu->context;
- }
- }
- vmu = vmu->next;
- }
- return NULL;
-}
-
-static struct ast_cli_entry show_voicemail_users_cli =
- { { "show", "voicemail", "users", NULL },
- handle_show_voicemail_users, "List defined voicemail boxes",
- show_voicemail_users_help, complete_show_voicemail_users };
-
-static struct ast_cli_entry show_voicemail_zones_cli =
- { { "show", "voicemail", "zones", NULL },
- handle_show_voicemail_zones, "List zone message formats",
- show_voicemail_zones_help, NULL };
-
-static int load_config(void)
-{
- struct ast_vm_user *cur, *l;
- struct vm_zone *zcur, *zl;
- struct ast_config *cfg;
- char *cat;
- struct ast_variable *var;
- char *notifystr = NULL;
- char *astattach;
- char *astsearch;
- char *astsaycid;
- char *send_voicemail;
- char *astcallop;
- char *astreview;
- char *astskipcmd;
- char *asthearenv;
- char *astsaydurationinfo;
- char *astsaydurationminfo;
- char *silencestr;
- char *maxmsgstr;
- char *astdirfwd;
- char *thresholdstr;
- char *fmt;
- char *astemail;
- char *astmailcmd = SENDMAIL;
- char *s,*q,*stringp;
- char *dialoutcxt = NULL;
- char *callbackcxt = NULL;
- char *exitcxt = NULL;
- char *extpc;
- char *emaildateformatstr;
- int x;
- int tmpadsi[4];
-
- cfg = ast_config_load(VOICEMAIL_CONFIG);
- ast_mutex_lock(&vmlock);
- cur = users;
- while (cur) {
- l = cur;
- cur = cur->next;
- ast_set_flag(l, VM_ALLOCED);
- free_user(l);
- }
- zcur = zones;
- while (zcur) {
- zl = zcur;
- zcur = zcur->next;
- free_zone(zl);
- }
- zones = NULL;
- zonesl = NULL;
- users = NULL;
- usersl = NULL;
- memset(ext_pass_cmd, 0, sizeof(ext_pass_cmd));
-
- if (cfg) {
- /* General settings */
-
- /* Attach voice message to mail message ? */
- if (!(astattach = ast_variable_retrieve(cfg, "general", "attach")))
- astattach = "yes";
- ast_set2_flag((&globalflags), ast_true(astattach), VM_ATTACH);
-
- if (!(astsearch = ast_variable_retrieve(cfg, "general", "searchcontexts")))
- astsearch = "no";
- ast_set2_flag((&globalflags), ast_true(astsearch), VM_SEARCH);
-
-#ifdef USE_ODBC_STORAGE
- strcpy(odbc_database, "asterisk");
- if ((thresholdstr = ast_variable_retrieve(cfg, "general", "odbcstorage"))) {
- ast_copy_string(odbc_database, thresholdstr, sizeof(odbc_database));
- }
- strcpy(odbc_table, "voicemessages");
- if ((thresholdstr = ast_variable_retrieve(cfg, "general", "odbctable"))) {
- ast_copy_string(odbc_table, thresholdstr, sizeof(odbc_table));
- }
-#endif
- /* Mail command */
- strcpy(mailcmd, SENDMAIL);
- if ((astmailcmd = ast_variable_retrieve(cfg, "general", "mailcmd")))
- ast_copy_string(mailcmd, astmailcmd, sizeof(mailcmd)); /* User setting */
-
- maxsilence = 0;
- if ((silencestr = ast_variable_retrieve(cfg, "general", "maxsilence"))) {
- maxsilence = atoi(silencestr);
- if (maxsilence > 0)
- maxsilence *= 1000;
- }
-
- if (!(maxmsgstr = ast_variable_retrieve(cfg, "general", "maxmsg"))) {
- maxmsg = MAXMSG;
- } else {
- maxmsg = atoi(maxmsgstr);
- if (maxmsg <= 0) {
- ast_log(LOG_WARNING, "Invalid number of messages per folder '%s'. Using default value %i\n", maxmsgstr, MAXMSG);
- maxmsg = MAXMSG;
- } else if (maxmsg > MAXMSGLIMIT) {
- ast_log(LOG_WARNING, "Maximum number of messages per folder is %i. Cannot accept value '%s'\n", MAXMSGLIMIT, maxmsgstr);
- maxmsg = MAXMSGLIMIT;
- }
- }
-
- /* Load date format config for voicemail mail */
- if ((emaildateformatstr = ast_variable_retrieve(cfg, "general", "emaildateformat"))) {
- ast_copy_string(emaildateformat, emaildateformatstr, sizeof(emaildateformat));
- }
-
- /* External password changing command */
- if ((extpc = ast_variable_retrieve(cfg, "general", "externpass"))) {
- ast_copy_string(ext_pass_cmd,extpc,sizeof(ext_pass_cmd));
- }
-
- /* External voicemail notify application */
-
- if ((notifystr = ast_variable_retrieve(cfg, "general", "externnotify"))) {
- ast_copy_string(externnotify, notifystr, sizeof(externnotify));
- ast_log(LOG_DEBUG, "found externnotify: %s\n", externnotify);
- } else {
- externnotify[0] = '\0';
- }
-
- /* Silence treshold */
- silencethreshold = 256;
- if ((thresholdstr = ast_variable_retrieve(cfg, "general", "silencethreshold")))
- silencethreshold = atoi(thresholdstr);
-
- if (!(astemail = ast_variable_retrieve(cfg, "general", "serveremail")))
- astemail = ASTERISK_USERNAME;
- ast_copy_string(serveremail, astemail, sizeof(serveremail));
-
- vmmaxmessage = 0;
- if ((s = ast_variable_retrieve(cfg, "general", "maxmessage"))) {
- if (sscanf(s, "%d", &x) == 1) {
- vmmaxmessage = x;
- } else {
- ast_log(LOG_WARNING, "Invalid max message time length\n");
- }
- }
-
- vmminmessage = 0;
- if ((s = ast_variable_retrieve(cfg, "general", "minmessage"))) {
- if (sscanf(s, "%d", &x) == 1) {
- vmminmessage = x;
- if (maxsilence <= vmminmessage)
- ast_log(LOG_WARNING, "maxsilence should be less than minmessage or you may get empty messages\n");
- } else {
- ast_log(LOG_WARNING, "Invalid min message time length\n");
- }
- }
- fmt = ast_variable_retrieve(cfg, "general", "format");
- if (!fmt)
- fmt = "wav";
- ast_copy_string(vmfmts, fmt, sizeof(vmfmts));
-
- skipms = 3000;
- if ((s = ast_variable_retrieve(cfg, "general", "maxgreet"))) {
- if (sscanf(s, "%d", &x) == 1) {
- maxgreet = x;
- } else {
- ast_log(LOG_WARNING, "Invalid max message greeting length\n");
- }
- }
-
- if ((s = ast_variable_retrieve(cfg, "general", "skipms"))) {
- if (sscanf(s, "%d", &x) == 1) {
- skipms = x;
- } else {
- ast_log(LOG_WARNING, "Invalid skipms value\n");
- }
- }
-
- maxlogins = 3;
- if ((s = ast_variable_retrieve(cfg, "general", "maxlogins"))) {
- if (sscanf(s, "%d", &x) == 1) {
- maxlogins = x;
- } else {
- ast_log(LOG_WARNING, "Invalid max failed login attempts\n");
- }
- }
-
- /* Force new user to record name ? */
- if (!(astattach = ast_variable_retrieve(cfg, "general", "forcename")))
- astattach = "no";
- ast_set2_flag((&globalflags), ast_true(astattach), VM_FORCENAME);
-
- /* Force new user to record greetings ? */
- if (!(astattach = ast_variable_retrieve(cfg, "general", "forcegreetings")))
- astattach = "no";
- ast_set2_flag((&globalflags), ast_true(astattach), VM_FORCEGREET);
-
- if ((s = ast_variable_retrieve(cfg, "general", "cidinternalcontexts"))){
- ast_log(LOG_DEBUG,"VM_CID Internal context string: %s\n",s);
- stringp = ast_strdupa(s);
- for (x = 0 ; x < MAX_NUM_CID_CONTEXTS ; x++){
- if (!ast_strlen_zero(stringp)) {
- q = strsep(&stringp,",");
- while ((*q == ' ')||(*q == '\t')) /* Eat white space between contexts */
- q++;
- ast_copy_string(cidinternalcontexts[x], q, sizeof(cidinternalcontexts[x]));
- ast_log(LOG_DEBUG,"VM_CID Internal context %d: %s\n", x, cidinternalcontexts[x]);
- } else {
- cidinternalcontexts[x][0] = '\0';
- }
- }
- }
- if (!(astreview = ast_variable_retrieve(cfg, "general", "review"))){
- ast_log(LOG_DEBUG,"VM Review Option disabled globally\n");
- astreview = "no";
- }
- ast_set2_flag((&globalflags), ast_true(astreview), VM_REVIEW);
-
- if (!(astcallop = ast_variable_retrieve(cfg, "general", "operator"))){
- ast_log(LOG_DEBUG,"VM Operator break disabled globally\n");
- astcallop = "no";
- }
- ast_set2_flag((&globalflags), ast_true(astcallop), VM_OPERATOR);
-
- if (!(astsaycid = ast_variable_retrieve(cfg, "general", "saycid"))) {
- ast_log(LOG_DEBUG,"VM CID Info before msg disabled globally\n");
- astsaycid = "no";
- }
- ast_set2_flag((&globalflags), ast_true(astsaycid), VM_SAYCID);
-
- if (!(send_voicemail = ast_variable_retrieve(cfg,"general", "sendvoicemail"))){
- ast_log(LOG_DEBUG,"Send Voicemail msg disabled globally\n");
- send_voicemail = "no";
- }
- ast_set2_flag((&globalflags), ast_true(send_voicemail), VM_SVMAIL);
-
- if (!(asthearenv = ast_variable_retrieve(cfg, "general", "envelope"))) {
- ast_log(LOG_DEBUG,"ENVELOPE before msg enabled globally\n");
- asthearenv = "yes";
- }
- ast_set2_flag((&globalflags), ast_true(asthearenv), VM_ENVELOPE);
-
- if (!(astsaydurationinfo = ast_variable_retrieve(cfg, "general", "sayduration"))) {
- ast_log(LOG_DEBUG,"Duration info before msg enabled globally\n");
- astsaydurationinfo = "yes";
- }
- ast_set2_flag((&globalflags), ast_true(astsaydurationinfo), VM_SAYDURATION);
-
- saydurationminfo = 2;
- if ((astsaydurationminfo = ast_variable_retrieve(cfg, "general", "saydurationm"))) {
- if (sscanf(astsaydurationminfo, "%d", &x) == 1) {
- saydurationminfo = x;
- } else {
- ast_log(LOG_WARNING, "Invalid min duration for say duration\n");
- }
- }
-
- if (!(astskipcmd = ast_variable_retrieve(cfg, "general", "nextaftercmd"))) {
- ast_log(LOG_DEBUG,"We are not going to skip to the next msg after save/delete\n");
- astskipcmd = "no";
- }
- ast_set2_flag((&globalflags), ast_true(astskipcmd), VM_SKIPAFTERCMD);
-
- if ((dialoutcxt = ast_variable_retrieve(cfg, "general", "dialout"))) {
- ast_copy_string(dialcontext, dialoutcxt, sizeof(dialcontext));
- ast_log(LOG_DEBUG, "found dialout context: %s\n", dialcontext);
- } else {
- dialcontext[0] = '\0';
- }
-
- if ((callbackcxt = ast_variable_retrieve(cfg, "general", "callback"))) {
- ast_copy_string(callcontext, callbackcxt, sizeof(callcontext));
- ast_log(LOG_DEBUG, "found callback context: %s\n", callcontext);
- } else {
- callcontext[0] = '\0';
- }
-
- if ((exitcxt = ast_variable_retrieve(cfg, "general", "exitcontext"))) {
- ast_copy_string(exitcontext, exitcxt, sizeof(exitcontext));
- ast_log(LOG_DEBUG, "found operator context: %s\n", exitcontext);
- } else {
- exitcontext[0] = '\0';
- }
-
- if (!(astdirfwd = ast_variable_retrieve(cfg, "general", "usedirectory")))
- astdirfwd = "no";
- ast_set2_flag((&globalflags), ast_true(astdirfwd), VM_DIRECFORWARD);
- cat = ast_category_browse(cfg, NULL);
- while (cat) {
- if (strcasecmp(cat, "general")) {
- var = ast_variable_browse(cfg, cat);
- if (strcasecmp(cat, "zonemessages")) {
- /* Process mailboxes in this context */
- while (var) {
- append_mailbox(cat, var->name, var->value);
- var = var->next;
- }
- } else {
- /* Timezones in this context */
- while (var) {
- struct vm_zone *z;
- z = malloc(sizeof(struct vm_zone));
- if (z != NULL) {
- char *msg_format, *timezone;
- msg_format = ast_strdupa(var->value);
- if (msg_format != NULL) {
- timezone = strsep(&msg_format, "|");
- if (msg_format) {
- ast_copy_string(z->name, var->name, sizeof(z->name));
- ast_copy_string(z->timezone, timezone, sizeof(z->timezone));
- ast_copy_string(z->msg_format, msg_format, sizeof(z->msg_format));
- z->next = NULL;
- if (zones) {
- zonesl->next = z;
- zonesl = z;
- } else {
- zones = z;
- zonesl = z;
- }
- } else {
- ast_log(LOG_WARNING, "Invalid timezone definition at line %d\n", var->lineno);
- free(z);
- }
- } else {
- ast_log(LOG_WARNING, "Out of memory while reading voicemail config\n");
- free(z);
- return -1;
- }
- } else {
- ast_log(LOG_WARNING, "Out of memory while reading voicemail config\n");
- return -1;
- }
- var = var->next;
- }
- }
- }
- cat = ast_category_browse(cfg, cat);
- }
- memset(fromstring,0,sizeof(fromstring));
- memset(pagerfromstring,0,sizeof(pagerfromstring));
- memset(emailtitle,0,sizeof(emailtitle));
- strcpy(charset, "ISO-8859-1");
- if (emailbody) {
- free(emailbody);
- emailbody = NULL;
- }
- if (emailsubject) {
- free(emailsubject);
- emailsubject = NULL;
- }
- if (pagerbody) {
- free(pagerbody);
- pagerbody = NULL;
- }
- if (pagersubject) {
- free(pagersubject);
- pagersubject = NULL;
- }
- if ((s=ast_variable_retrieve(cfg, "general", "pbxskip")))
- ast_set2_flag((&globalflags), ast_true(s), VM_PBXSKIP);
- if ((s=ast_variable_retrieve(cfg, "general", "fromstring")))
- ast_copy_string(fromstring,s,sizeof(fromstring));
- if ((s=ast_variable_retrieve(cfg, "general", "pagerfromstring")))
- ast_copy_string(pagerfromstring,s,sizeof(pagerfromstring));
- if ((s=ast_variable_retrieve(cfg, "general", "charset")))
- ast_copy_string(charset,s,sizeof(charset));
- if ((s=ast_variable_retrieve(cfg, "general", "adsifdn"))) {
- sscanf(s, "%2x%2x%2x%2x", &tmpadsi[0], &tmpadsi[1], &tmpadsi[2], &tmpadsi[3]);
- for (x=0; x<4; x++) {
- memcpy(&adsifdn[x], &tmpadsi[x], 1);
- }
- }
- if ((s=ast_variable_retrieve(cfg, "general", "adsisec"))) {
- sscanf(s, "%2x%2x%2x%2x", &tmpadsi[0], &tmpadsi[1], &tmpadsi[2], &tmpadsi[3]);
- for (x=0; x<4; x++) {
- memcpy(&adsisec[x], &tmpadsi[x], 1);
- }
- }
- if ((s=ast_variable_retrieve(cfg, "general", "adsiver")))
- if (atoi(s)) {
- adsiver = atoi(s);
- }
- if ((s=ast_variable_retrieve(cfg, "general", "emailtitle"))) {
- ast_log(LOG_NOTICE, "Keyword 'emailtitle' is DEPRECATED, please use 'emailsubject' instead.\n");
- ast_copy_string(emailtitle,s,sizeof(emailtitle));
- }
- if ((s=ast_variable_retrieve(cfg, "general", "emailsubject")))
- emailsubject = strdup(s);
- if ((s=ast_variable_retrieve(cfg, "general", "emailbody"))) {
- char *tmpread, *tmpwrite;
- emailbody = strdup(s);
-
- /* substitute strings \t and \n into the apropriate characters */
- tmpread = tmpwrite = emailbody;
- while ((tmpwrite = strchr(tmpread,'\\'))) {
- int len = strlen("\n");
- switch (tmpwrite[1]) {
- case 'n':
- strncpy(tmpwrite+len,tmpwrite+2,strlen(tmpwrite+2)+1);
- strncpy(tmpwrite,"\n",len);
- break;
- case 't':
- strncpy(tmpwrite+len,tmpwrite+2,strlen(tmpwrite+2)+1);
- strncpy(tmpwrite,"\t",len);
- break;
- default:
- ast_log(LOG_NOTICE, "Substitution routine does not support this character: %c\n",tmpwrite[1]);
- }
- tmpread = tmpwrite+len;
- }
- }
- if ((s=ast_variable_retrieve(cfg, "general", "pagersubject")))
- pagersubject = strdup(s);
- if ((s=ast_variable_retrieve(cfg, "general", "pagerbody"))) {
- char *tmpread, *tmpwrite;
- pagerbody = strdup(s);
-
- /* substitute strings \t and \n into the apropriate characters */
- tmpread = tmpwrite = pagerbody;
- while ((tmpwrite = strchr(tmpread,'\\'))) {
- int len = strlen("\n");
- switch (tmpwrite[1]) {
- case 'n':
- strncpy(tmpwrite+len,tmpwrite+2,strlen(tmpwrite+2)+1);
- strncpy(tmpwrite,"\n",len);
- break;
- case 't':
- strncpy(tmpwrite+len,tmpwrite+2,strlen(tmpwrite+2)+1);
- strncpy(tmpwrite,"\t",len);
- break;
- default:
- ast_log(LOG_NOTICE, "Substitution routine does not support this character: %c\n",tmpwrite[1]);
- }
- tmpread = tmpwrite+len;
- }
- }
- ast_mutex_unlock(&vmlock);
- ast_config_destroy(cfg);
- return 0;
- } else {
- ast_mutex_unlock(&vmlock);
- ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
- return 0;
- }
-}
-
-int reload(void)
-{
- return(load_config());
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
- res |= ast_unregister_application(app2);
- res |= ast_unregister_application(app3);
- res |= ast_unregister_application(app4);
- res |= ast_cli_unregister(&show_voicemail_users_cli);
- res |= ast_cli_unregister(&show_voicemail_zones_cli);
- ast_uninstall_vm_functions();
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
- res = ast_register_application(app, vm_exec, synopsis_vm, descrip_vm);
- res |= ast_register_application(app2, vm_execmain, synopsis_vmain, descrip_vmain);
- res |= ast_register_application(app3, vm_box_exists, synopsis_vm_box_exists, descrip_vm_box_exists);
- res |= ast_register_application(app4, vmauthenticate, synopsis_vmauthenticate, descrip_vmauthenticate);
- if (res)
- return(res);
-
- if ((res=load_config())) {
- return(res);
- }
-
- ast_cli_register(&show_voicemail_users_cli);
- ast_cli_register(&show_voicemail_zones_cli);
-
- /* compute the location of the voicemail spool directory */
- snprintf(VM_SPOOL_DIR, sizeof(VM_SPOOL_DIR), "%s/voicemail/", ast_config_AST_SPOOL_DIR);
-
- ast_install_vm_functions(has_voicemail, messagecount);
-
-#if defined(USE_ODBC_STORAGE) && !defined(EXTENDED_ODBC_STORAGE)
- ast_log(LOG_WARNING, "The current ODBC storage table format will be changed soon."
- "Please update your tables as per the README and edit the apps/Makefile "
- "and uncomment the line containing EXTENDED_ODBC_STORAGE to enable the "
- "new table format.\n");
-#endif
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-static int dialout(struct ast_channel *chan, struct ast_vm_user *vmu, char *num, char *outgoing_context)
-{
- int cmd = 0;
- char destination[80] = "";
- int retries = 0;
-
- if (!num) {
- ast_verbose( VERBOSE_PREFIX_3 "Destination number will be entered manually\n");
- while (retries < 3 && cmd != 't') {
- destination[1] = '\0';
- destination[0] = cmd = ast_play_and_wait(chan,"vm-enter-num-to-call");
- if (!cmd)
- destination[0] = cmd = ast_play_and_wait(chan, "vm-then-pound");
- if (!cmd)
- destination[0] = cmd = ast_play_and_wait(chan, "vm-star-cancel");
- if (!cmd) {
- cmd = ast_waitfordigit(chan, 6000);
- if (cmd)
- destination[0] = cmd;
- }
- if (!cmd) {
- retries++;
- } else {
-
- if (cmd < 0)
- return 0;
- if (cmd == '*') {
- ast_verbose( VERBOSE_PREFIX_3 "User hit '*' to cancel outgoing call\n");
- return 0;
- }
- if ((cmd = ast_readstring(chan,destination + strlen(destination),sizeof(destination)-1,6000,10000,"#")) < 0)
- retries++;
- else
- cmd = 't';
- }
- }
- if (retries >= 3) {
- return 0;
- }
-
- } else {
- ast_verbose( VERBOSE_PREFIX_3 "Destination number is CID number '%s'\n", num);
- ast_copy_string(destination, num, sizeof(destination));
- }
-
- if (!ast_strlen_zero(destination)) {
- if (destination[strlen(destination) -1 ] == '*')
- return 0;
- ast_verbose( VERBOSE_PREFIX_3 "Placing outgoing call to extension '%s' in context '%s' from context '%s'\n", destination, outgoing_context, chan->context);
- ast_copy_string(chan->exten, destination, sizeof(chan->exten));
- ast_copy_string(chan->context, outgoing_context, sizeof(chan->context));
- chan->priority = 0;
- return 9;
- }
- return 0;
-}
-
-static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, int msg,
- int option, signed char record_gain)
-{
- int res = 0;
- char filename[256],*origtime, *cid, *context, *name, *num;
- struct ast_config *msg_cfg;
- int retries = 0;
-
- vms->starting = 0;
- make_file(vms->fn, sizeof(vms->fn), vms->curdir, msg);
-
- /* Retrieve info from VM attribute file */
-
- make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
- snprintf(filename,sizeof(filename), "%s.txt", vms->fn2);
- RETRIEVE(vms->curdir, vms->curmsg);
- msg_cfg = ast_config_load(filename);
- DISPOSE(vms->curdir, vms->curmsg);
- if (!msg_cfg) {
- ast_log(LOG_WARNING, "No message attribute file?!! (%s)\n", filename);
- return 0;
- }
-
- if (!(origtime = ast_variable_retrieve(msg_cfg, "message", "origtime")))
- return 0;
-
- cid = ast_variable_retrieve(msg_cfg, "message", "callerid");
-
- context = ast_variable_retrieve(msg_cfg, "message", "context");
- if (!strncasecmp("macro",context,5)) /* Macro names in contexts are useless for our needs */
- context = ast_variable_retrieve(msg_cfg, "message","macrocontext");
-
- if (option == 3) {
-
- if (!res)
- res = play_message_datetime(chan, vmu, origtime, filename);
- if (!res)
- res = play_message_callerid(chan, vms, cid, context, 0);
- } else if (option == 2) { /* Call back */
-
- if (!ast_strlen_zero(cid)) {
- ast_callerid_parse(cid, &name, &num);
- while ((res > -1) && (res != 't')) {
- switch(res) {
- case '1':
- if (num) {
- /* Dial the CID number */
- res = dialout(chan, vmu, num, vmu->callback);
- if (res)
- return 9;
- } else {
- res = '2';
- }
- break;
-
- case '2':
- /* Want to enter a different number, can only do this if there's a dialout context for this user */
- if (!ast_strlen_zero(vmu->dialout)) {
- res = dialout(chan, vmu, NULL, vmu->dialout);
- if (res)
- return 9;
- } else {
- ast_verbose( VERBOSE_PREFIX_3 "Caller can not specify callback number - no dialout context available\n");
- res = ast_play_and_wait(chan, "vm-sorry");
- }
- return res;
- case '*':
- res = 't';
- break;
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '0':
-
- res = ast_play_and_wait(chan, "vm-sorry");
- retries++;
- break;
- default:
- if (num) {
- ast_verbose( VERBOSE_PREFIX_3 "Confirm CID number '%s' is number to use for callback\n", num);
- res = ast_play_and_wait(chan, "vm-num-i-have");
- if (!res)
- res = play_message_callerid(chan, vms, num, vmu->context, 1);
- if (!res)
- res = ast_play_and_wait(chan, "vm-tocallnum");
- /* Only prompt for a caller-specified number if there is a dialout context specified */
- if (!ast_strlen_zero(vmu->dialout)) {
- if (!res)
- res = ast_play_and_wait(chan, "vm-calldiffnum");
- }
- } else {
- res = ast_play_and_wait(chan, "vm-nonumber");
- if (!ast_strlen_zero(vmu->dialout)) {
- if (!res)
- res = ast_play_and_wait(chan, "vm-toenternumber");
- }
- }
- if (!res)
- res = ast_play_and_wait(chan, "vm-star-cancel");
- if (!res)
- res = ast_waitfordigit(chan, 6000);
- if (!res)
- retries++;
- if (retries > 3)
- res = 't';
- break;
-
- }
- if (res == 't')
- res = 0;
- else if (res == '*')
- res = -1;
- }
- }
-
- }
- else if (option == 1) { /* Reply */
- /* Send reply directly to sender */
- if (!ast_strlen_zero(cid)) {
- ast_callerid_parse(cid, &name, &num);
- if (!num) {
- ast_verbose(VERBOSE_PREFIX_3 "No CID number available, no reply sent\n");
- if (!res)
- res = ast_play_and_wait(chan, "vm-nonumber");
- return res;
- } else {
- if (find_user(NULL, vmu->context, num)) {
- struct leave_vm_options leave_options;
-
- ast_verbose(VERBOSE_PREFIX_3 "Leaving voicemail for '%s' in context '%s'\n", num, vmu->context);
-
- memset(&leave_options, 0, sizeof(leave_options));
- leave_options.record_gain = record_gain;
- res = leave_voicemail(chan, num, &leave_options);
- if (!res)
- res = 't';
- return res;
- } else {
- /* Sender has no mailbox, can't reply */
- ast_verbose( VERBOSE_PREFIX_3 "No mailbox number '%s' in context '%s', no reply sent\n", num, vmu->context);
- ast_play_and_wait(chan, "vm-nobox");
- res = 't';
- return res;
- }
- }
- res = 0;
- }
- }
-
- ast_config_destroy(msg_cfg);
-
- if (!res) {
- make_file(vms->fn, sizeof(vms->fn), vms->curdir, msg);
- vms->heard[msg] = 1;
- res = wait_file(chan, vms, vms->fn);
- }
- return res;
-}
-
-static int play_record_review(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt,
- int outsidecaller, struct ast_vm_user *vmu, int *duration, const char *unlockdir,
- signed char record_gain)
-{
- /* Record message & let caller review or re-record it, or set options if applicable */
- int res = 0;
- int cmd = 0;
- int max_attempts = 3;
- int attempts = 0;
- int recorded = 0;
- int message_exists = 0;
- signed char zero_gain = 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 play_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 {
- /* Otherwise 1 is to save the existing message */
- ast_verbose(VERBOSE_PREFIX_3 "Saving message as is\n");
- ast_streamfile(chan, "vm-msgsaved", chan->language);
- ast_waitstream(chan, "");
- STORE(recordfile, vmu->mailbox, vmu->context, -1);
- DISPOSE(recordfile, -1);
- cmd = 't';
- return res;
- }
- case '2':
- /* Review */
- ast_verbose(VERBOSE_PREFIX_3 "Reviewing the message\n");
- ast_streamfile(chan, recordfile, chan->language);
- cmd = ast_waitstream(chan, AST_DIGIT_ANY);
- break;
- case '3':
- message_exists = 0;
- /* Record */
- if (recorded == 1)
- ast_verbose(VERBOSE_PREFIX_3 "Re-recording the message\n");
- else
- ast_verbose(VERBOSE_PREFIX_3 "Recording the message\n");
- if (recorded && outsidecaller) {
- cmd = ast_play_and_wait(chan, INTRO);
- cmd = ast_play_and_wait(chan, "beep");
- }
- recorded = 1;
- /* After an attempt has been made to record message, we have to take care of INTRO and beep for incoming messages, but not for greetings */
- if (record_gain)
- ast_channel_setoption(chan, AST_OPTION_RXGAIN, &record_gain, sizeof(record_gain), 0);
- cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, silencethreshold, maxsilence, unlockdir);
- if (record_gain)
- ast_channel_setoption(chan, AST_OPTION_RXGAIN, &zero_gain, sizeof(zero_gain), 0);
- if (cmd == -1) {
- /* User has hung up, no options to give */
- return cmd;
- }
- if (cmd == '0') {
- break;
- } else if (cmd == '*') {
- break;
- }
-#if 0
- else if (vmu->review && (*duration < 5)) {
- /* Message is too short */
- ast_verbose(VERBOSE_PREFIX_3 "Message too short\n");
- cmd = ast_play_and_wait(chan, "vm-tooshort");
- cmd = vm_delete(recordfile);
- break;
- }
- else if (vmu->review && (cmd == 2 && *duration < (maxsilence + 3))) {
- /* Message is all silence */
- ast_verbose(VERBOSE_PREFIX_3 "Nothing recorded\n");
- cmd = vm_delete(recordfile);
- cmd = ast_play_and_wait(chan, "vm-nothingrecorded");
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-speakup");
- break;
- }
-#endif
- 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;
-#if 0
-/* XXX Commented out for the moment because of the dangers of deleting
- a message while recording (can put the message numbers out of sync) */
- case '*':
- /* Cancel recording, delete message, offer to take another message*/
- cmd = ast_play_and_wait(chan, "vm-deleted");
- cmd = vm_delete(recordfile);
- if (outsidecaller) {
- res = vm_exec(chan, NULL);
- return res;
- }
- else
- return 1;
-#endif
- case '0':
- if (message_exists || recorded) {
- cmd = ast_play_and_wait(chan, "vm-saveoper");
- if (!cmd)
- cmd = ast_waitfordigit(chan, 3000);
- if (cmd == '1') {
- ast_play_and_wait(chan, "vm-msgsaved");
- cmd = '0';
- } else {
- ast_play_and_wait(chan, "vm-deleted");
- DELETE(recordfile, -1, recordfile);
- cmd = '0';
- }
- }
- return cmd;
- default:
- /* If the caller is an ouside caller, and the review option is enabled,
- allow them to review the message, but let the owner of the box review
- their OGM's */
- if (outsidecaller && !ast_test_flag(vmu, VM_REVIEW))
- return cmd;
- 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 && outsidecaller && ast_test_flag(vmu, VM_OPERATOR)) {
- cmd = ast_play_and_wait(chan, "vm-reachoper");
- if (!cmd)
- cmd = ast_waitfordigit(chan, 600);
- }
-#if 0
- if (!cmd)
- cmd = ast_play_and_wait(chan, "vm-tocancelmsg");
-#endif
- if (!cmd)
- cmd = ast_waitfordigit(chan, 6000);
- if (!cmd) {
- attempts++;
- }
- if (attempts > max_attempts) {
- cmd = 't';
- }
- }
- }
- if (outsidecaller)
- ast_play_and_wait(chan, "vm-goodbye");
- if (cmd == 't')
- cmd = 0;
- return cmd;
- }
-
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_waitforring.c b/1.2-netsec/apps/app_waitforring.c
deleted file mode 100644
index 25e651d9e..000000000
--- a/1.2-netsec/apps/app_waitforring.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Wait for Ring Application
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
-
-static char *synopsis = "Wait for Ring Application";
-
-static char *tdesc = "Waits until first ring after time";
-
-static char *desc = " WaitForRing(timeout)\n"
-"Returns 0 after waiting at least timeout seconds. and\n"
-"only after the next ring has completed. Returns 0 on\n"
-"success or -1 on hangup\n";
-
-static char *app = "WaitForRing";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int waitforring_exec(struct ast_channel *chan, void *data)
-{
- struct localuser *u;
- struct ast_frame *f;
- int res = 0;
- int ms;
-
- if (!data || (sscanf(data, "%d", &ms) != 1)) {
- ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n");
- return 0;
- }
-
- LOCAL_USER_ADD(u);
-
- ms *= 1000;
- while(ms > 0) {
- ms = ast_waitfor(chan, ms);
- if (ms < 0) {
- res = ms;
- break;
- }
- if (ms > 0) {
- f = ast_read(chan);
- if (!f) {
- res = -1;
- break;
- }
- if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Got a ring but still waiting for timeout\n");
- }
- ast_frfree(f);
- }
- }
- /* Now we're really ready for the ring */
- if (!res) {
- ms = 99999999;
- while(ms > 0) {
- ms = ast_waitfor(chan, ms);
- if (ms < 0) {
- res = ms;
- break;
- }
- if (ms > 0) {
- f = ast_read(chan);
- if (!f) {
- res = -1;
- break;
- }
- if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Got a ring after the timeout\n");
- ast_frfree(f);
- break;
- }
- ast_frfree(f);
- }
- }
- }
- LOCAL_USER_REMOVE(u);
-
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, waitforring_exec, synopsis, desc);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_waitforsilence.c b/1.2-netsec/apps/app_waitforsilence.c
deleted file mode 100644
index 615eddbce..000000000
--- a/1.2-netsec/apps/app_waitforsilence.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * WaitForSilence Application by David C. Troy <dave@popvox.com>
- * Version 1.00 2004-01-29
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Wait for Silence
- * - Waits for up to 'x' milliseconds of silence, 'y' times \n
- * - WaitForSilence(500,2) will wait for 1/2 second of silence, twice \n
- * - WaitForSilence(1000,1) will wait for 1 second of silence, once \n
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/dsp.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Wait For Silence";
-static char *app = "WaitForSilence";
-static char *synopsis = "Waits for a specified amount of silence";
-static char *descrip =
-" WaitForSilence(x[|y]) Wait for Silence: Waits for up to 'x' \n"
-"milliseconds of silence, 'y' times or 1 if omitted\n"
-"Set the channel variable WAITSTATUS with to one of these values:"
-"SILENCE - if silence of x ms was detected"
-"TIMEOUT - if silence of x ms was not detected."
-"Examples:\n"
-" - WaitForSilence(500|2) will wait for 1/2 second of silence, twice\n"
-" - WaitForSilence(1000) will wait for 1 second of silence, once\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int do_waiting(struct ast_channel *chan, int maxsilence) {
-
- struct ast_frame *f;
- int totalsilence = 0;
- int dspsilence = 0;
- int gotsilence = 0;
- static int silencethreshold = 64;
- int rfmt = 0;
- int res = 0;
- struct ast_dsp *sildet; /* silence detector dsp */
- time_t start, now;
- time(&start);
-
- rfmt = chan->readformat; /* Set to linear mode */
- 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");
- return -1;
- }
-
- 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);
-
- /* Await silence... */
- f = NULL;
- for(;;) {
- res = ast_waitfor(chan, 2000);
- if (!res) {
- ast_log(LOG_WARNING, "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) {
- dspsilence = 0;
- ast_dsp_silence(sildet, f, &dspsilence);
- if (dspsilence) {
- totalsilence = dspsilence;
- time(&start);
- } else {
- totalsilence = 0;
- }
-
- if (totalsilence >= maxsilence) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Exiting with %dms silence > %dms required\n", totalsilence, maxsilence);
- /* Ended happily with silence */
- gotsilence = 1;
- pbx_builtin_setvar_helper(chan, "WAITSTATUS", "SILENCE");
- ast_log(LOG_DEBUG, "WAITSTATUS was set to SILENCE\n");
- ast_frfree(f);
- break;
- } else if ( difftime(time(&now),start) >= maxsilence/1000 ) {
- pbx_builtin_setvar_helper(chan, "WAITSTATUS", "TIMEOUT");
- ast_log(LOG_DEBUG, "WAITSTATUS was set to TIMEOUT\n");
- ast_frfree(f);
- break;
- }
- }
- ast_frfree(f);
- }
- 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);
- }
- ast_dsp_free(sildet);
- return gotsilence;
-}
-
-static int waitforsilence_exec(struct ast_channel *chan, void *data)
-{
- int res = 1;
- struct localuser *u;
- int maxsilence = 1000;
- int iterations = 1, i;
-
- LOCAL_USER_ADD(u);
-
- res = ast_answer(chan); /* Answer the channel */
-
- if (!data || ((sscanf(data, "%d|%d", &maxsilence, &iterations) != 2) &&
- (sscanf(data, "%d", &maxsilence) != 1))) {
- ast_log(LOG_WARNING, "Using default value of 1000ms, 1 iteration\n");
- }
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Waiting %d time(s) for %d ms silence\n", iterations, maxsilence);
-
- res = 1;
- for (i=0; (i<iterations) && (res == 1); i++) {
- res = do_waiting(chan, maxsilence);
- }
- LOCAL_USER_REMOVE(u);
- if (res > 0)
- res = 0;
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, waitforsilence_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_while.c b/1.2-netsec/apps/app_while.c
deleted file mode 100644
index 7c98afe80..000000000
--- a/1.2-netsec/apps/app_while.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright 2004 - 2005, Anthony Minessale <anthmct@yahoo.com>
- *
- * Anthony Minessale <anthmct@yahoo.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief While Loop and ExecIf Implementations
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/utils.h"
-#include "asterisk/config.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/options.h"
-
-#define ALL_DONE(u,ret) {LOCAL_USER_REMOVE(u); return ret;}
-
-
-static char *exec_app = "ExecIf";
-static char *exec_desc =
-"Usage: ExecIF (<expr>|<app>|<data>)\n"
-"If <expr> is true, execute and return the result of <app>(<data>).\n"
-"If <expr> is true, but <app> is not found, then the application\n"
-"will return a non-zero value.";
-static char *exec_synopsis = "Conditional exec";
-
-static char *start_app = "While";
-static char *start_desc =
-"Usage: While(<expr>)\n"
-"Start a While Loop. Execution will return to this point when\n"
-"EndWhile is called until expr is no longer true.\n";
-
-static char *start_synopsis = "Start A While Loop";
-
-
-static char *stop_app = "EndWhile";
-static char *stop_desc =
-"Usage: EndWhile()\n"
-"Return to the previous called While\n\n";
-
-static char *stop_synopsis = "End A While Loop";
-
-static char *tdesc = "While Loops and Conditional Execution";
-
-
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int execif_exec(struct ast_channel *chan, void *data) {
- int res=0;
- struct localuser *u;
- char *myapp = NULL;
- char *mydata = NULL;
- char *expr = NULL;
- struct ast_app *app = NULL;
-
- LOCAL_USER_ADD(u);
-
- expr = ast_strdupa(data);
- if (!expr) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- if ((myapp = strchr(expr,'|'))) {
- *myapp = '\0';
- myapp++;
- if ((mydata = strchr(myapp,'|'))) {
- *mydata = '\0';
- mydata++;
- } else
- mydata = "";
-
- if (ast_true(expr)) {
- if ((app = pbx_findapp(myapp))) {
- res = pbx_exec(chan, app, mydata, 1);
- } else {
- ast_log(LOG_WARNING, "Count not find application! (%s)\n", myapp);
- res = -1;
- }
- }
- } else {
- ast_log(LOG_ERROR,"Invalid Syntax.\n");
- res = -1;
- }
-
- ALL_DONE(u,res);
-}
-
-#define VAR_SIZE 64
-
-
-static char *get_index(struct ast_channel *chan, const char *prefix, int index) {
- char varname[VAR_SIZE];
-
- snprintf(varname, VAR_SIZE, "%s_%d", prefix, index);
- return pbx_builtin_getvar_helper(chan, varname);
-}
-
-static struct ast_exten *find_matching_priority(struct ast_context *c, const char *exten, int priority, const char *callerid)
-{
- struct ast_exten *e;
- struct ast_include *i;
- struct ast_context *c2;
-
- for (e=ast_walk_context_extensions(c, NULL); e; e=ast_walk_context_extensions(c, e)) {
- if (ast_extension_match(ast_get_extension_name(e), exten)) {
- int needmatch = ast_get_extension_matchcid(e);
- if ((needmatch && ast_extension_match(ast_get_extension_cidmatch(e), callerid)) ||
- (!needmatch)) {
- /* This is the matching extension we want */
- struct ast_exten *p;
- for (p=ast_walk_extension_priorities(e, NULL); p; p=ast_walk_extension_priorities(e, p)) {
- if (priority != ast_get_extension_priority(p))
- continue;
- return p;
- }
- }
- }
- }
-
- /* No match; run through includes */
- for (i=ast_walk_context_includes(c, NULL); i; i=ast_walk_context_includes(c, i)) {
- for (c2=ast_walk_contexts(NULL); c2; c2=ast_walk_contexts(c2)) {
- if (!strcmp(ast_get_context_name(c2), ast_get_include_name(i))) {
- e = find_matching_priority(c2, exten, priority, callerid);
- if (e)
- return e;
- }
- }
- }
- return NULL;
-}
-
-static int find_matching_endwhile(struct ast_channel *chan)
-{
- struct ast_context *c;
- int res=-1;
-
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Failed to lock contexts list\n");
- return -1;
- }
-
- for (c=ast_walk_contexts(NULL); c; c=ast_walk_contexts(c)) {
- struct ast_exten *e;
-
- if (!ast_lock_context(c)) {
- if (!strcmp(ast_get_context_name(c), chan->context)) {
- /* This is the matching context we want */
- int cur_priority = chan->priority + 1, level=1;
-
- for (e = find_matching_priority(c, chan->exten, cur_priority, chan->cid.cid_num); e; e = find_matching_priority(c, chan->exten, ++cur_priority, chan->cid.cid_num)) {
- if (!strcasecmp(ast_get_extension_app(e), "WHILE")) {
- level++;
- } else if (!strcasecmp(ast_get_extension_app(e), "ENDWHILE")) {
- level--;
- }
-
- if (level == 0) {
- res = cur_priority;
- break;
- }
- }
- }
- ast_unlock_context(c);
- if (res > 0) {
- break;
- }
- }
- }
- ast_unlock_contexts();
- return res;
-}
-
-static int _while_exec(struct ast_channel *chan, void *data, int end)
-{
- int res=0;
- struct localuser *u;
- char *while_pri = NULL;
- char *goto_str = NULL, *my_name = NULL;
- char *condition = NULL, *label = NULL;
- char varname[VAR_SIZE], end_varname[VAR_SIZE];
- const char *prefix = "WHILE";
- size_t size=0;
- int used_index_i = -1, x=0;
- char used_index[VAR_SIZE] = "0", new_index[VAR_SIZE] = "0";
-
- if (!chan) {
- /* huh ? */
- return -1;
- }
-
- LOCAL_USER_ADD(u);
-
- /* dont want run away loops if the chan isn't even up
- this is up for debate since it slows things down a tad ......
- */
- if (ast_waitfordigit(chan,1) < 0)
- ALL_DONE(u,-1);
-
-
- for (x=0;;x++) {
- if (get_index(chan, prefix, x)) {
- used_index_i = x;
- } else
- break;
- }
-
- snprintf(used_index, VAR_SIZE, "%d", used_index_i);
- snprintf(new_index, VAR_SIZE, "%d", used_index_i + 1);
-
- if (!end) {
- condition = ast_strdupa((char *) data);
- }
-
- size = strlen(chan->context) + strlen(chan->exten) + 32;
- my_name = alloca(size);
- memset(my_name, 0, size);
- snprintf(my_name, size, "%s_%s_%d", chan->context, chan->exten, chan->priority);
-
- if (ast_strlen_zero(label)) {
- if (end)
- label = used_index;
- else if (!(label = pbx_builtin_getvar_helper(chan, my_name))) {
- label = new_index;
- pbx_builtin_setvar_helper(chan, my_name, label);
- }
-
- }
-
- snprintf(varname, VAR_SIZE, "%s_%s", prefix, label);
- while_pri = pbx_builtin_getvar_helper(chan, varname);
-
- if ((while_pri = pbx_builtin_getvar_helper(chan, varname)) && !end) {
- snprintf(end_varname,VAR_SIZE,"END_%s",varname);
- }
-
-
- if (!end && !ast_true(condition)) {
- /* Condition Met (clean up helper vars) */
- pbx_builtin_setvar_helper(chan, varname, NULL);
- pbx_builtin_setvar_helper(chan, my_name, NULL);
- snprintf(end_varname,VAR_SIZE,"END_%s",varname);
- if ((goto_str=pbx_builtin_getvar_helper(chan, end_varname))) {
- pbx_builtin_setvar_helper(chan, end_varname, NULL);
- ast_parseable_goto(chan, goto_str);
- } else {
- int pri = find_matching_endwhile(chan);
- if (pri > 0) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Jumping to priority %d\n", pri);
- chan->priority = pri;
- } else {
- ast_log(LOG_WARNING, "Couldn't find matching EndWhile? (While at %s@%s priority %d)\n", chan->context, chan->exten, chan->priority);
- }
- }
- ALL_DONE(u,res);
- }
-
- if (!end && !while_pri) {
- size = strlen(chan->context) + strlen(chan->exten) + 32;
- goto_str = alloca(size);
- memset(goto_str, 0, size);
- snprintf(goto_str, size, "%s|%s|%d", chan->context, chan->exten, chan->priority);
- pbx_builtin_setvar_helper(chan, varname, goto_str);
- }
-
- else if (end && while_pri) {
- /* END of loop */
- snprintf(end_varname, VAR_SIZE, "END_%s", varname);
- if (! pbx_builtin_getvar_helper(chan, end_varname)) {
- size = strlen(chan->context) + strlen(chan->exten) + 32;
- goto_str = alloca(size);
- memset(goto_str, 0, size);
- snprintf(goto_str, size, "%s|%s|%d", chan->context, chan->exten, chan->priority+1);
- pbx_builtin_setvar_helper(chan, end_varname, goto_str);
- }
- ast_parseable_goto(chan, while_pri);
- }
-
-
-
-
- ALL_DONE(u, res);
-}
-
-static int while_start_exec(struct ast_channel *chan, void *data) {
- return _while_exec(chan, data, 0);
-}
-
-static int while_end_exec(struct ast_channel *chan, void *data) {
- return _while_exec(chan, data, 1);
-}
-
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(start_app);
- res |= ast_unregister_application(exec_app);
- res |= ast_unregister_application(stop_app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(start_app, while_start_exec, start_synopsis, start_desc);
- res |= ast_register_application(exec_app, execif_exec, exec_synopsis, exec_desc);
- res |= ast_register_application(stop_app, while_end_exec, stop_synopsis, stop_desc);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/app_zapateller.c b/1.2-netsec/apps/app_zapateller.c
deleted file mode 100644
index 3120a4267..000000000
--- a/1.2-netsec/apps/app_zapateller.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Playback the special information tone to get rid of telemarketers
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-
-static char *tdesc = "Block Telemarketers with Special Information Tone";
-
-static char *app = "Zapateller";
-
-static char *synopsis = "Block telemarketers with SIT";
-
-static char *descrip =
-" Zapateller(options): Generates special information tone to block\n"
-"telemarketers from calling you. Options is a pipe-delimited list of\n"
-"options. The following options are available:\n"
-"'answer' causes the line to be answered before playing the tone,\n"
-"'nocallerid' causes Zapateller to only play the tone if there\n"
-"is no callerid information available. Options should be separated by |\n"
-"characters\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static int zapateller_exec(struct ast_channel *chan, void *data)
-{
- int res = 0;
- struct localuser *u;
- int answer = 0, nocallerid = 0;
- char *c;
- char *stringp=NULL;
-
- LOCAL_USER_ADD(u);
-
- stringp=data;
- c = strsep(&stringp, "|");
- while(!ast_strlen_zero(c)) {
- if (!strcasecmp(c, "answer"))
- answer = 1;
- else if (!strcasecmp(c, "nocallerid"))
- nocallerid = 1;
-
- c = strsep(&stringp, "|");
- }
-
- ast_stopstream(chan);
- if (chan->_state != AST_STATE_UP) {
-
- if (answer)
- res = ast_answer(chan);
- if (!res) {
- res = ast_safe_sleep(chan, 500);
- }
- }
- if (chan->cid.cid_num && nocallerid) {
- LOCAL_USER_REMOVE(u);
- return res;
- }
- if (!res)
- res = ast_tonepair(chan, 950, 0, 330, 0);
- if (!res)
- res = ast_tonepair(chan, 1400, 0, 330, 0);
- if (!res)
- res = ast_tonepair(chan, 1800, 0, 330, 0);
- if (!res)
- res = ast_tonepair(chan, 0, 0, 1000, 0);
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, zapateller_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_zapbarge.c b/1.2-netsec/apps/app_zapbarge.c
deleted file mode 100644
index 10c5c49e5..000000000
--- a/1.2-netsec/apps/app_zapbarge.c
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Special thanks to comphealth.com for sponsoring this
- * GPL application.
- *
- * 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 Zap Barge support
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-
-#ifdef __linux__
-#include <linux/zaptel.h>
-#else
-#include <zaptel.h>
-#endif /* __linux__ */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/app.h"
-#include "asterisk/options.h"
-#include "asterisk/cli.h"
-#include "asterisk/say.h"
-#include "asterisk/utils.h"
-
-static char *tdesc = "Barge in on Zap channel application";
-
-static char *app = "ZapBarge";
-
-static char *synopsis = "Barge in (monitor) Zap channel";
-
-static char *descrip =
-" ZapBarge([channel]): Barges in on a specified zap\n"
-"channel or prompts if one is not specified. Returns\n"
-"-1 when caller user hangs up and is independent of the\n"
-"state of the channel being monitored.";
-
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-
-#define CONF_SIZE 160
-
-static int careful_write(int fd, unsigned char *data, int len)
-{
- int res;
- while(len) {
- res = write(fd, data, len);
- if (res < 1) {
- if (errno != EAGAIN) {
- ast_log(LOG_WARNING, "Failed to write audio data to conference: %s\n", strerror(errno));
- return -1;
- } else
- return 0;
- }
- len -= res;
- data += res;
- }
- return 0;
-}
-
-static int conf_run(struct ast_channel *chan, int confno, int confflags)
-{
- int fd;
- struct zt_confinfo ztc;
- struct ast_frame *f;
- struct ast_channel *c;
- struct ast_frame fr;
- int outfd;
- int ms;
- int nfds;
- int res;
- int flags;
- int retryzap;
- int origfd;
- int ret = -1;
-
- ZT_BUFFERINFO bi;
- char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
- char *buf = __buf + AST_FRIENDLY_OFFSET;
-
- /* Set it into U-law mode (write) */
- if (ast_set_write_format(chan, AST_FORMAT_ULAW) < 0) {
- ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", chan->name);
- goto outrun;
- }
-
- /* Set it into U-law mode (read) */
- if (ast_set_read_format(chan, AST_FORMAT_ULAW) < 0) {
- ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", chan->name);
- goto outrun;
- }
- ast_indicate(chan, -1);
- retryzap = strcasecmp(chan->type, "Zap");
-zapretry:
- origfd = chan->fds[0];
- if (retryzap) {
- fd = open("/dev/zap/pseudo", O_RDWR);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
- goto outrun;
- }
- /* Make non-blocking */
- flags = fcntl(fd, F_GETFL);
- if (flags < 0) {
- ast_log(LOG_WARNING, "Unable to get flags: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
- ast_log(LOG_WARNING, "Unable to set flags: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- /* Setup buffering information */
- memset(&bi, 0, sizeof(bi));
- bi.bufsize = CONF_SIZE;
- bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.numbufs = 4;
- if (ioctl(fd, ZT_SET_BUFINFO, &bi)) {
- ast_log(LOG_WARNING, "Unable to set buffering information: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- nfds = 1;
- } else {
- /* XXX Make sure we're not running on a pseudo channel XXX */
- fd = chan->fds[0];
- nfds = 0;
- }
- memset(&ztc, 0, sizeof(ztc));
- /* Check to see if we're in a conference... */
- ztc.chan = 0;
- if (ioctl(fd, ZT_GETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error getting conference\n");
- close(fd);
- goto outrun;
- }
- if (ztc.confmode) {
- /* Whoa, already in a conference... Retry... */
- if (!retryzap) {
- ast_log(LOG_DEBUG, "Zap channel is in a conference already, retrying with pseudo\n");
- retryzap = 1;
- goto zapretry;
- }
- }
- memset(&ztc, 0, sizeof(ztc));
- /* Add us to the conference */
- ztc.chan = 0;
- ztc.confno = confno;
- ztc.confmode = ZT_CONF_MONITORBOTH;
-
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- goto outrun;
- }
- ast_log(LOG_DEBUG, "Placed channel %s in ZAP channel %d monitor\n", chan->name, confno);
-
- for(;;) {
- outfd = -1;
- ms = -1;
- c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
- if (c) {
- if (c->fds[0] != origfd) {
- if (retryzap) {
- /* Kill old pseudo */
- close(fd);
- }
- ast_log(LOG_DEBUG, "Ooh, something swapped out under us, starting over\n");
- retryzap = 0;
- goto zapretry;
- }
- f = ast_read(c);
- if (!f)
- break;
- if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) {
- ret = 0;
- break;
- } else if (fd != chan->fds[0]) {
- if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass == AST_FORMAT_ULAW) {
- /* Carefully write */
- careful_write(fd, f->data, f->datalen);
- } else
- ast_log(LOG_WARNING, "Huh? Got a non-ulaw (%d) frame in the conference\n", f->subclass);
- }
- }
- ast_frfree(f);
- } else if (outfd > -1) {
- res = read(outfd, buf, CONF_SIZE);
- if (res > 0) {
- memset(&fr, 0, sizeof(fr));
- fr.frametype = AST_FRAME_VOICE;
- fr.subclass = AST_FORMAT_ULAW;
- fr.datalen = res;
- fr.samples = res;
- fr.data = buf;
- fr.offset = AST_FRIENDLY_OFFSET;
- if (ast_write(chan, &fr) < 0) {
- ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
- /* break; */
- }
- } else
- ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
- }
- }
- if (fd != chan->fds[0])
- close(fd);
- else {
- /* Take out of conference */
- /* Add us to the conference */
- ztc.chan = 0;
- ztc.confno = 0;
- ztc.confmode = 0;
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- }
- }
-
-outrun:
-
- return ret;
-}
-
-static int conf_exec(struct ast_channel *chan, void *data)
-{
- int res=-1;
- struct localuser *u;
- int retrycnt = 0;
- int confflags = 0;
- int confno = 0;
- char confstr[80] = "";
-
- LOCAL_USER_ADD(u);
-
- if (!ast_strlen_zero(data)) {
- if ((sscanf(data, "Zap/%d", &confno) != 1) &&
- (sscanf(data, "%d", &confno) != 1)) {
- ast_log(LOG_WARNING, "ZapBarge Argument (if specified) must be a channel number, not '%s'\n", (char *)data);
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- }
-
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
-
- while(!confno && (++retrycnt < 4)) {
- /* Prompt user for conference number */
- confstr[0] = '\0';
- res = ast_app_getdata(chan, "conf-getchannel",confstr, sizeof(confstr) - 1, 0);
- if (res <0) goto out;
- if (sscanf(confstr, "%d", &confno) != 1)
- confno = 0;
- }
- if (confno) {
- /* XXX Should prompt user for pin if pin is required XXX */
- /* Run the conference */
- res = conf_run(chan, confno, confflags);
- }
-out:
- /* Do the conference */
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, conf_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_zapras.c b/1.2-netsec/apps/app_zapras.c
deleted file mode 100644
index 4a94f34ba..000000000
--- a/1.2-netsec/apps/app_zapras.c
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Execute an ISDN RAS
- *
- * \ingroup applications
- */
-
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#ifdef __linux__
-#include <sys/signal.h>
-#else
-#include <signal.h>
-#endif /* __linux__ */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <stdio.h>
-#include <fcntl.h>
-
-/* Need some zaptel help here */
-#ifdef __linux__
-#include <linux/zaptel.h>
-#else
-#include <zaptel.h>
-#endif /* __linux__ */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-
-static char *tdesc = "Zap RAS Application";
-
-static char *app = "ZapRAS";
-
-static char *synopsis = "Executes Zaptel ISDN RAS application";
-
-static char *descrip =
-" ZapRAS(args): Executes a RAS server using pppd on the given channel.\n"
-"The channel must be a clear channel (i.e. PRI source) and a Zaptel\n"
-"channel to be able to use this function (No modem emulation is included).\n"
-"Your pppd must be patched to be zaptel aware. Arguments should be\n"
-"separated by | characters.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-#define PPP_MAX_ARGS 32
-#define PPP_EXEC "/usr/sbin/pppd"
-
-static pid_t spawn_ras(struct ast_channel *chan, char *args)
-{
- pid_t pid;
- int x;
- char *c;
-
- char *argv[PPP_MAX_ARGS];
- int argc = 0;
- char *stringp=NULL;
-
- /* Start by forking */
- pid = fork();
- if (pid)
- return pid;
-
- /* Execute RAS on File handles */
- dup2(chan->fds[0], STDIN_FILENO);
-
- /* Close other file descriptors */
- for (x=STDERR_FILENO + 1;x<1024;x++)
- close(x);
-
- /* Restore original signal handlers */
- for (x=0;x<NSIG;x++)
- signal(x, SIG_DFL);
-
- /* Reset all arguments */
- memset(argv, 0, sizeof(argv));
-
- /* First argument is executable, followed by standard
- arguments for zaptel PPP */
- argv[argc++] = PPP_EXEC;
- argv[argc++] = "nodetach";
-
- /* And all the other arguments */
- stringp=args;
- c = strsep(&stringp, "|");
- while(c && strlen(c) && (argc < (PPP_MAX_ARGS - 4))) {
- argv[argc++] = c;
- c = strsep(&stringp, "|");
- }
-
- argv[argc++] = "plugin";
- argv[argc++] = "zaptel.so";
- argv[argc++] = "stdin";
-
-#if 0
- for (x=0;x<argc;x++) {
- fprintf(stderr, "Arg %d: %s\n", x, argv[x]);
- }
-#endif
-
- /* Finally launch PPP */
- execv(PPP_EXEC, argv);
- fprintf(stderr, "Failed to exec PPPD!\n");
- exit(1);
-}
-
-static void run_ras(struct ast_channel *chan, char *args)
-{
- pid_t pid;
- int status;
- int res;
- int signalled = 0;
- struct zt_bufferinfo savebi;
- int x;
-
- res = ioctl(chan->fds[0], ZT_GET_BUFINFO, &savebi);
- if(res) {
- ast_log(LOG_WARNING, "Unable to check buffer policy on channel %s\n", chan->name);
- return;
- }
-
- pid = spawn_ras(chan, args);
- if (pid < 0) {
- ast_log(LOG_WARNING, "Failed to spawn RAS\n");
- } else {
- for (;;) {
- res = wait4(pid, &status, WNOHANG, NULL);
- if (!res) {
- /* Check for hangup */
- if (chan->_softhangup && !signalled) {
- ast_log(LOG_DEBUG, "Channel '%s' hungup. Signalling RAS at %d to die...\n", chan->name, pid);
- kill(pid, SIGTERM);
- signalled=1;
- }
- /* Try again */
- sleep(1);
- continue;
- }
- if (res < 0) {
- ast_log(LOG_WARNING, "wait4 returned %d: %s\n", res, strerror(errno));
- }
- if (option_verbose > 2) {
- if (WIFEXITED(status)) {
- ast_verbose(VERBOSE_PREFIX_3 "RAS on %s terminated with status %d\n", chan->name, WEXITSTATUS(status));
- } else if (WIFSIGNALED(status)) {
- ast_verbose(VERBOSE_PREFIX_3 "RAS on %s terminated with signal %d\n",
- chan->name, WTERMSIG(status));
- } else {
- ast_verbose(VERBOSE_PREFIX_3 "RAS on %s terminated weirdly.\n", chan->name);
- }
- }
- /* Throw back into audio mode */
- x = 1;
- ioctl(chan->fds[0], ZT_AUDIOMODE, &x);
-
- /* Restore saved values */
- res = ioctl(chan->fds[0], ZT_SET_BUFINFO, &savebi);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set buffer policy on channel %s\n", chan->name);
- }
- break;
- }
- }
-}
-
-static int zapras_exec(struct ast_channel *chan, void *data)
-{
- int res=-1;
- char *args;
- struct localuser *u;
- ZT_PARAMS ztp;
-
- if (!data)
- data = "";
-
- LOCAL_USER_ADD(u);
-
- args = ast_strdupa(data);
- if (!args) {
- ast_log(LOG_ERROR, "Out of memory\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- /* Answer the channel if it's not up */
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
- if (strcasecmp(chan->type, "Zap")) {
- /* If it's not a zap channel, we're done. Wait a couple of
- seconds and then hangup... */
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Channel %s is not a Zap channel\n", chan->name);
- sleep(2);
- } else {
- memset(&ztp, 0, sizeof(ztp));
- if (ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp)) {
- ast_log(LOG_WARNING, "Unable to get zaptel parameters\n");
- } else if (ztp.sigtype != ZT_SIG_CLEAR) {
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Channel %s is not a clear channel\n", chan->name);
- } else {
- /* Everything should be okay. Run PPP. */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Starting RAS on %s\n", chan->name);
- /* Execute RAS */
- run_ras(chan, args);
- }
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, zapras_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/apps/app_zapscan.c b/1.2-netsec/apps/app_zapscan.c
deleted file mode 100644
index ed0c77977..000000000
--- a/1.2-netsec/apps/app_zapscan.c
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Modified from app_zapbarge by David Troy <dave@toad.net>
- *
- * Special thanks to comphealth.com for sponsoring this
- * GPL application.
- *
- * 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 Zap Scanner
- *
- * \ingroup applications
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-
-#ifdef __linux__
-#include <linux/zaptel.h>
-#else
-#include <zaptel.h>
-#endif /* __linux__ */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/app.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-#include "asterisk/cli.h"
-#include "asterisk/say.h"
-
-static char *tdesc = "Scan Zap channels application";
-
-static char *app = "ZapScan";
-
-static char *synopsis = "Scan Zap channels to monitor calls";
-
-static char *descrip =
-" ZapScan([group]) allows a call center manager to monitor Zap channels in\n"
-"a convenient way. Use '#' to select the next channel and use '*' to exit\n"
-"Limit scanning to a channel GROUP by setting the option group argument.\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-
-#define CONF_SIZE 160
-
-static struct ast_channel *get_zap_channel_locked(int num) {
- char name[80];
-
- snprintf(name,sizeof(name),"Zap/%d-1",num);
- return ast_get_channel_by_name_locked(name);
-}
-
-static int careful_write(int fd, unsigned char *data, int len)
-{
- int res;
- while(len) {
- res = write(fd, data, len);
- if (res < 1) {
- if (errno != EAGAIN) {
- ast_log(LOG_WARNING, "Failed to write audio data to conference: %s\n", strerror(errno));
- return -1;
- } else
- return 0;
- }
- len -= res;
- data += res;
- }
- return 0;
-}
-
-static int conf_run(struct ast_channel *chan, int confno, int confflags)
-{
- int fd;
- struct zt_confinfo ztc;
- struct ast_frame *f;
- struct ast_channel *c;
- struct ast_frame fr;
- int outfd;
- int ms;
- int nfds;
- int res;
- int flags;
- int retryzap;
- int origfd;
- int ret = -1;
- char input[4];
- int ic=0;
-
- ZT_BUFFERINFO bi;
- char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
- char *buf = __buf + AST_FRIENDLY_OFFSET;
-
- /* Set it into U-law mode (write) */
- if (ast_set_write_format(chan, AST_FORMAT_ULAW) < 0) {
- ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", chan->name);
- goto outrun;
- }
-
- /* Set it into U-law mode (read) */
- if (ast_set_read_format(chan, AST_FORMAT_ULAW) < 0) {
- ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", chan->name);
- goto outrun;
- }
- ast_indicate(chan, -1);
- retryzap = strcasecmp(chan->type, "Zap");
- zapretry:
- origfd = chan->fds[0];
- if (retryzap) {
- fd = open("/dev/zap/pseudo", O_RDWR);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
- goto outrun;
- }
- /* Make non-blocking */
- flags = fcntl(fd, F_GETFL);
- if (flags < 0) {
- ast_log(LOG_WARNING, "Unable to get flags: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
- ast_log(LOG_WARNING, "Unable to set flags: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- /* Setup buffering information */
- memset(&bi, 0, sizeof(bi));
- bi.bufsize = CONF_SIZE;
- bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.numbufs = 4;
- if (ioctl(fd, ZT_SET_BUFINFO, &bi)) {
- ast_log(LOG_WARNING, "Unable to set buffering information: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- nfds = 1;
- } else {
- /* XXX Make sure we're not running on a pseudo channel XXX */
- fd = chan->fds[0];
- nfds = 0;
- }
- memset(&ztc, 0, sizeof(ztc));
- /* Check to see if we're in a conference... */
- ztc.chan = 0;
- if (ioctl(fd, ZT_GETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error getting conference\n");
- close(fd);
- goto outrun;
- }
- if (ztc.confmode) {
- /* Whoa, already in a conference... Retry... */
- if (!retryzap) {
- ast_log(LOG_DEBUG, "Zap channel is in a conference already, retrying with pseudo\n");
- retryzap = 1;
- goto zapretry;
- }
- }
- memset(&ztc, 0, sizeof(ztc));
- /* Add us to the conference */
- ztc.chan = 0;
- ztc.confno = confno;
- ztc.confmode = ZT_CONF_MONITORBOTH;
-
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- goto outrun;
- }
- ast_log(LOG_DEBUG, "Placed channel %s in ZAP channel %d monitor\n", chan->name, confno);
-
- for(;;) {
- outfd = -1;
- ms = -1;
- c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
- if (c) {
- if (c->fds[0] != origfd) {
- if (retryzap) {
- /* Kill old pseudo */
- close(fd);
- }
- ast_log(LOG_DEBUG, "Ooh, something swapped out under us, starting over\n");
- retryzap = 0;
- goto zapretry;
- }
- f = ast_read(c);
- if (!f)
- break;
- if(f->frametype == AST_FRAME_DTMF) {
- if(f->subclass == '#') {
- ret = 0;
- break;
- }
- else if (f->subclass == '*') {
- ret = -1;
- break;
-
- }
- else {
- input[ic++] = f->subclass;
- }
- if(ic == 3) {
- input[ic++] = '\0';
- ic=0;
- ret = atoi(input);
- ast_verbose(VERBOSE_PREFIX_3 "Zapscan: change channel to %d\n",ret);
- break;
- }
- }
-
- if (fd != chan->fds[0]) {
- if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass == AST_FORMAT_ULAW) {
- /* Carefully write */
- careful_write(fd, f->data, f->datalen);
- } else
- ast_log(LOG_WARNING, "Huh? Got a non-ulaw (%d) frame in the conference\n", f->subclass);
- }
- }
- ast_frfree(f);
- } else if (outfd > -1) {
- res = read(outfd, buf, CONF_SIZE);
- if (res > 0) {
- memset(&fr, 0, sizeof(fr));
- fr.frametype = AST_FRAME_VOICE;
- fr.subclass = AST_FORMAT_ULAW;
- fr.datalen = res;
- fr.samples = res;
- fr.data = buf;
- fr.offset = AST_FRIENDLY_OFFSET;
- if (ast_write(chan, &fr) < 0) {
- ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
- /* break; */
- }
- } else
- ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
- }
- }
- if (fd != chan->fds[0])
- close(fd);
- else {
- /* Take out of conference */
- /* Add us to the conference */
- ztc.chan = 0;
- ztc.confno = 0;
- ztc.confmode = 0;
- if (ioctl(fd, ZT_SETCONF, &ztc)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- }
- }
-
- outrun:
-
- return ret;
-}
-
-static int conf_exec(struct ast_channel *chan, void *data)
-{
- int res=-1;
- struct localuser *u;
- int confflags = 0;
- int confno = 0;
- char confstr[80] = "", *tmp = NULL;
- struct ast_channel *tempchan = NULL, *lastchan = NULL,*ichan = NULL;
- struct ast_frame *f;
- char *mygroup;
- char *desired_group;
- int input=0,search_group=0;
-
- LOCAL_USER_ADD(u);
-
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
-
- desired_group = ast_strdupa((char *) data);
- if(!ast_strlen_zero(desired_group)) {
- ast_verbose(VERBOSE_PREFIX_3 "Scanning for group %s\n", desired_group);
- search_group = 1;
- }
-
- for (;;) {
- if (ast_waitfor(chan, 100) < 0)
- break;
-
- f = ast_read(chan);
- if (!f)
- break;
- if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '*')) {
- ast_frfree(f);
- break;
- }
- ast_frfree(f);
- ichan = NULL;
- if(input) {
- ichan = get_zap_channel_locked(input);
- input = 0;
- }
-
- tempchan = ichan ? ichan : ast_channel_walk_locked(tempchan);
-
- if ( !tempchan && !lastchan )
- break;
-
- if (tempchan && search_group) {
- if((mygroup = pbx_builtin_getvar_helper(tempchan, "GROUP")) && (!strcmp(mygroup, desired_group))) {
- ast_verbose(VERBOSE_PREFIX_3 "Found Matching Channel %s in group %s\n", tempchan->name, desired_group);
- } else {
- ast_mutex_unlock(&tempchan->lock);
- lastchan = tempchan;
- continue;
- }
- }
- if ( tempchan && tempchan->type && (!strcmp(tempchan->type, "Zap")) && (tempchan != chan) ) {
- ast_verbose(VERBOSE_PREFIX_3 "Zap channel %s is in-use, monitoring...\n", tempchan->name);
- ast_copy_string(confstr, tempchan->name, sizeof(confstr));
- ast_mutex_unlock(&tempchan->lock);
- if ((tmp = strchr(confstr,'-'))) {
- *tmp = '\0';
- }
- confno = atoi(strchr(confstr,'/') + 1);
- ast_stopstream(chan);
- ast_say_number(chan, confno, AST_DIGIT_ANY, chan->language, (char *) NULL);
- res = conf_run(chan, confno, confflags);
- if (res<0) break;
- input = res;
- } else if (tempchan)
- ast_mutex_unlock(&tempchan->lock);
- lastchan = tempchan;
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-int unload_module(void)
-{
- int res;
-
- res = ast_unregister_application(app);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return res;
-}
-
-int load_module(void)
-{
- return ast_register_application(app, conf_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/apps/enter.h b/1.2-netsec/apps/enter.h
deleted file mode 100644
index ac765984a..000000000
--- a/1.2-netsec/apps/enter.h
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * U-law 8-bit audio data
- *
- * Source: enter.raw
- *
- * Copyright (C) 1999, Mark Spencer and Linux Support Services
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char enter[] = {
-0xba, 0xba, 0xb0, 0xa6, 0xa9, 0xb8, 0xfe, 0x46, 0x42, 0x46,
-0x4a, 0xfe, 0xac, 0xa2, 0x9f, 0x9f, 0xa8, 0xb8, 0x3b, 0x29,
-0x35, 0x4a, 0xfe, 0xc1, 0xad, 0xa2, 0xad, 0xc5, 0x4e, 0x68,
-0x68, 0xe7, 0xb8, 0xb0, 0xb2, 0xc1, 0xc1, 0xb0, 0xae, 0xcd,
-0xfe, 0xfe, 0xcd, 0xcd, 0xfe, 0x68, 0xd3, 0xb2, 0xae, 0xab,
-0xb2, 0xfe, 0x35, 0x31, 0xdb, 0xac, 0xab, 0xaf, 0xab, 0xaa,
-0xb4, 0x68, 0x3b, 0x39, 0x3f, 0x68, 0xb4, 0xa8, 0xa8, 0xb0,
-0xbc, 0xbc, 0xc5, 0x3f, 0x31, 0x37, 0xfe, 0xc1, 0xbc, 0xb0,
-0xa5, 0xa2, 0xa8, 0xaf, 0xbe, 0x3b, 0x28, 0x26, 0x3d, 0xbc,
-0xb0, 0xae, 0xa2, 0x9f, 0xa2, 0xfe, 0x29, 0x24, 0x29, 0x4a,
-0xc5, 0xaa, 0xa8, 0xa9, 0xa8, 0xa5, 0xa7, 0xdb, 0x2c, 0x27,
-0x2d, 0x4a, 0xfe, 0xdb, 0xb2, 0xa2, 0x9f, 0x9f, 0xae, 0xe7,
-0x2c, 0x22, 0x2b, 0xfe, 0xba, 0xb0, 0xaa, 0x9f, 0xa3, 0xb0,
-0x5c, 0x33, 0x33, 0x39, 0x5c, 0xdb, 0xc1, 0xb4, 0xb0, 0xaa,
-0xad, 0xba, 0x54, 0x46, 0xfe, 0xe7, 0xfe, 0x54, 0xe7, 0xaf,
-0xa6, 0xa7, 0xb0, 0xfe, 0x46, 0x39, 0x5c, 0xe7, 0xdb, 0xfe,
-0xba, 0xac, 0xa8, 0xc5, 0x46, 0x33, 0x54, 0xc5, 0xae, 0xad,
-0xb2, 0xc1, 0xcd, 0xc1, 0xbc, 0xfe, 0x3f, 0x37, 0xfe, 0xb4,
-0xb6, 0xcd, 0xdb, 0xc1, 0xb0, 0xb6, 0xcd, 0x4e, 0x39, 0x37,
-0xfe, 0xb0, 0xab, 0xa9, 0xa9, 0xa9, 0xb0, 0x5c, 0x29, 0x25,
-0x31, 0xfe, 0xc1, 0xb4, 0xae, 0xab, 0xab, 0xb2, 0xcd, 0x3b,
-0x2a, 0x2c, 0x54, 0xb4, 0xb4, 0xba, 0xb2, 0xa3, 0x9f, 0xa8,
-0xfe, 0x33, 0x27, 0x2a, 0x39, 0xfe, 0xc1, 0xbe, 0xb0, 0xa2,
-0x9f, 0xb0, 0x33, 0x22, 0x25, 0x46, 0xc1, 0xb8, 0xb0, 0xab,
-0xa8, 0xa8, 0xb0, 0xbe, 0x42, 0x2c, 0x2e, 0x4a, 0xfe, 0x5c,
-0xfe, 0xb4, 0xa8, 0xa8, 0xba, 0xfe, 0x4a, 0x39, 0x39, 0x46,
-0xfe, 0xbc, 0xaf, 0xa5, 0xa5, 0xae, 0x68, 0x37, 0x4a, 0xfe,
-0xfe, 0x4a, 0x4a, 0xd3, 0xb0, 0xb0, 0xc1, 0x5c, 0x46, 0x46,
-0xd3, 0xb6, 0xbe, 0x54, 0x54, 0xc9, 0xab, 0xae, 0xc5, 0x46,
-0x4a, 0xfe, 0xcd, 0xc9, 0xcd, 0xe7, 0xe7, 0xc9, 0xb4, 0xc5,
-0x4a, 0x2c, 0x37, 0xc1, 0xb0, 0xb2, 0xb4, 0xb2, 0xb6, 0xdb,
-0xfe, 0x4a, 0x46, 0x3f, 0x68, 0xba, 0xb2, 0xba, 0xc5, 0xb6,
-0xb2, 0xcd, 0x33, 0x2e, 0x39, 0x68, 0xfe, 0xe7, 0xba, 0xaf,
-0xa7, 0xa7, 0xad, 0xe7, 0x2d, 0x25, 0x2f, 0xd3, 0xbe, 0xcd,
-0xc5, 0xac, 0xa6, 0xac, 0xfe, 0x3b, 0x2c, 0x2d, 0x3d, 0xc1,
-0xb4, 0xbe, 0xcd, 0xaf, 0xa5, 0xa8, 0xe7, 0x31, 0x2f, 0x39,
-0x46, 0x5c, 0xdb, 0xbc, 0xba, 0xaf, 0xa9, 0xad, 0xfe, 0x2f,
-0x2d, 0xba, 0xad, 0xba, 0xfe, 0x3d, 0x42, 0x5c, 0xc9, 0xc1,
-0xcd, 0xfe, 0xc1, 0xae, 0xa6, 0xcd, 0x33, 0x25, 0x3b, 0xdb,
-0xb0, 0xb6, 0xb8, 0xb6, 0xb4, 0xb8, 0xba, 0xfe, 0x3d, 0x37,
-0xfe, 0xba, 0xc1, 0x54, 0x54, 0xd3, 0xb0, 0xb4, 0xe7, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xd3, 0xb6, 0xa9, 0xa7, 0xba,
-0x3d, 0x35, 0xfe, 0xc1, 0xcd, 0x4a, 0x54, 0xbe, 0xb2, 0xb8,
-0xfe, 0x46, 0x3b, 0xfe, 0xba, 0xab, 0xc5, 0x46, 0x3b, 0xbc,
-0xaa, 0xab, 0xd3, 0x68, 0xfe, 0xd3, 0xcd, 0xdb, 0x54, 0x3d,
-0x4a, 0xbc, 0xac, 0xb4, 0x3f, 0x2e, 0x3d, 0xba, 0xb0, 0xb8,
-0xba, 0xb6, 0xba, 0xcd, 0xfe, 0xfe, 0x5c, 0x54, 0xc9, 0xb4,
-0xbe, 0x54, 0x54, 0xcd, 0xb6, 0xc9, 0x46, 0x54, 0xcd, 0xc5,
-0xdb, 0xfe, 0xfe, 0xc1, 0xae, 0xa9, 0xac, 0xfe, 0x35, 0x2e,
-0xfe, 0xba, 0xc1, 0x5c, 0xfe, 0xb6, 0xaa, 0xb0, 0xe7, 0x35,
-0x2e, 0x39, 0xc1, 0xac, 0xb0, 0xfe, 0xfe, 0xbc, 0xa6, 0xac,
-0xc1, 0x42, 0x46, 0x54, 0xfe, 0xfe, 0xfe, 0xfe, 0xc9, 0xae,
-0xa9, 0xb0, 0x54, 0x35, 0x37, 0xfe, 0xd3, 0xd3, 0xb8, 0xae,
-0xab, 0xb6, 0xe7, 0xfe, 0xfe, 0x68, 0xfe, 0xfe, 0xfe, 0x4e,
-0xfe, 0xb0, 0xac, 0xb8, 0xfe, 0xfe, 0xc1, 0xb6, 0xc5, 0x46,
-0x3d, 0xe7, 0xb4, 0xa7, 0xab, 0xbc, 0x3f, 0x37, 0x54, 0xba,
-0xcd, 0x54, 0x42, 0xc5, 0xae, 0xac, 0xc9, 0x46, 0x3d, 0x54,
-0xba, 0xb0, 0xb0, 0xfe, 0x5c, 0xcd, 0xb0, 0xb0, 0xc9, 0x54,
-0x54, 0xfe, 0xfe, 0xfe, 0xfe, 0xe7, 0xcd, 0xc1, 0xba, 0xc5,
-0xfe, 0x42, 0x46, 0xfe, 0xc5, 0xba, 0xb2, 0xa7, 0xa7, 0xb0,
-0xfe, 0x3d, 0x4a, 0x5c, 0xfe, 0xfe, 0xfe, 0xe7, 0xbc, 0xb0,
-0xae, 0xc5, 0x4e, 0x39, 0xfe, 0xc5, 0xbe, 0xfe, 0x54, 0xc9,
-0xa9, 0xa2, 0xa5, 0xbc, 0x3b, 0x2f, 0x35, 0xfe, 0xc9, 0xfe,
-0xfe, 0xc5, 0xa9, 0xa6, 0xb0, 0x54, 0x31, 0x31, 0x3f, 0xd3,
-0xbc, 0xc1, 0xcd, 0xb8, 0xae, 0xa8, 0xb4, 0xd3, 0x54, 0x4e,
-0x5c, 0x54, 0xfe, 0xdb, 0xba, 0xb4, 0xb4, 0xba, 0xcd, 0x5c,
-0x3d, 0x3f, 0x54, 0xfe, 0xcd, 0xaf, 0xa8, 0xac, 0xc5, 0xfe,
-0xfe, 0xe7, 0xdb, 0xfe, 0xfe, 0xfe, 0xe7, 0xb8, 0xaf, 0xb0,
-0xe7, 0x42, 0x4a, 0xcd, 0xbc, 0xdb, 0x46, 0x68, 0xcd, 0xb0,
-0xab, 0xbc, 0xfe, 0x3d, 0x46, 0xfe, 0xb8, 0xbc, 0xd3, 0xd3,
-0xb6, 0xb0, 0xb6, 0x5c, 0x3b, 0x35, 0x54, 0xdb, 0xba, 0xb4,
-0xc1, 0xc9, 0xc1, 0xba, 0xc9, 0x5c, 0x3d, 0x46, 0xfe, 0xcd,
-0xc5, 0xb8, 0xae, 0xaf, 0xb4, 0xd3, 0x54, 0x3d, 0x35, 0x46,
-0xfe, 0xdb, 0xbc, 0xb2, 0xa9, 0xab, 0xba, 0x3f, 0x31, 0x39,
-0xfe, 0xe7, 0xdb, 0xcd, 0xb8, 0xae, 0xab, 0xac, 0xe7, 0x3d,
-0x2d, 0x3f, 0xfe, 0xdb, 0xfe, 0xfe, 0xbc, 0xaa, 0xa8, 0xb0,
-0xfe, 0x31, 0x2d, 0x3d, 0xdb, 0xc5, 0xcd, 0xc9, 0xb4, 0xa8,
-0xad, 0xc5, 0x46, 0x39, 0x3f, 0x5c, 0xfe, 0xd3, 0xc5, 0xc1,
-0xb6, 0xb0, 0xbc, 0x68, 0x46, 0x4e, 0xe7, 0xfe, 0x5c, 0xfe,
-0xc1, 0xaf, 0xb0, 0xb8, 0xe7, 0x5c, 0x5c, 0xfe, 0xe7, 0xfe,
-0xfe, 0xe7, 0xb0, 0xab, 0xb2, 0x4a, 0x37, 0x3f, 0xcd, 0xbe,
-0xc1, 0xe7, 0xe7, 0xd3, 0xb6, 0xb4, 0xc9, 0x3b, 0x33, 0x4a,
-0xba, 0xb4, 0xc5, 0xfe, 0xc9, 0xb6, 0xb4, 0xcd, 0xfe, 0x3b,
-0x3b, 0xfe, 0xc1, 0xb6, 0xc5, 0xc5, 0xb8, 0xb0, 0xba, 0x4a,
-0x31, 0x35, 0x68, 0xcd, 0xc5, 0xba, 0xb4, 0xb0, 0xb0, 0xba,
-0x5c, 0x35, 0x2f, 0x4e, 0xd3, 0xc1, 0xdb, 0xd3, 0xb4, 0xa9,
-0xab, 0xcd, 0x3b, 0x2f, 0x35, 0xfe, 0xd3, 0xd3, 0xdb, 0xbc,
-0xad, 0xa4, 0xb0, 0xfe, 0x2d, 0x2f, 0x3f, 0xe7, 0xe7, 0xe7,
-0xcd, 0xb4, 0xaf, 0xad, 0xc5, 0x3d, 0x31, 0x3d, 0xe7, 0xd3,
-0xe7, 0xe7, 0xc1, 0xaf, 0xad, 0xb6, 0xfe, 0x4a, 0x42, 0x54,
-0xfe, 0x68, 0xfe, 0xd3, 0xb2, 0xae, 0xb4, 0xfe, 0x42, 0x4e,
-0xcd, 0xc5, 0xcd, 0xdb, 0xc9, 0xb4, 0xb0, 0xb6, 0xfe, 0x3b,
-0x42, 0xe7, 0xb0, 0xb8, 0xcd, 0xfe, 0xc9, 0xb6, 0xb8, 0xfe,
-0x42, 0x3d, 0xfe, 0xc1, 0xb0, 0xba, 0xd3, 0xfe, 0xc1, 0xb0,
-0xb6, 0xfe, 0x3b, 0x3f, 0xe7, 0xba, 0xb8, 0xbc, 0xc5, 0xc1,
-0xc1, 0xcd, 0xfe, 0x3b, 0x37, 0xfe, 0xc1, 0xb4, 0xb6, 0xb8,
-0xb6, 0xb8, 0xc5, 0x5c, 0x3f, 0x46, 0xfe, 0xcd, 0xc5, 0xcd,
-0xcd, 0xc1, 0xb2, 0xb2, 0xfe, 0x3f, 0x35, 0x54, 0xdb, 0xc1,
-0xcd, 0xcd, 0xbc, 0xaf, 0xac, 0xb6, 0x54, 0x35, 0x31, 0x68,
-0xba, 0xb8, 0xcd, 0xdb, 0xc9, 0xb2, 0xb4, 0xc9, 0x46, 0x39,
-0x42, 0xdb, 0xbc, 0xbc, 0xcd, 0xcd, 0xbe, 0xb2, 0xb8, 0xe7,
-0x54, 0x46, 0xfe, 0xfe, 0xdb, 0xc9, 0xc5, 0xbe, 0xbe, 0xc9,
-0xfe, 0x5c, 0x5c, 0xfe, 0xd3, 0xcd, 0xcd, 0xc5, 0xb6, 0xb2,
-0xc5, 0x68, 0x4e, 0xfe, 0xc5, 0xc1, 0xcd, 0x68, 0x5c, 0xe7,
-0xb8, 0xb6, 0xd3, 0x4a, 0x46, 0xfe, 0xbc, 0xb8, 0xc1, 0xe7,
-0xe7, 0xc1, 0xb4, 0xbe, 0xfe, 0x3f, 0x3f, 0xfe, 0xba, 0xb2,
-0xba, 0xe7, 0xfe, 0xcd, 0xcd, 0xfe, 0x4e, 0x46, 0xfe, 0xc5,
-0xb8, 0xb2, 0xba, 0xc1, 0xcd, 0xd3, 0xe7, 0xfe, 0x5c, 0x5c,
-0xfe, 0xe7, 0xc5, 0xbe, 0xb6, 0xba, 0xc5, 0xfe, 0x3f, 0x3f,
-0x54, 0xfe, 0xd3, 0xc1, 0xbc, 0xb6, 0xb0, 0xb0, 0xd3, 0x54,
-0x39, 0x46, 0xfe, 0xc1, 0xcd, 0xe7, 0xe7, 0xc5, 0xb8, 0xb4,
-0xd3, 0x54, 0x37, 0x42, 0xdb, 0xbe, 0xc1, 0xd3, 0xcd, 0xb8,
-0xb0, 0xb0, 0xcd, 0x4a, 0x3b, 0x42, 0xe7, 0xc5, 0xbe, 0xcd,
-0xe7, 0xd3, 0xc5, 0xcd, 0xfe, 0x54, 0x54, 0x68, 0xe7, 0xc5,
-0xc1, 0xc1, 0xcd, 0xcd, 0xc9, 0xc9, 0xcd, 0xe7, 0xfe, 0xfe,
-0xfe, 0xe7, 0xc5, 0xbe, 0xc1, 0xfe, 0x5c, 0x5c, 0xfe, 0xcd,
-0xcd, 0xcd, 0xdb, 0xd3, 0xc1, 0xbc, 0xbe, 0xfe, 0x4e, 0x54,
-0xcd, 0xb6, 0xb8, 0xd3, 0x5c, 0x5c, 0xfe, 0xc5, 0xc9, 0xfe,
-0x46, 0x4a, 0xe7, 0xb4, 0xb6, 0xc5, 0xfe, 0xe7, 0xcd, 0xc9,
-0xdb, 0xfe, 0x4e, 0x68, 0xd3, 0xb6, 0xb2, 0xbc, 0xfe, 0x68,
-0xfe, 0xfe, 0x68, 0x54, 0x68, 0xe7, 0xc5, 0xbc, 0xb8, 0xbe,
-0xcd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xd3, 0xd3, 0xcd,
-0xc1, 0xb8, 0xbc, 0xdb, 0x4e, 0x42, 0x4a, 0xfe, 0xc9, 0xc1,
-0xcd, 0xd3, 0xcd, 0xba, 0xb8, 0xcd, 0x46, 0x3b, 0xfe, 0xc9,
-0xba, 0xcd, 0xe7, 0xfe, 0xd3, 0xc1, 0xba, 0xdb, 0x54, 0x3d,
-0x68, 0xd3, 0xbc, 0xcd, 0xfe, 0xfe, 0xc5, 0xbe, 0xc1, 0xe7,
-0x54, 0x4a, 0xfe, 0xc9, 0xc1, 0xcd, 0xfe, 0xfe, 0xd3, 0xd3,
-0xd3, 0xfe, 0xe7, 0xe7, 0xe7, 0xdb, 0xd3, 0xe7, 0xe7, 0xe7,
-0xfe, 0xfe, 0xfe, 0xfe, 0xcd, 0xc9, 0xdb, 0xfe, 0xfe, 0xdb,
-0xbe, 0xc9, 0xfe, 0x5c, 0xfe, 0xc9, 0xbc, 0xbe, 0xdb, 0x68,
-0x5c, 0xdb, 0xc5, 0xd3, 0x54, 0x46, 0xfe, 0xbc, 0xb2, 0xb8,
-0xdb, 0x68, 0x68, 0xe7, 0xcd, 0xdb, 0x5c, 0x54, 0xfe, 0xc1,
-0xb8, 0xc1, 0xe7, 0xfe, 0xfe, 0xe7, 0xe7, 0xfe, 0xfe, 0xfe,
-0xd3, 0xc5, 0xc1, 0xc5, 0xcd, 0xd3, 0xe7, 0xfe, 0x54, 0x4e,
-0xfe, 0xd3, 0xcd, 0xd3, 0xd3, 0xc5, 0xc1, 0xc1, 0xe7, 0x5c,
-0x4e, 0x5c, 0xd3, 0xc1, 0xcd, 0xfe, 0xfe, 0xcd, 0xba, 0xba,
-0xe7, 0x4a, 0x4a, 0x68, 0xcd, 0xc5, 0xcd, 0xfe, 0xfe, 0xcd,
-0xb8, 0xc1, 0xe7, 0x4e, 0x5c, 0xe7, 0xc1, 0xc9, 0xdb, 0xfe,
-0xe7, 0xc9, 0xc5, 0xd3, 0xfe, 0x68, 0xfe, 0xdb, 0xd3, 0xe7,
-0xfe, 0xfe, 0xcd, 0xc9, 0xcd, 0xd3, 0xd3, 0xd3, 0xcd, 0xe7,
-0xfe, 0xfe, 0xe7, 0xc5, 0xc5, 0xe7, 0x68, 0x68, 0xe7, 0xc1,
-0xc5, 0xfe, 0x5c, 0xfe, 0xd3, 0xc1, 0xd3, 0xfe, 0x68, 0xe7,
-0xc5, 0xb6, 0xc5, 0xe7, 0x68, 0xfe, 0xcd, 0xc5, 0xe7, 0xfe,
-0x54, 0xfe, 0xc9, 0xc5, 0xdb, 0xfe, 0xfe, 0xfe, 0xd3, 0xd3,
-0xfe, 0xfe, 0xfe, 0xcd, 0xc1, 0xc1, 0xc9, 0xd3, 0xd3, 0xe7,
-0xfe, 0xfe, 0xfe, 0xfe, 0xe7, 0xd3, 0xdb, 0xe7, 0xe7, 0xd3,
-0xcd, 0xd3, 0xfe, 0xfe, 0xfe, 0xcd, 0xc5, 0xd3, 0xe7, 0xe7,
-0xc9, 0xbc, 0xbe, 0xe7, 0x68, 0x4a, 0xfe, 0xdb, 0xcd, 0xfe,
-0xfe, 0xfe, 0xcd, 0xc1, 0xc9, 0xfe, 0x54, 0x5c, 0xe7, 0xc9,
-0xc5, 0xe7, 0xfe, 0xfe, 0xcd, 0xc5, 0xc5, 0xe7, 0xfe, 0xfe,
-0xfe, 0xe7, 0xe7, 0xfe, 0xfe, 0xdb, 0xd3, 0xd3, 0xdb, 0xe7,
-0xfe, 0xfe, 0xe7, 0xe7, 0xdb, 0xd3, 0xc9, 0xd3, 0xe7, 0xfe,
-0xfe, 0xd3, 0xd3, 0xdb, 0xfe, 0xfe, 0xfe, 0xd3, 0xcd, 0xcd,
-0xfe, 0xfe, 0xe7, 0xc9, 0xc5, 0xd3, 0xfe, 0xfe, 0xfe, 0xcd,
-0xc9, 0xd3, 0xfe, 0xfe, 0xfe, 0xdb, 0xc9, 0xcd, 0xe7, 0xfe,
-0xe7, 0xcd, 0xcd, 0xe7, 0xfe, 0xfe, 0xe7, 0xd3, 0xc5, 0xcd,
-0xe7, 0xfe, 0xfe, 0xfe, 0xdb, 0xe7, 0xfe, 0xfe, 0xfe, 0xfe,
-0xe7, 0xcd, 0xcd, 0xd3, 0xe7, 0xe7, 0xe7, 0xe7, 0xfe, 0xfe,
-0xe7, 0xe7, 0xdb, 0xc9, 0xc1, 0xc5, 0xfe, 0x5c, 0x68, 0xfe,
-0xd3, 0xdb, 0xe7, 0xe7, 0xe7, 0xd3, 0xc5, 0xcd, 0xe7, 0x68,
-0xfe, 0xe7, 0xcd, 0xd3, 0xe7, 0xfe, 0xe7, 0xcd, 0xc1, 0xc1,
-0xdb, 0xfe, 0x54, 0xfe, 0xe7, 0xcd, 0xe7, 0xfe, 0xe7, 0xd3,
-0xcd, 0xd3, 0xe7, 0xfe, 0xfe, 0xfe, 0xcd, 0xc5, 0xcd, 0xfe,
-0xfe, 0xe7, 0xcd, 0xd3, 0xdb, 0xe7, 0xfe, 0xfe, 0xfe, 0xe7,
-0xd3, 0xd3, 0xe7, 0xfe, 0xe7, 0xe7, 0xe7, 0xfe, 0xfe, 0xfe,
-0xfe, 0xdb, 0xc5, 0xc1, 0xd3, 0xfe, 0xfe, 0xfe, 0xd3, 0xc9,
-0xcd, 0xe7, 0xfe, 0xfe, 0xd3, 0xcd, 0xdb, 0xfe, 0x5c, 0xfe,
-0xcd, 0xc9, 0xd3, 0xfe, 0xfe, 0xfe, 0xd3, 0xc9, 0xcd, 0xfe,
-0x68, 0xfe, 0xd3, 0xc1, 0xc1, 0xdb, 0xfe, 0xfe, 0xe7, 0xe7,
-0xfe, 0xfe, 0x68, 0xfe, 0xe7, 0xc5, 0xc9, 0xdb, 0xfe, 0xfe,
-0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xdb, 0xc5, 0xc5,
-0xd3, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xe7, 0xe7, 0xfe, 0xfe,
-0xc9, 0xc1, 0xc5, 0xfe, 0x54, 0x5c, 0xfe, 0xcd, 0xc5, 0xcd,
-0xfe, 0xfe, 0xdb, 0xc5, 0xc9, 0xfe, 0x5c, 0x68, 0xfe, 0xcd,
-0xcd, 0xfe, 0xfe, 0xfe, 0xe7, 0xc5, 0xc1, 0xd3, 0xfe, 0xfe,
-0xdb, 0xc9, 0xc5, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xfe,
-0xfe, 0xfe, 0xe7, 0xcd, 0xcd, 0xdb, 0xfe, 0xfe, 0xfe, 0xfe,
-0xe7, 0xd3, 0xcd, 0xd3, 0xfe, 0xfe, 0xdb, 0xcd, 0xd3, 0xe7,
-0xfe, 0xfe, 0xfe, 0xdb, 0xcd, 0xd3, 0xe7, 0xfe, 0xd3, 0xc5,
-0xc9, 0xfe, 0x5c, 0x54, 0xfe, 0xcd, 0xc1, 0xcd, 0xe7, 0xfe,
-0xfe, 0xd3, 0xcd, 0xfe, 0x54, 0x5c, 0xe7, 0xc1, 0xc1, 0xd3,
-0xfe, 0xfe, 0xe7, 0xd3, 0xd3, 0xe7, 0xfe, 0xfe, 0xfe, 0xcd,
-0xc5, 0xcd, 0xd3, 0xe7, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xe7, 0xd3, 0xcd, 0xc9, 0xcd, 0xe7, 0xfe, 0xfe, 0xfe, 0xdb,
-0xc9, 0xcd, 0xe7, 0xfe, 0xe7, 0xc9, 0xc5, 0xdb, 0xfe, 0x5c,
-0xfe, 0xe7, 0xcd, 0xcd, 0xe7, 0xfe, 0xe7, 0xc5, 0xc1, 0xd3,
-0xfe, 0x5c, 0xfe, 0xcd, 0xc5, 0xcd, 0xe7, 0xfe, 0xfe, 0xe7,
-0xd3, 0xe7, 0xfe, 0xfe, 0xe7, 0xcd, 0xcd, 0xdb, 0xfe, 0xfe,
-0xfe, 0xe7, 0xe7, 0xe7, 0xe7, 0xfe, 0xe7, 0xdb, 0xcd, 0xd3,
-0xd3, 0xdb, 0xfe, 0xfe, 0xfe, 0xfe, 0xdb, 0xd3, 0xdb, 0xe7,
-0xe7, 0xdb, 0xd3, 0xe7, 0xfe, 0xfe, 0xfe, 0xe7, 0xc9, 0xc5,
-0xcd, 0xe7, 0xfe, 0xdb, 0xd3, 0xe7, 0xfe, 0x68, 0xfe, 0xe7,
-0xcd, 0xcd, 0xd3, 0xfe, 0xfe, 0xe7, 0xdb, 0xe7, 0xfe, 0x68,
-0xfe, 0xdb, 0xfe, 0x68, 0xbe, 0xb2, 0xae, 0xab, 0xb2, 0xfe,
-0x2f, 0x31, 0xdb, 0xac, 0xad, 0xaf, 0xab, 0xab, 0xb4, 0x68,
-0x37, 0x39, 0x3f, 0xe7, 0xb4, 0xa8, 0xaa, 0xb0, 0xbc, 0xbc,
-0xc5, 0x3f, 0x31, 0x3d, 0xfe, 0xc1, 0xb8, 0xb0, 0xa5, 0xa2,
-0xa8, 0xaf, 0xdb, 0x3b, 0x28, 0x2a, 0x3d, 0xbc, 0xb0, 0xaa,
-0xa2, 0x9f, 0xab, 0xfe, 0x29, 0x24, 0x29, 0x4a, 0xb4, 0xaa,
-0xa8, 0xa9, 0xa8, 0xa5, 0xac, 0xdb, 0x2c, 0x27, 0x35, 0x4a,
-0xfe, 0xcd, 0xb2, 0xa2, 0x9f, 0x9f, 0xae, 0x4e, 0x2c, 0x22,
-0x33, 0xfe, 0xba, 0xb0, 0xa6, 0x9f, 0xa3, 0xbc, 0x5c, 0x33,
-0x31, 0x39, 0x5c, 0xcd, 0xc1, 0xb4, 0xad, 0xaa, 0xad, 0xcd,
-0x54, 0x46, 0xfe, 0xe7, 0xfe, 0x54, 0xc5, 0xaf, 0xa6, 0xa9,
-0xb0, 0xfe, 0x3d, 0x39, 0x5c, 0xdb, 0xdb, 0xfe, 0xba, 0xac,
-0xa8, 0xc5, 0x39, 0x33, 0x54, 0xb8, 0xae, 0xad, 0xb8, 0xc1,
-0xcd, 0xbe, 0xbc, 0xfe, 0x39, 0x37, 0xfe, 0xb4, 0xba, 0xcd,
-0xdb, 0xb8, 0xb0, 0xb6, 0xfe, 0x4e, 0x39, 0x3d, 0xfe, 0xb0,
-0xaa, 0xa9, 0xa9, 0xaa, 0xb0, 0x5c, 0x29, 0x28, 0x31, 0xfe,
-0xba, 0xb4, 0xae, 0xab, 0xab, 0xb2, 0xfe, 0x3b, 0x2a, 0x2f,
-0x54, 0xb4, 0xb4, 0xba, 0xb2, 0xa3, 0x9f, 0xa8, 0xfe, 0x2c,
-0x27, 0x2a, 0x46, 0xfe, 0xc1, 0xbc, 0xb0, 0xa2, 0xa2, 0xb0,
-0x33, 0x22, 0x2b, 0x46, 0xc1, 0xb4, 0xb0, 0xab, 0xa8, 0xa8,
-0xb0, 0xdb, 0x42, 0x2c, 0x33, 0x4a, 0xfe, 0x5c, 0xdb, 0xb4,
-0xa8, 0xad, 0xba, 0xfe, 0x46, 0x39, 0x39, 0x4a, 0xfe, 0xbc,
-0xab, 0xa5, 0xa5, 0xb8, 0x68, 0x37, 0x4a, 0xe7, 0xfe, 0x4a,
-0x5c, 0xd3, 0xb0, 0xb2, 0xc1, 0x5c, 0x42, 0x46, 0xd3, 0xb4,
-0xbe, 0x54, 0x54, 0xb6, 0xab, 0xae, 0xe7, 0x46, 0x4a, 0xfe,
-0xcd, 0xc9, 0xd3, 0xe7, 0xe7, 0xbe, 0xb4, 0xc5, 0x37, 0x2c,
-0x37, 0xc1, 0xb0, 0xb2, 0xb4, 0xb2, 0xb6, 0xdb, 0x54, 0x4a,
-0x46, 0x42, 0x68, 0xba, 0xb2, 0xba, 0xc5, 0xb6, 0xb6, 0xcd,
-0x33, 0x2f, 0x39, 0x68, 0xfe, 0xe7, 0xba, 0xac, 0xa7, 0xa7,
-0xb2, 0xe7, 0x2d, 0x25, 0x2f, 0xd3, 0xbe, 0xd3, 0xc5, 0xac,
-0xa6, 0xac, 0xfe, 0x33, 0x2c, 0x2d, 0x54, 0xc1, 0xb4, 0xcd,
-0xcd, 0xaf, 0xa4, 0xa8, 0xe7, 0x31, 0x31, 0x39, 0x46, 0xfe,
-0xdb, 0xbc, 0xb6, 0xaf, 0xa9, 0xb2, 0xfe, 0x2f, 0xfe, 0xba,
-0xad, 0xba, 0x4e, 0x3d, 0x42, 0xfe, 0xc9, 0xc1, 0xe7, 0xfe,
-0xc1, 0xa9, 0xa6, 0xcd, 0x2a, 0x25, 0x3b, 0xbc, 0xb0, 0xb6,
-0xb8, 0xb4, 0xb4, 0xb8, 0xc1, 0xfe, 0x3d, 0x3d, 0xfe, 0xba,
-0xd3, 0x54, 0x54, 0xbe, 0xb0, 0xb4, 0xe7, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xc5, 0xb6, 0xa9, 0xaa, 0xba, 0x3d, 0x39,
-0xfe, 0xc1, 0xfe, 0x4a, 0x54, 0xbe, 0xb2, 0xb8, 0xfe, 0x3d,
-0x3b, 0xfe, 0xb0, 0xab, 0xc5, 0x39, 0x3b, 0xbc, 0xa7, 0xab,
-0xd3, 0x68, 0xfe, 0xd3, 0xcd, 0xfe, 0x54, 0x3d, 0xfe, 0xbc,
-0xac, 0xc9, 0x3f, 0x2e, 0xfe, 0xba, 0xb0, 0xba, 0xba, 0xb6,
-0xba, 0xd3, 0xfe, 0xfe, 0x5c, 0x54, 0xc9, 0xb4, 0xbe, 0x54,
-0x68, 0xcd, 0xb6, 0xfe, 0x46, 0x54, 0xcd, 0xc5, 0xdb, 0xfe,
-0xe7, 0xc1, 0xae, 0xa8, 0xac, 0xfe, 0x2e, 0x2e, 0xfe, 0xb6,
-0xc1, 0x5c, 0xe7, 0xb6, 0xaa, 0xb0, 0x54, 0x35, 0x2e, 0x4a,
-0xc1, 0xac, 0xbc, 0xfe, 0xfe, 0xaf, 0xa6, 0xac, 0xfe, 0x42,
-0x46, 0x5c, 0xfe, 0xfe, 0xfe, 0xe7, 0xc9, 0xae, 0xa9, 0xb0,
-0x54, 0x31, 0x37, 0xfe, 0xd3, 0xd3, 0xb8, 0xac, 0xab, 0xb6,
-0xe7, 0xfe, 0xfe, 0x68, 0xfe, 0xfe, 0xfe, 0x54, 0xfe, 0xb0,
-0xae, 0xb8, 0xfe, 0xe7, 0xc1, 0xb6, 0xe7, 0x46, 0x3d, 0xe7,
-0xae, 0xa7, 0xab, 0xdb, 0x3f, 0x37, 0xfe, 0xba, 0xcd, 0x3f,
-0x42, 0xc5, 0xab, 0xac, 0xc9, 0x46, 0x3d, 0x54, 0xba, 0xad,
-0xb0, 0xfe, 0x68, 0xcd, 0xb0, 0xb0, 0xc9, 0x54, 0x54, 0xfe,
-0xfe, 0xfe, 0xfe, 0xe7, 0xcd, 0xbe, 0xba, 0xc5, 0x68, 0x42,
-0x46, 0xe7, 0xc5, 0xba, 0xaf, 0xa7, 0xa7, 0xbc, 0xfe, 0x3d,
-0x4a, 0x68, 0xfe, 0xfe, 0xfe, 0xe7, 0xbc, 0xaf, 0xae, 0xc5,
-0x3d, 0x39, 0xfe, 0xbc, 0xbe, 0xfe, 0x68, 0xc9, 0xa9, 0xa2,
-0xaa, 0xbc, 0x3b, 0x2d, 0x35, 0xfe, 0xcd, 0xfe, 0xfe, 0xb4,
-0xa9, 0xa6, 0xbc, 0x54, 0x31, 0x31, 0x54, 0xd3, 0xbc, 0xc5,
-0xcd, 0xb8, 0xab, 0xa8, 0xb4, 0xfe, 0x54, 0x4e, 0x68, 0x54,
-0xfe, 0xc9, 0xba, 0xb4, 0xb4, 0xba, 0xcd, 0x5c, 0x3b, 0x3f,
-0x54, 0xfe, 0xcd, 0xaf, 0xa8, 0xac, 0xc5, 0x68, 0xfe, 0xe7,
-0xdb, 0xfe, 0xfe, 0xfe, 0xcd, 0xb8, 0xaf, 0xb6, 0xe7, 0x42,
-0x5c, 0xcd, 0xbc, 0xfe, 0x46, 0x68, 0xba, 0xb0, 0xab, 0xbc,
-0x54, 0x3d, 0x46, 0xc9, 0xb8, 0xbc, 0xdb, 0xd3, 0xb6, 0xb0,
-0xb6, 0x5c, 0x37, 0x35, 0x54, 0xc9, 0xba, 0xb4, 0xc1, 0xc9,
-0xc1, 0xba, 0xe7, 0x5c, 0x3d, 0x54, 0xfe, 0xcd, 0xc5, 0xb8,
-0xae, 0xaf, 0xb4, 0xd3, 0x54, 0x3b, 0x35, 0x46, 0xfe, 0xdb,
-0xbc, 0xaf, 0xa9, 0xab, 0xd3, 0x3f, 0x31, 0x3f, 0xfe, 0xe7,
-0xdb, 0xcd, 0xb8, 0xae, 0xaa, 0xac, 0xe7, 0x33, 0x2d, 0x3f,
-0xd3, 0xdb, 0xfe, 0xfe, 0xbc, 0xaa, 0xa9, 0xb0, 0xfe, 0x31,
-0x2f, 0x3d, 0xdb, 0xc5, 0xcd, 0xc9, 0xae, 0xa8, 0xad, 0xfe,
-0x46, 0x39, 0x46, 0x5c, 0xfe, 0xcd, 0xc5, 0xc1, 0xb6, 0xb0,
-0xbc, 0x68, 0x42, 0x4e, 0xe7, 0xfe, 0x5c, 0xfe, 0xb6, 0xaf,
-0xb0, 0xc5, 0xe7, 0x5c, 0x5c, 0xfe, 0xe7, 0xfe, 0x68, 0xe7,
-0xb0, 0xac, 0xb2, 0x4a, 0x35, 0x3f, 0xcd, 0xbc, 0xc1, 0xe7,
-0xe7, 0xd3, 0xb6, 0xb4, 0xfe, 0x3b, 0x33, 0xfe, 0xba, 0xb4,
-0xd3, 0xfe, 0xc9, 0xb4, 0xb4, 0xcd, 0x4a, 0x3b, 0x3b, 0xfe,
-0xb8, 0xb6, 0xc5, 0xc5, 0xb8, 0xb0, 0xcd, 0x4a, 0x31, 0x3b,
-0x68, 0xcd, 0xc1, 0xba, 0xb4, 0xb0, 0xb0, 0xba, 0x5c, 0x2f,
-0x2f, 0x4e, 0xc9, 0xc1, 0xdb, 0xc9, 0xb4 };
diff --git a/1.2-netsec/apps/leave.h b/1.2-netsec/apps/leave.h
deleted file mode 100644
index 238976f20..000000000
--- a/1.2-netsec/apps/leave.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * U-law 8-bit audio data
- *
- * Source: leave.raw
- *
- * Copyright (C) 1999, Mark Spencer and Linux Support Services
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char leave[] = {
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xc1, 0x3d,
-0x42, 0x46, 0x3f, 0x3f, 0x46, 0x3f, 0x4e, 0xba, 0xbe, 0xbe,
-0xbc, 0xba, 0xbe, 0xc5, 0xb6, 0x2e, 0x2c, 0x33, 0x2f, 0x2e,
-0x2f, 0x33, 0x2b, 0x54, 0xac, 0xb0, 0xb0, 0xad, 0xaf, 0xb0,
-0xae, 0xcd, 0x3b, 0x2f, 0x31, 0x2e, 0x2f, 0x31, 0x2e, 0x46,
-0xc5, 0xaf, 0xb0, 0xaf, 0xae, 0xaf, 0xaf, 0xb0, 0xfe, 0x2d,
-0x31, 0x31, 0x2e, 0x31, 0x2f, 0x31, 0xfe, 0xae, 0xaf, 0xaf,
-0xae, 0xb0, 0xae, 0xaf, 0xfe, 0xdb, 0x2e, 0x2e, 0x31, 0x31,
-0x2d, 0x2e, 0xdb, 0x68, 0xaf, 0xad, 0xb0, 0xb0, 0xae, 0xaf,
-0x5c, 0xe7, 0x39, 0x2d, 0x31, 0x31, 0x31, 0x2d, 0xfe, 0xfe,
-0x68, 0xad, 0xaf, 0xb0, 0xaf, 0xac, 0xbc, 0xfe, 0xd3, 0x2f,
-0x2e, 0x33, 0x31, 0x2d, 0x4e, 0xdb, 0xfe, 0xfe, 0xac, 0xaf,
-0xb0, 0xac, 0xb6, 0x68, 0xe7, 0xdb, 0x2e, 0x2f, 0x35, 0x2f,
-0x31, 0xe7, 0xe7, 0x68, 0xad, 0xac, 0xb0, 0xae, 0xac, 0xfe,
-0xfe, 0xdb, 0xfe, 0x2d, 0x33, 0x31, 0x2e, 0xfe, 0xfe, 0xfe,
-0xfe, 0xbc, 0xaf, 0xb0, 0xad, 0xfe, 0xfe, 0xfe, 0xe7, 0x5c,
-0x2e, 0x33, 0x2e, 0x35, 0xe7, 0xfe, 0xfe, 0xfe, 0xad, 0xb0,
-0xaf, 0xc1, 0xfe, 0xe7, 0xfe, 0xe7, 0x3d, 0x31, 0x2f, 0x37,
-0xe7, 0xfe, 0xfe, 0xe7, 0xfe, 0xaf, 0xad, 0xbe, 0xfe, 0xdb,
-0xfe, 0xfe, 0xdb, 0x35, 0x2d, 0x39, 0xdb, 0xfe, 0xfe, 0xdb,
-0xfe, 0xfe, 0xad, 0xaf, 0xfe, 0xfe, 0xe7, 0x68, 0xfe, 0xd3,
-0x2e, 0x2c, 0xdb, 0xdb, 0x2c, 0x35, 0xd3, 0x68, 0xaf, 0xad,
-0xb0, 0xb0, 0xad, 0xba, 0x68, 0xe7, 0xe7, 0x2e, 0x2f, 0x33,
-0x31, 0x2d, 0xdb, 0xd3, 0x5c, 0xae, 0xaa, 0xe7, 0x68, 0xaa,
-0xe7, 0xfe, 0xdb, 0xe7, 0xfe, 0xe7, 0xd3, 0x2d, 0xfe, 0xdb,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xc5, 0xfe, 0xe7, 0xe7,
-0xfe, 0xfe, 0xe7, 0xe7, 0x3b, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xe7, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xc5, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xe7, 0xfe, 0x3b,
-0xdb, 0xfe, 0xfe, 0xfe, 0xe7, 0xfe, 0xfe, 0xb0, 0xfe, 0xfe,
-0xe7, 0xfe, 0xfe, 0xfe, 0xdb, 0x2e, 0x5c, 0xdb, 0xfe, 0xfe,
-0xe7, 0xe7, 0x68, 0xb0, 0xbe, 0x68, 0xe7, 0xe7, 0xfe, 0xfe,
-0xdb, 0x39, 0x2f, 0xdb, 0xfe, 0xfe, 0xe7, 0xe7, 0xfe, 0xbe,
-0xaf, 0xe7, 0x68, 0xe7, 0xfe, 0xfe, 0xfe, 0xfe, 0x33, 0x33,
-0xdb, 0xfe, 0xfe, 0xdb, 0xe7, 0xfe, 0xb0, 0xb0, 0xfe, 0xfe,
-0xe7, 0xfe, 0xfe, 0xfe, 0x35, 0x33, 0xe7, 0xe7, 0xfe, 0xe7,
-0xe7, 0xfe, 0xb0, 0xb2, 0xb0, 0xfe, 0xfe, 0xe7, 0xfe, 0xe7,
-0x46, 0x35, 0x35, 0x3f, 0xe7, 0xfe, 0xe7, 0xfe, 0xb2, 0xb0,
-0xb2, 0xb0, 0xfe, 0xfe, 0xfe, 0xfe, 0x42, 0x35, 0x37, 0x33,
-0xe7, 0xfe, 0xfe, 0xfe, 0xb8, 0xb0, 0xb6, 0xb0, 0xba, 0xfe,
-0xfe, 0xe7, 0xe7, 0x33, 0x39, 0x39, 0x33, 0xe7, 0xdb, 0xfe,
-0xe7, 0xb0, 0xb4, 0xb6, 0xb0, 0xcd, 0xfe, 0xe7, 0xe7, 0x33,
-0x39, 0x3b, 0x33, 0x46, 0xd3, 0xfe, 0xfe, 0xb0, 0xb2, 0xb6,
-0xb4, 0xb0, 0xfe, 0xfe, 0xdb, 0x35, 0x37, 0x39, 0x39, 0x35,
-0x37, 0xdb, 0x68, 0xcd, 0xb2, 0xb6, 0xb6, 0xb4, 0xb4, 0x68,
-0xe7, 0x42, 0x37, 0x3b, 0x3b, 0x39, 0x37, 0xdb, 0xfe, 0xcd,
-0xb2, 0xb6, 0xb6, 0xb6, 0xb2, 0xb4, 0xfe, 0x54, 0x37, 0x3b,
-0x39, 0x3b, 0x3b, 0x39, 0xe7, 0xfe, 0xb6, 0xb6, 0xb6, 0xb4,
-0xb6, 0xb6, 0xbc, 0xfe, 0x3f, 0x3b, 0x3b, 0x39, 0x3b, 0x3b,
-0x39, 0xe7, 0xb6, 0xb8, 0xb8, 0xb6, 0xb8, 0xb8, 0xb4, 0xfe,
-0x3b, 0x3d, 0x3d, 0x3b, 0x39, 0x3d, 0x3b, 0x39, 0xbe, 0xb8,
-0xba, 0xb8, 0xb6, 0xb8, 0xba, 0xb4, 0xfe, 0x39, 0x3f, 0x3d,
-0x3b, 0x3d, 0x3f, 0x39, 0xdb, 0xb4, 0xba, 0xb8, 0xb6, 0xb8,
-0xbc, 0xb4, 0xba, 0x39, 0x42, 0x3f, 0x3d, 0x3d, 0x3f, 0x3f,
-0x3b, 0xb8, 0xb6, 0xbc, 0xb8, 0xb8, 0xba, 0xbc, 0xb8, 0xe7,
-0x3d, 0x42, 0x3f, 0x3d, 0x3f, 0x42, 0x3d, 0xfe, 0xb8, 0xbc,
-0xbc, 0xba, 0xba, 0xbc, 0xba, 0xe7, 0x3d, 0x3f, 0x42, 0x3f,
-0x3f, 0x42, 0x42, 0xfe, 0xfe, 0xbc, 0xbc, 0xbe, 0xbc, 0xbe,
-0xbc, 0xc5, 0xe7, 0x68, 0x42, 0x46, 0x42, 0x46, 0x42, 0x46,
-0xfe, 0xfe, 0xbc, 0xbe, 0xbe, 0xbe, 0xbc, 0xc5, 0xfe, 0xdb,
-0x46, 0x46, 0x4a, 0x4a, 0x46, 0x46, 0xe7, 0xfe, 0xd3, 0xbe,
-0xc9, 0xc9, 0xc5, 0xc5, 0xe7, 0xdb, 0xd3, 0x4a, 0x4e, 0x54,
-0x4e, 0x4e, 0xfe, 0x5c, 0x54, 0xd3, 0xcd, 0xd3, 0xd3, 0xcd,
-0xd3, 0xd3, 0xcd, 0xfe, 0x5c, 0x68, 0x5c, 0x5c, 0x5c, 0x68,
-0x5c, 0x5c, 0xcd, 0xcd, 0xd3, 0xcd, 0xdb, 0xe7, 0xe7, 0xdb,
-0xe7, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xe7,
-0xfe, 0x5c, 0x5c, 0xfe, 0xfe, 0xfe, 0xfe, 0x46, 0x35, 0x35,
-0x37, 0x39, 0x3b, 0x39, 0x35, 0x33, 0x35, 0x5c, 0xd3, 0xcd,
-0xdb, 0xfe, 0xfe, 0xd3, 0xb0, 0xb0, 0xb0, 0xb4, 0xb4, 0xb6,
-0xb2, 0xb0, 0xb0, 0xb6, 0xcd, 0x5c, 0x68, 0xfe, 0xfe, 0xfe,
-0x3b, 0x33, 0x35, 0x37, 0x39, 0x3b, 0x39, 0x37, 0x35, 0x35,
-0x3f, 0xdb, 0xcd, 0xcd, 0xdb, 0xfe, 0xe7, 0xc5, 0xb0, 0xb0,
-0xb2, 0xb6, 0xb6, 0xb6, 0xb2, 0xb0, 0xb0, 0xcd, 0x5c, 0x5c,
-0xfe, 0xe7, 0xe7, 0xfe, 0x35, 0x35, 0x35, 0x39, 0x3b, 0x3b,
-0x39, 0x35, 0x33, 0x39, 0xdb, 0xcd, 0xd3, 0xe7, 0xfe, 0xfe,
-0xba, 0xb0, 0xb0, 0xb2, 0xb4, 0xb6, 0xb6, 0xb4, 0xb2, 0xb0,
-0xb4, 0xc9, 0x5c, 0x68, 0xfe, 0xfe, 0x5c, 0x3b, 0x35, 0x37,
-0x39, 0x3b, 0x3b, 0x3b, 0x39, 0x37, 0x37, 0x3d, 0xe7, 0xcd,
-0xdb, 0xfe, 0xe7, 0xbe, 0xb2, 0xb2, 0xb4, 0xb4, 0xb6, 0xb6,
-0xb6, 0xb4, 0xb0, 0xb0, 0xc5, 0x5c, 0x5c, 0xfe, 0xe7, 0xe7,
-0x4e, 0x35, 0x35, 0x37, 0x3b, 0x3b, 0x3b, 0x39, 0x37, 0x37,
-0x3b, 0xe7, 0xc9, 0xcd, 0xe7, 0xfe, 0xd3, 0xb4, 0xb2, 0xb2,
-0xb4, 0xb6, 0xb6, 0xb6, 0xb6, 0xb4, 0xb2, 0xb4, 0xc1, 0x68,
-0x68, 0xfe, 0xfe, 0x42, 0x39, 0x37, 0x39, 0x3b, 0x3b, 0x3b,
-0x3b, 0x3b, 0x39, 0x37, 0x3b, 0xfe, 0xd3, 0xdb, 0xfe, 0xcd,
-0xb4, 0xb2, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6, 0xb6, 0xb4, 0xb2,
-0xb2, 0xc1, 0x5c, 0x5c, 0xfe, 0xfe, 0xfe, 0x3d, 0x37, 0x37,
-0x39, 0x3b, 0x3b, 0x3b, 0x3b, 0x37, 0x37, 0x39, 0xfe, 0xcd,
-0xd3, 0xfe, 0xfe, 0xc1, 0xb2, 0xb2, 0xb4, 0xb6, 0xb6, 0xb6,
-0xb6, 0xb6, 0xb6, 0xb4, 0xb4, 0xbc, 0x68, 0xfe, 0xfe, 0xfe,
-0x3b, 0x39, 0x39, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x39,
-0x39, 0x3b, 0xfe, 0xdb, 0xe7, 0xfe, 0xbc, 0xb6, 0xb6, 0xb6,
-0xb8, 0xb6, 0xb6, 0xb6, 0xb8, 0xb6, 0xb4, 0xb4, 0xbc, 0xfe,
-0x68, 0xfe, 0xe7, 0x5c, 0x3b, 0x39, 0x39, 0x3b, 0x3b, 0x3b,
-0x3d, 0x3d, 0x3b, 0x39, 0x3b, 0x68, 0xdb, 0xdb, 0xfe, 0xe7,
-0xb8, 0xb6, 0xb6, 0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0xb6,
-0xb4, 0xb6, 0xdb, 0x68, 0xfe, 0xfe, 0x46, 0x3b, 0x3b, 0x3b,
-0x3d, 0x3d, 0x3b, 0x3d, 0x3d, 0x3d, 0x3d, 0x3b, 0x3b, 0x5c,
-0xdb, 0xdb, 0xc9, 0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0xb8,
-0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0xbc, 0xcd, 0xfe, 0xfe, 0x3d,
-0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3b, 0x3d, 0x3d, 0x3d, 0x3d,
-0x3b, 0x3d, 0x46, 0xfe, 0xe7, 0xe7, 0xc5, 0xb8, 0xb8, 0xb8,
-0xba, 0xba, 0xb8, 0xb8, 0xba, 0xba, 0xb8, 0xb8, 0xb8, 0xcd,
-0xfe, 0xfe, 0x68, 0x3f, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d,
-0x3d, 0x3d, 0x3f, 0x3f, 0x3d, 0x3b, 0x4a, 0xfe, 0xdb, 0xbc,
-0xb8, 0xba, 0xba, 0xba, 0xba, 0xb8, 0xb8, 0xb8, 0xba, 0xba,
-0xba, 0xba, 0xba, 0xc5, 0xfe, 0x54, 0x3f, 0x3f, 0x3f, 0x3f,
-0x3f, 0x3f, 0x3d, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x42,
-0xfe, 0xe7, 0xdb, 0xbc, 0xba, 0xba, 0xba, 0xba, 0xba, 0xba,
-0xba, 0xba, 0xbc, 0xba, 0xba, 0xba, 0xc5, 0xfe, 0xfe, 0x4e,
-0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x42,
-0x42, 0x42, 0x3f, 0x46, 0xfe, 0xcd, 0xb8, 0xba, 0xbc, 0xbc,
-0xbc, 0xba, 0xba, 0xba, 0xba, 0xbc, 0xbc, 0xbc, 0xba, 0xb8,
-0xbe, 0xfe, 0x42, 0x3d, 0x3f, 0x42, 0x42, 0x42, 0x3f, 0x3f,
-0x3f, 0x42, 0x42, 0x42, 0x42, 0x3f, 0x3f, 0x68, 0xdb, 0xc5,
-0xba, 0xbc, 0xbc, 0xbc, 0xbc, 0xba, 0xba, 0xba, 0xbc, 0xbc,
-0xbc, 0xbc, 0xba, 0xc1, 0xfe, 0xfe, 0x3f, 0x42, 0x46, 0x46,
-0x46, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x46, 0x42, 0x3f,
-0x42, 0x68, 0xbe, 0xba, 0xbc, 0xbe, 0xbe, 0xbe, 0xbc, 0xbc,
-0xbc, 0xbc, 0xbe, 0xc1, 0xbe, 0xbc, 0xba, 0xbe, 0x68, 0x3f,
-0x42, 0x46, 0x4a, 0x4a, 0x46, 0x42, 0x42, 0x42, 0x46, 0x46,
-0x46, 0x46, 0x42, 0x42, 0x68, 0xd3, 0xbc, 0xbc, 0xbe, 0xc1,
-0xc1, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xc1, 0xc1, 0xbe, 0xbe,
-0xc1, 0xfe, 0x4e, 0x42, 0x46, 0x4a, 0x4a, 0x4a, 0x46, 0x46,
-0x46, 0x46, 0x4a, 0x4a, 0x4a, 0x46, 0x46, 0x68, 0xdb, 0xbe,
-0xbe, 0xc1, 0xc5, 0xc1, 0xc1, 0xbe, 0xbe, 0xbe, 0xbe, 0xc1,
-0xc5, 0xc5, 0xbe, 0xbc, 0xc1, 0x4e, 0x46, 0x46, 0x4a, 0x4e,
-0x4e, 0x4a, 0x46, 0x46, 0x46, 0x4a, 0x4a, 0x4e, 0x4a, 0x46,
-0x46, 0xfe, 0xbe, 0xbe, 0xc1, 0xc9, 0xc5, 0xc5, 0xc1, 0xc1,
-0xc1, 0xc1, 0xc5, 0xc5, 0xc5, 0xc5, 0xbe, 0xc1, 0xfe, 0x4a,
-0x4a, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4a, 0x4a, 0x4a, 0x4e,
-0x54, 0x4e, 0x4a, 0x4a, 0x4e, 0xcd, 0xc1, 0xc5, 0xc5, 0xc9,
-0xc5, 0xc5, 0xc5, 0xc5, 0xc9, 0xcd, 0xcd, 0xcd, 0xcd, 0xc9,
-0xc9, 0xd3, 0x68, 0x54, 0x5c, 0x68, 0x68, 0x68, 0x5c, 0x5c,
-0x5c, 0x5c, 0x5c, 0x68, 0x68, 0x5c, 0x54, 0x5c, 0xdb, 0xcd,
-0xcd, 0xdb, 0xdb, 0xdb, 0xdb, 0xd3, 0xd3, 0xe7, 0xe7, 0xe7,
-0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xe7, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
-0xfe, 0xfe, 0xfe };
diff --git a/1.2-netsec/apps/rpt_flow.pdf b/1.2-netsec/apps/rpt_flow.pdf
deleted file mode 100644
index 2085af0f2..000000000
--- a/1.2-netsec/apps/rpt_flow.pdf
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/ast_expr2.c b/1.2-netsec/ast_expr2.c
deleted file mode 100644
index adc58e74d..000000000
--- a/1.2-netsec/ast_expr2.c
+++ /dev/null
@@ -1,2419 +0,0 @@
-/* A Bison parser, made by GNU Bison 2.0. */
-
-/* Skeleton parser for Yacc-like parsing with Bison,
- Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-/* As a special exception, when this file is copied by Bison into a
- Bison output file, you may use that output file without restriction.
- This special exception was added by the Free Software Foundation
- in version 1.24 of Bison. */
-
-/* Written by Richard Stallman by simplifying the original so called
- ``semantic'' parser. */
-
-/* All symbols defined below should begin with yy or YY, to avoid
- infringing on user name space. This should be done even for local
- variables, as they might otherwise be expanded by user macros.
- There are some unavoidable exceptions within include files to
- define necessary library symbols; they are noted "INFRINGES ON
- USER NAME SPACE" below. */
-
-/* Identify Bison output. */
-#define YYBISON 1
-
-/* Skeleton name. */
-#define YYSKELETON_NAME "yacc.c"
-
-/* Pure parsers. */
-#define YYPURE 1
-
-/* Using locations. */
-#define YYLSP_NEEDED 1
-
-/* Substitute the variable and function names. */
-#define yyparse ast_yyparse
-#define yylex ast_yylex
-#define yyerror ast_yyerror
-#define yylval ast_yylval
-#define yychar ast_yychar
-#define yydebug ast_yydebug
-#define yynerrs ast_yynerrs
-#define yylloc ast_yylloc
-
-/* Tokens. */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
- /* Put the tokens into the symbol table, so that GDB and other debuggers
- know about them. */
- enum yytokentype {
- TOK_COLONCOLON = 258,
- TOK_COND = 259,
- TOK_OR = 260,
- TOK_AND = 261,
- TOK_NE = 262,
- TOK_LE = 263,
- TOK_GE = 264,
- TOK_LT = 265,
- TOK_GT = 266,
- TOK_EQ = 267,
- TOK_MINUS = 268,
- TOK_PLUS = 269,
- TOK_MOD = 270,
- TOK_DIV = 271,
- TOK_MULT = 272,
- TOK_COMPL = 273,
- TOK_EQTILDE = 274,
- TOK_COLON = 275,
- TOK_LP = 276,
- TOK_RP = 277,
- TOKEN = 278
- };
-#endif
-#define TOK_COLONCOLON 258
-#define TOK_COND 259
-#define TOK_OR 260
-#define TOK_AND 261
-#define TOK_NE 262
-#define TOK_LE 263
-#define TOK_GE 264
-#define TOK_LT 265
-#define TOK_GT 266
-#define TOK_EQ 267
-#define TOK_MINUS 268
-#define TOK_PLUS 269
-#define TOK_MOD 270
-#define TOK_DIV 271
-#define TOK_MULT 272
-#define TOK_COMPL 273
-#define TOK_EQTILDE 274
-#define TOK_COLON 275
-#define TOK_LP 276
-#define TOK_RP 277
-#define TOKEN 278
-
-
-
-
-/* Copy the first part of user declarations. */
-#line 1 "ast_expr2.y"
-
-/* Written by Pace Willisson (pace@blitz.com)
- * and placed in the public domain.
- *
- * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
- *
- * And then overhauled twice by Steve Murphy (murf@e-tools.com)
- * to add double-quoted strings, allow mult. spaces, improve
- * error messages, and then to fold in a flex scanner for the
- * yylex operation.
- *
- * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <locale.h>
-#include <ctype.h>
-#if !defined(SOLARIS) && !defined(__CYGWIN__)
-#include <err.h>
-#else
-#define quad_t int64_t
-#endif
-#include <errno.h>
-#include <regex.h>
-#include <limits.h>
-#include <asterisk/ast_expr.h>
-#include <asterisk/logger.h>
-
-#ifdef LONG_LONG_MIN
-#define QUAD_MIN LONG_LONG_MIN
-#endif
-#ifdef LONG_LONG_MAX
-#define QUAD_MAX LONG_LONG_MAX
-#endif
-
-# if ! defined(QUAD_MIN)
-# define QUAD_MIN (-0x7fffffffffffffffLL-1)
-# endif
-# if ! defined(QUAD_MAX)
-# define QUAD_MAX (0x7fffffffffffffffLL)
-# endif
-
-#define YYPARSE_PARAM parseio
-#define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
-#define YYERROR_VERBOSE 1
-
-enum valtype {
- AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
-} ;
-
-#ifdef STANDALONE
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
-#endif
-
-struct val {
- enum valtype type;
- union {
- char *s;
- quad_t i;
- } u;
-} ;
-
-typedef void *yyscan_t;
-
-struct parse_io
-{
- char *string;
- struct val *val;
- yyscan_t scanner;
-};
-
-static int chk_div __P((quad_t, quad_t));
-static int chk_minus __P((quad_t, quad_t, quad_t));
-static int chk_plus __P((quad_t, quad_t, quad_t));
-static int chk_times __P((quad_t, quad_t, quad_t));
-static void free_value __P((struct val *));
-static int is_zero_or_null __P((struct val *));
-static int isstring __P((struct val *));
-static struct val *make_integer __P((quad_t));
-static struct val *make_str __P((const char *));
-static struct val *op_and __P((struct val *, struct val *));
-static struct val *op_colon __P((struct val *, struct val *));
-static struct val *op_eqtilde __P((struct val *, struct val *));
-static struct val *op_div __P((struct val *, struct val *));
-static struct val *op_eq __P((struct val *, struct val *));
-static struct val *op_ge __P((struct val *, struct val *));
-static struct val *op_gt __P((struct val *, struct val *));
-static struct val *op_le __P((struct val *, struct val *));
-static struct val *op_lt __P((struct val *, struct val *));
-static struct val *op_cond __P((struct val *, struct val *, struct val *));
-static struct val *op_minus __P((struct val *, struct val *));
-static struct val *op_negate __P((struct val *));
-static struct val *op_compl __P((struct val *));
-static struct val *op_ne __P((struct val *, struct val *));
-static struct val *op_or __P((struct val *, struct val *));
-static struct val *op_plus __P((struct val *, struct val *));
-static struct val *op_rem __P((struct val *, struct val *));
-static struct val *op_times __P((struct val *, struct val *));
-static quad_t to_integer __P((struct val *));
-static void to_string __P((struct val *));
-
-/* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
-typedef struct yyltype
-{
- int first_line;
- int first_column;
-
- int last_line;
- int last_column;
-} yyltype;
-
-# define YYLTYPE yyltype
-# define YYLTYPE_IS_TRIVIAL 1
-
-/* we will get warning about no prototype for yylex! But we can't
- define it here, we have no definition yet for YYSTYPE. */
-
-int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
-
-/* I wanted to add args to the yyerror routine, so I could print out
- some useful info about the error. Not as easy as it looks, but it
- is possible. */
-#define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
-#define DESTROY(x) { \
-if ((x)->type == AST_EXPR_numeric_string || (x)->type == AST_EXPR_string) \
- free((x)->u.s); \
- (x)->u.s = 0; \
- free(x); \
-}
-
-
-/* Enabling traces. */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
-
-/* Enabling verbose error messages. */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE 0
-#endif
-
-#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
-#line 142 "ast_expr2.y"
-typedef union YYSTYPE {
- struct val *val;
-} YYSTYPE;
-/* Line 190 of yacc.c. */
-#line 268 "ast_expr2.c"
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
-# define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
-#endif
-
-#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
-typedef struct YYLTYPE
-{
- int first_line;
- int first_column;
- int last_line;
- int last_column;
-} YYLTYPE;
-# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
-# define YYLTYPE_IS_DECLARED 1
-# define YYLTYPE_IS_TRIVIAL 1
-#endif
-
-
-/* Copy the second part of user declarations. */
-#line 146 "ast_expr2.y"
-
-extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
-
-
-/* Line 213 of yacc.c. */
-#line 295 "ast_expr2.c"
-
-#if ! defined (yyoverflow) || YYERROR_VERBOSE
-
-# ifndef YYFREE
-# define YYFREE free
-# endif
-# ifndef YYMALLOC
-# define YYMALLOC malloc
-# endif
-
-/* The parser invokes alloca or malloc; define the necessary symbols. */
-
-# ifdef YYSTACK_USE_ALLOCA
-# if YYSTACK_USE_ALLOCA
-# ifdef __GNUC__
-# define YYSTACK_ALLOC __builtin_alloca
-# else
-# define YYSTACK_ALLOC alloca
-# endif
-# endif
-# endif
-
-# ifdef YYSTACK_ALLOC
- /* Pacify GCC's `empty if-body' warning. */
-# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
-# else
-# if defined (__STDC__) || defined (__cplusplus)
-# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-# define YYSIZE_T size_t
-# endif
-# define YYSTACK_ALLOC YYMALLOC
-# define YYSTACK_FREE YYFREE
-# endif
-#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
-
-
-#if (! defined (yyoverflow) \
- && (! defined (__cplusplus) \
- || (defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
- && defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
-
-/* A type that is properly aligned for any stack member. */
-union yyalloc
-{
- short int yyss;
- YYSTYPE yyvs;
- YYLTYPE yyls;
-};
-
-/* The size of the maximum gap between one aligned stack and the next. */
-# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
-
-/* The size of an array large to enough to hold all stacks, each with
- N elements. */
-# define YYSTACK_BYTES(N) \
- ((N) * (sizeof (short int) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
- + 2 * YYSTACK_GAP_MAXIMUM)
-
-/* Copy COUNT objects from FROM to TO. The source and destination do
- not overlap. */
-# ifndef YYCOPY
-# if defined (__GNUC__) && 1 < __GNUC__
-# define YYCOPY(To, From, Count) \
- __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
-# else
-# define YYCOPY(To, From, Count) \
- do \
- { \
- register YYSIZE_T yyi; \
- for (yyi = 0; yyi < (Count); yyi++) \
- (To)[yyi] = (From)[yyi]; \
- } \
- while (0)
-# endif
-# endif
-
-/* Relocate STACK from its old location to the new one. The
- local variables YYSIZE and YYSTACKSIZE give the old and new number of
- elements in the stack, and YYPTR gives the new location of the
- stack. Advance YYPTR to a properly aligned location for the next
- stack. */
-# define YYSTACK_RELOCATE(Stack) \
- do \
- { \
- YYSIZE_T yynewbytes; \
- YYCOPY (&yyptr->Stack, Stack, yysize); \
- Stack = &yyptr->Stack; \
- yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
- yyptr += yynewbytes / sizeof (*yyptr); \
- } \
- while (0)
-
-#endif
-
-#if defined (__STDC__) || defined (__cplusplus)
- typedef signed char yysigned_char;
-#else
- typedef short int yysigned_char;
-#endif
-
-/* YYFINAL -- State number of the termination state. */
-#define YYFINAL 10
-/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST 140
-
-/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS 24
-/* YYNNTS -- Number of nonterminals. */
-#define YYNNTS 3
-/* YYNRULES -- Number of rules. */
-#define YYNRULES 22
-/* YYNRULES -- Number of states. */
-#define YYNSTATES 46
-
-/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
-#define YYUNDEFTOK 2
-#define YYMAXUTOK 278
-
-#define YYTRANSLATE(YYX) \
- ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
-
-/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
-static const unsigned char yytranslate[] =
-{
- 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
- 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23
-};
-
-#if YYDEBUG
-/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
- YYRHS. */
-static const unsigned char yyprhs[] =
-{
- 0, 0, 3, 5, 7, 11, 15, 19, 23, 27,
- 31, 35, 39, 43, 47, 51, 54, 57, 61, 65,
- 69, 73, 77
-};
-
-/* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const yysigned_char yyrhs[] =
-{
- 25, 0, -1, 26, -1, 23, -1, 21, 26, 22,
- -1, 26, 5, 26, -1, 26, 6, 26, -1, 26,
- 12, 26, -1, 26, 11, 26, -1, 26, 10, 26,
- -1, 26, 9, 26, -1, 26, 8, 26, -1, 26,
- 7, 26, -1, 26, 14, 26, -1, 26, 13, 26,
- -1, 13, 26, -1, 18, 26, -1, 26, 17, 26,
- -1, 26, 16, 26, -1, 26, 15, 26, -1, 26,
- 20, 26, -1, 26, 19, 26, -1, 26, 4, 26,
- 3, 26, -1
-};
-
-/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
-static const unsigned char yyrline[] =
-{
- 0, 165, 165, 175, 176, 180, 184, 188, 192, 196,
- 200, 204, 208, 212, 216, 220, 224, 228, 232, 236,
- 240, 244, 248
-};
-#endif
-
-#if YYDEBUG || YYERROR_VERBOSE
-/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- First, the terminals, then, starting at YYNTOKENS, nonterminals. */
-static const char *const yytname[] =
-{
- "$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR",
- "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ",
- "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL",
- "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept",
- "start", "expr", 0
-};
-#endif
-
-# ifdef YYPRINT
-/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
- token YYLEX-NUM. */
-static const unsigned short int yytoknum[] =
-{
- 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
- 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
- 275, 276, 277, 278
-};
-# endif
-
-/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
-static const unsigned char yyr1[] =
-{
- 0, 24, 25, 26, 26, 26, 26, 26, 26, 26,
- 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
- 26, 26, 26
-};
-
-/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
-static const unsigned char yyr2[] =
-{
- 0, 2, 1, 1, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 2, 2, 3, 3, 3,
- 3, 3, 5
-};
-
-/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
- STATE-NUM when YYTABLE doesn't specify something else to do. Zero
- means the default is an error. */
-static const unsigned char yydefact[] =
-{
- 0, 0, 0, 0, 3, 0, 2, 15, 16, 0,
- 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 4, 0, 5,
- 6, 12, 11, 10, 9, 8, 7, 14, 13, 19,
- 18, 17, 21, 20, 0, 22
-};
-
-/* YYDEFGOTO[NTERM-NUM]. */
-static const yysigned_char yydefgoto[] =
-{
- -1, 5, 6
-};
-
-/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
- STATE-NUM. */
-#define YYPACT_NINF -13
-static const yysigned_char yypact[] =
-{
- 109, 109, 109, 109, -13, 6, 59, 106, 106, 22,
- -13, 109, 109, 109, 109, 109, 109, 109, 109, 109,
- 109, 109, 109, 109, 109, 109, 109, -13, 42, 90,
- 104, 120, 120, 120, 120, 120, 120, -12, -12, 106,
- 106, 106, -13, -13, 109, 75
-};
-
-/* YYPGOTO[NTERM-NUM]. */
-static const yysigned_char yypgoto[] =
-{
- -13, -13, -1
-};
-
-/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
- positive, shift that token. If negative, reduce the rule which
- number is the opposite. If zero, do what YYDEFACT says.
- If YYTABLE_NINF, syntax error. */
-#define YYTABLE_NINF -1
-static const unsigned char yytable[] =
-{
- 7, 8, 9, 22, 23, 24, 10, 25, 26, 0,
- 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
- 38, 39, 40, 41, 42, 43, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 0, 25, 26, 45, 27, 44, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 0, 25, 26, 11, 12, 13, 14, 15, 16, 17,
- 18, 19, 20, 21, 22, 23, 24, 0, 25, 26,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
- 22, 23, 24, 0, 25, 26, 13, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 23, 24, 0, 25,
- 26, 14, 15, 16, 17, 18, 19, 20, 21, 22,
- 23, 24, 1, 25, 26, 25, 26, 2, 0, 0,
- 3, 0, 4, 20, 21, 22, 23, 24, 0, 25,
- 26
-};
-
-static const yysigned_char yycheck[] =
-{
- 1, 2, 3, 15, 16, 17, 0, 19, 20, -1,
- 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
- -1, 19, 20, 44, 22, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
- -1, 19, 20, 4, 5, 6, 7, 8, 9, 10,
- 11, 12, 13, 14, 15, 16, 17, -1, 19, 20,
- 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, -1, 19, 20, 6, 7, 8, 9,
- 10, 11, 12, 13, 14, 15, 16, 17, -1, 19,
- 20, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 13, 19, 20, 19, 20, 18, -1, -1,
- 21, -1, 23, 13, 14, 15, 16, 17, -1, 19,
- 20
-};
-
-/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
- symbol of state STATE-NUM. */
-static const unsigned char yystos[] =
-{
- 0, 13, 18, 21, 23, 25, 26, 26, 26, 26,
- 0, 4, 5, 6, 7, 8, 9, 10, 11, 12,
- 13, 14, 15, 16, 17, 19, 20, 22, 26, 26,
- 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
- 26, 26, 26, 26, 3, 26
-};
-
-#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
-# define YYSIZE_T __SIZE_TYPE__
-#endif
-#if ! defined (YYSIZE_T) && defined (size_t)
-# define YYSIZE_T size_t
-#endif
-#if ! defined (YYSIZE_T)
-# if defined (__STDC__) || defined (__cplusplus)
-# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
-# define YYSIZE_T size_t
-# endif
-#endif
-#if ! defined (YYSIZE_T)
-# define YYSIZE_T unsigned int
-#endif
-
-#define yyerrok (yyerrstatus = 0)
-#define yyclearin (yychar = YYEMPTY)
-#define YYEMPTY (-2)
-#define YYEOF 0
-
-#define YYACCEPT goto yyacceptlab
-#define YYABORT goto yyabortlab
-#define YYERROR goto yyerrorlab
-
-
-/* Like YYERROR except do call yyerror. This remains here temporarily
- to ease the transition to the new meaning of YYERROR, for GCC.
- Once GCC version 2 has supplanted version 1, this can go. */
-
-#define YYFAIL goto yyerrlab
-
-#define YYRECOVERING() (!!yyerrstatus)
-
-#define YYBACKUP(Token, Value) \
-do \
- if (yychar == YYEMPTY && yylen == 1) \
- { \
- yychar = (Token); \
- yylval = (Value); \
- yytoken = YYTRANSLATE (yychar); \
- YYPOPSTACK; \
- goto yybackup; \
- } \
- else \
- { \
- yyerror ("syntax error: cannot back up");\
- YYERROR; \
- } \
-while (0)
-
-
-#define YYTERROR 1
-#define YYERRCODE 256
-
-
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
-#define YYRHSLOC(Rhs, K) ((Rhs)[K])
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (N) \
- { \
- (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = \
- YYRHSLOC (Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = \
- YYRHSLOC (Rhs, 0).last_column; \
- } \
- while (0)
-#endif
-
-
-/* YY_LOCATION_PRINT -- Print the location on the stream.
- This macro was not mandated originally: define only if we know
- we won't break user code: when these are the locations we know. */
-
-#ifndef YY_LOCATION_PRINT
-# if YYLTYPE_IS_TRIVIAL
-# define YY_LOCATION_PRINT(File, Loc) \
- fprintf (File, "%d.%d-%d.%d", \
- (Loc).first_line, (Loc).first_column, \
- (Loc).last_line, (Loc).last_column)
-# else
-# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
-# endif
-#endif
-
-
-/* YYLEX -- calling `yylex' with the right arguments. */
-
-#ifdef YYLEX_PARAM
-# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
-#else
-# define YYLEX yylex (&yylval, &yylloc)
-#endif
-
-/* Enable debugging if requested. */
-#if YYDEBUG
-
-# ifndef YYFPRINTF
-# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
-# define YYFPRINTF fprintf
-# endif
-
-# define YYDPRINTF(Args) \
-do { \
- if (yydebug) \
- YYFPRINTF Args; \
-} while (0)
-
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
-do { \
- if (yydebug) \
- { \
- YYFPRINTF (stderr, "%s ", Title); \
- yysymprint (stderr, \
- Type, Value, Location); \
- YYFPRINTF (stderr, "\n"); \
- } \
-} while (0)
-
-/*------------------------------------------------------------------.
-| yy_stack_print -- Print the state stack from its BOTTOM up to its |
-| TOP (included). |
-`------------------------------------------------------------------*/
-
-#if defined (__STDC__) || defined (__cplusplus)
-static void
-yy_stack_print (short int *bottom, short int *top)
-#else
-static void
-yy_stack_print (bottom, top)
- short int *bottom;
- short int *top;
-#endif
-{
- YYFPRINTF (stderr, "Stack now");
- for (/* Nothing. */; bottom <= top; ++bottom)
- YYFPRINTF (stderr, " %d", *bottom);
- YYFPRINTF (stderr, "\n");
-}
-
-# define YY_STACK_PRINT(Bottom, Top) \
-do { \
- if (yydebug) \
- yy_stack_print ((Bottom), (Top)); \
-} while (0)
-
-
-/*------------------------------------------------.
-| Report that the YYRULE is going to be reduced. |
-`------------------------------------------------*/
-
-#if defined (__STDC__) || defined (__cplusplus)
-static void
-yy_reduce_print (int yyrule)
-#else
-static void
-yy_reduce_print (yyrule)
- int yyrule;
-#endif
-{
- int yyi;
- unsigned int yylno = yyrline[yyrule];
- YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
- yyrule - 1, yylno);
- /* Print the symbols being reduced, and their result. */
- for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
- YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
- YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
-}
-
-# define YY_REDUCE_PRINT(Rule) \
-do { \
- if (yydebug) \
- yy_reduce_print (Rule); \
-} while (0)
-
-/* Nonzero means print parse trace. It is left uninitialized so that
- multiple parsers can coexist. */
-int yydebug;
-#else /* !YYDEBUG */
-# define YYDPRINTF(Args)
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
-# define YY_STACK_PRINT(Bottom, Top)
-# define YY_REDUCE_PRINT(Rule)
-#endif /* !YYDEBUG */
-
-
-/* YYINITDEPTH -- initial size of the parser's stacks. */
-#ifndef YYINITDEPTH
-# define YYINITDEPTH 200
-#endif
-
-/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
- if the built-in stack extension method is used).
-
- Do not make this value too large; the results are undefined if
- SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
- evaluated with infinite-precision integer arithmetic. */
-
-#ifndef YYMAXDEPTH
-# define YYMAXDEPTH 10000
-#endif
-
-
-
-#if YYERROR_VERBOSE
-
-# ifndef yystrlen
-# if defined (__GLIBC__) && defined (_STRING_H)
-# define yystrlen strlen
-# else
-/* Return the length of YYSTR. */
-static YYSIZE_T
-# if defined (__STDC__) || defined (__cplusplus)
-yystrlen (const char *yystr)
-# else
-yystrlen (yystr)
- const char *yystr;
-# endif
-{
- register const char *yys = yystr;
-
- while (*yys++ != '\0')
- continue;
-
- return yys - yystr - 1;
-}
-# endif
-# endif
-
-# ifndef yystpcpy
-# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
-# define yystpcpy stpcpy
-# else
-/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
- YYDEST. */
-static char *
-# if defined (__STDC__) || defined (__cplusplus)
-yystpcpy (char *yydest, const char *yysrc)
-# else
-yystpcpy (yydest, yysrc)
- char *yydest;
- const char *yysrc;
-# endif
-{
- register char *yyd = yydest;
- register const char *yys = yysrc;
-
- while ((*yyd++ = *yys++) != '\0')
- continue;
-
- return yyd - 1;
-}
-# endif
-# endif
-
-#endif /* !YYERROR_VERBOSE */
-
-
-
-#if YYDEBUG
-/*--------------------------------.
-| Print this symbol on YYOUTPUT. |
-`--------------------------------*/
-
-#if defined (__STDC__) || defined (__cplusplus)
-static void
-yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
-#else
-static void
-yysymprint (yyoutput, yytype, yyvaluep, yylocationp)
- FILE *yyoutput;
- int yytype;
- YYSTYPE *yyvaluep;
- YYLTYPE *yylocationp;
-#endif
-{
- /* Pacify ``unused variable'' warnings. */
- (void) yyvaluep;
- (void) yylocationp;
-
- if (yytype < YYNTOKENS)
- YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
- else
- YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
-
- YY_LOCATION_PRINT (yyoutput, *yylocationp);
- fprintf (yyoutput, ": ");
-
-# ifdef YYPRINT
- if (yytype < YYNTOKENS)
- YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
-# endif
- switch (yytype)
- {
- default:
- break;
- }
- YYFPRINTF (yyoutput, ")");
-}
-
-#endif /* ! YYDEBUG */
-/*-----------------------------------------------.
-| Release the memory associated to this symbol. |
-`-----------------------------------------------*/
-
-#if defined (__STDC__) || defined (__cplusplus)
-static void
-yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
-#else
-static void
-yydestruct (yymsg, yytype, yyvaluep, yylocationp)
- const char *yymsg;
- int yytype;
- YYSTYPE *yyvaluep;
- YYLTYPE *yylocationp;
-#endif
-{
- /* Pacify ``unused variable'' warnings. */
- (void) yyvaluep;
- (void) yylocationp;
-
- if (!yymsg)
- yymsg = "Deleting";
- YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
-
- switch (yytype)
- {
-
- default:
- break;
- }
-}
-
-
-/* Prevent warnings from -Wmissing-prototypes. */
-
-#ifdef YYPARSE_PARAM
-# if defined (__STDC__) || defined (__cplusplus)
-int yyparse (void *YYPARSE_PARAM);
-# else
-int yyparse ();
-# endif
-#else /* ! YYPARSE_PARAM */
-#if defined (__STDC__) || defined (__cplusplus)
-int yyparse (void);
-#else
-int yyparse ();
-#endif
-#endif /* ! YYPARSE_PARAM */
-
-
-
-
-
-
-/*----------.
-| yyparse. |
-`----------*/
-
-#ifdef YYPARSE_PARAM
-# if defined (__STDC__) || defined (__cplusplus)
-int yyparse (void *YYPARSE_PARAM)
-# else
-int yyparse (YYPARSE_PARAM)
- void *YYPARSE_PARAM;
-# endif
-#else /* ! YYPARSE_PARAM */
-#if defined (__STDC__) || defined (__cplusplus)
-int
-yyparse (void)
-#else
-int
-yyparse ()
-
-#endif
-#endif
-{
- /* The look-ahead symbol. */
-int yychar;
-
-/* The semantic value of the look-ahead symbol. */
-YYSTYPE yylval;
-
-/* Number of syntax errors so far. */
-int yynerrs;
-/* Location data for the look-ahead symbol. */
-YYLTYPE yylloc;
-
- register int yystate;
- register int yyn;
- int yyresult;
- /* Number of tokens to shift before error messages enabled. */
- int yyerrstatus;
- /* Look-ahead token as an internal (translated) token number. */
- int yytoken = 0;
-
- /* Three stacks and their tools:
- `yyss': related to states,
- `yyvs': related to semantic values,
- `yyls': related to locations.
-
- Refer to the stacks thru separate pointers, to allow yyoverflow
- to reallocate them elsewhere. */
-
- /* The state stack. */
- short int yyssa[YYINITDEPTH];
- short int *yyss = yyssa;
- register short int *yyssp;
-
- /* The semantic value stack. */
- YYSTYPE yyvsa[YYINITDEPTH];
- YYSTYPE *yyvs = yyvsa;
- register YYSTYPE *yyvsp;
-
- /* The location stack. */
- YYLTYPE yylsa[YYINITDEPTH];
- YYLTYPE *yyls = yylsa;
- YYLTYPE *yylsp;
- /* The locations where the error started and ended. */
- YYLTYPE yyerror_range[2];
-
-#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
-
- YYSIZE_T yystacksize = YYINITDEPTH;
-
- /* The variables used to return semantic value and location from the
- action routines. */
- YYSTYPE yyval;
- YYLTYPE yyloc;
-
- /* When reducing, the number of symbols on the RHS of the reduced
- rule. */
- int yylen;
-
- YYDPRINTF ((stderr, "Starting parse\n"));
-
- yystate = 0;
- yyerrstatus = 0;
- yynerrs = 0;
- yychar = YYEMPTY; /* Cause a token to be read. */
-
- /* Initialize stack pointers.
- Waste one element of value and location stack
- so that they stay on the same level as the state stack.
- The wasted elements are never initialized. */
-
- yyssp = yyss;
- yyvsp = yyvs;
- yylsp = yyls;
-#if YYLTYPE_IS_TRIVIAL
- /* Initialize the default location before parsing starts. */
- yylloc.first_line = yylloc.last_line = 1;
- yylloc.first_column = yylloc.last_column = 0;
-#endif
-
-
- yyvsp[0] = yylval;
- yylsp[0] = yylloc;
-
- goto yysetstate;
-
-/*------------------------------------------------------------.
-| yynewstate -- Push a new state, which is found in yystate. |
-`------------------------------------------------------------*/
- yynewstate:
- /* In all cases, when you get here, the value and location stacks
- have just been pushed. so pushing a state here evens the stacks.
- */
- yyssp++;
-
- yysetstate:
- *yyssp = yystate;
-
- if (yyss + yystacksize - 1 <= yyssp)
- {
- /* Get the current used size of the three stacks, in elements. */
- YYSIZE_T yysize = yyssp - yyss + 1;
-
-#ifdef yyoverflow
- {
- /* Give user a chance to reallocate the stack. Use copies of
- these so that the &'s don't force the real ones into
- memory. */
- YYSTYPE *yyvs1 = yyvs;
- short int *yyss1 = yyss;
- YYLTYPE *yyls1 = yyls;
-
- /* Each stack pointer address is followed by the size of the
- data in use in that stack, in bytes. This used to be a
- conditional around just the two extra args, but that might
- be undefined if yyoverflow is a macro. */
- yyoverflow ("parser stack overflow",
- &yyss1, yysize * sizeof (*yyssp),
- &yyvs1, yysize * sizeof (*yyvsp),
- &yyls1, yysize * sizeof (*yylsp),
- &yystacksize);
- yyls = yyls1;
- yyss = yyss1;
- yyvs = yyvs1;
- }
-#else /* no yyoverflow */
-# ifndef YYSTACK_RELOCATE
- goto yyoverflowlab;
-# else
- /* Extend the stack our own way. */
- if (YYMAXDEPTH <= yystacksize)
- goto yyoverflowlab;
- yystacksize *= 2;
- if (YYMAXDEPTH < yystacksize)
- yystacksize = YYMAXDEPTH;
-
- {
- short int *yyss1 = yyss;
- union yyalloc *yyptr =
- (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
- if (! yyptr)
- goto yyoverflowlab;
- YYSTACK_RELOCATE (yyss);
- YYSTACK_RELOCATE (yyvs);
- YYSTACK_RELOCATE (yyls);
-# undef YYSTACK_RELOCATE
- if (yyss1 != yyssa)
- YYSTACK_FREE (yyss1);
- }
-# endif
-#endif /* no yyoverflow */
-
- yyssp = yyss + yysize - 1;
- yyvsp = yyvs + yysize - 1;
- yylsp = yyls + yysize - 1;
-
- YYDPRINTF ((stderr, "Stack size increased to %lu\n",
- (unsigned long int) yystacksize));
-
- if (yyss + yystacksize - 1 <= yyssp)
- YYABORT;
- }
-
- YYDPRINTF ((stderr, "Entering state %d\n", yystate));
-
- goto yybackup;
-
-/*-----------.
-| yybackup. |
-`-----------*/
-yybackup:
-
-/* Do appropriate processing given the current state. */
-/* Read a look-ahead token if we need one and don't already have one. */
-/* yyresume: */
-
- /* First try to decide what to do without reference to look-ahead token. */
-
- yyn = yypact[yystate];
- if (yyn == YYPACT_NINF)
- goto yydefault;
-
- /* Not known => get a look-ahead token if don't already have one. */
-
- /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
- if (yychar == YYEMPTY)
- {
- YYDPRINTF ((stderr, "Reading a token: "));
- yychar = YYLEX;
- }
-
- if (yychar <= YYEOF)
- {
- yychar = yytoken = YYEOF;
- YYDPRINTF ((stderr, "Now at end of input.\n"));
- }
- else
- {
- yytoken = YYTRANSLATE (yychar);
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
- }
-
- /* If the proper action on seeing token YYTOKEN is to reduce or to
- detect an error, take that action. */
- yyn += yytoken;
- if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
- goto yydefault;
- yyn = yytable[yyn];
- if (yyn <= 0)
- {
- if (yyn == 0 || yyn == YYTABLE_NINF)
- goto yyerrlab;
- yyn = -yyn;
- goto yyreduce;
- }
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
- /* Shift the look-ahead token. */
- YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
-
- /* Discard the token being shifted unless it is eof. */
- if (yychar != YYEOF)
- yychar = YYEMPTY;
-
- *++yyvsp = yylval;
- *++yylsp = yylloc;
-
- /* Count tokens shifted since error; after three, turn off error
- status. */
- if (yyerrstatus)
- yyerrstatus--;
-
- yystate = yyn;
- goto yynewstate;
-
-
-/*-----------------------------------------------------------.
-| yydefault -- do the default action for the current state. |
-`-----------------------------------------------------------*/
-yydefault:
- yyn = yydefact[yystate];
- if (yyn == 0)
- goto yyerrlab;
- goto yyreduce;
-
-
-/*-----------------------------.
-| yyreduce -- Do a reduction. |
-`-----------------------------*/
-yyreduce:
- /* yyn is the number of a rule to reduce with. */
- yylen = yyr2[yyn];
-
- /* If YYLEN is nonzero, implement the default value of the action:
- `$$ = $1'.
-
- Otherwise, the following line sets YYVAL to garbage.
- This behavior is undocumented and Bison
- users should not rely upon it. Assigning to YYVAL
- unconditionally makes the parser a bit smaller, and it avoids a
- GCC warning that YYVAL may be used uninitialized. */
- yyval = yyvsp[1-yylen];
-
- /* Default location. */
- YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);
- YY_REDUCE_PRINT (yyn);
- switch (yyn)
- {
- case 2:
-#line 165 "ast_expr2.y"
- { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
- ((struct parse_io *)parseio)->val->type = (yyvsp[0].val)->type;
- if( (yyvsp[0].val)->type == AST_EXPR_integer )
- ((struct parse_io *)parseio)->val->u.i = (yyvsp[0].val)->u.i;
- else
- ((struct parse_io *)parseio)->val->u.s = (yyvsp[0].val)->u.s;
- free((yyvsp[0].val));
- ;}
- break;
-
- case 3:
-#line 175 "ast_expr2.y"
- { (yyval.val)= (yyvsp[0].val);;}
- break;
-
- case 4:
-#line 176 "ast_expr2.y"
- { (yyval.val) = (yyvsp[-1].val);
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;
- DESTROY((yyvsp[-2].val)); DESTROY((yyvsp[0].val)); ;}
- break;
-
- case 5:
-#line 180 "ast_expr2.y"
- { (yyval.val) = op_or ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 6:
-#line 184 "ast_expr2.y"
- { (yyval.val) = op_and ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 7:
-#line 188 "ast_expr2.y"
- { (yyval.val) = op_eq ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 8:
-#line 192 "ast_expr2.y"
- { (yyval.val) = op_gt ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 9:
-#line 196 "ast_expr2.y"
- { (yyval.val) = op_lt ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 10:
-#line 200 "ast_expr2.y"
- { (yyval.val) = op_ge ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 11:
-#line 204 "ast_expr2.y"
- { (yyval.val) = op_le ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 12:
-#line 208 "ast_expr2.y"
- { (yyval.val) = op_ne ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 13:
-#line 212 "ast_expr2.y"
- { (yyval.val) = op_plus ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 14:
-#line 216 "ast_expr2.y"
- { (yyval.val) = op_minus ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 15:
-#line 220 "ast_expr2.y"
- { (yyval.val) = op_negate ((yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-1]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 16:
-#line 224 "ast_expr2.y"
- { (yyval.val) = op_compl ((yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-1]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 17:
-#line 228 "ast_expr2.y"
- { (yyval.val) = op_times ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 18:
-#line 232 "ast_expr2.y"
- { (yyval.val) = op_div ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 19:
-#line 236 "ast_expr2.y"
- { (yyval.val) = op_rem ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 20:
-#line 240 "ast_expr2.y"
- { (yyval.val) = op_colon ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 21:
-#line 244 "ast_expr2.y"
- { (yyval.val) = op_eqtilde ((yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
- case 22:
-#line 248 "ast_expr2.y"
- { (yyval.val) = op_cond ((yyvsp[-4].val), (yyvsp[-2].val), (yyvsp[0].val));
- DESTROY((yyvsp[-3].val));
- DESTROY((yyvsp[-1].val));
- (yyloc).first_column = (yylsp[-4]).first_column; (yyloc).last_column = (yylsp[-2]).last_column;
- (yyloc).first_line=0; (yyloc).last_line=0;;}
- break;
-
-
- }
-
-/* Line 1037 of yacc.c. */
-#line 1445 "ast_expr2.c"
-
- yyvsp -= yylen;
- yyssp -= yylen;
- yylsp -= yylen;
-
- YY_STACK_PRINT (yyss, yyssp);
-
- *++yyvsp = yyval;
- *++yylsp = yyloc;
-
- /* Now `shift' the result of the reduction. Determine what state
- that goes to, based on the state we popped back to and the rule
- number reduced by. */
-
- yyn = yyr1[yyn];
-
- yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
- if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
- yystate = yytable[yystate];
- else
- yystate = yydefgoto[yyn - YYNTOKENS];
-
- goto yynewstate;
-
-
-/*------------------------------------.
-| yyerrlab -- here on detecting error |
-`------------------------------------*/
-yyerrlab:
- /* If not already recovering from an error, report this error. */
- if (!yyerrstatus)
- {
- ++yynerrs;
-#if YYERROR_VERBOSE
- yyn = yypact[yystate];
-
- if (YYPACT_NINF < yyn && yyn < YYLAST)
- {
- YYSIZE_T yysize = 0;
- int yytype = YYTRANSLATE (yychar);
- const char* yyprefix;
- char *yymsg;
- int yyx;
-
- /* Start YYX at -YYN if negative to avoid negative indexes in
- YYCHECK. */
- int yyxbegin = yyn < 0 ? -yyn : 0;
-
- /* Stay within bounds of both yycheck and yytname. */
- int yychecklim = YYLAST - yyn;
- int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
- int yycount = 0;
-
- yyprefix = ", expecting ";
- for (yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
- {
- yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
- yycount += 1;
- if (yycount == 5)
- {
- yysize = 0;
- break;
- }
- }
- yysize += (sizeof ("syntax error, unexpected ")
- + yystrlen (yytname[yytype]));
- yymsg = (char *) YYSTACK_ALLOC (yysize);
- if (yymsg != 0)
- {
- char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
- yyp = yystpcpy (yyp, yytname[yytype]);
-
- if (yycount < 5)
- {
- yyprefix = ", expecting ";
- for (yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
- {
- yyp = yystpcpy (yyp, yyprefix);
- yyp = yystpcpy (yyp, yytname[yyx]);
- yyprefix = " or ";
- }
- }
- yyerror (yymsg);
- YYSTACK_FREE (yymsg);
- }
- else
- yyerror ("syntax error; also virtual memory exhausted");
- }
- else
-#endif /* YYERROR_VERBOSE */
- yyerror ("syntax error");
- }
-
- yyerror_range[0] = yylloc;
-
- if (yyerrstatus == 3)
- {
- /* If just tried and failed to reuse look-ahead token after an
- error, discard it. */
-
- if (yychar <= YYEOF)
- {
- /* If at end of input, pop the error token,
- then the rest of the stack, then return failure. */
- if (yychar == YYEOF)
- for (;;)
- {
- yyerror_range[0] = *yylsp;
- YYPOPSTACK;
- if (yyssp == yyss)
- YYABORT;
- yydestruct ("Error: popping",
- yystos[*yyssp], yyvsp, yylsp);
- }
- }
- else
- {
- yydestruct ("Error: discarding", yytoken, &yylval, &yylloc);
- yychar = YYEMPTY;
- }
- }
-
- /* Else will try to reuse look-ahead token after shifting the error
- token. */
- goto yyerrlab1;
-
-
-/*---------------------------------------------------.
-| yyerrorlab -- error raised explicitly by YYERROR. |
-`---------------------------------------------------*/
-yyerrorlab:
-
-#ifdef __GNUC__
- /* Pacify GCC when the user code never invokes YYERROR and the label
- yyerrorlab therefore never appears in user code. */
- if (0)
- goto yyerrorlab;
-#endif
-
- yyerror_range[0] = yylsp[1-yylen];
- yylsp -= yylen;
- yyvsp -= yylen;
- yyssp -= yylen;
- yystate = *yyssp;
- goto yyerrlab1;
-
-
-/*-------------------------------------------------------------.
-| yyerrlab1 -- common code for both syntax error and YYERROR. |
-`-------------------------------------------------------------*/
-yyerrlab1:
- yyerrstatus = 3; /* Each real token shifted decrements this. */
-
- for (;;)
- {
- yyn = yypact[yystate];
- if (yyn != YYPACT_NINF)
- {
- yyn += YYTERROR;
- if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
- {
- yyn = yytable[yyn];
- if (0 < yyn)
- break;
- }
- }
-
- /* Pop the current state because it cannot handle the error token. */
- if (yyssp == yyss)
- YYABORT;
-
- yyerror_range[0] = *yylsp;
- yydestruct ("Error: popping", yystos[yystate], yyvsp, yylsp);
- YYPOPSTACK;
- yystate = *yyssp;
- YY_STACK_PRINT (yyss, yyssp);
- }
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
- *++yyvsp = yylval;
-
- yyerror_range[1] = yylloc;
- /* Using YYLLOC is tempting, but would change the location of
- the look-ahead. YYLOC is available though. */
- YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2);
- *++yylsp = yyloc;
-
- /* Shift the error token. */
- YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
-
- yystate = yyn;
- goto yynewstate;
-
-
-/*-------------------------------------.
-| yyacceptlab -- YYACCEPT comes here. |
-`-------------------------------------*/
-yyacceptlab:
- yyresult = 0;
- goto yyreturn;
-
-/*-----------------------------------.
-| yyabortlab -- YYABORT comes here. |
-`-----------------------------------*/
-yyabortlab:
- yydestruct ("Error: discarding lookahead",
- yytoken, &yylval, &yylloc);
- yychar = YYEMPTY;
- yyresult = 1;
- goto yyreturn;
-
-#ifndef yyoverflow
-/*----------------------------------------------.
-| yyoverflowlab -- parser overflow comes here. |
-`----------------------------------------------*/
-yyoverflowlab:
- yyerror ("parser stack overflow");
- yyresult = 2;
- /* Fall through. */
-#endif
-
-yyreturn:
-#ifndef yyoverflow
- if (yyss != yyssa)
- YYSTACK_FREE (yyss);
-#endif
- return yyresult;
-}
-
-
-#line 255 "ast_expr2.y"
-
-
-static struct val *
-make_integer (quad_t i)
-{
- struct val *vp;
-
- vp = (struct val *) malloc (sizeof (*vp));
- if (vp == NULL) {
- ast_log(LOG_WARNING, "malloc() failed\n");
- return(NULL);
- }
-
- vp->type = AST_EXPR_integer;
- vp->u.i = i;
- return vp;
-}
-
-static struct val *
-make_str (const char *s)
-{
- struct val *vp;
- size_t i;
- int isint;
-
- vp = (struct val *) malloc (sizeof (*vp));
- if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
- ast_log(LOG_WARNING,"malloc() failed\n");
- return(NULL);
- }
-
- for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
- isint && i < strlen(s);
- i++)
- {
- if(!isdigit(s[i]))
- isint = 0;
- }
-
- if (isint)
- vp->type = AST_EXPR_numeric_string;
- else
- vp->type = AST_EXPR_string;
-
- return vp;
-}
-
-
-static void
-free_value (struct val *vp)
-{
- if (vp==NULL) {
- return;
- }
- if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
- free (vp->u.s);
- free(vp);
-}
-
-
-static quad_t
-to_integer (struct val *vp)
-{
- quad_t i;
-
- if (vp == NULL) {
- ast_log(LOG_WARNING,"vp==NULL in to_integer()\n");
- return(0);
- }
-
- if (vp->type == AST_EXPR_integer)
- return 1;
-
- if (vp->type == AST_EXPR_string)
- return 0;
-
- /* vp->type == AST_EXPR_numeric_string, make it numeric */
- errno = 0;
- i = strtoll(vp->u.s, (char**)NULL, 10);
- if (errno != 0) {
- ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s);
- free(vp->u.s);
- vp->u.s = 0;
- return(0);
- }
- free (vp->u.s);
- vp->u.i = i;
- vp->type = AST_EXPR_integer;
- return 1;
-}
-
-static void
-strip_quotes(struct val *vp)
-{
- if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
- return;
-
- if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
- {
- char *f, *t;
- f = vp->u.s;
- t = vp->u.s;
-
- while( *f )
- {
- if( *f && *f != '"' )
- *t++ = *f++;
- else
- f++;
- }
- *t = *f;
- }
-}
-
-static void
-to_string (struct val *vp)
-{
- char *tmp;
-
- if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
- return;
-
- tmp = malloc ((size_t)25);
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"malloc() failed\n");
- return;
- }
-
- sprintf(tmp, "%ld", (long int) vp->u.i);
- vp->type = AST_EXPR_string;
- vp->u.s = tmp;
-}
-
-
-static int
-isstring (struct val *vp)
-{
- /* only TRUE if this string is not a valid integer */
- return (vp->type == AST_EXPR_string);
-}
-
-
-static int
-is_zero_or_null (struct val *vp)
-{
- if (vp->type == AST_EXPR_integer) {
- return (vp->u.i == 0);
- } else {
- return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
- }
- /* NOTREACHED */
-}
-
-#ifdef STANDALONE
-
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
-{
- va_list vars;
- va_start(vars,fmt);
-
- printf("LOG: lev:%d file:%s line:%d func: %s ",
- level, file, line, function);
- vprintf(fmt, vars);
- fflush(stdout);
- va_end(vars);
-}
-
-
-int main(int argc,char **argv) {
- char s[4096];
-
- if (ast_expr(argv[1], s, sizeof(s)))
- printf("=====%s======\n",s);
- else
- printf("No result\n");
-}
-
-#endif
-
-#undef ast_yyerror
-#define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
-
-/* I put the ast_yyerror func in the flex input file,
- because it refers to the buffer state. Best to
- let it access the BUFFER stuff there and not trying
- define all the structs, macros etc. in this file! */
-
-
-static struct val *
-op_or (struct val *a, struct val *b)
-{
- if (is_zero_or_null (a)) {
- free_value (a);
- return (b);
- } else {
- free_value (b);
- return (a);
- }
-}
-
-static struct val *
-op_and (struct val *a, struct val *b)
-{
- if (is_zero_or_null (a) || is_zero_or_null (b)) {
- free_value (a);
- free_value (b);
- return (make_integer ((quad_t)0));
- } else {
- free_value (b);
- return (a);
- }
-}
-
-static struct val *
-op_eq (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
- } else {
-#ifdef DEBUG_FOR_CONVERSIONS
- char buffer[2000];
- sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
-#endif
- (void)to_integer(a);
- (void)to_integer(b);
-#ifdef DEBUG_FOR_CONVERSIONS
- ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
-#endif
- r = make_integer ((quad_t)(a->u.i == b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_gt (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i > b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_lt (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i < b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_ge (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i >= b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_le (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i <= b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_cond (struct val *a, struct val *b, struct val *c)
-{
- struct val *r;
-
- if( isstring(a) )
- {
- if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
- {
- free_value(a);
- free_value(c);
- r = b;
- }
- else
- {
- free_value(a);
- free_value(b);
- r = c;
- }
- }
- else
- {
- (void)to_integer(a);
- if( a->u.i )
- {
- free_value(a);
- free_value(c);
- r = b;
- }
- else
- {
- free_value(a);
- free_value(b);
- r = c;
- }
- }
- return r;
-}
-
-static struct val *
-op_ne (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i != b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static int
-chk_plus (quad_t a, quad_t b, quad_t r)
-{
- /* sum of two positive numbers must be positive */
- if (a > 0 && b > 0 && r <= 0)
- return 1;
- /* sum of two negative numbers must be negative */
- if (a < 0 && b < 0 && r >= 0)
- return 1;
- /* all other cases are OK */
- return 0;
-}
-
-static struct val *
-op_plus (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a)) {
- ast_log(LOG_WARNING,"non-numeric argument\n");
- if (!to_integer (b)) {
- free_value(a);
- free_value(b);
- return make_integer(0);
- } else {
- free_value(a);
- return (b);
- }
- } else if (!to_integer(b)) {
- free_value(b);
- return (a);
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i + b->u.i));
- if (chk_plus (a->u.i, b->u.i, r->u.i)) {
- ast_log(LOG_WARNING,"overflow\n");
- }
- free_value (a);
- free_value (b);
- return r;
-}
-
-static int
-chk_minus (quad_t a, quad_t b, quad_t r)
-{
- /* special case subtraction of QUAD_MIN */
- if (b == QUAD_MIN) {
- if (a >= 0)
- return 1;
- else
- return 0;
- }
- /* this is allowed for b != QUAD_MIN */
- return chk_plus (a, -b, r);
-}
-
-static struct val *
-op_minus (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a)) {
- ast_log(LOG_WARNING, "non-numeric argument\n");
- if (!to_integer (b)) {
- free_value(a);
- free_value(b);
- return make_integer(0);
- } else {
- r = make_integer(0 - b->u.i);
- free_value(a);
- free_value(b);
- return (r);
- }
- } else if (!to_integer(b)) {
- ast_log(LOG_WARNING, "non-numeric argument\n");
- free_value(b);
- return (a);
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i - b->u.i));
- if (chk_minus (a->u.i, b->u.i, r->u.i)) {
- ast_log(LOG_WARNING, "overflow\n");
- }
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_negate (struct val *a)
-{
- struct val *r;
-
- if (!to_integer (a) ) {
- free_value(a);
- ast_log(LOG_WARNING, "non-numeric argument\n");
- return make_integer(0);
- }
-
- r = make_integer (/*(quad_t)*/(- a->u.i));
- if (chk_minus (0, a->u.i, r->u.i)) {
- ast_log(LOG_WARNING, "overflow\n");
- }
- free_value (a);
- return r;
-}
-
-static struct val *
-op_compl (struct val *a)
-{
- int v1 = 1;
- struct val *r;
-
- if( !a )
- {
- v1 = 0;
- }
- else
- {
- switch( a->type )
- {
- case AST_EXPR_integer:
- if( a->u.i == 0 )
- v1 = 0;
- break;
-
- case AST_EXPR_string:
- if( a->u.s == 0 )
- v1 = 0;
- else
- {
- if( a->u.s[0] == 0 )
- v1 = 0;
- else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
- v1 = 0;
- }
- break;
-
- case AST_EXPR_numeric_string:
- if( a->u.s == 0 )
- v1 = 0;
- else
- {
- if( a->u.s[0] == 0 )
- v1 = 0;
- else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
- v1 = 0;
- }
- break;
- }
- }
-
- r = make_integer (!v1);
- free_value (a);
- return r;
-}
-
-static int
-chk_times (quad_t a, quad_t b, quad_t r)
-{
- /* special case: first operand is 0, no overflow possible */
- if (a == 0)
- return 0;
- /* cerify that result of division matches second operand */
- if (r / a != b)
- return 1;
- return 0;
-}
-
-static struct val *
-op_times (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a) || !to_integer (b)) {
- free_value(a);
- free_value(b);
- ast_log(LOG_WARNING, "non-numeric argument\n");
- return(make_integer(0));
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i * b->u.i));
- if (chk_times (a->u.i, b->u.i, r->u.i)) {
- ast_log(LOG_WARNING, "overflow\n");
- }
- free_value (a);
- free_value (b);
- return (r);
-}
-
-static int
-chk_div (quad_t a, quad_t b)
-{
- /* div by zero has been taken care of before */
- /* only QUAD_MIN / -1 causes overflow */
- if (a == QUAD_MIN && b == -1)
- return 1;
- /* everything else is OK */
- return 0;
-}
-
-static struct val *
-op_div (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a)) {
- free_value(a);
- free_value(b);
- ast_log(LOG_WARNING, "non-numeric argument\n");
- return make_integer(0);
- } else if (!to_integer (b)) {
- free_value(a);
- free_value(b);
- ast_log(LOG_WARNING, "non-numeric argument\n");
- return make_integer(INT_MAX);
- }
-
- if (b->u.i == 0) {
- ast_log(LOG_WARNING, "division by zero\n");
- free_value(a);
- free_value(b);
- return make_integer(INT_MAX);
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i / b->u.i));
- if (chk_div (a->u.i, b->u.i)) {
- ast_log(LOG_WARNING, "overflow\n");
- }
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_rem (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a) || !to_integer (b)) {
- ast_log(LOG_WARNING, "non-numeric argument\n");
- free_value(a);
- free_value(b);
- return make_integer(0);
- }
-
- if (b->u.i == 0) {
- ast_log(LOG_WARNING, "div by zero\n");
- free_value(a);
- return(b);
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i % b->u.i));
- /* chk_rem necessary ??? */
- free_value (a);
- free_value (b);
- return r;
-}
-
-
-static struct val *
-op_colon (struct val *a, struct val *b)
-{
- regex_t rp;
- regmatch_t rm[2];
- char errbuf[256];
- int eval;
- struct val *v;
-
- /* coerce to both arguments to strings */
- to_string(a);
- to_string(b);
- /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
- strip_quotes(a);
- strip_quotes(b);
- /* compile regular expression */
- if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
- regerror (eval, &rp, errbuf, sizeof(errbuf));
- ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
- free_value(a);
- free_value(b);
- return make_str("");
- }
-
- /* compare string against pattern */
- /* remember that patterns are anchored to the beginning of the line */
- if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
- if (rm[1].rm_so >= 0) {
- *(a->u.s + rm[1].rm_eo) = '\0';
- v = make_str (a->u.s + rm[1].rm_so);
-
- } else {
- v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
- }
- } else {
- if (rp.re_nsub == 0) {
- v = make_integer ((quad_t)0);
- } else {
- v = make_str ("");
- }
- }
-
- /* free arguments and pattern buffer */
- free_value (a);
- free_value (b);
- regfree (&rp);
-
- return v;
-}
-
-
-static struct val *
-op_eqtilde (struct val *a, struct val *b)
-{
- regex_t rp;
- regmatch_t rm[2];
- char errbuf[256];
- int eval;
- struct val *v;
-
- /* coerce to both arguments to strings */
- to_string(a);
- to_string(b);
- /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
- strip_quotes(a);
- strip_quotes(b);
- /* compile regular expression */
- if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
- regerror (eval, &rp, errbuf, sizeof(errbuf));
- ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
- free_value(a);
- free_value(b);
- return make_str("");
- }
-
- /* compare string against pattern */
- /* remember that patterns are anchored to the beginning of the line */
- if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
- if (rm[1].rm_so >= 0) {
- *(a->u.s + rm[1].rm_eo) = '\0';
- v = make_str (a->u.s + rm[1].rm_so);
-
- } else {
- v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
- }
- } else {
- if (rp.re_nsub == 0) {
- v = make_integer ((quad_t)0);
- } else {
- v = make_str ("");
- }
- }
-
- /* free arguments and pattern buffer */
- free_value (a);
- free_value (b);
- regfree (&rp);
-
- return v;
-}
-
diff --git a/1.2-netsec/ast_expr2.fl b/1.2-netsec/ast_expr2.fl
deleted file mode 100644
index af9bdf4eb..000000000
--- a/1.2-netsec/ast_expr2.fl
+++ /dev/null
@@ -1,189 +0,0 @@
-%{
-/*! \file
- *
- * \brief Dialplan Expression Parser
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <locale.h>
-#include <ctype.h>
-#if !defined(SOLARIS) && !defined(__CYGWIN__)
-#include <err.h>
-#else
-#define quad_t int64_t
-#endif
-#include <errno.h>
-#include <regex.h>
-#include <limits.h>
-#include <asterisk/ast_expr.h>
-#include <asterisk/logger.h>
-#include <asterisk/strings.h>
-
-enum valtype {
- AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
-} ;
-
-struct val {
- enum valtype type;
- union {
- char *s;
- quad_t i;
- } u;
-} ;
-
-#include "ast_expr2.h" /* the o/p of the bison on ast_expr2.y */
-
-#define SET_COLUMNS yylloc_param->first_column = (int)(yyg->yytext_r - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf);yylloc_param->last_column = yylloc_param->last_column + yyleng - 1; yylloc_param->first_line = yylloc_param->last_line = 1
-#define SET_STRING yylval_param->val = (struct val *)calloc(sizeof(struct val),1); yylval_param->val->type = AST_EXPR_string; yylval_param->val->u.s = strdup(yytext);
-#define SET_NUMERIC_STRING yylval_param->val = (struct val *)calloc(sizeof(struct val),1); yylval_param->val->type = AST_EXPR_numeric_string; yylval_param->val->u.s = strdup(yytext);
-
-struct parse_io
-{
- char *string;
- struct val *val;
- yyscan_t scanner;
-};
-
-void ast_yyset_column(int column_no, yyscan_t yyscanner);
-int ast_yyget_column(yyscan_t yyscanner);
-static int curlycount = 0;
-%}
-
-%option prefix="ast_yy"
-%option batch
-%option outfile="ast_expr2f.c"
-%option reentrant
-%option bison-bridge
-%option bison-locations
-%option noyywrap
-%x var trail
-
-%%
-
-\| { SET_COLUMNS; SET_STRING; return TOK_OR;}
-\& { SET_COLUMNS; SET_STRING; return TOK_AND;}
-\= { SET_COLUMNS; SET_STRING; return TOK_EQ;}
-\> { SET_COLUMNS; SET_STRING; return TOK_GT;}
-\< { SET_COLUMNS; SET_STRING; return TOK_LT;}
-\>\= { SET_COLUMNS; SET_STRING; return TOK_GE;}
-\<\= { SET_COLUMNS; SET_STRING; return TOK_LE;}
-\!\= { SET_COLUMNS; SET_STRING; return TOK_NE;}
-\+ { SET_COLUMNS; SET_STRING; return TOK_PLUS;}
-\- { SET_COLUMNS; SET_STRING; return TOK_MINUS;}
-\* { SET_COLUMNS; SET_STRING; return TOK_MULT;}
-\/ { SET_COLUMNS; SET_STRING; return TOK_DIV;}
-\% { SET_COLUMNS; SET_STRING; return TOK_MOD;}
-\? { SET_COLUMNS; SET_STRING; return TOK_COND;}
-\: { SET_COLUMNS; SET_STRING; return TOK_COLON;}
-\:\: { SET_COLUMNS; SET_STRING; return TOK_COLONCOLON;}
-\( { SET_COLUMNS; SET_STRING; return TOK_LP;}
-\) { SET_COLUMNS; SET_STRING; return TOK_RP;}
-\$\{ {/* gather the contents of ${} expressions, with trailing stuff, into a single TOKEN. They are much more complex now than they used to be */
- curlycount = 0; BEGIN(var); yymore();}
-
-[ \r] {}
-\"[^"]*\" {SET_COLUMNS; SET_STRING; return TOKEN;}
-
-[\n] {/* what to do with eol */}
-[0-9]+ { SET_COLUMNS; /* the original behavior of the expression parser was to bring in numbers as a numeric string */
- SET_NUMERIC_STRING;
- return TOKEN;}
-[a-zA-Z0-9,.';\\_^%$#@!]+ {SET_COLUMNS; SET_STRING; return TOKEN;}
-
-<var>[^{}]*\} {curlycount--; if(curlycount < 0){ BEGIN(trail); yymore();} else { yymore();}}
-<var>[^{}]*\{ {curlycount++; yymore(); }
-<trail>[^-\t\r \n$():?%/+=*<>!|&]* {BEGIN(0); SET_COLUMNS; SET_STRING; return TOKEN;}
-<trail>[-\t\r \n$():?%/+=*<>!|&] {char c = yytext[yyleng-1]; BEGIN(0); unput(c); SET_COLUMNS; SET_STRING; return TOKEN;}
-<trail>\$\{ {curlycount = 0; BEGIN(var); yymore(); }
-<trail><<EOF>> {BEGIN(0); SET_COLUMNS; SET_STRING; return TOKEN; /* actually, if an expr is only a variable ref, this could happen a LOT */}
-
-%%
-
-/* I'm putting the interface routine to the whole parse here in the flexer input file
- mainly because of all the flexer initialization that has to be done. Shouldn't matter
- where it is, as long as it's somewhere. I didn't want to define a prototype for the
- ast_yy_scan_string in the .y file, because then, I'd have to define YY_BUFFER_STATE there...
- UGH! that would be inappropriate. */
-
-int ast_yyparse(void *); /* need to/should define this prototype for the call to yyparse */
-int ast_yyerror(const char *, YYLTYPE *, struct parse_io *); /* likewise */
-
-int ast_expr(char *expr, char *buf, int length)
-{
- struct parse_io io;
- int return_value = 0;
-
- memset(&io, 0, sizeof(io));
- io.string = expr; /* to pass to the error routine */
-
- ast_yylex_init(&io.scanner);
-
- ast_yy_scan_string(expr, io.scanner);
-
- ast_yyparse ((void *) &io);
-
- ast_yylex_destroy(io.scanner);
-
- if (!io.val) {
- if (length > 1) {
- strcpy(buf, "0");
- return_value = 1;
- }
- } else {
- if (io.val->type == AST_EXPR_integer) {
- int res_length;
-
- res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i);
- return_value = (res_length <= length) ? res_length : length;
- } else {
-#ifdef STANDALONE
- strncpy(buf, io.val->u.s, length - 1);
-#else /* !STANDALONE */
- ast_copy_string(buf, io.val->u.s, length);
-#endif /* STANDALONE */
- return_value = strlen(buf);
- free(io.val->u.s);
- }
- free(io.val);
- }
- return return_value;
-}
-
-int ast_yyerror (const char *s, yyltype *loc, struct parse_io *parseio )
-{
- struct yyguts_t * yyg = (struct yyguts_t*)(parseio->scanner);
- char spacebuf[8000]; /* best safe than sorry */
- char spacebuf2[8000]; /* best safe than sorry */
- int i=0;
- spacebuf[0] = 0;
-
- for(i=0;i< (int)(yytext - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf);i++) spacebuf2[i] = ' '; /* uh... assuming yyg is defined, then I can use the yycolumn macro,
- which is the same thing as... get this:
- yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]->yy_bs_column
- I was tempted to just use yy_buf_pos in the STATE, but..., well:
- a. the yy_buf_pos is the current position in the buffer, which
- may not relate to the entire string/buffer because of the
- buffering.
- b. but, analysis of the situation is that when you use the
- yy_scan_string func, it creates a single buffer the size of
- string, so the two would be the same...
- so, in the end, the yycolumn macro is available, shorter, therefore easier. */
- spacebuf2[i++]='^';
- spacebuf2[i]= 0;
-
-#ifdef STANDALONE3
- /* easier to read in the standalone version */
- printf("ast_yyerror(): syntax error: %s; Input:\n%s\n%s\n",
- s, parseio->string,spacebuf2);
-#else
- ast_log(LOG_WARNING,"ast_yyerror(): syntax error: %s; Input:\n%s\n%s\n",
- s, parseio->string,spacebuf2);
-#endif
-#ifndef STANDALONE
- ast_log(LOG_WARNING,"If you have questions, please refer to doc/README.variables in the asterisk source.\n");
-#endif
- return(0);
-}
diff --git a/1.2-netsec/ast_expr2.h b/1.2-netsec/ast_expr2.h
deleted file mode 100644
index 1afe7d180..000000000
--- a/1.2-netsec/ast_expr2.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/* A Bison parser, made by GNU Bison 2.0. */
-
-/* Skeleton parser for Yacc-like parsing with Bison,
- Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-/* As a special exception, when this file is copied by Bison into a
- Bison output file, you may use that output file without restriction.
- This special exception was added by the Free Software Foundation
- in version 1.24 of Bison. */
-
-/* Tokens. */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
- /* Put the tokens into the symbol table, so that GDB and other debuggers
- know about them. */
- enum yytokentype {
- TOK_COLONCOLON = 258,
- TOK_COND = 259,
- TOK_OR = 260,
- TOK_AND = 261,
- TOK_NE = 262,
- TOK_LE = 263,
- TOK_GE = 264,
- TOK_LT = 265,
- TOK_GT = 266,
- TOK_EQ = 267,
- TOK_MINUS = 268,
- TOK_PLUS = 269,
- TOK_MOD = 270,
- TOK_DIV = 271,
- TOK_MULT = 272,
- TOK_COMPL = 273,
- TOK_EQTILDE = 274,
- TOK_COLON = 275,
- TOK_LP = 276,
- TOK_RP = 277,
- TOKEN = 278
- };
-#endif
-#define TOK_COLONCOLON 258
-#define TOK_COND 259
-#define TOK_OR 260
-#define TOK_AND 261
-#define TOK_NE 262
-#define TOK_LE 263
-#define TOK_GE 264
-#define TOK_LT 265
-#define TOK_GT 266
-#define TOK_EQ 267
-#define TOK_MINUS 268
-#define TOK_PLUS 269
-#define TOK_MOD 270
-#define TOK_DIV 271
-#define TOK_MULT 272
-#define TOK_COMPL 273
-#define TOK_EQTILDE 274
-#define TOK_COLON 275
-#define TOK_LP 276
-#define TOK_RP 277
-#define TOKEN 278
-
-
-
-
-#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
-#line 142 "ast_expr2.y"
-typedef union YYSTYPE {
- struct val *val;
-} YYSTYPE;
-/* Line 1318 of yacc.c. */
-#line 87 "ast_expr2.h"
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
-# define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
-#endif
-
-
-
-#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
-typedef struct YYLTYPE
-{
- int first_line;
- int first_column;
- int last_line;
- int last_column;
-} YYLTYPE;
-# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
-# define YYLTYPE_IS_DECLARED 1
-# define YYLTYPE_IS_TRIVIAL 1
-#endif
-
-
-
-
diff --git a/1.2-netsec/ast_expr2.y b/1.2-netsec/ast_expr2.y
deleted file mode 100644
index ef3289bc1..000000000
--- a/1.2-netsec/ast_expr2.y
+++ /dev/null
@@ -1,993 +0,0 @@
-%{
-/* Written by Pace Willisson (pace@blitz.com)
- * and placed in the public domain.
- *
- * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
- *
- * And then overhauled twice by Steve Murphy (murf@e-tools.com)
- * to add double-quoted strings, allow mult. spaces, improve
- * error messages, and then to fold in a flex scanner for the
- * yylex operation.
- *
- * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <locale.h>
-#include <ctype.h>
-#if !defined(SOLARIS) && !defined(__CYGWIN__)
-#include <err.h>
-#else
-#define quad_t int64_t
-#endif
-#include <errno.h>
-#include <regex.h>
-#include <limits.h>
-#include <asterisk/ast_expr.h>
-#include <asterisk/logger.h>
-
-#ifdef LONG_LONG_MIN
-#define QUAD_MIN LONG_LONG_MIN
-#endif
-#ifdef LONG_LONG_MAX
-#define QUAD_MAX LONG_LONG_MAX
-#endif
-
-# if ! defined(QUAD_MIN)
-# define QUAD_MIN (-0x7fffffffffffffffLL-1)
-# endif
-# if ! defined(QUAD_MAX)
-# define QUAD_MAX (0x7fffffffffffffffLL)
-# endif
-
-#define YYPARSE_PARAM parseio
-#define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
-#define YYERROR_VERBOSE 1
-
-enum valtype {
- AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
-} ;
-
-#ifdef STANDALONE
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
-#endif
-
-struct val {
- enum valtype type;
- union {
- char *s;
- quad_t i;
- } u;
-} ;
-
-typedef void *yyscan_t;
-
-struct parse_io
-{
- char *string;
- struct val *val;
- yyscan_t scanner;
-};
-
-static int chk_div __P((quad_t, quad_t));
-static int chk_minus __P((quad_t, quad_t, quad_t));
-static int chk_plus __P((quad_t, quad_t, quad_t));
-static int chk_times __P((quad_t, quad_t, quad_t));
-static void free_value __P((struct val *));
-static int is_zero_or_null __P((struct val *));
-static int isstring __P((struct val *));
-static struct val *make_integer __P((quad_t));
-static struct val *make_str __P((const char *));
-static struct val *op_and __P((struct val *, struct val *));
-static struct val *op_colon __P((struct val *, struct val *));
-static struct val *op_eqtilde __P((struct val *, struct val *));
-static struct val *op_div __P((struct val *, struct val *));
-static struct val *op_eq __P((struct val *, struct val *));
-static struct val *op_ge __P((struct val *, struct val *));
-static struct val *op_gt __P((struct val *, struct val *));
-static struct val *op_le __P((struct val *, struct val *));
-static struct val *op_lt __P((struct val *, struct val *));
-static struct val *op_cond __P((struct val *, struct val *, struct val *));
-static struct val *op_minus __P((struct val *, struct val *));
-static struct val *op_negate __P((struct val *));
-static struct val *op_compl __P((struct val *));
-static struct val *op_ne __P((struct val *, struct val *));
-static struct val *op_or __P((struct val *, struct val *));
-static struct val *op_plus __P((struct val *, struct val *));
-static struct val *op_rem __P((struct val *, struct val *));
-static struct val *op_times __P((struct val *, struct val *));
-static quad_t to_integer __P((struct val *));
-static void to_string __P((struct val *));
-
-/* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
-typedef struct yyltype
-{
- int first_line;
- int first_column;
-
- int last_line;
- int last_column;
-} yyltype;
-
-# define YYLTYPE yyltype
-# define YYLTYPE_IS_TRIVIAL 1
-
-/* we will get warning about no prototype for yylex! But we can't
- define it here, we have no definition yet for YYSTYPE. */
-
-int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
-
-/* I wanted to add args to the yyerror routine, so I could print out
- some useful info about the error. Not as easy as it looks, but it
- is possible. */
-#define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
-#define DESTROY(x) { \
-if ((x)->type == AST_EXPR_numeric_string || (x)->type == AST_EXPR_string) \
- free((x)->u.s); \
- (x)->u.s = 0; \
- free(x); \
-}
-%}
-
-%pure-parser
-%locations
-/* %debug for when you are having big problems */
-
-/* %name-prefix="ast_yy" */
-
-%union
-{
- struct val *val;
-}
-
-%{
-extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
-%}
-%left <val> TOK_COND TOK_COLONCOLON
-%left <val> TOK_OR
-%left <val> TOK_AND
-%left <val> TOK_EQ TOK_GT TOK_LT TOK_GE TOK_LE TOK_NE
-%left <val> TOK_PLUS TOK_MINUS
-%left <val> TOK_MULT TOK_DIV TOK_MOD
-%right <val> TOK_COMPL
-%left <val> TOK_COLON TOK_EQTILDE
-%left <val> TOK_RP TOK_LP
-
-
-%token <val> TOKEN
-%type <val> start expr
-
-%%
-
-start: expr { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
- ((struct parse_io *)parseio)->val->type = $1->type;
- if( $1->type == AST_EXPR_integer )
- ((struct parse_io *)parseio)->val->u.i = $1->u.i;
- else
- ((struct parse_io *)parseio)->val->u.s = $1->u.s;
- free($1);
- }
- ;
-
-expr: TOKEN { $$= $1;}
- | TOK_LP expr TOK_RP { $$ = $2;
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;
- DESTROY($1); DESTROY($3); }
- | expr TOK_OR expr { $$ = op_or ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_AND expr { $$ = op_and ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_EQ expr { $$ = op_eq ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_GT expr { $$ = op_gt ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_LT expr { $$ = op_lt ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_GE expr { $$ = op_ge ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_LE expr { $$ = op_le ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_NE expr { $$ = op_ne ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_PLUS expr { $$ = op_plus ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_MINUS expr { $$ = op_minus ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | TOK_MINUS expr %prec TOK_COMPL { $$ = op_negate ($2);
- DESTROY($1);
- @$.first_column = @1.first_column; @$.last_column = @2.last_column;
- @$.first_line=0; @$.last_line=0;}
- | TOK_COMPL expr { $$ = op_compl ($2);
- DESTROY($1);
- @$.first_column = @1.first_column; @$.last_column = @2.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_MULT expr { $$ = op_times ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_DIV expr { $$ = op_div ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_MOD expr { $$ = op_rem ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_COLON expr { $$ = op_colon ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_EQTILDE expr { $$ = op_eqtilde ($1, $3);
- DESTROY($2);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- | expr TOK_COND expr TOK_COLONCOLON expr { $$ = op_cond ($1, $3, $5);
- DESTROY($2);
- DESTROY($4);
- @$.first_column = @1.first_column; @$.last_column = @3.last_column;
- @$.first_line=0; @$.last_line=0;}
- ;
-
-%%
-
-static struct val *
-make_integer (quad_t i)
-{
- struct val *vp;
-
- vp = (struct val *) malloc (sizeof (*vp));
- if (vp == NULL) {
- ast_log(LOG_WARNING, "malloc() failed\n");
- return(NULL);
- }
-
- vp->type = AST_EXPR_integer;
- vp->u.i = i;
- return vp;
-}
-
-static struct val *
-make_str (const char *s)
-{
- struct val *vp;
- size_t i;
- int isint;
-
- vp = (struct val *) malloc (sizeof (*vp));
- if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
- ast_log(LOG_WARNING,"malloc() failed\n");
- return(NULL);
- }
-
- for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
- isint && i < strlen(s);
- i++)
- {
- if(!isdigit(s[i]))
- isint = 0;
- }
-
- if (isint)
- vp->type = AST_EXPR_numeric_string;
- else
- vp->type = AST_EXPR_string;
-
- return vp;
-}
-
-
-static void
-free_value (struct val *vp)
-{
- if (vp==NULL) {
- return;
- }
- if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
- free (vp->u.s);
- free(vp);
-}
-
-
-static quad_t
-to_integer (struct val *vp)
-{
- quad_t i;
-
- if (vp == NULL) {
- ast_log(LOG_WARNING,"vp==NULL in to_integer()\n");
- return(0);
- }
-
- if (vp->type == AST_EXPR_integer)
- return 1;
-
- if (vp->type == AST_EXPR_string)
- return 0;
-
- /* vp->type == AST_EXPR_numeric_string, make it numeric */
- errno = 0;
- i = strtoll(vp->u.s, (char**)NULL, 10);
- if (errno != 0) {
- ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s);
- free(vp->u.s);
- vp->u.s = 0;
- return(0);
- }
- free (vp->u.s);
- vp->u.i = i;
- vp->type = AST_EXPR_integer;
- return 1;
-}
-
-static void
-strip_quotes(struct val *vp)
-{
- if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
- return;
-
- if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
- {
- char *f, *t;
- f = vp->u.s;
- t = vp->u.s;
-
- while( *f )
- {
- if( *f && *f != '"' )
- *t++ = *f++;
- else
- f++;
- }
- *t = *f;
- }
-}
-
-static void
-to_string (struct val *vp)
-{
- char *tmp;
-
- if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
- return;
-
- tmp = malloc ((size_t)25);
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"malloc() failed\n");
- return;
- }
-
- sprintf(tmp, "%ld", (long int) vp->u.i);
- vp->type = AST_EXPR_string;
- vp->u.s = tmp;
-}
-
-
-static int
-isstring (struct val *vp)
-{
- /* only TRUE if this string is not a valid integer */
- return (vp->type == AST_EXPR_string);
-}
-
-
-static int
-is_zero_or_null (struct val *vp)
-{
- if (vp->type == AST_EXPR_integer) {
- return (vp->u.i == 0);
- } else {
- return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
- }
- /* NOTREACHED */
-}
-
-#ifdef STANDALONE
-
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
-{
- va_list vars;
- va_start(vars,fmt);
-
- printf("LOG: lev:%d file:%s line:%d func: %s ",
- level, file, line, function);
- vprintf(fmt, vars);
- fflush(stdout);
- va_end(vars);
-}
-
-
-int main(int argc,char **argv) {
- char s[4096];
-
- if (ast_expr(argv[1], s, sizeof(s)))
- printf("=====%s======\n",s);
- else
- printf("No result\n");
-}
-
-#endif
-
-#undef ast_yyerror
-#define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
-
-/* I put the ast_yyerror func in the flex input file,
- because it refers to the buffer state. Best to
- let it access the BUFFER stuff there and not trying
- define all the structs, macros etc. in this file! */
-
-
-static struct val *
-op_or (struct val *a, struct val *b)
-{
- if (is_zero_or_null (a)) {
- free_value (a);
- return (b);
- } else {
- free_value (b);
- return (a);
- }
-}
-
-static struct val *
-op_and (struct val *a, struct val *b)
-{
- if (is_zero_or_null (a) || is_zero_or_null (b)) {
- free_value (a);
- free_value (b);
- return (make_integer ((quad_t)0));
- } else {
- free_value (b);
- return (a);
- }
-}
-
-static struct val *
-op_eq (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
- } else {
-#ifdef DEBUG_FOR_CONVERSIONS
- char buffer[2000];
- sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
-#endif
- (void)to_integer(a);
- (void)to_integer(b);
-#ifdef DEBUG_FOR_CONVERSIONS
- ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
-#endif
- r = make_integer ((quad_t)(a->u.i == b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_gt (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i > b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_lt (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i < b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_ge (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i >= b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_le (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i <= b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_cond (struct val *a, struct val *b, struct val *c)
-{
- struct val *r;
-
- if( isstring(a) )
- {
- if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
- {
- free_value(a);
- free_value(c);
- r = b;
- }
- else
- {
- free_value(a);
- free_value(b);
- r = c;
- }
- }
- else
- {
- (void)to_integer(a);
- if( a->u.i )
- {
- free_value(a);
- free_value(c);
- r = b;
- }
- else
- {
- free_value(a);
- free_value(b);
- r = c;
- }
- }
- return r;
-}
-
-static struct val *
-op_ne (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (isstring (a) || isstring (b)) {
- to_string (a);
- to_string (b);
- r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
- } else {
- (void)to_integer(a);
- (void)to_integer(b);
- r = make_integer ((quad_t)(a->u.i != b->u.i));
- }
-
- free_value (a);
- free_value (b);
- return r;
-}
-
-static int
-chk_plus (quad_t a, quad_t b, quad_t r)
-{
- /* sum of two positive numbers must be positive */
- if (a > 0 && b > 0 && r <= 0)
- return 1;
- /* sum of two negative numbers must be negative */
- if (a < 0 && b < 0 && r >= 0)
- return 1;
- /* all other cases are OK */
- return 0;
-}
-
-static struct val *
-op_plus (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a)) {
- ast_log(LOG_WARNING,"non-numeric argument\n");
- if (!to_integer (b)) {
- free_value(a);
- free_value(b);
- return make_integer(0);
- } else {
- free_value(a);
- return (b);
- }
- } else if (!to_integer(b)) {
- free_value(b);
- return (a);
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i + b->u.i));
- if (chk_plus (a->u.i, b->u.i, r->u.i)) {
- ast_log(LOG_WARNING,"overflow\n");
- }
- free_value (a);
- free_value (b);
- return r;
-}
-
-static int
-chk_minus (quad_t a, quad_t b, quad_t r)
-{
- /* special case subtraction of QUAD_MIN */
- if (b == QUAD_MIN) {
- if (a >= 0)
- return 1;
- else
- return 0;
- }
- /* this is allowed for b != QUAD_MIN */
- return chk_plus (a, -b, r);
-}
-
-static struct val *
-op_minus (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a)) {
- ast_log(LOG_WARNING, "non-numeric argument\n");
- if (!to_integer (b)) {
- free_value(a);
- free_value(b);
- return make_integer(0);
- } else {
- r = make_integer(0 - b->u.i);
- free_value(a);
- free_value(b);
- return (r);
- }
- } else if (!to_integer(b)) {
- ast_log(LOG_WARNING, "non-numeric argument\n");
- free_value(b);
- return (a);
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i - b->u.i));
- if (chk_minus (a->u.i, b->u.i, r->u.i)) {
- ast_log(LOG_WARNING, "overflow\n");
- }
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_negate (struct val *a)
-{
- struct val *r;
-
- if (!to_integer (a) ) {
- free_value(a);
- ast_log(LOG_WARNING, "non-numeric argument\n");
- return make_integer(0);
- }
-
- r = make_integer (/*(quad_t)*/(- a->u.i));
- if (chk_minus (0, a->u.i, r->u.i)) {
- ast_log(LOG_WARNING, "overflow\n");
- }
- free_value (a);
- return r;
-}
-
-static struct val *
-op_compl (struct val *a)
-{
- int v1 = 1;
- struct val *r;
-
- if( !a )
- {
- v1 = 0;
- }
- else
- {
- switch( a->type )
- {
- case AST_EXPR_integer:
- if( a->u.i == 0 )
- v1 = 0;
- break;
-
- case AST_EXPR_string:
- if( a->u.s == 0 )
- v1 = 0;
- else
- {
- if( a->u.s[0] == 0 )
- v1 = 0;
- else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
- v1 = 0;
- }
- break;
-
- case AST_EXPR_numeric_string:
- if( a->u.s == 0 )
- v1 = 0;
- else
- {
- if( a->u.s[0] == 0 )
- v1 = 0;
- else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
- v1 = 0;
- }
- break;
- }
- }
-
- r = make_integer (!v1);
- free_value (a);
- return r;
-}
-
-static int
-chk_times (quad_t a, quad_t b, quad_t r)
-{
- /* special case: first operand is 0, no overflow possible */
- if (a == 0)
- return 0;
- /* cerify that result of division matches second operand */
- if (r / a != b)
- return 1;
- return 0;
-}
-
-static struct val *
-op_times (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a) || !to_integer (b)) {
- free_value(a);
- free_value(b);
- ast_log(LOG_WARNING, "non-numeric argument\n");
- return(make_integer(0));
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i * b->u.i));
- if (chk_times (a->u.i, b->u.i, r->u.i)) {
- ast_log(LOG_WARNING, "overflow\n");
- }
- free_value (a);
- free_value (b);
- return (r);
-}
-
-static int
-chk_div (quad_t a, quad_t b)
-{
- /* div by zero has been taken care of before */
- /* only QUAD_MIN / -1 causes overflow */
- if (a == QUAD_MIN && b == -1)
- return 1;
- /* everything else is OK */
- return 0;
-}
-
-static struct val *
-op_div (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a)) {
- free_value(a);
- free_value(b);
- ast_log(LOG_WARNING, "non-numeric argument\n");
- return make_integer(0);
- } else if (!to_integer (b)) {
- free_value(a);
- free_value(b);
- ast_log(LOG_WARNING, "non-numeric argument\n");
- return make_integer(INT_MAX);
- }
-
- if (b->u.i == 0) {
- ast_log(LOG_WARNING, "division by zero\n");
- free_value(a);
- free_value(b);
- return make_integer(INT_MAX);
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i / b->u.i));
- if (chk_div (a->u.i, b->u.i)) {
- ast_log(LOG_WARNING, "overflow\n");
- }
- free_value (a);
- free_value (b);
- return r;
-}
-
-static struct val *
-op_rem (struct val *a, struct val *b)
-{
- struct val *r;
-
- if (!to_integer (a) || !to_integer (b)) {
- ast_log(LOG_WARNING, "non-numeric argument\n");
- free_value(a);
- free_value(b);
- return make_integer(0);
- }
-
- if (b->u.i == 0) {
- ast_log(LOG_WARNING, "div by zero\n");
- free_value(a);
- return(b);
- }
-
- r = make_integer (/*(quad_t)*/(a->u.i % b->u.i));
- /* chk_rem necessary ??? */
- free_value (a);
- free_value (b);
- return r;
-}
-
-
-static struct val *
-op_colon (struct val *a, struct val *b)
-{
- regex_t rp;
- regmatch_t rm[2];
- char errbuf[256];
- int eval;
- struct val *v;
-
- /* coerce to both arguments to strings */
- to_string(a);
- to_string(b);
- /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
- strip_quotes(a);
- strip_quotes(b);
- /* compile regular expression */
- if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
- regerror (eval, &rp, errbuf, sizeof(errbuf));
- ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
- free_value(a);
- free_value(b);
- return make_str("");
- }
-
- /* compare string against pattern */
- /* remember that patterns are anchored to the beginning of the line */
- if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
- if (rm[1].rm_so >= 0) {
- *(a->u.s + rm[1].rm_eo) = '\0';
- v = make_str (a->u.s + rm[1].rm_so);
-
- } else {
- v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
- }
- } else {
- if (rp.re_nsub == 0) {
- v = make_integer ((quad_t)0);
- } else {
- v = make_str ("");
- }
- }
-
- /* free arguments and pattern buffer */
- free_value (a);
- free_value (b);
- regfree (&rp);
-
- return v;
-}
-
-
-static struct val *
-op_eqtilde (struct val *a, struct val *b)
-{
- regex_t rp;
- regmatch_t rm[2];
- char errbuf[256];
- int eval;
- struct val *v;
-
- /* coerce to both arguments to strings */
- to_string(a);
- to_string(b);
- /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
- strip_quotes(a);
- strip_quotes(b);
- /* compile regular expression */
- if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
- regerror (eval, &rp, errbuf, sizeof(errbuf));
- ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
- free_value(a);
- free_value(b);
- return make_str("");
- }
-
- /* compare string against pattern */
- /* remember that patterns are anchored to the beginning of the line */
- if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
- if (rm[1].rm_so >= 0) {
- *(a->u.s + rm[1].rm_eo) = '\0';
- v = make_str (a->u.s + rm[1].rm_so);
-
- } else {
- v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
- }
- } else {
- if (rp.re_nsub == 0) {
- v = make_integer ((quad_t)0);
- } else {
- v = make_str ("");
- }
- }
-
- /* free arguments and pattern buffer */
- free_value (a);
- free_value (b);
- regfree (&rp);
-
- return v;
-}
diff --git a/1.2-netsec/ast_expr2f.c b/1.2-netsec/ast_expr2f.c
deleted file mode 100644
index 3079eb901..000000000
--- a/1.2-netsec/ast_expr2f.c
+++ /dev/null
@@ -1,2988 +0,0 @@
-#line 2 "ast_expr2f.c"
-
-#line 4 "ast_expr2f.c"
-
-#define YY_INT_ALIGNED short int
-
-/* A lexical scanner generated by flex */
-
-#define FLEX_SCANNER
-#define YY_FLEX_MAJOR_VERSION 2
-#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 31
-#if YY_FLEX_SUBMINOR_VERSION > 0
-#define FLEX_BETA
-#endif
-
-/* First, we deal with platform-specific or compiler-specific issues. */
-
-/* begin standard C headers. */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-
-/* end standard C headers. */
-
-/* flex integer type definitions */
-
-#ifndef FLEXINT_H
-#define FLEXINT_H
-
-/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
-
-#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
-#include <inttypes.h>
-typedef int8_t flex_int8_t;
-typedef uint8_t flex_uint8_t;
-typedef int16_t flex_int16_t;
-typedef uint16_t flex_uint16_t;
-typedef int32_t flex_int32_t;
-typedef uint32_t flex_uint32_t;
-#else
-typedef signed char flex_int8_t;
-typedef short int flex_int16_t;
-typedef int flex_int32_t;
-typedef unsigned char flex_uint8_t;
-typedef unsigned short int flex_uint16_t;
-typedef unsigned int flex_uint32_t;
-#endif /* ! C99 */
-
-/* Limits of integral types. */
-#ifndef INT8_MIN
-#define INT8_MIN (-128)
-#endif
-#ifndef INT16_MIN
-#define INT16_MIN (-32767-1)
-#endif
-#ifndef INT32_MIN
-#define INT32_MIN (-2147483647-1)
-#endif
-#ifndef INT8_MAX
-#define INT8_MAX (127)
-#endif
-#ifndef INT16_MAX
-#define INT16_MAX (32767)
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX (2147483647)
-#endif
-#ifndef UINT8_MAX
-#define UINT8_MAX (255U)
-#endif
-#ifndef UINT16_MAX
-#define UINT16_MAX (65535U)
-#endif
-#ifndef UINT32_MAX
-#define UINT32_MAX (4294967295U)
-#endif
-
-#endif /* ! FLEXINT_H */
-
-#ifdef __cplusplus
-
-/* The "const" storage-class-modifier is valid. */
-#define YY_USE_CONST
-
-#else /* ! __cplusplus */
-
-#if __STDC__
-
-#define YY_USE_CONST
-
-#endif /* __STDC__ */
-#endif /* ! __cplusplus */
-
-#ifdef YY_USE_CONST
-#define yyconst const
-#else
-#define yyconst
-#endif
-
-/* Returned upon end-of-file. */
-#define YY_NULL 0
-
-/* Promotes a possibly negative, possibly signed char to an unsigned
- * integer for use as an array index. If the signed char is negative,
- * we want to instead treat it as an 8-bit unsigned char, hence the
- * double cast.
- */
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
-
-/* An opaque pointer. */
-#ifndef YY_TYPEDEF_YY_SCANNER_T
-#define YY_TYPEDEF_YY_SCANNER_T
-typedef void* yyscan_t;
-#endif
-
-/* For convenience, these vars (plus the bison vars far below)
- are macros in the reentrant scanner. */
-#define yyin yyg->yyin_r
-#define yyout yyg->yyout_r
-#define yyextra yyg->yyextra_r
-#define yyleng yyg->yyleng_r
-#define yytext yyg->yytext_r
-#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
-#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
-#define yy_flex_debug yyg->yy_flex_debug_r
-
-int ast_yylex_init (yyscan_t* scanner);
-
-/* Enter a start condition. This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN.
- */
-#define BEGIN yyg->yy_start = 1 + 2 *
-
-/* Translate the current start state into a value that can be later handed
- * to BEGIN to return to the state. The YYSTATE alias is for lex
- * compatibility.
- */
-#define YY_START ((yyg->yy_start - 1) / 2)
-#define YYSTATE YY_START
-
-/* Action number for EOF rule of a given start state. */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-
-/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE ast_yyrestart(yyin ,yyscanner )
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-/* Size of default input buffer. */
-#ifndef YY_BUF_SIZE
-#define YY_BUF_SIZE 16384
-#endif
-
-#ifndef YY_TYPEDEF_YY_BUFFER_STATE
-#define YY_TYPEDEF_YY_BUFFER_STATE
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-#endif
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
- #define YY_LESS_LINENO(n)
-
-/* Return all but the first "n" matched characters back to the input stream. */
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up yytext. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- *yy_cp = yyg->yy_hold_char; \
- YY_RESTORE_YY_MORE_OFFSET \
- yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
- YY_DO_BEFORE_ACTION; /* set up yytext again */ \
- } \
- while ( 0 )
-
-#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
-
-/* The following is because we cannot portably get our hands on size_t
- * (without autoconf's help, which isn't available because we want
- * flex-generated scanners to compile on their own).
- */
-
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef unsigned int yy_size_t;
-#endif
-
-#ifndef YY_STRUCT_YY_BUFFER_STATE
-#define YY_STRUCT_YY_BUFFER_STATE
-struct yy_buffer_state
- {
- FILE *yy_input_file;
-
- char *yy_ch_buf; /* input buffer */
- char *yy_buf_pos; /* current position in input buffer */
-
- /* Size of input buffer in bytes, not including room for EOB
- * characters.
- */
- yy_size_t yy_buf_size;
-
- /* Number of characters read into yy_ch_buf, not including EOB
- * characters.
- */
- int yy_n_chars;
-
- /* Whether we "own" the buffer - i.e., we know we created it,
- * and can realloc() it to grow it, and should free() it to
- * delete it.
- */
- int yy_is_our_buffer;
-
- /* Whether this is an "interactive" input source; if so, and
- * if we're using stdio for input, then we want to use getc()
- * instead of fread(), to make sure we stop fetching input after
- * each newline.
- */
- int yy_is_interactive;
-
- /* Whether we're considered to be at the beginning of a line.
- * If so, '^' rules will be active on the next match, otherwise
- * not.
- */
- int yy_at_bol;
-
- int yy_bs_lineno; /**< The line count. */
- int yy_bs_column; /**< The column count. */
-
- /* Whether to try to fill the input buffer when we reach the
- * end of it.
- */
- int yy_fill_buffer;
-
- int yy_buffer_status;
-
-#define YY_BUFFER_NEW 0
-#define YY_BUFFER_NORMAL 1
- /* When an EOF's been seen but there's still some text to process
- * then we mark the buffer as YY_EOF_PENDING, to indicate that we
- * shouldn't try reading from the input source any more. We might
- * still have a bunch of tokens to match, though, because of
- * possible backing-up.
- *
- * When we actually see the EOF, we change the status to "new"
- * (via ast_yyrestart()), so that the user can continue scanning by
- * just pointing yyin at a new input file.
- */
-#define YY_BUFFER_EOF_PENDING 2
-
- };
-#endif /* !YY_STRUCT_YY_BUFFER_STATE */
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- *
- * Returns the top of the stack, or NULL.
- */
-#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
- ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
- : NULL)
-
-/* Same as previous macro, but useful when we know that the buffer stack is not
- * NULL or when we need an lvalue. For internal use only.
- */
-#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
-
-void ast_yyrestart (FILE *input_file ,yyscan_t yyscanner );
-void ast_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
-YY_BUFFER_STATE ast_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
-void ast_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
-void ast_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
-void ast_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
-void ast_yypop_buffer_state (yyscan_t yyscanner );
-
-static void ast_yyensure_buffer_stack (yyscan_t yyscanner );
-static void ast_yy_load_buffer_state (yyscan_t yyscanner );
-static void ast_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
-
-#define YY_FLUSH_BUFFER ast_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
-
-YY_BUFFER_STATE ast_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
-YY_BUFFER_STATE ast_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
-YY_BUFFER_STATE ast_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
-
-void *ast_yyalloc (yy_size_t ,yyscan_t yyscanner );
-void *ast_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
-void ast_yyfree (void * ,yyscan_t yyscanner );
-
-#define yy_new_buffer ast_yy_create_buffer
-
-#define yy_set_interactive(is_interactive) \
- { \
- if ( ! YY_CURRENT_BUFFER ){ \
- ast_yyensure_buffer_stack (yyscanner); \
- YY_CURRENT_BUFFER_LVALUE = \
- ast_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
- }
-
-#define yy_set_bol(at_bol) \
- { \
- if ( ! YY_CURRENT_BUFFER ){\
- ast_yyensure_buffer_stack (yyscanner); \
- YY_CURRENT_BUFFER_LVALUE = \
- ast_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
- }
-
-#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
-
-/* Begin user sect3 */
-
-#define ast_yywrap(n) 1
-#define YY_SKIP_YYWRAP
-
-typedef char YY_CHAR;
-
-typedef int yy_state_type;
-
-#define yytext_ptr yytext_r
-static yyconst flex_int16_t yy_nxt[][128] =
- {
- {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0
- },
-
- {
- 7, 8, 8, 8, 8, 8, 8, 8, 8, 9,
- 10, 8, 8, 9, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 9, 11, 12, 13, 14, 15, 16, 13,
- 17, 18, 19, 20, 13, 21, 13, 22, 23, 23,
- 23, 23, 23, 23, 23, 23, 23, 23, 24, 13,
- 25, 26, 27, 28, 13, 13, 13, 13, 13, 13,
-
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 8, 13, 8, 13, 13, 8, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 8, 29, 8, 8, 8
- },
-
- {
- 7, 8, 8, 8, 8, 8, 8, 8, 8, 9,
- 10, 8, 8, 9, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 9, 11, 12, 13, 14, 15, 16, 13,
-
- 17, 18, 19, 20, 13, 21, 13, 22, 23, 23,
- 23, 23, 23, 23, 23, 23, 23, 23, 24, 13,
- 25, 26, 27, 28, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 8, 13, 8, 13, 13, 8, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 8, 29, 8, 8, 8
- },
-
- {
- 7, 30, 30, 30, 30, 30, 30, 30, 30, 30,
-
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
-
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 31, 30, 32, 30, 30
- },
-
- {
- 7, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
-
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 31, 30, 32, 30, 30
- },
-
- {
- 7, 33, 33, 33, 33, 33, 33, 33, 33, 34,
- 34, 33, 33, 34, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 34, 34, 33, 33, 35, 34, 34, 33,
- 34, 34, 34, 34, 33, 34, 33, 34, 33, 33,
-
- 33, 33, 33, 33, 33, 33, 33, 33, 34, 33,
- 34, 34, 34, 34, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 34, 33, 33, 33
- },
-
- {
- 7, 33, 33, 33, 33, 33, 33, 33, 33, 34,
- 34, 33, 33, 34, 33, 33, 33, 33, 33, 33,
-
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 34, 34, 33, 33, 35, 34, 34, 33,
- 34, 34, 34, 34, 33, 34, 33, 34, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 34, 33,
- 34, 34, 34, 34, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
-
- 33, 33, 33, 33, 34, 33, 33, 33
- },
-
- {
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
-
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7, -7, -7,
- -7, -7, -7, -7, -7, -7, -7, -7
- },
-
- {
- 7, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
-
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8, -8, -8, -8, -8, -8, -8, -8
- },
-
- {
- 7, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
-
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
- -9, -9, -9, -9, -9, -9, -9, -9
-
- },
-
- {
- 7, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
-
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
- -10, -10, -10, -10, -10, -10, -10, -10
- },
-
- {
- 7, -11, -11, -11, -11, -11, -11, -11, -11, -11,
- -11, -11, -11, -11, -11, -11, -11, -11, -11, -11,
- -11, -11, -11, -11, -11, -11, -11, -11, -11, -11,
- -11, -11, -11, 36, -11, 36, 36, 36, -11, 36,
- -11, -11, -11, -11, 36, -11, 36, -11, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, -11, 36,
- -11, 37, -11, -11, 36, 36, 36, 36, 36, 36,
-
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, -11, 36, -11, 36, 36, -11, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, -11, -11, -11, -11, -11
- },
-
- {
- 7, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 39, 38, 38, 38, 38, 38,
-
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38
- },
-
- {
- 7, -13, -13, -13, -13, -13, -13, -13, -13, -13,
-
- -13, -13, -13, -13, -13, -13, -13, -13, -13, -13,
- -13, -13, -13, -13, -13, -13, -13, -13, -13, -13,
- -13, -13, -13, 36, -13, 36, 36, 36, -13, 36,
- -13, -13, -13, -13, 36, -13, 36, -13, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, -13, 36,
- -13, -13, -13, -13, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, -13, 36, -13, 36, 36, -13, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
-
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, -13, -13, -13, -13, -13
- },
-
- {
- 7, -14, -14, -14, -14, -14, -14, -14, -14, -14,
- -14, -14, -14, -14, -14, -14, -14, -14, -14, -14,
- -14, -14, -14, -14, -14, -14, -14, -14, -14, -14,
- -14, -14, -14, 36, -14, 36, 36, 36, -14, 36,
- -14, -14, -14, -14, 36, -14, 36, -14, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, -14, 36,
- -14, -14, -14, -14, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
-
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, -14, 36, -14, 36, 36, -14, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 40, -14, -14, -14, -14
- },
-
- {
- 7, -15, -15, -15, -15, -15, -15, -15, -15, -15,
- -15, -15, -15, -15, -15, -15, -15, -15, -15, -15,
- -15, -15, -15, -15, -15, -15, -15, -15, -15, -15,
- -15, -15, -15, 36, -15, 36, 36, 36, -15, 36,
- -15, -15, -15, -15, 36, -15, 36, -15, 36, 36,
-
- 36, 36, 36, 36, 36, 36, 36, 36, -15, 36,
- -15, -15, -15, -15, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, -15, 36, -15, 36, 36, -15, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, -15, -15, -15, -15, -15
- },
-
- {
- 7, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
-
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
- -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
-
- -16, -16, -16, -16, -16, -16, -16, -16
- },
-
- {
- 7, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
-
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
- -17, -17, -17, -17, -17, -17, -17, -17
- },
-
- {
- 7, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
-
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18, -18, -18,
- -18, -18, -18, -18, -18, -18, -18, -18
- },
-
- {
- 7, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
-
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
- -19, -19, -19, -19, -19, -19, -19, -19
-
- },
-
- {
- 7, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
-
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
- -20, -20, -20, -20, -20, -20, -20, -20
- },
-
- {
- 7, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
-
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
- -21, -21, -21, -21, -21, -21, -21, -21
- },
-
- {
- 7, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
-
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
- -22, -22, -22, -22, -22, -22, -22, -22
- },
-
- {
- 7, -23, -23, -23, -23, -23, -23, -23, -23, -23,
-
- -23, -23, -23, -23, -23, -23, -23, -23, -23, -23,
- -23, -23, -23, -23, -23, -23, -23, -23, -23, -23,
- -23, -23, -23, 36, -23, 36, 36, 36, -23, 36,
- -23, -23, -23, -23, 36, -23, 36, -23, 41, 41,
- 41, 41, 41, 41, 41, 41, 41, 41, -23, 36,
- -23, -23, -23, -23, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, -23, 36, -23, 36, 36, -23, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
-
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, -23, -23, -23, -23, -23
- },
-
- {
- 7, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, 42, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
-
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
- -24, -24, -24, -24, -24, -24, -24, -24
- },
-
- {
- 7, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
-
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, 43, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
- -25, -25, -25, -25, -25, -25, -25, -25
- },
-
- {
- 7, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
-
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
- -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
-
- -26, -26, -26, -26, -26, -26, -26, -26
- },
-
- {
- 7, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, 44, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
-
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
- -27, -27, -27, -27, -27, -27, -27, -27
- },
-
- {
- 7, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
-
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
- -28, -28, -28, -28, -28, -28, -28, -28
- },
-
- {
- 7, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
-
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
- -29, -29, -29, -29, -29, -29, -29, -29
-
- },
-
- {
- 7, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
-
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 46, 45, 47, 45, 45
- },
-
- {
- 7, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
-
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -31, -31, -31, -31
- },
-
- {
- 7, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
-
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32
- },
-
- {
- 7, 48, 48, 48, 48, 48, 48, 48, 48, -33,
-
- -33, 48, 48, -33, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, -33, -33, 48, 48, -33, -33, -33, 48,
- -33, -33, -33, -33, 48, -33, 48, -33, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, -33, 48,
- -33, -33, -33, -33, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
-
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, -33, 48, 48, 48
- },
-
- {
- 7, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
-
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
- -34, -34, -34, -34, -34, -34, -34, -34
- },
-
- {
- 7, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
-
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
- -35, -35, -35, 49, -35, -35, -35, -35
- },
-
- {
- 7, -36, -36, -36, -36, -36, -36, -36, -36, -36,
- -36, -36, -36, -36, -36, -36, -36, -36, -36, -36,
-
- -36, -36, -36, -36, -36, -36, -36, -36, -36, -36,
- -36, -36, -36, 36, -36, 36, 36, 36, -36, 36,
- -36, -36, -36, -36, 36, -36, 36, -36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, -36, 36,
- -36, -36, -36, -36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, -36, 36, -36, 36, 36, -36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
-
- 36, 36, 36, -36, -36, -36, -36, -36
- },
-
- {
- 7, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
-
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37
- },
-
- {
- 7, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 39, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
-
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38
- },
-
- {
- 7, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
-
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
- -39, -39, -39, -39, -39, -39, -39, -39
-
- },
-
- {
- 7, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
-
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
- -40, -40, -40, -40, -40, -40, -40, -40
- },
-
- {
- 7, -41, -41, -41, -41, -41, -41, -41, -41, -41,
- -41, -41, -41, -41, -41, -41, -41, -41, -41, -41,
- -41, -41, -41, -41, -41, -41, -41, -41, -41, -41,
- -41, -41, -41, 36, -41, 36, 36, 36, -41, 36,
- -41, -41, -41, -41, 36, -41, 36, -41, 41, 41,
- 41, 41, 41, 41, 41, 41, 41, 41, -41, 36,
- -41, -41, -41, -41, 36, 36, 36, 36, 36, 36,
-
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, -41, 36, -41, 36, 36, -41, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, -41, -41, -41, -41, -41
- },
-
- {
- 7, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
-
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
- -42, -42, -42, -42, -42, -42, -42, -42
- },
-
- {
- 7, -43, -43, -43, -43, -43, -43, -43, -43, -43,
-
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
-
- -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
- -43, -43, -43, -43, -43, -43, -43, -43
- },
-
- {
- 7, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
-
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
- -44, -44, -44, -44, -44, -44, -44, -44
- },
-
- {
- 7, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
-
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 46, 45, 47, 45, 45
- },
-
- {
- 7, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
-
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
- -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
-
- -46, -46, -46, -46, -46, -46, -46, -46
- },
-
- {
- 7, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
-
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47, -47, -47,
- -47, -47, -47, -47, -47, -47, -47, -47
- },
-
- {
- 7, 48, 48, 48, 48, 48, 48, 48, 48, -48,
- -48, 48, 48, -48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, -48, -48, 48, 48, -48, -48, -48, 48,
- -48, -48, -48, -48, 48, -48, 48, -48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, -48, 48,
-
- -48, -48, -48, -48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, -48, 48, 48, 48
- },
-
- {
- 7, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
-
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49, -49, -49,
- -49, -49, -49, -49, -49, -49, -49, -49
-
- },
-
- } ;
-
-static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
-static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
-static int yy_get_next_buffer (yyscan_t yyscanner );
-static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
-
-/* Done after the current pattern has been matched and before the
- * corresponding action - sets up yytext.
- */
-#define YY_DO_BEFORE_ACTION \
- yyg->yytext_ptr = yy_bp; \
- yyg->yytext_ptr -= yyg->yy_more_len; \
- yyleng = (size_t) (yy_cp - yyg->yytext_ptr); \
- yyg->yy_hold_char = *yy_cp; \
- *yy_cp = '\0'; \
- yyg->yy_c_buf_p = yy_cp;
-
-#define YY_NUM_RULES 30
-#define YY_END_OF_BUFFER 31
-/* This struct is not used in this scanner,
- but its presence is necessary. */
-struct yy_trans_info
- {
- flex_int32_t yy_verify;
- flex_int32_t yy_nxt;
- };
-static yyconst flex_int16_t yy_accept[50] =
- { 0,
- 0, 0, 0, 0, 27, 27, 31, 30, 20, 22,
- 24, 30, 24, 24, 13, 2, 17, 18, 11, 9,
- 10, 12, 23, 15, 5, 3, 4, 14, 1, 30,
- 26, 25, 27, 28, 28, 24, 8, 0, 21, 19,
- 23, 16, 7, 6, 0, 26, 25, 27, 29
- } ;
-
-static yyconst yy_state_type yy_NUL_trans[50] =
- { 0,
- 8, 8, 30, 30, 33, 33, 0, 0, 0, 0,
- 0, 38, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 45,
- 0, 0, 48, 0, 0, 0, 0, 38, 0, 0,
- 0, 0, 0, 0, 45, 0, 0, 48, 0
- } ;
-
-/* The intent behind this definition is that it'll catch
- * any uses of REJECT which flex missed.
- */
-#define REJECT reject_used_but_not_detected
-#define yymore() (yyg->yy_more_flag = 1)
-#define YY_MORE_ADJ yyg->yy_more_len
-#define YY_RESTORE_YY_MORE_OFFSET
-#line 1 "ast_expr2.fl"
-#line 2 "ast_expr2.fl"
-/*! \file
- *
- * \brief Dialplan Expression Parser
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <locale.h>
-#include <ctype.h>
-#if !defined(SOLARIS) && !defined(__CYGWIN__)
-#include <err.h>
-#else
-#define quad_t int64_t
-#endif
-#include <errno.h>
-#include <regex.h>
-#include <limits.h>
-#include <asterisk/ast_expr.h>
-#include <asterisk/logger.h>
-#include <asterisk/strings.h>
-
-enum valtype {
- AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
-} ;
-
-struct val {
- enum valtype type;
- union {
- char *s;
- quad_t i;
- } u;
-} ;
-
-#include "ast_expr2.h" /* the o/p of the bison on ast_expr2.y */
-
-#define SET_COLUMNS yylloc_param->first_column = (int)(yyg->yytext_r - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf);yylloc_param->last_column = yylloc_param->last_column + yyleng - 1; yylloc_param->first_line = yylloc_param->last_line = 1
-#define SET_STRING yylval_param->val = (struct val *)calloc(sizeof(struct val),1); yylval_param->val->type = AST_EXPR_string; yylval_param->val->u.s = strdup(yytext);
-#define SET_NUMERIC_STRING yylval_param->val = (struct val *)calloc(sizeof(struct val),1); yylval_param->val->type = AST_EXPR_numeric_string; yylval_param->val->u.s = strdup(yytext);
-
-struct parse_io
-{
- char *string;
- struct val *val;
- yyscan_t scanner;
-};
-
-void ast_yyset_column(int column_no, yyscan_t yyscanner);
-int ast_yyget_column(yyscan_t yyscanner);
-static int curlycount = 0;
-
-#line 1304 "ast_expr2f.c"
-
-#define INITIAL 0
-#define var 1
-#define trail 2
-
-/* Special case for "unistd.h", since it is non-ANSI. We include it way
- * down here because we want the user's section 1 to have been scanned first.
- * The user has a chance to override it with an option.
- */
-#include <unistd.h>
-
-#ifndef YY_EXTRA_TYPE
-#define YY_EXTRA_TYPE void *
-#endif
-
-/* Holds the entire state of the reentrant scanner. */
-struct yyguts_t
- {
-
- /* User-defined. Not touched by flex. */
- YY_EXTRA_TYPE yyextra_r;
-
- /* The rest are the same as the globals declared in the non-reentrant scanner. */
- FILE *yyin_r, *yyout_r;
- size_t yy_buffer_stack_top; /**< index of top of stack. */
- size_t yy_buffer_stack_max; /**< capacity of stack. */
- YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
- char yy_hold_char;
- int yy_n_chars;
- int yyleng_r;
- char *yy_c_buf_p;
- int yy_init;
- int yy_start;
- int yy_did_buffer_switch_on_eof;
- int yy_start_stack_ptr;
- int yy_start_stack_depth;
- int *yy_start_stack;
- yy_state_type yy_last_accepting_state;
- char* yy_last_accepting_cpos;
-
- int yylineno_r;
- int yy_flex_debug_r;
-
- char *yytext_r;
- int yy_more_flag;
- int yy_more_len;
-
- YYSTYPE * yylval_r;
-
- YYLTYPE * yylloc_r;
-
- }; /* end struct yyguts_t */
-
- /* This must go here because YYSTYPE and YYLTYPE are included
- * from bison output in section 1.*/
- # define yylval yyg->yylval_r
-
- # define yylloc yyg->yylloc_r
-
-/* Accessor methods to globals.
- These are made visible to non-reentrant scanners for convenience. */
-
-int ast_yylex_destroy (yyscan_t yyscanner );
-
-int ast_yyget_debug (yyscan_t yyscanner );
-
-void ast_yyset_debug (int debug_flag ,yyscan_t yyscanner );
-
-YY_EXTRA_TYPE ast_yyget_extra (yyscan_t yyscanner );
-
-void ast_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
-
-FILE *ast_yyget_in (yyscan_t yyscanner );
-
-void ast_yyset_in (FILE * in_str ,yyscan_t yyscanner );
-
-FILE *ast_yyget_out (yyscan_t yyscanner );
-
-void ast_yyset_out (FILE * out_str ,yyscan_t yyscanner );
-
-int ast_yyget_leng (yyscan_t yyscanner );
-
-char *ast_yyget_text (yyscan_t yyscanner );
-
-int ast_yyget_lineno (yyscan_t yyscanner );
-
-void ast_yyset_lineno (int line_number ,yyscan_t yyscanner );
-
-YYSTYPE * ast_yyget_lval (yyscan_t yyscanner );
-
-void ast_yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
-
- YYLTYPE *ast_yyget_lloc (yyscan_t yyscanner );
-
- void ast_yyset_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
-
-/* Macros after this point can all be overridden by user definitions in
- * section 1.
- */
-
-#ifndef YY_SKIP_YYWRAP
-#ifdef __cplusplus
-extern "C" int ast_yywrap (yyscan_t yyscanner );
-#else
-extern int ast_yywrap (yyscan_t yyscanner );
-#endif
-#endif
-
- static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner);
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
-#endif
-
-#ifndef YY_NO_INPUT
-
-#ifdef __cplusplus
-static int yyinput (yyscan_t yyscanner );
-#else
-static int input (yyscan_t yyscanner );
-#endif
-
-#endif
-
-/* Amount of stuff to slurp up with each read. */
-#ifndef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 8192
-#endif
-
-/* Copy whatever the last rule matched to the standard output. */
-#ifndef ECHO
-/* This used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite().
- */
-#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
-#endif
-
-/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#ifndef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
- errno=0; \
- while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
- { \
- if( errno != EINTR) \
- { \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- break; \
- } \
- errno=0; \
- clearerr(yyin); \
- }\
-\
-
-#endif
-
-/* No semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#ifndef yyterminate
-#define yyterminate() return YY_NULL
-#endif
-
-/* Number of entries by which start-condition stack grows. */
-#ifndef YY_START_STACK_INCR
-#define YY_START_STACK_INCR 25
-#endif
-
-/* Report a fatal error. */
-#ifndef YY_FATAL_ERROR
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
-#endif
-
-/* end tables serialization structures and prototypes */
-
-/* Default declaration of generated scanner - a define so the user can
- * easily add parameters.
- */
-#ifndef YY_DECL
-#define YY_DECL_IS_OURS 1
-
-extern int ast_yylex (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner);
-
-#define YY_DECL int ast_yylex (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner)
-#endif /* !YY_DECL */
-
-/* Code executed at the beginning of each rule, after yytext and yyleng
- * have been set up.
- */
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-/* Code executed at the end of each rule. */
-#ifndef YY_BREAK
-#define YY_BREAK break;
-#endif
-
-#define YY_RULE_SETUP \
- YY_USER_ACTION
-
-/** The main scanner function which does all the work.
- */
-YY_DECL
-{
- register yy_state_type yy_current_state;
- register char *yy_cp, *yy_bp;
- register int yy_act;
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-#line 64 "ast_expr2.fl"
-
-
-#line 1524 "ast_expr2f.c"
-
- yylval = yylval_param;
-
- yylloc = yylloc_param;
-
- if ( yyg->yy_init )
- {
- yyg->yy_init = 0;
-
-#ifdef YY_USER_INIT
- YY_USER_INIT;
-#endif
-
- if ( ! yyg->yy_start )
- yyg->yy_start = 1; /* first start state */
-
- if ( ! yyin )
- yyin = stdin;
-
- if ( ! yyout )
- yyout = stdout;
-
- if ( ! YY_CURRENT_BUFFER ) {
- ast_yyensure_buffer_stack (yyscanner);
- YY_CURRENT_BUFFER_LVALUE =
- ast_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
- }
-
- ast_yy_load_buffer_state(yyscanner );
- }
-
- while ( 1 ) /* loops until end-of-file is reached */
- {
- yyg->yy_more_len = 0;
- if ( yyg->yy_more_flag )
- {
- yyg->yy_more_len = yyg->yy_c_buf_p - yyg->yytext_ptr;
- yyg->yy_more_flag = 0;
- }
- yy_cp = yyg->yy_c_buf_p;
-
- /* Support of yytext. */
- *yy_cp = yyg->yy_hold_char;
-
- /* yy_bp points to the position in yy_ch_buf of the start of
- * the current run.
- */
- yy_bp = yy_cp;
-
- yy_current_state = yyg->yy_start;
-yy_match:
- while ( (yy_current_state = yy_nxt[yy_current_state][ YY_SC_TO_UI(*yy_cp) ]) > 0 )
- {
- if ( yy_accept[yy_current_state] )
- {
- yyg->yy_last_accepting_state = yy_current_state;
- yyg->yy_last_accepting_cpos = yy_cp;
- }
-
- ++yy_cp;
- }
-
- yy_current_state = -yy_current_state;
-
-yy_find_action:
- yy_act = yy_accept[yy_current_state];
-
- YY_DO_BEFORE_ACTION;
-
-do_action: /* This label is used only to access EOF actions. */
-
- switch ( yy_act )
- { /* beginning of action switch */
- case 0: /* must back up */
- /* undo the effects of YY_DO_BEFORE_ACTION */
- *yy_cp = yyg->yy_hold_char;
- yy_cp = yyg->yy_last_accepting_cpos + 1;
- yy_current_state = yyg->yy_last_accepting_state;
- goto yy_find_action;
-
-case 1:
-YY_RULE_SETUP
-#line 66 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_OR;}
- YY_BREAK
-case 2:
-YY_RULE_SETUP
-#line 67 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_AND;}
- YY_BREAK
-case 3:
-YY_RULE_SETUP
-#line 68 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_EQ;}
- YY_BREAK
-case 4:
-YY_RULE_SETUP
-#line 69 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_GT;}
- YY_BREAK
-case 5:
-YY_RULE_SETUP
-#line 70 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_LT;}
- YY_BREAK
-case 6:
-YY_RULE_SETUP
-#line 71 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_GE;}
- YY_BREAK
-case 7:
-YY_RULE_SETUP
-#line 72 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_LE;}
- YY_BREAK
-case 8:
-YY_RULE_SETUP
-#line 73 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_NE;}
- YY_BREAK
-case 9:
-YY_RULE_SETUP
-#line 74 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_PLUS;}
- YY_BREAK
-case 10:
-YY_RULE_SETUP
-#line 75 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_MINUS;}
- YY_BREAK
-case 11:
-YY_RULE_SETUP
-#line 76 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_MULT;}
- YY_BREAK
-case 12:
-YY_RULE_SETUP
-#line 77 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_DIV;}
- YY_BREAK
-case 13:
-YY_RULE_SETUP
-#line 78 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_MOD;}
- YY_BREAK
-case 14:
-YY_RULE_SETUP
-#line 79 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_COND;}
- YY_BREAK
-case 15:
-YY_RULE_SETUP
-#line 80 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_COLON;}
- YY_BREAK
-case 16:
-YY_RULE_SETUP
-#line 81 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_COLONCOLON;}
- YY_BREAK
-case 17:
-YY_RULE_SETUP
-#line 82 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_LP;}
- YY_BREAK
-case 18:
-YY_RULE_SETUP
-#line 83 "ast_expr2.fl"
-{ SET_COLUMNS; SET_STRING; return TOK_RP;}
- YY_BREAK
-case 19:
-YY_RULE_SETUP
-#line 84 "ast_expr2.fl"
-{/* gather the contents of ${} expressions, with trailing stuff, into a single TOKEN. They are much more complex now than they used to be */
- curlycount = 0; BEGIN(var); yymore();}
- YY_BREAK
-case 20:
-YY_RULE_SETUP
-#line 87 "ast_expr2.fl"
-{}
- YY_BREAK
-case 21:
-/* rule 21 can match eol */
-YY_RULE_SETUP
-#line 88 "ast_expr2.fl"
-{SET_COLUMNS; SET_STRING; return TOKEN;}
- YY_BREAK
-case 22:
-/* rule 22 can match eol */
-YY_RULE_SETUP
-#line 90 "ast_expr2.fl"
-{/* what to do with eol */}
- YY_BREAK
-case 23:
-YY_RULE_SETUP
-#line 91 "ast_expr2.fl"
-{ SET_COLUMNS; /* the original behavior of the expression parser was to bring in numbers as a numeric string */
- SET_NUMERIC_STRING;
- return TOKEN;}
- YY_BREAK
-case 24:
-YY_RULE_SETUP
-#line 94 "ast_expr2.fl"
-{SET_COLUMNS; SET_STRING; return TOKEN;}
- YY_BREAK
-case 25:
-/* rule 25 can match eol */
-YY_RULE_SETUP
-#line 96 "ast_expr2.fl"
-{curlycount--; if(curlycount < 0){ BEGIN(trail); yymore();} else { yymore();}}
- YY_BREAK
-case 26:
-/* rule 26 can match eol */
-YY_RULE_SETUP
-#line 97 "ast_expr2.fl"
-{curlycount++; yymore(); }
- YY_BREAK
-case 27:
-YY_RULE_SETUP
-#line 98 "ast_expr2.fl"
-{BEGIN(0); SET_COLUMNS; SET_STRING; return TOKEN;}
- YY_BREAK
-case 28:
-/* rule 28 can match eol */
-YY_RULE_SETUP
-#line 99 "ast_expr2.fl"
-{char c = yytext[yyleng-1]; BEGIN(0); unput(c); SET_COLUMNS; SET_STRING; return TOKEN;}
- YY_BREAK
-case 29:
-YY_RULE_SETUP
-#line 100 "ast_expr2.fl"
-{curlycount = 0; BEGIN(var); yymore(); }
- YY_BREAK
-case YY_STATE_EOF(trail):
-#line 101 "ast_expr2.fl"
-{BEGIN(0); SET_COLUMNS; SET_STRING; return TOKEN; /* actually, if an expr is only a variable ref, this could happen a LOT */}
- YY_BREAK
-case 30:
-YY_RULE_SETUP
-#line 103 "ast_expr2.fl"
-ECHO;
- YY_BREAK
-#line 1767 "ast_expr2f.c"
-case YY_STATE_EOF(INITIAL):
-case YY_STATE_EOF(var):
- yyterminate();
-
- case YY_END_OF_BUFFER:
- {
- /* Amount of text matched not including the EOB char. */
- int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
-
- /* Undo the effects of YY_DO_BEFORE_ACTION. */
- *yy_cp = yyg->yy_hold_char;
- YY_RESTORE_YY_MORE_OFFSET
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
- {
- /* We're scanning a new file or input source. It's
- * possible that this happened because the user
- * just pointed yyin at a new source and called
- * ast_yylex(). If so, then we have to assure
- * consistency between YY_CURRENT_BUFFER and our
- * globals. Here is the right place to do so, because
- * this is the first action (other than possibly a
- * back-up) that will match for the new input source.
- */
- yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
- }
-
- /* Note that here we test for yy_c_buf_p "<=" to the position
- * of the first EOB in the buffer, since yy_c_buf_p will
- * already have been incremented past the NUL character
- * (since all states make transitions on EOB to the
- * end-of-buffer state). Contrast this with the test
- * in input().
- */
- if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
- { /* This was really a NUL. */
- yy_state_type yy_next_state;
-
- yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( yyscanner );
-
- /* Okay, we're now positioned to make the NUL
- * transition. We couldn't have
- * yy_get_previous_state() go ahead and do it
- * for us because it doesn't know how to deal
- * with the possibility of jamming (and we don't
- * want to build jamming into it because then it
- * will run more slowly).
- */
-
- yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
-
- yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
-
- if ( yy_next_state )
- {
- /* Consume the NUL. */
- yy_cp = ++yyg->yy_c_buf_p;
- yy_current_state = yy_next_state;
- goto yy_match;
- }
-
- else
- {
- yy_cp = yyg->yy_c_buf_p;
- goto yy_find_action;
- }
- }
-
- else switch ( yy_get_next_buffer( yyscanner ) )
- {
- case EOB_ACT_END_OF_FILE:
- {
- yyg->yy_did_buffer_switch_on_eof = 0;
-
- if ( ast_yywrap(yyscanner ) )
- {
- /* Note: because we've taken care in
- * yy_get_next_buffer() to have set up
- * yytext, we can now set up
- * yy_c_buf_p so that if some total
- * hoser (like flex itself) wants to
- * call the scanner after we return the
- * YY_NULL, it'll still work - another
- * YY_NULL will get returned.
- */
- yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
-
- yy_act = YY_STATE_EOF(YY_START);
- goto do_action;
- }
-
- else
- {
- if ( ! yyg->yy_did_buffer_switch_on_eof )
- YY_NEW_FILE;
- }
- break;
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- yyg->yy_c_buf_p =
- yyg->yytext_ptr + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( yyscanner );
-
- yy_cp = yyg->yy_c_buf_p;
- yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
- goto yy_match;
-
- case EOB_ACT_LAST_MATCH:
- yyg->yy_c_buf_p =
- &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
-
- yy_current_state = yy_get_previous_state( yyscanner );
-
- yy_cp = yyg->yy_c_buf_p;
- yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
- goto yy_find_action;
- }
- break;
- }
-
- default:
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--no action found" );
- } /* end of action switch */
- } /* end of scanning one token */
-} /* end of ast_yylex */
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * Returns a code representing an action:
- * EOB_ACT_LAST_MATCH -
- * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- * EOB_ACT_END_OF_FILE - end of file
- */
-static int yy_get_next_buffer (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
- register char *source = yyg->yytext_ptr;
- register int number_to_move, i;
- int ret_val;
-
- if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--end of buffer missed" );
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
- { /* Don't try to fill the buffer, so this is an EOF. */
- if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
- {
- /* We matched a single character, the EOB, so
- * treat this as a final EOF.
- */
- return EOB_ACT_END_OF_FILE;
- }
-
- else
- {
- /* We matched some text prior to the EOB, first
- * process it.
- */
- return EOB_ACT_LAST_MATCH;
- }
- }
-
- /* Try to read more data. */
-
- /* First move last chars to start of buffer. */
- number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
-
- for ( i = 0; i < number_to_move; ++i )
- *(dest++) = *(source++);
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
- /* don't do the read, it's not guaranteed to return an EOF,
- * just force an EOF
- */
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
-
- else
- {
- size_t num_to_read =
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
-
- while ( num_to_read <= 0 )
- { /* Not enough room in the buffer - grow it. */
-
- /* just a shorter name for the current buffer */
- YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
-
- int yy_c_buf_p_offset =
- (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
-
- if ( b->yy_is_our_buffer )
- {
- int new_size = b->yy_buf_size * 2;
-
- if ( new_size <= 0 )
- b->yy_buf_size += b->yy_buf_size / 8;
- else
- b->yy_buf_size *= 2;
-
- b->yy_ch_buf = (char *)
- /* Include room in for 2 EOB chars. */
- ast_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
- }
- else
- /* Can't grow it, we don't own it. */
- b->yy_ch_buf = 0;
-
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR(
- "fatal error - scanner input buffer overflow" );
-
- yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
-
- num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
- number_to_move - 1;
-
- }
-
- if ( num_to_read > YY_READ_BUF_SIZE )
- num_to_read = YY_READ_BUF_SIZE;
-
- /* Read in more data. */
- YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
- yyg->yy_n_chars, num_to_read );
-
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
- }
-
- if ( yyg->yy_n_chars == 0 )
- {
- if ( number_to_move == YY_MORE_ADJ )
- {
- ret_val = EOB_ACT_END_OF_FILE;
- ast_yyrestart(yyin ,yyscanner);
- }
-
- else
- {
- ret_val = EOB_ACT_LAST_MATCH;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
- YY_BUFFER_EOF_PENDING;
- }
- }
-
- else
- ret_val = EOB_ACT_CONTINUE_SCAN;
-
- yyg->yy_n_chars += number_to_move;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
-
- yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
-
- return ret_val;
-}
-
-/* yy_get_previous_state - get the state just before the EOB char was reached */
-
- static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
-{
- register yy_state_type yy_current_state;
- register char *yy_cp;
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- yy_current_state = yyg->yy_start;
-
- for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
- {
- if ( *yy_cp )
- {
- yy_current_state = yy_nxt[yy_current_state][YY_SC_TO_UI(*yy_cp)];
- }
- else
- yy_current_state = yy_NUL_trans[yy_current_state];
- if ( yy_accept[yy_current_state] )
- {
- yyg->yy_last_accepting_state = yy_current_state;
- yyg->yy_last_accepting_cpos = yy_cp;
- }
- }
-
- return yy_current_state;
-}
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- * next_state = yy_try_NUL_trans( current_state );
- */
- static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
-{
- register int yy_is_jam;
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- register char *yy_cp = yyg->yy_c_buf_p;
-
- yy_current_state = yy_NUL_trans[yy_current_state];
- yy_is_jam = (yy_current_state == 0);
-
- if ( ! yy_is_jam )
- {
- if ( yy_accept[yy_current_state] )
- {
- yyg->yy_last_accepting_state = yy_current_state;
- yyg->yy_last_accepting_cpos = yy_cp;
- }
- }
-
- return yy_is_jam ? 0 : yy_current_state;
-}
-
- static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
-{
- register char *yy_cp;
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- yy_cp = yyg->yy_c_buf_p;
-
- /* undo effects of setting up yytext */
- *yy_cp = yyg->yy_hold_char;
-
- if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
- { /* need to shift things up to make room */
- /* +2 for EOB chars. */
- register int number_to_move = yyg->yy_n_chars + 2;
- register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
- register char *source =
- &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
-
- while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
- *--dest = *--source;
-
- yy_cp += (int) (dest - source);
- yy_bp += (int) (dest - source);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
- yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
-
- if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
- YY_FATAL_ERROR( "flex scanner push-back overflow" );
- }
-
- *--yy_cp = (char) c;
-
- yyg->yytext_ptr = yy_bp;
- yyg->yy_hold_char = *yy_cp;
- yyg->yy_c_buf_p = yy_cp;
-}
-
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
- static int yyinput (yyscan_t yyscanner)
-#else
- static int input (yyscan_t yyscanner)
-#endif
-
-{
- int c;
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- *yyg->yy_c_buf_p = yyg->yy_hold_char;
-
- if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
- {
- /* yy_c_buf_p now points to the character we want to return.
- * If this occurs *before* the EOB characters, then it's a
- * valid NUL; if not, then we've hit the end of the buffer.
- */
- if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
- /* This was really a NUL. */
- *yyg->yy_c_buf_p = '\0';
-
- else
- { /* need more input */
- int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
- ++yyg->yy_c_buf_p;
-
- switch ( yy_get_next_buffer( yyscanner ) )
- {
- case EOB_ACT_LAST_MATCH:
- /* This happens because yy_g_n_b()
- * sees that we've accumulated a
- * token and flags that we need to
- * try matching the token before
- * proceeding. But for input(),
- * there's no matching to consider.
- * So convert the EOB_ACT_LAST_MATCH
- * to EOB_ACT_END_OF_FILE.
- */
-
- /* Reset buffer status. */
- ast_yyrestart(yyin ,yyscanner);
-
- /*FALLTHROUGH*/
-
- case EOB_ACT_END_OF_FILE:
- {
- if ( ast_yywrap(yyscanner ) )
- return EOF;
-
- if ( ! yyg->yy_did_buffer_switch_on_eof )
- YY_NEW_FILE;
-#ifdef __cplusplus
- return yyinput(yyscanner);
-#else
- return input(yyscanner);
-#endif
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
- break;
- }
- }
- }
-
- c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
- *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
- yyg->yy_hold_char = *++yyg->yy_c_buf_p;
-
- return c;
-}
-#endif /* ifndef YY_NO_INPUT */
-
-/** Immediately switch to a different input stream.
- * @param input_file A readable stream.
- * @param yyscanner The scanner object.
- * @note This function does not reset the start condition to @c INITIAL .
- */
- void ast_yyrestart (FILE * input_file , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- if ( ! YY_CURRENT_BUFFER ){
- ast_yyensure_buffer_stack (yyscanner);
- YY_CURRENT_BUFFER_LVALUE =
- ast_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
- }
-
- ast_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
- ast_yy_load_buffer_state(yyscanner );
-}
-
-/** Switch to a different input buffer.
- * @param new_buffer The new input buffer.
- * @param yyscanner The scanner object.
- */
- void ast_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- /* TODO. We should be able to replace this entire function body
- * with
- * ast_yypop_buffer_state();
- * ast_yypush_buffer_state(new_buffer);
- */
- ast_yyensure_buffer_stack (yyscanner);
- if ( YY_CURRENT_BUFFER == new_buffer )
- return;
-
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *yyg->yy_c_buf_p = yyg->yy_hold_char;
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
- }
-
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
- ast_yy_load_buffer_state(yyscanner );
-
- /* We don't actually know whether we did this switch during
- * EOF (ast_yywrap()) processing, but the only time this flag
- * is looked at is after ast_yywrap() is called, so it's safe
- * to go ahead and always set it.
- */
- yyg->yy_did_buffer_switch_on_eof = 1;
-}
-
-static void ast_yy_load_buffer_state (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
- yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
- yyg->yy_hold_char = *yyg->yy_c_buf_p;
-}
-
-/** Allocate and initialize an input buffer state.
- * @param file A readable stream.
- * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
- * @param yyscanner The scanner object.
- * @return the allocated buffer state.
- */
- YY_BUFFER_STATE ast_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
-{
- YY_BUFFER_STATE b;
-
- b = (YY_BUFFER_STATE) ast_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in ast_yy_create_buffer()" );
-
- b->yy_buf_size = size;
-
- /* yy_ch_buf has to be 2 characters longer than the size given because
- * we need to put in 2 end-of-buffer characters.
- */
- b->yy_ch_buf = (char *) ast_yyalloc(b->yy_buf_size + 2 ,yyscanner );
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in ast_yy_create_buffer()" );
-
- b->yy_is_our_buffer = 1;
-
- ast_yy_init_buffer(b,file ,yyscanner);
-
- return b;
-}
-
-/** Destroy the buffer.
- * @param b a buffer created with ast_yy_create_buffer()
- * @param yyscanner The scanner object.
- */
- void ast_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- if ( ! b )
- return;
-
- if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
- YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
-
- if ( b->yy_is_our_buffer )
- ast_yyfree((void *) b->yy_ch_buf ,yyscanner );
-
- ast_yyfree((void *) b ,yyscanner );
-}
-
-#ifndef __cplusplus
-extern int isatty (int );
-#endif /* __cplusplus */
-
-/* Initializes or reinitializes a buffer.
- * This function is sometimes called more than once on the same buffer,
- * such as during a ast_yyrestart() or at EOF.
- */
- static void ast_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
-
-{
- int oerrno = errno;
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- ast_yy_flush_buffer(b ,yyscanner);
-
- b->yy_input_file = file;
- b->yy_fill_buffer = 1;
-
- /* If b is the current buffer, then ast_yy_init_buffer was _probably_
- * called from ast_yyrestart() or through yy_get_next_buffer.
- * In that case, we don't want to reset the lineno or column.
- */
- if (b != YY_CURRENT_BUFFER){
- b->yy_bs_lineno = 1;
- b->yy_bs_column = 0;
- }
-
- b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
-
- errno = oerrno;
-}
-
-/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
- * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
- * @param yyscanner The scanner object.
- */
- void ast_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- if ( ! b )
- return;
-
- b->yy_n_chars = 0;
-
- /* We always need two end-of-buffer characters. The first causes
- * a transition to the end-of-buffer state. The second causes
- * a jam in that state.
- */
- b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
- b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
-
- b->yy_buf_pos = &b->yy_ch_buf[0];
-
- b->yy_at_bol = 1;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- if ( b == YY_CURRENT_BUFFER )
- ast_yy_load_buffer_state(yyscanner );
-}
-
-/** Pushes the new state onto the stack. The new state becomes
- * the current state. This function will allocate the stack
- * if necessary.
- * @param new_buffer The new state.
- * @param yyscanner The scanner object.
- */
-void ast_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- if (new_buffer == NULL)
- return;
-
- ast_yyensure_buffer_stack(yyscanner);
-
- /* This block is copied from ast_yy_switch_to_buffer. */
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *yyg->yy_c_buf_p = yyg->yy_hold_char;
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
- }
-
- /* Only push if top exists. Otherwise, replace top. */
- if (YY_CURRENT_BUFFER)
- yyg->yy_buffer_stack_top++;
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
-
- /* copied from ast_yy_switch_to_buffer. */
- ast_yy_load_buffer_state(yyscanner );
- yyg->yy_did_buffer_switch_on_eof = 1;
-}
-
-/** Removes and deletes the top of the stack, if present.
- * The next element becomes the new top.
- * @param yyscanner The scanner object.
- */
-void ast_yypop_buffer_state (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- if (!YY_CURRENT_BUFFER)
- return;
-
- ast_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
- YY_CURRENT_BUFFER_LVALUE = NULL;
- if (yyg->yy_buffer_stack_top > 0)
- --yyg->yy_buffer_stack_top;
-
- if (YY_CURRENT_BUFFER) {
- ast_yy_load_buffer_state(yyscanner );
- yyg->yy_did_buffer_switch_on_eof = 1;
- }
-}
-
-/* Allocates the stack if it does not exist.
- * Guarantees space for at least one push.
- */
-static void ast_yyensure_buffer_stack (yyscan_t yyscanner)
-{
- int num_to_alloc;
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- if (!yyg->yy_buffer_stack) {
-
- /* First allocation is just for 2 elements, since we don't know if this
- * scanner will even need a stack. We use 2 instead of 1 to avoid an
- * immediate realloc on the next call.
- */
- num_to_alloc = 1;
- yyg->yy_buffer_stack = (struct yy_buffer_state**)ast_yyalloc
- (num_to_alloc * sizeof(struct yy_buffer_state*)
- , yyscanner);
-
- memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
-
- yyg->yy_buffer_stack_max = num_to_alloc;
- yyg->yy_buffer_stack_top = 0;
- return;
- }
-
- if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
-
- /* Increase the buffer to prepare for a possible push. */
- int grow_size = 8 /* arbitrary grow size */;
-
- num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
- yyg->yy_buffer_stack = (struct yy_buffer_state**)ast_yyrealloc
- (yyg->yy_buffer_stack,
- num_to_alloc * sizeof(struct yy_buffer_state*)
- , yyscanner);
-
- /* zero only the new slots.*/
- memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
- yyg->yy_buffer_stack_max = num_to_alloc;
- }
-}
-
-/** Setup the input buffer state to scan directly from a user-specified character buffer.
- * @param base the character buffer
- * @param size the size in bytes of the character buffer
- * @param yyscanner The scanner object.
- * @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE ast_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
-{
- YY_BUFFER_STATE b;
-
- if ( size < 2 ||
- base[size-2] != YY_END_OF_BUFFER_CHAR ||
- base[size-1] != YY_END_OF_BUFFER_CHAR )
- /* They forgot to leave room for the EOB's. */
- return 0;
-
- b = (YY_BUFFER_STATE) ast_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in ast_yy_scan_buffer()" );
-
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
- b->yy_buf_pos = b->yy_ch_buf = base;
- b->yy_is_our_buffer = 0;
- b->yy_input_file = 0;
- b->yy_n_chars = b->yy_buf_size;
- b->yy_is_interactive = 0;
- b->yy_at_bol = 1;
- b->yy_fill_buffer = 0;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- ast_yy_switch_to_buffer(b ,yyscanner );
-
- return b;
-}
-
-/** Setup the input buffer state to scan a string. The next call to ast_yylex() will
- * scan from a @e copy of @a str.
- * @param str a NUL-terminated string to scan
- * @param yyscanner The scanner object.
- * @return the newly allocated buffer state object.
- * @note If you want to scan bytes that may contain NUL values, then use
- * ast_yy_scan_bytes() instead.
- */
-YY_BUFFER_STATE ast_yy_scan_string (yyconst char * str , yyscan_t yyscanner)
-{
-
- return ast_yy_scan_bytes(str,strlen(str) ,yyscanner);
-}
-
-/** Setup the input buffer state to scan the given bytes. The next call to ast_yylex() will
- * scan from a @e copy of @a bytes.
- * @param bytes the byte buffer to scan
- * @param len the number of bytes in the buffer pointed to by @a bytes.
- * @param yyscanner The scanner object.
- * @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE ast_yy_scan_bytes (yyconst char * bytes, int len , yyscan_t yyscanner)
-{
- YY_BUFFER_STATE b;
- char *buf;
- yy_size_t n;
- int i;
-
- /* Get memory for full buffer, including space for trailing EOB's. */
- n = len + 2;
- buf = (char *) ast_yyalloc(n ,yyscanner );
- if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in ast_yy_scan_bytes()" );
-
- for ( i = 0; i < len; ++i )
- buf[i] = bytes[i];
-
- buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
-
- b = ast_yy_scan_buffer(buf,n ,yyscanner);
- if ( ! b )
- YY_FATAL_ERROR( "bad buffer in ast_yy_scan_bytes()" );
-
- /* It's okay to grow etc. this buffer, and we should throw it
- * away when we're done.
- */
- b->yy_is_our_buffer = 1;
-
- return b;
-}
-
-#ifndef YY_EXIT_FAILURE
-#define YY_EXIT_FAILURE 2
-#endif
-
-static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
-{
- (void) fprintf( stderr, "%s\n", msg );
- exit( YY_EXIT_FAILURE );
-}
-
-/* Redefine yyless() so it works in section 3 code. */
-
-#undef yyless
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up yytext. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- yytext[yyleng] = yyg->yy_hold_char; \
- yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
- yyg->yy_hold_char = *yyg->yy_c_buf_p; \
- *yyg->yy_c_buf_p = '\0'; \
- yyleng = yyless_macro_arg; \
- } \
- while ( 0 )
-
-/* Accessor methods (get/set functions) to struct members. */
-
-/** Get the user-defined data for this scanner.
- * @param yyscanner The scanner object.
- */
-YY_EXTRA_TYPE ast_yyget_extra (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- return yyextra;
-}
-
-/** Get the current line number.
- * @param yyscanner The scanner object.
- */
-int ast_yyget_lineno (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- if (! YY_CURRENT_BUFFER)
- return 0;
-
- return yylineno;
-}
-
-/** Get the current column number.
- * @param yyscanner The scanner object.
- */
-int ast_yyget_column (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- if (! YY_CURRENT_BUFFER)
- return 0;
-
- return yycolumn;
-}
-
-/** Get the input stream.
- * @param yyscanner The scanner object.
- */
-FILE *ast_yyget_in (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- return yyin;
-}
-
-/** Get the output stream.
- * @param yyscanner The scanner object.
- */
-FILE *ast_yyget_out (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- return yyout;
-}
-
-/** Get the length of the current token.
- * @param yyscanner The scanner object.
- */
-int ast_yyget_leng (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- return yyleng;
-}
-
-/** Get the current token.
- * @param yyscanner The scanner object.
- */
-
-char *ast_yyget_text (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- return yytext;
-}
-
-/** Set the user-defined data. This data is never touched by the scanner.
- * @param user_defined The data to be associated with this scanner.
- * @param yyscanner The scanner object.
- */
-void ast_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- yyextra = user_defined ;
-}
-
-/** Set the current line number.
- * @param line_number
- * @param yyscanner The scanner object.
- */
-void ast_yyset_lineno (int line_number , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- /* lineno is only valid if an input buffer exists. */
- if (! YY_CURRENT_BUFFER )
- yy_fatal_error( "ast_yyset_lineno called with no buffer" , yyscanner);
-
- yylineno = line_number;
-}
-
-/** Set the current column.
- * @param line_number
- * @param yyscanner The scanner object.
- */
-void ast_yyset_column (int column_no , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- /* column is only valid if an input buffer exists. */
- if (! YY_CURRENT_BUFFER )
- yy_fatal_error( "ast_yyset_column called with no buffer" , yyscanner);
-
- yycolumn = column_no;
-}
-
-/** Set the input stream. This does not discard the current
- * input buffer.
- * @param in_str A readable stream.
- * @param yyscanner The scanner object.
- * @see ast_yy_switch_to_buffer
- */
-void ast_yyset_in (FILE * in_str , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- yyin = in_str ;
-}
-
-void ast_yyset_out (FILE * out_str , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- yyout = out_str ;
-}
-
-int ast_yyget_debug (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- return yy_flex_debug;
-}
-
-void ast_yyset_debug (int bdebug , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- yy_flex_debug = bdebug ;
-}
-
-/* Accessor methods for yylval and yylloc */
-
-YYSTYPE * ast_yyget_lval (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- return yylval;
-}
-
-void ast_yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- yylval = yylval_param;
-}
-
-YYLTYPE *ast_yyget_lloc (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- return yylloc;
-}
-
-void ast_yyset_lloc (YYLTYPE * yylloc_param , yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- yylloc = yylloc_param;
-}
-
-static int yy_init_globals (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- /* Initialization is the same as for the non-reentrant scanner.
- This function is called once per scanner lifetime. */
-
- yyg->yy_buffer_stack = 0;
- yyg->yy_buffer_stack_top = 0;
- yyg->yy_buffer_stack_max = 0;
- yyg->yy_c_buf_p = (char *) 0;
- yyg->yy_init = 1;
- yyg->yy_start = 0;
- yyg->yy_start_stack_ptr = 0;
- yyg->yy_start_stack_depth = 0;
- yyg->yy_start_stack = (int *) 0;
-
-/* Defined in main.c */
-#ifdef YY_STDINIT
- yyin = stdin;
- yyout = stdout;
-#else
- yyin = (FILE *) 0;
- yyout = (FILE *) 0;
-#endif
-
- /* For future reference: Set errno on error, since we are called by
- * ast_yylex_init()
- */
- return 0;
-}
-
-/* User-visible API */
-
-/* ast_yylex_init is special because it creates the scanner itself, so it is
- * the ONLY reentrant function that doesn't take the scanner as the last argument.
- * That's why we explicitly handle the declaration, instead of using our macros.
- */
-
-int ast_yylex_init(yyscan_t* ptr_yy_globals)
-
-{
- if (ptr_yy_globals == NULL){
- errno = EINVAL;
- return 1;
- }
-
- *ptr_yy_globals = (yyscan_t) ast_yyalloc ( sizeof( struct yyguts_t ), NULL );
-
- if (*ptr_yy_globals == NULL){
- errno = ENOMEM;
- return 1;
- }
-
- memset(*ptr_yy_globals,0,sizeof(struct yyguts_t));
-
- return yy_init_globals ( *ptr_yy_globals );
-}
-
-/* ast_yylex_destroy is for both reentrant and non-reentrant scanners. */
-int ast_yylex_destroy (yyscan_t yyscanner)
-{
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
- /* Pop the buffer stack, destroying each element. */
- while(YY_CURRENT_BUFFER){
- ast_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- ast_yypop_buffer_state(yyscanner);
- }
-
- /* Destroy the stack itself. */
- ast_yyfree(yyg->yy_buffer_stack ,yyscanner);
- yyg->yy_buffer_stack = NULL;
-
- /* Destroy the start condition stack. */
- ast_yyfree(yyg->yy_start_stack ,yyscanner );
- yyg->yy_start_stack = NULL;
-
- /* Destroy the main struct (reentrant only). */
- ast_yyfree ( yyscanner , yyscanner );
- return 0;
-}
-
-/*
- * Internal utility routines.
- */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
-{
- register int i;
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- for ( i = 0; i < n; ++i )
- s1[i] = s2[i];
-}
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
-{
- register int n;
- struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- for ( n = 0; s[n]; ++n )
- ;
-
- return n;
-}
-#endif
-
-void *ast_yyalloc (yy_size_t size , yyscan_t yyscanner)
-{
- return (void *) malloc( size );
-}
-
-void *ast_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
-{
- /* The cast to (char *) in the following accommodates both
- * implementations that use char* generic pointers, and those
- * that use void* generic pointers. It works with the latter
- * because both ANSI C and C++ allow castless assignment from
- * any pointer type to void*, and deal with argument conversions
- * as though doing an assignment.
- */
- return (void *) realloc( (char *) ptr, size );
-}
-
-void ast_yyfree (void * ptr , yyscan_t yyscanner)
-{
- free( (char *) ptr ); /* see ast_yyrealloc() for (char *) cast */
-}
-
-#define YYTABLES_NAME "yytables"
-
-#undef YY_NEW_FILE
-#undef YY_FLUSH_BUFFER
-#undef yy_set_bol
-#undef yy_new_buffer
-#undef yy_set_interactive
-#undef yytext_ptr
-#undef YY_DO_BEFORE_ACTION
-
-#ifdef YY_DECL_IS_OURS
-#undef YY_DECL_IS_OURS
-#undef YY_DECL
-#endif
-#line 103 "ast_expr2.fl"
-
-
-
-/* I'm putting the interface routine to the whole parse here in the flexer input file
- mainly because of all the flexer initialization that has to be done. Shouldn't matter
- where it is, as long as it's somewhere. I didn't want to define a prototype for the
- ast_yy_scan_string in the .y file, because then, I'd have to define YY_BUFFER_STATE there...
- UGH! that would be inappropriate. */
-
-int ast_yyparse(void *); /* need to/should define this prototype for the call to yyparse */
-int ast_yyerror(const char *, YYLTYPE *, struct parse_io *); /* likewise */
-
-int ast_expr(char *expr, char *buf, int length)
-{
- struct parse_io io;
- int return_value = 0;
-
- memset(&io, 0, sizeof(io));
- io.string = expr; /* to pass to the error routine */
-
- ast_yylex_init(&io.scanner);
-
- ast_yy_scan_string(expr, io.scanner);
-
- ast_yyparse ((void *) &io);
-
- ast_yylex_destroy(io.scanner);
-
- if (!io.val) {
- if (length > 1) {
- strcpy(buf, "0");
- return_value = 1;
- }
- } else {
- if (io.val->type == AST_EXPR_integer) {
- int res_length;
-
- res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i);
- return_value = (res_length <= length) ? res_length : length;
- } else {
-#ifdef STANDALONE
- strncpy(buf, io.val->u.s, length - 1);
-#else /* !STANDALONE */
- ast_copy_string(buf, io.val->u.s, length);
-#endif /* STANDALONE */
- return_value = strlen(buf);
- free(io.val->u.s);
- }
- free(io.val);
- }
- return return_value;
-}
-
-int ast_yyerror (const char *s, yyltype *loc, struct parse_io *parseio )
-{
- struct yyguts_t * yyg = (struct yyguts_t*)(parseio->scanner);
- char spacebuf[8000]; /* best safe than sorry */
- char spacebuf2[8000]; /* best safe than sorry */
- int i=0;
- spacebuf[0] = 0;
-
- for(i=0;i< (int)(yytext - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf);i++) spacebuf2[i] = ' '; /* uh... assuming yyg is defined, then I can use the yycolumn macro,
- which is the same thing as... get this:
- yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]->yy_bs_column
- I was tempted to just use yy_buf_pos in the STATE, but..., well:
- a. the yy_buf_pos is the current position in the buffer, which
- may not relate to the entire string/buffer because of the
- buffering.
- b. but, analysis of the situation is that when you use the
- ast_yy_scan_string func, it creates a single buffer the size of
- string, so the two would be the same...
- so, in the end, the yycolumn macro is available, shorter, therefore easier. */
- spacebuf2[i++]='^';
- spacebuf2[i]= 0;
-
-#ifdef STANDALONE3
- /* easier to read in the standalone version */
- printf("ast_yyerror(): syntax error: %s; Input:\n%s\n%s\n",
- s, parseio->string,spacebuf2);
-#else
- ast_log(LOG_WARNING,"ast_yyerror(): syntax error: %s; Input:\n%s\n%s\n",
- s, parseio->string,spacebuf2);
-#endif
-#ifndef STANDALONE
- ast_log(LOG_WARNING,"If you have questions, please refer to doc/README.variables in the asterisk source.\n");
-#endif
- return(0);
-}
-
diff --git a/1.2-netsec/asterisk.8 b/1.2-netsec/asterisk.8
deleted file mode 100644
index fe0a9ba86..000000000
--- a/1.2-netsec/asterisk.8
+++ /dev/null
@@ -1,184 +0,0 @@
-.\" This manpage has been automatically generated by docbook2man
-.\" from a DocBook document. This tool can be found at:
-.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
-.\" Please send any bug reports, improvements, comments, patches,
-.\" etc. to Steve Cheng <steve@ggi-project.org>.
-.TH "ASTERISK" "8" "25 October 2005" "asterisk 1.2" ""
-
-.SH NAME
-asterisk \- All-purpose telephony server.
-.SH SYNOPSIS
-
-\fBasterisk\fR [ \fB-tThfdvVqpRgcin\fR ] [ \fB-C \fIfile\fB\fR ] [ \fB-U \fIuser\fB\fR ] [ \fB-G \fIgroup\fB\fR ] [ \fB-x \fIcommand\fB\fR ] [ \fB-M \fIvalue\fB\fR ]
-
-
-\fBasterisk -r\fR [ \fB-v\fR ] [ \fB-x \fIcommand\fB\fR ]
-
-.SH "DESCRIPTION"
-.PP
-\fBasterisk\fR is a full-featured telephony server which
-provides Private Branch eXchange (PBX), Interactive Voice Response (IVR),
-Automated Call Distribution (ACD), Voice over IP (VoIP) gatewaying,
-Conferencing, and a plethora of other telephony applications to a broad
-range of telephony devices including packet voice (SIP, IAX2, MGCP, Skinny,
-H.323) devices (both endpoints and proxies), as well as traditional TDM
-hardware including T1, E1, ISDN PRI, GR-303, RBS, Loopstart, Groundstart,
-ISDN BRI, and many more.
-.PP
-At start, Asterisk reads the /etc/asterisk/asterisk.conf main configuration
-file and locates the rest of the configuration files from the configuration
-in that file. The -C option specifies an alternate main configuration file.
-Virtually all aspects of the operation of asterisk's configuration files
-can be found in the sample configuration files. The format for those files
-is generally beyond the scope of this man page.
-.PP
-When running with \fB-c\fR, \fB-r\fR or \fB-R\fR
-options, Asterisk supplies a powerful command line, including command
-completion, which may be used to monitors its status, perform a variety
-of administrative actions and even explore the applications that are
-currently loaded into the system.
-.PP
-Asterisk is a trademark of Digium, Inc.
-.SH "OPTIONS"
-.TP
-\fB-C \fIfile\fB\fR
-Use \fIfile\fR as master configuration file
-instead of the default, /etc/asterisk/asterisk.conf
-.TP
-\fB-c\fR
-Provide a control console on the calling terminal.
-Specifying this option implies \fB-f\fR and will cause
-asterisk to no longer fork or detach from the controlling terminal.
-.TP
-\fB-d\fR
-Enable extra debugging statements.
-
-Note: This always sets the debug level in the asterisk process,
-even if it is running in the background. This will affect the size
-of your log files.
-.TP
-\fB-f\fR
-Do not fork or detach from controlling terminal.
-.TP
-\fB-g\fR
-Remove resource limit on core size, thus forcing Asterisk to dump
-core in the unlikely event of a segmentation fault or abort signal.
-\fBNOTE:\fR in some cases this may be incompatible
-with the \fB-U\fR or \fB-G\fR flags.
-.TP
-\fB-G \fIgroup\fB\fR
-Run as group \fIgroup\fR instead of the
-calling group. \fBNOTE:\fR this requires substantial work
-to be sure that Asterisk's environment has permission to write
-the files required for its operation, including logs, its comm
-socket, the asterisk database, etc.
-.TP
-\fB-h\fR
-Provide brief summary of command line arguments and terminate.
-.TP
-\fB-i\fR
-Prompt user to intialize any encrypted private keys for IAX2
-secure authentication during startup.
-.TP
-\fB-L \fIloadaverage\fB\fR
-Limits the maximum load average before rejecting new calls. This can
-be useful to prevent a system from being brought down by terminating
-too many simultaneous calls.
-.TP
-\fB-M \fIvalue\fB\fR
-Limits the maximum number of calls to the specified value. This can
-be useful to prevent a system from being brought down by terminating
-too many simultaneous calls.
-.TP
-\fB-n\fR
-Disable ANSI colors even on terminals capable of displaying them.
-.TP
-\fB-p\fR
-If supported by the operating system (and executing as root),
-attempt to run with realtime priority for increased performance and
-responsiveness within the Asterisk process, at the expense of other
-programs running on the same machine.
-.TP
-\fB-q\fR
-Reduce default console output when running in conjunction with
-console mode (\fB-c\fR).
-.TP
-\fB-r\fR
-Instead of running a new Asterisk process, attempt to connect
-to a running Asterisk process and provide a console interface
-for controlling it.
-.TP
-\fB-R\fR
-Much like \fB-r\fR\&. Instead of running a new Asterisk process, attempt to connect
-to a running Asterisk process and provide a console interface
-for controlling it. Additionally, if connection to the Asterisk
-process is lost, attempt to reconnect for as long as 30 seconds.
-.TP
-\fB-t\fR
-When recording files, write them first into a temporary holding directory,
-then move them into the final location when done.
-.TP
-\fB-T\fR
-Add timestamp to all non-command related output going to the console
-when running with verbose and/or logging to the console.
-.TP
-\fB-U \fIuser\fB\fR
-Run as user \fIuser\fR instead of the
-calling user. \fBNOTE:\fR this requires substantial work
-to be sure that Asterisk's environment has permission to write
-the files required for its operation, including logs, its comm
-socket, the asterisk database, etc.
-.TP
-\fB-v\fR
-Increase the level of verboseness on the console. The more times
-\fB-v\fR is specified, the more verbose the output is.
-Specifying this option implies \fB-f\fR and will cause
-asterisk to no longer fork or detach from the controlling terminal.
-This option may also be used in conjunction with \fB-r\fR
-and \fB-R\fR\&.
-
-Note: This always sets the verbose level in the asterisk process,
-even if it is running in the background. This will affect the size
-of your log files.
-.TP
-\fB-V\fR
-Display version information and exit immediately.
-.TP
-\fB-x \fIcommand\fB\fR
-Connect to a running Asterisk process and execute a command on
-a command line, passing any output through to standard out and
-then terminating when the command execution completes. Implies
-\fB-r\fR when \fB-R\fR is not explicitly
-supplied.
-.SH "EXAMPLES"
-.PP
-\fBasterisk\fR - Begin Asterisk as a daemon
-.PP
-\fBasterisk -vvvgc\fR - Run on controlling terminal
-.PP
-\fBasterisk -rx "show channels"\fR - Display channels on running server
-.SH "BUGS"
-.PP
-Bug reports and feature requests may be filed at http://bugs.digium.com
-.SH "SEE ALSO"
-.PP
-*CLI> \fBhelp\fR - Help on Asterisk CLI
-.PP
-*CLI> \fBshow applications\fR - Show loaded dialplan applications
-.PP
-*CLI> \fBshow functions\fR - Show loaded dialplan functions
-.PP
-http://www.asterisk.org - The Asterisk Home Page
-.PP
-http://www.asteriskdocs.org - The Asterisk Documentation Project
-.PP
-http://www.voip-info.org/wiki-Asterisk - The Asterisk Wiki
-.PP
-http://www.digium.com/ - Asterisk sponsor and hardware supplier
-.PP
-http://www.markocam.com/ - Asterisk author's web cam
-.SH "AUTHOR"
-.PP
-Mark Spencer <markster@digium.com>
-.PP
-Countless other contributers, see CREDITS with distribution for more information
diff --git a/1.2-netsec/asterisk.c b/1.2-netsec/asterisk.c
deleted file mode 100644
index f29d7e182..000000000
--- a/1.2-netsec/asterisk.c
+++ /dev/null
@@ -1,2450 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-
-/* Doxygenified Copyright Header */
-
-/*!
- * \mainpage Asterisk -- An Open Source Telephony Toolkit
- *
- * \par Developer Documentation for Asterisk
- * This is the main developer documentation for Asterisk. It is
- * generated by running "make progdocs".
- * \par Additional documentation
- * \arg \ref DevDoc
- * \arg \ref ConfigFiles
- *
- * \section copyright Copyright and author
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- * Asterisk is a trade mark registered by Digium, Inc.
- *
- * \author Mark Spencer <markster@digium.com>
- * Also see \ref AstCREDITS
- *
- * \section license License
- * 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.
- *
- * \verbinclude LICENSE
- *
- */
-
-/*! \file
- \brief Top level source file for Asterisk - the Open Source PBX. Implementation
- of PBX core functions and CLI interface.
-
- */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <signal.h>
-#include <sched.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/wait.h>
-#include <string.h>
-#include <errno.h>
-#include <ctype.h>
-#include <sys/resource.h>
-#include <grp.h>
-#include <pwd.h>
-#include <sys/stat.h>
-#include <regex.h>
-
-#ifdef linux
-#include <sys/prctl.h>
-#endif
-
-#if defined(__FreeBSD__) || defined( __NetBSD__ ) || defined(SOLARIS)
-#include <netdb.h>
-#if defined(SOLARIS)
-extern int daemon(int, int); /* defined in libresolv of all places */
-#endif
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/cli.h"
-#include "asterisk/channel.h"
-#include "asterisk/ulaw.h"
-#include "asterisk/alaw.h"
-#include "asterisk/callerid.h"
-#include "asterisk/module.h"
-#include "asterisk/image.h"
-#include "asterisk/tdd.h"
-#include "asterisk/term.h"
-#include "asterisk/manager.h"
-#include "asterisk/cdr.h"
-#include "asterisk/pbx.h"
-#include "asterisk/enum.h"
-#include "asterisk/rtp.h"
-#include "asterisk/app.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-#include "asterisk/file.h"
-#include "asterisk/io.h"
-#include "asterisk/lock.h"
-#include "editline/histedit.h"
-#include "asterisk/config.h"
-#include "asterisk/version.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/devicestate.h"
-#include "asterisk/compat.h"
-
-#include "asterisk/doxyref.h" /* Doxygen documentation */
-
-#include "defaults.h"
-
-#ifndef AF_LOCAL
-#define AF_LOCAL AF_UNIX
-#define PF_LOCAL PF_UNIX
-#endif
-
-#define AST_MAX_CONNECTS 128
-#define NUM_MSGS 64
-
-/*! \brief Welcome message when starting a CLI interface */
-#define WELCOME_MESSAGE \
- ast_verbose("Asterisk " ASTERISK_VERSION ", Copyright (C) 1999 - 2006 Digium, Inc. and others.\n"); \
- ast_verbose("Created by Mark Spencer <markster@digium.com>\n"); \
- ast_verbose("Asterisk comes with ABSOLUTELY NO WARRANTY; type 'show warranty' for details.\n"); \
- ast_verbose("This is free software, with components licensed under the GNU General Public\n"); \
- ast_verbose("License version 2 and other licenses; you are welcome to redistribute it under\n"); \
- ast_verbose("certain conditions. Type 'show license' for details.\n"); \
- ast_verbose("=========================================================================\n")
-
-/*! \defgroup main_options
- \brief Main configuration options from \ref Config_ast "asterisk.conf" or
- the operating system command line when starting Asterisk
- Some of them can be changed in the CLI
- */
-/*! @{ */
-int option_verbose=0; /*!< Verbosity level */
-int option_debug=0; /*!< Debug level */
-int option_exec_includes=0; /*!< Allow \#exec in config files? */
-int option_nofork=0; /*!< Do not fork */
-int option_quiet=0; /*!< Keep quiet */
-int option_console=0; /*!< Console mode, no background */
-int option_highpriority=0; /*!< Run in realtime Linux priority */
-int option_remote=0; /*!< Remote CLI */
-int option_exec=0; /*!< */
-int option_initcrypto=0; /*!< Initialize crypto keys for RSA auth */
-int option_nocolor; /*!< Don't use termcap colors */
-int option_dumpcore = 0; /*!< Dump core when failing */
-int option_cache_record_files = 0; /*!< Cache sound files */
-int option_timestamp = 0; /*!< Timestamp in logging */
-int option_overrideconfig = 0; /*!< */
-int option_reconnect = 0; /*!< */
-int option_transcode_slin = 1; /*!< */
-int option_maxcalls = 0; /*!< */
-double option_maxload = 0.0; /*!< Max load avg on system */
-int option_dontwarn = 0; /*!< */
-int option_priority_jumping = 1; /*!< Enable priority jumping as result value for apps */
-int option_transmit_silence_during_record = 0; /*!< Transmit silence during record() app */
-
-/*! @} */
-
-int fully_booted = 0;
-char record_cache_dir[AST_CACHE_DIR_LEN] = AST_TMP_DIR;
-char debug_filename[AST_FILENAME_MAX] = "";
-
-static int ast_socket = -1; /*!< UNIX Socket for allowing remote control */
-static int ast_consock = -1; /*!< UNIX Socket for controlling another asterisk */
-int ast_mainpid;
-struct console {
- int fd; /*!< File descriptor */
- int p[2]; /*!< Pipe */
- pthread_t t; /*!< Thread of handler */
-};
-
-static struct ast_atexit {
- void (*func)(void);
- struct ast_atexit *next;
-} *atexits = NULL;
-
-AST_MUTEX_DEFINE_STATIC(atexitslock);
-
-time_t ast_startuptime;
-time_t ast_lastreloadtime;
-
-static History *el_hist = NULL;
-static EditLine *el = NULL;
-static char *remotehostname;
-
-struct console consoles[AST_MAX_CONNECTS];
-
-char defaultlanguage[MAX_LANGUAGE] = DEFAULT_LANGUAGE;
-
-static int ast_el_add_history(char *);
-static int ast_el_read_history(char *);
-static int ast_el_write_history(char *);
-
-char ast_config_AST_CONFIG_DIR[AST_CONFIG_MAX_PATH];
-char ast_config_AST_CONFIG_FILE[AST_CONFIG_MAX_PATH];
-char ast_config_AST_MODULE_DIR[AST_CONFIG_MAX_PATH];
-char ast_config_AST_SPOOL_DIR[AST_CONFIG_MAX_PATH];
-char ast_config_AST_MONITOR_DIR[AST_CONFIG_MAX_PATH];
-char ast_config_AST_VAR_DIR[AST_CONFIG_MAX_PATH];
-char ast_config_AST_LOG_DIR[AST_CONFIG_MAX_PATH];
-char ast_config_AST_AGI_DIR[AST_CONFIG_MAX_PATH];
-char ast_config_AST_DB[AST_CONFIG_MAX_PATH];
-char ast_config_AST_KEY_DIR[AST_CONFIG_MAX_PATH];
-char ast_config_AST_PID[AST_CONFIG_MAX_PATH];
-char ast_config_AST_SOCKET[AST_CONFIG_MAX_PATH];
-char ast_config_AST_RUN_DIR[AST_CONFIG_MAX_PATH];
-char ast_config_AST_RUN_USER[AST_CONFIG_MAX_PATH];
-char ast_config_AST_RUN_GROUP[AST_CONFIG_MAX_PATH];
-char ast_config_AST_CTL_PERMISSIONS[AST_CONFIG_MAX_PATH];
-char ast_config_AST_CTL_OWNER[AST_CONFIG_MAX_PATH] = "\0";
-char ast_config_AST_CTL_GROUP[AST_CONFIG_MAX_PATH] = "\0";
-char ast_config_AST_CTL[AST_CONFIG_MAX_PATH] = "asterisk.ctl";
-
-static char *_argv[256];
-static int shuttingdown = 0;
-static int restartnow = 0;
-static pthread_t consolethread = AST_PTHREADT_NULL;
-
-#if !defined(LOW_MEMORY)
-struct file_version {
- AST_LIST_ENTRY(file_version) list;
- const char *file;
- char *version;
-};
-
-static AST_LIST_HEAD_STATIC(file_versions, file_version);
-
-void ast_register_file_version(const char *file, const char *version)
-{
- struct file_version *new;
- char *work;
- size_t version_length;
-
- work = ast_strdupa(version);
- work = ast_strip(ast_strip_quoted(work, "$", "$"));
- version_length = strlen(work) + 1;
-
- new = calloc(1, sizeof(*new) + version_length);
- if (!new)
- return;
-
- new->file = file;
- new->version = (char *) new + sizeof(*new);
- memcpy(new->version, work, version_length);
- AST_LIST_LOCK(&file_versions);
- AST_LIST_INSERT_HEAD(&file_versions, new, list);
- AST_LIST_UNLOCK(&file_versions);
-}
-
-void ast_unregister_file_version(const char *file)
-{
- struct file_version *find;
-
- AST_LIST_LOCK(&file_versions);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
- if (!strcasecmp(find->file, file)) {
- AST_LIST_REMOVE_CURRENT(&file_versions, list);
- break;
- }
- }
- AST_LIST_TRAVERSE_SAFE_END;
- AST_LIST_UNLOCK(&file_versions);
- if (find)
- free(find);
-}
-
-static char show_version_files_help[] =
-"Usage: show version files [like <pattern>]\n"
-" Shows the revision numbers of the files used to build this copy of Asterisk.\n"
-" Optional regular expression pattern is used to filter the file list.\n";
-
-/*! CLI command to list module versions */
-static int handle_show_version_files(int fd, int argc, char *argv[])
-{
-#define FORMAT "%-25.25s %-40.40s\n"
- struct file_version *iterator;
- regex_t regexbuf;
- int havepattern = 0;
- int havename = 0;
- int count_files = 0;
-
- switch (argc) {
- case 5:
- if (!strcasecmp(argv[3], "like")) {
- if (regcomp(&regexbuf, argv[4], REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
- havepattern = 1;
- } else
- return RESULT_SHOWUSAGE;
- break;
- case 4:
- havename = 1;
- break;
- case 3:
- break;
- default:
- return RESULT_SHOWUSAGE;
- }
-
- ast_cli(fd, FORMAT, "File", "Revision");
- ast_cli(fd, FORMAT, "----", "--------");
- AST_LIST_LOCK(&file_versions);
- AST_LIST_TRAVERSE(&file_versions, iterator, list) {
- if (havename && strcasecmp(iterator->file, argv[3]))
- continue;
-
- if (havepattern && regexec(&regexbuf, iterator->file, 0, NULL, 0))
- continue;
-
- ast_cli(fd, FORMAT, iterator->file, iterator->version);
- count_files++;
- if (havename)
- break;
- }
- AST_LIST_UNLOCK(&file_versions);
- if (!havename) {
- ast_cli(fd, "%d files listed.\n", count_files);
- }
-
- if (havepattern)
- regfree(&regexbuf);
-
- return RESULT_SUCCESS;
-#undef FORMAT
-}
-
-static char *complete_show_version_files(char *line, char *word, int pos, int state)
-{
- struct file_version *find;
- int which = 0;
- char *ret = NULL;
- int matchlen = strlen(word);
-
- if (pos != 3)
- return NULL;
-
- AST_LIST_LOCK(&file_versions);
- AST_LIST_TRAVERSE(&file_versions, find, list) {
- if (!strncasecmp(word, find->file, matchlen)) {
- if (++which > state) {
- ret = strdup(find->file);
- break;
- }
- }
- }
- AST_LIST_UNLOCK(&file_versions);
-
- return ret;
-}
-#endif /* ! LOW_MEMORY */
-
-int ast_register_atexit(void (*func)(void))
-{
- int res = -1;
- struct ast_atexit *ae;
- ast_unregister_atexit(func);
- ae = malloc(sizeof(struct ast_atexit));
- ast_mutex_lock(&atexitslock);
- if (ae) {
- memset(ae, 0, sizeof(struct ast_atexit));
- ae->next = atexits;
- ae->func = func;
- atexits = ae;
- res = 0;
- }
- ast_mutex_unlock(&atexitslock);
- return res;
-}
-
-void ast_unregister_atexit(void (*func)(void))
-{
- struct ast_atexit *ae, *prev = NULL;
- ast_mutex_lock(&atexitslock);
- ae = atexits;
- while(ae) {
- if (ae->func == func) {
- if (prev)
- prev->next = ae->next;
- else
- atexits = ae->next;
- break;
- }
- prev = ae;
- ae = ae->next;
- }
- ast_mutex_unlock(&atexitslock);
-}
-
-static int fdprint(int fd, const char *s)
-{
- return write(fd, s, strlen(s) + 1);
-}
-
-/*! NULL handler so we can collect the child exit status */
-static void null_sig_handler(int signal)
-{
-
-}
-
-AST_MUTEX_DEFINE_STATIC(safe_system_lock);
-static unsigned int safe_system_level = 0;
-static void *safe_system_prev_handler;
-
-int ast_safe_system(const char *s)
-{
- pid_t pid;
- int x;
- int res;
- struct rusage rusage;
- int status;
- unsigned int level;
-
- /* keep track of how many ast_safe_system() functions
- are running at this moment
- */
- ast_mutex_lock(&safe_system_lock);
- level = safe_system_level++;
-
- /* only replace the handler if it has not already been done */
- if (level == 0)
- safe_system_prev_handler = signal(SIGCHLD, null_sig_handler);
-
- ast_mutex_unlock(&safe_system_lock);
-
- pid = fork();
-
- if (pid == 0) {
- /* Close file descriptors and launch system command */
- for (x = STDERR_FILENO + 1; x < 4096; x++)
- close(x);
- execl("/bin/sh", "/bin/sh", "-c", s, NULL);
- exit(1);
- } else if (pid > 0) {
- for(;;) {
- res = wait4(pid, &status, 0, &rusage);
- if (res > -1) {
- res = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
- break;
- } else if (errno != EINTR)
- break;
- }
- } else {
- ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
- res = -1;
- }
-
- ast_mutex_lock(&safe_system_lock);
- level = --safe_system_level;
-
- /* only restore the handler if we are the last one */
- if (level == 0)
- signal(SIGCHLD, safe_system_prev_handler);
-
- ast_mutex_unlock(&safe_system_lock);
-
- return res;
-}
-
-/*!
- * write the string to all attached console clients
- */
-static void ast_network_puts(const char *string)
-{
- int x;
- for (x=0;x<AST_MAX_CONNECTS; x++) {
- if (consoles[x].fd > -1)
- fdprint(consoles[x].p[1], string);
- }
-}
-
-/*!
- * write the string to the console, and all attached
- * console clients
- */
-void ast_console_puts(const char *string)
-{
- fputs(string, stdout);
- fflush(stdout);
- ast_network_puts(string);
-}
-
-static void network_verboser(const char *s, int pos, int replace, int complete)
- /* ARGUSED */
-{
- if (replace) {
- char *t = alloca(strlen(s) + 2);
- if (t) {
- sprintf(t, "\r%s", s);
- if (complete)
- ast_network_puts(t);
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- ast_network_puts(s);
- }
- } else {
- if (complete)
- ast_network_puts(s);
- }
-}
-
-static pthread_t lthread;
-
-static void *netconsole(void *vconsole)
-{
- struct console *con = vconsole;
- char hostname[MAXHOSTNAMELEN]="";
- char tmp[512];
- int res;
- struct pollfd fds[2];
-
- if (gethostname(hostname, sizeof(hostname)-1))
- ast_copy_string(hostname, "<Unknown>", sizeof(hostname));
- snprintf(tmp, sizeof(tmp), "%s/%d/%s\n", hostname, ast_mainpid, ASTERISK_VERSION);
- fdprint(con->fd, tmp);
- for(;;) {
- fds[0].fd = con->fd;
- fds[0].events = POLLIN;
- fds[0].revents = 0;
- fds[1].fd = con->p[0];
- fds[1].events = POLLIN;
- fds[1].revents = 0;
-
- res = poll(fds, 2, -1);
- if (res < 0) {
- if (errno != EINTR)
- ast_log(LOG_WARNING, "poll returned < 0: %s\n", strerror(errno));
- continue;
- }
- if (fds[0].revents) {
- res = read(con->fd, tmp, sizeof(tmp));
- if (res < 1) {
- break;
- }
- tmp[res] = 0;
- ast_cli_command(con->fd, tmp);
- }
- if (fds[1].revents) {
- res = read(con->p[0], tmp, sizeof(tmp));
- if (res < 1) {
- ast_log(LOG_ERROR, "read returned %d\n", res);
- break;
- }
- res = write(con->fd, tmp, res);
- if (res < 1)
- break;
- }
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Remote UNIX connection disconnected\n");
- close(con->fd);
- close(con->p[0]);
- close(con->p[1]);
- con->fd = -1;
-
- return NULL;
-}
-
-static void *listener(void *unused)
-{
- struct sockaddr_un sunaddr;
- int s;
- socklen_t len;
- int x;
- int flags;
- struct pollfd fds[1];
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- for(;;) {
- if (ast_socket < 0)
- return NULL;
- fds[0].fd = ast_socket;
- fds[0].events= POLLIN;
- s = poll(fds, 1, -1);
- if (s < 0) {
- if (errno != EINTR)
- ast_log(LOG_WARNING, "poll returned error: %s\n", strerror(errno));
- continue;
- }
- len = sizeof(sunaddr);
- s = accept(ast_socket, (struct sockaddr *)&sunaddr, &len);
- if (s < 0) {
- if (errno != EINTR)
- ast_log(LOG_WARNING, "Accept returned %d: %s\n", s, strerror(errno));
- } else {
- for (x=0;x<AST_MAX_CONNECTS;x++) {
- if (consoles[x].fd < 0) {
- if (socketpair(AF_LOCAL, SOCK_STREAM, 0, consoles[x].p)) {
- ast_log(LOG_ERROR, "Unable to create pipe: %s\n", strerror(errno));
- consoles[x].fd = -1;
- fdprint(s, "Server failed to create pipe\n");
- close(s);
- break;
- }
- flags = fcntl(consoles[x].p[1], F_GETFL);
- fcntl(consoles[x].p[1], F_SETFL, flags | O_NONBLOCK);
- consoles[x].fd = s;
- if (ast_pthread_create(&consoles[x].t, &attr, netconsole, &consoles[x])) {
- ast_log(LOG_ERROR, "Unable to spawn thread to handle connection: %s\n", strerror(errno));
- consoles[x].fd = -1;
- fdprint(s, "Server failed to spawn thread\n");
- close(s);
- }
- break;
- }
- }
- if (x >= AST_MAX_CONNECTS) {
- fdprint(s, "No more connections allowed\n");
- ast_log(LOG_WARNING, "No more connections allowed\n");
- close(s);
- } else if (consoles[x].fd > -1) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Remote UNIX connection\n");
- }
- }
- }
- return NULL;
-}
-
-static int ast_makesocket(void)
-{
- struct sockaddr_un sunaddr;
- int res;
- int x;
- uid_t uid = -1;
- gid_t gid = -1;
-
- for (x = 0; x < AST_MAX_CONNECTS; x++)
- consoles[x].fd = -1;
- unlink(ast_config_AST_SOCKET);
- ast_socket = socket(PF_LOCAL, SOCK_STREAM, 0);
- if (ast_socket < 0) {
- ast_log(LOG_WARNING, "Unable to create control socket: %s\n", strerror(errno));
- return -1;
- }
- memset(&sunaddr, 0, sizeof(sunaddr));
- sunaddr.sun_family = AF_LOCAL;
- ast_copy_string(sunaddr.sun_path, ast_config_AST_SOCKET, sizeof(sunaddr.sun_path));
- res = bind(ast_socket, (struct sockaddr *)&sunaddr, sizeof(sunaddr));
- if (res) {
- ast_log(LOG_WARNING, "Unable to bind socket to %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
- close(ast_socket);
- ast_socket = -1;
- return -1;
- }
- res = listen(ast_socket, 2);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to listen on socket %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
- close(ast_socket);
- ast_socket = -1;
- return -1;
- }
- ast_register_verbose(network_verboser);
- ast_pthread_create(&lthread, NULL, listener, NULL);
-
- if (!ast_strlen_zero(ast_config_AST_CTL_OWNER)) {
- struct passwd *pw;
- if ((pw = getpwnam(ast_config_AST_CTL_OWNER)) == NULL) {
- ast_log(LOG_WARNING, "Unable to find uid of user %s\n", ast_config_AST_CTL_OWNER);
- } else {
- uid = pw->pw_uid;
- }
- }
-
- if (!ast_strlen_zero(ast_config_AST_CTL_GROUP)) {
- struct group *grp;
- if ((grp = getgrnam(ast_config_AST_CTL_GROUP)) == NULL) {
- ast_log(LOG_WARNING, "Unable to find gid of group %s\n", ast_config_AST_CTL_GROUP);
- } else {
- gid = grp->gr_gid;
- }
- }
-
- if (chown(ast_config_AST_SOCKET, uid, gid) < 0)
- ast_log(LOG_WARNING, "Unable to change ownership of %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
-
- if (!ast_strlen_zero(ast_config_AST_CTL_PERMISSIONS)) {
- int p1;
- mode_t p;
- sscanf(ast_config_AST_CTL_PERMISSIONS, "%o", &p1);
- p = p1;
- if ((chmod(ast_config_AST_SOCKET, p)) < 0)
- ast_log(LOG_WARNING, "Unable to change file permissions of %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
- }
-
- return 0;
-}
-
-static int ast_tryconnect(void)
-{
- struct sockaddr_un sunaddr;
- int res;
- ast_consock = socket(PF_LOCAL, SOCK_STREAM, 0);
- if (ast_consock < 0) {
- ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
- return 0;
- }
- memset(&sunaddr, 0, sizeof(sunaddr));
- sunaddr.sun_family = AF_LOCAL;
- ast_copy_string(sunaddr.sun_path, (char *)ast_config_AST_SOCKET, sizeof(sunaddr.sun_path));
- res = connect(ast_consock, (struct sockaddr *)&sunaddr, sizeof(sunaddr));
- if (res) {
- close(ast_consock);
- ast_consock = -1;
- return 0;
- } else
- return 1;
-}
-
-/*! Urgent handler
- Called by soft_hangup to interrupt the poll, read, or other
- system call. We don't actually need to do anything though.
- Remember: Cannot EVER ast_log from within a signal handler
- SLD: seems to be some pthread activity relating to the printf anyway:
- which is leading to a deadlock?
- */
-static void urg_handler(int num)
-{
-#if 0
- if (option_debug > 2)
- printf("-- Asterisk Urgent handler\n");
-#endif
- signal(num, urg_handler);
- return;
-}
-
-static void hup_handler(int num)
-{
- if (option_verbose > 1)
- printf("Received HUP signal -- Reloading configs\n");
- if (restartnow)
- execvp(_argv[0], _argv);
- /* XXX This could deadlock XXX */
- ast_module_reload(NULL);
- signal(num, hup_handler);
-}
-
-static void child_handler(int sig)
-{
- /* Must not ever ast_log or ast_verbose within signal handler */
- int n, status;
-
- /*
- * Reap all dead children -- not just one
- */
- for (n = 0; wait4(-1, &status, WNOHANG, NULL) > 0; n++)
- ;
- if (n == 0 && option_debug)
- printf("Huh? Child handler, but nobody there?\n");
- signal(sig, child_handler);
-}
-
-/*! Set an X-term or screen title */
-static void set_title(char *text)
-{
- if (getenv("TERM") && strstr(getenv("TERM"), "xterm"))
- fprintf(stdout, "\033]2;%s\007", text);
-}
-
-static void set_icon(char *text)
-{
- if (getenv("TERM") && strstr(getenv("TERM"), "xterm"))
- fprintf(stdout, "\033]1;%s\007", text);
-}
-
-/*! We set ourselves to a high priority, that we might pre-empt everything
- else. If your PBX has heavy activity on it, this is a good thing. */
-int ast_set_priority(int pri)
-{
- struct sched_param sched;
- memset(&sched, 0, sizeof(sched));
-#ifdef __linux__
- if (pri) {
- sched.sched_priority = 10;
- if (sched_setscheduler(0, SCHED_RR, &sched)) {
- ast_log(LOG_WARNING, "Unable to set high priority\n");
- return -1;
- } else
- if (option_verbose)
- ast_verbose("Set to realtime thread\n");
- } else {
- sched.sched_priority = 0;
- if (sched_setscheduler(0, SCHED_OTHER, &sched)) {
- ast_log(LOG_WARNING, "Unable to set normal priority\n");
- return -1;
- }
- }
-#else
- if (pri) {
- if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
- ast_log(LOG_WARNING, "Unable to set high priority\n");
- return -1;
- } else
- if (option_verbose)
- ast_verbose("Set to high priority\n");
- } else {
- if (setpriority(PRIO_PROCESS, 0, 0) == -1) {
- ast_log(LOG_WARNING, "Unable to set normal priority\n");
- return -1;
- }
- }
-#endif
- return 0;
-}
-
-static void ast_run_atexits(void)
-{
- struct ast_atexit *ae;
- ast_mutex_lock(&atexitslock);
- ae = atexits;
- while(ae) {
- if (ae->func)
- ae->func();
- ae = ae->next;
- }
- ast_mutex_unlock(&atexitslock);
-}
-
-static void quit_handler(int num, int nice, int safeshutdown, int restart)
-{
- char filename[80] = "";
- time_t s,e;
- int x;
- /* Try to get as many CDRs as possible submitted to the backend engines (if in batch mode) */
- ast_cdr_engine_term();
- if (safeshutdown) {
- shuttingdown = 1;
- if (!nice) {
- /* Begin shutdown routine, hanging up active channels */
- ast_begin_shutdown(1);
- if (option_verbose && option_console)
- ast_verbose("Beginning asterisk %s....\n", restart ? "restart" : "shutdown");
- time(&s);
- for(;;) {
- time(&e);
- /* Wait up to 15 seconds for all channels to go away */
- if ((e - s) > 15)
- break;
- if (!ast_active_channels())
- break;
- if (!shuttingdown)
- break;
- /* Sleep 1/10 of a second */
- usleep(100000);
- }
- } else {
- if (nice < 2)
- ast_begin_shutdown(0);
- if (option_verbose && option_console)
- ast_verbose("Waiting for inactivity to perform %s...\n", restart ? "restart" : "halt");
- for(;;) {
- if (!ast_active_channels())
- break;
- if (!shuttingdown)
- break;
- sleep(1);
- }
- }
-
- if (!shuttingdown) {
- if (option_verbose && option_console)
- ast_verbose("Asterisk %s cancelled.\n", restart ? "restart" : "shutdown");
- return;
- }
- }
- if (option_console || option_remote) {
- if (getenv("HOME"))
- snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
- if (!ast_strlen_zero(filename))
- ast_el_write_history(filename);
- if (el != NULL)
- el_end(el);
- if (el_hist != NULL)
- history_end(el_hist);
- }
- if (option_verbose)
- ast_verbose("Executing last minute cleanups\n");
- ast_run_atexits();
- /* Called on exit */
- if (option_verbose && option_console)
- ast_verbose("Asterisk %s ending (%d).\n", ast_active_channels() ? "uncleanly" : "cleanly", num);
- else if (option_debug)
- ast_log(LOG_DEBUG, "Asterisk ending (%d).\n", num);
- manager_event(EVENT_FLAG_SYSTEM, "Shutdown", "Shutdown: %s\r\nRestart: %s\r\n", ast_active_channels() ? "Uncleanly" : "Cleanly", restart ? "True" : "False");
- if (ast_socket > -1) {
- close(ast_socket);
- ast_socket = -1;
- }
- if (ast_consock > -1)
- close(ast_consock);
- if (ast_socket > -1)
- unlink((char *)ast_config_AST_SOCKET);
- if (!option_remote) unlink((char *)ast_config_AST_PID);
- printf(term_quit());
- if (restart) {
- if (option_verbose || option_console)
- ast_verbose("Preparing for Asterisk restart...\n");
- /* Mark all FD's for closing on exec */
- for (x=3;x<32768;x++) {
- fcntl(x, F_SETFD, FD_CLOEXEC);
- }
- if (option_verbose || option_console)
- ast_verbose("Restarting Asterisk NOW...\n");
- restartnow = 1;
-
- /* close logger */
- close_logger();
-
- /* If there is a consolethread running send it a SIGHUP
- so it can execvp, otherwise we can do it ourselves */
- if ((consolethread != AST_PTHREADT_NULL) && (consolethread != pthread_self())) {
- pthread_kill(consolethread, SIGHUP);
- /* Give the signal handler some time to complete */
- sleep(2);
- } else
- execvp(_argv[0], _argv);
-
- } else {
- /* close logger */
- close_logger();
- }
- exit(0);
-}
-
-static void __quit_handler(int num)
-{
- quit_handler(num, 0, 1, 0);
-}
-
-static const char *fix_header(char *outbuf, int maxout, const char *s, char *cmp)
-{
- const char *c;
- if (!strncmp(s, cmp, strlen(cmp))) {
- c = s + strlen(cmp);
- term_color(outbuf, cmp, COLOR_GRAY, 0, maxout);
- return c;
- }
- return NULL;
-}
-
-static void console_verboser(const char *s, int pos, int replace, int complete)
-{
- char tmp[80];
- const char *c=NULL;
- /* Return to the beginning of the line */
- if (!pos) {
- fprintf(stdout, "\r");
- if ((c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_4)) ||
- (c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_3)) ||
- (c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_2)) ||
- (c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_1)))
- fputs(tmp, stdout);
- }
- if (c)
- fputs(c + pos,stdout);
- else
- fputs(s + pos,stdout);
- fflush(stdout);
- if (complete) {
- /* Wake up a poll()ing console */
- if (option_console && consolethread != AST_PTHREADT_NULL)
- pthread_kill(consolethread, SIGURG);
- }
-}
-
-static int ast_all_zeros(char *s)
-{
- while(*s) {
- if (*s > 32)
- return 0;
- s++;
- }
- return 1;
-}
-
-static void consolehandler(char *s)
-{
- printf(term_end());
- fflush(stdout);
- /* Called when readline data is available */
- if (s && !ast_all_zeros(s))
- ast_el_add_history(s);
- /* Give the console access to the shell */
- if (s) {
- /* The real handler for bang */
- if (s[0] == '!') {
- if (s[1])
- ast_safe_system(s+1);
- else
- ast_safe_system(getenv("SHELL") ? getenv("SHELL") : "/bin/sh");
- } else
- ast_cli_command(STDOUT_FILENO, s);
- } else
- fprintf(stdout, "\nUse \"quit\" to exit\n");
-}
-
-static int remoteconsolehandler(char *s)
-{
- int ret = 0;
- /* Called when readline data is available */
- if (s && !ast_all_zeros(s))
- ast_el_add_history(s);
- /* Give the console access to the shell */
- if (s) {
- /* The real handler for bang */
- if (s[0] == '!') {
- if (s[1])
- ast_safe_system(s+1);
- else
- ast_safe_system(getenv("SHELL") ? getenv("SHELL") : "/bin/sh");
- ret = 1;
- }
- if ((strncasecmp(s, "quit", 4) == 0 || strncasecmp(s, "exit", 4) == 0) &&
- (s[4] == '\0' || isspace(s[4]))) {
- quit_handler(0, 0, 0, 0);
- ret = 1;
- }
- } else
- fprintf(stdout, "\nUse \"quit\" to exit\n");
-
- return ret;
-}
-
-static char abort_halt_help[] =
-"Usage: abort shutdown\n"
-" Causes Asterisk to abort an executing shutdown or restart, and resume normal\n"
-" call operations.\n";
-
-static char shutdown_now_help[] =
-"Usage: stop now\n"
-" Shuts down a running Asterisk immediately, hanging up all active calls .\n";
-
-static char shutdown_gracefully_help[] =
-"Usage: stop gracefully\n"
-" Causes Asterisk to not accept new calls, and exit when all\n"
-" active calls have terminated normally.\n";
-
-static char shutdown_when_convenient_help[] =
-"Usage: stop when convenient\n"
-" Causes Asterisk to perform a shutdown when all active calls have ended.\n";
-
-static char restart_now_help[] =
-"Usage: restart now\n"
-" Causes Asterisk to hangup all calls and exec() itself performing a cold\n"
-" restart.\n";
-
-static char restart_gracefully_help[] =
-"Usage: restart gracefully\n"
-" Causes Asterisk to stop accepting new calls and exec() itself performing a cold\n"
-" restart when all active calls have ended.\n";
-
-static char restart_when_convenient_help[] =
-"Usage: restart when convenient\n"
-" Causes Asterisk to perform a cold restart when all active calls have ended.\n";
-
-static char bang_help[] =
-"Usage: !<command>\n"
-" Executes a given shell command\n";
-
-static char show_warranty_help[] =
-"Usage: show warranty\n"
-" Shows the warranty (if any) for this copy of Asterisk.\n";
-
-static char show_license_help[] =
-"Usage: show license\n"
-" Shows the license(s) for this copy of Asterisk.\n";
-
-#if 0
-static int handle_quit(int fd, int argc, char *argv[])
-{
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- quit_handler(0, 0, 1, 0);
- return RESULT_SUCCESS;
-}
-#endif
-
-static int handle_shutdown_now(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- quit_handler(0, 0 /* Not nice */, 1 /* safely */, 0 /* not restart */);
- return RESULT_SUCCESS;
-}
-
-static int handle_shutdown_gracefully(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- quit_handler(0, 1 /* nicely */, 1 /* safely */, 0 /* no restart */);
- return RESULT_SUCCESS;
-}
-
-static int handle_shutdown_when_convenient(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- quit_handler(0, 2 /* really nicely */, 1 /* safely */, 0 /* don't restart */);
- return RESULT_SUCCESS;
-}
-
-static int handle_restart_now(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- quit_handler(0, 0 /* not nicely */, 1 /* safely */, 1 /* restart */);
- return RESULT_SUCCESS;
-}
-
-static int handle_restart_gracefully(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- quit_handler(0, 1 /* nicely */, 1 /* safely */, 1 /* restart */);
- return RESULT_SUCCESS;
-}
-
-static int handle_restart_when_convenient(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- quit_handler(0, 2 /* really nicely */, 1 /* safely */, 1 /* restart */);
- return RESULT_SUCCESS;
-}
-
-static int handle_abort_halt(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- ast_cancel_shutdown();
- shuttingdown = 0;
- return RESULT_SUCCESS;
-}
-
-static int handle_bang(int fd, int argc, char *argv[])
-{
- return RESULT_SUCCESS;
-}
-static const char *warranty_lines[] = {
- "\n",
- " NO WARRANTY\n",
- "\n",
- "BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n",
- "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n",
- "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n",
- "PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n",
- "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n",
- "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n",
- "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n",
- "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n",
- "REPAIR OR CORRECTION.\n",
- "\n",
- "IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n",
- "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n",
- "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n",
- "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n",
- "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n",
- "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n",
- "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n",
- "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n",
- "POSSIBILITY OF SUCH DAMAGES.\n",
-};
-
-static int show_warranty(int fd, int argc, char *argv[])
-{
- int x;
-
- for (x = 0; x < sizeof(warranty_lines) / sizeof(warranty_lines[0]); x++)
- ast_cli(fd, (char *) warranty_lines[x]);
-
- return RESULT_SUCCESS;
-}
-
-static const char *license_lines[] = {
- "\n",
- "This program is free software; you can redistribute it and/or modify\n",
- "it under the terms of the GNU General Public License version 2 as\n",
- "published by the Free Software Foundation.\n",
- "\n",
- "This program also contains components licensed under other licenses.\n",
- "They include:\n",
- "\n",
- "This program is distributed in the hope that it will be useful,\n",
- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
- "GNU General Public License for more details.\n",
- "\n",
- "You should have received a copy of the GNU General Public License\n",
- "along with this program; if not, write to the Free Software\n",
- "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n",
-};
-
-static int show_license(int fd, int argc, char *argv[])
-{
- int x;
-
- for (x = 0; x < sizeof(license_lines) / sizeof(license_lines[0]); x++)
- ast_cli(fd, (char *) license_lines[x]);
-
- return RESULT_SUCCESS;
-}
-
-#define ASTERISK_PROMPT "*CLI> "
-
-#define ASTERISK_PROMPT2 "%s*CLI> "
-
-static struct ast_cli_entry core_cli[] = {
- { { "abort", "halt", NULL }, handle_abort_halt,
- "Cancel a running halt", abort_halt_help },
- { { "stop", "now", NULL }, handle_shutdown_now,
- "Shut down Asterisk immediately", shutdown_now_help },
- { { "stop", "gracefully", NULL }, handle_shutdown_gracefully,
- "Gracefully shut down Asterisk", shutdown_gracefully_help },
- { { "stop", "when","convenient", NULL }, handle_shutdown_when_convenient,
- "Shut down Asterisk at empty call volume", shutdown_when_convenient_help },
- { { "restart", "now", NULL }, handle_restart_now,
- "Restart Asterisk immediately", restart_now_help },
- { { "restart", "gracefully", NULL }, handle_restart_gracefully,
- "Restart Asterisk gracefully", restart_gracefully_help },
- { { "restart", "when", "convenient", NULL }, handle_restart_when_convenient,
- "Restart Asterisk at empty call volume", restart_when_convenient_help },
- { { "show", "warranty", NULL }, show_warranty,
- "Show the warranty (if any) for this copy of Asterisk", show_warranty_help },
- { { "show", "license", NULL }, show_license,
- "Show the license(s) for this copy of Asterisk", show_license_help },
- { { "!", NULL }, handle_bang,
- "Execute a shell command", bang_help },
-#if !defined(LOW_MEMORY)
- { { "show", "version", "files", NULL }, handle_show_version_files,
- "Show versions of files used to build Asterisk", show_version_files_help, complete_show_version_files },
-#endif /* ! LOW_MEMORY */
-};
-
-static int ast_el_read_char(EditLine *el, char *cp)
-{
- int num_read=0;
- int lastpos=0;
- struct pollfd fds[2];
- int res;
- int max;
- char buf[512];
-
- for (;;) {
- max = 1;
- fds[0].fd = ast_consock;
- fds[0].events = POLLIN;
- if (!option_exec) {
- fds[1].fd = STDIN_FILENO;
- fds[1].events = POLLIN;
- max++;
- }
- res = poll(fds, max, -1);
- if (res < 0) {
- if (errno == EINTR)
- continue;
- ast_log(LOG_ERROR, "poll failed: %s\n", strerror(errno));
- break;
- }
-
- if (!option_exec && fds[1].revents) {
- num_read = read(STDIN_FILENO, cp, 1);
- if (num_read < 1) {
- break;
- } else
- return (num_read);
- }
- if (fds[0].revents) {
- res = read(ast_consock, buf, sizeof(buf) - 1);
- /* if the remote side disappears exit */
- if (res < 1) {
- fprintf(stderr, "\nDisconnected from Asterisk server\n");
- if (!option_reconnect) {
- quit_handler(0, 0, 0, 0);
- } else {
- int tries;
- int reconnects_per_second = 20;
- fprintf(stderr, "Attempting to reconnect for 30 seconds\n");
- for (tries=0;tries<30 * reconnects_per_second;tries++) {
- if (ast_tryconnect()) {
- fprintf(stderr, "Reconnect succeeded after %.3f seconds\n", 1.0 / reconnects_per_second * tries);
- printf(term_quit());
- WELCOME_MESSAGE;
- break;
- } else {
- usleep(1000000 / reconnects_per_second);
- }
- }
- if (tries >= 30 * reconnects_per_second) {
- fprintf(stderr, "Failed to reconnect for 30 seconds. Quitting.\n");
- quit_handler(0, 0, 0, 0);
- }
- }
- }
-
- buf[res] = '\0';
-
- if (!option_exec && !lastpos)
- write(STDOUT_FILENO, "\r", 1);
- write(STDOUT_FILENO, buf, res);
- if ((buf[res-1] == '\n') || (buf[res-2] == '\n')) {
- *cp = CC_REFRESH;
- return(1);
- } else {
- lastpos = 1;
- }
- }
- }
-
- *cp = '\0';
- return (0);
-}
-
-static char *cli_prompt(EditLine *el)
-{
- static char prompt[200];
- char *pfmt;
- int color_used=0;
- char term_code[20];
-
- if ((pfmt = getenv("ASTERISK_PROMPT"))) {
- char *t = pfmt, *p = prompt;
- memset(prompt, 0, sizeof(prompt));
- while (*t != '\0' && *p < sizeof(prompt)) {
- if (*t == '%') {
- char hostname[MAXHOSTNAMELEN]="";
- int i;
- time_t ts;
- struct tm tm;
-#ifdef linux
- FILE *LOADAVG;
-#endif
- int fgcolor = COLOR_WHITE, bgcolor = COLOR_BLACK;
-
- t++;
- switch (*t) {
- case 'C': /* color */
- t++;
- if (sscanf(t, "%d;%d%n", &fgcolor, &bgcolor, &i) == 2) {
- strncat(p, term_color_code(term_code, fgcolor, bgcolor, sizeof(term_code)),sizeof(prompt) - strlen(prompt) - 1);
- t += i - 1;
- } else if (sscanf(t, "%d%n", &fgcolor, &i) == 1) {
- strncat(p, term_color_code(term_code, fgcolor, 0, sizeof(term_code)),sizeof(prompt) - strlen(prompt) - 1);
- t += i - 1;
- }
-
- /* If the color has been reset correctly, then there's no need to reset it later */
- if ((fgcolor == COLOR_WHITE) && (bgcolor == COLOR_BLACK)) {
- color_used = 0;
- } else {
- color_used = 1;
- }
- break;
- case 'd': /* date */
- memset(&tm, 0, sizeof(struct tm));
- time(&ts);
- if (localtime_r(&ts, &tm)) {
- strftime(p, sizeof(prompt) - strlen(prompt), "%Y-%m-%d", &tm);
- }
- break;
- case 'h': /* hostname */
- if (!gethostname(hostname, sizeof(hostname) - 1)) {
- strncat(p, hostname, sizeof(prompt) - strlen(prompt) - 1);
- } else {
- strncat(p, "localhost", sizeof(prompt) - strlen(prompt) - 1);
- }
- break;
- case 'H': /* short hostname */
- if (!gethostname(hostname, sizeof(hostname) - 1)) {
- for (i=0;i<sizeof(hostname);i++) {
- if (hostname[i] == '.') {
- hostname[i] = '\0';
- break;
- }
- }
- strncat(p, hostname, sizeof(prompt) - strlen(prompt) - 1);
- } else {
- strncat(p, "localhost", sizeof(prompt) - strlen(prompt) - 1);
- }
- break;
-#ifdef linux
- case 'l': /* load avg */
- t++;
- if ((LOADAVG = fopen("/proc/loadavg", "r"))) {
- float avg1, avg2, avg3;
- int actproc, totproc, npid, which;
- fscanf(LOADAVG, "%f %f %f %d/%d %d",
- &avg1, &avg2, &avg3, &actproc, &totproc, &npid);
- if (sscanf(t, "%d", &which) == 1) {
- switch (which) {
- case 1:
- snprintf(p, sizeof(prompt) - strlen(prompt), "%.2f", avg1);
- break;
- case 2:
- snprintf(p, sizeof(prompt) - strlen(prompt), "%.2f", avg2);
- break;
- case 3:
- snprintf(p, sizeof(prompt) - strlen(prompt), "%.2f", avg3);
- break;
- case 4:
- snprintf(p, sizeof(prompt) - strlen(prompt), "%d/%d", actproc, totproc);
- break;
- case 5:
- snprintf(p, sizeof(prompt) - strlen(prompt), "%d", npid);
- break;
- }
- }
- }
- break;
-#endif
- case 't': /* time */
- memset(&tm, 0, sizeof(struct tm));
- time(&ts);
- if (localtime_r(&ts, &tm)) {
- strftime(p, sizeof(prompt) - strlen(prompt), "%H:%M:%S", &tm);
- }
- break;
- case '#': /* process console or remote? */
- if (! option_remote) {
- strncat(p, "#", sizeof(prompt) - strlen(prompt) - 1);
- } else {
- strncat(p, ">", sizeof(prompt) - strlen(prompt) - 1);
- }
- break;
- case '%': /* literal % */
- strncat(p, "%", sizeof(prompt) - strlen(prompt) - 1);
- break;
- case '\0': /* % is last character - prevent bug */
- t--;
- break;
- }
- while (*p != '\0') {
- p++;
- }
- t++;
- } else {
- *p = *t;
- p++;
- t++;
- }
- }
- if (color_used) {
- /* Force colors back to normal at end */
- term_color_code(term_code, COLOR_WHITE, COLOR_BLACK, sizeof(term_code));
- if (strlen(term_code) > sizeof(prompt) - strlen(prompt)) {
- strncat(prompt + sizeof(prompt) - strlen(term_code) - 1, term_code, strlen(term_code));
- } else {
- strncat(p, term_code, sizeof(term_code));
- }
- }
- } else if (remotehostname)
- snprintf(prompt, sizeof(prompt), ASTERISK_PROMPT2, remotehostname);
- else
- snprintf(prompt, sizeof(prompt), ASTERISK_PROMPT);
-
- return(prompt);
-}
-
-static char **ast_el_strtoarr(char *buf)
-{
- char **match_list = NULL, *retstr;
- size_t match_list_len;
- int matches = 0;
-
- match_list_len = 1;
- while ( (retstr = strsep(&buf, " ")) != NULL) {
-
- if (!strcmp(retstr, AST_CLI_COMPLETE_EOF))
- break;
- if (matches + 1 >= match_list_len) {
- match_list_len <<= 1;
- match_list = realloc(match_list, match_list_len * sizeof(char *));
- }
-
- match_list[matches++] = strdup(retstr);
- }
-
- if (!match_list)
- return (char **) NULL;
-
- if (matches>= match_list_len)
- match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
-
- match_list[matches] = (char *) NULL;
-
- return match_list;
-}
-
-static int ast_el_sort_compare(const void *i1, const void *i2)
-{
- char *s1, *s2;
-
- s1 = ((char **)i1)[0];
- s2 = ((char **)i2)[0];
-
- return strcasecmp(s1, s2);
-}
-
-static int ast_cli_display_match_list(char **matches, int len, int max)
-{
- int i, idx, limit, count;
- int screenwidth = 0;
- int numoutput = 0, numoutputline = 0;
-
- screenwidth = ast_get_termcols(STDOUT_FILENO);
-
- /* find out how many entries can be put on one line, with two spaces between strings */
- limit = screenwidth / (max + 2);
- if (limit == 0)
- limit = 1;
-
- /* how many lines of output */
- count = len / limit;
- if (count * limit < len)
- count++;
-
- idx = 1;
-
- qsort(&matches[0], (size_t)(len + 1), sizeof(char *), ast_el_sort_compare);
-
- for (; count > 0; count--) {
- numoutputline = 0;
- for (i=0; i < limit && matches[idx]; i++, idx++) {
-
- /* Don't print dupes */
- if ( (matches[idx+1] != NULL && strcmp(matches[idx], matches[idx+1]) == 0 ) ) {
- i--;
- free(matches[idx]);
- matches[idx] = NULL;
- continue;
- }
-
- numoutput++;
- numoutputline++;
- fprintf(stdout, "%-*s ", max, matches[idx]);
- free(matches[idx]);
- matches[idx] = NULL;
- }
- if (numoutputline > 0)
- fprintf(stdout, "\n");
- }
-
- return numoutput;
-}
-
-
-static char *cli_complete(EditLine *el, int ch)
-{
- int len=0;
- char *ptr;
- int nummatches = 0;
- char **matches;
- int retval = CC_ERROR;
- char buf[2048];
- int res;
-
- LineInfo *lf = (LineInfo *)el_line(el);
-
- *(char *)lf->cursor = '\0';
- ptr = (char *)lf->cursor;
- if (ptr) {
- while (ptr > lf->buffer) {
- if (isspace(*ptr)) {
- ptr++;
- break;
- }
- ptr--;
- }
- }
-
- len = lf->cursor - ptr;
-
- if (option_remote) {
- snprintf(buf, sizeof(buf),"_COMMAND NUMMATCHES \"%s\" \"%s\"", lf->buffer, ptr);
- fdprint(ast_consock, buf);
- res = read(ast_consock, buf, sizeof(buf));
- buf[res] = '\0';
- nummatches = atoi(buf);
-
- if (nummatches > 0) {
- char *mbuf;
- int mlen = 0, maxmbuf = 2048;
- /* Start with a 2048 byte buffer */
- mbuf = malloc(maxmbuf);
- if (!mbuf)
- return (char *)(CC_ERROR);
- snprintf(buf, sizeof(buf),"_COMMAND MATCHESARRAY \"%s\" \"%s\"", lf->buffer, ptr);
- fdprint(ast_consock, buf);
- res = 0;
- mbuf[0] = '\0';
- while (!strstr(mbuf, AST_CLI_COMPLETE_EOF) && res != -1) {
- if (mlen + 1024 > maxmbuf) {
- /* Every step increment buffer 1024 bytes */
- maxmbuf += 1024;
- mbuf = realloc(mbuf, maxmbuf);
- if (!mbuf)
- return (char *)(CC_ERROR);
- }
- /* Only read 1024 bytes at a time */
- res = read(ast_consock, mbuf + mlen, 1024);
- if (res > 0)
- mlen += res;
- }
- mbuf[mlen] = '\0';
-
- matches = ast_el_strtoarr(mbuf);
- free(mbuf);
- } else
- matches = (char **) NULL;
-
-
- } else {
-
- nummatches = ast_cli_generatornummatches((char *)lf->buffer,ptr);
- matches = ast_cli_completion_matches((char *)lf->buffer,ptr);
- }
-
- if (matches) {
- int i;
- int matches_num, maxlen, match_len;
-
- if (matches[0][0] != '\0') {
- el_deletestr(el, (int) len);
- el_insertstr(el, matches[0]);
- retval = CC_REFRESH;
- }
-
- if (nummatches == 1) {
- /* Found an exact match */
- el_insertstr(el, " ");
- retval = CC_REFRESH;
- } else {
- /* Must be more than one match */
- for (i=1, maxlen=0; matches[i]; i++) {
- match_len = strlen(matches[i]);
- if (match_len > maxlen)
- maxlen = match_len;
- }
- matches_num = i - 1;
- if (matches_num >1) {
- fprintf(stdout, "\n");
- ast_cli_display_match_list(matches, nummatches, maxlen);
- retval = CC_REDISPLAY;
- } else {
- el_insertstr(el," ");
- retval = CC_REFRESH;
- }
- }
- free(matches);
- }
-
- return (char *)(long)retval;
-}
-
-static int ast_el_initialize(void)
-{
- HistEvent ev;
- char *editor = getenv("AST_EDITOR");
-
- if (el != NULL)
- el_end(el);
- if (el_hist != NULL)
- history_end(el_hist);
-
- el = el_init("asterisk", stdin, stdout, stderr);
- el_set(el, EL_PROMPT, cli_prompt);
-
- el_set(el, EL_EDITMODE, 1);
- el_set(el, EL_EDITOR, editor ? editor : "emacs");
- el_hist = history_init();
- if (!el || !el_hist)
- return -1;
-
- /* setup history with 100 entries */
- history(el_hist, &ev, H_SETSIZE, 100);
-
- el_set(el, EL_HIST, history, el_hist);
-
- el_set(el, EL_ADDFN, "ed-complete", "Complete argument", cli_complete);
- /* Bind <tab> to command completion */
- el_set(el, EL_BIND, "^I", "ed-complete", NULL);
- /* Bind ? to command completion */
- el_set(el, EL_BIND, "?", "ed-complete", NULL);
- /* Bind ^D to redisplay */
- el_set(el, EL_BIND, "^D", "ed-redisplay", NULL);
-
- return 0;
-}
-
-static int ast_el_add_history(char *buf)
-{
- HistEvent ev;
-
- if (el_hist == NULL || el == NULL)
- ast_el_initialize();
- if (strlen(buf) > 256)
- return 0;
- return (history(el_hist, &ev, H_ENTER, buf));
-}
-
-static int ast_el_write_history(char *filename)
-{
- HistEvent ev;
-
- if (el_hist == NULL || el == NULL)
- ast_el_initialize();
-
- return (history(el_hist, &ev, H_SAVE, filename));
-}
-
-static int ast_el_read_history(char *filename)
-{
- char buf[256];
- FILE *f;
- int ret = -1;
-
- if (el_hist == NULL || el == NULL)
- ast_el_initialize();
-
- if ((f = fopen(filename, "r")) == NULL)
- return ret;
-
- while (!feof(f)) {
- fgets(buf, sizeof(buf), f);
- if (!strcmp(buf, "_HiStOrY_V2_\n"))
- continue;
- if (ast_all_zeros(buf))
- continue;
- if ((ret = ast_el_add_history(buf)) == -1)
- break;
- }
- fclose(f);
-
- return ret;
-}
-
-static void ast_remotecontrol(char * data)
-{
- char buf[80];
- int res;
- char filename[80] = "";
- char *hostname;
- char *cpid;
- char *version;
- int pid;
- char tmp[80];
- char *stringp=NULL;
-
- char *ebuf;
- int num = 0;
-
- read(ast_consock, buf, sizeof(buf));
- if (data)
- write(ast_consock, data, strlen(data) + 1);
- stringp=buf;
- hostname = strsep(&stringp, "/");
- cpid = strsep(&stringp, "/");
- version = strsep(&stringp, "\n");
- if (!version)
- version = "<Version Unknown>";
- stringp=hostname;
- strsep(&stringp, ".");
- if (cpid)
- pid = atoi(cpid);
- else
- pid = -1;
- snprintf(tmp, sizeof(tmp), "set verbose atleast %d", option_verbose);
- fdprint(ast_consock, tmp);
- snprintf(tmp, sizeof(tmp), "set debug atleast %d", option_debug);
- fdprint(ast_consock, tmp);
- ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid);
- remotehostname = hostname;
- if (getenv("HOME"))
- snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
- if (el_hist == NULL || el == NULL)
- ast_el_initialize();
-
- el_set(el, EL_GETCFN, ast_el_read_char);
-
- if (!ast_strlen_zero(filename))
- ast_el_read_history(filename);
-
- if (option_exec && data) { /* hack to print output then exit if asterisk -rx is used */
- char tempchar;
- struct pollfd fds[0];
- fds[0].fd = ast_consock;
- fds[0].events = POLLIN;
- fds[0].revents = 0;
- while(poll(fds, 1, 100) > 0) {
- ast_el_read_char(el, &tempchar);
- }
- return;
- }
- for(;;) {
- ebuf = (char *)el_gets(el, &num);
-
- if (!ast_strlen_zero(ebuf)) {
- if (ebuf[strlen(ebuf)-1] == '\n')
- ebuf[strlen(ebuf)-1] = '\0';
- if (!remoteconsolehandler(ebuf)) {
- res = write(ast_consock, ebuf, strlen(ebuf) + 1);
- if (res < 1) {
- ast_log(LOG_WARNING, "Unable to write: %s\n", strerror(errno));
- break;
- }
- }
- }
- }
- printf("\nDisconnected from Asterisk server\n");
-}
-
-static int show_version(void)
-{
- printf("Asterisk " ASTERISK_VERSION "\n");
- return 0;
-}
-
-static int show_cli_help(void) {
- printf("Asterisk " ASTERISK_VERSION ", Copyright (C) 1999 - 2005, Digium, Inc. and others.\n");
- printf("Usage: asterisk [OPTIONS]\n");
- printf("Valid Options:\n");
- printf(" -V Display version number and exit\n");
- printf(" -C <configfile> Use an alternate configuration file\n");
- printf(" -G <group> Run as a group other than the caller\n");
- printf(" -U <user> Run as a user other than the caller\n");
- printf(" -c Provide console CLI\n");
- printf(" -d Enable extra debugging\n");
- printf(" -f Do not fork\n");
- printf(" -g Dump core in case of a crash\n");
- printf(" -h This help screen\n");
- printf(" -i Initialize crypto keys at startup\n");
- printf(" -n Disable console colorization\n");
- printf(" -p Run as pseudo-realtime thread\n");
- printf(" -q Quiet mode (suppress output)\n");
- printf(" -r Connect to Asterisk on this machine\n");
- printf(" -R Connect to Asterisk, and attempt to reconnect if disconnected\n");
- printf(" -t Record soundfiles in /var/tmp and move them where they belong after they are done.\n");
- printf(" -T Display the time in [Mmm dd hh:mm:ss] format for each line of output to the CLI.\n");
- printf(" -v Increase verbosity (multiple v's = more verbose)\n");
- printf(" -x <cmd> Execute command <cmd> (only valid with -r)\n");
- printf("\n");
- return 0;
-}
-
-static void ast_readconfig(void) {
- struct ast_config *cfg;
- struct ast_variable *v;
- char *config = AST_CONFIG_FILE;
-
- if (option_overrideconfig == 1) {
- cfg = ast_config_load(ast_config_AST_CONFIG_FILE);
- if (!cfg)
- ast_log(LOG_WARNING, "Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE);
- } else {
- cfg = ast_config_load(config);
- }
-
- /* init with buildtime config */
- ast_copy_string(ast_config_AST_CONFIG_DIR, AST_CONFIG_DIR, sizeof(ast_config_AST_CONFIG_DIR));
- ast_copy_string(ast_config_AST_SPOOL_DIR, AST_SPOOL_DIR, sizeof(ast_config_AST_SPOOL_DIR));
- ast_copy_string(ast_config_AST_MODULE_DIR, AST_MODULE_DIR, sizeof(ast_config_AST_VAR_DIR));
- snprintf(ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", ast_config_AST_SPOOL_DIR);
- ast_copy_string(ast_config_AST_VAR_DIR, AST_VAR_DIR, sizeof(ast_config_AST_VAR_DIR));
- ast_copy_string(ast_config_AST_LOG_DIR, AST_LOG_DIR, sizeof(ast_config_AST_LOG_DIR));
- ast_copy_string(ast_config_AST_AGI_DIR, AST_AGI_DIR, sizeof(ast_config_AST_AGI_DIR));
- ast_copy_string(ast_config_AST_DB, AST_DB, sizeof(ast_config_AST_DB));
- ast_copy_string(ast_config_AST_KEY_DIR, AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR));
- ast_copy_string(ast_config_AST_PID, AST_PID, sizeof(ast_config_AST_PID));
- ast_copy_string(ast_config_AST_SOCKET, AST_SOCKET, sizeof(ast_config_AST_SOCKET));
- ast_copy_string(ast_config_AST_RUN_DIR, AST_RUN_DIR, sizeof(ast_config_AST_RUN_DIR));
-
- /* no asterisk.conf? no problem, use buildtime config! */
- if (!cfg) {
- return;
- }
- v = ast_variable_browse(cfg, "files");
- while (v) {
- if (!strcasecmp(v->name, "astctlpermissions")) {
- ast_copy_string(ast_config_AST_CTL_PERMISSIONS, v->value, sizeof(ast_config_AST_CTL_PERMISSIONS));
- } else if (!strcasecmp(v->name, "astctlowner")) {
- ast_copy_string(ast_config_AST_CTL_OWNER, v->value, sizeof(ast_config_AST_CTL_OWNER));
- } else if (!strcasecmp(v->name, "astctlgroup")) {
- ast_copy_string(ast_config_AST_CTL_GROUP, v->value, sizeof(ast_config_AST_CTL_GROUP));
- } else if (!strcasecmp(v->name, "astctl")) {
- ast_copy_string(ast_config_AST_CTL, v->value, sizeof(ast_config_AST_CTL));
- }
- v = v->next;
- }
- v = ast_variable_browse(cfg, "directories");
- while(v) {
- if (!strcasecmp(v->name, "astetcdir")) {
- ast_copy_string(ast_config_AST_CONFIG_DIR, v->value, sizeof(ast_config_AST_CONFIG_DIR));
- } else if (!strcasecmp(v->name, "astspooldir")) {
- ast_copy_string(ast_config_AST_SPOOL_DIR, v->value, sizeof(ast_config_AST_SPOOL_DIR));
- snprintf(ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", v->value);
- } else if (!strcasecmp(v->name, "astvarlibdir")) {
- ast_copy_string(ast_config_AST_VAR_DIR, v->value, sizeof(ast_config_AST_VAR_DIR));
- snprintf(ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
- snprintf(ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
- } else if (!strcasecmp(v->name, "astlogdir")) {
- ast_copy_string(ast_config_AST_LOG_DIR, v->value, sizeof(ast_config_AST_LOG_DIR));
- } else if (!strcasecmp(v->name, "astagidir")) {
- ast_copy_string(ast_config_AST_AGI_DIR, v->value, sizeof(ast_config_AST_AGI_DIR));
- } else if (!strcasecmp(v->name, "astrundir")) {
- snprintf(ast_config_AST_PID, sizeof(ast_config_AST_PID), "%s/%s", v->value, "asterisk.pid");
- snprintf(ast_config_AST_SOCKET, sizeof(ast_config_AST_SOCKET), "%s/%s", v->value, ast_config_AST_CTL);
- ast_copy_string(ast_config_AST_RUN_DIR, v->value, sizeof(ast_config_AST_RUN_DIR));
- } else if (!strcasecmp(v->name, "astmoddir")) {
- ast_copy_string(ast_config_AST_MODULE_DIR, v->value, sizeof(ast_config_AST_MODULE_DIR));
- }
- v = v->next;
- }
- v = ast_variable_browse(cfg, "options");
- while(v) {
- /* verbose level (-v at startup) */
- if (!strcasecmp(v->name, "verbose")) {
- option_verbose = atoi(v->value);
- /* whether or not to force timestamping. (-T at startup) */
- } else if (!strcasecmp(v->name, "timestamp")) {
- option_timestamp = ast_true(v->value);
- /* whether or not to support #exec in config files */
- } else if (!strcasecmp(v->name, "execincludes")) {
- option_exec_includes = ast_true(v->value);
- /* debug level (-d at startup) */
- } else if (!strcasecmp(v->name, "debug")) {
- option_debug = 0;
- if (sscanf(v->value, "%d", &option_debug) != 1) {
- option_debug = ast_true(v->value);
- }
- /* Disable forking (-f at startup) */
- } else if (!strcasecmp(v->name, "nofork")) {
- option_nofork = ast_true(v->value);
- /* Run quietly (-q at startup ) */
- } else if (!strcasecmp(v->name, "quiet")) {
- option_quiet = ast_true(v->value);
- /* Run as console (-c at startup, implies nofork) */
- } else if (!strcasecmp(v->name, "console")) {
- option_console = ast_true(v->value);
- /* Run with highg priority if the O/S permits (-p at startup) */
- } else if (!strcasecmp(v->name, "highpriority")) {
- option_highpriority = ast_true(v->value);
- /* Initialize RSA auth keys (IAX2) (-i at startup) */
- } else if (!strcasecmp(v->name, "initcrypto")) {
- option_initcrypto = ast_true(v->value);
- /* Disable ANSI colors for console (-c at startup) */
- } else if (!strcasecmp(v->name, "nocolor")) {
- option_nocolor = ast_true(v->value);
- /* Disable some usage warnings for picky people :p */
- } else if (!strcasecmp(v->name, "dontwarn")) {
- option_dontwarn = ast_true(v->value);
- /* Dump core in case of crash (-g) */
- } else if (!strcasecmp(v->name, "dumpcore")) {
- option_dumpcore = ast_true(v->value);
- /* Cache recorded sound files to another directory during recording */
- } else if (!strcasecmp(v->name, "cache_record_files")) {
- option_cache_record_files = ast_true(v->value);
- /* Specify cache directory */
- } else if (!strcasecmp(v->name, "record_cache_dir")) {
- ast_copy_string(record_cache_dir, v->value, AST_CACHE_DIR_LEN);
- /* Build transcode paths via SLINEAR, instead of directly */
- } else if (!strcasecmp(v->name, "transcode_via_sln")) {
- option_transcode_slin = ast_true(v->value);
- /* Transmit SLINEAR silence while a channel is being recorded */
- } else if (!strcasecmp(v->name, "transmit_silence_during_record")) {
- option_transmit_silence_during_record = ast_true(v->value);
- } else if (!strcasecmp(v->name, "maxcalls")) {
- if ((sscanf(v->value, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0)) {
- option_maxcalls = 0;
- }
- } else if (!strcasecmp(v->name, "maxload")) {
- double test[1];
-
- if (getloadavg(test, 1) == -1) {
- ast_log(LOG_ERROR, "Cannot obtain load average on this system. 'maxload' option disabled.\n");
- option_maxload = 0.0;
- } else if ((sscanf(v->value, "%lf", &option_maxload) != 1) || (option_maxload < 0.0)) {
- option_maxload = 0.0;
- }
- /* What user to run as */
- } else if (!strcasecmp(v->name, "runuser")) {
- ast_copy_string(ast_config_AST_RUN_USER, v->value, sizeof(ast_config_AST_RUN_USER));
- /* What group to run as */
- } else if (!strcasecmp(v->name, "rungroup")) {
- ast_copy_string(ast_config_AST_RUN_GROUP, v->value, sizeof(ast_config_AST_RUN_GROUP));
- }
- v = v->next;
- }
- ast_config_destroy(cfg);
-}
-
-int main(int argc, char *argv[])
-{
- int c;
- char filename[80] = "";
- char hostname[MAXHOSTNAMELEN]="";
- char tmp[80];
- char * xarg = NULL;
- int x;
- FILE *f;
- sigset_t sigs;
- int num;
- int is_child_of_nonroot=0;
- char *buf;
- char *runuser=NULL, *rungroup=NULL;
-
- /* Remember original args for restart */
- if (argc > sizeof(_argv) / sizeof(_argv[0]) - 1) {
- fprintf(stderr, "Truncating argument size to %d\n", (int)(sizeof(_argv) / sizeof(_argv[0])) - 1);
- argc = sizeof(_argv) / sizeof(_argv[0]) - 1;
- }
- for (x=0;x<argc;x++)
- _argv[x] = argv[x];
- _argv[x] = NULL;
-
- /* if the progname is rasterisk consider it a remote console */
- if (argv[0] && (strstr(argv[0], "rasterisk")) != NULL) {
- option_remote++;
- option_nofork++;
- }
- if (gethostname(hostname, sizeof(hostname)-1))
- ast_copy_string(hostname, "<Unknown>", sizeof(hostname));
- ast_mainpid = getpid();
- ast_ulaw_init();
- ast_alaw_init();
- callerid_init();
- ast_utils_init();
- tdd_init();
- /* When Asterisk restarts after it has dropped the root privileges,
- * it can't issue setuid(), setgid(), setgroups() or set_priority()
- * */
- if (getenv("ASTERISK_ALREADY_NONROOT"))
- is_child_of_nonroot=1;
- if (getenv("HOME"))
- snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
- /* Check if we're root */
- /*
- if (geteuid()) {
- ast_log(LOG_ERROR, "Must be run as root\n");
- exit(1);
- }
- */
- /* Check for options */
- while((c=getopt(argc, argv, "tThfdvVqprRgcinx:U:G:C:L:M:")) != -1) {
- switch(c) {
- case 'd':
- option_debug++;
- option_nofork++;
- break;
- case 'c':
- option_console++;
- option_nofork++;
- break;
- case 'f':
- option_nofork++;
- break;
- case 'n':
- option_nocolor++;
- break;
- case 'r':
- option_remote++;
- option_nofork++;
- break;
- case 'R':
- option_remote++;
- option_nofork++;
- option_reconnect++;
- break;
- case 'p':
- option_highpriority++;
- break;
- case 'v':
- option_verbose++;
- option_nofork++;
- break;
- case 'M':
- if ((sscanf(optarg, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0))
- option_maxcalls = 0;
- break;
- case 'L':
- if ((sscanf(optarg, "%lf", &option_maxload) != 1) || (option_maxload < 0.0))
- option_maxload = 0.0;
- break;
- case 'q':
- option_quiet++;
- break;
- case 't':
- option_cache_record_files++;
- break;
- case 'T':
- option_timestamp++;
- break;
- case 'x':
- option_exec++;
- xarg = optarg;
- break;
- case 'C':
- ast_copy_string((char *)ast_config_AST_CONFIG_FILE,optarg,sizeof(ast_config_AST_CONFIG_FILE));
- option_overrideconfig++;
- break;
- case 'i':
- option_initcrypto++;
- break;
- case'g':
- option_dumpcore++;
- break;
- case 'h':
- show_cli_help();
- exit(0);
- case 'V':
- show_version();
- exit(0);
- case 'U':
- runuser = optarg;
- break;
- case 'G':
- rungroup = optarg;
- break;
- case '?':
- exit(1);
- }
- }
-
- /* For remote connections, change the name of the remote connection.
- * We do this for the benefit of init scripts (which need to know if/when
- * the main asterisk process has died yet). */
- if (option_remote) {
- strcpy(argv[0], "rasterisk");
- for (x = 1; x < argc; x++) {
- argv[x] = argv[0] + 10;
- }
- }
-
- if (option_console && !option_verbose)
- ast_verbose("[ Reading Master Configuration ]");
- ast_readconfig();
-
- if (option_dumpcore) {
- struct rlimit l;
- memset(&l, 0, sizeof(l));
- l.rlim_cur = RLIM_INFINITY;
- l.rlim_max = RLIM_INFINITY;
- if (setrlimit(RLIMIT_CORE, &l)) {
- ast_log(LOG_WARNING, "Unable to disable core size resource limit: %s\n", strerror(errno));
- }
- }
-
- if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP))
- rungroup = ast_config_AST_RUN_GROUP;
- if ((!runuser) && !ast_strlen_zero(ast_config_AST_RUN_USER))
- runuser = ast_config_AST_RUN_USER;
-#ifndef __CYGWIN__
-
- if (!is_child_of_nonroot)
- ast_set_priority(option_highpriority);
-
- if (!is_child_of_nonroot && rungroup) {
- struct group *gr;
- gr = getgrnam(rungroup);
- if (!gr) {
- ast_log(LOG_WARNING, "No such group '%s'!\n", rungroup);
- exit(1);
- }
- if (setgid(gr->gr_gid)) {
- ast_log(LOG_WARNING, "Unable to setgid to %d (%s)\n", (int)gr->gr_gid, rungroup);
- exit(1);
- }
- if (setgroups(0, NULL)) {
- ast_log(LOG_WARNING, "Unable to drop unneeded groups\n");
- exit(1);
- }
- if (option_verbose)
- ast_verbose("Running as group '%s'\n", rungroup);
- }
-
- if (!is_child_of_nonroot && runuser) {
- struct passwd *pw;
- pw = getpwnam(runuser);
- if (!pw) {
- ast_log(LOG_WARNING, "No such user '%s'!\n", runuser);
- exit(1);
- }
- if (!rungroup) {
- if (setgid(pw->pw_gid)) {
- ast_log(LOG_WARNING, "Unable to setgid to %d!\n", (int)pw->pw_gid);
- exit(1);
- }
- if (initgroups(pw->pw_name, pw->pw_gid)) {
- ast_log(LOG_WARNING, "Unable to init groups for '%s'\n", runuser);
- exit(1);
- }
- }
- if (setuid(pw->pw_uid)) {
- ast_log(LOG_WARNING, "Unable to setuid to %d (%s)\n", (int)pw->pw_uid, runuser);
- exit(1);
- }
- setenv("ASTERISK_ALREADY_NONROOT","yes",1);
- if (option_verbose)
- ast_verbose("Running as user '%s'\n", runuser);
- }
-
-#endif /* __CYGWIN__ */
-
-#ifdef linux
-
- if (geteuid() && option_dumpcore) {
- if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0) {
- ast_log(LOG_WARNING, "Unable to set the process for core dumps after changing to a non-root user. %s\n", strerror(errno));
- }
- }
-
-#endif
-
- term_init();
- printf(term_end());
- fflush(stdout);
-
- if (option_console && !option_verbose)
- ast_verbose("[ Initializing Custom Configuration Options ]");
- /* custom config setup */
- register_config_cli();
- read_config_maps();
-
-
- if (option_console) {
- if (el_hist == NULL || el == NULL)
- ast_el_initialize();
-
- if (!ast_strlen_zero(filename))
- ast_el_read_history(filename);
- }
-
- if (ast_tryconnect()) {
- /* One is already running */
- if (option_remote) {
- if (option_exec) {
- ast_remotecontrol(xarg);
- quit_handler(0, 0, 0, 0);
- exit(0);
- }
- printf(term_quit());
- ast_register_verbose(console_verboser);
- WELCOME_MESSAGE;
- ast_remotecontrol(NULL);
- quit_handler(0, 0, 0, 0);
- exit(0);
- } else {
- ast_log(LOG_ERROR, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", (char *)ast_config_AST_SOCKET);
- printf(term_quit());
- exit(1);
- }
- } else if (option_remote || option_exec) {
- ast_log(LOG_ERROR, "Unable to connect to remote asterisk (does %s exist?)\n",ast_config_AST_SOCKET);
- printf(term_quit());
- exit(1);
- }
- /* Blindly write pid file since we couldn't connect */
- unlink((char *)ast_config_AST_PID);
- f = fopen((char *)ast_config_AST_PID, "w");
- if (f) {
- fprintf(f, "%d\n", (int)getpid());
- fclose(f);
- } else
- ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno));
-
- if (!option_verbose && !option_debug && !option_nofork && !option_console) {
- daemon(0,0);
- /* Blindly re-write pid file since we are forking */
- unlink((char *)ast_config_AST_PID);
- f = fopen((char *)ast_config_AST_PID, "w");
- if (f) {
- fprintf(f, "%d\n", (int)getpid());
- fclose(f);
- } else
- ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno));
- }
-
- /* Test recursive mutex locking. */
- if (test_for_thread_safety())
- ast_verbose("Warning! Asterisk is not thread safe.\n");
-
- ast_makesocket();
- sigemptyset(&sigs);
- sigaddset(&sigs, SIGHUP);
- sigaddset(&sigs, SIGTERM);
- sigaddset(&sigs, SIGINT);
- sigaddset(&sigs, SIGPIPE);
- sigaddset(&sigs, SIGWINCH);
- pthread_sigmask(SIG_BLOCK, &sigs, NULL);
- if (option_console || option_verbose || option_remote)
- ast_register_verbose(console_verboser);
- /* Print a welcome message if desired */
- if (option_verbose || option_console) {
- WELCOME_MESSAGE;
- }
- if (option_console && !option_verbose)
- ast_verbose("[ Booting...");
-
- signal(SIGURG, urg_handler);
- signal(SIGINT, __quit_handler);
- signal(SIGTERM, __quit_handler);
- signal(SIGHUP, hup_handler);
- signal(SIGCHLD, child_handler);
- signal(SIGPIPE, SIG_IGN);
-
- /* ensure that the random number generators are seeded with a different value every time
- Asterisk is started
- */
- srand((unsigned int) getpid() + (unsigned int) time(NULL));
- srandom((unsigned int) getpid() + (unsigned int) time(NULL));
-
- if (init_logger()) {
- printf(term_quit());
- exit(1);
- }
- if (dnsmgr_init()) {
- printf(term_quit());
- exit(1);
- }
- /* load 'preload' modules, required for access to Realtime-mapped configuration files */
- if (load_modules(1)) {
- printf(term_quit());
- exit(1);
- }
- ast_channels_init();
- if (init_manager()) {
- printf(term_quit());
- exit(1);
- }
- if (ast_cdr_engine_init()) {
- printf(term_quit());
- exit(1);
- }
- if (ast_device_state_engine_init()) {
- printf(term_quit());
- exit(1);
- }
- ast_rtp_init();
- if (ast_image_init()) {
- printf(term_quit());
- exit(1);
- }
- if (ast_file_init()) {
- printf(term_quit());
- exit(1);
- }
- if (load_pbx()) {
- printf(term_quit());
- exit(1);
- }
- if (load_modules(0)) {
- printf(term_quit());
- exit(1);
- }
- if (init_framer()) {
- printf(term_quit());
- exit(1);
- }
- if (astdb_init()) {
- printf(term_quit());
- exit(1);
- }
- if (ast_enum_init()) {
- printf(term_quit());
- exit(1);
- }
-
- dnsmgr_start_refresh();
-
-#if 0
- /* This should no longer be necessary */
- /* sync cust config and reload some internals in case a custom config handler binded to them */
- read_ast_cust_config();
- reload_logger(0);
- reload_manager();
- ast_enum_reload();
- ast_rtp_reload();
-#endif
-
-
- /* We might have the option of showing a console, but for now just
- do nothing... */
- if (option_console && !option_verbose)
- ast_verbose(" ]\n");
- if (option_verbose || option_console)
- ast_verbose(term_color(tmp, "Asterisk Ready.\n", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp)));
- if (option_nofork)
- consolethread = pthread_self();
- fully_booted = 1;
- pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
-#ifdef __AST_DEBUG_MALLOC
- __ast_mm_init();
-#endif
- time(&ast_startuptime);
- ast_cli_register_multiple(core_cli, sizeof(core_cli) / sizeof(core_cli[0]));
- if (option_console) {
- /* Console stuff now... */
- /* Register our quit function */
- char title[256];
- set_icon("Asterisk");
- snprintf(title, sizeof(title), "Asterisk Console on '%s' (pid %d)", hostname, ast_mainpid);
- set_title(title);
-
- for (;;) {
- buf = (char *)el_gets(el, &num);
- if (buf) {
- if (buf[strlen(buf)-1] == '\n')
- buf[strlen(buf)-1] = '\0';
-
- consolehandler((char *)buf);
- } else {
- if (write(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n",
- strlen("\nUse EXIT or QUIT to exit the asterisk console\n")) < 0) {
- /* Whoa, stdout disappeared from under us... Make /dev/null's */
- int fd;
- fd = open("/dev/null", O_RDWR);
- if (fd > -1) {
- dup2(fd, STDOUT_FILENO);
- dup2(fd, STDIN_FILENO);
- } else
- ast_log(LOG_WARNING, "Failed to open /dev/null to recover from dead console. Bad things will happen!\n");
- break;
- }
- }
- }
-
- }
- /* Do nothing */
- for(;;) { /* apparently needed for the MACos */
- struct pollfd p = { -1 /* no descriptor */, 0, 0 };
- poll(&p, 0, -1);
- }
- return 0;
-}
diff --git a/1.2-netsec/asterisk.sgml b/1.2-netsec/asterisk.sgml
deleted file mode 100644
index 663a816be..000000000
--- a/1.2-netsec/asterisk.sgml
+++ /dev/null
@@ -1,353 +0,0 @@
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
-<refentry>
-<refentryinfo>
- <date>2005-10-18</date>
-</refentryinfo>
-<refmeta>
- <refentrytitle>
- <application>asterisk</application>
- </refentrytitle>
- <manvolnum>8</manvolnum>
- <refmiscinfo>asterisk 1.2</refmiscinfo>
-</refmeta>
-<refnamediv>
- <refname>
- <application>asterisk</application>
- </refname>
- <refpurpose>
- All-purpose telephony server.
- </refpurpose>
-</refnamediv>
-<refsynopsisdiv>
- <cmdsynopsis>
- <command>asterisk</command>
-<arg><option>-tThfdvVqpRgcin</option></arg>
-<arg><option>-C </option><replaceable class="parameter">file</replaceable></arg>
-<arg><option>-U </option><replaceable class="parameter">user</replaceable></arg>
-<arg><option>-G </option><replaceable class="parameter">group</replaceable></arg>
-<arg><option>-x </option><replaceable class="parameter">command</replaceable></arg>
-<arg><option>-M </option><replaceable class="parameter">value</replaceable></arg>
-<arg><option>-L </option><replaceable class="parameter">loadaverage</replaceable></arg>
- </cmdsynopsis>
- <cmdsynopsis>
-
- <command>asterisk -r</command>
- <arg><option>-v</option></arg>
-<arg><option>-x </option><replaceable class="parameter">command</replaceable></arg>
- </cmdsynopsis>
-</refsynopsisdiv>
-<refsect1>
- <refsect1info>
- <date>2004-07-01</date>
- </refsect1info>
- <title>DESCRIPTION</title>
- <para>
- <command>asterisk</command> is a full-featured telephony server which
- provides Private Branch eXchange (PBX), Interactive Voice Response (IVR),
- Automated Call Distribution (ACD), Voice over IP (VoIP) gatewaying,
- Conferencing, and a plethora of other telephony applications to a broad
- range of telephony devices including packet voice (SIP, IAX2, MGCP, Skinny,
- H.323) devices (both endpoints and proxies), as well as traditional TDM
- hardware including T1, E1, ISDN PRI, GR-303, RBS, Loopstart, Groundstart,
- ISDN BRI, and many more.
- </para>
- <para>
- At start, Asterisk reads the /etc/asterisk/asterisk.conf main configuration
- file and locates the rest of the configuration files from the configuration
- in that file. The -C option specifies an alternate main configuration file.
- Virtually all aspects of the operation of asterisk's configuration files
- can be found in the sample configuration files. The format for those files
- is generally beyond the scope of this man page.
- </para>
- <para>
- When running with <command>-c</command>, <command>-r</command> or <command>-R</command>
- options, Asterisk supplies a powerful command line, including command
- completion, which may be used to monitors its status, perform a variety
- of administrative actions and even explore the applications that are
- currently loaded into the system.
- </para>
- <para>
- Asterisk is a trademark of Digium, Inc.
- </para>
-</refsect1>
-<refsect1>
- <title>OPTIONS</title>
- <variablelist>
- <varlistentry>
- <term>-C <replaceable class="parameter">file</replaceable></term>
- <listitem>
- <para>
- Use <filename>file</filename> as master configuration file
- instead of the default, /etc/asterisk/asterisk.conf
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-c</term>
- <listitem>
- <para>
- Provide a control console on the calling terminal.
- Specifying this option implies <command>-f</command> and will cause
- asterisk to no longer fork or detach from the controlling terminal.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-d</term>
- <listitem>
- <para>
- Enable extra debugging statements.
- </para>
- <para>
- Note: This always sets the debug level in the asterisk process,
- even if it is running in the background. This will affect the size
- of your log files.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-f</term>
- <listitem>
- <para>
- Do not fork or detach from controlling terminal.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-g</term>
- <listitem>
- <para>
- Remove resource limit on core size, thus forcing Asterisk to dump
- core in the unlikely event of a segmentation fault or abort signal.
- <command>NOTE:</command> in some cases this may be incompatible
- with the <command>-U</command> or <command>-G</command> flags.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-G <replaceable class="parameter">group</replaceable></term>
- <listitem>
- <para>
- Run as group <replaceable>group</replaceable> instead of the
- calling group. <command>NOTE:</command> this requires substantial work
- to be sure that Asterisk's environment has permission to write
- the files required for its operation, including logs, its comm
- socket, the asterisk database, etc.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-h</term>
- <listitem>
- <para>
- Provide brief summary of command line arguments and terminate.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-i</term>
- <listitem>
- <para>
- Prompt user to intialize any encrypted private keys for IAX2
- secure authentication during startup.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-L <replaceable class="parameter">loadaverage</replaceable></term>
- <listitem>
- <para>
- Limits the maximum load average before rejecting new calls. This can
- be useful to prevent a system from being brought down by terminating
- too many simultaneous calls.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-M <replaceable class="parameter">value</replaceable></term>
- <listitem>
- <para>
- Limits the maximum number of calls to the specified value. This can
- be useful to prevent a system from being brought down by terminating
- too many simultaneous calls.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-n</term>
- <listitem>
- <para>
- Disable ANSI colors even on terminals capable of displaying them.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-p</term>
- <listitem>
- <para>
- If supported by the operating system (and executing as root),
- attempt to run with realtime priority for increased performance and
- responsiveness within the Asterisk process, at the expense of other
- programs running on the same machine.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-q</term>
- <listitem>
- <para>
- Reduce default console output when running in conjunction with
- console mode (<command>-c</command>).
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-r</term>
- <listitem>
- <para>
- Instead of running a new Asterisk process, attempt to connect
- to a running Asterisk process and provide a console interface
- for controlling it.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-R</term>
- <listitem>
- <para>
- Much like <command>-r</command>. Instead of running a new Asterisk process, attempt to connect
- to a running Asterisk process and provide a console interface
- for controlling it. Additionally, if connection to the Asterisk
- process is lost, attempt to reconnect for as long as 30 seconds.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-t</term>
- <listitem>
- <para>
- When recording files, write them first into a temporary holding directory,
- then move them into the final location when done.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-T</term>
- <listitem>
- <para>
- Add timestamp to all non-command related output going to the console
- when running with verbose and/or logging to the console.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-U <replaceable class="parameter">user</replaceable></term>
- <listitem>
- <para>
- Run as user <replaceable>user</replaceable> instead of the
- calling user. <command>NOTE:</command> this requires substantial work
- to be sure that Asterisk's environment has permission to write
- the files required for its operation, including logs, its comm
- socket, the asterisk database, etc.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-v</term>
- <listitem>
- <para>
- Increase the level of verboseness on the console. The more times
- <command>-v</command> is specified, the more verbose the output is.
- Specifying this option implies <command>-f</command> and will cause
- asterisk to no longer fork or detach from the controlling terminal.
- This option may also be used in conjunction with <command>-r</command>
- and <command>-R</command>.
- </para>
- <para>
- Note: This always sets the verbose level in the asterisk process,
- even if it is running in the background. This will affect the size
- of your log files.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-V</term>
- <listitem>
- <para>
- Display version information and exit immediately.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>-x <replaceable class="parameter">command</replaceable></term>
- <listitem>
- <para>
- Connect to a running Asterisk process and execute a command on
- a command line, passing any output through to standard out and
- then terminating when the command execution completes. Implies
- <command>-r</command> when <command>-R</command> is not explicitly
- supplied.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
-</refsect1>
-<refsect1>
- <title>EXAMPLES</title>
- <para>
- <command>asterisk</command> - Begin Asterisk as a daemon
- </para>
- <para>
- <command>asterisk -vvvgc</command> - Run on controlling terminal
- </para>
- <para>
- <command>asterisk -rx "show channels"</command> - Display channels on running server
- </para>
-</refsect1>
-<refsect1>
- <title>BUGS</title>
- <para>
- Bug reports and feature requests may be filed at http://bugs.digium.com
- </para>
-</refsect1>
-<refsect1>
- <title>SEE ALSO</title>
- <para>
- *CLI&gt; <command>help</command> - Help on Asterisk CLI
- </para>
- <para>
- *CLI&gt; <command>show applications</command> - Show loaded dialplan applications
- </para>
- <para>
- *CLI&gt; <command>show functions</command> - Show loaded dialplan functions
- </para>
- <para>
- http://www.asterisk.org - The Asterisk Home Page
- </para>
- <para>
- http://www.asteriskdocs.org - The Asterisk Documentation Project
- </para>
- <para>
- http://www.voip-info.org/wiki-Asterisk - The Asterisk Wiki
- </para>
- <para>
- http://www.digium.com/ - Asterisk sponsor and hardware supplier
- </para>
- <para>
- http://www.markocam.com/ - Asterisk author's web cam
- </para>
-</refsect1>
-<refsect1>
- <title>AUTHOR</title>
- <para>
- <author>
- <firstname>Mark Spencer &lt;markster@digium.com&gt;</firstname>
- </author>
- </para>
- <para>
- <author>
- <firstname>Countless other contributers, see CREDITS with distribution for more information</firstname>
- </author>
- </para>
-</refsect1>
-</refentry>
diff --git a/1.2-netsec/astmm.c b/1.2-netsec/astmm.c
deleted file mode 100644
index 3f94e05fa..000000000
--- a/1.2-netsec/astmm.c
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Memory Management
- *
- */
-
-#ifdef __AST_DEBUG_MALLOC
-
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/cli.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
-#include "asterisk/strings.h"
-
-#define SOME_PRIME 563
-
-#define FUNC_CALLOC 1
-#define FUNC_MALLOC 2
-#define FUNC_REALLOC 3
-#define FUNC_STRDUP 4
-#define FUNC_STRNDUP 5
-#define FUNC_VASPRINTF 6
-
-/* Undefine all our macros */
-#undef malloc
-#undef calloc
-#undef realloc
-#undef strdup
-#undef strndup
-#undef free
-#undef vasprintf
-
-#define FENCE_MAGIC 0xdeadbeef
-
-static FILE *mmlog;
-
-static struct ast_region {
- struct ast_region *next;
- char file[40];
- char func[40];
- int lineno;
- int which;
- size_t len;
- unsigned int fence;
- unsigned char data[0];
-} *regions[SOME_PRIME];
-
-#define HASH(a) \
- (((unsigned long)(a)) % SOME_PRIME)
-
-AST_MUTEX_DEFINE_STATIC(reglock);
-AST_MUTEX_DEFINE_STATIC(showmemorylock);
-
-static inline void *__ast_alloc_region(size_t size, int which, const char *file, int lineno, const char *func)
-{
- struct ast_region *reg;
- void *ptr = NULL;
- unsigned int *fence;
- int hash;
- reg = malloc(size + sizeof(struct ast_region) + sizeof(unsigned int));
- ast_mutex_lock(&reglock);
- if (reg) {
- ast_copy_string(reg->file, file, sizeof(reg->file));
- reg->file[sizeof(reg->file) - 1] = '\0';
- ast_copy_string(reg->func, func, sizeof(reg->func));
- reg->func[sizeof(reg->func) - 1] = '\0';
- reg->lineno = lineno;
- reg->len = size;
- reg->which = which;
- ptr = reg->data;
- hash = HASH(ptr);
- reg->next = regions[hash];
- regions[hash] = reg;
- reg->fence = FENCE_MAGIC;
- fence = (ptr + reg->len);
- *fence = FENCE_MAGIC;
- }
- ast_mutex_unlock(&reglock);
- if (!reg) {
- fprintf(stderr, "Out of memory :(\n");
- if (mmlog) {
- fprintf(mmlog, "%ld - Out of memory\n", time(NULL));
- fflush(mmlog);
- }
- }
- return ptr;
-}
-
-static inline size_t __ast_sizeof_region(void *ptr)
-{
- int hash = HASH(ptr);
- struct ast_region *reg;
- size_t len = 0;
-
- ast_mutex_lock(&reglock);
- reg = regions[hash];
- while (reg) {
- if (reg->data == ptr) {
- len = reg->len;
- break;
- }
- reg = reg->next;
- }
- ast_mutex_unlock(&reglock);
- return len;
-}
-
-static void __ast_free_region(void *ptr, const char *file, int lineno, const char *func)
-{
- int hash = HASH(ptr);
- struct ast_region *reg, *prev = NULL;
- unsigned int *fence;
-
- ast_mutex_lock(&reglock);
- reg = regions[hash];
- while (reg) {
- if (reg->data == ptr) {
- if (prev) {
- prev->next = reg->next;
- } else {
- regions[hash] = reg->next;
- }
- break;
- }
- prev = reg;
- reg = reg->next;
- }
- ast_mutex_unlock(&reglock);
- if (reg) {
- fence = (unsigned int *)(reg->data + reg->len);
- if (reg->fence != FENCE_MAGIC) {
- fprintf(stderr, "WARNING: Low fence violation at %p, in %s of %s, line %d\n", reg->data, reg->func, reg->file, reg->lineno);
- if (mmlog) {
- fprintf(mmlog, "%ld - WARNING: Low fence violation at %p, in %s of %s, line %d\n", time(NULL), reg->data, reg->func, reg->file, reg->lineno);
- fflush(mmlog);
- }
- }
- if (*fence != FENCE_MAGIC) {
- fprintf(stderr, "WARNING: High fence violation at %p, in %s of %s, line %d\n", reg->data, reg->func, reg->file, reg->lineno);
- if (mmlog) {
- fprintf(mmlog, "%ld - WARNING: High fence violation at %p, in %s of %s, line %d\n", time(NULL), reg->data, reg->func, reg->file, reg->lineno);
- fflush(mmlog);
- }
- }
- free(reg);
- } else {
- fprintf(stderr, "WARNING: Freeing unused memory at %p, in %s of %s, line %d\n", ptr, func, file, lineno);
- if (mmlog) {
- fprintf(mmlog, "%ld - WARNING: Freeing unused memory at %p, in %s of %s, line %d\n", time(NULL), ptr, func, file, lineno);
- fflush(mmlog);
- }
- }
-}
-
-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
-{
- void *ptr;
- ptr = __ast_alloc_region(size * nmemb, FUNC_CALLOC, file, lineno, func);
- if (ptr)
- memset(ptr, 0, size * nmemb);
- return ptr;
-}
-
-void *__ast_malloc(size_t size, const char *file, int lineno, const char *func)
-{
- return __ast_alloc_region(size, FUNC_MALLOC, file, lineno, func);
-}
-
-void __ast_free(void *ptr, const char *file, int lineno, const char *func)
-{
- __ast_free_region(ptr, file, lineno, func);
-}
-
-void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
-{
- void *tmp;
- size_t len = 0;
- if (ptr) {
- len = __ast_sizeof_region(ptr);
- if (!len) {
- fprintf(stderr, "WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n", ptr, func, file, lineno);
- if (mmlog) {
- fprintf(mmlog, "%ld - WARNING: Realloc of unalloced memory at %p, in %s of %s, line %d\n", time(NULL), ptr, func, file, lineno);
- fflush(mmlog);
- }
- return NULL;
- }
- }
- tmp = __ast_alloc_region(size, FUNC_REALLOC, file, lineno, func);
- if (tmp) {
- if (len > size)
- len = size;
- if (ptr) {
- memcpy(tmp, ptr, len);
- __ast_free_region(ptr, file, lineno, func);
- }
- }
- return tmp;
-}
-
-char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)
-{
- size_t len;
- void *ptr;
- if (!s)
- return NULL;
- len = strlen(s) + 1;
- ptr = __ast_alloc_region(len, FUNC_STRDUP, file, lineno, func);
- if (ptr)
- strcpy(ptr, s);
- return ptr;
-}
-
-char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
-{
- size_t len;
- void *ptr;
- if (!s)
- return NULL;
- len = strlen(s) + 1;
- if (len > n)
- len = n;
- ptr = __ast_alloc_region(len, FUNC_STRNDUP, file, lineno, func);
- if (ptr)
- strcpy(ptr, s);
- return ptr;
-}
-
-int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func)
-{
- int size;
- va_list ap2;
- char s;
-
- *strp = NULL;
- va_copy(ap2, ap);
- size = vsnprintf(&s, 1, fmt, ap2);
- va_end(ap2);
- *strp = __ast_alloc_region(size + 1, FUNC_VASPRINTF, file, lineno, func);
- if (!*strp)
- return -1;
- vsnprintf(*strp, size + 1, fmt, ap);
-
- return size;
-}
-
-static int handle_show_memory(int fd, int argc, char *argv[])
-{
- char *fn = NULL;
- int x;
- struct ast_region *reg;
- unsigned int len = 0;
- int count = 0;
- unsigned int *fence;
- if (argc > 3)
- fn = argv[3];
-
- /* try to lock applications list ... */
- ast_mutex_lock(&showmemorylock);
-
- for (x = 0; x < SOME_PRIME; x++) {
- reg = regions[x];
- while (reg) {
- if (!fn || !strcasecmp(fn, reg->file) || !strcasecmp(fn, "anomolies")) {
- fence = (unsigned int *)(reg->data + reg->len);
- if (reg->fence != FENCE_MAGIC) {
- fprintf(stderr, "WARNING: Low fence violation at %p, in %s of %s, line %d\n", reg->data, reg->func, reg->file, reg->lineno);
- if (mmlog) {
- fprintf(mmlog, "%ld - WARNING: Low fence violation at %p, in %s of %s, line %d\n", time(NULL), reg->data, reg->func, reg-> file, reg->lineno);
- fflush(mmlog);
- }
- }
- if (*fence != FENCE_MAGIC) {
- fprintf(stderr, "WARNING: High fence violation at %p, in %s of %s, line %d\n", reg->data, reg->func, reg->file, reg->lineno);
- if (mmlog) {
- fprintf(mmlog, "%ld - WARNING: High fence violation at %p, in %s of %s, line %d\n", time(NULL), reg->data, reg->func, reg->file, reg->lineno);
- fflush(mmlog);
- }
- }
- }
- if (!fn || !strcasecmp(fn, reg->file)) {
- ast_cli(fd, "%10d bytes allocated in %20s at line %5d of %s\n", (int) reg->len, reg->func, reg->lineno, reg->file);
- len += reg->len;
- count++;
- }
- reg = reg->next;
- }
- }
- ast_cli(fd, "%d bytes allocated %d units total\n", len, count);
- ast_mutex_unlock(&showmemorylock);
- return RESULT_SUCCESS;
-}
-
-struct file_summary {
- char fn[80];
- int len;
- int count;
- struct file_summary *next;
-};
-
-static int handle_show_memory_summary(int fd, int argc, char *argv[])
-{
- char *fn = NULL;
- int x;
- struct ast_region *reg;
- unsigned int len = 0;
- int count = 0;
- struct file_summary *list = NULL, *cur;
-
- if (argc > 3)
- fn = argv[3];
-
- /* try to lock applications list ... */
- ast_mutex_lock(&reglock);
-
- for (x = 0; x < SOME_PRIME; x++) {
- reg = regions[x];
- while (reg) {
- if (!fn || !strcasecmp(fn, reg->file)) {
- cur = list;
- while (cur) {
- if ((!fn && !strcmp(cur->fn, reg->file)) || (fn && !strcmp(cur->fn, reg->func)))
- break;
- cur = cur->next;
- }
- if (!cur) {
- cur = alloca(sizeof(struct file_summary));
- memset(cur, 0, sizeof(struct file_summary));
- ast_copy_string(cur->fn, fn ? reg->func : reg->file, sizeof(cur->fn));
- cur->next = list;
- list = cur;
- }
- cur->len += reg->len;
- cur->count++;
- }
- reg = reg->next;
- }
- }
- ast_mutex_unlock(&reglock);
-
- /* Dump the whole list */
- while (list) {
- cur = list;
- len += list->len;
- count += list->count;
- if (fn) {
- ast_cli(fd, "%10d bytes in %5d allocations in function '%s' of '%s'\n", list->len, list->count, list->fn, fn);
- } else {
- ast_cli(fd, "%10d bytes in %5d allocations in file '%s'\n", list->len, list->count, list->fn);
- }
- list = list->next;
-#if 0
- free(cur);
-#endif
- }
- ast_cli(fd, "%d bytes allocated %d units total\n", len, count);
- return RESULT_SUCCESS;
-}
-
-static char show_memory_help[] =
-"Usage: show memory allocations [<file>]\n"
-" Dumps a list of all segments of allocated memory, optionally\n"
-"limited to those from a specific file\n";
-
-static char show_memory_summary_help[] =
-"Usage: show memory summary [<file>]\n"
-" Summarizes heap memory allocations by file, or optionally\n"
-"by function, if a file is specified\n";
-
-static struct ast_cli_entry show_memory_allocations_cli =
- { { "show", "memory", "allocations", NULL },
- handle_show_memory, "Display outstanding memory allocations",
- show_memory_help };
-
-static struct ast_cli_entry show_memory_summary_cli =
- { { "show", "memory", "summary", NULL },
- handle_show_memory_summary, "Summarize outstanding memory allocations",
- show_memory_summary_help };
-
-void __ast_mm_init(void)
-{
- char filename[80] = "";
- ast_cli_register(&show_memory_allocations_cli);
- ast_cli_register(&show_memory_summary_cli);
-
- snprintf(filename, sizeof(filename), "%s/mmlog", (char *)ast_config_AST_LOG_DIR);
- mmlog = fopen(filename, "a+");
- if (option_verbose)
- ast_verbose("Asterisk Malloc Debugger Started (see %s))\n", filename);
- if (mmlog) {
- fprintf(mmlog, "%ld - New session\n", time(NULL));
- fflush(mmlog);
- }
-}
-
-#endif
diff --git a/1.2-netsec/autoservice.c b/1.2-netsec/autoservice.c
deleted file mode 100644
index d8b5d8e80..000000000
--- a/1.2-netsec/autoservice.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Automatic channel service routines
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <math.h> /* For PI */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/pbx.h"
-#include "asterisk/frame.h"
-#include "asterisk/sched.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/file.h"
-#include "asterisk/translate.h"
-#include "asterisk/manager.h"
-#include "asterisk/chanvars.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/indications.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-
-#define MAX_AUTOMONS 256
-
-AST_MUTEX_DEFINE_STATIC(autolock);
-
-struct asent {
- struct ast_channel *chan;
- struct asent *next;
-};
-
-static struct asent *aslist = NULL;
-static pthread_t asthread = AST_PTHREADT_NULL;
-
-static void *autoservice_run(void *ign)
-{
- struct ast_channel *mons[MAX_AUTOMONS];
- int x;
- int ms;
- struct ast_channel *chan;
- struct asent *as;
- struct ast_frame *f;
- for(;;) {
- x = 0;
- ast_mutex_lock(&autolock);
- as = aslist;
- while(as) {
- if (!as->chan->_softhangup) {
- if (x < MAX_AUTOMONS)
- mons[x++] = as->chan;
- else
- ast_log(LOG_WARNING, "Exceeded maximum number of automatic monitoring events. Fix autoservice.c\n");
- }
- as = as->next;
- }
- ast_mutex_unlock(&autolock);
-
-/* if (!aslist)
- break; */
- ms = 500;
- chan = ast_waitfor_n(mons, x, &ms);
- if (chan) {
- /* Read and ignore anything that occurs */
- f = ast_read(chan);
- if (f)
- ast_frfree(f);
- }
- }
- asthread = AST_PTHREADT_NULL;
- return NULL;
-}
-
-int ast_autoservice_start(struct ast_channel *chan)
-{
- int res = -1;
- struct asent *as;
- int needstart;
- ast_mutex_lock(&autolock);
- needstart = (asthread == AST_PTHREADT_NULL) ? 1 : 0 /* aslist ? 0 : 1 */;
- as = aslist;
- while(as) {
- if (as->chan == chan)
- break;
- as = as->next;
- }
- if (!as) {
- as = malloc(sizeof(struct asent));
- if (as) {
- memset(as, 0, sizeof(struct asent));
- as->chan = chan;
- as->next = aslist;
- aslist = as;
- res = 0;
- if (needstart) {
- if (ast_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
- ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
- free(aslist);
- aslist = NULL;
- res = -1;
- } else
- pthread_kill(asthread, SIGURG);
- }
- }
- }
- ast_mutex_unlock(&autolock);
- return res;
-}
-
-int ast_autoservice_stop(struct ast_channel *chan)
-{
- int res = -1;
- struct asent *as, *prev;
- ast_mutex_lock(&autolock);
- as = aslist;
- prev = NULL;
- while(as) {
- if (as->chan == chan)
- break;
- prev = as;
- as = as->next;
- }
- if (as) {
- if (prev)
- prev->next = as->next;
- else
- aslist = as->next;
- free(as);
- if (!chan->_softhangup)
- res = 0;
- }
- if (asthread != AST_PTHREADT_NULL)
- pthread_kill(asthread, SIGURG);
- ast_mutex_unlock(&autolock);
- /* Wait for it to un-block */
- while(ast_test_flag(chan, AST_FLAG_BLOCKING))
- usleep(1000);
- return res;
-}
diff --git a/1.2-netsec/build_tools/make_build_h b/1.2-netsec/build_tools/make_build_h
deleted file mode 100755
index 167785340..000000000
--- a/1.2-netsec/build_tools/make_build_h
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-HOSTNAME=`uname -n`
-KERNEL=`uname -r`
-MACHINE=`uname -m`
-OS=`uname -s`
-if [ `uname -s` = "SunOS" ]; then
- USER=`/usr/xpg4/bin/id -un`
-else
- USER=`id -un`
-fi
-DATE=`date -u "+%Y-%m-%d %H:%M:%S"`
-cat << END
-/*
- * build.h
- * Automatically generated
- */
-#define BUILD_HOSTNAME "${HOSTNAME}"
-#define BUILD_KERNEL "${KERNEL}"
-#define BUILD_MACHINE "${MACHINE}"
-#define BUILD_OS "${OS}"
-#define BUILD_DATE "${DATE} UTC"
-#define BUILD_USER "${USER}"
-
-END
diff --git a/1.2-netsec/build_tools/make_defaults_h b/1.2-netsec/build_tools/make_defaults_h
deleted file mode 100755
index 7b9411111..000000000
--- a/1.2-netsec/build_tools/make_defaults_h
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-cat << END
-/*
- * defaults.h
- * Automatically generated
- */
-#define AST_CONFIG_DIR "${INSTALL_PATH}${ASTETCDIR}"
-#define AST_RUN_DIR "${INSTALL_PATH}${ASTVARRUNDIR}"
-#define AST_SOCKET "${INSTALL_PATH}${ASTVARRUNDIR}/asterisk.ctl"
-#define AST_PID "${INSTALL_PATH}${ASTVARRUNDIR}/asterisk.pid"
-#define AST_MODULE_DIR "${INSTALL_PATH}${MODULES_DIR}"
-#define AST_SPOOL_DIR "${INSTALL_PATH}${ASTSPOOLDIR}"
-#define AST_VAR_DIR "${INSTALL_PATH}${ASTVARLIBDIR}"
-#define AST_LOG_DIR "${INSTALL_PATH}${ASTLOGDIR}"
-#define AST_AGI_DIR "${INSTALL_PATH}${AGI_DIR}"
-#define AST_KEY_DIR "${INSTALL_PATH}${ASTVARLIBDIR}/keys"
-#define AST_DB "${INSTALL_PATH}${ASTVARLIBDIR}/astdb"
-#define AST_TMP_DIR "${INSTALL_PATH}${ASTSPOOLDIR}/tmp"
-
-#define AST_CONFIG_FILE "${INSTALL_PATH}${ASTCONFPATH}"
-
-#define AST_SOUNDS "${INSTALL_PATH}${ASTVARLIBDIR}/sounds"
-#define AST_IMAGES "${INSTALL_PATH}${ASTVARLIBDIR}/images"
-
-END
diff --git a/1.2-netsec/build_tools/make_svn_branch_name b/1.2-netsec/build_tools/make_svn_branch_name
deleted file mode 100755
index 848ca49eb..000000000
--- a/1.2-netsec/build_tools/make_svn_branch_name
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/sh
-
-PARTS=`LANG=C svn info | grep URL | awk '{print $2;}' | sed -e 's:^.*/svn/asterisk/::' | sed -e 's:/: :g'`
-BRANCH=0
-TEAM=0
-
-REV=`svnversion -c . | cut -d: -f2`
-
-if [ "${PARTS}" = "trunk" ]
-then
- echo 'trunk'-r${REV}
- exit 0
-fi
-
-for PART in $PARTS
-do
- if [ ${BRANCH} != 0 ]
- then
- RESULT="${RESULT}-${PART}"
- break
- fi
-
- if [ ${TEAM} != 0 ]
- then
- RESULT="${RESULT}-${PART}"
- continue
- fi
-
- if [ "${PART}" = "branches" ]
- then
- BRANCH=1
- RESULT="branch"
- continue
- fi
-
- if [ "${PART}" = "tags" ]
- then
- BRANCH=1
- RESULT="tag"
- continue
- fi
-
- if [ "${PART}" = "team" ]
- then
- TEAM=1
- continue
- fi
-done
-
-echo ${RESULT##-}-r${REV}
diff --git a/1.2-netsec/build_tools/make_version_h b/1.2-netsec/build_tools/make_version_h
deleted file mode 100755
index f0e81f70a..000000000
--- a/1.2-netsec/build_tools/make_version_h
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-cat << END
-/*
- * version.h
- * Automatically generated
- */
-#define ASTERISK_VERSION "${ASTERISKVERSION}"
-#define ASTERISK_VERSION_NUM ${ASTERISKVERSIONNUM}
-
-END
diff --git a/1.2-netsec/build_tools/mkdep b/1.2-netsec/build_tools/mkdep
deleted file mode 100755
index 84f969b1d..000000000
--- a/1.2-netsec/build_tools/mkdep
+++ /dev/null
@@ -1,123 +0,0 @@
-#!/bin/sh -
-#
-# $OpenBSD: mkdep.gcc.sh,v 1.8 1998/09/02 06:40:07 deraadt Exp $
-# $NetBSD: mkdep.gcc.sh,v 1.9 1994/12/23 07:34:59 jtc Exp $
-#
-# Copyright (c) 1991, 1993
-# The Regents of the University of California. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the University of
-# California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# @(#)mkdep.gcc.sh 8.1 (Berkeley) 6/6/93
-#
-
-D=.depend # default dependency file is .depend
-append=0
-pflag=
-dflag=
-
-while :
- do case "$1" in
- # -a appends to the depend file
- -a)
- append=1
- shift ;;
-
- # -f allows you to select a makefile name
- -f)
- D=$2
- shift; shift ;;
-
- # the -p flag produces "program: program.c" style dependencies
- # so .o's don't get produced
- -p)
- pflag=p
- shift ;;
-
- # the -d flag produces double-colon rules instead of single-colon rules
- -d)
- dflag=d
- shift ;;
-
- *)
- break ;;
- esac
-done
-
-if [ $# = 0 ] ; then
- echo 'usage: mkdep [-p] [-d] [-f depend_file] [cc_flags] file ...'
- exit 1
-fi
-
-DTMP=/tmp/mkdep$$
-TMP=$DTMP/mkdep
-
-um=`umask`
-umask 022
-mkdir $DTMP
-if [ $? != 0 ] ; then
- echo failed to create tmp dir $DTMP
- exit 1
-fi
-
-umask $um
-trap 'rm -rf $DTMP ; trap 2 ; kill -2 $$' 1 2 3 13 15
-
-if [ x$pflag = xp ]; then
- ${CC:-cc} -M "$@" 2>/dev/null | sed -e 's;\.o :; :;' -e 's; \./; ;g' > $TMP
-elif [ x$dflag = xd ]; then
- ${CC:-cc} -M "$@" 2>/dev/null | sed -e 's;\.o:;\.o::;' -e 's; \./; ;g' > $TMP
-else
- ${CC:-cc} -M "$@" 2>/dev/null | sed -e 's; \./; ;g' > $TMP
-fi
-
-if [ $? != 0 ]; then
- echo 'mkdep: compile failed.'
- rm -rf $DTMP
- exit 1
-fi
-
-if [ $append = 1 ]; then
- cat $TMP >> $D
- if [ $? != 0 ]; then
- echo 'mkdep: append failed.'
- rm -rf $DTMP
- exit 1
- fi
-else
- mv $TMP $D
- if [ $? != 0 ]; then
- echo 'mkdep: rename failed.'
- rm -rf $DTMP
- exit 1
- fi
-fi
-
-rm -rf $DTMP
-exit 0
diff --git a/1.2-netsec/buildinfo.c b/1.2-netsec/buildinfo.c
deleted file mode 100644
index cd7ce8df3..000000000
--- a/1.2-netsec/buildinfo.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Digium, Inc.
- *
- * Kevin P. Fleming <kpfleming@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Build timestamp variables
- *
- */
-
-#include "asterisk/build.h"
-
-const char *ast_build_hostname = BUILD_HOSTNAME;
-const char *ast_build_kernel = BUILD_KERNEL;
-const char *ast_build_machine = BUILD_MACHINE;
-const char *ast_build_os = BUILD_OS;
-const char *ast_build_date = BUILD_DATE;
-const char *ast_build_user = BUILD_USER;
diff --git a/1.2-netsec/callerid.c b/1.2-netsec/callerid.c
deleted file mode 100644
index a0937b24a..000000000
--- a/1.2-netsec/callerid.c
+++ /dev/null
@@ -1,788 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief CallerID Generation support
- *
- */
-
-#include <time.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <math.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/ulaw.h"
-#include "asterisk/alaw.h"
-#include "asterisk/frame.h"
-#include "asterisk/channel.h"
-#include "asterisk/callerid.h"
-#include "asterisk/logger.h"
-#include "asterisk/fskmodem.h"
-#include "asterisk/utils.h"
-
-struct callerid_state {
- fsk_data fskd;
- char rawdata[256];
- short oldstuff[160];
- int oldlen;
- int pos;
- int type;
- int cksum;
- char name[64];
- char number[64];
- int flags;
- int sawflag;
- int len;
-};
-
-
-float cid_dr[4], cid_di[4];
-float clidsb = 8000.0 / 1200.0;
-float sasdr, sasdi;
-float casdr1, casdi1, casdr2, casdi2;
-
-#define CALLERID_SPACE 2200.0 /*!< 2200 hz for "0" */
-#define CALLERID_MARK 1200.0 /*!< 1200 hz for "1" */
-#define SAS_FREQ 440.0
-#define CAS_FREQ1 2130.0
-#define CAS_FREQ2 2750.0
-
-#define AST_CALLERID_UNKNOWN "<unknown>"
-
-static inline void gen_tones(unsigned char *buf, int len, int codec, float ddr1, float ddi1, float ddr2, float ddi2, float *cr1, float *ci1, float *cr2, float *ci2)
-{
- int x;
- float t;
- for (x=0;x<len;x++) {
- t = *cr1 * ddr1 - *ci1 * ddi1;
- *ci1 = *cr1 * ddi1 + *ci1 * ddr1;
- *cr1 = t;
- t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1);
- *cr1 *= t;
- *ci1 *= t;
-
- t = *cr2 * ddr2 - *ci2 * ddi2;
- *ci2 = *cr2 * ddi2 + *ci2 * ddr2;
- *cr2 = t;
- t = 2.0 - (*cr2 * *cr2 + *ci2 * *ci2);
- *cr2 *= t;
- *ci2 *= t;
- buf[x] = AST_LIN2X((*cr1 + *cr2) * 2048.0);
- }
-}
-
-static inline void gen_tone(unsigned char *buf, int len, int codec, float ddr1, float ddi1, float *cr1, float *ci1)
-{
- int x;
- float t;
- for (x=0;x<len;x++) {
- t = *cr1 * ddr1 - *ci1 * ddi1;
- *ci1 = *cr1 * ddi1 + *ci1 * ddr1;
- *cr1 = t;
- t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1);
- *cr1 *= t;
- *ci1 *= t;
- buf[x] = AST_LIN2X(*cr1 * 8192.0);
- }
-}
-
-/*! \brief Initialize stuff for inverse FFT */
-void callerid_init(void)
-{
- cid_dr[0] = cos(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
- cid_di[0] = sin(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
- cid_dr[1] = cos(CALLERID_MARK * 2.0 * M_PI / 8000.0);
- cid_di[1] = sin(CALLERID_MARK * 2.0 * M_PI / 8000.0);
- sasdr = cos(SAS_FREQ * 2.0 * M_PI / 8000.0);
- sasdi = sin(SAS_FREQ * 2.0 * M_PI / 8000.0);
- casdr1 = cos(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
- casdi1 = sin(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
- casdr2 = cos(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
- casdi2 = sin(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
-}
-
-struct callerid_state *callerid_new(int cid_signalling)
-{
- struct callerid_state *cid;
- cid = malloc(sizeof(struct callerid_state));
- if (cid) {
- memset(cid, 0, sizeof(struct callerid_state));
- cid->fskd.spb = 7; /* 1200 baud */
- cid->fskd.hdlc = 0; /* Async */
- cid->fskd.nbit = 8; /* 8 bits */
- cid->fskd.nstop = 1; /* 1 stop bit */
- cid->fskd.paridad = 0; /* No parity */
- cid->fskd.bw=1; /* Filter 800 Hz */
- if (cid_signalling == 2) { /* v23 signalling */
- cid->fskd.f_mark_idx = 4; /* 1300 Hz */
- cid->fskd.f_space_idx = 5; /* 2100 Hz */
- } else { /* Bell 202 signalling as default */
- cid->fskd.f_mark_idx = 2; /* 1200 Hz */
- cid->fskd.f_space_idx = 3; /* 2200 Hz */
- }
- cid->fskd.pcola = 0; /* No clue */
- cid->fskd.cont = 0; /* Digital PLL reset */
- cid->fskd.x0 = 0.0;
- cid->fskd.state = 0;
- memset(cid->name, 0, sizeof(cid->name));
- memset(cid->number, 0, sizeof(cid->number));
- cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER;
- cid->pos = 0;
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return cid;
-}
-
-void callerid_get(struct callerid_state *cid, char **name, char **number, int *flags)
-{
- *flags = cid->flags;
- if (cid->flags & (CID_UNKNOWN_NAME | CID_PRIVATE_NUMBER))
- *name = NULL;
- else
- *name = cid->name;
- if (cid->flags & (CID_UNKNOWN_NUMBER | CID_PRIVATE_NUMBER))
- *number = NULL;
- else
- *number = cid->number;
-}
-
-void callerid_get_dtmf(char *cidstring, char *number, int *flags)
-{
- int i;
- int code;
-
- /* "Clear" the number-buffer. */
- number[0] = 0;
-
- if (strlen(cidstring) < 2) {
- ast_log(LOG_DEBUG, "No cid detected\n");
- *flags = CID_UNKNOWN_NUMBER;
- return;
- }
-
- /* Detect protocol and special types */
- if (cidstring[0] == 'B') {
- /* Handle special codes */
- code = atoi(&cidstring[1]);
- if (code == 0)
- *flags = CID_UNKNOWN_NUMBER;
- else if (code == 10)
- *flags = CID_PRIVATE_NUMBER;
- else
- ast_log(LOG_DEBUG, "Unknown DTMF code %d\n", code);
- } else if (cidstring[0] == 'D' && cidstring[2] == '#') {
- /* .DK special code */
- if (cidstring[1] == '1')
- *flags = CID_PRIVATE_NUMBER;
- if (cidstring[1] == '2' || cidstring[1] == '3')
- *flags = CID_UNKNOWN_NUMBER;
- } else if (cidstring[0] == 'D' || cidstring[0] == 'A') {
- /* "Standard" callerid */
- for (i = 1; i < strlen(cidstring); i++ ) {
- if (cidstring[i] == 'C' || cidstring[i] == '#')
- break;
- if (isdigit(cidstring[i]))
- number[i-1] = cidstring[i];
- else
- ast_log(LOG_DEBUG, "Unknown CID digit '%c'\n",
- cidstring[i]);
- }
- number[i-1] = 0;
- } else if (isdigit(cidstring[0])) {
- /* It begins with a digit, so we parse it as a number and hope
- * for the best */
- ast_log(LOG_WARNING, "Couldn't detect start-character. CID "
- "parsing might be unreliable\n");
- for (i = 0; i < strlen(cidstring); i++) {
- if (isdigit(cidstring[i]))
- number[i] = cidstring[i];
- else
- break;
- }
- number[i] = 0;
- } else {
- ast_log(LOG_DEBUG, "Unknown CID protocol, start digit '%c'\n",
- cidstring[0]);
- *flags = CID_UNKNOWN_NUMBER;
- }
-}
-
-int ast_gen_cas(unsigned char *outbuf, int sendsas, int len, int codec)
-{
- int pos = 0;
- int saslen=2400;
- float cr1 = 1.0;
- float ci1 = 0.0;
- float cr2 = 1.0;
- float ci2 = 0.0;
- if (sendsas) {
- if (len < saslen)
- return -1;
- gen_tone(outbuf, saslen, codec, sasdr, sasdi, &cr1, &ci1);
- len -= saslen;
- pos += saslen;
- cr2 = cr1;
- ci2 = ci1;
- }
- gen_tones(outbuf + pos, len, codec, casdr1, casdi1, casdr2, casdi2, &cr1, &ci1, &cr2, &ci2);
- return 0;
-}
-
-int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len, int codec)
-{
- int mylen = len;
- int olen;
- int b = 'X';
- int res;
- int x;
- short *buf = malloc(2 * len + cid->oldlen);
- short *obuf = buf;
- if (!buf) {
- ast_log(LOG_WARNING, "Out of memory\n");
- return -1;
- }
- memset(buf, 0, 2 * len + cid->oldlen);
- memcpy(buf, cid->oldstuff, cid->oldlen);
- mylen += cid->oldlen/2;
- for (x=0;x<len;x++)
- buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
- while(mylen >= 160) {
- olen = mylen;
- res = fsk_serie(&cid->fskd, buf, &mylen, &b);
- if (mylen < 0) {
- ast_log(LOG_ERROR, "fsk_serie made mylen < 0 (%d)\n", mylen);
- return -1;
- }
- buf += (olen - mylen);
- if (res < 0) {
- ast_log(LOG_NOTICE, "fsk_serie failed\n");
- return -1;
- }
- if (res == 1) {
- /* Ignore invalid bytes */
- if (b > 0xff)
- continue;
- switch(cid->sawflag) {
- case 0: /* Look for flag */
- if (b == 'U')
- cid->sawflag = 2;
- break;
- case 2: /* Get lead-in */
- if ((b == 0x04) || (b == 0x80)) {
- cid->type = b;
- cid->sawflag = 3;
- cid->cksum = b;
- }
- break;
- case 3: /* Get length */
- /* Not a lead in. We're ready */
- cid->sawflag = 4;
- cid->len = b;
- cid->pos = 0;
- cid->cksum += b;
- break;
- case 4: /* Retrieve message */
- if (cid->pos >= 128) {
- ast_log(LOG_WARNING, "Caller ID too long???\n");
- return -1;
- }
- cid->rawdata[cid->pos++] = b;
- cid->len--;
- cid->cksum += b;
- if (!cid->len) {
- cid->rawdata[cid->pos] = '\0';
- cid->sawflag = 5;
- }
- break;
- case 5: /* Check checksum */
- if (b != (256 - (cid->cksum & 0xff))) {
- ast_log(LOG_NOTICE, "Caller*ID failed checksum\n");
- /* Try again */
- cid->sawflag = 0;
- break;
- }
-
- cid->number[0] = '\0';
- cid->name[0] = '\0';
- /* If we get this far we're fine. */
- if (cid->type == 0x80) {
- /* MDMF */
- /* Go through each element and process */
- for (x=0;x< cid->pos;) {
- switch(cid->rawdata[x++]) {
- case 1:
- /* Date */
- break;
- case 2: /* Number */
- case 3: /* Number (for Zebble) */
- case 4: /* Number */
- res = cid->rawdata[x];
- if (res > 32) {
- ast_log(LOG_NOTICE, "Truncating long caller ID number from %d bytes to 32\n", cid->rawdata[x]);
- res = 32;
- }
- if (ast_strlen_zero(cid->number)) {
- memcpy(cid->number, cid->rawdata + x + 1, res);
- /* Null terminate */
- cid->number[res] = '\0';
- }
- break;
- case 6: /* Stentor Call Qualifier (ie. Long Distance call) */
- break;
- case 7: /* Name */
- case 8: /* Name */
- res = cid->rawdata[x];
- if (res > 32) {
- ast_log(LOG_NOTICE, "Truncating long caller ID name from %d bytes to 32\n", cid->rawdata[x]);
- res = 32;
- }
- memcpy(cid->name, cid->rawdata + x + 1, res);
- cid->name[res] = '\0';
- break;
- case 17: /* UK: Call type, 1=Voice Call, 2=Ringback when free, 129=Message waiting */
- case 19: /* UK: Network message system status (Number of messages waiting) */
- case 22: /* Something French */
- break;
- default:
- ast_log(LOG_NOTICE, "Unknown IE %d\n", cid->rawdata[x-1]);
- }
- x += cid->rawdata[x];
- x++;
- }
- } else {
- /* SDMF */
- ast_copy_string(cid->number, cid->rawdata + 8, sizeof(cid->number));
- }
- /* Update flags */
- cid->flags = 0;
- if (!strcmp(cid->number, "P")) {
- strcpy(cid->number, "");
- cid->flags |= CID_PRIVATE_NUMBER;
- } else if (!strcmp(cid->number, "O") || ast_strlen_zero(cid->number)) {
- strcpy(cid->number, "");
- cid->flags |= CID_UNKNOWN_NUMBER;
- }
- if (!strcmp(cid->name, "P")) {
- strcpy(cid->name, "");
- cid->flags |= CID_PRIVATE_NAME;
- } else if (!strcmp(cid->name, "O") || ast_strlen_zero(cid->name)) {
- strcpy(cid->name, "");
- cid->flags |= CID_UNKNOWN_NAME;
- }
- return 1;
- break;
- default:
- ast_log(LOG_ERROR, "Dunno what to do with a digit in sawflag %d\n", cid->sawflag);
- }
- }
- }
- if (mylen) {
- memcpy(cid->oldstuff, buf, mylen * 2);
- cid->oldlen = mylen * 2;
- } else
- cid->oldlen = 0;
- free(obuf);
- return 0;
-}
-
-void callerid_free(struct callerid_state *cid)
-{
- free(cid);
-}
-
-static int callerid_genmsg(char *msg, int size, char *number, char *name, int flags)
-{
- time_t t;
- struct tm tm;
- char *ptr;
- int res;
- int i,x;
- /* Get the time */
- time(&t);
- localtime_r(&t,&tm);
-
- ptr = msg;
-
- /* Format time and message header */
- res = snprintf(ptr, size, "\001\010%02d%02d%02d%02d", tm.tm_mon + 1,
- tm.tm_mday, tm.tm_hour, tm.tm_min);
- size -= res;
- ptr += res;
- if (ast_strlen_zero(number) || (flags & CID_UNKNOWN_NUMBER)) {
- /* Indicate number not known */
- res = snprintf(ptr, size, "\004\001O");
- size -= res;
- ptr += res;
- } else if (flags & CID_PRIVATE_NUMBER) {
- /* Indicate number is private */
- res = snprintf(ptr, size, "\004\001P");
- size -= res;
- ptr += res;
- } else {
- /* Send up to 16 digits of number MAX */
- i = strlen(number);
- if (i > 16) i = 16;
- res = snprintf(ptr, size, "\002%c", i);
- size -= res;
- ptr += res;
- for (x=0;x<i;x++)
- ptr[x] = number[x];
- ptr[i] = '\0';
- ptr += i;
- size -= i;
- }
-
- if (ast_strlen_zero(name) || (flags & CID_UNKNOWN_NAME)) {
- /* Indicate name not known */
- res = snprintf(ptr, size, "\010\001O");
- size -= res;
- ptr += res;
- } else if (flags & CID_PRIVATE_NAME) {
- /* Indicate name is private */
- res = snprintf(ptr, size, "\010\001P");
- size -= res;
- ptr += res;
- } else {
- /* Send up to 16 digits of name MAX */
- i = strlen(name);
- if (i > 16) i = 16;
- res = snprintf(ptr, size, "\007%c", i);
- size -= res;
- ptr += res;
- for (x=0;x<i;x++)
- ptr[x] = name[x];
- ptr[i] = '\0';
- ptr += i;
- size -= i;
- }
- return (ptr - msg);
-
-}
-
-int vmwi_generate(unsigned char *buf, int active, int mdmf, int codec)
-{
- unsigned char msg[256];
- int len=0;
- int sum;
- int x;
- int bytes = 0;
- float cr = 1.0;
- float ci = 0.0;
- float scont = 0.0;
- if (mdmf) {
- /* MDMF Message waiting */
- msg[len++] = 0x82;
- /* Length is 3 */
- msg[len++] = 3;
- /* IE is "Message Waiting Parameter" */
- msg[len++] = 0xb;
- /* Length of IE is one */
- msg[len++] = 1;
- /* Active or not */
- if (active)
- msg[len++] = 0xff;
- else
- msg[len++] = 0x00;
- } else {
- /* SDMF Message waiting */
- msg[len++] = 0x6;
- /* Length is 3 */
- msg[len++] = 3;
- if (active) {
- msg[len++] = 0x42;
- msg[len++] = 0x42;
- msg[len++] = 0x42;
- } else {
- msg[len++] = 0x6f;
- msg[len++] = 0x6f;
- msg[len++] = 0x6f;
- }
- }
- sum = 0;
- for (x=0;x<len;x++)
- sum += msg[x];
- sum = (256 - (sum & 255));
- msg[len++] = sum;
- /* Wait a half a second */
- for (x=0;x<4000;x++)
- PUT_BYTE(0x7f);
- /* Transmit 30 0x55's (looks like a square wave) for channel seizure */
- for (x=0;x<30;x++)
- PUT_CLID(0x55);
- /* Send 170ms of callerid marks */
- for (x=0;x<170;x++)
- PUT_CLID_MARKMS;
- for (x=0;x<len;x++) {
- PUT_CLID(msg[x]);
- }
- /* Send 50 more ms of marks */
- for (x=0;x<50;x++)
- PUT_CLID_MARKMS;
- return bytes;
-}
-
-int callerid_generate(unsigned char *buf, char *number, char *name, int flags, int callwaiting, int codec)
-{
- int bytes=0;
- int x, sum;
- int len;
- /* Initial carriers (real/imaginary) */
- float cr = 1.0;
- float ci = 0.0;
- float scont = 0.0;
- char msg[256];
- len = callerid_genmsg(msg, sizeof(msg), number, name, flags);
- if (!callwaiting) {
- /* Wait a half a second */
- for (x=0;x<4000;x++)
- PUT_BYTE(0x7f);
- /* Transmit 30 0x55's (looks like a square wave) for channel seizure */
- for (x=0;x<30;x++)
- PUT_CLID(0x55);
- }
- /* Send 150ms of callerid marks */
- for (x=0;x<150;x++)
- PUT_CLID_MARKMS;
- /* Send 0x80 indicating MDMF format */
- PUT_CLID(0x80);
- /* Put length of whole message */
- PUT_CLID(len);
- sum = 0x80 + strlen(msg);
- /* Put each character of message and update checksum */
- for (x=0;x<len; x++) {
- PUT_CLID(msg[x]);
- sum += msg[x];
- }
- /* Send 2's compliment of sum */
- PUT_CLID(256 - (sum & 255));
-
- /* Send 50 more ms of marks */
- for (x=0;x<50;x++)
- PUT_CLID_MARKMS;
-
- return bytes;
-}
-
-void ast_shrink_phone_number(char *n)
-{
- int x,y=0;
- int bracketed=0;
- for (x=0;n[x];x++) {
- switch(n[x]) {
- case '[':
- bracketed++;
- n[y++] = n[x];
- break;
- case ']':
- bracketed--;
- n[y++] = n[x];
- break;
- case '-':
- if (bracketed)
- n[y++] = n[x];
- break;
- case '.':
- if (!n[x+1])
- n[y++] = n[x];
- break;
- default:
- if (!strchr("( )", n[x]))
- n[y++] = n[x];
- }
- }
- n[y] = '\0';
-}
-
-/*! \brief checks if string consists only of digits and * \# and +
- \return 1 if string is valid AST phone number
- \return 0 if not
-*/
-int ast_isphonenumber(char *n)
-{
- int x;
- if (ast_strlen_zero(n))
- return 0;
- for (x=0;n[x];x++)
- if (!strchr("0123456789*#+", n[x]))
- return 0;
- return 1;
-}
-
-/*! \brief parse string for caller id information
- \return returns -1 on failure, otherwise 0
-*/
-int ast_callerid_parse(char *instr, char **name, char **location)
-{
- char *ns, *ne;
- char *ls, *le;
- char tmp[256];
- /* Try for "name" <location> format or
- name <location> format */
- if ((ls = strchr(instr, '<')) && (le = strchr(ls, '>'))) {
- /* Found the location */
- *le = '\0';
- *ls = '\0';
- *location = ls + 1;
- if ((ns = strchr(instr, '\"')) && (ne = strchr(ns + 1, '\"'))) {
- /* Get name out of quotes */
- *ns = '\0';
- *ne = '\0';
- *name = ns + 1;
- return 0;
- } else {
- /* Just trim off any trailing spaces */
- *name = instr;
- while(!ast_strlen_zero(instr) && (instr[strlen(instr) - 1] < 33))
- instr[strlen(instr) - 1] = '\0';
- /* And leading spaces */
- *name = ast_skip_blanks(*name);
- return 0;
- }
- } else {
- ast_copy_string(tmp, instr, sizeof(tmp));
- ast_shrink_phone_number(tmp);
- if (ast_isphonenumber(tmp)) {
- /* Assume it's just a location */
- *name = NULL;
- *location = instr;
- } else {
- /* Assume it's just a name. Make sure it's not quoted though */
- *name = instr;
- while(*(*name) && ((*(*name) < 33) || (*(*name) == '\"'))) (*name)++;
- ne = *name + strlen(*name) - 1;
- while((ne > *name) && ((*ne < 33) || (*ne == '\"'))) { *ne = '\0'; ne--; }
- *location = NULL;
- }
- return 0;
- }
- return -1;
-}
-
-static int __ast_callerid_generate(unsigned char *buf, char *name, char *number, int callwaiting, int codec)
-{
- if (ast_strlen_zero(name))
- name = NULL;
- if (ast_strlen_zero(number))
- number = NULL;
- return callerid_generate(buf, number, name, 0, callwaiting, codec);
-}
-
-int ast_callerid_generate(unsigned char *buf, char *name, char *number, int codec)
-{
- return __ast_callerid_generate(buf, name, number, 0, codec);
-}
-
-int ast_callerid_callwaiting_generate(unsigned char *buf, char *name, char *number, int codec)
-{
- return __ast_callerid_generate(buf, name, number, 1, codec);
-}
-
-char *ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown)
-{
- if (!unknown)
- unknown = "<unknown>";
- if (name && num)
- snprintf(buf, bufsiz, "\"%s\" <%s>", name, num);
- else if (name)
- ast_copy_string(buf, name, bufsiz);
- else if (num)
- ast_copy_string(buf, num, bufsiz);
- else
- ast_copy_string(buf, unknown, bufsiz);
- return buf;
-}
-
-int ast_callerid_split(const char *buf, char *name, int namelen, char *num, int numlen)
-{
- char *tmp;
- char *l = NULL, *n = NULL;
- tmp = ast_strdupa(buf);
- if (!tmp) {
- name[0] = '\0';
- num[0] = '\0';
- return -1;
- }
- ast_callerid_parse(tmp, &n, &l);
- if (n)
- ast_copy_string(name, n, namelen);
- else
- name[0] = '\0';
- if (l) {
- ast_shrink_phone_number(l);
- ast_copy_string(num, l, numlen);
- } else
- num[0] = '\0';
- return 0;
-}
-
-static struct {
- int val;
- char *name;
- char *description;
-} pres_types[] = {
- { AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, "allowed_not_screened", "Presentation Allowed, Not Screened"},
- { AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, "allowed_passed_screen", "Presentation Allowed, Passed Screen"},
- { AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, "allowed_failed_screen", "Presentation Allowed, Failed Screen"},
- { AST_PRES_ALLOWED_NETWORK_NUMBER, "allowed", "Presentation Allowed, Network Number"},
- { AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, "prohib_not_screened", "Presentation Prohibited, Not Screened"},
- { AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, "prohib_passed_screen", "Presentation Prohibited, Passed Screen"},
- { AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, "prohib_failed_screen", "Presentation Prohibited, Failed Screen"},
- { AST_PRES_PROHIB_NETWORK_NUMBER, "prohib", "Presentation Prohibited, Network Number"},
- { AST_PRES_NUMBER_NOT_AVAILABLE, "unavailable", "Number Unavailable"},
-};
-
-/*! \brief Convert caller ID text code to value
- used in config file parsing
- \param data text string
- \return value AST_PRES_ from callerid.h
-*/
-int ast_parse_caller_presentation(const char *data)
-{
- int i;
-
- for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) {
- if (!strcasecmp(pres_types[i].name, data))
- return pres_types[i].val;
- }
-
- return -1;
-}
-
-/*! \brief Convert caller ID pres value to explanatory string
- \param data value (see callerid.h AST_PRES_ )
- \return string for human presentation
-*/
-const char *ast_describe_caller_presentation(int data)
-{
- int i;
-
- for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) {
- if (pres_types[i].val == data)
- return pres_types[i].description;
- }
-
- return "unknown";
-}
diff --git a/1.2-netsec/cdr.c b/1.2-netsec/cdr.c
deleted file mode 100644
index 2e78671dc..000000000
--- a/1.2-netsec/cdr.c
+++ /dev/null
@@ -1,1267 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Call Detail Record API
- *
- * Includes code and algorithms from the Zapata library.
- *
- * \note We do a lot of checking here in the CDR code to try to be sure we don't ever let a CDR slip
- * through our fingers somehow. If someone allocates a CDR, it must be completely handled normally
- * or a WARNING shall be logged, so that we can best keep track of any escape condition where the CDR
- * isn't properly generated and posted.
- */
-
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <signal.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/cdr.h"
-#include "asterisk/logger.h"
-#include "asterisk/callerid.h"
-#include "asterisk/causes.h"
-#include "asterisk/options.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/utils.h"
-#include "asterisk/sched.h"
-#include "asterisk/config.h"
-#include "asterisk/cli.h"
-#include "asterisk/module.h"
-
-/*! Default AMA flag for billing records (CDR's) */
-int ast_default_amaflags = AST_CDR_DOCUMENTATION;
-char ast_default_accountcode[AST_MAX_ACCOUNT_CODE] = "";
-
-struct ast_cdr_beitem {
- char name[20];
- char desc[80];
- ast_cdrbe be;
- AST_LIST_ENTRY(ast_cdr_beitem) list;
-};
-
-static AST_LIST_HEAD_STATIC(be_list, ast_cdr_beitem);
-
-struct ast_cdr_batch_item {
- struct ast_cdr *cdr;
- struct ast_cdr_batch_item *next;
-};
-
-static struct ast_cdr_batch {
- int size;
- struct ast_cdr_batch_item *head;
- struct ast_cdr_batch_item *tail;
-} *batch = NULL;
-
-static struct sched_context *sched;
-static int cdr_sched = -1;
-static pthread_t cdr_thread = AST_PTHREADT_NULL;
-
-#define BATCH_SIZE_DEFAULT 100
-#define BATCH_TIME_DEFAULT 300
-#define BATCH_SCHEDULER_ONLY_DEFAULT 0
-#define BATCH_SAFE_SHUTDOWN_DEFAULT 1
-
-static int enabled;
-static int batchmode;
-static int batchsize;
-static int batchtime;
-static int batchscheduleronly;
-static int batchsafeshutdown;
-
-AST_MUTEX_DEFINE_STATIC(cdr_batch_lock);
-
-/* these are used to wake up the CDR thread when there's work to do */
-AST_MUTEX_DEFINE_STATIC(cdr_pending_lock);
-static ast_cond_t cdr_pending_cond;
-
-
-/*! Register a CDR driver. Each registered CDR driver generates a CDR
- \return 0 on success, -1 on failure
-*/
-int ast_cdr_register(char *name, char *desc, ast_cdrbe be)
-{
- struct ast_cdr_beitem *i;
-
- if (!name)
- return -1;
- if (!be) {
- ast_log(LOG_WARNING, "CDR engine '%s' lacks backend\n", name);
- return -1;
- }
-
- AST_LIST_LOCK(&be_list);
- AST_LIST_TRAVERSE(&be_list, i, list) {
- if (!strcasecmp(name, i->name))
- break;
- }
- AST_LIST_UNLOCK(&be_list);
-
- if (i) {
- ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name);
- return -1;
- }
-
- i = malloc(sizeof(*i));
- if (!i)
- return -1;
-
- memset(i, 0, sizeof(*i));
- i->be = be;
- ast_copy_string(i->name, name, sizeof(i->name));
- ast_copy_string(i->desc, desc, sizeof(i->desc));
-
- AST_LIST_LOCK(&be_list);
- AST_LIST_INSERT_HEAD(&be_list, i, list);
- AST_LIST_UNLOCK(&be_list);
-
- return 0;
-}
-
-/*! unregister a CDR driver */
-void ast_cdr_unregister(char *name)
-{
- struct ast_cdr_beitem *i = NULL;
-
- AST_LIST_LOCK(&be_list);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&be_list, i, list) {
- if (!strcasecmp(name, i->name)) {
- AST_LIST_REMOVE_CURRENT(&be_list, list);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Unregistered '%s' CDR backend\n", name);
- free(i);
- break;
- }
- }
- AST_LIST_TRAVERSE_SAFE_END;
- AST_LIST_UNLOCK(&be_list);
-}
-
-/*! Duplicate a CDR record
- \returns Pointer to new CDR record
-*/
-struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr)
-{
- struct ast_cdr *newcdr;
-
- if (!(newcdr = ast_cdr_alloc())) {
- ast_log(LOG_ERROR, "Memory Error!\n");
- return NULL;
- }
-
- memcpy(newcdr, cdr, sizeof(*newcdr));
- /* The varshead is unusable, volatile even, after the memcpy so we take care of that here */
- memset(&newcdr->varshead, 0, sizeof(newcdr->varshead));
- ast_cdr_copy_vars(newcdr, cdr);
- newcdr->next = NULL;
-
- return newcdr;
-}
-
-static const char *ast_cdr_getvar_internal(struct ast_cdr *cdr, const char *name, int recur)
-{
- struct ast_var_t *variables;
- struct varshead *headp;
-
- if (ast_strlen_zero(name))
- return NULL;
-
- while (cdr) {
- headp = &cdr->varshead;
- AST_LIST_TRAVERSE(headp, variables, entries) {
- if (!strcasecmp(name, ast_var_name(variables)))
- return ast_var_value(variables);
- }
- if (!recur)
- break;
- cdr = cdr->next;
- }
-
- return NULL;
-}
-
-/*! CDR channel variable retrieval */
-void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur)
-{
- struct tm tm;
- time_t t;
- const char *fmt = "%Y-%m-%d %T";
- const char *varbuf;
-
- *ret = NULL;
- /* special vars (the ones from the struct ast_cdr when requested by name)
- I'd almost say we should convert all the stringed vals to vars */
-
- if (!strcasecmp(name, "clid"))
- ast_copy_string(workspace, cdr->clid, workspacelen);
- else if (!strcasecmp(name, "src"))
- ast_copy_string(workspace, cdr->src, workspacelen);
- else if (!strcasecmp(name, "dst"))
- ast_copy_string(workspace, cdr->dst, workspacelen);
- else if (!strcasecmp(name, "dcontext"))
- ast_copy_string(workspace, cdr->dcontext, workspacelen);
- else if (!strcasecmp(name, "channel"))
- ast_copy_string(workspace, cdr->channel, workspacelen);
- else if (!strcasecmp(name, "dstchannel"))
- ast_copy_string(workspace, cdr->dstchannel, workspacelen);
- else if (!strcasecmp(name, "lastapp"))
- ast_copy_string(workspace, cdr->lastapp, workspacelen);
- else if (!strcasecmp(name, "lastdata"))
- ast_copy_string(workspace, cdr->lastdata, workspacelen);
- else if (!strcasecmp(name, "start")) {
- t = cdr->start.tv_sec;
- if (t) {
- localtime_r(&t, &tm);
- strftime(workspace, workspacelen, fmt, &tm);
- }
- } else if (!strcasecmp(name, "answer")) {
- t = cdr->answer.tv_sec;
- if (t) {
- localtime_r(&t, &tm);
- strftime(workspace, workspacelen, fmt, &tm);
- }
- } else if (!strcasecmp(name, "end")) {
- t = cdr->end.tv_sec;
- if (t) {
- localtime_r(&t, &tm);
- strftime(workspace, workspacelen, fmt, &tm);
- }
- } else if (!strcasecmp(name, "duration"))
- snprintf(workspace, workspacelen, "%ld", cdr->duration);
- else if (!strcasecmp(name, "billsec"))
- snprintf(workspace, workspacelen, "%ld", cdr->billsec);
- else if (!strcasecmp(name, "disposition"))
- ast_copy_string(workspace, ast_cdr_disp2str(cdr->disposition), workspacelen);
- else if (!strcasecmp(name, "amaflags"))
- ast_copy_string(workspace, ast_cdr_flags2str(cdr->amaflags), workspacelen);
- else if (!strcasecmp(name, "accountcode"))
- ast_copy_string(workspace, cdr->accountcode, workspacelen);
- else if (!strcasecmp(name, "uniqueid"))
- ast_copy_string(workspace, cdr->uniqueid, workspacelen);
- else if (!strcasecmp(name, "userfield"))
- ast_copy_string(workspace, cdr->userfield, workspacelen);
- else if ((varbuf = ast_cdr_getvar_internal(cdr, name, recur)))
- ast_copy_string(workspace, varbuf, workspacelen);
-
- if (!ast_strlen_zero(workspace))
- *ret = workspace;
-}
-
-/*! Set a CDR channel variable
- \note You can't set the CDR variables that belong to the actual CDR record, like "billsec".
-*/
-int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur)
-{
- struct ast_var_t *newvariable;
- struct varshead *headp;
- const char *read_only[] = { "clid", "src", "dst", "dcontext", "channel", "dstchannel",
- "lastapp", "lastdata", "start", "answer", "end", "duration",
- "billsec", "disposition", "amaflags", "accountcode", "uniqueid",
- "userfield", NULL };
- int x;
-
- for(x = 0; read_only[x]; x++) {
- if (!strcasecmp(name, read_only[x])) {
- ast_log(LOG_ERROR, "Attempt to set a read-only variable!.\n");
- return -1;
- }
- }
-
- if (!cdr) {
- ast_log(LOG_ERROR, "Attempt to set a variable on a nonexistent CDR record.\n");
- return -1;
- }
-
- while (cdr) {
- headp = &cdr->varshead;
- AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
- if (!strcasecmp(ast_var_name(newvariable), name)) {
- /* there is already such a variable, delete it */
- AST_LIST_REMOVE_CURRENT(headp, entries);
- ast_var_delete(newvariable);
- break;
- }
- }
- AST_LIST_TRAVERSE_SAFE_END;
-
- if (value) {
- newvariable = ast_var_assign(name, value);
- AST_LIST_INSERT_HEAD(headp, newvariable, entries);
- }
-
- if (!recur) {
- break;
- }
-
- cdr = cdr->next;
- }
-
- return 0;
-}
-
-int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr)
-{
- struct ast_var_t *variables, *newvariable = NULL;
- struct varshead *headpa, *headpb;
- char *var, *val;
- int x = 0;
-
- headpa = &from_cdr->varshead;
- headpb = &to_cdr->varshead;
-
- AST_LIST_TRAVERSE(headpa,variables,entries) {
- if (variables &&
- (var = ast_var_name(variables)) && (val = ast_var_value(variables)) &&
- !ast_strlen_zero(var) && !ast_strlen_zero(val)) {
- newvariable = ast_var_assign(var, val);
- AST_LIST_INSERT_HEAD(headpb, newvariable, entries);
- x++;
- }
- }
-
- return x;
-}
-
-int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur)
-{
- struct ast_var_t *variables;
- char *var, *val;
- char *tmp;
- char workspace[256];
- int total = 0, x = 0, i;
- const char *cdrcols[] = {
- "clid",
- "src",
- "dst",
- "dcontext",
- "channel",
- "dstchannel",
- "lastapp",
- "lastdata",
- "start",
- "answer",
- "end",
- "duration",
- "billsec",
- "disposition",
- "amaflags",
- "accountcode",
- "uniqueid",
- "userfield"
- };
-
- memset(buf, 0, size);
-
- for (; cdr; cdr = recur ? cdr->next : NULL) {
- if (++x > 1)
- ast_build_string(&buf, &size, "\n");
-
- AST_LIST_TRAVERSE(&cdr->varshead, variables, entries) {
- if (variables &&
- (var = ast_var_name(variables)) && (val = ast_var_value(variables)) &&
- !ast_strlen_zero(var) && !ast_strlen_zero(val)) {
- if (ast_build_string(&buf, &size, "level %d: %s%c%s%c", x, var, delim, val, sep)) {
- ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
- break;
- } else
- total++;
- } else
- break;
- }
-
- for (i = 0; i < (sizeof(cdrcols) / sizeof(cdrcols[0])); i++) {
- ast_cdr_getvar(cdr, cdrcols[i], &tmp, workspace, sizeof(workspace), 0);
- if (!tmp)
- continue;
-
- if (ast_build_string(&buf, &size, "level %d: %s%c%s%c", x, cdrcols[i], delim, tmp, sep)) {
- ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
- break;
- } else
- total++;
- }
- }
-
- return total;
-}
-
-
-void ast_cdr_free_vars(struct ast_cdr *cdr, int recur)
-{
- struct varshead *headp;
- struct ast_var_t *vardata;
-
- /* clear variables */
- while (cdr) {
- headp = &cdr->varshead;
- while (!AST_LIST_EMPTY(headp)) {
- vardata = AST_LIST_REMOVE_HEAD(headp, entries);
- ast_var_delete(vardata);
- }
-
- if (!recur) {
- break;
- }
-
- cdr = cdr->next;
- }
-}
-
-void ast_cdr_free(struct ast_cdr *cdr)
-{
- char *chan;
- struct ast_cdr *next;
-
- while (cdr) {
- next = cdr->next;
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (!ast_test_flag(cdr, AST_CDR_FLAG_POSTED) && !ast_test_flag(cdr, AST_CDR_FLAG_POST_DISABLED))
- ast_log(LOG_WARNING, "CDR on channel '%s' not posted\n", chan);
- if (ast_tvzero(cdr->end))
- ast_log(LOG_WARNING, "CDR on channel '%s' lacks end\n", chan);
- if (ast_tvzero(cdr->start))
- ast_log(LOG_WARNING, "CDR on channel '%s' lacks start\n", chan);
-
- ast_cdr_free_vars(cdr, 0);
- free(cdr);
- cdr = next;
- }
-}
-
-struct ast_cdr *ast_cdr_alloc(void)
-{
- struct ast_cdr *cdr;
-
- cdr = malloc(sizeof(*cdr));
- if (cdr)
- memset(cdr, 0, sizeof(*cdr));
-
- return cdr;
-}
-
-void ast_cdr_start(struct ast_cdr *cdr)
-{
- char *chan;
-
- while (cdr) {
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED))
- ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
- if (!ast_tvzero(cdr->start))
- ast_log(LOG_WARNING, "CDR on channel '%s' already started\n", chan);
- cdr->start = ast_tvnow();
- }
- cdr = cdr->next;
- }
-}
-
-void ast_cdr_answer(struct ast_cdr *cdr)
-{
- char *chan;
-
- while (cdr) {
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED))
- ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
- if (cdr->disposition < AST_CDR_ANSWERED)
- cdr->disposition = AST_CDR_ANSWERED;
- if (ast_tvzero(cdr->answer))
- cdr->answer = ast_tvnow();
- cdr = cdr->next;
- }
-}
-
-void ast_cdr_busy(struct ast_cdr *cdr)
-{
- char *chan;
-
- while (cdr) {
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED))
- ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
- if (cdr->disposition < AST_CDR_BUSY)
- cdr->disposition = AST_CDR_BUSY;
- }
- cdr = cdr->next;
- }
-}
-
-void ast_cdr_failed(struct ast_cdr *cdr)
-{
- char *chan;
-
- while (cdr) {
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED))
- ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED))
- cdr->disposition = AST_CDR_FAILED;
- cdr = cdr->next;
- }
-}
-
-int ast_cdr_disposition(struct ast_cdr *cdr, int cause)
-{
- int res = 0;
-
- while (cdr) {
- switch(cause) {
- case AST_CAUSE_BUSY:
- ast_cdr_busy(cdr);
- break;
- case AST_CAUSE_FAILURE:
- ast_cdr_failed(cdr);
- break;
- case AST_CAUSE_NORMAL:
- break;
- case AST_CAUSE_NOTDEFINED:
- res = -1;
- break;
- default:
- res = -1;
- ast_log(LOG_WARNING, "Cause not handled\n");
- }
- cdr = cdr->next;
- }
- return res;
-}
-
-void ast_cdr_setdestchan(struct ast_cdr *cdr, char *chann)
-{
- char *chan;
-
- while (cdr) {
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED))
- ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED))
- ast_copy_string(cdr->dstchannel, chann, sizeof(cdr->dstchannel));
- cdr = cdr->next;
- }
-}
-
-void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data)
-{
- char *chan;
-
- while (cdr) {
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED))
- ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
- if (!app)
- app = "";
- ast_copy_string(cdr->lastapp, app, sizeof(cdr->lastapp));
- if (!data)
- data = "";
- ast_copy_string(cdr->lastdata, data, sizeof(cdr->lastdata));
- }
- cdr = cdr->next;
- }
-}
-
-int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *c)
-{
- char tmp[AST_MAX_EXTENSION] = "";
- char *num;
-
- while (cdr) {
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
- /* Grab source from ANI or normal Caller*ID */
- num = c->cid.cid_ani ? c->cid.cid_ani : c->cid.cid_num;
-
- if (c->cid.cid_name && num)
- snprintf(tmp, sizeof(tmp), "\"%s\" <%s>", c->cid.cid_name, num);
- else if (c->cid.cid_name)
- ast_copy_string(tmp, c->cid.cid_name, sizeof(tmp));
- else if (num)
- ast_copy_string(tmp, num, sizeof(tmp));
- ast_copy_string(cdr->clid, tmp, sizeof(cdr->clid));
- ast_copy_string(cdr->src, num ? num : "", sizeof(cdr->src));
- }
- cdr = cdr->next;
- }
-
- return 0;
-}
-
-
-int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *c)
-{
- char *chan;
- char *num;
- char tmp[AST_MAX_EXTENSION] = "";
-
- while (cdr) {
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (!ast_strlen_zero(cdr->channel))
- ast_log(LOG_WARNING, "CDR already initialized on '%s'\n", chan);
- ast_copy_string(cdr->channel, c->name, sizeof(cdr->channel));
- /* Grab source from ANI or normal Caller*ID */
- num = c->cid.cid_ani ? c->cid.cid_ani : c->cid.cid_num;
-
- if (c->cid.cid_name && num)
- snprintf(tmp, sizeof(tmp), "\"%s\" <%s>", c->cid.cid_name, num);
- else if (c->cid.cid_name)
- ast_copy_string(tmp, c->cid.cid_name, sizeof(tmp));
- else if (num)
- ast_copy_string(tmp, num, sizeof(tmp));
- ast_copy_string(cdr->clid, tmp, sizeof(cdr->clid));
- ast_copy_string(cdr->src, num ? num : "", sizeof(cdr->src));
-
- cdr->disposition = (c->_state == AST_STATE_UP) ? AST_CDR_ANSWERED : AST_CDR_NOANSWER;
- cdr->amaflags = c->amaflags ? c->amaflags : ast_default_amaflags;
- ast_copy_string(cdr->accountcode, c->accountcode, sizeof(cdr->accountcode));
- /* Destination information */
- ast_copy_string(cdr->dst, c->exten, sizeof(cdr->dst));
- ast_copy_string(cdr->dcontext, c->context, sizeof(cdr->dcontext));
- /* Unique call identifier */
- ast_copy_string(cdr->uniqueid, c->uniqueid, sizeof(cdr->uniqueid));
- }
- cdr = cdr->next;
- }
- return 0;
-}
-
-void ast_cdr_end(struct ast_cdr *cdr)
-{
- char *chan;
-
- while (cdr) {
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED))
- ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
- if (ast_tvzero(cdr->start))
- ast_log(LOG_WARNING, "CDR on channel '%s' has not started\n", chan);
- if (ast_tvzero(cdr->end))
- cdr->end = ast_tvnow();
- cdr = cdr->next;
- }
-}
-
-char *ast_cdr_disp2str(int disposition)
-{
- switch (disposition) {
- case AST_CDR_NOANSWER:
- return "NO ANSWER";
- case AST_CDR_FAILED:
- return "FAILED";
- case AST_CDR_BUSY:
- return "BUSY";
- case AST_CDR_ANSWERED:
- return "ANSWERED";
- }
- return "UNKNOWN";
-}
-
-/*! Converts AMA flag to printable string */
-char *ast_cdr_flags2str(int flag)
-{
- switch(flag) {
- case AST_CDR_OMIT:
- return "OMIT";
- case AST_CDR_BILLING:
- return "BILLING";
- case AST_CDR_DOCUMENTATION:
- return "DOCUMENTATION";
- }
- return "Unknown";
-}
-
-int ast_cdr_setaccount(struct ast_channel *chan, const char *account)
-{
- struct ast_cdr *cdr = chan->cdr;
-
- ast_copy_string(chan->accountcode, account, sizeof(chan->accountcode));
- while (cdr) {
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED))
- ast_copy_string(cdr->accountcode, chan->accountcode, sizeof(cdr->accountcode));
- cdr = cdr->next;
- }
- return 0;
-}
-
-int ast_cdr_setamaflags(struct ast_channel *chan, const char *flag)
-{
- struct ast_cdr *cdr;
- int newflag;
-
- newflag = ast_cdr_amaflags2int(flag);
- if (newflag) {
- for (cdr = chan->cdr; cdr; cdr = cdr->next) {
- cdr->amaflags = newflag;
- }
- }
-
- return 0;
-}
-
-int ast_cdr_setuserfield(struct ast_channel *chan, const char *userfield)
-{
- struct ast_cdr *cdr = chan->cdr;
-
- while (cdr) {
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED))
- ast_copy_string(cdr->userfield, userfield, sizeof(cdr->userfield));
- cdr = cdr->next;
- }
-
- return 0;
-}
-
-int ast_cdr_appenduserfield(struct ast_channel *chan, const char *userfield)
-{
- struct ast_cdr *cdr = chan->cdr;
-
- while (cdr) {
- int len = strlen(cdr->userfield);
-
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED))
- strncpy(cdr->userfield+len, userfield, sizeof(cdr->userfield) - len - 1);
-
- cdr = cdr->next;
- }
-
- return 0;
-}
-
-int ast_cdr_update(struct ast_channel *c)
-{
- struct ast_cdr *cdr = c->cdr;
- char *num;
- char tmp[AST_MAX_EXTENSION] = "";
-
- while (cdr) {
- if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
- num = c->cid.cid_ani ? c->cid.cid_ani : c->cid.cid_num;
-
- if (c->cid.cid_name && num)
- snprintf(tmp, sizeof(tmp), "\"%s\" <%s>", c->cid.cid_name, num);
- else if (c->cid.cid_name)
- ast_copy_string(tmp, c->cid.cid_name, sizeof(tmp));
- else if (num)
- ast_copy_string(tmp, num, sizeof(tmp));
- ast_copy_string(cdr->clid, tmp, sizeof(cdr->clid));
- ast_copy_string(cdr->src, num ? num : "", sizeof(cdr->src));
-
- /* Copy account code et-al */
- ast_copy_string(cdr->accountcode, c->accountcode, sizeof(cdr->accountcode));
- /* Destination information */
- ast_copy_string(cdr->dst, (ast_strlen_zero(c->macroexten)) ? c->exten : c->macroexten, sizeof(cdr->dst));
- ast_copy_string(cdr->dcontext, (ast_strlen_zero(c->macrocontext)) ? c->context : c->macrocontext, sizeof(cdr->dcontext));
- }
- cdr = cdr->next;
- }
-
- return 0;
-}
-
-int ast_cdr_amaflags2int(const char *flag)
-{
- if (!strcasecmp(flag, "default"))
- return 0;
- if (!strcasecmp(flag, "omit"))
- return AST_CDR_OMIT;
- if (!strcasecmp(flag, "billing"))
- return AST_CDR_BILLING;
- if (!strcasecmp(flag, "documentation"))
- return AST_CDR_DOCUMENTATION;
- return -1;
-}
-
-static void post_cdr(struct ast_cdr *cdr)
-{
- char *chan;
- struct ast_cdr_beitem *i;
-
- while (cdr) {
- chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
- if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED))
- ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
- if (ast_tvzero(cdr->end))
- ast_log(LOG_WARNING, "CDR on channel '%s' lacks end\n", chan);
- if (ast_tvzero(cdr->start))
- ast_log(LOG_WARNING, "CDR on channel '%s' lacks start\n", chan);
- cdr->duration = cdr->end.tv_sec - cdr->start.tv_sec + (cdr->end.tv_usec - cdr->start.tv_usec) / 1000000;
- if (!ast_tvzero(cdr->answer))
- cdr->billsec = cdr->end.tv_sec - cdr->answer.tv_sec + (cdr->end.tv_usec - cdr->answer.tv_usec) / 1000000;
- else
- cdr->billsec = 0;
- ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
- AST_LIST_LOCK(&be_list);
- AST_LIST_TRAVERSE(&be_list, i, list) {
- i->be(cdr);
- }
- AST_LIST_UNLOCK(&be_list);
- cdr = cdr->next;
- }
-}
-
-void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *_flags)
-{
- struct ast_cdr *dup;
- struct ast_flags flags = { 0 };
-
- if (_flags)
- ast_copy_flags(&flags, _flags, AST_FLAGS_ALL);
-
- while (cdr) {
- /* Detach if post is requested */
- if (ast_test_flag(&flags, AST_CDR_FLAG_LOCKED) || !ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
- if (ast_test_flag(&flags, AST_CDR_FLAG_POSTED)) {
- ast_cdr_end(cdr);
- if ((dup = ast_cdr_dup(cdr))) {
- ast_cdr_detach(dup);
- }
- ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
- }
-
- /* clear variables */
- if (!ast_test_flag(&flags, AST_CDR_FLAG_KEEP_VARS)) {
- ast_cdr_free_vars(cdr, 0);
- }
-
- /* Reset to initial state */
- ast_clear_flag(cdr, AST_FLAGS_ALL);
- memset(&cdr->start, 0, sizeof(cdr->start));
- memset(&cdr->end, 0, sizeof(cdr->end));
- memset(&cdr->answer, 0, sizeof(cdr->answer));
- cdr->billsec = 0;
- cdr->duration = 0;
- ast_cdr_start(cdr);
- cdr->disposition = AST_CDR_NOANSWER;
- }
-
- cdr = cdr->next;
- }
-}
-
-struct ast_cdr *ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr)
-{
- struct ast_cdr *ret;
-
- if (cdr) {
- ret = cdr;
-
- while (cdr->next)
- cdr = cdr->next;
- cdr->next = newcdr;
- } else {
- ret = newcdr;
- }
-
- return ret;
-}
-
-/*! \note Don't call without cdr_batch_lock */
-static void reset_batch(void)
-{
- batch->size = 0;
- batch->head = NULL;
- batch->tail = NULL;
-}
-
-/*! \note Don't call without cdr_batch_lock */
-static int init_batch(void)
-{
- /* This is the single meta-batch used to keep track of all CDRs during the entire life of the program */
- batch = malloc(sizeof(*batch));
- if (!batch) {
- ast_log(LOG_WARNING, "CDR: out of memory while trying to handle batched records, data will most likely be lost\n");
- return -1;
- }
-
- reset_batch();
-
- return 0;
-}
-
-static void *do_batch_backend_process(void *data)
-{
- struct ast_cdr_batch_item *processeditem;
- struct ast_cdr_batch_item *batchitem = data;
-
- /* Push each CDR into storage mechanism(s) and free all the memory */
- while (batchitem) {
- post_cdr(batchitem->cdr);
- ast_cdr_free(batchitem->cdr);
- processeditem = batchitem;
- batchitem = batchitem->next;
- free(processeditem);
- }
-
- return NULL;
-}
-
-void ast_cdr_submit_batch(int shutdown)
-{
- struct ast_cdr_batch_item *oldbatchitems = NULL;
- pthread_attr_t attr;
- pthread_t batch_post_thread = AST_PTHREADT_NULL;
-
- /* if there's no batch, or no CDRs in the batch, then there's nothing to do */
- if (!batch || !batch->head)
- return;
-
- /* move the old CDRs aside, and prepare a new CDR batch */
- ast_mutex_lock(&cdr_batch_lock);
- oldbatchitems = batch->head;
- reset_batch();
- ast_mutex_unlock(&cdr_batch_lock);
-
- /* if configured, spawn a new thread to post these CDRs,
- also try to save as much as possible if we are shutting down safely */
- if (batchscheduleronly || shutdown) {
- if (option_debug)
- ast_log(LOG_DEBUG, "CDR single-threaded batch processing begins now\n");
- do_batch_backend_process(oldbatchitems);
- } else {
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&batch_post_thread, &attr, do_batch_backend_process, oldbatchitems)) {
- ast_log(LOG_WARNING, "CDR processing thread could not detach, now trying in this thread\n");
- do_batch_backend_process(oldbatchitems);
- } else {
- if (option_debug)
- ast_log(LOG_DEBUG, "CDR multi-threaded batch processing begins now\n");
- }
- }
-}
-
-static int submit_scheduled_batch(void *data)
-{
- ast_cdr_submit_batch(0);
- /* manually reschedule from this point in time */
- cdr_sched = ast_sched_add(sched, batchtime * 1000, submit_scheduled_batch, NULL);
- /* returning zero so the scheduler does not automatically reschedule */
- return 0;
-}
-
-static void submit_unscheduled_batch(void)
-{
- /* this is okay since we are not being called from within the scheduler */
- if (cdr_sched > -1)
- ast_sched_del(sched, cdr_sched);
- /* schedule the submission to occur ASAP (1 ms) */
- cdr_sched = ast_sched_add(sched, 1, submit_scheduled_batch, NULL);
- /* signal the do_cdr thread to wakeup early and do some work (that lazy thread ;) */
- ast_mutex_lock(&cdr_pending_lock);
- ast_cond_signal(&cdr_pending_cond);
- ast_mutex_unlock(&cdr_pending_lock);
-}
-
-void ast_cdr_detach(struct ast_cdr *cdr)
-{
- struct ast_cdr_batch_item *newtail;
- int curr;
-
- /* maybe they disabled CDR stuff completely, so just drop it */
- if (!enabled) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Dropping CDR !\n");
- ast_set_flag(cdr, AST_CDR_FLAG_POST_DISABLED);
- ast_cdr_free(cdr);
- return;
- }
-
- /* post stuff immediately if we are not in batch mode, this is legacy behaviour */
- if (!batchmode) {
- post_cdr(cdr);
- ast_cdr_free(cdr);
- return;
- }
-
- /* otherwise, each CDR gets put into a batch list (at the end) */
- if (option_debug)
- ast_log(LOG_DEBUG, "CDR detaching from this thread\n");
-
- /* we'll need a new tail for every CDR */
- newtail = malloc(sizeof(*newtail));
- if (!newtail) {
- ast_log(LOG_WARNING, "CDR: out of memory while trying to detach, will try in this thread instead\n");
- post_cdr(cdr);
- ast_cdr_free(cdr);
- return;
- }
- memset(newtail, 0, sizeof(*newtail));
-
- /* don't traverse a whole list (just keep track of the tail) */
- ast_mutex_lock(&cdr_batch_lock);
- if (!batch)
- init_batch();
- if (!batch->head) {
- /* new batch is empty, so point the head at the new tail */
- batch->head = newtail;
- } else {
- /* already got a batch with something in it, so just append a new tail */
- batch->tail->next = newtail;
- }
- newtail->cdr = cdr;
- batch->tail = newtail;
- curr = batch->size++;
- ast_mutex_unlock(&cdr_batch_lock);
-
- /* if we have enough stuff to post, then do it */
- if (curr >= (batchsize - 1))
- submit_unscheduled_batch();
-}
-
-static void *do_cdr(void *data)
-{
- struct timespec timeout;
- int schedms;
- int numevents = 0;
-
- for(;;) {
- struct timeval now = ast_tvnow();
- schedms = ast_sched_wait(sched);
- /* this shouldn't happen, but provide a 1 second default just in case */
- if (schedms <= 0)
- schedms = 1000;
- timeout.tv_sec = now.tv_sec + (schedms / 1000);
- timeout.tv_nsec = (now.tv_usec * 1000) + ((schedms % 1000) * 1000);
- /* prevent stuff from clobbering cdr_pending_cond, then wait on signals sent to it until the timeout expires */
- ast_mutex_lock(&cdr_pending_lock);
- ast_cond_timedwait(&cdr_pending_cond, &cdr_pending_lock, &timeout);
- numevents = ast_sched_runq(sched);
- ast_mutex_unlock(&cdr_pending_lock);
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "Processed %d scheduled CDR batches from the run queue\n", numevents);
- }
-
- return NULL;
-}
-
-static int handle_cli_status(int fd, int argc, char *argv[])
-{
- struct ast_cdr_beitem *beitem=NULL;
- int cnt=0;
- long nextbatchtime=0;
-
- if (argc > 2)
- return RESULT_SHOWUSAGE;
-
- ast_cli(fd, "CDR logging: %s\n", enabled ? "enabled" : "disabled");
- ast_cli(fd, "CDR mode: %s\n", batchmode ? "batch" : "simple");
- if (enabled) {
- if (batchmode) {
- if (batch)
- cnt = batch->size;
- if (cdr_sched > -1)
- nextbatchtime = ast_sched_when(sched, cdr_sched);
- ast_cli(fd, "CDR safe shut down: %s\n", batchsafeshutdown ? "enabled" : "disabled");
- ast_cli(fd, "CDR batch threading model: %s\n", batchscheduleronly ? "scheduler only" : "scheduler plus separate threads");
- ast_cli(fd, "CDR current batch size: %d record%s\n", cnt, (cnt != 1) ? "s" : "");
- ast_cli(fd, "CDR maximum batch size: %d record%s\n", batchsize, (batchsize != 1) ? "s" : "");
- ast_cli(fd, "CDR maximum batch time: %d second%s\n", batchtime, (batchtime != 1) ? "s" : "");
- ast_cli(fd, "CDR next scheduled batch processing time: %ld second%s\n", nextbatchtime, (nextbatchtime != 1) ? "s" : "");
- }
- AST_LIST_LOCK(&be_list);
- AST_LIST_TRAVERSE(&be_list, beitem, list) {
- ast_cli(fd, "CDR registered backend: %s\n", beitem->name);
- }
- AST_LIST_UNLOCK(&be_list);
- }
-
- return 0;
-}
-
-static int handle_cli_submit(int fd, int argc, char *argv[])
-{
- if (argc > 2)
- return RESULT_SHOWUSAGE;
-
- submit_unscheduled_batch();
- ast_cli(fd, "Submitted CDRs to backend engines for processing. This may take a while.\n");
-
- return 0;
-}
-
-static struct ast_cli_entry cli_submit = {
- .cmda = { "cdr", "submit", NULL },
- .handler = handle_cli_submit,
- .summary = "Posts all pending batched CDR data",
- .usage =
- "Usage: cdr submit\n"
- " Posts all pending batched CDR data to the configured CDR backend engine modules.\n"
-};
-
-static struct ast_cli_entry cli_status = {
- .cmda = { "cdr", "status", NULL },
- .handler = handle_cli_status,
- .summary = "Display the CDR status",
- .usage =
- "Usage: cdr status\n"
- " Displays the Call Detail Record engine system status.\n"
-};
-
-static int do_reload(void)
-{
- struct ast_config *config;
- const char *enabled_value;
- const char *batched_value;
- const char *scheduleronly_value;
- const char *batchsafeshutdown_value;
- const char *size_value;
- const char *time_value;
- int cfg_size;
- int cfg_time;
- int was_enabled;
- int was_batchmode;
- int res=0;
-
- ast_mutex_lock(&cdr_batch_lock);
-
- batchsize = BATCH_SIZE_DEFAULT;
- batchtime = BATCH_TIME_DEFAULT;
- batchscheduleronly = BATCH_SCHEDULER_ONLY_DEFAULT;
- batchsafeshutdown = BATCH_SAFE_SHUTDOWN_DEFAULT;
- was_enabled = enabled;
- was_batchmode = batchmode;
- enabled = 1;
- batchmode = 0;
-
- /* don't run the next scheduled CDR posting while reloading */
- if (cdr_sched > -1)
- ast_sched_del(sched, cdr_sched);
-
- if ((config = ast_config_load("cdr.conf"))) {
- if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
- enabled = ast_true(enabled_value);
- }
- if ((batched_value = ast_variable_retrieve(config, "general", "batch"))) {
- batchmode = ast_true(batched_value);
- }
- if ((scheduleronly_value = ast_variable_retrieve(config, "general", "scheduleronly"))) {
- batchscheduleronly = ast_true(scheduleronly_value);
- }
- if ((batchsafeshutdown_value = ast_variable_retrieve(config, "general", "safeshutdown"))) {
- batchsafeshutdown = ast_true(batchsafeshutdown_value);
- }
- if ((size_value = ast_variable_retrieve(config, "general", "size"))) {
- if (sscanf(size_value, "%d", &cfg_size) < 1)
- ast_log(LOG_WARNING, "Unable to convert '%s' to a numeric value.\n", size_value);
- else if (size_value < 0)
- ast_log(LOG_WARNING, "Invalid maximum batch size '%d' specified, using default\n", cfg_size);
- else
- batchsize = cfg_size;
- }
- if ((time_value = ast_variable_retrieve(config, "general", "time"))) {
- if (sscanf(time_value, "%d", &cfg_time) < 1)
- ast_log(LOG_WARNING, "Unable to convert '%s' to a numeric value.\n", time_value);
- else if (time_value < 0)
- ast_log(LOG_WARNING, "Invalid maximum batch time '%d' specified, using default\n", cfg_time);
- else
- batchtime = cfg_time;
- }
- }
-
- if (enabled && !batchmode) {
- ast_log(LOG_NOTICE, "CDR simple logging enabled.\n");
- } else if (enabled && batchmode) {
- cdr_sched = ast_sched_add(sched, batchtime * 1000, submit_scheduled_batch, NULL);
- ast_log(LOG_NOTICE, "CDR batch mode logging enabled, first of either size %d or time %d seconds.\n", batchsize, batchtime);
- } else {
- ast_log(LOG_NOTICE, "CDR logging disabled, data will be lost.\n");
- }
-
- /* if this reload enabled the CDR batch mode, create the background thread
- if it does not exist */
- if (enabled && batchmode && (!was_enabled || !was_batchmode) && (cdr_thread == AST_PTHREADT_NULL)) {
- ast_cond_init(&cdr_pending_cond, NULL);
- if (ast_pthread_create(&cdr_thread, NULL, do_cdr, NULL) < 0) {
- ast_log(LOG_ERROR, "Unable to start CDR thread.\n");
- ast_sched_del(sched, cdr_sched);
- } else {
- ast_cli_register(&cli_submit);
- ast_register_atexit(ast_cdr_engine_term);
- res = 0;
- }
- /* if this reload disabled the CDR and/or batch mode and there is a background thread,
- kill it */
- } else if (((!enabled && was_enabled) || (!batchmode && was_batchmode)) && (cdr_thread != AST_PTHREADT_NULL)) {
- /* wake up the thread so it will exit */
- pthread_cancel(cdr_thread);
- pthread_kill(cdr_thread, SIGURG);
- pthread_join(cdr_thread, NULL);
- cdr_thread = AST_PTHREADT_NULL;
- ast_cond_destroy(&cdr_pending_cond);
- ast_cli_unregister(&cli_submit);
- ast_unregister_atexit(ast_cdr_engine_term);
- res = 0;
- /* if leaving batch mode, then post the CDRs in the batch,
- and don't reschedule, since we are stopping CDR logging */
- if (!batchmode && was_batchmode) {
- ast_cdr_engine_term();
- }
- } else {
- res = 0;
- }
-
- ast_mutex_unlock(&cdr_batch_lock);
- ast_config_destroy(config);
-
- return res;
-}
-
-int ast_cdr_engine_init(void)
-{
- int res;
-
- sched = sched_context_create();
- if (!sched) {
- ast_log(LOG_ERROR, "Unable to create schedule context.\n");
- return -1;
- }
-
- ast_cli_register(&cli_status);
-
- res = do_reload();
- if (res) {
- ast_mutex_lock(&cdr_batch_lock);
- res = init_batch();
- ast_mutex_unlock(&cdr_batch_lock);
- }
-
- return res;
-}
-
-/* \note This actually gets called a couple of times at shutdown. Once, before we start
- hanging up channels, and then again, after the channel hangup timeout expires */
-void ast_cdr_engine_term(void)
-{
- ast_cdr_submit_batch(batchsafeshutdown);
-}
-
-void ast_cdr_engine_reload(void)
-{
- do_reload();
-}
-
diff --git a/1.2-netsec/cdr/Makefile b/1.2-netsec/cdr/Makefile
deleted file mode 100644
index 3cd83f492..000000000
--- a/1.2-netsec/cdr/Makefile
+++ /dev/null
@@ -1,140 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Makefile for CDR backends (dynamically loaded)
-#
-# Copyright (C) 1999-2005, Digium
-#
-# Mark Spencer <markster@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-MODS=cdr_csv.so cdr_manager.so cdr_custom.so
-
-ifeq (${OSARCH},CYGWIN)
-CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
-CYGSOLIB=-L.. -L. -lasterisk.dll
-else
-CFLAGS+=-fPIC
-endif
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include
- SOLINK+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
-#This works for even old (2.96) versions of gcc and provides a small boost either way.
-#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.
-#So we go lowest common available by gcc and go a step down, still a step up from
-#the default as we now have a better instruction set to work with. - Belgarath
-ifeq ($(PROC),sparc64)
- PROC=ultrasparc
- CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
-endif
-
-#
-# unixODBC stuff...
-#
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),)
- MODS+=cdr_odbc.so
-endif
-
-#
-# FreeTDS stuff...
-#
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/tds.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/tds.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/include/freetds/tds.h),)
- ifeq ($(shell grep -s TDS_VERSION_NO $(CROSS_COMPILE_TARGET)/usr/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/local/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/include/freetds/tdsver.h | grep -c 0.63),1)
- CFLAGS += -DFREETDS_0_63
- else
- ifeq ($(shell grep -s TDS_VERSION_NO $(CROSS_COMPILE_TARGET)/usr/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/local/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/include/freetds/tdsver.h | grep -c 0.62),1)
- CFLAGS += -DFREETDS_0_62
- else
- CFLAGS += -DFREETDS_PRE_0_62
- endif
- endif
- MODS+=cdr_tds.so
-endif
-
-#
-# PGSQL stuff... Autoconf anyone??
-#
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/pgsql/include)$(wildcard $(CROSS_COMPILE_TARGET)/usr/include/pgsql)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/pgsql)$(wildcard $(CROSS_COMPILE_TARGET)/opt/pgsql/include)$(wildcard $(CROSS_COMPILE_TARGET)/usr/include/libpq-fe.h),)
- MODS+=cdr_pgsql.so
-endif
-
-MLFLAGS=
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql),)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/postgresql
- MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib/postgresql
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/pgsql/include),)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/pgsql/include
- MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/pgsql/lib
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/pgsql),)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/pgsql
- MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib/pgsql
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/pgsql),)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include/pgsql
- MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib/pgsql
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/opt/pgsql/include),)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/opt/pgsql/include
- MLFLAGS+=-L$(CROSS_COMPILE_TARGET) /opt/pgsql/lib
-endif
-
-ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql),)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/postgresql
-endif
-
-ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/lib/libpq.so),)
- MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib
-endif
-
-#
-# SQLite stuff...
-#
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sqlite.h),)
- MODS+=cdr_sqlite.so
-endif
-
-all: depend $(MODS)
-
-install: all
- for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
-
-clean:
- rm -f *.so *.o .depend
-
-%.so : %.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-cdr_odbc.so: cdr_odbc.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc $(MLFLAGS)
-
-cdr_tds.so: cdr_tds.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -ltds $(MLFLAGS)
-
-cdr_pgsql.so: cdr_pgsql.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lpq -lz $(MLFLAGS)
-
-cdr_sqlite.so: cdr_sqlite.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lsqlite $(MLFLAGS)
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
diff --git a/1.2-netsec/cdr/cdr_csv.c b/1.2-netsec/cdr/cdr_csv.c
deleted file mode 100644
index 457759053..000000000
--- a/1.2-netsec/cdr/cdr_csv.c
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Includes code and algorithms from the Zapata library.
- *
- * 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 Comma Separated Value CDR records.
- *
- * \arg See also \ref AstCDR
- * \ingroup cdr_drivers
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/cdr.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-
-#define CSV_LOG_DIR "/cdr-csv"
-#define CSV_MASTER "/Master.csv"
-
-#define DATE_FORMAT "%Y-%m-%d %T"
-
-/* #define CSV_LOGUNIQUEID 1 */
-/* #define CSV_LOGUSERFIELD 1 */
-
-/*----------------------------------------------------
- The values are as follows:
-
-
- "accountcode", accountcode is the account name of detail records, Master.csv contains all records *
- Detail records are configured on a channel basis, IAX and SIP are determined by user *
- Zap is determined by channel in zaptel.conf
- "source",
- "destination",
- "destination context",
- "callerid",
- "channel",
- "destination channel", (if applicable)
- "last application", Last application run on the channel
- "last app argument", argument to the last channel
- "start time",
- "answer time",
- "end time",
- duration, Duration is the whole length that the entire call lasted. ie. call rx'd to hangup
- "end time" minus "start time"
- billable seconds, the duration that a call was up after other end answered which will be <= to duration
- "end time" minus "answer time"
- "disposition", ANSWERED, NO ANSWER, BUSY
- "amaflags", DOCUMENTATION, BILL, IGNORE etc, specified on a per channel basis like accountcode.
- "uniqueid", unique call identifier
- "userfield" user field set via SetCDRUserField
-----------------------------------------------------------*/
-
-static char *desc = "Comma Separated Values CDR Backend";
-
-static char *name = "csv";
-
-static FILE *mf = NULL;
-
-static int append_string(char *buf, char *s, size_t bufsize)
-{
- int pos = strlen(buf);
- int spos = 0;
- int error = 0;
- if (pos >= bufsize - 4)
- return -1;
- buf[pos++] = '\"';
- error = -1;
- while(pos < bufsize - 3) {
- if (!s[spos]) {
- error = 0;
- break;
- }
- if (s[spos] == '\"')
- buf[pos++] = '\"';
- buf[pos++] = s[spos];
- spos++;
- }
- buf[pos++] = '\"';
- buf[pos++] = ',';
- buf[pos++] = '\0';
- return error;
-}
-
-static int append_int(char *buf, int s, size_t bufsize)
-{
- char tmp[32];
- int pos = strlen(buf);
- snprintf(tmp, sizeof(tmp), "%d", s);
- if (pos + strlen(tmp) > bufsize - 3)
- return -1;
- strncat(buf, tmp, bufsize - strlen(buf) - 1);
- pos = strlen(buf);
- buf[pos++] = ',';
- buf[pos++] = '\0';
- return 0;
-}
-
-static int append_date(char *buf, struct timeval tv, size_t bufsize)
-{
- char tmp[80] = "";
- struct tm tm;
- time_t t;
- t = tv.tv_sec;
- if (strlen(buf) > bufsize - 3)
- return -1;
- if (ast_tvzero(tv)) {
- strncat(buf, ",", bufsize - strlen(buf) - 1);
- return 0;
- }
- localtime_r(&t,&tm);
- strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
- return append_string(buf, tmp, bufsize);
-}
-
-static int build_csv_record(char *buf, size_t bufsize, struct ast_cdr *cdr)
-{
-
- buf[0] = '\0';
- /* Account code */
- append_string(buf, cdr->accountcode, bufsize);
- /* Source */
- append_string(buf, cdr->src, bufsize);
- /* Destination */
- append_string(buf, cdr->dst, bufsize);
- /* Destination context */
- append_string(buf, cdr->dcontext, bufsize);
- /* Caller*ID */
- append_string(buf, cdr->clid, bufsize);
- /* Channel */
- append_string(buf, cdr->channel, bufsize);
- /* Destination Channel */
- append_string(buf, cdr->dstchannel, bufsize);
- /* Last Application */
- append_string(buf, cdr->lastapp, bufsize);
- /* Last Data */
- append_string(buf, cdr->lastdata, bufsize);
- /* Start Time */
- append_date(buf, cdr->start, bufsize);
- /* Answer Time */
- append_date(buf, cdr->answer, bufsize);
- /* End Time */
- append_date(buf, cdr->end, bufsize);
- /* Duration */
- append_int(buf, cdr->duration, bufsize);
- /* Billable seconds */
- append_int(buf, cdr->billsec, bufsize);
- /* Disposition */
- append_string(buf, ast_cdr_disp2str(cdr->disposition), bufsize);
- /* AMA Flags */
- append_string(buf, ast_cdr_flags2str(cdr->amaflags), bufsize);
-
-#ifdef CSV_LOGUNIQUEID
- /* Unique ID */
- append_string(buf, cdr->uniqueid, bufsize);
-#endif
-#ifdef CSV_LOGUSERFIELD
- /* append the user field */
- append_string(buf, cdr->userfield,bufsize);
-#endif
- /* If we hit the end of our buffer, log an error */
- if (strlen(buf) < bufsize - 5) {
- /* Trim off trailing comma */
- buf[strlen(buf) - 1] = '\0';
- strncat(buf, "\n", bufsize - strlen(buf) - 1);
- return 0;
- }
- return -1;
-}
-
-static int writefile(char *s, char *acc)
-{
- char tmp[AST_CONFIG_MAX_PATH];
- FILE *f;
- if (strchr(acc, '/') || (acc[0] == '.')) {
- ast_log(LOG_WARNING, "Account code '%s' insecure for writing file\n", acc);
- return -1;
- }
- snprintf(tmp, sizeof(tmp), "%s/%s/%s.csv", (char *)ast_config_AST_LOG_DIR,CSV_LOG_DIR, acc);
- f = fopen(tmp, "a");
- if (!f)
- return -1;
- fputs(s, f);
- fflush(f);
- fclose(f);
- return 0;
-}
-
-
-static int csv_log(struct ast_cdr *cdr)
-{
- /* Make sure we have a big enough buf */
- char buf[1024];
- char csvmaster[AST_CONFIG_MAX_PATH];
- snprintf(csvmaster, sizeof(csvmaster),"%s/%s/%s", ast_config_AST_LOG_DIR, CSV_LOG_DIR, CSV_MASTER);
-#if 0
- printf("[CDR] %s ('%s' -> '%s') Dur: %ds Bill: %ds Disp: %s Flags: %s Account: [%s]\n", cdr->channel, cdr->src, cdr->dst, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), ast_cdr_flags2str(cdr->amaflags), cdr->accountcode);
-#endif
- if (build_csv_record(buf, sizeof(buf), cdr)) {
- ast_log(LOG_WARNING, "Unable to create CSV record in %d bytes. CDR not recorded!\n", (int)sizeof(buf));
- } else {
- /* because of the absolutely unconditional need for the
- highest reliability possible in writing billing records,
- we open write and close the log file each time */
- mf = fopen(csvmaster, "a");
- if (!mf) {
- ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", csvmaster, strerror(errno));
- }
- if (mf) {
- fputs(buf, mf);
- fflush(mf); /* be particularly anal here */
- fclose(mf);
- mf = NULL;
- }
- if (!ast_strlen_zero(cdr->accountcode)) {
- if (writefile(buf, cdr->accountcode))
- ast_log(LOG_WARNING, "Unable to write CSV record to account file '%s' : %s\n", cdr->accountcode, strerror(errno));
- }
- }
- return 0;
-}
-
-char *description(void)
-{
- return desc;
-}
-
-int unload_module(void)
-{
- if (mf)
- fclose(mf);
- ast_cdr_unregister(name);
- return 0;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_cdr_register(name, desc, csv_log);
- if (res) {
- ast_log(LOG_ERROR, "Unable to register CSV CDR handling\n");
- if (mf)
- fclose(mf);
- }
- return res;
-}
-
-int reload(void)
-{
- return 0;
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/cdr/cdr_custom.c b/1.2-netsec/cdr/cdr_custom.c
deleted file mode 100644
index 64fddb368..000000000
--- a/1.2-netsec/cdr/cdr_custom.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Includes code and algorithms from the Zapata library.
- *
- * 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 Custom Comma Separated Value CDR records.
- *
- * \arg See also \ref AstCDR
- *
- * Logs in LOG_DIR/cdr_custom
- * \ingroup cdr_drivers
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/cdr.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-
-#define CUSTOM_LOG_DIR "/cdr_custom"
-
-#define DATE_FORMAT "%Y-%m-%d %T"
-
-AST_MUTEX_DEFINE_STATIC(lock);
-
-static char *desc = "Customizable Comma Separated Values CDR Backend";
-
-static char *name = "cdr-custom";
-
-static FILE *mf = NULL;
-
-static char master[AST_CONFIG_MAX_PATH];
-static char format[1024]="";
-
-static int load_config(int reload)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
- int res = -1;
-
- strcpy(format, "");
- strcpy(master, "");
- if((cfg = ast_config_load("cdr_custom.conf"))) {
- var = ast_variable_browse(cfg, "mappings");
- while(var) {
- ast_mutex_lock(&lock);
- if (!ast_strlen_zero(var->name) && !ast_strlen_zero(var->value)) {
- if (strlen(var->value) > (sizeof(format) - 2))
- ast_log(LOG_WARNING, "Format string too long, will be truncated, at line %d\n", var->lineno);
- strncpy(format, var->value, sizeof(format) - 2);
- strcat(format,"\n");
- snprintf(master, sizeof(master),"%s/%s/%s", ast_config_AST_LOG_DIR, name, var->name);
- ast_mutex_unlock(&lock);
- } else
- ast_log(LOG_NOTICE, "Mapping must have both filename and format at line %d\n", var->lineno);
- if (var->next)
- ast_log(LOG_NOTICE, "Sorry, only one mapping is supported at this time, mapping '%s' will be ignored at line %d.\n", var->next->name, var->next->lineno);
- var = var->next;
- }
- ast_config_destroy(cfg);
- res = 0;
- } else {
- if (reload)
- ast_log(LOG_WARNING, "Failed to reload configuration file.\n");
- else
- ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
- }
-
- return res;
-}
-
-
-
-static int custom_log(struct ast_cdr *cdr)
-{
- /* Make sure we have a big enough buf */
- char buf[2048];
- struct ast_channel dummy;
-
- /* Abort if no master file is specified */
- if (ast_strlen_zero(master))
- return 0;
-
- memset(buf, 0 , sizeof(buf));
- /* Quite possibly the first use of a static struct ast_channel, we need it so the var funcs will work */
- memset(&dummy, 0, sizeof(dummy));
- dummy.cdr = cdr;
- pbx_substitute_variables_helper(&dummy, format, buf, sizeof(buf) - 1);
-
- /* because of the absolutely unconditional need for the
- highest reliability possible in writing billing records,
- we open write and close the log file each time */
- mf = fopen(master, "a");
- if (!mf) {
- ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", master, strerror(errno));
- }
- if (mf) {
- fputs(buf, mf);
- fflush(mf); /* be particularly anal here */
- fclose(mf);
- mf = NULL;
- }
- return 0;
-}
-
-char *description(void)
-{
- return desc;
-}
-
-int unload_module(void)
-{
- if (mf)
- fclose(mf);
- ast_cdr_unregister(name);
- return 0;
-}
-
-int load_module(void)
-{
- int res = 0;
-
- if (!load_config(0)) {
- res = ast_cdr_register(name, desc, custom_log);
- if (res)
- ast_log(LOG_ERROR, "Unable to register custom CDR handling\n");
- if (mf)
- fclose(mf);
- }
- return res;
-}
-
-int reload(void)
-{
- return load_config(1);
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/cdr/cdr_manager.c b/1.2-netsec/cdr/cdr_manager.c
deleted file mode 100644
index cd43c12be..000000000
--- a/1.2-netsec/cdr/cdr_manager.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005
- *
- * 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 Asterisk Call Manager CDR records.
- *
- * See also
- * \arg \ref AstCDR
- * \arg \ref AstAMI
- * \arg \ref Config_ami
- * \ingroup cdr_drivers
- */
-
-#include <sys/types.h>
-#include <strings.h>
-#include <unistd.h>
-#include <time.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/cdr.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/manager.h"
-#include "asterisk/config.h"
-
-#define DATE_FORMAT "%Y-%m-%d %T"
-#define CONF_FILE "cdr_manager.conf"
-
-static char *desc = "Asterisk Call Manager CDR Backend";
-static char *name = "cdr_manager";
-
-static int enablecdr = 0;
-
-static void loadconfigurationfile(void)
-{
- char *cat;
- struct ast_config *cfg;
- struct ast_variable *v;
-
- cfg = ast_config_load(CONF_FILE);
- if (!cfg) {
- /* Standard configuration */
- enablecdr = 0;
- return;
- }
-
- cat = ast_category_browse(cfg, NULL);
- while (cat) {
- if (!strcasecmp(cat, "general")) {
- v = ast_variable_browse(cfg, cat);
- while (v) {
- if (!strcasecmp(v->name, "enabled")) {
- enablecdr = ast_true(v->value);
- }
-
- v = v->next;
- }
- }
-
- /* Next category */
- cat = ast_category_browse(cfg, cat);
- }
-
- ast_config_destroy(cfg);
-}
-
-static int manager_log(struct ast_cdr *cdr)
-{
- time_t t;
- struct tm timeresult;
- char strStartTime[80] = "";
- char strAnswerTime[80] = "";
- char strEndTime[80] = "";
-
- if (!enablecdr)
- return 0;
-
- t = cdr->start.tv_sec;
- localtime_r(&t, &timeresult);
- strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
-
- if (cdr->answer.tv_sec) {
- t = cdr->answer.tv_sec;
- localtime_r(&t, &timeresult);
- strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
- }
-
- t = cdr->end.tv_sec;
- localtime_r(&t, &timeresult);
- strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
-
- manager_event(EVENT_FLAG_CALL, "Cdr",
- "AccountCode: %s\r\n"
- "Source: %s\r\n"
- "Destination: %s\r\n"
- "DestinationContext: %s\r\n"
- "CallerID: %s\r\n"
- "Channel: %s\r\n"
- "DestinationChannel: %s\r\n"
- "LastApplication: %s\r\n"
- "LastData: %s\r\n"
- "StartTime: %s\r\n"
- "AnswerTime: %s\r\n"
- "EndTime: %s\r\n"
- "Duration: %ld\r\n"
- "BillableSeconds: %ld\r\n"
- "Disposition: %s\r\n"
- "AMAFlags: %s\r\n"
- "UniqueID: %s\r\n"
- "UserField: %s\r\n",
- cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel,
- cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime,
- cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition),
- ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield);
-
- return 0;
-}
-
-char *description(void)
-{
- return desc;
-}
-
-int unload_module(void)
-{
- ast_cdr_unregister(name);
- return 0;
-}
-
-int load_module(void)
-{
- int res;
-
- /* Configuration file */
- loadconfigurationfile();
-
- res = ast_cdr_register(name, desc, manager_log);
- if (res) {
- ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n");
- }
-
- return res;
-}
-
-int reload(void)
-{
- loadconfigurationfile();
- return 0;
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/cdr/cdr_odbc.c b/1.2-netsec/cdr/cdr_odbc.c
deleted file mode 100644
index f9a46c1f3..000000000
--- a/1.2-netsec/cdr/cdr_odbc.c
+++ /dev/null
@@ -1,483 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2003-2005, Digium, Inc.
- *
- * Brian K. West <brian@bkw.org>
- *
- * 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 ODBC CDR Backend
- *
- * \author Brian K. West <brian@bkw.org>
- *
- * See also:
- * \arg http://www.unixodbc.org
- * \arg \ref Config_cdr
- * \ingroup cdr_drivers
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-
-#ifndef __CYGWIN__
-#include <sql.h>
-#include <sqlext.h>
-#include <sqltypes.h>
-#else
-#include <windows.h>
-#include <w32api/sql.h>
-#include <w32api/sqlext.h>
-#include <w32api/sqltypes.h>
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/cdr.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-
-#define DATE_FORMAT "%Y-%m-%d %T"
-
-static char *desc = "ODBC CDR Backend";
-static char *name = "ODBC";
-static char *config = "cdr_odbc.conf";
-static char *dsn = NULL, *username = NULL, *password = NULL, *table = NULL;
-static int loguniqueid = 0;
-static int usegmtime = 0;
-static int dispositionstring = 0;
-static int connected = 0;
-
-AST_MUTEX_DEFINE_STATIC(odbc_lock);
-
-static int odbc_do_query(void);
-static int odbc_init(void);
-
-static SQLHENV ODBC_env = SQL_NULL_HANDLE; /* global ODBC Environment */
-static SQLHDBC ODBC_con; /* global ODBC Connection Handle */
-static SQLHSTMT ODBC_stmt; /* global ODBC Statement Handle */
-
-static int odbc_log(struct ast_cdr *cdr)
-{
- SQLINTEGER ODBC_err;
- short int ODBC_mlen;
- int ODBC_res;
- char ODBC_msg[200], ODBC_stat[10];
- char sqlcmd[2048] = "", timestr[128];
- int res = 0;
- struct tm tm;
-
- if (usegmtime)
- gmtime_r(&cdr->start.tv_sec,&tm);
- else
- localtime_r(&cdr->start.tv_sec,&tm);
-
- ast_mutex_lock(&odbc_lock);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
- memset(sqlcmd,0,2048);
- if (loguniqueid) {
- snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
- "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,"
- "lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) "
- "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table);
- } else {
- snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
- "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,"
- "duration,billsec,disposition,amaflags,accountcode) "
- "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table);
- }
-
- if (!connected) {
- res = odbc_init();
- if (res < 0) {
- connected = 0;
- ast_mutex_unlock(&odbc_lock);
- return 0;
- }
- }
-
- ODBC_res = SQLAllocHandle(SQL_HANDLE_STMT, ODBC_con, &ODBC_stmt);
-
- if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Failure in AllocStatement %d\n", ODBC_res);
- SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_con, 1, (unsigned char *)ODBC_stat, &ODBC_err, (unsigned char *)ODBC_msg, 100, &ODBC_mlen);
- SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
- connected = 0;
- ast_mutex_unlock(&odbc_lock);
- return 0;
- }
-
- /* We really should only have to do this once. But for some
- strange reason if I don't it blows holes in memory like
- like a shotgun. So we just do this so its safe. */
-
- ODBC_res = SQLPrepare(ODBC_stmt, (unsigned char *)sqlcmd, SQL_NTS);
-
- if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in PREPARE %d\n", ODBC_res);
- SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_con, 1, (unsigned char *)ODBC_stat, &ODBC_err, (unsigned char *)ODBC_msg, 100, &ODBC_mlen);
- SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
- connected = 0;
- ast_mutex_unlock(&odbc_lock);
- return 0;
- }
-
- SQLBindParameter(ODBC_stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(timestr), 0, &timestr, 0, NULL);
- SQLBindParameter(ODBC_stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->clid), 0, cdr->clid, 0, NULL);
- SQLBindParameter(ODBC_stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->src), 0, cdr->src, 0, NULL);
- SQLBindParameter(ODBC_stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dst), 0, cdr->dst, 0, NULL);
- SQLBindParameter(ODBC_stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dcontext), 0, cdr->dcontext, 0, NULL);
- SQLBindParameter(ODBC_stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->channel), 0, cdr->channel, 0, NULL);
- SQLBindParameter(ODBC_stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dstchannel), 0, cdr->dstchannel, 0, NULL);
- SQLBindParameter(ODBC_stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->lastapp), 0, cdr->lastapp, 0, NULL);
- SQLBindParameter(ODBC_stmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->lastdata), 0, cdr->lastdata, 0, NULL);
- SQLBindParameter(ODBC_stmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->duration, 0, NULL);
- SQLBindParameter(ODBC_stmt, 11, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->billsec, 0, NULL);
- if (dispositionstring)
- SQLBindParameter(ODBC_stmt, 12, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(ast_cdr_disp2str(cdr->disposition)) + 1, 0, ast_cdr_disp2str(cdr->disposition), 0, NULL);
- else
- SQLBindParameter(ODBC_stmt, 12, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->disposition, 0, NULL);
- SQLBindParameter(ODBC_stmt, 13, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->amaflags, 0, NULL);
- SQLBindParameter(ODBC_stmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->accountcode), 0, cdr->accountcode, 0, NULL);
-
- if (loguniqueid) {
- SQLBindParameter(ODBC_stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->uniqueid), 0, cdr->uniqueid, 0, NULL);
- SQLBindParameter(ODBC_stmt, 16, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->userfield), 0, cdr->userfield, 0, NULL);
- }
-
- if (connected) {
- res = odbc_do_query();
- if (res < 0) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
- res = odbc_init();
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Reconnecting to dsn %s\n", dsn);
- if (res < 0) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: %s has gone away!\n", dsn);
- connected = 0;
- } else {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Trying Query again!\n");
- res = odbc_do_query();
- if (res < 0) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
- }
- }
- }
- } else {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
- }
- SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
- ast_mutex_unlock(&odbc_lock);
- return 0;
-}
-
-char *description(void)
-{
- return desc;
-}
-
-static int odbc_unload_module(void)
-{
- ast_mutex_lock(&odbc_lock);
- if (connected) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Disconnecting from %s\n", dsn);
- SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
- SQLDisconnect(ODBC_con);
- SQLFreeHandle(SQL_HANDLE_DBC, ODBC_con);
- SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
- connected = 0;
- }
- if (dsn) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free dsn\n");
- free(dsn);
- }
- if (username) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free username\n");
- free(username);
- }
- if (password) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free password\n");
- free(password);
- }
- if (table) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free table\n");
- free(table);
- }
-
- ast_cdr_unregister(name);
- ast_mutex_unlock(&odbc_lock);
- return 0;
-}
-
-static int odbc_load_module(void)
-{
- int res = 0;
- struct ast_config *cfg;
- struct ast_variable *var;
- char *tmp;
-
- ast_mutex_lock(&odbc_lock);
-
- cfg = ast_config_load(config);
- if (!cfg) {
- ast_log(LOG_WARNING, "cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config);
- goto out;
- }
-
- var = ast_variable_browse(cfg, "global");
- if (!var) {
- /* nothing configured */
- goto out;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","dsn");
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"cdr_odbc: dsn not specified. Assuming asteriskdb\n");
- tmp = "asteriskdb";
- }
- dsn = strdup(tmp);
- if (dsn == NULL) {
- ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
- res = -1;
- goto out;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","dispositionstring");
- if (tmp) {
- dispositionstring = ast_true(tmp);
- } else {
- dispositionstring = 0;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","username");
- if (tmp) {
- username = strdup(tmp);
- if (username == NULL) {
- ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
- res = -1;
- goto out;
- }
- }
-
- tmp = ast_variable_retrieve(cfg,"global","password");
- if (tmp) {
- password = strdup(tmp);
- if (password == NULL) {
- ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
- res = -1;
- goto out;
- }
- }
-
- tmp = ast_variable_retrieve(cfg,"global","loguniqueid");
- if (tmp) {
- loguniqueid = ast_true(tmp);
- if (loguniqueid) {
- ast_log(LOG_DEBUG,"cdr_odbc: Logging uniqueid\n");
- } else {
- ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
- }
- } else {
- ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
- loguniqueid = 0;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","usegmtime");
- if (tmp) {
- usegmtime = ast_true(tmp);
- if (usegmtime) {
- ast_log(LOG_DEBUG,"cdr_odbc: Logging in GMT\n");
- } else {
- ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n");
- }
- } else {
- ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n");
- usegmtime = 0;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","table");
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"cdr_odbc: table not specified. Assuming cdr\n");
- tmp = "cdr";
- }
- table = strdup(tmp);
- if (table == NULL) {
- ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
- res = -1;
- goto out;
- }
-
- ast_config_destroy(cfg);
- if (option_verbose > 2) {
- ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: dsn is %s\n",dsn);
- if (username)
- {
- ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: username is %s\n",username);
- ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: password is [secret]\n");
- }
- else
- ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: retreiving username and password from odbc config\n");
- ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: table is %s\n",table);
- }
-
- res = odbc_init();
- if (res < 0) {
- ast_log(LOG_ERROR, "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
- if (option_verbose > 2) {
- ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
- }
- }
- res = ast_cdr_register(name, desc, odbc_log);
- if (res) {
- ast_log(LOG_ERROR, "cdr_odbc: Unable to register ODBC CDR handling\n");
- }
-out:
- ast_mutex_unlock(&odbc_lock);
- return res;
-}
-
-static int odbc_do_query(void)
-{
- SQLINTEGER ODBC_err;
- int ODBC_res;
- short int ODBC_mlen;
- char ODBC_msg[200], ODBC_stat[10];
-
- ODBC_res = SQLExecute(ODBC_stmt);
-
- if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in Query %d\n", ODBC_res);
- SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_con, 1, (unsigned char *)ODBC_stat, &ODBC_err, (unsigned char *)ODBC_msg, 100, &ODBC_mlen);
- SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
- connected = 0;
- return -1;
- } else {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query Successful!\n");
- connected = 1;
- }
- return 0;
-}
-
-static int odbc_init(void)
-{
- SQLINTEGER ODBC_err;
- short int ODBC_mlen;
- int ODBC_res;
- char ODBC_msg[200], ODBC_stat[10];
-
- if (ODBC_env == SQL_NULL_HANDLE || connected == 0) {
- ODBC_res = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &ODBC_env);
- if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error AllocHandle\n");
- connected = 0;
- return -1;
- }
-
- ODBC_res = SQLSetEnvAttr(ODBC_env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
-
- if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error SetEnv\n");
- SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
- connected = 0;
- return -1;
- }
-
- ODBC_res = SQLAllocHandle(SQL_HANDLE_DBC, ODBC_env, &ODBC_con);
-
- if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error AllocHDB %d\n", ODBC_res);
- SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
- connected = 0;
- return -1;
- }
- SQLSetConnectAttr(ODBC_con, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)10, 0);
- }
-
- /* Note that the username and password could be NULL here, but that is allowed in ODBC.
- In this case, the default username and password will be used from odbc.conf */
- ODBC_res = SQLConnect(ODBC_con, (SQLCHAR*)dsn, SQL_NTS, (SQLCHAR*)username, SQL_NTS, (SQLCHAR*)password, SQL_NTS);
-
- if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error SQLConnect %d\n", ODBC_res);
- SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_con, 1, (unsigned char *)ODBC_stat, &ODBC_err, (unsigned char *)ODBC_msg, 100, &ODBC_mlen);
- SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
- connected = 0;
- return -1;
- } else {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Connected to %s\n", dsn);
- connected = 1;
- }
- return 0;
-}
-
-int load_module(void)
-{
- return odbc_load_module();
-}
-
-int unload_module(void)
-{
- return odbc_unload_module();
-}
-
-int reload(void)
-{
- odbc_unload_module();
- return odbc_load_module();
-}
-
-int usecount(void)
-{
- /* Simplistic use count */
- if (ast_mutex_trylock(&odbc_lock)) {
- return 1;
- } else {
- ast_mutex_unlock(&odbc_lock);
- return 0;
- }
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/cdr/cdr_pgsql.c b/1.2-netsec/cdr/cdr_pgsql.c
deleted file mode 100644
index 776bf6a54..000000000
--- a/1.2-netsec/cdr/cdr_pgsql.c
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2003 - 2005
- *
- * Matthew D. Hardeman <mhardemn@papersoft.com>
- * Adapted from the MySQL CDR logger originally by James Sharp
- *
- * Modified September 2003
- * Matthew D. Hardeman <mhardemn@papersoft.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief PostgreSQL CDR logger
- *
- * \author Matthew D. Hardeman <mhardemn@papersoft.com>
- *
- * See also
- * \arg \ref Config_cdr
- * \arg http://www.postgresql.org/
- * \ingroup cdr_drivers
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-
-#include <libpq-fe.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/cdr.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk.h"
-
-#define DATE_FORMAT "%Y-%m-%d %T"
-
-static char *desc = "PostgreSQL CDR Backend";
-static char *name = "pgsql";
-static char *config = "cdr_pgsql.conf";
-static char *pghostname = NULL, *pgdbname = NULL, *pgdbuser = NULL, *pgpassword = NULL, *pgdbsock = NULL, *pgdbport = NULL, *table = NULL;
-static int connected = 0;
-
-AST_MUTEX_DEFINE_STATIC(pgsql_lock);
-
-PGconn *conn;
-PGresult *result;
-
-static int pgsql_log(struct ast_cdr *cdr)
-{
- struct tm tm;
- char sqlcmd[2048] = "", timestr[128];
- char *pgerror;
-
- ast_mutex_lock(&pgsql_lock);
-
- localtime_r(&cdr->start.tv_sec,&tm);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
-
- if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
- conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
- if (PQstatus(conn) != CONNECTION_BAD) {
- connected = 1;
- } else {
- pgerror = PQerrorMessage(conn);
- ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s. Calls will not be logged!\n", pghostname);
- ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
- }
- }
-
- if (connected) {
- char *clid=NULL, *dcontext=NULL, *channel=NULL, *dstchannel=NULL, *lastapp=NULL, *lastdata=NULL;
- char *uniqueid=NULL, *userfield=NULL;
-
- /* Maximum space needed would be if all characters needed to be escaped, plus a trailing NULL */
- if ((clid = alloca(strlen(cdr->clid) * 2 + 1)) != NULL)
- PQescapeString(clid, cdr->clid, strlen(cdr->clid));
- if ((dcontext = alloca(strlen(cdr->dcontext) * 2 + 1)) != NULL)
- PQescapeString(dcontext, cdr->dcontext, strlen(cdr->dcontext));
- if ((channel = alloca(strlen(cdr->channel) * 2 + 1)) != NULL)
- PQescapeString(channel, cdr->channel, strlen(cdr->channel));
- if ((dstchannel = alloca(strlen(cdr->dstchannel) * 2 + 1)) != NULL)
- PQescapeString(dstchannel, cdr->dstchannel, strlen(cdr->dstchannel));
- if ((lastapp = alloca(strlen(cdr->lastapp) * 2 + 1)) != NULL)
- PQescapeString(lastapp, cdr->lastapp, strlen(cdr->lastapp));
- if ((lastdata = alloca(strlen(cdr->lastdata) * 2 + 1)) != NULL)
- PQescapeString(lastdata, cdr->lastdata, strlen(cdr->lastdata));
- if ((uniqueid = alloca(strlen(cdr->uniqueid) * 2 + 1)) != NULL)
- PQescapeString(uniqueid, cdr->uniqueid, strlen(cdr->uniqueid));
- if ((userfield = alloca(strlen(cdr->userfield) * 2 + 1)) != NULL)
- PQescapeString(userfield, cdr->userfield, strlen(cdr->userfield));
-
- /* Check for all alloca failures above at once */
- if ((!clid) || (!dcontext) || (!channel) || (!dstchannel) || (!lastapp) || (!lastdata) || (!uniqueid) || (!userfield)) {
- ast_log(LOG_ERROR, "cdr_pgsql: Out of memory error (insert fails)\n");
- ast_mutex_unlock(&pgsql_lock);
- return -1;
- }
-
- ast_log(LOG_DEBUG,"cdr_pgsql: inserting a CDR record.\n");
-
- snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s (calldate,clid,src,dst,dcontext,channel,dstchannel,"
- "lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) VALUES"
- " ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s','%s')",
- table,timestr,clid,cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata,
- cdr->duration,cdr->billsec,ast_cdr_disp2str(cdr->disposition),cdr->amaflags, cdr->accountcode, uniqueid, userfield);
-
- ast_log(LOG_DEBUG,"cdr_pgsql: SQL command executed: %s\n",sqlcmd);
-
- /* Test to be sure we're still connected... */
- /* If we're connected, and connection is working, good. */
- /* Otherwise, attempt reconnect. If it fails... sorry... */
- if (PQstatus(conn) == CONNECTION_OK) {
- connected = 1;
- } else {
- ast_log(LOG_ERROR, "cdr_pgsql: Connection was lost... attempting to reconnect.\n");
- PQreset(conn);
- if (PQstatus(conn) == CONNECTION_OK) {
- ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n");
- connected = 1;
- } else {
- pgerror = PQerrorMessage(conn);
- ast_log(LOG_ERROR, "cdr_pgsql: Unable to reconnect to database server %s. Calls will not be logged!\n", pghostname);
- ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
- connected = 0;
- ast_mutex_unlock(&pgsql_lock);
- return -1;
- }
- }
- result = PQexec(conn, sqlcmd);
- if ( PQresultStatus(result) != PGRES_COMMAND_OK) {
- pgerror = PQresultErrorMessage(result);
- ast_log(LOG_ERROR,"cdr_pgsql: Failed to insert call detail record into database!\n");
- ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
- ast_log(LOG_ERROR,"cdr_pgsql: Connection may have been lost... attempting to reconnect.\n");
- PQreset(conn);
- if (PQstatus(conn) == CONNECTION_OK) {
- ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n");
- connected = 1;
- result = PQexec(conn, sqlcmd);
- if ( PQresultStatus(result) != PGRES_COMMAND_OK)
- {
- pgerror = PQresultErrorMessage(result);
- ast_log(LOG_ERROR,"cdr_pgsql: HARD ERROR! Attempted reconnection failed. DROPPING CALL RECORD!\n");
- ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
- }
- }
- ast_mutex_unlock(&pgsql_lock);
- return -1;
- }
- }
- ast_mutex_unlock(&pgsql_lock);
- return 0;
-}
-
-char *description(void)
-{
- return desc;
-}
-
-static int my_unload_module(void)
-{
- if (conn)
- PQfinish(conn);
- if (pghostname)
- free(pghostname);
- if (pgdbname)
- free(pgdbname);
- if (pgdbuser)
- free(pgdbuser);
- if (pgdbsock)
- free(pgdbsock);
- if (pgpassword)
- free(pgpassword);
- if (pgdbport)
- free(pgdbport);
- if (table)
- free(table);
- ast_cdr_unregister(name);
- return 0;
-}
-
-static int process_my_load_module(struct ast_config *cfg)
-{
- int res;
- struct ast_variable *var;
- char *pgerror;
- char *tmp;
-
- var = ast_variable_browse(cfg, "global");
- if (!var) {
- /* nothing configured */
- return 0;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","hostname");
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"PostgreSQL server hostname not specified. Assuming localhost\n");
- tmp = "localhost";
- }
- pghostname = strdup(tmp);
- if (pghostname == NULL) {
- ast_log(LOG_ERROR,"Out of memory error.\n");
- return -1;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","dbname");
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"PostgreSQL database not specified. Assuming asterisk\n");
- tmp = "asteriskcdrdb";
- }
- pgdbname = strdup(tmp);
- if (pgdbname == NULL) {
- ast_log(LOG_ERROR,"Out of memory error.\n");
- return -1;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","user");
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"PostgreSQL database user not specified. Assuming root\n");
- tmp = "root";
- }
- pgdbuser = strdup(tmp);
- if (pgdbuser == NULL) {
- ast_log(LOG_ERROR,"Out of memory error.\n");
- return -1;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","password");
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"PostgreSQL database password not specified. Assuming blank\n");
- tmp = "";
- }
- pgpassword = strdup(tmp);
- if (pgpassword == NULL) {
- ast_log(LOG_ERROR,"Out of memory error.\n");
- return -1;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","port");
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"PostgreSQL database port not specified. Using default 5432.\n");
- tmp = "5432";
- }
- pgdbport = strdup(tmp);
- if (pgdbport == NULL) {
- ast_log(LOG_ERROR,"Out of memory error.\n");
- return -1;
- }
-
- tmp = ast_variable_retrieve(cfg,"global","table");
- if (tmp == NULL) {
- ast_log(LOG_WARNING,"CDR table not specified. Assuming cdr\n");
- tmp = "cdr";
- }
- table = strdup(tmp);
- if (table == NULL) {
- ast_log(LOG_ERROR,"Out of memory error.\n");
- return -1;
- }
-
- ast_log(LOG_DEBUG,"cdr_pgsql: got hostname of %s\n",pghostname);
- ast_log(LOG_DEBUG,"cdr_pgsql: got port of %s\n",pgdbport);
- if (pgdbsock)
- ast_log(LOG_DEBUG,"cdr_pgsql: got sock file of %s\n",pgdbsock);
- ast_log(LOG_DEBUG,"cdr_pgsql: got user of %s\n",pgdbuser);
- ast_log(LOG_DEBUG,"cdr_pgsql: got dbname of %s\n",pgdbname);
- ast_log(LOG_DEBUG,"cdr_pgsql: got password of %s\n",pgpassword);
- ast_log(LOG_DEBUG,"cdr_pgsql: got sql table name of %s\n",table);
-
- conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
- if (PQstatus(conn) != CONNECTION_BAD) {
- ast_log(LOG_DEBUG,"Successfully connected to PostgreSQL database.\n");
- connected = 1;
- } else {
- pgerror = PQerrorMessage(conn);
- ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s. CALLS WILL NOT BE LOGGED!!\n", pghostname);
- ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
- connected = 0;
- }
-
- res = ast_cdr_register(name, desc, pgsql_log);
- if (res) {
- ast_log(LOG_ERROR, "Unable to register PGSQL CDR handling\n");
- }
- return res;
-}
-
-static int my_load_module(void)
-{
- struct ast_config *cfg;
- int res;
- cfg = ast_config_load(config);
- if (!cfg) {
- ast_log(LOG_WARNING, "Unable to load config for PostgreSQL CDR's: %s\n", config);
- return 0;
- }
- res = process_my_load_module(cfg);
- ast_config_destroy(cfg);
- return res;
-}
-
-int load_module(void)
-{
- return my_load_module();
-}
-
-int unload_module(void)
-{
- return my_unload_module();
-}
-
-int reload(void)
-{
- my_unload_module();
- return my_load_module();
-}
-
-int usecount(void)
-{
- /* To be able to unload the module */
- if ( ast_mutex_trylock(&pgsql_lock) ) {
- return 1;
- } else {
- ast_mutex_unlock(&pgsql_lock);
- return 0;
- }
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/cdr/cdr_sqlite.c b/1.2-netsec/cdr/cdr_sqlite.c
deleted file mode 100644
index 33410229f..000000000
--- a/1.2-netsec/cdr/cdr_sqlite.c
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005, Holger Schurig
- *
- *
- * Ideas taken from other cdr_*.c files
- *
- * 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 Store CDR records in a SQLite database.
- *
- * \author Holger Schurig <hs4233@mail.mn-solutions.de>
- *
- * See also
- * \arg \ref Config_cdr
- * \arg http://www.sqlite.org/
- *
- * Creates the database and table on-the-fly
- * \ingroup cdr_drivers
- */
-
-#include <sys/types.h>
-
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sqlite.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-
-#define LOG_UNIQUEID 0
-#define LOG_USERFIELD 0
-
-/* When you change the DATE_FORMAT, be sure to change the CHAR(19) below to something else */
-#define DATE_FORMAT "%Y-%m-%d %T"
-
-static char *desc = "SQLite CDR Backend";
-static char *name = "sqlite";
-static sqlite* db = NULL;
-
-AST_MUTEX_DEFINE_STATIC(sqlite_lock);
-
-/*! \brief SQL table format */
-static char sql_create_table[] = "CREATE TABLE cdr ("
-" AcctId INTEGER PRIMARY KEY,"
-" clid VARCHAR(80),"
-" src VARCHAR(80),"
-" dst VARCHAR(80),"
-" dcontext VARCHAR(80),"
-" channel VARCHAR(80),"
-" dstchannel VARCHAR(80),"
-" lastapp VARCHAR(80),"
-" lastdata VARCHAR(80),"
-" start CHAR(19),"
-" answer CHAR(19),"
-" end CHAR(19),"
-" duration INTEGER,"
-" billsec INTEGER,"
-" disposition INTEGER,"
-" amaflags INTEGER,"
-" accountcode VARCHAR(20)"
-#if LOG_UNIQUEID
-" ,uniqueid VARCHAR(32)"
-#endif
-#if LOG_USERFIELD
-" ,userfield VARCHAR(255)"
-#endif
-");";
-
-static int sqlite_log(struct ast_cdr *cdr)
-{
- int res = 0;
- char *zErr = 0;
- struct tm tm;
- time_t t;
- char startstr[80], answerstr[80], endstr[80];
- int count;
-
- ast_mutex_lock(&sqlite_lock);
-
- t = cdr->start.tv_sec;
- localtime_r(&t, &tm);
- strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm);
-
- t = cdr->answer.tv_sec;
- localtime_r(&t, &tm);
- strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm);
-
- t = cdr->end.tv_sec;
- localtime_r(&t, &tm);
- strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm);
-
- for(count=0; count<5; count++) {
- res = sqlite_exec_printf(db,
- "INSERT INTO cdr ("
- "clid,src,dst,dcontext,"
- "channel,dstchannel,lastapp,lastdata, "
- "start,answer,end,"
- "duration,billsec,disposition,amaflags, "
- "accountcode"
-# if LOG_UNIQUEID
- ",uniqueid"
-# endif
-# if LOG_USERFIELD
- ",userfield"
-# endif
- ") VALUES ("
- "'%q', '%q', '%q', '%q', "
- "'%q', '%q', '%q', '%q', "
- "'%q', '%q', '%q', "
- "%d, %d, %d, %d, "
- "'%q'"
-# if LOG_UNIQUEID
- ",'%q'"
-# endif
-# if LOG_USERFIELD
- ",'%q'"
-# endif
- ")", NULL, NULL, &zErr,
- cdr->clid, cdr->src, cdr->dst, cdr->dcontext,
- cdr->channel, cdr->dstchannel, cdr->lastapp, cdr->lastdata,
- startstr, answerstr, endstr,
- cdr->duration, cdr->billsec, cdr->disposition, cdr->amaflags,
- cdr->accountcode
-# if LOG_UNIQUEID
- ,cdr->uniqueid
-# endif
-# if LOG_USERFIELD
- ,cdr->userfield
-# endif
- );
- if (res != SQLITE_BUSY && res != SQLITE_LOCKED)
- break;
- usleep(200);
- }
-
- if (zErr) {
- ast_log(LOG_ERROR, "cdr_sqlite: %s\n", zErr);
- free(zErr);
- }
-
- ast_mutex_unlock(&sqlite_lock);
- return res;
-}
-
-
-char *description(void)
-{
- return desc;
-}
-
-int unload_module(void)
-{
- if (db)
- sqlite_close(db);
- ast_cdr_unregister(name);
- return 0;
-}
-
-int load_module(void)
-{
- char *zErr;
- char fn[PATH_MAX];
- int res;
-
- /* is the database there? */
- snprintf(fn, sizeof(fn), "%s/cdr.db", ast_config_AST_LOG_DIR);
- db = sqlite_open(fn, 0660, &zErr);
- if (!db) {
- ast_log(LOG_ERROR, "cdr_sqlite: %s\n", zErr);
- free(zErr);
- return -1;
- }
-
- /* is the table there? */
- res = sqlite_exec(db, "SELECT COUNT(AcctId) FROM cdr;", NULL, NULL, NULL);
- if (res) {
- res = sqlite_exec(db, sql_create_table, NULL, NULL, &zErr);
- if (res) {
- ast_log(LOG_ERROR, "cdr_sqlite: Unable to create table 'cdr': %s\n", zErr);
- free(zErr);
- goto err;
- }
-
- /* TODO: here we should probably create an index */
- }
-
- res = ast_cdr_register(name, desc, sqlite_log);
- if (res) {
- ast_log(LOG_ERROR, "Unable to register SQLite CDR handling\n");
- return -1;
- }
- return 0;
-
-err:
- if (db)
- sqlite_close(db);
- return -1;
-}
-
-int reload(void)
-{
- return 0;
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/cdr/cdr_tds.c b/1.2-netsec/cdr/cdr_tds.c
deleted file mode 100644
index 14aa9b2bd..000000000
--- a/1.2-netsec/cdr/cdr_tds.c
+++ /dev/null
@@ -1,522 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005, Digium, Inc.
- *
- * 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 FreeTDS CDR logger
- *
- * See also
- * \arg \ref Config_cdr
- * \arg http://www.freetds.org/
- * \ingroup cdr_drivers
- */
-
-/*! \verbatim
- *
- * Table Structure for `cdr`
- *
- * Created on: 05/20/2004 16:16
- * Last changed on: 07/27/2004 20:01
-
-CREATE TABLE [dbo].[cdr] (
- [accountcode] [varchar] (20) NULL ,
- [src] [varchar] (80) NULL ,
- [dst] [varchar] (80) NULL ,
- [dcontext] [varchar] (80) NULL ,
- [clid] [varchar] (80) NULL ,
- [channel] [varchar] (80) NULL ,
- [dstchannel] [varchar] (80) NULL ,
- [lastapp] [varchar] (80) NULL ,
- [lastdata] [varchar] (80) NULL ,
- [start] [datetime] NULL ,
- [answer] [datetime] NULL ,
- [end] [datetime] NULL ,
- [duration] [int] NULL ,
- [billsec] [int] NULL ,
- [disposition] [varchar] (20) NULL ,
- [amaflags] [varchar] (16) NULL ,
- [uniqueid] [varchar] (32) NULL
-) ON [PRIMARY]
-
-\endverbatim
-
-*/
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <math.h>
-
-#include <tds.h>
-#include <tdsconvert.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/cdr.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-
-#ifdef FREETDS_PRE_0_62
-#warning "You have older TDS, you should upgrade!"
-#endif
-
-#define DATE_FORMAT "%Y/%m/%d %T"
-
-static char *desc = "MSSQL CDR Backend";
-static char *name = "mssql";
-static char *config = "cdr_tds.conf";
-
-static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *charset = NULL, *language = NULL;
-
-static int connected = 0;
-
-AST_MUTEX_DEFINE_STATIC(tds_lock);
-
-static TDSSOCKET *tds;
-static TDSLOGIN *login;
-static TDSCONTEXT *context;
-
-static char *anti_injection(const char *, int);
-static void get_date(char *, struct timeval);
-
-static int mssql_connect(void);
-static int mssql_disconnect(void);
-
-static int tds_log(struct ast_cdr *cdr)
-{
- char sqlcmd[2048], start[80], answer[80], end[80];
- char *accountcode, *src, *dst, *dcontext, *clid, *channel, *dstchannel, *lastapp, *lastdata, *uniqueid;
- int res = 0;
- int retried = 0;
-#ifdef FREETDS_PRE_0_62
- TDS_INT result_type;
-#endif
-
- ast_mutex_lock(&tds_lock);
-
- memset(sqlcmd, 0, 2048);
-
- accountcode = anti_injection(cdr->accountcode, 20);
- src = anti_injection(cdr->src, 80);
- dst = anti_injection(cdr->dst, 80);
- dcontext = anti_injection(cdr->dcontext, 80);
- clid = anti_injection(cdr->clid, 80);
- channel = anti_injection(cdr->channel, 80);
- dstchannel = anti_injection(cdr->dstchannel, 80);
- lastapp = anti_injection(cdr->lastapp, 80);
- lastdata = anti_injection(cdr->lastdata, 80);
- uniqueid = anti_injection(cdr->uniqueid, 32);
-
- get_date(start, cdr->start);
- get_date(answer, cdr->answer);
- get_date(end, cdr->end);
-
- sprintf(
- sqlcmd,
- "INSERT INTO cdr "
- "("
- "accountcode, "
- "src, "
- "dst, "
- "dcontext, "
- "clid, "
- "channel, "
- "dstchannel, "
- "lastapp, "
- "lastdata, "
- "start, "
- "answer, "
- "[end], "
- "duration, "
- "billsec, "
- "disposition, "
- "amaflags, "
- "uniqueid"
- ") "
- "VALUES "
- "("
- "'%s', " /* accountcode */
- "'%s', " /* src */
- "'%s', " /* dst */
- "'%s', " /* dcontext */
- "'%s', " /* clid */
- "'%s', " /* channel */
- "'%s', " /* dstchannel */
- "'%s', " /* lastapp */
- "'%s', " /* lastdata */
- "%s, " /* start */
- "%s, " /* answer */
- "%s, " /* end */
- "%ld, " /* duration */
- "%ld, " /* billsec */
- "'%s', " /* disposition */
- "'%s', " /* amaflags */
- "'%s'" /* uniqueid */
- ")",
- accountcode,
- src,
- dst,
- dcontext,
- clid,
- channel,
- dstchannel,
- lastapp,
- lastdata,
- start,
- answer,
- end,
- cdr->duration,
- cdr->billsec,
- ast_cdr_disp2str(cdr->disposition),
- ast_cdr_flags2str(cdr->amaflags),
- uniqueid
- );
-
- do {
- if (!connected) {
- if (mssql_connect())
- ast_log(LOG_ERROR, "Failed to reconnect to SQL database.\n");
- else
- ast_log(LOG_WARNING, "Reconnected to SQL database.\n");
-
- retried = 1; /* note that we have now tried */
- }
-
-#ifdef FREETDS_PRE_0_62
- if (!connected || (tds_submit_query(tds, sqlcmd) != TDS_SUCCEED) || (tds_process_simple_query(tds, &result_type) != TDS_SUCCEED || result_type != TDS_CMD_SUCCEED))
-#else
- if (!connected || (tds_submit_query(tds, sqlcmd) != TDS_SUCCEED) || (tds_process_simple_query(tds) != TDS_SUCCEED))
-#endif
- {
- ast_log(LOG_ERROR, "Failed to insert Call Data Record into SQL database.\n");
-
- mssql_disconnect(); /* this is ok even if we are already disconnected */
- }
- } while (!connected && !retried);
-
- free(accountcode);
- free(src);
- free(dst);
- free(dcontext);
- free(clid);
- free(channel);
- free(dstchannel);
- free(lastapp);
- free(lastdata);
- free(uniqueid);
-
- ast_mutex_unlock(&tds_lock);
-
- return res;
-}
-
-static char *anti_injection(const char *str, int len)
-{
- /* Reference to http://www.nextgenss.com/papers/advanced_sql_injection.pdf */
-
- char *buf;
- char *buf_ptr, *srh_ptr;
- char *known_bad[] = {"select", "insert", "update", "delete", "drop", ";", "--", "\0"};
- int idx;
-
- if ((buf = malloc(len + 1)) == NULL)
- {
- ast_log(LOG_ERROR, "cdr_tds: Out of memory error\n");
- return NULL;
- }
- memset(buf, 0, len);
-
- buf_ptr = buf;
-
- /* Escape single quotes */
- for (; *str && strlen(buf) < len; str++)
- {
- if (*str == '\'')
- *buf_ptr++ = '\'';
- *buf_ptr++ = *str;
- }
- *buf_ptr = '\0';
-
- /* Erase known bad input */
- for (idx=0; *known_bad[idx]; idx++)
- {
- while((srh_ptr = strcasestr(buf, known_bad[idx])))
- {
- memmove(srh_ptr, srh_ptr+strlen(known_bad[idx]), strlen(srh_ptr+strlen(known_bad[idx]))+1);
- }
- }
-
- return buf;
-}
-
-static void get_date(char *dateField, struct timeval tv)
-{
- struct tm tm;
- time_t t;
- char buf[80];
-
- /* To make sure we have date variable if not insert null to SQL */
- if (!ast_tvzero(tv))
- {
- t = tv.tv_sec;
- localtime_r(&t, &tm);
- strftime(buf, 80, DATE_FORMAT, &tm);
- sprintf(dateField, "'%s'", buf);
- }
- else
- {
- strcpy(dateField, "null");
- }
-}
-
-char *description(void)
-{
- return desc;
-}
-
-static int mssql_disconnect(void)
-{
- if (tds) {
- tds_free_socket(tds);
- tds = NULL;
- }
-
- if (context) {
- tds_free_context(context);
- context = NULL;
- }
-
- if (login) {
- tds_free_login(login);
- login = NULL;
- }
-
- connected = 0;
-
- return 0;
-}
-
-static int mssql_connect(void)
-{
-#ifdef FREETDS_0_63
- TDSCONNECTION *connection = NULL;
-#else
- TDSCONNECTINFO *connection = NULL;
-#endif
- char query[128];
-
- /* Connect to M$SQL Server */
- if (!(login = tds_alloc_login()))
- {
- ast_log(LOG_ERROR, "tds_alloc_login() failed.\n");
- return -1;
- }
-
- tds_set_server(login, hostname);
- tds_set_user(login, dbuser);
- tds_set_passwd(login, password);
- tds_set_app(login, "TSQL");
- tds_set_library(login, "TDS-Library");
-#ifndef FREETDS_PRE_0_62
- tds_set_client_charset(login, charset);
-#endif
- tds_set_language(login, language);
- tds_set_packet(login, 512);
- tds_set_version(login, 7, 0);
-
- if (!(context = tds_alloc_context()))
- {
- ast_log(LOG_ERROR, "tds_alloc_context() failed.\n");
- goto connect_fail;
- }
-
- if (!(tds = tds_alloc_socket(context, 512))) {
- ast_log(LOG_ERROR, "tds_alloc_socket() failed.\n");
- goto connect_fail;
- }
-
- tds_set_parent(tds, NULL);
- connection = tds_read_config_info(tds, login, context->locale);
- if (!connection)
- {
- ast_log(LOG_ERROR, "tds_read_config() failed.\n");
- goto connect_fail;
- }
-
- if (tds_connect(tds, connection) == TDS_FAIL)
- {
- ast_log(LOG_ERROR, "Failed to connect to MSSQL server.\n");
- tds = NULL; /* freed by tds_connect() on error */
-#ifdef FREETDS_0_63
- tds_free_connection(connection);
-#else
- tds_free_connect(connection);
-#endif
- connection = NULL;
- goto connect_fail;
- }
-#ifdef FREETDS_0_63
- tds_free_connection(connection);
-#else
- tds_free_connect(connection);
-#endif
- connection = NULL;
-
- sprintf(query, "USE %s", dbname);
-#ifdef FREETDS_PRE_0_62
- if ((tds_submit_query(tds, query) != TDS_SUCCEED) || (tds_process_simple_query(tds, &result_type) != TDS_SUCCEED || result_type != TDS_CMD_SUCCEED))
-#else
- if ((tds_submit_query(tds, query) != TDS_SUCCEED) || (tds_process_simple_query(tds) != TDS_SUCCEED))
-#endif
- {
- ast_log(LOG_ERROR, "Could not change database (%s)\n", dbname);
- goto connect_fail;
- }
-
- connected = 1;
- return 0;
-
-connect_fail:
- mssql_disconnect();
- return -1;
-}
-
-static int tds_unload_module(void)
-{
- mssql_disconnect();
-
- ast_cdr_unregister(name);
-
- if (hostname) free(hostname);
- if (dbname) free(dbname);
- if (dbuser) free(dbuser);
- if (password) free(password);
- if (charset) free(charset);
- if (language) free(language);
-
- return 0;
-}
-
-static int tds_load_module(void)
-{
- int res = 0;
- struct ast_config *cfg;
- struct ast_variable *var;
- char *ptr = NULL;
-#ifdef FREETDS_PRE_0_62
- TDS_INT result_type;
-#endif
-
- cfg = ast_config_load(config);
- if (!cfg) {
- ast_log(LOG_NOTICE, "Unable to load config for MSSQL CDR's: %s\n", config);
- return 0;
- }
-
- var = ast_variable_browse(cfg, "global");
- if (!var) /* nothing configured */
- return 0;
-
- ptr = ast_variable_retrieve(cfg, "global", "hostname");
- if (ptr)
- hostname = strdup(ptr);
- else
- ast_log(LOG_ERROR,"Database server hostname not specified.\n");
-
- ptr = ast_variable_retrieve(cfg, "global", "dbname");
- if (ptr)
- dbname = strdup(ptr);
- else
- ast_log(LOG_ERROR,"Database dbname not specified.\n");
-
- ptr = ast_variable_retrieve(cfg, "global", "user");
- if (ptr)
- dbuser = strdup(ptr);
- else
- ast_log(LOG_ERROR,"Database dbuser not specified.\n");
-
- ptr = ast_variable_retrieve(cfg, "global", "password");
- if (ptr)
- password = strdup(ptr);
- else
- ast_log(LOG_ERROR,"Database password not specified.\n");
-
- ptr = ast_variable_retrieve(cfg, "global", "charset");
- if (ptr)
- charset = strdup(ptr);
- else
- charset = strdup("iso_1");
-
- ptr = ast_variable_retrieve(cfg, "global", "language");
- if (ptr)
- language = strdup(ptr);
- else
- language = strdup("us_english");
-
- ast_config_destroy(cfg);
-
- mssql_connect();
-
- /* Register MSSQL CDR handler */
- res = ast_cdr_register(name, desc, tds_log);
- if (res)
- {
- ast_log(LOG_ERROR, "Unable to register MSSQL CDR handling\n");
- }
-
- return res;
-}
-
-int reload(void)
-{
- tds_unload_module();
- return tds_load_module();
-}
-
-int load_module(void)
-{
- return tds_load_module();
-}
-
-int unload_module(void)
-{
- return tds_unload_module();
-}
-
-int usecount(void)
-{
- /* Simplistic use count */
- if (ast_mutex_trylock(&tds_lock)) {
- return 1;
- } else {
- ast_mutex_unlock(&tds_lock);
- return 0;
- }
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channel.c b/1.2-netsec/channel.c
deleted file mode 100644
index 011bdaef3..000000000
--- a/1.2-netsec/channel.c
+++ /dev/null
@@ -1,4059 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Channel Management
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <math.h> /* For PI */
-
-#ifdef ZAPTEL_OPTIMIZATIONS
-#include <sys/ioctl.h>
-#ifdef __linux__
-#include <linux/zaptel.h>
-#else
-#include <zaptel.h>
-#endif /* __linux__ */
-#ifndef ZT_TIMERPING
-#error "You need newer zaptel! Please cvs update zaptel"
-#endif
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/pbx.h"
-#include "asterisk/frame.h"
-#include "asterisk/sched.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/chanspy.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/logger.h"
-#include "asterisk/say.h"
-#include "asterisk/file.h"
-#include "asterisk/cli.h"
-#include "asterisk/translate.h"
-#include "asterisk/manager.h"
-#include "asterisk/chanvars.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/indications.h"
-#include "asterisk/monitor.h"
-#include "asterisk/causes.h"
-#include "asterisk/callerid.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-#include "asterisk/app.h"
-#include "asterisk/transcap.h"
-#include "asterisk/devicestate.h"
-
-struct channel_spy_trans {
- int last_format;
- struct ast_trans_pvt *path;
-};
-
-struct ast_channel_spy_list {
- struct channel_spy_trans read_translator;
- struct channel_spy_trans write_translator;
- AST_LIST_HEAD_NOLOCK(, ast_channel_spy) list;
-};
-
-/* uncomment if you have problems with 'monitoring' synchronized files */
-#if 0
-#define MONITOR_CONSTANT_DELAY
-#define MONITOR_DELAY 150 * 8 /* 150 ms of MONITORING DELAY */
-#endif
-
-/*
- * Prevent new channel allocation if shutting down.
- */
-static int shutting_down = 0;
-
-AST_MUTEX_DEFINE_STATIC(uniquelock);
-static int uniqueint = 0;
-
-unsigned long global_fin = 0, global_fout = 0;
-
-/* XXX Lock appropriately in more functions XXX */
-
-struct chanlist {
- const struct ast_channel_tech *tech;
- struct chanlist *next;
-};
-
-static struct chanlist *backends = NULL;
-
-/*
- * the list of channels we have
- */
-static struct ast_channel *channels = NULL;
-
-/* Protect the channel list, both backends and channels.
- */
-AST_MUTEX_DEFINE_STATIC(chlock);
-
-const struct ast_cause {
- int cause;
- const char *desc;
-} causes[] = {
- { AST_CAUSE_UNALLOCATED, "Unallocated (unassigned) number" },
- { AST_CAUSE_NO_ROUTE_TRANSIT_NET, "No route to specified transmit network" },
- { AST_CAUSE_NO_ROUTE_DESTINATION, "No route to destination" },
- { AST_CAUSE_CHANNEL_UNACCEPTABLE, "Channel unacceptable" },
- { AST_CAUSE_CALL_AWARDED_DELIVERED, "Call awarded and being delivered in an established channel" },
- { AST_CAUSE_NORMAL_CLEARING, "Normal Clearing" },
- { AST_CAUSE_USER_BUSY, "User busy" },
- { AST_CAUSE_NO_USER_RESPONSE, "No user responding" },
- { AST_CAUSE_NO_ANSWER, "User alerting, no answer" },
- { AST_CAUSE_CALL_REJECTED, "Call Rejected" },
- { AST_CAUSE_NUMBER_CHANGED, "Number changed" },
- { AST_CAUSE_DESTINATION_OUT_OF_ORDER, "Destination out of order" },
- { AST_CAUSE_INVALID_NUMBER_FORMAT, "Invalid number format" },
- { AST_CAUSE_FACILITY_REJECTED, "Facility rejected" },
- { AST_CAUSE_RESPONSE_TO_STATUS_ENQUIRY, "Response to STATus ENQuiry" },
- { AST_CAUSE_NORMAL_UNSPECIFIED, "Normal, unspecified" },
- { AST_CAUSE_NORMAL_CIRCUIT_CONGESTION, "Circuit/channel congestion" },
- { AST_CAUSE_NETWORK_OUT_OF_ORDER, "Network out of order" },
- { AST_CAUSE_NORMAL_TEMPORARY_FAILURE, "Temporary failure" },
- { AST_CAUSE_SWITCH_CONGESTION, "Switching equipment congestion" },
- { AST_CAUSE_ACCESS_INFO_DISCARDED, "Access information discarded" },
- { AST_CAUSE_REQUESTED_CHAN_UNAVAIL, "Requested channel not available" },
- { AST_CAUSE_PRE_EMPTED, "Pre-empted" },
- { AST_CAUSE_FACILITY_NOT_SUBSCRIBED, "Facility not subscribed" },
- { AST_CAUSE_OUTGOING_CALL_BARRED, "Outgoing call barred" },
- { AST_CAUSE_INCOMING_CALL_BARRED, "Incoming call barred" },
- { AST_CAUSE_BEARERCAPABILITY_NOTAUTH, "Bearer capability not authorized" },
- { AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, "Bearer capability not available" },
- { AST_CAUSE_BEARERCAPABILITY_NOTIMPL, "Bearer capability not implemented" },
- { AST_CAUSE_CHAN_NOT_IMPLEMENTED, "Channel not implemented" },
- { AST_CAUSE_FACILITY_NOT_IMPLEMENTED, "Facility not implemented" },
- { AST_CAUSE_INVALID_CALL_REFERENCE, "Invalid call reference value" },
- { AST_CAUSE_INCOMPATIBLE_DESTINATION, "Incompatible destination" },
- { AST_CAUSE_INVALID_MSG_UNSPECIFIED, "Invalid message unspecified" },
- { AST_CAUSE_MANDATORY_IE_MISSING, "Mandatory information element is missing" },
- { AST_CAUSE_MESSAGE_TYPE_NONEXIST, "Message type nonexist." },
- { AST_CAUSE_WRONG_MESSAGE, "Wrong message" },
- { AST_CAUSE_IE_NONEXIST, "Info. element nonexist or not implemented" },
- { AST_CAUSE_INVALID_IE_CONTENTS, "Invalid information element contents" },
- { AST_CAUSE_WRONG_CALL_STATE, "Message not compatible with call state" },
- { AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE, "Recover on timer expiry" },
- { AST_CAUSE_MANDATORY_IE_LENGTH_ERROR, "Mandatory IE length error" },
- { AST_CAUSE_PROTOCOL_ERROR, "Protocol error, unspecified" },
- { AST_CAUSE_INTERWORKING, "Interworking, unspecified" },
-};
-
-
-static int show_channeltypes(int fd, int argc, char *argv[])
-{
-#define FORMAT "%-10.10s %-30.30s %-12.12s %-12.12s %-12.12s\n"
- struct chanlist *cl = backends;
- ast_cli(fd, FORMAT, "Type", "Description", "Devicestate", "Indications", "Transfer");
- ast_cli(fd, FORMAT, "----------", "-----------", "-----------", "-----------", "--------");
- if (ast_mutex_lock(&chlock)) {
- ast_log(LOG_WARNING, "Unable to lock channel list\n");
- return -1;
- }
- while (cl) {
- ast_cli(fd, FORMAT, cl->tech->type, cl->tech->description,
- (cl->tech->devicestate) ? "yes" : "no",
- (cl->tech->indicate) ? "yes" : "no",
- (cl->tech->transfer) ? "yes" : "no");
- cl = cl->next;
- }
- ast_mutex_unlock(&chlock);
- return RESULT_SUCCESS;
-
-#undef FORMAT
-
-}
-
-static char show_channeltypes_usage[] =
-"Usage: show channeltypes\n"
-" Shows available channel types registered in your Asterisk server.\n";
-
-static struct ast_cli_entry cli_show_channeltypes =
- { { "show", "channeltypes", NULL }, show_channeltypes, "Show available channel types", show_channeltypes_usage };
-
-/*--- ast_check_hangup: Checks to see if a channel is needing hang up */
-int ast_check_hangup(struct ast_channel *chan)
-{
- time_t myt;
-
- /* if soft hangup flag, return true */
- if (chan->_softhangup)
- return 1;
- /* if no technology private data, return true */
- if (!chan->tech_pvt)
- return 1;
- /* if no hangup scheduled, just return here */
- if (!chan->whentohangup)
- return 0;
- time(&myt); /* get current time */
- /* return, if not yet */
- if (chan->whentohangup > myt)
- return 0;
- chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
- return 1;
-}
-
-static int ast_check_hangup_locked(struct ast_channel *chan)
-{
- int res;
- ast_mutex_lock(&chan->lock);
- res = ast_check_hangup(chan);
- ast_mutex_unlock(&chan->lock);
- return res;
-}
-
-/*--- ast_begin_shutdown: Initiate system shutdown */
-void ast_begin_shutdown(int hangup)
-{
- struct ast_channel *c;
- shutting_down = 1;
- if (hangup) {
- ast_mutex_lock(&chlock);
- c = channels;
- while(c) {
- ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN);
- c = c->next;
- }
- ast_mutex_unlock(&chlock);
- }
-}
-
-/*--- ast_active_channels: returns number of active/allocated channels */
-int ast_active_channels(void)
-{
- struct ast_channel *c;
- int cnt = 0;
- ast_mutex_lock(&chlock);
- c = channels;
- while(c) {
- cnt++;
- c = c->next;
- }
- ast_mutex_unlock(&chlock);
- return cnt;
-}
-
-/*--- ast_cancel_shutdown: Cancel a shutdown in progress */
-void ast_cancel_shutdown(void)
-{
- shutting_down = 0;
-}
-
-/*--- ast_shutting_down: Returns non-zero if Asterisk is being shut down */
-int ast_shutting_down(void)
-{
- return shutting_down;
-}
-
-/*--- ast_channel_setwhentohangup: Set when to hangup channel */
-void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset)
-{
- time_t myt;
- struct ast_frame fr = { AST_FRAME_NULL, };
-
- time(&myt);
- if (offset)
- chan->whentohangup = myt + offset;
- else
- chan->whentohangup = 0;
- ast_queue_frame(chan, &fr);
- return;
-}
-
-/*--- ast_channel_cmpwhentohangup: Compare a offset with when to hangup channel */
-int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset)
-{
- time_t whentohangup;
-
- if (chan->whentohangup == 0) {
- if (offset == 0)
- return (0);
- else
- return (-1);
- } else {
- if (offset == 0)
- return (1);
- else {
- whentohangup = offset + time (NULL);
- if (chan->whentohangup < whentohangup)
- return (1);
- else if (chan->whentohangup == whentohangup)
- return (0);
- else
- return (-1);
- }
- }
-}
-
-/*--- ast_channel_register: Register a new telephony channel in Asterisk */
-int ast_channel_register(const struct ast_channel_tech *tech)
-{
- struct chanlist *chan;
-
- ast_mutex_lock(&chlock);
-
- chan = backends;
- while (chan) {
- if (!strcasecmp(tech->type, chan->tech->type)) {
- ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
- ast_mutex_unlock(&chlock);
- return -1;
- }
- chan = chan->next;
- }
-
- chan = malloc(sizeof(*chan));
- if (!chan) {
- ast_log(LOG_WARNING, "Out of memory\n");
- ast_mutex_unlock(&chlock);
- return -1;
- }
- chan->tech = tech;
- chan->next = backends;
- backends = chan;
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description);
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Registered channel type '%s' (%s)\n", chan->tech->type,
- chan->tech->description);
-
- ast_mutex_unlock(&chlock);
- return 0;
-}
-
-void ast_channel_unregister(const struct ast_channel_tech *tech)
-{
- struct chanlist *chan, *last=NULL;
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Unregistering channel type '%s'\n", tech->type);
-
- ast_mutex_lock(&chlock);
-
- chan = backends;
- while (chan) {
- if (chan->tech == tech) {
- if (last)
- last->next = chan->next;
- else
- backends = backends->next;
- free(chan);
- ast_mutex_unlock(&chlock);
-
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Unregistered channel type '%s'\n", tech->type);
-
- return;
- }
- last = chan;
- chan = chan->next;
- }
-
- ast_mutex_unlock(&chlock);
-}
-
-const struct ast_channel_tech *ast_get_channel_tech(const char *name)
-{
- struct chanlist *chanls;
-
- if (ast_mutex_lock(&chlock)) {
- ast_log(LOG_WARNING, "Unable to lock channel tech list\n");
- return NULL;
- }
-
- for (chanls = backends; chanls; chanls = chanls->next) {
- if (strcasecmp(name, chanls->tech->type))
- continue;
-
- ast_mutex_unlock(&chlock);
- return chanls->tech;
- }
-
- ast_mutex_unlock(&chlock);
- return NULL;
-}
-
-/*--- ast_cause2str: Gives the string form of a given hangup cause */
-const char *ast_cause2str(int cause)
-{
- int x;
-
- for (x=0; x < sizeof(causes) / sizeof(causes[0]); x++)
- if (causes[x].cause == cause)
- return causes[x].desc;
-
- return "Unknown";
-}
-
-/*--- ast_state2str: Gives the string form of a given channel state */
-char *ast_state2str(int state)
-{
- /* XXX Not reentrant XXX */
- static char localtmp[256];
- switch(state) {
- case AST_STATE_DOWN:
- return "Down";
- case AST_STATE_RESERVED:
- return "Rsrvd";
- case AST_STATE_OFFHOOK:
- return "OffHook";
- case AST_STATE_DIALING:
- return "Dialing";
- case AST_STATE_RING:
- return "Ring";
- case AST_STATE_RINGING:
- return "Ringing";
- case AST_STATE_UP:
- return "Up";
- case AST_STATE_BUSY:
- return "Busy";
- default:
- snprintf(localtmp, sizeof(localtmp), "Unknown (%d)\n", state);
- return localtmp;
- }
-}
-
-/*--- ast_transfercapability2str: Gives the string form of a given transfer capability */
-char *ast_transfercapability2str(int transfercapability)
-{
- switch(transfercapability) {
- case AST_TRANS_CAP_SPEECH:
- return "SPEECH";
- case AST_TRANS_CAP_DIGITAL:
- return "DIGITAL";
- case AST_TRANS_CAP_RESTRICTED_DIGITAL:
- return "RESTRICTED_DIGITAL";
- case AST_TRANS_CAP_3_1K_AUDIO:
- return "3K1AUDIO";
- case AST_TRANS_CAP_DIGITAL_W_TONES:
- return "DIGITAL_W_TONES";
- case AST_TRANS_CAP_VIDEO:
- return "VIDEO";
- default:
- return "UNKNOWN";
- }
-}
-
-/*--- ast_best_codec: Pick the best codec */
-int ast_best_codec(int fmts)
-{
- /* This just our opinion, expressed in code. We are asked to choose
- the best codec to use, given no information */
- int x;
- static int prefs[] =
- {
- /* Okay, ulaw is used by all telephony equipment, so start with it */
- AST_FORMAT_ULAW,
- /* Unless of course, you're a silly European, so then prefer ALAW */
- AST_FORMAT_ALAW,
- /* Okay, well, signed linear is easy to translate into other stuff */
- AST_FORMAT_SLINEAR,
- /* G.726 is standard ADPCM */
- AST_FORMAT_G726,
- /* ADPCM has great sound quality and is still pretty easy to translate */
- AST_FORMAT_ADPCM,
- /* Okay, we're down to vocoders now, so pick GSM because it's small and easier to
- translate and sounds pretty good */
- AST_FORMAT_GSM,
- /* iLBC is not too bad */
- AST_FORMAT_ILBC,
- /* Speex is free, but computationally more expensive than GSM */
- AST_FORMAT_SPEEX,
- /* Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
- to use it */
- AST_FORMAT_LPC10,
- /* G.729a is faster than 723 and slightly less expensive */
- AST_FORMAT_G729A,
- /* Down to G.723.1 which is proprietary but at least designed for voice */
- AST_FORMAT_G723_1,
- };
-
-
- /* Find the first prefered codec in the format given */
- for (x=0; x < (sizeof(prefs) / sizeof(prefs[0]) ); x++)
- if (fmts & prefs[x])
- return prefs[x];
- ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts);
- return 0;
-}
-
-static const struct ast_channel_tech null_tech = {
- .type = "NULL",
- .description = "Null channel (should not see this)",
-};
-
-/*--- ast_channel_alloc: Create a new channel structure */
-struct ast_channel *ast_channel_alloc(int needqueue)
-{
- struct ast_channel *tmp;
- int x;
- int flags;
- struct varshead *headp;
-
-
- /* If shutting down, don't allocate any new channels */
- if (shutting_down) {
- ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
- return NULL;
- }
-
- tmp = malloc(sizeof(struct ast_channel));
- if (!tmp) {
- ast_log(LOG_WARNING, "Channel allocation failed: Out of memory\n");
- return NULL;
- }
-
- memset(tmp, 0, sizeof(struct ast_channel));
- tmp->sched = sched_context_create();
- if (!tmp->sched) {
- ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
- free(tmp);
- return NULL;
- }
-
- for (x=0; x<AST_MAX_FDS - 1; x++)
- tmp->fds[x] = -1;
-
-#ifdef ZAPTEL_OPTIMIZATIONS
- tmp->timingfd = open("/dev/zap/timer", O_RDWR);
- if (tmp->timingfd > -1) {
- /* Check if timing interface supports new
- ping/pong scheme */
- flags = 1;
- if (!ioctl(tmp->timingfd, ZT_TIMERPONG, &flags))
- needqueue = 0;
- }
-#else
- tmp->timingfd = -1;
-#endif
-
- if (needqueue) {
- if (pipe(tmp->alertpipe)) {
- ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
- free(tmp);
- return NULL;
- } else {
- flags = fcntl(tmp->alertpipe[0], F_GETFL);
- fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK);
- flags = fcntl(tmp->alertpipe[1], F_GETFL);
- fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK);
- }
- } else
- /* Make sure we've got it done right if they don't */
- tmp->alertpipe[0] = tmp->alertpipe[1] = -1;
-
- /* Always watch the alertpipe */
- tmp->fds[AST_MAX_FDS-1] = tmp->alertpipe[0];
- /* And timing pipe */
- tmp->fds[AST_MAX_FDS-2] = tmp->timingfd;
- strcpy(tmp->name, "**Unknown**");
- /* Initial state */
- tmp->_state = AST_STATE_DOWN;
- tmp->streamid = -1;
- tmp->appl = NULL;
- tmp->data = NULL;
- tmp->fin = global_fin;
- tmp->fout = global_fout;
- ast_mutex_lock(&uniquelock);
- snprintf(tmp->uniqueid, sizeof(tmp->uniqueid), "%li.%d", (long) time(NULL), uniqueint++);
- ast_mutex_unlock(&uniquelock);
- headp = &tmp->varshead;
- ast_mutex_init(&tmp->lock);
- AST_LIST_HEAD_INIT_NOLOCK(headp);
- strcpy(tmp->context, "default");
- ast_copy_string(tmp->language, defaultlanguage, sizeof(tmp->language));
- strcpy(tmp->exten, "s");
- tmp->priority = 1;
- tmp->amaflags = ast_default_amaflags;
- ast_copy_string(tmp->accountcode, ast_default_accountcode, sizeof(tmp->accountcode));
-
- tmp->tech = &null_tech;
-
- ast_mutex_lock(&chlock);
- tmp->next = channels;
- channels = tmp;
-
- ast_mutex_unlock(&chlock);
- return tmp;
-}
-
-/*--- ast_queue_frame: Queue an outgoing media frame */
-int ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin)
-{
- struct ast_frame *f;
- struct ast_frame *prev, *cur;
- int blah = 1;
- int qlen = 0;
-
- /* Build us a copy and free the original one */
- f = ast_frdup(fin);
- if (!f) {
- ast_log(LOG_WARNING, "Unable to duplicate frame\n");
- return -1;
- }
- ast_mutex_lock(&chan->lock);
- prev = NULL;
- cur = chan->readq;
- while(cur) {
- if ((cur->frametype == AST_FRAME_CONTROL) && (cur->subclass == AST_CONTROL_HANGUP)) {
- /* Don't bother actually queueing anything after a hangup */
- ast_frfree(f);
- ast_mutex_unlock(&chan->lock);
- return 0;
- }
- prev = cur;
- cur = cur->next;
- qlen++;
- }
- /* Allow up to 96 voice frames outstanding, and up to 128 total frames */
- if (((fin->frametype == AST_FRAME_VOICE) && (qlen > 96)) || (qlen > 128)) {
- if (fin->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Exceptionally long queue length queuing to %s\n", chan->name);
- CRASH;
- } else {
- ast_log(LOG_DEBUG, "Dropping voice to exceptionally long queue on %s\n", chan->name);
- ast_frfree(f);
- ast_mutex_unlock(&chan->lock);
- return 0;
- }
- }
- if (prev)
- prev->next = f;
- else
- chan->readq = f;
- if (chan->alertpipe[1] > -1) {
- if (write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah))
- ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d (qlen = %d): %s!\n",
- chan->name, f->frametype, f->subclass, qlen, strerror(errno));
-#ifdef ZAPTEL_OPTIMIZATIONS
- } else if (chan->timingfd > -1) {
- ioctl(chan->timingfd, ZT_TIMERPING, &blah);
-#endif
- } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
- pthread_kill(chan->blocker, SIGURG);
- }
- ast_mutex_unlock(&chan->lock);
- return 0;
-}
-
-/*--- ast_queue_hangup: Queue a hangup frame for channel */
-int ast_queue_hangup(struct ast_channel *chan)
-{
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
- /* Yeah, let's not change a lock-critical value without locking */
- if (!ast_mutex_trylock(&chan->lock)) {
- chan->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_mutex_unlock(&chan->lock);
- }
- return ast_queue_frame(chan, &f);
-}
-
-/*--- ast_queue_control: Queue a control frame */
-int ast_queue_control(struct ast_channel *chan, int control)
-{
- struct ast_frame f = { AST_FRAME_CONTROL, };
- f.subclass = control;
- return ast_queue_frame(chan, &f);
-}
-
-/*--- ast_channel_defer_dtmf: Set defer DTMF flag on channel */
-int ast_channel_defer_dtmf(struct ast_channel *chan)
-{
- int pre = 0;
-
- if (chan) {
- pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF);
- ast_set_flag(chan, AST_FLAG_DEFER_DTMF);
- }
- return pre;
-}
-
-/*--- ast_channel_undefer_dtmf: Unset defer DTMF flag on channel */
-void ast_channel_undefer_dtmf(struct ast_channel *chan)
-{
- if (chan)
- ast_clear_flag(chan, AST_FLAG_DEFER_DTMF);
-}
-
-/*
- * Helper function to find channels. It supports these modes:
- *
- * prev != NULL : get channel next in list after prev
- * name != NULL : get channel with matching name
- * name != NULL && namelen != 0 : get channel whose name starts with prefix
- * exten != NULL : get channel whose exten or macroexten matches
- * context != NULL && exten != NULL : get channel whose context or macrocontext
- *
- * It returns with the channel's lock held. If getting the individual lock fails,
- * unlock and retry quickly up to 10 times, then give up.
- *
- * XXX Note that this code has cost O(N) because of the need to verify
- * that the object is still on the global list.
- *
- * XXX also note that accessing fields (e.g. c->name in ast_log())
- * can only be done with the lock held or someone could delete the
- * object while we work on it. This causes some ugliness in the code.
- * Note that removing the first ast_log() may be harmful, as it would
- * shorten the retry period and possibly cause failures.
- * We should definitely go for a better scheme that is deadlock-free.
- */
-static struct ast_channel *channel_find_locked(const struct ast_channel *prev,
- const char *name, const int namelen,
- const char *context, const char *exten)
-{
- const char *msg = prev ? "deadlock" : "initial deadlock";
- int retries, done;
- struct ast_channel *c;
-
- for (retries = 0; retries < 10; retries++) {
- ast_mutex_lock(&chlock);
- for (c = channels; c; c = c->next) {
- if (!prev) {
- /* want head of list */
- if (!name && !exten)
- break;
- if (name) {
- /* want match by full name */
- if (!namelen) {
- if (!strcasecmp(c->name, name))
- break;
- else
- continue;
- }
- /* want match by name prefix */
- if (!strncasecmp(c->name, name, namelen))
- break;
- } else if (exten) {
- /* want match by context and exten */
- if (context && (strcasecmp(c->context, context) &&
- strcasecmp(c->macrocontext, context)))
- continue;
- /* match by exten */
- if (strcasecmp(c->exten, exten) &&
- strcasecmp(c->macroexten, exten))
- continue;
- else
- break;
- }
- } else if (c == prev) { /* found, return c->next */
- c = c->next;
- break;
- }
- }
- /* exit if chan not found or mutex acquired successfully */
- done = (c == NULL) || (ast_mutex_trylock(&c->lock) == 0);
- /* this is slightly unsafe, as we _should_ hold the lock to access c->name */
- if (!done && c)
- ast_log(LOG_DEBUG, "Avoiding %s for '%s'\n", msg, c->name);
- ast_mutex_unlock(&chlock);
- if (done)
- return c;
- usleep(1);
- }
- /*
- * c is surely not null, but we don't have the lock so cannot
- * access c->name
- */
- ast_log(LOG_WARNING, "Avoided %s for '%p', %d retries!\n",
- msg, c, retries);
-
- return NULL;
-}
-
-/*--- ast_channel_walk_locked: Browse channels in use */
-struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev)
-{
- return channel_find_locked(prev, NULL, 0, NULL, NULL);
-}
-
-/*--- ast_get_channel_by_name_locked: Get channel by name and lock it */
-struct ast_channel *ast_get_channel_by_name_locked(const char *name)
-{
- return channel_find_locked(NULL, name, 0, NULL, NULL);
-}
-
-/*--- ast_get_channel_by_name_prefix_locked: Get channel by name prefix and lock it */
-struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen)
-{
- return channel_find_locked(NULL, name, namelen, NULL, NULL);
-}
-
-/*--- ast_walk_channel_by_name_prefix_locked: Get next channel by name prefix and lock it */
-struct ast_channel *ast_walk_channel_by_name_prefix_locked(struct ast_channel *chan, const char *name, const int namelen)
-{
- return channel_find_locked(chan, name, namelen, NULL, NULL);
-}
-
-/*--- ast_get_channel_by_exten_locked: Get channel by exten (and optionally context) and lock it */
-struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context)
-{
- return channel_find_locked(NULL, NULL, 0, context, exten);
-}
-
-/*--- ast_safe_sleep_conditional: Wait, look for hangups and condition arg */
-int ast_safe_sleep_conditional( struct ast_channel *chan, int ms,
- int (*cond)(void*), void *data )
-{
- struct ast_frame *f;
-
- while(ms > 0) {
- if( cond && ((*cond)(data) == 0 ) )
- return 0;
- ms = ast_waitfor(chan, ms);
- if (ms <0)
- return -1;
- if (ms > 0) {
- f = ast_read(chan);
- if (!f)
- return -1;
- ast_frfree(f);
- }
- }
- return 0;
-}
-
-/*--- ast_safe_sleep: Wait, look for hangups */
-int ast_safe_sleep(struct ast_channel *chan, int ms)
-{
- struct ast_frame *f;
- while(ms > 0) {
- ms = ast_waitfor(chan, ms);
- if (ms <0)
- return -1;
- if (ms > 0) {
- f = ast_read(chan);
- if (!f)
- return -1;
- ast_frfree(f);
- }
- }
- return 0;
-}
-
-static void free_cid(struct ast_callerid *cid)
-{
- if (cid->cid_dnid)
- free(cid->cid_dnid);
- if (cid->cid_num)
- free(cid->cid_num);
- if (cid->cid_name)
- free(cid->cid_name);
- if (cid->cid_ani)
- free(cid->cid_ani);
- if (cid->cid_rdnis)
- free(cid->cid_rdnis);
-}
-
-/*--- ast_channel_free: Free a channel structure */
-void ast_channel_free(struct ast_channel *chan)
-{
- struct ast_channel *last=NULL, *cur;
- int fd;
- struct ast_var_t *vardata;
- struct ast_frame *f, *fp;
- struct varshead *headp;
- char name[AST_CHANNEL_NAME];
-
- headp=&chan->varshead;
-
- ast_mutex_lock(&chlock);
- cur = channels;
- while(cur) {
- if (cur == chan) {
- if (last)
- last->next = cur->next;
- else
- channels = cur->next;
- break;
- }
- last = cur;
- cur = cur->next;
- }
- if (!cur)
- ast_log(LOG_WARNING, "Unable to find channel in list\n");
- else {
- /* Lock and unlock the channel just to be sure nobody
- has it locked still */
- ast_mutex_lock(&cur->lock);
- ast_mutex_unlock(&cur->lock);
- }
- if (chan->tech_pvt) {
- ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name);
- free(chan->tech_pvt);
- }
-
- if (chan->sched)
- sched_context_destroy(chan->sched);
-
- ast_copy_string(name, chan->name, sizeof(name));
-
- /* Stop monitoring */
- if (chan->monitor) {
- chan->monitor->stop( chan, 0 );
- }
-
- /* If there is native format music-on-hold state, free it */
- if(chan->music_state)
- ast_moh_cleanup(chan);
-
- /* Free translatosr */
- if (chan->readtrans)
- ast_translator_free_path(chan->readtrans);
- if (chan->writetrans)
- ast_translator_free_path(chan->writetrans);
- if (chan->pbx)
- ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name);
- free_cid(&chan->cid);
- ast_mutex_destroy(&chan->lock);
- /* Close pipes if appropriate */
- if ((fd = chan->alertpipe[0]) > -1)
- close(fd);
- if ((fd = chan->alertpipe[1]) > -1)
- close(fd);
- if ((fd = chan->timingfd) > -1)
- close(fd);
- f = chan->readq;
- chan->readq = NULL;
- while(f) {
- fp = f;
- f = f->next;
- ast_frfree(fp);
- }
-
- /* loop over the variables list, freeing all data and deleting list items */
- /* no need to lock the list, as the channel is already locked */
-
- while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
- ast_var_delete(vardata);
-
- free(chan);
- ast_mutex_unlock(&chlock);
-
- ast_device_state_changed_literal(name);
-}
-
-int ast_channel_spy_add(struct ast_channel *chan, struct ast_channel_spy *spy)
-{
- if (!ast_test_flag(spy, CHANSPY_FORMAT_AUDIO)) {
- ast_log(LOG_WARNING, "Could not add channel spy '%s' to channel '%s', only audio format spies are supported.\n",
- spy->type, chan->name);
- return -1;
- }
-
- if (ast_test_flag(spy, CHANSPY_READ_VOLADJUST) && (spy->read_queue.format != AST_FORMAT_SLINEAR)) {
- ast_log(LOG_WARNING, "Cannot provide volume adjustment on '%s' format spies\n",
- ast_getformatname(spy->read_queue.format));
- return -1;
- }
-
- if (ast_test_flag(spy, CHANSPY_WRITE_VOLADJUST) && (spy->write_queue.format != AST_FORMAT_SLINEAR)) {
- ast_log(LOG_WARNING, "Cannot provide volume adjustment on '%s' format spies\n",
- ast_getformatname(spy->write_queue.format));
- return -1;
- }
-
- if (ast_test_flag(spy, CHANSPY_MIXAUDIO) &&
- ((spy->read_queue.format != AST_FORMAT_SLINEAR) ||
- (spy->write_queue.format != AST_FORMAT_SLINEAR))) {
- ast_log(LOG_WARNING, "Cannot provide audio mixing on '%s'-'%s' format spies\n",
- ast_getformatname(spy->read_queue.format), ast_getformatname(spy->write_queue.format));
- return -1;
- }
-
- if (!chan->spies) {
- if (!(chan->spies = calloc(1, sizeof(*chan->spies)))) {
- ast_log(LOG_WARNING, "Memory allocation failure\n");
- return -1;
- }
-
- AST_LIST_HEAD_INIT_NOLOCK(&chan->spies->list);
- AST_LIST_INSERT_HEAD(&chan->spies->list, spy, list);
- } else {
- AST_LIST_INSERT_TAIL(&chan->spies->list, spy, list);
- }
-
- if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE) {
- ast_cond_init(&spy->trigger, NULL);
- ast_set_flag(spy, CHANSPY_TRIGGER_READ);
- ast_clear_flag(spy, CHANSPY_TRIGGER_WRITE);
- }
-
- ast_log(LOG_DEBUG, "Spy %s added to channel %s\n",
- spy->type, chan->name);
-
- return 0;
-}
-
-void ast_channel_spy_stop_by_type(struct ast_channel *chan, const char *type)
-{
- struct ast_channel_spy *spy;
-
- if (!chan->spies)
- return;
-
- AST_LIST_TRAVERSE(&chan->spies->list, spy, list) {
- ast_mutex_lock(&spy->lock);
- if ((spy->type == type) && (spy->status == CHANSPY_RUNNING)) {
- spy->status = CHANSPY_STOP;
- if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE)
- ast_cond_signal(&spy->trigger);
- }
- ast_mutex_unlock(&spy->lock);
- }
-}
-
-void ast_channel_spy_trigger_wait(struct ast_channel_spy *spy)
-{
- ast_cond_wait(&spy->trigger, &spy->lock);
-}
-
-void ast_channel_spy_remove(struct ast_channel *chan, struct ast_channel_spy *spy)
-{
- struct ast_frame *f;
-
- if (!chan->spies)
- return;
-
- AST_LIST_REMOVE(&chan->spies->list, spy, list);
-
- ast_mutex_lock(&spy->lock);
-
- for (f = spy->read_queue.head; f; f = spy->read_queue.head) {
- spy->read_queue.head = f->next;
- ast_frfree(f);
- }
- for (f = spy->write_queue.head; f; f = spy->write_queue.head) {
- spy->write_queue.head = f->next;
- ast_frfree(f);
- }
-
- if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE)
- ast_cond_destroy(&spy->trigger);
-
- ast_mutex_unlock(&spy->lock);
-
- ast_log(LOG_DEBUG, "Spy %s removed from channel %s\n",
- spy->type, chan->name);
-
- if (AST_LIST_EMPTY(&chan->spies->list)) {
- if (chan->spies->read_translator.path)
- ast_translator_free_path(chan->spies->read_translator.path);
- if (chan->spies->write_translator.path)
- ast_translator_free_path(chan->spies->write_translator.path);
- free(chan->spies);
- chan->spies = NULL;
- }
-}
-
-static void detach_spies(struct ast_channel *chan)
-{
- struct ast_channel_spy *spy;
-
- if (!chan->spies)
- return;
-
- /* Marking the spies as done is sufficient. Chanspy or spy users will get the picture. */
- AST_LIST_TRAVERSE(&chan->spies->list, spy, list) {
- ast_mutex_lock(&spy->lock);
- if (spy->status == CHANSPY_RUNNING)
- spy->status = CHANSPY_DONE;
- if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE)
- ast_cond_signal(&spy->trigger);
- ast_mutex_unlock(&spy->lock);
- }
-
- AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->spies->list, spy, list)
- ast_channel_spy_remove(chan, spy);
- AST_LIST_TRAVERSE_SAFE_END;
-}
-
-/*--- ast_softhangup_nolock: Softly hangup a channel, don't lock */
-int ast_softhangup_nolock(struct ast_channel *chan, int cause)
-{
- int res = 0;
- struct ast_frame f = { AST_FRAME_NULL };
- if (option_debug)
- ast_log(LOG_DEBUG, "Soft-Hanging up channel '%s'\n", chan->name);
- /* Inform channel driver that we need to be hung up, if it cares */
- chan->_softhangup |= cause;
- ast_queue_frame(chan, &f);
- /* Interrupt any poll call or such */
- if (ast_test_flag(chan, AST_FLAG_BLOCKING))
- pthread_kill(chan->blocker, SIGURG);
- return res;
-}
-
-/*--- ast_softhangup_nolock: Softly hangup a channel, lock */
-int ast_softhangup(struct ast_channel *chan, int cause)
-{
- int res;
- ast_mutex_lock(&chan->lock);
- res = ast_softhangup_nolock(chan, cause);
- ast_mutex_unlock(&chan->lock);
- return res;
-}
-
-enum spy_direction {
- SPY_READ,
- SPY_WRITE,
-};
-
-#define SPY_QUEUE_SAMPLE_LIMIT 4000 /* half of one second */
-
-static void queue_frame_to_spies(struct ast_channel *chan, struct ast_frame *f, enum spy_direction dir)
-{
- struct ast_frame *translated_frame = NULL;
- struct ast_channel_spy *spy;
- struct ast_channel_spy_queue *queue;
- struct ast_channel_spy_queue *other_queue;
- struct channel_spy_trans *trans;
- struct ast_frame *last;
-
- trans = (dir == SPY_READ) ? &chan->spies->read_translator : &chan->spies->write_translator;
-
- AST_LIST_TRAVERSE(&chan->spies->list, spy, list) {
- ast_mutex_lock(&spy->lock);
-
- queue = (dir == SPY_READ) ? &spy->read_queue : &spy->write_queue;
-
- if ((queue->format == AST_FORMAT_SLINEAR) && (f->subclass != AST_FORMAT_SLINEAR)) {
- if (!translated_frame) {
- if (trans->path && (trans->last_format != f->subclass)) {
- ast_translator_free_path(trans->path);
- trans->path = NULL;
- }
- if (!trans->path) {
- ast_log(LOG_DEBUG, "Building translator from %s to SLINEAR for spies on channel %s\n",
- ast_getformatname(f->subclass), chan->name);
- if ((trans->path = ast_translator_build_path(AST_FORMAT_SLINEAR, f->subclass)) == NULL) {
- ast_log(LOG_WARNING, "Cannot build a path from %s to %s\n",
- ast_getformatname(f->subclass), ast_getformatname(AST_FORMAT_SLINEAR));
- ast_mutex_unlock(&spy->lock);
- continue;
- } else {
- trans->last_format = f->subclass;
- }
- }
- if (!(translated_frame = ast_translate(trans->path, f, 0))) {
- ast_log(LOG_ERROR, "Translation to %s failed, dropping frame for spies\n",
- ast_getformatname(AST_FORMAT_SLINEAR));
- ast_mutex_unlock(&spy->lock);
- break;
- }
- }
-
- for (last = queue->head; last && last->next; last = last->next);
- if (last)
- last->next = ast_frdup(translated_frame);
- else
- queue->head = ast_frdup(translated_frame);
- } else {
- if (f->subclass != queue->format) {
- ast_log(LOG_WARNING, "Spy '%s' on channel '%s' wants format '%s', but frame is '%s', dropping\n",
- spy->type, chan->name,
- ast_getformatname(queue->format), ast_getformatname(f->subclass));
- ast_mutex_unlock(&spy->lock);
- continue;
- }
-
- for (last = queue->head; last && last->next; last = last->next);
- if (last)
- last->next = ast_frdup(f);
- else
- queue->head = ast_frdup(f);
- }
-
- queue->samples += f->samples;
-
- if (queue->samples > SPY_QUEUE_SAMPLE_LIMIT) {
- if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE) {
- other_queue = (dir == SPY_WRITE) ? &spy->read_queue : &spy->write_queue;
-
- if (other_queue->samples == 0) {
- switch (ast_test_flag(spy, CHANSPY_TRIGGER_MODE)) {
- case CHANSPY_TRIGGER_READ:
- if (dir == SPY_WRITE) {
- ast_set_flag(spy, CHANSPY_TRIGGER_WRITE);
- ast_clear_flag(spy, CHANSPY_TRIGGER_READ);
- if (option_debug)
- ast_log(LOG_DEBUG, "Switching spy '%s' on '%s' to write-trigger mode\n",
- spy->type, chan->name);
- }
- break;
- case CHANSPY_TRIGGER_WRITE:
- if (dir == SPY_READ) {
- ast_set_flag(spy, CHANSPY_TRIGGER_READ);
- ast_clear_flag(spy, CHANSPY_TRIGGER_WRITE);
- if (option_debug)
- ast_log(LOG_DEBUG, "Switching spy '%s' on '%s' to read-trigger mode\n",
- spy->type, chan->name);
- }
- break;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Triggering queue flush for spy '%s' on '%s'\n",
- spy->type, chan->name);
- ast_set_flag(spy, CHANSPY_TRIGGER_FLUSH);
- ast_cond_signal(&spy->trigger);
- ast_mutex_unlock(&spy->lock);
- continue;
- }
- }
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Spy '%s' on channel '%s' %s queue too long, dropping frames\n",
- spy->type, chan->name, (dir == SPY_READ) ? "read" : "write");
- while (queue->samples > SPY_QUEUE_SAMPLE_LIMIT) {
- struct ast_frame *drop = queue->head;
-
- queue->samples -= drop->samples;
- queue->head = drop->next;
- ast_frfree(drop);
- }
- } else {
- switch (ast_test_flag(spy, CHANSPY_TRIGGER_MODE)) {
- case CHANSPY_TRIGGER_READ:
- if (dir == SPY_READ)
- ast_cond_signal(&spy->trigger);
- break;
- case CHANSPY_TRIGGER_WRITE:
- if (dir == SPY_WRITE)
- ast_cond_signal(&spy->trigger);
- break;
- }
- }
-
- ast_mutex_unlock(&spy->lock);
- }
-
- if (translated_frame)
- ast_frfree(translated_frame);
-}
-
-static void free_translation(struct ast_channel *clone)
-{
- if (clone->writetrans)
- ast_translator_free_path(clone->writetrans);
- if (clone->readtrans)
- ast_translator_free_path(clone->readtrans);
- clone->writetrans = NULL;
- clone->readtrans = NULL;
- clone->rawwriteformat = clone->nativeformats;
- clone->rawreadformat = clone->nativeformats;
-}
-
-/*--- ast_hangup: Hangup a channel */
-int ast_hangup(struct ast_channel *chan)
-{
- int res = 0;
-
- /* Don't actually hang up a channel that will masquerade as someone else, or
- if someone is going to masquerade as us */
- ast_mutex_lock(&chan->lock);
-
- detach_spies(chan); /* get rid of spies */
-
- if (chan->masq) {
- if (ast_do_masquerade(chan))
- ast_log(LOG_WARNING, "Failed to perform masquerade\n");
- }
-
- if (chan->masq) {
- ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name);
- ast_mutex_unlock(&chan->lock);
- return 0;
- }
- /* If this channel is one which will be masqueraded into something,
- mark it as a zombie already, so we know to free it later */
- if (chan->masqr) {
- ast_set_flag(chan, AST_FLAG_ZOMBIE);
- ast_mutex_unlock(&chan->lock);
- return 0;
- }
- free_translation(chan);
- if (chan->stream) /* Close audio stream */
- ast_closestream(chan->stream);
- if (chan->vstream) /* Close video stream */
- ast_closestream(chan->vstream);
- if (chan->sched) {
- sched_context_destroy(chan->sched);
- chan->sched = NULL;
- }
-
- if (chan->generatordata) /* Clear any tone stuff remaining */
- chan->generator->release(chan, chan->generatordata);
- chan->generatordata = NULL;
- chan->generator = NULL;
- if (chan->cdr) { /* End the CDR if it hasn't already */
- ast_cdr_end(chan->cdr);
- ast_cdr_detach(chan->cdr); /* Post and Free the CDR */
- chan->cdr = NULL;
- }
- if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
- ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
- "is blocked by thread %ld in procedure %s! Expect a failure\n",
- (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc);
- CRASH;
- }
- if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Hanging up channel '%s'\n", chan->name);
- if (chan->tech->hangup)
- res = chan->tech->hangup(chan);
- } else {
- if (option_debug)
- ast_log(LOG_DEBUG, "Hanging up zombie '%s'\n", chan->name);
- }
-
- ast_mutex_unlock(&chan->lock);
- manager_event(EVENT_FLAG_CALL, "Hangup",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Cause: %d\r\n"
- "Cause-txt: %s\r\n",
- chan->name,
- chan->uniqueid,
- chan->hangupcause,
- ast_cause2str(chan->hangupcause)
- );
- ast_channel_free(chan);
- return res;
-}
-
-int ast_answer(struct ast_channel *chan)
-{
- int res = 0;
- ast_mutex_lock(&chan->lock);
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
- ast_mutex_unlock(&chan->lock);
- return -1;
- }
- switch(chan->_state) {
- case AST_STATE_RINGING:
- case AST_STATE_RING:
- if (chan->tech->answer)
- res = chan->tech->answer(chan);
- ast_setstate(chan, AST_STATE_UP);
- if (chan->cdr)
- ast_cdr_answer(chan->cdr);
- ast_mutex_unlock(&chan->lock);
- return res;
- break;
- case AST_STATE_UP:
- if (chan->cdr)
- ast_cdr_answer(chan->cdr);
- break;
- }
- ast_mutex_unlock(&chan->lock);
- return 0;
-}
-
-
-
-void ast_deactivate_generator(struct ast_channel *chan)
-{
- ast_mutex_lock(&chan->lock);
- if (chan->generatordata) {
- if (chan->generator && chan->generator->release)
- chan->generator->release(chan, chan->generatordata);
- chan->generatordata = NULL;
- chan->generator = NULL;
- ast_clear_flag(chan, AST_FLAG_WRITE_INT);
- ast_settimeout(chan, 0, NULL, NULL);
- }
- ast_mutex_unlock(&chan->lock);
-}
-
-static int generator_force(void *data)
-{
- /* Called if generator doesn't have data */
- void *tmp;
- int res;
- int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples);
- struct ast_channel *chan = data;
- tmp = chan->generatordata;
- chan->generatordata = NULL;
- generate = chan->generator->generate;
- res = generate(chan, tmp, 0, 160);
- chan->generatordata = tmp;
- if (res) {
- ast_log(LOG_DEBUG, "Auto-deactivating generator\n");
- ast_deactivate_generator(chan);
- }
- return 0;
-}
-
-int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
-{
- int res = 0;
-
- ast_mutex_lock(&chan->lock);
-
- if (chan->generatordata) {
- if (chan->generator && chan->generator->release)
- chan->generator->release(chan, chan->generatordata);
- chan->generatordata = NULL;
- }
-
- ast_prod(chan);
- if (gen->alloc) {
- if (!(chan->generatordata = gen->alloc(chan, params)))
- res = -1;
- }
-
- if (!res) {
- ast_settimeout(chan, 160, generator_force, chan);
- chan->generator = gen;
- }
-
- ast_mutex_unlock(&chan->lock);
-
- return res;
-}
-
-/*--- ast_waitfor_n_fd: Wait for x amount of time on a file descriptor to have input. */
-int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception)
-{
- struct timeval start = { 0 , 0 };
- int res;
- int x, y;
- int winner = -1;
- int spoint;
- struct pollfd *pfds;
-
- pfds = alloca(sizeof(struct pollfd) * n);
- if (!pfds) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
- if (*ms > 0)
- start = ast_tvnow();
- y = 0;
- for (x=0; x < n; x++) {
- if (fds[x] > -1) {
- pfds[y].fd = fds[x];
- pfds[y].events = POLLIN | POLLPRI;
- y++;
- }
- }
- res = poll(pfds, y, *ms);
- if (res < 0) {
- /* Simulate a timeout if we were interrupted */
- if (errno != EINTR)
- *ms = -1;
- else
- *ms = 0;
- return -1;
- }
- spoint = 0;
- for (x=0; x < n; x++) {
- if (fds[x] > -1) {
- if ((res = ast_fdisset(pfds, fds[x], y, &spoint))) {
- winner = fds[x];
- if (exception) {
- if (res & POLLPRI)
- *exception = -1;
- else
- *exception = 0;
- }
- }
- }
- }
- if (*ms > 0) {
- *ms -= ast_tvdiff_ms(ast_tvnow(), start);
- if (*ms < 0)
- *ms = 0;
- }
- return winner;
-}
-
-/*--- ast_waitfor_nanfds: Wait for x amount of time on a file descriptor to have input. */
-struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, int nfds,
- int *exception, int *outfd, int *ms)
-{
- struct timeval start = { 0 , 0 };
- struct pollfd *pfds;
- int res;
- long rms;
- int x, y, max;
- int spoint;
- time_t now = 0;
- long whentohangup = 0, havewhen = 0, diff;
- struct ast_channel *winner = NULL;
-
- pfds = alloca(sizeof(struct pollfd) * (n * AST_MAX_FDS + nfds));
- if (!pfds) {
- ast_log(LOG_ERROR, "Out of memory\n");
- *outfd = -1;
- return NULL;
- }
-
- if (outfd)
- *outfd = -99999;
- if (exception)
- *exception = 0;
-
- /* Perform any pending masquerades */
- for (x=0; x < n; x++) {
- ast_mutex_lock(&c[x]->lock);
- if (c[x]->whentohangup) {
- if (!havewhen)
- time(&now);
- diff = c[x]->whentohangup - now;
- if (!havewhen || (diff < whentohangup)) {
- havewhen++;
- whentohangup = diff;
- }
- }
- if (c[x]->masq) {
- if (ast_do_masquerade(c[x])) {
- ast_log(LOG_WARNING, "Masquerade failed\n");
- *ms = -1;
- ast_mutex_unlock(&c[x]->lock);
- return NULL;
- }
- }
- ast_mutex_unlock(&c[x]->lock);
- }
-
- rms = *ms;
-
- if (havewhen) {
- if ((*ms < 0) || (whentohangup * 1000 < *ms)) {
- rms = whentohangup * 1000;
- }
- }
- max = 0;
- for (x=0; x < n; x++) {
- for (y=0; y< AST_MAX_FDS; y++) {
- if (c[x]->fds[y] > -1) {
- pfds[max].fd = c[x]->fds[y];
- pfds[max].events = POLLIN | POLLPRI;
- pfds[max].revents = 0;
- max++;
- }
- }
- CHECK_BLOCKING(c[x]);
- }
- for (x=0; x < nfds; x++) {
- if (fds[x] > -1) {
- pfds[max].fd = fds[x];
- pfds[max].events = POLLIN | POLLPRI;
- pfds[max].revents = 0;
- max++;
- }
- }
- if (*ms > 0)
- start = ast_tvnow();
-
- if (sizeof(int) == 4) {
- do {
- int kbrms = rms;
- if (kbrms > 600000)
- kbrms = 600000;
- res = poll(pfds, max, kbrms);
- if (!res)
- rms -= kbrms;
- } while (!res && (rms > 0));
- } else {
- res = poll(pfds, max, rms);
- }
-
- if (res < 0) {
- for (x=0; x < n; x++)
- ast_clear_flag(c[x], AST_FLAG_BLOCKING);
- /* Simulate a timeout if we were interrupted */
- if (errno != EINTR)
- *ms = -1;
- else {
- /* Just an interrupt */
-#if 0
- *ms = 0;
-#endif
- }
- return NULL;
- } else {
- /* If no fds signalled, then timeout. So set ms = 0
- since we may not have an exact timeout.
- */
- if (res == 0)
- *ms = 0;
- }
-
- if (havewhen)
- time(&now);
- spoint = 0;
- for (x=0; x < n; x++) {
- ast_clear_flag(c[x], AST_FLAG_BLOCKING);
- if (havewhen && c[x]->whentohangup && (now > c[x]->whentohangup)) {
- c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
- if (!winner)
- winner = c[x];
- }
- for (y=0; y < AST_MAX_FDS; y++) {
- if (c[x]->fds[y] > -1) {
- if ((res = ast_fdisset(pfds, c[x]->fds[y], max, &spoint))) {
- if (res & POLLPRI)
- ast_set_flag(c[x], AST_FLAG_EXCEPTION);
- else
- ast_clear_flag(c[x], AST_FLAG_EXCEPTION);
- c[x]->fdno = y;
- winner = c[x];
- }
- }
- }
- }
- for (x=0; x < nfds; x++) {
- if (fds[x] > -1) {
- if ((res = ast_fdisset(pfds, fds[x], max, &spoint))) {
- if (outfd)
- *outfd = fds[x];
- if (exception) {
- if (res & POLLPRI)
- *exception = -1;
- else
- *exception = 0;
- }
- winner = NULL;
- }
- }
- }
- if (*ms > 0) {
- *ms -= ast_tvdiff_ms(ast_tvnow(), start);
- if (*ms < 0)
- *ms = 0;
- }
- return winner;
-}
-
-struct ast_channel *ast_waitfor_n(struct ast_channel **c, int n, int *ms)
-{
- return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
-}
-
-int ast_waitfor(struct ast_channel *c, int ms)
-{
- struct ast_channel *chan;
- int oldms = ms;
-
- chan = ast_waitfor_n(&c, 1, &ms);
- if (ms < 0) {
- if (oldms < 0)
- return 0;
- else
- return -1;
- }
- return ms;
-}
-
-int ast_waitfordigit(struct ast_channel *c, int ms)
-{
- /* XXX Should I be merged with waitfordigit_full XXX */
- struct ast_frame *f;
- int result = 0;
-
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
- return -1;
-
- /* Wait for a digit, no more than ms milliseconds total. */
- while(ms && !result) {
- ms = ast_waitfor(c, ms);
- if (ms < 0) /* Error */
- result = -1;
- else if (ms > 0) {
- /* Read something */
- f = ast_read(c);
- if (f) {
- if (f->frametype == AST_FRAME_DTMF)
- result = f->subclass;
- ast_frfree(f);
- } else
- result = -1;
- }
- }
- return result;
-}
-
-int ast_settimeout(struct ast_channel *c, int samples, int (*func)(void *data), void *data)
-{
- int res = -1;
-#ifdef ZAPTEL_OPTIMIZATIONS
- if (c->timingfd > -1) {
- if (!func) {
- samples = 0;
- data = 0;
- }
- ast_log(LOG_DEBUG, "Scheduling timer at %d sample intervals\n", samples);
- res = ioctl(c->timingfd, ZT_TIMERCONFIG, &samples);
- c->timingfunc = func;
- c->timingdata = data;
- }
-#endif
- return res;
-}
-
-int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int cmdfd)
-{
- struct ast_frame *f;
- struct ast_channel *rchan;
- int outfd;
- int res;
-
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
- return -1;
- /* Wait for a digit, no more than ms milliseconds total. */
- while(ms) {
- errno = 0;
- rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
- if ((!rchan) && (outfd < 0) && (ms)) {
- if (errno == 0 || errno == EINTR)
- continue;
- ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
- return -1;
- } else if (outfd > -1) {
- /* The FD we were watching has something waiting */
- return 1;
- } else if (rchan) {
- f = ast_read(c);
- if(!f) {
- return -1;
- }
-
- switch(f->frametype) {
- case AST_FRAME_DTMF:
- res = f->subclass;
- ast_frfree(f);
- return res;
- case AST_FRAME_CONTROL:
- switch(f->subclass) {
- case AST_CONTROL_HANGUP:
- ast_frfree(f);
- return -1;
- case AST_CONTROL_RINGING:
- case AST_CONTROL_ANSWER:
- /* Unimportant */
- break;
- default:
- ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass);
- }
- case AST_FRAME_VOICE:
- /* Write audio if appropriate */
- if (audiofd > -1)
- write(audiofd, f->data, f->datalen);
- }
- /* Ignore */
- ast_frfree(f);
- }
- }
- return 0; /* Time is up */
-}
-
-struct ast_frame *ast_read(struct ast_channel *chan)
-{
- struct ast_frame *f = NULL;
- int blah;
- int prestate;
-#ifdef ZAPTEL_OPTIMIZATIONS
- int (*func)(void *);
- void *data;
- int res;
-#endif
- static struct ast_frame null_frame = {
- AST_FRAME_NULL,
- };
-
- ast_mutex_lock(&chan->lock);
- if (chan->masq) {
- if (ast_do_masquerade(chan)) {
- ast_log(LOG_WARNING, "Failed to perform masquerade\n");
- f = NULL;
- } else
- f = &null_frame;
- ast_mutex_unlock(&chan->lock);
- return f;
- }
-
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
- if (chan->generator)
- ast_deactivate_generator(chan);
- ast_mutex_unlock(&chan->lock);
- return NULL;
- }
- prestate = chan->_state;
-
- if (!ast_test_flag(chan, AST_FLAG_DEFER_DTMF) && !ast_strlen_zero(chan->dtmfq)) {
- /* We have DTMF that has been deferred. Return it now */
- chan->dtmff.frametype = AST_FRAME_DTMF;
- chan->dtmff.subclass = chan->dtmfq[0];
- /* Drop first digit */
- memmove(chan->dtmfq, chan->dtmfq + 1, sizeof(chan->dtmfq) - 1);
- ast_mutex_unlock(&chan->lock);
- return &chan->dtmff;
- }
-
- /* Read and ignore anything on the alertpipe, but read only
- one sizeof(blah) per frame that we send from it */
- if (chan->alertpipe[0] > -1) {
- read(chan->alertpipe[0], &blah, sizeof(blah));
- }
-#ifdef ZAPTEL_OPTIMIZATIONS
- if ((chan->timingfd > -1) && (chan->fdno == AST_MAX_FDS - 2) && ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
- ast_clear_flag(chan, AST_FLAG_EXCEPTION);
- blah = -1;
- /* IF we can't get event, assume it's an expired as-per the old interface */
- res = ioctl(chan->timingfd, ZT_GETEVENT, &blah);
- if (res)
- blah = ZT_EVENT_TIMER_EXPIRED;
-
- if (blah == ZT_EVENT_TIMER_PING) {
-#if 0
- ast_log(LOG_NOTICE, "Oooh, there's a PING!\n");
-#endif
- if (!chan->readq || !chan->readq->next) {
- /* Acknowledge PONG unless we need it again */
-#if 0
- ast_log(LOG_NOTICE, "Sending a PONG!\n");
-#endif
- if (ioctl(chan->timingfd, ZT_TIMERPONG, &blah)) {
- ast_log(LOG_WARNING, "Failed to pong timer on '%s': %s\n", chan->name, strerror(errno));
- }
- }
- } else if (blah == ZT_EVENT_TIMER_EXPIRED) {
- ioctl(chan->timingfd, ZT_TIMERACK, &blah);
- func = chan->timingfunc;
- data = chan->timingdata;
- ast_mutex_unlock(&chan->lock);
- if (func) {
-#if 0
- ast_log(LOG_DEBUG, "Calling private function\n");
-#endif
- func(data);
- } else {
- blah = 0;
- ast_mutex_lock(&chan->lock);
- ioctl(chan->timingfd, ZT_TIMERCONFIG, &blah);
- chan->timingdata = NULL;
- ast_mutex_unlock(&chan->lock);
- }
- f = &null_frame;
- return f;
- } else
- ast_log(LOG_NOTICE, "No/unknown event '%d' on timer for '%s'?\n", blah, chan->name);
- }
-#endif
- /* Check for pending read queue */
- if (chan->readq) {
- f = chan->readq;
- chan->readq = f->next;
- /* Interpret hangup and return NULL */
- if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) {
- ast_frfree(f);
- f = NULL;
- }
- } else {
- chan->blocker = pthread_self();
- if (ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
- if (chan->tech->exception)
- f = chan->tech->exception(chan);
- else {
- ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", chan->name);
- f = &null_frame;
- }
- /* Clear the exception flag */
- ast_clear_flag(chan, AST_FLAG_EXCEPTION);
- } else {
- if (chan->tech->read)
- f = chan->tech->read(chan);
- else
- ast_log(LOG_WARNING, "No read routine on channel %s\n", chan->name);
- }
- }
-
-
- if (f && (f->frametype == AST_FRAME_VOICE)) {
- if (!(f->subclass & chan->nativeformats)) {
- /* This frame can't be from the current native formats -- drop it on the
- floor */
- ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n", chan->name, ast_getformatname(f->subclass), ast_getformatname(chan->nativeformats));
- ast_frfree(f);
- f = &null_frame;
- } else {
- if (chan->spies)
- queue_frame_to_spies(chan, f, SPY_READ);
-
- if (chan->monitor && chan->monitor->read_stream ) {
-#ifndef MONITOR_CONSTANT_DELAY
- int jump = chan->outsmpl - chan->insmpl - 4 * f->samples;
- if (jump >= 0) {
- if (ast_seekstream(chan->monitor->read_stream, jump + f->samples, SEEK_FORCECUR) == -1)
- ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
- chan->insmpl += jump + 4 * f->samples;
- } else
- chan->insmpl+= f->samples;
-#else
- int jump = chan->outsmpl - chan->insmpl;
- if (jump - MONITOR_DELAY >= 0) {
- if (ast_seekstream(chan->monitor->read_stream, jump - f->samples, SEEK_FORCECUR) == -1)
- ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
- chan->insmpl += jump;
- } else
- chan->insmpl += f->samples;
-#endif
- if (ast_writestream(chan->monitor->read_stream, f) < 0)
- ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n");
- }
- if (chan->readtrans) {
- f = ast_translate(chan->readtrans, f, 1);
- if (!f)
- f = &null_frame;
- }
- }
- }
-
- /* Make sure we always return NULL in the future */
- if (!f) {
- chan->_softhangup |= AST_SOFTHANGUP_DEV;
- if (chan->generator)
- ast_deactivate_generator(chan);
- /* End the CDR if appropriate */
- if (chan->cdr)
- ast_cdr_end(chan->cdr);
- } else if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF) && f->frametype == AST_FRAME_DTMF) {
- if (strlen(chan->dtmfq) < sizeof(chan->dtmfq) - 2)
- chan->dtmfq[strlen(chan->dtmfq)] = f->subclass;
- else
- ast_log(LOG_WARNING, "Dropping deferred DTMF digits on %s\n", chan->name);
- f = &null_frame;
- } else if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_ANSWER)) {
- if (prestate == AST_STATE_UP) {
- ast_log(LOG_DEBUG, "Dropping duplicate answer!\n");
- f = &null_frame;
- }
- /* Answer the CDR */
- ast_setstate(chan, AST_STATE_UP);
- ast_cdr_answer(chan->cdr);
- }
-
- /* Run any generator sitting on the line */
- if (f && (f->frametype == AST_FRAME_VOICE) && chan->generatordata) {
- /* Mask generator data temporarily and apply. If there is a timing function, it
- will be calling the generator instead */
- void *tmp;
- int res;
- int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples);
-
- if (chan->timingfunc) {
- ast_log(LOG_DEBUG, "Generator got voice, switching to phase locked mode\n");
- ast_settimeout(chan, 0, NULL, NULL);
- }
- tmp = chan->generatordata;
- chan->generatordata = NULL;
- generate = chan->generator->generate;
- res = generate(chan, tmp, f->datalen, f->samples);
- chan->generatordata = tmp;
- if (res) {
- ast_log(LOG_DEBUG, "Auto-deactivating generator\n");
- ast_deactivate_generator(chan);
- }
- } else if (f && (f->frametype == AST_FRAME_CNG)) {
- if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) {
- ast_log(LOG_DEBUG, "Generator got CNG, switching to zap timed mode\n");
- ast_settimeout(chan, 160, generator_force, chan);
- }
- }
- /* High bit prints debugging */
- if (chan->fin & 0x80000000)
- ast_frame_dump(chan->name, f, "<<");
- if ((chan->fin & 0x7fffffff) == 0x7fffffff)
- chan->fin &= 0x80000000;
- else
- chan->fin++;
- ast_mutex_unlock(&chan->lock);
- return f;
-}
-
-int ast_indicate(struct ast_channel *chan, int condition)
-{
- int res = -1;
-
- ast_mutex_lock(&chan->lock);
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
- ast_mutex_unlock(&chan->lock);
- return -1;
- }
- if (chan->tech->indicate)
- res = chan->tech->indicate(chan, condition);
- ast_mutex_unlock(&chan->lock);
- if (!chan->tech->indicate || res) {
- /*
- * Device does not support (that) indication, lets fake
- * it by doing our own tone generation. (PM2002)
- */
- if (condition >= 0) {
- const struct tone_zone_sound *ts = NULL;
- switch (condition) {
- case AST_CONTROL_RINGING:
- ts = ast_get_indication_tone(chan->zone, "ring");
- break;
- case AST_CONTROL_BUSY:
- ts = ast_get_indication_tone(chan->zone, "busy");
- break;
- case AST_CONTROL_CONGESTION:
- ts = ast_get_indication_tone(chan->zone, "congestion");
- break;
- }
- if (ts && ts->data[0]) {
- ast_log(LOG_DEBUG, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
- ast_playtones_start(chan,0,ts->data, 1);
- res = 0;
- } else if (condition == AST_CONTROL_PROGRESS) {
- /* ast_playtones_stop(chan); */
- } else if (condition == AST_CONTROL_PROCEEDING) {
- /* Do nothing, really */
- } else if (condition == AST_CONTROL_HOLD) {
- /* Do nothing.... */
- } else if (condition == AST_CONTROL_UNHOLD) {
- /* Do nothing.... */
- } else if (condition == AST_CONTROL_VIDUPDATE) {
- /* Do nothing.... */
- } else {
- /* not handled */
- ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name);
- res = -1;
- }
- }
- else ast_playtones_stop(chan);
- }
- return res;
-}
-
-int ast_recvchar(struct ast_channel *chan, int timeout)
-{
- int c;
- char *buf = ast_recvtext(chan, timeout);
- if (buf == NULL)
- return -1; /* error or timeout */
- c = *(unsigned char *)buf;
- free(buf);
- return c;
-}
-
-char *ast_recvtext(struct ast_channel *chan, int timeout)
-{
- int res, done = 0;
- char *buf = NULL;
-
- while (!done) {
- struct ast_frame *f;
- if (ast_check_hangup(chan))
- break;
- res = ast_waitfor(chan, timeout);
- if (res <= 0) /* timeout or error */
- break;
- timeout = res; /* update timeout */
- f = ast_read(chan);
- if (f == NULL)
- break; /* no frame */
- if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
- done = 1; /* force a break */
- else if (f->frametype == AST_FRAME_TEXT) { /* what we want */
- buf = strndup((char *) f->data, f->datalen); /* dup and break */
- done = 1;
- }
- ast_frfree(f);
- }
- return buf;
-}
-
-int ast_sendtext(struct ast_channel *chan, const char *text)
-{
- int res = 0;
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
- return -1;
- CHECK_BLOCKING(chan);
- if (chan->tech->send_text)
- res = chan->tech->send_text(chan, text);
- ast_clear_flag(chan, AST_FLAG_BLOCKING);
- return res;
-}
-
-static int do_senddigit(struct ast_channel *chan, char digit)
-{
- int res = -1;
-
- if (chan->tech->send_digit)
- res = chan->tech->send_digit(chan, digit);
- if (!chan->tech->send_digit || res) {
- /*
- * Device does not support DTMF tones, lets fake
- * it by doing our own generation. (PM2002)
- */
- static const char* dtmf_tones[] = {
- "!941+1336/100,!0/100", /* 0 */
- "!697+1209/100,!0/100", /* 1 */
- "!697+1336/100,!0/100", /* 2 */
- "!697+1477/100,!0/100", /* 3 */
- "!770+1209/100,!0/100", /* 4 */
- "!770+1336/100,!0/100", /* 5 */
- "!770+1477/100,!0/100", /* 6 */
- "!852+1209/100,!0/100", /* 7 */
- "!852+1336/100,!0/100", /* 8 */
- "!852+1477/100,!0/100", /* 9 */
- "!697+1633/100,!0/100", /* A */
- "!770+1633/100,!0/100", /* B */
- "!852+1633/100,!0/100", /* C */
- "!941+1633/100,!0/100", /* D */
- "!941+1209/100,!0/100", /* * */
- "!941+1477/100,!0/100" }; /* # */
- if (digit >= '0' && digit <='9')
- ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
- else if (digit >= 'A' && digit <= 'D')
- ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
- else if (digit == '*')
- ast_playtones_start(chan, 0, dtmf_tones[14], 0);
- else if (digit == '#')
- ast_playtones_start(chan, 0, dtmf_tones[15], 0);
- else {
- /* not handled */
- ast_log(LOG_DEBUG, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name);
- }
- }
- return 0;
-}
-
-int ast_senddigit(struct ast_channel *chan, char digit)
-{
- return do_senddigit(chan, digit);
-}
-
-int ast_prod(struct ast_channel *chan)
-{
- struct ast_frame a = { AST_FRAME_VOICE };
- char nothing[128];
-
- /* Send an empty audio frame to get things moving */
- if (chan->_state != AST_STATE_UP) {
- ast_log(LOG_DEBUG, "Prodding channel '%s'\n", chan->name);
- a.subclass = chan->rawwriteformat;
- a.data = nothing + AST_FRIENDLY_OFFSET;
- a.src = "ast_prod";
- if (ast_write(chan, &a))
- ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name);
- }
- return 0;
-}
-
-int ast_write_video(struct ast_channel *chan, struct ast_frame *fr)
-{
- int res;
- if (!chan->tech->write_video)
- return 0;
- res = ast_write(chan, fr);
- if (!res)
- res = 1;
- return res;
-}
-
-int ast_write(struct ast_channel *chan, struct ast_frame *fr)
-{
- int res = -1;
- struct ast_frame *f = NULL;
- /* Stop if we're a zombie or need a soft hangup */
- ast_mutex_lock(&chan->lock);
- if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
- ast_mutex_unlock(&chan->lock);
- return -1;
- }
- /* Handle any pending masquerades */
- if (chan->masq) {
- if (ast_do_masquerade(chan)) {
- ast_log(LOG_WARNING, "Failed to perform masquerade\n");
- ast_mutex_unlock(&chan->lock);
- return -1;
- }
- }
- if (chan->masqr) {
- ast_mutex_unlock(&chan->lock);
- return 0;
- }
- if (chan->generatordata) {
- if (ast_test_flag(chan, AST_FLAG_WRITE_INT))
- ast_deactivate_generator(chan);
- else {
- ast_mutex_unlock(&chan->lock);
- return 0;
- }
- }
- /* High bit prints debugging */
- if (chan->fout & 0x80000000)
- ast_frame_dump(chan->name, fr, ">>");
- CHECK_BLOCKING(chan);
- switch(fr->frametype) {
- case AST_FRAME_CONTROL:
- /* XXX Interpret control frames XXX */
- ast_log(LOG_WARNING, "Don't know how to handle control frames yet\n");
- break;
- case AST_FRAME_DTMF:
- ast_clear_flag(chan, AST_FLAG_BLOCKING);
- ast_mutex_unlock(&chan->lock);
- res = do_senddigit(chan,fr->subclass);
- ast_mutex_lock(&chan->lock);
- CHECK_BLOCKING(chan);
- break;
- case AST_FRAME_TEXT:
- if (chan->tech->send_text)
- res = chan->tech->send_text(chan, (char *) fr->data);
- else
- res = 0;
- break;
- case AST_FRAME_HTML:
- if (chan->tech->send_html)
- res = chan->tech->send_html(chan, fr->subclass, (char *) fr->data, fr->datalen);
- else
- res = 0;
- break;
- case AST_FRAME_VIDEO:
- /* XXX Handle translation of video codecs one day XXX */
- if (chan->tech->write_video)
- res = chan->tech->write_video(chan, fr);
- else
- res = 0;
- break;
- default:
- if (chan->tech->write) {
- f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr;
- if (f) {
- if (f->frametype == AST_FRAME_VOICE && chan->spies)
- queue_frame_to_spies(chan, f, SPY_WRITE);
-
- if( chan->monitor && chan->monitor->write_stream &&
- f && ( f->frametype == AST_FRAME_VOICE ) ) {
-#ifndef MONITOR_CONSTANT_DELAY
- int jump = chan->insmpl - chan->outsmpl - 4 * f->samples;
- if (jump >= 0) {
- if (ast_seekstream(chan->monitor->write_stream, jump + f->samples, SEEK_FORCECUR) == -1)
- ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
- chan->outsmpl += jump + 4 * f->samples;
- } else
- chan->outsmpl += f->samples;
-#else
- int jump = chan->insmpl - chan->outsmpl;
- if (jump - MONITOR_DELAY >= 0) {
- if (ast_seekstream(chan->monitor->write_stream, jump - f->samples, SEEK_FORCECUR) == -1)
- ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
- chan->outsmpl += jump;
- } else
- chan->outsmpl += f->samples;
-#endif
- if (ast_writestream(chan->monitor->write_stream, f) < 0)
- ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
- }
-
- res = chan->tech->write(chan, f);
- } else
- res = 0;
- }
- }
-
- /* It's possible this is a translated frame */
- if (f && f->frametype == AST_FRAME_DTMF) {
- ast_log(LOG_DTMF, "%s : %c\n", chan->name, f->subclass);
- } else if (fr->frametype == AST_FRAME_DTMF) {
- ast_log(LOG_DTMF, "%s : %c\n", chan->name, fr->subclass);
- }
-
- if (f && (f != fr))
- ast_frfree(f);
- ast_clear_flag(chan, AST_FLAG_BLOCKING);
- /* Consider a write failure to force a soft hangup */
- if (res < 0)
- chan->_softhangup |= AST_SOFTHANGUP_DEV;
- else {
- if ((chan->fout & 0x7fffffff) == 0x7fffffff)
- chan->fout &= 0x80000000;
- else
- chan->fout++;
- }
- ast_mutex_unlock(&chan->lock);
- return res;
-}
-
-static int set_format(struct ast_channel *chan, int fmt, int *rawformat, int *format,
- struct ast_trans_pvt **trans, const int direction)
-{
- int native;
- int res;
-
- native = chan->nativeformats;
- /* Find a translation path from the native format to one of the desired formats */
- if (!direction)
- /* reading */
- res = ast_translator_best_choice(&fmt, &native);
- else
- /* writing */
- res = ast_translator_best_choice(&native, &fmt);
-
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n",
- ast_getformatname(native), ast_getformatname(fmt));
- return -1;
- }
-
- /* Now we have a good choice for both. */
- ast_mutex_lock(&chan->lock);
- *rawformat = native;
- /* User perspective is fmt */
- *format = fmt;
- /* Free any read translation we have right now */
- if (*trans)
- ast_translator_free_path(*trans);
- /* Build a translation path from the raw format to the desired format */
- if (!direction)
- /* reading */
- *trans = ast_translator_build_path(*format, *rawformat);
- else
- /* writing */
- *trans = ast_translator_build_path(*rawformat, *format);
- ast_mutex_unlock(&chan->lock);
- if (option_debug)
- ast_log(LOG_DEBUG, "Set channel %s to %s format %s\n", chan->name,
- direction ? "write" : "read", ast_getformatname(fmt));
- return 0;
-}
-
-int ast_set_read_format(struct ast_channel *chan, int fmt)
-{
- return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat,
- &chan->readtrans, 0);
-}
-
-int ast_set_write_format(struct ast_channel *chan, int fmt)
-{
- return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat,
- &chan->writetrans, 1);
-}
-
-struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
-{
- int state = 0;
- int cause = 0;
- struct ast_channel *chan;
- struct ast_frame *f;
- int res = 0;
-
- chan = ast_request(type, format, data, &cause);
- if (chan) {
- if (oh) {
- if (oh->vars)
- ast_set_variables(chan, oh->vars);
- if (oh->cid_num && *oh->cid_num && oh->cid_name && *oh->cid_name)
- ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num);
- if (oh->parent_channel)
- ast_channel_inherit_variables(oh->parent_channel, chan);
- if (oh->account)
- ast_cdr_setaccount(chan, oh->account);
- }
- ast_set_callerid(chan, cid_num, cid_name, cid_num);
-
- if (!ast_call(chan, data, 0)) {
- res = 1; /* in case chan->_state is already AST_STATE_UP */
- while (timeout && (chan->_state != AST_STATE_UP)) {
- res = ast_waitfor(chan, timeout);
- if (res < 0) {
- /* Something not cool, or timed out */
- break;
- }
- /* If done, break out */
- if (!res)
- break;
- if (timeout > -1)
- timeout = res;
- f = ast_read(chan);
- if (!f) {
- state = AST_CONTROL_HANGUP;
- res = 0;
- break;
- }
- if (f->frametype == AST_FRAME_CONTROL) {
- if (f->subclass == AST_CONTROL_RINGING)
- state = AST_CONTROL_RINGING;
- else if ((f->subclass == AST_CONTROL_BUSY) || (f->subclass == AST_CONTROL_CONGESTION)) {
- state = f->subclass;
- ast_frfree(f);
- break;
- } else if (f->subclass == AST_CONTROL_ANSWER) {
- state = f->subclass;
- ast_frfree(f);
- break;
- } else if (f->subclass == AST_CONTROL_PROGRESS) {
- /* Ignore */
- } else if (f->subclass == -1) {
- /* Ignore -- just stopping indications */
- } else {
- ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass);
- }
- }
- ast_frfree(f);
- }
- } else
- ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
- } else {
- ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
- switch(cause) {
- case AST_CAUSE_BUSY:
- state = AST_CONTROL_BUSY;
- break;
- case AST_CAUSE_CONGESTION:
- state = AST_CONTROL_CONGESTION;
- break;
- }
- }
- if (chan) {
- /* Final fixups */
- if (oh) {
- if (oh->context && *oh->context)
- ast_copy_string(chan->context, oh->context, sizeof(chan->context));
- if (oh->exten && *oh->exten)
- ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten));
- if (oh->priority)
- chan->priority = oh->priority;
- }
- if (chan->_state == AST_STATE_UP)
- state = AST_CONTROL_ANSWER;
- }
- if (outstate)
- *outstate = state;
- if (chan && res <= 0) {
- if (!chan->cdr) {
- chan->cdr = ast_cdr_alloc();
- if (chan->cdr)
- ast_cdr_init(chan->cdr, chan);
- }
- if (chan->cdr) {
- char tmp[256];
- snprintf(tmp, 256, "%s/%s", type, (char *)data);
- ast_cdr_setapp(chan->cdr,"Dial",tmp);
- ast_cdr_update(chan);
- ast_cdr_start(chan->cdr);
- ast_cdr_end(chan->cdr);
- /* If the cause wasn't handled properly */
- if (ast_cdr_disposition(chan->cdr,chan->hangupcause))
- ast_cdr_failed(chan->cdr);
- } else
- ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
- ast_hangup(chan);
- chan = NULL;
- }
- return chan;
-}
-
-struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *outstate, const char *cidnum, const char *cidname)
-{
- return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL);
-}
-
-struct ast_channel *ast_request(const char *type, int format, void *data, int *cause)
-{
- struct chanlist *chan;
- struct ast_channel *c;
- int capabilities;
- int fmt;
- int res;
- int foo;
-
- if (!cause)
- cause = &foo;
- *cause = AST_CAUSE_NOTDEFINED;
-
- if (ast_mutex_lock(&chlock)) {
- ast_log(LOG_WARNING, "Unable to lock channel list\n");
- return NULL;
- }
-
- for (chan = backends; chan; chan = chan->next) {
- if (strcasecmp(type, chan->tech->type))
- continue;
-
- capabilities = chan->tech->capabilities;
- fmt = format;
- res = ast_translator_best_choice(&fmt, &capabilities);
- if (res < 0) {
- ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %d) to %d\n", type, chan->tech->capabilities, format);
- ast_mutex_unlock(&chlock);
- return NULL;
- }
- ast_mutex_unlock(&chlock);
- if (!chan->tech->requester)
- return NULL;
-
- if (!(c = chan->tech->requester(type, capabilities, data, cause)))
- return NULL;
-
- if (c->_state == AST_STATE_DOWN) {
- manager_event(EVENT_FLAG_CALL, "Newchannel",
- "Channel: %s\r\n"
- "State: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- "Uniqueid: %s\r\n",
- c->name, ast_state2str(c->_state),
- c->cid.cid_num ? c->cid.cid_num : "<unknown>",
- c->cid.cid_name ? c->cid.cid_name : "<unknown>",
- c->uniqueid);
- }
- return c;
- }
-
- ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
- *cause = AST_CAUSE_NOSUCHDRIVER;
- ast_mutex_unlock(&chlock);
-
- return NULL;
-}
-
-int ast_call(struct ast_channel *chan, char *addr, int timeout)
-{
- /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
- If the remote end does not answer within the timeout, then do NOT hang up, but
- return anyway. */
- int res = -1;
- /* Stop if we're a zombie or need a soft hangup */
- ast_mutex_lock(&chan->lock);
- if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan))
- if (chan->tech->call)
- res = chan->tech->call(chan, addr, timeout);
- ast_mutex_unlock(&chan->lock);
- return res;
-}
-
-/*--- ast_transfer: Transfer a call to dest, if the channel supports transfer */
-/* called by app_transfer or the manager interface */
-int ast_transfer(struct ast_channel *chan, char *dest)
-{
- int res = -1;
-
- /* Stop if we're a zombie or need a soft hangup */
- ast_mutex_lock(&chan->lock);
- if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
- if (chan->tech->transfer) {
- res = chan->tech->transfer(chan, dest);
- if (!res)
- res = 1;
- } else
- res = 0;
- }
- ast_mutex_unlock(&chan->lock);
- return res;
-}
-
-int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders)
-{
- int pos=0;
- int to = ftimeout;
- int d;
-
- /* XXX Merge with full version? XXX */
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
- return -1;
- if (!len)
- return -1;
- do {
- if (c->stream) {
- d = ast_waitstream(c, AST_DIGIT_ANY);
- ast_stopstream(c);
- usleep(1000);
- if (!d)
- d = ast_waitfordigit(c, to);
- } else {
- d = ast_waitfordigit(c, to);
- }
- if (d < 0)
- return -1;
- if (d == 0) {
- s[pos]='\0';
- return 1;
- }
- if (!strchr(enders, d))
- s[pos++] = d;
- if (strchr(enders, d) || (pos >= len)) {
- s[pos]='\0';
- return 0;
- }
- to = timeout;
- } while(1);
- /* Never reached */
- return 0;
-}
-
-int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd)
-{
- int pos=0;
- int to = ftimeout;
- int d;
-
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
- return -1;
- if (!len)
- return -1;
- do {
- if (c->stream) {
- d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
- ast_stopstream(c);
- usleep(1000);
- if (!d)
- d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
- } else {
- d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
- }
- if (d < 0)
- return -1;
- if (d == 0) {
- s[pos]='\0';
- return 1;
- }
- if (d == 1) {
- s[pos]='\0';
- return 2;
- }
- if (!strchr(enders, d))
- s[pos++] = d;
- if (strchr(enders, d) || (pos >= len)) {
- s[pos]='\0';
- return 0;
- }
- to = timeout;
- } while(1);
- /* Never reached */
- return 0;
-}
-
-int ast_channel_supports_html(struct ast_channel *chan)
-{
- if (chan->tech->send_html)
- return 1;
- return 0;
-}
-
-int ast_channel_sendhtml(struct ast_channel *chan, int subclass, const char *data, int datalen)
-{
- if (chan->tech->send_html)
- return chan->tech->send_html(chan, subclass, data, datalen);
- return -1;
-}
-
-int ast_channel_sendurl(struct ast_channel *chan, const char *url)
-{
- if (chan->tech->send_html)
- return chan->tech->send_html(chan, AST_HTML_URL, url, strlen(url) + 1);
- return -1;
-}
-
-int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
-{
- int src;
- int dst;
-
- /* Set up translation from the chan to the peer */
- src = chan->nativeformats;
- dst = peer->nativeformats;
- if (ast_translator_best_choice(&dst, &src) < 0) {
- ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", chan->name, src, peer->name, dst);
- return -1;
- }
-
- /* if the best path is not 'pass through', then
- transcoding is needed; if desired, force transcode path
- to use SLINEAR between channels */
- if ((src != dst) && option_transcode_slin)
- dst = AST_FORMAT_SLINEAR;
- if (ast_set_read_format(chan, dst) < 0) {
- ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", chan->name, dst);
- return -1;
- }
- if (ast_set_write_format(peer, dst) < 0) {
- ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", peer->name, dst);
- return -1;
- }
-
- /* Set up translation from the peer to the chan */
- src = peer->nativeformats;
- dst = chan->nativeformats;
- if (ast_translator_best_choice(&dst, &src) < 0) {
- ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", peer->name, src, chan->name, dst);
- return -1;
- }
- /* if the best path is not 'pass through', then
- transcoding is needed; if desired, force transcode path
- to use SLINEAR between channels */
- if ((src != dst) && option_transcode_slin)
- dst = AST_FORMAT_SLINEAR;
- if (ast_set_read_format(peer, dst) < 0) {
- ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, dst);
- return -1;
- }
- if (ast_set_write_format(chan, dst) < 0) {
- ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", chan->name, dst);
- return -1;
- }
- return 0;
-}
-
-int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone)
-{
- struct ast_frame null = { AST_FRAME_NULL, };
- int res = -1;
-
- if (original == clone) {
- ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
- return -1;
- }
- ast_mutex_lock(&original->lock);
- while(ast_mutex_trylock(&clone->lock)) {
- ast_mutex_unlock(&original->lock);
- usleep(1);
- ast_mutex_lock(&original->lock);
- }
- ast_log(LOG_DEBUG, "Planning to masquerade channel %s into the structure of %s\n",
- clone->name, original->name);
- if (original->masq) {
- ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
- original->masq->name, original->name);
- } else if (clone->masqr) {
- ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
- clone->name, clone->masqr->name);
- } else {
- original->masq = clone;
- clone->masqr = original;
- ast_queue_frame(original, &null);
- ast_queue_frame(clone, &null);
- ast_log(LOG_DEBUG, "Done planning to masquerade channel %s into the structure of %s\n", clone->name, original->name);
- res = 0;
- }
- ast_mutex_unlock(&clone->lock);
- ast_mutex_unlock(&original->lock);
- return res;
-}
-
-void ast_change_name(struct ast_channel *chan, char *newname)
-{
- char tmp[256];
- ast_copy_string(tmp, chan->name, sizeof(tmp));
- ast_copy_string(chan->name, newname, sizeof(chan->name));
- manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", tmp, chan->name, chan->uniqueid);
-}
-
-void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
-{
- struct ast_var_t *current, *newvar;
- char *varname;
-
- AST_LIST_TRAVERSE(&parent->varshead, current, entries) {
- int vartype = 0;
-
- varname = ast_var_full_name(current);
- if (!varname)
- continue;
-
- if (varname[0] == '_') {
- vartype = 1;
- if (varname[1] == '_')
- vartype = 2;
- }
-
- switch (vartype) {
- case 1:
- newvar = ast_var_assign(&varname[1], ast_var_value(current));
- if (newvar) {
- AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
- if (option_debug)
- ast_log(LOG_DEBUG, "Copying soft-transferable variable %s.\n", ast_var_name(newvar));
- }
- break;
- case 2:
- newvar = ast_var_assign(ast_var_full_name(current), ast_var_value(current));
- if (newvar) {
- AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
- if (option_debug)
- ast_log(LOG_DEBUG, "Copying hard-transferable variable %s.\n", ast_var_name(newvar));
- }
- break;
- default:
- if (option_debug)
- ast_log(LOG_DEBUG, "Not copying variable %s.\n", ast_var_name(current));
- break;
- }
- }
-}
-
-/* Clone channel variables from 'clone' channel into 'original' channel
- All variables except those related to app_groupcount are cloned
- Variables are actually _removed_ from 'clone' channel, presumably
- because it will subsequently be destroyed.
- Assumes locks will be in place on both channels when called.
-*/
-
-static void clone_variables(struct ast_channel *original, struct ast_channel *clone)
-{
- struct ast_var_t *varptr;
-
- /* we need to remove all app_groupcount related variables from the original
- channel before merging in the clone's variables; any groups assigned to the
- original channel should be released, only those assigned to the clone
- should remain
- */
-
- AST_LIST_TRAVERSE_SAFE_BEGIN(&original->varshead, varptr, entries) {
- if (!strncmp(ast_var_name(varptr), GROUP_CATEGORY_PREFIX, strlen(GROUP_CATEGORY_PREFIX))) {
- AST_LIST_REMOVE(&original->varshead, varptr, entries);
- ast_var_delete(varptr);
- }
- }
- AST_LIST_TRAVERSE_SAFE_END;
-
- /* Append variables from clone channel into original channel */
- /* XXX Is this always correct? We have to in order to keep MACROS working XXX */
- if (AST_LIST_FIRST(&clone->varshead))
- AST_LIST_INSERT_TAIL(&original->varshead, AST_LIST_FIRST(&clone->varshead), entries);
-}
-
-/*--- ast_do_masquerade: Masquerade a channel */
-/* Assumes channel will be locked when called */
-int ast_do_masquerade(struct ast_channel *original)
-{
- int x,i;
- int res=0;
- int origstate;
- struct ast_frame *cur, *prev;
- const struct ast_channel_tech *t;
- void *t_pvt;
- struct ast_callerid tmpcid;
- struct ast_channel *clone = original->masq;
- int rformat = original->readformat;
- int wformat = original->writeformat;
- char newn[100];
- char orig[100];
- char masqn[100];
- char zombn[100];
-
- if (option_debug > 3)
- ast_log(LOG_DEBUG, "Actually Masquerading %s(%d) into the structure of %s(%d)\n",
- clone->name, clone->_state, original->name, original->_state);
-
- /* XXX This is a seriously wacked out operation. We're essentially putting the guts of
- the clone channel into the original channel. Start by killing off the original
- channel's backend. I'm not sure we're going to keep this function, because
- while the features are nice, the cost is very high in terms of pure nastiness. XXX */
-
- /* We need the clone's lock, too */
- ast_mutex_lock(&clone->lock);
-
- ast_log(LOG_DEBUG, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock);
-
- /* Having remembered the original read/write formats, we turn off any translation on either
- one */
- free_translation(clone);
- free_translation(original);
-
-
- /* Unlink the masquerade */
- original->masq = NULL;
- clone->masqr = NULL;
-
- /* Save the original name */
- ast_copy_string(orig, original->name, sizeof(orig));
- /* Save the new name */
- ast_copy_string(newn, clone->name, sizeof(newn));
- /* Create the masq name */
- snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn);
-
- /* Copy the name from the clone channel */
- ast_copy_string(original->name, newn, sizeof(original->name));
-
- /* Mangle the name of the clone channel */
- ast_copy_string(clone->name, masqn, sizeof(clone->name));
-
- /* Notify any managers of the change, first the masq then the other */
- manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clone->uniqueid);
- manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid);
-
- /* Swap the technlogies */
- t = original->tech;
- original->tech = clone->tech;
- clone->tech = t;
-
- t_pvt = original->tech_pvt;
- original->tech_pvt = clone->tech_pvt;
- clone->tech_pvt = t_pvt;
-
- /* Swap the readq's */
- cur = original->readq;
- original->readq = clone->readq;
- clone->readq = cur;
-
- /* Swap the alertpipes */
- for (i = 0; i < 2; i++) {
- x = original->alertpipe[i];
- original->alertpipe[i] = clone->alertpipe[i];
- clone->alertpipe[i] = x;
- }
-
- /* Swap the raw formats */
- x = original->rawreadformat;
- original->rawreadformat = clone->rawreadformat;
- clone->rawreadformat = x;
- x = original->rawwriteformat;
- original->rawwriteformat = clone->rawwriteformat;
- clone->rawwriteformat = x;
-
- /* Save any pending frames on both sides. Start by counting
- * how many we're going to need... */
- prev = NULL;
- cur = clone->readq;
- x = 0;
- while(cur) {
- x++;
- prev = cur;
- cur = cur->next;
- }
- /* If we had any, prepend them to the ones already in the queue, and
- * load up the alertpipe */
- if (prev) {
- prev->next = original->readq;
- original->readq = clone->readq;
- clone->readq = NULL;
- if (original->alertpipe[1] > -1) {
- for (i = 0; i < x; i++)
- write(original->alertpipe[1], &x, sizeof(x));
- }
- }
- clone->_softhangup = AST_SOFTHANGUP_DEV;
-
-
- /* And of course, so does our current state. Note we need not
- call ast_setstate since the event manager doesn't really consider
- these separate. We do this early so that the clone has the proper
- state of the original channel. */
- origstate = original->_state;
- original->_state = clone->_state;
- clone->_state = origstate;
-
- if (clone->tech->fixup){
- res = clone->tech->fixup(original, clone);
- if (res)
- ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clone->name);
- }
-
- /* Start by disconnecting the original's physical side */
- if (clone->tech->hangup)
- res = clone->tech->hangup(clone);
- if (res) {
- ast_log(LOG_WARNING, "Hangup failed! Strange things may happen!\n");
- ast_mutex_unlock(&clone->lock);
- return -1;
- }
-
- snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig);
- /* Mangle the name of the clone channel */
- ast_copy_string(clone->name, zombn, sizeof(clone->name));
- manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clone->uniqueid);
-
- /* Update the type. */
- original->type = clone->type;
- t_pvt = original->monitor;
- original->monitor = clone->monitor;
- clone->monitor = t_pvt;
-
- /* Keep the same language. */
- ast_copy_string(original->language, clone->language, sizeof(original->language));
- /* Copy the FD's */
- for (x = 0; x < AST_MAX_FDS; x++) {
- original->fds[x] = clone->fds[x];
- }
- clone_variables(original, clone);
- AST_LIST_HEAD_INIT_NOLOCK(&clone->varshead);
- /* Presense of ADSI capable CPE follows clone */
- original->adsicpe = clone->adsicpe;
- /* Bridge remains the same */
- /* CDR fields remain the same */
- /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
- /* Application and data remain the same */
- /* Clone exception becomes real one, as with fdno */
- ast_copy_flags(original, clone, AST_FLAG_EXCEPTION);
- original->fdno = clone->fdno;
- /* Schedule context remains the same */
- /* Stream stuff stays the same */
- /* Keep the original state. The fixup code will need to work with it most likely */
-
- /* Just swap the whole structures, nevermind the allocations, they'll work themselves
- out. */
- tmpcid = original->cid;
- original->cid = clone->cid;
- clone->cid = tmpcid;
-
- /* Restore original timing file descriptor */
- original->fds[AST_MAX_FDS - 2] = original->timingfd;
-
- /* Our native formats are different now */
- original->nativeformats = clone->nativeformats;
-
- /* Context, extension, priority, app data, jump table, remain the same */
- /* pvt switches. pbx stays the same, as does next */
-
- /* Set the write format */
- ast_set_write_format(original, wformat);
-
- /* Set the read format */
- ast_set_read_format(original, rformat);
-
- /* Copy the music class */
- ast_copy_string(original->musicclass, clone->musicclass, sizeof(original->musicclass));
-
- ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
-
- /* Okay. Last thing is to let the channel driver know about all this mess, so he
- can fix up everything as best as possible */
- if (original->tech->fixup) {
- res = original->tech->fixup(clone, original);
- if (res) {
- ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n",
- original->type, original->name);
- ast_mutex_unlock(&clone->lock);
- return -1;
- }
- } else
- ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)! Bad things may happen.\n",
- original->type, original->name);
-
- /* Now, at this point, the "clone" channel is totally F'd up. We mark it as
- a zombie so nothing tries to touch it. If it's already been marked as a
- zombie, then free it now (since it already is considered invalid). */
- if (ast_test_flag(clone, AST_FLAG_ZOMBIE)) {
- ast_log(LOG_DEBUG, "Destroying channel clone '%s'\n", clone->name);
- ast_mutex_unlock(&clone->lock);
- manager_event(EVENT_FLAG_CALL, "Hangup",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Cause: %d\r\n"
- "Cause-txt: %s\r\n",
- clone->name,
- clone->uniqueid,
- clone->hangupcause,
- ast_cause2str(clone->hangupcause)
- );
- ast_channel_free(clone);
- } else {
- struct ast_frame null_frame = { AST_FRAME_NULL, };
- ast_log(LOG_DEBUG, "Released clone lock on '%s'\n", clone->name);
- ast_set_flag(clone, AST_FLAG_ZOMBIE);
- ast_queue_frame(clone, &null_frame);
- ast_mutex_unlock(&clone->lock);
- }
-
- /* Signal any blocker */
- if (ast_test_flag(original, AST_FLAG_BLOCKING))
- pthread_kill(original->blocker, SIGURG);
- ast_log(LOG_DEBUG, "Done Masquerading %s (%d)\n", original->name, original->_state);
- return 0;
-}
-
-void ast_set_callerid(struct ast_channel *chan, const char *callerid, const char *calleridname, const char *ani)
-{
- if (callerid) {
- if (chan->cid.cid_num)
- free(chan->cid.cid_num);
- if (ast_strlen_zero(callerid))
- chan->cid.cid_num = NULL;
- else
- chan->cid.cid_num = strdup(callerid);
- }
- if (calleridname) {
- if (chan->cid.cid_name)
- free(chan->cid.cid_name);
- if (ast_strlen_zero(calleridname))
- chan->cid.cid_name = NULL;
- else
- chan->cid.cid_name = strdup(calleridname);
- }
- if (ani) {
- if (chan->cid.cid_ani)
- free(chan->cid.cid_ani);
- if (ast_strlen_zero(ani))
- chan->cid.cid_ani = NULL;
- else
- chan->cid.cid_ani = strdup(ani);
- }
- if (chan->cdr)
- ast_cdr_setcid(chan->cdr, chan);
- manager_event(EVENT_FLAG_CALL, "Newcallerid",
- "Channel: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- "Uniqueid: %s\r\n"
- "CID-CallingPres: %d (%s)\r\n",
- chan->name, chan->cid.cid_num ?
- chan->cid.cid_num : "<Unknown>",
- chan->cid.cid_name ?
- chan->cid.cid_name : "<Unknown>",
- chan->uniqueid,
- chan->cid.cid_pres,
- ast_describe_caller_presentation(chan->cid.cid_pres)
- );
-}
-
-int ast_setstate(struct ast_channel *chan, int state)
-{
- int oldstate = chan->_state;
-
- if (oldstate == state)
- return 0;
-
- chan->_state = state;
- ast_device_state_changed_literal(chan->name);
- manager_event(EVENT_FLAG_CALL,
- (oldstate == AST_STATE_DOWN) ? "Newchannel" : "Newstate",
- "Channel: %s\r\n"
- "State: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- "Uniqueid: %s\r\n",
- chan->name, ast_state2str(chan->_state),
- chan->cid.cid_num ? chan->cid.cid_num : "<unknown>",
- chan->cid.cid_name ? chan->cid.cid_name : "<unknown>",
- chan->uniqueid);
-
- return 0;
-}
-
-/*--- Find bridged channel */
-struct ast_channel *ast_bridged_channel(struct ast_channel *chan)
-{
- struct ast_channel *bridged;
- bridged = chan->_bridge;
- if (bridged && bridged->tech->bridged_channel)
- bridged = bridged->tech->bridged_channel(chan, bridged);
- return bridged;
-}
-
-static void bridge_playfile(struct ast_channel *chan, struct ast_channel *peer, char *sound, int remain)
-{
- int res=0, min=0, sec=0,check=0;
-
- check = ast_autoservice_start(peer);
- if(check)
- return;
-
- if (remain > 0) {
- if (remain / 60 > 1) {
- min = remain / 60;
- sec = remain % 60;
- } else {
- sec = remain;
- }
- }
-
- if (!strcmp(sound,"timeleft")) { /* Queue support */
- res = ast_streamfile(chan, "vm-youhave", chan->language);
- res = ast_waitstream(chan, "");
- if (min) {
- res = ast_say_number(chan, min, AST_DIGIT_ANY, chan->language, (char *) NULL);
- res = ast_streamfile(chan, "queue-minutes", chan->language);
- res = ast_waitstream(chan, "");
- }
- if (sec) {
- res = ast_say_number(chan, sec, AST_DIGIT_ANY, chan->language, (char *) NULL);
- res = ast_streamfile(chan, "queue-seconds", chan->language);
- res = ast_waitstream(chan, "");
- }
- } else {
- res = ast_streamfile(chan, sound, chan->language);
- res = ast_waitstream(chan, "");
- }
-
- check = ast_autoservice_stop(peer);
-}
-
-static enum ast_bridge_result ast_generic_bridge(struct ast_channel *c0, struct ast_channel *c1,
- struct ast_bridge_config *config, struct ast_frame **fo,
- struct ast_channel **rc, struct timeval bridge_end)
-{
- /* Copy voice back and forth between the two channels. */
- struct ast_channel *cs[3];
- struct ast_frame *f;
- struct ast_channel *who = NULL;
- enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
- int o0nativeformats;
- int o1nativeformats;
- int watch_c0_dtmf;
- int watch_c1_dtmf;
- void *pvt0, *pvt1;
- int to;
-
- cs[0] = c0;
- cs[1] = c1;
- pvt0 = c0->tech_pvt;
- pvt1 = c1->tech_pvt;
- o0nativeformats = c0->nativeformats;
- o1nativeformats = c1->nativeformats;
- watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0;
- watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1;
-
- for (;;) {
- if ((c0->tech_pvt != pvt0) || (c1->tech_pvt != pvt1) ||
- (o0nativeformats != c0->nativeformats) ||
- (o1nativeformats != c1->nativeformats)) {
- /* Check for Masquerade, codec changes, etc */
- res = AST_BRIDGE_RETRY;
- break;
- }
- if (bridge_end.tv_sec) {
- to = ast_tvdiff_ms(bridge_end, ast_tvnow());
- if (to <= 0) {
- res = AST_BRIDGE_RETRY;
- break;
- }
- } else
- to = -1;
- who = ast_waitfor_n(cs, 2, &to);
- if (!who) {
- ast_log(LOG_DEBUG, "Nobody there, continuing...\n");
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
- c0->_softhangup = 0;
- if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
- c1->_softhangup = 0;
- c0->_bridge = c1;
- c1->_bridge = c0;
- }
- continue;
- }
- f = ast_read(who);
- if (!f) {
- *fo = NULL;
- *rc = who;
- res = AST_BRIDGE_COMPLETE;
- ast_log(LOG_DEBUG, "Didn't get a frame from channel: %s\n",who->name);
- break;
- }
-
- if ((f->frametype == AST_FRAME_CONTROL) && !(config->flags & AST_BRIDGE_IGNORE_SIGS)) {
- if ((f->subclass == AST_CONTROL_HOLD) || (f->subclass == AST_CONTROL_UNHOLD) ||
- (f->subclass == AST_CONTROL_VIDUPDATE)) {
- ast_indicate(who == c0 ? c1 : c0, f->subclass);
- } else {
- *fo = f;
- *rc = who;
- res = AST_BRIDGE_COMPLETE;
- ast_log(LOG_DEBUG, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass, who->name);
- break;
- }
- }
- if ((f->frametype == AST_FRAME_VOICE) ||
- (f->frametype == AST_FRAME_DTMF) ||
- (f->frametype == AST_FRAME_VIDEO) ||
- (f->frametype == AST_FRAME_IMAGE) ||
- (f->frametype == AST_FRAME_HTML) ||
- (f->frametype == AST_FRAME_TEXT)) {
- if (f->frametype == AST_FRAME_DTMF) {
- if (((who == c0) && watch_c0_dtmf) ||
- ((who == c1) && watch_c1_dtmf)) {
- *rc = who;
- *fo = f;
- res = AST_BRIDGE_COMPLETE;
- ast_log(LOG_DEBUG, "Got DTMF on channel (%s)\n", who->name);
- break;
- } else {
- goto tackygoto;
- }
- } else {
-#if 0
- ast_log(LOG_DEBUG, "Read from %s\n", who->name);
- if (who == last)
- ast_log(LOG_DEBUG, "Servicing channel %s twice in a row?\n", last->name);
- last = who;
-#endif
-tackygoto:
- ast_write((who == c0) ? c1 : c0, f);
- }
- }
- ast_frfree(f);
-
- /* Swap who gets priority */
- cs[2] = cs[0];
- cs[0] = cs[1];
- cs[1] = cs[2];
- }
- return res;
-}
-
-/*--- ast_channel_bridge: Bridge two channels together */
-enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1,
- struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc)
-{
- struct ast_channel *who = NULL;
- enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
- int nativefailed=0;
- int firstpass;
- int o0nativeformats;
- int o1nativeformats;
- long time_left_ms=0;
- struct timeval nexteventts = { 0, };
- char caller_warning = 0;
- char callee_warning = 0;
- int to;
-
- if (c0->_bridge) {
- ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
- c0->name, c0->_bridge->name);
- return -1;
- }
- if (c1->_bridge) {
- ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
- c1->name, c1->_bridge->name);
- return -1;
- }
-
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
- ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
- return -1;
-
- *fo = NULL;
- firstpass = config->firstpass;
- config->firstpass = 0;
-
- if (ast_tvzero(config->start_time))
- config->start_time = ast_tvnow();
- time_left_ms = config->timelimit;
-
- caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
- callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);
-
- if (config->start_sound && firstpass) {
- if (caller_warning)
- bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000);
- if (callee_warning)
- bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000);
- }
-
- /* Keep track of bridge */
- c0->_bridge = c1;
- c1->_bridge = c0;
-
- manager_event(EVENT_FLAG_CALL, "Link",
- "Channel1: %s\r\n"
- "Channel2: %s\r\n"
- "Uniqueid1: %s\r\n"
- "Uniqueid2: %s\r\n"
- "CallerID1: %s\r\n"
- "CallerID2: %s\r\n",
- c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
-
- o0nativeformats = c0->nativeformats;
- o1nativeformats = c1->nativeformats;
-
- if (config->timelimit) {
- nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
- if (caller_warning || callee_warning)
- nexteventts = ast_tvsub(nexteventts, ast_samp2tv(config->play_warning, 1000));
- }
-
- for (/* ever */;;) {
- to = -1;
- if (config->timelimit) {
- struct timeval now;
- now = ast_tvnow();
- to = ast_tvdiff_ms(nexteventts, now);
- if (to < 0)
- to = 0;
- time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time);
- if (time_left_ms < to)
- to = time_left_ms;
-
- if (time_left_ms <= 0) {
- if (caller_warning && config->end_sound)
- bridge_playfile(c0, c1, config->end_sound, 0);
- if (callee_warning && config->end_sound)
- bridge_playfile(c1, c0, config->end_sound, 0);
- *fo = NULL;
- if (who)
- *rc = who;
- res = 0;
- break;
- }
-
- if (!to) {
- if (time_left_ms >= 5000) {
- /* force the time left to round up if appropriate */
- if (caller_warning && config->warning_sound && config->play_warning)
- bridge_playfile(c0, c1, config->warning_sound,
- (time_left_ms + 500) / 1000);
- if (callee_warning && config->warning_sound && config->play_warning)
- bridge_playfile(c1, c0, config->warning_sound,
- (time_left_ms + 500) / 1000);
- }
- if (config->warning_freq) {
- nexteventts = ast_tvadd(nexteventts, ast_samp2tv(config->warning_freq, 1000));
- } else
- nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
- }
- }
-
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
- c0->_softhangup = 0;
- if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
- c1->_softhangup = 0;
- c0->_bridge = c1;
- c1->_bridge = c0;
- ast_log(LOG_DEBUG, "Unbridge signal received. Ending native bridge.\n");
- continue;
- }
-
- /* Stop if we're a zombie or need a soft hangup */
- if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
- ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) {
- *fo = NULL;
- if (who)
- *rc = who;
- res = 0;
- ast_log(LOG_DEBUG, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n",
- c0->name, c1->name,
- ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No",
- ast_check_hangup(c0) ? "Yes" : "No",
- ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No",
- ast_check_hangup(c1) ? "Yes" : "No");
- break;
- }
-
- if (c0->tech->bridge &&
- (config->timelimit == 0) &&
- (c0->tech->bridge == c1->tech->bridge) &&
- !nativefailed && !c0->monitor && !c1->monitor &&
- !c0->spies && !c1->spies) {
- /* Looks like they share a bridge method and nothing else is in the way */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Attempting native bridge of %s and %s\n", c0->name, c1->name);
- ast_set_flag(c0, AST_FLAG_NBRIDGE);
- ast_set_flag(c1, AST_FLAG_NBRIDGE);
- if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, to)) == AST_BRIDGE_COMPLETE) {
- manager_event(EVENT_FLAG_CALL, "Unlink",
- "Channel1: %s\r\n"
- "Channel2: %s\r\n"
- "Uniqueid1: %s\r\n"
- "Uniqueid2: %s\r\n"
- "CallerID1: %s\r\n"
- "CallerID2: %s\r\n",
- c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
- ast_log(LOG_DEBUG, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name);
-
- ast_clear_flag(c0, AST_FLAG_NBRIDGE);
- ast_clear_flag(c1, AST_FLAG_NBRIDGE);
-
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
- continue;
-
- c0->_bridge = NULL;
- c1->_bridge = NULL;
-
- return res;
- } else {
- ast_clear_flag(c0, AST_FLAG_NBRIDGE);
- ast_clear_flag(c1, AST_FLAG_NBRIDGE);
- }
- switch (res) {
- case AST_BRIDGE_RETRY:
- continue;
- default:
- ast_log(LOG_WARNING, "Private bridge between %s and %s failed\n", c0->name, c1->name);
- /* fallthrough */
- case AST_BRIDGE_FAILED_NOWARN:
- nativefailed++;
- break;
- }
- }
-
- if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) ||
- (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) &&
- !(c0->generator || c1->generator)) {
- if (ast_channel_make_compatible(c0, c1)) {
- ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name);
- manager_event(EVENT_FLAG_CALL, "Unlink",
- "Channel1: %s\r\n"
- "Channel2: %s\r\n"
- "Uniqueid1: %s\r\n"
- "Uniqueid2: %s\r\n"
- "CallerID1: %s\r\n"
- "CallerID2: %s\r\n",
- c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
- return AST_BRIDGE_FAILED;
- }
- o0nativeformats = c0->nativeformats;
- o1nativeformats = c1->nativeformats;
- }
- res = ast_generic_bridge(c0, c1, config, fo, rc, nexteventts);
- if (res != AST_BRIDGE_RETRY)
- break;
- }
-
- c0->_bridge = NULL;
- c1->_bridge = NULL;
-
- manager_event(EVENT_FLAG_CALL, "Unlink",
- "Channel1: %s\r\n"
- "Channel2: %s\r\n"
- "Uniqueid1: %s\r\n"
- "Uniqueid2: %s\r\n"
- "CallerID1: %s\r\n"
- "CallerID2: %s\r\n",
- c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
- ast_log(LOG_DEBUG, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name);
-
- return res;
-}
-
-/*--- ast_channel_setoption: Sets an option on a channel */
-int ast_channel_setoption(struct ast_channel *chan, int option, void *data, int datalen, int block)
-{
- int res;
-
- if (chan->tech->setoption) {
- res = chan->tech->setoption(chan, option, data, datalen);
- if (res < 0)
- return res;
- } else {
- errno = ENOSYS;
- return -1;
- }
- if (block) {
- /* XXX Implement blocking -- just wait for our option frame reply, discarding
- intermediate packets. XXX */
- ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
- return -1;
- }
- return 0;
-}
-
-struct tonepair_def {
- int freq1;
- int freq2;
- int duration;
- int vol;
-};
-
-struct tonepair_state {
- float freq1;
- float freq2;
- float vol;
- int duration;
- int pos;
- int origwfmt;
- struct ast_frame f;
- unsigned char offset[AST_FRIENDLY_OFFSET];
- short data[4000];
-};
-
-static void tonepair_release(struct ast_channel *chan, void *params)
-{
- struct tonepair_state *ts = params;
-
- if (chan) {
- ast_set_write_format(chan, ts->origwfmt);
- }
- free(ts);
-}
-
-static void *tonepair_alloc(struct ast_channel *chan, void *params)
-{
- struct tonepair_state *ts;
- struct tonepair_def *td = params;
-
- ts = malloc(sizeof(struct tonepair_state));
- if (!ts)
- return NULL;
- memset(ts, 0, sizeof(struct tonepair_state));
- ts->origwfmt = chan->writeformat;
- if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
- ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
- tonepair_release(NULL, ts);
- ts = NULL;
- } else {
- ts->freq1 = td->freq1;
- ts->freq2 = td->freq2;
- ts->duration = td->duration;
- ts->vol = td->vol;
- }
- /* Let interrupts interrupt :) */
- ast_set_flag(chan, AST_FLAG_WRITE_INT);
- return ts;
-}
-
-static int tonepair_generator(struct ast_channel *chan, void *data, int len, int samples)
-{
- struct tonepair_state *ts = data;
- int x;
-
- /* we need to prepare a frame with 16 * timelen samples as we're
- * generating SLIN audio
- */
- len = samples * 2;
-
- if (len > sizeof(ts->data) / 2 - 1) {
- ast_log(LOG_WARNING, "Can't generate that much data!\n");
- return -1;
- }
- memset(&ts->f, 0, sizeof(ts->f));
- for (x = 0; x < (len / 2); x++) {
- ts->data[x] = ts->vol * (
- sin((ts->freq1 * 2.0 * M_PI / 8000.0) * (ts->pos + x)) +
- sin((ts->freq2 * 2.0 * M_PI / 8000.0) * (ts->pos + x))
- );
- }
- ts->f.frametype = AST_FRAME_VOICE;
- ts->f.subclass = AST_FORMAT_SLINEAR;
- ts->f.datalen = len;
- ts->f.samples = samples;
- ts->f.offset = AST_FRIENDLY_OFFSET;
- ts->f.data = ts->data;
- ast_write(chan, &ts->f);
- ts->pos += x;
- if (ts->duration > 0) {
- if (ts->pos >= ts->duration * 8)
- return -1;
- }
- return 0;
-}
-
-static struct ast_generator tonepair = {
- alloc: tonepair_alloc,
- release: tonepair_release,
- generate: tonepair_generator,
-};
-
-int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
-{
- struct tonepair_def d = { 0, };
-
- d.freq1 = freq1;
- d.freq2 = freq2;
- d.duration = duration;
- if (vol < 1)
- d.vol = 8192;
- else
- d.vol = vol;
- if (ast_activate_generator(chan, &tonepair, &d))
- return -1;
- return 0;
-}
-
-void ast_tonepair_stop(struct ast_channel *chan)
-{
- ast_deactivate_generator(chan);
-}
-
-int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
-{
- struct ast_frame *f;
- int res;
-
- if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
- return res;
-
- /* Give us some wiggle room */
- while(chan->generatordata && (ast_waitfor(chan, 100) >= 0)) {
- f = ast_read(chan);
- if (f)
- ast_frfree(f);
- else
- return -1;
- }
- return 0;
-}
-
-ast_group_t ast_get_group(char *s)
-{
- char *copy;
- char *piece;
- char *c=NULL;
- int start=0, finish=0, x;
- ast_group_t group = 0;
-
- copy = ast_strdupa(s);
- if (!copy) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return 0;
- }
- c = copy;
-
- while((piece = strsep(&c, ","))) {
- if (sscanf(piece, "%d-%d", &start, &finish) == 2) {
- /* Range */
- } else if (sscanf(piece, "%d", &start)) {
- /* Just one */
- finish = start;
- } else {
- ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
- continue;
- }
- for (x = start; x <= finish; x++) {
- if ((x > 63) || (x < 0)) {
- ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
- } else
- group |= ((ast_group_t) 1 << x);
- }
- }
- return group;
-}
-
-static int (*ast_moh_start_ptr)(struct ast_channel *, char *) = NULL;
-static void (*ast_moh_stop_ptr)(struct ast_channel *) = NULL;
-static void (*ast_moh_cleanup_ptr)(struct ast_channel *) = NULL;
-
-
-void ast_install_music_functions(int (*start_ptr)(struct ast_channel *, char *),
- void (*stop_ptr)(struct ast_channel *),
- void (*cleanup_ptr)(struct ast_channel *)
- )
-{
- ast_moh_start_ptr = start_ptr;
- ast_moh_stop_ptr = stop_ptr;
- ast_moh_cleanup_ptr = cleanup_ptr;
-}
-
-void ast_uninstall_music_functions(void)
-{
- ast_moh_start_ptr = NULL;
- ast_moh_stop_ptr = NULL;
- ast_moh_cleanup_ptr = NULL;
-}
-
-/*! Turn on music on hold on a given channel */
-int ast_moh_start(struct ast_channel *chan, char *mclass)
-{
- if (ast_moh_start_ptr)
- return ast_moh_start_ptr(chan, mclass);
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : "default");
-
- return 0;
-}
-
-/*! Turn off music on hold on a given channel */
-void ast_moh_stop(struct ast_channel *chan)
-{
- if(ast_moh_stop_ptr)
- ast_moh_stop_ptr(chan);
-}
-
-void ast_moh_cleanup(struct ast_channel *chan)
-{
- if(ast_moh_cleanup_ptr)
- ast_moh_cleanup_ptr(chan);
-}
-
-void ast_channels_init(void)
-{
- ast_cli_register(&cli_show_channeltypes);
-}
-
-/*--- ast_print_group: Print call group and pickup group ---*/
-char *ast_print_group(char *buf, int buflen, ast_group_t group)
-{
- unsigned int i;
- int first=1;
- char num[3];
-
- buf[0] = '\0';
-
- if (!group) /* Return empty string if no group */
- return(buf);
-
- for (i=0; i<=63; i++) { /* Max group is 63 */
- if (group & ((ast_group_t) 1 << i)) {
- if (!first) {
- strncat(buf, ", ", buflen);
- } else {
- first=0;
- }
- snprintf(num, sizeof(num), "%u", i);
- strncat(buf, num, buflen);
- }
- }
- return(buf);
-}
-
-void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
-{
- struct ast_variable *cur;
-
- for (cur = vars; cur; cur = cur->next)
- pbx_builtin_setvar_helper(chan, cur->name, cur->value);
-}
-
-static void copy_data_from_queue(struct ast_channel_spy_queue *queue, short *buf, unsigned int samples)
-{
- struct ast_frame *f;
- int tocopy;
- int bytestocopy;
-
- while (samples) {
- f = queue->head;
-
- if (!f) {
- ast_log(LOG_ERROR, "Ran out of frames before buffer filled!\n");
- break;
- }
-
- tocopy = (f->samples > samples) ? samples : f->samples;
- bytestocopy = ast_codec_get_len(queue->format, tocopy);
- memcpy(buf, f->data, bytestocopy);
- samples -= tocopy;
- buf += tocopy;
- f->samples -= tocopy;
- f->data += bytestocopy;
- f->datalen -= bytestocopy;
- f->offset += bytestocopy;
- queue->samples -= tocopy;
- if (!f->samples) {
- queue->head = f->next;
- ast_frfree(f);
- }
- }
-}
-
-struct ast_frame *ast_channel_spy_read_frame(struct ast_channel_spy *spy, unsigned int samples)
-{
- struct ast_frame *result;
- /* buffers are allocated to hold SLINEAR, which is the largest format */
- short read_buf[samples];
- short write_buf[samples];
- struct ast_frame *read_frame;
- struct ast_frame *write_frame;
- int need_dup;
- struct ast_frame stack_read_frame = { .frametype = AST_FRAME_VOICE,
- .subclass = spy->read_queue.format,
- .data = read_buf,
- .samples = samples,
- .datalen = ast_codec_get_len(spy->read_queue.format, samples),
- };
- struct ast_frame stack_write_frame = { .frametype = AST_FRAME_VOICE,
- .subclass = spy->write_queue.format,
- .data = write_buf,
- .samples = samples,
- .datalen = ast_codec_get_len(spy->write_queue.format, samples),
- };
-
- /* if a flush has been requested, dump everything in whichever queue is larger */
- if (ast_test_flag(spy, CHANSPY_TRIGGER_FLUSH)) {
- if (spy->read_queue.samples > spy->write_queue.samples) {
- if (ast_test_flag(spy, CHANSPY_READ_VOLADJUST)) {
- for (result = spy->read_queue.head; result; result = result->next)
- ast_frame_adjust_volume(result, spy->read_vol_adjustment);
- }
- result = spy->read_queue.head;
- spy->read_queue.head = NULL;
- spy->read_queue.samples = 0;
- ast_clear_flag(spy, CHANSPY_TRIGGER_FLUSH);
- return result;
- } else {
- if (ast_test_flag(spy, CHANSPY_WRITE_VOLADJUST)) {
- for (result = spy->write_queue.head; result; result = result->next)
- ast_frame_adjust_volume(result, spy->write_vol_adjustment);
- }
- result = spy->write_queue.head;
- spy->write_queue.head = NULL;
- spy->write_queue.samples = 0;
- ast_clear_flag(spy, CHANSPY_TRIGGER_FLUSH);
- return result;
- }
- }
-
- if ((spy->read_queue.samples < samples) || (spy->write_queue.samples < samples))
- return NULL;
-
- /* short-circuit if both head frames have exactly what we want */
- if ((spy->read_queue.head->samples == samples) &&
- (spy->write_queue.head->samples == samples)) {
- read_frame = spy->read_queue.head;
- spy->read_queue.head = read_frame->next;
- read_frame->next = NULL;
-
- write_frame = spy->write_queue.head;
- spy->write_queue.head = write_frame->next;
- write_frame->next = NULL;
-
- spy->read_queue.samples -= samples;
- spy->write_queue.samples -= samples;
-
- need_dup = 0;
- } else {
- copy_data_from_queue(&spy->read_queue, read_buf, samples);
- copy_data_from_queue(&spy->write_queue, write_buf, samples);
-
- read_frame = &stack_read_frame;
- write_frame = &stack_write_frame;
- need_dup = 1;
- }
-
- if (ast_test_flag(spy, CHANSPY_READ_VOLADJUST))
- ast_frame_adjust_volume(read_frame, spy->read_vol_adjustment);
-
- if (ast_test_flag(spy, CHANSPY_WRITE_VOLADJUST))
- ast_frame_adjust_volume(write_frame, spy->write_vol_adjustment);
-
- if (ast_test_flag(spy, CHANSPY_MIXAUDIO)) {
- ast_frame_slinear_sum(read_frame, write_frame);
-
- if (need_dup)
- result = ast_frdup(read_frame);
- else {
- result = read_frame;
- ast_frfree(write_frame);
- }
- } else {
- if (need_dup) {
- result = ast_frdup(read_frame);
- result->next = ast_frdup(write_frame);
- } else {
- result = read_frame;
- result->next = write_frame;
- }
- }
-
- return result;
-}
-
-static void *silence_generator_alloc(struct ast_channel *chan, void *data)
-{
- /* just store the data pointer in the channel structure */
- return data;
-}
-
-static void silence_generator_release(struct ast_channel *chan, void *data)
-{
- /* nothing to do */
-}
-
-static int silence_generator_generate(struct ast_channel *chan, void *data, int len, int samples)
-{
- if (samples == 160) {
- short buf[160] = { 0, };
- struct ast_frame frame = {
- .frametype = AST_FRAME_VOICE,
- .subclass = AST_FORMAT_SLINEAR,
- .data = buf,
- .samples = 160,
- .datalen = sizeof(buf),
- };
-
- if (ast_write(chan, &frame))
- return -1;
- } else {
- short buf[samples];
- int x;
- struct ast_frame frame = {
- .frametype = AST_FRAME_VOICE,
- .subclass = AST_FORMAT_SLINEAR,
- .data = buf,
- .samples = samples,
- .datalen = sizeof(buf),
- };
-
- for (x = 0; x < samples; x++)
- buf[x] = 0;
-
- if (ast_write(chan, &frame))
- return -1;
- }
-
- return 0;
-}
-
-static struct ast_generator silence_generator = {
- .alloc = silence_generator_alloc,
- .release = silence_generator_release,
- .generate = silence_generator_generate,
-};
-
-struct ast_silence_generator {
- int old_write_format;
-};
-
-struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan)
-{
- struct ast_silence_generator *state;
-
- if (!(state = calloc(1, sizeof(*state)))) {
- ast_log(LOG_WARNING, "Could not allocate state structure\n");
- return NULL;
- }
-
- state->old_write_format = chan->writeformat;
-
- if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
- ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
- free(state);
- return NULL;
- }
-
- ast_activate_generator(chan, &silence_generator, state);
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Started silence generator on '%s'\n", chan->name);
-
- return state;
-}
-
-void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
-{
- if (!state)
- return;
-
- ast_deactivate_generator(chan);
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Stopped silence generator on '%s'\n", chan->name);
-
- if (ast_set_write_format(chan, state->old_write_format) < 0)
- ast_log(LOG_ERROR, "Could not return write format to its original state\n");
-
- free(state);
-}
diff --git a/1.2-netsec/channels/DialTone.h b/1.2-netsec/channels/DialTone.h
deleted file mode 100644
index 098ed44d7..000000000
--- a/1.2-netsec/channels/DialTone.h
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * 8-bit raw data
- *
- * Source: DialTone.ulaw
- *
- * Copyright (C) 1999, Mark Spencer
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char DialTone[] = {
-0xff, 0xab, 0x9d, 0x96, 0x91, 0x90, 0x91, 0x96, 0x9c, 0xaa,
-0xd9, 0x2f, 0x1f, 0x19, 0x15, 0x14, 0x15, 0x19, 0x1f, 0x2c,
-0x4e, 0xb9, 0xa7, 0x9f, 0x9c, 0x9b, 0x9c, 0x9f, 0xa7, 0xb3,
-0xcf, 0x47, 0x34, 0x2d, 0x2a, 0x2a, 0x2c, 0x31, 0x3a, 0x47,
-0x5f, 0xe4, 0xd8, 0xd9, 0xe9, 0x64, 0x4f, 0x49, 0x46, 0x49,
-0x58, 0xde, 0xc2, 0xb5, 0xad, 0xa8, 0xa6, 0xa6, 0xa9, 0xaf,
-0xbf, 0x56, 0x32, 0x26, 0x1e, 0x1b, 0x19, 0x1a, 0x1d, 0x24,
-0x33, 0xdd, 0xad, 0x9f, 0x98, 0x94, 0x92, 0x93, 0x97, 0x9e,
-0xac, 0xf8, 0x2c, 0x1d, 0x16, 0x11, 0xf, 0x10, 0x15, 0x1b,
-0x29, 0x55, 0xae, 0x9e, 0x97, 0x92, 0x90, 0x91, 0x95, 0x9c,
-0xa8, 0xca, 0x35, 0x22, 0x1a, 0x16, 0x15, 0x16, 0x19, 0x1f,
-0x2b, 0x47, 0xbe, 0xab, 0xa2, 0x9e, 0x9d, 0x9e, 0xa2, 0xa9,
-0xb4, 0xcc, 0x4f, 0x3a, 0x32, 0x2f, 0x2f, 0x32, 0x39, 0x41,
-0x4f, 0x67, 0xf5, 0xf5, 0x67, 0x51, 0x46, 0x3e, 0x3b, 0x3b,
-0x3f, 0x4d, 0xe2, 0xbe, 0xb0, 0xa9, 0xa4, 0xa1, 0xa1, 0xa5,
-0xab, 0xba, 0x64, 0x33, 0x25, 0x1d, 0x19, 0x17, 0x18, 0x1b,
-0x20, 0x2e, 0x72, 0xae, 0x9f, 0x98, 0x94, 0x91, 0x92, 0x96,
-0x9c, 0xa9, 0xd4, 0x2f, 0x1e, 0x17, 0x11, 0xf, 0x10, 0x14,
-0x1a, 0x26, 0x48, 0xb2, 0x9f, 0x98, 0x93, 0x91, 0x92, 0x95,
-0x9b, 0xa7, 0xc1, 0x3a, 0x25, 0x1c, 0x18, 0x16, 0x17, 0x1a,
-0x1f, 0x2b, 0x42, 0xc6, 0xae, 0xa6, 0xa0, 0x9f, 0xa0, 0xa5,
-0xab, 0xb6, 0xcb, 0x5a, 0x40, 0x39, 0x36, 0x37, 0x3b, 0x43,
-0x4e, 0x60, 0x7b, 0x7c, 0x60, 0x4e, 0x41, 0x3a, 0x34, 0x32,
-0x33, 0x39, 0x45, 0xed, 0xbd, 0xae, 0xa6, 0xa0, 0x9e, 0x9e,
-0xa0, 0xa8, 0xb4, 0xef, 0x34, 0x24, 0x1c, 0x18, 0x16, 0x16,
-0x19, 0x1e, 0x2b, 0x54, 0xb1, 0x9f, 0x98, 0x93, 0x91, 0x91,
-0x95, 0x9b, 0xa6, 0xc6, 0x33, 0x1f, 0x17, 0x12, 0xf, 0x10,
-0x13, 0x1a, 0x24, 0x3e, 0xb8, 0xa2, 0x99, 0x94, 0x92, 0x92,
-0x96, 0x9b, 0xa6, 0xbc, 0x40, 0x29, 0x1e, 0x1a, 0x18, 0x19,
-0x1b, 0x20, 0x2b, 0x3f, 0xcf, 0xb3, 0xa9, 0xa5, 0xa3, 0xa4,
-0xa8, 0xae, 0xb9, 0xcc, 0x67, 0x49, 0x40, 0x3f, 0x42, 0x4a,
-0x59, 0x79, 0xe5, 0xe4, 0x7a, 0x54, 0x43, 0x39, 0x31, 0x2d,
-0x2c, 0x2d, 0x32, 0x3e, 0x71, 0xbd, 0xad, 0xa4, 0x9e, 0x9c,
-0x9c, 0x9e, 0xa4, 0xaf, 0xd7, 0x36, 0x24, 0x1c, 0x17, 0x15,
-0x15, 0x17, 0x1d, 0x28, 0x47, 0xb5, 0xa1, 0x98, 0x93, 0x90,
-0x90, 0x93, 0x99, 0xa4, 0xbd, 0x38, 0x21, 0x18, 0x13, 0x10,
-0x10, 0x13, 0x19, 0x22, 0x39, 0xbe, 0xa5, 0x9b, 0x96, 0x93,
-0x93, 0x96, 0x9b, 0xa5, 0xb9, 0x4a, 0x2c, 0x20, 0x1c, 0x1a,
-0x1a, 0x1d, 0x22, 0x2c, 0x3d, 0xdc, 0xb8, 0xad, 0xa9, 0xa8,
-0xa9, 0xac, 0xb2, 0xbd, 0xce, 0x78, 0x54, 0x4d, 0x4f, 0x5a,
-0xff, 0xda, 0xcf, 0xcd, 0xd4, 0xf8, 0x4e, 0x3d, 0x32, 0x2c,
-0x29, 0x28, 0x29, 0x2d, 0x38, 0x5c, 0xbd, 0xac, 0xa2, 0x9d,
-0x9a, 0x9a, 0x9c, 0xa0, 0xac, 0xca, 0x39, 0x25, 0x1b, 0x16,
-0x13, 0x13, 0x16, 0x1b, 0x25, 0x3e, 0xb9, 0xa2, 0x99, 0x93,
-0x90, 0x90, 0x93, 0x98, 0xa1, 0xb8, 0x3d, 0x24, 0x19, 0x13,
-0x10, 0x10, 0x13, 0x18, 0x21, 0x35, 0xc7, 0xa8, 0x9d, 0x97,
-0x95, 0x95, 0x97, 0x9c, 0xa4, 0xb6, 0x57, 0x2f, 0x24, 0x1e,
-0x1c, 0x1c, 0x1e, 0x24, 0x2d, 0x3d, 0xf1, 0xbe, 0xb2, 0xad,
-0xac, 0xad, 0xb1, 0xb9, 0xc3, 0xd4, 0xfa, 0x64, 0x65, 0xf9,
-0xd9, 0xca, 0xc2, 0xbf, 0xc0, 0xc9, 0xe7, 0x4c, 0x39, 0x2e,
-0x28, 0x24, 0x23, 0x25, 0x29, 0x33, 0x4f, 0xbf, 0xab, 0xa0,
-0x9b, 0x99, 0x98, 0x9a, 0x9e, 0xa9, 0xc0, 0x3c, 0x26, 0x1b,
-0x16, 0x12, 0x12, 0x14, 0x19, 0x22, 0x38, 0xbe, 0xa4, 0x9a,
-0x93, 0x90, 0x8f, 0x92, 0x97, 0x9f, 0xb3, 0x46, 0x26, 0x1b,
-0x15, 0x11, 0x11, 0x13, 0x18, 0x1f, 0x31, 0xd4, 0xab, 0x9e,
-0x99, 0x96, 0x96, 0x98, 0x9c, 0xa4, 0xb4, 0x6f, 0x34, 0x28,
-0x20, 0x1e, 0x1e, 0x20, 0x26, 0x2e, 0x3d, 0x6d, 0xc5, 0xb9,
-0xb3, 0xb2, 0xb4, 0xba, 0xc1, 0xcd, 0xe0, 0xfc, 0xfb, 0xe0,
-0xce, 0xc3, 0xbb, 0xb7, 0xb6, 0xb9, 0xc0, 0xda, 0x4b, 0x36,
-0x2b, 0x25, 0x20, 0x1f, 0x20, 0x26, 0x2e, 0x46, 0xc2, 0xab,
-0x9f, 0x9a, 0x97, 0x96, 0x98, 0x9c, 0xa5, 0xba, 0x41, 0x27,
-0x1b, 0x15, 0x12, 0x11, 0x13, 0x18, 0x1f, 0x32, 0xc8, 0xa6,
-0x9a, 0x94, 0x90, 0x8f, 0x91, 0x97, 0x9e, 0xaf, 0x54, 0x29,
-0x1c, 0x16, 0x12, 0x11, 0x14, 0x18, 0x1f, 0x2e, 0xf2, 0xae,
-0xa0, 0x9b, 0x98, 0x97, 0x99, 0x9d, 0xa5, 0xb3, 0xe4, 0x3a,
-0x2b, 0x25, 0x21, 0x21, 0x24, 0x29, 0x30, 0x3e, 0x62, 0xcd,
-0xbf, 0xbb, 0xbb, 0xbe, 0xc6, 0xd1, 0xe7, 0x76, 0x75, 0xe7,
-0xcf, 0xc1, 0xb9, 0xb2, 0xaf, 0xaf, 0xb2, 0xba, 0xcf, 0x4c,
-0x34, 0x29, 0x22, 0x1e, 0x1d, 0x1e, 0x22, 0x2b, 0x3e, 0xc7,
-0xab, 0x9f, 0x99, 0x96, 0x95, 0x96, 0x9a, 0xa2, 0xb5, 0x4a,
-0x28, 0x1c, 0x15, 0x11, 0x10, 0x12, 0x17, 0x1e, 0x2e, 0xd5,
-0xa9, 0x9b, 0x95, 0x90, 0x8f, 0x91, 0x96, 0x9d, 0xac, 0x78,
-0x2c, 0x1e, 0x17, 0x13, 0x12, 0x14, 0x18, 0x1f, 0x2d, 0x5d,
-0xb3, 0xa4, 0x9d, 0x9a, 0x99, 0x9b, 0x9e, 0xa6, 0xb2, 0xd6,
-0x3f, 0x2f, 0x29, 0x26, 0x26, 0x28, 0x2d, 0x35, 0x42, 0x5e,
-0xd8, 0xca, 0xc6, 0xc9, 0xcf, 0xe4, 0x69, 0x59, 0x58, 0x64,
-0xdf, 0xc7, 0xba, 0xb1, 0xac, 0xaa, 0xaa, 0xad, 0xb4, 0xc7,
-0x4f, 0x33, 0x27, 0x1f, 0x1c, 0x1b, 0x1c, 0x1f, 0x27, 0x39,
-0xce, 0xac, 0x9f, 0x99, 0x95, 0x94, 0x95, 0x99, 0x9f, 0xaf,
-0x59, 0x2a, 0x1c, 0x16, 0x11, 0x10, 0x11, 0x16, 0x1d, 0x2b,
-0xff, 0xab, 0x9d, 0x96, 0x91, 0x90, 0x91, 0x96, 0x9c, 0xaa,
-0xd9, 0x2f, 0x1f, 0x19, 0x15, 0x14, 0x15, 0x19, 0x1f, 0x2c,
-0x4e, 0xb9, 0xa7, 0x9f, 0x9c, 0x9b, 0x9c, 0x9f, 0xa7, 0xb3,
-0xcf, 0x47, 0x34, 0x2d, 0x2a, 0x2a, 0x2c, 0x31, 0x3a, 0x47,
-0x5f, 0xe4, 0xd8, 0xd9, 0xe9, 0x64, 0x4f, 0x49, 0x46, 0x49,
-0x58, 0xde, 0xc2, 0xb5, 0xad, 0xa8, 0xa6, 0xa6, 0xa9, 0xaf,
-0xbf, 0x56, 0x32, 0x26, 0x1e, 0x1b, 0x19, 0x1a, 0x1d, 0x24,
-0x33, 0xdd, 0xad, 0x9f, 0x98, 0x94, 0x92, 0x93, 0x97, 0x9e,
-0xac, 0xf8, 0x2c, 0x1d, 0x16, 0x11, 0xf, 0x10, 0x15, 0x1b,
-0x29, 0x55, 0xae, 0x9e, 0x97, 0x92, 0x90, 0x91, 0x95, 0x9c,
-0xa8, 0xca, 0x35, 0x22, 0x1a, 0x16, 0x15, 0x16, 0x19, 0x1f,
-0x2b, 0x47, 0xbe, 0xab, 0xa2, 0x9e, 0x9d, 0x9e, 0xa2, 0xa9,
-0xb4, 0xcc, 0x4f, 0x3a, 0x32, 0x2f, 0x2f, 0x32, 0x39, 0x41,
-0x4f, 0x67, 0xf5, 0xf5, 0x67, 0x51, 0x46, 0x3e, 0x3b, 0x3b,
-0x3f, 0x4d, 0xe2, 0xbe, 0xb0, 0xa9, 0xa4, 0xa1, 0xa1, 0xa5,
-0xab, 0xba, 0x64, 0x33, 0x25, 0x1d, 0x19, 0x17, 0x18, 0x1b,
-0x20, 0x2e, 0x72, 0xae, 0x9f, 0x98, 0x94, 0x91, 0x92, 0x96,
-0x9c, 0xa9, 0xd4, 0x2f, 0x1e, 0x17, 0x11, 0xf, 0x10, 0x14,
-0x1a, 0x26, 0x48, 0xb2, 0x9f, 0x98, 0x93, 0x91, 0x92, 0x95,
-0x9b, 0xa7, 0xc1, 0x3a, 0x25, 0x1c, 0x18, 0x16, 0x17, 0x1a,
-0x1f, 0x2b, 0x42, 0xc6, 0xae, 0xa6, 0xa0, 0x9f, 0xa0, 0xa5,
-0xab, 0xb6, 0xcb, 0x5a, 0x40, 0x39, 0x36, 0x37, 0x3b, 0x43,
-0x4e, 0x60, 0x7b, 0x7c, 0x60, 0x4e, 0x41, 0x3a, 0x34, 0x32,
-0x33, 0x39, 0x45, 0xed, 0xbd, 0xae, 0xa6, 0xa0, 0x9e, 0x9e,
-0xa0, 0xa8, 0xb4, 0xef, 0x34, 0x24, 0x1c, 0x18, 0x16, 0x16,
-0x19, 0x1e, 0x2b, 0x54, 0xb1, 0x9f, 0x98, 0x93, 0x91, 0x91,
-0x95, 0x9b, 0xa6, 0xc6, 0x33, 0x1f, 0x17, 0x12, 0xf, 0x10,
-0x13, 0x1a, 0x24, 0x3e, 0xb8, 0xa2, 0x99, 0x94, 0x92, 0x92,
-0x96, 0x9b, 0xa6, 0xbc, 0x40, 0x29, 0x1e, 0x1a, 0x18, 0x19,
-0x1b, 0x20, 0x2b, 0x3f, 0xcf, 0xb3, 0xa9, 0xa5, 0xa3, 0xa4,
-0xa8, 0xae, 0xb9, 0xcc, 0x67, 0x49, 0x40, 0x3f, 0x42, 0x4a,
-0x59, 0x79, 0xe5, 0xe4, 0x7a, 0x54, 0x43, 0x39, 0x31, 0x2d,
-0x2c, 0x2d, 0x32, 0x3e, 0x71, 0xbd, 0xad, 0xa4, 0x9e, 0x9c,
-0x9c, 0x9e, 0xa4, 0xaf, 0xd7, 0x36, 0x24, 0x1c, 0x17, 0x15,
-0x15, 0x17, 0x1d, 0x28, 0x47, 0xb5, 0xa1, 0x98, 0x93, 0x90,
-0x90, 0x93, 0x99, 0xa4, 0xbd, 0x38, 0x21, 0x18, 0x13, 0x10,
-0x10, 0x13, 0x19, 0x22, 0x39, 0xbe, 0xa5, 0x9b, 0x96, 0x93,
-0x93, 0x96, 0x9b, 0xa5, 0xb9, 0x4a, 0x2c, 0x20, 0x1c, 0x1a,
-0x1a, 0x1d, 0x22, 0x2c, 0x3d, 0xdc, 0xb8, 0xad, 0xa9, 0xa8,
-0xa9, 0xac, 0xb2, 0xbd, 0xce, 0x78, 0x54, 0x4d, 0x4f, 0x5a,
-0xff, 0xda, 0xcf, 0xcd, 0xd4, 0xf8, 0x4e, 0x3d, 0x32, 0x2c,
-0x29, 0x28, 0x29, 0x2d, 0x38, 0x5c, 0xbd, 0xac, 0xa2, 0x9d,
-0x9a, 0x9a, 0x9c, 0xa0, 0xac, 0xca, 0x39, 0x25, 0x1b, 0x16,
-0x13, 0x13, 0x16, 0x1b, 0x25, 0x3e, 0xb9, 0xa2, 0x99, 0x93,
-0x90, 0x90, 0x93, 0x98, 0xa1, 0xb8, 0x3d, 0x24, 0x19, 0x13,
-0x10, 0x10, 0x13, 0x18, 0x21, 0x35, 0xc7, 0xa8, 0x9d, 0x97,
-0x95, 0x95, 0x97, 0x9c, 0xa4, 0xb6, 0x57, 0x2f, 0x24, 0x1e,
-0x1c, 0x1c, 0x1e, 0x24, 0x2d, 0x3d, 0xf1, 0xbe, 0xb2, 0xad,
-0xac, 0xad, 0xb1, 0xb9, 0xc3, 0xd4, 0xfa, 0x64, 0x65, 0xf9,
-0xd9, 0xca, 0xc2, 0xbf, 0xc0, 0xc9, 0xe7, 0x4c, 0x39, 0x2e,
-0x28, 0x24, 0x23, 0x25, 0x29, 0x33, 0x4f, 0xbf, 0xab, 0xa0,
-0x9b, 0x99, 0x98, 0x9a, 0x9e, 0xa9, 0xc0, 0x3c, 0x26, 0x1b,
-0x16, 0x12, 0x12, 0x14, 0x19, 0x22, 0x38, 0xbe, 0xa4, 0x9a,
-0x93, 0x90, 0x8f, 0x92, 0x97, 0x9f, 0xb3, 0x46, 0x26, 0x1b,
-0x15, 0x11, 0x11, 0x13, 0x18, 0x1f, 0x31, 0xd4, 0xab, 0x9e,
-0x99, 0x96, 0x96, 0x98, 0x9c, 0xa4, 0xb4, 0x6f, 0x34, 0x28,
-0x20, 0x1e, 0x1e, 0x20, 0x26, 0x2e, 0x3d, 0x6d, 0xc5, 0xb9,
-0xb3, 0xb2, 0xb4, 0xba, 0xc1, 0xcd, 0xe0, 0xfc, 0xfb, 0xe0,
-0xce, 0xc3, 0xbb, 0xb7, 0xb6, 0xb9, 0xc0, 0xda, 0x4b, 0x36,
-0x2b, 0x25, 0x20, 0x1f, 0x20, 0x26, 0x2e, 0x46, 0xc2, 0xab,
-0x9f, 0x9a, 0x97, 0x96, 0x98, 0x9c, 0xa5, 0xba, 0x41, 0x27,
-0x1b, 0x15, 0x12, 0x11, 0x13, 0x18, 0x1f, 0x32, 0xc8, 0xa6,
-0x9a, 0x94, 0x90, 0x8f, 0x91, 0x97, 0x9e, 0xaf, 0x54, 0x29,
-0x1c, 0x16, 0x12, 0x11, 0x14, 0x18, 0x1f, 0x2e, 0xf2, 0xae,
-0xa0, 0x9b, 0x98, 0x97, 0x99, 0x9d, 0xa5, 0xb3, 0xe4, 0x3a,
-0x2b, 0x25, 0x21, 0x21, 0x24, 0x29, 0x30, 0x3e, 0x62, 0xcd,
-0xbf, 0xbb, 0xbb, 0xbe, 0xc6, 0xd1, 0xe7, 0x76, 0x75, 0xe7,
-0xcf, 0xc1, 0xb9, 0xb2, 0xaf, 0xaf, 0xb2, 0xba, 0xcf, 0x4c,
-0x34, 0x29, 0x22, 0x1e, 0x1d, 0x1e, 0x22, 0x2b, 0x3e, 0xc7,
-0xab, 0x9f, 0x99, 0x96, 0x95, 0x96, 0x9a, 0xa2, 0xb5, 0x4a,
-0x28, 0x1c, 0x15, 0x11, 0x10, 0x12, 0x17, 0x1e, 0x2e, 0xd5,
-0xa9, 0x9b, 0x95, 0x90, 0x8f, 0x91, 0x96, 0x9d, 0xac, 0x78,
-0x2c, 0x1e, 0x17, 0x13, 0x12, 0x14, 0x18, 0x1f, 0x2d, 0x5d,
-0xb3, 0xa4, 0x9d, 0x9a, 0x99, 0x9b, 0x9e, 0xa6, 0xb2, 0xd6,
-0x3f, 0x2f, 0x29, 0x26, 0x26, 0x28, 0x2d, 0x35, 0x42, 0x5e,
-0xd8, 0xca, 0xc6, 0xc9, 0xcf, 0xe4, 0x69, 0x59, 0x58, 0x64,
-0xdf, 0xc7, 0xba, 0xb1, 0xac, 0xaa, 0xaa, 0xad, 0xb4, 0xc7,
-0x4f, 0x33, 0x27, 0x1f, 0x1c, 0x1b, 0x1c, 0x1f, 0x27, 0x39,
-0xce, 0xac, 0x9f, 0x99, 0x95, 0x94, 0x95, 0x99, 0x9f, 0xaf,
-0x59, 0x2a, 0x1c, 0x16, 0x11, 0x10, 0x11, 0x16, 0x1d, 0x2b,
-0xff, 0xab, 0x9d, 0x96, 0x91, 0x90, 0x91, 0x96, 0x9c, 0xaa,
-0xd9, 0x2f, 0x1f, 0x19, 0x15, 0x14, 0x15, 0x19, 0x1f, 0x2c,
-0x4e, 0xb9, 0xa7, 0x9f, 0x9c, 0x9b, 0x9c, 0x9f, 0xa7, 0xb3,
-0xcf, 0x47, 0x34, 0x2d, 0x2a, 0x2a, 0x2c, 0x31, 0x3a, 0x47,
-0x5f, 0xe4, 0xd8, 0xd9, 0xe9, 0x64, 0x4f, 0x49, 0x46, 0x49,
-0x58, 0xde, 0xc2, 0xb5, 0xad, 0xa8, 0xa6, 0xa6, 0xa9, 0xaf,
-0xbf, 0x56, 0x32, 0x26, 0x1e, 0x1b, 0x19, 0x1a, 0x1d, 0x24,
-0x33, 0xdd, 0xad, 0x9f, 0x98, 0x94, 0x92, 0x93, 0x97, 0x9e,
-0xac, 0xf8, 0x2c, 0x1d, 0x16, 0x11, 0xf, 0x10, 0x15, 0x1b,
-0x29, 0x55, 0xae, 0x9e, 0x97, 0x92, 0x90, 0x91, 0x95, 0x9c,
-0xa8, 0xca, 0x35, 0x22, 0x1a, 0x16, 0x15, 0x16, 0x19, 0x1f,
-0x2b, 0x47, 0xbe, 0xab, 0xa2, 0x9e, 0x9d, 0x9e, 0xa2, 0xa9,
-0xb4, 0xcc, 0x4f, 0x3a, 0x32, 0x2f, 0x2f, 0x32, 0x39, 0x41,
-0x4f, 0x67, 0xf5, 0xf5, 0x67, 0x51, 0x46, 0x3e, 0x3b, 0x3b,
-0x3f, 0x4d, 0xe2, 0xbe, 0xb0, 0xa9, 0xa4, 0xa1, 0xa1, 0xa5,
-0xab, 0xba, 0x64, 0x33, 0x25, 0x1d, 0x19, 0x17, 0x18, 0x1b,
-0x20, 0x2e, 0x72, 0xae, 0x9f, 0x98, 0x94, 0x91, 0x92, 0x96,
-0x9c, 0xa9, 0xd4, 0x2f, 0x1e, 0x17, 0x11, 0xf, 0x10, 0x14,
-0x1a, 0x26, 0x48, 0xb2, 0x9f, 0x98, 0x93, 0x91, 0x92, 0x95,
-0x9b, 0xa7, 0xc1, 0x3a, 0x25, 0x1c, 0x18, 0x16, 0x17, 0x1a,
-0x1f, 0x2b, 0x42, 0xc6, 0xae, 0xa6, 0xa0, 0x9f, 0xa0, 0xa5,
-0xab, 0xb6, 0xcb, 0x5a, 0x40, 0x39, 0x36, 0x37, 0x3b, 0x43,
-0x4e, 0x60, 0x7b, 0x7c, 0x60, 0x4e, 0x41, 0x3a, 0x34, 0x32,
-0x33, 0x39, 0x45, 0xed, 0xbd, 0xae, 0xa6, 0xa0, 0x9e, 0x9e,
-0xa0, 0xa8, 0xb4, 0xef, 0x34, 0x24, 0x1c, 0x18, 0x16, 0x16,
-0x19, 0x1e, 0x2b, 0x54, 0xb1, 0x9f, 0x98, 0x93, 0x91, 0x91,
-0x95, 0x9b, 0xa6, 0xc6, 0x33, 0x1f, 0x17, 0x12, 0xf, 0x10,
-0x13, 0x1a, 0x24, 0x3e, 0xb8, 0xa2, 0x99, 0x94, 0x92, 0x92,
-0x96, 0x9b, 0xa6, 0xbc, 0x40, 0x29, 0x1e, 0x1a, 0x18, 0x19,
-0x1b, 0x20, 0x2b, 0x3f, 0xcf, 0xb3, 0xa9, 0xa5, 0xa3, 0xa4,
-0xa8, 0xae, 0xb9, 0xcc, 0x67, 0x49, 0x40, 0x3f, 0x42, 0x4a,
-0x59, 0x79, 0xe5, 0xe4, 0x7a, 0x54, 0x43, 0x39, 0x31, 0x2d,
-0x2c, 0x2d, 0x32, 0x3e, 0x71, 0xbd, 0xad, 0xa4, 0x9e, 0x9c,
-0x9c, 0x9e, 0xa4, 0xaf, 0xd7, 0x36, 0x24, 0x1c, 0x17, 0x15,
-0x15, 0x17, 0x1d, 0x28, 0x47, 0xb5, 0xa1, 0x98, 0x93, 0x90,
-0x90, 0x93, 0x99, 0xa4, 0xbd, 0x38, 0x21, 0x18, 0x13, 0x10,
-0x10, 0x13, 0x19, 0x22, 0x39, 0xbe, 0xa5, 0x9b, 0x96, 0x93,
-0x93, 0x96, 0x9b, 0xa5, 0xb9, 0x4a, 0x2c, 0x20, 0x1c, 0x1a,
-0x1a, 0x1d, 0x22, 0x2c, 0x3d, 0xdc, 0xb8, 0xad, 0xa9, 0xa8,
-0xa9, 0xac, 0xb2, 0xbd, 0xce, 0x78, 0x54, 0x4d, 0x4f, 0x5a,
-0xff, 0xda, 0xcf, 0xcd, 0xd4, 0xf8, 0x4e, 0x3d, 0x32, 0x2c,
-0x29, 0x28, 0x29, 0x2d, 0x38, 0x5c, 0xbd, 0xac, 0xa2, 0x9d,
-0x9a, 0x9a, 0x9c, 0xa0, 0xac, 0xca, 0x39, 0x25, 0x1b, 0x16,
-0x13, 0x13, 0x16, 0x1b, 0x25, 0x3e, 0xb9, 0xa2, 0x99, 0x93,
-0x90, 0x90, 0x93, 0x98, 0xa1, 0xb8, 0x3d, 0x24, 0x19, 0x13,
-0x10, 0x10, 0x13, 0x18, 0x21, 0x35, 0xc7, 0xa8, 0x9d, 0x97,
-0x95, 0x95, 0x97, 0x9c, 0xa4, 0xb6, 0x57, 0x2f, 0x24, 0x1e,
-0x1c, 0x1c, 0x1e, 0x24, 0x2d, 0x3d, 0xf1, 0xbe, 0xb2, 0xad,
-0xac, 0xad, 0xb1, 0xb9, 0xc3, 0xd4, 0xfa, 0x64, 0x65, 0xf9,
-0xd9, 0xca, 0xc2, 0xbf, 0xc0, 0xc9, 0xe7, 0x4c, 0x39, 0x2e,
-0x28, 0x24, 0x23, 0x25, 0x29, 0x33, 0x4f, 0xbf, 0xab, 0xa0,
-0x9b, 0x99, 0x98, 0x9a, 0x9e, 0xa9, 0xc0, 0x3c, 0x26, 0x1b,
-0x16, 0x12, 0x12, 0x14, 0x19, 0x22, 0x38, 0xbe, 0xa4, 0x9a,
-0x93, 0x90, 0x8f, 0x92, 0x97, 0x9f, 0xb3, 0x46, 0x26, 0x1b,
-0x15, 0x11, 0x11, 0x13, 0x18, 0x1f, 0x31, 0xd4, 0xab, 0x9e,
-0x99, 0x96, 0x96, 0x98, 0x9c, 0xa4, 0xb4, 0x6f, 0x34, 0x28,
-0x20, 0x1e, 0x1e, 0x20, 0x26, 0x2e, 0x3d, 0x6d, 0xc5, 0xb9,
-0xb3, 0xb2, 0xb4, 0xba, 0xc1, 0xcd, 0xe0, 0xfc, 0xfb, 0xe0,
-0xce, 0xc3, 0xbb, 0xb7, 0xb6, 0xb9, 0xc0, 0xda, 0x4b, 0x36,
-0x2b, 0x25, 0x20, 0x1f, 0x20, 0x26, 0x2e, 0x46, 0xc2, 0xab,
-0x9f, 0x9a, 0x97, 0x96, 0x98, 0x9c, 0xa5, 0xba, 0x41, 0x27,
-0x1b, 0x15, 0x12, 0x11, 0x13, 0x18, 0x1f, 0x32, 0xc8, 0xa6,
-0x9a, 0x94, 0x90, 0x8f, 0x91, 0x97, 0x9e, 0xaf, 0x54, 0x29,
-0x1c, 0x16, 0x12, 0x11, 0x14, 0x18, 0x1f, 0x2e, 0xf2, 0xae,
-0xa0, 0x9b, 0x98, 0x97, 0x99, 0x9d, 0xa5, 0xb3, 0xe4, 0x3a,
-0x2b, 0x25, 0x21, 0x21, 0x24, 0x29, 0x30, 0x3e, 0x62, 0xcd,
-0xbf, 0xbb, 0xbb, 0xbe, 0xc6, 0xd1, 0xe7, 0x76, 0x75, 0xe7,
-0xcf, 0xc1, 0xb9, 0xb2, 0xaf, 0xaf, 0xb2, 0xba, 0xcf, 0x4c,
-0x34, 0x29, 0x22, 0x1e, 0x1d, 0x1e, 0x22, 0x2b, 0x3e, 0xc7,
-0xab, 0x9f, 0x99, 0x96, 0x95, 0x96, 0x9a, 0xa2, 0xb5, 0x4a,
-0x28, 0x1c, 0x15, 0x11, 0x10, 0x12, 0x17, 0x1e, 0x2e, 0xd5,
-0xa9, 0x9b, 0x95, 0x90, 0x8f, 0x91, 0x96, 0x9d, 0xac, 0x78,
-0x2c, 0x1e, 0x17, 0x13, 0x12, 0x14, 0x18, 0x1f, 0x2d, 0x5d,
-0xb3, 0xa4, 0x9d, 0x9a, 0x99, 0x9b, 0x9e, 0xa6, 0xb2, 0xd6,
-0x3f, 0x2f, 0x29, 0x26, 0x26, 0x28, 0x2d, 0x35, 0x42, 0x5e,
-0xd8, 0xca, 0xc6, 0xc9, 0xcf, 0xe4, 0x69, 0x59, 0x58, 0x64,
-0xdf, 0xc7, 0xba, 0xb1, 0xac, 0xaa, 0xaa, 0xad, 0xb4, 0xc7,
-0x4f, 0x33, 0x27, 0x1f, 0x1c, 0x1b, 0x1c, 0x1f, 0x27, 0x39,
-0xce, 0xac, 0x9f, 0x99, 0x95, 0x94, 0x95, 0x99, 0x9f, 0xaf,
-0x59, 0x2a, 0x1c, 0x16, 0x11, 0x10, 0x11, 0x16, 0x1d, 0x2b };
diff --git a/1.2-netsec/channels/Makefile b/1.2-netsec/channels/Makefile
deleted file mode 100644
index 349343f5a..000000000
--- a/1.2-netsec/channels/Makefile
+++ /dev/null
@@ -1,262 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Makefile for channel drivers
-#
-# Copyright (C) 1999-2005, Mark Spencer
-#
-# Mark Spencer <markster@digium.com>
-#
-# Edited By Belgarath <> Aug 28 2004
-# Added bare bones ultrasparc-linux support.
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-CHANNEL_LIBS=chan_sip.so chan_agent.so chan_mgcp.so chan_iax2.so chan_local.so chan_skinny.so chan_features.so
-
-ifneq (${OSARCH},CYGWIN)
-# if you really, really want to use these drivers, uncomment the line below
-#CHANNEL_LIBS+=chan_modem.so chan_modem_aopen.so chan_modem_bestdata.so
-endif
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-ifeq (${OSARCH},OpenBSD)
- PTLIB=-lpt_OpenBSD_x86_r
- H323LIB=-lh323_OpenBSD_x86_r
-endif
-
-ifeq (${OSARCH},Linux)
- PTLIB=-lpt_linux_x86_r
- H323LIB=-lh323_linux_x86_r
- CHANH323LIB=-ldl
-endif
-
-ifeq (${OSARCH},CYGWIN)
-CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
-CYGSOLIB=-L.. -L. -L../res -lasterisk.dll -lres_features.so
-CYG_CHAN_AGENT=-lres_monitor.so
-endif
-
-ifeq ($(PROC),sparc64)
- PROC=ultrasparc
- CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
-endif
-
-ifeq (${OSARCH},FreeBSD)
- PTLIB=-lpt_FreeBSD_x86_r
- H323LIB=-lh323_FreeBSD_x86_r
- CHANH323LIB=-pthread
-endif
-
-ifeq (${OSARCH},NetBSD)
- PTLIB=-lpt_NetBSD_x86_r
- H323LIB=-lh323_NetBSD_x86_r
-endif
-
-ifneq (${OSARCH},Darwin)
- ifneq (${OSARCH},SunOS)
- ifneq (${OSARCH},CYGWIN)
-# the ISDN4Linux channel driver is probably broken on all modern kernels,
-# but if you wish to try to use it, uncomment the line below
-# CHANNEL_LIBS+=chan_modem_i4l.so
- CHANNEL_LIBS+=chan_oss.so
- endif
- endif
-endif
-
-ifeq (${OSARCH},SunOS)
- SOLINK+=-lrt
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/linux/ixjuser.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/ixjuser.h),)
- CHANNEL_LIBS+=chan_phone.so
-endif
-
-ifneq ($(wildcard h323/libchanh323.a),)
- CHANNEL_LIBS+=chan_h323.so
-endif
-
-ifneq ($(wildcard misdn/chan_misdn_lib.a),)
- CHANNEL_LIBS+=chan_misdn.so
- CFLAGS+=-Imisdn
-endif
-
-CFLAGS+=-Wno-missing-prototypes -Wno-missing-declarations
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/alsa/asoundlib.h),)
- CHANNEL_LIBS+=chan_alsa.so
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/lib/libpri.so.1)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/lib/libpri.so.1),)
- CFLAGS+=-DZAPATA_PRI
- ZAPPRI=-lpri
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/lib/asterisk/modules/res_netsec.so)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/lib/asterisk/modules/res_netsec.so),)
- CFLAGS+=-DSIP_MIDCOM
-# NETSEC=-lnetsec -lssl -lcrypto -lstdc++
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/lib/libmfcr2.so.1)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/lib/libmfcr2.so.1),)
- CFLAGS+=-DZAPATA_R2
- ZAPR2=-lmfcr2
-endif
-
-ALSA_SRC=chan_alsa.c
-
-ifneq ($(wildcard alsa-monitor.h),)
- CFLAGS+=-DALSA_MONITOR
- ALSA_SRC+=alsa-monitor.h
-endif
-
-ifndef WITHOUT_ZAPTEL
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/linux/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/pkg/include/zaptel.h),)
- ifeq (${OSARCH},NetBSD)
- SOLINK+=-L$(CROSS_COMPILE_TARGET)/usr/pkg/lib
- endif
- ifeq (${OSARCH},FreeBSD)
- SOLINK+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib
- endif
- CFLAGS+=-DIAX_TRUNKING
- CHANNEL_LIBS+=chan_zap.so
-endif
-endif # WITHOUT_ZAPTEL
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/vpbapi.h),)
- CHANNEL_LIBS+=chan_vpb.so
- CFLAGS+=-DLINUX
-endif
-
-CFLAGS+=-DCRYPTO
-
-ifneq ($(OSARCH),CYGWIN)
-CFLAGS+=-fPIC
-endif
-
-CFLAGS+=#-DVOFRDUMPER
-
-ZAPDIR=/usr/lib
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/nbs.h),)
- CHANNEL_LIBS+=chan_nbs.so
-endif
-
-ifndef OPENH323DIR
- OPENH323DIR=$(HOME)/openh323
-endif
-
-ifndef PWLIBDIR
- PWLIBDIR=$(HOME)/pwlib
-endif
-
-#CFLAGS+=$(shell [ -f $(ZAPDIR)/libzap.a ] && echo "-I$(ZAPDIR)")
-
-all: depend $(CHANNEL_LIBS)
-
-clean:
- rm -f *.so *.o .depend
- rm -f busy.h ringtone.h gentone gentone-ulaw
-
-%.so : %.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} ${LIBS}
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-ifneq ($(wildcard h323/Makefile.ast),)
- include h323/Makefile.ast
-endif
-
-ifneq ($(wildcard misdn/Makefile.ast),)
- include misdn/Makefile.ast
-endif
-
-gentone: gentone.c
- $(HOST_CC) -o gentone gentone.c -lm
-
-gentone-ulaw: gentone-ulaw.c
- $(HOST_CC) -o gentone-ulaw gentone-ulaw.c -lm
-
-busy.h: gentone
- ./gentone busy 480 620
-
-ringtone.h: gentone
- ./gentone ringtone 440 480
-
-chan_oss.o: chan_oss.c busy.h ringtone.h
-
-chan_alsa.o: chan_alsa.c busy.h ringtone.h
-
-ifeq (${OSARCH},OpenBSD)
-chan_oss.so: chan_oss.o
- $(CC) $(SOLINK) -o $@ chan_oss.o -lossaudio
-endif
-ifeq (${OSARCH},NetBSD)
-chan_oss.so: chan_oss.o
- $(CC) $(SOLINK) -o $@ chan_oss.o -lossaudio
-endif
-
-chan_iax2.so: chan_iax2.o iax2-parser.o iax2-provision.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} chan_iax2.o iax2-parser.o iax2-provision.o ${CYGSOLIB}
-
-chan_zap.o: chan_zap.c
- $(CC) -c $(CFLAGS) -o chan_zap.o chan_zap.c
-
-chan_zap.so: chan_zap.o
- $(CC) $(SOLINK) -o $@ $< $(ZAPPRI) $(ZAPR2) -ltonezone
-
-chan_sip.so: chan_sip.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} chan_sip.o ${CYGSOLIB} ${NETSEC}
-
-chan_agent.so: chan_agent.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} chan_agent.o ${CYGSOLIB} ${CYG_CHAN_AGENT}
-
-chan_alsa.o: $(ALSA_SRC)
-
-chan_alsa.so: chan_alsa.o
- $(CC) $(SOLINK) -o $@ $< -lasound -lm -ldl
-
-chan_nbs.so: chan_nbs.o
- $(CC) $(SOLINK) -o $@ $< -lnbs
-
-chan_vpb.o: chan_vpb.c
- $(CXX) -c $(CFLAGS) -o $@ chan_vpb.c
-
-chan_vpb.so: chan_vpb.o
- $(CXX) $(SOLINK) -o $@ $< -lvpb -lpthread -lm -ldl
-
-ifeq (${OSARCH},Linux)
-chan_h323.so: chan_h323.o h323/libchanh323.a h323/Makefile.ast
- $(CC) $(SOLINK) $(H323LDFLAGS) -o $@ $< h323/libchanh323.a $(H323LDLIBS) -lstdc++
-else
-chan_h323.so: chan_h323.o h323/libchanh323.a
- $(CC) $(SOLINK) -o $@ $< h323/libchanh323.a $(CHANH323LIB) -L$(PWLIBDIR)/lib $(PTLIB) -L$(OPENH323DIR)/lib $(H323LIB) -L/usr/lib -lcrypto -lssl -lexpat
-endif
-
-chan_misdn.so: chan_misdn.o chan_misdn_config.o misdn/chan_misdn_lib.a
- $(CC) -shared -Xlinker -x -L/usr/lib -o $@ $^ -lmISDN -lisdnnet
-
-chan_misdn.o: chan_misdn.c
- $(CC) $(CFLAGS) -DCHAN_MISDN_VERSION=\"0.2.1\" -c $< -o $@
-
-#chan_modem.so : chan_modem.o
-# $(CC) -rdynamic -shared -Xlinker -x -o $@ $<
-
-install: all
- for x in $(CHANNEL_LIBS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
- if ! [ -f chan_iax.so ]; then rm -f $(DESTDIR)$(MODULES_DIR)/chan_iax.so ; fi
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
-
-env:
- env
-
diff --git a/1.2-netsec/channels/adtranvofr.h b/1.2-netsec/channels/adtranvofr.h
deleted file mode 100644
index 88fd428ee..000000000
--- a/1.2-netsec/channels/adtranvofr.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Asterisk -- A telephony toolkit for Linux.
- *
- * Implementation of Voice over Frame Relay, Adtran Style
- *
- * Copyright (C) 1999, Mark Spencer
- *
- * Mark Spencer <markster@linux-support.net>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-#ifndef _ADTRANVOFR_H
-#define _ADTRANVOFR_H
-
-#define VOFR_CONTROL_ADTRAN 0x0
-#define VOFR_CONTROL_VOICE 0x1
-#define VOFR_CONTROL_RFC1490 0x3
-
-#define VOFR_TYPE_SIGNAL 0x0
-#define VOFR_TYPE_VOICE 0x1
-#define VOFR_TYPE_ANSWER 0x2
-#define VOFR_TYPE_FAX 0x3
-#define VOFR_TYPE_DTMF 0x4
-
-#define VOFR_CARD_TYPE_UNSPEC 0x0
-#define VOFR_CARD_TYPE_FXS 0x1
-#define VOFR_CARD_TYPE_FXO 0x2
-#define VOFR_CARD_TYPE_ENM 0x3
-#define VOFR_CARD_TYPE_VCOM 0x4
-#define VOFR_CARD_TYPE_ASTERISK 0xf
-
-#define VOFR_MODULATION_SINGLE 0x0
-#define VOFR_MODULATION_V21 0x1
-#define VOFR_MODULATION_V27ter_2 0x2
-#define VOFR_MODULATION_V27ter_4 0x3
-#define VOFR_MODULATION_V29_7 0x4
-#define VOFR_MODULATION_V29_9 0x5
-#define VOFR_MODULATION_V33_12 0x6
-#define VOFR_MODULATION_V33_14 0x7
-
-#define VOFR_ROUTE_NONE 0x0
-#define VOFR_ROUTE_LOCAL 0x1
-#define VOFR_ROUTE_VOICE 0x2
-#define VOFR_ROUTE_DTE1 0x4
-#define VOFR_ROUTE_DTE2 0x8
-#define VOFR_ROUTE_DTE 0xC
-
-#define VOFR_MASK_EI 0x80
-#define VOFR_MASK_LI 0x40
-#define VOFR_MASK_CONTROL 0x3F
-
-#define VOFR_SIGNAL_ON_HOOK 0x00
-#define VOFR_SIGNAL_OFF_HOOK 0x01
-#define VOFR_SIGNAL_RING 0x40
-#define VOFR_SIGNAL_SWITCHED_DIAL 0x08
-#define VOFR_SIGNAL_BUSY 0x02
-#define VOFR_SIGNAL_TRUNK_BUSY 0x04
-#define VOFR_SIGNAL_UNKNOWN 0x10
-#define VOFR_SIGNAL_OFFHOOK 0x81
-
-#define VOFR_TRACE_SIGNAL 1 << 0
-#define VOFR_TRACE_VOICE 1 << 1
-
-#define VOFR_MAX_PKT_SIZE 1500
-
-/*
- * Wire level protocol
- */
-
-struct vofr_hdr {
- u_int8_t control; /* Also contains unused EI and LI bits */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- u_int8_t dtype:4; /* Data type */
- u_int8_t ctag:4; /* Connect tag */
- u_int8_t dlcih:4; /* Hi 2 bits of DLCI x-ref */
- u_int8_t vflags:4; /* Voice Routing Flags */
- u_int8_t dlcil; /* Lo 8 bits of DLCI x-ref */
- u_int8_t cid; /* Channel ID */
- u_int8_t mod:4; /* Modulation */
- u_int8_t remid:4; /* Remote ID */
-#elif __BYTE_ORDER == __BIG_ENDIAN
- u_int8_t ctag:4; /* Connect tag */
- u_int8_t dtype:4; /* Data type */
- u_int8_t vflags:4; /* Voice Routing Flags */
- u_int8_t dlcih:4; /* Hi 2 bits of DLCI x-ref */
- u_int8_t dlcil; /* Lo 8 bits of DLCI x-ref */
- u_int8_t cid; /* Channel ID */
- u_int8_t remid:4; /* Remote ID or Relay CMD*/
- u_int8_t mod:4; /* Modulation */
-#else
-#error "Please fix <bytesex.h>"
-#endif
-#ifdef __GNUC__
- u_int8_t data[0]; /* Data */
-#endif
-};
-
-#define VOFR_HDR_SIZE 6
-
-/* Number of milliseconds to fudge -- experimentally derived */
-#define VOFR_FUDGE 2
-
-#endif
diff --git a/1.2-netsec/channels/answer.h b/1.2-netsec/channels/answer.h
deleted file mode 100644
index 4168c5012..000000000
--- a/1.2-netsec/channels/answer.h
+++ /dev/null
@@ -1,237 +0,0 @@
-/*!\file
- * \brief Signed 16-bit audio data
- *
- * Source: answer.raw
- *
- * Copyright (C) 1999-2005, Digium, Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short answer[] = {
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 0x19b7, 0x0245, 0xeee5, 0xb875, 0xd9a4, 0x6018, 0x660a, 0xc3c6,
-0x8741, 0xff55, 0x4c2e, 0x2146, 0xfed2, 0xf079, 0xcbd4, 0xe561, 0x3c41, 0x3166,
-0xd425, 0xdc59, 0x2748, 0x087d, 0xc72b, 0xfe3a, 0x4681, 0x14c6, 0xcf45, 0xdd38,
-0xf8dd, 0x0a39, 0x3a5a, 0x32b9, 0xbfec, 0x957f, 0x15a3, 0x70f4, 0x1d95, 0xbfc4,
-0xd367, 0xfda0, 0x0dc0, 0x29eb, 0x1fc2, 0xd684, 0xcab1, 0x19c7, 0x29ef, 0xe679,
-0xe9d0, 0x2b82, 0x151a, 0xca9f, 0xdb68, 0x1f4a, 0x271c, 0x0e2a, 0xfb32, 0xd1b2,
-0xc8ff, 0x2382, 0x6380, 0x0a52, 0xa118, 0xccbf, 0x2ddc, 0x33fd, 0x0964, 0xf2a4,
-0xdd81, 0xe092, 0x1a00, 0x325c, 0xf5e3, 0xd6a1, 0x0b6c, 0x1c75, 0xe4f8, 0xe07c,
-0x2082, 0x2b3e, 0xf445, 0xdaa9, 0xea13, 0xff3c, 0x245c, 0x35c1, 0xf308, 0xab53,
-0xdf59, 0x4698, 0x3f3b, 0xe7f7, 0xca84, 0xed4d, 0x0c3f, 0x1e94, 0x1c2d, 0xf06f,
-0xd4df, 0xff34, 0x23d8, 0x001e, 0xe3f1, 0x0b15, 0x2113, 0xf3fd, 0xd768, 0xf9a0,
-0x1d31, 0x1c6e, 0x0797, 0xe3a0, 0xce6c, 0xfd7b, 0x422a, 0x2c4c, 0xd364, 0xbf42,
-0x0278, 0x303e, 0x1c51, 0xf737, 0xe25a, 0xe75f, 0x0a8f, 0x22ab, 0x05f4, 0xe3f9,
-0xf8c4, 0x1705, 0x0162, 0xe49f, 0xfb8b, 0x1e2b, 0x13ac, 0xf044, 0xe07b, 0xf01a,
-0x1567, 0x2cbf, 0x0b75, 0xd01b, 0xd206, 0x1563, 0x38d7, 0x0f2e, 0xdb32, 0xdc30,
-0x023b, 0x1e44, 0x16eb, 0xf5f7, 0xe425, 0xfa33, 0x14d5, 0x0968, 0xeff2, 0xf762,
-0x1137, 0x0e59, 0xf13a, 0xe651, 0xff41, 0x1d60, 0x18fd, 0xf1e6, 0xd75f, 0xf097,
-0x20ec, 0x27fa, 0xfba4, 0xd5b8, 0xe68e, 0x1657, 0x2518, 0x04f6, 0xe5a3, 0xe976,
-0x0578, 0x18fa, 0x0a92, 0xec0a, 0xef2a, 0x111f, 0x12f4, 0xeec3, 0xe95e, 0x0d3a,
-0x18fd, 0xff72, 0xeefc, 0xf114, 0xfaaa, 0x14ee, 0x21db, 0xf56e, 0xcb49, 0xf621,
-0x3323, 0x1947, 0xe017, 0xe7e9, 0x0819, 0x0707, 0x084c, 0x0f57, 0xf152, 0xdf92,
-0x104a, 0x28eb, 0xedcc, 0xd4ad, 0x1415, 0x296d, 0xed9a, 0xdf57, 0x0cc2, 0x0d95,
-0xf7b5, 0x0deb, 0x0b34, 0xd713, 0xea08, 0x38d6, 0x216d, 0xc727, 0xdc32, 0x2cd2,
-0x1822, 0xe2d5, 0xfeb3, 0x106c, 0xe6e5, 0xf81e, 0x2fe8, 0x01af, 0xc180, 0x037a,
-0x42d8, 0xf88d, 0xc344, 0x0a4f, 0x2c4e, 0xf19d, 0xebeb, 0x162c, 0xf9e9, 0xde93,
-0x1b56, 0x2c60, 0xd8aa, 0xce3e, 0x2a41, 0x2eeb, 0xdab1, 0xde32, 0x1c32, 0x0aba,
-0xeabe, 0x1008, 0x136d, 0xda2f, 0xec3b, 0x31dd, 0x1130, 0xca79, 0xf5b8, 0x3423,
-0x0274, 0xd27d, 0x035e, 0x1e68, 0xf641, 0xf904, 0x1691, 0xef7d, 0xd57a, 0x1c3b,
-0x3c23, 0xe881, 0xc274, 0x0af5, 0x2962, 0xfa34, 0xf676, 0x0f71, 0xefcc, 0xe01f,
-0x19e7, 0x276f, 0xe694, 0xe134, 0x1c3a, 0x0e8b, 0xd8e7, 0xfa81, 0x2f8b, 0x07c5,
-0xd904, 0xf6fa, 0x0ca5, 0xf9a2, 0x0dc7, 0x2623, 0xec54, 0xbe23, 0x02b6, 0x4296,
-0x10cd, 0xda61, 0xf11c, 0x0103, 0xf41c, 0x10b4, 0x2a03, 0xf63c, 0xce1a, 0xfdbd,
-0x1fb4, 0xfc51, 0xf727, 0x1c8a, 0x04ff, 0xcf41, 0xec05, 0x2913, 0x1ce8, 0xf70c,
-0xf744, 0xede8, 0xdd77, 0x0d99, 0x43f1, 0x119c, 0xc14f, 0xd60e, 0x17cb, 0x1e19,
-0x0d4e, 0x0c95, 0xeed1, 0xcdf4, 0xf7a5, 0x331f, 0x1cd0, 0xeb17, 0xf082, 0xfb19,
-0xe899, 0xfdeb, 0x323c, 0x2036, 0xdad3, 0xd134, 0xfd03, 0x1345, 0x1c10, 0x2239,
-0xf656, 0xbc22, 0xdc3f, 0x3392, 0x3d59, 0xfd77, 0xdb4d, 0xe23f, 0xedbe, 0x0f7e,
-0x35cc, 0x1947, 0xd5dc, 0xd1bf, 0x035d, 0x16fc, 0x1174, 0x1675, 0x0249, 0xd2d4,
-0xd851, 0x184d, 0x32fe, 0x0f91, 0xee14, 0xe1e6, 0xdf9b, 0x016b, 0x3668, 0x2b2b,
-0xe20c, 0xc554, 0xf257, 0x1c05, 0x1fc5, 0x14f0, 0xf891, 0xd41c, 0xdf83, 0x1865,
-0x2de1, 0x0b16, 0xed58, 0xea0c, 0xea79, 0xfbd9, 0x22af, 0x2732, 0xf62f, 0xd389,
-0xe7d9, 0x0b39, 0x1cdc, 0x1de3, 0x038a, 0xd809, 0xd5f7, 0x0b55, 0x305e, 0x1910,
-0xf02e, 0xe089, 0xe7c7, 0x0195, 0x2265, 0x21da, 0xf743, 0xd8f2, 0xe978, 0x09a1,
-0x190a, 0x17c5, 0x045a, 0xe46d, 0xdd06, 0xffb2, 0x2293, 0x1cfe, 0xfd4d, 0xe4f9,
-0xe310, 0xfaf1, 0x1d22, 0x2376, 0x0113, 0xde3a, 0xe21b, 0x0204, 0x1ba1, 0x1bd6,
-0x0333, 0xe563, 0xe104, 0xfd51, 0x1bc1, 0x1ccf, 0x0285, 0xe757, 0xe35e, 0xfaf2,
-0x185d, 0x1d46, 0x06b7, 0xec13, 0xe108, 0xef6e, 0x121d, 0x2a17, 0x16a6, 0xe32c,
-0xc9a9, 0xf070, 0x2f48, 0x3788, 0xfa4e, 0xc32a, 0xd9c2, 0x1fa1, 0x36fe, 0x07fa,
-0xd9e4, 0xe577, 0x0e5e, 0x1755, 0xfb53, 0xed71, 0x0540, 0x19e0, 0x0301, 0xdc97,
-0xe391, 0x1937, 0x367c, 0x0bc9, 0xca4c, 0xc96b, 0x105d, 0x461f, 0x2416, 0xd481,
-0xbc97, 0xf8b7, 0x39af, 0x2ec9, 0xecc6, 0xcb50, 0xeee3, 0x1ffe, 0x1e8e, 0xf700,
-0xe66a, 0xff58, 0x149f, 0x02e5, 0xe792, 0xf2d8, 0x1a4d, 0x225a, 0xf642, 0xce7f,
-0xe6a6, 0x25e2, 0x38f5, 0x01d0, 0xc50f, 0xd243, 0x19bd, 0x3fc6, 0x14f0, 0xd2d7,
-0xcdb6, 0x069a, 0x2ffe, 0x1847, 0xe6f8, 0xdf0a, 0x0337, 0x1a90, 0x067a, 0xeb5b,
-0xf541, 0x143b, 0x14f2, 0xf092, 0xdc02, 0xfb91, 0x28a3, 0x2274, 0xeaa8, 0xc9e7,
-0xef48, 0x2d01, 0x322e, 0xf6d2, 0xc7cb, 0xe13b, 0x1fda, 0x3217, 0x0458, 0xd690,
-0xe2bf, 0x11c4, 0x21d5, 0x0291, 0xe5c8, 0xf3a9, 0x12ba, 0x11aa, 0xf22b, 0xe627,
-0x03ec, 0x219a, 0x1036, 0xe2f2, 0xd93f, 0x059c, 0x2ed6, 0x1b75, 0xe227, 0xce55,
-0xfb19, 0x2de0, 0x2477, 0xed08, 0xd148, 0xf307, 0x21d4, 0x2002, 0xf543, 0xdeac,
-0xf7f9, 0x18a9, 0x11d6, 0xf0ef, 0xe8e4, 0x05ea, 0x1ba5, 0x0727, 0xe448, 0xe748,
-0x100e, 0x265e, 0x07fc, 0xdbae, 0xde78, 0x0efa, 0x2ce0, 0x0f94, 0xddf1, 0xd9ea,
-0x0797, 0x28f6, 0x12eb, 0xe60c, 0xdf46, 0x0469, 0x1fbb, 0x0ced, 0xe9f6, 0xe95f,
-0x09fe, 0x1ab9, 0x02cb, 0xe5a4, 0xef2a, 0x1327, 0x1d7b, 0xfd07, 0xde3d, 0xed9c,
-0x17e5, 0x22e7, 0xfe3a, 0xdb38, 0xe9b9, 0x161a, 0x2416, 0x0175, 0xde3d, 0xe9de,
-0x1294, 0x1fc9, 0x00ea, 0xe2a7, 0xeee2, 0x1298, 0x1a7d, 0xfc1d, 0xe3bb, 0xf47a,
-0x1642, 0x185e, 0xf727, 0xe1af, 0xf709, 0x19c3, 0x18e7, 0xf50d, 0xe010, 0xf75b,
-0x1a9c, 0x18d8, 0xf4c5, 0xe0c9, 0xf865, 0x1a1c, 0x16d5, 0xf3a6, 0xe257, 0xfaf2,
-0x1a44, 0x14d5, 0xf34f, 0xe4b6, 0xfc77, 0x17d5, 0x0ff8, 0xf133, 0xe8b7, 0x0344,
-0x1a37, 0x0ad5, 0xe95e, 0xe61a, 0x08a5, 0x227e, 0x0e33, 0xe4a7, 0xdd70, 0x03b0,
-0x25f4, 0x17b2, 0xec0a, 0xdb4e, 0xf898, 0x1ba3, 0x18f6, 0xf973, 0xe87f, 0xf77a,
-0x0b93, 0x096c, 0xfb0e, 0xfb03, 0x0896, 0x0940, 0xf51d, 0xe904, 0xfdc7, 0x1dda,
-0x1bf9, 0xf29b, 0xd37f, 0xea1b, 0x1f37, 0x3175, 0x07eb, 0xd3f7, 0xd46b, 0x077d,
-0x2eeb, 0x1e67, 0xeeae, 0xd8c7, 0xef85, 0x1119, 0x18d3, 0x088e, 0xf953, 0xf5ad,
-0xf556, 0xf63d, 0x0234, 0x167a, 0x19a1, 0xfbf9, 0xd873, 0xdd4b, 0x0f06, 0x3748,
-0x21e6, 0xe181, 0xc032, 0xe79a, 0x2bec, 0x3e76, 0x0b1b, 0xce41, 0xcb23, 0xff96,
-0x2d79, 0x26d1, 0xfcc7, 0xdf8a, 0xe525, 0xfd83, 0x10f1, 0x16d7, 0x0f50, 0xfaea,
-0xe3f1, 0xe20f, 0x0158, 0x27d9, 0x2866, 0xf96f, 0xcb34, 0xd563, 0x11d6, 0x3d25,
-0x2424, 0xe254, 0xc2c9, 0xe7cd, 0x248d, 0x34f5, 0x0c42, 0xdcd0, 0xd827, 0xfa65,
-0x19eb, 0x1b50, 0x0721, 0xf396, 0xeb9c, 0xefde, 0x0016, 0x1594, 0x1cc1, 0x0658,
-0xe22b, 0xd852, 0xfb3e, 0x2923, 0x2c78, 0xfc87, 0xcdb5, 0xd69c, 0x0e3c, 0x3527,
-0x201f, 0xe993, 0xcf9e, 0xeb21, 0x183f, 0x25ea, 0x0c93, 0xed4d, 0xe5f9, 0xf548,
-0x07fb, 0x117c, 0x0ff2, 0x0398, 0xf08c, 0xe628, 0xf489, 0x143b, 0x2419, 0x0ccf,
-0xe2cc, 0xd5a6, 0xf861, 0x2615, 0x2a1b, 0xfeb4, 0xd543, 0xdc53, 0x09b4, 0x2901,
-0x19ff, 0xf24a, 0xde86, 0xeec4, 0x0b7b, 0x1733, 0x0d0a, 0xfc24, 0xf1bb, 0xf110,
-0xfa03, 0x0a0f, 0x15d4, 0x0e21, 0xf435, 0xe17e, 0xee90, 0x1225, 0x2527, 0x0efa,
-0xe61f, 0xd916, 0xf7b8, 0x1f50, 0x2326, 0x0099, 0xe01e, 0xe473, 0x0491, 0x1b37,
-0x1360, 0xfb17, 0xecd9, 0xf20d, 0x0051, 0x0aec, 0x0d4a, 0x073d, 0xfa5a, 0xeeb8,
-0xf165, 0x0516, 0x17dc, 0x12da, 0xf71b, 0xe213, 0xed85, 0x0eef, 0x20c8, 0x0e09,
-0xebcc, 0xe0d4, 0xf848, 0x1637, 0x19d6, 0x026b, 0xec09, 0xed00, 0xff9b, 0x0e5a,
-0x0d6b, 0x026c, 0xf865, 0xf4da, 0xf888, 0x025a, 0x0cbb, 0x0d53, 0xff96, 0xeefa,
-0xee80, 0x021c, 0x15d6, 0x126a, 0xf9c1, 0xe724, 0xf017, 0x0aa1, 0x18b6, 0x0b4e,
-0xf2d7, 0xea91, 0xf957, 0x0cac, 0x1061, 0x03f4, 0xf6ad, 0xf476, 0xfbdf, 0x0489,
-0x08b1, 0x06df, 0xffcf, 0xf766, 0xf537, 0xfddf, 0x0ad4, 0x0e15, 0x01da, 0xf205,
-0xf0a0, 0x0082, 0x1066, 0x0e41, 0xfc71, 0xef1b, 0xf4ad, 0x05cd, 0x0f32, 0x07ed,
-0xf9c8, 0xf401, 0xfa93, 0x04af, 0x088c, 0x04a7, 0xfe15, 0xf9f1, 0xfa64, 0xff1e,
-0x0539, 0x078c, 0x02af, 0xfa1a, 0xf69d, 0xfd09, 0x075b, 0x0a3d, 0x01f2, 0xf761,
-0xf642, 0xffa7, 0x08f3, 0x0830, 0xff05, 0xf7db, 0xf9bc, 0x0174, 0x068b, 0x04b2,
-0xfeff, 0xfb39, 0xfc1a, 000000, 0x0371, 0x03d7, 0x00fe, 0xfd37, 0xfbe0, 0xfe78,
-0x02af, 0x044a, 0x0180, 0xfd43, 0xfc00, 0xfed1, 0x02aa, 0x0346, 0x00dd, 0xfde0,
-0xfbfe, 0x0114, 0x0987, 0x04bc, 0xf49d, 0xf23a, 0x06ab, 0x162e, 0x0544, 0xe76b,
-0xea25, 0x1015, 0x2474, 0x0431, 0xd7d3, 0xe1ec, 0x1923, 0x2df5, 0x01cd, 0xd386,
-0xe3d9, 0x1b9d, 0x2c62, 0xfeb8, 0xd31a, 0xe6ba, 0x1dbd, 0x2abb, 0xfbab, 0xd2ed,
-0xe9ab, 0x1fa7, 0x28ef, 0xf8b3, 0xd2f5, 0xeca5, 0x2160, 0x26fd, 0xf5d7, 0xd334,
-0xefa1, 0x22e5, 0x24ea, 0xf31b, 0xd3a9, 0xf29f, 0x2435, 0x22b6, 0xf07e, 0xd44e,
-0xf59b, 0x2551, 0x2067, 0xee08, 0xd527, 0xf88e, 0x2639, 0x1e00, 0xebb6, 0xd62d,
-0xfb77, 0x26eb, 0x1b85, 0xe98b, 0xd75f, 0xfe51, 0x276b, 0x18f9, 0xe78e, 0xd8b9,
-0x011a, 0x27b6, 0x1660, 0xe5bb, 0xda3a, 0x03cc, 0x27cf, 0x13bd, 0xe415, 0xdbdf,
-0x066a, 0x27b7, 0x1117, 0xe29e, 0xdda5, 0x08ec, 0x276e, 0x0e6d, 0xe154, 0xdf89,
-0x0b52, 0x26f6, 0x0bc7, 0xe039, 0xe185, 0x0d96, 0x2653, 0x0924, 0xdf4e, 0xe399,
-0x0fb9, 0x2584, 0x068b, 0xde93, 0xe5c0, 0x11b8, 0x248e, 0x03fd, 0xde08, 0xe7f8,
-0x1390, 0x2372, 0x0180, 0xddaa, 0xea3c, 0x1544, 0x2231, 0xff12, 0xdd7a, 0xec89,
-0x16cf, 0x20d0, 0xfcb9, 0xdd77, 0xeedb, 0x1831, 0x1f52, 0xfa77, 0xdd9f, 0xf132,
-0x1969, 0x1db7, 0xf850, 0xddf1, 0xf385, 0x1a75, 0x1c06, 0xf645, 0xde6b, 0xf5d7,
-0x1b5b, 0x1a3f, 0xf457, 0xdf0d, 0xf820, 0x1c13, 0x1867, 0xf288, 0xdfd2, 0xfa5f,
-0x1ca1, 0x167f, 0xf0db, 0xe0ba, 0xfc92, 0x1d06, 0x148b, 0xef50, 0xe1c1, 0xfeb5,
-0x1d43, 0x1290, 0xede9, 0xe2e6, 0x00c6, 0x1d58, 0x108e, 0xeca7, 0xe426, 0x02c4,
-0x1d45, 0x0e8a, 0xeb8a, 0xe57f, 0x04a9, 0x1d0e, 0x0c87, 0xea92, 0xe6ec, 0x0677,
-0x1cb2, 0x0a87, 0xe9be, 0xe86e, 0x082a, 0x1c34, 0x088b, 0xe912, 0xe9fe, 0x09c1,
-0x1b95, 0x069c, 0xe88c, 0xeb9c, 0x0b3a, 0x1ad9, 0x04b6, 0xe82a, 0xed43, 0x0c96,
-0x1a00, 0x02df, 0xe7eb, 0xeef3, 0x0dd0, 0x190d, 0x0116, 0xe7d0, 0xf0a8, 0x0eec,
-0x1804, 0xff61, 0xe7d8, 0xf25d, 0x0fe6, 0x16e3, 0xfdc0, 0xe800, 0xf412, 0x10bf,
-0x15b1, 0xfc36, 0xe848, 0xf5c5, 0x1176, 0x146e, 0xfac2, 0xe8ad, 0xf771, 0x120d,
-0x1320, 0xf969, 0xe92e, 0xf913, 0x1282, 0x11c4, 0xf828, 0xe9cb, 0xfaac, 0x12d8,
-0x1062, 0xf703, 0xea7e, 0xfc38, 0x130e, 0x0efa, 0xf5fb, 0xeb49, 0xfdb5, 0x1325,
-0x0d8e, 0xf50e, 0xec26, 0xff20, 0x131e, 0x0c21, 0xf43f, 0xed15, 0x007a, 0x12fa,
-0x0ab6, 0xf38d, 0xee15, 0x01be, 0x12bd, 0x094f, 0xf2f9, 0xef22, 0x02ef, 0x1265,
-0x07f0, 0xf283, 0xf037, 0x0408, 0x11f6, 0x0699, 0xf226, 0xf156, 0x050a, 0x1170,
-0x054b, 0xf1e8, 0xf27a, 0x05f4, 0x10d8, 0x040c, 0xf1c5, 0xf3a3, 0x06c2, 0x102c,
-0x02da, 0xf1bc, 0xf4cc, 0x0779, 0x0f71, 0x01b7, 0xf1cc, 0xf5f5, 0x0815, 0x0ea7,
-0x00a8, 0xf1f4, 0xf719, 0x0899, 0x0dd2, 0xffab, 0xf233, 0xf839, 0x0902, 0x0cf4,
-0xfec0, 0xf288, 0xf950, 0x0952, 0x0c0e, 0xfdec, 0xf2ee, 0xfa5d, 0x0989, 0x0b23,
-0xfd2d, 0xf368, 0xfb62, 0x09a7, 0x0a35, 0xfc85, 0xf3f1, 0xfc58, 0x09af, 0x0946,
-0xfbf2, 0xf488, 0xfd3f, 0x09a1, 0x0859, 0xfb77, 0xf52c, 0xfe17, 0x097d, 0x076f,
-0xfb14, 0xf5d8, 0xfede, 0x0945, 0x068a, 0xfac6, 0xf68d, 0xff93, 0x08fb, 0x05ad,
-0xfa8e, 0xf747, 0x0034, 0x08a1, 0x04da, 0xfa6f, 0xf805, 0x00c2, 0x0836, 0x0410,
-0xfa63, 0xf8c6, 0x013c, 0x07bf, 0x0354, 0xfa6c, 0xf985, 0x01a1, 0x073b, 0x02a4,
-0xfa8a, 0xfa43, 0x01f1, 0x06af, 0x0204, 0xfab9, 0xfafc, 0x022c, 0x0619, 0x0175,
-0xfafa, 0xfbae, 0x0252, 0x057f, 0x00f6, 0xfb4b, 0xfc5a, 0x0263, 0x04e0, 0x008b,
-0xfbaa, 0xfcfa, 0x0262, 0x0440, 0x0032, 0xfc16, 0xfd90, 0x024b, 0x03a0, 0xffec,
-0xfc8c, 0xfe19, 0x0225, 0x0301, 0xffb9, 0xfd0c, 0xfe93, 0x01ea, 0x0267, 0xff9c,
-0xfd95, 0xfefe, 0x01a0, 0x01d3, 0xff90, 0xfe22, 0xff5a, 0x0147, 0x0145, 0xff99,
-0xfeb3, 0xffa1, 0x00e0, 0x00c3, 0xffb6, 0xff46, 0xffd9, 0x006d, 0x004b, 0xffe5,
-0xffda, 0xfffc, 000000, 0xfffe, 000000, 0xffff, 000000, 0xffff, 0xffff, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000 };
diff --git a/1.2-netsec/channels/chan_agent.c b/1.2-netsec/channels/chan_agent.c
deleted file mode 100644
index 0193d8cdd..000000000
--- a/1.2-netsec/channels/chan_agent.c
+++ /dev/null
@@ -1,2507 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-
-/*! \file
- * \brief Implementation of Agents (proxy channel)
- *
- * This file is the implementation of Agents modules.
- * It is a dynamic module that is loaded by Asterisk.
- * \par See also
- * \arg \ref Config_agent
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/signal.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp.h"
-#include "asterisk/acl.h"
-#include "asterisk/callerid.h"
-#include "asterisk/file.h"
-#include "asterisk/cli.h"
-#include "asterisk/app.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/manager.h"
-#include "asterisk/features.h"
-#include "asterisk/utils.h"
-#include "asterisk/causes.h"
-#include "asterisk/astdb.h"
-#include "asterisk/devicestate.h"
-#include "asterisk/monitor.h"
-
-static const char desc[] = "Agent Proxy Channel";
-static const char channeltype[] = "Agent";
-static const char tdesc[] = "Call Agent Proxy Channel";
-static const char config[] = "agents.conf";
-
-static const char app[] = "AgentLogin";
-static const char app2[] = "AgentCallbackLogin";
-static const char app3[] = "AgentMonitorOutgoing";
-
-static const char synopsis[] = "Call agent login";
-static const char synopsis2[] = "Call agent callback login";
-static const char synopsis3[] = "Record agent's outgoing call";
-
-static const char descrip[] =
-" AgentLogin([AgentNo][|options]):\n"
-"Asks the agent to login to the system. Always returns -1. While\n"
-"logged in, the agent can receive calls and will hear a 'beep'\n"
-"when a new call comes in. The agent can dump the call by pressing\n"
-"the star key.\n"
-"The option string may contain zero or more of the following characters:\n"
-" 's' -- silent login - do not announce the login ok segment after agent logged in/off\n";
-
-static const char descrip2[] =
-" AgentCallbackLogin([AgentNo][|[options][|[exten]@context]]):\n"
-"Asks the agent to login to the system with callback.\n"
-"The agent's callback extension is called (optionally with the specified\n"
-"context).\n"
-"The option string may contain zero or more of the following characters:\n"
-" 's' -- silent login - do not announce the login ok segment agent logged in/off\n";
-
-static const char descrip3[] =
-" AgentMonitorOutgoing([options]):\n"
-"Tries to figure out the id of the agent who is placing outgoing call based on\n"
-"comparison of the callerid of the current interface and the global variable \n"
-"placed by the AgentCallbackLogin application. That's why it should be used only\n"
-"with the AgentCallbackLogin app. Uses the monitoring functions in chan_agent \n"
-"instead of Monitor application. That have to be configured in the agents.conf file.\n"
-"\nReturn value:\n"
-"Normally the app returns 0 unless the options are passed. Also if the callerid or\n"
-"the agentid are not specified it'll look for n+101 priority.\n"
-"\nOptions:\n"
-" 'd' - make the app return -1 if there is an error condition and there is\n"
-" no extension n+101\n"
-" 'c' - change the CDR so that the source of the call is 'Agent/agent_id'\n"
-" 'n' - don't generate the warnings when there is no callerid or the\n"
-" agentid is not known.\n"
-" It's handy if you want to have one context for agent and non-agent calls.\n";
-
-static const char mandescr_agents[] =
-"Description: Will list info about all possible agents.\n"
-"Variables: NONE\n";
-
-static const char mandescr_agent_logoff[] =
-"Description: Sets an agent as no longer logged in.\n"
-"Variables: (Names marked with * are required)\n"
-" *Agent: Agent ID of the agent to log off\n"
-" Soft: Set to 'true' to not hangup existing calls\n";
-
-static const char mandescr_agent_callback_login[] =
-"Description: Sets an agent as logged in with callback.\n"
-"Variables: (Names marked with * are required)\n"
-" *Agent: Agent ID of the agent to login\n"
-" *Exten: Extension to use for callback\n"
-" Context: Context to use for callback\n"
-" AckCall: Set to 'true' to require an acknowledgement by '#' when agent is called back\n"
-" WrapupTime: the minimum amount of time after disconnecting before the caller can receive a new call\n";
-
-static char moh[80] = "default";
-
-#define AST_MAX_AGENT 80 /**< Agent ID or Password max length */
-#define AST_MAX_BUF 256
-#define AST_MAX_FILENAME_LEN 256
-
-/** Persistent Agents astdb family */
-static const char pa_family[] = "/Agents";
-/** The maximum length of each persistent member agent database entry */
-#define PA_MAX_LEN 2048
-/** queues.conf [general] option */
-static int persistent_agents = 0;
-static void dump_agents(void);
-
-static ast_group_t group;
-static int autologoff;
-static int wrapuptime;
-static int ackcall;
-
-static int maxlogintries = 3;
-static char agentgoodbye[AST_MAX_FILENAME_LEN] = "vm-goodbye";
-
-static int usecnt =0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-/* Protect the interface list (of pvt's) */
-AST_MUTEX_DEFINE_STATIC(agentlock);
-
-static int recordagentcalls = 0;
-static char recordformat[AST_MAX_BUF] = "";
-static char recordformatext[AST_MAX_BUF] = "";
-static int createlink = 0;
-static char urlprefix[AST_MAX_BUF] = "";
-static char savecallsin[AST_MAX_BUF] = "";
-static int updatecdr = 0;
-static char beep[AST_MAX_BUF] = "beep";
-
-#define GETAGENTBYCALLERID "AGENTBYCALLERID"
-
-/**
- * Structure representing an agent.
- */
-struct agent_pvt {
- ast_mutex_t lock; /**< Channel private lock */
- int dead; /**< Poised for destruction? */
- int pending; /**< Not a real agent -- just pending a match */
- int abouttograb; /**< About to grab */
- int autologoff; /**< Auto timeout time */
- int ackcall; /**< ackcall */
- time_t loginstart; /**< When agent first logged in (0 when logged off) */
- time_t start; /**< When call started */
- struct timeval lastdisc; /**< When last disconnected */
- int wrapuptime; /**< Wrapup time in ms */
- ast_group_t group; /**< Group memberships */
- int acknowledged; /**< Acknowledged */
- char moh[80]; /**< Which music on hold */
- char agent[AST_MAX_AGENT]; /**< Agent ID */
- char password[AST_MAX_AGENT]; /**< Password for Agent login */
- char name[AST_MAX_AGENT];
- ast_mutex_t app_lock; /**< Synchronization between owning applications */
- volatile pthread_t owning_app; /**< Owning application thread id */
- volatile int app_sleep_cond; /**< Sleep condition for the login app */
- struct ast_channel *owner; /**< Agent */
- char loginchan[80]; /**< channel they logged in from */
- char logincallerid[80]; /**< Caller ID they had when they logged in */
- struct ast_channel *chan; /**< Channel we use */
- struct agent_pvt *next; /**< Next Agent in the linked list. */
-};
-
-static struct agent_pvt *agents = NULL; /**< Holds the list of agents (loaded form agents.conf). */
-
-#define CHECK_FORMATS(ast, p) do { \
- if (p->chan) {\
- if (ast->nativeformats != p->chan->nativeformats) { \
- ast_log(LOG_DEBUG, "Native formats changing from %d to %d\n", ast->nativeformats, p->chan->nativeformats); \
- /* Native formats changed, reset things */ \
- ast->nativeformats = p->chan->nativeformats; \
- ast_log(LOG_DEBUG, "Resetting read to %d and write to %d\n", ast->readformat, ast->writeformat);\
- ast_set_read_format(ast, ast->readformat); \
- ast_set_write_format(ast, ast->writeformat); \
- } \
- if (p->chan->readformat != ast->rawreadformat) \
- ast_set_read_format(p->chan, ast->rawreadformat); \
- if (p->chan->writeformat != ast->rawwriteformat) \
- ast_set_write_format(p->chan, ast->rawwriteformat); \
- } \
-} while(0)
-
-/* Cleanup moves all the relevant FD's from the 2nd to the first, but retains things
- properly for a timingfd XXX This might need more work if agents were logged in as agents or other
- totally impractical combinations XXX */
-
-#define CLEANUP(ast, p) do { \
- int x; \
- if (p->chan) { \
- for (x=0;x<AST_MAX_FDS;x++) {\
- if (x != AST_MAX_FDS - 2) \
- ast->fds[x] = p->chan->fds[x]; \
- } \
- ast->fds[AST_MAX_FDS - 3] = p->chan->fds[AST_MAX_FDS - 2]; \
- } \
-} while(0)
-
-static struct ast_channel *agent_request(const char *type, int format, void *data, int *cause);
-static int agent_devicestate(void *data);
-static int agent_digit(struct ast_channel *ast, char digit);
-static int agent_call(struct ast_channel *ast, char *dest, int timeout);
-static int agent_hangup(struct ast_channel *ast);
-static int agent_answer(struct ast_channel *ast);
-static struct ast_frame *agent_read(struct ast_channel *ast);
-static int agent_write(struct ast_channel *ast, struct ast_frame *f);
-static int agent_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
-static int agent_sendtext(struct ast_channel *ast, const char *text);
-static int agent_indicate(struct ast_channel *ast, int condition);
-static int agent_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-static struct ast_channel *agent_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge);
-
-static const struct ast_channel_tech agent_tech = {
- .type = channeltype,
- .description = tdesc,
- .capabilities = -1,
- .requester = agent_request,
- .devicestate = agent_devicestate,
- .send_digit = agent_digit,
- .call = agent_call,
- .hangup = agent_hangup,
- .answer = agent_answer,
- .read = agent_read,
- .write = agent_write,
- .send_html = agent_sendhtml,
- .send_text = agent_sendtext,
- .exception = agent_read,
- .indicate = agent_indicate,
- .fixup = agent_fixup,
- .bridged_channel = agent_bridgedchannel,
-};
-
-/**
- * Unlink (that is, take outside of the linked list) an agent.
- *
- * @param agent Agent to be unlinked.
- */
-static void agent_unlink(struct agent_pvt *agent)
-{
- struct agent_pvt *p, *prev;
- prev = NULL;
- p = agents;
- // Iterate over all agents looking for the one.
- while(p) {
- if (p == agent) {
- // Once it wal found, check if it is the first one.
- if (prev)
- // If it is not, tell the previous agent that the next one is the next one of the current (jumping the current).
- prev->next = agent->next;
- else
- // If it is the first one, just change the general pointer to point to the second one.
- agents = agent->next;
- // We are done.
- break;
- }
- prev = p;
- p = p->next;
- }
-}
-
-/**
- * Adds an agent to the global list of agents.
- *
- * @param agent A string with the username, password and real name of an agent. As defined in agents.conf. Example: "13,169,John Smith"
- * @param pending If it is pending or not.
- * @return The just created agent.
- * @sa agent_pvt, agents.
- */
-static struct agent_pvt *add_agent(char *agent, int pending)
-{
- int argc;
- char *argv[3];
- char *args;
- char *password = NULL;
- char *name = NULL;
- char *agt = NULL;
- struct agent_pvt *p, *prev;
-
- args = ast_strdupa(agent);
-
- // Extract username (agt), password and name from agent (args).
- if ((argc = ast_app_separate_args(args, ',', argv, sizeof(argv) / sizeof(argv[0])))) {
- agt = argv[0];
- if (argc > 1) {
- password = argv[1];
- while (*password && *password < 33) password++;
- }
- if (argc > 2) {
- name = argv[2];
- while (*name && *name < 33) name++;
- }
- } else {
- ast_log(LOG_WARNING, "A blank agent line!\n");
- }
-
- // Are we searching for the agent here ? to see if it exists already ?
- prev=NULL;
- p = agents;
- while(p) {
- if (!pending && !strcmp(p->agent, agt))
- break;
- prev = p;
- p = p->next;
- }
- if (!p) {
- // Build the agent.
- p = malloc(sizeof(struct agent_pvt));
- if (p) {
- memset(p, 0, sizeof(struct agent_pvt));
- ast_copy_string(p->agent, agt, sizeof(p->agent));
- ast_mutex_init(&p->lock);
- ast_mutex_init(&p->app_lock);
- p->owning_app = (pthread_t) -1;
- p->app_sleep_cond = 1;
- p->group = group;
- p->pending = pending;
- p->next = NULL;
- if (prev)
- prev->next = p;
- else
- agents = p;
-
- } else {
- return NULL;
- }
- }
-
- ast_copy_string(p->password, password ? password : "", sizeof(p->password));
- ast_copy_string(p->name, name ? name : "", sizeof(p->name));
- ast_copy_string(p->moh, moh, sizeof(p->moh));
- p->ackcall = ackcall;
- p->autologoff = autologoff;
-
- /* If someone reduces the wrapuptime and reloads, we want it
- * to change the wrapuptime immediately on all calls */
- if (p->wrapuptime > wrapuptime) {
- struct timeval now = ast_tvnow();
- /* XXX check what is this exactly */
-
- /* We won't be pedantic and check the tv_usec val */
- if (p->lastdisc.tv_sec > (now.tv_sec + wrapuptime/1000)) {
- p->lastdisc.tv_sec = now.tv_sec + wrapuptime/1000;
- p->lastdisc.tv_usec = now.tv_usec;
- }
- }
- p->wrapuptime = wrapuptime;
-
- if (pending)
- p->dead = 1;
- else
- p->dead = 0;
- return p;
-}
-
-/**
- * Deletes an agent after doing some clean up.
- * Further documentation: How safe is this function ? What state should the agent be to be cleaned.
- * @param p Agent to be deleted.
- * @returns Always 0.
- */
-static int agent_cleanup(struct agent_pvt *p)
-{
- struct ast_channel *chan = p->owner;
- p->owner = NULL;
- chan->tech_pvt = NULL;
- p->app_sleep_cond = 1;
- /* Release ownership of the agent to other threads (presumably running the login app). */
- ast_mutex_unlock(&p->app_lock);
- if (chan)
- ast_channel_free(chan);
- if (p->dead) {
- ast_mutex_destroy(&p->lock);
- ast_mutex_destroy(&p->app_lock);
- free(p);
- }
- return 0;
-}
-
-static int check_availability(struct agent_pvt *newlyavailable, int needlock);
-
-static int agent_answer(struct ast_channel *ast)
-{
- ast_log(LOG_WARNING, "Huh? Agent is being asked to answer?\n");
- return -1;
-}
-
-static int __agent_start_monitoring(struct ast_channel *ast, struct agent_pvt *p, int needlock)
-{
- char tmp[AST_MAX_BUF],tmp2[AST_MAX_BUF], *pointer;
- char filename[AST_MAX_BUF];
- int res = -1;
- if (!p)
- return -1;
- if (!ast->monitor) {
- snprintf(filename, sizeof(filename), "agent-%s-%s",p->agent, ast->uniqueid);
- /* substitute . for - */
- if ((pointer = strchr(filename, '.')))
- *pointer = '-';
- snprintf(tmp, sizeof(tmp), "%s%s",savecallsin ? savecallsin : "", filename);
- ast_monitor_start(ast, recordformat, tmp, needlock);
- ast_monitor_setjoinfiles(ast, 1);
- snprintf(tmp2, sizeof(tmp2), "%s%s.%s", urlprefix ? urlprefix : "", filename, recordformatext);
-#if 0
- ast_verbose("name is %s, link is %s\n",tmp, tmp2);
-#endif
- if (!ast->cdr)
- ast->cdr = ast_cdr_alloc();
- ast_cdr_setuserfield(ast, tmp2);
- res = 0;
- } else
- ast_log(LOG_ERROR, "Recording already started on that call.\n");
- return res;
-}
-
-static int agent_start_monitoring(struct ast_channel *ast, int needlock)
-{
- return __agent_start_monitoring(ast, ast->tech_pvt, needlock);
-}
-
-static struct ast_frame *agent_read(struct ast_channel *ast)
-{
- struct agent_pvt *p = ast->tech_pvt;
- struct ast_frame *f = NULL;
- static struct ast_frame null_frame = { AST_FRAME_NULL, };
- static struct ast_frame answer_frame = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
- ast_mutex_lock(&p->lock);
- CHECK_FORMATS(ast, p);
- if (p->chan) {
- ast_copy_flags(p->chan, ast, AST_FLAG_EXCEPTION);
- if (ast->fdno == AST_MAX_FDS - 3)
- p->chan->fdno = AST_MAX_FDS - 2;
- else
- p->chan->fdno = ast->fdno;
- f = ast_read(p->chan);
- } else
- f = &null_frame;
- if (!f) {
- /* If there's a channel, hang it up (if it's on a callback) make it NULL */
- if (p->chan) {
- p->chan->_bridge = NULL;
- /* Note that we don't hangup if it's not a callback because Asterisk will do it
- for us when the PBX instance that called login finishes */
- if (!ast_strlen_zero(p->loginchan)) {
- if (p->chan)
- ast_log(LOG_DEBUG, "Bridge on '%s' being cleared (2)\n", p->chan->name);
- ast_hangup(p->chan);
- if (p->wrapuptime && p->acknowledged)
- p->lastdisc = ast_tvadd(ast_tvnow(), ast_samp2tv(p->wrapuptime, 1000));
- }
- p->chan = NULL;
- p->acknowledged = 0;
- }
- } else {
- /* if acknowledgement is not required, and the channel is up, we may have missed
- an AST_CONTROL_ANSWER (if there was one), so mark the call acknowledged anyway */
- if (!p->ackcall && !p->acknowledged && p->chan && (p->chan->_state == AST_STATE_UP))
- p->acknowledged = 1;
- switch (f->frametype) {
- case AST_FRAME_CONTROL:
- if (f->subclass == AST_CONTROL_ANSWER) {
- if (p->ackcall) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "%s answered, waiting for '#' to acknowledge\n", p->chan->name);
- /* Don't pass answer along */
- ast_frfree(f);
- f = &null_frame;
- } else {
- p->acknowledged = 1;
- /* Use the builtin answer frame for the
- recording start check below. */
- ast_frfree(f);
- f = &answer_frame;
- }
- }
- break;
- case AST_FRAME_DTMF:
- if (!p->acknowledged && (f->subclass == '#')) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "%s acknowledged\n", p->chan->name);
- p->acknowledged = 1;
- ast_frfree(f);
- f = &answer_frame;
- } else if (f->subclass == '*') {
- /* terminates call */
- ast_frfree(f);
- f = NULL;
- }
- break;
- case AST_FRAME_VOICE:
- /* don't pass voice until the call is acknowledged */
- if (!p->acknowledged) {
- ast_frfree(f);
- f = &null_frame;
- }
- break;
- }
- }
-
- CLEANUP(ast,p);
- if (p->chan && !p->chan->_bridge) {
- if (strcasecmp(p->chan->type, "Local")) {
- p->chan->_bridge = ast;
- if (p->chan)
- ast_log(LOG_DEBUG, "Bridge on '%s' being set to '%s' (3)\n", p->chan->name, p->chan->_bridge->name);
- }
- }
- ast_mutex_unlock(&p->lock);
- if (recordagentcalls && f == &answer_frame)
- agent_start_monitoring(ast,0);
- return f;
-}
-
-static int agent_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
-{
- struct agent_pvt *p = ast->tech_pvt;
- int res = -1;
- ast_mutex_lock(&p->lock);
- if (p->chan)
- res = ast_channel_sendhtml(p->chan, subclass, data, datalen);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int agent_sendtext(struct ast_channel *ast, const char *text)
-{
- struct agent_pvt *p = ast->tech_pvt;
- int res = -1;
- ast_mutex_lock(&p->lock);
- if (p->chan)
- res = ast_sendtext(p->chan, text);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int agent_write(struct ast_channel *ast, struct ast_frame *f)
-{
- struct agent_pvt *p = ast->tech_pvt;
- int res = -1;
- CHECK_FORMATS(ast, p);
- ast_mutex_lock(&p->lock);
- if (p->chan) {
- if ((f->frametype != AST_FRAME_VOICE) ||
- (f->subclass == p->chan->writeformat)) {
- res = ast_write(p->chan, f);
- } else {
- ast_log(LOG_DEBUG, "Dropping one incompatible voice frame on '%s' to '%s'\n", ast->name, p->chan->name);
- res = 0;
- }
- } else
- res = 0;
- CLEANUP(ast, p);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int agent_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct agent_pvt *p = newchan->tech_pvt;
- ast_mutex_lock(&p->lock);
- if (p->owner != oldchan) {
- ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner);
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- p->owner = newchan;
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-static int agent_indicate(struct ast_channel *ast, int condition)
-{
- struct agent_pvt *p = ast->tech_pvt;
- int res = -1;
- ast_mutex_lock(&p->lock);
- if (p->chan)
- res = ast_indicate(p->chan, condition);
- else
- res = 0;
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int agent_digit(struct ast_channel *ast, char digit)
-{
- struct agent_pvt *p = ast->tech_pvt;
- int res = -1;
- ast_mutex_lock(&p->lock);
- if (p->chan)
- res = p->chan->tech->send_digit(p->chan, digit);
- else
- res = 0;
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int agent_call(struct ast_channel *ast, char *dest, int timeout)
-{
- struct agent_pvt *p = ast->tech_pvt;
- int res = -1;
- int newstate=0;
- ast_mutex_lock(&p->lock);
- p->acknowledged = 0;
- if (!p->chan) {
- if (p->pending) {
- ast_log(LOG_DEBUG, "Pretending to dial on pending agent\n");
- newstate = AST_STATE_DIALING;
- res = 0;
- } else {
- ast_log(LOG_NOTICE, "Whoa, they hung up between alloc and call... what are the odds of that?\n");
- res = -1;
- }
- ast_mutex_unlock(&p->lock);
- if (newstate)
- ast_setstate(ast, newstate);
- return res;
- } else if (!ast_strlen_zero(p->loginchan)) {
- time(&p->start);
- /* Call on this agent */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "outgoing agentcall, to agent '%s', on '%s'\n", p->agent, p->chan->name);
- if (p->chan->cid.cid_num)
- free(p->chan->cid.cid_num);
- if (ast->cid.cid_num)
- p->chan->cid.cid_num = strdup(ast->cid.cid_num);
- else
- p->chan->cid.cid_num = NULL;
- if (p->chan->cid.cid_name)
- free(p->chan->cid.cid_name);
- if (ast->cid.cid_name)
- p->chan->cid.cid_name = strdup(ast->cid.cid_name);
- else
- p->chan->cid.cid_name = NULL;
- ast_channel_inherit_variables(ast, p->chan);
- res = ast_call(p->chan, p->loginchan, 0);
- CLEANUP(ast,p);
- ast_mutex_unlock(&p->lock);
- return res;
- }
- ast_verbose( VERBOSE_PREFIX_3 "agent_call, call to agent '%s' call on '%s'\n", p->agent, p->chan->name);
- ast_log( LOG_DEBUG, "Playing beep, lang '%s'\n", p->chan->language);
- res = ast_streamfile(p->chan, beep, p->chan->language);
- ast_log( LOG_DEBUG, "Played beep, result '%d'\n", res);
- if (!res) {
- res = ast_waitstream(p->chan, "");
- ast_log( LOG_DEBUG, "Waited for stream, result '%d'\n", res);
- }
- if (!res) {
- res = ast_set_read_format(p->chan, ast_best_codec(p->chan->nativeformats));
- ast_log( LOG_DEBUG, "Set read format, result '%d'\n", res);
- if (res)
- ast_log(LOG_WARNING, "Unable to set read format to %s\n", ast_getformatname(ast_best_codec(p->chan->nativeformats)));
- } else {
- /* Agent hung-up */
- p->chan = NULL;
- }
-
- if (!res) {
- ast_set_write_format(p->chan, ast_best_codec(p->chan->nativeformats));
- ast_log( LOG_DEBUG, "Set write format, result '%d'\n", res);
- if (res)
- ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_getformatname(ast_best_codec(p->chan->nativeformats)));
- }
- if( !res )
- {
- /* Call is immediately up, or might need ack */
- if (p->ackcall > 1)
- newstate = AST_STATE_RINGING;
- else {
- newstate = AST_STATE_UP;
- if (recordagentcalls)
- agent_start_monitoring(ast,0);
- p->acknowledged = 1;
- }
- res = 0;
- }
- CLEANUP(ast,p);
- ast_mutex_unlock(&p->lock);
- if (newstate)
- ast_setstate(ast, newstate);
- return res;
-}
-
-/* store/clear the global variable that stores agentid based on the callerid */
-static void set_agentbycallerid(const char *callerid, const char *agent)
-{
- char buf[AST_MAX_BUF];
-
- /* if there is no Caller ID, nothing to do */
- if (ast_strlen_zero(callerid))
- return;
-
- snprintf(buf, sizeof(buf), "%s_%s",GETAGENTBYCALLERID, callerid);
- pbx_builtin_setvar_helper(NULL, buf, agent);
-}
-
-static int agent_hangup(struct ast_channel *ast)
-{
- struct agent_pvt *p = ast->tech_pvt;
- int howlong = 0;
- ast_mutex_lock(&p->lock);
- p->owner = NULL;
- ast->tech_pvt = NULL;
- p->app_sleep_cond = 1;
- p->acknowledged = 0;
-
- /* if they really are hung up then set start to 0 so the test
- * later if we're called on an already downed channel
- * doesn't cause an agent to be logged out like when
- * agent_request() is followed immediately by agent_hangup()
- * as in apps/app_chanisavail.c:chanavail_exec()
- */
-
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
-
- ast_log(LOG_DEBUG, "Hangup called for state %s\n", ast_state2str(ast->_state));
- if (p->start && (ast->_state != AST_STATE_UP)) {
- howlong = time(NULL) - p->start;
- p->start = 0;
- } else if (ast->_state == AST_STATE_RESERVED) {
- howlong = 0;
- } else
- p->start = 0;
- if (p->chan) {
- p->chan->_bridge = NULL;
- /* If they're dead, go ahead and hang up on the agent now */
- if (!ast_strlen_zero(p->loginchan)) {
- /* Store last disconnect time */
- if (p->wrapuptime)
- p->lastdisc = ast_tvadd(ast_tvnow(), ast_samp2tv(p->wrapuptime, 1000));
- else
- p->lastdisc = ast_tv(0,0);
- if (p->chan) {
- /* Recognize the hangup and pass it along immediately */
- ast_hangup(p->chan);
- p->chan = NULL;
- }
- ast_log(LOG_DEBUG, "Hungup, howlong is %d, autologoff is %d\n", howlong, p->autologoff);
- if (howlong && p->autologoff && (howlong > p->autologoff)) {
- char agent[AST_MAX_AGENT] = "";
- long logintime = time(NULL) - p->loginstart;
- p->loginstart = 0;
- ast_log(LOG_NOTICE, "Agent '%s' didn't answer/confirm within %d seconds (waited %d)\n", p->name, p->autologoff, howlong);
- manager_event(EVENT_FLAG_AGENT, "Agentcallbacklogoff",
- "Agent: %s\r\n"
- "Loginchan: %s\r\n"
- "Logintime: %ld\r\n"
- "Reason: Autologoff\r\n"
- "Uniqueid: %s\r\n",
- p->agent, p->loginchan, logintime, ast->uniqueid);
- snprintf(agent, sizeof(agent), "Agent/%s", p->agent);
- ast_queue_log("NONE", ast->uniqueid, agent, "AGENTCALLBACKLOGOFF", "%s|%ld|%s", p->loginchan, logintime, "Autologoff");
- set_agentbycallerid(p->logincallerid, NULL);
- ast_device_state_changed("Agent/%s", p->agent);
- p->loginchan[0] = '\0';
- p->logincallerid[0] = '\0';
- if (persistent_agents)
- dump_agents();
- }
- } else if (p->dead) {
- ast_mutex_lock(&p->chan->lock);
- ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);
- ast_mutex_unlock(&p->chan->lock);
- } else {
- ast_mutex_lock(&p->chan->lock);
- ast_moh_start(p->chan, p->moh);
- ast_mutex_unlock(&p->chan->lock);
- }
- }
- ast_mutex_unlock(&p->lock);
- ast_device_state_changed("Agent/%s", p->agent);
-
- if (p->pending) {
- ast_mutex_lock(&agentlock);
- agent_unlink(p);
- ast_mutex_unlock(&agentlock);
- }
- if (p->abouttograb) {
- /* Let the "about to grab" thread know this isn't valid anymore, and let it
- kill it later */
- p->abouttograb = 0;
- } else if (p->dead) {
- ast_mutex_destroy(&p->lock);
- ast_mutex_destroy(&p->app_lock);
- free(p);
- } else {
- if (p->chan) {
- /* Not dead -- check availability now */
- ast_mutex_lock(&p->lock);
- /* Store last disconnect time */
- p->lastdisc = ast_tvnow();
- ast_mutex_unlock(&p->lock);
- }
- /* Release ownership of the agent to other threads (presumably running the login app). */
- ast_mutex_unlock(&p->app_lock);
- }
- return 0;
-}
-
-static int agent_cont_sleep( void *data )
-{
- struct agent_pvt *p;
- int res;
-
- p = (struct agent_pvt *)data;
-
- ast_mutex_lock(&p->lock);
- res = p->app_sleep_cond;
- if (p->lastdisc.tv_sec) {
- if (ast_tvdiff_ms(ast_tvnow(), p->lastdisc) > p->wrapuptime)
- res = 1;
- }
- ast_mutex_unlock(&p->lock);
-#if 0
- if( !res )
- ast_log( LOG_DEBUG, "agent_cont_sleep() returning %d\n", res );
-#endif
- return res;
-}
-
-static int agent_ack_sleep( void *data )
-{
- struct agent_pvt *p;
- int res=0;
- int to = 1000;
- struct ast_frame *f;
-
- /* Wait a second and look for something */
-
- p = (struct agent_pvt *)data;
- if (p->chan) {
- for(;;) {
- to = ast_waitfor(p->chan, to);
- if (to < 0) {
- res = -1;
- break;
- }
- if (!to) {
- res = 0;
- break;
- }
- f = ast_read(p->chan);
- if (!f) {
- res = -1;
- break;
- }
- if (f->frametype == AST_FRAME_DTMF)
- res = f->subclass;
- else
- res = 0;
- ast_frfree(f);
- ast_mutex_lock(&p->lock);
- if (!p->app_sleep_cond) {
- ast_mutex_unlock(&p->lock);
- res = 0;
- break;
- } else if (res == '#') {
- ast_mutex_unlock(&p->lock);
- res = 1;
- break;
- }
- ast_mutex_unlock(&p->lock);
- res = 0;
- }
- } else
- res = -1;
- return res;
-}
-
-static struct ast_channel *agent_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge)
-{
- struct agent_pvt *p = bridge->tech_pvt;
- struct ast_channel *ret=NULL;
-
- if (p) {
- if (chan == p->chan)
- ret = bridge->_bridge;
- else if (chan == bridge->_bridge)
- ret = p->chan;
- }
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Asked for bridged channel on '%s'/'%s', returning '%s'\n", chan->name, bridge->name, ret ? ret->name : "<none>");
- return ret;
-}
-
-/*--- agent_new: Create new agent channel ---*/
-static struct ast_channel *agent_new(struct agent_pvt *p, int state)
-{
- struct ast_channel *tmp;
- struct ast_frame null_frame = { AST_FRAME_NULL };
-#if 0
- if (!p->chan) {
- ast_log(LOG_WARNING, "No channel? :(\n");
- return NULL;
- }
-#endif
- tmp = ast_channel_alloc(0);
- if (tmp) {
- tmp->tech = &agent_tech;
- if (p->chan) {
- tmp->nativeformats = p->chan->nativeformats;
- tmp->writeformat = p->chan->writeformat;
- tmp->rawwriteformat = p->chan->writeformat;
- tmp->readformat = p->chan->readformat;
- tmp->rawreadformat = p->chan->readformat;
- ast_copy_string(tmp->language, p->chan->language, sizeof(tmp->language));
- ast_copy_string(tmp->context, p->chan->context, sizeof(tmp->context));
- ast_copy_string(tmp->exten, p->chan->exten, sizeof(tmp->exten));
- } else {
- tmp->nativeformats = AST_FORMAT_SLINEAR;
- tmp->writeformat = AST_FORMAT_SLINEAR;
- tmp->rawwriteformat = AST_FORMAT_SLINEAR;
- tmp->readformat = AST_FORMAT_SLINEAR;
- tmp->rawreadformat = AST_FORMAT_SLINEAR;
- }
- if (p->pending)
- snprintf(tmp->name, sizeof(tmp->name), "Agent/P%s-%d", p->agent, rand() & 0xffff);
- else
- snprintf(tmp->name, sizeof(tmp->name), "Agent/%s", p->agent);
- tmp->type = channeltype;
- /* Safe, agentlock already held */
- ast_setstate(tmp, state);
- tmp->tech_pvt = p;
- p->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- tmp->priority = 1;
- /* Wake up and wait for other applications (by definition the login app)
- * to release this channel). Takes ownership of the agent channel
- * to this thread only.
- * For signalling the other thread, ast_queue_frame is used until we
- * can safely use signals for this purpose. The pselect() needs to be
- * implemented in the kernel for this.
- */
- p->app_sleep_cond = 0;
- if( ast_mutex_trylock(&p->app_lock) )
- {
- if (p->chan) {
- ast_queue_frame(p->chan, &null_frame);
- ast_mutex_unlock(&p->lock); /* For other thread to read the condition. */
- ast_mutex_lock(&p->app_lock);
- ast_mutex_lock(&p->lock);
- }
- if( !p->chan )
- {
- ast_log(LOG_WARNING, "Agent disconnected while we were connecting the call\n");
- p->owner = NULL;
- tmp->tech_pvt = NULL;
- p->app_sleep_cond = 1;
- ast_channel_free( tmp );
- ast_mutex_unlock(&p->lock); /* For other thread to read the condition. */
- ast_mutex_unlock(&p->app_lock);
- return NULL;
- }
- }
- p->owning_app = pthread_self();
- /* After the above step, there should not be any blockers. */
- if (p->chan) {
- if (ast_test_flag(p->chan, AST_FLAG_BLOCKING)) {
- ast_log( LOG_ERROR, "A blocker exists after agent channel ownership acquired\n" );
- CRASH;
- }
- ast_moh_stop(p->chan);
- }
- } else
- ast_log(LOG_WARNING, "Unable to allocate agent channel structure\n");
- return tmp;
-}
-
-
-/**
- * Read configuration data. The file named agents.conf.
- *
- * @returns Always 0, or so it seems.
- */
-static int read_agent_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- struct agent_pvt *p, *pl, *pn;
- char *general_val;
-
- group = 0;
- autologoff = 0;
- wrapuptime = 0;
- ackcall = 0;
- cfg = ast_config_load(config);
- if (!cfg) {
- ast_log(LOG_NOTICE, "No agent configuration found -- agent support disabled\n");
- return 0;
- }
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- p->dead = 1;
- p = p->next;
- }
- strcpy(moh, "default");
- /* set the default recording values */
- recordagentcalls = 0;
- createlink = 0;
- strcpy(recordformat, "wav");
- strcpy(recordformatext, "wav");
- urlprefix[0] = '\0';
- savecallsin[0] = '\0';
-
- /* Read in [general] section for persistence */
- if ((general_val = ast_variable_retrieve(cfg, "general", "persistentagents")))
- persistent_agents = ast_true(general_val);
-
- /* Read in the [agents] section */
- v = ast_variable_browse(cfg, "agents");
- while(v) {
- /* Create the interface list */
- if (!strcasecmp(v->name, "agent")) {
- add_agent(v->value, 0);
- } else if (!strcasecmp(v->name, "group")) {
- group = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "autologoff")) {
- autologoff = atoi(v->value);
- if (autologoff < 0)
- autologoff = 0;
- } else if (!strcasecmp(v->name, "ackcall")) {
- if (!strcasecmp(v->value, "always"))
- ackcall = 2;
- else if (ast_true(v->value))
- ackcall = 1;
- else
- ackcall = 0;
- } else if (!strcasecmp(v->name, "wrapuptime")) {
- wrapuptime = atoi(v->value);
- if (wrapuptime < 0)
- wrapuptime = 0;
- } else if (!strcasecmp(v->name, "maxlogintries") && !ast_strlen_zero(v->value)) {
- maxlogintries = atoi(v->value);
- if (maxlogintries < 0)
- maxlogintries = 0;
- } else if (!strcasecmp(v->name, "goodbye") && !ast_strlen_zero(v->value)) {
- strcpy(agentgoodbye,v->value);
- } else if (!strcasecmp(v->name, "musiconhold")) {
- ast_copy_string(moh, v->value, sizeof(moh));
- } else if (!strcasecmp(v->name, "updatecdr")) {
- if (ast_true(v->value))
- updatecdr = 1;
- else
- updatecdr = 0;
- } else if (!strcasecmp(v->name, "recordagentcalls")) {
- recordagentcalls = ast_true(v->value);
- } else if (!strcasecmp(v->name, "createlink")) {
- createlink = ast_true(v->value);
- } else if (!strcasecmp(v->name, "recordformat")) {
- ast_copy_string(recordformat, v->value, sizeof(recordformat));
- if (!strcasecmp(v->value, "wav49"))
- strcpy(recordformatext, "WAV");
- else
- ast_copy_string(recordformatext, v->value, sizeof(recordformatext));
- } else if (!strcasecmp(v->name, "urlprefix")) {
- ast_copy_string(urlprefix, v->value, sizeof(urlprefix));
- if (urlprefix[strlen(urlprefix) - 1] != '/')
- strncat(urlprefix, "/", sizeof(urlprefix) - strlen(urlprefix) - 1);
- } else if (!strcasecmp(v->name, "savecallsin")) {
- if (v->value[0] == '/')
- ast_copy_string(savecallsin, v->value, sizeof(savecallsin));
- else
- snprintf(savecallsin, sizeof(savecallsin) - 2, "/%s", v->value);
- if (savecallsin[strlen(savecallsin) - 1] != '/')
- strncat(savecallsin, "/", sizeof(savecallsin) - strlen(savecallsin) - 1);
- } else if (!strcasecmp(v->name, "custom_beep")) {
- ast_copy_string(beep, v->value, sizeof(beep));
- }
- v = v->next;
- }
- p = agents;
- pl = NULL;
- while(p) {
- pn = p->next;
- if (p->dead) {
- /* Unlink */
- if (pl)
- pl->next = p->next;
- else
- agents = p->next;
- /* Destroy if appropriate */
- if (!p->owner) {
- if (!p->chan) {
- ast_mutex_destroy(&p->lock);
- ast_mutex_destroy(&p->app_lock);
- free(p);
- } else {
- /* Cause them to hang up */
- ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);
- }
- }
- } else
- pl = p;
- p = pn;
- }
- ast_mutex_unlock(&agentlock);
- ast_config_destroy(cfg);
- return 0;
-}
-
-static int check_availability(struct agent_pvt *newlyavailable, int needlock)
-{
- struct ast_channel *chan=NULL, *parent=NULL;
- struct agent_pvt *p;
- int res;
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Checking availability of '%s'\n", newlyavailable->agent);
- if (needlock)
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- if (p == newlyavailable) {
- p = p->next;
- continue;
- }
- ast_mutex_lock(&p->lock);
- if (!p->abouttograb && p->pending && ((p->group && (newlyavailable->group & p->group)) || !strcmp(p->agent, newlyavailable->agent))) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Call '%s' looks like a winner for agent '%s'\n", p->owner->name, newlyavailable->agent);
- /* We found a pending call, time to merge */
- chan = agent_new(newlyavailable, AST_STATE_DOWN);
- parent = p->owner;
- p->abouttograb = 1;
- ast_mutex_unlock(&p->lock);
- break;
- }
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- if (needlock)
- ast_mutex_unlock(&agentlock);
- if (parent && chan) {
- if (newlyavailable->ackcall > 1) {
- /* Don't do beep here */
- res = 0;
- } else {
- if (option_debug > 2)
- ast_log( LOG_DEBUG, "Playing beep, lang '%s'\n", newlyavailable->chan->language);
- res = ast_streamfile(newlyavailable->chan, beep, newlyavailable->chan->language);
- if (option_debug > 2)
- ast_log( LOG_DEBUG, "Played beep, result '%d'\n", res);
- if (!res) {
- res = ast_waitstream(newlyavailable->chan, "");
- ast_log( LOG_DEBUG, "Waited for stream, result '%d'\n", res);
- }
- }
- if (!res) {
- /* Note -- parent may have disappeared */
- if (p->abouttograb) {
- newlyavailable->acknowledged = 1;
- /* Safe -- agent lock already held */
- ast_setstate(parent, AST_STATE_UP);
- ast_setstate(chan, AST_STATE_UP);
- ast_copy_string(parent->context, chan->context, sizeof(parent->context));
- /* Go ahead and mark the channel as a zombie so that masquerade will
- destroy it for us, and we need not call ast_hangup */
- ast_mutex_lock(&parent->lock);
- ast_set_flag(chan, AST_FLAG_ZOMBIE);
- ast_channel_masquerade(parent, chan);
- ast_mutex_unlock(&parent->lock);
- p->abouttograb = 0;
- } else {
- if (option_debug)
- ast_log(LOG_DEBUG, "Sneaky, parent disappeared in the mean time...\n");
- agent_cleanup(newlyavailable);
- }
- } else {
- if (option_debug)
- ast_log(LOG_DEBUG, "Ugh... Agent hung up at exactly the wrong time\n");
- agent_cleanup(newlyavailable);
- }
- }
- return 0;
-}
-
-static int check_beep(struct agent_pvt *newlyavailable, int needlock)
-{
- struct agent_pvt *p;
- int res=0;
-
- ast_log(LOG_DEBUG, "Checking beep availability of '%s'\n", newlyavailable->agent);
- if (needlock)
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- if (p == newlyavailable) {
- p = p->next;
- continue;
- }
- ast_mutex_lock(&p->lock);
- if (!p->abouttograb && p->pending && ((p->group && (newlyavailable->group & p->group)) || !strcmp(p->agent, newlyavailable->agent))) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Call '%s' looks like a would-be winner for agent '%s'\n", p->owner->name, newlyavailable->agent);
- ast_mutex_unlock(&p->lock);
- break;
- }
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- if (needlock)
- ast_mutex_unlock(&agentlock);
- if (p) {
- ast_mutex_unlock(&newlyavailable->lock);
- if (option_debug > 2)
- ast_log( LOG_DEBUG, "Playing beep, lang '%s'\n", newlyavailable->chan->language);
- res = ast_streamfile(newlyavailable->chan, beep, newlyavailable->chan->language);
- if (option_debug > 2)
- ast_log( LOG_DEBUG, "Played beep, result '%d'\n", res);
- if (!res) {
- res = ast_waitstream(newlyavailable->chan, "");
- if (option_debug)
- ast_log( LOG_DEBUG, "Waited for stream, result '%d'\n", res);
- }
- ast_mutex_lock(&newlyavailable->lock);
- }
- return res;
-}
-
-/*--- agent_request: Part of the Asterisk PBX interface ---*/
-static struct ast_channel *agent_request(const char *type, int format, void *data, int *cause)
-{
- struct agent_pvt *p;
- struct ast_channel *chan = NULL;
- char *s;
- ast_group_t groupmatch;
- int groupoff;
- int waitforagent=0;
- int hasagent = 0;
- struct timeval tv;
-
- s = data;
- if ((s[0] == '@') && (sscanf(s + 1, "%d", &groupoff) == 1)) {
- groupmatch = (1 << groupoff);
- } else if ((s[0] == ':') && (sscanf(s + 1, "%d", &groupoff) == 1)) {
- groupmatch = (1 << groupoff);
- waitforagent = 1;
- } else {
- groupmatch = 0;
- }
-
- /* Check actual logged in agents first */
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- ast_mutex_lock(&p->lock);
- if (!p->pending && ((groupmatch && (p->group & groupmatch)) || !strcmp(data, p->agent)) &&
- ast_strlen_zero(p->loginchan)) {
- if (p->chan)
- hasagent++;
- if (!p->lastdisc.tv_sec) {
- /* Agent must be registered, but not have any active call, and not be in a waiting state */
- if (!p->owner && p->chan) {
- /* Fixed agent */
- chan = agent_new(p, AST_STATE_DOWN);
- }
- if (chan) {
- ast_mutex_unlock(&p->lock);
- break;
- }
- }
- }
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- if (!p) {
- p = agents;
- while(p) {
- ast_mutex_lock(&p->lock);
- if (!p->pending && ((groupmatch && (p->group & groupmatch)) || !strcmp(data, p->agent))) {
- if (p->chan || !ast_strlen_zero(p->loginchan))
- hasagent++;
- tv = ast_tvnow();
-#if 0
- ast_log(LOG_NOTICE, "Time now: %ld, Time of lastdisc: %ld\n", tv.tv_sec, p->lastdisc.tv_sec);
-#endif
- if (!p->lastdisc.tv_sec || (tv.tv_sec > p->lastdisc.tv_sec)) {
- p->lastdisc = ast_tv(0, 0);
- /* Agent must be registered, but not have any active call, and not be in a waiting state */
- if (!p->owner && p->chan) {
- /* Could still get a fixed agent */
- chan = agent_new(p, AST_STATE_DOWN);
- } else if (!p->owner && !ast_strlen_zero(p->loginchan)) {
- /* Adjustable agent */
- p->chan = ast_request("Local", format, p->loginchan, cause);
- if (p->chan)
- chan = agent_new(p, AST_STATE_DOWN);
- }
- if (chan) {
- ast_mutex_unlock(&p->lock);
- break;
- }
- }
- }
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- }
-
- if (!chan && waitforagent) {
- /* No agent available -- but we're requesting to wait for one.
- Allocate a place holder */
- if (hasagent) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Creating place holder for '%s'\n", s);
- p = add_agent(data, 1);
- p->group = groupmatch;
- chan = agent_new(p, AST_STATE_DOWN);
- if (!chan) {
- ast_log(LOG_WARNING, "Weird... Fix this to drop the unused pending agent\n");
- }
- } else
- ast_log(LOG_DEBUG, "Not creating place holder for '%s' since nobody logged in\n", s);
- }
- if (hasagent)
- *cause = AST_CAUSE_BUSY;
- else
- *cause = AST_CAUSE_UNREGISTERED;
- ast_mutex_unlock(&agentlock);
- return chan;
-}
-
-static int powerof(unsigned int v)
-{
- int x;
- for (x=0;x<32;x++) {
- if (v & (1 << x)) return x;
- }
- return 0;
-}
-
-/**
- * Lists agents and their status to the Manager API.
- * It is registered on load_module() and it gets called by the manager backend.
- * @param s
- * @param m
- * @returns
- * @sa action_agent_logoff(), action_agent_callback_login(), load_module().
- */
-static int action_agents(struct mansession *s, struct message *m)
-{
- char *id = astman_get_header(m,"ActionID");
- char idText[256] = "";
- char chanbuf[256];
- struct agent_pvt *p;
- char *username = NULL;
- char *loginChan = NULL;
- char *talkingtoChan = NULL;
- char *status = NULL;
-
- if (!ast_strlen_zero(id))
- snprintf(idText, sizeof(idText) ,"ActionID: %s\r\n", id);
- astman_send_ack(s, m, "Agents will follow");
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- ast_mutex_lock(&p->lock);
-
- /* Status Values:
- AGENT_LOGGEDOFF - Agent isn't logged in
- AGENT_IDLE - Agent is logged in, and waiting for call
- AGENT_ONCALL - Agent is logged in, and on a call
- AGENT_UNKNOWN - Don't know anything about agent. Shouldn't ever get this. */
-
- if(!ast_strlen_zero(p->name)) {
- username = p->name;
- } else {
- username = "None";
- }
-
- /* Set a default status. It 'should' get changed. */
- status = "AGENT_UNKNOWN";
-
- if (!ast_strlen_zero(p->loginchan) && !p->chan) {
- loginChan = p->loginchan;
- talkingtoChan = "n/a";
- status = "AGENT_IDLE";
- if (p->acknowledged) {
- snprintf(chanbuf, sizeof(chanbuf), " %s (Confirmed)", p->loginchan);
- loginChan = chanbuf;
- }
- } else if (p->chan) {
- loginChan = ast_strdupa(p->chan->name);
- if (p->owner && p->owner->_bridge) {
- talkingtoChan = p->chan->cid.cid_num;
- status = "AGENT_ONCALL";
- } else {
- talkingtoChan = "n/a";
- status = "AGENT_IDLE";
- }
- } else {
- loginChan = "n/a";
- talkingtoChan = "n/a";
- status = "AGENT_LOGGEDOFF";
- }
-
- ast_cli(s->fd, "Event: Agents\r\n"
- "Agent: %s\r\n"
- "Name: %s\r\n"
- "Status: %s\r\n"
- "LoggedInChan: %s\r\n"
- "LoggedInTime: %d\r\n"
- "TalkingTo: %s\r\n"
- "%s"
- "\r\n",
- p->agent, username, status, loginChan, (int)p->loginstart, talkingtoChan, idText);
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- ast_mutex_unlock(&agentlock);
- ast_cli(s->fd, "Event: AgentsComplete\r\n"
- "%s"
- "\r\n",idText);
- return 0;
-}
-
-static int agent_logoff(char *agent, int soft)
-{
- struct agent_pvt *p;
- long logintime;
- int ret = -1; /* Return -1 if no agent if found */
-
- for (p=agents; p; p=p->next) {
- if (!strcasecmp(p->agent, agent)) {
- if (!soft) {
- if (p->owner) {
- ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
- }
- if (p->chan) {
- ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);
- }
- }
- ret = 0; /* found an agent => return 0 */
- logintime = time(NULL) - p->loginstart;
- p->loginstart = 0;
-
- manager_event(EVENT_FLAG_AGENT, "Agentcallbacklogoff",
- "Agent: %s\r\n"
- "Loginchan: %s\r\n"
- "Logintime: %ld\r\n",
- p->agent, p->loginchan, logintime);
- ast_queue_log("NONE", "NONE", agent, "AGENTCALLBACKLOGOFF", "%s|%ld|%s", p->loginchan, logintime, "CommandLogoff");
- set_agentbycallerid(p->logincallerid, NULL);
- p->loginchan[0] = '\0';
- p->logincallerid[0] = '\0';
- ast_device_state_changed("Agent/%s", p->agent);
- if (persistent_agents)
- dump_agents();
- break;
- }
- }
-
- return ret;
-}
-
-static int agent_logoff_cmd(int fd, int argc, char **argv)
-{
- int ret;
- char *agent;
-
- if (argc < 3 || argc > 4)
- return RESULT_SHOWUSAGE;
- if (argc == 4 && strcasecmp(argv[3], "soft"))
- return RESULT_SHOWUSAGE;
-
- agent = argv[2] + 6;
- ret = agent_logoff(agent, argc == 4);
- if (ret == 0)
- ast_cli(fd, "Logging out %s\n", agent);
-
- return RESULT_SUCCESS;
-}
-
-/**
- * Sets an agent as no longer logged in in the Manager API.
- * It is registered on load_module() and it gets called by the manager backend.
- * @param s
- * @param m
- * @returns
- * @sa action_agents(), action_agent_callback_login(), load_module().
- */
-static int action_agent_logoff(struct mansession *s, struct message *m)
-{
- char *agent = astman_get_header(m, "Agent");
- char *soft_s = astman_get_header(m, "Soft"); /* "true" is don't hangup */
- int soft;
- int ret; /* return value of agent_logoff */
-
- if (ast_strlen_zero(agent)) {
- astman_send_error(s, m, "No agent specified");
- return 0;
- }
-
- if (ast_true(soft_s))
- soft = 1;
- else
- soft = 0;
-
- ret = agent_logoff(agent, soft);
- if (ret == 0)
- astman_send_ack(s, m, "Agent logged out");
- else
- astman_send_error(s, m, "No such agent");
-
- return 0;
-}
-
-static char *complete_agent_logoff_cmd(char *line, char *word, int pos, int state)
-{
- struct agent_pvt *p;
- char name[AST_MAX_AGENT];
- int which = 0;
-
- if (pos == 2) {
- for (p=agents; p; p=p->next) {
- snprintf(name, sizeof(name), "Agent/%s", p->agent);
- if (!strncasecmp(word, name, strlen(word))) {
- if (++which > state) {
- return strdup(name);
- }
- }
- }
- } else if (pos == 3 && state == 0) {
- return strdup("soft");
- }
- return NULL;
-}
-
-/**
- * Show agents in cli.
- */
-static int agents_show(int fd, int argc, char **argv)
-{
- struct agent_pvt *p;
- char username[AST_MAX_BUF];
- char location[AST_MAX_BUF] = "";
- char talkingto[AST_MAX_BUF] = "";
- char moh[AST_MAX_BUF];
- int count_agents = 0; /* Number of agents configured */
- int online_agents = 0; /* Number of online agents */
- int offline_agents = 0; /* Number of offline agents */
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- ast_mutex_lock(&p->lock);
- if (p->pending) {
- if (p->group)
- ast_cli(fd, "-- Pending call to group %d\n", powerof(p->group));
- else
- ast_cli(fd, "-- Pending call to agent %s\n", p->agent);
- } else {
- if (!ast_strlen_zero(p->name))
- snprintf(username, sizeof(username), "(%s) ", p->name);
- else
- username[0] = '\0';
- if (p->chan) {
- snprintf(location, sizeof(location), "logged in on %s", p->chan->name);
- if (p->owner && ast_bridged_channel(p->owner)) {
- snprintf(talkingto, sizeof(talkingto), " talking to %s", ast_bridged_channel(p->owner)->name);
- } else {
- strcpy(talkingto, " is idle");
- }
- online_agents++;
- } else if (!ast_strlen_zero(p->loginchan)) {
- snprintf(location, sizeof(location) - 20, "available at '%s'", p->loginchan);
- talkingto[0] = '\0';
- online_agents++;
- if (p->acknowledged)
- strncat(location, " (Confirmed)", sizeof(location) - strlen(location) - 1);
- } else {
- strcpy(location, "not logged in");
- talkingto[0] = '\0';
- offline_agents++;
- }
- if (!ast_strlen_zero(p->moh))
- snprintf(moh, sizeof(moh), " (musiconhold is '%s')", p->moh);
- ast_cli(fd, "%-12.12s %s%s%s%s\n", p->agent,
- username, location, talkingto, moh);
- count_agents++;
- }
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- ast_mutex_unlock(&agentlock);
- if ( !count_agents ) {
- ast_cli(fd, "No Agents are configured in %s\n",config);
- } else {
- ast_cli(fd, "%d agents configured [%d online , %d offline]\n",count_agents, online_agents, offline_agents);
- }
- ast_cli(fd, "\n");
-
- return RESULT_SUCCESS;
-}
-
-static char show_agents_usage[] =
-"Usage: show agents\n"
-" Provides summary information on agents.\n";
-
-static char agent_logoff_usage[] =
-"Usage: agent logoff <channel> [soft]\n"
-" Sets an agent as no longer logged in.\n"
-" If 'soft' is specified, do not hangup existing calls.\n";
-
-static struct ast_cli_entry cli_show_agents = {
- { "show", "agents", NULL }, agents_show,
- "Show status of agents", show_agents_usage, NULL };
-
-static struct ast_cli_entry cli_agent_logoff = {
- { "agent", "logoff", NULL }, agent_logoff_cmd,
- "Sets an agent offline", agent_logoff_usage, complete_agent_logoff_cmd };
-
-STANDARD_LOCAL_USER;
-LOCAL_USER_DECL;
-
-/*!
- * \brief Log in agent application.
- *
- * \param chan
- * \param data
- * \param callbackmode non-zero for AgentCallbackLogin
- */
-static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
-{
- int res=0;
- int tries = 0;
- int max_login_tries = maxlogintries;
- struct agent_pvt *p;
- struct localuser *u;
- int login_state = 0;
- char user[AST_MAX_AGENT] = "";
- char pass[AST_MAX_AGENT];
- char agent[AST_MAX_AGENT] = "";
- char xpass[AST_MAX_AGENT] = "";
- char *errmsg;
- char *parse;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(agent_id);
- AST_APP_ARG(options);
- AST_APP_ARG(extension);
- );
- char *tmpoptions = NULL;
- char *context = NULL;
- int play_announcement = 1;
- char agent_goodbye[AST_MAX_FILENAME_LEN];
- int update_cdr = updatecdr;
- char *filename = "agent-loginok";
- char tmpchan[AST_MAX_BUF] = "";
-
- LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
-
- ast_copy_string(agent_goodbye, agentgoodbye, sizeof(agent_goodbye));
-
- /* Set Channel Specific Login Overrides */
- if (pbx_builtin_getvar_helper(chan, "AGENTLMAXLOGINTRIES") && strlen(pbx_builtin_getvar_helper(chan, "AGENTLMAXLOGINTRIES"))) {
- max_login_tries = atoi(pbx_builtin_getvar_helper(chan, "AGENTMAXLOGINTRIES"));
- if (max_login_tries < 0)
- max_login_tries = 0;
- tmpoptions=pbx_builtin_getvar_helper(chan, "AGENTMAXLOGINTRIES");
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Saw variable AGENTMAXLOGINTRIES=%s, setting max_login_tries to: %d on Channel '%s'.\n",tmpoptions,max_login_tries,chan->name);
- }
- if (pbx_builtin_getvar_helper(chan, "AGENTUPDATECDR") && !ast_strlen_zero(pbx_builtin_getvar_helper(chan, "AGENTUPDATECDR"))) {
- if (ast_true(pbx_builtin_getvar_helper(chan, "AGENTUPDATECDR")))
- update_cdr = 1;
- else
- update_cdr = 0;
- tmpoptions=pbx_builtin_getvar_helper(chan, "AGENTUPDATECDR");
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Saw variable AGENTUPDATECDR=%s, setting update_cdr to: %d on Channel '%s'.\n",tmpoptions,update_cdr,chan->name);
- }
- if (pbx_builtin_getvar_helper(chan, "AGENTGOODBYE") && !ast_strlen_zero(pbx_builtin_getvar_helper(chan, "AGENTGOODBYE"))) {
- strcpy(agent_goodbye, pbx_builtin_getvar_helper(chan, "AGENTGOODBYE"));
- tmpoptions=pbx_builtin_getvar_helper(chan, "AGENTGOODBYE");
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Saw variable AGENTGOODBYE=%s, setting agent_goodbye to: %s on Channel '%s'.\n",tmpoptions,agent_goodbye,chan->name);
- }
- /* End Channel Specific Login Overrides */
-
- if (callbackmode && args.extension) {
- parse = args.extension;
- args.extension = strsep(&parse, "@");
- context = parse;
- }
-
- if (!ast_strlen_zero(args.options)) {
- if (strchr(args.options, 's')) {
- play_announcement = 0;
- }
- }
-
- if (chan->_state != AST_STATE_UP)
- res = ast_answer(chan);
- if (!res) {
- if (!ast_strlen_zero(args.agent_id))
- ast_copy_string(user, args.agent_id, AST_MAX_AGENT);
- else
- res = ast_app_getdata(chan, "agent-user", user, sizeof(user) - 1, 0);
- }
- while (!res && (max_login_tries==0 || tries < max_login_tries)) {
- tries++;
- /* Check for password */
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- if (!strcmp(p->agent, user) && !p->pending)
- ast_copy_string(xpass, p->password, sizeof(xpass));
- p = p->next;
- }
- ast_mutex_unlock(&agentlock);
- if (!res) {
- if (!ast_strlen_zero(xpass))
- res = ast_app_getdata(chan, "agent-pass", pass, sizeof(pass) - 1, 0);
- else
- pass[0] = '\0';
- }
- errmsg = "agent-incorrect";
-
-#if 0
- ast_log(LOG_NOTICE, "user: %s, pass: %s\n", user, pass);
-#endif
-
- /* Check again for accuracy */
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- ast_mutex_lock(&p->lock);
- if (!strcmp(p->agent, user) &&
- !strcmp(p->password, pass) && !p->pending) {
- login_state = 1; /* Successful Login */
-
- /* Ensure we can't be gotten until we're done */
- gettimeofday(&p->lastdisc, NULL);
- p->lastdisc.tv_sec++;
-
- /* Set Channel Specific Agent Overrides */
- if (pbx_builtin_getvar_helper(chan, "AGENTACKCALL") && strlen(pbx_builtin_getvar_helper(chan, "AGENTACKCALL"))) {
- if (!strcasecmp(pbx_builtin_getvar_helper(chan, "AGENTACKCALL"), "always"))
- p->ackcall = 2;
- else if (ast_true(pbx_builtin_getvar_helper(chan, "AGENTACKCALL")))
- p->ackcall = 1;
- else
- p->ackcall = 0;
- tmpoptions=pbx_builtin_getvar_helper(chan, "AGENTACKCALL");
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Saw variable AGENTACKCALL=%s, setting ackcall to: %d for Agent '%s'.\n",tmpoptions,p->ackcall,p->agent);
- }
- if (pbx_builtin_getvar_helper(chan, "AGENTAUTOLOGOFF") && strlen(pbx_builtin_getvar_helper(chan, "AGENTAUTOLOGOFF"))) {
- p->autologoff = atoi(pbx_builtin_getvar_helper(chan, "AGENTAUTOLOGOFF"));
- if (p->autologoff < 0)
- p->autologoff = 0;
- tmpoptions=pbx_builtin_getvar_helper(chan, "AGENTAUTOLOGOFF");
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Saw variable AGENTAUTOLOGOFF=%s, setting autologff to: %d for Agent '%s'.\n",tmpoptions,p->autologoff,p->agent);
- }
- if (pbx_builtin_getvar_helper(chan, "AGENTWRAPUPTIME") && strlen(pbx_builtin_getvar_helper(chan, "AGENTWRAPUPTIME"))) {
- p->wrapuptime = atoi(pbx_builtin_getvar_helper(chan, "AGENTWRAPUPTIME"));
- if (p->wrapuptime < 0)
- p->wrapuptime = 0;
- tmpoptions=pbx_builtin_getvar_helper(chan, "AGENTWRAPUPTIME");
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Saw variable AGENTWRAPUPTIME=%s, setting wrapuptime to: %d for Agent '%s'.\n",tmpoptions,p->wrapuptime,p->agent);
- }
- /* End Channel Specific Agent Overrides */
- if (!p->chan) {
- char last_loginchan[80] = "";
- long logintime;
- snprintf(agent, sizeof(agent), "Agent/%s", p->agent);
-
- if (callbackmode) {
- int pos = 0;
- /* Retrieve login chan */
- for (;;) {
- if (!ast_strlen_zero(args.extension)) {
- ast_copy_string(tmpchan, args.extension, sizeof(tmpchan));
- res = 0;
- } else
- res = ast_app_getdata(chan, "agent-newlocation", tmpchan+pos, sizeof(tmpchan) - 2, 0);
- if (ast_strlen_zero(tmpchan) || ast_exists_extension(chan, !ast_strlen_zero(context) ? context : "default", tmpchan,
- 1, NULL))
- break;
- if (args.extension) {
- ast_log(LOG_WARNING, "Extension '%s' is not valid for automatic login of agent '%s'\n", args.extension, p->agent);
- args.extension = NULL;
- pos = 0;
- } else {
- ast_log(LOG_WARNING, "Extension '%s@%s' is not valid for automatic login of agent '%s'\n", tmpchan, !ast_strlen_zero(context) ? context : "default", p->agent);
- res = ast_streamfile(chan, "invalid", chan->language);
- if (!res)
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- if (res > 0) {
- tmpchan[0] = res;
- tmpchan[1] = '\0';
- pos = 1;
- } else {
- tmpchan[0] = '\0';
- pos = 0;
- }
- }
- }
- args.extension = tmpchan;
- if (!res) {
- set_agentbycallerid(p->logincallerid, NULL);
- if (!ast_strlen_zero(context) && !ast_strlen_zero(tmpchan))
- snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context);
- else {
- ast_copy_string(last_loginchan, p->loginchan, sizeof(last_loginchan));
- ast_copy_string(p->loginchan, tmpchan, sizeof(p->loginchan));
- }
- p->acknowledged = 0;
- if (ast_strlen_zero(p->loginchan)) {
- login_state = 2;
- filename = "agent-loggedoff";
- } else {
- if (chan->cid.cid_num) {
- ast_copy_string(p->logincallerid, chan->cid.cid_num, sizeof(p->logincallerid));
- set_agentbycallerid(p->logincallerid, p->agent);
- } else
- p->logincallerid[0] = '\0';
- }
-
- if(update_cdr && chan->cdr)
- snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent);
-
- }
- } else {
- p->loginchan[0] = '\0';
- p->logincallerid[0] = '\0';
- p->acknowledged = 0;
- }
- ast_mutex_unlock(&p->lock);
- ast_mutex_unlock(&agentlock);
- if( !res && play_announcement==1 )
- res = ast_streamfile(chan, filename, chan->language);
- if (!res)
- ast_waitstream(chan, "");
- ast_mutex_lock(&agentlock);
- ast_mutex_lock(&p->lock);
- if (!res) {
- res = ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
- if (res)
- ast_log(LOG_WARNING, "Unable to set read format to %d\n", ast_best_codec(chan->nativeformats));
- }
- if (!res) {
- res = ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
- if (res)
- ast_log(LOG_WARNING, "Unable to set write format to %d\n", ast_best_codec(chan->nativeformats));
- }
- /* Check once more just in case */
- if (p->chan)
- res = -1;
- if (callbackmode && !res) {
- /* Just say goodbye and be done with it */
- if (!ast_strlen_zero(p->loginchan)) {
- if (p->loginstart == 0)
- time(&p->loginstart);
- manager_event(EVENT_FLAG_AGENT, "Agentcallbacklogin",
- "Agent: %s\r\n"
- "Loginchan: %s\r\n"
- "Uniqueid: %s\r\n",
- p->agent, p->loginchan, chan->uniqueid);
- ast_queue_log("NONE", chan->uniqueid, agent, "AGENTCALLBACKLOGIN", "%s", p->loginchan);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Callback Agent '%s' logged in on %s\n", p->agent, p->loginchan);
- ast_device_state_changed("Agent/%s", p->agent);
- } else {
- logintime = time(NULL) - p->loginstart;
- p->loginstart = 0;
- manager_event(EVENT_FLAG_AGENT, "Agentcallbacklogoff",
- "Agent: %s\r\n"
- "Loginchan: %s\r\n"
- "Logintime: %ld\r\n"
- "Uniqueid: %s\r\n",
- p->agent, last_loginchan, logintime, chan->uniqueid);
- ast_queue_log("NONE", chan->uniqueid, agent, "AGENTCALLBACKLOGOFF", "%s|%ld|", last_loginchan, logintime);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Callback Agent '%s' logged out\n", p->agent);
- ast_device_state_changed("Agent/%s", p->agent);
- }
- ast_mutex_unlock(&agentlock);
- if (!res)
- res = ast_safe_sleep(chan, 500);
- ast_mutex_unlock(&p->lock);
- if (persistent_agents)
- dump_agents();
- } else if (!res) {
-#ifdef HONOR_MUSIC_CLASS
- /* check if the moh class was changed with setmusiconhold */
- if (*(chan->musicclass))
- ast_copy_string(p->moh, chan->musicclass, sizeof(p->moh));
-#endif
- ast_moh_start(chan, p->moh);
- if (p->loginstart == 0)
- time(&p->loginstart);
- manager_event(EVENT_FLAG_AGENT, "Agentlogin",
- "Agent: %s\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n",
- p->agent, chan->name, chan->uniqueid);
- if (update_cdr && chan->cdr)
- snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent);
- ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGIN", "%s", chan->name);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Agent '%s' logged in (format %s/%s)\n", p->agent,
- ast_getformatname(chan->readformat), ast_getformatname(chan->writeformat));
- /* Login this channel and wait for it to
- go away */
- p->chan = chan;
- if (p->ackcall > 1)
- check_beep(p, 0);
- else
- check_availability(p, 0);
- ast_mutex_unlock(&p->lock);
- ast_mutex_unlock(&agentlock);
- ast_device_state_changed("Agent/%s", p->agent);
- while (res >= 0) {
- ast_mutex_lock(&p->lock);
- if (p->chan != chan)
- res = -1;
- ast_mutex_unlock(&p->lock);
- /* Yield here so other interested threads can kick in. */
- sched_yield();
- if (res)
- break;
-
- ast_mutex_lock(&agentlock);
- ast_mutex_lock(&p->lock);
- if (p->lastdisc.tv_sec) {
- if (ast_tvdiff_ms(ast_tvnow(), p->lastdisc) > p->wrapuptime) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Wrapup time for %s expired!\n", p->agent);
- p->lastdisc = ast_tv(0, 0);
- if (p->ackcall > 1)
- check_beep(p, 0);
- else
- check_availability(p, 0);
- }
- }
- ast_mutex_unlock(&p->lock);
- ast_mutex_unlock(&agentlock);
- /* Synchronize channel ownership between call to agent and itself. */
- ast_mutex_lock( &p->app_lock );
- ast_mutex_lock(&p->lock);
- p->owning_app = pthread_self();
- ast_mutex_unlock(&p->lock);
- if (p->ackcall > 1)
- res = agent_ack_sleep(p);
- else
- res = ast_safe_sleep_conditional( chan, 1000,
- agent_cont_sleep, p );
- ast_mutex_unlock( &p->app_lock );
- if ((p->ackcall > 1) && (res == 1)) {
- ast_mutex_lock(&agentlock);
- ast_mutex_lock(&p->lock);
- check_availability(p, 0);
- ast_mutex_unlock(&p->lock);
- ast_mutex_unlock(&agentlock);
- res = 0;
- }
- sched_yield();
- }
- ast_mutex_lock(&p->lock);
- if (res && p->owner)
- ast_log(LOG_WARNING, "Huh? We broke out when there was still an owner?\n");
- /* Log us off if appropriate */
- if (p->chan == chan)
- p->chan = NULL;
- p->acknowledged = 0;
- logintime = time(NULL) - p->loginstart;
- p->loginstart = 0;
- ast_mutex_unlock(&p->lock);
- manager_event(EVENT_FLAG_AGENT, "Agentlogoff",
- "Agent: %s\r\n"
- "Logintime: %ld\r\n"
- "Uniqueid: %s\r\n",
- p->agent, logintime, chan->uniqueid);
- ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGOFF", "%s|%ld", chan->name, logintime);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Agent '%s' logged out\n", p->agent);
- /* If there is no owner, go ahead and kill it now */
- ast_device_state_changed("Agent/%s", p->agent);
- if (p->dead && !p->owner) {
- ast_mutex_destroy(&p->lock);
- ast_mutex_destroy(&p->app_lock);
- free(p);
- }
- }
- else {
- ast_mutex_unlock(&p->lock);
- p = NULL;
- }
- res = -1;
- } else {
- ast_mutex_unlock(&p->lock);
- errmsg = "agent-alreadyon";
- p = NULL;
- }
- break;
- }
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- if (!p)
- ast_mutex_unlock(&agentlock);
-
- if (!res && (max_login_tries==0 || tries < max_login_tries))
- res = ast_app_getdata(chan, errmsg, user, sizeof(user) - 1, 0);
- }
-
- if (!res)
- res = ast_safe_sleep(chan, 500);
-
- /* AgentLogin() exit */
- if (!callbackmode) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- /* AgentCallbackLogin() exit*/
- else {
- /* Set variables */
- if (login_state > 0) {
- pbx_builtin_setvar_helper(chan, "AGENTNUMBER", user);
- if (login_state==1) {
- pbx_builtin_setvar_helper(chan, "AGENTSTATUS", "on");
- pbx_builtin_setvar_helper(chan, "AGENTEXTEN", args.extension);
- }
- else {
- pbx_builtin_setvar_helper(chan, "AGENTSTATUS", "off");
- }
- }
- else {
- pbx_builtin_setvar_helper(chan, "AGENTSTATUS", "fail");
- }
- if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1, chan->cid.cid_num)) {
- LOCAL_USER_REMOVE(u);
- return 0;
- }
- /* Do we need to play agent-goodbye now that we will be hanging up? */
- if (play_announcement) {
- if (!res)
- res = ast_safe_sleep(chan, 1000);
- res = ast_streamfile(chan, agent_goodbye, chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- if (!res)
- res = ast_safe_sleep(chan, 1000);
- }
- }
-
- LOCAL_USER_REMOVE(u);
-
- /* We should never get here if next priority exists when in callbackmode */
- return -1;
-}
-
-/**
- * Called by the AgentLogin application (from the dial plan).
- *
- * @param chan
- * @param data
- * @returns
- * @sa callback_login_exec(), agentmonitoroutgoing_exec(), load_module().
- */
-static int login_exec(struct ast_channel *chan, void *data)
-{
- return __login_exec(chan, data, 0);
-}
-
-/**
- * Called by the AgentCallbackLogin application (from the dial plan).
- *
- * @param chan
- * @param data
- * @returns
- * @sa login_exec(), agentmonitoroutgoing_exec(), load_module().
- */
-static int callback_exec(struct ast_channel *chan, void *data)
-{
- return __login_exec(chan, data, 1);
-}
-
-/**
- * Sets an agent as logged in by callback in the Manager API.
- * It is registered on load_module() and it gets called by the manager backend.
- * @param s
- * @param m
- * @returns
- * @sa action_agents(), action_agent_logoff(), load_module().
- */
-static int action_agent_callback_login(struct mansession *s, struct message *m)
-{
- char *agent = astman_get_header(m, "Agent");
- char *exten = astman_get_header(m, "Exten");
- char *context = astman_get_header(m, "Context");
- char *wrapuptime_s = astman_get_header(m, "WrapupTime");
- char *ackcall_s = astman_get_header(m, "AckCall");
- struct agent_pvt *p;
- int login_state = 0;
-
- if (ast_strlen_zero(agent)) {
- astman_send_error(s, m, "No agent specified");
- return 0;
- }
-
- if (ast_strlen_zero(exten)) {
- astman_send_error(s, m, "No extension specified");
- return 0;
- }
-
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- if (strcmp(p->agent, agent) || p->pending) {
- p = p->next;
- continue;
- }
- if (p->chan) {
- login_state = 2; /* already logged in (and on the phone)*/
- break;
- }
- ast_mutex_lock(&p->lock);
- login_state = 1; /* Successful Login */
-
- if (ast_strlen_zero(context))
- ast_copy_string(p->loginchan, exten, sizeof(p->loginchan));
- else
- snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", exten, context);
-
- if (!ast_strlen_zero(wrapuptime_s)) {
- p->wrapuptime = atoi(wrapuptime_s);
- if (p->wrapuptime < 0)
- p->wrapuptime = 0;
- }
-
- if (ast_true(ackcall_s))
- p->ackcall = 1;
- else
- p->ackcall = 0;
-
- if (p->loginstart == 0)
- time(&p->loginstart);
- manager_event(EVENT_FLAG_AGENT, "Agentcallbacklogin",
- "Agent: %s\r\n"
- "Loginchan: %s\r\n",
- p->agent, p->loginchan);
- ast_queue_log("NONE", "NONE", agent, "AGENTCALLBACKLOGIN", "%s", p->loginchan);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Callback Agent '%s' logged in on %s\n", p->agent, p->loginchan);
- ast_device_state_changed("Agent/%s", p->agent);
- ast_mutex_unlock(&p->lock);
- p = p->next;
- if (persistent_agents)
- dump_agents();
- }
- ast_mutex_unlock(&agentlock);
-
- if (login_state == 1)
- astman_send_ack(s, m, "Agent logged in");
- else if (login_state == 0)
- astman_send_error(s, m, "No such agent");
- else if (login_state == 2)
- astman_send_error(s, m, "Agent already logged in");
-
- return 0;
-}
-
-/**
- * Called by the AgentMonitorOutgoing application (from the dial plan).
- *
- * @param chan
- * @param data
- * @returns
- * @sa login_exec(), callback_login_exec(), load_module().
- */
-static int agentmonitoroutgoing_exec(struct ast_channel *chan, void *data)
-{
- int exitifnoagentid = 0;
- int nowarnings = 0;
- int changeoutgoing = 0;
- int res = 0;
- char agent[AST_MAX_AGENT], *tmp;
-
- if (data) {
- if (strchr(data, 'd'))
- exitifnoagentid = 1;
- if (strchr(data, 'n'))
- nowarnings = 1;
- if (strchr(data, 'c'))
- changeoutgoing = 1;
- }
- if (chan->cid.cid_num) {
- char agentvar[AST_MAX_BUF];
- snprintf(agentvar, sizeof(agentvar), "%s_%s", GETAGENTBYCALLERID, chan->cid.cid_num);
- if ((tmp = pbx_builtin_getvar_helper(NULL, agentvar))) {
- struct agent_pvt *p = agents;
- ast_copy_string(agent, tmp, sizeof(agent));
- ast_mutex_lock(&agentlock);
- while (p) {
- if (!strcasecmp(p->agent, tmp)) {
- if (changeoutgoing) snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent);
- __agent_start_monitoring(chan, p, 1);
- break;
- }
- p = p->next;
- }
- ast_mutex_unlock(&agentlock);
-
- } else {
- res = -1;
- if (!nowarnings)
- ast_log(LOG_WARNING, "Couldn't find the global variable %s, so I can't figure out which agent (if it's an agent) is placing outgoing call.\n", agentvar);
- }
- } else {
- res = -1;
- if (!nowarnings)
- ast_log(LOG_WARNING, "There is no callerid on that call, so I can't figure out which agent (if it's an agent) is placing outgoing call.\n");
- }
- /* check if there is n + 101 priority */
- if (res) {
- if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num)) {
- chan->priority+=100;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Going to %d priority because there is no callerid or the agentid cannot be found.\n",chan->priority);
- }
- else if (exitifnoagentid)
- return res;
- }
- return 0;
-}
-
-/**
- * Dump AgentCallbackLogin agents to the database for persistence
- */
-static void dump_agents(void)
-{
- struct agent_pvt *cur_agent = NULL;
- char buf[256];
-
- for (cur_agent = agents; cur_agent; cur_agent = cur_agent->next) {
- if (cur_agent->chan)
- continue;
-
- if (!ast_strlen_zero(cur_agent->loginchan)) {
- snprintf(buf, sizeof(buf), "%s;%s", cur_agent->loginchan, cur_agent->logincallerid);
- if (ast_db_put(pa_family, cur_agent->agent, buf))
- ast_log(LOG_WARNING, "failed to create persistent entry!\n");
- else if (option_debug)
- ast_log(LOG_DEBUG, "Saved Agent: %s on %s\n", cur_agent->agent, cur_agent->loginchan);
- } else {
- /* Delete - no agent or there is an error */
- ast_db_del(pa_family, cur_agent->agent);
- }
- }
-}
-
-/**
- * Reload the persistent agents from astdb.
- */
-static void reload_agents(void)
-{
- char *agent_num;
- struct ast_db_entry *db_tree;
- struct ast_db_entry *entry;
- struct agent_pvt *cur_agent;
- char agent_data[256];
- char *parse;
- char *agent_chan;
- char *agent_callerid;
-
- db_tree = ast_db_gettree(pa_family, NULL);
-
- ast_mutex_lock(&agentlock);
- for (entry = db_tree; entry; entry = entry->next) {
- agent_num = entry->key + strlen(pa_family) + 2;
- cur_agent = agents;
- while (cur_agent) {
- ast_mutex_lock(&cur_agent->lock);
- if (strcmp(agent_num, cur_agent->agent) == 0)
- break;
- ast_mutex_unlock(&cur_agent->lock);
- cur_agent = cur_agent->next;
- }
- if (!cur_agent) {
- ast_db_del(pa_family, agent_num);
- continue;
- } else
- ast_mutex_unlock(&cur_agent->lock);
- if (!ast_db_get(pa_family, agent_num, agent_data, sizeof(agent_data)-1)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Reload Agent: %s on %s\n", cur_agent->agent, agent_data);
- parse = agent_data;
- agent_chan = strsep(&parse, ";");
- agent_callerid = strsep(&parse, ";");
- ast_copy_string(cur_agent->loginchan, agent_chan, sizeof(cur_agent->loginchan));
- if (agent_callerid) {
- ast_copy_string(cur_agent->logincallerid, agent_callerid, sizeof(cur_agent->logincallerid));
- set_agentbycallerid(cur_agent->logincallerid, cur_agent->agent);
- } else
- cur_agent->logincallerid[0] = '\0';
- if (cur_agent->loginstart == 0)
- time(&cur_agent->loginstart);
- ast_device_state_changed("Agent/%s", cur_agent->agent);
- }
- }
- ast_mutex_unlock(&agentlock);
- if (db_tree) {
- ast_log(LOG_NOTICE, "Agents successfully reloaded from database.\n");
- ast_db_freetree(db_tree);
- }
-}
-
-/*--- agent_devicestate: Part of PBX channel interface ---*/
-static int agent_devicestate(void *data)
-{
- struct agent_pvt *p;
- char *s;
- ast_group_t groupmatch;
- int groupoff;
- int waitforagent=0;
- int res = AST_DEVICE_INVALID;
-
- s = data;
- if ((s[0] == '@') && (sscanf(s + 1, "%d", &groupoff) == 1)) {
- groupmatch = (1 << groupoff);
- } else if ((s[0] == ':') && (sscanf(s + 1, "%d", &groupoff) == 1)) {
- groupmatch = (1 << groupoff);
- waitforagent = 1;
- } else {
- groupmatch = 0;
- }
-
- /* Check actual logged in agents first */
- ast_mutex_lock(&agentlock);
- p = agents;
- while(p) {
- ast_mutex_lock(&p->lock);
- if (!p->pending && ((groupmatch && (p->group & groupmatch)) || !strcmp(data, p->agent))) {
- if (p->owner) {
- if (res != AST_DEVICE_INUSE)
- res = AST_DEVICE_BUSY;
- } else {
- if (res == AST_DEVICE_BUSY)
- res = AST_DEVICE_INUSE;
- if (p->chan || !ast_strlen_zero(p->loginchan)) {
- if (res == AST_DEVICE_INVALID)
- res = AST_DEVICE_UNKNOWN;
- } else if (res == AST_DEVICE_INVALID)
- res = AST_DEVICE_UNAVAILABLE;
- }
- if (!strcmp(data, p->agent)) {
- ast_mutex_unlock(&p->lock);
- break;
- }
- }
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- ast_mutex_unlock(&agentlock);
- return res;
-}
-
-/**
- * Initialize the Agents module.
- * This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
- *
- * @returns int Always 0.
- */
-int load_module()
-{
- /* Make sure we can register our agent channel type */
- if (ast_channel_register(&agent_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", channeltype);
- return -1;
- }
- /* Dialplan applications */
- ast_register_application(app, login_exec, synopsis, descrip);
- ast_register_application(app2, callback_exec, synopsis2, descrip2);
- ast_register_application(app3, agentmonitoroutgoing_exec, synopsis3, descrip3);
- /* Manager commands */
- ast_manager_register2("Agents", EVENT_FLAG_AGENT, action_agents, "Lists agents and their status", mandescr_agents);
- ast_manager_register2("AgentLogoff", EVENT_FLAG_AGENT, action_agent_logoff, "Sets an agent as no longer logged in", mandescr_agent_logoff);
- ast_manager_register2("AgentCallbackLogin", EVENT_FLAG_AGENT, action_agent_callback_login, "Sets an agent as logged in by callback", mandescr_agent_callback_login);
- /* CLI Application */
- ast_cli_register(&cli_show_agents);
- ast_cli_register(&cli_agent_logoff);
- /* Read in the config */
- read_agent_config();
- if (persistent_agents)
- reload_agents();
- return 0;
-}
-
-int reload()
-{
- read_agent_config();
- if (persistent_agents)
- reload_agents();
- return 0;
-}
-
-int unload_module()
-{
- struct agent_pvt *p;
- /* First, take us out of the channel loop */
- /* Unregister CLI application */
- ast_cli_unregister(&cli_show_agents);
- ast_cli_unregister(&cli_agent_logoff);
- /* Unregister dialplan applications */
- ast_unregister_application(app);
- ast_unregister_application(app2);
- ast_unregister_application(app3);
- /* Unregister manager command */
- ast_manager_unregister("Agents");
- ast_manager_unregister("AgentLogoff");
- ast_manager_unregister("AgentCallbackLogin");
- /* Unregister channel */
- ast_channel_unregister(&agent_tech);
- if (!ast_mutex_lock(&agentlock)) {
- /* Hangup all interfaces if they have an owner */
- p = agents;
- while(p) {
- if (p->owner)
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- p = p->next;
- }
- agents = NULL;
- ast_mutex_unlock(&agentlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
diff --git a/1.2-netsec/channels/chan_alsa.c b/1.2-netsec/channels/chan_alsa.c
deleted file mode 100644
index 6f0d36070..000000000
--- a/1.2-netsec/channels/chan_alsa.c
+++ /dev/null
@@ -1,1140 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * By Matthew Fredrickson <creslin@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief ALSA sound card channel driver
- *
- * \par See also
- * \arg Config_alsa
- *
- * \ingroup channel_drivers
- */
-
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define ALSA_PCM_NEW_HW_PARAMS_API
-#define ALSA_PCM_NEW_SW_PARAMS_API
-#include <alsa/asoundlib.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/pbx.h"
-#include "asterisk/config.h"
-#include "asterisk/cli.h"
-#include "asterisk/utils.h"
-#include "asterisk/causes.h"
-#include "asterisk/endian.h"
-
-#include "busy.h"
-#include "ringtone.h"
-#include "ring10.h"
-#include "answer.h"
-
-#ifdef ALSA_MONITOR
-#include "alsa-monitor.h"
-#endif
-
-#define DEBUG 0
-/* Which device to use */
-#define ALSA_INDEV "default"
-#define ALSA_OUTDEV "default"
-#define DESIRED_RATE 8000
-
-/* Lets use 160 sample frames, just like GSM. */
-#define FRAME_SIZE 160
-#define PERIOD_FRAMES 80 /* 80 Frames, at 2 bytes each */
-
-/* When you set the frame size, you have to come up with
- the right buffer format as well. */
-/* 5 64-byte frames = one frame */
-#define BUFFER_FMT ((buffersize * 10) << 16) | (0x0006);
-
-/* Don't switch between read/write modes faster than every 300 ms */
-#define MIN_SWITCH_TIME 600
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-static snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE;
-#else
-static snd_pcm_format_t format = SND_PCM_FORMAT_S16_BE;
-#endif
-
-/* static int block = O_NONBLOCK; */
-static char indevname[50] = ALSA_INDEV;
-static char outdevname[50] = ALSA_OUTDEV;
-
-#if 0
-static struct timeval lasttime;
-#endif
-
-static int usecnt;
-static int silencesuppression = 0;
-static int silencethreshold = 1000;
-
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-AST_MUTEX_DEFINE_STATIC(alsalock);
-
-static const char type[] = "Console";
-static const char desc[] = "ALSA Console Channel Driver";
-static const char tdesc[] = "ALSA Console Channel Driver";
-static const char config[] = "alsa.conf";
-
-static char context[AST_MAX_CONTEXT] = "default";
-static char language[MAX_LANGUAGE] = "";
-static char exten[AST_MAX_EXTENSION] = "s";
-
-static int hookstate=0;
-
-static short silence[FRAME_SIZE] = {0, };
-
-struct sound {
- int ind;
- short *data;
- int datalen;
- int samplen;
- int silencelen;
- int repeat;
-};
-
-static struct sound sounds[] = {
- { AST_CONTROL_RINGING, ringtone, sizeof(ringtone)/2, 16000, 32000, 1 },
- { AST_CONTROL_BUSY, busy, sizeof(busy)/2, 4000, 4000, 1 },
- { AST_CONTROL_CONGESTION, busy, sizeof(busy)/2, 2000, 2000, 1 },
- { AST_CONTROL_RING, ring10, sizeof(ring10)/2, 16000, 32000, 1 },
- { AST_CONTROL_ANSWER, answer, sizeof(answer)/2, 2200, 0, 0 },
-};
-
-/* Sound command pipe */
-static int sndcmd[2];
-
-static struct chan_alsa_pvt {
- /* We only have one ALSA structure -- near sighted perhaps, but it
- keeps this driver as simple as possible -- as it should be. */
- struct ast_channel *owner;
- char exten[AST_MAX_EXTENSION];
- char context[AST_MAX_CONTEXT];
-#if 0
- snd_pcm_t *card;
-#endif
- snd_pcm_t *icard, *ocard;
-
-} alsa;
-
-/* Number of buffers... Each is FRAMESIZE/8 ms long. For example
- with 160 sample frames, and a buffer size of 3, we have a 60ms buffer,
- usually plenty. */
-
-pthread_t sthread;
-
-#define MAX_BUFFER_SIZE 100
-
-/* File descriptors for sound device */
-static int readdev = -1;
-static int writedev = -1;
-
-static int autoanswer = 1;
-
-static int cursound = -1;
-static int sampsent = 0;
-static int silencelen=0;
-static int offset=0;
-static int nosound=0;
-
-/* ZZ */
-static struct ast_channel *alsa_request(const char *type, int format, void *data, int *cause);
-static int alsa_digit(struct ast_channel *c, char digit);
-static int alsa_text(struct ast_channel *c, const char *text);
-static int alsa_hangup(struct ast_channel *c);
-static int alsa_answer(struct ast_channel *c);
-static struct ast_frame *alsa_read(struct ast_channel *chan);
-static int alsa_call(struct ast_channel *c, char *dest, int timeout);
-static int alsa_write(struct ast_channel *chan, struct ast_frame *f);
-static int alsa_indicate(struct ast_channel *chan, int cond);
-static int alsa_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-
-static const struct ast_channel_tech alsa_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_SLINEAR,
- .requester = alsa_request,
- .send_digit = alsa_digit,
- .send_text = alsa_text,
- .hangup = alsa_hangup,
- .answer = alsa_answer,
- .read = alsa_read,
- .call = alsa_call,
- .write = alsa_write,
- .indicate = alsa_indicate,
- .fixup = alsa_fixup,
-};
-
-static int send_sound(void)
-{
- short myframe[FRAME_SIZE];
- int total = FRAME_SIZE;
- short *frame = NULL;
- int amt=0;
- int res;
- int myoff;
- snd_pcm_state_t state;
-
- if (cursound > -1) {
- res = total;
- if (sampsent < sounds[cursound].samplen) {
- myoff=0;
- while(total) {
- amt = total;
- if (amt > (sounds[cursound].datalen - offset))
- amt = sounds[cursound].datalen - offset;
- memcpy(myframe + myoff, sounds[cursound].data + offset, amt * 2);
- total -= amt;
- offset += amt;
- sampsent += amt;
- myoff += amt;
- if (offset >= sounds[cursound].datalen)
- offset = 0;
- }
- /* Set it up for silence */
- if (sampsent >= sounds[cursound].samplen)
- silencelen = sounds[cursound].silencelen;
- frame = myframe;
- } else {
- if (silencelen > 0) {
- frame = silence;
- silencelen -= res;
- } else {
- if (sounds[cursound].repeat) {
- /* Start over */
- sampsent = 0;
- offset = 0;
- } else {
- cursound = -1;
- nosound = 0;
- }
- return 0;
- }
- }
-
- if (res == 0 || !frame) {
- return 0;
- }
-#ifdef ALSA_MONITOR
- alsa_monitor_write((char *)frame, res * 2);
-#endif
- state = snd_pcm_state(alsa.ocard);
- if (state == SND_PCM_STATE_XRUN) {
- snd_pcm_prepare(alsa.ocard);
- }
- res = snd_pcm_writei(alsa.ocard, frame, res);
- if (res > 0)
- return 0;
- return 0;
- }
- return 0;
-}
-
-static void *sound_thread(void *unused)
-{
- fd_set rfds;
- fd_set wfds;
- int max;
- int res;
- for(;;) {
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- max = sndcmd[0];
- FD_SET(sndcmd[0], &rfds);
- if (cursound > -1) {
- FD_SET(writedev, &wfds);
- if (writedev > max)
- max = writedev;
- }
-#ifdef ALSA_MONITOR
- if (!alsa.owner) {
- FD_SET(readdev, &rfds);
- if (readdev > max)
- max = readdev;
- }
-#endif
- res = ast_select(max + 1, &rfds, &wfds, NULL, NULL);
- if (res < 1) {
- ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
- continue;
- }
-#ifdef ALSA_MONITOR
- if (FD_ISSET(readdev, &rfds)) {
- /* Keep the pipe going with read audio */
- snd_pcm_state_t state;
- short buf[FRAME_SIZE];
- int r;
-
- state = snd_pcm_state(alsa.ocard);
- if (state == SND_PCM_STATE_XRUN) {
- snd_pcm_prepare(alsa.ocard);
- }
- r = snd_pcm_readi(alsa.icard, buf, FRAME_SIZE);
- if (r == -EPIPE) {
-#if DEBUG
- ast_log(LOG_ERROR, "XRUN read\n");
-#endif
- snd_pcm_prepare(alsa.icard);
- } else if (r == -ESTRPIPE) {
- ast_log(LOG_ERROR, "-ESTRPIPE\n");
- snd_pcm_prepare(alsa.icard);
- } else if (r < 0) {
- ast_log(LOG_ERROR, "Read error: %s\n", snd_strerror(r));
- } else
- alsa_monitor_read((char *)buf, r * 2);
- }
-#endif
- if (FD_ISSET(sndcmd[0], &rfds)) {
- read(sndcmd[0], &cursound, sizeof(cursound));
- silencelen = 0;
- offset = 0;
- sampsent = 0;
- }
- if (FD_ISSET(writedev, &wfds))
- if (send_sound())
- ast_log(LOG_WARNING, "Failed to write sound\n");
- }
- /* Never reached */
- return NULL;
-}
-
-static snd_pcm_t *alsa_card_init(char *dev, snd_pcm_stream_t stream)
-{
- int err;
- int direction;
- snd_pcm_t *handle = NULL;
- snd_pcm_hw_params_t *hwparams = NULL;
- snd_pcm_sw_params_t *swparams = NULL;
- struct pollfd pfd;
- snd_pcm_uframes_t period_size = PERIOD_FRAMES * 4;
- /* int period_bytes = 0; */
- snd_pcm_uframes_t buffer_size = 0;
-
- unsigned int rate = DESIRED_RATE;
-#if 0
- unsigned int per_min = 1;
-#endif
- /* unsigned int per_max = 8; */
- snd_pcm_uframes_t start_threshold, stop_threshold;
-
- err = snd_pcm_open(&handle, dev, stream, O_NONBLOCK);
- if (err < 0) {
- ast_log(LOG_ERROR, "snd_pcm_open failed: %s\n", snd_strerror(err));
- return NULL;
- } else {
- ast_log(LOG_DEBUG, "Opening device %s in %s mode\n", dev, (stream == SND_PCM_STREAM_CAPTURE) ? "read" : "write");
- }
-
- snd_pcm_hw_params_alloca(&hwparams);
- snd_pcm_hw_params_any(handle, hwparams);
-
- err = snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED);
- if (err < 0) {
- ast_log(LOG_ERROR, "set_access failed: %s\n", snd_strerror(err));
- }
-
- err = snd_pcm_hw_params_set_format(handle, hwparams, format);
- if (err < 0) {
- ast_log(LOG_ERROR, "set_format failed: %s\n", snd_strerror(err));
- }
-
- err = snd_pcm_hw_params_set_channels(handle, hwparams, 1);
- if (err < 0) {
- ast_log(LOG_ERROR, "set_channels failed: %s\n", snd_strerror(err));
- }
-
- direction = 0;
- err = snd_pcm_hw_params_set_rate_near(handle, hwparams, &rate, &direction);
- if (rate != DESIRED_RATE) {
- ast_log(LOG_WARNING, "Rate not correct, requested %d, got %d\n", DESIRED_RATE, rate);
- }
-
- direction = 0;
- err = snd_pcm_hw_params_set_period_size_near(handle, hwparams, &period_size, &direction);
- if (err < 0) {
- ast_log(LOG_ERROR, "period_size(%ld frames) is bad: %s\n", period_size, snd_strerror(err));
- } else {
- ast_log(LOG_DEBUG, "Period size is %d\n", err);
- }
-
- buffer_size = 4096 * 2; /* period_size * 16; */
- err = snd_pcm_hw_params_set_buffer_size_near(handle, hwparams, &buffer_size);
- if (err < 0) {
- ast_log(LOG_WARNING, "Problem setting buffer size of %ld: %s\n", buffer_size, snd_strerror(err));
- } else {
- ast_log(LOG_DEBUG, "Buffer size is set to %d frames\n", err);
- }
-
-#if 0
- direction = 0;
- err = snd_pcm_hw_params_set_periods_min(handle, hwparams, &per_min, &direction);
- if (err < 0) {
- ast_log(LOG_ERROR, "periods_min: %s\n", snd_strerror(err));
- }
-
- err = snd_pcm_hw_params_set_periods_max(handle, hwparams, &per_max, 0);
- if (err < 0) {
- ast_log(LOG_ERROR, "periods_max: %s\n", snd_strerror(err));
- }
-#endif
-
- err = snd_pcm_hw_params(handle, hwparams);
- if (err < 0) {
- ast_log(LOG_ERROR, "Couldn't set the new hw params: %s\n", snd_strerror(err));
- }
-
- snd_pcm_sw_params_alloca(&swparams);
- snd_pcm_sw_params_current(handle, swparams);
-
-#if 1
- if (stream == SND_PCM_STREAM_PLAYBACK) {
- start_threshold = period_size;
- } else {
- start_threshold = 1;
- }
-
- err = snd_pcm_sw_params_set_start_threshold(handle, swparams, start_threshold);
- if (err < 0) {
- ast_log(LOG_ERROR, "start threshold: %s\n", snd_strerror(err));
- }
-#endif
-
-#if 1
- if (stream == SND_PCM_STREAM_PLAYBACK) {
- stop_threshold = buffer_size;
- } else {
- stop_threshold = buffer_size;
- }
- err = snd_pcm_sw_params_set_stop_threshold(handle, swparams, stop_threshold);
- if (err < 0) {
- ast_log(LOG_ERROR, "stop threshold: %s\n", snd_strerror(err));
- }
-#endif
-#if 0
- err = snd_pcm_sw_params_set_xfer_align(handle, swparams, PERIOD_FRAMES);
- if (err < 0) {
- ast_log(LOG_ERROR, "Unable to set xfer alignment: %s\n", snd_strerror(err));
- }
-#endif
-
-#if 0
- err = snd_pcm_sw_params_set_silence_threshold(handle, swparams, silencethreshold);
- if (err < 0) {
- ast_log(LOG_ERROR, "Unable to set silence threshold: %s\n", snd_strerror(err));
- }
-#endif
- err = snd_pcm_sw_params(handle, swparams);
- if (err < 0) {
- ast_log(LOG_ERROR, "sw_params: %s\n", snd_strerror(err));
- }
-
- err = snd_pcm_poll_descriptors_count(handle);
- if (err <= 0) {
- ast_log(LOG_ERROR, "Unable to get a poll descriptors count, error is %s\n", snd_strerror(err));
- }
-
- if (err != 1) {
- ast_log(LOG_DEBUG, "Can't handle more than one device\n");
- }
-
- snd_pcm_poll_descriptors(handle, &pfd, err);
- ast_log(LOG_DEBUG, "Acquired fd %d from the poll descriptor\n", pfd.fd);
-
- if (stream == SND_PCM_STREAM_CAPTURE)
- readdev = pfd.fd;
- else
- writedev = pfd.fd;
-
- return handle;
-}
-
-static int soundcard_init(void)
-{
- alsa.icard = alsa_card_init(indevname, SND_PCM_STREAM_CAPTURE);
- alsa.ocard = alsa_card_init(outdevname, SND_PCM_STREAM_PLAYBACK);
-
- if (!alsa.icard || !alsa.ocard) {
- ast_log(LOG_ERROR, "Problem opening alsa I/O devices\n");
- return -1;
- }
-
- return readdev;
-}
-
-static int alsa_digit(struct ast_channel *c, char digit)
-{
- ast_mutex_lock(&alsalock);
- ast_verbose( " << Console Received digit %c >> \n", digit);
- ast_mutex_unlock(&alsalock);
- return 0;
-}
-
-static int alsa_text(struct ast_channel *c, const char *text)
-{
- ast_mutex_lock(&alsalock);
- ast_verbose( " << Console Received text %s >> \n", text);
- ast_mutex_unlock(&alsalock);
- return 0;
-}
-
-static void grab_owner(void)
-{
- while(alsa.owner && ast_mutex_trylock(&alsa.owner->lock)) {
- ast_mutex_unlock(&alsalock);
- usleep(1);
- ast_mutex_lock(&alsalock);
- }
-}
-
-static int alsa_call(struct ast_channel *c, char *dest, int timeout)
-{
- int res = 3;
- struct ast_frame f = { AST_FRAME_CONTROL };
- ast_mutex_lock(&alsalock);
- ast_verbose( " << Call placed to '%s' on console >> \n", dest);
- if (autoanswer) {
- ast_verbose( " << Auto-answered >> \n" );
- grab_owner();
- if (alsa.owner) {
- f.subclass = AST_CONTROL_ANSWER;
- ast_queue_frame(alsa.owner, &f);
- ast_mutex_unlock(&alsa.owner->lock);
- }
- } else {
- ast_verbose( " << Type 'answer' to answer, or use 'autoanswer' for future calls >> \n");
- grab_owner();
- if (alsa.owner) {
- f.subclass = AST_CONTROL_RINGING;
- ast_queue_frame(alsa.owner, &f);
- ast_mutex_unlock(&alsa.owner->lock);
- }
- write(sndcmd[1], &res, sizeof(res));
- }
- snd_pcm_prepare(alsa.icard);
- snd_pcm_start(alsa.icard);
- ast_mutex_unlock(&alsalock);
- return 0;
-}
-
-static void answer_sound(void)
-{
- int res;
- nosound = 1;
- res = 4;
- write(sndcmd[1], &res, sizeof(res));
-
-}
-
-static int alsa_answer(struct ast_channel *c)
-{
- ast_mutex_lock(&alsalock);
- ast_verbose( " << Console call has been answered >> \n");
- answer_sound();
- ast_setstate(c, AST_STATE_UP);
- cursound = -1;
- snd_pcm_prepare(alsa.icard);
- snd_pcm_start(alsa.icard);
- ast_mutex_unlock(&alsalock);
- return 0;
-}
-
-static int alsa_hangup(struct ast_channel *c)
-{
- int res;
- ast_mutex_lock(&alsalock);
- cursound = -1;
- c->tech_pvt = NULL;
- alsa.owner = NULL;
- ast_verbose( " << Hangup on console >> \n");
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
- if (hookstate) {
- if (autoanswer) {
- hookstate = 0;
- } else {
- /* Congestion noise */
- res = 2;
- write(sndcmd[1], &res, sizeof(res));
- hookstate = 0;
- }
- }
- snd_pcm_drop(alsa.icard);
- ast_mutex_unlock(&alsalock);
- return 0;
-}
-
-static int alsa_write(struct ast_channel *chan, struct ast_frame *f)
-{
- static char sizbuf[8000];
- static int sizpos = 0;
- int len = sizpos;
- int pos;
- int res = 0;
- /* size_t frames = 0; */
- snd_pcm_state_t state;
- /* Immediately return if no sound is enabled */
- if (nosound)
- return 0;
- ast_mutex_lock(&alsalock);
- /* Stop any currently playing sound */
- if (cursound != -1) {
- snd_pcm_drop(alsa.ocard);
- snd_pcm_prepare(alsa.ocard);
- cursound = -1;
- }
-
-
- /* We have to digest the frame in 160-byte portions */
- if (f->datalen > sizeof(sizbuf) - sizpos) {
- ast_log(LOG_WARNING, "Frame too large\n");
- res = -1;
- } else {
- memcpy(sizbuf + sizpos, f->data, f->datalen);
- len += f->datalen;
- pos = 0;
-#ifdef ALSA_MONITOR
- alsa_monitor_write(sizbuf, len);
-#endif
- state = snd_pcm_state(alsa.ocard);
- if (state == SND_PCM_STATE_XRUN) {
- snd_pcm_prepare(alsa.ocard);
- }
- res = snd_pcm_writei(alsa.ocard, sizbuf, len/2);
- if (res == -EPIPE) {
-#if DEBUG
- ast_log(LOG_DEBUG, "XRUN write\n");
-#endif
- snd_pcm_prepare(alsa.ocard);
- res = snd_pcm_writei(alsa.ocard, sizbuf, len/2);
- if (res != len/2) {
- ast_log(LOG_ERROR, "Write error: %s\n", snd_strerror(res));
- res = -1;
- } else if (res < 0) {
- ast_log(LOG_ERROR, "Write error %s\n", snd_strerror(res));
- res = -1;
- }
- } else {
- if (res == -ESTRPIPE) {
- ast_log(LOG_ERROR, "You've got some big problems\n");
- } else if (res < 0)
- ast_log(LOG_NOTICE, "Error %d on write\n", res);
- }
- }
- ast_mutex_unlock(&alsalock);
- if (res > 0)
- res = 0;
- return res;
-}
-
-
-static struct ast_frame *alsa_read(struct ast_channel *chan)
-{
- static struct ast_frame f;
- static short __buf[FRAME_SIZE + AST_FRIENDLY_OFFSET/2];
- short *buf;
- static int readpos = 0;
- static int left = FRAME_SIZE;
- snd_pcm_state_t state;
- int r = 0;
- int off = 0;
-
- ast_mutex_lock(&alsalock);
- /* Acknowledge any pending cmd */
- f.frametype = AST_FRAME_NULL;
- f.subclass = 0;
- f.samples = 0;
- f.datalen = 0;
- f.data = NULL;
- f.offset = 0;
- f.src = type;
- f.mallocd = 0;
- f.delivery.tv_sec = 0;
- f.delivery.tv_usec = 0;
-
- state = snd_pcm_state(alsa.icard);
- if ((state != SND_PCM_STATE_PREPARED) &&
- (state != SND_PCM_STATE_RUNNING)) {
- snd_pcm_prepare(alsa.icard);
- }
-
- buf = __buf + AST_FRIENDLY_OFFSET/2;
-
- r = snd_pcm_readi(alsa.icard, buf + readpos, left);
- if (r == -EPIPE) {
-#if DEBUG
- ast_log(LOG_ERROR, "XRUN read\n");
-#endif
- snd_pcm_prepare(alsa.icard);
- } else if (r == -ESTRPIPE) {
- ast_log(LOG_ERROR, "-ESTRPIPE\n");
- snd_pcm_prepare(alsa.icard);
- } else if (r < 0) {
- ast_log(LOG_ERROR, "Read error: %s\n", snd_strerror(r));
- } else if (r >= 0) {
- off -= r;
- }
- /* Update positions */
- readpos += r;
- left -= r;
-
- if (readpos >= FRAME_SIZE) {
- /* A real frame */
- readpos = 0;
- left = FRAME_SIZE;
- if (chan->_state != AST_STATE_UP) {
- /* Don't transmit unless it's up */
- ast_mutex_unlock(&alsalock);
- return &f;
- }
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.samples = FRAME_SIZE;
- f.datalen = FRAME_SIZE * 2;
- f.data = buf;
- f.offset = AST_FRIENDLY_OFFSET;
- f.src = type;
- f.mallocd = 0;
-#ifdef ALSA_MONITOR
- alsa_monitor_read((char *)buf, FRAME_SIZE * 2);
-#endif
-
- }
- ast_mutex_unlock(&alsalock);
- return &f;
-}
-
-static int alsa_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct chan_alsa_pvt *p = newchan->tech_pvt;
- ast_mutex_lock(&alsalock);
- p->owner = newchan;
- ast_mutex_unlock(&alsalock);
- return 0;
-}
-
-static int alsa_indicate(struct ast_channel *chan, int cond)
-{
- int res = 0;
- ast_mutex_lock(&alsalock);
- switch(cond) {
- case AST_CONTROL_BUSY:
- res = 1;
- break;
- case AST_CONTROL_CONGESTION:
- res = 2;
- break;
- case AST_CONTROL_RINGING:
- res = 0;
- break;
- case -1:
- res = -1;
- break;
- case AST_CONTROL_VIDUPDATE:
- res = -1;
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n", cond, chan->name);
- res = -1;
- }
- if (res > -1) {
- write(sndcmd[1], &res, sizeof(res));
- }
- ast_mutex_unlock(&alsalock);
- return res;
-}
-
-static struct ast_channel *alsa_new(struct chan_alsa_pvt *p, int state)
-{
- struct ast_channel *tmp;
- tmp = ast_channel_alloc(1);
- if (tmp) {
- tmp->tech = &alsa_tech;
- snprintf(tmp->name, sizeof(tmp->name), "ALSA/%s", indevname);
- tmp->type = type;
- tmp->fds[0] = readdev;
- tmp->nativeformats = AST_FORMAT_SLINEAR;
- tmp->readformat = AST_FORMAT_SLINEAR;
- tmp->writeformat = AST_FORMAT_SLINEAR;
- tmp->tech_pvt = p;
- if (!ast_strlen_zero(p->context))
- ast_copy_string(tmp->context, p->context, sizeof(tmp->context));
- if (!ast_strlen_zero(p->exten))
- ast_copy_string(tmp->exten, p->exten, sizeof(tmp->exten));
- if (!ast_strlen_zero(language))
- ast_copy_string(tmp->language, language, sizeof(tmp->language));
- p->owner = tmp;
- ast_setstate(tmp, state);
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- tmp = NULL;
- }
- }
- }
- return tmp;
-}
-
-static struct ast_channel *alsa_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat = format;
- struct ast_channel *tmp=NULL;
- format &= AST_FORMAT_SLINEAR;
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of format '%d'\n", oldformat);
- return NULL;
- }
- ast_mutex_lock(&alsalock);
- if (alsa.owner) {
- ast_log(LOG_NOTICE, "Already have a call on the ALSA channel\n");
- *cause = AST_CAUSE_BUSY;
- } else {
- tmp= alsa_new(&alsa, AST_STATE_DOWN);
- if (!tmp) {
- ast_log(LOG_WARNING, "Unable to create new ALSA channel\n");
- }
- }
- ast_mutex_unlock(&alsalock);
- return tmp;
-}
-
-static int console_autoanswer(int fd, int argc, char *argv[])
-{
- int res = RESULT_SUCCESS;;
- if ((argc != 1) && (argc != 2))
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&alsalock);
- if (argc == 1) {
- ast_cli(fd, "Auto answer is %s.\n", autoanswer ? "on" : "off");
- } else {
- if (!strcasecmp(argv[1], "on"))
- autoanswer = -1;
- else if (!strcasecmp(argv[1], "off"))
- autoanswer = 0;
- else
- res = RESULT_SHOWUSAGE;
- }
- ast_mutex_unlock(&alsalock);
- return res;
-}
-
-static char *autoanswer_complete(char *line, char *word, int pos, int state)
-{
-#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
- switch(state) {
- case 0:
- if (!ast_strlen_zero(word) && !strncasecmp(word, "on", MIN(strlen(word), 2)))
- return strdup("on");
- case 1:
- if (!ast_strlen_zero(word) && !strncasecmp(word, "off", MIN(strlen(word), 3)))
- return strdup("off");
- default:
- return NULL;
- }
- return NULL;
-}
-
-static char autoanswer_usage[] =
-"Usage: autoanswer [on|off]\n"
-" Enables or disables autoanswer feature. If used without\n"
-" argument, displays the current on/off status of autoanswer.\n"
-" The default value of autoanswer is in 'alsa.conf'.\n";
-
-static int console_answer(int fd, int argc, char *argv[])
-{
- int res = RESULT_SUCCESS;
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&alsalock);
- if (!alsa.owner) {
- ast_cli(fd, "No one is calling us\n");
- res = RESULT_FAILURE;
- } else {
- hookstate = 1;
- cursound = -1;
- grab_owner();
- if (alsa.owner) {
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
- ast_queue_frame(alsa.owner, &f);
- ast_mutex_unlock(&alsa.owner->lock);
- }
- answer_sound();
- }
- snd_pcm_prepare(alsa.icard);
- snd_pcm_start(alsa.icard);
- ast_mutex_unlock(&alsalock);
- return RESULT_SUCCESS;
-}
-
-static char sendtext_usage[] =
-"Usage: send text <message>\n"
-" Sends a text message for display on the remote terminal.\n";
-
-static int console_sendtext(int fd, int argc, char *argv[])
-{
- int tmparg = 2;
- int res = RESULT_SUCCESS;
- if (argc < 2)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&alsalock);
- if (!alsa.owner) {
- ast_cli(fd, "No one is calling us\n");
- res = RESULT_FAILURE;
- } else {
- struct ast_frame f = { AST_FRAME_TEXT, 0 };
- char text2send[256] = "";
- text2send[0] = '\0';
- while(tmparg < argc) {
- strncat(text2send, argv[tmparg++], sizeof(text2send) - strlen(text2send) - 1);
- strncat(text2send, " ", sizeof(text2send) - strlen(text2send) - 1);
- }
- text2send[strlen(text2send) - 1] = '\n';
- f.data = text2send;
- f.datalen = strlen(text2send) + 1;
- grab_owner();
- if (alsa.owner) {
- ast_queue_frame(alsa.owner, &f);
- f.frametype = AST_FRAME_CONTROL;
- f.subclass = AST_CONTROL_ANSWER;
- f.data = NULL;
- f.datalen = 0;
- ast_queue_frame(alsa.owner, &f);
- ast_mutex_unlock(&alsa.owner->lock);
- }
- }
- ast_mutex_unlock(&alsalock);
- return res;
-}
-
-static char answer_usage[] =
-"Usage: answer\n"
-" Answers an incoming call on the console (ALSA) channel.\n";
-
-static int console_hangup(int fd, int argc, char *argv[])
-{
- int res = RESULT_SUCCESS;
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- cursound = -1;
- ast_mutex_lock(&alsalock);
- if (!alsa.owner && !hookstate) {
- ast_cli(fd, "No call to hangup up\n");
- res = RESULT_FAILURE;
- } else {
- hookstate = 0;
- grab_owner();
- if (alsa.owner) {
- ast_queue_hangup(alsa.owner);
- ast_mutex_unlock(&alsa.owner->lock);
- }
- }
- ast_mutex_unlock(&alsalock);
- return res;
-}
-
-static char hangup_usage[] =
-"Usage: hangup\n"
-" Hangs up any call currently placed on the console.\n";
-
-
-static int console_dial(int fd, int argc, char *argv[])
-{
- char tmp[256], *tmp2;
- char *mye, *myc;
- char *d;
- int res = RESULT_SUCCESS;
- if ((argc != 1) && (argc != 2))
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&alsalock);
- if (alsa.owner) {
- if (argc == 2) {
- d = argv[1];
- grab_owner();
- if (alsa.owner) {
- struct ast_frame f = { AST_FRAME_DTMF };
- while(*d) {
- f.subclass = *d;
- ast_queue_frame(alsa.owner, &f);
- d++;
- }
- ast_mutex_unlock(&alsa.owner->lock);
- }
- } else {
- ast_cli(fd, "You're already in a call. You can use this only to dial digits until you hangup\n");
- res = RESULT_FAILURE;
- }
- } else {
- mye = exten;
- myc = context;
- if (argc == 2) {
- char *stringp=NULL;
- strncpy(tmp, argv[1], sizeof(tmp)-1);
- stringp=tmp;
- strsep(&stringp, "@");
- tmp2 = strsep(&stringp, "@");
- if (!ast_strlen_zero(tmp))
- mye = tmp;
- if (!ast_strlen_zero(tmp2))
- myc = tmp2;
- }
- if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
- strncpy(alsa.exten, mye, sizeof(alsa.exten)-1);
- strncpy(alsa.context, myc, sizeof(alsa.context)-1);
- hookstate = 1;
- alsa_new(&alsa, AST_STATE_RINGING);
- } else
- ast_cli(fd, "No such extension '%s' in context '%s'\n", mye, myc);
- }
- ast_mutex_unlock(&alsalock);
- return res;
-}
-
-static char dial_usage[] =
-"Usage: dial [extension[@context]]\n"
-" Dials a given extension (and context if specified)\n";
-
-
-static struct ast_cli_entry myclis[] = {
- { { "answer", NULL }, console_answer, "Answer an incoming console call", answer_usage },
- { { "hangup", NULL }, console_hangup, "Hangup a call on the console", hangup_usage },
- { { "dial", NULL }, console_dial, "Dial an extension on the console", dial_usage },
- { { "send", "text", NULL }, console_sendtext, "Send text to the remote device", sendtext_usage },
- { { "autoanswer", NULL }, console_autoanswer, "Sets/displays autoanswer", autoanswer_usage, autoanswer_complete }
-};
-
-int load_module()
-{
- int res;
- int x;
- struct ast_config *cfg;
- struct ast_variable *v;
- if ((cfg = ast_config_load(config))) {
- v = ast_variable_browse(cfg, "general");
- while(v) {
- if (!strcasecmp(v->name, "autoanswer"))
- autoanswer = ast_true(v->value);
- else if (!strcasecmp(v->name, "silencesuppression"))
- silencesuppression = ast_true(v->value);
- else if (!strcasecmp(v->name, "silencethreshold"))
- silencethreshold = atoi(v->value);
- else if (!strcasecmp(v->name, "context"))
- strncpy(context, v->value, sizeof(context)-1);
- else if (!strcasecmp(v->name, "language"))
- strncpy(language, v->value, sizeof(language)-1);
- else if (!strcasecmp(v->name, "extension"))
- strncpy(exten, v->value, sizeof(exten)-1);
- else if (!strcasecmp(v->name, "input_device"))
- strncpy(indevname, v->value, sizeof(indevname)-1);
- else if (!strcasecmp(v->name, "output_device"))
- strncpy(outdevname, v->value, sizeof(outdevname)-1);
- v=v->next;
- }
- ast_config_destroy(cfg);
- }
- res = pipe(sndcmd);
- if (res) {
- ast_log(LOG_ERROR, "Unable to create pipe\n");
- return -1;
- }
- res = soundcard_init();
- if (res < 0) {
- if (option_verbose > 1) {
- ast_verbose(VERBOSE_PREFIX_2 "No sound card detected -- console channel will be unavailable\n");
- ast_verbose(VERBOSE_PREFIX_2 "Turn off ALSA support by adding 'noload=chan_alsa.so' in /etc/asterisk/modules.conf\n");
- }
- return 0;
- }
-
- res = ast_channel_register(&alsa_tech);
- if (res < 0) {
- ast_log(LOG_ERROR, "Unable to register channel class '%s'\n", type);
- return -1;
- }
- for (x=0;x<sizeof(myclis)/sizeof(struct ast_cli_entry); x++)
- ast_cli_register(myclis + x);
- ast_pthread_create(&sthread, NULL, sound_thread, NULL);
-#ifdef ALSA_MONITOR
- if (alsa_monitor_start()) {
- ast_log(LOG_ERROR, "Problem starting Monitoring\n");
- }
-#endif
- return 0;
-}
-
-
-
-int unload_module()
-{
- int x;
-
- ast_channel_unregister(&alsa_tech);
- for (x=0;x<sizeof(myclis)/sizeof(struct ast_cli_entry); x++)
- ast_cli_unregister(myclis + x);
- if (alsa.icard)
- snd_pcm_close(alsa.icard);
- if (alsa.ocard)
- snd_pcm_close(alsa.ocard);
- if (sndcmd[0] > 0) {
- close(sndcmd[0]);
- close(sndcmd[1]);
- }
- if (alsa.owner)
- ast_softhangup(alsa.owner, AST_SOFTHANGUP_APPUNLOAD);
- if (alsa.owner)
- return -1;
- return 0;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_features.c b/1.2-netsec/channels/chan_features.c
deleted file mode 100644
index 97bbdf8ed..000000000
--- a/1.2-netsec/channels/chan_features.c
+++ /dev/null
@@ -1,606 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief feature Proxy Channel
- *
- * \note *** Experimental code ****
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/signal.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp.h"
-#include "asterisk/acl.h"
-#include "asterisk/callerid.h"
-#include "asterisk/file.h"
-#include "asterisk/cli.h"
-#include "asterisk/app.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/manager.h"
-
-static const char desc[] = "Feature Proxy Channel";
-static const char type[] = "Feature";
-static const char tdesc[] = "Feature Proxy Channel Driver";
-
-static int usecnt =0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-#define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
-
-/* Protect the interface list (of feature_pvt's) */
-AST_MUTEX_DEFINE_STATIC(featurelock);
-
-struct feature_sub {
- struct ast_channel *owner;
- int inthreeway;
- int pfd;
- int timingfdbackup;
- int alertpipebackup[2];
-};
-
-static struct feature_pvt {
- ast_mutex_t lock; /* Channel private lock */
- char tech[AST_MAX_EXTENSION]; /* Technology to abstract */
- char dest[AST_MAX_EXTENSION]; /* Destination to abstract */
- struct ast_channel *subchan;
- struct feature_sub subs[3]; /* Subs */
- struct ast_channel *owner; /* Current Master Channel */
- struct feature_pvt *next; /* Next entity */
-} *features = NULL;
-
-#define SUB_REAL 0 /* Active call */
-#define SUB_CALLWAIT 1 /* Call-Waiting call on hold */
-#define SUB_THREEWAY 2 /* Three-way call */
-
-static struct ast_channel *features_request(const char *type, int format, void *data, int *cause);
-static int features_digit(struct ast_channel *ast, char digit);
-static int features_call(struct ast_channel *ast, char *dest, int timeout);
-static int features_hangup(struct ast_channel *ast);
-static int features_answer(struct ast_channel *ast);
-static struct ast_frame *features_read(struct ast_channel *ast);
-static int features_write(struct ast_channel *ast, struct ast_frame *f);
-static int features_indicate(struct ast_channel *ast, int condition);
-static int features_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-
-static const struct ast_channel_tech features_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = -1,
- .requester = features_request,
- .send_digit = features_digit,
- .call = features_call,
- .hangup = features_hangup,
- .answer = features_answer,
- .read = features_read,
- .write = features_write,
- .exception = features_read,
- .indicate = features_indicate,
- .fixup = features_fixup,
-};
-
-static inline void init_sub(struct feature_sub *sub)
-{
- sub->inthreeway = 0;
- sub->pfd = -1;
- sub->timingfdbackup = -1;
- sub->alertpipebackup[0] = sub->alertpipebackup[1] = -1;
-}
-
-static inline int indexof(struct feature_pvt *p, struct ast_channel *owner, int nullok)
-{
- int x;
- if (!owner) {
- ast_log(LOG_WARNING, "indexof called on NULL owner??\n");
- return -1;
- }
- for (x=0; x<3; x++) {
- if (owner == p->subs[x].owner)
- return x;
- }
- return -1;
-}
-
-#if 0
-static void wakeup_sub(struct feature_pvt *p, int a)
-{
- struct ast_frame null = { AST_FRAME_NULL, };
- for (;;) {
- if (p->subs[a].owner) {
- if (ast_mutex_trylock(&p->subs[a].owner->lock)) {
- ast_mutex_unlock(&p->lock);
- usleep(1);
- ast_mutex_lock(&p->lock);
- } else {
- ast_queue_frame(p->subs[a].owner, &null);
- ast_mutex_unlock(&p->subs[a].owner->lock);
- break;
- }
- } else
- break;
- }
-}
-#endif
-
-static void restore_channel(struct feature_pvt *p, int index)
-{
- /* Restore timing/alertpipe */
- p->subs[index].owner->timingfd = p->subs[index].timingfdbackup;
- p->subs[index].owner->alertpipe[0] = p->subs[index].alertpipebackup[0];
- p->subs[index].owner->alertpipe[1] = p->subs[index].alertpipebackup[1];
- p->subs[index].owner->fds[AST_MAX_FDS-1] = p->subs[index].alertpipebackup[0];
- p->subs[index].owner->fds[AST_MAX_FDS-2] = p->subs[index].timingfdbackup;
-}
-
-static void update_features(struct feature_pvt *p, int index)
-{
- int x;
- if (p->subs[index].owner) {
- for (x=0; x<AST_MAX_FDS; x++) {
- if (index)
- p->subs[index].owner->fds[x] = -1;
- else
- p->subs[index].owner->fds[x] = p->subchan->fds[x];
- }
- if (!index) {
- /* Copy timings from master channel */
- p->subs[index].owner->timingfd = p->subchan->timingfd;
- p->subs[index].owner->alertpipe[0] = p->subchan->alertpipe[0];
- p->subs[index].owner->alertpipe[1] = p->subchan->alertpipe[1];
- if (p->subs[index].owner->nativeformats != p->subchan->readformat) {
- p->subs[index].owner->nativeformats = p->subchan->readformat;
- if (p->subs[index].owner->readformat)
- ast_set_read_format(p->subs[index].owner, p->subs[index].owner->readformat);
- if (p->subs[index].owner->writeformat)
- ast_set_write_format(p->subs[index].owner, p->subs[index].owner->writeformat);
- }
- } else{
- restore_channel(p, index);
- }
- }
-}
-
-#if 0
-static void swap_subs(struct feature_pvt *p, int a, int b)
-{
- int tinthreeway;
- struct ast_channel *towner;
-
- ast_log(LOG_DEBUG, "Swapping %d and %d\n", a, b);
-
- towner = p->subs[a].owner;
- tinthreeway = p->subs[a].inthreeway;
-
- p->subs[a].owner = p->subs[b].owner;
- p->subs[a].inthreeway = p->subs[b].inthreeway;
-
- p->subs[b].owner = towner;
- p->subs[b].inthreeway = tinthreeway;
- update_features(p,a);
- update_features(p,b);
- wakeup_sub(p, a);
- wakeup_sub(p, b);
-}
-#endif
-
-static int features_answer(struct ast_channel *ast)
-{
- struct feature_pvt *p = ast->tech_pvt;
- int res = -1;
- int x;
-
- ast_mutex_lock(&p->lock);
- x = indexof(p, ast, 0);
- if (!x && p->subchan)
- res = ast_answer(p->subchan);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static struct ast_frame *features_read(struct ast_channel *ast)
-{
- static struct ast_frame null_frame = { AST_FRAME_NULL, };
- struct feature_pvt *p = ast->tech_pvt;
- struct ast_frame *f;
- int x;
-
- f = &null_frame;
- ast_mutex_lock(&p->lock);
- x = indexof(p, ast, 0);
- if (!x && p->subchan) {
- update_features(p, x);
- f = ast_read(p->subchan);
- }
- ast_mutex_unlock(&p->lock);
- return f;
-}
-
-static int features_write(struct ast_channel *ast, struct ast_frame *f)
-{
- struct feature_pvt *p = ast->tech_pvt;
- int res = -1;
- int x;
-
- ast_mutex_lock(&p->lock);
- x = indexof(p, ast, 0);
- if (!x && p->subchan)
- res = ast_write(p->subchan, f);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int features_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct feature_pvt *p = newchan->tech_pvt;
- int x;
-
- ast_mutex_lock(&p->lock);
- if (p->owner == oldchan)
- p->owner = newchan;
- for (x = 0; x < 3; x++) {
- if (p->subs[x].owner == oldchan)
- p->subs[x].owner = newchan;
- }
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-static int features_indicate(struct ast_channel *ast, int condition)
-{
- struct feature_pvt *p = ast->tech_pvt;
- int res = -1;
- int x;
-
- /* Queue up a frame representing the indication as a control frame */
- ast_mutex_lock(&p->lock);
- x = indexof(p, ast, 0);
- if (!x && p->subchan)
- res = ast_indicate(p->subchan, condition);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int features_digit(struct ast_channel *ast, char digit)
-{
- struct feature_pvt *p = ast->tech_pvt;
- int res = -1;
- int x;
-
- /* Queue up a frame representing the indication as a control frame */
- ast_mutex_lock(&p->lock);
- x = indexof(p, ast, 0);
- if (!x && p->subchan)
- res = ast_senddigit(p->subchan, digit);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int features_call(struct ast_channel *ast, char *dest, int timeout)
-{
- struct feature_pvt *p = ast->tech_pvt;
- int res = -1;
- int x;
- char *dest2;
-
- dest2 = strchr(dest, '/');
- if (dest2) {
- ast_mutex_lock(&p->lock);
- x = indexof(p, ast, 0);
- if (!x && p->subchan) {
- if (p->owner->cid.cid_num)
- p->subchan->cid.cid_num = strdup(p->owner->cid.cid_num);
- else
- p->subchan->cid.cid_num = NULL;
-
- if (p->owner->cid.cid_name)
- p->subchan->cid.cid_name = strdup(p->owner->cid.cid_name);
- else
- p->subchan->cid.cid_name = NULL;
-
- if (p->owner->cid.cid_rdnis)
- p->subchan->cid.cid_rdnis = strdup(p->owner->cid.cid_rdnis);
- else
- p->subchan->cid.cid_rdnis = NULL;
-
- if (p->owner->cid.cid_ani)
- p->subchan->cid.cid_ani = strdup(p->owner->cid.cid_ani);
- else
- p->subchan->cid.cid_ani = NULL;
-
- p->subchan->cid.cid_pres = p->owner->cid.cid_pres;
- strncpy(p->subchan->language, p->owner->language, sizeof(p->subchan->language) - 1);
- strncpy(p->subchan->accountcode, p->owner->accountcode, sizeof(p->subchan->accountcode) - 1);
- p->subchan->cdrflags = p->owner->cdrflags;
- res = ast_call(p->subchan, dest2, timeout);
- update_features(p, x);
- } else
- ast_log(LOG_NOTICE, "Uhm yah, not quite there with the call waiting...\n");
- ast_mutex_unlock(&p->lock);
- }
- return res;
-}
-
-static int features_hangup(struct ast_channel *ast)
-{
- struct feature_pvt *p = ast->tech_pvt;
- struct feature_pvt *cur, *prev=NULL;
- int x;
-
- ast_mutex_lock(&p->lock);
- x = indexof(p, ast, 0);
- if (x > -1) {
- restore_channel(p, x);
- p->subs[x].owner = NULL;
- /* XXX Re-arrange, unconference, etc XXX */
- }
- ast->tech_pvt = NULL;
-
-
- if (!p->subs[SUB_REAL].owner && !p->subs[SUB_CALLWAIT].owner && !p->subs[SUB_THREEWAY].owner) {
- ast_mutex_unlock(&p->lock);
- /* Remove from list */
- ast_mutex_lock(&featurelock);
- cur = features;
- while(cur) {
- if (cur == p) {
- if (prev)
- prev->next = cur->next;
- else
- features = cur->next;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- ast_mutex_unlock(&featurelock);
- ast_mutex_lock(&p->lock);
- /* And destroy */
- if (p->subchan)
- ast_hangup(p->subchan);
- ast_mutex_unlock(&p->lock);
- ast_mutex_destroy(&p->lock);
- free(p);
- return 0;
- }
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-static struct feature_pvt *features_alloc(char *data, int format)
-{
- struct feature_pvt *tmp;
- char *dest=NULL;
- char *tech;
- int x;
- int status;
- struct ast_channel *chan;
-
- tech = ast_strdupa(data);
- if (tech) {
- dest = strchr(tech, '/');
- if (dest) {
- *dest = '\0';
- dest++;
- }
- }
- if (!tech || !dest) {
- ast_log(LOG_NOTICE, "Format for feature channel is Feature/Tech/Dest ('%s' not valid)!\n",
- data);
- return NULL;
- }
- ast_mutex_lock(&featurelock);
- tmp = features;
- while(tmp) {
- if (!strcasecmp(tmp->tech, tech) && !strcmp(tmp->dest, dest))
- break;
- tmp = tmp->next;
- }
- ast_mutex_unlock(&featurelock);
- if (!tmp) {
- chan = ast_request(tech, format, dest, &status);
- if (!chan) {
- ast_log(LOG_NOTICE, "Unable to allocate subchannel '%s/%s'\n", tech, dest);
- return NULL;
- }
- tmp = malloc(sizeof(struct feature_pvt));
- if (tmp) {
- memset(tmp, 0, sizeof(struct feature_pvt));
- for (x=0;x<3;x++)
- init_sub(tmp->subs + x);
- ast_mutex_init(&tmp->lock);
- strncpy(tmp->tech, tech, sizeof(tmp->tech) - 1);
- strncpy(tmp->dest, dest, sizeof(tmp->dest) - 1);
- tmp->subchan = chan;
- ast_mutex_lock(&featurelock);
- tmp->next = features;
- features = tmp;
- ast_mutex_unlock(&featurelock);
- }
- }
- return tmp;
-}
-
-static struct ast_channel *features_new(struct feature_pvt *p, int state, int index)
-{
- struct ast_channel *tmp;
- int x,y;
- if (!p->subchan) {
- ast_log(LOG_WARNING, "Called upon channel with no subchan:(\n");
- return NULL;
- }
- if (p->subs[index].owner) {
- ast_log(LOG_WARNING, "Called to put index %d already there!\n", index);
- return NULL;
- }
- tmp = ast_channel_alloc(0);
- if (!tmp) {
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- return NULL;
- }
- tmp->tech = &features_tech;
- for (x=1;x<4;x++) {
- snprintf(tmp->name, sizeof(tmp->name), "Feature/%s/%s-%d", p->tech, p->dest, x);
- for (y=0;y<3;y++) {
- if (y == index)
- continue;
- if (p->subs[y].owner && !strcasecmp(p->subs[y].owner->name, tmp->name))
- break;
- }
- if (y >= 3)
- break;
- }
- tmp->type = type;
- ast_setstate(tmp, state);
- tmp->writeformat = p->subchan->writeformat;
- tmp->rawwriteformat = p->subchan->rawwriteformat;
- tmp->readformat = p->subchan->readformat;
- tmp->rawreadformat = p->subchan->rawreadformat;
- tmp->nativeformats = p->subchan->readformat;
- tmp->tech_pvt = p;
- p->subs[index].owner = tmp;
- if (!p->owner)
- p->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- return tmp;
-}
-
-
-static struct ast_channel *features_request(const char *type, int format, void *data, int *cause)
-{
- struct feature_pvt *p;
- struct ast_channel *chan = NULL;
-
- p = features_alloc(data, format);
- if (p && !p->subs[SUB_REAL].owner)
- chan = features_new(p, AST_STATE_DOWN, SUB_REAL);
- if (chan)
- update_features(p,SUB_REAL);
- return chan;
-}
-
-static int features_show(int fd, int argc, char **argv)
-{
- struct feature_pvt *p;
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&featurelock);
- p = features;
- while(p) {
- ast_mutex_lock(&p->lock);
- ast_cli(fd, "%s -- %s/%s\n", p->owner ? p->owner->name : "<unowned>", p->tech, p->dest);
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- if (!features)
- ast_cli(fd, "No feature channels in use\n");
- ast_mutex_unlock(&featurelock);
- return RESULT_SUCCESS;
-}
-
-static char show_features_usage[] =
-"Usage: feature show channels\n"
-" Provides summary information on feature channels.\n";
-
-static struct ast_cli_entry cli_show_features = {
- { "feature", "show", "channels", NULL }, features_show,
- "Show status of feature channels", show_features_usage, NULL };
-
-int load_module()
-{
- /* Make sure we can register our sip channel type */
- if (ast_channel_register(&features_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- return -1;
- }
- ast_cli_register(&cli_show_features);
- return 0;
-}
-
-int reload()
-{
- return 0;
-}
-
-int unload_module()
-{
- struct feature_pvt *p, *prev;
- /* First, take us out of the channel loop */
- ast_cli_unregister(&cli_show_features);
- ast_channel_unregister(&features_tech);
- if (!ast_mutex_lock(&featurelock)) {
- /* Hangup all interfaces if they have an owner */
- for (p = features; p; p = p->next) {
- prev = p;
- if (p->owner)
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- free(prev);
- }
- features = NULL;
- ast_mutex_unlock(&featurelock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
diff --git a/1.2-netsec/channels/chan_h323.c b/1.2-netsec/channels/chan_h323.c
deleted file mode 100644
index 469ce398e..000000000
--- a/1.2-netsec/channels/chan_h323.c
+++ /dev/null
@@ -1,2471 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005
- *
- * OpenH323 Channel Driver for ASTERISK PBX.
- * By Jeremy McNamara
- * For The NuFone Network
- *
- * chan_h323 has been derived from code created by
- * Michael Manousos and 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 This file is part of the chan_h323 driver for Asterisk
- *
- * \par See also
- * \arg Config_h323
- *
- * \ingroup channel_drivers
- */
-
-#include <sys/socket.h>
-#include <sys/signal.h>
-#include <sys/param.h>
-#if defined(BSD)
-#ifndef IPTOS_MINCOST
-#define IPTOS_MINCOST 0x02
-#endif
-#endif
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp.h"
-#include "asterisk/acl.h"
-#include "asterisk/callerid.h"
-#include "asterisk/cli.h"
-#include "asterisk/dsp.h"
-#include "asterisk/causes.h"
-#ifdef __cplusplus
-}
-#endif
-#include "h323/chan_h323.h"
-
-send_digit_cb on_send_digit;
-on_rtp_cb on_external_rtp_create;
-start_rtp_cb on_start_rtp_channel;
-setup_incoming_cb on_incoming_call;
-setup_outbound_cb on_outgoing_call;
-chan_ringing_cb on_chan_ringing;
-con_established_cb on_connection_established;
-clear_con_cb on_connection_cleared;
-answer_call_cb on_answer_call;
-progress_cb on_progress;
-rfc2833_cb on_set_rfc2833_payload;
-hangup_cb on_hangup;
-setcapabilities_cb on_setcapabilities;
-
-/* global debug flag */
-int h323debug;
-
-/** Variables required by Asterisk */
-static const char type[] = "H323";
-static const char desc[] = "The NuFone Network's Open H.323 Channel Driver";
-static const char tdesc[] = "The NuFone Network's Open H.323 Channel Driver";
-static const char config[] = "h323.conf";
-static char default_context[AST_MAX_CONTEXT] = "default";
-static struct sockaddr_in bindaddr;
-
-/** H.323 configuration values */
-static int h323_signalling_port = 1720;
-static char gatekeeper[100];
-static int gatekeeper_disable = 1;
-static int gatekeeper_discover = 0;
-static int usingGk = 0;
-static int gkroute = 0;
-/* Find user by alias (h.323 id) is default, alternative is the incomming call's source IP address*/
-static int userbyalias = 1;
-static int tos = 0;
-static char secret[50];
-static unsigned int unique = 0;
-
-static call_options_t global_options;
-
-/** Private structure of a OpenH323 channel */
-struct oh323_pvt {
- ast_mutex_t lock; /* Channel private lock */
- call_options_t options; /* Options to be used during call setup */
- int alreadygone; /* Whether or not we've already been destroyed by our peer */
- int needdestroy; /* if we need to be destroyed */
- call_details_t cd; /* Call details */
- struct ast_channel *owner; /* Who owns us */
- struct sockaddr_in sa; /* Our peer */
- struct sockaddr_in redirip; /* Where our RTP should be going if not to us */
- int nonCodecCapability; /* non-audio capability */
- int outgoing; /* Outgoing or incoming call? */
- char exten[AST_MAX_EXTENSION]; /* Requested extension */
- char context[AST_MAX_CONTEXT]; /* Context where to start */
- char accountcode[256]; /* Account code */
- char cid_num[80]; /* Caller*id number, if available */
- char cid_name[80]; /* Caller*id name, if available */
- char rdnis[80]; /* Referring DNIS, if available */
- int amaflags; /* AMA Flags */
- struct ast_rtp *rtp; /* RTP Session */
- struct ast_dsp *vad; /* Used for in-band DTMF detection */
- int nativeformats; /* Codec formats supported by a channel */
- int needhangup; /* Send hangup when Asterisk is ready */
- int hangupcause; /* Hangup cause from OpenH323 layer */
- int newstate; /* Pending state change */
- int newcontrol; /* Pending control to send */
- struct oh323_pvt *next; /* Next channel in list */
-} *iflist = NULL;
-
-static struct ast_user_list {
- struct oh323_user *users;
- ast_mutex_t lock;
-} userl;
-
-static struct ast_peer_list {
- struct oh323_peer *peers;
- ast_mutex_t lock;
-} peerl;
-
-static struct ast_alias_list {
- struct oh323_alias *aliases;
- ast_mutex_t lock;
-} aliasl;
-
-/** Asterisk RTP stuff */
-static struct sched_context *sched;
-static struct io_context *io;
-
-/** Protect the interface list (oh323_pvt) */
-AST_MUTEX_DEFINE_STATIC(iflock);
-
-/** Usage counter and associated lock */
-static int usecnt = 0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-/* Protect the monitoring thread, so only one process can kill or start it, and not
- when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(monlock);
-
-/* Protect the H.323 capabilities list, to avoid more than one channel to set the capabilities simultaneaously in the h323 stack. */
-AST_MUTEX_DEFINE_STATIC(caplock);
-
-/* Protect the reload process */
-AST_MUTEX_DEFINE_STATIC(h323_reload_lock);
-static int h323_reloading = 0;
-
-/* This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
-static int restart_monitor(void);
-static int h323_do_reload(void);
-
-static struct ast_channel *oh323_request(const char *type, int format, void *data, int *cause);
-static int oh323_digit(struct ast_channel *c, char digit);
-static int oh323_call(struct ast_channel *c, char *dest, int timeout);
-static int oh323_hangup(struct ast_channel *c);
-static int oh323_answer(struct ast_channel *c);
-static struct ast_frame *oh323_read(struct ast_channel *c);
-static int oh323_write(struct ast_channel *c, struct ast_frame *frame);
-static int oh323_indicate(struct ast_channel *c, int condition);
-static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-
-static const struct ast_channel_tech oh323_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_ULAW,
- .properties = AST_CHAN_TP_WANTSJITTER,
- .requester = oh323_request,
- .send_digit = oh323_digit,
- .call = oh323_call,
- .hangup = oh323_hangup,
- .answer = oh323_answer,
- .read = oh323_read,
- .write = oh323_write,
- .indicate = oh323_indicate,
- .fixup = oh323_fixup,
- /* disable, for now */
-#if 0
- .bridge = ast_rtp_bridge,
-#endif
-};
-
-/* Channel and private structures should be already locked */
-static void __oh323_update_info(struct ast_channel *c, struct oh323_pvt *pvt)
-{
- if (c->nativeformats != pvt->nativeformats) {
- if (h323debug)
- ast_log(LOG_DEBUG, "Preparing %s for new native format\n", c->name);
- c->nativeformats = pvt->nativeformats;
- ast_set_read_format(c, c->readformat);
- ast_set_write_format(c, c->writeformat);
- }
- if (pvt->needhangup) {
- if (h323debug)
- ast_log(LOG_DEBUG, "Process pending hangup for %s\n", c->name);
- c->_softhangup |= AST_SOFTHANGUP_DEV;
- c->hangupcause = pvt->hangupcause;
- ast_queue_hangup(c);
- pvt->needhangup = 0;
- pvt->newstate = pvt->newcontrol = -1;
- }
- if (pvt->newstate >= 0) {
- ast_setstate(c, pvt->newstate);
- pvt->newstate = -1;
- }
- if (pvt->newcontrol >= 0) {
- ast_queue_control(c, pvt->newcontrol);
- pvt->newcontrol = -1;
- }
-}
-
-/* Only channel structure should be locked */
-static void oh323_update_info(struct ast_channel *c)
-{
- struct oh323_pvt *pvt = c->tech_pvt;
-
- if (pvt) {
- ast_mutex_lock(&pvt->lock);
- __oh323_update_info(c, pvt);
- ast_mutex_unlock(&pvt->lock);
- }
-}
-
-static void cleanup_call_details(call_details_t *cd)
-{
- if (cd->call_token) {
- free(cd->call_token);
- cd->call_token = NULL;
- }
- if (cd->call_source_aliases) {
- free(cd->call_source_aliases);
- cd->call_source_aliases = NULL;
- }
- if (cd->call_dest_alias) {
- free(cd->call_dest_alias);
- cd->call_dest_alias = NULL;
- }
- if (cd->call_source_name) {
- free(cd->call_source_name);
- cd->call_source_name = NULL;
- }
- if (cd->call_source_e164) {
- free(cd->call_source_e164);
- cd->call_source_e164 = NULL;
- }
- if (cd->call_dest_e164) {
- free(cd->call_dest_e164);
- cd->call_dest_e164 = NULL;
- }
- if (cd->sourceIp) {
- free(cd->sourceIp);
- cd->sourceIp = NULL;
- }
-}
-
-static void __oh323_destroy(struct oh323_pvt *pvt)
-{
- struct oh323_pvt *cur, *prev = NULL;
-
- if (pvt->rtp) {
- ast_rtp_destroy(pvt->rtp);
- }
-
- /* Free dsp used for in-band DTMF detection */
- if (pvt->vad) {
- ast_dsp_free(pvt->vad);
- }
- cleanup_call_details(&pvt->cd);
-
- /* Unlink us from the owner if we have one */
- if (pvt->owner) {
- ast_mutex_lock(&pvt->owner->lock);
- ast_log(LOG_DEBUG, "Detaching from %s\n", pvt->owner->name);
- pvt->owner->tech_pvt = NULL;
- ast_mutex_unlock(&pvt->owner->lock);
- }
- cur = iflist;
- while(cur) {
- if (cur == pvt) {
- if (prev)
- prev->next = cur->next;
- else
- iflist = cur->next;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- if (!cur) {
- ast_log(LOG_WARNING, "%p is not in list?!?! \n", cur);
- } else {
- ast_mutex_destroy(&pvt->lock);
- free(pvt);
- }
-}
-
-static void oh323_destroy(struct oh323_pvt *pvt)
-{
- ast_mutex_lock(&iflock);
- __oh323_destroy(pvt);
- ast_mutex_unlock(&iflock);
-}
-
-/**
- * Send (play) the specified digit to the channel.
- *
- */
-static int oh323_digit(struct ast_channel *c, char digit)
-{
- struct oh323_pvt *pvt = (struct oh323_pvt *) c->tech_pvt;
- char *token;
-
- if (!pvt) {
- ast_log(LOG_ERROR, "No private structure?! This is bad\n");
- return -1;
- }
- ast_mutex_lock(&pvt->lock);
- if (pvt->rtp && (pvt->options.dtmfmode & H323_DTMF_RFC2833)) {
- /* out-of-band DTMF */
- if (h323debug) {
- ast_log(LOG_DEBUG, "Sending out-of-band digit %c on %s\n", digit, c->name);
- }
- ast_rtp_senddigit(pvt->rtp, digit);
- } else {
- /* in-band DTMF */
- if (h323debug) {
- ast_log(LOG_DEBUG, "Sending inband digit %c on %s\n", digit, c->name);
- }
- token = pvt->cd.call_token ? strdup(pvt->cd.call_token) : NULL;
- h323_send_tone(token, digit);
- if (token) {
- free(token);
- }
- }
- ast_mutex_unlock(&pvt->lock);
- oh323_update_info(c);
- return 0;
-}
-
-/**
- * Make a call over the specified channel to the specified
- * destination.
- * Returns -1 on error, 0 on success.
- */
-static int oh323_call(struct ast_channel *c, char *dest, int timeout)
-{
- int res = 0;
- struct oh323_pvt *pvt = (struct oh323_pvt *)c->tech_pvt;
- char addr[INET_ADDRSTRLEN];
- char called_addr[1024];
-
- if (h323debug) {
- ast_log(LOG_DEBUG, "Calling to %s on %s\n", dest, c->name);
- }
- if ((c->_state != AST_STATE_DOWN) && (c->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "Line is already in use (%s)\n", c->name);
- return -1;
- }
- ast_mutex_lock(&pvt->lock);
- if (usingGk) {
- if (ast_strlen_zero(pvt->exten)) {
- strncpy(called_addr, dest, sizeof(called_addr));
- } else {
- snprintf(called_addr, sizeof(called_addr), "%s@%s", pvt->exten, dest);
- }
- } else {
- ast_inet_ntoa(addr, sizeof(addr), pvt->sa.sin_addr);
- res = htons(pvt->sa.sin_port);
- if (ast_strlen_zero(pvt->exten)) {
- snprintf(called_addr, sizeof(called_addr), "%s:%d", addr, res);
- } else {
- snprintf(called_addr, sizeof(called_addr), "%s@%s:%d", pvt->exten, addr, res);
- }
- }
- /* make sure null terminated */
- called_addr[sizeof(called_addr) - 1] = '\0';
-
- if (c->cid.cid_num) {
- strncpy(pvt->options.cid_num, c->cid.cid_num, sizeof(pvt->options.cid_num));
- }
- if (c->cid.cid_name) {
- strncpy(pvt->options.cid_name, c->cid.cid_name, sizeof(pvt->options.cid_name));
- }
-
- /* indicate that this is an outgoing call */
- pvt->outgoing = 1;
-
- ast_log(LOG_DEBUG, "Placing outgoing call to %s, %d\n", called_addr, pvt->options.dtmfcodec);
- ast_mutex_unlock(&pvt->lock);
- res = h323_make_call(called_addr, &(pvt->cd), &pvt->options);
- if (res) {
- ast_log(LOG_NOTICE, "h323_make_call failed(%s)\n", c->name);
- return -1;
- }
- oh323_update_info(c);
- return 0;
-}
-
-static int oh323_answer(struct ast_channel *c)
-{
- int res;
- struct oh323_pvt *pvt = (struct oh323_pvt *) c->tech_pvt;
- char *token;
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Answering on %s\n", c->name);
-
- ast_mutex_lock(&pvt->lock);
- token = pvt->cd.call_token ? strdup(pvt->cd.call_token) : NULL;
- ast_mutex_unlock(&pvt->lock);
- res = h323_answering_call(token, 0);
- if (token)
- free(token);
-
- oh323_update_info(c);
- if (c->_state != AST_STATE_UP) {
- ast_setstate(c, AST_STATE_UP);
- }
- return res;
-}
-
-static int oh323_hangup(struct ast_channel *c)
-{
- struct oh323_pvt *pvt = (struct oh323_pvt *) c->tech_pvt;
- int needcancel = 0;
- int q931cause = AST_CAUSE_NORMAL_CLEARING;
- char *call_token;
-
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Hanging up call %s\n", c->name);
-
- if (!c->tech_pvt) {
- ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n");
- return 0;
- }
- ast_mutex_lock(&pvt->lock);
- /* Determine how to disconnect */
- if (pvt->owner != c) {
- ast_log(LOG_WARNING, "Huh? We aren't the owner?\n");
- ast_mutex_unlock(&pvt->lock);
- return 0;
- }
- if (!c || (c->_state != AST_STATE_UP)) {
- needcancel = 1;
- }
-
- pvt->owner = NULL;
- c->tech_pvt = NULL;
-
- if (c->hangupcause) {
- q931cause = c->hangupcause;
- } else {
- char *cause = pbx_builtin_getvar_helper(c, "DIALSTATUS");
- if (cause) {
- if (!strcmp(cause, "CONGESTION")) {
- q931cause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION;
- } else if (!strcmp(cause, "BUSY")) {
- q931cause = AST_CAUSE_USER_BUSY;
- } else if (!strcmp(cause, "CHANISUNVAIL")) {
- q931cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
- } else if (!strcmp(cause, "NOANSWER")) {
- q931cause = AST_CAUSE_NO_ANSWER;
- } else if (!strcmp(cause, "CANCEL")) {
- q931cause = AST_CAUSE_CALL_REJECTED;
- }
- }
- }
-
- /* Start the process if it's not already started */
- if (!pvt->alreadygone && !pvt->hangupcause) {
- call_token = pvt->cd.call_token ? strdup(pvt->cd.call_token) : NULL;
- if (call_token) {
- /* Release lock to eliminate deadlock */
- ast_mutex_unlock(&pvt->lock);
- if (h323_clear_call(call_token, q931cause)) {
- ast_log(LOG_DEBUG, "ClearCall failed.\n");
- }
- free(call_token);
- ast_mutex_lock(&pvt->lock);
- }
- }
- pvt->needdestroy = 1;
-
- /* Update usage counter */
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- if (usecnt < 0) {
- ast_log(LOG_WARNING, "Usecnt < 0\n");
- }
- ast_mutex_unlock(&usecnt_lock);
- ast_mutex_unlock(&pvt->lock);
- ast_update_use_count();
- return 0;
-}
-
-static struct ast_frame *oh323_rtp_read(struct oh323_pvt *pvt)
-{
- /* Retrieve audio/etc from channel. Assumes pvt->lock is already held. */
- struct ast_frame *f;
- static struct ast_frame null_frame = { AST_FRAME_NULL, };
-
- /* Only apply it for the first packet, we just need the correct ip/port */
- if (pvt->options.nat) {
- ast_rtp_setnat(pvt->rtp, pvt->options.nat);
- pvt->options.nat = 0;
- }
-
- f = ast_rtp_read(pvt->rtp);
- /* Don't send RFC2833 if we're not supposed to */
- if (f && (f->frametype == AST_FRAME_DTMF) && !(pvt->options.dtmfmode & H323_DTMF_RFC2833)) {
- return &null_frame;
- }
- if (pvt->owner) {
- /* We already hold the channel lock */
- if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass != pvt->owner->nativeformats) {
- /* Try to avoid deadlock */
- if (ast_mutex_trylock(&pvt->owner->lock)) {
- ast_log(LOG_NOTICE, "Format changed but channel is locked. Ignoring frame...\n");
- return &null_frame;
- }
- ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
- pvt->owner->nativeformats = f->subclass;
- pvt->nativeformats = f->subclass;
- ast_set_read_format(pvt->owner, pvt->owner->readformat);
- ast_set_write_format(pvt->owner, pvt->owner->writeformat);
- ast_mutex_unlock(&pvt->owner->lock);
- }
- /* Do in-band DTMF detection */
- if ((pvt->options.dtmfmode & H323_DTMF_INBAND) && pvt->vad) {
- if (!ast_mutex_trylock(&pvt->owner->lock)) {
- f = ast_dsp_process(pvt->owner,pvt->vad,f);
- ast_mutex_unlock(&pvt->owner->lock);
- }
- else
- ast_log(LOG_NOTICE, "Unable to process inband DTMF while channel is locked\n");
- if (f &&(f->frametype == AST_FRAME_DTMF)) {
- ast_log(LOG_DEBUG, "Received in-band digit %c.\n", f->subclass);
- }
- }
- }
- }
- return f;
-}
-
-static struct ast_frame *oh323_read(struct ast_channel *c)
-{
- struct ast_frame *fr;
- struct oh323_pvt *pvt = (struct oh323_pvt *)c->tech_pvt;
- ast_mutex_lock(&pvt->lock);
- __oh323_update_info(c, pvt);
- fr = oh323_rtp_read(pvt);
- ast_mutex_unlock(&pvt->lock);
- return fr;
-}
-
-static int oh323_write(struct ast_channel *c, struct ast_frame *frame)
-{
- struct oh323_pvt *pvt = (struct oh323_pvt *) c->tech_pvt;
- int res = 0;
- if (frame->frametype != AST_FRAME_VOICE) {
- if (frame->frametype == AST_FRAME_IMAGE) {
- return 0;
- } else {
- ast_log(LOG_WARNING, "Can't send %d type frames with H323 write\n", frame->frametype);
- return 0;
- }
- } else {
- if (!(frame->subclass & c->nativeformats)) {
- ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
- frame->subclass, c->nativeformats, c->readformat, c->writeformat);
- return 0;
- }
- }
- if (pvt) {
- ast_mutex_lock(&pvt->lock);
- if (pvt->rtp) {
- res = ast_rtp_write(pvt->rtp, frame);
- }
- __oh323_update_info(c, pvt);
- ast_mutex_unlock(&pvt->lock);
- }
- return res;
-}
-
-static int oh323_indicate(struct ast_channel *c, int condition)
-{
-
- struct oh323_pvt *pvt = (struct oh323_pvt *) c->tech_pvt;
- char *token = (char *)NULL;
-
- ast_mutex_lock(&pvt->lock);
- token = (pvt->cd.call_token ? strdup(pvt->cd.call_token) : NULL);
- ast_mutex_unlock(&pvt->lock);
-
- if (h323debug)
- ast_log(LOG_DEBUG, "OH323: Indicating %d on %s\n", condition, token);
-
- switch(condition) {
- case AST_CONTROL_RINGING:
- if (c->_state == AST_STATE_RING || c->_state == AST_STATE_RINGING) {
- h323_send_alerting(token);
- break;
- }
- if (token)
- free(token);
- return -1;
- case AST_CONTROL_PROGRESS:
- if (c->_state != AST_STATE_UP) {
- h323_send_progress(token);
- break;
- }
- if (token)
- free(token);
- return -1;
-
- case AST_CONTROL_BUSY:
- if (c->_state != AST_STATE_UP) {
- h323_answering_call(token, 1);
- ast_mutex_lock(&pvt->lock);
- pvt->alreadygone = 1;
- ast_mutex_unlock(&pvt->lock);
- ast_softhangup_nolock(c, AST_SOFTHANGUP_DEV);
- break;
- }
- if (token)
- free(token);
- return -1;
- case AST_CONTROL_CONGESTION:
- if (c->_state != AST_STATE_UP) {
- h323_answering_call(token, 1);
- ast_mutex_lock(&pvt->lock);
- pvt->alreadygone = 1;
- ast_mutex_unlock(&pvt->lock);
- ast_softhangup_nolock(c, AST_SOFTHANGUP_DEV);
- break;
- }
- if (token)
- free(token);
- return -1;
- case AST_CONTROL_PROCEEDING:
- case -1:
- if (token)
- free(token);
- return -1;
- default:
- ast_log(LOG_WARNING, "Don't know how to indicate condition %d on %s\n", condition, token);
- if (token)
- free(token);
- return -1;
- }
-
- if (h323debug)
- ast_log(LOG_DEBUG, "OH323: Indicated %d on %s\n", condition, token);
- if (token)
- free(token);
- oh323_update_info(c);
-
- return -1;
-}
-
-static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct oh323_pvt *pvt = (struct oh323_pvt *) newchan->tech_pvt;
-
- ast_mutex_lock(&pvt->lock);
- if (pvt->owner != oldchan) {
- ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, pvt->owner);
- return -1;
- }
- pvt->owner = newchan;
- ast_mutex_unlock(&pvt->lock);
- return 0;
-}
-
-/* Private structure should be locked on a call */
-static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const char *host)
-{
- struct ast_channel *ch;
- int fmt;
-
- /* Don't hold a oh323_pvt lock while we allocate a chanel */
- ast_mutex_unlock(&pvt->lock);
- ch = ast_channel_alloc(1);
- /* Update usage counter */
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- ast_mutex_lock(&pvt->lock);
- if (ch) {
- ch->tech = &oh323_tech;
- snprintf(ch->name, sizeof(ch->name), "H323/%s", host);
- ch->nativeformats = pvt->options.capability;
- if (!ch->nativeformats) {
- ch->nativeformats = global_options.capability;
- }
- pvt->nativeformats = ch->nativeformats;
- fmt = ast_best_codec(ch->nativeformats);
- ch->type = type;
- ch->fds[0] = ast_rtp_fd(pvt->rtp);
- if (state == AST_STATE_RING) {
- ch->rings = 1;
- }
- ch->writeformat = fmt;
- ch->rawwriteformat = fmt;
- ch->readformat = fmt;
- ch->rawreadformat = fmt;
- /* Allocate dsp for in-band DTMF support */
- if (pvt->options.dtmfmode & H323_DTMF_INBAND) {
- pvt->vad = ast_dsp_new();
- ast_dsp_set_features(pvt->vad, DSP_FEATURE_DTMF_DETECT);
- }
- /* Register channel functions. */
- ch->tech_pvt = pvt;
- /* Set the owner of this channel */
- pvt->owner = ch;
-
- strncpy(ch->context, pvt->context, sizeof(ch->context) - 1);
- strncpy(ch->exten, pvt->exten, sizeof(ch->exten) - 1);
- ch->priority = 1;
- if (!ast_strlen_zero(pvt->accountcode)) {
- strncpy(ch->accountcode, pvt->accountcode, sizeof(ch->accountcode) - 1);
- }
- if (pvt->amaflags) {
- ch->amaflags = pvt->amaflags;
- }
- if (!ast_strlen_zero(pvt->cid_num)) {
- ch->cid.cid_num = strdup(pvt->cid_num);
- } else if (!ast_strlen_zero(pvt->cd.call_source_e164)) {
- ch->cid.cid_num = strdup(pvt->cd.call_source_e164);
- }
- if (!ast_strlen_zero(pvt->cid_name)) {
- ch->cid.cid_name = strdup(pvt->cid_name);
- } else if (!ast_strlen_zero(pvt->cd.call_source_name)) {
- ch->cid.cid_name = strdup(pvt->cd.call_source_name);
- }
- if (!ast_strlen_zero(pvt->rdnis)) {
- ch->cid.cid_rdnis = strdup(pvt->rdnis);
- }
- if (!ast_strlen_zero(pvt->exten) && strcmp(pvt->exten, "s")) {
- ch->cid.cid_dnid = strdup(pvt->exten);
- }
- ast_setstate(ch, state);
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(ch)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ch->name);
- ast_hangup(ch);
- ch = NULL;
- }
- }
- } else {
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- }
- return ch;
-}
-
-static struct oh323_pvt *oh323_alloc(int callid)
-{
- struct oh323_pvt *pvt;
-
- pvt = (struct oh323_pvt *) malloc(sizeof(struct oh323_pvt));
- if (!pvt) {
- ast_log(LOG_ERROR, "Couldn't allocate private structure. This is bad\n");
- return NULL;
- }
- memset(pvt, 0, sizeof(struct oh323_pvt));
- pvt->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0,bindaddr.sin_addr);
- if (!pvt->rtp) {
- ast_log(LOG_WARNING, "Unable to create RTP session: %s\n", strerror(errno));
- free(pvt);
- return NULL;
- }
- ast_rtp_settos(pvt->rtp, tos);
- ast_mutex_init(&pvt->lock);
- /* Ensure the call token is allocated */
- if ((pvt->cd).call_token == NULL) {
- (pvt->cd).call_token = (char *)malloc(128);
- }
- if (!pvt->cd.call_token) {
- ast_log(LOG_ERROR, "Not enough memory to alocate call token\n");
- return NULL;
- }
- memset((char *)(pvt->cd).call_token, 0, 128);
- pvt->cd.call_reference = callid;
- memcpy(&pvt->options, &global_options, sizeof(pvt->options));
- if (pvt->options.dtmfmode & H323_DTMF_RFC2833) {
- pvt->nonCodecCapability |= AST_RTP_DTMF;
- } else {
- pvt->nonCodecCapability &= ~AST_RTP_DTMF;
- }
- strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
- pvt->newstate = pvt->newcontrol = -1;
- /* Add to interface list */
- ast_mutex_lock(&iflock);
- pvt->next = iflist;
- iflist = pvt;
- ast_mutex_unlock(&iflock);
- return pvt;
-}
-
-static struct oh323_pvt *find_call_locked(int call_reference, const char *token)
-{
- struct oh323_pvt *pvt;
-
- ast_mutex_lock(&iflock);
- pvt = iflist;
- while(pvt) {
- if (!pvt->needdestroy && ((signed int)pvt->cd.call_reference == call_reference)) {
- /* Found the call */
- if ((token != NULL) && (!strcmp(pvt->cd.call_token, token))) {
- ast_mutex_lock(&pvt->lock);
- ast_mutex_unlock(&iflock);
- return pvt;
- } else if (token == NULL) {
- ast_log(LOG_WARNING, "Call Token is NULL\n");
- ast_mutex_lock(&pvt->lock);
- ast_mutex_unlock(&iflock);
- return pvt;
- }
- }
- pvt = pvt->next;
- }
- ast_mutex_unlock(&iflock);
- return NULL;
-}
-
-static int update_state(struct oh323_pvt *pvt, int state, int signal)
-{
- if (!pvt)
- return 0;
- if (pvt->owner && !ast_mutex_trylock(&pvt->owner->lock)) {
- if (state >= 0)
- ast_setstate(pvt->owner, state);
- if (signal >= 0)
- ast_queue_control(pvt->owner, signal);
- return 1;
- }
- else {
- if (state >= 0)
- pvt->newstate = state;
- if (signal >= 0)
- pvt->newcontrol = signal;
- return 0;
- }
-}
-
-struct oh323_user *find_user(const call_details_t *cd)
-{
- struct oh323_user *u;
- char iabuf[INET_ADDRSTRLEN];
- u = userl.users;
- if (userbyalias) {
- while(u) {
- if (!strcasecmp(u->name, cd->call_source_aliases)) {
- break;
- }
- u = u->next;
- }
- } else {
- while(u) {
- if (!strcasecmp(cd->sourceIp, ast_inet_ntoa(iabuf, sizeof(iabuf), u->addr.sin_addr))) {
- break;
- }
- u = u->next;
- }
- }
- return u;
-}
-
-struct oh323_peer *find_peer(const char *peer, struct sockaddr_in *sin)
-{
- struct oh323_peer *p = NULL;
- static char iabuf[INET_ADDRSTRLEN];
-
- p = peerl.peers;
- if (peer) {
- while(p) {
- if (!strcasecmp(p->name, peer)) {
- ast_log(LOG_DEBUG, "Found peer %s by name\n", peer);
- break;
- }
- p = p->next;
- }
- } else {
- /* find by sin */
- if (sin) {
- while (p) {
- if ((!inaddrcmp(&p->addr, sin)) ||
- (p->addr.sin_addr.s_addr == sin->sin_addr.s_addr)) {
- ast_log(LOG_DEBUG, "Found peer %s/%s by addr\n", peer, ast_inet_ntoa(iabuf, sizeof(iabuf), p->addr.sin_addr));
- break;
- }
- p = p->next;
- }
- }
- }
- if (!p) {
- ast_log(LOG_DEBUG, "Could not find peer %s by name or address\n", peer);
- }
- return p;
-}
-
-static int create_addr(struct oh323_pvt *pvt, char *opeer)
-{
- struct hostent *hp;
- struct ast_hostent ahp;
- struct oh323_peer *p;
- int portno;
- int found = 0;
- char *port;
- char *hostn;
- char peer[256] = "";
-
- strncpy(peer, opeer, sizeof(peer) - 1);
- port = strchr(peer, ':');
- if (port) {
- *port = '\0';
- port++;
- }
- pvt->sa.sin_family = AF_INET;
- ast_mutex_lock(&peerl.lock);
- p = find_peer(peer, NULL);
- if (p) {
- found++;
- memcpy(&pvt->options, &p->options, sizeof(pvt->options));
- if (pvt->rtp) {
- ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", pvt->options.nat);
- ast_rtp_setnat(pvt->rtp, pvt->options.nat);
- }
- if (pvt->options.dtmfmode) {
- if (pvt->options.dtmfmode & H323_DTMF_RFC2833) {
- pvt->nonCodecCapability |= AST_RTP_DTMF;
- } else {
- pvt->nonCodecCapability &= ~AST_RTP_DTMF;
- }
- }
- if (p->addr.sin_addr.s_addr) {
- pvt->sa.sin_addr = p->addr.sin_addr;
- pvt->sa.sin_port = p->addr.sin_port;
- }
- }
- ast_mutex_unlock(&peerl.lock);
- if (!p && !found) {
- hostn = peer;
- if (port) {
- portno = atoi(port);
- } else {
- portno = h323_signalling_port;
- }
- hp = ast_gethostbyname(hostn, &ahp);
- if (hp) {
- memcpy(&pvt->options, &global_options, sizeof(pvt->options));
- memcpy(&pvt->sa.sin_addr, hp->h_addr, sizeof(pvt->sa.sin_addr));
- pvt->sa.sin_port = htons(portno);
- return 0;
- } else {
- ast_log(LOG_WARNING, "No such host: %s\n", peer);
- return -1;
- }
- } else if (!p) {
- return -1;
- } else {
- return 0;
- }
-}
-static struct ast_channel *oh323_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- struct oh323_pvt *pvt;
- struct ast_channel *tmpc = NULL;
- char *dest = (char *)data;
- char *ext, *host;
- char *h323id = NULL;
- char tmp[256], tmp1[256];
-
- ast_log(LOG_DEBUG, "type=%s, format=%d, data=%s.\n", type, format, (char *)data);
- pvt = oh323_alloc(0);
- if (!pvt) {
- ast_log(LOG_WARNING, "Unable to build pvt data for '%s'\n", (char *)data);
- return NULL;
- }
- oldformat = format;
- format &= ((AST_FORMAT_MAX_AUDIO << 1) - 1);
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", format);
- return NULL;
- }
- strncpy(tmp, dest, sizeof(tmp) - 1);
- host = strchr(tmp, '@');
- if (host) {
- *host = '\0';
- host++;
- ext = tmp;
- } else {
- host = tmp;
- ext = NULL;
- }
- strtok_r(host, "/", &(h323id));
- if (!ast_strlen_zero(h323id)) {
- h323_set_id(h323id);
- }
- if (ext) {
- strncpy(pvt->exten, ext, sizeof(pvt->exten) - 1);
- }
- ast_log(LOG_DEBUG, "Extension: %s Host: %s\n", pvt->exten, host);
- if (!usingGk) {
- if (create_addr(pvt, host)) {
- oh323_destroy(pvt);
- return NULL;
- }
- }
- else {
- memcpy(&pvt->options, &global_options, sizeof(pvt->options));
- if (pvt->rtp) {
- ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", pvt->options.nat);
- ast_rtp_setnat(pvt->rtp, pvt->options.nat);
- }
- if (pvt->options.dtmfmode) {
- if (pvt->options.dtmfmode & H323_DTMF_RFC2833) {
- pvt->nonCodecCapability |= AST_RTP_DTMF;
- } else {
- pvt->nonCodecCapability &= ~AST_RTP_DTMF;
- }
- }
- }
-
- ast_mutex_lock(&caplock);
- /* Generate unique channel identifier */
- snprintf(tmp1, sizeof(tmp1)-1, "%s-%u", host, ++unique);
- tmp1[sizeof(tmp1)-1] = '\0';
- ast_mutex_unlock(&caplock);
-
- ast_mutex_lock(&pvt->lock);
- tmpc = __oh323_new(pvt, AST_STATE_DOWN, tmp1);
- ast_mutex_unlock(&pvt->lock);
- if (!tmpc) {
- oh323_destroy(pvt);
- }
- ast_update_use_count();
- restart_monitor();
- return tmpc;
-}
-
-/** Find a call by alias */
-struct oh323_alias *find_alias(const char *source_aliases)
-{
- struct oh323_alias *a;
-
- a = aliasl.aliases;
- while(a) {
- if (!strcasecmp(a->name, source_aliases)) {
- break;
- }
- a = a->next;
- }
- return a;
-}
-
-/**
- * Callback for sending digits from H.323 up to asterisk
- *
- */
-int send_digit(unsigned call_reference, char digit, const char *token)
-{
- struct oh323_pvt *pvt;
- struct ast_frame f;
- int res;
-
- ast_log(LOG_DEBUG, "Received Digit: %c\n", digit);
- pvt = find_call_locked(call_reference, token);
- if (!pvt) {
- ast_log(LOG_ERROR, "Private structure not found in send_digit.\n");
- return -1;
- }
- memset(&f, 0, sizeof(f));
- f.frametype = AST_FRAME_DTMF;
- f.subclass = digit;
- f.datalen = 0;
- f.samples = 800;
- f.offset = 0;
- f.data = NULL;
- f.mallocd = 0;
- f.src = "SEND_DIGIT";
- res = ast_queue_frame(pvt->owner, &f);
- ast_mutex_unlock(&pvt->lock);
- return res;
-}
-
-/**
- * Callback function used to inform the H.323 stack of the local rtp ip/port details
- *
- * Returns the local RTP information
- */
-struct rtp_info *external_rtp_create(unsigned call_reference, const char * token)
-{
- struct oh323_pvt *pvt;
- struct sockaddr_in us;
- struct rtp_info *info;
-
- info = (struct rtp_info *)malloc(sizeof(struct rtp_info));
- if (!info) {
- ast_log(LOG_ERROR, "Unable to allocated info structure, this is very bad\n");
- return NULL;
- }
- pvt = find_call_locked(call_reference, token);
- if (!pvt) {
- free(info);
- ast_log(LOG_ERROR, "Unable to find call %s(%d)\n", token, call_reference);
- return NULL;
- }
- /* figure out our local RTP port and tell the H.323 stack about it */
- ast_rtp_get_us(pvt->rtp, &us);
- ast_mutex_unlock(&pvt->lock);
-
- ast_inet_ntoa(info->addr, sizeof(info->addr), us.sin_addr);
- info->port = ntohs(us.sin_port);
- if (h323debug)
- ast_log(LOG_DEBUG, "Sending RTP 'US' %s:%d\n", info->addr, info->port);
- return info;
-}
-
-/**
- * Definition taken from rtp.c for rtpPayloadType because we need it here.
- */
-struct rtpPayloadType {
- int isAstFormat; /* whether the following code is an AST_FORMAT */
- int code;
-};
-
-/**
- * Call-back function passing remote ip/port information from H.323 to asterisk
- *
- * Returns nothing
- */
-void setup_rtp_connection(unsigned call_reference, const char *remoteIp, int remotePort, const char *token, int pt)
-{
- struct oh323_pvt *pvt;
- struct sockaddr_in them;
- struct rtpPayloadType rtptype;
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Setting up RTP connection for %s\n", token);
-
- /* Find the call or allocate a private structure if call not found */
- pvt = find_call_locked(call_reference, token);
- if (!pvt) {
- ast_log(LOG_ERROR, "Something is wrong: rtp\n");
- return;
- }
- if (pvt->alreadygone) {
- ast_mutex_unlock(&pvt->lock);
- return;
- }
- rtptype = ast_rtp_lookup_pt(pvt->rtp, pt);
- pvt->nativeformats = rtptype.code;
- if (pvt->owner && !ast_mutex_trylock(&pvt->owner->lock)) {
- pvt->owner->nativeformats = pvt->nativeformats;
- ast_set_read_format(pvt->owner, pvt->owner->readformat);
- ast_set_write_format(pvt->owner, pvt->owner->writeformat);
- if (pvt->options.progress_audio)
- ast_queue_control(pvt->owner, AST_CONTROL_PROGRESS);
- ast_mutex_unlock(&pvt->owner->lock);
- }
- else {
- if (pvt->options.progress_audio)
- pvt->newcontrol = AST_CONTROL_PROGRESS;
- if (h323debug)
- ast_log(LOG_DEBUG, "RTP connection preparation for %s is pending...\n", token);
- }
-
- them.sin_family = AF_INET;
- /* only works for IPv4 */
- them.sin_addr.s_addr = inet_addr(remoteIp);
- them.sin_port = htons(remotePort);
- ast_rtp_set_peer(pvt->rtp, &them);
-
- ast_mutex_unlock(&pvt->lock);
-
- if (h323debug)
- ast_log(LOG_DEBUG, "RTP connection prepared for %s\n", token);
-
- return;
-}
-
-/**
- * Call-back function to signal asterisk that the channel has been answered
- * Returns nothing
- */
-void connection_made(unsigned call_reference, const char *token)
-{
- struct ast_channel *c = NULL;
- struct oh323_pvt *pvt;
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Call %s answered\n", token);
-
- pvt = find_call_locked(call_reference, token);
- if (!pvt) {
- ast_log(LOG_ERROR, "Something is wrong: connection\n");
- return;
- }
-
- /* Inform asterisk about remote party connected only on outgoing calls */
- if (!pvt->outgoing) {
- ast_mutex_unlock(&pvt->lock);
- return;
- }
- if (update_state(pvt, AST_STATE_UP, AST_CONTROL_ANSWER))
- ast_mutex_unlock(&pvt->owner->lock);
- ast_mutex_unlock(&pvt->lock);
- return;
-}
-
-int progress(unsigned call_reference, const char *token, int inband)
-{
- struct oh323_pvt *pvt;
-
- ast_log(LOG_DEBUG, "Received ALERT/PROGRESS message for %s tones\n", (inband ? "inband" : "self-generated"));
-
- pvt = find_call_locked(call_reference, token);
- if (!pvt) {
- ast_log(LOG_ERROR, "Private structure not found in progress.\n");
- return -1;
- }
- if (!pvt->owner) {
- ast_mutex_unlock(&pvt->lock);
- ast_log(LOG_ERROR, "No Asterisk channel associated with private structure.\n");
- return -1;
- }
- if (update_state(pvt, -1, (inband ? AST_CONTROL_PROGRESS : AST_CONTROL_RINGING)))
- ast_mutex_unlock(&pvt->owner->lock);
- ast_mutex_unlock(&pvt->lock);
-
- return 0;
-}
-
-/**
- * Call-back function for incoming calls
- *
- * Returns 1 on success
- */
-call_options_t *setup_incoming_call(call_details_t *cd)
-{
- struct oh323_pvt *pvt;
- struct oh323_user *user = NULL;
- struct oh323_alias *alias = NULL;
- char iabuf[INET_ADDRSTRLEN];
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Setting up incoming call for %s\n", cd->call_token);
-
- /* allocate the call*/
- pvt = oh323_alloc(cd->call_reference);
-
- if (!pvt) {
- ast_log(LOG_ERROR, "Unable to allocate private structure, this is bad.\n");
- return NULL;
- }
-
- /* Populate the call details in the private structure */
- memcpy(&pvt->cd, cd, sizeof(pvt->cd));
- memcpy(&pvt->options, &global_options, sizeof(pvt->options));
-
- if (h323debug) {
- ast_verbose(VERBOSE_PREFIX_3 "Setting up Call\n");
- ast_verbose(VERBOSE_PREFIX_3 "\tCall token: [%s]\n", pvt->cd.call_token);
- ast_verbose(VERBOSE_PREFIX_3 "\tCalling party name: [%s]\n", pvt->cd.call_source_name);
- ast_verbose(VERBOSE_PREFIX_3 "\tCalling party number: [%s]\n", pvt->cd.call_source_e164);
- ast_verbose(VERBOSE_PREFIX_3 "\tCalled party name: [%s]\n", pvt->cd.call_dest_alias);
- ast_verbose(VERBOSE_PREFIX_3 "\tCalled party number: [%s]\n", pvt->cd.call_dest_e164);
- }
-
- /* Decide if we are allowing Gatekeeper routed calls*/
- if ((!strcasecmp(cd->sourceIp, gatekeeper)) && (gkroute == -1) && (usingGk)) {
- if (!ast_strlen_zero(cd->call_dest_e164)) {
- strncpy(pvt->exten, cd->call_dest_e164, sizeof(pvt->exten) - 1);
- strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
- } else {
- alias = find_alias(cd->call_dest_alias);
- if (!alias) {
- ast_log(LOG_ERROR, "Call for %s rejected, alias not found\n", cd->call_dest_alias);
- return NULL;
- }
- strncpy(pvt->exten, alias->name, sizeof(pvt->exten) - 1);
- strncpy(pvt->context, alias->context, sizeof(pvt->context) - 1);
- }
- } else {
- /* Either this call is not from the Gatekeeper
- or we are not allowing gk routed calls */
- user = find_user(cd);
- if (!user) {
- if (!ast_strlen_zero(pvt->cd.call_dest_e164)) {
- strncpy(pvt->exten, cd->call_dest_e164, sizeof(pvt->exten) - 1);
- } else {
- strncpy(pvt->exten, cd->call_dest_alias, sizeof(pvt->exten) - 1);
- }
- if (ast_strlen_zero(default_context)) {
- ast_log(LOG_ERROR, "Call from '%s' rejected due to no default context\n", pvt->cd.call_source_aliases);
- return NULL;
- }
- strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
- ast_log(LOG_DEBUG, "Sending %s to context [%s]\n", cd->call_source_aliases, pvt->context);
- /* XXX: Is it really required??? */
-#if 0
- memset(&pvt->options, 0, sizeof(pvt->options));
-#endif
- } else {
- if (user->host) {
- if (strcasecmp(cd->sourceIp, ast_inet_ntoa(iabuf, sizeof(iabuf), user->addr.sin_addr))) {
- if (ast_strlen_zero(user->context)) {
- if (ast_strlen_zero(default_context)) {
- ast_log(LOG_ERROR, "Call from '%s' rejected due to non-matching IP address (%s) and no default context\n", user->name, cd->sourceIp);
- return NULL;
- }
- strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
- } else {
- strncpy(pvt->context, user->context, sizeof(pvt->context) - 1);
- }
- pvt->exten[0] = 'i';
- pvt->exten[1] = '\0';
- ast_log(LOG_ERROR, "Call from '%s' rejected due to non-matching IP address (%s)s\n", user->name, cd->sourceIp);
- return NULL; /* XXX: Hmmm... Why to setup context if we drop connection immediately??? */
- }
- }
- strncpy(pvt->context, user->context, sizeof(pvt->context) - 1);
- memcpy(&pvt->options, &user->options, sizeof(pvt->options));
- if (!ast_strlen_zero(pvt->cd.call_dest_e164)) {
- strncpy(pvt->exten, cd->call_dest_e164, sizeof(pvt->exten) - 1);
- } else {
- strncpy(pvt->exten, cd->call_dest_alias, sizeof(pvt->exten) - 1);
- }
- if (!ast_strlen_zero(user->accountcode)) {
- strncpy(pvt->accountcode, user->accountcode, sizeof(pvt->accountcode) - 1);
- }
- if (user->amaflags) {
- pvt->amaflags = user->amaflags;
- }
- }
- }
- return &pvt->options;
-}
-
-/**
- * Call-back function to start PBX when OpenH323 ready to serve incoming call
- *
- * Returns 1 on success
- */
-static int answer_call(unsigned call_reference, const char *token)
-{
- struct oh323_pvt *pvt;
- struct ast_channel *c = NULL;
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Preparing Asterisk to answer for %s\n", token);
-
- /* Find the call or allocate a private structure if call not found */
- pvt = find_call_locked(call_reference, token);
- if (!pvt) {
- ast_log(LOG_ERROR, "Something is wrong: answer_call\n");
- return 0;
- }
- /* allocate a channel and tell asterisk about it */
- c = __oh323_new(pvt, AST_STATE_RINGING, pvt->cd.call_token);
-
- /* And release when done */
- ast_mutex_unlock(&pvt->lock);
- if (!c) {
- ast_log(LOG_ERROR, "Couldn't create channel. This is bad\n");
- return 0;
- }
- return 1;
-}
-
-/**
- * Call-back function to establish an outgoing H.323 call
- *
- * Returns 1 on success
- */
-int setup_outgoing_call(call_details_t *cd)
-{
- /* Use argument here or free it immediately */
- cleanup_call_details(cd);
-
- return 1;
-}
-
-/**
- * Call-back function to signal asterisk that the channel is ringing
- * Returns nothing
- */
-void chan_ringing(unsigned call_reference, const char *token)
-{
- struct ast_channel *c = NULL;
- struct oh323_pvt *pvt;
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Ringing on %s\n", token);
-
- pvt = find_call_locked(call_reference, token);
- if (!pvt) {
- ast_log(LOG_ERROR, "Something is wrong: ringing\n");
- return;
- }
- if (!pvt->owner) {
- ast_mutex_unlock(&pvt->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- if (update_state(pvt, AST_STATE_RINGING, AST_CONTROL_RINGING))
- ast_mutex_unlock(&pvt->owner->lock);
- ast_mutex_unlock(&pvt->lock);
- return;
-}
-
-/**
- * Call-back function to cleanup communication
- * Returns nothing,
- */
-static void cleanup_connection(unsigned call_reference, const char *call_token)
-{
- struct oh323_pvt *pvt;
-
- ast_log(LOG_DEBUG, "Cleaning connection to %s\n", call_token);
-
- while (1) {
- pvt = find_call_locked(call_reference, call_token);
- if (!pvt) {
- if (h323debug)
- ast_log(LOG_DEBUG, "No connection for %s\n", call_token);
- return;
- }
- if (!pvt->owner || !ast_mutex_trylock(&pvt->owner->lock))
- break;
-#if 1
-#ifdef DEBUG_THREADS
- ast_log(LOG_NOTICE, "Avoiding H.323 destory deadlock on %s, locked at %ld/%d by %s (%s:%d)\n", call_token, pvt->owner->lock.thread, pvt->owner->lock.reentrancy, pvt->owner->lock.func, pvt->owner->lock.file, pvt->owner->lock.lineno);
-#else
- ast_log(LOG_NOTICE, "Avoiding H.323 destory deadlock on %s\n", call_token);
-#endif
-#endif
- ast_mutex_unlock(&pvt->lock);
- usleep(1);
- }
- if (pvt->rtp) {
- /* Immediately stop RTP */
- ast_rtp_destroy(pvt->rtp);
- pvt->rtp = NULL;
- }
- /* Free dsp used for in-band DTMF detection */
- if (pvt->vad) {
- ast_dsp_free(pvt->vad);
- pvt->vad = NULL;
- }
- cleanup_call_details(&pvt->cd);
- pvt->alreadygone = 1;
- /* Send hangup */
- if (pvt->owner) {
- pvt->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_queue_hangup(pvt->owner);
- ast_mutex_unlock(&pvt->owner->lock);
- }
- ast_mutex_unlock(&pvt->lock);
- if (h323debug)
- ast_log(LOG_DEBUG, "Connection to %s cleaned\n", call_token);
- return;
-}
-
-static void hangup_connection(unsigned int call_reference, const char *token, int cause)
-{
- struct oh323_pvt *pvt;
-
- ast_log(LOG_DEBUG, "Hanging up connection to %s with cause %d\n", token, cause);
-
- pvt = find_call_locked(call_reference, token);
- if (!pvt) {
- return;
- }
- if (pvt->owner && !ast_mutex_trylock(&pvt->owner->lock)) {
- pvt->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- pvt->owner->hangupcause = pvt->hangupcause = cause;
- ast_queue_hangup(pvt->owner);
- ast_mutex_unlock(&pvt->owner->lock);
- }
- else {
- pvt->needhangup = 1;
- pvt->hangupcause = cause;
- ast_log(LOG_DEBUG, "Hangup for %s is pending\n", token);
- }
- ast_mutex_unlock(&pvt->lock);
-}
-
-void set_dtmf_payload(unsigned call_reference, const char *token, int payload)
-{
- struct oh323_pvt *pvt;
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Setting DTMF payload to %d on %s\n", payload, token);
-
- pvt = find_call_locked(call_reference, token);
- if (!pvt) {
- return;
- }
- if (pvt->rtp) {
- ast_rtp_set_rtpmap_type(pvt->rtp, payload, "audio", "telephone-event");
- }
- ast_mutex_unlock(&pvt->lock);
- if (h323debug)
- ast_log(LOG_DEBUG, "DTMF payload on %s set to %d\n", token, payload);
-}
-
-static void set_local_capabilities(unsigned call_reference, const char *token)
-{
- struct oh323_pvt *pvt;
- int capability, dtmfmode;
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Setting capabilities for connection %s\n", token);
-
- pvt = find_call_locked(call_reference, token);
- if (!pvt)
- return;
- capability = pvt->options.capability;
- dtmfmode = pvt->options.dtmfmode;
- ast_mutex_unlock(&pvt->lock);
- h323_set_capabilities(token, capability, dtmfmode);
-
- if (h323debug)
- ast_log(LOG_DEBUG, "Capabilities for connection %s is set\n", token);
-}
-
-static void *do_monitor(void *data)
-{
- int res;
- int reloading;
- struct oh323_pvt *oh323 = NULL;
-
- for(;;) {
- /* Check for a reload request */
- ast_mutex_lock(&h323_reload_lock);
- reloading = h323_reloading;
- h323_reloading = 0;
- ast_mutex_unlock(&h323_reload_lock);
- if (reloading) {
- if (option_verbose > 0) {
- ast_verbose(VERBOSE_PREFIX_1 "Reloading H.323\n");
- }
- h323_do_reload();
- }
- /* Check for interfaces needing to be killed */
- ast_mutex_lock(&iflock);
-restartsearch:
- oh323 = iflist;
- while(oh323) {
- if (oh323->needdestroy) {
- __oh323_destroy(oh323);
- goto restartsearch;
- }
- oh323 = oh323->next;
- }
- ast_mutex_unlock(&iflock);
- pthread_testcancel();
- /* Wait for sched or io */
- res = ast_sched_wait(sched);
- if ((res < 0) || (res > 1000)) {
- res = 1000;
- }
- res = ast_io_wait(io, res);
- pthread_testcancel();
- ast_mutex_lock(&monlock);
- if (res >= 0) {
- ast_sched_runq(sched);
- }
- ast_mutex_unlock(&monlock);
- }
- /* Never reached */
- return NULL;
-}
-
-static int restart_monitor(void)
-{
- pthread_attr_t attr;
- /* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == AST_PTHREADT_STOP) {
- return 0;
- }
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_WARNING, "Unable to lock monitor\n");
- return -1;
- }
- if (monitor_thread == pthread_self()) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- return -1;
- }
- if (monitor_thread && (monitor_thread != AST_PTHREADT_NULL)) {
- /* Wake up the thread */
- pthread_kill(monitor_thread, SIGURG);
- } else {
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- /* Start a new monitor */
- if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- return -1;
- }
-
- }
- ast_mutex_unlock(&monlock);
- return 0;
-}
-
-static int h323_do_trace(int fd, int argc, char *argv[])
-{
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- h323_debug(1, atoi(argv[2]));
- ast_cli(fd, "H.323 trace set to level %s\n", argv[2]);
- return RESULT_SUCCESS;
-}
-
-static int h323_no_trace(int fd, int argc, char *argv[])
-{
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- h323_debug(0,0);
- ast_cli(fd, "H.323 trace disabled\n");
- return RESULT_SUCCESS;
-}
-
-static int h323_do_debug(int fd, int argc, char *argv[])
-{
- if (argc != 2) {
- return RESULT_SHOWUSAGE;
- }
- h323debug = 1;
- ast_cli(fd, "H323 debug enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int h323_no_debug(int fd, int argc, char *argv[])
-{
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- h323debug = 0;
- ast_cli(fd, "H323 Debug disabled\n");
- return RESULT_SUCCESS;
-}
-
-static int h323_gk_cycle(int fd, int argc, char *argv[])
-{
-#if 0
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- h323_gk_urq();
-
- /* Possibly register with a GK */
- if (!gatekeeper_disable) {
- if (h323_set_gk(gatekeeper_discover, gatekeeper, secret)) {
- ast_log(LOG_ERROR, "Gatekeeper registration failed.\n");
- }
- }
-#endif
- return RESULT_SUCCESS;
-}
-
-static int h323_ep_hangup(int fd, int argc, char *argv[])
-{
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- if (h323_soft_hangup(argv[2])) {
- ast_verbose(VERBOSE_PREFIX_3 "Hangup succeeded on %s\n", argv[2]);
- } else {
- ast_verbose(VERBOSE_PREFIX_3 "Hangup failed for %s\n", argv[2]);
- }
- return RESULT_SUCCESS;
-}
-
-static int h323_tokens_show(int fd, int argc, char *argv[])
-{
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- h323_show_tokens();
- return RESULT_SUCCESS;
-}
-
-static char trace_usage[] =
-"Usage: h.323 trace <level num>\n"
-" Enables H.323 stack tracing for debugging purposes\n";
-
-static char no_trace_usage[] =
-"Usage: h.323 no trace\n"
-" Disables H.323 stack tracing for debugging purposes\n";
-
-static char debug_usage[] =
-"Usage: h.323 debug\n"
-" Enables H.323 debug output\n";
-
-static char no_debug_usage[] =
-"Usage: h.323 no debug\n"
-" Disables H.323 debug output\n";
-
-static char show_codec_usage[] =
-"Usage: h.323 show codec\n"
-" Shows all enabled codecs\n";
-
-static char show_cycle_usage[] =
-"Usage: h.323 gk cycle\n"
-" Manually re-register with the Gatekeper (Currently Disabled)\n";
-
-static char show_hangup_usage[] =
-"Usage: h.323 hangup <token>\n"
-" Manually try to hang up call identified by <token>\n";
-
-static char show_tokens_usage[] =
-"Usage: h.323 show tokens\n"
-" Print out all active call tokens\n";
-
-static char h323_reload_usage[] =
-"Usage: h323 reload\n"
-" Reloads H.323 configuration from sip.conf\n";
-
-static struct ast_cli_entry cli_trace =
- { { "h.323", "trace", NULL }, h323_do_trace, "Enable H.323 Stack Tracing", trace_usage };
-static struct ast_cli_entry cli_no_trace =
- { { "h.323", "no", "trace", NULL }, h323_no_trace, "Disable H.323 Stack Tracing", no_trace_usage };
-static struct ast_cli_entry cli_debug =
- { { "h.323", "debug", NULL }, h323_do_debug, "Enable H.323 debug", debug_usage };
-static struct ast_cli_entry cli_no_debug =
- { { "h.323", "no", "debug", NULL }, h323_no_debug, "Disable H.323 debug", no_debug_usage };
-static struct ast_cli_entry cli_show_codecs =
- { { "h.323", "show", "codecs", NULL }, h323_show_codec, "Show enabled codecs", show_codec_usage };
-static struct ast_cli_entry cli_gk_cycle =
- { { "h.323", "gk", "cycle", NULL }, h323_gk_cycle, "Manually re-register with the Gatekeper", show_cycle_usage };
-static struct ast_cli_entry cli_hangup_call =
- { { "h.323", "hangup", NULL }, h323_ep_hangup, "Manually try to hang up a call", show_hangup_usage };
-static struct ast_cli_entry cli_show_tokens =
- { { "h.323", "show", "tokens", NULL }, h323_tokens_show, "Show all active call tokens", show_tokens_usage };
-
-static int update_common_options(struct ast_variable *v, struct call_options *options)
-{
- unsigned int format;
- int tmp;
-
- if (!strcasecmp(v->name, "allow")) {
- format = ast_getformatbyname(v->value);
- if (format < 1)
- ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value);
- else
- options->capability |= format;
- } else if (!strcasecmp(v->name, "disallow")) {
- format = ast_getformatbyname(v->value);
- if (format < 1)
- ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value);
- else
- options->capability &= ~format;
- } else if (!strcasecmp(v->name, "dtmfmode")) {
- if (!strcasecmp(v->value, "inband")) {
- options->dtmfmode = H323_DTMF_INBAND;
- } else if (!strcasecmp(v->value, "rfc2833")) {
- options->dtmfmode = H323_DTMF_RFC2833;
- } else {
- ast_log(LOG_WARNING, "Unknown dtmf mode '%s', using rfc2833\n", v->value);
- options->dtmfmode = H323_DTMF_RFC2833;
- }
- } else if (!strcasecmp(v->name, "dtmfcodec")) {
- tmp = atoi(v->value);
- if (tmp < 96)
- ast_log(LOG_WARNING, "Invalid global dtmfcodec value %s\n", v->value);
- else
- options->dtmfcodec = tmp;
- } else if (!strcasecmp(v->name, "bridge")) {
- options->bridge = ast_true(v->value);
- } else if (!strcasecmp(v->name, "nat")) {
- options->nat = ast_true(v->value);
- } else if (!strcasecmp(v->name, "noFastStart")) {
- options->noFastStart = ast_true(v->value);
- } else if (!strcasecmp(v->name, "noH245Tunneling")) {
- options->noH245Tunneling = ast_true(v->value);
- } else if (!strcasecmp(v->name, "noSilenceSuppression")) {
- options->noSilenceSuppression = ast_true(v->value);
- } else if (!strcasecmp(v->name, "progress_setup")) {
- tmp = atoi(v->value);
- if ((tmp != 0) && (tmp != 1) && (tmp != 3) && (tmp != 8)) {
- ast_log(LOG_WARNING, "Invalid value %d for progress_setup at line %d, assuming 0\n", tmp, v->lineno);
- tmp = 0;
- }
- options->progress_setup = tmp;
- } else if (!strcasecmp(v->name, "progress_alert")) {
- tmp = atoi(v->value);
- if ((tmp != 0) && (tmp != 8)) {
- ast_log(LOG_WARNING, "Invalud value %d for progress_alert at line %d, assuming 0\n", tmp, v->lineno);
- tmp = 0;
- }
- options->progress_alert = tmp;
- } else if (!strcasecmp(v->name, "progress_audio")) {
- options->progress_audio = ast_true(v->value);
- } else
- return 1;
-
- return 0;
-}
-
-static struct oh323_alias *build_alias(char *name, struct ast_variable *v)
-{
- struct oh323_alias *alias;
-
- alias = (struct oh323_alias *)malloc(sizeof(struct oh323_alias));
- if (alias) {
- memset(alias, 0, sizeof(struct oh323_alias));
- strncpy(alias->name, name, sizeof(alias->name) - 1);
- while (v) {
- if (!strcasecmp(v->name, "e164")) {
- strncpy(alias->e164, v->value, sizeof(alias->e164) - 1);
- } else if (!strcasecmp(v->name, "prefix")) {
- strncpy(alias->prefix, v->value, sizeof(alias->prefix) - 1);
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(alias->context, v->value, sizeof(alias->context) - 1);
- } else if (!strcasecmp(v->name, "secret")) {
- strncpy(alias->secret, v->value, sizeof(alias->secret) - 1);
- } else {
- if (strcasecmp(v->value, "h323")) {
- ast_log(LOG_WARNING, "Keyword %s does not make sense in type=h323\n", v->value);
- }
- }
- v = v->next;
- }
- }
- return alias;
-}
-
-static struct oh323_user *build_user(char *name, struct ast_variable *v)
-{
- struct oh323_user *user;
- int format;
-
- user = (struct oh323_user *)malloc(sizeof(struct oh323_user));
- if (user) {
- memset(user, 0, sizeof(struct oh323_user));
- strncpy(user->name, name, sizeof(user->name) - 1);
- memcpy(&user->options, &global_options, sizeof(user->options));
- /* Set default context */
- strncpy(user->context, default_context, sizeof(user->context) - 1);
- while(v) {
- if (!strcasecmp(v->name, "context")) {
- strncpy(user->context, v->value, sizeof(user->context) - 1);
- } else if (!update_common_options(v, &user->options)) {
- /* dummy */
- } else if (!strcasecmp(v->name, "secret")) {
- strncpy(user->secret, v->value, sizeof(user->secret) - 1);
- } else if (!strcasecmp(v->name, "callerid")) {
- strncpy(user->callerid, v->value, sizeof(user->callerid) - 1);
- } else if (!strcasecmp(v->name, "accountcode")) {
- strncpy(user->accountcode, v->value, sizeof(user->accountcode) - 1);
- } else if (!strcasecmp(v->name, "host")) {
- if (!strcasecmp(v->value, "dynamic")) {
- ast_log(LOG_ERROR, "A dynamic host on a type=user does not make any sense\n");
- free(user);
- return NULL;
- } else if (ast_get_ip(&user->addr, v->value)) {
- free(user);
- return NULL;
- }
- /* Let us know we need to use ip authentication */
- user->host = 1;
- } else if (!strcasecmp(v->name, "amaflags")) {
- format = ast_cdr_amaflags2int(v->value);
- if (format < 0) {
- ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno);
- } else {
- user->amaflags = format;
- }
- }
- v = v->next;
- }
- }
- return user;
-}
-
-static struct oh323_peer *build_peer(char *name, struct ast_variable *v)
-{
- struct oh323_peer *peer;
- struct oh323_peer *prev;
- struct ast_ha *oldha = NULL;
- int found=0;
-
- prev = NULL;
- ast_mutex_lock(&peerl.lock);
- peer = peerl.peers;
-
- while(peer) {
- if (!strcasecmp(peer->name, name)) {
- break;
- }
- prev = peer;
- peer = peer->next;
- }
-
- if (peer) {
- found++;
- /* Already in the list, remove it and it will be added back (or FREE'd) */
- if (prev) {
- prev->next = peer->next;
- } else {
- peerl.peers = peer->next;
- }
- ast_mutex_unlock(&peerl.lock);
- } else {
- ast_mutex_unlock(&peerl.lock);
- peer = (struct oh323_peer*)malloc(sizeof(struct oh323_peer));
- if (peer)
- memset(peer, 0, sizeof(struct oh323_peer));
- }
- if (peer) {
- if (!found) {
- strncpy(peer->name, name, sizeof(peer->name) - 1);
- peer->addr.sin_port = htons(h323_signalling_port);
- peer->addr.sin_family = AF_INET;
- }
- oldha = peer->ha;
- peer->ha = NULL;
- peer->addr.sin_family = AF_INET;
- memcpy(&peer->options, &global_options, sizeof(peer->options));
-
- while(v) {
- if (!update_common_options(v, &peer->options)) {
- /* dummy */
- } else if (!strcasecmp(v->name, "host")) {
- if (!strcasecmp(v->value, "dynamic")) {
- ast_log(LOG_ERROR, "Dynamic host configuration not implemented.\n");
- free(peer);
- return NULL;
- }
- if (ast_get_ip(&peer->addr, v->value)) {
- ast_log(LOG_ERROR, "Could not determine IP for %s\n", v->value);
- free(peer);
- return NULL;
- }
- } else if (!strcasecmp(v->name, "port")) {
- peer->addr.sin_port = htons(atoi(v->value));
- }
- v=v->next;
- }
- }
- return peer;
-}
-
-int reload_config(void)
-{
- int format;
- struct ast_config *cfg;
- struct ast_variable *v;
- struct oh323_peer *peer = NULL;
- struct oh323_user *user = NULL;
- struct oh323_alias *alias = NULL;
- struct ast_hostent ahp; struct hostent *hp;
- char *cat;
- char *utype;
-
- cfg = ast_config_load(config);
-
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_NOTICE, "Unable to load config %s, H.323 disabled\n", config);
- return 1;
- }
-
- /* fire up the H.323 Endpoint */
- if (!h323_end_point_exist()) {
- h323_end_point_create();
- }
- h323debug = 0;
- memset(&bindaddr, 0, sizeof(bindaddr));
- memset(&global_options, 0, sizeof(global_options));
- global_options.dtmfcodec = 101;
- global_options.dtmfmode = H323_DTMF_RFC2833;
- global_options.capability = ~0; /* All capabilities */
- global_options.bridge = 1; /* Do native bridging by default */
- v = ast_variable_browse(cfg, "general");
- while(v) {
- /* Create the interface list */
- if (!strcasecmp(v->name, "port")) {
- h323_signalling_port = (int)strtol(v->value, NULL, 10);
- } else if (!strcasecmp(v->name, "bindaddr")) {
- if (!(hp = ast_gethostbyname(v->value, &ahp))) {
- ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
- } else {
- memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
- }
- } else if (!strcasecmp(v->name, "tos")) {
- if (sscanf(v->value, "%d", &format)) {
- tos = format & 0xff;
- } else if (!strcasecmp(v->value, "lowdelay")) {
- tos = IPTOS_LOWDELAY;
- } else if (!strcasecmp(v->value, "throughput")) {
- tos = IPTOS_THROUGHPUT;
- } else if (!strcasecmp(v->value, "reliability")) {
- tos = IPTOS_RELIABILITY;
- } else if (!strcasecmp(v->value, "mincost")) {
- tos = IPTOS_MINCOST;
- } else if (!strcasecmp(v->value, "none")) {
- tos = 0;
- } else {
- ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
- }
- } else if (!strcasecmp(v->name, "gatekeeper")) {
- if (!strcasecmp(v->value, "DISABLE")) {
- gatekeeper_disable = 1;
- usingGk = 0;
- } else if (!strcasecmp(v->value, "DISCOVER")) {
- gatekeeper_disable = 0;
- gatekeeper_discover = 1;
- usingGk = 1;
- } else {
- gatekeeper_disable = 0;
- usingGk = 1;
- strncpy(gatekeeper, v->value, sizeof(gatekeeper) - 1);
- }
- } else if (!strcasecmp(v->name, "secret")) {
- strncpy(secret, v->value, sizeof(secret) - 1);
- } else if (!strcasecmp(v->name, "AllowGKRouted")) {
- gkroute = ast_true(v->value);
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(default_context, v->value, sizeof(default_context) - 1);
- ast_verbose(VERBOSE_PREFIX_2 "Setting default context to %s\n", default_context);
- } else if (!strcasecmp(v->name, "UserByAlias")) {
- userbyalias = ast_true(v->value);
- } else if (!update_common_options(v, &global_options)) {
- /* dummy */
- }
- v = v->next;
- }
-
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (strcasecmp(cat, "general")) {
- utype = ast_variable_retrieve(cfg, cat, "type");
- if (utype) {
- if (!strcasecmp(utype, "user")) {
- user = build_user(cat, ast_variable_browse(cfg, cat));
- if (user) {
- ast_mutex_lock(&userl.lock);
- user->next = userl.users;
- userl.users = user;
- ast_mutex_unlock(&userl.lock);
- }
- } else if (!strcasecmp(utype, "peer")) {
- peer = build_peer(cat, ast_variable_browse(cfg, cat));
- if (peer) {
- ast_mutex_lock(&peerl.lock);
- peer->next = peerl.peers;
- peerl.peers = peer;
- ast_mutex_unlock(&peerl.lock);
- }
- } else if (!strcasecmp(utype, "friend")) {
- user = build_user(cat, ast_variable_browse(cfg, cat));
- peer = build_peer(cat, ast_variable_browse(cfg, cat));
- if (user) {
- ast_mutex_lock(&userl.lock);
- user->next = userl.users;
- userl.users = user;
- ast_mutex_unlock(&userl.lock);
- }
- if (peer) {
- ast_mutex_lock(&peerl.lock);
- peer->next = peerl.peers;
- peerl.peers = peer;
- ast_mutex_unlock(&peerl.lock);
- }
- } else if (!strcasecmp(utype, "h323") || !strcasecmp(utype, "alias")) {
- alias = build_alias(cat, ast_variable_browse(cfg, cat));
- if (alias) {
- ast_mutex_lock(&aliasl.lock);
- alias->next = aliasl.aliases;
- aliasl.aliases = alias;
- ast_mutex_unlock(&aliasl.lock);
- }
- } else {
- ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, config);
- }
- } else {
- ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat);
- }
- }
- cat = ast_category_browse(cfg, cat);
- }
- ast_config_destroy(cfg);
-
- /* Register our H.323 aliases if any*/
- while (alias) {
- if (h323_set_alias(alias)) {
- ast_log(LOG_ERROR, "Alias %s rejected by endpoint\n", alias->name);
- return -1;
- }
- alias = alias->next;
- }
-
- return 0;
-}
-
-void delete_users(void)
-{
- struct oh323_user *user, *userlast;
- struct oh323_peer *peer;
-
- /* Delete all users */
- ast_mutex_lock(&userl.lock);
- for (user=userl.users;user;) {
- userlast = user;
- user=user->next;
- free(userlast);
- }
- userl.users=NULL;
- ast_mutex_unlock(&userl.lock);
- ast_mutex_lock(&peerl.lock);
- for (peer=peerl.peers;peer;) {
- /* Assume all will be deleted, and we'll find out for sure later */
- peer->delme = 1;
- peer = peer->next;
- }
- ast_mutex_unlock(&peerl.lock);
-}
-
-void delete_aliases(void)
-{
- struct oh323_alias *alias, *aliaslast;
-
- /* Delete all users */
- ast_mutex_lock(&aliasl.lock);
- for (alias=aliasl.aliases;alias;) {
- aliaslast = alias;
- alias=alias->next;
- free(aliaslast);
- }
- aliasl.aliases=NULL;
- ast_mutex_unlock(&aliasl.lock);
-}
-
-void prune_peers(void)
-{
- /* Prune peers who still are supposed to be deleted */
- struct oh323_peer *peer, *peerlast, *peernext;
- ast_mutex_lock(&peerl.lock);
- peerlast = NULL;
- for (peer=peerl.peers;peer;) {
- peernext = peer->next;
- if (peer->delme) {
- free(peer);
- if (peerlast) {
- peerlast->next = peernext;
- } else {
- peerl.peers = peernext;
- }
- } else {
- peerlast = peer;
- }
- peer = peernext;
- }
- ast_mutex_unlock(&peerl.lock);
-}
-
-static int h323_reload(int fd, int argc, char *argv[])
-{
- ast_mutex_lock(&h323_reload_lock);
- if (h323_reloading) {
- ast_verbose("Previous H.323 reload not yet done\n");
- } else {
- h323_reloading = 1;
- }
- ast_mutex_unlock(&h323_reload_lock);
- restart_monitor();
- return 0;
-}
-
-static int h323_do_reload(void)
-{
- delete_users();
- delete_aliases();
- prune_peers();
- reload_config();
- restart_monitor();
- return 0;
-}
-
-int reload(void)
-{
- return h323_reload(0, 0, NULL);
-}
-
-static struct ast_cli_entry cli_h323_reload =
- { { "h.323", "reload", NULL }, h323_reload, "Reload H.323 configuration", h323_reload_usage };
-
-static struct ast_rtp *oh323_get_rtp_peer(struct ast_channel *chan)
-{
- struct oh323_pvt *pvt;
- pvt = (struct oh323_pvt *) chan->tech_pvt;
- if (pvt && pvt->rtp && pvt->options.bridge) {
- return pvt->rtp;
- }
- return NULL;
-}
-
-static struct ast_rtp *oh323_get_vrtp_peer(struct ast_channel *chan)
-{
- return NULL;
-}
-
-static char *convertcap(int cap)
-{
- switch (cap) {
- case AST_FORMAT_G723_1:
- return "G.723";
- case AST_FORMAT_GSM:
- return "GSM";
- case AST_FORMAT_ULAW:
- return "ULAW";
- case AST_FORMAT_ALAW:
- return "ALAW";
- case AST_FORMAT_ADPCM:
- return "G.728";
- case AST_FORMAT_G729A:
- return "G.729";
- case AST_FORMAT_SPEEX:
- return "SPEEX";
- case AST_FORMAT_ILBC:
- return "ILBC";
- default:
- ast_log(LOG_NOTICE, "Don't know how to deal with mode %d\n", cap);
- return NULL;
- }
-}
-
-static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs)
-{
- /* XXX Deal with Video */
- struct oh323_pvt *pvt;
- struct sockaddr_in them;
- struct sockaddr_in us;
- char *mode;
- char iabuf[INET_ADDRSTRLEN];
-
- if (!rtp) {
- return 0;
- }
-
- mode = convertcap(chan->writeformat);
- pvt = (struct oh323_pvt *) chan->tech_pvt;
- if (!pvt) {
- ast_log(LOG_ERROR, "No Private Structure, this is bad\n");
- return -1;
- }
- ast_rtp_get_peer(rtp, &them);
- ast_rtp_get_us(rtp, &us);
- h323_native_bridge(pvt->cd.call_token, ast_inet_ntoa(iabuf, sizeof(iabuf), them.sin_addr), mode);
- return 0;
-}
-
-static struct ast_rtp_protocol oh323_rtp = {
- .type = type,
- .get_rtp_info = oh323_get_rtp_peer,
- .get_vrtp_info = oh323_get_vrtp_peer,
- .set_rtp_peer= oh323_set_rtp_peer,
-};
-
-int load_module()
-{
- int res;
- ast_mutex_init(&userl.lock);
- ast_mutex_init(&peerl.lock);
- ast_mutex_init(&aliasl.lock);
- sched = sched_context_create();
- if (!sched) {
- ast_log(LOG_WARNING, "Unable to create schedule context\n");
- }
- io = io_context_create();
- if (!io) {
- ast_log(LOG_WARNING, "Unable to create I/O context\n");
- }
- res = reload_config();
- if (res) {
- return 0;
- } else {
- /* Make sure we can register our channel type */
- if (ast_channel_register(&oh323_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- h323_end_process();
- return -1;
- }
- ast_cli_register(&cli_debug);
- ast_cli_register(&cli_no_debug);
- ast_cli_register(&cli_trace);
- ast_cli_register(&cli_no_trace);
- ast_cli_register(&cli_show_codecs);
- ast_cli_register(&cli_gk_cycle);
- ast_cli_register(&cli_hangup_call);
- ast_cli_register(&cli_show_tokens);
- ast_cli_register(&cli_h323_reload);
-
- ast_rtp_proto_register(&oh323_rtp);
-
- /* Register our callback functions */
- h323_callback_register(setup_incoming_call,
- setup_outgoing_call,
- external_rtp_create,
- setup_rtp_connection,
- cleanup_connection,
- chan_ringing,
- connection_made,
- send_digit,
- answer_call,
- progress,
- set_dtmf_payload,
- hangup_connection,
- set_local_capabilities);
- /* start the h.323 listener */
- if (h323_start_listener(h323_signalling_port, bindaddr)) {
- ast_log(LOG_ERROR, "Unable to create H323 listener.\n");
- return -1;
- }
- /* Possibly register with a GK */
- if (!gatekeeper_disable) {
- if (h323_set_gk(gatekeeper_discover, gatekeeper, secret)) {
- ast_log(LOG_ERROR, "Gatekeeper registration failed.\n");
- return 0;
- }
- }
- /* And start the monitor for the first time */
- restart_monitor();
- }
- return res;
-}
-
-int unload_module()
-{
- struct oh323_pvt *p, *pl;
-
- /* unregister commands */
- ast_cli_unregister(&cli_debug);
- ast_cli_unregister(&cli_no_debug);
- ast_cli_unregister(&cli_trace);
- ast_cli_unregister(&cli_no_trace);
- ast_cli_unregister(&cli_show_codecs);
- ast_cli_unregister(&cli_gk_cycle);
- ast_cli_unregister(&cli_hangup_call);
- ast_cli_unregister(&cli_show_tokens);
- ast_cli_unregister(&cli_h323_reload);
- ast_rtp_proto_unregister(&oh323_rtp);
- ast_channel_unregister(&oh323_tech);
-
- if (!ast_mutex_lock(&iflock)) {
- /* hangup all interfaces if they have an owner */
- p = iflist;
- while(p) {
- if (p->owner) {
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- }
- p = p->next;
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- return -1;
- }
- if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
- /* this causes a seg, anyone know why? */
- pthread_cancel(monitor_thread);
- pthread_kill(monitor_thread, SIGURG);
- pthread_join(monitor_thread, NULL);
- }
- monitor_thread = AST_PTHREADT_STOP;
- ast_mutex_unlock(&monlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- if (!ast_mutex_lock(&iflock)) {
- /* destroy all the interfaces and free their memory */
- p = iflist;
- while(p) {
- pl = p;
- p = p->next;
- /* free associated memory */
- ast_mutex_destroy(&pl->lock);
- free(pl);
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- return -1;
- }
- h323_gk_urq();
- h323_end_process();
- io_context_destroy(io);
- sched_context_destroy(sched);
- delete_users();
- delete_aliases();
- prune_peers();
- ast_mutex_destroy(&aliasl.lock);
- ast_mutex_destroy(&userl.lock);
- ast_mutex_destroy(&peerl.lock);
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_iax2.c b/1.2-netsec/channels/chan_iax2.c
deleted file mode 100644
index ec2dec5da..000000000
--- a/1.2-netsec/channels/chan_iax2.c
+++ /dev/null
@@ -1,9659 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Implementation of Inter-Asterisk eXchange Version 2
- *
- * \par See also
- * \arg \ref Config_iax
- *
- * \ingroup channel_drivers
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <dirent.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <sys/time.h>
-#include <sys/signal.h>
-#include <signal.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <netdb.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <regex.h>
-#ifdef IAX_TRUNKING
-#include <sys/ioctl.h>
-#ifdef __linux__
-#include <linux/zaptel.h>
-#else
-#include <zaptel.h>
-#endif /* __linux__ */
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/frame.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/cli.h"
-#include "asterisk/translate.h"
-#include "asterisk/md5.h"
-#include "asterisk/cdr.h"
-#include "asterisk/crypto.h"
-#include "asterisk/acl.h"
-#include "asterisk/manager.h"
-#include "asterisk/callerid.h"
-#include "asterisk/app.h"
-#include "asterisk/astdb.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/features.h"
-#include "asterisk/utils.h"
-#include "asterisk/causes.h"
-#include "asterisk/localtime.h"
-#include "asterisk/aes.h"
-#include "asterisk/dnsmgr.h"
-#include "asterisk/devicestate.h"
-#include "asterisk/netsock.h"
-
-#include "iax2.h"
-#include "iax2-parser.h"
-#include "iax2-provision.h"
-
-/* Define NEWJB to use the new channel independent jitterbuffer,
- * otherwise, use the old jitterbuffer */
-#define NEWJB
-
-#ifdef NEWJB
-#include "../jitterbuf.h"
-#endif
-
-#ifndef IPTOS_MINCOST
-#define IPTOS_MINCOST 0x02
-#endif
-
-#ifdef SO_NO_CHECK
-static int nochecksums = 0;
-#endif
-
-/*
- * Uncomment to try experimental IAX bridge optimization,
- * designed to reduce latency when IAX calls cannot
- * be trasnferred -- obsolete
- */
-
-/* #define BRIDGE_OPTIMIZATION */
-
-
-#define PTR_TO_CALLNO(a) ((unsigned short)(unsigned long)(a))
-#define CALLNO_TO_PTR(a) ((void *)(unsigned long)(a))
-
-#define DEFAULT_RETRY_TIME 1000
-#define MEMORY_SIZE 100
-#define DEFAULT_DROP 3
-/* Flag to use with trunk calls, keeping these calls high up. It halves our effective use
- but keeps the division between trunked and non-trunked better. */
-#define TRUNK_CALL_START 0x4000
-
-#define DEBUG_SUPPORT
-
-#define MIN_REUSE_TIME 60 /* Don't reuse a call number within 60 seconds */
-
-/* Sample over last 100 units to determine historic jitter */
-#define GAMMA (0.01)
-
-static struct ast_codec_pref prefs;
-
-static const char desc[] = "Inter Asterisk eXchange (Ver 2)";
-static const char tdesc[] = "Inter Asterisk eXchange Driver (Ver 2)";
-static const char channeltype[] = "IAX2";
-
-static char context[80] = "default";
-
-static char language[MAX_LANGUAGE] = "";
-static char regcontext[AST_MAX_CONTEXT] = "";
-
-static int max_retries = 4;
-static int ping_time = 20;
-static int lagrq_time = 10;
-static int maxtrunkcall = TRUNK_CALL_START;
-static int maxnontrunkcall = 1;
-static int maxjitterbuffer=1000;
-#ifdef NEWJB
-static int resyncthreshold=1000;
-static int maxjitterinterps=10;
-#endif
-static int jittershrinkrate=2;
-static int trunkfreq = 20;
-static int authdebug = 1;
-static int autokill = 0;
-static int iaxcompat = 0;
-
-static int iaxdefaultdpcache=10 * 60; /* Cache dialplan entries for 10 minutes by default */
-
-static int iaxdefaulttimeout = 5; /* Default to wait no more than 5 seconds for a reply to come back */
-
-static int tos = 0;
-
-static int min_reg_expire;
-static int max_reg_expire;
-
-static int timingfd = -1; /* Timing file descriptor */
-
-static struct ast_netsock_list *netsock;
-static int defaultsockfd = -1;
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-int (*iax2_regfunk)(char *username, int onoff) = NULL;
-
-/* Ethernet, etc */
-#define IAX_CAPABILITY_FULLBANDWIDTH 0xFFFF
-/* T1, maybe ISDN */
-#define IAX_CAPABILITY_MEDBANDWIDTH (IAX_CAPABILITY_FULLBANDWIDTH & \
- ~AST_FORMAT_SLINEAR & \
- ~AST_FORMAT_ULAW & \
- ~AST_FORMAT_ALAW)
-/* A modem */
-#define IAX_CAPABILITY_LOWBANDWIDTH (IAX_CAPABILITY_MEDBANDWIDTH & \
- ~AST_FORMAT_G726 & \
- ~AST_FORMAT_ADPCM)
-
-#define IAX_CAPABILITY_LOWFREE (IAX_CAPABILITY_LOWBANDWIDTH & \
- ~AST_FORMAT_G723_1)
-
-
-#define DEFAULT_MAXMS 2000 /* Must be faster than 2 seconds by default */
-#define DEFAULT_FREQ_OK 60 * 1000 /* How often to check for the host to be up */
-#define DEFAULT_FREQ_NOTOK 10 * 1000 /* How often to check, if the host is down... */
-
-static struct io_context *io;
-static struct sched_context *sched;
-
-static int iax2_capability = IAX_CAPABILITY_FULLBANDWIDTH;
-
-static int iax2_dropcount = DEFAULT_DROP;
-
-static int iaxdebug = 0;
-
-static int iaxtrunkdebug = 0;
-
-static int test_losspct = 0;
-#ifdef IAXTESTS
-static int test_late = 0;
-static int test_resync = 0;
-static int test_jit = 0;
-static int test_jitpct = 0;
-#endif /* IAXTESTS */
-
-static char accountcode[AST_MAX_ACCOUNT_CODE];
-static int amaflags = 0;
-static int delayreject = 0;
-static int iax2_encryption = 0;
-
-static struct ast_flags globalflags = { 0 };
-
-static pthread_t netthreadid = AST_PTHREADT_NULL;
-
-enum {
- IAX_STATE_STARTED = (1 << 0),
- IAX_STATE_AUTHENTICATED = (1 << 1),
- IAX_STATE_TBD = (1 << 2)
-} iax2_state;
-
-struct iax2_context {
- char context[AST_MAX_CONTEXT];
- struct iax2_context *next;
-};
-
-enum {
- IAX_HASCALLERID = (1 << 0), /*!< CallerID has been specified */
- IAX_DELME = (1 << 1), /*!< Needs to be deleted */
- IAX_TEMPONLY = (1 << 2), /*!< Temporary (realtime) */
- IAX_TRUNK = (1 << 3), /*!< Treat as a trunk */
- IAX_NOTRANSFER = (1 << 4), /*!< Don't native bridge */
- IAX_USEJITTERBUF = (1 << 5), /*!< Use jitter buffer */
- IAX_DYNAMIC = (1 << 6), /*!< dynamic peer */
- IAX_SENDANI = (1 << 7), /*!< Send ANI along with CallerID */
- IAX_MESSAGEDETAIL = (1 << 8), /*!< Show exact numbers */
- IAX_ALREADYGONE = (1 << 9), /*!< Already disconnected */
- IAX_PROVISION = (1 << 10), /*!< This is a provisioning request */
- IAX_QUELCH = (1 << 11), /*!< Whether or not we quelch audio */
- IAX_ENCRYPTED = (1 << 12), /*!< Whether we should assume encrypted tx/rx */
- IAX_KEYPOPULATED = (1 << 13), /*!< Whether we have a key populated */
- IAX_CODEC_USER_FIRST = (1 << 14), /*!< are we willing to let the other guy choose the codec? */
- IAX_CODEC_NOPREFS = (1 << 15), /*!< Force old behaviour by turning off prefs */
- IAX_CODEC_NOCAP = (1 << 16), /*!< only consider requested format and ignore capabilities*/
- IAX_RTCACHEFRIENDS = (1 << 17), /*!< let realtime stay till your reload */
- IAX_RTUPDATE = (1 << 18), /*!< Send a realtime update */
- IAX_RTAUTOCLEAR = (1 << 19), /*!< erase me on expire */
- IAX_FORCEJITTERBUF = (1 << 20), /*!< Force jitterbuffer, even when bridged to a channel that can take jitter */
- IAX_RTIGNOREREGEXPIRE = (1 << 21), /*!< When using realtime, ignore registration expiration */
- IAX_TRUNKTIMESTAMPS = (1 << 22) /*!< Send trunk timestamps */
-} iax2_flags;
-
-static int global_rtautoclear = 120;
-
-static int reload_config(void);
-static int iax2_reload(int fd, int argc, char *argv[]);
-
-
-struct iax2_user {
- char name[80];
- char secret[80];
- char dbsecret[80];
- int authmethods;
- int encmethods;
- char accountcode[AST_MAX_ACCOUNT_CODE];
- char inkeys[80]; /*!< Key(s) this user can use to authenticate to us */
- char language[MAX_LANGUAGE];
- int amaflags;
- unsigned int flags;
- int capability;
- char cid_num[AST_MAX_EXTENSION];
- char cid_name[AST_MAX_EXTENSION];
- struct ast_codec_pref prefs;
- struct ast_ha *ha;
- struct iax2_context *contexts;
- struct iax2_user *next;
- struct ast_variable *vars;
-};
-
-struct iax2_peer {
- char name[80];
- char username[80];
- char secret[80];
- char dbsecret[80];
- char outkey[80]; /*!< What key we use to talk to this peer */
- char context[AST_MAX_CONTEXT]; /*!< For transfers only */
- char regexten[AST_MAX_EXTENSION]; /*!< Extension to register (if regcontext is used) */
- char peercontext[AST_MAX_EXTENSION]; /*!< Context to pass to peer */
- char mailbox[AST_MAX_EXTENSION]; /*!< Mailbox */
- struct ast_codec_pref prefs;
- struct ast_dnsmgr_entry *dnsmgr; /*!< DNS refresh manager */
- struct sockaddr_in addr;
- int formats;
- int sockfd; /*!< Socket to use for transmission */
- struct in_addr mask;
- unsigned int flags;
-
- /* Dynamic Registration fields */
- struct sockaddr_in defaddr; /*!< Default address if there is one */
- int authmethods; /*!< Authentication methods (IAX_AUTH_*) */
- int encmethods; /*!< Encryption methods (IAX_ENCRYPT_*) */
- char inkeys[80]; /*!< Key(s) this peer can use to authenticate to us */
-
- /* Suggested caller id if registering */
- char cid_num[AST_MAX_EXTENSION]; /*!< Default context (for transfer really) */
- char cid_name[AST_MAX_EXTENSION]; /*!< Default context (for transfer really) */
-
- int expire; /*!< Schedule entry for expiry */
- int expiry; /*!< How soon to expire */
- int capability; /*!< Capability */
- char zonetag[80]; /*!< Time Zone */
-
- /* Qualification */
- int callno; /*!< Call number of POKE request */
- int pokeexpire; /*!< When to expire poke */
- int lastms; /*!< How long last response took (in ms), or -1 for no response */
- int maxms; /*!< Max ms we will accept for the host to be up, 0 to not monitor */
-
- int pokefreqok; /*!< How often to check if the host is up */
- int pokefreqnotok; /*!< How often to check when the host has been determined to be down */
- int historicms; /*!< How long recent average responses took */
- int smoothing; /*!< Sample over how many units to determine historic ms */
-
- struct ast_ha *ha;
- struct iax2_peer *next;
-};
-
-#define IAX2_TRUNK_PREFACE (sizeof(struct iax_frame) + sizeof(struct ast_iax2_meta_hdr) + sizeof(struct ast_iax2_meta_trunk_hdr))
-
-static struct iax2_trunk_peer {
- ast_mutex_t lock;
- int sockfd;
- struct sockaddr_in addr;
- struct timeval txtrunktime; /*!< Transmit trunktime */
- struct timeval rxtrunktime; /*!< Receive trunktime */
- struct timeval lasttxtime; /*!< Last transmitted trunktime */
- struct timeval trunkact; /*!< Last trunk activity */
- unsigned int lastsent; /*!< Last sent time */
- /* Trunk data and length */
- unsigned char *trunkdata;
- unsigned int trunkdatalen;
- unsigned int trunkdataalloc;
- struct iax2_trunk_peer *next;
- int trunkerror;
- int calls;
-} *tpeers = NULL;
-
-AST_MUTEX_DEFINE_STATIC(tpeerlock);
-
-struct iax_firmware {
- struct iax_firmware *next;
- int fd;
- int mmaplen;
- int dead;
- struct ast_iax2_firmware_header *fwh;
- unsigned char *buf;
-};
-
-enum iax_reg_state {
- REG_STATE_UNREGISTERED = 0,
- REG_STATE_REGSENT,
- REG_STATE_AUTHSENT,
- REG_STATE_REGISTERED,
- REG_STATE_REJECTED,
- REG_STATE_TIMEOUT,
- REG_STATE_NOAUTH
-};
-
-enum iax_transfer_state {
- TRANSFER_NONE = 0,
- TRANSFER_BEGIN,
- TRANSFER_READY,
- TRANSFER_RELEASED,
- TRANSFER_PASSTHROUGH
-};
-
-struct iax2_registry {
- struct sockaddr_in addr; /*!< Who we connect to for registration purposes */
- char username[80];
- char secret[80]; /*!< Password or key name in []'s */
- char random[80];
- int expire; /*!< Sched ID of expiration */
- int refresh; /*!< How often to refresh */
- enum iax_reg_state regstate;
- int messages; /*!< Message count */
- int callno; /*!< Associated call number if applicable */
- struct sockaddr_in us; /*!< Who the server thinks we are */
- struct iax2_registry *next;
-};
-
-static struct iax2_registry *registrations;
-
-/* Don't retry more frequently than every 10 ms, or less frequently than every 5 seconds */
-#define MIN_RETRY_TIME 100
-#define MAX_RETRY_TIME 10000
-
-#define MAX_JITTER_BUFFER 50
-#define MIN_JITTER_BUFFER 10
-
-#define DEFAULT_TRUNKDATA 640 * 10 /*!< 40ms, uncompressed linear * 10 channels */
-#define MAX_TRUNKDATA 640 * 200 /*!< 40ms, uncompressed linear * 200 channels */
-
-#define MAX_TIMESTAMP_SKEW 160 /*!< maximum difference between actual and predicted ts for sending */
-
-/* If consecutive voice frame timestamps jump by more than this many milliseconds, then jitter buffer will resync */
-#define TS_GAP_FOR_JB_RESYNC 5000
-
-/* If we have more than this much excess real jitter buffer, shrink it. */
-static int max_jitter_buffer = MAX_JITTER_BUFFER;
-/* If we have less than this much excess real jitter buffer, enlarge it. */
-static int min_jitter_buffer = MIN_JITTER_BUFFER;
-
-struct iax_rr {
- int jitter;
- int losspct;
- int losscnt;
- int packets;
- int delay;
- int dropped;
- int ooo;
-};
-
-struct chan_iax2_pvt {
- /*! Socket to send/receive on for this call */
- int sockfd;
- /*! Last received voice format */
- int voiceformat;
- /*! Last received video format */
- int videoformat;
- /*! Last sent voice format */
- int svoiceformat;
- /*! Last sent video format */
- int svideoformat;
- /*! What we are capable of sending */
- int capability;
- /*! Last received timestamp */
- unsigned int last;
- /*! Last sent timestamp - never send the same timestamp twice in a single call */
- unsigned int lastsent;
- /*! Next outgoing timestamp if everything is good */
- unsigned int nextpred;
- /*! True if the last voice we transmitted was not silence/CNG */
- int notsilenttx;
- /*! Ping time */
- unsigned int pingtime;
- /*! Max time for initial response */
- int maxtime;
- /*! Peer Address */
- struct sockaddr_in addr;
- struct ast_codec_pref prefs;
- /*! Our call number */
- unsigned short callno;
- /*! Peer callno */
- unsigned short peercallno;
- /*! Peer selected format */
- int peerformat;
- /*! Peer capability */
- int peercapability;
- /*! timeval that we base our transmission on */
- struct timeval offset;
- /*! timeval that we base our delivery on */
- struct timeval rxcore;
-#ifdef NEWJB
- /*! The jitterbuffer */
- jitterbuf *jb;
- /*! active jb read scheduler id */
- int jbid;
-#else
- /*! Historical delivery time */
- int history[MEMORY_SIZE];
- /*! Current base jitterbuffer */
- int jitterbuffer;
- /*! Current jitter measure */
- int jitter;
- /*! Historic jitter value */
- int historicjitter;
-#endif
- /*! LAG */
- int lag;
- /*! Error, as discovered by the manager */
- int error;
- /*! Owner if we have one */
- struct ast_channel *owner;
- /*! What's our state? */
- struct ast_flags state;
- /*! Expiry (optional) */
- int expiry;
- /*! Next outgoing sequence number */
- unsigned char oseqno;
- /*! Next sequence number they have not yet acknowledged */
- unsigned char rseqno;
- /*! Next incoming sequence number */
- unsigned char iseqno;
- /*! Last incoming sequence number we have acknowledged */
- unsigned char aseqno;
- /*! Peer name */
- char peer[80];
- /*! Default Context */
- char context[80];
- /*! Caller ID if available */
- char cid_num[80];
- char cid_name[80];
- /*! Hidden Caller ID (i.e. ANI) if appropriate */
- char ani[80];
- /*! DNID */
- char dnid[80];
- /*! Requested Extension */
- char exten[AST_MAX_EXTENSION];
- /*! Expected Username */
- char username[80];
- /*! Expected Secret */
- char secret[80];
- /*! permitted authentication methods */
- int authmethods;
- /*! permitted encryption methods */
- int encmethods;
- /*! MD5 challenge */
- char challenge[10];
- /*! Public keys permitted keys for incoming authentication */
- char inkeys[80];
- /*! Private key for outgoing authentication */
- char outkey[80];
- /*! Encryption AES-128 Key */
- aes_encrypt_ctx ecx;
- /*! Decryption AES-128 Key */
- aes_decrypt_ctx dcx;
- /*! 32 bytes of semi-random data */
- unsigned char semirand[32];
- /*! Preferred language */
- char language[MAX_LANGUAGE];
- /*! Hostname/peername for naming purposes */
- char host[80];
- /*! Associated registry */
- struct iax2_registry *reg;
- /*! Associated peer for poking */
- struct iax2_peer *peerpoke;
- /*! IAX_ flags */
- unsigned int flags;
-
- /*! Transferring status */
- enum iax_transfer_state transferring;
- /*! Transfer identifier */
- int transferid;
- /*! Who we are IAX transfering to */
- struct sockaddr_in transfer;
- /*! What's the new call number for the transfer */
- unsigned short transfercallno;
- /*! Transfer decrypt AES-128 Key */
- aes_encrypt_ctx tdcx;
-
- /*! Status of knowledge of peer ADSI capability */
- int peeradsicpe;
-
- /*! Who we are bridged to */
- unsigned short bridgecallno;
- unsigned int bridgesfmt;
- struct ast_trans_pvt *bridgetrans;
-
- int pingid; /*!< Transmit PING request */
- int lagid; /*!< Retransmit lag request */
- int autoid; /*!< Auto hangup for Dialplan requestor */
- int authid; /*!< Authentication rejection ID */
- int authfail; /*!< Reason to report failure */
- int initid; /*!< Initial peer auto-congest ID (based on qualified peers) */
- int calling_ton;
- int calling_tns;
- int calling_pres;
- char dproot[AST_MAX_EXTENSION];
- char accountcode[AST_MAX_ACCOUNT_CODE];
- int amaflags;
- struct iax2_dpcache *dpentries;
- struct ast_variable *vars;
- /*! last received remote rr */
- struct iax_rr remote_rr;
- /*! Current base time: (just for stats) */
- int min;
- /*! Dropped frame count: (just for stats) */
- int frames_dropped;
- /*! received frame count: (just for stats) */
- int frames_received;
-};
-
-static struct ast_iax2_queue {
- struct iax_frame *head;
- struct iax_frame *tail;
- int count;
- ast_mutex_t lock;
-} iaxq;
-
-static struct ast_user_list {
- struct iax2_user *users;
- ast_mutex_t lock;
-} userl;
-
-static struct ast_peer_list {
- struct iax2_peer *peers;
- ast_mutex_t lock;
-} peerl;
-
-static struct ast_firmware_list {
- struct iax_firmware *wares;
- ast_mutex_t lock;
-} waresl;
-
-/*! Extension exists */
-#define CACHE_FLAG_EXISTS (1 << 0)
-/*! Extension is nonexistent */
-#define CACHE_FLAG_NONEXISTENT (1 << 1)
-/*! Extension can exist */
-#define CACHE_FLAG_CANEXIST (1 << 2)
-/*! Waiting to hear back response */
-#define CACHE_FLAG_PENDING (1 << 3)
-/*! Timed out */
-#define CACHE_FLAG_TIMEOUT (1 << 4)
-/*! Request transmitted */
-#define CACHE_FLAG_TRANSMITTED (1 << 5)
-/*! Timeout */
-#define CACHE_FLAG_UNKNOWN (1 << 6)
-/*! Matchmore */
-#define CACHE_FLAG_MATCHMORE (1 << 7)
-
-static struct iax2_dpcache {
- char peercontext[AST_MAX_CONTEXT];
- char exten[AST_MAX_EXTENSION];
- struct timeval orig;
- struct timeval expiry;
- int flags;
- unsigned short callno;
- int waiters[256];
- struct iax2_dpcache *next;
- struct iax2_dpcache *peer; /*!< For linking in peers */
-} *dpcache;
-
-AST_MUTEX_DEFINE_STATIC(dpcache_lock);
-
-static void reg_source_db(struct iax2_peer *p);
-static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin);
-
-static void destroy_peer(struct iax2_peer *peer);
-static int ast_cli_netstats(int fd, int limit_fmt);
-
-static void iax_debug_output(const char *data)
-{
- if (iaxdebug)
- ast_verbose("%s", data);
-}
-
-static void iax_error_output(const char *data)
-{
- ast_log(LOG_WARNING, "%s", data);
-}
-
-#ifdef NEWJB
-static void jb_error_output(const char *fmt, ...)
-{
- va_list args;
- char buf[1024];
-
- va_start(args, fmt);
- vsnprintf(buf, 1024, fmt, args);
- va_end(args);
-
- ast_log(LOG_ERROR, buf);
-}
-
-static void jb_warning_output(const char *fmt, ...)
-{
- va_list args;
- char buf[1024];
-
- va_start(args, fmt);
- vsnprintf(buf, 1024, fmt, args);
- va_end(args);
-
- ast_log(LOG_WARNING, buf);
-}
-
-static void jb_debug_output(const char *fmt, ...)
-{
- va_list args;
- char buf[1024];
-
- va_start(args, fmt);
- vsnprintf(buf, 1024, fmt, args);
- va_end(args);
-
- ast_verbose(buf);
-}
-#endif
-
-
-/* XXX We probably should use a mutex when working with this XXX */
-static struct chan_iax2_pvt *iaxs[IAX_MAX_CALLS];
-static ast_mutex_t iaxsl[IAX_MAX_CALLS];
-static struct timeval lastused[IAX_MAX_CALLS];
-
-
-static int send_command(struct chan_iax2_pvt *, char, int, unsigned int, const unsigned char *, int, int);
-static int send_command_locked(unsigned short callno, char, int, unsigned int, const unsigned char *, int, int);
-static int send_command_immediate(struct chan_iax2_pvt *, char, int, unsigned int, const unsigned char *, int, int);
-static int send_command_final(struct chan_iax2_pvt *, char, int, unsigned int, const unsigned char *, int, int);
-static int send_command_transfer(struct chan_iax2_pvt *, char, int, unsigned int, const unsigned char *, int);
-static struct iax2_user *build_user(const char *name, struct ast_variable *v, int temponly);
-static void destroy_user(struct iax2_user *user);
-static int expire_registry(void *data);
-static int iax2_write(struct ast_channel *c, struct ast_frame *f);
-static int iax2_do_register(struct iax2_registry *reg);
-static void prune_peers(void);
-static int iax2_poke_peer(struct iax2_peer *peer, int heldcall);
-static int iax2_provision(struct sockaddr_in *end, int sockfd, char *dest, const char *template, int force);
-
-static struct ast_channel *iax2_request(const char *type, int format, void *data, int *cause);
-static int iax2_devicestate(void *data);
-static int iax2_digit(struct ast_channel *c, char digit);
-static int iax2_sendtext(struct ast_channel *c, const char *text);
-static int iax2_sendimage(struct ast_channel *c, struct ast_frame *img);
-static int iax2_sendhtml(struct ast_channel *c, int subclass, const char *data, int datalen);
-static int iax2_call(struct ast_channel *c, char *dest, int timeout);
-static int iax2_hangup(struct ast_channel *c);
-static int iax2_answer(struct ast_channel *c);
-static struct ast_frame *iax2_read(struct ast_channel *c);
-static int iax2_write(struct ast_channel *c, struct ast_frame *f);
-static int iax2_indicate(struct ast_channel *c, int condition);
-static int iax2_setoption(struct ast_channel *c, int option, void *data, int datalen);
-static enum ast_bridge_result iax2_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
-static int iax2_transfer(struct ast_channel *c, const char *dest);
-static int iax2_fixup(struct ast_channel *oldchannel, struct ast_channel *newchan);
-
-static const struct ast_channel_tech iax2_tech = {
- .type = channeltype,
- .description = tdesc,
- .capabilities = IAX_CAPABILITY_FULLBANDWIDTH,
- .properties = AST_CHAN_TP_WANTSJITTER,
- .requester = iax2_request,
- .devicestate = iax2_devicestate,
- .send_digit = iax2_digit,
- .send_text = iax2_sendtext,
- .send_image = iax2_sendimage,
- .send_html = iax2_sendhtml,
- .call = iax2_call,
- .hangup = iax2_hangup,
- .answer = iax2_answer,
- .read = iax2_read,
- .write = iax2_write,
- .write_video = iax2_write,
- .indicate = iax2_indicate,
- .setoption = iax2_setoption,
- .bridge = iax2_bridge,
- .transfer = iax2_transfer,
- .fixup = iax2_fixup,
-};
-
-static int send_ping(void *data)
-{
- int callno = (long)data;
- /* Ping only if it's real, not if it's bridged */
- if (iaxs[callno]) {
-#ifdef BRIDGE_OPTIMIZATION
- if (!iaxs[callno]->bridgecallno)
-#endif
- send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_PING, 0, NULL, 0, -1);
- return 1;
- } else
- return 0;
-}
-
-static int get_encrypt_methods(const char *s)
-{
- int e;
- if (!strcasecmp(s, "aes128"))
- e = IAX_ENCRYPT_AES128;
- else if (ast_true(s))
- e = IAX_ENCRYPT_AES128;
- else
- e = 0;
- return e;
-}
-
-static int send_lagrq(void *data)
-{
- int callno = (long)data;
- /* Ping only if it's real not if it's bridged */
- if (iaxs[callno]) {
-#ifdef BRIDGE_OPTIMIZATION
- if (!iaxs[callno]->bridgecallno)
-#endif
- send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_LAGRQ, 0, NULL, 0, -1);
- return 1;
- } else
- return 0;
-}
-
-static unsigned char compress_subclass(int subclass)
-{
- int x;
- int power=-1;
- /* If it's 128 or smaller, just return it */
- if (subclass < IAX_FLAG_SC_LOG)
- return subclass;
- /* Otherwise find its power */
- for (x = 0; x < IAX_MAX_SHIFT; x++) {
- if (subclass & (1 << x)) {
- if (power > -1) {
- ast_log(LOG_WARNING, "Can't compress subclass %d\n", subclass);
- return 0;
- } else
- power = x;
- }
- }
- return power | IAX_FLAG_SC_LOG;
-}
-
-static int uncompress_subclass(unsigned char csub)
-{
- /* If the SC_LOG flag is set, return 2^csub otherwise csub */
- if (csub & IAX_FLAG_SC_LOG) {
- /* special case for 'compressed' -1 */
- if (csub == 0xff)
- return -1;
- else
- return 1 << (csub & ~IAX_FLAG_SC_LOG & IAX_MAX_SHIFT);
- }
- else
- return csub;
-}
-
-static struct iax2_peer *find_peer(const char *name, int realtime)
-{
- struct iax2_peer *peer;
- ast_mutex_lock(&peerl.lock);
- for(peer = peerl.peers; peer; peer = peer->next) {
- if (!strcasecmp(peer->name, name)) {
- break;
- }
- }
- ast_mutex_unlock(&peerl.lock);
- if(!peer && realtime)
- peer = realtime_peer(name, NULL);
- return peer;
-}
-
-static int iax2_getpeername(struct sockaddr_in sin, char *host, int len, int lockpeer)
-{
- struct iax2_peer *peer;
- int res = 0;
-
- if (lockpeer)
- ast_mutex_lock(&peerl.lock);
- peer = peerl.peers;
- while (peer) {
- if ((peer->addr.sin_addr.s_addr == sin.sin_addr.s_addr) &&
- (peer->addr.sin_port == sin.sin_port)) {
- ast_copy_string(host, peer->name, len);
- res = 1;
- break;
- }
- peer = peer->next;
- }
- if (lockpeer)
- ast_mutex_unlock(&peerl.lock);
- if (!peer) {
- peer = realtime_peer(NULL, &sin);
- if (peer) {
- ast_copy_string(host, peer->name, len);
- if (ast_test_flag(peer, IAX_TEMPONLY))
- destroy_peer(peer);
- res = 1;
- }
- }
-
- return res;
-}
-
-static struct chan_iax2_pvt *new_iax(struct sockaddr_in *sin, int lockpeer, const char *host)
-{
- struct chan_iax2_pvt *tmp;
- tmp = malloc(sizeof(struct chan_iax2_pvt));
- if (tmp) {
- memset(tmp, 0, sizeof(struct chan_iax2_pvt));
- tmp->prefs = prefs;
- tmp->callno = 0;
- tmp->peercallno = 0;
- tmp->transfercallno = 0;
- tmp->bridgecallno = 0;
- tmp->pingid = -1;
- tmp->lagid = -1;
- tmp->autoid = -1;
- tmp->authid = -1;
- tmp->initid = -1;
- /* ast_copy_string(tmp->context, context, sizeof(tmp->context)); */
- ast_copy_string(tmp->exten, "s", sizeof(tmp->exten));
- ast_copy_string(tmp->host, host, sizeof(tmp->host));
-#ifdef NEWJB
- {
- jb_conf jbconf;
-
- tmp->jb = jb_new();
- tmp->jbid = -1;
- jbconf.max_jitterbuf = maxjitterbuffer;
- jbconf.resync_threshold = resyncthreshold;
- jbconf.max_contig_interp = maxjitterinterps;
- jb_setconf(tmp->jb,&jbconf);
- }
-#endif
- }
- return tmp;
-}
-
-static struct iax_frame *iaxfrdup2(struct iax_frame *fr)
-{
- /* Malloc() a copy of a frame */
- struct iax_frame *new = iax_frame_new(DIRECTION_INGRESS, fr->af.datalen);
- if (new) {
- memcpy(new, fr, sizeof(struct iax_frame));
- iax_frame_wrap(new, &fr->af);
- new->data = NULL;
- new->datalen = 0;
- new->direction = DIRECTION_INGRESS;
- new->retrans = -1;
- }
- return new;
-}
-
-#define NEW_PREVENT 0
-#define NEW_ALLOW 1
-#define NEW_FORCE 2
-
-static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, struct chan_iax2_pvt *cur)
-{
- if ((cur->addr.sin_addr.s_addr == sin->sin_addr.s_addr) &&
- (cur->addr.sin_port == sin->sin_port)) {
- /* This is the main host */
- if ((cur->peercallno == callno) ||
- ((dcallno == cur->callno) && !cur->peercallno)) {
- /* That's us. Be sure we keep track of the peer call number */
- return 1;
- }
- }
- if ((cur->transfer.sin_addr.s_addr == sin->sin_addr.s_addr) &&
- (cur->transfer.sin_port == sin->sin_port) && (cur->transferring)) {
- /* We're transferring */
- if (dcallno == cur->callno)
- return 1;
- }
- return 0;
-}
-
-static void update_max_trunk(void)
-{
- int max = TRUNK_CALL_START;
- int x;
- /* XXX Prolly don't need locks here XXX */
- for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
- if (iaxs[x])
- max = x + 1;
- }
- maxtrunkcall = max;
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "New max trunk callno is %d\n", max);
-}
-
-static void update_max_nontrunk(void)
-{
- int max = 1;
- int x;
- /* XXX Prolly don't need locks here XXX */
- for (x=1;x<TRUNK_CALL_START - 1; x++) {
- if (iaxs[x])
- max = x + 1;
- }
- maxnontrunkcall = max;
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "New max nontrunk callno is %d\n", max);
-}
-
-static int make_trunk(unsigned short callno, int locked)
-{
- int x;
- int res= 0;
- struct timeval now;
- if (iaxs[callno]->oseqno) {
- ast_log(LOG_WARNING, "Can't make trunk once a call has started!\n");
- return -1;
- }
- if (callno & TRUNK_CALL_START) {
- ast_log(LOG_WARNING, "Call %d is already a trunk\n", callno);
- return -1;
- }
- gettimeofday(&now, NULL);
- for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
- ast_mutex_lock(&iaxsl[x]);
- if (!iaxs[x] && ((now.tv_sec - lastused[x].tv_sec) > MIN_REUSE_TIME)) {
- iaxs[x] = iaxs[callno];
- iaxs[x]->callno = x;
- iaxs[callno] = NULL;
- /* Update the two timers that should have been started */
- if (iaxs[x]->pingid > -1)
- ast_sched_del(sched, iaxs[x]->pingid);
- if (iaxs[x]->lagid > -1)
- ast_sched_del(sched, iaxs[x]->lagid);
- iaxs[x]->pingid = ast_sched_add(sched, ping_time * 1000, send_ping, (void *)(long)x);
- iaxs[x]->lagid = ast_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
- if (locked)
- ast_mutex_unlock(&iaxsl[callno]);
- res = x;
- if (!locked)
- ast_mutex_unlock(&iaxsl[x]);
- break;
- }
- ast_mutex_unlock(&iaxsl[x]);
- }
- if (x >= IAX_MAX_CALLS - 1) {
- ast_log(LOG_WARNING, "Unable to trunk call: Insufficient space\n");
- return -1;
- }
- ast_log(LOG_DEBUG, "Made call %d into trunk call %d\n", callno, x);
- /* We move this call from a non-trunked to a trunked call */
- update_max_trunk();
- update_max_nontrunk();
- return res;
-}
-
-static int find_callno(unsigned short callno, unsigned short dcallno, struct sockaddr_in *sin, int new, int lockpeer, int sockfd)
-{
- int res = 0;
- int x;
- struct timeval now;
- char iabuf[INET_ADDRSTRLEN];
- char host[80];
- if (new <= NEW_ALLOW) {
- /* Look for an existing connection first */
- for (x=1;(res < 1) && (x<maxnontrunkcall);x++) {
- ast_mutex_lock(&iaxsl[x]);
- if (iaxs[x]) {
- /* Look for an exact match */
- if (match(sin, callno, dcallno, iaxs[x])) {
- res = x;
- }
- }
- ast_mutex_unlock(&iaxsl[x]);
- }
- for (x=TRUNK_CALL_START;(res < 1) && (x<maxtrunkcall);x++) {
- ast_mutex_lock(&iaxsl[x]);
- if (iaxs[x]) {
- /* Look for an exact match */
- if (match(sin, callno, dcallno, iaxs[x])) {
- res = x;
- }
- }
- ast_mutex_unlock(&iaxsl[x]);
- }
- }
- if ((res < 1) && (new >= NEW_ALLOW)) {
- if (!iax2_getpeername(*sin, host, sizeof(host), lockpeer))
- snprintf(host, sizeof(host), "%s:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port));
- gettimeofday(&now, NULL);
- for (x=1;x<TRUNK_CALL_START;x++) {
- /* Find first unused call number that hasn't been used in a while */
- ast_mutex_lock(&iaxsl[x]);
- if (!iaxs[x] && ((now.tv_sec - lastused[x].tv_sec) > MIN_REUSE_TIME)) break;
- ast_mutex_unlock(&iaxsl[x]);
- }
- /* We've still got lock held if we found a spot */
- if (x >= TRUNK_CALL_START) {
- ast_log(LOG_WARNING, "No more space\n");
- return 0;
- }
- iaxs[x] = new_iax(sin, lockpeer, host);
- update_max_nontrunk();
- if (iaxs[x]) {
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Creating new call structure %d\n", x);
- iaxs[x]->sockfd = sockfd;
- iaxs[x]->addr.sin_port = sin->sin_port;
- iaxs[x]->addr.sin_family = sin->sin_family;
- iaxs[x]->addr.sin_addr.s_addr = sin->sin_addr.s_addr;
- iaxs[x]->peercallno = callno;
- iaxs[x]->callno = x;
- iaxs[x]->pingtime = DEFAULT_RETRY_TIME;
- iaxs[x]->expiry = min_reg_expire;
- iaxs[x]->pingid = ast_sched_add(sched, ping_time * 1000, send_ping, (void *)(long)x);
- iaxs[x]->lagid = ast_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
- iaxs[x]->amaflags = amaflags;
- ast_copy_flags(iaxs[x], (&globalflags), IAX_NOTRANSFER | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
- ast_copy_string(iaxs[x]->accountcode, accountcode, sizeof(iaxs[x]->accountcode));
- } else {
- ast_log(LOG_WARNING, "Out of resources\n");
- ast_mutex_unlock(&iaxsl[x]);
- return 0;
- }
- ast_mutex_unlock(&iaxsl[x]);
- res = x;
- }
- return res;
-}
-
-static void iax2_frame_free(struct iax_frame *fr)
-{
- if (fr->retrans > -1)
- ast_sched_del(sched, fr->retrans);
- iax_frame_free(fr);
-}
-
-static int iax2_queue_frame(int callno, struct ast_frame *f)
-{
- /* Assumes lock for callno is already held... */
- for (;;) {
- if (iaxs[callno] && iaxs[callno]->owner) {
- if (ast_mutex_trylock(&iaxs[callno]->owner->lock)) {
- /* Avoid deadlock by pausing and trying again */
- ast_mutex_unlock(&iaxsl[callno]);
- usleep(1);
- ast_mutex_lock(&iaxsl[callno]);
- } else {
- ast_queue_frame(iaxs[callno]->owner, f);
- ast_mutex_unlock(&iaxs[callno]->owner->lock);
- break;
- }
- } else
- break;
- }
- return 0;
-}
-
-static void destroy_firmware(struct iax_firmware *cur)
-{
- /* Close firmware */
- if (cur->fwh) {
- munmap(cur->fwh, ntohl(cur->fwh->datalen) + sizeof(*(cur->fwh)));
- }
- close(cur->fd);
- free(cur);
-}
-
-static int try_firmware(char *s)
-{
- struct stat stbuf;
- struct iax_firmware *cur;
- int ifd;
- int fd;
- int res;
-
- struct ast_iax2_firmware_header *fwh, fwh2;
- struct MD5Context md5;
- unsigned char sum[16];
- unsigned char buf[1024];
- int len, chunk;
- char *s2;
- char *last;
- s2 = alloca(strlen(s) + 100);
- if (!s2) {
- ast_log(LOG_WARNING, "Alloca failed!\n");
- return -1;
- }
- last = strrchr(s, '/');
- if (last)
- last++;
- else
- last = s;
- snprintf(s2, strlen(s) + 100, "/var/tmp/%s-%ld", last, (unsigned long)rand());
- res = stat(s, &stbuf);
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to stat '%s': %s\n", s, strerror(errno));
- return -1;
- }
- /* Make sure it's not a directory */
- if (S_ISDIR(stbuf.st_mode))
- return -1;
- ifd = open(s, O_RDONLY);
- if (ifd < 0) {
- ast_log(LOG_WARNING, "Cannot open '%s': %s\n", s, strerror(errno));
- return -1;
- }
- fd = open(s2, O_RDWR | O_CREAT | O_EXCL);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Cannot open '%s' for writing: %s\n", s2, strerror(errno));
- close(ifd);
- return -1;
- }
- /* Unlink our newly created file */
- unlink(s2);
-
- /* Now copy the firmware into it */
- len = stbuf.st_size;
- while(len) {
- chunk = len;
- if (chunk > sizeof(buf))
- chunk = sizeof(buf);
- res = read(ifd, buf, chunk);
- if (res != chunk) {
- ast_log(LOG_WARNING, "Only read %d of %d bytes of data :(: %s\n", res, chunk, strerror(errno));
- close(ifd);
- close(fd);
- return -1;
- }
- res = write(fd, buf, chunk);
- if (res != chunk) {
- ast_log(LOG_WARNING, "Only write %d of %d bytes of data :(: %s\n", res, chunk, strerror(errno));
- close(ifd);
- close(fd);
- return -1;
- }
- len -= chunk;
- }
- close(ifd);
- /* Return to the beginning */
- lseek(fd, 0, SEEK_SET);
- if ((res = read(fd, &fwh2, sizeof(fwh2))) != sizeof(fwh2)) {
- ast_log(LOG_WARNING, "Unable to read firmware header in '%s'\n", s);
- close(fd);
- return -1;
- }
- if (ntohl(fwh2.magic) != IAX_FIRMWARE_MAGIC) {
- ast_log(LOG_WARNING, "'%s' is not a valid firmware file\n", s);
- close(fd);
- return -1;
- }
- if (ntohl(fwh2.datalen) != (stbuf.st_size - sizeof(fwh2))) {
- ast_log(LOG_WARNING, "Invalid data length in firmware '%s'\n", s);
- close(fd);
- return -1;
- }
- if (fwh2.devname[sizeof(fwh2.devname) - 1] || ast_strlen_zero((char *)fwh2.devname)) {
- ast_log(LOG_WARNING, "No or invalid device type specified for '%s'\n", s);
- close(fd);
- return -1;
- }
- fwh = mmap(NULL, stbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (!fwh) {
- ast_log(LOG_WARNING, "mmap failed: %s\n", strerror(errno));
- close(fd);
- return -1;
- }
- MD5Init(&md5);
- MD5Update(&md5, fwh->data, ntohl(fwh->datalen));
- MD5Final(sum, &md5);
- if (memcmp(sum, fwh->chksum, sizeof(sum))) {
- ast_log(LOG_WARNING, "Firmware file '%s' fails checksum\n", s);
- munmap(fwh, stbuf.st_size);
- close(fd);
- return -1;
- }
- cur = waresl.wares;
- while(cur) {
- if (!strcmp((char *)cur->fwh->devname, (char *)fwh->devname)) {
- /* Found a candidate */
- if (cur->dead || (ntohs(cur->fwh->version) < ntohs(fwh->version)))
- /* The version we have on loaded is older, load this one instead */
- break;
- /* This version is no newer than what we have. Don't worry about it.
- We'll consider it a proper load anyhow though */
- munmap(fwh, stbuf.st_size);
- close(fd);
- return 0;
- }
- cur = cur->next;
- }
- if (!cur) {
- /* Allocate a new one and link it */
- cur = malloc(sizeof(struct iax_firmware));
- if (cur) {
- memset(cur, 0, sizeof(struct iax_firmware));
- cur->fd = -1;
- cur->next = waresl.wares;
- waresl.wares = cur;
- }
- }
- if (cur) {
- if (cur->fwh) {
- munmap(cur->fwh, cur->mmaplen);
- }
- if (cur->fd > -1)
- close(cur->fd);
- cur->fwh = fwh;
- cur->fd = fd;
- cur->mmaplen = stbuf.st_size;
- cur->dead = 0;
- }
- return 0;
-}
-
-static int iax_check_version(char *dev)
-{
- int res = 0;
- struct iax_firmware *cur;
- if (!ast_strlen_zero(dev)) {
- ast_mutex_lock(&waresl.lock);
- cur = waresl.wares;
- while(cur) {
- if (!strcmp(dev, (char *)cur->fwh->devname)) {
- res = ntohs(cur->fwh->version);
- break;
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&waresl.lock);
- }
- return res;
-}
-
-static int iax_firmware_append(struct iax_ie_data *ied, const unsigned char *dev, unsigned int desc)
-{
- int res = -1;
- unsigned int bs = desc & 0xff;
- unsigned int start = (desc >> 8) & 0xffffff;
- unsigned int bytes;
- struct iax_firmware *cur;
- if (!ast_strlen_zero((char *)dev) && bs) {
- start *= bs;
- ast_mutex_lock(&waresl.lock);
- cur = waresl.wares;
- while(cur) {
- if (!strcmp((char *)dev, (char *)cur->fwh->devname)) {
- iax_ie_append_int(ied, IAX_IE_FWBLOCKDESC, desc);
- if (start < ntohl(cur->fwh->datalen)) {
- bytes = ntohl(cur->fwh->datalen) - start;
- if (bytes > bs)
- bytes = bs;
- iax_ie_append_raw(ied, IAX_IE_FWBLOCKDATA, cur->fwh->data + start, bytes);
- } else {
- bytes = 0;
- iax_ie_append(ied, IAX_IE_FWBLOCKDATA);
- }
- if (bytes == bs)
- res = 0;
- else
- res = 1;
- break;
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&waresl.lock);
- }
- return res;
-}
-
-
-static void reload_firmware(void)
-{
- struct iax_firmware *cur, *curl, *curp;
- DIR *fwd;
- struct dirent *de;
- char dir[256];
- char fn[256];
- /* Mark all as dead */
- ast_mutex_lock(&waresl.lock);
- cur = waresl.wares;
- while(cur) {
- cur->dead = 1;
- cur = cur->next;
- }
- /* Now that we've freed them, load the new ones */
- snprintf(dir, sizeof(dir), "%s/firmware/iax", (char *)ast_config_AST_VAR_DIR);
- fwd = opendir(dir);
- if (fwd) {
- while((de = readdir(fwd))) {
- if (de->d_name[0] != '.') {
- snprintf(fn, sizeof(fn), "%s/%s", dir, de->d_name);
- if (!try_firmware(fn)) {
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Loaded firmware '%s'\n", de->d_name);
- }
- }
- }
- closedir(fwd);
- } else
- ast_log(LOG_WARNING, "Error opening firmware directory '%s': %s\n", dir, strerror(errno));
-
- /* Clean up leftovers */
- cur = waresl.wares;
- curp = NULL;
- while(cur) {
- curl = cur;
- cur = cur->next;
- if (curl->dead) {
- if (curp) {
- curp->next = cur;
- } else {
- waresl.wares = cur;
- }
- destroy_firmware(curl);
- } else {
- curp = cur;
- }
- }
- ast_mutex_unlock(&waresl.lock);
-}
-
-static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned int ts, int seqno, int now, int transfer, int final);
-
-static int __do_deliver(void *data)
-{
- /* Just deliver the packet by using queueing. This is called by
- the IAX thread with the iaxsl lock held. */
- struct iax_frame *fr = data;
- fr->retrans = -1;
- if (iaxs[fr->callno] && !ast_test_flag(iaxs[fr->callno], IAX_ALREADYGONE))
- iax2_queue_frame(fr->callno, &fr->af);
- /* Free our iax frame */
- iax2_frame_free(fr);
- /* And don't run again */
- return 0;
-}
-
-#ifndef NEWJB
-static int do_deliver(void *data)
-{
- /* Locking version of __do_deliver */
- struct iax_frame *fr = data;
- int callno = fr->callno;
- int res;
- ast_mutex_lock(&iaxsl[callno]);
- res = __do_deliver(data);
- ast_mutex_unlock(&iaxsl[callno]);
- return res;
-}
-#endif /* NEWJB */
-
-static int handle_error(void)
-{
- /* XXX Ideally we should figure out why an error occured and then abort those
- rather than continuing to try. Unfortunately, the published interface does
- not seem to work XXX */
-#if 0
- struct sockaddr_in *sin;
- int res;
- struct msghdr m;
- struct sock_extended_err e;
- m.msg_name = NULL;
- m.msg_namelen = 0;
- m.msg_iov = NULL;
- m.msg_control = &e;
- m.msg_controllen = sizeof(e);
- m.msg_flags = 0;
- res = recvmsg(netsocket, &m, MSG_ERRQUEUE);
- if (res < 0)
- ast_log(LOG_WARNING, "Error detected, but unable to read error: %s\n", strerror(errno));
- else {
- if (m.msg_controllen) {
- sin = (struct sockaddr_in *)SO_EE_OFFENDER(&e);
- if (sin)
- ast_log(LOG_WARNING, "Receive error from %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- else
- ast_log(LOG_WARNING, "No address detected??\n");
- } else {
- ast_log(LOG_WARNING, "Local error: %s\n", strerror(e.ee_errno));
- }
- }
-#endif
- return 0;
-}
-
-static int transmit_trunk(struct iax_frame *f, struct sockaddr_in *sin, int sockfd)
-{
- int res;
- res = sendto(sockfd, f->data, f->datalen, 0,(struct sockaddr *)sin,
- sizeof(*sin));
- if (res < 0) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Received error: %s\n", strerror(errno));
- handle_error();
- } else
- res = 0;
- return res;
-}
-
-static int send_packet(struct iax_frame *f)
-{
- int res;
- char iabuf[INET_ADDRSTRLEN];
- /* Called with iaxsl held */
- if (option_debug > 2 && iaxdebug)
- ast_log(LOG_DEBUG, "Sending %d on %d/%d to %s:%d\n", f->ts, f->callno, iaxs[f->callno]->peercallno, ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[f->callno]->addr.sin_addr), ntohs(iaxs[f->callno]->addr.sin_port));
- /* Don't send if there was an error, but return error instead */
- if (!f->callno) {
- ast_log(LOG_WARNING, "Call number = %d\n", f->callno);
- return -1;
- }
- if (!iaxs[f->callno])
- return -1;
- if (iaxs[f->callno]->error)
- return -1;
- if (f->transfer) {
- if (iaxdebug)
- iax_showframe(f, NULL, 0, &iaxs[f->callno]->transfer, f->datalen - sizeof(struct ast_iax2_full_hdr));
- res = sendto(iaxs[f->callno]->sockfd, f->data, f->datalen, 0,(struct sockaddr *)&iaxs[f->callno]->transfer,
- sizeof(iaxs[f->callno]->transfer));
- } else {
- if (iaxdebug)
- iax_showframe(f, NULL, 0, &iaxs[f->callno]->addr, f->datalen - sizeof(struct ast_iax2_full_hdr));
- res = sendto(iaxs[f->callno]->sockfd, f->data, f->datalen, 0,(struct sockaddr *)&iaxs[f->callno]->addr,
- sizeof(iaxs[f->callno]->addr));
- }
- if (res < 0) {
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Received error: %s\n", strerror(errno));
- handle_error();
- } else
- res = 0;
- return res;
-}
-
-
-static int iax2_predestroy(int callno)
-{
- struct ast_channel *c;
- struct chan_iax2_pvt *pvt;
- ast_mutex_lock(&iaxsl[callno]);
- pvt = iaxs[callno];
- if (!pvt) {
- ast_mutex_unlock(&iaxsl[callno]);
- return -1;
- }
- if (!ast_test_flag(pvt, IAX_ALREADYGONE)) {
- /* No more pings or lagrq's */
- if (pvt->pingid > -1)
- ast_sched_del(sched, pvt->pingid);
- if (pvt->lagid > -1)
- ast_sched_del(sched, pvt->lagid);
- if (pvt->autoid > -1)
- ast_sched_del(sched, pvt->autoid);
- if (pvt->authid > -1)
- ast_sched_del(sched, pvt->authid);
- if (pvt->initid > -1)
- ast_sched_del(sched, pvt->initid);
-#ifdef NEWJB
- if (pvt->jbid > -1)
- ast_sched_del(sched, pvt->jbid);
- pvt->jbid = -1;
-#endif
- pvt->pingid = -1;
- pvt->lagid = -1;
- pvt->autoid = -1;
- pvt->initid = -1;
- pvt->authid = -1;
- ast_set_flag(pvt, IAX_ALREADYGONE);
- }
- c = pvt->owner;
- if (c) {
- c->_softhangup |= AST_SOFTHANGUP_DEV;
- c->tech_pvt = NULL;
- ast_queue_hangup(c);
- pvt->owner = NULL;
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- if (usecnt < 0)
- ast_log(LOG_WARNING, "Usecnt < 0???\n");
- ast_mutex_unlock(&usecnt_lock);
- }
- ast_mutex_unlock(&iaxsl[callno]);
- ast_update_use_count();
- return 0;
-}
-
-static int iax2_predestroy_nolock(int callno)
-{
- int res;
- ast_mutex_unlock(&iaxsl[callno]);
- res = iax2_predestroy(callno);
- ast_mutex_lock(&iaxsl[callno]);
- return res;
-}
-
-static void iax2_destroy(int callno)
-{
- struct chan_iax2_pvt *pvt;
- struct iax_frame *cur;
- struct ast_channel *owner;
-
-retry:
- ast_mutex_lock(&iaxsl[callno]);
- pvt = iaxs[callno];
- gettimeofday(&lastused[callno], NULL);
-
- if (pvt)
- owner = pvt->owner;
- else
- owner = NULL;
- if (owner) {
- if (ast_mutex_trylock(&owner->lock)) {
- ast_log(LOG_NOTICE, "Avoiding IAX destroy deadlock\n");
- ast_mutex_unlock(&iaxsl[callno]);
- usleep(1);
- goto retry;
- }
- }
- if (!owner)
- iaxs[callno] = NULL;
- if (pvt) {
- if (!owner)
- pvt->owner = NULL;
- /* No more pings or lagrq's */
- if (pvt->pingid > -1)
- ast_sched_del(sched, pvt->pingid);
- if (pvt->lagid > -1)
- ast_sched_del(sched, pvt->lagid);
- if (pvt->autoid > -1)
- ast_sched_del(sched, pvt->autoid);
- if (pvt->authid > -1)
- ast_sched_del(sched, pvt->authid);
- if (pvt->initid > -1)
- ast_sched_del(sched, pvt->initid);
-#ifdef NEWJB
- if (pvt->jbid > -1)
- ast_sched_del(sched, pvt->jbid);
- pvt->jbid = -1;
-#endif
- pvt->pingid = -1;
- pvt->lagid = -1;
- pvt->autoid = -1;
- pvt->authid = -1;
- pvt->initid = -1;
- if (pvt->bridgetrans)
- ast_translator_free_path(pvt->bridgetrans);
- pvt->bridgetrans = NULL;
-
- /* Already gone */
- ast_set_flag(pvt, IAX_ALREADYGONE);
-
- if (owner) {
- /* If there's an owner, prod it to give up */
- owner->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_queue_hangup(owner);
- }
-
- for (cur = iaxq.head; cur ; cur = cur->next) {
- /* Cancel any pending transmissions */
- if (cur->callno == pvt->callno)
- cur->retries = -1;
- }
- if (pvt->reg) {
- pvt->reg->callno = 0;
- }
- if (!owner) {
- if (pvt->vars) {
- ast_variables_destroy(pvt->vars);
- pvt->vars = NULL;
- }
-#ifdef NEWJB
- {
- jb_frame frame;
- while(jb_getall(pvt->jb,&frame) == JB_OK)
- iax2_frame_free(frame.data);
- jb_destroy(pvt->jb);
- }
-#endif
- free(pvt);
- }
- }
- if (owner) {
- ast_mutex_unlock(&owner->lock);
- }
- ast_mutex_unlock(&iaxsl[callno]);
- if (callno & 0x4000)
- update_max_trunk();
-}
-static void iax2_destroy_nolock(int callno)
-{
- /* Actually it's easier to unlock, kill it, and relock */
- ast_mutex_unlock(&iaxsl[callno]);
- iax2_destroy(callno);
- ast_mutex_lock(&iaxsl[callno]);
-}
-
-static int update_packet(struct iax_frame *f)
-{
- /* Called with iaxsl lock held, and iaxs[callno] non-NULL */
- struct ast_iax2_full_hdr *fh = f->data;
- /* Mark this as a retransmission */
- fh->dcallno = ntohs(IAX_FLAG_RETRANS | f->dcallno);
- /* Update iseqno */
- f->iseqno = iaxs[f->callno]->iseqno;
- fh->iseqno = f->iseqno;
- return 0;
-}
-
-static int attempt_transmit(void *data)
-{
- /* Attempt to transmit the frame to the remote peer...
- Called without iaxsl held. */
- struct iax_frame *f = data;
- int freeme=0;
- int callno = f->callno;
- char iabuf[INET_ADDRSTRLEN];
- /* Make sure this call is still active */
- if (callno)
- ast_mutex_lock(&iaxsl[callno]);
- if ((f->callno) && iaxs[f->callno]) {
- if ((f->retries < 0) /* Already ACK'd */ ||
- (f->retries >= max_retries) /* Too many attempts */) {
- /* Record an error if we've transmitted too many times */
- if (f->retries >= max_retries) {
- if (f->transfer) {
- /* Transfer timeout */
- send_command(iaxs[f->callno], AST_FRAME_IAX, IAX_COMMAND_TXREJ, 0, NULL, 0, -1);
- } else if (f->final) {
- if (f->final)
- iax2_destroy_nolock(f->callno);
- } else {
- if (iaxs[f->callno]->owner)
- ast_log(LOG_WARNING, "Max retries exceeded to host %s on %s (type = %d, subclass = %d, ts=%d, seqno=%d)\n", ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[f->callno]->addr.sin_addr),iaxs[f->callno]->owner->name , f->af.frametype, f->af.subclass, f->ts, f->oseqno);
- iaxs[f->callno]->error = ETIMEDOUT;
- if (iaxs[f->callno]->owner) {
- struct ast_frame fr = { 0, };
- /* Hangup the fd */
- fr.frametype = AST_FRAME_CONTROL;
- fr.subclass = AST_CONTROL_HANGUP;
- iax2_queue_frame(f->callno, &fr);
- /* Remember, owner could disappear */
- if (iaxs[f->callno]->owner)
- iaxs[f->callno]->owner->hangupcause = AST_CAUSE_DESTINATION_OUT_OF_ORDER;
- } else {
- if (iaxs[f->callno]->reg) {
- memset(&iaxs[f->callno]->reg->us, 0, sizeof(iaxs[f->callno]->reg->us));
- iaxs[f->callno]->reg->regstate = REG_STATE_TIMEOUT;
- iaxs[f->callno]->reg->refresh = IAX_DEFAULT_REG_EXPIRE;
- }
- iax2_destroy_nolock(f->callno);
- }
- }
-
- }
- freeme++;
- } else {
- /* Update it if it needs it */
- update_packet(f);
- /* Attempt transmission */
- send_packet(f);
- f->retries++;
- /* Try again later after 10 times as long */
- f->retrytime *= 10;
- if (f->retrytime > MAX_RETRY_TIME)
- f->retrytime = MAX_RETRY_TIME;
- /* Transfer messages max out at one second */
- if (f->transfer && (f->retrytime > 1000))
- f->retrytime = 1000;
- f->retrans = ast_sched_add(sched, f->retrytime, attempt_transmit, f);
- }
- } else {
- /* Make sure it gets freed */
- f->retries = -1;
- freeme++;
- }
- if (callno)
- ast_mutex_unlock(&iaxsl[callno]);
- /* Do not try again */
- if (freeme) {
- /* Don't attempt delivery, just remove it from the queue */
- ast_mutex_lock(&iaxq.lock);
- if (f->prev)
- f->prev->next = f->next;
- else
- iaxq.head = f->next;
- if (f->next)
- f->next->prev = f->prev;
- else
- iaxq.tail = f->prev;
- iaxq.count--;
- ast_mutex_unlock(&iaxq.lock);
- f->retrans = -1;
- /* Free the IAX frame */
- iax2_frame_free(f);
- }
- return 0;
-}
-
-static int iax2_set_jitter(int fd, int argc, char *argv[])
-{
-#ifdef NEWJB
- ast_cli(fd, "sorry, this command is deprecated\n");
- return RESULT_SUCCESS;
-#else
- if ((argc != 4) && (argc != 5))
- return RESULT_SHOWUSAGE;
- if (argc == 4) {
- max_jitter_buffer = atoi(argv[3]);
- if (max_jitter_buffer < 0)
- max_jitter_buffer = 0;
- } else {
- if (argc == 5) {
- if ((atoi(argv[3]) >= 0) && (atoi(argv[3]) < IAX_MAX_CALLS)) {
- if (iaxs[atoi(argv[3])]) {
- iaxs[atoi(argv[3])]->jitterbuffer = atoi(argv[4]);
- if (iaxs[atoi(argv[3])]->jitterbuffer < 0)
- iaxs[atoi(argv[3])]->jitterbuffer = 0;
- } else
- ast_cli(fd, "No such call '%d'\n", atoi(argv[3]));
- } else
- ast_cli(fd, "%d is not a valid call number\n", atoi(argv[3]));
- }
- }
- return RESULT_SUCCESS;
-#endif
-}
-
-static char jitter_usage[] =
-"Usage: iax set jitter [callid] <value>\n"
-" If used with a callid, it sets the jitter buffer to the given static\n"
-"value (until its next calculation). If used without a callid, the value is used\n"
-"to establish the maximum excess jitter buffer that is permitted before the jitter\n"
-"buffer size is reduced.";
-
-static int iax2_prune_realtime(int fd, int argc, char *argv[])
-{
- struct iax2_peer *peer;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- if (!strcmp(argv[3],"all")) {
- reload_config();
- ast_cli(fd, "OK cache is flushed.\n");
- } else if ((peer = find_peer(argv[3], 0))) {
- if(ast_test_flag(peer, IAX_RTCACHEFRIENDS)) {
- ast_set_flag(peer, IAX_RTAUTOCLEAR);
- expire_registry(peer);
- ast_cli(fd, "OK peer %s was removed from the cache.\n", argv[3]);
- } else {
- ast_cli(fd, "SORRY peer %s is not eligible for this operation.\n", argv[3]);
- }
- } else {
- ast_cli(fd, "SORRY peer %s was not found in the cache.\n", argv[3]);
- }
-
- return RESULT_SUCCESS;
-}
-
-static int iax2_test_losspct(int fd, int argc, char *argv[])
-{
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- test_losspct = atoi(argv[3]);
-
- return RESULT_SUCCESS;
-}
-
-#ifdef IAXTESTS
-static int iax2_test_late(int fd, int argc, char *argv[])
-{
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- test_late = atoi(argv[3]);
-
- return RESULT_SUCCESS;
-}
-
-static int iax2_test_resync(int fd, int argc, char *argv[])
-{
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- test_resync = atoi(argv[3]);
-
- return RESULT_SUCCESS;
-}
-
-static int iax2_test_jitter(int fd, int argc, char *argv[])
-{
- if (argc < 4 || argc > 5)
- return RESULT_SHOWUSAGE;
-
- test_jit = atoi(argv[3]);
- if (argc == 5)
- test_jitpct = atoi(argv[4]);
-
- return RESULT_SUCCESS;
-}
-#endif /* IAXTESTS */
-
-/*! \brief peer_status: Report Peer status in character string */
-/* returns 1 if peer is online, -1 if unmonitored */
-static int peer_status(struct iax2_peer *peer, char *status, int statuslen)
-{
- int res = 0;
- if (peer->maxms) {
- if (peer->lastms < 0) {
- ast_copy_string(status, "UNREACHABLE", statuslen);
- } else if (peer->lastms > peer->maxms) {
- snprintf(status, statuslen, "LAGGED (%d ms)", peer->lastms);
- res = 1;
- } else if (peer->lastms) {
- snprintf(status, statuslen, "OK (%d ms)", peer->lastms);
- res = 1;
- } else {
- ast_copy_string(status, "UNKNOWN", statuslen);
- }
- } else {
- ast_copy_string(status, "Unmonitored", statuslen);
- res = -1;
- }
- return res;
-}
-
-/*--- iax2_show_peer: Show one peer in detail ---*/
-static int iax2_show_peer(int fd, int argc, char *argv[])
-{
- char status[30];
- char cbuf[256];
- char iabuf[INET_ADDRSTRLEN];
- struct iax2_peer *peer;
- char codec_buf[512];
- int x = 0, codec = 0, load_realtime = 0;
-
- if (argc < 4)
- return RESULT_SHOWUSAGE;
-
- load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? 1 : 0;
-
- peer = find_peer(argv[3], load_realtime);
- if (peer) {
- ast_cli(fd,"\n\n");
- ast_cli(fd, " * Name : %s\n", peer->name);
- ast_cli(fd, " Secret : %s\n", ast_strlen_zero(peer->secret)?"<Not set>":"<Set>");
- ast_cli(fd, " Context : %s\n", peer->context);
- ast_cli(fd, " Mailbox : %s\n", peer->mailbox);
- ast_cli(fd, " Dynamic : %s\n", ast_test_flag(peer, IAX_DYNAMIC) ? "Yes":"No");
- ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>"));
- ast_cli(fd, " Expire : %d\n", peer->expire);
- ast_cli(fd, " ACL : %s\n", (peer->ha?"Yes":"No"));
- ast_cli(fd, " Addr->IP : %s Port %d\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)", ntohs(peer->addr.sin_port));
- ast_cli(fd, " Defaddr->IP : %s Port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port));
- ast_cli(fd, " Username : %s\n", peer->username);
- ast_cli(fd, " Codecs : ");
- ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability);
- ast_cli(fd, "%s\n", codec_buf);
-
- ast_cli(fd, " Codec Order : (");
- for(x = 0; x < 32 ; x++) {
- codec = ast_codec_pref_index(&peer->prefs,x);
- if(!codec)
- break;
- ast_cli(fd, "%s", ast_getformatname(codec));
- if(x < 31 && ast_codec_pref_index(&peer->prefs,x+1))
- ast_cli(fd, "|");
- }
-
- if (!x)
- ast_cli(fd, "none");
- ast_cli(fd, ")\n");
-
- ast_cli(fd, " Status : ");
- peer_status(peer, status, sizeof(status));
- ast_cli(fd, "%s\n",status);
- ast_cli(fd, " Qualify : every %dms when OK, every %dms when UNREACHABLE (sample smoothing %s)\n", peer->pokefreqok, peer->pokefreqnotok, peer->smoothing ? "On" : "Off");
- ast_cli(fd,"\n");
- if (ast_test_flag(peer, IAX_TEMPONLY))
- destroy_peer(peer);
- } else {
- ast_cli(fd,"Peer %s not found.\n", argv[3]);
- ast_cli(fd,"\n");
- }
-
- return RESULT_SUCCESS;
-}
-
-static char *complete_iax2_show_peer(char *line, char *word, int pos, int state)
-{
- int which = 0;
- struct iax2_peer *p;
- char *res = NULL;
-
- /* 0 - iax2; 1 - show; 2 - peer; 3 - <peername> */
- if(pos == 3) {
- ast_mutex_lock(&peerl.lock);
- for(p = peerl.peers ; p ; p = p->next) {
- if(!strncasecmp(p->name, word, strlen(word))) {
- if(++which > state) {
- res = strdup(p->name);
- break;
- }
- }
- }
- ast_mutex_unlock(&peerl.lock);
- }
-
- return res;
-}
-
-static int iax2_show_stats(int fd, int argc, char *argv[])
-{
- struct iax_frame *cur;
- int cnt = 0, dead=0, final=0;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- for (cur = iaxq.head; cur ; cur = cur->next) {
- if (cur->retries < 0)
- dead++;
- if (cur->final)
- final++;
- cnt++;
- }
- ast_cli(fd, " IAX Statistics\n");
- ast_cli(fd, "---------------------\n");
- ast_cli(fd, "Outstanding frames: %d (%d ingress, %d egress)\n", iax_get_frames(), iax_get_iframes(), iax_get_oframes());
- ast_cli(fd, "Packets in transmit queue: %d dead, %d final, %d total\n", dead, final, cnt);
- return RESULT_SUCCESS;
-}
-
-static int iax2_show_cache(int fd, int argc, char *argv[])
-{
- struct iax2_dpcache *dp;
- char tmp[1024], *pc;
- int s;
- int x,y;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- ast_mutex_lock(&dpcache_lock);
- dp = dpcache;
- ast_cli(fd, "%-20.20s %-12.12s %-9.9s %-8.8s %s\n", "Peer/Context", "Exten", "Exp.", "Wait.", "Flags");
- while(dp) {
- s = dp->expiry.tv_sec - tv.tv_sec;
- tmp[0] = '\0';
- if (dp->flags & CACHE_FLAG_EXISTS)
- strncat(tmp, "EXISTS|", sizeof(tmp) - strlen(tmp) - 1);
- if (dp->flags & CACHE_FLAG_NONEXISTENT)
- strncat(tmp, "NONEXISTENT|", sizeof(tmp) - strlen(tmp) - 1);
- if (dp->flags & CACHE_FLAG_CANEXIST)
- strncat(tmp, "CANEXIST|", sizeof(tmp) - strlen(tmp) - 1);
- if (dp->flags & CACHE_FLAG_PENDING)
- strncat(tmp, "PENDING|", sizeof(tmp) - strlen(tmp) - 1);
- if (dp->flags & CACHE_FLAG_TIMEOUT)
- strncat(tmp, "TIMEOUT|", sizeof(tmp) - strlen(tmp) - 1);
- if (dp->flags & CACHE_FLAG_TRANSMITTED)
- strncat(tmp, "TRANSMITTED|", sizeof(tmp) - strlen(tmp) - 1);
- if (dp->flags & CACHE_FLAG_MATCHMORE)
- strncat(tmp, "MATCHMORE|", sizeof(tmp) - strlen(tmp) - 1);
- if (dp->flags & CACHE_FLAG_UNKNOWN)
- strncat(tmp, "UNKNOWN|", sizeof(tmp) - strlen(tmp) - 1);
- /* Trim trailing pipe */
- if (!ast_strlen_zero(tmp))
- tmp[strlen(tmp) - 1] = '\0';
- else
- ast_copy_string(tmp, "(none)", sizeof(tmp));
- y=0;
- pc = strchr(dp->peercontext, '@');
- if (!pc)
- pc = dp->peercontext;
- else
- pc++;
- for (x=0;x<sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++)
- if (dp->waiters[x] > -1)
- y++;
- if (s > 0)
- ast_cli(fd, "%-20.20s %-12.12s %-9d %-8d %s\n", pc, dp->exten, s, y, tmp);
- else
- ast_cli(fd, "%-20.20s %-12.12s %-9.9s %-8d %s\n", pc, dp->exten, "(expired)", y, tmp);
- dp = dp->next;
- }
- ast_mutex_unlock(&dpcache_lock);
- return RESULT_SUCCESS;
-}
-
-static unsigned int calc_rxstamp(struct chan_iax2_pvt *p, unsigned int offset);
-
-#ifdef BRIDGE_OPTIMIZATION
-static unsigned int calc_fakestamp(struct chan_iax2_pvt *from, struct chan_iax2_pvt *to, unsigned int ts);
-
-static int forward_delivery(struct iax_frame *fr)
-{
- struct chan_iax2_pvt *p1, *p2;
- char iabuf[INET_ADDRSTRLEN];
- int res, orig_ts;
-
- p1 = iaxs[fr->callno];
- p2 = iaxs[p1->bridgecallno];
- if (!p1)
- return -1;
- if (!p2)
- return -1;
-
- if (option_debug)
- ast_log(LOG_DEBUG, "forward_delivery: Forwarding ts=%d on %d/%d to %d/%d on %s:%d\n",
- fr->ts,
- p1->callno, p1->peercallno,
- p2->callno, p2->peercallno,
- ast_inet_ntoa(iabuf, sizeof(iabuf), p2->addr.sin_addr),
- ntohs(p2->addr.sin_port));
-
- /* Undo wraparound - which can happen when full VOICE frame wasn't sent by our peer.
- This is necessary for when our peer is chan_iax2.c v1.1nn or earlier which didn't
- send full frame on timestamp wrap when doing optimized bridging
- (actually current code STILL doesn't)
- */
- if (fr->ts + 50000 <= p1->last) {
- fr->ts = ( (p1->last & 0xFFFF0000) + 0x10000) | (fr->ts & 0xFFFF);
- if (option_debug)
- ast_log(LOG_DEBUG, "forward_delivery: pushed forward timestamp to %u\n", fr->ts);
- }
-
- /* Send with timestamp adjusted to the origin of the outbound leg */
- /* But don't destroy inbound timestamp still needed later to set "last" */
- orig_ts = fr->ts;
- fr->ts = calc_fakestamp(p1, p2, fr->ts);
- res = iax2_send(p2, &fr->af, fr->ts, -1, 0, 0, 0);
- fr->ts = orig_ts;
- return res;
-}
-#endif
-
-static void unwrap_timestamp(struct iax_frame *fr)
-{
- int x;
-
- if ( (fr->ts & 0xFFFF0000) == (iaxs[fr->callno]->last & 0xFFFF0000) ) {
- x = fr->ts - iaxs[fr->callno]->last;
- if (x < -50000) {
- /* Sudden big jump backwards in timestamp:
- What likely happened here is that miniframe timestamp has circled but we haven't
- gotten the update from the main packet. We'll just pretend that we did, and
- update the timestamp appropriately. */
- fr->ts = ( (iaxs[fr->callno]->last & 0xFFFF0000) + 0x10000) | (fr->ts & 0xFFFF);
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "schedule_delivery: pushed forward timestamp\n");
- }
- if (x > 50000) {
- /* Sudden apparent big jump forwards in timestamp:
- What's likely happened is this is an old miniframe belonging to the previous
- top-16-bit timestamp that has turned up out of order.
- Adjust the timestamp appropriately. */
- fr->ts = ( (iaxs[fr->callno]->last & 0xFFFF0000) - 0x10000) | (fr->ts & 0xFFFF);
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "schedule_delivery: pushed back timestamp\n");
- }
- }
-}
-
-#ifdef NEWJB
-static int get_from_jb(void *p);
-
-static void update_jbsched(struct chan_iax2_pvt *pvt) {
- int when;
-
- when = ast_tvdiff_ms(ast_tvnow(), pvt->rxcore);
-
- /* fprintf(stderr, "now = %d, next=%d\n", when, jb_next(pvt->jb)); */
-
- when = jb_next(pvt->jb) - when;
- /* fprintf(stderr, "when = %d\n", when); */
-
- if(pvt->jbid > -1) ast_sched_del(sched, pvt->jbid);
-
- if(when <= 0) {
- /* XXX should really just empty until when > 0.. */
- when = 1;
- }
-
- pvt->jbid = ast_sched_add(sched, when, get_from_jb, (void *)pvt);
-}
-
-static int get_from_jb(void *p)
-{
- /* make sure pvt is valid! */
- struct chan_iax2_pvt *pvt = p;
- struct iax_frame *fr;
- jb_frame frame;
- int ret;
- long now;
- long next;
- struct timeval tv;
-
- ast_mutex_lock(&iaxsl[pvt->callno]);
- /* fprintf(stderr, "get_from_jb called\n"); */
- pvt->jbid = -1;
-
- gettimeofday(&tv,NULL);
- /* round up a millisecond since ast_sched_runq does; */
- /* prevents us from spinning while waiting for our now */
- /* to catch up with runq's now */
- tv.tv_usec += 1000;
-
- now = ast_tvdiff_ms(tv, pvt->rxcore);
-
- if(now >= (next = jb_next(pvt->jb))) {
- ret = jb_get(pvt->jb,&frame,now,ast_codec_interp_len(pvt->voiceformat));
- switch(ret) {
- case JB_OK:
- /*if(frame.type == JB_TYPE_VOICE && next + 20 != jb_next(pvt->jb)) fprintf(stderr, "NEXT %ld is not %ld+20!\n", jb_next(pvt->jb), next); */
- fr = frame.data;
- __do_deliver(fr);
- break;
- case JB_INTERP:
- {
- struct ast_frame af;
-
- /*if(next + 20 != jb_next(pvt->jb)) fprintf(stderr, "NEXT %ld is not %ld+20!\n", jb_next(pvt->jb), next); */
-
- /* create an interpolation frame */
- /*fprintf(stderr, "Making Interpolation frame\n"); */
- af.frametype = AST_FRAME_VOICE;
- af.subclass = pvt->voiceformat;
- af.datalen = 0;
- af.samples = frame.ms * 8;
- af.mallocd = 0;
- af.src = "IAX2 JB interpolation";
- af.data = NULL;
- af.delivery = ast_tvadd(pvt->rxcore, ast_samp2tv(next, 1000));
- af.offset=AST_FRIENDLY_OFFSET;
-
- /* queue the frame: For consistency, we would call __do_deliver here, but __do_deliver wants an iax_frame,
- * which we'd need to malloc, and then it would free it. That seems like a drag */
- if (iaxs[pvt->callno] && !ast_test_flag(iaxs[pvt->callno], IAX_ALREADYGONE))
- iax2_queue_frame(pvt->callno, &af);
- }
- break;
- case JB_DROP:
- /*if(next != jb_next(pvt->jb)) fprintf(stderr, "NEXT %ld is not next %ld!\n", jb_next(pvt->jb), next); */
- iax2_frame_free(frame.data);
- break;
- case JB_NOFRAME:
- case JB_EMPTY:
- /* do nothing */
- break;
- default:
- /* shouldn't happen */
- break;
- }
- }
- update_jbsched(pvt);
- ast_mutex_unlock(&iaxsl[pvt->callno]);
- return 0;
-}
-#endif
-
-/* while we transition from the old JB to the new one, we can either make two schedule_delivery functions, or
- * make preprocessor swiss-cheese out of this one. I'm not sure which is less revolting.. */
-static int schedule_delivery(struct iax_frame *fr, int updatehistory, int fromtrunk, unsigned int *tsout)
-{
-#ifdef NEWJB
- int type, len;
- int ret;
- int needfree = 0;
-#else
- int x;
- int ms;
- int delay;
- unsigned int orig_ts;
- int drops[MEMORY_SIZE];
- int min, max=0, prevjitterbuffer, maxone=0,y,z, match;
-
- /* Remember current jitterbuffer so we can log any change */
- prevjitterbuffer = iaxs[fr->callno]->jitterbuffer;
- /* Similarly for the frame timestamp */
- orig_ts = fr->ts;
-#endif
-
-#if 0
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "schedule_delivery: ts=%d, last=%d, update=%d\n",
- fr->ts, iaxs[fr->callno]->last, updatehistory);
-#endif
-
- /* Attempt to recover wrapped timestamps */
- unwrap_timestamp(fr);
-
- if (updatehistory) {
-#ifndef NEWJB
-
- /* Attempt to spot a change of timebase on timestamps coming from the other side
- We detect by noticing a jump in consecutive timestamps that can't reasonably be explained
- by network jitter or reordering. Sometimes, also, the peer stops sending us frames
- for a while - in this case this code might also resync us. But that's not a bad thing.
- Be careful of non-voice frames which are timestamped differently (especially ACKS!)
- [that's why we only do this when updatehistory is true]
- */
- x = fr->ts - iaxs[fr->callno]->last;
- if (x > TS_GAP_FOR_JB_RESYNC || x < -TS_GAP_FOR_JB_RESYNC) {
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "schedule_delivery: call=%d: TS jumped. resyncing rxcore (ts=%d, last=%d)\n",
- fr->callno, fr->ts, iaxs[fr->callno]->last);
- /* zap rxcore - calc_rxstamp will make a new one based on this frame */
- iaxs[fr->callno]->rxcore = ast_tv(0, 0);
- /* wipe "last" if stamps have jumped backwards */
- if (x<0)
- iaxs[fr->callno]->last = 0;
- /* should we also empty history? */
- }
- /* ms is a measure of the "lateness" of the frame relative to the "reference"
- frame we received. (initially the very first, but also see code just above here).
- Understand that "ms" can easily be -ve if lag improves since the reference frame.
- Called by IAX thread, with iaxsl lock held. */
- ms = calc_rxstamp(iaxs[fr->callno], fr->ts) - fr->ts;
-
- /* Rotate our history queue of "lateness". Don't worry about those initial
- zeros because the first entry will always be zero */
- for (x=0;x<MEMORY_SIZE - 1;x++)
- iaxs[fr->callno]->history[x] = iaxs[fr->callno]->history[x+1];
- /* Add a history entry for this one */
- iaxs[fr->callno]->history[x] = ms;
-#endif
- }
-#ifndef NEWJB
- else
- ms = 0;
-#endif
-
-
- /* delivery time is sender's sent timestamp converted back into absolute time according to our clock */
- if ( !fromtrunk && !ast_tvzero(iaxs[fr->callno]->rxcore))
- fr->af.delivery = ast_tvadd(iaxs[fr->callno]->rxcore, ast_samp2tv(fr->ts, 1000));
- else {
-#if 0
- ast_log(LOG_DEBUG, "schedule_delivery: set delivery to 0 as we don't have an rxcore yet, or frame is from trunk.\n");
-#endif
- fr->af.delivery = ast_tv(0,0);
- }
-
-#ifndef NEWJB
- /* Initialize the minimum to reasonable values. It's too much
- work to do the same for the maximum, repeatedly */
- min=iaxs[fr->callno]->history[0];
- for (z=0;z < iax2_dropcount + 1;z++) {
- /* Start very optimistic ;-) */
- max=-999999999;
- for (x=0;x<MEMORY_SIZE;x++) {
- if (max < iaxs[fr->callno]->history[x]) {
- /* We have a candidate new maximum value. Make
- sure it's not in our drop list */
- match = 0;
- for (y=0;!match && (y<z);y++)
- match |= (drops[y] == x);
- if (!match) {
- /* It's not in our list, use it as the new maximum */
- max = iaxs[fr->callno]->history[x];
- maxone = x;
- }
-
- }
- if (!z) {
- /* On our first pass, find the minimum too */
- if (min > iaxs[fr->callno]->history[x])
- min = iaxs[fr->callno]->history[x];
- }
- }
-#if 1
- drops[z] = maxone;
-#endif
- }
-#endif
-
-#ifdef NEWJB
- type = JB_TYPE_CONTROL;
- len = 0;
-
- if(fr->af.frametype == AST_FRAME_VOICE) {
- type = JB_TYPE_VOICE;
- len = ast_codec_get_samples(&fr->af) / 8;
- } else if(fr->af.frametype == AST_FRAME_CNG) {
- type = JB_TYPE_SILENCE;
- }
-
- if ( (!ast_test_flag(iaxs[fr->callno], IAX_USEJITTERBUF)) ) {
- if (tsout)
- *tsout = fr->ts;
- __do_deliver(fr);
- return -1;
- }
-
- /* if the user hasn't requested we force the use of the jitterbuffer, and we're bridged to
- * a channel that can accept jitter, then flush and suspend the jb, and send this frame straight through */
- if( (!ast_test_flag(iaxs[fr->callno], IAX_FORCEJITTERBUF)) &&
- iaxs[fr->callno]->owner && ast_bridged_channel(iaxs[fr->callno]->owner) &&
- (ast_bridged_channel(iaxs[fr->callno]->owner)->tech->properties & AST_CHAN_TP_WANTSJITTER)) {
- jb_frame frame;
-
- /* deliver any frames in the jb */
- while(jb_getall(iaxs[fr->callno]->jb,&frame) == JB_OK)
- __do_deliver(frame.data);
-
- jb_reset(iaxs[fr->callno]->jb);
-
- if (iaxs[fr->callno]->jbid > -1)
- ast_sched_del(sched, iaxs[fr->callno]->jbid);
-
- iaxs[fr->callno]->jbid = -1;
-
- /* deliver this frame now */
- if (tsout)
- *tsout = fr->ts;
- __do_deliver(fr);
- return -1;
-
- }
-
-
- /* insert into jitterbuffer */
- /* TODO: Perhaps we could act immediately if it's not droppable and late */
- ret = jb_put(iaxs[fr->callno]->jb, fr, type, len, fr->ts,
- calc_rxstamp(iaxs[fr->callno],fr->ts));
- if (ret == JB_DROP) {
- needfree++;
- } else if (ret == JB_SCHED) {
- update_jbsched(iaxs[fr->callno]);
- }
-#else
- /* Just for reference, keep the "jitter" value, the difference between the
- earliest and the latest. */
- if (max >= min)
- iaxs[fr->callno]->jitter = max - min;
-
- /* IIR filter for keeping track of historic jitter, but always increase
- historic jitter immediately for increase */
-
- if (iaxs[fr->callno]->jitter > iaxs[fr->callno]->historicjitter )
- iaxs[fr->callno]->historicjitter = iaxs[fr->callno]->jitter;
- else
- iaxs[fr->callno]->historicjitter = GAMMA * (double)iaxs[fr->callno]->jitter + (1-GAMMA) *
- iaxs[fr->callno]->historicjitter;
-
- /* If our jitter buffer is too big (by a significant margin), then we slowly
- shrink it to avoid letting the change be perceived */
- if (max < iaxs[fr->callno]->jitterbuffer - max_jitter_buffer)
- iaxs[fr->callno]->jitterbuffer -= jittershrinkrate;
-
- /* If our jitter buffer headroom is too small (by a significant margin), then we slowly enlarge it */
- /* min_jitter_buffer should be SMALLER than max_jitter_buffer - leaving a "no mans land"
- in between - otherwise the jitterbuffer size will hunt up and down causing unnecessary
- disruption. Set maxexcessbuffer to say 150msec, minexcessbuffer to say 50 */
- if (max > iaxs[fr->callno]->jitterbuffer - min_jitter_buffer)
- iaxs[fr->callno]->jitterbuffer += jittershrinkrate;
-
- /* If our jitter buffer is smaller than our maximum delay, grow the jitter
- buffer immediately to accomodate it (and a little more). */
- if (max > iaxs[fr->callno]->jitterbuffer)
- iaxs[fr->callno]->jitterbuffer = max
- /* + ((float)iaxs[fr->callno]->jitter) * 0.1 */;
-
- /* update "min", just for RRs and stats */
- iaxs[fr->callno]->min = min;
-
- /* Subtract the lateness from our jitter buffer to know how long to wait
- before sending our packet. */
- delay = iaxs[fr->callno]->jitterbuffer - ms;
-
- /* Whatever happens, no frame waits longer than maxjitterbuffer */
- if (delay > maxjitterbuffer)
- delay = maxjitterbuffer;
-
- /* If jitter buffer is disabled then just pretend the frame is "right on time" */
- /* If frame came from trunk, also don't do any delay */
- if ( (!ast_test_flag(iaxs[fr->callno], IAX_USEJITTERBUF)) || fromtrunk )
- delay = 0;
-
- if (option_debug && iaxdebug) {
- /* Log jitter stats for possible offline analysis */
- ast_log(LOG_DEBUG, "Jitter: call=%d ts=%d orig=%d last=%d %s: min=%d max=%d jb=%d %+d lateness=%d jbdelay=%d jitter=%d historic=%d\n",
- fr->callno, fr->ts, orig_ts, iaxs[fr->callno]->last,
- (fr->af.frametype == AST_FRAME_VOICE) ? "VOICE" : "CONTROL",
- min, max, iaxs[fr->callno]->jitterbuffer,
- iaxs[fr->callno]->jitterbuffer - prevjitterbuffer,
- ms, delay,
- iaxs[fr->callno]->jitter, iaxs[fr->callno]->historicjitter);
- }
-
- if (delay < 1) {
- /* Don't deliver it more than 4 ms late */
- if ((delay > -4) || (fr->af.frametype != AST_FRAME_VOICE)) {
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "schedule_delivery: Delivering immediately (Calculated delay is %d)\n", delay);
- if (tsout)
- *tsout = fr->ts;
- __do_deliver(fr);
- return -1;
- } else {
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "schedule_delivery: Dropping voice packet since %dms delay is too old\n", delay);
- iaxs[fr->callno]->frames_dropped++;
- needfree++;
- }
- } else {
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "schedule_delivery: Scheduling delivery in %d ms\n", delay);
- fr->retrans = ast_sched_add(sched, delay, do_deliver, fr);
- }
-#endif
- if (tsout)
- *tsout = fr->ts;
- if (needfree) {
- /* Free our iax frame */
- iax2_frame_free(fr);
- return -1;
- }
- return 0;
-}
-
-static int iax2_transmit(struct iax_frame *fr)
-{
- /* Lock the queue and place this packet at the end */
- fr->next = NULL;
- fr->prev = NULL;
- /* By setting this to 0, the network thread will send it for us, and
- queue retransmission if necessary */
- fr->sentyet = 0;
- ast_mutex_lock(&iaxq.lock);
- if (!iaxq.head) {
- /* Empty queue */
- iaxq.head = fr;
- iaxq.tail = fr;
- } else {
- /* Double link */
- iaxq.tail->next = fr;
- fr->prev = iaxq.tail;
- iaxq.tail = fr;
- }
- iaxq.count++;
- ast_mutex_unlock(&iaxq.lock);
- /* Wake up the network thread */
- pthread_kill(netthreadid, SIGURG);
- return 0;
-}
-
-
-
-static int iax2_digit(struct ast_channel *c, char digit)
-{
- return send_command_locked(PTR_TO_CALLNO(c->tech_pvt), AST_FRAME_DTMF, digit, 0, NULL, 0, -1);
-}
-
-static int iax2_sendtext(struct ast_channel *c, const char *text)
-{
-
- return send_command_locked(PTR_TO_CALLNO(c->tech_pvt), AST_FRAME_TEXT,
- 0, 0, (unsigned char *)text, strlen(text) + 1, -1);
-}
-
-static int iax2_sendimage(struct ast_channel *c, struct ast_frame *img)
-{
- return send_command_locked(PTR_TO_CALLNO(c->tech_pvt), AST_FRAME_IMAGE, img->subclass, 0, img->data, img->datalen, -1);
-}
-
-static int iax2_sendhtml(struct ast_channel *c, int subclass, const char *data, int datalen)
-{
- return send_command_locked(PTR_TO_CALLNO(c->tech_pvt), AST_FRAME_HTML, subclass, 0, (unsigned char *)data, datalen, -1);
-}
-
-static int iax2_fixup(struct ast_channel *oldchannel, struct ast_channel *newchan)
-{
- unsigned short callno = PTR_TO_CALLNO(newchan->tech_pvt);
- ast_mutex_lock(&iaxsl[callno]);
- if (iaxs[callno])
- iaxs[callno]->owner = newchan;
- else
- ast_log(LOG_WARNING, "Uh, this isn't a good sign...\n");
- ast_mutex_unlock(&iaxsl[callno]);
- return 0;
-}
-
-static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, int temponly);
-static struct iax2_user *build_user(const char *name, struct ast_variable *v, int temponly);
-
-static void destroy_user(struct iax2_user *user);
-static int expire_registry(void *data);
-
-static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin)
-{
- struct ast_variable *var;
- struct ast_variable *tmp;
- struct iax2_peer *peer=NULL;
- time_t regseconds, nowtime;
- int dynamic=0;
-
- if (peername)
- var = ast_load_realtime("iaxpeers", "name", peername, NULL);
- else {
- char iabuf[INET_ADDRSTRLEN];
- char porta[25];
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr);
- sprintf(porta, "%d", ntohs(sin->sin_port));
- var = ast_load_realtime("iaxpeers", "ipaddr", iabuf, "port", porta, NULL);
- if (var) {
- /* We'll need the peer name in order to build the structure! */
- tmp = var;
- while(tmp) {
- if (!strcasecmp(tmp->name, "name"))
- peername = tmp->value;
- tmp = tmp->next;
- }
- }
- }
- if (!var)
- return NULL;
-
- peer = build_peer(peername, var, ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS) ? 0 : 1);
-
- if (!peer)
- return NULL;
-
- tmp = var;
- while(tmp) {
- /* Make sure it's not a user only... */
- if (!strcasecmp(tmp->name, "type")) {
- if (strcasecmp(tmp->value, "friend") &&
- strcasecmp(tmp->value, "peer")) {
- /* Whoops, we weren't supposed to exist! */
- destroy_peer(peer);
- peer = NULL;
- break;
- }
- } else if (!strcasecmp(tmp->name, "regseconds")) {
- if (sscanf(tmp->value, "%ld", (time_t *)&regseconds) != 1)
- regseconds = 0;
- } else if (!strcasecmp(tmp->name, "ipaddr")) {
- inet_aton(tmp->value, &(peer->addr.sin_addr));
- } else if (!strcasecmp(tmp->name, "port")) {
- peer->addr.sin_port = htons(atoi(tmp->value));
- } else if (!strcasecmp(tmp->name, "host")) {
- if (!strcasecmp(tmp->value, "dynamic"))
- dynamic = 1;
- }
- tmp = tmp->next;
- }
- if (!peer)
- return NULL;
-
- ast_variables_destroy(var);
-
- if (ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS)) {
- ast_copy_flags(peer, &globalflags, IAX_RTAUTOCLEAR|IAX_RTCACHEFRIENDS);
- if (ast_test_flag(peer, IAX_RTAUTOCLEAR)) {
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- peer->expire = ast_sched_add(sched, (global_rtautoclear) * 1000, expire_registry, peer);
- }
- ast_mutex_lock(&peerl.lock);
- peer->next = peerl.peers;
- peerl.peers = peer;
- ast_mutex_unlock(&peerl.lock);
- if (ast_test_flag(peer, IAX_DYNAMIC))
- reg_source_db(peer);
- } else {
- ast_set_flag(peer, IAX_TEMPONLY);
- }
-
- if (!ast_test_flag(&globalflags, IAX_RTIGNOREREGEXPIRE) && dynamic) {
- time(&nowtime);
- if ((nowtime - regseconds) > IAX_DEFAULT_REG_EXPIRE) {
- memset(&peer->addr, 0, sizeof(peer->addr));
- if (option_debug)
- ast_log(LOG_DEBUG, "realtime_peer: Bah, '%s' is expired (%d/%d/%d)!\n",
- peername, (int)(nowtime - regseconds), (int)regseconds, (int)nowtime);
- }
- else {
- if (option_debug)
- ast_log(LOG_DEBUG, "realtime_peer: Registration for '%s' still active (%d/%d/%d)!\n",
- peername, (int)(nowtime - regseconds), (int)regseconds, (int)nowtime);
- }
- }
-
- return peer;
-}
-
-static struct iax2_user *realtime_user(const char *username)
-{
- struct ast_variable *var;
- struct ast_variable *tmp;
- struct iax2_user *user=NULL;
-
- var = ast_load_realtime("iaxusers", "name", username, NULL);
- if (!var)
- return NULL;
-
- tmp = var;
- while(tmp) {
- /* Make sure it's not a peer only... */
- if (!strcasecmp(tmp->name, "type")) {
- if (strcasecmp(tmp->value, "friend") &&
- strcasecmp(tmp->value, "user")) {
- return NULL;
- }
- }
- tmp = tmp->next;
- }
-
- user = build_user(username, var, !ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS));
- if (!user)
- return NULL;
-
- ast_variables_destroy(var);
-
- if (ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS)) {
- ast_set_flag(user, IAX_RTCACHEFRIENDS);
- ast_mutex_lock(&userl.lock);
- user->next = userl.users;
- userl.users = user;
- ast_mutex_unlock(&userl.lock);
- } else {
- ast_set_flag(user, IAX_TEMPONLY);
- }
-
- return user;
-}
-
-static void realtime_update_peer(const char *peername, struct sockaddr_in *sin)
-{
- char port[10];
- char ipaddr[20];
- char regseconds[20];
- time_t nowtime;
-
- time(&nowtime);
- snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);
- ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
- snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
- ast_update_realtime("iaxpeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, NULL);
-}
-
-struct create_addr_info {
- int capability;
- unsigned int flags;
- int maxtime;
- int encmethods;
- int found;
- int sockfd;
- char username[80];
- char secret[80];
- char outkey[80];
- char timezone[80];
- char prefs[32];
- char context[AST_MAX_CONTEXT];
- char peercontext[AST_MAX_CONTEXT];
-};
-
-static int create_addr(const char *peername, struct sockaddr_in *sin, struct create_addr_info *cai)
-{
- struct ast_hostent ahp;
- struct hostent *hp;
- struct iax2_peer *peer;
-
- ast_clear_flag(cai, IAX_SENDANI | IAX_TRUNK);
- cai->sockfd = defaultsockfd;
- cai->maxtime = 0;
- sin->sin_family = AF_INET;
-
- if (!(peer = find_peer(peername, 1))) {
- cai->found = 0;
-
- hp = ast_gethostbyname(peername, &ahp);
- if (hp) {
- memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr));
- sin->sin_port = htons(IAX_DEFAULT_PORTNO);
- /* use global iax prefs for unknown peer/user */
- ast_codec_pref_convert(&prefs, cai->prefs, sizeof(cai->prefs), 1);
- return 0;
- } else {
- ast_log(LOG_WARNING, "No such host: %s\n", peername);
- return -1;
- }
- }
-
- cai->found = 1;
-
- /* if the peer has no address (current or default), return failure */
- if (!(peer->addr.sin_addr.s_addr || peer->defaddr.sin_addr.s_addr)) {
- if (ast_test_flag(peer, IAX_TEMPONLY))
- destroy_peer(peer);
- return -1;
- }
-
- /* if the peer is being monitored and is currently unreachable, return failure */
- if (peer->maxms && ((peer->lastms > peer->maxms) || (peer->lastms < 0))) {
- if (ast_test_flag(peer, IAX_TEMPONLY))
- destroy_peer(peer);
- return -1;
- }
-
- ast_copy_flags(cai, peer, IAX_SENDANI | IAX_TRUNK | IAX_NOTRANSFER | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
- cai->maxtime = peer->maxms;
- cai->capability = peer->capability;
- cai->encmethods = peer->encmethods;
- cai->sockfd = peer->sockfd;
- ast_codec_pref_convert(&peer->prefs, cai->prefs, sizeof(cai->prefs), 1);
- ast_copy_string(cai->context, peer->context, sizeof(cai->context));
- ast_copy_string(cai->peercontext, peer->peercontext, sizeof(cai->peercontext));
- ast_copy_string(cai->username, peer->username, sizeof(cai->username));
- ast_copy_string(cai->timezone, peer->zonetag, sizeof(cai->timezone));
- ast_copy_string(cai->outkey, peer->outkey, sizeof(cai->outkey));
- if (ast_strlen_zero(peer->dbsecret)) {
- ast_copy_string(cai->secret, peer->secret, sizeof(cai->secret));
- } else {
- char *family;
- char *key = NULL;
-
- family = ast_strdupa(peer->dbsecret);
- if (family) {
- key = strchr(family, '/');
- if (key)
- *key++ = '\0';
- }
- if (!family || !key || ast_db_get(family, key, cai->secret, sizeof(cai->secret))) {
- ast_log(LOG_WARNING, "Unable to retrieve database password for family/key '%s'!\n", peer->dbsecret);
- if (ast_test_flag(peer, IAX_TEMPONLY))
- destroy_peer(peer);
- return -1;
- }
- }
-
- if (peer->addr.sin_addr.s_addr) {
- sin->sin_addr = peer->addr.sin_addr;
- sin->sin_port = peer->addr.sin_port;
- } else {
- sin->sin_addr = peer->defaddr.sin_addr;
- sin->sin_port = peer->defaddr.sin_port;
- }
-
- if (ast_test_flag(peer, IAX_TEMPONLY))
- destroy_peer(peer);
-
- return 0;
-}
-
-static int auto_congest(void *nothing)
-{
- int callno = PTR_TO_CALLNO(nothing);
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_CONGESTION };
- ast_mutex_lock(&iaxsl[callno]);
- if (iaxs[callno]) {
- iaxs[callno]->initid = -1;
- iax2_queue_frame(callno, &f);
- ast_log(LOG_NOTICE, "Auto-congesting call due to slow response\n");
- }
- ast_mutex_unlock(&iaxsl[callno]);
- return 0;
-}
-
-static unsigned int iax2_datetime(char *tz)
-{
- time_t t;
- struct tm tm;
- unsigned int tmp;
- time(&t);
- localtime_r(&t, &tm);
- if (!ast_strlen_zero(tz))
- ast_localtime(&t, &tm, tz);
- tmp = (tm.tm_sec >> 1) & 0x1f; /* 5 bits of seconds */
- tmp |= (tm.tm_min & 0x3f) << 5; /* 6 bits of minutes */
- tmp |= (tm.tm_hour & 0x1f) << 11; /* 5 bits of hours */
- tmp |= (tm.tm_mday & 0x1f) << 16; /* 5 bits of day of month */
- tmp |= ((tm.tm_mon + 1) & 0xf) << 21; /* 4 bits of month */
- tmp |= ((tm.tm_year - 100) & 0x7f) << 25; /* 7 bits of year */
- return tmp;
-}
-
-struct parsed_dial_string {
- char *username;
- char *password;
- char *key;
- char *peer;
- char *port;
- char *exten;
- char *context;
- char *options;
-};
-
-/*!
- * \brief Parses an IAX dial string into its component parts.
- * \param data the string to be parsed
- * \param pds pointer to a \c struct \c parsed_dial_string to be filled in
- * \return nothing
- *
- * This function parses the string and fills the structure
- * with pointers to its component parts. The input string
- * will be modified.
- *
- * \note This function supports both plaintext passwords and RSA
- * key names; if the password string is formatted as '[keyname]',
- * then the keyname will be placed into the key field, and the
- * password field will be set to NULL.
- *
- * \note The dial string format is:
- * [username[:password]@]peer[:port][/exten[@@context]][/options]
- */
-static void parse_dial_string(char *data, struct parsed_dial_string *pds)
-{
- if (ast_strlen_zero(data))
- return;
-
- pds->peer = strsep(&data, "/");
- pds->exten = strsep(&data, "/");
- pds->options = data;
-
- if (pds->exten) {
- data = pds->exten;
- pds->exten = strsep(&data, "@");
- pds->context = data;
- }
-
- if (strchr(pds->peer, '@')) {
- data = pds->peer;
- pds->username = strsep(&data, "@");
- pds->peer = data;
- }
-
- if (pds->username) {
- data = pds->username;
- pds->username = strsep(&data, ":");
- pds->password = data;
- }
-
- data = pds->peer;
- pds->peer = strsep(&data, ":");
- pds->port = data;
-
- /* check for a key name wrapped in [] in the secret position, if found,
- move it to the key field instead
- */
- if (pds->password && (pds->password[0] == '[')) {
- pds->key = ast_strip_quoted(pds->password, "[", "]");
- pds->password = NULL;
- }
-}
-
-static int iax2_call(struct ast_channel *c, char *dest, int timeout)
-{
- struct sockaddr_in sin;
- char *l=NULL, *n=NULL, *tmpstr;
- struct iax_ie_data ied;
- char *defaultrdest = "s";
- unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
- struct parsed_dial_string pds;
- struct create_addr_info cai;
-
- if ((c->_state != AST_STATE_DOWN) && (c->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "Channel is already in use (%s)?\n", c->name);
- return -1;
- }
-
- memset(&cai, 0, sizeof(cai));
- cai.encmethods = iax2_encryption;
-
- memset(&pds, 0, sizeof(pds));
- tmpstr = ast_strdupa(dest);
- parse_dial_string(tmpstr, &pds);
-
- if (!pds.exten)
- pds.exten = defaultrdest;
-
- if (create_addr(pds.peer, &sin, &cai)) {
- ast_log(LOG_WARNING, "No address associated with '%s'\n", pds.peer);
- return -1;
- }
-
- if (!pds.username && !ast_strlen_zero(cai.username))
- pds.username = cai.username;
- if (!pds.password && !ast_strlen_zero(cai.secret))
- pds.password = cai.secret;
- if (!pds.key && !ast_strlen_zero(cai.outkey))
- pds.key = cai.outkey;
- if (!pds.context && !ast_strlen_zero(cai.peercontext))
- pds.context = cai.peercontext;
-
- /* Keep track of the context for outgoing calls too */
- ast_copy_string(c->context, cai.context, sizeof(c->context));
-
- if (pds.port)
- sin.sin_port = htons(atoi(pds.port));
-
- l = c->cid.cid_num;
- n = c->cid.cid_name;
-
- /* Now build request */
- memset(&ied, 0, sizeof(ied));
-
- /* On new call, first IE MUST be IAX version of caller */
- iax_ie_append_short(&ied, IAX_IE_VERSION, IAX_PROTO_VERSION);
- iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, pds.exten);
- if (pds.options && strchr(pds.options, 'a')) {
- /* Request auto answer */
- iax_ie_append(&ied, IAX_IE_AUTOANSWER);
- }
-
- iax_ie_append_str(&ied, IAX_IE_CODEC_PREFS, cai.prefs);
-
- if (l) {
- iax_ie_append_str(&ied, IAX_IE_CALLING_NUMBER, l);
- iax_ie_append_byte(&ied, IAX_IE_CALLINGPRES, c->cid.cid_pres);
- } else {
- if (n)
- iax_ie_append_byte(&ied, IAX_IE_CALLINGPRES, c->cid.cid_pres);
- else
- iax_ie_append_byte(&ied, IAX_IE_CALLINGPRES, AST_PRES_NUMBER_NOT_AVAILABLE);
- }
-
- iax_ie_append_byte(&ied, IAX_IE_CALLINGTON, c->cid.cid_ton);
- iax_ie_append_short(&ied, IAX_IE_CALLINGTNS, c->cid.cid_tns);
-
- if (n)
- iax_ie_append_str(&ied, IAX_IE_CALLING_NAME, n);
- if (ast_test_flag(iaxs[callno], IAX_SENDANI) && c->cid.cid_ani)
- iax_ie_append_str(&ied, IAX_IE_CALLING_ANI, c->cid.cid_ani);
-
- if (!ast_strlen_zero(c->language))
- iax_ie_append_str(&ied, IAX_IE_LANGUAGE, c->language);
- if (!ast_strlen_zero(c->cid.cid_dnid))
- iax_ie_append_str(&ied, IAX_IE_DNID, c->cid.cid_dnid);
-
- if (pds.context)
- iax_ie_append_str(&ied, IAX_IE_CALLED_CONTEXT, pds.context);
-
- if (pds.username)
- iax_ie_append_str(&ied, IAX_IE_USERNAME, pds.username);
-
- if (cai.encmethods)
- iax_ie_append_short(&ied, IAX_IE_ENCRYPTION, cai.encmethods);
-
- ast_mutex_lock(&iaxsl[callno]);
-
- if (!ast_strlen_zero(c->context))
- ast_copy_string(iaxs[callno]->context, c->context, sizeof(iaxs[callno]->context));
-
- if (pds.username)
- ast_copy_string(iaxs[callno]->username, pds.username, sizeof(iaxs[callno]->username));
-
- iaxs[callno]->encmethods = cai.encmethods;
-
- if (pds.key)
- ast_copy_string(iaxs[callno]->outkey, pds.key, sizeof(iaxs[callno]->outkey));
- if (pds.password)
- ast_copy_string(iaxs[callno]->secret, pds.password, sizeof(iaxs[callno]->secret));
-
- iax_ie_append_int(&ied, IAX_IE_FORMAT, c->nativeformats);
- iax_ie_append_int(&ied, IAX_IE_CAPABILITY, iaxs[callno]->capability);
- iax_ie_append_short(&ied, IAX_IE_ADSICPE, c->adsicpe);
- iax_ie_append_int(&ied, IAX_IE_DATETIME, iax2_datetime(cai.timezone));
-
- if (iaxs[callno]->maxtime) {
- /* Initialize pingtime and auto-congest time */
- iaxs[callno]->pingtime = iaxs[callno]->maxtime / 2;
- iaxs[callno]->initid = ast_sched_add(sched, iaxs[callno]->maxtime * 2, auto_congest, CALLNO_TO_PTR(callno));
- } else if (autokill) {
- iaxs[callno]->pingtime = autokill / 2;
- iaxs[callno]->initid = ast_sched_add(sched, autokill * 2, auto_congest, CALLNO_TO_PTR(callno));
- }
-
- /* Transmit the string in a "NEW" request */
- send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_NEW, 0, ied.buf, ied.pos, -1);
-
- ast_mutex_unlock(&iaxsl[callno]);
- ast_setstate(c, AST_STATE_RINGING);
-
- return 0;
-}
-
-static int iax2_hangup(struct ast_channel *c)
-{
- unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
- int alreadygone;
- struct iax_ie_data ied;
- memset(&ied, 0, sizeof(ied));
- ast_mutex_lock(&iaxsl[callno]);
- if (callno && iaxs[callno]) {
- ast_log(LOG_DEBUG, "We're hanging up %s now...\n", c->name);
- alreadygone = ast_test_flag(iaxs[callno], IAX_ALREADYGONE);
- /* Send the hangup unless we have had a transmission error or are already gone */
- iax_ie_append_byte(&ied, IAX_IE_CAUSECODE, (unsigned char)c->hangupcause);
- if (!iaxs[callno]->error && !alreadygone)
- send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_HANGUP, 0, ied.buf, ied.pos, -1);
- /* Explicitly predestroy it */
- iax2_predestroy_nolock(callno);
- /* If we were already gone to begin with, destroy us now */
- if (alreadygone) {
- ast_log(LOG_DEBUG, "Really destroying %s now...\n", c->name);
- iax2_destroy_nolock(callno);
- }
- }
- ast_mutex_unlock(&iaxsl[callno]);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Hungup '%s'\n", c->name);
- return 0;
-}
-
-static int iax2_setoption(struct ast_channel *c, int option, void *data, int datalen)
-{
- struct ast_option_header *h;
- int res;
-
- switch (option) {
- case AST_OPTION_TXGAIN:
- case AST_OPTION_RXGAIN:
- /* these two cannot be sent, because they require a result */
- errno = ENOSYS;
- return -1;
- default:
- h = malloc(datalen + sizeof(*h));
- if (h) {
- h->flag = AST_OPTION_FLAG_REQUEST;
- h->option = htons(option);
- memcpy(h->data, data, datalen);
- res = send_command_locked(PTR_TO_CALLNO(c->tech_pvt), AST_FRAME_CONTROL,
- AST_CONTROL_OPTION, 0, (unsigned char *) h,
- datalen + sizeof(*h), -1);
- free(h);
- return res;
- } else {
- ast_log(LOG_WARNING, "Out of memory\n");
- return -1;
- }
- }
-}
-
-static struct ast_frame *iax2_read(struct ast_channel *c)
-{
- static struct ast_frame f = { AST_FRAME_NULL, };
- ast_log(LOG_NOTICE, "I should never be called!\n");
- return &f;
-}
-
-static int iax2_start_transfer(unsigned short callno0, unsigned short callno1)
-{
- int res;
- struct iax_ie_data ied0;
- struct iax_ie_data ied1;
- unsigned int transferid = rand();
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_addr(&ied0, IAX_IE_APPARENT_ADDR, &iaxs[callno1]->addr);
- iax_ie_append_short(&ied0, IAX_IE_CALLNO, iaxs[callno1]->peercallno);
- iax_ie_append_int(&ied0, IAX_IE_TRANSFERID, transferid);
-
- memset(&ied1, 0, sizeof(ied1));
- iax_ie_append_addr(&ied1, IAX_IE_APPARENT_ADDR, &iaxs[callno0]->addr);
- iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[callno0]->peercallno);
- iax_ie_append_int(&ied1, IAX_IE_TRANSFERID, transferid);
-
- res = send_command(iaxs[callno0], AST_FRAME_IAX, IAX_COMMAND_TXREQ, 0, ied0.buf, ied0.pos, -1);
- if (res)
- return -1;
- res = send_command(iaxs[callno1], AST_FRAME_IAX, IAX_COMMAND_TXREQ, 0, ied1.buf, ied1.pos, -1);
- if (res)
- return -1;
- iaxs[callno0]->transferring = TRANSFER_BEGIN;
- iaxs[callno1]->transferring = TRANSFER_BEGIN;
- return 0;
-}
-
-static void lock_both(unsigned short callno0, unsigned short callno1)
-{
- ast_mutex_lock(&iaxsl[callno0]);
- while (ast_mutex_trylock(&iaxsl[callno1])) {
- ast_mutex_unlock(&iaxsl[callno0]);
- usleep(10);
- ast_mutex_lock(&iaxsl[callno0]);
- }
-}
-
-static void unlock_both(unsigned short callno0, unsigned short callno1)
-{
- ast_mutex_unlock(&iaxsl[callno1]);
- ast_mutex_unlock(&iaxsl[callno0]);
-}
-
-static enum ast_bridge_result iax2_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms)
-{
- struct ast_channel *cs[3];
- struct ast_channel *who;
- int to = -1;
- int res = -1;
- int transferstarted=0;
- struct ast_frame *f;
- unsigned short callno0 = PTR_TO_CALLNO(c0->tech_pvt);
- unsigned short callno1 = PTR_TO_CALLNO(c1->tech_pvt);
- struct timeval waittimer = {0, 0}, tv;
-
- lock_both(callno0, callno1);
- /* Put them in native bridge mode */
- if (!flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1)) {
- iaxs[callno0]->bridgecallno = callno1;
- iaxs[callno1]->bridgecallno = callno0;
- }
- unlock_both(callno0, callno1);
-
- /* If not, try to bridge until we can execute a transfer, if we can */
- cs[0] = c0;
- cs[1] = c1;
- for (/* ever */;;) {
- /* Check in case we got masqueraded into */
- if ((c0->type != channeltype) || (c1->type != channeltype)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Can't masquerade, we're different...\n");
- /* Remove from native mode */
- if (c0->type == channeltype) {
- ast_mutex_lock(&iaxsl[callno0]);
- iaxs[callno0]->bridgecallno = 0;
- ast_mutex_unlock(&iaxsl[callno0]);
- }
- if (c1->type == channeltype) {
- ast_mutex_lock(&iaxsl[callno1]);
- iaxs[callno1]->bridgecallno = 0;
- ast_mutex_unlock(&iaxsl[callno1]);
- }
- return AST_BRIDGE_FAILED_NOWARN;
- }
- if (c0->nativeformats != c1->nativeformats) {
- if (option_verbose > 2) {
- char buf0[255];
- char buf1[255];
- ast_getformatname_multiple(buf0, sizeof(buf0) -1, c0->nativeformats);
- ast_getformatname_multiple(buf1, sizeof(buf1) -1, c1->nativeformats);
- ast_verbose(VERBOSE_PREFIX_3 "Operating with different codecs %d[%s] %d[%s] , can't native bridge...\n", c0->nativeformats, buf0, c1->nativeformats, buf1);
- }
- /* Remove from native mode */
- lock_both(callno0, callno1);
- iaxs[callno0]->bridgecallno = 0;
- iaxs[callno1]->bridgecallno = 0;
- unlock_both(callno0, callno1);
- return AST_BRIDGE_FAILED_NOWARN;
- }
- /* check if transfered and if we really want native bridging */
- if (!transferstarted && !ast_test_flag(iaxs[callno0], IAX_NOTRANSFER) && !ast_test_flag(iaxs[callno1], IAX_NOTRANSFER) &&
- !(flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1))) {
- /* Try the transfer */
- if (iax2_start_transfer(callno0, callno1))
- ast_log(LOG_WARNING, "Unable to start the transfer\n");
- transferstarted = 1;
- }
- if ((iaxs[callno0]->transferring == TRANSFER_RELEASED) && (iaxs[callno1]->transferring == TRANSFER_RELEASED)) {
- /* Call has been transferred. We're no longer involved */
- gettimeofday(&tv, NULL);
- if (ast_tvzero(waittimer)) {
- waittimer = tv;
- } else if (tv.tv_sec - waittimer.tv_sec > IAX_LINGER_TIMEOUT) {
- c0->_softhangup |= AST_SOFTHANGUP_DEV;
- c1->_softhangup |= AST_SOFTHANGUP_DEV;
- *fo = NULL;
- *rc = c0;
- res = AST_BRIDGE_COMPLETE;
- break;
- }
- }
- to = 1000;
- who = ast_waitfor_n(cs, 2, &to);
- if (timeoutms > -1) {
- timeoutms -= (1000 - to);
- if (timeoutms < 0)
- timeoutms = 0;
- }
- if (!who) {
- if (!timeoutms) {
- res = AST_BRIDGE_RETRY;
- break;
- }
- if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
- res = AST_BRIDGE_FAILED;
- break;
- }
- continue;
- }
- f = ast_read(who);
- if (!f) {
- *fo = NULL;
- *rc = who;
- res = AST_BRIDGE_COMPLETE;
- break;
- }
- if ((f->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
- *fo = f;
- *rc = who;
- res = AST_BRIDGE_COMPLETE;
- break;
- }
- if ((f->frametype == AST_FRAME_VOICE) ||
- (f->frametype == AST_FRAME_TEXT) ||
- (f->frametype == AST_FRAME_VIDEO) ||
- (f->frametype == AST_FRAME_IMAGE) ||
- (f->frametype == AST_FRAME_DTMF)) {
- if ((f->frametype == AST_FRAME_DTMF) &&
- (flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1))) {
- if ((who == c0)) {
- if ((flags & AST_BRIDGE_DTMF_CHANNEL_0)) {
- *rc = c0;
- *fo = f;
- res = AST_BRIDGE_COMPLETE;
- /* Remove from native mode */
- break;
- } else
- goto tackygoto;
- } else
- if ((who == c1)) {
- if (flags & AST_BRIDGE_DTMF_CHANNEL_1) {
- *rc = c1;
- *fo = f;
- res = AST_BRIDGE_COMPLETE;
- break;
- } else
- goto tackygoto;
- }
- } else {
-#if 0
- if (iaxdebug && option_debug)
- ast_log(LOG_DEBUG, "Read from %s\n", who->name);
- if (who == last)
- ast_log(LOG_DEBUG, "Servicing channel %s twice in a row?\n", last->name);
- last = who;
-#endif
-tackygoto:
- if (who == c0)
- ast_write(c1, f);
- else
- ast_write(c0, f);
- }
- ast_frfree(f);
- } else
- ast_frfree(f);
- /* Swap who gets priority */
- cs[2] = cs[0];
- cs[0] = cs[1];
- cs[1] = cs[2];
- }
- lock_both(callno0, callno1);
- if(iaxs[callno0])
- iaxs[callno0]->bridgecallno = 0;
- if(iaxs[callno1])
- iaxs[callno1]->bridgecallno = 0;
- unlock_both(callno0, callno1);
- return res;
-}
-
-static int iax2_answer(struct ast_channel *c)
-{
- unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
- if (option_debug)
- ast_log(LOG_DEBUG, "Answering IAX2 call\n");
- return send_command_locked(callno, AST_FRAME_CONTROL, AST_CONTROL_ANSWER, 0, NULL, 0, -1);
-}
-
-static int iax2_indicate(struct ast_channel *c, int condition)
-{
- unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Indicating condition %d\n", condition);
- return send_command_locked(callno, AST_FRAME_CONTROL, condition, 0, NULL, 0, -1);
-}
-
-static int iax2_transfer(struct ast_channel *c, const char *dest)
-{
- unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
- struct iax_ie_data ied;
- char tmp[256], *context;
- ast_copy_string(tmp, dest, sizeof(tmp));
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- }
- memset(&ied, 0, sizeof(ied));
- iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, tmp);
- if (context)
- iax_ie_append_str(&ied, IAX_IE_CALLED_CONTEXT, context);
- if (option_debug)
- ast_log(LOG_DEBUG, "Transferring '%s' to '%s'\n", c->name, dest);
- return send_command_locked(callno, AST_FRAME_IAX, IAX_COMMAND_TRANSFER, 0, ied.buf, ied.pos, -1);
-}
-
-
-static int iax2_write(struct ast_channel *c, struct ast_frame *f);
-
-static int iax2_getpeertrunk(struct sockaddr_in sin)
-{
- struct iax2_peer *peer;
- int res = 0;
- ast_mutex_lock(&peerl.lock);
- peer = peerl.peers;
- while(peer) {
- if ((peer->addr.sin_addr.s_addr == sin.sin_addr.s_addr) &&
- (peer->addr.sin_port == sin.sin_port)) {
- res = ast_test_flag(peer, IAX_TRUNK);
- break;
- }
- peer = peer->next;
- }
- ast_mutex_unlock(&peerl.lock);
- return res;
-}
-
-/*--- ast_iax2_new: Create new call, interface with the PBX core */
-static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
-{
- struct ast_channel *tmp;
- struct chan_iax2_pvt *i;
- struct ast_variable *v = NULL;
-
- /* Don't hold call lock */
- ast_mutex_unlock(&iaxsl[callno]);
- tmp = ast_channel_alloc(1);
- ast_mutex_lock(&iaxsl[callno]);
- i = iaxs[callno];
- if (i && tmp) {
- tmp->tech = &iax2_tech;
- snprintf(tmp->name, sizeof(tmp->name), "IAX2/%s-%d", i->host, i->callno);
- tmp->type = channeltype;
- /* We can support any format by default, until we get restricted */
- tmp->nativeformats = capability;
- tmp->readformat = ast_best_codec(capability);
- tmp->writeformat = ast_best_codec(capability);
- tmp->tech_pvt = CALLNO_TO_PTR(i->callno);
-
- if (!ast_strlen_zero(i->cid_num))
- tmp->cid.cid_num = strdup(i->cid_num);
- if (!ast_strlen_zero(i->cid_name))
- tmp->cid.cid_name = strdup(i->cid_name);
- if (!ast_strlen_zero(i->ani))
- tmp->cid.cid_ani = strdup(i->ani);
- if (!ast_strlen_zero(i->language))
- ast_copy_string(tmp->language, i->language, sizeof(tmp->language));
- if (!ast_strlen_zero(i->dnid))
- tmp->cid.cid_dnid = strdup(i->dnid);
- tmp->cid.cid_pres = i->calling_pres;
- tmp->cid.cid_ton = i->calling_ton;
- tmp->cid.cid_tns = i->calling_tns;
- if (!ast_strlen_zero(i->accountcode))
- ast_copy_string(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode));
- if (i->amaflags)
- tmp->amaflags = i->amaflags;
- ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
- ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
- tmp->adsicpe = i->peeradsicpe;
- i->owner = tmp;
- i->capability = capability;
- ast_setstate(tmp, state);
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- tmp = NULL;
- }
- }
- for (v = i->vars ; v ; v = v->next)
- pbx_builtin_setvar_helper(tmp,v->name,v->value);
-
- }
- return tmp;
-}
-
-static unsigned int calc_txpeerstamp(struct iax2_trunk_peer *tpeer, int sampms, struct timeval *tv)
-{
- unsigned long int mssincetx; /* unsigned to handle overflows */
- long int ms, pred;
-
- tpeer->trunkact = *tv;
- mssincetx = ast_tvdiff_ms(*tv, tpeer->lasttxtime);
- if (mssincetx > 5000 || ast_tvzero(tpeer->txtrunktime)) {
- /* If it's been at least 5 seconds since the last time we transmitted on this trunk, reset our timers */
- tpeer->txtrunktime = *tv;
- tpeer->lastsent = 999999;
- }
- /* Update last transmit time now */
- tpeer->lasttxtime = *tv;
-
- /* Calculate ms offset */
- ms = ast_tvdiff_ms(*tv, tpeer->txtrunktime);
- /* Predict from last value */
- pred = tpeer->lastsent + sampms;
- if (abs(ms - pred) < MAX_TIMESTAMP_SKEW)
- ms = pred;
-
- /* We never send the same timestamp twice, so fudge a little if we must */
- if (ms == tpeer->lastsent)
- ms = tpeer->lastsent + 1;
- tpeer->lastsent = ms;
- return ms;
-}
-
-static unsigned int fix_peerts(struct timeval *tv, int callno, unsigned int ts)
-{
- long ms; /* NOT unsigned */
- if (ast_tvzero(iaxs[callno]->rxcore)) {
- /* Initialize rxcore time if appropriate */
- gettimeofday(&iaxs[callno]->rxcore, NULL);
- /* Round to nearest 20ms so traces look pretty */
- iaxs[callno]->rxcore.tv_usec -= iaxs[callno]->rxcore.tv_usec % 20000;
- }
- /* Calculate difference between trunk and channel */
- ms = ast_tvdiff_ms(*tv, iaxs[callno]->rxcore);
- /* Return as the sum of trunk time and the difference between trunk and real time */
- return ms + ts;
-}
-
-static unsigned int calc_timestamp(struct chan_iax2_pvt *p, unsigned int ts, struct ast_frame *f)
-{
- int ms;
- int voice = 0;
- int genuine = 0;
- int adjust;
- struct timeval *delivery = NULL;
-
-
- /* What sort of frame do we have?: voice is self-explanatory
- "genuine" means an IAX frame - things like LAGRQ/RP, PING/PONG, ACK
- non-genuine frames are CONTROL frames [ringing etc], DTMF
- The "genuine" distinction is needed because genuine frames must get a clock-based timestamp,
- the others need a timestamp slaved to the voice frames so that they go in sequence
- */
- if (f) {
- if (f->frametype == AST_FRAME_VOICE) {
- voice = 1;
- delivery = &f->delivery;
- } else if (f->frametype == AST_FRAME_IAX) {
- genuine = 1;
- } else if (f->frametype == AST_FRAME_CNG) {
- p->notsilenttx = 0;
- }
- }
- if (ast_tvzero(p->offset)) {
- gettimeofday(&p->offset, NULL);
- /* Round to nearest 20ms for nice looking traces */
- p->offset.tv_usec -= p->offset.tv_usec % 20000;
- }
- /* If the timestamp is specified, just send it as is */
- if (ts)
- return ts;
- /* If we have a time that the frame arrived, always use it to make our timestamp */
- if (delivery && !ast_tvzero(*delivery)) {
- ms = ast_tvdiff_ms(*delivery, p->offset);
- if (option_debug > 2 && iaxdebug)
- ast_log(LOG_DEBUG, "calc_timestamp: call %d/%d: Timestamp slaved to delivery time\n", p->callno, iaxs[p->callno]->peercallno);
- } else {
- ms = ast_tvdiff_ms(ast_tvnow(), p->offset);
- if (ms < 0)
- ms = 0;
- if (voice) {
- /* On a voice frame, use predicted values if appropriate */
- if (p->notsilenttx && abs(ms - p->nextpred) <= MAX_TIMESTAMP_SKEW) {
- /* Adjust our txcore, keeping voice and non-voice synchronized */
- /* AN EXPLANATION:
- When we send voice, we usually send "calculated" timestamps worked out
- on the basis of the number of samples sent. When we send other frames,
- we usually send timestamps worked out from the real clock.
- The problem is that they can tend to drift out of step because the
- source channel's clock and our clock may not be exactly at the same rate.
- We fix this by continuously "tweaking" p->offset. p->offset is "time zero"
- for this call. Moving it adjusts timestamps for non-voice frames.
- We make the adjustment in the style of a moving average. Each time we
- adjust p->offset by 10% of the difference between our clock-derived
- timestamp and the predicted timestamp. That's why you see "10000"
- below even though IAX2 timestamps are in milliseconds.
- The use of a moving average avoids offset moving too radically.
- Generally, "adjust" roams back and forth around 0, with offset hardly
- changing at all. But if a consistent different starts to develop it
- will be eliminated over the course of 10 frames (200-300msecs)
- */
- adjust = (ms - p->nextpred);
- if (adjust < 0)
- p->offset = ast_tvsub(p->offset, ast_samp2tv(abs(adjust), 10000));
- else if (adjust > 0)
- p->offset = ast_tvadd(p->offset, ast_samp2tv(adjust, 10000));
-
- if (!p->nextpred) {
- p->nextpred = ms; /*f->samples / 8;*/
- if (p->nextpred <= p->lastsent)
- p->nextpred = p->lastsent + 3;
- }
- ms = p->nextpred;
- } else {
- /* in this case, just use the actual
- * time, since we're either way off
- * (shouldn't happen), or we're ending a
- * silent period -- and seed the next
- * predicted time. Also, round ms to the
- * next multiple of frame size (so our
- * silent periods are multiples of
- * frame size too) */
-
- if (iaxdebug && abs(ms - p->nextpred) > MAX_TIMESTAMP_SKEW )
- ast_log(LOG_DEBUG, "predicted timestamp skew (%u) > max (%u), using real ts instead.\n",
- abs(ms - p->nextpred), MAX_TIMESTAMP_SKEW);
-
- if (f->samples >= 8) /* check to make sure we dont core dump */
- {
- int diff = ms % (f->samples / 8);
- if (diff)
- ms += f->samples/8 - diff;
- }
-
- p->nextpred = ms;
- p->notsilenttx = 1;
- }
- } else {
- /* On a dataframe, use last value + 3 (to accomodate jitter buffer shrinking) if appropriate unless
- it's a genuine frame */
- if (genuine) {
- /* genuine (IAX LAGRQ etc) must keep their clock-based stamps */
- if (ms <= p->lastsent)
- ms = p->lastsent + 3;
- } else if (abs(ms - p->lastsent) <= MAX_TIMESTAMP_SKEW) {
- /* non-genuine frames (!?) (DTMF, CONTROL) should be pulled into the predicted stream stamps */
- ms = p->lastsent + 3;
- }
- }
- }
- p->lastsent = ms;
- if (voice)
- p->nextpred = p->nextpred + f->samples / 8;
-#if 0
- printf("TS: %s - %dms\n", voice ? "Audio" : "Control", ms);
-#endif
- return ms;
-}
-
-#ifdef BRIDGE_OPTIMIZATION
-static unsigned int calc_fakestamp(struct chan_iax2_pvt *p1, struct chan_iax2_pvt *p2, unsigned int fakets)
-{
- int ms;
- /* Receive from p1, send to p2 */
-
- /* Setup rxcore if necessary on outgoing channel */
- if (ast_tvzero(p1->rxcore))
- p1->rxcore = ast_tvnow();
-
- /* Setup txcore if necessary on outgoing channel */
- if (ast_tvzero(p2->offset))
- p2->offset = ast_tvnow();
-
- /* Now, ts is the timestamp of the original packet in the orignal context.
- Adding rxcore to it gives us when we would want the packet to be delivered normally.
- Subtracting txcore of the outgoing channel gives us what we'd expect */
-
- ms = ast_tvdiff_ms(p1->rxcore, p2->offset);
- fakets += ms;
-
- p2->lastsent = fakets;
- return fakets;
-}
-#endif
-
-static unsigned int calc_rxstamp(struct chan_iax2_pvt *p, unsigned int offset)
-{
- /* Returns where in "receive time" we are. That is, how many ms
- since we received (or would have received) the frame with timestamp 0 */
- int ms;
-#ifdef IAXTESTS
- int jit;
-#endif /* IAXTESTS */
- /* Setup rxcore if necessary */
- if (ast_tvzero(p->rxcore)) {
- p->rxcore = ast_tvnow();
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "calc_rxstamp: call=%d: rxcore set to %d.%6.6d - %dms\n",
- p->callno, (int)(p->rxcore.tv_sec), (int)(p->rxcore.tv_usec), offset);
- p->rxcore = ast_tvsub(p->rxcore, ast_samp2tv(offset, 1000));
-#if 1
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "calc_rxstamp: call=%d: works out as %d.%6.6d\n",
- p->callno, (int)(p->rxcore.tv_sec),(int)( p->rxcore.tv_usec));
-#endif
- }
-
- ms = ast_tvdiff_ms(ast_tvnow(), p->rxcore);
-#ifdef IAXTESTS
- if (test_jit) {
- if (!test_jitpct || ((100.0 * rand() / (RAND_MAX + 1.0)) < test_jitpct)) {
- jit = (int)((float)test_jit * rand() / (RAND_MAX + 1.0));
- if ((int)(2.0 * rand() / (RAND_MAX + 1.0)))
- jit = -jit;
- ms += jit;
- }
- }
- if (test_late) {
- ms += test_late;
- test_late = 0;
- }
-#endif /* IAXTESTS */
- return ms;
-}
-
-static struct iax2_trunk_peer *find_tpeer(struct sockaddr_in *sin, int fd)
-{
- struct iax2_trunk_peer *tpeer;
- char iabuf[INET_ADDRSTRLEN];
- /* Finds and locks trunk peer */
- ast_mutex_lock(&tpeerlock);
- tpeer = tpeers;
- while(tpeer) {
- /* We don't lock here because tpeer->addr *never* changes */
- if (!inaddrcmp(&tpeer->addr, sin)) {
- ast_mutex_lock(&tpeer->lock);
- break;
- }
- tpeer = tpeer->next;
- }
- if (!tpeer) {
- tpeer = malloc(sizeof(struct iax2_trunk_peer));
- if (tpeer) {
- memset(tpeer, 0, sizeof(struct iax2_trunk_peer));
- ast_mutex_init(&tpeer->lock);
- tpeer->lastsent = 9999;
- memcpy(&tpeer->addr, sin, sizeof(tpeer->addr));
- tpeer->trunkact = ast_tvnow();
- ast_mutex_lock(&tpeer->lock);
- tpeer->next = tpeers;
- tpeer->sockfd = fd;
- tpeers = tpeer;
-#ifdef SO_NO_CHECK
- setsockopt(tpeer->sockfd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
-#endif
- ast_log(LOG_DEBUG, "Created trunk peer for '%s:%d'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port));
- }
- }
- ast_mutex_unlock(&tpeerlock);
- return tpeer;
-}
-
-static int iax2_trunk_queue(struct chan_iax2_pvt *pvt, struct iax_frame *fr)
-{
- struct ast_frame *f;
- struct iax2_trunk_peer *tpeer;
- void *tmp, *ptr;
- struct ast_iax2_meta_trunk_entry *met;
- struct ast_iax2_meta_trunk_mini *mtm;
- char iabuf[INET_ADDRSTRLEN];
-
- f = &fr->af;
- tpeer = find_tpeer(&pvt->addr, pvt->sockfd);
- if (tpeer) {
- if (tpeer->trunkdatalen + f->datalen + 4 >= tpeer->trunkdataalloc) {
- /* Need to reallocate space */
- if (tpeer->trunkdataalloc < MAX_TRUNKDATA) {
- tmp = realloc(tpeer->trunkdata, tpeer->trunkdataalloc + DEFAULT_TRUNKDATA + IAX2_TRUNK_PREFACE);
- if (tmp) {
- tpeer->trunkdataalloc += DEFAULT_TRUNKDATA;
- tpeer->trunkdata = tmp;
- ast_log(LOG_DEBUG, "Expanded trunk '%s:%d' to %d bytes\n", ast_inet_ntoa(iabuf, sizeof(iabuf), tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port), tpeer->trunkdataalloc);
- } else {
- ast_log(LOG_WARNING, "Insufficient memory to expand trunk data to %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port));
- ast_mutex_unlock(&tpeer->lock);
- return -1;
- }
- } else {
- ast_log(LOG_WARNING, "Maximum trunk data space exceeded to %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port));
- ast_mutex_unlock(&tpeer->lock);
- return -1;
- }
- }
-
- /* Append to meta frame */
- ptr = tpeer->trunkdata + IAX2_TRUNK_PREFACE + tpeer->trunkdatalen;
- if (ast_test_flag(&globalflags, IAX_TRUNKTIMESTAMPS)) {
- mtm = (struct ast_iax2_meta_trunk_mini *)ptr;
- mtm->len = htons(f->datalen);
- mtm->mini.callno = htons(pvt->callno);
- mtm->mini.ts = htons(0xffff & fr->ts);
- ptr += sizeof(struct ast_iax2_meta_trunk_mini);
- tpeer->trunkdatalen += sizeof(struct ast_iax2_meta_trunk_mini);
- } else {
- met = (struct ast_iax2_meta_trunk_entry *)ptr;
- /* Store call number and length in meta header */
- met->callno = htons(pvt->callno);
- met->len = htons(f->datalen);
- /* Advance pointers/decrease length past trunk entry header */
- ptr += sizeof(struct ast_iax2_meta_trunk_entry);
- tpeer->trunkdatalen += sizeof(struct ast_iax2_meta_trunk_entry);
- }
- /* Copy actual trunk data */
- memcpy(ptr, f->data, f->datalen);
- tpeer->trunkdatalen += f->datalen;
-
- tpeer->calls++;
- ast_mutex_unlock(&tpeer->lock);
- }
- return 0;
-}
-
-static void build_enc_keys(const unsigned char *digest, aes_encrypt_ctx *ecx, aes_decrypt_ctx *dcx)
-{
- aes_encrypt_key128(digest, ecx);
- aes_decrypt_key128(digest, dcx);
-}
-
-static void memcpy_decrypt(unsigned char *dst, const unsigned char *src, int len, aes_decrypt_ctx *dcx)
-{
-#if 0
- /* Debug with "fake encryption" */
- int x;
- if (len % 16)
- ast_log(LOG_WARNING, "len should be multiple of 16, not %d!\n", len);
- for (x=0;x<len;x++)
- dst[x] = src[x] ^ 0xff;
-#else
- unsigned char lastblock[16] = { 0 };
- int x;
- while(len > 0) {
- aes_decrypt(src, dst, dcx);
- for (x=0;x<16;x++)
- dst[x] ^= lastblock[x];
- memcpy(lastblock, src, sizeof(lastblock));
- dst += 16;
- src += 16;
- len -= 16;
- }
-#endif
-}
-
-static void memcpy_encrypt(unsigned char *dst, const unsigned char *src, int len, aes_encrypt_ctx *ecx)
-{
-#if 0
- /* Debug with "fake encryption" */
- int x;
- if (len % 16)
- ast_log(LOG_WARNING, "len should be multiple of 16, not %d!\n", len);
- for (x=0;x<len;x++)
- dst[x] = src[x] ^ 0xff;
-#else
- unsigned char curblock[16] = { 0 };
- int x;
- while(len > 0) {
- for (x=0;x<16;x++)
- curblock[x] ^= src[x];
- aes_encrypt(curblock, dst, ecx);
- memcpy(curblock, dst, sizeof(curblock));
- dst += 16;
- src += 16;
- len -= 16;
- }
-#endif
-}
-
-static int decode_frame(aes_decrypt_ctx *dcx, struct ast_iax2_full_hdr *fh, struct ast_frame *f, int *datalen)
-{
- int padding;
- unsigned char *workspace;
- workspace = alloca(*datalen);
- if (!workspace)
- return -1;
- if (ntohs(fh->scallno) & IAX_FLAG_FULL) {
- struct ast_iax2_full_enc_hdr *efh = (struct ast_iax2_full_enc_hdr *)fh;
- if (*datalen < 16 + sizeof(struct ast_iax2_full_hdr))
- return -1;
- /* Decrypt */
- memcpy_decrypt(workspace, efh->encdata, *datalen - sizeof(struct ast_iax2_full_enc_hdr), dcx);
-
- padding = 16 + (workspace[15] & 0xf);
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Decoding full frame with length %d (padding = %d) (15=%02x)\n", *datalen, padding, workspace[15]);
- if (*datalen < padding + sizeof(struct ast_iax2_full_hdr))
- return -1;
-
- *datalen -= padding;
- memcpy(efh->encdata, workspace + padding, *datalen - sizeof(struct ast_iax2_full_enc_hdr));
- f->frametype = fh->type;
- if (f->frametype == AST_FRAME_VIDEO) {
- f->subclass = uncompress_subclass(fh->csub & ~0x40) | ((fh->csub >> 6) & 0x1);
- } else {
- f->subclass = uncompress_subclass(fh->csub);
- }
- } else {
- struct ast_iax2_mini_enc_hdr *efh = (struct ast_iax2_mini_enc_hdr *)fh;
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Decoding mini with length %d\n", *datalen);
- if (*datalen < 16 + sizeof(struct ast_iax2_mini_hdr))
- return -1;
- /* Decrypt */
- memcpy_decrypt(workspace, efh->encdata, *datalen - sizeof(struct ast_iax2_mini_enc_hdr), dcx);
- padding = 16 + (workspace[15] & 0x0f);
- if (*datalen < padding + sizeof(struct ast_iax2_mini_hdr))
- return -1;
- *datalen -= padding;
- memcpy(efh->encdata, workspace + padding, *datalen - sizeof(struct ast_iax2_mini_enc_hdr));
- }
- return 0;
-}
-
-static int encrypt_frame(aes_encrypt_ctx *ecx, struct ast_iax2_full_hdr *fh, unsigned char *poo, int *datalen)
-{
- int padding;
- unsigned char *workspace;
- workspace = alloca(*datalen + 32);
- if (!workspace)
- return -1;
- if (ntohs(fh->scallno) & IAX_FLAG_FULL) {
- struct ast_iax2_full_enc_hdr *efh = (struct ast_iax2_full_enc_hdr *)fh;
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Encoding full frame %d/%d with length %d\n", fh->type, fh->csub, *datalen);
- padding = 16 - ((*datalen - sizeof(struct ast_iax2_full_enc_hdr)) % 16);
- padding = 16 + (padding & 0xf);
- memcpy(workspace, poo, padding);
- memcpy(workspace + padding, efh->encdata, *datalen - sizeof(struct ast_iax2_full_enc_hdr));
- workspace[15] &= 0xf0;
- workspace[15] |= (padding & 0xf);
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Encoding full frame %d/%d with length %d + %d padding (15=%02x)\n", fh->type, fh->csub, *datalen, padding, workspace[15]);
- *datalen += padding;
- memcpy_encrypt(efh->encdata, workspace, *datalen - sizeof(struct ast_iax2_full_enc_hdr), ecx);
- if (*datalen >= 32 + sizeof(struct ast_iax2_full_enc_hdr))
- memcpy(poo, workspace + *datalen - 32, 32);
- } else {
- struct ast_iax2_mini_enc_hdr *efh = (struct ast_iax2_mini_enc_hdr *)fh;
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Encoding mini frame with length %d\n", *datalen);
- padding = 16 - ((*datalen - sizeof(struct ast_iax2_mini_enc_hdr)) % 16);
- padding = 16 + (padding & 0xf);
- memcpy(workspace, poo, padding);
- memcpy(workspace + padding, efh->encdata, *datalen - sizeof(struct ast_iax2_mini_enc_hdr));
- workspace[15] &= 0xf0;
- workspace[15] |= (padding & 0x0f);
- *datalen += padding;
- memcpy_encrypt(efh->encdata, workspace, *datalen - sizeof(struct ast_iax2_mini_enc_hdr), ecx);
- if (*datalen >= 32 + sizeof(struct ast_iax2_mini_enc_hdr))
- memcpy(poo, workspace + *datalen - 32, 32);
- }
- return 0;
-}
-
-static int decrypt_frame(int callno, struct ast_iax2_full_hdr *fh, struct ast_frame *f, int *datalen)
-{
- int res=-1;
- if (!ast_test_flag(iaxs[callno], IAX_KEYPOPULATED)) {
- /* Search for possible keys, given secrets */
- struct MD5Context md5;
- unsigned char digest[16];
- char *tmppw, *stringp;
-
- tmppw = ast_strdupa(iaxs[callno]->secret);
- stringp = tmppw;
- while((tmppw = strsep(&stringp, ";"))) {
- MD5Init(&md5);
- MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
- MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
- MD5Final(digest, &md5);
- build_enc_keys(digest, &iaxs[callno]->ecx, &iaxs[callno]->dcx);
- res = decode_frame(&iaxs[callno]->dcx, fh, f, datalen);
- if (!res) {
- ast_set_flag(iaxs[callno], IAX_KEYPOPULATED);
- break;
- }
- }
- } else
- res = decode_frame(&iaxs[callno]->dcx, fh, f, datalen);
- return res;
-}
-
-static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned int ts, int seqno, int now, int transfer, int final)
-{
- /* Queue a packet for delivery on a given private structure. Use "ts" for
- timestamp, or calculate if ts is 0. Send immediately without retransmission
- or delayed, with retransmission */
- struct ast_iax2_full_hdr *fh;
- struct ast_iax2_mini_hdr *mh;
- struct ast_iax2_video_hdr *vh;
- struct {
- struct iax_frame fr2;
- unsigned char buffer[4096];
- } frb;
- struct iax_frame *fr;
- int res;
- int sendmini=0;
- unsigned int lastsent;
- unsigned int fts;
-
- if (!pvt) {
- ast_log(LOG_WARNING, "No private structure for packet?\n");
- return -1;
- }
-
- lastsent = pvt->lastsent;
-
- /* Calculate actual timestamp */
- fts = calc_timestamp(pvt, ts, f);
-
- /* Bail here if this is an "interp" frame; we don't want or need to send these placeholders out
- * (the endpoint should detect the lost packet itself). But, we want to do this here, so that we
- * increment the "predicted timestamps" for voice, if we're predecting */
- if(f->frametype == AST_FRAME_VOICE && f->datalen == 0)
- return 0;
-
-
- if ((ast_test_flag(pvt, IAX_TRUNK) || ((fts & 0xFFFF0000L) == (lastsent & 0xFFFF0000L)))
- /* High two bytes are the same on timestamp, or sending on a trunk */ &&
- (f->frametype == AST_FRAME_VOICE)
- /* is a voice frame */ &&
- (f->subclass == pvt->svoiceformat)
- /* is the same type */ ) {
- /* Force immediate rather than delayed transmission */
- now = 1;
- /* Mark that mini-style frame is appropriate */
- sendmini = 1;
- }
- if (((fts & 0xFFFF8000L) == (lastsent & 0xFFFF8000L)) &&
- (f->frametype == AST_FRAME_VIDEO) &&
- ((f->subclass & ~0x1) == pvt->svideoformat)) {
- now = 1;
- sendmini = 1;
- }
- /* Allocate an iax_frame */
- if (now) {
- fr = &frb.fr2;
- } else
- fr = iax_frame_new(DIRECTION_OUTGRESS, ast_test_flag(pvt, IAX_ENCRYPTED) ? f->datalen + 32 : f->datalen);
- if (!fr) {
- ast_log(LOG_WARNING, "Out of memory\n");
- return -1;
- }
- /* Copy our prospective frame into our immediate or retransmitted wrapper */
- iax_frame_wrap(fr, f);
-
- fr->ts = fts;
- fr->callno = pvt->callno;
- fr->transfer = transfer;
- fr->final = final;
- if (!sendmini) {
- /* We need a full frame */
- if (seqno > -1)
- fr->oseqno = seqno;
- else
- fr->oseqno = pvt->oseqno++;
- fr->iseqno = pvt->iseqno;
- fh = (struct ast_iax2_full_hdr *)(fr->af.data - sizeof(struct ast_iax2_full_hdr));
- fh->scallno = htons(fr->callno | IAX_FLAG_FULL);
- fh->ts = htonl(fr->ts);
- fh->oseqno = fr->oseqno;
- if (transfer) {
- fh->iseqno = 0;
- } else
- fh->iseqno = fr->iseqno;
- /* Keep track of the last thing we've acknowledged */
- if (!transfer)
- pvt->aseqno = fr->iseqno;
- fh->type = fr->af.frametype & 0xFF;
- if (fr->af.frametype == AST_FRAME_VIDEO)
- fh->csub = compress_subclass(fr->af.subclass & ~0x1) | ((fr->af.subclass & 0x1) << 6);
- else
- fh->csub = compress_subclass(fr->af.subclass);
- if (transfer) {
- fr->dcallno = pvt->transfercallno;
- } else
- fr->dcallno = pvt->peercallno;
- fh->dcallno = htons(fr->dcallno);
- fr->datalen = fr->af.datalen + sizeof(struct ast_iax2_full_hdr);
- fr->data = fh;
- fr->retries = 0;
- /* Retry after 2x the ping time has passed */
- fr->retrytime = pvt->pingtime * 2;
- if (fr->retrytime < MIN_RETRY_TIME)
- fr->retrytime = MIN_RETRY_TIME;
- if (fr->retrytime > MAX_RETRY_TIME)
- fr->retrytime = MAX_RETRY_TIME;
- /* Acks' don't get retried */
- if ((f->frametype == AST_FRAME_IAX) && (f->subclass == IAX_COMMAND_ACK))
- fr->retries = -1;
- else if (f->frametype == AST_FRAME_VOICE)
- pvt->svoiceformat = f->subclass;
- else if (f->frametype == AST_FRAME_VIDEO)
- pvt->svideoformat = f->subclass & ~0x1;
- if (ast_test_flag(pvt, IAX_ENCRYPTED)) {
- if (ast_test_flag(pvt, IAX_KEYPOPULATED)) {
- if (iaxdebug) {
- if (fr->transfer)
- iax_showframe(fr, NULL, 2, &pvt->transfer, fr->datalen - sizeof(struct ast_iax2_full_hdr));
- else
- iax_showframe(fr, NULL, 2, &pvt->addr, fr->datalen - sizeof(struct ast_iax2_full_hdr));
- }
- encrypt_frame(&pvt->ecx, fh, pvt->semirand, &fr->datalen);
- } else
- ast_log(LOG_WARNING, "Supposed to send packet encrypted, but no key?\n");
- }
-
- if (now) {
- res = send_packet(fr);
- } else
- res = iax2_transmit(fr);
- } else {
- if (ast_test_flag(pvt, IAX_TRUNK)) {
- iax2_trunk_queue(pvt, fr);
- res = 0;
- } else if (fr->af.frametype == AST_FRAME_VIDEO) {
- /* Video frame have no sequence number */
- fr->oseqno = -1;
- fr->iseqno = -1;
- vh = (struct ast_iax2_video_hdr *)(fr->af.data - sizeof(struct ast_iax2_video_hdr));
- vh->zeros = 0;
- vh->callno = htons(0x8000 | fr->callno);
- vh->ts = htons((fr->ts & 0x7FFF) | (fr->af.subclass & 0x1 ? 0x8000 : 0));
- fr->datalen = fr->af.datalen + sizeof(struct ast_iax2_video_hdr);
- fr->data = vh;
- fr->retries = -1;
- res = send_packet(fr);
- } else {
- /* Mini-frames have no sequence number */
- fr->oseqno = -1;
- fr->iseqno = -1;
- /* Mini frame will do */
- mh = (struct ast_iax2_mini_hdr *)(fr->af.data - sizeof(struct ast_iax2_mini_hdr));
- mh->callno = htons(fr->callno);
- mh->ts = htons(fr->ts & 0xFFFF);
- fr->datalen = fr->af.datalen + sizeof(struct ast_iax2_mini_hdr);
- fr->data = mh;
- fr->retries = -1;
- if (ast_test_flag(pvt, IAX_ENCRYPTED)) {
- if (ast_test_flag(pvt, IAX_KEYPOPULATED)) {
- encrypt_frame(&pvt->ecx, (struct ast_iax2_full_hdr *)mh, pvt->semirand, &fr->datalen);
- } else
- ast_log(LOG_WARNING, "Supposed to send packet encrypted, but no key?\n");
- }
- res = send_packet(fr);
- }
- }
- return res;
-}
-
-
-
-static int iax2_show_users(int fd, int argc, char *argv[])
-{
- regex_t regexbuf;
- int havepattern = 0;
-
-#define FORMAT "%-15.15s %-20.20s %-15.15s %-15.15s %-5.5s %-5.10s\n"
-#define FORMAT2 "%-15.15s %-20.20s %-15.15d %-15.15s %-5.5s %-5.10s\n"
-
- struct iax2_user *user;
- char auth[90];
- char *pstr = "";
-
- switch (argc) {
- case 5:
- if (!strcasecmp(argv[3], "like")) {
- if (regcomp(&regexbuf, argv[4], REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
- havepattern = 1;
- } else
- return RESULT_SHOWUSAGE;
- case 3:
- break;
- default:
- return RESULT_SHOWUSAGE;
- }
-
- ast_mutex_lock(&userl.lock);
- ast_cli(fd, FORMAT, "Username", "Secret", "Authen", "Def.Context", "A/C","Codec Pref");
- for(user=userl.users;user;user=user->next) {
- if (havepattern && regexec(&regexbuf, user->name, 0, NULL, 0))
- continue;
-
- if (!ast_strlen_zero(user->secret)) {
- ast_copy_string(auth,user->secret,sizeof(auth));
- } else if (!ast_strlen_zero(user->inkeys)) {
- snprintf(auth, sizeof(auth), "Key: %-15.15s ", user->inkeys);
- } else
- ast_copy_string(auth, "-no secret-", sizeof(auth));
-
- if(ast_test_flag(user,IAX_CODEC_NOCAP))
- pstr = "REQ Only";
- else if(ast_test_flag(user,IAX_CODEC_NOPREFS))
- pstr = "Disabled";
- else
- pstr = ast_test_flag(user,IAX_CODEC_USER_FIRST) ? "Caller" : "Host";
-
- ast_cli(fd, FORMAT2, user->name, auth, user->authmethods,
- user->contexts ? user->contexts->context : context,
- user->ha ? "Yes" : "No", pstr);
-
- }
- ast_mutex_unlock(&userl.lock);
-
- if (havepattern)
- regfree(&regexbuf);
-
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-static int __iax2_show_peers(int manager, int fd, int argc, char *argv[])
-{
- regex_t regexbuf;
- int havepattern = 0;
- int total_peers = 0;
- int online_peers = 0;
- int offline_peers = 0;
- int unmonitored_peers = 0;
-
-#define FORMAT2 "%-15.15s %-15.15s %s %-15.15s %-8s %s %-10s%s"
-#define FORMAT "%-15.15s %-15.15s %s %-15.15s %-5d%s %s %-10s%s"
-
- struct iax2_peer *peer;
- char name[256];
- char iabuf[INET_ADDRSTRLEN];
- int registeredonly=0;
- char *term = manager ? "\r\n" : "\n";
-
- switch (argc) {
- case 6:
- if (!strcasecmp(argv[3], "registered"))
- registeredonly = 1;
- else
- return RESULT_SHOWUSAGE;
- if (!strcasecmp(argv[4], "like")) {
- if (regcomp(&regexbuf, argv[5], REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
- havepattern = 1;
- } else
- return RESULT_SHOWUSAGE;
- break;
- case 5:
- if (!strcasecmp(argv[3], "like")) {
- if (regcomp(&regexbuf, argv[4], REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
- havepattern = 1;
- } else
- return RESULT_SHOWUSAGE;
- break;
- case 4:
- if (!strcasecmp(argv[3], "registered"))
- registeredonly = 1;
- else
- return RESULT_SHOWUSAGE;
- break;
- case 3:
- break;
- default:
- return RESULT_SHOWUSAGE;
- }
-
- ast_mutex_lock(&peerl.lock);
- ast_cli(fd, FORMAT2, "Name/Username", "Host", " ", "Mask", "Port", " ", "Status", term);
- for (peer = peerl.peers;peer;peer = peer->next) {
- char nm[20];
- char status[20];
- char srch[2000];
- int retstatus;
-
- if (registeredonly && !peer->addr.sin_addr.s_addr)
- continue;
- if (havepattern && regexec(&regexbuf, peer->name, 0, NULL, 0))
- continue;
-
- if (!ast_strlen_zero(peer->username))
- snprintf(name, sizeof(name), "%s/%s", peer->name, peer->username);
- else
- ast_copy_string(name, peer->name, sizeof(name));
-
- retstatus = peer_status(peer, status, sizeof(status));
- if (retstatus > 0)
- online_peers++;
- else if (!retstatus)
- offline_peers++;
- else
- unmonitored_peers++;
-
- ast_copy_string(nm, ast_inet_ntoa(iabuf, sizeof(iabuf), peer->mask), sizeof(nm));
-
- snprintf(srch, sizeof(srch), FORMAT, name,
- peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)",
- ast_test_flag(peer, IAX_DYNAMIC) ? "(D)" : "(S)",
- nm,
- ntohs(peer->addr.sin_port), ast_test_flag(peer, IAX_TRUNK) ? "(T)" : " ",
- peer->encmethods ? "(E)" : " ", status, term);
-
- ast_cli(fd, FORMAT, name,
- peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)",
- ast_test_flag(peer, IAX_DYNAMIC) ? "(D)" : "(S)",
- nm,
- ntohs(peer->addr.sin_port), ast_test_flag(peer, IAX_TRUNK) ? "(T)" : " ",
- peer->encmethods ? "(E)" : " ", status, term);
- total_peers++;
- }
- ast_mutex_unlock(&peerl.lock);
-
- ast_cli(fd,"%d iax2 peers [%d online, %d offline, %d unmonitored]%s", total_peers, online_peers, offline_peers, unmonitored_peers, term);
-
- if (havepattern)
- regfree(&regexbuf);
-
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-static int iax2_show_peers(int fd, int argc, char *argv[])
-{
- return __iax2_show_peers(0, fd, argc, argv);
-}
-static int manager_iax2_show_netstats( struct mansession *s, struct message *m )
-{
- ast_cli_netstats(s->fd, 0);
- ast_cli(s->fd, "\r\n");
- return RESULT_SUCCESS;
-}
-
-static int iax2_show_firmware(int fd, int argc, char *argv[])
-{
-#define FORMAT2 "%-15.15s %-15.15s %-15.15s\n"
-#if !defined(__FreeBSD__)
-#define FORMAT "%-15.15s %-15d %-15d\n"
-#else /* __FreeBSD__ */
-#define FORMAT "%-15.15s %-15d %-15d\n" /* XXX 2.95 ? */
-#endif /* __FreeBSD__ */
- struct iax_firmware *cur;
- if ((argc != 3) && (argc != 4))
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&waresl.lock);
-
- ast_cli(fd, FORMAT2, "Device", "Version", "Size");
- for (cur = waresl.wares;cur;cur = cur->next) {
- if ((argc == 3) || (!strcasecmp(argv[3], (char *)cur->fwh->devname)))
- ast_cli(fd, FORMAT, cur->fwh->devname, ntohs(cur->fwh->version),
- (int)ntohl(cur->fwh->datalen));
- }
- ast_mutex_unlock(&waresl.lock);
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-/* JDG: callback to display iax peers in manager */
-static int manager_iax2_show_peers( struct mansession *s, struct message *m )
-{
- char *a[] = { "iax2", "show", "users" };
- int ret;
- char *id;
- id = astman_get_header(m,"ActionID");
- if (!ast_strlen_zero(id))
- ast_cli(s->fd, "ActionID: %s\r\n",id);
- ret = __iax2_show_peers(1, s->fd, 3, a );
- ast_cli(s->fd, "\r\n\r\n" );
- return ret;
-} /* /JDG */
-
-static char *regstate2str(int regstate)
-{
- switch(regstate) {
- case REG_STATE_UNREGISTERED:
- return "Unregistered";
- case REG_STATE_REGSENT:
- return "Request Sent";
- case REG_STATE_AUTHSENT:
- return "Auth. Sent";
- case REG_STATE_REGISTERED:
- return "Registered";
- case REG_STATE_REJECTED:
- return "Rejected";
- case REG_STATE_TIMEOUT:
- return "Timeout";
- case REG_STATE_NOAUTH:
- return "No Authentication";
- default:
- return "Unknown";
- }
-}
-
-static int iax2_show_registry(int fd, int argc, char *argv[])
-{
-#define FORMAT2 "%-20.20s %-10.10s %-20.20s %8.8s %s\n"
-#define FORMAT "%-20.20s %-10.10s %-20.20s %8d %s\n"
- struct iax2_registry *reg;
- char host[80];
- char perceived[80];
- char iabuf[INET_ADDRSTRLEN];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&peerl.lock);
- ast_cli(fd, FORMAT2, "Host", "Username", "Perceived", "Refresh", "State");
- for (reg = registrations;reg;reg = reg->next) {
- snprintf(host, sizeof(host), "%s:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), reg->addr.sin_addr), ntohs(reg->addr.sin_port));
- if (reg->us.sin_addr.s_addr)
- snprintf(perceived, sizeof(perceived), "%s:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), reg->us.sin_addr), ntohs(reg->us.sin_port));
- else
- ast_copy_string(perceived, "<Unregistered>", sizeof(perceived));
- ast_cli(fd, FORMAT, host,
- reg->username, perceived, reg->refresh, regstate2str(reg->regstate));
- }
- ast_mutex_unlock(&peerl.lock);
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-#ifndef NEWJB
-static int jitterbufsize(struct chan_iax2_pvt *pvt) {
- int min, i;
- min = 99999999;
- for (i=0; i<MEMORY_SIZE; i++) {
- if (pvt->history[i] < min)
- min = pvt->history[i];
- }
- if (pvt->jitterbuffer - min > maxjitterbuffer)
- return maxjitterbuffer;
- else
- return pvt->jitterbuffer - min;
-}
-#endif
-
-static int iax2_show_channels(int fd, int argc, char *argv[])
-{
-#define FORMAT2 "%-20.20s %-15.15s %-10.10s %-11.11s %-11.11s %-7.7s %-6.6s %-6.6s %s\n"
-#define FORMAT "%-20.20s %-15.15s %-10.10s %5.5d/%5.5d %5.5d/%5.5d %-5.5dms %-4.4dms %-4.4dms %-6.6s\n"
-#define FORMATB "%-20.20s %-15.15s %-10.10s %5.5d/%5.5d %5.5d/%5.5d [Native Bridged to ID=%5.5d]\n"
- int x;
- int numchans = 0;
- char iabuf[INET_ADDRSTRLEN];
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, FORMAT2, "Channel", "Peer", "Username", "ID (Lo/Rem)", "Seq (Tx/Rx)", "Lag", "Jitter", "JitBuf", "Format");
- for (x=0;x<IAX_MAX_CALLS;x++) {
- ast_mutex_lock(&iaxsl[x]);
- if (iaxs[x]) {
-#ifdef BRIDGE_OPTIMIZATION
- if (iaxs[x]->bridgecallno)
- ast_cli(fd, FORMATB,
- iaxs[x]->owner ? iaxs[x]->owner->name : "(None)",
- ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[x]->addr.sin_addr),
- !ast_strlen_zero(iaxs[x]->username) ? iaxs[x]->username : "(None)",
- iaxs[x]->callno, iaxs[x]->peercallno,
- iaxs[x]->oseqno, iaxs[x]->iseqno,
- iaxs[x]->bridgecallno );
- else
-#endif
- {
- int lag, jitter, localdelay;
-#ifdef NEWJB
- jb_info jbinfo;
-
- if(ast_test_flag(iaxs[x], IAX_USEJITTERBUF)) {
- jb_getinfo(iaxs[x]->jb, &jbinfo);
- jitter = jbinfo.jitter;
- localdelay = jbinfo.current - jbinfo.min;
- } else {
- jitter = -1;
- localdelay = 0;
- }
-#else
- jitter = iaxs[x]->jitter;
- localdelay = ast_test_flag(iaxs[x], IAX_USEJITTERBUF) ? jitterbufsize(iaxs[x]) : 0;
-#endif
- lag = iaxs[x]->remote_rr.delay;
- ast_cli(fd, FORMAT,
- iaxs[x]->owner ? iaxs[x]->owner->name : "(None)",
- ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[x]->addr.sin_addr),
- !ast_strlen_zero(iaxs[x]->username) ? iaxs[x]->username : "(None)",
- iaxs[x]->callno, iaxs[x]->peercallno,
- iaxs[x]->oseqno, iaxs[x]->iseqno,
- lag,
- jitter,
- localdelay,
- ast_getformatname(iaxs[x]->voiceformat) );
- }
- numchans++;
- }
- ast_mutex_unlock(&iaxsl[x]);
- }
- ast_cli(fd, "%d active IAX channel%s\n", numchans, (numchans != 1) ? "s" : "");
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-#undef FORMATB
-}
-
-static int ast_cli_netstats(int fd, int limit_fmt)
-{
- int x;
- int numchans = 0;
- for (x=0;x<IAX_MAX_CALLS;x++) {
- ast_mutex_lock(&iaxsl[x]);
- if (iaxs[x]) {
-#ifdef BRIDGE_OPTIMIZATION
- if (iaxs[x]->bridgecallno) {
- if (limit_fmt)
- ast_cli(fd, "%-25.25s <NATIVE BRIDGED>",
- iaxs[x]->owner ? iaxs[x]->owner->name : "(None)");
- else
- ast_cli(fd, "%s <NATIVE BRIDGED>",
- iaxs[x]->owner ? iaxs[x]->owner->name : "(None)");
- } else
-#endif
- {
- int localjitter, localdelay, locallost, locallosspct, localdropped, localooo;
- char *fmt;
-#ifdef NEWJB
- jb_info jbinfo;
-
- if(ast_test_flag(iaxs[x], IAX_USEJITTERBUF)) {
- jb_getinfo(iaxs[x]->jb, &jbinfo);
- localjitter = jbinfo.jitter;
- localdelay = jbinfo.current - jbinfo.min;
- locallost = jbinfo.frames_lost;
- locallosspct = jbinfo.losspct/1000;
- localdropped = jbinfo.frames_dropped;
- localooo = jbinfo.frames_ooo;
- } else {
- localjitter = -1;
- localdelay = 0;
- locallost = -1;
- locallosspct = -1;
- localdropped = 0;
- localooo = -1;
- }
-#else
- localjitter = iaxs[x]->jitter;
- if(ast_test_flag(iaxs[x], IAX_USEJITTERBUF))
- {
- localdelay = jitterbufsize(iaxs[x]);
- localdropped = iaxs[x]->frames_dropped;
- } else {
- localdelay = localdropped = 0;
- }
- locallost = locallosspct = localooo = -1;
-#endif
- if (limit_fmt)
- fmt = "%-25.25s %4d %4d %4d %5d %3d %5d %4d %6d %4d %4d %5d %3d %5d %4d %6d\n";
- else
- fmt = "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n";
- ast_cli(fd, fmt,
- iaxs[x]->owner ? iaxs[x]->owner->name : "(None)",
- iaxs[x]->pingtime,
- localjitter,
- localdelay,
- locallost,
- locallosspct,
- localdropped,
- localooo,
- iaxs[x]->frames_received/1000,
- iaxs[x]->remote_rr.jitter,
- iaxs[x]->remote_rr.delay,
- iaxs[x]->remote_rr.losscnt,
- iaxs[x]->remote_rr.losspct,
- iaxs[x]->remote_rr.dropped,
- iaxs[x]->remote_rr.ooo,
- iaxs[x]->remote_rr.packets/1000
- );
- }
- numchans++;
- }
- ast_mutex_unlock(&iaxsl[x]);
- }
- return numchans;
-}
-
-static int iax2_show_netstats(int fd, int argc, char *argv[])
-{
- int numchans = 0;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, " -------- LOCAL --------------------- -------- REMOTE --------------------\n");
- ast_cli(fd, "Channel RTT Jit Del Lost %% Drop OOO Kpkts Jit Del Lost %% Drop OOO Kpkts\n");
- numchans = ast_cli_netstats(fd, 1);
- ast_cli(fd, "%d active IAX channel%s\n", numchans, (numchans != 1) ? "s" : "");
- return RESULT_SUCCESS;
-}
-
-static int iax2_do_debug(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- iaxdebug = 1;
- ast_cli(fd, "IAX2 Debugging Enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int iax2_do_trunk_debug(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- iaxtrunkdebug = 1;
- ast_cli(fd, "IAX2 Trunk Debug Requested\n");
- return RESULT_SUCCESS;
-}
-
-static int iax2_do_jb_debug(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
-#ifdef NEWJB
- jb_setoutput(jb_error_output, jb_warning_output, jb_debug_output);
-#endif
- ast_cli(fd, "IAX2 Jitterbuffer Debugging Enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int iax2_no_debug(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- iaxdebug = 0;
- ast_cli(fd, "IAX2 Debugging Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static int iax2_no_trunk_debug(int fd, int argc, char *argv[])
-{
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- iaxtrunkdebug = 0;
- ast_cli(fd, "IAX2 Trunk Debugging Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static int iax2_no_jb_debug(int fd, int argc, char *argv[])
-{
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-#ifdef NEWJB
- jb_setoutput(jb_error_output, jb_warning_output, NULL);
- jb_debug_output("\n");
-#endif
- ast_cli(fd, "IAX2 Jitterbuffer Debugging Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static int iax2_write(struct ast_channel *c, struct ast_frame *f)
-{
- unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
- int res = -1;
- ast_mutex_lock(&iaxsl[callno]);
- if (iaxs[callno]) {
- /* If there's an outstanding error, return failure now */
- if (!iaxs[callno]->error) {
- if (ast_test_flag(iaxs[callno], IAX_ALREADYGONE))
- res = 0;
- /* Don't waste bandwidth sending null frames */
- else if (f->frametype == AST_FRAME_NULL)
- res = 0;
- else if ((f->frametype == AST_FRAME_VOICE) && ast_test_flag(iaxs[callno], IAX_QUELCH))
- res = 0;
- else if (!ast_test_flag(&iaxs[callno]->state, IAX_STATE_STARTED))
- res = 0;
- else
- /* Simple, just queue for transmission */
- res = iax2_send(iaxs[callno], f, 0, -1, 0, 0, 0);
- } else {
- ast_log(LOG_DEBUG, "Write error: %s\n", strerror(errno));
- }
- }
- /* If it's already gone, just return */
- ast_mutex_unlock(&iaxsl[callno]);
- return res;
-}
-
-static int __send_command(struct chan_iax2_pvt *i, char type, int command, unsigned int ts, const unsigned char *data, int datalen, int seqno,
- int now, int transfer, int final)
-{
- struct ast_frame f;
- f.frametype = type;
- f.subclass = command;
- f.datalen = datalen;
- f.samples = 0;
- f.mallocd = 0;
- f.offset = 0;
- f.src = (char *)__FUNCTION__;
- f.data = (char *)data;
- return iax2_send(i, &f, ts, seqno, now, transfer, final);
-}
-
-static int send_command(struct chan_iax2_pvt *i, char type, int command, unsigned int ts, const unsigned char *data, int datalen, int seqno)
-{
- return __send_command(i, type, command, ts, data, datalen, seqno, 0, 0, 0);
-}
-
-static int send_command_locked(unsigned short callno, char type, int command, unsigned int ts, const unsigned char *data, int datalen, int seqno)
-{
- int res;
- ast_mutex_lock(&iaxsl[callno]);
- res = send_command(iaxs[callno], type, command, ts, data, datalen, seqno);
- ast_mutex_unlock(&iaxsl[callno]);
- return res;
-}
-
-#ifdef BRIDGE_OPTIMIZATION
-static int forward_command(struct chan_iax2_pvt *i, char type, int command, unsigned int ts, const char *data, int datalen, int seqno)
-{
- return __send_command(iaxs[i->bridgecallno], type, command, ts, data, datalen, seqno, 0, 0, 0);
-}
-#endif
-
-static int send_command_final(struct chan_iax2_pvt *i, char type, int command, unsigned int ts, const unsigned char *data, int datalen, int seqno)
-{
- /* It is assumed that the callno has already been locked */
- iax2_predestroy_nolock(i->callno);
- return __send_command(i, type, command, ts, data, datalen, seqno, 0, 0, 1);
-}
-
-static int send_command_immediate(struct chan_iax2_pvt *i, char type, int command, unsigned int ts, const unsigned char *data, int datalen, int seqno)
-{
- return __send_command(i, type, command, ts, data, datalen, seqno, 1, 0, 0);
-}
-
-static int send_command_transfer(struct chan_iax2_pvt *i, char type, int command, unsigned int ts, const unsigned char *data, int datalen)
-{
- return __send_command(i, type, command, ts, data, datalen, 0, 0, 1, 0);
-}
-
-static int apply_context(struct iax2_context *con, char *context)
-{
- while(con) {
- if (!strcmp(con->context, context) || !strcmp(con->context, "*"))
- return -1;
- con = con->next;
- }
- return 0;
-}
-
-
-static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies)
-{
- /* Start pessimistic */
- int res = -1;
- int version = 2;
- struct iax2_user *user, *best = NULL;
- int bestscore = 0;
- int gotcapability=0;
- char iabuf[INET_ADDRSTRLEN];
- struct ast_variable *v = NULL, *tmpvar = NULL;
-
- if (!iaxs[callno])
- return res;
- if (ies->called_number)
- ast_copy_string(iaxs[callno]->exten, ies->called_number, sizeof(iaxs[callno]->exten));
- if (ies->calling_number) {
- ast_shrink_phone_number(ies->calling_number);
- ast_copy_string(iaxs[callno]->cid_num, ies->calling_number, sizeof(iaxs[callno]->cid_num));
- }
- if (ies->calling_name)
- ast_copy_string(iaxs[callno]->cid_name, ies->calling_name, sizeof(iaxs[callno]->cid_name));
- if (ies->calling_ani)
- ast_copy_string(iaxs[callno]->ani, ies->calling_ani, sizeof(iaxs[callno]->ani));
- if (ies->dnid)
- ast_copy_string(iaxs[callno]->dnid, ies->dnid, sizeof(iaxs[callno]->dnid));
- if (ies->called_context)
- ast_copy_string(iaxs[callno]->context, ies->called_context, sizeof(iaxs[callno]->context));
- if (ies->language)
- ast_copy_string(iaxs[callno]->language, ies->language, sizeof(iaxs[callno]->language));
- if (ies->username)
- ast_copy_string(iaxs[callno]->username, ies->username, sizeof(iaxs[callno]->username));
- if (ies->calling_ton > -1)
- iaxs[callno]->calling_ton = ies->calling_ton;
- if (ies->calling_tns > -1)
- iaxs[callno]->calling_tns = ies->calling_tns;
- if (ies->calling_pres > -1)
- iaxs[callno]->calling_pres = ies->calling_pres;
- if (ies->format)
- iaxs[callno]->peerformat = ies->format;
- if (ies->adsicpe)
- iaxs[callno]->peeradsicpe = ies->adsicpe;
- if (ies->capability) {
- gotcapability = 1;
- iaxs[callno]->peercapability = ies->capability;
- }
- if (ies->version)
- version = ies->version;
-
- if(ies->codec_prefs)
- ast_codec_pref_convert(&iaxs[callno]->prefs, ies->codec_prefs, 32, 0);
-
- if (!gotcapability)
- iaxs[callno]->peercapability = iaxs[callno]->peerformat;
- if (version > IAX_PROTO_VERSION) {
- ast_log(LOG_WARNING, "Peer '%s' has too new a protocol version (%d) for me\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), version);
- return res;
- }
- ast_mutex_lock(&userl.lock);
- /* Search the userlist for a compatible entry, and fill in the rest */
- user = userl.users;
- while(user) {
- if ((ast_strlen_zero(iaxs[callno]->username) || /* No username specified */
- !strcmp(iaxs[callno]->username, user->name)) /* Or this username specified */
- && ast_apply_ha(user->ha, sin) /* Access is permitted from this IP */
- && (ast_strlen_zero(iaxs[callno]->context) || /* No context specified */
- apply_context(user->contexts, iaxs[callno]->context))) { /* Context is permitted */
- if (!ast_strlen_zero(iaxs[callno]->username)) {
- /* Exact match, stop right now. */
- best = user;
- break;
- } else if (ast_strlen_zero(user->secret) && ast_strlen_zero(user->inkeys)) {
- /* No required authentication */
- if (user->ha) {
- /* There was host authentication and we passed, bonus! */
- if (bestscore < 4) {
- bestscore = 4;
- best = user;
- }
- } else {
- /* No host access, but no secret, either, not bad */
- if (bestscore < 3) {
- bestscore = 3;
- best = user;
- }
- }
- } else {
- if (user->ha) {
- /* Authentication, but host access too, eh, it's something.. */
- if (bestscore < 2) {
- bestscore = 2;
- best = user;
- }
- } else {
- /* Authentication and no host access... This is our baseline */
- if (bestscore < 1) {
- bestscore = 1;
- best = user;
- }
- }
- }
- }
- user = user->next;
- }
- ast_mutex_unlock(&userl.lock);
- user = best;
- if (!user && !ast_strlen_zero(iaxs[callno]->username) && (strlen(iaxs[callno]->username) < 128)) {
- user = realtime_user(iaxs[callno]->username);
- if (user && !ast_strlen_zero(iaxs[callno]->context) && /* No context specified */
- !apply_context(user->contexts, iaxs[callno]->context)) { /* Context is permitted */
- destroy_user(user);
- user = NULL;
- }
- }
- if (user) {
- /* We found our match (use the first) */
- /* copy vars */
- for (v = user->vars ; v ; v = v->next) {
- if((tmpvar = ast_variable_new(v->name, v->value))) {
- tmpvar->next = iaxs[callno]->vars;
- iaxs[callno]->vars = tmpvar;
- }
- }
- iaxs[callno]->prefs = user->prefs;
- ast_copy_flags(iaxs[callno], user, IAX_CODEC_USER_FIRST);
- ast_copy_flags(iaxs[callno], user, IAX_CODEC_NOPREFS);
- ast_copy_flags(iaxs[callno], user, IAX_CODEC_NOCAP);
- iaxs[callno]->encmethods = user->encmethods;
- /* Store the requested username if not specified */
- if (ast_strlen_zero(iaxs[callno]->username))
- ast_copy_string(iaxs[callno]->username, user->name, sizeof(iaxs[callno]->username));
- /* Store whether this is a trunked call, too, of course, and move if appropriate */
- ast_copy_flags(iaxs[callno], user, IAX_TRUNK);
- iaxs[callno]->capability = user->capability;
- /* And use the default context */
- if (ast_strlen_zero(iaxs[callno]->context)) {
- if (user->contexts)
- ast_copy_string(iaxs[callno]->context, user->contexts->context, sizeof(iaxs[callno]->context));
- else
- ast_copy_string(iaxs[callno]->context, context, sizeof(iaxs[callno]->context));
- }
- /* And any input keys */
- ast_copy_string(iaxs[callno]->inkeys, user->inkeys, sizeof(iaxs[callno]->inkeys));
- /* And the permitted authentication methods */
- iaxs[callno]->authmethods = user->authmethods;
- /* If they have callerid, override the given caller id. Always store the ANI */
- if (!ast_strlen_zero(iaxs[callno]->cid_num) || !ast_strlen_zero(iaxs[callno]->cid_name)) {
- if (ast_test_flag(user, IAX_HASCALLERID)) {
- iaxs[callno]->calling_tns = 0;
- iaxs[callno]->calling_ton = 0;
- ast_copy_string(iaxs[callno]->cid_num, user->cid_num, sizeof(iaxs[callno]->cid_num));
- ast_copy_string(iaxs[callno]->cid_name, user->cid_name, sizeof(iaxs[callno]->cid_name));
- iaxs[callno]->calling_pres = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
- }
- ast_copy_string(iaxs[callno]->ani, user->cid_num, sizeof(iaxs[callno]->ani));
- } else {
- iaxs[callno]->calling_pres = AST_PRES_NUMBER_NOT_AVAILABLE;
- }
- if (!ast_strlen_zero(user->accountcode))
- ast_copy_string(iaxs[callno]->accountcode, user->accountcode, sizeof(iaxs[callno]->accountcode));
- if (user->amaflags)
- iaxs[callno]->amaflags = user->amaflags;
- if (!ast_strlen_zero(user->language))
- ast_copy_string(iaxs[callno]->language, user->language, sizeof(iaxs[callno]->language));
- ast_copy_flags(iaxs[callno], user, IAX_NOTRANSFER | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
- /* Keep this check last */
- if (!ast_strlen_zero(user->dbsecret)) {
- char *family, *key=NULL;
- family = ast_strdupa(user->dbsecret);
- if (family) {
- key = strchr(family, '/');
- if (key) {
- *key = '\0';
- key++;
- }
- }
- if (!family || !key || ast_db_get(family, key, iaxs[callno]->secret, sizeof(iaxs[callno]->secret))) {
- ast_log(LOG_WARNING, "Unable to retrieve database password for family/key '%s'!\n", user->dbsecret);
- if (ast_test_flag(user, IAX_TEMPONLY)) {
- destroy_user(user);
- user = NULL;
- }
- }
- } else
- ast_copy_string(iaxs[callno]->secret, user->secret, sizeof(iaxs[callno]->secret));
- res = 0;
- }
- ast_set2_flag(iaxs[callno], iax2_getpeertrunk(*sin), IAX_TRUNK);
- return res;
-}
-
-static int raw_hangup(struct sockaddr_in *sin, unsigned short src, unsigned short dst, int sockfd)
-{
- struct ast_iax2_full_hdr fh;
- char iabuf[INET_ADDRSTRLEN];
- fh.scallno = htons(src | IAX_FLAG_FULL);
- fh.dcallno = htons(dst);
- fh.ts = 0;
- fh.oseqno = 0;
- fh.iseqno = 0;
- fh.type = AST_FRAME_IAX;
- fh.csub = compress_subclass(IAX_COMMAND_INVAL);
- if (iaxdebug)
- iax_showframe(NULL, &fh, 0, sin, 0);
-#if 0
- if (option_debug)
-#endif
- ast_log(LOG_DEBUG, "Raw Hangup %s:%d, src=%d, dst=%d\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port), src, dst);
- return sendto(sockfd, &fh, sizeof(fh), 0, (struct sockaddr *)sin, sizeof(*sin));
-}
-
-static void merge_encryption(struct chan_iax2_pvt *p, unsigned int enc)
-{
- /* Select exactly one common encryption if there are any */
- p->encmethods &= enc;
- if (p->encmethods) {
- if (p->encmethods & IAX_ENCRYPT_AES128)
- p->encmethods = IAX_ENCRYPT_AES128;
- else
- p->encmethods = 0;
- }
-}
-
-static int authenticate_request(struct chan_iax2_pvt *p)
-{
- struct iax_ie_data ied;
- int res;
- memset(&ied, 0, sizeof(ied));
- iax_ie_append_short(&ied, IAX_IE_AUTHMETHODS, p->authmethods);
- if (p->authmethods & (IAX_AUTH_MD5 | IAX_AUTH_RSA)) {
- snprintf(p->challenge, sizeof(p->challenge), "%d", rand());
- iax_ie_append_str(&ied, IAX_IE_CHALLENGE, p->challenge);
- }
- if (p->encmethods)
- iax_ie_append_short(&ied, IAX_IE_ENCRYPTION, p->encmethods);
- iax_ie_append_str(&ied,IAX_IE_USERNAME, p->username);
- res = send_command(p, AST_FRAME_IAX, IAX_COMMAND_AUTHREQ, 0, ied.buf, ied.pos, -1);
- if (p->encmethods)
- ast_set_flag(p, IAX_ENCRYPTED);
- return res;
-}
-
-static int authenticate_verify(struct chan_iax2_pvt *p, struct iax_ies *ies)
-{
- char requeststr[256];
- char md5secret[256] = "";
- char secret[256] = "";
- char rsasecret[256] = "";
- int res = -1;
- int x;
-
- if (!ast_test_flag(&p->state, IAX_STATE_AUTHENTICATED))
- return res;
- if (ies->password)
- ast_copy_string(secret, ies->password, sizeof(secret));
- if (ies->md5_result)
- ast_copy_string(md5secret, ies->md5_result, sizeof(md5secret));
- if (ies->rsa_result)
- ast_copy_string(rsasecret, ies->rsa_result, sizeof(rsasecret));
- if ((p->authmethods & IAX_AUTH_RSA) && !ast_strlen_zero(rsasecret) && !ast_strlen_zero(p->inkeys)) {
- struct ast_key *key;
- char *keyn;
- char tmpkey[256];
- char *stringp=NULL;
- ast_copy_string(tmpkey, p->inkeys, sizeof(tmpkey));
- stringp=tmpkey;
- keyn = strsep(&stringp, ":");
- while(keyn) {
- key = ast_key_get(keyn, AST_KEY_PUBLIC);
- if (key && !ast_check_signature(key, p->challenge, rsasecret)) {
- res = 0;
- break;
- } else if (!key)
- ast_log(LOG_WARNING, "requested inkey '%s' for RSA authentication does not exist\n", keyn);
- keyn = strsep(&stringp, ":");
- }
- } else if (p->authmethods & IAX_AUTH_MD5) {
- struct MD5Context md5;
- unsigned char digest[16];
- char *tmppw, *stringp;
-
- tmppw = ast_strdupa(p->secret);
- stringp = tmppw;
- while((tmppw = strsep(&stringp, ";"))) {
- MD5Init(&md5);
- MD5Update(&md5, (unsigned char *)p->challenge, strlen(p->challenge));
- MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
- MD5Final(digest, &md5);
- /* If they support md5, authenticate with it. */
- for (x=0;x<16;x++)
- sprintf(requeststr + (x << 1), "%2.2x", digest[x]); /* safe */
- if (!strcasecmp(requeststr, md5secret)) {
- res = 0;
- break;
- }
- }
- } else if (p->authmethods & IAX_AUTH_PLAINTEXT) {
- if (!strcmp(secret, p->secret))
- res = 0;
- }
- return res;
-}
-
-/*! \brief Verify inbound registration */
-static int register_verify(int callno, struct sockaddr_in *sin, struct iax_ies *ies)
-{
- char requeststr[256] = "";
- char peer[256] = "";
- char md5secret[256] = "";
- char rsasecret[256] = "";
- char secret[256] = "";
- char iabuf[INET_ADDRSTRLEN];
- struct iax2_peer *p;
- struct ast_key *key;
- char *keyn;
- int x;
- int expire = 0;
-
- ast_clear_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED);
- iaxs[callno]->peer[0] = '\0';
- if (ies->username)
- ast_copy_string(peer, ies->username, sizeof(peer));
- if (ies->password)
- ast_copy_string(secret, ies->password, sizeof(secret));
- if (ies->md5_result)
- ast_copy_string(md5secret, ies->md5_result, sizeof(md5secret));
- if (ies->rsa_result)
- ast_copy_string(rsasecret, ies->rsa_result, sizeof(rsasecret));
- if (ies->refresh)
- expire = ies->refresh;
-
- if (ast_strlen_zero(peer)) {
- ast_log(LOG_NOTICE, "Empty registration from %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- return -1;
- }
- /* We release the lock for the call to prevent a deadlock, but it's okay because
- only the current thread could possibly make it go away or make changes */
- ast_mutex_unlock(&iaxsl[callno]);
- /* SLD: first call to lookup peer during registration */
- p = find_peer(peer, 1);
- ast_mutex_lock(&iaxsl[callno]);
-
- if (!p) {
- if (authdebug)
- ast_log(LOG_NOTICE, "No registration for peer '%s' (from %s)\n", peer, ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- return -1;
- }
-
- if (!ast_test_flag(p, IAX_DYNAMIC)) {
- if (authdebug)
- ast_log(LOG_NOTICE, "Peer '%s' is not dynamic (from %s)\n", peer, ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return -1;
- }
-
- if (!ast_apply_ha(p->ha, sin)) {
- if (authdebug)
- ast_log(LOG_NOTICE, "Host %s denied access to register peer '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), p->name);
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return -1;
- }
- ast_copy_string(iaxs[callno]->secret, p->secret, sizeof(iaxs[callno]->secret));
- ast_copy_string(iaxs[callno]->inkeys, p->inkeys, sizeof(iaxs[callno]->inkeys));
- /* Check secret against what we have on file */
- if (!ast_strlen_zero(rsasecret) && (p->authmethods & IAX_AUTH_RSA) && !ast_strlen_zero(iaxs[callno]->challenge)) {
- if (!ast_strlen_zero(p->inkeys)) {
- char tmpkeys[256];
- char *stringp=NULL;
- ast_copy_string(tmpkeys, p->inkeys, sizeof(tmpkeys));
- stringp=tmpkeys;
- keyn = strsep(&stringp, ":");
- while(keyn) {
- key = ast_key_get(keyn, AST_KEY_PUBLIC);
- if (key && !ast_check_signature(key, iaxs[callno]->challenge, rsasecret)) {
- ast_set_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED);
- break;
- } else if (!key)
- ast_log(LOG_WARNING, "requested inkey '%s' does not exist\n", keyn);
- keyn = strsep(&stringp, ":");
- }
- if (!keyn) {
- if (authdebug)
- ast_log(LOG_NOTICE, "Host %s failed RSA authentication with inkeys '%s'\n", peer, p->inkeys);
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return -1;
- }
- } else {
- if (authdebug)
- ast_log(LOG_NOTICE, "Host '%s' trying to do RSA authentication, but we have no inkeys\n", peer);
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return -1;
- }
- } else if (!ast_strlen_zero(secret) && (p->authmethods & IAX_AUTH_PLAINTEXT)) {
- /* They've provided a plain text password and we support that */
- if (strcmp(secret, p->secret)) {
- if (authdebug)
- ast_log(LOG_NOTICE, "Host %s did not provide proper plaintext password for '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), p->name);
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return -1;
- } else
- ast_set_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED);
- } else if (!ast_strlen_zero(md5secret) && (p->authmethods & IAX_AUTH_MD5) && !ast_strlen_zero(iaxs[callno]->challenge)) {
- struct MD5Context md5;
- unsigned char digest[16];
- char *tmppw, *stringp;
-
- tmppw = ast_strdupa(p->secret);
- stringp = tmppw;
- while((tmppw = strsep(&stringp, ";"))) {
- MD5Init(&md5);
- MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
- MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
- MD5Final(digest, &md5);
- for (x=0;x<16;x++)
- sprintf(requeststr + (x << 1), "%2.2x", digest[x]); /* safe */
- if (!strcasecmp(requeststr, md5secret))
- break;
- }
- if (tmppw) {
- ast_set_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED);
- } else {
- if (authdebug)
- ast_log(LOG_NOTICE, "Host %s failed MD5 authentication for '%s' (%s != %s)\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), p->name, requeststr, md5secret);
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return -1;
- }
- } else if (!ast_strlen_zero(md5secret) || !ast_strlen_zero(secret)) {
- if (authdebug)
- ast_log(LOG_NOTICE, "Inappropriate authentication received\n");
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return -1;
- }
- ast_copy_string(iaxs[callno]->peer, peer, sizeof(iaxs[callno]->peer));
- /* Choose lowest expiry number */
- if (expire && (expire < iaxs[callno]->expiry))
- iaxs[callno]->expiry = expire;
-
- ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
-
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return 0;
-
-}
-
-static int authenticate(char *challenge, char *secret, char *keyn, int authmethods, struct iax_ie_data *ied, struct sockaddr_in *sin, aes_encrypt_ctx *ecx, aes_decrypt_ctx *dcx)
-{
- int res = -1;
- int x;
- char iabuf[INET_ADDRSTRLEN];
- if (!ast_strlen_zero(keyn)) {
- if (!(authmethods & IAX_AUTH_RSA)) {
- if (ast_strlen_zero(secret))
- ast_log(LOG_NOTICE, "Asked to authenticate to %s with an RSA key, but they don't allow RSA authentication\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- } else if (ast_strlen_zero(challenge)) {
- ast_log(LOG_NOTICE, "No challenge provided for RSA authentication to %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- } else {
- char sig[256];
- struct ast_key *key;
- key = ast_key_get(keyn, AST_KEY_PRIVATE);
- if (!key) {
- ast_log(LOG_NOTICE, "Unable to find private key '%s'\n", keyn);
- } else {
- if (ast_sign(key, challenge, sig)) {
- ast_log(LOG_NOTICE, "Unable to sign challenge withy key\n");
- res = -1;
- } else {
- iax_ie_append_str(ied, IAX_IE_RSA_RESULT, sig);
- res = 0;
- }
- }
- }
- }
- /* Fall back */
- if (res && !ast_strlen_zero(secret)) {
- if ((authmethods & IAX_AUTH_MD5) && !ast_strlen_zero(challenge)) {
- struct MD5Context md5;
- unsigned char digest[16];
- char digres[128];
- MD5Init(&md5);
- MD5Update(&md5, (unsigned char *)challenge, strlen(challenge));
- MD5Update(&md5, (unsigned char *)secret, strlen(secret));
- MD5Final(digest, &md5);
- /* If they support md5, authenticate with it. */
- for (x=0;x<16;x++)
- sprintf(digres + (x << 1), "%2.2x", digest[x]); /* safe */
- if (ecx && dcx)
- build_enc_keys(digest, ecx, dcx);
- iax_ie_append_str(ied, IAX_IE_MD5_RESULT, digres);
- res = 0;
- } else if (authmethods & IAX_AUTH_PLAINTEXT) {
- iax_ie_append_str(ied, IAX_IE_PASSWORD, secret);
- res = 0;
- } else
- ast_log(LOG_NOTICE, "No way to send secret to peer '%s' (their methods: %d)\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), authmethods);
- }
- return res;
-}
-
-static int authenticate_reply(struct chan_iax2_pvt *p, struct sockaddr_in *sin, struct iax_ies *ies, char *override, char *okey)
-{
- struct iax2_peer *peer;
- /* Start pessimistic */
- int res = -1;
- int authmethods = 0;
- struct iax_ie_data ied;
-
- memset(&ied, 0, sizeof(ied));
-
- if (ies->username)
- ast_copy_string(p->username, ies->username, sizeof(p->username));
- if (ies->challenge)
- ast_copy_string(p->challenge, ies->challenge, sizeof(p->challenge));
- if (ies->authmethods)
- authmethods = ies->authmethods;
- if (authmethods & IAX_AUTH_MD5)
- merge_encryption(p, ies->encmethods);
- else
- p->encmethods = 0;
-
- /* Check for override RSA authentication first */
- if (!ast_strlen_zero(override) || !ast_strlen_zero(okey)) {
- /* Normal password authentication */
- res = authenticate(p->challenge, override, okey, authmethods, &ied, sin, &p->ecx, &p->dcx);
- } else {
- ast_mutex_lock(&peerl.lock);
- peer = peerl.peers;
- while(peer) {
- if ((ast_strlen_zero(p->peer) || !strcmp(p->peer, peer->name))
- /* No peer specified at our end, or this is the peer */
- && (ast_strlen_zero(peer->username) || (!strcmp(peer->username, p->username)))
- /* No username specified in peer rule, or this is the right username */
- && (!peer->addr.sin_addr.s_addr || ((sin->sin_addr.s_addr & peer->mask.s_addr) == (peer->addr.sin_addr.s_addr & peer->mask.s_addr)))
- /* No specified host, or this is our host */
- ) {
- res = authenticate(p->challenge, peer->secret, peer->outkey, authmethods, &ied, sin, &p->ecx, &p->dcx);
- if (!res)
- break;
- }
- peer = peer->next;
- }
- ast_mutex_unlock(&peerl.lock);
- if (!peer) {
- /* We checked our list and didn't find one. It's unlikely, but possible,
- that we're trying to authenticate *to* a realtime peer */
- if ((peer = realtime_peer(p->peer, NULL))) {
- res = authenticate(p->challenge, peer->secret,peer->outkey, authmethods, &ied, sin, &p->ecx, &p->dcx);
- if (ast_test_flag(peer, IAX_TEMPONLY))
- destroy_peer(peer);
- }
- }
- }
- if (ies->encmethods)
- ast_set_flag(p, IAX_ENCRYPTED | IAX_KEYPOPULATED);
- if (!res)
- res = send_command(p, AST_FRAME_IAX, IAX_COMMAND_AUTHREP, 0, ied.buf, ied.pos, -1);
- return res;
-}
-
-static int iax2_do_register(struct iax2_registry *reg);
-
-static int iax2_do_register_s(void *data)
-{
- struct iax2_registry *reg = data;
- reg->expire = -1;
- iax2_do_register(reg);
- return 0;
-}
-
-static int try_transfer(struct chan_iax2_pvt *pvt, struct iax_ies *ies)
-{
- int newcall = 0;
- char newip[256];
- struct iax_ie_data ied;
- struct sockaddr_in new;
-
-
- memset(&ied, 0, sizeof(ied));
- if (ies->apparent_addr)
- memcpy(&new, ies->apparent_addr, sizeof(new));
- if (ies->callno)
- newcall = ies->callno;
- if (!newcall || !new.sin_addr.s_addr || !new.sin_port) {
- ast_log(LOG_WARNING, "Invalid transfer request\n");
- return -1;
- }
- pvt->transfercallno = newcall;
- memcpy(&pvt->transfer, &new, sizeof(pvt->transfer));
- inet_aton(newip, &pvt->transfer.sin_addr);
- pvt->transfer.sin_family = AF_INET;
- pvt->transferring = TRANSFER_BEGIN;
- pvt->transferid = ies->transferid;
- if (ies->transferid)
- iax_ie_append_int(&ied, IAX_IE_TRANSFERID, ies->transferid);
- send_command_transfer(pvt, AST_FRAME_IAX, IAX_COMMAND_TXCNT, 0, ied.buf, ied.pos);
- return 0;
-}
-
-static int complete_dpreply(struct chan_iax2_pvt *pvt, struct iax_ies *ies)
-{
- char exten[256] = "";
- int status = CACHE_FLAG_UNKNOWN;
- int expiry = iaxdefaultdpcache;
- int x;
- int matchmore = 0;
- struct iax2_dpcache *dp, *prev;
-
- if (ies->called_number)
- ast_copy_string(exten, ies->called_number, sizeof(exten));
-
- if (ies->dpstatus & IAX_DPSTATUS_EXISTS)
- status = CACHE_FLAG_EXISTS;
- else if (ies->dpstatus & IAX_DPSTATUS_CANEXIST)
- status = CACHE_FLAG_CANEXIST;
- else if (ies->dpstatus & IAX_DPSTATUS_NONEXISTENT)
- status = CACHE_FLAG_NONEXISTENT;
-
- if (ies->dpstatus & IAX_DPSTATUS_IGNOREPAT) {
- /* Don't really do anything with this */
- }
- if (ies->refresh)
- expiry = ies->refresh;
- if (ies->dpstatus & IAX_DPSTATUS_MATCHMORE)
- matchmore = CACHE_FLAG_MATCHMORE;
- ast_mutex_lock(&dpcache_lock);
- prev = NULL;
- dp = pvt->dpentries;
- while(dp) {
- if (!strcmp(dp->exten, exten)) {
- /* Let them go */
- if (prev)
- prev->peer = dp->peer;
- else
- pvt->dpentries = dp->peer;
- dp->peer = NULL;
- dp->callno = 0;
- dp->expiry.tv_sec = dp->orig.tv_sec + expiry;
- if (dp->flags & CACHE_FLAG_PENDING) {
- dp->flags &= ~CACHE_FLAG_PENDING;
- dp->flags |= status;
- dp->flags |= matchmore;
- }
- /* Wake up waiters */
- for (x=0;x<sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++)
- if (dp->waiters[x] > -1)
- write(dp->waiters[x], "asdf", 4);
- }
- prev = dp;
- dp = dp->peer;
- }
- ast_mutex_unlock(&dpcache_lock);
- return 0;
-}
-
-static int complete_transfer(int callno, struct iax_ies *ies)
-{
- int peercallno = 0;
- struct chan_iax2_pvt *pvt = iaxs[callno];
- struct iax_frame *cur;
-
- if (ies->callno)
- peercallno = ies->callno;
-
- if (peercallno < 1) {
- ast_log(LOG_WARNING, "Invalid transfer request\n");
- return -1;
- }
- memcpy(&pvt->addr, &pvt->transfer, sizeof(pvt->addr));
- memset(&pvt->transfer, 0, sizeof(pvt->transfer));
- /* Reset sequence numbers */
- pvt->oseqno = 0;
- pvt->rseqno = 0;
- pvt->iseqno = 0;
- pvt->aseqno = 0;
- pvt->peercallno = peercallno;
- pvt->transferring = TRANSFER_NONE;
- pvt->svoiceformat = -1;
- pvt->voiceformat = 0;
- pvt->svideoformat = -1;
- pvt->videoformat = 0;
- pvt->transfercallno = -1;
- memset(&pvt->rxcore, 0, sizeof(pvt->rxcore));
- memset(&pvt->offset, 0, sizeof(pvt->offset));
-#ifdef NEWJB
- { /* reset jitterbuffer */
- jb_frame frame;
- while(jb_getall(pvt->jb,&frame) == JB_OK)
- iax2_frame_free(frame.data);
-
- jb_reset(pvt->jb);
- }
-#else
- memset(&pvt->history, 0, sizeof(pvt->history));
- pvt->jitterbuffer = 0;
- pvt->jitter = 0;
- pvt->historicjitter = 0;
-#endif
- pvt->lag = 0;
- pvt->last = 0;
- pvt->lastsent = 0;
- pvt->nextpred = 0;
- pvt->pingtime = DEFAULT_RETRY_TIME;
- ast_mutex_lock(&iaxq.lock);
- for (cur = iaxq.head; cur ; cur = cur->next) {
- /* We must cancel any packets that would have been transmitted
- because now we're talking to someone new. It's okay, they
- were transmitted to someone that didn't care anyway. */
- if (callno == cur->callno)
- cur->retries = -1;
- }
- ast_mutex_unlock(&iaxq.lock);
- return 0;
-}
-
-/*! \brief Acknowledgment received for OUR registration */
-static int iax2_ack_registry(struct iax_ies *ies, struct sockaddr_in *sin, int callno)
-{
- struct iax2_registry *reg;
- /* Start pessimistic */
- char peer[256] = "";
- char msgstatus[40];
- int refresh = 0;
- char ourip[256] = "<Unspecified>";
- struct sockaddr_in oldus;
- struct sockaddr_in us;
- char iabuf[INET_ADDRSTRLEN];
- int oldmsgs;
-
- memset(&us, 0, sizeof(us));
- if (ies->apparent_addr)
- memcpy(&us, ies->apparent_addr, sizeof(us));
- if (ies->username)
- ast_copy_string(peer, ies->username, sizeof(peer));
- if (ies->refresh)
- refresh = ies->refresh;
- if (ies->calling_number) {
- /* We don't do anything with it really, but maybe we should */
- }
- reg = iaxs[callno]->reg;
- if (!reg) {
- ast_log(LOG_WARNING, "Registry acknowledge on unknown registry '%s'\n", peer);
- return -1;
- }
- memcpy(&oldus, &reg->us, sizeof(oldus));
- oldmsgs = reg->messages;
- if (inaddrcmp(&reg->addr, sin)) {
- ast_log(LOG_WARNING, "Received unsolicited registry ack from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- return -1;
- }
- memcpy(&reg->us, &us, sizeof(reg->us));
- reg->messages = ies->msgcount;
- /* always refresh the registration at the interval requested by the server
- we are registering to
- */
- reg->refresh = refresh;
- if (reg->expire > -1)
- ast_sched_del(sched, reg->expire);
- reg->expire = ast_sched_add(sched, (5 * reg->refresh / 6) * 1000, iax2_do_register_s, reg);
- if ((inaddrcmp(&oldus, &reg->us) || (reg->messages != oldmsgs)) && (option_verbose > 2)) {
- if (reg->messages > 65534)
- snprintf(msgstatus, sizeof(msgstatus), " with message(s) waiting\n");
- else if (reg->messages > 1)
- snprintf(msgstatus, sizeof(msgstatus), " with %d messages waiting\n", reg->messages);
- else if (reg->messages > 0)
- snprintf(msgstatus, sizeof(msgstatus), " with 1 message waiting\n");
- else
- snprintf(msgstatus, sizeof(msgstatus), " with no messages waiting\n");
- snprintf(ourip, sizeof(ourip), "%s:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), reg->us.sin_addr), ntohs(reg->us.sin_port));
- ast_verbose(VERBOSE_PREFIX_3 "Registered IAX2 to '%s', who sees us as %s%s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ourip, msgstatus);
- manager_event(EVENT_FLAG_SYSTEM, "Registry", "Channel: IAX2\r\nDomain: %s\r\nStatus: Registered\r\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- }
- reg->regstate = REG_STATE_REGISTERED;
- return 0;
-}
-
-static int iax2_register(char *value, int lineno)
-{
- struct iax2_registry *reg;
- char copy[256];
- char *username, *hostname, *secret;
- char *porta;
- char *stringp=NULL;
-
- struct ast_hostent ahp; struct hostent *hp;
- if (!value)
- return -1;
- ast_copy_string(copy, value, sizeof(copy));
- stringp=copy;
- username = strsep(&stringp, "@");
- hostname = strsep(&stringp, "@");
- if (!hostname) {
- ast_log(LOG_WARNING, "Format for registration is user[:secret]@host[:port] at line %d", lineno);
- return -1;
- }
- stringp=username;
- username = strsep(&stringp, ":");
- secret = strsep(&stringp, ":");
- stringp=hostname;
- hostname = strsep(&stringp, ":");
- porta = strsep(&stringp, ":");
-
- if (porta && !atoi(porta)) {
- ast_log(LOG_WARNING, "%s is not a valid port number at line %d\n", porta, lineno);
- return -1;
- }
- hp = ast_gethostbyname(hostname, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Host '%s' not found at line %d\n", hostname, lineno);
- return -1;
- }
- reg = malloc(sizeof(struct iax2_registry));
- if (reg) {
- memset(reg, 0, sizeof(struct iax2_registry));
- ast_copy_string(reg->username, username, sizeof(reg->username));
- if (secret)
- ast_copy_string(reg->secret, secret, sizeof(reg->secret));
- reg->expire = -1;
- reg->refresh = IAX_DEFAULT_REG_EXPIRE;
- reg->addr.sin_family = AF_INET;
- memcpy(&reg->addr.sin_addr, hp->h_addr, sizeof(&reg->addr.sin_addr));
- reg->addr.sin_port = porta ? htons(atoi(porta)) : htons(IAX_DEFAULT_PORTNO);
- reg->next = registrations;
- reg->callno = 0;
- registrations = reg;
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
- return 0;
-}
-
-static void register_peer_exten(struct iax2_peer *peer, int onoff)
-{
- char multi[256];
- char *stringp, *ext;
- if (!ast_strlen_zero(regcontext)) {
- ast_copy_string(multi, ast_strlen_zero(peer->regexten) ? peer->name : peer->regexten, sizeof(multi));
- stringp = multi;
- while((ext = strsep(&stringp, "&"))) {
- if (onoff) {
- if (!ast_exists_extension(NULL, regcontext, ext, 1, NULL))
- ast_add_extension(regcontext, 1, ext, 1, NULL, NULL, "Noop", strdup(peer->name), free, channeltype);
- } else
- ast_context_remove_extension(regcontext, ext, 1, NULL);
- }
- }
-}
-static void prune_peers(void);
-
-static int expire_registry(void *data)
-{
- struct iax2_peer *p = data;
-
- ast_log(LOG_DEBUG, "Expiring registration for peer '%s'\n", p->name);
- /* Reset the address */
- memset(&p->addr, 0, sizeof(p->addr));
- /* Reset expire notice */
- p->expire = -1;
- /* Reset expiry value */
- p->expiry = min_reg_expire;
- if (!ast_test_flag(p, IAX_TEMPONLY))
- ast_db_del("IAX/Registry", p->name);
- register_peer_exten(p, 0);
- ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
- if (iax2_regfunk)
- iax2_regfunk(p->name, 0);
-
- if (ast_test_flag(p, IAX_RTAUTOCLEAR)) {
- ast_set_flag(p, IAX_DELME);
- prune_peers();
- }
-
- return 0;
-}
-
-
-static int iax2_poke_peer(struct iax2_peer *peer, int heldcall);
-
-static void reg_source_db(struct iax2_peer *p)
-{
- char data[80];
- struct in_addr in;
- char iabuf[INET_ADDRSTRLEN];
- char *c, *d;
- if (!ast_test_flag(p, IAX_TEMPONLY) && (!ast_db_get("IAX/Registry", p->name, data, sizeof(data)))) {
- c = strchr(data, ':');
- if (c) {
- *c = '\0';
- c++;
- if (inet_aton(data, &in)) {
- d = strchr(c, ':');
- if (d) {
- *d = '\0';
- d++;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Seeding '%s' at %s:%d for %d\n", p->name,
- ast_inet_ntoa(iabuf, sizeof(iabuf), in), atoi(c), atoi(d));
- iax2_poke_peer(p, 0);
- p->expiry = atoi(d);
- memset(&p->addr, 0, sizeof(p->addr));
- p->addr.sin_family = AF_INET;
- p->addr.sin_addr = in;
- p->addr.sin_port = htons(atoi(c));
- if (p->expire > -1)
- ast_sched_del(sched, p->expire);
- ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
- p->expire = ast_sched_add(sched, (p->expiry + 10) * 1000, expire_registry, (void *)p);
- if (iax2_regfunk)
- iax2_regfunk(p->name, 1);
- register_peer_exten(p, 1);
- }
-
- }
- }
- }
-}
-
-static int update_registry(char *name, struct sockaddr_in *sin, int callno, char *devtype, int fd, unsigned short refresh)
-{
- /* Called from IAX thread only, with proper iaxsl lock */
- struct iax_ie_data ied;
- struct iax2_peer *p;
- int msgcount;
- char data[80];
- char iabuf[INET_ADDRSTRLEN];
- int version;
-
- memset(&ied, 0, sizeof(ied));
-
- /* SLD: Another find_peer call during registration - this time when we are really updating our registration */
- if (!(p = find_peer(name, 1))) {
- ast_log(LOG_WARNING, "No such peer '%s'\n", name);
- return -1;
- }
-
- if (ast_test_flag((&globalflags), IAX_RTUPDATE) && (ast_test_flag(p, IAX_TEMPONLY|IAX_RTCACHEFRIENDS)))
- realtime_update_peer(name, sin);
- if (inaddrcmp(&p->addr, sin)) {
- if (iax2_regfunk)
- iax2_regfunk(p->name, 1);
- /* Stash the IP address from which they registered */
- memcpy(&p->addr, sin, sizeof(p->addr));
- snprintf(data, sizeof(data), "%s:%d:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port), p->expiry);
- if (!ast_test_flag(p, IAX_TEMPONLY) && sin->sin_addr.s_addr) {
- ast_db_put("IAX/Registry", p->name, data);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Registered IAX2 '%s' (%s) at %s:%d\n", p->name,
- ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port));
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: IAX2/%s\r\nPeerStatus: Registered\r\n", p->name);
- register_peer_exten(p, 1);
- ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
- } else if (!ast_test_flag(p, IAX_TEMPONLY)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Unregistered IAX2 '%s' (%s)\n", p->name,
- ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED");
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: IAX2/%s\r\nPeerStatus: Unregistered\r\n", p->name);
- register_peer_exten(p, 0);
- ast_db_del("IAX/Registry", p->name);
- ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
- }
- /* Update the host */
- /* Verify that the host is really there */
- iax2_poke_peer(p, callno);
- }
- /* Store socket fd */
- p->sockfd = fd;
- /* Setup the expiry */
- if (p->expire > -1)
- ast_sched_del(sched, p->expire);
- /* treat an unspecified refresh interval as the minimum */
- if (!refresh)
- refresh = min_reg_expire;
- if (refresh > max_reg_expire) {
- ast_log(LOG_NOTICE, "Restricting registration for peer '%s' to %d seconds (requested %d)\n",
- p->name, max_reg_expire, refresh);
- p->expiry = max_reg_expire;
- } else if (refresh < min_reg_expire) {
- ast_log(LOG_NOTICE, "Restricting registration for peer '%s' to %d seconds (requested %d)\n",
- p->name, min_reg_expire, refresh);
- p->expiry = min_reg_expire;
- } else {
- p->expiry = refresh;
- }
- if (p->expiry && sin->sin_addr.s_addr)
- p->expire = ast_sched_add(sched, (p->expiry + 10) * 1000, expire_registry, (void *)p);
- iax_ie_append_str(&ied, IAX_IE_USERNAME, p->name);
- iax_ie_append_int(&ied, IAX_IE_DATETIME, iax2_datetime(p->zonetag));
- if (sin->sin_addr.s_addr) {
- iax_ie_append_short(&ied, IAX_IE_REFRESH, p->expiry);
- iax_ie_append_addr(&ied, IAX_IE_APPARENT_ADDR, &p->addr);
- if (!ast_strlen_zero(p->mailbox)) {
- if (ast_test_flag(p, IAX_MESSAGEDETAIL)) {
- int new, old;
- ast_app_messagecount(p->mailbox, &new, &old);
- if (new > 255)
- new = 255;
- if (old > 255)
- old = 255;
- msgcount = (old << 8) | new;
- } else {
- msgcount = ast_app_has_voicemail(p->mailbox, NULL);
- if (msgcount)
- msgcount = 65535;
- }
- iax_ie_append_short(&ied, IAX_IE_MSGCOUNT, msgcount);
- }
- if (ast_test_flag(p, IAX_HASCALLERID)) {
- iax_ie_append_str(&ied, IAX_IE_CALLING_NUMBER, p->cid_num);
- iax_ie_append_str(&ied, IAX_IE_CALLING_NAME, p->cid_name);
- }
- }
- version = iax_check_version(devtype);
- if (version)
- iax_ie_append_short(&ied, IAX_IE_FIRMWAREVER, version);
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGACK, 0, ied.buf, ied.pos, -1);
-}
-
-static int registry_authrequest(char *name, int callno)
-{
- struct iax_ie_data ied;
- struct iax2_peer *p;
- /* SLD: third call to find_peer in registration */
- p = find_peer(name, 1);
- if (p) {
- memset(&ied, 0, sizeof(ied));
- iax_ie_append_short(&ied, IAX_IE_AUTHMETHODS, p->authmethods);
- if (p->authmethods & (IAX_AUTH_RSA | IAX_AUTH_MD5)) {
- /* Build the challenge */
- snprintf(iaxs[callno]->challenge, sizeof(iaxs[callno]->challenge), "%d", rand());
- iax_ie_append_str(&ied, IAX_IE_CHALLENGE, iaxs[callno]->challenge);
- }
- iax_ie_append_str(&ied, IAX_IE_USERNAME, name);
- if (ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGAUTH, 0, ied.buf, ied.pos, -1);;
- }
- ast_log(LOG_WARNING, "No such peer '%s'\n", name);
- return 0;
-}
-
-static int registry_rerequest(struct iax_ies *ies, int callno, struct sockaddr_in *sin)
-{
- struct iax2_registry *reg;
- /* Start pessimistic */
- struct iax_ie_data ied;
- char peer[256] = "";
- char iabuf[INET_ADDRSTRLEN];
- char challenge[256] = "";
- int res;
- int authmethods = 0;
- if (ies->authmethods)
- authmethods = ies->authmethods;
- if (ies->username)
- ast_copy_string(peer, ies->username, sizeof(peer));
- if (ies->challenge)
- ast_copy_string(challenge, ies->challenge, sizeof(challenge));
- memset(&ied, 0, sizeof(ied));
- reg = iaxs[callno]->reg;
- if (reg) {
- if (inaddrcmp(&reg->addr, sin)) {
- ast_log(LOG_WARNING, "Received unsolicited registry authenticate request from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- return -1;
- }
- if (ast_strlen_zero(reg->secret)) {
- ast_log(LOG_NOTICE, "No secret associated with peer '%s'\n", reg->username);
- reg->regstate = REG_STATE_NOAUTH;
- return -1;
- }
- iax_ie_append_str(&ied, IAX_IE_USERNAME, reg->username);
- iax_ie_append_short(&ied, IAX_IE_REFRESH, reg->refresh);
- if (reg->secret[0] == '[') {
- char tmpkey[256];
- ast_copy_string(tmpkey, reg->secret + 1, sizeof(tmpkey));
- tmpkey[strlen(tmpkey) - 1] = '\0';
- res = authenticate(challenge, NULL, tmpkey, authmethods, &ied, sin, NULL, NULL);
- } else
- res = authenticate(challenge, reg->secret, NULL, authmethods, &ied, sin, NULL, NULL);
- if (!res) {
- reg->regstate = REG_STATE_AUTHSENT;
- return send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1);
- } else
- return -1;
- ast_log(LOG_WARNING, "Registry acknowledge on unknown registery '%s'\n", peer);
- } else
- ast_log(LOG_NOTICE, "Can't reregister without a reg\n");
- return -1;
-}
-
-static int stop_stuff(int callno)
-{
- if (iaxs[callno]->lagid > -1)
- ast_sched_del(sched, iaxs[callno]->lagid);
- iaxs[callno]->lagid = -1;
- if (iaxs[callno]->pingid > -1)
- ast_sched_del(sched, iaxs[callno]->pingid);
- iaxs[callno]->pingid = -1;
- if (iaxs[callno]->autoid > -1)
- ast_sched_del(sched, iaxs[callno]->autoid);
- iaxs[callno]->autoid = -1;
- if (iaxs[callno]->initid > -1)
- ast_sched_del(sched, iaxs[callno]->initid);
- iaxs[callno]->initid = -1;
- if (iaxs[callno]->authid > -1)
- ast_sched_del(sched, iaxs[callno]->authid);
- iaxs[callno]->authid = -1;
-#ifdef NEWJB
- if (iaxs[callno]->jbid > -1)
- ast_sched_del(sched, iaxs[callno]->jbid);
- iaxs[callno]->jbid = -1;
-#endif
- return 0;
-}
-
-static int auth_reject(void *nothing)
-{
- /* Called from IAX thread only, without iaxs lock */
- int callno = (int)(long)(nothing);
- struct iax_ie_data ied;
- ast_mutex_lock(&iaxsl[callno]);
- if (iaxs[callno]) {
- iaxs[callno]->authid = -1;
- memset(&ied, 0, sizeof(ied));
- if (iaxs[callno]->authfail == IAX_COMMAND_REGREJ) {
- iax_ie_append_str(&ied, IAX_IE_CAUSE, "Registration Refused");
- iax_ie_append_byte(&ied, IAX_IE_CAUSECODE, AST_CAUSE_FACILITY_REJECTED);
- } else if (iaxs[callno]->authfail == IAX_COMMAND_REJECT) {
- iax_ie_append_str(&ied, IAX_IE_CAUSE, "No authority found");
- iax_ie_append_byte(&ied, IAX_IE_CAUSECODE, AST_CAUSE_FACILITY_NOT_SUBSCRIBED);
- }
- send_command_final(iaxs[callno], AST_FRAME_IAX, iaxs[callno]->authfail, 0, ied.buf, ied.pos, -1);
- }
- ast_mutex_unlock(&iaxsl[callno]);
- return 0;
-}
-
-static int auth_fail(int callno, int failcode)
-{
- /* Schedule sending the authentication failure in one second, to prevent
- guessing */
- ast_mutex_lock(&iaxsl[callno]);
- iaxs[callno]->authfail = failcode;
- if (delayreject) {
- ast_mutex_lock(&iaxsl[callno]);
- if (iaxs[callno]->authid > -1)
- ast_sched_del(sched, iaxs[callno]->authid);
- iaxs[callno]->authid = ast_sched_add(sched, 1000, auth_reject, (void *)(long)callno);
- ast_mutex_unlock(&iaxsl[callno]);
- } else
- auth_reject((void *)(long)callno);
- ast_mutex_unlock(&iaxsl[callno]);
- return 0;
-}
-
-static int auto_hangup(void *nothing)
-{
- /* Called from IAX thread only, without iaxs lock */
- int callno = (int)(long)(nothing);
- struct iax_ie_data ied;
- ast_mutex_lock(&iaxsl[callno]);
- if (iaxs[callno]) {
- iaxs[callno]->autoid = -1;
- memset(&ied, 0, sizeof(ied));
- iax_ie_append_str(&ied, IAX_IE_CAUSE, "Timeout");
- iax_ie_append_byte(&ied, IAX_IE_CAUSECODE, AST_CAUSE_NO_USER_RESPONSE);
- send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_HANGUP, 0, ied.buf, ied.pos, -1);
- }
- ast_mutex_unlock(&iaxsl[callno]);
- return 0;
-}
-
-static void iax2_dprequest(struct iax2_dpcache *dp, int callno)
-{
- struct iax_ie_data ied;
- /* Auto-hangup with 30 seconds of inactivity */
- if (iaxs[callno]->autoid > -1)
- ast_sched_del(sched, iaxs[callno]->autoid);
- iaxs[callno]->autoid = ast_sched_add(sched, 30000, auto_hangup, (void *)(long)callno);
- memset(&ied, 0, sizeof(ied));
- iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, dp->exten);
- send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_DPREQ, 0, ied.buf, ied.pos, -1);
- dp->flags |= CACHE_FLAG_TRANSMITTED;
-}
-
-static int iax2_vnak(int callno)
-{
- return send_command_immediate(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_VNAK, 0, NULL, 0, iaxs[callno]->iseqno);
-}
-
-static void vnak_retransmit(int callno, int last)
-{
- struct iax_frame *f;
- ast_mutex_lock(&iaxq.lock);
- f = iaxq.head;
- while(f) {
- /* Send a copy immediately */
- if ((f->callno == callno) && iaxs[f->callno] &&
- (f->oseqno >= last)) {
- send_packet(f);
- }
- f = f->next;
- }
- ast_mutex_unlock(&iaxq.lock);
-}
-
-static int iax2_poke_peer_s(void *data)
-{
- struct iax2_peer *peer = data;
- peer->pokeexpire = -1;
- iax2_poke_peer(peer, 0);
- return 0;
-}
-
-static int send_trunk(struct iax2_trunk_peer *tpeer, struct timeval *now)
-{
- int res = 0;
- struct iax_frame *fr;
- struct ast_iax2_meta_hdr *meta;
- struct ast_iax2_meta_trunk_hdr *mth;
- int calls = 0;
-
- /* Point to frame */
- fr = (struct iax_frame *)tpeer->trunkdata;
- /* Point to meta data */
- meta = (struct ast_iax2_meta_hdr *)fr->afdata;
- mth = (struct ast_iax2_meta_trunk_hdr *)meta->data;
- if (tpeer->trunkdatalen) {
- /* We're actually sending a frame, so fill the meta trunk header and meta header */
- meta->zeros = 0;
- meta->metacmd = IAX_META_TRUNK;
- if (ast_test_flag(&globalflags, IAX_TRUNKTIMESTAMPS))
- meta->cmddata = IAX_META_TRUNK_MINI;
- else
- meta->cmddata = IAX_META_TRUNK_SUPERMINI;
- mth->ts = htonl(calc_txpeerstamp(tpeer, trunkfreq, now));
- /* And the rest of the ast_iax2 header */
- fr->direction = DIRECTION_OUTGRESS;
- fr->retrans = -1;
- fr->transfer = 0;
- /* Any appropriate call will do */
- fr->data = fr->afdata;
- fr->datalen = tpeer->trunkdatalen + sizeof(struct ast_iax2_meta_hdr) + sizeof(struct ast_iax2_meta_trunk_hdr);
- res = transmit_trunk(fr, &tpeer->addr, tpeer->sockfd);
- calls = tpeer->calls;
-#if 0
- ast_log(LOG_DEBUG, "Trunking %d call chunks in %d bytes to %s:%d, ts=%d\n", calls, fr->datalen, ast_inet_ntoa(iabuf, sizeof(iabuf), tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port), ntohl(mth->ts));
-#endif
- /* Reset transmit trunk side data */
- tpeer->trunkdatalen = 0;
- tpeer->calls = 0;
- }
- if (res < 0)
- return res;
- return calls;
-}
-
-static inline int iax2_trunk_expired(struct iax2_trunk_peer *tpeer, struct timeval *now)
-{
- /* Drop when trunk is about 5 seconds idle */
- if (now->tv_sec > tpeer->trunkact.tv_sec + 5)
- return 1;
- return 0;
-}
-
-static int timing_read(int *id, int fd, short events, void *cbdata)
-{
- char buf[1024];
- int res;
- char iabuf[INET_ADDRSTRLEN];
- struct iax2_trunk_peer *tpeer, *prev = NULL, *drop=NULL;
- int processed = 0;
- int totalcalls = 0;
-#ifdef ZT_TIMERACK
- int x = 1;
-#endif
- struct timeval now;
- if (iaxtrunkdebug)
- ast_verbose("Beginning trunk processing. Trunk queue ceiling is %d bytes per host\n", MAX_TRUNKDATA);
- gettimeofday(&now, NULL);
- if (events & AST_IO_PRI) {
-#ifdef ZT_TIMERACK
- /* Great, this is a timing interface, just call the ioctl */
- if (ioctl(fd, ZT_TIMERACK, &x))
- ast_log(LOG_WARNING, "Unable to acknowledge zap timer\n");
- res = 0;
-#endif
- } else {
- /* Read and ignore from the pseudo channel for timing */
- res = read(fd, buf, sizeof(buf));
- if (res < 1) {
- ast_log(LOG_WARNING, "Unable to read from timing fd\n");
- ast_mutex_unlock(&peerl.lock);
- return 1;
- }
- }
- /* For each peer that supports trunking... */
- ast_mutex_lock(&tpeerlock);
- tpeer = tpeers;
- while(tpeer) {
- processed++;
- res = 0;
- ast_mutex_lock(&tpeer->lock);
- /* We can drop a single tpeer per pass. That makes all this logic
- substantially easier */
- if (!drop && iax2_trunk_expired(tpeer, &now)) {
- /* Take it out of the list, but don't free it yet, because it
- could be in use */
- if (prev)
- prev->next = tpeer->next;
- else
- tpeers = tpeer->next;
- drop = tpeer;
- } else {
- res = send_trunk(tpeer, &now);
- if (iaxtrunkdebug)
- ast_verbose(" - Trunk peer (%s:%d) has %d call chunk%s in transit, %d bytes backloged and has hit a high water mark of %d bytes\n", ast_inet_ntoa(iabuf, sizeof(iabuf), tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port), res, (res != 1) ? "s" : "", tpeer->trunkdatalen, tpeer->trunkdataalloc);
- }
- totalcalls += res;
- res = 0;
- ast_mutex_unlock(&tpeer->lock);
- prev = tpeer;
- tpeer = tpeer->next;
- }
- ast_mutex_unlock(&tpeerlock);
- if (drop) {
- ast_mutex_lock(&drop->lock);
- /* Once we have this lock, we're sure nobody else is using it or could use it once we release it,
- because by the time they could get tpeerlock, we've already grabbed it */
- ast_log(LOG_DEBUG, "Dropping unused iax2 trunk peer '%s:%d'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), drop->addr.sin_addr), ntohs(drop->addr.sin_port));
- free(drop->trunkdata);
- ast_mutex_unlock(&drop->lock);
- ast_mutex_destroy(&drop->lock);
- free(drop);
-
- }
- if (iaxtrunkdebug)
- ast_verbose("Ending trunk processing with %d peers and %d call chunks processed\n", processed, totalcalls);
- iaxtrunkdebug =0;
- return 1;
-}
-
-struct dpreq_data {
- int callno;
- char context[AST_MAX_EXTENSION];
- char callednum[AST_MAX_EXTENSION];
- char *callerid;
-};
-
-static void dp_lookup(int callno, char *context, char *callednum, char *callerid, int skiplock)
-{
- unsigned short dpstatus = 0;
- struct iax_ie_data ied1;
- int mm;
-
- memset(&ied1, 0, sizeof(ied1));
- mm = ast_matchmore_extension(NULL, context, callednum, 1, callerid);
- /* Must be started */
- if (!strcmp(callednum, ast_parking_ext()) || ast_exists_extension(NULL, context, callednum, 1, callerid)) {
- dpstatus = IAX_DPSTATUS_EXISTS;
- } else if (ast_canmatch_extension(NULL, context, callednum, 1, callerid)) {
- dpstatus = IAX_DPSTATUS_CANEXIST;
- } else {
- dpstatus = IAX_DPSTATUS_NONEXISTENT;
- }
- if (ast_ignore_pattern(context, callednum))
- dpstatus |= IAX_DPSTATUS_IGNOREPAT;
- if (mm)
- dpstatus |= IAX_DPSTATUS_MATCHMORE;
- if (!skiplock)
- ast_mutex_lock(&iaxsl[callno]);
- if (iaxs[callno]) {
- iax_ie_append_str(&ied1, IAX_IE_CALLED_NUMBER, callednum);
- iax_ie_append_short(&ied1, IAX_IE_DPSTATUS, dpstatus);
- iax_ie_append_short(&ied1, IAX_IE_REFRESH, iaxdefaultdpcache);
- send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_DPREP, 0, ied1.buf, ied1.pos, -1);
- }
- if (!skiplock)
- ast_mutex_unlock(&iaxsl[callno]);
-}
-
-static void *dp_lookup_thread(void *data)
-{
- /* Look up for dpreq */
- struct dpreq_data *dpr = data;
- dp_lookup(dpr->callno, dpr->context, dpr->callednum, dpr->callerid, 0);
- if (dpr->callerid)
- free(dpr->callerid);
- free(dpr);
- return NULL;
-}
-
-static void spawn_dp_lookup(int callno, char *context, char *callednum, char *callerid)
-{
- pthread_t newthread;
- struct dpreq_data *dpr;
- dpr = malloc(sizeof(struct dpreq_data));
- if (dpr) {
- memset(dpr, 0, sizeof(struct dpreq_data));
- dpr->callno = callno;
- ast_copy_string(dpr->context, context, sizeof(dpr->context));
- ast_copy_string(dpr->callednum, callednum, sizeof(dpr->callednum));
- if (callerid)
- dpr->callerid = strdup(callerid);
- if (ast_pthread_create(&newthread, NULL, dp_lookup_thread, dpr)) {
- ast_log(LOG_WARNING, "Unable to start lookup thread!\n");
- }
- } else
- ast_log(LOG_WARNING, "Out of memory!\n");
-}
-
-struct iax_dual {
- struct ast_channel *chan1;
- struct ast_channel *chan2;
-};
-
-static void *iax_park_thread(void *stuff)
-{
- struct ast_channel *chan1, *chan2;
- struct iax_dual *d;
- struct ast_frame *f;
- int ext;
- int res;
- d = stuff;
- chan1 = d->chan1;
- chan2 = d->chan2;
- free(d);
- f = ast_read(chan1);
- if (f)
- ast_frfree(f);
- res = ast_park_call(chan1, chan2, 0, &ext);
- ast_hangup(chan2);
- ast_log(LOG_NOTICE, "Parked on extension '%d'\n", ext);
- return NULL;
-}
-
-static int iax_park(struct ast_channel *chan1, struct ast_channel *chan2)
-{
- struct iax_dual *d;
- struct ast_channel *chan1m, *chan2m;
- pthread_t th;
- chan1m = ast_channel_alloc(0);
- chan2m = ast_channel_alloc(0);
- if (chan2m && chan1m) {
- snprintf(chan1m->name, sizeof(chan1m->name), "Parking/%s", chan1->name);
- /* Make formats okay */
- chan1m->readformat = chan1->readformat;
- chan1m->writeformat = chan1->writeformat;
- ast_channel_masquerade(chan1m, chan1);
- /* Setup the extensions and such */
- ast_copy_string(chan1m->context, chan1->context, sizeof(chan1m->context));
- ast_copy_string(chan1m->exten, chan1->exten, sizeof(chan1m->exten));
- chan1m->priority = chan1->priority;
-
- /* We make a clone of the peer channel too, so we can play
- back the announcement */
- snprintf(chan2m->name, sizeof (chan2m->name), "IAXPeer/%s",chan2->name);
- /* Make formats okay */
- chan2m->readformat = chan2->readformat;
- chan2m->writeformat = chan2->writeformat;
- ast_channel_masquerade(chan2m, chan2);
- /* Setup the extensions and such */
- ast_copy_string(chan2m->context, chan2->context, sizeof(chan2m->context));
- ast_copy_string(chan2m->exten, chan2->exten, sizeof(chan2m->exten));
- chan2m->priority = chan2->priority;
- if (ast_do_masquerade(chan2m)) {
- ast_log(LOG_WARNING, "Masquerade failed :(\n");
- ast_hangup(chan2m);
- return -1;
- }
- } else {
- if (chan1m)
- ast_hangup(chan1m);
- if (chan2m)
- ast_hangup(chan2m);
- return -1;
- }
- d = malloc(sizeof(struct iax_dual));
- if (d) {
- memset(d, 0, sizeof(*d));
- d->chan1 = chan1m;
- d->chan2 = chan2m;
- if (!ast_pthread_create(&th, NULL, iax_park_thread, d))
- return 0;
- free(d);
- }
- return -1;
-}
-
-
-static int iax2_provision(struct sockaddr_in *end, int sockfd, char *dest, const char *template, int force);
-
-static int check_provisioning(struct sockaddr_in *sin, int sockfd, char *si, unsigned int ver)
-{
- unsigned int ourver;
- char rsi[80];
- snprintf(rsi, sizeof(rsi), "si-%s", si);
- if (iax_provision_version(&ourver, rsi, 1))
- return 0;
- if (option_debug)
- ast_log(LOG_DEBUG, "Service identifier '%s', we think '%08x', they think '%08x'\n", si, ourver, ver);
- if (ourver != ver)
- iax2_provision(sin, sockfd, NULL, rsi, 1);
- return 0;
-}
-
-static void construct_rr(struct chan_iax2_pvt *pvt, struct iax_ie_data *iep)
-{
-#ifdef NEWJB
- jb_info stats;
- jb_getinfo(pvt->jb, &stats);
-
- memset(iep, 0, sizeof(*iep));
-
- iax_ie_append_int(iep,IAX_IE_RR_JITTER, stats.jitter);
- if(stats.frames_in == 0) stats.frames_in = 1;
- iax_ie_append_int(iep,IAX_IE_RR_LOSS, ((0xff & (stats.losspct/1000)) << 24 | (stats.frames_lost & 0x00ffffff)));
- iax_ie_append_int(iep,IAX_IE_RR_PKTS, stats.frames_in);
- iax_ie_append_short(iep,IAX_IE_RR_DELAY, stats.current - stats.min);
- iax_ie_append_int(iep,IAX_IE_RR_DROPPED, stats.frames_dropped);
- iax_ie_append_int(iep,IAX_IE_RR_OOO, stats.frames_ooo);
-#else
- memset(iep, 0, sizeof(*iep));
- iax_ie_append_int(iep,IAX_IE_RR_JITTER, pvt->jitter);
- iax_ie_append_int(iep,IAX_IE_RR_PKTS, pvt->frames_received);
- if(!ast_test_flag(pvt, IAX_USEJITTERBUF))
- iax_ie_append_short(iep,IAX_IE_RR_DELAY, 0);
- else
- iax_ie_append_short(iep,IAX_IE_RR_DELAY, pvt->jitterbuffer - pvt->min);
- iax_ie_append_int(iep,IAX_IE_RR_DROPPED, pvt->frames_dropped);
- /* don't know, don't send! iax_ie_append_int(&ied,IAX_IE_RR_OOO, 0); */
- /* don't know, don't send! iax_ie_append_int(&ied,IAX_IE_RR_LOSS, 0); */
-#endif
-}
-
-static void save_rr(struct iax_frame *fr, struct iax_ies *ies)
-{
- iaxs[fr->callno]->remote_rr.jitter = ies->rr_jitter;
- iaxs[fr->callno]->remote_rr.losspct = ies->rr_loss >> 24;
- iaxs[fr->callno]->remote_rr.losscnt = ies->rr_loss & 0xffffff;
- iaxs[fr->callno]->remote_rr.packets = ies->rr_pkts;
- iaxs[fr->callno]->remote_rr.delay = ies->rr_delay;
- iaxs[fr->callno]->remote_rr.dropped = ies->rr_dropped;
- iaxs[fr->callno]->remote_rr.ooo = ies->rr_ooo;
-}
-
-static int socket_read(int *id, int fd, short events, void *cbdata)
-{
- struct sockaddr_in sin;
- int res;
- int updatehistory=1;
- int new = NEW_PREVENT;
- unsigned char buf[4096];
- void *ptr;
- socklen_t len = sizeof(sin);
- int dcallno = 0;
- struct ast_iax2_full_hdr *fh = (struct ast_iax2_full_hdr *)buf;
- struct ast_iax2_mini_hdr *mh = (struct ast_iax2_mini_hdr *)buf;
- struct ast_iax2_meta_hdr *meta = (struct ast_iax2_meta_hdr *)buf;
- struct ast_iax2_video_hdr *vh = (struct ast_iax2_video_hdr *)buf;
- struct ast_iax2_meta_trunk_hdr *mth;
- struct ast_iax2_meta_trunk_entry *mte;
- struct ast_iax2_meta_trunk_mini *mtm;
- char dblbuf[4096]; /* Declaration of dblbuf must immediately *preceed* fr on the stack */
- struct iax_frame fr;
- struct iax_frame *cur;
- char iabuf[INET_ADDRSTRLEN];
- struct ast_frame f;
- struct ast_channel *c;
- struct iax2_dpcache *dp;
- struct iax2_peer *peer;
- struct iax2_trunk_peer *tpeer;
- struct timeval rxtrunktime;
- struct iax_ies ies;
- struct iax_ie_data ied0, ied1;
- int format;
- int exists;
- int minivid = 0;
- unsigned int ts;
- char empty[32]=""; /* Safety measure */
- struct iax_frame *duped_fr;
- char host_pref_buf[128];
- char caller_pref_buf[128];
- struct ast_codec_pref pref,rpref;
- char *using_prefs = "mine";
-
- dblbuf[0] = 0; /* Keep GCC from whining */
- fr.callno = 0;
-
- res = recvfrom(fd, buf, sizeof(buf), 0,(struct sockaddr *) &sin, &len);
- if (res < 0) {
- if (errno != ECONNREFUSED)
- ast_log(LOG_WARNING, "Error: %s\n", strerror(errno));
- handle_error();
- return 1;
- }
- if(test_losspct) { /* simulate random loss condition */
- if( (100.0*rand()/(RAND_MAX+1.0)) < test_losspct)
- return 1;
-
- }
- if (res < sizeof(struct ast_iax2_mini_hdr)) {
- ast_log(LOG_WARNING, "midget packet received (%d of %d min)\n", res, (int)sizeof(struct ast_iax2_mini_hdr));
- return 1;
- }
- if ((vh->zeros == 0) && (ntohs(vh->callno) & 0x8000)) {
- /* This is a video frame, get call number */
- fr.callno = find_callno(ntohs(vh->callno) & ~0x8000, dcallno, &sin, new, 1, fd);
- minivid = 1;
- } else if (meta->zeros == 0) {
- unsigned char metatype;
- /* This is a meta header */
- switch(meta->metacmd) {
- case IAX_META_TRUNK:
- if (res < sizeof(struct ast_iax2_meta_hdr) + sizeof(struct ast_iax2_meta_trunk_hdr)) {
- ast_log(LOG_WARNING, "midget meta trunk packet received (%d of %d min)\n", res, (int)sizeof(struct ast_iax2_mini_hdr));
- return 1;
- }
- mth = (struct ast_iax2_meta_trunk_hdr *)(meta->data);
- ts = ntohl(mth->ts);
- metatype = meta->cmddata;
- res -= (sizeof(struct ast_iax2_meta_hdr) + sizeof(struct ast_iax2_meta_trunk_hdr));
- ptr = mth->data;
- tpeer = find_tpeer(&sin, fd);
- if (!tpeer) {
- ast_log(LOG_WARNING, "Unable to accept trunked packet from '%s:%d': No matching peer\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- return 1;
- }
- tpeer->trunkact = ast_tvnow();
- if (!ts || ast_tvzero(tpeer->rxtrunktime))
- tpeer->rxtrunktime = tpeer->trunkact;
- rxtrunktime = tpeer->rxtrunktime;
- ast_mutex_unlock(&tpeer->lock);
- while(res >= sizeof(struct ast_iax2_meta_trunk_entry)) {
- /* Process channels */
- unsigned short callno, trunked_ts, len;
-
- if(metatype == IAX_META_TRUNK_MINI) {
- mtm = (struct ast_iax2_meta_trunk_mini *)ptr;
- ptr += sizeof(struct ast_iax2_meta_trunk_mini);
- res -= sizeof(struct ast_iax2_meta_trunk_mini);
- len = ntohs(mtm->len);
- callno = ntohs(mtm->mini.callno);
- trunked_ts = ntohs(mtm->mini.ts);
- } else if ( metatype == IAX_META_TRUNK_SUPERMINI ) {
- mte = (struct ast_iax2_meta_trunk_entry *)ptr;
- ptr += sizeof(struct ast_iax2_meta_trunk_entry);
- res -= sizeof(struct ast_iax2_meta_trunk_entry);
- len = ntohs(mte->len);
- callno = ntohs(mte->callno);
- trunked_ts = 0;
- } else {
- ast_log(LOG_WARNING, "Unknown meta trunk cmd from '%s:%d': dropping\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- break;
- }
- /* Stop if we don't have enough data */
- if (len > res)
- break;
- fr.callno = find_callno(callno & ~IAX_FLAG_FULL, 0, &sin, NEW_PREVENT, 1, fd);
- if (fr.callno) {
- ast_mutex_lock(&iaxsl[fr.callno]);
- /* If it's a valid call, deliver the contents. If not, we
- drop it, since we don't have a scallno to use for an INVAL */
- /* Process as a mini frame */
- f.frametype = AST_FRAME_VOICE;
- if (iaxs[fr.callno]) {
- if (iaxs[fr.callno]->voiceformat > 0) {
- f.subclass = iaxs[fr.callno]->voiceformat;
- f.datalen = len;
- if (f.datalen >= 0) {
- if (f.datalen)
- f.data = ptr;
- else
- f.data = NULL;
- if(trunked_ts) {
- fr.ts = (iaxs[fr.callno]->last & 0xFFFF0000L) | (trunked_ts & 0xffff);
- } else
- fr.ts = fix_peerts(&rxtrunktime, fr.callno, ts);
- /* Don't pass any packets until we're started */
- if (ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED)) {
- /* Common things */
- f.src = "IAX2";
- f.mallocd = 0;
- f.offset = 0;
- if (f.datalen && (f.frametype == AST_FRAME_VOICE))
- f.samples = ast_codec_get_samples(&f);
- else
- f.samples = 0;
- fr.outoforder = 0;
- iax_frame_wrap(&fr, &f);
-#ifdef BRIDGE_OPTIMIZATION
- if (iaxs[fr.callno]->bridgecallno) {
- forward_delivery(&fr);
- } else {
- duped_fr = iaxfrdup2(&fr);
- if (duped_fr) {
- schedule_delivery(duped_fr, updatehistory, 1, &fr.ts);
- }
- }
-#else
- duped_fr = iaxfrdup2(&fr);
- if (duped_fr) {
- schedule_delivery(duped_fr, updatehistory, 1, &fr.ts);
- }
-#endif
- if (iaxs[fr.callno]->last < fr.ts) {
- iaxs[fr.callno]->last = fr.ts;
-#if 1
- if (option_debug)
- ast_log(LOG_DEBUG, "For call=%d, set last=%d\n", fr.callno, fr.ts);
-#endif
- }
- }
- } else {
- ast_log(LOG_WARNING, "Datalen < 0?\n");
- }
- } else {
- ast_log(LOG_WARNING, "Received trunked frame before first full voice frame\n ");
- iax2_vnak(fr.callno);
- }
- }
- ast_mutex_unlock(&iaxsl[fr.callno]);
- }
- ptr += len;
- res -= len;
- }
-
- }
- return 1;
- }
-#ifdef DEBUG_SUPPORT
- if (iaxdebug)
- iax_showframe(NULL, fh, 1, &sin, res - sizeof(struct ast_iax2_full_hdr));
-#endif
- if (ntohs(mh->callno) & IAX_FLAG_FULL) {
- /* Get the destination call number */
- dcallno = ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS;
- /* Retrieve the type and subclass */
- f.frametype = fh->type;
- if (f.frametype == AST_FRAME_VIDEO) {
- f.subclass = uncompress_subclass(fh->csub & ~0x40) | ((fh->csub >> 6) & 0x1);
- } else {
- f.subclass = uncompress_subclass(fh->csub);
- }
- if ((f.frametype == AST_FRAME_IAX) && ((f.subclass == IAX_COMMAND_NEW) || (f.subclass == IAX_COMMAND_REGREQ) ||
- (f.subclass == IAX_COMMAND_POKE) || (f.subclass == IAX_COMMAND_FWDOWNL) ||
- (f.subclass == IAX_COMMAND_REGREL)))
- new = NEW_ALLOW;
- } else {
- /* Don't know anything about it yet */
- f.frametype = AST_FRAME_NULL;
- f.subclass = 0;
- }
-
- if (!fr.callno)
- fr.callno = find_callno(ntohs(mh->callno) & ~IAX_FLAG_FULL, dcallno, &sin, new, 1, fd);
-
- if (fr.callno > 0)
- ast_mutex_lock(&iaxsl[fr.callno]);
-
- if (!fr.callno || !iaxs[fr.callno]) {
- /* A call arrived for a nonexistent destination. Unless it's an "inval"
- frame, reply with an inval */
- if (ntohs(mh->callno) & IAX_FLAG_FULL) {
- /* We can only raw hangup control frames */
- if (((f.subclass != IAX_COMMAND_INVAL) &&
- (f.subclass != IAX_COMMAND_TXCNT) &&
- (f.subclass != IAX_COMMAND_TXACC) &&
- (f.subclass != IAX_COMMAND_FWDOWNL))||
- (f.frametype != AST_FRAME_IAX))
- raw_hangup(&sin, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS, ntohs(mh->callno) & ~IAX_FLAG_FULL,
- fd);
- }
- if (fr.callno > 0)
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- if (ast_test_flag(iaxs[fr.callno], IAX_ENCRYPTED)) {
- if (decrypt_frame(fr.callno, fh, &f, &res)) {
- ast_log(LOG_NOTICE, "Packet Decrypt Failed!\n");
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
-#ifdef DEBUG_SUPPORT
- else if (iaxdebug)
- iax_showframe(NULL, fh, 3, &sin, res - sizeof(struct ast_iax2_full_hdr));
-#endif
- }
-
- /* count this frame */
- iaxs[fr.callno]->frames_received++;
-
- if (!inaddrcmp(&sin, &iaxs[fr.callno]->addr) && !minivid &&
- f.subclass != IAX_COMMAND_TXCNT && /* for attended transfer */
- f.subclass != IAX_COMMAND_TXACC) /* for attended transfer */
- iaxs[fr.callno]->peercallno = (unsigned short)(ntohs(mh->callno) & ~IAX_FLAG_FULL);
- if (ntohs(mh->callno) & IAX_FLAG_FULL) {
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Received packet %d, (%d, %d)\n", fh->oseqno, f.frametype, f.subclass);
- /* Check if it's out of order (and not an ACK or INVAL) */
- fr.oseqno = fh->oseqno;
- fr.iseqno = fh->iseqno;
- fr.ts = ntohl(fh->ts);
-#ifdef IAXTESTS
- if (test_resync) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Simulating frame ts resync, was %u now %u\n", fr.ts, fr.ts + test_resync);
- fr.ts += test_resync;
- }
-#endif /* IAXTESTS */
-#if 0
- if ( (ntohs(fh->dcallno) & IAX_FLAG_RETRANS) ||
- ( (f.frametype != AST_FRAME_VOICE) && ! (f.frametype == AST_FRAME_IAX &&
- (f.subclass == IAX_COMMAND_NEW ||
- f.subclass == IAX_COMMAND_AUTHREQ ||
- f.subclass == IAX_COMMAND_ACCEPT ||
- f.subclass == IAX_COMMAND_REJECT)) ) )
-#endif
- if ((ntohs(fh->dcallno) & IAX_FLAG_RETRANS) || (f.frametype != AST_FRAME_VOICE))
- updatehistory = 0;
- if ((iaxs[fr.callno]->iseqno != fr.oseqno) &&
- (iaxs[fr.callno]->iseqno ||
- ((f.subclass != IAX_COMMAND_TXCNT) &&
- (f.subclass != IAX_COMMAND_TXREADY) && /* for attended transfer */
- (f.subclass != IAX_COMMAND_TXREL) && /* for attended transfer */
- (f.subclass != IAX_COMMAND_UNQUELCH ) && /* for attended transfer */
- (f.subclass != IAX_COMMAND_TXACC)) ||
- (f.frametype != AST_FRAME_IAX))) {
- if (
- ((f.subclass != IAX_COMMAND_ACK) &&
- (f.subclass != IAX_COMMAND_INVAL) &&
- (f.subclass != IAX_COMMAND_TXCNT) &&
- (f.subclass != IAX_COMMAND_TXREADY) && /* for attended transfer */
- (f.subclass != IAX_COMMAND_TXREL) && /* for attended transfer */
- (f.subclass != IAX_COMMAND_UNQUELCH ) && /* for attended transfer */
- (f.subclass != IAX_COMMAND_TXACC) &&
- (f.subclass != IAX_COMMAND_VNAK)) ||
- (f.frametype != AST_FRAME_IAX)) {
- /* If it's not an ACK packet, it's out of order. */
- if (option_debug)
- ast_log(LOG_DEBUG, "Packet arrived out of order (expecting %d, got %d) (frametype = %d, subclass = %d)\n",
- iaxs[fr.callno]->iseqno, fr.oseqno, f.frametype, f.subclass);
- if (iaxs[fr.callno]->iseqno > fr.oseqno) {
- /* If we've already seen it, ack it XXX There's a border condition here XXX */
- if ((f.frametype != AST_FRAME_IAX) ||
- ((f.subclass != IAX_COMMAND_ACK) && (f.subclass != IAX_COMMAND_INVAL))) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Acking anyway\n");
- /* XXX Maybe we should handle its ack to us, but then again, it's probably outdated anyway, and if
- we have anything to send, we'll retransmit and get an ACK back anyway XXX */
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- }
- } else {
- /* Send a VNAK requesting retransmission */
- iax2_vnak(fr.callno);
- }
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- } else {
- /* Increment unless it's an ACK or VNAK */
- if (((f.subclass != IAX_COMMAND_ACK) &&
- (f.subclass != IAX_COMMAND_INVAL) &&
- (f.subclass != IAX_COMMAND_TXCNT) &&
- (f.subclass != IAX_COMMAND_TXACC) &&
- (f.subclass != IAX_COMMAND_VNAK)) ||
- (f.frametype != AST_FRAME_IAX))
- iaxs[fr.callno]->iseqno++;
- }
- /* A full frame */
- if (res < sizeof(struct ast_iax2_full_hdr)) {
- ast_log(LOG_WARNING, "midget packet received (%d of %d min)\n", res, (int)sizeof(struct ast_iax2_full_hdr));
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- f.datalen = res - sizeof(struct ast_iax2_full_hdr);
-
- /* Handle implicit ACKing unless this is an INVAL, and only if this is
- from the real peer, not the transfer peer */
- if (!inaddrcmp(&sin, &iaxs[fr.callno]->addr) &&
- ((f.subclass != IAX_COMMAND_INVAL) ||
- (f.frametype != AST_FRAME_IAX))) {
- unsigned char x;
- /* XXX This code is not very efficient. Surely there is a better way which still
- properly handles boundary conditions? XXX */
- /* First we have to qualify that the ACKed value is within our window */
- for (x=iaxs[fr.callno]->rseqno; x != iaxs[fr.callno]->oseqno; x++)
- if (fr.iseqno == x)
- break;
- if ((x != iaxs[fr.callno]->oseqno) || (iaxs[fr.callno]->oseqno == fr.iseqno)) {
- /* The acknowledgement is within our window. Time to acknowledge everything
- that it says to */
- for (x=iaxs[fr.callno]->rseqno; x != fr.iseqno; x++) {
- /* Ack the packet with the given timestamp */
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Cancelling transmission of packet %d\n", x);
- ast_mutex_lock(&iaxq.lock);
- for (cur = iaxq.head; cur ; cur = cur->next) {
- /* If it's our call, and our timestamp, mark -1 retries */
- if ((fr.callno == cur->callno) && (x == cur->oseqno)) {
- cur->retries = -1;
- /* Destroy call if this is the end */
- if (cur->final) {
- if (iaxdebug && option_debug)
- ast_log(LOG_DEBUG, "Really destroying %d, having been acked on final message\n", fr.callno);
- iax2_destroy_nolock(fr.callno);
- }
- }
- }
- ast_mutex_unlock(&iaxq.lock);
- }
- /* Note how much we've received acknowledgement for */
- if (iaxs[fr.callno])
- iaxs[fr.callno]->rseqno = fr.iseqno;
- else {
- /* Stop processing now */
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- } else
- ast_log(LOG_DEBUG, "Received iseqno %d not within window %d->%d\n", fr.iseqno, iaxs[fr.callno]->rseqno, iaxs[fr.callno]->oseqno);
- }
- if (inaddrcmp(&sin, &iaxs[fr.callno]->addr) &&
- ((f.frametype != AST_FRAME_IAX) ||
- ((f.subclass != IAX_COMMAND_TXACC) &&
- (f.subclass != IAX_COMMAND_TXCNT)))) {
- /* Only messages we accept from a transfer host are TXACC and TXCNT */
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
-
- if (f.datalen) {
- if (f.frametype == AST_FRAME_IAX) {
- if (iax_parse_ies(&ies, buf + sizeof(struct ast_iax2_full_hdr), f.datalen)) {
- ast_log(LOG_WARNING, "Undecodable frame received from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr));
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- f.data = NULL;
- } else
- f.data = buf + sizeof(struct ast_iax2_full_hdr);
- } else {
- if (f.frametype == AST_FRAME_IAX)
- f.data = NULL;
- else
- f.data = empty;
- memset(&ies, 0, sizeof(ies));
- }
- if (f.frametype == AST_FRAME_VOICE) {
- if (f.subclass != iaxs[fr.callno]->voiceformat) {
- iaxs[fr.callno]->voiceformat = f.subclass;
- ast_log(LOG_DEBUG, "Ooh, voice format changed to %d\n", f.subclass);
- if (iaxs[fr.callno]->owner) {
- int orignative;
-retryowner:
- if (ast_mutex_trylock(&iaxs[fr.callno]->owner->lock)) {
- ast_mutex_unlock(&iaxsl[fr.callno]);
- usleep(1);
- ast_mutex_lock(&iaxsl[fr.callno]);
- if (iaxs[fr.callno] && iaxs[fr.callno]->owner) goto retryowner;
- }
- if (iaxs[fr.callno]) {
- if (iaxs[fr.callno]->owner) {
- orignative = iaxs[fr.callno]->owner->nativeformats;
- iaxs[fr.callno]->owner->nativeformats = f.subclass;
- if (iaxs[fr.callno]->owner->readformat)
- ast_set_read_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->readformat);
- iaxs[fr.callno]->owner->nativeformats = orignative;
- ast_mutex_unlock(&iaxs[fr.callno]->owner->lock);
- }
- } else {
- ast_log(LOG_DEBUG, "Neat, somebody took away the channel at a magical time but i found it!\n");
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- }
- }
- }
- if (f.frametype == AST_FRAME_VIDEO) {
- if (f.subclass != iaxs[fr.callno]->videoformat) {
- ast_log(LOG_DEBUG, "Ooh, video format changed to %d\n", f.subclass & ~0x1);
- iaxs[fr.callno]->videoformat = f.subclass & ~0x1;
- }
- }
- if (f.frametype == AST_FRAME_IAX) {
- if (iaxs[fr.callno]->initid > -1) {
- /* Don't auto congest anymore since we've gotten something usefulb ack */
- ast_sched_del(sched, iaxs[fr.callno]->initid);
- iaxs[fr.callno]->initid = -1;
- }
- /* Handle the IAX pseudo frame itself */
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "IAX subclass %d received\n", f.subclass);
-
- /* Update last ts unless the frame's timestamp originated with us. */
- if (iaxs[fr.callno]->last < fr.ts &&
- f.subclass != IAX_COMMAND_ACK &&
- f.subclass != IAX_COMMAND_PONG &&
- f.subclass != IAX_COMMAND_LAGRP) {
- iaxs[fr.callno]->last = fr.ts;
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "For call=%d, set last=%d\n", fr.callno, fr.ts);
- }
-
- switch(f.subclass) {
- case IAX_COMMAND_ACK:
- /* Do nothing */
- break;
- case IAX_COMMAND_QUELCH:
- if (ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED)) {
- /* Generate Manager Hold event, if necessary*/
- if (iaxs[fr.callno]->owner) {
- manager_event(EVENT_FLAG_CALL, "Hold",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n",
- iaxs[fr.callno]->owner->name,
- iaxs[fr.callno]->owner->uniqueid);
- }
-
- ast_set_flag(iaxs[fr.callno], IAX_QUELCH);
- if (ies.musiconhold) {
- if (iaxs[fr.callno]->owner &&
- ast_bridged_channel(iaxs[fr.callno]->owner))
- ast_moh_start(ast_bridged_channel(iaxs[fr.callno]->owner), NULL);
- }
- }
- break;
- case IAX_COMMAND_UNQUELCH:
- if (ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED)) {
- /* Generate Manager Unhold event, if necessary*/
- if (iaxs[fr.callno]->owner && ast_test_flag(iaxs[fr.callno], IAX_QUELCH)) {
- manager_event(EVENT_FLAG_CALL, "Unhold",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n",
- iaxs[fr.callno]->owner->name,
- iaxs[fr.callno]->owner->uniqueid);
- }
-
- ast_clear_flag(iaxs[fr.callno], IAX_QUELCH);
- if (iaxs[fr.callno]->owner &&
- ast_bridged_channel(iaxs[fr.callno]->owner))
- ast_moh_stop(ast_bridged_channel(iaxs[fr.callno]->owner));
- }
- break;
- case IAX_COMMAND_TXACC:
- if (iaxs[fr.callno]->transferring == TRANSFER_BEGIN) {
- /* Ack the packet with the given timestamp */
- ast_mutex_lock(&iaxq.lock);
- for (cur = iaxq.head; cur ; cur = cur->next) {
- /* Cancel any outstanding txcnt's */
- if ((fr.callno == cur->callno) && (cur->transfer))
- cur->retries = -1;
- }
- ast_mutex_unlock(&iaxq.lock);
- memset(&ied1, 0, sizeof(ied1));
- iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[fr.callno]->callno);
- send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_TXREADY, 0, ied1.buf, ied1.pos, -1);
- iaxs[fr.callno]->transferring = TRANSFER_READY;
- }
- break;
- case IAX_COMMAND_NEW:
- /* Ignore if it's already up */
- if (ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED | IAX_STATE_TBD))
- break;
- if (ies.provverpres && ies.serviceident && sin.sin_addr.s_addr)
- check_provisioning(&sin, fd, ies.serviceident, ies.provver);
- /* If we're in trunk mode, do it now, and update the trunk number in our frame before continuing */
- if (ast_test_flag(iaxs[fr.callno], IAX_TRUNK)) {
- fr.callno = make_trunk(fr.callno, 1);
- }
- /* For security, always ack immediately */
- if (delayreject)
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- if (check_access(fr.callno, &sin, &ies)) {
- /* They're not allowed on */
- auth_fail(fr.callno, IAX_COMMAND_REJECT);
- if (authdebug)
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, who was trying to reach '%s@%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
- break;
- }
- /* This might re-enter the IAX code and need the lock */
- if (strcasecmp(iaxs[fr.callno]->exten, "TBD")) {
- ast_mutex_unlock(&iaxsl[fr.callno]);
- exists = ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->cid_num);
- ast_mutex_lock(&iaxsl[fr.callno]);
- } else
- exists = 0;
- if (ast_strlen_zero(iaxs[fr.callno]->secret) && ast_strlen_zero(iaxs[fr.callno]->inkeys)) {
- if (strcmp(iaxs[fr.callno]->exten, "TBD") && !exists) {
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No such context/extension");
- iax_ie_append_byte(&ied0, IAX_IE_CAUSECODE, AST_CAUSE_NO_ROUTE_DESTINATION);
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- if (authdebug)
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, request '%s@%s' does not exist\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
- } else {
- /* Select an appropriate format */
-
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOPREFS)) {
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP)) {
- using_prefs = "reqonly";
- } else {
- using_prefs = "disabled";
- }
- format = iaxs[fr.callno]->peerformat & iaxs[fr.callno]->capability;
- memset(&pref, 0, sizeof(pref));
- strcpy(caller_pref_buf, "disabled");
- strcpy(host_pref_buf, "disabled");
- } else {
- using_prefs = "mine";
- if(ies.codec_prefs) {
- ast_codec_pref_convert(&rpref, ies.codec_prefs, 32, 0);
- /* If we are codec_first_choice we let the caller have the 1st shot at picking the codec.*/
- if (ast_test_flag(iaxs[fr.callno], IAX_CODEC_USER_FIRST)) {
- pref = rpref;
- using_prefs = "caller";
- } else {
- pref = iaxs[fr.callno]->prefs;
- }
- } else
- pref = iaxs[fr.callno]->prefs;
-
- format = ast_codec_choose(&pref, iaxs[fr.callno]->capability & iaxs[fr.callno]->peercapability, 0);
- ast_codec_pref_string(&rpref, caller_pref_buf, sizeof(caller_pref_buf) - 1);
- ast_codec_pref_string(&iaxs[fr.callno]->prefs, host_pref_buf, sizeof(host_pref_buf) - 1);
- }
- if (!format) {
- if(!ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP))
- format = iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability;
- if (!format) {
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
- iax_ie_append_byte(&ied0, IAX_IE_CAUSECODE, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- if (authdebug) {
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP))
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested 0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->capability);
- else
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iaxs[fr.callno]->capability);
- }
- } else {
- /* Pick one... */
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP)) {
- if(!(iaxs[fr.callno]->peerformat & iaxs[fr.callno]->capability))
- format = 0;
- } else {
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOPREFS)) {
- using_prefs = ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP) ? "reqonly" : "disabled";
- memset(&pref, 0, sizeof(pref));
- format = ast_best_codec(iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
- strcpy(caller_pref_buf,"disabled");
- strcpy(host_pref_buf,"disabled");
- } else {
- using_prefs = "mine";
- if(ies.codec_prefs) {
- /* Do the opposite of what we tried above. */
- if (ast_test_flag(iaxs[fr.callno], IAX_CODEC_USER_FIRST)) {
- pref = iaxs[fr.callno]->prefs;
- } else {
- pref = rpref;
- using_prefs = "caller";
- }
- format = ast_codec_choose(&pref, iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability, 1);
-
- } else /* if no codec_prefs IE do it the old way */
- format = ast_best_codec(iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
- }
- }
-
- if (!format) {
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
- iax_ie_append_byte(&ied0, IAX_IE_CAUSECODE, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
- ast_log(LOG_ERROR, "No best format in 0x%x???\n", iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- if (authdebug)
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iaxs[fr.callno]->capability);
- ast_set_flag(iaxs[fr.callno], IAX_ALREADYGONE);
- break;
- }
- }
- }
- if (format) {
- /* No authentication required, let them in */
- memset(&ied1, 0, sizeof(ied1));
- iax_ie_append_int(&ied1, IAX_IE_FORMAT, format);
- send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACCEPT, 0, ied1.buf, ied1.pos, -1);
- if (strcmp(iaxs[fr.callno]->exten, "TBD")) {
- ast_set_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Accepting UNAUTHENTICATED call from %s:\n"
- "%srequested format = %s,\n"
- "%srequested prefs = %s,\n"
- "%sactual format = %s,\n"
- "%shost prefs = %s,\n"
- "%spriority = %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr),
- VERBOSE_PREFIX_4,
- ast_getformatname(iaxs[fr.callno]->peerformat),
- VERBOSE_PREFIX_4,
- caller_pref_buf,
- VERBOSE_PREFIX_4,
- ast_getformatname(format),
- VERBOSE_PREFIX_4,
- host_pref_buf,
- VERBOSE_PREFIX_4,
- using_prefs);
-
- if(!(c = ast_iax2_new(fr.callno, AST_STATE_RING, format)))
- iax2_destroy_nolock(fr.callno);
- } else {
- ast_set_flag(&iaxs[fr.callno]->state, IAX_STATE_TBD);
- /* If this is a TBD call, we're ready but now what... */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Accepted unauthenticated TBD call from %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr));
- }
- }
- }
- break;
- }
- if (iaxs[fr.callno]->authmethods & IAX_AUTH_MD5)
- merge_encryption(iaxs[fr.callno],ies.encmethods);
- else
- iaxs[fr.callno]->encmethods = 0;
- authenticate_request(iaxs[fr.callno]);
- ast_set_flag(&iaxs[fr.callno]->state, IAX_STATE_AUTHENTICATED);
- break;
- case IAX_COMMAND_DPREQ:
- /* Request status in the dialplan */
- if (ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_TBD) &&
- !ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED) && ies.called_number) {
- if (iaxcompat) {
- /* Spawn a thread for the lookup */
- spawn_dp_lookup(fr.callno, iaxs[fr.callno]->context, ies.called_number, iaxs[fr.callno]->cid_num);
- } else {
- /* Just look it up */
- dp_lookup(fr.callno, iaxs[fr.callno]->context, ies.called_number, iaxs[fr.callno]->cid_num, 1);
- }
- }
- break;
- case IAX_COMMAND_HANGUP:
- ast_set_flag(iaxs[fr.callno], IAX_ALREADYGONE);
- ast_log(LOG_DEBUG, "Immediately destroying %d, having received hangup\n", fr.callno);
- /* Set hangup cause according to remote */
- if (ies.causecode && iaxs[fr.callno]->owner)
- iaxs[fr.callno]->owner->hangupcause = ies.causecode;
- /* Send ack immediately, before we destroy */
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- iax2_destroy_nolock(fr.callno);
- break;
- case IAX_COMMAND_REJECT:
- memset(&f, 0, sizeof(f));
- f.frametype = AST_FRAME_CONTROL;
- f.subclass = AST_CONTROL_CONGESTION;
-
- /* Set hangup cause according to remote */
- if (ies.causecode && iaxs[fr.callno]->owner)
- iaxs[fr.callno]->owner->hangupcause = ies.causecode;
-
- iax2_queue_frame(fr.callno, &f);
- if (ast_test_flag(iaxs[fr.callno], IAX_PROVISION)) {
- /* Send ack immediately, before we destroy */
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- iax2_destroy_nolock(fr.callno);
- break;
- }
- if (iaxs[fr.callno]->owner) {
- if (authdebug)
- ast_log(LOG_WARNING, "Call rejected by %s: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[fr.callno]->addr.sin_addr), ies.cause ? ies.cause : "<Unknown>");
- }
- ast_log(LOG_DEBUG, "Immediately destroying %d, having received reject\n", fr.callno);
- /* Send ack immediately, before we destroy */
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- iaxs[fr.callno]->error = EPERM;
- iax2_destroy_nolock(fr.callno);
- break;
- case IAX_COMMAND_TRANSFER:
- if (iaxs[fr.callno]->owner && ast_bridged_channel(iaxs[fr.callno]->owner) && ies.called_number) {
- if (!strcmp(ies.called_number, ast_parking_ext())) {
- if (iax_park(ast_bridged_channel(iaxs[fr.callno]->owner), iaxs[fr.callno]->owner)) {
- ast_log(LOG_WARNING, "Failed to park call on '%s'\n", ast_bridged_channel(iaxs[fr.callno]->owner)->name);
- } else
- ast_log(LOG_DEBUG, "Parked call on '%s'\n", ast_bridged_channel(iaxs[fr.callno]->owner)->name);
- } else {
- if (ast_async_goto(ast_bridged_channel(iaxs[fr.callno]->owner), iaxs[fr.callno]->context, ies.called_number, 1))
- ast_log(LOG_WARNING, "Async goto of '%s' to '%s@%s' failed\n", ast_bridged_channel(iaxs[fr.callno]->owner)->name,
- ies.called_number, iaxs[fr.callno]->context);
- else
- ast_log(LOG_DEBUG, "Async goto of '%s' to '%s@%s' started\n", ast_bridged_channel(iaxs[fr.callno]->owner)->name,
- ies.called_number, iaxs[fr.callno]->context);
- }
- } else
- ast_log(LOG_DEBUG, "Async goto not applicable on call %d\n", fr.callno);
- break;
- case IAX_COMMAND_ACCEPT:
- /* Ignore if call is already up or needs authentication or is a TBD */
- if (ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED | IAX_STATE_TBD | IAX_STATE_AUTHENTICATED))
- break;
- if (ast_test_flag(iaxs[fr.callno], IAX_PROVISION)) {
- /* Send ack immediately, before we destroy */
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- iax2_destroy_nolock(fr.callno);
- break;
- }
- if (ies.format) {
- iaxs[fr.callno]->peerformat = ies.format;
- } else {
- if (iaxs[fr.callno]->owner)
- iaxs[fr.callno]->peerformat = iaxs[fr.callno]->owner->nativeformats;
- else
- iaxs[fr.callno]->peerformat = iaxs[fr.callno]->capability;
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Call accepted by %s (format %s)\n", ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[fr.callno]->addr.sin_addr), ast_getformatname(iaxs[fr.callno]->peerformat));
- if (!(iaxs[fr.callno]->peerformat & iaxs[fr.callno]->capability)) {
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
- iax_ie_append_byte(&ied0, IAX_IE_CAUSECODE, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- if (authdebug)
- ast_log(LOG_NOTICE, "Rejected call to %s, format 0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->capability);
- } else {
- ast_set_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED);
- if (iaxs[fr.callno]->owner) {
- /* Switch us to use a compatible format */
- iaxs[fr.callno]->owner->nativeformats = iaxs[fr.callno]->peerformat;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Format for call is %s\n", ast_getformatname(iaxs[fr.callno]->owner->nativeformats));
-retryowner2:
- if (ast_mutex_trylock(&iaxs[fr.callno]->owner->lock)) {
- ast_mutex_unlock(&iaxsl[fr.callno]);
- usleep(1);
- ast_mutex_lock(&iaxsl[fr.callno]);
- if (iaxs[fr.callno] && iaxs[fr.callno]->owner) goto retryowner2;
- }
-
- if (iaxs[fr.callno] && iaxs[fr.callno]->owner) {
- /* Setup read/write formats properly. */
- if (iaxs[fr.callno]->owner->writeformat)
- ast_set_write_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->writeformat);
- if (iaxs[fr.callno]->owner->readformat)
- ast_set_read_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->readformat);
- ast_mutex_unlock(&iaxs[fr.callno]->owner->lock);
- }
- }
- }
- ast_mutex_lock(&dpcache_lock);
- dp = iaxs[fr.callno]->dpentries;
- while(dp) {
- if (!(dp->flags & CACHE_FLAG_TRANSMITTED)) {
- iax2_dprequest(dp, fr.callno);
- }
- dp = dp->peer;
- }
- ast_mutex_unlock(&dpcache_lock);
- break;
- case IAX_COMMAND_POKE:
- /* Send back a pong packet with the original timestamp */
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PONG, fr.ts, NULL, 0, -1);
- break;
- case IAX_COMMAND_PING:
-#ifdef BRIDGE_OPTIMIZATION
- if (iaxs[fr.callno]->bridgecallno) {
- /* If we're in a bridged call, just forward this */
- forward_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PING, fr.ts, NULL, 0, -1);
- } else {
- struct iax_ie_data pingied;
- construct_rr(iaxs[fr.callno], &pingied);
- /* Send back a pong packet with the original timestamp */
- send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PONG, fr.ts, pingied.buf, pingied.pos, -1);
- }
-#else
- {
- struct iax_ie_data pingied;
- construct_rr(iaxs[fr.callno], &pingied);
- /* Send back a pong packet with the original timestamp */
- send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PONG, fr.ts, pingied.buf, pingied.pos, -1);
- }
-#endif
- break;
- case IAX_COMMAND_PONG:
-#ifdef BRIDGE_OPTIMIZATION
- if (iaxs[fr.callno]->bridgecallno) {
- /* Forward to the other side of the bridge */
- forward_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PONG, fr.ts, NULL, 0, -1);
- } else {
- /* Calculate ping time */
- iaxs[fr.callno]->pingtime = calc_timestamp(iaxs[fr.callno], 0, &f) - fr.ts;
- }
-#else
- /* Calculate ping time */
- iaxs[fr.callno]->pingtime = calc_timestamp(iaxs[fr.callno], 0, &f) - fr.ts;
-#endif
- /* save RR info */
- save_rr(&fr, &ies);
-
- if (iaxs[fr.callno]->peerpoke) {
- peer = iaxs[fr.callno]->peerpoke;
- if ((peer->lastms < 0) || (peer->historicms > peer->maxms)) {
- if (iaxs[fr.callno]->pingtime <= peer->maxms) {
- ast_log(LOG_NOTICE, "Peer '%s' is now REACHABLE! Time: %d\n", peer->name, iaxs[fr.callno]->pingtime);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: IAX2/%s\r\nPeerStatus: Reachable\r\nTime: %d\r\n", peer->name, iaxs[fr.callno]->pingtime);
- ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
- }
- } else if ((peer->historicms > 0) && (peer->historicms <= peer->maxms)) {
- if (iaxs[fr.callno]->pingtime > peer->maxms) {
- ast_log(LOG_NOTICE, "Peer '%s' is now TOO LAGGED (%d ms)!\n", peer->name, iaxs[fr.callno]->pingtime);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: IAX2/%s\r\nPeerStatus: Lagged\r\nTime: %d\r\n", peer->name, iaxs[fr.callno]->pingtime);
- ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
- }
- }
- peer->lastms = iaxs[fr.callno]->pingtime;
- if (peer->smoothing && (peer->lastms > -1))
- peer->historicms = (iaxs[fr.callno]->pingtime + peer->historicms) / 2;
- else if (peer->smoothing && peer->lastms < 0)
- peer->historicms = (0 + peer->historicms) / 2;
- else
- peer->historicms = iaxs[fr.callno]->pingtime;
-
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- iax2_destroy_nolock(fr.callno);
- peer->callno = 0;
- /* Try again eventually */
- ast_log(LOG_DEBUG, "Peer lastms %d, historicms %d, maxms %d\n", peer->lastms, peer->historicms, peer->maxms);
- if ((peer->lastms < 0) || (peer->historicms > peer->maxms))
- peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_peer_s, peer);
- else
- peer->pokeexpire = ast_sched_add(sched, peer->pokefreqok, iax2_poke_peer_s, peer);
- }
- break;
- case IAX_COMMAND_LAGRQ:
- case IAX_COMMAND_LAGRP:
-#ifdef BRIDGE_OPTIMIZATION
- if (iaxs[fr.callno]->bridgecallno) {
- forward_command(iaxs[fr.callno], AST_FRAME_IAX, f.subclass, fr.ts, NULL, 0, -1);
- } else {
-#endif
- f.src = "LAGRQ";
- f.mallocd = 0;
- f.offset = 0;
- f.samples = 0;
- iax_frame_wrap(&fr, &f);
- if(f.subclass == IAX_COMMAND_LAGRQ) {
- /* Received a LAGRQ - echo back a LAGRP */
- fr.af.subclass = IAX_COMMAND_LAGRP;
- iax2_send(iaxs[fr.callno], &fr.af, fr.ts, -1, 0, 0, 0);
- } else {
- /* Received LAGRP in response to our LAGRQ */
- unsigned int ts;
- /* This is a reply we've been given, actually measure the difference */
- ts = calc_timestamp(iaxs[fr.callno], 0, &fr.af);
- iaxs[fr.callno]->lag = ts - fr.ts;
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Peer %s lag measured as %dms\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[fr.callno]->addr.sin_addr), iaxs[fr.callno]->lag);
- }
-#ifdef BRIDGE_OPTIMIZATION
- }
-#endif
- break;
- case IAX_COMMAND_AUTHREQ:
- if (ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED | IAX_STATE_TBD)) {
- ast_log(LOG_WARNING, "Call on %s is already up, can't start on it\n", iaxs[fr.callno]->owner ? iaxs[fr.callno]->owner->name : "<Unknown>");
- break;
- }
- if (authenticate_reply(iaxs[fr.callno], &iaxs[fr.callno]->addr, &ies, iaxs[fr.callno]->secret, iaxs[fr.callno]->outkey)) {
- ast_log(LOG_WARNING,
- "I don't know how to authenticate %s to %s\n",
- ies.username ? ies.username : "<unknown>", ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[fr.callno]->addr.sin_addr));
- }
- break;
- case IAX_COMMAND_AUTHREP:
- /* For security, always ack immediately */
- if (delayreject)
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- /* Ignore once we've started */
- if (ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED | IAX_STATE_TBD)) {
- ast_log(LOG_WARNING, "Call on %s is already up, can't start on it\n", iaxs[fr.callno]->owner ? iaxs[fr.callno]->owner->name : "<Unknown>");
- break;
- }
- if (authenticate_verify(iaxs[fr.callno], &ies)) {
- if (authdebug)
- ast_log(LOG_NOTICE, "Host %s failed to authenticate as %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[fr.callno]->addr.sin_addr), iaxs[fr.callno]->username);
- memset(&ied0, 0, sizeof(ied0));
- auth_fail(fr.callno, IAX_COMMAND_REJECT);
- break;
- }
- if (strcasecmp(iaxs[fr.callno]->exten, "TBD")) {
- /* This might re-enter the IAX code and need the lock */
- exists = ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->cid_num);
- } else
- exists = 0;
- if (strcmp(iaxs[fr.callno]->exten, "TBD") && !exists) {
- if (authdebug)
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, request '%s@%s' does not exist\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No such context/extension");
- iax_ie_append_byte(&ied0, IAX_IE_CAUSECODE, AST_CAUSE_NO_ROUTE_DESTINATION);
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- } else {
- /* Select an appropriate format */
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOPREFS)) {
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP)) {
- using_prefs = "reqonly";
- } else {
- using_prefs = "disabled";
- }
- format = iaxs[fr.callno]->peerformat & iaxs[fr.callno]->capability;
- memset(&pref, 0, sizeof(pref));
- strcpy(caller_pref_buf, "disabled");
- strcpy(host_pref_buf, "disabled");
- } else {
- using_prefs = "mine";
- if(ies.codec_prefs) {
- /* If we are codec_first_choice we let the caller have the 1st shot at picking the codec.*/
- ast_codec_pref_convert(&rpref, ies.codec_prefs, 32, 0);
- if (ast_test_flag(iaxs[fr.callno], IAX_CODEC_USER_FIRST)) {
- ast_codec_pref_convert(&pref, ies.codec_prefs, 32, 0);
- using_prefs = "caller";
- } else {
- pref = iaxs[fr.callno]->prefs;
- }
- } else /* if no codec_prefs IE do it the old way */
- pref = iaxs[fr.callno]->prefs;
-
- format = ast_codec_choose(&pref, iaxs[fr.callno]->capability & iaxs[fr.callno]->peercapability, 0);
- ast_codec_pref_string(&rpref, caller_pref_buf, sizeof(caller_pref_buf) - 1);
- ast_codec_pref_string(&iaxs[fr.callno]->prefs, host_pref_buf, sizeof(host_pref_buf) - 1);
- }
- if (!format) {
- if(!ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP)) {
- ast_log(LOG_DEBUG, "We don't do requested format %s, falling back to peer capability %d\n", ast_getformatname(iaxs[fr.callno]->peerformat), iaxs[fr.callno]->peercapability);
- format = iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability;
- }
- if (!format) {
- if (authdebug) {
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP))
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested 0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->capability);
- else
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iaxs[fr.callno]->capability);
- }
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
- iax_ie_append_byte(&ied0, IAX_IE_CAUSECODE, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- } else {
- /* Pick one... */
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP)) {
- if(!(iaxs[fr.callno]->peerformat & iaxs[fr.callno]->capability))
- format = 0;
- } else {
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOPREFS)) {
- using_prefs = ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP) ? "reqonly" : "disabled";
- memset(&pref, 0, sizeof(pref));
- format = ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP) ?
- iaxs[fr.callno]->peerformat : ast_best_codec(iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
- strcpy(caller_pref_buf,"disabled");
- strcpy(host_pref_buf,"disabled");
- } else {
- using_prefs = "mine";
- if(ies.codec_prefs) {
- /* Do the opposite of what we tried above. */
- if (ast_test_flag(iaxs[fr.callno], IAX_CODEC_USER_FIRST)) {
- pref = iaxs[fr.callno]->prefs;
- } else {
- pref = rpref;
- using_prefs = "caller";
- }
- format = ast_codec_choose(&pref, iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability, 1);
- } else /* if no codec_prefs IE do it the old way */
- format = ast_best_codec(iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
- }
- }
- if (!format) {
- ast_log(LOG_ERROR, "No best format in 0x%x???\n", iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
- if (authdebug) {
- if(ast_test_flag(iaxs[fr.callno], IAX_CODEC_NOCAP))
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested 0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->capability);
- else
- ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iaxs[fr.callno]->capability);
- }
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
- iax_ie_append_byte(&ied0, IAX_IE_CAUSECODE, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- }
- }
- }
- if (format) {
- /* Authentication received */
- memset(&ied1, 0, sizeof(ied1));
- iax_ie_append_int(&ied1, IAX_IE_FORMAT, format);
- send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACCEPT, 0, ied1.buf, ied1.pos, -1);
- if (strcmp(iaxs[fr.callno]->exten, "TBD")) {
- ast_set_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Accepting AUTHENTICATED call from %s:\n"
- "%srequested format = %s,\n"
- "%srequested prefs = %s,\n"
- "%sactual format = %s,\n"
- "%shost prefs = %s,\n"
- "%spriority = %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr),
- VERBOSE_PREFIX_4,
- ast_getformatname(iaxs[fr.callno]->peerformat),
- VERBOSE_PREFIX_4,
- caller_pref_buf,
- VERBOSE_PREFIX_4,
- ast_getformatname(format),
- VERBOSE_PREFIX_4,
- host_pref_buf,
- VERBOSE_PREFIX_4,
- using_prefs);
-
- ast_set_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED);
- if(!(c = ast_iax2_new(fr.callno, AST_STATE_RING, format)))
- iax2_destroy_nolock(fr.callno);
- } else {
- ast_set_flag(&iaxs[fr.callno]->state, IAX_STATE_TBD);
- /* If this is a TBD call, we're ready but now what... */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Accepted AUTHENTICATED TBD call from %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr));
- }
- }
- }
- break;
- case IAX_COMMAND_DIAL:
- if (ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_TBD)) {
- ast_clear_flag(&iaxs[fr.callno]->state, IAX_STATE_TBD);
- ast_copy_string(iaxs[fr.callno]->exten, ies.called_number ? ies.called_number : "s", sizeof(iaxs[fr.callno]->exten));
- if (!ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->cid_num)) {
- if (authdebug)
- ast_log(LOG_NOTICE, "Rejected dial attempt from %s, request '%s@%s' does not exist\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No such context/extension");
- iax_ie_append_byte(&ied0, IAX_IE_CAUSECODE, AST_CAUSE_NO_ROUTE_DESTINATION);
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- } else {
- ast_set_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Accepting DIAL from %s, formats = 0x%x\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat);
- ast_set_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED);
- send_command(iaxs[fr.callno], AST_FRAME_CONTROL, AST_CONTROL_PROGRESS, 0, NULL, 0, -1);
- if(!(c = ast_iax2_new(fr.callno, AST_STATE_RING, iaxs[fr.callno]->peerformat)))
- iax2_destroy_nolock(fr.callno);
- }
- }
- break;
- case IAX_COMMAND_INVAL:
- iaxs[fr.callno]->error = ENOTCONN;
- ast_log(LOG_DEBUG, "Immediately destroying %d, having received INVAL\n", fr.callno);
- iax2_destroy_nolock(fr.callno);
- if (option_debug)
- ast_log(LOG_DEBUG, "Destroying call %d\n", fr.callno);
- break;
- case IAX_COMMAND_VNAK:
- ast_log(LOG_DEBUG, "Received VNAK: resending outstanding frames\n");
- /* Force retransmission */
- vnak_retransmit(fr.callno, fr.iseqno);
- break;
- case IAX_COMMAND_REGREQ:
- case IAX_COMMAND_REGREL:
- /* For security, always ack immediately */
- if (delayreject)
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- if (register_verify(fr.callno, &sin, &ies)) {
- /* Send delayed failure */
- auth_fail(fr.callno, IAX_COMMAND_REGREJ);
- break;
- }
- if ((ast_strlen_zero(iaxs[fr.callno]->secret) && ast_strlen_zero(iaxs[fr.callno]->inkeys)) || ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_AUTHENTICATED)) {
- if (f.subclass == IAX_COMMAND_REGREL)
- memset(&sin, 0, sizeof(sin));
- if (update_registry(iaxs[fr.callno]->peer, &sin, fr.callno, ies.devicetype, fd, ies.refresh))
- ast_log(LOG_WARNING, "Registry error\n");
- if (ies.provverpres && ies.serviceident && sin.sin_addr.s_addr)
- check_provisioning(&sin, fd, ies.serviceident, ies.provver);
- break;
- }
- registry_authrequest(iaxs[fr.callno]->peer, fr.callno);
- break;
- case IAX_COMMAND_REGACK:
- if (iax2_ack_registry(&ies, &sin, fr.callno))
- ast_log(LOG_WARNING, "Registration failure\n");
- /* Send ack immediately, before we destroy */
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- iax2_destroy_nolock(fr.callno);
- break;
- case IAX_COMMAND_REGREJ:
- if (iaxs[fr.callno]->reg) {
- if (authdebug) {
- ast_log(LOG_NOTICE, "Registration of '%s' rejected: '%s' from: '%s'\n", iaxs[fr.callno]->reg->username, ies.cause ? ies.cause : "<unknown>", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr));
- manager_event(EVENT_FLAG_SYSTEM, "Registry", "Channel: IAX2\r\nUsername: %s\r\nStatus: Rejected\r\nCause: %s\r\n", iaxs[fr.callno]->reg->username, ies.cause ? ies.cause : "<unknown>");
- }
- iaxs[fr.callno]->reg->regstate = REG_STATE_REJECTED;
- }
- /* Send ack immediately, before we destroy */
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- iax2_destroy_nolock(fr.callno);
- break;
- case IAX_COMMAND_REGAUTH:
- /* Authentication request */
- if (registry_rerequest(&ies, fr.callno, &sin)) {
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No authority found");
- iax_ie_append_byte(&ied0, IAX_IE_CAUSECODE, AST_CAUSE_FACILITY_NOT_SUBSCRIBED);
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- }
- break;
- case IAX_COMMAND_TXREJ:
- iaxs[fr.callno]->transferring = 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel '%s' unable to transfer\n", iaxs[fr.callno]->owner ? iaxs[fr.callno]->owner->name : "<Unknown>");
- memset(&iaxs[fr.callno]->transfer, 0, sizeof(iaxs[fr.callno]->transfer));
- if (iaxs[fr.callno]->bridgecallno) {
- if (iaxs[iaxs[fr.callno]->bridgecallno]->transferring) {
- iaxs[iaxs[fr.callno]->bridgecallno]->transferring = 0;
- send_command(iaxs[iaxs[fr.callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXREJ, 0, NULL, 0, -1);
- }
- }
- break;
- case IAX_COMMAND_TXREADY:
- if (iaxs[fr.callno]->transferring == TRANSFER_BEGIN) {
- iaxs[fr.callno]->transferring = TRANSFER_READY;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel '%s' ready to transfer\n", iaxs[fr.callno]->owner ? iaxs[fr.callno]->owner->name : "<Unknown>");
- if (iaxs[fr.callno]->bridgecallno) {
- if (iaxs[iaxs[fr.callno]->bridgecallno]->transferring == TRANSFER_READY) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Releasing %s and %s\n", iaxs[fr.callno]->owner ? iaxs[fr.callno]->owner->name : "<Unknown>",
- iaxs[iaxs[fr.callno]->bridgecallno]->owner ? iaxs[iaxs[fr.callno]->bridgecallno]->owner->name : "<Unknown>");
-
- /* They're both ready, now release them. */
- iaxs[iaxs[fr.callno]->bridgecallno]->transferring = TRANSFER_RELEASED;
- iaxs[fr.callno]->transferring = TRANSFER_RELEASED;
- ast_set_flag(iaxs[iaxs[fr.callno]->bridgecallno], IAX_ALREADYGONE);
- ast_set_flag(iaxs[fr.callno], IAX_ALREADYGONE);
-
- /* Stop doing lag & ping requests */
- stop_stuff(fr.callno);
- stop_stuff(iaxs[fr.callno]->bridgecallno);
-
- memset(&ied0, 0, sizeof(ied0));
- memset(&ied1, 0, sizeof(ied1));
- iax_ie_append_short(&ied0, IAX_IE_CALLNO, iaxs[iaxs[fr.callno]->bridgecallno]->peercallno);
- iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[fr.callno]->peercallno);
- send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_TXREL, 0, ied0.buf, ied0.pos, -1);
- send_command(iaxs[iaxs[fr.callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXREL, 0, ied1.buf, ied1.pos, -1);
-
- }
- }
- }
- break;
- case IAX_COMMAND_TXREQ:
- try_transfer(iaxs[fr.callno], &ies);
- break;
- case IAX_COMMAND_TXCNT:
- if (iaxs[fr.callno]->transferring)
- send_command_transfer(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_TXACC, 0, NULL, 0);
- break;
- case IAX_COMMAND_TXREL:
- /* Send ack immediately, rather than waiting until we've changed addresses */
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- complete_transfer(fr.callno, &ies);
- stop_stuff(fr.callno); /* for attended transfer to work with libiax */
- break;
- case IAX_COMMAND_DPREP:
- complete_dpreply(iaxs[fr.callno], &ies);
- break;
- case IAX_COMMAND_UNSUPPORT:
- ast_log(LOG_NOTICE, "Peer did not understand our iax command '%d'\n", ies.iax_unknown);
- break;
- case IAX_COMMAND_FWDOWNL:
- /* Firmware download */
- memset(&ied0, 0, sizeof(ied0));
- res = iax_firmware_append(&ied0, (unsigned char *)ies.devicetype, ies.fwdesc);
- if (res < 0)
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
- else if (res > 0)
- send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_FWDATA, 0, ied0.buf, ied0.pos, -1);
- else
- send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_FWDATA, 0, ied0.buf, ied0.pos, -1);
- break;
- default:
- ast_log(LOG_DEBUG, "Unknown IAX command %d on %d/%d\n", f.subclass, fr.callno, iaxs[fr.callno]->peercallno);
- memset(&ied0, 0, sizeof(ied0));
- iax_ie_append_byte(&ied0, IAX_IE_IAX_UNKNOWN, f.subclass);
- send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_UNSUPPORT, 0, ied0.buf, ied0.pos, -1);
- }
- /* Don't actually pass these frames along */
- if ((f.subclass != IAX_COMMAND_ACK) &&
- (f.subclass != IAX_COMMAND_TXCNT) &&
- (f.subclass != IAX_COMMAND_TXACC) &&
- (f.subclass != IAX_COMMAND_INVAL) &&
- (f.subclass != IAX_COMMAND_VNAK)) {
- if (iaxs[fr.callno] && iaxs[fr.callno]->aseqno != iaxs[fr.callno]->iseqno)
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- }
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- /* Unless this is an ACK or INVAL frame, ack it */
- if (iaxs[fr.callno]->aseqno != iaxs[fr.callno]->iseqno)
- send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
- } else if (minivid) {
- f.frametype = AST_FRAME_VIDEO;
- if (iaxs[fr.callno]->videoformat > 0)
- f.subclass = iaxs[fr.callno]->videoformat | (ntohs(vh->ts) & 0x8000 ? 1 : 0);
- else {
- ast_log(LOG_WARNING, "Received mini frame before first full video frame\n ");
- iax2_vnak(fr.callno);
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- f.datalen = res - sizeof(struct ast_iax2_video_hdr);
- if (f.datalen)
- f.data = buf + sizeof(struct ast_iax2_video_hdr);
- else
- f.data = NULL;
-#ifdef IAXTESTS
- if (test_resync) {
- fr.ts = (iaxs[fr.callno]->last & 0xFFFF8000L) | ((ntohs(mh->ts) + test_resync) & 0x7fff);
- } else
-#endif /* IAXTESTS */
- fr.ts = (iaxs[fr.callno]->last & 0xFFFF8000L) | (ntohs(mh->ts) & 0x7fff);
- } else {
- /* A mini frame */
- f.frametype = AST_FRAME_VOICE;
- if (iaxs[fr.callno]->voiceformat > 0)
- f.subclass = iaxs[fr.callno]->voiceformat;
- else {
- ast_log(LOG_WARNING, "Received mini frame before first full voice frame\n ");
- iax2_vnak(fr.callno);
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- f.datalen = res - sizeof(struct ast_iax2_mini_hdr);
- if (f.datalen < 0) {
- ast_log(LOG_WARNING, "Datalen < 0?\n");
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- if (f.datalen)
- f.data = buf + sizeof(struct ast_iax2_mini_hdr);
- else
- f.data = NULL;
-#ifdef IAXTESTS
- if (test_resync) {
- fr.ts = (iaxs[fr.callno]->last & 0xFFFF0000L) | ((ntohs(mh->ts) + test_resync) & 0xffff);
- } else
-#endif /* IAXTESTS */
- fr.ts = (iaxs[fr.callno]->last & 0xFFFF0000L) | ntohs(mh->ts);
- /* FIXME? Surely right here would be the right place to undo timestamp wraparound? */
- }
- /* Don't pass any packets until we're started */
- if (!ast_test_flag(&iaxs[fr.callno]->state, IAX_STATE_STARTED)) {
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
- }
- /* Common things */
- f.src = "IAX2";
- f.mallocd = 0;
- f.offset = 0;
- if (f.datalen && (f.frametype == AST_FRAME_VOICE)) {
- f.samples = ast_codec_get_samples(&f);
- /* We need to byteswap incoming slinear samples from network byte order */
- if (f.subclass == AST_FORMAT_SLINEAR)
- ast_frame_byteswap_be(&f);
- } else
- f.samples = 0;
- iax_frame_wrap(&fr, &f);
-
- /* If this is our most recent packet, use it as our basis for timestamping */
- if (iaxs[fr.callno]->last < fr.ts) {
- /*iaxs[fr.callno]->last = fr.ts; (do it afterwards cos schedule/forward_delivery needs the last ts too)*/
- fr.outoforder = 0;
- } else {
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Received out of order packet... (type=%d, subclass %d, ts = %d, last = %d)\n", f.frametype, f.subclass, fr.ts, iaxs[fr.callno]->last);
- fr.outoforder = -1;
- }
-#ifdef BRIDGE_OPTIMIZATION
- if (iaxs[fr.callno]->bridgecallno) {
- forward_delivery(&fr);
- } else {
- duped_fr = iaxfrdup2(&fr);
- if (duped_fr) {
- schedule_delivery(duped_fr, updatehistory, 0, &fr.ts);
- }
- }
-#else
- duped_fr = iaxfrdup2(&fr);
- if (duped_fr) {
- schedule_delivery(duped_fr, updatehistory, 0, &fr.ts);
- }
-#endif
-
- if (iaxs[fr.callno]->last < fr.ts) {
- iaxs[fr.callno]->last = fr.ts;
-#if 1
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "For call=%d, set last=%d\n", fr.callno, fr.ts);
-#endif
- }
-
- /* Always run again */
- ast_mutex_unlock(&iaxsl[fr.callno]);
- return 1;
-}
-
-static int iax2_do_register(struct iax2_registry *reg)
-{
- struct iax_ie_data ied;
- if (option_debug && iaxdebug)
- ast_log(LOG_DEBUG, "Sending registration request for '%s'\n", reg->username);
- if (!reg->callno) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Allocate call number\n");
- reg->callno = find_callno(0, 0, &reg->addr, NEW_FORCE, 1, defaultsockfd);
- if (reg->callno < 1) {
- ast_log(LOG_WARNING, "Unable to create call for registration\n");
- return -1;
- } else if (option_debug)
- ast_log(LOG_DEBUG, "Registration created on call %d\n", reg->callno);
- iaxs[reg->callno]->reg = reg;
- }
- /* Schedule the next registration attempt */
- if (reg->expire > -1)
- ast_sched_del(sched, reg->expire);
- /* Setup the next registration a little early */
- reg->expire = ast_sched_add(sched, (5 * reg->refresh / 6) * 1000, iax2_do_register_s, reg);
- /* Send the request */
- memset(&ied, 0, sizeof(ied));
- iax_ie_append_str(&ied, IAX_IE_USERNAME, reg->username);
- iax_ie_append_short(&ied, IAX_IE_REFRESH, reg->refresh);
- send_command(iaxs[reg->callno],AST_FRAME_IAX, IAX_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1);
- reg->regstate = REG_STATE_REGSENT;
- return 0;
-}
-
-static char *iax2_prov_complete_template_3rd(char *line, char *word, int pos, int state)
-{
- if (pos != 3)
- return NULL;
- return iax_prov_complete_template(line, word, pos, state);
-}
-
-static int iax2_provision(struct sockaddr_in *end, int sockfd, char *dest, const char *template, int force)
-{
- /* Returns 1 if provisioned, -1 if not able to find destination, or 0 if no provisioning
- is found for template */
- struct iax_ie_data provdata;
- struct iax_ie_data ied;
- unsigned int sig;
- struct sockaddr_in sin;
- int callno;
- struct create_addr_info cai;
-
- memset(&cai, 0, sizeof(cai));
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Provisioning '%s' from template '%s'\n", dest, template);
-
- if (iax_provision_build(&provdata, &sig, template, force)) {
- ast_log(LOG_DEBUG, "No provisioning found for template '%s'\n", template);
- return 0;
- }
-
- if (end) {
- memcpy(&sin, end, sizeof(sin));
- cai.sockfd = sockfd;
- } else if (create_addr(dest, &sin, &cai))
- return -1;
-
- /* Build the rest of the message */
- memset(&ied, 0, sizeof(ied));
- iax_ie_append_raw(&ied, IAX_IE_PROVISIONING, provdata.buf, provdata.pos);
-
- callno = find_callno(0, 0, &sin, NEW_FORCE, 1, cai.sockfd);
- if (!callno)
- return -1;
-
- ast_mutex_lock(&iaxsl[callno]);
- if (iaxs[callno]) {
- /* Schedule autodestruct in case they don't ever give us anything back */
- if (iaxs[callno]->autoid > -1)
- ast_sched_del(sched, iaxs[callno]->autoid);
- iaxs[callno]->autoid = ast_sched_add(sched, 15000, auto_hangup, (void *)(long)callno);
- ast_set_flag(iaxs[callno], IAX_PROVISION);
- /* Got a call number now, so go ahead and send the provisioning information */
- send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_PROVISION, 0, ied.buf, ied.pos, -1);
- }
- ast_mutex_unlock(&iaxsl[callno]);
-
- return 1;
-}
-
-static char *papp = "IAX2Provision";
-static char *psyn = "Provision a calling IAXy with a given template";
-static char *pdescrip =
-" IAX2Provision([template]): Provisions the calling IAXy (assuming\n"
-"the calling entity is in fact an IAXy) with the given template or\n"
-"default if one is not specified. Returns -1 on error or 0 on success.\n";
-
-/*! iax2provision
-\ingroup applications
-*/
-static int iax2_prov_app(struct ast_channel *chan, void *data)
-{
- int res;
- char *sdata;
- char *opts;
- int force =0;
- unsigned short callno = PTR_TO_CALLNO(chan->tech_pvt);
- char iabuf[INET_ADDRSTRLEN];
- if (ast_strlen_zero(data))
- data = "default";
- sdata = ast_strdupa(data);
- opts = strchr(sdata, '|');
- if (opts)
- *opts='\0';
-
- if (chan->type != channeltype) {
- ast_log(LOG_NOTICE, "Can't provision a non-IAX device!\n");
- return -1;
- }
- if (!callno || !iaxs[callno] || !iaxs[callno]->addr.sin_addr.s_addr) {
- ast_log(LOG_NOTICE, "Can't provision something with no IP?\n");
- return -1;
- }
- res = iax2_provision(&iaxs[callno]->addr, iaxs[callno]->sockfd, NULL, sdata, force);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Provisioned IAXY at '%s' with '%s'= %d\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[callno]->addr.sin_addr),
- sdata, res);
- return res;
-}
-
-
-static int iax2_prov_cmd(int fd, int argc, char *argv[])
-{
- int force = 0;
- int res;
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- if ((argc > 4)) {
- if (!strcasecmp(argv[4], "forced"))
- force = 1;
- else
- return RESULT_SHOWUSAGE;
- }
- res = iax2_provision(NULL, -1, argv[2], argv[3], force);
- if (res < 0)
- ast_cli(fd, "Unable to find peer/address '%s'\n", argv[2]);
- else if (res < 1)
- ast_cli(fd, "No template (including wildcard) matching '%s'\n", argv[3]);
- else
- ast_cli(fd, "Provisioning '%s' with template '%s'%s\n", argv[2], argv[3], force ? ", forced" : "");
- return RESULT_SUCCESS;
-}
-
-static int iax2_poke_noanswer(void *data)
-{
- struct iax2_peer *peer = data;
- peer->pokeexpire = -1;
- if (peer->lastms > -1) {
- ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE! Time: %d\n", peer->name, peer->lastms);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: IAX2/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, peer->lastms);
- ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
- }
- if (peer->callno > 0)
- iax2_destroy(peer->callno);
- peer->callno = 0;
- peer->lastms = -1;
- /* Try again quickly */
- peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_peer_s, peer);
- return 0;
-}
-
-static int iax2_poke_peer(struct iax2_peer *peer, int heldcall)
-{
- if (!peer->maxms || !peer->addr.sin_addr.s_addr) {
- /* IF we have no IP, or this isn't to be monitored, return
- imeediately after clearing things out */
- peer->lastms = 0;
- peer->historicms = 0;
- peer->pokeexpire = -1;
- peer->callno = 0;
- return 0;
- }
- if (peer->callno > 0) {
- ast_log(LOG_NOTICE, "Still have a callno...\n");
- iax2_destroy(peer->callno);
- }
- if (heldcall)
- ast_mutex_unlock(&iaxsl[heldcall]);
- peer->callno = find_callno(0, 0, &peer->addr, NEW_FORCE, 0, peer->sockfd);
- if (heldcall)
- ast_mutex_lock(&iaxsl[heldcall]);
- if (peer->callno < 1) {
- ast_log(LOG_WARNING, "Unable to allocate call for poking peer '%s'\n", peer->name);
- return -1;
- }
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
- /* Speed up retransmission times */
- iaxs[peer->callno]->pingtime = peer->maxms / 4 + 1;
- iaxs[peer->callno]->peerpoke = peer;
- send_command(iaxs[peer->callno], AST_FRAME_IAX, IAX_COMMAND_POKE, 0, NULL, 0, -1);
-
- /* If the host is already unreachable then use the unreachable interval instead */
- if (peer->lastms < 0) {
- peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_noanswer, peer);
- } else
- peer->pokeexpire = ast_sched_add(sched, DEFAULT_MAXMS * 2, iax2_poke_noanswer, peer);
-
- return 0;
-}
-
-static void free_context(struct iax2_context *con)
-{
- struct iax2_context *conl;
- while(con) {
- conl = con;
- con = con->next;
- free(conl);
- }
-}
-
-static struct ast_channel *iax2_request(const char *type, int format, void *data, int *cause)
-{
- int callno;
- int res;
- int fmt, native;
- struct sockaddr_in sin;
- struct ast_channel *c;
- struct parsed_dial_string pds;
- struct create_addr_info cai;
- char *tmpstr;
-
- memset(&pds, 0, sizeof(pds));
- tmpstr = ast_strdupa(data);
- parse_dial_string(tmpstr, &pds);
-
- memset(&cai, 0, sizeof(cai));
- cai.capability = iax2_capability;
-
- ast_copy_flags(&cai, &globalflags, IAX_NOTRANSFER | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
-
- if (!pds.peer) {
- ast_log(LOG_WARNING, "No peer given\n");
- return NULL;
- }
-
-
- /* Populate our address from the given */
- if (create_addr(pds.peer, &sin, &cai)) {
- *cause = AST_CAUSE_UNREGISTERED;
- return NULL;
- }
-
- if (pds.port)
- sin.sin_port = htons(atoi(pds.port));
-
- callno = find_callno(0, 0, &sin, NEW_FORCE, 1, cai.sockfd);
- if (callno < 1) {
- ast_log(LOG_WARNING, "Unable to create call\n");
- *cause = AST_CAUSE_CONGESTION;
- return NULL;
- }
-
- ast_mutex_lock(&iaxsl[callno]);
-
- /* If this is a trunk, update it now */
- ast_copy_flags(iaxs[callno], &cai, IAX_TRUNK | IAX_SENDANI | IAX_NOTRANSFER | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
- if (ast_test_flag(&cai, IAX_TRUNK))
- callno = make_trunk(callno, 1);
- iaxs[callno]->maxtime = cai.maxtime;
- if (cai.found)
- ast_copy_string(iaxs[callno]->host, pds.peer, sizeof(iaxs[callno]->host));
-
- c = ast_iax2_new(callno, AST_STATE_DOWN, cai.capability);
-
- ast_mutex_unlock(&iaxsl[callno]);
-
- if (c) {
- /* Choose a format we can live with */
- if (c->nativeformats & format)
- c->nativeformats &= format;
- else {
- native = c->nativeformats;
- fmt = format;
- res = ast_translator_best_choice(&fmt, &native);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to create translator path for %s to %s on %s\n",
- ast_getformatname(c->nativeformats), ast_getformatname(fmt), c->name);
- ast_hangup(c);
- return NULL;
- }
- c->nativeformats = native;
- }
- c->readformat = ast_best_codec(c->nativeformats);
- c->writeformat = c->readformat;
- }
-
- return c;
-}
-
-static void *network_thread(void *ignore)
-{
- /* Our job is simple: Send queued messages, retrying if necessary. Read frames
- from the network, and queue them for delivery to the channels */
- int res, count;
- struct iax_frame *f, *freeme;
- if (timingfd > -1)
- ast_io_add(io, timingfd, timing_read, AST_IO_IN | AST_IO_PRI, NULL);
- for(;;) {
- /* Go through the queue, sending messages which have not yet been
- sent, and scheduling retransmissions if appropriate */
- ast_mutex_lock(&iaxq.lock);
- f = iaxq.head;
- count = 0;
- while(f) {
- freeme = NULL;
- if (!f->sentyet) {
- f->sentyet++;
- /* Send a copy immediately -- errors here are ok, so don't bother locking */
- if (iaxs[f->callno]) {
- send_packet(f);
- count++;
- }
- if (f->retries < 0) {
- /* This is not supposed to be retransmitted */
- if (f->prev)
- f->prev->next = f->next;
- else
- iaxq.head = f->next;
- if (f->next)
- f->next->prev = f->prev;
- else
- iaxq.tail = f->prev;
- iaxq.count--;
- /* Free the iax frame */
- freeme = f;
- } else {
- /* We need reliable delivery. Schedule a retransmission */
- f->retries++;
- f->retrans = ast_sched_add(sched, f->retrytime, attempt_transmit, f);
- }
- }
- f = f->next;
- if (freeme)
- iax_frame_free(freeme);
- }
- ast_mutex_unlock(&iaxq.lock);
- if (count >= 20)
- ast_log(LOG_DEBUG, "chan_iax2: Sent %d queued outbound frames all at once\n", count);
-
- /* Now do the IO, and run scheduled tasks */
- res = ast_sched_wait(sched);
- if ((res > 1000) || (res < 0))
- res = 1000;
- res = ast_io_wait(io, res);
- if (res >= 0) {
- if (res >= 20)
- ast_log(LOG_DEBUG, "chan_iax2: ast_io_wait ran %d I/Os all at once\n", res);
- count = ast_sched_runq(sched);
- if (count >= 20)
- ast_log(LOG_DEBUG, "chan_iax2: ast_sched_runq ran %d scheduled tasks all at once\n", count);
- }
- }
- return NULL;
-}
-
-static int start_network_thread(void)
-{
- return ast_pthread_create(&netthreadid, NULL, network_thread, NULL);
-}
-
-static struct iax2_context *build_context(char *context)
-{
- struct iax2_context *con = malloc(sizeof(struct iax2_context));
- if (con) {
- ast_copy_string(con->context, context, sizeof(con->context));
- con->next = NULL;
- }
- return con;
-}
-
-static int get_auth_methods(char *value)
-{
- int methods = 0;
- if (strstr(value, "rsa"))
- methods |= IAX_AUTH_RSA;
- if (strstr(value, "md5"))
- methods |= IAX_AUTH_MD5;
- if (strstr(value, "plaintext"))
- methods |= IAX_AUTH_PLAINTEXT;
- return methods;
-}
-
-
-/*--- check_src_ip: Check if address can be used as packet source.
- returns:
- 0 address available
- 1 address unavailable
--1 error
-*/
-static int check_srcaddr(struct sockaddr *sa, socklen_t salen)
-{
- int sd;
- int res;
-
- sd = socket(AF_INET, SOCK_DGRAM, 0);
- if (sd < 0) {
- ast_log(LOG_ERROR, "Socket: %s\n", strerror(errno));
- return -1;
- }
-
- res = bind(sd, sa, salen);
- if (res < 0) {
- ast_log(LOG_DEBUG, "Can't bind: %s\n", strerror(errno));
- close(sd);
- return 1;
- }
-
- close(sd);
- return 0;
-}
-
-/*--- peer_set_srcaddr: Parse the "sourceaddress" value,
- lookup in netsock list and set peer's sockfd. Defaults to defaultsockfd if
- not found. */
-static int peer_set_srcaddr(struct iax2_peer *peer, const char *srcaddr)
-{
- struct sockaddr_in sin;
- int nonlocal = 1;
- int port = IAX_DEFAULT_PORTNO;
- int sockfd = defaultsockfd;
- char *tmp;
- char *addr;
- char *portstr;
-
- tmp = ast_strdupa(srcaddr);
- if (!tmp) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- return -1;
- }
-
- addr = strsep(&tmp, ":");
- portstr = tmp;
-
- if (portstr) {
- port = atoi(portstr);
- if (port < 1)
- port = IAX_DEFAULT_PORTNO;
- }
-
- if (!ast_get_ip(&sin, addr)) {
- struct ast_netsock *sock;
- int res;
-
- sin.sin_port = 0;
- res = check_srcaddr((struct sockaddr *) &sin, sizeof(sin));
- if (res == 0) {
- /* ip address valid. */
- sin.sin_port = htons(port);
- sock = ast_netsock_find(netsock, &sin);
- if (sock) {
- sockfd = ast_netsock_sockfd(sock);
- nonlocal = 0;
- }
- }
- }
-
- peer->sockfd = sockfd;
-
- if (nonlocal) {
- ast_log(LOG_WARNING, "Non-local or unbound address specified (%s) in sourceaddress for '%s', reverting to default\n",
- srcaddr, peer->name);
- return -1;
- } else {
- ast_log(LOG_DEBUG, "Using sourceaddress %s for '%s'\n", srcaddr, peer->name);
- return 0;
- }
-}
-
-
-/*--- build_peer: Create peer structure based on configuration */
-static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, int temponly)
-{
- struct iax2_peer *peer;
- struct iax2_peer *prev;
- struct ast_ha *oldha = NULL;
- int maskfound=0;
- int found=0;
- prev = NULL;
- ast_mutex_lock(&peerl.lock);
- if (!temponly) {
- peer = peerl.peers;
- while(peer) {
- if (!strcmp(peer->name, name)) {
- break;
- }
- prev = peer;
- peer = peer->next;
- }
- } else
- peer = NULL;
- if (peer) {
- found++;
- oldha = peer->ha;
- peer->ha = NULL;
- /* Already in the list, remove it and it will be added back (or FREE'd) */
- if (prev) {
- prev->next = peer->next;
- } else {
- peerl.peers = peer->next;
- }
- ast_mutex_unlock(&peerl.lock);
- } else {
- ast_mutex_unlock(&peerl.lock);
- peer = malloc(sizeof(struct iax2_peer));
- if (peer) {
- memset(peer, 0, sizeof(struct iax2_peer));
- peer->expire = -1;
- peer->pokeexpire = -1;
- peer->sockfd = defaultsockfd;
- }
- }
- if (peer) {
- ast_copy_flags(peer, &globalflags, IAX_MESSAGEDETAIL | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
- peer->encmethods = iax2_encryption;
- peer->secret[0] = '\0';
- if (!found) {
- ast_copy_string(peer->name, name, sizeof(peer->name));
- peer->addr.sin_port = htons(IAX_DEFAULT_PORTNO);
- peer->expiry = min_reg_expire;
- }
- peer->prefs = prefs;
- peer->capability = iax2_capability;
- peer->smoothing = 0;
- peer->pokefreqok = DEFAULT_FREQ_OK;
- peer->pokefreqnotok = DEFAULT_FREQ_NOTOK;
- peer->context[0] = '\0';
- peer->peercontext[0] = '\0';
- while(v) {
- if (!strcasecmp(v->name, "secret")) {
- if (!ast_strlen_zero(peer->secret)) {
- strncpy(peer->secret + strlen(peer->secret), ";", sizeof(peer->secret)-strlen(peer->secret) - 1);
- strncpy(peer->secret + strlen(peer->secret), v->value, sizeof(peer->secret)-strlen(peer->secret) - 1);
- } else
- ast_copy_string(peer->secret, v->value, sizeof(peer->secret));
- } else if (!strcasecmp(v->name, "mailbox")) {
- ast_copy_string(peer->mailbox, v->value, sizeof(peer->mailbox));
- } else if (!strcasecmp(v->name, "dbsecret")) {
- ast_copy_string(peer->dbsecret, v->value, sizeof(peer->dbsecret));
- } else if (!strcasecmp(v->name, "mailboxdetail")) {
- ast_set2_flag(peer, ast_true(v->value), IAX_MESSAGEDETAIL);
- } else if (!strcasecmp(v->name, "trunk")) {
- ast_set2_flag(peer, ast_true(v->value), IAX_TRUNK);
- if (ast_test_flag(peer, IAX_TRUNK) && (timingfd < 0)) {
- ast_log(LOG_WARNING, "Unable to support trunking on peer '%s' without zaptel timing\n", peer->name);
- ast_clear_flag(peer, IAX_TRUNK);
- }
- } else if (!strcasecmp(v->name, "auth")) {
- peer->authmethods = get_auth_methods(v->value);
- } else if (!strcasecmp(v->name, "encryption")) {
- peer->encmethods = get_encrypt_methods(v->value);
- } else if (!strcasecmp(v->name, "notransfer")) {
- ast_set2_flag(peer, ast_true(v->value), IAX_NOTRANSFER);
- } else if (!strcasecmp(v->name, "jitterbuffer")) {
- ast_set2_flag(peer, ast_true(v->value), IAX_USEJITTERBUF);
- } else if (!strcasecmp(v->name, "forcejitterbuffer")) {
- ast_set2_flag(peer, ast_true(v->value), IAX_FORCEJITTERBUF);
- } else if (!strcasecmp(v->name, "host")) {
- if (!strcasecmp(v->value, "dynamic")) {
- /* They'll register with us */
- ast_set_flag(peer, IAX_DYNAMIC);
- if (!found) {
- /* Initialize stuff iff we're not found, otherwise
- we keep going with what we had */
- memset(&peer->addr.sin_addr, 0, 4);
- if (peer->addr.sin_port) {
- /* If we've already got a port, make it the default rather than absolute */
- peer->defaddr.sin_port = peer->addr.sin_port;
- peer->addr.sin_port = 0;
- }
- }
- } else {
- /* Non-dynamic. Make sure we become that way if we're not */
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- peer->expire = -1;
- ast_clear_flag(peer, IAX_DYNAMIC);
- if (ast_dnsmgr_lookup(v->value, &peer->addr.sin_addr, &peer->dnsmgr)) {
- free(peer);
- return NULL;
- }
- if (!peer->addr.sin_port)
- peer->addr.sin_port = htons(IAX_DEFAULT_PORTNO);
- }
- if (!maskfound)
- inet_aton("255.255.255.255", &peer->mask);
- } else if (!strcasecmp(v->name, "defaultip")) {
- if (ast_get_ip(&peer->defaddr, v->value)) {
- free(peer);
- return NULL;
- }
- } else if (!strcasecmp(v->name, "sourceaddress")) {
- peer_set_srcaddr(peer, v->value);
- } else if (!strcasecmp(v->name, "permit") ||
- !strcasecmp(v->name, "deny")) {
- peer->ha = ast_append_ha(v->name, v->value, peer->ha);
- } else if (!strcasecmp(v->name, "mask")) {
- maskfound++;
- inet_aton(v->value, &peer->mask);
- } else if (!strcasecmp(v->name, "context")) {
- if (ast_strlen_zero(peer->context))
- ast_copy_string(peer->context, v->value, sizeof(peer->context));
- } else if (!strcasecmp(v->name, "regexten")) {
- ast_copy_string(peer->regexten, v->value, sizeof(peer->regexten));
- } else if (!strcasecmp(v->name, "peercontext")) {
- if (ast_strlen_zero(peer->peercontext))
- ast_copy_string(peer->peercontext, v->value, sizeof(peer->peercontext));
- } else if (!strcasecmp(v->name, "port")) {
- if (ast_test_flag(peer, IAX_DYNAMIC))
- peer->defaddr.sin_port = htons(atoi(v->value));
- else
- peer->addr.sin_port = htons(atoi(v->value));
- } else if (!strcasecmp(v->name, "username")) {
- ast_copy_string(peer->username, v->value, sizeof(peer->username));
- } else if (!strcasecmp(v->name, "allow")) {
- ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, 1);
- } else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, 0);
- } else if (!strcasecmp(v->name, "callerid")) {
- ast_callerid_split(v->value, peer->cid_name, sizeof(peer->cid_name),
- peer->cid_num, sizeof(peer->cid_num));
- ast_set_flag(peer, IAX_HASCALLERID);
- } else if (!strcasecmp(v->name, "sendani")) {
- ast_set2_flag(peer, ast_true(v->value), IAX_SENDANI);
- } else if (!strcasecmp(v->name, "inkeys")) {
- ast_copy_string(peer->inkeys, v->value, sizeof(peer->inkeys));
- } else if (!strcasecmp(v->name, "outkey")) {
- ast_copy_string(peer->outkey, v->value, sizeof(peer->outkey));
- } else if (!strcasecmp(v->name, "qualify")) {
- if (!strcasecmp(v->value, "no")) {
- peer->maxms = 0;
- } else if (!strcasecmp(v->value, "yes")) {
- peer->maxms = DEFAULT_MAXMS;
- } else if (sscanf(v->value, "%d", &peer->maxms) != 1) {
- ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of iax.conf\n", peer->name, v->lineno);
- peer->maxms = 0;
- }
- } else if (!strcasecmp(v->name, "qualifysmoothing")) {
- peer->smoothing = ast_true(v->value);
- } else if (!strcasecmp(v->name, "qualifyfreqok")) {
- if (sscanf(v->value, "%d", &peer->pokefreqok) != 1) {
- ast_log(LOG_WARNING, "Qualification testing frequency of peer '%s' when OK should a number of milliseconds at line %d of iax.conf\n", peer->name, v->lineno);
- }
- } else if (!strcasecmp(v->name, "qualifyfreqnotok")) {
- if (sscanf(v->value, "%d", &peer->pokefreqnotok) != 1) {
- ast_log(LOG_WARNING, "Qualification testing frequency of peer '%s' when NOT OK should be a number of milliseconds at line %d of iax.conf\n", peer->name, v->lineno);
- } else ast_log(LOG_WARNING, "Set peer->pokefreqnotok to %d\n", peer->pokefreqnotok);
- } else if (!strcasecmp(v->name, "timezone")) {
- ast_copy_string(peer->zonetag, v->value, sizeof(peer->zonetag));
- }/* else if (strcasecmp(v->name,"type")) */
- /* ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
- v=v->next;
- }
- if (!peer->authmethods)
- peer->authmethods = IAX_AUTH_MD5 | IAX_AUTH_PLAINTEXT;
- ast_clear_flag(peer, IAX_DELME);
- /* Make sure these are IPv4 addresses */
- peer->addr.sin_family = AF_INET;
- }
- if (oldha)
- ast_free_ha(oldha);
- return peer;
-}
-
-/*--- build_user: Create in-memory user structure from configuration */
-static struct iax2_user *build_user(const char *name, struct ast_variable *v, int temponly)
-{
- struct iax2_user *prev, *user;
- struct iax2_context *con, *conl = NULL;
- struct ast_ha *oldha = NULL;
- struct iax2_context *oldcon = NULL;
- int format;
- char *varname = NULL, *varval = NULL;
- struct ast_variable *tmpvar = NULL;
-
- prev = NULL;
- ast_mutex_lock(&userl.lock);
- if (!temponly) {
- user = userl.users;
- while(user) {
- if (!strcmp(user->name, name)) {
- break;
- }
- prev = user;
- user = user->next;
- }
- } else
- user = NULL;
-
- if (user) {
- oldha = user->ha;
- oldcon = user->contexts;
- user->ha = NULL;
- user->contexts = NULL;
- /* Already in the list, remove it and it will be added back (or FREE'd) */
- if (prev) {
- prev->next = user->next;
- } else {
- userl.users = user->next;
- }
- ast_mutex_unlock(&userl.lock);
- } else {
- ast_mutex_unlock(&userl.lock);
- user = malloc(sizeof(struct iax2_user));
- if (user)
- memset(user, 0, sizeof(struct iax2_user));
- }
-
- if (user) {
- memset(user, 0, sizeof(struct iax2_user));
- user->prefs = prefs;
- user->capability = iax2_capability;
- user->encmethods = iax2_encryption;
- ast_copy_string(user->name, name, sizeof(user->name));
- ast_copy_string(user->language, language, sizeof(user->language));
- ast_copy_flags(user, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_CODEC_USER_FIRST | IAX_CODEC_NOPREFS | IAX_CODEC_NOCAP);
- while(v) {
- if (!strcasecmp(v->name, "context")) {
- con = build_context(v->value);
- if (con) {
- if (conl)
- conl->next = con;
- else
- user->contexts = con;
- conl = con;
- }
- } else if (!strcasecmp(v->name, "permit") ||
- !strcasecmp(v->name, "deny")) {
- user->ha = ast_append_ha(v->name, v->value, user->ha);
- } else if (!strcasecmp(v->name, "setvar")) {
- varname = ast_strdupa(v->value);
- if (varname && (varval = strchr(varname,'='))) {
- *varval = '\0';
- varval++;
- if((tmpvar = ast_variable_new(varname, varval))) {
- tmpvar->next = user->vars;
- user->vars = tmpvar;
- }
- }
- } else if (!strcasecmp(v->name, "allow")) {
- ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, 1);
- } else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&user->prefs, &user->capability,v->value, 0);
- } else if (!strcasecmp(v->name, "trunk")) {
- ast_set2_flag(user, ast_true(v->value), IAX_TRUNK);
- if (ast_test_flag(user, IAX_TRUNK) && (timingfd < 0)) {
- ast_log(LOG_WARNING, "Unable to support trunking on user '%s' without zaptel timing\n", user->name);
- ast_clear_flag(user, IAX_TRUNK);
- }
- } else if (!strcasecmp(v->name, "auth")) {
- user->authmethods = get_auth_methods(v->value);
- } else if (!strcasecmp(v->name, "encryption")) {
- user->encmethods = get_encrypt_methods(v->value);
- } else if (!strcasecmp(v->name, "notransfer")) {
- ast_set2_flag(user, ast_true(v->value), IAX_NOTRANSFER);
- } else if (!strcasecmp(v->name, "codecpriority")) {
- if(!strcasecmp(v->value, "caller"))
- ast_set_flag(user, IAX_CODEC_USER_FIRST);
- else if(!strcasecmp(v->value, "disabled"))
- ast_set_flag(user, IAX_CODEC_NOPREFS);
- else if(!strcasecmp(v->value, "reqonly")) {
- ast_set_flag(user, IAX_CODEC_NOCAP);
- ast_set_flag(user, IAX_CODEC_NOPREFS);
- }
- } else if (!strcasecmp(v->name, "jitterbuffer")) {
- ast_set2_flag(user, ast_true(v->value), IAX_USEJITTERBUF);
- } else if (!strcasecmp(v->name, "forcejitterbuffer")) {
- ast_set2_flag(user, ast_true(v->value), IAX_FORCEJITTERBUF);
- } else if (!strcasecmp(v->name, "dbsecret")) {
- ast_copy_string(user->dbsecret, v->value, sizeof(user->dbsecret));
- } else if (!strcasecmp(v->name, "secret")) {
- if (!ast_strlen_zero(user->secret)) {
- strncpy(user->secret + strlen(user->secret), ";", sizeof(user->secret) - strlen(user->secret) - 1);
- strncpy(user->secret + strlen(user->secret), v->value, sizeof(user->secret) - strlen(user->secret) - 1);
- } else
- ast_copy_string(user->secret, v->value, sizeof(user->secret));
- } else if (!strcasecmp(v->name, "callerid")) {
- ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num));
- ast_set_flag(user, IAX_HASCALLERID);
- } else if (!strcasecmp(v->name, "accountcode")) {
- ast_copy_string(user->accountcode, v->value, sizeof(user->accountcode));
- } else if (!strcasecmp(v->name, "language")) {
- ast_copy_string(user->language, v->value, sizeof(user->language));
- } else if (!strcasecmp(v->name, "amaflags")) {
- format = ast_cdr_amaflags2int(v->value);
- if (format < 0) {
- ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno);
- } else {
- user->amaflags = format;
- }
- } else if (!strcasecmp(v->name, "inkeys")) {
- ast_copy_string(user->inkeys, v->value, sizeof(user->inkeys));
- }/* else if (strcasecmp(v->name,"type")) */
- /* ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
- v = v->next;
- }
- if (!user->authmethods) {
- if (!ast_strlen_zero(user->secret)) {
- user->authmethods = IAX_AUTH_MD5 | IAX_AUTH_PLAINTEXT;
- if (!ast_strlen_zero(user->inkeys))
- user->authmethods |= IAX_AUTH_RSA;
- } else if (!ast_strlen_zero(user->inkeys)) {
- user->authmethods = IAX_AUTH_RSA;
- } else {
- user->authmethods = IAX_AUTH_MD5 | IAX_AUTH_PLAINTEXT;
- }
- }
- ast_clear_flag(user, IAX_DELME);
- }
- if (oldha)
- ast_free_ha(oldha);
- if (oldcon)
- free_context(oldcon);
- return user;
-}
-
-static void delete_users(void)
-{
- struct iax2_user *user;
- struct iax2_peer *peer;
- struct iax2_registry *reg, *regl;
-
- ast_mutex_lock(&userl.lock);
- for (user=userl.users;user;) {
- ast_set_flag(user, IAX_DELME);
- user = user->next;
- }
- ast_mutex_unlock(&userl.lock);
- for (reg = registrations;reg;) {
- regl = reg;
- reg = reg->next;
- if (regl->expire > -1) {
- ast_sched_del(sched, regl->expire);
- }
- if (regl->callno) {
- /* XXX Is this a potential lock? I don't think so, but you never know */
- ast_mutex_lock(&iaxsl[regl->callno]);
- if (iaxs[regl->callno]) {
- iaxs[regl->callno]->reg = NULL;
- iax2_destroy_nolock(regl->callno);
- }
- ast_mutex_unlock(&iaxsl[regl->callno]);
- }
- free(regl);
- }
- registrations = NULL;
- ast_mutex_lock(&peerl.lock);
- for (peer=peerl.peers;peer;) {
- /* Assume all will be deleted, and we'll find out for sure later */
- ast_set_flag(peer, IAX_DELME);
- peer = peer->next;
- }
- ast_mutex_unlock(&peerl.lock);
-}
-
-static void destroy_user(struct iax2_user *user)
-{
- ast_free_ha(user->ha);
- free_context(user->contexts);
- if(user->vars) {
- ast_variables_destroy(user->vars);
- user->vars = NULL;
- }
- free(user);
-}
-
-static void prune_users(void)
-{
- struct iax2_user *user, *usernext, *userlast = NULL;
- ast_mutex_lock(&userl.lock);
- for (user=userl.users;user;) {
- usernext = user->next;
- if (ast_test_flag(user, IAX_DELME)) {
- destroy_user(user);
- if (userlast)
- userlast->next = usernext;
- else
- userl.users = usernext;
- } else
- userlast = user;
- user = usernext;
- }
- ast_mutex_unlock(&userl.lock);
-}
-
-static void destroy_peer(struct iax2_peer *peer)
-{
- int x;
- ast_free_ha(peer->ha);
- for (x=0;x<IAX_MAX_CALLS;x++) {
- ast_mutex_lock(&iaxsl[x]);
- if (iaxs[x] && (iaxs[x]->peerpoke == peer)) {
- iax2_destroy(x);
- }
- ast_mutex_unlock(&iaxsl[x]);
- }
- /* Delete it, it needs to disappear */
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
- if (peer->callno > 0)
- iax2_destroy(peer->callno);
- register_peer_exten(peer, 0);
- if (peer->dnsmgr)
- ast_dnsmgr_release(peer->dnsmgr);
- free(peer);
-}
-
-static void prune_peers(void){
- /* Prune peers who still are supposed to be deleted */
- struct iax2_peer *peer, *peerlast, *peernext;
- ast_mutex_lock(&peerl.lock);
- peerlast = NULL;
- for (peer=peerl.peers;peer;) {
- peernext = peer->next;
- if (ast_test_flag(peer, IAX_DELME)) {
- destroy_peer(peer);
- if (peerlast)
- peerlast->next = peernext;
- else
- peerl.peers = peernext;
- } else
- peerlast = peer;
- peer=peernext;
- }
- ast_mutex_unlock(&peerl.lock);
-}
-
-static void set_timing(void)
-{
-#ifdef IAX_TRUNKING
- int bs = trunkfreq * 8;
- if (timingfd > -1) {
- if (
-#ifdef ZT_TIMERACK
- ioctl(timingfd, ZT_TIMERCONFIG, &bs) &&
-#endif
- ioctl(timingfd, ZT_SET_BLOCKSIZE, &bs))
- ast_log(LOG_WARNING, "Unable to set blocksize on timing source\n");
- }
-#endif
-}
-
-
-/*--- set_config: Load configuration */
-static int set_config(char *config_file, int reload)
-{
- struct ast_config *cfg;
- int capability=iax2_capability;
- struct ast_variable *v;
- char *cat;
- char *utype;
- char *tosval;
- int format;
- int portno = IAX_DEFAULT_PORTNO;
- int x;
- struct iax2_user *user;
- struct iax2_peer *peer;
- struct ast_netsock *ns;
-#if 0
- static unsigned short int last_port=0;
-#endif
-
- cfg = ast_config_load(config_file);
-
- if (!cfg) {
- ast_log(LOG_ERROR, "Unable to load config %s\n", config_file);
- return -1;
- }
-
- /* Reset global codec prefs */
- memset(&prefs, 0 , sizeof(struct ast_codec_pref));
-
- /* Reset Global Flags */
- memset(&globalflags, 0, sizeof(globalflags));
- ast_set_flag(&globalflags, IAX_RTUPDATE);
-
-#ifdef SO_NO_CHECK
- nochecksums = 0;
-#endif
-
- min_reg_expire = IAX_DEFAULT_REG_EXPIRE;
- max_reg_expire = IAX_DEFAULT_REG_EXPIRE;
-
- v = ast_variable_browse(cfg, "general");
-
- /* Seed initial tos value */
- tosval = ast_variable_retrieve(cfg, "general", "tos");
- if (tosval) {
- if (ast_str2tos(tosval, &tos))
- ast_log(LOG_WARNING, "Invalid tos value, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n");
- }
- while(v) {
- if (!strcasecmp(v->name, "bindport")){
- if (reload)
- ast_log(LOG_NOTICE, "Ignoring bindport on reload\n");
- else
- portno = atoi(v->value);
- } else if (!strcasecmp(v->name, "pingtime"))
- ping_time = atoi(v->value);
- else if (!strcasecmp(v->name, "nochecksums")) {
-#ifdef SO_NO_CHECK
- if (ast_true(v->value))
- nochecksums = 1;
- else
- nochecksums = 0;
-#else
- if (ast_true(v->value))
- ast_log(LOG_WARNING, "Disabling RTP checksums is not supported on this operating system!\n");
-#endif
- }
- else if (!strcasecmp(v->name, "maxjitterbuffer"))
- maxjitterbuffer = atoi(v->value);
-#ifdef NEWJB
- else if (!strcasecmp(v->name, "resyncthreshold"))
- resyncthreshold = atoi(v->value);
- else if (!strcasecmp(v->name, "maxjitterinterps"))
- maxjitterinterps = atoi(v->value);
-#endif
- else if (!strcasecmp(v->name, "jittershrinkrate"))
- jittershrinkrate = atoi(v->value);
- else if (!strcasecmp(v->name, "maxexcessbuffer"))
- max_jitter_buffer = atoi(v->value);
- else if (!strcasecmp(v->name, "minexcessbuffer"))
- min_jitter_buffer = atoi(v->value);
- else if (!strcasecmp(v->name, "lagrqtime"))
- lagrq_time = atoi(v->value);
- else if (!strcasecmp(v->name, "dropcount"))
- iax2_dropcount = atoi(v->value);
- else if (!strcasecmp(v->name, "maxregexpire"))
- max_reg_expire = atoi(v->value);
- else if (!strcasecmp(v->name, "minregexpire"))
- min_reg_expire = atoi(v->value);
- else if (!strcasecmp(v->name, "bindaddr")) {
- if (reload) {
- ast_log(LOG_NOTICE, "Ignoring bindaddr on reload\n");
- } else {
- if (!(ns = ast_netsock_bind(netsock, io, v->value, portno, tos, socket_read, NULL))) {
- ast_log(LOG_WARNING, "Unable apply binding to '%s' at line %d\n", v->value, v->lineno);
- } else {
- if (option_verbose > 1) {
- if (strchr(v->value, ':'))
- ast_verbose(VERBOSE_PREFIX_2 "Binding IAX2 to '%s'\n", v->value);
- else
- ast_verbose(VERBOSE_PREFIX_2 "Binding IAX2 to '%s:%d'\n", v->value, portno);
- }
- if (defaultsockfd < 0)
- defaultsockfd = ast_netsock_sockfd(ns);
- ast_netsock_unref(ns);
- }
- }
- } else if (!strcasecmp(v->name, "authdebug"))
- authdebug = ast_true(v->value);
- else if (!strcasecmp(v->name, "encryption"))
- iax2_encryption = get_encrypt_methods(v->value);
- else if (!strcasecmp(v->name, "notransfer"))
- ast_set2_flag((&globalflags), ast_true(v->value), IAX_NOTRANSFER);
- else if (!strcasecmp(v->name, "codecpriority")) {
- if(!strcasecmp(v->value, "caller"))
- ast_set_flag((&globalflags), IAX_CODEC_USER_FIRST);
- else if(!strcasecmp(v->value, "disabled"))
- ast_set_flag((&globalflags), IAX_CODEC_NOPREFS);
- else if(!strcasecmp(v->value, "reqonly")) {
- ast_set_flag((&globalflags), IAX_CODEC_NOCAP);
- ast_set_flag((&globalflags), IAX_CODEC_NOPREFS);
- }
- } else if (!strcasecmp(v->name, "jitterbuffer"))
- ast_set2_flag((&globalflags), ast_true(v->value), IAX_USEJITTERBUF);
- else if (!strcasecmp(v->name, "forcejitterbuffer"))
- ast_set2_flag((&globalflags), ast_true(v->value), IAX_FORCEJITTERBUF);
- else if (!strcasecmp(v->name, "delayreject"))
- delayreject = ast_true(v->value);
- else if (!strcasecmp(v->name, "mailboxdetail"))
- ast_set2_flag((&globalflags), ast_true(v->value), IAX_MESSAGEDETAIL);
- else if (!strcasecmp(v->name, "rtcachefriends"))
- ast_set2_flag((&globalflags), ast_true(v->value), IAX_RTCACHEFRIENDS);
- else if (!strcasecmp(v->name, "rtignoreregexpire"))
- ast_set2_flag((&globalflags), ast_true(v->value), IAX_RTIGNOREREGEXPIRE);
- else if (!strcasecmp(v->name, "rtupdate"))
- ast_set2_flag((&globalflags), ast_true(v->value), IAX_RTUPDATE);
- else if (!strcasecmp(v->name, "trunktimestamps"))
- ast_set2_flag(&globalflags, ast_true(v->value), IAX_TRUNKTIMESTAMPS);
- else if (!strcasecmp(v->name, "rtautoclear")) {
- int i = atoi(v->value);
- if(i > 0)
- global_rtautoclear = i;
- else
- i = 0;
- ast_set2_flag((&globalflags), i || ast_true(v->value), IAX_RTAUTOCLEAR);
- } else if (!strcasecmp(v->name, "trunkfreq")) {
- trunkfreq = atoi(v->value);
- if (trunkfreq < 10)
- trunkfreq = 10;
- } else if (!strcasecmp(v->name, "autokill")) {
- if (sscanf(v->value, "%d", &x) == 1) {
- if (x >= 0)
- autokill = x;
- else
- ast_log(LOG_NOTICE, "Nice try, but autokill has to be >0 or 'yes' or 'no' at line %d\n", v->lineno);
- } else if (ast_true(v->value)) {
- autokill = DEFAULT_MAXMS;
- } else {
- autokill = 0;
- }
- } else if (!strcasecmp(v->name, "bandwidth")) {
- if (!strcasecmp(v->value, "low")) {
- capability = IAX_CAPABILITY_LOWBANDWIDTH;
- } else if (!strcasecmp(v->value, "medium")) {
- capability = IAX_CAPABILITY_MEDBANDWIDTH;
- } else if (!strcasecmp(v->value, "high")) {
- capability = IAX_CAPABILITY_FULLBANDWIDTH;
- } else
- ast_log(LOG_WARNING, "bandwidth must be either low, medium, or high\n");
- } else if (!strcasecmp(v->name, "allow")) {
- ast_parse_allow_disallow(&prefs, &capability, v->value, 1);
- } else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&prefs, &capability, v->value, 0);
- } else if (!strcasecmp(v->name, "register")) {
- iax2_register(v->value, v->lineno);
- } else if (!strcasecmp(v->name, "iaxcompat")) {
- iaxcompat = ast_true(v->value);
- } else if (!strcasecmp(v->name, "regcontext")) {
- ast_copy_string(regcontext, v->value, sizeof(regcontext));
- /* Create context if it doesn't exist already */
- if (!ast_context_find(regcontext))
- ast_context_create(NULL, regcontext, channeltype);
- } else if (!strcasecmp(v->name, "tos")) {
- if (ast_str2tos(v->value, &tos))
- ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
- } else if (!strcasecmp(v->name, "accountcode")) {
- ast_copy_string(accountcode, v->value, sizeof(accountcode));
- } else if (!strcasecmp(v->name, "amaflags")) {
- format = ast_cdr_amaflags2int(v->value);
- if (format < 0) {
- ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno);
- } else {
- amaflags = format;
- }
- } else if (!strcasecmp(v->name, "language")) {
- ast_copy_string(language, v->value, sizeof(language));
- } /*else if (strcasecmp(v->name,"type")) */
- /* ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
- v = v->next;
- }
- if (min_reg_expire > max_reg_expire) {
- ast_log(LOG_WARNING, "Minimum registration interval of %d is more than maximum of %d, resetting minimum to %d\n",
- min_reg_expire, max_reg_expire, max_reg_expire);
- min_reg_expire = max_reg_expire;
- }
- iax2_capability = capability;
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (strcasecmp(cat, "general")) {
- utype = ast_variable_retrieve(cfg, cat, "type");
- if (utype) {
- if (!strcasecmp(utype, "user") || !strcasecmp(utype, "friend")) {
- user = build_user(cat, ast_variable_browse(cfg, cat), 0);
- if (user) {
- ast_mutex_lock(&userl.lock);
- user->next = userl.users;
- userl.users = user;
- ast_mutex_unlock(&userl.lock);
- }
- }
- if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) {
- peer = build_peer(cat, ast_variable_browse(cfg, cat), 0);
- if (peer) {
- ast_mutex_lock(&peerl.lock);
- peer->next = peerl.peers;
- peerl.peers = peer;
- ast_mutex_unlock(&peerl.lock);
- if (ast_test_flag(peer, IAX_DYNAMIC))
- reg_source_db(peer);
- }
- } else if (strcasecmp(utype, "user")) {
- ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, config_file);
- }
- } else
- ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat);
- }
- cat = ast_category_browse(cfg, cat);
- }
- ast_config_destroy(cfg);
- set_timing();
- return capability;
-}
-
-static int reload_config(void)
-{
- char *config = "iax.conf";
- struct iax2_registry *reg;
- struct iax2_peer *peer;
- ast_copy_string(accountcode, "", sizeof(accountcode));
- ast_copy_string(language, "", sizeof(language));
- amaflags = 0;
- delayreject = 0;
- ast_clear_flag((&globalflags), IAX_NOTRANSFER);
- ast_clear_flag((&globalflags), IAX_USEJITTERBUF);
- ast_clear_flag((&globalflags), IAX_FORCEJITTERBUF);
- delete_users();
- set_config(config,1);
- prune_peers();
- prune_users();
- for (reg = registrations; reg; reg = reg->next)
- iax2_do_register(reg);
- /* Qualify hosts, too */
- ast_mutex_lock(&peerl.lock);
- for (peer = peerl.peers; peer; peer = peer->next)
- iax2_poke_peer(peer, 0);
- ast_mutex_unlock(&peerl.lock);
- reload_firmware();
- iax_provision_reload();
- return 0;
-}
-
-static int iax2_reload(int fd, int argc, char *argv[])
-{
- return reload_config();
-}
-
-int reload(void)
-{
- return reload_config();
-}
-
-static int cache_get_callno_locked(const char *data)
-{
- struct sockaddr_in sin;
- int x;
- int callno;
- struct iax_ie_data ied;
- struct create_addr_info cai;
- struct parsed_dial_string pds;
- char *tmpstr;
-
- for (x=0; x<IAX_MAX_CALLS; x++) {
- /* Look for an *exact match* call. Once a call is negotiated, it can only
- look up entries for a single context */
- if (!ast_mutex_trylock(&iaxsl[x])) {
- if (iaxs[x] && !strcasecmp(data, iaxs[x]->dproot))
- return x;
- ast_mutex_unlock(&iaxsl[x]);
- }
- }
-
- /* No match found, we need to create a new one */
-
- memset(&cai, 0, sizeof(cai));
- memset(&ied, 0, sizeof(ied));
- memset(&pds, 0, sizeof(pds));
-
- tmpstr = ast_strdupa(data);
- parse_dial_string(tmpstr, &pds);
-
- /* Populate our address from the given */
- if (create_addr(pds.peer, &sin, &cai))
- return -1;
-
- ast_log(LOG_DEBUG, "peer: %s, username: %s, password: %s, context: %s\n",
- pds.peer, pds.username, pds.password, pds.context);
-
- callno = find_callno(0, 0, &sin, NEW_FORCE, 1, cai.sockfd);
- if (callno < 1) {
- ast_log(LOG_WARNING, "Unable to create call\n");
- return -1;
- }
-
- ast_mutex_lock(&iaxsl[callno]);
- ast_copy_string(iaxs[callno]->dproot, data, sizeof(iaxs[callno]->dproot));
- iaxs[callno]->capability = IAX_CAPABILITY_FULLBANDWIDTH;
-
- iax_ie_append_short(&ied, IAX_IE_VERSION, IAX_PROTO_VERSION);
- iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, "TBD");
- /* the string format is slightly different from a standard dial string,
- because the context appears in the 'exten' position
- */
- if (pds.exten)
- iax_ie_append_str(&ied, IAX_IE_CALLED_CONTEXT, pds.exten);
- if (pds.username)
- iax_ie_append_str(&ied, IAX_IE_USERNAME, pds.username);
- iax_ie_append_int(&ied, IAX_IE_FORMAT, IAX_CAPABILITY_FULLBANDWIDTH);
- iax_ie_append_int(&ied, IAX_IE_CAPABILITY, IAX_CAPABILITY_FULLBANDWIDTH);
- /* Keep password handy */
- if (pds.password)
- ast_copy_string(iaxs[callno]->secret, pds.password, sizeof(iaxs[callno]->secret));
- if (pds.key)
- ast_copy_string(iaxs[callno]->outkey, pds.key, sizeof(iaxs[callno]->outkey));
- /* Start the call going */
- send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_NEW, 0, ied.buf, ied.pos, -1);
-
- return callno;
-}
-
-static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *data, const char *context, const char *exten, int priority)
-{
- struct iax2_dpcache *dp, *prev = NULL, *next;
- struct timeval tv;
- int x;
- int com[2];
- int timeout;
- int old=0;
- int outfd;
- int abort;
- int callno;
- struct ast_channel *c;
- struct ast_frame *f;
- gettimeofday(&tv, NULL);
- dp = dpcache;
- while(dp) {
- next = dp->next;
- /* Expire old caches */
- if (ast_tvcmp(tv, dp->expiry) > 0) {
- /* It's expired, let it disappear */
- if (prev)
- prev->next = dp->next;
- else
- dpcache = dp->next;
- if (!dp->peer && !(dp->flags & CACHE_FLAG_PENDING) && !dp->callno) {
- /* Free memory and go again */
- free(dp);
- } else {
- ast_log(LOG_WARNING, "DP still has peer field or pending or callno (flags = %d, peer = %p callno = %d)\n", dp->flags, dp->peer, dp->callno);
- }
- dp = next;
- continue;
- }
- /* We found an entry that matches us! */
- if (!strcmp(dp->peercontext, data) && !strcmp(dp->exten, exten))
- break;
- prev = dp;
- dp = next;
- }
- if (!dp) {
- /* No matching entry. Create a new one. */
- /* First, can we make a callno? */
- callno = cache_get_callno_locked(data);
- if (callno < 0) {
- ast_log(LOG_WARNING, "Unable to generate call for '%s'\n", data);
- return NULL;
- }
- dp = malloc(sizeof(struct iax2_dpcache));
- if (!dp) {
- ast_mutex_unlock(&iaxsl[callno]);
- return NULL;
- }
- memset(dp, 0, sizeof(struct iax2_dpcache));
- ast_copy_string(dp->peercontext, data, sizeof(dp->peercontext));
- ast_copy_string(dp->exten, exten, sizeof(dp->exten));
- gettimeofday(&dp->expiry, NULL);
- dp->orig = dp->expiry;
- /* Expires in 30 mins by default */
- dp->expiry.tv_sec += iaxdefaultdpcache;
- dp->next = dpcache;
- dp->flags = CACHE_FLAG_PENDING;
- for (x=0;x<sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++)
- dp->waiters[x] = -1;
- dpcache = dp;
- dp->peer = iaxs[callno]->dpentries;
- iaxs[callno]->dpentries = dp;
- /* Send the request if we're already up */
- if (ast_test_flag(&iaxs[callno]->state, IAX_STATE_STARTED))
- iax2_dprequest(dp, callno);
- ast_mutex_unlock(&iaxsl[callno]);
- }
- /* By here we must have a dp */
- if (dp->flags & CACHE_FLAG_PENDING) {
- /* Okay, here it starts to get nasty. We need a pipe now to wait
- for a reply to come back so long as it's pending */
- for (x=0;x<sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++) {
- /* Find an empty slot */
- if (dp->waiters[x] < 0)
- break;
- }
- if (x >= sizeof(dp->waiters) / sizeof(dp->waiters[0])) {
- ast_log(LOG_WARNING, "No more waiter positions available\n");
- return NULL;
- }
- if (pipe(com)) {
- ast_log(LOG_WARNING, "Unable to create pipe for comm\n");
- return NULL;
- }
- dp->waiters[x] = com[1];
- /* Okay, now we wait */
- timeout = iaxdefaulttimeout * 1000;
- /* Temporarily unlock */
- ast_mutex_unlock(&dpcache_lock);
- /* Defer any dtmf */
- if (chan)
- old = ast_channel_defer_dtmf(chan);
- abort = 0;
- while(timeout) {
- c = ast_waitfor_nandfds(&chan, chan ? 1 : 0, &com[0], 1, NULL, &outfd, &timeout);
- if (outfd > -1) {
- break;
- }
- if (c) {
- f = ast_read(c);
- if (f)
- ast_frfree(f);
- else {
- /* Got hung up on, abort! */
- break;
- abort = 1;
- }
- }
- }
- if (!timeout) {
- ast_log(LOG_WARNING, "Timeout waiting for %s exten %s\n", data, exten);
- }
- ast_mutex_lock(&dpcache_lock);
- dp->waiters[x] = -1;
- close(com[1]);
- close(com[0]);
- if (abort) {
- /* Don't interpret anything, just abort. Not sure what th epoint
- of undeferring dtmf on a hung up channel is but hey whatever */
- if (!old && chan)
- ast_channel_undefer_dtmf(chan);
- return NULL;
- }
- if (!(dp->flags & CACHE_FLAG_TIMEOUT)) {
- /* Now to do non-independent analysis the results of our wait */
- if (dp->flags & CACHE_FLAG_PENDING) {
- /* Still pending... It's a timeout. Wake everybody up. Consider it no longer
- pending. Don't let it take as long to timeout. */
- dp->flags &= ~CACHE_FLAG_PENDING;
- dp->flags |= CACHE_FLAG_TIMEOUT;
- /* Expire after only 60 seconds now. This is designed to help reduce backlog in heavily loaded
- systems without leaving it unavailable once the server comes back online */
- dp->expiry.tv_sec = dp->orig.tv_sec + 60;
- for (x=0;x<sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++)
- if (dp->waiters[x] > -1)
- write(dp->waiters[x], "asdf", 4);
- }
- }
- /* Our caller will obtain the rest */
- if (!old && chan)
- ast_channel_undefer_dtmf(chan);
- }
- return dp;
-}
-
-/*--- iax2_exists: Part of the IAX2 switch interface ---*/
-static int iax2_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- struct iax2_dpcache *dp;
- int res = 0;
-#if 0
- ast_log(LOG_NOTICE, "iax2_exists: con: %s, exten: %s, pri: %d, cid: %s, data: %s\n", context, exten, priority, callerid ? callerid : "<unknown>", data);
-#endif
- if ((priority != 1) && (priority != 2))
- return 0;
- ast_mutex_lock(&dpcache_lock);
- dp = find_cache(chan, data, context, exten, priority);
- if (dp) {
- if (dp->flags & CACHE_FLAG_EXISTS)
- res= 1;
- }
- ast_mutex_unlock(&dpcache_lock);
- if (!dp) {
- ast_log(LOG_WARNING, "Unable to make DP cache\n");
- }
- return res;
-}
-
-/*--- iax2_canmatch: part of the IAX2 dial plan switch interface */
-static int iax2_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- int res = 0;
- struct iax2_dpcache *dp;
-#if 0
- ast_log(LOG_NOTICE, "iax2_canmatch: con: %s, exten: %s, pri: %d, cid: %s, data: %s\n", context, exten, priority, callerid ? callerid : "<unknown>", data);
-#endif
- if ((priority != 1) && (priority != 2))
- return 0;
- ast_mutex_lock(&dpcache_lock);
- dp = find_cache(chan, data, context, exten, priority);
- if (dp) {
- if (dp->flags & CACHE_FLAG_CANEXIST)
- res= 1;
- }
- ast_mutex_unlock(&dpcache_lock);
- if (!dp) {
- ast_log(LOG_WARNING, "Unable to make DP cache\n");
- }
- return res;
-}
-
-/*--- iax2_matchmore: Part of the IAX2 Switch interface */
-static int iax2_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- int res = 0;
- struct iax2_dpcache *dp;
-#if 0
- ast_log(LOG_NOTICE, "iax2_matchmore: con: %s, exten: %s, pri: %d, cid: %s, data: %s\n", context, exten, priority, callerid ? callerid : "<unknown>", data);
-#endif
- if ((priority != 1) && (priority != 2))
- return 0;
- ast_mutex_lock(&dpcache_lock);
- dp = find_cache(chan, data, context, exten, priority);
- if (dp) {
- if (dp->flags & CACHE_FLAG_MATCHMORE)
- res= 1;
- }
- ast_mutex_unlock(&dpcache_lock);
- if (!dp) {
- ast_log(LOG_WARNING, "Unable to make DP cache\n");
- }
- return res;
-}
-
-/*--- iax2_exec: Execute IAX2 dialplan switch */
-static int iax2_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data)
-{
- char odata[256];
- char req[256];
- char *ncontext;
- char *dialstatus;
- struct iax2_dpcache *dp;
- struct ast_app *dial;
-#if 0
- ast_log(LOG_NOTICE, "iax2_exec: con: %s, exten: %s, pri: %d, cid: %s, data: %s, newstack: %d\n", context, exten, priority, callerid ? callerid : "<unknown>", data, newstack);
-#endif
- if (priority == 2) {
- /* Indicate status, can be overridden in dialplan */
- dialstatus = pbx_builtin_getvar_helper(chan, "DIALSTATUS");
- if (dialstatus) {
- dial = pbx_findapp(dialstatus);
- if (dial)
- pbx_exec(chan, dial, "", newstack);
- }
- return -1;
- } else if (priority != 1)
- return -1;
- ast_mutex_lock(&dpcache_lock);
- dp = find_cache(chan, data, context, exten, priority);
- if (dp) {
- if (dp->flags & CACHE_FLAG_EXISTS) {
- ast_copy_string(odata, data, sizeof(odata));
- ncontext = strchr(odata, '/');
- if (ncontext) {
- *ncontext = '\0';
- ncontext++;
- snprintf(req, sizeof(req), "IAX2/%s/%s@%s", odata, exten, ncontext);
- } else {
- snprintf(req, sizeof(req), "IAX2/%s/%s", odata, exten);
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Executing Dial('%s')\n", req);
- } else {
- ast_mutex_unlock(&dpcache_lock);
- ast_log(LOG_WARNING, "Can't execute nonexistent extension '%s[@%s]' in data '%s'\n", exten, context, data);
- return -1;
- }
- }
- ast_mutex_unlock(&dpcache_lock);
- dial = pbx_findapp("Dial");
- if (dial) {
- return pbx_exec(chan, dial, req, newstack);
- } else {
- ast_log(LOG_WARNING, "No dial application registered\n");
- }
- return -1;
-}
-
-static char *function_iaxpeer(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *ret = NULL;
- struct iax2_peer *peer;
- char *peername, *colname;
- char iabuf[INET_ADDRSTRLEN];
-
- if (!(peername = ast_strdupa(data))) {
- ast_log(LOG_ERROR, "Memory Error!\n");
- return ret;
- }
-
- /* if our channel, return the IP address of the endpoint of current channel */
- if (!strcmp(peername,"CURRENTCHANNEL")) {
- unsigned short callno = PTR_TO_CALLNO(chan->tech_pvt);
- ast_copy_string(buf, iaxs[callno]->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[callno]->addr.sin_addr) : "", len);
- return buf;
- }
-
- if ((colname = strchr(peername, ':'))) {
- *colname = '\0';
- colname++;
- } else {
- colname = "ip";
- }
- if (!(peer = find_peer(peername, 1)))
- return ret;
-
- if (!strcasecmp(colname, "ip")) {
- ast_copy_string(buf, peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "", len);
- } else if (!strcasecmp(colname, "status")) {
- peer_status(peer, buf, len);
- } else if (!strcasecmp(colname, "mailbox")) {
- ast_copy_string(buf, peer->mailbox, len);
- } else if (!strcasecmp(colname, "context")) {
- ast_copy_string(buf, peer->context, len);
- } else if (!strcasecmp(colname, "expire")) {
- snprintf(buf, len, "%d", peer->expire);
- } else if (!strcasecmp(colname, "dynamic")) {
- ast_copy_string(buf, (ast_test_flag(peer, IAX_DYNAMIC) ? "yes" : "no"), len);
- } else if (!strcasecmp(colname, "callerid_name")) {
- ast_copy_string(buf, peer->cid_name, len);
- } else if (!strcasecmp(colname, "callerid_num")) {
- ast_copy_string(buf, peer->cid_num, len);
- } else if (!strcasecmp(colname, "codecs")) {
- ast_getformatname_multiple(buf, len -1, peer->capability);
- } else if (!strncasecmp(colname, "codec[", 6)) {
- char *codecnum, *ptr;
- int index = 0, codec = 0;
-
- codecnum = strchr(colname, '[');
- *codecnum = '\0';
- codecnum++;
- if ((ptr = strchr(codecnum, ']'))) {
- *ptr = '\0';
- }
- index = atoi(codecnum);
- if((codec = ast_codec_pref_index(&peer->prefs, index))) {
- ast_copy_string(buf, ast_getformatname(codec), len);
- }
- }
- ret = buf;
-
- return ret;
-}
-
-struct ast_custom_function iaxpeer_function = {
- .name = "IAXPEER",
- .synopsis = "Gets IAX peer information",
- .syntax = "IAXPEER(<peername|CURRENTCHANNEL>[:item])",
- .read = function_iaxpeer,
- .desc = "If peername specified, valid items are:\n"
- "- ip (default) The IP address.\n"
- "- status The peer's status (if qualify=yes)\n"
- "- mailbox The configured mailbox.\n"
- "- context The configured context.\n"
- "- expire The epoch time of the next expire.\n"
- "- dynamic Is it dynamic? (yes/no).\n"
- "- callerid_name The configured Caller ID name.\n"
- "- callerid_num The configured Caller ID number.\n"
- "- codecs The configured codecs.\n"
- "- codec[x] Preferred codec index number 'x' (beginning with zero).\n"
- "\n"
- "If CURRENTCHANNEL specified, returns IP address of current channel\n"
- "\n"
-};
-
-
-/*--- iax2_devicestate: Part of the device state notification system ---*/
-static int iax2_devicestate(void *data)
-{
- char *dest = (char *) data;
- struct iax2_peer *p;
- int found = 0;
- char *ext, *host;
- char tmp[256];
- int res = AST_DEVICE_INVALID;
-
- ast_copy_string(tmp, dest, sizeof(tmp));
- host = strchr(tmp, '@');
- if (host) {
- *host = '\0';
- host++;
- ext = tmp;
- } else {
- host = tmp;
- ext = NULL;
- }
-
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Checking device state for device %s\n", dest);
-
- /* SLD: FIXME: second call to find_peer during registration */
- p = find_peer(host, 1);
- if (p) {
- found++;
- res = AST_DEVICE_UNAVAILABLE;
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "iax2_devicestate(%s): Found peer. What's device state of %s? addr=%d, defaddr=%d maxms=%d, lastms=%d\n",
- host, dest, p->addr.sin_addr.s_addr, p->defaddr.sin_addr.s_addr, p->maxms, p->lastms);
-
- if ((p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) &&
- (!p->maxms || ((p->lastms > -1) && (p->historicms <= p->maxms)))) {
- /* Peer is registered, or have default IP address
- and a valid registration */
- if (p->historicms == 0 || p->historicms <= p->maxms)
- /* let the core figure out whether it is in use or not */
- res = AST_DEVICE_UNKNOWN;
- }
- } else {
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Devicestate: Can't find peer %s.\n", host);
- }
-
- if (p && ast_test_flag(p, IAX_TEMPONLY))
- destroy_peer(p);
- return res;
-}
-
-static struct ast_switch iax2_switch =
-{
- name: "IAX2",
- description: "IAX Remote Dialplan Switch",
- exists: iax2_exists,
- canmatch: iax2_canmatch,
- exec: iax2_exec,
- matchmore: iax2_matchmore,
-};
-
-static char show_stats_usage[] =
-"Usage: iax show stats\n"
-" Display statistics on IAX channel driver.\n";
-
-static char show_cache_usage[] =
-"Usage: iax show cache\n"
-" Display currently cached IAX Dialplan results.\n";
-
-static char show_peer_usage[] =
-"Usage: iax show peer <name>\n"
-" Display details on specific IAX peer\n";
-
-static char prune_realtime_usage[] =
-"Usage: iax2 prune realtime [<peername>|all]\n"
-" Prunes object(s) from the cache\n";
-
-static char iax2_reload_usage[] =
-"Usage: iax2 reload\n"
-" Reloads IAX configuration from iax.conf\n";
-
-static char show_prov_usage[] =
-"Usage: iax2 provision <host> <template> [forced]\n"
-" Provisions the given peer or IP address using a template\n"
-" matching either 'template' or '*' if the template is not\n"
-" found. If 'forced' is specified, even empty provisioning\n"
-" fields will be provisioned as empty fields.\n";
-
-static char show_users_usage[] =
-"Usage: iax2 show users [like <pattern>]\n"
-" Lists all known IAX2 users.\n"
-" Optional regular expression pattern is used to filter the user list.\n";
-
-static char show_channels_usage[] =
-"Usage: iax2 show channels\n"
-" Lists all currently active IAX channels.\n";
-
-static char show_netstats_usage[] =
-"Usage: iax2 show netstats\n"
-" Lists network status for all currently active IAX channels.\n";
-
-static char show_peers_usage[] =
-"Usage: iax2 show peers [registered] [like <pattern>]\n"
-" Lists all known IAX2 peers.\n"
-" Optional 'registered' argument lists only peers with known addresses.\n"
-" Optional regular expression pattern is used to filter the peer list.\n";
-
-static char show_firmware_usage[] =
-"Usage: iax2 show firmware\n"
-" Lists all known IAX firmware images.\n";
-
-static char show_reg_usage[] =
-"Usage: iax2 show registry\n"
-" Lists all registration requests and status.\n";
-
-static char debug_usage[] =
-"Usage: iax2 debug\n"
-" Enables dumping of IAX packets for debugging purposes\n";
-
-static char no_debug_usage[] =
-"Usage: iax2 no debug\n"
-" Disables dumping of IAX packets for debugging purposes\n";
-
-static char debug_trunk_usage[] =
-"Usage: iax2 trunk debug\n"
-" Requests current status of IAX trunking\n";
-
-static char no_debug_trunk_usage[] =
-"Usage: iax2 no trunk debug\n"
-" Requests current status of IAX trunking\n";
-
-static char debug_jb_usage[] =
-"Usage: iax2 jb debug\n"
-" Enables jitterbuffer debugging information\n";
-
-static char no_debug_jb_usage[] =
-"Usage: iax2 no jb debug\n"
-" Disables jitterbuffer debugging information\n";
-
-static char iax2_test_losspct_usage[] =
-"Usage: iax2 test losspct <percentage>\n"
-" For testing, throws away <percentage> percent of incoming packets\n";
-
-#ifdef IAXTESTS
-static char iax2_test_late_usage[] =
-"Usage: iax2 test late <ms>\n"
-" For testing, count the next frame as <ms> ms late\n";
-
-static char iax2_test_resync_usage[] =
-"Usage: iax2 test resync <ms>\n"
-" For testing, adjust all future frames by <ms> ms\n";
-
-static char iax2_test_jitter_usage[] =
-"Usage: iax2 test jitter <ms> <pct>\n"
-" For testing, simulate maximum jitter of +/- <ms> on <pct> percentage of packets. If <pct> is not specified, adds jitter to all packets.\n";
-#endif /* IAXTESTS */
-
-static struct ast_cli_entry iax2_cli[] = {
- { { "iax2", "set", "jitter", NULL }, iax2_set_jitter,
- "Sets IAX jitter buffer", jitter_usage },
- { { "iax2", "show", "stats", NULL }, iax2_show_stats,
- "Display IAX statistics", show_stats_usage },
- { { "iax2", "show", "cache", NULL }, iax2_show_cache,
- "Display IAX cached dialplan", show_cache_usage },
- { { "iax2", "show", "peer", NULL }, iax2_show_peer,
- "Show details on specific IAX peer", show_peer_usage, complete_iax2_show_peer },
- { { "iax2", "prune", "realtime", NULL }, iax2_prune_realtime,
- "Prune a cached realtime lookup", prune_realtime_usage, complete_iax2_show_peer },
- { { "iax2", "reload", NULL }, iax2_reload,
- "Reload IAX configuration", iax2_reload_usage },
- { { "iax2", "show", "users", NULL }, iax2_show_users,
- "Show defined IAX users", show_users_usage },
- { { "iax2", "show", "firmware", NULL }, iax2_show_firmware,
- "Show available IAX firmwares", show_firmware_usage },
- { { "iax2", "show", "channels", NULL }, iax2_show_channels,
- "Show active IAX channels", show_channels_usage },
- { { "iax2", "show", "netstats", NULL }, iax2_show_netstats,
- "Show active IAX channel netstats", show_netstats_usage },
- { { "iax2", "show", "peers", NULL }, iax2_show_peers,
- "Show defined IAX peers", show_peers_usage },
- { { "iax2", "show", "registry", NULL }, iax2_show_registry,
- "Show IAX registration status", show_reg_usage },
- { { "iax2", "debug", NULL }, iax2_do_debug,
- "Enable IAX debugging", debug_usage },
- { { "iax2", "trunk", "debug", NULL }, iax2_do_trunk_debug,
- "Enable IAX trunk debugging", debug_trunk_usage },
- { { "iax2", "jb", "debug", NULL }, iax2_do_jb_debug,
- "Enable IAX jitterbuffer debugging", debug_jb_usage },
- { { "iax2", "no", "debug", NULL }, iax2_no_debug,
- "Disable IAX debugging", no_debug_usage },
- { { "iax2", "no", "trunk", "debug", NULL }, iax2_no_trunk_debug,
- "Disable IAX trunk debugging", no_debug_trunk_usage },
- { { "iax2", "no", "jb", "debug", NULL }, iax2_no_jb_debug,
- "Disable IAX jitterbuffer debugging", no_debug_jb_usage },
- { { "iax2", "test", "losspct", NULL }, iax2_test_losspct,
- "Set IAX2 incoming frame loss percentage", iax2_test_losspct_usage },
- { { "iax2", "provision", NULL }, iax2_prov_cmd,
- "Provision an IAX device", show_prov_usage, iax2_prov_complete_template_3rd },
-#ifdef IAXTESTS
- { { "iax2", "test", "late", NULL }, iax2_test_late,
- "Test the receipt of a late frame", iax2_test_late_usage },
- { { "iax2", "test", "resync", NULL }, iax2_test_resync,
- "Test a resync in received timestamps", iax2_test_resync_usage },
- { { "iax2", "test", "jitter", NULL }, iax2_test_jitter,
- "Simulates jitter for testing", iax2_test_jitter_usage },
-#endif /* IAXTESTS */
-};
-
-static int __unload_module(void)
-{
- int x;
- /* Cancel the network thread, close the net socket */
- if (netthreadid != AST_PTHREADT_NULL) {
- pthread_cancel(netthreadid);
- pthread_join(netthreadid, NULL);
- }
- ast_netsock_release(netsock);
- for (x=0;x<IAX_MAX_CALLS;x++)
- if (iaxs[x])
- iax2_destroy(x);
- ast_manager_unregister( "IAXpeers" );
- ast_manager_unregister( "IAXnetstats" );
- ast_unregister_application(papp);
- ast_cli_unregister_multiple(iax2_cli, sizeof(iax2_cli) / sizeof(iax2_cli[0]));
- ast_unregister_switch(&iax2_switch);
- ast_channel_unregister(&iax2_tech);
- delete_users();
- iax_provision_unload();
- sched_context_destroy(sched);
- return 0;
-}
-
-int unload_module()
-{
- ast_mutex_destroy(&iaxq.lock);
- ast_mutex_destroy(&userl.lock);
- ast_mutex_destroy(&peerl.lock);
- ast_mutex_destroy(&waresl.lock);
- ast_custom_function_unregister(&iaxpeer_function);
- return __unload_module();
-}
-
-
-/*--- load_module: Load IAX2 module, load configuraiton ---*/
-int load_module(void)
-{
- char *config = "iax.conf";
- int res = 0;
- int x;
- struct iax2_registry *reg;
- struct iax2_peer *peer;
-
- struct ast_netsock *ns;
- struct sockaddr_in sin;
-
- ast_custom_function_register(&iaxpeer_function);
-
- iax_set_output(iax_debug_output);
- iax_set_error(iax_error_output);
-#ifdef NEWJB
- jb_setoutput(jb_error_output, jb_warning_output, NULL);
-#endif
-
- sin.sin_family = AF_INET;
- sin.sin_port = htons(IAX_DEFAULT_PORTNO);
- sin.sin_addr.s_addr = INADDR_ANY;
-
-#ifdef IAX_TRUNKING
-#ifdef ZT_TIMERACK
- timingfd = open("/dev/zap/timer", O_RDWR);
- if (timingfd < 0)
-#endif
- timingfd = open("/dev/zap/pseudo", O_RDWR);
- if (timingfd < 0)
- ast_log(LOG_WARNING, "Unable to open IAX timing interface: %s\n", strerror(errno));
-#endif
-
- memset(iaxs, 0, sizeof(iaxs));
-
- for (x=0;x<IAX_MAX_CALLS;x++)
- ast_mutex_init(&iaxsl[x]);
-
- io = io_context_create();
- sched = sched_context_create();
-
- if (!io || !sched) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
-
- netsock = ast_netsock_list_alloc();
- if (!netsock) {
- ast_log(LOG_ERROR, "Could not allocate netsock list.\n");
- return -1;
- }
- ast_netsock_init(netsock);
-
- ast_mutex_init(&iaxq.lock);
- ast_mutex_init(&userl.lock);
- ast_mutex_init(&peerl.lock);
- ast_mutex_init(&waresl.lock);
-
- ast_cli_register_multiple(iax2_cli, sizeof(iax2_cli) / sizeof(iax2_cli[0]));
-
- ast_register_application(papp, iax2_prov_app, psyn, pdescrip);
-
- ast_manager_register( "IAXpeers", 0, manager_iax2_show_peers, "List IAX Peers" );
- ast_manager_register( "IAXnetstats", 0, manager_iax2_show_netstats, "Show IAX Netstats" );
-
- set_config(config, 0);
-
- if (ast_channel_register(&iax2_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", channeltype);
- __unload_module();
- return -1;
- }
-
- if (ast_register_switch(&iax2_switch))
- ast_log(LOG_ERROR, "Unable to register IAX switch\n");
-
- if (defaultsockfd < 0) {
- if (!(ns = ast_netsock_bindaddr(netsock, io, &sin, tos, socket_read, NULL))) {
- ast_log(LOG_ERROR, "Unable to create network socket: %s\n", strerror(errno));
- return -1;
- } else {
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Binding IAX2 to default address 0.0.0.0:%d\n", IAX_DEFAULT_PORTNO);
- defaultsockfd = ast_netsock_sockfd(ns);
- ast_netsock_unref(ns);
- }
- }
-
- res = start_network_thread();
- if (!res) {
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "IAX Ready and Listening\n");
- } else {
- ast_log(LOG_ERROR, "Unable to start network thread\n");
- ast_netsock_release(netsock);
- }
-
- for (reg = registrations; reg; reg = reg->next)
- iax2_do_register(reg);
- ast_mutex_lock(&peerl.lock);
- for (peer = peerl.peers; peer; peer = peer->next) {
- if (peer->sockfd < 0)
- peer->sockfd = defaultsockfd;
- iax2_poke_peer(peer, 0);
- }
- ast_mutex_unlock(&peerl.lock);
- reload_firmware();
- iax_provision_reload();
- return res;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_local.c b/1.2-netsec/channels/chan_local.c
deleted file mode 100644
index f843fd95d..000000000
--- a/1.2-netsec/channels/chan_local.c
+++ /dev/null
@@ -1,661 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Local Proxy Channel
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/signal.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp.h"
-#include "asterisk/acl.h"
-#include "asterisk/callerid.h"
-#include "asterisk/file.h"
-#include "asterisk/cli.h"
-#include "asterisk/app.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/manager.h"
-
-static const char desc[] = "Local Proxy Channel";
-static const char type[] = "Local";
-static const char tdesc[] = "Local Proxy Channel Driver";
-
-static int usecnt =0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-#define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
-
-/* Protect the interface list (of sip_pvt's) */
-AST_MUTEX_DEFINE_STATIC(locallock);
-
-static struct ast_channel *local_request(const char *type, int format, void *data, int *cause);
-static int local_digit(struct ast_channel *ast, char digit);
-static int local_call(struct ast_channel *ast, char *dest, int timeout);
-static int local_hangup(struct ast_channel *ast);
-static int local_answer(struct ast_channel *ast);
-static struct ast_frame *local_read(struct ast_channel *ast);
-static int local_write(struct ast_channel *ast, struct ast_frame *f);
-static int local_indicate(struct ast_channel *ast, int condition);
-static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
-
-/* PBX interface structure for channel registration */
-static const struct ast_channel_tech local_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = -1,
- .requester = local_request,
- .send_digit = local_digit,
- .call = local_call,
- .hangup = local_hangup,
- .answer = local_answer,
- .read = local_read,
- .write = local_write,
- .exception = local_read,
- .indicate = local_indicate,
- .fixup = local_fixup,
- .send_html = local_sendhtml,
-};
-
-static struct local_pvt {
- ast_mutex_t lock; /* Channel private lock */
- char context[AST_MAX_CONTEXT]; /* Context to call */
- char exten[AST_MAX_EXTENSION]; /* Extension to call */
- int reqformat; /* Requested format */
- int glaredetect; /* Detect glare on hangup */
- int cancelqueue; /* Cancel queue */
- int alreadymasqed; /* Already masqueraded */
- int launchedpbx; /* Did we launch the PBX */
- int nooptimization; /* Don't leave masq state */
- struct ast_channel *owner; /* Master Channel */
- struct ast_channel *chan; /* Outbound channel */
- struct local_pvt *next; /* Next entity */
-} *locals = NULL;
-
-static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us)
-{
- struct ast_channel *other;
-retrylock:
- /* Recalculate outbound channel */
- if (isoutbound) {
- other = p->owner;
- } else {
- other = p->chan;
- }
- /* Set glare detection */
- p->glaredetect = 1;
- if (p->cancelqueue) {
- /* We had a glare on the hangup. Forget all this business,
- return and destroy p. */
- ast_mutex_unlock(&p->lock);
- ast_mutex_destroy(&p->lock);
- free(p);
- return -1;
- }
- if (!other) {
- p->glaredetect = 0;
- return 0;
- }
- if (ast_mutex_trylock(&other->lock)) {
- /* Failed to lock. Release main lock and try again */
- ast_mutex_unlock(&p->lock);
- if (us) {
- if (ast_mutex_unlock(&us->lock)) {
- ast_log(LOG_WARNING, "%s wasn't locked while sending %d/%d\n",
- us->name, f->frametype, f->subclass);
- us = NULL;
- }
- }
- /* Wait just a bit */
- usleep(1);
- /* Only we can destroy ourselves, so we can't disappear here */
- if (us)
- ast_mutex_lock(&us->lock);
- ast_mutex_lock(&p->lock);
- goto retrylock;
- }
- ast_queue_frame(other, f);
- ast_mutex_unlock(&other->lock);
- p->glaredetect = 0;
- return 0;
-}
-
-static int local_answer(struct ast_channel *ast)
-{
- struct local_pvt *p = ast->tech_pvt;
- int isoutbound;
- int res = -1;
-
- ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
- if (isoutbound) {
- /* Pass along answer since somebody answered us */
- struct ast_frame answer = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
- res = local_queue_frame(p, isoutbound, &answer, ast);
- } else
- ast_log(LOG_WARNING, "Huh? Local is being asked to answer?\n");
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static void check_bridge(struct local_pvt *p, int isoutbound)
-{
- if (p->alreadymasqed || p->nooptimization)
- return;
- if (!p->chan || !p->owner)
- return;
- if (isoutbound&& p->chan->_bridge /* Not ast_bridged_channel! Only go one step! */ && !p->owner->readq) {
- /* Masquerade bridged channel into owner */
- /* Lock everything we need, one by one, and give up if
- we can't get everything. Remember, we'll get another
- chance in just a little bit */
- if (!ast_mutex_trylock(&(p->chan->_bridge)->lock)) {
- if (!p->chan->_bridge->_softhangup) {
- if (!ast_mutex_trylock(&p->owner->lock)) {
- if (!p->owner->_softhangup) {
- ast_channel_masquerade(p->owner, p->chan->_bridge);
- p->alreadymasqed = 1;
- }
- ast_mutex_unlock(&p->owner->lock);
- }
- ast_mutex_unlock(&(p->chan->_bridge)->lock);
- }
- }
- } else if (!isoutbound && p->owner && p->owner->_bridge && p->chan && !p->chan->readq) {
- /* Masquerade bridged channel into chan */
- if (!ast_mutex_trylock(&(p->owner->_bridge)->lock)) {
- if (!p->owner->_bridge->_softhangup) {
- if (!ast_mutex_trylock(&p->chan->lock)) {
- if (!p->chan->_softhangup) {
- ast_channel_masquerade(p->chan, p->owner->_bridge);
- p->alreadymasqed = 1;
- }
- ast_mutex_unlock(&p->chan->lock);
- }
- }
- ast_mutex_unlock(&(p->owner->_bridge)->lock);
- }
- }
-}
-
-static struct ast_frame *local_read(struct ast_channel *ast)
-{
- static struct ast_frame null = { AST_FRAME_NULL, };
-
- return &null;
-}
-
-static int local_write(struct ast_channel *ast, struct ast_frame *f)
-{
- struct local_pvt *p = ast->tech_pvt;
- int res = -1;
- int isoutbound;
-
- /* Just queue for delivery to the other side */
- ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
- if (f && (f->frametype == AST_FRAME_VOICE))
- check_bridge(p, isoutbound);
- if (!p->alreadymasqed)
- res = local_queue_frame(p, isoutbound, f, ast);
- else {
- ast_log(LOG_DEBUG, "Not posting to queue since already masked on '%s'\n", ast->name);
- res = 0;
- }
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct local_pvt *p = newchan->tech_pvt;
- ast_mutex_lock(&p->lock);
-
- if ((p->owner != oldchan) && (p->chan != oldchan)) {
- ast_log(LOG_WARNING, "Old channel wasn't %p but was %p/%p\n", oldchan, p->owner, p->chan);
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- if (p->owner == oldchan)
- p->owner = newchan;
- else
- p->chan = newchan;
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-static int local_indicate(struct ast_channel *ast, int condition)
-{
- struct local_pvt *p = ast->tech_pvt;
- int res = -1;
- struct ast_frame f = { AST_FRAME_CONTROL, };
- int isoutbound;
-
- /* Queue up a frame representing the indication as a control frame */
- ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
- f.subclass = condition;
- res = local_queue_frame(p, isoutbound, &f, ast);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int local_digit(struct ast_channel *ast, char digit)
-{
- struct local_pvt *p = ast->tech_pvt;
- int res = -1;
- struct ast_frame f = { AST_FRAME_DTMF, };
- int isoutbound;
-
- ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
- f.subclass = digit;
- res = local_queue_frame(p, isoutbound, &f, ast);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
-{
- struct local_pvt *p = ast->tech_pvt;
- int res = -1;
- struct ast_frame f = { AST_FRAME_HTML, };
- int isoutbound;
-
- ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
- f.subclass = subclass;
- f.data = (char *)data;
- f.datalen = datalen;
- res = local_queue_frame(p, isoutbound, &f, ast);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-/*--- local_call: Initiate new call, part of PBX interface */
-/* dest is the dial string */
-static int local_call(struct ast_channel *ast, char *dest, int timeout)
-{
- struct local_pvt *p = ast->tech_pvt;
- int res;
- struct ast_var_t *varptr = NULL, *new;
- size_t len, namelen;
-
- ast_mutex_lock(&p->lock);
- if (p->owner->cid.cid_num)
- p->chan->cid.cid_num = strdup(p->owner->cid.cid_num);
- else
- p->chan->cid.cid_num = NULL;
-
- if (p->owner->cid.cid_name)
- p->chan->cid.cid_name = strdup(p->owner->cid.cid_name);
- else
- p->chan->cid.cid_name = NULL;
-
- if (p->owner->cid.cid_rdnis)
- p->chan->cid.cid_rdnis = strdup(p->owner->cid.cid_rdnis);
- else
- p->chan->cid.cid_rdnis = NULL;
-
- if (p->owner->cid.cid_ani)
- p->chan->cid.cid_ani = strdup(p->owner->cid.cid_ani);
- else
- p->chan->cid.cid_ani = NULL;
-
- strncpy(p->chan->language, p->owner->language, sizeof(p->chan->language) - 1);
- strncpy(p->chan->accountcode, p->owner->accountcode, sizeof(p->chan->accountcode) - 1);
- p->chan->cdrflags = p->owner->cdrflags;
-
- /* copy the channel variables from the incoming channel to the outgoing channel */
- /* Note that due to certain assumptions, they MUST be in the same order */
- AST_LIST_TRAVERSE(&p->owner->varshead, varptr, entries) {
- namelen = strlen(varptr->name);
- len = sizeof(struct ast_var_t) + namelen + strlen(varptr->value) + 2;
- new = malloc(len);
- if (new) {
- memcpy(new, varptr, len);
- new->value = &(new->name[0]) + namelen + 1;
- AST_LIST_INSERT_TAIL(&p->chan->varshead, new, entries);
- } else {
- ast_log(LOG_ERROR, "Out of memory!\n");
- }
- }
-
- p->launchedpbx = 1;
-
- /* Start switch on sub channel */
- res = ast_pbx_start(p->chan);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-#if 0
-static void local_destroy(struct local_pvt *p)
-{
- struct local_pvt *cur, *prev = NULL;
- ast_mutex_lock(&locallock);
- cur = locals;
- while(cur) {
- if (cur == p) {
- if (prev)
- prev->next = cur->next;
- else
- locals = cur->next;
- ast_mutex_destroy(cur);
- free(cur);
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- ast_mutex_unlock(&locallock);
- if (!cur)
- ast_log(LOG_WARNING, "Unable ot find local '%s@%s' in local list\n", p->exten, p->context);
-}
-#endif
-
-/*--- local_hangup: Hangup a call through the local proxy channel */
-static int local_hangup(struct ast_channel *ast)
-{
- struct local_pvt *p = ast->tech_pvt;
- int isoutbound;
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
- struct local_pvt *cur, *prev=NULL;
- struct ast_channel *ochan = NULL;
- int glaredetect;
-
- ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
- if (isoutbound) {
- p->chan = NULL;
- p->launchedpbx = 0;
- } else
- p->owner = NULL;
- ast->tech_pvt = NULL;
-
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
-
- if (!p->owner && !p->chan) {
- /* Okay, done with the private part now, too. */
- glaredetect = p->glaredetect;
- /* If we have a queue holding, don't actually destroy p yet, but
- let local_queue do it. */
- if (p->glaredetect)
- p->cancelqueue = 1;
- ast_mutex_unlock(&p->lock);
- /* Remove from list */
- ast_mutex_lock(&locallock);
- cur = locals;
- while(cur) {
- if (cur == p) {
- if (prev)
- prev->next = cur->next;
- else
- locals = cur->next;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- ast_mutex_unlock(&locallock);
- /* Grab / release lock just in case */
- ast_mutex_lock(&p->lock);
- ast_mutex_unlock(&p->lock);
- /* And destroy */
- if (!glaredetect) {
- ast_mutex_destroy(&p->lock);
- free(p);
- }
- return 0;
- }
- if (p->chan && !p->launchedpbx)
- /* Need to actually hangup since there is no PBX */
- ochan = p->chan;
- else
- local_queue_frame(p, isoutbound, &f, NULL);
- ast_mutex_unlock(&p->lock);
- if (ochan)
- ast_hangup(ochan);
- return 0;
-}
-
-/*--- local_alloc: Create a call structure */
-static struct local_pvt *local_alloc(char *data, int format)
-{
- struct local_pvt *tmp;
- char *c;
- char *opts;
-
- tmp = malloc(sizeof(struct local_pvt));
- if (tmp) {
- memset(tmp, 0, sizeof(struct local_pvt));
- ast_mutex_init(&tmp->lock);
- strncpy(tmp->exten, data, sizeof(tmp->exten) - 1);
- opts = strchr(tmp->exten, '/');
- if (opts) {
- *opts='\0';
- opts++;
- if (strchr(opts, 'n'))
- tmp->nooptimization = 1;
- }
- c = strchr(tmp->exten, '@');
- if (c) {
- *c = '\0';
- c++;
- strncpy(tmp->context, c, sizeof(tmp->context) - 1);
- } else
- strncpy(tmp->context, "default", sizeof(tmp->context) - 1);
- tmp->reqformat = format;
- if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) {
- ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context);
- ast_mutex_destroy(&tmp->lock);
- free(tmp);
- tmp = NULL;
- } else {
- /* Add to list */
- ast_mutex_lock(&locallock);
- tmp->next = locals;
- locals = tmp;
- ast_mutex_unlock(&locallock);
- }
-
- }
- return tmp;
-}
-
-/*--- local_new: Start new local channel */
-static struct ast_channel *local_new(struct local_pvt *p, int state)
-{
- struct ast_channel *tmp, *tmp2;
- int randnum = rand() & 0xffff;
-
- tmp = ast_channel_alloc(1);
- tmp2 = ast_channel_alloc(1);
- if (!tmp || !tmp2) {
- if (tmp)
- ast_channel_free(tmp);
- if (tmp2)
- ast_channel_free(tmp2);
- ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
- return NULL;
- }
-
- tmp2->tech = tmp->tech = &local_tech;
- tmp->nativeformats = p->reqformat;
- tmp2->nativeformats = p->reqformat;
- snprintf(tmp->name, sizeof(tmp->name), "Local/%s@%s-%04x,1", p->exten, p->context, randnum);
- snprintf(tmp2->name, sizeof(tmp2->name), "Local/%s@%s-%04x,2", p->exten, p->context, randnum);
- tmp->type = type;
- tmp2->type = type;
- ast_setstate(tmp, state);
- ast_setstate(tmp2, AST_STATE_RING);
- tmp->writeformat = p->reqformat;
- tmp2->writeformat = p->reqformat;
- tmp->rawwriteformat = p->reqformat;
- tmp2->rawwriteformat = p->reqformat;
- tmp->readformat = p->reqformat;
- tmp2->readformat = p->reqformat;
- tmp->rawreadformat = p->reqformat;
- tmp2->rawreadformat = p->reqformat;
- tmp->tech_pvt = p;
- tmp2->tech_pvt = p;
- p->owner = tmp;
- p->chan = tmp2;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- ast_copy_string(tmp->context, p->context, sizeof(tmp->context));
- ast_copy_string(tmp2->context, p->context, sizeof(tmp2->context));
- ast_copy_string(tmp2->exten, p->exten, sizeof(tmp->exten));
- tmp->priority = 1;
- tmp2->priority = 1;
-
- return tmp;
-}
-
-
-/*--- local_request: Part of PBX interface */
-static struct ast_channel *local_request(const char *type, int format, void *data, int *cause)
-{
- struct local_pvt *p;
- struct ast_channel *chan = NULL;
-
- p = local_alloc(data, format);
- if (p)
- chan = local_new(p, AST_STATE_DOWN);
- return chan;
-}
-
-/*--- locals_show: CLI command "local show channels" */
-static int locals_show(int fd, int argc, char **argv)
-{
- struct local_pvt *p;
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&locallock);
- p = locals;
- while(p) {
- ast_mutex_lock(&p->lock);
- ast_cli(fd, "%s -- %s@%s\n", p->owner ? p->owner->name : "<unowned>", p->exten, p->context);
- ast_mutex_unlock(&p->lock);
- p = p->next;
- }
- if (!locals)
- ast_cli(fd, "No local channels in use\n");
- ast_mutex_unlock(&locallock);
- return RESULT_SUCCESS;
-}
-
-static char show_locals_usage[] =
-"Usage: local show channels\n"
-" Provides summary information on active local proxy channels.\n";
-
-static struct ast_cli_entry cli_show_locals = {
- { "local", "show", "channels", NULL }, locals_show,
- "Show status of local channels", show_locals_usage, NULL };
-
-/*--- load_module: Load module into PBX, register channel */
-int load_module()
-{
- /* Make sure we can register our channel type */
- if (ast_channel_register(&local_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- return -1;
- }
- ast_cli_register(&cli_show_locals);
- return 0;
-}
-
-/*--- reload: Reload module */
-int reload()
-{
- return 0;
-}
-
-/*--- unload_module: Unload the local proxy channel from Asterisk */
-int unload_module()
-{
- struct local_pvt *p;
-
- /* First, take us out of the channel loop */
- ast_cli_unregister(&cli_show_locals);
- ast_channel_unregister(&local_tech);
- if (!ast_mutex_lock(&locallock)) {
- /* Hangup all interfaces if they have an owner */
- p = locals;
- while(p) {
- if (p->owner)
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- p = p->next;
- }
- locals = NULL;
- ast_mutex_unlock(&locallock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
diff --git a/1.2-netsec/channels/chan_mgcp.c b/1.2-netsec/channels/chan_mgcp.c
deleted file mode 100644
index 7538fd9d7..000000000
--- a/1.2-netsec/channels/chan_mgcp.c
+++ /dev/null
@@ -1,4409 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Implementation of Media Gateway Control Protocol
- *
- * \par See also
- * \arg \ref Config_mgcp
- *
- * \ingroup channel_drivers
- */
-
-/* FO: Changes
- * -- add distinctive ring signalling (part of RFC 3660)
- */
-
-/* JS: Changes
- -- add support for the wildcard endpoint
- -- seteable wildcard with wcardep on mgcp.conf
- -- added package indicator on RQNT, i.e "dl" --> "L/dl"
- -- removed MDCX just before DLCX, do we need this ?
-*/
-
-/* JS: TODO
- -- reload for wildcard endpoint probably buggy
- -- when hf is notified we're sending CRCX after MDCX, without waiting for
- OK on the MDCX which fails on Cisco IAD 24XX
- -- honour codec order, by now the lowest codec number in "allow" is the prefered
-*/
-
-/* SC: Changes
- -- packet retransmit mechanism (simplistic)
- -- per endpoint/subchannel mgcp command sequencing.
- -- better transaction handling
- -- fixed some mem leaks
- -- run-time configuration reload
- -- distinguish CA and GW default MGCP ports
- -- prevent clipping of DTMF tones in an established call
- -- fixed a few crash scenarios in 3-way
- -- fix for a few cases where asterisk and MGW end-up in conflicting ep states
- -- enclose numeric IP in [] for outgoing requests
-*/
-
-/* SC: TODO
- -- piggyback support
- -- responseAck support
- -- enhance retransmit mechanism (RTO calc. etc.)
- -- embedded command support
-*/
-
-/* FS: Changes
- -- fixed reload_config() / do_monitor to stay responsive during reloads
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <sys/signal.h>
-#include <signal.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <arpa/inet.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp.h"
-#include "asterisk/acl.h"
-#include "asterisk/callerid.h"
-#include "asterisk/cli.h"
-#include "asterisk/say.h"
-#include "asterisk/cdr.h"
-#include "asterisk/astdb.h"
-#include "asterisk/features.h"
-#include "asterisk/app.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/utils.h"
-#include "asterisk/causes.h"
-#include "asterisk/dsp.h"
-
-#ifndef IPTOS_MINCOST
-#define IPTOS_MINCOST 0x02
-#endif
-
-/*
- * Define to work around buggy dlink MGCP phone firmware which
- * appears not to know that "rt" is part of the "G" package.
- */
-/* #define DLINK_BUGGY_FIRMWARE */
-
-#define MGCPDUMPER
-#define DEFAULT_EXPIRY 120
-#define MAX_EXPIRY 3600
-#define CANREINVITE 1
-
-#ifndef INADDR_NONE
-#define INADDR_NONE (in_addr_t)(-1)
-#endif
-
-static const char desc[] = "Media Gateway Control Protocol (MGCP)";
-static const char type[] = "MGCP";
-static const char tdesc[] = "Media Gateway Control Protocol (MGCP)";
-static const char config[] = "mgcp.conf";
-
-#define MGCP_DTMF_RFC2833 (1 << 0)
-#define MGCP_DTMF_INBAND (1 << 1)
-#define MGCP_DTMF_HYBRID (1 << 2)
-
-#define DEFAULT_MGCP_GW_PORT 2427 /* From RFC 2705 */
-#define DEFAULT_MGCP_CA_PORT 2727 /* From RFC 2705 */
-#define MGCP_MAX_PACKET 1500 /* Also from RFC 2543, should sub headers tho */
-#define DEFAULT_RETRANS 1000 /* How frequently to retransmit */
-#define MAX_RETRANS 5 /* Try only 5 times for retransmissions */
-
-/* MGCP rtp stream modes */
-#define MGCP_CX_SENDONLY 0
-#define MGCP_CX_RECVONLY 1
-#define MGCP_CX_SENDRECV 2
-#define MGCP_CX_CONF 3
-#define MGCP_CX_CONFERENCE 3
-#define MGCP_CX_MUTE 4
-#define MGCP_CX_INACTIVE 4
-
-static char *mgcp_cxmodes[] = {
- "sendonly",
- "recvonly",
- "sendrecv",
- "confrnce",
- "inactive"
-};
-
-/* SC: MGCP commands */
-#define MGCP_CMD_EPCF 0
-#define MGCP_CMD_CRCX 1
-#define MGCP_CMD_MDCX 2
-#define MGCP_CMD_DLCX 3
-#define MGCP_CMD_RQNT 4
-#define MGCP_CMD_NTFY 5
-#define MGCP_CMD_AUEP 6
-#define MGCP_CMD_AUCX 7
-#define MGCP_CMD_RSIP 8
-
-static char context[AST_MAX_EXTENSION] = "default";
-
-static char language[MAX_LANGUAGE] = "";
-static char musicclass[MAX_MUSICCLASS] = "";
-static char cid_num[AST_MAX_EXTENSION] = "";
-static char cid_name[AST_MAX_EXTENSION] = "";
-
-static int dtmfmode = 0;
-static int nat = 0;
-
-/* Not used. Dosn't hurt for us to always send cid */
-/* to the mgcp box. */
-/*static int use_callerid = 1;*/
-/*static int cur_signalling = -1;*/
-
-/*static unsigned int cur_group = 0;*/
-static ast_group_t cur_callergroup = 0;
-static ast_group_t cur_pickupgroup = 0;
-
-/* XXX Is this needed? */
-/* Doesn't look like the dsp stuff for */
-/* dtmfmode is actually hooked up. */
-/*static int relaxdtmf = 0;*/
-
-static int tos = 0;
-
-static int immediate = 0;
-
-static int callwaiting = 0;
-
-/* Not used. Dosn't hurt for us to always send cid */
-/* to the mgcp box. */
-/*static int callwaitingcallerid = 0;*/
-
-/*static int hidecallerid = 0;*/
-
-static int callreturn = 0;
-
-static int slowsequence = 0;
-
-static int threewaycalling = 0;
-
-/* This is for flashhook transfers */
-static int transfer = 0;
-
-static int cancallforward = 0;
-
-static int singlepath = 0;
-
-static int canreinvite = CANREINVITE;
-
-/*static int busycount = 3;*/
-
-/*static int callprogress = 0;*/
-
-static char accountcode[AST_MAX_ACCOUNT_CODE] = "";
-
-static char mailbox[AST_MAX_EXTENSION];
-
-static int amaflags = 0;
-
-static int adsi = 0;
-
-static int usecnt =0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-/* SC: transaction id should always be positive */
-static unsigned int oseq;
-
-/* Wait up to 16 seconds for first digit (FXO logic) */
-static int firstdigittimeout = 16000;
-
-/* How long to wait for following digits (FXO logic) */
-static int gendigittimeout = 8000;
-
-/* How long to wait for an extra digit, if there is an ambiguous match */
-static int matchdigittimeout = 3000;
-
-/* Protect the monitoring thread, so only one process can kill or start it, and not
- when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(netlock);
-
-AST_MUTEX_DEFINE_STATIC(monlock);
-
-/* This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
-
-static int restart_monitor(void);
-
-static int capability = AST_FORMAT_ULAW;
-static int nonCodecCapability = AST_RTP_DTMF;
-
-static char ourhost[MAXHOSTNAMELEN];
-static struct in_addr __ourip;
-static int ourport;
-
-static int mgcpdebug = 0;
-
-static struct sched_context *sched;
-static struct io_context *io;
-/* The private structures of the mgcp channels are linked for
- selecting outgoing channels */
-
-#define MGCP_MAX_HEADERS 64
-#define MGCP_MAX_LINES 64
-
-struct mgcp_request {
- int len;
- char *verb;
- char *identifier;
- char *endpoint;
- char *version;
- int headers; /* MGCP Headers */
- char *header[MGCP_MAX_HEADERS];
- int lines; /* SDP Content */
- char *line[MGCP_MAX_LINES];
- char data[MGCP_MAX_PACKET];
- int cmd; /* SC: int version of verb = command */
- unsigned int trid; /* SC: int version of identifier = transaction id */
- struct mgcp_request *next; /* SC: next in the queue */
-};
-
-/* SC: obsolete
-static struct mgcp_pkt {
- int retrans;
- struct mgcp_endpoint *owner;
- int packetlen;
- char data[MGCP_MAX_PACKET];
- struct mgcp_pkt *next;
-} *packets = NULL;
-*/
-
-/* MGCP message for queuing up */
-struct mgcp_message {
- struct mgcp_endpoint *owner_ep;
- struct mgcp_subchannel *owner_sub;
- int retrans;
- unsigned long expire;
- unsigned int seqno;
- int len;
- struct mgcp_message *next;
- char buf[0];
-};
-
-#define RESPONSE_TIMEOUT 30 /* in seconds */
-
-struct mgcp_response {
- time_t whensent;
- int len;
- int seqno;
- struct mgcp_response *next;
- char buf[0];
-};
-
-#define MAX_SUBS 2
-
-#define SUB_REAL 0
-#define SUB_ALT 1
-
-struct mgcp_subchannel {
- /* SC: subchannel magic string.
- Needed to prove that any subchannel pointer passed by asterisk
- really points to a valid subchannel memory area.
- Ugly.. But serves the purpose for the time being.
- */
-#define MGCP_SUBCHANNEL_MAGIC "!978!"
- char magic[6];
- ast_mutex_t lock;
- int id;
- struct ast_channel *owner;
- struct mgcp_endpoint *parent;
- struct ast_rtp *rtp;
- struct sockaddr_in tmpdest;
- char txident[80]; /* FIXME SC: txident is replaced by rqnt_ident in endpoint.
- This should be obsoleted */
- char cxident[80];
- char callid[80];
-/* SC: obsolete
- time_t lastouttime;
- int lastout;
-*/
- int cxmode;
- struct mgcp_request *cx_queue; /* SC: pending CX commands */
- ast_mutex_t cx_queue_lock; /* SC: CX queue lock */
- int nat;
- int iseq; /* Not used? RTP? */
- int outgoing;
- int alreadygone;
-/* SC: obsolete
- int messagepending;
- struct mgcp_message *msgs;
-*/
- struct mgcp_subchannel *next; /* for out circular linked list */
-};
-
-#define MGCP_ONHOOK 1
-#define MGCP_OFFHOOK 2
-
-#define TYPE_TRUNK 1
-#define TYPE_LINE 2
-
-struct mgcp_endpoint {
- ast_mutex_t lock;
- char name[80];
- struct mgcp_subchannel *sub; /* pointer to our current connection, channel and stuff */
- char accountcode[AST_MAX_ACCOUNT_CODE];
- char exten[AST_MAX_EXTENSION]; /* Extention where to start */
- char context[AST_MAX_EXTENSION];
- char language[MAX_LANGUAGE];
- char cid_num[AST_MAX_EXTENSION]; /* Caller*ID */
- char cid_name[AST_MAX_EXTENSION]; /* Caller*ID */
- char lastcallerid[AST_MAX_EXTENSION]; /* Last Caller*ID */
- char call_forward[AST_MAX_EXTENSION]; /* Last Caller*ID */
- char mailbox[AST_MAX_EXTENSION];
- char musicclass[MAX_MUSICCLASS];
- char curtone[80]; /* Current tone */
- ast_group_t callgroup;
- ast_group_t pickupgroup;
- int callwaiting;
- int hascallwaiting;
- int transfer;
- int threewaycalling;
- int singlepath;
- int cancallforward;
- int canreinvite;
- int callreturn;
- int dnd; /* How does this affect callwait? Do we just deny a mgcp_request if we're dnd? */
- int hascallerid;
- int hidecallerid;
- int dtmfmode;
- int amaflags;
- int type;
- int slowsequence; /* MS: Sequence the endpoint as a whole */
- int group;
- int iseq; /* Not used? */
- int lastout; /* tracking this on the subchannels. Is it needed here? */
- int needdestroy; /* Not used? */
- int capability;
- int nonCodecCapability;
- int onhooktime;
- int msgstate; /* voicemail message state */
- int immediate;
- int hookstate;
- int adsi;
- char rqnt_ident[80]; /* SC: request identifier */
- struct mgcp_request *rqnt_queue; /* SC: pending RQNT commands */
- ast_mutex_t rqnt_queue_lock;
- struct mgcp_request *cmd_queue; /* SC: pending commands other than RQNT */
- ast_mutex_t cmd_queue_lock;
- int delme; /* SC: needed for reload */
- int needaudit; /* SC: needed for reload */
- struct ast_dsp *dsp; /* XXX Should there be a dsp/subchannel? XXX */
- /* owner is tracked on the subchannels, and the *sub indicates whos in charge */
- /* struct ast_channel *owner; */
- /* struct ast_rtp *rtp; */
- /* struct sockaddr_in tmpdest; */
- /* message go the the endpoint and not the channel so they stay here */
- struct mgcp_endpoint *next;
- struct mgcp_gateway *parent;
-};
-
-static struct mgcp_gateway {
- /* A gateway containing one or more endpoints */
- char name[80];
- int isnamedottedip; /* SC: is the name FQDN or dotted ip */
- struct sockaddr_in addr;
- struct sockaddr_in defaddr;
- struct in_addr ourip;
- int dynamic;
- int expire; /* XXX Should we ever expire dynamic registrations? XXX */
- struct mgcp_endpoint *endpoints;
- struct ast_ha *ha;
-/* SC: obsolete
- time_t lastouttime;
- int lastout;
- int messagepending;
-*/
-/* JS: Wildcard endpoint name */
- char wcardep[30];
- struct mgcp_message *msgs; /* SC: gw msg queue */
- ast_mutex_t msgs_lock; /* SC: queue lock */
- int retransid; /* SC: retrans timer id */
- int delme; /* SC: needed for reload */
- struct mgcp_response *responses;
- struct mgcp_gateway *next;
-} *gateways;
-
-AST_MUTEX_DEFINE_STATIC(mgcp_reload_lock);
-static int mgcp_reloading = 0;
-
-AST_MUTEX_DEFINE_STATIC(gatelock);
-
-static int mgcpsock = -1;
-
-static struct sockaddr_in bindaddr;
-
-static struct ast_frame *mgcp_read(struct ast_channel *ast);
-static int transmit_response(struct mgcp_subchannel *sub, char *msg, struct mgcp_request *req, char *msgrest);
-static int transmit_notify_request(struct mgcp_subchannel *sub, char *tone);
-static int transmit_modify_request(struct mgcp_subchannel *sub);
-static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callernum, char *callername);
-static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp, int codecs);
-static int transmit_connection_del(struct mgcp_subchannel *sub);
-static int transmit_audit_endpoint(struct mgcp_endpoint *p);
-static void start_rtp(struct mgcp_subchannel *sub);
-static void handle_response(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
- int result, unsigned int ident, struct mgcp_request *resp);
-static void dump_cmd_queues(struct mgcp_endpoint *p, struct mgcp_subchannel *sub);
-static int mgcp_do_reload(void);
-static int mgcp_reload(int fd, int argc, char *argv[]);
-
-static struct ast_channel *mgcp_request(const char *type, int format, void *data, int *cause);
-static int mgcp_call(struct ast_channel *ast, char *dest, int timeout);
-static int mgcp_hangup(struct ast_channel *ast);
-static int mgcp_answer(struct ast_channel *ast);
-static struct ast_frame *mgcp_read(struct ast_channel *ast);
-static int mgcp_write(struct ast_channel *ast, struct ast_frame *frame);
-static int mgcp_indicate(struct ast_channel *ast, int ind);
-static int mgcp_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-static int mgcp_senddigit(struct ast_channel *ast, char digit);
-
-static const struct ast_channel_tech mgcp_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_ULAW,
- .properties = AST_CHAN_TP_WANTSJITTER,
- .requester = mgcp_request,
- .call = mgcp_call,
- .hangup = mgcp_hangup,
- .answer = mgcp_answer,
- .read = mgcp_read,
- .write = mgcp_write,
- .indicate = mgcp_indicate,
- .fixup = mgcp_fixup,
- .send_digit = mgcp_senddigit,
- .bridge = ast_rtp_bridge,
-};
-
-static int has_voicemail(struct mgcp_endpoint *p)
-{
- return ast_app_has_voicemail(p->mailbox, NULL);
-}
-
-static int unalloc_sub(struct mgcp_subchannel *sub)
-{
- struct mgcp_endpoint *p = sub->parent;
- if (p->sub == sub) {
- ast_log(LOG_WARNING, "Trying to unalloc the real channel %s@%s?!?\n", p->name, p->parent->name);
- return -1;
- }
- ast_log(LOG_DEBUG, "Released sub %d of channel %s@%s\n", sub->id, p->name, p->parent->name);
-
- sub->owner = NULL;
- if (!ast_strlen_zero(sub->cxident)) {
- transmit_connection_del(sub);
- }
- sub->cxident[0] = '\0';
- sub->callid[0] = '\0';
- sub->cxmode = MGCP_CX_INACTIVE;
- sub->outgoing = 0;
- sub->alreadygone = 0;
- memset(&sub->tmpdest, 0, sizeof(sub->tmpdest));
- if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
- sub->rtp = NULL;
- }
- dump_cmd_queues(NULL, sub); /* SC */
- return 0;
-}
-
-/* SC: modified for new transport mechanism */
-static int __mgcp_xmit(struct mgcp_gateway *gw, char *data, int len)
-{
- int res;
- if (gw->addr.sin_addr.s_addr)
- res=sendto(mgcpsock, data, len, 0, (struct sockaddr *)&gw->addr, sizeof(struct sockaddr_in));
- else
- res=sendto(mgcpsock, data, len, 0, (struct sockaddr *)&gw->defaddr, sizeof(struct sockaddr_in));
- if (res != len) {
- ast_log(LOG_WARNING, "mgcp_xmit returned %d: %s\n", res, strerror(errno));
- }
- return res;
-}
-
-static int resend_response(struct mgcp_subchannel *sub, struct mgcp_response *resp)
-{
- struct mgcp_endpoint *p = sub->parent;
- int res;
- char iabuf[INET_ADDRSTRLEN];
- if (mgcpdebug) {
- ast_verbose("Retransmitting:\n%s\n to %s:%d\n", resp->buf, ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
- }
- res = __mgcp_xmit(p->parent, resp->buf, resp->len);
- if (res > 0)
- res = 0;
- return res;
-}
-
-static int send_response(struct mgcp_subchannel *sub, struct mgcp_request *req)
-{
- struct mgcp_endpoint *p = sub->parent;
- int res;
- char iabuf[INET_ADDRSTRLEN];
- if (mgcpdebug) {
- ast_verbose("Transmitting:\n%s\n to %s:%d\n", req->data, ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
- }
- res = __mgcp_xmit(p->parent, req->data, req->len);
- if (res > 0)
- res = 0;
- return res;
-}
-
-/* SC: modified for new transport framework */
-static void dump_queue(struct mgcp_gateway *gw, struct mgcp_endpoint *p)
-{
- struct mgcp_message *cur, *q = NULL, *w, *prev;
-
- ast_mutex_lock(&gw->msgs_lock);
- prev = NULL, cur = gw->msgs;
- while (cur) {
- if (!p || cur->owner_ep == p) {
- if (prev)
- prev->next = cur->next;
- else
- gw->msgs = cur->next;
-
- ast_log(LOG_NOTICE, "Removing message from %s transaction %u\n",
- gw->name, cur->seqno);
-
- w = cur;
- cur = cur->next;
- if (q) {
- w->next = q;
- } else {
- w->next = NULL;
- }
- q = w;
- } else {
- prev = cur, cur=cur->next;
- }
- }
- ast_mutex_unlock(&gw->msgs_lock);
-
- while (q) {
- cur = q;
- q = q->next;
- free(cur);
- }
-}
-
-static void mgcp_queue_frame(struct mgcp_subchannel *sub, struct ast_frame *f)
-{
- for(;;) {
- if (sub->owner) {
- if (!ast_mutex_trylock(&sub->owner->lock)) {
- ast_queue_frame(sub->owner, f);
- ast_mutex_unlock(&sub->owner->lock);
- break;
- } else {
- ast_mutex_unlock(&sub->lock);
- usleep(1);
- ast_mutex_lock(&sub->lock);
- }
- } else
- break;
- }
-}
-
-static void mgcp_queue_hangup(struct mgcp_subchannel *sub)
-{
- for(;;) {
- if (sub->owner) {
- if (!ast_mutex_trylock(&sub->owner->lock)) {
- ast_queue_hangup(sub->owner);
- ast_mutex_unlock(&sub->owner->lock);
- break;
- } else {
- ast_mutex_unlock(&sub->lock);
- usleep(1);
- ast_mutex_lock(&sub->lock);
- }
- } else
- break;
- }
-}
-
-static void mgcp_queue_control(struct mgcp_subchannel *sub, int control)
-{
- struct ast_frame f = { AST_FRAME_CONTROL, };
- f.subclass = control;
- return mgcp_queue_frame(sub, &f);
-}
-
-static int retrans_pkt(void *data)
-{
- struct mgcp_gateway *gw = (struct mgcp_gateway *)data;
- struct mgcp_message *cur, *exq = NULL, *w, *prev;
- int res = 0;
-
- /* find out expired msgs */
- ast_mutex_lock(&gw->msgs_lock);
-
- prev = NULL, cur = gw->msgs;
- while (cur) {
- if (cur->retrans < MAX_RETRANS) {
- cur->retrans++;
- if (mgcpdebug) {
- ast_verbose("Retransmitting #%d transaction %u on [%s]\n",
- cur->retrans, cur->seqno, gw->name);
- }
- __mgcp_xmit(gw, cur->buf, cur->len);
-
- prev = cur;
- cur = cur->next;
- } else {
- if (prev)
- prev->next = cur->next;
- else
- gw->msgs = cur->next;
-
- ast_log(LOG_WARNING, "Maximum retries exceeded for transaction %u on [%s]\n",
- cur->seqno, gw->name);
-
- w = cur;
- cur = cur->next;
-
- if (exq) {
- w->next = exq;
- } else {
- w->next = NULL;
- }
- exq = w;
- }
- }
-
- if (!gw->msgs) {
- gw->retransid = -1;
- res = 0;
- } else {
- res = 1;
- }
- ast_mutex_unlock(&gw->msgs_lock);
-
- while (exq) {
- cur = exq;
- /* time-out transaction */
- handle_response(cur->owner_ep, cur->owner_sub, 406, cur->seqno, NULL);
- exq = exq->next;
- free(cur);
- }
-
- return res;
-}
-
-/* SC: modified for the new transaction mechanism */
-static int mgcp_postrequest(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
- char *data, int len, unsigned int seqno)
-{
- struct mgcp_message *msg = malloc(sizeof(struct mgcp_message) + len);
- struct mgcp_message *cur;
- struct mgcp_gateway *gw = ((p && p->parent) ? p->parent : NULL);
- struct timeval tv;
-
- if (!msg) {
- return -1;
- }
- if (!gw) {
- return -1;
- }
-/* SC
- time(&t);
- if (gw->messagepending && (gw->lastouttime + 20 < t)) {
- ast_log(LOG_NOTICE, "Timeout waiting for response to message:%d, lastouttime: %ld, now: %ld. Dumping pending queue\n",
- gw->msgs ? gw->msgs->seqno : -1, (long) gw->lastouttime, (long) t);
- dump_queue(sub->parent);
- }
-*/
- msg->owner_sub = sub;
- msg->owner_ep = p;
- msg->seqno = seqno;
- msg->next = NULL;
- msg->len = len;
- msg->retrans = 0;
- memcpy(msg->buf, data, msg->len);
-
- ast_mutex_lock(&gw->msgs_lock);
- cur = gw->msgs;
- if (cur) {
- while(cur->next)
- cur = cur->next;
- cur->next = msg;
- } else {
- gw->msgs = msg;
- }
-
- if (gettimeofday(&tv, NULL) < 0) {
- /* This shouldn't ever happen, but let's be sure */
- ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
- } else {
- msg->expire = tv.tv_sec * 1000 + tv.tv_usec / 1000 + DEFAULT_RETRANS;
-
- if (gw->retransid == -1)
- gw->retransid = ast_sched_add(sched, DEFAULT_RETRANS, retrans_pkt, (void *)gw);
- }
- ast_mutex_unlock(&gw->msgs_lock);
-/* SC
- if (!gw->messagepending) {
- gw->messagepending = 1;
- gw->lastout = seqno;
- gw->lastouttime = t;
-*/
- __mgcp_xmit(gw, msg->buf, msg->len);
- /* XXX Should schedule retransmission XXX */
-/* SC
- } else
- ast_log(LOG_DEBUG, "Deferring transmission of transaction %d\n", seqno);
-*/
- return 0;
-}
-
-/* SC: modified for new transport */
-static int send_request(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
- struct mgcp_request *req, unsigned int seqno)
-{
- int res = 0;
- struct mgcp_request **queue, *q, *r, *t;
- char iabuf[INET_ADDRSTRLEN];
- ast_mutex_t *l;
-
- ast_log(LOG_DEBUG, "Slow sequence is %d\n", p->slowsequence);
- if (p->slowsequence) {
- queue = &p->cmd_queue;
- l = &p->cmd_queue_lock;
- ast_mutex_lock(l);
- } else {
- switch (req->cmd) {
- case MGCP_CMD_DLCX:
- queue = &sub->cx_queue;
- l = &sub->cx_queue_lock;
- ast_mutex_lock(l);
- q = sub->cx_queue;
- /* delete pending cx cmds */
- while (q) {
- r = q->next;
- free(q);
- q = r;
- }
- *queue = NULL;
- break;
-
- case MGCP_CMD_CRCX:
- case MGCP_CMD_MDCX:
- queue = &sub->cx_queue;
- l = &sub->cx_queue_lock;
- ast_mutex_lock(l);
- break;
-
- case MGCP_CMD_RQNT:
- queue = &p->rqnt_queue;
- l = &p->rqnt_queue_lock;
- ast_mutex_lock(l);
- break;
-
- default:
- queue = &p->cmd_queue;
- l = &p->cmd_queue_lock;
- ast_mutex_lock(l);
- break;
- }
- }
-
- r = (struct mgcp_request *) malloc (sizeof(struct mgcp_request));
- if (!r) {
- ast_log(LOG_WARNING, "Cannot post MGCP request: insufficient memory\n");
- ast_mutex_unlock(l);
- return -1;
- }
- memcpy(r, req, sizeof(struct mgcp_request));
-
- if (!(*queue)) {
- if (mgcpdebug) {
- ast_verbose("Posting Request:\n%s to %s:%d\n", req->data,
- ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
- }
-
- res = mgcp_postrequest(p, sub, req->data, req->len, seqno);
- } else {
- if (mgcpdebug) {
- ast_verbose("Queueing Request:\n%s to %s:%d\n", req->data,
- ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
- }
- }
-
- /* XXX SC: find tail. We could also keep tail in the data struct for faster access */
- for (t = *queue; t && t->next; t = t->next);
-
- r->next = NULL;
- if (t)
- t->next = r;
- else
- *queue = r;
-
- ast_mutex_unlock(l);
-
- return res;
-}
-
-static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
-{
- int res;
- struct mgcp_endpoint *p;
- struct mgcp_subchannel *sub;
- char tone[50] = "";
- char *distinctive_ring = NULL;
- struct varshead *headp;
- struct ast_var_t *current;
-
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_call(%s)\n", ast->name);
- }
- sub = ast->tech_pvt;
- p = sub->parent;
- headp = &ast->varshead;
- AST_LIST_TRAVERSE(headp,current,entries) {
- /* Check whether there is an ALERT_INFO variable */
- if (strcasecmp(ast_var_name(current),"ALERT_INFO") == 0) {
- distinctive_ring = ast_var_value(current);
- }
- }
-
- ast_mutex_lock(&sub->lock);
- switch (p->hookstate) {
- case MGCP_OFFHOOK:
- if (!ast_strlen_zero(distinctive_ring)) {
- snprintf(tone, sizeof(tone), "L/wt%s", distinctive_ring);
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP distinctive callwait %s\n", tone);
- }
- } else {
- snprintf(tone, sizeof(tone), "L/wt");
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP normal callwait %s\n", tone);
- }
- }
- break;
- case MGCP_ONHOOK:
- default:
- if (!ast_strlen_zero(distinctive_ring)) {
- snprintf(tone, sizeof(tone), "L/r%s", distinctive_ring);
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP distinctive ring %s\n", tone);
- }
- } else {
- snprintf(tone, sizeof(tone), "L/rg");
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP default ring\n");
- }
- }
- break;
- }
-
- if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "mgcp_call called on %s, neither down nor reserved\n", ast->name);
- ast_mutex_unlock(&sub->lock);
- return -1;
- }
-
- res = 0;
- sub->outgoing = 1;
- sub->cxmode = MGCP_CX_RECVONLY;
- if (p->type == TYPE_LINE) {
- if (!sub->rtp) {
- start_rtp(sub);
- } else {
- transmit_modify_request(sub);
- }
-
- if (sub->next->owner && !ast_strlen_zero(sub->next->cxident) && !ast_strlen_zero(sub->next->callid)) {
- /* try to prevent a callwait from disturbing the other connection */
- sub->next->cxmode = MGCP_CX_RECVONLY;
- transmit_modify_request(sub->next);
- }
-
- transmit_notify_request_with_callerid(sub, tone, ast->cid.cid_num, ast->cid.cid_name);
- ast_setstate(ast, AST_STATE_RINGING);
-
- if (sub->next->owner && !ast_strlen_zero(sub->next->cxident) && !ast_strlen_zero(sub->next->callid)) {
- /* Put the connection back in sendrecv */
- sub->next->cxmode = MGCP_CX_SENDRECV;
- transmit_modify_request(sub->next);
- }
- } else {
- ast_log(LOG_NOTICE, "Don't know how to dial on trunks yet\n");
- res = -1;
- }
- ast_mutex_unlock(&sub->lock);
- ast_queue_control(ast, AST_CONTROL_RINGING);
- return res;
-}
-
-static int mgcp_hangup(struct ast_channel *ast)
-{
- struct mgcp_subchannel *sub = ast->tech_pvt;
- struct mgcp_endpoint *p = sub->parent;
-
- if (option_debug) {
- ast_log(LOG_DEBUG, "mgcp_hangup(%s)\n", ast->name);
- }
- if (!ast->tech_pvt) {
- ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n");
- return 0;
- }
- if (strcmp(sub->magic, MGCP_SUBCHANNEL_MAGIC)) {
- ast_log(LOG_DEBUG, "Invalid magic. MGCP subchannel freed up already.\n");
- return 0;
- }
- ast_mutex_lock(&sub->lock);
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_hangup(%s) on %s@%s\n", ast->name, p->name, p->parent->name);
- }
-
- if ((p->dtmfmode & MGCP_DTMF_INBAND) && p->dsp) {
- /* SC: check whether other channel is active. */
- if (!sub->next->owner) {
- if (p->dtmfmode & MGCP_DTMF_HYBRID)
- p->dtmfmode &= ~MGCP_DTMF_INBAND;
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_2 "MGCP free dsp on %s@%s\n", p->name, p->parent->name);
- }
- ast_dsp_free(p->dsp);
- p->dsp = NULL;
- }
- }
-
- sub->owner = NULL;
- if (!ast_strlen_zero(sub->cxident)) {
- transmit_connection_del(sub);
- }
- sub->cxident[0] = '\0';
- if ((sub == p->sub) && sub->next->owner) {
- if (p->hookstate == MGCP_OFFHOOK) {
- if (sub->next->owner && ast_bridged_channel(sub->next->owner)) {
- transmit_notify_request_with_callerid(p->sub, "L/wt", ast_bridged_channel(sub->next->owner)->cid.cid_num, ast_bridged_channel(sub->next->owner)->cid.cid_name);
- }
- } else {
- /* set our other connection as the primary and swith over to it */
- p->sub = sub->next;
- p->sub->cxmode = MGCP_CX_RECVONLY;
- transmit_modify_request(p->sub);
- if (sub->next->owner && ast_bridged_channel(sub->next->owner)) {
- transmit_notify_request_with_callerid(p->sub, "L/rg", ast_bridged_channel(sub->next->owner)->cid.cid_num, ast_bridged_channel(sub->next->owner)->cid.cid_name);
- }
- }
-
- } else if ((sub == p->sub->next) && p->hookstate == MGCP_OFFHOOK) {
- transmit_notify_request(sub, "L/v");
- } else if (p->hookstate == MGCP_OFFHOOK) {
- transmit_notify_request(sub, "L/ro");
- } else {
- transmit_notify_request(sub, "");
- }
-
- ast->tech_pvt = NULL;
- sub->alreadygone = 0;
- sub->outgoing = 0;
- sub->cxmode = MGCP_CX_INACTIVE;
- sub->callid[0] = '\0';
- /* Reset temporary destination */
- memset(&sub->tmpdest, 0, sizeof(sub->tmpdest));
- if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
- sub->rtp = NULL;
- }
-
- /* SC: Decrement use count */
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- /* SC: Decrement use count */
-
- if ((p->hookstate == MGCP_ONHOOK) && (!sub->next->rtp)) {
- p->hidecallerid = 0;
- if (p->hascallwaiting && !p->callwaiting) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Enabling call waiting on %s\n", ast->name);
- p->callwaiting = -1;
- }
- if (has_voicemail(p)) {
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_hangup(%s) on %s@%s set vmwi(+)\n",
- ast->name, p->name, p->parent->name);
- }
- transmit_notify_request(sub, "L/vmwi(+)");
- } else {
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_hangup(%s) on %s@%s set vmwi(-)\n",
- ast->name, p->name, p->parent->name);
- }
- transmit_notify_request(sub, "L/vmwi(-)");
- }
- }
- ast_mutex_unlock(&sub->lock);
- return 0;
-}
-
-static int mgcp_show_endpoints(int fd, int argc, char *argv[])
-{
- struct mgcp_gateway *g;
- struct mgcp_endpoint *e;
- int hasendpoints = 0;
- char iabuf[INET_ADDRSTRLEN];
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&gatelock);
- g = gateways;
- while(g) {
- e = g->endpoints;
- ast_cli(fd, "Gateway '%s' at %s (%s)\n", g->name, g->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), g->addr.sin_addr) : ast_inet_ntoa(iabuf, sizeof(iabuf), g->defaddr.sin_addr), g->dynamic ? "Dynamic" : "Static");
- while(e) {
- /* JS: Don't show wilcard endpoint */
- if (strcmp(e->name, g->wcardep) !=0)
- ast_cli(fd, " -- '%s@%s in '%s' is %s\n", e->name, g->name, e->context, e->sub->owner ? "active" : "idle");
- hasendpoints = 1;
- e = e->next;
- }
- if (!hasendpoints) {
- ast_cli(fd, " << No Endpoints Defined >> ");
- }
- g = g->next;
- }
- ast_mutex_unlock(&gatelock);
- return RESULT_SUCCESS;
-}
-
-static char show_endpoints_usage[] =
-"Usage: mgcp show endpoints\n"
-" Lists all endpoints known to the MGCP (Media Gateway Control Protocol) subsystem.\n";
-
-static struct ast_cli_entry cli_show_endpoints =
- { { "mgcp", "show", "endpoints", NULL }, mgcp_show_endpoints, "Show defined MGCP endpoints", show_endpoints_usage };
-
-static int mgcp_audit_endpoint(int fd, int argc, char *argv[])
-{
- struct mgcp_gateway *g;
- struct mgcp_endpoint *e;
- int found = 0;
- char *ename,*gname, *c;
-
- if (!mgcpdebug) {
- return RESULT_SHOWUSAGE;
- }
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- /* split the name into parts by null */
- ename = argv[3];
- gname = ename;
- while (*gname) {
- if (*gname == '@') {
- *gname = 0;
- gname++;
- break;
- }
- gname++;
- }
- if (gname[0] == '[')
- gname++;
- if ((c = strrchr(gname, ']')))
- *c = '\0';
- ast_mutex_lock(&gatelock);
- g = gateways;
- while(g) {
- if (!strcasecmp(g->name, gname)) {
- e = g->endpoints;
- while(e) {
- if (!strcasecmp(e->name, ename)) {
- found = 1;
- transmit_audit_endpoint(e);
- break;
- }
- e = e->next;
- }
- if (found) {
- break;
- }
- }
- g = g->next;
- }
- if (!found) {
- ast_cli(fd, " << Could not find endpoint >> ");
- }
- ast_mutex_unlock(&gatelock);
- return RESULT_SUCCESS;
-}
-
-static char audit_endpoint_usage[] =
-"Usage: mgcp audit endpoint <endpointid>\n"
-" Lists the capabilities of an endpoint in the MGCP (Media Gateway Control Protocol) subsystem.\n"
-" mgcp debug MUST be on to see the results of this command.\n";
-
-static struct ast_cli_entry cli_audit_endpoint =
- { { "mgcp", "audit", "endpoint", NULL }, mgcp_audit_endpoint, "Audit specified MGCP endpoint", audit_endpoint_usage };
-
-static int mgcp_answer(struct ast_channel *ast)
-{
- int res = 0;
- struct mgcp_subchannel *sub = ast->tech_pvt;
- struct mgcp_endpoint *p = sub->parent;
-
- ast_mutex_lock(&sub->lock);
- sub->cxmode = MGCP_CX_SENDRECV;
- if (!sub->rtp) {
- start_rtp(sub);
- } else {
- transmit_modify_request(sub);
- }
- /* SC: verbose level check */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_answer(%s) on %s@%s-%d\n",
- ast->name, p->name, p->parent->name, sub->id);
- }
- if (ast->_state != AST_STATE_UP) {
- ast_setstate(ast, AST_STATE_UP);
- if (option_debug)
- ast_log(LOG_DEBUG, "mgcp_answer(%s)\n", ast->name);
- transmit_notify_request(sub, "");
- transmit_modify_request(sub);
- }
- ast_mutex_unlock(&sub->lock);
- return res;
-}
-
-static struct ast_frame *mgcp_rtp_read(struct mgcp_subchannel *sub)
-{
- /* Retrieve audio/etc from channel. Assumes sub->lock is already held. */
- struct ast_frame *f;
- static struct ast_frame null_frame = { AST_FRAME_NULL, };
-
- f = ast_rtp_read(sub->rtp);
- /* Don't send RFC2833 if we're not supposed to */
- if (f && (f->frametype == AST_FRAME_DTMF) && !(sub->parent->dtmfmode & MGCP_DTMF_RFC2833))
- return &null_frame;
- if (sub->owner) {
- /* We already hold the channel lock */
- if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass != sub->owner->nativeformats) {
- ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
- sub->owner->nativeformats = f->subclass;
- ast_set_read_format(sub->owner, sub->owner->readformat);
- ast_set_write_format(sub->owner, sub->owner->writeformat);
- }
- /* Courtesy fearnor aka alex@pilosoft.com */
- if ((sub->parent->dtmfmode & MGCP_DTMF_INBAND) && (sub->parent->dsp)) {
-#if 0
- ast_log(LOG_NOTICE, "MGCP ast_dsp_process\n");
-#endif
- f = ast_dsp_process(sub->owner, sub->parent->dsp, f);
- }
- }
- }
- return f;
-}
-
-
-static struct ast_frame *mgcp_read(struct ast_channel *ast)
-{
- struct ast_frame *f;
- struct mgcp_subchannel *sub = ast->tech_pvt;
- ast_mutex_lock(&sub->lock);
- f = mgcp_rtp_read(sub);
- ast_mutex_unlock(&sub->lock);
- return f;
-}
-
-static int mgcp_write(struct ast_channel *ast, struct ast_frame *frame)
-{
- struct mgcp_subchannel *sub = ast->tech_pvt;
- int res = 0;
- if (frame->frametype != AST_FRAME_VOICE) {
- if (frame->frametype == AST_FRAME_IMAGE)
- return 0;
- else {
- ast_log(LOG_WARNING, "Can't send %d type frames with MGCP write\n", frame->frametype);
- return 0;
- }
- } else {
- if (!(frame->subclass & ast->nativeformats)) {
- ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
- frame->subclass, ast->nativeformats, ast->readformat, ast->writeformat);
- return -1;
- }
- }
- if (sub) {
- ast_mutex_lock(&sub->lock);
- if ((sub->parent->sub == sub) || !sub->parent->singlepath) {
- if (sub->rtp) {
- res = ast_rtp_write(sub->rtp, frame);
- }
- }
- ast_mutex_unlock(&sub->lock);
- }
- return res;
-}
-
-static int mgcp_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct mgcp_subchannel *sub = newchan->tech_pvt;
-
- ast_mutex_lock(&sub->lock);
- ast_log(LOG_NOTICE, "mgcp_fixup(%s, %s)\n", oldchan->name, newchan->name);
- if (sub->owner != oldchan) {
- ast_mutex_unlock(&sub->lock);
- ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, sub->owner);
- return -1;
- }
- sub->owner = newchan;
- ast_mutex_unlock(&sub->lock);
- return 0;
-}
-
-static int mgcp_senddigit(struct ast_channel *ast, char digit)
-{
- struct mgcp_subchannel *sub = ast->tech_pvt;
- char tmp[4];
-
- tmp[0] = 'D';
- tmp[1] = '/';
- tmp[2] = digit;
- tmp[3] = '\0';
- ast_mutex_lock(&sub->lock);
- transmit_notify_request(sub, tmp);
- ast_mutex_unlock(&sub->lock);
- return -1;
-}
-
-static char *control2str(int ind) {
- switch (ind) {
- case AST_CONTROL_HANGUP:
- return "Other end has hungup";
- case AST_CONTROL_RING:
- return "Local ring";
- case AST_CONTROL_RINGING:
- return "Remote end is ringing";
- case AST_CONTROL_ANSWER:
- return "Remote end has answered";
- case AST_CONTROL_BUSY:
- return "Remote end is busy";
- case AST_CONTROL_TAKEOFFHOOK:
- return "Make it go off hook";
- case AST_CONTROL_OFFHOOK:
- return "Line is off hook";
- case AST_CONTROL_CONGESTION:
- return "Congestion (circuits busy)";
- case AST_CONTROL_FLASH:
- return "Flash hook";
- case AST_CONTROL_WINK:
- return "Wink";
- case AST_CONTROL_OPTION:
- return "Set a low-level option";
- case AST_CONTROL_RADIO_KEY:
- return "Key Radio";
- case AST_CONTROL_RADIO_UNKEY:
- return "Un-Key Radio";
- }
- return "UNKNOWN";
-}
-
-static int mgcp_indicate(struct ast_channel *ast, int ind)
-{
- struct mgcp_subchannel *sub = ast->tech_pvt;
- int res = 0;
-
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP asked to indicate %d '%s' condition on channel %s\n",
- ind, control2str(ind), ast->name);
- }
- ast_mutex_lock(&sub->lock);
- switch(ind) {
- case AST_CONTROL_RINGING:
-#ifdef DLINK_BUGGY_FIRMWARE
- transmit_notify_request(sub, "rt");
-#else
- transmit_notify_request(sub, "G/rt");
-#endif
- break;
- case AST_CONTROL_BUSY:
- transmit_notify_request(sub, "L/bz");
- break;
- case AST_CONTROL_CONGESTION:
- transmit_notify_request(sub, "G/cg");
- break;
- case -1:
- transmit_notify_request(sub, "");
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", ind);
- res = -1;
- }
- ast_mutex_unlock(&sub->lock);
- return res;
-}
-
-static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state)
-{
- struct ast_channel *tmp;
- struct mgcp_endpoint *i = sub->parent;
- int fmt;
-
- tmp = ast_channel_alloc(1);
- if (tmp) {
- tmp->tech = &mgcp_tech;
- tmp->nativeformats = i->capability;
- if (!tmp->nativeformats)
- tmp->nativeformats = capability;
- fmt = ast_best_codec(tmp->nativeformats);
- snprintf(tmp->name, sizeof(tmp->name), "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id);
- if (sub->rtp)
- tmp->fds[0] = ast_rtp_fd(sub->rtp);
- tmp->type = type;
- if (i->dtmfmode & (MGCP_DTMF_INBAND | MGCP_DTMF_HYBRID)) {
- i->dsp = ast_dsp_new();
- ast_dsp_set_features(i->dsp,DSP_FEATURE_DTMF_DETECT);
- /* SC: this is to prevent clipping of dtmf tones during dsp processing */
- ast_dsp_digitmode(i->dsp, DSP_DIGITMODE_NOQUELCH);
- } else {
- i->dsp = NULL;
- }
- ast_setstate(tmp, state);
- if (state == AST_STATE_RING)
- tmp->rings = 1;
- tmp->writeformat = fmt;
- tmp->rawwriteformat = fmt;
- tmp->readformat = fmt;
- tmp->rawreadformat = fmt;
- tmp->tech_pvt = sub;
- if (!ast_strlen_zero(i->language))
- strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
- if (!ast_strlen_zero(i->accountcode))
- strncpy(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode)-1);
- if (i->amaflags)
- tmp->amaflags = i->amaflags;
- sub->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- tmp->callgroup = i->callgroup;
- tmp->pickupgroup = i->pickupgroup;
- strncpy(tmp->call_forward, i->call_forward, sizeof(tmp->call_forward) - 1);
- strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
- strncpy(tmp->exten, i->exten, sizeof(tmp->exten)-1);
- if (!ast_strlen_zero(i->cid_num))
- tmp->cid.cid_num = strdup(i->cid_num);
- if (!ast_strlen_zero(i->cid_name))
- tmp->cid.cid_name = strdup(i->cid_name);
- if (!i->adsi)
- tmp->adsicpe = AST_ADSI_UNAVAILABLE;
- tmp->priority = 1;
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- tmp = NULL;
- }
- }
- /* SC: verbose level check */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_new(%s) created in state: %s\n",
- tmp->name, ast_state2str(state));
- }
- } else {
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- }
- return tmp;
-}
-
-static char* get_sdp_by_line(char* line, char *name, int nameLen)
-{
- if (strncasecmp(line, name, nameLen) == 0 && line[nameLen] == '=') {
- char* r = line + nameLen + 1;
- while (*r && (*r < 33)) ++r;
- return r;
- }
- return "";
-}
-
-static char *get_sdp(struct mgcp_request *req, char *name)
-{
- int x;
- int len = strlen(name);
- char *r;
-
- for (x=0; x<req->lines; x++) {
- r = get_sdp_by_line(req->line[x], name, len);
- if (r[0] != '\0') return r;
- }
- return "";
-}
-
-static void sdpLineNum_iterator_init(int* iterator)
-{
- *iterator = 0;
-}
-
-static char* get_sdp_iterate(int* iterator, struct mgcp_request *req, char *name)
-{
- int len = strlen(name);
- char *r;
- while (*iterator < req->lines) {
- r = get_sdp_by_line(req->line[(*iterator)++], name, len);
- if (r[0] != '\0') return r;
- }
- return "";
-}
-
-static char *__get_header(struct mgcp_request *req, char *name, int *start)
-{
- int x;
- int len = strlen(name);
- char *r;
- for (x=*start;x<req->headers;x++) {
- if (!strncasecmp(req->header[x], name, len) &&
- (req->header[x][len] == ':')) {
- r = req->header[x] + len + 1;
- while(*r && (*r < 33))
- r++;
- *start = x+1;
- return r;
- }
- }
- /* Don't return NULL, so get_header is always a valid pointer */
- return "";
-}
-
-static char *get_header(struct mgcp_request *req, char *name)
-{
- int start = 0;
- return __get_header(req, name, &start);
-}
-
-/* SC: get comma separated value */
-static char *get_csv(char *c, int *len, char **next)
-{
- char *s;
-
- *next = NULL, *len = 0;
- if (!c) return NULL;
-
- while (*c && (*c < 33 || *c == ','))
- c++;
-
- s = c;
- while (*c && (*c >= 33 && *c != ','))
- c++, (*len)++;
- *next = c;
-
- if (*len == 0)
- s = NULL, *next = NULL;
-
- return s;
-}
-
-static struct mgcp_subchannel *find_subchannel_and_lock(char *name, int msgid, struct sockaddr_in *sin)
-{
- struct mgcp_endpoint *p = NULL;
- struct mgcp_subchannel *sub = NULL;
- struct mgcp_gateway *g;
- char iabuf[INET_ADDRSTRLEN];
- char tmp[256] = "";
- char *at = NULL, *c;
- int found = 0;
- if (name) {
- strncpy(tmp, name, sizeof(tmp) - 1);
- at = strchr(tmp, '@');
- if (!at) {
- ast_log(LOG_NOTICE, "Endpoint '%s' has no at sign!\n", name);
- return NULL;
- }
- *at = '\0';
- at++;
- }
- ast_mutex_lock(&gatelock);
- if (at && (at[0] == '[')) {
- at++;
- c = strrchr(at, ']');
- if (c)
- *c = '\0';
- }
- g = gateways;
- while(g) {
- if ((!name || !strcasecmp(g->name, at)) &&
- (sin || g->addr.sin_addr.s_addr || g->defaddr.sin_addr.s_addr)) {
- /* Found the gateway. If it's dynamic, save it's address -- now for the endpoint */
- if (sin && g->dynamic && name) {
- if ((g->addr.sin_addr.s_addr != sin->sin_addr.s_addr) ||
- (g->addr.sin_port != sin->sin_port)) {
- memcpy(&g->addr, sin, sizeof(g->addr));
- if (ast_ouraddrfor(&g->addr.sin_addr, &g->ourip))
- memcpy(&g->ourip, &__ourip, sizeof(g->ourip));
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Registered MGCP gateway '%s' at %s port %d\n", g->name, ast_inet_ntoa(iabuf, sizeof(iabuf), g->addr.sin_addr), ntohs(g->addr.sin_port));
- }
- }
- /* SC: not dynamic, check if the name matches */
- else if (name) {
- if (strcasecmp(g->name, at)) {
- g = g->next;
- continue;
- }
- }
- /* SC: not dynamic, no name, check if the addr matches */
- else if (!name && sin) {
- if ((g->addr.sin_addr.s_addr != sin->sin_addr.s_addr) ||
- (g->addr.sin_port != sin->sin_port)) {
- g = g->next;
- continue;
- }
- } else {
- g = g->next;
- continue;
- }
- /* SC */
- p = g->endpoints;
- while(p) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Searching on %s@%s for subchannel\n",
- p->name, g->name);
- if (msgid) {
-#if 0 /* SC: new transport mech */
- sub = p->sub;
- do {
- if (option_debug)
- ast_log(LOG_DEBUG, "Searching on %s@%s-%d for subchannel with lastout: %d\n",
- p->name, g->name, sub->id, msgid);
- if (sub->lastout == msgid) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Found subchannel sub%d to handle request %d sub->lastout: %d\n",
- sub->id, msgid, sub->lastout);
- found = 1;
- break;
- }
- sub = sub->next;
- } while (sub != p->sub);
- if (found) {
- break;
- }
-#endif
- /* SC */
- sub = p->sub;
- found = 1;
- /* SC */
- break;
- } else if (name && !strcasecmp(p->name, tmp)) {
- ast_log(LOG_DEBUG, "Coundn't determine subchannel, assuming current master %s@%s-%d\n",
- p->name, g->name, p->sub->id);
- sub = p->sub;
- found = 1;
- break;
- }
- p = p->next;
- }
- if (sub && found) {
- ast_mutex_lock(&sub->lock);
- break;
- }
- }
- g = g->next;
- }
- ast_mutex_unlock(&gatelock);
- if (!sub) {
- if (name) {
- if (g)
- ast_log(LOG_NOTICE, "Endpoint '%s' not found on gateway '%s'\n", tmp, at);
- else
- ast_log(LOG_NOTICE, "Gateway '%s' (and thus its endpoint '%s') does not exist\n", at, tmp);
- }
- }
- return sub;
-}
-
-static void parse(struct mgcp_request *req)
-{
- /* Divide fields by NULL's */
- char *c;
- int f = 0;
- c = req->data;
-
- /* First header starts immediately */
- req->header[f] = c;
- while(*c) {
- if (*c == '\n') {
- /* We've got a new header */
- *c = 0;
-#if 0
- printf("Header: %s (%d)\n", req->header[f], strlen(req->header[f]));
-#endif
- if (ast_strlen_zero(req->header[f])) {
- /* Line by itself means we're now in content */
- c++;
- break;
- }
- if (f >= MGCP_MAX_HEADERS - 1) {
- ast_log(LOG_WARNING, "Too many MGCP headers...\n");
- } else
- f++;
- req->header[f] = c + 1;
- } else if (*c == '\r') {
- /* Ignore but eliminate \r's */
- *c = 0;
- }
- c++;
- }
- /* Check for last header */
- if (!ast_strlen_zero(req->header[f]))
- f++;
- req->headers = f;
- /* Now we process any mime content */
- f = 0;
- req->line[f] = c;
- while(*c) {
- if (*c == '\n') {
- /* We've got a new line */
- *c = 0;
-#if 0
- printf("Line: %s (%d)\n", req->line[f], strlen(req->line[f]));
-#endif
- if (f >= MGCP_MAX_LINES - 1) {
- ast_log(LOG_WARNING, "Too many SDP lines...\n");
- } else
- f++;
- req->line[f] = c + 1;
- } else if (*c == '\r') {
- /* Ignore and eliminate \r's */
- *c = 0;
- }
- c++;
- }
- /* Check for last line */
- if (!ast_strlen_zero(req->line[f]))
- f++;
- req->lines = f;
- /* Parse up the initial header */
- c = req->header[0];
- while(*c && *c < 33) c++;
- /* First the verb */
- req->verb = c;
- while(*c && (*c > 32)) c++;
- if (*c) {
- *c = '\0';
- c++;
- while(*c && (*c < 33)) c++;
- req->identifier = c;
- while(*c && (*c > 32)) c++;
- if (*c) {
- *c = '\0';
- c++;
- while(*c && (*c < 33)) c++;
- req->endpoint = c;
- while(*c && (*c > 32)) c++;
- if (*c) {
- *c = '\0';
- c++;
- while(*c && (*c < 33)) c++;
- req->version = c;
- while(*c && (*c > 32)) c++;
- while(*c && (*c < 33)) c++;
- while(*c && (*c > 32)) c++;
- *c = '\0';
- }
- }
- }
-
- if (mgcpdebug) {
- ast_verbose("Verb: '%s', Identifier: '%s', Endpoint: '%s', Version: '%s'\n",
- req->verb, req->identifier, req->endpoint, req->version);
- ast_verbose("%d headers, %d lines\n", req->headers, req->lines);
- }
- if (*c)
- ast_log(LOG_WARNING, "Odd content, extra stuff left over ('%s')\n", c);
-}
-
-static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
-{
- char *m;
- char *c;
- char *a;
- char host[258];
- int len;
- int portno;
- int peercapability, peerNonCodecCapability;
- struct sockaddr_in sin;
- char *codecs;
- struct ast_hostent ahp; struct hostent *hp;
- int codec, codec_count=0;
- int iterator;
- struct mgcp_endpoint *p = sub->parent;
-
- /* Get codec and RTP info from SDP */
- m = get_sdp(req, "m");
- c = get_sdp(req, "c");
- if (ast_strlen_zero(m) || ast_strlen_zero(c)) {
- ast_log(LOG_WARNING, "Insufficient information for SDP (m = '%s', c = '%s')\n", m, c);
- return -1;
- }
- if (sscanf(c, "IN IP4 %256s", host) != 1) {
- ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c);
- return -1;
- }
- /* XXX This could block for a long time, and block the main thread! XXX */
- hp = ast_gethostbyname(host, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Unable to lookup host in c= line, '%s'\n", c);
- return -1;
- }
- if (sscanf(m, "audio %d RTP/AVP %n", &portno, &len) != 1) {
- ast_log(LOG_WARNING, "Unable to determine port number for RTP in '%s'\n", m);
- return -1;
- }
- sin.sin_family = AF_INET;
- memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
- sin.sin_port = htons(portno);
- ast_rtp_set_peer(sub->rtp, &sin);
-#if 0
- printf("Peer RTP is at port %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
-#endif
- /* Scan through the RTP payload types specified in a "m=" line: */
- ast_rtp_pt_clear(sub->rtp);
- codecs = ast_strdupa(m + len);
- while (!ast_strlen_zero(codecs)) {
- if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
- if (codec_count)
- break;
- ast_log(LOG_WARNING, "Error in codec string '%s' at '%s'\n", m, codecs);
- return -1;
- }
- ast_rtp_set_m_type(sub->rtp, codec);
- codec_count++;
- codecs += len;
- }
-
- /* Next, scan through each "a=rtpmap:" line, noting each */
- /* specified RTP payload type (with corresponding MIME subtype): */
- sdpLineNum_iterator_init(&iterator);
- while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') {
- char* mimeSubtype = ast_strdupa(a); /* ensures we have enough space */
- if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2)
- continue;
- /* Note: should really look at the 'freq' and '#chans' params too */
- ast_rtp_set_rtpmap_type(sub->rtp, codec, "audio", mimeSubtype);
- }
-
- /* Now gather all of the codecs that were asked for: */
- ast_rtp_get_current_formats(sub->rtp, &peercapability, &peerNonCodecCapability);
- p->capability = capability & peercapability;
- if (mgcpdebug) {
- ast_verbose("Capabilities: us - %d, them - %d, combined - %d\n",
- capability, peercapability, p->capability);
- ast_verbose("Non-codec capabilities: us - %d, them - %d, combined - %d\n",
- nonCodecCapability, peerNonCodecCapability, p->nonCodecCapability);
- }
- if (!p->capability) {
- ast_log(LOG_WARNING, "No compatible codecs!\n");
- return -1;
- }
- return 0;
-}
-
-static int add_header(struct mgcp_request *req, char *var, char *value)
-{
- if (req->len >= sizeof(req->data) - 4) {
- ast_log(LOG_WARNING, "Out of space, can't add anymore\n");
- return -1;
- }
- if (req->lines) {
- ast_log(LOG_WARNING, "Can't add more headers when lines have been added\n");
- return -1;
- }
- req->header[req->headers] = req->data + req->len;
- snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s: %s\r\n", var, value);
- req->len += strlen(req->header[req->headers]);
- if (req->headers < MGCP_MAX_HEADERS)
- req->headers++;
- else {
- ast_log(LOG_WARNING, "Out of header space\n");
- return -1;
- }
- return 0;
-}
-
-static int add_line(struct mgcp_request *req, char *line)
-{
- if (req->len >= sizeof(req->data) - 4) {
- ast_log(LOG_WARNING, "Out of space, can't add anymore\n");
- return -1;
- }
- if (!req->lines) {
- /* Add extra empty return */
- snprintf(req->data + req->len, sizeof(req->data) - req->len, "\r\n");
- req->len += strlen(req->data + req->len);
- }
- req->line[req->lines] = req->data + req->len;
- snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line);
- req->len += strlen(req->line[req->lines]);
- if (req->lines < MGCP_MAX_LINES)
- req->lines++;
- else {
- ast_log(LOG_WARNING, "Out of line space\n");
- return -1;
- }
- return 0;
-}
-
-static int init_resp(struct mgcp_request *req, char *resp, struct mgcp_request *orig, char *resprest)
-{
- /* Initialize a response */
- if (req->headers || req->len) {
- ast_log(LOG_WARNING, "Request already initialized?!?\n");
- return -1;
- }
- req->header[req->headers] = req->data + req->len;
- snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %s %s\r\n", resp, orig->identifier, resprest);
- req->len += strlen(req->header[req->headers]);
- if (req->headers < MGCP_MAX_HEADERS)
- req->headers++;
- else
- ast_log(LOG_WARNING, "Out of header space\n");
- return 0;
-}
-
-static int init_req(struct mgcp_endpoint *p, struct mgcp_request *req, char *verb)
-{
- /* Initialize a response */
- if (req->headers || req->len) {
- ast_log(LOG_WARNING, "Request already initialized?!?\n");
- return -1;
- }
- req->header[req->headers] = req->data + req->len;
- /* SC: check if we need brackets around the gw name */
- if (p->parent->isnamedottedip)
- snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %d %s@[%s] MGCP 1.0\r\n", verb, oseq, p->name, p->parent->name);
- else
- snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %d %s@%s MGCP 1.0\r\n", verb, oseq, p->name, p->parent->name);
- req->len += strlen(req->header[req->headers]);
- if (req->headers < MGCP_MAX_HEADERS)
- req->headers++;
- else
- ast_log(LOG_WARNING, "Out of header space\n");
- return 0;
-}
-
-
-static int respprep(struct mgcp_request *resp, struct mgcp_endpoint *p, char *msg, struct mgcp_request *req, char *msgrest)
-{
- memset(resp, 0, sizeof(*resp));
- init_resp(resp, msg, req, msgrest);
- return 0;
-}
-
-static int reqprep(struct mgcp_request *req, struct mgcp_endpoint *p, char *verb)
-{
- memset(req, 0, sizeof(struct mgcp_request));
- oseq++;
- if (oseq > 999999999)
- oseq = 1;
- init_req(p, req, verb);
- return 0;
-}
-
-static int transmit_response(struct mgcp_subchannel *sub, char *msg, struct mgcp_request *req, char *msgrest)
-{
- struct mgcp_request resp;
- struct mgcp_endpoint *p = sub->parent;
- struct mgcp_response *mgr;
-
- respprep(&resp, p, msg, req, msgrest);
- mgr = malloc(sizeof(struct mgcp_response) + resp.len + 1);
- if (mgr) {
- /* Store MGCP response in case we have to retransmit */
- memset(mgr, 0, sizeof(struct mgcp_response));
- sscanf(req->identifier, "%d", &mgr->seqno);
- time(&mgr->whensent);
- mgr->len = resp.len;
- memcpy(mgr->buf, resp.data, resp.len);
- mgr->buf[resp.len] = '\0';
- mgr->next = p->parent->responses;
- p->parent->responses = mgr;
- }
- return send_response(sub, &resp);
-}
-
-
-static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struct ast_rtp *rtp)
-{
- int len;
- int codec;
- char costr[80];
- struct sockaddr_in sin;
- char v[256];
- char s[256];
- char o[256];
- char c[256];
- char t[256];
- char m[256] = "";
- char a[1024] = "";
- char iabuf[INET_ADDRSTRLEN];
- int x;
- struct sockaddr_in dest;
- struct mgcp_endpoint *p = sub->parent;
- /* XXX We break with the "recommendation" and send our IP, in order that our
- peer doesn't have to ast_gethostbyname() us XXX */
- len = 0;
- if (!sub->rtp) {
- ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
- return -1;
- }
- ast_rtp_get_us(sub->rtp, &sin);
- if (rtp) {
- ast_rtp_get_peer(rtp, &dest);
- } else {
- if (sub->tmpdest.sin_addr.s_addr) {
- dest.sin_addr = sub->tmpdest.sin_addr;
- dest.sin_port = sub->tmpdest.sin_port;
- /* Reset temporary destination */
- memset(&sub->tmpdest, 0, sizeof(sub->tmpdest));
- } else {
- dest.sin_addr = p->parent->ourip;
- dest.sin_port = sin.sin_port;
- }
- }
- if (mgcpdebug) {
- ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->ourip), ntohs(sin.sin_port));
- }
- snprintf(v, sizeof(v), "v=0\r\n");
- snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", getpid(), getpid(), ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr));
- snprintf(s, sizeof(s), "s=session\r\n");
- snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr));
- snprintf(t, sizeof(t), "t=0 0\r\n");
- snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port));
- for (x = 1; x <= AST_FORMAT_MAX_AUDIO; x <<= 1) {
- if (p->capability & x) {
- if (mgcpdebug) {
- ast_verbose("Answering with capability %d\n", x);
- }
- codec = ast_rtp_lookup_code(sub->rtp, 1, x);
- if (codec > -1) {
- snprintf(costr, sizeof(costr), " %d", codec);
- strncat(m, costr, sizeof(m) - strlen(m) - 1);
- snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(1, x));
- strncat(a, costr, sizeof(a) - strlen(a) - 1);
- }
- }
- }
- for (x = 1; x <= AST_RTP_MAX; x <<= 1) {
- if (p->nonCodecCapability & x) {
- if (mgcpdebug) {
- ast_verbose("Answering with non-codec capability %d\n", x);
- }
- codec = ast_rtp_lookup_code(sub->rtp, 0, x);
- if (codec > -1) {
- snprintf(costr, sizeof(costr), " %d", codec);
- strncat(m, costr, sizeof(m) - strlen(m) - 1);
- snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(0, x));
- strncat(a, costr, sizeof(a) - strlen(a) - 1);
- if (x == AST_RTP_DTMF) {
- /* Indicate we support DTMF... Not sure about 16,
- but MSN supports it so dang it, we will too... */
- snprintf(costr, sizeof costr, "a=fmtp:%d 0-16\r\n", codec);
- strncat(a, costr, sizeof(a) - strlen(a) - 1);
- }
- }
- }
- }
- strncat(m, "\r\n", sizeof(m) - strlen(m) - 1);
- len = strlen(v) + strlen(s) + strlen(o) + strlen(c) + strlen(t) + strlen(m) + strlen(a);
- snprintf(costr, sizeof(costr), "%d", len);
- add_line(resp, v);
- add_line(resp, o);
- add_line(resp, s);
- add_line(resp, c);
- add_line(resp, t);
- add_line(resp, m);
- add_line(resp, a);
- return 0;
-}
-
-static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp, int codecs)
-{
- struct mgcp_request resp;
- char local[256];
- char tmp[80];
- int x;
- int capability;
- struct mgcp_endpoint *p = sub->parent;
-
- capability = p->capability;
- if (codecs)
- capability = codecs;
- if (ast_strlen_zero(sub->cxident) && rtp) {
- /* We don't have a CXident yet, store the destination and
- wait a bit */
- ast_rtp_get_peer(rtp, &sub->tmpdest);
- return 0;
- }
- snprintf(local, sizeof(local), "p:20");
- for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) {
- if (p->capability & x) {
- snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x));
- strncat(local, tmp, sizeof(local) - strlen(local) - 1);
- }
- }
- reqprep(&resp, p, "MDCX");
- add_header(&resp, "C", sub->callid);
- add_header(&resp, "L", local);
- add_header(&resp, "M", mgcp_cxmodes[sub->cxmode]);
- /* SC: X header should not be sent. kept for compatibility */
- add_header(&resp, "X", sub->txident);
- add_header(&resp, "I", sub->cxident);
- /*add_header(&resp, "S", "");*/
- ast_rtp_offered_from_local(sub->rtp, 0);
- add_sdp(&resp, sub, rtp);
- /* SC: fill in new fields */
- resp.cmd = MGCP_CMD_MDCX;
- resp.trid = oseq;
- return send_request(p, sub, &resp, oseq); /* SC */
-}
-
-static int transmit_connect_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp)
-{
- struct mgcp_request resp;
- char local[256];
- char tmp[80];
- int x;
- struct mgcp_endpoint *p = sub->parent;
-
- snprintf(local, sizeof(local), "p:20");
- for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) {
- if (p->capability & x) {
- snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x));
- strncat(local, tmp, sizeof(local) - strlen(local) - 1);
- }
- }
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "Creating connection for %s@%s-%d in cxmode: %s callid: %s\n",
- p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode], sub->callid);
- }
- reqprep(&resp, p, "CRCX");
- add_header(&resp, "C", sub->callid);
- add_header(&resp, "L", local);
- add_header(&resp, "M", mgcp_cxmodes[sub->cxmode]);
- /* SC: X header should not be sent. kept for compatibility */
- add_header(&resp, "X", sub->txident);
- /*add_header(&resp, "S", "");*/
- ast_rtp_offered_from_local(sub->rtp, 1);
- add_sdp(&resp, sub, rtp);
- /* SC: fill in new fields */
- resp.cmd = MGCP_CMD_CRCX;
- resp.trid = oseq;
- return send_request(p, sub, &resp, oseq); /* SC */
-}
-
-static int transmit_notify_request(struct mgcp_subchannel *sub, char *tone)
-{
- struct mgcp_request resp;
- struct mgcp_endpoint *p = sub->parent;
-
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP Asked to indicate tone: %s on %s@%s-%d in cxmode: %s\n",
- tone, p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode]);
- }
- strncpy(p->curtone, tone, sizeof(p->curtone) - 1);
- reqprep(&resp, p, "RQNT");
- add_header(&resp, "X", p->rqnt_ident); /* SC */
- switch (p->hookstate) {
- case MGCP_ONHOOK:
- add_header(&resp, "R", "L/hd(N)");
- break;
- case MGCP_OFFHOOK:
- add_header(&resp, "R", (sub->rtp && (p->dtmfmode & MGCP_DTMF_INBAND)) ? "L/hu(N),L/hf(N)" : "L/hu(N),L/hf(N),D/[0-9#*](N)");
- break;
- }
- if (!ast_strlen_zero(tone)) {
- add_header(&resp, "S", tone);
- }
- /* SC: fill in new fields */
- resp.cmd = MGCP_CMD_RQNT;
- resp.trid = oseq;
- return send_request(p, NULL, &resp, oseq); /* SC */
-}
-
-static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callernum, char *callername)
-{
- struct mgcp_request resp;
- char tone2[256];
- char *l, *n;
- time_t t;
- struct tm tm;
- struct mgcp_endpoint *p = sub->parent;
-
- time(&t);
- localtime_r(&t,&tm);
- n = callername;
- l = callernum;
- if (!n)
- n = "";
- if (!l)
- l = "";
-
- /* Keep track of last callerid for blacklist and callreturn */
- strncpy(p->lastcallerid, l, sizeof(p->lastcallerid) - 1);
-
- snprintf(tone2, sizeof(tone2), "%s,L/ci(%02d/%02d/%02d/%02d,%s,%s)", tone,
- tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, l, n);
- strncpy(p->curtone, tone, sizeof(p->curtone) - 1);
- reqprep(&resp, p, "RQNT");
- add_header(&resp, "X", p->rqnt_ident); /* SC */
- switch (p->hookstate) {
- case MGCP_ONHOOK:
- add_header(&resp, "R", "L/hd(N)");
- break;
- case MGCP_OFFHOOK:
- add_header(&resp, "R", (sub->rtp && (p->dtmfmode & MGCP_DTMF_INBAND)) ? "L/hu(N),L/hf(N)" : "L/hu(N),L/hf(N),D/[0-9#*](N)");
- break;
- }
- if (!ast_strlen_zero(tone2)) {
- add_header(&resp, "S", tone2);
- }
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP Asked to indicate tone: %s on %s@%s-%d in cxmode: %s\n",
- tone2, p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode]);
- }
- /* SC: fill in new fields */
- resp.cmd = MGCP_CMD_RQNT;
- resp.trid = oseq;
- return send_request(p, NULL, &resp, oseq); /* SC */
-}
-
-static int transmit_modify_request(struct mgcp_subchannel *sub)
-{
- struct mgcp_request resp;
- struct mgcp_endpoint *p = sub->parent;
-
- if (ast_strlen_zero(sub->cxident)) {
- /* We don't have a CXident yet, store the destination and
- wait a bit */
- return 0;
- }
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "Modified %s@%s-%d with new mode: %s on callid: %s\n",
- p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode], sub->callid);
- }
- reqprep(&resp, p, "MDCX");
- add_header(&resp, "C", sub->callid);
- add_header(&resp, "M", mgcp_cxmodes[sub->cxmode]);
- /* SC: X header should not be sent. kept for compatibility */
- add_header(&resp, "X", sub->txident);
- add_header(&resp, "I", sub->cxident);
- switch (sub->parent->hookstate) {
- case MGCP_ONHOOK:
- add_header(&resp, "R", "L/hd(N)");
- break;
- case MGCP_OFFHOOK:
- add_header(&resp, "R", (sub->rtp && (p->dtmfmode & MGCP_DTMF_INBAND)) ? "L/hu(N), L/hf(N)" : "L/hu(N),L/hf(N),D/[0-9#*](N)");
- break;
- }
- /* SC: fill in new fields */
- resp.cmd = MGCP_CMD_MDCX;
- resp.trid = oseq;
- return send_request(p, sub, &resp, oseq); /* SC */
-}
-
-
-static int transmit_audit_endpoint(struct mgcp_endpoint *p)
-{
- struct mgcp_request resp;
- reqprep(&resp, p, "AUEP");
- /* SC: removed unknown param VS */
- /*add_header(&resp, "F", "A,R,D,S,X,N,I,T,O,ES,E,MD,M");*/
- add_header(&resp, "F", "A");
- /* SC: fill in new fields */
- resp.cmd = MGCP_CMD_AUEP;
- resp.trid = oseq;
- return send_request(p, NULL, &resp, oseq); /* SC */
-}
-
-static int transmit_connection_del(struct mgcp_subchannel *sub)
-{
- struct mgcp_endpoint *p = sub->parent;
- struct mgcp_request resp;
-
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "Delete connection %s %s@%s-%d with new mode: %s on callid: %s\n",
- sub->cxident, p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode], sub->callid);
- }
- reqprep(&resp, p, "DLCX");
- /* SC: check if call id is avail */
- if (sub->callid[0])
- add_header(&resp, "C", sub->callid);
- /* SC: X header should not be sent. kept for compatibility */
- add_header(&resp, "X", sub->txident);
- /* SC: check if cxident is avail */
- if (sub->cxident[0])
- add_header(&resp, "I", sub->cxident);
- /* SC: fill in new fields */
- resp.cmd = MGCP_CMD_DLCX;
- resp.trid = oseq;
- return send_request(p, sub, &resp, oseq); /* SC */
-}
-
-static int transmit_connection_del_w_params(struct mgcp_endpoint *p, char *callid, char *cxident)
-{
- struct mgcp_request resp;
-
- if (mgcpdebug) {
- ast_verbose(VERBOSE_PREFIX_3 "Delete connection %s %s@%s on callid: %s\n",
- cxident ? cxident : "", p->name, p->parent->name, callid ? callid : "");
- }
- reqprep(&resp, p, "DLCX");
- /* SC: check if call id is avail */
- if (callid && *callid)
- add_header(&resp, "C", callid);
- /* SC: check if cxident is avail */
- if (cxident && *cxident)
- add_header(&resp, "I", cxident);
- /* SC: fill in new fields */
- resp.cmd = MGCP_CMD_DLCX;
- resp.trid = oseq;
- return send_request(p, p->sub, &resp, oseq);
-}
-
-/* SC: cleanup pending commands */
-static void dump_cmd_queues(struct mgcp_endpoint *p, struct mgcp_subchannel *sub)
-{
- struct mgcp_request *t, *q;
-
- if (p) {
- ast_mutex_lock(&p->rqnt_queue_lock);
- for (q = p->rqnt_queue; q; t = q->next, free(q), q=t);
- p->rqnt_queue = NULL;
- ast_mutex_unlock(&p->rqnt_queue_lock);
-
- ast_mutex_lock(&p->cmd_queue_lock);
- for (q = p->cmd_queue; q; t = q->next, free(q), q=t);
- p->cmd_queue = NULL;
- ast_mutex_unlock(&p->cmd_queue_lock);
-
- ast_mutex_lock(&p->sub->cx_queue_lock);
- for (q = p->sub->cx_queue; q; t = q->next, free(q), q=t);
- p->sub->cx_queue = NULL;
- ast_mutex_unlock(&p->sub->cx_queue_lock);
-
- ast_mutex_lock(&p->sub->next->cx_queue_lock);
- for (q = p->sub->next->cx_queue; q; t = q->next, free(q), q=t);
- p->sub->next->cx_queue = NULL;
- ast_mutex_unlock(&p->sub->next->cx_queue_lock);
- } else if (sub) {
- ast_mutex_lock(&sub->cx_queue_lock);
- for (q = sub->cx_queue; q; t = q->next, free(q), q=t);
- sub->cx_queue = NULL;
- ast_mutex_unlock(&sub->cx_queue_lock);
- }
-}
-
-
-/* SC: remove command transaction from queue */
-static struct mgcp_request *find_command(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
- struct mgcp_request **queue, ast_mutex_t *l, int ident)
-{
- struct mgcp_request *prev, *req;
- char iabuf[INET_ADDRSTRLEN];
-
- ast_mutex_lock(l);
- for (prev = NULL, req = *queue; req; prev = req, req = req->next) {
- if (req->trid == ident) {
- /* remove from queue */
- if (!prev)
- *queue = req->next;
- else
- prev->next = req->next;
-
- /* send next pending command */
- if (*queue) {
- if (mgcpdebug) {
- ast_verbose("Posting Queued Request:\n%s to %s:%d\n", (*queue)->data,
- ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
- }
-
- mgcp_postrequest(p, sub, (*queue)->data, (*queue)->len, (*queue)->trid);
- }
- break;
- }
- }
- ast_mutex_unlock(l);
- return req;
-}
-
-/* SC: modified for new transport mechanism */
-static void handle_response(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
- int result, unsigned int ident, struct mgcp_request *resp)
-{
- char *c;
- struct mgcp_request *req;
- struct mgcp_gateway *gw = p->parent;
-
- if (result < 200) {
- /* provisional response */
- return;
- }
-
- if (p->slowsequence)
- req = find_command(p, sub, &p->cmd_queue, &p->cmd_queue_lock, ident);
- else if (sub)
- req = find_command(p, sub, &sub->cx_queue, &sub->cx_queue_lock, ident);
- else if (!(req = find_command(p, sub, &p->rqnt_queue, &p->rqnt_queue_lock, ident)))
- req = find_command(p, sub, &p->cmd_queue, &p->cmd_queue_lock, ident);
-
- if (!req) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "No command found on [%s] for transaction %d. Ignoring...\n",
- gw->name, ident);
- }
- return;
- }
-
- if (p && (result >= 400) && (result <= 599)) {
- switch (result) {
- case 401:
- p->hookstate = MGCP_OFFHOOK;
- break;
- case 402:
- p->hookstate = MGCP_ONHOOK;
- break;
- case 406:
- ast_log(LOG_NOTICE, "Transaction %d timed out\n", ident);
- break;
- case 407:
- ast_log(LOG_NOTICE, "Transaction %d aborted\n", ident);
- break;
- }
- if (sub) {
- if (sub->owner) {
- ast_log(LOG_NOTICE, "Terminating on result %d from %s@%s-%d\n",
- result, p->name, p->parent->name, sub ? sub->id:-1);
- mgcp_queue_hangup(sub);
- }
- } else {
- if (p->sub->next->owner) {
- ast_log(LOG_NOTICE, "Terminating on result %d from %s@%s-%d\n",
- result, p->name, p->parent->name, sub ? sub->id:-1);
- mgcp_queue_hangup(p->sub);
- }
-
- if (p->sub->owner) {
- ast_log(LOG_NOTICE, "Terminating on result %d from %s@%s-%d\n",
- result, p->name, p->parent->name, sub ? sub->id:-1);
- mgcp_queue_hangup(p->sub);
- }
-
- dump_cmd_queues(p, NULL);
- }
- }
-
- if (resp) {
- if (req->cmd == MGCP_CMD_CRCX) {
- if ((c = get_header(resp, "I"))) {
- if (!ast_strlen_zero(c) && sub) {
- /* SC: if we are hanging up do not process this conn. */
- if (sub->owner) {
- if (!ast_strlen_zero(sub->cxident)) {
- if (strcasecmp(c, sub->cxident)) {
- ast_log(LOG_WARNING, "Subchannel already has a cxident. sub->cxident: %s requested %s\n", sub->cxident, c);
- }
- }
- strncpy(sub->cxident, c, sizeof(sub->cxident) - 1);
- if (sub->tmpdest.sin_addr.s_addr) {
- transmit_modify_with_sdp(sub, NULL, 0);
- }
- } else {
- /* XXX SC: delete this one
- callid and conn id may already be lost.
- so the following del conn may have a side effect of
- cleaning up the next subchannel */
- transmit_connection_del(sub);
- }
- }
- }
- }
-
- if (req->cmd == MGCP_CMD_AUEP) {
- /* SC: check stale connection ids */
- if ((c = get_header(resp, "I"))) {
- char *v, *n;
- int len;
- while ((v = get_csv(c, &len, &n))) {
- if (len) {
- if (strncasecmp(v, p->sub->cxident, len) &&
- strncasecmp(v, p->sub->next->cxident, len)) {
- /* connection id not found. delete it */
- char cxident[80];
- memcpy(cxident, v, len);
- cxident[len] = '\0';
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Non existing connection id %s on %s@%s \n",
- cxident, p->name, gw->name);
- }
- transmit_connection_del_w_params(p, NULL, cxident);
- }
- }
- c = n;
- }
- }
-
- /* Try to determine the hookstate returned from an audit endpoint command */
- if ((c = get_header(resp, "ES"))) {
- if (!ast_strlen_zero(c)) {
- if (strstr(c, "hu")) {
- if (p->hookstate != MGCP_ONHOOK) {
- /* SC: XXX cleanup if we think we are offhook XXX */
- if ((p->sub->owner || p->sub->next->owner ) &&
- p->hookstate == MGCP_OFFHOOK)
- mgcp_queue_hangup(sub);
- p->hookstate = MGCP_ONHOOK;
-
- /* SC: update the requested events according to the new hookstate */
- transmit_notify_request(p->sub, "");
-
- /* SC: verbose level check */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Setting hookstate of %s@%s to ONHOOK\n", p->name, gw->name);
- }
- }
- } else if (strstr(c, "hd")) {
- if (p->hookstate != MGCP_OFFHOOK) {
- p->hookstate = MGCP_OFFHOOK;
-
- /* SC: update the requested events according to the new hookstate */
- transmit_notify_request(p->sub, "");
-
- /* SC: verbose level check */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Setting hookstate of %s@%s to OFFHOOK\n", p->name, gw->name);
- }
- }
- }
- }
- }
- }
-
- if (resp && resp->lines) {
- /* SC: do not process sdp if we are hanging up. this may be a late response */
- if (sub && sub->owner) {
- if (!sub->rtp)
- start_rtp(sub);
- if (sub->rtp)
- process_sdp(sub, resp);
- }
- }
- }
-
- free(req);
-}
-
-static void start_rtp(struct mgcp_subchannel *sub)
-{
- ast_mutex_lock(&sub->lock);
- /* SC: check again to be on the safe side */
- if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
- sub->rtp = NULL;
- }
- /* Allocate the RTP now */
- sub->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
- if (sub->rtp && sub->owner)
- sub->owner->fds[0] = ast_rtp_fd(sub->rtp);
- if (sub->rtp)
- ast_rtp_setnat(sub->rtp, sub->nat);
-#if 0
- ast_rtp_set_callback(p->rtp, rtpready);
- ast_rtp_set_data(p->rtp, p);
-#endif
- /* Make a call*ID */
- snprintf(sub->callid, sizeof(sub->callid), "%08x%s", rand(), sub->txident);
- /* Transmit the connection create */
- transmit_connect_with_sdp(sub, NULL);
- ast_mutex_unlock(&sub->lock);
-}
-
-static void *mgcp_ss(void *data)
-{
- struct ast_channel *chan = data;
- struct mgcp_subchannel *sub = chan->tech_pvt;
- struct mgcp_endpoint *p = sub->parent;
- char exten[AST_MAX_EXTENSION] = "";
- int len = 0;
- int timeout = firstdigittimeout;
- int res;
- int getforward = 0;
-
- while(len < AST_MAX_EXTENSION-1) {
- res = ast_waitfordigit(chan, timeout);
- timeout = 0;
- if (res < 0) {
- ast_log(LOG_DEBUG, "waitfordigit returned < 0...\n");
- /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/
- ast_indicate(chan, -1);
- ast_hangup(chan);
- return NULL;
- } else if (res) {
- exten[len++]=res;
- exten[len] = '\0';
- }
- if (!ast_ignore_pattern(chan->context, exten)) {
- /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/
- ast_indicate(chan, -1);
- } else {
- /* XXX Redundant? We should already be playing dialtone */
- /*tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);*/
- transmit_notify_request(sub, "L/dl");
- }
- if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num)) {
- if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
- if (getforward) {
- /* Record this as the forwarding extension */
- strncpy(p->call_forward, exten, sizeof(p->call_forward) - 1);
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Setting call forward to '%s' on channel %s\n",
- p->call_forward, chan->name);
- }
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- if (res)
- break;
- usleep(500000);
- /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/
- ast_indicate(chan, -1);
- sleep(1);
- memset(exten, 0, sizeof(exten));
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);*/
- transmit_notify_request(sub, "L/dl");
- len = 0;
- getforward = 0;
- } else {
- /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/
- ast_indicate(chan, -1);
- strncpy(chan->exten, exten, sizeof(chan->exten)-1);
- if (!ast_strlen_zero(p->cid_num)) {
- if (!p->hidecallerid) {
- /* SC: free existing chan->callerid */
- if (chan->cid.cid_num)
- free(chan->cid.cid_num);
- chan->cid.cid_num = strdup(p->cid_num);
- /* SC: free existing chan->callerid */
- if (chan->cid.cid_name)
- free(chan->cid.cid_name);
- chan->cid.cid_name = strdup(p->cid_name);
- }
- if (chan->cid.cid_ani)
- free(chan->cid.cid_ani);
- chan->cid.cid_ani = strdup(p->cid_num);
- }
- ast_setstate(chan, AST_STATE_RING);
- /*zt_enable_ec(p);*/
- if (p->dtmfmode & MGCP_DTMF_HYBRID) {
- p->dtmfmode |= MGCP_DTMF_INBAND;
- ast_indicate(chan, -1);
- }
- res = ast_pbx_run(chan);
- if (res) {
- ast_log(LOG_WARNING, "PBX exited non-zero\n");
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);*/
- /*transmit_notify_request(p, "nbz", 1);*/
- transmit_notify_request(sub, "G/cg");
- }
- return NULL;
- }
- } else {
- /* It's a match, but they just typed a digit, and there is an ambiguous match,
- so just set the timeout to matchdigittimeout and wait some more */
- timeout = matchdigittimeout;
- }
- } else if (res == 0) {
- ast_log(LOG_DEBUG, "not enough digits (and no ambiguous match)...\n");
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);*/
- transmit_notify_request(sub, "G/cg");
- /*zt_wait_event(p->subs[index].zfd);*/
- ast_hangup(chan);
- return NULL;
- } else if (p->hascallwaiting && p->callwaiting && !strcmp(exten, "*70")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Disabling call waiting on %s\n", chan->name);
- }
- /* Disable call waiting if enabled */
- p->callwaiting = 0;
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- len = 0;
- memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
- } else if (!strcmp(exten,ast_pickup_ext())) {
- /* Scan all channels and see if any there
- * ringing channqels with that have call groups
- * that equal this channels pickup group
- */
- if (ast_pickup_call(chan)) {
- ast_log(LOG_WARNING, "No call pickup possible...\n");
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);*/
- transmit_notify_request(sub, "G/cg");
- }
- ast_hangup(chan);
- return NULL;
- } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Disabling Caller*ID on %s\n", chan->name);
- }
- /* Disable Caller*ID if enabled */
- p->hidecallerid = 1;
- if (chan->cid.cid_num)
- free(chan->cid.cid_num);
- chan->cid.cid_num = NULL;
- if (chan->cid.cid_name)
- free(chan->cid.cid_name);
- chan->cid.cid_name = NULL;
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- len = 0;
- memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
- } else if (p->callreturn && !strcmp(exten, "*69")) {
- res = 0;
- if (!ast_strlen_zero(p->lastcallerid)) {
- res = ast_say_digit_str(chan, p->lastcallerid, "", chan->language);
- }
- if (!res)
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- break;
- } else if (!strcmp(exten, "*78")) {
- /* Do not disturb */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Enabled DND on channel %s\n", chan->name);
- }
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- p->dnd = 1;
- getforward = 0;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (!strcmp(exten, "*79")) {
- /* Do not disturb */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Disabled DND on channel %s\n", chan->name);
- }
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- p->dnd = 0;
- getforward = 0;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (p->cancallforward && !strcmp(exten, "*72")) {
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- getforward = 1;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (p->cancallforward && !strcmp(exten, "*73")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Cancelling call forwarding on channel %s\n", chan->name);
- }
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- memset(p->call_forward, 0, sizeof(p->call_forward));
- getforward = 0;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (!strcmp(exten, ast_parking_ext()) &&
- sub->next->owner && ast_bridged_channel(sub->next->owner)) {
- /* This is a three way call, the main call being a real channel,
- and we're parking the first call. */
- ast_masq_park_call(ast_bridged_channel(sub->next->owner), chan, 0, NULL);
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Parking call to '%s'\n", chan->name);
- }
- break;
- } else if (!ast_strlen_zero(p->lastcallerid) && !strcmp(exten, "*60")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Blacklisting number %s\n", p->lastcallerid);
- }
- res = ast_db_put("blacklist", p->lastcallerid, "1");
- if (!res) {
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- memset(exten, 0, sizeof(exten));
- len = 0;
- }
- } else if (p->hidecallerid && !strcmp(exten, "*82")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Enabling Caller*ID on %s\n", chan->name);
- }
- /* Enable Caller*ID if enabled */
- p->hidecallerid = 0;
- if (chan->cid.cid_num)
- free(chan->cid.cid_num);
- if (!ast_strlen_zero(p->cid_num))
- chan->cid.cid_num = strdup(p->cid_num);
- if (chan->cid.cid_name)
- free(chan->cid.cid_name);
- if (!ast_strlen_zero(p->cid_name))
- chan->cid.cid_name = strdup(p->cid_name);
- /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
- transmit_notify_request(sub, "L/sl");
- len = 0;
- memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
- } else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->cid.cid_num) &&
- ((exten[0] != '*') || (strlen(exten) > 2))) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Can't match %s from '%s' in context %s\n", exten, chan->cid.cid_num ? chan->cid.cid_num : "<Unknown Caller>", chan->context);
- break;
- }
- if (!timeout)
- timeout = gendigittimeout;
- if (len && !ast_ignore_pattern(chan->context, exten))
- /*tone_zone_play_tone(p->subs[index].zfd, -1);*/
- ast_indicate(chan, -1);
- }
-#if 0
- for (;;) {
- res = ast_waitfordigit(chan, to);
- if (!res) {
- ast_log(LOG_DEBUG, "Timeout...\n");
- break;
- }
- if (res < 0) {
- ast_log(LOG_DEBUG, "Got hangup...\n");
- ast_hangup(chan);
- break;
- }
- exten[pos++] = res;
- if (!ast_ignore_pattern(chan->context, exten))
- ast_indicate(chan, -1);
- if (ast_matchmore_extension(chan, chan->context, exten, 1, chan->callerid)) {
- if (ast_exists_extension(chan, chan->context, exten, 1, chan->callerid))
- to = 3000;
- else
- to = 8000;
- } else
- break;
- }
- if (ast_exists_extension(chan, chan->context, exten, 1, chan->callerid)) {
- strncpy(chan->exten, exten, sizeof(chan->exten) - 1);
- if (!p->rtp) {
- start_rtp(p);
- }
- ast_setstate(chan, AST_STATE_RING);
- chan->rings = 1;
- if (ast_pbx_run(chan)) {
- ast_log(LOG_WARNING, "Unable to launch PBX on %s\n", chan->name);
- } else
- return NULL;
- }
-#endif
- ast_hangup(chan);
- return NULL;
-}
-
-static int attempt_transfer(struct mgcp_endpoint *p)
-{
- /* *************************
- * I hope this works.
- * Copied out of chan_zap
- * Cross your fingers
- * *************************/
-
- /* In order to transfer, we need at least one of the channels to
- actually be in a call bridge. We can't conference two applications
- together (but then, why would we want to?) */
- if (ast_bridged_channel(p->sub->owner)) {
- /* The three-way person we're about to transfer to could still be in MOH, so
- stop if now if appropriate */
- if (ast_bridged_channel(p->sub->next->owner))
- ast_moh_stop(ast_bridged_channel(p->sub->next->owner));
- if (p->sub->owner->_state == AST_STATE_RINGING) {
- ast_indicate(ast_bridged_channel(p->sub->next->owner), AST_CONTROL_RINGING);
- }
- if (ast_channel_masquerade(p->sub->next->owner, ast_bridged_channel(p->sub->owner))) {
- ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
- ast_bridged_channel(p->sub->owner)->name, p->sub->next->owner->name);
- return -1;
- }
- /* Orphan the channel */
- unalloc_sub(p->sub->next);
- } else if (ast_bridged_channel(p->sub->next->owner)) {
- if (p->sub->owner->_state == AST_STATE_RINGING) {
- ast_indicate(ast_bridged_channel(p->sub->next->owner), AST_CONTROL_RINGING);
- }
- ast_moh_stop(ast_bridged_channel(p->sub->next->owner));
- if (ast_channel_masquerade(p->sub->owner, ast_bridged_channel(p->sub->next->owner))) {
- ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
- ast_bridged_channel(p->sub->next->owner)->name, p->sub->owner->name);
- return -1;
- }
- /*swap_subs(p, SUB_THREEWAY, SUB_REAL);*/
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Swapping %d for %d on %s@%s\n", p->sub->id, p->sub->next->id, p->name, p->parent->name);
- }
- p->sub = p->sub->next;
- unalloc_sub(p->sub->next);
- /* Tell the caller not to hangup */
- return 1;
- } else {
- ast_log(LOG_DEBUG, "Neither %s nor %s are in a bridge, nothing to transfer\n",
- p->sub->owner->name, p->sub->next->owner->name);
- p->sub->next->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- if (p->sub->next->owner) {
- p->sub->next->alreadygone = 1;
- mgcp_queue_hangup(p->sub->next);
- }
- }
- return 0;
-}
-
-static void handle_hd_hf(struct mgcp_subchannel *sub, char *ev)
-{
- struct mgcp_endpoint *p = sub->parent;
- struct ast_channel *c;
- pthread_t t;
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- /* Off hook / answer */
- if (sub->outgoing) {
- /* Answered */
- if (sub->owner) {
- if (ast_bridged_channel(sub->owner)) {
- ast_moh_stop(ast_bridged_channel(sub->owner));
- }
- sub->cxmode = MGCP_CX_SENDRECV;
- if (!sub->rtp) {
- start_rtp(sub);
- } else {
- transmit_modify_request(sub);
- }
- /*transmit_notify_request(sub, "aw");*/
- transmit_notify_request(sub, "");
- mgcp_queue_control(sub, AST_CONTROL_ANSWER);
- }
- } else {
- /* Start switch */
- /*sub->cxmode = MGCP_CX_SENDRECV;*/
- if (!sub->owner) {
- if (!sub->rtp) {
- start_rtp(sub);
- } else {
- transmit_modify_request(sub);
- }
- if (p->immediate) {
- /* The channel is immediately up. Start right away */
-#ifdef DLINK_BUGGY_FIRMWARE
- transmit_notify_request(sub, "rt");
-#else
- transmit_notify_request(sub, "G/rt");
-#endif
- c = mgcp_new(sub, AST_STATE_RING);
- if (!c) {
- ast_log(LOG_WARNING, "Unable to start PBX on channel %s@%s\n", p->name, p->parent->name);
- transmit_notify_request(sub, "G/cg");
- ast_hangup(c);
- }
- } else {
- if (has_voicemail(p)) {
- transmit_notify_request(sub, "L/sl");
- } else {
- transmit_notify_request(sub, "L/dl");
- }
- c = mgcp_new(sub, AST_STATE_DOWN);
- if (c) {
- if (ast_pthread_create(&t, &attr, mgcp_ss, c)) {
- ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno));
- ast_hangup(c);
- }
- } else {
- ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", p->name, p->parent->name);
- }
- }
- } else {
- if (p->hookstate == MGCP_OFFHOOK) {
- ast_log(LOG_WARNING, "Off hook, but already have owner on %s@%s\n", p->name, p->parent->name);
- } else {
- ast_log(LOG_WARNING, "On hook, but already have owner on %s@%s\n", p->name, p->parent->name);
- ast_log(LOG_WARNING, "If we're onhook why are we here trying to handle a hd or hf?");
- }
- if (ast_bridged_channel(sub->owner)) {
- ast_moh_stop(ast_bridged_channel(sub->owner));
- }
- sub->cxmode = MGCP_CX_SENDRECV;
- if (!sub->rtp) {
- start_rtp(sub);
- } else {
- transmit_modify_request(sub);
- }
- /*transmit_notify_request(sub, "aw");*/
- transmit_notify_request(sub, "");
- /*ast_queue_control(sub->owner, AST_CONTROL_ANSWER);*/
- }
- }
-}
-
-static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req, struct sockaddr_in *sin)
-{
- char *ev, *s;
- struct ast_frame f = { 0, };
- struct mgcp_endpoint *p = sub->parent;
- struct mgcp_gateway *g = NULL;
- char iabuf[INET_ADDRSTRLEN];
- int res;
-
- if (mgcpdebug) {
- ast_verbose("Handling request '%s' on %s@%s\n", req->verb, p->name, p->parent->name);
- }
- /* Clear out potential response */
- if (!strcasecmp(req->verb, "RSIP")) {
- /* Test if this RSIP request is just a keepalive */
- if(!strcasecmp( get_header(req, "RM"), "X-keepalive")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Received keepalive request from %s@%s\n", p->name, p->parent->name);
- transmit_response(sub, "200", req, "OK");
- } else {
- dump_queue(p->parent, p);
- dump_cmd_queues(p, NULL);
-
- if (option_verbose > 2 && (strcmp(p->name, p->parent->wcardep) != 0)) {
- ast_verbose(VERBOSE_PREFIX_3 "Resetting interface %s@%s\n", p->name, p->parent->name);
- }
- /* JS: For RSIP on wildcard we reset all endpoints */
- if (!strcmp(p->name, p->parent->wcardep)) {
- /* Reset all endpoints */
- struct mgcp_endpoint *tmp_ep;
-
- g = p->parent;
- tmp_ep = g->endpoints;
- while (tmp_ep) {
- /*if ((strcmp(tmp_ep->name, "*") != 0) && (strcmp(tmp_ep->name, "aaln/" "*") != 0)) {*/
- if (strcmp(tmp_ep->name, g->wcardep) != 0) {
- struct mgcp_subchannel *tmp_sub, *first_sub;
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Resetting interface %s@%s\n", tmp_ep->name, p->parent->name);
- }
-
- first_sub = tmp_ep->sub;
- tmp_sub = tmp_ep->sub;
- while (tmp_sub) {
- mgcp_queue_hangup(tmp_sub);
- tmp_sub = tmp_sub->next;
- if (tmp_sub == first_sub)
- break;
- }
- }
- tmp_ep = tmp_ep->next;
- }
- } else if (sub->owner) {
- mgcp_queue_hangup(sub);
- }
- transmit_response(sub, "200", req, "OK");
- /* JS: We dont send NTFY or AUEP to wildcard ep */
- if (strcmp(p->name, p->parent->wcardep) != 0) {
- transmit_notify_request(sub, "");
- /* SC: Audit endpoint.
- Idea is to prevent lost lines due to race conditions
- */
- transmit_audit_endpoint(p);
- }
- }
- } else if (!strcasecmp(req->verb, "NTFY")) {
- /* Acknowledge and be sure we keep looking for the same things */
- transmit_response(sub, "200", req, "OK");
- /* Notified of an event */
- ev = get_header(req, "O");
- s = strchr(ev, '/');
- if (s) ev = s + 1;
- ast_log(LOG_DEBUG, "Endpoint '%s@%s-%d' observed '%s'\n", p->name, p->parent->name, sub->id, ev);
- /* Keep looking for events unless this was a hangup */
- if (strcasecmp(ev, "hu") && strcasecmp(ev, "hd") && strcasecmp(ev, "ping")) {
- transmit_notify_request(sub, p->curtone);
- }
- if (!strcasecmp(ev, "hd")) {
- p->hookstate = MGCP_OFFHOOK;
- sub->cxmode = MGCP_CX_SENDRECV;
- handle_hd_hf(sub, ev);
- } else if (!strcasecmp(ev, "hf")) {
- /* We can assume we are offhook if we received a hookflash */
- /* First let's just do call wait and ignore threeway */
- /* We're currently in charge */
- if (p->hookstate != MGCP_OFFHOOK) {
- /* Cisco c7940 sends hf even if the phone is onhook */
- /* Thanks to point on IRC for pointing this out */
- return -1;
- }
- /* do not let * conference two down channels */
- if (sub->owner && sub->owner->_state == AST_STATE_DOWN && !sub->next->owner)
- return -1;
-
- if (p->callwaiting || p->transfer || p->threewaycalling) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Swapping %d for %d on %s@%s\n", p->sub->id, p->sub->next->id, p->name, p->parent->name);
- }
- p->sub = p->sub->next;
-
- /* transfer control to our next subchannel */
- if (!sub->next->owner) {
- /* plave the first call on hold and start up a new call */
- sub->cxmode = MGCP_CX_MUTE;
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP Muting %d on %s@%s\n", sub->id, p->name, p->parent->name);
- }
- transmit_modify_request(sub);
- if (sub->owner && ast_bridged_channel(sub->owner)) {
- ast_moh_start(ast_bridged_channel(sub->owner), NULL);
- }
- sub->next->cxmode = MGCP_CX_RECVONLY;
- handle_hd_hf(sub->next, ev);
- } else if (sub->owner && sub->next->owner) {
- /* We've got two active calls lets decide whether or not to conference or just flip flop */
- if ((!sub->outgoing) && (!sub->next->outgoing)) {
- /* We made both calls lets conferenct */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP Conferencing %d and %d on %s@%s\n",
- sub->id, sub->next->id, p->name, p->parent->name);
- }
- sub->cxmode = MGCP_CX_CONF;
- sub->next->cxmode = MGCP_CX_CONF;
- if (ast_bridged_channel(sub->next->owner))
- ast_moh_stop(ast_bridged_channel(sub->next->owner));
- transmit_modify_request(sub);
- transmit_modify_request(sub->next);
- } else {
- /* Let's flipflop between calls */
- /* XXX Need to check for state up ??? */
- /* XXX Need a way to indicate the current call, or maybe the call that's waiting */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "We didn't make one of the calls FLIPFLOP %d and %d on %s@%s\n",
- sub->id, sub->next->id, p->name, p->parent->name);
- }
- sub->cxmode = MGCP_CX_MUTE;
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP Muting %d on %s@%s\n", sub->id, p->name, p->parent->name);
- }
- transmit_modify_request(sub);
- if (ast_bridged_channel(sub->owner))
- ast_moh_start(ast_bridged_channel(sub->owner), NULL);
-
- if (ast_bridged_channel(sub->next->owner))
- ast_moh_stop(ast_bridged_channel(sub->next->owner));
-
- handle_hd_hf(sub->next, ev);
-#if 0
- if (sub->next->owner && (sub->next->owner->_state != AST_STATE_UP)) {
- handle_hd_hf(sub->next, ev);
- } else {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP Unmuting %d on %s@%s\n", sub->next->id, p->name, p->parent->name);
- sub->next->cxmode = MGCP_CX_SENDRECV;
- transmit_modify_request(sub->next);
- }
-#endif
- }
- } else {
- /* We've most likely lost one of our calls find an active call and bring it up */
- if (sub->owner) {
- p->sub = sub;
- } else if (sub->next->owner) {
- p->sub = sub->next;
- } else {
- /* We seem to have lost both our calls */
- /* XXX - What do we do now? */
- return -1;
- }
- if (ast_bridged_channel(p->sub->owner)) {
- ast_moh_stop(ast_bridged_channel(p->sub->owner));
- }
- p->sub->cxmode = MGCP_CX_SENDRECV;
- transmit_modify_request(p->sub);
- }
- } else {
- ast_log(LOG_WARNING, "Callwaiting, call transfer or threeway calling not enabled on endpoint %s@%s\n",
- p->name, p->parent->name);
- }
- /*ast_moh_stop(sub->owner->bridge);*/
- } else if (!strcasecmp(ev, "hu")) {
- p->hookstate = MGCP_ONHOOK;
- sub->cxmode = MGCP_CX_RECVONLY;
- ast_log(LOG_DEBUG, "MGCP %s@%s Went on hook\n", p->name, p->parent->name);
- /* JS: Do we need to send MDCX before a DLCX ?
- if (sub->rtp) {
- transmit_modify_request(sub);
- }
- */
- if (p->transfer && (sub->owner && sub->next->owner) && ((!sub->outgoing) || (!sub->next->outgoing))) {
- /* We're allowed to transfer, we have two avtive calls and */
- /* we made at least one of the calls. Let's try and transfer */
- ast_mutex_lock(&p->sub->next->lock);
- res = attempt_transfer(p);
- if (res < 0) {
- if (p->sub->next->owner) {
- sub->next->alreadygone = 1;
- mgcp_queue_hangup(sub->next);
- }
- } else if (res) {
- ast_log(LOG_WARNING, "Transfer attempt failed\n");
- ast_mutex_unlock(&p->sub->next->lock);
- return -1;
- }
- ast_mutex_unlock(&p->sub->next->lock);
- } else {
- /* Hangup the current call */
- /* If there is another active call, mgcp_hangup will ring the phone with the other call */
- if (sub->owner) {
- sub->alreadygone = 1;
- mgcp_queue_hangup(sub);
- } else {
- /* SC: verbose level check */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP handle_request(%s@%s-%d) ast_channel already destroyed, resending DLCX.\n",
- p->name, p->parent->name, sub->id);
- }
- /* Instruct the other side to remove the connection since it apparently *
- * still thinks the channel is active. *
- * For Cisco IAD2421 /BAK/ */
- transmit_connection_del(sub);
- }
- }
- if ((p->hookstate == MGCP_ONHOOK) && (!sub->rtp) && (!sub->next->rtp)) {
- p->hidecallerid = 0;
- if (p->hascallwaiting && !p->callwaiting) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Enabling call waiting on MGCP/%s@%s-%d\n", p->name, p->parent->name, sub->id);
- p->callwaiting = -1;
- }
- if (has_voicemail(p)) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP handle_request(%s@%s) set vmwi(+)\n", p->name, p->parent->name);
- }
- transmit_notify_request(sub, "L/vmwi(+)");
- } else {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP handle_request(%s@%s) set vmwi(-)\n", p->name, p->parent->name);
- }
- transmit_notify_request(sub, "L/vmwi(-)");
- }
- }
- } else if ((strlen(ev) == 1) &&
- (((ev[0] >= '0') && (ev[0] <= '9')) ||
- ((ev[0] >= 'A') && (ev[0] <= 'D')) ||
- (ev[0] == '*') || (ev[0] == '#'))) {
- f.frametype = AST_FRAME_DTMF;
- f.subclass = ev[0];
- f.src = "mgcp";
- if (sub->owner) {
- /* XXX MUST queue this frame to all subs in threeway call if threeway call is active */
- mgcp_queue_frame(sub, &f);
- ast_mutex_lock(&sub->next->lock);
- if (sub->next->owner) {
- mgcp_queue_frame(sub->next, &f);
- }
- ast_mutex_unlock(&sub->next->lock);
- }
- if (strstr(p->curtone, "wt") && (ev[0] == 'A')) {
- memset(p->curtone, 0, sizeof(p->curtone));
- }
- } else if (!strcasecmp(ev, "T")) {
- /* Digit timeout -- unimportant */
- } else if (!strcasecmp(ev, "ping")) {
- /* ping -- unimportant */
- } else {
- ast_log(LOG_NOTICE, "Received unknown event '%s' from %s@%s\n", ev, p->name, p->parent->name);
- }
- } else {
- ast_log(LOG_WARNING, "Unknown verb '%s' received from %s\n", req->verb, ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- transmit_response(sub, "510", req, "Unknown verb");
- }
- return 0;
-}
-
-static int find_and_retrans(struct mgcp_subchannel *sub, struct mgcp_request *req)
-{
- int seqno=0;
- time_t now;
- struct mgcp_response *prev = NULL, *cur, *next, *answer=NULL;
- time(&now);
- if (sscanf(req->identifier, "%d", &seqno) != 1)
- seqno = 0;
- cur = sub->parent->parent->responses;
- while(cur) {
- next = cur->next;
- if (now - cur->whensent > RESPONSE_TIMEOUT) {
- /* Delete this entry */
- if (prev)
- prev->next = next;
- else
- sub->parent->parent->responses = next;
- free(cur);
- } else {
- if (seqno == cur->seqno)
- answer = cur;
- prev = cur;
- }
- cur = next;
- }
- if (answer) {
- resend_response(sub, answer);
- return 1;
- }
- return 0;
-}
-
-static int mgcpsock_read(int *id, int fd, short events, void *ignore)
-{
- struct mgcp_request req;
- struct sockaddr_in sin;
- struct mgcp_subchannel *sub;
- int res;
- socklen_t len;
- int result;
- int ident;
- char iabuf[INET_ADDRSTRLEN];
- len = sizeof(sin);
- memset(&req, 0, sizeof(req));
- res = recvfrom(mgcpsock, req.data, sizeof(req.data) - 1, 0, (struct sockaddr *)&sin, &len);
- if (res < 0) {
- if (errno != ECONNREFUSED)
- ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno));
- return 1;
- }
- req.data[res] = '\0';
- req.len = res;
- if (mgcpdebug) {
- ast_verbose("MGCP read: \n%s\nfrom %s:%d\n", req.data, ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- }
- parse(&req);
- if (req.headers < 1) {
- /* Must have at least one header */
- return 1;
- }
- if (ast_strlen_zero(req.identifier)) {
- ast_log(LOG_NOTICE, "Message from %s missing identifier\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr));
- return 1;
- }
-
- if (sscanf(req.verb, "%d", &result) && sscanf(req.identifier, "%d", &ident)) {
- /* Try to find who this message is for, if it's important */
- sub = find_subchannel_and_lock(NULL, ident, &sin);
- if (sub) {
- struct mgcp_gateway *gw = sub->parent->parent;
- struct mgcp_message *cur, *prev;
-
- ast_mutex_unlock(&sub->lock);
- ast_mutex_lock(&gw->msgs_lock);
- for (prev = NULL, cur = gw->msgs; cur; prev = cur, cur = cur->next) {
- if (cur->seqno == ident) {
- ast_log(LOG_DEBUG, "Got response back on transaction %d\n", ident);
- if (prev)
- prev->next = cur->next;
- else
- gw->msgs = cur->next;
- break;
- }
- }
-
- /* stop retrans timer if the queue is empty */
- if (!gw->msgs && (gw->retransid != -1)) {
- ast_sched_del(sched, gw->retransid);
- gw->retransid = -1;
- }
-
- ast_mutex_unlock(&gw->msgs_lock);
- if (cur) {
- handle_response(cur->owner_ep, cur->owner_sub, result, ident, &req);
- free(cur);
- return 1;
- }
-
- ast_log(LOG_NOTICE, "Got response back on [%s] for transaction %d we aren't sending?\n",
- gw->name, ident);
- }
- } else {
- if (ast_strlen_zero(req.endpoint) ||
- ast_strlen_zero(req.version) ||
- ast_strlen_zero(req.verb)) {
- ast_log(LOG_NOTICE, "Message must have a verb, an idenitifier, version, and endpoint\n");
- return 1;
- }
- /* Process request, with iflock held */
- sub = find_subchannel_and_lock(req.endpoint, 0, &sin);
- if (sub) {
- /* look first to find a matching response in the queue */
- if (!find_and_retrans(sub, &req))
- /* pass the request off to the currently mastering subchannel */
- handle_request(sub, &req, &sin);
- ast_mutex_unlock(&sub->lock);
- }
- }
- return 1;
-}
-
-static int *mgcpsock_read_id = NULL;
-
-static void *do_monitor(void *data)
-{
- int res;
- int reloading;
- /*struct mgcp_gateway *g;*/
- /*struct mgcp_endpoint *e;*/
- /*time_t thispass = 0, lastpass = 0;*/
-
- /* Add an I/O event to our UDP socket */
- if (mgcpsock > -1)
- mgcpsock_read_id = ast_io_add(io, mgcpsock, mgcpsock_read, AST_IO_IN, NULL);
-
- /* This thread monitors all the frame relay interfaces which are not yet in use
- (and thus do not have a separate thread) indefinitely */
- /* From here on out, we die whenever asked */
- for(;;) {
- /* Check for a reload request */
- ast_mutex_lock(&mgcp_reload_lock);
- reloading = mgcp_reloading;
- mgcp_reloading = 0;
- ast_mutex_unlock(&mgcp_reload_lock);
- if (reloading) {
- if (option_verbose > 0)
- ast_verbose(VERBOSE_PREFIX_1 "Reloading MGCP\n");
- mgcp_do_reload();
- /* Add an I/O event to our UDP socket */
- if (mgcpsock > -1)
- mgcpsock_read_id = ast_io_add(io, mgcpsock, mgcpsock_read, AST_IO_IN, NULL);
- }
-
- /* Check for interfaces needing to be killed */
- /* Don't let anybody kill us right away. Nobody should lock the interface list
- and wait for the monitor list, but the other way around is okay. */
- ast_mutex_lock(&monlock);
- /* Lock the network interface */
- ast_mutex_lock(&netlock);
-
-#if 0
- /* XXX THIS IS COMPLETELY HOSED */
- /* The gateway goes into a state of panic */
- /* If the vmwi indicator is sent while it is reseting interfaces */
- lastpass = thispass;
- thispass = time(NULL);
- g = gateways;
- while(g) {
- if (thispass != lastpass) {
- e = g->endpoints;
- while(e) {
- if (e->type == TYPE_LINE) {
- res = has_voicemail(e);
- if ((e->msgstate != res) && (e->hookstate == MGCP_ONHOOK) && (!e->rtp)){
- if (res) {
- transmit_notify_request(e, "L/vmwi(+)");
- } else {
- transmit_notify_request(e, "L/vmwi(-)");
- }
- e->msgstate = res;
- e->onhooktime = thispass;
- }
- }
- e = e->next;
- }
- }
- g = g->next;
- }
-#endif
- /* Okay, now that we know what to do, release the network lock */
- ast_mutex_unlock(&netlock);
- /* And from now on, we're okay to be killed, so release the monitor lock as well */
- ast_mutex_unlock(&monlock);
- pthread_testcancel();
- /* Wait for sched or io */
- res = ast_sched_wait(sched);
- /* SC: copied from chan_sip.c */
- if ((res < 0) || (res > 1000))
- res = 1000;
- res = ast_io_wait(io, res);
- ast_mutex_lock(&monlock);
- if (res >= 0)
- ast_sched_runq(sched);
- ast_mutex_unlock(&monlock);
- }
- /* Never reached */
- return NULL;
-}
-
-static int restart_monitor(void)
-{
- /* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == AST_PTHREADT_STOP)
- return 0;
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_WARNING, "Unable to lock monitor\n");
- return -1;
- }
- if (monitor_thread == pthread_self()) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- return -1;
- }
- if (monitor_thread != AST_PTHREADT_NULL) {
- /* Wake up the thread */
- pthread_kill(monitor_thread, SIGURG);
- } else {
- /* Start a new monitor */
- if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- return -1;
- }
- }
- ast_mutex_unlock(&monlock);
- return 0;
-}
-
-static struct ast_channel *mgcp_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- struct mgcp_subchannel *sub;
- struct ast_channel *tmpc = NULL;
- char tmp[256];
- char *dest = data;
-
- oldformat = format;
- format &= capability;
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", format);
- return NULL;
- }
- strncpy(tmp, dest, sizeof(tmp) - 1);
- if (ast_strlen_zero(tmp)) {
- ast_log(LOG_NOTICE, "MGCP Channels require an endpoint\n");
- return NULL;
- }
- sub = find_subchannel_and_lock(tmp, 0, NULL);
- if (!sub) {
- ast_log(LOG_WARNING, "Unable to find MGCP endpoint '%s'\n", tmp);
- *cause = AST_CAUSE_UNREGISTERED;
- return NULL;
- }
-
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_request(%s)\n", tmp);
- ast_verbose(VERBOSE_PREFIX_3 "MGCP cw: %d, dnd: %d, so: %d, sno: %d\n",
- sub->parent->callwaiting, sub->parent->dnd, sub->owner ? 1 : 0, sub->next->owner ? 1: 0);
- }
- /* Must be busy */
- if (((sub->parent->callwaiting) && ((sub->owner) && (sub->next->owner))) ||
- ((!sub->parent->callwaiting) && (sub->owner)) ||
- (sub->parent->dnd && (ast_strlen_zero(sub->parent->call_forward)))) {
- if (sub->parent->hookstate == MGCP_ONHOOK) {
- if (has_voicemail(sub->parent)) {
- transmit_notify_request(sub,"L/vmwi(+)");
- } else {
- transmit_notify_request(sub,"L/vmwi(-)");
- }
- }
- *cause = AST_CAUSE_BUSY;
- ast_mutex_unlock(&sub->lock);
- return NULL;
- }
- tmpc = mgcp_new(sub->owner ? sub->next : sub, AST_STATE_DOWN);
- ast_mutex_unlock(&sub->lock);
- if (!tmpc)
- ast_log(LOG_WARNING, "Unable to make channel for '%s'\n", tmp);
- restart_monitor();
- return tmpc;
-}
-
-/* SC: modified for reload support */
-static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v)
-{
- struct mgcp_gateway *gw;
- struct mgcp_endpoint *e;
- struct mgcp_subchannel *sub;
- /*char txident[80];*/
- int i=0, y=0;
- int gw_reload = 0;
- int ep_reload = 0;
- canreinvite = CANREINVITE;
-
- /* SC: locate existing gateway */
- gw = gateways;
- while (gw) {
- if (!strcasecmp(cat, gw->name)) {
- /* gateway already exists */
- gw->delme = 0;
- gw_reload = 1;
- break;
- }
- gw = gw->next;
- }
-
- if (!gw)
- gw = malloc(sizeof(struct mgcp_gateway));
-
- if (gw) {
- if (!gw_reload) {
- memset(gw, 0, sizeof(struct mgcp_gateway));
- gw->expire = -1;
- gw->retransid = -1; /* SC */
- ast_mutex_init(&gw->msgs_lock);
- strncpy(gw->name, cat, sizeof(gw->name) - 1);
- /* SC: check if the name is numeric ip */
- if ((strchr(gw->name, '.')) && inet_addr(gw->name) != INADDR_NONE)
- gw->isnamedottedip = 1;
- }
- while(v) {
- if (!strcasecmp(v->name, "host")) {
- if (!strcasecmp(v->value, "dynamic")) {
- /* They'll register with us */
- gw->dynamic = 1;
- memset(&gw->addr.sin_addr, 0, 4);
- if (gw->addr.sin_port) {
- /* If we've already got a port, make it the default rather than absolute */
- gw->defaddr.sin_port = gw->addr.sin_port;
- gw->addr.sin_port = 0;
- }
- } else {
- /* Non-dynamic. Make sure we become that way if we're not */
- if (gw->expire > -1)
- ast_sched_del(sched, gw->expire);
- gw->expire = -1;
- gw->dynamic = 0;
- if (ast_get_ip(&gw->addr, v->value)) {
- if (!gw_reload) {
- ast_mutex_destroy(&gw->msgs_lock);
- free(gw);
- }
- return NULL;
- }
- }
- } else if (!strcasecmp(v->name, "defaultip")) {
- if (ast_get_ip(&gw->defaddr, v->value)) {
- if (!gw_reload) {
- ast_mutex_destroy(&gw->msgs_lock);
- free(gw);
- }
- return NULL;
- }
- } else if (!strcasecmp(v->name, "permit") ||
- !strcasecmp(v->name, "deny")) {
- gw->ha = ast_append_ha(v->name, v->value, gw->ha);
- } else if (!strcasecmp(v->name, "port")) {
- gw->addr.sin_port = htons(atoi(v->value));
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(context, v->value, sizeof(context) - 1);
- } else if (!strcasecmp(v->name, "dtmfmode")) {
- if (!strcasecmp(v->value, "inband"))
- dtmfmode = MGCP_DTMF_INBAND;
- else if (!strcasecmp(v->value, "rfc2833"))
- dtmfmode = MGCP_DTMF_RFC2833;
- else if (!strcasecmp(v->value, "hybrid"))
- dtmfmode = MGCP_DTMF_HYBRID;
- else if (!strcasecmp(v->value, "none"))
- dtmfmode = 0;
- else
- ast_log(LOG_WARNING, "'%s' is not a valid DTMF mode at line %d\n", v->value, v->lineno);
- } else if (!strcasecmp(v->name, "nat")) {
- nat = ast_true(v->value);
- } else if (!strcasecmp(v->name, "callerid")) {
- if (!strcasecmp(v->value, "asreceived")) {
- cid_num[0] = '\0';
- cid_name[0] = '\0';
- } else {
- ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
- }
- } else if (!strcasecmp(v->name, "language")) {
- strncpy(language, v->value, sizeof(language)-1);
- } else if (!strcasecmp(v->name, "accountcode")) {
- strncpy(accountcode, v->value, sizeof(accountcode)-1);
- } else if (!strcasecmp(v->name, "amaflags")) {
- y = ast_cdr_amaflags2int(v->value);
- if (y < 0) {
- ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
- } else {
- amaflags = y;
- }
- } else if (!strcasecmp(v->name, "musiconhold")) {
- strncpy(musicclass, v->value, sizeof(musicclass)-1);
- } else if (!strcasecmp(v->name, "callgroup")) {
- cur_callergroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "pickupgroup")) {
- cur_pickupgroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "immediate")) {
- immediate = ast_true(v->value);
- } else if (!strcasecmp(v->name, "cancallforward")) {
- cancallforward = ast_true(v->value);
- } else if (!strcasecmp(v->name, "singlepath")) {
- singlepath = ast_true(v->value);
- } else if (!strcasecmp(v->name, "canreinvite")) {
- canreinvite = ast_true(v->value);
- } else if (!strcasecmp(v->name, "mailbox")) {
- strncpy(mailbox, v->value, sizeof(mailbox) -1);
- } else if (!strcasecmp(v->name, "adsi")) {
- adsi = ast_true(v->value);
- } else if (!strcasecmp(v->name, "callreturn")) {
- callreturn = ast_true(v->value);
- } else if (!strcasecmp(v->name, "callwaiting")) {
- callwaiting = ast_true(v->value);
- } else if (!strcasecmp(v->name, "slowsequence")) {
- slowsequence = ast_true(v->value);
- } else if (!strcasecmp(v->name, "transfer")) {
- transfer = ast_true(v->value);
- } else if (!strcasecmp(v->name, "threewaycalling")) {
- threewaycalling = ast_true(v->value);
- } else if (!strcasecmp(v->name, "wcardep")) {
- /* SC: locate existing endpoint */
- e = gw->endpoints;
- while (e) {
- if (!strcasecmp(v->value, e->name)) {
- /* endpoint already exists */
- e->delme = 0;
- ep_reload = 1;
- break;
- }
- e = e->next;
- }
-
- if (!e) {
- /* Allocate wildcard endpoint */
- e = malloc(sizeof(struct mgcp_endpoint));
- ep_reload = 0;
- }
-
- if (e) {
- if (!ep_reload) {
- memset(e, 0, sizeof(struct mgcp_endpoint));
- ast_mutex_init(&e->lock);
- ast_mutex_init(&e->rqnt_queue_lock);
- ast_mutex_init(&e->cmd_queue_lock);
- strncpy(e->name, v->value, sizeof(e->name) - 1);
- e->needaudit = 1;
- }
- strncpy(gw->wcardep, v->value, sizeof(gw->wcardep) - 1);
- /*strncpy(e->name, "aaln/" "*", sizeof(e->name) - 1);*/
- /* XXX Should we really check for uniqueness?? XXX */
- strncpy(e->accountcode, accountcode, sizeof(e->accountcode) - 1);
- strncpy(e->context, context, sizeof(e->context) - 1);
- strncpy(e->cid_num, cid_num, sizeof(e->cid_num) - 1);
- strncpy(e->cid_name, cid_name, sizeof(e->cid_name) - 1);
- strncpy(e->language, language, sizeof(e->language) - 1);
- strncpy(e->musicclass, musicclass, sizeof(e->musicclass) - 1);
- strncpy(e->mailbox, mailbox, sizeof(e->mailbox) - 1);
- snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08x", rand());
- e->msgstate = -1;
- e->amaflags = amaflags;
- e->capability = capability;
- e->parent = gw;
- e->dtmfmode = dtmfmode;
- if (!ep_reload && e->sub && e->sub->rtp)
- e->dtmfmode |= MGCP_DTMF_INBAND;
- e->adsi = adsi;
- e->type = TYPE_LINE;
- e->immediate = immediate;
- e->callgroup=cur_callergroup;
- e->pickupgroup=cur_pickupgroup;
- e->callreturn = callreturn;
- e->cancallforward = cancallforward;
- e->singlepath = singlepath;
- e->canreinvite = canreinvite;
- e->callwaiting = callwaiting;
- e->hascallwaiting = callwaiting;
- e->slowsequence = slowsequence;
- e->transfer = transfer;
- e->threewaycalling = threewaycalling;
- e->onhooktime = time(NULL);
- /* ASSUME we're onhook */
- e->hookstate = MGCP_ONHOOK;
- if (!ep_reload) {
- /*snprintf(txident, sizeof(txident), "%08x", rand());*/
- for (i = 0; i < MAX_SUBS; i++) {
- sub = malloc(sizeof(struct mgcp_subchannel));
- if (sub) {
- ast_verbose(VERBOSE_PREFIX_3 "Allocating subchannel '%d' on %s@%s\n", i, e->name, gw->name);
- memset(sub, 0, sizeof(struct mgcp_subchannel));
- ast_mutex_init(&sub->lock);
- ast_mutex_init(&sub->cx_queue_lock);
- sub->parent = e;
- sub->id = i;
- snprintf(sub->txident, sizeof(sub->txident), "%08x", rand());
- /*stnrcpy(sub->txident, txident, sizeof(sub->txident) - 1);*/
- sub->cxmode = MGCP_CX_INACTIVE;
- sub->nat = nat;
- sub->next = e->sub;
- e->sub = sub;
- } else {
- /* XXX Should find a way to clean up our memory */
- ast_log(LOG_WARNING, "Out of memory allocating subchannel");
- return NULL;
- }
- }
- /* Make out subs a circular linked list so we can always sping through the whole bunch */
- sub = e->sub;
- /* find the end of the list */
- while(sub->next){
- sub = sub->next;
- }
- /* set the last sub->next to the first sub */
- sub->next = e->sub;
-
- e->next = gw->endpoints;
- gw->endpoints = e;
- }
- }
- } else if (!strcasecmp(v->name, "trunk") ||
- !strcasecmp(v->name, "line")) {
-
- /* SC: locate existing endpoint */
- e = gw->endpoints;
- while (e) {
- if (!strcasecmp(v->value, e->name)) {
- /* endpoint already exists */
- e->delme = 0;
- ep_reload = 1;
- break;
- }
- e = e->next;
- }
-
- if (!e) {
- e = malloc(sizeof(struct mgcp_endpoint));
- ep_reload = 0;
- }
-
- if (e) {
- if (!ep_reload) {
- memset(e, 0, sizeof(struct mgcp_endpoint));
- ast_mutex_init(&e->lock);
- ast_mutex_init(&e->rqnt_queue_lock);
- ast_mutex_init(&e->cmd_queue_lock);
- strncpy(e->name, v->value, sizeof(e->name) - 1);
- e->needaudit = 1;
- }
- /* XXX Should we really check for uniqueness?? XXX */
- strncpy(e->accountcode, accountcode, sizeof(e->accountcode) - 1);
- strncpy(e->context, context, sizeof(e->context) - 1);
- strncpy(e->cid_num, cid_num, sizeof(e->cid_num) - 1);
- strncpy(e->cid_name, cid_name, sizeof(e->cid_name) - 1);
- strncpy(e->language, language, sizeof(e->language) - 1);
- strncpy(e->musicclass, musicclass, sizeof(e->musicclass) - 1);
- strncpy(e->mailbox, mailbox, sizeof(e->mailbox)-1);
- if (!ast_strlen_zero(mailbox)) {
- ast_verbose(VERBOSE_PREFIX_3 "Setting mailbox '%s' on %s@%s\n", mailbox, gw->name, e->name);
- }
- if (!ep_reload) {
- /* XXX SC: potential issue due to reload */
- e->msgstate = -1;
- e->parent = gw;
- }
- e->amaflags = amaflags;
- e->capability = capability;
- e->dtmfmode = dtmfmode;
- e->adsi = adsi;
- if (!strcasecmp(v->name, "trunk"))
- e->type = TYPE_TRUNK;
- else
- e->type = TYPE_LINE;
-
- e->immediate = immediate;
- e->callgroup=cur_callergroup;
- e->pickupgroup=cur_pickupgroup;
- e->callreturn = callreturn;
- e->cancallforward = cancallforward;
- e->canreinvite = canreinvite;
- e->singlepath = singlepath;
- e->callwaiting = callwaiting;
- e->hascallwaiting = callwaiting;
- e->slowsequence = slowsequence;
- e->transfer = transfer;
- e->threewaycalling = threewaycalling;
- if (!ep_reload) {
- e->onhooktime = time(NULL);
- /* ASSUME we're onhook */
- e->hookstate = MGCP_ONHOOK;
- snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08x", rand());
- }
-
- for (i = 0, sub = NULL; i < MAX_SUBS; i++) {
- if (!ep_reload) {
- sub = malloc(sizeof(struct mgcp_subchannel));
- } else {
- if (!sub)
- sub = e->sub;
- else
- sub = sub->next;
- }
-
- if (sub) {
- if (!ep_reload) {
- ast_verbose(VERBOSE_PREFIX_3 "Allocating subchannel '%d' on %s@%s\n", i, e->name, gw->name);
- memset(sub, 0, sizeof(struct mgcp_subchannel));
- ast_mutex_init(&sub->lock);
- ast_mutex_init(&sub->cx_queue_lock);
- strncpy(sub->magic, MGCP_SUBCHANNEL_MAGIC, sizeof(sub->magic) - 1);
- sub->parent = e;
- sub->id = i;
- snprintf(sub->txident, sizeof(sub->txident), "%08x", rand());
- sub->cxmode = MGCP_CX_INACTIVE;
- sub->next = e->sub;
- e->sub = sub;
- }
- sub->nat = nat;
- } else {
- /* XXX Should find a way to clean up our memory */
- ast_log(LOG_WARNING, "Out of memory allocating subchannel");
- return NULL;
- }
- }
- if (!ep_reload) {
- /* Make out subs a circular linked list so we can always sping through the whole bunch */
- sub = e->sub;
- /* find the end of the list */
- while (sub->next) {
- sub = sub->next;
- }
- /* set the last sub->next to the first sub */
- sub->next = e->sub;
-
- e->next = gw->endpoints;
- gw->endpoints = e;
- }
- }
- } else
- ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name, v->lineno);
- v = v->next;
- }
- }
- if (!ntohl(gw->addr.sin_addr.s_addr) && !gw->dynamic) {
- ast_log(LOG_WARNING, "Gateway '%s' lacks IP address and isn't dynamic\n", gw->name);
- if (!gw_reload) {
- ast_mutex_destroy(&gw->msgs_lock);
- free(gw);
- }
- return NULL;
- }
- gw->defaddr.sin_family = AF_INET;
- gw->addr.sin_family = AF_INET;
- if (gw->defaddr.sin_addr.s_addr && !ntohs(gw->defaddr.sin_port))
- gw->defaddr.sin_port = htons(DEFAULT_MGCP_GW_PORT);
- if (gw->addr.sin_addr.s_addr && !ntohs(gw->addr.sin_port))
- gw->addr.sin_port = htons(DEFAULT_MGCP_GW_PORT);
- if (gw->addr.sin_addr.s_addr)
- if (ast_ouraddrfor(&gw->addr.sin_addr, &gw->ourip))
- memcpy(&gw->ourip, &__ourip, sizeof(gw->ourip));
-
- return (gw_reload ? NULL : gw);
-}
-
-static struct ast_rtp *mgcp_get_rtp_peer(struct ast_channel *chan)
-{
- struct mgcp_subchannel *sub;
- sub = chan->tech_pvt;
- if (sub && sub->rtp && sub->parent->canreinvite)
- return sub->rtp;
- return NULL;
-}
-
-static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active)
-{
- /* XXX Is there such thing as video support with MGCP? XXX */
- struct mgcp_subchannel *sub;
- sub = chan->tech_pvt;
- if (sub) {
- transmit_modify_with_sdp(sub, rtp, codecs);
- return 0;
- }
- return -1;
-}
-
-static struct ast_rtp_protocol mgcp_rtp = {
- .type = type,
- .get_rtp_info = mgcp_get_rtp_peer,
- .set_rtp_peer = mgcp_set_rtp_peer,
-};
-
-static int mgcp_do_debug(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- mgcpdebug = 1;
- ast_cli(fd, "MGCP Debugging Enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int mgcp_no_debug(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- mgcpdebug = 0;
- ast_cli(fd, "MGCP Debugging Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static char debug_usage[] =
-"Usage: mgcp debug\n"
-" Enables dumping of MGCP packets for debugging purposes\n";
-
-static char no_debug_usage[] =
-"Usage: mgcp no debug\n"
-" Disables dumping of MGCP packets for debugging purposes\n";
-
-static char mgcp_reload_usage[] =
-"Usage: mgcp reload\n"
-" Reloads MGCP configuration from mgcp.conf\n";
-
-static struct ast_cli_entry cli_debug =
- { { "mgcp", "debug", NULL }, mgcp_do_debug, "Enable MGCP debugging", debug_usage };
-static struct ast_cli_entry cli_no_debug =
- { { "mgcp", "no", "debug", NULL }, mgcp_no_debug, "Disable MGCP debugging", no_debug_usage };
-static struct ast_cli_entry cli_mgcp_reload =
- { { "mgcp", "reload", NULL }, mgcp_reload, "Reload MGCP configuration", mgcp_reload_usage };
-
-
-static void destroy_endpoint(struct mgcp_endpoint *e)
-{
- struct mgcp_subchannel *sub = e->sub->next, *s;
- int i;
-
- for (i = 0; i < MAX_SUBS; i++) {
- ast_mutex_lock(&sub->lock);
- if (!ast_strlen_zero(sub->cxident)) {
- transmit_connection_del(sub);
- }
- if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
- sub->rtp = NULL;
- }
- memset(sub->magic, 0, sizeof(sub->magic));
- mgcp_queue_hangup(sub);
- dump_cmd_queues(NULL, sub);
- ast_mutex_unlock(&sub->lock);
- sub = sub->next;
- }
-
- if (e->dsp) {
- ast_dsp_free(e->dsp);
- }
-
- dump_queue(e->parent, e);
- dump_cmd_queues(e, NULL);
-
- sub = e->sub;
- for (i = 0; (i < MAX_SUBS) && sub; i++) {
- s = sub;
- sub = sub->next;
- ast_mutex_destroy(&s->lock);
- ast_mutex_destroy(&s->cx_queue_lock);
- free(s);
- }
- ast_mutex_destroy(&e->lock);
- ast_mutex_destroy(&e->rqnt_queue_lock);
- ast_mutex_destroy(&e->cmd_queue_lock);
- free(e);
-}
-
-static void destroy_gateway(struct mgcp_gateway *g)
-{
- if (g->ha)
- ast_free_ha(g->ha);
-
- dump_queue(g, NULL);
-
- free (g);
-}
-
-static void prune_gateways(void)
-{
- struct mgcp_gateway *g, *z, *r;
- struct mgcp_endpoint *e, *p, *t;
-
- ast_mutex_lock(&gatelock);
-
- /* prune gateways */
- for (z = NULL, g = gateways; g;) {
- /* prune endpoints */
- for (p = NULL, e = g->endpoints; e; ) {
- if (e->delme || g->delme) {
- t = e;
- e = e->next;
- if (!p)
- g->endpoints = e;
- else
- p->next = e;
- destroy_endpoint(t);
- } else {
- p = e;
- e = e->next;
- }
- }
-
- if (g->delme) {
- r = g;
- g = g->next;
- if (!z)
- gateways = g;
- else
- z->next = g;
-
- destroy_gateway(r);
- } else {
- z = g;
- g = g->next;
- }
- }
-
- ast_mutex_unlock(&gatelock);
-}
-
-static int reload_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- struct mgcp_gateway *g;
- struct mgcp_endpoint *e;
- char iabuf[INET_ADDRSTRLEN];
- char *cat;
- struct ast_hostent ahp;
- struct hostent *hp;
- int format;
-
- if (gethostname(ourhost, sizeof(ourhost)-1)) {
- ast_log(LOG_WARNING, "Unable to get hostname, MGCP disabled\n");
- return 0;
- }
- cfg = ast_config_load(config);
-
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_NOTICE, "Unable to load config %s, MGCP disabled\n", config);
- return 0;
- }
- memset(&bindaddr, 0, sizeof(bindaddr));
- dtmfmode = 0;
- v = ast_variable_browse(cfg, "general");
- while(v) {
- /* Create the interface list */
- if (!strcasecmp(v->name, "bindaddr")) {
- if (!(hp = ast_gethostbyname(v->value, &ahp))) {
- ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
- } else {
- memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
- }
- } else if (!strcasecmp(v->name, "allow")) {
- format = ast_getformatbyname(v->value);
- if (format < 1)
- ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value);
- else
- capability |= format;
- } else if (!strcasecmp(v->name, "disallow")) {
- format = ast_getformatbyname(v->value);
- if (format < 1)
- ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value);
- else
- capability &= ~format;
- } else if (!strcasecmp(v->name, "tos")) {
- if (sscanf(v->value, "%d", &format) == 1)
- tos = format & 0xff;
- else if (!strcasecmp(v->value, "lowdelay"))
- tos = IPTOS_LOWDELAY;
- else if (!strcasecmp(v->value, "throughput"))
- tos = IPTOS_THROUGHPUT;
- else if (!strcasecmp(v->value, "reliability"))
- tos = IPTOS_RELIABILITY;
- else if (!strcasecmp(v->value, "mincost"))
- tos = IPTOS_MINCOST;
- else if (!strcasecmp(v->value, "none"))
- tos = 0;
- else
- ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
- } else if (!strcasecmp(v->name, "port")) {
- if (sscanf(v->value, "%d", &ourport) == 1) {
- bindaddr.sin_port = htons(ourport);
- } else {
- ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config);
- }
- }
- v = v->next;
- }
-
- /* SC: mark existing entries for deletion */
- ast_mutex_lock(&gatelock);
- g = gateways;
- while (g) {
- g->delme = 1;
- e = g->endpoints;
- while (e) {
- e->delme = 1;
- e = e->next;
- }
- g = g->next;
- }
- ast_mutex_unlock(&gatelock);
-
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (strcasecmp(cat, "general")) {
- ast_mutex_lock(&gatelock);
- g = build_gateway(cat, ast_variable_browse(cfg, cat));
- if (g) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Added gateway '%s'\n", g->name);
- }
- g->next = gateways;
- gateways = g;
- }
- ast_mutex_unlock(&gatelock);
-
- /* FS: process queue and IO */
- if (monitor_thread == pthread_self()) {
- if (sched) ast_sched_runq(sched);
- if (io) ast_io_wait(io, 10);
- }
- }
- cat = ast_category_browse(cfg, cat);
- }
-
- /* SC: prune deleted entries etc. */
- prune_gateways();
-
- if (ntohl(bindaddr.sin_addr.s_addr)) {
- memcpy(&__ourip, &bindaddr.sin_addr, sizeof(__ourip));
- } else {
- hp = ast_gethostbyname(ourhost, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Unable to get our IP address, MGCP disabled\n");
- ast_config_destroy(cfg);
- return 0;
- }
- memcpy(&__ourip, hp->h_addr, sizeof(__ourip));
- }
- if (!ntohs(bindaddr.sin_port))
- bindaddr.sin_port = ntohs(DEFAULT_MGCP_CA_PORT);
- bindaddr.sin_family = AF_INET;
- ast_mutex_lock(&netlock);
- if (mgcpsock > -1)
- close(mgcpsock);
-
- if (mgcpsock_read_id != NULL)
- ast_io_remove(io, mgcpsock_read_id);
- mgcpsock_read_id = NULL;
-
- mgcpsock = socket(AF_INET, SOCK_DGRAM, 0);
- if (mgcpsock < 0) {
- ast_log(LOG_WARNING, "Unable to create MGCP socket: %s\n", strerror(errno));
- } else {
- if (bind(mgcpsock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) {
- ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port),
- strerror(errno));
- close(mgcpsock);
- mgcpsock = -1;
- } else {
- if (option_verbose > 1) {
- ast_verbose(VERBOSE_PREFIX_2 "MGCP Listening on %s:%d\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port));
- ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos);
- }
- if (setsockopt(mgcpsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))
- ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
- }
- }
- ast_mutex_unlock(&netlock);
- ast_config_destroy(cfg);
-
- /* SC: send audit only to the new endpoints */
- g = gateways;
- while (g) {
- e = g->endpoints;
- while (e && e->needaudit) {
- e->needaudit = 0;
- transmit_audit_endpoint(e);
- ast_verbose(VERBOSE_PREFIX_3 "MGCP Auditing endpoint %s@%s for hookstate\n", e->name, g->name);
- e = e->next;
- }
- g = g->next;
- }
-
- return 0;
-}
-
-int load_module()
-{
- int res;
-
- sched = sched_context_create();
- if (!sched) {
- ast_log(LOG_WARNING, "Unable to create schedule context\n");
- return -1;
- }
- io = io_context_create();
- if (!io) {
- ast_log(LOG_WARNING, "Unable to create I/O context\n");
- return -1;
- }
-
- if (!(res = reload_config())) {
- /* Make sure we can register our mgcp channel type */
- if (ast_channel_register(&mgcp_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- return -1;
- }
- ast_rtp_proto_register(&mgcp_rtp);
- ast_cli_register(&cli_show_endpoints);
- ast_cli_register(&cli_audit_endpoint);
- ast_cli_register(&cli_debug);
- ast_cli_register(&cli_no_debug);
- ast_cli_register(&cli_mgcp_reload);
-
- /* And start the monitor for the first time */
- restart_monitor();
- }
-
- return res;
-}
-
-static int mgcp_do_reload(void)
-{
- reload_config();
- return 0;
-}
-
-static int mgcp_reload(int fd, int argc, char *argv[])
-{
- ast_mutex_lock(&mgcp_reload_lock);
- if (mgcp_reloading) {
- ast_verbose("Previous mgcp reload not yet done\n");
- } else
- mgcp_reloading = 1;
- ast_mutex_unlock(&mgcp_reload_lock);
- restart_monitor();
- return 0;
-}
-
-int reload(void)
-{
- mgcp_reload(0, 0, NULL);
- return 0;
-}
-
-int unload_module()
-{
- struct mgcp_endpoint *e;
- struct mgcp_gateway *g;
-
- /* Check to see if we're reloading */
- if (ast_mutex_trylock(&mgcp_reload_lock)) {
- ast_log(LOG_WARNING, "MGCP is currently reloading. Unable to remove module.\n");
- return -1;
- } else {
- mgcp_reloading = 1;
- ast_mutex_unlock(&mgcp_reload_lock);
- }
-
- /* First, take us out of the channel loop */
- ast_channel_unregister(&mgcp_tech);
-
- /* Shut down the monitoring thread */
- if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
- pthread_cancel(monitor_thread);
- pthread_kill(monitor_thread, SIGURG);
- pthread_join(monitor_thread, NULL);
- }
- monitor_thread = AST_PTHREADT_STOP;
- ast_mutex_unlock(&monlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- /* We always want to leave this in a consistent state */
- ast_channel_register(&mgcp_tech);
- mgcp_reloading = 0;
- mgcp_reload(0, 0, NULL);
- return -1;
- }
-
- if (!ast_mutex_lock(&gatelock)) {
- g = gateways;
- while (g) {
- g->delme = 1;
- e = g->endpoints;
- while (e) {
- e->delme = 1;
- e = e->next;
- }
- g = g->next;
- }
-
- prune_gateways();
- ast_mutex_unlock(&gatelock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the gateways list.\n");
- /* We always want to leave this in a consistent state */
- ast_channel_register(&mgcp_tech);
- /* Allow the monitor to restart */
- monitor_thread = AST_PTHREADT_NULL;
- mgcp_reloading = 0;
- mgcp_reload(0, 0, NULL);
- return -1;
- }
-
- close(mgcpsock);
- ast_rtp_proto_unregister(&mgcp_rtp);
- ast_cli_unregister(&cli_show_endpoints);
- ast_cli_unregister(&cli_audit_endpoint);
- ast_cli_unregister(&cli_debug);
- ast_cli_unregister(&cli_no_debug);
- ast_cli_unregister(&cli_mgcp_reload);
- sched_context_destroy(sched);
-
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-char *description()
-{
- return (char *) desc;
-}
diff --git a/1.2-netsec/channels/chan_misdn.c b/1.2-netsec/channels/chan_misdn.c
deleted file mode 100644
index 46296c18f..000000000
--- a/1.2-netsec/channels/chan_misdn.c
+++ /dev/null
@@ -1,3816 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004, Christian Richter
- *
- * Christian Richter <crich@beronet.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- *
- */
-
-/*!
- * \file
- *
- * \brief the chan_misdn channel driver for Asterisk
- * \author Christian Richter <crich@beronet.com>
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <pthread.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <arpa/inet.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/file.h>
-
-#include <asterisk/channel.h>
-#include <asterisk/config.h>
-#include <asterisk/logger.h>
-#include <asterisk/module.h>
-#include <asterisk/pbx.h>
-#include <asterisk/options.h>
-#include <asterisk/io.h>
-#include <asterisk/frame.h>
-#include <asterisk/translate.h>
-#include <asterisk/cli.h>
-#include <asterisk/musiconhold.h>
-#include <asterisk/dsp.h>
-#include <asterisk/translate.h>
-#include <asterisk/config.h>
-#include <asterisk/file.h>
-#include <asterisk/callerid.h>
-#include <asterisk/indications.h>
-#include <asterisk/app.h>
-#include <asterisk/features.h>
-
-#include "chan_misdn_config.h"
-#include "isdn_lib.h"
-
-ast_mutex_t release_lock_mutex;
-
-#define release_lock ast_mutex_lock(&release_lock_mutex)
-#define release_unlock ast_mutex_unlock(&release_lock_mutex)
-
-
-/* BEGIN: chan_misdn.h */
-
-enum misdn_chan_state {
- MISDN_NOTHING, /*!< at beginning */
- MISDN_WAITING4DIGS, /*!< when waiting for infos */
- MISDN_EXTCANTMATCH, /*!< when asterisk couldnt match our ext */
- MISDN_DIALING, /*!< when pbx_start */
- MISDN_PROGRESS, /*!< we got a progress */
- MISDN_CALLING, /*!< when misdn_call is called */
- MISDN_CALLING_ACKNOWLEDGE, /*!< when we get SETUP_ACK */
- MISDN_ALERTING, /*!< when Alerting */
- MISDN_BUSY, /*!< when BUSY */
- MISDN_CONNECTED, /*!< when connected */
- MISDN_BRIDGED, /*!< when bridged */
- MISDN_CLEANING, /*!< when hangup from * but we were connected before */
- MISDN_HUNGUP_FROM_MISDN, /*!< when DISCONNECT/RELEASE/REL_COMP cam from misdn */
- MISDN_HUNGUP_FROM_AST, /*!< when DISCONNECT/RELEASE/REL_COMP came out of */
- /* misdn_hangup */
- MISDN_HOLDED, /*!< if this chan is holded */
- MISDN_HOLD_DISCONNECT /*!< if this chan is holded */
-
-};
-
-#define ORG_AST 1
-#define ORG_MISDN 2
-
-struct chan_list {
-
- ast_mutex_t lock;
-
- enum misdn_chan_state state;
- int holded;
- int orginator;
-
- int norxtone;
- int notxtone;
-
- int pipe[2];
- char ast_rd_buf[4096];
- struct ast_frame frame;
-
- int faxdetect;
- int faxhandled;
-
- int ast_dsp;
-
- struct ast_dsp *dsp;
- struct ast_trans_pvt *trans;
-
- struct ast_channel * ast;
-
- struct misdn_bchannel *bc;
- struct misdn_bchannel *holded_bc;
-
- unsigned int l3id;
- int addr;
-
- struct chan_list *peer;
- struct chan_list *next;
- struct chan_list *prev;
- struct chan_list *first;
-};
-
-struct robin_list {
- char *group;
- int port;
- int channel;
- struct robin_list *next;
- struct robin_list *prev;
-};
-static struct robin_list *robin = NULL;
-
-static inline void free_robin_list_r (struct robin_list *r)
-{
- if (r) {
- if (r->next) free_robin_list_r(r->next);
- if (r->group) free(r->group);
- free(r);
- }
-}
-
-static void free_robin_list ( void )
-{
- free_robin_list_r(robin);
- robin = NULL;
-}
-
-struct robin_list* get_robin_position (char *group)
-{
- struct robin_list *iter = robin;
- for (; iter; iter = iter->next) {
- if (!strcasecmp(iter->group, group))
- return iter;
- }
- struct robin_list *new = (struct robin_list *)calloc(1, sizeof(struct robin_list));
- new->group = strndup(group, strlen(group));
- new->channel = 1;
- if (robin) {
- new->next = robin;
- robin->prev = new;
- }
- robin = new;
- return robin;
-}
-
-struct ast_channel *misdn_new(struct chan_list *cl, int state, char * name, char * context, char *exten, char *callerid, int format, int port, int c);
-void send_digit_to_chan(struct chan_list *cl, char digit );
-
-
-#define AST_CID_P(ast) ast->cid.cid_num
-#define AST_BRIDGED_P(ast) ast_bridged_channel(ast)
-#define AST_LOAD_CFG ast_config_load
-#define AST_DESTROY_CFG ast_config_destroy
-
-#define MISDN_ASTERISK_TECH_PVT(ast) ast->tech_pvt
-#define MISDN_ASTERISK_PVT(ast) 1
-#define MISDN_ASTERISK_TYPE(ast) ast->tech->type
-
-/* END: chan_misdn.h */
-
-#include <asterisk/strings.h>
-
-/* #define MISDN_DEBUG 1 */
-
-static char *desc = "Channel driver for mISDN Support (Bri/Pri)";
-static char *type = "mISDN";
-
-int tracing = 0 ;
-
-static int usecnt=0;
-
-char **misdn_key_vector=NULL;
-int misdn_key_vector_size=0;
-
-/* Only alaw and mulaw is allowed for now */
-static int prefformat = AST_FORMAT_ALAW ; /* AST_FORMAT_SLINEAR ; AST_FORMAT_ULAW | */
-
-static ast_mutex_t usecnt_lock;
-
-int *misdn_debug;
-int *misdn_debug_only;
-int max_ports;
-
-struct chan_list dummy_cl;
-
-struct chan_list *cl_te=NULL;
-ast_mutex_t cl_te_lock;
-
-enum event_response_e
-cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data);
-
-void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc);
-
-void cl_queue_chan(struct chan_list **list, struct chan_list *chan);
-void cl_dequeue_chan(struct chan_list **list, struct chan_list *chan);
-struct chan_list *find_chan_by_bc(struct chan_list *list, struct misdn_bchannel *bc);
-void chan_misdn_log(int level, int port, char *tmpl, ...);
-void chan_misdn_trace_call(struct ast_channel *chan, int debug, char *tmpl, ...);
-
-static int start_bc_tones(struct chan_list *cl);
-static int stop_bc_tones(struct chan_list *cl);
-static void release_chan(struct misdn_bchannel *bc);
-
-static int misdn_set_opt_exec(struct ast_channel *chan, void *data);
-static int misdn_facility_exec(struct ast_channel *chan, void *data);
-
-/*************** Helpers *****************/
-
-static struct chan_list * get_chan_by_ast(struct ast_channel *ast)
-{
- struct chan_list *tmp;
-
- for (tmp=cl_te; tmp; tmp = tmp->next) {
- if ( tmp->ast == ast ) return tmp;
- }
-
- return NULL;
-}
-
-static struct chan_list * get_chan_by_ast_name(char *name)
-{
- struct chan_list *tmp;
-
- for (tmp=cl_te; tmp; tmp = tmp->next) {
- if ( tmp->ast && strcmp(tmp->ast->name,name) == 0) return tmp;
- }
-
- return NULL;
-}
-
-static char* tone2str(struct misdn_bchannel *bc)
-{
- static struct {
- char name[16];
- enum tone_e tone;
- } *tone, tone_buf[] = {
- {"NOTONE",TONE_NONE},
- {"DIAL",TONE_DIAL},
- {"BUSY",TONE_BUSY},
- {"ALERT",TONE_ALERTING},
- {"",TONE_NONE}
- };
-
-
- for (tone=&tone_buf[0]; tone->name[0]; tone++) {
- if (tone->tone == bc->tone) return tone->name;
- }
- return NULL;
-}
-
-static char *bearer2str(int cap) {
- static char *bearers[]={
- "Speech",
- "Audio 3.1k",
- "Unres Digital",
- "Res Digital",
- "Unknown Bearer"
- };
-
- switch (cap) {
- case INFO_CAPABILITY_SPEECH:
- return bearers[0];
- break;
- case INFO_CAPABILITY_AUDIO_3_1K:
- return bearers[1];
- break;
- case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:
- return bearers[2];
- break;
- case INFO_CAPABILITY_DIGITAL_RESTRICTED:
- return bearers[3];
- break;
- default:
- return bearers[4];
- break;
- }
-}
-
-static void print_bearer(struct misdn_bchannel *bc)
-{
-
- chan_misdn_log(2, bc->port, " --> Bearer: %s\n",bearer2str(bc->capability));
-
- switch(bc->law) {
- case INFO_CODEC_ALAW:
- chan_misdn_log(2, bc->port, " --> Codec: Alaw\n");
- break;
- case INFO_CODEC_ULAW:
- chan_misdn_log(2, bc->port, " --> Codec: Ulaw\n");
- break;
- }
-}
-/*************** Helpers END *************/
-
-void send_digit_to_chan(struct chan_list *cl, char digit )
-{
- static const char* dtmf_tones[] = {
- "!941+1336/100,!0/100", /* 0 */
- "!697+1209/100,!0/100", /* 1 */
- "!697+1336/100,!0/100", /* 2 */
- "!697+1477/100,!0/100", /* 3 */
- "!770+1209/100,!0/100", /* 4 */
- "!770+1336/100,!0/100", /* 5 */
- "!770+1477/100,!0/100", /* 6 */
- "!852+1209/100,!0/100", /* 7 */
- "!852+1336/100,!0/100", /* 8 */
- "!852+1477/100,!0/100", /* 9 */
- "!697+1633/100,!0/100", /* A */
- "!770+1633/100,!0/100", /* B */
- "!852+1633/100,!0/100", /* C */
- "!941+1633/100,!0/100", /* D */
- "!941+1209/100,!0/100", /* * */
- "!941+1477/100,!0/100" }; /* # */
- struct ast_channel *chan=cl->ast;
-
- if (digit >= '0' && digit <='9')
- ast_playtones_start(chan,0,dtmf_tones[digit-'0'], 0);
- else if (digit >= 'A' && digit <= 'D')
- ast_playtones_start(chan,0,dtmf_tones[digit-'A'+10], 0);
- else if (digit == '*')
- ast_playtones_start(chan,0,dtmf_tones[14], 0);
- else if (digit == '#')
- ast_playtones_start(chan,0,dtmf_tones[15], 0);
- else {
- /* not handled */
- ast_log(LOG_DEBUG, "Unable to handle DTMF tone '%c' for '%s'\n", digit, chan->name);
-
-
- }
-}
-/*** CLI HANDLING ***/
-static int misdn_set_debug(int fd, int argc, char *argv[])
-{
- if (argc != 4 && argc != 5 && argc != 6 && argc != 7)
- return RESULT_SHOWUSAGE;
-
- int level = atoi(argv[3]);
-
- switch (argc) {
- case 4:
- case 5: {
- int only = 0;
- if (argc == 5) {
- if (strncasecmp(argv[4], "only", strlen(argv[4])))
- return RESULT_SHOWUSAGE;
- else
- only = 1;
- }
- int i;
- for (i=0; i<=max_ports; i++) {
- misdn_debug[i] = level;
- misdn_debug_only[i] = only;
- }
- ast_cli(fd, "changing debug level for all ports to %d%s\n",misdn_debug[0], only?" (only)":"");
- }
- break;
- case 6:
- case 7: {
- if (strncasecmp(argv[4], "port", strlen(argv[4])))
- return RESULT_SHOWUSAGE;
- int port = atoi(argv[5]);
- if (port <= 0 || port > max_ports) {
- switch (max_ports) {
- case 0:
- ast_cli(fd, "port number not valid! no ports available so you won't get lucky with any number here...\n");
- break;
- case 1:
- ast_cli(fd, "port number not valid! only port 1 is availble.\n");
- break;
- default:
- ast_cli(fd, "port number not valid! only ports 1 to %d are available.\n", max_ports);
- }
- return 0;
- }
- if (argc == 7) {
- if (strncasecmp(argv[6], "only", strlen(argv[6])))
- return RESULT_SHOWUSAGE;
- else
- misdn_debug_only[port] = 1;
- } else
- misdn_debug_only[port] = 0;
- misdn_debug[port] = level;
- ast_cli(fd, "changing debug level to %d%s for port %d\n", misdn_debug[port], misdn_debug_only[port]?" (only)":"", port);
- }
- }
- return 0;
-}
-
-
-static int misdn_set_crypt_debug(int fd, int argc, char *argv[])
-{
- if (argc != 5 )return RESULT_SHOWUSAGE;
-
- return 0;
-}
-
-
-static int misdn_restart_port (int fd, int argc, char *argv[])
-{
- int port;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- port = atoi(argv[3]);
-
- misdn_lib_port_restart(port);
-
- return 0;
-}
-
-static int misdn_port_up (int fd, int argc, char *argv[])
-{
- int port;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- port = atoi(argv[3]);
-
- misdn_lib_get_port_up(port);
-
- return 0;
-}
-
-
-static int misdn_show_config (int fd, int argc, char *argv[])
-{
- char buffer[BUFFERSIZE];
- enum misdn_cfg_elements elem;
- int linebreak;
-
- int onlyport = -1;
- if (argc >= 4) {
- if (!sscanf(argv[3], "%d", &onlyport) || onlyport < 0) {
- ast_cli(fd, "Unknown option: %s\n", argv[3]);
- return RESULT_SHOWUSAGE;
- }
- }
-
- if (argc == 3 || onlyport == 0) {
- ast_cli(fd,"Misdn General-Config: \n");
- ast_cli(fd," -> VERSION: " CHAN_MISDN_VERSION "\n");
-
- for (elem = MISDN_GEN_FIRST + 1, linebreak = 1; elem < MISDN_GEN_LAST; elem++, linebreak++) {
- misdn_cfg_get_config_string( 0, elem, buffer, BUFFERSIZE);
- ast_cli(fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
- }
- }
-
- if (onlyport < 0) {
- int port = misdn_cfg_get_next_port(0);
- for (; port > 0; port = misdn_cfg_get_next_port(port)) {
- ast_cli(fd, "\n[PORT %d]\n", port);
- for (elem = MISDN_CFG_FIRST + 1, linebreak = 1; elem < MISDN_CFG_LAST; elem++, linebreak++) {
- misdn_cfg_get_config_string( port, elem, buffer, BUFFERSIZE);
- ast_cli(fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
- }
- ast_cli(fd, "\n");
- }
- }
-
- if (onlyport > 0) {
- if (misdn_cfg_is_port_valid(onlyport)) {
- ast_cli(fd, "[PORT %d]\n", onlyport);
- for (elem = MISDN_CFG_FIRST + 1, linebreak = 1; elem < MISDN_CFG_LAST; elem++, linebreak++) {
- misdn_cfg_get_config_string( onlyport, elem, buffer, BUFFERSIZE);
- ast_cli(fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
- }
- ast_cli(fd, "\n");
- } else {
- ast_cli(fd, "Port %d is not active!\n", onlyport);
- }
- }
- return 0;
-}
-
-
-
-struct state_struct {
- enum misdn_chan_state state;
- char txt[255] ;
-} ;
-
-struct state_struct state_array[] = {
- {MISDN_NOTHING,"NOTHING"}, /* at beginning */
- {MISDN_WAITING4DIGS,"WAITING4DIGS"}, /* when waiting for infos */
- {MISDN_EXTCANTMATCH,"EXTCANTMATCH"}, /* when asterisk couldnt match our ext */
- {MISDN_DIALING,"DIALING"}, /* when pbx_start */
- {MISDN_PROGRESS,"PROGRESS"}, /* when pbx_start */
- {MISDN_CALLING,"CALLING"}, /* when misdn_call is called */
- {MISDN_ALERTING,"ALERTING"}, /* when Alerting */
- {MISDN_BUSY,"BUSY"}, /* when BUSY */
- {MISDN_CONNECTED,"CONNECTED"}, /* when connected */
- {MISDN_BRIDGED,"BRIDGED"}, /* when bridged */
- {MISDN_CLEANING,"CLEANING"}, /* when hangup from * but we were connected before */
- {MISDN_HUNGUP_FROM_MISDN,"HUNGUP_FROM_MISDN"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */
- {MISDN_HOLDED,"HOLDED"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */
- {MISDN_HOLD_DISCONNECT,"HOLD_DISCONNECT"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */
- {MISDN_HUNGUP_FROM_AST,"HUNGUP_FROM_AST"} /* when DISCONNECT/RELEASE/REL_COMP came out of */
- /* misdn_hangup */
-};
-
-
-
-
-char *misdn_get_ch_state(struct chan_list *p)
-{
- int i;
- if( !p) return NULL;
-
- for (i=0; i< sizeof(state_array)/sizeof(struct state_struct); i++) {
- if ( state_array[i].state == p->state) return state_array[i].txt;
- }
-
- return NULL;
-}
-
-static int misdn_reload (int fd, int argc, char *argv[])
-{
- int i, cfg_debug;
-
- ast_cli(fd, "Reloading mISDN Config\n");
- chan_misdn_log(0, 0, "Dynamic Crypting Activation is not support during reload at the moment\n");
-
- free_robin_list();
-
- misdn_cfg_reload();
-
- {
- char tempbuf[BUFFERSIZE];
- misdn_cfg_get( 0, MISDN_GEN_TRACEFILE, tempbuf, BUFFERSIZE);
- if (strlen(tempbuf))
- tracing = 1;
- }
-
- misdn_cfg_get( 0, MISDN_GEN_DEBUG, &cfg_debug, sizeof(int));
- for (i = 0; i <= max_ports; i++) {
- misdn_debug[i] = cfg_debug;
- misdn_debug_only[i] = 0;
- }
-
- return 0;
-}
-
-static void print_bc_info (int fd, struct chan_list* help, struct misdn_bchannel* bc)
-{
- struct ast_channel *ast=help->ast;
- ast_cli(fd,
- "* Pid:%d Prt:%d Ch:%d Mode:%s Org:%s dad:%s oad:%s ctx:%s state:%s\n",
- bc->pid, bc->port, bc->channel,
- bc->nt?"NT":"TE",
- help->orginator == ORG_AST?"*":"I",
- ast?ast->exten:NULL,
- ast?AST_CID_P(ast):NULL,
- ast?ast->context:NULL,
- misdn_get_ch_state(help)
- );
- if (misdn_debug[bc->port] > 0)
- ast_cli(fd,
- " --> astname: %s\n"
- " --> ch_l3id: %x\n"
- " --> ch_addr: %x\n"
- " --> bc_addr: %x\n"
- " --> bc_l3id: %x\n"
- " --> tone: %s\n"
- " --> display: %s\n"
- " --> activated: %d\n"
- " --> capability: %s\n"
- " --> echo_cancel: %d\n"
- " --> notone : rx %d tx:%d\n"
- " --> bc_hold: %d holded_bc :%d\n",
- help->ast->name,
- help->l3id,
- help->addr,
- bc->addr,
- bc?bc->l3_id:-1,
- tone2str(bc),
- bc->display,
-
- bc->active,
- bearer2str(bc->capability),
- bc->ec_enable,
- help->norxtone,help->notxtone,
- bc->holded, help->holded_bc?1:0
- );
-
-}
-
-
-static int misdn_show_cls (int fd, int argc, char *argv[])
-{
- struct chan_list *help=cl_te;
-
- ast_cli(fd,"Chan List: %p\n",cl_te);
-
- for (;help; help=help->next) {
- struct misdn_bchannel *bc=help->bc;
- struct ast_channel *ast=help->ast;
- if (misdn_debug[0] > 2) ast_cli(fd, "Bc:%p Ast:%p\n", bc, ast);
- if (bc) {
- print_bc_info(fd, help, bc);
- } else if ( (bc=help->holded_bc) ) {
- chan_misdn_log(0, 0, "ITS A HOLDED BC:\n");
- print_bc_info(fd, help, bc);
- } else {
- ast_cli(fd,"* Channel in unknown STATE !!! Exten:%s, Callerid:%s\n", ast->exten, AST_CID_P(ast));
- }
- }
-
-
- return 0;
-}
-
-
-
-static int misdn_show_cl (int fd, int argc, char *argv[])
-{
- struct chan_list *help=cl_te;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- for (;help; help=help->next) {
- struct misdn_bchannel *bc=help->bc;
- struct ast_channel *ast=help->ast;
-
- if (bc && ast) {
- if (!strcasecmp(ast->name,argv[3])) {
- print_bc_info(fd, help, bc);
- break;
- }
- }
- }
-
-
- return 0;
-}
-
-ast_mutex_t lock;
-int MAXTICS=8;
-
-static int misdn_set_tics (int fd, int argc, char *argv[])
-{
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- MAXTICS=atoi(argv[3]);
-
- return 0;
-}
-
-
-
-static int misdn_show_stacks (int fd, int argc, char *argv[])
-{
- int port;
-
- ast_cli(fd, "BEGIN STACK_LIST:\n");
- for (port=misdn_cfg_get_next_port(0); port > 0;
- port=misdn_cfg_get_next_port(port)) {
- char buf[128];
- get_show_stack_details(port,buf);
- ast_cli(fd," %s Debug:%d%s\n", buf, misdn_debug[port], misdn_debug_only[port]?"(only)":"");
- }
-
-
- return 0;
-
-}
-
-static int misdn_show_port (int fd, int argc, char *argv[])
-{
- int port;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- port = atoi(argv[3]);
-
- ast_cli(fd, "BEGIN STACK_LIST:\n");
-
- char buf[128];
- get_show_stack_details(port,buf);
- ast_cli(fd," %s Debug:%d%s\n",buf, misdn_debug[port], misdn_debug_only[port]?"(only)":"");
-
-
- return 0;
-}
-
-static int misdn_send_cd (int fd, int argc, char *argv[])
-{
- char *channame;
- char *nr;
-
- if (argc != 5)
- return RESULT_SHOWUSAGE;
-
- channame = argv[3];
- nr = argv[4];
-
- ast_cli(fd, "Sending Calldeflection (%s) to %s\n",nr, channame);
-
- {
- struct chan_list *tmp=get_chan_by_ast_name(channame);
-
- if (!tmp) {
- ast_cli(fd, "Sending CD with nr %s to %s failed Channel does not exist\n",nr, channame);
- return 0;
- } else {
-
- misdn_lib_send_facility(tmp->bc, FACILITY_CALLDEFLECT, nr);
- }
- }
-
- return 0;
-}
-
-
-
-static int misdn_send_digit (int fd, int argc, char *argv[])
-{
- char *channame;
- char *msg;
-
- if (argc != 5)
- return RESULT_SHOWUSAGE;
-
- channame = argv[3];
- msg = argv[4];
-
- ast_cli(fd, "Sending %s to %s\n",msg, channame);
-
- {
- struct chan_list *tmp=get_chan_by_ast_name(channame);
-
- if (!tmp) {
- ast_cli(fd, "Sending %s to %s failed Channel does not exist\n",msg, channame);
- return 0;
- } else {
-#if 1
- int i;
- int msglen = strlen(msg);
- for (i=0; i<msglen; i++) {
- ast_cli(fd, "Sending: %c\n",msg[i]);
- send_digit_to_chan(tmp, msg[i]);
- /* res = ast_safe_sleep(tmp->ast, 250); */
- usleep(250000);
- /* res = ast_waitfor(tmp->ast,100); */
- }
-#else
- int res;
- res = ast_dtmf_stream(tmp->ast,NULL,msg,250);
-#endif
- }
- }
-
- return 0;
-}
-
-static int misdn_toggle_echocancel (int fd, int argc, char *argv[])
-{
- char *channame;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- channame = argv[3];
-
- ast_cli(fd, "Toggling EchoCancel on %s\n", channame);
-
- {
- struct chan_list *tmp=get_chan_by_ast_name(channame);
-
- if (!tmp) {
- ast_cli(fd, "Toggling EchoCancel %s failed Channel does not exist\n", channame);
- return 0;
- } else {
- tmp->bc->ec_enable=tmp->bc->ec_enable?0:1;
-
- if (tmp->bc->ec_enable) {
- manager_ec_enable(tmp->bc);
- } else {
- manager_ec_disable(tmp->bc);
- }
- }
- }
-
- return 0;
-}
-
-
-
-static int misdn_send_display (int fd, int argc, char *argv[])
-{
- char *channame;
- char *msg;
-
- if (argc != 5)
- return RESULT_SHOWUSAGE;
-
- channame = argv[3];
- msg = argv[4];
-
- ast_cli(fd, "Sending %s to %s\n",msg, channame);
- {
- struct chan_list *tmp;
- tmp=get_chan_by_ast_name(channame);
-
- if (tmp && tmp->bc) {
- int l = sizeof(tmp->bc->display);
- strncpy(tmp->bc->display, msg, l);
- tmp->bc->display[l-1] = 0;
- misdn_lib_send_event(tmp->bc, EVENT_INFORMATION);
- } else {
- ast_cli(fd,"No such channel %s\n",channame);
- return RESULT_FAILURE;
- }
- }
-
- return RESULT_SUCCESS ;
-}
-
-
-
-
-static char *complete_ch_helper(char *line, char *word, int pos, int state, int rpos)
-{
- struct ast_channel *c;
- int which=0;
- char *ret;
- if (pos != rpos)
- return NULL;
- c = ast_channel_walk_locked(NULL);
- while(c) {
- if (!strncasecmp(word, c->name, strlen(word))) {
- if (++which > state)
- break;
- }
- ast_mutex_unlock(&c->lock);
- c = ast_channel_walk_locked(c);
- }
- if (c) {
- ret = strdup(c->name);
- ast_mutex_unlock(&c->lock);
- } else
- ret = NULL;
- return ret;
-}
-
-static char *complete_ch(char *line, char *word, int pos, int state)
-{
- return complete_ch_helper(line, word, pos, state, 3);
-}
-
-static char *complete_debug_port (char *line, char *word, int pos, int state)
-{
- if (state)
- return NULL;
-
- switch (pos) {
- case 4: if (*word == 'p')
- return strdup("port");
- else if (*word == 'o')
- return strdup("only");
- break;
- case 6: if (*word == 'o')
- return strdup("only");
- break;
- }
- return NULL;
-}
-
-static struct ast_cli_entry cli_send_cd =
-{ {"misdn","send","calldeflect", NULL},
- misdn_send_cd,
- "Sends CallDeflection to mISDN Channel",
- "Usage: misdn send calldeflect <channel> \"<nr>\" \n",
- complete_ch
-};
-
-
-static struct ast_cli_entry cli_send_digit =
-{ {"misdn","send","digit", NULL},
- misdn_send_digit,
- "Sends DTMF Digit to mISDN Channel",
- "Usage: misdn send digit <channel> \"<msg>\" \n"
- " Send <digit> to <channel> as DTMF Tone\n"
- " when channel is a mISDN channel\n",
- complete_ch
-};
-
-
-static struct ast_cli_entry cli_toggle_echocancel =
-{ {"misdn","toggle","echocancel", NULL},
- misdn_toggle_echocancel,
- "Toggles EchoCancel on mISDN Channel",
- "Usage: misdn toggle echocancel <channel>\n",
- complete_ch
-};
-
-
-
-static struct ast_cli_entry cli_send_display =
-{ {"misdn","send","display", NULL},
- misdn_send_display,
- "Sends Text to mISDN Channel",
- "Usage: misdn send display <channel> \"<msg>\" \n"
- " Send <msg> to <channel> as Display Message\n"
- " when channel is a mISDN channel\n",
- complete_ch
-};
-
-
-static struct ast_cli_entry cli_show_config =
-{ {"misdn","show","config", NULL},
- misdn_show_config,
- "Shows internal mISDN config, read from cfg-file",
- "Usage: misdn show config [port | 0]\n use 0 to only print the general config.\n"
-};
-
-
-static struct ast_cli_entry cli_reload =
-{ {"misdn","reload", NULL},
- misdn_reload,
- "Reloads internal mISDN config, read from cfg-file",
- "Usage: misdn reload\n"
-};
-
-static struct ast_cli_entry cli_set_tics =
-{ {"misdn","set","tics", NULL},
- misdn_set_tics,
- "",
- "\n"
-};
-
-
-static struct ast_cli_entry cli_show_cls =
-{ {"misdn","show","channels", NULL},
- misdn_show_cls,
- "Shows internal mISDN chan_list",
- "Usage: misdn show channels\n"
-};
-
-static struct ast_cli_entry cli_show_cl =
-{ {"misdn","show","channel", NULL},
- misdn_show_cl,
- "Shows internal mISDN chan_list",
- "Usage: misdn show channels\n",
- complete_ch
-};
-
-
-
-static struct ast_cli_entry cli_restart_port =
-{ {"misdn","restart","port", NULL},
- misdn_restart_port,
- "Restarts the given port",
- "Usage: misdn restart port\n"
-};
-
-
-static struct ast_cli_entry cli_port_up =
-{ {"misdn","port","up", NULL},
- misdn_port_up,
- "Tries to establish L1 on the given port",
- "Usage: misdn port up <port>\n"
-};
-
-
-static struct ast_cli_entry cli_show_stacks =
-{ {"misdn","show","stacks", NULL},
- misdn_show_stacks,
- "Shows internal mISDN stack_list",
- "Usage: misdn show stacks\n"
-};
-
-static struct ast_cli_entry cli_show_port =
-{ {"misdn","show","port", NULL},
- misdn_show_port,
- "Shows detailed information for given port",
- "Usage: misdn show port <port>\n"
-};
-
-
-
-static struct ast_cli_entry cli_set_debug =
-{ {"misdn","set","debug", NULL},
- misdn_set_debug,
- "Sets Debuglevel of chan_misdn",
- "Usage: misdn set debug <level> [only] | [port <port> [only]]\n",
- complete_debug_port
-};
-
-static struct ast_cli_entry cli_set_crypt_debug =
-{ {"misdn","set","crypt","debug", NULL},
- misdn_set_crypt_debug,
- "Sets CryptDebuglevel of chan_misdn, at the moment, level={1,2}",
- "Usage: misdn set crypt debug <level>\n"
-};
-/*** CLI END ***/
-
-
-/*****************************/
-/*** AST Indications Start ***/
-/*****************************/
-
-static int misdn_call(struct ast_channel *ast, char *dest, int timeout)
-{
- int port=0;
- int r;
- struct chan_list *ch=MISDN_ASTERISK_TECH_PVT(ast);
- struct misdn_bchannel *newbc;
- char *opts=NULL, *ext=NULL;
- char dest_cp[256];
- char *tokb;
-
- {
- strncpy(dest_cp,dest,sizeof(dest_cp)-1);
- dest_cp[sizeof(dest_cp)]=0;
-
- ext=strtok_r(dest_cp,"/",&tokb);
-
- if (ext) {
- ext=strtok_r(NULL,"/",&tokb);
- if (ext) {
- opts=strtok_r(NULL,"/",&tokb);
- } else {
- chan_misdn_log(-1,0,"misdn_call: No Extension given!\n");
- return -1;
- }
- }
-
-
- }
-
- if (!ast) {
- ast_log(LOG_WARNING, " --> ! misdn_call called on ast_channel *ast where ast == NULL\n");
- return -1;
- }
-
- if (((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) || !dest ) {
- ast_log(LOG_WARNING, " --> ! misdn_call called on %s, neither down nor reserved (or dest==NULL)\n", ast->name);
- ast->hangupcause=41;
- ast_setstate(ast, AST_STATE_DOWN);
- return -1;
- }
-
-
- if (!ch) {
- ast_log(LOG_WARNING, " --> ! misdn_call called on %s, neither down nor reserved (or dest==NULL)\n", ast->name);
- ast->hangupcause=41;
- ast_setstate(ast, AST_STATE_DOWN);
- return -1;
- }
-
- newbc=ch->bc;
-
- if (!newbc) {
- ast_log(LOG_WARNING, " --> ! misdn_call called on %s, neither down nor reserved (or dest==NULL)\n", ast->name);
- ast->hangupcause=41;
- ast_setstate(ast, AST_STATE_DOWN);
- return -1;
- }
-
- port=newbc->port;
-
- ast_copy_string(newbc->dad, ext, sizeof(newbc->dad));
- ast_copy_string(ast->exten, ext, sizeof(ast->exten));
-
- chan_misdn_log(1, 0, "* CALL: %s\n",dest);
-
- chan_misdn_log(1, port, " --> * dad:%s tech:%s ctx:%s\n",ast->exten,ast->name, ast->context);
-
- {
- char context[BUFFERSIZE];
-
- misdn_cfg_get( port, MISDN_CFG_CONTEXT, context, sizeof(ast->context));
- {
- int l = sizeof(ast->context);
- strncpy(ast->context,context, l);
- ast->context[l-1] = 0;
- }
- chan_misdn_log(2, port, " --> * Setting Context to %s\n",context);
- misdn_cfg_get( port, MISDN_CFG_LANGUAGE, ast->language, BUFFERSIZE);
-
- misdn_cfg_get( port, MISDN_CFG_TXGAIN, &newbc->txgain, sizeof(int));
- misdn_cfg_get( port, MISDN_CFG_RXGAIN, &newbc->rxgain, sizeof(int));
-
- misdn_cfg_get( port, MISDN_CFG_TE_CHOOSE_CHANNEL, &(newbc->te_choose_channel), sizeof(int));
-
-
- {
- char callerid[BUFFERSIZE];
- misdn_cfg_get( port, MISDN_CFG_CALLERID, callerid, BUFFERSIZE);
- if ( ! ast_strlen_zero(callerid) ) {
- chan_misdn_log(1, port, " --> * Setting Cid to %s\n", callerid);
- {
- int l = sizeof(newbc->oad);
- strncpy(newbc->oad,callerid, l);
- newbc->oad[l-1] = 0;
- }
- }
-
-
- misdn_cfg_get( port, MISDN_CFG_DIALPLAN, &newbc->dnumplan, sizeof(int));
- switch (newbc->dnumplan) {
- case NUMPLAN_INTERNATIONAL:
- chan_misdn_log(2, port, " --> TON: International\n");
- break;
- case NUMPLAN_NATIONAL:
- chan_misdn_log(2, port, " --> TON: National\n");
- break;
- case NUMPLAN_SUBSCRIBER:
- chan_misdn_log(2, port, " --> TON: Subscriber\n");
- break;
- case NUMPLAN_UNKNOWN:
- chan_misdn_log(2, port, " --> TON: Unknown\n");
- break;
- /* Maybe we should cut off the prefix if present ? */
- default:
- chan_misdn_log(0, port, " --> !!!! Wrong dialplan setting, please see the misdn.conf sample file\n ");
- break;
- }
-
-
- misdn_cfg_get( port, MISDN_CFG_LOCALDIALPLAN, &newbc->onumplan, sizeof(int));
- switch (newbc->onumplan) {
- case NUMPLAN_INTERNATIONAL:
- chan_misdn_log(2, port, " --> TON: International\n");
- break;
- case NUMPLAN_NATIONAL:
- chan_misdn_log(2, port, " --> TON: National\n");
- break;
- case NUMPLAN_SUBSCRIBER:
- chan_misdn_log(2, port, " --> TON: Subscriber\n");
- break;
- case NUMPLAN_UNKNOWN:
- chan_misdn_log(2, port, " --> TON: Unknown\n");
- break;
- /* Maybe we should cut off the prefix if present ? */
- default:
- chan_misdn_log(0, port, " --> !!!! Wrong dialplan setting, please see the misdn.conf sample file\n ");
- break;
- }
- }
-
-
-
-
- {
- int eb3;
-
- misdn_cfg_get( port, MISDN_CFG_EARLY_BCONNECT, &eb3, sizeof(int));
- newbc->early_bconnect=eb3;
-
- }
-
-
-
- /* Will be overridden by asterisk in head! */
- {
- int pres;
-
- misdn_cfg_get( port, MISDN_CFG_PRES, &pres, sizeof(int));
- newbc->pres=pres?0:1;
-
- }
-
- int def_callingpres;
- misdn_cfg_get( port, MISDN_CFG_USE_CALLINGPRES, &def_callingpres, sizeof(int));
- if ( def_callingpres) {
-
- switch (ast->cid.cid_pres & 0x60){
-
- case AST_PRES_RESTRICTED:
- chan_misdn_log(2, port, " --> PRES: Restricted (0x1)\n");
- newbc->pres=1;
- break;
-
-
- case AST_PRES_UNAVAILABLE:
- chan_misdn_log(2, port, " --> PRES: Unavailable (0x2)\n");
- newbc->pres=2;
- break;
-
- default:
- chan_misdn_log(2, port, " --> PRES: Allowed (0x0)\n");
- newbc->pres=0;
- }
-
- switch (ast->cid.cid_pres & 0x3){
-
- case AST_PRES_USER_NUMBER_UNSCREENED:
- chan_misdn_log(2, port, " --> SCREEN: Unscreened (0x0)\n");
- newbc->screen=0;
- break;
-
- case AST_PRES_USER_NUMBER_PASSED_SCREEN:
- chan_misdn_log(2, port, " --> SCREEN: Passed Screen (0x1)\n");
- newbc->screen=1;
- break;
- case AST_PRES_USER_NUMBER_FAILED_SCREEN:
- chan_misdn_log(2, port, " --> SCREEN: Failed Screen (0x2)\n");
- newbc->screen=2;
- break;
-
- case AST_PRES_NETWORK_NUMBER:
- chan_misdn_log(2, port, " --> SCREEN: Network Nr. (0x3)\n");
- newbc->screen=3;
- break;
-
- default:
- chan_misdn_log(2, port, " --> SCREEN: Unscreened (0x0)\n");
- newbc->screen=0;
- }
- }
-
-
- {
- int ec, ectr;
-
- misdn_cfg_get( port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int));
-
- misdn_cfg_get( port, MISDN_CFG_ECHOTRAINING, &ectr, sizeof(int));
- if (ec == 1 ) {
- newbc->ec_enable=1;
- } else if ( ec > 1 ) {
- newbc->ec_enable=1;
- newbc->ec_deftaps=ec;
- }
-
-
- if (ectr>=0) {
- newbc->ec_training=ectr;
- }
-
- }
-
- }
-
- chan_misdn_log(3, port, " --> * adding2newbc ext %s\n",ast->exten);
- if (ast->exten) {
- int l = sizeof(newbc->dad);
- strncpy(newbc->dad,ast->exten, l);
- newbc->dad[l-1] = 0;
- }
- newbc->rad[0]=0;
- chan_misdn_log(3, port, " --> * adding2newbc callerid %s\n",AST_CID_P(ast));
- if (ast_strlen_zero(newbc->oad) && AST_CID_P(ast) ) {
- if (AST_CID_P(ast)) {
- int l = sizeof(newbc->oad);
- strncpy(newbc->oad,AST_CID_P(ast), l);
- newbc->oad[l-1] = 0;
- }
- }
-
- {
- struct chan_list *ch=MISDN_ASTERISK_TECH_PVT(ast);
- if (!ch) { ast_verbose("No chan_list in misdn_call"); return -1;}
- ch->bc = newbc;
- ch->orginator=ORG_AST;
- ch->ast = ast;
-
- MISDN_ASTERISK_TECH_PVT(ast) = ch ;
-
-
-
- newbc->capability=ast->transfercapability;
- pbx_builtin_setvar_helper(ast,"TRANSFERCAPABILITY",ast_transfercapability2str(newbc->capability));
- if ( ast->transfercapability == INFO_CAPABILITY_DIGITAL_UNRESTRICTED) {
- chan_misdn_log(2, port, " --> * Call with flag Digital\n");
- }
-
-
- /* Finally The Options Override Everything */
- if (opts)
- misdn_set_opt_exec(ast,opts);
- else
- chan_misdn_log(1,0,"NO OPTS GIVEN\n");
-
-
- cl_queue_chan(&cl_te, ch) ;
- ch->state=MISDN_CALLING;
-
- chan_misdn_trace_call(ast,1,"*->I: EVENT_CALL\n" );
-
- r=misdn_lib_send_event( newbc, EVENT_SETUP );
-
- /** we should have l3id after sending setup **/
- ch->l3id=newbc->l3_id;
- }
-
- if ( r == -ENOCHAN ) {
- chan_misdn_log(0, port, " --> * Theres no Channel at the moment .. !\n");
- chan_misdn_log(1, port, " --> * SEND: State Down pid:%d\n",newbc?newbc->pid:-1);
- ast->hangupcause=34;
- ast_setstate(ast, AST_STATE_DOWN);
- return -1;
- }
-
- chan_misdn_log(1, port, " --> * SEND: State Dialing pid:%d\n",newbc?newbc->pid:1);
-
- ast_setstate(ast, AST_STATE_DIALING);
-
- ast->hangupcause=16;
- return 0;
-}
-
-
-int misdn_answer(struct ast_channel *ast)
-{
- struct chan_list *p;
-
-
- if (!ast || ! MISDN_ASTERISK_PVT(ast)) return -1;
- p = MISDN_ASTERISK_TECH_PVT(ast) ;
-
- chan_misdn_trace_call(ast,1,"*->I: EVENT_ANSWER\n");
-
- chan_misdn_log(1, p? (p->bc? p->bc->port : 0) : 0, "* ANSWER:\n");
-
- if (!p) {
- ast_log(LOG_WARNING, " --> Channel not connected ??\n");
- ast_queue_hangup(ast);
- }
-
- if (!p->bc) {
- chan_misdn_log(1, 0, " --> Got Answer, but theres no bc obj ??\n");
-
- ast_queue_hangup(ast);
- }
-
- {
- char *tmp_key = pbx_builtin_getvar_helper(p->ast, "CRYPT_KEY");
-
- if (tmp_key ) {
- chan_misdn_log(1, p->bc->port, " --> Connection will be BF crypted\n");
- {
- int l = sizeof(p->bc->crypt_key);
- strncpy(p->bc->crypt_key,tmp_key, l);
- p->bc->crypt_key[l-1] = 0;
- }
- } else {
- chan_misdn_log(3, p->bc->port, " --> Connection is without BF encryption\n");
- }
-
- }
-
- {
- char *async=pbx_builtin_getvar_helper(ast, "MISDN_DIGITAL_TRANS");
- if (async) {
- chan_misdn_log(1, p->bc->port, " --> Connection is transparent digital\n");
- p->bc->async=1;
- }
- }
-
- p->state = MISDN_CONNECTED;
- misdn_lib_send_event( p->bc, EVENT_CONNECT);
- start_bc_tones(p);
-
- return 0;
-}
-
-int misdn_digit(struct ast_channel *ast, char digit )
-{
- struct chan_list *p;
-
- if (!ast || ! MISDN_ASTERISK_PVT(ast)) return -1;
- p = MISDN_ASTERISK_TECH_PVT(ast) ;
-
-
- struct misdn_bchannel *bc=p->bc;
- chan_misdn_log(1, bc?bc->port:0, "* IND : Digit %c\n",digit);
-
- if (!bc) {
- ast_log(LOG_WARNING, " --> !! Got Digit Event withut having bchannel Object\n");
- return -1;
- }
-
- switch (p->state ) {
- case MISDN_CALLING:
- {
-
- char buf[8];
- buf[0]=digit;
- buf[1]=0;
-
- int l = sizeof(bc->infos_pending);
- strncat(bc->infos_pending,buf,l);
- bc->infos_pending[l-1] = 0;
- }
- break;
- case MISDN_CALLING_ACKNOWLEDGE:
- {
- bc->info_dad[0]=digit;
- bc->info_dad[1]=0;
-
- {
- int l = sizeof(bc->dad);
- strncat(bc->dad,bc->info_dad, l - strlen(bc->dad));
- bc->dad[l-1] = 0;
- }
- {
- int l = sizeof(p->ast->exten);
- strncpy(p->ast->exten, bc->dad, l);
- p->ast->exten[l-1] = 0;
- }
-
- misdn_lib_send_event( bc, EVENT_INFORMATION);
- }
- break;
-
- default:
- if ( bc->send_dtmf ) {
- send_digit_to_chan(p,digit);
- }
- break;
- }
-
- return 0;
-}
-
-
-int misdn_fixup(struct ast_channel *oldast, struct ast_channel *ast)
-{
- struct chan_list *p;
-
- if (!ast || ! MISDN_ASTERISK_PVT(ast)) return -1;
- p = MISDN_ASTERISK_TECH_PVT(ast) ;
-
- chan_misdn_log(1, p->bc?p->bc->port:0, "* IND: Got Fixup State:%s Holded:%d L3id:%x\n", misdn_get_ch_state(p), p->holded, p->l3id);
-
- p->ast = ast ;
- p->state=MISDN_CONNECTED;
-
- return 0;
-}
-
-
-int misdn_transfer (struct ast_channel *ast, char *dest)
-{
- struct chan_list *p;
-
- if (!ast || ! MISDN_ASTERISK_PVT(ast)) return -1;
- p = MISDN_ASTERISK_TECH_PVT(ast) ;
-
- chan_misdn_log(1, p->bc?p->bc->port:0, "* IND : Got Transfer %s\n",dest);
- return 0;
-}
-
-
-
-int misdn_indication(struct ast_channel *ast, int cond)
-{
- struct chan_list *p;
-
-
- if (!ast || ! MISDN_ASTERISK_PVT(ast)) {
- ast_log(LOG_WARNING, "Returnded -1 in misdn_indication\n");
- return -1;
- }
- p = MISDN_ASTERISK_TECH_PVT(ast) ;
-
- if (!p->bc ) {
- chan_misdn_log(1, 0, "* IND : Indication from %s\n",ast->exten);
- ast_log(LOG_WARNING, "Private Pointer but no bc ?\n");
- return -1;
- }
-
- chan_misdn_log(1, p->bc->port, "* IND : Indication from %s\n",ast->exten);
-
- switch (cond) {
- case AST_CONTROL_BUSY:
- chan_misdn_log(1, p->bc->port, "* IND :\tbusy\n");
- chan_misdn_log(1, p->bc->port, " --> * SEND: State Busy pid:%d\n",p->bc?p->bc->pid:-1);
- ast_setstate(ast,AST_STATE_BUSY);
-
- p->bc->out_cause=17;
- if (p->state != MISDN_CONNECTED) {
- misdn_lib_send_event( p->bc, EVENT_DISCONNECT);
- manager_send_tone(p->bc, TONE_BUSY);
- } else {
- chan_misdn_log(0, p->bc->port, " --> !! Got Busy in Connected State !?! port:%d ast:%s\n",
- p->bc->port, ast->name);
- }
- break;
- case AST_CONTROL_RING:
- chan_misdn_log(1, p->bc->port, " --> * IND :\tring pid:%d\n",p->bc?p->bc->pid:-1);
- break;
- case AST_CONTROL_RINGING:
- if ( p->state == MISDN_ALERTING) {
- chan_misdn_log(1, p->bc->port, " --> * IND :\tringing pid:%d but I ws Ringing before, so ignoreing it\n",p->bc?p->bc->pid:-1);
- break;
- }
- p->state=MISDN_ALERTING;
-
- chan_misdn_log(1, p->bc->port, " --> * IND :\tringing pid:%d\n",p->bc?p->bc->pid:-1);
-
- misdn_lib_send_event( p->bc, EVENT_ALERTING);
-
- manager_send_tone(p->bc, TONE_ALERTING);
- chan_misdn_log(1, p->bc->port, " --> * SEND: State Ring pid:%d\n",p->bc?p->bc->pid:-1);
- ast_setstate(ast,AST_STATE_RINGING);
- break;
-
- case AST_CONTROL_ANSWER:
- chan_misdn_log(1, p->bc->port, " --> * IND :\tanswer pid:%d\n",p->bc?p->bc->pid:-1);
- break;
- case AST_CONTROL_TAKEOFFHOOK:
- chan_misdn_log(1, p->bc->port, " --> *\ttakeoffhook pid:%d\n",p->bc?p->bc->pid:-1);
- break;
- case AST_CONTROL_OFFHOOK:
- chan_misdn_log(1, p->bc->port, " --> *\toffhook pid:%d\n",p->bc?p->bc->pid:-1);
- break;
- case AST_CONTROL_FLASH:
- chan_misdn_log(1, p->bc->port, " --> *\tflash pid:%d\n",p->bc?p->bc->pid:-1);
- break;
- case AST_CONTROL_PROGRESS:
- chan_misdn_log(1, p->bc->port, " --> * IND :\tprogress pid:%d\n",p->bc?p->bc->pid:-1);
- break;
- case AST_CONTROL_CONGESTION:
- chan_misdn_log(1, p->bc->port, " --> * IND :\tcongestion pid:%d\n",p->bc?p->bc->pid:-1);
-
- p->bc->out_cause=42;
- if (p->state != MISDN_CONNECTED) {
- start_bc_tones(p);
- //misdn_lib_send_event( p->bc, EVENT_RELEASE_COMPLETE);
- misdn_lib_send_event( p->bc, EVENT_RELEASE);
- } else {
- misdn_lib_send_event( p->bc, EVENT_DISCONNECT);
- }
- if (p->bc->nt) {
- manager_send_tone(p->bc, TONE_BUSY);
- }
- break;
- case -1 :
- chan_misdn_log(1, p->bc->port, " --> * IND :\t-1! pid:%d\n",p->bc?p->bc->pid:-1);
- break;
- case AST_CONTROL_HOLD:
- chan_misdn_log(1, p->bc->port, " --> *\tHOLD pid:%d\n",p->bc?p->bc->pid:-1);
- break;
- case AST_CONTROL_UNHOLD:
- chan_misdn_log(1, p->bc->port, " --> *\tUNHOLD pid:%d\n",p->bc?p->bc->pid:-1);
- break;
- default:
- ast_log(LOG_WARNING, " --> * Unknown Indication:%d pid:%d\n",cond,p->bc?p->bc->pid:-1);
- }
-
- return 0;
-}
-
-int misdn_hangup(struct ast_channel *ast)
-{
- struct chan_list *p;
- struct misdn_bchannel *bc=NULL;
-
- if (!ast || ! (p=MISDN_ASTERISK_TECH_PVT(ast) ) ) return -1;
-
- release_lock;
-
- chan_misdn_trace_call(ast,1,"*->I: EVENT_HANGUP cause=%d\n",ast->hangupcause);
-
- ast_log(LOG_DEBUG, "misdn_hangup(%s)\n", ast->name);
-
- if (!p) {
- chan_misdn_log(3, 0, "misdn_hangup called, without chan_list obj.\n");
- release_unlock;
- return 0 ;
- }
-
- bc=p->bc;
-
- if (!bc) {
- release_unlock;
- ast_log(LOG_WARNING,"Hangup with private but no bc ?\n");
- return 0;
- }
-
-
- MISDN_ASTERISK_TECH_PVT(ast)=NULL;
- p->ast=NULL;
-
- if (ast->_state == AST_STATE_RESERVED) {
- /* between request and call */
- MISDN_ASTERISK_TECH_PVT(ast)=NULL;
- release_unlock;
-
- cl_dequeue_chan(&cl_te, p);
- free(p);
-
- misdn_lib_release(bc);
-
- return 0;
- }
-
- stop_bc_tones(p);
-
- release_unlock;
-
-
-
-
-
-
- {
- char *varcause=NULL;
- bc->cause=ast->hangupcause?ast->hangupcause:16;
-
- if ( (varcause=pbx_builtin_getvar_helper(ast, "HANGUPCAUSE")) ||
- (varcause=pbx_builtin_getvar_helper(ast, "PRI_CAUSE"))) {
- int tmpcause=atoi(varcause);
- bc->out_cause=tmpcause?tmpcause:16;
- }
-
- chan_misdn_log(1, bc->port, "* IND : HANGUP\tpid:%d ctx:%s dad:%s oad:%s State:%s\n",p->bc?p->bc->pid:-1, ast->context, ast->exten, AST_CID_P(ast), misdn_get_ch_state(p));
- chan_misdn_log(2, bc->port, " --> l3id:%x\n",p->l3id);
- chan_misdn_log(1, bc->port, " --> cause:%d\n",bc->cause);
- chan_misdn_log(1, bc->port, " --> out_cause:%d\n",bc->out_cause);
-
- switch (p->state) {
- case MISDN_CALLING:
- p->state=MISDN_CLEANING;
- misdn_lib_send_event( bc, EVENT_RELEASE_COMPLETE);
- break;
- case MISDN_HOLDED:
- case MISDN_DIALING:
- start_bc_tones(p);
- manager_send_tone(bc, TONE_BUSY);
- p->state=MISDN_CLEANING;
-
- misdn_lib_send_event( bc, EVENT_RELEASE_COMPLETE);
-
- break;
-
- case MISDN_ALERTING:
- chan_misdn_log(2, bc->port, " --> * State Alerting\n");
-
- if (p->orginator != ORG_AST)
- manager_send_tone(bc, TONE_BUSY);
-
- p->state=MISDN_CLEANING;
- misdn_lib_send_event( bc, EVENT_DISCONNECT);
- break;
- case MISDN_CONNECTED:
- /* Alerting or Disconect */
- chan_misdn_log(2, bc->port, " --> * State Connected\n");
- start_bc_tones(p);
- manager_send_tone(bc, TONE_BUSY);
- misdn_lib_send_event( bc, EVENT_DISCONNECT);
-
- p->state=MISDN_CLEANING; /* MISDN_HUNGUP_FROM_AST; */
- break;
-
- case MISDN_CLEANING:
- break;
-
- case MISDN_HOLD_DISCONNECT:
- /* need to send release here */
- chan_misdn_log(2, bc->port, " --> state HOLD_DISC\n");
- chan_misdn_log(1, bc->port, " --> cause %d\n",bc->cause);
- chan_misdn_log(1, bc->port, " --> out_cause %d\n",bc->out_cause);
-
- misdn_lib_send_event(bc,EVENT_RELEASE);
- break;
- default:
- /* Alerting or Disconect */
- if (bc->nt)
- misdn_lib_send_event(bc, EVENT_RELEASE);
- else
- misdn_lib_send_event(bc, EVENT_DISCONNECT);
- p->state=MISDN_CLEANING; /* MISDN_HUNGUP_FROM_AST; */
- }
-
- }
-
- chan_misdn_log(1, bc->port, "Channel: %s hanguped\n",ast->name);
-
- return 0;
-}
-
-struct ast_frame *misdn_read(struct ast_channel *ast)
-{
- struct chan_list *tmp;
-
- char blah[255];
- int len =0 ;
-
- if (!ast) return NULL;
- if (! (tmp=MISDN_ASTERISK_TECH_PVT(ast)) ) return NULL;
- if (!tmp->bc) return NULL;
-
-
- read(tmp->pipe[0],blah,sizeof(blah));
-
-
- len = misdn_ibuf_usedcount(tmp->bc->astbuf);
-
- /*shrinken len if necessary, we transmit at maximum 4k*/
- len = len<=sizeof(tmp->ast_rd_buf)?len:sizeof(tmp->ast_rd_buf);
-
- misdn_ibuf_memcpy_r(tmp->ast_rd_buf, tmp->bc->astbuf,len);
-
- tmp->frame.frametype = AST_FRAME_VOICE;
- tmp->frame.subclass = AST_FORMAT_ALAW;
- tmp->frame.datalen = len;
- tmp->frame.samples = len ;
- tmp->frame.mallocd =0 ;
- tmp->frame.offset= 0 ;
- tmp->frame.src = NULL;
- tmp->frame.data = tmp->ast_rd_buf ;
-
- chan_misdn_trace_call(tmp->ast,3,"*->I: EVENT_READ len=%d\n",len);
- return &tmp->frame;
-}
-
-int misdn_write(struct ast_channel *ast, struct ast_frame *frame)
-{
- struct chan_list *p;
- int i = 0;
-
- if (!ast || ! (p=MISDN_ASTERISK_TECH_PVT(ast)) ) return -1;
-
- if (!p->bc ) {
- ast_log(LOG_WARNING, "private but no bc\n");
- return -1;
- }
-
- if (p->bc->tone != TONE_NONE)
- manager_send_tone(p->bc,TONE_NONE);
-
-
- if (p->holded ) {
- chan_misdn_log(5, p->bc->port, "misdn_write: Returning because holded\n");
- return 0;
- }
-
- if (p->notxtone) {
- chan_misdn_log(5, p->bc->port, "misdn_write: Returning because notxone\n");
- return 0;
- }
-
- if ( !(frame->subclass & prefformat)) {
- chan_misdn_log(0, p->bc->port, "Got Unsupported Frame with Format:%d\n", frame->subclass);
- }
-
-
-#if MISDN_DEBUG
- {
- int i, max=5>frame->samples?frame->samples:5;
-
- printf("write2mISDN %p %d bytes: ", p, frame->samples);
-
- for (i=0; i< max ; i++) printf("%2.2x ",((char*) frame->data)[i]);
- printf ("\n");
- }
-#endif
- chan_misdn_trace_call(ast,3,"*->I: EVENT_WRITE len=%d\n",frame->samples);
- i= manager_tx2misdn_frm(p->bc, frame->data, frame->samples);
-
- return 0;
-}
-
-
-enum ast_bridge_result misdn_bridge (struct ast_channel *c0,
- struct ast_channel *c1, int flags,
- struct ast_frame **fo,
- struct ast_channel **rc,
- int timeoutms)
-
-{
- struct chan_list *ch1,*ch2;
- struct ast_channel *carr[2], *who;
- int to=-1;
- struct ast_frame *f;
-
- ch1=get_chan_by_ast(c0);
- ch2=get_chan_by_ast(c1);
-
- carr[0]=c0;
- carr[1]=c1;
-
-
- if (ch1 && ch2 ) ;
- else
- return -1;
-
-
- int bridging;
- misdn_cfg_get( 0, MISDN_GEN_BRIDGING, &bridging, sizeof(int));
- if (bridging) {
- int ecwb;
- misdn_cfg_get( ch1->bc->port, MISDN_CFG_ECHOCANCELWHENBRIDGED, &ecwb, sizeof(int));
- if ( !ecwb ) {
- chan_misdn_log(0, ch1->bc->port, "Disabling Echo Cancellor when Bridged\n");
- ch1->bc->ec_enable=0;
- manager_ec_disable(ch1->bc);
- }
- misdn_cfg_get( ch2->bc->port, MISDN_CFG_ECHOCANCELWHENBRIDGED, &ecwb, sizeof(int));
- if ( !ecwb ) {
- chan_misdn_log(0, ch2->bc->port, "Disabling Echo Cancellor when Bridged\n");
- ch2->bc->ec_enable=0;
- manager_ec_disable(ch2->bc);
- }
-
- /* trying to make a mISDN_dsp conference */
- chan_misdn_log(0, ch1->bc->port, "I SEND: Making conference with Number:%d\n", (ch1->bc->pid<<1) +1);
-
- misdn_lib_bridge(ch1->bc,ch2->bc);
- }
-
- chan_misdn_log(1, ch1->bc->port, "* Makeing Native Bridge between %s and %s\n", ch1->bc->oad, ch2->bc->oad);
-
- while(1) {
- to=-1;
- who = ast_waitfor_n(carr, 2, &to);
-
- if (!who) {
- ast_log(LOG_DEBUG,"misdn_bridge: empty read\n");
- continue;
- }
- f = ast_read(who);
-
- if (!f || f->frametype == AST_FRAME_CONTROL) {
- /* got hangup .. */
- *fo=f;
- *rc=who;
-
- break;
- }
-
-
- if (who == c0) {
- ast_write(c1,f);
- }
- else {
- ast_write(c0,f);
- }
-
- }
-
- if (bridging) {
- misdn_lib_split_bridge(ch1->bc,ch2->bc);
- }
-
- return 0;
-}
-
-/** AST INDICATIONS END **/
-
-static int start_bc_tones(struct chan_list* cl)
-{
- manager_bchannel_activate(cl->bc);
- manager_send_tone(cl->bc ,TONE_NONE);
- cl->notxtone=0;
- cl->norxtone=0;
- return 0;
-}
-
-static int stop_bc_tones(struct chan_list *cl)
-{
- if (cl->bc) {
- manager_bchannel_deactivate(cl->bc);
- }
- cl->notxtone=1;
- cl->norxtone=1;
-
- return 0;
-}
-
-
-struct chan_list *init_chan_list(void)
-{
- struct chan_list *cl=malloc(sizeof(struct chan_list));
-
- if (!cl) {
- chan_misdn_log(0, 0, "misdn_request: malloc failed!");
- return NULL;
- }
-
- memset(cl,0,sizeof(struct chan_list));
-
- return cl;
-
-}
-
-static struct ast_channel *misdn_request(const char *type, int format, void *data, int *cause)
-
-{
- struct ast_channel *tmp = NULL;
- char group[BUFFERSIZE]="";
- char buf[128];
- char buf2[128], *ext=NULL, *port_str;
- char *tokb=NULL, *p=NULL;
- int channel=0, port=0;
- struct misdn_bchannel *newbc = NULL;
-
- struct chan_list *cl=init_chan_list();
-
- sprintf(buf,"%s/%s",type,(char*)data);
- strncpy(buf2,data, 128);
- buf2[127] = 0;
- port_str=strtok_r(buf2,"/", &tokb);
-
- ext=strtok_r(NULL,"/", &tokb);
-
- /*
- if (!ext) {
- ast_log(LOG_WARNING, " --> ! IND : CALL dad:%s WITH WRONG ARGS, check extension.conf\n",ext);
-
- return NULL;
- }
- */
-
- if (port_str) {
- if (port_str[0]=='g' && port_str[1]==':' ) {
- /* We make a group call lets checkout which ports are in my group */
- port_str += 2;
- strncpy(group, port_str, BUFFERSIZE);
- group[127] = 0;
- chan_misdn_log(2, 0, " --> Group Call group: %s\n",group);
- }
- else if ((p = strchr(port_str, ':'))) {
- // we have a preselected channel
- *p = 0;
- channel = atoi(++p);
- port = atoi(port_str);
- chan_misdn_log(2, port, " --> Call on preselected Channel (%d) on Port %d\n", channel, port);
- }
- else {
- port = atoi(port_str);
- }
-
-
- } else {
- ast_log(LOG_WARNING, " --> ! IND : CALL dad:%s WITHOUT PORT/Group, check extension.conf\n",ext);
- return NULL;
- }
-
- if (!ast_strlen_zero(group)) {
-
- char cfg_group[BUFFERSIZE];
- struct robin_list *rr = NULL;
-
- if (misdn_cfg_is_group_method(group, METHOD_ROUND_ROBIN)) {
- chan_misdn_log(4, port, " --> STARTING ROUND ROBIN...");
- rr = get_robin_position(group);
- }
-
- if (rr) {
- int robin_channel = rr->channel;
- int port_start;
- int next_chan = 1;
-
- do {
- port_start = 0;
- for (port = misdn_cfg_get_next_port_spin(rr->port); port > 0 && port != port_start;
- port = misdn_cfg_get_next_port_spin(port)) {
-
- if (!port_start)
- port_start = port;
-
- if (port >= port_start)
- next_chan = 1;
-
- if (port < port_start && next_chan) {
- if (++robin_channel >= MAX_BCHANS) {
- robin_channel = 1;
- }
- next_chan = 0;
- }
-
- misdn_cfg_get(port, MISDN_CFG_GROUPNAME, cfg_group, BUFFERSIZE);
-
- if (!strcasecmp(cfg_group, group)) {
- int l1, port_up;
-
- misdn_cfg_get( 0, MISDN_GEN_L1_INFO_OK, &l1, sizeof(l1));
- port_up = misdn_lib_port_up(port);
-
- if ((l1 && port_up) || !l1) {
- newbc = misdn_lib_get_free_bc(port, robin_channel);
- if (newbc) {
- chan_misdn_log(4, port, " Success! Found port:%d channel:%d\n", newbc->port, newbc->channel);
- if (port_up)
- chan_misdn_log(4, port, "def_l1:%d, portup:%d\n", l1, port_up);
- rr->port = newbc->port;
- rr->channel = newbc->channel;
- break;
- }
- }
- }
- }
- } while (!newbc && robin_channel != rr->channel);
-
- if (!newbc)
- chan_misdn_log(4, port, " Failed! No free channel in group %d!", group);
- }
-
- else {
- for (port=misdn_cfg_get_next_port(0); port > 0;
- port=misdn_cfg_get_next_port(port)) {
-
- misdn_cfg_get( port, MISDN_CFG_GROUPNAME, cfg_group, BUFFERSIZE);
-
- if (!strcasecmp(cfg_group, group)) {
- int l1, port_up;
-
- misdn_cfg_get( 0, MISDN_GEN_L1_INFO_OK, &l1, sizeof(l1));
- port_up = misdn_lib_port_up(port);
-
- chan_misdn_log(4, port, "def_l1:%d, portup:%d\n", l1, port_up);
-
- if ((l1 && port_up) || !l1) {
- newbc = misdn_lib_get_free_bc(port, 0);
- if (newbc)
- break;
- }
- }
- }
- }
-
- } else {
- if (channel)
- chan_misdn_log(1, port," --> preselected_channel: %d\n",channel);
- newbc = misdn_lib_get_free_bc(port, channel);
- }
-
- if (!newbc) {
- chan_misdn_log(1, 0, " --> ! No free channel chan ext:%s even after Group Call\n",ext);
- chan_misdn_log(1, 0, " --> SEND: State Down\n");
- return NULL;
- }
-
- cl->bc=newbc;
-
- tmp = misdn_new(cl, AST_STATE_RESERVED, buf, "default", ext, ext, format, port, channel);
-
- return tmp;
-}
-
-
-struct ast_channel_tech misdn_tech = {
- .type="mISDN",
- .description="Channel driver for mISDN Support (Bri/Pri)",
- .capabilities= AST_FORMAT_ALAW ,
- .requester=misdn_request,
- .send_digit=misdn_digit,
- .call=misdn_call,
- .bridge=misdn_bridge,
- .hangup=misdn_hangup,
- .answer=misdn_answer,
- .read=misdn_read,
- .write=misdn_write,
- .indicate=misdn_indication,
- .fixup=misdn_fixup,
- .properties=0
- /* .transfer=misdn_transfer */
-};
-
-struct ast_channel_tech misdn_tech_wo_bridge = {
- .type="mISDN",
- .description="Channel driver for mISDN Support (Bri/Pri)",
- .capabilities=AST_FORMAT_ALAW ,
- .requester=misdn_request,
- .send_digit=misdn_digit,
- .call=misdn_call,
- .hangup=misdn_hangup,
- .answer=misdn_answer,
- .read=misdn_read,
- .write=misdn_write,
- .indicate=misdn_indication,
- .fixup=misdn_fixup,
- .properties=0
- /* .transfer=misdn_transfer */
-};
-
-
-unsigned long glob_channel=0;
-
-struct ast_channel *misdn_new(struct chan_list *chlist, int state, char * name, char * context, char *exten, char *callerid, int format, int port, int c)
-{
- struct ast_channel *tmp;
-
- tmp = ast_channel_alloc(1);
-
- if (tmp) {
- chan_misdn_log(2, 0, " --> * NEW CHANNEL dad:%s oad:%s ctx:%s\n",exten,callerid, context);
-
-
- if (c<=0) {
- c=glob_channel++;
- snprintf(tmp->name, sizeof(tmp->name), "%s/%d-u%d",
- type, port, c);
- } else {
- snprintf(tmp->name, sizeof(tmp->name), "%s/%d-%d",
- type, port, c);
- }
-
- tmp->type = type;
-
- tmp->nativeformats = prefformat;
- tmp->readformat = format;
- tmp->writeformat = format;
-
- tmp->tech_pvt = chlist;
-
- int bridging;
- misdn_cfg_get( 0, MISDN_GEN_BRIDGING, &bridging, sizeof(int));
- if (bridging)
- tmp->tech = &misdn_tech;
- else
- tmp->tech = &misdn_tech_wo_bridge;
-
-
- tmp->writeformat = format;
- tmp->readformat = format;
- tmp->priority=1;
-
-
- if (context) {
- ast_copy_string(tmp->context, context, sizeof(tmp->context));
- } else {
- chan_misdn_log(1,0,"misdn_new: no context given.\n");
- }
-
- if (exten) {
- ast_copy_string(tmp->exten, exten, sizeof(tmp->exten));
- } else {
- chan_misdn_log(1,0,"misdn_new: no exten given.\n");
- }
-
- if (callerid) {
- char *cid_name, *cid_num;
-
- ast_callerid_parse(callerid, &cid_name, &cid_num);
- if (cid_name)
- tmp->cid.cid_name=strdup(cid_name);
- if (cid_num)
- tmp->cid.cid_num=strdup(cid_num);
- }
-
- {
- if (pipe(chlist->pipe)<0)
- perror("Pipe failed\n");
-
- tmp->fds[0]=chlist->pipe[0];
-
- }
-
- if (chlist->bc) {
- int port=chlist->bc->port;
- misdn_cfg_get( port, MISDN_CFG_LANGUAGE, tmp->language, sizeof(tmp->language));
-
- {
- char buf[256];
- ast_group_t pg,cg;
-
- misdn_cfg_get(port, MISDN_CFG_PICKUPGROUP, &pg, sizeof(pg));
- misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg));
-
- chan_misdn_log(2, port, " --> * CallGrp:%s PickupGrp:%s\n",ast_print_group(buf,sizeof(buf),cg),ast_print_group(buf,sizeof(buf),pg));
- tmp->pickupgroup=pg;
- tmp->callgroup=cg;
- }
- misdn_cfg_get(port, MISDN_CFG_TXGAIN, &chlist->bc->txgain, sizeof(int));
- misdn_cfg_get(port, MISDN_CFG_RXGAIN, &chlist->bc->rxgain, sizeof(int));
- chan_misdn_log(2, port, " --> rxgain:%d txgain:%d\n",chlist->bc->rxgain,chlist->bc->txgain);
-
- } else {
- chan_misdn_log(3, 0, " --> Not Setting Pickupgroup, we have no bc yet\n");
- }
-
- ast_setstate(tmp, state);
- if (state == AST_STATE_RING)
- tmp->rings = 1;
- else
- tmp->rings = 0;
- } else {
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- chan_misdn_log(0,0,"Unable to allocate channel structure\n");
- }
-
- return tmp;
-}
-
-
-
-int misdn_tx2ast_frm(struct chan_list * tmp, char * buf, int len )
-{
- struct ast_frame frame;
-
- /* If in hold state we drop frame .. */
- if (tmp->holded ) return 0;
-
- switch(tmp->state) {
- case MISDN_CLEANING:
- case MISDN_EXTCANTMATCH:
- case MISDN_WAITING4DIGS:
- return 0;
- default:
- break;
- }
-
- if (tmp->norxtone) {
- chan_misdn_log(3, tmp->bc->port, "misdn_tx2ast_frm: Returning because norxtone\n");
- return 0;
- }
-
- frame.frametype = AST_FRAME_VOICE;
- frame.subclass = AST_FORMAT_ALAW;
- frame.datalen = len;
- frame.samples = len ;
- frame.mallocd =0 ;
- frame.offset= 0 ;
- frame.src = NULL;
- frame.data = buf ;
-
- if (tmp->faxdetect || tmp->ast_dsp ) {
- struct ast_frame *f,*f2;
- if (tmp->trans)
- f2=ast_translate(tmp->trans, &frame,0);
- else {
- chan_misdn_log(0, tmp->bc->port, "No T-Path found\n");
- return 0;
- }
-
- f = ast_dsp_process(tmp->ast, tmp->dsp, f2);
- if (f && (f->frametype == AST_FRAME_DTMF)) {
- ast_log(LOG_DEBUG, "Detected inband DTMF digit: %c", f->subclass);
- if (f->subclass == 'f' && tmp->faxdetect) {
- /* Fax tone -- Handle and return NULL */
- struct ast_channel *ast = tmp->ast;
- if (!tmp->faxhandled) {
- tmp->faxhandled++;
- if (strcmp(ast->exten, "fax")) {
- if (ast_exists_extension(ast, ast_strlen_zero(ast->macrocontext)? ast->context : ast->macrocontext, "fax", 1, AST_CID_P(ast))) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", ast->name);
- /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
- pbx_builtin_setvar_helper(ast,"FAXEXTEN",ast->exten);
- if (ast_async_goto(ast, ast->context, "fax", 1))
- ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, ast->context);
- } else
- ast_log(LOG_NOTICE, "Fax detected, but no fax extension ctx:%s exten:%s\n",ast->context, ast->exten);
- } else
- ast_log(LOG_DEBUG, "Already in a fax extension, not redirecting\n");
- } else
- ast_log(LOG_DEBUG, "Fax already handled\n");
- frame.frametype = AST_FRAME_NULL;
- frame.subclass = 0;
- f = &frame;
- } else if ( tmp->ast_dsp) {
- struct ast_frame fr;
- memset(&fr, 0 , sizeof(fr));
- fr.frametype = AST_FRAME_DTMF;
- fr.subclass = f->subclass ;
- fr.src=NULL;
- fr.data = NULL ;
- fr.datalen = 0;
- fr.samples = 0 ;
- fr.mallocd =0 ;
- fr.offset= 0 ;
-
- chan_misdn_log(2, tmp->bc->port, " --> * SEND: DTMF (AST_DSP) :%c\n",f->subclass);
- ast_queue_frame(tmp->ast, &fr);
-
- frame.frametype = AST_FRAME_NULL;
- frame.subclass = 0;
- f = &frame;
- }
- }
- }
-
- if (tmp && tmp->ast && MISDN_ASTERISK_PVT (tmp->ast) && MISDN_ASTERISK_TECH_PVT(tmp->ast) ) {
-#if MISDN_DEBUG
- int i, max=5>len?len:5;
-
- printf("write2* %p %d bytes: ",tmp, len);
-
- for (i=0; i< max ; i++) printf("%2.2x ",((char*) frame.data)[i]);
- printf ("\n");
-#endif
- chan_misdn_log(9, tmp->bc->port, "Queueing %d bytes 2 Asterisk\n",len);
- ast_queue_frame(tmp->ast,&frame);
-
- } else {
- ast_log (LOG_WARNING, "No ast || ast->pvt || ch\n");
- }
-
- return 0;
-}
-
-/** Channel Queue ***/
-
-struct chan_list *find_chan_by_l3id(struct chan_list *list, unsigned long l3id)
-{
- struct chan_list *help=list;
- for (;help; help=help->next) {
- if (help->l3id == l3id ) return help;
- }
-
- chan_misdn_log(4, list? (list->bc? list->bc->port : 0) : 0, "$$$ find_chan: No channel found with l3id:%x\n",l3id);
-
- return NULL;
-}
-
-struct chan_list *find_chan_by_bc(struct chan_list *list, struct misdn_bchannel *bc)
-{
- struct chan_list *help=list;
- for (;help; help=help->next) {
- if (help->bc == bc) return help;
- }
-
- chan_misdn_log(4, bc->port, "$$$ find_chan: No channel found for oad:%s dad:%s\n",bc->oad,bc->dad);
-
- return NULL;
-}
-
-
-struct chan_list *find_holded(struct chan_list *list, struct misdn_bchannel *bc)
-{
- struct chan_list *help=list;
-
- chan_misdn_log(4, bc->port, "$$$ find_holded: channel:%d oad:%s dad:%s\n",bc->channel, bc->oad,bc->dad);
- for (;help; help=help->next) {
- chan_misdn_log(4, bc->port, "$$$ find_holded: --> holded:%d channel:%d\n",help->bc->holded, help->bc->channel);
- if (help->bc->port == bc->port
- && help->bc->holded ) return help;
- }
-
- chan_misdn_log(4, bc->port, "$$$ find_chan: No channel found for oad:%s dad:%s\n",bc->oad,bc->dad);
-
- return NULL;
-}
-
-void cl_queue_chan(struct chan_list **list, struct chan_list *chan)
-{
- chan_misdn_log(4, chan->bc? chan->bc->port : 0, "* Queuing chan %p\n",chan);
-
- ast_mutex_lock(&cl_te_lock);
- if (!*list) {
- *list = chan;
- } else {
- struct chan_list *help=*list;
- for (;help->next; help=help->next);
- help->next=chan;
- }
- chan->next=NULL;
- ast_mutex_unlock(&cl_te_lock);
-}
-
-void cl_dequeue_chan(struct chan_list **list, struct chan_list *chan)
-{
- if (chan->dsp)
- ast_dsp_free(chan->dsp);
- if (chan->trans)
- ast_translator_free_path(chan->trans);
-
-
- ast_mutex_lock(&cl_te_lock);
- if (!*list) {
- ast_mutex_unlock(&cl_te_lock);
- return;
- }
-
- if (*list == chan) {
- *list=(*list)->next;
- ast_mutex_unlock(&cl_te_lock);
- return ;
- }
-
- {
- struct chan_list *help=*list;
- for (;help->next; help=help->next) {
- if (help->next == chan) {
- help->next=help->next->next;
- ast_mutex_unlock(&cl_te_lock);
- return;
- }
- }
- }
-
- ast_mutex_unlock(&cl_te_lock);
-}
-
-/** Channel Queue End **/
-
-
-
-/** Isdn asks us to release channel, pendant to misdn_hangup **/
-static void release_chan(struct misdn_bchannel *bc) {
- struct ast_channel *ast=NULL;
-
- {
- struct chan_list *ch=find_chan_by_bc(cl_te, bc);
- if (!ch) ch=find_chan_by_l3id (cl_te, bc->l3_id);
-
- release_lock;
- if (ch->ast) {
- ast=ch->ast;
- }
- release_unlock;
-
- chan_misdn_log(1, bc->port, "Trying to Release bc with l3id: %x\n",bc->l3_id);
- if (ch) {
- if (ast)
- chan_misdn_trace_call(ast,1,"I->*: EVENT_RELEASE\n");
-
- close(ch->pipe[0]);
- close(ch->pipe[1]);
-
- if (ast && MISDN_ASTERISK_PVT(ast)) {
- chan_misdn_log(1, bc->port, "* RELEASING CHANNEL pid:%d ctx:%s dad:%s oad:%s state: %s\n",bc?bc->pid:-1, ast->context, ast->exten,AST_CID_P(ast),misdn_get_ch_state(ch));
- chan_misdn_log(3, bc->port, " --> * State Down\n");
- /* copy cause */
- send_cause2ast(ast,bc);
-
- MISDN_ASTERISK_TECH_PVT(ast)=NULL;
-
-
- if (ast->_state != AST_STATE_RESERVED) {
- chan_misdn_log(3, bc->port, " --> Setting AST State to down\n");
- ast_setstate(ast, AST_STATE_DOWN);
- }
-
- switch(ch->state) {
- case MISDN_EXTCANTMATCH:
- case MISDN_WAITING4DIGS:
- {
- chan_misdn_log(3, bc->port, " --> * State Wait4dig | ExtCantMatch\n");
- ast_hangup(ast);
- }
- break;
-
- case MISDN_DIALING:
- case MISDN_CALLING_ACKNOWLEDGE:
- case MISDN_PROGRESS:
- chan_misdn_log(2, bc->port, "* --> In State Dialin\n");
- chan_misdn_log(2, bc->port, "* --> Queue Hangup\n");
-
-
- ast_queue_hangup(ast);
- break;
- case MISDN_CALLING:
-
- chan_misdn_log(2, bc->port, "* --> In State Callin\n");
-
- if (!bc->nt) {
- chan_misdn_log(2, bc->port, "* --> Queue Hangup\n");
- ast_queue_hangup(ast);
- } else {
- chan_misdn_log(2, bc->port, "* --> Hangup\n");
- ast_queue_hangup(ast);
- //ast_hangup(ast);
- }
- break;
-
- case MISDN_CLEANING:
- /* this state comes out of ast so we mustnt call a ast function ! */
- chan_misdn_log(2, bc->port, "* --> In StateCleaning\n");
- break;
- case MISDN_HOLD_DISCONNECT:
- chan_misdn_log(2, bc->port, "* --> In HOLD_DISC\n");
- break;
- default:
- chan_misdn_log(2, bc->port, "* --> In State Default\n");
- chan_misdn_log(2, bc->port, "* --> Queue Hangup\n");
-
-
- if (ast && MISDN_ASTERISK_PVT(ast)) {
- ast_queue_hangup(ast);
- } else {
- chan_misdn_log (0, bc->port, "!! Not really queued!\n");
- }
- }
- }
- cl_dequeue_chan(&cl_te, ch);
-
- free(ch);
- } else {
- /* chan is already cleaned, so exiting */
- }
- }
-}
-/*** release end **/
-
-void misdn_transfer_bc(struct chan_list *tmp_ch, struct chan_list *holded_chan)
-{
- chan_misdn_log(4,0,"TRANSFERING %s to %s\n",holded_chan->ast->name, tmp_ch->ast->name);
-
- tmp_ch->state=MISDN_HOLD_DISCONNECT;
-
- ast_moh_stop(AST_BRIDGED_P(holded_chan->ast));
-
- holded_chan->state=MISDN_CONNECTED;
- holded_chan->holded=0;
- misdn_lib_transfer(holded_chan->bc?holded_chan->bc:holded_chan->holded_bc);
-
- ast_channel_masquerade(holded_chan->ast, AST_BRIDGED_P(tmp_ch->ast));
-}
-
-
-void do_immediate_setup(struct misdn_bchannel *bc,struct chan_list *ch , struct ast_channel *ast)
-{
- char predial[256]="";
- char *p = predial;
-
- struct ast_frame fr;
-
- strncpy(predial, ast->exten, sizeof(predial) -1 );
-
- ch->state=MISDN_DIALING;
-
- if (bc->nt) {
- int ret;
- ret = misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
- } else {
- int ret;
- if ( misdn_lib_is_ptp(bc->port)) {
- ret = misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
- } else {
- ret = misdn_lib_send_event(bc, EVENT_PROCEEDING );
- }
- }
-
- manager_send_tone(bc,TONE_DIAL);
-
- chan_misdn_log(1, bc->port, "* Starting Ast ctx:%s dad:%s oad:%s with 's' extension\n", ast->context, ast->exten, AST_CID_P(ast));
-
- strncpy(ast->exten,"s", 2);
-
- if (ast_pbx_start(ast)<0) {
- ast=NULL;
- manager_send_tone(bc,TONE_BUSY);
- if (bc->nt)
- misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
- else
- misdn_lib_send_event(bc, EVENT_DISCONNECT );
- }
-
-
- while (!ast_strlen_zero(p) ) {
- fr.frametype = AST_FRAME_DTMF;
- fr.subclass = *p ;
- fr.src=NULL;
- fr.data = NULL ;
- fr.datalen = 0;
- fr.samples = 0 ;
- fr.mallocd =0 ;
- fr.offset= 0 ;
-
- if (ch->ast && MISDN_ASTERISK_PVT(ch->ast) && MISDN_ASTERISK_TECH_PVT(ch->ast)) {
- ast_queue_frame(ch->ast, &fr);
- }
- p++;
- }
-}
-
-
-
-void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc) {
-
- ast->hangupcause=bc->cause;
-
- switch ( bc->cause) {
-
- case 1: /** Congestion Cases **/
- case 2:
- case 3:
- case 4:
- case 22:
- case 27:
- chan_misdn_log(1, bc?bc->port:0, " --> * SEND: Queue Congestion pid:%d\n", bc?bc->pid:-1);
-
- ast_queue_control(ast, AST_CONTROL_CONGESTION);
- break;
-
- case 21:
- case 17: /* user busy */
- chan_misdn_log(1, bc?bc->port:0, " --> * SEND: Queue Busy pid:%d\n", bc?bc->pid:-1);
-
- ast_queue_control(ast, AST_CONTROL_BUSY);
-
- break;
- }
-}
-
-/************************************************************/
-/* Receive Events from isdn_lib here */
-/************************************************************/
-enum event_response_e
-cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
-{
- struct chan_list *ch=find_chan_by_bc(cl_te, bc);
-
- if (!ch)
- ch=find_chan_by_l3id(cl_te, bc->l3_id);
-
- if (event != EVENT_BCHAN_DATA) { /* Debug Only Non-Bchan */
- chan_misdn_log(1, bc->port, "I IND :%s oad:%s dad:%s port:%d\n", manager_isdn_get_info(event), bc->oad, bc->dad, bc->port);
- misdn_lib_log_ies(bc);
- }
-
- if (event != EVENT_SETUP) {
- if (!ch) {
- if (event != EVENT_CLEANUP )
- ast_log(LOG_WARNING, "Chan not existing at the moment bc->l3id:%x bc:%p event:%s port:%d channel:%d\n",bc->l3_id, bc, manager_isdn_get_info( event), bc->port,bc->channel);
- return -1;
- }
- }
-
- if (ch ) {
- switch (event) {
- case EVENT_RELEASE:
- case EVENT_RELEASE_COMPLETE:
- case EVENT_CLEANUP:
- break;
- default:
- if ( !ch->ast || !MISDN_ASTERISK_PVT(ch->ast) || !MISDN_ASTERISK_TECH_PVT(ch->ast)) {
- if (event!=EVENT_BCHAN_DATA)
- ast_log(LOG_WARNING, "No Ast or No private Pointer in Event (%d:%s)\n", event, manager_isdn_get_info(event));
- return -1;
- }
- }
- }
-
-
- switch (event) {
- case EVENT_NEW_L3ID:
- ch->l3id=bc->l3_id;
- break;
-
- case EVENT_NEW_BC:
- if (bc)
- ch->bc=bc;
- break;
-
- case EVENT_DTMF_TONE:
- {
- /* sending INFOS as DTMF-Frames :) */
- struct ast_frame fr;
- memset(&fr, 0 , sizeof(fr));
- fr.frametype = AST_FRAME_DTMF;
- fr.subclass = bc->dtmf ;
- fr.src=NULL;
- fr.data = NULL ;
- fr.datalen = 0;
- fr.samples = 0 ;
- fr.mallocd =0 ;
- fr.offset= 0 ;
-
- chan_misdn_log(2, bc->port, " --> DTMF:%c\n", bc->dtmf);
-
- ast_queue_frame(ch->ast, &fr);
- }
- break;
- case EVENT_STATUS:
- break;
-
- case EVENT_INFORMATION:
- {
- int stop_tone;
- misdn_cfg_get( 0, MISDN_GEN_STOP_TONE, &stop_tone, sizeof(int));
- if ( stop_tone && bc->tone != TONE_NONE) {
- manager_send_tone(bc,TONE_NONE);
- }
-
- if (ch->state == MISDN_WAITING4DIGS ) {
- /* Ok, incomplete Setup, waiting till extension exists */
- {
- int l = sizeof(bc->dad);
- strncat(bc->dad,bc->info_dad, l);
- bc->dad[l-1] = 0;
- }
-
-
- {
- int l = sizeof(ch->ast->exten);
- strncpy(ch->ast->exten, bc->dad, l);
- ch->ast->exten[l-1] = 0;
- }
-/* chan_misdn_log(5, bc->port, "Can Match Extension: dad:%s oad:%s\n",bc->dad,bc->oad);*/
-
- char bc_context[BUFFERSIZE];
- misdn_cfg_get( bc->port, MISDN_CFG_CONTEXT, bc_context, BUFFERSIZE);
- if(!ast_canmatch_extension(ch->ast, bc_context, bc->dad, 1, bc->oad)) {
- chan_misdn_log(0, bc->port, "Extension can never match, so disconnecting\n");
- manager_send_tone(bc,TONE_BUSY);
- ch->state=MISDN_EXTCANTMATCH;
- bc->out_cause=1;
- if (bc->nt)
- misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
- else
- misdn_lib_send_event(bc, EVENT_DISCONNECT );
- break;
- }
- if (ast_exists_extension(ch->ast, bc_context, bc->dad, 1, bc->oad)) {
- ch->state=MISDN_DIALING;
-
- manager_send_tone(bc,TONE_NONE);
-/* chan_misdn_log(1, bc->port, " --> * Starting Ast ctx:%s\n", ch->ast->context);*/
- if (ast_pbx_start(ch->ast)<0) {
- chan_misdn_log(0, bc->port, "ast_pbx_start returned < 0 in INFO\n");
- manager_send_tone(bc,TONE_BUSY);
- if (bc->nt)
- misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
- else
- misdn_lib_send_event(bc, EVENT_DISCONNECT );
- }
- }
-
- } else {
- /* sending INFOS as DTMF-Frames :) */
- struct ast_frame fr;
- fr.frametype = AST_FRAME_DTMF;
- fr.subclass = bc->info_dad[0] ;
- fr.src=NULL;
- fr.data = NULL ;
- fr.datalen = 0;
- fr.samples = 0 ;
- fr.mallocd =0 ;
- fr.offset= 0 ;
-
-
- int digits;
- misdn_cfg_get( 0, MISDN_GEN_APPEND_DIGITS2EXTEN, &digits, sizeof(int));
- if (ch->state != MISDN_CONNECTED ) {
- if (digits) {
- int l = sizeof(bc->dad);
- strncat(bc->dad,bc->info_dad, l);
- bc->dad[l-1] = 0;
- l = sizeof(ch->ast->exten);
- strncpy(ch->ast->exten, bc->dad, l);
- ch->ast->exten[l-1] = 0;
-
- ast_cdr_update(ch->ast);
- }
-
- ast_queue_frame(ch->ast, &fr);
- }
-
- }
- }
- break;
- case EVENT_SETUP:
- {
- struct chan_list *ch=find_chan_by_bc(cl_te, bc);
- if (ch && ch->state != MISDN_NOTHING ) {
- chan_misdn_log(1, bc->port, " --> Ignoring Call we have already one\n");
- return RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE; /* Ignore MSNs which are not in our List */
- }
- }
-
- int msn_valid = misdn_cfg_is_msn_valid(bc->port, bc->dad);
- if (!bc->nt && ! msn_valid) {
- chan_misdn_log(1, bc->port, " --> Ignoring Call, its not in our MSN List\n");
- return RESPONSE_IGNORE_SETUP; /* Ignore MSNs which are not in our List */
- }
-
- print_bearer(bc);
-
- {
- struct chan_list *ch=init_chan_list();
- struct ast_channel *chan;
- char name[128];
- if (!ch) { chan_misdn_log(0, bc->port, "cb_events: malloc for chan_list failed!\n"); return 0;}
-
- ch->bc = bc;
- ch->l3id=bc->l3_id;
- ch->addr=bc->addr;
- ch->orginator = ORG_MISDN;
-
-
- {
- char prefix[BUFFERSIZE]="";
- switch( bc->onumplan ) {
- case NUMPLAN_INTERNATIONAL:
- misdn_cfg_get( bc->port, MISDN_CFG_INTERNATPREFIX, prefix, BUFFERSIZE);
- break;
-
- case NUMPLAN_NATIONAL:
- misdn_cfg_get( bc->port, MISDN_CFG_NATPREFIX, prefix, BUFFERSIZE);
- break;
-
-
- case NUMPLAN_SUBSCRIBER:
- /* dunno what to do here ? */
- break;
-
- case NUMPLAN_UNKNOWN:
- break;
- default:
- break;
- }
-
- {
- int l = strlen(prefix) + strlen(bc->oad);
- char tmp[l+1];
- strcpy(tmp,prefix);
- strcat(tmp,bc->oad);
- strcpy(bc->oad,tmp);
- }
-
- if (!ast_strlen_zero(bc->oad))
- sprintf(name,"mISDN/%d/%s",bc->port,bc->oad);
- else
- sprintf(name,"mISDN/%d",bc->port);
-
-
- if (!ast_strlen_zero(bc->dad)) {
- strncpy(bc->orig_dad,bc->dad, sizeof(bc->orig_dad));
- bc->orig_dad[sizeof(bc->orig_dad)-1] = 0;
- }
-
- if ( ast_strlen_zero(bc->dad) && !ast_strlen_zero(bc->keypad)) {
- strncpy(bc->dad,bc->keypad, sizeof(bc->dad));
- bc->dad[sizeof(bc->dad)-1] = 0;
- }
- prefix[0] = 0;
-
- switch( bc->dnumplan ) {
- case NUMPLAN_INTERNATIONAL:
- misdn_cfg_get( bc->port, MISDN_CFG_INTERNATPREFIX, prefix, BUFFERSIZE);
- break;
-
- case NUMPLAN_NATIONAL:
- misdn_cfg_get( bc->port, MISDN_CFG_NATPREFIX, prefix, BUFFERSIZE);
- break;
-
-
- case NUMPLAN_SUBSCRIBER:
- /* dunno what to do here ? */
- break;
-
- case NUMPLAN_UNKNOWN:
- break;
- default:
- break;
- }
-
- {
- int l = strlen(prefix) + strlen(bc->dad);
- char tmp[l+1];
- strcpy(tmp,prefix);
- strcat(tmp,bc->dad);
- strcpy(bc->dad,tmp);
- }
-
- char bc_context[BUFFERSIZE];
- misdn_cfg_get( bc->port, MISDN_CFG_CONTEXT, bc_context, BUFFERSIZE);
- chan=misdn_new(ch, AST_STATE_RING,name ,bc_context, bc->dad, bc->oad, AST_FORMAT_ALAW, bc->port, bc->channel);
-
- if (!chan) {
- misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
- return 0;
- }
-
- ch->ast = chan;
- pbx_builtin_setvar_helper(ch->ast,"REDIRECTING_NUMBER",bc->rad);
-
- }
-
-
-
- chan_misdn_trace_call(chan,1,"I->*: EVENT_SETUP\n");
-
- if ( bc->pres ) {
- chan->cid.cid_pres=AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
- } else {
- chan->cid.cid_pres=AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
- }
-
- pbx_builtin_setvar_helper(chan, "TRANSFERCAPABILITY", ast_transfercapability2str(bc->capability));
- chan->transfercapability=bc->capability;
-
- switch (bc->capability) {
- case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:
- pbx_builtin_setvar_helper(chan,"CALLTYPE","DIGITAL");
- break;
- default:
- pbx_builtin_setvar_helper(chan,"CALLTYPE","SPEECH");
- }
-
- /** queue new chan **/
- cl_queue_chan(&cl_te, ch) ;
-
-
- /*
- added support for s extension hope it will help those poor cretains
- which haven't overlap dial.
- */
- {
-
- misdn_cfg_get( bc->port, MISDN_CFG_LANGUAGE, chan->language, sizeof(chan->language));
-
- }
-
- {
- int eb3;
-
- misdn_cfg_get( bc->port, MISDN_CFG_EARLY_BCONNECT, &eb3, sizeof(int));
- bc->early_bconnect=eb3;
-
- }
-
- {
- int ec, ectr;
-
- misdn_cfg_get( bc->port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int));
-
- misdn_cfg_get( bc->port, MISDN_CFG_ECHOTRAINING, &ectr, sizeof(int));
- if (ec == 1 ) {
- bc->ec_enable=1;
- } else if ( ec > 1 ) {
- bc->ec_enable=1;
- bc->ec_deftaps=ec;
- }
-
- if ( ectr>=0 ) {
- bc->ec_training=ectr;
- }
- }
-
-
- if (bc->urate>0) {
- char buf[16];
- snprintf(buf,16,"%d",bc->urate);
- pbx_builtin_setvar_helper(chan,"MISDN_URATE",buf);
- }
-
-
-
- /**
- from here on we start the PBX, so no configuration should
- be considered anymore
- **/
-
- int ai;
- misdn_cfg_get( bc->port, MISDN_CFG_ALWAYS_IMMEDIATE, &ai, sizeof(ai));
- if ( ai ) {
- do_immediate_setup(bc, ch , chan);
- break;
- }
-
-
- int immediate;
- misdn_cfg_get( bc->port, MISDN_CFG_IMMEDIATE, &immediate, sizeof(int));
-
- if (ast_strlen_zero(bc->orig_dad) && immediate ) {
- do_immediate_setup(bc, ch , chan);
- break;
- }
-
- /* Check for Pickup Request first */
- if (!strcmp(chan->exten, ast_pickup_ext())) {
- int ret;/** Sending SETUP_ACK**/
- ret = misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
-
- if (ast_pickup_call(chan)) {
- ast_hangup(chan);
- } else {
- ch->state = MISDN_CALLING_ACKNOWLEDGE;
-
- ch->ast=NULL;
-
- ast_setstate(chan, AST_STATE_DOWN);
- ast_hangup(chan);
-
- break;
- }
- }
-
- /** Now after we've finished configuring our channel object
- we'll jump into the dialplan **/
-
- char bc_context[BUFFERSIZE];
- misdn_cfg_get( bc->port, MISDN_CFG_CONTEXT, bc_context, BUFFERSIZE);
- if(!ast_canmatch_extension(ch->ast, bc_context, bc->dad, 1, bc->oad)) {
- chan_misdn_log(0, bc->port, "Extension can never match, so disconnecting\n");
- manager_send_tone(bc,TONE_BUSY);
- ch->state=MISDN_EXTCANTMATCH;
- bc->out_cause=1;
- if (bc->nt)
- misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
- else
- misdn_lib_send_event(bc, EVENT_DISCONNECT );
- break;
- }
-
- if (ast_exists_extension(ch->ast, bc_context, bc->dad, 1, bc->oad)) {
- ch->state=MISDN_DIALING;
-
- if (bc->nt) {
- int ret;
- ret = misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
- } else {
- int ret;
- ret= misdn_lib_send_event(bc, EVENT_PROCEEDING );
- }
-
- if (ast_pbx_start(chan)<0) {
- chan_misdn_log(0, bc->port, "ast_pbx_start returned <0 in SETUP\n");
- chan=NULL;
- manager_send_tone(bc,TONE_BUSY);
- if (bc->nt)
- misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
- else
- misdn_lib_send_event(bc, EVENT_DISCONNECT );
- }
- } else {
- int ret= misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
- if (ret == -ENOCHAN) {
- ast_log(LOG_WARNING,"Channel was catched, before we could Acknowledge\n");
- misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
- }
- /* send tone to phone :) */
-
- int stop_tone;
- misdn_cfg_get( 0, MISDN_GEN_STOP_TONE, &stop_tone, sizeof(int));
- if ( (!ast_strlen_zero(bc->dad)) && stop_tone )
- manager_send_tone(bc,TONE_NONE);
- else
- manager_send_tone(bc,TONE_DIAL);
-
- ch->state=MISDN_WAITING4DIGS;
- }
-
- }
- break;
- case EVENT_SETUP_ACKNOWLEDGE:
- {
- ch->state = MISDN_CALLING_ACKNOWLEDGE;
- if (!ast_strlen_zero(bc->infos_pending)) {
- /* TX Pending Infos */
-
- {
- int l = sizeof(bc->dad);
- strncat(bc->dad,bc->infos_pending, l - strlen(bc->dad));
- bc->dad[l-1] = 0;
- }
- {
- int l = sizeof(ch->ast->exten);
- strncpy(ch->ast->exten, bc->dad, l);
- ch->ast->exten[l-1] = 0;
- }
- {
- int l = sizeof(bc->info_dad);
- strncpy(bc->info_dad, bc->infos_pending, l);
- bc->info_dad[l-1] = 0;
- }
- strncpy(bc->infos_pending,"", 1);
-
- misdn_lib_send_event(bc, EVENT_INFORMATION);
- }
- }
- break;
- case EVENT_PROCEEDING:
- {
-
- if ( misdn_cap_is_speech(bc->capability) &&
- misdn_inband_avail(bc) ) {
- start_bc_tones(ch);
- }
- }
- break;
- case EVENT_PROGRESS:
- if (!bc->nt ) {
- if ( misdn_cap_is_speech(bc->capability) &&
- misdn_inband_avail(bc)
- ) {
- start_bc_tones(ch);
- }
-
- ast_queue_control(ch->ast, AST_CONTROL_PROGRESS);
-
- ch->state=MISDN_PROGRESS;
- }
- break;
-
-
- case EVENT_ALERTING:
- {
- ch->state = MISDN_ALERTING;
-
- ast_queue_control(ch->ast, AST_CONTROL_RINGING);
- ast_setstate(ch->ast, AST_STATE_RINGING);
-
- cb_log(1,bc->port,"Set State Ringing\n");
-
- if ( misdn_cap_is_speech(bc->capability) && misdn_inband_avail(bc)) {
- start_bc_tones(ch);
- }
- }
- break;
- case EVENT_CONNECT:
- misdn_lib_send_event(bc,EVENT_CONNECT_ACKNOWLEDGE);
- case EVENT_CONNECT_ACKNOWLEDGE:
- {
- bc->state=STATE_CONNECTED;
-
- ch->l3id=bc->l3_id;
- ch->addr=bc->addr;
-
- start_bc_tones(ch);
-
- chan_misdn_trace_call(ch->ast,1,"I->*: EVENT_CONNECT\n");
-
- ch->state = MISDN_CONNECTED;
- ast_queue_control(ch->ast, AST_CONTROL_ANSWER);
- }
- break;
- case EVENT_DISCONNECT:
- {
-
- struct chan_list *holded_ch=find_holded(cl_te, bc);
-
-
- send_cause2ast(ch->ast,bc);
-
- if (misdn_inband_avail(bc) && ch->state != MISDN_CONNECTED) {
- /* If there's inband information available (e.g. a
- recorded message saying what was wrong with the
- dialled number, or perhaps even giving an
- alternative number, then play it instead of
- immediately releasing the call */
- start_bc_tones(ch);
- break;
- }
-
- /*Check for holded channel, to implement transfer*/
- if (holded_ch ) {
- if (ch->state == MISDN_CONNECTED ) {
- misdn_transfer_bc(ch, holded_ch) ;
- misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
- break;
- }
- }
-
- stop_bc_tones(ch);
- bc->out_cause=16;
- misdn_lib_send_event(bc,EVENT_RELEASE);
-
- }
- break;
-
- case EVENT_RELEASE:
- {
-
- switch ( bc->cause) {
-
- case -1:
- /*
- OK, it really sucks, this is a RELEASE from NT-Stack So we take
- it and return easylie, It seems that we've send a DISCONNECT
- before, so we should RELEASE_COMPLETE after that Disconnect
- (looks like ALERTING State at misdn_hangup !!
- */
- return RESPONSE_OK;
- break;
- }
-
-
- bc->out_cause=16;
-
- stop_bc_tones(ch);
- release_chan(bc);
- }
- break;
- case EVENT_RELEASE_COMPLETE:
- {
- stop_bc_tones(ch);
- release_chan(bc);
- }
- break;
-
- case EVENT_BCHAN_DATA:
- {
- chan_misdn_trace_call(ch->ast,3,"I->*: EVENT_B_DATA len=%d\n",bc->bframe_len);
-
- if ( !misdn_cap_is_speech(ch->bc->capability) || bc->nojitter) {
- misdn_tx2ast_frm(ch, bc->bframe, bc->bframe_len );
- } else {
- int len=bc->bframe_len;
- int free=misdn_ibuf_freecount(bc->astbuf);
-
-
- if (bc->bframe_len > free) {
- ast_log(LOG_DEBUG, "sbuf overflow!\n");
- len=misdn_ibuf_freecount(bc->astbuf);
-
- if (len == 0) {
- ast_log(LOG_WARNING, "BCHAN_DATA: write buffer overflow port:%d channel:%d!\n",bc->port,bc->channel);
- }
- }
-
- misdn_ibuf_memcpy_w(bc->astbuf, bc->bframe, len);
-
- {
- char blah[1]="\0";
-#ifdef FLATTEN_JITTER
- {
- struct timeval tv;
- gettimeofday(&tv,NULL);
-
- if (tv.tv_usec % 10000 > 0 ) {
- write(ch->pipe[1], blah,sizeof(blah));
- bc->time_usec=tv.tv_usec;
- }
- }
-#else
- write(ch->pipe[1], blah,sizeof(blah));
-#endif
-
-
- }
- }
-
- }
- break;
- case EVENT_TIMEOUT:
- break; /* Ignore now .. */
- {
- switch (ch->state) {
- case MISDN_CALLING:
- chan_misdn_log(0, bc?bc->port:0, "GOT TIMOUT AT CALING pid:%d\n", bc?bc->pid:-1);
- break;
- case MISDN_DIALING:
- case MISDN_PROGRESS:
- break;
- default:
- misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
- }
- }
- break;
- case EVENT_CLEANUP:
- {
- stop_bc_tones(ch);
- release_chan(bc);
- }
- break;
-
- /***************************/
- /** Suplementary Services **/
- /***************************/
- case EVENT_RETRIEVE:
- {
- struct ast_channel *hold_ast=AST_BRIDGED_P(ch->ast);
- ch->state = MISDN_CONNECTED;
-
- if (hold_ast) {
- ast_moh_stop(hold_ast);
- }
-
- if ( misdn_lib_send_event(bc, EVENT_RETRIEVE_ACKNOWLEDGE) < 0)
- misdn_lib_send_event(bc, EVENT_RETRIEVE_REJECT);
-
-
- }
- break;
-
- case EVENT_HOLD:
- {
- int hold_allowed;
- misdn_cfg_get( bc->port, MISDN_CFG_HOLD_ALLOWED, &hold_allowed, sizeof(int));
-
- if (!hold_allowed) {
- chan_misdn_log(0, bc->port, "Hold not allowed on port:%d\n", bc->port);
- misdn_lib_send_event(bc, EVENT_HOLD_REJECT);
- break;
- }
-
- {
- struct chan_list *holded_ch=find_holded(cl_te, bc);
- if (holded_ch) {
- misdn_lib_send_event(bc, EVENT_HOLD_REJECT);
- chan_misdn_log(0, bc->port, "We can't use RETRIEVE at the moment due to mISDN bug!\n");
- break;
- }
- }
-
- if (AST_BRIDGED_P(ch->ast)){
- ch->state = MISDN_HOLDED;
- ch->l3id = bc->l3_id;
-
- ast_moh_start(AST_BRIDGED_P(ch->ast), NULL);
- misdn_lib_send_event(bc, EVENT_HOLD_ACKNOWLEDGE);
- } else {
- misdn_lib_send_event(bc, EVENT_HOLD_REJECT);
- chan_misdn_log(0, bc->port, "We aren't bridged to anybody\n");
- }
- }
- break;
- default:
- ast_log(LOG_WARNING, "Got Unknown Event\n");
- break;
- }
-
- return RESPONSE_OK;
-}
-
-/** TE STUFF END **/
-
-/******************************************
- *
- * Asterisk Channel Endpoint END
- *
- *
- *******************************************/
-
-
-int clearl3_true ( void ) {
- int default_clearl3;
- misdn_cfg_get( 0, MISDN_GEN_CLEAR_L3, &default_clearl3, sizeof(int));
- return default_clearl3;
-}
-
-int g_config_initialized=0;
-
-int load_module(void)
-{
- int i;
-
- char ports[256]="";
-
- max_ports=misdn_lib_maxports_get();
-
- if (max_ports<=0) {
- ast_log(LOG_ERROR, "Unable to initialize mISDN\n");
- return -1;
- }
-
-
- misdn_cfg_init(max_ports);
- g_config_initialized=1;
-
- misdn_debug = (int *)malloc(sizeof(int) * (max_ports+1));
- misdn_cfg_get( 0, MISDN_GEN_DEBUG, &misdn_debug[0], sizeof(int));
- for (i = 1; i <= max_ports; i++)
- misdn_debug[i] = misdn_debug[0];
- misdn_debug_only = (int *)calloc(max_ports + 1, sizeof(int));
-
-
- {
- char tempbuf[BUFFERSIZE];
- misdn_cfg_get( 0, MISDN_GEN_TRACEFILE, tempbuf, BUFFERSIZE);
- if (strlen(tempbuf))
- tracing = 1;
- }
-
- ast_mutex_init(&cl_te_lock);
- ast_mutex_init(&release_lock_mutex);
-
- misdn_cfg_get_ports_string(ports);
- if (strlen(ports))
- chan_misdn_log(0, 0, "Got: %s from get_ports\n",ports);
-
- {
- struct misdn_lib_iface iface = {
- .cb_event = cb_events,
- .cb_log = chan_misdn_log,
- .cb_clearl3_true = clearl3_true
- };
- if (misdn_lib_init(ports, &iface, NULL))
- chan_misdn_log(0, 0, "No te ports initialized\n");
- }
-
-
- {
- if (ast_channel_register(&misdn_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- unload_module();
- return -1;
- }
- }
-
- ast_cli_register(&cli_send_display);
- ast_cli_register(&cli_send_cd);
- ast_cli_register(&cli_send_digit);
- ast_cli_register(&cli_toggle_echocancel);
- ast_cli_register(&cli_set_tics);
-
- ast_cli_register(&cli_show_cls);
- ast_cli_register(&cli_show_cl);
- ast_cli_register(&cli_show_config);
- ast_cli_register(&cli_show_port);
- ast_cli_register(&cli_show_stacks);
-
- ast_cli_register(&cli_restart_port);
- ast_cli_register(&cli_port_up);
- ast_cli_register(&cli_set_debug);
- ast_cli_register(&cli_set_crypt_debug);
- ast_cli_register(&cli_reload);
-
-
- ast_register_application("misdn_set_opt", misdn_set_opt_exec, "misdn_set_flags",
- "misdn_set_opt(:<opt><optarg>:<opt><optarg>..):\n"
- "Sets mISDN opts. and optargs\n"
- "\n"
- );
-
-
- ast_register_application("misdn_facility", misdn_facility_exec, "misdn_facility",
- "misdn_facility(<FACILITY_TYPE>|<ARG1>|..)\n"
- "Sends the Facility Message FACILITY_TYPE with \n"
- "the given Arguments to the current ISDN Channel\n"
- "Supported Facilities are:\n"
- "\n"
- "type=calldeflect args=Nr where to deflect\n"
- "\n"
- );
-
- chan_misdn_log(0, 0, "-- mISDN Channel Driver Registred -- (BE AWARE THIS DRIVER IS EXPERIMENTAL!)\n");
-
- return 0;
-}
-
-
-
-int unload_module(void)
-{
- /* First, take us out of the channel loop */
- ast_log(LOG_VERBOSE, "-- Unregistering mISDN Channel Driver --\n");
-
- if (!g_config_initialized) return 0;
-
- ast_cli_unregister(&cli_send_display);
-
- ast_cli_unregister(&cli_send_cd);
-
- ast_cli_unregister(&cli_send_digit);
- ast_cli_unregister(&cli_toggle_echocancel);
- ast_cli_unregister(&cli_set_tics);
-
- ast_cli_unregister(&cli_show_cls);
- ast_cli_unregister(&cli_show_cl);
- ast_cli_unregister(&cli_show_config);
- ast_cli_unregister(&cli_show_port);
- ast_cli_unregister(&cli_show_stacks);
- ast_cli_unregister(&cli_restart_port);
- ast_cli_unregister(&cli_port_up);
- ast_cli_unregister(&cli_set_debug);
- ast_cli_unregister(&cli_set_crypt_debug);
- ast_cli_unregister(&cli_reload);
- /* ast_unregister_application("misdn_crypt"); */
- ast_unregister_application("misdn_set_opt");
- ast_unregister_application("misdn_facility");
-
- ast_channel_unregister(&misdn_tech);
-
- free_robin_list();
- misdn_cfg_destroy();
- misdn_lib_destroy();
-
- if (misdn_debug)
- free(misdn_debug);
- if (misdn_debug_only)
- free(misdn_debug_only);
-
- return 0;
-}
-
-int usecount(void)
-{
- int res;
- ast_mutex_lock(&usecnt_lock);
- res = usecnt;
- ast_mutex_unlock(&usecnt_lock);
- return res;
-}
-
-char *description(void)
-{
- return desc;
-}
-
-char *key(void)
-{
- return ASTERISK_GPL_KEY;
-}
-
-void chan_misdn_log(int level, int port, char *tmpl, ...)
-{
- if (! ((0 <= port) && (port <= max_ports))) {
- ast_log(LOG_WARNING, "cb_log called with out-of-range port number! (%d)\n", port);
- return;
- }
-
- va_list ap;
- char buf[1024];
-
- va_start(ap, tmpl);
- vsnprintf( buf, 1023, tmpl, ap );
- va_end(ap);
-
- if (misdn_debug_only[port] ? (level==1 && misdn_debug[port]) || (level==misdn_debug[port]) : level <= misdn_debug[port]) {
- ast_console_puts(buf);
- }
-
- if (level <= misdn_debug[0] && tracing) {
- time_t tm = time(NULL);
- char *tmp=ctime(&tm),*p;
- char file[BUFFERSIZE];
- misdn_cfg_get( 0, MISDN_GEN_TRACEFILE, file, BUFFERSIZE);
- FILE *fp= fopen(file, "a+");
-
- p=strchr(tmp,'\n');
- if (p) *p=':';
-
- if (!fp) {
- ast_console_puts("Error opening Tracefile: ");
- ast_console_puts(strerror(errno));
- ast_console_puts("\n");
- return ;
- }
-
- fputs(tmp,fp);
- fputs(" ", fp);
- fputs(buf, fp);
-
- fclose(fp);
- }
-}
-
-
-void chan_misdn_trace_call(struct ast_channel *chan, int debug, char *tmpl, ...)
-{
- va_list ap;
- char buf[1024];
- char name[1024];
-
- int trace;
- misdn_cfg_get( 0, MISDN_GEN_TRACE_CALLS, &trace, sizeof(int));
- if (!trace) return ;
-
- if (misdn_debug[0] < debug) return ;
-
- char tracedir[BUFFERSIZE];
- misdn_cfg_get( 0, MISDN_GEN_TRACE_DIR, tracedir, BUFFERSIZE);
- sprintf(name,"%s/%s.%s",tracedir, chan->uniqueid, chan->cid.cid_num );
-
- va_start(ap, tmpl);
-
- vsprintf( buf, tmpl, ap );
-
- va_end(ap);
-
- time_t tm = time(NULL);
- char *tmp=ctime(&tm),*p;
- FILE *fp= fopen(name, "a");
- int fd;
-
- if (!fp) {
- ast_console_puts("Error opening Tracefile");
- ast_console_puts(strerror(errno));
- ast_console_puts("\n");
- return ;
- }
-
- fd=fileno(fp) ;
-
- flock(fd, LOCK_EX);
-
- p=strchr(tmp,'\n');
- if (p) *p=':';
-
-
-
- fputs(tmp,fp);
- fputs(" ", fp);
- fputs(buf, fp);
-
- flock(fd, LOCK_UN);
-
- fclose(fp);
-
-}
-
-
-/*** SOME APPS ;)***/
-
-static int misdn_facility_exec(struct ast_channel *chan, void *data)
-{
- struct chan_list *ch = MISDN_ASTERISK_TECH_PVT(chan);
- char *tok, *tokb;
-
-
- if (strcasecmp(MISDN_ASTERISK_TYPE(chan),"mISDN")) {
- ast_log(LOG_WARNING, "misdn_facility makes only sense with chan_misdn channels!\n");
- return -1;
- }
-
- if (ast_strlen_zero((char *)data)) {
- ast_log(LOG_WARNING, "misdn_facility Requires arguments\n");
- return -1;
- }
-
- tok=strtok_r((char*)data,"|", &tokb) ;
-
- if (!tok) {
- ast_log(LOG_WARNING, "misdn_facility Requires arguments\n");
- return -1;
- }
-
- if (!strcasecmp(tok,"calldeflect")) {
- tok=strtok_r(NULL,"|", &tokb) ;
-
- if (!tok) {
- ast_log(LOG_WARNING, "Facility: Call Defl Requires arguments\n");
- }
-
- misdn_lib_send_facility(ch->bc, FACILITY_CALLDEFLECT, tok);
-
- } else {
- ast_log(LOG_WARNING, "Unknown Facility: %s\n",tok);
- }
-
- return 0;
-
-}
-
-
-static int misdn_set_opt_exec(struct ast_channel *chan, void *data)
-{
- struct chan_list *ch = MISDN_ASTERISK_TECH_PVT(chan);
- char *tok,*tokb;
- int keyidx=0;
- int rxgain=0;
- int txgain=0;
-
- if (strcasecmp(MISDN_ASTERISK_TYPE(chan),"mISDN")) {
- ast_log(LOG_WARNING, "misdn_set_opt makes only sense with chan_misdn channels!\n");
- return -1;
- }
-
- if (ast_strlen_zero((char *)data)) {
- ast_log(LOG_WARNING, "misdn_set_opt Requires arguments\n");
- return -1;
- }
-
- for (tok=strtok_r((char*)data, ":",&tokb);
- tok;
- tok=strtok_r(NULL,":",&tokb) ) {
- int neglect=0;
-
- if (tok[0] == '!' ) {
- neglect=1;
- tok++;
- }
-
- switch(tok[0]) {
-
- case 'd' :
- strncpy(ch->bc->display,++tok,84);
- chan_misdn_log(1, ch->bc->port, "SETOPT: Display:%s\n",ch->bc->display);
- break;
-
- case 'n':
- chan_misdn_log(1, ch->bc->port, "SETOPT: No DSP\n");
- ch->bc->nodsp=1;
- break;
-
- case 'j':
- chan_misdn_log(1, ch->bc->port, "SETOPT: No jitter\n");
- ch->bc->nojitter=1;
- break;
-
- case 'v':
- tok++;
-
- switch ( tok[0] ) {
- case 'r' :
- rxgain=atoi(++tok);
- if (rxgain<-8) rxgain=-8;
- if (rxgain>8) rxgain=8;
- ch->bc->rxgain=rxgain;
- chan_misdn_log(1, ch->bc->port, "SETOPT: Volume:%d\n",rxgain);
- break;
- case 't':
- txgain=atoi(++tok);
- if (txgain<-8) txgain=-8;
- if (txgain>8) txgain=8;
- ch->bc->txgain=txgain;
- chan_misdn_log(1, ch->bc->port, "SETOPT: Volume:%d\n",txgain);
- break;
- }
- break;
-
- case 'c':
- keyidx=atoi(++tok);
-
- if (keyidx > misdn_key_vector_size || keyidx < 0 ) {
- ast_log(LOG_WARNING, "You entered the keyidx: %d but we have only %d keys\n",keyidx, misdn_key_vector_size );
- continue;
- }
-
- {
- int l = sizeof(ch->bc->crypt_key);
- strncpy(ch->bc->crypt_key, misdn_key_vector[keyidx], l);
- ch->bc->crypt_key[l-1] = 0;
- }
- chan_misdn_log(0, ch->bc->port, "SETOPT: crypt with key:%s\n",misdn_key_vector[keyidx]);
- break;
-
- case 'e':
- chan_misdn_log(1, ch->bc->port, "SETOPT: EchoCancel\n");
-
- if (neglect) {
- ch->bc->ec_enable=0;
- } else {
- ch->bc->ec_enable=1;
- ch->bc->orig=ch->orginator;
- tok++;
- if (tok) {
- ch->bc->ec_deftaps=atoi(tok);
- }
- }
-
- break;
-
- case 'h':
- chan_misdn_log(1, ch->bc->port, "SETOPT: Digital\n");
- if (strlen(tok) > 1 && tok[1]=='1') {
- chan_misdn_log(1, ch->bc->port, "SETOPT: Digital TRANS_DIGITAL\n");
- ch->bc->async=1;
- ch->bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
- /*ch->bc->state=STATE_CONNECTED;
- misdn_lib_setup_bc(ch->bc);*/
- } else {
- ch->bc->async=0;
- ch->bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
- /*ch->bc->state=STATE_CONNECTED;
- misdn_lib_setup_bc(ch->bc);*/
- }
- break;
-
- case 's':
- chan_misdn_log(1, ch->bc->port, "SETOPT: Send DTMF\n");
- ch->bc->send_dtmf=1;
- break;
-
- case 'f':
- chan_misdn_log(1, ch->bc->port, "SETOPT: Faxdetect\n");
- ch->faxdetect=1;
- break;
-
- case 'a':
- chan_misdn_log(1, ch->bc->port, "SETOPT: AST_DSP (for DTMF)\n");
- ch->ast_dsp=1;
- break;
-
- case 'p':
- chan_misdn_log(1, ch->bc->port, "SETOPT: callerpres: %s\n",&tok[1]);
- /* CRICH: callingpres!!! */
- if (strstr(tok,"allowed") ) {
- ch->bc->pres=0;
- } else if (strstr(tok,"not_screened")) {
- ch->bc->pres=1;
- }
-
-
- break;
-
-
- default:
- break;
- }
- }
-
- if (ch->faxdetect || ch->ast_dsp) {
-
- if (!ch->dsp) ch->dsp = ast_dsp_new();
- if (ch->dsp) ast_dsp_set_features(ch->dsp, DSP_FEATURE_DTMF_DETECT| DSP_FEATURE_FAX_DETECT);
- if (!ch->trans) ch->trans=ast_translator_build_path(AST_FORMAT_SLINEAR, AST_FORMAT_ALAW);
- }
-
- if (ch->ast_dsp) {
- chan_misdn_log(1,ch->bc->port,"SETOPT: with AST_DSP we deactivate mISDN_dsp\n");
- ch->bc->nodsp=1;
- ch->bc->nojitter=1;
- }
-
- return 0;
-}
-
-
diff --git a/1.2-netsec/channels/chan_misdn_config.c b/1.2-netsec/channels/chan_misdn_config.c
deleted file mode 100644
index 26598717c..000000000
--- a/1.2-netsec/channels/chan_misdn_config.c
+++ /dev/null
@@ -1,1083 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Christian Richter
- *
- * Christian Richter <crich@beronet.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- *
- */
-
-/*!
- * \file
- *
- * \brief chan_misdn configuration management
- * \author Christian Richter <crich@beronet.com>
- *
- * \ingroup channel_drivers
- */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "chan_misdn_config.h"
-
-#include <asterisk/config.h>
-#include <asterisk/channel.h>
-#include <asterisk/logger.h>
-#include <asterisk/lock.h>
-#include <asterisk/strings.h>
-
-#include <asterisk/utils.h>
-#define AST_LOAD_CFG ast_config_load
-#define AST_DESTROY_CFG ast_config_destroy
-
-#define DEF_ECHOCANCEL 128
-#define DEF_ECHOTRAINING 1
-
-struct msn_list {
- char *msn;
- struct msn_list *next;
-};
-
-struct port_config {
- char *name;
- int *rxgain;
- int *txgain;
- int *te_choose_channel;
- char *context;
- char *language;
- char *callerid;
- char *method;
- int *dialplan;
- int *localdialplan;
- char *nationalprefix;
- char *internationalprefix;
- int *pres;
- int *always_immediate;
- int *immediate;
- int *hold_allowed;
- int *early_bconnect;
- int *use_callingpres;
- int *echocancel;
- int *echocancelwhenbridged;
- int *echotraining;
- struct msn_list *msn_list;
- ast_group_t *callgroup; /* Call group */
- ast_group_t *pickupgroup; /* Pickup group */
-};
-
-struct general_config {
- int *debug;
- char *tracefile;
- int *trace_calls;
- char *trace_dir;
- int *bridging;
- int *stop_tone_after_first_digit;
- int *append_digits2exten;
- int *l1_info_ok;
- int *clear_l3;
- int *dynamic_crypt;
- char *crypt_prefix;
- char *crypt_keys;
-};
-
-/* array of port configs, default is at position 0. */
-static struct port_config **port_cfg;
-/* max number of available ports, is set on init */
-static int max_ports;
-/* general config */
-static struct general_config *general_cfg;
-/* storing the ptp flag separated to save memory */
-static int *ptp;
-
-static ast_mutex_t config_mutex;
-
-
-static inline void misdn_cfg_lock (void) {
- ast_mutex_lock(&config_mutex);
-}
-
-static inline void misdn_cfg_unlock (void) {
- ast_mutex_unlock(&config_mutex);
-}
-
-static void free_msn_list (struct msn_list* iter) {
- if (iter->next)
- free_msn_list(iter->next);
- if (iter->msn)
- free(iter->msn);
- free(iter);
-}
-
-static void free_port_cfg (void) {
-
- struct port_config **free_list = (struct port_config **)calloc(max_ports + 1, sizeof(struct port_config *));
-
- int i, j;
-
- for (i = 0; i < max_ports; i++) {
- if (port_cfg[i]) {
- for (j = 0; j < max_ports && free_list[j]; j++) {
- if (free_list[j] && free_list[j] == port_cfg[i])
- continue; /* already in list */
- free_list[j] = port_cfg[i];
- }
- }
- }
-
-#define FREE_ELEM(elem) ({ \
- if (free_list[i]->elem) \
- free(free_list[i]->elem); \
- })
-
- for (i = 0; i < max_ports; i++) {
- if (free_list[i]) {
- FREE_ELEM(name);
- FREE_ELEM(rxgain);
- FREE_ELEM(txgain);
- FREE_ELEM(te_choose_channel);
- FREE_ELEM(context);
- FREE_ELEM(language);
- FREE_ELEM(callerid);
- FREE_ELEM(method);
- FREE_ELEM(dialplan);
- FREE_ELEM(localdialplan);
- FREE_ELEM(nationalprefix);
- FREE_ELEM(internationalprefix);
- FREE_ELEM(pres);
- FREE_ELEM(always_immediate);
- FREE_ELEM(immediate);
- FREE_ELEM(hold_allowed);
- FREE_ELEM(early_bconnect);
- FREE_ELEM(use_callingpres);
- FREE_ELEM(echocancel);
- FREE_ELEM(echocancelwhenbridged);
- FREE_ELEM(echotraining);
- if (free_list[i]->msn_list)
- free_msn_list(free_list[i]->msn_list);
- FREE_ELEM(callgroup);
- FREE_ELEM(pickupgroup);
- free(free_list[i]);
- }
- }
- free(free_list);
-}
-
-static void free_general_cfg (void) {
-
-#define FREE_GEN_ELEM(elem) ({ \
- if (general_cfg->elem) \
- free(general_cfg->elem); \
- })
-
- FREE_GEN_ELEM(debug);
- FREE_GEN_ELEM(tracefile);
- FREE_GEN_ELEM(trace_calls);
- FREE_GEN_ELEM(trace_dir);
- FREE_GEN_ELEM(bridging);
- FREE_GEN_ELEM(stop_tone_after_first_digit);
- FREE_GEN_ELEM(append_digits2exten);
- FREE_GEN_ELEM(l1_info_ok);
- FREE_GEN_ELEM(clear_l3);
- FREE_GEN_ELEM(dynamic_crypt);
- FREE_GEN_ELEM(crypt_prefix);
- FREE_GEN_ELEM(crypt_keys);
-}
-
-#define GET_PORTCFG_STRCPY(item) ({ \
- char *temp; \
- if (port_cfg[port] && port_cfg[port]->item) \
- temp = port_cfg[port]->item; \
- else \
- temp = port_cfg[0]->item; \
- if (!temp || !memccpy((void *)buf, (void *)temp, '\0', bufsize)) \
- memset(buf, 0, 1); \
- })
-
-#define GET_GENCFG_STRCPY(item) ({ \
- if (general_cfg && general_cfg->item) { \
- if (!memccpy((void *)buf, (void *)general_cfg->item, '\0', bufsize)) \
- memset(buf, 0, 1); \
- } else \
- memset(buf, 0, 1); \
- })
-
-#define GET_PORTCFG_MEMCPY(item) ({ \
- typeof(port_cfg[0]->item) temp; \
- if (port_cfg[port] && port_cfg[port]->item) \
- temp = port_cfg[port]->item; \
- else \
- temp = port_cfg[0]->item; \
- if (temp) { \
- int l = sizeof(*temp); \
- if (l > bufsize) \
- memset(buf, 0, bufsize); \
- else \
- memcpy(buf, temp, l); \
- } else \
- memset(buf, 0, bufsize); \
- })
-
-#define GET_GENCFG_MEMCPY(item) ({ \
- if (general_cfg && general_cfg->item) { \
- typeof(general_cfg->item) temp = general_cfg->item; \
- int l = sizeof(*temp); \
- if (l > bufsize) \
- memset(buf, 0, bufsize); \
- else \
- memcpy(buf, temp, l); \
- } else \
- memset(buf, 0, bufsize); \
- })
-
-void misdn_cfg_get(int port, enum misdn_cfg_elements elem, void *buf, int bufsize) {
-
- if (!(elem > MISDN_GEN_FIRST) && !misdn_cfg_is_port_valid(port)) {
- memset(buf, 0, bufsize);
- ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port);
- return;
- }
-
- misdn_cfg_lock();
-
- switch (elem) {
-
- /* port config elements */
-
- case MISDN_CFG_PTP: if (sizeof(ptp[port]) <= bufsize)
- memcpy(buf, &ptp[port], sizeof(ptp[port]));
- else
- buf = 0; /* error, should not happen */
- break;
- case MISDN_CFG_GROUPNAME: GET_PORTCFG_STRCPY(name);
- break;
- case MISDN_CFG_RXGAIN: GET_PORTCFG_MEMCPY(rxgain);
- break;
- case MISDN_CFG_TXGAIN: GET_PORTCFG_MEMCPY(txgain);
- break;
- case MISDN_CFG_TE_CHOOSE_CHANNEL:
- GET_PORTCFG_MEMCPY(te_choose_channel);
- break;
- case MISDN_CFG_CONTEXT: GET_PORTCFG_STRCPY(context);
- break;
- case MISDN_CFG_LANGUAGE: GET_PORTCFG_STRCPY(language);
- break;
- case MISDN_CFG_CALLERID: GET_PORTCFG_STRCPY(callerid);
- break;
- case MISDN_CFG_METHOD: GET_PORTCFG_STRCPY(method);
- break;
- case MISDN_CFG_DIALPLAN: GET_PORTCFG_MEMCPY(dialplan);
- break;
- case MISDN_CFG_LOCALDIALPLAN: GET_PORTCFG_MEMCPY(localdialplan);
- break;
- case MISDN_CFG_NATPREFIX: GET_PORTCFG_STRCPY(nationalprefix);
- break;
- case MISDN_CFG_INTERNATPREFIX:
- GET_PORTCFG_STRCPY(internationalprefix);
- break;
- case MISDN_CFG_PRES: GET_PORTCFG_MEMCPY(pres);
- break;
- case MISDN_CFG_ALWAYS_IMMEDIATE:
- GET_PORTCFG_MEMCPY(always_immediate);
- break;
- case MISDN_CFG_IMMEDIATE: GET_PORTCFG_MEMCPY(immediate);
- break;
- case MISDN_CFG_HOLD_ALLOWED:
- GET_PORTCFG_MEMCPY(hold_allowed);
- break;
- case MISDN_CFG_EARLY_BCONNECT:
- GET_PORTCFG_MEMCPY(early_bconnect);
- break;
- case MISDN_CFG_USE_CALLINGPRES:
- GET_PORTCFG_MEMCPY(use_callingpres);
- break;
- case MISDN_CFG_ECHOCANCEL:
- GET_PORTCFG_MEMCPY(echocancel );
- break;
- case MISDN_CFG_ECHOCANCELWHENBRIDGED:
- GET_PORTCFG_MEMCPY(echocancelwhenbridged);
- break;
- case MISDN_CFG_ECHOTRAINING:
- GET_PORTCFG_MEMCPY(echotraining);
- break;
- case MISDN_CFG_CALLGROUP: GET_PORTCFG_MEMCPY(callgroup);
- break;
- case MISDN_CFG_PICKUPGROUP: GET_PORTCFG_MEMCPY(pickupgroup);
- break;
-
- /* general config elements */
-
- case MISDN_GEN_DEBUG: GET_GENCFG_MEMCPY(debug);
- break;
- case MISDN_GEN_TRACEFILE: GET_GENCFG_STRCPY(tracefile);
- break;
- case MISDN_GEN_TRACE_CALLS: GET_GENCFG_MEMCPY(trace_calls);
- break;
- case MISDN_GEN_TRACE_DIR: GET_GENCFG_STRCPY(trace_dir);
- break;
- case MISDN_GEN_BRIDGING: GET_GENCFG_MEMCPY(bridging);
- break;
- case MISDN_GEN_STOP_TONE: GET_GENCFG_MEMCPY(stop_tone_after_first_digit);
- break;
- case MISDN_GEN_APPEND_DIGITS2EXTEN:
- GET_GENCFG_MEMCPY(append_digits2exten);
- break;
- case MISDN_GEN_L1_INFO_OK: GET_GENCFG_MEMCPY(l1_info_ok);
- break;
- case MISDN_GEN_CLEAR_L3: GET_GENCFG_MEMCPY(clear_l3);
- break;
- case MISDN_GEN_DYNAMIC_CRYPT: GET_GENCFG_MEMCPY(dynamic_crypt);
- break;
- case MISDN_GEN_CRYPT_PREFIX: GET_GENCFG_STRCPY(crypt_prefix);
- break;
- case MISDN_GEN_CRYPT_KEYS: GET_GENCFG_STRCPY(crypt_keys);
- break;
- default: memset(buf, 0, bufsize);
- }
-
- misdn_cfg_unlock();
-}
-
-int misdn_cfg_is_msn_valid (int port, char* msn) {
-
- if (!misdn_cfg_is_port_valid(port)) {
- ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
- return 0;
- }
-
- struct msn_list *iter;
-
- misdn_cfg_lock();
-
- if (port_cfg[port]->msn_list)
- iter = port_cfg[port]->msn_list;
- else
- iter = port_cfg[0]->msn_list;
- for (; iter; iter = iter->next)
- if (*(iter->msn) == '*' || !strcasecmp(iter->msn, msn)) {
- misdn_cfg_unlock();
- return 1;
- }
-
- misdn_cfg_unlock();
-
- return 0;
-}
-
-int misdn_cfg_is_port_valid (int port) {
-
- misdn_cfg_lock();
-
- if (port < 1 || port > max_ports) {
- misdn_cfg_unlock();
- return 0;
- }
-
- int valid = (port_cfg[port] != NULL);
-
- misdn_cfg_unlock();
-
- return valid;
-}
-
-int misdn_cfg_is_group_method (char *group, enum misdn_cfg_method meth) {
-
- int i, re = 0;
- char *method = NULL;
-
- misdn_cfg_lock();
-
- for (i = 0; i < max_ports; i++) {
- if (port_cfg[i]) {
- if (!strcasecmp(port_cfg[i]->name, group))
- method = port_cfg[i]->method ? port_cfg[i]->method : port_cfg[0]->method;
- }
- }
-
- if (method) {
- switch (meth) {
- case METHOD_STANDARD: re = !strcasecmp(method, "standard");
- break;
- case METHOD_ROUND_ROBIN: re = !strcasecmp(method, "round_robin");
- break;
- }
- }
-
- misdn_cfg_unlock();
-
- return re;
-}
-
-void misdn_cfg_get_ports_string (char *ports) {
- *ports = 0;
- char tmp[16];
- int l;
-
- misdn_cfg_lock();
-
- int i = 1;
- for (; i <= max_ports; i++) {
- if (port_cfg[i]) {
- if (ptp[i])
- sprintf(tmp, "%dptp,", i);
- else
- sprintf(tmp, "%d,", i);
- strcat(ports, tmp);
- }
- }
-
- misdn_cfg_unlock();
-
- if ((l = strlen(ports)))
- ports[l-1] = 0;
-}
-
-#define GET_CFG_STRING(typestr, type) ({ \
- if (port_cfg[port] && port_cfg[port]->type) \
- snprintf(buf, bufsize, "%s " #typestr ": %s", begin, port_cfg[port]->type); \
- else \
- snprintf(buf, bufsize, "%s " #typestr ": %s", begin, port_cfg[0]->type); \
- }) \
-
-#define GET_GEN_STRING(typestr, type) ({ \
- snprintf(buf, bufsize, "%s " #typestr ": %s", begin, general_cfg->type ? general_cfg->type : "not set"); \
- }) \
-
-#define GET_CFG_INT(typestr, type) ({ \
- if (port_cfg[port] && port_cfg[port]->type) \
- snprintf(buf, bufsize, "%s " #typestr ": %d", begin, *port_cfg[port]->type); \
- else \
- snprintf(buf, bufsize, "%s " #typestr ": %d", begin, *port_cfg[0]->type); \
- }) \
-
-#define GET_GEN_INT(typestr, type) ({ \
- snprintf(buf, bufsize, "%s " #typestr ": %d", begin, general_cfg->type ? *general_cfg->type : 0); \
- }) \
-
-#define GET_CFG_BOOL(typestr, type, yes, no) ({ \
- int bool; \
- if (port_cfg[port] && port_cfg[port]->type) \
- bool = *port_cfg[port]->type; \
- else \
- bool = *port_cfg[0]->type; \
- snprintf(buf, bufsize, "%s " #typestr ": %s", begin, bool ? #yes : #no); \
- }) \
-
-#define GET_CFG_HYBRID(typestr, type, yes, no) ({ \
- int bool; \
- if (port_cfg[port] && port_cfg[port]->type) \
- bool = *port_cfg[port]->type; \
- else \
- bool = *port_cfg[0]->type; \
- if (bool == 1 || bool == 0) \
- snprintf(buf, bufsize, "%s " #typestr ": %s", begin, bool ? #yes : #no); \
- else \
- snprintf(buf, bufsize, "%s " #typestr ": %d", begin, bool); \
- }) \
-
-#define GET_GEN_BOOL(typestr, type, yes, no) ({ \
- snprintf(buf, bufsize, "%s " #typestr ": %s", begin, general_cfg->type ? (*general_cfg->type ? #yes : #no) : "not set"); \
- }) \
-
-#define GET_CFG_AST_GROUP_T(typestr, type) ({ \
- ast_group_t *tmp; \
- if (port_cfg[port] && port_cfg[port]->type) \
- tmp = port_cfg[port]->type; \
- else \
- tmp = port_cfg[0]->type; \
- if (tmp) { \
- char tmpbuf[256]; \
- snprintf(buf, bufsize, "%s " #typestr ": %s", begin, ast_print_group(tmpbuf, sizeof(tmpbuf), *tmp)); \
- } else \
- snprintf(buf, bufsize, "%s " #typestr ": %s", begin, "none"); \
- }) \
-
-void misdn_cfg_get_config_string(int port, enum misdn_cfg_elements elem, char* buf, int bufsize) {
-
- if (!(elem > MISDN_GEN_FIRST) && !misdn_cfg_is_port_valid(port)) {
- *buf = 0;
- ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port);
- return;
- }
-
- char begin[] = " -> ";
-
- misdn_cfg_lock();
-
- switch (elem) {
-
- case MISDN_CFG_PTP: snprintf(buf, bufsize, "%s PTP: %s", begin, ptp[port] ? "yes" : "no");
- break;
- case MISDN_CFG_GROUPNAME: GET_CFG_STRING(GROUPNAME, name);
- break;
- case MISDN_CFG_RXGAIN: GET_CFG_INT(RXGAIN, rxgain);
- break;
- case MISDN_CFG_TXGAIN: GET_CFG_INT(TXGAIN, txgain);
- break;
- case MISDN_CFG_TE_CHOOSE_CHANNEL:
- GET_CFG_BOOL(TE_CHOOSE_CHANNEL, te_choose_channel, yes, no);
- break;
- case MISDN_CFG_CONTEXT: GET_CFG_STRING(CONTEXT, context);
- break;
- case MISDN_CFG_LANGUAGE: GET_CFG_STRING(LANGUAGE, language);
- break;
- case MISDN_CFG_CALLERID: GET_CFG_STRING(CALLERID, callerid);
- break;
- case MISDN_CFG_METHOD: GET_CFG_STRING(METHOD, method);
- break;
- case MISDN_CFG_DIALPLAN: GET_CFG_INT(DIALPLAN, dialplan);
- break;
- case MISDN_CFG_LOCALDIALPLAN: GET_CFG_INT(LOCALDIALPLAN, localdialplan);
- break;
- case MISDN_CFG_NATPREFIX: GET_CFG_STRING(NATIONALPREFIX, nationalprefix);
- break;
- case MISDN_CFG_INTERNATPREFIX:
- GET_CFG_STRING(INTERNATIONALPREFIX, internationalprefix);
- break;
- case MISDN_CFG_PRES: GET_CFG_BOOL(PRESENTATION, pres, allowed, not_screened);
- break;
- case MISDN_CFG_ALWAYS_IMMEDIATE:
- GET_CFG_BOOL(ALWAYS_IMMEDIATE, always_immediate, yes, no);
- break;
- case MISDN_CFG_IMMEDIATE: GET_CFG_BOOL(IMMEDIATE, immediate, yes, no);
- break;
- case MISDN_CFG_HOLD_ALLOWED:
- GET_CFG_BOOL(HOLD_ALLOWED, hold_allowed, yes, no);
- break;
- case MISDN_CFG_EARLY_BCONNECT:
- GET_CFG_BOOL(EARLY_BCONNECT, early_bconnect, yes, no);
- break;
- case MISDN_CFG_USE_CALLINGPRES:
- GET_CFG_BOOL(USE_CALLINGPRES, use_callingpres, yes, no);
- break;
- case MISDN_CFG_ECHOCANCEL: GET_CFG_HYBRID(ECHOCANCEL, echocancel, yes, no);
- break;
- case MISDN_CFG_ECHOCANCELWHENBRIDGED:
- GET_CFG_BOOL(ECHOCANCELWHENBRIDGED, echocancelwhenbridged, yes, no);
- break;
- case MISDN_CFG_ECHOTRAINING:
- GET_CFG_HYBRID(ECHOTRAINING, echotraining, yes, no);
- break;
- case MISDN_CFG_CALLGROUP: GET_CFG_AST_GROUP_T(CALLINGGROUP, callgroup);
- break;
- case MISDN_CFG_PICKUPGROUP: GET_CFG_AST_GROUP_T(PICKUPGROUP, pickupgroup);
- break;
- case MISDN_CFG_MSNS: {
- char tmpbuffer[BUFFERSIZE];
- tmpbuffer[0] = 0;
- struct msn_list *iter;
- if (port_cfg[port]->msn_list)
- iter = port_cfg[port]->msn_list;
- else
- iter = port_cfg[0]->msn_list;
- if (iter) {
- for (; iter; iter = iter->next)
- sprintf(tmpbuffer, "%s%s, ", tmpbuffer, iter->msn);
- tmpbuffer[strlen(tmpbuffer)-2] = 0;
- }
- snprintf(buf, bufsize, "%s MSNs: %s", begin, *tmpbuffer ? tmpbuffer : "none"); \
- }
- break;
-
- /* general config elements */
-
- case MISDN_GEN_DEBUG: GET_GEN_INT(DEBUG_LEVEL, debug);
- break;
- case MISDN_GEN_TRACEFILE: GET_GEN_STRING(TRACEFILE, tracefile);
- break;
- case MISDN_GEN_TRACE_CALLS: GET_GEN_BOOL(TRACE_CALLS, trace_calls, true, false);
- break;
- case MISDN_GEN_TRACE_DIR: GET_GEN_STRING(TRACE_DIR, trace_dir);
- break;
- case MISDN_GEN_BRIDGING: GET_GEN_BOOL(BRIDGING, bridging, yes, no);
- break;
- case MISDN_GEN_STOP_TONE: GET_GEN_BOOL(STOP_TONE_AFTER_FIRST_DIGIT, stop_tone_after_first_digit, yes, no);
- break;
- case MISDN_GEN_APPEND_DIGITS2EXTEN:
- GET_GEN_BOOL(APPEND_DIGITS2EXTEN, append_digits2exten, yes, no);
- break;
- case MISDN_GEN_L1_INFO_OK: GET_GEN_BOOL(L1_INFO_OK, l1_info_ok, yes, no);
- break;
- case MISDN_GEN_CLEAR_L3: GET_GEN_BOOL(CLEAR_L3, clear_l3, yes, no);
- break;
- case MISDN_GEN_DYNAMIC_CRYPT:
- GET_GEN_BOOL(DYNAMIC_CRYPT,dynamic_crypt, yes, no);
- break;
- case MISDN_GEN_CRYPT_PREFIX:
- GET_GEN_STRING(CRYPT_PREFIX, crypt_prefix);
- break;
- case MISDN_GEN_CRYPT_KEYS: GET_GEN_STRING(CRYPT_KEYS, crypt_keys);
- break;
-
- default: *buf = 0;
- break;
- }
-
- misdn_cfg_unlock();
-}
-
-int misdn_cfg_get_next_port (int port) {
-
- misdn_cfg_lock();
-
- for (port++; port <= max_ports; port++) {
- if (port_cfg[port]) {
- misdn_cfg_unlock();
- return port;
- }
- }
-
- misdn_cfg_unlock();
-
- return -1;
-}
-
-int misdn_cfg_get_next_port_spin (int port) {
-
- int ret = misdn_cfg_get_next_port(port);
-
- if (ret > 0)
- return ret;
-
- return misdn_cfg_get_next_port(0);
-}
-
-#define PARSE_GEN_INT(item) ({ \
- if (!strcasecmp(v->name, #item)) { \
- int temp; \
- if (!sscanf(v->value, "%d", &temp)) { \
- ast_log(LOG_WARNING, "Value \"%s\" for \"" #item "\" (generals section) invalid or out of range! Please edit your misdn.conf and then do a \"misdn reload\".\n", v->value); \
- } else { \
- general_cfg->item = (int *)malloc(sizeof(int)); \
- memcpy(general_cfg->item, &temp, sizeof(int)); \
- } \
- continue; \
- } \
- }) \
-
-#define PARSE_GEN_BOOL(item) ({ \
- if (!strcasecmp(v->name, #item)) { \
- general_cfg->item = (int *)malloc(sizeof(int)); \
- *(general_cfg->item) = ast_true(v->value)?1:0; \
- continue; \
- } \
- })
-
-#define PARSE_GEN_STR(item) ({ \
- if (!strcasecmp(v->name, #item)) { \
- int l = strlen(v->value); \
- if (l) { \
- general_cfg->item = (char *)calloc(l+1, sizeof(char)); \
- strncpy(general_cfg->item,v->value, l); \
- } \
- continue; \
- } \
- })
-
-static void build_general_config(struct ast_variable *v) {
-
- if (!v)
- return;
-
- for (; v; v = v->next) {
-
- PARSE_GEN_INT(debug);
- PARSE_GEN_STR(tracefile);
- PARSE_GEN_BOOL(trace_calls);
- PARSE_GEN_STR(trace_dir);
- PARSE_GEN_BOOL(bridging);
- PARSE_GEN_BOOL(stop_tone_after_first_digit);
- PARSE_GEN_BOOL(append_digits2exten);
- PARSE_GEN_BOOL(l1_info_ok);
- PARSE_GEN_BOOL(clear_l3);
- PARSE_GEN_BOOL(dynamic_crypt);
- PARSE_GEN_STR(crypt_prefix);
- PARSE_GEN_STR(crypt_keys);
-
- }
-}
-
-#define PARSE_CFG_HYBRID(item, def) ({ \
- if (!strcasecmp(v->name, #item)) { \
- new->item = (int *)malloc(sizeof(int)); \
- if (!sscanf(v->value, "%d", new->item)) { \
- if (ast_true(v->value)) \
- *new->item = def; \
- else \
- *new->item = 0; \
- } \
- continue; \
- } \
- }) \
-
-#define PARSE_CFG_INT(item) ({ \
- if (!strcasecmp(v->name, #item)) { \
- new->item = (int *)malloc(sizeof(int)); \
- if (!sscanf(v->value, "%d", new->item)) { \
- ast_log(LOG_WARNING, "Value \"%s\" for \"" #item "\" of group \"%s\" invalid or out of range! Please edit your misdn.conf and then do a \"misdn reload\".\n", v->value, cat); \
- free(new->item); \
- new->item = NULL; \
- } \
- continue; \
- } \
- }) \
-
-#define PARSE_CFG_BOOL(item) ({ \
- if (!strcasecmp(v->name, #item)) { \
- new->item = (int *)malloc(sizeof(int)); \
- *(new->item) = ast_true(v->value)?1:0; \
- continue; \
- } \
- })
-
-#define PARSE_CFG_STR(item) ({ \
- if (!strcasecmp(v->name, #item)) { \
- int l = strlen(v->value); \
- if (l) { \
- new->item = (char *)calloc(l+1, sizeof(char)); \
- strncpy(new->item,v->value,l); \
- } \
- continue; \
- } \
- })
-
-static void build_port_config(struct ast_variable *v, char *cat) {
- if (!v || !cat)
- return;
-
- int cfg_for_ports[max_ports + 1];
- int i = 0;
- for (; i < (max_ports + 1); i++) {
- cfg_for_ports[i] = 0;
- }
-
- /* we store the default config at position 0 */
- if (!strcasecmp(cat, "default")) {
- cfg_for_ports[0] = 1;
- }
-
- struct port_config* new = (struct port_config *)calloc(1, sizeof(struct port_config));
-
- {
- int l = strlen(cat);
- new->name = (char *)calloc(l+1, sizeof(char));
- strncpy(new->name, cat, l);
- }
-
- for (; v; v=v->next) {
- if (!strcasecmp(v->name, "ports")) {
- /* TODO check for value not beeing set, like PORTS= */
- char *iter;
- char *value = v->value;
- while ((iter = strchr(value, ',')) != NULL) {
- *iter = 0;
- /* strip spaces */
- while (*value && *value == ' ') {
- value++;
- }
- /* TODO check for char not 0-9 */
-
- if (*value){
- int p = atoi(value);
- if (p <= max_ports && p > 0) {
- cfg_for_ports[p] = 1;
- if (strstr(value, "ptp"))
- ptp[p] = 1;
- } else
- ast_log(LOG_WARNING, "Port value \"%s\" of group %s invalid or out of range! Please edit your misdn.conf and then do a \"misdn reload\".\n", value, cat);
- value = ++iter;
- }
- }
- /* the remaining or the only one */
- /* strip spaces */
- while (*value && *value == ' ') {
- value++;
- }
- /* TODO check for char not 0-9 */
- if (*value) {
- int p = atoi(value);
- if (p <= max_ports && p > 0) {
- cfg_for_ports[p] = 1;
- if (strstr(value, "ptp"))
- ptp[p] = 1;
- } else
- ast_log(LOG_WARNING, "Port value \"%s\" of group %s invalid or out of range! Please edit your misdn.conf and then do a \"misdn reload\".\n", value, cat);
- }
- continue;
- }
- PARSE_CFG_STR(context);
- PARSE_CFG_INT(dialplan);
- PARSE_CFG_INT(localdialplan);
- PARSE_CFG_STR(nationalprefix);
- PARSE_CFG_STR(internationalprefix);
- PARSE_CFG_STR(language);
- if (!strcasecmp(v->name, "presentation")) {
- if (v->value && strlen(v->value)) {
- new->pres = (int *)malloc(sizeof(int));
- if (!strcasecmp(v->value, "allowed")) {
- *(new->pres) = 1;
- }
- /* TODO: i assume if it is not "allowed", it is "not_screened" */
- else {
- *(new->pres) = 0;
- }
- }
- continue;
- }
- PARSE_CFG_INT(rxgain);
- PARSE_CFG_INT(txgain);
- PARSE_CFG_BOOL(te_choose_channel);
- PARSE_CFG_BOOL(immediate);
- PARSE_CFG_BOOL(always_immediate);
- PARSE_CFG_BOOL(hold_allowed);
- PARSE_CFG_BOOL(early_bconnect);
- PARSE_CFG_BOOL(use_callingpres);
- PARSE_CFG_HYBRID(echocancel, DEF_ECHOCANCEL);
- PARSE_CFG_BOOL(echocancelwhenbridged);
- PARSE_CFG_HYBRID(echotraining, DEF_ECHOTRAINING);
- PARSE_CFG_STR(callerid);
- PARSE_CFG_STR(method);
- if (!strcasecmp(v->name, "msns")) {
- /* TODO check for value not beeing set, like msns= */
- char *iter;
- char *value = v->value;
-
- while ((iter = strchr(value, ',')) != NULL) {
- *iter = 0;
- /* strip spaces */
- while (*value && *value == ' ') {
- value++;
- }
- /* TODO check for char not 0-9 */
- if (*value){
- int l = strlen(value);
- if (l) {
- struct msn_list *ml = (struct msn_list *)calloc(1, sizeof(struct msn_list));
- ml->msn = (char *)calloc(l+1, sizeof(char));
- strncpy(ml->msn,value,l);
- ml->next = new->msn_list;
- new->msn_list = ml;
- }
- value = ++iter;
- }
- }
- /* the remaining or the only one */
- /* strip spaces */
- while (*value && *value == ' ') {
- value++;
- }
- /* TODO check for char not 0-9 */
- if (*value) {
- int l = strlen(value);
- if (l) {
- struct msn_list *ml = (struct msn_list *)calloc(1, sizeof(struct msn_list));
- ml->msn = (char *)calloc(l+1, sizeof(char));
- strncpy(ml->msn,value,l);
- ml->next = new->msn_list;
- new->msn_list = ml;
- }
- }
- continue;
- }
- if (!strcasecmp(v->name, "callgroup")) {
- new->callgroup = (ast_group_t *)malloc(sizeof(ast_group_t));
- *(new->callgroup)=ast_get_group(v->value);
- continue;
- }
- if (!strcasecmp(v->name, "pickupgroup")) {
- new->pickupgroup = (ast_group_t *)malloc(sizeof(ast_group_t));
- *(new->pickupgroup)=ast_get_group(v->value);
- continue;
- }
- }
- /* store the new config in our array of port configs */
- for (i = 0; i < (max_ports + 1); i++) {
- if (cfg_for_ports[i])
- port_cfg[i] = new;
- }
-}
-
-
-static void fill_defaults (void) {
-
- /* general defaults */
- if (!general_cfg->debug)
- general_cfg->debug = (int*)calloc(1, sizeof(int));
- if (!general_cfg->trace_calls)
- general_cfg->trace_calls = (int*)calloc(1, sizeof(int));
- if (!general_cfg->trace_dir) {
- general_cfg->trace_dir = (char *)malloc(10 * sizeof(char));
- sprintf(general_cfg->trace_dir, "/var/log/");
- }
- if (!general_cfg->bridging) {
- general_cfg->bridging = (int*)malloc(sizeof(int));
- *general_cfg->bridging = 1;
- }
- if (!general_cfg->stop_tone_after_first_digit) {
- general_cfg->stop_tone_after_first_digit = (int*)malloc(sizeof(int));
- *general_cfg->stop_tone_after_first_digit = 1;
- }
- if (!general_cfg->append_digits2exten) {
- general_cfg->append_digits2exten = (int*)malloc(sizeof(int));
- *general_cfg->append_digits2exten = 1;
- }
- if (!general_cfg->l1_info_ok) {
- general_cfg->l1_info_ok = (int*)malloc(sizeof(int));
- *general_cfg->l1_info_ok = 1;
- }
- if (!general_cfg->clear_l3)
- general_cfg->clear_l3 =(int*)calloc(1, sizeof(int));
- if (!general_cfg->dynamic_crypt)
- general_cfg->dynamic_crypt = (int*)calloc(1, sizeof(int));
-
- /* defaults for default port config */
- if (!port_cfg[0])
- port_cfg[0] = (struct port_config*)calloc(1, sizeof(struct port_config));
- if (!port_cfg[0]->name) {
- port_cfg[0]->name = (char *)malloc(8 * sizeof(char));
- sprintf(port_cfg[0]->name, "default");
- }
- if (!port_cfg[0]->rxgain)
- port_cfg[0]->rxgain = (int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->txgain)
- port_cfg[0]->txgain = (int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->te_choose_channel)
- port_cfg[0]->te_choose_channel = (int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->context) {
- port_cfg[0]->context = (char *)malloc(8 * sizeof(char));
- sprintf(port_cfg[0]->context, "default");
- }
- if (!port_cfg[0]->language) {
- port_cfg[0]->language = (char *)malloc(3 * sizeof(char));
- sprintf(port_cfg[0]->language, "en");
- }
- if (!port_cfg[0]->callerid)
- port_cfg[0]->callerid = (char *)calloc(1, sizeof(char));
- if (!port_cfg[0]->method) {
- port_cfg[0]->method = (char *)malloc(9 * sizeof(char));
- sprintf(port_cfg[0]->method, "standard");
- }
- if (!port_cfg[0]->dialplan)
- port_cfg[0]->dialplan = (int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->localdialplan)
- port_cfg[0]->localdialplan = (int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->nationalprefix) {
- port_cfg[0]->nationalprefix = (char *)malloc(2 * sizeof(char));
- sprintf(port_cfg[0]->nationalprefix, "0");
- }
- if (!port_cfg[0]->internationalprefix) {
- port_cfg[0]->internationalprefix = (char *)malloc(3 * sizeof(char));
- sprintf(port_cfg[0]->internationalprefix, "00");
- }
- if (!port_cfg[0]->pres) {
- port_cfg[0]->pres = (int *)malloc(sizeof(int));
- *port_cfg[0]->pres = 1;
- }
- if (!port_cfg[0]->always_immediate)
- port_cfg[0]->always_immediate = (int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->immediate)
- port_cfg[0]->immediate = (int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->hold_allowed)
- port_cfg[0]->hold_allowed = (int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->early_bconnect) {
- port_cfg[0]->early_bconnect = (int *)malloc(sizeof(int));
- *port_cfg[0]->early_bconnect = 1;
- }
- if (!port_cfg[0]->echocancel)
- port_cfg[0]->echocancel=(int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->echocancelwhenbridged)
- port_cfg[0]->echocancelwhenbridged=(int *)calloc(1, sizeof(int));
- if (!port_cfg[0]->echotraining) {
- port_cfg[0]->echotraining=(int *)malloc(sizeof(int));
- *port_cfg[0]->echotraining = 1;
- }
- if (!port_cfg[0]->use_callingpres) {
- port_cfg[0]->use_callingpres = (int *)malloc(sizeof(int));
- *port_cfg[0]->use_callingpres = 1;
- }
- if (!port_cfg[0]->msn_list) {
- port_cfg[0]->msn_list = (struct msn_list *)malloc(sizeof(struct msn_list));
- port_cfg[0]->msn_list->next = NULL;
- port_cfg[0]->msn_list->msn = (char *)calloc(2, sizeof(char));
- *(port_cfg[0]->msn_list->msn) = '*';
- }
-}
-
-void misdn_cfg_reload (void) {
- misdn_cfg_init (0);
-}
-
-void misdn_cfg_destroy (void) {
-
- misdn_cfg_lock();
-
- free_port_cfg();
- free_general_cfg();
-
- free(port_cfg);
- free(general_cfg);
- free(ptp);
-
- misdn_cfg_unlock();
- ast_mutex_destroy(&config_mutex);
-}
-
-void misdn_cfg_init (int this_max_ports)
-{
- char config[]="misdn.conf";
-
- struct ast_config *cfg;
- cfg = AST_LOAD_CFG(config);
- if (!cfg) {
- ast_log(LOG_WARNING,"no misdn.conf ?\n");
- return;
- }
-
- misdn_cfg_lock();
-
- if (this_max_ports) {
- /* this is the first run */
- max_ports = this_max_ports;
- port_cfg = (struct port_config **)calloc(max_ports + 1, sizeof(struct port_config *));
- general_cfg = (struct general_config*)calloc(1, sizeof(struct general_config));
- ptp = (int *)calloc(max_ports + 1, sizeof(int));
- }
- else {
- free_port_cfg();
- free_general_cfg();
- port_cfg = memset(port_cfg, 0, sizeof(struct port_config *) * (max_ports + 1));
- general_cfg = memset(general_cfg, 0, sizeof(struct general_config));
- ptp = memset(ptp, 0, sizeof(int) * (max_ports + 1));
- }
-
- char *cat;
- cat = ast_category_browse(cfg, NULL);
-
- while(cat) {
- struct ast_variable *v=ast_variable_browse(cfg,cat);
- if (!strcasecmp(cat,"general")) {
- build_general_config (v);
- } else {
- build_port_config (v, cat);
- }
- cat=ast_category_browse(cfg,cat);
- }
-
- fill_defaults();
-
- misdn_cfg_unlock();
-
- AST_DESTROY_CFG(cfg);
-}
diff --git a/1.2-netsec/channels/chan_modem.c b/1.2-netsec/channels/chan_modem.c
deleted file mode 100644
index 09adc4733..000000000
--- a/1.2-netsec/channels/chan_modem.c
+++ /dev/null
@@ -1,1117 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief A/Open ITU-56/2 Voice Modem Driver (Rockwell, IS-101, and others)
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/termios.h>
-#include <sys/signal.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/vmodem.h"
-#include "asterisk/utils.h"
-
-/* Up to 10 seconds for an echo to arrive */
-#define ECHO_TIMEOUT 10
-
-static const char desc[] = "Generic Voice Modem Driver";
-static const char tdesc[] = "Generic Voice Modem Channel Driver";
-static const char type[] = "Modem";
-static const char config[] = "modem.conf";
-static char dialtype = 'T';
-static int gmode = MODEM_MODE_IMMEDIATE;
-
-/* Default modem type */
-static char mtype[80] = "autodetect";
-/* Default context for incoming calls */
-static char context[AST_MAX_EXTENSION]= "default";
-
-/* Default language */
-static char language[MAX_LANGUAGE] = "";
-
-/* Initialization String */
-static char initstr[AST_MAX_INIT_STR] = "ATE0Q0";
-
-/* Default MSN */
-static char msn[AST_MAX_EXTENSION]="";
-
-/* Default Listen */
-static char incomingmsn[AST_MAX_EXTENSION]="";
-
-/* Default DTMF-detection mode (i4l/asterisk) */
-static int dtmfmode = MODEM_DTMF_AST;
-/* Default DTMF-generation mode (i4l (outband) / asterisk (inband) */
-static int dtmfmodegen = MODEM_DTMF_AST;
-
-struct ast_dsp *dsp = NULL;
-
-/* Default valid outgoing MSN */
-static char outgoingmsn[AST_MAX_EXTENSION]="";
-
-/* Default group */
-static ast_group_t cur_group = 0;
-
-static int usecnt =0;
-
-static int baudrate = 115200;
-
-static int stripmsd = 0;
-
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-/* Protect the interface list (of ast_modem_pvt's) */
-AST_MUTEX_DEFINE_STATIC(iflock);
-
-/* Protect the monitoring thread, so only one process can kill or start it, and not
- when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(monlock);
-
-/* This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
-
-static int restart_monitor(void);
-
-int dep_warning = 0;
-
-static struct ast_channel *modem_request(const char *type, int format, void *data, int *cause);
-static int modem_digit(struct ast_channel *ast, char digit);
-static int modem_call(struct ast_channel *ast, char *idest, int timeout);
-static int modem_hangup(struct ast_channel *ast);
-static int modem_answer(struct ast_channel *ast);
-static struct ast_frame *modem_read(struct ast_channel *);
-static int modem_write(struct ast_channel *ast, struct ast_frame *frame);
-static int modem_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-
-static const struct ast_channel_tech modem_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_SLINEAR,
- .requester = modem_request,
- .send_digit = modem_digit,
- .call = modem_call,
- .hangup = modem_hangup,
- .answer = modem_answer,
- .read = modem_read,
- .write = modem_write,
- .fixup = modem_fixup,
-};
-
-/* The private structures of the Phone Jack channels are linked for
- selecting outgoing channels */
-
-static struct ast_modem_pvt *iflist = NULL;
-
-static int modem_digit(struct ast_channel *ast, char digit)
-{
- struct ast_modem_pvt *p;
- p = ast->tech_pvt;
- if (p->mc->dialdigit)
- return p->mc->dialdigit(p, digit);
- ast_log(LOG_DEBUG, "Channel %s lacks digit dialing\n", ast->name);
- return -1;
-}
-
-static struct ast_modem_driver *drivers = NULL;
-
-static struct ast_modem_driver *find_capability(char *ident)
-{
- struct ast_modem_driver *mc;
- int x;
- mc = drivers;
- while(mc) {
- for (x=0;mc->idents[x];x++) {
- if (!strcmp(ident, mc->idents[x]))
- break;
- }
- if (mc->idents[x])
- break;
- mc = mc->next;
- }
- if (mc) {
- if (mc->incusecnt)
- mc->incusecnt();
- }
- return mc;
-}
-
-static struct ast_modem_driver *find_driver(char *drv)
-{
- struct ast_modem_driver *mc;
- mc = drivers;
- while(mc) {
- if (!strcasecmp(mc->name, drv))
- break;
- mc = mc->next;
- }
- if (mc) {
- if (mc->incusecnt)
- mc->incusecnt();
- }
- return mc;
-}
-
-int ast_register_modem_driver(struct ast_modem_driver *mc)
-{
- mc->next = drivers;
- drivers = mc;
- return 0;
-}
-
-int ast_unregister_modem_driver(struct ast_modem_driver *mc)
-{
- struct ast_modem_driver *last = NULL, *cur;
- cur = drivers;
- while(cur) {
- if (cur == mc) {
- if (last)
- last->next = mc->next;
- else
- drivers = mc->next;
- return 0;
- }
- cur = cur->next;
- }
- return -1;
-}
-
-static int modem_call(struct ast_channel *ast, char *idest, int timeout)
-{
- struct ast_modem_pvt *p;
- int ms = timeout;
- char rdest[80], *where, dstr[100] = "";
- char *stringp=NULL;
- strncpy(rdest, idest, sizeof(rdest)-1);
- stringp=rdest;
- strsep(&stringp, ":");
- where = strsep(&stringp, ":");
- if (!where) {
- ast_log(LOG_WARNING, "Destination %s requres a real destination (device:destination)\n", idest);
- return -1;
- }
- p = ast->tech_pvt;
- strncpy(dstr, where + p->stripmsd, sizeof(dstr) - 1);
- /* if not a transfer or just sending tones, must be in correct state */
- if (strcasecmp(rdest, "transfer") && strcasecmp(rdest,"sendtones")) {
- if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "modem_call called on %s, neither down nor reserved\n", ast->name);
- return -1;
- }
- }
- if (!strcasecmp(rdest,"transfer")) /* if a transfer, put in transfer stuff */
- {
- snprintf(dstr, sizeof(dstr), "!,%s", where + p->stripmsd);
- }
- if (!strcasecmp(where, "handset")) {
- if (p->mc->setdev)
- if (p->mc->setdev(p, MODEM_DEV_HANDSET))
- return -1;
- /* Should be immediately up */
- ast_setstate(ast, AST_STATE_UP);
- } else {
- if (p->mc->setdev)
- if (p->mc->setdev(p, MODEM_DEV_TELCO_SPK))
- return -1;
- if (p->mc->dial)
- p->mc->dial(p, dstr);
- ast_setstate(ast, AST_STATE_DIALING);
- while((ast->_state != AST_STATE_UP) && (ms > 0)) {
- ms = ast_waitfor(ast, ms);
- /* Just read packets and watch what happens */
- if (ms > 0) {
- if (!modem_read(ast))
- return -1;
- }
- }
- if (ms < 0)
- return -1;
- }
- return 0;
-}
-
-int ast_modem_send(struct ast_modem_pvt *p, char *cmd, int len)
-{
- int i;
- usleep(5000);
- if (!len) {
- for(i = 0; cmd[i];)
- {
- if (fwrite(cmd + i,1,1,p->f) != 1)
- {
- if (errno == EWOULDBLOCK) continue;
- return -1;
- }
- i++;
- }
- tcdrain(fileno(p->f));
- fprintf(p->f,"\r\n");
- return 0;
- } else {
- if (fwrite(cmd, 1, len, p->f) < len)
- return -1;
- return 0;
- }
-}
-
-int ast_modem_read_response(struct ast_modem_pvt *p, int timeout)
-{
- int res = -1,c,i;
- timeout *= 1000;
- p->response[0] = 0;
- c = i = 0;
- do {
- res = ast_waitfor_n_fd(&p->fd, 1, &timeout, NULL);
- if (res < 0) {
- strncpy(p->response, "(No Response)", sizeof(p->response)-1);
- return -1;
- }
- /* get no more then buffer length */
- while(i < sizeof(p->response) - 1)
- {
- c = fgetc(p->f); /* get a char */
- if (c < 1) /* if error */
- {
- /* if nothing in buffer, go back into timeout stuff */
- if (errno == EWOULDBLOCK) break;
- /* return as error */
- strncpy(p->response, "(No Response)", sizeof(p->response)-1);
- return -1;
- }
- /* save char */
- p->response[i++] = c;
- p->response[i] = 0;
- /* if end of input */
- if (c == '\n') break;
- }
- if (c >= 0) /* if input terminated normally */
- {
- /* ignore just CR/LF */
- if (!strcmp(p->response,"\r\n"))
- {
- /* reset input buffer stuff */
- i = 0;
- p->response[0] = 0;
- }
- else /* otherwise return with info in buffer */
- {
- return 0;
- }
- }
- } while(timeout > 0);
- strncpy(p->response, "(No Response)", sizeof(p->response)-1);
- return -1;
-}
-
-int ast_modem_expect(struct ast_modem_pvt *p, char *result, int timeout)
-{
- int res = -1;
- timeout *= 1000;
- strncpy(p->response, "(No Response)", sizeof(p->response)-1);
- do {
- res = ast_waitfor_n_fd(&p->fd, 1, &timeout, NULL);
- if (res < 0) {
- return -1;
- }
- /* Read a response */
- fgets(p->response, sizeof(p->response), p->f);
-#if 0
- fprintf(stderr, "Modem said: %s", p->response);
-#endif
- if (!strncasecmp(p->response, result, strlen(result)))
- return 0;
- } while(timeout > 0);
- return -1;
-}
-
-void ast_modem_trim(char *s)
-{
- int x;
- x = strlen(s) - 1;
- while(x >= 0) {
- if ((s[x] != '\r') && (s[x] != '\n') && (s[x] != ' '))
- break;
- s[x] = '\0';
- x--;
- }
-}
-
-static int modem_setup(struct ast_modem_pvt *p, int baudrate)
-{
-
- /* Make sure there's a modem there and that it's in a reasonable
- mode. Set the baud rate, etc. */
- char identity[256];
- char *ident = NULL;
- char etx[2] = { 0x10, '!' };
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting up modem %s\n", p->dev);
- if (ast_modem_send(p, etx, 2)) {
- ast_log(LOG_WARNING, "Failed to send ETX?\n");
- return -1;
- }
- if (ast_modem_send(p, "\r\n", 2)) {
- ast_log(LOG_WARNING, "Failed to send enter?\n");
- return -1;
- }
- usleep(10000);
- /* Read any outstanding stuff */
- while(!ast_modem_read_response(p, 0));
- if (ast_modem_send(p, "ATZ", 0)) {
- ast_log(LOG_WARNING, "Modem not responding on %s\n", p->dev);
- return -1;
- }
- if (ast_modem_expect(p, "OK", ECHO_TIMEOUT)) {
- ast_log(LOG_WARNING, "Modem reset failed: %s\n", p->response);
- return -1;
- }
- if (ast_modem_send(p, p->initstr, 0)) {
- ast_log(LOG_WARNING, "Modem not responding on %s\n", p->dev);
- return -1;
- }
- if (ast_modem_expect(p, "OK", ECHO_TIMEOUT)) {
- ast_log(LOG_WARNING, "Modem initialization failed: %s\n", p->response);
- return -1;
- }
- if (ast_modem_send(p, "ATI3", 0)) {
- ast_log(LOG_WARNING, "Modem not responding on %s\n", p->dev);
- return -1;
- }
- if (ast_modem_read_response(p, ECHO_TIMEOUT)) {
- ast_log(LOG_WARNING, "Modem did not provide identification\n");
- return -1;
- }
- strncpy(identity, p->response, sizeof(identity)-1);
- ast_modem_trim(identity);
- if (ast_modem_expect(p, "OK", ECHO_TIMEOUT)) {
- ast_log(LOG_WARNING, "Modem did not provide identification\n");
- return -1;
- }
- if (!strcasecmp(mtype, "autodetect")) {
- p->mc = find_capability(identity);
- if (!p->mc) {
- ast_log(LOG_WARNING, "Unable to autodetect modem. You'll need to specify a driver in modem.conf. Please report modem identification (%s) and which driver works to markster@linux-support.net.\n", identity);
- return -1;
- }
- } else {
- p->mc = find_driver(mtype);
- if (!p->mc) {
- ast_log(LOG_WARNING, "No driver for modem type '%s'\n", mtype);
- return -1;
- }
- }
- if (p->mc->init) {
- if (p->mc->init(p)) {
- ast_log(LOG_WARNING, "Modem Initialization Failed on '%s', driver %s.\n", p->dev, p->mc->name);
- p->mc->decusecnt();
- return -1;
- }
- }
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Configured modem %s with driver %s (%s)\n", p->dev, p->mc->name, p->mc->identify ? (ident = p->mc->identify(p)) : "No identification");
- }
- if (ident)
- free(ident);
- return 0;
-}
-
-static int modem_hangup(struct ast_channel *ast)
-{
- struct ast_modem_pvt *p;
- if (option_debug)
- ast_log(LOG_DEBUG, "modem_hangup(%s)\n", ast->name);
- p = ast->tech_pvt;
- /* Hang up */
- if (p->mc->hangup)
- p->mc->hangup(p);
- /* Re-initialize */
- if (p->mc->init)
- p->mc->init(p);
- ast_setstate(ast, AST_STATE_DOWN);
- memset(p->cid_num, 0, sizeof(p->cid_num));
- memset(p->cid_name, 0, sizeof(p->cid_name));
- memset(p->dnid, 0, sizeof(p->dnid));
- ((struct ast_modem_pvt *)(ast->tech_pvt))->owner = NULL;
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- if (usecnt < 0)
- ast_log(LOG_WARNING, "Usecnt < 0???\n");
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
- ast->tech_pvt = NULL;
- ast_setstate(ast, AST_STATE_DOWN);
- restart_monitor();
- return 0;
-}
-
-static int modem_answer(struct ast_channel *ast)
-{
- struct ast_modem_pvt *p;
- int res=0;
- if (option_debug)
- ast_log(LOG_DEBUG, "modem_answer(%s)\n", ast->name);
- p = ast->tech_pvt;
- if (p->mc->answer) {
- res = p->mc->answer(p);
- }
- if (!res) {
- ast->rings = 0;
- ast_setstate(ast, AST_STATE_UP);
- }
- return res;
-}
-
-#if 0
-static char modem_2digit(char c)
-{
- if (c == 12)
- return '#';
- else if (c == 11)
- return '*';
- else if ((c < 10) && (c >= 0))
- return '0' + c - 1;
- else
- return '?';
-}
-#endif
-static struct ast_frame *modem_read(struct ast_channel *ast)
-{
- struct ast_modem_pvt *p = ast->tech_pvt;
- struct ast_frame *fr=NULL;
- if (p->mc->read)
- fr = p->mc->read(p);
- return fr;
-}
-
-static int modem_write(struct ast_channel *ast, struct ast_frame *frame)
-{
- int res=0;
- long flags;
- struct ast_modem_pvt *p = ast->tech_pvt;
-
- /* Modems tend to get upset when they receive data whilst in
- * command mode. This makes esp. dial commands short lived.
- * Pauline Middelink - 2002-09-24 */
- if (ast->_state != AST_STATE_UP)
- return 0;
-
- /* Temporarily make non-blocking */
- flags = fcntl(ast->fds[0], F_GETFL);
- fcntl(ast->fds[0], F_SETFL, flags | O_NONBLOCK);
-
- if (p->mc->write)
- res = p->mc->write(p, frame);
-
- /* Block again */
- fcntl(ast->fds[0], F_SETFL, flags);
- return res;
-}
-
-static int modem_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct ast_modem_pvt *p = newchan->tech_pvt;
-ast_log(LOG_WARNING, "fixup called\n");
- if (p->owner!=oldchan) {
- ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n",oldchan,p->owner);
- return -1;
- }
- p->owner = newchan;
- return 0;
-}
-
-struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
-{
- struct ast_channel *tmp;
- tmp = ast_channel_alloc(1);
- if (tmp) {
- tmp->tech = &modem_tech;
- snprintf(tmp->name, sizeof(tmp->name), "Modem[%s]/%s", i->mc->name, i->dev + 5);
- tmp->type = type;
- tmp->fds[0] = i->fd;
- tmp->nativeformats = i->mc->formats;
- ast_setstate(tmp, state);
- if (state == AST_STATE_RING)
- tmp->rings = 1;
- tmp->tech_pvt = i;
- strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
-
- if (!ast_strlen_zero(i->cid_num))
- tmp->cid.cid_num = strdup(i->cid_num);
- if (!ast_strlen_zero(i->cid_name))
- tmp->cid.cid_name = strdup(i->cid_name);
-
- if (!ast_strlen_zero(i->language))
- strncpy(tmp->language,i->language, sizeof(tmp->language)-1);
- if (!ast_strlen_zero(i->dnid))
- strncpy(tmp->exten, i->dnid, sizeof(tmp->exten) - 1);
- i->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- tmp = NULL;
- }
- }
- } else
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- return tmp;
-}
-
-static void modem_mini_packet(struct ast_modem_pvt *i)
-{
- struct ast_frame *fr;
- fr = i->mc->read(i);
- if (!fr) return;
- if (fr->frametype == AST_FRAME_CONTROL) {
- if (fr->subclass == AST_CONTROL_RING) {
- ast_modem_new(i, AST_STATE_RING);
- }
- }
-}
-
-static void *do_monitor(void *data)
-{
- fd_set rfds, efds;
- int n, res;
- struct ast_modem_pvt *i;
- /* This thread monitors all the frame relay interfaces which are not yet in use
- (and thus do not have a separate thread) indefinitely */
- /* From here on out, we die whenever asked */
-#if 0
- if (pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)) {
- ast_log(LOG_WARNING, "Unable to set cancel type to asynchronous\n");
- return NULL;
- }
-#endif
- for(;;) {
- /* Don't let anybody kill us right away. Nobody should lock the interface list
- and wait for the monitor list, but the other way around is okay. */
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_ERROR, "Unable to grab monitor lock\n");
- return NULL;
- }
- /* Lock the interface list */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_ERROR, "Unable to grab interface lock\n");
- ast_mutex_unlock(&monlock);
- return NULL;
- }
- /* Build the stuff we're going to select on, that is the socket of every
- ast_modem_pvt that does not have an associated owner channel */
- n = -1;
- FD_ZERO(&rfds);
- FD_ZERO(&efds);
- i = iflist;
- while(i) {
- if (FD_ISSET(i->fd, &rfds))
- ast_log(LOG_WARNING, "Descriptor %d appears twice (%s)?\n", i->fd, i->dev);
- if (!i->owner) {
- /* This needs to be watched, as it lacks an owner */
- FD_SET(i->fd, &rfds);
- FD_SET(i->fd, &efds);
- if (i->fd > n)
- n = i->fd;
- }
-
- i = i->next;
- }
- /* Okay, now that we know what to do, release the interface lock */
- ast_mutex_unlock(&iflock);
-
- /* And from now on, we're okay to be killed, so release the monitor lock as well */
- ast_mutex_unlock(&monlock);
-#if 0
- ast_log(LOG_DEBUG, "In monitor, n=%d, pid=%d\n", n, getpid());
-#endif
- /* Wait indefinitely for something to happen */
- pthread_testcancel();
- res = ast_select(n + 1, &rfds, NULL, &efds, NULL);
- pthread_testcancel();
- /* Okay, select has finished. Let's see what happened. */
- if (res < 1) {
- if ((errno != EINTR) && (errno != EAGAIN))
- ast_log(LOG_WARNING, "select return %d: %s\n", res, strerror(errno));
- continue;
- }
- /* Alright, lock the interface list again, and let's look and see what has
- happened */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- continue;
- }
- i = iflist;
- while(i) {
- if (FD_ISSET(i->fd, &rfds) || FD_ISSET(i->fd, &efds)) {
- if (i->owner) {
- ast_log(LOG_WARNING, "Whoa.... I'm owned but found (%d, %s)...\n", i->fd, i->dev);
- i = i->next;
- continue;
- }
- modem_mini_packet(i);
- }
- i=i->next;
- }
- ast_mutex_unlock(&iflock);
- }
- /* Never reached */
- return NULL;
-
-}
-
-static int restart_monitor()
-{
- /* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == AST_PTHREADT_STOP)
- return 0;
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_WARNING, "Unable to lock monitor\n");
- return -1;
- }
- if (monitor_thread == pthread_self()) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- return -1;
- }
- if (monitor_thread != AST_PTHREADT_NULL) {
- pthread_kill(monitor_thread, SIGURG);
- pthread_join(monitor_thread, NULL);
- } else {
- /* Start a new monitor */
- if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- return -1;
- }
- }
- ast_mutex_unlock(&monlock);
- return 0;
-}
-
-static void stty(struct ast_modem_pvt *p)
-{
- struct termios mode;
- memset(&mode, 0, sizeof(mode));
- if (tcgetattr(p->fd, &mode)) {
- ast_log(LOG_WARNING, "Unable to get serial parameters on %s: %s\n", p->dev, strerror(errno));
- return;
- }
-#ifndef SOLARIS
- cfmakeraw(&mode);
-#else
- mode.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
- |INLCR|IGNCR|ICRNL|IXON);
- mode.c_oflag &= ~OPOST;
- mode.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
- mode.c_cflag &= ~(CSIZE|PARENB);
- mode.c_cflag |= CS8;
-#endif
-
- cfsetispeed(&mode, B115200);
- cfsetospeed(&mode, B115200);
- if (tcsetattr(p->fd, TCSANOW, &mode))
- ast_log(LOG_WARNING, "Unable to set serial parameters on %s: %s\n", p->dev, strerror(errno));
-
-}
-
-static struct ast_modem_pvt *mkif(char *iface)
-{
- /* Make a ast_modem_pvt structure for this interface */
- struct ast_modem_pvt *tmp;
-#if 0
- int flags;
-#endif
-
- tmp = malloc(sizeof(struct ast_modem_pvt));
- if (tmp) {
- memset(tmp, 0, sizeof(struct ast_modem_pvt));
- tmp->fd = open(iface, O_RDWR | O_NONBLOCK);
- if (tmp->fd < 0) {
- ast_log(LOG_WARNING, "Unable to open '%s'\n", iface);
- free(tmp);
- return NULL;
- }
- strncpy(tmp->language, language, sizeof(tmp->language)-1);
- strncpy(tmp->msn, msn, sizeof(tmp->msn)-1);
- strncpy(tmp->incomingmsn, incomingmsn, sizeof(tmp->incomingmsn)-1);
- tmp->dtmfmode = dtmfmode;
- tmp->dtmfmodegen = dtmfmodegen;
- snprintf(tmp->outgoingmsn, sizeof(tmp->outgoingmsn), ",%s,", outgoingmsn);
- strncpy(tmp->dev, iface, sizeof(tmp->dev)-1);
- /* Maybe in the future we want to allow variable
- serial settings */
- stty(tmp);
- tmp->f = fdopen(tmp->fd, "w+");
- /* Disable buffering */
- setvbuf(tmp->f, NULL, _IONBF,0);
- if (tmp->f < 0) {
- ast_log(LOG_WARNING, "Unable to fdopen '%s'\n", iface);
- free(tmp);
- return NULL;
- }
- tmp->owner = NULL;
- tmp->ministate = 0;
- tmp->stripmsd = stripmsd;
- tmp->dialtype = dialtype;
- tmp->mode = gmode;
- tmp->group = cur_group;
- memset(tmp->cid_num, 0, sizeof(tmp->cid_num));
- memset(tmp->cid_name, 0, sizeof(tmp->cid_name));
- strncpy(tmp->context, context, sizeof(tmp->context)-1);
- strncpy(tmp->initstr, initstr, sizeof(tmp->initstr)-1);
- tmp->next = NULL;
- tmp->obuflen = 0;
-
- if (modem_setup(tmp, baudrate) < 0) {
- ast_log(LOG_WARNING, "Unable to configure modem '%s'\n", iface);
- free(tmp);
- return NULL;
- }
- }
- return tmp;
-}
-
-static struct ast_channel *modem_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- struct ast_modem_pvt *p;
- struct ast_channel *tmp = NULL;
- char dev[80];
- ast_group_t group = 0;
- int groupint;
- char *stringp=NULL;
- strncpy(dev, (char *)data, sizeof(dev)-1);
- stringp=dev;
- strsep(&stringp, ":");
- oldformat = format;
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "This channel driver is deprecated. Please see the UPGRADE.txt file.\n");
- dep_warning = 1;
- }
-
- if (dev[0]=='g' && isdigit(dev[1])) {
- /* Retrieve the group number */
- if (sscanf(dev+1, "%u", &groupint) < 1) {
- ast_log(LOG_WARNING, "Unable to determine group from [%s]\n", (char *)data);
- return NULL;
- }
- group = 1 << groupint;
- }
-
- /* Search for an unowned channel */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_ERROR, "Unable to lock interface list???\n");
- return NULL;
- }
- p = iflist;
- while(p) {
- if (group) {
- /* if it belongs to the proper group, and the format matches
- * and it is not in use, we found a candidate! */
- if (p->group & group &&
- p->mc->formats & format &&
- !p->owner) {
- /* XXX Not quite sure that not having an owner is
- * sufficient evidence of beeing a free device XXX */
- tmp = ast_modem_new(p, AST_STATE_DOWN);
- restart_monitor();
- break;
- }
- } else {
- if (!strcmp(dev, p->dev + 5)) {
- if (p->mc->formats & format) {
- if (!p->owner) {
- tmp = ast_modem_new(p, AST_STATE_DOWN);
- restart_monitor();
- break;
- } else
- ast_log(LOG_WARNING, "Device '%s' is busy\n", p->dev);
- } else
- ast_log(LOG_WARNING, "Asked for a format %s line on %s\n", ast_getformatname(format), p->dev);
- break;
- }
- }
- p = p->next;
- }
- if (!p)
- ast_log(LOG_WARNING, "Requested device '%s' does not exist\n", dev);
-
- ast_mutex_unlock(&iflock);
- return tmp;
-}
-
-static ast_group_t get_group(char *s)
-{
- char *piece;
- int start, finish,x;
- ast_group_t group = 0;
- char *copy = ast_strdupa(s);
- char *stringp=NULL;
- if (!copy) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return 0;
- }
- stringp=copy;
- piece = strsep(&stringp, ",");
- while(piece) {
- if (sscanf(piece, "%d-%d", &start, &finish) == 2) {
- /* Range */
- } else if (sscanf(piece, "%d", &start)) {
- /* Just one */
- finish = start;
- } else {
- ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'. Using '0'\n", s,piece);
- return 0;
- }
- piece = strsep(&stringp, ",");
-
- for (x=start;x<=finish;x++) {
- if ((x > 63) || (x < 0)) {
- ast_log(LOG_WARNING, "Ignoring invalid group %d\n", x);
- break;
- }
- group |= (1 << x);
- }
- }
- return group;
-}
-
-static int __unload_module(void)
-{
- struct ast_modem_pvt *p, *pl;
- /* First, take us out of the channel loop */
- ast_channel_unregister(&modem_tech);
- if (!ast_mutex_lock(&iflock)) {
- /* Hangup all interfaces if they have an owner */
- p = iflist;
- while(p) {
- if (p->owner)
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- p = p->next;
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread != AST_PTHREADT_NULL && monitor_thread != AST_PTHREADT_STOP) {
- pthread_cancel(monitor_thread);
- pthread_join(monitor_thread, NULL);
- }
- monitor_thread = AST_PTHREADT_STOP;
- ast_mutex_unlock(&monlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-
- if (!ast_mutex_lock(&iflock)) {
- /* Destroy all the interfaces and free their memory */
- p = iflist;
- while(p) {
- /* Close the socket, assuming it's real */
- if (p->fd > -1)
- close(p->fd);
- pl = p;
- p = p->next;
- /* Free associated memory */
- free(pl);
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-
- return 0;
-}
-
-int unload_module()
-{
- return __unload_module();
-}
-
-int load_module()
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- struct ast_modem_pvt *tmp;
- char driver[80];
- cfg = ast_config_load(config);
-
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_ERROR, "Unable to load config %s\n", config);
- return -1;
- }
- if (ast_mutex_lock(&iflock)) {
- /* It's a little silly to lock it, but we mind as well just to be sure */
- ast_log(LOG_ERROR, "Unable to lock interface list???\n");
- return -1;
- }
- v = ast_variable_browse(cfg, "interfaces");
- while(v) {
- /* Create the interface list */
- if (!strcasecmp(v->name, "device")) {
- tmp = mkif(v->value);
- if (tmp) {
- tmp->next = iflist;
- iflist = tmp;
-
- } else {
- ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- __unload_module();
- return -1;
- }
- } else if (!strcasecmp(v->name, "driver")) {
- snprintf(driver, sizeof(driver), "chan_modem_%s.so", v->value);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Loading modem driver %s", driver);
-
- if (ast_load_resource(driver)) {
- ast_log(LOG_ERROR, "Failed to load driver %s\n", driver);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- __unload_module();
- return -1;
- }
- } else if (!strcasecmp(v->name, "mode")) {
- if (!strncasecmp(v->value, "ri", 2))
- gmode = MODEM_MODE_WAIT_RING;
- else if (!strncasecmp(v->value, "im", 2))
- gmode = MODEM_MODE_IMMEDIATE;
- else if (!strncasecmp(v->value, "an", 2))
- gmode = MODEM_MODE_WAIT_ANSWER;
- else
- ast_log(LOG_WARNING, "Unknown mode: %s\n", v->value);
- } else if (!strcasecmp(v->name, "stripmsd")) {
- stripmsd = atoi(v->value);
- } else if (!strcasecmp(v->name, "type")) {
- strncpy(mtype, v->value, sizeof(mtype)-1);
- } else if (!strcasecmp(v->name, "initstr")) {
- strncpy(initstr, v->value, sizeof(initstr)-1);
- } else if (!strcasecmp(v->name, "dialtype")) {
- dialtype = toupper(v->value[0]);
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(context, v->value, sizeof(context)-1);
- } else if (!strcasecmp(v->name, "msn")) {
- strncpy(msn, v->value, sizeof(msn)-1);
- } else if (!strcasecmp(v->name, "incomingmsn")) {
- strncpy(incomingmsn, v->value, sizeof(incomingmsn)-1);
- } else if (!strcasecmp(v->name, "dtmfmode")) {
- char tmp[80];
- char *alt;
- strncpy(tmp, v->value, sizeof(tmp) - 1);
- alt = strchr(tmp, '/');
- if (!strcasecmp(tmp, "none"))
- dtmfmode=MODEM_DTMF_NONE;
- else if (!strcasecmp(tmp, "asterisk"))
- dtmfmode = MODEM_DTMF_AST;
- else if (!strcasecmp(tmp, "i4l"))
- dtmfmode = MODEM_DTMF_I4L;
- else {
- ast_log(LOG_WARNING, "Unknown dtmf detection mode '%s', using 'asterisk'\n", v->value);
- dtmfmode = MODEM_DTMF_AST;
- }
- if (alt) {
- if (!strcasecmp(alt, "none"))
- dtmfmodegen=MODEM_DTMF_NONE;
- else if (!strcasecmp(alt, "asterisk"))
- dtmfmodegen = MODEM_DTMF_AST;
- else if (!strcasecmp(alt, "i4l"))
- dtmfmodegen = MODEM_DTMF_I4L;
- else if (!strcasecmp(alt, "both"))
- dtmfmodegen = MODEM_DTMF_I4L | MODEM_DTMF_AST;
- else {
- ast_log(LOG_WARNING, "Unknown dtmf generation mode '%s', using 'asterisk'\n", v->value);
- dtmfmodegen = MODEM_DTMF_AST;
- }
- } else
- dtmfmodegen = dtmfmode;
- } else if (!strcasecmp(v->name, "outgoingmsn")) {
- strncpy(outgoingmsn, v->value, sizeof(outgoingmsn)-1);
- } else if (!strcasecmp(v->name, "language")) {
- strncpy(language, v->value, sizeof(language)-1);
- } else if (!strcasecmp(v->name, "group")) {
- cur_group = get_group(v->value);
- }
- v = v->next;
- }
- ast_mutex_unlock(&iflock);
- if (ast_channel_register(&modem_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- ast_config_destroy(cfg);
- __unload_module();
- return -1;
- }
- ast_config_destroy(cfg);
- /* And start the monitor for the first time */
- restart_monitor();
- return 0;
-}
-
-int usecount(void)
-{
- return usecnt;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/channels/chan_modem_aopen.c b/1.2-netsec/channels/chan_modem_aopen.c
deleted file mode 100644
index 0183cde92..000000000
--- a/1.2-netsec/channels/chan_modem_aopen.c
+++ /dev/null
@@ -1,501 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
- *
- * A/Open ITU-56/2 Voice Modem Driver (Rockwell, IS-101, and others)
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/vmodem.h"
-#include "asterisk/module.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-
-#define STATE_COMMAND 0
-#define STATE_VOICE 1
-
-#define VRA "40" /* Number of 100ms of non-ring after a ring cadence after which we consider the lien to be answered */
-#define VRN "100" /* Number of 100ms of non-ring with no cadence after which we assume an answer */
-
-static char *breakcmd = "\0x10\0x03";
-
-static char *desc = "A/Open (Rockwell Chipset) ITU-2 VoiceModem Driver";
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-static char *aopen_idents[] = {
- /* Identify A/Open Modem */
- "V2.210-V90_2M_DLP",
- NULL
-};
-
-static int aopen_setdev(struct ast_modem_pvt *p, int dev)
-{
- char cmd[80];
- if (ast_modem_send(p, "AT#VLS?", 0)) {
- ast_log(LOG_WARNING, "Unable to select current mode %d\n", dev);
- return -1;
- }
- if (ast_modem_read_response(p, 5)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- ast_modem_trim(p->response);
- strncpy(cmd, p->response, sizeof(cmd)-1);
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- if (dev == atoi(cmd)) {
- /* We're already in the right mode, don't bother changing for fear of
- hanging up */
- return 0;
- }
- snprintf(cmd, sizeof(cmd), "AT#VLS=%d", dev);
- if (ast_modem_send(p, cmd, 0)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- if (ast_modem_read_response(p, 5)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- ast_modem_trim(p->response);
- if (strcasecmp(p->response, "VCON") && strcasecmp(p->response, "OK")) {
- ast_log(LOG_WARNING, "Unexpected reply: %s\n", p->response);
- return -1;
- }
- return 0;
-}
-
-static int aopen_startrec(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "AT#VRX", 0) ||
- ast_modem_expect(p, "CONNECT", 5)) {
- ast_log(LOG_WARNING, "Unable to start recording\n");
- return -1;
- }
- p->ministate = STATE_VOICE;
- return 0;
-}
-
-static int aopen_break(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "\r\n", 2)) {
- ast_log(LOG_WARNING, "Failed to send enter?\n");
- return -1;
- }
- if (ast_modem_send(p, breakcmd, 2)) {
- ast_log(LOG_WARNING, "Failed to break\n");
- return -1;
- }
- if (ast_modem_send(p, "\r\n", 2)) {
- ast_log(LOG_WARNING, "Failed to send enter?\n");
- return -1;
- }
- /* Read any outstanding junk */
- while(!ast_modem_read_response(p, 1));
- if (ast_modem_send(p, "AT", 0)) {
- /* Modem might be stuck in some weird mode, try to get it out */
- ast_modem_send(p, "+++", 3);
- if (ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- if (ast_modem_send(p, "AT", 0)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- }
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- return 0;
-}
-
-static int aopen_init(struct ast_modem_pvt *p)
-{
- if (option_debug)
- ast_log(LOG_DEBUG, "aopen_init()\n");
- if (aopen_break(p))
- return -1;
- /* Force into command mode */
- p->ministate = STATE_COMMAND;
- if (ast_modem_send(p, "AT#BDR=0", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to auto-baud\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#CLS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VBS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 8-bit mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VSR=8000", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 8000 Hz sampling\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VLS=0", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to telco interface\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VRA=" VRA, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 'ringback goes away' timer\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VRN=" VRN, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 'ringback never came timer'\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VTD=3F,3F,3F", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to tone detection\n");
- return -1;
- }
-
- return 0;
-}
-
-static struct ast_frame *aopen_handle_escape(struct ast_modem_pvt *p, char esc)
-{
- /* Handle escaped characters -- but sometimes we call it directly as
- a quick way to cause known responses */
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- p->fr.data = NULL;
- p->fr.datalen = 0;
- p->fr.samples = 0;
- p->fr.offset = 0;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- if (esc)
- ast_log(LOG_DEBUG, "Escaped character '%c'\n", esc);
-
- switch(esc) {
- case 'R': /* Pseudo ring */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- return &p->fr;
- case 'X': /* Pseudo connect */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- if (p->owner)
- ast_setstate(p->owner, AST_STATE_UP);
- if (aopen_startrec(p))
- return NULL;
- return &p->fr;
- case 'b': /* Busy signal */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_BUSY;
- return &p->fr;
- case 'o': /* Overrun */
- ast_log(LOG_WARNING, "Overflow on modem, flushing buffers\n");
- if (ast_modem_send(p, "\0x10E", 2))
- ast_log(LOG_WARNING, "Unable to flush buffers\n");
- return &p->fr;
- case 'u': /* Underrun */
- ast_log(LOG_WARNING, "Data underrun\n");
- /* Fall Through */
- case CHAR_ETX: /* End Transmission */
- case 'd': /* Dialtone */
- case 'c': /* Calling Tone */
- case 'e': /* European version */
- case 'a': /* Answer Tone */
- case 'f': /* Bell Answer Tone */
- case 'T': /* Timing mark */
- case 't': /* Handset off hook */
- case 'h': /* Handset hungup */
- case 0: /* Pseudo signal */
- /* Ignore */
- return &p->fr;
- default:
- ast_log(LOG_DEBUG, "Unknown Escaped character '%c' (%d)\n", esc, esc);
- }
- return &p->fr;
-}
-
-static struct ast_frame *aopen_read(struct ast_modem_pvt *p)
-{
- char result[256];
- short *b;
- struct ast_frame *f=NULL;
- int res;
- int x;
- if (p->ministate == STATE_COMMAND) {
- /* Read the first two bytes, first, in case it's a control message */
- fread(result, 1, 2, p->f);
- if (result[0] == CHAR_DLE) {
- return aopen_handle_escape(p, result[1]);
-
- } else {
- if ((result[0] == '\n') || (result[0] == '\r'))
- return aopen_handle_escape(p, 0);
- /* Read the rest of the line */
- fgets(result + 2, sizeof(result) - 2, p->f);
- ast_modem_trim(result);
- if (!strcasecmp(result, "VCON")) {
- /* If we're in immediate mode, reply now */
- if (p->mode == MODEM_MODE_IMMEDIATE)
- return aopen_handle_escape(p, 'X');
- } else
- if (!strcasecmp(result, "BUSY")) {
- /* Same as a busy signal */
- return aopen_handle_escape(p, 'b');
- } else
- if (!strcasecmp(result, "RING")) {
- return aopen_handle_escape(p, 'R');
- } else
- if (!strcasecmp(result, "NO DIALTONE")) {
- /* There's no dialtone, so the line isn't working */
- ast_log(LOG_WARNING, "Device '%s' lacking dialtone\n", p->dev);
- return NULL;
- }
- ast_log(LOG_DEBUG, "Modem said '%s'\n", result);
- return aopen_handle_escape(p, 0);
- }
- } else {
- /* We have to be more efficient in voice mode */
- b = (short *)(p->obuf + p->obuflen);
- while (p->obuflen/2 < 240) {
- /* Read ahead the full amount */
- res = fread(result, 1, 240 - p->obuflen/2, p->f);
- if (res < 1) {
- /* If there's nothing there, just continue on */
- if (errno == EAGAIN)
- return aopen_handle_escape(p, 0);
- ast_log(LOG_WARNING, "Read failed: %s\n", strerror(errno));
- }
- for (x=0;x<res;x++) {
- /* Process all the bytes that we've read */
- if (result[x] == CHAR_DLE) {
- /* We assume there is no more than one signal frame among our
- data. */
- if (f)
- ast_log(LOG_WARNING, "Warning: Dropped a signal frame\n");
- f = aopen_handle_escape(p, result[x+1]);
- /* If aopen_handle_escape says NULL, say it now, doesn't matter
- what else is there, the connection is dead. */
- if (!f)
- return NULL;
- } else {
- /* Generate a 16-bit signed linear value from our
- unsigned 8-bit value */
- *(b++) = (((short)result[x]) - 127) * 0xff;
- p->obuflen += 2;
- }
- }
- if (f)
- break;
- }
- /* If we have a control frame, return it now */
- if (f)
- return f;
- /* If we get here, we have a complete voice frame */
- p->fr.frametype = AST_FRAME_VOICE;
- p->fr.subclass = AST_FORMAT_SLINEAR;
- p->fr.samples = 240;
- p->fr.data = p->obuf;
- p->fr.datalen = p->obuflen;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- p->fr.offset = AST_FRIENDLY_OFFSET;
- p->fr.src = __FUNCTION__;
- if (option_debug)
- ast_log(LOG_DEBUG, "aopen_read(voice frame)\n");
- p->obuflen = 0;
- return &p->fr;
- }
- return NULL;
-}
-
-static int aopen_write(struct ast_modem_pvt *p, struct ast_frame *f)
-{
- if (option_debug)
- ast_log(LOG_DEBUG, "aopen_write()\n");
- return 0;
-}
-
-static char *aopen_identify(struct ast_modem_pvt *p)
-{
- char identity[256];
- char mfr[80];
- char mdl[80];
- char rev[80];
- ast_modem_send(p, "AT#MDL?", 0);
- ast_modem_read_response(p, 5);
- strncpy(mdl, p->response, sizeof(mdl)-1);
- ast_modem_trim(mdl);
- ast_modem_expect(p, "OK", 5);
- ast_modem_send(p, "AT#MFR?", 0);
- ast_modem_read_response(p, 5);
- strncpy(mfr, p->response, sizeof(mfr)-1);
- ast_modem_trim(mfr);
- ast_modem_expect(p, "OK", 5);
- ast_modem_send(p, "AT#REV?", 0);
- ast_modem_read_response(p, 5);
- strncpy(rev, p->response, sizeof(rev)-1);
- ast_modem_trim(rev);
- ast_modem_expect(p, "OK", 5);
- snprintf(identity, sizeof(identity), "%s Model %s Revision %s", mfr, mdl, rev);
- return strdup(identity);
-}
-
-static void aopen_incusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static void aopen_decusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static int aopen_answer(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "ATA", 0) ||
- ast_modem_expect(p, "VCON", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- return 0;
-}
-
-static int aopen_dialdigit(struct ast_modem_pvt *p, char digit)
-{
- char cmd[80];
- snprintf(cmd, sizeof(cmd), "AT#VTS=%c", digit);
- if (ast_modem_send(p, cmd, 0) ||
- ast_modem_expect(p, "VCON", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- return 0;
-}
-
-static int aopen_dial(struct ast_modem_pvt *p, char *stuff)
-{
- char cmd[80];
- snprintf(cmd, sizeof(cmd), "ATD%c %s", p->dialtype,stuff);
- if (ast_modem_send(p, cmd, 0)) {
- ast_log(LOG_WARNING, "Unable to dial\n");
- return -1;
- }
- return 0;
-}
-
-static int aopen_hangup(struct ast_modem_pvt *p)
-{
- if (aopen_break(p))
- return -1;
- /* Hangup by switching to data, then back to voice */
- if (ast_modem_send(p, "ATH", 0) ||
- ast_modem_expect(p, "OK", 8)) {
- ast_log(LOG_WARNING, "Unable to set to data mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#CLS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_modem_driver aopen_driver =
-{
- "AOpen",
- aopen_idents,
- AST_FORMAT_SLINEAR,
- 0, /* Not full duplex */
- aopen_incusecnt, /* incusecnt */
- aopen_decusecnt, /* decusecnt */
- aopen_identify, /* identify */
- aopen_init, /* init */
- aopen_setdev, /* setdev */
- aopen_read,
- aopen_write,
- aopen_dial, /* dial */
- aopen_answer, /* answer */
- aopen_hangup, /* hangup */
- aopen_startrec, /* start record */
- NULL, /* stop record */
- NULL, /* start playback */
- NULL, /* stop playback */
- NULL, /* set silence supression */
- aopen_dialdigit, /* dialdigit */
-};
-
-
-
-int usecount(void)
-{
- return usecnt;
-}
-
-int load_module(void)
-{
- return ast_register_modem_driver(&aopen_driver);
-}
-
-int unload_module(void)
-{
- return ast_unregister_modem_driver(&aopen_driver);
-}
-
-char *description()
-{
- return desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_modem_bestdata.c b/1.2-netsec/channels/chan_modem_bestdata.c
deleted file mode 100644
index e54a66a49..000000000
--- a/1.2-netsec/channels/chan_modem_bestdata.c
+++ /dev/null
@@ -1,613 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999, Mark Spencer and 2001 Jim Dixon
- *
- * Mark Spencer <markster@linux-support.net>
- * Jim Dixon <jim@lambdatel.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
- *
- * BestData 56SX-92 Voice Modem Driver (Conexant)
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/vmodem.h"
-#include "asterisk/module.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-
-#define STATE_COMMAND 0
-#define STATE_VOICE 1
-#define STATE_VOICEPLAY 2
-
-#define VRA "40" /* Number of 100ms of non-ring after a ring cadence after which we consider the lien to be answered */
-#define VRN "25" /* Number of 100ms of non-ring with no cadence after which we assume an answer */
-
-#define RINGT 7000
-
-static char *breakcmd = "\020!";
-
-static char *desc = "BestData (Conexant V.90 Chipset) VoiceModem Driver";
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-static char *bestdata_idents[] = {
- /* Identify BestData Modem */
- "ACF3_V1.010-V90_P21_FSH",
- NULL
-};
-
-static int bestdata_break(struct ast_modem_pvt *p);
-
-static int bestdata_startrec(struct ast_modem_pvt *p)
-{
- if (p->ministate != STATE_COMMAND) bestdata_break(p);
- if (ast_modem_send(p, "AT+VRX", 0) ||
- ast_modem_expect(p, "CONNECT", 5)) {
- ast_log(LOG_WARNING, "Unable to start recording\n");
- return -1;
- }
- p->ministate = STATE_VOICE;
- return 0;
-}
-
-static int bestdata_startplay(struct ast_modem_pvt *p)
-{
- if (p->ministate != STATE_COMMAND) bestdata_break(p);
- if (ast_modem_send(p, "AT+VTX", 0) ||
- ast_modem_expect(p, "CONNECT", 5)) {
- ast_log(LOG_WARNING, "Unable to start recording\n");
- return -1;
- }
- p->ministate = STATE_VOICEPLAY;
- return 0;
-}
-
-static int bestdata_break(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, breakcmd, 2)) {
- ast_log(LOG_WARNING, "Failed to break\n");
- return -1;
- }
- p->ministate = STATE_COMMAND;
- usleep(10000);
- /* Read any outstanding junk */
- while(!ast_modem_read_response(p, 1));
- if (ast_modem_send(p, "AT", 0)) {
- /* Modem might be stuck in some weird mode, try to get it out */
- ast_modem_send(p, "+++", 3);
- if (ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- if (ast_modem_send(p, "AT", 0)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- }
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- return 0;
-}
-
-static int bestdata_init(struct ast_modem_pvt *p)
-{
- if (option_debug)
- ast_log(LOG_DEBUG, "bestdata_init()\n");
- if (bestdata_break(p))
- return -1;
- /* Force into command mode */
- p->ministate = STATE_COMMAND;
- if (ast_modem_send(p, "AT+FCLASS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VSM=1,8000,0,0", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 8000 Hz sampling\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VLS=0", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to telco interface\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VRA=" VRA, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 'ringback goes away' timer\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VRN=" VRN, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 'ringback never came timer'\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VTD=63", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to tone detection\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VCID=1", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to enable Caller*ID\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_frame *bestdata_handle_escape(struct ast_modem_pvt *p, char esc)
-{
- char name[30]="",nmbr[30]="";
- time_t now;
-
- /* Handle escaped characters -- but sometimes we call it directly as
- a quick way to cause known responses */
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- p->fr.data = NULL;
- p->fr.datalen = 0;
- p->fr.samples = 0;
- p->fr.offset = 0;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- if (esc)
- ast_log(LOG_DEBUG, "Escaped character '%c'\n", esc);
-
- switch(esc) {
- case 'R': /* Pseudo ring */
- time(&now);
- if (now > (p->lastring + (RINGT / 1000)))
- { /* if stale, treat as new */
- p->gotclid = 0;
- }
- if (p->gotclid)
- {
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- }
- p->ringt = RINGT;
- time(&p->lastring);
- return &p->fr;
- case 'X': /* Caller-ID Spill */
- if (p->gotclid) return &p->fr;
- name[0] = nmbr[0] = 0;
- for(;;)
- {
- char res[1000]="";
-
- if (ast_modem_read_response(p, 5)) break;
- strncpy(res, p->response, sizeof(res)-1);
- ast_modem_trim(res);
- if (!strncmp(res,"\020.",2)) break;
- if (!strncmp(res,"NAME",4)) strncpy(name,res + 7, sizeof(name) - 1);
- if (!strncmp(res,"NMBR",4)) strncpy(nmbr,res + 7, sizeof(nmbr) - 1);
- }
- p->gotclid = 1;
- if ((!strcmp(name,"O")) || (!strcmp(name,"P"))) name[0] = 0;
- if ((!strcmp(nmbr,"O")) || (!strcmp(nmbr,"P"))) nmbr[0] = 0;
- if (name[0])
- strncpy(p->cid_name, name, sizeof(p->cid_name) - 1);
- if (nmbr[0])
- strncpy(p->cid_num, nmbr, sizeof(p->cid_num) - 1);
- if (p->owner) {
- p->owner->cid.cid_num = strdup(p->cid_num);
- p->owner->cid.cid_name = strdup(p->cid_name);
- }
- return &p->fr;
- case '@': /* response from "OK" in command mode */
- if (p->owner)
- ast_setstate(p->owner, AST_STATE_UP);
- if (bestdata_startrec(p)) return NULL;
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- return &p->fr;
- case 'b': /* Busy signal */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_BUSY;
- return &p->fr;
- case 'o': /* Overrun */
- ast_log(LOG_WARNING, "Overflow on modem, flushing buffers\n");
- if (ast_modem_send(p, "\0x10E", 2))
- ast_log(LOG_WARNING, "Unable to flush buffers\n");
- return &p->fr;
- case '0': /* All the DTMF characters */
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '*':
- case '#':
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- p->dtmfrx = esc; /* save this for when its done */
- return &p->fr;
- case '/': /* Start of DTMF tone shielding */
- p->dtmfrx = ' ';
- return &p->fr;
- case '~': /* DTMF transition to off */
- if (p->dtmfrx > ' ')
- {
- p->fr.frametype = AST_FRAME_DTMF;
- p->fr.subclass = p->dtmfrx;
- }
- p->dtmfrx = 0;
- return &p->fr;
- case 'u': /* Underrun */
- ast_log(LOG_WARNING, "Data underrun\n");
- /* Fall Through */
- case CHAR_ETX: /* End Transmission */
- case 'd': /* Dialtone */
- case 'c': /* Calling Tone */
- case 'e': /* European version */
- case 'a': /* Answer Tone */
- case 'f': /* Bell Answer Tone */
- case 'T': /* Timing mark */
- case 't': /* Handset off hook */
- case 'h': /* Handset hungup */
- case 0: /* Pseudo signal */
- /* Ignore */
- return &p->fr;
- default:
- ast_log(LOG_DEBUG, "Unknown Escaped character '%c' (%d)\n", esc, esc);
- }
- return &p->fr;
-}
-
-static struct ast_frame *bestdata_read(struct ast_modem_pvt *p)
-{
- char result[256];
- short *b;
- struct ast_frame *f=NULL;
- int res;
- int x;
-
- if (p->ministate == STATE_COMMAND) {
- /* Read the first two bytes, first, in case it's a control message */
- fread(result, 1, 2, p->f);
- if (result[0] == CHAR_DLE) {
- return bestdata_handle_escape(p, result[1]);
- } else {
- if (p->ringt) /* if ring timeout specified */
- {
- x = fileno(p->f);
- res = ast_waitfor_n_fd(&x, 1, &p->ringt, NULL);
- if (res < 0) {
- return NULL;
- }
- }
- if ((result[0] == '\n') || (result[0] == '\r'))
- return bestdata_handle_escape(p, 0);
- /* Read the rest of the line */
- fgets(result + 2, sizeof(result) - 2, p->f);
- ast_modem_trim(result);
- if (!strcasecmp(result, "OK")) {
- /* If we're in immediate mode, reply now */
- if (p->mode == MODEM_MODE_IMMEDIATE)
- return bestdata_handle_escape(p, '@');
- } else
- if (!strcasecmp(result, "BUSY")) {
- /* Same as a busy signal */
- return bestdata_handle_escape(p, 'b');
- } else
- if (!strcasecmp(result, "RING")) {
- return bestdata_handle_escape(p, 'R');
- } else
- if (!strcasecmp(result, "NO DIALTONE")) {
- /* There's no dialtone, so the line isn't working */
- ast_log(LOG_WARNING, "Device '%s' lacking dialtone\n", p->dev);
- return NULL;
- }
- ast_log(LOG_DEBUG, "Modem said '%s'\n", result);
- return bestdata_handle_escape(p, 0);
- }
- } else {
- /* if playing, start recording instead */
- if (p->ministate == STATE_VOICEPLAY)
- {
- if (bestdata_startrec(p)) return NULL;
- }
- /* We have to be more efficient in voice mode */
- b = (short *)(p->obuf + p->obuflen);
- while (p->obuflen/2 < 240) {
- /* Read ahead the full amount */
- res = fread(result, 1, 240 - p->obuflen/2, p->f);
- if (res < 1) {
- /* If there's nothing there, just continue on */
- if (errno == EAGAIN)
- return bestdata_handle_escape(p, 0);
- ast_log(LOG_WARNING, "Read failed: %s\n", strerror(errno));
- }
- for (x=0;x<res;x++) {
- /* Process all the bytes that we've read */
- if (result[x] == CHAR_DLE) {
- /* We assume there is no more than one signal frame among our
- data. */
- if (f) ast_log(LOG_WARNING, "Warning: Dropped a signal frame\n");
- /* if not a DLE in the data */
- if (result[++x] != CHAR_DLE)
- {
- /* If bestdata_handle_escape says NULL, say it now, doesn't matter
- what else is there, the connection is dead. */
- f = bestdata_handle_escape(p, result[x]);
- if (p->dtmfrx) continue;
- return(f);
- }
- }
- /* Generate a 16-bit signed linear value from our
- unsigned 8-bit value */
- *(b++) = (((short)result[x]) - 127) * 0xff;
- p->obuflen += 2;
- }
- if (f) break;
- }
- /* If we have a control frame, return it now */
- if (f) return f;
- /* If we get here, we have a complete voice frame */
- p->fr.frametype = AST_FRAME_VOICE;
- p->fr.subclass = AST_FORMAT_SLINEAR;
- p->fr.samples = 240;
- p->fr.data = p->obuf;
- p->fr.datalen = p->obuflen;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- p->fr.offset = AST_FRIENDLY_OFFSET;
- p->fr.src = __FUNCTION__;
- if (option_debug)
- ast_log(LOG_DEBUG, "bestdata_read(voice frame)\n");
- p->obuflen = 0;
- return &p->fr;
- }
- return NULL;
-}
-
-static int bestdata_write(struct ast_modem_pvt *p, struct ast_frame *f)
-{
-unsigned char c,buf[32768]; /* I hope we dont have frames larger then 16K */
-int i,j;
-short *sp;
-unsigned long u;
-#define DLE 16
-
- if (p->owner && (p->owner->_state == AST_STATE_UP) &&
- (p->ministate != STATE_VOICEPLAY) && bestdata_startplay(p)) return -1;
- sp = (short *) f->data;
- /* stick DLE's in ahead of anything else */
- for(i = 0,j = 0; i < f->datalen / 2; i++)
- {
- *sp *= 3;
- u = *sp++ + 32768;
- c = u >> 8;
- if (c == DLE) buf[j++] = DLE;
- buf[j++] = c;
- }
- do i = fwrite(buf,1,j,p->f);
- while ((i == -1) && (errno == EWOULDBLOCK));
- if (i != j)
- {
- ast_log(LOG_WARNING,"modem short write!!\n");
- return -1;
- }
- fflush(p->f);
- if (option_debug)
- ast_log(LOG_DEBUG, "bestdata_write()\n");
- return 0;
-}
-
-static char *bestdata_identify(struct ast_modem_pvt *p)
-{
- char identity[256];
- char mfr[80];
- char mdl[80];
- char rev[80];
- ast_modem_send(p, "AT+FMM", 0);
- ast_modem_read_response(p, 5);
- strncpy(mdl, p->response, sizeof(mdl)-1);
- ast_modem_trim(mdl);
- ast_modem_expect(p, "OK", 5);
- ast_modem_send(p, "AT+FMI", 0);
- ast_modem_read_response(p, 5);
- strncpy(mfr, p->response, sizeof(mfr)-1);
- ast_modem_trim(mfr);
- ast_modem_expect(p, "OK", 5);
- ast_modem_send(p, "AT+FMR", 0);
- ast_modem_read_response(p, 5);
- strncpy(rev, p->response, sizeof(rev)-1);
- ast_modem_trim(rev);
- ast_modem_expect(p, "OK", 5);
- snprintf(identity, sizeof(identity), "%s Model %s Revision %s", mfr, mdl, rev);
- return strdup(identity);
-}
-
-static void bestdata_incusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static void bestdata_decusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static int bestdata_answer(struct ast_modem_pvt *p)
-{
- p->ringt = 0;
- p->lastring = 0;
- if (ast_modem_send(p, "AT+VLS=1", 0) ||
- ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- return 0;
-}
-
-static int bestdata_dialdigit(struct ast_modem_pvt *p, char digit)
-{
- char cmd[80];
-
- if (p->ministate != STATE_COMMAND) bestdata_break(p);
- snprintf(cmd, sizeof(cmd), "AT+VTS=%c", digit);
- if (ast_modem_send(p, cmd, 0) ||
- ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- return 0;
-}
-
-static int bestdata_dial(struct ast_modem_pvt *p, char *stuff)
-{
- char cmd[800] = "",a[20]="";
- int i,j;
-
- if (p->ministate != STATE_COMMAND)
- {
- bestdata_break(p);
- strncpy(cmd, "AT+VTS=", sizeof(cmd) - 1);
- j = strlen(cmd);
- for(i = 0; stuff[i]; i++)
- {
- switch(stuff[i])
- {
- case '!' :
- a[0] = stuff[i];
- a[1] = 0;
- break;
- case ',':
- strncpy(a, "[,,100]", sizeof(a) - 1);
- break;
- default:
- snprintf(a, sizeof(a), "{%c,7}", stuff[i]);
- }
- if (stuff[i + 1]) strncat(a, ",", sizeof(a) - strlen(a) - 1);
- strncpy(cmd + j, a, sizeof(cmd) - j - 1);
- j += strlen(a);
- }
- }
- else
- {
- snprintf(cmd, sizeof(cmd), "ATD%c %s", p->dialtype,stuff);
- }
- if (ast_modem_send(p, cmd, 0)) {
- ast_log(LOG_WARNING, "Unable to dial\n");
- return -1;
- }
- return 0;
-}
-
-static int bestdata_hangup(struct ast_modem_pvt *p)
-{
- if (bestdata_break(p))
- return -1;
- /* Hangup by switching to data, then back to voice */
- if (ast_modem_send(p, "ATH", 0) ||
- ast_modem_expect(p, "OK", 8)) {
- ast_log(LOG_WARNING, "Unable to set to data mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+FCLASS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- p->gotclid = 0;
- p->ringt = 0;
- p->lastring = 0;
- p->dtmfrx = 0;
- return 0;
-}
-
-static struct ast_modem_driver bestdata_driver =
-{
- "BestData",
- bestdata_idents,
- AST_FORMAT_SLINEAR,
- 0, /* Not full duplex */
- bestdata_incusecnt, /* incusecnt */
- bestdata_decusecnt, /* decusecnt */
- bestdata_identify, /* identify */
- bestdata_init, /* init */
- NULL, /* setdev */
- bestdata_read,
- bestdata_write,
- bestdata_dial, /* dial */
- bestdata_answer, /* answer */
- bestdata_hangup, /* hangup */
- bestdata_startrec, /* start record */
- NULL, /* stop record */
- bestdata_startplay, /* start playback */
- NULL, /* stop playback */
- NULL, /* set silence supression */
- bestdata_dialdigit, /* dialdigit */
-};
-
-
-
-int usecount(void)
-{
- return usecnt;
-}
-
-int load_module(void)
-{
- return ast_register_modem_driver(&bestdata_driver);
-}
-
-int unload_module(void)
-{
- return ast_unregister_modem_driver(&bestdata_driver);
-}
-
-char *description()
-{
- return desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_modem_i4l.c b/1.2-netsec/channels/chan_modem_i4l.c
deleted file mode 100644
index 69aa00454..000000000
--- a/1.2-netsec/channels/chan_modem_i4l.c
+++ /dev/null
@@ -1,743 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief ISDN4Linux TTY Driver
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/vmodem.h"
-#include "asterisk/module.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/dsp.h"
-#include "asterisk/callerid.h"
-#include "asterisk/ulaw.h"
-#include "asterisk/pbx.h"
-#include "asterisk/utils.h"
-
-#define STATE_COMMAND 0
-#define STATE_VOICE 1
-
-static char *breakcmd = "\0x10\0x14\0x10\0x3";
-
-static char *desc = "ISDN4Linux Emulated Modem Driver";
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-static char *i4l_idents[] = {
- /* Identify ISDN4Linux Driver */
- "Linux ISDN",
- NULL
-};
-
-static int i4l_setdev(struct ast_modem_pvt *p, int dev)
-{
- char cmd[80];
- if ((dev != MODEM_DEV_TELCO) && (dev != MODEM_DEV_TELCO_SPK)) {
- ast_log(LOG_WARNING, "ISDN4Linux only supports telco device, not %d.\n", dev);
- return -1;
- } else /* Convert DEV to our understanding of it */
- dev = 2;
- if (ast_modem_send(p, "AT+VLS?", 0)) {
- ast_log(LOG_WARNING, "Unable to select current mode %d\n", dev);
- return -1;
- }
- if (ast_modem_read_response(p, 5)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- ast_modem_trim(p->response);
- strncpy(cmd, p->response, sizeof(cmd)-1);
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- if (dev == atoi(cmd)) {
- /* We're already in the right mode, don't bother changing for fear of
- hanging up */
- return 0;
- }
- snprintf(cmd, sizeof(cmd), "AT+VLS=%d", dev);
- if (ast_modem_send(p, cmd, 0)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- if (ast_modem_read_response(p, 5)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- ast_modem_trim(p->response);
- if (strcasecmp(p->response, "VCON") && strcasecmp(p->response, "OK")) {
- ast_log(LOG_WARNING, "Unexpected reply: %s\n", p->response);
- return -1;
- }
- return 0;
-}
-
-static int i4l_startrec(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "AT+VRX+VTX", 0) ||
- ast_modem_expect(p, "CONNECT", 5)) {
- ast_log(LOG_WARNING, "Unable to start recording\n");
- return -1;
- }
- p->ministate = STATE_VOICE;
-
- /* let ast dsp detect dtmf */
- if (p->dtmfmode & MODEM_DTMF_AST) {
- if (p->dsp) {
- ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev);
- } else {
- p->dsp = ast_dsp_new();
- if (p->dsp) {
- ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev);
- ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT|DSP_FEATURE_FAX_DETECT);
- ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0);
- }
- }
- }
-
- return 0;
-}
-
-static int i4l_break(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, breakcmd, 2)) {
- ast_log(LOG_WARNING, "Failed to break\n");
- return -1;
- }
- if (ast_modem_send(p, "\r\n", 2)) {
- ast_log(LOG_WARNING, "Failed to send enter?\n");
- return -1;
- }
-#if 0
- /* Read any outstanding junk */
- while(!ast_modem_read_response(p, 1));
-#endif
- if (ast_modem_send(p, "AT", 0)) {
- /* Modem might be stuck in some weird mode, try to get it out */
- ast_modem_send(p, "+++", 3);
- if (ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- if (ast_modem_send(p, "AT", 0)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- }
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- return 0;
-}
-
-static int i4l_init(struct ast_modem_pvt *p)
-{
- char cmd[256];
- if (option_debug)
- ast_log(LOG_DEBUG, "i4l_init()\n");
- if (i4l_break(p))
- return -1;
- /* Force into command mode */
- p->ministate = STATE_COMMAND;
- if (ast_modem_send(p, "AT+FCLASS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- if (!ast_strlen_zero(p->msn)) {
- snprintf(cmd, sizeof(cmd), "AT&E%s", p->msn);
- if (ast_modem_send(p, cmd, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set MSN to %s\n", p->msn);
- return -1;
- }
- }
- if (!ast_strlen_zero(p->incomingmsn)) {
- char *q;
- snprintf(cmd, sizeof(cmd), "AT&L%s", p->incomingmsn);
- /* translate , into ; since that is the seperator I4L uses, but can't be directly */
- /* put in the config file because it will interpret the rest of the line as comment. */
- q = cmd+4;
- while (*q) {
- if (*q == ',') *q = ';';
- ++q;
- }
- if (ast_modem_send(p, cmd, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set Listen to %s\n", p->msn);
- return -1;
- }
- }
- if (ast_modem_send(p, "AT&D2", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to DTR disconnect mode\n");
- return -1;
- }
- if (ast_modem_send(p, "ATS18=1", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to audio only mode\n");
- return -1;
- }
- if (ast_modem_send(p, "ATS13.6=1", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to RUNG indication\n");
- return -1;
- }
- if (ast_modem_send(p, "ATS14=4", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to transparent mode\n");
- return -1;
- }
- if (ast_modem_send(p, "ATS23=9", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to transparent/ringing mode\n");
- return -1;
- }
-
- if (ast_modem_send(p, "AT+VSM=6", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to muLAW mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VLS=2", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to phone line interface\n");
- return -1;
- }
- p->escape = 0;
- return 0;
-}
-
-static struct ast_frame *i4l_handle_escape(struct ast_modem_pvt *p, char esc)
-{
- /* Handle escaped characters -- but sometimes we call it directly as
- a quick way to cause known responses */
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- p->fr.data = NULL;
- p->fr.datalen = 0;
- p->fr.samples = 0;
- p->fr.offset = 0;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- if (esc && option_debug)
- ast_log(LOG_DEBUG, "Escaped character '%c'\n", esc);
-
- switch(esc) {
- case 'R': /* Pseudo ring */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- return &p->fr;
- case 'I': /* Pseudo ringing */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RINGING;
- return &p->fr;
- case 'X': /* Pseudo connect */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_ANSWER;
- if (p->owner)
- ast_setstate(p->owner, AST_STATE_UP);
- if (i4l_startrec(p))
- return NULL;
- return &p->fr;
- case 'b': /* Busy signal */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_BUSY;
- return &p->fr;
- case 'o': /* Overrun */
- ast_log(LOG_WARNING, "Overflow on modem, flushing buffers\n");
- if (ast_modem_send(p, "\0x10E", 2))
- ast_log(LOG_WARNING, "Unable to flush buffers\n");
- return &p->fr;
- case CHAR_ETX: /* End Transmission */
- return NULL;
- case 'u': /* Underrun */
- ast_log(LOG_WARNING, "Data underrun\n");
- /* Fall Through */
- case 'd': /* Dialtone */
- case 'c': /* Calling Tone */
- case 'e': /* European version */
- case 'a': /* Answer Tone */
- case 'f': /* Bell Answer Tone */
- case 'T': /* Timing mark */
- case 't': /* Handset off hook */
- case 'h': /* Handset hungup */
- /* Ignore */
- if (option_debug)
- ast_log(LOG_DEBUG, "Ignoring Escaped character '%c' (%d)\n", esc, esc);
- return &p->fr;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '*':
- case '#':
- ast_log(LOG_DEBUG, "Detected outband DTMF digit: '%c' (%d)\n", esc, esc);
- p->fr.frametype=AST_FRAME_DTMF;
- p->fr.subclass=esc;
- return &p->fr;
- case 0: /* Pseudo signal */
- return &p->fr;
- default:
- ast_log(LOG_DEBUG, "Unknown Escaped character '%c' (%d)\n", esc, esc);
- }
- return &p->fr;
-}
-
-static struct ast_frame *i4l_read(struct ast_modem_pvt *p)
-{
- unsigned char result[256];
- short *b;
- struct ast_frame *f=NULL;
- int res;
- int x;
- if (p->ministate == STATE_COMMAND) {
- /* Read the first two bytes, first, in case it's a control message */
- res = read(p->fd, result, 2);
- if (res < 2) {
- /* short read, means there was a hangup? */
- /* (or is this also possible without hangup?) */
- /* Anyway, reading from unitialized buffers is a bad idea anytime. */
- if (errno == EAGAIN)
- return i4l_handle_escape(p, 0);
- return NULL;
- }
- if (result[0] == CHAR_DLE) {
- return i4l_handle_escape(p, result[1]);
-
- } else {
- if ((result[0] == '\n') || (result[0] == '\r'))
- return i4l_handle_escape(p, 0);
- /* Read the rest of the line */
- fgets(result + 2, sizeof(result) - 2, p->f);
- ast_modem_trim(result);
- if (!strcasecmp(result, "VCON")) {
- /* If we're in immediate mode, reply now */
-/* if (p->mode == MODEM_MODE_IMMEDIATE) */
- return i4l_handle_escape(p, 'X');
- } else
- if (!strcasecmp(result, "BUSY")) {
- /* Same as a busy signal */
- return i4l_handle_escape(p, 'b');
- } else
- if (!strncasecmp(result, "CALLER NUMBER: ", 15 )) {
- strncpy(p->cid_num, result + 15, sizeof(p->cid_num)-1);
- return i4l_handle_escape(p, 0);
- } else
- if (!strcasecmp(result, "RINGING")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "%s is ringing...\n", p->dev);
- return i4l_handle_escape(p, 'I');
- } else
- if (!strncasecmp(result, "RUNG", 4)) {
- /* PM2002: the line was hung up before we picked it up, bye bye */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "%s was hung up on before we answered\n", p->dev);
- return NULL;
- } else
- if (!strncasecmp(result, "RING", 4)) {
- if (result[4]=='/')
- strncpy(p->dnid, result + 5, sizeof(p->dnid)-1);
- return i4l_handle_escape(p, 'R');
- } else
- if (!strcasecmp(result, "NO CARRIER")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "%s hung up on\n", p->dev);
- return NULL;
- } else
- if (!strcasecmp(result, "NO DIALTONE")) {
- /* There's no dialtone, so the line isn't working */
- ast_log(LOG_WARNING, "Device '%s' lacking dialtone\n", p->dev);
- return NULL;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Modem said '%s'\n", result);
- return i4l_handle_escape(p, 0);
- }
- } else {
- /* We have to be more efficient in voice mode */
- b = (short *)(p->obuf + p->obuflen);
- while (p->obuflen/2 < 240) {
- /* Read ahead the full amount */
- res = read(p->fd, result, 240 - p->obuflen/2);
- if (res < 1) {
- /* If there's nothing there, just continue on */
- if (errno == EAGAIN)
- return i4l_handle_escape(p, 0);
- ast_log(LOG_WARNING, "Read failed: %s\n", strerror(errno));
- return NULL;
- }
-
- for (x=0;x<res;x++) {
- /* Process all the bytes that we've read */
- switch(result[x]) {
- case CHAR_DLE:
-#if 0
- ast_log(LOG_DEBUG, "Ooh, an escape at %d...\n", x);
-#endif
- if (!p->escape) {
- /* Note that next value is
- an escape, and continue. */
- p->escape++;
- break;
- } else {
- /* Send as is -- fallthrough */
- p->escape = 0;
- }
- default:
- if (p->escape) {
- ast_log(LOG_DEBUG, "Value of escape is %c (%d)...\n", result[x] < 32 ? '^' : result[x], result[x]);
- p->escape = 0;
- if (f)
- ast_log(LOG_WARNING, "Warning: Dropped a signal frame\n");
- f = i4l_handle_escape(p, result[x]);
- /* If i4l_handle_escape says NULL, say it now, doesn't matter
- what else is there, the connection is dead. */
- if (!f)
- return NULL;
- } else {
- *(b++) = AST_MULAW((int)result[x]);
- p->obuflen += 2;
- }
- }
- }
- if (f)
- break;
- }
- if (f) {
- if( ! (!(p->dtmfmode & MODEM_DTMF_I4L) && f->frametype == AST_FRAME_DTMF))
- return f;
- }
-
- /* If we get here, we have a complete voice frame */
- p->fr.frametype = AST_FRAME_VOICE;
- p->fr.subclass = AST_FORMAT_SLINEAR;
- p->fr.samples = 240;
- p->fr.data = p->obuf;
- p->fr.datalen = p->obuflen;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- p->fr.offset = AST_FRIENDLY_OFFSET;
- p->fr.src = __FUNCTION__;
- p->obuflen = 0;
-
- /* process with dsp */
- if (p->dsp) {
- f = ast_dsp_process(p->owner, p->dsp, &p->fr);
- if (f && (f->frametype == AST_FRAME_DTMF)) {
- ast_log(LOG_DEBUG, "Detected inband DTMF digit: %c on %s\n", f->subclass, p->dev);
- if (f->subclass == 'f') {
- /* Fax tone -- Handle and return NULL */
- struct ast_channel *ast = p->owner;
- if (!p->faxhandled) {
- p->faxhandled++;
- if (strcmp(ast->exten, "fax")) {
- const char *target_context = ast_strlen_zero(ast->macrocontext) ? ast->context : ast->macrocontext;
-
- if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", ast->name);
- /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
- pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
- if (ast_async_goto(ast, target_context, "fax", 1))
- ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
- } else
- ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
- } else
- ast_log(LOG_DEBUG, "Already in a fax extension, not redirecting\n");
- } else
- ast_log(LOG_DEBUG, "Fax already handled\n");
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- f = &p->fr;
- }
- return f;
- }
- }
-
- return &p->fr;
- }
- return NULL;
-}
-
-static int i4l_write(struct ast_modem_pvt *p, struct ast_frame *f)
-{
-#define MAX_WRITE_SIZE 2048
- unsigned char result[MAX_WRITE_SIZE << 1];
- unsigned char b;
- int bpos=0, x;
- int res;
- if (f->datalen > MAX_WRITE_SIZE) {
- ast_log(LOG_WARNING, "Discarding too big frame of size %d\n", f->datalen);
- return -1;
- }
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Don't know how to handle %d type frames\n", f->frametype);
- return -1;
- }
- if (f->subclass != AST_FORMAT_SLINEAR) {
- ast_log(LOG_WARNING, "Don't know how to handle anything but signed linear frames\n");
- return -1;
- }
- for (x=0;x<f->datalen/2;x++) {
- b = AST_LIN2MU(((short *)f->data)[x]);
- result[bpos++] = b;
- if (b == CHAR_DLE)
- result[bpos++]=b;
- }
-#if 0
- res = fwrite(result, bpos, 1, p->f);
- res *= bpos;
-#else
- res = write(p->fd, result, bpos);
-#endif
- if (res < 1) {
- if (errno != EAGAIN) {
- ast_log(LOG_WARNING, "Failed to write buffer\n");
- return -1;
- }
- }
-#if 0
- printf("Result of write is %d\n", res);
-#endif
- return 0;
-}
-
-static char *i4l_identify(struct ast_modem_pvt *p)
-{
- return strdup("Linux ISDN");
-}
-
-static void i4l_incusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static void i4l_decusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static int i4l_answer(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "ATA\r", 4) ||
- ast_modem_expect(p, "VCON", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
-#if 1
- if (ast_modem_send(p, "AT+VDD=0,8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to phone line interface\n");
- return -1;
- }
-#endif
- if (ast_modem_send(p, "AT+VTX+VRX", 0) ||
- ast_modem_expect(p, "CONNECT", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- p->ministate = STATE_VOICE;
-
- /* let ast dsp detect dtmf */
- if (p->dtmfmode & MODEM_DTMF_AST) {
- if (p->dsp) {
- ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev);
- } else {
- p->dsp = ast_dsp_new();
- if (p->dsp) {
- ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev);
- ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT|DSP_FEATURE_FAX_DETECT);
- ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0);
- }
- }
- }
-
- return 0;
-}
-
-static int i4l_dialdigit(struct ast_modem_pvt *p, char digit)
-{
- char c[2];
- if (p->ministate == STATE_VOICE) {
- if (p->dtmfmodegen & MODEM_DTMF_I4L) {
- c[0] = CHAR_DLE;
- c[1] = digit;
- write(p->fd, c, 2);
- ast_log(LOG_DEBUG, "Send ISDN out-of-band DTMF %c\n",digit);
- }
- if(p->dtmfmodegen & MODEM_DTMF_AST) {
- ast_log(LOG_DEBUG, "Generating inband DTMF\n");
- return -1;
- }
- } else
- ast_log(LOG_DEBUG, "Asked to send digit but call not up on %s\n", p->dev);
- return 0;
-}
-
-static int i4l_dial(struct ast_modem_pvt *p, char *stuff)
-{
- char cmd[80];
- char tmpmsn[255];
- struct ast_channel *c = p->owner;
-
- /* Find callerid number first, to set the correct A number */
- if (c && c->cid.cid_num && !(c->cid.cid_pres & 0x20)) {
- snprintf(tmpmsn, sizeof(tmpmsn), ",%s,", c->cid.cid_num);
- if(!ast_strlen_zero(p->outgoingmsn) && strstr(p->outgoingmsn,tmpmsn) != NULL) {
- /* Tell ISDN4Linux to use this as A number */
- snprintf(cmd, sizeof(cmd), "AT&E%s\n", c->cid.cid_num);
- if (ast_modem_send(p, cmd, strlen(cmd))) {
- ast_log(LOG_WARNING, "Unable to set A number to %s\n", c->cid.cid_num);
- }
-
- } else {
- ast_log(LOG_WARNING, "Outgoing MSN %s not allowed (see outgoingmsn=%s in modem.conf)\n",c->cid.cid_num,p->outgoingmsn);
- }
- }
-
- snprintf(cmd, sizeof(cmd), "ATD%c %s\n", p->dialtype,stuff);
- if (ast_modem_send(p, cmd, strlen(cmd))) {
- ast_log(LOG_WARNING, "Unable to dial\n");
- return -1;
- }
- return 0;
-}
-
-static int i4l_hangup(struct ast_modem_pvt *p)
-{
- char dummy[50];
- int dtr = TIOCM_DTR;
-
- /* free the memory used by the DSP */
- if (p->dsp) {
- ast_dsp_free(p->dsp);
- p->dsp = NULL;
- }
-
- /* down DTR to hangup modem */
- ioctl(p->fd, TIOCMBIC, &dtr);
- /* Read anything outstanding */
- while(read(p->fd, dummy, sizeof(dummy)) > 0);
-
- /* rise DTR to re-enable line */
- ioctl(p->fd, TIOCMBIS, &dtr);
-
- /* Read anything outstanding */
- while(read(p->fd, dummy, sizeof(dummy)) > 0);
-
- /* basically we're done, just to be sure */
- write(p->fd, "\n\n", 2);
- read(p->fd, dummy, sizeof(dummy));
- if (ast_modem_send(p, "ATH", 0)) {
- ast_log(LOG_WARNING, "Unable to hang up\n");
- return -1;
- }
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Final 'OK' not received\n");
- return -1;
- }
-
- return 0;
-}
-
-static struct ast_modem_driver i4l_driver =
-{
- "i4l",
- i4l_idents,
- AST_FORMAT_SLINEAR,
- 0, /* Not full duplex */
- i4l_incusecnt, /* incusecnt */
- i4l_decusecnt, /* decusecnt */
- i4l_identify, /* identify */
- i4l_init, /* init */
- i4l_setdev, /* setdev */
- i4l_read,
- i4l_write,
- i4l_dial, /* dial */
- i4l_answer, /* answer */
- i4l_hangup, /* hangup */
- i4l_startrec, /* start record */
- NULL, /* stop record */
- NULL, /* start playback */
- NULL, /* stop playback */
- NULL, /* set silence supression */
- i4l_dialdigit, /* dialdigit */
-};
-
-
-
-int usecount(void)
-{
- return usecnt;
-}
-
-int load_module(void)
-{
- return ast_register_modem_driver(&i4l_driver);
-}
-
-int unload_module(void)
-{
- return ast_unregister_modem_driver(&i4l_driver);
-}
-
-char *description()
-{
- return desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_nbs.c b/1.2-netsec/channels/chan_nbs.c
deleted file mode 100644
index 380cb3b98..000000000
--- a/1.2-netsec/channels/chan_nbs.c
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Network broadcast sound support channel driver
- *
- * \author Mark Spencer <markster@digium.com>
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <arpa/inet.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <nbs.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-
-static const char desc[] = "Network Broadcast Sound Support";
-static const char type[] = "NBS";
-static const char tdesc[] = "Network Broadcast Sound Driver";
-
-static int usecnt =0;
-
-/* Only linear is allowed */
-static int prefformat = AST_FORMAT_SLINEAR;
-
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-static char context[AST_MAX_EXTENSION] = "default";
-
-/* NBS creates private structures on demand */
-
-struct nbs_pvt {
- NBS *nbs;
- struct ast_channel *owner; /* Channel we belong to, possibly NULL */
- char app[16]; /* Our app */
- char stream[80]; /* Our stream */
- struct ast_frame fr; /* "null" frame */
-};
-
-static struct ast_channel *nbs_request(const char *type, int format, void *data, int *cause);
-static int nbs_call(struct ast_channel *ast, char *dest, int timeout);
-static int nbs_hangup(struct ast_channel *ast);
-static struct ast_frame *nbs_xread(struct ast_channel *ast);
-static int nbs_xwrite(struct ast_channel *ast, struct ast_frame *frame);
-
-static const struct ast_channel_tech nbs_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_SLINEAR,
- .requester = nbs_request,
- .call = nbs_call,
- .hangup = nbs_hangup,
- .read = nbs_xread,
- .write = nbs_xwrite,
-};
-
-static int nbs_call(struct ast_channel *ast, char *dest, int timeout)
-{
- struct nbs_pvt *p;
-
- p = ast->tech_pvt;
-
- if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "nbs_call called on %s, neither down nor reserved\n", ast->name);
- return -1;
- }
- /* When we call, it just works, really, there's no destination... Just
- ring the phone and wait for someone to answer */
- if (option_debug)
- ast_log(LOG_DEBUG, "Calling %s on %s\n", dest, ast->name);
-
- /* If we can't connect, return congestion */
- if (nbs_connect(p->nbs)) {
- ast_log(LOG_WARNING, "NBS Connection failed on %s\n", ast->name);
- ast_queue_control(ast, AST_CONTROL_CONGESTION);
- } else {
- ast_setstate(ast, AST_STATE_RINGING);
- ast_queue_control(ast, AST_CONTROL_ANSWER);
- }
-
- return 0;
-}
-
-static void nbs_destroy(struct nbs_pvt *p)
-{
- if (p->nbs)
- nbs_delstream(p->nbs);
- free(p);
-}
-
-static struct nbs_pvt *nbs_alloc(void *data)
-{
- struct nbs_pvt *p;
- int flags = 0;
- char stream[256] = "";
- char *opts;
- strncpy(stream, data, sizeof(stream) - 1);
- if ((opts = strchr(stream, ':'))) {
- *opts = '\0';
- opts++;
- } else
- opts = "";
- p = malloc(sizeof(struct nbs_pvt));
- if (p) {
- memset(p, 0, sizeof(struct nbs_pvt));
- if (!ast_strlen_zero(opts)) {
- if (strchr(opts, 'm'))
- flags |= NBS_FLAG_MUTE;
- if (strchr(opts, 'o'))
- flags |= NBS_FLAG_OVERSPEAK;
- if (strchr(opts, 'e'))
- flags |= NBS_FLAG_EMERGENCY;
- if (strchr(opts, 'O'))
- flags |= NBS_FLAG_OVERRIDE;
- } else
- flags = NBS_FLAG_OVERSPEAK;
-
- strncpy(p->stream, stream, sizeof(p->stream) - 1);
- p->nbs = nbs_newstream("asterisk", stream, flags);
- if (!p->nbs) {
- ast_log(LOG_WARNING, "Unable to allocate new NBS stream '%s' with flags %d\n", stream, flags);
- free(p);
- p = NULL;
- } else {
- /* Set for 8000 hz mono, 640 samples */
- nbs_setbitrate(p->nbs, 8000);
- nbs_setchannels(p->nbs, 1);
- nbs_setblocksize(p->nbs, 640);
- nbs_setblocking(p->nbs, 0);
- }
- }
- return p;
-}
-
-static int nbs_hangup(struct ast_channel *ast)
-{
- struct nbs_pvt *p;
- p = ast->tech_pvt;
- if (option_debug)
- ast_log(LOG_DEBUG, "nbs_hangup(%s)\n", ast->name);
- if (!ast->tech_pvt) {
- ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
- return 0;
- }
- nbs_destroy(p);
- ast->tech_pvt = NULL;
- ast_setstate(ast, AST_STATE_DOWN);
- return 0;
-}
-
-static struct ast_frame *nbs_xread(struct ast_channel *ast)
-{
- struct nbs_pvt *p = ast->tech_pvt;
-
-
- /* Some nice norms */
- p->fr.datalen = 0;
- p->fr.samples = 0;
- p->fr.data = NULL;
- p->fr.src = type;
- p->fr.offset = 0;
- p->fr.mallocd=0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
-
- ast_log(LOG_DEBUG, "Returning null frame on %s\n", ast->name);
-
- return &p->fr;
-}
-
-static int nbs_xwrite(struct ast_channel *ast, struct ast_frame *frame)
-{
- struct nbs_pvt *p = ast->tech_pvt;
- /* Write a frame of (presumably voice) data */
- if (frame->frametype != AST_FRAME_VOICE) {
- if (frame->frametype != AST_FRAME_IMAGE)
- ast_log(LOG_WARNING, "Don't know what to do with frame type '%d'\n", frame->frametype);
- return 0;
- }
- if (!(frame->subclass &
- (AST_FORMAT_SLINEAR))) {
- ast_log(LOG_WARNING, "Cannot handle frames in %d format\n", frame->subclass);
- return 0;
- }
- if (ast->_state != AST_STATE_UP) {
- /* Don't try tos end audio on-hook */
- return 0;
- }
- if (nbs_write(p->nbs, frame->data, frame->datalen / 2) < 0)
- return -1;
- return 0;
-}
-
-static struct ast_channel *nbs_new(struct nbs_pvt *i, int state)
-{
- struct ast_channel *tmp;
- tmp = ast_channel_alloc(1);
- if (tmp) {
- tmp->tech = &nbs_tech;
- snprintf(tmp->name, sizeof(tmp->name), "NBS/%s", i->stream);
- tmp->type = type;
- tmp->fds[0] = nbs_fd(i->nbs);
- tmp->nativeformats = prefformat;
- tmp->rawreadformat = prefformat;
- tmp->rawwriteformat = prefformat;
- tmp->writeformat = prefformat;
- tmp->readformat = prefformat;
- ast_setstate(tmp, state);
- if (state == AST_STATE_RING)
- tmp->rings = 1;
- tmp->tech_pvt = i;
- strncpy(tmp->context, context, sizeof(tmp->context)-1);
- strncpy(tmp->exten, "s", sizeof(tmp->exten) - 1);
- tmp->language[0] = '\0';
- i->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- }
- }
- } else
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- return tmp;
-}
-
-
-static struct ast_channel *nbs_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- struct nbs_pvt *p;
- struct ast_channel *tmp = NULL;
-
- oldformat = format;
- format &= (AST_FORMAT_SLINEAR);
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", oldformat);
- return NULL;
- }
- p = nbs_alloc(data);
- if (p) {
- tmp = nbs_new(p, AST_STATE_DOWN);
- if (!tmp)
- nbs_destroy(p);
- }
- return tmp;
-}
-
-static int __unload_module(void)
-{
- /* First, take us out of the channel loop */
- ast_channel_unregister(&nbs_tech);
- return 0;
-}
-
-int unload_module(void)
-{
- return __unload_module();
-}
-
-int load_module()
-{
- /* Make sure we can register our channel type */
- if (ast_channel_register(&nbs_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- __unload_module();
- return -1;
- }
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_oss.c b/1.2-netsec/channels/chan_oss.c
deleted file mode 100644
index 70b70333e..000000000
--- a/1.2-netsec/channels/chan_oss.c
+++ /dev/null
@@ -1,1438 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * FreeBSD changes and multiple device support by Luigi Rizzo, 2005.05.25
- * note-this code best seen with ts=8 (8-spaces tabs) in the editor
- *
- * 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 Channel driver for OSS sound cards
- *
- * \par See also
- * \arg \ref Config_oss
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <ctype.h> /* for isalnum */
-#include <string.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#include <stdlib.h>
-#include <errno.h>
-
-
-#ifdef __linux
-#include <linux/soundcard.h>
-#elif defined(__FreeBSD__)
-#include <sys/soundcard.h>
-#else
-#include <soundcard.h>
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/pbx.h"
-#include "asterisk/config.h"
-
-#include "asterisk/cli.h"
-#include "asterisk/utils.h"
-#include "asterisk/causes.h"
-#include "asterisk/endian.h"
-
-/* ringtones we use */
-#include "busy.h"
-#include "ringtone.h"
-#include "ring10.h"
-#include "answer.h"
-
-/*
- * Basic mode of operation:
- *
- * we have one keyboard (which receives commands from the keyboard)
- * and multiple headset's connected to audio cards.
- * Cards/Headsets are named as the sections of oss.conf.
- * The section called [general] contains the default parameters.
- *
- * At any time, the keyboard is attached to one card, and you
- * can switch among them using the command 'console foo'
- * where 'foo' is the name of the card you want.
- *
- * oss.conf parameters are
-
-[general]
-; general config options, default values are shown
-; all but debug can go also in the device-specific sections.
-; debug=0x0 ; misc debug flags, default is 0
-
-[card1]
-; autoanswer = no ; no autoanswer on call
-; autohangup = yes ; hangup when other party closes
-; extension=s ; default extension to call
-; context=default ; default context
-; language="" ; default language
-; overridecontext=yes ; the whole dial string is considered an extension.
- ; if no, the last @ will start the context
-
-; device=/dev/dsp ; device to open
-; mixer="-f /dev/mixer0 pcm 80 ; mixer command to run on start
-; queuesize=10 ; frames in device driver
-; frags=8 ; argument to SETFRAGMENT
-
-.. and so on for the other cards.
-
- */
-
-/*
- * Helper macros to parse config arguments. They will go in a common
- * header file if their usage is globally accepted. In the meantime,
- * we define them here. Typical usage is as below.
- * Remember to open a block right before M_START (as it declares
- * some variables) and use the M_* macros WITHOUT A SEMICOLON:
- *
- * {
- * M_START(v->name, v->value)
- *
- * M_BOOL("dothis", x->flag1)
- * M_STR("name", x->somestring)
- * M_F("bar", some_c_code)
- * M_END(some_final_statement)
- * ... other code in the block
- * }
- *
- * XXX NOTE these macros should NOT be replicated in other parts of asterisk.
- * Likely we will come up with a better way of doing config file parsing.
- */
-#define M_START(var, val) \
- char *__s = var; char *__val = val;
-#define M_END(x) x;
-#define M_F(tag, f) if (!strcasecmp((__s), tag)) { f; } else
-#define M_BOOL(tag, dst) M_F(tag, (dst) = ast_true(__val) )
-#define M_UINT(tag, dst) M_F(tag, (dst) = strtoul(__val, NULL, 0) )
-#define M_STR(tag, dst) M_F(tag, ast_copy_string(dst, __val, sizeof(dst)))
-
-/*
- * The following parameters are used in the driver:
- *
- * FRAME_SIZE the size of an audio frame, in samples.
- * 160 is used almost universally, so you should not change it.
- *
- * FRAGS the argument for the SETFRAGMENT ioctl.
- * Overridden by the 'frags' parameter in oss.conf
- *
- * Bits 0-7 are the base-2 log of the device's block size,
- * bits 16-31 are the number of blocks in the driver's queue.
- * There are a lot of differences in the way this parameter
- * is supported by different drivers, so you may need to
- * experiment a bit with the value.
- * A good default for linux is 30 blocks of 64 bytes, which
- * results in 6 frames of 320 bytes (160 samples).
- * FreeBSD works decently with blocks of 256 or 512 bytes,
- * leaving the number unspecified.
- * Note that this only refers to the device buffer size,
- * this module will then try to keep the lenght of audio
- * buffered within small constraints.
- *
- * QUEUE_SIZE The max number of blocks actually allowed in the device
- * driver's buffer, irrespective of the available number.
- * Overridden by the 'queuesize' parameter in oss.conf
- *
- * Should be >=2, and at most as large as the hw queue above
- * (otherwise it will never be full).
- */
-
-#define FRAME_SIZE 160
-#define QUEUE_SIZE 10
-
-#if defined(__FreeBSD__)
-#define FRAGS 0x8
-#else
-#define FRAGS ( ( (6 * 5) << 16 ) | 0x6 )
-#endif
-
-/*
- * XXX text message sizes are probably 256 chars, but i am
- * not sure if there is a suitable definition anywhere.
- */
-#define TEXT_SIZE 256
-
-#if 0
-#define TRYOPEN 1 /* try to open on startup */
-#endif
-#define O_CLOSE 0x444 /* special 'close' mode for device */
-/* Which device to use */
-#if defined( __OpenBSD__ ) || defined( __NetBSD__ )
-#define DEV_DSP "/dev/audio"
-#else
-#define DEV_DSP "/dev/dsp"
-#endif
-
-#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-static char *config = "oss.conf"; /* default config file */
-
-static int oss_debug;
-
-/*
- * Each sound is made of 'datalen' samples of sound, repeated as needed to
- * generate 'samplen' samples of data, then followed by 'silencelen' samples
- * of silence. The loop is repeated if 'repeat' is set.
- */
-struct sound {
- int ind;
- char *desc;
- short *data;
- int datalen;
- int samplen;
- int silencelen;
- int repeat;
-};
-
-static struct sound sounds[] = {
- { AST_CONTROL_RINGING, "RINGING", ringtone, sizeof(ringtone)/2, 16000, 32000, 1 },
- { AST_CONTROL_BUSY, "BUSY", busy, sizeof(busy)/2, 4000, 4000, 1 },
- { AST_CONTROL_CONGESTION, "CONGESTION", busy, sizeof(busy)/2, 2000, 2000, 1 },
- { AST_CONTROL_RING, "RING10", ring10, sizeof(ring10)/2, 16000, 32000, 1 },
- { AST_CONTROL_ANSWER, "ANSWER", answer, sizeof(answer)/2, 2200, 0, 0 },
- { -1, NULL, 0, 0, 0, 0 }, /* end marker */
-};
-
-
-/*
- * descriptor for one of our channels.
- * There is one used for 'default' values (from the [general] entry in
- * the configuration file), and then one instance for each device
- * (the default is cloned from [general], others are only created
- * if the relevant section exists).
- */
-struct chan_oss_pvt {
- struct chan_oss_pvt *next;
-
- char *type; /* XXX maybe take the one from oss_tech */
- char *name;
- /*
- * cursound indicates which in struct sound we play. -1 means nothing,
- * any other value is a valid sound, in which case sampsent indicates
- * the next sample to send in [0..samplen + silencelen]
- * nosound is set to disable the audio data from the channel
- * (so we can play the tones etc.).
- */
- int sndcmd[2]; /* Sound command pipe */
- int cursound; /* index of sound to send */
- int sampsent; /* # of sound samples sent */
- int nosound; /* set to block audio from the PBX */
-
- int total_blocks; /* total blocks in the output device */
- int sounddev;
- enum { M_UNSET, M_FULL, M_READ, M_WRITE } duplex;
- int autoanswer;
- int autohangup;
- int hookstate;
- char *mixer_cmd; /* initial command to issue to the mixer */
- unsigned int queuesize; /* max fragments in queue */
- unsigned int frags; /* parameter for SETFRAGMENT */
-
- int warned; /* various flags used for warnings */
-#define WARN_used_blocks 1
-#define WARN_speed 2
-#define WARN_frag 4
- int w_errors; /* overfull in the write path */
- struct timeval lastopen;
-
- int overridecontext;
- int mute;
- char device[64]; /* device to open */
-
- pthread_t sthread;
-
- struct ast_channel *owner;
- char ext[AST_MAX_EXTENSION];
- char ctx[AST_MAX_CONTEXT];
- char language[MAX_LANGUAGE];
-
- /* buffers used in oss_write */
- char oss_write_buf[FRAME_SIZE*2];
- int oss_write_dst;
- /* buffers used in oss_read - AST_FRIENDLY_OFFSET space for headers
- * plus enough room for a full frame
- */
- char oss_read_buf[FRAME_SIZE * 2 + AST_FRIENDLY_OFFSET];
- int readpos; /* read position above */
- struct ast_frame read_f; /* returned by oss_read */
-};
-
-static struct chan_oss_pvt oss_default = {
- .type = "Console",
- .cursound = -1,
- .sounddev = -1,
- .duplex = M_UNSET, /* XXX check this */
- .autoanswer = 1,
- .autohangup = 1,
- .queuesize = QUEUE_SIZE,
- .frags = FRAGS,
- .ext = "s",
- .ctx = "default",
- .readpos = AST_FRIENDLY_OFFSET, /* start here on reads */
- .lastopen = { 0, 0 },
-};
-
-static char *oss_active; /* the active device */
-
-static int setformat(struct chan_oss_pvt *o, int mode);
-
-static struct ast_channel *oss_request(const char *type, int format, void *data
-, int *cause);
-static int oss_digit(struct ast_channel *c, char digit);
-static int oss_text(struct ast_channel *c, const char *text);
-static int oss_hangup(struct ast_channel *c);
-static int oss_answer(struct ast_channel *c);
-static struct ast_frame *oss_read(struct ast_channel *chan);
-static int oss_call(struct ast_channel *c, char *dest, int timeout);
-static int oss_write(struct ast_channel *chan, struct ast_frame *f);
-static int oss_indicate(struct ast_channel *chan, int cond);
-static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-
-static const struct ast_channel_tech oss_tech = {
- .type = "Console",
- .description = "OSS Console Channel Driver",
- .capabilities = AST_FORMAT_SLINEAR,
- .requester = oss_request,
- .send_digit = oss_digit,
- .send_text = oss_text,
- .hangup = oss_hangup,
- .answer = oss_answer,
- .read = oss_read,
- .call = oss_call,
- .write = oss_write,
- .indicate = oss_indicate,
- .fixup = oss_fixup,
-};
-
-/*
- * returns a pointer to the descriptor with the given name
- */
-static struct chan_oss_pvt *find_desc(char *dev)
-{
- struct chan_oss_pvt *o;
-
- for (o = oss_default.next; o && strcmp(o->name, dev) != 0; o = o->next)
- ;
- if (o == NULL)
- ast_log(LOG_WARNING, "could not find <%s>\n", dev);
- return o;
-}
-
-/*
- * split a string in extension-context, returns pointers to malloc'ed
- * strings.
- * If we do not have 'overridecontext' then the last @ is considered as
- * a context separator, and the context is overridden.
- * This is usually not very necessary as you can play with the dialplan,
- * and it is nice not to need it because you have '@' in SIP addresses.
- * Return value is the buffer address.
- */
-static char *ast_ext_ctx(const char *src, char **ext, char **ctx)
-{
- struct chan_oss_pvt *o = find_desc(oss_active);
-
- if (ext == NULL || ctx == NULL)
- return NULL; /* error */
- *ext = *ctx = NULL;
- if (src && *src != '\0')
- *ext = strdup(src);
- if (*ext == NULL)
- return NULL;
- if (!o->overridecontext) {
- /* parse from the right */
- *ctx = strrchr(*ext, '@');
- if (*ctx)
- *(*ctx)++ = '\0';
- }
- return *ext;
-}
-
-/*
- * Returns the number of blocks used in the audio output channel
- */
-static int used_blocks(struct chan_oss_pvt *o)
-{
- struct audio_buf_info info;
-
- if (ioctl(o->sounddev, SNDCTL_DSP_GETOSPACE, &info)) {
- if (! (o->warned & WARN_used_blocks)) {
- ast_log(LOG_WARNING, "Error reading output space\n");
- o->warned |= WARN_used_blocks;
- }
- return 1;
- }
- if (o->total_blocks == 0) {
- if (0) /* debugging */
- ast_log(LOG_WARNING, "fragtotal %d size %d avail %d\n",
- info.fragstotal,
- info.fragsize,
- info.fragments);
- o->total_blocks = info.fragments;
- }
- return o->total_blocks - info.fragments;
-}
-
-/* Write an exactly FRAME_SIZE sized frame */
-static int soundcard_writeframe(struct chan_oss_pvt *o, short *data)
-{
- int res;
-
- if (o->sounddev < 0)
- setformat(o, O_RDWR);
- if (o->sounddev < 0)
- return 0; /* not fatal */
- /*
- * Nothing complex to manage the audio device queue.
- * If the buffer is full just drop the extra, otherwise write.
- * XXX in some cases it might be useful to write anyways after
- * a number of failures, to restart the output chain.
- */
- res = used_blocks(o);
- if (res > o->queuesize) { /* no room to write a block */
- if (o->w_errors++ == 0 && (oss_debug & 0x4))
- ast_log(LOG_WARNING, "write: used %d blocks (%d)\n",
- res, o->w_errors);
- return 0;
- }
- o->w_errors = 0;
- return write(o->sounddev, ((void *)data), FRAME_SIZE * 2);
-}
-
-/*
- * Handler for 'sound writable' events from the sound thread.
- * Builds a frame from the high level description of the sounds,
- * and passes it to the audio device.
- * The actual sound is made of 1 or more sequences of sound samples
- * (s->datalen, repeated to make s->samplen samples) followed by
- * s->silencelen samples of silence. The position in the sequence is stored
- * in o->sampsent, which goes between 0 .. s->samplen+s->silencelen.
- * In case we fail to write a frame, don't update o->sampsent.
- */
-static void send_sound(struct chan_oss_pvt *o)
-{
- short myframe[FRAME_SIZE];
- int ofs, l, start;
- int l_sampsent = o->sampsent;
- struct sound *s;
-
- if (o->cursound < 0) /* no sound to send */
- return;
- s = &sounds[o->cursound];
- for (ofs = 0; ofs < FRAME_SIZE; ofs += l) {
- l = s->samplen - l_sampsent; /* # of available samples */
- if (l > 0) {
- start = l_sampsent % s->datalen; /* source offset */
- if (l > FRAME_SIZE - ofs) /* don't overflow the frame */
- l = FRAME_SIZE - ofs;
- if (l > s->datalen - start) /* don't overflow the source */
- l = s->datalen - start;
- bcopy(s->data + start, myframe + ofs, l*2);
- if (0)
- ast_log(LOG_WARNING, "send_sound sound %d/%d of %d into %d\n",
- l_sampsent, l, s->samplen, ofs);
- l_sampsent += l;
- } else { /* end of samples, maybe some silence */
- static const short silence[FRAME_SIZE] = {0, };
-
- l += s->silencelen;
- if (l > 0) {
- if (l > FRAME_SIZE - ofs)
- l = FRAME_SIZE - ofs;
- bcopy(silence, myframe + ofs, l*2);
- l_sampsent += l;
- } else { /* silence is over, restart sound if loop */
- if (s->repeat == 0) { /* last block */
- o->cursound = -1;
- o->nosound = 0; /* allow audio data */
- if (ofs < FRAME_SIZE) /* pad with silence */
- bcopy(silence, myframe + ofs, (FRAME_SIZE - ofs)*2);
- }
- l_sampsent = 0;
- }
- }
- }
- l = soundcard_writeframe(o, myframe);
- if (l > 0)
- o->sampsent = l_sampsent; /* update status */
-}
-
-static void *sound_thread(void *arg)
-{
- char ign[4096];
- struct chan_oss_pvt *o = (struct chan_oss_pvt *)arg;
-
- /*
- * Just in case, kick the driver by trying to read from it.
- * Ignore errors - this read is almost guaranteed to fail.
- */
- read(o->sounddev, ign, sizeof(ign));
- for (;;) {
- fd_set rfds, wfds;
- int maxfd, res;
-
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- FD_SET(o->sndcmd[0], &rfds);
- maxfd = o->sndcmd[0]; /* pipe from the main process */
- if (o->cursound > -1 && o->sounddev < 0)
- setformat(o, O_RDWR); /* need the channel, try to reopen */
- else if (o->cursound == -1 && o->owner == NULL)
- setformat(o, O_CLOSE); /* can close */
- if (o->sounddev > -1) {
- if (!o->owner) { /* no one owns the audio, so we must drain it */
- FD_SET(o->sounddev, &rfds);
- maxfd = MAX(o->sounddev, maxfd);
- }
- if (o->cursound > -1) {
- FD_SET(o->sounddev, &wfds);
- maxfd = MAX(o->sounddev, maxfd);
- }
- }
- /* ast_select emulates linux behaviour in terms of timeout handling */
- res = ast_select(maxfd + 1, &rfds, &wfds, NULL, NULL);
- if (res < 1) {
- ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
- sleep(1);
- continue;
- }
- if (FD_ISSET(o->sndcmd[0], &rfds)) {
- /* read which sound to play from the pipe */
- int i, what = -1;
-
- read(o->sndcmd[0], &what, sizeof(what));
- for (i = 0; sounds[i].ind != -1; i++) {
- if (sounds[i].ind == what) {
- o->cursound = i;
- o->sampsent = 0;
- o->nosound = 1; /* block audio from pbx */
- break;
- }
- }
- if (sounds[i].ind == -1)
- ast_log(LOG_WARNING, "invalid sound index: %d\n", what);
- }
- if (o->sounddev > -1) {
- if (FD_ISSET(o->sounddev, &rfds)) /* read and ignore errors */
- read(o->sounddev, ign, sizeof(ign));
- if (FD_ISSET(o->sounddev, &wfds))
- send_sound(o);
- }
- }
- return NULL; /* Never reached */
-}
-
-/*
- * reset and close the device if opened,
- * then open and initialize it in the desired mode,
- * trigger reads and writes so we can start using it.
- */
-static int setformat(struct chan_oss_pvt *o, int mode)
-{
- int fmt, desired, res, fd;
-
- if (o->sounddev >= 0) {
- ioctl(o->sounddev, SNDCTL_DSP_RESET, 0);
- close(o->sounddev);
- o->duplex = M_UNSET;
- o->sounddev = -1;
- }
- if (mode == O_CLOSE) /* we are done */
- return 0;
- if (ast_tvdiff_ms(ast_tvnow(), o->lastopen) < 1000)
- return -1; /* don't open too often */
- o->lastopen = ast_tvnow();
- fd = o->sounddev = open(o->device, mode |O_NONBLOCK);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to re-open DSP device %s: %s\n",
- o->device, strerror(errno));
- return -1;
- }
- if (o->owner)
- o->owner->fds[0] = fd;
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- fmt = AFMT_S16_LE;
-#else
- fmt = AFMT_S16_BE;
-#endif
- res = ioctl(fd, SNDCTL_DSP_SETFMT, &fmt);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set format to 16-bit signed\n");
- return -1;
- }
- switch (mode) {
- case O_RDWR:
- res = ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
- /* Check to see if duplex set (FreeBSD Bug)*/
- res = ioctl(fd, SNDCTL_DSP_GETCAPS, &fmt);
- if (res == 0 && (fmt & DSP_CAP_DUPLEX)) {
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Console is full duplex\n");
- o->duplex = M_FULL;
- };
- break;
- case O_WRONLY:
- o->duplex = M_WRITE;
- break;
- case O_RDONLY:
- o->duplex = M_READ;
- break;
- }
-
- fmt = 0;
- res = ioctl(fd, SNDCTL_DSP_STEREO, &fmt);
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
- return -1;
- }
- fmt = desired = 8000; /* 8000 Hz desired */
- res = ioctl(fd, SNDCTL_DSP_SPEED, &fmt);
-
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
- return -1;
- }
- if (fmt != desired) {
- if (!(o->warned & WARN_speed)) {
- ast_log(LOG_WARNING,
- "Requested %d Hz, got %d Hz -- sound may be choppy\n",
- desired, fmt);
- o->warned |= WARN_speed;
- }
- }
- /*
- * on Freebsd, SETFRAGMENT does not work very well on some cards.
- * Default to use 256 bytes, let the user override
- */
- if (o->frags) {
- fmt = o->frags;
- res = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fmt);
- if (res < 0) {
- if (!(o->warned & WARN_frag)) {
- ast_log(LOG_WARNING,
- "Unable to set fragment size -- sound may be choppy\n");
- o->warned |= WARN_frag;
- }
- }
- }
- /* on some cards, we need SNDCTL_DSP_SETTRIGGER to start outputting */
- res = PCM_ENABLE_INPUT | PCM_ENABLE_OUTPUT;
- res = ioctl(fd, SNDCTL_DSP_SETTRIGGER, &res);
- /* it may fail if we are in half duplex, never mind */
- return 0;
-}
-
-/*
- * some of the standard methods supported by channels.
- */
-static int oss_digit(struct ast_channel *c, char digit)
-{
- /* no better use for received digits than print them */
- ast_verbose( " << Console Received digit %c >> \n", digit);
- return 0;
-}
-
-static int oss_text(struct ast_channel *c, const char *text)
-{
- /* print received messages */
- ast_verbose( " << Console Received text %s >> \n", text);
- return 0;
-}
-
-/* Play ringtone 'x' on device 'o' */
-static void ring(struct chan_oss_pvt *o, int x)
-{
- write(o->sndcmd[1], &x, sizeof(x));
-}
-
-
-/*
- * handler for incoming calls. Either autoanswer, or start ringing
- */
-static int oss_call(struct ast_channel *c, char *dest, int timeout)
-{
- struct chan_oss_pvt *o = c->tech_pvt;
- struct ast_frame f = { 0, };
-
- ast_verbose(" << Call to '%s' on console from <%s><%s><%s> >>\n",
- dest, c->cid.cid_dnid, c->cid.cid_num, c->cid.cid_name);
- if (o->autoanswer) {
- ast_verbose( " << Auto-answered >> \n" );
- f.frametype = AST_FRAME_CONTROL;
- f.subclass = AST_CONTROL_ANSWER;
- ast_queue_frame(c, &f);
- } else {
- ast_verbose("<< Type 'answer' to answer, or use 'autoanswer' for future calls >> \n");
- f.frametype = AST_FRAME_CONTROL;
- f.subclass = AST_CONTROL_RINGING;
- ast_queue_frame(c, &f);
- ring(o, AST_CONTROL_RING);
- }
- return 0;
-}
-
-/*
- * remote side answered the phone
- */
-static int oss_answer(struct ast_channel *c)
-{
- struct chan_oss_pvt *o = c->tech_pvt;
-
- ast_verbose( " << Console call has been answered >> \n");
-#if 0
- /* play an answer tone (XXX do we really need it ?) */
- ring(o, AST_CONTROL_ANSWER);
-#endif
- ast_setstate(c, AST_STATE_UP);
- o->cursound = -1;
- o->nosound=0;
- return 0;
-}
-
-static int oss_hangup(struct ast_channel *c)
-{
- struct chan_oss_pvt *o = c->tech_pvt;
-
- o->cursound = -1;
- o->nosound = 0;
- c->tech_pvt = NULL;
- o->owner = NULL;
- ast_verbose( " << Hangup on console >> \n");
- ast_mutex_lock(&usecnt_lock); /* XXX not sure why */
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
- if (o->hookstate) {
- if (o->autoanswer || o->autohangup) {
- /* Assume auto-hangup too */
- o->hookstate = 0;
- setformat(o, O_CLOSE);
- } else {
- /* Make congestion noise */
- ring(o, AST_CONTROL_CONGESTION);
- }
- }
- return 0;
-}
-
-/* used for data coming from the network */
-static int oss_write(struct ast_channel *c, struct ast_frame *f)
-{
- int src;
- struct chan_oss_pvt *o = c->tech_pvt;
-
- /* Immediately return if no sound is enabled */
- if (o->nosound)
- return 0;
- /* Stop any currently playing sound */
- o->cursound = -1;
- /*
- * we could receive a block which is not a multiple of our
- * FRAME_SIZE, so buffer it locally and write to the device
- * in FRAME_SIZE chunks.
- * Keep the residue stored for future use.
- */
- src = 0; /* read position into f->data */
- while ( src < f->datalen ) {
- /* Compute spare room in the buffer */
- int l = sizeof(o->oss_write_buf) - o->oss_write_dst;
-
- if (f->datalen - src >= l) { /* enough to fill a frame */
- memcpy(o->oss_write_buf + o->oss_write_dst,
- f->data + src, l);
- soundcard_writeframe(o, (short *)o->oss_write_buf);
- src += l;
- o->oss_write_dst = 0;
- } else { /* copy residue */
- l = f->datalen - src;
- memcpy(o->oss_write_buf + o->oss_write_dst,
- f->data + src, l);
- src += l; /* but really, we are done */
- o->oss_write_dst += l;
- }
- }
- return 0;
-}
-
-static struct ast_frame *oss_read(struct ast_channel *c)
-{
- int res;
- struct chan_oss_pvt *o = c->tech_pvt;
- struct ast_frame *f = &o->read_f;
-
- /* prepare a NULL frame in case we don't have enough data to return */
- bzero(f, sizeof(struct ast_frame));
- f->frametype = AST_FRAME_NULL;
- f->src = o->type;
-
- res = read(o->sounddev, o->oss_read_buf + o->readpos,
- sizeof(o->oss_read_buf) - o->readpos);
- if (res < 0) /* audio data not ready, return a NULL frame */
- return f;
-
- o->readpos += res;
- if (o->readpos < sizeof(o->oss_read_buf)) /* not enough samples */
- return f;
-
- if (o->mute)
- return f;
-
- o->readpos = AST_FRIENDLY_OFFSET; /* reset read pointer for next frame */
- if (c->_state != AST_STATE_UP) /* drop data if frame is not up */
- return f;
- /* ok we can build and deliver the frame to the caller */
- f->frametype = AST_FRAME_VOICE;
- f->subclass = AST_FORMAT_SLINEAR;
- f->samples = FRAME_SIZE;
- f->datalen = FRAME_SIZE * 2;
- f->data = o->oss_read_buf + AST_FRIENDLY_OFFSET;
- f->offset = AST_FRIENDLY_OFFSET;
- return f;
-}
-
-static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct chan_oss_pvt *o = newchan->tech_pvt;
- o->owner = newchan;
- return 0;
-}
-
-static int oss_indicate(struct ast_channel *c, int cond)
-{
- struct chan_oss_pvt *o = c->tech_pvt;
- int res;
-
- switch(cond) {
- case AST_CONTROL_BUSY:
- case AST_CONTROL_CONGESTION:
- case AST_CONTROL_RINGING:
- res = cond;
- break;
-
- case -1:
- o->cursound = -1;
- o->nosound = 0; /* when cursound is -1 nosound must be 0 */
- return 0;
-
- case AST_CONTROL_VIDUPDATE:
- res = -1;
- break;
- default:
- ast_log(LOG_WARNING,
- "Don't know how to display condition %d on %s\n",
- cond, c->name);
- return -1;
- }
- if (res > -1)
- ring(o, res);
- return 0;
-}
-
-/*
- * allocate a new channel.
- */
-static struct ast_channel *oss_new(struct chan_oss_pvt *o,
- char *ext, char *ctx, int state)
-{
- struct ast_channel *c;
-
- c = ast_channel_alloc(1);
- if (c == NULL)
- return NULL;
- c->tech = &oss_tech;
- snprintf(c->name, sizeof(c->name), "OSS/%s", o->device + 5);
- c->type = o->type;
- c->fds[0] = o->sounddev; /* -1 if device closed, override later */
- c->nativeformats = AST_FORMAT_SLINEAR;
- c->readformat = AST_FORMAT_SLINEAR;
- c->writeformat = AST_FORMAT_SLINEAR;
- c->tech_pvt = o;
-
- if (!ast_strlen_zero(ctx))
- ast_copy_string(c->context, ctx, sizeof(c->context));
- if (!ast_strlen_zero(ext))
- ast_copy_string(c->exten, ext, sizeof(c->exten));
- if (!ast_strlen_zero(o->language))
- ast_copy_string(c->language, o->language, sizeof(c->language));
-
- o->owner = c;
- ast_setstate(c, state);
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(c)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", c->name);
- ast_hangup(c);
- o->owner = c = NULL;
- /* XXX what about the channel itself ? */
- /* XXX what about usecnt ? */
- }
- }
- return c;
-}
-
-static struct ast_channel *oss_request(const char *type,
- int format, void *data, int *cause)
-{
- struct ast_channel *c;
- struct chan_oss_pvt *o = find_desc(data);
-
- ast_log(LOG_WARNING, "oss_request ty <%s> data 0x%p <%s>\n",
- type, data, (char *)data);
- if (o == NULL) {
- ast_log(LOG_NOTICE, "Device %s not found\n", (char *)data);
- /* XXX we could default to 'dsp' perhaps ? */
- return NULL;
- }
- if ((format & AST_FORMAT_SLINEAR) == 0) {
- ast_log(LOG_NOTICE, "Format 0x%x unsupported\n", format);
- return NULL;
- }
- if (o->owner) {
- ast_log(LOG_NOTICE, "Already have a call (chan %p) on the OSS channel\n", o->owner);
- *cause = AST_CAUSE_BUSY;
- return NULL;
- }
- c= oss_new(o, NULL, NULL, AST_STATE_DOWN);
- if (c == NULL) {
- ast_log(LOG_WARNING, "Unable to create new OSS channel\n");
- return NULL;
- }
- return c;
-}
-
-static int console_autoanswer(int fd, int argc, char *argv[])
-{
- struct chan_oss_pvt *o = find_desc(oss_active);
-
- if (argc == 1) {
- ast_cli(fd, "Auto answer is %s.\n", o->autoanswer ? "on" : "off");
- return RESULT_SUCCESS;
- }
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- if (o == NULL) {
- ast_log(LOG_WARNING, "Cannot find device %s (should not happen!)\n",
- oss_active);
- return RESULT_FAILURE;
- }
- if (!strcasecmp(argv[1], "on"))
- o->autoanswer = -1;
- else if (!strcasecmp(argv[1], "off"))
- o->autoanswer = 0;
- else
- return RESULT_SHOWUSAGE;
- return RESULT_SUCCESS;
-}
-
-static char *autoanswer_complete(char *line, char *word, int pos, int state)
-{
- int l = strlen(word);
-
- switch(state) {
- case 0:
- if (l && !strncasecmp(word, "on", MIN(l, 2)))
- return strdup("on");
- case 1:
- if (l && !strncasecmp(word, "off", MIN(l, 3)))
- return strdup("off");
- default:
- return NULL;
- }
- return NULL;
-}
-
-static char autoanswer_usage[] =
-"Usage: autoanswer [on|off]\n"
-" Enables or disables autoanswer feature. If used without\n"
-" argument, displays the current on/off status of autoanswer.\n"
-" The default value of autoanswer is in 'oss.conf'.\n";
-
-/*
- * answer command from the console
- */
-static int console_answer(int fd, int argc, char *argv[])
-{
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
- struct chan_oss_pvt *o = find_desc(oss_active);
-
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- if (!o->owner) {
- ast_cli(fd, "No one is calling us\n");
- return RESULT_FAILURE;
- }
- o->hookstate = 1;
- o->cursound = -1;
- o->nosound = 0;
- ast_queue_frame(o->owner, &f);
-#if 0
- /* XXX do we really need it ? considering we shut down immediately... */
- ring(o, AST_CONTROL_ANSWER);
-#endif
- return RESULT_SUCCESS;
-}
-
-static char sendtext_usage[] =
-"Usage: send text <message>\n"
-" Sends a text message for display on the remote terminal.\n";
-
-/*
- * concatenate all arguments into a single string
- */
-static int console_sendtext(int fd, int argc, char *argv[])
-{
- struct chan_oss_pvt *o = find_desc(oss_active);
- int tmparg = 2;
- char text2send[TEXT_SIZE] = "";
- struct ast_frame f = { 0, };
-
- if (argc < 2)
- return RESULT_SHOWUSAGE;
- if (!o->owner) {
- ast_cli(fd, "Not in a call\n");
- return RESULT_FAILURE;
- }
- while (tmparg < argc) {
- strncat(text2send, argv[tmparg++],
- sizeof(text2send) - strlen(text2send) - 1);
- strncat(text2send, " ",
- sizeof(text2send) - strlen(text2send) - 1);
- }
- if (!ast_strlen_zero(text2send)) {
- text2send[strlen(text2send) - 1] = '\n';
- f.frametype = AST_FRAME_TEXT;
- f.subclass = 0;
- f.data = text2send;
- f.datalen = strlen(text2send);
- ast_queue_frame(o->owner, &f);
- }
- return RESULT_SUCCESS;
-}
-
-static char answer_usage[] =
-"Usage: answer\n"
-" Answers an incoming call on the console (OSS) channel.\n";
-
-static int console_hangup(int fd, int argc, char *argv[])
-{
- struct chan_oss_pvt *o = find_desc(oss_active);
-
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- o->cursound = -1;
- o->nosound = 0;
- if (!o->owner && !o->hookstate) { /* XXX maybe only one ? */
- ast_cli(fd, "No call to hang up\n");
- return RESULT_FAILURE;
- }
- o->hookstate = 0;
- if (o->owner)
- ast_queue_hangup(o->owner);
- setformat(o, O_CLOSE);
- return RESULT_SUCCESS;
-}
-
-static char hangup_usage[] =
-"Usage: hangup\n"
-" Hangs up any call currently placed on the console.\n";
-
-
-static int console_flash(int fd, int argc, char *argv[])
-{
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH };
- struct chan_oss_pvt *o = find_desc(oss_active);
-
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- o->cursound = -1;
- o->nosound = 0; /* when cursound is -1 nosound must be 0 */
- if (!o->owner) { /* XXX maybe !o->hookstate too ? */
- ast_cli(fd, "No call to flash\n");
- return RESULT_FAILURE;
- }
- o->hookstate = 0;
- if (o->owner) /* XXX must be true, right ? */
- ast_queue_frame(o->owner, &f);
- return RESULT_SUCCESS;
-}
-
-
-static char flash_usage[] =
-"Usage: flash\n"
-" Flashes the call currently placed on the console.\n";
-
-
-
-static int console_dial(int fd, int argc, char *argv[])
-{
- char *s = NULL, *mye = NULL, *myc = NULL;
- struct chan_oss_pvt *o = find_desc(oss_active);
-
- if (argc != 1 && argc != 2)
- return RESULT_SHOWUSAGE;
- if (o->owner) { /* already in a call */
- int i;
- struct ast_frame f = { AST_FRAME_DTMF, 0 };
-
- if (argc == 1) { /* argument is mandatory here */
- ast_cli(fd, "Already in a call. You can only dial digits until you hangup.\n");
- return RESULT_FAILURE;
- }
- s = argv[1];
- /* send the string one char at a time */
- for (i=0; i<strlen(s); i++) {
- f.subclass = s[i];
- ast_queue_frame(o->owner, &f);
- }
- return RESULT_SUCCESS;
- }
- /* if we have an argument split it into extension and context */
- if (argc == 2)
- s = ast_ext_ctx(argv[1], &mye, &myc);
- /* supply default values if needed */
- if (mye == NULL)
- mye = o->ext;
- if (myc == NULL)
- myc = o->ctx;
- if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
- o->hookstate = 1;
- oss_new(o, mye, myc, AST_STATE_RINGING);
- } else
- ast_cli(fd, "No such extension '%s' in context '%s'\n", mye, myc);
- if (s)
- free(s);
- return RESULT_SUCCESS;
-}
-
-static char dial_usage[] =
-"Usage: dial [extension[@context]]\n"
-" Dials a given extensison (and context if specified)\n";
-
-static char mute_usage[] =
-"Usage: mute\nMutes the microphone\n";
-
-static char unmute_usage[] =
-"Usage: unmute\nUnmutes the microphone\n";
-
-static int console_mute(int fd, int argc, char *argv[])
-{
- struct chan_oss_pvt *o = find_desc(oss_active);
-
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- o->mute = 1;
- return RESULT_SUCCESS;
-}
-
-static int console_unmute(int fd, int argc, char *argv[])
-{
- struct chan_oss_pvt *o = find_desc(oss_active);
-
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- o->mute = 0;
- return RESULT_SUCCESS;
-}
-
-static int console_transfer(int fd, int argc, char *argv[])
-{
- struct chan_oss_pvt *o = find_desc(oss_active);
- struct ast_channel *b = NULL;
- char *tmp, *ext, *ctx;
-
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- if (o == NULL)
- return RESULT_FAILURE;
- if (o->owner ==NULL || (b = ast_bridged_channel(o->owner)) == NULL) {
- ast_cli(fd, "There is no call to transfer\n");
- return RESULT_SUCCESS;
- }
-
- tmp = ast_ext_ctx(argv[1], &ext, &ctx);
- if (ctx == NULL) /* supply default context if needed */
- ctx = o->owner->context;
- if (!ast_exists_extension(b, ctx, ext, 1, b->cid.cid_num))
- ast_cli(fd, "No such extension exists\n");
- else {
- ast_cli(fd, "Whee, transferring %s to %s@%s.\n",
- b->name, ext, ctx);
- if (ast_async_goto(b, ctx, ext, 1))
- ast_cli(fd, "Failed to transfer :(\n");
- }
- if (tmp)
- free(tmp);
- return RESULT_SUCCESS;
-}
-
-static char transfer_usage[] =
-"Usage: transfer <extension>[@context]\n"
-" Transfers the currently connected call to the given extension (and\n"
-"context if specified)\n";
-
-static char console_usage[] =
-"Usage: console [device]\n"
-" If used without a parameter, displays which device is the current\n"
-"console. If a device is specified, the console sound device is changed to\n"
-"the device specified.\n";
-
-static int console_active(int fd, int argc, char *argv[])
-{
- if (argc == 1)
- ast_cli(fd, "active console is [%s]\n", oss_active);
- else if (argc != 2)
- return RESULT_SHOWUSAGE;
- else {
- struct chan_oss_pvt *o;
- if (strcmp(argv[1], "show") == 0) {
- for (o = oss_default.next; o ; o = o->next)
- ast_cli(fd, "device [%s] exists\n", o->name);
- return RESULT_SUCCESS;
- }
- o = find_desc(argv[1]);
- if (o == NULL)
- ast_cli(fd, "No device [%s] exists\n", argv[1]);
- else
- oss_active = o->name;
- }
- return RESULT_SUCCESS;
-}
-
-static struct ast_cli_entry myclis[] = {
- { { "answer", NULL }, console_answer, "Answer an incoming console call", answer_usage },
- { { "hangup", NULL }, console_hangup, "Hangup a call on the console", hangup_usage },
- { { "flash", NULL }, console_flash, "Flash a call on the console", flash_usage },
- { { "dial", NULL }, console_dial, "Dial an extension on the console", dial_usage },
- { { "mute", NULL }, console_mute, "Disable mic input", mute_usage },
- { { "unmute", NULL }, console_unmute, "Enable mic input", unmute_usage },
- { { "transfer", NULL }, console_transfer, "Transfer a call to a different extension", transfer_usage },
- { { "send", "text", NULL }, console_sendtext, "Send text to the remote device", sendtext_usage },
- { { "autoanswer", NULL }, console_autoanswer, "Sets/displays autoanswer", autoanswer_usage, autoanswer_complete },
- { { "console", NULL }, console_active, "Sets/displays active console", console_usage },
-};
-
-/*
- * store the mixer argument from the config file, filtering possibly
- * invalid or dangerous values (the string is used as argument for
- * system("mixer %s")
- */
-static void store_mixer(struct chan_oss_pvt *o, char *s)
-{
- int i;
-
- for (i=0; i < strlen(s); i++) {
- if (!isalnum(s[i]) && index(" \t-/", s[i]) == NULL) {
- ast_log(LOG_WARNING,
- "Suspect char %c in mixer cmd, ignoring:\n\t%s\n", s[i], s);
- return;
- }
- }
- if (o->mixer_cmd)
- free(o->mixer_cmd);
- o->mixer_cmd = strdup(s);
- ast_log(LOG_WARNING, "setting mixer %s\n", s);
-}
-
-/*
- * grab fields from the config file, init the descriptor and open the device.
- */
-static struct chan_oss_pvt * store_config(struct ast_config *cfg, char *ctg)
-{
- struct ast_variable *v;
- struct chan_oss_pvt *o;
-
- if (ctg == NULL) {
- o = &oss_default;
- ctg = "general";
- } else {
- o = (struct chan_oss_pvt *)malloc(sizeof *o);
- if (o == NULL) /* fail */
- return NULL;
- *o = oss_default;
- /* "general" is also the default thing */
- if (strcmp(ctg, "general") == 0) {
- o->name = strdup("dsp");
- oss_active = o->name;
- goto openit;
- }
- o->name = strdup(ctg);
- }
-
- o->lastopen = ast_tvnow(); /* don't leave it 0 or tvdiff may wrap */
- /* fill other fields from configuration */
- for (v = ast_variable_browse(cfg, ctg);v; v=v->next) {
- M_START(v->name, v->value);
-
- M_BOOL("autoanswer", o->autoanswer)
- M_BOOL("autohangup", o->autohangup)
- M_BOOL("overridecontext", o->overridecontext)
- M_STR("device", o->device)
- M_UINT("frags", o->frags)
- M_UINT("debug", oss_debug)
- M_UINT("queuesize", o->queuesize)
- M_STR("context", o->ctx)
- M_STR("language", o->language)
- M_STR("extension", o->ext)
- M_F("mixer", store_mixer(o, v->value))
- M_END(;);
- }
- if (ast_strlen_zero(o->device))
- ast_copy_string(o->device, DEV_DSP, sizeof(o->device));
- if (o->mixer_cmd) {
- char *cmd;
-
- asprintf(&cmd, "mixer %s", o->mixer_cmd);
- ast_log(LOG_WARNING, "running [%s]\n", cmd);
- system(cmd);
- free(cmd);
- }
- if (o == &oss_default) /* we are done with the default */
- return NULL;
-
-openit:
-#if TRYOPEN
- if (setformat(o, O_RDWR) < 0) { /* open device */
- if (option_verbose > 0) {
- ast_verbose(VERBOSE_PREFIX_2 "Device %s not detected\n", ctg);
- ast_verbose(VERBOSE_PREFIX_2 "Turn off OSS support by adding "
- "'noload=chan_oss.so' in /etc/asterisk/modules.conf\n");
- }
- goto error;
- }
- if (o->duplex != M_FULL)
- ast_log(LOG_WARNING, "XXX I don't work right with non "
- "full-duplex sound cards XXX\n");
-#endif /* TRYOPEN */
- if (pipe(o->sndcmd) != 0) {
- ast_log(LOG_ERROR, "Unable to create pipe\n");
- goto error;
- }
- ast_pthread_create(&o->sthread, NULL, sound_thread, o);
- /* link into list of devices */
- if (o != &oss_default) {
- o->next = oss_default.next;
- oss_default.next = o;
- }
- return o;
-
-error:
- if (o != &oss_default)
- free(o);
- return NULL;
-}
-
-int load_module(void)
-{
- int i;
- struct ast_config *cfg;
-
- /* load config file */
- cfg = ast_config_load(config);
- if (cfg != NULL) {
- char *ctg = NULL; /* first pass is 'general' */
-
- do {
- store_config(cfg, ctg);
- } while ( (ctg = ast_category_browse(cfg, ctg)) != NULL);
- ast_config_destroy(cfg);
- } else {
- ast_log(LOG_NOTICE, "Unable to load config oss.conf\n");
- return -1;
- }
- if (find_desc(oss_active) == NULL) {
- ast_log(LOG_NOTICE, "Device %s not found\n", oss_active);
- /* XXX we could default to 'dsp' perhaps ? */
- /* XXX should cleanup allocated memory etc. */
- return -1;
- }
- i = ast_channel_register(&oss_tech);
- if (i < 0) {
- ast_log(LOG_ERROR, "Unable to register channel class '%s'\n",
- oss_default.type);
- /* XXX should cleanup allocated memory etc. */
- return -1;
- }
- ast_cli_register_multiple(myclis, sizeof(myclis)/sizeof(struct ast_cli_entry));
- return 0;
-}
-
-
-int unload_module()
-{
- struct chan_oss_pvt *o;
-
- ast_channel_unregister(&oss_tech);
- ast_cli_unregister_multiple(myclis,
- sizeof(myclis)/sizeof(struct ast_cli_entry));
-
- for (o = oss_default.next; o ; o = o->next) {
- close(o->sounddev);
- if (o->sndcmd[0] > 0) {
- close(o->sndcmd[0]);
- close(o->sndcmd[1]);
- }
- if (o->owner)
- ast_softhangup(o->owner, AST_SOFTHANGUP_APPUNLOAD);
- if (o->owner) /* XXX how ??? */
- return -1;
- /* XXX what about the thread ? */
- /* XXX what about the memory allocated ? */
- }
- return 0;
-}
-
-char *description()
-{
- return (char *)oss_tech.description;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_oss_old.c b/1.2-netsec/channels/chan_oss_old.c
deleted file mode 100644
index c1613d3b6..000000000
--- a/1.2-netsec/channels/chan_oss_old.c
+++ /dev/null
@@ -1,1132 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
- * Use /dev/dsp as a channel, and the console to command it :).
- *
- * The full-duplex "simulation" is pretty weak. This is generally a
- * VERY BADLY WRITTEN DRIVER so please don't use it as a model for
- * writing a driver.
- *
- * \ingroup channel_drivers
- */
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#ifdef __linux
-#include <linux/soundcard.h>
-#elif defined(__FreeBSD__)
-#include <sys/soundcard.h>
-#else
-#include <soundcard.h>
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/pbx.h"
-#include "asterisk/config.h"
-#include "asterisk/cli.h"
-#include "asterisk/utils.h"
-#include "asterisk/causes.h"
-#include "asterisk/endian.h"
-
-#include "busy.h"
-#include "ringtone.h"
-#include "ring10.h"
-#include "answer.h"
-
-/* Which device to use */
-#if defined( __OpenBSD__ ) || defined( __NetBSD__ )
-#define DEV_DSP "/dev/audio"
-#else
-#define DEV_DSP "/dev/dsp"
-#endif
-
-/* Lets use 160 sample frames, just like GSM. */
-#define FRAME_SIZE 160
-
-/* When you set the frame size, you have to come up with
- the right buffer format as well. */
-/* 5 64-byte frames = one frame */
-#define BUFFER_FMT ((buffersize * 10) << 16) | (0x0006);
-
-/* Don't switch between read/write modes faster than every 300 ms */
-#define MIN_SWITCH_TIME 600
-
-static struct timeval lasttime;
-
-static int usecnt;
-static int silencesuppression = 0;
-static int silencethreshold = 1000;
-static int playbackonly = 0;
-
-
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-static const char type[] = "Console";
-static const char desc[] = "OSS Console Channel Driver";
-static const char tdesc[] = "OSS Console Channel Driver";
-static const char config[] = "oss.conf";
-
-static char context[AST_MAX_CONTEXT] = "default";
-static char language[MAX_LANGUAGE] = "";
-static char exten[AST_MAX_EXTENSION] = "s";
-
-static int hookstate=0;
-
-static short silence[FRAME_SIZE] = {0, };
-
-struct sound {
- int ind;
- short *data;
- int datalen;
- int samplen;
- int silencelen;
- int repeat;
-};
-
-static struct sound sounds[] = {
- { AST_CONTROL_RINGING, ringtone, sizeof(ringtone)/2, 16000, 32000, 1 },
- { AST_CONTROL_BUSY, busy, sizeof(busy)/2, 4000, 4000, 1 },
- { AST_CONTROL_CONGESTION, busy, sizeof(busy)/2, 2000, 2000, 1 },
- { AST_CONTROL_RING, ring10, sizeof(ring10)/2, 16000, 32000, 1 },
- { AST_CONTROL_ANSWER, answer, sizeof(answer)/2, 2200, 0, 0 },
-};
-
-/* Sound command pipe */
-static int sndcmd[2];
-
-static struct chan_oss_pvt {
- /* We only have one OSS structure -- near sighted perhaps, but it
- keeps this driver as simple as possible -- as it should be. */
- struct ast_channel *owner;
- char exten[AST_MAX_EXTENSION];
- char context[AST_MAX_CONTEXT];
-} oss;
-
-static struct ast_channel *oss_request(const char *type, int format, void *data, int *cause);
-static int oss_digit(struct ast_channel *c, char digit);
-static int oss_text(struct ast_channel *c, const char *text);
-static int oss_hangup(struct ast_channel *c);
-static int oss_answer(struct ast_channel *c);
-static struct ast_frame *oss_read(struct ast_channel *chan);
-static int oss_call(struct ast_channel *c, char *dest, int timeout);
-static int oss_write(struct ast_channel *chan, struct ast_frame *f);
-static int oss_indicate(struct ast_channel *chan, int cond);
-static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-
-static const struct ast_channel_tech oss_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_SLINEAR,
- .requester = oss_request,
- .send_digit = oss_digit,
- .send_text = oss_text,
- .hangup = oss_hangup,
- .answer = oss_answer,
- .read = oss_read,
- .call = oss_call,
- .write = oss_write,
- .indicate = oss_indicate,
- .fixup = oss_fixup,
-};
-
-static int time_has_passed(void)
-{
- struct timeval tv;
- int ms;
- gettimeofday(&tv, NULL);
- ms = (tv.tv_sec - lasttime.tv_sec) * 1000 +
- (tv.tv_usec - lasttime.tv_usec) / 1000;
- if (ms > MIN_SWITCH_TIME)
- return -1;
- return 0;
-}
-
-/* Number of buffers... Each is FRAMESIZE/8 ms long. For example
- with 160 sample frames, and a buffer size of 3, we have a 60ms buffer,
- usually plenty. */
-
-static pthread_t sthread;
-
-#define MAX_BUFFER_SIZE 100
-static int buffersize = 3;
-
-static int full_duplex = 0;
-
-/* Are we reading or writing (simulated full duplex) */
-static int readmode = 1;
-
-/* File descriptor for sound device */
-static int sounddev = -1;
-
-static int autoanswer = 1;
-
-#if 0
-static int calc_loudness(short *frame)
-{
- int sum = 0;
- int x;
- for (x=0;x<FRAME_SIZE;x++) {
- if (frame[x] < 0)
- sum -= frame[x];
- else
- sum += frame[x];
- }
- sum = sum/FRAME_SIZE;
- return sum;
-}
-#endif
-
-static int cursound = -1;
-static int sampsent = 0;
-static int silencelen=0;
-static int offset=0;
-static int nosound=0;
-
-static int send_sound(void)
-{
- short myframe[FRAME_SIZE];
- int total = FRAME_SIZE;
- short *frame = NULL;
- int amt=0;
- int res;
- int myoff;
- audio_buf_info abi;
- if (cursound > -1) {
- res = ioctl(sounddev, SNDCTL_DSP_GETOSPACE ,&abi);
- if (res) {
- ast_log(LOG_WARNING, "Unable to read output space\n");
- return -1;
- }
- /* Calculate how many samples we can send, max */
- if (total > (abi.fragments * abi.fragsize / 2))
- total = abi.fragments * abi.fragsize / 2;
- res = total;
- if (sampsent < sounds[cursound].samplen) {
- myoff=0;
- while(total) {
- amt = total;
- if (amt > (sounds[cursound].datalen - offset))
- amt = sounds[cursound].datalen - offset;
- memcpy(myframe + myoff, sounds[cursound].data + offset, amt * 2);
- total -= amt;
- offset += amt;
- sampsent += amt;
- myoff += amt;
- if (offset >= sounds[cursound].datalen)
- offset = 0;
- }
- /* Set it up for silence */
- if (sampsent >= sounds[cursound].samplen)
- silencelen = sounds[cursound].silencelen;
- frame = myframe;
- } else {
- if (silencelen > 0) {
- frame = silence;
- silencelen -= res;
- } else {
- if (sounds[cursound].repeat) {
- /* Start over */
- sampsent = 0;
- offset = 0;
- } else {
- cursound = -1;
- nosound = 0;
- }
- }
- }
- if (frame)
- res = write(sounddev, frame, res * 2);
- if (res > 0)
- return 0;
- return res;
- }
- return 0;
-}
-
-static void *sound_thread(void *unused)
-{
- fd_set rfds;
- fd_set wfds;
- int max;
- int res;
- char ign[4096];
- if (read(sounddev, ign, sizeof(sounddev)) < 0)
- ast_log(LOG_WARNING, "Read error on sound device: %s\n", strerror(errno));
- for(;;) {
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- max = sndcmd[0];
- FD_SET(sndcmd[0], &rfds);
- if (!oss.owner) {
- FD_SET(sounddev, &rfds);
- if (sounddev > max)
- max = sounddev;
- }
- if (cursound > -1) {
- FD_SET(sounddev, &wfds);
- if (sounddev > max)
- max = sounddev;
- }
- res = ast_select(max + 1, &rfds, &wfds, NULL, NULL);
- if (res < 1) {
- ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
- continue;
- }
- if (FD_ISSET(sndcmd[0], &rfds)) {
- read(sndcmd[0], &cursound, sizeof(cursound));
- silencelen = 0;
- offset = 0;
- sampsent = 0;
- }
- if (FD_ISSET(sounddev, &rfds)) {
- /* Ignore read */
- if (read(sounddev, ign, sizeof(ign)) < 0)
- ast_log(LOG_WARNING, "Read error on sound device: %s\n", strerror(errno));
- }
- if (FD_ISSET(sounddev, &wfds))
- if (send_sound())
- ast_log(LOG_WARNING, "Failed to write sound\n");
- }
- /* Never reached */
- return NULL;
-}
-
-#if 0
-static int silence_suppress(short *buf)
-{
-#define SILBUF 3
- int loudness;
- static int silentframes = 0;
- static char silbuf[FRAME_SIZE * 2 * SILBUF];
- static int silbufcnt=0;
- if (!silencesuppression)
- return 0;
- loudness = calc_loudness((short *)(buf));
- if (option_debug)
- ast_log(LOG_DEBUG, "loudness is %d\n", loudness);
- if (loudness < silencethreshold) {
- silentframes++;
- silbufcnt++;
- /* Keep track of the last few bits of silence so we can play
- them as lead-in when the time is right */
- if (silbufcnt >= SILBUF) {
- /* Make way for more buffer */
- memmove(silbuf, silbuf + FRAME_SIZE * 2, FRAME_SIZE * 2 * (SILBUF - 1));
- silbufcnt--;
- }
- memcpy(silbuf + FRAME_SIZE * 2 * silbufcnt, buf, FRAME_SIZE * 2);
- if (silentframes > 10) {
- /* We've had plenty of silence, so compress it now */
- return 1;
- }
- } else {
- silentframes=0;
- /* Write any buffered silence we have, it may have something
- important */
- if (silbufcnt) {
- write(sounddev, silbuf, silbufcnt * FRAME_SIZE);
- silbufcnt = 0;
- }
- }
- return 0;
-}
-#endif
-
-static int setformat(void)
-{
- int fmt, desired, res, fd = sounddev;
- static int warnedalready = 0;
- static int warnedalready2 = 0;
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- fmt = AFMT_S16_LE;
-#else
- fmt = AFMT_S16_BE;
-#endif
-
- res = ioctl(fd, SNDCTL_DSP_SETFMT, &fmt);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set format to 16-bit signed\n");
- return -1;
- }
- res = ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
-
- /* Check to see if duplex set (FreeBSD Bug)*/
- res = ioctl(fd, SNDCTL_DSP_GETCAPS, &fmt);
-
- if ((fmt & DSP_CAP_DUPLEX) && !res) {
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Console is full duplex\n");
- full_duplex = -1;
- }
- fmt = 0;
- res = ioctl(fd, SNDCTL_DSP_STEREO, &fmt);
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
- return -1;
- }
- /* 8000 Hz desired */
- desired = 8000;
- fmt = desired;
- res = ioctl(fd, SNDCTL_DSP_SPEED, &fmt);
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
- return -1;
- }
- if (fmt != desired) {
- if (!warnedalready++)
- ast_log(LOG_WARNING, "Requested %d Hz, got %d Hz -- sound may be choppy\n", desired, fmt);
- }
-#if 1
- fmt = BUFFER_FMT;
- res = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fmt);
- if (res < 0) {
- if (!warnedalready2++)
- ast_log(LOG_WARNING, "Unable to set fragment size -- sound may be choppy\n");
- }
-#endif
- return 0;
-}
-
-static int soundcard_setoutput(int force)
-{
- /* Make sure the soundcard is in output mode. */
- int fd = sounddev;
- if (full_duplex || (!readmode && !force))
- return 0;
- readmode = 0;
- if (force || time_has_passed()) {
- ioctl(sounddev, SNDCTL_DSP_RESET, 0);
- /* Keep the same fd reserved by closing the sound device and copying stdin at the same
- time. */
- /* dup2(0, sound); */
- close(sounddev);
- fd = open(DEV_DSP, O_WRONLY |O_NONBLOCK);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to re-open DSP device: %s\n", strerror(errno));
- return -1;
- }
- /* dup2 will close the original and make fd be sound */
- if (dup2(fd, sounddev) < 0) {
- ast_log(LOG_WARNING, "dup2() failed: %s\n", strerror(errno));
- return -1;
- }
- if (setformat()) {
- return -1;
- }
- return 0;
- }
- return 1;
-}
-
-static int soundcard_setinput(int force)
-{
- int fd = sounddev;
- if (full_duplex || (readmode && !force))
- return 0;
- readmode = -1;
- if (force || time_has_passed()) {
- ioctl(sounddev, SNDCTL_DSP_RESET, 0);
- close(sounddev);
- /* dup2(0, sound); */
- fd = open(DEV_DSP, O_RDONLY | O_NONBLOCK);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to re-open DSP device: %s\n", strerror(errno));
- return -1;
- }
- /* dup2 will close the original and make fd be sound */
- if (dup2(fd, sounddev) < 0) {
- ast_log(LOG_WARNING, "dup2() failed: %s\n", strerror(errno));
- return -1;
- }
- if (setformat()) {
- return -1;
- }
- return 0;
- }
- return 1;
-}
-
-static int soundcard_init(void)
-{
- /* Assume it's full duplex for starters */
- int fd = open(DEV_DSP, O_RDWR | O_NONBLOCK);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to open %s: %s\n", DEV_DSP, strerror(errno));
- return fd;
- }
- gettimeofday(&lasttime, NULL);
- sounddev = fd;
- setformat();
- if (!full_duplex)
- soundcard_setinput(1);
- return sounddev;
-}
-
-static int oss_digit(struct ast_channel *c, char digit)
-{
- ast_verbose( " << Console Received digit %c >> \n", digit);
- return 0;
-}
-
-static int oss_text(struct ast_channel *c, const char *text)
-{
- ast_verbose( " << Console Received text %s >> \n", text);
- return 0;
-}
-
-static int oss_call(struct ast_channel *c, char *dest, int timeout)
-{
- int res = 3;
- struct ast_frame f = { 0, };
- ast_verbose( " << Call placed to '%s' on console >> \n", dest);
- if (autoanswer) {
- ast_verbose( " << Auto-answered >> \n" );
- f.frametype = AST_FRAME_CONTROL;
- f.subclass = AST_CONTROL_ANSWER;
- ast_queue_frame(c, &f);
- } else {
- nosound = 1;
- ast_verbose( " << Type 'answer' to answer, or use 'autoanswer' for future calls >> \n");
- f.frametype = AST_FRAME_CONTROL;
- f.subclass = AST_CONTROL_RINGING;
- ast_queue_frame(c, &f);
- write(sndcmd[1], &res, sizeof(res));
- }
- return 0;
-}
-
-static void answer_sound(void)
-{
- int res;
- nosound = 1;
- res = 4;
- write(sndcmd[1], &res, sizeof(res));
-
-}
-
-static int oss_answer(struct ast_channel *c)
-{
- ast_verbose( " << Console call has been answered >> \n");
- answer_sound();
- ast_setstate(c, AST_STATE_UP);
- cursound = -1;
- nosound=0;
- return 0;
-}
-
-static int oss_hangup(struct ast_channel *c)
-{
- int res = 0;
- cursound = -1;
- c->tech_pvt = NULL;
- oss.owner = NULL;
- ast_verbose( " << Hangup on console >> \n");
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
- if (hookstate) {
- if (autoanswer) {
- /* Assume auto-hangup too */
- hookstate = 0;
- } else {
- /* Make congestion noise */
- res = 2;
- write(sndcmd[1], &res, sizeof(res));
- hookstate = 0;
- }
- }
- return 0;
-}
-
-static int soundcard_writeframe(short *data)
-{
- /* Write an exactly FRAME_SIZE sized of frame */
- static int bufcnt = 0;
- static short buffer[FRAME_SIZE * MAX_BUFFER_SIZE * 5];
- struct audio_buf_info info;
- int res;
- int fd = sounddev;
- static int warned=0;
- if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info)) {
- if (!warned)
- ast_log(LOG_WARNING, "Error reading output space\n");
- bufcnt = buffersize;
- warned++;
- }
- if ((info.fragments >= buffersize * 5) && (bufcnt == buffersize)) {
- /* We've run out of stuff, buffer again */
- bufcnt = 0;
- }
- if (bufcnt == buffersize) {
- /* Write sample immediately */
- res = write(fd, ((void *)data), FRAME_SIZE * 2);
- } else {
- /* Copy the data into our buffer */
- res = FRAME_SIZE * 2;
- memcpy(buffer + (bufcnt * FRAME_SIZE), data, FRAME_SIZE * 2);
- bufcnt++;
- if (bufcnt == buffersize) {
- res = write(fd, ((void *)buffer), FRAME_SIZE * 2 * buffersize);
- }
- }
- return res;
-}
-
-
-static int oss_write(struct ast_channel *chan, struct ast_frame *f)
-{
- int res;
- static char sizbuf[8000];
- static int sizpos = 0;
- int len = sizpos;
- int pos;
- /* Immediately return if no sound is enabled */
- if (nosound)
- return 0;
- /* Stop any currently playing sound */
- cursound = -1;
- if (!full_duplex && !playbackonly) {
- /* If we're half duplex, we have to switch to read mode
- to honor immediate needs if necessary. But if we are in play
- back only mode, then we don't switch because the console
- is only being used one way -- just to playback something. */
- res = soundcard_setinput(1);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set device to input mode\n");
- return -1;
- }
- return 0;
- }
- res = soundcard_setoutput(0);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set output device\n");
- return -1;
- } else if (res > 0) {
- /* The device is still in read mode, and it's too soon to change it,
- so just pretend we wrote it */
- return 0;
- }
- /* We have to digest the frame in 160-byte portions */
- if (f->datalen > sizeof(sizbuf) - sizpos) {
- ast_log(LOG_WARNING, "Frame too large\n");
- return -1;
- }
- memcpy(sizbuf + sizpos, f->data, f->datalen);
- len += f->datalen;
- pos = 0;
- while(len - pos > FRAME_SIZE * 2) {
- soundcard_writeframe((short *)(sizbuf + pos));
- pos += FRAME_SIZE * 2;
- }
- if (len - pos)
- memmove(sizbuf, sizbuf + pos, len - pos);
- sizpos = len - pos;
- return 0;
-}
-
-static struct ast_frame *oss_read(struct ast_channel *chan)
-{
- static struct ast_frame f;
- static char buf[FRAME_SIZE * 2 + AST_FRIENDLY_OFFSET];
- static int readpos = 0;
- int res;
-
-#if 0
- ast_log(LOG_DEBUG, "oss_read()\n");
-#endif
-
- f.frametype = AST_FRAME_NULL;
- f.subclass = 0;
- f.samples = 0;
- f.datalen = 0;
- f.data = NULL;
- f.offset = 0;
- f.src = type;
- f.mallocd = 0;
- f.delivery.tv_sec = 0;
- f.delivery.tv_usec = 0;
-
- res = soundcard_setinput(0);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set input mode\n");
- return NULL;
- }
- if (res > 0) {
- /* Theoretically shouldn't happen, but anyway, return a NULL frame */
- return &f;
- }
- res = read(sounddev, buf + AST_FRIENDLY_OFFSET + readpos, FRAME_SIZE * 2 - readpos);
- if (res < 0) {
- ast_log(LOG_WARNING, "Error reading from sound device (If you're running 'artsd' then kill it): %s\n", strerror(errno));
-#if 0
- CRASH;
-#endif
- return NULL;
- }
- readpos += res;
-
- if (readpos >= FRAME_SIZE * 2) {
- /* A real frame */
- readpos = 0;
- if (chan->_state != AST_STATE_UP) {
- /* Don't transmit unless it's up */
- return &f;
- }
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.samples = FRAME_SIZE;
- f.datalen = FRAME_SIZE * 2;
- f.data = buf + AST_FRIENDLY_OFFSET;
- f.offset = AST_FRIENDLY_OFFSET;
- f.src = type;
- f.mallocd = 0;
- f.delivery.tv_sec = 0;
- f.delivery.tv_usec = 0;
-#if 0
- { static int fd = -1;
- if (fd < 0)
- fd = open("output.raw", O_RDWR | O_TRUNC | O_CREAT);
- write(fd, f.data, f.datalen);
- }
-#endif
- }
- return &f;
-}
-
-static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct chan_oss_pvt *p = newchan->tech_pvt;
- p->owner = newchan;
- return 0;
-}
-
-static int oss_indicate(struct ast_channel *chan, int cond)
-{
- int res;
- switch(cond) {
- case AST_CONTROL_BUSY:
- res = 1;
- break;
- case AST_CONTROL_CONGESTION:
- res = 2;
- break;
- case AST_CONTROL_RINGING:
- res = 0;
- break;
- case -1:
- cursound = -1;
- return 0;
- default:
- ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n", cond, chan->name);
- return -1;
- }
- if (res > -1) {
- write(sndcmd[1], &res, sizeof(res));
- }
- return 0;
-}
-
-static struct ast_channel *oss_new(struct chan_oss_pvt *p, int state)
-{
- struct ast_channel *tmp;
- tmp = ast_channel_alloc(1);
- if (tmp) {
- tmp->tech = &oss_tech;
- snprintf(tmp->name, sizeof(tmp->name), "OSS/%s", DEV_DSP + 5);
- tmp->type = type;
- tmp->fds[0] = sounddev;
- tmp->nativeformats = AST_FORMAT_SLINEAR;
- tmp->readformat = AST_FORMAT_SLINEAR;
- tmp->writeformat = AST_FORMAT_SLINEAR;
- tmp->tech_pvt = p;
- if (!ast_strlen_zero(p->context))
- strncpy(tmp->context, p->context, sizeof(tmp->context)-1);
- if (!ast_strlen_zero(p->exten))
- strncpy(tmp->exten, p->exten, sizeof(tmp->exten)-1);
- if (!ast_strlen_zero(language))
- strncpy(tmp->language, language, sizeof(tmp->language)-1);
- p->owner = tmp;
- ast_setstate(tmp, state);
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- tmp = NULL;
- }
- }
- }
- return tmp;
-}
-
-static struct ast_channel *oss_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat = format;
- struct ast_channel *tmp;
- format &= AST_FORMAT_SLINEAR;
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of format '%d'\n", oldformat);
- return NULL;
- }
- if (oss.owner) {
- ast_log(LOG_NOTICE, "Already have a call on the OSS channel\n");
- *cause = AST_CAUSE_BUSY;
- return NULL;
- }
- tmp= oss_new(&oss, AST_STATE_DOWN);
- if (!tmp) {
- ast_log(LOG_WARNING, "Unable to create new OSS channel\n");
- }
- return tmp;
-}
-
-static int console_autoanswer(int fd, int argc, char *argv[])
-{
- if ((argc != 1) && (argc != 2))
- return RESULT_SHOWUSAGE;
- if (argc == 1) {
- ast_cli(fd, "Auto answer is %s.\n", autoanswer ? "on" : "off");
- return RESULT_SUCCESS;
- } else {
- if (!strcasecmp(argv[1], "on"))
- autoanswer = -1;
- else if (!strcasecmp(argv[1], "off"))
- autoanswer = 0;
- else
- return RESULT_SHOWUSAGE;
- }
- return RESULT_SUCCESS;
-}
-
-static char *autoanswer_complete(char *line, char *word, int pos, int state)
-{
-#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
- switch(state) {
- case 0:
- if (!ast_strlen_zero(word) && !strncasecmp(word, "on", MIN(strlen(word), 2)))
- return strdup("on");
- case 1:
- if (!ast_strlen_zero(word) && !strncasecmp(word, "off", MIN(strlen(word), 3)))
- return strdup("off");
- default:
- return NULL;
- }
- return NULL;
-}
-
-static char autoanswer_usage[] =
-"Usage: autoanswer [on|off]\n"
-" Enables or disables autoanswer feature. If used without\n"
-" argument, displays the current on/off status of autoanswer.\n"
-" The default value of autoanswer is in 'oss.conf'.\n";
-
-static int console_answer(int fd, int argc, char *argv[])
-{
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- if (!oss.owner) {
- ast_cli(fd, "No one is calling us\n");
- return RESULT_FAILURE;
- }
- hookstate = 1;
- cursound = -1;
- ast_queue_frame(oss.owner, &f);
- answer_sound();
- return RESULT_SUCCESS;
-}
-
-static char sendtext_usage[] =
-"Usage: send text <message>\n"
-" Sends a text message for display on the remote terminal.\n";
-
-static int console_sendtext(int fd, int argc, char *argv[])
-{
- int tmparg = 2;
- char text2send[256] = "";
- struct ast_frame f = { 0, };
- if (argc < 2)
- return RESULT_SHOWUSAGE;
- if (!oss.owner) {
- ast_cli(fd, "No one is calling us\n");
- return RESULT_FAILURE;
- }
- if (!ast_strlen_zero(text2send))
- ast_cli(fd, "Warning: message already waiting to be sent, overwriting\n");
- text2send[0] = '\0';
- while(tmparg < argc) {
- strncat(text2send, argv[tmparg++], sizeof(text2send) - strlen(text2send) - 1);
- strncat(text2send, " ", sizeof(text2send) - strlen(text2send) - 1);
- }
- if (!ast_strlen_zero(text2send)) {
- f.frametype = AST_FRAME_TEXT;
- f.subclass = 0;
- f.data = text2send;
- f.datalen = strlen(text2send);
- ast_queue_frame(oss.owner, &f);
- }
- return RESULT_SUCCESS;
-}
-
-static char answer_usage[] =
-"Usage: answer\n"
-" Answers an incoming call on the console (OSS) channel.\n";
-
-static int console_hangup(int fd, int argc, char *argv[])
-{
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- cursound = -1;
- if (!oss.owner && !hookstate) {
- ast_cli(fd, "No call to hangup up\n");
- return RESULT_FAILURE;
- }
- hookstate = 0;
- if (oss.owner) {
- ast_queue_hangup(oss.owner);
- }
- return RESULT_SUCCESS;
-}
-
-static int console_flash(int fd, int argc, char *argv[])
-{
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH };
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- cursound = -1;
- if (!oss.owner) {
- ast_cli(fd, "No call to flash\n");
- return RESULT_FAILURE;
- }
- hookstate = 0;
- if (oss.owner) {
- ast_queue_frame(oss.owner, &f);
- }
- return RESULT_SUCCESS;
-}
-
-static char hangup_usage[] =
-"Usage: hangup\n"
-" Hangs up any call currently placed on the console.\n";
-
-
-static char flash_usage[] =
-"Usage: flash\n"
-" Flashes the call currently placed on the console.\n";
-
-static int console_dial(int fd, int argc, char *argv[])
-{
- char tmp[256], *tmp2;
- char *mye, *myc;
- int x;
- struct ast_frame f = { AST_FRAME_DTMF, 0 };
- if ((argc != 1) && (argc != 2))
- return RESULT_SHOWUSAGE;
- if (oss.owner) {
- if (argc == 2) {
- for (x=0;x<strlen(argv[1]);x++) {
- f.subclass = argv[1][x];
- ast_queue_frame(oss.owner, &f);
- }
- } else {
- ast_cli(fd, "You're already in a call. You can use this only to dial digits until you hangup\n");
- return RESULT_FAILURE;
- }
- return RESULT_SUCCESS;
- }
- mye = exten;
- myc = context;
- if (argc == 2) {
- char *stringp=NULL;
- strncpy(tmp, argv[1], sizeof(tmp)-1);
- stringp=tmp;
- strsep(&stringp, "@");
- tmp2 = strsep(&stringp, "@");
- if (!ast_strlen_zero(tmp))
- mye = tmp;
- if (!ast_strlen_zero(tmp2))
- myc = tmp2;
- }
- if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
- strncpy(oss.exten, mye, sizeof(oss.exten)-1);
- strncpy(oss.context, myc, sizeof(oss.context)-1);
- hookstate = 1;
- oss_new(&oss, AST_STATE_RINGING);
- } else
- ast_cli(fd, "No such extension '%s' in context '%s'\n", mye, myc);
- return RESULT_SUCCESS;
-}
-
-static char dial_usage[] =
-"Usage: dial [extension[@context]]\n"
-" Dials a given extensison (and context if specified)\n";
-
-static int console_transfer(int fd, int argc, char *argv[])
-{
- char tmp[256];
- char *context;
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- if (oss.owner && ast_bridged_channel(oss.owner)) {
- strncpy(tmp, argv[1], sizeof(tmp) - 1);
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- } else
- context = oss.owner->context;
- if (ast_exists_extension(ast_bridged_channel(oss.owner), context, tmp, 1, ast_bridged_channel(oss.owner)->cid.cid_num)) {
- ast_cli(fd, "Whee, transferring %s to %s@%s.\n",
- ast_bridged_channel(oss.owner)->name, tmp, context);
- if (ast_async_goto(ast_bridged_channel(oss.owner), context, tmp, 1))
- ast_cli(fd, "Failed to transfer :(\n");
- } else {
- ast_cli(fd, "No such extension exists\n");
- }
- } else {
- ast_cli(fd, "There is no call to transfer\n");
- }
- return RESULT_SUCCESS;
-}
-
-static char transfer_usage[] =
-"Usage: transfer <extension>[@context]\n"
-" Transfers the currently connected call to the given extension (and\n"
-"context if specified)\n";
-
-static struct ast_cli_entry myclis[] = {
- { { "answer", NULL }, console_answer, "Answer an incoming console call", answer_usage },
- { { "hangup", NULL }, console_hangup, "Hangup a call on the console", hangup_usage },
- { { "flash", NULL }, console_flash, "Flash a call on the console", flash_usage },
- { { "dial", NULL }, console_dial, "Dial an extension on the console", dial_usage },
- { { "transfer", NULL }, console_transfer, "Transfer a call to a different extension", transfer_usage },
- { { "send", "text", NULL }, console_sendtext, "Send text to the remote device", sendtext_usage },
- { { "autoanswer", NULL }, console_autoanswer, "Sets/displays autoanswer", autoanswer_usage, autoanswer_complete }
-};
-
-int load_module()
-{
- int res;
- int x;
- struct ast_config *cfg;
- struct ast_variable *v;
- res = pipe(sndcmd);
- if (res) {
- ast_log(LOG_ERROR, "Unable to create pipe\n");
- return -1;
- }
- res = soundcard_init();
- if (res < 0) {
- if (option_verbose > 1) {
- ast_verbose(VERBOSE_PREFIX_2 "No sound card detected -- console channel will be unavailable\n");
- ast_verbose(VERBOSE_PREFIX_2 "Turn off OSS support by adding 'noload=chan_oss.so' in /etc/asterisk/modules.conf\n");
- }
- return 0;
- }
- if (!full_duplex)
- ast_log(LOG_WARNING, "XXX I don't work right with non-full duplex sound cards XXX\n");
- res = ast_channel_register(&oss_tech);
- if (res < 0) {
- ast_log(LOG_ERROR, "Unable to register channel class '%s'\n", type);
- return -1;
- }
- for (x=0;x<sizeof(myclis)/sizeof(struct ast_cli_entry); x++)
- ast_cli_register(myclis + x);
- if ((cfg = ast_config_load(config))) {
- v = ast_variable_browse(cfg, "general");
- while(v) {
- if (!strcasecmp(v->name, "autoanswer"))
- autoanswer = ast_true(v->value);
- else if (!strcasecmp(v->name, "silencesuppression"))
- silencesuppression = ast_true(v->value);
- else if (!strcasecmp(v->name, "silencethreshold"))
- silencethreshold = atoi(v->value);
- else if (!strcasecmp(v->name, "context"))
- strncpy(context, v->value, sizeof(context)-1);
- else if (!strcasecmp(v->name, "language"))
- strncpy(language, v->value, sizeof(language)-1);
- else if (!strcasecmp(v->name, "extension"))
- strncpy(exten, v->value, sizeof(exten)-1);
- else if (!strcasecmp(v->name, "playbackonly"))
- playbackonly = ast_true(v->value);
- v=v->next;
- }
- ast_config_destroy(cfg);
- }
- ast_pthread_create(&sthread, NULL, sound_thread, NULL);
- return 0;
-}
-
-
-
-int unload_module()
-{
- int x;
-
- ast_channel_unregister(&oss_tech);
- for (x=0;x<sizeof(myclis)/sizeof(struct ast_cli_entry); x++)
- ast_cli_unregister(myclis + x);
- close(sounddev);
- if (sndcmd[0] > 0) {
- close(sndcmd[0]);
- close(sndcmd[1]);
- }
- if (oss.owner)
- ast_softhangup(oss.owner, AST_SOFTHANGUP_APPUNLOAD);
- if (oss.owner)
- return -1;
- return 0;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_phone.c b/1.2-netsec/channels/chan_phone.c
deleted file mode 100644
index c1d552716..000000000
--- a/1.2-netsec/channels/chan_phone.c
+++ /dev/null
@@ -1,1414 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Generic Linux Telephony Interface driver
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <arpa/inet.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <linux/telephony.h>
-/* Still use some IXJ specific stuff */
-#include <linux/version.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-# include <linux/compiler.h>
-#endif
-#include <linux/ixjuser.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-#include "asterisk/callerid.h"
-#include "asterisk/causes.h"
-#include "DialTone.h"
-
-#ifdef QTI_PHONEJACK_TJ_PCI /* check for the newer quicknet driver v.3.1.0 which has this symbol */
-#define QNDRV_VER 310
-#else
-#define QNDRV_VER 100
-#endif
-
-#if QNDRV_VER > 100
-#ifdef __linux__
-#define IXJ_PHONE_RING_START(x) ioctl(p->fd, PHONE_RING_START, &x);
-#else /* FreeBSD and others */
-#define IXJ_PHONE_RING_START(x) ioctl(p->fd, PHONE_RING_START, x);
-#endif /* __linux__ */
-#else /* older driver */
-#define IXJ_PHONE_RING_START(x) ioctl(p->fd, PHONE_RING_START, &x);
-#endif
-
-#define DEFAULT_CALLER_ID "Unknown"
-#define PHONE_MAX_BUF 480
-#define DEFAULT_GAIN 0x100
-
-static const char desc[] = "Linux Telephony API Support";
-static const char type[] = "Phone";
-static const char tdesc[] = "Standard Linux Telephony API Driver";
-static const char config[] = "phone.conf";
-
-/* Default context for dialtone mode */
-static char context[AST_MAX_EXTENSION] = "default";
-
-/* Default language */
-static char language[MAX_LANGUAGE] = "";
-static int usecnt =0;
-
-static int echocancel = AEC_OFF;
-
-static int silencesupression = 0;
-
-static int prefformat = AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW;
-
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-/* Protect the interface list (of phone_pvt's) */
-AST_MUTEX_DEFINE_STATIC(iflock);
-
-/* Protect the monitoring thread, so only one process can kill or start it, and not
- when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(monlock);
-
-/* This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
-
-static int restart_monitor(void);
-
-/* The private structures of the Phone Jack channels are linked for
- selecting outgoing channels */
-
-#define MODE_DIALTONE 1
-#define MODE_IMMEDIATE 2
-#define MODE_FXO 3
-#define MODE_FXS 4
-
-static struct phone_pvt {
- int fd; /* Raw file descriptor for this device */
- struct ast_channel *owner; /* Channel we belong to, possibly NULL */
- int mode; /* Is this in the */
- int lastformat; /* Last output format */
- int lastinput; /* Last input format */
- int ministate; /* Miniature state, for dialtone mode */
- char dev[256]; /* Device name */
- struct phone_pvt *next; /* Next channel in list */
- struct ast_frame fr; /* Frame */
- char offset[AST_FRIENDLY_OFFSET];
- char buf[PHONE_MAX_BUF]; /* Static buffer for reading frames */
- int obuflen;
- int dialtone;
- int txgain, rxgain; /* gain control for playing, recording */
- /* 0x100 - 1.0, 0x200 - 2.0, 0x80 - 0.5 */
- int cpt; /* Call Progress Tone playing? */
- int silencesupression;
- char context[AST_MAX_EXTENSION];
- char obuf[PHONE_MAX_BUF * 2];
- char ext[AST_MAX_EXTENSION];
- char language[MAX_LANGUAGE];
- char cid_num[AST_MAX_EXTENSION];
- char cid_name[AST_MAX_EXTENSION];
-} *iflist = NULL;
-
-static char cid_num[AST_MAX_EXTENSION];
-static char cid_name[AST_MAX_EXTENSION];
-
-static struct ast_channel *phone_request(const char *type, int format, void *data, int *cause);
-static int phone_digit(struct ast_channel *ast, char digit);
-static int phone_call(struct ast_channel *ast, char *dest, int timeout);
-static int phone_hangup(struct ast_channel *ast);
-static int phone_answer(struct ast_channel *ast);
-static struct ast_frame *phone_read(struct ast_channel *ast);
-static int phone_write(struct ast_channel *ast, struct ast_frame *frame);
-static struct ast_frame *phone_exception(struct ast_channel *ast);
-static int phone_send_text(struct ast_channel *ast, const char *text);
-static int phone_fixup(struct ast_channel *old, struct ast_channel *new);
-
-static const struct ast_channel_tech phone_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW,
- .requester = phone_request,
- .send_digit = phone_digit,
- .call = phone_call,
- .hangup = phone_hangup,
- .answer = phone_answer,
- .read = phone_read,
- .write = phone_write,
- .exception = phone_exception,
- .fixup = phone_fixup
-};
-
-static struct ast_channel_tech phone_tech_fxs = {
- .type = type,
- .description = tdesc,
- .requester = phone_request,
- .send_digit = phone_digit,
- .call = phone_call,
- .hangup = phone_hangup,
- .answer = phone_answer,
- .read = phone_read,
- .write = phone_write,
- .exception = phone_exception,
- .write_video = phone_write,
- .send_text = phone_send_text,
- .fixup = phone_fixup
-};
-
-static struct ast_channel_tech *cur_tech;
-
-static int phone_fixup(struct ast_channel *old, struct ast_channel *new)
-{
- struct phone_pvt *pvt = old->tech_pvt;
- if (pvt && pvt->owner == old)
- pvt->owner = new;
- return 0;
-}
-
-static int phone_digit(struct ast_channel *ast, char digit)
-{
- struct phone_pvt *p;
- int outdigit;
- p = ast->tech_pvt;
- ast_log(LOG_NOTICE, "Dialed %c\n", digit);
- switch(digit) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- outdigit = digit - '0';
- break;
- case '*':
- outdigit = 11;
- break;
- case '#':
- outdigit = 12;
- break;
- case 'f': /*flash*/
- case 'F':
- ioctl(p->fd, IXJCTL_PSTN_SET_STATE, PSTN_ON_HOOK);
- usleep(320000);
- ioctl(p->fd, IXJCTL_PSTN_SET_STATE, PSTN_OFF_HOOK);
- p->lastformat = -1;
- return 0;
- default:
- ast_log(LOG_WARNING, "Unknown digit '%c'\n", digit);
- return -1;
- }
- ast_log(LOG_NOTICE, "Dialed %d\n", outdigit);
- ioctl(p->fd, PHONE_PLAY_TONE, outdigit);
- p->lastformat = -1;
- return 0;
-}
-
-static int phone_call(struct ast_channel *ast, char *dest, int timeout)
-{
- struct phone_pvt *p;
-
- PHONE_CID cid;
- time_t UtcTime;
- struct tm tm;
- int start;
-
- time(&UtcTime);
- localtime_r(&UtcTime,&tm);
-
- memset(&cid, 0, sizeof(PHONE_CID));
- if(&tm != NULL) {
- snprintf(cid.month, sizeof(cid.month), "%02d",(tm.tm_mon + 1));
- snprintf(cid.day, sizeof(cid.day), "%02d", tm.tm_mday);
- snprintf(cid.hour, sizeof(cid.hour), "%02d", tm.tm_hour);
- snprintf(cid.min, sizeof(cid.min), "%02d", tm.tm_min);
- }
- /* the standard format of ast->callerid is: "name" <number>, but not always complete */
- if (ast_strlen_zero(ast->cid.cid_name))
- strncpy(cid.name, DEFAULT_CALLER_ID, sizeof(cid.name) - 1);
- else
- strncpy(cid.name, ast->cid.cid_name, sizeof(cid.name) - 1);
-
- if (ast->cid.cid_num)
- strncpy(cid.number, ast->cid.cid_num, sizeof(cid.number) - 1);
-
- p = ast->tech_pvt;
-
- if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "phone_call called on %s, neither down nor reserved\n", ast->name);
- return -1;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Ringing %s on %s (%d)\n", dest, ast->name, ast->fds[0]);
-
- start = IXJ_PHONE_RING_START(cid);
- if (start == -1)
- return -1;
-
- if (p->mode == MODE_FXS) {
- char *digit = strchr(dest, '/');
- if (digit)
- {
- digit++;
- while (*digit)
- phone_digit(ast, *digit++);
- }
- }
-
- ast_setstate(ast, AST_STATE_RINGING);
- ast_queue_control(ast, AST_CONTROL_RINGING);
- return 0;
-}
-
-static int phone_hangup(struct ast_channel *ast)
-{
- struct phone_pvt *p;
- p = ast->tech_pvt;
- if (option_debug)
- ast_log(LOG_DEBUG, "phone_hangup(%s)\n", ast->name);
- if (!ast->tech_pvt) {
- ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
- return 0;
- }
- /* XXX Is there anything we can do to really hang up except stop recording? */
- ast_setstate(ast, AST_STATE_DOWN);
- if (ioctl(p->fd, PHONE_REC_STOP))
- ast_log(LOG_WARNING, "Failed to stop recording\n");
- if (ioctl(p->fd, PHONE_PLAY_STOP))
- ast_log(LOG_WARNING, "Failed to stop playing\n");
- if (ioctl(p->fd, PHONE_RING_STOP))
- ast_log(LOG_WARNING, "Failed to stop ringing\n");
- if (ioctl(p->fd, PHONE_CPT_STOP))
- ast_log(LOG_WARNING, "Failed to stop sounds\n");
-
- /* If it's an FXO, hang them up */
- if (p->mode == MODE_FXO) {
- if (ioctl(p->fd, PHONE_PSTN_SET_STATE, PSTN_ON_HOOK))
- ast_log(LOG_DEBUG, "ioctl(PHONE_PSTN_SET_STATE) failed on %s (%s)\n",ast->name, strerror(errno));
- }
-
- /* If they're off hook, give a busy signal */
- if (ioctl(p->fd, PHONE_HOOKSTATE)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Got hunghup, giving busy signal\n");
- ioctl(p->fd, PHONE_BUSY);
- p->cpt = 1;
- }
- p->lastformat = -1;
- p->lastinput = -1;
- p->ministate = 0;
- p->obuflen = 0;
- p->dialtone = 0;
- memset(p->ext, 0, sizeof(p->ext));
- ((struct phone_pvt *)(ast->tech_pvt))->owner = NULL;
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- if (usecnt < 0)
- ast_log(LOG_WARNING, "Usecnt < 0???\n");
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
- ast->tech_pvt = NULL;
- ast_setstate(ast, AST_STATE_DOWN);
- restart_monitor();
- return 0;
-}
-
-static int phone_setup(struct ast_channel *ast)
-{
- struct phone_pvt *p;
- p = ast->tech_pvt;
- ioctl(p->fd, PHONE_CPT_STOP);
- /* Nothing to answering really, just start recording */
- if (ast->rawreadformat == AST_FORMAT_G723_1) {
- /* Prefer g723 */
- ioctl(p->fd, PHONE_REC_STOP);
- if (p->lastinput != AST_FORMAT_G723_1) {
- p->lastinput = AST_FORMAT_G723_1;
- if (ioctl(p->fd, PHONE_REC_CODEC, G723_63)) {
- ast_log(LOG_WARNING, "Failed to set codec to g723.1\n");
- return -1;
- }
- }
- } else if (ast->rawreadformat == AST_FORMAT_SLINEAR) {
- ioctl(p->fd, PHONE_REC_STOP);
- if (p->lastinput != AST_FORMAT_SLINEAR) {
- p->lastinput = AST_FORMAT_SLINEAR;
- if (ioctl(p->fd, PHONE_REC_CODEC, LINEAR16)) {
- ast_log(LOG_WARNING, "Failed to set codec to signed linear 16\n");
- return -1;
- }
- }
- } else if (ast->rawreadformat == AST_FORMAT_ULAW) {
- ioctl(p->fd, PHONE_REC_STOP);
- if (p->lastinput != AST_FORMAT_ULAW) {
- p->lastinput = AST_FORMAT_ULAW;
- if (ioctl(p->fd, PHONE_REC_CODEC, ULAW)) {
- ast_log(LOG_WARNING, "Failed to set codec to uLaw\n");
- return -1;
- }
- }
- } else if (p->mode == MODE_FXS) {
- ioctl(p->fd, PHONE_REC_STOP);
- if (p->lastinput != ast->rawreadformat) {
- p->lastinput = ast->rawreadformat;
- if (ioctl(p->fd, PHONE_REC_CODEC, ast->rawreadformat)) {
- ast_log(LOG_WARNING, "Failed to set codec to %d\n",
- ast->rawreadformat);
- return -1;
- }
- }
- } else {
- ast_log(LOG_WARNING, "Can't do format %s\n", ast_getformatname(ast->rawreadformat));
- return -1;
- }
- if (ioctl(p->fd, PHONE_REC_START)) {
- ast_log(LOG_WARNING, "Failed to start recording\n");
- return -1;
- }
- /* set the DTMF times (the default is too short) */
- ioctl(p->fd, PHONE_SET_TONE_ON_TIME, 300);
- ioctl(p->fd, PHONE_SET_TONE_OFF_TIME, 200);
- return 0;
-}
-
-static int phone_answer(struct ast_channel *ast)
-{
- struct phone_pvt *p;
- p = ast->tech_pvt;
- /* In case it's a LineJack, take it off hook */
- if (p->mode == MODE_FXO) {
- if (ioctl(p->fd, PHONE_PSTN_SET_STATE, PSTN_OFF_HOOK))
- ast_log(LOG_DEBUG, "ioctl(PHONE_PSTN_SET_STATE) failed on %s (%s)\n", ast->name, strerror(errno));
- else
- ast_log(LOG_DEBUG, "Took linejack off hook\n");
- }
- phone_setup(ast);
- if (option_debug)
- ast_log(LOG_DEBUG, "phone_answer(%s)\n", ast->name);
- ast->rings = 0;
- ast_setstate(ast, AST_STATE_UP);
- return 0;
-}
-
-#if 0
-static char phone_2digit(char c)
-{
- if (c == 12)
- return '#';
- else if (c == 11)
- return '*';
- else if ((c < 10) && (c >= 0))
- return '0' + c - 1;
- else
- return '?';
-}
-#endif
-
-static struct ast_frame *phone_exception(struct ast_channel *ast)
-{
- int res;
- union telephony_exception phonee;
- struct phone_pvt *p = ast->tech_pvt;
- char digit;
-
- /* Some nice norms */
- p->fr.datalen = 0;
- p->fr.samples = 0;
- p->fr.data = NULL;
- p->fr.src = type;
- p->fr.offset = 0;
- p->fr.mallocd=0;
- p->fr.delivery = ast_tv(0,0);
-
- phonee.bytes = ioctl(p->fd, PHONE_EXCEPTION);
- if (phonee.bits.dtmf_ready) {
- if (option_debug)
- ast_log(LOG_DEBUG, "phone_exception(): DTMF\n");
-
- /* We've got a digit -- Just handle this nicely and easily */
- digit = ioctl(p->fd, PHONE_GET_DTMF_ASCII);
- p->fr.subclass = digit;
- p->fr.frametype = AST_FRAME_DTMF;
- return &p->fr;
- }
- if (phonee.bits.hookstate) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Hookstate changed\n");
- res = ioctl(p->fd, PHONE_HOOKSTATE);
- /* See if we've gone on hook, if so, notify by returning NULL */
- if (option_debug)
- ast_log(LOG_DEBUG, "New hookstate: %d\n", res);
- if (!res && (p->mode != MODE_FXO))
- return NULL;
- else {
- if (ast->_state == AST_STATE_RINGING) {
- /* They've picked up the phone */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_ANSWER;
- phone_setup(ast);
- ast_setstate(ast, AST_STATE_UP);
- return &p->fr;
- } else
- ast_log(LOG_WARNING, "Got off hook in weird state %d\n", ast->_state);
- }
- }
-#if 1
- if (phonee.bits.pstn_ring)
- ast_verbose("Unit is ringing\n");
- if (phonee.bits.caller_id) {
- ast_verbose("We have caller ID\n");
- }
- if (phonee.bits.pstn_wink)
- ast_verbose("Detected Wink\n");
-#endif
- /* Strange -- nothing there.. */
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- return &p->fr;
-}
-
-static struct ast_frame *phone_read(struct ast_channel *ast)
-{
- int res;
- struct phone_pvt *p = ast->tech_pvt;
-
-
- /* Some nice norms */
- p->fr.datalen = 0;
- p->fr.samples = 0;
- p->fr.data = NULL;
- p->fr.src = type;
- p->fr.offset = 0;
- p->fr.mallocd=0;
- p->fr.delivery = ast_tv(0,0);
-
- /* Try to read some data... */
- CHECK_BLOCKING(ast);
- res = read(p->fd, p->buf, PHONE_MAX_BUF);
- ast_clear_flag(ast, AST_FLAG_BLOCKING);
- if (res < 0) {
-#if 0
- if (errno == EAGAIN) {
- ast_log(LOG_WARNING, "Null frame received\n");
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- return &p->fr;
- }
-#endif
- ast_log(LOG_WARNING, "Error reading: %s\n", strerror(errno));
- return NULL;
- }
- p->fr.data = p->buf;
- if (p->mode != MODE_FXS)
- switch(p->buf[0] & 0x3) {
- case '0':
- case '1':
- /* Normal */
- break;
- case '2':
- case '3':
- /* VAD/CNG, only send two words */
- res = 4;
- break;
- }
- p->fr.samples = 240;
- p->fr.datalen = res;
- p->fr.frametype = p->lastinput <= AST_FORMAT_MAX_AUDIO ?
- AST_FRAME_VOICE :
- p->lastinput <= AST_FORMAT_PNG ? AST_FRAME_IMAGE
- : AST_FRAME_VIDEO;
- p->fr.subclass = p->lastinput;
- p->fr.offset = AST_FRIENDLY_OFFSET;
- /* Byteswap from little-endian to native-endian */
- if (p->fr.subclass == AST_FORMAT_SLINEAR)
- ast_frame_byteswap_le(&p->fr);
- return &p->fr;
-}
-
-static int phone_write_buf(struct phone_pvt *p, const char *buf, int len, int frlen, int swap)
-{
- int res;
- /* Store as much of the buffer as we can, then write fixed frames */
- int space = sizeof(p->obuf) - p->obuflen;
- /* Make sure we have enough buffer space to store the frame */
- if (space < len)
- len = space;
- if (swap)
- ast_swapcopy_samples(p->obuf+p->obuflen, buf, len/2);
- else
- memcpy(p->obuf + p->obuflen, buf, len);
- p->obuflen += len;
- while(p->obuflen > frlen) {
- res = write(p->fd, p->obuf, frlen);
- if (res != frlen) {
- if (res < 1) {
-/*
- * Card is in non-blocking mode now and it works well now, but there are
- * lot of messages like this. So, this message is temporarily disabled.
- */
- return 0;
- } else {
- ast_log(LOG_WARNING, "Only wrote %d of %d bytes\n", res, frlen);
- }
- }
- p->obuflen -= frlen;
- /* Move memory if necessary */
- if (p->obuflen)
- memmove(p->obuf, p->obuf + frlen, p->obuflen);
- }
- return len;
-}
-
-static int phone_send_text(struct ast_channel *ast, const char *text)
-{
- int length = strlen(text);
- return phone_write_buf(ast->tech_pvt, text, length, length, 0) ==
- length ? 0 : -1;
-}
-
-static int phone_write(struct ast_channel *ast, struct ast_frame *frame)
-{
- struct phone_pvt *p = ast->tech_pvt;
- int res;
- int maxfr=0;
- char *pos;
- int sofar;
- int expected;
- int codecset = 0;
- char tmpbuf[4];
- /* Write a frame of (presumably voice) data */
- if (frame->frametype != AST_FRAME_VOICE && p->mode != MODE_FXS) {
- if (frame->frametype != AST_FRAME_IMAGE)
- ast_log(LOG_WARNING, "Don't know what to do with frame type '%d'\n", frame->frametype);
- return 0;
- }
- if (!(frame->subclass &
- (AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW)) &&
- p->mode != MODE_FXS) {
- ast_log(LOG_WARNING, "Cannot handle frames in %d format\n", frame->subclass);
- return -1;
- }
-#if 0
- /* If we're not in up mode, go into up mode now */
- if (ast->_state != AST_STATE_UP) {
- ast_setstate(ast, AST_STATE_UP);
- phone_setup(ast);
- }
-#else
- if (ast->_state != AST_STATE_UP) {
- /* Don't try tos end audio on-hook */
- return 0;
- }
-#endif
- if (frame->subclass == AST_FORMAT_G723_1) {
- if (p->lastformat != AST_FORMAT_G723_1) {
- ioctl(p->fd, PHONE_PLAY_STOP);
- ioctl(p->fd, PHONE_REC_STOP);
- if (ioctl(p->fd, PHONE_PLAY_CODEC, G723_63)) {
- ast_log(LOG_WARNING, "Unable to set G723.1 mode\n");
- return -1;
- }
- if (ioctl(p->fd, PHONE_REC_CODEC, G723_63)) {
- ast_log(LOG_WARNING, "Unable to set G723.1 mode\n");
- return -1;
- }
- p->lastformat = AST_FORMAT_G723_1;
- p->lastinput = AST_FORMAT_G723_1;
- /* Reset output buffer */
- p->obuflen = 0;
- codecset = 1;
- }
- if (frame->datalen > 24) {
- ast_log(LOG_WARNING, "Frame size too large for G.723.1 (%d bytes)\n", frame->datalen);
- return -1;
- }
- maxfr = 24;
- } else if (frame->subclass == AST_FORMAT_SLINEAR) {
- if (p->lastformat != AST_FORMAT_SLINEAR) {
- ioctl(p->fd, PHONE_PLAY_STOP);
- ioctl(p->fd, PHONE_REC_STOP);
- if (ioctl(p->fd, PHONE_PLAY_CODEC, LINEAR16)) {
- ast_log(LOG_WARNING, "Unable to set 16-bit linear mode\n");
- return -1;
- }
- if (ioctl(p->fd, PHONE_REC_CODEC, LINEAR16)) {
- ast_log(LOG_WARNING, "Unable to set 16-bit linear mode\n");
- return -1;
- }
- p->lastformat = AST_FORMAT_SLINEAR;
- p->lastinput = AST_FORMAT_SLINEAR;
- codecset = 1;
- /* Reset output buffer */
- p->obuflen = 0;
- }
- maxfr = 480;
- } else if (frame->subclass == AST_FORMAT_ULAW) {
- if (p->lastformat != AST_FORMAT_ULAW) {
- ioctl(p->fd, PHONE_PLAY_STOP);
- ioctl(p->fd, PHONE_REC_STOP);
- if (ioctl(p->fd, PHONE_PLAY_CODEC, ULAW)) {
- ast_log(LOG_WARNING, "Unable to set uLaw mode\n");
- return -1;
- }
- if (ioctl(p->fd, PHONE_REC_CODEC, ULAW)) {
- ast_log(LOG_WARNING, "Unable to set uLaw mode\n");
- return -1;
- }
- p->lastformat = AST_FORMAT_ULAW;
- p->lastinput = AST_FORMAT_ULAW;
- codecset = 1;
- /* Reset output buffer */
- p->obuflen = 0;
- }
- maxfr = 240;
- } else {
- if (p->lastformat != frame->subclass) {
- ioctl(p->fd, PHONE_PLAY_STOP);
- ioctl(p->fd, PHONE_REC_STOP);
- if (ioctl(p->fd, PHONE_PLAY_CODEC, frame->subclass)) {
- ast_log(LOG_WARNING, "Unable to set %d mode\n",
- frame->subclass);
- return -1;
- }
- if (ioctl(p->fd, PHONE_REC_CODEC, frame->subclass)) {
- ast_log(LOG_WARNING, "Unable to set %d mode\n",
- frame->subclass);
- return -1;
- }
- p->lastformat = frame->subclass;
- p->lastinput = frame->subclass;
- codecset = 1;
- /* Reset output buffer */
- p->obuflen = 0;
- }
- maxfr = 480;
- }
- if (codecset) {
- ioctl(p->fd, PHONE_REC_DEPTH, 3);
- ioctl(p->fd, PHONE_PLAY_DEPTH, 3);
- if (ioctl(p->fd, PHONE_PLAY_START)) {
- ast_log(LOG_WARNING, "Failed to start playback\n");
- return -1;
- }
- if (ioctl(p->fd, PHONE_REC_START)) {
- ast_log(LOG_WARNING, "Failed to start recording\n");
- return -1;
- }
- }
- /* If we get here, we have a frame of Appropriate data */
- sofar = 0;
- pos = frame->data;
- while(sofar < frame->datalen) {
- /* Write in no more than maxfr sized frames */
- expected = frame->datalen - sofar;
- if (maxfr < expected)
- expected = maxfr;
- /* XXX Internet Phone Jack does not handle the 4-byte VAD frame properly! XXX
- we have to pad it to 24 bytes still. */
- if (frame->datalen == 4) {
- if (p->silencesupression) {
- memset(tmpbuf + 4, 0, sizeof(tmpbuf) - 4);
- memcpy(tmpbuf, frame->data, 4);
- expected = 24;
- res = phone_write_buf(p, tmpbuf, expected, maxfr, 0);
- }
- res = 4;
- expected=4;
- } else {
- int swap = 0;
-#if __BYTE_ORDER == __BIG_ENDIAN
- if (frame->subclass == AST_FORMAT_SLINEAR)
- swap = 1; /* Swap big-endian samples to little-endian as we copy */
-#endif
- res = phone_write_buf(p, pos, expected, maxfr, swap);
- }
- if (res != expected) {
- if ((errno != EAGAIN) && (errno != EINTR)) {
- if (res < 0)
- ast_log(LOG_WARNING, "Write returned error (%s)\n", strerror(errno));
- /*
- * Card is in non-blocking mode now and it works well now, but there are
- * lot of messages like this. So, this message is temporarily disabled.
- */
-#if 0
- else
- ast_log(LOG_WARNING, "Only wrote %d of %d bytes\n", res, frame->datalen);
-#endif
- return -1;
- } else /* Pretend it worked */
- res = expected;
- }
- sofar += res;
- pos += res;
- }
- return 0;
-}
-
-static struct ast_channel *phone_new(struct phone_pvt *i, int state, char *context)
-{
- struct ast_channel *tmp;
- struct phone_codec_data codec;
- tmp = ast_channel_alloc(1);
- if (tmp) {
- tmp->tech = cur_tech;
- snprintf(tmp->name, sizeof(tmp->name), "Phone/%s", i->dev + 5);
- tmp->type = type;
- tmp->fds[0] = i->fd;
- /* XXX Switching formats silently causes kernel panics XXX */
- if (i->mode == MODE_FXS &&
- ioctl(i->fd, PHONE_QUERY_CODEC, &codec) == 0) {
- if (codec.type == LINEAR16)
- tmp->nativeformats =
- tmp->rawreadformat =
- tmp->rawwriteformat =
- AST_FORMAT_SLINEAR;
- else {
- tmp->nativeformats =
- tmp->rawreadformat =
- tmp->rawwriteformat =
- prefformat & ~AST_FORMAT_SLINEAR;
- }
- }
- else {
- tmp->nativeformats = prefformat;
- tmp->rawreadformat = prefformat;
- tmp->rawwriteformat = prefformat;
- }
- ast_setstate(tmp, state);
- if (state == AST_STATE_RING)
- tmp->rings = 1;
- tmp->tech_pvt = i;
- strncpy(tmp->context, context, sizeof(tmp->context)-1);
- if (!ast_strlen_zero(i->ext))
- strncpy(tmp->exten, i->ext, sizeof(tmp->exten)-1);
- else
- strncpy(tmp->exten, "s", sizeof(tmp->exten) - 1);
- if (!ast_strlen_zero(i->language))
- strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
- if (!ast_strlen_zero(i->cid_num))
- tmp->cid.cid_num = strdup(i->cid_num);
- if (!ast_strlen_zero(i->cid_name))
- tmp->cid.cid_name = strdup(i->cid_name);
- i->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (state != AST_STATE_DOWN) {
- if (state == AST_STATE_RING) {
- ioctl(tmp->fds[0], PHONE_RINGBACK);
- i->cpt = 1;
- }
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- }
- }
- } else
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- return tmp;
-}
-
-static void phone_mini_packet(struct phone_pvt *i)
-{
- int res;
- char buf[1024];
- /* Ignore stuff we read... */
- res = read(i->fd, buf, sizeof(buf));
- if (res < 1) {
- ast_log(LOG_WARNING, "Read returned %d: %s\n", res, strerror(errno));
- return;
- }
-}
-
-static void phone_check_exception(struct phone_pvt *i)
-{
- int offhook=0;
- char digit[2] = {0 , 0};
- union telephony_exception phonee;
- /* XXX Do something XXX */
-#if 0
- ast_log(LOG_DEBUG, "Exception!\n");
-#endif
- phonee.bytes = ioctl(i->fd, PHONE_EXCEPTION);
- if (phonee.bits.dtmf_ready) {
- digit[0] = ioctl(i->fd, PHONE_GET_DTMF_ASCII);
- if (i->mode == MODE_DIALTONE || i->mode == MODE_FXS) {
- ioctl(i->fd, PHONE_PLAY_STOP);
- ioctl(i->fd, PHONE_REC_STOP);
- ioctl(i->fd, PHONE_CPT_STOP);
- i->dialtone = 0;
- if (strlen(i->ext) < AST_MAX_EXTENSION - 1)
- strncat(i->ext, digit, sizeof(i->ext) - strlen(i->ext) - 1);
- if ((i->mode != MODE_FXS ||
- !(phonee.bytes = ioctl(i->fd, PHONE_EXCEPTION)) ||
- !phonee.bits.dtmf_ready) &&
- ast_exists_extension(NULL, i->context, i->ext, 1, i->cid_num)) {
- /* It's a valid extension in its context, get moving! */
- phone_new(i, AST_STATE_RING, i->context);
- /* No need to restart monitor, we are the monitor */
- } else if (!ast_canmatch_extension(NULL, i->context, i->ext, 1, i->cid_num)) {
- /* There is nothing in the specified extension that can match anymore.
- Try the default */
- if (ast_exists_extension(NULL, "default", i->ext, 1, i->cid_num)) {
- /* Check the default, too... */
- phone_new(i, AST_STATE_RING, "default");
- /* XXX This should probably be justified better XXX */
- } else if (!ast_canmatch_extension(NULL, "default", i->ext, 1, i->cid_num)) {
- /* It's not a valid extension, give a busy signal */
- if (option_debug)
- ast_log(LOG_DEBUG, "%s can't match anything in %s or default\n", i->ext, i->context);
- ioctl(i->fd, PHONE_BUSY);
- i->cpt = 1;
- }
- }
-#if 0
- ast_verbose("Extension is %s\n", i->ext);
-#endif
- }
- }
- if (phonee.bits.hookstate) {
- offhook = ioctl(i->fd, PHONE_HOOKSTATE);
- if (offhook) {
- if (i->mode == MODE_IMMEDIATE) {
- phone_new(i, AST_STATE_RING, i->context);
- } else if (i->mode == MODE_DIALTONE) {
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- /* Reset the extension */
- i->ext[0] = '\0';
- /* Play the dialtone */
- i->dialtone++;
- ioctl(i->fd, PHONE_PLAY_STOP);
- ioctl(i->fd, PHONE_PLAY_CODEC, ULAW);
- ioctl(i->fd, PHONE_PLAY_START);
- i->lastformat = -1;
- }
- } else {
- if (i->dialtone) {
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- }
- memset(i->ext, 0, sizeof(i->ext));
- if (i->cpt)
- {
- ioctl(i->fd, PHONE_CPT_STOP);
- i->cpt = 0;
- }
- ioctl(i->fd, PHONE_PLAY_STOP);
- ioctl(i->fd, PHONE_REC_STOP);
- i->dialtone = 0;
- i->lastformat = -1;
- }
- }
- if (phonee.bits.pstn_ring) {
- ast_verbose("Unit is ringing\n");
- phone_new(i, AST_STATE_RING, i->context);
- }
- if (phonee.bits.caller_id)
- ast_verbose("We have caller ID\n");
-
-
-}
-
-static void *do_monitor(void *data)
-{
- fd_set rfds, efds;
- int n, res;
- struct phone_pvt *i;
- int tonepos = 0;
- /* The tone we're playing this round */
- struct timeval tv = {0,0};
- int dotone;
- /* This thread monitors all the frame relay interfaces which are not yet in use
- (and thus do not have a separate thread) indefinitely */
- /* From here on out, we die whenever asked */
- if (pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)) {
- ast_log(LOG_WARNING, "Unable to set cancel type to asynchronous\n");
- return NULL;
- }
- for(;;) {
- /* Don't let anybody kill us right away. Nobody should lock the interface list
- and wait for the monitor list, but the other way around is okay. */
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_ERROR, "Unable to grab monitor lock\n");
- return NULL;
- }
- /* Lock the interface list */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_ERROR, "Unable to grab interface lock\n");
- ast_mutex_unlock(&monlock);
- return NULL;
- }
- /* Build the stuff we're going to select on, that is the socket of every
- phone_pvt that does not have an associated owner channel */
- n = -1;
- FD_ZERO(&rfds);
- FD_ZERO(&efds);
- i = iflist;
- dotone = 0;
- while(i) {
- if (FD_ISSET(i->fd, &rfds))
- ast_log(LOG_WARNING, "Descriptor %d appears twice (%s)?\n", i->fd, i->dev);
- if (!i->owner) {
- /* This needs to be watched, as it lacks an owner */
- FD_SET(i->fd, &rfds);
- FD_SET(i->fd, &efds);
- if (i->fd > n)
- n = i->fd;
- if (i->dialtone) {
- /* Remember we're going to have to come back and play
- more dialtones */
- if (ast_tvzero(tv)) {
- /* If we're due for a dialtone, play one */
- if (write(i->fd, DialTone + tonepos, 240) != 240)
- ast_log(LOG_WARNING, "Dial tone write error\n");
- }
- dotone++;
- }
- }
-
- i = i->next;
- }
- /* Okay, now that we know what to do, release the interface lock */
- ast_mutex_unlock(&iflock);
-
- /* And from now on, we're okay to be killed, so release the monitor lock as well */
- ast_mutex_unlock(&monlock);
-
- /* Wait indefinitely for something to happen */
- if (dotone) {
- /* If we're ready to recycle the time, set it to 30 ms */
- tonepos += 240;
- if (tonepos >= sizeof(DialTone))
- tonepos = 0;
- if (ast_tvzero(tv)) {
- tv = ast_tv(30000, 0);
- }
- res = ast_select(n + 1, &rfds, NULL, &efds, &tv);
- } else {
- res = ast_select(n + 1, &rfds, NULL, &efds, NULL);
- tv = ast_tv(0,0);
- tonepos = 0;
- }
- /* Okay, select has finished. Let's see what happened. */
- if (res < 0) {
- ast_log(LOG_WARNING, "select return %d: %s\n", res, strerror(errno));
- continue;
- }
- /* If there are no fd's changed, just continue, it's probably time
- to play some more dialtones */
- if (!res)
- continue;
- /* Alright, lock the interface list again, and let's look and see what has
- happened */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- continue;
- }
-
- i = iflist;
- for(; i; i=i->next) {
- if (FD_ISSET(i->fd, &rfds)) {
- if (i->owner) {
- continue;
- }
- phone_mini_packet(i);
- }
- if (FD_ISSET(i->fd, &efds)) {
- if (i->owner) {
- continue;
- }
- phone_check_exception(i);
- }
- }
- ast_mutex_unlock(&iflock);
- }
- /* Never reached */
- return NULL;
-
-}
-
-static int restart_monitor()
-{
- /* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == AST_PTHREADT_STOP)
- return 0;
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_WARNING, "Unable to lock monitor\n");
- return -1;
- }
- if (monitor_thread == pthread_self()) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- return -1;
- }
- if (monitor_thread != AST_PTHREADT_NULL) {
- if (ast_mutex_lock(&iflock)) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- return -1;
- }
- pthread_cancel(monitor_thread);
-#if 0
- pthread_join(monitor_thread, NULL);
-#endif
- ast_mutex_unlock(&iflock);
- }
- /* Start a new monitor */
- if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- return -1;
- }
- ast_mutex_unlock(&monlock);
- return 0;
-}
-
-static struct phone_pvt *mkif(char *iface, int mode, int txgain, int rxgain)
-{
- /* Make a phone_pvt structure for this interface */
- struct phone_pvt *tmp;
- int flags;
-
- tmp = malloc(sizeof(struct phone_pvt));
- if (tmp) {
- tmp->fd = open(iface, O_RDWR);
- if (tmp->fd < 0) {
- ast_log(LOG_WARNING, "Unable to open '%s'\n", iface);
- free(tmp);
- return NULL;
- }
- if (mode == MODE_FXO) {
- if (ioctl(tmp->fd, IXJCTL_PORT, PORT_PSTN))
- ast_log(LOG_DEBUG, "Unable to set port to PSTN\n");
- } else {
- if (ioctl(tmp->fd, IXJCTL_PORT, PORT_POTS))
- if (mode != MODE_FXS)
- ast_log(LOG_DEBUG, "Unable to set port to POTS\n");
- }
- ioctl(tmp->fd, PHONE_PLAY_STOP);
- ioctl(tmp->fd, PHONE_REC_STOP);
- ioctl(tmp->fd, PHONE_RING_STOP);
- ioctl(tmp->fd, PHONE_CPT_STOP);
- if (ioctl(tmp->fd, PHONE_PSTN_SET_STATE, PSTN_ON_HOOK))
- ast_log(LOG_DEBUG, "ioctl(PHONE_PSTN_SET_STATE) failed on %s (%s)\n",iface, strerror(errno));
- if (echocancel != AEC_OFF)
- ioctl(tmp->fd, IXJCTL_AEC_START, echocancel);
- if (silencesupression)
- tmp->silencesupression = 1;
-#ifdef PHONE_VAD
- ioctl(tmp->fd, PHONE_VAD, tmp->silencesupression);
-#endif
- tmp->mode = mode;
- flags = fcntl(tmp->fd, F_GETFL);
- fcntl(tmp->fd, F_SETFL, flags | O_NONBLOCK);
- tmp->owner = NULL;
- tmp->lastformat = -1;
- tmp->lastinput = -1;
- tmp->ministate = 0;
- memset(tmp->ext, 0, sizeof(tmp->ext));
- strncpy(tmp->language, language, sizeof(tmp->language)-1);
- strncpy(tmp->dev, iface, sizeof(tmp->dev)-1);
- strncpy(tmp->context, context, sizeof(tmp->context)-1);
- tmp->next = NULL;
- tmp->obuflen = 0;
- tmp->dialtone = 0;
- tmp->cpt = 0;
- strncpy(tmp->cid_num, cid_num, sizeof(tmp->cid_num)-1);
- strncpy(tmp->cid_name, cid_name, sizeof(tmp->cid_name)-1);
- tmp->txgain = txgain;
- ioctl(tmp->fd, PHONE_PLAY_VOLUME, tmp->txgain);
- tmp->rxgain = rxgain;
- ioctl(tmp->fd, PHONE_REC_VOLUME, tmp->rxgain);
- }
- return tmp;
-}
-
-static struct ast_channel *phone_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- struct phone_pvt *p;
- struct ast_channel *tmp = NULL;
- char *name = data;
-
- /* Search for an unowned channel */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_ERROR, "Unable to lock interface list???\n");
- return NULL;
- }
- p = iflist;
- while(p) {
- if (p->mode == MODE_FXS ||
- format & (AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW)) {
- size_t length = strlen(p->dev + 5);
- if (strncmp(name, p->dev + 5, length) == 0 &&
- !isalnum(name[length])) {
- if (!p->owner) {
- tmp = phone_new(p, AST_STATE_DOWN, p->context);
- break;
- } else
- *cause = AST_CAUSE_BUSY;
- }
- }
- p = p->next;
- }
- ast_mutex_unlock(&iflock);
- restart_monitor();
- if (tmp == NULL) {
- oldformat = format;
- format &= (AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW);
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", oldformat);
- return NULL;
- }
- }
- return tmp;
-}
-
-/* parse gain value from config file */
-static int parse_gain_value(char *gain_type, char *value)
-{
- float gain;
-
- /* try to scan number */
- if (sscanf(value, "%f", &gain) != 1)
- {
- ast_log(LOG_ERROR, "Invalid %s value '%s' in '%s' config\n",
- value, gain_type, config);
- return DEFAULT_GAIN;
- }
-
- /* multiplicate gain by 1.0 gain value */
- gain = gain * (float)DEFAULT_GAIN;
-
- /* percentage? */
- if (value[strlen(value) - 1] == '%')
- return (int)(gain / (float)100);
-
- return (int)gain;
-}
-
-static int __unload_module(void)
-{
- struct phone_pvt *p, *pl;
- /* First, take us out of the channel loop */
- ast_channel_unregister(cur_tech);
- if (!ast_mutex_lock(&iflock)) {
- /* Hangup all interfaces if they have an owner */
- p = iflist;
- while(p) {
- if (p->owner)
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- p = p->next;
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread > AST_PTHREADT_NULL) {
- pthread_cancel(monitor_thread);
- pthread_join(monitor_thread, NULL);
- }
- monitor_thread = AST_PTHREADT_STOP;
- ast_mutex_unlock(&monlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-
- if (!ast_mutex_lock(&iflock)) {
- /* Destroy all the interfaces and free their memory */
- p = iflist;
- while(p) {
- /* Close the socket, assuming it's real */
- if (p->fd > -1)
- close(p->fd);
- pl = p;
- p = p->next;
- /* Free associated memory */
- free(pl);
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-
- return 0;
-}
-
-int unload_module(void)
-{
- return __unload_module();
-}
-
-int load_module()
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- struct phone_pvt *tmp;
- int mode = MODE_IMMEDIATE;
- int txgain = DEFAULT_GAIN, rxgain = DEFAULT_GAIN; /* default gain 1.0 */
- cfg = ast_config_load(config);
-
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_ERROR, "Unable to load config %s\n", config);
- return -1;
- }
- if (ast_mutex_lock(&iflock)) {
- /* It's a little silly to lock it, but we mind as well just to be sure */
- ast_log(LOG_ERROR, "Unable to lock interface list???\n");
- return -1;
- }
- v = ast_variable_browse(cfg, "interfaces");
- while(v) {
- /* Create the interface list */
- if (!strcasecmp(v->name, "device")) {
- tmp = mkif(v->value, mode, txgain, rxgain);
- if (tmp) {
- tmp->next = iflist;
- iflist = tmp;
-
- } else {
- ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- __unload_module();
- return -1;
- }
- } else if (!strcasecmp(v->name, "silencesupression")) {
- silencesupression = ast_true(v->value);
- } else if (!strcasecmp(v->name, "language")) {
- strncpy(language, v->value, sizeof(language)-1);
- } else if (!strcasecmp(v->name, "callerid")) {
- ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
- } else if (!strcasecmp(v->name, "mode")) {
- if (!strncasecmp(v->value, "di", 2))
- mode = MODE_DIALTONE;
- else if (!strncasecmp(v->value, "im", 2))
- mode = MODE_IMMEDIATE;
- else if (!strncasecmp(v->value, "fxs", 3)) {
- mode = MODE_FXS;
- prefformat = 0x01ff0000; /* All non-voice */
- }
- else if (!strncasecmp(v->value, "fx", 2))
- mode = MODE_FXO;
- else
- ast_log(LOG_WARNING, "Unknown mode: %s\n", v->value);
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(context, v->value, sizeof(context)-1);
- } else if (!strcasecmp(v->name, "format")) {
- if (!strcasecmp(v->value, "g723.1")) {
- prefformat = AST_FORMAT_G723_1;
- } else if (!strcasecmp(v->value, "slinear")) {
- if (mode == MODE_FXS)
- prefformat |= AST_FORMAT_SLINEAR;
- else prefformat = AST_FORMAT_SLINEAR;
- } else if (!strcasecmp(v->value, "ulaw")) {
- prefformat = AST_FORMAT_ULAW;
- } else
- ast_log(LOG_WARNING, "Unknown format '%s'\n", v->value);
- } else if (!strcasecmp(v->name, "echocancel")) {
- if (!strcasecmp(v->value, "off")) {
- echocancel = AEC_OFF;
- } else if (!strcasecmp(v->value, "low")) {
- echocancel = AEC_LOW;
- } else if (!strcasecmp(v->value, "medium")) {
- echocancel = AEC_MED;
- } else if (!strcasecmp(v->value, "high")) {
- echocancel = AEC_HIGH;
- } else
- ast_log(LOG_WARNING, "Unknown echo cancellation '%s'\n", v->value);
- } else if (!strcasecmp(v->name, "txgain")) {
- txgain = parse_gain_value(v->name, v->value);
- } else if (!strcasecmp(v->name, "rxgain")) {
- rxgain = parse_gain_value(v->name, v->value);
- }
- v = v->next;
- }
- ast_mutex_unlock(&iflock);
-
- if (mode == MODE_FXS) {
- phone_tech_fxs.capabilities = prefformat;
- cur_tech = &phone_tech_fxs;
- } else
- cur_tech = (struct ast_channel_tech *) &phone_tech;
-
- /* Make sure we can register our Adtranphone channel type */
-
- if (ast_channel_register(cur_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- ast_config_destroy(cfg);
- __unload_module();
- return -1;
- }
- ast_config_destroy(cfg);
- /* And start the monitor for the first time */
- restart_monitor();
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/channels/chan_sip.c b/1.2-netsec/channels/chan_sip.c
deleted file mode 100644
index 9960b7174..000000000
--- a/1.2-netsec/channels/chan_sip.c
+++ /dev/null
@@ -1,13481 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*!
- * \file
- * \brief Implementation of Session Initiation Protocol
- *
- * Implementation of RFC 3261 - without S/MIME, TCP and TLS support
- * Configuration file \link Config_sip sip.conf \endlink
- *
- * \todo SIP over TCP
- * \todo SIP over TLS
- * \todo Better support of forking
- */
-
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <signal.h>
-#include <sys/signal.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <arpa/inet.h>
-#include <netinet/ip.h>
-#include <regex.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp.h"
-#include "asterisk/acl.h"
-#include "asterisk/manager.h"
-#include "asterisk/callerid.h"
-#include "asterisk/cli.h"
-#include "asterisk/app.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/dsp.h"
-#include "asterisk/features.h"
-#include "asterisk/acl.h"
-#include "asterisk/srv.h"
-#include "asterisk/astdb.h"
-#include "asterisk/causes.h"
-#include "asterisk/utils.h"
-#include "asterisk/file.h"
-#include "asterisk/astobj.h"
-#include "asterisk/dnsmgr.h"
-#include "asterisk/devicestate.h"
-#include "asterisk/linkedlists.h"
-
-#ifdef OSP_SUPPORT
-#include "asterisk/astosp.h"
-#endif
-
-#ifdef SIP_MIDCOM
-#include "asterisk/res_netsec.h"
-#endif
-
-#ifndef DEFAULT_USERAGENT
-#define DEFAULT_USERAGENT "Asterisk PBX"
-#endif
-
-#define VIDEO_CODEC_MASK 0x1fc0000 /* Video codecs from H.261 thru AST_FORMAT_MAX_VIDEO */
-#ifndef IPTOS_MINCOST
-#define IPTOS_MINCOST 0x02
-#endif
-
-/* #define VOCAL_DATA_HACK */
-
-#define SIPDUMPER
-#define DEFAULT_DEFAULT_EXPIRY 120
-#define DEFAULT_MAX_EXPIRY 3600
-#define DEFAULT_REGISTRATION_TIMEOUT 20
-#define DEFAULT_MAX_FORWARDS "70"
-
-/* guard limit must be larger than guard secs */
-/* guard min must be < 1000, and should be >= 250 */
-#define EXPIRY_GUARD_SECS 15 /* How long before expiry do we reregister */
-#define EXPIRY_GUARD_LIMIT 30 /* Below here, we use EXPIRY_GUARD_PCT instead of
- EXPIRY_GUARD_SECS */
-#define EXPIRY_GUARD_MIN 500 /* This is the minimum guard time applied. If
- GUARD_PCT turns out to be lower than this, it
- will use this time instead.
- This is in milliseconds. */
-#define EXPIRY_GUARD_PCT 0.20 /* Percentage of expires timeout to use when
- below EXPIRY_GUARD_LIMIT */
-
-static int max_expiry = DEFAULT_MAX_EXPIRY;
-static int default_expiry = DEFAULT_DEFAULT_EXPIRY;
-
-#ifndef MAX
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-#define CALLERID_UNKNOWN "Unknown"
-
-
-
-#define DEFAULT_MAXMS 2000 /* Must be faster than 2 seconds by default */
-#define DEFAULT_FREQ_OK 60 * 1000 /* How often to check for the host to be up */
-#define DEFAULT_FREQ_NOTOK 10 * 1000 /* How often to check, if the host is down... */
-
-#define DEFAULT_RETRANS 1000 /* How frequently to retransmit */
- /* 2 * 500 ms in RFC 3261 */
-#define MAX_RETRANS 6 /* Try only 6 times for retransmissions, a total of 7 transmissions */
-#define MAX_AUTHTRIES 3 /* Try authentication three times, then fail */
-
-
-#define DEBUG_READ 0 /* Recieved data */
-#define DEBUG_SEND 1 /* Transmit data */
-
-static const char desc[] = "Session Initiation Protocol (SIP)";
-static const char channeltype[] = "SIP";
-static const char config[] = "sip.conf";
-static const char notify_config[] = "sip_notify.conf";
-
-#define RTP 1
-#define NO_RTP 0
-
-/* Do _NOT_ make any changes to this enum, or the array following it;
- if you think you are doing the right thing, you are probably
- not doing the right thing. If you think there are changes
- needed, get someone else to review them first _before_
- submitting a patch. If these two lists do not match properly
- bad things will happen.
-*/
-
-enum subscriptiontype {
- NONE = 0,
- TIMEOUT,
- XPIDF_XML,
- DIALOG_INFO_XML,
- CPIM_PIDF_XML,
- PIDF_XML
-};
-
-static const struct cfsubscription_types {
- enum subscriptiontype type;
- const char * const event;
- const char * const mediatype;
- const char * const text;
-} subscription_types[] = {
- { NONE, "-", "unknown", "unknown" },
- /* IETF draft: draft-ietf-sipping-dialog-package-05.txt */
- { DIALOG_INFO_XML, "dialog", "application/dialog-info+xml", "dialog-info+xml" },
- { CPIM_PIDF_XML, "presence", "application/cpim-pidf+xml", "cpim-pidf+xml" }, /* RFC 3863 */
- { PIDF_XML, "presence", "application/pidf+xml", "pidf+xml" }, /* RFC 3863 */
- { XPIDF_XML, "presence", "application/xpidf+xml", "xpidf+xml" } /* Pre-RFC 3863 with MS additions */
-};
-
-enum sipmethod {
- SIP_UNKNOWN,
- SIP_RESPONSE,
- SIP_REGISTER,
- SIP_OPTIONS,
- SIP_NOTIFY,
- SIP_INVITE,
- SIP_ACK,
- SIP_PRACK,
- SIP_BYE,
- SIP_REFER,
- SIP_SUBSCRIBE,
- SIP_MESSAGE,
- SIP_UPDATE,
- SIP_INFO,
- SIP_CANCEL,
- SIP_PUBLISH,
-} sip_method_list;
-
-enum sip_auth_type {
- PROXY_AUTH,
- WWW_AUTH,
-};
-
-/*! XXX Note that sip_methods[i].id == i must hold or the code breaks */
-static const struct cfsip_methods {
- enum sipmethod id;
- int need_rtp; /*!< when this is the 'primary' use for a pvt structure, does it need RTP? */
- char * const text;
-} sip_methods[] = {
- { SIP_UNKNOWN, RTP, "-UNKNOWN-" },
- { SIP_RESPONSE, NO_RTP, "SIP/2.0" },
- { SIP_REGISTER, NO_RTP, "REGISTER" },
- { SIP_OPTIONS, NO_RTP, "OPTIONS" },
- { SIP_NOTIFY, NO_RTP, "NOTIFY" },
- { SIP_INVITE, RTP, "INVITE" },
- { SIP_ACK, NO_RTP, "ACK" },
- { SIP_PRACK, NO_RTP, "PRACK" },
- { SIP_BYE, NO_RTP, "BYE" },
- { SIP_REFER, NO_RTP, "REFER" },
- { SIP_SUBSCRIBE, NO_RTP, "SUBSCRIBE" },
- { SIP_MESSAGE, NO_RTP, "MESSAGE" },
- { SIP_UPDATE, NO_RTP, "UPDATE" },
- { SIP_INFO, NO_RTP, "INFO" },
- { SIP_CANCEL, NO_RTP, "CANCEL" },
- { SIP_PUBLISH, NO_RTP, "PUBLISH" }
-};
-
-/*! \brief Structure for conversion between compressed SIP and "normal" SIP */
-static const struct cfalias {
- char * const fullname;
- char * const shortname;
-} aliases[] = {
- { "Content-Type", "c" },
- { "Content-Encoding", "e" },
- { "From", "f" },
- { "Call-ID", "i" },
- { "Contact", "m" },
- { "Content-Length", "l" },
- { "Subject", "s" },
- { "To", "t" },
- { "Supported", "k" },
- { "Refer-To", "r" },
- { "Referred-By", "b" },
- { "Allow-Events", "u" },
- { "Event", "o" },
- { "Via", "v" },
- { "Accept-Contact", "a" },
- { "Reject-Contact", "j" },
- { "Request-Disposition", "d" },
- { "Session-Expires", "x" },
-};
-
-/*! Define SIP option tags, used in Require: and Supported: headers
- We need to be aware of these properties in the phones to use
- the replace: header. We should not do that without knowing
- that the other end supports it...
- This is nothing we can configure, we learn by the dialog
- Supported: header on the REGISTER (peer) or the INVITE
- (other devices)
- We are not using many of these today, but will in the future.
- This is documented in RFC 3261
-*/
-#define SUPPORTED 1
-#define NOT_SUPPORTED 0
-
-#define SIP_OPT_REPLACES (1 << 0)
-#define SIP_OPT_100REL (1 << 1)
-#define SIP_OPT_TIMER (1 << 2)
-#define SIP_OPT_EARLY_SESSION (1 << 3)
-#define SIP_OPT_JOIN (1 << 4)
-#define SIP_OPT_PATH (1 << 5)
-#define SIP_OPT_PREF (1 << 6)
-#define SIP_OPT_PRECONDITION (1 << 7)
-#define SIP_OPT_PRIVACY (1 << 8)
-#define SIP_OPT_SDP_ANAT (1 << 9)
-#define SIP_OPT_SEC_AGREE (1 << 10)
-#define SIP_OPT_EVENTLIST (1 << 11)
-#define SIP_OPT_GRUU (1 << 12)
-#define SIP_OPT_TARGET_DIALOG (1 << 13)
-
-/*! \brief List of well-known SIP options. If we get this in a require,
- we should check the list and answer accordingly. */
-static const struct cfsip_options {
- int id; /*!< Bitmap ID */
- int supported; /*!< Supported by Asterisk ? */
- char * const text; /*!< Text id, as in standard */
-} sip_options[] = {
- /* Replaces: header for transfer */
- { SIP_OPT_REPLACES, SUPPORTED, "replaces" },
- /* RFC3262: PRACK 100% reliability */
- { SIP_OPT_100REL, NOT_SUPPORTED, "100rel" },
- /* SIP Session Timers */
- { SIP_OPT_TIMER, NOT_SUPPORTED, "timer" },
- /* RFC3959: SIP Early session support */
- { SIP_OPT_EARLY_SESSION, NOT_SUPPORTED, "early-session" },
- /* SIP Join header support */
- { SIP_OPT_JOIN, NOT_SUPPORTED, "join" },
- /* RFC3327: Path support */
- { SIP_OPT_PATH, NOT_SUPPORTED, "path" },
- /* RFC3840: Callee preferences */
- { SIP_OPT_PREF, NOT_SUPPORTED, "pref" },
- /* RFC3312: Precondition support */
- { SIP_OPT_PRECONDITION, NOT_SUPPORTED, "precondition" },
- /* RFC3323: Privacy with proxies*/
- { SIP_OPT_PRIVACY, NOT_SUPPORTED, "privacy" },
- /* RFC4092: Usage of the SDP ANAT Semantics in the SIP */
- { SIP_OPT_SDP_ANAT, NOT_SUPPORTED, "sdp-anat" },
- /* RFC3329: Security agreement mechanism */
- { SIP_OPT_SEC_AGREE, NOT_SUPPORTED, "sec_agree" },
- /* SIMPLE events: draft-ietf-simple-event-list-07.txt */
- { SIP_OPT_EVENTLIST, NOT_SUPPORTED, "eventlist" },
- /* GRUU: Globally Routable User Agent URI's */
- { SIP_OPT_GRUU, NOT_SUPPORTED, "gruu" },
- /* Target-dialog: draft-ietf-sip-target-dialog-00.txt */
- { SIP_OPT_TARGET_DIALOG,NOT_SUPPORTED, "target-dialog" },
-};
-
-
-/*! \brief SIP Methods we support */
-#define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY"
-
-/*! \brief SIP Extensions we support */
-#define SUPPORTED_EXTENSIONS "replaces"
-
-#define DEFAULT_SIP_PORT 5060 /*!< From RFC 3261 (former 2543) */
-#define SIP_MAX_PACKET 4096 /*!< Also from RFC 3261 (2543), should sub headers tho */
-
-static char default_useragent[AST_MAX_EXTENSION] = DEFAULT_USERAGENT;
-
-#define DEFAULT_CONTEXT "default"
-static char default_context[AST_MAX_CONTEXT] = DEFAULT_CONTEXT;
-static char default_subscribecontext[AST_MAX_CONTEXT];
-
-#define DEFAULT_VMEXTEN "asterisk"
-static char global_vmexten[AST_MAX_EXTENSION] = DEFAULT_VMEXTEN;
-
-static char default_language[MAX_LANGUAGE] = "";
-
-#define DEFAULT_CALLERID "asterisk"
-static char default_callerid[AST_MAX_EXTENSION] = DEFAULT_CALLERID;
-
-static char default_fromdomain[AST_MAX_EXTENSION] = "";
-
-#define DEFAULT_NOTIFYMIME "application/simple-message-summary"
-static char default_notifymime[AST_MAX_EXTENSION] = DEFAULT_NOTIFYMIME;
-
-static int global_notifyringing = 1; /*!< Send notifications on ringing */
-
-static int default_qualify = 0; /*!< Default Qualify= setting */
-
-static struct ast_flags global_flags = {0}; /*!< global SIP_ flags */
-static struct ast_flags global_flags_page2 = {0}; /*!< more global SIP_ flags */
-
-static int srvlookup = 0; /*!< SRV Lookup on or off. Default is off, RFC behavior is on */
-
-static int pedanticsipchecking = 0; /*!< Extra checking ? Default off */
-
-static int autocreatepeer = 0; /*!< Auto creation of peers at registration? Default off. */
-
-static int relaxdtmf = 0;
-
-static int global_rtptimeout = 0;
-
-static int global_rtpholdtimeout = 0;
-
-static int global_rtpkeepalive = 0;
-
-static int global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT;
-static int global_regattempts_max = 0;
-
-/* Object counters */
-static int suserobjs = 0;
-static int ruserobjs = 0;
-static int speerobjs = 0;
-static int rpeerobjs = 0;
-static int apeerobjs = 0;
-static int regobjs = 0;
-
-static int global_allowguest = 1; /*!< allow unauthenticated users/peers to connect? */
-
-#define DEFAULT_MWITIME 10
-static int global_mwitime = DEFAULT_MWITIME; /*!< Time between MWI checks for peers */
-
-static int usecnt =0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-AST_MUTEX_DEFINE_STATIC(rand_lock);
-
-/*! \brief Protect the interface list (of sip_pvt's) */
-AST_MUTEX_DEFINE_STATIC(iflock);
-
-/*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
- when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(netlock);
-
-AST_MUTEX_DEFINE_STATIC(monlock);
-
-/*! \brief This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
-
-static int restart_monitor(void);
-
-/*! \brief Codecs that we support by default: */
-static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
-static int noncodeccapability = AST_RTP_DTMF;
-
-static struct in_addr __ourip;
-static struct sockaddr_in outboundproxyip;
-static int ourport;
-
-#define SIP_DEBUG_CONFIG 1 << 0
-#define SIP_DEBUG_CONSOLE 1 << 1
-static int sipdebug = 0;
-static struct sockaddr_in debugaddr;
-
-static int tos = 0;
-
-static int videosupport = 0;
-
-static int compactheaders = 0; /*!< send compact sip headers */
-
-static int recordhistory = 0; /*!< Record SIP history. Off by default */
-static int dumphistory = 0; /*!< Dump history to verbose before destroying SIP dialog */
-
-static char global_musicclass[MAX_MUSICCLASS] = ""; /*!< Global music on hold class */
-#define DEFAULT_REALM "asterisk"
-static char global_realm[MAXHOSTNAMELEN] = DEFAULT_REALM; /*!< Default realm */
-static char regcontext[AST_MAX_CONTEXT] = ""; /*!< Context for auto-extensions */
-
-#define DEFAULT_EXPIRY 900 /*!< Expire slowly */
-static int expiry = DEFAULT_EXPIRY;
-
-static struct sched_context *sched;
-static struct io_context *io;
-
-#define SIP_MAX_HEADERS 64 /*!< Max amount of SIP headers to read */
-#define SIP_MAX_LINES 64 /*!< Max amount of lines in SIP attachment (like SDP) */
-
-#define DEC_CALL_LIMIT 0
-#define INC_CALL_LIMIT 1
-
-static struct ast_codec_pref prefs;
-
-
-/*! \brief sip_request: The data grabbed from the UDP socket */
-struct sip_request {
- char *rlPart1; /*!< SIP Method Name or "SIP/2.0" protocol version */
- char *rlPart2; /*!< The Request URI or Response Status */
- int len; /*!< Length */
- int headers; /*!< # of SIP Headers */
- int method; /*!< Method of this request */
- char *header[SIP_MAX_HEADERS];
- int lines; /*!< SDP Content */
- char *line[SIP_MAX_LINES];
- char data[SIP_MAX_PACKET];
- int debug; /*!< Debug flag for this packet */
- unsigned int flags; /*!< SIP_PKT Flags for this packet */
-};
-
-struct sip_pkt;
-
-/*! \brief Parameters to the transmit_invite function */
-struct sip_invite_param {
- char *distinctive_ring; /*!< Distinctive ring header */
- char *osptoken; /*!< OSP token for this call */
- int addsipheaders; /*!< Add extra SIP headers */
- char *uri_options; /*!< URI options to add to the URI */
- char *vxml_url; /*!< VXML url for Cisco phones */
- char *auth; /*!< Authentication */
- char *authheader; /*!< Auth header */
- enum sip_auth_type auth_type; /*!< Authentication type */
-};
-
-struct sip_route {
- struct sip_route *next;
- char hop[0];
-};
-
-enum domain_mode {
- SIP_DOMAIN_AUTO, /*!< This domain is auto-configured */
- SIP_DOMAIN_CONFIG, /*!< This domain is from configuration */
-};
-
-struct domain {
- char domain[MAXHOSTNAMELEN]; /*!< SIP domain we are responsible for */
- char context[AST_MAX_EXTENSION]; /*!< Incoming context for this domain */
- enum domain_mode mode; /*!< How did we find this domain? */
- AST_LIST_ENTRY(domain) list; /*!< List mechanics */
-};
-
-static AST_LIST_HEAD_STATIC(domain_list, domain); /*!< The SIP domain list */
-
-int allow_external_domains; /*!< Accept calls to external SIP domains? */
-
-/*! \brief sip_history: Structure for saving transactions within a SIP dialog */
-struct sip_history {
- char event[80];
- struct sip_history *next;
-};
-
-/*! \brief sip_auth: Creadentials for authentication to other SIP services */
-struct sip_auth {
- char realm[AST_MAX_EXTENSION]; /*!< Realm in which these credentials are valid */
- char username[256]; /*!< Username */
- char secret[256]; /*!< Secret */
- char md5secret[256]; /*!< MD5Secret */
- struct sip_auth *next; /*!< Next auth structure in list */
-};
-
-#define SIP_ALREADYGONE (1 << 0) /*!< Whether or not we've already been destroyed by our peer */
-#define SIP_NEEDDESTROY (1 << 1) /*!< if we need to be destroyed */
-#define SIP_NOVIDEO (1 << 2) /*!< Didn't get video in invite, don't offer */
-#define SIP_RINGING (1 << 3) /*!< Have sent 180 ringing */
-#define SIP_PROGRESS_SENT (1 << 4) /*!< Have sent 183 message progress */
-#define SIP_NEEDREINVITE (1 << 5) /*!< Do we need to send another reinvite? */
-#define SIP_PENDINGBYE (1 << 6) /*!< Need to send bye after we ack? */
-#define SIP_GOTREFER (1 << 7) /*!< Got a refer? */
-#define SIP_PROMISCREDIR (1 << 8) /*!< Promiscuous redirection */
-#define SIP_TRUSTRPID (1 << 9) /*!< Trust RPID headers? */
-#define SIP_USEREQPHONE (1 << 10) /*!< Add user=phone to numeric URI. Default off */
-#define SIP_REALTIME (1 << 11) /*!< Flag for realtime users */
-#define SIP_USECLIENTCODE (1 << 12) /*!< Trust X-ClientCode info message */
-#define SIP_OUTGOING (1 << 13) /*!< Is this an outgoing call? */
-#define SIP_SELFDESTRUCT (1 << 14)
-#define SIP_DYNAMIC (1 << 15) /*!< Is this a dynamic peer? */
-/* --- Choices for DTMF support in SIP channel */
-#define SIP_DTMF (3 << 16) /*!< three settings, uses two bits */
-#define SIP_DTMF_RFC2833 (0 << 16) /*!< RTP DTMF */
-#define SIP_DTMF_INBAND (1 << 16) /*!< Inband audio, only for ULAW/ALAW */
-#define SIP_DTMF_INFO (2 << 16) /*!< SIP Info messages */
-#define SIP_DTMF_AUTO (3 << 16) /*!< AUTO switch between rfc2833 and in-band DTMF */
-/* NAT settings */
-#define SIP_NAT (3 << 18) /*!< four settings, uses two bits */
-#define SIP_NAT_NEVER (0 << 18) /*!< No nat support */
-#define SIP_NAT_RFC3581 (1 << 18)
-#define SIP_NAT_ROUTE (2 << 18)
-#define SIP_NAT_ALWAYS (3 << 18)
-/* re-INVITE related settings */
-#define SIP_REINVITE (3 << 20) /*!< two bits used */
-#define SIP_CAN_REINVITE (1 << 20) /*!< allow peers to be reinvited to send media directly p2p */
-#define SIP_REINVITE_UPDATE (2 << 20) /*!< use UPDATE (RFC3311) when reinviting this peer */
-/* "insecure" settings */
-#define SIP_INSECURE_PORT (1 << 22) /*!< don't require matching port for incoming requests */
-#define SIP_INSECURE_INVITE (1 << 23) /*!< don't require authentication for incoming INVITEs */
-/* Sending PROGRESS in-band settings */
-#define SIP_PROG_INBAND (3 << 24) /*!< three settings, uses two bits */
-#define SIP_PROG_INBAND_NEVER (0 << 24)
-#define SIP_PROG_INBAND_NO (1 << 24)
-#define SIP_PROG_INBAND_YES (2 << 24)
-/* Open Settlement Protocol authentication */
-#define SIP_OSPAUTH (3 << 26) /*!< four settings, uses two bits */
-#define SIP_OSPAUTH_NO (0 << 26)
-#define SIP_OSPAUTH_GATEWAY (1 << 26)
-#define SIP_OSPAUTH_PROXY (2 << 26)
-#define SIP_OSPAUTH_EXCLUSIVE (3 << 26)
-/* Call states */
-#define SIP_CALL_ONHOLD (1 << 28)
-#define SIP_CALL_LIMIT (1 << 29)
-/* Remote Party-ID Support */
-#define SIP_SENDRPID (1 << 30)
-/* Did this connection increment the counter of in-use calls? */
-#define SIP_INC_COUNT (1 << 31)
-
-#define SIP_FLAGS_TO_COPY \
- (SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_SENDRPID | SIP_DTMF | SIP_REINVITE | \
- SIP_PROG_INBAND | SIP_OSPAUTH | SIP_USECLIENTCODE | SIP_NAT | \
- SIP_INSECURE_PORT | SIP_INSECURE_INVITE)
-
-/* a new page of flags for peer */
-#define SIP_PAGE2_RTCACHEFRIENDS (1 << 0)
-#define SIP_PAGE2_RTUPDATE (1 << 1)
-#define SIP_PAGE2_RTAUTOCLEAR (1 << 2)
-#define SIP_PAGE2_IGNOREREGEXPIRE (1 << 3)
-#define SIP_PAGE2_RT_FROMCONTACT (1 << 4)
-
-/* SIP packet flags */
-#define SIP_PKT_DEBUG (1 << 0) /*!< Debug this packet */
-#define SIP_PKT_WITH_TOTAG (1 << 1) /*!< This packet has a to-tag */
-
-static int global_rtautoclear = 120;
-
-/*! \brief sip_pvt: PVT structures are used for each SIP conversation, ie. a call */
-static struct sip_pvt {
- ast_mutex_t lock; /*!< Channel private lock */
- int method; /*!< SIP method of this packet */
- char callid[80]; /*!< Global CallID */
- char randdata[80]; /*!< Random data */
- struct ast_codec_pref prefs; /*!< codec prefs */
- unsigned int ocseq; /*!< Current outgoing seqno */
- unsigned int icseq; /*!< Current incoming seqno */
- ast_group_t callgroup; /*!< Call group */
- ast_group_t pickupgroup; /*!< Pickup group */
- int lastinvite; /*!< Last Cseq of invite */
- unsigned int flags; /*!< SIP_ flags */
- int timer_t1; /*!< SIP timer T1, ms rtt */
- unsigned int sipoptions; /*!< Supported SIP sipoptions on the other end */
- int capability; /*!< Special capability (codec) */
- int jointcapability; /*!< Supported capability at both ends (codecs ) */
- int peercapability; /*!< Supported peer capability */
- int prefcodec; /*!< Preferred codec (outbound only) */
- int noncodeccapability;
- int callingpres; /*!< Calling presentation */
- int authtries; /*!< Times we've tried to authenticate */
- int expiry; /*!< How long we take to expire */
- int branch; /*!< One random number */
- char tag[11]; /*!< Another random number */
- int sessionid; /*!< SDP Session ID */
- int sessionversion; /*!< SDP Session Version */
- struct sockaddr_in sa; /*!< Our peer */
- struct sockaddr_in redirip; /*!< Where our RTP should be going if not to us */
- struct sockaddr_in vredirip; /*!< Where our Video RTP should be going if not to us */
- int redircodecs; /*!< Redirect codecs */
- struct sockaddr_in recv; /*!< Received as */
- struct in_addr ourip; /*!< Our IP */
- struct ast_channel *owner; /*!< Who owns us */
- char exten[AST_MAX_EXTENSION]; /*!< Extension where to start */
- char refer_to[AST_MAX_EXTENSION]; /*!< Place to store REFER-TO extension */
- char referred_by[AST_MAX_EXTENSION]; /*!< Place to store REFERRED-BY extension */
- char refer_contact[AST_MAX_EXTENSION]; /*!< Place to store Contact info from a REFER extension */
- struct sip_pvt *refer_call; /*!< Call we are referring */
- struct sip_route *route; /*!< Head of linked list of routing steps (fm Record-Route) */
- int route_persistant; /*!< Is this the "real" route? */
- char from[256]; /*!< The From: header */
- char useragent[256]; /*!< User agent in SIP request */
- char context[AST_MAX_CONTEXT]; /*!< Context for this call */
- char subscribecontext[AST_MAX_CONTEXT]; /*!< Subscribecontext */
- char fromdomain[MAXHOSTNAMELEN]; /*!< Domain to show in the from field */
- char fromuser[AST_MAX_EXTENSION]; /*!< User to show in the user field */
- char fromname[AST_MAX_EXTENSION]; /*!< Name to show in the user field */
- char tohost[MAXHOSTNAMELEN]; /*!< Host we should put in the "to" field */
- char language[MAX_LANGUAGE]; /*!< Default language for this call */
- char musicclass[MAX_MUSICCLASS]; /*!< Music on Hold class */
- char rdnis[256]; /*!< Referring DNIS */
- char theirtag[256]; /*!< Their tag */
- char username[256]; /*!< [user] name */
- char peername[256]; /*!< [peer] name, not set if [user] */
- char authname[256]; /*!< Who we use for authentication */
- char uri[256]; /*!< Original requested URI */
- char okcontacturi[256]; /*!< URI from the 200 OK on INVITE */
- char peersecret[256]; /*!< Password */
- char peermd5secret[256];
- struct sip_auth *peerauth; /*!< Realm authentication */
- char cid_num[256]; /*!< Caller*ID */
- char cid_name[256]; /*!< Caller*ID */
- char via[256]; /*!< Via: header */
- char fullcontact[128]; /*!< The Contact: that the UA registers with us */
- char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
- char our_contact[256]; /*!< Our contact header */
- char *rpid; /*!< Our RPID header */
- char *rpid_from; /*!< Our RPID From header */
- char realm[MAXHOSTNAMELEN]; /*!< Authorization realm */
- char nonce[256]; /*!< Authorization nonce */
- int noncecount; /*!< Nonce-count */
- char opaque[256]; /*!< Opaque nonsense */
- char qop[80]; /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
- char domain[MAXHOSTNAMELEN]; /*!< Authorization domain */
- char lastmsg[256]; /*!< Last Message sent/received */
- int amaflags; /*!< AMA Flags */
- int pendinginvite; /*!< Any pending invite */
-#ifdef OSP_SUPPORT
- int osphandle; /*!< OSP Handle for call */
- time_t ospstart; /*!< OSP Start time */
- unsigned int osptimelimit; /*!< OSP call duration limit */
-#endif
- struct sip_request initreq; /*!< Initial request */
-
- int maxtime; /*!< Max time for first response */
- int initid; /*!< Auto-congest ID if appropriate */
- int autokillid; /*!< Auto-kill ID */
- time_t lastrtprx; /*!< Last RTP received */
- time_t lastrtptx; /*!< Last RTP sent */
- int rtptimeout; /*!< RTP timeout time */
- int rtpholdtimeout; /*!< RTP timeout when on hold */
- int rtpkeepalive; /*!< Send RTP packets for keepalive */
- enum subscriptiontype subscribed; /*!< Is this call a subscription? */
- int stateid;
- int laststate; /*!< Last known extension state */
- int dialogver;
-
- struct ast_dsp *vad; /*!< Voice Activation Detection dsp */
-
-#ifdef SIP_MIDCOM
- void *r;
-#endif
-
- struct sip_peer *peerpoke; /*!< If this calls is to poke a peer, which one */
- struct sip_registry *registry; /*!< If this is a REGISTER call, to which registry */
- struct ast_rtp *rtp; /*!< RTP Session */
- struct ast_rtp *vrtp; /*!< Video RTP session */
- struct sip_pkt *packets; /*!< Packets scheduled for re-transmission */
- struct sip_history *history; /*!< History of this SIP dialog */
- struct ast_variable *chanvars; /*!< Channel variables to set for call */
- struct sip_pvt *next; /*!< Next call in chain */
- struct sip_invite_param *options; /*!< Options for INVITE */
-} *iflist = NULL;
-
-#define FLAG_RESPONSE (1 << 0)
-#define FLAG_FATAL (1 << 1)
-
-/*! \brief sip packet - read in sipsock_read, transmitted in send_request */
-struct sip_pkt {
- struct sip_pkt *next; /*!< Next packet */
- int retrans; /*!< Retransmission number */
- int method; /*!< SIP method for this packet */
- int seqno; /*!< Sequence number */
- unsigned int flags; /*!< non-zero if this is a response packet (e.g. 200 OK) */
- struct sip_pvt *owner; /*!< Owner call */
- int retransid; /*!< Retransmission ID */
- int timer_a; /*!< SIP timer A, retransmission timer */
- int timer_t1; /*!< SIP Timer T1, estimated RTT or 500 ms */
- int packetlen; /*!< Length of packet */
- char data[0];
-};
-
-/*! \brief Structure for SIP user data. User's place calls to us */
-struct sip_user {
- /* Users who can access various contexts */
- ASTOBJ_COMPONENTS(struct sip_user);
- char secret[80]; /*!< Password */
- char md5secret[80]; /*!< Password in md5 */
- char context[AST_MAX_CONTEXT]; /*!< Default context for incoming calls */
- char subscribecontext[AST_MAX_CONTEXT]; /* Default context for subscriptions */
- char cid_num[80]; /*!< Caller ID num */
- char cid_name[80]; /*!< Caller ID name */
- char accountcode[AST_MAX_ACCOUNT_CODE]; /* Account code */
- char language[MAX_LANGUAGE]; /*!< Default language for this user */
- char musicclass[MAX_MUSICCLASS];/*!< Music on Hold class */
- char useragent[256]; /*!< User agent in SIP request */
- struct ast_codec_pref prefs; /*!< codec prefs */
- ast_group_t callgroup; /*!< Call group */
- ast_group_t pickupgroup; /*!< Pickup Group */
- unsigned int flags; /*!< SIP flags */
- unsigned int sipoptions; /*!< Supported SIP options */
- struct ast_flags flags_page2; /*!< SIP_PAGE2 flags */
- int amaflags; /*!< AMA flags for billing */
- int callingpres; /*!< Calling id presentation */
- int capability; /*!< Codec capability */
- int inUse; /*!< Number of calls in use */
- int call_limit; /*!< Limit of concurrent calls */
- struct ast_ha *ha; /*!< ACL setting */
- struct ast_variable *chanvars; /*!< Variables to set for channel created by user */
-};
-
-/* Structure for SIP peer data, we place calls to peers if registered or fixed IP address (host) */
-struct sip_peer {
- ASTOBJ_COMPONENTS(struct sip_peer); /*!< name, refcount, objflags, object pointers */
- /*!< peer->name is the unique name of this object */
- char secret[80]; /*!< Password */
- char md5secret[80]; /*!< Password in MD5 */
- struct sip_auth *auth; /*!< Realm authentication list */
- char context[AST_MAX_CONTEXT]; /*!< Default context for incoming calls */
- char subscribecontext[AST_MAX_CONTEXT]; /*!< Default context for subscriptions */
- char username[80]; /*!< Temporary username until registration */
- char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
- int amaflags; /*!< AMA Flags (for billing) */
- char tohost[MAXHOSTNAMELEN]; /*!< If not dynamic, IP address */
- char regexten[AST_MAX_EXTENSION]; /*!< Extension to register (if regcontext is used) */
- char fromuser[80]; /*!< From: user when calling this peer */
- char fromdomain[MAXHOSTNAMELEN]; /*!< From: domain when calling this peer */
- char fullcontact[256]; /*!< Contact registered with us (not in sip.conf) */
- char cid_num[80]; /*!< Caller ID num */
- char cid_name[80]; /*!< Caller ID name */
- int callingpres; /*!< Calling id presentation */
- int inUse; /*!< Number of calls in use */
- int call_limit; /*!< Limit of concurrent calls */
- char vmexten[AST_MAX_EXTENSION]; /*!< Dialplan extension for MWI notify message*/
- char mailbox[AST_MAX_EXTENSION]; /*!< Mailbox setting for MWI checks */
- char language[MAX_LANGUAGE]; /*!< Default language for prompts */
- char musicclass[MAX_MUSICCLASS];/*!< Music on Hold class */
- char useragent[256]; /*!< User agent in SIP request (saved from registration) */
- struct ast_codec_pref prefs; /*!< codec prefs */
- int lastmsgssent;
- time_t lastmsgcheck; /*!< Last time we checked for MWI */
- unsigned int flags; /*!< SIP flags */
- unsigned int sipoptions; /*!< Supported SIP options */
- struct ast_flags flags_page2; /*!< SIP_PAGE2 flags */
- int expire; /*!< When to expire this peer registration */
- int capability; /*!< Codec capability */
- int rtptimeout; /*!< RTP timeout */
- int rtpholdtimeout; /*!< RTP Hold Timeout */
- int rtpkeepalive; /*!< Send RTP packets for keepalive */
- ast_group_t callgroup; /*!< Call group */
- ast_group_t pickupgroup; /*!< Pickup group */
- struct ast_dnsmgr_entry *dnsmgr;/*!< DNS refresh manager for peer */
- struct sockaddr_in addr; /*!< IP address of peer */
-
- /* Qualification */
- struct sip_pvt *call; /*!< Call pointer */
- int pokeexpire; /*!< When to expire poke (qualify= checking) */
- int lastms; /*!< How long last response took (in ms), or -1 for no response */
- int maxms; /*!< Max ms we will accept for the host to be up, 0 to not monitor */
- struct timeval ps; /*!< Ping send time */
-
- struct sockaddr_in defaddr; /*!< Default IP address, used until registration */
- struct ast_ha *ha; /*!< Access control list */
- struct ast_variable *chanvars; /*!< Variables to set for channel created by user */
- int lastmsg;
-};
-
-AST_MUTEX_DEFINE_STATIC(sip_reload_lock);
-static int sip_reloading = 0;
-
-/* States for outbound registrations (with register= lines in sip.conf */
-#define REG_STATE_UNREGISTERED 0
-#define REG_STATE_REGSENT 1
-#define REG_STATE_AUTHSENT 2
-#define REG_STATE_REGISTERED 3
-#define REG_STATE_REJECTED 4
-#define REG_STATE_TIMEOUT 5
-#define REG_STATE_NOAUTH 6
-#define REG_STATE_FAILED 7
-
-
-/*! \brief sip_registry: Registrations with other SIP proxies */
-struct sip_registry {
- ASTOBJ_COMPONENTS_FULL(struct sip_registry,1,1);
- int portno; /*!< Optional port override */
- char username[80]; /*!< Who we are registering as */
- char authuser[80]; /*!< Who we *authenticate* as */
- char hostname[MAXHOSTNAMELEN]; /*!< Domain or host we register to */
- char secret[80]; /*!< Password in clear text */
- char md5secret[80]; /*!< Password in md5 */
- char contact[256]; /*!< Contact extension */
- char random[80];
- int expire; /*!< Sched ID of expiration */
- int regattempts; /*!< Number of attempts (since the last success) */
- int timeout; /*!< sched id of sip_reg_timeout */
- int refresh; /*!< How often to refresh */
- struct sip_pvt *call; /*!< create a sip_pvt structure for each outbound "registration call" in progress */
- int regstate; /*!< Registration state (see above) */
- int callid_valid; /*!< 0 means we haven't chosen callid for this registry yet. */
- char callid[80]; /*!< Global CallID for this registry */
- unsigned int ocseq; /*!< Sequence number we got to for REGISTERs for this registry */
- struct sockaddr_in us; /*!< Who the server thinks we are */
-
- /* Saved headers */
- char realm[MAXHOSTNAMELEN]; /*!< Authorization realm */
- char nonce[256]; /*!< Authorization nonce */
- char domain[MAXHOSTNAMELEN]; /*!< Authorization domain */
- char opaque[256]; /*!< Opaque nonsense */
- char qop[80]; /*!< Quality of Protection. */
- int noncecount; /*!< Nonce-count */
-
- char lastmsg[256]; /*!< Last Message sent/received */
-};
-
-/*! \brief The user list: Users and friends ---*/
-static struct ast_user_list {
- ASTOBJ_CONTAINER_COMPONENTS(struct sip_user);
-} userl;
-
-/*! \brief The peer list: Peers and Friends ---*/
-static struct ast_peer_list {
- ASTOBJ_CONTAINER_COMPONENTS(struct sip_peer);
-} peerl;
-
-/*! \brief The register list: Other SIP proxys we register with and call ---*/
-static struct ast_register_list {
- ASTOBJ_CONTAINER_COMPONENTS(struct sip_registry);
- int recheck;
-} regl;
-
-
-static int __sip_do_register(struct sip_registry *r);
-
-static int sipsock = -1;
-
-
-static struct sockaddr_in bindaddr = { 0, };
-static struct sockaddr_in externip;
-static char externhost[MAXHOSTNAMELEN] = "";
-static time_t externexpire = 0;
-static int externrefresh = 10;
-static struct ast_ha *localaddr;
-
-/* The list of manual NOTIFY types we know how to send */
-struct ast_config *notify_types;
-
-static struct sip_auth *authl; /*!< Authentication list */
-
-
-static int transmit_response(struct sip_pvt *p, char *msg, struct sip_request *req);
-static int transmit_response_with_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans);
-static int transmit_response_with_unsupported(struct sip_pvt *p, char *msg, struct sip_request *req, char *unsupported);
-static int transmit_response_with_auth(struct sip_pvt *p, char *msg, struct sip_request *req, char *rand, int reliable, char *header, int stale);
-static int transmit_request(struct sip_pvt *p, int sipmethod, int inc, int reliable, int newbranch);
-static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, int inc, int reliable, int newbranch);
-static int transmit_invite(struct sip_pvt *p, int sipmethod, int sendsdp, int init);
-static int transmit_reinvite_with_sdp(struct sip_pvt *p);
-static int transmit_info_with_digit(struct sip_pvt *p, char digit);
-static int transmit_info_with_vidupdate(struct sip_pvt *p);
-static int transmit_message_with_text(struct sip_pvt *p, const char *text);
-static int transmit_refer(struct sip_pvt *p, const char *dest);
-static int sip_sipredirect(struct sip_pvt *p, const char *dest);
-static struct sip_peer *temp_peer(const char *name);
-static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, char *header, char *respheader, int sipmethod, int init);
-static void free_old_route(struct sip_route *route);
-static int build_reply_digest(struct sip_pvt *p, int method, char *digest, int digest_len);
-static int update_call_counter(struct sip_pvt *fup, int event);
-static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int realtime);
-static struct sip_user *build_user(const char *name, struct ast_variable *v, int realtime);
-static int sip_do_reload(void);
-static int expire_register(void *data);
-static int callevents = 0;
-
-static struct ast_channel *sip_request_call(const char *type, int format, void *data, int *cause);
-static int sip_devicestate(void *data);
-static int sip_sendtext(struct ast_channel *ast, const char *text);
-static int sip_call(struct ast_channel *ast, char *dest, int timeout);
-static int sip_hangup(struct ast_channel *ast);
-static int sip_answer(struct ast_channel *ast);
-static struct ast_frame *sip_read(struct ast_channel *ast);
-static int sip_write(struct ast_channel *ast, struct ast_frame *frame);
-static int sip_indicate(struct ast_channel *ast, int condition);
-static int sip_transfer(struct ast_channel *ast, const char *dest);
-static int sip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-static int sip_senddigit(struct ast_channel *ast, char digit);
-static int clear_realm_authentication(struct sip_auth *authlist); /* Clear realm authentication list (at reload) */
-static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno); /* Add realm authentication in list */
-static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, char *realm); /* Find authentication for a specific realm */
-static int check_sip_domain(const char *domain, char *context, size_t len); /* Check if domain is one of our local domains */
-static void append_date(struct sip_request *req); /* Append date to SIP packet */
-static int determine_firstline_parts(struct sip_request *req);
-static void sip_dump_history(struct sip_pvt *dialog); /* Dump history to LOG_DEBUG at end of dialog, before destroying data */
-static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
-static int transmit_state_notify(struct sip_pvt *p, int state, int full, int substate);
-static char *gettag(struct sip_request *req, char *header, char *tagbuf, int tagbufsize);
-
-#ifdef SIP_MIDCOM
-static void sip_rtp_get_peer_audio_helper(void *p, struct sockaddr_in *them);
-static void sip_rtp_get_peer_video_helper(void *p, struct sockaddr_in *them);
-static void sip_rtp_get_us_audio_helper(void *p, struct sockaddr_in *sin);
-static void sip_rtp_get_us_video_helper(void *p, struct sockaddr_in *vsin);
-static void sip_map_hook_struct(void *p, void *r);
-static void *sip_get_hook_struct(void *p);
-static int sip_get_flag_novideo(void *p);
-static int sip_cmp_sa_addr(void *p, struct sockaddr_in *addr);
-static void sip_get_recv_addr(void *p, struct in_addr *addr);
-static char *sip_get_username(void *p);
-static struct ast_channel *sip_channel_helper(void *p);
-static struct ast_channel *sip_bridged_channel_helper(void *p);
-static int sip_get_capability_helper(void *p);
-static void sip_softhangup_helper(void *p);
-
-extern struct ast_sip_hook_cb *m_cb;
-#endif
-
-/*! \brief Definition of this channel for PBX channel registration */
-static const struct ast_channel_tech sip_tech = {
- .type = channeltype,
- .description = "Session Initiation Protocol (SIP)",
- .capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1),
- .properties = AST_CHAN_TP_WANTSJITTER,
- .requester = sip_request_call,
- .devicestate = sip_devicestate,
- .call = sip_call,
- .hangup = sip_hangup,
- .answer = sip_answer,
- .read = sip_read,
- .write = sip_write,
- .write_video = sip_write,
- .indicate = sip_indicate,
- .transfer = sip_transfer,
- .fixup = sip_fixup,
- .send_digit = sip_senddigit,
- .bridge = ast_rtp_bridge,
- .send_text = sip_sendtext,
-};
-
-/*!
- \brief Thread-safe random number generator
- \return a random number
-
- This function uses a mutex lock to guarantee that no
- two threads will receive the same random number.
- */
-static force_inline int thread_safe_rand(void)
-{
- int val;
-
- ast_mutex_lock(&rand_lock);
- val = rand();
- ast_mutex_unlock(&rand_lock);
-
- return val;
-}
-
-/*! \brief find_sip_method: Find SIP method from header
- * Strictly speaking, SIP methods are case SENSITIVE, but we don't check
- * following Jon Postel's rule: Be gentle in what you accept, strict with what you send */
-int find_sip_method(char *msg)
-{
- int i, res = 0;
-
- if (ast_strlen_zero(msg))
- return 0;
-
- for (i = 1; (i < (sizeof(sip_methods) / sizeof(sip_methods[0]))) && !res; i++) {
- if (!strcasecmp(sip_methods[i].text, msg))
- res = sip_methods[i].id;
- }
- return res;
-}
-
-/*! \brief parse_sip_options: Parse supported header in incoming packet */
-unsigned int parse_sip_options(struct sip_pvt *pvt, char *supported)
-{
- char *next = NULL;
- char *sep = NULL;
- char *temp = ast_strdupa(supported);
- int i;
- unsigned int profile = 0;
-
- if (ast_strlen_zero(supported) )
- return 0;
-
- if (option_debug > 2 && sipdebug)
- ast_log(LOG_DEBUG, "Begin: parsing SIP \"Supported: %s\"\n", supported);
-
- next = temp;
- while (next) {
- char res=0;
- if ( (sep = strchr(next, ',')) != NULL) {
- *sep = '\0';
- sep++;
- }
- while (*next == ' ') /* Skip spaces */
- next++;
- if (option_debug > 2 && sipdebug)
- ast_log(LOG_DEBUG, "Found SIP option: -%s-\n", next);
- for (i=0; (i < (sizeof(sip_options) / sizeof(sip_options[0]))) && !res; i++) {
- if (!strcasecmp(next, sip_options[i].text)) {
- profile |= sip_options[i].id;
- res = 1;
- if (option_debug > 2 && sipdebug)
- ast_log(LOG_DEBUG, "Matched SIP option: %s\n", next);
- }
- }
- if (!res)
- if (option_debug > 2 && sipdebug)
- ast_log(LOG_DEBUG, "Found no match for SIP option: %s (Please file bug report!)\n", next);
- next = sep;
- }
- if (pvt) {
- pvt->sipoptions = profile;
- if (option_debug)
- ast_log(LOG_DEBUG, "* SIP extension value: %d for call %s\n", profile, pvt->callid);
- }
- return profile;
-}
-
-/*! \brief sip_debug_test_addr: See if we pass debug IP filter */
-static inline int sip_debug_test_addr(struct sockaddr_in *addr)
-{
- if (sipdebug == 0)
- return 0;
- if (debugaddr.sin_addr.s_addr) {
- if (((ntohs(debugaddr.sin_port) != 0)
- && (debugaddr.sin_port != addr->sin_port))
- || (debugaddr.sin_addr.s_addr != addr->sin_addr.s_addr))
- return 0;
- }
- return 1;
-}
-
-/*! \brief sip_debug_test_pvt: Test PVT for debugging output */
-static inline int sip_debug_test_pvt(struct sip_pvt *p)
-{
- if (sipdebug == 0)
- return 0;
- return sip_debug_test_addr(((ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) ? &p->recv : &p->sa));
-}
-
-
-/*! \brief __sip_xmit: Transmit SIP message ---*/
-static int __sip_xmit(struct sip_pvt *p, char *data, int len)
-{
- int res;
- char iabuf[INET_ADDRSTRLEN];
-
- if (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE)
- res=sendto(sipsock, data, len, 0, (struct sockaddr *)&p->recv, sizeof(struct sockaddr_in));
- else
- res=sendto(sipsock, data, len, 0, (struct sockaddr *)&p->sa, sizeof(struct sockaddr_in));
-
- if (res != len) {
- ast_log(LOG_WARNING, "sip_xmit of %p (len %d) to %s:%d returned %d: %s\n", data, len, ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), ntohs(p->sa.sin_port), res, strerror(errno));
- }
- return res;
-}
-
-static void sip_destroy(struct sip_pvt *p);
-
-/*! \brief build_via: Build a Via header for a request ---*/
-static void build_via(struct sip_pvt *p, char *buf, int len)
-{
- char iabuf[INET_ADDRSTRLEN];
-
- /* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */
- if (ast_test_flag(p, SIP_NAT) & SIP_NAT_RFC3581)
- snprintf(buf, len, "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x;rport", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch);
- else /* Work around buggy UNIDEN UIP200 firmware */
- snprintf(buf, len, "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch);
-}
-
-/*! \brief ast_sip_ouraddrfor: NAT fix - decide which IP address to use for ASterisk server? ---*/
-/* Only used for outbound registrations */
-static int ast_sip_ouraddrfor(struct in_addr *them, struct in_addr *us)
-{
- /*
- * Using the localaddr structure built up with localnet statements
- * apply it to their address to see if we need to substitute our
- * externip or can get away with our internal bindaddr
- */
- struct sockaddr_in theirs;
- theirs.sin_addr = *them;
- if (localaddr && externip.sin_addr.s_addr &&
- ast_apply_ha(localaddr, &theirs)) {
- char iabuf[INET_ADDRSTRLEN];
- if (externexpire && (time(NULL) >= externexpire)) {
- struct ast_hostent ahp;
- struct hostent *hp;
- time(&externexpire);
- externexpire += externrefresh;
- if ((hp = ast_gethostbyname(externhost, &ahp))) {
- memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
- } else
- ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
- }
- memcpy(us, &externip.sin_addr, sizeof(struct in_addr));
- ast_inet_ntoa(iabuf, sizeof(iabuf), *(struct in_addr *)&them->s_addr);
- ast_log(LOG_DEBUG, "Target address %s is not local, substituting externip\n", iabuf);
- }
- else if (bindaddr.sin_addr.s_addr)
- memcpy(us, &bindaddr.sin_addr, sizeof(struct in_addr));
- else
- return ast_ouraddrfor(them, us);
- return 0;
-}
-
-/*! \brief append_history: Append to SIP dialog history */
-/* Always returns 0 */
-static int append_history(struct sip_pvt *p, const char *event, const char *data)
-{
- struct sip_history *hist, *prev;
- char *c;
-
- if (!recordhistory || !p)
- return 0;
- if(!(hist = malloc(sizeof(struct sip_history)))) {
- ast_log(LOG_WARNING, "Can't allocate memory for history");
- return 0;
- }
- memset(hist, 0, sizeof(struct sip_history));
- snprintf(hist->event, sizeof(hist->event), "%-15s %s", event, data);
- /* Trim up nicely */
- c = hist->event;
- while(*c) {
- if ((*c == '\r') || (*c == '\n')) {
- *c = '\0';
- break;
- }
- c++;
- }
- /* Enqueue into history */
- prev = p->history;
- if (prev) {
- while(prev->next)
- prev = prev->next;
- prev->next = hist;
- } else {
- p->history = hist;
- }
- return 0;
-}
-
-/*! \brief retrans_pkt: Retransmit SIP message if no answer ---*/
-static int retrans_pkt(void *data)
-{
- struct sip_pkt *pkt=data, *prev, *cur = NULL;
- char iabuf[INET_ADDRSTRLEN];
- int reschedule = DEFAULT_RETRANS;
-
- /* Lock channel */
- ast_mutex_lock(&pkt->owner->lock);
-
- if (pkt->retrans < MAX_RETRANS) {
- char buf[80];
-
- pkt->retrans++;
- if (!pkt->timer_t1) { /* Re-schedule using timer_a and timer_t1 */
- if (sipdebug && option_debug > 3)
- ast_log(LOG_DEBUG, "SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n", pkt->retransid, sip_methods[pkt->method].text, pkt->method);
- } else {
- int siptimer_a;
-
- if (sipdebug && option_debug > 3)
- ast_log(LOG_DEBUG, "SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n", pkt->retransid, pkt->retrans, sip_methods[pkt->method].text, pkt->method);
- if (!pkt->timer_a)
- pkt->timer_a = 2 ;
- else
- pkt->timer_a = 2 * pkt->timer_a;
-
- /* For non-invites, a maximum of 4 secs */
- siptimer_a = pkt->timer_t1 * pkt->timer_a; /* Double each time */
- if (pkt->method != SIP_INVITE && siptimer_a > 4000)
- siptimer_a = 4000;
-
- /* Reschedule re-transmit */
- reschedule = siptimer_a;
- if (option_debug > 3)
- ast_log(LOG_DEBUG, "** SIP timers: Rescheduling retransmission %d to %d ms (t1 %d ms (Retrans id #%d)) \n", pkt->retrans +1, siptimer_a, pkt->timer_t1, pkt->retransid);
- }
-
- if (pkt->owner && sip_debug_test_pvt(pkt->owner)) {
- if (ast_test_flag(pkt->owner, SIP_NAT) & SIP_NAT_ROUTE)
- ast_verbose("Retransmitting #%d (NAT) to %s:%d:\n%s\n---\n", pkt->retrans, ast_inet_ntoa(iabuf, sizeof(iabuf), pkt->owner->recv.sin_addr), ntohs(pkt->owner->recv.sin_port), pkt->data);
- else
- ast_verbose("Retransmitting #%d (no NAT) to %s:%d:\n%s\n---\n", pkt->retrans, ast_inet_ntoa(iabuf, sizeof(iabuf), pkt->owner->sa.sin_addr), ntohs(pkt->owner->sa.sin_port), pkt->data);
- }
- snprintf(buf, sizeof(buf), "ReTx %d", reschedule);
-
- append_history(pkt->owner, buf, pkt->data);
- __sip_xmit(pkt->owner, pkt->data, pkt->packetlen);
- ast_mutex_unlock(&pkt->owner->lock);
- return reschedule;
- }
- /* Too many retries */
- if (pkt->owner && pkt->method != SIP_OPTIONS) {
- if (ast_test_flag(pkt, FLAG_FATAL) || sipdebug) /* Tell us if it's critical or if we're debugging */
- ast_log(LOG_WARNING, "Maximum retries exceeded on transmission %s for seqno %d (%s %s)\n", pkt->owner->callid, pkt->seqno, (ast_test_flag(pkt, FLAG_FATAL)) ? "Critical" : "Non-critical", (ast_test_flag(pkt, FLAG_RESPONSE)) ? "Response" : "Request");
- } else {
- if (pkt->method == SIP_OPTIONS && sipdebug)
- ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s) \n", pkt->owner->callid);
- }
- append_history(pkt->owner, "MaxRetries", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)");
-
- pkt->retransid = -1;
-
- if (ast_test_flag(pkt, FLAG_FATAL)) {
- while(pkt->owner->owner && ast_mutex_trylock(&pkt->owner->owner->lock)) {
- ast_mutex_unlock(&pkt->owner->lock);
- usleep(1);
- ast_mutex_lock(&pkt->owner->lock);
- }
- if (pkt->owner->owner) {
- ast_set_flag(pkt->owner, SIP_ALREADYGONE);
- ast_log(LOG_WARNING, "Hanging up call %s - no reply to our critical packet.\n", pkt->owner->callid);
- ast_queue_hangup(pkt->owner->owner);
- ast_mutex_unlock(&pkt->owner->owner->lock);
- } else {
- /* If no channel owner, destroy now */
- ast_set_flag(pkt->owner, SIP_NEEDDESTROY);
- }
- }
- /* In any case, go ahead and remove the packet */
- prev = NULL;
- cur = pkt->owner->packets;
- while(cur) {
- if (cur == pkt)
- break;
- prev = cur;
- cur = cur->next;
- }
- if (cur) {
- if (prev)
- prev->next = cur->next;
- else
- pkt->owner->packets = cur->next;
- ast_mutex_unlock(&pkt->owner->lock);
- free(cur);
- pkt = NULL;
- } else
- ast_log(LOG_WARNING, "Weird, couldn't find packet owner!\n");
- if (pkt)
- ast_mutex_unlock(&pkt->owner->lock);
- return 0;
-}
-
-/*! \brief __sip_reliable_xmit: transmit packet with retransmits ---*/
-static int __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, char *data, int len, int fatal, int sipmethod)
-{
- struct sip_pkt *pkt;
- int siptimer_a = DEFAULT_RETRANS;
-
- pkt = malloc(sizeof(struct sip_pkt) + len + 1);
- if (!pkt)
- return -1;
- memset(pkt, 0, sizeof(struct sip_pkt));
- memcpy(pkt->data, data, len);
- pkt->method = sipmethod;
- pkt->packetlen = len;
- pkt->next = p->packets;
- pkt->owner = p;
- pkt->seqno = seqno;
- pkt->flags = resp;
- pkt->data[len] = '\0';
- pkt->timer_t1 = p->timer_t1; /* Set SIP timer T1 */
- if (fatal)
- ast_set_flag(pkt, FLAG_FATAL);
- if (pkt->timer_t1)
- siptimer_a = pkt->timer_t1 * 2;
-
- /* Schedule retransmission */
- pkt->retransid = ast_sched_add_variable(sched, siptimer_a, retrans_pkt, pkt, 1);
- if (option_debug > 3 && sipdebug)
- ast_log(LOG_DEBUG, "*** SIP TIMER: Initalizing retransmit timer on packet: Id #%d\n", pkt->retransid);
- pkt->next = p->packets;
- p->packets = pkt;
-
- __sip_xmit(pkt->owner, pkt->data, pkt->packetlen); /* Send packet */
- if (sipmethod == SIP_INVITE) {
- /* Note this is a pending invite */
- p->pendinginvite = seqno;
- }
- return 0;
-}
-
-/*! \brief __sip_autodestruct: Kill a call (called by scheduler) ---*/
-static int __sip_autodestruct(void *data)
-{
- struct sip_pvt *p = data;
-
-
- /* If this is a subscription, tell the phone that we got a timeout */
- if (p->subscribed) {
- p->subscribed = TIMEOUT;
- transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, 1); /* Send first notification */
- p->subscribed = NONE;
- append_history(p, "Subscribestatus", "timeout");
- return 10000; /* Reschedule this destruction so that we know that it's gone */
- }
-
- /* This scheduled event is now considered done. */
- p->autokillid = -1;
-
- ast_log(LOG_DEBUG, "Auto destroying call '%s'\n", p->callid);
- append_history(p, "AutoDestroy", "");
- if (p->owner) {
- ast_log(LOG_WARNING, "Autodestruct on call '%s' with owner in place\n", p->callid);
- ast_queue_hangup(p->owner);
- } else {
- sip_destroy(p);
- }
- return 0;
-}
-
-/*! \brief sip_scheddestroy: Schedule destruction of SIP call ---*/
-static int sip_scheddestroy(struct sip_pvt *p, int ms)
-{
- char tmp[80];
- if (sip_debug_test_pvt(p))
- ast_verbose("Scheduling destruction of call '%s' in %d ms\n", p->callid, ms);
- if (recordhistory) {
- snprintf(tmp, sizeof(tmp), "%d ms", ms);
- append_history(p, "SchedDestroy", tmp);
- }
-
- if (p->autokillid > -1)
- ast_sched_del(sched, p->autokillid);
- p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, p);
- return 0;
-}
-
-/*! \brief sip_cancel_destroy: Cancel destruction of SIP call ---*/
-static int sip_cancel_destroy(struct sip_pvt *p)
-{
- if (p->autokillid > -1)
- ast_sched_del(sched, p->autokillid);
- append_history(p, "CancelDestroy", "");
- p->autokillid = -1;
- return 0;
-}
-
-/*! \brief __sip_ack: Acknowledges receipt of a packet and stops retransmission ---*/
-static int __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod)
-{
- struct sip_pkt *cur, *prev = NULL;
- int res = -1;
- int resetinvite = 0;
- /* Just in case... */
- char *msg;
-
- msg = sip_methods[sipmethod].text;
-
- cur = p->packets;
- while(cur) {
- if ((cur->seqno == seqno) && ((ast_test_flag(cur, FLAG_RESPONSE)) == resp) &&
- ((ast_test_flag(cur, FLAG_RESPONSE)) ||
- (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) {
- ast_mutex_lock(&p->lock);
- if (!resp && (seqno == p->pendinginvite)) {
- ast_log(LOG_DEBUG, "Acked pending invite %d\n", p->pendinginvite);
- p->pendinginvite = 0;
- resetinvite = 1;
- }
- /* this is our baby */
- if (prev)
- prev->next = cur->next;
- else
- p->packets = cur->next;
- if (cur->retransid > -1) {
- if (sipdebug && option_debug > 3)
- ast_log(LOG_DEBUG, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid);
- ast_sched_del(sched, cur->retransid);
- }
- free(cur);
- ast_mutex_unlock(&p->lock);
- res = 0;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- ast_log(LOG_DEBUG, "Stopping retransmission on '%s' of %s %d: Match %s\n", p->callid, resp ? "Response" : "Request", seqno, res ? "Not Found" : "Found");
- return res;
-}
-
-/* Pretend to ack all packets */
-static int __sip_pretend_ack(struct sip_pvt *p)
-{
- struct sip_pkt *cur=NULL;
-
- while(p->packets) {
- if (cur == p->packets) {
- ast_log(LOG_WARNING, "Have a packet that doesn't want to give up! %s\n", sip_methods[cur->method].text);
- return -1;
- }
- cur = p->packets;
- if (cur->method)
- __sip_ack(p, p->packets->seqno, (ast_test_flag(p->packets, FLAG_RESPONSE)), cur->method);
- else { /* Unknown packet type */
- char *c;
- char method[128];
- ast_copy_string(method, p->packets->data, sizeof(method));
- c = ast_skip_blanks(method); /* XXX what ? */
- *c = '\0';
- __sip_ack(p, p->packets->seqno, (ast_test_flag(p->packets, FLAG_RESPONSE)), find_sip_method(method));
- }
- }
- return 0;
-}
-
-/*! \brief __sip_semi_ack: Acks receipt of packet, keep it around (used for provisional responses) ---*/
-static int __sip_semi_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod)
-{
- struct sip_pkt *cur;
- int res = -1;
- char *msg = sip_methods[sipmethod].text;
-
- cur = p->packets;
- while(cur) {
- if ((cur->seqno == seqno) && ((ast_test_flag(cur, FLAG_RESPONSE)) == resp) &&
- ((ast_test_flag(cur, FLAG_RESPONSE)) ||
- (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) {
- /* this is our baby */
- if (cur->retransid > -1) {
- if (option_debug > 3 && sipdebug)
- ast_log(LOG_DEBUG, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, msg);
- ast_sched_del(sched, cur->retransid);
- }
- cur->retransid = -1;
- res = 0;
- break;
- }
- cur = cur->next;
- }
- ast_log(LOG_DEBUG, "(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %d: %s\n", p->callid, resp ? "Response" : "Request", seqno, res ? "Not Found" : "Found");
- return res;
-}
-
-static void parse_request(struct sip_request *req);
-static char *get_header(struct sip_request *req, char *name);
-static void copy_request(struct sip_request *dst,struct sip_request *src);
-
-/*! \brief parse_copy: Copy SIP request, parse it */
-static void parse_copy(struct sip_request *dst, struct sip_request *src)
-{
- memset(dst, 0, sizeof(*dst));
- memcpy(dst->data, src->data, sizeof(dst->data));
- dst->len = src->len;
- parse_request(dst);
-}
-
-/*! \brief send_response: Transmit response on SIP request---*/
-static int send_response(struct sip_pvt *p, struct sip_request *req, int reliable, int seqno)
-{
- int res;
- char iabuf[INET_ADDRSTRLEN];
- struct sip_request tmp;
- char tmpmsg[80];
-
- if (sip_debug_test_pvt(p)) {
- if (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE)
- ast_verbose("%sTransmitting (NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port), req->data);
- else
- ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), ntohs(p->sa.sin_port), req->data);
- }
- if (reliable) {
- if (recordhistory) {
- parse_copy(&tmp, req);
- snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
- append_history(p, "TxRespRel", tmpmsg);
- }
- res = __sip_reliable_xmit(p, seqno, 1, req->data, req->len, (reliable > 1), req->method);
- } else {
- if (recordhistory) {
- parse_copy(&tmp, req);
- snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
- append_history(p, "TxResp", tmpmsg);
- }
- res = __sip_xmit(p, req->data, req->len);
- }
- if (res > 0)
- return 0;
- return res;
-}
-
-/*! \brief send_request: Send SIP Request to the other part of the dialogue ---*/
-static int send_request(struct sip_pvt *p, struct sip_request *req, int reliable, int seqno)
-{
- int res;
- char iabuf[INET_ADDRSTRLEN];
- struct sip_request tmp;
- char tmpmsg[80];
-
- if (sip_debug_test_pvt(p)) {
- if (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE)
- ast_verbose("%sTransmitting (NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port), req->data);
- else
- ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), ntohs(p->sa.sin_port), req->data);
- }
- if (reliable) {
- if (recordhistory) {
- parse_copy(&tmp, req);
- snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
- append_history(p, "TxReqRel", tmpmsg);
- }
- res = __sip_reliable_xmit(p, seqno, 0, req->data, req->len, (reliable > 1), req->method);
- } else {
- if (recordhistory) {
- parse_copy(&tmp, req);
- snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
- append_history(p, "TxReq", tmpmsg);
- }
- res = __sip_xmit(p, req->data, req->len);
- }
- return res;
-}
-
-/*! \brief get_in_brackets: Pick out text in brackets from character string ---*/
-/* returns pointer to terminated stripped string. modifies input string. */
-static char *get_in_brackets(char *tmp)
-{
- char *parse;
- char *first_quote;
- char *first_bracket;
- char *second_bracket;
- char last_char;
-
- parse = tmp;
- while (1) {
- first_quote = strchr(parse, '"');
- first_bracket = strchr(parse, '<');
- if (first_quote && first_bracket && (first_quote < first_bracket)) {
- last_char = '\0';
- for (parse = first_quote + 1; *parse; parse++) {
- if ((*parse == '"') && (last_char != '\\'))
- break;
- last_char = *parse;
- }
- if (!*parse) {
- ast_log(LOG_WARNING, "No closing quote found in '%s'\n", tmp);
- return tmp;
- }
- parse++;
- continue;
- }
- if (first_bracket) {
- second_bracket = strchr(first_bracket + 1, '>');
- if (second_bracket) {
- *second_bracket = '\0';
- return first_bracket + 1;
- } else {
- ast_log(LOG_WARNING, "No closing bracket found in '%s'\n", tmp);
- return tmp;
- }
- }
- return tmp;
- }
-}
-
-/*! \brief sip_sendtext: Send SIP MESSAGE text within a call ---*/
-/* Called from PBX core text message functions */
-static int sip_sendtext(struct ast_channel *ast, const char *text)
-{
- struct sip_pvt *p = ast->tech_pvt;
- int debug=sip_debug_test_pvt(p);
-
- if (debug)
- ast_verbose("Sending text %s on %s\n", text, ast->name);
- if (!p)
- return -1;
- if (ast_strlen_zero(text))
- return 0;
- if (debug)
- ast_verbose("Really sending text %s on %s\n", text, ast->name);
- transmit_message_with_text(p, text);
- return 0;
-}
-
-/*! \brief realtime_update_peer: Update peer object in realtime storage ---*/
-static void realtime_update_peer(const char *peername, struct sockaddr_in *sin, const char *username, const char *fullcontact, int expirey)
-{
- char port[10];
- char ipaddr[20];
- char regseconds[20];
- time_t nowtime;
-
- time(&nowtime);
- nowtime += expirey;
- snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime); /* Expiration time */
- ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
- snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
-
- if (fullcontact)
- ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, "username", username, "fullcontact", fullcontact, NULL);
- else
- ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, "username", username, NULL);
-}
-
-/*! \brief register_peer_exten: Automatically add peer extension to dial plan ---*/
-static void register_peer_exten(struct sip_peer *peer, int onoff)
-{
- char multi[256];
- char *stringp, *ext;
- if (!ast_strlen_zero(regcontext)) {
- ast_copy_string(multi, ast_strlen_zero(peer->regexten) ? peer->name : peer->regexten, sizeof(multi));
- stringp = multi;
- while((ext = strsep(&stringp, "&"))) {
- if (onoff)
- ast_add_extension(regcontext, 1, ext, 1, NULL, NULL, "Noop", strdup(peer->name), free, channeltype);
- else
- ast_context_remove_extension(regcontext, ext, 1, NULL);
- }
- }
-}
-
-/*! \brief sip_destroy_peer: Destroy peer object from memory */
-static void sip_destroy_peer(struct sip_peer *peer)
-{
- /* Delete it, it needs to disappear */
- if (peer->call)
- sip_destroy(peer->call);
- if (peer->chanvars) {
- ast_variables_destroy(peer->chanvars);
- peer->chanvars = NULL;
- }
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
- register_peer_exten(peer, 0);
- ast_free_ha(peer->ha);
- if (ast_test_flag(peer, SIP_SELFDESTRUCT))
- apeerobjs--;
- else if (ast_test_flag(peer, SIP_REALTIME))
- rpeerobjs--;
- else
- speerobjs--;
- clear_realm_authentication(peer->auth);
- peer->auth = (struct sip_auth *) NULL;
- if (peer->dnsmgr)
- ast_dnsmgr_release(peer->dnsmgr);
- free(peer);
-}
-
-/*! \brief update_peer: Update peer data in database (if used) ---*/
-static void update_peer(struct sip_peer *p, int expiry)
-{
- int rtcachefriends = ast_test_flag(&(p->flags_page2), SIP_PAGE2_RTCACHEFRIENDS);
- if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTUPDATE) &&
- (ast_test_flag(p, SIP_REALTIME) || rtcachefriends)) {
- realtime_update_peer(p->name, &p->addr, p->username, rtcachefriends ? p->fullcontact : NULL, expiry);
- }
-}
-
-
-/*! \brief realtime_peer: Get peer from realtime storage
- * Checks the "sippeers" realtime family from extconfig.conf */
-static struct sip_peer *realtime_peer(const char *peername, struct sockaddr_in *sin)
-{
- struct sip_peer *peer=NULL;
- struct ast_variable *var;
- struct ast_variable *tmp;
- char *newpeername = (char *) peername;
- char iabuf[80];
-
- /* First check on peer name */
- if (newpeername)
- var = ast_load_realtime("sippeers", "name", peername, NULL);
- else if (sin) { /* Then check on IP address */
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr);
- var = ast_load_realtime("sippeers", "host", iabuf, NULL); /* First check for fixed IP hosts */
- if (!var)
- var = ast_load_realtime("sippeers", "ipaddr", iabuf, NULL); /* Then check for registred hosts */
-
- } else
- return NULL;
-
- if (!var)
- return NULL;
-
- tmp = var;
- /* If this is type=user, then skip this object. */
- while(tmp) {
- if (!strcasecmp(tmp->name, "type") &&
- !strcasecmp(tmp->value, "user")) {
- ast_variables_destroy(var);
- return NULL;
- } else if (!newpeername && !strcasecmp(tmp->name, "name")) {
- newpeername = tmp->value;
- }
- tmp = tmp->next;
- }
-
- if (!newpeername) { /* Did not find peer in realtime */
- ast_log(LOG_WARNING, "Cannot Determine peer name ip=%s\n", iabuf);
- ast_variables_destroy(var);
- return (struct sip_peer *) NULL;
- }
-
- /* Peer found in realtime, now build it in memory */
- peer = build_peer(newpeername, var, !ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS));
- if (!peer) {
- ast_variables_destroy(var);
- return (struct sip_peer *) NULL;
- }
-
- if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
- /* Cache peer */
- ast_copy_flags((&peer->flags_page2),(&global_flags_page2), SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS);
- if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTAUTOCLEAR)) {
- if (peer->expire > -1) {
- ast_sched_del(sched, peer->expire);
- }
- peer->expire = ast_sched_add(sched, (global_rtautoclear) * 1000, expire_register, (void *)peer);
- }
- ASTOBJ_CONTAINER_LINK(&peerl,peer);
- } else {
- ast_set_flag(peer, SIP_REALTIME);
- }
- ast_variables_destroy(var);
-
- return peer;
-}
-
-/*! \brief sip_addrcmp: Support routine for find_peer ---*/
-static int sip_addrcmp(char *name, struct sockaddr_in *sin)
-{
- /* We know name is the first field, so we can cast */
- struct sip_peer *p = (struct sip_peer *)name;
- return !(!inaddrcmp(&p->addr, sin) ||
- (ast_test_flag(p, SIP_INSECURE_PORT) &&
- (p->addr.sin_addr.s_addr == sin->sin_addr.s_addr)));
-}
-
-/*! \brief find_peer: Locate peer by name or ip address
- * This is used on incoming SIP message to find matching peer on ip
- or outgoing message to find matching peer on name */
-static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime)
-{
- struct sip_peer *p = NULL;
-
- if (peer)
- p = ASTOBJ_CONTAINER_FIND(&peerl,peer);
- else
- p = ASTOBJ_CONTAINER_FIND_FULL(&peerl,sin,name,sip_addr_hashfunc,1,sip_addrcmp);
-
- if (!p && realtime) {
- p = realtime_peer(peer, sin);
- }
-
- return p;
-}
-
-/*! \brief sip_destroy_user: Remove user object from in-memory storage ---*/
-static void sip_destroy_user(struct sip_user *user)
-{
- ast_free_ha(user->ha);
- if (user->chanvars) {
- ast_variables_destroy(user->chanvars);
- user->chanvars = NULL;
- }
- if (ast_test_flag(user, SIP_REALTIME))
- ruserobjs--;
- else
- suserobjs--;
- free(user);
-}
-
-/*! \brief realtime_user: Load user from realtime storage
- * Loads user from "sipusers" category in realtime (extconfig.conf)
- * Users are matched on From: user name (the domain in skipped) */
-static struct sip_user *realtime_user(const char *username)
-{
- struct ast_variable *var;
- struct ast_variable *tmp;
- struct sip_user *user = NULL;
-
- var = ast_load_realtime("sipusers", "name", username, NULL);
-
- if (!var)
- return NULL;
-
- tmp = var;
- while (tmp) {
- if (!strcasecmp(tmp->name, "type") &&
- !strcasecmp(tmp->value, "peer")) {
- ast_variables_destroy(var);
- return NULL;
- }
- tmp = tmp->next;
- }
-
-
-
- user = build_user(username, var, !ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS));
-
- if (!user) { /* No user found */
- ast_variables_destroy(var);
- return NULL;
- }
-
- if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
- ast_set_flag((&user->flags_page2), SIP_PAGE2_RTCACHEFRIENDS);
- suserobjs++;
- ASTOBJ_CONTAINER_LINK(&userl,user);
- } else {
- /* Move counter from s to r... */
- suserobjs--;
- ruserobjs++;
- ast_set_flag(user, SIP_REALTIME);
- }
- ast_variables_destroy(var);
- return user;
-}
-
-/*! \brief find_user: Locate user by name
- * Locates user by name (From: sip uri user name part) first
- * from in-memory list (static configuration) then from
- * realtime storage (defined in extconfig.conf) */
-static struct sip_user *find_user(const char *name, int realtime)
-{
- struct sip_user *u = NULL;
- u = ASTOBJ_CONTAINER_FIND(&userl,name);
- if (!u && realtime) {
- u = realtime_user(name);
- }
- return u;
-}
-
-/*! \brief create_addr_from_peer: create address structure from peer reference ---*/
-static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer)
-{
- char *callhost;
-
- if ((peer->addr.sin_addr.s_addr || peer->defaddr.sin_addr.s_addr) &&
- (!peer->maxms || ((peer->lastms >= 0) && (peer->lastms <= peer->maxms)))) {
- if (peer->addr.sin_addr.s_addr) {
- r->sa.sin_family = peer->addr.sin_family;
- r->sa.sin_addr = peer->addr.sin_addr;
- r->sa.sin_port = peer->addr.sin_port;
- } else {
- r->sa.sin_family = peer->defaddr.sin_family;
- r->sa.sin_addr = peer->defaddr.sin_addr;
- r->sa.sin_port = peer->defaddr.sin_port;
- }
- memcpy(&r->recv, &r->sa, sizeof(r->recv));
- } else {
- return -1;
- }
-
- ast_copy_flags(r, peer, SIP_FLAGS_TO_COPY);
- r->capability = peer->capability;
- r->prefs = peer->prefs;
- if (r->rtp) {
- ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(r, SIP_NAT) & SIP_NAT_ROUTE));
- ast_rtp_setnat(r->rtp, (ast_test_flag(r, SIP_NAT) & SIP_NAT_ROUTE));
- }
- if (r->vrtp) {
- ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (ast_test_flag(r, SIP_NAT) & SIP_NAT_ROUTE));
- ast_rtp_setnat(r->vrtp, (ast_test_flag(r, SIP_NAT) & SIP_NAT_ROUTE));
- }
- ast_copy_string(r->peername, peer->username, sizeof(r->peername));
- ast_copy_string(r->authname, peer->username, sizeof(r->authname));
- ast_copy_string(r->username, peer->username, sizeof(r->username));
- ast_copy_string(r->peersecret, peer->secret, sizeof(r->peersecret));
- ast_copy_string(r->peermd5secret, peer->md5secret, sizeof(r->peermd5secret));
- ast_copy_string(r->tohost, peer->tohost, sizeof(r->tohost));
- ast_copy_string(r->fullcontact, peer->fullcontact, sizeof(r->fullcontact));
- if (!r->initreq.headers && !ast_strlen_zero(peer->fromdomain)) {
- if ((callhost = strchr(r->callid, '@'))) {
- strncpy(callhost + 1, peer->fromdomain, sizeof(r->callid) - (callhost - r->callid) - 2);
- }
- }
- if (ast_strlen_zero(r->tohost)) {
- if (peer->addr.sin_addr.s_addr)
- ast_inet_ntoa(r->tohost, sizeof(r->tohost), peer->addr.sin_addr);
- else
- ast_inet_ntoa(r->tohost, sizeof(r->tohost), peer->defaddr.sin_addr);
- }
- if (!ast_strlen_zero(peer->fromdomain))
- ast_copy_string(r->fromdomain, peer->fromdomain, sizeof(r->fromdomain));
- if (!ast_strlen_zero(peer->fromuser))
- ast_copy_string(r->fromuser, peer->fromuser, sizeof(r->fromuser));
- r->maxtime = peer->maxms;
- r->callgroup = peer->callgroup;
- r->pickupgroup = peer->pickupgroup;
- /* Set timer T1 to RTT for this peer (if known by qualify=) */
- if (peer->maxms && peer->lastms)
- r->timer_t1 = peer->lastms;
- if ((ast_test_flag(r, SIP_DTMF) == SIP_DTMF_RFC2833) || (ast_test_flag(r, SIP_DTMF) == SIP_DTMF_AUTO))
- r->noncodeccapability |= AST_RTP_DTMF;
- else
- r->noncodeccapability &= ~AST_RTP_DTMF;
- ast_copy_string(r->context, peer->context,sizeof(r->context));
- r->rtptimeout = peer->rtptimeout;
- r->rtpholdtimeout = peer->rtpholdtimeout;
- r->rtpkeepalive = peer->rtpkeepalive;
- if (peer->call_limit)
- ast_set_flag(r, SIP_CALL_LIMIT);
-
- return 0;
-}
-
-/*! \brief create_addr: create address structure from peer name
- * Or, if peer not found, find it in the global DNS
- * returns TRUE (-1) on failure, FALSE on success */
-static int create_addr(struct sip_pvt *dialog, char *opeer)
-{
- struct hostent *hp;
- struct ast_hostent ahp;
- struct sip_peer *p;
- int found=0;
- char *port;
- int portno;
- char host[MAXHOSTNAMELEN], *hostn;
- char peer[256];
-
- ast_copy_string(peer, opeer, sizeof(peer));
- port = strchr(peer, ':');
- if (port) {
- *port = '\0';
- port++;
- }
- dialog->sa.sin_family = AF_INET;
- dialog->timer_t1 = 500; /* Default SIP retransmission timer T1 (RFC 3261) */
- p = find_peer(peer, NULL, 1);
-
- if (p) {
- found++;
- if (create_addr_from_peer(dialog, p))
- ASTOBJ_UNREF(p, sip_destroy_peer);
- }
- if (!p) {
- if (found)
- return -1;
-
- hostn = peer;
- if (port)
- portno = atoi(port);
- else
- portno = DEFAULT_SIP_PORT;
- if (srvlookup) {
- char service[MAXHOSTNAMELEN];
- int tportno;
- int ret;
- snprintf(service, sizeof(service), "_sip._udp.%s", peer);
- ret = ast_get_srv(NULL, host, sizeof(host), &tportno, service);
- if (ret > 0) {
- hostn = host;
- portno = tportno;
- }
- }
- hp = ast_gethostbyname(hostn, &ahp);
- if (hp) {
- ast_copy_string(dialog->tohost, peer, sizeof(dialog->tohost));
- memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
- dialog->sa.sin_port = htons(portno);
- memcpy(&dialog->recv, &dialog->sa, sizeof(dialog->recv));
- return 0;
- } else {
- ast_log(LOG_WARNING, "No such host: %s\n", peer);
- return -1;
- }
- } else {
- ASTOBJ_UNREF(p, sip_destroy_peer);
- return 0;
- }
-}
-
-/*! \brief auto_congest: Scheduled congestion on a call ---*/
-static int auto_congest(void *nothing)
-{
- struct sip_pvt *p = nothing;
- ast_mutex_lock(&p->lock);
- p->initid = -1;
- if (p->owner) {
- if (!ast_mutex_trylock(&p->owner->lock)) {
- ast_log(LOG_NOTICE, "Auto-congesting %s\n", p->owner->name);
- ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- ast_mutex_unlock(&p->owner->lock);
- }
- }
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-
-
-
-/*! \brief sip_call: Initiate SIP call from PBX
- * used from the dial() application */
-static int sip_call(struct ast_channel *ast, char *dest, int timeout)
-{
- int res;
- struct sip_pvt *p;
-#ifdef OSP_SUPPORT
- char *osphandle = NULL;
-#endif
- struct varshead *headp;
- struct ast_var_t *current;
-
-
-
- p = ast->tech_pvt;
- if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "sip_call called on %s, neither down nor reserved\n", ast->name);
- return -1;
- }
-
-
- /* Check whether there is vxml_url, distinctive ring variables */
-
- headp=&ast->varshead;
- AST_LIST_TRAVERSE(headp,current,entries) {
- /* Check whether there is a VXML_URL variable */
- if (!p->options->vxml_url && !strcasecmp(ast_var_name(current), "VXML_URL")) {
- p->options->vxml_url = ast_var_value(current);
- } else if (!p->options->uri_options && !strcasecmp(ast_var_name(current), "SIP_URI_OPTIONS")) {
- p->options->uri_options = ast_var_value(current);
- } else if (!p->options->distinctive_ring && !strcasecmp(ast_var_name(current), "ALERT_INFO")) {
- /* Check whether there is a ALERT_INFO variable */
- p->options->distinctive_ring = ast_var_value(current);
- } else if (!p->options->addsipheaders && !strncasecmp(ast_var_name(current), "SIPADDHEADER", strlen("SIPADDHEADER"))) {
- /* Check whether there is a variable with a name starting with SIPADDHEADER */
- p->options->addsipheaders = 1;
- }
-
-
-#ifdef OSP_SUPPORT
- else if (!p->options->osptoken && !strcasecmp(ast_var_name(current), "OSPTOKEN")) {
- p->options->osptoken = ast_var_value(current);
- } else if (!osphandle && !strcasecmp(ast_var_name(current), "OSPHANDLE")) {
- osphandle = ast_var_value(current);
- }
-#endif
- }
-
- res = 0;
- ast_set_flag(p, SIP_OUTGOING);
-#ifdef OSP_SUPPORT
- if (!p->options->osptoken || !osphandle || (sscanf(osphandle, "%d", &p->osphandle) != 1)) {
- /* Force Disable OSP support */
- ast_log(LOG_DEBUG, "Disabling OSP support for this call. osptoken = %s, osphandle = %s\n", p->options->osptoken, osphandle);
- p->options->osptoken = NULL;
- osphandle = NULL;
- p->osphandle = -1;
- }
-#endif
- ast_log(LOG_DEBUG, "Outgoing Call for %s\n", p->username);
- res = update_call_counter(p, INC_CALL_LIMIT);
- if ( res != -1 ) {
- p->callingpres = ast->cid.cid_pres;
- p->jointcapability = p->capability;
- transmit_invite(p, SIP_INVITE, 1, 2);
- if (p->maxtime) {
- /* Initialize auto-congest time */
- p->initid = ast_sched_add(sched, p->maxtime * 4, auto_congest, p);
- }
- }
- return res;
-}
-
-/*! \brief sip_registry_destroy: Destroy registry object ---*/
-/* Objects created with the register= statement in static configuration */
-static void sip_registry_destroy(struct sip_registry *reg)
-{
- /* Really delete */
- if (reg->call) {
- /* Clear registry before destroying to ensure
- we don't get reentered trying to grab the registry lock */
- reg->call->registry = NULL;
- sip_destroy(reg->call);
- }
- if (reg->expire > -1)
- ast_sched_del(sched, reg->expire);
- if (reg->timeout > -1)
- ast_sched_del(sched, reg->timeout);
- regobjs--;
- free(reg);
-
-}
-
-/*! \brief __sip_destroy: Execute destrucion of call structure, release memory---*/
-static void __sip_destroy(struct sip_pvt *p, int lockowner)
-{
- struct sip_pvt *cur, *prev = NULL;
- struct sip_pkt *cp;
- struct sip_history *hist;
-
- if (sip_debug_test_pvt(p))
- ast_verbose("Destroying call '%s'\n", p->callid);
-
-#ifdef SIP_MIDCOM
- if (m_cb)
- m_cb->__sip_destroy_hook(p);
-#endif
-
- if (dumphistory)
- sip_dump_history(p);
-
- if (p->options)
- free(p->options);
-
- if (p->stateid > -1)
- ast_extension_state_del(p->stateid, NULL);
- if (p->initid > -1)
- ast_sched_del(sched, p->initid);
- if (p->autokillid > -1)
- ast_sched_del(sched, p->autokillid);
-
- if (p->rtp) {
- ast_rtp_destroy(p->rtp);
- }
- if (p->vrtp) {
- ast_rtp_destroy(p->vrtp);
- }
- if (p->route) {
- free_old_route(p->route);
- p->route = NULL;
- }
- if (p->registry) {
- if (p->registry->call == p)
- p->registry->call = NULL;
- ASTOBJ_UNREF(p->registry,sip_registry_destroy);
- }
-
- if (p->rpid)
- free(p->rpid);
-
- if (p->rpid_from)
- free(p->rpid_from);
-
- /* Unlink us from the owner if we have one */
- if (p->owner) {
- if (lockowner)
- ast_mutex_lock(&p->owner->lock);
- ast_log(LOG_DEBUG, "Detaching from %s\n", p->owner->name);
- p->owner->tech_pvt = NULL;
- if (lockowner)
- ast_mutex_unlock(&p->owner->lock);
- }
- /* Clear history */
- while(p->history) {
- hist = p->history;
- p->history = p->history->next;
- free(hist);
- }
-
- cur = iflist;
- while(cur) {
- if (cur == p) {
- if (prev)
- prev->next = cur->next;
- else
- iflist = cur->next;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- if (!cur) {
- ast_log(LOG_WARNING, "Trying to destroy \"%s\", not found in dialog list?!?! \n", p->callid);
- return;
- }
- if (p->initid > -1)
- ast_sched_del(sched, p->initid);
-
- while((cp = p->packets)) {
- p->packets = p->packets->next;
- if (cp->retransid > -1) {
- ast_sched_del(sched, cp->retransid);
- }
- free(cp);
- }
- if (p->chanvars) {
- ast_variables_destroy(p->chanvars);
- p->chanvars = NULL;
- }
- ast_mutex_destroy(&p->lock);
- free(p);
-}
-
-/*! \brief update_call_counter: Handle call_limit for SIP users
- * Note: This is going to be replaced by app_groupcount
- * Thought: For realtime, we should propably update storage with inuse counter... */
-static int update_call_counter(struct sip_pvt *fup, int event)
-{
- char name[256];
- int *inuse, *call_limit;
- int outgoing = ast_test_flag(fup, SIP_OUTGOING);
- struct sip_user *u = NULL;
- struct sip_peer *p = NULL;
-
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Updating call counter for %s call\n", outgoing ? "outgoing" : "incoming");
- /* Test if we need to check call limits, in order to avoid
- realtime lookups if we do not need it */
- if (!ast_test_flag(fup, SIP_CALL_LIMIT))
- return 0;
-
- ast_copy_string(name, fup->username, sizeof(name));
-
- /* Check the list of users */
- u = find_user(name, 1);
- if (u) {
- inuse = &u->inUse;
- call_limit = &u->call_limit;
- p = NULL;
- } else {
- /* Try to find peer */
- if (!p)
- p = find_peer(fup->peername, NULL, 1);
- if (p) {
- inuse = &p->inUse;
- call_limit = &p->call_limit;
- ast_copy_string(name, fup->peername, sizeof(name));
- } else {
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "%s is not a local user, no call limit\n", name);
- return 0;
- }
- }
- switch(event) {
- /* incoming and outgoing affects the inUse counter */
- case DEC_CALL_LIMIT:
- if ( *inuse > 0 ) {
- if (ast_test_flag(fup,SIP_INC_COUNT))
- (*inuse)--;
- } else {
- *inuse = 0;
- }
- if (option_debug > 1 || sipdebug) {
- ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
- }
- break;
- case INC_CALL_LIMIT:
- if (*call_limit > 0 ) {
- if (*inuse >= *call_limit) {
- ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
- if (u)
- ASTOBJ_UNREF(u,sip_destroy_user);
- else
- ASTOBJ_UNREF(p,sip_destroy_peer);
- return -1;
- }
- }
- (*inuse)++;
- ast_set_flag(fup,SIP_INC_COUNT);
- if (option_debug > 1 || sipdebug) {
- ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit);
- }
- break;
- default:
- ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event);
- }
- if (u)
- ASTOBJ_UNREF(u,sip_destroy_user);
- else
- ASTOBJ_UNREF(p,sip_destroy_peer);
- return 0;
-}
-
-/*! \brief sip_destroy: Destroy SIP call structure ---*/
-static void sip_destroy(struct sip_pvt *p)
-{
- ast_mutex_lock(&iflock);
- __sip_destroy(p, 1);
- ast_mutex_unlock(&iflock);
-}
-
-
-static int transmit_response_reliable(struct sip_pvt *p, char *msg, struct sip_request *req, int fatal);
-
-/*! \brief hangup_sip2cause: Convert SIP hangup causes to Asterisk hangup causes ---*/
-static int hangup_sip2cause(int cause)
-{
-/* Possible values taken from causes.h */
-
- switch(cause) {
- case 603: /* Declined */
- case 403: /* Not found */
- return AST_CAUSE_CALL_REJECTED;
- case 404: /* Not found */
- return AST_CAUSE_UNALLOCATED;
- case 408: /* No reaction */
- return AST_CAUSE_NO_USER_RESPONSE;
- case 480: /* No answer */
- return AST_CAUSE_FAILURE;
- case 483: /* Too many hops */
- return AST_CAUSE_NO_ANSWER;
- case 486: /* Busy everywhere */
- return AST_CAUSE_BUSY;
- case 488: /* No codecs approved */
- return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
- case 500: /* Server internal failure */
- return AST_CAUSE_FAILURE;
- case 501: /* Call rejected */
- return AST_CAUSE_FACILITY_REJECTED;
- case 502:
- return AST_CAUSE_DESTINATION_OUT_OF_ORDER;
- case 503: /* Service unavailable */
- return AST_CAUSE_CONGESTION;
- default:
- return AST_CAUSE_NORMAL;
- }
- /* Never reached */
- return 0;
-}
-
-
-/*! \brief hangup_cause2sip: Convert Asterisk hangup causes to SIP codes
-\verbatim
- Possible values from causes.h
- AST_CAUSE_NOTDEFINED AST_CAUSE_NORMAL AST_CAUSE_BUSY
- AST_CAUSE_FAILURE AST_CAUSE_CONGESTION AST_CAUSE_UNALLOCATED
-
- In addition to these, a lot of PRI codes is defined in causes.h
- ...should we take care of them too ?
-
- Quote RFC 3398
-
- ISUP Cause value SIP response
- ---------------- ------------
- 1 unallocated number 404 Not Found
- 2 no route to network 404 Not found
- 3 no route to destination 404 Not found
- 16 normal call clearing --- (*)
- 17 user busy 486 Busy here
- 18 no user responding 408 Request Timeout
- 19 no answer from the user 480 Temporarily unavailable
- 20 subscriber absent 480 Temporarily unavailable
- 21 call rejected 403 Forbidden (+)
- 22 number changed (w/o diagnostic) 410 Gone
- 22 number changed (w/ diagnostic) 301 Moved Permanently
- 23 redirection to new destination 410 Gone
- 26 non-selected user clearing 404 Not Found (=)
- 27 destination out of order 502 Bad Gateway
- 28 address incomplete 484 Address incomplete
- 29 facility rejected 501 Not implemented
- 31 normal unspecified 480 Temporarily unavailable
-\endverbatim
-*/
-static char *hangup_cause2sip(int cause)
-{
- switch(cause)
- {
- case AST_CAUSE_UNALLOCATED: /* 1 */
- case AST_CAUSE_NO_ROUTE_DESTINATION: /* 3 IAX2: Can't find extension in context */
- case AST_CAUSE_NO_ROUTE_TRANSIT_NET: /* 2 */
- return "404 Not Found";
- case AST_CAUSE_CONGESTION: /* 34 */
- case AST_CAUSE_SWITCH_CONGESTION: /* 42 */
- return "503 Service Unavailable";
- case AST_CAUSE_NO_USER_RESPONSE: /* 18 */
- return "408 Request Timeout";
- case AST_CAUSE_NO_ANSWER: /* 19 */
- return "480 Temporarily unavailable";
- case AST_CAUSE_CALL_REJECTED: /* 21 */
- return "403 Forbidden";
- case AST_CAUSE_NUMBER_CHANGED: /* 22 */
- return "410 Gone";
- case AST_CAUSE_NORMAL_UNSPECIFIED: /* 31 */
- return "480 Temporarily unavailable";
- case AST_CAUSE_INVALID_NUMBER_FORMAT:
- return "484 Address incomplete";
- case AST_CAUSE_USER_BUSY:
- return "486 Busy here";
- case AST_CAUSE_FAILURE:
- return "500 Server internal failure";
- case AST_CAUSE_FACILITY_REJECTED: /* 29 */
- return "501 Not Implemented";
- case AST_CAUSE_CHAN_NOT_IMPLEMENTED:
- return "503 Service Unavailable";
- /* Used in chan_iax2 */
- case AST_CAUSE_DESTINATION_OUT_OF_ORDER:
- return "502 Bad Gateway";
- case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL: /* Can't find codec to connect to host */
- return "488 Not Acceptable Here";
-
- case AST_CAUSE_NOTDEFINED:
- default:
- ast_log(LOG_DEBUG, "AST hangup cause %d (no match found in SIP)\n", cause);
- return NULL;
- }
-
- /* Never reached */
- return 0;
-}
-
-
-/*! \brief sip_hangup: Hangup SIP call
- * Part of PBX interface, called from ast_hangup */
-static int sip_hangup(struct ast_channel *ast)
-{
- struct sip_pvt *p = ast->tech_pvt;
- int needcancel = 0;
- struct ast_flags locflags = {0};
-
- if (!p) {
- ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n");
- return 0;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Hangup call %s, SIP callid %s)\n", ast->name, p->callid);
-
- ast_mutex_lock(&p->lock);
-#ifdef OSP_SUPPORT
- if ((p->osphandle > -1) && (ast->_state == AST_STATE_UP)) {
- ast_osp_terminate(p->osphandle, AST_CAUSE_NORMAL, p->ospstart, time(NULL) - p->ospstart);
- }
-#endif
- ast_log(LOG_DEBUG, "update_call_counter(%s) - decrement call limit counter\n", p->username);
- update_call_counter(p, DEC_CALL_LIMIT);
- /* Determine how to disconnect */
- if (p->owner != ast) {
- ast_log(LOG_WARNING, "Huh? We aren't the owner? Can't hangup call.\n");
- ast_mutex_unlock(&p->lock);
- return 0;
- }
- /* If the call is not UP, we need to send CANCEL instead of BYE */
- if (ast->_state != AST_STATE_UP)
- needcancel = 1;
-
-#ifdef SIP_MIDCOM
- /* For callee to shutdown, send "BYE" instead of "CANCEL"
- -- this needs to be verified */
- if (m_cb && ast_test_flag(p, SIP_OUTGOING)) needcancel = 0;
-#endif
-
- /* Disconnect */
- p = ast->tech_pvt;
- if (p->vad) {
- ast_dsp_free(p->vad);
- }
- p->owner = NULL;
- ast->tech_pvt = NULL;
-
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-
- ast_set_flag(&locflags, SIP_NEEDDESTROY);
-
- /* Start the process if it's not already started */
- if (!ast_test_flag(p, SIP_ALREADYGONE) && !ast_strlen_zero(p->initreq.data)) {
- if (needcancel) { /* Outgoing call, not up */
- if (ast_test_flag(p, SIP_OUTGOING)) {
- transmit_request_with_auth(p, SIP_CANCEL, p->ocseq, 1, 0);
- /* Actually don't destroy us yet, wait for the 487 on our original
- INVITE, but do set an autodestruct just in case we never get it. */
- ast_clear_flag(&locflags, SIP_NEEDDESTROY);
- sip_scheddestroy(p, 15000);
- /* stop retransmitting an INVITE that has not received a response */
- __sip_pretend_ack(p);
- if ( p->initid != -1 ) {
- /* channel still up - reverse dec of inUse counter
- only if the channel is not auto-congested */
- update_call_counter(p, INC_CALL_LIMIT);
- }
- } else { /* Incoming call, not up */
- char *res;
- if (ast->hangupcause && ((res = hangup_cause2sip(ast->hangupcause)))) {
- transmit_response_reliable(p, res, &p->initreq, 1);
- } else
- transmit_response_reliable(p, "603 Declined", &p->initreq, 1);
- }
- } else { /* Call is in UP state, send BYE */
- if (!p->pendinginvite) {
- /* Send a hangup */
- transmit_request_with_auth(p, SIP_BYE, 0, 1, 1);
- } else {
- /* Note we will need a BYE when this all settles out
- but we can't send one while we have "INVITE" outstanding. */
- ast_set_flag(p, SIP_PENDINGBYE);
- ast_clear_flag(p, SIP_NEEDREINVITE);
- }
- }
- }
- ast_copy_flags(p, (&locflags), SIP_NEEDDESTROY);
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-/*! \brief sip_answer: Answer SIP call , send 200 OK on Invite
- * Part of PBX interface */
-static int sip_answer(struct ast_channel *ast)
-{
- int res = 0,fmt;
- char *codec;
- struct sip_pvt *p = ast->tech_pvt;
-
- ast_mutex_lock(&p->lock);
- if (ast->_state != AST_STATE_UP) {
-#ifdef OSP_SUPPORT
- time(&p->ospstart);
-#endif
-
- codec=pbx_builtin_getvar_helper(p->owner,"SIP_CODEC");
- if (codec) {
- fmt=ast_getformatbyname(codec);
- if (fmt) {
- ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC) variable\n",codec);
- if (p->jointcapability & fmt) {
- p->jointcapability &= fmt;
- p->capability &= fmt;
- } else
- ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because it is not shared by both ends.\n");
- } else ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because of unrecognized/not configured codec (check allow/disallow in sip.conf): %s\n",codec);
- }
-
- ast_setstate(ast, AST_STATE_UP);
- if (option_debug)
- ast_log(LOG_DEBUG, "sip_answer(%s)\n", ast->name);
- res = transmit_response_with_sdp(p, "200 OK", &p->initreq, 1);
- }
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-/*! \brief sip_write: Send frame to media channel (rtp) ---*/
-static int sip_write(struct ast_channel *ast, struct ast_frame *frame)
-{
- struct sip_pvt *p = ast->tech_pvt;
- int res = 0;
- switch (frame->frametype) {
- case AST_FRAME_VOICE:
- if (!(frame->subclass & ast->nativeformats)) {
- ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
- frame->subclass, ast->nativeformats, ast->readformat, ast->writeformat);
- return 0;
- }
- if (p) {
- ast_mutex_lock(&p->lock);
- if (p->rtp) {
- /* If channel is not up, activate early media session */
- if ((ast->_state != AST_STATE_UP) && !ast_test_flag(p, SIP_PROGRESS_SENT) && !ast_test_flag(p, SIP_OUTGOING)) {
- transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, 0);
- ast_set_flag(p, SIP_PROGRESS_SENT);
- }
- time(&p->lastrtptx);
- res = ast_rtp_write(p->rtp, frame);
- }
- ast_mutex_unlock(&p->lock);
- }
- break;
- case AST_FRAME_VIDEO:
- if (p) {
- ast_mutex_lock(&p->lock);
- if (p->vrtp) {
- /* Activate video early media */
- if ((ast->_state != AST_STATE_UP) && !ast_test_flag(p, SIP_PROGRESS_SENT) && !ast_test_flag(p, SIP_OUTGOING)) {
- transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, 0);
- ast_set_flag(p, SIP_PROGRESS_SENT);
- }
- time(&p->lastrtptx);
- res = ast_rtp_write(p->vrtp, frame);
- }
- ast_mutex_unlock(&p->lock);
- }
- break;
- case AST_FRAME_IMAGE:
- return 0;
- break;
- default:
- ast_log(LOG_WARNING, "Can't send %d type frames with SIP write\n", frame->frametype);
- return 0;
- }
-
- return res;
-}
-
-/*! \brief sip_fixup: Fix up a channel: If a channel is consumed, this is called.
- Basically update any ->owner links ----*/
-static int sip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct sip_pvt *p = newchan->tech_pvt;
- ast_mutex_lock(&p->lock);
- if (p->owner != oldchan) {
- ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner);
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- p->owner = newchan;
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-/*! \brief sip_senddigit: Send DTMF character on SIP channel */
-/* within one call, we're able to transmit in many methods simultaneously */
-static int sip_senddigit(struct ast_channel *ast, char digit)
-{
- struct sip_pvt *p = ast->tech_pvt;
- int res = 0;
- ast_mutex_lock(&p->lock);
- switch (ast_test_flag(p, SIP_DTMF)) {
- case SIP_DTMF_INFO:
- transmit_info_with_digit(p, digit);
- break;
- case SIP_DTMF_RFC2833:
- if (p->rtp)
- ast_rtp_senddigit(p->rtp, digit);
- break;
- case SIP_DTMF_INBAND:
- res = -1;
- break;
- }
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-
-
-/*! \brief sip_transfer: Transfer SIP call */
-static int sip_transfer(struct ast_channel *ast, const char *dest)
-{
- struct sip_pvt *p = ast->tech_pvt;
- int res;
-
- ast_mutex_lock(&p->lock);
- if (ast->_state == AST_STATE_RING)
- res = sip_sipredirect(p, dest);
- else
- res = transmit_refer(p, dest);
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-/*! \brief sip_indicate: Play indication to user
- * With SIP a lot of indications is sent as messages, letting the device play
- the indication - busy signal, congestion etc */
-static int sip_indicate(struct ast_channel *ast, int condition)
-{
- struct sip_pvt *p = ast->tech_pvt;
- int res = 0;
-
- ast_mutex_lock(&p->lock);
- switch(condition) {
- case AST_CONTROL_RINGING:
- if (ast->_state == AST_STATE_RING) {
- if (!ast_test_flag(p, SIP_PROGRESS_SENT) ||
- (ast_test_flag(p, SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER)) {
- /* Send 180 ringing if out-of-band seems reasonable */
- transmit_response(p, "180 Ringing", &p->initreq);
- ast_set_flag(p, SIP_RINGING);
- if (ast_test_flag(p, SIP_PROG_INBAND) != SIP_PROG_INBAND_YES)
- break;
- } else {
- /* Well, if it's not reasonable, just send in-band */
- }
- }
- res = -1;
- break;
- case AST_CONTROL_BUSY:
- if (ast->_state != AST_STATE_UP) {
- transmit_response(p, "486 Busy Here", &p->initreq);
- ast_set_flag(p, SIP_ALREADYGONE);
- ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV);
- break;
- }
- res = -1;
- break;
- case AST_CONTROL_CONGESTION:
- if (ast->_state != AST_STATE_UP) {
- transmit_response(p, "503 Service Unavailable", &p->initreq);
- ast_set_flag(p, SIP_ALREADYGONE);
- ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV);
- break;
- }
- res = -1;
- break;
- case AST_CONTROL_PROCEEDING:
- if ((ast->_state != AST_STATE_UP) && !ast_test_flag(p, SIP_PROGRESS_SENT) && !ast_test_flag(p, SIP_OUTGOING)) {
- transmit_response(p, "100 Trying", &p->initreq);
- break;
- }
- res = -1;
- break;
- case AST_CONTROL_PROGRESS:
- if ((ast->_state != AST_STATE_UP) && !ast_test_flag(p, SIP_PROGRESS_SENT) && !ast_test_flag(p, SIP_OUTGOING)) {
- transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, 0);
- ast_set_flag(p, SIP_PROGRESS_SENT);
- break;
- }
- res = -1;
- break;
- case AST_CONTROL_HOLD: /* The other part of the bridge are put on hold */
- if (sipdebug)
- ast_log(LOG_DEBUG, "Bridged channel now on hold%s\n", p->callid);
- res = -1;
- break;
- case AST_CONTROL_UNHOLD: /* The other part of the bridge are back from hold */
- if (sipdebug)
- ast_log(LOG_DEBUG, "Bridged channel is back from hold, let's talk! : %s\n", p->callid);
- res = -1;
- break;
- case AST_CONTROL_VIDUPDATE: /* Request a video frame update */
- if (p->vrtp && !ast_test_flag(p, SIP_NOVIDEO)) {
- transmit_info_with_vidupdate(p);
- res = 0;
- } else
- res = -1;
- break;
- case -1:
- res = -1;
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", condition);
- res = -1;
- break;
- }
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-
-
-/*! \brief sip_new: Initiate a call in the SIP channel */
-/* called from sip_request_call (calls from the pbx ) */
-static struct ast_channel *sip_new(struct sip_pvt *i, int state, char *title)
-{
- struct ast_channel *tmp;
- struct ast_variable *v = NULL;
- int fmt;
-#ifdef OSP_SUPPORT
- char iabuf[INET_ADDRSTRLEN];
- char peer[MAXHOSTNAMELEN];
-#endif
-
- ast_mutex_unlock(&i->lock);
- /* Don't hold a sip pvt lock while we allocate a channel */
- tmp = ast_channel_alloc(1);
- ast_mutex_lock(&i->lock);
- if (!tmp) {
- ast_log(LOG_WARNING, "Unable to allocate SIP channel structure\n");
- return NULL;
- }
- tmp->tech = &sip_tech;
- /* Select our native format based on codec preference until we receive
- something from another device to the contrary. */
- if (i->jointcapability)
- tmp->nativeformats = ast_codec_choose(&i->prefs, i->jointcapability, 1);
- else if (i->capability)
- tmp->nativeformats = ast_codec_choose(&i->prefs, i->capability, 1);
- else
- tmp->nativeformats = ast_codec_choose(&i->prefs, global_capability, 1);
- fmt = ast_best_codec(tmp->nativeformats);
-
- if (title)
- snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%04x", title, thread_safe_rand() & 0xffff);
- else if (strchr(i->fromdomain,':'))
- snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%08x", strchr(i->fromdomain,':')+1, (int)(long)(i));
- else
- snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%08x", i->fromdomain, (int)(long)(i));
-
- tmp->type = channeltype;
- if (ast_test_flag(i, SIP_DTMF) == SIP_DTMF_INBAND) {
- i->vad = ast_dsp_new();
- ast_dsp_set_features(i->vad, DSP_FEATURE_DTMF_DETECT);
- if (relaxdtmf)
- ast_dsp_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
- }
- if (i->rtp) {
- tmp->fds[0] = ast_rtp_fd(i->rtp);
- tmp->fds[1] = ast_rtcp_fd(i->rtp);
- }
- if (i->vrtp) {
- tmp->fds[2] = ast_rtp_fd(i->vrtp);
- tmp->fds[3] = ast_rtcp_fd(i->vrtp);
- }
- if (state == AST_STATE_RING)
- tmp->rings = 1;
- tmp->adsicpe = AST_ADSI_UNAVAILABLE;
- tmp->writeformat = fmt;
- tmp->rawwriteformat = fmt;
- tmp->readformat = fmt;
- tmp->rawreadformat = fmt;
- tmp->tech_pvt = i;
-
- tmp->callgroup = i->callgroup;
- tmp->pickupgroup = i->pickupgroup;
- tmp->cid.cid_pres = i->callingpres;
- if (!ast_strlen_zero(i->accountcode))
- ast_copy_string(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode));
- if (i->amaflags)
- tmp->amaflags = i->amaflags;
- if (!ast_strlen_zero(i->language))
- ast_copy_string(tmp->language, i->language, sizeof(tmp->language));
- if (!ast_strlen_zero(i->musicclass))
- ast_copy_string(tmp->musicclass, i->musicclass, sizeof(tmp->musicclass));
- i->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
- ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
- if (!ast_strlen_zero(i->cid_num))
- tmp->cid.cid_num = strdup(i->cid_num);
- if (!ast_strlen_zero(i->cid_name))
- tmp->cid.cid_name = strdup(i->cid_name);
- if (!ast_strlen_zero(i->rdnis))
- tmp->cid.cid_rdnis = strdup(i->rdnis);
- if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
- tmp->cid.cid_dnid = strdup(i->exten);
- tmp->priority = 1;
- if (!ast_strlen_zero(i->uri)) {
- pbx_builtin_setvar_helper(tmp, "SIPURI", i->uri);
- }
- if (!ast_strlen_zero(i->domain)) {
- pbx_builtin_setvar_helper(tmp, "SIPDOMAIN", i->domain);
- }
- if (!ast_strlen_zero(i->useragent)) {
- pbx_builtin_setvar_helper(tmp, "SIPUSERAGENT", i->useragent);
- }
- if (!ast_strlen_zero(i->callid)) {
- pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid);
- }
-#ifdef OSP_SUPPORT
- snprintf(peer, sizeof(peer), "[%s]:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), i->sa.sin_addr), ntohs(i->sa.sin_port));
- pbx_builtin_setvar_helper(tmp, "OSPPEER", peer);
-#endif
- ast_setstate(tmp, state);
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- tmp = NULL;
- }
- }
- /* Set channel variables for this call from configuration */
- for (v = i->chanvars ; v ; v = v->next)
- pbx_builtin_setvar_helper(tmp,v->name,v->value);
-
- return tmp;
-}
-
-/*! \brief get_sdp_by_line: Reads one line of SIP message body */
-static char* get_sdp_by_line(char* line, char *name, int nameLen)
-{
- if (strncasecmp(line, name, nameLen) == 0 && line[nameLen] == '=') {
- return ast_skip_blanks(line + nameLen + 1);
- }
- return "";
-}
-
-/*! \brief get_sdp: Gets all kind of SIP message bodies, including SDP,
- but the name wrongly applies _only_ sdp */
-static char *get_sdp(struct sip_request *req, char *name)
-{
- int x;
- int len = strlen(name);
- char *r;
-
- for (x=0; x<req->lines; x++) {
- r = get_sdp_by_line(req->line[x], name, len);
- if (r[0] != '\0')
- return r;
- }
- return "";
-}
-
-
-static void sdpLineNum_iterator_init(int* iterator)
-{
- *iterator = 0;
-}
-
-static char* get_sdp_iterate(int* iterator,
- struct sip_request *req, char *name)
-{
- int len = strlen(name);
- char *r;
-
- while (*iterator < req->lines) {
- r = get_sdp_by_line(req->line[(*iterator)++], name, len);
- if (r[0] != '\0')
- return r;
- }
- return "";
-}
-
-static char *find_alias(const char *name, char *_default)
-{
- int x;
- for (x=0;x<sizeof(aliases) / sizeof(aliases[0]); x++)
- if (!strcasecmp(aliases[x].fullname, name))
- return aliases[x].shortname;
- return _default;
-}
-
-static char *__get_header(struct sip_request *req, char *name, int *start)
-{
- int pass;
-
- /*
- * Technically you can place arbitrary whitespace both before and after the ':' in
- * a header, although RFC3261 clearly says you shouldn't before, and place just
- * one afterwards. If you shouldn't do it, what absolute idiot decided it was
- * a good idea to say you can do it, and if you can do it, why in the hell would.
- * you say you shouldn't.
- * Anyways, pedanticsipchecking controls whether we allow spaces before ':',
- * and we always allow spaces after that for compatibility.
- */
- for (pass = 0; name && pass < 2;pass++) {
- int x, len = strlen(name);
- for (x=*start; x<req->headers; x++) {
- if (!strncasecmp(req->header[x], name, len)) {
- char *r = req->header[x] + len; /* skip name */
- if (pedanticsipchecking)
- r = ast_skip_blanks(r);
-
- if (*r == ':') {
- *start = x+1;
- return ast_skip_blanks(r+1);
- }
- }
- }
- if (pass == 0) /* Try aliases */
- name = find_alias(name, NULL);
- }
-
- /* Don't return NULL, so get_header is always a valid pointer */
- return "";
-}
-
-/*! \brief get_header: Get header from SIP request ---*/
-static char *get_header(struct sip_request *req, char *name)
-{
- int start = 0;
- return __get_header(req, name, &start);
-}
-
-/*! \brief sip_rtp_read: Read RTP from network ---*/
-static struct ast_frame *sip_rtp_read(struct ast_channel *ast, struct sip_pvt *p)
-{
- /* Retrieve audio/etc from channel. Assumes p->lock is already held. */
- struct ast_frame *f;
- static struct ast_frame null_frame = { AST_FRAME_NULL, };
-
- if (!p->rtp) {
- /* We have no RTP allocated for this channel */
- return &null_frame;
- }
-
- switch(ast->fdno) {
- case 0:
- f = ast_rtp_read(p->rtp); /* RTP Audio */
- break;
- case 1:
- f = ast_rtcp_read(p->rtp); /* RTCP Control Channel */
- break;
- case 2:
- f = ast_rtp_read(p->vrtp); /* RTP Video */
- break;
- case 3:
- f = ast_rtcp_read(p->vrtp); /* RTCP Control Channel for video */
- break;
- default:
- f = &null_frame;
- }
- /* Don't forward RFC2833 if we're not supposed to */
- if (f && (f->frametype == AST_FRAME_DTMF) && (ast_test_flag(p, SIP_DTMF) != SIP_DTMF_RFC2833))
- return &null_frame;
- if (p->owner) {
- /* We already hold the channel lock */
- if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass != p->owner->nativeformats) {
- ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
- p->owner->nativeformats = f->subclass;
- ast_set_read_format(p->owner, p->owner->readformat);
- ast_set_write_format(p->owner, p->owner->writeformat);
- }
- if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_INBAND) && p->vad) {
- f = ast_dsp_process(p->owner, p->vad, f);
- if (f && (f->frametype == AST_FRAME_DTMF))
- ast_log(LOG_DEBUG, "* Detected inband DTMF '%c'\n", f->subclass);
- }
- }
- }
- return f;
-}
-
-/*! \brief sip_read: Read SIP RTP from channel */
-static struct ast_frame *sip_read(struct ast_channel *ast)
-{
- struct ast_frame *fr;
- struct sip_pvt *p = ast->tech_pvt;
- ast_mutex_lock(&p->lock);
- fr = sip_rtp_read(ast, p);
- time(&p->lastrtprx);
- ast_mutex_unlock(&p->lock);
- return fr;
-}
-
-/*! \brief build_callid: Build SIP CALLID header ---*/
-static void build_callid(char *callid, int len, struct in_addr ourip, char *fromdomain)
-{
- int res;
- int val;
- int x;
- char iabuf[INET_ADDRSTRLEN];
- for (x=0; x<4; x++) {
- val = thread_safe_rand();
- res = snprintf(callid, len, "%08x", val);
- len -= res;
- callid += res;
- }
- if (!ast_strlen_zero(fromdomain))
- snprintf(callid, len, "@%s", fromdomain);
- else
- /* It's not important that we really use our right IP here... */
- snprintf(callid, len, "@%s", ast_inet_ntoa(iabuf, sizeof(iabuf), ourip));
-}
-
-static void make_our_tag(char *tagbuf, size_t len)
-{
- snprintf(tagbuf, len, "as%08x", thread_safe_rand());
-}
-
-/*! \brief sip_alloc: Allocate SIP_PVT structure and set defaults ---*/
-static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method)
-{
- struct sip_pvt *p;
-
- if (!(p = calloc(1, sizeof(*p))))
- return NULL;
-
- ast_mutex_init(&p->lock);
-
- p->method = intended_method;
- p->initid = -1;
- p->autokillid = -1;
- p->subscribed = NONE;
- p->stateid = -1;
- p->prefs = prefs;
- if (intended_method != SIP_OPTIONS) /* Peerpoke has it's own system */
- p->timer_t1 = 500; /* Default SIP retransmission timer T1 (RFC 3261) */
-#ifdef OSP_SUPPORT
- p->osphandle = -1;
- p->osptimelimit = 0;
-#endif
- if (sin) {
- memcpy(&p->sa, sin, sizeof(p->sa));
- if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
- memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- } else {
- memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- }
-
- p->branch = thread_safe_rand();
- make_our_tag(p->tag, sizeof(p->tag));
- /* Start with 101 instead of 1 */
- p->ocseq = 101;
-
- if (sip_methods[intended_method].need_rtp) {
- p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
- if (videosupport)
- p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
- if (!p->rtp || (videosupport && !p->vrtp)) {
- ast_log(LOG_WARNING, "Unable to create RTP audio %s session: %s\n", videosupport ? "and video" : "", strerror(errno));
- ast_mutex_destroy(&p->lock);
- if (p->chanvars) {
- ast_variables_destroy(p->chanvars);
- p->chanvars = NULL;
- }
- free(p);
- return NULL;
- }
- ast_rtp_settos(p->rtp, tos);
- if (p->vrtp)
- ast_rtp_settos(p->vrtp, tos);
- p->rtptimeout = global_rtptimeout;
- p->rtpholdtimeout = global_rtpholdtimeout;
- p->rtpkeepalive = global_rtpkeepalive;
- }
-
- if (useglobal_nat && sin) {
- /* Setup NAT structure according to global settings if we have an address */
- ast_copy_flags(p, &global_flags, SIP_NAT);
- memcpy(&p->recv, sin, sizeof(p->recv));
- if (p->rtp)
- ast_rtp_setnat(p->rtp, (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- if (p->vrtp)
- ast_rtp_setnat(p->vrtp, (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- }
-
- if (p->method != SIP_REGISTER)
- ast_copy_string(p->fromdomain, default_fromdomain, sizeof(p->fromdomain));
- build_via(p, p->via, sizeof(p->via));
- if (!callid)
- build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
- else
- ast_copy_string(p->callid, callid, sizeof(p->callid));
- ast_copy_flags(p, &global_flags, SIP_FLAGS_TO_COPY);
- /* Assign default music on hold class */
- strcpy(p->musicclass, global_musicclass);
- p->capability = global_capability;
- if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_RFC2833) || (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_AUTO))
- p->noncodeccapability |= AST_RTP_DTMF;
- strcpy(p->context, default_context);
-
- /* Add to active dialog list */
- ast_mutex_lock(&iflock);
- p->next = iflist;
- iflist = p;
- ast_mutex_unlock(&iflock);
- if (option_debug)
- ast_log(LOG_DEBUG, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : "(No Call-ID)", sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP");
- return p;
-}
-
-/*! \brief find_call: Connect incoming SIP message to current dialog or create new dialog structure */
-/* Called by handle_request, sipsock_read */
-static struct sip_pvt *find_call(struct sip_request *req, struct sockaddr_in *sin, const int intended_method)
-{
- struct sip_pvt *p;
- char *callid;
- char *tag = "";
- char totag[128];
- char fromtag[128];
-
- callid = get_header(req, "Call-ID");
-
- if (pedanticsipchecking) {
- /* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy
- we need more to identify a branch - so we have to check branch, from
- and to tags to identify a call leg.
- For Asterisk to behave correctly, you need to turn on pedanticsipchecking
- in sip.conf
- */
- if (gettag(req, "To", totag, sizeof(totag)))
- ast_set_flag(req, SIP_PKT_WITH_TOTAG); /* Used in handle_request/response */
- gettag(req, "From", fromtag, sizeof(fromtag));
-
- if (req->method == SIP_RESPONSE)
- tag = totag;
- else
- tag = fromtag;
-
-
- if (option_debug > 4 )
- ast_log(LOG_DEBUG, "= Looking for Call ID: %s (Checking %s) --From tag %s --To-tag %s \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag);
- }
-
- ast_mutex_lock(&iflock);
- p = iflist;
- while(p) { /* In pedantic, we do not want packets with bad syntax to be connected to a PVT */
- int found = 0;
- if (req->method == SIP_REGISTER)
- found = (!strcmp(p->callid, callid));
- else
- found = (!strcmp(p->callid, callid) &&
- (!pedanticsipchecking || !tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))) ;
-
- if (option_debug > 4)
- ast_log(LOG_DEBUG, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", p->callid, p->theirtag, p->tag);
-
- /* If we get a new request within an existing to-tag - check the to tag as well */
- if (pedanticsipchecking && found && req->method != SIP_RESPONSE) { /* SIP Request */
- if (p->tag[0] == '\0' && totag[0]) {
- /* We have no to tag, but they have. Wrong dialog */
- found = 0;
- } else if (totag[0]) { /* Both have tags, compare them */
- if (strcmp(totag, p->tag)) {
- found = 0; /* This is not our packet */
- }
- }
- if (!found && option_debug > 4)
- ast_log(LOG_DEBUG, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag <null> Totag %s Method %s\n", p->callid, totag, sip_methods[req->method].text);
- }
-
-
- if (found) {
- /* Found the call */
- ast_mutex_lock(&p->lock);
- ast_mutex_unlock(&iflock);
- return p;
- }
- p = p->next;
- }
- ast_mutex_unlock(&iflock);
- p = sip_alloc(callid, sin, 1, intended_method);
- if (p)
- ast_mutex_lock(&p->lock);
- return p;
-}
-
-/*! \brief sip_register: Parse register=> line in sip.conf and add to registry */
-static int sip_register(char *value, int lineno)
-{
- struct sip_registry *reg;
- char copy[256];
- char *username=NULL, *hostname=NULL, *secret=NULL, *authuser=NULL;
- char *porta=NULL;
- char *contact=NULL;
- char *stringp=NULL;
-
- if (!value)
- return -1;
- ast_copy_string(copy, value, sizeof(copy));
- stringp=copy;
- username = stringp;
- hostname = strrchr(stringp, '@');
- if (hostname) {
- *hostname = '\0';
- hostname++;
- }
- if (ast_strlen_zero(username) || ast_strlen_zero(hostname)) {
- ast_log(LOG_WARNING, "Format for registration is user[:secret[:authuser]]@host[:port][/contact] at line %d\n", lineno);
- return -1;
- }
- stringp=username;
- username = strsep(&stringp, ":");
- if (username) {
- secret = strsep(&stringp, ":");
- if (secret)
- authuser = strsep(&stringp, ":");
- }
- stringp = hostname;
- hostname = strsep(&stringp, "/");
- if (hostname)
- contact = strsep(&stringp, "/");
- if (ast_strlen_zero(contact))
- contact = "s";
- stringp=hostname;
- hostname = strsep(&stringp, ":");
- porta = strsep(&stringp, ":");
-
- if (porta && !atoi(porta)) {
- ast_log(LOG_WARNING, "%s is not a valid port number at line %d\n", porta, lineno);
- return -1;
- }
- reg = malloc(sizeof(struct sip_registry));
- if (!reg) {
- ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry entry\n");
- return -1;
- }
- memset(reg, 0, sizeof(struct sip_registry));
- regobjs++;
- ASTOBJ_INIT(reg);
- ast_copy_string(reg->contact, contact, sizeof(reg->contact));
- if (username)
- ast_copy_string(reg->username, username, sizeof(reg->username));
- if (hostname)
- ast_copy_string(reg->hostname, hostname, sizeof(reg->hostname));
- if (authuser)
- ast_copy_string(reg->authuser, authuser, sizeof(reg->authuser));
- if (secret)
- ast_copy_string(reg->secret, secret, sizeof(reg->secret));
- reg->expire = -1;
- reg->timeout = -1;
- reg->refresh = default_expiry;
- reg->portno = porta ? atoi(porta) : 0;
- reg->callid_valid = 0;
- reg->ocseq = 101;
- ASTOBJ_CONTAINER_LINK(&regl, reg);
- ASTOBJ_UNREF(reg,sip_registry_destroy);
- return 0;
-}
-
-/*! \brief lws2sws: Parse multiline SIP headers into one header */
-/* This is enabled if pedanticsipchecking is enabled */
-static int lws2sws(char *msgbuf, int len)
-{
- int h = 0, t = 0;
- int lws = 0;
-
- for (; h < len;) {
- /* Eliminate all CRs */
- if (msgbuf[h] == '\r') {
- h++;
- continue;
- }
- /* Check for end-of-line */
- if (msgbuf[h] == '\n') {
- /* Check for end-of-message */
- if (h + 1 == len)
- break;
- /* Check for a continuation line */
- if (msgbuf[h + 1] == ' ' || msgbuf[h + 1] == '\t') {
- /* Merge continuation line */
- h++;
- continue;
- }
- /* Propagate LF and start new line */
- msgbuf[t++] = msgbuf[h++];
- lws = 0;
- continue;
- }
- if (msgbuf[h] == ' ' || msgbuf[h] == '\t') {
- if (lws) {
- h++;
- continue;
- }
- msgbuf[t++] = msgbuf[h++];
- lws = 1;
- continue;
- }
- msgbuf[t++] = msgbuf[h++];
- if (lws)
- lws = 0;
- }
- msgbuf[t] = '\0';
- return t;
-}
-
-/*! \brief parse_request: Parse a SIP message ----*/
-static void parse_request(struct sip_request *req)
-{
- /* Divide fields by NULL's */
- char *c;
- int f = 0;
-
- c = req->data;
-
- /* First header starts immediately */
- req->header[f] = c;
- while(*c) {
- if (*c == '\n') {
- /* We've got a new header */
- *c = 0;
-
- if (sipdebug && option_debug > 3)
- ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f]));
- if (ast_strlen_zero(req->header[f])) {
- /* Line by itself means we're now in content */
- c++;
- break;
- }
- if (f >= SIP_MAX_HEADERS - 1) {
- ast_log(LOG_WARNING, "Too many SIP headers. Ignoring.\n");
- } else
- f++;
- req->header[f] = c + 1;
- } else if (*c == '\r') {
- /* Ignore but eliminate \r's */
- *c = 0;
- }
- c++;
- }
- /* Check for last header */
- if (!ast_strlen_zero(req->header[f])) {
- if (sipdebug && option_debug > 3)
- ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f]));
- f++;
- }
- req->headers = f;
- /* Now we process any mime content */
- f = 0;
- req->line[f] = c;
- while(*c) {
- if (*c == '\n') {
- /* We've got a new line */
- *c = 0;
- if (sipdebug && option_debug > 3)
- ast_log(LOG_DEBUG, "Line: %s (%d)\n", req->line[f], (int) strlen(req->line[f]));
- if (f >= SIP_MAX_LINES - 1) {
- ast_log(LOG_WARNING, "Too many SDP lines. Ignoring.\n");
- } else
- f++;
- req->line[f] = c + 1;
- } else if (*c == '\r') {
- /* Ignore and eliminate \r's */
- *c = 0;
- }
- c++;
- }
- /* Check for last line */
- if (!ast_strlen_zero(req->line[f]))
- f++;
- req->lines = f;
- if (*c)
- ast_log(LOG_WARNING, "Odd content, extra stuff left over ('%s')\n", c);
- /* Split up the first line parts */
- determine_firstline_parts(req);
-}
-
-/*! \brief process_sdp: Process SIP SDP and activate RTP channels---*/
-static int process_sdp(struct sip_pvt *p, struct sip_request *req)
-{
- char *m;
- char *c;
- char *a;
- char host[258];
- char iabuf[INET_ADDRSTRLEN];
- int len = -1;
- int portno = -1;
- int vportno = -1;
- int peercapability, peernoncodeccapability;
- int vpeercapability=0, vpeernoncodeccapability=0;
- struct sockaddr_in sin;
- char *codecs;
- struct hostent *hp;
- struct ast_hostent ahp;
- int codec;
- int destiterator = 0;
- int iterator;
- int sendonly = 0;
- int x,y;
- int debug=sip_debug_test_pvt(p);
- struct ast_channel *bridgepeer = NULL;
-
- if (!p->rtp) {
- ast_log(LOG_ERROR, "Got SDP but have no RTP session allocated.\n");
- return -1;
- }
-
- /* Update our last rtprx when we receive an SDP, too */
- time(&p->lastrtprx);
- time(&p->lastrtptx);
-
- /* Get codec and RTP info from SDP */
- if (strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
- ast_log(LOG_NOTICE, "Content is '%s', not 'application/sdp'\n", get_header(req, "Content-Type"));
- return -1;
- }
- m = get_sdp(req, "m");
- sdpLineNum_iterator_init(&destiterator);
- c = get_sdp_iterate(&destiterator, req, "c");
- if (ast_strlen_zero(m) || ast_strlen_zero(c)) {
- ast_log(LOG_WARNING, "Insufficient information for SDP (m = '%s', c = '%s')\n", m, c);
- return -1;
- }
- if (sscanf(c, "IN IP4 %256s", host) != 1) {
- ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c);
- return -1;
- }
- /* XXX This could block for a long time, and block the main thread! XXX */
- hp = ast_gethostbyname(host, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Unable to lookup host in c= line, '%s'\n", c);
- return -1;
- }
- sdpLineNum_iterator_init(&iterator);
- ast_set_flag(p, SIP_NOVIDEO);
- while ((m = get_sdp_iterate(&iterator, req, "m"))[0] != '\0') {
- int found = 0;
- if ((sscanf(m, "audio %d/%d RTP/AVP %n", &x, &y, &len) == 2) ||
- (sscanf(m, "audio %d RTP/AVP %n", &x, &len) == 1)) {
- found = 1;
- portno = x;
- /* Scan through the RTP payload types specified in a "m=" line: */
- ast_rtp_pt_clear(p->rtp);
- codecs = m + len;
- while(!ast_strlen_zero(codecs)) {
- if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
- ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
- return -1;
- }
- if (debug)
- ast_verbose("Found RTP audio format %d\n", codec);
- ast_rtp_set_m_type(p->rtp, codec);
- codecs = ast_skip_blanks(codecs + len);
- }
- }
- if (p->vrtp)
- ast_rtp_pt_clear(p->vrtp); /* Must be cleared in case no m=video line exists */
-
- if (p->vrtp && (sscanf(m, "video %d RTP/AVP %n", &x, &len) == 1)) {
- found = 1;
- ast_clear_flag(p, SIP_NOVIDEO);
- vportno = x;
- /* Scan through the RTP payload types specified in a "m=" line: */
- codecs = m + len;
- while(!ast_strlen_zero(codecs)) {
- if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
- ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
- return -1;
- }
- if (debug)
- ast_verbose("Found RTP video format %d\n", codec);
- ast_rtp_set_m_type(p->vrtp, codec);
- codecs = ast_skip_blanks(codecs + len);
- }
- }
- if (!found )
- ast_log(LOG_WARNING, "Unknown SDP media type in offer: %s\n", m);
- }
- if (portno == -1 && vportno == -1) {
- /* No acceptable offer found in SDP */
- return -2;
- }
- /* Check for Media-description-level-address for audio */
- if (pedanticsipchecking) {
- c = get_sdp_iterate(&destiterator, req, "c");
- if (!ast_strlen_zero(c)) {
- if (sscanf(c, "IN IP4 %256s", host) != 1) {
- ast_log(LOG_WARNING, "Invalid secondary host in c= line, '%s'\n", c);
- } else {
- /* XXX This could block for a long time, and block the main thread! XXX */
- hp = ast_gethostbyname(host, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Unable to lookup host in secondary c= line, '%s'\n", c);
- }
- }
- }
- }
- /* RTP addresses and ports for audio and video */
- sin.sin_family = AF_INET;
- memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
-
- /* Setup audio port number */
- sin.sin_port = htons(portno);
- if (p->rtp && sin.sin_port) {
- ast_rtp_set_peer(p->rtp, &sin);
- if (debug) {
- ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(iabuf,sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- ast_log(LOG_DEBUG,"Peer audio RTP is at port %s:%d\n",ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- }
- }
- /* Check for Media-description-level-address for video */
- if (pedanticsipchecking) {
- c = get_sdp_iterate(&destiterator, req, "c");
- if (!ast_strlen_zero(c)) {
- if (sscanf(c, "IN IP4 %256s", host) != 1) {
- ast_log(LOG_WARNING, "Invalid secondary host in c= line, '%s'\n", c);
- } else {
- /* XXX This could block for a long time, and block the main thread! XXX */
- hp = ast_gethostbyname(host, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Unable to lookup host in secondary c= line, '%s'\n", c);
- }
- }
- }
- }
- /* Setup video port number */
- sin.sin_port = htons(vportno);
- if (p->vrtp && sin.sin_port) {
- ast_rtp_set_peer(p->vrtp, &sin);
- if (debug) {
- ast_verbose("Peer video RTP is at port %s:%d\n", ast_inet_ntoa(iabuf,sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- ast_log(LOG_DEBUG,"Peer video RTP is at port %s:%d\n",ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- }
- }
-
- /* Next, scan through each "a=rtpmap:" line, noting each
- * specified RTP payload type (with corresponding MIME subtype):
- */
- sdpLineNum_iterator_init(&iterator);
- while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') {
- char* mimeSubtype = ast_strdupa(a); /* ensures we have enough space */
- if (!strcasecmp(a, "sendonly")) {
- sendonly=1;
- continue;
- }
- if (!strcasecmp(a, "sendrecv")) {
- sendonly=0;
- }
- if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2) continue;
- if (debug)
- ast_verbose("Found description format %s\n", mimeSubtype);
- /* Note: should really look at the 'freq' and '#chans' params too */
- ast_rtp_set_rtpmap_type(p->rtp, codec, "audio", mimeSubtype);
- if (p->vrtp)
- ast_rtp_set_rtpmap_type(p->vrtp, codec, "video", mimeSubtype);
- }
-
- /* Now gather all of the codecs that were asked for: */
- ast_rtp_get_current_formats(p->rtp,
- &peercapability, &peernoncodeccapability);
- if (p->vrtp)
- ast_rtp_get_current_formats(p->vrtp,
- &vpeercapability, &vpeernoncodeccapability);
- p->jointcapability = p->capability & (peercapability | vpeercapability);
- p->peercapability = (peercapability | vpeercapability);
- p->noncodeccapability = noncodeccapability & peernoncodeccapability;
-
- if (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_AUTO) {
- ast_clear_flag(p, SIP_DTMF);
- if (p->noncodeccapability & AST_RTP_DTMF) {
- /* XXX Would it be reasonable to drop the DSP at this point? XXX */
- ast_set_flag(p, SIP_DTMF_RFC2833);
- } else {
- ast_set_flag(p, SIP_DTMF_INBAND);
- }
- }
-
- if (debug) {
- /* shame on whoever coded this.... */
- const unsigned slen=512;
- char s1[slen], s2[slen], s3[slen], s4[slen];
-
- ast_verbose("Capabilities: us - %s, peer - audio=%s/video=%s, combined - %s\n",
- ast_getformatname_multiple(s1, slen, p->capability),
- ast_getformatname_multiple(s2, slen, peercapability),
- ast_getformatname_multiple(s3, slen, vpeercapability),
- ast_getformatname_multiple(s4, slen, p->jointcapability));
-
- ast_verbose("Non-codec capabilities: us - %s, peer - %s, combined - %s\n",
- ast_rtp_lookup_mime_multiple(s1, slen, noncodeccapability, 0),
- ast_rtp_lookup_mime_multiple(s2, slen, peernoncodeccapability, 0),
- ast_rtp_lookup_mime_multiple(s3, slen, p->noncodeccapability, 0));
- }
- if (!p->jointcapability) {
- ast_log(LOG_NOTICE, "No compatible codecs!\n");
- return -1;
- }
-
- if (!p->owner) /* There's no open channel owning us */
- return 0;
-
- if (!(p->owner->nativeformats & p->jointcapability)) {
- const unsigned slen=512;
- char s1[slen], s2[slen];
- ast_log(LOG_DEBUG, "Oooh, we need to change our formats since our peer supports only %s and not %s\n",
- ast_getformatname_multiple(s1, slen, p->jointcapability),
- ast_getformatname_multiple(s2, slen, p->owner->nativeformats));
- p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1);
- ast_set_read_format(p->owner, p->owner->readformat);
- ast_set_write_format(p->owner, p->owner->writeformat);
- }
- if ((bridgepeer=ast_bridged_channel(p->owner))) {
- /* We have a bridge */
- /* Turn on/off music on hold if we are holding/unholding */
- struct ast_frame af = { AST_FRAME_NULL, };
- if (sin.sin_addr.s_addr && !sendonly) {
- ast_moh_stop(bridgepeer);
-
- /* Activate a re-invite */
- ast_queue_frame(p->owner, &af);
- } else {
- /* No address for RTP, we're on hold */
-
- ast_moh_start(bridgepeer, NULL);
- if (sendonly)
- ast_rtp_stop(p->rtp);
- /* Activate a re-invite */
- ast_queue_frame(p->owner, &af);
- }
- }
-
- /* Manager Hold and Unhold events must be generated, if necessary */
- if (sin.sin_addr.s_addr && !sendonly) {
- append_history(p, "Unhold", req->data);
-
- if (callevents && ast_test_flag(p, SIP_CALL_ONHOLD)) {
- manager_event(EVENT_FLAG_CALL, "Unhold",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n",
- p->owner->name,
- p->owner->uniqueid);
-
- }
- ast_clear_flag(p, SIP_CALL_ONHOLD);
- } else {
- /* No address for RTP, we're on hold */
- append_history(p, "Hold", req->data);
-
- if (callevents && !ast_test_flag(p, SIP_CALL_ONHOLD)) {
- manager_event(EVENT_FLAG_CALL, "Hold",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n",
- p->owner->name,
- p->owner->uniqueid);
- }
- ast_set_flag(p, SIP_CALL_ONHOLD);
- }
-
- return 0;
-}
-
-/*! \brief add_header: Add header to SIP message */
-static int add_header(struct sip_request *req, const char *var, const char *value)
-{
- int x = 0;
-
- if (req->headers == SIP_MAX_HEADERS) {
- ast_log(LOG_WARNING, "Out of SIP header space\n");
- return -1;
- }
-
- if (req->lines) {
- ast_log(LOG_WARNING, "Can't add more headers when lines have been added\n");
- return -1;
- }
-
- if (req->len >= sizeof(req->data) - 4) {
- ast_log(LOG_WARNING, "Out of space, can't add anymore (%s:%s)\n", var, value);
- return -1;
- }
-
- req->header[req->headers] = req->data + req->len;
-
- if (compactheaders) {
- for (x = 0; x < (sizeof(aliases) / sizeof(aliases[0])); x++)
- if (!strcasecmp(aliases[x].fullname, var))
- var = aliases[x].shortname;
- }
-
- snprintf(req->header[req->headers], sizeof(req->data) - req->len - 4, "%s: %s\r\n", var, value);
- req->len += strlen(req->header[req->headers]);
- req->headers++;
-
- return 0;
-}
-
-/*! \brief add_header_contentLen: Add 'Content-Length' header to SIP message */
-static int add_header_contentLength(struct sip_request *req, int len)
-{
- char clen[10];
-
- snprintf(clen, sizeof(clen), "%d", len);
- return add_header(req, "Content-Length", clen);
-}
-
-/*! \brief add_blank_header: Add blank header to SIP message */
-static int add_blank_header(struct sip_request *req)
-{
- if (req->headers == SIP_MAX_HEADERS) {
- ast_log(LOG_WARNING, "Out of SIP header space\n");
- return -1;
- }
- if (req->lines) {
- ast_log(LOG_WARNING, "Can't add more headers when lines have been added\n");
- return -1;
- }
- if (req->len >= sizeof(req->data) - 4) {
- ast_log(LOG_WARNING, "Out of space, can't add anymore\n");
- return -1;
- }
- req->header[req->headers] = req->data + req->len;
- snprintf(req->header[req->headers], sizeof(req->data) - req->len, "\r\n");
- req->len += strlen(req->header[req->headers]);
- req->headers++;
- return 0;
-}
-
-/*! \brief add_line: Add content (not header) to SIP message */
-static int add_line(struct sip_request *req, const char *line)
-{
- if (req->lines == SIP_MAX_LINES) {
- ast_log(LOG_WARNING, "Out of SIP line space\n");
- return -1;
- }
- if (!req->lines) {
- /* Add extra empty return */
- snprintf(req->data + req->len, sizeof(req->data) - req->len, "\r\n");
- req->len += strlen(req->data + req->len);
- }
- if (req->len >= sizeof(req->data) - 4) {
- ast_log(LOG_WARNING, "Out of space, can't add anymore\n");
- return -1;
- }
- req->line[req->lines] = req->data + req->len;
- snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line);
- req->len += strlen(req->line[req->lines]);
- req->lines++;
- return 0;
-}
-
-/*! \brief copy_header: Copy one header field from one request to another */
-static int copy_header(struct sip_request *req, struct sip_request *orig, char *field)
-{
- char *tmp;
- tmp = get_header(orig, field);
- if (!ast_strlen_zero(tmp)) {
- /* Add what we're responding to */
- return add_header(req, field, tmp);
- }
- ast_log(LOG_NOTICE, "No field '%s' present to copy\n", field);
- return -1;
-}
-
-/*! \brief copy_all_header: Copy all headers from one request to another ---*/
-static int copy_all_header(struct sip_request *req, struct sip_request *orig, char *field)
-{
- char *tmp;
- int start = 0;
- int copied = 0;
- for (;;) {
- tmp = __get_header(orig, field, &start);
- if (!ast_strlen_zero(tmp)) {
- /* Add what we're responding to */
- add_header(req, field, tmp);
- copied++;
- } else
- break;
- }
- return copied ? 0 : -1;
-}
-
-/*! \brief copy_via_headers: Copy SIP VIA Headers from the request to the response ---*/
-/* If the client indicates that it wishes to know the port we received from,
- it adds ;rport without an argument to the topmost via header. We need to
- add the port number (from our point of view) to that parameter.
- We always add ;received=<ip address> to the topmost via header.
- Received: RFC 3261, rport RFC 3581 */
-static int copy_via_headers(struct sip_pvt *p, struct sip_request *req, struct sip_request *orig, char *field)
-{
- char tmp[256], *oh, *end;
- int start = 0;
- int copied = 0;
- char iabuf[INET_ADDRSTRLEN];
-
- for (;;) {
- oh = __get_header(orig, field, &start);
- if (!ast_strlen_zero(oh)) {
- if (!copied) { /* Only check for empty rport in topmost via header */
- char *rport;
- char new[256];
-
- /* Find ;rport; (empty request) */
- rport = strstr(oh, ";rport");
- if (rport && *(rport+6) == '=')
- rport = NULL; /* We already have a parameter to rport */
-
- if (rport && (ast_test_flag(p, SIP_NAT) == SIP_NAT_ALWAYS)) {
- /* We need to add received port - rport */
- ast_copy_string(tmp, oh, sizeof(tmp));
-
- rport = strstr(tmp, ";rport");
-
- if (rport) {
- end = strchr(rport + 1, ';');
- if (end)
- memmove(rport, end, strlen(end) + 1);
- else
- *rport = '\0';
- }
-
- /* Add rport to first VIA header if requested */
- /* Whoo hoo! Now we can indicate port address translation too! Just
- another RFC (RFC3581). I'll leave the original comments in for
- posterity. */
- snprintf(new, sizeof(new), "%s;received=%s;rport=%d", tmp, ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port));
- } else {
- /* We should *always* add a received to the topmost via */
- snprintf(new, sizeof(new), "%s;received=%s", oh, ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr));
- }
- add_header(req, field, new);
- } else {
- /* Add the following via headers untouched */
- add_header(req, field, oh);
- }
- copied++;
- } else
- break;
- }
- if (!copied) {
- ast_log(LOG_NOTICE, "No header field '%s' present to copy\n", field);
- return -1;
- }
- return 0;
-}
-
-/*! \brief add_route: Add route header into request per learned route ---*/
-static void add_route(struct sip_request *req, struct sip_route *route)
-{
- char r[256], *p;
- int n, rem = sizeof(r);
-
- if (!route) return;
-
- p = r;
- while (route) {
- n = strlen(route->hop);
- if ((n+3)>rem) break;
- if (p != r) {
- *p++ = ',';
- --rem;
- }
- *p++ = '<';
- ast_copy_string(p, route->hop, rem); p += n;
- *p++ = '>';
- rem -= (n+2);
- route = route->next;
- }
- *p = '\0';
- add_header(req, "Route", r);
-}
-
-/*! \brief set_destination: Set destination from SIP URI ---*/
-static void set_destination(struct sip_pvt *p, char *uri)
-{
- char *h, *maddr, hostname[256];
- char iabuf[INET_ADDRSTRLEN];
- int port, hn;
- struct hostent *hp;
- struct ast_hostent ahp;
- int debug=sip_debug_test_pvt(p);
-
- /* Parse uri to h (host) and port - uri is already just the part inside the <> */
- /* general form we are expecting is sip[s]:username[:password]@host[:port][;...] */
-
- if (debug)
- ast_verbose("set_destination: Parsing <%s> for address/port to send to\n", uri);
-
- /* Find and parse hostname */
- h = strchr(uri, '@');
- if (h)
- ++h;
- else {
- h = uri;
- if (strncmp(h, "sip:", 4) == 0)
- h += 4;
- else if (strncmp(h, "sips:", 5) == 0)
- h += 5;
- }
- hn = strcspn(h, ":;>") + 1;
- if (hn > sizeof(hostname))
- hn = sizeof(hostname);
- ast_copy_string(hostname, h, hn);
- h += hn - 1;
-
- /* Is "port" present? if not default to DEFAULT_SIP_PORT */
- if (*h == ':') {
- /* Parse port */
- ++h;
- port = strtol(h, &h, 10);
- }
- else
- port = DEFAULT_SIP_PORT;
-
- /* Got the hostname:port - but maybe there's a "maddr=" to override address? */
- maddr = strstr(h, "maddr=");
- if (maddr) {
- maddr += 6;
- hn = strspn(maddr, "0123456789.") + 1;
- if (hn > sizeof(hostname)) hn = sizeof(hostname);
- ast_copy_string(hostname, maddr, hn);
- }
-
- hp = ast_gethostbyname(hostname, &ahp);
- if (hp == NULL) {
- ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname);
- return;
- }
- p->sa.sin_family = AF_INET;
- memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr));
- p->sa.sin_port = htons(port);
- if (debug)
- ast_verbose("set_destination: set destination to %s, port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), port);
-}
-
-/*! \brief init_resp: Initialize SIP response, based on SIP request ---*/
-static int init_resp(struct sip_request *req, char *resp, struct sip_request *orig)
-{
- /* Initialize a response */
- if (req->headers || req->len) {
- ast_log(LOG_WARNING, "Request already initialized?!?\n");
- return -1;
- }
- req->method = SIP_RESPONSE;
- req->header[req->headers] = req->data + req->len;
- snprintf(req->header[req->headers], sizeof(req->data) - req->len, "SIP/2.0 %s\r\n", resp);
- req->len += strlen(req->header[req->headers]);
- req->headers++;
- return 0;
-}
-
-/*! \brief init_req: Initialize SIP request ---*/
-static int init_req(struct sip_request *req, int sipmethod, char *recip)
-{
- /* Initialize a response */
- if (req->headers || req->len) {
- ast_log(LOG_WARNING, "Request already initialized?!?\n");
- return -1;
- }
- req->header[req->headers] = req->data + req->len;
- snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %s SIP/2.0\r\n", sip_methods[sipmethod].text, recip);
- req->len += strlen(req->header[req->headers]);
- req->headers++;
- req->method = sipmethod;
- return 0;
-}
-
-
-/*! \brief respprep: Prepare SIP response packet ---*/
-static int respprep(struct sip_request *resp, struct sip_pvt *p, char *msg, struct sip_request *req)
-{
- char newto[256], *ot;
-
- memset(resp, 0, sizeof(*resp));
- init_resp(resp, msg, req);
- copy_via_headers(p, resp, req, "Via");
- if (msg[0] == '2')
- copy_all_header(resp, req, "Record-Route");
- copy_header(resp, req, "From");
- ot = get_header(req, "To");
- if (!strcasestr(ot, "tag=") && strncmp(msg, "100", 3)) {
- /* Add the proper tag if we don't have it already. If they have specified
- their tag, use it. Otherwise, use our own tag */
- if (!ast_strlen_zero(p->theirtag) && ast_test_flag(p, SIP_OUTGOING))
- snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag);
- else if (p->tag && !ast_test_flag(p, SIP_OUTGOING))
- snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag);
- else {
- ast_copy_string(newto, ot, sizeof(newto));
- newto[sizeof(newto) - 1] = '\0';
- }
- ot = newto;
- }
- add_header(resp, "To", ot);
- copy_header(resp, req, "Call-ID");
- copy_header(resp, req, "CSeq");
- add_header(resp, "User-Agent", default_useragent);
- add_header(resp, "Allow", ALLOWED_METHODS);
- if (msg[0] == '2' && (p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER)) {
- /* For registration responses, we also need expiry and
- contact info */
- char tmp[256];
-
- snprintf(tmp, sizeof(tmp), "%d", p->expiry);
- add_header(resp, "Expires", tmp);
- if (p->expiry) { /* Only add contact if we have an expiry time */
- char contact[256];
- snprintf(contact, sizeof(contact), "%s;expires=%d", p->our_contact, p->expiry);
- add_header(resp, "Contact", contact); /* Not when we unregister */
- }
- } else if (p->our_contact[0]) {
- add_header(resp, "Contact", p->our_contact);
- }
- return 0;
-}
-
-/*! \brief reqprep: Initialize a SIP request response packet ---*/
-static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch)
-{
- struct sip_request *orig = &p->initreq;
- char stripped[80];
- char tmp[80];
- char newto[256];
- char *c, *n;
- char *ot, *of;
- int is_strict = 0; /* Strict routing flag */
-
- memset(req, 0, sizeof(struct sip_request));
-
- snprintf(p->lastmsg, sizeof(p->lastmsg), "Tx: %s", sip_methods[sipmethod].text);
-
- if (!seqno) {
- p->ocseq++;
- seqno = p->ocseq;
- }
-
- if (newbranch) {
- p->branch ^= thread_safe_rand();
- build_via(p, p->via, sizeof(p->via));
- }
-
- /* Check for strict or loose router */
- if (p->route && !ast_strlen_zero(p->route->hop) && strstr(p->route->hop,";lr") == NULL)
- is_strict = 1;
-
- if (sipmethod == SIP_CANCEL) {
- c = p->initreq.rlPart2; /* Use original URI */
- } else if (sipmethod == SIP_ACK) {
- /* Use URI from Contact: in 200 OK (if INVITE)
- (we only have the contacturi on INVITEs) */
- if (!ast_strlen_zero(p->okcontacturi))
- c = is_strict ? p->route->hop : p->okcontacturi;
- else
- c = p->initreq.rlPart2;
- } else if (!ast_strlen_zero(p->okcontacturi)) {
- c = is_strict ? p->route->hop : p->okcontacturi; /* Use for BYE or REINVITE */
- } else if (!ast_strlen_zero(p->uri)) {
- c = p->uri;
- } else {
- /* We have no URI, use To: or From: header as URI (depending on direction) */
- c = get_header(orig, (ast_test_flag(p, SIP_OUTGOING)) ? "To" : "From");
- ast_copy_string(stripped, c, sizeof(stripped));
- c = get_in_brackets(stripped);
- n = strchr(c, ';');
- if (n)
- *n = '\0';
- }
- init_req(req, sipmethod, c);
-
- snprintf(tmp, sizeof(tmp), "%d %s", seqno, sip_methods[sipmethod].text);
-
- add_header(req, "Via", p->via);
- if (p->route) {
- set_destination(p, p->route->hop);
- if (is_strict)
- add_route(req, p->route->next);
- else
- add_route(req, p->route);
- }
-
- ot = get_header(orig, "To");
- of = get_header(orig, "From");
-
- /* Add tag *unless* this is a CANCEL, in which case we need to send it exactly
- as our original request, including tag (or presumably lack thereof) */
- if (!strcasestr(ot, "tag=") && sipmethod != SIP_CANCEL) {
- /* Add the proper tag if we don't have it already. If they have specified
- their tag, use it. Otherwise, use our own tag */
- if (ast_test_flag(p, SIP_OUTGOING) && !ast_strlen_zero(p->theirtag))
- snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag);
- else if (!ast_test_flag(p, SIP_OUTGOING))
- snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag);
- else
- snprintf(newto, sizeof(newto), "%s", ot);
- ot = newto;
- }
-
- if (ast_test_flag(p, SIP_OUTGOING)) {
- add_header(req, "From", of);
- add_header(req, "To", ot);
- } else {
- add_header(req, "From", ot);
- add_header(req, "To", of);
- }
- add_header(req, "Contact", p->our_contact);
- copy_header(req, orig, "Call-ID");
- add_header(req, "CSeq", tmp);
-
- add_header(req, "User-Agent", default_useragent);
- add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS);
-
- if (p->rpid)
- add_header(req, "Remote-Party-ID", p->rpid);
-
- return 0;
-}
-
-/*! \brief __transmit_response: Base transmit response function */
-static int __transmit_response(struct sip_pvt *p, char *msg, struct sip_request *req, int reliable)
-{
- struct sip_request resp;
- int seqno = 0;
-
- if (reliable && (sscanf(get_header(req, "CSeq"), "%d ", &seqno) != 1)) {
- ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq"));
- return -1;
- }
- respprep(&resp, p, msg, req);
- add_header_contentLength(&resp, 0);
- /* If we are cancelling an incoming invite for some reason, add information
- about the reason why we are doing this in clear text */
- if (p->owner && p->owner->hangupcause) {
- add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause));
- }
- add_blank_header(&resp);
- return send_response(p, &resp, reliable, seqno);
-}
-
-/*! \brief transmit_response: Transmit response, no retransmits */
-static int transmit_response(struct sip_pvt *p, char *msg, struct sip_request *req)
-{
- return __transmit_response(p, msg, req, 0);
-}
-
-/*! \brief transmit_response_with_unsupported: Transmit response, no retransmits */
-static int transmit_response_with_unsupported(struct sip_pvt *p, char *msg, struct sip_request *req, char *unsupported)
-{
- struct sip_request resp;
- respprep(&resp, p, msg, req);
- append_date(&resp);
- add_header(&resp, "Unsupported", unsupported);
- return send_response(p, &resp, 0, 0);
-}
-
-/*! \brief transmit_response_reliable: Transmit response, Make sure you get a reply */
-static int transmit_response_reliable(struct sip_pvt *p, char *msg, struct sip_request *req, int fatal)
-{
- return __transmit_response(p, msg, req, fatal ? 2 : 1);
-}
-
-/*! \brief append_date: Append date to SIP message ---*/
-static void append_date(struct sip_request *req)
-{
- char tmpdat[256];
- struct tm tm;
- time_t t;
-
- time(&t);
- gmtime_r(&t, &tm);
- strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T GMT", &tm);
- add_header(req, "Date", tmpdat);
-}
-
-/*! \brief transmit_response_with_date: Append date and content length before transmitting response ---*/
-static int transmit_response_with_date(struct sip_pvt *p, char *msg, struct sip_request *req)
-{
- struct sip_request resp;
- respprep(&resp, p, msg, req);
- append_date(&resp);
- add_header_contentLength(&resp, 0);
- add_blank_header(&resp);
- return send_response(p, &resp, 0, 0);
-}
-
-/*! \brief transmit_response_with_allow: Append Accept header, content length before transmitting response ---*/
-static int transmit_response_with_allow(struct sip_pvt *p, char *msg, struct sip_request *req, int reliable)
-{
- struct sip_request resp;
- respprep(&resp, p, msg, req);
- add_header(&resp, "Accept", "application/sdp");
- add_header_contentLength(&resp, 0);
- add_blank_header(&resp);
- return send_response(p, &resp, reliable, 0);
-}
-
-/* transmit_response_with_auth: Respond with authorization request */
-static int transmit_response_with_auth(struct sip_pvt *p, char *msg, struct sip_request *req, char *randdata, int reliable, char *header, int stale)
-{
- struct sip_request resp;
- char tmp[256];
- int seqno = 0;
-
- if (reliable && (sscanf(get_header(req, "CSeq"), "%d ", &seqno) != 1)) {
- ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq"));
- return -1;
- }
- /* Stale means that they sent us correct authentication, but
- based it on an old challenge (nonce) */
- snprintf(tmp, sizeof(tmp), "Digest realm=\"%s\", nonce=\"%s\"%s", global_realm, randdata, stale ? ", stale=true" : "");
- respprep(&resp, p, msg, req);
- add_header(&resp, header, tmp);
- add_header_contentLength(&resp, 0);
- add_blank_header(&resp);
- return send_response(p, &resp, reliable, seqno);
-}
-
-/*! \brief add_text: Add text body to SIP message ---*/
-static int add_text(struct sip_request *req, const char *text)
-{
- /* XXX Convert \n's to \r\n's XXX */
- add_header(req, "Content-Type", "text/plain");
- add_header_contentLength(req, strlen(text));
- add_line(req, text);
- return 0;
-}
-
-/*! \brief add_digit: add DTMF INFO tone to sip message ---*/
-/* Always adds default duration 250 ms, regardless of what came in over the line */
-static int add_digit(struct sip_request *req, char digit)
-{
- char tmp[256];
-
- snprintf(tmp, sizeof(tmp), "Signal=%c\r\nDuration=250\r\n", digit);
- add_header(req, "Content-Type", "application/dtmf-relay");
- add_header_contentLength(req, strlen(tmp));
- add_line(req, tmp);
- return 0;
-}
-
-/*! \brief add_vidupdate: add XML encoded media control with update ---*/
-/* XML: The only way to turn 0 bits of information into a few hundred. */
-static int add_vidupdate(struct sip_request *req)
-{
- const char *xml_is_a_huge_waste_of_space =
- "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n"
- " <media_control>\r\n"
- " <vc_primitive>\r\n"
- " <to_encoder>\r\n"
- " <picture_fast_update>\r\n"
- " </picture_fast_update>\r\n"
- " </to_encoder>\r\n"
- " </vc_primitive>\r\n"
- " </media_control>\r\n";
- add_header(req, "Content-Type", "application/media_control+xml");
- add_header_contentLength(req, strlen(xml_is_a_huge_waste_of_space));
- add_line(req, xml_is_a_huge_waste_of_space);
- return 0;
-}
-
-static void add_codec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate,
- char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
- int debug)
-{
- int rtp_code;
-
- if (debug)
- ast_verbose("Adding codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
- if ((rtp_code = ast_rtp_lookup_code(p->rtp, 1, codec)) == -1)
- return;
-
- ast_build_string(m_buf, m_size, " %d", rtp_code);
- ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
- ast_rtp_lookup_mime_subtype(1, codec),
- sample_rate);
- if (codec == AST_FORMAT_G729A)
- /* Indicate that we don't support VAD (G.729 annex B) */
- ast_build_string(a_buf, a_size, "a=fmtp:%d annexb=no\r\n", rtp_code);
-}
-
-static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_rate,
- char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
- int debug)
-{
- int rtp_code;
-
- if (debug)
- ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype(0, format));
- if ((rtp_code = ast_rtp_lookup_code(p->rtp, 0, format)) == -1)
- return;
-
- ast_build_string(m_buf, m_size, " %d", rtp_code);
- ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
- ast_rtp_lookup_mime_subtype(0, format),
- sample_rate);
- if (format == AST_RTP_DTMF)
- /* Indicate we support DTMF and FLASH... */
- ast_build_string(a_buf, a_size, "a=fmtp:%d 0-16\r\n", rtp_code);
-}
-
-/*! \brief add_sdp: Add Session Description Protocol message ---*/
-static int add_sdp(struct sip_request *resp, struct sip_pvt *p)
-{
- int len = 0;
- int pref_codec;
- int alreadysent = 0;
- struct sockaddr_in sin;
- struct sockaddr_in vsin;
- char v[256];
- char s[256];
- char o[256];
- char c[256];
- char t[256];
- char m_audio[256];
- char m_video[256];
- char a_audio[1024];
- char a_video[1024];
- char *m_audio_next = m_audio;
- char *m_video_next = m_video;
- size_t m_audio_left = sizeof(m_audio);
- size_t m_video_left = sizeof(m_video);
- char *a_audio_next = a_audio;
- char *a_video_next = a_video;
- size_t a_audio_left = sizeof(a_audio);
- size_t a_video_left = sizeof(a_video);
- char iabuf[INET_ADDRSTRLEN];
- int x;
- int capability;
- struct sockaddr_in dest;
- struct sockaddr_in vdest = { 0, };
- int debug;
-
- debug = sip_debug_test_pvt(p);
-
- len = 0;
- if (!p->rtp) {
- ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
- return -1;
- }
- capability = p->jointcapability;
-
- if (!p->sessionid) {
- p->sessionid = getpid();
- p->sessionversion = p->sessionid;
- } else
- p->sessionversion++;
- ast_rtp_get_us(p->rtp, &sin);
- if (p->vrtp)
- ast_rtp_get_us(p->vrtp, &vsin);
-
- if (p->redirip.sin_addr.s_addr) {
-#ifdef SIP_MIDCOM
- if (m_cb && p->r) {
- struct sockaddr_in redirip_hook;
- char iabuf2[INET_ADDRSTRLEN];
- m_cb->ast_get_redirip_audio_hook(p->r, &redirip_hook);
- ast_log(LOG_DEBUG, "Replacing %s:%d by %s:%d in SDP before sending to %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->redirip.sin_addr), ntohs(p->redirip.sin_port), ast_inet_ntoa(iabuf2, sizeof(iabuf2), redirip_hook.sin_addr), ntohs(redirip_hook.sin_port), p->username);
- dest.sin_port = redirip_hook.sin_port;
- dest.sin_addr = redirip_hook.sin_addr;
- } else {
- dest.sin_port = p->redirip.sin_port;
- dest.sin_addr = p->redirip.sin_addr;
- }
-#else
- dest.sin_port = p->redirip.sin_port;
- dest.sin_addr = p->redirip.sin_addr;
-#endif
- if (p->redircodecs)
- capability = p->redircodecs;
- } else {
- dest.sin_addr = p->ourip;
- dest.sin_port = sin.sin_port;
- }
-
- /* Determine video destination */
- if (p->vrtp) {
- if (p->vredirip.sin_addr.s_addr) {
-#ifdef SIP_MIDCOM
- if (m_cb && p->r) {
- struct sockaddr_in vredirip_hook;
- char iabuf2[INET_ADDRSTRLEN];
- m_cb->ast_get_vredirip_video_hook(p->r, &vredirip_hook);
- ast_log(LOG_DEBUG, "Replacing %s:%d by %s:%d in video SDP before sending to %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->vredirip.sin_addr), ntohs(p->vredirip.sin_port), ast_inet_ntoa(iabuf2, sizeof(iabuf2), vredirip_hook.sin_addr), ntohs(vredirip_hook.sin_port), p->username);
- vdest.sin_port = vredirip_hook.sin_port;
- vdest.sin_addr = vredirip_hook.sin_addr;
- } else {
- vdest.sin_port = p->vredirip.sin_port;
- vdest.sin_addr = p->vredirip.sin_addr;
- }
-#else
- vdest.sin_port = p->vredirip.sin_port;
- vdest.sin_addr = p->vredirip.sin_addr;
-#endif
- } else {
- vdest.sin_addr = p->ourip;
- vdest.sin_port = vsin.sin_port;
- }
- }
- if (debug){
- ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(sin.sin_port));
- if (p->vrtp)
- ast_verbose("Video is at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(vsin.sin_port));
- }
-
- /* We break with the "recommendation" and send our IP, in order that our
- peer doesn't have to ast_gethostbyname() us */
-
- snprintf(v, sizeof(v), "v=0\r\n");
- snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr));
- snprintf(s, sizeof(s), "s=session\r\n");
- snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr));
- snprintf(t, sizeof(t), "t=0 0\r\n");
-
- ast_build_string(&m_audio_next, &m_audio_left, "m=audio %d RTP/AVP", ntohs(dest.sin_port));
- ast_build_string(&m_video_next, &m_video_left, "m=video %d RTP/AVP", ntohs(vdest.sin_port));
-
- /* Prefer the codec we were requested to use, first, no matter what */
- if (capability & p->prefcodec) {
- if (p->prefcodec <= AST_FORMAT_MAX_AUDIO)
- add_codec_to_sdp(p, p->prefcodec, 8000,
- &m_audio_next, &m_audio_left,
- &a_audio_next, &a_audio_left,
- debug);
- else
- add_codec_to_sdp(p, p->prefcodec, 90000,
- &m_video_next, &m_video_left,
- &a_video_next, &a_video_left,
- debug);
- alreadysent |= p->prefcodec;
- }
-
- /* Start by sending our preferred codecs */
- for (x = 0; x < 32; x++) {
- if (!(pref_codec = ast_codec_pref_index(&p->prefs, x)))
- break;
-
- if (!(capability & pref_codec))
- continue;
-
- if (alreadysent & pref_codec)
- continue;
-
- if (pref_codec <= AST_FORMAT_MAX_AUDIO)
- add_codec_to_sdp(p, pref_codec, 8000,
- &m_audio_next, &m_audio_left,
- &a_audio_next, &a_audio_left,
- debug);
- else
- add_codec_to_sdp(p, pref_codec, 90000,
- &m_video_next, &m_video_left,
- &a_video_next, &a_video_left,
- debug);
- alreadysent |= pref_codec;
- }
-
- /* Now send any other common codecs, and non-codec formats: */
- for (x = 1; x <= ((videosupport && p->vrtp) ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO); x <<= 1) {
- if (!(capability & x))
- continue;
-
- if (alreadysent & x)
- continue;
-
- if (x <= AST_FORMAT_MAX_AUDIO)
- add_codec_to_sdp(p, x, 8000,
- &m_audio_next, &m_audio_left,
- &a_audio_next, &a_audio_left,
- debug);
- else
- add_codec_to_sdp(p, x, 90000,
- &m_video_next, &m_video_left,
- &a_video_next, &a_video_left,
- debug);
- }
-
- for (x = 1; x <= AST_RTP_MAX; x <<= 1) {
- if (!(p->noncodeccapability & x))
- continue;
-
- add_noncodec_to_sdp(p, x, 8000,
- &m_audio_next, &m_audio_left,
- &a_audio_next, &a_audio_left,
- debug);
- }
-
- ast_build_string(&a_audio_next, &a_audio_left, "a=silenceSupp:off - - - -\r\n");
-
- if ((m_audio_left < 2) || (m_video_left < 2) || (a_audio_left == 0) || (a_video_left == 0))
- ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n");
-
- ast_build_string(&m_audio_next, &m_audio_left, "\r\n");
- ast_build_string(&m_video_next, &m_video_left, "\r\n");
-
- len = strlen(v) + strlen(s) + strlen(o) + strlen(c) + strlen(t) + strlen(m_audio) + strlen(a_audio);
- if ((p->vrtp) && (!ast_test_flag(p, SIP_NOVIDEO)) && (capability & VIDEO_CODEC_MASK)) /* only if video response is appropriate */
- len += strlen(m_video) + strlen(a_video);
-
- add_header(resp, "Content-Type", "application/sdp");
- add_header_contentLength(resp, len);
- add_line(resp, v);
- add_line(resp, o);
- add_line(resp, s);
- add_line(resp, c);
- add_line(resp, t);
- add_line(resp, m_audio);
- add_line(resp, a_audio);
- if ((p->vrtp) && (!ast_test_flag(p, SIP_NOVIDEO)) && (capability & VIDEO_CODEC_MASK)) { /* only if video response is appropriate */
- add_line(resp, m_video);
- add_line(resp, a_video);
- }
-
- /* Update lastrtprx when we send our SDP */
- time(&p->lastrtprx);
- time(&p->lastrtptx);
-
- return 0;
-}
-
-/*! \brief copy_request: copy SIP request (mostly used to save request for responses) ---*/
-static void copy_request(struct sip_request *dst, struct sip_request *src)
-{
- long offset;
- int x;
- offset = ((void *)dst) - ((void *)src);
- /* First copy stuff */
- memcpy(dst, src, sizeof(*dst));
- /* Now fix pointer arithmetic */
- for (x=0; x < src->headers; x++)
- dst->header[x] += offset;
- for (x=0; x < src->lines; x++)
- dst->line[x] += offset;
-}
-
-/*! \brief transmit_response_with_sdp: Used for 200 OK and 183 early media ---*/
-static int transmit_response_with_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans)
-{
- struct sip_request resp;
- int seqno;
- if (sscanf(get_header(req, "CSeq"), "%d ", &seqno) != 1) {
- ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq"));
- return -1;
- }
- respprep(&resp, p, msg, req);
- if (p->rtp) {
- ast_rtp_offered_from_local(p->rtp, 0);
- add_sdp(&resp, p);
- } else {
- ast_log(LOG_ERROR, "Can't add SDP to response, since we have no RTP session allocated. Call-ID %s\n", p->callid);
- }
-#ifdef SIP_MIDCOM
- if (m_cb) {
- if (!m_cb->transmit_response_with_sdp_hook(p)) {
- ast_log(LOG_NOTICE, "Failed transmit_response_with_sdp_hook()\n");
- return -1;
- }
- }
-#endif
- return send_response(p, &resp, retrans, seqno);
-}
-
-/*! \brief determine_firstline_parts: parse first line of incoming SIP request */
-static int determine_firstline_parts( struct sip_request *req )
-{
- char *e, *cmd;
- int len;
-
- cmd = ast_skip_blanks(req->header[0]);
- if (!*cmd)
- return -1;
- req->rlPart1 = cmd;
- e = ast_skip_nonblanks(cmd);
- /* Get the command */
- if (*e)
- *e++ = '\0';
- e = ast_skip_blanks(e);
- if ( !*e )
- return -1;
-
- if ( !strcasecmp(cmd, "SIP/2.0") ) {
- /* We have a response */
- req->rlPart2 = e;
- len = strlen( req->rlPart2 );
- if ( len < 2 ) {
- return -1;
- }
- ast_trim_blanks(e);
- } else {
- /* We have a request */
- if ( *e == '<' ) {
- e++;
- if ( !*e ) {
- return -1;
- }
- }
- req->rlPart2 = e; /* URI */
- if ( ( e= strrchr( req->rlPart2, 'S' ) ) == NULL ) {
- return -1;
- }
- /* XXX maybe trim_blanks() ? */
- while( isspace( *(--e) ) ) {}
- if ( *e == '>' ) {
- *e = '\0';
- } else {
- *(++e)= '\0';
- }
- }
- return 1;
-}
-
-/*! \brief transmit_reinvite_with_sdp: Transmit reinvite with SDP :-) ---*/
-/* A re-invite is basically a new INVITE with the same CALL-ID and TAG as the
- INVITE that opened the SIP dialogue
- We reinvite so that the audio stream (RTP) go directly between
- the SIP UAs. SIP Signalling stays with * in the path.
-*/
-static int transmit_reinvite_with_sdp(struct sip_pvt *p)
-{
- struct sip_request req;
-
-#ifdef SIP_MIDCOM
- if (m_cb) {
- if (!m_cb->transmit_reinvite_with_sdp_hook(p)) {
- ast_log(LOG_NOTICE, "Failed transmit_reinvite_with_sdp_hook()\n");
- if (p->owner)
- ast_queue_hangup(p->owner);
- else
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- }
-#endif
-
- if (ast_test_flag(p, SIP_REINVITE_UPDATE))
- reqprep(&req, p, SIP_UPDATE, 0, 1);
- else
- reqprep(&req, p, SIP_INVITE, 0, 1);
-
- add_header(&req, "Allow", ALLOWED_METHODS);
- if (sipdebug)
- add_header(&req, "X-asterisk-info", "SIP re-invite (RTP bridge)");
- ast_rtp_offered_from_local(p->rtp, 1);
- add_sdp(&req, p);
- /* Use this as the basis */
- copy_request(&p->initreq, &req);
- parse_request(&p->initreq);
- if (sip_debug_test_pvt(p))
- ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
- p->lastinvite = p->ocseq;
- ast_set_flag(p, SIP_OUTGOING);
- return send_request(p, &req, 1, p->ocseq);
-}
-
-/*! \brief extract_uri: Check Contact: URI of SIP message ---*/
-static void extract_uri(struct sip_pvt *p, struct sip_request *req)
-{
- char stripped[256];
- char *c, *n;
- ast_copy_string(stripped, get_header(req, "Contact"), sizeof(stripped));
- c = get_in_brackets(stripped);
- n = strchr(c, ';');
- if (n)
- *n = '\0';
- if (!ast_strlen_zero(c))
- ast_copy_string(p->uri, c, sizeof(p->uri));
-}
-
-/*! \brief build_contact: Build contact header - the contact header we send out ---*/
-static void build_contact(struct sip_pvt *p)
-{
- char iabuf[INET_ADDRSTRLEN];
-
- /* Construct Contact: header */
- if (ourport != 5060) /* Needs to be 5060, according to the RFC */
- snprintf(p->our_contact, sizeof(p->our_contact), "<sip:%s%s%s:%d>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport);
- else
- snprintf(p->our_contact, sizeof(p->our_contact), "<sip:%s%s%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip));
-}
-
-/*! \brief build_rpid: Build the Remote Party-ID & From using callingpres options ---*/
-static void build_rpid(struct sip_pvt *p)
-{
- int send_pres_tags = 1;
- const char *privacy=NULL;
- const char *screen=NULL;
- char buf[256];
- const char *clid = default_callerid;
- const char *clin = NULL;
- char iabuf[INET_ADDRSTRLEN];
- const char *fromdomain;
-
- if (p->rpid || p->rpid_from)
- return;
-
- if (p->owner && p->owner->cid.cid_num)
- clid = p->owner->cid.cid_num;
- if (p->owner && p->owner->cid.cid_name)
- clin = p->owner->cid.cid_name;
- if (ast_strlen_zero(clin))
- clin = clid;
-
- switch (p->callingpres) {
- case AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
- privacy = "off";
- screen = "no";
- break;
- case AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
- privacy = "off";
- screen = "pass";
- break;
- case AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN:
- privacy = "off";
- screen = "fail";
- break;
- case AST_PRES_ALLOWED_NETWORK_NUMBER:
- privacy = "off";
- screen = "yes";
- break;
- case AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED:
- privacy = "full";
- screen = "no";
- break;
- case AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN:
- privacy = "full";
- screen = "pass";
- break;
- case AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN:
- privacy = "full";
- screen = "fail";
- break;
- case AST_PRES_PROHIB_NETWORK_NUMBER:
- privacy = "full";
- screen = "pass";
- break;
- case AST_PRES_NUMBER_NOT_AVAILABLE:
- send_pres_tags = 0;
- break;
- default:
- ast_log(LOG_WARNING, "Unsupported callingpres (%d)\n", p->callingpres);
- if ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED)
- privacy = "full";
- else
- privacy = "off";
- screen = "no";
- break;
- }
-
- fromdomain = ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain;
-
- snprintf(buf, sizeof(buf), "\"%s\" <sip:%s@%s>", clin, clid, fromdomain);
- if (send_pres_tags)
- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ";privacy=%s;screen=%s", privacy, screen);
- p->rpid = strdup(buf);
-
- snprintf(buf, sizeof(buf), "\"%s\" <sip:%s@%s>;tag=%s", clin,
- ast_strlen_zero(p->fromuser) ? clid : p->fromuser,
- fromdomain, p->tag);
- p->rpid_from = strdup(buf);
-}
-
-/*! \brief initreqprep: Initiate new SIP request to peer/user ---*/
-static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod)
-{
- char invite_buf[256] = "";
- char *invite = invite_buf;
- size_t invite_max = sizeof(invite_buf);
- char from[256];
- char to[256];
- char tmp[BUFSIZ/2];
- char tmp2[BUFSIZ/2];
- char iabuf[INET_ADDRSTRLEN];
- char *l = NULL, *n = NULL;
- int x;
- char urioptions[256]="";
-
- if (ast_test_flag(p, SIP_USEREQPHONE)) {
- char onlydigits = 1;
- x=0;
-
- /* Test p->username against allowed characters in AST_DIGIT_ANY
- If it matches the allowed characters list, then sipuser = ";user=phone"
- If not, then sipuser = ""
- */
- /* + is allowed in first position in a tel: uri */
- if (p->username && p->username[0] == '+')
- x=1;
-
- for (; x < strlen(p->username); x++) {
- if (!strchr(AST_DIGIT_ANYNUM, p->username[x])) {
- onlydigits = 0;
- break;
- }
- }
-
- /* If we have only digits, add ;user=phone to the uri */
- if (onlydigits)
- strcpy(urioptions, ";user=phone");
- }
-
-
- snprintf(p->lastmsg, sizeof(p->lastmsg), "Init: %s", sip_methods[sipmethod].text);
-
- if (p->owner) {
- l = p->owner->cid.cid_num;
- n = p->owner->cid.cid_name;
- }
- /* if we are not sending RPID and user wants his callerid restricted */
- if (!ast_test_flag(p, SIP_SENDRPID) && ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED)) {
- l = CALLERID_UNKNOWN;
- n = l;
- }
- if (!l)
- l = default_callerid;
- if (ast_strlen_zero(n))
- n = l;
- /* Allow user to be overridden */
- if (!ast_strlen_zero(p->fromuser))
- l = p->fromuser;
- else /* Save for any further attempts */
- ast_copy_string(p->fromuser, l, sizeof(p->fromuser));
-
- /* Allow user to be overridden */
- if (!ast_strlen_zero(p->fromname))
- n = p->fromname;
- else /* Save for any further attempts */
- ast_copy_string(p->fromname, n, sizeof(p->fromname));
-
- if (pedanticsipchecking) {
- ast_uri_encode(n, tmp, sizeof(tmp), 0);
- n = tmp;
- ast_uri_encode(l, tmp2, sizeof(tmp2), 0);
- l = tmp2;
- }
-
- if ((ourport != 5060) && ast_strlen_zero(p->fromdomain)) /* Needs to be 5060 */
- snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s:%d>;tag=%s", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, ourport, p->tag);
- else
- snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s>;tag=%s", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, p->tag);
-
- /* If we're calling a registered SIP peer, use the fullcontact to dial to the peer */
- if (!ast_strlen_zero(p->fullcontact)) {
- /* If we have full contact, trust it */
- ast_build_string(&invite, &invite_max, "%s", p->fullcontact);
- } else {
- /* Otherwise, use the username while waiting for registration */
- ast_build_string(&invite, &invite_max, "sip:");
- if (!ast_strlen_zero(p->username)) {
- n = p->username;
- if (pedanticsipchecking) {
- ast_uri_encode(n, tmp, sizeof(tmp), 0);
- n = tmp;
- }
- ast_build_string(&invite, &invite_max, "%s@", n);
- }
- ast_build_string(&invite, &invite_max, "%s", p->tohost);
- if (ntohs(p->sa.sin_port) != 5060) /* Needs to be 5060 */
- ast_build_string(&invite, &invite_max, ":%d", ntohs(p->sa.sin_port));
- ast_build_string(&invite, &invite_max, "%s", urioptions);
- }
-
- /* If custom URI options have been provided, append them */
- if (p->options && p->options->uri_options)
- ast_build_string(&invite, &invite_max, ";%s", p->options->uri_options);
-
- ast_copy_string(p->uri, invite_buf, sizeof(p->uri));
-
- /* If there is a VXML URL append it to the SIP URL */
- if (p->options && p->options->vxml_url) {
- snprintf(to, sizeof(to), "<%s>;%s", p->uri, p->options->vxml_url);
- } else {
- snprintf(to, sizeof(to), "<%s>", p->uri);
- }
- memset(req, 0, sizeof(struct sip_request));
- init_req(req, sipmethod, p->uri);
- snprintf(tmp, sizeof(tmp), "%d %s", ++p->ocseq, sip_methods[sipmethod].text);
-
- add_header(req, "Via", p->via);
- /* SLD: FIXME?: do Route: here too? I think not cos this is the first request.
- * OTOH, then we won't have anything in p->route anyway */
- /* Build Remote Party-ID and From */
- if (ast_test_flag(p, SIP_SENDRPID) && (sipmethod == SIP_INVITE)) {
- build_rpid(p);
- add_header(req, "From", p->rpid_from);
- } else {
- add_header(req, "From", from);
- }
- add_header(req, "To", to);
- ast_copy_string(p->exten, l, sizeof(p->exten));
- build_contact(p);
- add_header(req, "Contact", p->our_contact);
- add_header(req, "Call-ID", p->callid);
- add_header(req, "CSeq", tmp);
- add_header(req, "User-Agent", default_useragent);
- add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS);
- if (p->rpid)
- add_header(req, "Remote-Party-ID", p->rpid);
-}
-
-/*! \brief transmit_invite: Build REFER/INVITE/OPTIONS message and transmit it ---*/
-static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init)
-{
- struct sip_request req;
-
- req.method = sipmethod;
- if (init) {
- /* Bump branch even on initial requests */
- p->branch ^= thread_safe_rand();
- build_via(p, p->via, sizeof(p->via));
- if (init > 1)
- initreqprep(&req, p, sipmethod);
- else
- reqprep(&req, p, sipmethod, 0, 1);
- } else
- reqprep(&req, p, sipmethod, 0, 1);
-
- if (p->options && p->options->auth)
- add_header(&req, p->options->authheader, p->options->auth);
- append_date(&req);
- if (sipmethod == SIP_REFER) { /* Call transfer */
- if (!ast_strlen_zero(p->refer_to))
- add_header(&req, "Refer-To", p->refer_to);
- if (!ast_strlen_zero(p->referred_by))
- add_header(&req, "Referred-By", p->referred_by);
- }
-#ifdef OSP_SUPPORT
- if ((req.method != SIP_OPTIONS) && p->options && !ast_strlen_zero(p->options->osptoken)) {
- ast_log(LOG_DEBUG,"Adding OSP Token: %s\n", p->options->osptoken);
- add_header(&req, "P-OSP-Auth-Token", p->options->osptoken);
- }
-#endif
- if (p->options && !ast_strlen_zero(p->options->distinctive_ring))
- {
- add_header(&req, "Alert-Info", p->options->distinctive_ring);
- }
- add_header(&req, "Allow", ALLOWED_METHODS);
- if (p->options && p->options->addsipheaders ) {
- struct ast_channel *ast;
- char *header = (char *) NULL;
- char *content = (char *) NULL;
- char *end = (char *) NULL;
- struct varshead *headp = (struct varshead *) NULL;
- struct ast_var_t *current;
-
- ast = p->owner; /* The owner channel */
- if (ast) {
- char *headdup;
- headp = &ast->varshead;
- if (!headp)
- ast_log(LOG_WARNING,"No Headp for the channel...ooops!\n");
- else {
- AST_LIST_TRAVERSE(headp, current, entries) {
- /* SIPADDHEADER: Add SIP header to outgoing call */
- if (!strncasecmp(ast_var_name(current), "SIPADDHEADER", strlen("SIPADDHEADER"))) {
- header = ast_var_value(current);
- headdup = ast_strdupa(header);
- /* Strip of the starting " (if it's there) */
- if (*headdup == '"')
- headdup++;
- if ((content = strchr(headdup, ':'))) {
- *content = '\0';
- content++; /* Move pointer ahead */
- /* Skip white space */
- while (*content == ' ')
- content++;
- /* Strip the ending " (if it's there) */
- end = content + strlen(content) -1;
- if (*end == '"')
- *end = '\0';
-
- add_header(&req, headdup, content);
- if (sipdebug)
- ast_log(LOG_DEBUG, "Adding SIP Header \"%s\" with content :%s: \n", headdup, content);
- }
- }
- }
- }
- }
- }
- if (sdp && p->rtp) {
- ast_rtp_offered_from_local(p->rtp, 1);
- add_sdp(&req, p);
- } else {
- add_header_contentLength(&req, 0);
- add_blank_header(&req);
- }
-
- if (!p->initreq.headers) {
- /* Use this as the basis */
- copy_request(&p->initreq, &req);
- parse_request(&p->initreq);
- if (sip_debug_test_pvt(p))
- ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
- }
- p->lastinvite = p->ocseq;
- return send_request(p, &req, init ? 2 : 1, p->ocseq);
-}
-
-/*! \brief transmit_state_notify: Used in the SUBSCRIBE notification subsystem ----*/
-static int transmit_state_notify(struct sip_pvt *p, int state, int full, int substate)
-{
- char tmp[4000], from[256], to[256];
- char *t = tmp, *c, *a, *mfrom, *mto;
- size_t maxbytes = sizeof(tmp);
- struct sip_request req;
- char hint[AST_MAX_EXTENSION];
- char *statestring = "terminated";
- const struct cfsubscription_types *subscriptiontype;
- enum state { NOTIFY_OPEN, NOTIFY_INUSE, NOTIFY_CLOSED } local_state = NOTIFY_OPEN;
- char *pidfstate = "--";
- char *pidfnote= "Ready";
-
- memset(from, 0, sizeof(from));
- memset(to, 0, sizeof(to));
- memset(tmp, 0, sizeof(tmp));
-
- switch (state) {
- case (AST_EXTENSION_RINGING | AST_EXTENSION_INUSE):
- if (global_notifyringing)
- statestring = "early";
- else
- statestring = "confirmed";
- local_state = NOTIFY_INUSE;
- pidfstate = "busy";
- pidfnote = "Ringing";
- break;
- case AST_EXTENSION_RINGING:
- statestring = "early";
- local_state = NOTIFY_INUSE;
- pidfstate = "busy";
- pidfnote = "Ringing";
- break;
- case AST_EXTENSION_INUSE:
- statestring = "confirmed";
- local_state = NOTIFY_INUSE;
- pidfstate = "busy";
- pidfnote = "On the phone";
- break;
- case AST_EXTENSION_BUSY:
- statestring = "confirmed";
- local_state = NOTIFY_CLOSED;
- pidfstate = "busy";
- pidfnote = "On the phone";
- break;
- case AST_EXTENSION_UNAVAILABLE:
- statestring = "confirmed";
- local_state = NOTIFY_CLOSED;
- pidfstate = "away";
- pidfnote = "Unavailable";
- break;
- case AST_EXTENSION_NOT_INUSE:
- default:
- /* Default setting */
- break;
- }
-
- subscriptiontype = find_subscription_type(p->subscribed);
-
- /* Check which device/devices we are watching and if they are registered */
- if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, p->exten)) {
- /* If they are not registered, we will override notification and show no availability */
- if (ast_device_state(hint) == AST_DEVICE_UNAVAILABLE) {
- local_state = NOTIFY_CLOSED;
- pidfstate = "away";
- pidfnote = "Not online";
- }
- }
-
- ast_copy_string(from, get_header(&p->initreq, "From"), sizeof(from));
- c = get_in_brackets(from);
- if (strncmp(c, "sip:", 4)) {
- ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c);
- return -1;
- }
- if ((a = strchr(c, ';')))
- *a = '\0';
- mfrom = c;
-
- ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to));
- c = get_in_brackets(to);
- if (strncmp(c, "sip:", 4)) {
- ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c);
- return -1;
- }
- if ((a = strchr(c, ';')))
- *a = '\0';
- mto = c;
-
- reqprep(&req, p, SIP_NOTIFY, 0, 1);
-
-
- add_header(&req, "Event", subscriptiontype->event);
- add_header(&req, "Content-Type", subscriptiontype->mediatype);
- switch(state) {
- case AST_EXTENSION_DEACTIVATED:
- if (p->subscribed == TIMEOUT)
- add_header(&req, "Subscription-State", "terminated;reason=timeout");
- else {
- add_header(&req, "Subscription-State", "terminated;reason=probation");
- add_header(&req, "Retry-After", "60");
- }
- break;
- case AST_EXTENSION_REMOVED:
- add_header(&req, "Subscription-State", "terminated;reason=noresource");
- break;
- break;
- default:
- if (p->expiry)
- add_header(&req, "Subscription-State", "active");
- else /* Expired */
- add_header(&req, "Subscription-State", "terminated;reason=timeout");
- }
- switch (p->subscribed) {
- case XPIDF_XML:
- case CPIM_PIDF_XML:
- ast_build_string(&t, &maxbytes, "<?xml version=\"1.0\"?>\n");
- ast_build_string(&t, &maxbytes, "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n");
- ast_build_string(&t, &maxbytes, "<presence>\n");
- ast_build_string(&t, &maxbytes, "<presentity uri=\"%s;method=SUBSCRIBE\" />\n", mfrom);
- ast_build_string(&t, &maxbytes, "<atom id=\"%s\">\n", p->exten);
- ast_build_string(&t, &maxbytes, "<address uri=\"%s;user=ip\" priority=\"0.800000\">\n", mto);
- ast_build_string(&t, &maxbytes, "<status status=\"%s\" />\n", (local_state == NOTIFY_OPEN) ? "open" : (local_state == NOTIFY_INUSE) ? "inuse" : "closed");
- ast_build_string(&t, &maxbytes, "<msnsubstatus substatus=\"%s\" />\n", (local_state == NOTIFY_OPEN) ? "online" : (local_state == NOTIFY_INUSE) ? "onthephone" : "offline");
- ast_build_string(&t, &maxbytes, "</address>\n</atom>\n</presence>\n");
- break;
- case PIDF_XML: /* Eyebeam supports this format */
- ast_build_string(&t, &maxbytes, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
- ast_build_string(&t, &maxbytes, "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \nxmlns:pp=\"urn:ietf:params:xml:ns:pidf:person\"\nxmlns:es=\"urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status\"\nxmlns:ep=\"urn:ietf:params:xml:ns:pidf:rpid:rpid-person\"\nentity=\"%s\">\n", mfrom);
- ast_build_string(&t, &maxbytes, "<pp:person><status>\n");
- if (pidfstate[0] != '-')
- ast_build_string(&t, &maxbytes, "<ep:activities><ep:%s/></ep:activities>\n", pidfstate);
- ast_build_string(&t, &maxbytes, "</status></pp:person>\n");
- ast_build_string(&t, &maxbytes, "<note>%s</note>\n", pidfnote); /* Note */
- ast_build_string(&t, &maxbytes, "<tuple id=\"%s\">\n", p->exten); /* Tuple start */
- ast_build_string(&t, &maxbytes, "<contact priority=\"1\">%s</contact>\n", mto);
- if (pidfstate[0] == 'b') /* Busy? Still open ... */
- ast_build_string(&t, &maxbytes, "<status><basic>open</basic></status>\n");
- else
- ast_build_string(&t, &maxbytes, "<status><basic>%s</basic></status>\n", (local_state != NOTIFY_CLOSED) ? "open" : "closed");
- ast_build_string(&t, &maxbytes, "</tuple>\n</presence>\n");
- break;
- case DIALOG_INFO_XML: /* SNOM subscribes in this format */
- ast_build_string(&t, &maxbytes, "<?xml version=\"1.0\"?>\n");
- ast_build_string(&t, &maxbytes, "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"%d\" state=\"%s\" entity=\"%s\">\n", p->dialogver++, full ? "full":"partial", mto);
- if ((state & AST_EXTENSION_RINGING) && global_notifyringing)
- ast_build_string(&t, &maxbytes, "<dialog id=\"%s\" direction=\"recipient\">\n", p->exten);
- else
- ast_build_string(&t, &maxbytes, "<dialog id=\"%s\">\n", p->exten);
- ast_build_string(&t, &maxbytes, "<state>%s</state>\n", statestring);
- ast_build_string(&t, &maxbytes, "</dialog>\n</dialog-info>\n");
- break;
- case NONE:
- default:
- break;
- }
-
- if (t > tmp + sizeof(tmp))
- ast_log(LOG_WARNING, "Buffer overflow detected!! (Please file a bug report)\n");
-
- add_header_contentLength(&req, strlen(tmp));
- add_line(&req, tmp);
-
- return send_request(p, &req, 1, p->ocseq);
-}
-
-/*! \brief transmit_notify_with_mwi: Notify user of messages waiting in voicemail ---*/
-/* Notification only works for registered peers with mailbox= definitions
- * in sip.conf
- * We use the SIP Event package message-summary
- * MIME type defaults to "application/simple-message-summary";
- */
-static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, char *vmexten)
-{
- struct sip_request req;
- char tmp[500];
- char *t = tmp;
- size_t maxbytes = sizeof(tmp);
- char iabuf[INET_ADDRSTRLEN];
-
- initreqprep(&req, p, SIP_NOTIFY);
- add_header(&req, "Event", "message-summary");
- add_header(&req, "Content-Type", default_notifymime);
-
- ast_build_string(&t, &maxbytes, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
- ast_build_string(&t, &maxbytes, "Message-Account: sip:%s@%s\r\n", !ast_strlen_zero(vmexten) ? vmexten : global_vmexten, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain);
- ast_build_string(&t, &maxbytes, "Voice-Message: %d/%d (0/0)\r\n", newmsgs, oldmsgs);
-
- if (t > tmp + sizeof(tmp))
- ast_log(LOG_WARNING, "Buffer overflow detected!! (Please file a bug report)\n");
-
- add_header_contentLength(&req, strlen(tmp));
- add_line(&req, tmp);
-
- if (!p->initreq.headers) { /* Use this as the basis */
- copy_request(&p->initreq, &req);
- parse_request(&p->initreq);
- if (sip_debug_test_pvt(p))
- ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
- determine_firstline_parts(&p->initreq);
- }
-
- return send_request(p, &req, 1, p->ocseq);
-}
-
-/*! \brief transmit_sip_request: Transmit SIP request */
-static int transmit_sip_request(struct sip_pvt *p,struct sip_request *req)
-{
- if (!p->initreq.headers) {
- /* Use this as the basis */
- copy_request(&p->initreq, req);
- parse_request(&p->initreq);
- if (sip_debug_test_pvt(p))
- ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
- determine_firstline_parts(&p->initreq);
- }
-
- return send_request(p, req, 0, p->ocseq);
-}
-
-/*! \brief transmit_notify_with_sipfrag: Notify a transferring party of the status of trasnfer ---*/
-/* Apparently the draft SIP REFER structure was too simple, so it was decided that the
- * status of transfers also needed to be sent via NOTIFY instead of just the 202 Accepted
- * that had worked heretofore.
- */
-static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq)
-{
- struct sip_request req;
- char tmp[20];
- reqprep(&req, p, SIP_NOTIFY, 0, 1);
- snprintf(tmp, sizeof(tmp), "refer;id=%d", cseq);
- add_header(&req, "Event", tmp);
- add_header(&req, "Subscription-state", "terminated;reason=noresource");
- add_header(&req, "Content-Type", "message/sipfrag;version=2.0");
-
- strcpy(tmp, "SIP/2.0 200 OK");
- add_header_contentLength(&req, strlen(tmp));
- add_line(&req, tmp);
-
- if (!p->initreq.headers) {
- /* Use this as the basis */
- copy_request(&p->initreq, &req);
- parse_request(&p->initreq);
- if (sip_debug_test_pvt(p))
- ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
- determine_firstline_parts(&p->initreq);
- }
-
- return send_request(p, &req, 1, p->ocseq);
-}
-
-static char *regstate2str(int regstate)
-{
- switch(regstate) {
- case REG_STATE_FAILED:
- return "Failed";
- case REG_STATE_UNREGISTERED:
- return "Unregistered";
- case REG_STATE_REGSENT:
- return "Request Sent";
- case REG_STATE_AUTHSENT:
- return "Auth. Sent";
- case REG_STATE_REGISTERED:
- return "Registered";
- case REG_STATE_REJECTED:
- return "Rejected";
- case REG_STATE_TIMEOUT:
- return "Timeout";
- case REG_STATE_NOAUTH:
- return "No Authentication";
- default:
- return "Unknown";
- }
-}
-
-static int transmit_register(struct sip_registry *r, int sipmethod, char *auth, char *authheader);
-
-/*! \brief sip_reregister: Update registration with SIP Proxy---*/
-static int sip_reregister(void *data)
-{
- /* if we are here, we know that we need to reregister. */
- struct sip_registry *r= ASTOBJ_REF((struct sip_registry *) data);
-
- /* if we couldn't get a reference to the registry object, punt */
- if (!r)
- return 0;
-
- if (r->call && recordhistory) {
- char tmp[80];
- snprintf(tmp, sizeof(tmp), "Account: %s@%s", r->username, r->hostname);
- append_history(r->call, "RegistryRenew", tmp);
- }
- /* Since registry's are only added/removed by the the monitor thread, this
- may be overkill to reference/dereference at all here */
- if (sipdebug)
- ast_log(LOG_NOTICE, " -- Re-registration for %s@%s\n", r->username, r->hostname);
-
- r->expire = -1;
- __sip_do_register(r);
- ASTOBJ_UNREF(r, sip_registry_destroy);
- return 0;
-}
-
-/*! \brief __sip_do_register: Register with SIP proxy ---*/
-static int __sip_do_register(struct sip_registry *r)
-{
- int res;
-
- res = transmit_register(r, SIP_REGISTER, NULL, NULL);
- return res;
-}
-
-/*! \brief sip_reg_timeout: Registration timeout, register again */
-static int sip_reg_timeout(void *data)
-{
-
- /* if we are here, our registration timed out, so we'll just do it over */
- struct sip_registry *r = ASTOBJ_REF((struct sip_registry *) data);
- struct sip_pvt *p;
- int res;
-
- /* if we couldn't get a reference to the registry object, punt */
- if (!r)
- return 0;
-
- ast_log(LOG_NOTICE, " -- Registration for '%s@%s' timed out, trying again (Attempt #%d)\n", r->username, r->hostname, r->regattempts);
- if (r->call) {
- /* Unlink us, destroy old call. Locking is not relevant here because all this happens
- in the single SIP manager thread. */
- p = r->call;
- if (p->registry)
- ASTOBJ_UNREF(p->registry, sip_registry_destroy);
- r->call = NULL;
- ast_set_flag(p, SIP_NEEDDESTROY);
- /* Pretend to ACK anything just in case */
- __sip_pretend_ack(p);
- }
- /* If we have a limit, stop registration and give up */
- if (global_regattempts_max && (r->regattempts > global_regattempts_max)) {
- /* Ok, enough is enough. Don't try any more */
- /* We could add an external notification here...
- steal it from app_voicemail :-) */
- ast_log(LOG_NOTICE, " -- Giving up forever trying to register '%s@%s'\n", r->username, r->hostname);
- r->regstate=REG_STATE_FAILED;
- } else {
- r->regstate=REG_STATE_UNREGISTERED;
- r->timeout = -1;
- res=transmit_register(r, SIP_REGISTER, NULL, NULL);
- }
- manager_event(EVENT_FLAG_SYSTEM, "Registry", "Channel: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate));
- ASTOBJ_UNREF(r,sip_registry_destroy);
- return 0;
-}
-
-/*! \brief transmit_register: Transmit register to SIP proxy or UA ---*/
-static int transmit_register(struct sip_registry *r, int sipmethod, char *auth, char *authheader)
-{
- struct sip_request req;
- char from[256];
- char to[256];
- char tmp[80];
- char via[80];
- char addr[80];
- struct sip_pvt *p;
-
- /* exit if we are already in process with this registrar ?*/
- if ( r == NULL || ((auth==NULL) && (r->regstate==REG_STATE_REGSENT || r->regstate==REG_STATE_AUTHSENT))) {
- ast_log(LOG_NOTICE, "Strange, trying to register %s@%s when registration already pending\n", r->username, r->hostname);
- return 0;
- }
-
- if (r->call) { /* We have a registration */
- if (!auth) {
- ast_log(LOG_WARNING, "Already have a REGISTER going on to %s@%s?? \n", r->username, r->hostname);
- return 0;
- } else {
- p = r->call;
- make_our_tag(p->tag, sizeof(p->tag)); /* create a new local tag for every register attempt */
- p->theirtag[0]='\0'; /* forget their old tag, so we don't match tags when getting response */
- }
- } else {
- /* Build callid for registration if we haven't registered before */
- if (!r->callid_valid) {
- build_callid(r->callid, sizeof(r->callid), __ourip, default_fromdomain);
- r->callid_valid = 1;
- }
- /* Allocate SIP packet for registration */
- p=sip_alloc( r->callid, NULL, 0, SIP_REGISTER);
- if (!p) {
- ast_log(LOG_WARNING, "Unable to allocate registration call\n");
- return 0;
- }
- if (recordhistory) {
- char tmp[80];
- snprintf(tmp, sizeof(tmp), "Account: %s@%s", r->username, r->hostname);
- append_history(p, "RegistryInit", tmp);
- }
- /* Find address to hostname */
- if (create_addr(p, r->hostname)) {
- /* we have what we hope is a temporary network error,
- * probably DNS. We need to reschedule a registration try */
- sip_destroy(p);
- if (r->timeout > -1) {
- ast_sched_del(sched, r->timeout);
- r->timeout = ast_sched_add(sched, global_reg_timeout*1000, sip_reg_timeout, r);
- ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout);
- } else {
- r->timeout = ast_sched_add(sched, global_reg_timeout*1000, sip_reg_timeout, r);
- ast_log(LOG_WARNING, "Probably a DNS error for registration to %s@%s, trying REGISTER again (after %d seconds)\n", r->username, r->hostname, global_reg_timeout);
- }
- r->regattempts++;
- return 0;
- }
- /* Copy back Call-ID in case create_addr changed it */
- ast_copy_string(r->callid, p->callid, sizeof(r->callid));
- if (r->portno)
- p->sa.sin_port = htons(r->portno);
- ast_set_flag(p, SIP_OUTGOING); /* Registration is outgoing call */
- r->call=p; /* Save pointer to SIP packet */
- p->registry=ASTOBJ_REF(r); /* Add pointer to registry in packet */
- if (!ast_strlen_zero(r->secret)) /* Secret (password) */
- ast_copy_string(p->peersecret, r->secret, sizeof(p->peersecret));
- if (!ast_strlen_zero(r->md5secret))
- ast_copy_string(p->peermd5secret, r->md5secret, sizeof(p->peermd5secret));
- /* User name in this realm
- - if authuser is set, use that, otherwise use username */
- if (!ast_strlen_zero(r->authuser)) {
- ast_copy_string(p->peername, r->authuser, sizeof(p->peername));
- ast_copy_string(p->authname, r->authuser, sizeof(p->authname));
- } else {
- if (!ast_strlen_zero(r->username)) {
- ast_copy_string(p->peername, r->username, sizeof(p->peername));
- ast_copy_string(p->authname, r->username, sizeof(p->authname));
- ast_copy_string(p->fromuser, r->username, sizeof(p->fromuser));
- }
- }
- if (!ast_strlen_zero(r->username))
- ast_copy_string(p->username, r->username, sizeof(p->username));
- /* Save extension in packet */
- ast_copy_string(p->exten, r->contact, sizeof(p->exten));
-
- /*
- check which address we should use in our contact header
- based on whether the remote host is on the external or
- internal network so we can register through nat
- */
- if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
- memcpy(&p->ourip, &bindaddr.sin_addr, sizeof(p->ourip));
- build_contact(p);
- }
-
- /* set up a timeout */
- if (auth == NULL) {
- if (r->timeout > -1) {
- ast_log(LOG_WARNING, "Still have a registration timeout, #%d - deleting it\n", r->timeout);
- ast_sched_del(sched, r->timeout);
- }
- r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, r);
- ast_log(LOG_DEBUG, "Scheduled a registration timeout for %s id #%d \n", r->hostname, r->timeout);
- }
-
- if (strchr(r->username, '@')) {
- snprintf(from, sizeof(from), "<sip:%s>;tag=%s", r->username, p->tag);
- if (!ast_strlen_zero(p->theirtag))
- snprintf(to, sizeof(to), "<sip:%s>;tag=%s", r->username, p->theirtag);
- else
- snprintf(to, sizeof(to), "<sip:%s>", r->username);
- } else {
- snprintf(from, sizeof(from), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->tag);
- if (!ast_strlen_zero(p->theirtag))
- snprintf(to, sizeof(to), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->theirtag);
- else
- snprintf(to, sizeof(to), "<sip:%s@%s>", r->username, p->tohost);
- }
-
- /* Fromdomain is what we are registering to, regardless of actual
- host name from SRV */
- if (!ast_strlen_zero(p->fromdomain))
- snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
- else
- snprintf(addr, sizeof(addr), "sip:%s", r->hostname);
- ast_copy_string(p->uri, addr, sizeof(p->uri));
-
- p->branch ^= thread_safe_rand();
-
- memset(&req, 0, sizeof(req));
- init_req(&req, sipmethod, addr);
-
- /* Add to CSEQ */
- snprintf(tmp, sizeof(tmp), "%u %s", ++r->ocseq, sip_methods[sipmethod].text);
- p->ocseq = r->ocseq;
-
- build_via(p, via, sizeof(via));
- add_header(&req, "Via", via);
- add_header(&req, "From", from);
- add_header(&req, "To", to);
- add_header(&req, "Call-ID", p->callid);
- add_header(&req, "CSeq", tmp);
- add_header(&req, "User-Agent", default_useragent);
- add_header(&req, "Max-Forwards", DEFAULT_MAX_FORWARDS);
-
-
- if (auth) /* Add auth header */
- add_header(&req, authheader, auth);
- else if (!ast_strlen_zero(r->nonce)) {
- char digest[1024];
-
- /* We have auth data to reuse, build a digest header! */
- if (sipdebug)
- ast_log(LOG_DEBUG, " >>> Re-using Auth data for %s@%s\n", r->username, r->hostname);
- ast_copy_string(p->realm, r->realm, sizeof(p->realm));
- ast_copy_string(p->nonce, r->nonce, sizeof(p->nonce));
- ast_copy_string(p->domain, r->domain, sizeof(p->domain));
- ast_copy_string(p->opaque, r->opaque, sizeof(p->opaque));
- ast_copy_string(p->qop, r->qop, sizeof(p->qop));
- p->noncecount = r->noncecount++;
-
- memset(digest,0,sizeof(digest));
- if(!build_reply_digest(p, sipmethod, digest, sizeof(digest)))
- add_header(&req, "Authorization", digest);
- else
- ast_log(LOG_NOTICE, "No authorization available for authentication of registration to %s@%s\n", r->username, r->hostname);
-
- }
-
- snprintf(tmp, sizeof(tmp), "%d", default_expiry);
- add_header(&req, "Expires", tmp);
- add_header(&req, "Contact", p->our_contact);
- add_header(&req, "Event", "registration");
- add_header_contentLength(&req, 0);
- add_blank_header(&req);
- copy_request(&p->initreq, &req);
- parse_request(&p->initreq);
- if (sip_debug_test_pvt(p)) {
- ast_verbose("REGISTER %d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
- }
- determine_firstline_parts(&p->initreq);
- r->regstate=auth?REG_STATE_AUTHSENT:REG_STATE_REGSENT;
- r->regattempts++; /* Another attempt */
- if (option_debug > 3)
- ast_verbose("REGISTER attempt %d to %s@%s\n", r->regattempts, r->username, r->hostname);
- return send_request(p, &req, 2, p->ocseq);
-}
-
-/*! \brief transmit_message_with_text: Transmit text with SIP MESSAGE method ---*/
-static int transmit_message_with_text(struct sip_pvt *p, const char *text)
-{
- struct sip_request req;
- reqprep(&req, p, SIP_MESSAGE, 0, 1);
- add_text(&req, text);
- return send_request(p, &req, 1, p->ocseq);
-}
-
-/*! \brief transmit_refer: Transmit SIP REFER message ---*/
-static int transmit_refer(struct sip_pvt *p, const char *dest)
-{
- struct sip_request req;
- char from[256];
- char *of, *c;
- char referto[256];
-
- if (ast_test_flag(p, SIP_OUTGOING))
- of = get_header(&p->initreq, "To");
- else
- of = get_header(&p->initreq, "From");
- ast_copy_string(from, of, sizeof(from));
- of = get_in_brackets(from);
- ast_copy_string(p->from,of,sizeof(p->from));
- if (strncmp(of, "sip:", 4)) {
- ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
- } else
- of += 4;
- /* Get just the username part */
- if ((c = strchr(dest, '@'))) {
- c = NULL;
- } else if ((c = strchr(of, '@'))) {
- *c = '\0';
- c++;
- }
- if (c) {
- snprintf(referto, sizeof(referto), "<sip:%s@%s>", dest, c);
- } else {
- snprintf(referto, sizeof(referto), "<sip:%s>", dest);
- }
-
- /* save in case we get 407 challenge */
- ast_copy_string(p->refer_to, referto, sizeof(p->refer_to));
- ast_copy_string(p->referred_by, p->our_contact, sizeof(p->referred_by));
-
- reqprep(&req, p, SIP_REFER, 0, 1);
- add_header(&req, "Refer-To", referto);
- if (!ast_strlen_zero(p->our_contact))
- add_header(&req, "Referred-By", p->our_contact);
- add_blank_header(&req);
- return send_request(p, &req, 1, p->ocseq);
-}
-
-/*! \brief transmit_info_with_digit: Send SIP INFO dtmf message, see Cisco documentation on cisco.co
-m ---*/
-static int transmit_info_with_digit(struct sip_pvt *p, char digit)
-{
- struct sip_request req;
- reqprep(&req, p, SIP_INFO, 0, 1);
- add_digit(&req, digit);
- return send_request(p, &req, 1, p->ocseq);
-}
-
-/*! \brief transmit_info_with_vidupdate: Send SIP INFO with video update request ---*/
-static int transmit_info_with_vidupdate(struct sip_pvt *p)
-{
- struct sip_request req;
- reqprep(&req, p, SIP_INFO, 0, 1);
- add_vidupdate(&req);
- return send_request(p, &req, 1, p->ocseq);
-}
-
-/*! \brief transmit_request: transmit generic SIP request ---*/
-static int transmit_request(struct sip_pvt *p, int sipmethod, int seqno, int reliable, int newbranch)
-{
- struct sip_request resp;
- reqprep(&resp, p, sipmethod, seqno, newbranch);
- add_header_contentLength(&resp, 0);
- add_blank_header(&resp);
- return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq);
-}
-
-/*! \brief transmit_request_with_auth: Transmit SIP request, auth added ---*/
-static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, int seqno, int reliable, int newbranch)
-{
- struct sip_request resp;
-
- reqprep(&resp, p, sipmethod, seqno, newbranch);
- if (*p->realm) {
- char digest[1024];
-
- memset(digest, 0, sizeof(digest));
- if(!build_reply_digest(p, sipmethod, digest, sizeof(digest))) {
- if (p->options && p->options->auth_type == PROXY_AUTH)
- add_header(&resp, "Proxy-Authorization", digest);
- else if (p->options && p->options->auth_type == WWW_AUTH)
- add_header(&resp, "Authorization", digest);
- else /* Default, to be backwards compatible (maybe being too careful, but leaving it for now) */
- add_header(&resp, "Proxy-Authorization", digest);
- } else
- ast_log(LOG_WARNING, "No authentication available for call %s\n", p->callid);
- }
- /* If we are hanging up and know a cause for that, send it in clear text to make
- debugging easier. */
- if (sipmethod == SIP_BYE) {
- if (p->owner && p->owner->hangupcause) {
- add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause));
- }
- }
-
- add_header_contentLength(&resp, 0);
- add_blank_header(&resp);
- return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq);
-}
-
-static void destroy_association(struct sip_peer *peer)
-{
- if (!ast_test_flag((&global_flags_page2), SIP_PAGE2_IGNOREREGEXPIRE)) {
- if (ast_test_flag(&(peer->flags_page2), SIP_PAGE2_RT_FROMCONTACT)) {
- ast_update_realtime("sippeers", "name", peer->name, "fullcontact", "", "ipaddr", "", "port", "", "regseconds", "0", "username", "", NULL);
- } else {
- ast_db_del("SIP/Registry", peer->name);
- }
- }
-}
-
-/*! \brief expire_register: Expire registration of SIP peer ---*/
-static int expire_register(void *data)
-{
- struct sip_peer *peer = data;
-
- memset(&peer->addr, 0, sizeof(peer->addr));
-
- destroy_association(peer);
-
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name);
- register_peer_exten(peer, 0);
- peer->expire = -1;
- ast_device_state_changed("SIP/%s", peer->name);
- if (ast_test_flag(peer, SIP_SELFDESTRUCT) || ast_test_flag((&peer->flags_page2), SIP_PAGE2_RTAUTOCLEAR)) {
- peer = ASTOBJ_CONTAINER_UNLINK(&peerl, peer);
- ASTOBJ_UNREF(peer, sip_destroy_peer);
- }
-
- return 0;
-}
-
-static int sip_poke_peer(struct sip_peer *peer);
-
-static int sip_poke_peer_s(void *data)
-{
- struct sip_peer *peer = data;
- peer->pokeexpire = -1;
- sip_poke_peer(peer);
- return 0;
-}
-
-/*! \brief reg_source_db: Get registration details from Asterisk DB ---*/
-static void reg_source_db(struct sip_peer *peer)
-{
- char data[256];
- char iabuf[INET_ADDRSTRLEN];
- struct in_addr in;
- int expiry;
- int port;
- char *scan, *addr, *port_str, *expiry_str, *username, *contact;
-
- if (ast_test_flag(&(peer->flags_page2), SIP_PAGE2_RT_FROMCONTACT))
- return;
- if (ast_db_get("SIP/Registry", peer->name, data, sizeof(data)))
- return;
-
- scan = data;
- addr = strsep(&scan, ":");
- port_str = strsep(&scan, ":");
- expiry_str = strsep(&scan, ":");
- username = strsep(&scan, ":");
- contact = scan; /* Contact include sip: and has to be the last part of the database entry as long as we use : as a separator */
-
- if (!inet_aton(addr, &in))
- return;
-
- if (port_str)
- port = atoi(port_str);
- else
- return;
-
- if (expiry_str)
- expiry = atoi(expiry_str);
- else
- return;
-
- if (username)
- ast_copy_string(peer->username, username, sizeof(peer->username));
- if (contact)
- ast_copy_string(peer->fullcontact, contact, sizeof(peer->fullcontact));
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "SIP Seeding peer from astdb: '%s' at %s@%s:%d for %d\n",
- peer->name, peer->username, ast_inet_ntoa(iabuf, sizeof(iabuf), in), port, expiry);
-
- memset(&peer->addr, 0, sizeof(peer->addr));
- peer->addr.sin_family = AF_INET;
- peer->addr.sin_addr = in;
- peer->addr.sin_port = htons(port);
- if (sipsock < 0) {
- /* SIP isn't up yet, so schedule a poke only, pretty soon */
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
- peer->pokeexpire = ast_sched_add(sched, thread_safe_rand() % 5000 + 1, sip_poke_peer_s, peer);
- } else
- sip_poke_peer(peer);
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- peer->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, peer);
- register_peer_exten(peer, 1);
-}
-
-/*! \brief parse_ok_contact: Parse contact header for 200 OK on INVITE ---*/
-static int parse_ok_contact(struct sip_pvt *pvt, struct sip_request *req)
-{
- char contact[250];
- char *c, *n, *pt;
- int port;
- struct hostent *hp;
- struct ast_hostent ahp;
- struct sockaddr_in oldsin;
-
- /* Look for brackets */
- ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact));
- c = get_in_brackets(contact);
-
- /* Save full contact to call pvt for later bye or re-invite */
- ast_copy_string(pvt->fullcontact, c, sizeof(pvt->fullcontact));
-
- /* Save URI for later ACKs, BYE or RE-invites */
- ast_copy_string(pvt->okcontacturi, c, sizeof(pvt->okcontacturi));
-
- /* Make sure it's a SIP URL */
- if (strncasecmp(c, "sip:", 4)) {
- ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", c);
- } else
- c += 4;
-
- /* Ditch arguments */
- n = strchr(c, ';');
- if (n)
- *n = '\0';
-
- /* Grab host */
- n = strchr(c, '@');
- if (!n) {
- n = c;
- c = NULL;
- } else {
- *n = '\0';
- n++;
- }
- pt = strchr(n, ':');
- if (pt) {
- *pt = '\0';
- pt++;
- port = atoi(pt);
- } else
- port = DEFAULT_SIP_PORT;
-
- memcpy(&oldsin, &pvt->sa, sizeof(oldsin));
-
- if (!(ast_test_flag(pvt, SIP_NAT) & SIP_NAT_ROUTE)) {
- /* XXX This could block for a long time XXX */
- /* We should only do this if it's a name, not an IP */
- hp = ast_gethostbyname(n, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Invalid host '%s'\n", n);
- return -1;
- }
- pvt->sa.sin_family = AF_INET;
- memcpy(&pvt->sa.sin_addr, hp->h_addr, sizeof(pvt->sa.sin_addr));
- pvt->sa.sin_port = htons(port);
- } else {
- /* Don't trust the contact field. Just use what they came to us
- with. */
- memcpy(&pvt->sa, &pvt->recv, sizeof(pvt->sa));
- }
- return 0;
-}
-
-
-enum parse_register_result {
- PARSE_REGISTER_FAILED,
- PARSE_REGISTER_UPDATE,
- PARSE_REGISTER_QUERY,
-};
-
-/*! \brief parse_register_contact: Parse contact header and save registration ---*/
-static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_request *req)
-{
- char contact[80];
- char data[256];
- char iabuf[INET_ADDRSTRLEN];
- char *expires = get_header(req, "Expires");
- int expiry = atoi(expires);
- char *c, *n, *pt;
- int port;
- char *useragent;
- struct hostent *hp;
- struct ast_hostent ahp;
- struct sockaddr_in oldsin;
-
- if (ast_strlen_zero(expires)) { /* No expires header */
- expires = strcasestr(get_header(req, "Contact"), ";expires=");
- if (expires) {
- char *ptr;
- if ((ptr = strchr(expires, ';')))
- *ptr = '\0';
- if (sscanf(expires + 9, "%d", &expiry) != 1)
- expiry = default_expiry;
- } else {
- /* Nothing has been specified */
- expiry = default_expiry;
- }
- }
- /* Look for brackets */
- ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact));
- if (strchr(contact, '<') == NULL) { /* No <, check for ; and strip it */
- char *ptr = strchr(contact, ';'); /* This is Header options, not URI options */
- if (ptr)
- *ptr = '\0';
- }
- c = get_in_brackets(contact);
-
- /* if they did not specify Contact: or Expires:, they are querying
- what we currently have stored as their contact address, so return
- it
- */
- if (ast_strlen_zero(c) && ast_strlen_zero(expires)) {
- /* If we have an active registration, tell them when the registration is going to expire */
- if ((p->expire > -1) && !ast_strlen_zero(p->fullcontact)) {
- pvt->expiry = ast_sched_when(sched, p->expire);
- }
- return PARSE_REGISTER_QUERY;
- } else if (!strcasecmp(c, "*") || !expiry) { /* Unregister this peer */
- /* This means remove all registrations and return OK */
- memset(&p->addr, 0, sizeof(p->addr));
- if (p->expire > -1)
- ast_sched_del(sched, p->expire);
- p->expire = -1;
-
- destroy_association(p);
-
- register_peer_exten(p, 0);
- p->fullcontact[0] = '\0';
- p->useragent[0] = '\0';
- p->sipoptions = 0;
- p->lastms = 0;
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Unregistered SIP '%s'\n", p->name);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unregistered\r\n", p->name);
- return PARSE_REGISTER_UPDATE;
- }
- ast_copy_string(p->fullcontact, c, sizeof(p->fullcontact));
- /* For the 200 OK, we should use the received contact */
- snprintf(pvt->our_contact, sizeof(pvt->our_contact) - 1, "<%s>", c);
- /* Make sure it's a SIP URL */
- if (strncasecmp(c, "sip:", 4)) {
- ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", c);
- } else
- c += 4;
- /* Ditch q */
- n = strchr(c, ';');
- if (n) {
- *n = '\0';
- }
- /* Grab host */
- n = strchr(c, '@');
- if (!n) {
- n = c;
- c = NULL;
- } else {
- *n = '\0';
- n++;
- }
- pt = strchr(n, ':');
- if (pt) {
- *pt = '\0';
- pt++;
- port = atoi(pt);
- } else
- port = DEFAULT_SIP_PORT;
- memcpy(&oldsin, &p->addr, sizeof(oldsin));
- if (!(ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE)) {
- /* XXX This could block for a long time XXX */
- hp = ast_gethostbyname(n, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Invalid host '%s'\n", n);
- return PARSE_REGISTER_FAILED;
- }
- p->addr.sin_family = AF_INET;
- memcpy(&p->addr.sin_addr, hp->h_addr, sizeof(p->addr.sin_addr));
- p->addr.sin_port = htons(port);
- } else {
- /* Don't trust the contact field. Just use what they came to us
- with */
- memcpy(&p->addr, &pvt->recv, sizeof(p->addr));
- }
-
- if (c) /* Overwrite the default username from config at registration */
- ast_copy_string(p->username, c, sizeof(p->username));
- else
- p->username[0] = '\0';
-
- if (p->expire > -1)
- ast_sched_del(sched, p->expire);
- if ((expiry < 1) || (expiry > max_expiry))
- expiry = max_expiry;
- if (!ast_test_flag(p, SIP_REALTIME))
- p->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, p);
- else
- p->expire = -1;
- pvt->expiry = expiry;
- snprintf(data, sizeof(data), "%s:%d:%d:%s:%s", ast_inet_ntoa(iabuf, sizeof(iabuf), p->addr.sin_addr), ntohs(p->addr.sin_port), expiry, p->username, p->fullcontact);
- if (!ast_test_flag((&p->flags_page2), SIP_PAGE2_RT_FROMCONTACT))
- ast_db_put("SIP/Registry", p->name, data);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Registered\r\n", p->name);
- if (inaddrcmp(&p->addr, &oldsin)) {
- sip_poke_peer(p);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Registered SIP '%s' at %s port %d expires %d\n", p->name, ast_inet_ntoa(iabuf, sizeof(iabuf), p->addr.sin_addr), ntohs(p->addr.sin_port), expiry);
- register_peer_exten(p, 1);
- }
-
- /* Save SIP options profile */
- p->sipoptions = pvt->sipoptions;
-
- /* Save User agent */
- useragent = get_header(req, "User-Agent");
- if (useragent && strcasecmp(useragent, p->useragent)) {
- ast_copy_string(p->useragent, useragent, sizeof(p->useragent));
- if (option_verbose > 3) {
- ast_verbose(VERBOSE_PREFIX_3 "Saved useragent \"%s\" for peer %s\n",p->useragent,p->name);
- }
- }
- return PARSE_REGISTER_UPDATE;
-}
-
-/*! \brief free_old_route: Remove route from route list ---*/
-static void free_old_route(struct sip_route *route)
-{
- struct sip_route *next;
- while (route) {
- next = route->next;
- free(route);
- route = next;
- }
-}
-
-/*! \brief list_route: List all routes - mostly for debugging ---*/
-static void list_route(struct sip_route *route)
-{
- if (!route) {
- ast_verbose("list_route: no route\n");
- return;
- }
- while (route) {
- ast_verbose("list_route: hop: <%s>\n", route->hop);
- route = route->next;
- }
-}
-
-/*! \brief build_route: Build route list from Record-Route header ---*/
-static void build_route(struct sip_pvt *p, struct sip_request *req, int backwards)
-{
- struct sip_route *thishop, *head, *tail;
- int start = 0;
- int len;
- char *rr, *contact, *c;
-
- /* Once a persistant route is set, don't fool with it */
- if (p->route && p->route_persistant) {
- ast_log(LOG_DEBUG, "build_route: Retaining previous route: <%s>\n", p->route->hop);
- return;
- }
-
- if (p->route) {
- free_old_route(p->route);
- p->route = NULL;
- }
-
- p->route_persistant = backwards;
-
- /* We build up head, then assign it to p->route when we're done */
- head = NULL; tail = head;
- /* 1st we pass through all the hops in any Record-Route headers */
- for (;;) {
- /* Each Record-Route header */
- rr = __get_header(req, "Record-Route", &start);
- if (*rr == '\0') break;
- for (;;) {
- /* Each route entry */
- /* Find < */
- rr = strchr(rr, '<');
- if (!rr) break; /* No more hops */
- ++rr;
- len = strcspn(rr, ">") + 1;
- /* Make a struct route */
- thishop = malloc(sizeof(*thishop) + len);
- if (thishop) {
- ast_copy_string(thishop->hop, rr, len);
- ast_log(LOG_DEBUG, "build_route: Record-Route hop: <%s>\n", thishop->hop);
- /* Link in */
- if (backwards) {
- /* Link in at head so they end up in reverse order */
- thishop->next = head;
- head = thishop;
- /* If this was the first then it'll be the tail */
- if (!tail) tail = thishop;
- } else {
- thishop->next = NULL;
- /* Link in at the end */
- if (tail)
- tail->next = thishop;
- else
- head = thishop;
- tail = thishop;
- }
- }
- rr += len;
- }
- }
-
- /* Only append the contact if we are dealing with a strict router */
- if (!head || (!ast_strlen_zero(head->hop) && strstr(head->hop,";lr") == NULL) ) {
- /* 2nd append the Contact: if there is one */
- /* Can be multiple Contact headers, comma separated values - we just take the first */
- contact = get_header(req, "Contact");
- if (!ast_strlen_zero(contact)) {
- ast_log(LOG_DEBUG, "build_route: Contact hop: %s\n", contact);
- /* Look for <: delimited address */
- c = strchr(contact, '<');
- if (c) {
- /* Take to > */
- ++c;
- len = strcspn(c, ">") + 1;
- } else {
- /* No <> - just take the lot */
- c = contact;
- len = strlen(contact) + 1;
- }
- thishop = malloc(sizeof(*thishop) + len);
- if (thishop) {
- ast_copy_string(thishop->hop, c, len);
- thishop->next = NULL;
- /* Goes at the end */
- if (tail)
- tail->next = thishop;
- else
- head = thishop;
- }
- }
- }
-
- /* Store as new route */
- p->route = head;
-
- /* For debugging dump what we ended up with */
- if (sip_debug_test_pvt(p))
- list_route(p->route);
-}
-
-#ifdef OSP_SUPPORT
-/*! \brief check_osptoken: Validate OSP token for user authrroization ---*/
-static int check_osptoken (struct sip_pvt *p, char *token)
-{
- char tmp[80];
-
- if (ast_osp_validate (NULL, token, &p->osphandle, &p->osptimelimit, p->cid_num, p->sa.sin_addr, p->exten) < 1) {
- return (-1);
- } else {
- snprintf (tmp, sizeof (tmp), "%d", p->osphandle);
- pbx_builtin_setvar_helper (p->owner, "_OSPHANDLE", tmp);
- return (0);
- }
-}
-#endif
-
-/*! \brief check_auth: Check user authorization from peer definition ---*/
-/* Some actions, like REGISTER and INVITEs from peers require
- authentication (if peer have secret set) */
-static int check_auth(struct sip_pvt *p, struct sip_request *req, char *randdata, int randlen, char *username, char *secret, char *md5secret, int sipmethod, char *uri, int reliable, int ignore)
-{
- int res = -1;
- char *response = "407 Proxy Authentication Required";
- char *reqheader = "Proxy-Authorization";
- char *respheader = "Proxy-Authenticate";
- char *authtoken;
-#ifdef OSP_SUPPORT
- char *osptoken;
-#endif
- /* Always OK if no secret */
- if (ast_strlen_zero(secret) && ast_strlen_zero(md5secret)
-#ifdef OSP_SUPPORT
- && !ast_test_flag(p, SIP_OSPAUTH)
- && global_allowguest != 2
-#endif
- )
- return 0;
- if (sipmethod == SIP_REGISTER || sipmethod == SIP_SUBSCRIBE) {
- /* On a REGISTER, we have to use 401 and its family of headers instead of 407 and its family
- of headers -- GO SIP! Whoo hoo! Two things that do the same thing but are used in
- different circumstances! What a surprise. */
- response = "401 Unauthorized";
- reqheader = "Authorization";
- respheader = "WWW-Authenticate";
- }
-#ifdef OSP_SUPPORT
- else {
- ast_log (LOG_DEBUG, "Checking OSP Authentication!\n");
- osptoken = get_header (req, "P-OSP-Auth-Token");
- switch (ast_test_flag (p, SIP_OSPAUTH)) {
- case SIP_OSPAUTH_NO:
- break;
- case SIP_OSPAUTH_GATEWAY:
- if (ast_strlen_zero (osptoken)) {
- if (ast_strlen_zero (secret) && ast_strlen_zero (md5secret)) {
- return (0);
- }
- }
- else {
- return (check_osptoken (p, osptoken));
- }
- break;
- case SIP_OSPAUTH_PROXY:
- if (ast_strlen_zero (osptoken)) {
- return (0);
- }
- else {
- return (check_osptoken (p, osptoken));
- }
- break;
- case SIP_OSPAUTH_EXCLUSIVE:
- if (ast_strlen_zero (osptoken)) {
- return (-1);
- }
- else {
- return (check_osptoken (p, osptoken));
- }
- break;
- default:
- return (-1);
- }
- }
-#endif
- authtoken = get_header(req, reqheader);
- if (ignore && !ast_strlen_zero(randdata) && ast_strlen_zero(authtoken)) {
- /* This is a retransmitted invite/register/etc, don't reconstruct authentication
- information */
- if (!ast_strlen_zero(randdata)) {
- if (!reliable) {
- /* Resend message if this was NOT a reliable delivery. Otherwise the
- retransmission should get it */
- transmit_response_with_auth(p, response, req, randdata, reliable, respheader, 0);
- /* Schedule auto destroy in 15 seconds */
- sip_scheddestroy(p, 15000);
- }
- res = 1;
- }
- } else if (ast_strlen_zero(randdata) || ast_strlen_zero(authtoken)) {
- snprintf(randdata, randlen, "%08x", thread_safe_rand());
- transmit_response_with_auth(p, response, req, randdata, reliable, respheader, 0);
- /* Schedule auto destroy in 15 seconds */
- sip_scheddestroy(p, 15000);
- res = 1;
- } else {
- /* Whoever came up with the authentication section of SIP can suck my %&#$&* for not putting
- an example in the spec of just what it is you're doing a hash on. */
- char a1[256];
- char a2[256];
- char a1_hash[256];
- char a2_hash[256];
- char resp[256];
- char resp_hash[256]="";
- char tmp[256];
- char *c;
- char *z;
- char *ua_hash ="";
- char *resp_uri ="";
- char *nonce = "";
- char *digestusername = "";
- int wrongnonce = 0;
- char *usednonce = randdata;
-
- /* Find their response among the mess that we'r sent for comparison */
- ast_copy_string(tmp, authtoken, sizeof(tmp));
- c = tmp;
-
- while(c) {
- c = ast_skip_blanks(c);
- if (!*c)
- break;
- if (!strncasecmp(c, "response=", strlen("response="))) {
- c+= strlen("response=");
- if ((*c == '\"')) {
- ua_hash=++c;
- if ((c = strchr(c,'\"')))
- *c = '\0';
-
- } else {
- ua_hash=c;
- if ((c = strchr(c,',')))
- *c = '\0';
- }
-
- } else if (!strncasecmp(c, "uri=", strlen("uri="))) {
- c+= strlen("uri=");
- if ((*c == '\"')) {
- resp_uri=++c;
- if ((c = strchr(c,'\"')))
- *c = '\0';
- } else {
- resp_uri=c;
- if ((c = strchr(c,',')))
- *c = '\0';
- }
-
- } else if (!strncasecmp(c, "username=", strlen("username="))) {
- c+= strlen("username=");
- if ((*c == '\"')) {
- digestusername=++c;
- if((c = strchr(c,'\"')))
- *c = '\0';
- } else {
- digestusername=c;
- if((c = strchr(c,',')))
- *c = '\0';
- }
- } else if (!strncasecmp(c, "nonce=", strlen("nonce="))) {
- c+= strlen("nonce=");
- if ((*c == '\"')) {
- nonce=++c;
- if ((c = strchr(c,'\"')))
- *c = '\0';
- } else {
- nonce=c;
- if ((c = strchr(c,',')))
- *c = '\0';
- }
-
- } else
- if ((z = strchr(c,' ')) || (z = strchr(c,','))) c=z;
- if (c)
- c++;
- }
- /* Verify that digest username matches the username we auth as */
- if (strcmp(username, digestusername)) {
- /* Oops, we're trying something here */
- return -2;
- }
-
- /* Verify nonce from request matches our nonce. If not, send 401 with new nonce */
- if (strncasecmp(randdata, nonce, randlen)) {
- wrongnonce = 1;
- usednonce = nonce;
- }
-
- snprintf(a1, sizeof(a1), "%s:%s:%s", username, global_realm, secret);
-
- if (!ast_strlen_zero(resp_uri))
- snprintf(a2, sizeof(a2), "%s:%s", sip_methods[sipmethod].text, resp_uri);
- else
- snprintf(a2, sizeof(a2), "%s:%s", sip_methods[sipmethod].text, uri);
-
- if (!ast_strlen_zero(md5secret))
- snprintf(a1_hash, sizeof(a1_hash), "%s", md5secret);
- else
- ast_md5_hash(a1_hash, a1);
-
- ast_md5_hash(a2_hash, a2);
-
- snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, usednonce, a2_hash);
- ast_md5_hash(resp_hash, resp);
-
- if (wrongnonce) {
-
- snprintf(randdata, randlen, "%08x", thread_safe_rand());
- if (ua_hash && !strncasecmp(ua_hash, resp_hash, strlen(resp_hash))) {
- if (sipdebug)
- ast_log(LOG_NOTICE, "stale nonce received from '%s'\n", get_header(req, "To"));
- /* We got working auth token, based on stale nonce . */
- transmit_response_with_auth(p, response, req, randdata, reliable, respheader, 1);
- } else {
- /* Everything was wrong, so give the device one more try with a new challenge */
- if (sipdebug)
- ast_log(LOG_NOTICE, "Bad authentication received from '%s'\n", get_header(req, "To"));
- transmit_response_with_auth(p, response, req, randdata, reliable, respheader, 0);
- }
-
- /* Schedule auto destroy in 15 seconds */
- sip_scheddestroy(p, 15000);
- return 1;
- }
- /* resp_hash now has the expected response, compare the two */
- if (ua_hash && !strncasecmp(ua_hash, resp_hash, strlen(resp_hash))) {
- /* Auth is OK */
- res = 0;
- }
- }
- /* Failure */
- return res;
-}
-
-/*! \brief cb_extensionstate: Callback for the devicestate notification (SUBSCRIBE) support subsystem ---*/
-/* If you add an "hint" priority to the extension in the dial plan,
- you will get notifications on device state changes */
-static int cb_extensionstate(char *context, char* exten, int state, void *data)
-{
- struct sip_pvt *p = data;
-
- switch(state) {
- case AST_EXTENSION_DEACTIVATED: /* Retry after a while */
- case AST_EXTENSION_REMOVED: /* Extension is gone */
- if (p->autokillid > -1)
- sip_cancel_destroy(p); /* Remove subscription expiry for renewals */
- sip_scheddestroy(p, 15000); /* Delete subscription in 15 secs */
- ast_verbose(VERBOSE_PREFIX_2 "Extension state: Watcher for hint %s %s. Notify User %s\n", exten, state == AST_EXTENSION_DEACTIVATED ? "deactivated" : "removed", p->username);
- p->stateid = -1;
- p->subscribed = NONE;
- append_history(p, "Subscribestatus", state == AST_EXTENSION_REMOVED ? "HintRemoved" : "Deactivated");
- break;
- default: /* Tell user */
- p->laststate = state;
- break;
- }
- transmit_state_notify(p, state, 1, 1);
-
- if (option_debug > 1)
- ast_verbose(VERBOSE_PREFIX_1 "Extension Changed %s new state %s for Notify User %s\n", exten, ast_extension_state2str(state), p->username);
- return 0;
-}
-
-/*! \brief register_verify: Verify registration of user */
-static int register_verify(struct sip_pvt *p, struct sockaddr_in *sin, struct sip_request *req, char *uri, int ignore)
-{
- int res = -3;
- struct sip_peer *peer;
- char tmp[256];
- char iabuf[INET_ADDRSTRLEN];
- char *name, *c;
- char *t;
- char *domain;
-
- /* Terminate URI */
- t = uri;
- while(*t && (*t > 32) && (*t != ';'))
- t++;
- *t = '\0';
-
- ast_copy_string(tmp, get_header(req, "To"), sizeof(tmp));
- if (pedanticsipchecking)
- ast_uri_decode(tmp);
-
- c = get_in_brackets(tmp);
- /* Ditch ;user=phone */
- name = strchr(c, ';');
- if (name)
- *name = '\0';
-
- if (!strncmp(c, "sip:", 4)) {
- name = c + 4;
- } else {
- name = c;
- ast_log(LOG_NOTICE, "Invalid to address: '%s' from %s (missing sip:) trying to use anyway...\n", c, ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
- }
-
- /* Strip off the domain name */
- if ((c = strchr(name, '@'))) {
- *c++ = '\0';
- domain = c;
- if ((c = strchr(domain, ':'))) /* Remove :port */
- *c = '\0';
- if (!AST_LIST_EMPTY(&domain_list)) {
- if (!check_sip_domain(domain, NULL, 0)) {
- transmit_response(p, "404 Not found (unknown domain)", &p->initreq);
- return -3;
- }
- }
- }
-
- ast_copy_string(p->exten, name, sizeof(p->exten));
- build_contact(p);
- peer = find_peer(name, NULL, 1);
- if (!(peer && ast_apply_ha(peer->ha, sin))) {
- if (peer)
- ASTOBJ_UNREF(peer,sip_destroy_peer);
- }
- if (peer) {
- if (!ast_test_flag(peer, SIP_DYNAMIC)) {
- ast_log(LOG_ERROR, "Peer '%s' is trying to register, but not configured as host=dynamic\n", peer->name);
- } else {
- ast_copy_flags(p, peer, SIP_NAT);
- transmit_response(p, "100 Trying", req);
- if (!(res = check_auth(p, req, p->randdata, sizeof(p->randdata), peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri, 0, ignore))) {
- sip_cancel_destroy(p);
- switch (parse_register_contact(p, peer, req)) {
- case PARSE_REGISTER_FAILED:
- ast_log(LOG_WARNING, "Failed to parse contact info\n");
- break;
- case PARSE_REGISTER_QUERY:
- transmit_response_with_date(p, "200 OK", req);
- peer->lastmsgssent = -1;
- res = 0;
- break;
- case PARSE_REGISTER_UPDATE:
- update_peer(peer, p->expiry);
- /* Say OK and ask subsystem to retransmit msg counter */
- transmit_response_with_date(p, "200 OK", req);
- peer->lastmsgssent = -1;
- res = 0;
- break;
- }
- }
- }
- }
- if (!peer && autocreatepeer) {
- /* Create peer if we have autocreate mode enabled */
- peer = temp_peer(name);
- if (peer) {
- ASTOBJ_CONTAINER_LINK(&peerl, peer);
- peer->lastmsgssent = -1;
- sip_cancel_destroy(p);
- switch (parse_register_contact(p, peer, req)) {
- case PARSE_REGISTER_FAILED:
- ast_log(LOG_WARNING, "Failed to parse contact info\n");
- break;
- case PARSE_REGISTER_QUERY:
- transmit_response_with_date(p, "200 OK", req);
- peer->lastmsgssent = -1;
- res = 0;
- break;
- case PARSE_REGISTER_UPDATE:
- /* Say OK and ask subsystem to retransmit msg counter */
- transmit_response_with_date(p, "200 OK", req);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Registered\r\n", peer->name);
- peer->lastmsgssent = -1;
- res = 0;
- break;
- }
- }
- }
- if (!res) {
- ast_device_state_changed("SIP/%s", peer->name);
- }
- if (res < 0) {
- switch (res) {
- case -1:
- /* Wrong password in authentication. Go away, don't try again until you fixed it */
- transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq);
- break;
- case -2:
- /* Username and digest username does not match.
- Asterisk uses the From: username for authentication. We need the
- users to use the same authentication user name until we support
- proper authentication by digest auth name */
- transmit_response(p, "403 Authentication user name does not match account name", &p->initreq);
- break;
- case -3:
- /* URI not found */
- transmit_response(p, "404 Not found", &p->initreq);
- /* Set res back to -2 because we don't want to return an invalid domain message. That check already happened up above. */
- res = -2;
- break;
- }
- if (option_debug > 1) {
- ast_log(LOG_DEBUG, "SIP REGISTER attempt failed for %s : %s\n",
- peer->name,
- (res == -1) ? "Bad password" : ((res == -2 ) ? "Bad digest user" : "Peer not found"));
- }
- }
- if (peer)
- ASTOBJ_UNREF(peer,sip_destroy_peer);
-
- return res;
-}
-
-/*! \brief get_rdnis: get referring dnis ---*/
-static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq)
-{
- char tmp[256], *c, *a;
- struct sip_request *req;
-
- req = oreq;
- if (!req)
- req = &p->initreq;
- ast_copy_string(tmp, get_header(req, "Diversion"), sizeof(tmp));
- if (ast_strlen_zero(tmp))
- return 0;
- c = get_in_brackets(tmp);
- if (strncmp(c, "sip:", 4)) {
- ast_log(LOG_WARNING, "Huh? Not an RDNIS SIP header (%s)?\n", c);
- return -1;
- }
- c += 4;
- if ((a = strchr(c, '@')) || (a = strchr(c, ';'))) {
- *a = '\0';
- }
- if (sip_debug_test_pvt(p))
- ast_verbose("RDNIS is %s\n", c);
- ast_copy_string(p->rdnis, c, sizeof(p->rdnis));
-
- return 0;
-}
-
-/*! \brief get_destination: Find out who the call is for --*/
-static int get_destination(struct sip_pvt *p, struct sip_request *oreq)
-{
- char tmp[256] = "", *uri, *a;
- char tmpf[256], *from;
- struct sip_request *req;
-
- req = oreq;
- if (!req)
- req = &p->initreq;
- if (req->rlPart2)
- ast_copy_string(tmp, req->rlPart2, sizeof(tmp));
- uri = get_in_brackets(tmp);
-
- ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf));
-
- from = get_in_brackets(tmpf);
-
- if (strncmp(uri, "sip:", 4)) {
- ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", uri);
- return -1;
- }
- uri += 4;
- if (!ast_strlen_zero(from)) {
- if (strncmp(from, "sip:", 4)) {
- ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", from);
- return -1;
- }
- from += 4;
- } else
- from = NULL;
-
- if (pedanticsipchecking) {
- ast_uri_decode(uri);
- ast_uri_decode(from);
- }
-
- /* Get the target domain */
- if ((a = strchr(uri, '@'))) {
- char *colon;
- *a = '\0';
- a++;
- colon = strchr(a, ':'); /* Remove :port */
- if (colon)
- *colon = '\0';
- ast_copy_string(p->domain, a, sizeof(p->domain));
- }
- /* Skip any options */
- if ((a = strchr(uri, ';'))) {
- *a = '\0';
- }
-
- if (!AST_LIST_EMPTY(&domain_list)) {
- char domain_context[AST_MAX_EXTENSION];
-
- domain_context[0] = '\0';
- if (!check_sip_domain(p->domain, domain_context, sizeof(domain_context))) {
- if (!allow_external_domains && (req->method == SIP_INVITE || req->method == SIP_REFER)) {
- ast_log(LOG_DEBUG, "Got SIP %s to non-local domain '%s'; refusing request.\n", sip_methods[req->method].text, p->domain);
- return -2;
- }
- }
- /* If we have a context defined, overwrite the original context */
- if (!ast_strlen_zero(domain_context))
- ast_copy_string(p->context, domain_context, sizeof(p->context));
- }
-
- if (from) {
- if ((a = strchr(from, ';')))
- *a = '\0';
- if ((a = strchr(from, '@'))) {
- *a = '\0';
- ast_copy_string(p->fromdomain, a + 1, sizeof(p->fromdomain));
- } else
- ast_copy_string(p->fromdomain, from, sizeof(p->fromdomain));
- }
- if (sip_debug_test_pvt(p))
- ast_verbose("Looking for %s in %s (domain %s)\n", uri, p->context, p->domain);
-
- /* Return 0 if we have a matching extension */
- if (ast_exists_extension(NULL, p->context, uri, 1, from) ||
- !strcmp(uri, ast_pickup_ext())) {
- if (!oreq)
- ast_copy_string(p->exten, uri, sizeof(p->exten));
- return 0;
- }
-
- /* Return 1 for overlap dialling support */
- if (ast_canmatch_extension(NULL, p->context, uri, 1, from) ||
- !strncmp(uri, ast_pickup_ext(),strlen(uri))) {
- return 1;
- }
-
- return -1;
-}
-
-/*! \brief get_sip_pvt_byid_locked: Lock interface lock and find matching pvt lock ---*/
-static struct sip_pvt *get_sip_pvt_byid_locked(char *callid)
-{
- struct sip_pvt *sip_pvt_ptr = NULL;
-
- /* Search interfaces and find the match */
- ast_mutex_lock(&iflock);
- sip_pvt_ptr = iflist;
- while(sip_pvt_ptr) {
- if (!strcmp(sip_pvt_ptr->callid, callid)) {
- /* Go ahead and lock it (and its owner) before returning */
- ast_mutex_lock(&sip_pvt_ptr->lock);
- if (sip_pvt_ptr->owner) {
- while(ast_mutex_trylock(&sip_pvt_ptr->owner->lock)) {
- ast_mutex_unlock(&sip_pvt_ptr->lock);
- usleep(1);
- ast_mutex_lock(&sip_pvt_ptr->lock);
- if (!sip_pvt_ptr->owner)
- break;
- }
- }
- break;
- }
- sip_pvt_ptr = sip_pvt_ptr->next;
- }
- ast_mutex_unlock(&iflock);
- return sip_pvt_ptr;
-}
-
-/*! \brief get_refer_info: Call transfer support (the REFER method) ---*/
-static int get_refer_info(struct sip_pvt *sip_pvt, struct sip_request *outgoing_req)
-{
-
- char *p_refer_to = NULL, *p_referred_by = NULL, *h_refer_to = NULL, *h_referred_by = NULL, *h_contact = NULL;
- char *replace_callid = "", *refer_to = NULL, *referred_by = NULL, *ptr = NULL;
- struct sip_request *req = NULL;
- struct sip_pvt *sip_pvt_ptr = NULL;
- struct ast_channel *chan = NULL, *peer = NULL;
-
- req = outgoing_req;
-
- if (!req) {
- req = &sip_pvt->initreq;
- }
-
- if (!( (p_refer_to = get_header(req, "Refer-To")) && (h_refer_to = ast_strdupa(p_refer_to)) )) {
- ast_log(LOG_WARNING, "No Refer-To Header That's illegal\n");
- return -1;
- }
-
- refer_to = get_in_brackets(h_refer_to);
-
- if (!( (p_referred_by = get_header(req, "Referred-By")) && (h_referred_by = ast_strdupa(p_referred_by)) )) {
- ast_log(LOG_WARNING, "No Referrred-By Header That's not illegal\n");
- return -1;
- } else {
- if (pedanticsipchecking) {
- ast_uri_decode(h_referred_by);
- }
- referred_by = get_in_brackets(h_referred_by);
- }
- h_contact = get_header(req, "Contact");
-
- if (strncmp(refer_to, "sip:", 4)) {
- ast_log(LOG_WARNING, "Refer-to: Huh? Not a SIP header (%s)?\n", refer_to);
- return -1;
- }
-
- if (strncmp(referred_by, "sip:", 4)) {
- ast_log(LOG_WARNING, "Referred-by: Huh? Not a SIP header (%s) Ignoring?\n", referred_by);
- referred_by = NULL;
- }
-
- if (refer_to)
- refer_to += 4;
-
- if (referred_by)
- referred_by += 4;
-
- if ((ptr = strchr(refer_to, '?'))) {
- /* Search for arguments */
- *ptr = '\0';
- ptr++;
- if (!strncasecmp(ptr, "REPLACES=", 9)) {
- char *p;
- replace_callid = ast_strdupa(ptr + 9);
- /* someday soon to support invite/replaces properly!
- replaces_header = ast_strdupa(replace_callid);
- -anthm
- */
- ast_uri_decode(replace_callid);
- if ((ptr = strchr(replace_callid, '%')))
- *ptr = '\0';
- if ((ptr = strchr(replace_callid, ';')))
- *ptr = '\0';
- /* Skip leading whitespace XXX memmove behaviour with overlaps ? */
- p = ast_skip_blanks(replace_callid);
- if (p != replace_callid)
- memmove(replace_callid, p, strlen(p));
- }
- }
-
- if ((ptr = strchr(refer_to, '@'))) /* Skip domain (should be saved in SIPDOMAIN) */
- *ptr = '\0';
- if ((ptr = strchr(refer_to, ';')))
- *ptr = '\0';
-
- if (referred_by) {
- if ((ptr = strchr(referred_by, '@')))
- *ptr = '\0';
- if ((ptr = strchr(referred_by, ';')))
- *ptr = '\0';
- }
-
- if (sip_debug_test_pvt(sip_pvt)) {
- ast_verbose("Transfer to %s in %s\n", refer_to, sip_pvt->context);
- if (referred_by)
- ast_verbose("Transfer from %s in %s\n", referred_by, sip_pvt->context);
- }
- if (!ast_strlen_zero(replace_callid)) {
- /* This is a supervised transfer */
- ast_log(LOG_DEBUG,"Assigning Replace-Call-ID Info %s to REPLACE_CALL_ID\n",replace_callid);
-
- ast_copy_string(sip_pvt->refer_to, "", sizeof(sip_pvt->refer_to));
- ast_copy_string(sip_pvt->referred_by, "", sizeof(sip_pvt->referred_by));
- ast_copy_string(sip_pvt->refer_contact, "", sizeof(sip_pvt->refer_contact));
- sip_pvt->refer_call = NULL;
- if ((sip_pvt_ptr = get_sip_pvt_byid_locked(replace_callid))) {
- sip_pvt->refer_call = sip_pvt_ptr;
- if (sip_pvt->refer_call == sip_pvt) {
- ast_log(LOG_NOTICE, "Supervised transfer attempted to transfer into same call id (%s == %s)!\n", replace_callid, sip_pvt->callid);
- sip_pvt->refer_call = NULL;
- } else
- return 0;
- } else {
- ast_log(LOG_NOTICE, "Supervised transfer requested, but unable to find callid '%s'. Both legs must reside on Asterisk box to transfer at this time.\n", replace_callid);
- /* XXX The refer_to could contain a call on an entirely different machine, requiring an
- INVITE with a replaces header -anthm XXX */
- /* The only way to find out is to use the dialplan - oej */
- }
- } else if (ast_exists_extension(NULL, sip_pvt->context, refer_to, 1, NULL) || !strcmp(refer_to, ast_parking_ext())) {
- /* This is an unsupervised transfer (blind transfer) */
-
- ast_log(LOG_DEBUG,"Unsupervised transfer to (Refer-To): %s\n", refer_to);
- if (referred_by)
- ast_log(LOG_DEBUG,"Transferred by (Referred-by: ) %s \n", referred_by);
- ast_log(LOG_DEBUG,"Transfer Contact Info %s (REFER_CONTACT)\n", h_contact);
- ast_copy_string(sip_pvt->refer_to, refer_to, sizeof(sip_pvt->refer_to));
- if (referred_by)
- ast_copy_string(sip_pvt->referred_by, referred_by, sizeof(sip_pvt->referred_by));
- if (h_contact) {
- ast_copy_string(sip_pvt->refer_contact, h_contact, sizeof(sip_pvt->refer_contact));
- }
- sip_pvt->refer_call = NULL;
- if ((chan = sip_pvt->owner) && (peer = ast_bridged_channel(sip_pvt->owner))) {
- pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", peer->name);
- pbx_builtin_setvar_helper(peer, "BLINDTRANSFER", chan->name);
- }
- return 0;
- } else if (ast_canmatch_extension(NULL, sip_pvt->context, refer_to, 1, NULL)) {
- return 1;
- }
-
- return -1;
-}
-
-/*! \brief get_also_info: Call transfer support (old way, depreciated)--*/
-static int get_also_info(struct sip_pvt *p, struct sip_request *oreq)
-{
- char tmp[256], *c, *a;
- struct sip_request *req;
-
- req = oreq;
- if (!req)
- req = &p->initreq;
- ast_copy_string(tmp, get_header(req, "Also"), sizeof(tmp));
-
- c = get_in_brackets(tmp);
-
-
- if (strncmp(c, "sip:", 4)) {
- ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c);
- return -1;
- }
- c += 4;
- if ((a = strchr(c, '@')))
- *a = '\0';
- if ((a = strchr(c, ';')))
- *a = '\0';
-
- if (sip_debug_test_pvt(p)) {
- ast_verbose("Looking for %s in %s\n", c, p->context);
- }
- if (ast_exists_extension(NULL, p->context, c, 1, NULL)) {
- /* This is an unsupervised transfer */
- ast_log(LOG_DEBUG,"Assigning Extension %s to REFER-TO\n", c);
- ast_copy_string(p->refer_to, c, sizeof(p->refer_to));
- ast_copy_string(p->referred_by, "", sizeof(p->referred_by));
- ast_copy_string(p->refer_contact, "", sizeof(p->refer_contact));
- p->refer_call = NULL;
- return 0;
- } else if (ast_canmatch_extension(NULL, p->context, c, 1, NULL)) {
- return 1;
- }
-
- return -1;
-}
-
-/*! \brief check Via: header for hostname, port and rport request/answer */
-static int check_via(struct sip_pvt *p, struct sip_request *req)
-{
- char via[256];
- char iabuf[INET_ADDRSTRLEN];
- char *c, *pt;
- struct hostent *hp;
- struct ast_hostent ahp;
-
- ast_copy_string(via, get_header(req, "Via"), sizeof(via));
-
- /* Check for rport */
- c = strstr(via, ";rport");
- if (c && (c[6] != '=')) /* rport query, not answer */
- ast_set_flag(p, SIP_NAT_ROUTE);
-
- c = strchr(via, ';');
- if (c)
- *c = '\0';
-
- c = strchr(via, ' ');
- if (c) {
- *c = '\0';
- c = ast_skip_blanks(c+1);
- if (strcasecmp(via, "SIP/2.0/UDP")) {
- ast_log(LOG_WARNING, "Don't know how to respond via '%s'\n", via);
- return -1;
- }
- pt = strchr(c, ':');
- if (pt)
- *pt++ = '\0'; /* remember port pointer */
- hp = ast_gethostbyname(c, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "'%s' is not a valid host\n", c);
- return -1;
- }
- memset(&p->sa, 0, sizeof(p->sa));
- p->sa.sin_family = AF_INET;
- memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr));
- p->sa.sin_port = htons(pt ? atoi(pt) : DEFAULT_SIP_PORT);
-
- if (sip_debug_test_pvt(p)) {
- c = (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) ? "NAT" : "non-NAT";
- ast_verbose("Sending to %s : %d (%s)\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), ntohs(p->sa.sin_port), c);
- }
- }
- return 0;
-}
-
-/*! \brief get_calleridname: Get caller id name from SIP headers ---*/
-static char *get_calleridname(char *input, char *output, size_t outputsize)
-{
- char *end = strchr(input,'<');
- char *tmp = strchr(input,'\"');
- int bytes = 0;
- int maxbytes = outputsize - 1;
-
- if (!end || (end == input)) return NULL;
- /* move away from "<" */
- end--;
- /* we found "name" */
- if (tmp && tmp < end) {
- end = strchr(tmp+1, '\"');
- if (!end) return NULL;
- bytes = (int) (end - tmp);
- /* protect the output buffer */
- if (bytes > maxbytes)
- bytes = maxbytes;
- ast_copy_string(output, tmp + 1, bytes);
- } else {
- /* we didn't find "name" */
- /* clear the empty characters in the begining*/
- input = ast_skip_blanks(input);
- /* clear the empty characters in the end */
- while(*end && (*end < 33) && end > input)
- end--;
- if (end >= input) {
- bytes = (int) (end - input) + 2;
- /* protect the output buffer */
- if (bytes > maxbytes) {
- bytes = maxbytes;
- }
- ast_copy_string(output, input, bytes);
- }
- else
- return NULL;
- }
- return output;
-}
-
-/*! \brief get_rpid_num: Get caller id number from Remote-Party-ID header field
- * Returns true if number should be restricted (privacy setting found)
- * output is set to NULL if no number found
- */
-static int get_rpid_num(char *input,char *output, int maxlen)
-{
- char *start;
- char *end;
-
- start = strchr(input,':');
- if (!start) {
- output[0] = '\0';
- return 0;
- }
- start++;
-
- /* we found "number" */
- ast_copy_string(output,start,maxlen);
- output[maxlen-1] = '\0';
-
- end = strchr(output,'@');
- if (end)
- *end = '\0';
- else
- output[0] = '\0';
- if (strstr(input,"privacy=full") || strstr(input,"privacy=uri"))
- return AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
-
- return 0;
-}
-
-
-/*! \brief check_user_full: Check if matching user or peer is defined ---*/
-/* Match user on From: user name and peer on IP/port */
-/* This is used on first invite (not re-invites) and subscribe requests */
-static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipmethod, char *uri, int reliable, struct sockaddr_in *sin, int ignore, char *mailbox, int mailboxlen)
-{
- struct sip_user *user = NULL;
- struct sip_peer *peer;
- char *of, from[256], *c;
- char *rpid,rpid_num[50];
- char iabuf[INET_ADDRSTRLEN];
- int res = 0;
- char *t;
- char calleridname[50];
- int debug=sip_debug_test_addr(sin);
- struct ast_variable *tmpvar = NULL, *v = NULL;
-
- /* Terminate URI */
- t = uri;
- while(*t && (*t > 32) && (*t != ';'))
- t++;
- *t = '\0';
- of = get_header(req, "From");
- if (pedanticsipchecking)
- ast_uri_decode(of);
-
- ast_copy_string(from, of, sizeof(from));
-
- memset(calleridname,0,sizeof(calleridname));
- get_calleridname(from, calleridname, sizeof(calleridname));
- if (calleridname[0])
- ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
-
- rpid = get_header(req, "Remote-Party-ID");
- memset(rpid_num,0,sizeof(rpid_num));
- if (!ast_strlen_zero(rpid))
- p->callingpres = get_rpid_num(rpid,rpid_num, sizeof(rpid_num));
-
- of = get_in_brackets(from);
- if (ast_strlen_zero(p->exten)) {
- t = uri;
- if (!strncmp(t, "sip:", 4))
- t+= 4;
- ast_copy_string(p->exten, t, sizeof(p->exten));
- t = strchr(p->exten, '@');
- if (t)
- *t = '\0';
- if (ast_strlen_zero(p->our_contact))
- build_contact(p);
- }
- /* save the URI part of the From header */
- ast_copy_string(p->from, of, sizeof(p->from));
- if (strncmp(of, "sip:", 4)) {
- ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
- } else
- of += 4;
- /* Get just the username part */
- if ((c = strchr(of, '@'))) {
- *c = '\0';
- if ((c = strchr(of, ':')))
- *c = '\0';
- ast_copy_string(p->cid_num, of, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
- }
- if (ast_strlen_zero(of))
- return 0;
-
- if (!mailbox) /* If it's a mailbox SUBSCRIBE, don't check users */
- user = find_user(of, 1);
-
- /* Find user based on user name in the from header */
- if (user && ast_apply_ha(user->ha, sin)) {
- ast_copy_flags(p, user, SIP_FLAGS_TO_COPY);
- /* copy channel vars */
- for (v = user->chanvars ; v ; v = v->next) {
- if ((tmpvar = ast_variable_new(v->name, v->value))) {
- tmpvar->next = p->chanvars;
- p->chanvars = tmpvar;
- }
- }
- p->prefs = user->prefs;
- /* replace callerid if rpid found, and not restricted */
- if (!ast_strlen_zero(rpid_num) && ast_test_flag(p, SIP_TRUSTRPID)) {
- if (*calleridname)
- ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
- ast_copy_string(p->cid_num, rpid_num, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
- }
-
- if (p->rtp) {
- ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- ast_rtp_setnat(p->rtp, (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- }
- if (p->vrtp) {
- ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- ast_rtp_setnat(p->vrtp, (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- }
- if (!(res = check_auth(p, req, p->randdata, sizeof(p->randdata), user->name, user->secret, user->md5secret, sipmethod, uri, reliable, ignore))) {
- sip_cancel_destroy(p);
- ast_copy_flags(p, user, SIP_FLAGS_TO_COPY);
- /* Copy SIP extensions profile from INVITE */
- if (p->sipoptions)
- user->sipoptions = p->sipoptions;
-
- /* If we have a call limit, set flag */
- if (user->call_limit)
- ast_set_flag(p, SIP_CALL_LIMIT);
- if (!ast_strlen_zero(user->context))
- ast_copy_string(p->context, user->context, sizeof(p->context));
- if (!ast_strlen_zero(user->cid_num) && !ast_strlen_zero(p->cid_num)) {
- ast_copy_string(p->cid_num, user->cid_num, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
- }
- if (!ast_strlen_zero(user->cid_name) && !ast_strlen_zero(p->cid_num))
- ast_copy_string(p->cid_name, user->cid_name, sizeof(p->cid_name));
- ast_copy_string(p->username, user->name, sizeof(p->username));
- ast_copy_string(p->peersecret, user->secret, sizeof(p->peersecret));
- ast_copy_string(p->subscribecontext, user->subscribecontext, sizeof(p->subscribecontext));
- ast_copy_string(p->peermd5secret, user->md5secret, sizeof(p->peermd5secret));
- ast_copy_string(p->accountcode, user->accountcode, sizeof(p->accountcode));
- ast_copy_string(p->language, user->language, sizeof(p->language));
- ast_copy_string(p->musicclass, user->musicclass, sizeof(p->musicclass));
- p->amaflags = user->amaflags;
- p->callgroup = user->callgroup;
- p->pickupgroup = user->pickupgroup;
- p->callingpres = user->callingpres;
- p->capability = user->capability;
- p->jointcapability = user->capability;
- if (p->peercapability)
- p->jointcapability &= p->peercapability;
- if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_RFC2833) || (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_AUTO))
- p->noncodeccapability |= AST_RTP_DTMF;
- else
- p->noncodeccapability &= ~AST_RTP_DTMF;
- }
- if (user && debug)
- ast_verbose("Found user '%s'\n", user->name);
- } else {
- if (user) {
- if (!mailbox && debug)
- ast_verbose("Found user '%s', but fails host access\n", user->name);
- ASTOBJ_UNREF(user,sip_destroy_user);
- }
- user = NULL;
- }
-
- if (!user) {
- /* If we didn't find a user match, check for peers */
- if (sipmethod == SIP_SUBSCRIBE)
- /* For subscribes, match on peer name only */
- peer = find_peer(of, NULL, 1);
- else
- /* Look for peer based on the IP address we received data from */
- /* If peer is registered from this IP address or have this as a default
- IP address, this call is from the peer
- */
- peer = find_peer(NULL, &p->recv, 1);
-
- if (peer) {
- if (debug)
- ast_verbose("Found peer '%s'\n", peer->name);
- /* Take the peer */
- ast_copy_flags(p, peer, SIP_FLAGS_TO_COPY);
-
- /* Copy SIP extensions profile to peer */
- if (p->sipoptions)
- peer->sipoptions = p->sipoptions;
-
- /* replace callerid if rpid found, and not restricted */
- if (!ast_strlen_zero(rpid_num) && ast_test_flag(p, SIP_TRUSTRPID)) {
- if (*calleridname)
- ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
- ast_copy_string(p->cid_num, rpid_num, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
- }
- if (p->rtp) {
- ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- ast_rtp_setnat(p->rtp, (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- }
- if (p->vrtp) {
- ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- ast_rtp_setnat(p->vrtp, (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
- }
- ast_copy_string(p->peersecret, peer->secret, sizeof(p->peersecret));
- p->peersecret[sizeof(p->peersecret)-1] = '\0';
- ast_copy_string(p->subscribecontext, peer->subscribecontext, sizeof(p->subscribecontext));
- ast_copy_string(p->peermd5secret, peer->md5secret, sizeof(p->peermd5secret));
- p->peermd5secret[sizeof(p->peermd5secret)-1] = '\0';
- p->callingpres = peer->callingpres;
- if (peer->maxms && peer->lastms)
- p->timer_t1 = peer->lastms;
- if (ast_test_flag(peer, SIP_INSECURE_INVITE)) {
- /* Pretend there is no required authentication */
- p->peersecret[0] = '\0';
- p->peermd5secret[0] = '\0';
- }
- if (!(res = check_auth(p, req, p->randdata, sizeof(p->randdata), peer->name, p->peersecret, p->peermd5secret, sipmethod, uri, reliable, ignore))) {
- ast_copy_flags(p, peer, SIP_FLAGS_TO_COPY);
- /* If we have a call limit, set flag */
- if (peer->call_limit)
- ast_set_flag(p, SIP_CALL_LIMIT);
- ast_copy_string(p->peername, peer->name, sizeof(p->peername));
- ast_copy_string(p->authname, peer->name, sizeof(p->authname));
- /* copy channel vars */
- for (v = peer->chanvars ; v ; v = v->next) {
- if ((tmpvar = ast_variable_new(v->name, v->value))) {
- tmpvar->next = p->chanvars;
- p->chanvars = tmpvar;
- }
- }
- if (mailbox)
- snprintf(mailbox, mailboxlen, ",%s,", peer->mailbox);
- if (!ast_strlen_zero(peer->username)) {
- ast_copy_string(p->username, peer->username, sizeof(p->username));
- /* Use the default username for authentication on outbound calls */
- ast_copy_string(p->authname, peer->username, sizeof(p->authname));
- }
- if (!ast_strlen_zero(peer->cid_num) && !ast_strlen_zero(p->cid_num)) {
- ast_copy_string(p->cid_num, peer->cid_num, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
- }
- if (!ast_strlen_zero(peer->cid_name) && !ast_strlen_zero(p->cid_name))
- ast_copy_string(p->cid_name, peer->cid_name, sizeof(p->cid_name));
- ast_copy_string(p->fullcontact, peer->fullcontact, sizeof(p->fullcontact));
- if (!ast_strlen_zero(peer->context))
- ast_copy_string(p->context, peer->context, sizeof(p->context));
- ast_copy_string(p->peersecret, peer->secret, sizeof(p->peersecret));
- ast_copy_string(p->peermd5secret, peer->md5secret, sizeof(p->peermd5secret));
- ast_copy_string(p->language, peer->language, sizeof(p->language));
- ast_copy_string(p->accountcode, peer->accountcode, sizeof(p->accountcode));
- p->amaflags = peer->amaflags;
- p->callgroup = peer->callgroup;
- p->pickupgroup = peer->pickupgroup;
- p->capability = peer->capability;
- p->prefs = peer->prefs;
- p->jointcapability = peer->capability;
- if (p->peercapability)
- p->jointcapability &= p->peercapability;
- if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_RFC2833) || (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_AUTO))
- p->noncodeccapability |= AST_RTP_DTMF;
- else
- p->noncodeccapability &= ~AST_RTP_DTMF;
- }
- ASTOBJ_UNREF(peer,sip_destroy_peer);
- } else {
- if (debug)
- ast_verbose("Found no matching peer or user for '%s:%d'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port));
-
- /* do we allow guests? */
- if (!global_allowguest)
- res = -1; /* we don't want any guests, authentication will fail */
-#ifdef OSP_SUPPORT
- else if (global_allowguest == 2) {
- ast_copy_flags(p, &global_flags, SIP_OSPAUTH);
- res = check_auth(p, req, p->randdata, sizeof(p->randdata), "", "", "", sipmethod, uri, reliable, ignore);
- }
-#endif
- }
-
- }
-
- if (user)
- ASTOBJ_UNREF(user,sip_destroy_user);
- return res;
-}
-
-/*! \brief check_user: Find user ---*/
-static int check_user(struct sip_pvt *p, struct sip_request *req, int sipmethod, char *uri, int reliable, struct sockaddr_in *sin, int ignore)
-{
- return check_user_full(p, req, sipmethod, uri, reliable, sin, ignore, NULL, 0);
-}
-
-/*! \brief get_msg_text: Get text out of a SIP MESSAGE packet ---*/
-static int get_msg_text(char *buf, int len, struct sip_request *req)
-{
- int x;
- int y;
-
- buf[0] = '\0';
- y = len - strlen(buf) - 5;
- if (y < 0)
- y = 0;
- for (x=0;x<req->lines;x++) {
- strncat(buf, req->line[x], y); /* safe */
- y -= strlen(req->line[x]) + 1;
- if (y < 0)
- y = 0;
- if (y != 0)
- strcat(buf, "\n"); /* safe */
- }
- return 0;
-}
-
-
-/*! \brief receive_message: Receive SIP MESSAGE method messages ---*/
-/* We only handle messages within current calls currently */
-/* Reference: RFC 3428 */
-static void receive_message(struct sip_pvt *p, struct sip_request *req)
-{
- char buf[1024];
- struct ast_frame f;
- char *content_type;
-
- content_type = get_header(req, "Content-Type");
- if (strcmp(content_type, "text/plain")) { /* No text/plain attachment */
- transmit_response(p, "415 Unsupported Media Type", req); /* Good enough, or? */
- ast_set_flag(p, SIP_NEEDDESTROY);
- return;
- }
-
- if (get_msg_text(buf, sizeof(buf), req)) {
- ast_log(LOG_WARNING, "Unable to retrieve text from %s\n", p->callid);
- transmit_response(p, "202 Accepted", req);
- ast_set_flag(p, SIP_NEEDDESTROY);
- return;
- }
-
- if (p->owner) {
- if (sip_debug_test_pvt(p))
- ast_verbose("Message received: '%s'\n", buf);
- memset(&f, 0, sizeof(f));
- f.frametype = AST_FRAME_TEXT;
- f.subclass = 0;
- f.offset = 0;
- f.data = buf;
- f.datalen = strlen(buf);
- ast_queue_frame(p->owner, &f);
- transmit_response(p, "202 Accepted", req); /* We respond 202 accepted, since we relay the message */
- } else { /* Message outside of a call, we do not support that */
- ast_log(LOG_WARNING,"Received message to %s from %s, dropped it...\n Content-Type:%s\n Message: %s\n", get_header(req,"To"), get_header(req,"From"), content_type, buf);
- transmit_response(p, "405 Method Not Allowed", req); /* Good enough, or? */
- }
- ast_set_flag(p, SIP_NEEDDESTROY);
- return;
-}
-
-/*! \brief sip_show_inuse: CLI Command to show calls within limits set by
- call_limit ---*/
-static int sip_show_inuse(int fd, int argc, char *argv[]) {
-#define FORMAT "%-25.25s %-15.15s %-15.15s \n"
-#define FORMAT2 "%-25.25s %-15.15s %-15.15s \n"
- char ilimits[40];
- char iused[40];
- int showall = 0;
-
- if (argc < 3)
- return RESULT_SHOWUSAGE;
-
- if (argc == 4 && !strcmp(argv[3],"all"))
- showall = 1;
-
- ast_cli(fd, FORMAT, "* User name", "In use", "Limit");
- ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do {
- ASTOBJ_RDLOCK(iterator);
- if (iterator->call_limit)
- snprintf(ilimits, sizeof(ilimits), "%d", iterator->call_limit);
- else
- ast_copy_string(ilimits, "N/A", sizeof(ilimits));
- snprintf(iused, sizeof(iused), "%d", iterator->inUse);
- if (showall || iterator->call_limit)
- ast_cli(fd, FORMAT2, iterator->name, iused, ilimits);
- ASTOBJ_UNLOCK(iterator);
- } while (0) );
-
- ast_cli(fd, FORMAT, "* Peer name", "In use", "Limit");
-
- ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
- ASTOBJ_RDLOCK(iterator);
- if (iterator->call_limit)
- snprintf(ilimits, sizeof(ilimits), "%d", iterator->call_limit);
- else
- ast_copy_string(ilimits, "N/A", sizeof(ilimits));
- snprintf(iused, sizeof(iused), "%d", iterator->inUse);
- if (showall || iterator->call_limit)
- ast_cli(fd, FORMAT2, iterator->name, iused, ilimits);
- ASTOBJ_UNLOCK(iterator);
- } while (0) );
-
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-/*! \brief nat2str: Convert NAT setting to text string */
-static char *nat2str(int nat)
-{
- switch(nat) {
- case SIP_NAT_NEVER:
- return "No";
- case SIP_NAT_ROUTE:
- return "Route";
- case SIP_NAT_ALWAYS:
- return "Always";
- case SIP_NAT_RFC3581:
- return "RFC3581";
- default:
- return "Unknown";
- }
-}
-
-/*! \brief peer_status: Report Peer status in character string */
-/* returns 1 if peer is online, -1 if unmonitored */
-static int peer_status(struct sip_peer *peer, char *status, int statuslen)
-{
- int res = 0;
- if (peer->maxms) {
- if (peer->lastms < 0) {
- ast_copy_string(status, "UNREACHABLE", statuslen);
- } else if (peer->lastms > peer->maxms) {
- snprintf(status, statuslen, "LAGGED (%d ms)", peer->lastms);
- res = 1;
- } else if (peer->lastms) {
- snprintf(status, statuslen, "OK (%d ms)", peer->lastms);
- res = 1;
- } else {
- ast_copy_string(status, "UNKNOWN", statuslen);
- }
- } else {
- ast_copy_string(status, "Unmonitored", statuslen);
- /* Checking if port is 0 */
- res = -1;
- }
- return res;
-}
-
-/*! \brief sip_show_users: CLI Command 'SIP Show Users' ---*/
-static int sip_show_users(int fd, int argc, char *argv[])
-{
- regex_t regexbuf;
- int havepattern = 0;
-
-#define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n"
-
- switch (argc) {
- case 5:
- if (!strcasecmp(argv[3], "like")) {
- if (regcomp(&regexbuf, argv[4], REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
- havepattern = 1;
- } else
- return RESULT_SHOWUSAGE;
- case 3:
- break;
- default:
- return RESULT_SHOWUSAGE;
- }
-
- ast_cli(fd, FORMAT, "Username", "Secret", "Accountcode", "Def.Context", "ACL", "NAT");
- ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do {
- ASTOBJ_RDLOCK(iterator);
-
- if (havepattern && regexec(&regexbuf, iterator->name, 0, NULL, 0)) {
- ASTOBJ_UNLOCK(iterator);
- continue;
- }
-
- ast_cli(fd, FORMAT, iterator->name,
- iterator->secret,
- iterator->accountcode,
- iterator->context,
- iterator->ha ? "Yes" : "No",
- nat2str(ast_test_flag(iterator, SIP_NAT)));
- ASTOBJ_UNLOCK(iterator);
- } while (0)
- );
-
- if (havepattern)
- regfree(&regexbuf);
-
- return RESULT_SUCCESS;
-#undef FORMAT
-}
-
-static char mandescr_show_peers[] =
-"Description: Lists SIP peers in text format with details on current status.\n"
-"Variables: \n"
-" ActionID: <id> Action ID for this transaction. Will be returned.\n";
-
-static int _sip_show_peers(int fd, int *total, struct mansession *s, struct message *m, int argc, char *argv[]);
-
-/*! \brief manager_sip_show_peers: Show SIP peers in the manager API ---*/
-/* Inspired from chan_iax2 */
-static int manager_sip_show_peers( struct mansession *s, struct message *m )
-{
- char *id = astman_get_header(m,"ActionID");
- char *a[] = { "sip", "show", "peers" };
- char idtext[256] = "";
- int total = 0;
-
- if (!ast_strlen_zero(id))
- snprintf(idtext,256,"ActionID: %s\r\n",id);
-
- astman_send_ack(s, m, "Peer status list will follow");
- /* List the peers in separate manager events */
- _sip_show_peers(s->fd, &total, s, m, 3, a);
- /* Send final confirmation */
- ast_cli(s->fd,
- "Event: PeerlistComplete\r\n"
- "ListItems: %d\r\n"
- "%s"
- "\r\n", total, idtext);
- return 0;
-}
-
-/*! \brief sip_show_peers: CLI Show Peers command */
-static int sip_show_peers(int fd, int argc, char *argv[])
-{
- return _sip_show_peers(fd, NULL, NULL, NULL, argc, argv);
-}
-
-/*! \brief _sip_show_peers: Execute sip show peers command */
-static int _sip_show_peers(int fd, int *total, struct mansession *s, struct message *m, int argc, char *argv[])
-{
- regex_t regexbuf;
- int havepattern = 0;
-
-#define FORMAT2 "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8s %-10s\n"
-#define FORMAT "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8d %-10s\n"
-
- char name[256];
- char iabuf[INET_ADDRSTRLEN];
- int total_peers = 0;
- int peers_online = 0;
- int peers_offline = 0;
- char *id;
- char idtext[256] = "";
-
- if (s) { /* Manager - get ActionID */
- id = astman_get_header(m,"ActionID");
- if (!ast_strlen_zero(id))
- snprintf(idtext,256,"ActionID: %s\r\n",id);
- }
-
- switch (argc) {
- case 5:
- if (!strcasecmp(argv[3], "like")) {
- if (regcomp(&regexbuf, argv[4], REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
- havepattern = 1;
- } else
- return RESULT_SHOWUSAGE;
- case 3:
- break;
- default:
- return RESULT_SHOWUSAGE;
- }
-
- if (!s) { /* Normal list */
- ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Nat", "ACL", "Port", "Status");
- }
-
- ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
- char status[20] = "";
- char srch[2000];
- char pstatus;
-
- ASTOBJ_RDLOCK(iterator);
-
- if (havepattern && regexec(&regexbuf, iterator->name, 0, NULL, 0)) {
- ASTOBJ_UNLOCK(iterator);
- continue;
- }
-
- if (!ast_strlen_zero(iterator->username) && !s)
- snprintf(name, sizeof(name), "%s/%s", iterator->name, iterator->username);
- else
- ast_copy_string(name, iterator->name, sizeof(name));
-
- pstatus = peer_status(iterator, status, sizeof(status));
- if (pstatus)
- peers_online++;
- else {
- if (pstatus == 0)
- peers_offline++;
- else { /* Unmonitored */
- /* Checking if port is 0 */
- if ( ntohs(iterator->addr.sin_port) == 0 ) {
- peers_offline++;
- } else {
- peers_online++;
- }
- }
- }
-
- snprintf(srch, sizeof(srch), FORMAT, name,
- iterator->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), iterator->addr.sin_addr) : "(Unspecified)",
- ast_test_flag(iterator, SIP_DYNAMIC) ? " D " : " ", /* Dynamic or not? */
- (ast_test_flag(iterator, SIP_NAT) & SIP_NAT_ROUTE) ? " N " : " ", /* NAT=yes? */
- iterator->ha ? " A " : " ", /* permit/deny */
- ntohs(iterator->addr.sin_port), status);
-
- if (!s) {/* Normal CLI list */
- ast_cli(fd, FORMAT, name,
- iterator->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), iterator->addr.sin_addr) : "(Unspecified)",
- ast_test_flag(iterator, SIP_DYNAMIC) ? " D " : " ", /* Dynamic or not? */
- (ast_test_flag(iterator, SIP_NAT) & SIP_NAT_ROUTE) ? " N " : " ", /* NAT=yes? */
- iterator->ha ? " A " : " ", /* permit/deny */
-
- ntohs(iterator->addr.sin_port), status);
- } else { /* Manager format */
- /* The names here need to be the same as other channels */
- ast_cli(fd,
- "Event: PeerEntry\r\n%s"
- "Channeltype: SIP\r\n"
- "ObjectName: %s\r\n"
- "ChanObjectType: peer\r\n" /* "peer" or "user" */
- "IPaddress: %s\r\n"
- "IPport: %d\r\n"
- "Dynamic: %s\r\n"
- "Natsupport: %s\r\n"
- "ACL: %s\r\n"
- "Status: %s\r\n\r\n",
- idtext,
- iterator->name,
- iterator->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), iterator->addr.sin_addr) : "-none-",
- ntohs(iterator->addr.sin_port),
- ast_test_flag(iterator, SIP_DYNAMIC) ? "yes" : "no", /* Dynamic or not? */
- (ast_test_flag(iterator, SIP_NAT) & SIP_NAT_ROUTE) ? "yes" : "no", /* NAT=yes? */
- iterator->ha ? "yes" : "no", /* permit/deny */
- status);
- }
-
- ASTOBJ_UNLOCK(iterator);
-
- total_peers++;
- } while(0) );
-
- if (!s) {
- ast_cli(fd,"%d sip peers [%d online , %d offline]\n",total_peers,peers_online,peers_offline);
- }
-
- if (havepattern)
- regfree(&regexbuf);
-
- if (total)
- *total = total_peers;
-
-
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-/*! \brief sip_show_objects: List all allocated SIP Objects ---*/
-static int sip_show_objects(int fd, int argc, char *argv[])
-{
- char tmp[256];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, "-= User objects: %d static, %d realtime =-\n\n", suserobjs, ruserobjs);
- ASTOBJ_CONTAINER_DUMP(fd, tmp, sizeof(tmp), &userl);
- ast_cli(fd, "-= Peer objects: %d static, %d realtime, %d autocreate =-\n\n", speerobjs, rpeerobjs, apeerobjs);
- ASTOBJ_CONTAINER_DUMP(fd, tmp, sizeof(tmp), &peerl);
- ast_cli(fd, "-= Registry objects: %d =-\n\n", regobjs);
- ASTOBJ_CONTAINER_DUMP(fd, tmp, sizeof(tmp), &regl);
- return RESULT_SUCCESS;
-}
-/*! \brief print_group: Print call group and pickup group ---*/
-static void print_group(int fd, unsigned int group, int crlf)
-{
- char buf[256];
- ast_cli(fd, crlf ? "%s\r\n" : "%s\n", ast_print_group(buf, sizeof(buf), group) );
-}
-
-/*! \brief dtmfmode2str: Convert DTMF mode to printable string ---*/
-static const char *dtmfmode2str(int mode)
-{
- switch (mode) {
- case SIP_DTMF_RFC2833:
- return "rfc2833";
- case SIP_DTMF_INFO:
- return "info";
- case SIP_DTMF_INBAND:
- return "inband";
- case SIP_DTMF_AUTO:
- return "auto";
- }
- return "<error>";
-}
-
-/*! \brief insecure2str: Convert Insecure setting to printable string ---*/
-static const char *insecure2str(int port, int invite)
-{
- if (port && invite)
- return "port,invite";
- else if (port)
- return "port";
- else if (invite)
- return "invite";
- else
- return "no";
-}
-
-/*! \brief sip_prune_realtime: Remove temporary realtime objects from memory (CLI) ---*/
-static int sip_prune_realtime(int fd, int argc, char *argv[])
-{
- struct sip_peer *peer;
- struct sip_user *user;
- int pruneuser = 0;
- int prunepeer = 0;
- int multi = 0;
- char *name = NULL;
- regex_t regexbuf;
-
- switch (argc) {
- case 4:
- if (!strcasecmp(argv[3], "user"))
- return RESULT_SHOWUSAGE;
- if (!strcasecmp(argv[3], "peer"))
- return RESULT_SHOWUSAGE;
- if (!strcasecmp(argv[3], "like"))
- return RESULT_SHOWUSAGE;
- if (!strcasecmp(argv[3], "all")) {
- multi = 1;
- pruneuser = prunepeer = 1;
- } else {
- pruneuser = prunepeer = 1;
- name = argv[3];
- }
- break;
- case 5:
- if (!strcasecmp(argv[4], "like"))
- return RESULT_SHOWUSAGE;
- if (!strcasecmp(argv[3], "all"))
- return RESULT_SHOWUSAGE;
- if (!strcasecmp(argv[3], "like")) {
- multi = 1;
- name = argv[4];
- pruneuser = prunepeer = 1;
- } else if (!strcasecmp(argv[3], "user")) {
- pruneuser = 1;
- if (!strcasecmp(argv[4], "all"))
- multi = 1;
- else
- name = argv[4];
- } else if (!strcasecmp(argv[3], "peer")) {
- prunepeer = 1;
- if (!strcasecmp(argv[4], "all"))
- multi = 1;
- else
- name = argv[4];
- } else
- return RESULT_SHOWUSAGE;
- break;
- case 6:
- if (strcasecmp(argv[4], "like"))
- return RESULT_SHOWUSAGE;
- if (!strcasecmp(argv[3], "user")) {
- pruneuser = 1;
- name = argv[5];
- } else if (!strcasecmp(argv[3], "peer")) {
- prunepeer = 1;
- name = argv[5];
- } else
- return RESULT_SHOWUSAGE;
- break;
- default:
- return RESULT_SHOWUSAGE;
- }
-
- if (multi && name) {
- if (regcomp(&regexbuf, name, REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
- }
-
- if (multi) {
- if (prunepeer) {
- int pruned = 0;
-
- ASTOBJ_CONTAINER_WRLOCK(&peerl);
- ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
- ASTOBJ_RDLOCK(iterator);
- if (name && regexec(&regexbuf, iterator->name, 0, NULL, 0)) {
- ASTOBJ_UNLOCK(iterator);
- continue;
- };
- if (ast_test_flag((&iterator->flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
- ASTOBJ_MARK(iterator);
- pruned++;
- }
- ASTOBJ_UNLOCK(iterator);
- } while (0) );
- if (pruned) {
- ASTOBJ_CONTAINER_PRUNE_MARKED(&peerl, sip_destroy_peer);
- ast_cli(fd, "%d peers pruned.\n", pruned);
- } else
- ast_cli(fd, "No peers found to prune.\n");
- ASTOBJ_CONTAINER_UNLOCK(&peerl);
- }
- if (pruneuser) {
- int pruned = 0;
-
- ASTOBJ_CONTAINER_WRLOCK(&userl);
- ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do {
- ASTOBJ_RDLOCK(iterator);
- if (name && regexec(&regexbuf, iterator->name, 0, NULL, 0)) {
- ASTOBJ_UNLOCK(iterator);
- continue;
- };
- if (ast_test_flag((&iterator->flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
- ASTOBJ_MARK(iterator);
- pruned++;
- }
- ASTOBJ_UNLOCK(iterator);
- } while (0) );
- if (pruned) {
- ASTOBJ_CONTAINER_PRUNE_MARKED(&userl, sip_destroy_user);
- ast_cli(fd, "%d users pruned.\n", pruned);
- } else
- ast_cli(fd, "No users found to prune.\n");
- ASTOBJ_CONTAINER_UNLOCK(&userl);
- }
- } else {
- if (prunepeer) {
- if ((peer = ASTOBJ_CONTAINER_FIND_UNLINK(&peerl, name))) {
- if (!ast_test_flag((&peer->flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
- ast_cli(fd, "Peer '%s' is not a Realtime peer, cannot be pruned.\n", name);
- ASTOBJ_CONTAINER_LINK(&peerl, peer);
- } else
- ast_cli(fd, "Peer '%s' pruned.\n", name);
- ASTOBJ_UNREF(peer, sip_destroy_peer);
- } else
- ast_cli(fd, "Peer '%s' not found.\n", name);
- }
- if (pruneuser) {
- if ((user = ASTOBJ_CONTAINER_FIND_UNLINK(&userl, name))) {
- if (!ast_test_flag((&user->flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
- ast_cli(fd, "User '%s' is not a Realtime user, cannot be pruned.\n", name);
- ASTOBJ_CONTAINER_LINK(&userl, user);
- } else
- ast_cli(fd, "User '%s' pruned.\n", name);
- ASTOBJ_UNREF(user, sip_destroy_user);
- } else
- ast_cli(fd, "User '%s' not found.\n", name);
- }
- }
-
- return RESULT_SUCCESS;
-}
-
-/*! \brief print_codec_to_cli: Print codec list from preference to CLI/manager */
-static void print_codec_to_cli(int fd, struct ast_codec_pref *pref)
-{
- int x, codec;
-
- for(x = 0; x < 32 ; x++) {
- codec = ast_codec_pref_index(pref, x);
- if (!codec)
- break;
- ast_cli(fd, "%s", ast_getformatname(codec));
- if (x < 31 && ast_codec_pref_index(pref, x + 1))
- ast_cli(fd, ",");
- }
- if (!x)
- ast_cli(fd, "none");
-}
-
-static const char *domain_mode_to_text(const enum domain_mode mode)
-{
- switch (mode) {
- case SIP_DOMAIN_AUTO:
- return "[Automatic]";
- case SIP_DOMAIN_CONFIG:
- return "[Configured]";
- }
-
- return "";
-}
-
-/*! \brief sip_show_domains: CLI command to list local domains */
-#define FORMAT "%-40.40s %-20.20s %-16.16s\n"
-static int sip_show_domains(int fd, int argc, char *argv[])
-{
- struct domain *d;
-
- if (AST_LIST_EMPTY(&domain_list)) {
- ast_cli(fd, "SIP Domain support not enabled.\n\n");
- return RESULT_SUCCESS;
- } else {
- ast_cli(fd, FORMAT, "Our local SIP domains:", "Context", "Set by");
- AST_LIST_LOCK(&domain_list);
- AST_LIST_TRAVERSE(&domain_list, d, list)
- ast_cli(fd, FORMAT, d->domain, ast_strlen_zero(d->context) ? "(default)": d->context,
- domain_mode_to_text(d->mode));
- AST_LIST_UNLOCK(&domain_list);
- ast_cli(fd, "\n");
- return RESULT_SUCCESS;
- }
-}
-#undef FORMAT
-
-static char mandescr_show_peer[] =
-"Description: Show one SIP peer with details on current status.\n"
-" The XML format is under development, feedback welcome! /oej\n"
-"Variables: \n"
-" Peer: <name> The peer name you want to check.\n"
-" ActionID: <id> Optional action ID for this AMI transaction.\n";
-
-static int _sip_show_peer(int type, int fd, struct mansession *s, struct message *m, int argc, char *argv[]);
-
-/*! \brief manager_sip_show_peer: Show SIP peers in the manager API ---*/
-static int manager_sip_show_peer( struct mansession *s, struct message *m )
-{
- char *id = astman_get_header(m,"ActionID");
- char *a[4];
- char *peer;
- int ret;
-
- peer = astman_get_header(m,"Peer");
- if (ast_strlen_zero(peer)) {
- astman_send_error(s, m, "Peer: <name> missing.\n");
- return 0;
- }
- a[0] = "sip";
- a[1] = "show";
- a[2] = "peer";
- a[3] = peer;
-
- if (!ast_strlen_zero(id))
- ast_cli(s->fd, "ActionID: %s\r\n",id);
- ret = _sip_show_peer(1, s->fd, s, m, 4, a );
- ast_cli( s->fd, "\r\n\r\n" );
- return ret;
-}
-
-
-
-/*! \brief sip_show_peer: Show one peer in detail ---*/
-static int sip_show_peer(int fd, int argc, char *argv[])
-{
- return _sip_show_peer(0, fd, NULL, NULL, argc, argv);
-}
-
-static int _sip_show_peer(int type, int fd, struct mansession *s, struct message *m, int argc, char *argv[])
-{
- char status[30] = "";
- char cbuf[256];
- char iabuf[INET_ADDRSTRLEN];
- struct sip_peer *peer;
- char codec_buf[512];
- struct ast_codec_pref *pref;
- struct ast_variable *v;
- struct sip_auth *auth;
- int x = 0, codec = 0, load_realtime = 0;
-
- if (argc < 4)
- return RESULT_SHOWUSAGE;
-
- load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? 1 : 0;
- peer = find_peer(argv[3], NULL, load_realtime);
- if (s) { /* Manager */
- if (peer)
- ast_cli(s->fd, "Response: Success\r\n");
- else {
- snprintf (cbuf, sizeof(cbuf), "Peer %s not found.\n", argv[3]);
- astman_send_error(s, m, cbuf);
- return 0;
- }
- }
- if (peer && type==0 ) { /* Normal listing */
- ast_cli(fd,"\n\n");
- ast_cli(fd, " * Name : %s\n", peer->name);
- ast_cli(fd, " Secret : %s\n", ast_strlen_zero(peer->secret)?"<Not set>":"<Set>");
- ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(peer->md5secret)?"<Not set>":"<Set>");
- auth = peer->auth;
- while(auth) {
- ast_cli(fd, " Realm-auth : Realm %-15.15s User %-10.20s ", auth->realm, auth->username);
- ast_cli(fd, "%s\n", !ast_strlen_zero(auth->secret)?"<Secret set>":(!ast_strlen_zero(auth->md5secret)?"<MD5secret set>" : "<Not set>"));
- auth = auth->next;
- }
- ast_cli(fd, " Context : %s\n", peer->context);
- ast_cli(fd, " Subscr.Cont. : %s\n", ast_strlen_zero(peer->subscribecontext)?"<Not set>":peer->subscribecontext);
- ast_cli(fd, " Language : %s\n", peer->language);
- if (!ast_strlen_zero(peer->accountcode))
- ast_cli(fd, " Accountcode : %s\n", peer->accountcode);
- ast_cli(fd, " AMA flags : %s\n", ast_cdr_flags2str(peer->amaflags));
- ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(peer->callingpres));
- if (!ast_strlen_zero(peer->fromuser))
- ast_cli(fd, " FromUser : %s\n", peer->fromuser);
- if (!ast_strlen_zero(peer->fromdomain))
- ast_cli(fd, " FromDomain : %s\n", peer->fromdomain);
- ast_cli(fd, " Callgroup : ");
- print_group(fd, peer->callgroup, 0);
- ast_cli(fd, " Pickupgroup : ");
- print_group(fd, peer->pickupgroup, 0);
- ast_cli(fd, " Mailbox : %s\n", peer->mailbox);
- ast_cli(fd, " VM Extension : %s\n", peer->vmexten);
- ast_cli(fd, " LastMsgsSent : %d\n", peer->lastmsgssent);
- ast_cli(fd, " Call limit : %d\n", peer->call_limit);
- ast_cli(fd, " Dynamic : %s\n", (ast_test_flag(peer, SIP_DYNAMIC)?"Yes":"No"));
- ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>"));
- ast_cli(fd, " Expire : %d\n", peer->expire);
- ast_cli(fd, " Insecure : %s\n", insecure2str(ast_test_flag(peer, SIP_INSECURE_PORT), ast_test_flag(peer, SIP_INSECURE_INVITE)));
- ast_cli(fd, " Nat : %s\n", nat2str(ast_test_flag(peer, SIP_NAT)));
- ast_cli(fd, " ACL : %s\n", (peer->ha?"Yes":"No"));
- ast_cli(fd, " CanReinvite : %s\n", (ast_test_flag(peer, SIP_CAN_REINVITE)?"Yes":"No"));
- ast_cli(fd, " PromiscRedir : %s\n", (ast_test_flag(peer, SIP_PROMISCREDIR)?"Yes":"No"));
- ast_cli(fd, " User=Phone : %s\n", (ast_test_flag(peer, SIP_USEREQPHONE)?"Yes":"No"));
- ast_cli(fd, " Trust RPID : %s\n", (ast_test_flag(peer, SIP_TRUSTRPID) ? "Yes" : "No"));
- ast_cli(fd, " Send RPID : %s\n", (ast_test_flag(peer, SIP_SENDRPID) ? "Yes" : "No"));
-
- /* - is enumerated */
- ast_cli(fd, " DTMFmode : %s\n", dtmfmode2str(ast_test_flag(peer, SIP_DTMF)));
- ast_cli(fd, " LastMsg : %d\n", peer->lastmsg);
- ast_cli(fd, " ToHost : %s\n", peer->tohost);
- ast_cli(fd, " Addr->IP : %s Port %d\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)", ntohs(peer->addr.sin_port));
- ast_cli(fd, " Defaddr->IP : %s Port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port));
- ast_cli(fd, " Def. Username: %s\n", peer->username);
- ast_cli(fd, " SIP Options : ");
- if (peer->sipoptions) {
- for (x=0 ; (x < (sizeof(sip_options) / sizeof(sip_options[0]))); x++) {
- if (peer->sipoptions & sip_options[x].id)
- ast_cli(fd, "%s ", sip_options[x].text);
- }
- } else
- ast_cli(fd, "(none)");
-
- ast_cli(fd, "\n");
- ast_cli(fd, " Codecs : ");
- ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability);
- ast_cli(fd, "%s\n", codec_buf);
- ast_cli(fd, " Codec Order : (");
- print_codec_to_cli(fd, &peer->prefs);
-
- ast_cli(fd, ")\n");
-
- ast_cli(fd, " Status : ");
- peer_status(peer, status, sizeof(status));
- ast_cli(fd, "%s\n",status);
- ast_cli(fd, " Useragent : %s\n", peer->useragent);
- ast_cli(fd, " Reg. Contact : %s\n", peer->fullcontact);
- if (peer->chanvars) {
- ast_cli(fd, " Variables :\n");
- for (v = peer->chanvars ; v ; v = v->next)
- ast_cli(fd, " %s = %s\n", v->name, v->value);
- }
- ast_cli(fd,"\n");
- ASTOBJ_UNREF(peer,sip_destroy_peer);
- } else if (peer && type == 1) { /* manager listing */
- char *actionid = astman_get_header(m,"ActionID");
-
- ast_cli(fd, "Channeltype: SIP\r\n");
- if (actionid)
- ast_cli(fd, "ActionID: %s\r\n", actionid);
- ast_cli(fd, "ObjectName: %s\r\n", peer->name);
- ast_cli(fd, "ChanObjectType: peer\r\n");
- ast_cli(fd, "SecretExist: %s\r\n", ast_strlen_zero(peer->secret)?"N":"Y");
- ast_cli(fd, "MD5SecretExist: %s\r\n", ast_strlen_zero(peer->md5secret)?"N":"Y");
- ast_cli(fd, "Context: %s\r\n", peer->context);
- ast_cli(fd, "Language: %s\r\n", peer->language);
- if (!ast_strlen_zero(peer->accountcode))
- ast_cli(fd, "Accountcode: %s\r\n", peer->accountcode);
- ast_cli(fd, "AMAflags: %s\r\n", ast_cdr_flags2str(peer->amaflags));
- ast_cli(fd, "CID-CallingPres: %s\r\n", ast_describe_caller_presentation(peer->callingpres));
- if (!ast_strlen_zero(peer->fromuser))
- ast_cli(fd, "SIP-FromUser: %s\r\n", peer->fromuser);
- if (!ast_strlen_zero(peer->fromdomain))
- ast_cli(fd, "SIP-FromDomain: %s\r\n", peer->fromdomain);
- ast_cli(fd, "Callgroup: ");
- print_group(fd, peer->callgroup, 1);
- ast_cli(fd, "Pickupgroup: ");
- print_group(fd, peer->pickupgroup, 1);
- ast_cli(fd, "VoiceMailbox: %s\r\n", peer->mailbox);
- ast_cli(fd, "LastMsgsSent: %d\r\n", peer->lastmsgssent);
- ast_cli(fd, "Call limit: %d\r\n", peer->call_limit);
- ast_cli(fd, "Dynamic: %s\r\n", (ast_test_flag(peer, SIP_DYNAMIC)?"Y":"N"));
- ast_cli(fd, "Callerid: %s\r\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, ""));
- ast_cli(fd, "RegExpire: %ld seconds\r\n", ast_sched_when(sched,peer->expire));
- ast_cli(fd, "SIP-AuthInsecure: %s\r\n", insecure2str(ast_test_flag(peer, SIP_INSECURE_PORT), ast_test_flag(peer, SIP_INSECURE_INVITE)));
- ast_cli(fd, "SIP-NatSupport: %s\r\n", nat2str(ast_test_flag(peer, SIP_NAT)));
- ast_cli(fd, "ACL: %s\r\n", (peer->ha?"Y":"N"));
- ast_cli(fd, "SIP-CanReinvite: %s\r\n", (ast_test_flag(peer, SIP_CAN_REINVITE)?"Y":"N"));
- ast_cli(fd, "SIP-PromiscRedir: %s\r\n", (ast_test_flag(peer, SIP_PROMISCREDIR)?"Y":"N"));
- ast_cli(fd, "SIP-UserPhone: %s\r\n", (ast_test_flag(peer, SIP_USEREQPHONE)?"Y":"N"));
-
- /* - is enumerated */
- ast_cli(fd, "SIP-DTMFmode %s\r\n", dtmfmode2str(ast_test_flag(peer, SIP_DTMF)));
- ast_cli(fd, "SIPLastMsg: %d\r\n", peer->lastmsg);
- ast_cli(fd, "ToHost: %s\r\n", peer->tohost);
- ast_cli(fd, "Address-IP: %s\r\nAddress-Port: %d\r\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "", ntohs(peer->addr.sin_port));
- ast_cli(fd, "Default-addr-IP: %s\r\nDefault-addr-port: %d\r\n", ast_inet_ntoa(iabuf, sizeof(iabuf), peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port));
- ast_cli(fd, "Default-Username: %s\r\n", peer->username);
- ast_cli(fd, "Codecs: ");
- ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability);
- ast_cli(fd, "%s\r\n", codec_buf);
- ast_cli(fd, "CodecOrder: ");
- pref = &peer->prefs;
- for(x = 0; x < 32 ; x++) {
- codec = ast_codec_pref_index(pref,x);
- if (!codec)
- break;
- ast_cli(fd, "%s", ast_getformatname(codec));
- if (x < 31 && ast_codec_pref_index(pref,x+1))
- ast_cli(fd, ",");
- }
-
- ast_cli(fd, "\r\n");
- ast_cli(fd, "Status: ");
- peer_status(peer, status, sizeof(status));
- ast_cli(fd, "%s\r\n", status);
- ast_cli(fd, "SIP-Useragent: %s\r\n", peer->useragent);
- ast_cli(fd, "Reg-Contact : %s\r\n", peer->fullcontact);
- if (peer->chanvars) {
- for (v = peer->chanvars ; v ; v = v->next) {
- ast_cli(fd, "ChanVariable:\n");
- ast_cli(fd, " %s,%s\r\n", v->name, v->value);
- }
- }
-
- ASTOBJ_UNREF(peer,sip_destroy_peer);
-
- } else {
- ast_cli(fd,"Peer %s not found.\n", argv[3]);
- ast_cli(fd,"\n");
- }
-
- return RESULT_SUCCESS;
-}
-
-/*! \brief sip_show_user: Show one user in detail ---*/
-static int sip_show_user(int fd, int argc, char *argv[])
-{
- char cbuf[256];
- struct sip_user *user;
- struct ast_codec_pref *pref;
- struct ast_variable *v;
- int x = 0, codec = 0, load_realtime = 0;
-
- if (argc < 4)
- return RESULT_SHOWUSAGE;
-
- /* Load from realtime storage? */
- load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? 1 : 0;
-
- user = find_user(argv[3], load_realtime);
- if (user) {
- ast_cli(fd,"\n\n");
- ast_cli(fd, " * Name : %s\n", user->name);
- ast_cli(fd, " Secret : %s\n", ast_strlen_zero(user->secret)?"<Not set>":"<Set>");
- ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(user->md5secret)?"<Not set>":"<Set>");
- ast_cli(fd, " Context : %s\n", user->context);
- ast_cli(fd, " Language : %s\n", user->language);
- if (!ast_strlen_zero(user->accountcode))
- ast_cli(fd, " Accountcode : %s\n", user->accountcode);
- ast_cli(fd, " AMA flags : %s\n", ast_cdr_flags2str(user->amaflags));
- ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(user->callingpres));
- ast_cli(fd, " Call limit : %d\n", user->call_limit);
- ast_cli(fd, " Callgroup : ");
- print_group(fd, user->callgroup, 0);
- ast_cli(fd, " Pickupgroup : ");
- print_group(fd, user->pickupgroup, 0);
- ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>"));
- ast_cli(fd, " ACL : %s\n", (user->ha?"Yes":"No"));
- ast_cli(fd, " Codec Order : (");
- pref = &user->prefs;
- for(x = 0; x < 32 ; x++) {
- codec = ast_codec_pref_index(pref,x);
- if (!codec)
- break;
- ast_cli(fd, "%s", ast_getformatname(codec));
- if (x < 31 && ast_codec_pref_index(pref,x+1))
- ast_cli(fd, "|");
- }
-
- if (!x)
- ast_cli(fd, "none");
- ast_cli(fd, ")\n");
-
- if (user->chanvars) {
- ast_cli(fd, " Variables :\n");
- for (v = user->chanvars ; v ; v = v->next)
- ast_cli(fd, " %s = %s\n", v->name, v->value);
- }
- ast_cli(fd,"\n");
- ASTOBJ_UNREF(user,sip_destroy_user);
- } else {
- ast_cli(fd,"User %s not found.\n", argv[3]);
- ast_cli(fd,"\n");
- }
-
- return RESULT_SUCCESS;
-}
-
-/*! \brief sip_show_registry: Show SIP Registry (registrations with other SIP proxies ---*/
-static int sip_show_registry(int fd, int argc, char *argv[])
-{
-#define FORMAT2 "%-30.30s %-12.12s %8.8s %-20.20s\n"
-#define FORMAT "%-30.30s %-12.12s %8d %-20.20s\n"
- char host[80];
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, FORMAT2, "Host", "Username", "Refresh", "State");
- ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
- ASTOBJ_RDLOCK(iterator);
- snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : DEFAULT_SIP_PORT);
- ast_cli(fd, FORMAT, host, iterator->username, iterator->refresh, regstate2str(iterator->regstate));
- ASTOBJ_UNLOCK(iterator);
- } while(0));
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-/*! \brief sip_show_settings: List global settings for the SIP channel ---*/
-static int sip_show_settings(int fd, int argc, char *argv[])
-{
- char tmp[BUFSIZ];
- int realtimepeers = 0;
- int realtimeusers = 0;
-
- realtimepeers = ast_check_realtime("sippeers");
- realtimeusers = ast_check_realtime("sipusers");
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, "\n\nGlobal Settings:\n");
- ast_cli(fd, "----------------\n");
- ast_cli(fd, " SIP Port: %d\n", ntohs(bindaddr.sin_port));
- ast_cli(fd, " Bindaddress: %s\n", ast_inet_ntoa(tmp, sizeof(tmp), bindaddr.sin_addr));
- ast_cli(fd, " Videosupport: %s\n", videosupport ? "Yes" : "No");
- ast_cli(fd, " AutoCreatePeer: %s\n", autocreatepeer ? "Yes" : "No");
- ast_cli(fd, " Allow unknown access: %s\n", global_allowguest ? "Yes" : "No");
- ast_cli(fd, " Promsic. redir: %s\n", ast_test_flag(&global_flags, SIP_PROMISCREDIR) ? "Yes" : "No");
- ast_cli(fd, " SIP domain support: %s\n", AST_LIST_EMPTY(&domain_list) ? "No" : "Yes");
- ast_cli(fd, " Call to non-local dom.: %s\n", allow_external_domains ? "Yes" : "No");
- ast_cli(fd, " URI user is phone no: %s\n", ast_test_flag(&global_flags, SIP_USEREQPHONE) ? "Yes" : "No");
- ast_cli(fd, " Our auth realm %s\n", global_realm);
- ast_cli(fd, " Realm. auth: %s\n", authl ? "Yes": "No");
- ast_cli(fd, " User Agent: %s\n", default_useragent);
- ast_cli(fd, " MWI checking interval: %d secs\n", global_mwitime);
- ast_cli(fd, " Reg. context: %s\n", ast_strlen_zero(regcontext) ? "(not set)" : regcontext);
- ast_cli(fd, " Caller ID: %s\n", default_callerid);
- ast_cli(fd, " From: Domain: %s\n", default_fromdomain);
- ast_cli(fd, " Record SIP history: %s\n", recordhistory ? "On" : "Off");
- ast_cli(fd, " Call Events: %s\n", callevents ? "On" : "Off");
- ast_cli(fd, " IP ToS: 0x%x\n", tos);
-#ifdef OSP_SUPPORT
- ast_cli(fd, " OSP Support: Yes\n");
-#else
- ast_cli(fd, " OSP Support: No\n");
-#endif
- if (!realtimepeers && !realtimeusers)
- ast_cli(fd, " SIP realtime: Disabled\n" );
- else
- ast_cli(fd, " SIP realtime: Enabled\n" );
-
- ast_cli(fd, "\nGlobal Signalling Settings:\n");
- ast_cli(fd, "---------------------------\n");
- ast_cli(fd, " Codecs: ");
- print_codec_to_cli(fd, &prefs);
- ast_cli(fd, "\n");
- ast_cli(fd, " Relax DTMF: %s\n", relaxdtmf ? "Yes" : "No");
- ast_cli(fd, " Compact SIP headers: %s\n", compactheaders ? "Yes" : "No");
- ast_cli(fd, " RTP Timeout: %d %s\n", global_rtptimeout, global_rtptimeout ? "" : "(Disabled)" );
- ast_cli(fd, " RTP Hold Timeout: %d %s\n", global_rtpholdtimeout, global_rtpholdtimeout ? "" : "(Disabled)");
- ast_cli(fd, " MWI NOTIFY mime type: %s\n", default_notifymime);
- ast_cli(fd, " DNS SRV lookup: %s\n", srvlookup ? "Yes" : "No");
- ast_cli(fd, " Pedantic SIP support: %s\n", pedanticsipchecking ? "Yes" : "No");
- ast_cli(fd, " Reg. max duration: %d secs\n", max_expiry);
- ast_cli(fd, " Reg. default duration: %d secs\n", default_expiry);
- ast_cli(fd, " Outbound reg. timeout: %d secs\n", global_reg_timeout);
- ast_cli(fd, " Outbound reg. attempts: %d\n", global_regattempts_max);
- ast_cli(fd, " Notify ringing state: %s\n", global_notifyringing ? "Yes" : "No");
- ast_cli(fd, "\nDefault Settings:\n");
- ast_cli(fd, "-----------------\n");
- ast_cli(fd, " Context: %s\n", default_context);
- ast_cli(fd, " Nat: %s\n", nat2str(ast_test_flag(&global_flags, SIP_NAT)));
- ast_cli(fd, " DTMF: %s\n", dtmfmode2str(ast_test_flag(&global_flags, SIP_DTMF)));
- ast_cli(fd, " Qualify: %d\n", default_qualify);
- ast_cli(fd, " Use ClientCode: %s\n", ast_test_flag(&global_flags, SIP_USECLIENTCODE) ? "Yes" : "No");
- ast_cli(fd, " Progress inband: %s\n", (ast_test_flag(&global_flags, SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER) ? "Never" : (ast_test_flag(&global_flags, SIP_PROG_INBAND) == SIP_PROG_INBAND_NO) ? "No" : "Yes" );
- ast_cli(fd, " Language: %s\n", ast_strlen_zero(default_language) ? "(Defaults to English)" : default_language);
- ast_cli(fd, " Musicclass: %s\n", global_musicclass);
- ast_cli(fd, " Voice Mail Extension: %s\n", global_vmexten);
-
-
- if (realtimepeers || realtimeusers) {
- ast_cli(fd, "\nRealtime SIP Settings:\n");
- ast_cli(fd, "----------------------\n");
- ast_cli(fd, " Realtime Peers: %s\n", realtimepeers ? "Yes" : "No");
- ast_cli(fd, " Realtime Users: %s\n", realtimeusers ? "Yes" : "No");
- ast_cli(fd, " Cache Friends: %s\n", ast_test_flag(&global_flags_page2, SIP_PAGE2_RTCACHEFRIENDS) ? "Yes" : "No");
- ast_cli(fd, " Update: %s\n", ast_test_flag(&global_flags_page2, SIP_PAGE2_RTUPDATE) ? "Yes" : "No");
- ast_cli(fd, " Ignore Reg. Expire: %s\n", ast_test_flag(&global_flags_page2, SIP_PAGE2_IGNOREREGEXPIRE) ? "Yes" : "No");
- ast_cli(fd, " Auto Clear: %d\n", global_rtautoclear);
- }
- ast_cli(fd, "\n----\n");
- return RESULT_SUCCESS;
-}
-
-/*! \brief subscription_type2str: Show subscription type in string format */
-static const char *subscription_type2str(enum subscriptiontype subtype) {
- int i;
-
- for (i = 1; (i < (sizeof(subscription_types) / sizeof(subscription_types[0]))); i++) {
- if (subscription_types[i].type == subtype) {
- return subscription_types[i].text;
- }
- }
- return subscription_types[0].text;
-}
-
-/*! \brief find_subscription_type: Find subscription type in array */
-static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype) {
- int i;
-
- for (i = 1; (i < (sizeof(subscription_types) / sizeof(subscription_types[0]))); i++) {
- if (subscription_types[i].type == subtype) {
- return &subscription_types[i];
- }
- }
- return &subscription_types[0];
-}
-
-/* Forward declaration */
-static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions);
-
-/*! \brief sip_show_channels: Show active SIP channels ---*/
-static int sip_show_channels(int fd, int argc, char *argv[])
-{
- return __sip_show_channels(fd, argc, argv, 0);
-}
-
-/*! \brief sip_show_subscriptions: Show active SIP subscriptions ---*/
-static int sip_show_subscriptions(int fd, int argc, char *argv[])
-{
- return __sip_show_channels(fd, argc, argv, 1);
-}
-
-static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions)
-{
-#define FORMAT3 "%-15.15s %-10.10s %-11.11s %-15.15s %-13.13s %-15.15s\n"
-#define FORMAT2 "%-15.15s %-10.10s %-11.11s %-11.11s %-4.4s %-7.7s %-15.15s\n"
-#define FORMAT "%-15.15s %-10.10s %-11.11s %5.5d/%5.5d %-4.4s %-3.3s %-3.3s %-15.15s\n"
- struct sip_pvt *cur;
- char iabuf[INET_ADDRSTRLEN];
- int numchans = 0;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&iflock);
- cur = iflist;
- if (!subscriptions)
- ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
- else
- ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type");
- while (cur) {
- if (cur->subscribed == NONE && !subscriptions) {
- ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr),
- ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username,
- cur->callid,
- cur->ocseq, cur->icseq,
- ast_getformatname(cur->owner ? cur->owner->nativeformats : 0),
- ast_test_flag(cur, SIP_CALL_ONHOLD) ? "Yes" : "No",
- ast_test_flag(cur, SIP_NEEDDESTROY) ? "(d)" : "",
- cur->lastmsg );
- numchans++;
- }
- if (cur->subscribed != NONE && subscriptions) {
- ast_cli(fd, FORMAT3, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr),
- ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username,
- cur->callid, cur->exten, ast_extension_state2str(cur->laststate),
- subscription_type2str(cur->subscribed));
- numchans++;
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&iflock);
- if (!subscriptions)
- ast_cli(fd, "%d active SIP channel%s\n", numchans, (numchans != 1) ? "s" : "");
- else
- ast_cli(fd, "%d active SIP subscription%s\n", numchans, (numchans != 1) ? "s" : "");
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-#undef FORMAT3
-}
-
-/*! \brief complete_sipch: Support routine for 'sip show channel' CLI ---*/
-static char *complete_sipch(char *line, char *word, int pos, int state)
-{
- int which=0;
- struct sip_pvt *cur;
- char *c = NULL;
-
- ast_mutex_lock(&iflock);
- cur = iflist;
- while(cur) {
- if (!strncasecmp(word, cur->callid, strlen(word))) {
- if (++which > state) {
- c = strdup(cur->callid);
- break;
- }
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&iflock);
- return c;
-}
-
-/*! \brief complete_sip_peer: Do completion on peer name ---*/
-static char *complete_sip_peer(char *word, int state, int flags2)
-{
- char *result = NULL;
- int wordlen = strlen(word);
- int which = 0;
-
- ASTOBJ_CONTAINER_TRAVERSE(&peerl, !result, do {
- /* locking of the object is not required because only the name and flags are being compared */
- if (!strncasecmp(word, iterator->name, wordlen)) {
- if (flags2 && !ast_test_flag((&iterator->flags_page2), flags2))
- continue;
- if (++which > state) {
- result = strdup(iterator->name);
- }
- }
- } while(0) );
- return result;
-}
-
-/*! \brief complete_sip_show_peer: Support routine for 'sip show peer' CLI ---*/
-static char *complete_sip_show_peer(char *line, char *word, int pos, int state)
-{
- if (pos == 3)
- return complete_sip_peer(word, state, 0);
-
- return NULL;
-}
-
-/*! \brief complete_sip_debug_peer: Support routine for 'sip debug peer' CLI ---*/
-static char *complete_sip_debug_peer(char *line, char *word, int pos, int state)
-{
- if (pos == 3)
- return complete_sip_peer(word, state, 0);
-
- return NULL;
-}
-
-/*! \brief complete_sip_user: Do completion on user name ---*/
-static char *complete_sip_user(char *word, int state, int flags2)
-{
- char *result = NULL;
- int wordlen = strlen(word);
- int which = 0;
-
- ASTOBJ_CONTAINER_TRAVERSE(&userl, !result, do {
- /* locking of the object is not required because only the name and flags are being compared */
- if (!strncasecmp(word, iterator->name, wordlen)) {
- if (flags2 && !ast_test_flag(&(iterator->flags_page2), flags2))
- continue;
- if (++which > state) {
- result = strdup(iterator->name);
- }
- }
- } while(0) );
- return result;
-}
-
-/*! \brief complete_sip_show_user: Support routine for 'sip show user' CLI ---*/
-static char *complete_sip_show_user(char *line, char *word, int pos, int state)
-{
- if (pos == 3)
- return complete_sip_user(word, state, 0);
-
- return NULL;
-}
-
-/*! \brief complete_sipnotify: Support routine for 'sip notify' CLI ---*/
-static char *complete_sipnotify(char *line, char *word, int pos, int state)
-{
- char *c = NULL;
-
- if (pos == 2) {
- int which = 0;
- char *cat;
-
- /* do completion for notify type */
-
- if (!notify_types)
- return NULL;
-
- cat = ast_category_browse(notify_types, NULL);
- while(cat) {
- if (!strncasecmp(word, cat, strlen(word))) {
- if (++which > state) {
- c = strdup(cat);
- break;
- }
- }
- cat = ast_category_browse(notify_types, cat);
- }
- return c;
- }
-
- if (pos > 2)
- return complete_sip_peer(word, state, 0);
-
- return NULL;
-}
-
-/*! \brief complete_sip_prune_realtime_peer: Support routine for 'sip prune realtime peer' CLI ---*/
-static char *complete_sip_prune_realtime_peer(char *line, char *word, int pos, int state)
-{
- if (pos == 4)
- return complete_sip_peer(word, state, SIP_PAGE2_RTCACHEFRIENDS);
- return NULL;
-}
-
-/*! \brief complete_sip_prune_realtime_user: Support routine for 'sip prune realtime user' CLI ---*/
-static char *complete_sip_prune_realtime_user(char *line, char *word, int pos, int state)
-{
- if (pos == 4)
- return complete_sip_user(word, state, SIP_PAGE2_RTCACHEFRIENDS);
-
- return NULL;
-}
-
-/*! \brief sip_show_channel: Show details of one call ---*/
-static int sip_show_channel(int fd, int argc, char *argv[])
-{
- struct sip_pvt *cur;
- char iabuf[INET_ADDRSTRLEN];
- size_t len;
- int found = 0;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- len = strlen(argv[3]);
- ast_mutex_lock(&iflock);
- cur = iflist;
- while(cur) {
- if (!strncasecmp(cur->callid, argv[3],len)) {
- ast_cli(fd,"\n");
- if (cur->subscribed != NONE)
- ast_cli(fd, " * Subscription (type: %s)\n", subscription_type2str(cur->subscribed));
- else
- ast_cli(fd, " * SIP Call\n");
- ast_cli(fd, " Direction: %s\n", ast_test_flag(cur, SIP_OUTGOING)?"Outgoing":"Incoming");
- ast_cli(fd, " Call-ID: %s\n", cur->callid);
- ast_cli(fd, " Our Codec Capability: %d\n", cur->capability);
- ast_cli(fd, " Non-Codec Capability: %d\n", cur->noncodeccapability);
- ast_cli(fd, " Their Codec Capability: %d\n", cur->peercapability);
- ast_cli(fd, " Joint Codec Capability: %d\n", cur->jointcapability);
- ast_cli(fd, " Format %s\n", ast_getformatname(cur->owner ? cur->owner->nativeformats : 0) );
- ast_cli(fd, " Theoretical Address: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), ntohs(cur->sa.sin_port));
- ast_cli(fd, " Received Address: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), cur->recv.sin_addr), ntohs(cur->recv.sin_port));
- ast_cli(fd, " NAT Support: %s\n", nat2str(ast_test_flag(cur, SIP_NAT)));
- ast_cli(fd, " Audio IP: %s %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), cur->redirip.sin_addr.s_addr ? cur->redirip.sin_addr : cur->ourip), cur->redirip.sin_addr.s_addr ? "(Outside bridge)" : "(local)" );
- ast_cli(fd, " Our Tag: %s\n", cur->tag);
- ast_cli(fd, " Their Tag: %s\n", cur->theirtag);
- ast_cli(fd, " SIP User agent: %s\n", cur->useragent);
- if (!ast_strlen_zero(cur->username))
- ast_cli(fd, " Username: %s\n", cur->username);
- if (!ast_strlen_zero(cur->peername))
- ast_cli(fd, " Peername: %s\n", cur->peername);
- if (!ast_strlen_zero(cur->uri))
- ast_cli(fd, " Original uri: %s\n", cur->uri);
- if (!ast_strlen_zero(cur->cid_num))
- ast_cli(fd, " Caller-ID: %s\n", cur->cid_num);
- ast_cli(fd, " Need Destroy: %d\n", ast_test_flag(cur, SIP_NEEDDESTROY));
- ast_cli(fd, " Last Message: %s\n", cur->lastmsg);
- ast_cli(fd, " Promiscuous Redir: %s\n", ast_test_flag(cur, SIP_PROMISCREDIR) ? "Yes" : "No");
- ast_cli(fd, " Route: %s\n", cur->route ? cur->route->hop : "N/A");
- ast_cli(fd, " DTMF Mode: %s\n", dtmfmode2str(ast_test_flag(cur, SIP_DTMF)));
- ast_cli(fd, " SIP Options: ");
- if (cur->sipoptions) {
- int x;
- for (x=0 ; (x < (sizeof(sip_options) / sizeof(sip_options[0]))); x++) {
- if (cur->sipoptions & sip_options[x].id)
- ast_cli(fd, "%s ", sip_options[x].text);
- }
- } else
- ast_cli(fd, "(none)\n");
- ast_cli(fd, "\n\n");
- found++;
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&iflock);
- if (!found)
- ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
- return RESULT_SUCCESS;
-}
-
-/*! \brief sip_show_history: Show history details of one call ---*/
-static int sip_show_history(int fd, int argc, char *argv[])
-{
- struct sip_pvt *cur;
- struct sip_history *hist;
- size_t len;
- int x;
- int found = 0;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- if (!recordhistory)
- ast_cli(fd, "\n***Note: History recording is currently DISABLED. Use 'sip history' to ENABLE.\n");
- len = strlen(argv[3]);
- ast_mutex_lock(&iflock);
- cur = iflist;
- while(cur) {
- if (!strncasecmp(cur->callid, argv[3], len)) {
- ast_cli(fd,"\n");
- if (cur->subscribed != NONE)
- ast_cli(fd, " * Subscription\n");
- else
- ast_cli(fd, " * SIP Call\n");
- x = 0;
- hist = cur->history;
- while(hist) {
- x++;
- ast_cli(fd, "%d. %s\n", x, hist->event);
- hist = hist->next;
- }
- if (!x)
- ast_cli(fd, "Call '%s' has no history\n", cur->callid);
- found++;
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&iflock);
- if (!found)
- ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
- return RESULT_SUCCESS;
-}
-
-/*! \brief dump_history: Dump SIP history to debug log file at end of
- lifespan for SIP dialog */
-void sip_dump_history(struct sip_pvt *dialog)
-{
- int x;
- struct sip_history *hist;
-
- if (!dialog)
- return;
-
- ast_log(LOG_DEBUG, "\n---------- SIP HISTORY for '%s' \n", dialog->callid);
- if (dialog->subscribed)
- ast_log(LOG_DEBUG, " * Subscription\n");
- else
- ast_log(LOG_DEBUG, " * SIP Call\n");
- x = 0;
- hist = dialog->history;
- while(hist) {
- x++;
- ast_log(LOG_DEBUG, " %d. %s\n", x, hist->event);
- hist = hist->next;
- }
- if (!x)
- ast_log(LOG_DEBUG, "Call '%s' has no history\n", dialog->callid);
- ast_log(LOG_DEBUG, "\n---------- END SIP HISTORY for '%s' \n", dialog->callid);
-
-}
-
-
-/*! \brief handle_request_info: Receive SIP INFO Message ---*/
-/* Doesn't read the duration of the DTMF signal */
-static void handle_request_info(struct sip_pvt *p, struct sip_request *req)
-{
- char buf[1024];
- unsigned int event;
- char *c;
-
- /* Need to check the media/type */
- if (!strcasecmp(get_header(req, "Content-Type"), "application/dtmf-relay") ||
- !strcasecmp(get_header(req, "Content-Type"), "application/vnd.nortelnetworks.digits")) {
-
- /* Try getting the "signal=" part */
- if (ast_strlen_zero(c = get_sdp(req, "Signal")) && ast_strlen_zero(c = get_sdp(req, "d"))) {
- ast_log(LOG_WARNING, "Unable to retrieve DTMF signal from INFO message from %s\n", p->callid);
- transmit_response(p, "200 OK", req); /* Should return error */
- return;
- } else {
- ast_copy_string(buf, c, sizeof(buf));
- }
-
- if (!p->owner) { /* not a PBX call */
- transmit_response(p, "481 Call leg/transaction does not exist", req);
- ast_set_flag(p, SIP_NEEDDESTROY);
- return;
- }
-
- if (ast_strlen_zero(buf)) {
- transmit_response(p, "200 OK", req);
- return;
- }
-
- if (buf[0] == '*')
- event = 10;
- else if (buf[0] == '#')
- event = 11;
- else if ((buf[0] >= 'A') && (buf[0] <= 'D'))
- event = 12 + buf[0] - 'A';
- else
- event = atoi(buf);
- if (event == 16) {
- /* send a FLASH event */
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH, };
- ast_queue_frame(p->owner, &f);
- if (sipdebug)
- ast_verbose("* DTMF-relay event received: FLASH\n");
- } else {
- /* send a DTMF event */
- struct ast_frame f = { AST_FRAME_DTMF, };
- if (event < 10) {
- f.subclass = '0' + event;
- } else if (event < 11) {
- f.subclass = '*';
- } else if (event < 12) {
- f.subclass = '#';
- } else if (event < 16) {
- f.subclass = 'A' + (event - 12);
- }
- ast_queue_frame(p->owner, &f);
- if (sipdebug)
- ast_verbose("* DTMF-relay event received: %c\n", f.subclass);
- }
- transmit_response(p, "200 OK", req);
- return;
- } else if (!strcasecmp(get_header(req, "Content-Type"), "application/media_control+xml")) {
- /* Eh, we'll just assume it's a fast picture update for now */
- if (p->owner)
- ast_queue_control(p->owner, AST_CONTROL_VIDUPDATE);
- transmit_response(p, "200 OK", req);
- return;
- } else if ((c = get_header(req, "X-ClientCode"))) {
- /* Client code (from SNOM phone) */
- if (ast_test_flag(p, SIP_USECLIENTCODE)) {
- if (p->owner && p->owner->cdr)
- ast_cdr_setuserfield(p->owner, c);
- if (p->owner && ast_bridged_channel(p->owner) && ast_bridged_channel(p->owner)->cdr)
- ast_cdr_setuserfield(ast_bridged_channel(p->owner), c);
- transmit_response(p, "200 OK", req);
- } else {
- transmit_response(p, "403 Unauthorized", req);
- }
- return;
- }
- /* Other type of INFO message, not really understood by Asterisk */
- /* if (get_msg_text(buf, sizeof(buf), req)) { */
-
- ast_log(LOG_WARNING, "Unable to parse INFO message from %s. Content %s\n", p->callid, buf);
- transmit_response(p, "415 Unsupported media type", req);
- return;
-}
-
-/*! \brief sip_do_debug: Enable SIP Debugging in CLI ---*/
-static int sip_do_debug_ip(int fd, int argc, char *argv[])
-{
- struct hostent *hp;
- struct ast_hostent ahp;
- char iabuf[INET_ADDRSTRLEN];
- int port = 0;
- char *p, *arg;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- arg = argv[3];
- p = strstr(arg, ":");
- if (p) {
- *p = '\0';
- p++;
- port = atoi(p);
- }
- hp = ast_gethostbyname(arg, &ahp);
- if (hp == NULL) {
- return RESULT_SHOWUSAGE;
- }
- debugaddr.sin_family = AF_INET;
- memcpy(&debugaddr.sin_addr, hp->h_addr, sizeof(debugaddr.sin_addr));
- debugaddr.sin_port = htons(port);
- if (port == 0)
- ast_cli(fd, "SIP Debugging Enabled for IP: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr));
- else
- ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr), port);
- sipdebug |= SIP_DEBUG_CONSOLE;
- return RESULT_SUCCESS;
-}
-
-/*! \brief sip_do_debug_peer: Turn on SIP debugging with peer mask */
-static int sip_do_debug_peer(int fd, int argc, char *argv[])
-{
- struct sip_peer *peer;
- char iabuf[INET_ADDRSTRLEN];
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- peer = find_peer(argv[3], NULL, 1);
- if (peer) {
- if (peer->addr.sin_addr.s_addr) {
- debugaddr.sin_family = AF_INET;
- memcpy(&debugaddr.sin_addr, &peer->addr.sin_addr, sizeof(debugaddr.sin_addr));
- debugaddr.sin_port = peer->addr.sin_port;
- ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr), ntohs(debugaddr.sin_port));
- sipdebug |= SIP_DEBUG_CONSOLE;
- } else
- ast_cli(fd, "Unable to get IP address of peer '%s'\n", argv[3]);
- ASTOBJ_UNREF(peer,sip_destroy_peer);
- } else
- ast_cli(fd, "No such peer '%s'\n", argv[3]);
- return RESULT_SUCCESS;
-}
-
-/*! \brief sip_do_debug: Turn on SIP debugging (CLI command) */
-static int sip_do_debug(int fd, int argc, char *argv[])
-{
- int oldsipdebug = sipdebug & SIP_DEBUG_CONSOLE;
- if (argc != 2) {
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- else if (strncmp(argv[2], "ip\0", 3) == 0)
- return sip_do_debug_ip(fd, argc, argv);
- else if (strncmp(argv[2], "peer\0", 5) == 0)
- return sip_do_debug_peer(fd, argc, argv);
- else return RESULT_SHOWUSAGE;
- }
- sipdebug |= SIP_DEBUG_CONSOLE;
- memset(&debugaddr, 0, sizeof(debugaddr));
- if (oldsipdebug)
- ast_cli(fd, "SIP Debugging re-enabled\n");
- else
- ast_cli(fd, "SIP Debugging enabled\n");
- return RESULT_SUCCESS;
-}
-
-/*! \brief sip_notify: Send SIP notify to peer */
-static int sip_notify(int fd, int argc, char *argv[])
-{
- struct ast_variable *varlist;
- int i;
-
- if (argc < 4)
- return RESULT_SHOWUSAGE;
-
- if (!notify_types) {
- ast_cli(fd, "No %s file found, or no types listed there\n", notify_config);
- return RESULT_FAILURE;
- }
-
- varlist = ast_variable_browse(notify_types, argv[2]);
-
- if (!varlist) {
- ast_cli(fd, "Unable to find notify type '%s'\n", argv[2]);
- return RESULT_FAILURE;
- }
-
- for (i = 3; i < argc; i++) {
- struct sip_pvt *p;
- struct sip_request req;
- struct ast_variable *var;
-
- p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY);
- if (!p) {
- ast_log(LOG_WARNING, "Unable to build sip pvt data for notify\n");
- return RESULT_FAILURE;
- }
-
- if (create_addr(p, argv[i])) {
- /* Maybe they're not registered, etc. */
- sip_destroy(p);
- ast_cli(fd, "Could not create address for '%s'\n", argv[i]);
- continue;
- }
-
- initreqprep(&req, p, SIP_NOTIFY);
-
- for (var = varlist; var; var = var->next)
- add_header(&req, var->name, var->value);
-
- add_blank_header(&req);
- /* Recalculate our side, and recalculate Call ID */
- if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
- memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- build_via(p, p->via, sizeof(p->via));
- build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
- ast_cli(fd, "Sending NOTIFY of type '%s' to '%s'\n", argv[2], argv[i]);
- transmit_sip_request(p, &req);
- sip_scheddestroy(p, 15000);
- }
-
- return RESULT_SUCCESS;
-}
-/*! \brief sip_do_history: Enable SIP History logging (CLI) ---*/
-static int sip_do_history(int fd, int argc, char *argv[])
-{
- if (argc != 2) {
- return RESULT_SHOWUSAGE;
- }
- recordhistory = 1;
- ast_cli(fd, "SIP History Recording Enabled (use 'sip show history')\n");
- return RESULT_SUCCESS;
-}
-
-/*! \brief sip_no_history: Disable SIP History logging (CLI) ---*/
-static int sip_no_history(int fd, int argc, char *argv[])
-{
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- recordhistory = 0;
- ast_cli(fd, "SIP History Recording Disabled\n");
- return RESULT_SUCCESS;
-}
-
-/*! \brief sip_no_debug: Disable SIP Debugging in CLI ---*/
-static int sip_no_debug(int fd, int argc, char *argv[])
-
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- sipdebug &= ~SIP_DEBUG_CONSOLE;
- ast_cli(fd, "SIP Debugging Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len);
-
-/*! \brief do_register_auth: Authenticate for outbound registration ---*/
-static int do_register_auth(struct sip_pvt *p, struct sip_request *req, char *header, char *respheader)
-{
- char digest[1024];
- p->authtries++;
- memset(digest,0,sizeof(digest));
- if (reply_digest(p, req, header, SIP_REGISTER, digest, sizeof(digest))) {
- /* There's nothing to use for authentication */
- /* No digest challenge in request */
- if (sip_debug_test_pvt(p) && p->registry)
- ast_verbose("No authentication challenge, sending blank registration to domain/host name %s\n", p->registry->hostname);
- /* No old challenge */
- return -1;
- }
- if (recordhistory) {
- char tmp[80];
- snprintf(tmp, sizeof(tmp), "Try: %d", p->authtries);
- append_history(p, "RegistryAuth", tmp);
- }
- if (sip_debug_test_pvt(p) && p->registry)
- ast_verbose("Responding to challenge, registration to domain/host name %s\n", p->registry->hostname);
- return transmit_register(p->registry, SIP_REGISTER, digest, respheader);
-}
-
-/*! \brief do_proxy_auth: Add authentication on outbound SIP packet ---*/
-static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, char *header, char *respheader, int sipmethod, int init)
-{
- char digest[1024];
-
- if (!p->options) {
- p->options = calloc(1, sizeof(*p->options));
- if (!p->options) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -2;
- }
- }
-
- p->authtries++;
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "Auth attempt %d on %s\n", p->authtries, sip_methods[sipmethod].text);
- memset(digest, 0, sizeof(digest));
- if (reply_digest(p, req, header, sipmethod, digest, sizeof(digest) )) {
- /* No way to authenticate */
- return -1;
- }
- /* Now we have a reply digest */
- p->options->auth = digest;
- p->options->authheader = respheader;
- return transmit_invite(p, sipmethod, sipmethod == SIP_INVITE, init);
-}
-
-/*! \brief reply_digest: reply to authentication for outbound registrations ---*/
-/* This is used for register= servers in sip.conf, SIP proxies we register
- with for receiving calls from. */
-/* Returns -1 if we have no auth */
-static int reply_digest(struct sip_pvt *p, struct sip_request *req,
- char *header, int sipmethod, char *digest, int digest_len)
-{
- char tmp[512];
- char *c;
- char oldnonce[256];
-
- /* table of recognised keywords, and places where they should be copied */
- const struct x {
- const char *key;
- char *dst;
- int dstlen;
- } *i, keys[] = {
- { "realm=", p->realm, sizeof(p->realm) },
- { "nonce=", p->nonce, sizeof(p->nonce) },
- { "opaque=", p->opaque, sizeof(p->opaque) },
- { "qop=", p->qop, sizeof(p->qop) },
- { "domain=", p->domain, sizeof(p->domain) },
- { NULL, NULL, 0 },
- };
-
- ast_copy_string(tmp, get_header(req, header), sizeof(tmp));
- if (ast_strlen_zero(tmp))
- return -1;
- if (strncasecmp(tmp, "Digest ", strlen("Digest "))) {
- ast_log(LOG_WARNING, "missing Digest.\n");
- return -1;
- }
- c = tmp + strlen("Digest ");
- for (i = keys; i->key != NULL; i++)
- i->dst[0] = '\0'; /* init all to empty strings */
- ast_copy_string(oldnonce, p->nonce, sizeof(oldnonce));
- while (c && *(c = ast_skip_blanks(c))) { /* lookup for keys */
- for (i = keys; i->key != NULL; i++) {
- char *src, *separator;
- if (strncasecmp(c, i->key, strlen(i->key)) != 0)
- continue;
- /* Found. Skip keyword, take text in quotes or up to the separator. */
- c += strlen(i->key);
- if (*c == '\"') {
- src = ++c;
- separator = "\"";
- } else {
- src = c;
- separator = ",";
- }
- strsep(&c, separator); /* clear separator and move ptr */
- ast_copy_string(i->dst, src, i->dstlen);
- break;
- }
- if (i->key == NULL) /* not found, try ',' */
- strsep(&c, ",");
- }
- /* Reset nonce count */
- if (strcmp(p->nonce, oldnonce))
- p->noncecount = 0;
-
- /* Save auth data for following registrations */
- if (p->registry) {
- struct sip_registry *r = p->registry;
-
- if (strcmp(r->nonce, p->nonce)) {
- ast_copy_string(r->realm, p->realm, sizeof(r->realm));
- ast_copy_string(r->nonce, p->nonce, sizeof(r->nonce));
- ast_copy_string(r->domain, p->domain, sizeof(r->domain));
- ast_copy_string(r->opaque, p->opaque, sizeof(r->opaque));
- ast_copy_string(r->qop, p->qop, sizeof(r->qop));
- r->noncecount = 0;
- }
- }
- return build_reply_digest(p, sipmethod, digest, digest_len);
-}
-
-/*! \brief build_reply_digest: Build reply digest ---*/
-/* Build digest challenge for authentication of peers (for registration)
- and users (for calls). Also used for authentication of CANCEL and BYE */
-/* Returns -1 if we have no auth */
-static int build_reply_digest(struct sip_pvt *p, int method, char* digest, int digest_len)
-{
- char a1[256];
- char a2[256];
- char a1_hash[256];
- char a2_hash[256];
- char resp[256];
- char resp_hash[256];
- char uri[256];
- char cnonce[80];
- char iabuf[INET_ADDRSTRLEN];
- char *username;
- char *secret;
- char *md5secret;
- struct sip_auth *auth = (struct sip_auth *) NULL; /* Realm authentication */
-
- if (!ast_strlen_zero(p->domain))
- ast_copy_string(uri, p->domain, sizeof(uri));
- else if (!ast_strlen_zero(p->uri))
- ast_copy_string(uri, p->uri, sizeof(uri));
- else
- snprintf(uri, sizeof(uri), "sip:%s@%s",p->username, ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr));
-
- snprintf(cnonce, sizeof(cnonce), "%08x", thread_safe_rand());
-
- /* Check if we have separate auth credentials */
- if ((auth = find_realm_authentication(authl, p->realm))) {
- username = auth->username;
- secret = auth->secret;
- md5secret = auth->md5secret;
- if (sipdebug)
- ast_log(LOG_DEBUG,"Using realm %s authentication for call %s\n", p->realm, p->callid);
- } else {
- /* No authentication, use peer or register= config */
- username = p->authname;
- secret = p->peersecret;
- md5secret = p->peermd5secret;
- }
- if (ast_strlen_zero(username)) /* We have no authentication */
- return -1;
-
-
- /* Calculate SIP digest response */
- snprintf(a1,sizeof(a1),"%s:%s:%s", username, p->realm, secret);
- snprintf(a2,sizeof(a2),"%s:%s", sip_methods[method].text, uri);
- if (!ast_strlen_zero(md5secret))
- ast_copy_string(a1_hash, md5secret, sizeof(a1_hash));
- else
- ast_md5_hash(a1_hash,a1);
- ast_md5_hash(a2_hash,a2);
-
- p->noncecount++;
- if (!ast_strlen_zero(p->qop))
- snprintf(resp,sizeof(resp),"%s:%s:%08x:%s:%s:%s", a1_hash, p->nonce, p->noncecount, cnonce, "auth", a2_hash);
- else
- snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, p->nonce, a2_hash);
- ast_md5_hash(resp_hash, resp);
- /* XXX We hard code our qop to "auth" for now. XXX */
- if (!ast_strlen_zero(p->qop))
- snprintf(digest, digest_len, "Digest username=\"%s\", realm=\"%s\", algorithm=MD5, uri=\"%s\", nonce=\"%s\", response=\"%s\", opaque=\"%s\", qop=auth, cnonce=\"%s\", nc=%08x", username, p->realm, uri, p->nonce, resp_hash, p->opaque, cnonce, p->noncecount);
- else
- snprintf(digest, digest_len, "Digest username=\"%s\", realm=\"%s\", algorithm=MD5, uri=\"%s\", nonce=\"%s\", response=\"%s\", opaque=\"%s\"", username, p->realm, uri, p->nonce, resp_hash, p->opaque);
-
- return 0;
-}
-
-static char show_domains_usage[] =
-"Usage: sip show domains\n"
-" Lists all configured SIP local domains.\n"
-" Asterisk only responds to SIP messages to local domains.\n";
-
-static char notify_usage[] =
-"Usage: sip notify <type> <peer> [<peer>...]\n"
-" Send a NOTIFY message to a SIP peer or peers\n"
-" Message types are defined in sip_notify.conf\n";
-
-static char show_users_usage[] =
-"Usage: sip show users [like <pattern>]\n"
-" Lists all known SIP users.\n"
-" Optional regular expression pattern is used to filter the user list.\n";
-
-static char show_user_usage[] =
-"Usage: sip show user <name> [load]\n"
-" Lists all details on one SIP user and the current status.\n"
-" Option \"load\" forces lookup of peer in realtime storage.\n";
-
-static char show_inuse_usage[] =
-"Usage: sip show inuse [all]\n"
-" List all SIP users and peers usage counters and limits.\n"
-" Add option \"all\" to show all devices, not only those with a limit.\n";
-
-static char show_channels_usage[] =
-"Usage: sip show channels\n"
-" Lists all currently active SIP channels.\n";
-
-static char show_channel_usage[] =
-"Usage: sip show channel <channel>\n"
-" Provides detailed status on a given SIP channel.\n";
-
-static char show_history_usage[] =
-"Usage: sip show history <channel>\n"
-" Provides detailed dialog history on a given SIP channel.\n";
-
-static char show_peers_usage[] =
-"Usage: sip show peers [like <pattern>]\n"
-" Lists all known SIP peers.\n"
-" Optional regular expression pattern is used to filter the peer list.\n";
-
-static char show_peer_usage[] =
-"Usage: sip show peer <name> [load]\n"
-" Lists all details on one SIP peer and the current status.\n"
-" Option \"load\" forces lookup of peer in realtime storage.\n";
-
-static char prune_realtime_usage[] =
-"Usage: sip prune realtime [peer|user] [<name>|all|like <pattern>]\n"
-" Prunes object(s) from the cache.\n"
-" Optional regular expression pattern is used to filter the objects.\n";
-
-static char show_reg_usage[] =
-"Usage: sip show registry\n"
-" Lists all registration requests and status.\n";
-
-static char debug_usage[] =
-"Usage: sip debug\n"
-" Enables dumping of SIP packets for debugging purposes\n\n"
-" sip debug ip <host[:PORT]>\n"
-" Enables dumping of SIP packets to and from host.\n\n"
-" sip debug peer <peername>\n"
-" Enables dumping of SIP packets to and from host.\n"
-" Require peer to be registered.\n";
-
-static char no_debug_usage[] =
-"Usage: sip no debug\n"
-" Disables dumping of SIP packets for debugging purposes\n";
-
-static char no_history_usage[] =
-"Usage: sip no history\n"
-" Disables recording of SIP dialog history for debugging purposes\n";
-
-static char history_usage[] =
-"Usage: sip history\n"
-" Enables recording of SIP dialog history for debugging purposes.\n"
-"Use 'sip show history' to view the history of a call number.\n";
-
-static char sip_reload_usage[] =
-"Usage: sip reload\n"
-" Reloads SIP configuration from sip.conf\n";
-
-static char show_subscriptions_usage[] =
-"Usage: sip show subscriptions\n"
-" Shows active SIP subscriptions for extension states\n";
-
-static char show_objects_usage[] =
-"Usage: sip show objects\n"
-" Shows status of known SIP objects\n";
-
-static char show_settings_usage[] =
-"Usage: sip show settings\n"
-" Provides detailed list of the configuration of the SIP channel.\n";
-
-
-
-/*! \brief func_header_read: Read SIP header (dialplan function) */
-static char *func_header_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- struct sip_pvt *p;
- char *content;
-
- if (!data) {
- ast_log(LOG_WARNING, "This function requires a header name.\n");
- return NULL;
- }
-
- ast_mutex_lock(&chan->lock);
- if (chan->type != channeltype) {
- ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n");
- ast_mutex_unlock(&chan->lock);
- return NULL;
- }
-
- p = chan->tech_pvt;
-
- /* If there is no private structure, this channel is no longer alive */
- if (!p) {
- ast_mutex_unlock(&chan->lock);
- return NULL;
- }
-
- content = get_header(&p->initreq, data);
-
- if (ast_strlen_zero(content)) {
- ast_mutex_unlock(&chan->lock);
- return NULL;
- }
-
- ast_copy_string(buf, content, len);
- ast_mutex_unlock(&chan->lock);
-
- return buf;
-}
-
-
-static struct ast_custom_function sip_header_function = {
- .name = "SIP_HEADER",
- .synopsis = "Gets or sets the specified SIP header",
- .syntax = "SIP_HEADER(<name>)",
- .read = func_header_read,
-};
-
-/*! \brief function_check_sipdomain: Dial plan function to check if domain is local */
-static char *func_check_sipdomain(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "CHECKSIPDOMAIN requires an argument - A domain name\n");
- return buf;
- }
- if (check_sip_domain(data, NULL, 0))
- ast_copy_string(buf, data, len);
- else
- buf[0] = '\0';
- return buf;
-}
-
-static struct ast_custom_function checksipdomain_function = {
- .name = "CHECKSIPDOMAIN",
- .synopsis = "Checks if domain is a local domain",
- .syntax = "CHECKSIPDOMAIN(<domain|IP>)",
- .read = func_check_sipdomain,
- .desc = "This function checks if the domain in the argument is configured\n"
- "as a local SIP domain that this Asterisk server is configured to handle.\n"
- "Returns the domain name if it is locally handled, otherwise an empty string.\n"
- "Check the domain= configuration in sip.conf\n",
-};
-
-
-/*! \brief function_sippeer: ${SIPPEER()} Dialplan function - reads peer data */
-static char *function_sippeer(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *ret = NULL;
- struct sip_peer *peer;
- char *peername, *colname;
- char iabuf[INET_ADDRSTRLEN];
-
- if (!(peername = ast_strdupa(data))) {
- ast_log(LOG_ERROR, "Memory Error!\n");
- return ret;
- }
-
- if ((colname = strchr(peername, ':'))) {
- *colname = '\0';
- colname++;
- } else {
- colname = "ip";
- }
- if (!(peer = find_peer(peername, NULL, 1)))
- return ret;
-
- if (!strcasecmp(colname, "ip")) {
- ast_copy_string(buf, peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "", len);
- } else if (!strcasecmp(colname, "status")) {
- peer_status(peer, buf, sizeof(buf));
- } else if (!strcasecmp(colname, "language")) {
- ast_copy_string(buf, peer->language, len);
- } else if (!strcasecmp(colname, "regexten")) {
- ast_copy_string(buf, peer->regexten, len);
- } else if (!strcasecmp(colname, "limit")) {
- snprintf(buf, len, "%d", peer->call_limit);
- } else if (!strcasecmp(colname, "curcalls")) {
- snprintf(buf, len, "%d", peer->inUse);
- } else if (!strcasecmp(colname, "useragent")) {
- ast_copy_string(buf, peer->useragent, len);
- } else if (!strcasecmp(colname, "mailbox")) {
- ast_copy_string(buf, peer->mailbox, len);
- } else if (!strcasecmp(colname, "context")) {
- ast_copy_string(buf, peer->context, len);
- } else if (!strcasecmp(colname, "expire")) {
- snprintf(buf, len, "%d", peer->expire);
- } else if (!strcasecmp(colname, "dynamic")) {
- ast_copy_string(buf, (ast_test_flag(peer, SIP_DYNAMIC) ? "yes" : "no"), len);
- } else if (!strcasecmp(colname, "callerid_name")) {
- ast_copy_string(buf, peer->cid_name, len);
- } else if (!strcasecmp(colname, "callerid_num")) {
- ast_copy_string(buf, peer->cid_num, len);
- } else if (!strcasecmp(colname, "codecs")) {
- ast_getformatname_multiple(buf, len -1, peer->capability);
- } else if (!strncasecmp(colname, "codec[", 6)) {
- char *codecnum, *ptr;
- int index = 0, codec = 0;
-
- codecnum = strchr(colname, '[');
- *codecnum = '\0';
- codecnum++;
- if ((ptr = strchr(codecnum, ']'))) {
- *ptr = '\0';
- }
- index = atoi(codecnum);
- if((codec = ast_codec_pref_index(&peer->prefs, index))) {
- ast_copy_string(buf, ast_getformatname(codec), len);
- }
- }
- ret = buf;
-
- ASTOBJ_UNREF(peer, sip_destroy_peer);
-
- return ret;
-}
-
-/* Structure to declare a dialplan function: SIPPEER */
-struct ast_custom_function sippeer_function = {
- .name = "SIPPEER",
- .synopsis = "Gets SIP peer information",
- .syntax = "SIPPEER(<peername>[:item])",
- .read = function_sippeer,
- .desc = "Valid items are:\n"
- "- ip (default) The IP address.\n"
- "- mailbox The configured mailbox.\n"
- "- context The configured context.\n"
- "- expire The epoch time of the next expire.\n"
- "- dynamic Is it dynamic? (yes/no).\n"
- "- callerid_name The configured Caller ID name.\n"
- "- callerid_num The configured Caller ID number.\n"
- "- codecs The configured codecs.\n"
- "- status Status (if qualify=yes).\n"
- "- regexten Registration extension\n"
- "- limit Call limit (call-limit)\n"
- "- curcalls Current amount of calls \n"
- " Only available if call-limit is set\n"
- "- language Default language for peer\n"
- "- useragent Current user agent id for peer\n"
- "- codec[x] Preferred codec index number 'x' (beginning with zero).\n"
- "\n"
-};
-
-/*! \brief function_sipchaninfo_read: ${SIPCHANINFO()} Dialplan function - reads sip channel data */
-static char *function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- struct sip_pvt *p;
- char iabuf[INET_ADDRSTRLEN];
-
- *buf = 0;
-
- if (!data) {
- ast_log(LOG_WARNING, "This function requires a parameter name.\n");
- return NULL;
- }
-
- ast_mutex_lock(&chan->lock);
- if (chan->type != channeltype) {
- ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n");
- ast_mutex_unlock(&chan->lock);
- return NULL;
- }
-
-/* ast_verbose("function_sipchaninfo_read: %s\n", data); */
- p = chan->tech_pvt;
-
- /* If there is no private structure, this channel is no longer alive */
- if (!p) {
- ast_mutex_unlock(&chan->lock);
- return NULL;
- }
-
- if (!strcasecmp(data, "peerip")) {
- ast_copy_string(buf, p->sa.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr) : "", len);
- } else if (!strcasecmp(data, "recvip")) {
- ast_copy_string(buf, p->recv.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr) : "", len);
- } else if (!strcasecmp(data, "from")) {
- ast_copy_string(buf, p->from, len);
- } else if (!strcasecmp(data, "uri")) {
- ast_copy_string(buf, p->uri, len);
- } else if (!strcasecmp(data, "useragent")) {
- ast_copy_string(buf, p->useragent, len);
- } else if (!strcasecmp(data, "peername")) {
- ast_copy_string(buf, p->peername, len);
- } else {
- ast_mutex_unlock(&chan->lock);
- return NULL;
- }
- ast_mutex_unlock(&chan->lock);
-
- return buf;
-}
-
-/* Structure to declare a dialplan function: SIPCHANINFO */
-static struct ast_custom_function sipchaninfo_function = {
- .name = "SIPCHANINFO",
- .synopsis = "Gets the specified SIP parameter from the current channel",
- .syntax = "SIPCHANINFO(item)",
- .read = function_sipchaninfo_read,
- .desc = "Valid items are:\n"
- "- peerip The IP address of the peer.\n"
- "- recvip The source IP address of the peer.\n"
- "- from The URI from the From: header.\n"
- "- uri The URI from the Contact: header.\n"
- "- useragent The useragent.\n"
- "- peername The name of the peer.\n"
-};
-
-
-
-/*! \brief parse_moved_contact: Parse 302 Moved temporalily response */
-static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req)
-{
- char tmp[256];
- char *s, *e;
- ast_copy_string(tmp, get_header(req, "Contact"), sizeof(tmp));
- s = get_in_brackets(tmp);
- e = strchr(s, ';');
- if (e)
- *e = '\0';
- if (ast_test_flag(p, SIP_PROMISCREDIR)) {
- if (!strncasecmp(s, "sip:", 4))
- s += 4;
- e = strchr(s, '/');
- if (e)
- *e = '\0';
- ast_log(LOG_DEBUG, "Found promiscuous redirection to 'SIP/%s'\n", s);
- if (p->owner)
- snprintf(p->owner->call_forward, sizeof(p->owner->call_forward), "SIP/%s", s);
- } else {
- e = strchr(tmp, '@');
- if (e)
- *e = '\0';
- e = strchr(tmp, '/');
- if (e)
- *e = '\0';
- if (!strncasecmp(s, "sip:", 4))
- s += 4;
- ast_log(LOG_DEBUG, "Found 302 Redirect to extension '%s'\n", s);
- if (p->owner)
- ast_copy_string(p->owner->call_forward, s, sizeof(p->owner->call_forward));
- }
-}
-
-/*! \brief check_pendings: Check pending actions on SIP call ---*/
-static void check_pendings(struct sip_pvt *p)
-{
- /* Go ahead and send bye at this point */
- if (ast_test_flag(p, SIP_PENDINGBYE)) {
- transmit_request_with_auth(p, SIP_BYE, 0, 1, 1);
- ast_set_flag(p, SIP_NEEDDESTROY);
- ast_clear_flag(p, SIP_NEEDREINVITE);
- } else if (ast_test_flag(p, SIP_NEEDREINVITE)) {
- ast_log(LOG_DEBUG, "Sending pending reinvite on '%s'\n", p->callid);
- /* Didn't get to reinvite yet, so do it now */
- transmit_reinvite_with_sdp(p);
- ast_clear_flag(p, SIP_NEEDREINVITE);
- }
-}
-
-/*! \brief handle_response_invite: Handle SIP response in dialogue ---*/
-static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
-{
- int outgoing = ast_test_flag(p, SIP_OUTGOING);
-
- if (option_debug > 3) {
- int reinvite = (p->owner && p->owner->_state == AST_STATE_UP);
- if (reinvite)
- ast_log(LOG_DEBUG, "SIP response %d to RE-invite on %s call %s\n", resp, outgoing ? "outgoing" : "incoming", p->callid);
- else
- ast_log(LOG_DEBUG, "SIP response %d to standard invite\n", resp);
- }
-
- if (ast_test_flag(p, SIP_ALREADYGONE)) { /* This call is already gone */
- ast_log(LOG_DEBUG, "Got response on call that is already terminated: %s (ignoring)\n", p->callid);
- return;
- }
-
- switch (resp) {
- case 100: /* Trying */
- sip_cancel_destroy(p);
- break;
- case 180: /* 180 Ringing */
- sip_cancel_destroy(p);
- if (!ignore && p->owner) {
- ast_queue_control(p->owner, AST_CONTROL_RINGING);
- if (p->owner->_state != AST_STATE_UP)
- ast_setstate(p->owner, AST_STATE_RINGING);
- }
- if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
- process_sdp(p, req);
- if (!ignore && p->owner) {
- /* Queue a progress frame only if we have SDP in 180 */
- ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
- }
- }
- break;
- case 183: /* Session progress */
- sip_cancel_destroy(p);
- if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
- process_sdp(p, req);
- }
- if (!ignore && p->owner) {
- /* Queue a progress frame */
- ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
- }
- break;
- case 200: /* 200 OK on invite - someone's answering our call */
- sip_cancel_destroy(p);
- p->authtries = 0;
- if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
- process_sdp(p, req);
-#ifdef SIP_MIDCOM
- if (m_cb) {
- if (!m_cb->handle_response_invite_hook(p)) {
- if (p->owner)
- ast_queue_hangup(p->owner);
- else
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- }
-#endif
- }
-
- /* Parse contact header for continued conversation */
- /* When we get 200 OK, we know which device (and IP) to contact for this call */
- /* This is important when we have a SIP proxy between us and the phone */
- if (outgoing) {
- parse_ok_contact(p, req);
-
- /* Save Record-Route for any later requests we make on this dialogue */
- build_route(p, req, 1);
- }
-
- if (!ignore && p->owner) {
- if (p->owner->_state != AST_STATE_UP) {
-#ifdef OSP_SUPPORT
- time(&p->ospstart);
-#endif
- ast_queue_control(p->owner, AST_CONTROL_ANSWER);
- } else { /* RE-invite */
- struct ast_frame af = { AST_FRAME_NULL, };
- ast_queue_frame(p->owner, &af);
- }
- } else {
- /* It's possible we're getting an ACK after we've tried to disconnect
- by sending CANCEL */
- /* THIS NEEDS TO BE CHECKED: OEJ */
- if (!ignore)
- ast_set_flag(p, SIP_PENDINGBYE);
- }
- /* If I understand this right, the branch is different for a non-200 ACK only */
- transmit_request(p, SIP_ACK, seqno, 0, 1);
- check_pendings(p);
- break;
- case 407: /* Proxy authentication */
- case 401: /* Www auth */
- /* First we ACK */
- transmit_request(p, SIP_ACK, seqno, 0, 0);
- if (p->options)
- p->options->auth_type = (resp == 401 ? WWW_AUTH : PROXY_AUTH);
-
- /* Then we AUTH */
- p->theirtag[0]='\0'; /* forget their old tag, so we don't match tags when getting response */
- if (!ignore) {
- char *authenticate = (resp == 401 ? "WWW-Authenticate" : "Proxy-Authenticate");
- char *authorization = (resp == 401 ? "Authorization" : "Proxy-Authorization");
- if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, authenticate, authorization, SIP_INVITE, 1)) {
- ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From"));
- ast_set_flag(p, SIP_NEEDDESTROY);
- ast_set_flag(p, SIP_ALREADYGONE);
- if (p->owner)
- ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- }
- }
- break;
- case 403: /* Forbidden */
- /* First we ACK */
- transmit_request(p, SIP_ACK, seqno, 0, 0);
- ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for INVITE to '%s'\n", get_header(&p->initreq, "From"));
- if (!ignore && p->owner)
- ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- ast_set_flag(p, SIP_NEEDDESTROY);
- ast_set_flag(p, SIP_ALREADYGONE);
- break;
- case 404: /* Not found */
- transmit_request(p, SIP_ACK, seqno, 0, 0);
- if (p->owner && !ignore)
- ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- ast_set_flag(p, SIP_ALREADYGONE);
- break;
- case 481: /* Call leg does not exist */
- /* Could be REFER or INVITE */
- ast_log(LOG_WARNING, "Re-invite to non-existing call leg on other UA. SIP dialog '%s'. Giving up.\n", p->callid);
- transmit_request(p, SIP_ACK, seqno, 0, 0);
- break;
- case 491: /* Pending */
- /* we have to wait a while, then retransmit */
- /* Transmission is rescheduled, so everything should be taken care of.
- We should support the retry-after at some point */
- break;
- case 501: /* Not implemented */
- if (p->owner)
- ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- break;
- }
-}
-
-/*! \brief handle_response_register: Handle responses on REGISTER to services ---*/
-static int handle_response_register(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
-{
- int expires, expires_ms;
- struct sip_registry *r;
- r=p->registry;
-
- switch (resp) {
- case 401: /* Unauthorized */
- if ((p->authtries == MAX_AUTHTRIES) || do_register_auth(p, req, "WWW-Authenticate", "Authorization")) {
- ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s@%s' (Tries %d)\n", p->registry->username, p->registry->hostname, p->authtries);
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- break;
- case 403: /* Forbidden */
- ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for REGISTER for '%s' to '%s'\n", p->registry->username, p->registry->hostname);
- if (global_regattempts_max)
- p->registry->regattempts = global_regattempts_max+1;
- ast_sched_del(sched, r->timeout);
- ast_set_flag(p, SIP_NEEDDESTROY);
- break;
- case 404: /* Not found */
- ast_log(LOG_WARNING, "Got 404 Not found on SIP register to service %s@%s, giving up\n", p->registry->username,p->registry->hostname);
- if (global_regattempts_max)
- p->registry->regattempts = global_regattempts_max+1;
- ast_set_flag(p, SIP_NEEDDESTROY);
- r->call = NULL;
- ast_sched_del(sched, r->timeout);
- break;
- case 407: /* Proxy auth */
- if ((p->authtries == MAX_AUTHTRIES) || do_register_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization")) {
- ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s' (tries '%d')\n", get_header(&p->initreq, "From"), p->authtries);
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- break;
- case 479: /* SER: Not able to process the URI - address is wrong in register*/
- ast_log(LOG_WARNING, "Got error 479 on register to %s@%s, giving up (check config)\n", p->registry->username,p->registry->hostname);
- if (global_regattempts_max)
- p->registry->regattempts = global_regattempts_max+1;
- ast_set_flag(p, SIP_NEEDDESTROY);
- r->call = NULL;
- ast_sched_del(sched, r->timeout);
- break;
- case 200: /* 200 OK */
- if (!r) {
- ast_log(LOG_WARNING, "Got 200 OK on REGISTER that isn't a register\n");
- ast_set_flag(p, SIP_NEEDDESTROY);
- return 0;
- }
-
- r->regstate=REG_STATE_REGISTERED;
- manager_event(EVENT_FLAG_SYSTEM, "Registry", "Channel: SIP\r\nDomain: %s\r\nStatus: %s\r\n", r->hostname, regstate2str(r->regstate));
- r->regattempts = 0;
- ast_log(LOG_DEBUG, "Registration successful\n");
- if (r->timeout > -1) {
- ast_log(LOG_DEBUG, "Cancelling timeout %d\n", r->timeout);
- ast_sched_del(sched, r->timeout);
- }
- r->timeout=-1;
- r->call = NULL;
- p->registry = NULL;
- /* Let this one hang around until we have all the responses */
- sip_scheddestroy(p, 32000);
- /* ast_set_flag(p, SIP_NEEDDESTROY); */
-
- /* set us up for re-registering */
- /* figure out how long we got registered for */
- if (r->expire > -1)
- ast_sched_del(sched, r->expire);
- /* according to section 6.13 of RFC, contact headers override
- expires headers, so check those first */
- expires = 0;
- if (!ast_strlen_zero(get_header(req, "Contact"))) {
- char *contact = NULL;
- char *tmptmp = NULL;
- int start = 0;
- for(;;) {
- contact = __get_header(req, "Contact", &start);
- /* this loop ensures we get a contact header about our register request */
- if(!ast_strlen_zero(contact)) {
- if( (tmptmp=strstr(contact, p->our_contact))) {
- contact=tmptmp;
- break;
- }
- } else
- break;
- }
- tmptmp = strcasestr(contact, "expires=");
- if (tmptmp) {
- if (sscanf(tmptmp + 8, "%d;", &expires) != 1)
- expires = 0;
- }
-
- }
- if (!expires)
- expires=atoi(get_header(req, "expires"));
- if (!expires)
- expires=default_expiry;
-
- expires_ms = expires * 1000;
- if (expires <= EXPIRY_GUARD_LIMIT)
- expires_ms -= MAX((expires_ms * EXPIRY_GUARD_PCT),EXPIRY_GUARD_MIN);
- else
- expires_ms -= EXPIRY_GUARD_SECS * 1000;
- if (sipdebug)
- ast_log(LOG_NOTICE, "Outbound Registration: Expiry for %s is %d sec (Scheduling reregistration in %d s)\n", r->hostname, expires, expires_ms/1000);
-
- r->refresh= (int) expires_ms / 1000;
-
- /* Schedule re-registration before we expire */
- r->expire=ast_sched_add(sched, expires_ms, sip_reregister, r);
- ASTOBJ_UNREF(r, sip_registry_destroy);
- }
- return 1;
-}
-
-/*! \brief handle_response_peerpoke: Handle qualification responses (OPTIONS) */
-static int handle_response_peerpoke(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno, int sipmethod)
-{
- struct sip_peer *peer;
- int pingtime;
- struct timeval tv;
-
- if (resp != 100) {
- int statechanged = 0;
- int newstate = 0;
- peer = p->peerpoke;
- gettimeofday(&tv, NULL);
- pingtime = ast_tvdiff_ms(tv, peer->ps);
- if (pingtime < 1)
- pingtime = 1;
- if ((peer->lastms < 0) || (peer->lastms > peer->maxms)) {
- if (pingtime <= peer->maxms) {
- ast_log(LOG_NOTICE, "Peer '%s' is now REACHABLE! (%dms / %dms)\n", peer->name, pingtime, peer->maxms);
- statechanged = 1;
- newstate = 1;
- }
- } else if ((peer->lastms > 0) && (peer->lastms <= peer->maxms)) {
- if (pingtime > peer->maxms) {
- ast_log(LOG_NOTICE, "Peer '%s' is now TOO LAGGED! (%dms / %dms)\n", peer->name, pingtime, peer->maxms);
- statechanged = 1;
- newstate = 2;
- }
- }
- if (!peer->lastms)
- statechanged = 1;
- peer->lastms = pingtime;
- peer->call = NULL;
- if (statechanged) {
- ast_device_state_changed("SIP/%s", peer->name);
- if (newstate == 2) {
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Lagged\r\nTime: %d\r\n", peer->name, pingtime);
- } else {
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Reachable\r\nTime: %d\r\n", peer->name, pingtime);
- }
- }
-
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
- if (sipmethod == SIP_INVITE) /* Does this really happen? */
- transmit_request(p, SIP_ACK, seqno, 0, 0);
- ast_set_flag(p, SIP_NEEDDESTROY);
-
- /* Try again eventually */
- if ((peer->lastms < 0) || (peer->lastms > peer->maxms))
- peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
- else
- peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_OK, sip_poke_peer_s, peer);
- }
- return 1;
-}
-
-/*! \brief handle_response: Handle SIP response in dialogue ---*/
-static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
-{
- char *msg, *c;
- struct ast_channel *owner;
- char iabuf[INET_ADDRSTRLEN];
- int sipmethod;
- int res = 1;
-
- c = get_header(req, "Cseq");
- msg = strchr(c, ' ');
- if (!msg)
- msg = "";
- else
- msg++;
- sipmethod = find_sip_method(msg);
-
- owner = p->owner;
- if (owner)
- owner->hangupcause = hangup_sip2cause(resp);
-
- /* Acknowledge whatever it is destined for */
- if ((resp >= 100) && (resp <= 199))
- __sip_semi_ack(p, seqno, 0, sipmethod);
- else
- __sip_ack(p, seqno, 0, sipmethod);
-
- /* Get their tag if we haven't already */
- if (ast_strlen_zero(p->theirtag) || (resp >= 200)) {
- gettag(req, "To", p->theirtag, sizeof(p->theirtag));
- }
- if (p->peerpoke) {
- /* We don't really care what the response is, just that it replied back.
- Well, as long as it's not a 100 response... since we might
- need to hang around for something more "definitive" */
-
- res = handle_response_peerpoke(p, resp, rest, req, ignore, seqno, sipmethod);
- } else if (ast_test_flag(p, SIP_OUTGOING)) {
- /* Acknowledge sequence number */
- if (p->initid > -1) {
- /* Don't auto congest anymore since we've gotten something useful back */
- ast_sched_del(sched, p->initid);
- p->initid = -1;
- }
- switch(resp) {
- case 100: /* 100 Trying */
- if (sipmethod == SIP_INVITE)
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- break;
- case 183: /* 183 Session Progress */
- if (sipmethod == SIP_INVITE)
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- break;
- case 180: /* 180 Ringing */
- if (sipmethod == SIP_INVITE)
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- break;
- case 200: /* 200 OK */
- p->authtries = 0; /* Reset authentication counter */
- if (sipmethod == SIP_MESSAGE) {
- /* We successfully transmitted a message */
- ast_set_flag(p, SIP_NEEDDESTROY);
- } else if (sipmethod == SIP_NOTIFY) {
- /* They got the notify, this is the end */
- if (p->owner) {
- ast_log(LOG_WARNING, "Notify answer on an owned channel?\n");
- ast_queue_hangup(p->owner);
- } else {
- if (p->subscribed == NONE) {
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- }
- } else if (sipmethod == SIP_INVITE) {
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- } else if (sipmethod == SIP_REGISTER) {
- res = handle_response_register(p, resp, rest, req, ignore, seqno);
- }
- break;
- case 401: /* Not www-authorized on SIP method */
- if (sipmethod == SIP_INVITE) {
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- } else if (p->registry && sipmethod == SIP_REGISTER) {
- res = handle_response_register(p, resp, rest, req, ignore, seqno);
- } else {
- ast_log(LOG_WARNING, "Got authentication request (401) on unknown %s to '%s'\n", sip_methods[sipmethod].text, get_header(req, "To"));
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- break;
- case 403: /* Forbidden - we failed authentication */
- if (sipmethod == SIP_INVITE) {
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- } else if (p->registry && sipmethod == SIP_REGISTER) {
- res = handle_response_register(p, resp, rest, req, ignore, seqno);
- } else {
- ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for %s\n", msg);
- }
- break;
- case 404: /* Not found */
- if (p->registry && sipmethod == SIP_REGISTER) {
- res = handle_response_register(p, resp, rest, req, ignore, seqno);
- } else if (sipmethod == SIP_INVITE) {
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- } else if (owner)
- ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- break;
- case 407: /* Proxy auth required */
- if (sipmethod == SIP_INVITE) {
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- } else if (sipmethod == SIP_BYE || sipmethod == SIP_REFER) {
- if (ast_strlen_zero(p->authname))
- ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n",
- msg, ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port));
- ast_set_flag(p, SIP_NEEDDESTROY);
- if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", sipmethod, 0)) {
- ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From"));
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- } else if (p->registry && sipmethod == SIP_REGISTER) {
- res = handle_response_register(p, resp, rest, req, ignore, seqno);
- } else /* We can't handle this, giving up in a bad way */
- ast_set_flag(p, SIP_NEEDDESTROY);
-
- break;
- case 491: /* Pending */
- if (sipmethod == SIP_INVITE) {
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- }
- case 501: /* Not Implemented */
- if (sipmethod == SIP_INVITE) {
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- } else
- ast_log(LOG_WARNING, "Host '%s' does not implement '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), msg);
- break;
- default:
- if ((resp >= 300) && (resp < 700)) {
- if ((option_verbose > 2) && (resp != 487))
- ast_verbose(VERBOSE_PREFIX_3 "Got SIP response %d \"%s\" back from %s\n", resp, rest, ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr));
- ast_set_flag(p, SIP_ALREADYGONE);
- if (p->rtp) {
- /* Immediately stop RTP */
- ast_rtp_stop(p->rtp);
- }
- if (p->vrtp) {
- /* Immediately stop VRTP */
- ast_rtp_stop(p->vrtp);
- }
- /* XXX Locking issues?? XXX */
- switch(resp) {
- case 300: /* Multiple Choices */
- case 301: /* Moved permenantly */
- case 302: /* Moved temporarily */
- case 305: /* Use Proxy */
- parse_moved_contact(p, req);
- /* Fall through */
- case 486: /* Busy here */
- case 600: /* Busy everywhere */
- case 603: /* Decline */
- if (p->owner)
- ast_queue_control(p->owner, AST_CONTROL_BUSY);
- break;
- case 487:
- /* channel now destroyed - dec the inUse counter */
- update_call_counter(p, DEC_CALL_LIMIT);
- break;
- case 482: /* SIP is incapable of performing a hairpin call, which
- is yet another failure of not having a layer 2 (again, YAY
- IETF for thinking ahead). So we treat this as a call
- forward and hope we end up at the right place... */
- ast_log(LOG_DEBUG, "Hairpin detected, setting up call forward for what it's worth\n");
- if (p->owner)
- snprintf(p->owner->call_forward, sizeof(p->owner->call_forward), "Local/%s@%s", p->username, p->context);
- /* Fall through */
- case 488: /* Not acceptable here - codec error */
- case 480: /* Temporarily Unavailable */
- case 404: /* Not Found */
- case 410: /* Gone */
- case 400: /* Bad Request */
- case 500: /* Server error */
- case 503: /* Service Unavailable */
- if (owner)
- ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- break;
- default:
- /* Send hangup */
- if (owner)
- ast_queue_hangup(p->owner);
- break;
- }
- /* ACK on invite */
- if (sipmethod == SIP_INVITE)
- transmit_request(p, SIP_ACK, seqno, 0, 0);
- ast_set_flag(p, SIP_ALREADYGONE);
- if (!p->owner)
- ast_set_flag(p, SIP_NEEDDESTROY);
- } else if ((resp >= 100) && (resp < 200)) {
- if (sipmethod == SIP_INVITE) {
- sip_cancel_destroy(p);
- if (!ast_strlen_zero(get_header(req, "Content-Type")))
- process_sdp(p, req);
- if (p->owner) {
- /* Queue a progress frame */
- ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
- }
- }
- } else
- ast_log(LOG_NOTICE, "Dont know how to handle a %d %s response from %s\n", resp, rest, p->owner ? p->owner->name : ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr));
- }
- } else {
- /* Responses to OUTGOING SIP requests on INCOMING calls
- get handled here. As well as out-of-call message responses */
- if (req->debug)
- ast_verbose("SIP Response message for INCOMING dialog %s arrived\n", msg);
- if (resp == 200) {
- /* Tags in early session is replaced by the tag in 200 OK, which is
- the final reply to our INVITE */
- gettag(req, "To", p->theirtag, sizeof(p->theirtag));
- }
-
- switch(resp) {
- case 200:
- if (sipmethod == SIP_INVITE) {
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- } else if (sipmethod == SIP_CANCEL) {
- ast_log(LOG_DEBUG, "Got 200 OK on CANCEL\n");
- } else if (sipmethod == SIP_MESSAGE)
- /* We successfully transmitted a message */
- ast_set_flag(p, SIP_NEEDDESTROY);
- break;
- case 401: /* www-auth */
- case 407:
- if (sipmethod == SIP_BYE || sipmethod == SIP_REFER) {
- char *auth, *auth2;
-
- if (resp == 407) {
- auth = "Proxy-Authenticate";
- auth2 = "Proxy-Authorization";
- } else {
- auth = "WWW-Authenticate";
- auth2 = "Authorization";
- }
- if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, auth, auth2, sipmethod, 0)) {
- ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From"));
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- } else if (sipmethod == SIP_INVITE) {
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- }
- break;
- case 481: /* Call leg does not exist */
- if (sipmethod == SIP_INVITE) {
- /* Re-invite failed */
- handle_response_invite(p, resp, rest, req, ignore, seqno);
- }
- break;
- default: /* Errors without handlers */
- if ((resp >= 100) && (resp < 200)) {
- if (sipmethod == SIP_INVITE) { /* re-invite */
- sip_cancel_destroy(p);
- }
- }
- if ((resp >= 300) && (resp < 700)) {
- if ((option_verbose > 2) && (resp != 487))
- ast_verbose(VERBOSE_PREFIX_3 "Incoming call: Got SIP response %d \"%s\" back from %s\n", resp, rest, ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr));
- switch(resp) {
- case 488: /* Not acceptable here - codec error */
- case 603: /* Decline */
- case 500: /* Server error */
- case 503: /* Service Unavailable */
-
- if (sipmethod == SIP_INVITE) { /* re-invite failed */
- sip_cancel_destroy(p);
- }
- break;
- }
- }
- break;
- }
- }
-}
-
-struct sip_dual {
- struct ast_channel *chan1;
- struct ast_channel *chan2;
- struct sip_request req;
-};
-
-/*! \brief sip_park_thread: Park SIP call support function */
-static void *sip_park_thread(void *stuff)
-{
- struct ast_channel *chan1, *chan2;
- struct sip_dual *d;
- struct sip_request req;
- int ext;
- int res;
- d = stuff;
- chan1 = d->chan1;
- chan2 = d->chan2;
- copy_request(&req, &d->req);
- free(d);
- ast_mutex_lock(&chan1->lock);
- ast_do_masquerade(chan1);
- ast_mutex_unlock(&chan1->lock);
- res = ast_park_call(chan1, chan2, 0, &ext);
- /* Then hangup */
- ast_hangup(chan2);
- ast_log(LOG_DEBUG, "Parked on extension '%d'\n", ext);
- return NULL;
-}
-
-/*! \brief sip_park: Park a call ---*/
-static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req)
-{
- struct sip_dual *d;
- struct ast_channel *chan1m, *chan2m;
- pthread_t th;
- chan1m = ast_channel_alloc(0);
- chan2m = ast_channel_alloc(0);
- if ((!chan2m) || (!chan1m)) {
- if (chan1m)
- ast_hangup(chan1m);
- if (chan2m)
- ast_hangup(chan2m);
- return -1;
- }
- snprintf(chan1m->name, sizeof(chan1m->name), "Parking/%s", chan1->name);
- /* Make formats okay */
- chan1m->readformat = chan1->readformat;
- chan1m->writeformat = chan1->writeformat;
- ast_channel_masquerade(chan1m, chan1);
- /* Setup the extensions and such */
- ast_copy_string(chan1m->context, chan1->context, sizeof(chan1m->context));
- ast_copy_string(chan1m->exten, chan1->exten, sizeof(chan1m->exten));
- chan1m->priority = chan1->priority;
-
- /* We make a clone of the peer channel too, so we can play
- back the announcement */
- snprintf(chan2m->name, sizeof (chan2m->name), "SIPPeer/%s",chan2->name);
- /* Make formats okay */
- chan2m->readformat = chan2->readformat;
- chan2m->writeformat = chan2->writeformat;
- ast_channel_masquerade(chan2m, chan2);
- /* Setup the extensions and such */
- ast_copy_string(chan2m->context, chan2->context, sizeof(chan2m->context));
- ast_copy_string(chan2m->exten, chan2->exten, sizeof(chan2m->exten));
- chan2m->priority = chan2->priority;
- ast_mutex_lock(&chan2m->lock);
- if (ast_do_masquerade(chan2m)) {
- ast_log(LOG_WARNING, "Masquerade failed :(\n");
- ast_mutex_unlock(&chan2m->lock);
- ast_hangup(chan2m);
- return -1;
- }
- ast_mutex_unlock(&chan2m->lock);
- d = malloc(sizeof(struct sip_dual));
- if (d) {
- memset(d, 0, sizeof(*d));
- /* Save original request for followup */
- copy_request(&d->req, req);
- d->chan1 = chan1m;
- d->chan2 = chan2m;
- if (!ast_pthread_create(&th, NULL, sip_park_thread, d))
- return 0;
- free(d);
- }
- return -1;
-}
-
-/*! \brief ast_quiet_chan: Turn off generator data */
-static void ast_quiet_chan(struct ast_channel *chan)
-{
- if (chan && chan->_state == AST_STATE_UP) {
- if (chan->generatordata)
- ast_deactivate_generator(chan);
- }
-}
-
-/*! \brief attempt_transfer: Attempt transfer of SIP call ---*/
-static int attempt_transfer(struct sip_pvt *p1, struct sip_pvt *p2)
-{
- int res = 0;
- struct ast_channel
- *chana = NULL,
- *chanb = NULL,
- *bridgea = NULL,
- *bridgeb = NULL,
- *peera = NULL,
- *peerb = NULL,
- *peerc = NULL,
- *peerd = NULL;
-
- if (!p1->owner || !p2->owner) {
- ast_log(LOG_WARNING, "Transfer attempted without dual ownership?\n");
- return -1;
- }
- chana = p1->owner;
- chanb = p2->owner;
- bridgea = ast_bridged_channel(chana);
- bridgeb = ast_bridged_channel(chanb);
-
- if (bridgea) {
- peera = chana;
- peerb = chanb;
- peerc = bridgea;
- peerd = bridgeb;
- } else if (bridgeb) {
- peera = chanb;
- peerb = chana;
- peerc = bridgeb;
- peerd = bridgea;
- }
-
- if (peera && peerb && peerc && (peerb != peerc)) {
- ast_quiet_chan(peera);
- ast_quiet_chan(peerb);
- ast_quiet_chan(peerc);
- ast_quiet_chan(peerd);
-
- if (peera->cdr && peerb->cdr) {
- peerb->cdr = ast_cdr_append(peerb->cdr, peera->cdr);
- } else if (peera->cdr) {
- peerb->cdr = peera->cdr;
- }
- peera->cdr = NULL;
-
- if (peerb->cdr && peerc->cdr) {
- peerb->cdr = ast_cdr_append(peerb->cdr, peerc->cdr);
- } else if (peerc->cdr) {
- peerb->cdr = peerc->cdr;
- }
- peerc->cdr = NULL;
-
- if (ast_channel_masquerade(peerb, peerc)) {
- ast_log(LOG_WARNING, "Failed to masquerade %s into %s\n", peerb->name, peerc->name);
- res = -1;
- }
- return res;
- } else {
- ast_log(LOG_NOTICE, "Transfer attempted with no appropriate bridged calls to transfer\n");
- if (chana)
- ast_softhangup_nolock(chana, AST_SOFTHANGUP_DEV);
- if (chanb)
- ast_softhangup_nolock(chanb, AST_SOFTHANGUP_DEV);
- return -1;
- }
- return 0;
-}
-
-/*! \brief gettag: Get tag from packet */
-static char *gettag(struct sip_request *req, char *header, char *tagbuf, int tagbufsize)
-{
-
- char *thetag, *sep;
-
-
- if (!tagbuf)
- return NULL;
- tagbuf[0] = '\0'; /* reset the buffer */
- thetag = get_header(req, header);
- thetag = strcasestr(thetag, ";tag=");
- if (thetag) {
- thetag += 5;
- ast_copy_string(tagbuf, thetag, tagbufsize);
- sep = strchr(tagbuf, ';');
- if (sep)
- *sep = '\0';
- }
- return thetag;
-}
-
-/*! \brief handle_request_options: Handle incoming OPTIONS request */
-static int handle_request_options(struct sip_pvt *p, struct sip_request *req, int debug)
-{
- int res;
-
- res = get_destination(p, req);
- build_contact(p);
- /* XXX Should we authenticate OPTIONS? XXX */
- if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
- if (res < 0)
- transmit_response_with_allow(p, "404 Not Found", req, 0);
- else if (res > 0)
- transmit_response_with_allow(p, "484 Address Incomplete", req, 0);
- else
- transmit_response_with_allow(p, "200 OK", req, 0);
- /* Destroy if this OPTIONS was the opening request, but not if
- it's in the middle of a normal call flow. */
- if (!p->lastinvite)
- ast_set_flag(p, SIP_NEEDDESTROY);
-
- return res;
-}
-
-/*! \brief handle_request_invite: Handle incoming INVITE request */
-static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int ignore, int seqno, struct sockaddr_in *sin, int *recount, char *e)
-{
- int res = 1;
- struct ast_channel *c=NULL;
- int gotdest;
- struct ast_frame af = { AST_FRAME_NULL, };
- char *supported;
- char *required;
- unsigned int required_profile = 0;
-
- /* Find out what they support */
- if (!p->sipoptions) {
- supported = get_header(req, "Supported");
- if (supported)
- parse_sip_options(p, supported);
- }
- required = get_header(req, "Required");
- if (!ast_strlen_zero(required)) {
- required_profile = parse_sip_options(NULL, required);
- if (required_profile) { /* They require something */
- /* At this point we support no extensions, so fail */
- transmit_response_with_unsupported(p, "420 Bad extension", req, required);
- if (!p->lastinvite)
- ast_set_flag(p, SIP_NEEDDESTROY);
- return -1;
-
- }
- }
-
- /* Check if this is a loop */
- /* This happens since we do not properly support SIP domain
- handling yet... -oej */
- if (ast_test_flag(p, SIP_OUTGOING) && p->owner && (p->owner->_state != AST_STATE_UP)) {
- /* This is a call to ourself. Send ourselves an error code and stop
- processing immediately, as SIP really has no good mechanism for
- being able to call yourself */
- transmit_response(p, "482 Loop Detected", req);
- /* We do NOT destroy p here, so that our response will be accepted */
- return 0;
- }
- if (!ignore) {
- /* Use this as the basis */
- if (debug)
- ast_verbose("Using INVITE request as basis request - %s\n", p->callid);
- sip_cancel_destroy(p);
- /* This call is no longer outgoing if it ever was */
- ast_clear_flag(p, SIP_OUTGOING);
- /* This also counts as a pending invite */
- p->pendinginvite = seqno;
- copy_request(&p->initreq, req);
- check_via(p, req);
- if (p->owner) {
- /* Handle SDP here if we already have an owner */
- if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
- if (process_sdp(p, req)) {
- transmit_response(p, "488 Not acceptable here", req);
- if (!p->lastinvite)
- ast_set_flag(p, SIP_NEEDDESTROY);
- return -1;
- }
- } else {
- p->jointcapability = p->capability;
- ast_log(LOG_DEBUG, "Hm.... No sdp for the moment\n");
- }
- }
- } else if (debug)
- ast_verbose("Ignoring this INVITE request\n");
- if (!p->lastinvite && !ignore && !p->owner) {
- /* Handle authentication if this is our first invite */
- res = check_user(p, req, SIP_INVITE, e, 1, sin, ignore);
- if (res) {
- if (res < 0) {
- ast_log(LOG_NOTICE, "Failed to authenticate user %s\n", get_header(req, "From"));
- if (ignore)
- transmit_response(p, "403 Forbidden", req);
- else
- transmit_response_reliable(p, "403 Forbidden", req, 1);
- ast_set_flag(p, SIP_NEEDDESTROY);
- p->theirtag[0] = '\0'; /* Forget their to-tag, we'll get a new one */
- }
- return 0;
- }
- /* Process the SDP portion */
- if (!ast_strlen_zero(get_header(req, "Content-Type"))) {
- if (process_sdp(p, req)) {
- transmit_response(p, "488 Not acceptable here", req);
- ast_set_flag(p, SIP_NEEDDESTROY);
- return -1;
- }
-#ifdef SIP_MIDCOM
- if (m_cb) {
- if (!m_cb->handle_request_invite_hook((void *)p)) {
- ast_log(LOG_NOTICE, "Failed to NAT for (%s)\n", get_header(req, "From"));
- if (ignore)
- transmit_response(p, "403 Forbidden", req);
- else
- transmit_response_reliable(p, "403 Forbidden", req, 1);
- ast_set_flag(p, SIP_NEEDDESTROY);
- return 0;
- }
- }
-#endif
- } else {
- p->jointcapability = p->capability;
- ast_log(LOG_DEBUG, "Hm.... No sdp for the moment\n");
- }
- /* Queue NULL frame to prod ast_rtp_bridge if appropriate */
- if (p->owner)
- ast_queue_frame(p->owner, &af);
- /* Initialize the context if it hasn't been already */
- if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
- /* Check number of concurrent calls -vs- incoming limit HERE */
- ast_log(LOG_DEBUG, "Checking SIP call limits for device %s\n", p->username);
- res = update_call_counter(p, INC_CALL_LIMIT);
- if (res) {
- if (res < 0) {
- ast_log(LOG_NOTICE, "Failed to place call for user %s, too many calls\n", p->username);
- if (ignore)
- transmit_response(p, "480 Temporarily Unavailable (Call limit)", req);
- else
- transmit_response_reliable(p, "480 Temporarily Unavailable (Call limit) ", req, 1);
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- return 0;
- }
- /* Get destination right away */
- gotdest = get_destination(p, NULL);
-
- get_rdnis(p, NULL);
- extract_uri(p, req);
- build_contact(p);
-
- if (gotdest) {
- if (gotdest < 0) {
- if (ignore)
- transmit_response(p, "404 Not Found", req);
- else
- transmit_response_reliable(p, "404 Not Found", req, 1);
- update_call_counter(p, DEC_CALL_LIMIT);
- } else {
- if (ignore)
- transmit_response(p, "484 Address Incomplete", req);
- else
- transmit_response_reliable(p, "484 Address Incomplete", req, 1);
- update_call_counter(p, DEC_CALL_LIMIT);
- }
- ast_set_flag(p, SIP_NEEDDESTROY);
- } else {
- /* If no extension was specified, use the s one */
- if (ast_strlen_zero(p->exten))
- ast_copy_string(p->exten, "s", sizeof(p->exten));
- /* Initialize tag */
- make_our_tag(p->tag, sizeof(p->tag));
- /* First invitation */
- c = sip_new(p, AST_STATE_DOWN, ast_strlen_zero(p->username) ? NULL : p->username );
- *recount = 1;
- /* Save Record-Route for any later requests we make on this dialogue */
- build_route(p, req, 0);
- if (c) {
- /* Pre-lock the call */
- ast_mutex_lock(&c->lock);
- }
- }
-
- } else {
- if (option_debug > 1 && sipdebug)
- ast_log(LOG_DEBUG, "Got a SIP re-invite for call %s\n", p->callid);
- c = p->owner;
- }
- if (!ignore && p)
- p->lastinvite = seqno;
- if (c) {
-#ifdef OSP_SUPPORT
- ast_channel_setwhentohangup (c, p->osptimelimit);
-#endif
- switch(c->_state) {
- case AST_STATE_DOWN:
- transmit_response(p, "100 Trying", req);
- ast_setstate(c, AST_STATE_RING);
- if (strcmp(p->exten, ast_pickup_ext())) {
- enum ast_pbx_result res;
-
- res = ast_pbx_start(c);
-
- switch (res) {
- case AST_PBX_FAILED:
- ast_log(LOG_WARNING, "Failed to start PBX :(\n");
- if (ignore)
- transmit_response(p, "503 Unavailable", req);
- else
- transmit_response_reliable(p, "503 Unavailable", req, 1);
- break;
- case AST_PBX_CALL_LIMIT:
- ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n");
- if (ignore)
- transmit_response(p, "480 Temporarily Unavailable", req);
- else
- transmit_response_reliable(p, "480 Temporarily Unavailable", req, 1);
- break;
- case AST_PBX_SUCCESS:
- /* nothing to do */
- break;
- }
-
- if (res) {
- ast_log(LOG_WARNING, "Failed to start PBX :(\n");
- /* Unlock locks so ast_hangup can do its magic */
- ast_mutex_unlock(&c->lock);
- ast_mutex_unlock(&p->lock);
- ast_hangup(c);
- ast_mutex_lock(&p->lock);
- c = NULL;
- }
- } else {
- ast_mutex_unlock(&c->lock);
- if (ast_pickup_call(c)) {
- ast_log(LOG_NOTICE, "Nothing to pick up\n");
- if (ignore)
- transmit_response(p, "503 Unavailable", req);
- else
- transmit_response_reliable(p, "503 Unavailable", req, 1);
- ast_set_flag(p, SIP_ALREADYGONE);
- /* Unlock locks so ast_hangup can do its magic */
- ast_mutex_unlock(&p->lock);
- ast_hangup(c);
- ast_mutex_lock(&p->lock);
- c = NULL;
- } else {
- ast_mutex_unlock(&p->lock);
- ast_setstate(c, AST_STATE_DOWN);
- ast_hangup(c);
- ast_mutex_lock(&p->lock);
- c = NULL;
- }
- }
- break;
- case AST_STATE_RING:
- transmit_response(p, "100 Trying", req);
- break;
- case AST_STATE_RINGING:
- transmit_response(p, "180 Ringing", req);
- break;
- case AST_STATE_UP:
- transmit_response_with_sdp(p, "200 OK", req, 1);
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to handle INVITE in state %d\n", c->_state);
- transmit_response(p, "100 Trying", req);
- }
- } else {
- if (p && !ast_test_flag(p, SIP_NEEDDESTROY) && !ignore) {
- if (!p->jointcapability) {
- if (ignore)
- transmit_response(p, "488 Not Acceptable Here (codec error)", req);
- else
- transmit_response_reliable(p, "488 Not Acceptable Here (codec error)", req, 1);
- ast_set_flag(p, SIP_NEEDDESTROY);
- } else {
- ast_log(LOG_NOTICE, "Unable to create/find channel\n");
- if (ignore)
- transmit_response(p, "503 Unavailable", req);
- else
- transmit_response_reliable(p, "503 Unavailable", req, 1);
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- }
- }
- return res;
-}
-
-/*! \brief handle_request_refer: Handle incoming REFER request ---*/
-static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int debug, int ignore, int seqno, int *nounlock)
-{
- struct ast_channel *c=NULL;
- int res;
- struct ast_channel *transfer_to;
-
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "SIP call transfer received for call %s (REFER)!\n", p->callid);
- if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
- res = get_refer_info(p, req);
- if (res < 0)
- transmit_response_with_allow(p, "404 Not Found", req, 1);
- else if (res > 0)
- transmit_response_with_allow(p, "484 Address Incomplete", req, 1);
- else {
- int nobye = 0;
- if (!ignore) {
- if (p->refer_call) {
- ast_log(LOG_DEBUG,"202 Accepted (supervised)\n");
- attempt_transfer(p, p->refer_call);
- if (p->refer_call->owner)
- ast_mutex_unlock(&p->refer_call->owner->lock);
- ast_mutex_unlock(&p->refer_call->lock);
- p->refer_call = NULL;
- ast_set_flag(p, SIP_GOTREFER);
- } else {
- ast_log(LOG_DEBUG,"202 Accepted (blind)\n");
- c = p->owner;
- if (c) {
- transfer_to = ast_bridged_channel(c);
- if (transfer_to) {
- ast_log(LOG_DEBUG, "Got SIP blind transfer, applying to '%s'\n", transfer_to->name);
- ast_moh_stop(transfer_to);
- if (!strcmp(p->refer_to, ast_parking_ext())) {
- /* Must release c's lock now, because it will not longer
- be accessible after the transfer! */
- *nounlock = 1;
- ast_mutex_unlock(&c->lock);
- sip_park(transfer_to, c, req);
- nobye = 1;
- } else {
- /* Must release c's lock now, because it will not longer
- be accessible after the transfer! */
- *nounlock = 1;
- ast_mutex_unlock(&c->lock);
- ast_async_goto(transfer_to,p->context, p->refer_to,1);
- }
- } else {
- ast_log(LOG_DEBUG, "Got SIP blind transfer but nothing to transfer to.\n");
- ast_queue_hangup(p->owner);
- }
- }
- ast_set_flag(p, SIP_GOTREFER);
- }
- transmit_response(p, "202 Accepted", req);
- transmit_notify_with_sipfrag(p, seqno);
- /* Always increment on a BYE */
- if (!nobye) {
- transmit_request_with_auth(p, SIP_BYE, 0, 1, 1);
- ast_set_flag(p, SIP_ALREADYGONE);
- }
- }
- }
- return res;
-}
-/*! \brief handle_request_cancel: Handle incoming CANCEL request ---*/
-static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req, int debug, int ignore)
-{
-
- check_via(p, req);
- ast_set_flag(p, SIP_ALREADYGONE);
- if (p->rtp) {
- /* Immediately stop RTP */
- ast_rtp_stop(p->rtp);
- }
- if (p->vrtp) {
- /* Immediately stop VRTP */
- ast_rtp_stop(p->vrtp);
- }
- if (p->owner)
- ast_queue_hangup(p->owner);
- else
- ast_set_flag(p, SIP_NEEDDESTROY);
- if (p->initreq.len > 0) {
- if (!ignore)
- transmit_response_reliable(p, "487 Request Terminated", &p->initreq, 1);
- transmit_response(p, "200 OK", req);
- return 1;
- } else {
- transmit_response(p, "481 Call Leg Does Not Exist", req);
- return 0;
- }
-}
-
-/*! \brief handle_request_bye: Handle incoming BYE request ---*/
-static int handle_request_bye(struct sip_pvt *p, struct sip_request *req, int debug, int ignore)
-{
- struct ast_channel *c=NULL;
- int res;
- struct ast_channel *bridged_to;
- char iabuf[INET_ADDRSTRLEN];
-
- if (p->pendinginvite && !ast_test_flag(p, SIP_OUTGOING) && !ignore)
- transmit_response_reliable(p, "487 Request Terminated", &p->initreq, 1);
-
- copy_request(&p->initreq, req);
- check_via(p, req);
- ast_set_flag(p, SIP_ALREADYGONE);
- if (p->rtp) {
- /* Immediately stop RTP */
- ast_rtp_stop(p->rtp);
- }
- if (p->vrtp) {
- /* Immediately stop VRTP */
- ast_rtp_stop(p->vrtp);
- }
- if (!ast_strlen_zero(get_header(req, "Also"))) {
- ast_log(LOG_NOTICE, "Client '%s' using deprecated BYE/Also transfer method. Ask vendor to support REFER instead\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr));
- if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
- res = get_also_info(p, req);
- if (!res) {
- c = p->owner;
- if (c) {
- bridged_to = ast_bridged_channel(c);
- if (bridged_to) {
- /* Don't actually hangup here... */
- ast_moh_stop(bridged_to);
- ast_async_goto(bridged_to, p->context, p->refer_to,1);
- } else
- ast_queue_hangup(p->owner);
- }
- } else {
- ast_log(LOG_WARNING, "Invalid transfer information from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr));
- if (p->owner)
- ast_queue_hangup(p->owner);
- }
- } else if (p->owner)
- ast_queue_hangup(p->owner);
- else
- ast_set_flag(p, SIP_NEEDDESTROY);
- transmit_response(p, "200 OK", req);
-
- return 1;
-}
-
-/*! \brief handle_request_message: Handle incoming MESSAGE request ---*/
-static int handle_request_message(struct sip_pvt *p, struct sip_request *req, int debug, int ignore)
-{
- if (!ignore) {
- if (debug)
- ast_verbose("Receiving message!\n");
- receive_message(p, req);
- } else {
- transmit_response(p, "202 Accepted", req);
- }
- return 1;
-}
-/*! \brief handle_request_subscribe: Handle incoming SUBSCRIBE request ---*/
-static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, int debug, int ignore, struct sockaddr_in *sin, int seqno, char *e)
-{
- int gotdest;
- int res = 0;
- int firststate = AST_EXTENSION_REMOVED;
-
- if (p->initreq.headers) {
- /* We already have a dialog */
- if (p->initreq.method != SIP_SUBSCRIBE) {
- /* This is a SUBSCRIBE within another SIP dialog, which we do not support */
- /* For transfers, this could happen, but since we haven't seen it happening, let us just refuse this */
- transmit_response(p, "403 Forbidden (within dialog)", req);
- /* Do not destroy session, since we will break the call if we do */
- ast_log(LOG_DEBUG, "Got a subscription within the context of another call, can't handle that - %s (Method %s)\n", p->callid, sip_methods[p->initreq.method].text);
- return 0;
- } else {
- if (debug)
- ast_log(LOG_DEBUG, "Got a re-subscribe on existing subscription %s\n", p->callid);
- }
- }
- if (!ignore && !p->initreq.headers) {
- /* Use this as the basis */
- if (debug)
- ast_verbose("Using latest SUBSCRIBE request as basis request\n");
- /* This call is no longer outgoing if it ever was */
- ast_clear_flag(p, SIP_OUTGOING);
- copy_request(&p->initreq, req);
- check_via(p, req);
- } else if (debug && ignore)
- ast_verbose("Ignoring this SUBSCRIBE request\n");
-
- if (!p->lastinvite) {
- char mailboxbuf[256]="";
- int found = 0;
- char *mailbox = NULL;
- int mailboxsize = 0;
-
- char *event = get_header(req, "Event"); /* Get Event package name */
- char *accept = get_header(req, "Accept");
-
- if (!strcmp(event, "message-summary") && !strcmp(accept, "application/simple-message-summary")) {
- mailbox = mailboxbuf;
- mailboxsize = sizeof(mailboxbuf);
- }
- /* Handle authentication if this is our first subscribe */
- res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, sin, ignore, mailbox, mailboxsize);
- if (res) {
- if (res < 0) {
- ast_log(LOG_NOTICE, "Failed to authenticate user %s for SUBSCRIBE\n", get_header(req, "From"));
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- return 0;
- }
- /* Initialize the context if it hasn't been already */
- if (!ast_strlen_zero(p->subscribecontext))
- ast_copy_string(p->context, p->subscribecontext, sizeof(p->context));
- else if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
- /* Get destination right away */
- gotdest = get_destination(p, NULL);
- build_contact(p);
- if (gotdest) {
- if (gotdest < 0)
- transmit_response(p, "404 Not Found", req);
- else
- transmit_response(p, "484 Address Incomplete", req); /* Overlap dialing on SUBSCRIBE?? */
- ast_set_flag(p, SIP_NEEDDESTROY);
- } else {
-
- /* Initialize tag for new subscriptions */
- if (ast_strlen_zero(p->tag))
- make_our_tag(p->tag, sizeof(p->tag));
-
- if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */
-
- /* Header from Xten Eye-beam Accept: multipart/related, application/rlmi+xml, application/pidf+xml, application/xpidf+xml */
- if (strstr(accept, "application/pidf+xml")) {
- p->subscribed = PIDF_XML; /* RFC 3863 format */
- } else if (strstr(accept, "application/dialog-info+xml")) {
- p->subscribed = DIALOG_INFO_XML;
- /* IETF draft: draft-ietf-sipping-dialog-package-05.txt */
- } else if (strstr(accept, "application/cpim-pidf+xml")) {
- p->subscribed = CPIM_PIDF_XML; /* RFC 3863 format */
- } else if (strstr(accept, "application/xpidf+xml")) {
- p->subscribed = XPIDF_XML; /* Early pre-RFC 3863 format with MSN additions (Microsoft Messenger) */
- } else if (strstr(p->useragent, "Polycom")) {
- p->subscribed = XPIDF_XML; /* Polycoms subscribe for "event: dialog" but don't include an "accept:" header */
- } else {
- /* Can't find a format for events that we know about */
- transmit_response(p, "489 Bad Event", req);
- ast_set_flag(p, SIP_NEEDDESTROY);
- return 0;
- }
- } else if (!strcmp(event, "message-summary") && !strcmp(accept, "application/simple-message-summary")) {
- /* Looks like they actually want a mailbox status */
-
- /* At this point, we should check if they subscribe to a mailbox that
- has the same extension as the peer or the mailbox id. If we configure
- the context to be the same as a SIP domain, we could check mailbox
- context as well. To be able to securely accept subscribes on mailbox
- IDs, not extensions, we need to check the digest auth user to make
- sure that the user has access to the mailbox.
-
- Since we do not act on this subscribe anyway, we might as well
- accept any authenticated peer with a mailbox definition in their
- config section.
-
- */
- if (!ast_strlen_zero(mailbox)) {
- found++;
- }
-
- if (found){
- transmit_response(p, "200 OK", req);
- ast_set_flag(p, SIP_NEEDDESTROY);
- } else {
- transmit_response(p, "404 Not found", req);
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- return 0;
- } else { /* At this point, Asterisk does not understand the specified event */
- transmit_response(p, "489 Bad Event", req);
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "Received SIP subscribe for unknown event package: %s\n", event);
- ast_set_flag(p, SIP_NEEDDESTROY);
- return 0;
- }
- if (p->subscribed != NONE)
- p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, p);
- }
- }
-
- if (!ignore && p)
- p->lastinvite = seqno;
- if (p && !ast_test_flag(p, SIP_NEEDDESTROY)) {
- p->expiry = atoi(get_header(req, "Expires"));
-
- /* The next 4 lines can be removed if the SNOM Expires bug is fixed */
- if (p->subscribed == DIALOG_INFO_XML) {
- if (p->expiry > max_expiry)
- p->expiry = max_expiry;
- }
- if (sipdebug || option_debug > 1)
- ast_log(LOG_DEBUG, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username);
- if (p->autokillid > -1)
- sip_cancel_destroy(p); /* Remove subscription expiry for renewals */
- sip_scheddestroy(p, (p->expiry + 10) * 1000); /* Set timer for destruction of call at expiration */
-
- if ((firststate = ast_extension_state(NULL, p->context, p->exten)) < 0) {
- ast_log(LOG_ERROR, "Got SUBSCRIBE for extensions without hint. Please add hint to %s in context %s\n", p->exten, p->context);
- transmit_response(p, "404 Not found", req);
- ast_set_flag(p, SIP_NEEDDESTROY);
- return 0;
- } else {
- struct sip_pvt *p_old;
-
- transmit_response(p, "200 OK", req);
- transmit_state_notify(p, firststate, 1, 1); /* Send first notification */
- append_history(p, "Subscribestatus", ast_extension_state2str(firststate));
-
- /* remove any old subscription from this peer for the same exten/context,
- as the peer has obviously forgotten about it and it's wasteful to wait
- for it to expire and send NOTIFY messages to the peer only to have them
- ignored (or generate errors)
- */
- ast_mutex_lock(&iflock);
- for (p_old = iflist; p_old; p_old = p_old->next) {
- if (p_old == p)
- continue;
- if (p_old->initreq.method != SIP_SUBSCRIBE)
- continue;
- if (p_old->subscribed == NONE)
- continue;
- ast_mutex_lock(&p_old->lock);
- if (!strcmp(p_old->username, p->username)) {
- if (!strcmp(p_old->exten, p->exten) &&
- !strcmp(p_old->context, p->context)) {
- ast_set_flag(p_old, SIP_NEEDDESTROY);
- ast_mutex_unlock(&p_old->lock);
- break;
- }
- }
- ast_mutex_unlock(&p_old->lock);
- }
- ast_mutex_unlock(&iflock);
- }
- if (!p->expiry)
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- return 1;
-}
-
-/*! \brief handle_request_register: Handle incoming REGISTER request ---*/
-static int handle_request_register(struct sip_pvt *p, struct sip_request *req, int debug, int ignore, struct sockaddr_in *sin, char *e)
-{
- int res = 0;
- char iabuf[INET_ADDRSTRLEN];
-
- /* Use this as the basis */
- if (debug)
- ast_verbose("Using latest REGISTER request as basis request\n");
- copy_request(&p->initreq, req);
- check_via(p, req);
- if ((res = register_verify(p, sin, req, e, ignore)) < 0)
- ast_log(LOG_NOTICE, "Registration from '%s' failed for '%s' - %s\n", get_header(req, "To"), ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), (res == -1) ? "Wrong password" : (res == -2 ? "Username/auth name mismatch" : "Not a local SIP domain"));
- if (res < 1) {
- /* Destroy the session, but keep us around for just a bit in case they don't
- get our 200 OK */
- sip_scheddestroy(p, 15*1000);
- }
- return res;
-}
-
-/*! \brief handle_request: Handle SIP requests (methods) ---*/
-/* this is where all incoming requests go first */
-static int handle_request(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int *recount, int *nounlock)
-{
- /* Called with p->lock held, as well as p->owner->lock if appropriate, keeping things
- relatively static */
- struct sip_request resp;
- char *cmd;
- char *cseq;
- char *useragent;
- int seqno;
- int len;
- int ignore=0;
- int respid;
- int res = 0;
- char iabuf[INET_ADDRSTRLEN];
- int debug = sip_debug_test_pvt(p);
- char *e;
- int error = 0;
-
- /* Clear out potential response */
- memset(&resp, 0, sizeof(resp));
-
- /* Get Method and Cseq */
- cseq = get_header(req, "Cseq");
- cmd = req->header[0];
-
- /* Must have Cseq */
- if (ast_strlen_zero(cmd) || ast_strlen_zero(cseq)) {
- ast_log(LOG_ERROR, "Missing Cseq. Dropping this SIP message, it's incomplete.\n");
- error = 1;
- }
- if (!error && sscanf(cseq, "%d%n", &seqno, &len) != 1) {
- ast_log(LOG_ERROR, "No seqno in '%s'. Dropping incomplete message.\n", cmd);
- error = 1;
- }
- if (error) {
- if (!p->initreq.header) /* New call */
- ast_set_flag(p, SIP_NEEDDESTROY); /* Make sure we destroy this dialog */
- return -1;
- }
- /* Get the command XXX */
-
- cmd = req->rlPart1;
- e = req->rlPart2;
-
- /* Save useragent of the client */
- useragent = get_header(req, "User-Agent");
- if (!ast_strlen_zero(useragent))
- ast_copy_string(p->useragent, useragent, sizeof(p->useragent));
-
- /* Find out SIP method for incoming request */
- if (req->method == SIP_RESPONSE) { /* Response to our request */
- /* Response to our request -- Do some sanity checks */
- if (!p->initreq.headers) {
- ast_log(LOG_DEBUG, "That's odd... Got a response on a call we dont know about. Cseq %d Cmd %s\n", seqno, cmd);
- ast_set_flag(p, SIP_NEEDDESTROY);
- return 0;
- } else if (p->ocseq && (p->ocseq < seqno)) {
- ast_log(LOG_DEBUG, "Ignoring out of order response %d (expecting %d)\n", seqno, p->ocseq);
- return -1;
- } else if (p->ocseq && (p->ocseq != seqno)) {
- /* ignore means "don't do anything with it" but still have to
- respond appropriately */
- ignore=1;
- }
-
- e = ast_skip_blanks(e);
- if (sscanf(e, "%d %n", &respid, &len) != 1) {
- ast_log(LOG_WARNING, "Invalid response: '%s'\n", e);
- } else {
- /* More SIP ridiculousness, we have to ignore bogus contacts in 100 etc responses */
- if ((respid == 200) || ((respid >= 300) && (respid <= 399)))
- extract_uri(p, req);
- handle_response(p, respid, e + len, req, ignore, seqno);
- }
- return 0;
- }
-
- /* New SIP request coming in
- (could be new request in existing SIP dialog as well...)
- */
-
- p->method = req->method; /* Find out which SIP method they are using */
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "**** Received %s (%d) - Command in SIP %s\n", sip_methods[p->method].text, sip_methods[p->method].id, cmd);
-
- if (p->icseq && (p->icseq > seqno)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Ignoring too old SIP packet packet %d (expecting >= %d)\n", seqno, p->icseq);
- if (req->method != SIP_ACK)
- transmit_response(p, "503 Server error", req); /* We must respond according to RFC 3261 sec 12.2 */
- return -1;
- } else if (p->icseq && (p->icseq == seqno) && req->method != SIP_ACK &&(p->method != SIP_CANCEL|| ast_test_flag(p, SIP_ALREADYGONE))) {
- /* ignore means "don't do anything with it" but still have to
- respond appropriately. We do this if we receive a repeat of
- the last sequence number */
- ignore=2;
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Ignoring SIP message because of retransmit (%s Seqno %d, ours %d)\n", sip_methods[p->method].text, p->icseq, seqno);
- }
-
- if (seqno >= p->icseq)
- /* Next should follow monotonically (but not necessarily
- incrementally -- thanks again to the genius authors of SIP --
- increasing */
- p->icseq = seqno;
-
- /* Find their tag if we haven't got it */
- if (ast_strlen_zero(p->theirtag)) {
- gettag(req, "From", p->theirtag, sizeof(p->theirtag));
- }
- snprintf(p->lastmsg, sizeof(p->lastmsg), "Rx: %s", cmd);
-
- if (pedanticsipchecking) {
- /* If this is a request packet without a from tag, it's not
- correct according to RFC 3261 */
- /* Check if this a new request in a new dialog with a totag already attached to it,
- RFC 3261 - section 12.2 - and we don't want to mess with recovery */
- if (!p->initreq.headers && ast_test_flag(req, SIP_PKT_WITH_TOTAG)) {
- /* If this is a first request and it got a to-tag, it is not for us */
- if (!ignore && req->method == SIP_INVITE) {
- transmit_response_reliable(p, "481 Call/Transaction Does Not Exist", req, 1);
- /* Will cease to exist after ACK */
- } else {
- transmit_response(p, "481 Call/Transaction Does Not Exist", req);
- ast_set_flag(p, SIP_NEEDDESTROY);
- }
- return res;
- }
- }
-
- /* Handle various incoming SIP methods in requests */
- switch (p->method) {
- case SIP_OPTIONS:
- res = handle_request_options(p, req, debug);
- break;
- case SIP_INVITE:
- res = handle_request_invite(p, req, debug, ignore, seqno, sin, recount, e);
- break;
- case SIP_REFER:
- res = handle_request_refer(p, req, debug, ignore, seqno, nounlock);
- break;
- case SIP_CANCEL:
- res = handle_request_cancel(p, req, debug, ignore);
- break;
- case SIP_BYE:
- res = handle_request_bye(p, req, debug, ignore);
- break;
- case SIP_MESSAGE:
- res = handle_request_message(p, req, debug, ignore);
- break;
- case SIP_SUBSCRIBE:
- res = handle_request_subscribe(p, req, debug, ignore, sin, seqno, e);
- break;
- case SIP_REGISTER:
- res = handle_request_register(p, req, debug, ignore, sin, e);
- break;
- case SIP_INFO:
- if (!ignore) {
- if (debug)
- ast_verbose("Receiving INFO!\n");
- handle_request_info(p, req);
- } else { /* if ignoring, transmit response */
- transmit_response(p, "200 OK", req);
- }
- break;
- case SIP_NOTIFY:
- /* XXX we get NOTIFY's from some servers. WHY?? Maybe we should
- look into this someday XXX */
- transmit_response(p, "200 OK", req);
- if (!p->lastinvite)
- ast_set_flag(p, SIP_NEEDDESTROY);
- break;
- case SIP_ACK:
- /* Make sure we don't ignore this */
- if (seqno == p->pendinginvite) {
- p->pendinginvite = 0;
- __sip_ack(p, seqno, FLAG_RESPONSE, 0);
- if (!ast_strlen_zero(get_header(req, "Content-Type"))) {
- if (process_sdp(p, req))
- return -1;
- }
- check_pendings(p);
- }
- if (!p->lastinvite && ast_strlen_zero(p->randdata))
- ast_set_flag(p, SIP_NEEDDESTROY);
- break;
- default:
- transmit_response_with_allow(p, "501 Method Not Implemented", req, 0);
- ast_log(LOG_NOTICE, "Unknown SIP command '%s' from '%s'\n",
- cmd, ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr));
- /* If this is some new method, and we don't have a call, destroy it now */
- if (!p->initreq.headers)
- ast_set_flag(p, SIP_NEEDDESTROY);
- break;
- }
- return res;
-}
-
-/*! \brief sipsock_read: Read data from SIP socket ---*/
-/* Successful messages is connected to SIP call and forwarded to handle_request() */
-static int sipsock_read(int *id, int fd, short events, void *ignore)
-{
- struct sip_request req;
- struct sockaddr_in sin = { 0, };
- struct sip_pvt *p;
- int res;
- socklen_t len;
- int nounlock;
- int recount = 0;
- char iabuf[INET_ADDRSTRLEN];
-
- len = sizeof(sin);
- memset(&req, 0, sizeof(req));
- res = recvfrom(sipsock, req.data, sizeof(req.data) - 1, 0, (struct sockaddr *)&sin, &len);
- if (res < 0) {
-#if !defined(__FreeBSD__)
- if (errno == EAGAIN)
- ast_log(LOG_NOTICE, "SIP: Received packet with bad UDP checksum\n");
- else
-#endif
- if (errno != ECONNREFUSED)
- ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno));
- return 1;
- }
- if (res == sizeof(req.data)) {
- ast_log(LOG_DEBUG, "Received packet exceeds buffer. Data is possibly lost\n");
- }
- req.data[res] = '\0';
- req.len = res;
- if(sip_debug_test_addr(&sin))
- ast_set_flag(&req, SIP_PKT_DEBUG);
- if (pedanticsipchecking)
- req.len = lws2sws(req.data, req.len); /* Fix multiline headers */
- if (ast_test_flag(&req, SIP_PKT_DEBUG)) {
- ast_verbose("\n<-- SIP read from %s:%d: \n%s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port), req.data);
- }
- parse_request(&req);
- req.method = find_sip_method(req.rlPart1);
- if (ast_test_flag(&req, SIP_PKT_DEBUG)) {
- ast_verbose("--- (%d headers %d lines)", req.headers, req.lines);
- if (req.headers + req.lines == 0)
- ast_verbose(" Nat keepalive ");
- ast_verbose("---\n");
- }
-
- if (req.headers < 2) {
- /* Must have at least two headers */
- return 1;
- }
-
-
- /* Process request, with netlock held */
-retrylock:
- ast_mutex_lock(&netlock);
- p = find_call(&req, &sin, req.method);
- if (p) {
- /* Go ahead and lock the owner if it has one -- we may need it */
- if (p->owner && ast_mutex_trylock(&p->owner->lock)) {
- ast_log(LOG_DEBUG, "Failed to grab lock, trying again...\n");
- ast_mutex_unlock(&p->lock);
- ast_mutex_unlock(&netlock);
- /* Sleep infintismly short amount of time */
- usleep(1);
- goto retrylock;
- }
- memcpy(&p->recv, &sin, sizeof(p->recv));
- if (recordhistory) {
- char tmp[80];
- /* This is a response, note what it was for */
- snprintf(tmp, sizeof(tmp), "%s / %s", req.data, get_header(&req, "CSeq"));
- append_history(p, "Rx", tmp);
- }
- nounlock = 0;
- if (handle_request(p, &req, &sin, &recount, &nounlock) == -1) {
- /* Request failed */
- ast_log(LOG_DEBUG, "SIP message could not be handled, bad request: %-70.70s\n", p->callid[0] ? p->callid : "<no callid>");
- }
-
- if (p->owner && !nounlock)
- ast_mutex_unlock(&p->owner->lock);
- ast_mutex_unlock(&p->lock);
- }
- ast_mutex_unlock(&netlock);
- if (recount)
- ast_update_use_count();
-
- return 1;
-}
-
-/*! \brief sip_send_mwi_to_peer: Send message waiting indication ---*/
-static int sip_send_mwi_to_peer(struct sip_peer *peer)
-{
- /* Called with peerl lock, but releases it */
- struct sip_pvt *p;
- int newmsgs, oldmsgs;
-
- /* Check for messages */
- ast_app_messagecount(peer->mailbox, &newmsgs, &oldmsgs);
-
- time(&peer->lastmsgcheck);
-
- /* Return now if it's the same thing we told them last time */
- if (((newmsgs << 8) | (oldmsgs)) == peer->lastmsgssent) {
- return 0;
- }
-
- p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY);
- if (!p) {
- ast_log(LOG_WARNING, "Unable to build sip pvt data for MWI\n");
- return -1;
- }
- peer->lastmsgssent = ((newmsgs << 8) | (oldmsgs));
- if (create_addr_from_peer(p, peer)) {
- /* Maybe they're not registered, etc. */
- sip_destroy(p);
- return 0;
- }
- /* Recalculate our side, and recalculate Call ID */
- if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
- memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- build_via(p, p->via, sizeof(p->via));
- build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
- /* Send MWI */
- ast_set_flag(p, SIP_OUTGOING);
- transmit_notify_with_mwi(p, newmsgs, oldmsgs, peer->vmexten);
- sip_scheddestroy(p, 15000);
- return 0;
-}
-
-/*! \brief do_monitor: The SIP monitoring thread ---*/
-static void *do_monitor(void *data)
-{
- int res;
- struct sip_pvt *sip;
- struct sip_peer *peer = NULL;
- time_t t;
- int fastrestart =0;
- int lastpeernum = -1;
- int curpeernum;
- int reloading;
-
- /* Add an I/O event to our UDP socket */
- if (sipsock > -1)
- ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL);
-
- /* This thread monitors all the frame relay interfaces which are not yet in use
- (and thus do not have a separate thread) indefinitely */
- /* From here on out, we die whenever asked */
- for(;;) {
- /* Check for a reload request */
- ast_mutex_lock(&sip_reload_lock);
- reloading = sip_reloading;
- sip_reloading = 0;
- ast_mutex_unlock(&sip_reload_lock);
- if (reloading) {
- if (option_verbose > 0)
- ast_verbose(VERBOSE_PREFIX_1 "Reloading SIP\n");
- sip_do_reload();
- }
- /* Check for interfaces needing to be killed */
- ast_mutex_lock(&iflock);
-restartsearch:
- time(&t);
- sip = iflist;
- while(sip) {
- ast_mutex_lock(&sip->lock);
- if (sip->rtp && sip->owner && (sip->owner->_state == AST_STATE_UP) && !sip->redirip.sin_addr.s_addr) {
- if (sip->lastrtptx && sip->rtpkeepalive && t > sip->lastrtptx + sip->rtpkeepalive) {
- /* Need to send an empty RTP packet */
- time(&sip->lastrtptx);
- ast_rtp_sendcng(sip->rtp, 0);
- }
- if (sip->lastrtprx && (sip->rtptimeout || sip->rtpholdtimeout) && t > sip->lastrtprx + sip->rtptimeout) {
- /* Might be a timeout now -- see if we're on hold */
- struct sockaddr_in sin;
- ast_rtp_get_peer(sip->rtp, &sin);
- if (sin.sin_addr.s_addr ||
- (sip->rtpholdtimeout &&
- (t > sip->lastrtprx + sip->rtpholdtimeout))) {
- /* Needs a hangup */
- if (sip->rtptimeout) {
- while(sip->owner && ast_mutex_trylock(&sip->owner->lock)) {
- ast_mutex_unlock(&sip->lock);
- usleep(1);
- ast_mutex_lock(&sip->lock);
- }
- if (sip->owner) {
- ast_log(LOG_NOTICE, "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n", sip->owner->name, (long)(t - sip->lastrtprx));
- /* Issue a softhangup */
- ast_softhangup(sip->owner, AST_SOFTHANGUP_DEV);
- ast_mutex_unlock(&sip->owner->lock);
- }
- }
- }
- }
- }
- if (ast_test_flag(sip, SIP_NEEDDESTROY) && !sip->packets && !sip->owner) {
- ast_mutex_unlock(&sip->lock);
- __sip_destroy(sip, 1);
- goto restartsearch;
- }
- ast_mutex_unlock(&sip->lock);
- sip = sip->next;
- }
- ast_mutex_unlock(&iflock);
- /* Don't let anybody kill us right away. Nobody should lock the interface list
- and wait for the monitor list, but the other way around is okay. */
- ast_mutex_lock(&monlock);
- /* Lock the network interface */
- ast_mutex_lock(&netlock);
- /* Okay, now that we know what to do, release the network lock */
- ast_mutex_unlock(&netlock);
- /* And from now on, we're okay to be killed, so release the monitor lock as well */
- ast_mutex_unlock(&monlock);
- pthread_testcancel();
- /* Wait for sched or io */
- res = ast_sched_wait(sched);
- if ((res < 0) || (res > 1000))
- res = 1000;
- /* If we might need to send more mailboxes, don't wait long at all.*/
- if (fastrestart)
- res = 1;
- res = ast_io_wait(io, res);
- if (res > 20)
- ast_log(LOG_DEBUG, "chan_sip: ast_io_wait ran %d all at once\n", res);
- ast_mutex_lock(&monlock);
- if (res >= 0) {
- res = ast_sched_runq(sched);
- if (res >= 20)
- ast_log(LOG_DEBUG, "chan_sip: ast_sched_runq ran %d all at once\n", res);
- }
-
- /* needs work to send mwi to realtime peers */
- time(&t);
- fastrestart = 0;
- curpeernum = 0;
- peer = NULL;
- ASTOBJ_CONTAINER_TRAVERSE(&peerl, !peer, do {
- if ((curpeernum > lastpeernum) && !ast_strlen_zero(iterator->mailbox) && ((t - iterator->lastmsgcheck) > global_mwitime)) {
- fastrestart = 1;
- lastpeernum = curpeernum;
- peer = ASTOBJ_REF(iterator);
- };
- curpeernum++;
- } while (0)
- );
- if (peer) {
- ASTOBJ_WRLOCK(peer);
- sip_send_mwi_to_peer(peer);
- ASTOBJ_UNLOCK(peer);
- ASTOBJ_UNREF(peer,sip_destroy_peer);
- } else {
- /* Reset where we come from */
- lastpeernum = -1;
- }
- ast_mutex_unlock(&monlock);
- }
- /* Never reached */
- return NULL;
-
-}
-
-/*! \brief restart_monitor: Start the channel monitor thread ---*/
-static int restart_monitor(void)
-{
- /* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == AST_PTHREADT_STOP)
- return 0;
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_WARNING, "Unable to lock monitor\n");
- return -1;
- }
- if (monitor_thread == pthread_self()) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- return -1;
- }
- if (monitor_thread != AST_PTHREADT_NULL) {
- /* Wake up the thread */
- pthread_kill(monitor_thread, SIGURG);
- } else {
- /* Start a new monitor */
- if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- return -1;
- }
- }
- ast_mutex_unlock(&monlock);
- return 0;
-}
-
-/*! \brief sip_poke_noanswer: No answer to Qualify poke ---*/
-static int sip_poke_noanswer(void *data)
-{
- struct sip_peer *peer = data;
-
- peer->pokeexpire = -1;
- if (peer->lastms > -1) {
- ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE! Last qualify: %d\n", peer->name, peer->lastms);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, -1);
- }
- if (peer->call)
- sip_destroy(peer->call);
- peer->call = NULL;
- peer->lastms = -1;
- ast_device_state_changed("SIP/%s", peer->name);
- /* Try again quickly */
- peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
- return 0;
-}
-
-/*! \brief sip_poke_peer: Check availability of peer, also keep NAT open ---*/
-/* This is done with the interval in qualify= option in sip.conf */
-/* Default is 2 seconds */
-static int sip_poke_peer(struct sip_peer *peer)
-{
- struct sip_pvt *p;
- if (!peer->maxms || !peer->addr.sin_addr.s_addr) {
- /* IF we have no IP, or this isn't to be monitored, return
- imeediately after clearing things out */
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
- peer->lastms = 0;
- peer->pokeexpire = -1;
- peer->call = NULL;
- return 0;
- }
- if (peer->call > 0) {
- if (sipdebug)
- ast_log(LOG_NOTICE, "Still have a QUALIFY dialog active, deleting\n");
- sip_destroy(peer->call);
- }
- p = peer->call = sip_alloc(NULL, NULL, 0, SIP_OPTIONS);
- if (!peer->call) {
- ast_log(LOG_WARNING, "Unable to allocate dialog for poking peer '%s'\n", peer->name);
- return -1;
- }
- memcpy(&p->sa, &peer->addr, sizeof(p->sa));
- memcpy(&p->recv, &peer->addr, sizeof(p->sa));
-
- /* Send options to peer's fullcontact */
- if (!ast_strlen_zero(peer->fullcontact)) {
- ast_copy_string (p->fullcontact, peer->fullcontact, sizeof(p->fullcontact));
- }
-
- if (!ast_strlen_zero(peer->tohost))
- ast_copy_string(p->tohost, peer->tohost, sizeof(p->tohost));
- else
- ast_inet_ntoa(p->tohost, sizeof(p->tohost), peer->addr.sin_addr);
-
- /* Recalculate our side, and recalculate Call ID */
- if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
- memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- build_via(p, p->via, sizeof(p->via));
- build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
-
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
- p->peerpoke = peer;
- ast_set_flag(p, SIP_OUTGOING);
-#ifdef VOCAL_DATA_HACK
- ast_copy_string(p->username, "__VOCAL_DATA_SHOULD_READ_THE_SIP_SPEC__", sizeof(p->username));
- transmit_invite(p, SIP_INVITE, 0, 2);
-#else
- transmit_invite(p, SIP_OPTIONS, 0, 2);
-#endif
- gettimeofday(&peer->ps, NULL);
- peer->pokeexpire = ast_sched_add(sched, DEFAULT_MAXMS * 2, sip_poke_noanswer, peer);
-
- return 0;
-}
-
-/*! \brief sip_devicestate: Part of PBX channel interface ---*/
-
-/* Return values:---
- If we have qualify on and the device is not reachable, regardless of registration
- state we return AST_DEVICE_UNAVAILABLE
-
- For peers with call limit:
- not registered AST_DEVICE_UNAVAILABLE
- registered, no call AST_DEVICE_NOT_INUSE
- registered, calls possible AST_DEVICE_INUSE
- registered, call limit reached AST_DEVICE_BUSY
- For peers without call limit:
- not registered AST_DEVICE_UNAVAILABLE
- registered AST_DEVICE_UNKNOWN
-*/
-static int sip_devicestate(void *data)
-{
- char *host;
- char *tmp;
-
- struct hostent *hp;
- struct ast_hostent ahp;
- struct sip_peer *p;
-
- int res = AST_DEVICE_INVALID;
-
- host = ast_strdupa(data);
- if ((tmp = strchr(host, '@')))
- host = tmp + 1;
-
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Checking device state for peer %s\n", host);
-
- if ((p = find_peer(host, NULL, 1))) {
- if (p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) {
- /* we have an address for the peer */
- /* if qualify is turned on, check the status */
- if (p->maxms && (p->lastms > p->maxms)) {
- res = AST_DEVICE_UNAVAILABLE;
- } else {
- /* qualify is not on, or the peer is responding properly */
- /* check call limit */
- if (p->call_limit && (p->inUse == p->call_limit))
- res = AST_DEVICE_BUSY;
- else if (p->call_limit && p->inUse)
- res = AST_DEVICE_INUSE;
- else if (p->call_limit)
- res = AST_DEVICE_NOT_INUSE;
- else
- res = AST_DEVICE_UNKNOWN;
- }
- } else {
- /* there is no address, it's unavailable */
- res = AST_DEVICE_UNAVAILABLE;
- }
- ASTOBJ_UNREF(p,sip_destroy_peer);
- } else {
- hp = ast_gethostbyname(host, &ahp);
- if (hp)
- res = AST_DEVICE_UNKNOWN;
- }
-
- return res;
-}
-
-/*! \brief sip_request: PBX interface function -build SIP pvt structure ---*/
-/* SIP calls initiated by the PBX arrive here */
-static struct ast_channel *sip_request_call(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- struct sip_pvt *p;
- struct ast_channel *tmpc = NULL;
- char *ext, *host;
- char tmp[256];
- char *dest = data;
-
- oldformat = format;
- format &= ((AST_FORMAT_MAX_AUDIO << 1) - 1);
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format %s while capability is %s\n", ast_getformatname(oldformat), ast_getformatname(global_capability));
- return NULL;
- }
- p = sip_alloc(NULL, NULL, 0, SIP_INVITE);
- if (!p) {
- ast_log(LOG_WARNING, "Unable to build sip pvt data for '%s'\n", (char *)data);
- return NULL;
- }
-
- p->options = calloc(1, sizeof(*p->options));
- if (!p->options) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return NULL;
- }
-
- ast_copy_string(tmp, dest, sizeof(tmp));
- host = strchr(tmp, '@');
- if (host) {
- *host = '\0';
- host++;
- ext = tmp;
- } else {
- ext = strchr(tmp, '/');
- if (ext) {
- *ext++ = '\0';
- host = tmp;
- }
- else {
- host = tmp;
- ext = NULL;
- }
- }
-
- if (create_addr(p, host)) {
- *cause = AST_CAUSE_UNREGISTERED;
- sip_destroy(p);
- return NULL;
- }
- if (ast_strlen_zero(p->peername) && ext)
- ast_copy_string(p->peername, ext, sizeof(p->peername));
- /* Recalculate our side, and recalculate Call ID */
- if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
- memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- build_via(p, p->via, sizeof(p->via));
- build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
-
- /* We have an extension to call, don't use the full contact here */
- /* This to enable dialling registered peers with extension dialling,
- like SIP/peername/extension
- SIP/peername will still use the full contact */
- if (ext) {
- ast_copy_string(p->username, ext, sizeof(p->username));
- p->fullcontact[0] = 0;
- }
-#if 0
- printf("Setting up to call extension '%s' at '%s'\n", ext ? ext : "<none>", host);
-#endif
- p->prefcodec = format;
- ast_mutex_lock(&p->lock);
- tmpc = sip_new(p, AST_STATE_DOWN, host); /* Place the call */
- ast_mutex_unlock(&p->lock);
- if (!tmpc)
- sip_destroy(p);
- ast_update_use_count();
- restart_monitor();
- return tmpc;
-}
-
-/*! \brief handle_common_options: Handle flag-type options common to users and peers ---*/
-static int handle_common_options(struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v)
-{
- int res = 0;
-
- if (!strcasecmp(v->name, "trustrpid")) {
- ast_set_flag(mask, SIP_TRUSTRPID);
- ast_set2_flag(flags, ast_true(v->value), SIP_TRUSTRPID);
- res = 1;
- } else if (!strcasecmp(v->name, "sendrpid")) {
- ast_set_flag(mask, SIP_SENDRPID);
- ast_set2_flag(flags, ast_true(v->value), SIP_SENDRPID);
- res = 1;
- } else if (!strcasecmp(v->name, "useclientcode")) {
- ast_set_flag(mask, SIP_USECLIENTCODE);
- ast_set2_flag(flags, ast_true(v->value), SIP_USECLIENTCODE);
- res = 1;
- } else if (!strcasecmp(v->name, "dtmfmode")) {
- ast_set_flag(mask, SIP_DTMF);
- ast_clear_flag(flags, SIP_DTMF);
- if (!strcasecmp(v->value, "inband"))
- ast_set_flag(flags, SIP_DTMF_INBAND);
- else if (!strcasecmp(v->value, "rfc2833"))
- ast_set_flag(flags, SIP_DTMF_RFC2833);
- else if (!strcasecmp(v->value, "info"))
- ast_set_flag(flags, SIP_DTMF_INFO);
- else if (!strcasecmp(v->value, "auto"))
- ast_set_flag(flags, SIP_DTMF_AUTO);
- else {
- ast_log(LOG_WARNING, "Unknown dtmf mode '%s' on line %d, using rfc2833\n", v->value, v->lineno);
- ast_set_flag(flags, SIP_DTMF_RFC2833);
- }
- } else if (!strcasecmp(v->name, "nat")) {
- ast_set_flag(mask, SIP_NAT);
- ast_clear_flag(flags, SIP_NAT);
- if (!strcasecmp(v->value, "never"))
- ast_set_flag(flags, SIP_NAT_NEVER);
- else if (!strcasecmp(v->value, "route"))
- ast_set_flag(flags, SIP_NAT_ROUTE);
- else if (ast_true(v->value))
- ast_set_flag(flags, SIP_NAT_ALWAYS);
- else
- ast_set_flag(flags, SIP_NAT_RFC3581);
- } else if (!strcasecmp(v->name, "canreinvite")) {
- ast_set_flag(mask, SIP_REINVITE);
- ast_clear_flag(flags, SIP_REINVITE);
- if (!strcasecmp(v->value, "update"))
- ast_set_flag(flags, SIP_REINVITE_UPDATE | SIP_CAN_REINVITE);
- else
- ast_set2_flag(flags, ast_true(v->value), SIP_CAN_REINVITE);
- } else if (!strcasecmp(v->name, "insecure")) {
- ast_set_flag(mask, SIP_INSECURE_PORT | SIP_INSECURE_INVITE);
- ast_clear_flag(flags, SIP_INSECURE_PORT | SIP_INSECURE_INVITE);
- if (!strcasecmp(v->value, "very"))
- ast_set_flag(flags, SIP_INSECURE_PORT | SIP_INSECURE_INVITE);
- else if (ast_true(v->value))
- ast_set_flag(flags, SIP_INSECURE_PORT);
- else if (!ast_false(v->value)) {
- char buf[64];
- char *word, *next;
-
- ast_copy_string(buf, v->value, sizeof(buf));
- next = buf;
- while ((word = strsep(&next, ","))) {
- if (!strcasecmp(word, "port"))
- ast_set_flag(flags, SIP_INSECURE_PORT);
- else if (!strcasecmp(word, "invite"))
- ast_set_flag(flags, SIP_INSECURE_INVITE);
- else
- ast_log(LOG_WARNING, "Unknown insecure mode '%s' on line %d\n", v->value, v->lineno);
- }
- }
- } else if (!strcasecmp(v->name, "progressinband")) {
- ast_set_flag(mask, SIP_PROG_INBAND);
- ast_clear_flag(flags, SIP_PROG_INBAND);
- if (ast_true(v->value))
- ast_set_flag(flags, SIP_PROG_INBAND_YES);
- else if (strcasecmp(v->value, "never"))
- ast_set_flag(flags, SIP_PROG_INBAND_NO);
- } else if (!strcasecmp(v->name, "allowguest")) {
-#ifdef OSP_SUPPORT
- if (!strcasecmp(v->value, "osp"))
- global_allowguest = 2;
- else
-#endif
- if (ast_true(v->value))
- global_allowguest = 1;
- else
- global_allowguest = 0;
-#ifdef OSP_SUPPORT
- } else if (!strcasecmp(v->name, "ospauth")) {
- ast_set_flag(mask, SIP_OSPAUTH);
- ast_clear_flag(flags, SIP_OSPAUTH);
- if (!strcasecmp(v->value, "proxy"))
- ast_set_flag(flags, SIP_OSPAUTH_PROXY);
- else if (!strcasecmp(v->value, "gateway"))
- ast_set_flag(flags, SIP_OSPAUTH_GATEWAY);
- else if(!strcasecmp (v->value, "exclusive"))
- ast_set_flag(flags, SIP_OSPAUTH_EXCLUSIVE);
-#endif
- } else if (!strcasecmp(v->name, "promiscredir")) {
- ast_set_flag(mask, SIP_PROMISCREDIR);
- ast_set2_flag(flags, ast_true(v->value), SIP_PROMISCREDIR);
- res = 1;
- }
-
- return res;
-}
-
-/*! \brief add_sip_domain: Add SIP domain to list of domains we are responsible for */
-static int add_sip_domain(const char *domain, const enum domain_mode mode, const char *context)
-{
- struct domain *d;
-
- if (ast_strlen_zero(domain)) {
- ast_log(LOG_WARNING, "Zero length domain.\n");
- return 1;
- }
-
- d = calloc(1, sizeof(*d));
- if (!d) {
- ast_log(LOG_ERROR, "Allocation of domain structure failed, Out of memory\n");
- return 0;
- }
-
- ast_copy_string(d->domain, domain, sizeof(d->domain));
-
- if (!ast_strlen_zero(context))
- ast_copy_string(d->context, context, sizeof(d->context));
-
- d->mode = mode;
-
- AST_LIST_LOCK(&domain_list);
- AST_LIST_INSERT_TAIL(&domain_list, d, list);
- AST_LIST_UNLOCK(&domain_list);
-
- if (sipdebug)
- ast_log(LOG_DEBUG, "Added local SIP domain '%s'\n", domain);
-
- return 1;
-}
-
-/*! \brief check_sip_domain: Check if domain part of uri is local to our server */
-static int check_sip_domain(const char *domain, char *context, size_t len)
-{
- struct domain *d;
- int result = 0;
-
- AST_LIST_LOCK(&domain_list);
- AST_LIST_TRAVERSE(&domain_list, d, list) {
- if (strcasecmp(d->domain, domain))
- continue;
-
- if (len && !ast_strlen_zero(d->context))
- ast_copy_string(context, d->context, len);
-
- result = 1;
- break;
- }
- AST_LIST_UNLOCK(&domain_list);
-
- return result;
-}
-
-/*! \brief clear_sip_domains: Clear our domain list (at reload) */
-static void clear_sip_domains(void)
-{
- struct domain *d;
-
- AST_LIST_LOCK(&domain_list);
- while ((d = AST_LIST_REMOVE_HEAD(&domain_list, list)))
- free(d);
- AST_LIST_UNLOCK(&domain_list);
-}
-
-
-/*! \brief add_realm_authentication: Add realm authentication in list ---*/
-static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno)
-{
- char authcopy[256];
- char *username=NULL, *realm=NULL, *secret=NULL, *md5secret=NULL;
- char *stringp;
- struct sip_auth *auth;
- struct sip_auth *b = NULL, *a = authlist;
-
- if (ast_strlen_zero(configuration))
- return authlist;
-
- ast_log(LOG_DEBUG, "Auth config :: %s\n", configuration);
-
- ast_copy_string(authcopy, configuration, sizeof(authcopy));
- stringp = authcopy;
-
- username = stringp;
- realm = strrchr(stringp, '@');
- if (realm) {
- *realm = '\0';
- realm++;
- }
- if (ast_strlen_zero(username) || ast_strlen_zero(realm)) {
- ast_log(LOG_WARNING, "Format for authentication entry is user[:secret]@realm at line %d\n", lineno);
- return authlist;
- }
- stringp = username;
- username = strsep(&stringp, ":");
- if (username) {
- secret = strsep(&stringp, ":");
- if (!secret) {
- stringp = username;
- md5secret = strsep(&stringp,"#");
- }
- }
- auth = malloc(sizeof(struct sip_auth));
- if (auth) {
- memset(auth, 0, sizeof(struct sip_auth));
- ast_copy_string(auth->realm, realm, sizeof(auth->realm));
- ast_copy_string(auth->username, username, sizeof(auth->username));
- if (secret)
- ast_copy_string(auth->secret, secret, sizeof(auth->secret));
- if (md5secret)
- ast_copy_string(auth->md5secret, md5secret, sizeof(auth->md5secret));
- } else {
- ast_log(LOG_ERROR, "Allocation of auth structure failed, Out of memory\n");
- return authlist;
- }
-
- /* Add authentication to authl */
- if (!authlist) { /* No existing list */
- return auth;
- }
- while(a) {
- b = a;
- a = a->next;
- }
- b->next = auth; /* Add structure add end of list */
-
- if (option_verbose > 2)
- ast_verbose("Added authentication for realm %s\n", realm);
-
- return authlist;
-
-}
-
-/*! \brief clear_realm_authentication: Clear realm authentication list (at reload) ---*/
-static int clear_realm_authentication(struct sip_auth *authlist)
-{
- struct sip_auth *a = authlist;
- struct sip_auth *b;
-
- while (a) {
- b = a;
- a = a->next;
- free(b);
- }
-
- return 1;
-}
-
-/*! \brief find_realm_authentication: Find authentication for a specific realm ---*/
-static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, char *realm)
-{
- struct sip_auth *a = authlist; /* First entry in auth list */
-
- while (a) {
- if (!strcasecmp(a->realm, realm)){
- break;
- }
- a = a->next;
- }
-
- return a;
-}
-
-/*! \brief build_user: Initiate a SIP user structure from sip.conf ---*/
-static struct sip_user *build_user(const char *name, struct ast_variable *v, int realtime)
-{
- struct sip_user *user;
- int format;
- struct ast_ha *oldha = NULL;
- char *varname = NULL, *varval = NULL;
- struct ast_variable *tmpvar = NULL;
- struct ast_flags userflags = {(0)};
- struct ast_flags mask = {(0)};
-
-
- user = (struct sip_user *)malloc(sizeof(struct sip_user));
- if (!user) {
- return NULL;
- }
- memset(user, 0, sizeof(struct sip_user));
- suserobjs++;
- ASTOBJ_INIT(user);
- ast_copy_string(user->name, name, sizeof(user->name));
- oldha = user->ha;
- user->ha = NULL;
- ast_copy_flags(user, &global_flags, SIP_FLAGS_TO_COPY);
- user->capability = global_capability;
- user->prefs = prefs;
- /* set default context */
- strcpy(user->context, default_context);
- strcpy(user->language, default_language);
- strcpy(user->musicclass, global_musicclass);
- while(v) {
- if (handle_common_options(&userflags, &mask, v)) {
- v = v->next;
- continue;
- }
-
- if (!strcasecmp(v->name, "context")) {
- ast_copy_string(user->context, v->value, sizeof(user->context));
- } else if (!strcasecmp(v->name, "subscribecontext")) {
- ast_copy_string(user->subscribecontext, v->value, sizeof(user->subscribecontext));
- } else if (!strcasecmp(v->name, "setvar")) {
- varname = ast_strdupa(v->value);
- if (varname && (varval = strchr(varname,'='))) {
- *varval = '\0';
- varval++;
- if ((tmpvar = ast_variable_new(varname, varval))) {
- tmpvar->next = user->chanvars;
- user->chanvars = tmpvar;
- }
- }
- } else if (!strcasecmp(v->name, "permit") ||
- !strcasecmp(v->name, "deny")) {
- user->ha = ast_append_ha(v->name, v->value, user->ha);
- } else if (!strcasecmp(v->name, "secret")) {
- ast_copy_string(user->secret, v->value, sizeof(user->secret));
- } else if (!strcasecmp(v->name, "md5secret")) {
- ast_copy_string(user->md5secret, v->value, sizeof(user->md5secret));
- } else if (!strcasecmp(v->name, "callerid")) {
- ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num));
- } else if (!strcasecmp(v->name, "callgroup")) {
- user->callgroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "pickupgroup")) {
- user->pickupgroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "language")) {
- ast_copy_string(user->language, v->value, sizeof(user->language));
- } else if (!strcasecmp(v->name, "musicclass") || !strcasecmp(v->name, "musiconhold")) {
- ast_copy_string(user->musicclass, v->value, sizeof(user->musicclass));
- } else if (!strcasecmp(v->name, "accountcode")) {
- ast_copy_string(user->accountcode, v->value, sizeof(user->accountcode));
- } else if (!strcasecmp(v->name, "call-limit") || !strcasecmp(v->name, "incominglimit")) {
- user->call_limit = atoi(v->value);
- if (user->call_limit < 0)
- user->call_limit = 0;
- } else if (!strcasecmp(v->name, "amaflags")) {
- format = ast_cdr_amaflags2int(v->value);
- if (format < 0) {
- ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno);
- } else {
- user->amaflags = format;
- }
- } else if (!strcasecmp(v->name, "allow")) {
- ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, 1);
- } else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, 0);
- } else if (!strcasecmp(v->name, "callingpres")) {
- user->callingpres = ast_parse_caller_presentation(v->value);
- if (user->callingpres == -1)
- user->callingpres = atoi(v->value);
- }
- /*else if (strcasecmp(v->name,"type"))
- * ast_log(LOG_WARNING, "Ignoring %s\n", v->name);
- */
- v = v->next;
- }
- ast_copy_flags(user, &userflags, mask.flags);
- ast_free_ha(oldha);
- return user;
-}
-
-/*! \brief temp_peer: Create temporary peer (used in autocreatepeer mode) ---*/
-static struct sip_peer *temp_peer(const char *name)
-{
- struct sip_peer *peer;
-
- peer = malloc(sizeof(*peer));
- if (!peer)
- return NULL;
-
- memset(peer, 0, sizeof(*peer));
- apeerobjs++;
- ASTOBJ_INIT(peer);
-
- peer->expire = -1;
- peer->pokeexpire = -1;
- ast_copy_string(peer->name, name, sizeof(peer->name));
- ast_copy_flags(peer, &global_flags, SIP_FLAGS_TO_COPY);
- strcpy(peer->context, default_context);
- strcpy(peer->subscribecontext, default_subscribecontext);
- strcpy(peer->language, default_language);
- strcpy(peer->musicclass, global_musicclass);
- peer->addr.sin_port = htons(DEFAULT_SIP_PORT);
- peer->addr.sin_family = AF_INET;
- peer->capability = global_capability;
- peer->rtptimeout = global_rtptimeout;
- peer->rtpholdtimeout = global_rtpholdtimeout;
- peer->rtpkeepalive = global_rtpkeepalive;
- ast_set_flag(peer, SIP_SELFDESTRUCT);
- ast_set_flag(peer, SIP_DYNAMIC);
- peer->prefs = prefs;
- reg_source_db(peer);
-
- return peer;
-}
-
-/*! \brief build_peer: Build peer from config file ---*/
-static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int realtime)
-{
- struct sip_peer *peer = NULL;
- struct ast_ha *oldha = NULL;
- int obproxyfound=0;
- int found=0;
- int format=0; /* Ama flags */
- time_t regseconds;
- char *varname = NULL, *varval = NULL;
- struct ast_variable *tmpvar = NULL;
- struct ast_flags peerflags = {(0)};
- struct ast_flags mask = {(0)};
-
-
- if (!realtime)
- /* Note we do NOT use find_peer here, to avoid realtime recursion */
- /* We also use a case-sensitive comparison (unlike find_peer) so
- that case changes made to the peer name will be properly handled
- during reload
- */
- peer = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&peerl, name, name, 0, 0, strcmp);
-
- if (peer) {
- /* Already in the list, remove it and it will be added back (or FREE'd) */
- found++;
- } else {
- peer = malloc(sizeof(*peer));
- if (peer) {
- memset(peer, 0, sizeof(*peer));
- if (realtime)
- rpeerobjs++;
- else
- speerobjs++;
- ASTOBJ_INIT(peer);
- peer->expire = -1;
- peer->pokeexpire = -1;
- } else {
- ast_log(LOG_WARNING, "Can't allocate SIP peer memory\n");
- }
- }
- /* Note that our peer HAS had its reference count incrased */
- if (!peer)
- return NULL;
-
- peer->lastmsgssent = -1;
- if (!found) {
- if (name)
- ast_copy_string(peer->name, name, sizeof(peer->name));
- peer->addr.sin_port = htons(DEFAULT_SIP_PORT);
- peer->addr.sin_family = AF_INET;
- peer->defaddr.sin_family = AF_INET;
- }
- /* If we have channel variables, remove them (reload) */
- if (peer->chanvars) {
- ast_variables_destroy(peer->chanvars);
- peer->chanvars = NULL;
- }
- strcpy(peer->context, default_context);
- strcpy(peer->subscribecontext, default_subscribecontext);
- strcpy(peer->vmexten, global_vmexten);
- strcpy(peer->language, default_language);
- strcpy(peer->musicclass, global_musicclass);
- ast_copy_flags(peer, &global_flags, SIP_USEREQPHONE);
- peer->secret[0] = '\0';
- peer->md5secret[0] = '\0';
- peer->cid_num[0] = '\0';
- peer->cid_name[0] = '\0';
- peer->fromdomain[0] = '\0';
- peer->fromuser[0] = '\0';
- peer->regexten[0] = '\0';
- peer->mailbox[0] = '\0';
- peer->callgroup = 0;
- peer->pickupgroup = 0;
- peer->rtpkeepalive = global_rtpkeepalive;
- peer->maxms = default_qualify;
- peer->prefs = prefs;
- oldha = peer->ha;
- peer->ha = NULL;
- peer->addr.sin_family = AF_INET;
- ast_copy_flags(peer, &global_flags, SIP_FLAGS_TO_COPY);
- peer->capability = global_capability;
- peer->rtptimeout = global_rtptimeout;
- peer->rtpholdtimeout = global_rtpholdtimeout;
- while(v) {
- if (handle_common_options(&peerflags, &mask, v)) {
- v = v->next;
- continue;
- }
-
- if (realtime && !strcasecmp(v->name, "regseconds")) {
- if (sscanf(v->value, "%ld", (time_t *)&regseconds) != 1)
- regseconds = 0;
- } else if (realtime && !strcasecmp(v->name, "ipaddr") && !ast_strlen_zero(v->value) ) {
- inet_aton(v->value, &(peer->addr.sin_addr));
- } else if (realtime && !strcasecmp(v->name, "name"))
- ast_copy_string(peer->name, v->value, sizeof(peer->name));
- else if (realtime && !strcasecmp(v->name, "fullcontact")) {
- ast_copy_string(peer->fullcontact, v->value, sizeof(peer->fullcontact));
- ast_set_flag((&peer->flags_page2), SIP_PAGE2_RT_FROMCONTACT);
- } else if (!strcasecmp(v->name, "secret"))
- ast_copy_string(peer->secret, v->value, sizeof(peer->secret));
- else if (!strcasecmp(v->name, "md5secret"))
- ast_copy_string(peer->md5secret, v->value, sizeof(peer->md5secret));
- else if (!strcasecmp(v->name, "auth"))
- peer->auth = add_realm_authentication(peer->auth, v->value, v->lineno);
- else if (!strcasecmp(v->name, "callerid")) {
- ast_callerid_split(v->value, peer->cid_name, sizeof(peer->cid_name), peer->cid_num, sizeof(peer->cid_num));
- } else if (!strcasecmp(v->name, "context")) {
- ast_copy_string(peer->context, v->value, sizeof(peer->context));
- } else if (!strcasecmp(v->name, "subscribecontext")) {
- ast_copy_string(peer->subscribecontext, v->value, sizeof(peer->subscribecontext));
- } else if (!strcasecmp(v->name, "fromdomain"))
- ast_copy_string(peer->fromdomain, v->value, sizeof(peer->fromdomain));
- else if (!strcasecmp(v->name, "usereqphone"))
- ast_set2_flag(peer, ast_true(v->value), SIP_USEREQPHONE);
- else if (!strcasecmp(v->name, "fromuser"))
- ast_copy_string(peer->fromuser, v->value, sizeof(peer->fromuser));
- else if (!strcasecmp(v->name, "host") || !strcasecmp(v->name, "outboundproxy")) {
- if (!strcasecmp(v->value, "dynamic")) {
- if (!strcasecmp(v->name, "outboundproxy") || obproxyfound) {
- ast_log(LOG_WARNING, "You can't have a dynamic outbound proxy, you big silly head at line %d.\n", v->lineno);
- } else {
- /* They'll register with us */
- ast_set_flag(peer, SIP_DYNAMIC);
- if (!found) {
- /* Initialize stuff iff we're not found, otherwise
- we keep going with what we had */
- memset(&peer->addr.sin_addr, 0, 4);
- if (peer->addr.sin_port) {
- /* If we've already got a port, make it the default rather than absolute */
- peer->defaddr.sin_port = peer->addr.sin_port;
- peer->addr.sin_port = 0;
- }
- }
- }
- } else {
- /* Non-dynamic. Make sure we become that way if we're not */
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- peer->expire = -1;
- ast_clear_flag(peer, SIP_DYNAMIC);
- if (!obproxyfound || !strcasecmp(v->name, "outboundproxy")) {
- if (ast_get_ip_or_srv(&peer->addr, v->value, "_sip._udp")) {
- ASTOBJ_UNREF(peer, sip_destroy_peer);
- return NULL;
- }
- }
- if (!strcasecmp(v->name, "outboundproxy"))
- obproxyfound=1;
- else {
- ast_copy_string(peer->tohost, v->value, sizeof(peer->tohost));
- if (!peer->addr.sin_port)
- peer->addr.sin_port = htons(DEFAULT_SIP_PORT);
- }
- }
- } else if (!strcasecmp(v->name, "defaultip")) {
- if (ast_get_ip(&peer->defaddr, v->value)) {
- ASTOBJ_UNREF(peer, sip_destroy_peer);
- return NULL;
- }
- } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
- peer->ha = ast_append_ha(v->name, v->value, peer->ha);
- } else if (!strcasecmp(v->name, "port")) {
- if (!realtime && ast_test_flag(peer, SIP_DYNAMIC))
- peer->defaddr.sin_port = htons(atoi(v->value));
- else
- peer->addr.sin_port = htons(atoi(v->value));
- } else if (!strcasecmp(v->name, "callingpres")) {
- peer->callingpres = ast_parse_caller_presentation(v->value);
- if (peer->callingpres == -1)
- peer->callingpres = atoi(v->value);
- } else if (!strcasecmp(v->name, "username")) {
- ast_copy_string(peer->username, v->value, sizeof(peer->username));
- } else if (!strcasecmp(v->name, "language")) {
- ast_copy_string(peer->language, v->value, sizeof(peer->language));
- } else if (!strcasecmp(v->name, "regexten")) {
- ast_copy_string(peer->regexten, v->value, sizeof(peer->regexten));
- } else if (!strcasecmp(v->name, "call-limit") || !strcasecmp(v->name, "incominglimit")) {
- peer->call_limit = atoi(v->value);
- if (peer->call_limit < 0)
- peer->call_limit = 0;
- } else if (!strcasecmp(v->name, "amaflags")) {
- format = ast_cdr_amaflags2int(v->value);
- if (format < 0) {
- ast_log(LOG_WARNING, "Invalid AMA Flags for peer: %s at line %d\n", v->value, v->lineno);
- } else {
- peer->amaflags = format;
- }
- } else if (!strcasecmp(v->name, "accountcode")) {
- ast_copy_string(peer->accountcode, v->value, sizeof(peer->accountcode));
- } else if (!strcasecmp(v->name, "musicclass") || !strcasecmp(v->name, "musiconhold")) {
- ast_copy_string(peer->musicclass, v->value, sizeof(peer->musicclass));
- } else if (!strcasecmp(v->name, "mailbox")) {
- ast_copy_string(peer->mailbox, v->value, sizeof(peer->mailbox));
- } else if (!strcasecmp(v->name, "vmexten")) {
- ast_copy_string(peer->vmexten, v->value, sizeof(peer->vmexten));
- } else if (!strcasecmp(v->name, "callgroup")) {
- peer->callgroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "pickupgroup")) {
- peer->pickupgroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "allow")) {
- ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, 1);
- } else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, 0);
- } else if (!strcasecmp(v->name, "rtptimeout")) {
- if ((sscanf(v->value, "%d", &peer->rtptimeout) != 1) || (peer->rtptimeout < 0)) {
- ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
- peer->rtptimeout = global_rtptimeout;
- }
- } else if (!strcasecmp(v->name, "rtpholdtimeout")) {
- if ((sscanf(v->value, "%d", &peer->rtpholdtimeout) != 1) || (peer->rtpholdtimeout < 0)) {
- ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
- peer->rtpholdtimeout = global_rtpholdtimeout;
- }
- } else if (!strcasecmp(v->name, "rtpkeepalive")) {
- if ((sscanf(v->value, "%d", &peer->rtpkeepalive) != 1) || (peer->rtpkeepalive < 0)) {
- ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno);
- peer->rtpkeepalive = global_rtpkeepalive;
- }
- } else if (!strcasecmp(v->name, "setvar")) {
- /* Set peer channel variable */
- varname = ast_strdupa(v->value);
- if (varname && (varval = strchr(varname,'='))) {
- *varval = '\0';
- varval++;
- if ((tmpvar = ast_variable_new(varname, varval))) {
- tmpvar->next = peer->chanvars;
- peer->chanvars = tmpvar;
- }
- }
- } else if (!strcasecmp(v->name, "qualify")) {
- if (!strcasecmp(v->value, "no")) {
- peer->maxms = 0;
- } else if (!strcasecmp(v->value, "yes")) {
- peer->maxms = DEFAULT_MAXMS;
- } else if (sscanf(v->value, "%d", &peer->maxms) != 1) {
- ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", peer->name, v->lineno);
- peer->maxms = 0;
- }
- }
- /* else if (strcasecmp(v->name,"type"))
- * ast_log(LOG_WARNING, "Ignoring %s\n", v->name);
- */
- v=v->next;
- }
- if (!ast_test_flag((&global_flags_page2), SIP_PAGE2_IGNOREREGEXPIRE) && ast_test_flag(peer, SIP_DYNAMIC) && realtime) {
- time_t nowtime;
-
- time(&nowtime);
- if ((nowtime - regseconds) > 0) {
- destroy_association(peer);
- memset(&peer->addr, 0, sizeof(peer->addr));
- if (option_debug)
- ast_log(LOG_DEBUG, "Bah, we're expired (%d/%d/%d)!\n", (int)(nowtime - regseconds), (int)regseconds, (int)nowtime);
- }
- }
- ast_copy_flags(peer, &peerflags, mask.flags);
- if (!found && ast_test_flag(peer, SIP_DYNAMIC) && !ast_test_flag(peer, SIP_REALTIME))
- reg_source_db(peer);
- ASTOBJ_UNMARK(peer);
- ast_free_ha(oldha);
- return peer;
-}
-
-/*! \brief reload_config: Re-read SIP.conf config file ---*/
-/* This function reloads all config data, except for
- active peers (with registrations). They will only
- change configuration data at restart, not at reload.
- SIP debug and recordhistory state will not change
- */
-static int reload_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- struct sip_peer *peer;
- struct sip_user *user;
- struct ast_hostent ahp;
- char *cat;
- char *utype;
- struct hostent *hp;
- int format;
- char iabuf[INET_ADDRSTRLEN];
- struct ast_flags dummy;
- int auto_sip_domains = 0;
- struct sockaddr_in old_bindaddr = bindaddr;
-
- cfg = ast_config_load(config);
-
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
- return -1;
- }
-
- /* Reset IP addresses */
- memset(&bindaddr, 0, sizeof(bindaddr));
- memset(&localaddr, 0, sizeof(localaddr));
- memset(&externip, 0, sizeof(externip));
- memset(&prefs, 0 , sizeof(prefs));
- sipdebug &= ~SIP_DEBUG_CONFIG;
-
- /* Initialize some reasonable defaults at SIP reload */
- ast_copy_string(default_context, DEFAULT_CONTEXT, sizeof(default_context));
- default_subscribecontext[0] = '\0';
- default_language[0] = '\0';
- default_fromdomain[0] = '\0';
- default_qualify = 0;
- allow_external_domains = 1; /* Allow external invites */
- externhost[0] = '\0';
- externexpire = 0;
- externrefresh = 10;
- ast_copy_string(default_useragent, DEFAULT_USERAGENT, sizeof(default_useragent));
- ast_copy_string(default_notifymime, DEFAULT_NOTIFYMIME, sizeof(default_notifymime));
- global_notifyringing = 1;
- ast_copy_string(global_realm, DEFAULT_REALM, sizeof(global_realm));
- ast_copy_string(global_musicclass, "default", sizeof(global_musicclass));
- ast_copy_string(default_callerid, DEFAULT_CALLERID, sizeof(default_callerid));
- memset(&outboundproxyip, 0, sizeof(outboundproxyip));
- outboundproxyip.sin_port = htons(DEFAULT_SIP_PORT);
- outboundproxyip.sin_family = AF_INET; /* Type of address: IPv4 */
- videosupport = 0;
- compactheaders = 0;
- dumphistory = 0;
- recordhistory = 0;
- relaxdtmf = 0;
- callevents = 0;
- ourport = DEFAULT_SIP_PORT;
- global_rtptimeout = 0;
- global_rtpholdtimeout = 0;
- global_rtpkeepalive = 0;
- pedanticsipchecking = 0;
- global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT;
- global_regattempts_max = 0;
- ast_clear_flag(&global_flags, AST_FLAGS_ALL);
- ast_set_flag(&global_flags, SIP_DTMF_RFC2833);
- ast_set_flag(&global_flags, SIP_NAT_RFC3581);
- ast_set_flag(&global_flags, SIP_CAN_REINVITE);
- ast_set_flag(&global_flags_page2, SIP_PAGE2_RTUPDATE);
- global_mwitime = DEFAULT_MWITIME;
- strcpy(global_vmexten, DEFAULT_VMEXTEN);
- srvlookup = 0;
- autocreatepeer = 0;
- regcontext[0] = '\0';
- tos = 0;
- expiry = DEFAULT_EXPIRY;
- global_allowguest = 1;
-
- /* Read the [general] config section of sip.conf (or from realtime config) */
- v = ast_variable_browse(cfg, "general");
- while(v) {
- if (handle_common_options(&global_flags, &dummy, v)) {
- v = v->next;
- continue;
- }
-
- /* Create the interface list */
- if (!strcasecmp(v->name, "context")) {
- ast_copy_string(default_context, v->value, sizeof(default_context));
- } else if (!strcasecmp(v->name, "realm")) {
- ast_copy_string(global_realm, v->value, sizeof(global_realm));
- } else if (!strcasecmp(v->name, "useragent")) {
- ast_copy_string(default_useragent, v->value, sizeof(default_useragent));
- ast_log(LOG_DEBUG, "Setting User Agent Name to %s\n",
- default_useragent);
- } else if (!strcasecmp(v->name, "rtcachefriends")) {
- ast_set2_flag((&global_flags_page2), ast_true(v->value), SIP_PAGE2_RTCACHEFRIENDS);
- } else if (!strcasecmp(v->name, "rtupdate")) {
- ast_set2_flag((&global_flags_page2), ast_true(v->value), SIP_PAGE2_RTUPDATE);
- } else if (!strcasecmp(v->name, "ignoreregexpire")) {
- ast_set2_flag((&global_flags_page2), ast_true(v->value), SIP_PAGE2_IGNOREREGEXPIRE);
- } else if (!strcasecmp(v->name, "rtautoclear")) {
- int i = atoi(v->value);
- if (i > 0)
- global_rtautoclear = i;
- else
- i = 0;
- ast_set2_flag((&global_flags_page2), i || ast_true(v->value), SIP_PAGE2_RTAUTOCLEAR);
- } else if (!strcasecmp(v->name, "usereqphone")) {
- ast_set2_flag((&global_flags), ast_true(v->value), SIP_USEREQPHONE);
- } else if (!strcasecmp(v->name, "relaxdtmf")) {
- relaxdtmf = ast_true(v->value);
- } else if (!strcasecmp(v->name, "checkmwi")) {
- if ((sscanf(v->value, "%d", &global_mwitime) != 1) || (global_mwitime < 0)) {
- ast_log(LOG_WARNING, "'%s' is not a valid MWI time setting at line %d. Using default (10).\n", v->value, v->lineno);
- global_mwitime = DEFAULT_MWITIME;
- }
- } else if (!strcasecmp(v->name, "vmexten")) {
- ast_copy_string(global_vmexten, v->value, sizeof(global_vmexten));
- } else if (!strcasecmp(v->name, "rtptimeout")) {
- if ((sscanf(v->value, "%d", &global_rtptimeout) != 1) || (global_rtptimeout < 0)) {
- ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
- global_rtptimeout = 0;
- }
- } else if (!strcasecmp(v->name, "rtpholdtimeout")) {
- if ((sscanf(v->value, "%d", &global_rtpholdtimeout) != 1) || (global_rtpholdtimeout < 0)) {
- ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
- global_rtpholdtimeout = 0;
- }
- } else if (!strcasecmp(v->name, "rtpkeepalive")) {
- if ((sscanf(v->value, "%d", &global_rtpkeepalive) != 1) || (global_rtpkeepalive < 0)) {
- ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno);
- global_rtpkeepalive = 0;
- }
- } else if (!strcasecmp(v->name, "videosupport")) {
- videosupport = ast_true(v->value);
- } else if (!strcasecmp(v->name, "compactheaders")) {
- compactheaders = ast_true(v->value);
- } else if (!strcasecmp(v->name, "notifymimetype")) {
- ast_copy_string(default_notifymime, v->value, sizeof(default_notifymime));
- } else if (!strcasecmp(v->name, "notifyringing")) {
- global_notifyringing = ast_true(v->value);
- } else if (!strcasecmp(v->name, "musicclass") || !strcasecmp(v->name, "musiconhold")) {
- ast_copy_string(global_musicclass, v->value, sizeof(global_musicclass));
- } else if (!strcasecmp(v->name, "language")) {
- ast_copy_string(default_language, v->value, sizeof(default_language));
- } else if (!strcasecmp(v->name, "regcontext")) {
- ast_copy_string(regcontext, v->value, sizeof(regcontext));
- /* Create context if it doesn't exist already */
- if (!ast_context_find(regcontext))
- ast_context_create(NULL, regcontext, channeltype);
- } else if (!strcasecmp(v->name, "callerid")) {
- ast_copy_string(default_callerid, v->value, sizeof(default_callerid));
- } else if (!strcasecmp(v->name, "fromdomain")) {
- ast_copy_string(default_fromdomain, v->value, sizeof(default_fromdomain));
- } else if (!strcasecmp(v->name, "outboundproxy")) {
- if (ast_get_ip_or_srv(&outboundproxyip, v->value, "_sip._udp") < 0)
- ast_log(LOG_WARNING, "Unable to locate host '%s'\n", v->value);
- } else if (!strcasecmp(v->name, "outboundproxyport")) {
- /* Port needs to be after IP */
- sscanf(v->value, "%d", &format);
- outboundproxyip.sin_port = htons(format);
- } else if (!strcasecmp(v->name, "autocreatepeer")) {
- autocreatepeer = ast_true(v->value);
- } else if (!strcasecmp(v->name, "srvlookup")) {
- srvlookup = ast_true(v->value);
- } else if (!strcasecmp(v->name, "pedantic")) {
- pedanticsipchecking = ast_true(v->value);
- } else if (!strcasecmp(v->name, "maxexpirey") || !strcasecmp(v->name, "maxexpiry")) {
- max_expiry = atoi(v->value);
- if (max_expiry < 1)
- max_expiry = DEFAULT_MAX_EXPIRY;
- } else if (!strcasecmp(v->name, "defaultexpiry") || !strcasecmp(v->name, "defaultexpirey")) {
- default_expiry = atoi(v->value);
- if (default_expiry < 1)
- default_expiry = DEFAULT_DEFAULT_EXPIRY;
- } else if (!strcasecmp(v->name, "sipdebug")) {
- if (ast_true(v->value))
- sipdebug |= SIP_DEBUG_CONFIG;
- } else if (!strcasecmp(v->name, "dumphistory")) {
- dumphistory = ast_true(v->value);
- } else if (!strcasecmp(v->name, "recordhistory")) {
- recordhistory = ast_true(v->value);
- } else if (!strcasecmp(v->name, "registertimeout")) {
- global_reg_timeout = atoi(v->value);
- if (global_reg_timeout < 1)
- global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT;
- } else if (!strcasecmp(v->name, "registerattempts")) {
- global_regattempts_max = atoi(v->value);
- } else if (!strcasecmp(v->name, "bindaddr")) {
- if (!(hp = ast_gethostbyname(v->value, &ahp))) {
- ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
- } else {
- memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
- }
- } else if (!strcasecmp(v->name, "localnet")) {
- struct ast_ha *na;
- if (!(na = ast_append_ha("d", v->value, localaddr)))
- ast_log(LOG_WARNING, "Invalid localnet value: %s\n", v->value);
- else
- localaddr = na;
- } else if (!strcasecmp(v->name, "localmask")) {
- ast_log(LOG_WARNING, "Use of localmask is no long supported -- use localnet with mask syntax\n");
- } else if (!strcasecmp(v->name, "externip")) {
- if (!(hp = ast_gethostbyname(v->value, &ahp)))
- ast_log(LOG_WARNING, "Invalid address for externip keyword: %s\n", v->value);
- else
- memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
- externexpire = 0;
- } else if (!strcasecmp(v->name, "externhost")) {
- ast_copy_string(externhost, v->value, sizeof(externhost));
- if (!(hp = ast_gethostbyname(externhost, &ahp)))
- ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost);
- else
- memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
- time(&externexpire);
- } else if (!strcasecmp(v->name, "externrefresh")) {
- if (sscanf(v->value, "%d", &externrefresh) != 1) {
- ast_log(LOG_WARNING, "Invalid externrefresh value '%s', must be an integer >0 at line %d\n", v->value, v->lineno);
- externrefresh = 10;
- }
- } else if (!strcasecmp(v->name, "allow")) {
- ast_parse_allow_disallow(&prefs, &global_capability, v->value, 1);
- } else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&prefs, &global_capability, v->value, 0);
- } else if (!strcasecmp(v->name, "allowexternaldomains")) {
- allow_external_domains = ast_true(v->value);
- } else if (!strcasecmp(v->name, "autodomain")) {
- auto_sip_domains = ast_true(v->value);
- } else if (!strcasecmp(v->name, "domain")) {
- char *domain = ast_strdupa(v->value);
- char *context = strchr(domain, ',');
-
- if (context)
- *context++ = '\0';
-
- if (ast_strlen_zero(domain))
- ast_log(LOG_WARNING, "Empty domain specified at line %d\n", v->lineno);
- else if (ast_strlen_zero(context))
- ast_log(LOG_WARNING, "Empty context specified at line %d for domain '%s'\n", v->lineno, domain);
- else
- add_sip_domain(ast_strip(domain), SIP_DOMAIN_CONFIG, context ? ast_strip(context) : "");
- } else if (!strcasecmp(v->name, "register")) {
- sip_register(v->value, v->lineno);
- } else if (!strcasecmp(v->name, "tos")) {
- if (ast_str2tos(v->value, &tos))
- ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
- } else if (!strcasecmp(v->name, "bindport")) {
- if (sscanf(v->value, "%d", &ourport) == 1) {
- bindaddr.sin_port = htons(ourport);
- } else {
- ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config);
- }
- } else if (!strcasecmp(v->name, "qualify")) {
- if (!strcasecmp(v->value, "no")) {
- default_qualify = 0;
- } else if (!strcasecmp(v->value, "yes")) {
- default_qualify = DEFAULT_MAXMS;
- } else if (sscanf(v->value, "%d", &default_qualify) != 1) {
- ast_log(LOG_WARNING, "Qualification default should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", v->lineno);
- default_qualify = 0;
- }
- } else if (!strcasecmp(v->name, "callevents")) {
- callevents = ast_true(v->value);
- }
- /* else if (strcasecmp(v->name,"type"))
- * ast_log(LOG_WARNING, "Ignoring %s\n", v->name);
- */
- v = v->next;
- }
-
- if (!allow_external_domains && AST_LIST_EMPTY(&domain_list)) {
- ast_log(LOG_WARNING, "To disallow external domains, you need to configure local SIP domains.\n");
- allow_external_domains = 1;
- }
-
- /* Build list of authentication to various SIP realms, i.e. service providers */
- v = ast_variable_browse(cfg, "authentication");
- while(v) {
- /* Format for authentication is auth = username:password@realm */
- if (!strcasecmp(v->name, "auth")) {
- authl = add_realm_authentication(authl, v->value, v->lineno);
- }
- v = v->next;
- }
-
- /* Load peers, users and friends */
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (strcasecmp(cat, "general") && strcasecmp(cat, "authentication")) {
- utype = ast_variable_retrieve(cfg, cat, "type");
- if (utype) {
- if (!strcasecmp(utype, "user") || !strcasecmp(utype, "friend")) {
- user = build_user(cat, ast_variable_browse(cfg, cat), 0);
- if (user) {
- ASTOBJ_CONTAINER_LINK(&userl,user);
- ASTOBJ_UNREF(user, sip_destroy_user);
- }
- }
- if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) {
- peer = build_peer(cat, ast_variable_browse(cfg, cat), 0);
- if (peer) {
- ASTOBJ_CONTAINER_LINK(&peerl,peer);
- ASTOBJ_UNREF(peer, sip_destroy_peer);
- }
- } else if (strcasecmp(utype, "user")) {
- ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf");
- }
- } else
- ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat);
- }
- cat = ast_category_browse(cfg, cat);
- }
- if (ast_find_ourip(&__ourip, bindaddr)) {
- ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n");
- return 0;
- }
- if (!ntohs(bindaddr.sin_port))
- bindaddr.sin_port = ntohs(DEFAULT_SIP_PORT);
- bindaddr.sin_family = AF_INET;
- ast_mutex_lock(&netlock);
- if ((sipsock > -1) && (memcmp(&old_bindaddr, &bindaddr, sizeof(struct sockaddr_in)))) {
- close(sipsock);
- sipsock = -1;
- }
- if (sipsock < 0) {
- sipsock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sipsock < 0) {
- ast_log(LOG_WARNING, "Unable to create SIP socket: %s\n", strerror(errno));
- } else {
- /* Allow SIP clients on the same host to access us: */
- const int reuseFlag = 1;
- setsockopt(sipsock, SOL_SOCKET, SO_REUSEADDR,
- (const char*)&reuseFlag,
- sizeof reuseFlag);
-
- if (bind(sipsock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) {
- ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port),
- strerror(errno));
- close(sipsock);
- sipsock = -1;
- } else {
- if (option_verbose > 1) {
- ast_verbose(VERBOSE_PREFIX_2 "SIP Listening on %s:%d\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port));
- ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos);
- }
- if (setsockopt(sipsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))
- ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
- }
- }
- }
- ast_mutex_unlock(&netlock);
-
- /* Add default domains - host name, IP address and IP:port */
- /* Only do this if user added any sip domain with "localdomains" */
- /* In order to *not* break backwards compatibility */
- /* Some phones address us at IP only, some with additional port number */
- if (auto_sip_domains) {
- char temp[MAXHOSTNAMELEN];
-
- /* First our default IP address */
- if (bindaddr.sin_addr.s_addr) {
- ast_inet_ntoa(temp, sizeof(temp), bindaddr.sin_addr);
- add_sip_domain(temp, SIP_DOMAIN_AUTO, NULL);
- } else {
- ast_log(LOG_NOTICE, "Can't add wildcard IP address to domain list, please add IP address to domain manually.\n");
- }
-
- /* Our extern IP address, if configured */
- if (externip.sin_addr.s_addr) {
- ast_inet_ntoa(temp, sizeof(temp), externip.sin_addr);
- add_sip_domain(temp, SIP_DOMAIN_AUTO, NULL);
- }
-
- /* Extern host name (NAT traversal support) */
- if (!ast_strlen_zero(externhost))
- add_sip_domain(externhost, SIP_DOMAIN_AUTO, NULL);
-
- /* Our host name */
- if (!gethostname(temp, sizeof(temp)))
- add_sip_domain(temp, SIP_DOMAIN_AUTO, NULL);
- }
-
- /* Release configuration from memory */
- ast_config_destroy(cfg);
-
- /* Load the list of manual NOTIFY types to support */
- if (notify_types)
- ast_config_destroy(notify_types);
- notify_types = ast_config_load(notify_config);
-
- return 0;
-}
-
-/*! \brief sip_get_rtp_peer: Returns null if we can't reinvite (part of RTP interface) */
-static struct ast_rtp *sip_get_rtp_peer(struct ast_channel *chan)
-{
- struct sip_pvt *p;
- struct ast_rtp *rtp = NULL;
- p = chan->tech_pvt;
- if (!p)
- return NULL;
- ast_mutex_lock(&p->lock);
- if (p->rtp && ast_test_flag(p, SIP_CAN_REINVITE)) {
- rtp = p->rtp;
-#ifdef SIP_MIDCOM
- if (m_cb)
- m_cb->ast_rtp_nat_us_audio_hook(rtp, p->r); /* change the ip port in rtp */
-#endif
- }
- ast_mutex_unlock(&p->lock);
- return rtp;
-}
-
-/*! \brief sip_get_vrtp_peer: Returns null if we can't reinvite video (part of RTP interface) */
-static struct ast_rtp *sip_get_vrtp_peer(struct ast_channel *chan)
-{
- struct sip_pvt *p;
- struct ast_rtp *rtp = NULL;
- p = chan->tech_pvt;
- if (!p)
- return NULL;
-
- ast_mutex_lock(&p->lock);
- if (p->vrtp && ast_test_flag(p, SIP_CAN_REINVITE)) {
- rtp = p->vrtp;
-#ifdef SIP_MIDCOM
- if (m_cb)
- m_cb->ast_rtp_nat_us_video_hook(rtp, p->r); /* change the ip port in rtp */
-#endif
- }
- ast_mutex_unlock(&p->lock);
- return rtp;
-}
-
-/*! \brief sip_set_rtp_peer: Set the RTP peer for this call ---*/
-static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active)
-{
- struct sip_pvt *p;
-
- p = chan->tech_pvt;
- if (!p)
- return -1;
- ast_mutex_lock(&p->lock);
- if (rtp) {
- ast_rtp_get_peer(rtp, &p->redirip);
-#ifdef SIP_MIDCOM
- if (m_cb)
- m_cb->ast_rtp_get_their_nat_audio_hook(rtp, p->r);
-#endif
- }
- else
- memset(&p->redirip, 0, sizeof(p->redirip));
- if (vrtp) {
- ast_rtp_get_peer(vrtp, &p->vredirip);
-#ifdef SIP_MIDCOM
- if (m_cb)
- m_cb->ast_rtp_get_their_nat_video_hook(vrtp, p->r);
-#endif
- }
- else
- memset(&p->vredirip, 0, sizeof(p->vredirip));
- p->redircodecs = codecs;
- if (!ast_test_flag(p, SIP_GOTREFER)) {
- if (!p->pendinginvite) {
- if (option_debug > 2) {
- char iabuf[INET_ADDRSTRLEN];
- ast_log(LOG_DEBUG, "Sending reinvite on SIP '%s' - It's audio soon redirected to IP %s\n", p->callid, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp ? p->redirip.sin_addr : p->ourip));
- }
- transmit_reinvite_with_sdp(p);
- } else if (!ast_test_flag(p, SIP_PENDINGBYE)) {
- if (option_debug > 2) {
- char iabuf[INET_ADDRSTRLEN];
- ast_log(LOG_DEBUG, "Deferring reinvite on SIP '%s' - It's audio will be redirected to IP %s\n", p->callid, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp ? p->redirip.sin_addr : p->ourip));
- }
- ast_set_flag(p, SIP_NEEDREINVITE);
- }
- }
- /* Reset lastrtprx timer */
- time(&p->lastrtprx);
- time(&p->lastrtptx);
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-static char *synopsis_dtmfmode = "Change the dtmfmode for a SIP call";
-static char *descrip_dtmfmode = "SIPDtmfMode(inband|info|rfc2833): Changes the dtmfmode for a SIP call\n";
-static char *app_dtmfmode = "SIPDtmfMode";
-
-static char *app_sipaddheader = "SIPAddHeader";
-static char *synopsis_sipaddheader = "Add a SIP header to the outbound call";
-
-
-static char *descrip_sipaddheader = ""
-" SIPAddHeader(Header: Content)\n"
-"Adds a header to a SIP call placed with DIAL.\n"
-"Remember to user the X-header if you are adding non-standard SIP\n"
-"headers, like \"X-Asterisk-Accountcode:\". Use this with care.\n"
-"Adding the wrong headers may jeopardize the SIP dialog.\n"
-"Always returns 0\n";
-
-static char *app_sipgetheader = "SIPGetHeader";
-static char *synopsis_sipgetheader = "Get a SIP header from an incoming call";
-
-static char *descrip_sipgetheader = ""
-" SIPGetHeader(var=headername): \n"
-"Sets a channel variable to the content of a SIP header\n"
-"Skips to priority+101 if header does not exist\n"
-"Otherwise returns 0\n";
-
-/*! \brief sip_dtmfmode: change the DTMFmode for a SIP call (application) ---*/
-static int sip_dtmfmode(struct ast_channel *chan, void *data)
-{
- struct sip_pvt *p;
- char *mode;
- if (data)
- mode = (char *)data;
- else {
- ast_log(LOG_WARNING, "This application requires the argument: info, inband, rfc2833\n");
- return 0;
- }
- ast_mutex_lock(&chan->lock);
- if (chan->type != channeltype) {
- ast_log(LOG_WARNING, "Call this application only on SIP incoming calls\n");
- ast_mutex_unlock(&chan->lock);
- return 0;
- }
- p = chan->tech_pvt;
- if (!p) {
- ast_mutex_unlock(&chan->lock);
- return 0;
- }
- ast_mutex_lock(&p->lock);
- if (!strcasecmp(mode,"info")) {
- ast_clear_flag(p, SIP_DTMF);
- ast_set_flag(p, SIP_DTMF_INFO);
- } else if (!strcasecmp(mode,"rfc2833")) {
- ast_clear_flag(p, SIP_DTMF);
- ast_set_flag(p, SIP_DTMF_RFC2833);
- } else if (!strcasecmp(mode,"inband")) {
- ast_clear_flag(p, SIP_DTMF);
- ast_set_flag(p, SIP_DTMF_INBAND);
- } else
- ast_log(LOG_WARNING, "I don't know about this dtmf mode: %s\n",mode);
- if (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_INBAND) {
- if (!p->vad) {
- p->vad = ast_dsp_new();
- ast_dsp_set_features(p->vad, DSP_FEATURE_DTMF_DETECT);
- }
- } else {
- if (p->vad) {
- ast_dsp_free(p->vad);
- p->vad = NULL;
- }
- }
- ast_mutex_unlock(&p->lock);
- ast_mutex_unlock(&chan->lock);
- return 0;
-}
-
-/*! \brief sip_addheader: Add a SIP header ---*/
-static int sip_addheader(struct ast_channel *chan, void *data)
-{
- int no = 0;
- int ok = 0;
- char varbuf[128];
-
- if (ast_strlen_zero((char *)data)) {
- ast_log(LOG_WARNING, "This application requires the argument: Header\n");
- return 0;
- }
- ast_mutex_lock(&chan->lock);
-
- /* Check for headers */
- while (!ok && no <= 50) {
- no++;
- snprintf(varbuf, sizeof(varbuf), "_SIPADDHEADER%02d", no);
- if (ast_strlen_zero(pbx_builtin_getvar_helper(chan, varbuf + 1)))
- ok = 1;
- }
- if (ok) {
- pbx_builtin_setvar_helper (chan, varbuf, (char *)data);
- if (sipdebug)
- ast_log(LOG_DEBUG,"SIP Header added \"%s\" as %s\n", (char *) data, varbuf);
- } else {
- ast_log(LOG_WARNING, "Too many SIP headers added, max 50\n");
- }
- ast_mutex_unlock(&chan->lock);
- return 0;
-}
-
-/*! \brief sip_getheader: Get a SIP header (dialplan app) ---*/
-static int sip_getheader(struct ast_channel *chan, void *data)
-{
- static int dep_warning = 0;
- struct sip_pvt *p;
- char *argv, *varname = NULL, *header = NULL, *content;
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "SIPGetHeader is deprecated, use the SIP_HEADER function instead.\n");
- dep_warning = 1;
- }
-
- argv = ast_strdupa(data);
- if (!argv) {
- ast_log(LOG_DEBUG, "Memory allocation failed\n");
- return 0;
- }
-
- if (strchr (argv, '=') ) { /* Pick out argumenet */
- varname = strsep (&argv, "=");
- header = strsep (&argv, "\0");
- }
-
- if (!varname || !header) {
- ast_log(LOG_DEBUG, "SipGetHeader: Ignoring command, Syntax error in argument\n");
- return 0;
- }
-
- ast_mutex_lock(&chan->lock);
- if (chan->type != channeltype) {
- ast_log(LOG_WARNING, "Call this application only on incoming SIP calls\n");
- ast_mutex_unlock(&chan->lock);
- return 0;
- }
-
- p = chan->tech_pvt;
- content = get_header(&p->initreq, header); /* Get the header */
- if (!ast_strlen_zero(content)) {
- pbx_builtin_setvar_helper(chan, varname, content);
- } else {
- ast_log(LOG_WARNING,"SIP Header %s not found for channel variable %s\n", header, varname);
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
- }
-
- ast_mutex_unlock(&chan->lock);
- return 0;
-}
-
-/*! \brief sip_sipredirect: Transfer call before connect with a 302 redirect ---*/
-/* Called by the transfer() dialplan application through the sip_transfer() */
-/* pbx interface function if the call is in ringing state */
-/* coded by Martin Pycko (m78pl@yahoo.com) */
-static int sip_sipredirect(struct sip_pvt *p, const char *dest)
-{
- char *cdest;
- char *extension, *host, *port;
- char tmp[80];
-
- cdest = ast_strdupa(dest);
- if (!cdest) {
- ast_log(LOG_ERROR, "Problem allocating the memory\n");
- return 0;
- }
- extension = strsep(&cdest, "@");
- host = strsep(&cdest, ":");
- port = strsep(&cdest, ":");
- if (!extension) {
- ast_log(LOG_ERROR, "Missing mandatory argument: extension\n");
- return 0;
- }
-
- /* we'll issue the redirect message here */
- if (!host) {
- char *localtmp;
- ast_copy_string(tmp, get_header(&p->initreq, "To"), sizeof(tmp));
- if (!strlen(tmp)) {
- ast_log(LOG_ERROR, "Cannot retrieve the 'To' header from the original SIP request!\n");
- return 0;
- }
- if ((localtmp = strstr(tmp, "sip:")) && (localtmp = strchr(localtmp, '@'))) {
- char lhost[80], lport[80];
- memset(lhost, 0, sizeof(lhost));
- memset(lport, 0, sizeof(lport));
- localtmp++;
- /* This is okey because lhost and lport are as big as tmp */
- sscanf(localtmp, "%[^<>:; ]:%[^<>:; ]", lhost, lport);
- if (!strlen(lhost)) {
- ast_log(LOG_ERROR, "Can't find the host address\n");
- return 0;
- }
- host = ast_strdupa(lhost);
- if (!host) {
- ast_log(LOG_ERROR, "Problem allocating the memory\n");
- return 0;
- }
- if (!ast_strlen_zero(lport)) {
- port = ast_strdupa(lport);
- if (!port) {
- ast_log(LOG_ERROR, "Problem allocating the memory\n");
- return 0;
- }
- }
- }
- }
-
- snprintf(p->our_contact, sizeof(p->our_contact), "Transfer <sip:%s@%s%s%s>", extension, host, port ? ":" : "", port ? port : "");
- transmit_response_reliable(p, "302 Moved Temporarily", &p->initreq, 1);
-
- /* this is all that we want to send to that SIP device */
- ast_set_flag(p, SIP_ALREADYGONE);
-
- /* hangup here */
- return -1;
-}
-
-/*! \brief sip_get_codec: Return SIP UA's codec (part of the RTP interface) ---*/
-static int sip_get_codec(struct ast_channel *chan)
-{
- struct sip_pvt *p = chan->tech_pvt;
- return p->peercapability;
-}
-
-/*! \brief sip_rtp: Interface structure with callbacks used to connect to rtp module --*/
-static struct ast_rtp_protocol sip_rtp = {
- type: channeltype,
- get_rtp_info: sip_get_rtp_peer,
- get_vrtp_info: sip_get_vrtp_peer,
- set_rtp_peer: sip_set_rtp_peer,
- get_codec: sip_get_codec,
-};
-
-#ifdef SIP_MIDCOM
-/*! \brief sip_helper: Interface structure with callbacks used to connect to midcom module --*/
-static struct ast_sip_helper_cb sip_helper = {
- ast_rtp_get_peer_audio_helper: sip_rtp_get_peer_audio_helper,
- ast_rtp_get_peer_video_helper: sip_rtp_get_peer_video_helper,
- ast_rtp_get_us_audio_helper: sip_rtp_get_us_audio_helper,
- ast_rtp_get_us_video_helper: sip_rtp_get_us_video_helper,
- ast_map_hook_struct: sip_map_hook_struct,
- ast_get_hook_struct: sip_get_hook_struct,
- ast_get_flag_novideo: sip_get_flag_novideo,
- ast_cmp_sa_addr: sip_cmp_sa_addr,
- ast_get_recv_addr: sip_get_recv_addr,
- ast_get_username: sip_get_username,
- ast_channel_helper: sip_channel_helper,
- ast_bridged_channel_helper: sip_bridged_channel_helper,
- ast_get_capability_helper: sip_get_capability_helper,
- ast_softhangup_helper: sip_softhangup_helper,
-};
-#endif
-
-/*! \brief sip_poke_all_peers: Send a poke to all known peers */
-static void sip_poke_all_peers(void)
-{
- ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
- ASTOBJ_WRLOCK(iterator);
- sip_poke_peer(iterator);
- ASTOBJ_UNLOCK(iterator);
- } while (0)
- );
-}
-
-/*! \brief sip_send_all_registers: Send all known registrations */
-static void sip_send_all_registers(void)
-{
- int ms;
- int regspacing;
- if (!regobjs)
- return;
- regspacing = default_expiry * 1000/regobjs;
- if (regspacing > 100)
- regspacing = 100;
- ms = regspacing;
- ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
- ASTOBJ_WRLOCK(iterator);
- if (iterator->expire > -1)
- ast_sched_del(sched, iterator->expire);
- ms += regspacing;
- iterator->expire = ast_sched_add(sched, ms, sip_reregister, iterator);
- ASTOBJ_UNLOCK(iterator);
- } while (0)
- );
-}
-
-/*! \brief sip_do_reload: Reload module */
-static int sip_do_reload(void)
-{
- clear_realm_authentication(authl);
- clear_sip_domains();
- authl = NULL;
-
- /* First, destroy all outstanding registry calls */
- /* This is needed, since otherwise active registry entries will not be destroyed */
- ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
- ASTOBJ_RDLOCK(iterator);
- if (iterator->call) {
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Destroying active SIP dialog for registry %s@%s\n", iterator->username, iterator->hostname);
- /* This will also remove references to the registry */
- sip_destroy(iterator->call);
- }
- ASTOBJ_UNLOCK(iterator);
- } while(0));
-
- ASTOBJ_CONTAINER_DESTROYALL(&userl, sip_destroy_user);
- ASTOBJ_CONTAINER_DESTROYALL(&regl, sip_registry_destroy);
- ASTOBJ_CONTAINER_MARKALL(&peerl);
- reload_config();
- /* Prune peers who still are supposed to be deleted */
- ASTOBJ_CONTAINER_PRUNE_MARKED(&peerl, sip_destroy_peer);
-
- sip_poke_all_peers();
- sip_send_all_registers();
-
- return 0;
-}
-
-/*! \brief sip_reload: Force reload of module from cli ---*/
-static int sip_reload(int fd, int argc, char *argv[])
-{
-
- ast_mutex_lock(&sip_reload_lock);
- if (sip_reloading) {
- ast_verbose("Previous SIP reload not yet done\n");
- } else
- sip_reloading = 1;
- ast_mutex_unlock(&sip_reload_lock);
- restart_monitor();
-
- return 0;
-}
-
-/*! \brief reload: Part of Asterisk module interface ---*/
-int reload(void)
-{
- return sip_reload(0, 0, NULL);
-}
-
-static struct ast_cli_entry my_clis[] = {
- { { "sip", "notify", NULL }, sip_notify, "Send a notify packet to a SIP peer", notify_usage, complete_sipnotify },
- { { "sip", "show", "objects", NULL }, sip_show_objects, "Show all SIP object allocations", show_objects_usage },
- { { "sip", "show", "users", NULL }, sip_show_users, "Show defined SIP users", show_users_usage },
- { { "sip", "show", "user", NULL }, sip_show_user, "Show details on specific SIP user", show_user_usage, complete_sip_show_user },
- { { "sip", "show", "subscriptions", NULL }, sip_show_subscriptions, "Show active SIP subscriptions", show_subscriptions_usage},
- { { "sip", "show", "channels", NULL }, sip_show_channels, "Show active SIP channels", show_channels_usage},
- { { "sip", "show", "channel", NULL }, sip_show_channel, "Show detailed SIP channel info", show_channel_usage, complete_sipch },
- { { "sip", "show", "history", NULL }, sip_show_history, "Show SIP dialog history", show_history_usage, complete_sipch },
- { { "sip", "show", "domains", NULL }, sip_show_domains, "List our local SIP domains.", show_domains_usage },
- { { "sip", "show", "settings", NULL }, sip_show_settings, "Show SIP global settings", show_settings_usage },
- { { "sip", "debug", NULL }, sip_do_debug, "Enable SIP debugging", debug_usage },
- { { "sip", "debug", "ip", NULL }, sip_do_debug, "Enable SIP debugging on IP", debug_usage },
- { { "sip", "debug", "peer", NULL }, sip_do_debug, "Enable SIP debugging on Peername", debug_usage, complete_sip_debug_peer },
- { { "sip", "show", "peer", NULL }, sip_show_peer, "Show details on specific SIP peer", show_peer_usage, complete_sip_show_peer },
- { { "sip", "show", "peers", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage },
- { { "sip", "prune", "realtime", NULL }, sip_prune_realtime,
- "Prune cached Realtime object(s)", prune_realtime_usage },
- { { "sip", "prune", "realtime", "peer", NULL }, sip_prune_realtime,
- "Prune cached Realtime peer(s)", prune_realtime_usage, complete_sip_prune_realtime_peer },
- { { "sip", "prune", "realtime", "user", NULL }, sip_prune_realtime,
- "Prune cached Realtime user(s)", prune_realtime_usage, complete_sip_prune_realtime_user },
- { { "sip", "show", "inuse", NULL }, sip_show_inuse, "List all inuse/limits", show_inuse_usage },
- { { "sip", "show", "registry", NULL }, sip_show_registry, "Show SIP registration status", show_reg_usage },
- { { "sip", "history", NULL }, sip_do_history, "Enable SIP history", history_usage },
- { { "sip", "no", "history", NULL }, sip_no_history, "Disable SIP history", no_history_usage },
- { { "sip", "no", "debug", NULL }, sip_no_debug, "Disable SIP debugging", no_debug_usage },
- { { "sip", "reload", NULL }, sip_reload, "Reload SIP configuration", sip_reload_usage },
-};
-
-/*! \brief load_module: PBX load module - initialization ---*/
-int load_module()
-{
- ASTOBJ_CONTAINER_INIT(&userl); /* User object list */
- ASTOBJ_CONTAINER_INIT(&peerl); /* Peer object list */
- ASTOBJ_CONTAINER_INIT(&regl); /* Registry object list */
-
- sched = sched_context_create();
- if (!sched) {
- ast_log(LOG_WARNING, "Unable to create schedule context\n");
- }
-
- io = io_context_create();
- if (!io) {
- ast_log(LOG_WARNING, "Unable to create I/O context\n");
- }
-
- reload_config(); /* Load the configuration from sip.conf */
-
- /* Make sure we can register our sip channel type */
- if (ast_channel_register(&sip_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel type %s\n", channeltype);
- return -1;
- }
-
- /* Register all CLI functions for SIP */
- ast_cli_register_multiple(my_clis, sizeof(my_clis)/ sizeof(my_clis[0]));
-
- /* Tell the RTP subdriver that we're here */
- ast_rtp_proto_register(&sip_rtp);
-
-#ifdef SIP_MIDCOM
- /* Register the sip helper functions */
- if (m_cb)
- m_cb->ast_sip_helper_register(&sip_helper);
-#endif
-
- /* Register dialplan applications */
- ast_register_application(app_dtmfmode, sip_dtmfmode, synopsis_dtmfmode, descrip_dtmfmode);
-
- /* These will be removed soon */
- ast_register_application(app_sipaddheader, sip_addheader, synopsis_sipaddheader, descrip_sipaddheader);
- ast_register_application(app_sipgetheader, sip_getheader, synopsis_sipgetheader, descrip_sipgetheader);
-
- /* Register dialplan functions */
- ast_custom_function_register(&sip_header_function);
- ast_custom_function_register(&sippeer_function);
- ast_custom_function_register(&sipchaninfo_function);
- ast_custom_function_register(&checksipdomain_function);
-
- /* Register manager commands */
- ast_manager_register2("SIPpeers", EVENT_FLAG_SYSTEM, manager_sip_show_peers,
- "List SIP peers (text format)", mandescr_show_peers);
- ast_manager_register2("SIPshowpeer", EVENT_FLAG_SYSTEM, manager_sip_show_peer,
- "Show SIP peer (text format)", mandescr_show_peer);
-
- sip_poke_all_peers();
- sip_send_all_registers();
-
- /* And start the monitor for the first time */
- restart_monitor();
-
- return 0;
-}
-
-int unload_module()
-{
- struct sip_pvt *p, *pl;
-
- /* First, take us out of the channel type list */
- ast_channel_unregister(&sip_tech);
-
- ast_custom_function_unregister(&sipchaninfo_function);
- ast_custom_function_unregister(&sippeer_function);
- ast_custom_function_unregister(&sip_header_function);
- ast_custom_function_unregister(&checksipdomain_function);
-
- ast_unregister_application(app_dtmfmode);
- ast_unregister_application(app_sipaddheader);
- ast_unregister_application(app_sipgetheader);
-
- ast_cli_unregister_multiple(my_clis, sizeof(my_clis) / sizeof(my_clis[0]));
-
- ast_rtp_proto_unregister(&sip_rtp);
-
-#ifdef SIP_MIDCOM
- /* Unregister the sip helper functions */
- if (m_cb)
- m_cb->ast_sip_helper_unregister();
-#endif
-
- ast_manager_unregister("SIPpeers");
- ast_manager_unregister("SIPshowpeer");
-
- if (!ast_mutex_lock(&iflock)) {
- /* Hangup all interfaces if they have an owner */
- p = iflist;
- while (p) {
- if (p->owner)
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- p = p->next;
- }
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- return -1;
- }
-
- if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
- pthread_cancel(monitor_thread);
- pthread_kill(monitor_thread, SIGURG);
- pthread_join(monitor_thread, NULL);
- }
- monitor_thread = AST_PTHREADT_STOP;
- ast_mutex_unlock(&monlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-
- if (!ast_mutex_lock(&iflock)) {
- /* Destroy all the interfaces and free their memory */
- p = iflist;
- while (p) {
- pl = p;
- p = p->next;
- /* Free associated memory */
- ast_mutex_destroy(&pl->lock);
- if (pl->chanvars) {
- ast_variables_destroy(pl->chanvars);
- pl->chanvars = NULL;
- }
- free(pl);
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- return -1;
- }
-
- /* Free memory for local network address mask */
- ast_free_ha(localaddr);
-
- ASTOBJ_CONTAINER_DESTROYALL(&userl, sip_destroy_user);
- ASTOBJ_CONTAINER_DESTROY(&userl);
- ASTOBJ_CONTAINER_DESTROYALL(&peerl, sip_destroy_peer);
- ASTOBJ_CONTAINER_DESTROY(&peerl);
- ASTOBJ_CONTAINER_DESTROYALL(&regl, sip_registry_destroy);
- ASTOBJ_CONTAINER_DESTROY(&regl);
-
- clear_realm_authentication(authl);
- clear_sip_domains();
- close(sipsock);
- sched_context_destroy(sched);
-
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-#ifdef SIP_MIDCOM
-static void sip_rtp_get_peer_audio_helper(void *p, struct sockaddr_in *them)
-{
- ast_rtp_get_peer(((struct sip_pvt*)p)->rtp, them);
-}
-
-static void sip_rtp_get_peer_video_helper(void *p, struct sockaddr_in *them)
-{
- ast_rtp_get_peer(((struct sip_pvt*)p)->vrtp, them);
-}
-
-static void sip_rtp_get_us_audio_helper(void *p, struct sockaddr_in *sin)
-{
- ast_rtp_get_us(((struct sip_pvt*)p)->rtp, sin);
- sin->sin_addr = ((struct sip_pvt*)p)->ourip;
-}
-
-static void sip_rtp_get_us_video_helper(void *p, struct sockaddr_in *vsin)
-{
- ast_rtp_get_us(((struct sip_pvt*)p)->vrtp, vsin);
- vsin->sin_addr = ((struct sip_pvt*)p)->ourip;
-}
-
-static void sip_map_hook_struct(void *p, void *r)
-{
- ((struct sip_pvt*)p)->r = r;
-}
-
-static void *sip_get_hook_struct(void *p)
-{
- return ((struct sip_pvt*)p)->r;
-}
-
-static int sip_get_flag_novideo(void *p)
-{
- return ast_test_flag((struct sip_pvt*)p, SIP_NOVIDEO);
-}
-
-static int sip_cmp_sa_addr(void *p, struct sockaddr_in *addr)
-{
- return (((struct sip_pvt*)p)->sa.sin_addr.s_addr == addr->sin_addr.s_addr);
-}
-
-static void sip_get_recv_addr(void *p, struct in_addr *addr)
-{
- memcpy(addr, &((struct sip_pvt *)p)->recv.sin_addr, sizeof(struct in_addr));
-}
-
-static char *sip_get_username(void *p)
-{
- return ((struct sip_pvt*)p)->username;
-}
-
-static struct ast_channel *sip_channel_helper(void *p)
-{
- return ((struct sip_pvt*)p)->owner;
-}
-
-static struct ast_channel *sip_bridged_channel_helper(void *p)
-{
- return ast_bridged_channel(((struct sip_pvt*)p)->owner);
-}
-
-static int sip_get_capability_helper(void *p)
-{
- return ((struct sip_pvt*)p)->jointcapability;
-}
-
-static void sip_softhangup_helper(void *p)
-{
- if (p && ((struct sip_pvt *)p)->owner)
- ast_softhangup(((struct sip_pvt *)p)->owner, AST_SOFTHANGUP_APPUNLOAD);
-}
-#endif
-
diff --git a/1.2-netsec/channels/chan_skinny.c b/1.2-netsec/channels/chan_skinny.c
deleted file mode 100644
index 37321a355..000000000
--- a/1.2-netsec/channels/chan_skinny.c
+++ /dev/null
@@ -1,3381 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * chan_skinny was developed by Jeremy McNamara & Florian Overkamp
- *
- * 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 Implementation of the Skinny protocol
- *
- * \author Jeremy McNamara & Florian Overkamp
- * \ingroup channel_drivers
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <sys/signal.h>
-#include <signal.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp.h"
-#include "asterisk/acl.h"
-#include "asterisk/callerid.h"
-#include "asterisk/cli.h"
-#include "asterisk/say.h"
-#include "asterisk/cdr.h"
-#include "asterisk/astdb.h"
-#include "asterisk/features.h"
-#include "asterisk/app.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/utils.h"
-#include "asterisk/dsp.h"
-
-/************************************************************************************/
-/* Skinny/Asterisk Protocol Settings */
-/************************************************************************************/
-static const char desc[] = "Skinny Client Control Protocol (Skinny)";
-static const char tdesc[] = "Skinny Client Control Protocol (Skinny)";
-static const char type[] = "Skinny";
-static const char config[] = "skinny.conf";
-
-/* Just about everybody seems to support ulaw, so make it a nice default */
-static int capability = AST_FORMAT_ULAW;
-
-#define DEFAULT_SKINNY_PORT 2000
-#define DEFAULT_SKINNY_BACKLOG 2
-#define SKINNY_MAX_PACKET 1000
-
-static int keep_alive = 120;
-static char date_format[6] = "D-M-Y";
-static char version_id[16] = "P002F202";
-
-/* these should be in an include file, but dunno what to include */
-typedef unsigned char UINT8;
-typedef unsigned short UINT16;
-typedef unsigned int UINT32;
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define letohl(x) (x)
-#define letohs(x) (x)
-#define htolel(x) (x)
-#define htoles(x) (x)
-#else
-#if defined(SOLARIS) || defined(__Darwin__) || defined(__NetBSD__)
-#define __bswap_16(x) \
- ((((x) & 0xff00) >> 8) | \
- (((x) & 0x00ff) << 8))
-#define __bswap_32(x) \
- ((((x) & 0xff000000) >> 24) | \
- (((x) & 0x00ff0000) >> 8) | \
- (((x) & 0x0000ff00) << 8) | \
- (((x) & 0x000000ff) << 24))
-#else
-#include <bits/byteswap.h>
-#endif
-#define letohl(x) __bswap_32(x)
-#define letohs(x) __bswap_16(x)
-#define htolel(x) __bswap_32(x)
-#define htoles(x) __bswap_16(x)
-#endif
-
-
-/************************************************************************************/
-/* Protocol Messages */
-/************************************************************************************/
-/* message types */
-#define KEEP_ALIVE_MESSAGE 0x0000
-/* no additional struct */
-
-#define REGISTER_MESSAGE 0x0001
-typedef struct register_message {
- char name[16];
- int userId;
- int instance;
- char ip[4];
- int type;
- int maxStreams;
-} register_message;
-
-#define IP_PORT_MESSAGE 0x0002
-
-#define KEYPAD_BUTTON_MESSAGE 0x0003
-typedef struct keypad_button_message {
- int button;
-} keypad_button_message;
-
-#define STIMULUS_MESSAGE 0x0005
-typedef struct stimulus_message {
- int stimulus;
- int stimulusInstance;
-} stimulus_message;
-
-#define OFFHOOK_MESSAGE 0x0006
-#define ONHOOK_MESSAGE 0x0007
-
-#define CAPABILITIES_RES_MESSAGE 0x0010
-typedef struct station_capabilities {
- int codec;
- int frames;
- union {
- char res[8];
- long rate;
- } payloads;
-} station_capabilities;
-
-typedef struct capabilities_res_message {
- int count;
- struct station_capabilities caps[18];
-} capabilities_res_message;
-
-#define SPEED_DIAL_STAT_REQ_MESSAGE 0x000A
-typedef struct speed_dial_stat_req_message {
- int speedDialNumber;
-} speed_dial_stat_req_message;
-
-#define LINE_STATE_REQ_MESSAGE 0x000B
-typedef struct line_state_req_message {
- int lineNumber;
-} line_state_req_message;
-
-#define TIME_DATE_REQ_MESSAGE 0x000D
-#define VERSION_REQ_MESSAGE 0x000F
-#define BUTTON_TEMPLATE_REQ_MESSAGE 0x000E
-#define SERVER_REQUEST_MESSAGE 0x0012
-#define ALARM_MESSAGE 0x0020
-
-#define OPEN_RECIEVE_CHANNEL_ACK_MESSAGE 0x0022
-typedef struct open_recieve_channel_ack_message {
- int status;
- char ipAddr[4];
- int port;
- int passThruId;
-} open_recieve_channel_ack_message;
-
-#define SOFT_KEY_SET_REQ_MESSAGE 0x0025
-#define UNREGISTER_MESSAGE 0x0027
-#define SOFT_KEY_TEMPLATE_REQ_MESSAGE 0x0028
-
-#define REGISTER_ACK_MESSAGE 0x0081
-typedef struct register_ack_message {
- int keepAlive;
- char dateTemplate[6];
- char res[2];
- int secondaryKeepAlive;
- char res2[4];
-} register_ack_message;
-
-#define START_TONE_MESSAGE 0x0082
-typedef struct start_tone_message {
- int tone;
-} start_tone_message;
-
-#define STOP_TONE_MESSAGE 0x0083
-
-#define SET_RINGER_MESSAGE 0x0085
-typedef struct set_ringer_message {
- int ringerMode;
-} set_ringer_message;
-
-#define SET_LAMP_MESSAGE 0x0086
-typedef struct set_lamp_message {
- int stimulus;
- int stimulusInstance;
- int deviceStimulus;
-} set_lamp_message;
-
-#define SET_SPEAKER_MESSAGE 0x0088
-typedef struct set_speaker_message {
- int mode;
-} set_speaker_message;
-
-#define START_MEDIA_TRANSMISSION_MESSAGE 0x008A
-typedef struct media_qualifier {
- int precedence;
- int vad;
- int packets;
- int bitRate;
-} media_qualifier;
-
-typedef struct start_media_transmission_message {
- int conferenceId;
- int passThruPartyId;
- char remoteIp[4];
- int remotePort;
- int packetSize;
- int payloadType;
- media_qualifier qualifier;
-} start_media_transmission_message;
-
-#define STOP_MEDIA_TRANSMISSION_MESSAGE 0x008B
-typedef struct stop_media_transmission_message {
- int conferenceId;
- int passThruPartyId;
-} stop_media_transmission_message;
-
-#define CALL_INFO_MESSAGE 0x008F
-typedef struct call_info_message {
- char callingPartyName[40];
- char callingParty[24];
- char calledPartyName[40];
- char calledParty[24];
- int instance;
- int reference;
- int type;
- char originalCalledPartyName[40];
- char originalCalledParty[24];
-} call_info_message;
-
-#define SPEED_DIAL_STAT_RES_MESSAGE 0x0091
-typedef struct speed_dial_stat_res_message {
- int speedDialNumber;
- char speedDialDirNumber[24];
- char speedDialDisplayName[40];
-} speed_dial_stat_res_message;
-
-#define LINE_STAT_RES_MESSAGE 0x0092
-typedef struct line_stat_res_message {
- int linenumber;
- char lineDirNumber[24];
- char lineDisplayName[42];
- int space;
-} line_stat_res_message;
-
-#define DEFINETIMEDATE_MESSAGE 0x0094
-typedef struct definetimedate_message {
- int year; /* since 1900 */
- int month;
- int dayofweek; /* monday = 1 */
- int day;
- int hour;
- int minute;
- int seconds;
- int milliseconds;
- int timestamp;
-} definetimedate_message;
-
-#define DISPLAYTEXT_MESSAGE 0x0099
-typedef struct displaytext_message {
- char text[40];
-} displaytext_message;
-
-#define CLEAR_DISPLAY_MESSAGE 0x009A
-
-#define REGISTER_REJ_MESSAGE 0x009D
-typedef struct register_rej_message {
- char errMsg[33];
-} register_rej_message;
-
-#define CAPABILITIES_REQ_MESSAGE 0x009B
-
-#define SERVER_RES_MESSAGE 0x009E
-typedef struct server_identifier {
- char serverName[48];
-} server_identifier;
-
-typedef struct server_res_message {
- server_identifier server[5];
- int serverListenPort[5];
- int serverIpAddr[5];
-} server_res_message;
-
-#define BUTTON_TEMPLATE_RES_MESSAGE 0x0097
-
-typedef struct buttondefinition {
- UINT8 instanceNumber;
- UINT8 buttonDefinition;
-} button_definition;
-
-#define STIMULUS_REDIAL 0x01
-#define STIMULUS_SPEEDDIAL 0x02
-#define STIMULUS_HOLD 0x03
-#define STIMULUS_TRANSFER 0x04
-#define STIMULUS_FORWARDALL 0x05
-#define STIMULUS_FORWARDBUSY 0x06
-#define STIMULUS_FORWARDNOANSWER 0x07
-#define STIMULUS_DISPLAY 0x08
-#define STIMULUS_LINE 0x09
-#define STIMULUS_VOICEMAIL 0x0F
-#define STIMULUS_AUTOANSWER 0x11
-#define STIMULUS_CONFERENCE 0x7D
-#define STIMULUS_CALLPARK 0x7E
-#define STIMULUS_CALLPICKUP 0x7F
-#define STIMULUS_NONE 0xFF
-
-button_definition button_def_30vip[] = {
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 2, STIMULUS_LINE }, /* Line 2 */
- { 3, STIMULUS_LINE }, /* Line 3 */
- { 4, STIMULUS_LINE }, /* Line 4 */
- { 1, STIMULUS_CALLPARK }, /* Call Park */
- { 0, STIMULUS_NONE },
- { 1, STIMULUS_SPEEDDIAL }, /* Speeddial 1 */
- { 2, STIMULUS_SPEEDDIAL }, /* Speeddial 2 */
- { 3, STIMULUS_SPEEDDIAL }, /* Speeddial 3 */
- { 4, STIMULUS_SPEEDDIAL }, /* Speeddial 4 */
- { 5, STIMULUS_SPEEDDIAL }, /* Speeddial 5 */
- { 6, STIMULUS_SPEEDDIAL }, /* Speeddial 6 */
- { 1, STIMULUS_VOICEMAIL }, /* Voicemail */
- { 1, STIMULUS_FORWARDALL }, /* Forward All */
- { 1, STIMULUS_CONFERENCE }, /* Conference */
- { 0, STIMULUS_NONE },
- { 0, STIMULUS_NONE },
- { 0, STIMULUS_NONE },
- { 0, STIMULUS_NONE },
- { 0, STIMULUS_NONE },
- { 7, STIMULUS_SPEEDDIAL }, /* Speeddial 7 */
- { 8, STIMULUS_SPEEDDIAL }, /* Speeddial 8 */
- { 9, STIMULUS_SPEEDDIAL }, /* Speeddial 9 */
- { 10, STIMULUS_SPEEDDIAL } /* Speeddial 10 */
-};
-
-button_definition button_def_12sp[] = {
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 1, STIMULUS_SPEEDDIAL }, /* Speeddial 1 */
- { 2, STIMULUS_SPEEDDIAL }, /* Speeddial 2 */
- { 3, STIMULUS_SPEEDDIAL }, /* Speeddial 3 */
- { 4, STIMULUS_SPEEDDIAL }, /* Speeddial 4 */
- { 1, STIMULUS_VOICEMAIL }, /* Voicemail */
- { 5, STIMULUS_SPEEDDIAL }, /* Speeddial 5 */
- { 6, STIMULUS_SPEEDDIAL }, /* Speeddial 6 */
- { 7, STIMULUS_SPEEDDIAL }, /* Speeddial 7 */
- { 8, STIMULUS_SPEEDDIAL }, /* Speeddial 8 */
- { 9, STIMULUS_SPEEDDIAL } /* Speeddial 9 */
-};
-
-button_definition button_def_7902[] = {
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 1, STIMULUS_HOLD }, /* Hold */
- { 1, STIMULUS_TRANSFER },
- { 1, STIMULUS_DISPLAY },
- { 1, STIMULUS_VOICEMAIL },
- { 1, STIMULUS_CONFERENCE },
- { 1, STIMULUS_FORWARDALL },
- { 1, STIMULUS_SPEEDDIAL }, /* Speeddial 1 */
- { 2, STIMULUS_SPEEDDIAL }, /* Speeddial 2 */
- { 3, STIMULUS_SPEEDDIAL }, /* Speeddial 3 */
- { 4, STIMULUS_SPEEDDIAL }, /* Speeddial 4 */
- { 1, STIMULUS_REDIAL }
-};
-
-button_definition button_def_7910[] = {
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 1, STIMULUS_HOLD }, /* Hold */
- { 1, STIMULUS_TRANSFER },
- { 1, STIMULUS_DISPLAY },
- { 1, STIMULUS_VOICEMAIL },
- { 1, STIMULUS_CONFERENCE },
- { 1, STIMULUS_FORWARDALL },
- { 1, STIMULUS_SPEEDDIAL }, /* Speeddial 1 */
- { 2, STIMULUS_SPEEDDIAL }, /* Speeddial 2 */
- { 1, STIMULUS_REDIAL }
-};
-
-button_definition button_def_7920[] = {
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 2, STIMULUS_LINE }, /* Line 2 */
- { 1, STIMULUS_SPEEDDIAL }, /* Speeddial 1 */
- { 2, STIMULUS_SPEEDDIAL }, /* Speeddial 2 */
- { 3, STIMULUS_SPEEDDIAL }, /* Speeddial 3 */
- { 4, STIMULUS_SPEEDDIAL } /* Speeddial 4 */
-};
-
-button_definition button_def_7935[] = {
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 2, STIMULUS_LINE } /* Line 2 */
-};
-
-button_definition button_def_7940[] = {
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 2, STIMULUS_LINE } /* Line 2 */
-};
-
-button_definition button_def_7960[] = {
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 2, STIMULUS_LINE }, /* Line 2 */
- { 3, STIMULUS_LINE }, /* Line 3 */
- { 1, STIMULUS_SPEEDDIAL }, /* Speeddial 1 */
- { 2, STIMULUS_SPEEDDIAL }, /* Speeddial 2 */
- { 3, STIMULUS_SPEEDDIAL } /* Speeddial 3 */
-};
-
-button_definition button_def_7970[] = {
- { 1, STIMULUS_LINE }, /* Line 1 */
- { 2, STIMULUS_LINE }, /* Line 2 */
- { 3, STIMULUS_LINE }, /* Line 3 */
- { 1, STIMULUS_SPEEDDIAL }, /* Speeddial 1 */
- { 2, STIMULUS_SPEEDDIAL }, /* Speeddial 2 */
- { 3, STIMULUS_SPEEDDIAL }, /* Speeddial 3 */
- { 4, STIMULUS_SPEEDDIAL }, /* Speeddial 4 */
- { 5, STIMULUS_SPEEDDIAL } /* Speeddial 5 */
-};
-
-button_definition button_def_none = { 0, STIMULUS_NONE };
-
-typedef struct button_defs {
- char *type;
- int num_buttons;
- button_definition *button_def;
-} button_defs_t;
-
-button_defs_t button_defs[] = {
- { "12SP", 12, button_def_12sp }, /* First one is used if
- there's no match */
- { "30VIP", 26, button_def_30vip },
- { "7902", 12, button_def_7902 },
- { "7910", 10, button_def_7910 },
- { "7920", 6, button_def_7920 },
- { "7935", 2, button_def_7935 },
- { "7940", 2, button_def_7940 },
- { "7960", 6, button_def_7960 },
- { "7970", 8, button_def_7970 },
- { NULL, 0, NULL }
-};
-
-typedef struct button_template_res_message {
- UINT32 buttonOffset;
- UINT32 buttonCount;
- UINT32 totalButtonCount;
- button_definition definition[42];
-} button_template_res_message;
-
-#define VERSION_RES_MESSAGE 0x0098
-typedef struct version_res_message {
- char version[16];
-} version_res_message;
-
-#define KEEP_ALIVE_ACK_MESSAGE 0x0100
-
-#define OPEN_RECIEVE_CHANNEL_MESSAGE 0x0105
-typedef struct open_recieve_channel_message {
- int conferenceId;
- int partyId;
- int packets;
- int capability;
- int echo;
- int bitrate;
-} open_recieve_channel_message;
-
-#define CLOSE_RECIEVE_CHANNEL_MESSAGE 0x0106
-typedef struct close_recieve_channel_message {
- int conferenceId;
- int partyId;
-} close_recieve_channel_message;
-
-#define SOFT_KEY_TEMPLATE_RES_MESSAGE 0x0108
-
-typedef struct soft_key_template_definition {
- char softKeyLabel[16];
- int softKeyEvent;
-} soft_key_template_definition;
-
-soft_key_template_definition soft_key_template_default[] = {
- { "Redial", 1 },
- { "NewCall", 2 },
- { "Hold", 3 },
- { "Trnsfer", 4 },
- { "CFwdAll", 5 },
- { "CFwdBusy", 6 },
- { "CFwdNoAnswer", 7 },
- { "<<", 8 },
- { "EndCall", 9 },
- { "Resume", 10 },
- { "Answer", 11 },
- { "Info", 12 },
- { "Confrn", 13 },
- { "Park", 14 },
- { "Join", 15 },
- { "MeetMe", 16 },
- { "PickUp", 17 },
- { "GPickUp", 18 },
-};
-
-typedef struct soft_key_template {
- int softKeyOffset;
- int softKeyCount;
- int totalSoftKeyCount;
- soft_key_template_definition softKeyTemplateDefinition[32];
-} soft_key_template;
-
-#define SOFT_KEY_SET_RES_MESSAGE 0x0109
-static const char *soft_key_set_hack = {
- "\x01\x02\x05\x03\x09\x0a\x0b\x10\x11\x12\x04\x0e\x0d\x00\x00\x00"
- "\x2d\x01\x2e\x01\x31\x01\x2f\x01\x35\x01\x36\x01\x37\x01\x3c\x01"
- "\x3d\x01\x3e\x01\x30\x01\x3a\x01\x39\x01\x00\x00\x00\x00\x00\x00"
- "\x03\x09\x04\x0e\x0d\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x2f\x01\x35\x01\x30\x01\x3a\x01\x39\x01\x3f\x01\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x0a\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x36\x01\x2e\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x37\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x01\x09\x05\x10\x11\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x2d\x01\x35\x01\x31\x01\x3c\x01\x3d\x01\x3e\x01\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x09\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x35\x01\x30\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x08\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x34\x01\x35\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x09\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x35\x01\x39\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x35\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x01\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x2d\x01\x35\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x41\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-};
-
-typedef struct soft_key_set_definition {
- UINT8 softKeyTemplateIndex[16];
- UINT16 softKeyInfoIndex[16];
-} soft_key_set_definition;
-
-typedef struct soft_key_sets {
- UINT32 softKeySetOffset;
- UINT32 softKeySetCount;
- UINT32 totalSoftKeySetCount;
- soft_key_set_definition softKeySetDefinition[16];
- UINT32 res;
-} soft_key_sets;
-
-#define SELECT_SOFT_KEYS_MESSAGE 0x0110
-typedef struct select_soft_keys_message {
- int instance;
- int reference;
- int softKeySetIndex;
- int validKeyMask;
-} select_soft_keys_message;
-
-#define CALL_STATE_MESSAGE 0x0111
-typedef struct call_state_message {
- int callState;
- int lineInstance;
- int callReference;
-} call_state_message;
-
-#define DISPLAY_PROMPT_STATUS_MESSAGE 0x0112
-typedef struct display_prompt_status_message {
- int messageTimeout;
- char promptMessage[32];
- int lineInstance;
- int callReference;
-} display_prompt_status_message;
-
-#define DISPLAY_NOTIFY_MESSAGE 0x0114
-typedef struct display_notify_message {
- int displayTimeout;
- char displayMessage[100];
-} display_notify_message;
-
-#define ACTIVATE_CALL_PLANE_MESSAGE 0x0116
-typedef struct activate_call_plane_message {
- int lineInstance;
-} activate_call_plane_message;
-
-#define DIALLED_NUMBER_MESSAGE 0x011D
-typedef struct dialled_number_message {
- char dialledNumber[24];
- int lineInstance;
- int callReference;
-} dialled_number_message;
-
-/* packet composition */
-typedef struct {
- int len;
- int res;
- int e;
- union {
- speed_dial_stat_req_message speeddialreq;
- register_message reg;
- register_ack_message regack;
- register_rej_message regrej;
- capabilities_res_message caps;
- version_res_message version;
- button_template_res_message buttontemplate;
- displaytext_message displaytext;
- display_prompt_status_message displaypromptstatus;
- definetimedate_message definetimedate;
- start_tone_message starttone;
- speed_dial_stat_res_message speeddial;
- line_state_req_message line;
- line_stat_res_message linestat;
- soft_key_sets softkeysets;
- soft_key_template softkeytemplate;
- server_res_message serverres;
- set_lamp_message setlamp;
- set_ringer_message setringer;
- call_state_message callstate;
- keypad_button_message keypad;
- select_soft_keys_message selectsoftkey;
- activate_call_plane_message activatecallplane;
- stimulus_message stimulus;
- set_speaker_message setspeaker;
- call_info_message callinfo;
- start_media_transmission_message startmedia;
- stop_media_transmission_message stopmedia;
- open_recieve_channel_message openrecievechannel;
- open_recieve_channel_ack_message openrecievechannelack;
- close_recieve_channel_message closerecievechannel;
- display_notify_message displaynotify;
- dialled_number_message diallednumber;
- } data;
-} skinny_req;
-
-/************************************************************************************/
-/* Asterisk specific globals */
-/************************************************************************************/
-
-static int skinnydebug = 1; /* XXX for now, enable debugging default */
-
-/* a hostname, portnumber, socket and such is usefull for VoIP protocols */
-static struct sockaddr_in bindaddr;
-static char ourhost[256];
-static int ourport;
-static struct in_addr __ourip;
-struct ast_hostent ahp; struct hostent *hp;
-static int skinnysock = -1;
-static pthread_t tcp_thread;
-static pthread_t accept_t;
-static char context[AST_MAX_CONTEXT] = "default";
-static char language[MAX_LANGUAGE] = "";
-static char musicclass[MAX_MUSICCLASS] = "";
-static char cid_num[AST_MAX_EXTENSION] = "";
-static char cid_name[AST_MAX_EXTENSION] = "";
-static char linelabel[AST_MAX_EXTENSION] ="";
-static int nat = 0;
-static ast_group_t cur_callergroup = 0;
-static ast_group_t cur_pickupgroup = 0;
-static int immediate = 0;
-static int callwaiting = 0;
-static int callreturn = 0;
-static int threewaycalling = 0;
-static int mwiblink = 0;
-/* This is for flashhook transfers */
-static int transfer = 0;
-static int cancallforward = 0;
-/* static int busycount = 3;*/
-static char accountcode[AST_MAX_ACCOUNT_CODE] = "";
-static char mailbox[AST_MAX_EXTENSION];
-static int amaflags = 0;
-static int callnums = 1;
-
-#define SUB_REAL 0
-#define SUB_ALT 1
-#define MAX_SUBS 2
-
-#define SKINNY_SPEAKERON 1
-#define SKINNY_SPEAKEROFF 2
-
-#define SKINNY_OFFHOOK 1
-#define SKINNY_ONHOOK 2
-#define SKINNY_RINGOUT 3
-#define SKINNY_RINGIN 4
-#define SKINNY_CONNECTED 5
-#define SKINNY_BUSY 6
-#define SKINNY_CONGESTION 7
-#define SKINNY_HOLD 8
-#define SKINNY_CALLWAIT 9
-#define SKINNY_TRANSFER 10
-#define SKINNY_PARK 11
-#define SKINNY_PROGRESS 12
-#define SKINNY_INVALID 14
-
-#define SKINNY_SILENCE 0x00
-#define SKINNY_DIALTONE 0x21
-#define SKINNY_BUSYTONE 0x23
-#define SKINNY_ALERT 0x24
-#define SKINNY_REORDER 0x25
-#define SKINNY_CALLWAITTONE 0x2D
-#define SKINNY_NOTONE 0x7F
-
-#define SKINNY_LAMP_OFF 1
-#define SKINNY_LAMP_ON 2
-#define SKINNY_LAMP_WINK 3
-#define SKINNY_LAMP_FLASH 4
-#define SKINNY_LAMP_BLINK 5
-
-#define SKINNY_RING_OFF 1
-#define SKINNY_RING_INSIDE 2
-#define SKINNY_RING_OUTSIDE 3
-#define SKINNY_RING_FEATURE 4
-
-#define TYPE_TRUNK 1
-#define TYPE_LINE 2
-
-/* Skinny rtp stream modes. Do we really need this? */
-#define SKINNY_CX_SENDONLY 0
-#define SKINNY_CX_RECVONLY 1
-#define SKINNY_CX_SENDRECV 2
-#define SKINNY_CX_CONF 3
-#define SKINNY_CX_CONFERENCE 3
-#define SKINNY_CX_MUTE 4
-#define SKINNY_CX_INACTIVE 4
-
-#if 0
-static char *skinny_cxmodes[] = {
- "sendonly",
- "recvonly",
- "sendrecv",
- "confrnce",
- "inactive"
-};
-#endif
-
-/* driver scheduler */
-static struct sched_context *sched;
-static struct io_context *io;
-
-/* usage count and locking */
-static int usecnt = 0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-/* Protect the monitoring thread, so only one process can kill or start it, and not
- when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(monlock);
-/* Protect the network socket */
-AST_MUTEX_DEFINE_STATIC(netlock);
-/* Protect the session list */
-AST_MUTEX_DEFINE_STATIC(sessionlock);
-/* Protect the device list */
-AST_MUTEX_DEFINE_STATIC(devicelock);
-#if 0
-/* Protect the paging device list */
-AST_MUTEX_DEFINE_STATIC(pagingdevicelock);
-#endif
-
-/* This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
-
-/* Wait up to 16 seconds for first digit */
-static int firstdigittimeout = 16000;
-
-/* How long to wait for following digits */
-static int gendigittimeout = 8000;
-
-/* How long to wait for an extra digit, if there is an ambiguous match */
-static int matchdigittimeout = 3000;
-
-struct skinny_subchannel {
- ast_mutex_t lock;
- unsigned int callid;
- struct ast_channel *owner;
- struct skinny_line *parent;
- struct ast_rtp *rtp;
- time_t lastouttime;
- int progress;
- int ringing;
- int lastout;
- int cxmode;
- int nat;
- int outgoing;
- int alreadygone;
- struct skinny_subchannel *next;
-};
-
-struct skinny_line {
- ast_mutex_t lock;
- char name[80];
- char label[42]; /* Label that shows next to the line buttons */
- struct skinny_subchannel *sub; /* pointer to our current connection, channel and stuff */
- char accountcode[AST_MAX_ACCOUNT_CODE];
- char exten[AST_MAX_EXTENSION]; /* Extention where to start */
- char context[AST_MAX_CONTEXT];
- char language[MAX_LANGUAGE];
- char cid_num[AST_MAX_EXTENSION]; /* Caller*ID */
- char cid_name[AST_MAX_EXTENSION]; /* Caller*ID */
- char lastcallerid[AST_MAX_EXTENSION]; /* Last Caller*ID */
- char call_forward[AST_MAX_EXTENSION];
- char mailbox[AST_MAX_EXTENSION];
- char musicclass[MAX_MUSICCLASS];
- int curtone; /* Current tone being played */
- ast_group_t callgroup;
- ast_group_t pickupgroup;
- int callwaiting;
- int transfer;
- int threewaycalling;
- int mwiblink;
- int cancallforward;
- int callreturn;
- int dnd; /* How does this affect callwait? Do we just deny a skinny_request if we're dnd? */
- int hascallerid;
- int hidecallerid;
- int amaflags;
- int type;
- int instance;
- int group;
- int needdestroy;
- int capability;
- int nonCodecCapability;
- int onhooktime;
- int msgstate; /* voicemail message state */
- int immediate;
- int hookstate;
- int progress;
- struct skinny_line *next;
- struct skinny_device *parent;
-};
-
-static struct skinny_device {
- /* A device containing one or more lines */
- char name[80];
- char id[16];
- char version_id[16];
- int type;
- int registered;
- char model[6];
- struct sockaddr_in addr;
- struct in_addr ourip;
- struct skinny_line *lines;
- struct ast_ha *ha;
- struct skinnysession *session;
- struct skinny_device *next;
-} *devices = NULL;
-
-struct skinny_paging_device {
- char name[80];
- char id[16];
- struct skinny_device ** devices;
- struct skinny_paging_device *next;
-};
-
-static struct skinnysession {
- pthread_t t;
- ast_mutex_t lock;
- struct sockaddr_in sin;
- int fd;
- char inbuf[SKINNY_MAX_PACKET];
- struct skinny_device *device;
- struct skinnysession *next;
-} *sessions = NULL;
-
-static struct ast_channel *skinny_request(const char *type, int format, void *data, int *cause);
-static int skinny_call(struct ast_channel *ast, char *dest, int timeout);
-static int skinny_hangup(struct ast_channel *ast);
-static int skinny_answer(struct ast_channel *ast);
-static struct ast_frame *skinny_read(struct ast_channel *ast);
-static int skinny_write(struct ast_channel *ast, struct ast_frame *frame);
-static int skinny_indicate(struct ast_channel *ast, int ind);
-static int skinny_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-static int skinny_senddigit(struct ast_channel *ast, char digit);
-
-static const struct ast_channel_tech skinny_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_ULAW,
- .properties = AST_CHAN_TP_WANTSJITTER,
- .requester = skinny_request,
- .call = skinny_call,
- .hangup = skinny_hangup,
- .answer = skinny_answer,
- .read = skinny_read,
- .write = skinny_write,
- .indicate = skinny_indicate,
- .fixup = skinny_fixup,
- .send_digit = skinny_senddigit,
-/* .bridge = ast_rtp_bridge, */
-};
-
-static skinny_req *req_alloc(size_t size)
-{
- skinny_req *req;
- req = malloc(size+12);
- if (!req) {
- return NULL;
- }
- memset(req, 0, size+12);
- return req;
-}
-
-static struct skinny_subchannel *find_subchannel_by_line(struct skinny_line *l)
-{
- /* XXX Need to figure out how to determine which sub we want */
- struct skinny_subchannel *sub = l->sub;
- return sub;
-}
-
-static struct skinny_subchannel *find_subchannel_by_name(char *dest)
-{
- struct skinny_line *l;
- struct skinny_device *d;
- char line[256];
- char *at;
- char *device;
-
- strncpy(line, dest, sizeof(line) - 1);
- at = strchr(line, '@');
- if (!at) {
- ast_log(LOG_NOTICE, "Device '%s' has no @ (at) sign!\n", dest);
- return NULL;
- }
- *at = '\0';
- at++;
- device = at;
- ast_mutex_lock(&devicelock);
- d = devices;
- while(d) {
- if (!strcasecmp(d->name, device)) {
- if (skinnydebug) {
- ast_verbose("Found device: %s\n", d->name);
- }
- /* Found the device */
- l = d->lines;
- while (l) {
- /* Search for the right line */
- if (!strcasecmp(l->name, line)) {
- ast_mutex_unlock(&devicelock);
- return l->sub;
- }
- l = l->next;
- }
- }
- d = d->next;
- }
- /* Device not found*/
- ast_mutex_unlock(&devicelock);
- return NULL;
-}
-
-static int transmit_response(struct skinnysession *s, skinny_req *req)
-{
- int res = 0;
- ast_mutex_lock(&s->lock);
-
-#if 0
- if (skinnydebug) {
- ast_verbose("writing packet type %04X (%d bytes) to socket %d\n", letohl(req->e), letohl(req->len)+8, s->fd);
- }
-#endif
-
- res = write(s->fd, req, letohl(req->len)+8);
- if (res != letohl(req->len)+8) {
- ast_log(LOG_WARNING, "Transmit: write only sent %d out of %d bytes: %s\n", res, letohl(req->len)+8, strerror(errno));
- }
- ast_mutex_unlock(&s->lock);
- return 1;
-}
-
-/* XXX Do this right */
-static int convert_cap(int capability)
-{
- return 4; /* ulaw (this is not the same as asterisk's '4' */
-
-}
-
-static void transmit_speaker_mode(struct skinnysession *s, int mode)
-{
- skinny_req *req;
-
- req = req_alloc(sizeof(struct set_speaker_message));
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
- req->len = htolel(sizeof(set_speaker_message)+4);
- req->e = htolel(SET_SPEAKER_MESSAGE);
- req->data.setspeaker.mode = htolel(mode);
- transmit_response(s, req);
-}
-
-static void transmit_callstate(struct skinnysession *s, int instance, int state, unsigned callid)
-{
- skinny_req *req;
- int memsize = sizeof(struct call_state_message);
-
- req = req_alloc(memsize);
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
- if (state == SKINNY_ONHOOK) {
- transmit_speaker_mode(s, SKINNY_SPEAKEROFF);
- }
- req->len = htolel(sizeof(call_state_message)+4);
- req->e = htolel(CALL_STATE_MESSAGE);
- req->data.callstate.callState = htolel(state);
- req->data.callstate.lineInstance = htolel(instance);
- req->data.callstate.callReference = htolel(callid);
- transmit_response(s, req);
- if (state == SKINNY_OFFHOOK) {
- memset(req, 0, memsize);
- req->len = htolel(sizeof(activate_call_plane_message)+4);
- req->e = htolel(ACTIVATE_CALL_PLANE_MESSAGE);
- req->data.activatecallplane.lineInstance = htolel(instance);
- transmit_response(s, req);
- } else if (state == SKINNY_ONHOOK) {
- memset(req, 0, memsize);
- req->len = htolel(sizeof(activate_call_plane_message)+4);
- req->e = htolel(ACTIVATE_CALL_PLANE_MESSAGE);
- req->data.activatecallplane.lineInstance = 0;
- transmit_response(s, req);
- memset(req, 0, memsize);
- req->len = htolel(sizeof(close_recieve_channel_message)+4);
- req->e = htolel(CLOSE_RECIEVE_CHANNEL_MESSAGE);
- req->data.closerecievechannel.conferenceId = 0;
- req->data.closerecievechannel.partyId = 0;
- transmit_response(s, req);
- memset(req, 0, memsize);
- req->len = htolel(sizeof(stop_media_transmission_message)+4);
- req->e = htolel(STOP_MEDIA_TRANSMISSION_MESSAGE);
- req->data.stopmedia.conferenceId = 0;
- req->data.stopmedia.passThruPartyId = 0;
- transmit_response(s, req);
- }
-}
-
-static void transmit_callinfo(struct skinnysession *s, char *fromname, char *fromnum, char *toname, char *tonum, int instance, int callid, int calltype)
-{
- skinny_req *req;
-
- req = req_alloc(sizeof(struct call_info_message));
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
-
- req->len = htolel(sizeof(struct call_info_message));
- req->e = htolel(CALL_INFO_MESSAGE);
-
- if (fromname) {
- ast_copy_string(req->data.callinfo.callingPartyName, fromname, sizeof(req->data.callinfo.callingPartyName));
- }
- if (fromnum) {
- ast_copy_string(req->data.callinfo.callingParty, fromnum, sizeof(req->data.callinfo.callingParty));
- }
- if (toname) {
- ast_copy_string(req->data.callinfo.calledPartyName, toname, sizeof(req->data.callinfo.calledPartyName));
- }
- if (tonum) {
- ast_copy_string(req->data.callinfo.calledParty, tonum, sizeof(req->data.callinfo.calledParty));
- }
- req->data.callinfo.instance = htolel(instance);
- req->data.callinfo.reference = htolel(callid);
- req->data.callinfo.type = htolel(calltype);
- transmit_response(s, req);
-}
-
-static void transmit_connect(struct skinnysession *s)
-{
- skinny_req *req;
- struct skinny_line *l = s->device->lines;
-
- req = req_alloc(sizeof(struct open_recieve_channel_message));
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
- req->len = htolel(sizeof(struct open_recieve_channel_message));
- req->e = htolel(OPEN_RECIEVE_CHANNEL_MESSAGE);
- req->data.openrecievechannel.conferenceId = 0;
- req->data.openrecievechannel.partyId = 0;
- req->data.openrecievechannel.packets = htolel(20);
- req->data.openrecievechannel.capability = htolel(convert_cap(l->capability));
- req->data.openrecievechannel.echo = 0;
- req->data.openrecievechannel.bitrate = 0;
- transmit_response(s, req);
-}
-
-static void transmit_tone(struct skinnysession *s, int tone)
-{
- skinny_req *req;
-
- if (tone > 0) {
- req = req_alloc(sizeof(struct start_tone_message));
- } else {
- req = req_alloc(4);
- }
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
- if (tone > 0) {
- req->len = htolel(sizeof(start_tone_message)+4);
- req->e = htolel(START_TONE_MESSAGE);
- req->data.starttone.tone = htolel(tone);
- } else {
- req->len = htolel(4);
- req->e = htolel(STOP_TONE_MESSAGE);
- }
- transmit_response(s, req);
-}
-
-#if 0
-/* XXX need to properly deal with softkeys */
-static void transmit_selectsoftkeys(struct skinnysession *s, int instance, int callid, int softkey)
-{
- skinny_req *req;
- int memsize = sizeof(struct select_soft_keys_message);
-
- req = req_alloc(memsize);
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
- memset(req, 0, memsize);
- req->len = htolel(sizeof(select_soft_keys_message)+4);
- req->e = htolel(SELECT_SOFT_KEYS_MESSAGE);
- req->data.selectsoftkey.instance = htolel(instance);
- req->data.selectsoftkey.reference = htolel(callid);
- req->data.selectsoftkey.softKeySetIndex = htolel(softkey);
- transmit_response(s, req);
-}
-#endif
-
-static void transmit_lamp_indication(struct skinnysession *s, int stimulus, int instance, int indication)
-{
- skinny_req *req;
-
- req = req_alloc(sizeof(struct set_lamp_message));
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
- req->len = htolel(sizeof(set_lamp_message)+4);
- req->e = htolel(SET_LAMP_MESSAGE);
- req->data.setlamp.stimulus = htolel(stimulus);
- req->data.setlamp.stimulusInstance = htolel(instance);
- req->data.setlamp.deviceStimulus = htolel(indication);
- transmit_response(s, req);
-}
-
-static void transmit_ringer_mode(struct skinnysession *s, int mode)
-{
- skinny_req *req;
-
- req = req_alloc(sizeof(struct set_ringer_message));
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
- req->len = htolel(sizeof(set_ringer_message)+4);
- req->e = htolel(SET_RINGER_MESSAGE);
- req->data.setringer.ringerMode = htolel(mode);
- transmit_response(s, req);
-}
-
-static void transmit_displaymessage(struct skinnysession *s, char *text)
-{
- skinny_req *req;
-
- if (text == 0) {
- req = req_alloc(4);
- req->len = htolel(4);
- req->e = htolel(CLEAR_DISPLAY_MESSAGE);
- } else {
- req = req_alloc(sizeof(struct displaytext_message));
-
- strncpy(req->data.displaytext.text, text, sizeof(req->data.displaytext.text)-1);
- req->len = htolel(sizeof(displaytext_message) + 4);
- req->e = htolel(DISPLAYTEXT_MESSAGE);
- if (skinnydebug) {
- ast_verbose("Displaying message '%s'\n", req->data.displaytext.text);
- }
- }
-
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
- transmit_response(s, req);
-}
-
-static void transmit_displaynotify(struct skinnysession *s, char *text, int t)
-{
- skinny_req *req;
-
- req = req_alloc(sizeof(struct display_notify_message));
-
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
-
- req->e = htolel(DISPLAY_NOTIFY_MESSAGE);
- req->len = htolel(sizeof(display_notify_message) + 4);
- strncpy(req->data.displaynotify.displayMessage, text, sizeof(req->data.displaynotify.displayMessage)-1);
- req->data.displaynotify.displayTimeout = htolel(t);
-
- if (skinnydebug) {
- ast_verbose("Displaying notify '%s'\n", text);
- }
-
- transmit_response(s, req);
-}
-
-static void transmit_displaypromptstatus(struct skinnysession *s, char *text, int t, int instance, int callid)
-{
- skinny_req *req;
-
- req = req_alloc(sizeof(struct display_prompt_status_message));
-
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
-
- req->e = htolel(DISPLAY_PROMPT_STATUS_MESSAGE);
- req->len = htolel(sizeof(display_prompt_status_message) + 4);
- strncpy(req->data.displaypromptstatus.promptMessage, text, sizeof(req->data.displaypromptstatus.promptMessage)-1);
- req->data.displaypromptstatus.messageTimeout = htolel(t);
- req->data.displaypromptstatus.lineInstance = htolel(instance);
- req->data.displaypromptstatus.callReference = htolel(callid);
-
- if (skinnydebug) {
- ast_verbose("Displaying Prompt Status '%s'\n", text);
- }
-
- transmit_response(s, req);
-}
-
-static void transmit_diallednumber(struct skinnysession *s, char *text, int instance, int callid)
-{
- skinny_req *req;
-
- req = req_alloc(sizeof(struct dialled_number_message));
-
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return;
- }
-
- req->e = htolel(DIALLED_NUMBER_MESSAGE);
- req->len = htolel(sizeof(dialled_number_message) + 4);
- strncpy(req->data.diallednumber.dialledNumber, text, sizeof(req->data.diallednumber.dialledNumber)-1);
- req->data.diallednumber.lineInstance = htolel(instance);
- req->data.diallednumber.callReference = htolel(callid);
-
- transmit_response(s, req);
-}
-
-static int has_voicemail(struct skinny_line *l)
-{
- return ast_app_has_voicemail(l->mailbox, NULL);
-}
-
-
-static void do_housekeeping(struct skinnysession *s)
-{
- int new;
- int old;
- struct skinny_subchannel *sub;
- struct skinny_line *l = s->device->lines;
-
- sub = find_subchannel_by_line(l);
- transmit_displaymessage(s, NULL);
-
- if (has_voicemail(sub->parent)) {
- if (skinnydebug) {
- ast_verbose("Checking for voicemail Skinny %s@%s\n", sub->parent->name, sub->parent->parent->name);
- }
- ast_app_messagecount(sub->parent->mailbox, &new, &old);
- if (skinnydebug) {
- ast_verbose("Skinny %s@%s has voicemail!\n", sub->parent->name, sub->parent->parent->name);
- }
- transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON);
- } else {
- transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, SKINNY_LAMP_OFF);
- }
-
-}
-
-/* I do not believe skinny can deal with video.
- Anyone know differently? */
-static struct ast_rtp *skinny_get_vrtp_peer(struct ast_channel *chan)
-{
- return NULL;
-}
-
-static struct ast_rtp *skinny_get_rtp_peer(struct ast_channel *chan)
-{
- struct skinny_subchannel *sub;
- sub = chan->tech_pvt;
- if (sub && sub->rtp) {
- return sub->rtp;
- }
- return NULL;
-}
-
-static int skinny_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active)
-{
- struct skinny_subchannel *sub;
- sub = chan->tech_pvt;
- if (sub) {
- /* transmit_modify_with_sdp(sub, rtp); @@FIXME@@ if needed */
- return 0;
- }
- return -1;
-}
-
-static struct ast_rtp_protocol skinny_rtp = {
- .type = type,
- .get_rtp_info = skinny_get_rtp_peer,
- .get_vrtp_info = skinny_get_vrtp_peer,
- .set_rtp_peer = skinny_set_rtp_peer,
-};
-
-static int skinny_do_debug(int fd, int argc, char *argv[])
-{
- if (argc != 2) {
- return RESULT_SHOWUSAGE;
- }
- skinnydebug = 1;
- ast_cli(fd, "Skinny Debugging Enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int skinny_no_debug(int fd, int argc, char *argv[])
-{
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- skinnydebug = 0;
- ast_cli(fd, "Skinny Debugging Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static int skinny_show_devices(int fd, int argc, char *argv[])
-{
- struct skinny_device *d;
- struct skinny_line *l;
- int numlines = 0;
- char iabuf[INET_ADDRSTRLEN];
-
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- ast_mutex_lock(&devicelock);
- d = devices;
-
- ast_cli(fd, "Name DeviceId IP TypeId R Model NL\n");
- ast_cli(fd, "-------------------- ---------------- --------------- ------ - ------ --\n");
- while(d) {
- l = d->lines;
- numlines = 0;
- while(l) { numlines++; l = l->next; }
-
- ast_cli(fd, "%-20s %-16s %-16s %6X %c %-6s %2d\n",
- d->name,
- d->id,
- ast_inet_ntoa(iabuf, sizeof(iabuf), d->addr.sin_addr),
- d->type,
- d->registered?'Y':'N',
- d->model,
- numlines);
-
- d = d->next;
- }
- ast_mutex_unlock(&devicelock);
- return RESULT_SUCCESS;
-}
-
-static int skinny_show_lines(int fd, int argc, char *argv[])
-{
- struct skinny_device *d;
- struct skinny_line *l;
-
- if (argc != 3) {
- return RESULT_SHOWUSAGE;
- }
- ast_mutex_lock(&devicelock);
- d = devices;
- while(d) {
- l = d->lines;
- while (l) {
- ast_cli(fd, "%-20s %2d %-20s %-20s %c %c\n",
- l->parent->name,
- l->instance,
- l->name,
- l->label,
- l->sub->owner?'Y':'N',
- l->sub->rtp?'Y':'N');
- l = l->next;
- }
- d = d->next;
- }
- ast_mutex_unlock(&devicelock);
- return RESULT_SUCCESS;
-}
-
-static char show_devices_usage[] =
-"Usage: skinny show devices\n"
-" Lists all devices known to the Skinny subsystem.\n";
-
-static char show_lines_usage[] =
-"Usage: skinny show lines\n"
-" Lists all lines known to the Skinny subsystem.\n";
-
-static char debug_usage[] =
-"Usage: skinny debug\n"
-" Enables dumping of Skinny packets for debugging purposes\n";
-
-static char no_debug_usage[] =
-"Usage: skinny no debug\n"
-" Disables dumping of Skinny packets for debugging purposes\n";
-
-static struct ast_cli_entry cli_show_devices =
- { { "skinny", "show", "devices", NULL }, skinny_show_devices, "Show defined Skinny devices", show_devices_usage };
-
-static struct ast_cli_entry cli_show_lines =
- { { "skinny", "show", "lines", NULL }, skinny_show_lines, "Show defined Skinny lines per device", show_lines_usage };
-
-static struct ast_cli_entry cli_debug =
- { { "skinny", "debug", NULL }, skinny_do_debug, "Enable Skinny debugging", debug_usage };
-
-static struct ast_cli_entry cli_no_debug =
- { { "skinny", "no", "debug", NULL }, skinny_no_debug, "Disable Skinny debugging", no_debug_usage };
-
-#if 0
-static struct skinny_paging_device *build_paging_device(char *cat, struct ast_variable *v)
-{
- return NULL;
-}
-#endif
-
-static struct skinny_device *build_device(char *cat, struct ast_variable *v)
-{
- struct skinny_device *d;
- struct skinny_line *l;
- struct skinny_subchannel *sub;
- int i=0, y=0;
-
- d = malloc(sizeof(struct skinny_device));
- if (d) {
- memset(d, 0, sizeof(struct skinny_device));
- strncpy(d->name, cat, sizeof(d->name) - 1);
- while(v) {
- if (!strcasecmp(v->name, "host")) {
- if (ast_get_ip(&d->addr, v->value)) {
- free(d);
- return NULL;
- }
- } else if (!strcasecmp(v->name, "port")) {
- d->addr.sin_port = htons(atoi(v->value));
- } else if (!strcasecmp(v->name, "device")) {
- strncpy(d->id, v->value, sizeof(d->id)-1);
- } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
- d->ha = ast_append_ha(v->name, v->value, d->ha);
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(context, v->value, sizeof(context) - 1);
- } else if (!strcasecmp(v->name, "version")) {
- strncpy(d->version_id, v->value, sizeof(d->version_id) -1);
- } else if (!strcasecmp(v->name, "nat")) {
- nat = ast_true(v->value);
- } else if (!strcasecmp(v->name, "model")) {
- strncpy(d->model, v->value, sizeof(d->model) - 1);
- } else if (!strcasecmp(v->name, "callerid")) {
- if (!strcasecmp(v->value, "asreceived")) {
- cid_num[0] = '\0';
- cid_name[0] = '\0';
- } else {
- ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
- }
- } else if (!strcasecmp(v->name, "language")) {
- strncpy(language, v->value, sizeof(language)-1);
- } else if (!strcasecmp(v->name, "accountcode")) {
- strncpy(accountcode, v->value, sizeof(accountcode)-1);
- } else if (!strcasecmp(v->name, "amaflags")) {
- y = ast_cdr_amaflags2int(v->value);
- if (y < 0) {
- ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
- } else {
- amaflags = y;
- }
- } else if (!strcasecmp(v->name, "musiconhold")) {
- strncpy(musicclass, v->value, sizeof(musicclass)-1);
- } else if (!strcasecmp(v->name, "callgroup")) {
- cur_callergroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "pickupgroup")) {
- cur_pickupgroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "immediate")) {
- immediate = ast_true(v->value);
- } else if (!strcasecmp(v->name, "cancallforward")) {
- cancallforward = ast_true(v->value);
- } else if (!strcasecmp(v->name, "mailbox")) {
- strncpy(mailbox, v->value, sizeof(mailbox) -1);
- } else if (!strcasecmp(v->name, "callreturn")) {
- callreturn = ast_true(v->value);
- } else if (!strcasecmp(v->name, "callwaiting")) {
- callwaiting = ast_true(v->value);
- } else if (!strcasecmp(v->name, "transfer")) {
- transfer = ast_true(v->value);
- } else if (!strcasecmp(v->name, "threewaycalling")) {
- threewaycalling = ast_true(v->value);
- } else if (!strcasecmp(v->name, "mwiblink")) {
- mwiblink = ast_true(v->value);
- } else if (!strcasecmp(v->name, "linelabel")) {
- strncpy(linelabel, v->value, sizeof(linelabel)-1);
- } else if (!strcasecmp(v->name, "trunk") || !strcasecmp(v->name, "line")) {
- l = malloc(sizeof(struct skinny_line));;
- if (l) {
- memset(l, 0, sizeof(struct skinny_line));
- ast_mutex_init(&l->lock);
- strncpy(l->name, v->value, sizeof(l->name) - 1);
-
- /* XXX Should we check for uniqueness?? XXX */
- strncpy(l->context, context, sizeof(l->context) - 1);
- strncpy(l->cid_num, cid_num, sizeof(l->cid_num) - 1);
- strncpy(l->cid_name, cid_name, sizeof(l->cid_name) - 1);
- strncpy(l->label, linelabel, sizeof(l->label) - 1);
- strncpy(l->language, language, sizeof(l->language) - 1);
- strncpy(l->musicclass, musicclass, sizeof(l->musicclass)-1);
- strncpy(l->mailbox, mailbox, sizeof(l->mailbox)-1);
- strncpy(l->mailbox, mailbox, sizeof(l->mailbox)-1);
- if (!ast_strlen_zero(mailbox)) {
- ast_verbose(VERBOSE_PREFIX_3 "Setting mailbox '%s' on %s@%s\n", mailbox, d->name, l->name);
- }
- l->msgstate = -1;
- l->capability = capability;
- l->parent = d;
- if (!strcasecmp(v->name, "trunk")) {
- l->type = TYPE_TRUNK;
- } else {
- l->type = TYPE_LINE;
- }
- l->immediate = immediate;
- l->callgroup = cur_callergroup;
- l->pickupgroup = cur_pickupgroup;
- l->callreturn = callreturn;
- l->cancallforward = cancallforward;
- l->callwaiting = callwaiting;
- l->transfer = transfer;
- l->threewaycalling = threewaycalling;
- l->mwiblink = mwiblink;
- l->onhooktime = time(NULL);
- l->instance = 1;
- /* ASSUME we're onhook at this point*/
- l->hookstate = SKINNY_ONHOOK;
-
- for (i = 0; i < MAX_SUBS; i++) {
- sub = malloc(sizeof(struct skinny_subchannel));
- if (sub) {
- ast_verbose(VERBOSE_PREFIX_3 "Allocating Skinny subchannel '%d' on %s@%s\n", i, l->name, d->name);
- memset(sub, 0, sizeof(struct skinny_subchannel));
- ast_mutex_init(&sub->lock);
- sub->parent = l;
- /* Make a call*ID */
- sub->callid = callnums;
- callnums++;
- sub->cxmode = SKINNY_CX_INACTIVE;
- sub->nat = nat;
- sub->next = l->sub;
- l->sub = sub;
- } else {
- /* XXX Should find a way to clean up our memory */
- ast_log(LOG_WARNING, "Out of memory allocating subchannel");
- return NULL;
- }
- }
- l->next = d->lines;
- d->lines = l;
- } else {
- /* XXX Should find a way to clean up our memory */
- ast_log(LOG_WARNING, "Out of memory allocating line");
- return NULL;
- }
- } else {
- ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name, v->lineno);
- }
- v = v->next;
- }
-
- if (!d->lines) {
- ast_log(LOG_ERROR, "A Skinny device must have at least one line!\n");
- return NULL;
- }
- if (d->addr.sin_addr.s_addr && !ntohs(d->addr.sin_port)) {
- d->addr.sin_port = htons(DEFAULT_SKINNY_PORT);
- }
- if (d->addr.sin_addr.s_addr) {
- if (ast_ouraddrfor(&d->addr.sin_addr, &d->ourip)) {
- memcpy(&d->ourip, &__ourip, sizeof(d->ourip));
- }
- } else {
- memcpy(&d->ourip, &__ourip, sizeof(d->ourip));
- }
- }
- return d;
-}
-
-static int skinny_register(skinny_req *req, struct skinnysession *s)
-{
- struct skinny_device *d;
-
- ast_mutex_lock(&devicelock);
- d = devices;
- while (d) {
- if (!strcasecmp(req->data.reg.name, d->id)
- && ast_apply_ha(d->ha, &(s->sin))) {
- s->device = d;
- d->type = letohl(req->data.reg.type);
- if (ast_strlen_zero(d->version_id)) {
- strncpy(d->version_id, version_id, sizeof(d->version_id) - 1);
- }
- d->registered = 1;
- d->session = s;
- break;
- }
- d = d->next;
- }
- ast_mutex_unlock(&devicelock);
- if (!d) {
- return 0;
- }
- return 1;
-}
-
-static void start_rtp(struct skinny_subchannel *sub)
-{
- ast_mutex_lock(&sub->lock);
- /* Allocate the RTP */
- sub->rtp = ast_rtp_new(sched, io, 1, 0);
- if (sub->rtp && sub->owner) {
- sub->owner->fds[0] = ast_rtp_fd(sub->rtp);
- }
- if (sub->rtp) {
- ast_rtp_setnat(sub->rtp, sub->nat);
- }
- /* Create the RTP connection */
- transmit_connect(sub->parent->parent->session);
- ast_mutex_unlock(&sub->lock);
-}
-
-static void *skinny_ss(void *data)
-{
- struct ast_channel *chan = data;
- struct skinny_subchannel *sub = chan->tech_pvt;
- struct skinny_line *l = sub->parent;
- struct skinnysession *s = l->parent->session;
- char exten[AST_MAX_EXTENSION] = "";
- int len = 0;
- int timeout = firstdigittimeout;
- int res;
- int getforward=0;
-
- if (option_verbose > 2) {
- ast_verbose( VERBOSE_PREFIX_3 "Starting simple switch on '%s@%s'\n", l->name, l->parent->name);
- }
- while(len < AST_MAX_EXTENSION-1) {
- res = ast_waitfordigit(chan, timeout);
- timeout = 0;
- if (res < 0) {
- if (skinnydebug) {
- ast_verbose("Skinny(%s@%s): waitfordigit returned < 0\n", l->name, l->parent->name);
- }
- ast_indicate(chan, -1);
- ast_hangup(chan);
- return NULL;
- } else if (res) {
- exten[len++]=res;
- exten[len] = '\0';
- }
- if (!ast_ignore_pattern(chan->context, exten)) {
- transmit_tone(s, SKINNY_SILENCE);
- }
- if (ast_exists_extension(chan, chan->context, exten, 1, l->cid_num)) {
- if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, l->cid_num)) {
- if (getforward) {
- /* Record this as the forwarding extension */
- strncpy(l->call_forward, exten, sizeof(l->call_forward) - 1);
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Setting call forward to '%s' on channel %s\n",
- l->call_forward, chan->name);
- }
- transmit_tone(s, SKINNY_DIALTONE);
- if (res) {
- break;
- }
- ast_safe_sleep(chan, 500);
- ast_indicate(chan, -1);
- ast_safe_sleep(chan, 1000);
- memset(exten, 0, sizeof(exten));
- transmit_tone(s, SKINNY_DIALTONE);
- len = 0;
- getforward = 0;
- } else {
- strncpy(chan->exten, exten, sizeof(chan->exten)-1);
- if (!ast_strlen_zero(l->cid_num)) {
- if (!l->hidecallerid) {
- chan->cid.cid_num = strdup(l->cid_num);
- chan->cid.cid_ani = strdup(l->cid_num);
- }
- ast_setstate(chan, AST_STATE_RING);
- res = ast_pbx_run(chan);
- if (res) {
- ast_log(LOG_WARNING, "PBX exited non-zero\n");
- transmit_tone(s, SKINNY_REORDER);
- }
- return NULL;
- }
- }
- } else {
- /* It's a match, but they just typed a digit, and there is an ambiguous match,
- so just set the timeout to matchdigittimeout and wait some more */
- timeout = matchdigittimeout;
- }
- } else if (res == 0) {
- ast_log(LOG_DEBUG, "Not enough digits (and no ambiguous match)...\n");
- transmit_tone(s, SKINNY_REORDER);
- ast_hangup(chan);
- return NULL;
- } else if (l->callwaiting && !strcmp(exten, "*70")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Disabling call waiting on %s\n", chan->name);
- }
- /* Disable call waiting if enabled */
- l->callwaiting = 0;
- transmit_tone(s, SKINNY_DIALTONE);
- len = 0;
- memset(exten, 0, sizeof(exten));\
- timeout = firstdigittimeout;
- } else if (!strcmp(exten,ast_pickup_ext())) {
- /* Scan all channels and see if any there
- * ringing channqels with that have call groups
- * that equal this channels pickup group
- */
- if (ast_pickup_call(chan)) {
- ast_log(LOG_WARNING, "No call pickup possible...\n");
- transmit_tone(s, SKINNY_REORDER);
- }
- ast_hangup(chan);
- return NULL;
- } else if (!l->hidecallerid && !strcmp(exten, "*67")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Disabling Caller*ID on %s\n", chan->name);
- }
- /* Disable Caller*ID if enabled */
- l->hidecallerid = 1;
- if (chan->cid.cid_num) {
- free(chan->cid.cid_num);
- }
- chan->cid.cid_num = NULL;
- if (chan->cid.cid_name) {
- free(chan->cid.cid_name);
- }
- chan->cid.cid_name = NULL;
- transmit_tone(s, SKINNY_DIALTONE);
- len = 0;
- memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
- } else if (l->callreturn && !strcmp(exten, "*69")) {
- res = 0;
- if (!ast_strlen_zero(l->lastcallerid)) {
- res = ast_say_digit_str(chan, l->lastcallerid, "", chan->language);
- }
- if (!res) {
- transmit_tone(s, SKINNY_DIALTONE);
- }
- break;
- } else if (!strcmp(exten, "*78")) {
- /* Do not disturb */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Enabled DND on channel %s\n", chan->name);
- }
- transmit_tone(s, SKINNY_DIALTONE);
- l->dnd = 1;
- getforward = 0;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (!strcmp(exten, "*79")) {
- /* Do not disturb */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Disabled DND on channel %s\n", chan->name);
- }
- transmit_tone(s, SKINNY_DIALTONE);
- l->dnd = 0;
- getforward = 0;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (l->cancallforward && !strcmp(exten, "*72")) {
- transmit_tone(s, SKINNY_DIALTONE);
- getforward = 1;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (l->cancallforward && !strcmp(exten, "*73")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Cancelling call forwarding on channel %s\n", chan->name);
- }
- transmit_tone(s, SKINNY_DIALTONE);
- memset(l->call_forward, 0, sizeof(l->call_forward));
- getforward = 0;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (!strcmp(exten, ast_parking_ext()) &&
- sub->next->owner &&
- ast_bridged_channel(sub->next->owner)) {
- /* This is a three way call, the main call being a real channel,
- and we're parking the first call. */
- ast_masq_park_call(ast_bridged_channel(sub->next->owner), chan, 0, NULL);
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Parking call to '%s'\n", chan->name);
- }
- break;
- } else if (!ast_strlen_zero(l->lastcallerid) && !strcmp(exten, "*60")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Blacklisting number %s\n", l->lastcallerid);
- }
- res = ast_db_put("blacklist", l->lastcallerid, "1");
- if (!res) {
- transmit_tone(s, SKINNY_DIALTONE);
- memset(exten, 0, sizeof(exten));
- len = 0;
- }
- } else if (l->hidecallerid && !strcmp(exten, "*82")) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Enabling Caller*ID on %s\n", chan->name);
- }
- /* Enable Caller*ID if enabled */
- l->hidecallerid = 0;
- if (chan->cid.cid_num) {
- free(chan->cid.cid_num);
- }
- if (!ast_strlen_zero(l->cid_num)) {
- chan->cid.cid_num = strdup(l->cid_num);
- }
- if (chan->cid.cid_name) {
- free(chan->cid.cid_name);
- }
- if (!ast_strlen_zero(l->cid_name)) {
- chan->cid.cid_name = strdup(l->cid_name);
- }
- transmit_tone(s, SKINNY_DIALTONE);
- len = 0;
- memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
- } else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->cid.cid_num) &&
- ((exten[0] != '*') || (!ast_strlen_zero(exten) > 2))) {
- ast_log(LOG_WARNING, "Can't match [%s] from '%s' in context %s\n", exten, chan->cid.cid_num ? chan->cid.cid_num : "<Unknown Caller>", chan->context);
- transmit_tone(s, SKINNY_REORDER);
- /* hang out for 3 seconds to let congestion play */
- ast_safe_sleep(chan, 3000);
- break;
- }
- if (!timeout) {
- timeout = gendigittimeout;
- }
- if (len && !ast_ignore_pattern(chan->context, exten)) {
- ast_indicate(chan, -1);
- }
- }
- ast_hangup(chan);
- return NULL;
-}
-
-
-
-static int skinny_call(struct ast_channel *ast, char *dest, int timeout)
-{
- int res = 0;
- int tone = 0;
- struct skinny_line *l;
- struct skinny_subchannel *sub;
- struct skinnysession *session;
-
- sub = ast->tech_pvt;
- l = sub->parent;
- session = l->parent->session;
-
- if (!l->parent->registered) {
- ast_log(LOG_ERROR, "Device not registered, cannot call %s\n", dest);
- return -1;
- }
-
- if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "skinny_call called on %s, neither down nor reserved\n", ast->name);
- return -1;
- }
-
- if (skinnydebug) {
- ast_verbose(VERBOSE_PREFIX_3 "skinny_call(%s)\n", ast->name);
- }
-
- if (l->dnd) {
- ast_queue_control(ast, AST_CONTROL_BUSY);
- return -1;
- }
-
- switch (l->hookstate) {
- case SKINNY_OFFHOOK:
- tone = SKINNY_CALLWAITTONE;
- break;
- case SKINNY_ONHOOK:
- tone = SKINNY_ALERT;
- break;
- default:
- ast_log(LOG_ERROR, "Don't know how to deal with hookstate %d\n", l->hookstate);
- break;
- }
-
- transmit_lamp_indication(session, STIMULUS_LINE, l->instance, SKINNY_LAMP_BLINK);
- transmit_ringer_mode(session, SKINNY_RING_INSIDE);
-
- if (ast->cid.cid_num) {
- char ciddisplay[41];
- char *work;
- size_t size = sizeof(ciddisplay);
-
- /* For now, we'll assume that if it is 10 numbers, it is a standard NANPA number */
- if (strlen(ast->cid.cid_num) == 10) {
- ast_build_string(&work, &size, "(xxx)xxx-xxxx %s",
- ast->cid.cid_name ? ast->cid.cid_name : "");
- memcpy(&ciddisplay[1], ast->cid.cid_num, 3);
- memcpy(&ciddisplay[5], &ast->cid.cid_num[3], 3);
- memcpy(&ciddisplay[9], &ast->cid.cid_num[6], 4);
- } else {
- if (strlen(ast->cid.cid_num) < 41) {
- ast_build_string(&work, &size, "%s -- %s", ast->cid.cid_num,
- ast->cid.cid_name ? ast->cid.cid_name : "");
- } else {
- strncpy(ciddisplay, "Number too long!", 15);
- }
- }
- if (skinnydebug) {
- ast_verbose("Trying to send: '%s'\n",ciddisplay);
- }
- transmit_displaymessage(session, ciddisplay);
- } else {
- transmit_displaymessage(session, "Unknown Name");
- }
- transmit_tone(session, tone);
- transmit_callstate(session, l->instance, SKINNY_RINGIN, sub->callid);
- transmit_displaypromptstatus(session, "Ring-In", 0, l->instance, sub->callid);
- transmit_callinfo(session, ast->cid.cid_name, ast->cid.cid_num, l->cid_name, l->cid_num, l->instance, sub->callid, 1);
-
- /* XXX need to deal with softkeys */
-
- ast_setstate(ast, AST_STATE_RINGING);
- ast_queue_control(ast, AST_CONTROL_RINGING);
- sub->outgoing = 1;
- return res;
-}
-
-static int skinny_hangup(struct ast_channel *ast)
-{
- struct skinny_subchannel *sub = ast->tech_pvt;
- struct skinny_line *l = sub->parent;
- struct skinnysession *s = l->parent->session;
-
- if (skinnydebug) {
- ast_verbose("skinny_hangup(%s) on %s@%s\n", ast->name, l->name, l->parent->name);
- }
- if (!ast->tech_pvt) {
- ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n");
- return 0;
- }
-
- if (l->parent->registered) {
- if ((sub->parent->type = TYPE_LINE) && (sub->parent->hookstate == SKINNY_OFFHOOK)) {
- sub->parent->hookstate = SKINNY_ONHOOK;
- transmit_callstate(s, l->instance, SKINNY_ONHOOK, sub->callid);
- transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_OFF);
- transmit_speaker_mode(s, SKINNY_SPEAKEROFF);
- } else if ((sub->parent->type = TYPE_LINE) && (sub->parent->hookstate == SKINNY_ONHOOK)) {
- transmit_callstate(s, l->instance, SKINNY_ONHOOK, sub->callid);
- transmit_speaker_mode(s, SKINNY_SPEAKEROFF);
- transmit_ringer_mode(s, SKINNY_RING_OFF);
- transmit_tone(s, SKINNY_SILENCE);
- transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_OFF);
- do_housekeeping(s);
- }
- }
- ast_mutex_lock(&sub->lock);
- sub->owner = NULL;
- ast->tech_pvt = NULL;
- sub->alreadygone = 0;
- sub->outgoing = 0;
- if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
- sub->rtp = NULL;
- }
- ast_mutex_unlock(&sub->lock);
- return 0;
-}
-
-static int skinny_answer(struct ast_channel *ast)
-{
- int res = 0;
- struct skinny_subchannel *sub = ast->tech_pvt;
- struct skinny_line *l = sub->parent;
- struct skinnysession *s = l->parent->session;
-
- sub->cxmode = SKINNY_CX_SENDRECV;
- if (!sub->rtp) {
- start_rtp(sub);
- }
- ast_verbose("skinny_answer(%s) on %s@%s-%d\n", ast->name, l->name, l->parent->name, sub->callid);
- if (ast->_state != AST_STATE_UP) {
- ast_setstate(ast, AST_STATE_UP);
- }
- transmit_tone(s, SKINNY_NOTONE);
- transmit_callstate(s, l->instance, SKINNY_CONNECTED, sub->callid);
- transmit_displaypromptstatus(s, "Connected", 0, l->instance, sub->callid);
- return res;
-}
-
-static struct ast_frame *skinny_rtp_read(struct skinny_subchannel *sub)
-{
- /* Retrieve audio/etc from channel. Assumes sub->lock is already held. */
- struct ast_frame *f;
- f = ast_rtp_read(sub->rtp);
- if (sub->owner) {
- /* We already hold the channel lock */
- if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass != sub->owner->nativeformats) {
- ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
- sub->owner->nativeformats = f->subclass;
- ast_set_read_format(sub->owner, sub->owner->readformat);
- ast_set_write_format(sub->owner, sub->owner->writeformat);
- }
- }
- }
- return f;
-}
-
-static struct ast_frame *skinny_read(struct ast_channel *ast)
-{
- struct ast_frame *fr;
- struct skinny_subchannel *sub = ast->tech_pvt;
- ast_mutex_lock(&sub->lock);
- fr = skinny_rtp_read(sub);
- ast_mutex_unlock(&sub->lock);
- return fr;
-}
-
-static int skinny_write(struct ast_channel *ast, struct ast_frame *frame)
-{
- struct skinny_subchannel *sub = ast->tech_pvt;
- int res = 0;
- if (frame->frametype != AST_FRAME_VOICE) {
- if (frame->frametype == AST_FRAME_IMAGE) {
- return 0;
- } else {
- ast_log(LOG_WARNING, "Can't send %d type frames with skinny_write\n", frame->frametype);
- return 0;
- }
- } else {
- if (!(frame->subclass & ast->nativeformats)) {
- ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
- frame->subclass, ast->nativeformats, ast->readformat, ast->writeformat);
- return -1;
- }
- }
- if (sub) {
- ast_mutex_lock(&sub->lock);
- if (sub->rtp) {
- res = ast_rtp_write(sub->rtp, frame);
- }
- ast_mutex_unlock(&sub->lock);
- }
- return res;
-}
-
-static int skinny_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct skinny_subchannel *sub = newchan->tech_pvt;
- ast_log(LOG_NOTICE, "skinny_fixup(%s, %s)\n", oldchan->name, newchan->name);
- if (sub->owner != oldchan) {
- ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, sub->owner);
- return -1;
- }
- sub->owner = newchan;
- return 0;
-}
-
-static int skinny_senddigit(struct ast_channel *ast, char digit)
-{
-#if 0
- struct skinny_subchannel *sub = ast->tech_pvt;
- int tmp;
- /* not right */
- sprintf(tmp, "%d", digit);
- transmit_tone(sub->parent->parent->session, digit);
-#endif
- return -1;
-}
-
-static char *control2str(int ind) {
- static char tmp[100];
-
- switch (ind) {
- case AST_CONTROL_HANGUP:
- return "Other end has hungup";
- case AST_CONTROL_RING:
- return "Local ring";
- case AST_CONTROL_RINGING:
- return "Remote end is ringing";
- case AST_CONTROL_ANSWER:
- return "Remote end has answered";
- case AST_CONTROL_BUSY:
- return "Remote end is busy";
- case AST_CONTROL_TAKEOFFHOOK:
- return "Make it go off hook";
- case AST_CONTROL_OFFHOOK:
- return "Line is off hook";
- case AST_CONTROL_CONGESTION:
- return "Congestion (circuits busy)";
- case AST_CONTROL_FLASH:
- return "Flash hook";
- case AST_CONTROL_WINK:
- return "Wink";
- case AST_CONTROL_OPTION:
- return "Set a low-level option";
- case AST_CONTROL_RADIO_KEY:
- return "Key Radio";
- case AST_CONTROL_RADIO_UNKEY:
- return "Un-Key Radio";
- case AST_CONTROL_PROGRESS:
- return "Remote end is making Progress";
- case AST_CONTROL_PROCEEDING:
- return "Remote end is proceeding";
- case AST_CONTROL_HOLD:
- return "Hold";
- case AST_CONTROL_UNHOLD:
- return "Unhold";
- case -1:
- return "Stop tone";
- }
- snprintf(tmp, 100, "UNKNOWN-%d", ind);
- return tmp;
-}
-
-
-static int skinny_indicate(struct ast_channel *ast, int ind)
-{
- struct skinny_subchannel *sub = ast->tech_pvt;
- struct skinny_line *l = sub->parent;
- struct skinnysession *s = l->parent->session;
-
- if (skinnydebug) {
- ast_verbose(VERBOSE_PREFIX_3 "Asked to indicate '%s' condition on channel %s\n", control2str(ind), ast->name);
- }
- switch(ind) {
- case AST_CONTROL_RINGING:
- if (ast->_state != AST_STATE_UP) {
- if (!sub->progress) {
- transmit_tone(s, SKINNY_ALERT);
- transmit_callstate(s, l->instance, SKINNY_RINGOUT, sub->callid);
- transmit_diallednumber(s, ast->exten, l->instance, sub->callid);
- transmit_displaypromptstatus(s, "Ring Out", 0, l->instance, sub->callid);
- transmit_callinfo(s, ast->cid.cid_name, ast->cid.cid_num, ast->exten, ast->exten, l->instance, sub->callid, 2); /* 2 = outgoing from phone */
- sub->ringing = 1;
- break;
- }
- }
- return -1;
- case AST_CONTROL_BUSY:
- if (ast->_state != AST_STATE_UP) {
- transmit_tone(s, SKINNY_BUSYTONE);
- transmit_callstate(s, l->instance, SKINNY_BUSY, sub->callid);
- sub->alreadygone = 1;
- ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV);
- break;
- }
- return -1;
- case AST_CONTROL_CONGESTION:
- if (ast->_state != AST_STATE_UP) {
- transmit_tone(s, SKINNY_REORDER);
- transmit_callstate(s, l->instance, SKINNY_CONGESTION, sub->callid);
- sub->alreadygone = 1;
- ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV);
- break;
- }
- return -1;
- case AST_CONTROL_PROGRESS:
- if ((ast->_state != AST_STATE_UP) && !sub->progress && !sub->outgoing) {
- transmit_tone(s, SKINNY_ALERT);
- transmit_callstate(s, l->instance, SKINNY_PROGRESS, sub->callid);
- transmit_displaypromptstatus(s, "Call Progress", 0, l->instance, sub->callid);
- transmit_callinfo(s, ast->cid.cid_name, ast->cid.cid_num, ast->exten, ast->exten, l->instance, sub->callid, 2); /* 2 = outgoing from phone */
- sub->progress = 1;
- break;
- }
- return -1;
- case -1:
- transmit_tone(s, SKINNY_SILENCE);
- break;
- case AST_CONTROL_PROCEEDING:
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", ind);
- return -1;
- }
- return 0;
-}
-
-static struct ast_channel *skinny_new(struct skinny_subchannel *sub, int state)
-{
- struct ast_channel *tmp;
- struct skinny_line *l = sub->parent;
- int fmt;
- l = sub->parent;
- tmp = ast_channel_alloc(1);
- if (tmp) {
- tmp->tech = &skinny_tech;
- tmp->nativeformats = l->capability;
- if (!tmp->nativeformats)
- tmp->nativeformats = capability;
- fmt = ast_best_codec(tmp->nativeformats);
- ast_verbose("skinny_new: tmp->nativeformats=%d fmt=%d\n", tmp->nativeformats, fmt);
- snprintf(tmp->name, sizeof(tmp->name), "Skinny/%s@%s-%d", l->name, l->parent->name, sub->callid);
- if (sub->rtp) {
- tmp->fds[0] = ast_rtp_fd(sub->rtp);
- }
- tmp->type = type;
- ast_setstate(tmp, state);
- if (state == AST_STATE_RING) {
- tmp->rings = 1;
- }
- tmp->writeformat = fmt;
- tmp->rawwriteformat = fmt;
- tmp->readformat = fmt;
- tmp->rawreadformat = fmt;
- tmp->tech_pvt = sub;
- if (!ast_strlen_zero(l->language)) {
- strncpy(tmp->language, l->language, sizeof(tmp->language)-1);
- }
- if (!ast_strlen_zero(l->accountcode)) {
- strncpy(tmp->accountcode, l->accountcode, sizeof(tmp->accountcode)-1);
- }
- if (l->amaflags) {
- tmp->amaflags = l->amaflags;
- }
- sub->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- tmp->callgroup = l->callgroup;
- tmp->pickupgroup = l->pickupgroup;
- strncpy(tmp->call_forward, l->call_forward, sizeof(tmp->call_forward) - 1);
- strncpy(tmp->context, l->context, sizeof(tmp->context)-1);
- strncpy(tmp->exten,l->exten, sizeof(tmp->exten)-1);
- if (!ast_strlen_zero(l->cid_num)) {
- tmp->cid.cid_num = strdup(l->cid_num);
- }
- if (!ast_strlen_zero(l->cid_name)) {
- tmp->cid.cid_name = strdup(l->cid_name);
- }
- tmp->priority = 1;
- tmp->adsicpe = AST_ADSI_UNAVAILABLE;
-
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- tmp = NULL;
- }
- }
- } else {
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- }
- return tmp;
-}
-
-static int handle_message(skinny_req *req, struct skinnysession *s)
-{
- struct skinny_subchannel *sub;
- struct ast_channel *c;
- struct ast_frame f = { 0, };
- struct sockaddr_in sin;
- struct sockaddr_in us;
- struct skinny_line *lines;
- char name[16];
- char addr[4];
- char d;
- char iabuf[INET_ADDRSTRLEN];
- int digit;
- int res=0;
- int speedDialNum;
- int lineNumber;
- int stimulus;
- int stimulusInstance;
- int status;
- int port;
- int i;
- time_t timer;
- struct tm *cmtime;
- pthread_t t;
- button_defs_t *b, *buse;
-
- if ((!s->device) && (letohl(req->e) != REGISTER_MESSAGE && letohl(req->e) != ALARM_MESSAGE)) {
- ast_log(LOG_WARNING, "Client sent message #%d without first registering.\n", req->e);
- free(req);
- return 0;
- }
-
- switch(letohl(req->e)) {
- case ALARM_MESSAGE:
- /* no response necessary */
- break;
- case REGISTER_MESSAGE:
- if (skinnydebug) {
- ast_verbose("Device %s is attempting to register\n", req->data.reg.name);
- }
- res = skinny_register(req, s);
- if (!res) {
- ast_log(LOG_ERROR, "Rejecting Device %s: Device not found\n", req->data.reg.name);
- memcpy(&name, req->data.reg.name, sizeof(req->data.reg.name));
- memset(req, 0, sizeof(skinny_req));
- req->len = htolel(sizeof(register_rej_message)+4);
- req->e = htolel(REGISTER_REJ_MESSAGE);
- snprintf(req->data.regrej.errMsg, sizeof(req->data.regrej.errMsg), "No Authority: %s", name);
- transmit_response(s, req);
- break;
- }
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Device '%s' successfuly registered\n", s->device->name);
- }
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(sizeof(register_ack_message)+4);
- req->e = htolel(REGISTER_ACK_MESSAGE);
- req->data.regack.res[0] = '0';
- req->data.regack.res[1] = '\0';
- req->data.regack.keepAlive = htolel(keep_alive);
- strncpy(req->data.regack.dateTemplate, date_format, sizeof(req->data.regack.dateTemplate) - 1);
- req->data.regack.res2[0] = '0';
- req->data.regack.res2[1] = '\0';
- req->data.regack.secondaryKeepAlive = htolel(keep_alive);
- transmit_response(s, req);
- if (skinnydebug) {
- ast_verbose("Requesting capabilities\n");
- }
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(4);
- req->e = htolel(CAPABILITIES_REQ_MESSAGE);
- transmit_response(s, req);
- break;
- case UNREGISTER_MESSAGE:
- /* XXX Acutally unregister the device */
- break;
- case IP_PORT_MESSAGE:
- /* no response necessary */
- break;
- case STIMULUS_MESSAGE:
- stimulus = letohl(req->data.stimulus.stimulus);
- stimulusInstance = letohl(req->data.stimulus.stimulusInstance);
-
- switch(stimulus) {
- case STIMULUS_REDIAL:
- /* If we can keep an array of dialed frames we can implement a quick
- and dirty redial, feeding the frames we last got into the queue
- function */
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: Redial(%d)\n", stimulusInstance);
- }
- break;
- case STIMULUS_SPEEDDIAL:
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: SpeedDial(%d)\n", stimulusInstance);
- }
- break;
- case STIMULUS_HOLD:
- /* start moh? set RTP to 0.0.0.0? */
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: Hold(%d)\n", stimulusInstance);
- }
- break;
- case STIMULUS_TRANSFER:
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: Transfer(%d)\n", stimulusInstance);
- }
- transmit_tone(s, SKINNY_DIALTONE);
- /* XXX figure out how to transfer */
- break;
- case STIMULUS_CONFERENCE:
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: Transfer(%d)\n", stimulusInstance);
- }
- transmit_tone(s, SKINNY_DIALTONE);
- /* XXX determine the best way to pull off a conference. Meetme? */
- break;
- case STIMULUS_VOICEMAIL:
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: Voicemail(%d)\n", stimulusInstance);
- }
- /* XXX Find and dial voicemail extension */
- break;
- case STIMULUS_CALLPARK:
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: Park Call(%d)\n", stimulusInstance);
- }
- /* XXX Park the call */
- break;
- case STIMULUS_FORWARDALL:
- /* Why is DND under FORWARDALL ? */
-
- /* Do not disturb */
- transmit_tone(s, SKINNY_DIALTONE);
- if (s->device->lines->dnd != 0){
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Disabling DND on %s@%s\n",find_subchannel_by_line(s->device->lines)->parent->name,find_subchannel_by_line(s->device->lines)->parent->name);
- }
- s->device->lines->dnd = 0;
- transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_ON);
- transmit_displaynotify(s, "DnD disabled",10);
- } else {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Enabling DND on %s@%s\n",find_subchannel_by_line(s->device->lines)->parent->name,find_subchannel_by_line(s->device->lines)->parent->name);
- }
- s->device->lines->dnd = 1;
- transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_OFF);
- transmit_displaynotify(s, "DnD enabled",10);
- }
- break;
- case STIMULUS_FORWARDBUSY:
- case STIMULUS_FORWARDNOANSWER:
- /* Gonna be fun, not */
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: Forward (%d)\n", stimulusInstance);
- }
- break;
- case STIMULUS_DISPLAY:
- /* Not sure what this is */
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: Display(%d)\n", stimulusInstance);
- }
- break;
- case STIMULUS_LINE:
- if (skinnydebug) {
- ast_verbose("Recieved Stimulus: Line(%d)\n", stimulusInstance);
- }
- sub = find_subchannel_by_line(s->device->lines);
- /* turn the speaker on */
- transmit_speaker_mode(s, 1);
- break;
- default:
- ast_verbose("RECEIVED UNKNOWN STIMULUS: %d(%d)\n", stimulus, stimulusInstance);
- break;
- }
- break;
- case VERSION_REQ_MESSAGE:
- if (skinnydebug) {
- ast_verbose("Version Request\n");
- }
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(sizeof(version_res_message)+4);
- req->e = htolel(VERSION_RES_MESSAGE);
- snprintf(req->data.version.version, sizeof(req->data.version.version), s->device->version_id);
- transmit_response(s, req);
- break;
- case SERVER_REQUEST_MESSAGE:
- if (skinnydebug) {
- ast_verbose("Recieved Server Request\n");
- }
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(sizeof(server_res_message)+4);
- req->e = htolel(SERVER_RES_MESSAGE);
- memcpy(req->data.serverres.server[0].serverName, ourhost,
- sizeof(req->data.serverres.server[0].serverName));
- req->data.serverres.serverListenPort[0] = htolel(ourport);
- req->data.serverres.serverIpAddr[0] = htolel(__ourip.s_addr);
- transmit_response(s, req);
- break;
- case BUTTON_TEMPLATE_REQ_MESSAGE:
- if (skinnydebug) {
- ast_verbose("Buttontemplate requested\n");
- }
- sub = find_subchannel_by_line(s->device->lines);
- memset(req, 0, SKINNY_MAX_PACKET);
- req->e = htolel(BUTTON_TEMPLATE_RES_MESSAGE);
- req->len = htolel(sizeof(button_template_res_message)+4);
-
- /* Find a matching button definition, default to first in the
- list */
- buse = button_defs;
- for(b=button_defs; b->type; b++) {
- if (!strcmp(s->device->model, b->type)) {
- buse = b;
- }
- }
- req->data.buttontemplate.buttonOffset = 0;
- req->data.buttontemplate.buttonCount = htolel(buse->num_buttons);
- req->data.buttontemplate.totalButtonCount = htolel(buse->num_buttons);
- for (i=0; i<42; i++) {
- if (i < buse->num_buttons) {
- memcpy(&(req->data.buttontemplate.definition[i]),
- &(buse->button_def[i]),
- sizeof(button_definition));
- } else {
- memcpy(&(req->data.buttontemplate.definition[i]),
- &(button_def_none),
- sizeof(button_definition));
- }
- }
-
- if (skinnydebug) {
- ast_verbose("Sending %s template to %s@%s (%s)\n",
- buse->type,
- sub->parent->name,
- sub->parent->parent->name,
- s->device->model);
- }
- transmit_response(s, req);
- break;
- case SOFT_KEY_SET_REQ_MESSAGE:
- if (skinnydebug) {
- ast_verbose("Received SoftKeySetReq\n");
- }
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(sizeof(soft_key_sets)+4);
- req->e = htolel(SOFT_KEY_SET_RES_MESSAGE);
- req->data.softkeysets.softKeySetOffset = 0;
- req->data.softkeysets.softKeySetCount = htolel(11);
- req->data.softkeysets.totalSoftKeySetCount = htolel(11);
- /* XXX Wicked hack XXX */
- memcpy(req->data.softkeysets.softKeySetDefinition,
- soft_key_set_hack,
- sizeof(req->data.softkeysets.softKeySetDefinition));
- transmit_response(s,req);
- break;
- case SOFT_KEY_TEMPLATE_REQ_MESSAGE:
- if (skinnydebug) {
- ast_verbose("Recieved SoftKey Template Request\n");
- }
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(sizeof(soft_key_template)+4);
- req->e = htolel(SOFT_KEY_TEMPLATE_RES_MESSAGE);
- req->data.softkeytemplate.softKeyOffset = 0;
- req->data.softkeytemplate.softKeyCount = htolel(sizeof(soft_key_template_default) / sizeof(soft_key_template_definition));
- req->data.softkeytemplate.totalSoftKeyCount = htolel(sizeof(soft_key_template_default) / sizeof(soft_key_template_definition));
- memcpy(req->data.softkeytemplate.softKeyTemplateDefinition,
- soft_key_template_default,
- sizeof(soft_key_template_default));
- transmit_response(s,req);
- break;
- case TIME_DATE_REQ_MESSAGE:
- if (skinnydebug) {
- ast_verbose("Received Time/Date Request\n");
- }
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(sizeof(definetimedate_message)+4);
- req->e = htolel(DEFINETIMEDATE_MESSAGE);
- timer=time(NULL);
- cmtime = localtime(&timer);
- req->data.definetimedate.year = htolel(cmtime->tm_year+1900);
- req->data.definetimedate.month = htolel(cmtime->tm_mon+1);
- req->data.definetimedate.dayofweek = htolel(cmtime->tm_wday);
- req->data.definetimedate.day = htolel(cmtime->tm_mday);
- req->data.definetimedate.hour = htolel(cmtime->tm_hour);
- req->data.definetimedate.minute = htolel(cmtime->tm_min);
- req->data.definetimedate.seconds = htolel(cmtime->tm_sec);
- transmit_response(s, req);
- break;
- case SPEED_DIAL_STAT_REQ_MESSAGE:
- /* Not really sure how Speed Dial's are different than the
- Softkey templates */
- speedDialNum = letohl(req->data.speeddialreq.speedDialNumber);
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(sizeof(speed_dial_stat_res_message)+4);
- req->e = htolel(SPEED_DIAL_STAT_RES_MESSAGE);
-#if 0
- /* XXX Do this right XXX */
- /* If the redial function works the way I think it will, a modification of it
- can work here was well. Yikes. */
- req->data.speeddialreq.speedDialNumber = speedDialNum;
- snprintf(req->data.speeddial.speedDialDirNumber, sizeof(req->data.speeddial.speedDialDirNumber), "31337");
- snprintf(req->data.speeddial.speedDialDisplayName, sizeof(req->data.speeddial.speedDialDisplayName),"Asterisk Rules!");
-#endif
- transmit_response(s, req);
- break;
- case LINE_STATE_REQ_MESSAGE:
- lineNumber = letohl(req->data.line.lineNumber);
- if (skinnydebug) {
- ast_verbose("Received LineStateReq\n");
- }
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(sizeof(line_stat_res_message)+4);
- req->e = htolel(LINE_STAT_RES_MESSAGE);
- sub = find_subchannel_by_line(s->device->lines);
- if (!sub) {
- ast_log(LOG_NOTICE, "No available lines on: %s\n", s->device->name);
- return 0;
- }
- lines = sub->parent;
- ast_mutex_lock(&devicelock);
- for (i=1; i < lineNumber; i++) {
- lines = lines->next;
- }
- ast_mutex_unlock(&devicelock);
- req->data.linestat.linenumber = letohl(lineNumber);
- memcpy(req->data.linestat.lineDirNumber, lines->name,
- sizeof(req->data.linestat.lineDirNumber));
- memcpy(req->data.linestat.lineDisplayName, lines->label,
- sizeof(req->data.linestat.lineDisplayName));
- transmit_response(s,req);
- break;
- case CAPABILITIES_RES_MESSAGE:
- if (skinnydebug) {
- ast_verbose("Received CapabilitiesRes\n");
- }
- /* XXX process the capabilites */
- break;
- case KEEP_ALIVE_MESSAGE:
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(4);
- req->e = htolel(KEEP_ALIVE_ACK_MESSAGE);
- transmit_response(s, req);
- do_housekeeping(s);
- break;
- case OFFHOOK_MESSAGE:
- transmit_ringer_mode(s,SKINNY_RING_OFF);
- transmit_lamp_indication(s, STIMULUS_LINE, s->device->lines->instance, SKINNY_LAMP_ON);
- sub = find_subchannel_by_line(s->device->lines);
- if (!sub) {
- ast_log(LOG_NOTICE, "No available lines on: %s\n", s->device->name);
- return 0;
- }
- sub->parent->hookstate = SKINNY_OFFHOOK;
-
- if (sub->outgoing) {
- /* We're answering a ringing call */
- ast_queue_control(sub->owner, AST_CONTROL_ANSWER);
- transmit_callstate(s, s->device->lines->instance, SKINNY_OFFHOOK, sub->callid);
- transmit_tone(s, SKINNY_SILENCE);
- transmit_callstate(s, s->device->lines->instance, SKINNY_CONNECTED, sub->callid);
- start_rtp(sub);
- ast_setstate(sub->owner, AST_STATE_UP);
- /* XXX select the appropriate soft key here */
- } else {
- if (!sub->owner) {
- transmit_callstate(s, s->device->lines->instance, SKINNY_OFFHOOK, sub->callid);
- if (skinnydebug) {
- ast_verbose("Attempting to Clear display on Skinny %s@%s\n",sub->parent->name, sub->parent->parent->name);
- }
- transmit_displaymessage(s, NULL); /* clear display */
- transmit_tone(s, SKINNY_DIALTONE);
- c = skinny_new(sub, AST_STATE_DOWN);
- if(c) {
- /* start the switch thread */
- if (ast_pthread_create(&t, NULL, skinny_ss, c)) {
- ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno));
- ast_hangup(c);
- }
- } else {
- ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", sub->parent->name, s->device->name);
- }
- } else {
- ast_log(LOG_DEBUG, "Current sub [%s] already has owner\n", sub->owner->name);
- }
- }
- break;
- case ONHOOK_MESSAGE:
- sub = find_subchannel_by_line(s->device->lines);
- if (sub->parent->hookstate == SKINNY_ONHOOK) {
- /* Somthing else already put us back on hook */
- break;
- }
- sub->cxmode = SKINNY_CX_RECVONLY;
- sub->parent->hookstate = SKINNY_ONHOOK;
- transmit_callstate(s, s->device->lines->instance, sub->parent->hookstate,sub->callid);
- if (skinnydebug) {
- ast_verbose("Skinny %s@%s went on hook\n",sub->parent->name, sub->parent->parent->name);
- }
- if (sub->parent->transfer && (sub->owner && sub->next->owner) && ((!sub->outgoing) || (!sub->next->outgoing))) {
- /* We're allowed to transfer, we have two active calls and */
- /* we made at least one of the calls. Let's try and transfer */
-
-#if 0
- if ((res = attempt_transfer(p)) < 0) {
- if (p->sub->next->owner) {
- sub->next->alreadygone = 1;
- ast_queue_hangup(sub->next->owner,1);
- }
- } else if (res) {
- ast_log(LOG_WARNING, "Transfer attempt failed\n");
- return -1;
- }
-#endif
- } else {
- /* Hangup the current call */
- /* If there is another active call, skinny_hangup will ring the phone with the other call */
- if (sub->owner) {
- sub->alreadygone = 1;
- ast_queue_hangup(sub->owner);
- } else {
- ast_log(LOG_WARNING, "Skinny(%s@%s-%d) channel already destroyed\n",
- sub->parent->name, sub->parent->parent->name, sub->callid);
- }
- }
- if ((sub->parent->hookstate == SKINNY_ONHOOK) && (!sub->next->rtp)) {
- do_housekeeping(s);
- }
- break;
- case KEYPAD_BUTTON_MESSAGE:
- digit = letohl(req->data.keypad.button);
- if (skinnydebug) {
- ast_verbose("Collected digit: [%d]\n", digit);
- }
- f.frametype = AST_FRAME_DTMF;
- if (digit == 14) {
- d = '*';
- } else if (digit == 15) {
- d = '#';
- } else if (digit >=0 && digit <= 9) {
- d = '0' + digit;
- } else {
- /* digit=10-13 (A,B,C,D ?), or
- * digit is bad value
- *
- * probably should not end up here, but set
- * value for backward compatibility, and log
- * a warning.
- */
- d = '0' + digit;
- ast_log(LOG_WARNING, "Unsupported digit %d\n", digit);
- }
- f.subclass = d;
- f.src = "skinny";
- sub = find_subchannel_by_line(s->device->lines);
- if (sub->owner) {
- /* XXX MUST queue this frame to all subs in threeway call if threeway call is active */
- ast_queue_frame(sub->owner, &f);
- if (sub->next->owner) {
- ast_queue_frame(sub->next->owner, &f);
- }
- } else {
- ast_verbose("No owner: %s\n", s->device->lines->name);
- }
- break;
- case OPEN_RECIEVE_CHANNEL_ACK_MESSAGE:
- ast_verbose("Recieved Open Recieve Channel Ack\n");
- status = letohl(req->data.openrecievechannelack.status);
- if (status) {
- ast_log(LOG_ERROR, "Open Recieve Channel Failure\n");
- break;
- }
- /* ENDIAN */
- memcpy(addr, req->data.openrecievechannelack.ipAddr, sizeof(addr));
- port = htolel(req->data.openrecievechannelack.port);
- sin.sin_family = AF_INET;
- /* I smell endian problems */
- memcpy(&sin.sin_addr, addr, sizeof(sin.sin_addr));
- sin.sin_port = htons(port);
- if (skinnydebug) {
- ast_verbose("ipaddr = %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- }
- sub = find_subchannel_by_line(s->device->lines);
- if (sub->rtp) {
- ast_rtp_set_peer(sub->rtp, &sin);
- ast_rtp_get_us(sub->rtp, &us);
- } else {
- ast_log(LOG_ERROR, "No RTP structure, this is very bad\n");
- break;
- }
- memset(req, 0, SKINNY_MAX_PACKET);
- req->len = htolel(sizeof(start_media_transmission_message)+4);
- req->e = htolel(START_MEDIA_TRANSMISSION_MESSAGE);
- req->data.startmedia.conferenceId = 0;
- req->data.startmedia.passThruPartyId = 0;
- memcpy(req->data.startmedia.remoteIp, &s->device->ourip, 4); /* Endian? */
- req->data.startmedia.remotePort = htolel(ntohs(us.sin_port));
- req->data.startmedia.packetSize = htolel(20);
- req->data.startmedia.payloadType = htolel(convert_cap(s->device->lines->capability));
- req->data.startmedia.qualifier.precedence = htolel(127);
- req->data.startmedia.qualifier.vad = 0;
- req->data.startmedia.qualifier.packets = 0;
- req->data.startmedia.qualifier.bitRate = 0;
- transmit_response(s, req);
- break;
- default:
- ast_verbose("RECEIVED UNKNOWN MESSAGE TYPE: %x\n", letohl(req->e));
- break;
- }
- free(req);
- return 1;
-}
-
-static void destroy_session(struct skinnysession *s)
-{
- struct skinnysession *cur, *prev = NULL;
- ast_mutex_lock(&sessionlock);
- cur = sessions;
- while(cur) {
- if (cur == s) {
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- if (cur) {
- if (prev) {
- prev->next = cur->next;
- } else {
- sessions = cur->next;
- }
- if (s->fd > -1) {
- close(s->fd);
- }
- ast_mutex_destroy(&s->lock);
- free(s);
- } else {
- ast_log(LOG_WARNING, "Trying to delete nonexistent session %p?\n", s);
- }
- ast_mutex_unlock(&sessionlock);
-}
-
-static int get_input(struct skinnysession *s)
-{
- int res;
- int dlen = 0;
- struct pollfd fds[1];
-
- fds[0].fd = s->fd;
- fds[0].events = POLLIN;
- res = poll(fds, 1, -1);
-
- if (res < 0) {
- ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
- } else if (res > 0) {
- memset(s->inbuf,0,sizeof(s->inbuf));
- res = read(s->fd, s->inbuf, 4);
- if (res != 4) {
- ast_log(LOG_WARNING, "Skinny Client sent less data than expected.\n");
- return -1;
- }
- dlen = letohl(*(int *)s->inbuf);
- if (dlen+8 > sizeof(s->inbuf)) {
- dlen = sizeof(s->inbuf) - 8;
- }
- *(int *)s->inbuf = htolel(dlen);
- res = read(s->fd, s->inbuf+4, dlen+4);
- ast_mutex_unlock(&s->lock);
- if (res != (dlen+4)) {
- ast_log(LOG_WARNING, "Skinny Client sent less data than expected.\n");
- return -1;
- }
- }
- return res;
-}
-
-static skinny_req *skinny_req_parse(struct skinnysession *s)
-{
- skinny_req *req;
-
- req = malloc(SKINNY_MAX_PACKET);
- if (!req) {
- ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
- return NULL;
- }
- memset(req, 0, sizeof(skinny_req));
- /* +8 to account for reserved and length fields */
- memcpy(req, s->inbuf, letohl(*(int*)(s->inbuf))+8);
- if (letohl(req->e) < 0) {
- ast_log(LOG_ERROR, "Event Message is NULL from socket %d, This is bad\n", s->fd);
- free(req);
- return NULL;
- }
- return req;
-}
-
-static void *skinny_session(void *data)
-{
- int res;
- skinny_req *req;
- struct skinnysession *s = data;
- char iabuf[INET_ADDRSTRLEN];
-
- ast_verbose(VERBOSE_PREFIX_3 "Starting Skinny session from %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
- for (;;) {
- res = 0;
- res = get_input(s);
- if (res < 0) {
- break;
- }
- req = skinny_req_parse(s);
- if (!req) {
- return NULL;
- }
- res = handle_message(req, s);
- if (res < 0) {
- destroy_session(s);
- return NULL;
- }
- }
- ast_log(LOG_NOTICE, "Skinny Session returned: %s\n", strerror(errno));
- destroy_session(s);
- return 0;
-}
-
-static void *accept_thread(void *ignore)
-{
- int as;
- struct sockaddr_in sin;
- socklen_t sinlen;
- struct skinnysession *s;
- struct protoent *p;
- int arg = 1;
- pthread_attr_t attr;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- for (;;) {
- sinlen = sizeof(sin);
- as = accept(skinnysock, (struct sockaddr *)&sin, &sinlen);
- if (as < 0) {
- ast_log(LOG_NOTICE, "Accept returned -1: %s\n", strerror(errno));
- continue;
- }
- p = getprotobyname("tcp");
- if(p) {
- if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
- ast_log(LOG_WARNING, "Failed to set Skinny tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
- }
- }
- s = malloc(sizeof(struct skinnysession));
- if (!s) {
- ast_log(LOG_WARNING, "Failed to allocate Skinny session: %s\n", strerror(errno));
- continue;
- }
- memset(s, 0, sizeof(struct skinnysession));
- memcpy(&s->sin, &sin, sizeof(sin));
- ast_mutex_init(&s->lock);
- s->fd = as;
- ast_mutex_lock(&sessionlock);
- s->next = sessions;
- sessions = s;
- ast_mutex_unlock(&sessionlock);
-
- if (ast_pthread_create(&tcp_thread, NULL, skinny_session, s)) {
- destroy_session(s);
- }
- }
- if (skinnydebug) {
- ast_verbose("killing accept thread\n");
- }
- close(as);
- return 0;
-}
-
-static void *do_monitor(void *data)
-{
- int res;
-
- /* This thread monitors all the interfaces which are not yet in use
- (and thus do not have a separate thread) indefinitely */
- /* From here on out, we die whenever asked */
- for(;;) {
- pthread_testcancel();
- /* Wait for sched or io */
- res = ast_sched_wait(sched);
- if ((res < 0) || (res > 1000)) {
- res = 1000;
- }
- res = ast_io_wait(io, res);
- ast_mutex_lock(&monlock);
- if (res >= 0) {
- ast_sched_runq(sched);
- }
- ast_mutex_unlock(&monlock);
- }
- /* Never reached */
- return NULL;
-
-}
-
-static int restart_monitor(void)
-{
- /* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == AST_PTHREADT_STOP)
- return 0;
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_WARNING, "Unable to lock monitor\n");
- return -1;
- }
- if (monitor_thread == pthread_self()) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- return -1;
- }
- if (monitor_thread != AST_PTHREADT_NULL) {
- /* Wake up the thread */
- pthread_kill(monitor_thread, SIGURG);
- } else {
- /* Start a new monitor */
- if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- return -1;
- }
- }
- ast_mutex_unlock(&monlock);
- return 0;
-}
-
-static struct ast_channel *skinny_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- struct skinny_subchannel *sub;
- struct ast_channel *tmpc = NULL;
- char tmp[256];
- char *dest = data;
-
- oldformat = format;
- format &= capability;
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", format);
- return NULL;
- }
- strncpy(tmp, dest, sizeof(tmp) - 1);
- if (ast_strlen_zero(tmp)) {
- ast_log(LOG_NOTICE, "Skinny channels require a device\n");
- return NULL;
- }
- sub = find_subchannel_by_name(tmp);
- if (!sub) {
- ast_log(LOG_NOTICE, "No available lines on: %s\n", dest);
- return NULL;
- }
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "skinny_request(%s)\n", tmp);
- ast_verbose(VERBOSE_PREFIX_3 "Skinny cw: %d, dnd: %d, so: %d, sno: %d\n",
- sub->parent->callwaiting, sub->parent->dnd, sub->owner ? 1 : 0, sub->next->owner ? 1: 0);
- }
- tmpc = skinny_new(sub->owner ? sub->next : sub, AST_STATE_DOWN);
- if (!tmpc) {
- ast_log(LOG_WARNING, "Unable to make channel for '%s'\n", tmp);
- }
- restart_monitor();
- return tmpc;
-}
-
-static int reload_config(void)
-{
- int on = 1;
- struct ast_config *cfg;
- struct ast_variable *v;
- int format;
- char *cat;
- char iabuf[INET_ADDRSTRLEN];
- struct skinny_device *d;
- int oldport = ntohs(bindaddr.sin_port);
-
- if (gethostname(ourhost, sizeof(ourhost))) {
- ast_log(LOG_WARNING, "Unable to get hostname, Skinny disabled\n");
- return 0;
- }
- cfg = ast_config_load(config);
-
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_NOTICE, "Unable to load config %s, Skinny disabled\n", config);
- return 0;
- }
- /* load the general section */
- memset(&bindaddr, 0, sizeof(bindaddr));
- v = ast_variable_browse(cfg, "general");
- while(v) {
- /* Create the interface list */
- if (!strcasecmp(v->name, "bindaddr")) {
- if (!(hp = ast_gethostbyname(v->value, &ahp))) {
- ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
- } else {
- memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
- }
- } else if (!strcasecmp(v->name, "keepAlive")) {
- keep_alive = atoi(v->value);
- } else if (!strcasecmp(v->name, "dateFormat")) {
- strncpy(date_format, v->value, sizeof(date_format) - 1);
- } else if (!strcasecmp(v->name, "allow")) {
- format = ast_getformatbyname(v->value);
- if (format < 1) {
- ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value);
- } else {
- capability |= format;
- }
- } else if (!strcasecmp(v->name, "disallow")) {
- format = ast_getformatbyname(v->value);
- if (format < 1) {
- ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value);
- } else {
- capability &= ~format;
- }
- } else if (!strcasecmp(v->name, "port")) {
- if (sscanf(v->value, "%d", &ourport) == 1) {
- bindaddr.sin_port = htons(ourport);
- } else {
- ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config);
- }
- }
- v = v->next;
- }
- if (ntohl(bindaddr.sin_addr.s_addr)) {
- memcpy(&__ourip, &bindaddr.sin_addr, sizeof(__ourip));
- } else {
- hp = ast_gethostbyname(ourhost, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Unable to get our IP address, Skinny disabled\n");
- ast_config_destroy(cfg);
- return 0;
- }
- memcpy(&__ourip, hp->h_addr, sizeof(__ourip));
- }
- if (!ntohs(bindaddr.sin_port)) {
- bindaddr.sin_port = ntohs(DEFAULT_SKINNY_PORT);
- }
- bindaddr.sin_family = AF_INET;
-
- /* load the device sections */
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (!strcasecmp(cat, "general")) {
- /* Nothing to do */
-#if 0
- } else if (!strncasecmp(cat, "paging-", 7)) {
- p = build_paging_device(cat, ast_variable_browse(cfg, cat));
- if (p) {
- }
-#endif
- } else {
- d = build_device(cat, ast_variable_browse(cfg, cat));
- if (d) {
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Added device '%s'\n", d->name);
- }
- ast_mutex_lock(&devicelock);
- d->next = devices;
- devices = d;
- ast_mutex_unlock(&devicelock);
- }
- }
- cat = ast_category_browse(cfg, cat);
- }
- ast_mutex_lock(&netlock);
- if ((skinnysock > -1) && (ntohs(bindaddr.sin_port) != oldport)) {
- close(skinnysock);
- skinnysock = -1;
- }
- if (skinnysock < 0) {
- skinnysock = socket(AF_INET, SOCK_STREAM, 0);
- if(setsockopt(skinnysock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
- ast_log(LOG_ERROR, "Set Socket Options failed: errno %d, %s", errno, strerror(errno));
- ast_config_destroy(cfg);
- return 0;
- }
- if (skinnysock < 0) {
- ast_log(LOG_WARNING, "Unable to create Skinny socket: %s\n", strerror(errno));
- } else {
- if (bind(skinnysock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) {
- ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port),
- strerror(errno));
- close(skinnysock);
- skinnysock = -1;
- ast_config_destroy(cfg);
- return 0;
- }
- if (listen(skinnysock,DEFAULT_SKINNY_BACKLOG)) {
- ast_log(LOG_WARNING, "Failed to start listening to %s:%d: %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port),
- strerror(errno));
- close(skinnysock);
- skinnysock = -1;
- ast_config_destroy(cfg);
- return 0;
- }
- if (option_verbose > 1) {
- ast_verbose(VERBOSE_PREFIX_2 "Skinny listening on %s:%d\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port));
- }
- ast_pthread_create(&accept_t,NULL, accept_thread, NULL);
- }
- }
- ast_mutex_unlock(&netlock);
- ast_config_destroy(cfg);
- return 0;
-}
-
-void delete_devices(void)
-{
- struct skinny_device *d, *dlast;
- struct skinny_line *l, *llast;
- struct skinny_subchannel *sub, *slast;
-
- ast_mutex_lock(&devicelock);
-
- /* Delete all devices */
- for (d=devices;d;) {
- /* Delete all lines for this device */
- for (l=d->lines;l;) {
- /* Delete all subchannels for this line */
- for (sub=l->sub;sub;) {
- slast = sub;
- sub = sub->next;
- ast_mutex_destroy(&slast->lock);
- free(slast);
- }
- llast = l;
- l = l->next;
- ast_mutex_destroy(&llast->lock);
- free(llast);
- }
- dlast = d;
- d = d->next;
- free(dlast);
- }
- devices=NULL;
- ast_mutex_unlock(&devicelock);
-}
-
-int reload(void)
-{
- delete_devices();
- reload_config();
- restart_monitor();
- return 0;
-}
-
-
-int load_module()
-{
- int res = 0;
-
- for (; res < (sizeof(soft_key_template_default) / sizeof(soft_key_template_default[0])); res++) {
- soft_key_template_default[res].softKeyEvent = htolel(soft_key_template_default[res].softKeyEvent);
- }
- /* load and parse config */
- res = reload_config();
-
- ast_rtp_proto_register(&skinny_rtp);
- ast_cli_register(&cli_show_devices);
- ast_cli_register(&cli_show_lines);
- ast_cli_register(&cli_debug);
- ast_cli_register(&cli_no_debug);
- sched = sched_context_create();
- if (!sched) {
- ast_log(LOG_WARNING, "Unable to create schedule context\n");
- }
- io = io_context_create();
- if (!io) {
- ast_log(LOG_WARNING, "Unable to create I/O context\n");
- }
- /* And start the monitor for the first time */
- restart_monitor();
-
- /* Announce our presence to Asterisk */
- if (!res) {
- /* Make sure we can register our skinny channel type */
- if (ast_channel_register(&skinny_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- return -1;
- }
- }
- return res;
-}
-
-int unload_module()
-{
-#if 0
- struct skinny_session *session, s;
- struct skinny_subchannel *sub;
- struct skinny_line *line = session;
-
- /* close all IP connections */
- if (!ast_mutex_lock(&devicelock)) {
- /* Terminate tcp listener thread */
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
- pthread_cancel(monitor_thread);
- pthread_kill(monitor_thread, SIGURG);
- pthread_join(monitor_thread, NULL);
- }
- monitor_thread = AST_PTHREADT_STOP;
- ast_mutex_unlock(&monlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- if (!ast_mutex_lock(&iflock)) {
- /* Destroy all the interfaces and free their memory */
- p = iflist;
- while(p) {
- pl = p;
- p = p->next;
- /* Free associated memory */
- ast_mutex_destroy(&pl->lock);
- free(pl);
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-
- ast_rtp_proto_register(&skinny_rtp);
- ast_channel_unregister(&skinny_tech);
- ast_cli_register(&cli_show_devices);
- ast_cli_register(&cli_show_lines);
- ast_cli_register(&cli_debug);
- ast_cli_register(&cli_no_debug);
-
- return 0;
-#endif
- return -1;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-char *description()
-{
- return (char *) desc;
-}
diff --git a/1.2-netsec/channels/chan_vpb.c b/1.2-netsec/channels/chan_vpb.c
deleted file mode 100644
index f735e3d16..000000000
--- a/1.2-netsec/channels/chan_vpb.c
+++ /dev/null
@@ -1,3051 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2003, Paul Bagyenda
- * Paul Bagyenda <bagyenda@dsmagic.com>
- * Copyright (C) 2004 - 2005, Ben Kramer
- * Ben Kramer <ben@voicetronix.com.au>
- *
- * Daniel Bichara <daniel@bichara.com.br> - Brazilian CallerID detection (c)2004
- *
- * Welber Silveira - welberms@magiclink.com.br - (c)2004
- * Copying CLID string to propper structure after detection
- *
- * 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 VoiceTronix Interface driver
- *
- * \ingroup channel_drivers
- */
-
-
-extern "C" {
-
-#include <stdio.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/callerid.h"
-#include "asterisk/dsp.h"
-#include "asterisk/features.h"
-}
-
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <arpa/inet.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <ctype.h>
-
-#include <vpbapi.h>
-#include <assert.h>
-
-#ifdef pthread_create
-#undef pthread_create
-#endif
-
-#define DEFAULT_GAIN 0
-#define DEFAULT_ECHO_CANCEL 1
-
-#define VPB_SAMPLES 160
-#define VPB_MAX_BUF VPB_SAMPLES*4 + AST_FRIENDLY_OFFSET
-
-#define VPB_NULL_EVENT 200
-
-#define VPB_WAIT_TIMEOUT 4000
-
-#define MAX_VPB_GAIN 12.0
-#define MIN_VPB_GAIN -12.0
-
-#define DTMF_CALLERID
-#define DTMF_CID_START 'D'
-#define DTMF_CID_STOP 'C'
-
-/**/
-#if defined(__cplusplus) || defined(c_plusplus)
- extern "C" {
-#endif
-/**/
-
-static const char desc[] = "VoiceTronix V6PCI/V12PCI/V4PCI API Support";
-static const char type[] = "vpb";
-static const char tdesc[] = "Standard VoiceTronix API Driver";
-static const char config[] = "vpb.conf";
-
-/* Default context for dialtone mode */
-static char context[AST_MAX_EXTENSION] = "default";
-
-/* Default language */
-static char language[MAX_LANGUAGE] = "";
-static int usecnt =0;
-
-static int gruntdetect_timeout = 3600000; /* Grunt detect timeout is 1hr. */
-
-static const int prefformat = AST_FORMAT_SLINEAR;
-
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-/* Protect the interface list (of vpb_pvt's) */
-AST_MUTEX_DEFINE_STATIC(iflock);
-
-/* Protect the monitoring thread, so only one process can kill or start it, and not
- when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(monlock);
-
-/* This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
-static pthread_t monitor_thread;
-
-static int mthreadactive = -1; /* Flag for monitoring monitorthread.*/
-
-
-static int restart_monitor(void);
-
-/* The private structures of the VPB channels are
- linked for selecting outgoing channels */
-
-#define MODE_DIALTONE 1
-#define MODE_IMMEDIATE 2
-#define MODE_FXO 3
-
-/* Pick a country or add your own! */
-/* These are the tones that are played to the user */
-#define TONES_AU
-/* #define TONES_USA */
-
-#ifdef TONES_AU
-static VPB_TONE Dialtone = {440, 440, 440, -10, -10, -10, 5000, 0 };
-static VPB_TONE Busytone = {470, 0, 0, -10, -100, -100, 5000, 0 };
-static VPB_TONE Ringbacktone = {400, 50, 440, -10, -10, -10, 1400, 800 };
-#endif
-#ifdef TONES_USA
-static VPB_TONE Dialtone = {350, 440, 0, -16, -16, -100, 10000, 0};
-static VPB_TONE Busytone = {480, 620, 0, -10, -10, -100, 500, 500};
-static VPB_TONE Ringbacktone = {440, 480, 0, -20, -20, -100, 2000, 4000};
-#endif
-
-/* grunt tone defn's */
-static VPB_DETECT toned_grunt = { 3, VPB_GRUNT, 1, 2000, 3000, 0, 0, -40, 0, 0, 0, 40, { { VPB_DELAY, 1000, 0, 0 }, { VPB_RISING, 0, 40, 0 }, { 0, 100, 0, 0 } } };
-static VPB_DETECT toned_ungrunt = { 2, VPB_GRUNT, 1, 2000, 1, 0, 0, -40, 0, 0, 30, 40, { { 0, 0, 0, 0 } } };
-
-/* Use loop polarity detection for CID */
-static int UsePolarityCID=0;
-
-/* Use loop drop detection */
-static int UseLoopDrop=1;
-
-/* To use or not to use Native bridging */
-static int UseNativeBridge=1;
-
-/* Use Asterisk Indication or VPB */
-static int use_ast_ind=0;
-
-/* Use Asterisk DTMF detection or VPB */
-static int use_ast_dtmfdet=0;
-
-static int relaxdtmf=0;
-
-/* Use Asterisk DTMF play back or VPB */
-static int use_ast_dtmf=0;
-
-/* Break for DTMF on native bridge ? */
-static int break_for_dtmf=1;
-
-/* Set EC suppression threshold */
-static int ec_supp_threshold=-1;
-
-/* Inter Digit Delay for collecting DTMF's */
-static int dtmf_idd = 3000;
-
-#define TIMER_PERIOD_RINGBACK 2000
-#define TIMER_PERIOD_BUSY 700
-#define TIMER_PERIOD_RING 4000
-static int timer_period_ring = TIMER_PERIOD_RING;
-
-#define VPB_EVENTS_ALL (VPB_MRING|VPB_MDIGIT|VPB_MDTMF|VPB_MTONEDETECT|VPB_MTIMEREXP|VPB_MPLAY_UNDERFLOW \
- |VPB_MRECORD_OVERFLOW|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
- |VPB_MRING_OFF|VPB_MDROP|VPB_MSTATION_FLASH)
-#define VPB_EVENTS_NODROP (VPB_MRING|VPB_MDIGIT|VPB_MDTMF|VPB_MTONEDETECT|VPB_MTIMEREXP|VPB_MPLAY_UNDERFLOW \
- |VPB_MRECORD_OVERFLOW|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
- |VPB_MRING_OFF|VPB_MSTATION_FLASH)
-#define VPB_EVENTS_NODTMF (VPB_MRING|VPB_MDIGIT|VPB_MTONEDETECT|VPB_MTIMEREXP|VPB_MPLAY_UNDERFLOW \
- |VPB_MRECORD_OVERFLOW|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
- |VPB_MRING_OFF|VPB_MDROP|VPB_MSTATION_FLASH)
-#define VPB_EVENTS_STAT (VPB_MRING|VPB_MDIGIT|VPB_MDTMF|VPB_MTONEDETECT|VPB_MTIMEREXP|VPB_MPLAY_UNDERFLOW \
- |VPB_MRECORD_OVERFLOW|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
- |VPB_MRING_OFF|VPB_MSTATION_FLASH)
-
-
-/* Dialing parameters for Australia */
-/* #define DIAL_WITH_CALL_PROGRESS */
-VPB_TONE_MAP DialToneMap[] = { { VPB_BUSY_AUST, VPB_CALL_DISCONNECT, 0 },
- { VPB_DIAL, VPB_CALL_DIALTONE, 0 },
- { VPB_RINGBACK_308, VPB_CALL_RINGBACK, 0 },
- { VPB_BUSY_AUST, VPB_CALL_BUSY, 0 },
- { VPB_GRUNT, VPB_CALL_GRUNT, 0 },
- { 0, 0, 1 } };
-#define VPB_DIALTONE_WAIT 2000 /* Wait up to 2s for a dialtone */
-#define VPB_RINGWAIT 4000 /* Wait up to 4s for ring tone after dialing */
-#define VPB_CONNECTED_WAIT 4000 /* If no ring tone detected for 4s then consider call connected */
-#define TIMER_PERIOD_NOANSWER 120000 /* Let it ring for 120s before deciding theres noone there */
-
-#define MAX_BRIDGES_V4PCI 2
-#define MAX_BRIDGES_V12PCI 128
-
-/* port states */
-#define VPB_STATE_ONHOOK 0
-#define VPB_STATE_OFFHOOK 1
-#define VPB_STATE_DIALLING 2
-#define VPB_STATE_JOINED 3
-#define VPB_STATE_GETDTMF 4
-#define VPB_STATE_PLAYDIAL 5
-#define VPB_STATE_PLAYBUSY 6
-#define VPB_STATE_PLAYRING 7
-
-#define VPB_GOT_RXHWG 1
-#define VPB_GOT_TXHWG 2
-#define VPB_GOT_RXSWG 4
-#define VPB_GOT_TXSWG 8
-
-typedef struct {
- int inuse;
- struct ast_channel *c0, *c1, **rc;
- struct ast_frame **fo;
- int flags;
- ast_mutex_t lock;
- ast_cond_t cond;
- int endbridge;
-} vpb_bridge_t;
-
-static vpb_bridge_t * bridges;
-static int max_bridges = MAX_BRIDGES_V4PCI;
-
-AST_MUTEX_DEFINE_STATIC(bridge_lock);
-
-typedef enum {
- vpb_model_unknown = 0,
- vpb_model_v4pci,
- vpb_model_v12pci
-} vpb_model_t;
-
-static struct vpb_pvt {
-
- ast_mutex_t owner_lock; /* Protect blocks that expect ownership to remain the same */
- struct ast_channel *owner; /* Channel who owns us, possibly NULL */
-
- int golock; /* Got owner lock ? */
-
- int mode; /* fxo/imediate/dialtone*/
- int handle; /* Handle for vpb interface */
-
- int state; /* used to keep port state (internal to driver) */
-
- int group; /* Which group this port belongs to */
- ast_group_t callgroup; /* Call group */
- ast_group_t pickupgroup; /* Pickup group */
-
-
- char dev[256]; /* Device name, eg vpb/1-1 */
- vpb_model_t vpb_model; /* card model */
-
- struct ast_frame f, fr; /* Asterisk frame interface */
- char buf[VPB_MAX_BUF]; /* Static buffer for reading frames */
-
- int dialtone; /* NOT USED */
- float txgain, rxgain; /* Hardware gain control */
- float txswgain, rxswgain; /* Software gain control */
-
- int wantdtmf; /* Waiting for DTMF. */
- char context[AST_MAX_EXTENSION]; /* The context for this channel */
-
- char ext[AST_MAX_EXTENSION]; /* DTMF buffer for the ext[ens] */
- char language[MAX_LANGUAGE]; /* language being used */
- char callerid[AST_MAX_EXTENSION]; /* CallerId used for directly connected phone */
- int callerid_type; /* Caller ID type: 0=>none 1=>vpb 2=>AstV23 3=>AstBell */
- char cid_num[AST_MAX_EXTENSION];
- char cid_name[AST_MAX_EXTENSION];
-
- int dtmf_caller_pos; /* DTMF CallerID detection (Brazil)*/
-
- int lastoutput; /* Holds the last Audio format output'ed */
- int lastinput; /* Holds the last Audio format input'ed */
- int last_ignore_dtmf;
-
- void *busy_timer; /* Void pointer for busy vpb_timer */
- int busy_timer_id; /* unique timer ID for busy timer */
-
- void *ringback_timer; /* Void pointer for ringback vpb_timer */
- int ringback_timer_id; /* unique timer ID for ringback timer */
-
- void *ring_timer; /* Void pointer for ring vpb_timer */
- int ring_timer_id; /* unique timer ID for ring timer */
-
- void *dtmfidd_timer; /* Void pointer for DTMF IDD vpb_timer */
- int dtmfidd_timer_id; /* unique timer ID for DTMF IDD timer */
-
- struct ast_dsp *vad; /* AST Voice Activation Detection dsp */
-
- struct timeval lastgrunt; /* time stamp of last grunt event */
-
- ast_mutex_t lock; /* This one just protects bridge ptr below */
- vpb_bridge_t *bridge;
-
- int stopreads; /* Stop reading...*/
- int read_state; /* Read state */
- int chuck_count; /* a count of packets weve chucked away!*/
- pthread_t readthread; /* For monitoring read channel. One per owned channel. */
-
- ast_mutex_t record_lock; /* This one prevents reentering a record_buf block */
- ast_mutex_t play_lock; /* This one prevents reentering a play_buf block */
- int play_buf_time; /* How long the last play_buf took */
- struct timeval lastplay; /* Last play time */
-
- ast_mutex_t play_dtmf_lock;
- char play_dtmf[16];
-
- int faxhandled; /* has a fax tone been handled ? */
-
- struct vpb_pvt *next; /* Next channel in list */
-
-} *iflist = NULL;
-
-static struct ast_channel *vpb_new(struct vpb_pvt *i, int state, char *context);
-static void *do_chanreads(void *pvt);
-
-static struct ast_channel *vpb_request(const char *type, int format, void *data, int *cause);
-static int vpb_digit(struct ast_channel *ast, char digit);
-static int vpb_call(struct ast_channel *ast, char *dest, int timeout);
-static int vpb_hangup(struct ast_channel *ast);
-static int vpb_answer(struct ast_channel *ast);
-static struct ast_frame *vpb_read(struct ast_channel *ast);
-static int vpb_write(struct ast_channel *ast, struct ast_frame *frame);
-static enum ast_bridge_result vpb_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
-static int vpb_indicate(struct ast_channel *ast, int condition);
-static int vpb_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-
-static struct ast_channel_tech vpb_tech = {
- type: type,
- description: tdesc,
- capabilities: AST_FORMAT_SLINEAR,
- properties: NULL,
- requester: vpb_request,
- devicestate: NULL,
- send_digit: vpb_digit,
- call: vpb_call,
- hangup: vpb_hangup,
- answer: vpb_answer,
- read: vpb_read,
- write: vpb_write,
- send_text: NULL,
- send_image: NULL,
- send_html: NULL,
- exception: NULL,
- bridge: vpb_bridge,
- indicate: vpb_indicate,
- fixup: vpb_fixup,
- setoption: NULL,
- queryoption: NULL,
- transfer: NULL,
- write_video: NULL,
- bridged_channel: NULL
-};
-
-static struct ast_channel_tech vpb_tech_indicate = {
- type: type,
- description: tdesc,
- capabilities: AST_FORMAT_SLINEAR,
- properties: NULL,
- requester: vpb_request,
- devicestate: NULL,
- send_digit: vpb_digit,
- call: vpb_call,
- hangup: vpb_hangup,
- answer: vpb_answer,
- read: vpb_read,
- write: vpb_write,
- send_text: NULL,
- send_image: NULL,
- send_html: NULL,
- exception: NULL,
- bridge: vpb_bridge,
- indicate: NULL,
- fixup: vpb_fixup,
- setoption: NULL,
- queryoption: NULL,
- transfer: NULL,
- write_video: NULL,
- bridged_channel: NULL
-};
-
-/* Can't get vpb_bridge() working on v4pci without either a horrible
-* high pitched feedback noise or bad hiss noise depending on gain settings
-* Get asterisk to do the bridging
-*/
-#define BAD_V4PCI_BRIDGE
-
-/* This one enables a half duplex bridge which may be required to prevent high pitched
- * feedback when getting asterisk to do the bridging and when using certain gain settings.
- */
-/* #define HALF_DUPLEX_BRIDGE */
-
-/* This is the Native bridge code, which Asterisk will try before using its own bridging code */
-static enum ast_bridge_result vpb_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms)
-{
- struct vpb_pvt *p0 = (struct vpb_pvt *)c0->tech_pvt;
- struct vpb_pvt *p1 = (struct vpb_pvt *)c1->tech_pvt;
- int i;
- int res;
- struct ast_channel *cs[3];
- struct ast_channel *who;
- struct ast_frame *f;
-
- cs[0] = c0;
- cs[1] = c1;
-
- #ifdef BAD_V4PCI_BRIDGE
- if(p0->vpb_model==vpb_model_v4pci)
- return AST_BRIDGE_FAILED_NOWARN;
- #endif
- if ( UseNativeBridge != 1){
- return AST_BRIDGE_FAILED_NOWARN;
- }
-
-/*
- ast_mutex_lock(&p0->lock);
- ast_mutex_lock(&p1->lock);
-*/
-
- /* Bridge channels, check if we can. I believe we always can, so find a slot.*/
-
- ast_mutex_lock(&bridge_lock); {
- for (i = 0; i < max_bridges; i++)
- if (!bridges[i].inuse)
- break;
- if (i < max_bridges) {
- bridges[i].inuse = 1;
- bridges[i].endbridge = 0;
- bridges[i].flags = flags;
- bridges[i].rc = rc;
- bridges[i].fo = fo;
- bridges[i].c0 = c0;
- bridges[i].c1 = c1;
- }
- } ast_mutex_unlock(&bridge_lock);
-
- if (i == max_bridges) {
- ast_log(LOG_WARNING, "%s: vpb_bridge: Failed to bridge %s and %s!\n", p0->dev, c0->name, c1->name);
- ast_mutex_unlock(&p0->lock);
- ast_mutex_unlock(&p1->lock);
- return AST_BRIDGE_FAILED_NOWARN;
- } else {
- /* Set bridge pointers. You don't want to take these locks while holding bridge lock.*/
- ast_mutex_lock(&p0->lock); {
- p0->bridge = &bridges[i];
- } ast_mutex_unlock(&p0->lock);
-
- ast_mutex_lock(&p1->lock); {
- p1->bridge = &bridges[i];
- } ast_mutex_unlock(&p1->lock);
-
- if (option_verbose>1)
- ast_verbose(VERBOSE_PREFIX_2 "%s: vpb_bridge: Bridging call entered with [%s, %s]\n",p0->dev, c0->name, c1->name);
- }
-
- #ifdef HALF_DUPLEX_BRIDGE
-
- if (option_verbose>1)
- ast_verbose(VERBOSE_PREFIX_2 "%s: vpb_bridge: Starting half-duplex bridge [%s, %s]\n",p0->dev, c0->name, c1->name);
-
- int dir = 0;
-
- memset(p0->buf, 0, sizeof p0->buf);
- memset(p1->buf, 0, sizeof p1->buf);
-
- vpb_record_buf_start(p0->handle, VPB_ALAW);
- vpb_record_buf_start(p1->handle, VPB_ALAW);
-
- vpb_play_buf_start(p0->handle, VPB_ALAW);
- vpb_play_buf_start(p1->handle, VPB_ALAW);
-
- while( !bridges[i].endbridge ) {
- struct vpb_pvt *from, *to;
- if(++dir%2) {
- from = p0;
- to = p1;
- } else {
- from = p1;
- to = p0;
- }
- vpb_record_buf_sync(from->handle, from->buf, VPB_SAMPLES);
- vpb_play_buf_sync(to->handle, from->buf, VPB_SAMPLES);
- }
-
- vpb_record_buf_finish(p0->handle);
- vpb_record_buf_finish(p1->handle);
-
- vpb_play_buf_finish(p0->handle);
- vpb_play_buf_finish(p1->handle);
-
- if (option_verbose>1)
- ast_verbose(VERBOSE_PREFIX_2 "%s: vpb_bridge: Finished half-duplex bridge [%s, %s]\n",p0->dev, c0->name, c1->name);
-
- res = VPB_OK;
-
- #else
-
- res = vpb_bridge(p0->handle, p1->handle, VPB_BRIDGE_ON, i+1 /* resource 1 & 2 only for V4PCI*/ );
- if (res == VPB_OK) {
- /* pthread_cond_wait(&bridges[i].cond, &bridges[i].lock);*/ /* Wait for condition signal. */
- while( !bridges[i].endbridge ) {
- /* Are we really ment to be doing nothing ?!?! */
- who = ast_waitfor_n(cs, 2, &timeoutms);
- if (!who) {
- if (!timeoutms) {
- res = AST_BRIDGE_RETRY;
- break;
- }
- ast_log(LOG_DEBUG, "%s: vpb_bridge: Empty frame read...\n",p0->dev);
- /* check for hangup / whentohangup */
- if (ast_check_hangup(c0) || ast_check_hangup(c1))
- break;
- continue;
- }
- f = ast_read(who);
- if (!f || ((f->frametype == AST_FRAME_DTMF) &&
- (((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) ||
- ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1))))) {
- *fo = f;
- *rc = who;
- ast_log(LOG_DEBUG, "%s: vpb_bridge: Got a [%s]\n",p0->dev, f ? "digit" : "hangup");
-/*
- if ((c0->tech_pvt == pvt0) && (!c0->_softhangup)) {
- if (pr0->set_rtp_peer(c0, NULL, NULL, 0))
- ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name);
- }
- if ((c1->tech_pvt == pvt1) && (!c1->_softhangup)) {
- if (pr1->set_rtp_peer(c1, NULL, NULL, 0))
- ast_log(LOG_WARNING, "Channel '%s' failed to revert back\n", c1->name);
- }
-*/
- /* That's all we needed */
- /*return 0; */
- /* Check if we need to break */
- if (break_for_dtmf){
- break;
- }
- else if ((f->frametype == AST_FRAME_DTMF) && ((f->subclass == '#')||(f->subclass == '*'))){
- break;
- }
- } else {
- if ((f->frametype == AST_FRAME_DTMF) ||
- (f->frametype == AST_FRAME_VOICE) ||
- (f->frametype == AST_FRAME_VIDEO))
- {
- /* Forward voice or DTMF frames if they happen upon us */
- /* Actually I dont think we want to forward on any frames!
- if (who == c0) {
- ast_write(c1, f);
- } else if (who == c1) {
- ast_write(c0, f);
- }
- */
- }
- ast_frfree(f);
- }
- /* Swap priority not that it's a big deal at this point */
- cs[2] = cs[0];
- cs[0] = cs[1];
- cs[1] = cs[2];
- };
- vpb_bridge(p0->handle, p1->handle, VPB_BRIDGE_OFF, i+1 /* resource 1 & 2 only for V4PCI*/ );
- }
-
- #endif
-
- ast_mutex_lock(&bridge_lock); {
- bridges[i].inuse = 0;
- } ast_mutex_unlock(&bridge_lock);
-
- p0->bridge = NULL;
- p1->bridge = NULL;
-
-
- if (option_verbose>1)
- ast_verbose(VERBOSE_PREFIX_2 "Bridging call done with [%s, %s] => %d\n", c0->name, c1->name, res);
-
-/*
- ast_mutex_unlock(&p0->lock);
- ast_mutex_unlock(&p1->lock);
-*/
- return (res==VPB_OK) ? AST_BRIDGE_COMPLETE : AST_BRIDGE_FAILED;
-}
-
-/* Caller ID can be located in different positions between the rings depending on your Telco
- * Australian (Telstra) callerid starts 700ms after 1st ring and finishes 1.5s after first ring
- * Use ANALYSE_CID to record rings and determine location of callerid
- */
-/* #define ANALYSE_CID */
-#define RING_SKIP 300
-#define CID_MSECS 2000
-
-static void get_callerid(struct vpb_pvt *p)
-{
- short buf[CID_MSECS*8]; /* 8kHz sampling rate */
- struct timeval cid_record_time;
- int rc;
- struct ast_channel *owner = p->owner;
-/*
- char callerid[AST_MAX_EXTENSION] = "";
-*/
-#ifdef ANALYSE_CID
- void * ws;
- char * file="cidsams.wav";
-#endif
-
-
- if( ast_mutex_trylock(&p->record_lock) == 0 ) {
-
- cid_record_time = ast_tvnow();
- if (option_verbose>3)
- ast_verbose(VERBOSE_PREFIX_4 "CID record - start\n");
-
- /* Skip any trailing ringtone */
- if (UsePolarityCID != 1){
- vpb_sleep(RING_SKIP);
- }
-
- if (option_verbose>3)
- ast_verbose(VERBOSE_PREFIX_4 "CID record - skipped %ldms trailing ring\n",
- ast_tvdiff_ms(ast_tvnow(), cid_record_time));
- cid_record_time = ast_tvnow();
-
- /* Record bit between the rings which contains the callerid */
- vpb_record_buf_start(p->handle, VPB_LINEAR);
- rc = vpb_record_buf_sync(p->handle, (char*)buf, sizeof(buf));
- vpb_record_buf_finish(p->handle);
-#ifdef ANALYSE_CID
- vpb_wave_open_write(&ws, file, VPB_LINEAR);
- vpb_wave_write(ws,(char*)buf,sizeof(buf));
- vpb_wave_close_write(ws);
-#endif
-
- if (option_verbose>3)
- ast_verbose(VERBOSE_PREFIX_4 "CID record - recorded %ldms between rings\n",
- ast_tvdiff_ms(ast_tvnow(), cid_record_time));
-
- ast_mutex_unlock(&p->record_lock);
-
- if( rc != VPB_OK ) {
- ast_log(LOG_ERROR, "Failed to record caller id sample on %s\n", p->dev );
- return;
- }
-
- VPB_CID *cli_struct = new VPB_CID;
- cli_struct->ra_cldn[0]=0;
- cli_struct->ra_cn[0]=0;
- /* This decodes FSK 1200baud type callerid */
- if ((rc=vpb_cid_decode2(cli_struct, buf, CID_MSECS*8)) == VPB_OK ) {
- /*
- if (owner->cid.cid_num)
- free(owner->cid.cid_num);
- owner->cid.cid_num=NULL;
- if (owner->cid.cid_name)
- free(owner->cid.cid_name);
- owner->cid.cid_name=NULL;
- */
-
- if (cli_struct->ra_cldn[0]=='\0'){
- /*
- owner->cid.cid_num = strdup(cli_struct->cldn);
- owner->cid.cid_name = strdup(cli_struct->cn);
- */
- if (owner){
- ast_set_callerid(owner, cli_struct->cldn, cli_struct->cn, cli_struct->cldn);
- } else {
- strcpy(p->cid_num, cli_struct->cldn);
- strcpy(p->cid_name, cli_struct->cn);
-
- }
- if (option_verbose>3)
- ast_verbose(VERBOSE_PREFIX_4 "CID record - got [%s] [%s]\n",owner->cid.cid_num,owner->cid.cid_name );
- snprintf(p->callerid,sizeof(p->callerid)-1,"%s %s",cli_struct->cldn,cli_struct->cn);
- }
- else {
- ast_log(LOG_ERROR,"CID record - No caller id avalable on %s \n", p->dev);
- }
-
- } else {
- ast_log(LOG_ERROR, "CID record - Failed to decode caller id on %s - %s\n", p->dev, vpb_strerror(rc) );
- strncpy(p->callerid,"unknown", sizeof(p->callerid) - 1);
- }
- delete cli_struct;
-
- } else
- ast_log(LOG_ERROR, "CID record - Failed to set record mode for caller id on %s\n", p->dev );
-}
-
-static void get_callerid_ast(struct vpb_pvt *p)
-{
- struct callerid_state *cs;
- char buf[1024];
- char *name=NULL, *number=NULL;
- int flags;
- int rc=0,vrc;
- int sam_count=0;
- struct ast_channel *owner = p->owner;
- int which_cid;
-/*
- float old_gain;
-*/
-#ifdef ANALYSE_CID
- void * ws;
- char * file="cidsams.wav";
-#endif
-
- if(p->callerid_type == 1) {
- if (option_verbose>3) ast_verbose(VERBOSE_PREFIX_4 "Collected caller ID already\n");
- return;
- }
- else if(p->callerid_type == 2 ) {
- which_cid=CID_SIG_V23;
- if (option_verbose>3) ast_verbose(VERBOSE_PREFIX_4 "Collecting Caller ID v23...\n");
- }
- else if(p->callerid_type == 3) {
- which_cid=CID_SIG_BELL;
- if (option_verbose>3) ast_verbose(VERBOSE_PREFIX_4 "Collecting Caller ID bell...\n");
- }
- else {
- if (option_verbose>3)
- ast_verbose(VERBOSE_PREFIX_4 "Caller ID disabled\n");
- return;
- }
-/* vpb_sleep(RING_SKIP); */
-/* vpb_record_get_gain(p->handle, &old_gain); */
- cs = callerid_new(which_cid);
- if (cs){
-#ifdef ANALYSE_CID
- vpb_wave_open_write(&ws, file, VPB_MULAW);
- vpb_record_set_gain(p->handle, 3.0);
- vpb_record_set_hw_gain(p->handle,12.0);
-#endif
- vpb_record_buf_start(p->handle, VPB_MULAW);
- while((rc == 0)&&(sam_count<8000*3)){
- vrc = vpb_record_buf_sync(p->handle, (char*)buf, sizeof(buf));
- if (vrc != VPB_OK)
- ast_log(LOG_ERROR, "%s: Caller ID couldnt read audio buffer!\n",p->dev);
- rc = callerid_feed(cs,(unsigned char *)buf,sizeof(buf),AST_FORMAT_ULAW);
-#ifdef ANALYSE_CID
- vpb_wave_write(ws,(char*)buf,sizeof(buf));
-#endif
- sam_count+=sizeof(buf);
- if (option_verbose>3) ast_verbose(VERBOSE_PREFIX_4 "Collecting Caller ID samples [%d][%d]...\n",sam_count,rc);
- }
- vpb_record_buf_finish(p->handle);
-#ifdef ANALYSE_CID
- vpb_wave_close_write(ws);
-#endif
- if (rc == 1){
- callerid_get(cs, &name, &number, &flags);
- if (option_verbose>0)
- ast_verbose(VERBOSE_PREFIX_1 "%s: Caller ID name [%s] number [%s] flags [%d]\n",p->dev,name, number,flags);
- }
- else {
- ast_log(LOG_ERROR, "%s: Failed to decode Caller ID \n", p->dev );
- }
-/* vpb_record_set_gain(p->handle, old_gain); */
-/* vpb_record_set_hw_gain(p->handle,6.0); */
- }
- else {
- ast_log(LOG_ERROR, "%s: Failed to create Caller ID struct\n", p->dev );
- }
- if (owner->cid.cid_num) {
- free(owner->cid.cid_num);
- owner->cid.cid_num = NULL;
- }
- if (owner->cid.cid_name) {
- free(owner->cid.cid_name);
- owner->cid.cid_name = NULL;
- }
- if (number)
- ast_shrink_phone_number(number);
- if (!ast_strlen_zero(number)) {
- owner->cid.cid_num = strdup(number);
- owner->cid.cid_ani = strdup(number);
- if (!ast_strlen_zero(name)){
- owner->cid.cid_name = strdup(name);
- snprintf(p->callerid,(sizeof(p->callerid)-1),"%s %s",number,name);
- }
- else {
- snprintf(p->callerid,(sizeof(p->callerid)-1),"%s",number);
- }
- }
-
- if (cs)
- callerid_free(cs);
-}
-
-/* Terminate any tones we are presently playing */
-static void stoptone( int handle)
-{
- int ret;
- VPB_EVENT je;
- while(vpb_playtone_state(handle)!=VPB_OK){
- vpb_tone_terminate(handle);
- ret = vpb_get_event_ch_async(handle,&je);
- if ((ret == VPB_OK)&&(je.type != VPB_DIALEND)){
- if (option_verbose > 3){
- ast_verbose(VERBOSE_PREFIX_4 "Stop tone collected a wrong event!![%d]\n",je.type);
- }
-/* vpb_put_event(&je); */
- }
- vpb_sleep(10);
- }
-}
-
-/* Safe vpb_playtone_async */
-static int playtone( int handle, VPB_TONE *tone)
-{
- int ret=VPB_OK;
- stoptone(handle);
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "[%02d]: Playing tone\n", handle);
- ret = vpb_playtone_async(handle, tone);
- return ret;
-}
-
-static inline int monitor_handle_owned(struct vpb_pvt *p, VPB_EVENT *e)
-{
- struct ast_frame f = {AST_FRAME_CONTROL}; /* default is control, Clear rest. */
- int endbridge = 0;
- int res=0;
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_owned: got event: [%d=>%d]\n", p->dev, e->type, e->data);
-
- f.src = (char *)type;
- switch (e->type) {
- case VPB_RING:
- if (p->mode == MODE_FXO) {
- f.subclass = AST_CONTROL_RING;
- vpb_timer_stop(p->ring_timer);
- vpb_timer_start(p->ring_timer);
- } else
- f.frametype = -1; /* ignore ring on station port. */
- break;
-
- case VPB_RING_OFF:
- f.frametype = -1;
- break;
-
- case VPB_TIMEREXP:
- if (e->data == p->busy_timer_id) {
- playtone(p->handle,&Busytone);
- p->state = VPB_STATE_PLAYBUSY;
- vpb_timer_stop(p->busy_timer);
- vpb_timer_start(p->busy_timer);
- f.frametype = -1;
- } else if (e->data == p->ringback_timer_id) {
- playtone(p->handle, &Ringbacktone);
- vpb_timer_stop(p->ringback_timer);
- vpb_timer_start(p->ringback_timer);
- f.frametype = -1;
- } else if (e->data == p->ring_timer_id) {
- /* We didnt get another ring in time! */
- if (p->owner->_state != AST_STATE_UP) {
- /* Assume caller has hung up */
- vpb_timer_stop(p->ring_timer);
- f.subclass = AST_CONTROL_HANGUP;
- } else {
- vpb_timer_stop(p->ring_timer);
- f.frametype = -1;
- }
-
- } else {
- f.frametype = -1; /* Ignore. */
- }
- break;
-
- case VPB_DTMF_DOWN:
- case VPB_DTMF:
- if (use_ast_dtmfdet){
- f.frametype = -1;
- } else if (p->owner->_state == AST_STATE_UP) {
- f.frametype = AST_FRAME_DTMF;
- f.subclass = e->data;
- } else
- f.frametype = -1;
- break;
-
- case VPB_TONEDETECT:
- if (e->data == VPB_BUSY || e->data == VPB_BUSY_308 || e->data == VPB_BUSY_AUST ) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_owned: got event: BUSY\n", p->dev);
- if (p->owner->_state == AST_STATE_UP) {
- f.subclass = AST_CONTROL_HANGUP;
- }
- else {
- f.subclass = AST_CONTROL_BUSY;
- }
- }
- else if (e->data == VPB_FAX){
- if (!p->faxhandled){
- if (strcmp(p->owner->exten, "fax")) {
- const char *target_context = ast_strlen_zero(p->owner->macrocontext) ? p->owner->context : p->owner->macrocontext;
-
- if (ast_exists_extension(p->owner, target_context, "fax", 1, p->owner->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", p->owner->name);
- /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
- pbx_builtin_setvar_helper(p->owner, "FAXEXTEN", p->owner->exten);
- if (ast_async_goto(p->owner, target_context, "fax", 1))
- ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", p->owner->name, target_context);
- } else
- ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
- } else
- ast_log(LOG_DEBUG, "Already in a fax extension, not redirecting\n");
- } else
- ast_log(LOG_DEBUG, "Fax already handled\n");
-
- }
- else if (e->data == VPB_GRUNT) {
- if ( ast_tvdiff_ms(ast_tvnow(), p->lastgrunt) > gruntdetect_timeout ) {
- /* Nothing heard on line for a very long time
- * Timeout connection */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "grunt timeout\n");
- ast_log(LOG_NOTICE,"%s: Line hangup due of lack of conversation\n",p->dev);
- f.subclass = AST_CONTROL_HANGUP;
- } else {
- p->lastgrunt = ast_tvnow();
- f.frametype = -1;
- }
- }
- else {
- f.frametype = -1;
- }
- break;
-
- case VPB_CALLEND:
- #ifdef DIAL_WITH_CALL_PROGRESS
- if (e->data == VPB_CALL_CONNECTED)
- f.subclass = AST_CONTROL_ANSWER;
- else if (e->data == VPB_CALL_NO_DIAL_TONE || e->data == VPB_CALL_NO_RING_BACK)
- f.subclass = AST_CONTROL_CONGESTION;
- else if (e->data == VPB_CALL_NO_ANSWER || e->data == VPB_CALL_BUSY)
- f.subclass = AST_CONTROL_BUSY;
- else if (e->data == VPB_CALL_DISCONNECTED)
- f.subclass = AST_CONTROL_HANGUP;
- #else
- ast_log(LOG_NOTICE,"%s: Got call progress callback but blind dialing \n", p->dev);
- f.frametype = -1;
- #endif
- break;
-
- case VPB_STATION_OFFHOOK:
- f.subclass = AST_CONTROL_ANSWER;
- break;
-
- case VPB_DROP:
- if ((p->mode == MODE_FXO)&&(UseLoopDrop)){ /* ignore loop drop on stations */
- if (p->owner->_state == AST_STATE_UP)
- f.subclass = AST_CONTROL_HANGUP;
- else
- f.frametype = -1;
- }
- break;
- case VPB_LOOP_ONHOOK:
- if (p->owner->_state == AST_STATE_UP)
- f.subclass = AST_CONTROL_HANGUP;
- else
- f.frametype = -1;
- break;
- case VPB_STATION_ONHOOK:
- f.subclass = AST_CONTROL_HANGUP;
- break;
-
- case VPB_STATION_FLASH:
- f.subclass = AST_CONTROL_FLASH;
- break;
-
- /* Called when dialing has finished and ringing starts
- * No indication that call has really been answered when using blind dialing
- */
- case VPB_DIALEND:
- if (p->state < 5){
- f.subclass = AST_CONTROL_ANSWER;
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "%s: Dialend\n", p->dev);
- } else {
- f.frametype = -1;
- }
- break;
-
- case VPB_PLAY_UNDERFLOW:
- f.frametype = -1;
- vpb_reset_play_fifo_alarm(p->handle);
- break;
-
- case VPB_RECORD_OVERFLOW:
- f.frametype = -1;
- vpb_reset_record_fifo_alarm(p->handle);
- break;
-
- default:
- f.frametype = -1;
- break;
- }
-
-/*
- if (option_verbose > 3) ast_verbose("%s: LOCKING in handle_owned [%d]\n", p->dev,res);
- res = ast_mutex_lock(&p->lock);
- if (option_verbose > 3) ast_verbose("%s: LOCKING count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
-*/
- {
- if (p->bridge) { /* Check what happened, see if we need to report it. */
- switch (f.frametype) {
- case AST_FRAME_DTMF:
- if ( !(p->bridge->c0 == p->owner &&
- (p->bridge->flags & AST_BRIDGE_DTMF_CHANNEL_0) ) &&
- !(p->bridge->c1 == p->owner &&
- (p->bridge->flags & AST_BRIDGE_DTMF_CHANNEL_1) ))
- /* Kill bridge, this is interesting. */
- endbridge = 1;
- break;
-
- case AST_FRAME_CONTROL:
- if (!(p->bridge->flags & AST_BRIDGE_IGNORE_SIGS))
- #if 0
- if (f.subclass == AST_CONTROL_BUSY ||
- f.subclass == AST_CONTROL_CONGESTION ||
- f.subclass == AST_CONTROL_HANGUP ||
- f.subclass == AST_CONTROL_FLASH)
- #endif
- endbridge = 1;
- break;
-
- default:
- break;
- }
- if (endbridge) {
- if (p->bridge->fo)
- *p->bridge->fo = ast_frisolate(&f);
- if (p->bridge->rc)
- *p->bridge->rc = p->owner;
-
- ast_mutex_lock(&p->bridge->lock); {
- p->bridge->endbridge = 1;
- ast_cond_signal(&p->bridge->cond);
- } ast_mutex_unlock(&p->bridge->lock);
- }
- }
- }
-
- if (endbridge){
- res = ast_mutex_unlock(&p->lock);
-/*
- if (option_verbose > 3) ast_verbose("%s: unLOCKING in handle_owned [%d]\n", p->dev,res);
-*/
- return 0;
- }
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_owned: Prepared frame type[%d]subclass[%d], bridge=%p owner=[%s]\n",
- p->dev, f.frametype, f.subclass, (void *)p->bridge, p->owner->name);
-
- /* Trylock used here to avoid deadlock that can occur if we
- * happen to be in here handling an event when hangup is called
- * Problem is that hangup holds p->owner->lock
- */
- if ((f.frametype >= 0)&& (f.frametype != AST_FRAME_NULL)&&(p->owner)) {
- if (ast_mutex_trylock(&p->owner->lock)==0) {
- ast_queue_frame(p->owner, &f);
- ast_mutex_unlock(&p->owner->lock);
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: handled_owned: Queued Frame to [%s]\n", p->dev,p->owner->name);
- } else {
- ast_verbose("%s: handled_owned: Missed event %d/%d \n",
- p->dev,f.frametype, f.subclass);
- }
- }
- res = ast_mutex_unlock(&p->lock);
-/*
- if (option_verbose > 3) ast_verbose("%s: unLOCKING in handle_owned [%d]\n", p->dev,res);
-*/
-
- return 0;
-}
-
-static inline int monitor_handle_notowned(struct vpb_pvt *p, VPB_EVENT *e)
-{
- char s[2] = {0};
- struct ast_channel *owner = p->owner;
- char cid_num[256];
- char cid_name[256];
-/*
- struct ast_channel *c;
-*/
-
- if (option_verbose > 3) {
- char str[VPB_MAX_STR];
- vpb_translate_event(e, str);
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: mode=%d, event[%d][%s]=[%d]\n",
- p->dev, p->mode, e->type,str, e->data);
- }
-
- switch(e->type) {
- case VPB_LOOP_ONHOOK:
- case VPB_LOOP_POLARITY:
- if (UsePolarityCID == 1){
- if (option_verbose>3)
- ast_verbose(VERBOSE_PREFIX_4 "Polarity reversal\n");
- if(p->callerid_type == 1) {
- if (option_verbose>3)
- ast_verbose(VERBOSE_PREFIX_4 "Using VPB Caller ID\n");
- get_callerid(p); /* UK CID before 1st ring*/
- }
-/* get_callerid_ast(p); /* Caller ID using the ast functions */
- }
- break;
- case VPB_RING:
- if (p->mode == MODE_FXO) /* FXO port ring, start * */ {
- vpb_new(p, AST_STATE_RING, p->context);
- if (UsePolarityCID != 1){
- if(p->callerid_type == 1) {
- if (option_verbose>3)
- ast_verbose(VERBOSE_PREFIX_4 "Using VPB Caller ID\n");
- get_callerid(p); /* Australian CID only between 1st and 2nd ring */
- }
- get_callerid_ast(p); /* Caller ID using the ast functions */
- }
- else {
- ast_log(LOG_ERROR, "Setting caller ID: %s %s\n",p->cid_num, p->cid_name);
- ast_set_callerid(p->owner, p->cid_num, p->cid_name, p->cid_num);
- p->cid_num[0]=0;
- p->cid_name[0]=0;
- }
-
- vpb_timer_stop(p->ring_timer);
- vpb_timer_start(p->ring_timer);
- }
- break;
-
- case VPB_RING_OFF:
- break;
-
- case VPB_STATION_OFFHOOK:
- if (p->mode == MODE_IMMEDIATE)
- vpb_new(p,AST_STATE_RING, p->context);
- else {
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: playing dialtone\n",p->dev);
- playtone(p->handle, &Dialtone);
- p->state=VPB_STATE_PLAYDIAL;
- p->wantdtmf = 1;
- p->ext[0] = 0; /* Just to be sure & paranoid.*/
- }
- break;
-
- case VPB_DIALEND:
- if (p->mode == MODE_DIALTONE){
- if (p->state == VPB_STATE_PLAYDIAL) {
- playtone(p->handle, &Dialtone);
- p->wantdtmf = 1;
- p->ext[0] = 0; /* Just to be sure & paranoid. */
- }
- /* These are not needed as they have timers to restart them
- else if (p->state == VPB_STATE_PLAYBUSY) {
- playtone(p->handle, &Busytone);
- p->wantdtmf = 1;
- p->ext[0] = 0;
- }
- else if (p->state == VPB_STATE_PLAYRING) {
- playtone(p->handle, &Ringbacktone);
- p->wantdtmf = 1;
- p->ext[0] = 0;
- }
- */
- } else {
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: Got a DIALEND when not really expected\n",p->dev);
- }
- break;
-
- case VPB_STATION_ONHOOK: /* clear ext */
- stoptone(p->handle);
- p->wantdtmf = 1 ;
- p->ext[0] = 0;
- p->state=VPB_STATE_ONHOOK;
- break;
- case VPB_TIMEREXP:
- if (e->data == p->dtmfidd_timer_id) {
- if (ast_exists_extension(NULL, p->context, p->ext, 1, p->callerid)){
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: DTMF IDD timer out, matching on [%s] in [%s]\n", p->dev,p->ext , p->context);
-
- vpb_new(p,AST_STATE_RING, p->context);
- }
- } else if (e->data == p->ring_timer_id) {
- /* We didnt get another ring in time! */
- if (p->owner){
- if (p->owner->_state != AST_STATE_UP) {
- /* Assume caller has hung up */
- vpb_timer_stop(p->ring_timer);
- }
- } else {
- /* No owner any more, Assume caller has hung up */
- vpb_timer_stop(p->ring_timer);
- }
- }
- break;
-
- case VPB_DTMF:
- if (p->state == VPB_STATE_ONHOOK){
- /* DTMF's being passed while on-hook maybe Caller ID */
- if ( p->mode == MODE_FXO ) {
- if ( e->data == DTMF_CID_START ) { /* CallerID Start signal */
- p->dtmf_caller_pos = 0; /* Leaves the first digit out */
- memset(p->callerid,0,AST_MAX_EXTENSION);
- }
- else if ( e->data == DTMF_CID_STOP ) { /* CallerID End signal */
- p->callerid[p->dtmf_caller_pos] = '\0';
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 " %s: DTMF CallerID %s\n",p->dev,p->callerid);
- if (owner){
- /*
- if (owner->cid.cid_num)
- free(owner->cid.cid_num);
- owner->cid.cid_num=NULL;
- if (owner->cid.cid_name)
- free(owner->cid.cid_name);
- owner->cid.cid_name=NULL;
- owner->cid.cid_num = strdup(p->callerid);
- */
- cid_name[0] = '\0';
- cid_num[0] = '\0';
- ast_callerid_split(p->callerid, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
- ast_set_callerid(owner, cid_num, cid_name, cid_num);
-
- }
- else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 " %s: DTMF CallerID: no owner to assign CID \n",p->dev);
- }
- } else if ( p->dtmf_caller_pos < AST_MAX_EXTENSION ) {
- if ( p->dtmf_caller_pos >= 0 )
- p->callerid[p->dtmf_caller_pos] = e->data;
- p->dtmf_caller_pos++;
- }
- }
- break;
- }
- if (p->wantdtmf == 1) {
- stoptone(p->handle);
- p->wantdtmf = 0;
- }
- p->state=VPB_STATE_GETDTMF;
- s[0] = e->data;
- strncat(p->ext, s, sizeof(p->ext) - strlen(p->ext) - 1);
- #if 0
- if (!strcmp(p->ext,ast_pickup_ext())) {
- /* Call pickup has been dialled! */
- if (ast_pickup_call(c)) {
- /* Call pickup wasnt possible */
- }
- }
- else
- #endif
- if (ast_exists_extension(NULL, p->context, p->ext, 1, p->callerid)){
- if ( ast_canmatch_extension(NULL, p->context, p->ext, 1, p->callerid)){
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: Multiple matches on [%s] in [%s]\n", p->dev,p->ext , p->context);
- /* Start DTMF IDD timer */
- vpb_timer_stop(p->dtmfidd_timer);
- vpb_timer_start(p->dtmfidd_timer);
- }
- else {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: Matched on [%s] in [%s]\n", p->dev,p->ext , p->context);
- vpb_new(p,AST_STATE_UP, p->context);
- }
- } else if (!ast_canmatch_extension(NULL, p->context, p->ext, 1, p->callerid)){
- if (ast_exists_extension(NULL, "default", p->ext, 1, p->callerid)) {
- vpb_new(p,AST_STATE_UP, "default");
- } else if (!ast_canmatch_extension(NULL, "default", p->ext, 1, p->callerid)) {
- if (option_verbose > 3) {
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: can't match anything in %s or default\n", p->dev, p->context);
- }
- playtone(p->handle, &Busytone);
- vpb_timer_stop(p->busy_timer);
- vpb_timer_start(p->busy_timer);
- p->state = VPB_STATE_PLAYBUSY;
- }
- }
- break;
-
- default:
- /* Ignore.*/
- break;
- }
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: mode=%d, [%d=>%d]\n",
- p->dev, p->mode, e->type, e->data);
-
- return 0;
-}
-
-static void *do_monitor(void *unused)
-{
-
- /* Monitor thread, doesn't die until explicitly killed. */
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Starting vpb monitor thread[%ld]\n",
- pthread_self());
-
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
-
- for(;;) {
- VPB_EVENT e;
- VPB_EVENT je;
- char str[VPB_MAX_STR];
- struct vpb_pvt *p;
-
- /*
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Monitor waiting for event\n");
- */
-
- int res = vpb_get_event_sync(&e, VPB_WAIT_TIMEOUT);
- if( (res==VPB_NO_EVENTS) || (res==VPB_TIME_OUT) ){
- /*
- if (option_verbose > 3){
- if (res == VPB_NO_EVENTS){
- ast_verbose(VERBOSE_PREFIX_4 "No events....\n");
- } else {
- ast_verbose(VERBOSE_PREFIX_4 "No events, timed out....\n");
- }
- }
- */
- continue;
- }
-
- if (res != VPB_OK) {
- ast_log(LOG_ERROR,"Monitor get event error %s\n", vpb_strerror(res) );
- ast_verbose("Monitor get event error %s\n", vpb_strerror(res) );
- continue;
- }
-
- str[0] = 0;
-
- p = NULL;
-
- ast_mutex_lock(&monlock); {
-
- if (e.type == VPB_NULL_EVENT) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Monitor got null event\n");
- }
- else {
- vpb_translate_event(&e, str);
- if (strlen(str)>1){
- str[(strlen(str)-1)]='\0';
- }
-
- ast_mutex_lock(&iflock); {
- p = iflist;
- while (p && p->handle != e.handle)
- p = p->next;
- } ast_mutex_unlock(&iflock);
-
- if (p && (option_verbose > 3))
- ast_verbose(VERBOSE_PREFIX_4 "%s: Event [%d=>%s] \n",
- p ? p->dev : "null", e.type, str );
- }
-
- } ast_mutex_unlock(&monlock);
-
- if (!p) {
- if (e.type != VPB_NULL_EVENT){
- ast_log(LOG_WARNING, "Got event [%s][%d], no matching iface!\n", str,e.type);
- if (option_verbose > 3){
- ast_verbose(VERBOSE_PREFIX_4 "vpb/ERR: No interface for Event [%d=>%s] \n",e.type,str );
- }
- }
- continue;
- }
-
- /* flush the event from the channel event Q */
- vpb_get_event_ch_async(e.handle,&je);
- if (option_verbose > 4){
- vpb_translate_event(&je, str);
- ast_verbose("%s: Flushing event [%d]=>%s\n",p->dev,je.type,str);
- }
-
- /* Check for ownership and locks */
- if ((p->owner)&&(!p->golock)){
- /* Need to get owner lock */
- /* Safely grab both p->lock and p->owner->lock so that there
- cannot be a race with something from the other side */
- /*
- ast_mutex_lock(&p->lock);
- while(ast_mutex_trylock(&p->owner->lock)) {
- ast_mutex_unlock(&p->lock);
- usleep(1);
- ast_mutex_lock(&p->lock);
- if (!p->owner)
- break;
- }
- if (p->owner)
- p->golock=1;
- */
- }
- /* Two scenarios: Are you owned or not. */
- if (p->owner) {
- monitor_handle_owned(p, &e);
- } else {
- monitor_handle_notowned(p, &e);
- }
- /* if ((!p->owner)&&(p->golock)){
- ast_mutex_unlock(&p->owner->lock);
- ast_mutex_unlock(&p->lock);
- }
- */
-
- }
-
- return NULL;
-}
-
-static int restart_monitor(void)
-{
- int error = 0;
-
- /* If we're supposed to be stopped -- stay stopped */
- if (mthreadactive == -2)
- return 0;
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Restarting monitor\n");
-
- ast_mutex_lock(&monlock); {
- if (monitor_thread == pthread_self()) {
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- error = -1;
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Monitor trying to kill monitor\n");
- }
- else {
- if (mthreadactive != -1) {
- /* Why do other drivers kill the thread? No need says I, simply awake thread with event. */
- VPB_EVENT e;
- e.handle = 0;
- e.type = VPB_NULL_EVENT;
- e.data = 0;
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Trying to reawake monitor\n");
-
- vpb_put_event(&e);
- } else {
- /* Start a new monitor */
- int pid = ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL);
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Created new monitor thread %d\n",pid);
- if (pid < 0) {
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- error = -1;
- } else
- mthreadactive = 0; /* Started the thread!*/
- }
- }
- } ast_mutex_unlock(&monlock);
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Monitor restarted\n");
-
- return error;
-}
-
-/* Per board config that must be called after vpb_open() */
-static void mkbrd(vpb_model_t model, int echo_cancel)
-{
- if(!bridges) {
- if(model==vpb_model_v4pci)
- max_bridges = MAX_BRIDGES_V4PCI;
- bridges = (vpb_bridge_t *)malloc(max_bridges * sizeof(vpb_bridge_t) );
- if(!bridges)
- ast_log(LOG_ERROR, "Failed to initialize bridges\n");
- else {
- memset(bridges,0,max_bridges * sizeof(vpb_bridge_t));
- for(int i = 0; i < max_bridges; i++ ) {
- ast_mutex_init(&bridges[i].lock);
- ast_cond_init(&bridges[i].cond, NULL);
- }
- }
- }
- if(!echo_cancel) {
- if (model==vpb_model_v4pci) {
- vpb_echo_canc_disable();
- ast_log(LOG_NOTICE, "Voicetronix echo cancellation OFF\n");
- }
- else {
- /* need to it port by port for OpenSwitch*/
- }
- } else {
- if (model==vpb_model_v4pci) {
- vpb_echo_canc_enable();
- ast_log(LOG_NOTICE, "Voicetronix echo cancellation ON\n");
- if (ec_supp_threshold > -1){
- #ifdef VPB_PRI
- vpb_echo_canc_set_sup_thresh(0,(short *)&ec_supp_threshold);
- #else
- vpb_echo_canc_set_sup_thresh((short *)&ec_supp_threshold);
- #endif
- ast_log(LOG_NOTICE, "Voicetronix EC Sup Thres set\n");
- }
- }
- else {
- /* need to it port by port for OpenSwitch*/
- }
- }
-}
-
-static struct vpb_pvt *mkif(int board, int channel, int mode, int gains, float txgain, float rxgain,
- float txswgain, float rxswgain, int bal1, int bal2, int bal3,
- char * callerid, int echo_cancel, int group, ast_group_t callgroup, ast_group_t pickupgroup )
-{
- struct vpb_pvt *tmp;
- char buf[64];
-
- tmp = (struct vpb_pvt *)calloc(1, sizeof *tmp);
-
- if (!tmp)
- return NULL;
-
- tmp->handle = vpb_open(board, channel);
-
- if (tmp->handle < 0) {
- ast_log(LOG_WARNING, "Unable to create channel vpb/%d-%d: %s\n",
- board, channel, strerror(errno));
- free(tmp);
- return NULL;
- }
-
- snprintf(tmp->dev, sizeof(tmp->dev), "vpb/%d-%d", board, channel);
-
- tmp->mode = mode;
-
- tmp->group = group;
- tmp->callgroup = callgroup;
- tmp->pickupgroup = pickupgroup;
-
- /* Initilize dtmf caller ID position variable */
- tmp->dtmf_caller_pos=0;
-
- strncpy(tmp->language, language, sizeof(tmp->language) - 1);
- strncpy(tmp->context, context, sizeof(tmp->context) - 1);
-
- tmp->callerid_type=0;
- if(callerid) {
- if (strcasecmp(callerid,"on")==0){
- tmp->callerid_type =1;
- strncpy(tmp->callerid, "unknown", sizeof(tmp->callerid) - 1);
- }
- else if (strcasecmp(callerid,"v23")==0){
- tmp->callerid_type =2;
- strncpy(tmp->callerid, "unknown", sizeof(tmp->callerid) - 1);
- }
- else if (strcasecmp(callerid,"bell")==0){
- tmp->callerid_type =3;
- strncpy(tmp->callerid, "unknown", sizeof(tmp->callerid) - 1);
- }
- else {
- strncpy(tmp->callerid, callerid, sizeof(tmp->callerid) - 1);
- }
- } else {
- strncpy(tmp->callerid, "unknown", sizeof(tmp->callerid) - 1);
- }
-
- /* check if codec balances have been set in the config file */
- if (bal3>=0) {
- if ((bal1>=0) && !(bal1 & 32)) bal1 |= 32;
- vpb_set_codec_reg(tmp->handle, 0x42, bal3);
- }
- if(bal1>=0) vpb_set_codec_reg(tmp->handle, 0x32, bal1);
- if(bal2>=0) vpb_set_codec_reg(tmp->handle, 0x3a, bal2);
-
- if (gains & VPB_GOT_TXHWG){
- if (txgain > MAX_VPB_GAIN){
- tmp->txgain = MAX_VPB_GAIN;
- }
- else if (txgain < MIN_VPB_GAIN){
- tmp->txgain = MIN_VPB_GAIN;
- }
- else {
- tmp->txgain = txgain;
- }
-
- ast_log(LOG_NOTICE,"VPB setting Tx Hw gain to [%f]\n",tmp->txgain);
- vpb_play_set_hw_gain(tmp->handle, tmp->txgain);
- }
-
- if (gains & VPB_GOT_RXHWG){
- if (rxgain > MAX_VPB_GAIN){
- tmp->rxgain = MAX_VPB_GAIN;
- }
- else if (rxgain < MIN_VPB_GAIN){
- tmp->rxgain = MIN_VPB_GAIN;
- }
- else {
- tmp->rxgain = rxgain;
- }
- ast_log(LOG_NOTICE,"VPB setting Rx Hw gain to [%f]\n",tmp->rxgain);
- vpb_record_set_hw_gain(tmp->handle,tmp->rxgain);
- }
-
- if (gains & VPB_GOT_TXSWG){
- tmp->txswgain = txswgain;
- ast_log(LOG_NOTICE,"VPB setting Tx Sw gain to [%f]\n",tmp->txswgain);
- vpb_play_set_gain(tmp->handle, tmp->txswgain);
- }
-
- if (gains & VPB_GOT_RXSWG){
- tmp->rxswgain = rxswgain;
- ast_log(LOG_NOTICE,"VPB setting Rx Sw gain to [%f]\n",tmp->rxswgain);
- vpb_record_set_gain(tmp->handle, tmp->rxswgain);
- }
-
- tmp->vpb_model = vpb_model_unknown;
- if( vpb_get_model(buf) == VPB_OK ) {
- if(strcmp(buf,"V12PCI")==0)
- tmp->vpb_model = vpb_model_v12pci;
- else if(strcmp(buf,"VPB4")==0)
- tmp->vpb_model = vpb_model_v4pci;
- }
-
- ast_mutex_init(&tmp->owner_lock);
- ast_mutex_init(&tmp->lock);
- ast_mutex_init(&tmp->record_lock);
- ast_mutex_init(&tmp->play_lock);
- ast_mutex_init(&tmp->play_dtmf_lock);
-
- /* set default read state */
- tmp->read_state = 0;
-
- tmp->golock=0;
-
- tmp->busy_timer_id = vpb_timer_get_unique_timer_id();
- vpb_timer_open(&tmp->busy_timer, tmp->handle, tmp->busy_timer_id, TIMER_PERIOD_BUSY);
-
- tmp->ringback_timer_id = vpb_timer_get_unique_timer_id();
- vpb_timer_open(&tmp->ringback_timer, tmp->handle, tmp->ringback_timer_id, TIMER_PERIOD_RINGBACK);
-
- tmp->ring_timer_id = vpb_timer_get_unique_timer_id();
- vpb_timer_open(&tmp->ring_timer, tmp->handle, tmp->ring_timer_id, timer_period_ring);
-
- tmp->dtmfidd_timer_id = vpb_timer_get_unique_timer_id();
- vpb_timer_open(&tmp->dtmfidd_timer, tmp->handle, tmp->dtmfidd_timer_id, dtmf_idd);
-
- if (mode == MODE_FXO){
- if (use_ast_dtmfdet)
- vpb_set_event_mask(tmp->handle, VPB_EVENTS_NODTMF );
- else
- vpb_set_event_mask(tmp->handle, VPB_EVENTS_ALL );
- }
- else {
-/*
- if (use_ast_dtmfdet)
- vpb_set_event_mask(tmp->handle, VPB_EVENTS_NODTMF );
- else
-*/
- vpb_set_event_mask(tmp->handle, VPB_EVENTS_STAT );
- }
-
- if ((tmp->vpb_model == vpb_model_v12pci) && (echo_cancel)){
- vpb_hostecho_on(tmp->handle);
- }
- if (use_ast_dtmfdet) {
- tmp->vad = ast_dsp_new();
- ast_dsp_set_features(tmp->vad, DSP_FEATURE_DTMF_DETECT);
- ast_dsp_digitmode(tmp->vad, DSP_DIGITMODE_DTMF);
- if (relaxdtmf)
- ast_dsp_digitmode(tmp->vad, DSP_DIGITMODE_DTMF|DSP_DIGITMODE_RELAXDTMF);
- }
- else {
- tmp->vad = NULL;
- }
-
- /* define grunt tone */
- vpb_settonedet(tmp->handle,&toned_ungrunt);
-
- ast_log(LOG_NOTICE,"Voicetronix %s channel %s initialized (rxsg=%f/txsg=%f/rxhg=%f/txhg=%f)(0x%x/0x%x/0x%x)\n",
- (tmp->vpb_model==vpb_model_v4pci)?"V4PCI": (tmp->vpb_model==vpb_model_v12pci)?"V12PCI":"[Unknown model]",
- tmp->dev, tmp->rxswgain, tmp->txswgain, tmp->rxgain, tmp->txgain, bal1, bal2, bal3 );
-
- return tmp;
-}
-
-static int vpb_indicate(struct ast_channel *ast, int condition)
-{
- struct vpb_pvt *p = (struct vpb_pvt *)ast->tech_pvt;
- int res = 0;
- int tmp = 0;
-
- if (use_ast_ind == 1) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: vpb_indicate called when using Ast Indications !?!\n", p->dev);
- return 0;
- }
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: vpb_indicate [%d] state[%d]\n", p->dev, condition,ast->_state);
-/*
- if (ast->_state != AST_STATE_UP) {
- ast_verbose(VERBOSE_PREFIX_4 "%s: vpb_indicate Not in AST_STATE_UP\n", p->dev, condition,ast->_state);
- return res;
- }
-*/
-
-/*
- if (option_verbose > 3) ast_verbose("%s: LOCKING in indicate \n", p->dev);
- if (option_verbose > 3) ast_verbose("%s: LOCKING count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
-*/
- ast_mutex_lock(&p->lock);
- switch(condition) {
- case AST_CONTROL_BUSY:
- case AST_CONTROL_CONGESTION:
- if (ast->_state == AST_STATE_UP) {
- playtone(p->handle, &Busytone);
- p->state = VPB_STATE_PLAYBUSY;
- vpb_timer_stop(p->busy_timer);
- vpb_timer_start(p->busy_timer);
- }
- break;
- case AST_CONTROL_RINGING:
- if (ast->_state == AST_STATE_UP) {
- playtone(p->handle, &Ringbacktone);
- p->state = VPB_STATE_PLAYRING;
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: vpb indicate: setting ringback timer [%d]\n", p->dev,p->ringback_timer_id);
-
- vpb_timer_stop(p->ringback_timer);
- vpb_timer_start(p->ringback_timer);
- }
- break;
- case AST_CONTROL_ANSWER:
- case -1: /* -1 means stop playing? */
- vpb_timer_stop(p->ringback_timer);
- vpb_timer_stop(p->busy_timer);
- stoptone(p->handle);
- break;
- case AST_CONTROL_HANGUP:
- if (ast->_state == AST_STATE_UP) {
- playtone(p->handle, &Busytone);
- p->state = VPB_STATE_PLAYBUSY;
- vpb_timer_stop(p->busy_timer);
- vpb_timer_start(p->busy_timer);
- }
- break;
-
- default:
- res = 0;
- break;
- }
- tmp = ast_mutex_unlock(&p->lock);
-/*
- if (option_verbose > 3) ast_verbose("%s: unLOCKING in indicate [%d]\n", p->dev,tmp);
-*/
- return res;
-}
-
-static int vpb_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct vpb_pvt *p = (struct vpb_pvt *)newchan->tech_pvt;
- int res = 0;
-
-/*
- if (option_verbose > 3) ast_verbose("%s: LOCKING in fixup \n", p->dev);
- if (option_verbose > 3) ast_verbose("%s: LOCKING count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
-*/
- ast_mutex_lock(&p->lock);
- ast_log(LOG_DEBUG, "New owner for channel %s is %s\n", p->dev, newchan->name);
-
- if (p->owner == oldchan) {
- p->owner = newchan;
- }
-
- if (newchan->_state == AST_STATE_RINGING){
- if (use_ast_ind == 1) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: vpb_fixup Calling ast_indicate\n", p->dev);
- ast_indicate(newchan, AST_CONTROL_RINGING);
- }
- else {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: vpb_fixup Calling vpb_indicate\n", p->dev);
- vpb_indicate(newchan, AST_CONTROL_RINGING);
- }
- }
-
- res= ast_mutex_unlock(&p->lock);
-/*
- if (option_verbose > 3) ast_verbose("%s: unLOCKING in fixup [%d]\n", p->dev,res);
-*/
- return 0;
-}
-
-static int vpb_digit(struct ast_channel *ast, char digit)
-{
- struct vpb_pvt *p = (struct vpb_pvt *)ast->tech_pvt;
- char s[2];
- int res = 0;
-
- if (use_ast_dtmf){
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: vpb_digit: asked to play digit[%c] but we are using asterisk dtmf play back?!\n", p->dev, digit);
- return 0;
- }
-
-/*
- if (option_verbose > 3) ast_verbose("%s: LOCKING in digit \n", p->dev);
- if (option_verbose > 3) ast_verbose("%s: LOCKING count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
-*/
- ast_mutex_lock(&p->lock);
-
-
- s[0] = digit;
- s[1] = '\0';
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: vpb_digit: asked to play digit[%s]\n", p->dev, s);
-
- ast_mutex_lock(&p->play_dtmf_lock);
- strncat(p->play_dtmf,s,sizeof(*p->play_dtmf));
- ast_mutex_unlock(&p->play_dtmf_lock);
-
- res = ast_mutex_unlock(&p->lock);
-/*
- if (option_verbose > 3) ast_verbose("%s: unLOCKING in digit [%d]\n", p->dev,res);
-*/
- return 0;
-}
-
-/* Places a call out of a VPB channel */
-static int vpb_call(struct ast_channel *ast, char *dest, int timeout)
-{
- struct vpb_pvt *p = (struct vpb_pvt *)ast->tech_pvt;
- int res = 0,i;
- char *s = strrchr(dest, '/');
- char dialstring[254] = "";
- int tmp = 0;
-
-/*
- if (option_verbose > 3) ast_verbose("%s: LOCKING in call \n", p->dev);
- if (option_verbose > 3) ast_verbose("%s: LOCKING count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
-*/
- ast_mutex_lock(&p->lock);
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: starting call to [%s]\n", p->dev,dest);
-
- if (s)
- s = s + 1;
- else
- s = dest;
- strncpy(dialstring, s, sizeof(dialstring) - 1);
- for (i=0; dialstring[i] != '\0' ; i++) {
- if ((dialstring[i] == 'w') || (dialstring[i] == 'W'))
- dialstring[i] = ',';
- else if ((dialstring[i] == 'f') || (dialstring[i] == 'F'))
- dialstring[i] = '&';
- }
-
- if (ast->_state != AST_STATE_DOWN && ast->_state != AST_STATE_RESERVED) {
- ast_log(LOG_WARNING, "vpb_call on %s neither down nor reserved!\n", ast->name);
- tmp = ast_mutex_unlock(&p->lock);
-/*
- if (option_verbose > 3) ast_verbose("%s: unLOCKING in call [%d]\n", p->dev,tmp);
-*/
- return -1;
- }
- if (p->mode != MODE_FXO) /* Station port, ring it. */
- res = vpb_ring_station_async(p->handle, VPB_RING_STATION_ON,0);
- else {
- VPB_CALL call;
-
- /* Dial must timeout or it can leave channels unuseable */
- if( timeout == 0 )
- timeout = TIMER_PERIOD_NOANSWER;
- else
- timeout = timeout * 1000; /* convert from secs to ms. */
-
- /* These timeouts are only used with call progress dialing */
- call.dialtones = 1; /* Number of dialtones to get outside line */
- call.dialtone_timeout = VPB_DIALTONE_WAIT; /* Wait this long for dialtone (ms) */
- call.ringback_timeout = VPB_RINGWAIT; /* Wait this long for ringing after dialing (ms) */
- call.inter_ringback_timeout = VPB_CONNECTED_WAIT; /* If ringing stops for this long consider it connected (ms) */
- call.answer_timeout = timeout; /* Time to wait for answer after ringing starts (ms) */
- memcpy( &call.tone_map, DialToneMap, sizeof(DialToneMap) );
- vpb_set_call(p->handle, &call);
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "%s: Calling %s on %s \n",p->dev, dialstring, ast->name);
-
- if (option_verbose > 2) {
- int j;
- ast_verbose(VERBOSE_PREFIX_2 "%s: Dial parms for %s %d/%dms/%dms/%dms/%dms\n", p->dev
- , ast->name, call.dialtones, call.dialtone_timeout
- , call.ringback_timeout, call.inter_ringback_timeout
- , call.answer_timeout );
- for( j=0; !call.tone_map[j].terminate; j++ )
- ast_verbose(VERBOSE_PREFIX_2 "%s: Dial parms for %s tone %d->%d\n", p->dev,
- ast->name, call.tone_map[j].tone_id, call.tone_map[j].call_id);
- }
-
- if (option_verbose > 3)
- ast_verbose("%s: Disabling Loop Drop detection\n",p->dev);
- vpb_disable_event(p->handle, VPB_MDROP);
- vpb_sethook_sync(p->handle,VPB_OFFHOOK);
- p->state=VPB_STATE_OFFHOOK;
-
- #ifndef DIAL_WITH_CALL_PROGRESS
- vpb_sleep(300);
- if (option_verbose > 3)
- ast_verbose("%s: Enabling Loop Drop detection\n",p->dev);
- vpb_enable_event(p->handle, VPB_MDROP);
- res = vpb_dial_async(p->handle, dialstring);
- #else
- if (option_verbose > 3)
- ast_verbose("%s: Enabling Loop Drop detection\n",p->dev);
- vpb_enable_event(p->handle, VPB_MDROP);
- res = vpb_call_async(p->handle, dialstring);
- #endif
-
- if (res != VPB_OK) {
- ast_log(LOG_DEBUG, "Call on %s to %s failed: %s\n", ast->name, s, vpb_strerror(res));
- res = -1;
- } else
- res = 0;
- }
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "%s: VPB Calling %s [t=%d] on %s returned %d\n",p->dev , s, timeout, ast->name, res);
- if (res == 0) {
- ast_setstate(ast, AST_STATE_RINGING);
- ast_queue_control(ast,AST_CONTROL_RINGING);
- }
-
- if (!p->readthread){
- ast_pthread_create(&p->readthread, NULL, do_chanreads, (void *)p);
- }
-
- tmp = ast_mutex_unlock(&p->lock);
-/*
- if (option_verbose > 3) ast_verbose("%s: unLOCKING in call [%d]\n", p->dev,tmp);
-*/
- return res;
-}
-
-static int vpb_hangup(struct ast_channel *ast)
-{
- struct vpb_pvt *p = (struct vpb_pvt *)ast->tech_pvt;
- VPB_EVENT je;
- char str[VPB_MAX_STR];
- int res =0 ;
-
-/*
- if (option_verbose > 3) ast_verbose("%s: LOCKING in hangup \n", p->dev);
- if (option_verbose > 3) ast_verbose("%s: LOCKING in hangup count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
- if (option_verbose > 3) ast_verbose("%s: LOCKING pthread_self(%d)\n", p->dev,pthread_self());
- ast_mutex_lock(&p->lock);
-*/
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "%s: Hangup requested\n", ast->name);
-
- if (!ast->tech || !ast->tech_pvt) {
- ast_log(LOG_WARNING, "%s: channel not connected?\n", ast->name);
- res = ast_mutex_unlock(&p->lock);
-/*
- if (option_verbose > 3) ast_verbose("%s: unLOCKING in hangup [%d]\n", p->dev,res);
-*/
- /* Free up ast dsp if we have one */
- if ((use_ast_dtmfdet)&&(p->vad)) {
- ast_dsp_free(p->vad);
- p->vad = NULL;
- }
- return 0;
- }
-
-
-
- /* Stop record */
- p->stopreads = 1;
- if( p->readthread ){
- pthread_join(p->readthread, NULL);
- if(option_verbose>3)
- ast_verbose( VERBOSE_PREFIX_4 "%s: stopped record thread \n",ast->name);
- }
-
- /* Stop play */
- if (p->lastoutput != -1) {
- if(option_verbose>1)
- ast_verbose( VERBOSE_PREFIX_2 "%s: Ending play mode \n",ast->name);
- vpb_play_terminate(p->handle);
- ast_mutex_lock(&p->play_lock); {
- vpb_play_buf_finish(p->handle);
- } ast_mutex_unlock(&p->play_lock);
- }
-
- if(option_verbose>3)
- ast_verbose( VERBOSE_PREFIX_4 "%s: Setting state down\n",ast->name);
- ast_setstate(ast,AST_STATE_DOWN);
-
-
-/*
- if (option_verbose > 3) ast_verbose("%s: LOCKING in hangup \n", p->dev);
- if (option_verbose > 3) ast_verbose("%s: LOCKING in hangup count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
- if (option_verbose > 3) ast_verbose("%s: LOCKING pthread_self(%d)\n", p->dev,pthread_self());
-*/
- ast_mutex_lock(&p->lock);
-
- if (p->mode != MODE_FXO) {
- /* station port. */
- vpb_ring_station_async(p->handle, VPB_RING_STATION_OFF,0);
- if(p->state!=VPB_STATE_ONHOOK){
- /* This is causing a "dial end" "play tone" loop
- playtone(p->handle, &Busytone);
- p->state = VPB_STATE_PLAYBUSY;
- if(option_verbose>4)
- ast_verbose( VERBOSE_PREFIX_4 "%s: Station offhook[%d], playing busy tone\n",
- ast->name,p->state);
- */
- }
- else {
- stoptone(p->handle);
- }
- #ifdef VPB_PRI
- vpb_setloop_async(p->handle, VPB_OFFHOOK);
- vpb_sleep(100);
- vpb_setloop_async(p->handle, VPB_ONHOOK);
- #endif
- } else {
- stoptone(p->handle); /* Terminates any dialing */
- vpb_sethook_sync(p->handle, VPB_ONHOOK);
- p->state=VPB_STATE_ONHOOK;
- }
- while (VPB_OK==vpb_get_event_ch_async(p->handle,&je)){
- if(option_verbose>3) {
- vpb_translate_event(&je, str);
- ast_verbose( VERBOSE_PREFIX_4 "%s: Flushing event [%d]=>%s\n",ast->name,je.type,str);
- }
- }
-
- p->readthread = 0;
- p->lastoutput = -1;
- p->lastinput = -1;
- p->last_ignore_dtmf = 1;
- p->ext[0] = 0;
- p->dialtone = 0;
-
- p->owner = NULL;
- ast->tech_pvt=NULL;
-
- /* Free up ast dsp if we have one */
- if ((use_ast_dtmfdet)&&(p->vad)) {
- ast_dsp_free(p->vad);
- p->vad = NULL;
- }
-
- ast_mutex_lock(&usecnt_lock); {
- usecnt--;
- } ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "%s: Hangup complete\n", ast->name);
-
- restart_monitor();
-/*
- if (option_verbose > 3) ast_verbose("%s: LOCKING in hangup count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
-*/
- res = ast_mutex_unlock(&p->lock);
-/*
- if (option_verbose > 3) ast_verbose("%s: unLOCKING in hangup [%d]\n", p->dev,res);
- if (option_verbose > 3) ast_verbose("%s: LOCKING in hangup count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
-*/
- return 0;
-}
-
-static int vpb_answer(struct ast_channel *ast)
-{
- struct vpb_pvt *p = (struct vpb_pvt *)ast->tech_pvt;
- int res = 0;
-/*
- VPB_EVENT je;
- int ret;
- if (option_verbose > 3) ast_verbose("%s: LOCKING in answer \n", p->dev);
- if (option_verbose > 3) ast_verbose("%s: LOCKING count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
-*/
- ast_mutex_lock(&p->lock);
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: Answering channel\n",p->dev);
-
- if (p->mode == MODE_FXO){
- if (option_verbose > 3)
- ast_verbose("%s: Disabling Loop Drop detection\n",p->dev);
- vpb_disable_event(p->handle, VPB_MDROP);
- }
-
- if (ast->_state != AST_STATE_UP) {
- if (p->mode == MODE_FXO){
- vpb_sethook_sync(p->handle, VPB_OFFHOOK);
- p->state=VPB_STATE_OFFHOOK;
-/* vpb_sleep(500);
- ret = vpb_get_event_ch_async(p->handle,&je);
- if ((ret == VPB_OK)&&((je.type != VPB_DROP)&&(je.type != VPB_RING))){
- if (option_verbose > 3){
- ast_verbose(VERBOSE_PREFIX_4 "%s: Answer collected a wrong event!!\n",p->dev);
- }
- vpb_put_event(&je);
- }
-*/
- }
- ast_setstate(ast, AST_STATE_UP);
-
- if(option_verbose>1)
-/*
- ast_verbose( VERBOSE_PREFIX_2 "%s: Answered call from %s on %s [%s]\n", p->dev,
- p->owner->callerid, ast->name,(p->mode == MODE_FXO)?"FXO":"FXS");
-*/
- ast_verbose( VERBOSE_PREFIX_2 "%s: Answered call on %s [%s]\n", p->dev,
- ast->name,(p->mode == MODE_FXO)?"FXO":"FXS");
-
- ast->rings = 0;
- if( !p->readthread ){
- /* res = ast_mutex_unlock(&p->lock); */
- /* ast_verbose("%s: unLOCKING in answer [%d]\n", p->dev,res); */
- ast_pthread_create(&p->readthread, NULL, do_chanreads, (void *)p);
- } else {
- if(option_verbose>3)
- ast_verbose(VERBOSE_PREFIX_4 "%s: Record thread already running!!\n",p->dev);
- }
- } else {
- if(option_verbose>3) {
- ast_verbose(VERBOSE_PREFIX_4 "%s: Answered state is up\n",p->dev);
- }
- /* res = ast_mutex_unlock(&p->lock); */
- /* ast_verbose("%s: unLOCKING in answer [%d]\n", p->dev,res); */
- }
- vpb_sleep(500);
- if (p->mode == MODE_FXO){
- if (option_verbose > 3)
- ast_verbose("%s: Re-enabling Loop Drop detection\n",p->dev);
- vpb_enable_event(p->handle,VPB_MDROP);
- }
- res = ast_mutex_unlock(&p->lock);
-/*
- if(option_verbose>3) ast_verbose("%s: unLOCKING in answer [%d]\n", p->dev,res);
-*/
- return 0;
-}
-
-static struct ast_frame *vpb_read(struct ast_channel *ast)
-{
- struct vpb_pvt *p = (struct vpb_pvt *)ast->tech_pvt;
- static struct ast_frame f = {AST_FRAME_NULL};
-
- f.src = (char *)type;
- ast_log(LOG_NOTICE, "%s: vpb_read: should never be called!\n", p->dev);
- ast_verbose("%s: vpb_read: should never be called!\n", p->dev);
-
- return &f;
-}
-
-static inline int ast2vpbformat(int ast_format)
-{
- switch(ast_format) {
- case AST_FORMAT_ALAW:
- return VPB_ALAW;
- case AST_FORMAT_SLINEAR:
- return VPB_LINEAR;
- case AST_FORMAT_ULAW:
- return VPB_MULAW;
- case AST_FORMAT_ADPCM:
- return VPB_OKIADPCM;
- default:
- return -1;
- }
-}
-
-static inline char * ast2vpbformatname(int ast_format)
-{
- switch(ast_format) {
- case AST_FORMAT_ALAW:
- return "AST_FORMAT_ALAW:VPB_ALAW";
- case AST_FORMAT_SLINEAR:
- return "AST_FORMAT_SLINEAR:VPB_LINEAR";
- case AST_FORMAT_ULAW:
- return "AST_FORMAT_ULAW:VPB_MULAW";
- case AST_FORMAT_ADPCM:
- return "AST_FORMAT_ADPCM:VPB_OKIADPCM";
- default:
- return "UNKN:UNKN";
- }
-}
-
-static inline int astformatbits(int ast_format)
-{
- switch(ast_format) {
- case AST_FORMAT_ALAW:
- case AST_FORMAT_ULAW:
- return 8;
- case AST_FORMAT_SLINEAR:
- return 16;
- case AST_FORMAT_ADPCM:
- return 4;
- default:
- return 8;
- }
-}
-
-int a_gain_vector(float g, short *v, int n)
-{
- int i;
- float tmp;
- for ( i = 0; i<n; i++) {
- tmp = g*v[i];
- if (tmp > 32767.0)
- tmp = 32767.0;
- if (tmp < -32768.0)
- tmp = -32768.0;
- v[i] = (short)tmp;
- }
- return(i);
-}
-
-/* Writes a frame of voice data to a VPB channel */
-static int vpb_write(struct ast_channel *ast, struct ast_frame *frame)
-{
- struct vpb_pvt *p = (struct vpb_pvt *)ast->tech_pvt;
- int res = 0, fmt = 0;
- struct timeval play_buf_time_start;
- struct ast_frame *nextf;
- int tdiff;
-
-/* ast_mutex_lock(&p->lock); */
- if(option_verbose>5)
- ast_verbose("%s: vpb_write: Writing to channel\n", p->dev);
-
- if (frame->frametype != AST_FRAME_VOICE) {
- if(option_verbose>3)
- ast_verbose("%s: vpb_write: Don't know how to handle from type %d\n", ast->name, frame->frametype);
-/* ast_mutex_unlock(&p->lock); */
- return 0;
- } else if (ast->_state != AST_STATE_UP) {
- if(option_verbose>3)
- ast_verbose("%s: vpb_write: Attempt to Write frame type[%d]subclass[%d] on not up chan(state[%d])\n",ast->name, frame->frametype, frame->subclass,ast->_state);
- p->lastoutput = -1;
-/* ast_mutex_unlock(&p->lock); */
- return 0;
- }
-/* ast_log(LOG_DEBUG, "%s: vpb_write: Checked frame type..\n", p->dev); */
-
-
- fmt = ast2vpbformat(frame->subclass);
- if (fmt < 0) {
- ast_log(LOG_WARNING, "%s: vpb_write: Cannot handle frames of %d format!\n",ast->name, frame->subclass);
- return -1;
- }
-
- tdiff = ast_tvdiff_ms(ast_tvnow(), p->lastplay);
- ast_log(LOG_DEBUG, "%s: vpb_write: time since last play(%d) \n", p->dev, tdiff);
- if (tdiff < (VPB_SAMPLES/8 - 1)){
- ast_log(LOG_DEBUG, "%s: vpb_write: Asked to play too often (%d) (%d)\n", p->dev, tdiff,frame->datalen);
-// return 0;
- }
- p->lastplay = ast_tvnow();
-/*
- ast_log(LOG_DEBUG, "%s: vpb_write: Checked frame format..\n", p->dev);
-*/
-
- ast_mutex_lock(&p->play_lock);
-
-/*
- ast_log(LOG_DEBUG, "%s: vpb_write: Got play lock..\n", p->dev);
-*/
-
- /* Check if we have set up the play_buf */
- if (p->lastoutput == -1) {
- vpb_play_buf_start(p->handle, fmt);
- if(option_verbose>1) {
- ast_verbose("%s: vpb_write: Starting play mode (codec=%d)[%s]\n",p->dev,fmt,ast2vpbformatname(frame->subclass));
- }
- p->lastoutput = fmt;
- ast_mutex_unlock(&p->play_lock);
- return 0;
- } else if (p->lastoutput != fmt) {
- vpb_play_buf_finish(p->handle);
- vpb_play_buf_start(p->handle, fmt);
- if(option_verbose>1)
- ast_verbose("%s: vpb_write: Changed play format (%d=>%d)\n",p->dev,p->lastoutput,fmt);
- ast_mutex_unlock(&p->play_lock);
- return 0;
- }
- p->lastoutput = fmt;
-
-
-
- /* Apply extra gain ! */
- if( p->txswgain > MAX_VPB_GAIN )
- a_gain_vector(p->txswgain - MAX_VPB_GAIN , (short*)frame->data, frame->datalen/sizeof(short));
-
-/* ast_log(LOG_DEBUG, "%s: vpb_write: Applied gain..\n", p->dev); */
-/* ast_log(LOG_DEBUG, "%s: vpb_write: play_buf_time %d\n", p->dev, p->play_buf_time); */
-
- if ((p->read_state == 1)&&(p->play_buf_time<5)){
- play_buf_time_start = ast_tvnow();
-/* res = vpb_play_buf_sync(p->handle, (char*)frame->data, tdiff*8*2); */
- res = vpb_play_buf_sync(p->handle, (char*)frame->data, frame->datalen);
- if( res == VPB_OK && option_verbose > 5 ) {
- short * data = (short*)frame->data;
- ast_verbose("%s: vpb_write: Wrote chan (codec=%d) %d %d\n", p->dev, fmt, data[0],data[1]);
- }
- p->play_buf_time = ast_tvdiff_ms(ast_tvnow(), play_buf_time_start);
- }
- else {
- p->chuck_count++;
- ast_log(LOG_DEBUG, "%s: vpb_write: Tossed data away, tooooo much data!![%d]\n", p->dev,p->chuck_count);
- p->play_buf_time=0;
- }
-
- ast_mutex_unlock(&p->play_lock);
-/* ast_mutex_unlock(&p->lock); */
- if(option_verbose>5)
- ast_verbose("%s: vpb_write: Done Writing to channel\n", p->dev);
- return 0;
-}
-
-/* Read monitor thread function. */
-static void *do_chanreads(void *pvt)
-{
- struct vpb_pvt *p = (struct vpb_pvt *)pvt;
- struct ast_frame *fr = &p->fr;
- char *readbuf = ((char *)p->buf) + AST_FRIENDLY_OFFSET;
- int bridgerec = 0;
- int afmt, readlen, res, fmt, trycnt=0;
- int ignore_dtmf;
- char * getdtmf_var = NULL;
-
- fr->frametype = AST_FRAME_VOICE;
- fr->src = (char *)type;
- fr->mallocd = 0;
- fr->delivery.tv_sec = 0;
- fr->delivery.tv_usec = 0;
- fr->samples = VPB_SAMPLES;
- fr->offset = AST_FRIENDLY_OFFSET;
- memset(p->buf, 0, sizeof p->buf);
-
- if (option_verbose > 2) {
- ast_verbose("%s: chanreads: starting thread\n", p->dev);
- }
- ast_mutex_lock(&p->record_lock);
-
- p->stopreads = 0;
- p->read_state = 1;
- while (!p->stopreads && p->owner) {
-
- if (option_verbose > 4)
- ast_verbose("%s: chanreads: Starting cycle ...\n", p->dev);
- if (option_verbose > 4)
- ast_verbose("%s: chanreads: Checking bridge \n", p->dev);
- if (p->bridge) {
- if (p->bridge->c0 == p->owner && (p->bridge->flags & AST_BRIDGE_REC_CHANNEL_0))
- bridgerec = 1;
- else if (p->bridge->c1 == p->owner && (p->bridge->flags & AST_BRIDGE_REC_CHANNEL_1))
- bridgerec = 1;
- else
- bridgerec = 0;
- } else {
- if (option_verbose > 4)
- ast_verbose("%s: chanreads: No native bridge.\n", p->dev);
- if (p->owner->_bridge){
- if (option_verbose > 4){
- ast_verbose("%s: chanreads: Got Asterisk bridge with [%s].\n", p->dev,p->owner->_bridge->name);
- }
- bridgerec = 1;
- }
- else {
- bridgerec = 0;
- }
- }
-
-/* if ( (p->owner->_state != AST_STATE_UP) || !bridgerec) */
- if ( (p->owner->_state != AST_STATE_UP) )
- {
- if (option_verbose > 4) {
- if (p->owner->_state != AST_STATE_UP)
- ast_verbose("%s: chanreads: Im not up[%d]\n", p->dev,p->owner->_state);
- else
- ast_verbose("%s: chanreads: No bridgerec[%d]\n", p->dev,bridgerec);
- }
- vpb_sleep(10);
- continue;
- }
-
- /* Voicetronix DTMF detection can be triggered off ordinary speech
- * This leads to annoying beeps during the conversation
- * Avoid this problem by just setting VPB_GETDTMF when you want to listen for DTMF
- */
- /* ignore_dtmf = 1; */
- ignore_dtmf = 0; /* set this to 1 to turn this feature on */
- getdtmf_var = pbx_builtin_getvar_helper(p->owner,"VPB_GETDTMF");
- if( getdtmf_var && ( strcasecmp( getdtmf_var, "yes" ) == 0 ) )
- ignore_dtmf = 0;
-
- if(( ignore_dtmf != p->last_ignore_dtmf ) &&(!use_ast_dtmfdet)){
- if(option_verbose>1)
- ast_verbose( VERBOSE_PREFIX_2 "%s:Now %s DTMF \n",
- p->dev, ignore_dtmf ? "ignoring" : "listening for");
- vpb_set_event_mask(p->handle, ignore_dtmf ? VPB_EVENTS_NODTMF : VPB_EVENTS_ALL );
- }
- p->last_ignore_dtmf = ignore_dtmf;
-
- /* Play DTMF digits here to avoid problem you get if playing a digit during
- * a record operation
- */
- if (option_verbose > 5) {
- ast_verbose("%s: chanreads: Checking dtmf's \n", p->dev);
- }
- ast_mutex_lock(&p->play_dtmf_lock);
- if( p->play_dtmf[0] ) {
- /* Try to ignore DTMF event we get after playing digit */
- /* This DTMF is played by asterisk and leads to an annoying trailing beep on CISCO phones */
- if( !ignore_dtmf)
- vpb_set_event_mask(p->handle, VPB_EVENTS_NODTMF );
- if (p->bridge == NULL){
- vpb_dial_sync(p->handle,p->play_dtmf);
- if(option_verbose>1)
- ast_verbose( VERBOSE_PREFIX_2 "%s: chanreads: Played DTMF %s\n",p->dev,p->play_dtmf);
- }
- else {
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "%s: chanreads: Not playing DTMF frame on native bridge\n", p->dev);
- }
- p->play_dtmf[0] = '\0';
- ast_mutex_unlock(&p->play_dtmf_lock);
- vpb_sleep(700); /* Long enough to miss echo and DTMF event */
- if( !ignore_dtmf)
- vpb_set_event_mask(p->handle, VPB_EVENTS_ALL );
- continue;
- }
- ast_mutex_unlock(&p->play_dtmf_lock);
-
-/* afmt = (p->owner) ? p->owner->rawreadformat : AST_FORMAT_SLINEAR; */
- if (p->owner){
- afmt = p->owner->rawreadformat;
-/* ast_log(LOG_DEBUG,"%s: Record using owner format [%s]\n", p->dev, ast2vpbformatname(afmt)); */
- }
- else {
- afmt = AST_FORMAT_SLINEAR;
-/* ast_log(LOG_DEBUG,"%s: Record using default format [%s]\n", p->dev, ast2vpbformatname(afmt)); */
- }
- fmt = ast2vpbformat(afmt);
- if (fmt < 0) {
- ast_log(LOG_WARNING,"%s: Record failure (unsupported format %d)\n", p->dev, afmt);
- return NULL;
- }
- readlen = VPB_SAMPLES * astformatbits(afmt) / 8;
-
- if (p->lastinput == -1) {
- vpb_record_buf_start(p->handle, fmt);
- vpb_reset_record_fifo_alarm(p->handle);
- p->lastinput = fmt;
- if(option_verbose>1)
- ast_verbose( VERBOSE_PREFIX_2 "%s: Starting record mode (codec=%d)[%s]\n",p->dev,fmt,ast2vpbformatname(afmt));
- continue;
- } else if (p->lastinput != fmt) {
- vpb_record_buf_finish(p->handle);
- vpb_record_buf_start(p->handle, fmt);
- p->lastinput = fmt;
- if(option_verbose>1)
- ast_verbose( VERBOSE_PREFIX_2 "%s: Changed record format (%d=>%d)\n",p->dev,p->lastinput,fmt);
- continue;
- }
-
- /* Read only if up and not bridged, or a bridge for which we can read. */
- if (option_verbose > 5) {
- ast_verbose("%s: chanreads: getting buffer!\n", p->dev);
- }
- if( (res = vpb_record_buf_sync(p->handle, readbuf, readlen) ) == VPB_OK ) {
- if (option_verbose > 5) {
- ast_verbose("%s: chanreads: got buffer!\n", p->dev);
- }
- /* Apply extra gain ! */
- if( p->rxswgain > MAX_VPB_GAIN )
- a_gain_vector(p->rxswgain - MAX_VPB_GAIN , (short*)readbuf, readlen/sizeof(short));
- if (option_verbose > 5) {
- ast_verbose("%s: chanreads: applied gain\n", p->dev);
- }
-
- fr->subclass = afmt;
- fr->data = readbuf;
- fr->datalen = readlen;
- fr->frametype = AST_FRAME_VOICE;
-
- if ((use_ast_dtmfdet)&&(p->vad)){
- fr = ast_dsp_process(p->owner,p->vad,fr);
- if (fr && (fr->frametype == AST_FRAME_DTMF))
- ast_log(LOG_DEBUG, "%s: chanreads: Detected DTMF '%c'\n",p->dev, fr->subclass);
- if (fr->subclass == 'm'){
- /* conf mute request */
- fr->frametype = AST_FRAME_NULL;
- fr->subclass = 0;
- }
- else if (fr->subclass == 'u'){
- /* Unmute */
- fr->frametype = AST_FRAME_NULL;
- fr->subclass = 0;
- }
- else if (fr->subclass == 'f'){
- }
- }
- /* Using trylock here to prevent deadlock when channel is hungup
- * (ast_hangup() immediately gets lock)
- */
- if (p->owner && !p->stopreads ) {
- if (option_verbose > 5) {
- ast_verbose("%s: chanreads: queueing buffer on read frame q (state[%d])\n", p->dev,p->owner->_state);
- }
- do {
- res = ast_mutex_trylock(&p->owner->lock);
- trycnt++;
- } while((res !=0)&&(trycnt<300));
- if (res==0) {
- ast_queue_frame(p->owner, fr);
- ast_mutex_unlock(&p->owner->lock);
- } else {
- if (option_verbose > 4)
- ast_verbose("%s: chanreads: Couldnt get lock after %d tries!\n", p->dev,trycnt);
- }
- trycnt=0;
-
-/*
- res = ast_mutex_trylock(&p->owner->lock);
- if (res==0) {
- ast_queue_frame(p->owner, fr);
- ast_mutex_unlock(&p->owner->lock);
- } else {
- if (res == EINVAL )
- if (option_verbose > 4) ast_verbose("%s: chanreads: try owner->lock gave me EINVAL[%d]\n", p->dev,res);
- else if (res == EBUSY )
- if (option_verbose > 4) ast_verbose("%s: chanreads: try owner->lock gave me EBUSY[%d]\n", p->dev,res);
- while(res !=0){
- res = ast_mutex_trylock(&p->owner->lock);
- }
- if (res==0) {
- ast_queue_frame(p->owner, fr);
- ast_mutex_unlock(&p->owner->lock);
- }
- else {
- if (res == EINVAL )
- if (option_verbose > 4) ast_verbose("%s: chanreads: try owner->lock gave me EINVAL[%d]\n", p->dev,res);
- else if (res == EBUSY )
- if (option_verbose > 4) ast_verbose("%s: chanreads: try owner->lock gave me EBUSY[%d]\n", p->dev,res);
- if (option_verbose > 4) ast_verbose("%s: chanreads: Couldnt get lock on owner[%s][%d][%d] channel to send frame!\n", p->dev,p->owner->name,(int)p->owner->lock.__m_owner,(int)p->owner->lock.__m_count);
- }
- }
-*/
- if (option_verbose > 6) {
- short * data = (short*)readbuf;
- ast_verbose("%s: Read channel (codec=%d) %d %d\n", p->dev, fmt, data[0], data[1] );
- }
- }
- else {
- if (option_verbose > 4) {
- ast_verbose("%s: p->stopreads[%d] p->owner[%p]\n", p->dev, p->stopreads,(void *)p->owner);
- }
- }
- }
- if (option_verbose > 4)
- ast_verbose("%s: chanreads: Finished cycle...\n", p->dev);
- }
- p->read_state=0;
-
- /* When stopreads seen, go away! */
- vpb_record_buf_finish(p->handle);
- p->read_state=0;
- ast_mutex_unlock(&p->record_lock);
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "%s: Ending record mode (%d/%s)\n",
- p->dev, p->stopreads, p->owner? "yes" : "no");
- return NULL;
-}
-
-static struct ast_channel *vpb_new(struct vpb_pvt *me, int state, char *context)
-{
- struct ast_channel *tmp;
- char cid_num[256];
- char cid_name[256];
-
- if (me->owner) {
- ast_log(LOG_WARNING, "Called vpb_new on owned channel (%s) ?!\n", me->dev);
- return NULL;
- }
- if (option_verbose > 3)
- ast_verbose("%s: New call for context [%s]\n",me->dev,context);
-
- tmp = ast_channel_alloc(1);
- if (tmp) {
- if (use_ast_ind == 1){
- tmp->tech = &vpb_tech_indicate;
- }
- else {
- tmp->tech = &vpb_tech;
- }
-
- strncpy(tmp->name, me->dev, sizeof(tmp->name) - 1);
- tmp->type = type;
-
- tmp->callgroup = me->callgroup;
- tmp->pickupgroup = me->pickupgroup;
-
- /* Linear is the preferred format. Although Voicetronix supports other formats
- * they are all converted to/from linear in the vpb code. Best for us to use
- * linear since we can then adjust volume in this modules.
- */
- tmp->nativeformats = prefformat;
- tmp->rawreadformat = AST_FORMAT_SLINEAR;
- tmp->rawwriteformat = AST_FORMAT_SLINEAR;
- ast_setstate(tmp, state);
- if (state == AST_STATE_RING) {
- tmp->rings = 1;
- cid_name[0] = '\0';
- cid_num[0] = '\0';
- ast_callerid_split(me->callerid, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
- ast_set_callerid(tmp, cid_num, cid_name, cid_num);
- }
- tmp->tech_pvt = me;
-
- strncpy(tmp->context, context, sizeof(tmp->context)-1);
- if (strlen(me->ext))
- strncpy(tmp->exten, me->ext, sizeof(tmp->exten)-1);
- else
- strncpy(tmp->exten, "s", sizeof(tmp->exten) - 1);
- if (strlen(me->language))
- strncpy(tmp->language, me->language, sizeof(tmp->language)-1);
-
- me->owner = tmp;
-
- me->bridge = NULL;
- me->lastoutput = -1;
- me->lastinput = -1;
- me->last_ignore_dtmf = 1;
- me->readthread = 0;
- me->play_dtmf[0] = '\0';
- me->faxhandled =0;
-
- me->lastgrunt = ast_tvnow(); /* Assume at least one grunt tone seen now. */
- me->lastplay = ast_tvnow(); /* Assume at least one grunt tone seen now. */
-
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (state != AST_STATE_DOWN) {
- if ((me->mode != MODE_FXO)&&(state != AST_STATE_UP)){
- vpb_answer(tmp);
- }
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- }
- }
- } else {
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- }
- return tmp;
-}
-
-static struct ast_channel *vpb_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- struct vpb_pvt *p;
- struct ast_channel *tmp = NULL;
- char *name = strdup(data ? (char *)data : "");
- char *s, *sepstr;
- int group=-1;
-
- oldformat = format;
- format &= prefformat;
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", oldformat);
- return NULL;
- }
-
- sepstr = name;
- s = strsep(&sepstr, "/"); /* Handle / issues */
- if (!s)
- s = "";
- /* Check if we are looking for a group */
- if (toupper(name[0]) == 'G' || toupper(name[0])=='R') {
- group=atoi(name+1);
- }
- /* Search for an unowned channel */
- ast_mutex_lock(&iflock); {
- p = iflist;
- while(p) {
- if (group == -1){
- if (strncmp(s, p->dev + 4, sizeof p->dev) == 0) {
- if (!p->owner) {
- tmp = vpb_new(p, AST_STATE_DOWN, p->context);
- break;
- }
- }
- }
- else {
- if ((p->group == group) && (!p->owner)) {
- tmp = vpb_new(p, AST_STATE_DOWN, p->context);
- break;
- }
- }
- p = p->next;
- }
- } ast_mutex_unlock(&iflock);
-
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 " %s requested, got: [%s]\n",
- name, tmp ? tmp->name : "None");
-
- free(name);
-
- restart_monitor();
- return tmp;
-}
-
-static float parse_gain_value(char *gain_type, char *value)
-{
- float gain;
-
- /* try to scan number */
- if (sscanf(value, "%f", &gain) != 1)
- {
- ast_log(LOG_ERROR, "Invalid %s value '%s' in '%s' config\n", value, gain_type, config);
- return DEFAULT_GAIN;
- }
-
-
- /* percentage? */
- /*if (value[strlen(value) - 1] == '%') */
- /* return gain / (float)100; */
-
- return gain;
-}
-
-int load_module()
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- struct vpb_pvt *tmp;
- int board = 0, group = 0;
- ast_group_t callgroup = 0;
- ast_group_t pickupgroup = 0;
- int mode = MODE_IMMEDIATE;
- float txgain = DEFAULT_GAIN, rxgain = DEFAULT_GAIN;
- float txswgain = 0, rxswgain = 0;
- int got_gain=0;
- int first_channel = 1;
- int echo_cancel = DEFAULT_ECHO_CANCEL;
- int error = 0; /* Error flag */
- int bal1 = -1; /* Special value - means do not set */
- int bal2 = -1;
- int bal3 = -1;
- char * callerid = NULL;
-
- cfg = ast_config_load(config);
-
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_ERROR, "Unable to load config %s\n", config);
- return -1;
- }
-
- vpb_seterrormode(VPB_ERROR_CODE);
-
- ast_mutex_lock(&iflock); {
- v = ast_variable_browse(cfg, "general");
- while (v){
- if (strcasecmp(v->name, "cards") == 0) {
- ast_log(LOG_NOTICE,"VPB Driver configured to use [%d] cards\n",atoi(v->value));
- }
- else if (strcasecmp(v->name, "indication") == 0) {
- use_ast_ind = 1;
- ast_log(LOG_NOTICE,"VPB driver using Asterisk Indication functions!\n");
- }
- else if (strcasecmp(v->name, "break-for-dtmf") == 0) {
- if (ast_true(v->value)){
- break_for_dtmf = 1;
- }
- else {
- break_for_dtmf = 0;
- ast_log(LOG_NOTICE,"VPB driver not stopping for DTMF's in native bridge\n");
- }
- }
- else if (strcasecmp(v->name, "ast-dtmf") == 0) {
- use_ast_dtmf = 1;
- ast_log(LOG_NOTICE,"VPB driver using Asterisk DTMF play functions!\n");
- }
- else if (strcasecmp(v->name, "ast-dtmf-det") == 0) {
- use_ast_dtmfdet = 1;
- ast_log(LOG_NOTICE,"VPB driver using Asterisk DTMF detection functions!\n");
- }
- else if (strcasecmp(v->name, "relaxdtmf") == 0) {
- relaxdtmf = 1;
- ast_log(LOG_NOTICE,"VPB driver using Relaxed DTMF with Asterisk DTMF detections functions!\n");
- }
- else if (strcasecmp(v->name, "timer_period_ring") ==0) {
- timer_period_ring = atoi(v->value);
- }
- else if (strcasecmp(v->name, "ecsuppthres") ==0) {
- ec_supp_threshold = atoi(v->value);
- }
- else if (strcasecmp(v->name, "dtmfidd") ==0) {
- dtmf_idd = atoi(v->value);
- ast_log(LOG_NOTICE,"VPB Driver setting DTMF IDD to [%d]ms\n",dtmf_idd);
- }
- v = v->next;
- }
-
- v = ast_variable_browse(cfg, "interfaces");
- while(v) {
- /* Create the interface list */
- if (strcasecmp(v->name, "board") == 0) {
- board = atoi(v->value);
- } else if (strcasecmp(v->name, "group") == 0){
- group = atoi(v->value);
- } else if (strcasecmp(v->name, "callgroup") == 0){
- callgroup = ast_get_group(v->value);
- } else if (strcasecmp(v->name, "pickupgroup") == 0){
- pickupgroup = ast_get_group(v->value);
- } else if (strcasecmp(v->name, "usepolaritycid") == 0){
- UsePolarityCID = atoi(v->value);
- } else if (strcasecmp(v->name, "useloopdrop") == 0){
- UseLoopDrop = atoi(v->value);
- } else if (strcasecmp(v->name, "usenativebridge") == 0){
- UseNativeBridge = atoi(v->value);
- } else if (strcasecmp(v->name, "channel") == 0) {
- int channel = atoi(v->value);
- tmp = mkif(board, channel, mode, got_gain, txgain, rxgain, txswgain, rxswgain, bal1, bal2, bal3, callerid, echo_cancel,group,callgroup,pickupgroup);
- if (tmp) {
- if(first_channel) {
- mkbrd( tmp->vpb_model, echo_cancel );
- first_channel = 0;
- }
- tmp->next = iflist;
- iflist = tmp;
- } else {
- ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
- error = -1;
- goto done;
- }
- } else if (strcasecmp(v->name, "language") == 0) {
- strncpy(language, v->value, sizeof(language)-1);
- } else if (strcasecmp(v->name, "callerid") == 0) {
- callerid = strdup(v->value);
- } else if (strcasecmp(v->name, "mode") == 0) {
- if (strncasecmp(v->value, "di", 2) == 0)
- mode = MODE_DIALTONE;
- else if (strncasecmp(v->value, "im", 2) == 0)
- mode = MODE_IMMEDIATE;
- else if (strncasecmp(v->value, "fx", 2) == 0)
- mode = MODE_FXO;
- else
- ast_log(LOG_WARNING, "Unknown mode: %s\n", v->value);
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(context, v->value, sizeof(context)-1);
- } else if (!strcasecmp(v->name, "echocancel")) {
- if (!strcasecmp(v->value, "off"))
- echo_cancel = 0;
- } else if (strcasecmp(v->name, "txgain") == 0) {
- txswgain = parse_gain_value(v->name, v->value);
- got_gain |=VPB_GOT_TXSWG;
- } else if (strcasecmp(v->name, "rxgain") == 0) {
- rxswgain = parse_gain_value(v->name, v->value);
- got_gain |=VPB_GOT_RXSWG;
- } else if (strcasecmp(v->name, "txhwgain") == 0) {
- txgain = parse_gain_value(v->name, v->value);
- got_gain |=VPB_GOT_TXHWG;
- } else if (strcasecmp(v->name, "rxhwgain") == 0) {
- rxgain = parse_gain_value(v->name, v->value);
- got_gain |=VPB_GOT_RXHWG;
- } else if (strcasecmp(v->name, "bal1") == 0) {
- bal1 = strtol(v->value, NULL, 16);
- if(bal1<0 || bal1>255) {
- ast_log(LOG_WARNING, "Bad bal1 value: %d\n", bal1);
- bal1 = -1;
- }
- } else if (strcasecmp(v->name, "bal2") == 0) {
- bal2 = strtol(v->value, NULL, 16);
- if(bal2<0 || bal2>255) {
- ast_log(LOG_WARNING, "Bad bal2 value: %d\n", bal2);
- bal2 = -1;
- }
- } else if (strcasecmp(v->name, "bal3") == 0) {
- bal3 = strtol(v->value, NULL, 16);
- if(bal3<0 || bal3>255) {
- ast_log(LOG_WARNING, "Bad bal3 value: %d\n", bal3);
- bal3 = -1;
- }
- } else if (strcasecmp(v->name, "grunttimeout") == 0) {
- gruntdetect_timeout = 1000*atoi(v->value);
- }
- v = v->next;
- }
-
- if (gruntdetect_timeout < 1000)
- gruntdetect_timeout = 1000;
-
- done: (void)0;
- } ast_mutex_unlock(&iflock);
-
- ast_config_destroy(cfg);
-
- if (use_ast_ind == 1){
- if (!error && ast_channel_register(&vpb_tech_indicate) != 0) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- error = -1;
- }
- else {
- ast_log(LOG_NOTICE,"VPB driver Registered (w/AstIndication)\n");
- }
- }
- else {
- if (!error && ast_channel_register(&vpb_tech) != 0) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- error = -1;
- }
- else {
- ast_log(LOG_NOTICE,"VPB driver Registered )\n");
- }
- }
-
-
- if (error)
- unload_module();
- else
- restart_monitor(); /* And start the monitor for the first time */
-
- return error;
-}
-
-
-int unload_module()
-{
- struct vpb_pvt *p;
- /* First, take us out of the channel loop */
- if (use_ast_ind == 1){
- ast_channel_unregister(&vpb_tech_indicate);
- }
- else {
- ast_channel_unregister(&vpb_tech);
- }
-
- ast_mutex_lock(&iflock); {
- /* Hangup all interfaces if they have an owner */
- p = iflist;
- while(p) {
- if (p->owner)
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- p = p->next;
- }
- iflist = NULL;
- } ast_mutex_unlock(&iflock);
-
- ast_mutex_lock(&monlock); {
- if (mthreadactive > -1) {
- pthread_cancel(monitor_thread);
- pthread_join(monitor_thread, NULL);
- }
- mthreadactive = -2;
- } ast_mutex_unlock(&monlock);
-
- ast_mutex_lock(&iflock); {
- /* Destroy all the interfaces and free their memory */
-
- while(iflist) {
- p = iflist;
- ast_mutex_destroy(&p->lock);
- pthread_cancel(p->readthread);
- ast_mutex_destroy(&p->owner_lock);
- ast_mutex_destroy(&p->record_lock);
- ast_mutex_destroy(&p->play_lock);
- ast_mutex_destroy(&p->play_dtmf_lock);
- p->readthread = 0;
-
- vpb_close(p->handle);
-
- iflist = iflist->next;
-
- free(p);
- }
- iflist = NULL;
- } ast_mutex_unlock(&iflock);
-
- ast_mutex_lock(&bridge_lock); {
- memset(bridges, 0, sizeof bridges);
- } ast_mutex_unlock(&bridge_lock);
- ast_mutex_destroy(&bridge_lock);
- for(int i = 0; i < max_bridges; i++ ) {
- ast_mutex_destroy(&bridges[i].lock);
- ast_cond_destroy(&bridges[i].cond);
- }
- free(bridges);
-
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-/**/
-#if defined(__cplusplus) || defined(c_plusplus)
- }
-#endif
-/**/
diff --git a/1.2-netsec/channels/chan_zap.c b/1.2-netsec/channels/chan_zap.c
deleted file mode 100644
index 0a4f21b8e..000000000
--- a/1.2-netsec/channels/chan_zap.c
+++ /dev/null
@@ -1,11089 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Zaptel Pseudo TDM interface
- *
- * Connects to the zaptel telephony library as well as
- * libpri. Libpri is optional and needed only if you are
- * going to use ISDN connections.
- *
- * You need to install libraries before you attempt to compile
- * and install the zaptel channel.
- *
- * \par See also
- * \arg \ref Config_zap
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <string.h>
-#ifdef __NetBSD__
-#include <pthread.h>
-#include <signal.h>
-#else
-#include <sys/signal.h>
-#endif
-#include <errno.h>
-#include <stdlib.h>
-#if !defined(SOLARIS) && !defined(__FreeBSD__)
-#include <stdint.h>
-#endif
-#include <unistd.h>
-#include <sys/ioctl.h>
-#ifdef __linux__
-#include <linux/zaptel.h>
-#else
-#include <zaptel.h>
-#endif /* __linux__ */
-#include <math.h>
-#include <tonezone.h>
-#include <ctype.h>
-#ifdef ZAPATA_PRI
-#include <libpri.h>
-#ifndef PRI_USER_USER_TX
-#error "You need newer libpri"
-#endif
-#endif
-#ifdef ZAPATA_R2
-#include <libmfcr2.h>
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/file.h"
-#include "asterisk/ulaw.h"
-#include "asterisk/alaw.h"
-#include "asterisk/callerid.h"
-#include "asterisk/adsi.h"
-#include "asterisk/cli.h"
-#include "asterisk/cdr.h"
-#include "asterisk/features.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/say.h"
-#include "asterisk/tdd.h"
-#include "asterisk/app.h"
-#include "asterisk/dsp.h"
-#include "asterisk/astdb.h"
-#include "asterisk/manager.h"
-#include "asterisk/causes.h"
-#include "asterisk/term.h"
-#include "asterisk/utils.h"
-#include "asterisk/transcap.h"
-
-#ifndef ZT_SIG_EM_E1
-#error "Your zaptel is too old. please cvs update"
-#endif
-
-#ifndef ZT_TONEDETECT
-/* Work around older code with no tone detect */
-#define ZT_EVENT_DTMFDOWN 0
-#define ZT_EVENT_DTMFUP 0
-#endif
-
-/* define this to send PRI user-user information elements */
-#undef SUPPORT_USERUSER
-
-/*!
- * \note Define ZHONE_HACK to cause us to go off hook and then back on hook when
- * the user hangs up to reset the state machine so ring works properly.
- * This is used to be able to support kewlstart by putting the zhone in
- * groundstart mode since their forward disconnect supervision is entirely
- * broken even though their documentation says it isn't and their support
- * is entirely unwilling to provide any assistance with their channel banks
- * even though their web site says they support their products for life.
- */
-/* #define ZHONE_HACK */
-
-/*! \note
- * Define if you want to check the hook state for an FXO (FXS signalled) interface
- * before dialing on it. Certain FXO interfaces always think they're out of
- * service with this method however.
- */
-/* #define ZAP_CHECK_HOOKSTATE */
-
-/*! \brief Typically, how many rings before we should send Caller*ID */
-#define DEFAULT_CIDRINGS 1
-
-#define CHANNEL_PSEUDO -12
-
-#define AST_LAW(p) (((p)->law == ZT_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
-
-/*! \brief Signaling types that need to use MF detection should be placed in this macro */
-#define NEED_MFDETECT(p) (((p)->sig == SIG_FEATDMF) || ((p)->sig == SIG_FEATDMF_TA) || ((p)->sig == SIG_E911) || ((p)->sig == SIG_FEATB))
-
-static const char desc[] = "Zapata Telephony"
-#ifdef ZAPATA_PRI
- " w/PRI"
-#endif
-#ifdef ZAPATA_R2
- " w/R2"
-#endif
-;
-
-static const char tdesc[] = "Zapata Telephony Driver"
-#ifdef ZAPATA_PRI
- " w/PRI"
-#endif
-#ifdef ZAPATA_R2
- " w/R2"
-#endif
-;
-
-static const char type[] = "Zap";
-static const char config[] = "zapata.conf";
-
-#define SIG_EM ZT_SIG_EM
-#define SIG_EMWINK (0x0100000 | ZT_SIG_EM)
-#define SIG_FEATD (0x0200000 | ZT_SIG_EM)
-#define SIG_FEATDMF (0x0400000 | ZT_SIG_EM)
-#define SIG_FEATB (0x0800000 | ZT_SIG_EM)
-#define SIG_E911 (0x1000000 | ZT_SIG_EM)
-#define SIG_FEATDMF_TA (0x2000000 | ZT_SIG_EM)
-#define SIG_FXSLS ZT_SIG_FXSLS
-#define SIG_FXSGS ZT_SIG_FXSGS
-#define SIG_FXSKS ZT_SIG_FXSKS
-#define SIG_FXOLS ZT_SIG_FXOLS
-#define SIG_FXOGS ZT_SIG_FXOGS
-#define SIG_FXOKS ZT_SIG_FXOKS
-#define SIG_PRI ZT_SIG_CLEAR
-#define SIG_R2 ZT_SIG_CAS
-#define SIG_SF ZT_SIG_SF
-#define SIG_SFWINK (0x0100000 | ZT_SIG_SF)
-#define SIG_SF_FEATD (0x0200000 | ZT_SIG_SF)
-#define SIG_SF_FEATDMF (0x0400000 | ZT_SIG_SF)
-#define SIG_SF_FEATB (0x0800000 | ZT_SIG_SF)
-#define SIG_EM_E1 ZT_SIG_EM_E1
-#define SIG_GR303FXOKS (0x0100000 | ZT_SIG_FXOKS)
-#define SIG_GR303FXSKS (0x0100000 | ZT_SIG_FXSKS)
-
-#define NUM_SPANS 32
-#define NUM_DCHANS 4 /*!< No more than 4 d-channels */
-#define MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */
-
-#define CHAN_PSEUDO -2
-
-#define DCHAN_PROVISIONED (1 << 0)
-#define DCHAN_NOTINALARM (1 << 1)
-#define DCHAN_UP (1 << 2)
-
-#define DCHAN_AVAILABLE (DCHAN_PROVISIONED | DCHAN_NOTINALARM | DCHAN_UP)
-
-static char context[AST_MAX_CONTEXT] = "default";
-static char cid_num[256] = "";
-static char cid_name[256] = "";
-static char defaultcic[64] = "";
-static char defaultozz[64] = "";
-
-static char language[MAX_LANGUAGE] = "";
-static char musicclass[MAX_MUSICCLASS] = "";
-static char progzone[10]= "";
-
-static int usedistinctiveringdetection = 0;
-
-static int transfertobusy = 1;
-
-static int use_callerid = 1;
-static int cid_signalling = CID_SIG_BELL;
-static int cid_start = CID_START_RING;
-static int zaptrcallerid = 0;
-static int cur_signalling = -1;
-
-static ast_group_t cur_group = 0;
-static ast_group_t cur_callergroup = 0;
-static ast_group_t cur_pickupgroup = 0;
-static int relaxdtmf = 0;
-
-static int immediate = 0;
-
-static int stripmsd = 0;
-
-static int callwaiting = 0;
-
-static int callwaitingcallerid = 0;
-
-static int hidecallerid = 0;
-
-static int restrictcid = 0;
-
-static int use_callingpres = 0;
-
-static int callreturn = 0;
-
-static int threewaycalling = 0;
-
-static int transfer = 0;
-
-static int canpark = 0;
-
-static int cancallforward = 0;
-
-static float rxgain = 0.0;
-
-static float txgain = 0.0;
-
-static int tonezone = -1;
-
-static int echocancel;
-
-static int echotraining;
-
-static int pulse;
-
-static int echocanbridged = 0;
-
-static int busydetect = 0;
-
-static int busycount = 3;
-static int busy_tonelength = 0;
-static int busy_quietlength = 0;
-
-static int callprogress = 0;
-
-static char accountcode[AST_MAX_ACCOUNT_CODE] = "";
-
-static char mailbox[AST_MAX_EXTENSION];
-
-static int amaflags = 0;
-
-static int adsi = 0;
-
-static int numbufs = 4;
-
-static int cur_prewink = -1;
-static int cur_preflash = -1;
-static int cur_wink = -1;
-static int cur_flash = -1;
-static int cur_start = -1;
-static int cur_rxwink = -1;
-static int cur_rxflash = -1;
-static int cur_debounce = -1;
-static int cur_priexclusive = 0;
-
-static int priindication_oob = 0;
-
-#ifdef ZAPATA_PRI
-static int minunused = 2;
-static int minidle = 0;
-static char idleext[AST_MAX_EXTENSION];
-static char idledial[AST_MAX_EXTENSION];
-static int overlapdial = 0;
-static int facilityenable = 0;
-static char internationalprefix[10] = "";
-static char nationalprefix[10] = "";
-static char localprefix[20] = "";
-static char privateprefix[20] = "";
-static char unknownprefix[20] = "";
-static long resetinterval = 3600; /*!< How often (in seconds) to reset unused channels. Default 1 hour. */
-static struct ast_channel inuse = { "GR-303InUse" };
-#ifdef PRI_GETSET_TIMERS
-static int pritimers[PRI_MAX_TIMERS];
-#endif
-static int pridebugfd = -1;
-static char pridebugfilename[1024]="";
-#endif
-
-/*! \brief Wait up to 16 seconds for first digit (FXO logic) */
-static int firstdigittimeout = 16000;
-
-/*! \brief How long to wait for following digits (FXO logic) */
-static int gendigittimeout = 8000;
-
-/*! \brief How long to wait for an extra digit, if there is an ambiguous match */
-static int matchdigittimeout = 3000;
-
-static int usecnt =0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-/*! \brief Protect the interface list (of zt_pvt's) */
-AST_MUTEX_DEFINE_STATIC(iflock);
-
-
-static int ifcount = 0;
-
-#ifdef ZAPATA_PRI
-AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
-#endif
-
-/*! \brief Whether we answer on a Polarity Switch event */
-static int answeronpolarityswitch = 0;
-
-/*! \brief Whether we hang up on a Polarity Switch event */
-static int hanguponpolarityswitch = 0;
-
-/*! \brief How long (ms) to ignore Polarity Switch events after we answer a call */
-static int polarityonanswerdelay = 600;
-
-/*! \brief When to send the CallerID signals (rings) */
-static int sendcalleridafter = DEFAULT_CIDRINGS;
-
-/*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
- when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(monlock);
-
-/*! \brief This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
-
-static int restart_monitor(void);
-
-static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
-
-static int zt_sendtext(struct ast_channel *c, const char *text);
-
-/*! \brief Avoid the silly zt_getevent which ignores a bunch of events */
-static inline int zt_get_event(int fd)
-{
- int j;
- if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
- return j;
-}
-
-/*! \brief Avoid the silly zt_waitevent which ignores a bunch of events */
-static inline int zt_wait_event(int fd)
-{
- int i,j=0;
- i = ZT_IOMUX_SIGEVENT;
- if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
- if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
- return j;
-}
-
-/*! Chunk size to read -- we use 20ms chunks to make things happy. */
-#define READ_SIZE 160
-
-#define MASK_AVAIL (1 << 0) /*!< Channel available for PRI use */
-#define MASK_INUSE (1 << 1) /*!< Channel currently in use */
-
-#define CALLWAITING_SILENT_SAMPLES ( (300 * 8) / READ_SIZE) /*!< 300 ms */
-#define CALLWAITING_REPEAT_SAMPLES ( (10000 * 8) / READ_SIZE) /*!< 300 ms */
-#define CIDCW_EXPIRE_SAMPLES ( (500 * 8) / READ_SIZE) /*!< 500 ms */
-#define MIN_MS_SINCE_FLASH ( (2000) ) /*!< 2000 ms */
-#define DEFAULT_RINGT ( (8000 * 8) / READ_SIZE)
-
-struct zt_pvt;
-
-
-#ifdef ZAPATA_R2
-static int r2prot = -1;
-#endif
-
-static int ringt_base = DEFAULT_RINGT;
-
-#ifdef ZAPATA_PRI
-
-#define PVT_TO_CHANNEL(p) (((p)->prioffset) | ((p)->logicalspan << 8) | (p->pri->mastertrunkgroup ? 0x10000 : 0))
-#define PRI_CHANNEL(p) ((p) & 0xff)
-#define PRI_SPAN(p) (((p) >> 8) & 0xff)
-#define PRI_EXPLICIT(p) (((p) >> 16) & 0x01)
-
-struct zt_pri {
- pthread_t master; /*!< Thread of master */
- ast_mutex_t lock; /*!< Mutex */
- char idleext[AST_MAX_EXTENSION]; /*!< Where to idle extra calls */
- char idlecontext[AST_MAX_CONTEXT]; /*!< What context to use for idle */
- char idledial[AST_MAX_EXTENSION]; /*!< What to dial before dumping */
- int minunused; /*!< Min # of channels to keep empty */
- int minidle; /*!< Min # of "idling" calls to keep active */
- int nodetype; /*!< Node type */
- int switchtype; /*!< Type of switch to emulate */
- int nsf; /*!< Network-Specific Facilities */
- int dialplan; /*!< Dialing plan */
- int localdialplan; /*!< Local dialing plan */
- char internationalprefix[10]; /*!< country access code ('00' for european dialplans) */
- char nationalprefix[10]; /*!< area access code ('0' for european dialplans) */
- char localprefix[20]; /*!< area access code + area code ('0'+area code for european dialplans) */
- char privateprefix[20]; /*!< for private dialplans */
- char unknownprefix[20]; /*!< for unknown dialplans */
- int dchannels[NUM_DCHANS]; /*!< What channel are the dchannels on */
- int trunkgroup; /*!< What our trunkgroup is */
- int mastertrunkgroup; /*!< What trunk group is our master */
- int prilogicalspan; /*!< Logical span number within trunk group */
- int numchans; /*!< Num of channels we represent */
- int overlapdial; /*!< In overlap dialing mode */
- int facilityenable; /*!< Enable facility IEs */
- struct pri *dchans[NUM_DCHANS]; /*!< Actual d-channels */
- int dchanavail[NUM_DCHANS]; /*!< Whether each channel is available */
- struct pri *pri; /*!< Currently active D-channel */
- int debug;
- int fds[NUM_DCHANS]; /*!< FD's for d-channels */
- int offset;
- int span;
- int resetting;
- int resetpos;
- time_t lastreset; /*!< time when unused channels were last reset */
- long resetinterval; /*!< Interval (in seconds) for resetting unused channels */
- struct zt_pvt *pvts[MAX_CHANNELS]; /*!< Member channel pvt structs */
- struct zt_pvt *crvs; /*!< Member CRV structs */
- struct zt_pvt *crvend; /*!< Pointer to end of CRV structs */
-};
-
-
-static struct zt_pri pris[NUM_SPANS];
-
-static int pritype = PRI_CPE;
-
-#if 0
-#define DEFAULT_PRI_DEBUG (PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_STATE)
-#else
-#define DEFAULT_PRI_DEBUG 0
-#endif
-
-static inline void pri_rel(struct zt_pri *pri)
-{
- ast_mutex_unlock(&pri->lock);
-}
-
-static int switchtype = PRI_SWITCH_NI2;
-static int nsf = PRI_NSF_NONE;
-static int dialplan = PRI_NATIONAL_ISDN + 1;
-static int localdialplan = PRI_NATIONAL_ISDN + 1;
-
-#else
-/*! Shut up the compiler */
-struct zt_pri;
-#endif
-
-#define SUB_REAL 0 /*!< Active call */
-#define SUB_CALLWAIT 1 /*!< Call-Waiting call on hold */
-#define SUB_THREEWAY 2 /*!< Three-way call */
-
-/* Polarity states */
-#define POLARITY_IDLE 0
-#define POLARITY_REV 1
-
-
-static struct zt_distRings drings;
-
-struct distRingData {
- int ring[3];
-};
-struct ringContextData {
- char contextData[AST_MAX_CONTEXT];
-};
-struct zt_distRings {
- struct distRingData ringnum[3];
- struct ringContextData ringContext[3];
-};
-
-static char *subnames[] = {
- "Real",
- "Callwait",
- "Threeway"
-};
-
-struct zt_subchannel {
- int zfd;
- struct ast_channel *owner;
- int chan;
- short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
- struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
- unsigned int needringing:1;
- unsigned int needbusy:1;
- unsigned int needcongestion:1;
- unsigned int needcallerid:1;
- unsigned int needanswer:1;
- unsigned int needflash:1;
- unsigned int linear:1;
- unsigned int inthreeway:1;
- ZT_CONFINFO curconf;
-};
-
-#define CONF_USER_REAL (1 << 0)
-#define CONF_USER_THIRDCALL (1 << 1)
-
-#define MAX_SLAVES 4
-
-static struct zt_pvt {
- ast_mutex_t lock;
- struct ast_channel *owner; /*!< Our current active owner (if applicable) */
- /*!< Up to three channels can be associated with this call */
-
- struct zt_subchannel sub_unused; /*!< Just a safety precaution */
- struct zt_subchannel subs[3]; /*!< Sub-channels */
- struct zt_confinfo saveconf; /*!< Saved conference info */
-
- struct zt_pvt *slaves[MAX_SLAVES]; /*!< Slave to us (follows our conferencing) */
- struct zt_pvt *master; /*!< Master to us (we follow their conferencing) */
- int inconference; /*!< If our real should be in the conference */
-
- int sig; /*!< Signalling style */
- int radio; /*!< radio type */
- float rxgain;
- float txgain;
- int tonezone; /*!< tone zone for this chan, or -1 for default */
- struct zt_pvt *next; /*!< Next channel in list */
- struct zt_pvt *prev; /*!< Prev channel in list */
-
- /* flags */
- unsigned int adsi:1;
- unsigned int answeronpolarityswitch:1;
- unsigned int busydetect:1;
- unsigned int callreturn:1;
- unsigned int callwaiting:1;
- unsigned int callwaitingcallerid:1;
- unsigned int cancallforward:1;
- unsigned int canpark:1;
- unsigned int confirmanswer:1; /*!< Wait for '#' to confirm answer */
- unsigned int destroy:1;
- unsigned int didtdd:1; /*!< flag to say its done it once */
- unsigned int dialednone:1;
- unsigned int dialing:1;
- unsigned int digital:1;
- unsigned int dnd:1;
- unsigned int echobreak:1;
- unsigned int echocanbridged:1;
- unsigned int echocanon:1;
- unsigned int faxhandled:1; /*!< Has a fax tone already been handled? */
- unsigned int firstradio:1;
- unsigned int hanguponpolarityswitch:1;
- unsigned int hardwaredtmf:1;
- unsigned int hidecallerid;
- unsigned int ignoredtmf:1;
- unsigned int immediate:1; /*!< Answer before getting digits? */
- unsigned int inalarm:1;
- unsigned int mate:1; /*!< flag to say its in MATE mode */
- unsigned int outgoing:1;
- unsigned int overlapdial:1;
- unsigned int permcallwaiting:1;
- unsigned int permhidecallerid:1; /*!< Whether to hide our outgoing caller ID or not */
- unsigned int priindication_oob:1;
- unsigned int priexclusive:1;
- unsigned int pulse:1;
- unsigned int pulsedial:1; /*!< whether a pulse dial phone is detected */
- unsigned int restrictcid:1; /*!< Whether restrict the callerid -> only send ANI */
- unsigned int threewaycalling:1;
- unsigned int transfer:1;
- unsigned int use_callerid:1; /*!< Whether or not to use caller id on this channel */
- unsigned int use_callingpres:1; /*!< Whether to use the callingpres the calling switch sends */
- unsigned int usedistinctiveringdetection:1;
- unsigned int zaptrcallerid:1; /*!< should we use the callerid from incoming call on zap transfer or not */
- unsigned int transfertobusy:1; /*!< allow flash-transfers to busy channels */
-#if defined(ZAPATA_PRI)
- unsigned int alerting:1;
- unsigned int alreadyhungup:1;
- unsigned int isidlecall:1;
- unsigned int proceeding:1;
- unsigned int progress:1;
- unsigned int resetting:1;
- unsigned int setup_ack:1;
-#endif
-#if defined(ZAPATA_R2)
- unsigned int hasr2call:1;
- unsigned int r2blocked:1;
- unsigned int sigchecked:1;
-#endif
-
- struct zt_distRings drings;
-
- char context[AST_MAX_CONTEXT];
- char defcontext[AST_MAX_CONTEXT];
- char exten[AST_MAX_EXTENSION];
- char language[MAX_LANGUAGE];
- char musicclass[MAX_MUSICCLASS];
-#ifdef PRI_ANI
- char cid_ani[AST_MAX_EXTENSION];
-#endif
- char cid_num[AST_MAX_EXTENSION];
- int cid_ton; /*!< Type Of Number (TON) */
- char cid_name[AST_MAX_EXTENSION];
- char lastcid_num[AST_MAX_EXTENSION];
- char lastcid_name[AST_MAX_EXTENSION];
- char *origcid_num; /*!< malloced original callerid */
- char *origcid_name; /*!< malloced original callerid */
- char callwait_num[AST_MAX_EXTENSION];
- char callwait_name[AST_MAX_EXTENSION];
- char rdnis[AST_MAX_EXTENSION];
- char dnid[AST_MAX_EXTENSION];
- unsigned int group;
- int law;
- int confno; /*!< Our conference */
- int confusers; /*!< Who is using our conference */
- int propconfno; /*!< Propagated conference number */
- ast_group_t callgroup;
- ast_group_t pickupgroup;
- int channel; /*!< Channel Number or CRV */
- int span; /*!< Span number */
- time_t guardtime; /*!< Must wait this much time before using for new call */
- int cid_signalling; /*!< CID signalling type bell202 or v23 */
- int cid_start; /*!< CID start indicator, polarity or ring */
- int callingpres; /*!< The value of callling presentation that we're going to use when placing a PRI call */
- int callwaitingrepeat; /*!< How many samples to wait before repeating call waiting */
- int cidcwexpire; /*!< When to expire our muting for CID/CW */
- unsigned char *cidspill;
- int cidpos;
- int cidlen;
- int ringt;
- int ringt_base;
- int stripmsd;
- int callwaitcas;
- int callwaitrings;
- int echocancel;
- int echotraining;
- char echorest[20];
- int busycount;
- int busy_tonelength;
- int busy_quietlength;
- int callprogress;
- struct timeval flashtime; /*!< Last flash-hook time */
- struct ast_dsp *dsp;
- int cref; /*!< Call reference number */
- ZT_DIAL_OPERATION dop;
- int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
- char finaldial[64];
- char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
- int amaflags; /*!< AMA Flags */
- struct tdd_state *tdd; /*!< TDD flag */
- char call_forward[AST_MAX_EXTENSION];
- char mailbox[AST_MAX_EXTENSION];
- char dialdest[256];
- int onhooktime;
- int msgstate;
- int distinctivering; /*!< Which distinctivering to use */
- int cidrings; /*!< Which ring to deliver CID on */
- int dtmfrelax; /*!< whether to run in relaxed DTMF mode */
- int fake_event;
- int polarityonanswerdelay;
- struct timeval polaritydelaytv;
- int sendcalleridafter;
-#ifdef ZAPATA_PRI
- struct zt_pri *pri;
- struct zt_pvt *bearer;
- struct zt_pvt *realcall;
- q931_call *call;
- int prioffset;
- int logicalspan;
-#endif
-#ifdef ZAPATA_R2
- int r2prot;
- mfcr2_t *r2;
-#endif
- int polarity;
- int dsp_features;
-
-} *iflist = NULL, *ifend = NULL;
-
-static struct ast_channel *zt_request(const char *type, int format, void *data, int *cause);
-static int zt_digit(struct ast_channel *ast, char digit);
-static int zt_sendtext(struct ast_channel *c, const char *text);
-static int zt_call(struct ast_channel *ast, char *rdest, int timeout);
-static int zt_hangup(struct ast_channel *ast);
-static int zt_answer(struct ast_channel *ast);
-struct ast_frame *zt_read(struct ast_channel *ast);
-static int zt_write(struct ast_channel *ast, struct ast_frame *frame);
-struct ast_frame *zt_exception(struct ast_channel *ast);
-static int zt_indicate(struct ast_channel *chan, int condition);
-static int zt_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-static int zt_setoption(struct ast_channel *chan, int option, void *data, int datalen);
-
-static const struct ast_channel_tech zap_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_SLINEAR | AST_FORMAT_ULAW,
- .requester = zt_request,
- .send_digit = zt_digit,
- .send_text = zt_sendtext,
- .call = zt_call,
- .hangup = zt_hangup,
- .answer = zt_answer,
- .read = zt_read,
- .write = zt_write,
- .bridge = zt_bridge,
- .exception = zt_exception,
- .indicate = zt_indicate,
- .fixup = zt_fixup,
- .setoption = zt_setoption,
-};
-
-#ifdef ZAPATA_PRI
-#define GET_CHANNEL(p) ((p)->bearer ? (p)->bearer->channel : p->channel)
-#else
-#define GET_CHANNEL(p) ((p)->channel)
-#endif
-
-struct zt_pvt *round_robin[32];
-
-#ifdef ZAPATA_PRI
-static inline int pri_grab(struct zt_pvt *pvt, struct zt_pri *pri)
-{
- int res;
- /* Grab the lock first */
- do {
- res = ast_mutex_trylock(&pri->lock);
- if (res) {
- ast_mutex_unlock(&pvt->lock);
- /* Release the lock and try again */
- usleep(1);
- ast_mutex_lock(&pvt->lock);
- }
- } while(res);
- /* Then break the poll */
- pthread_kill(pri->master, SIGURG);
- return 0;
-}
-#endif
-
-#define NUM_CADENCE_MAX 25
-static int num_cadence = 4;
-static int user_has_defined_cadences = 0;
-
-static struct zt_ring_cadence cadences[NUM_CADENCE_MAX] = {
- { { 125, 125, 2000, 4000 } }, /*!< Quick chirp followed by normal ring */
- { { 250, 250, 500, 1000, 250, 250, 500, 4000 } }, /*!< British style ring */
- { { 125, 125, 125, 125, 125, 4000 } }, /*!< Three short bursts */
- { { 1000, 500, 2500, 5000 } }, /*!< Long ring */
-};
-
-int receivedRingT; /*!< Used to find out what ringtone we are on */
-
-/*! \brief cidrings says in which pause to transmit the cid information, where the first pause
- * is 1, the second pause is 2 and so on.
- */
-
-static int cidrings[NUM_CADENCE_MAX] = {
- 2, /*!< Right after first long ring */
- 4, /*!< Right after long part */
- 3, /*!< After third chirp */
- 2, /*!< Second spell */
-};
-
-#define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
- (p->sig == SIG_FXSGS) || (p->sig == SIG_PRI))
-
-#define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __ZT_SIG_FXO) */)
-#define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __ZT_SIG_FXO) */)
-
-static int zt_get_index(struct ast_channel *ast, struct zt_pvt *p, int nullok)
-{
- int res;
- if (p->subs[0].owner == ast)
- res = 0;
- else if (p->subs[1].owner == ast)
- res = 1;
- else if (p->subs[2].owner == ast)
- res = 2;
- else {
- res = -1;
- if (!nullok)
- ast_log(LOG_WARNING, "Unable to get index, and nullok is not asserted\n");
- }
- return res;
-}
-
-#ifdef ZAPATA_PRI
-static void wakeup_sub(struct zt_pvt *p, int a, struct zt_pri *pri)
-#else
-static void wakeup_sub(struct zt_pvt *p, int a, void *pri)
-#endif
-{
- struct ast_frame null = { AST_FRAME_NULL, };
-#ifdef ZAPATA_PRI
- if (pri)
- ast_mutex_unlock(&pri->lock);
-#endif
- for (;;) {
- if (p->subs[a].owner) {
- if (ast_mutex_trylock(&p->subs[a].owner->lock)) {
- ast_mutex_unlock(&p->lock);
- usleep(1);
- ast_mutex_lock(&p->lock);
- } else {
- ast_queue_frame(p->subs[a].owner, &null);
- ast_mutex_unlock(&p->subs[a].owner->lock);
- break;
- }
- } else
- break;
- }
-#ifdef ZAPATA_PRI
- if (pri)
- ast_mutex_lock(&pri->lock);
-#endif
-}
-
-#ifdef ZAPATA_PRI
-static void zap_queue_frame(struct zt_pvt *p, struct ast_frame *f, struct zt_pri *pri)
-#else
-static void zap_queue_frame(struct zt_pvt *p, struct ast_frame *f, void *pri)
-#endif
-{
- /* We must unlock the PRI to avoid the possibility of a deadlock */
-#ifdef ZAPATA_PRI
- if (pri)
- ast_mutex_unlock(&pri->lock);
-#endif
- for (;;) {
- if (p->owner) {
- if (ast_mutex_trylock(&p->owner->lock)) {
- ast_mutex_unlock(&p->lock);
- usleep(1);
- ast_mutex_lock(&p->lock);
- } else {
- ast_queue_frame(p->owner, f);
- ast_mutex_unlock(&p->owner->lock);
- break;
- }
- } else
- break;
- }
-#ifdef ZAPATA_PRI
- if (pri)
- ast_mutex_lock(&pri->lock);
-#endif
-}
-
-static int restore_gains(struct zt_pvt *p);
-
-static void swap_subs(struct zt_pvt *p, int a, int b)
-{
- int tchan;
- int tinthreeway;
- struct ast_channel *towner;
-
- ast_log(LOG_DEBUG, "Swapping %d and %d\n", a, b);
-
- tchan = p->subs[a].chan;
- towner = p->subs[a].owner;
- tinthreeway = p->subs[a].inthreeway;
-
- p->subs[a].chan = p->subs[b].chan;
- p->subs[a].owner = p->subs[b].owner;
- p->subs[a].inthreeway = p->subs[b].inthreeway;
-
- p->subs[b].chan = tchan;
- p->subs[b].owner = towner;
- p->subs[b].inthreeway = tinthreeway;
-
- if (p->subs[a].owner)
- p->subs[a].owner->fds[0] = p->subs[a].zfd;
- if (p->subs[b].owner)
- p->subs[b].owner->fds[0] = p->subs[b].zfd;
- wakeup_sub(p, a, NULL);
- wakeup_sub(p, b, NULL);
-}
-
-static int zt_open(char *fn)
-{
- int fd;
- int isnum;
- int chan = 0;
- int bs;
- int x;
- isnum = 1;
- for (x=0;x<strlen(fn);x++) {
- if (!isdigit(fn[x])) {
- isnum = 0;
- break;
- }
- }
- if (isnum) {
- chan = atoi(fn);
- if (chan < 1) {
- ast_log(LOG_WARNING, "Invalid channel number '%s'\n", fn);
- return -1;
- }
- fn = "/dev/zap/channel";
- }
- fd = open(fn, O_RDWR | O_NONBLOCK);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to open '%s': %s\n", fn, strerror(errno));
- return -1;
- }
- if (chan) {
- if (ioctl(fd, ZT_SPECIFY, &chan)) {
- x = errno;
- close(fd);
- errno = x;
- ast_log(LOG_WARNING, "Unable to specify channel %d: %s\n", chan, strerror(errno));
- return -1;
- }
- }
- bs = READ_SIZE;
- if (ioctl(fd, ZT_SET_BLOCKSIZE, &bs) == -1) return -1;
- return fd;
-}
-
-static void zt_close(int fd)
-{
- if(fd > 0)
- close(fd);
-}
-
-int zt_setlinear(int zfd, int linear)
-{
- int res;
- res = ioctl(zfd, ZT_SETLINEAR, &linear);
- if (res)
- return res;
- return 0;
-}
-
-
-int zt_setlaw(int zfd, int law)
-{
- int res;
- res = ioctl(zfd, ZT_SETLAW, &law);
- if (res)
- return res;
- return 0;
-}
-
-static int alloc_sub(struct zt_pvt *p, int x)
-{
- ZT_BUFFERINFO bi;
- int res;
- if (p->subs[x].zfd < 0) {
- p->subs[x].zfd = zt_open("/dev/zap/pseudo");
- if (p->subs[x].zfd > -1) {
- res = ioctl(p->subs[x].zfd, ZT_GET_BUFINFO, &bi);
- if (!res) {
- bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.numbufs = numbufs;
- res = ioctl(p->subs[x].zfd, ZT_SET_BUFINFO, &bi);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set buffer policy on channel %d\n", x);
- }
- } else
- ast_log(LOG_WARNING, "Unable to check buffer policy on channel %d\n", x);
- if (ioctl(p->subs[x].zfd, ZT_CHANNO, &p->subs[x].chan) == 1) {
- ast_log(LOG_WARNING,"Unable to get channel number for pseudo channel on FD %d\n",p->subs[x].zfd);
- zt_close(p->subs[x].zfd);
- p->subs[x].zfd = -1;
- return -1;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Allocated %s subchannel on FD %d channel %d\n", subnames[x], p->subs[x].zfd, p->subs[x].chan);
- return 0;
- } else
- ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
- return -1;
- }
- ast_log(LOG_WARNING, "%s subchannel of %d already in use\n", subnames[x], p->channel);
- return -1;
-}
-
-static int unalloc_sub(struct zt_pvt *p, int x)
-{
- if (!x) {
- ast_log(LOG_WARNING, "Trying to unalloc the real channel %d?!?\n", p->channel);
- return -1;
- }
- ast_log(LOG_DEBUG, "Released sub %d of channel %d\n", x, p->channel);
- if (p->subs[x].zfd > -1) {
- zt_close(p->subs[x].zfd);
- }
- p->subs[x].zfd = -1;
- p->subs[x].linear = 0;
- p->subs[x].chan = 0;
- p->subs[x].owner = NULL;
- p->subs[x].inthreeway = 0;
- p->polarity = POLARITY_IDLE;
- memset(&p->subs[x].curconf, 0, sizeof(p->subs[x].curconf));
- return 0;
-}
-
-static int zt_digit(struct ast_channel *ast, char digit)
-{
- ZT_DIAL_OPERATION zo;
- struct zt_pvt *p;
- int res = 0;
- int index;
- p = ast->tech_pvt;
- ast_mutex_lock(&p->lock);
- index = zt_get_index(ast, p, 0);
- if ((index == SUB_REAL) && p->owner) {
-#ifdef ZAPATA_PRI
- if ((p->sig == SIG_PRI) && (ast->_state == AST_STATE_DIALING) && !p->proceeding) {
- if (p->setup_ack) {
- if (!pri_grab(p, p->pri)) {
- pri_information(p->pri->pri,p->call,digit);
- pri_rel(p->pri);
- } else
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- } else if (strlen(p->dialdest) < sizeof(p->dialdest) - 1) {
- ast_log(LOG_DEBUG, "Queueing digit '%c' since setup_ack not yet received\n", digit);
- res = strlen(p->dialdest);
- p->dialdest[res++] = digit;
- p->dialdest[res] = '\0';
- }
- } else {
-#else
- {
-#endif
- zo.op = ZT_DIAL_OP_APPEND;
- zo.dialstr[0] = 'T';
- zo.dialstr[1] = digit;
- zo.dialstr[2] = 0;
- if ((res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &zo)))
- ast_log(LOG_WARNING, "Couldn't dial digit %c\n", digit);
- else
- p->dialing = 1;
- }
- }
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static char *events[] = {
- "No event",
- "On hook",
- "Ring/Answered",
- "Wink/Flash",
- "Alarm",
- "No more alarm",
- "HDLC Abort",
- "HDLC Overrun",
- "HDLC Bad FCS",
- "Dial Complete",
- "Ringer On",
- "Ringer Off",
- "Hook Transition Complete",
- "Bits Changed",
- "Pulse Start",
- "Timer Expired",
- "Timer Ping",
- "Polarity Reversal",
- "Ring Begin",
-};
-
-static struct {
- int alarm;
- char *name;
-} alarms[] = {
- { ZT_ALARM_RED, "Red Alarm" },
- { ZT_ALARM_YELLOW, "Yellow Alarm" },
- { ZT_ALARM_BLUE, "Blue Alarm" },
- { ZT_ALARM_RECOVER, "Recovering" },
- { ZT_ALARM_LOOPBACK, "Loopback" },
- { ZT_ALARM_NOTOPEN, "Not Open" },
- { ZT_ALARM_NONE, "None" },
-};
-
-static char *alarm2str(int alarm)
-{
- int x;
- for (x=0;x<sizeof(alarms) / sizeof(alarms[0]); x++) {
- if (alarms[x].alarm & alarm)
- return alarms[x].name;
- }
- return alarm ? "Unknown Alarm" : "No Alarm";
-}
-
-static char *event2str(int event)
-{
- static char buf[256];
- if ((event < (sizeof(events) / sizeof(events[0]))) && (event > -1))
- return events[event];
- sprintf(buf, "Event %d", event); /* safe */
- return buf;
-}
-
-#ifdef ZAPATA_PRI
-static char *dialplan2str(int dialplan)
-{
- if (dialplan == -1) {
- return("Dynamically set dialplan in ISDN");
- }
- return(pri_plan2str(dialplan));
-}
-#endif
-
-#ifdef ZAPATA_R2
-static int str2r2prot(char *swtype)
-{
- if (!strcasecmp(swtype, "ar"))
- return MFCR2_PROT_ARGENTINA;
- /*endif*/
- if (!strcasecmp(swtype, "cn"))
- return MFCR2_PROT_CHINA;
- /*endif*/
- if (!strcasecmp(swtype, "kr"))
- return MFCR2_PROT_KOREA;
- /*endif*/
- return -1;
-}
-#endif
-
-static char *zap_sig2str(int sig)
-{
- static char buf[256];
- switch(sig) {
- case SIG_EM:
- return "E & M Immediate";
- case SIG_EMWINK:
- return "E & M Wink";
- case SIG_EM_E1:
- return "E & M E1";
- case SIG_FEATD:
- return "Feature Group D (DTMF)";
- case SIG_FEATDMF:
- return "Feature Group D (MF)";
- case SIG_FEATDMF_TA:
- return "Feature Groud D (MF) Tandem Access";
- case SIG_FEATB:
- return "Feature Group B (MF)";
- case SIG_E911:
- return "E911 (MF)";
- case SIG_FXSLS:
- return "FXS Loopstart";
- case SIG_FXSGS:
- return "FXS Groundstart";
- case SIG_FXSKS:
- return "FXS Kewlstart";
- case SIG_FXOLS:
- return "FXO Loopstart";
- case SIG_FXOGS:
- return "FXO Groundstart";
- case SIG_FXOKS:
- return "FXO Kewlstart";
- case SIG_PRI:
- return "PRI Signalling";
- case SIG_R2:
- return "R2 Signalling";
- case SIG_SF:
- return "SF (Tone) Signalling Immediate";
- case SIG_SFWINK:
- return "SF (Tone) Signalling Wink";
- case SIG_SF_FEATD:
- return "SF (Tone) Signalling with Feature Group D (DTMF)";
- case SIG_SF_FEATDMF:
- return "SF (Tone) Signalling with Feature Group D (MF)";
- case SIG_SF_FEATB:
- return "SF (Tone) Signalling with Feature Group B (MF)";
- case SIG_GR303FXOKS:
- return "GR-303 Signalling with FXOKS";
- case SIG_GR303FXSKS:
- return "GR-303 Signalling with FXSKS";
- case 0:
- return "Pseudo Signalling";
- default:
- snprintf(buf, sizeof(buf), "Unknown signalling %d", sig);
- return buf;
- }
-}
-
-#define sig2str zap_sig2str
-
-static int conf_add(struct zt_pvt *p, struct zt_subchannel *c, int index, int slavechannel)
-{
- /* If the conference already exists, and we're already in it
- don't bother doing anything */
- ZT_CONFINFO zi;
-
- memset(&zi, 0, sizeof(zi));
- zi.chan = 0;
-
- if (slavechannel > 0) {
- /* If we have only one slave, do a digital mon */
- zi.confmode = ZT_CONF_DIGITALMON;
- zi.confno = slavechannel;
- } else {
- if (!index) {
- /* Real-side and pseudo-side both participate in conference */
- zi.confmode = ZT_CONF_REALANDPSEUDO | ZT_CONF_TALKER | ZT_CONF_LISTENER |
- ZT_CONF_PSEUDO_TALKER | ZT_CONF_PSEUDO_LISTENER;
- } else
- zi.confmode = ZT_CONF_CONF | ZT_CONF_TALKER | ZT_CONF_LISTENER;
- zi.confno = p->confno;
- }
- if ((zi.confno == c->curconf.confno) && (zi.confmode == c->curconf.confmode))
- return 0;
- if (c->zfd < 0)
- return 0;
- if (ioctl(c->zfd, ZT_SETCONF, &zi)) {
- ast_log(LOG_WARNING, "Failed to add %d to conference %d/%d\n", c->zfd, zi.confmode, zi.confno);
- return -1;
- }
- if (slavechannel < 1) {
- p->confno = zi.confno;
- }
- memcpy(&c->curconf, &zi, sizeof(c->curconf));
- ast_log(LOG_DEBUG, "Added %d to conference %d/%d\n", c->zfd, c->curconf.confmode, c->curconf.confno);
- return 0;
-}
-
-static int isourconf(struct zt_pvt *p, struct zt_subchannel *c)
-{
- /* If they're listening to our channel, they're ours */
- if ((p->channel == c->curconf.confno) && (c->curconf.confmode == ZT_CONF_DIGITALMON))
- return 1;
- /* If they're a talker on our (allocated) conference, they're ours */
- if ((p->confno > 0) && (p->confno == c->curconf.confno) && (c->curconf.confmode & ZT_CONF_TALKER))
- return 1;
- return 0;
-}
-
-static int conf_del(struct zt_pvt *p, struct zt_subchannel *c, int index)
-{
- ZT_CONFINFO zi;
- if (/* Can't delete if there's no zfd */
- (c->zfd < 0) ||
- /* Don't delete from the conference if it's not our conference */
- !isourconf(p, c)
- /* Don't delete if we don't think it's conferenced at all (implied) */
- ) return 0;
- memset(&zi, 0, sizeof(zi));
- zi.chan = 0;
- zi.confno = 0;
- zi.confmode = 0;
- if (ioctl(c->zfd, ZT_SETCONF, &zi)) {
- ast_log(LOG_WARNING, "Failed to drop %d from conference %d/%d\n", c->zfd, c->curconf.confmode, c->curconf.confno);
- return -1;
- }
- ast_log(LOG_DEBUG, "Removed %d from conference %d/%d\n", c->zfd, c->curconf.confmode, c->curconf.confno);
- memcpy(&c->curconf, &zi, sizeof(c->curconf));
- return 0;
-}
-
-static int isslavenative(struct zt_pvt *p, struct zt_pvt **out)
-{
- int x;
- int useslavenative;
- struct zt_pvt *slave = NULL;
- /* Start out optimistic */
- useslavenative = 1;
- /* Update conference state in a stateless fashion */
- for (x=0;x<3;x++) {
- /* Any three-way calling makes slave native mode *definitely* out
- of the question */
- if ((p->subs[x].zfd > -1) && p->subs[x].inthreeway)
- useslavenative = 0;
- }
- /* If we don't have any 3-way calls, check to see if we have
- precisely one slave */
- if (useslavenative) {
- for (x=0;x<MAX_SLAVES;x++) {
- if (p->slaves[x]) {
- if (slave) {
- /* Whoops already have a slave! No
- slave native and stop right away */
- slave = NULL;
- useslavenative = 0;
- break;
- } else {
- /* We have one slave so far */
- slave = p->slaves[x];
- }
- }
- }
- }
- /* If no slave, slave native definitely out */
- if (!slave)
- useslavenative = 0;
- else if (slave->law != p->law) {
- useslavenative = 0;
- slave = NULL;
- }
- if (out)
- *out = slave;
- return useslavenative;
-}
-
-static int reset_conf(struct zt_pvt *p)
-{
- ZT_CONFINFO zi;
- memset(&zi, 0, sizeof(zi));
- p->confno = -1;
- memset(&p->subs[SUB_REAL].curconf, 0, sizeof(p->subs[SUB_REAL].curconf));
- if (p->subs[SUB_REAL].zfd > -1) {
- if (ioctl(p->subs[SUB_REAL].zfd, ZT_SETCONF, &zi))
- ast_log(LOG_WARNING, "Failed to reset conferencing on channel %d!\n", p->channel);
- }
- return 0;
-}
-
-static int update_conf(struct zt_pvt *p)
-{
- int needconf = 0;
- int x;
- int useslavenative;
- struct zt_pvt *slave = NULL;
-
- useslavenative = isslavenative(p, &slave);
- /* Start with the obvious, general stuff */
- for (x=0;x<3;x++) {
- /* Look for three way calls */
- if ((p->subs[x].zfd > -1) && p->subs[x].inthreeway) {
- conf_add(p, &p->subs[x], x, 0);
- needconf++;
- } else {
- conf_del(p, &p->subs[x], x);
- }
- }
- /* If we have a slave, add him to our conference now. or DAX
- if this is slave native */
- for (x=0;x<MAX_SLAVES;x++) {
- if (p->slaves[x]) {
- if (useslavenative)
- conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
- else {
- conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0);
- needconf++;
- }
- }
- }
- /* If we're supposed to be in there, do so now */
- if (p->inconference && !p->subs[SUB_REAL].inthreeway) {
- if (useslavenative)
- conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave));
- else {
- conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0);
- needconf++;
- }
- }
- /* If we have a master, add ourselves to his conference */
- if (p->master) {
- if (isslavenative(p->master, NULL)) {
- conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master));
- } else {
- conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0);
- }
- }
- if (!needconf) {
- /* Nobody is left (or should be left) in our conference.
- Kill it. */
- p->confno = -1;
- }
- ast_log(LOG_DEBUG, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf);
- return 0;
-}
-
-static void zt_enable_ec(struct zt_pvt *p)
-{
- int x;
- int res;
- if (!p)
- return;
- if (p->echocanon) {
- ast_log(LOG_DEBUG, "Echo cancellation already on\n");
- return;
- }
- if (p->digital) {
- ast_log(LOG_DEBUG, "Echo cancellation isn't required on digital connection\n");
- return;
- }
- if (p->echocancel) {
- if (p->sig == SIG_PRI) {
- x = 1;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &x);
- if (res)
- ast_log(LOG_WARNING, "Unable to enable echo cancellation on channel %d\n", p->channel);
- }
- x = p->echocancel;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_ECHOCANCEL, &x);
- if (res)
- ast_log(LOG_WARNING, "Unable to enable echo cancellation on channel %d\n", p->channel);
- else {
- p->echocanon = 1;
- ast_log(LOG_DEBUG, "Enabled echo cancellation on channel %d\n", p->channel);
- }
- } else
- ast_log(LOG_DEBUG, "No echo cancellation requested\n");
-}
-
-static void zt_train_ec(struct zt_pvt *p)
-{
- int x;
- int res;
- if (p && p->echocancel && p->echotraining) {
- x = p->echotraining;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_ECHOTRAIN, &x);
- if (res)
- ast_log(LOG_WARNING, "Unable to request echo training on channel %d\n", p->channel);
- else {
- ast_log(LOG_DEBUG, "Engaged echo training on channel %d\n", p->channel);
- }
- } else
- ast_log(LOG_DEBUG, "No echo training requested\n");
-}
-
-static void zt_disable_ec(struct zt_pvt *p)
-{
- int x;
- int res;
- if (p->echocancel) {
- x = 0;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_ECHOCANCEL, &x);
- if (res)
- ast_log(LOG_WARNING, "Unable to disable echo cancellation on channel %d\n", p->channel);
- else
- ast_log(LOG_DEBUG, "disabled echo cancellation on channel %d\n", p->channel);
- }
- p->echocanon = 0;
-}
-
-static void fill_txgain(struct zt_gains *g, float gain, int law)
-{
- int j;
- int k;
- float linear_gain = pow(10.0, gain / 20.0);
-
- switch (law) {
- case ZT_LAW_ALAW:
- for (j = 0; j < (sizeof(g->txgain) / sizeof(g->txgain[0])); j++) {
- if (gain) {
- k = (int) (((float) AST_ALAW(j)) * linear_gain);
- if (k > 32767) k = 32767;
- if (k < -32767) k = -32767;
- g->txgain[j] = AST_LIN2A(k);
- } else {
- g->txgain[j] = j;
- }
- }
- break;
- case ZT_LAW_MULAW:
- for (j = 0; j < (sizeof(g->txgain) / sizeof(g->txgain[0])); j++) {
- if (gain) {
- k = (int) (((float) AST_MULAW(j)) * linear_gain);
- if (k > 32767) k = 32767;
- if (k < -32767) k = -32767;
- g->txgain[j] = AST_LIN2MU(k);
- } else {
- g->txgain[j] = j;
- }
- }
- break;
- }
-}
-
-static void fill_rxgain(struct zt_gains *g, float gain, int law)
-{
- int j;
- int k;
- float linear_gain = pow(10.0, gain / 20.0);
-
- switch (law) {
- case ZT_LAW_ALAW:
- for (j = 0; j < (sizeof(g->rxgain) / sizeof(g->rxgain[0])); j++) {
- if (gain) {
- k = (int) (((float) AST_ALAW(j)) * linear_gain);
- if (k > 32767) k = 32767;
- if (k < -32767) k = -32767;
- g->rxgain[j] = AST_LIN2A(k);
- } else {
- g->rxgain[j] = j;
- }
- }
- break;
- case ZT_LAW_MULAW:
- for (j = 0; j < (sizeof(g->rxgain) / sizeof(g->rxgain[0])); j++) {
- if (gain) {
- k = (int) (((float) AST_MULAW(j)) * linear_gain);
- if (k > 32767) k = 32767;
- if (k < -32767) k = -32767;
- g->rxgain[j] = AST_LIN2MU(k);
- } else {
- g->rxgain[j] = j;
- }
- }
- break;
- }
-}
-
-int set_actual_txgain(int fd, int chan, float gain, int law)
-{
- struct zt_gains g;
- int res;
-
- memset(&g, 0, sizeof(g));
- g.chan = chan;
- res = ioctl(fd, ZT_GETGAINS, &g);
- if (res) {
- ast_log(LOG_DEBUG, "Failed to read gains: %s\n", strerror(errno));
- return res;
- }
-
- fill_txgain(&g, gain, law);
-
- return ioctl(fd, ZT_SETGAINS, &g);
-}
-
-int set_actual_rxgain(int fd, int chan, float gain, int law)
-{
- struct zt_gains g;
- int res;
-
- memset(&g, 0, sizeof(g));
- g.chan = chan;
- res = ioctl(fd, ZT_GETGAINS, &g);
- if (res) {
- ast_log(LOG_DEBUG, "Failed to read gains: %s\n", strerror(errno));
- return res;
- }
-
- fill_rxgain(&g, gain, law);
-
- return ioctl(fd, ZT_SETGAINS, &g);
-}
-
-int set_actual_gain(int fd, int chan, float rxgain, float txgain, int law)
-{
- return set_actual_txgain(fd, chan, txgain, law) | set_actual_rxgain(fd, chan, rxgain, law);
-}
-
-static int bump_gains(struct zt_pvt *p)
-{
- int res;
-
- /* Bump receive gain by 5.0db */
- res = set_actual_gain(p->subs[SUB_REAL].zfd, 0, p->rxgain + 5.0, p->txgain, p->law);
- if (res) {
- ast_log(LOG_WARNING, "Unable to bump gain: %s\n", strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-static int restore_gains(struct zt_pvt *p)
-{
- int res;
-
- res = set_actual_gain(p->subs[SUB_REAL].zfd, 0, p->rxgain, p->txgain, p->law);
- if (res) {
- ast_log(LOG_WARNING, "Unable to restore gains: %s\n", strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-static inline int zt_set_hook(int fd, int hs)
-{
- int x, res;
- x = hs;
- res = ioctl(fd, ZT_HOOK, &x);
- if (res < 0)
- {
- if (errno == EINPROGRESS) return 0;
- ast_log(LOG_WARNING, "zt hook failed: %s\n", strerror(errno));
- }
- return res;
-}
-
-static inline int zt_confmute(struct zt_pvt *p, int muted)
-{
- int x, y, res;
- x = muted;
- if (p->sig == SIG_PRI) {
- y = 1;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &y);
- if (res)
- ast_log(LOG_WARNING, "Unable to set audio mode on '%d'\n", p->channel);
- }
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_CONFMUTE, &x);
- if (res < 0)
- ast_log(LOG_WARNING, "zt confmute(%d) failed on channel %d: %s\n", muted, p->channel, strerror(errno));
- return res;
-}
-
-static int save_conference(struct zt_pvt *p)
-{
- struct zt_confinfo c;
- int res;
- if (p->saveconf.confmode) {
- ast_log(LOG_WARNING, "Can't save conference -- already in use\n");
- return -1;
- }
- p->saveconf.chan = 0;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_GETCONF, &p->saveconf);
- if (res) {
- ast_log(LOG_WARNING, "Unable to get conference info: %s\n", strerror(errno));
- p->saveconf.confmode = 0;
- return -1;
- }
- c.chan = 0;
- c.confno = 0;
- c.confmode = ZT_CONF_NORMAL;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_SETCONF, &c);
- if (res) {
- ast_log(LOG_WARNING, "Unable to set conference info: %s\n", strerror(errno));
- return -1;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Disabled conferencing\n");
- return 0;
-}
-
-static int restore_conference(struct zt_pvt *p)
-{
- int res;
- if (p->saveconf.confmode) {
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_SETCONF, &p->saveconf);
- p->saveconf.confmode = 0;
- if (res) {
- ast_log(LOG_WARNING, "Unable to restore conference info: %s\n", strerror(errno));
- return -1;
- }
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Restored conferencing\n");
- return 0;
-}
-
-static int send_callerid(struct zt_pvt *p);
-
-int send_cwcidspill(struct zt_pvt *p)
-{
- p->callwaitcas = 0;
- p->cidcwexpire = 0;
- p->cidspill = malloc(MAX_CALLERID_SIZE);
- if (p->cidspill) {
- memset(p->cidspill, 0x7f, MAX_CALLERID_SIZE);
- p->cidlen = ast_callerid_callwaiting_generate(p->cidspill, p->callwait_name, p->callwait_num, AST_LAW(p));
- /* Make sure we account for the end */
- p->cidlen += READ_SIZE * 4;
- p->cidpos = 0;
- send_callerid(p);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CPE supports Call Waiting Caller*ID. Sending '%s/%s'\n", p->callwait_name, p->callwait_num);
- } else return -1;
- return 0;
-}
-
-static int has_voicemail(struct zt_pvt *p)
-{
-
- return ast_app_has_voicemail(p->mailbox, NULL);
-}
-
-static int send_callerid(struct zt_pvt *p)
-{
- /* Assumes spill in p->cidspill, p->cidlen in length and we're p->cidpos into it */
- int res;
- /* Take out of linear mode if necessary */
- if (p->subs[SUB_REAL].linear) {
- p->subs[SUB_REAL].linear = 0;
- zt_setlinear(p->subs[SUB_REAL].zfd, 0);
- }
- while(p->cidpos < p->cidlen) {
- res = write(p->subs[SUB_REAL].zfd, p->cidspill + p->cidpos, p->cidlen - p->cidpos);
- if (res < 0) {
- if (errno == EAGAIN)
- return 0;
- else {
- ast_log(LOG_WARNING, "write failed: %s\n", strerror(errno));
- return -1;
- }
- }
- if (!res)
- return 0;
- p->cidpos += res;
- }
- free(p->cidspill);
- p->cidspill = NULL;
- if (p->callwaitcas) {
- /* Wait for CID/CW to expire */
- p->cidcwexpire = CIDCW_EXPIRE_SAMPLES;
- } else
- restore_conference(p);
- return 0;
-}
-
-static int zt_callwait(struct ast_channel *ast)
-{
- struct zt_pvt *p = ast->tech_pvt;
- p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
- if (p->cidspill) {
- ast_log(LOG_WARNING, "Spill already exists?!?\n");
- free(p->cidspill);
- }
- p->cidspill = malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4);
- if (p->cidspill) {
- save_conference(p);
- /* Silence */
- memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
- if (!p->callwaitrings && p->callwaitingcallerid) {
- ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p));
- p->callwaitcas = 1;
- p->cidlen = 2400 + 680 + READ_SIZE * 4;
- } else {
- ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p));
- p->callwaitcas = 0;
- p->cidlen = 2400 + READ_SIZE * 4;
- }
- p->cidpos = 0;
- send_callerid(p);
- } else {
- ast_log(LOG_WARNING, "Unable to create SAS/CAS spill\n");
- return -1;
- }
- return 0;
-}
-
-static int zt_call(struct ast_channel *ast, char *rdest, int timeout)
-{
- struct zt_pvt *p = ast->tech_pvt;
- int x, res, index;
- char *c, *n, *l;
-#ifdef ZAPATA_PRI
- char *s=NULL;
-#endif
- char dest[256]; /* must be same length as p->dialdest */
- ast_mutex_lock(&p->lock);
- ast_copy_string(dest, rdest, sizeof(dest));
- ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
- if ((ast->_state == AST_STATE_BUSY)) {
- p->subs[SUB_REAL].needbusy = 1;
- ast_mutex_unlock(&p->lock);
- return 0;
- }
- if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "zt_call called on %s, neither down nor reserved\n", ast->name);
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- p->dialednone = 0;
- if (p->radio) /* if a radio channel, up immediately */
- {
- /* Special pseudo -- automatically up */
- ast_setstate(ast, AST_STATE_UP);
- ast_mutex_unlock(&p->lock);
- return 0;
- }
- x = ZT_FLUSH_READ | ZT_FLUSH_WRITE;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_FLUSH, &x);
- if (res)
- ast_log(LOG_WARNING, "Unable to flush input on channel %d\n", p->channel);
- p->outgoing = 1;
-
- set_actual_gain(p->subs[SUB_REAL].zfd, 0, p->rxgain, p->txgain, p->law);
-
- switch(p->sig) {
- case SIG_FXOLS:
- case SIG_FXOGS:
- case SIG_FXOKS:
- if (p->owner == ast) {
- /* Normal ring, on hook */
-
- /* Don't send audio while on hook, until the call is answered */
- p->dialing = 1;
- if (p->use_callerid) {
- /* Generate the Caller-ID spill if desired */
- if (p->cidspill) {
- ast_log(LOG_WARNING, "cidspill already exists??\n");
- free(p->cidspill);
- }
- p->cidspill = malloc(MAX_CALLERID_SIZE);
- p->callwaitcas = 0;
- if (p->cidspill) {
- p->cidlen = ast_callerid_generate(p->cidspill, ast->cid.cid_name, ast->cid.cid_num, AST_LAW(p));
- p->cidpos = 0;
- send_callerid(p);
- } else
- ast_log(LOG_WARNING, "Unable to generate CallerID spill\n");
- }
- /* Choose proper cadence */
- if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
- if (ioctl(p->subs[SUB_REAL].zfd, ZT_SETCADENCE, &cadences[p->distinctivering-1]))
- ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s'\n", p->distinctivering, ast->name);
- p->cidrings = cidrings[p->distinctivering - 1];
- } else {
- if (ioctl(p->subs[SUB_REAL].zfd, ZT_SETCADENCE, NULL))
- ast_log(LOG_WARNING, "Unable to reset default ring on '%s'\n", ast->name);
- p->cidrings = p->sendcalleridafter;
- }
-
-
- /* nick@dccinc.com 4/3/03 mods to allow for deferred dialing */
- c = strchr(dest, '/');
- if (c)
- c++;
- if (c && (strlen(c) < p->stripmsd)) {
- ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
- c = NULL;
- }
- if (c) {
- p->dop.op = ZT_DIAL_OP_REPLACE;
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c);
- ast_log(LOG_DEBUG, "FXO: setup deferred dialstring: %s\n", c);
- } else {
- p->dop.dialstr[0] = '\0';
- }
- x = ZT_RING;
- if (ioctl(p->subs[SUB_REAL].zfd, ZT_HOOK, &x) && (errno != EINPROGRESS)) {
- ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- p->dialing = 1;
- } else {
- /* Call waiting call */
- p->callwaitrings = 0;
- if (ast->cid.cid_num)
- ast_copy_string(p->callwait_num, ast->cid.cid_num, sizeof(p->callwait_num));
- else
- p->callwait_num[0] = '\0';
- if (ast->cid.cid_name)
- ast_copy_string(p->callwait_name, ast->cid.cid_name, sizeof(p->callwait_name));
- else
- p->callwait_name[0] = '\0';
- /* Call waiting tone instead */
- if (zt_callwait(ast)) {
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- /* Make ring-back */
- if (tone_zone_play_tone(p->subs[SUB_CALLWAIT].zfd, ZT_TONE_RINGTONE))
- ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast->name);
-
- }
- n = ast->cid.cid_name;
- l = ast->cid.cid_num;
- if (l)
- ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
- else
- p->lastcid_num[0] = '\0';
- if (n)
- ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
- else
- p->lastcid_name[0] = '\0';
- ast_setstate(ast, AST_STATE_RINGING);
- index = zt_get_index(ast, p, 0);
- if (index > -1) {
- p->subs[index].needringing = 1;
- }
- break;
- case SIG_FXSLS:
- case SIG_FXSGS:
- case SIG_FXSKS:
- case SIG_EMWINK:
- case SIG_EM:
- case SIG_EM_E1:
- case SIG_FEATD:
- case SIG_FEATDMF:
- case SIG_E911:
- case SIG_FEATB:
- case SIG_SFWINK:
- case SIG_SF:
- case SIG_SF_FEATD:
- case SIG_SF_FEATDMF:
- case SIG_FEATDMF_TA:
- case SIG_SF_FEATB:
- c = strchr(dest, '/');
- if (c)
- c++;
- else
- c = "";
- if (strlen(c) < p->stripmsd) {
- ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
- ast_mutex_unlock(&p->lock);
- return -1;
- }
-#ifdef ZAPATA_PRI
- /* Start the trunk, if not GR-303 */
- if (!p->pri) {
-#endif
- x = ZT_START;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_HOOK, &x);
- if (res < 0) {
- if (errno != EINPROGRESS) {
- ast_log(LOG_WARNING, "Unable to start channel: %s\n", strerror(errno));
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- }
-#ifdef ZAPATA_PRI
- }
-#endif
- ast_log(LOG_DEBUG, "Dialing '%s'\n", c);
- p->dop.op = ZT_DIAL_OP_REPLACE;
-
- c += p->stripmsd;
-
- switch (p->sig) {
- case SIG_FEATD:
- l = ast->cid.cid_num;
- if (l)
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c);
- else
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c);
- break;
- case SIG_FEATDMF:
- l = ast->cid.cid_num;
- if (l)
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c);
- else
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c);
- break;
- case SIG_FEATDMF_TA:
- {
- char *cic = NULL, *ozz = NULL;
-
- /* If you have to go through a Tandem Access point you need to use this */
- ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
- if (!ozz)
- ozz = defaultozz;
- cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC");
- if (!cic)
- cic = defaultcic;
- if (!ozz || !cic) {
- ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic);
- snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c);
- p->whichwink = 0;
- }
- break;
- case SIG_E911:
- ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
- break;
- case SIG_FEATB:
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c);
- break;
- default:
- if (p->pulse)
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c);
- else
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c);
- break;
- }
-
- if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
- memset(p->echorest, 'w', sizeof(p->echorest) - 1);
- strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
- p->echorest[sizeof(p->echorest) - 1] = '\0';
- p->echobreak = 1;
- p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
- } else
- p->echobreak = 0;
- if (!res) {
- if (ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop)) {
- x = ZT_ONHOOK;
- ioctl(p->subs[SUB_REAL].zfd, ZT_HOOK, &x);
- ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(errno));
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- } else
- ast_log(LOG_DEBUG, "Deferring dialing...\n");
- p->dialing = 1;
- if (ast_strlen_zero(c))
- p->dialednone = 1;
- ast_setstate(ast, AST_STATE_DIALING);
- break;
- case 0:
- /* Special pseudo -- automatically up*/
- ast_setstate(ast, AST_STATE_UP);
- break;
- case SIG_PRI:
- /* We'll get it in a moment -- but use dialdest to store pre-setup_ack digits */
- p->dialdest[0] = '\0';
- break;
- default:
- ast_log(LOG_DEBUG, "not yet implemented\n");
- ast_mutex_unlock(&p->lock);
- return -1;
- }
-#ifdef ZAPATA_PRI
- if (p->pri) {
- struct pri_sr *sr;
-#ifdef SUPPORT_USERUSER
- char *useruser;
-#endif
- int pridialplan;
- int dp_strip;
- int prilocaldialplan;
- int ldp_strip;
- int exclusive;
-
- c = strchr(dest, '/');
- if (c)
- c++;
- else
- c = dest;
- if (!p->hidecallerid) {
- l = ast->cid.cid_num;
- n = ast->cid.cid_name;
- } else {
- l = NULL;
- n = NULL;
- }
- if (strlen(c) < p->stripmsd) {
- ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- if (p->sig != SIG_FXSKS) {
- p->dop.op = ZT_DIAL_OP_REPLACE;
- s = strchr(c + p->stripmsd, 'w');
- if (s) {
- if (strlen(s) > 1)
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%s", s);
- else
- p->dop.dialstr[0] = '\0';
- *s = '\0';
- } else {
- p->dop.dialstr[0] = '\0';
- }
- }
- if (pri_grab(p, p->pri)) {
- ast_log(LOG_WARNING, "Failed to grab PRI!\n");
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- if (!(p->call = pri_new_call(p->pri->pri))) {
- ast_log(LOG_WARNING, "Unable to create call on channel %d\n", p->channel);
- pri_rel(p->pri);
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- if (!(sr = pri_sr_new())) {
- ast_log(LOG_WARNING, "Failed to allocate setup request channel %d\n", p->channel);
- pri_rel(p->pri);
- ast_mutex_unlock(&p->lock);
- }
- if (p->bearer || (p->sig == SIG_FXSKS)) {
- if (p->bearer) {
- ast_log(LOG_DEBUG, "Oooh, I have a bearer on %d (%d:%d)\n", PVT_TO_CHANNEL(p->bearer), p->bearer->logicalspan, p->bearer->channel);
- p->bearer->call = p->call;
- } else
- ast_log(LOG_DEBUG, "I'm being setup with no bearer right now...\n");
- pri_set_crv(p->pri->pri, p->call, p->channel, 0);
- }
- p->digital = IS_DIGITAL(ast->transfercapability);
- /* Add support for exclusive override */
- if (p->priexclusive)
- exclusive = 1;
- else {
- /* otherwise, traditional behavior */
- if (p->pri->nodetype == PRI_NETWORK)
- exclusive = 0;
- else
- exclusive = 1;
- }
-
- pri_sr_set_channel(sr, p->bearer ? PVT_TO_CHANNEL(p->bearer) : PVT_TO_CHANNEL(p), exclusive, 1);
- pri_sr_set_bearer(sr, p->digital ? PRI_TRANS_CAP_DIGITAL : ast->transfercapability,
- (p->digital ? -1 :
- ((p->law == ZT_LAW_ALAW) ? PRI_LAYER_1_ALAW : PRI_LAYER_1_ULAW)));
- if (p->pri->facilityenable)
- pri_facility_enable(p->pri->pri);
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Requested transfer capability: 0x%.2x - %s\n", ast->transfercapability, ast_transfercapability2str(ast->transfercapability));
- dp_strip = 0;
- pridialplan = p->pri->dialplan - 1;
- if (pridialplan == -2) { /* compute dynamically */
- if (strncmp(c + p->stripmsd, p->pri->internationalprefix, strlen(p->pri->internationalprefix)) == 0) {
- dp_strip = strlen(p->pri->internationalprefix);
- pridialplan = PRI_INTERNATIONAL_ISDN;
- } else if (strncmp(c + p->stripmsd, p->pri->nationalprefix, strlen(p->pri->nationalprefix)) == 0) {
- dp_strip = strlen(p->pri->nationalprefix);
- pridialplan = PRI_NATIONAL_ISDN;
- } else {
- pridialplan = PRI_LOCAL_ISDN;
- }
- }
- pri_sr_set_called(sr, c + p->stripmsd + dp_strip, pridialplan, s ? 1 : 0);
-
- ldp_strip = 0;
- prilocaldialplan = p->pri->localdialplan - 1;
- if ((l != NULL) && (prilocaldialplan == -2)) { /* compute dynamically */
- if (strncmp(l, p->pri->internationalprefix, strlen(p->pri->internationalprefix)) == 0) {
- ldp_strip = strlen(p->pri->internationalprefix);
- prilocaldialplan = PRI_INTERNATIONAL_ISDN;
- } else if (strncmp(l, p->pri->nationalprefix, strlen(p->pri->nationalprefix)) == 0) {
- ldp_strip = strlen(p->pri->nationalprefix);
- prilocaldialplan = PRI_NATIONAL_ISDN;
- } else {
- prilocaldialplan = PRI_LOCAL_ISDN;
- }
- }
- pri_sr_set_caller(sr, l ? (l + ldp_strip) : NULL, n, prilocaldialplan,
- l ? (p->use_callingpres ? ast->cid.cid_pres : PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN) :
- PRES_NUMBER_NOT_AVAILABLE);
- pri_sr_set_redirecting(sr, ast->cid.cid_rdnis, p->pri->localdialplan - 1, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
-
-#ifdef SUPPORT_USERUSER
- /* User-user info */
- useruser = pbx_builtin_getvar_helper(p->owner, "USERUSERINFO");
-
- if (useruser)
- pri_sr_set_useruser(sr, useruser);
-#endif
-
- if (pri_setup(p->pri->pri, p->call, sr)) {
- ast_log(LOG_WARNING, "Unable to setup call to %s (using %s)\n",
- c + p->stripmsd + dp_strip, dialplan2str(p->pri->dialplan));
- pri_rel(p->pri);
- ast_mutex_unlock(&p->lock);
- pri_sr_free(sr);
- return -1;
- }
- pri_sr_free(sr);
- ast_setstate(ast, AST_STATE_DIALING);
- pri_rel(p->pri);
- }
-#endif
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-static void destroy_zt_pvt(struct zt_pvt **pvt)
-{
- struct zt_pvt *p = *pvt;
- /* Remove channel from the list */
- if(p->prev)
- p->prev->next = p->next;
- if(p->next)
- p->next->prev = p->prev;
- ast_mutex_destroy(&p->lock);
- free(p);
- *pvt = NULL;
-}
-
-static int destroy_channel(struct zt_pvt *prev, struct zt_pvt *cur, int now)
-{
- int owned = 0;
- int i = 0;
-
- if (!now) {
- if (cur->owner) {
- owned = 1;
- }
-
- for (i = 0; i < 3; i++) {
- if (cur->subs[i].owner) {
- owned = 1;
- }
- }
- if (!owned) {
- if (prev) {
- prev->next = cur->next;
- if (prev->next)
- prev->next->prev = prev;
- else
- ifend = prev;
- } else {
- iflist = cur->next;
- if (iflist)
- iflist->prev = NULL;
- else
- ifend = NULL;
- }
- if (cur->subs[SUB_REAL].zfd > -1) {
- zt_close(cur->subs[SUB_REAL].zfd);
- }
- destroy_zt_pvt(&cur);
- }
- } else {
- if (prev) {
- prev->next = cur->next;
- if (prev->next)
- prev->next->prev = prev;
- else
- ifend = prev;
- } else {
- iflist = cur->next;
- if (iflist)
- iflist->prev = NULL;
- else
- ifend = NULL;
- }
- if (cur->subs[SUB_REAL].zfd > -1) {
- zt_close(cur->subs[SUB_REAL].zfd);
- }
- destroy_zt_pvt(&cur);
- }
- return 0;
-}
-
-#ifdef ZAPATA_PRI
-int pri_is_up(struct zt_pri *pri)
-{
- int x;
- for (x=0;x<NUM_DCHANS;x++) {
- if (pri->dchanavail[x] == DCHAN_AVAILABLE)
- return 1;
- }
- return 0;
-}
-
-int pri_assign_bearer(struct zt_pvt *crv, struct zt_pri *pri, struct zt_pvt *bearer)
-{
- bearer->owner = &inuse;
- bearer->realcall = crv;
- crv->subs[SUB_REAL].zfd = bearer->subs[SUB_REAL].zfd;
- if (crv->subs[SUB_REAL].owner)
- crv->subs[SUB_REAL].owner->fds[0] = crv->subs[SUB_REAL].zfd;
- crv->bearer = bearer;
- crv->call = bearer->call;
- crv->pri = pri;
- return 0;
-}
-
-static char *pri_order(int level)
-{
- switch(level) {
- case 0:
- return "Primary";
- case 1:
- return "Secondary";
- case 2:
- return "Tertiary";
- case 3:
- return "Quaternary";
- default:
- return "<Unknown>";
- }
-}
-
-/* Returns fd of the active dchan */
-int pri_active_dchan_fd(struct zt_pri *pri)
-{
- int x = -1;
-
- for (x = 0; x < NUM_DCHANS; x++) {
- if ((pri->dchans[x] == pri->pri))
- break;
- }
-
- return pri->fds[x];
-}
-
-int pri_find_dchan(struct zt_pri *pri)
-{
- int oldslot = -1;
- struct pri *old;
- int newslot = -1;
- int x;
- old = pri->pri;
- for(x=0;x<NUM_DCHANS;x++) {
- if ((pri->dchanavail[x] == DCHAN_AVAILABLE) && (newslot < 0))
- newslot = x;
- if (pri->dchans[x] == old) {
- oldslot = x;
- }
- }
- if (newslot < 0) {
- newslot = 0;
- ast_log(LOG_WARNING, "No D-channels available! Using Primary channel %d as D-channel anyway!\n",
- pri->dchannels[newslot]);
- }
- if (old && (oldslot != newslot))
- ast_log(LOG_NOTICE, "Switching from from d-channel %d to channel %d!\n",
- pri->dchannels[oldslot], pri->dchannels[newslot]);
- pri->pri = pri->dchans[newslot];
- return 0;
-}
-#endif
-
-static int zt_hangup(struct ast_channel *ast)
-{
- int res;
- int index,x, law;
- /*static int restore_gains(struct zt_pvt *p);*/
- struct zt_pvt *p = ast->tech_pvt;
- struct zt_pvt *tmp = NULL;
- struct zt_pvt *prev = NULL;
- ZT_PARAMS par;
-
- if (option_debug)
- ast_log(LOG_DEBUG, "zt_hangup(%s)\n", ast->name);
- if (!ast->tech_pvt) {
- ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
- return 0;
- }
-
- ast_mutex_lock(&p->lock);
-
- index = zt_get_index(ast, p, 1);
-
- if (p->sig == SIG_PRI) {
- x = 1;
- ast_channel_setoption(ast,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0);
- }
-
- x = 0;
- zt_confmute(p, 0);
- restore_gains(p);
- if (p->origcid_num) {
- ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num));
- free(p->origcid_num);
- p->origcid_num = NULL;
- }
- if (p->origcid_name) {
- ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name));
- free(p->origcid_name);
- p->origcid_name = NULL;
- }
- if (p->dsp)
- ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_DTMF | p->dtmfrelax);
- if (p->exten)
- p->exten[0] = '\0';
-
- ast_log(LOG_DEBUG, "Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n",
- p->channel, index, p->subs[SUB_REAL].zfd, p->subs[SUB_CALLWAIT].zfd, p->subs[SUB_THREEWAY].zfd);
- p->ignoredtmf = 0;
-
- if (index > -1) {
- /* Real channel, do some fixup */
- p->subs[index].owner = NULL;
- p->subs[index].needanswer = 0;
- p->subs[index].needflash = 0;
- p->subs[index].needringing = 0;
- p->subs[index].needbusy = 0;
- p->subs[index].needcongestion = 0;
- p->subs[index].linear = 0;
- p->subs[index].needcallerid = 0;
- p->polarity = POLARITY_IDLE;
- zt_setlinear(p->subs[index].zfd, 0);
- if (index == SUB_REAL) {
- if ((p->subs[SUB_CALLWAIT].zfd > -1) && (p->subs[SUB_THREEWAY].zfd > -1)) {
- ast_log(LOG_DEBUG, "Normal call hung up with both three way call and a call waiting call in place?\n");
- if (p->subs[SUB_CALLWAIT].inthreeway) {
- /* We had flipped over to answer a callwait and now it's gone */
- ast_log(LOG_DEBUG, "We were flipped over to the callwait, moving back and unowning.\n");
- /* Move to the call-wait, but un-own us until they flip back. */
- swap_subs(p, SUB_CALLWAIT, SUB_REAL);
- unalloc_sub(p, SUB_CALLWAIT);
- p->owner = NULL;
- } else {
- /* The three way hung up, but we still have a call wait */
- ast_log(LOG_DEBUG, "We were in the threeway and have a callwait still. Ditching the threeway.\n");
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- unalloc_sub(p, SUB_THREEWAY);
- if (p->subs[SUB_REAL].inthreeway) {
- /* This was part of a three way call. Immediately make way for
- another call */
- ast_log(LOG_DEBUG, "Call was complete, setting owner to former third call\n");
- p->owner = p->subs[SUB_REAL].owner;
- } else {
- /* This call hasn't been completed yet... Set owner to NULL */
- ast_log(LOG_DEBUG, "Call was incomplete, setting owner to NULL\n");
- p->owner = NULL;
- }
- p->subs[SUB_REAL].inthreeway = 0;
- }
- } else if (p->subs[SUB_CALLWAIT].zfd > -1) {
- /* Move to the call-wait and switch back to them. */
- swap_subs(p, SUB_CALLWAIT, SUB_REAL);
- unalloc_sub(p, SUB_CALLWAIT);
- p->owner = p->subs[SUB_REAL].owner;
- if (p->owner->_state != AST_STATE_UP)
- p->subs[SUB_REAL].needanswer = 1;
- if (ast_bridged_channel(p->subs[SUB_REAL].owner))
- ast_moh_stop(ast_bridged_channel(p->subs[SUB_REAL].owner));
- } else if (p->subs[SUB_THREEWAY].zfd > -1) {
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- unalloc_sub(p, SUB_THREEWAY);
- if (p->subs[SUB_REAL].inthreeway) {
- /* This was part of a three way call. Immediately make way for
- another call */
- ast_log(LOG_DEBUG, "Call was complete, setting owner to former third call\n");
- p->owner = p->subs[SUB_REAL].owner;
- } else {
- /* This call hasn't been completed yet... Set owner to NULL */
- ast_log(LOG_DEBUG, "Call was incomplete, setting owner to NULL\n");
- p->owner = NULL;
- }
- p->subs[SUB_REAL].inthreeway = 0;
- }
- } else if (index == SUB_CALLWAIT) {
- /* Ditch the holding callwait call, and immediately make it availabe */
- if (p->subs[SUB_CALLWAIT].inthreeway) {
- /* This is actually part of a three way, placed on hold. Place the third part
- on music on hold now */
- if (p->subs[SUB_THREEWAY].owner && ast_bridged_channel(p->subs[SUB_THREEWAY].owner))
- ast_moh_start(ast_bridged_channel(p->subs[SUB_THREEWAY].owner), NULL);
- p->subs[SUB_THREEWAY].inthreeway = 0;
- /* Make it the call wait now */
- swap_subs(p, SUB_CALLWAIT, SUB_THREEWAY);
- unalloc_sub(p, SUB_THREEWAY);
- } else
- unalloc_sub(p, SUB_CALLWAIT);
- } else if (index == SUB_THREEWAY) {
- if (p->subs[SUB_CALLWAIT].inthreeway) {
- /* The other party of the three way call is currently in a call-wait state.
- Start music on hold for them, and take the main guy out of the third call */
- if (p->subs[SUB_CALLWAIT].owner && ast_bridged_channel(p->subs[SUB_CALLWAIT].owner))
- ast_moh_start(ast_bridged_channel(p->subs[SUB_CALLWAIT].owner), NULL);
- p->subs[SUB_CALLWAIT].inthreeway = 0;
- }
- p->subs[SUB_REAL].inthreeway = 0;
- /* If this was part of a three way call index, let us make
- another three way call */
- unalloc_sub(p, SUB_THREEWAY);
- } else {
- /* This wasn't any sort of call, but how are we an index? */
- ast_log(LOG_WARNING, "Index found but not any type of call?\n");
- }
- }
-
-
- if (!p->subs[SUB_REAL].owner && !p->subs[SUB_CALLWAIT].owner && !p->subs[SUB_THREEWAY].owner) {
- p->owner = NULL;
- p->ringt = 0;
- p->distinctivering = 0;
- p->confirmanswer = 0;
- p->cidrings = 1;
- p->outgoing = 0;
- p->digital = 0;
- p->faxhandled = 0;
- p->pulsedial = 0;
- p->onhooktime = time(NULL);
-#ifdef ZAPATA_PRI
- p->proceeding = 0;
- p->progress = 0;
- p->alerting = 0;
- p->setup_ack = 0;
-#endif
- if (p->dsp) {
- ast_dsp_free(p->dsp);
- p->dsp = NULL;
- }
-
- law = ZT_LAW_DEFAULT;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_SETLAW, &law);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to set law on channel %d to default\n", p->channel);
- /* Perform low level hangup if no owner left */
-#ifdef ZAPATA_PRI
- if (p->pri) {
-#ifdef SUPPORT_USERUSER
- char *useruser = pbx_builtin_getvar_helper(ast,"USERUSERINFO");
-#endif
-
- /* Make sure we have a call (or REALLY have a call in the case of a PRI) */
- if (p->call && (!p->bearer || (p->bearer->call == p->call))) {
- if (!pri_grab(p, p->pri)) {
- if (p->alreadyhungup) {
- ast_log(LOG_DEBUG, "Already hungup... Calling hangup once, and clearing call\n");
-
-#ifdef SUPPORT_USERUSER
- pri_call_set_useruser(p->call, useruser);
-#endif
-
- pri_hangup(p->pri->pri, p->call, -1);
- p->call = NULL;
- if (p->bearer)
- p->bearer->call = NULL;
- } else {
- char *cause = pbx_builtin_getvar_helper(ast,"PRI_CAUSE");
- int icause = ast->hangupcause ? ast->hangupcause : -1;
- ast_log(LOG_DEBUG, "Not yet hungup... Calling hangup once with icause, and clearing call\n");
-
-#ifdef SUPPORT_USERUSER
- pri_call_set_useruser(p->call, useruser);
-#endif
-
- p->alreadyhungup = 1;
- if (p->bearer)
- p->bearer->alreadyhungup = 1;
- if (cause) {
- if (atoi(cause))
- icause = atoi(cause);
- }
- pri_hangup(p->pri->pri, p->call, icause);
- }
- if (res < 0)
- ast_log(LOG_WARNING, "pri_disconnect failed\n");
- pri_rel(p->pri);
- } else {
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- res = -1;
- }
- } else {
- if (p->bearer)
- ast_log(LOG_DEBUG, "Bearer call is %p, while ours is still %p\n", p->bearer->call, p->call);
- p->call = NULL;
- res = 0;
- }
- }
-#endif
-#ifdef ZAPATA_R2
- if (p->sig == SIG_R2) {
- if (p->hasr2call) {
- mfcr2_DropCall(p->r2, NULL, UC_NORMAL_CLEARING);
- p->hasr2call = 0;
- res = 0;
- } else
- res = 0;
-
- }
-#endif
- if (p->sig && (p->sig != SIG_PRI) && (p->sig != SIG_R2))
- res = zt_set_hook(p->subs[SUB_REAL].zfd, ZT_ONHOOK);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast->name);
- }
- switch(p->sig) {
- case SIG_FXOGS:
- case SIG_FXOLS:
- case SIG_FXOKS:
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &par);
- if (!res) {
-#if 0
- ast_log(LOG_DEBUG, "Hanging up channel %d, offhook = %d\n", p->channel, par.rxisoffhook);
-#endif
- /* If they're off hook, try playing congestion */
- if ((par.rxisoffhook) && (!p->radio))
- tone_zone_play_tone(p->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
- else
- tone_zone_play_tone(p->subs[SUB_REAL].zfd, -1);
- }
- break;
- case SIG_FXSGS:
- case SIG_FXSLS:
- case SIG_FXSKS:
- /* Make sure we're not made available for at least two seconds assuming
- we were actually used for an inbound or outbound call. */
- if (ast->_state != AST_STATE_RESERVED) {
- time(&p->guardtime);
- p->guardtime += 2;
- }
- break;
- default:
- tone_zone_play_tone(p->subs[SUB_REAL].zfd, -1);
- }
- if (p->cidspill)
- free(p->cidspill);
- if (p->sig)
- zt_disable_ec(p);
- x = 0;
- ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
- ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0);
- p->didtdd = 0;
- p->cidspill = NULL;
- p->callwaitcas = 0;
- p->callwaiting = p->permcallwaiting;
- p->hidecallerid = p->permhidecallerid;
- p->dialing = 0;
- p->rdnis[0] = '\0';
- update_conf(p);
- reset_conf(p);
- /* Restore data mode */
- if (p->sig == SIG_PRI) {
- x = 0;
- ast_channel_setoption(ast,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0);
- }
-#ifdef ZAPATA_PRI
- if (p->bearer) {
- ast_log(LOG_DEBUG, "Freeing up bearer channel %d\n", p->bearer->channel);
- /* Free up the bearer channel as well, and
- don't use its file descriptor anymore */
- update_conf(p->bearer);
- reset_conf(p->bearer);
- p->bearer->owner = NULL;
- p->bearer->realcall = NULL;
- p->bearer = NULL;
- p->subs[SUB_REAL].zfd = -1;
- p->pri = NULL;
- }
-#endif
- restart_monitor();
- }
-
-
- p->callwaitingrepeat = 0;
- p->cidcwexpire = 0;
- ast->tech_pvt = NULL;
- ast_mutex_unlock(&p->lock);
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- if (usecnt < 0)
- ast_log(LOG_WARNING, "Usecnt < 0???\n");
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
-
- ast_mutex_lock(&iflock);
- tmp = iflist;
- prev = NULL;
- if (p->destroy) {
- while (tmp) {
- if (tmp == p) {
- destroy_channel(prev, tmp, 0);
- break;
- } else {
- prev = tmp;
- tmp = tmp->next;
- }
- }
- }
- ast_mutex_unlock(&iflock);
- return 0;
-}
-
-static int zt_answer(struct ast_channel *ast)
-{
- struct zt_pvt *p = ast->tech_pvt;
- int res=0;
- int index;
- int oldstate = ast->_state;
- ast_setstate(ast, AST_STATE_UP);
- ast_mutex_lock(&p->lock);
- index = zt_get_index(ast, p, 0);
- if (index < 0)
- index = SUB_REAL;
- /* nothing to do if a radio channel */
- if (p->radio) {
- ast_mutex_unlock(&p->lock);
- return 0;
- }
- switch(p->sig) {
- case SIG_FXSLS:
- case SIG_FXSGS:
- case SIG_FXSKS:
- p->ringt = 0;
- /* Fall through */
- case SIG_EM:
- case SIG_EM_E1:
- case SIG_EMWINK:
- case SIG_FEATD:
- case SIG_FEATDMF:
- case SIG_E911:
- case SIG_FEATB:
- case SIG_SF:
- case SIG_SFWINK:
- case SIG_SF_FEATD:
- case SIG_SF_FEATDMF:
- case SIG_SF_FEATB:
- case SIG_FXOLS:
- case SIG_FXOGS:
- case SIG_FXOKS:
- /* Pick up the line */
- ast_log(LOG_DEBUG, "Took %s off hook\n", ast->name);
- if(p->hanguponpolarityswitch) {
- gettimeofday(&p->polaritydelaytv, NULL);
- }
- res = zt_set_hook(p->subs[SUB_REAL].zfd, ZT_OFFHOOK);
- tone_zone_play_tone(p->subs[index].zfd, -1);
- p->dialing = 0;
- if ((index == SUB_REAL) && p->subs[SUB_THREEWAY].inthreeway) {
- if (oldstate == AST_STATE_RINGING) {
- ast_log(LOG_DEBUG, "Finally swapping real and threeway\n");
- tone_zone_play_tone(p->subs[SUB_THREEWAY].zfd, -1);
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- p->owner = p->subs[SUB_REAL].owner;
- }
- }
- if (p->sig & __ZT_SIG_FXS) {
- zt_enable_ec(p);
- zt_train_ec(p);
- }
- break;
-#ifdef ZAPATA_PRI
- case SIG_PRI:
- /* Send a pri acknowledge */
- if (!pri_grab(p, p->pri)) {
- p->proceeding = 1;
- res = pri_answer(p->pri->pri, p->call, 0, !p->digital);
- pri_rel(p->pri);
- } else {
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- res= -1;
- }
- break;
-#endif
-#ifdef ZAPATA_R2
- case SIG_R2:
- res = mfcr2_AnswerCall(p->r2, NULL);
- if (res)
- ast_log(LOG_WARNING, "R2 Answer call failed :( on %s\n", ast->name);
- break;
-#endif
- case 0:
- ast_mutex_unlock(&p->lock);
- return 0;
- default:
- ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel);
- res = -1;
- }
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static int zt_setoption(struct ast_channel *chan, int option, void *data, int datalen)
-{
- char *cp;
- signed char *scp;
- int x;
- int index;
- struct zt_pvt *p = chan->tech_pvt;
-
- /* all supported options require data */
- if (!data || (datalen < 1)) {
- errno = EINVAL;
- return -1;
- }
-
- switch(option) {
- case AST_OPTION_TXGAIN:
- scp = (signed char *) data;
- index = zt_get_index(chan, p, 0);
- if (index < 0) {
- ast_log(LOG_WARNING, "No index in TXGAIN?\n");
- return -1;
- }
- ast_log(LOG_DEBUG, "Setting actual tx gain on %s to %f\n", chan->name, p->txgain + (float) *scp);
- return set_actual_txgain(p->subs[index].zfd, 0, p->txgain + (float) *scp, p->law);
- case AST_OPTION_RXGAIN:
- scp = (signed char *) data;
- index = zt_get_index(chan, p, 0);
- if (index < 0) {
- ast_log(LOG_WARNING, "No index in RXGAIN?\n");
- return -1;
- }
- ast_log(LOG_DEBUG, "Setting actual rx gain on %s to %f\n", chan->name, p->rxgain + (float) *scp);
- return set_actual_rxgain(p->subs[index].zfd, 0, p->rxgain + (float) *scp, p->law);
- case AST_OPTION_TONE_VERIFY:
- if (!p->dsp)
- break;
- cp = (char *) data;
- switch (*cp) {
- case 1:
- ast_log(LOG_DEBUG, "Set option TONE VERIFY, mode: MUTECONF(1) on %s\n",chan->name);
- ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_MUTECONF | p->dtmfrelax); /* set mute mode if desired */
- break;
- case 2:
- ast_log(LOG_DEBUG, "Set option TONE VERIFY, mode: MUTECONF/MAX(2) on %s\n",chan->name);
- ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX | p->dtmfrelax); /* set mute mode if desired */
- break;
- default:
- ast_log(LOG_DEBUG, "Set option TONE VERIFY, mode: OFF(0) on %s\n",chan->name);
- ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_DTMF | p->dtmfrelax); /* set mute mode if desired */
- break;
- }
- break;
- case AST_OPTION_TDD:
- /* turn on or off TDD */
- cp = (char *) data;
- p->mate = 0;
- if (!*cp) { /* turn it off */
- ast_log(LOG_DEBUG, "Set option TDD MODE, value: OFF(0) on %s\n",chan->name);
- if (p->tdd) tdd_free(p->tdd);
- p->tdd = 0;
- break;
- }
- ast_log(LOG_DEBUG, "Set option TDD MODE, value: %s(%d) on %s\n",
- (*cp == 2) ? "MATE" : "ON", (int) *cp, chan->name);
- zt_disable_ec(p);
- /* otherwise, turn it on */
- if (!p->didtdd) { /* if havent done it yet */
- unsigned char mybuf[41000],*buf;
- int size,res,fd,len;
- struct pollfd fds[1];
-
- buf = mybuf;
- memset(buf, 0x7f, sizeof(mybuf)); /* set to silence */
- ast_tdd_gen_ecdisa(buf + 16000, 16000); /* put in tone */
- len = 40000;
- index = zt_get_index(chan, p, 0);
- if (index < 0) {
- ast_log(LOG_WARNING, "No index in TDD?\n");
- return -1;
- }
- fd = p->subs[index].zfd;
- while(len) {
- if (ast_check_hangup(chan)) return -1;
- size = len;
- if (size > READ_SIZE)
- size = READ_SIZE;
- fds[0].fd = fd;
- fds[0].events = POLLPRI | POLLOUT;
- fds[0].revents = 0;
- res = poll(fds, 1, -1);
- if (!res) {
- ast_log(LOG_DEBUG, "poll (for write) ret. 0 on channel %d\n", p->channel);
- continue;
- }
- /* if got exception */
- if (fds[0].revents & POLLPRI) return -1;
- if (!(fds[0].revents & POLLOUT)) {
- ast_log(LOG_DEBUG, "write fd not ready on channel %d\n", p->channel);
- continue;
- }
- res = write(fd, buf, size);
- if (res != size) {
- if (res == -1) return -1;
- ast_log(LOG_DEBUG, "Write returned %d (%s) on channel %d\n", res, strerror(errno), p->channel);
- break;
- }
- len -= size;
- buf += size;
- }
- p->didtdd = 1; /* set to have done it now */
- }
- if (*cp == 2) { /* Mate mode */
- if (p->tdd) tdd_free(p->tdd);
- p->tdd = 0;
- p->mate = 1;
- break;
- }
- if (!p->tdd) { /* if we dont have one yet */
- p->tdd = tdd_new(); /* allocate one */
- }
- break;
- case AST_OPTION_RELAXDTMF: /* Relax DTMF decoding (or not) */
- if (!p->dsp)
- break;
- cp = (char *) data;
- ast_log(LOG_DEBUG, "Set option RELAX DTMF, value: %s(%d) on %s\n",
- *cp ? "ON" : "OFF", (int) *cp, chan->name);
- ast_dsp_digitmode(p->dsp, ((*cp) ? DSP_DIGITMODE_RELAXDTMF : DSP_DIGITMODE_DTMF) | p->dtmfrelax);
- break;
- case AST_OPTION_AUDIO_MODE: /* Set AUDIO mode (or not) */
- cp = (char *) data;
- if (!*cp) {
- ast_log(LOG_DEBUG, "Set option AUDIO MODE, value: OFF(0) on %s\n", chan->name);
- x = 0;
- zt_disable_ec(p);
- } else {
- ast_log(LOG_DEBUG, "Set option AUDIO MODE, value: ON(1) on %s\n", chan->name);
- x = 1;
- }
- if (ioctl(p->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &x) == -1)
- ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d\n", p->channel, x);
- break;
- }
- errno = 0;
-
- return 0;
-}
-
-static void zt_unlink(struct zt_pvt *slave, struct zt_pvt *master, int needlock)
-{
- /* Unlink a specific slave or all slaves/masters from a given master */
- int x;
- int hasslaves;
- if (!master)
- return;
- if (needlock) {
- ast_mutex_lock(&master->lock);
- if (slave) {
- while(ast_mutex_trylock(&slave->lock)) {
- ast_mutex_unlock(&master->lock);
- usleep(1);
- ast_mutex_lock(&master->lock);
- }
- }
- }
- hasslaves = 0;
- for (x=0;x<MAX_SLAVES;x++) {
- if (master->slaves[x]) {
- if (!slave || (master->slaves[x] == slave)) {
- /* Take slave out of the conference */
- ast_log(LOG_DEBUG, "Unlinking slave %d from %d\n", master->slaves[x]->channel, master->channel);
- conf_del(master, &master->slaves[x]->subs[SUB_REAL], SUB_REAL);
- conf_del(master->slaves[x], &master->subs[SUB_REAL], SUB_REAL);
- master->slaves[x]->master = NULL;
- master->slaves[x] = NULL;
- } else
- hasslaves = 1;
- }
- if (!hasslaves)
- master->inconference = 0;
- }
- if (!slave) {
- if (master->master) {
- /* Take master out of the conference */
- conf_del(master->master, &master->subs[SUB_REAL], SUB_REAL);
- conf_del(master, &master->master->subs[SUB_REAL], SUB_REAL);
- hasslaves = 0;
- for (x=0;x<MAX_SLAVES;x++) {
- if (master->master->slaves[x] == master)
- master->master->slaves[x] = NULL;
- else if (master->master->slaves[x])
- hasslaves = 1;
- }
- if (!hasslaves)
- master->master->inconference = 0;
- }
- master->master = NULL;
- }
- update_conf(master);
- if (needlock) {
- if (slave)
- ast_mutex_unlock(&slave->lock);
- ast_mutex_unlock(&master->lock);
- }
-}
-
-static void zt_link(struct zt_pvt *slave, struct zt_pvt *master) {
- int x;
- if (!slave || !master) {
- ast_log(LOG_WARNING, "Tried to link to/from NULL??\n");
- return;
- }
- for (x=0;x<MAX_SLAVES;x++) {
- if (!master->slaves[x]) {
- master->slaves[x] = slave;
- break;
- }
- }
- if (x >= MAX_SLAVES) {
- ast_log(LOG_WARNING, "Replacing slave %d with new slave, %d\n", master->slaves[MAX_SLAVES - 1]->channel, slave->channel);
- master->slaves[MAX_SLAVES - 1] = slave;
- }
- if (slave->master)
- ast_log(LOG_WARNING, "Replacing master %d with new master, %d\n", slave->master->channel, master->channel);
- slave->master = master;
-
- ast_log(LOG_DEBUG, "Making %d slave to master %d at %d\n", slave->channel, master->channel, x);
-}
-
-static void disable_dtmf_detect(struct zt_pvt *p)
-{
-#ifdef ZT_TONEDETECT
- int val;
-#endif
-
- p->ignoredtmf = 1;
-
-#ifdef ZT_TONEDETECT
- val = 0;
- ioctl(p->subs[SUB_REAL].zfd, ZT_TONEDETECT, &val);
-#endif
- if (!p->hardwaredtmf && p->dsp) {
- p->dsp_features &= ~DSP_FEATURE_DTMF_DETECT;
- ast_dsp_set_features(p->dsp, p->dsp_features);
- }
-}
-
-static void enable_dtmf_detect(struct zt_pvt *p)
-{
-#ifdef ZT_TONEDETECT
- int val;
-#endif
-
- if (p->channel == CHAN_PSEUDO)
- return;
-
- p->ignoredtmf = 0;
-
-#ifdef ZT_TONEDETECT
- val = ZT_TONEDETECT_ON | ZT_TONEDETECT_MUTE;
- ioctl(p->subs[SUB_REAL].zfd, ZT_TONEDETECT, &val);
-#endif
- if (!p->hardwaredtmf && p->dsp) {
- p->dsp_features |= DSP_FEATURE_DTMF_DETECT;
- ast_dsp_set_features(p->dsp, p->dsp_features);
- }
-}
-
-static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms)
-{
- struct ast_channel *who;
- struct zt_pvt *p0, *p1, *op0, *op1;
- struct zt_pvt *master = NULL, *slave = NULL;
- struct ast_frame *f;
- int inconf = 0;
- int nothingok = 1;
- int ofd0, ofd1;
- int oi0, oi1, i0 = -1, i1 = -1, t0, t1;
- int os0 = -1, os1 = -1;
- int priority = 0;
- struct ast_channel *oc0, *oc1;
- enum ast_bridge_result res;
-
-#ifdef PRI_2BCT
- int triedtopribridge = 0;
- q931_call *q931c0 = NULL, *q931c1 = NULL;
-#endif
-
- /* For now, don't attempt to native bridge if either channel needs DTMF detection.
- There is code below to handle it properly until DTMF is actually seen,
- but due to currently unresolved issues it's ignored...
- */
-
- if (flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1))
- return AST_BRIDGE_FAILED_NOWARN;
-
- ast_mutex_lock(&c0->lock);
- ast_mutex_lock(&c1->lock);
-
- p0 = c0->tech_pvt;
- p1 = c1->tech_pvt;
- /* cant do pseudo-channels here */
- if (!p0 || (!p0->sig) || !p1 || (!p1->sig)) {
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
- return AST_BRIDGE_FAILED_NOWARN;
- }
-
- oi0 = zt_get_index(c0, p0, 0);
- oi1 = zt_get_index(c1, p1, 0);
- if ((oi0 < 0) || (oi1 < 0)) {
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
- return AST_BRIDGE_FAILED;
- }
-
- op0 = p0 = c0->tech_pvt;
- op1 = p1 = c1->tech_pvt;
- ofd0 = c0->fds[0];
- ofd1 = c1->fds[0];
- oc0 = p0->owner;
- oc1 = p1->owner;
-
- ast_mutex_lock(&p0->lock);
- if (ast_mutex_trylock(&p1->lock)) {
- /* Don't block, due to potential for deadlock */
- ast_mutex_unlock(&p0->lock);
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
- ast_log(LOG_NOTICE, "Avoiding deadlock...\n");
- return AST_BRIDGE_RETRY;
- }
-
- if ((oi0 == SUB_REAL) && (oi1 == SUB_REAL)) {
- if (p0->owner && p1->owner) {
- /* If we don't have a call-wait in a 3-way, and we aren't in a 3-way, we can be master */
- if (!p0->subs[SUB_CALLWAIT].inthreeway && !p1->subs[SUB_REAL].inthreeway) {
- master = p0;
- slave = p1;
- inconf = 1;
- } else if (!p1->subs[SUB_CALLWAIT].inthreeway && !p0->subs[SUB_REAL].inthreeway) {
- master = p1;
- slave = p0;
- inconf = 1;
- } else {
- ast_log(LOG_WARNING, "Huh? Both calls are callwaits or 3-ways? That's clever...?\n");
- ast_log(LOG_WARNING, "p0: chan %d/%d/CW%d/3W%d, p1: chan %d/%d/CW%d/3W%d\n",
- p0->channel,
- oi0, (p0->subs[SUB_CALLWAIT].zfd > -1) ? 1 : 0,
- p0->subs[SUB_REAL].inthreeway, p0->channel,
- oi0, (p1->subs[SUB_CALLWAIT].zfd > -1) ? 1 : 0,
- p1->subs[SUB_REAL].inthreeway);
- }
- nothingok = 0;
- }
- } else if ((oi0 == SUB_REAL) && (oi1 == SUB_THREEWAY)) {
- if (p1->subs[SUB_THREEWAY].inthreeway) {
- master = p1;
- slave = p0;
- nothingok = 0;
- }
- } else if ((oi0 == SUB_THREEWAY) && (oi1 == SUB_REAL)) {
- if (p0->subs[SUB_THREEWAY].inthreeway) {
- master = p0;
- slave = p1;
- nothingok = 0;
- }
- } else if ((oi0 == SUB_REAL) && (oi1 == SUB_CALLWAIT)) {
- /* We have a real and a call wait. If we're in a three way call, put us in it, otherwise,
- don't put us in anything */
- if (p1->subs[SUB_CALLWAIT].inthreeway) {
- master = p1;
- slave = p0;
- nothingok = 0;
- }
- } else if ((oi0 == SUB_CALLWAIT) && (oi1 == SUB_REAL)) {
- /* Same as previous */
- if (p0->subs[SUB_CALLWAIT].inthreeway) {
- master = p0;
- slave = p1;
- nothingok = 0;
- }
- }
- ast_log(LOG_DEBUG, "master: %d, slave: %d, nothingok: %d\n",
- master ? master->channel : 0, slave ? slave->channel : 0, nothingok);
- if (master && slave) {
- /* Stop any tones, or play ringtone as appropriate. If they're bridged
- in an active threeway call with a channel that is ringing, we should
- indicate ringing. */
- if ((oi1 == SUB_THREEWAY) &&
- p1->subs[SUB_THREEWAY].inthreeway &&
- p1->subs[SUB_REAL].owner &&
- p1->subs[SUB_REAL].inthreeway &&
- (p1->subs[SUB_REAL].owner->_state == AST_STATE_RINGING)) {
- ast_log(LOG_DEBUG, "Playing ringback on %s since %s is in a ringing three-way\n", c0->name, c1->name);
- tone_zone_play_tone(p0->subs[oi0].zfd, ZT_TONE_RINGTONE);
- os1 = p1->subs[SUB_REAL].owner->_state;
- } else {
- ast_log(LOG_DEBUG, "Stopping tones on %d/%d talking to %d/%d\n", p0->channel, oi0, p1->channel, oi1);
- tone_zone_play_tone(p0->subs[oi0].zfd, -1);
- }
- if ((oi0 == SUB_THREEWAY) &&
- p0->subs[SUB_THREEWAY].inthreeway &&
- p0->subs[SUB_REAL].owner &&
- p0->subs[SUB_REAL].inthreeway &&
- (p0->subs[SUB_REAL].owner->_state == AST_STATE_RINGING)) {
- ast_log(LOG_DEBUG, "Playing ringback on %s since %s is in a ringing three-way\n", c1->name, c0->name);
- tone_zone_play_tone(p1->subs[oi1].zfd, ZT_TONE_RINGTONE);
- os0 = p0->subs[SUB_REAL].owner->_state;
- } else {
- ast_log(LOG_DEBUG, "Stopping tones on %d/%d talking to %d/%d\n", p1->channel, oi1, p0->channel, oi0);
- tone_zone_play_tone(p1->subs[oi0].zfd, -1);
- }
- if ((oi0 == SUB_REAL) && (oi1 == SUB_REAL)) {
- if (!p0->echocanbridged || !p1->echocanbridged) {
- /* Disable echo cancellation if appropriate */
- zt_disable_ec(p0);
- zt_disable_ec(p1);
- }
- }
- zt_link(slave, master);
- master->inconference = inconf;
- } else if (!nothingok)
- ast_log(LOG_WARNING, "Can't link %d/%s with %d/%s\n", p0->channel, subnames[oi0], p1->channel, subnames[oi1]);
-
- update_conf(p0);
- update_conf(p1);
- t0 = p0->subs[SUB_REAL].inthreeway;
- t1 = p1->subs[SUB_REAL].inthreeway;
-
- ast_mutex_unlock(&p0->lock);
- ast_mutex_unlock(&p1->lock);
-
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
-
- /* Native bridge failed */
- if ((!master || !slave) && !nothingok) {
- zt_enable_ec(p0);
- zt_enable_ec(p1);
- return AST_BRIDGE_FAILED;
- }
-
- if (!(flags & AST_BRIDGE_DTMF_CHANNEL_0) && (oi0 == SUB_REAL))
- disable_dtmf_detect(op0);
-
- if (!(flags & AST_BRIDGE_DTMF_CHANNEL_1) && (oi1 == SUB_REAL))
- disable_dtmf_detect(op1);
-
- for (;;) {
- struct ast_channel *c0_priority[2] = {c0, c1};
- struct ast_channel *c1_priority[2] = {c1, c0};
-
- /* Here's our main loop... Start by locking things, looking for private parts,
- and then balking if anything is wrong */
- ast_mutex_lock(&c0->lock);
- ast_mutex_lock(&c1->lock);
- p0 = c0->tech_pvt;
- p1 = c1->tech_pvt;
-
- if (op0 == p0)
- i0 = zt_get_index(c0, p0, 1);
- if (op1 == p1)
- i1 = zt_get_index(c1, p1, 1);
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
-
- if (!timeoutms ||
- (op0 != p0) ||
- (op1 != p1) ||
- (ofd0 != c0->fds[0]) ||
- (ofd1 != c1->fds[0]) ||
- (p0->subs[SUB_REAL].owner && (os0 > -1) && (os0 != p0->subs[SUB_REAL].owner->_state)) ||
- (p1->subs[SUB_REAL].owner && (os1 > -1) && (os1 != p1->subs[SUB_REAL].owner->_state)) ||
- (oc0 != p0->owner) ||
- (oc1 != p1->owner) ||
- (t0 != p0->subs[SUB_REAL].inthreeway) ||
- (t1 != p1->subs[SUB_REAL].inthreeway) ||
- (oi0 != i0) ||
- (oi1 != i1)) {
- ast_log(LOG_DEBUG, "Something changed out on %d/%d to %d/%d, returning -3 to restart\n",
- op0->channel, oi0, op1->channel, oi1);
- res = AST_BRIDGE_RETRY;
- goto return_from_bridge;
- }
-
-#ifdef PRI_2BCT
- q931c0 = p0->call;
- q931c1 = p1->call;
- if (p0->transfer && p1->transfer
- && q931c0 && q931c1
- && !triedtopribridge) {
- pri_channel_bridge(q931c0, q931c1);
- triedtopribridge = 1;
- }
-#endif
-
- who = ast_waitfor_n(priority ? c0_priority : c1_priority, 2, &timeoutms);
- if (!who) {
- ast_log(LOG_DEBUG, "Ooh, empty read...\n");
- continue;
- }
- f = ast_read(who);
- if (!f || (f->frametype == AST_FRAME_CONTROL)) {
- *fo = f;
- *rc = who;
- res = AST_BRIDGE_COMPLETE;
- goto return_from_bridge;
- }
- if (f->frametype == AST_FRAME_DTMF) {
- if ((who == c0) && p0->pulsedial) {
- ast_write(c1, f);
- } else if ((who == c1) && p1->pulsedial) {
- ast_write(c0, f);
- } else {
- *fo = f;
- *rc = who;
- res = AST_BRIDGE_COMPLETE;
- goto return_from_bridge;
- }
- }
- ast_frfree(f);
-
- /* Swap who gets priority */
- priority = !priority;
- }
-
-return_from_bridge:
- if (op0 == p0)
- zt_enable_ec(p0);
-
- if (op1 == p1)
- zt_enable_ec(p1);
-
- if (!(flags & AST_BRIDGE_DTMF_CHANNEL_0) && (oi0 == SUB_REAL))
- enable_dtmf_detect(op0);
-
- if (!(flags & AST_BRIDGE_DTMF_CHANNEL_1) && (oi1 == SUB_REAL))
- enable_dtmf_detect(op1);
-
- zt_unlink(slave, master, 1);
-
- return res;
-}
-
-static int zt_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct zt_pvt *p = newchan->tech_pvt;
- int x;
- ast_mutex_lock(&p->lock);
- ast_log(LOG_DEBUG, "New owner for channel %d is %s\n", p->channel, newchan->name);
- if (p->owner == oldchan) {
- p->owner = newchan;
- }
- for (x=0;x<3;x++)
- if (p->subs[x].owner == oldchan) {
- if (!x)
- zt_unlink(NULL, p, 0);
- p->subs[x].owner = newchan;
- }
- if (newchan->_state == AST_STATE_RINGING)
- zt_indicate(newchan, AST_CONTROL_RINGING);
- update_conf(p);
- ast_mutex_unlock(&p->lock);
- return 0;
-}
-
-static int zt_ring_phone(struct zt_pvt *p)
-{
- int x;
- int res;
- /* Make sure our transmit state is on hook */
- x = 0;
- x = ZT_ONHOOK;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_HOOK, &x);
- do {
- x = ZT_RING;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_HOOK, &x);
-#if 0
- printf("Res: %d, error: %s\n", res, strerror(errno));
-#endif
- if (res) {
- switch(errno) {
- case EBUSY:
- case EINTR:
- /* Wait just in case */
- usleep(10000);
- continue;
- case EINPROGRESS:
- res = 0;
- break;
- default:
- ast_log(LOG_WARNING, "Couldn't ring the phone: %s\n", strerror(errno));
- res = 0;
- }
- }
- } while (res);
- return res;
-}
-
-static void *ss_thread(void *data);
-
-static struct ast_channel *zt_new(struct zt_pvt *, int, int, int, int, int);
-
-static int attempt_transfer(struct zt_pvt *p)
-{
- /* In order to transfer, we need at least one of the channels to
- actually be in a call bridge. We can't conference two applications
- together (but then, why would we want to?) */
- if (ast_bridged_channel(p->subs[SUB_REAL].owner)) {
- /* The three-way person we're about to transfer to could still be in MOH, so
- stop if now if appropriate */
- if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner))
- ast_moh_stop(ast_bridged_channel(p->subs[SUB_THREEWAY].owner));
- if (p->subs[SUB_THREEWAY].owner->_state == AST_STATE_RINGING) {
- ast_indicate(ast_bridged_channel(p->subs[SUB_REAL].owner), AST_CONTROL_RINGING);
- }
- if (p->subs[SUB_REAL].owner->cdr) {
- /* Move CDR from second channel to current one */
- p->subs[SUB_THREEWAY].owner->cdr =
- ast_cdr_append(p->subs[SUB_THREEWAY].owner->cdr, p->subs[SUB_REAL].owner->cdr);
- p->subs[SUB_REAL].owner->cdr = NULL;
- }
- if (ast_bridged_channel(p->subs[SUB_REAL].owner)->cdr) {
- /* Move CDR from second channel's bridge to current one */
- p->subs[SUB_THREEWAY].owner->cdr =
- ast_cdr_append(p->subs[SUB_THREEWAY].owner->cdr, ast_bridged_channel(p->subs[SUB_REAL].owner)->cdr);
- ast_bridged_channel(p->subs[SUB_REAL].owner)->cdr = NULL;
- }
- if (ast_channel_masquerade(p->subs[SUB_THREEWAY].owner, ast_bridged_channel(p->subs[SUB_REAL].owner))) {
- ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
- ast_bridged_channel(p->subs[SUB_REAL].owner)->name, p->subs[SUB_THREEWAY].owner->name);
- return -1;
- }
- /* Orphan the channel after releasing the lock */
- ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
- unalloc_sub(p, SUB_THREEWAY);
- } else if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) {
- if (p->subs[SUB_REAL].owner->_state == AST_STATE_RINGING) {
- ast_indicate(ast_bridged_channel(p->subs[SUB_THREEWAY].owner), AST_CONTROL_RINGING);
- }
- ast_moh_stop(ast_bridged_channel(p->subs[SUB_THREEWAY].owner));
- if (p->subs[SUB_THREEWAY].owner->cdr) {
- /* Move CDR from second channel to current one */
- p->subs[SUB_REAL].owner->cdr =
- ast_cdr_append(p->subs[SUB_REAL].owner->cdr, p->subs[SUB_THREEWAY].owner->cdr);
- p->subs[SUB_THREEWAY].owner->cdr = NULL;
- }
- if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner)->cdr) {
- /* Move CDR from second channel's bridge to current one */
- p->subs[SUB_REAL].owner->cdr =
- ast_cdr_append(p->subs[SUB_REAL].owner->cdr, ast_bridged_channel(p->subs[SUB_THREEWAY].owner)->cdr);
- ast_bridged_channel(p->subs[SUB_THREEWAY].owner)->cdr = NULL;
- }
- if (ast_channel_masquerade(p->subs[SUB_REAL].owner, ast_bridged_channel(p->subs[SUB_THREEWAY].owner))) {
- ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
- ast_bridged_channel(p->subs[SUB_THREEWAY].owner)->name, p->subs[SUB_REAL].owner->name);
- return -1;
- }
- /* Three-way is now the REAL */
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- ast_mutex_unlock(&p->subs[SUB_REAL].owner->lock);
- unalloc_sub(p, SUB_THREEWAY);
- /* Tell the caller not to hangup */
- return 1;
- } else {
- ast_log(LOG_DEBUG, "Neither %s nor %s are in a bridge, nothing to transfer\n",
- p->subs[SUB_REAL].owner->name, p->subs[SUB_THREEWAY].owner->name);
- p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
- return -1;
- }
- return 0;
-}
-
-#ifdef ZAPATA_R2
-static struct ast_frame *handle_r2_event(struct zt_pvt *p, mfcr2_event_t *e, int index)
-{
- struct ast_frame *f;
- f = &p->subs[index].f;
- if (!p->r2) {
- ast_log(LOG_WARNING, "Huh? No R2 structure :(\n");
- return NULL;
- }
- switch(e->e) {
- case MFCR2_EVENT_BLOCKED:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d blocked\n", p->channel);
- break;
- case MFCR2_EVENT_UNBLOCKED:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d unblocked\n", p->channel);
- break;
- case MFCR2_EVENT_CONFIG_ERR:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Config error on channel %d\n", p->channel);
- break;
- case MFCR2_EVENT_RING:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Ring on channel %d\n", p->channel);
- break;
- case MFCR2_EVENT_HANGUP:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Hangup on channel %d\n", p->channel);
- break;
- case MFCR2_EVENT_RINGING:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Ringing on channel %d\n", p->channel);
- break;
- case MFCR2_EVENT_ANSWER:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Answer on channel %d\n", p->channel);
- break;
- case MFCR2_EVENT_HANGUP_ACK:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Hangup ACK on channel %d\n", p->channel);
- break;
- case MFCR2_EVENT_IDLE:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Idle on channel %d\n", p->channel);
- break;
- default:
- ast_log(LOG_WARNING, "Unknown MFC/R2 event %d\n", e->e);
- break;
- }
- return f;
-}
-
-static mfcr2_event_t *r2_get_event_bits(struct zt_pvt *p)
-{
- int x;
- int res;
- mfcr2_event_t *e;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_GETRXBITS, &x);
- if (res) {
- ast_log(LOG_WARNING, "Unable to check received bits\n");
- return NULL;
- }
- if (!p->r2) {
- ast_log(LOG_WARNING, "Odd, no R2 structure on channel %d\n", p->channel);
- return NULL;
- }
- e = mfcr2_cas_signaling_event(p->r2, x);
- return e;
-}
-#endif
-
-static int check_for_conference(struct zt_pvt *p)
-{
- ZT_CONFINFO ci;
- /* Fine if we already have a master, etc */
- if (p->master || (p->confno > -1))
- return 0;
- memset(&ci, 0, sizeof(ci));
- if (ioctl(p->subs[SUB_REAL].zfd, ZT_GETCONF, &ci)) {
- ast_log(LOG_WARNING, "Failed to get conference info on channel %d\n", p->channel);
- return 0;
- }
- /* If we have no master and don't have a confno, then
- if we're in a conference, it's probably a MeetMe room or
- some such, so don't let us 3-way out! */
- if ((p->subs[SUB_REAL].curconf.confno != ci.confno) || (p->subs[SUB_REAL].curconf.confmode != ci.confmode)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Avoiding 3-way call when in an external conference\n");
- return 1;
- }
- return 0;
-}
-
-static int get_alarms(struct zt_pvt *p)
-{
- int res;
- ZT_SPANINFO zi;
- memset(&zi, 0, sizeof(zi));
- zi.spanno = p->span;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_SPANSTAT, &zi);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to determine alarm on channel %d\n", p->channel);
- return 0;
- }
- return zi.alarms;
-}
-
-static struct ast_frame *zt_handle_event(struct ast_channel *ast)
-{
- int res,x;
- int index;
- char *c;
- struct zt_pvt *p = ast->tech_pvt;
- pthread_t threadid;
- pthread_attr_t attr;
- struct ast_channel *chan;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- index = zt_get_index(ast, p, 0);
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.datalen = 0;
- p->subs[index].f.samples = 0;
- p->subs[index].f.mallocd = 0;
- p->subs[index].f.offset = 0;
- p->subs[index].f.src = "zt_handle_event";
- p->subs[index].f.data = NULL;
- if (index < 0)
- return &p->subs[index].f;
- if (p->fake_event) {
- res = p->fake_event;
- p->fake_event = 0;
- } else
- res = zt_get_event(p->subs[index].zfd);
-
- ast_log(LOG_DEBUG, "Got event %s(%d) on channel %d (index %d)\n", event2str(res), res, p->channel, index);
-
- if (res & (ZT_EVENT_PULSEDIGIT | ZT_EVENT_DTMFUP)) {
- if (res & ZT_EVENT_PULSEDIGIT)
- p->pulsedial = 1;
- else
- p->pulsedial = 0;
- ast_log(LOG_DEBUG, "Detected %sdigit '%c'\n", p->pulsedial ? "pulse ": "", res & 0xff);
-#ifdef ZAPATA_PRI
- if (!p->proceeding && p->sig == SIG_PRI && p->pri && p->pri->overlapdial) {
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- } else {
-#endif
- p->subs[index].f.frametype = AST_FRAME_DTMF;
- p->subs[index].f.subclass = res & 0xff;
-#ifdef ZAPATA_PRI
- }
-#endif
- /* Unmute conference, return the captured digit */
- zt_confmute(p, 0);
- return &p->subs[index].f;
- }
-
- if (res & ZT_EVENT_DTMFDOWN) {
- ast_log(LOG_DEBUG, "DTMF Down '%c'\n", res & 0xff);
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- zt_confmute(p, 1);
- /* Mute conference, return null frame */
- return &p->subs[index].f;
- }
-
- switch(res) {
- case ZT_EVENT_BITSCHANGED:
- if (p->sig == SIG_R2) {
-#ifdef ZAPATA_R2
- struct ast_frame *f = &p->subs[index].f;
- mfcr2_event_t *e;
- e = r2_get_event_bits(p);
- if (e)
- f = handle_r2_event(p, e, index);
- return f;
-#else
- break;
-#endif
- }
- ast_log(LOG_WARNING, "Recieved bits changed on %s signalling?\n", sig2str(p->sig));
- case ZT_EVENT_PULSE_START:
- /* Stop tone if there's a pulse start and the PBX isn't started */
- if (!ast->pbx)
- tone_zone_play_tone(p->subs[index].zfd, -1);
- break;
- case ZT_EVENT_DIALCOMPLETE:
- if (p->inalarm) break;
- if (p->radio) break;
- if (ioctl(p->subs[index].zfd,ZT_DIALING,&x) == -1) {
- ast_log(LOG_DEBUG, "ZT_DIALING ioctl failed on %s\n",ast->name);
- return NULL;
- }
- if (!x) { /* if not still dialing in driver */
- zt_enable_ec(p);
- if (p->echobreak) {
- zt_train_ec(p);
- ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
- p->dop.op = ZT_DIAL_OP_REPLACE;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop);
- p->echobreak = 0;
- } else {
- p->dialing = 0;
- if (p->sig == SIG_E911) {
- /* if thru with dialing after offhook */
- if (ast->_state == AST_STATE_DIALING_OFFHOOK) {
- ast_setstate(ast, AST_STATE_UP);
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_ANSWER;
- break;
- } else { /* if to state wait for offhook to dial rest */
- /* we now wait for off hook */
- ast_setstate(ast,AST_STATE_DIALING_OFFHOOK);
- }
- }
- if (ast->_state == AST_STATE_DIALING) {
- if ((p->callprogress & 1) && CANPROGRESSDETECT(p) && p->dsp && p->outgoing) {
- ast_log(LOG_DEBUG, "Done dialing, but waiting for progress detection before doing more...\n");
- } else if (p->confirmanswer || (!p->dialednone && ((p->sig == SIG_EM) || (p->sig == SIG_EM_E1) || (p->sig == SIG_EMWINK) || (p->sig == SIG_FEATD) || (p->sig == SIG_FEATDMF) || (p->sig == SIG_E911) || (p->sig == SIG_FEATB) || (p->sig == SIG_SF) || (p->sig == SIG_SFWINK) || (p->sig == SIG_SF_FEATD) || (p->sig == SIG_SF_FEATDMF) || (p->sig == SIG_SF_FEATB)))) {
- ast_setstate(ast, AST_STATE_RINGING);
- } else if (!p->answeronpolarityswitch) {
- ast_setstate(ast, AST_STATE_UP);
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_ANSWER;
- }
- }
- }
- }
- break;
- case ZT_EVENT_ALARM:
-#ifdef ZAPATA_PRI
- if (p->call) {
- if (p->pri && p->pri->pri) {
- if (!pri_grab(p, p->pri)) {
- pri_hangup(p->pri->pri, p->call, -1);
- pri_destroycall(p->pri->pri, p->call);
- p->call = NULL;
- pri_rel(p->pri);
- } else
- ast_log(LOG_WARNING, "Failed to grab PRI!\n");
- } else
- ast_log(LOG_WARNING, "The PRI Call have not been destroyed\n");
- }
- if (p->owner)
- p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- if (p->bearer)
- p->bearer->inalarm = 1;
- else
-#endif
- p->inalarm = 1;
- res = get_alarms(p);
- ast_log(LOG_WARNING, "Detected alarm on channel %d: %s\n", p->channel, alarm2str(res));
- manager_event(EVENT_FLAG_SYSTEM, "Alarm",
- "Alarm: %s\r\n"
- "Channel: %d\r\n",
- alarm2str(res), p->channel);
- /* fall through intentionally */
- case ZT_EVENT_ONHOOK:
- if (p->radio)
- {
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_RADIO_UNKEY;
- break;
- }
- switch(p->sig) {
- case SIG_FXOLS:
- case SIG_FXOGS:
- case SIG_FXOKS:
- p->onhooktime = time(NULL);
- p->msgstate = -1;
- /* Check for some special conditions regarding call waiting */
- if (index == SUB_REAL) {
- /* The normal line was hung up */
- if (p->subs[SUB_CALLWAIT].owner) {
- /* There's a call waiting call, so ring the phone, but make it unowned in the mean time */
- swap_subs(p, SUB_CALLWAIT, SUB_REAL);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d still has (callwait) call, ringing phone\n", p->channel);
- unalloc_sub(p, SUB_CALLWAIT);
-#if 0
- p->subs[index].needanswer = 0;
- p->subs[index].needringing = 0;
-#endif
- p->callwaitingrepeat = 0;
- p->cidcwexpire = 0;
- p->owner = NULL;
- /* Don't start streaming audio yet if the incoming call isn't up yet */
- if (p->subs[SUB_REAL].owner->_state != AST_STATE_UP)
- p->dialing = 1;
- zt_ring_phone(p);
- } else if (p->subs[SUB_THREEWAY].owner) {
- unsigned int mssinceflash;
- /* Here we have to retain the lock on both the main channel, the 3-way channel, and
- the private structure -- not especially easy or clean */
- while(p->subs[SUB_THREEWAY].owner && ast_mutex_trylock(&p->subs[SUB_THREEWAY].owner->lock)) {
- /* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */
- ast_mutex_unlock(&p->lock);
- ast_mutex_unlock(&ast->lock);
- usleep(1);
- /* We can grab ast and p in that order, without worry. We should make sure
- nothing seriously bad has happened though like some sort of bizarre double
- masquerade! */
- ast_mutex_lock(&ast->lock);
- ast_mutex_lock(&p->lock);
- if (p->owner != ast) {
- ast_log(LOG_WARNING, "This isn't good...\n");
- return NULL;
- }
- }
- if (!p->subs[SUB_THREEWAY].owner) {
- ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
- return NULL;
- }
- mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
- ast_log(LOG_DEBUG, "Last flash was %d ms ago\n", mssinceflash);
- if (mssinceflash < MIN_MS_SINCE_FLASH) {
- /* It hasn't been long enough since the last flashook. This is probably a bounce on
- hanging up. Hangup both channels now */
- if (p->subs[SUB_THREEWAY].owner)
- ast_queue_hangup(p->subs[SUB_THREEWAY].owner);
- p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_log(LOG_DEBUG, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
- ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
- } else if ((ast->pbx) || (ast->_state == AST_STATE_UP)) {
- if (p->transfer) {
- /* In any case this isn't a threeway call anymore */
- p->subs[SUB_REAL].inthreeway = 0;
- p->subs[SUB_THREEWAY].inthreeway = 0;
- /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
- if (!p->transfertobusy && ast->_state == AST_STATE_BUSY) {
- ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
- /* Swap subs and dis-own channel */
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- p->owner = NULL;
- /* Ring the phone */
- zt_ring_phone(p);
- } else {
- if ((res = attempt_transfer(p)) < 0) {
- p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
- if (p->subs[SUB_THREEWAY].owner)
- ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
- } else if (res) {
- /* Don't actually hang up at this point */
- if (p->subs[SUB_THREEWAY].owner)
- ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
- break;
- }
- }
- } else {
- p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
- if (p->subs[SUB_THREEWAY].owner)
- ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
- }
- } else {
- ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
- /* Swap subs and dis-own channel */
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- p->owner = NULL;
- /* Ring the phone */
- zt_ring_phone(p);
- }
- }
- } else {
- ast_log(LOG_WARNING, "Got a hangup and my index is %d?\n", index);
- }
- /* Fall through */
- default:
- zt_disable_ec(p);
- return NULL;
- }
- break;
- case ZT_EVENT_RINGOFFHOOK:
- if (p->inalarm) break;
- if (p->radio)
- {
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_RADIO_KEY;
- break;
- }
- /* for E911, its supposed to wait for offhook then dial
- the second half of the dial string */
- if ((p->sig == SIG_E911) && (ast->_state == AST_STATE_DIALING_OFFHOOK)) {
- c = strchr(p->dialdest, '/');
- if (c)
- c++;
- else
- c = p->dialdest;
- if (*c) snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
- else ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
- if (strlen(p->dop.dialstr) > 4) {
- memset(p->echorest, 'w', sizeof(p->echorest) - 1);
- strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
- p->echorest[sizeof(p->echorest) - 1] = '\0';
- p->echobreak = 1;
- p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
- } else
- p->echobreak = 0;
- if (ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop)) {
- x = ZT_ONHOOK;
- ioctl(p->subs[SUB_REAL].zfd, ZT_HOOK, &x);
- ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(errno));
- return NULL;
- }
- p->dialing = 1;
- return &p->subs[index].f;
- }
- switch(p->sig) {
- case SIG_FXOLS:
- case SIG_FXOGS:
- case SIG_FXOKS:
- switch(ast->_state) {
- case AST_STATE_RINGING:
- zt_enable_ec(p);
- zt_train_ec(p);
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_ANSWER;
- /* Make sure it stops ringing */
- zt_set_hook(p->subs[index].zfd, ZT_OFFHOOK);
- ast_log(LOG_DEBUG, "channel %d answered\n", p->channel);
- if (p->cidspill) {
- /* Cancel any running CallerID spill */
- free(p->cidspill);
- p->cidspill = NULL;
- }
- p->dialing = 0;
- p->callwaitcas = 0;
- if (p->confirmanswer) {
- /* Ignore answer if "confirm answer" is enabled */
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- } else if (!ast_strlen_zero(p->dop.dialstr)) {
- /* nick@dccinc.com 4/3/03 - fxo should be able to do deferred dialing */
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", p->channel);
- p->dop.dialstr[0] = '\0';
- return NULL;
- } else {
- ast_log(LOG_DEBUG, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- p->dialing = 1;
- }
- p->dop.dialstr[0] = '\0';
- ast_setstate(ast, AST_STATE_DIALING);
- } else
- ast_setstate(ast, AST_STATE_UP);
- return &p->subs[index].f;
- case AST_STATE_DOWN:
- ast_setstate(ast, AST_STATE_RING);
- ast->rings = 1;
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_OFFHOOK;
- ast_log(LOG_DEBUG, "channel %d picked up\n", p->channel);
- return &p->subs[index].f;
- case AST_STATE_UP:
- /* Make sure it stops ringing */
- zt_set_hook(p->subs[index].zfd, ZT_OFFHOOK);
- /* Okay -- probably call waiting*/
- if (ast_bridged_channel(p->owner))
- ast_moh_stop(ast_bridged_channel(p->owner));
- break;
- case AST_STATE_RESERVED:
- /* Start up dialtone */
- if (has_voicemail(p))
- res = tone_zone_play_tone(p->subs[SUB_REAL].zfd, ZT_TONE_STUTTER);
- else
- res = tone_zone_play_tone(p->subs[SUB_REAL].zfd, ZT_TONE_DIALTONE);
- break;
- default:
- ast_log(LOG_WARNING, "FXO phone off hook in weird state %d??\n", ast->_state);
- }
- break;
- case SIG_FXSLS:
- case SIG_FXSGS:
- case SIG_FXSKS:
- if (ast->_state == AST_STATE_RING) {
- p->ringt = p->ringt_base;
- }
-
- /* If we get a ring then we cannot be in
- * reversed polarity. So we reset to idle */
- ast_log(LOG_DEBUG, "Setting IDLE polarity due "
- "to ring. Old polarity was %d\n",
- p->polarity);
- p->polarity = POLARITY_IDLE;
-
- /* Fall through */
- case SIG_EM:
- case SIG_EM_E1:
- case SIG_EMWINK:
- case SIG_FEATD:
- case SIG_FEATDMF:
- case SIG_FEATDMF_TA:
- case SIG_E911:
- case SIG_FEATB:
- case SIG_SF:
- case SIG_SFWINK:
- case SIG_SF_FEATD:
- case SIG_SF_FEATDMF:
- case SIG_SF_FEATB:
- if (ast->_state == AST_STATE_PRERING)
- ast_setstate(ast, AST_STATE_RING);
- if ((ast->_state == AST_STATE_DOWN) || (ast->_state == AST_STATE_RING)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Ring detected\n");
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_RING;
- } else if (p->outgoing && ((ast->_state == AST_STATE_RINGING) || (ast->_state == AST_STATE_DIALING))) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Line answered\n");
- if (p->confirmanswer) {
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- } else {
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_ANSWER;
- ast_setstate(ast, AST_STATE_UP);
- }
- } else if (ast->_state != AST_STATE_RING)
- ast_log(LOG_WARNING, "Ring/Off-hook in strange state %d on channel %d\n", ast->_state, p->channel);
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
- }
- break;
-#ifdef ZT_EVENT_RINGBEGIN
- case ZT_EVENT_RINGBEGIN:
- switch(p->sig) {
- case SIG_FXSLS:
- case SIG_FXSGS:
- case SIG_FXSKS:
- if (ast->_state == AST_STATE_RING) {
- p->ringt = p->ringt_base;
- }
- break;
- }
- break;
-#endif
- case ZT_EVENT_RINGEROFF:
- if (p->inalarm) break;
- if (p->radio) break;
- ast->rings++;
- if ((ast->rings > p->cidrings) && (p->cidspill)) {
- ast_log(LOG_WARNING, "Didn't finish Caller-ID spill. Cancelling.\n");
- free(p->cidspill);
- p->cidspill = NULL;
- p->callwaitcas = 0;
- }
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_RINGING;
- break;
- case ZT_EVENT_RINGERON:
- break;
- case ZT_EVENT_NOALARM:
- p->inalarm = 0;
-#ifdef ZAPATA_PRI
- /* Extremely unlikely but just in case */
- if (p->bearer)
- p->bearer->inalarm = 0;
-#endif
- ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", p->channel);
- manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
- "Channel: %d\r\n", p->channel);
- break;
- case ZT_EVENT_WINKFLASH:
- if (p->inalarm) break;
- if (p->radio) break;
- /* Remember last time we got a flash-hook */
- gettimeofday(&p->flashtime, NULL);
- switch(p->sig) {
- case SIG_FXOLS:
- case SIG_FXOGS:
- case SIG_FXOKS:
- ast_log(LOG_DEBUG, "Winkflash, index: %d, normal: %d, callwait: %d, thirdcall: %d\n",
- index, p->subs[SUB_REAL].zfd, p->subs[SUB_CALLWAIT].zfd, p->subs[SUB_THREEWAY].zfd);
- p->callwaitcas = 0;
-
- if (index != SUB_REAL) {
- ast_log(LOG_WARNING, "Got flash hook with index %d on channel %d?!?\n", index, p->channel);
- goto winkflashdone;
- }
-
- if (p->subs[SUB_CALLWAIT].owner) {
- /* Swap to call-wait */
- swap_subs(p, SUB_REAL, SUB_CALLWAIT);
- tone_zone_play_tone(p->subs[SUB_REAL].zfd, -1);
- p->owner = p->subs[SUB_REAL].owner;
- ast_log(LOG_DEBUG, "Making %s the new owner\n", p->owner->name);
- if (p->owner->_state == AST_STATE_RINGING) {
- ast_setstate(p->owner, AST_STATE_UP);
- p->subs[SUB_REAL].needanswer = 1;
- }
- p->callwaitingrepeat = 0;
- p->cidcwexpire = 0;
- /* Start music on hold if appropriate */
- if (!p->subs[SUB_CALLWAIT].inthreeway && ast_bridged_channel(p->subs[SUB_CALLWAIT].owner))
- ast_moh_start(ast_bridged_channel(p->subs[SUB_CALLWAIT].owner), NULL);
- if (ast_bridged_channel(p->subs[SUB_REAL].owner))
- ast_moh_stop(ast_bridged_channel(p->subs[SUB_REAL].owner));
- } else if (!p->subs[SUB_THREEWAY].owner) {
- char cid_num[256];
- char cid_name[256];
-
- if (!p->threewaycalling) {
- /* Just send a flash if no 3-way calling */
- p->subs[SUB_REAL].needflash = 1;
- goto winkflashdone;
- } else if (!check_for_conference(p)) {
- if (p->zaptrcallerid && p->owner) {
- if (p->owner->cid.cid_num)
- ast_copy_string(cid_num, p->owner->cid.cid_num, sizeof(cid_num));
- if (p->owner->cid.cid_name)
- ast_copy_string(cid_name, p->owner->cid.cid_name, sizeof(cid_name));
- }
- /* XXX This section needs much more error checking!!! XXX */
- /* Start a 3-way call if feasible */
- if (!((ast->pbx) ||
- (ast->_state == AST_STATE_UP) ||
- (ast->_state == AST_STATE_RING))) {
- ast_log(LOG_DEBUG, "Flash when call not up or ringing\n");
- goto winkflashdone;
- }
- if (alloc_sub(p, SUB_THREEWAY)) {
- ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
- goto winkflashdone;
- }
- /* Make new channel */
- chan = zt_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0, 0);
- if (p->zaptrcallerid) {
- if (!p->origcid_num)
- p->origcid_num = strdup(p->cid_num);
- if (!p->origcid_name)
- p->origcid_name = strdup(p->cid_name);
- ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
- ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
- }
- /* Swap things around between the three-way and real call */
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- /* Disable echo canceller for better dialing */
- zt_disable_ec(p);
- res = tone_zone_play_tone(p->subs[SUB_REAL].zfd, ZT_TONE_DIALRECALL);
- if (res)
- ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
- p->owner = chan;
- if (!chan) {
- ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", p->channel);
- } else if (ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
- ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
- res = tone_zone_play_tone(p->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
- zt_enable_ec(p);
- ast_hangup(chan);
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Started three way call on channel %d\n", p->channel);
- /* Start music on hold if appropriate */
- if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner))
- ast_moh_start(ast_bridged_channel(p->subs[SUB_THREEWAY].owner), NULL);
- }
- }
- } else {
- /* Already have a 3 way call */
- if (p->subs[SUB_THREEWAY].inthreeway) {
- /* Call is already up, drop the last person */
- if (option_debug)
- ast_log(LOG_DEBUG, "Got flash with three way call up, dropping last call on %d\n", p->channel);
- /* If the primary call isn't answered yet, use it */
- if ((p->subs[SUB_REAL].owner->_state != AST_STATE_UP) && (p->subs[SUB_THREEWAY].owner->_state == AST_STATE_UP)) {
- /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- p->owner = p->subs[SUB_REAL].owner;
- }
- /* Drop the last call and stop the conference */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Dropping three-way call on %s\n", p->subs[SUB_THREEWAY].owner->name);
- p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
- p->subs[SUB_REAL].inthreeway = 0;
- p->subs[SUB_THREEWAY].inthreeway = 0;
- } else {
- /* Lets see what we're up to */
- if (((ast->pbx) || (ast->_state == AST_STATE_UP)) &&
- (p->transfertobusy || (ast->_state != AST_STATE_BUSY))) {
- int otherindex = SUB_THREEWAY;
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Building conference on call on %s and %s\n", p->subs[SUB_THREEWAY].owner->name, p->subs[SUB_REAL].owner->name);
- /* Put them in the threeway, and flip */
- p->subs[SUB_THREEWAY].inthreeway = 1;
- p->subs[SUB_REAL].inthreeway = 1;
- if (ast->_state == AST_STATE_UP) {
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- otherindex = SUB_REAL;
- }
- if (p->subs[otherindex].owner && ast_bridged_channel(p->subs[otherindex].owner))
- ast_moh_stop(ast_bridged_channel(p->subs[otherindex].owner));
- p->owner = p->subs[SUB_REAL].owner;
- if (ast->_state == AST_STATE_RINGING) {
- ast_log(LOG_DEBUG, "Enabling ringtone on real and threeway\n");
- res = tone_zone_play_tone(p->subs[SUB_REAL].zfd, ZT_TONE_RINGTONE);
- res = tone_zone_play_tone(p->subs[SUB_THREEWAY].zfd, ZT_TONE_RINGTONE);
- }
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Dumping incomplete call on on %s\n", p->subs[SUB_THREEWAY].owner->name);
- swap_subs(p, SUB_THREEWAY, SUB_REAL);
- p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
- p->owner = p->subs[SUB_REAL].owner;
- if (p->subs[SUB_REAL].owner && ast_bridged_channel(p->subs[SUB_REAL].owner))
- ast_moh_stop(ast_bridged_channel(p->subs[SUB_REAL].owner));
- zt_enable_ec(p);
- }
-
- }
- }
- winkflashdone:
- update_conf(p);
- break;
- case SIG_EM:
- case SIG_EM_E1:
- case SIG_EMWINK:
- case SIG_FEATD:
- case SIG_SF:
- case SIG_SFWINK:
- case SIG_SF_FEATD:
- case SIG_FXSLS:
- case SIG_FXSGS:
- if (p->dialing)
- ast_log(LOG_DEBUG, "Ignoring wink on channel %d\n", p->channel);
- else
- ast_log(LOG_DEBUG, "Got wink in weird state %d on channel %d\n", ast->_state, p->channel);
- break;
- case SIG_FEATDMF_TA:
- switch (p->whichwink) {
- case 0:
- ast_log(LOG_DEBUG, "ANI2 set to '%d' and ANI is '%s'\n", p->owner->cid.cid_ani2, p->owner->cid.cid_ani);
- snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#", p->owner->cid.cid_ani2, p->owner->cid.cid_ani);
- break;
- case 1:
- ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
- break;
- case 2:
- ast_log(LOG_WARNING, "Received unexpected wink on channel of type SIG_FEATDMF_TA\n");
- return NULL;
- }
- p->whichwink++;
- /* Fall through */
- case SIG_FEATDMF:
- case SIG_E911:
- case SIG_FEATB:
- case SIG_SF_FEATDMF:
- case SIG_SF_FEATB:
- /* FGD MF *Must* wait for wink */
- if (!ast_strlen_zero(p->dop.dialstr))
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop);
- else if (res < 0) {
- ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", p->channel);
- p->dop.dialstr[0] = '\0';
- return NULL;
- } else
- ast_log(LOG_DEBUG, "Sent deferred digit string: %s\n", p->dop.dialstr);
- p->dop.dialstr[0] = '\0';
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to handle ring/off hoook for signalling %d\n", p->sig);
- }
- break;
- case ZT_EVENT_HOOKCOMPLETE:
- if (p->inalarm) break;
- if (p->radio) break;
- switch(p->sig) {
- case SIG_FXSLS: /* only interesting for FXS */
- case SIG_FXSGS:
- case SIG_FXSKS:
- case SIG_EM:
- case SIG_EM_E1:
- case SIG_EMWINK:
- case SIG_FEATD:
- case SIG_SF:
- case SIG_SFWINK:
- case SIG_SF_FEATD:
- if (!ast_strlen_zero(p->dop.dialstr))
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop);
- else if (res < 0) {
- ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", p->channel);
- p->dop.dialstr[0] = '\0';
- return NULL;
- } else
- ast_log(LOG_DEBUG, "Sent deferred digit string: %s\n", p->dop.dialstr);
- p->dop.dialstr[0] = '\0';
- p->dop.op = ZT_DIAL_OP_REPLACE;
- break;
- case SIG_FEATDMF:
- case SIG_E911:
- case SIG_FEATB:
- case SIG_SF_FEATDMF:
- case SIG_SF_FEATB:
- ast_log(LOG_DEBUG, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel);
- break;
- default:
- break;
- }
- break;
- case ZT_EVENT_POLARITY:
- /*
- * If we get a Polarity Switch event, check to see
- * if we should change the polarity state and
- * mark the channel as UP or if this is an indication
- * of remote end disconnect.
- */
- if (p->polarity == POLARITY_IDLE) {
- p->polarity = POLARITY_REV;
- if (p->answeronpolarityswitch &&
- ((ast->_state == AST_STATE_DIALING) ||
- (ast->_state == AST_STATE_RINGING))) {
- ast_log(LOG_DEBUG, "Answering on polarity switch!\n");
- ast_setstate(p->owner, AST_STATE_UP);
- if(p->hanguponpolarityswitch) {
- gettimeofday(&p->polaritydelaytv, NULL);
- }
- break;
- } else
- ast_log(LOG_DEBUG, "Ignore switch to REVERSED Polarity on channel %d, state %d\n", p->channel, ast->_state);
- }
- /* Removed else statement from here as it was preventing hangups from ever happening*/
- /* Added AST_STATE_RING in if statement below to deal with calling party hangups that take place when ringing */
- if(p->hanguponpolarityswitch &&
- (p->polarityonanswerdelay > 0) &&
- (p->polarity == POLARITY_REV) &&
- ((ast->_state == AST_STATE_UP) || (ast->_state == AST_STATE_RING)) ) {
- /* Added log_debug information below to provide a better indication of what is going on */
- ast_log(LOG_DEBUG, "Polarity Reversal event occured - DEBUG 1: channel %d, state %d, pol= %d, aonp= %d, honp= %d, pdelay= %d, tv= %d\n", p->channel, ast->_state, p->polarity, p->answeronpolarityswitch, p->hanguponpolarityswitch, p->polarityonanswerdelay, ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) );
-
- if(ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) > p->polarityonanswerdelay) {
- ast_log(LOG_DEBUG, "Polarity Reversal detected and now Hanging up on channel %d\n", p->channel);
- ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
- p->polarity = POLARITY_IDLE;
- } else {
- ast_log(LOG_DEBUG, "Polarity Reversal detected but NOT hanging up (too close to answer event) on channel %d, state %d\n", p->channel, ast->_state);
- }
- } else {
- p->polarity = POLARITY_IDLE;
- ast_log(LOG_DEBUG, "Ignoring Polarity switch to IDLE on channel %d, state %d\n", p->channel, ast->_state);
- }
- /* Added more log_debug information below to provide a better indication of what is going on */
- ast_log(LOG_DEBUG, "Polarity Reversal event occured - DEBUG 2: channel %d, state %d, pol= %d, aonp= %d, honp= %d, pdelay= %d, tv= %d\n", p->channel, ast->_state, p->polarity, p->answeronpolarityswitch, p->hanguponpolarityswitch, p->polarityonanswerdelay, ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) );
- break;
- default:
- ast_log(LOG_DEBUG, "Dunno what to do with event %d on channel %d\n", res, p->channel);
- }
- return &p->subs[index].f;
-}
-
-static struct ast_frame *__zt_exception(struct ast_channel *ast)
-{
- struct zt_pvt *p = ast->tech_pvt;
- int res;
- int usedindex=-1;
- int index;
- struct ast_frame *f;
-
-
- index = zt_get_index(ast, p, 1);
-
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.datalen = 0;
- p->subs[index].f.samples = 0;
- p->subs[index].f.mallocd = 0;
- p->subs[index].f.offset = 0;
- p->subs[index].f.subclass = 0;
- p->subs[index].f.delivery = ast_tv(0,0);
- p->subs[index].f.src = "zt_exception";
- p->subs[index].f.data = NULL;
-
-
- if ((!p->owner) && (!p->radio)) {
- /* If nobody owns us, absorb the event appropriately, otherwise
- we loop indefinitely. This occurs when, during call waiting, the
- other end hangs up our channel so that it no longer exists, but we
- have neither FLASH'd nor ONHOOK'd to signify our desire to
- change to the other channel. */
- if (p->fake_event) {
- res = p->fake_event;
- p->fake_event = 0;
- } else
- res = zt_get_event(p->subs[SUB_REAL].zfd);
- /* Switch to real if there is one and this isn't something really silly... */
- if ((res != ZT_EVENT_RINGEROFF) && (res != ZT_EVENT_RINGERON) &&
- (res != ZT_EVENT_HOOKCOMPLETE)) {
- ast_log(LOG_DEBUG, "Restoring owner of channel %d on event %d\n", p->channel, res);
- p->owner = p->subs[SUB_REAL].owner;
- if (p->owner && ast_bridged_channel(p->owner))
- ast_moh_stop(ast_bridged_channel(p->owner));
- }
- switch(res) {
- case ZT_EVENT_ONHOOK:
- zt_disable_ec(p);
- if (p->owner) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %s still has call, ringing phone\n", p->owner->name);
- zt_ring_phone(p);
- p->callwaitingrepeat = 0;
- p->cidcwexpire = 0;
- } else
- ast_log(LOG_WARNING, "Absorbed on hook, but nobody is left!?!?\n");
- update_conf(p);
- break;
- case ZT_EVENT_RINGOFFHOOK:
- zt_set_hook(p->subs[SUB_REAL].zfd, ZT_OFFHOOK);
- if (p->owner && (p->owner->_state == AST_STATE_RINGING)) {
- p->subs[SUB_REAL].needanswer = 1;
- p->dialing = 0;
- }
- break;
- case ZT_EVENT_HOOKCOMPLETE:
- case ZT_EVENT_RINGERON:
- case ZT_EVENT_RINGEROFF:
- /* Do nothing */
- break;
- case ZT_EVENT_WINKFLASH:
- gettimeofday(&p->flashtime, NULL);
- if (p->owner) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d flashed to other channel %s\n", p->channel, p->owner->name);
- if (p->owner->_state != AST_STATE_UP) {
- /* Answer if necessary */
- usedindex = zt_get_index(p->owner, p, 0);
- if (usedindex > -1) {
- p->subs[usedindex].needanswer = 1;
- }
- ast_setstate(p->owner, AST_STATE_UP);
- }
- p->callwaitingrepeat = 0;
- p->cidcwexpire = 0;
- if (ast_bridged_channel(p->owner))
- ast_moh_stop(ast_bridged_channel(p->owner));
- } else
- ast_log(LOG_WARNING, "Absorbed on hook, but nobody is left!?!?\n");
- update_conf(p);
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", event2str(res));
- }
- f = &p->subs[index].f;
- return f;
- }
- if (!p->radio) ast_log(LOG_DEBUG, "Exception on %d, channel %d\n", ast->fds[0],p->channel);
- /* If it's not us, return NULL immediately */
- if (ast != p->owner) {
- ast_log(LOG_WARNING, "We're %s, not %s\n", ast->name, p->owner->name);
- f = &p->subs[index].f;
- return f;
- }
- f = zt_handle_event(ast);
- return f;
-}
-
-struct ast_frame *zt_exception(struct ast_channel *ast)
-{
- struct zt_pvt *p = ast->tech_pvt;
- struct ast_frame *f;
- ast_mutex_lock(&p->lock);
- f = __zt_exception(ast);
- ast_mutex_unlock(&p->lock);
- return f;
-}
-
-struct ast_frame *zt_read(struct ast_channel *ast)
-{
- struct zt_pvt *p = ast->tech_pvt;
- int res;
- int index;
- void *readbuf;
- struct ast_frame *f;
-
-
- ast_mutex_lock(&p->lock);
-
- index = zt_get_index(ast, p, 0);
-
- /* Hang up if we don't really exist */
- if (index < 0) {
- ast_log(LOG_WARNING, "We dont exist?\n");
- ast_mutex_unlock(&p->lock);
- return NULL;
- }
-
- if (p->radio && p->inalarm) return NULL;
-
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.datalen = 0;
- p->subs[index].f.samples = 0;
- p->subs[index].f.mallocd = 0;
- p->subs[index].f.offset = 0;
- p->subs[index].f.subclass = 0;
- p->subs[index].f.delivery = ast_tv(0,0);
- p->subs[index].f.src = "zt_read";
- p->subs[index].f.data = NULL;
-
- /* make sure it sends initial key state as first frame */
- if (p->radio && (!p->firstradio))
- {
- ZT_PARAMS ps;
-
- ps.channo = p->channel;
- if (ioctl(p->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &ps) < 0) {
- ast_mutex_unlock(&p->lock);
- return NULL;
- }
- p->firstradio = 1;
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- if (ps.rxisoffhook)
- {
- p->subs[index].f.subclass = AST_CONTROL_RADIO_KEY;
- }
- else
- {
- p->subs[index].f.subclass = AST_CONTROL_RADIO_UNKEY;
- }
- ast_mutex_unlock(&p->lock);
- return &p->subs[index].f;
- }
- if (p->ringt == 1) {
- ast_mutex_unlock(&p->lock);
- return NULL;
- }
- else if (p->ringt > 0)
- p->ringt--;
-
- if (p->subs[index].needringing) {
- /* Send ringing frame if requested */
- p->subs[index].needringing = 0;
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_RINGING;
- ast_setstate(ast, AST_STATE_RINGING);
- ast_mutex_unlock(&p->lock);
- return &p->subs[index].f;
- }
-
- if (p->subs[index].needbusy) {
- /* Send busy frame if requested */
- p->subs[index].needbusy = 0;
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_BUSY;
- ast_mutex_unlock(&p->lock);
- return &p->subs[index].f;
- }
-
- if (p->subs[index].needcongestion) {
- /* Send congestion frame if requested */
- p->subs[index].needcongestion = 0;
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_CONGESTION;
- ast_mutex_unlock(&p->lock);
- return &p->subs[index].f;
- }
-
- if (p->subs[index].needcallerid) {
- ast_set_callerid(ast, !ast_strlen_zero(p->lastcid_num) ? p->lastcid_num : NULL,
- !ast_strlen_zero(p->lastcid_name) ? p->lastcid_name : NULL,
- !ast_strlen_zero(p->lastcid_num) ? p->lastcid_num : NULL
- );
- p->subs[index].needcallerid = 0;
- }
-
- if (p->subs[index].needanswer) {
- /* Send answer frame if requested */
- p->subs[index].needanswer = 0;
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_ANSWER;
- ast_mutex_unlock(&p->lock);
- return &p->subs[index].f;
- }
-
- if (p->subs[index].needflash) {
- /* Send answer frame if requested */
- p->subs[index].needflash = 0;
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_FLASH;
- ast_mutex_unlock(&p->lock);
- return &p->subs[index].f;
- }
-
- if (ast->rawreadformat == AST_FORMAT_SLINEAR) {
- if (!p->subs[index].linear) {
- p->subs[index].linear = 1;
- res = zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
- if (res)
- ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to linear mode.\n", p->channel, index);
- }
- } else if ((ast->rawreadformat == AST_FORMAT_ULAW) ||
- (ast->rawreadformat == AST_FORMAT_ALAW)) {
- if (p->subs[index].linear) {
- p->subs[index].linear = 0;
- res = zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
- if (res)
- ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to companded mode.\n", p->channel, index);
- }
- } else {
- ast_log(LOG_WARNING, "Don't know how to read frames in format %s\n", ast_getformatname(ast->rawreadformat));
- ast_mutex_unlock(&p->lock);
- return NULL;
- }
- readbuf = ((unsigned char *)p->subs[index].buffer) + AST_FRIENDLY_OFFSET;
- CHECK_BLOCKING(ast);
- res = read(p->subs[index].zfd, readbuf, p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE);
- ast_clear_flag(ast, AST_FLAG_BLOCKING);
- /* Check for hangup */
- if (res < 0) {
- f = NULL;
- if (res == -1) {
- if (errno == EAGAIN) {
- /* Return "NULL" frame if there is nobody there */
- ast_mutex_unlock(&p->lock);
- return &p->subs[index].f;
- } else if (errno == ELAST) {
- f = __zt_exception(ast);
- } else
- ast_log(LOG_WARNING, "zt_rec: %s\n", strerror(errno));
- }
- ast_mutex_unlock(&p->lock);
- return f;
- }
- if (res != (p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE)) {
- ast_log(LOG_DEBUG, "Short read (%d/%d), must be an event...\n", res, p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE);
- f = __zt_exception(ast);
- ast_mutex_unlock(&p->lock);
- return f;
- }
- if (p->tdd) { /* if in TDD mode, see if we receive that */
- int c;
-
- c = tdd_feed(p->tdd,readbuf,READ_SIZE);
- if (c < 0) {
- ast_log(LOG_DEBUG,"tdd_feed failed\n");
- ast_mutex_unlock(&p->lock);
- return NULL;
- }
- if (c) { /* if a char to return */
- p->subs[index].f.subclass = 0;
- p->subs[index].f.frametype = AST_FRAME_TEXT;
- p->subs[index].f.mallocd = 0;
- p->subs[index].f.offset = AST_FRIENDLY_OFFSET;
- p->subs[index].f.data = p->subs[index].buffer + AST_FRIENDLY_OFFSET;
- p->subs[index].f.datalen = 1;
- *((char *) p->subs[index].f.data) = c;
- ast_mutex_unlock(&p->lock);
- return &p->subs[index].f;
- }
- }
- if (p->callwaitingrepeat)
- p->callwaitingrepeat--;
- if (p->cidcwexpire)
- p->cidcwexpire--;
- /* Repeat callwaiting */
- if (p->callwaitingrepeat == 1) {
- p->callwaitrings++;
- zt_callwait(ast);
- }
- /* Expire CID/CW */
- if (p->cidcwexpire == 1) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CPE does not support Call Waiting Caller*ID.\n");
- restore_conference(p);
- }
- if (p->subs[index].linear) {
- p->subs[index].f.datalen = READ_SIZE * 2;
- } else
- p->subs[index].f.datalen = READ_SIZE;
-
- /* Handle CallerID Transmission */
- if ((p->owner == ast) && p->cidspill &&((ast->_state == AST_STATE_UP) || (ast->rings == p->cidrings))) {
- send_callerid(p);
- }
-
- p->subs[index].f.frametype = AST_FRAME_VOICE;
- p->subs[index].f.subclass = ast->rawreadformat;
- p->subs[index].f.samples = READ_SIZE;
- p->subs[index].f.mallocd = 0;
- p->subs[index].f.offset = AST_FRIENDLY_OFFSET;
- p->subs[index].f.data = p->subs[index].buffer + AST_FRIENDLY_OFFSET/2;
-#if 0
- ast_log(LOG_DEBUG, "Read %d of voice on %s\n", p->subs[index].f.datalen, ast->name);
-#endif
- if (p->dialing || /* Transmitting something */
- (index && (ast->_state != AST_STATE_UP)) || /* Three-way or callwait that isn't up */
- ((index == SUB_CALLWAIT) && !p->subs[SUB_CALLWAIT].inthreeway) /* Inactive and non-confed call-wait */
- ) {
- /* Whoops, we're still dialing, or in a state where we shouldn't transmit....
- don't send anything */
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- p->subs[index].f.samples = 0;
- p->subs[index].f.mallocd = 0;
- p->subs[index].f.offset = 0;
- p->subs[index].f.data = NULL;
- p->subs[index].f.datalen= 0;
- }
- if (p->dsp && (!p->ignoredtmf || p->callwaitcas || p->busydetect || p->callprogress) && !index) {
- /* Perform busy detection. etc on the zap line */
- f = ast_dsp_process(ast, p->dsp, &p->subs[index].f);
- if (f) {
- if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_BUSY)) {
- if ((ast->_state == AST_STATE_UP) && !p->outgoing) {
- /* Treat this as a "hangup" instead of a "busy" on the assumption that
- a busy */
- f = NULL;
- }
- } else if (f->frametype == AST_FRAME_DTMF) {
-#ifdef ZAPATA_PRI
- if (!p->proceeding && p->sig==SIG_PRI && p->pri && p->pri->overlapdial) {
- /* Don't accept in-band DTMF when in overlap dial mode */
- f->frametype = AST_FRAME_NULL;
- f->subclass = 0;
- }
-#endif
- /* DSP clears us of being pulse */
- p->pulsedial = 0;
- }
- }
- } else
- f = &p->subs[index].f;
- if (f && (f->frametype == AST_FRAME_DTMF)) {
- ast_log(LOG_DEBUG, "DTMF digit: %c on %s\n", f->subclass, ast->name);
- if (p->confirmanswer) {
- ast_log(LOG_DEBUG, "Confirm answer on %s!\n", ast->name);
- /* Upon receiving a DTMF digit, consider this an answer confirmation instead
- of a DTMF digit */
- p->subs[index].f.frametype = AST_FRAME_CONTROL;
- p->subs[index].f.subclass = AST_CONTROL_ANSWER;
- f = &p->subs[index].f;
- /* Reset confirmanswer so DTMF's will behave properly for the duration of the call */
- p->confirmanswer = 0;
- } else if (p->callwaitcas) {
- if ((f->subclass == 'A') || (f->subclass == 'D')) {
- ast_log(LOG_DEBUG, "Got some DTMF, but it's for the CAS\n");
- if (p->cidspill)
- free(p->cidspill);
- send_cwcidspill(p);
- }
- if ((f->subclass != 'm') && (f->subclass != 'u'))
- p->callwaitcas = 0;
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- f = &p->subs[index].f;
- } else if (f->subclass == 'f') {
- /* Fax tone -- Handle and return NULL */
- if (!p->faxhandled) {
- p->faxhandled++;
- if (strcmp(ast->exten, "fax")) {
- const char *target_context = ast_strlen_zero(ast->macrocontext) ? ast->context : ast->macrocontext;
-
- if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", ast->name);
- /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
- pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
- if (ast_async_goto(ast, target_context, "fax", 1))
- ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
- } else
- ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
- } else
- ast_log(LOG_DEBUG, "Already in a fax extension, not redirecting\n");
- } else
- ast_log(LOG_DEBUG, "Fax already handled\n");
- zt_confmute(p, 0);
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- f = &p->subs[index].f;
- } else if (f->subclass == 'm') {
- /* Confmute request */
- zt_confmute(p, 1);
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- f = &p->subs[index].f;
- } else if (f->subclass == 'u') {
- /* Unmute */
- zt_confmute(p, 0);
- p->subs[index].f.frametype = AST_FRAME_NULL;
- p->subs[index].f.subclass = 0;
- f = &p->subs[index].f;
- } else
- zt_confmute(p, 0);
- }
-
- /* If we have a fake_event, trigger exception to handle it */
- if (p->fake_event)
- ast_set_flag(ast, AST_FLAG_EXCEPTION);
-
- ast_mutex_unlock(&p->lock);
- return f;
-}
-
-static int my_zt_write(struct zt_pvt *p, unsigned char *buf, int len, int index, int linear)
-{
- int sent=0;
- int size;
- int res;
- int fd;
- fd = p->subs[index].zfd;
- while(len) {
- size = len;
- if (size > (linear ? READ_SIZE * 2 : READ_SIZE))
- size = (linear ? READ_SIZE * 2 : READ_SIZE);
- res = write(fd, buf, size);
- if (res != size) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Write returned %d (%s) on channel %d\n", res, strerror(errno), p->channel);
- return sent;
- }
- len -= size;
- buf += size;
- }
- return sent;
-}
-
-static int zt_write(struct ast_channel *ast, struct ast_frame *frame)
-{
- struct zt_pvt *p = ast->tech_pvt;
- int res;
- unsigned char outbuf[4096];
- int index;
- index = zt_get_index(ast, p, 0);
- if (index < 0) {
- ast_log(LOG_WARNING, "%s doesn't really exist?\n", ast->name);
- return -1;
- }
-
-#if 0
-#ifdef ZAPATA_PRI
- ast_mutex_lock(&p->lock);
- if (!p->proceeding && p->sig==SIG_PRI && p->pri && !p->outgoing) {
- if (p->pri->pri) {
- if (!pri_grab(p, p->pri)) {
- pri_progress(p->pri->pri,p->call, PVT_TO_CHANNEL(p), !p->digital);
- pri_rel(p->pri);
- } else
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- }
- p->proceeding=1;
- }
- ast_mutex_unlock(&p->lock);
-#endif
-#endif
- /* Write a frame of (presumably voice) data */
- if (frame->frametype != AST_FRAME_VOICE) {
- if (frame->frametype != AST_FRAME_IMAGE)
- ast_log(LOG_WARNING, "Don't know what to do with frame type '%d'\n", frame->frametype);
- return 0;
- }
- if ((frame->subclass != AST_FORMAT_SLINEAR) &&
- (frame->subclass != AST_FORMAT_ULAW) &&
- (frame->subclass != AST_FORMAT_ALAW)) {
- ast_log(LOG_WARNING, "Cannot handle frames in %d format\n", frame->subclass);
- return -1;
- }
- if (p->dialing) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Dropping frame since I'm still dialing on %s...\n",ast->name);
- return 0;
- }
- if (!p->owner) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Dropping frame since there is no active owner on %s...\n",ast->name);
- return 0;
- }
- if (p->cidspill) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Dropping frame since I've still got a callerid spill\n");
- return 0;
- }
- /* Return if it's not valid data */
- if (!frame->data || !frame->datalen)
- return 0;
- if (frame->datalen > sizeof(outbuf) * 2) {
- ast_log(LOG_WARNING, "Frame too large\n");
- return 0;
- }
-
- if (frame->subclass == AST_FORMAT_SLINEAR) {
- if (!p->subs[index].linear) {
- p->subs[index].linear = 1;
- res = zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
- if (res)
- ast_log(LOG_WARNING, "Unable to set linear mode on channel %d\n", p->channel);
- }
- res = my_zt_write(p, (unsigned char *)frame->data, frame->datalen, index, 1);
- } else {
- /* x-law already */
- if (p->subs[index].linear) {
- p->subs[index].linear = 0;
- res = zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
- if (res)
- ast_log(LOG_WARNING, "Unable to set companded mode on channel %d\n", p->channel);
- }
- res = my_zt_write(p, (unsigned char *)frame->data, frame->datalen, index, 0);
- }
- if (res < 0) {
- ast_log(LOG_WARNING, "write failed: %s\n", strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int zt_indicate(struct ast_channel *chan, int condition)
-{
- struct zt_pvt *p = chan->tech_pvt;
- int res=-1;
- int index;
- int func = ZT_FLASH;
- ast_mutex_lock(&p->lock);
- index = zt_get_index(chan, p, 0);
- ast_log(LOG_DEBUG, "Requested indication %d on channel %s\n", condition, chan->name);
- if (index == SUB_REAL) {
- switch(condition) {
- case AST_CONTROL_BUSY:
-#ifdef ZAPATA_PRI
- if (p->priindication_oob && p->sig == SIG_PRI) {
- chan->hangupcause = AST_CAUSE_USER_BUSY;
- chan->_softhangup |= AST_SOFTHANGUP_DEV;
- res = 0;
- } else if (!p->progress && p->sig==SIG_PRI && p->pri && !p->outgoing) {
- if (p->pri->pri) {
- if (!pri_grab(p, p->pri)) {
- pri_progress(p->pri->pri,p->call, PVT_TO_CHANNEL(p), 1);
- pri_rel(p->pri);
- }
- else
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- }
- p->progress = 1;
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_BUSY);
- } else
-#endif
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_BUSY);
- break;
- case AST_CONTROL_RINGING:
-#ifdef ZAPATA_PRI
- if ((!p->alerting) && p->sig==SIG_PRI && p->pri && !p->outgoing && (chan->_state != AST_STATE_UP)) {
- if (p->pri->pri) {
- if (!pri_grab(p, p->pri)) {
- pri_acknowledge(p->pri->pri,p->call, PVT_TO_CHANNEL(p), !p->digital);
- pri_rel(p->pri);
- }
- else
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- }
- p->alerting = 1;
- }
-#endif
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_RINGTONE);
- if (chan->_state != AST_STATE_UP) {
- if ((chan->_state != AST_STATE_RING) ||
- ((p->sig != SIG_FXSKS) &&
- (p->sig != SIG_FXSLS) &&
- (p->sig != SIG_FXSGS)))
- ast_setstate(chan, AST_STATE_RINGING);
- }
- break;
- case AST_CONTROL_PROCEEDING:
- ast_log(LOG_DEBUG,"Received AST_CONTROL_PROCEEDING on %s\n",chan->name);
-#ifdef ZAPATA_PRI
- if (!p->proceeding && p->sig==SIG_PRI && p->pri && !p->outgoing) {
- if (p->pri->pri) {
- if (!pri_grab(p, p->pri)) {
- pri_proceeding(p->pri->pri,p->call, PVT_TO_CHANNEL(p), !p->digital);
- pri_rel(p->pri);
- }
- else
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- }
- p->proceeding = 1;
- }
-#endif
- /* don't continue in ast_indicate */
- res = 0;
- break;
- case AST_CONTROL_PROGRESS:
- ast_log(LOG_DEBUG,"Received AST_CONTROL_PROGRESS on %s\n",chan->name);
-#ifdef ZAPATA_PRI
- p->digital = 0; /* Digital-only calls isn't allows any inband progress messages */
- if (!p->progress && p->sig==SIG_PRI && p->pri && !p->outgoing) {
- if (p->pri->pri) {
- if (!pri_grab(p, p->pri)) {
- pri_progress(p->pri->pri,p->call, PVT_TO_CHANNEL(p), 1);
- pri_rel(p->pri);
- }
- else
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- }
- p->progress = 1;
- }
-#endif
- /* don't continue in ast_indicate */
- res = 0;
- break;
- case AST_CONTROL_CONGESTION:
- chan->hangupcause = AST_CAUSE_CONGESTION;
-#ifdef ZAPATA_PRI
- if (p->priindication_oob && p->sig == SIG_PRI) {
- chan->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
- chan->_softhangup |= AST_SOFTHANGUP_DEV;
- res = 0;
- } else if (!p->progress && p->sig==SIG_PRI && p->pri && !p->outgoing) {
- if (p->pri) {
- if (!pri_grab(p, p->pri)) {
- pri_progress(p->pri->pri,p->call, PVT_TO_CHANNEL(p), 1);
- pri_rel(p->pri);
- } else
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- }
- p->progress = 1;
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- } else
-#endif
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- break;
-#ifdef ZAPATA_PRI
- case AST_CONTROL_HOLD:
- if (p->pri) {
- if (!pri_grab(p, p->pri)) {
- res = pri_notify(p->pri->pri, p->call, p->prioffset, PRI_NOTIFY_REMOTE_HOLD);
- pri_rel(p->pri);
- } else
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- }
- break;
- case AST_CONTROL_UNHOLD:
- if (p->pri) {
- if (!pri_grab(p, p->pri)) {
- res = pri_notify(p->pri->pri, p->call, p->prioffset, PRI_NOTIFY_REMOTE_RETRIEVAL);
- pri_rel(p->pri);
- } else
- ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
- }
- break;
-#endif
- case AST_CONTROL_RADIO_KEY:
- if (p->radio)
- res = zt_set_hook(p->subs[index].zfd, ZT_OFFHOOK);
- res = 0;
- break;
- case AST_CONTROL_RADIO_UNKEY:
- if (p->radio)
- res = zt_set_hook(p->subs[index].zfd, ZT_RINGOFF);
- res = 0;
- break;
- case AST_CONTROL_FLASH:
- /* flash hookswitch */
- if (ISTRUNK(p) && (p->sig != SIG_PRI)) {
- /* Clear out the dial buffer */
- p->dop.dialstr[0] = '\0';
- if ((ioctl(p->subs[SUB_REAL].zfd,ZT_HOOK,&func) == -1) && (errno != EINPROGRESS)) {
- ast_log(LOG_WARNING, "Unable to flash external trunk on channel %s: %s\n",
- chan->name, strerror(errno));
- } else
- res = 0;
- } else
- res = 0;
- break;
- case -1:
- res = tone_zone_play_tone(p->subs[index].zfd, -1);
- break;
- }
- } else
- res = 0;
- ast_mutex_unlock(&p->lock);
- return res;
-}
-
-static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int index, int law, int transfercapability)
-{
- struct ast_channel *tmp;
- int deflaw;
- int res;
- int x,y;
- int features;
- ZT_PARAMS ps;
- if (i->subs[index].owner) {
- ast_log(LOG_WARNING, "Channel %d already has a %s call\n", i->channel,subnames[index]);
- return NULL;
- }
- tmp = ast_channel_alloc(0);
- if (tmp) {
- tmp->tech = &zap_tech;
- ps.channo = i->channel;
- res = ioctl(i->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &ps);
- if (res) {
- ast_log(LOG_WARNING, "Unable to get parameters, assuming MULAW\n");
- ps.curlaw = ZT_LAW_MULAW;
- }
- if (ps.curlaw == ZT_LAW_ALAW)
- deflaw = AST_FORMAT_ALAW;
- else
- deflaw = AST_FORMAT_ULAW;
- if (law) {
- if (law == ZT_LAW_ALAW)
- deflaw = AST_FORMAT_ALAW;
- else
- deflaw = AST_FORMAT_ULAW;
- }
- y = 1;
- do {
-#ifdef ZAPATA_PRI
- if (i->bearer || (i->pri && (i->sig == SIG_FXSKS)))
- snprintf(tmp->name, sizeof(tmp->name), "Zap/%d:%d-%d", i->pri->trunkgroup, i->channel, y);
- else
-#endif
- if (i->channel == CHAN_PSEUDO)
- snprintf(tmp->name, sizeof(tmp->name), "Zap/pseudo-%d", rand());
- else
- snprintf(tmp->name, sizeof(tmp->name), "Zap/%d-%d", i->channel, y);
- for (x=0;x<3;x++) {
- if ((index != x) && i->subs[x].owner && !strcasecmp(tmp->name, i->subs[x].owner->name))
- break;
- }
- y++;
- } while (x < 3);
- tmp->type = type;
- tmp->fds[0] = i->subs[index].zfd;
- tmp->nativeformats = AST_FORMAT_SLINEAR | deflaw;
- /* Start out assuming ulaw since it's smaller :) */
- tmp->rawreadformat = deflaw;
- tmp->readformat = deflaw;
- tmp->rawwriteformat = deflaw;
- tmp->writeformat = deflaw;
- i->subs[index].linear = 0;
- zt_setlinear(i->subs[index].zfd, i->subs[index].linear);
- features = 0;
- if (i->busydetect && CANBUSYDETECT(i)) {
- features |= DSP_FEATURE_BUSY_DETECT;
- }
- if ((i->callprogress & 1) && CANPROGRESSDETECT(i)) {
- features |= DSP_FEATURE_CALL_PROGRESS;
- }
- if ((!i->outgoing && (i->callprogress & 4)) ||
- (i->outgoing && (i->callprogress & 2))) {
- features |= DSP_FEATURE_FAX_DETECT;
- }
-#ifdef ZT_TONEDETECT
- x = ZT_TONEDETECT_ON | ZT_TONEDETECT_MUTE;
- if (ioctl(i->subs[index].zfd, ZT_TONEDETECT, &x)) {
-#endif
- i->hardwaredtmf = 0;
- features |= DSP_FEATURE_DTMF_DETECT;
-#ifdef ZT_TONEDETECT
- } else if (NEED_MFDETECT(i)) {
- i->hardwaredtmf = 1;
- features |= DSP_FEATURE_DTMF_DETECT;
- }
-#endif
- if (features) {
- if (i->dsp) {
- ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", tmp->name);
- } else {
- if (i->channel != CHAN_PSEUDO)
- i->dsp = ast_dsp_new();
- else
- i->dsp = NULL;
- if (i->dsp) {
- i->dsp_features = features & ~DSP_PROGRESS_TALK;
-#ifdef ZAPATA_PRI
- /* We cannot do progress detection until receives PROGRESS message */
- if (i->outgoing && (i->sig == SIG_PRI)) {
- /* Remember requested DSP features, don't treat
- talking as ANSWER */
- features = 0;
- }
-#endif
- ast_dsp_set_features(i->dsp, features);
- ast_dsp_digitmode(i->dsp, DSP_DIGITMODE_DTMF | i->dtmfrelax);
- if (!ast_strlen_zero(progzone))
- ast_dsp_set_call_progress_zone(i->dsp, progzone);
- if (i->busydetect && CANBUSYDETECT(i)) {
- ast_dsp_set_busy_count(i->dsp, i->busycount);
- ast_dsp_set_busy_pattern(i->dsp, i->busy_tonelength, i->busy_quietlength);
- }
- }
- }
- }
-
- if (state == AST_STATE_RING)
- tmp->rings = 1;
- tmp->tech_pvt = i;
- if ((i->sig == SIG_FXOKS) || (i->sig == SIG_FXOGS) || (i->sig == SIG_FXOLS)) {
- /* Only FXO signalled stuff can be picked up */
- tmp->callgroup = i->callgroup;
- tmp->pickupgroup = i->pickupgroup;
- }
- if (!ast_strlen_zero(i->language))
- ast_copy_string(tmp->language, i->language, sizeof(tmp->language));
- if (!ast_strlen_zero(i->musicclass))
- ast_copy_string(tmp->musicclass, i->musicclass, sizeof(tmp->musicclass));
- if (!i->owner)
- i->owner = tmp;
- if (!ast_strlen_zero(i->accountcode))
- ast_copy_string(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode));
- if (i->amaflags)
- tmp->amaflags = i->amaflags;
- i->subs[index].owner = tmp;
- ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
- /* Copy call forward info */
- ast_copy_string(tmp->call_forward, i->call_forward, sizeof(tmp->call_forward));
- /* If we've been told "no ADSI" then enforce it */
- if (!i->adsi)
- tmp->adsicpe = AST_ADSI_UNAVAILABLE;
- if (!ast_strlen_zero(i->exten))
- ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
- if (!ast_strlen_zero(i->rdnis))
- tmp->cid.cid_rdnis = strdup(i->rdnis);
- if (!ast_strlen_zero(i->dnid))
- tmp->cid.cid_dnid = strdup(i->dnid);
-
-#ifdef PRI_ANI
- ast_set_callerid(tmp, i->cid_num, i->cid_name, ast_strlen_zero(i->cid_ani) ? i->cid_num : i->cid_ani);
-#else
- ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
-#endif
- tmp->cid.cid_pres = i->callingpres;
- tmp->cid.cid_ton = i->cid_ton;
-#ifdef ZAPATA_PRI
- tmp->transfercapability = transfercapability;
- pbx_builtin_setvar_helper(tmp, "TRANSFERCAPABILITY", ast_transfercapability2str(transfercapability));
- if (transfercapability & PRI_TRANS_CAP_DIGITAL) {
- i->digital = 1;
- }
- /* Assume calls are not idle calls unless we're told differently */
- i->isidlecall = 0;
- i->alreadyhungup = 0;
-#endif
- /* clear the fake event in case we posted one before we had ast_channel */
- i->fake_event = 0;
- /* Assure there is no confmute on this channel */
- zt_confmute(i, 0);
- ast_setstate(tmp, state);
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (startpbx) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- tmp = NULL;
- }
- }
- } else
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- return tmp;
-}
-
-
-static int my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
-{
- char c;
-
- *str = 0; /* start with empty output buffer */
- for (;;)
- {
- /* Wait for the first digit (up to specified ms). */
- c = ast_waitfordigit(chan, ms);
- /* if timeout, hangup or error, return as such */
- if (c < 1)
- return c;
- *str++ = c;
- *str = 0;
- if (strchr(term, c))
- return 1;
- }
-}
-
-static int zt_wink(struct zt_pvt *p, int index)
-{
- int j;
- zt_set_hook(p->subs[index].zfd, ZT_WINK);
- for(;;)
- {
- /* set bits of interest */
- j = ZT_IOMUX_SIGEVENT;
- /* wait for some happening */
- if (ioctl(p->subs[index].zfd,ZT_IOMUX,&j) == -1) return(-1);
- /* exit loop if we have it */
- if (j & ZT_IOMUX_SIGEVENT) break;
- }
- /* get the event info */
- if (ioctl(p->subs[index].zfd,ZT_GETEVENT,&j) == -1) return(-1);
- return 0;
-}
-
-static void *ss_thread(void *data)
-{
- struct ast_channel *chan = data;
- struct zt_pvt *p = chan->tech_pvt;
- char exten[AST_MAX_EXTENSION]="";
- char exten2[AST_MAX_EXTENSION]="";
- unsigned char buf[256];
- char dtmfcid[300];
- char dtmfbuf[300];
- struct callerid_state *cs;
- char *name=NULL, *number=NULL;
- int distMatches;
- int curRingData[3];
- int receivedRingT;
- int counter1;
- int counter;
- int samples = 0;
-
- int flags;
- int i;
- int timeout;
- int getforward=0;
- char *s1, *s2;
- int len = 0;
- int res;
- int index;
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Starting simple switch on '%s'\n", chan->name);
- index = zt_get_index(chan, p, 1);
- if (index < 0) {
- ast_log(LOG_WARNING, "Huh?\n");
- ast_hangup(chan);
- return NULL;
- }
- if (p->dsp)
- ast_dsp_digitreset(p->dsp);
- switch(p->sig) {
-#ifdef ZAPATA_PRI
- case SIG_PRI:
- /* Now loop looking for an extension */
- ast_copy_string(exten, p->exten, sizeof(exten));
- len = strlen(exten);
- res = 0;
- while((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
- if (len && !ast_ignore_pattern(chan->context, exten))
- tone_zone_play_tone(p->subs[index].zfd, -1);
- else
- tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);
- if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num))
- timeout = matchdigittimeout;
- else
- timeout = gendigittimeout;
- res = ast_waitfordigit(chan, timeout);
- if (res < 0) {
- ast_log(LOG_DEBUG, "waitfordigit returned < 0...\n");
- ast_hangup(chan);
- return NULL;
- } else if (res) {
- exten[len++] = res;
- exten[len] = '\0';
- } else
- break;
- }
- /* if no extension was received ('unspecified') on overlap call, use the 's' extension */
- if (ast_strlen_zero(exten)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Going to extension s|1 because of empty extension received on overlap call\n");
- exten[0] = 's';
- exten[1] = '\0';
- }
- tone_zone_play_tone(p->subs[index].zfd, -1);
- if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num)) {
- /* Start the real PBX */
- ast_copy_string(chan->exten, exten, sizeof(chan->exten));
- if (p->dsp) ast_dsp_digitreset(p->dsp);
- zt_enable_ec(p);
- ast_setstate(chan, AST_STATE_RING);
- res = ast_pbx_run(chan);
- if (res) {
- ast_log(LOG_WARNING, "PBX exited non-zero!\n");
- }
- } else {
- ast_log(LOG_DEBUG, "No such possible extension '%s' in context '%s'\n", exten, chan->context);
- chan->hangupcause = AST_CAUSE_UNALLOCATED;
- ast_hangup(chan);
- p->exten[0] = '\0';
- /* Since we send release complete here, we won't get one */
- p->call = NULL;
- }
- return NULL;
- break;
-#endif
- case SIG_FEATD:
- case SIG_FEATDMF:
- case SIG_E911:
- case SIG_FEATB:
- case SIG_EMWINK:
- case SIG_SF_FEATD:
- case SIG_SF_FEATDMF:
- case SIG_SF_FEATB:
- case SIG_SFWINK:
- if (zt_wink(p, index))
- return NULL;
- /* Fall through */
- case SIG_EM:
- case SIG_EM_E1:
- case SIG_SF:
- res = tone_zone_play_tone(p->subs[index].zfd, -1);
- if (p->dsp)
- ast_dsp_digitreset(p->dsp);
- /* set digit mode appropriately */
- if (p->dsp) {
- if (NEED_MFDETECT(p))
- ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_MF | p->dtmfrelax);
- else
- ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_DTMF | p->dtmfrelax);
- }
- memset(dtmfbuf, 0, sizeof(dtmfbuf));
- /* Wait for the first digit only if immediate=no */
- if (!p->immediate)
- /* Wait for the first digit (up to 5 seconds). */
- res = ast_waitfordigit(chan, 5000);
- else res = 0;
- if (res > 0) {
- /* save first char */
- dtmfbuf[0] = res;
- switch(p->sig) {
- case SIG_FEATD:
- case SIG_SF_FEATD:
- res = my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
- if (res > 0)
- res = my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
- if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp);
- break;
- case SIG_FEATDMF:
- case SIG_E911:
- case SIG_SF_FEATDMF:
- res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
- if (res > 0) {
- /* if E911, take off hook */
- if (p->sig == SIG_E911)
- zt_set_hook(p->subs[SUB_REAL].zfd, ZT_OFFHOOK);
- res = my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000);
- }
- if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp);
- break;
- case SIG_FEATB:
- case SIG_SF_FEATB:
- res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
- if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp);
- break;
- case SIG_EMWINK:
- /* if we received a '*', we are actually receiving Feature Group D
- dial syntax, so use that mode; otherwise, fall through to normal
- mode
- */
- if (res == '*') {
- res = my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
- if (res > 0)
- res = my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
- if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp);
- break;
- }
- default:
- /* If we got the first digit, get the rest */
- len = 1;
- dtmfbuf[len] = '\0';
- while((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, dtmfbuf, 1, p->cid_num)) {
- if (ast_exists_extension(chan, chan->context, dtmfbuf, 1, p->cid_num)) {
- timeout = matchdigittimeout;
- } else {
- timeout = gendigittimeout;
- }
- res = ast_waitfordigit(chan, timeout);
- if (res < 0) {
- ast_log(LOG_DEBUG, "waitfordigit returned < 0...\n");
- ast_hangup(chan);
- return NULL;
- } else if (res) {
- dtmfbuf[len++] = res;
- dtmfbuf[len] = '\0';
- } else {
- break;
- }
- }
- break;
- }
- }
- if (res == -1) {
- ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno));
- ast_hangup(chan);
- return NULL;
- } else if (res < 0) {
- ast_log(LOG_DEBUG, "Got hung up before digits finished\n");
- ast_hangup(chan);
- return NULL;
- }
- ast_copy_string(exten, dtmfbuf, sizeof(exten));
- if (ast_strlen_zero(exten))
- ast_copy_string(exten, "s", sizeof(exten));
- if (p->sig == SIG_FEATD || p->sig == SIG_EMWINK) {
- /* Look for Feature Group D on all E&M Wink and Feature Group D trunks */
- if (exten[0] == '*') {
- char *stringp=NULL;
- ast_copy_string(exten2, exten, sizeof(exten2));
- /* Parse out extension and callerid */
- stringp=exten2 +1;
- s1 = strsep(&stringp, "*");
- s2 = strsep(&stringp, "*");
- if (s2) {
- if (!ast_strlen_zero(p->cid_num))
- ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
- else
- ast_set_callerid(chan, s1, NULL, s1);
- ast_copy_string(exten, s2, sizeof(exten));
- } else
- ast_copy_string(exten, s1, sizeof(exten));
- } else if (p->sig == SIG_FEATD)
- ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
- }
- if (p->sig == SIG_FEATDMF) {
- if (exten[0] == '*') {
- char *stringp=NULL;
- ast_copy_string(exten2, exten, sizeof(exten2));
- /* Parse out extension and callerid */
- stringp=exten2 +1;
- s1 = strsep(&stringp, "#");
- s2 = strsep(&stringp, "#");
- if (s2) {
- if (!ast_strlen_zero(p->cid_num))
- ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
- else
- if(*(s1 + 2))
- ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
- ast_copy_string(exten, s2 + 1, sizeof(exten));
- } else
- ast_copy_string(exten, s1 + 2, sizeof(exten));
- } else
- ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
- }
- if (p->sig == SIG_E911) {
- if (exten[0] == '*') {
- char *stringp=NULL;
- ast_copy_string(exten2, exten, sizeof(exten2));
- /* Parse out extension and callerid */
- stringp=exten2 +1;
- s1 = strsep(&stringp, "#");
- s2 = strsep(&stringp, "#");
- if (s2 && (*(s2 + 1) == '0')) {
- if(*(s2 + 2))
- ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
- }
- if (s1) ast_copy_string(exten, s1, sizeof(exten));
- else ast_copy_string(exten, "911", sizeof(exten));
- printf("E911: exten: %s, ANI: %s\n",exten, chan->cid.cid_ani);
- } else
- ast_log(LOG_WARNING, "Got a non-E911 input on channel %d. Assuming E&M Wink instead\n", p->channel);
- }
- if (p->sig == SIG_FEATB) {
- if (exten[0] == '*') {
- char *stringp=NULL;
- ast_copy_string(exten2, exten, sizeof(exten2));
- /* Parse out extension and callerid */
- stringp=exten2 +1;
- s1 = strsep(&stringp, "#");
- ast_copy_string(exten, exten2 + 1, sizeof(exten));
- } else
- ast_log(LOG_WARNING, "Got a non-Feature Group B input on channel %d. Assuming E&M Wink instead\n", p->channel);
- }
- if (p->sig == SIG_FEATDMF) {
- zt_wink(p, index);
- }
- zt_enable_ec(p);
- if (NEED_MFDETECT(p)) {
- if (p->dsp) {
- if (!p->hardwaredtmf)
- ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_DTMF | p->dtmfrelax);
- else {
- ast_dsp_free(p->dsp);
- p->dsp = NULL;
- }
- }
- }
-
- if (ast_exists_extension(chan, chan->context, exten, 1, chan->cid.cid_num)) {
- ast_copy_string(chan->exten, exten, sizeof(chan->exten));
- if (p->dsp) ast_dsp_digitreset(p->dsp);
- res = ast_pbx_run(chan);
- if (res) {
- ast_log(LOG_WARNING, "PBX exited non-zero\n");
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- }
- return NULL;
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_2 "Unknown extension '%s' in context '%s' requested\n", exten, chan->context);
- sleep(2);
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_INFO);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel);
- else
- sleep(1);
- res = ast_streamfile(chan, "ss-noservice", chan->language);
- if (res >= 0)
- ast_waitstream(chan, "");
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- ast_hangup(chan);
- return NULL;
- }
- break;
- case SIG_FXOLS:
- case SIG_FXOGS:
- case SIG_FXOKS:
- /* Read the first digit */
- timeout = firstdigittimeout;
- /* If starting a threeway call, never timeout on the first digit so someone
- can use flash-hook as a "hold" feature */
- if (p->subs[SUB_THREEWAY].owner)
- timeout = 999999;
- while(len < AST_MAX_EXTENSION-1) {
- /* Read digit unless it's supposed to be immediate, in which case the
- only answer is 's' */
- if (p->immediate)
- res = 's';
- else
- res = ast_waitfordigit(chan, timeout);
- timeout = 0;
- if (res < 0) {
- ast_log(LOG_DEBUG, "waitfordigit returned < 0...\n");
- res = tone_zone_play_tone(p->subs[index].zfd, -1);
- ast_hangup(chan);
- return NULL;
- } else if (res) {
- exten[len++]=res;
- exten[len] = '\0';
- }
- if (!ast_ignore_pattern(chan->context, exten))
- tone_zone_play_tone(p->subs[index].zfd, -1);
- else
- tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);
- if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num) && strcmp(exten, ast_parking_ext())) {
- if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
- if (getforward) {
- /* Record this as the forwarding extension */
- ast_copy_string(p->call_forward, exten, sizeof(p->call_forward));
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Setting call forward to '%s' on channel %d\n", p->call_forward, p->channel);
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- if (res)
- break;
- usleep(500000);
- res = tone_zone_play_tone(p->subs[index].zfd, -1);
- sleep(1);
- memset(exten, 0, sizeof(exten));
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);
- len = 0;
- getforward = 0;
- } else {
- res = tone_zone_play_tone(p->subs[index].zfd, -1);
- ast_copy_string(chan->exten, exten, sizeof(chan->exten));
- if (!ast_strlen_zero(p->cid_num)) {
- if (!p->hidecallerid)
- ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
- else
- ast_set_callerid(chan, NULL, NULL, p->cid_num);
- }
- if (!ast_strlen_zero(p->cid_name)) {
- if (!p->hidecallerid)
- ast_set_callerid(chan, NULL, p->cid_name, NULL);
- }
- ast_setstate(chan, AST_STATE_RING);
- zt_enable_ec(p);
- res = ast_pbx_run(chan);
- if (res) {
- ast_log(LOG_WARNING, "PBX exited non-zero\n");
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- }
- return NULL;
- }
- } else {
- /* It's a match, but they just typed a digit, and there is an ambiguous match,
- so just set the timeout to matchdigittimeout and wait some more */
- timeout = matchdigittimeout;
- }
- } else if (res == 0) {
- ast_log(LOG_DEBUG, "not enough digits (and no ambiguous match)...\n");
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- zt_wait_event(p->subs[index].zfd);
- ast_hangup(chan);
- return NULL;
- } else if (p->callwaiting && !strcmp(exten, "*70")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Disabling call waiting on %s\n", chan->name);
- /* Disable call waiting if enabled */
- p->callwaiting = 0;
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- if (res) {
- ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
- chan->name, strerror(errno));
- }
- len = 0;
- ioctl(p->subs[index].zfd,ZT_CONFDIAG,&len);
- memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
-
- } else if (!strcmp(exten,ast_pickup_ext())) {
- /* Scan all channels and see if any there
- * ringing channqels with that have call groups
- * that equal this channels pickup group
- */
- if (index == SUB_REAL) {
- /* Switch us from Third call to Call Wait */
- if (p->subs[SUB_THREEWAY].owner) {
- /* If you make a threeway call and the *8# a call, it should actually
- look like a callwait */
- alloc_sub(p, SUB_CALLWAIT);
- swap_subs(p, SUB_CALLWAIT, SUB_THREEWAY);
- unalloc_sub(p, SUB_THREEWAY);
- }
- zt_enable_ec(p);
- if (ast_pickup_call(chan)) {
- ast_log(LOG_DEBUG, "No call pickup possible...\n");
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- zt_wait_event(p->subs[index].zfd);
- }
- ast_hangup(chan);
- return NULL;
- } else {
- ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n");
- ast_hangup(chan);
- return NULL;
- }
-
- } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Disabling Caller*ID on %s\n", chan->name);
- /* Disable Caller*ID if enabled */
- p->hidecallerid = 1;
- if (chan->cid.cid_num)
- free(chan->cid.cid_num);
- chan->cid.cid_num = NULL;
- if (chan->cid.cid_name)
- free(chan->cid.cid_name);
- chan->cid.cid_name = NULL;
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- if (res) {
- ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
- chan->name, strerror(errno));
- }
- len = 0;
- memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
- } else if (p->callreturn && !strcmp(exten, "*69")) {
- res = 0;
- if (!ast_strlen_zero(p->lastcid_num)) {
- res = ast_say_digit_str(chan, p->lastcid_num, "", chan->language);
- }
- if (!res)
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- break;
- } else if (!strcmp(exten, "*78")) {
- /* Do not disturb */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Enabled DND on channel %d\n", p->channel);
- manager_event(EVENT_FLAG_SYSTEM, "DNDState",
- "Channel: Zap/%d\r\n"
- "Status: enabled\r\n", p->channel);
- }
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- p->dnd = 1;
- getforward = 0;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (!strcmp(exten, "*79")) {
- /* Do not disturb */
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Disabled DND on channel %d\n", p->channel);
- manager_event(EVENT_FLAG_SYSTEM, "DNDState",
- "Channel: Zap/%d\r\n"
- "Status: disabled\r\n", p->channel);
- }
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- p->dnd = 0;
- getforward = 0;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (p->cancallforward && !strcmp(exten, "*72")) {
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- getforward = 1;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if (p->cancallforward && !strcmp(exten, "*73")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Cancelling call forwarding on channel %d\n", p->channel);
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- memset(p->call_forward, 0, sizeof(p->call_forward));
- getforward = 0;
- memset(exten, 0, sizeof(exten));
- len = 0;
- } else if ((p->transfer || p->canpark) && !strcmp(exten, ast_parking_ext()) &&
- p->subs[SUB_THREEWAY].owner &&
- ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) {
- /* This is a three way call, the main call being a real channel,
- and we're parking the first call. */
- ast_masq_park_call(ast_bridged_channel(p->subs[SUB_THREEWAY].owner), chan, 0, NULL);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Parking call to '%s'\n", chan->name);
- break;
- } else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Blacklisting number %s\n", p->lastcid_num);
- res = ast_db_put("blacklist", p->lastcid_num, "1");
- if (!res) {
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- memset(exten, 0, sizeof(exten));
- len = 0;
- }
- } else if (p->hidecallerid && !strcmp(exten, "*82")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Enabling Caller*ID on %s\n", chan->name);
- /* Enable Caller*ID if enabled */
- p->hidecallerid = 0;
- if (chan->cid.cid_num)
- free(chan->cid.cid_num);
- chan->cid.cid_num = NULL;
- if (chan->cid.cid_name)
- free(chan->cid.cid_name);
- chan->cid.cid_name = NULL;
- ast_set_callerid(chan, p->cid_num, p->cid_name, NULL);
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
- if (res) {
- ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
- chan->name, strerror(errno));
- }
- len = 0;
- memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
- } else if (!strcmp(exten, "*0")) {
- struct ast_channel *nbridge =
- p->subs[SUB_THREEWAY].owner;
- struct zt_pvt *pbridge = NULL;
- /* set up the private struct of the bridged one, if any */
- if (nbridge && ast_bridged_channel(nbridge))
- pbridge = ast_bridged_channel(nbridge)->tech_pvt;
- if (nbridge && pbridge &&
- (!strcmp(nbridge->type,"Zap")) &&
- (!strcmp(ast_bridged_channel(nbridge)->type, "Zap")) &&
- ISTRUNK(pbridge)) {
- int func = ZT_FLASH;
- /* Clear out the dial buffer */
- p->dop.dialstr[0] = '\0';
- /* flash hookswitch */
- if ((ioctl(pbridge->subs[SUB_REAL].zfd,ZT_HOOK,&func) == -1) && (errno != EINPROGRESS)) {
- ast_log(LOG_WARNING, "Unable to flash external trunk on channel %s: %s\n",
- nbridge->name, strerror(errno));
- }
- swap_subs(p, SUB_REAL, SUB_THREEWAY);
- unalloc_sub(p, SUB_THREEWAY);
- p->owner = p->subs[SUB_REAL].owner;
- if (ast_bridged_channel(p->subs[SUB_REAL].owner))
- ast_moh_stop(ast_bridged_channel(p->subs[SUB_REAL].owner));
- ast_hangup(chan);
- return NULL;
- } else {
- tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- zt_wait_event(p->subs[index].zfd);
- tone_zone_play_tone(p->subs[index].zfd, -1);
- swap_subs(p, SUB_REAL, SUB_THREEWAY);
- unalloc_sub(p, SUB_THREEWAY);
- p->owner = p->subs[SUB_REAL].owner;
- ast_hangup(chan);
- return NULL;
- }
- } else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->cid.cid_num) &&
- ((exten[0] != '*') || (strlen(exten) > 2))) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Can't match %s from '%s' in context %s\n", exten, chan->cid.cid_num ? chan->cid.cid_num : "<Unknown Caller>", chan->context);
- break;
- }
- if (!timeout)
- timeout = gendigittimeout;
- if (len && !ast_ignore_pattern(chan->context, exten))
- tone_zone_play_tone(p->subs[index].zfd, -1);
- }
- break;
- case SIG_FXSLS:
- case SIG_FXSGS:
- case SIG_FXSKS:
-#ifdef ZAPATA_PRI
- if (p->pri) {
- /* This is a GR-303 trunk actually. Wait for the first ring... */
- struct ast_frame *f;
- int res;
- time_t start;
-
- time(&start);
- ast_setstate(chan, AST_STATE_RING);
- while(time(NULL) < start + 3) {
- res = ast_waitfor(chan, 1000);
- if (res) {
- f = ast_read(chan);
- if (!f) {
- ast_log(LOG_WARNING, "Whoa, hangup while waiting for first ring!\n");
- ast_hangup(chan);
- return NULL;
- } else if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) {
- res = 1;
- } else
- res = 0;
- ast_frfree(f);
- if (res) {
- ast_log(LOG_DEBUG, "Got ring!\n");
- res = 0;
- break;
- }
- }
- }
- }
-#endif
- /* If we want caller id, we're in a prering state due to a polarity reversal
- * and we're set to use a polarity reversal to trigger the start of caller id,
- * grab the caller id and wait for ringing to start... */
- if (p->use_callerid && (chan->_state == AST_STATE_PRERING && p->cid_start == CID_START_POLARITY)) {
- /* If set to use DTMF CID signalling, listen for DTMF */
- if (p->cid_signalling == CID_SIG_DTMF) {
- int i = 0;
- cs = NULL;
- ast_log(LOG_DEBUG, "Receiving DTMF cid on "
- "channel %s\n", chan->name);
- zt_setlinear(p->subs[index].zfd, 0);
- res = 2000;
- for (;;) {
- struct ast_frame *f;
- res = ast_waitfor(chan, res);
- if (res <= 0) {
- ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. "
- "Exiting simple switch\n");
- ast_hangup(chan);
- return NULL;
- }
- f = ast_read(chan);
- if (f->frametype == AST_FRAME_DTMF) {
- dtmfbuf[i++] = f->subclass;
- ast_log(LOG_DEBUG, "CID got digit '%c'\n", f->subclass);
- res = 2000;
- }
- ast_frfree(f);
- if (chan->_state == AST_STATE_RING ||
- chan->_state == AST_STATE_RINGING)
- break; /* Got ring */
- }
- dtmfbuf[i] = 0;
- zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
- /* Got cid and ring. */
- ast_log(LOG_DEBUG, "CID got string '%s'\n", dtmfbuf);
- callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
- ast_log(LOG_DEBUG, "CID is '%s', flags %d\n",
- dtmfcid, flags);
- /* If first byte is NULL, we have no cid */
- if (dtmfcid[0])
- number = dtmfcid;
- else
- number = 0;
- /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
- } else if (p->cid_signalling == CID_SIG_V23) {
- cs = callerid_new(cid_signalling);
- if (cs) {
- samples = 0;
-#if 1
- bump_gains(p);
-#endif
- /* Take out of linear mode for Caller*ID processing */
- zt_setlinear(p->subs[index].zfd, 0);
-
- /* First we wait and listen for the Caller*ID */
- for(;;) {
- i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT;
- if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i))) {
- ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
- callerid_free(cs);
- ast_hangup(chan);
- return NULL;
- }
- if (i & ZT_IOMUX_SIGEVENT) {
- res = zt_get_event(p->subs[index].zfd);
- ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
- res = 0;
- break;
- } else if (i & ZT_IOMUX_READ) {
- res = read(p->subs[index].zfd, buf, sizeof(buf));
- if (res < 0) {
- if (errno != ELAST) {
- ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
- callerid_free(cs);
- ast_hangup(chan);
- return NULL;
- }
- break;
- }
- samples += res;
- res = callerid_feed(cs, buf, res, AST_LAW(p));
- if (res < 0) {
- ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno));
- break;
- } else if (res)
- break;
- else if (samples > (8000 * 10))
- break;
- }
- }
- if (res == 1) {
- callerid_get(cs, &name, &number, &flags);
- if (option_debug)
- ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags);
- }
- if (res < 0) {
- ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name);
- }
-
- /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
- res = 2000;
- for (;;) {
- struct ast_frame *f;
- res = ast_waitfor(chan, res);
- if (res <= 0) {
- ast_log(LOG_WARNING, "CID timed out waiting for ring. "
- "Exiting simple switch\n");
- ast_hangup(chan);
- return NULL;
- }
- f = ast_read(chan);
- ast_frfree(f);
- if (chan->_state == AST_STATE_RING ||
- chan->_state == AST_STATE_RINGING)
- break; /* Got ring */
- }
-
- /* We must have a ring by now, so, if configured, lets try to listen for
- * distinctive ringing */
- if (p->usedistinctiveringdetection == 1) {
- len = 0;
- distMatches = 0;
- /* Clear the current ring data array so we dont have old data in it. */
- for (receivedRingT=0; receivedRingT < 3; receivedRingT++) {
- curRingData[receivedRingT] = 0;
- }
- receivedRingT = 0;
- counter = 0;
- counter1 = 0;
- /* Check to see if context is what it should be, if not set to be. */
- if (strcmp(p->context,p->defcontext) != 0) {
- ast_copy_string(p->context, p->defcontext, sizeof(p->context));
- ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
- }
-
- for(;;) {
- i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT;
- if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i))) {
- ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
- callerid_free(cs);
- ast_hangup(chan);
- return NULL;
- }
- if (i & ZT_IOMUX_SIGEVENT) {
- res = zt_get_event(p->subs[index].zfd);
- ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
- res = 0;
- /* Let us detect distinctive ring */
-
- curRingData[receivedRingT] = p->ringt;
-
- if (p->ringt < p->ringt_base/2)
- break;
- ++receivedRingT; /* Increment the ringT counter so we can match it against
- values in zapata.conf for distinctive ring */
- } else if (i & ZT_IOMUX_READ) {
- res = read(p->subs[index].zfd, buf, sizeof(buf));
- if (res < 0) {
- if (errno != ELAST) {
- ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
- callerid_free(cs);
- ast_hangup(chan);
- return NULL;
- }
- break;
- }
- if (p->ringt)
- p->ringt--;
- if (p->ringt == 1) {
- res = -1;
- break;
- }
- }
- }
- if(option_verbose > 2)
- /* this only shows up if you have n of the dring patterns filled in */
- ast_verbose( VERBOSE_PREFIX_3 "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]);
-
- for (counter=0; counter < 3; counter++) {
- /* Check to see if the rings we received match any of the ones in zapata.conf for this
- channel */
- distMatches = 0;
- for (counter1=0; counter1 < 3; counter1++) {
- if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1]+10) && curRingData[counter1] >=
- (p->drings.ringnum[counter].ring[counter1]-10)) {
- distMatches++;
- }
- }
- if (distMatches == 3) {
- /* The ring matches, set the context to whatever is for distinctive ring.. */
- ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
- ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
- if(option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Distinctive Ring matched context %s\n",p->context);
- break;
- }
- }
- }
- /* Restore linear mode (if appropriate) for Caller*ID processing */
- zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
-#if 1
- restore_gains(p);
-#endif
- } else
- ast_log(LOG_WARNING, "Unable to get caller ID space\n");
- } else {
- ast_log(LOG_WARNING, "Channel %s in prering "
- "state, but I have nothing to do. "
- "Terminating simple switch, should be "
- "restarted by the actual ring.\n",
- chan->name);
- ast_hangup(chan);
- return NULL;
- }
- } else if (p->use_callerid && p->cid_start == CID_START_RING) {
- /* FSK Bell202 callerID */
- cs = callerid_new(cid_signalling);
- if (cs) {
-#if 1
- bump_gains(p);
-#endif
- samples = 0;
- len = 0;
- distMatches = 0;
- /* Clear the current ring data array so we dont have old data in it. */
- for (receivedRingT=0; receivedRingT < 3; receivedRingT++) {
- curRingData[receivedRingT] = 0;
- }
- receivedRingT = 0;
- counter = 0;
- counter1 = 0;
- /* Check to see if context is what it should be, if not set to be. */
- if (strcmp(p->context,p->defcontext) != 0) {
- ast_copy_string(p->context, p->defcontext, sizeof(p->context));
- ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
- }
-
- /* Take out of linear mode for Caller*ID processing */
- zt_setlinear(p->subs[index].zfd, 0);
- for(;;) {
- i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT;
- if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i))) {
- ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
- callerid_free(cs);
- ast_hangup(chan);
- return NULL;
- }
- if (i & ZT_IOMUX_SIGEVENT) {
- res = zt_get_event(p->subs[index].zfd);
- ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
- res = 0;
- /* Let us detect callerid when the telco uses distinctive ring */
-
- curRingData[receivedRingT] = p->ringt;
-
- if (p->ringt < p->ringt_base/2)
- break;
- ++receivedRingT; /* Increment the ringT counter so we can match it against
- values in zapata.conf for distinctive ring */
- } else if (i & ZT_IOMUX_READ) {
- res = read(p->subs[index].zfd, buf, sizeof(buf));
- if (res < 0) {
- if (errno != ELAST) {
- ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
- callerid_free(cs);
- ast_hangup(chan);
- return NULL;
- }
- break;
- }
- if (p->ringt)
- p->ringt--;
- if (p->ringt == 1) {
- res = -1;
- break;
- }
- samples += res;
- res = callerid_feed(cs, buf, res, AST_LAW(p));
- if (res < 0) {
- ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno));
- break;
- } else if (res)
- break;
- else if (samples > (8000 * 10))
- break;
- }
- }
- if (p->usedistinctiveringdetection == 1) {
- if(option_verbose > 2)
- /* this only shows up if you have n of the dring patterns filled in */
- ast_verbose( VERBOSE_PREFIX_3 "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]);
-
- for (counter=0; counter < 3; counter++) {
- /* Check to see if the rings we received match any of the ones in zapata.conf for this
- channel */
- distMatches = 0;
- for (counter1=0; counter1 < 3; counter1++) {
- if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1]+10) && curRingData[counter1] >=
- (p->drings.ringnum[counter].ring[counter1]-10)) {
- distMatches++;
- }
- }
- if (distMatches == 3) {
- /* The ring matches, set the context to whatever is for distinctive ring.. */
- ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
- ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
- if(option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Distinctive Ring matched context %s\n",p->context);
- break;
- }
- }
- }
- if (res == 1) {
- callerid_get(cs, &name, &number, &flags);
- if (option_debug)
- ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags);
- }
- /* Restore linear mode (if appropriate) for Caller*ID processing */
- zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
-#if 1
- restore_gains(p);
-#endif
- if (res < 0) {
- ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name);
- }
- } else
- ast_log(LOG_WARNING, "Unable to get caller ID space\n");
- }
- else
- cs = NULL;
- if (number || name) {
- if (chan->cid.cid_num) {
- free(chan->cid.cid_num);
- chan->cid.cid_num = NULL;
- }
- if (chan->cid.cid_name) {
- free(chan->cid.cid_name);
- chan->cid.cid_name = NULL;
- }
- }
- if (number)
- ast_shrink_phone_number(number);
-
- ast_set_callerid(chan, number, name, number);
-
- if (cs)
- callerid_free(cs);
- ast_setstate(chan, AST_STATE_RING);
- chan->rings = 1;
- p->ringt = p->ringt_base;
- res = ast_pbx_run(chan);
- if (res) {
- ast_hangup(chan);
- ast_log(LOG_WARNING, "PBX exited non-zero\n");
- }
- return NULL;
- default:
- ast_log(LOG_WARNING, "Don't know how to handle simple switch with signalling %s on channel %d\n", sig2str(p->sig), p->channel);
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
- }
- res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
- ast_hangup(chan);
- return NULL;
-}
-
-#ifdef ZAPATA_R2
-static int handle_init_r2_event(struct zt_pvt *i, mfcr2_event_t *e)
-{
- struct ast_channel *chan;
-
- switch(e->e) {
- case MFCR2_EVENT_UNBLOCKED:
- i->r2blocked = 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "R2 Channel %d unblocked\n", i->channel);
- break;
- case MFCR2_EVENT_BLOCKED:
- i->r2blocked = 1;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "R2 Channel %d unblocked\n", i->channel);
- break;
- case MFCR2_EVENT_IDLE:
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "R2 Channel %d idle\n", i->channel);
- break;
- case MFCR2_EVENT_RINGING:
- /* This is what Asterisk refers to as a "RING" event. For some reason they're reversed in
- Steve's code */
- /* Check for callerid, digits, etc */
- i->hasr2call = 1;
- chan = zt_new(i, AST_STATE_RING, 0, SUB_REAL, 0, 0);
- if (!chan) {
- ast_log(LOG_WARNING, "Unable to create channel for channel %d\n", i->channel);
- mfcr2_DropCall(i->r2, NULL, UC_NETWORK_CONGESTION);
- i->hasr2call = 0;
- }
- if (ast_pbx_start(chan)) {
- ast_log(LOG_WARNING, "Unable to start PBX on channel %s\n", chan->name);
- ast_hangup(chan);
- }
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to handle initial R2 event %s on channel %d\n", mfcr2_event2str(e->e), i->channel);
- return -1;
- }
- return 0;
-}
-#endif
-
-static int handle_init_event(struct zt_pvt *i, int event)
-{
- int res;
- pthread_t threadid;
- pthread_attr_t attr;
- struct ast_channel *chan;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- /* Handle an event on a given channel for the monitor thread. */
- switch(event) {
- case ZT_EVENT_NONE:
- case ZT_EVENT_BITSCHANGED:
- if (i->radio) break;
-#ifdef ZAPATA_R2
- if (i->r2) {
- mfcr2_event_t *e;
- e = r2_get_event_bits(i);
- i->sigchecked = 1;
- if (e)
- handle_init_r2_event(i, e);
- }
-#endif
- break;
- case ZT_EVENT_WINKFLASH:
- case ZT_EVENT_RINGOFFHOOK:
- if (i->inalarm) break;
- if (i->radio) break;
- /* Got a ring/answer. What kind of channel are we? */
- switch(i->sig) {
- case SIG_FXOLS:
- case SIG_FXOGS:
- case SIG_FXOKS:
- zt_set_hook(i->subs[SUB_REAL].zfd, ZT_OFFHOOK);
- if (i->cidspill) {
- /* Cancel VMWI spill */
- free(i->cidspill);
- i->cidspill = NULL;
- }
- if (i->immediate) {
- zt_enable_ec(i);
- /* The channel is immediately up. Start right away */
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_RINGTONE);
- chan = zt_new(i, AST_STATE_RING, 1, SUB_REAL, 0, 0);
- if (!chan) {
- ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel);
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
- }
- } else {
- /* Check for callerid, digits, etc */
- chan = zt_new(i, AST_STATE_RESERVED, 0, SUB_REAL, 0, 0);
- if (chan) {
- if (has_voicemail(i))
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_STUTTER);
- else
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_DIALTONE);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to play dialtone on channel %d\n", i->channel);
- if (ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
- ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
- ast_hangup(chan);
- }
- } else
- ast_log(LOG_WARNING, "Unable to create channel\n");
-#if 0
- printf("Created thread %ld detached in switch\n", threadid);
-#endif
- }
- break;
- case SIG_FXSLS:
- case SIG_FXSGS:
- case SIG_FXSKS:
- i->ringt = i->ringt_base;
- /* Fall through */
- case SIG_EMWINK:
- case SIG_FEATD:
- case SIG_FEATDMF:
- case SIG_E911:
- case SIG_FEATB:
- case SIG_EM:
- case SIG_EM_E1:
- case SIG_SFWINK:
- case SIG_SF_FEATD:
- case SIG_SF_FEATDMF:
- case SIG_SF_FEATB:
- case SIG_SF:
- /* Check for callerid, digits, etc */
- chan = zt_new(i, AST_STATE_RING, 0, SUB_REAL, 0, 0);
- if (chan && ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
- ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
- ast_hangup(chan);
- } else if (!chan) {
- ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
- }
-#if 0
- printf("Created thread %ld detached in switch(2)\n", threadid);
-#endif
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to handle ring/answer with signalling %s on channel %d\n", sig2str(i->sig), i->channel);
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
- return -1;
- }
- break;
- case ZT_EVENT_NOALARM:
- i->inalarm = 0;
- ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", i->channel);
- break;
- case ZT_EVENT_ALARM:
- i->inalarm = 1;
- res = get_alarms(i);
- ast_log(LOG_WARNING, "Detected alarm on channel %d: %s\n", i->channel, alarm2str(res));
- /* fall thru intentionally */
- case ZT_EVENT_ONHOOK:
- if (i->radio) break;
- /* Back on hook. Hang up. */
- switch(i->sig) {
- case SIG_FXOLS:
- case SIG_FXOGS:
- case SIG_FEATD:
- case SIG_FEATDMF:
- case SIG_E911:
- case SIG_FEATB:
- case SIG_EM:
- case SIG_EM_E1:
- case SIG_EMWINK:
- case SIG_SF_FEATD:
- case SIG_SF_FEATDMF:
- case SIG_SF_FEATB:
- case SIG_SF:
- case SIG_SFWINK:
- case SIG_FXSLS:
- case SIG_FXSGS:
- case SIG_FXSKS:
- case SIG_GR303FXSKS:
- zt_disable_ec(i);
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, -1);
- zt_set_hook(i->subs[SUB_REAL].zfd, ZT_ONHOOK);
- break;
- case SIG_GR303FXOKS:
- case SIG_FXOKS:
- zt_disable_ec(i);
- /* Diddle the battery for the zhone */
-#ifdef ZHONE_HACK
- zt_set_hook(i->subs[SUB_REAL].zfd, ZT_OFFHOOK);
- usleep(1);
-#endif
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, -1);
- zt_set_hook(i->subs[SUB_REAL].zfd, ZT_ONHOOK);
- break;
- case SIG_PRI:
- zt_disable_ec(i);
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, -1);
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to handle on hook with signalling %s on channel %d\n", sig2str(i->sig), i->channel);
- res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, -1);
- return -1;
- }
- break;
- case ZT_EVENT_POLARITY:
- switch(i->sig) {
- case SIG_FXSLS:
- case SIG_FXSKS:
- case SIG_FXSGS:
- if (i->cid_start == CID_START_POLARITY) {
- i->polarity = POLARITY_REV;
- ast_verbose(VERBOSE_PREFIX_2 "Starting post polarity "
- "CID detection on channel %d\n",
- i->channel);
- chan = zt_new(i, AST_STATE_PRERING, 0, SUB_REAL, 0, 0);
- if (chan && ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
- ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
- }
- }
- break;
- default:
- ast_log(LOG_WARNING, "handle_init_event detected "
- "polarity reversal on non-FXO (SIG_FXS) "
- "interface %d\n", i->channel);
- }
- }
- return 0;
-}
-
-static void *do_monitor(void *data)
-{
- int count, res, res2, spoint, pollres=0;
- struct zt_pvt *i;
- struct zt_pvt *last = NULL;
- time_t thispass = 0, lastpass = 0;
- int found;
- char buf[1024];
- struct pollfd *pfds=NULL;
- int lastalloc = -1;
- /* This thread monitors all the frame relay interfaces which are not yet in use
- (and thus do not have a separate thread) indefinitely */
- /* From here on out, we die whenever asked */
-#if 0
- if (pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)) {
- ast_log(LOG_WARNING, "Unable to set cancel type to asynchronous\n");
- return NULL;
- }
- ast_log(LOG_DEBUG, "Monitor starting...\n");
-#endif
- for(;;) {
- /* Lock the interface list */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_ERROR, "Unable to grab interface lock\n");
- return NULL;
- }
- if (!pfds || (lastalloc != ifcount)) {
- if (pfds)
- free(pfds);
- if (ifcount) {
- pfds = malloc(ifcount * sizeof(struct pollfd));
- if (!pfds) {
- ast_log(LOG_WARNING, "Critical memory error. Zap dies.\n");
- ast_mutex_unlock(&iflock);
- return NULL;
- }
- }
- lastalloc = ifcount;
- }
- /* Build the stuff we're going to poll on, that is the socket of every
- zt_pvt that does not have an associated owner channel */
- count = 0;
- i = iflist;
- while(i) {
- if ((i->subs[SUB_REAL].zfd > -1) && i->sig && (!i->radio)) {
- if (!i->owner && !i->subs[SUB_REAL].owner) {
- /* This needs to be watched, as it lacks an owner */
- pfds[count].fd = i->subs[SUB_REAL].zfd;
- pfds[count].events = POLLPRI;
- pfds[count].revents = 0;
- /* Message waiting or r2 channels also get watched for reading */
-#ifdef ZAPATA_R2
- if (i->cidspill || i->r2)
-#else
- if (i->cidspill)
-#endif
- pfds[count].events |= POLLIN;
- count++;
- }
- }
- i = i->next;
- }
- /* Okay, now that we know what to do, release the interface lock */
- ast_mutex_unlock(&iflock);
-
- pthread_testcancel();
- /* Wait at least a second for something to happen */
- res = poll(pfds, count, 1000);
- pthread_testcancel();
- /* Okay, poll has finished. Let's see what happened. */
- if (res < 0) {
- if ((errno != EAGAIN) && (errno != EINTR))
- ast_log(LOG_WARNING, "poll return %d: %s\n", res, strerror(errno));
- continue;
- }
- /* Alright, lock the interface list again, and let's look and see what has
- happened */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- continue;
- }
- found = 0;
- spoint = 0;
- lastpass = thispass;
- thispass = time(NULL);
- i = iflist;
- while(i) {
- if (thispass != lastpass) {
- if (!found && ((i == last) || ((i == iflist) && !last))) {
- last = i;
- if (last) {
-#if 0
- printf("Checking channel %d\n", last->channel);
-#endif
- if (!last->cidspill && !last->owner && !ast_strlen_zero(last->mailbox) && (thispass - last->onhooktime > 3) &&
- (last->sig & __ZT_SIG_FXO)) {
-#if 0
- printf("Channel %d has mailbox %s\n", last->channel, last->mailbox);
-#endif
- res = ast_app_has_voicemail(last->mailbox, NULL);
- if (last->msgstate != res) {
- int x;
- ast_log(LOG_DEBUG, "Message status for %s changed from %d to %d on %d\n", last->mailbox, last->msgstate, res, last->channel);
- x = ZT_FLUSH_BOTH;
- res2 = ioctl(last->subs[SUB_REAL].zfd, ZT_FLUSH, &x);
- if (res2)
- ast_log(LOG_WARNING, "Unable to flush input on channel %d\n", last->channel);
- last->cidspill = malloc(MAX_CALLERID_SIZE);
- if (last->cidspill) {
- /* Turn on on hook transfer for 4 seconds */
- x = 4000;
- ioctl(last->subs[SUB_REAL].zfd, ZT_ONHOOKTRANSFER, &x);
- last->cidlen = vmwi_generate(last->cidspill, res, 1, AST_LAW(last));
- last->cidpos = 0;
-#if 0
- printf("Made %d bytes of message waiting for %d\n", last->cidlen, res);
-#endif
- last->msgstate = res;
- last->onhooktime = thispass;
- }
- found ++;
- }
- }
- last = last->next;
- }
- }
- }
- if ((i->subs[SUB_REAL].zfd > -1) && i->sig) {
- if (i->radio && !i->owner)
- {
- res = zt_get_event(i->subs[SUB_REAL].zfd);
- if (res)
- {
- if (option_debug)
- ast_log(LOG_DEBUG, "Monitor doohicky got event %s on radio channel %d\n", event2str(res), i->channel);
- /* Don't hold iflock while handling init events */
- ast_mutex_unlock(&iflock);
- handle_init_event(i, res);
- ast_mutex_lock(&iflock);
- }
- i = i->next;
- continue;
- }
- pollres = ast_fdisset(pfds, i->subs[SUB_REAL].zfd, count, &spoint);
- if (pollres & POLLIN) {
- if (i->owner || i->subs[SUB_REAL].owner) {
-#ifdef ZAPATA_PRI
- if (!i->pri)
-#endif
- ast_log(LOG_WARNING, "Whoa.... I'm owned but found (%d) in read...\n", i->subs[SUB_REAL].zfd);
- i = i->next;
- continue;
- }
-#ifdef ZAPATA_R2
- if (i->r2) {
- /* If it's R2 signalled, we always have to check for events */
- mfcr2_event_t *e;
- e = mfcr2_check_event(i->r2);
- if (e)
- handle_init_r2_event(i, e);
- else {
- e = mfcr2_schedule_run(i->r2);
- if (e)
- handle_init_r2_event(i, e);
- }
- i = i->next;
- continue;
- }
-#endif
- if (!i->cidspill) {
- ast_log(LOG_WARNING, "Whoa.... I'm reading but have no cidspill (%d)...\n", i->subs[SUB_REAL].zfd);
- i = i->next;
- continue;
- }
- res = read(i->subs[SUB_REAL].zfd, buf, sizeof(buf));
- if (res > 0) {
- /* We read some number of bytes. Write an equal amount of data */
- if (res > i->cidlen - i->cidpos)
- res = i->cidlen - i->cidpos;
- res2 = write(i->subs[SUB_REAL].zfd, i->cidspill + i->cidpos, res);
- if (res2 > 0) {
- i->cidpos += res2;
- if (i->cidpos >= i->cidlen) {
- free(i->cidspill);
- i->cidspill = 0;
- i->cidpos = 0;
- i->cidlen = 0;
- }
- } else {
- ast_log(LOG_WARNING, "Write failed: %s\n", strerror(errno));
- i->msgstate = -1;
- }
- } else {
- ast_log(LOG_WARNING, "Read failed with %d: %s\n", res, strerror(errno));
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Monitor doohicky got event %s on channel %d\n", event2str(res), i->channel);
- /* Don't hold iflock while handling init events -- race with chlock */
- ast_mutex_unlock(&iflock);
- handle_init_event(i, res);
- ast_mutex_lock(&iflock);
- }
-#ifdef ZAPATA_R2
- if ((pollres & POLLPRI) || (i->r2 && !i->sigchecked))
-#else
- if (pollres & POLLPRI)
-#endif
- {
- if (i->owner || i->subs[SUB_REAL].owner) {
-#ifdef ZAPATA_PRI
- if (!i->pri)
-#endif
- ast_log(LOG_WARNING, "Whoa.... I'm owned but found (%d)...\n", i->subs[SUB_REAL].zfd);
- i = i->next;
- continue;
- }
- res = zt_get_event(i->subs[SUB_REAL].zfd);
- if (option_debug)
- ast_log(LOG_DEBUG, "Monitor doohicky got event %s on channel %d\n", event2str(res), i->channel);
- /* Don't hold iflock while handling init events */
- ast_mutex_unlock(&iflock);
- handle_init_event(i, res);
- ast_mutex_lock(&iflock);
- }
- }
- i=i->next;
- }
- ast_mutex_unlock(&iflock);
- }
- /* Never reached */
- return NULL;
-
-}
-
-static int restart_monitor(void)
-{
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- /* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == AST_PTHREADT_STOP)
- return 0;
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_WARNING, "Unable to lock monitor\n");
- return -1;
- }
- if (monitor_thread == pthread_self()) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- return -1;
- }
- if (monitor_thread != AST_PTHREADT_NULL) {
- /* Just signal it to be sure it wakes up */
-#if 0
- pthread_cancel(monitor_thread);
-#endif
- pthread_kill(monitor_thread, SIGURG);
-#if 0
- pthread_join(monitor_thread, NULL);
-#endif
- } else {
- /* Start a new monitor */
- if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- return -1;
- }
- }
-#if 0
- printf("Created thread %ld detached in restart monitor\n", monitor_thread);
-#endif
- ast_mutex_unlock(&monlock);
- return 0;
-}
-
-#ifdef ZAPATA_PRI
-static int pri_resolve_span(int *span, int channel, int offset, struct zt_spaninfo *si)
-{
- int x;
- int trunkgroup;
- /* Get appropriate trunk group if there is one */
- trunkgroup = pris[*span].mastertrunkgroup;
- if (trunkgroup) {
- /* Select a specific trunk group */
- for (x=0;x<NUM_SPANS;x++) {
- if (pris[x].trunkgroup == trunkgroup) {
- *span = x;
- return 0;
- }
- }
- ast_log(LOG_WARNING, "Channel %d on span %d configured to use nonexistent trunk group %d\n", channel, *span, trunkgroup);
- *span = -1;
- } else {
- if (pris[*span].trunkgroup) {
- ast_log(LOG_WARNING, "Unable to use span %d implicitly since it is trunk group %d (please use spanmap)\n", *span, pris[*span].trunkgroup);
- *span = -1;
- } else if (pris[*span].mastertrunkgroup) {
- ast_log(LOG_WARNING, "Unable to use span %d implicitly since it is already part of trunk group %d\n", *span, pris[*span].mastertrunkgroup);
- *span = -1;
- } else {
- if (si->totalchans == 31) { /* if it's an E1 */
- pris[*span].dchannels[0] = 16 + offset;
- } else {
- pris[*span].dchannels[0] = 24 + offset;
- }
- pris[*span].dchanavail[0] |= DCHAN_PROVISIONED;
- pris[*span].offset = offset;
- pris[*span].span = *span + 1;
- }
- }
- return 0;
-}
-
-static int pri_create_trunkgroup(int trunkgroup, int *channels)
-{
- struct zt_spaninfo si;
- ZT_PARAMS p;
- int fd;
- int span;
- int ospan=0;
- int x,y;
- for (x=0;x<NUM_SPANS;x++) {
- if (pris[x].trunkgroup == trunkgroup) {
- ast_log(LOG_WARNING, "Trunk group %d already exists on span %d, Primary d-channel %d\n", trunkgroup, x + 1, pris[x].dchannels[0]);
- return -1;
- }
- }
- for (y=0;y<NUM_DCHANS;y++) {
- if (!channels[y])
- break;
- memset(&si, 0, sizeof(si));
- memset(&p, 0, sizeof(p));
- fd = open("/dev/zap/channel", O_RDWR);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Failed to open channel: %s\n", strerror(errno));
- return -1;
- }
- x = channels[y];
- if (ioctl(fd, ZT_SPECIFY, &x)) {
- ast_log(LOG_WARNING, "Failed to specify channel %d: %s\n", channels[y], strerror(errno));
- zt_close(fd);
- return -1;
- }
- if (ioctl(fd, ZT_GET_PARAMS, &p)) {
- ast_log(LOG_WARNING, "Failed to get channel parameters for channel %d: %s\n", channels[y], strerror(errno));
- return -1;
- }
- if (ioctl(fd, ZT_SPANSTAT, &si)) {
- ast_log(LOG_WARNING, "Failed go get span information on channel %d (span %d)\n", channels[y], p.spanno);
- zt_close(fd);
- return -1;
- }
- span = p.spanno - 1;
- if (pris[span].trunkgroup) {
- ast_log(LOG_WARNING, "Span %d is already provisioned for trunk group %d\n", span + 1, pris[span].trunkgroup);
- zt_close(fd);
- return -1;
- }
- if (pris[span].pvts[0]) {
- ast_log(LOG_WARNING, "Span %d is already provisioned with channels (implicit PRI maybe?)\n", span + 1);
- zt_close(fd);
- return -1;
- }
- if (!y) {
- pris[span].trunkgroup = trunkgroup;
- pris[span].offset = channels[y] - p.chanpos;
- ospan = span;
- }
- pris[ospan].dchannels[y] = channels[y];
- pris[ospan].dchanavail[y] |= DCHAN_PROVISIONED;
- pris[span].span = span + 1;
- zt_close(fd);
- }
- return 0;
-}
-
-static int pri_create_spanmap(int span, int trunkgroup, int logicalspan)
-{
- if (pris[span].mastertrunkgroup) {
- ast_log(LOG_WARNING, "Span %d is already part of trunk group %d, cannot add to trunk group %d\n", span + 1, pris[span].mastertrunkgroup, trunkgroup);
- return -1;
- }
- pris[span].mastertrunkgroup = trunkgroup;
- pris[span].prilogicalspan = logicalspan;
- return 0;
-}
-
-#endif
-
-static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_pri *pri, int reloading)
-{
- /* Make a zt_pvt structure for this interface (or CRV if "pri" is specified) */
- struct zt_pvt *tmp = NULL, *tmp2, *prev = NULL;
- char fn[80];
-#if 1
- struct zt_bufferinfo bi;
-#endif
- struct zt_spaninfo si;
- int res;
- int span=0;
- int here = 0;
- int x;
- struct zt_pvt **wlist;
- struct zt_pvt **wend;
- ZT_PARAMS p;
-
- wlist = &iflist;
- wend = &ifend;
-
-#ifdef ZAPATA_PRI
- if (pri) {
- wlist = &pri->crvs;
- wend = &pri->crvend;
- }
-#endif
-
- tmp2 = *wlist;
- prev = NULL;
-
- while (tmp2) {
- if (!tmp2->destroy) {
- if (tmp2->channel == channel) {
- tmp = tmp2;
- here = 1;
- break;
- }
- if (tmp2->channel > channel) {
- break;
- }
- }
- prev = tmp2;
- tmp2 = tmp2->next;
- }
-
- if (!here && !reloading) {
- tmp = (struct zt_pvt*)malloc(sizeof(struct zt_pvt));
- if (!tmp) {
- ast_log(LOG_ERROR, "MALLOC FAILED\n");
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- memset(tmp, 0, sizeof(struct zt_pvt));
- ast_mutex_init(&tmp->lock);
- ifcount++;
- for (x=0;x<3;x++)
- tmp->subs[x].zfd = -1;
- tmp->channel = channel;
- }
-
- if (tmp) {
- if (!here) {
- if ((channel != CHAN_PSEUDO) && !pri) {
- snprintf(fn, sizeof(fn), "%d", channel);
- /* Open non-blocking */
- if (!here)
- tmp->subs[SUB_REAL].zfd = zt_open(fn);
- /* Allocate a zapata structure */
- if (tmp->subs[SUB_REAL].zfd < 0) {
- ast_log(LOG_ERROR, "Unable to open channel %d: %s\nhere = %d, tmp->channel = %d, channel = %d\n", channel, strerror(errno), here, tmp->channel, channel);
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- memset(&p, 0, sizeof(p));
- res = ioctl(tmp->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &p);
- if (res < 0) {
- ast_log(LOG_ERROR, "Unable to get parameters\n");
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (p.sigtype != (signalling & 0x3ffff)) {
- ast_log(LOG_ERROR, "Signalling requested on channel %d is %s but line is in %s signalling\n", channel, sig2str(signalling), sig2str(p.sigtype));
- destroy_zt_pvt(&tmp);
- return tmp;
- }
- tmp->law = p.curlaw;
- tmp->span = p.spanno;
- span = p.spanno - 1;
- } else {
- if (channel == CHAN_PSEUDO)
- signalling = 0;
- else if ((signalling != SIG_FXOKS) && (signalling != SIG_FXSKS)) {
- ast_log(LOG_ERROR, "CRV's must use FXO/FXS Kewl Start (fxo_ks/fxs_ks) signalling only.\n");
- return NULL;
- }
- }
-#ifdef ZAPATA_PRI
- if ((signalling == SIG_PRI) || (signalling == SIG_GR303FXOKS) || (signalling == SIG_GR303FXSKS)) {
- int offset;
- int myswitchtype;
- int matchesdchan;
- int x,y;
- offset = 0;
- if ((signalling == SIG_PRI) && ioctl(tmp->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &offset)) {
- ast_log(LOG_ERROR, "Unable to set clear mode on clear channel %d of span %d: %s\n", channel, p.spanno, strerror(errno));
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (span >= NUM_SPANS) {
- ast_log(LOG_ERROR, "Channel %d does not lie on a span I know of (%d)\n", channel, span);
- destroy_zt_pvt(&tmp);
- return NULL;
- } else {
- si.spanno = 0;
- if (ioctl(tmp->subs[SUB_REAL].zfd,ZT_SPANSTAT,&si) == -1) {
- ast_log(LOG_ERROR, "Unable to get span status: %s\n", strerror(errno));
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- /* Store the logical span first based upon the real span */
- tmp->logicalspan = pris[span].prilogicalspan;
- pri_resolve_span(&span, channel, (channel - p.chanpos), &si);
- if (span < 0) {
- ast_log(LOG_WARNING, "Channel %d: Unable to find locate channel/trunk group!\n", channel);
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (signalling == SIG_PRI)
- myswitchtype = switchtype;
- else
- myswitchtype = PRI_SWITCH_GR303_TMC;
- /* Make sure this isn't a d-channel */
- matchesdchan=0;
- for (x=0;x<NUM_SPANS;x++) {
- for (y=0;y<NUM_DCHANS;y++) {
- if (pris[x].dchannels[y] == tmp->channel) {
- matchesdchan = 1;
- break;
- }
- }
- }
- offset = p.chanpos;
- if (!matchesdchan) {
- if (pris[span].nodetype && (pris[span].nodetype != pritype)) {
- ast_log(LOG_ERROR, "Span %d is already a %s node\n", span + 1, pri_node2str(pris[span].nodetype));
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (pris[span].switchtype && (pris[span].switchtype != myswitchtype)) {
- ast_log(LOG_ERROR, "Span %d is already a %s switch\n", span + 1, pri_switch2str(pris[span].switchtype));
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if ((pris[span].dialplan) && (pris[span].dialplan != dialplan)) {
- ast_log(LOG_ERROR, "Span %d is already a %s dialing plan\n", span + 1, dialplan2str(pris[span].dialplan));
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (!ast_strlen_zero(pris[span].idledial) && strcmp(pris[span].idledial, idledial)) {
- ast_log(LOG_ERROR, "Span %d already has idledial '%s'.\n", span + 1, idledial);
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (!ast_strlen_zero(pris[span].idleext) && strcmp(pris[span].idleext, idleext)) {
- ast_log(LOG_ERROR, "Span %d already has idleext '%s'.\n", span + 1, idleext);
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (pris[span].minunused && (pris[span].minunused != minunused)) {
- ast_log(LOG_ERROR, "Span %d already has minunused of %d.\n", span + 1, minunused);
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (pris[span].minidle && (pris[span].minidle != minidle)) {
- ast_log(LOG_ERROR, "Span %d already has minidle of %d.\n", span + 1, minidle);
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (pris[span].numchans >= MAX_CHANNELS) {
- ast_log(LOG_ERROR, "Unable to add channel %d: Too many channels in trunk group %d!\n", channel,
- pris[span].trunkgroup);
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- pris[span].nodetype = pritype;
- pris[span].switchtype = myswitchtype;
- pris[span].nsf = nsf;
- pris[span].dialplan = dialplan;
- pris[span].localdialplan = localdialplan;
- pris[span].pvts[pris[span].numchans++] = tmp;
- pris[span].minunused = minunused;
- pris[span].minidle = minidle;
- pris[span].overlapdial = overlapdial;
- pris[span].facilityenable = facilityenable;
- ast_copy_string(pris[span].idledial, idledial, sizeof(pris[span].idledial));
- ast_copy_string(pris[span].idleext, idleext, sizeof(pris[span].idleext));
- ast_copy_string(pris[span].internationalprefix, internationalprefix, sizeof(pris[span].internationalprefix));
- ast_copy_string(pris[span].nationalprefix, nationalprefix, sizeof(pris[span].nationalprefix));
- ast_copy_string(pris[span].localprefix, localprefix, sizeof(pris[span].localprefix));
- ast_copy_string(pris[span].privateprefix, privateprefix, sizeof(pris[span].privateprefix));
- ast_copy_string(pris[span].unknownprefix, unknownprefix, sizeof(pris[span].unknownprefix));
- pris[span].resetinterval = resetinterval;
-
- tmp->pri = &pris[span];
- tmp->prioffset = offset;
- tmp->call = NULL;
- } else {
- ast_log(LOG_ERROR, "Channel %d is reserved for D-channel.\n", offset);
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- }
- } else {
- tmp->prioffset = 0;
- }
-#endif
-#ifdef ZAPATA_R2
- if (signalling == SIG_R2) {
- if (r2prot < 0) {
- ast_log(LOG_WARNING, "R2 Country not specified for channel %d -- Assuming China\n", tmp->channel);
- tmp->r2prot = MFCR2_PROT_CHINA;
- } else
- tmp->r2prot = r2prot;
- tmp->r2 = mfcr2_new(tmp->subs[SUB_REAL].zfd, tmp->r2prot, 1);
- if (!tmp->r2) {
- ast_log(LOG_WARNING, "Unable to create r2 call :(\n");
- zt_close(tmp->subs[SUB_REAL].zfd);
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- } else {
- if (tmp->r2)
- mfcr2_free(tmp->r2);
- tmp->r2 = NULL;
- }
-#endif
- } else {
- signalling = tmp->sig;
- radio = tmp->radio;
- memset(&p, 0, sizeof(p));
- if (tmp->subs[SUB_REAL].zfd > -1)
- res = ioctl(tmp->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &p);
- }
- /* Adjust starttime on loopstart and kewlstart trunks to reasonable values */
- if ((signalling == SIG_FXSKS) || (signalling == SIG_FXSLS) ||
- (signalling == SIG_EM) || (signalling == SIG_EM_E1) || (signalling == SIG_EMWINK) ||
- (signalling == SIG_FEATD) || (signalling == SIG_FEATDMF) || (signalling == SIG_FEATDMF_TA) ||
- (signalling == SIG_FEATB) || (signalling == SIG_E911) ||
- (signalling == SIG_SF) || (signalling == SIG_SFWINK) ||
- (signalling == SIG_SF_FEATD) || (signalling == SIG_SF_FEATDMF) ||
- (signalling == SIG_SF_FEATB)) {
- p.starttime = 250;
- }
- if (radio) {
- /* XXX Waiting to hear back from Jim if these should be adjustable XXX */
- p.channo = channel;
- p.rxwinktime = 1;
- p.rxflashtime = 1;
- p.starttime = 1;
- p.debouncetime = 5;
- }
- if (!radio) {
- p.channo = channel;
- /* Override timing settings based on config file */
- if (cur_prewink >= 0)
- p.prewinktime = cur_prewink;
- if (cur_preflash >= 0)
- p.preflashtime = cur_preflash;
- if (cur_wink >= 0)
- p.winktime = cur_wink;
- if (cur_flash >= 0)
- p.flashtime = cur_flash;
- if (cur_start >= 0)
- p.starttime = cur_start;
- if (cur_rxwink >= 0)
- p.rxwinktime = cur_rxwink;
- if (cur_rxflash >= 0)
- p.rxflashtime = cur_rxflash;
- if (cur_debounce >= 0)
- p.debouncetime = cur_debounce;
- }
-
- /* dont set parms on a pseudo-channel (or CRV) */
- if (tmp->subs[SUB_REAL].zfd >= 0)
- {
- res = ioctl(tmp->subs[SUB_REAL].zfd, ZT_SET_PARAMS, &p);
- if (res < 0) {
- ast_log(LOG_ERROR, "Unable to set parameters\n");
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- }
-#if 1
- if (!here && (tmp->subs[SUB_REAL].zfd > -1)) {
- memset(&bi, 0, sizeof(bi));
- res = ioctl(tmp->subs[SUB_REAL].zfd, ZT_GET_BUFINFO, &bi);
- if (!res) {
- bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.numbufs = numbufs;
- res = ioctl(tmp->subs[SUB_REAL].zfd, ZT_SET_BUFINFO, &bi);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set buffer policy on channel %d\n", channel);
- }
- } else
- ast_log(LOG_WARNING, "Unable to check buffer policy on channel %d\n", channel);
- }
-#endif
- tmp->immediate = immediate;
- tmp->transfertobusy = transfertobusy;
- tmp->sig = signalling;
- tmp->radio = radio;
- tmp->ringt_base = ringt_base;
- tmp->firstradio = 0;
- if ((signalling == SIG_FXOKS) || (signalling == SIG_FXOLS) || (signalling == SIG_FXOGS))
- tmp->permcallwaiting = callwaiting;
- else
- tmp->permcallwaiting = 0;
- /* Flag to destroy the channel must be cleared on new mkif. Part of changes for reload to work */
- tmp->destroy = 0;
- tmp->drings = drings;
- tmp->usedistinctiveringdetection = usedistinctiveringdetection;
- tmp->callwaitingcallerid = callwaitingcallerid;
- tmp->threewaycalling = threewaycalling;
- tmp->adsi = adsi;
- tmp->permhidecallerid = hidecallerid;
- tmp->callreturn = callreturn;
- tmp->echocancel = echocancel;
- tmp->echotraining = echotraining;
- tmp->pulse = pulse;
- tmp->echocanbridged = echocanbridged;
- tmp->busydetect = busydetect;
- tmp->busycount = busycount;
- tmp->busy_tonelength = busy_tonelength;
- tmp->busy_quietlength = busy_quietlength;
- tmp->callprogress = callprogress;
- tmp->cancallforward = cancallforward;
- tmp->dtmfrelax = relaxdtmf;
- tmp->callwaiting = tmp->permcallwaiting;
- tmp->hidecallerid = tmp->permhidecallerid;
- tmp->channel = channel;
- tmp->stripmsd = stripmsd;
- tmp->use_callerid = use_callerid;
- tmp->cid_signalling = cid_signalling;
- tmp->cid_start = cid_start;
- tmp->zaptrcallerid = zaptrcallerid;
- tmp->restrictcid = restrictcid;
- tmp->use_callingpres = use_callingpres;
- tmp->priindication_oob = priindication_oob;
- tmp->priexclusive = cur_priexclusive;
- if (tmp->usedistinctiveringdetection) {
- if (!tmp->use_callerid) {
- ast_log(LOG_NOTICE, "Distinctive Ring detect requires 'usecallerid' be on\n");
- tmp->use_callerid = 1;
- }
- }
-
- ast_copy_string(tmp->accountcode, accountcode, sizeof(tmp->accountcode));
- tmp->amaflags = amaflags;
- if (!here) {
- tmp->confno = -1;
- tmp->propconfno = -1;
- }
- tmp->canpark = canpark;
- tmp->transfer = transfer;
- ast_copy_string(tmp->defcontext,context,sizeof(tmp->defcontext));
- ast_copy_string(tmp->language, language, sizeof(tmp->language));
- ast_copy_string(tmp->musicclass, musicclass, sizeof(tmp->musicclass));
- ast_copy_string(tmp->context, context, sizeof(tmp->context));
- ast_copy_string(tmp->cid_num, cid_num, sizeof(tmp->cid_num));
- tmp->cid_ton = 0;
- ast_copy_string(tmp->cid_name, cid_name, sizeof(tmp->cid_name));
- ast_copy_string(tmp->mailbox, mailbox, sizeof(tmp->mailbox));
- tmp->msgstate = -1;
- tmp->group = cur_group;
- tmp->callgroup=cur_callergroup;
- tmp->pickupgroup=cur_pickupgroup;
- tmp->rxgain = rxgain;
- tmp->txgain = txgain;
- tmp->tonezone = tonezone;
- tmp->onhooktime = time(NULL);
- if (tmp->subs[SUB_REAL].zfd > -1) {
- set_actual_gain(tmp->subs[SUB_REAL].zfd, 0, tmp->rxgain, tmp->txgain, tmp->law);
- if (tmp->dsp)
- ast_dsp_digitmode(tmp->dsp, DSP_DIGITMODE_DTMF | tmp->dtmfrelax);
- update_conf(tmp);
- if (!here) {
- if ((signalling != SIG_PRI) && (signalling != SIG_R2))
- /* Hang it up to be sure it's good */
- zt_set_hook(tmp->subs[SUB_REAL].zfd, ZT_ONHOOK);
- }
- ioctl(tmp->subs[SUB_REAL].zfd,ZT_SETTONEZONE,&tmp->tonezone);
-#ifdef ZAPATA_PRI
- /* the dchannel is down so put the channel in alarm */
- if (tmp->pri && !pri_is_up(tmp->pri))
- tmp->inalarm = 1;
- else
- tmp->inalarm = 0;
-#endif
- memset(&si, 0, sizeof(si));
- if (ioctl(tmp->subs[SUB_REAL].zfd,ZT_SPANSTAT,&si) == -1) {
- ast_log(LOG_ERROR, "Unable to get span status: %s\n", strerror(errno));
- destroy_zt_pvt(&tmp);
- return NULL;
- }
- if (si.alarms) tmp->inalarm = 1;
- }
-
- tmp->polarityonanswerdelay = polarityonanswerdelay;
- tmp->answeronpolarityswitch = answeronpolarityswitch;
- tmp->hanguponpolarityswitch = hanguponpolarityswitch;
- tmp->sendcalleridafter = sendcalleridafter;
-
- }
- if (tmp && !here) {
- /* nothing on the iflist */
- if (!*wlist) {
- *wlist = tmp;
- tmp->prev = NULL;
- tmp->next = NULL;
- *wend = tmp;
- } else {
- /* at least one member on the iflist */
- struct zt_pvt *working = *wlist;
-
- /* check if we maybe have to put it on the begining */
- if (working->channel > tmp->channel) {
- tmp->next = *wlist;
- tmp->prev = NULL;
- (*wlist)->prev = tmp;
- *wlist = tmp;
- } else {
- /* go through all the members and put the member in the right place */
- while (working) {
- /* in the middle */
- if (working->next) {
- if (working->channel < tmp->channel && working->next->channel > tmp->channel) {
- tmp->next = working->next;
- tmp->prev = working;
- working->next->prev = tmp;
- working->next = tmp;
- break;
- }
- } else {
- /* the last */
- if (working->channel < tmp->channel) {
- working->next = tmp;
- tmp->next = NULL;
- tmp->prev = working;
- *wend = tmp;
- break;
- }
- }
- working = working->next;
- }
- }
- }
- }
- return tmp;
-}
-
-static inline int available(struct zt_pvt *p, int channelmatch, int groupmatch, int *busy, int *channelmatched, int *groupmatched)
-{
- int res;
- ZT_PARAMS par;
-
- /* First, check group matching */
- if (groupmatch) {
- if ((p->group & groupmatch) != groupmatch)
- return 0;
- *groupmatched = 1;
- }
- /* Check to see if we have a channel match */
- if (channelmatch != -1) {
- if (p->channel != channelmatch)
- return 0;
- *channelmatched = 1;
- }
- /* We're at least busy at this point */
- if (busy) {
- if ((p->sig == SIG_FXOKS) || (p->sig == SIG_FXOLS) || (p->sig == SIG_FXOGS))
- *busy = 1;
- }
- /* If do not disturb, definitely not */
- if (p->dnd)
- return 0;
- /* If guard time, definitely not */
- if (p->guardtime && (time(NULL) < p->guardtime))
- return 0;
-
- /* If no owner definitely available */
- if (!p->owner) {
-#ifdef ZAPATA_PRI
- /* Trust PRI */
- if (p->pri) {
- if (p->resetting || p->call)
- return 0;
- else
- return 1;
- }
-#endif
-#ifdef ZAPATA_R2
- /* Trust R2 as well */
- if (p->r2) {
- if (p->hasr2call || p->r2blocked)
- return 0;
- else
- return 1;
- }
-#endif
- if (!p->radio)
- {
- if (!p->sig || (p->sig == SIG_FXSLS))
- return 1;
- /* Check hook state */
- if (p->subs[SUB_REAL].zfd > -1)
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &par);
- else {
- /* Assume not off hook on CVRS */
- res = 0;
- par.rxisoffhook = 0;
- }
- if (res) {
- ast_log(LOG_WARNING, "Unable to check hook state on channel %d\n", p->channel);
- } else if ((p->sig == SIG_FXSKS) || (p->sig == SIG_FXSGS)) {
- /* When "onhook" that means no battery on the line, and thus
- it is out of service..., if it's on a TDM card... If it's a channel
- bank, there is no telling... */
- if (par.rxbits > -1)
- return 1;
- if (par.rxisoffhook)
- return 1;
- else
-#ifdef ZAP_CHECK_HOOKSTATE
- return 0;
-#else
- return 1;
-#endif
- } else if (par.rxisoffhook) {
- ast_log(LOG_DEBUG, "Channel %d off hook, can't use\n", p->channel);
- /* Not available when the other end is off hook */
- return 0;
- }
- }
- return 1;
- }
-
- /* If it's not an FXO, forget about call wait */
- if ((p->sig != SIG_FXOKS) && (p->sig != SIG_FXOLS) && (p->sig != SIG_FXOGS))
- return 0;
-
- if (!p->callwaiting) {
- /* If they don't have call waiting enabled, then for sure they're unavailable at this point */
- return 0;
- }
-
- if (p->subs[SUB_CALLWAIT].zfd > -1) {
- /* If there is already a call waiting call, then we can't take a second one */
- return 0;
- }
-
- if ((p->owner->_state != AST_STATE_UP) &&
- ((p->owner->_state != AST_STATE_RINGING) || p->outgoing)) {
- /* If the current call is not up, then don't allow the call */
- return 0;
- }
- if ((p->subs[SUB_THREEWAY].owner) && (!p->subs[SUB_THREEWAY].inthreeway)) {
- /* Can't take a call wait when the three way calling hasn't been merged yet. */
- return 0;
- }
- /* We're cool */
- return 1;
-}
-
-static struct zt_pvt *chandup(struct zt_pvt *src)
-{
- struct zt_pvt *p;
- ZT_BUFFERINFO bi;
- int res;
- p = malloc(sizeof(struct zt_pvt));
- if (p) {
- memcpy(p, src, sizeof(struct zt_pvt));
- ast_mutex_init(&p->lock);
- p->subs[SUB_REAL].zfd = zt_open("/dev/zap/pseudo");
- /* Allocate a zapata structure */
- if (p->subs[SUB_REAL].zfd < 0) {
- ast_log(LOG_ERROR, "Unable to dup channel: %s\n", strerror(errno));
- destroy_zt_pvt(&p);
- return NULL;
- }
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_GET_BUFINFO, &bi);
- if (!res) {
- bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.numbufs = numbufs;
- res = ioctl(p->subs[SUB_REAL].zfd, ZT_SET_BUFINFO, &bi);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set buffer policy on dup channel\n");
- }
- } else
- ast_log(LOG_WARNING, "Unable to check buffer policy on dup channel\n");
- }
- p->destroy = 1;
- p->next = iflist;
- iflist = p;
- return p;
-}
-
-
-#ifdef ZAPATA_PRI
-static int pri_find_empty_chan(struct zt_pri *pri, int backwards)
-{
- int x;
- if (backwards)
- x = pri->numchans;
- else
- x = 0;
- for (;;) {
- if (backwards && (x < 0))
- break;
- if (!backwards && (x >= pri->numchans))
- break;
- if (pri->pvts[x] && !pri->pvts[x]->inalarm && !pri->pvts[x]->owner) {
- ast_log(LOG_DEBUG, "Found empty available channel %d/%d\n",
- pri->pvts[x]->logicalspan, pri->pvts[x]->prioffset);
- return x;
- }
- if (backwards)
- x--;
- else
- x++;
- }
- return -1;
-}
-#endif
-
-static struct ast_channel *zt_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- int groupmatch = 0;
- int channelmatch = -1;
- int roundrobin = 0;
- int callwait = 0;
- int busy = 0;
- struct zt_pvt *p;
- struct ast_channel *tmp = NULL;
- char *dest=NULL;
- int x;
- char *s;
- char opt=0;
- int res=0, y=0;
- int backwards = 0;
-#ifdef ZAPATA_PRI
- int crv;
- int bearer = -1;
- int trunkgroup;
- struct zt_pri *pri=NULL;
-#endif
- struct zt_pvt *exit, *start, *end;
- ast_mutex_t *lock;
- int channelmatched = 0;
- int groupmatched = 0;
-
- /* Assume we're locking the iflock */
- lock = &iflock;
- start = iflist;
- end = ifend;
- /* We do signed linear */
- oldformat = format;
- format &= (AST_FORMAT_SLINEAR | AST_FORMAT_ULAW);
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", oldformat);
- return NULL;
- }
- if (data) {
- dest = ast_strdupa((char *)data);
- } else {
- ast_log(LOG_WARNING, "Channel requested with no data\n");
- return NULL;
- }
- if (toupper(dest[0]) == 'G' || toupper(dest[0])=='R') {
- /* Retrieve the group number */
- char *stringp=NULL;
- stringp=dest + 1;
- s = strsep(&stringp, "/");
- if ((res = sscanf(s, "%d%c%d", &x, &opt, &y)) < 1) {
- ast_log(LOG_WARNING, "Unable to determine group for data %s\n", (char *)data);
- return NULL;
- }
- groupmatch = 1 << x;
- if (toupper(dest[0]) == 'G') {
- if (dest[0] == 'G') {
- backwards = 1;
- p = ifend;
- } else
- p = iflist;
- } else {
- if (dest[0] == 'R') {
- backwards = 1;
- p = round_robin[x]?round_robin[x]->prev:ifend;
- if (!p)
- p = ifend;
- } else {
- p = round_robin[x]?round_robin[x]->next:iflist;
- if (!p)
- p = iflist;
- }
- roundrobin = 1;
- }
- } else {
- char *stringp=NULL;
- stringp=dest;
- s = strsep(&stringp, "/");
- p = iflist;
- if (!strcasecmp(s, "pseudo")) {
- /* Special case for pseudo */
- x = CHAN_PSEUDO;
- channelmatch = x;
- }
-#ifdef ZAPATA_PRI
- else if ((res = sscanf(s, "%d:%d%c%d", &trunkgroup, &crv, &opt, &y)) > 1) {
- if ((trunkgroup < 1) || (crv < 1)) {
- ast_log(LOG_WARNING, "Unable to determine trunk group and CRV for data %s\n", (char *)data);
- return NULL;
- }
- res--;
- for (x=0;x<NUM_SPANS;x++) {
- if (pris[x].trunkgroup == trunkgroup) {
- pri = pris + x;
- lock = &pri->lock;
- start = pri->crvs;
- end = pri->crvend;
- break;
- }
- }
- if (!pri) {
- ast_log(LOG_WARNING, "Unable to find trunk group %d\n", trunkgroup);
- return NULL;
- }
- channelmatch = crv;
- p = pris[x].crvs;
- }
-#endif
- else if ((res = sscanf(s, "%d%c%d", &x, &opt, &y)) < 1) {
- ast_log(LOG_WARNING, "Unable to determine channel for data %s\n", (char *)data);
- return NULL;
- } else {
- channelmatch = x;
- }
- }
- /* Search for an unowned channel */
- if (ast_mutex_lock(lock)) {
- ast_log(LOG_ERROR, "Unable to lock interface list???\n");
- return NULL;
- }
- exit = p;
- while(p && !tmp) {
- if (roundrobin)
- round_robin[x] = p;
-#if 0
- ast_verbose("name = %s, %d, %d, %d\n",p->owner ? p->owner->name : "<none>", p->channel, channelmatch, groupmatch);
-#endif
-
- if (p && available(p, channelmatch, groupmatch, &busy, &channelmatched, &groupmatched)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Using channel %d\n", p->channel);
- if (p->inalarm)
- goto next;
-
- callwait = (p->owner != NULL);
-#ifdef ZAPATA_PRI
- if (pri && (p->subs[SUB_REAL].zfd < 0)) {
- if (p->sig != SIG_FXSKS) {
- /* Gotta find an actual channel to use for this
- CRV if this isn't a callwait */
- bearer = pri_find_empty_chan(pri, 0);
- if (bearer < 0) {
- ast_log(LOG_NOTICE, "Out of bearer channels on span %d for call to CRV %d:%d\n", pri->span, trunkgroup, crv);
- p = NULL;
- break;
- }
- pri_assign_bearer(p, pri, pri->pvts[bearer]);
- } else {
- if (alloc_sub(p, 0)) {
- ast_log(LOG_NOTICE, "Failed to allocate place holder pseudo channel!\n");
- p = NULL;
- break;
- } else
- ast_log(LOG_DEBUG, "Allocated placeholder pseudo channel\n");
- p->pri = pri;
- }
- }
-#endif
- if (p->channel == CHAN_PSEUDO) {
- p = chandup(p);
- if (!p) {
- break;
- }
- }
- if (p->owner) {
- if (alloc_sub(p, SUB_CALLWAIT)) {
- p = NULL;
- break;
- }
- }
- p->outgoing = 1;
- tmp = zt_new(p, AST_STATE_RESERVED, 0, p->owner ? SUB_CALLWAIT : SUB_REAL, 0, 0);
-#ifdef ZAPATA_PRI
- if (p->bearer) {
- /* Log owner to bearer channel, too */
- p->bearer->owner = tmp;
- }
-#endif
- /* Make special notes */
- if (res > 1) {
- if (opt == 'c') {
- /* Confirm answer */
- p->confirmanswer = 1;
- } else if (opt == 'r') {
- /* Distinctive ring */
- if (res < 3)
- ast_log(LOG_WARNING, "Distinctive ring missing identifier in '%s'\n", (char *)data);
- else
- p->distinctivering = y;
- } else if (opt == 'd') {
- /* If this is an ISDN call, make it digital */
- p->digital = 1;
- if (tmp)
- tmp->transfercapability = AST_TRANS_CAP_DIGITAL;
- } else {
- ast_log(LOG_WARNING, "Unknown option '%c' in '%s'\n", opt, (char *)data);
- }
- }
- /* Note if the call is a call waiting call */
- if (tmp && callwait)
- tmp->cdrflags |= AST_CDR_CALLWAIT;
- break;
- }
-next:
- if (backwards) {
- p = p->prev;
- if (!p)
- p = end;
- } else {
- p = p->next;
- if (!p)
- p = start;
- }
- /* stop when you roll to the one that we started from */
- if (p == exit)
- break;
- }
- ast_mutex_unlock(lock);
- restart_monitor();
- if (callwait)
- *cause = AST_CAUSE_BUSY;
- else if (!tmp) {
- if (channelmatched) {
- if (busy)
- *cause = AST_CAUSE_BUSY;
- } else if (groupmatched) {
- *cause = AST_CAUSE_CONGESTION;
- }
- }
-
- return tmp;
-}
-
-
-#ifdef ZAPATA_PRI
-static struct zt_pvt *pri_find_crv(struct zt_pri *pri, int crv)
-{
- struct zt_pvt *p;
- p = pri->crvs;
- while(p) {
- if (p->channel == crv)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-
-static int pri_find_principle(struct zt_pri *pri, int channel)
-{
- int x;
- int span = PRI_SPAN(channel);
- int spanfd;
- ZT_PARAMS param;
- int principle = -1;
- int explicit = PRI_EXPLICIT(channel);
- span = PRI_SPAN(channel);
- channel = PRI_CHANNEL(channel);
-
- if (!explicit) {
- spanfd = pri_active_dchan_fd(pri);
- if (ioctl(spanfd, ZT_GET_PARAMS, &param))
- return -1;
- span = pris[param.spanno - 1].prilogicalspan;
- }
-
- for (x=0;x<pri->numchans;x++) {
- if (pri->pvts[x] && (pri->pvts[x]->prioffset == channel) && (pri->pvts[x]->logicalspan == span)) {
- principle = x;
- break;
- }
- }
-
- return principle;
-}
-
-static int pri_fixup_principle(struct zt_pri *pri, int principle, q931_call *c)
-{
- int x;
- struct zt_pvt *crv;
- if (!c) {
- if (principle < 0)
- return -1;
- return principle;
- }
- if ((principle > -1) &&
- (principle < pri->numchans) &&
- (pri->pvts[principle]) &&
- (pri->pvts[principle]->call == c))
- return principle;
- /* First, check for other bearers */
- for (x=0;x<pri->numchans;x++) {
- if (!pri->pvts[x]) continue;
- if (pri->pvts[x]->call == c) {
- /* Found our call */
- if (principle != x) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Moving call from channel %d to channel %d\n",
- pri->pvts[x]->channel, pri->pvts[principle]->channel);
- if (pri->pvts[principle]->owner) {
- ast_log(LOG_WARNING, "Can't fix up channel from %d to %d because %d is already in use\n",
- pri->pvts[x]->channel, pri->pvts[principle]->channel, pri->pvts[principle]->channel);
- return -1;
- }
- /* Fix it all up now */
- pri->pvts[principle]->owner = pri->pvts[x]->owner;
- if (pri->pvts[principle]->owner) {
- snprintf(pri->pvts[principle]->owner->name, sizeof(pri->pvts[principle]->owner->name),
- "Zap/%d:%d-%d", pri->trunkgroup, pri->pvts[principle]->channel, 1);
- pri->pvts[principle]->owner->tech_pvt = pri->pvts[principle];
- pri->pvts[principle]->owner->fds[0] = pri->pvts[principle]->subs[SUB_REAL].zfd;
- pri->pvts[principle]->subs[SUB_REAL].owner = pri->pvts[x]->subs[SUB_REAL].owner;
- } else
- ast_log(LOG_WARNING, "Whoa, there's no owner, and we're having to fix up channel %d to channel %d\n", pri->pvts[x]->channel, pri->pvts[principle]->channel);
- pri->pvts[principle]->call = pri->pvts[x]->call;
- /* Free up the old channel, now not in use */
- pri->pvts[x]->subs[SUB_REAL].owner = NULL;
- pri->pvts[x]->owner = NULL;
- pri->pvts[x]->call = NULL;
- }
- return principle;
- }
- }
- /* Now check for a CRV with no bearer */
- crv = pri->crvs;
- while(crv) {
- if (crv->call == c) {
- /* This is our match... Perform some basic checks */
- if (crv->bearer)
- ast_log(LOG_WARNING, "Trying to fix up call which already has a bearer which isn't the one we think it is\n");
- else if (pri->pvts[principle]->owner)
- ast_log(LOG_WARNING, "Tring to fix up a call to a bearer which already has an owner!\n");
- else {
- /* Looks good. Drop the pseudo channel now, clear up the assignment, and
- wakeup the potential sleeper */
- zt_close(crv->subs[SUB_REAL].zfd);
- pri->pvts[principle]->call = crv->call;
- pri_assign_bearer(crv, pri, pri->pvts[principle]);
- ast_log(LOG_DEBUG, "Assigning bearer %d/%d to CRV %d:%d\n",
- pri->pvts[principle]->logicalspan, pri->pvts[principle]->prioffset,
- pri->trunkgroup, crv->channel);
- wakeup_sub(crv, SUB_REAL, pri);
- }
- return principle;
- }
- crv = crv->next;
- }
- ast_log(LOG_WARNING, "Call specified, but not found?\n");
- return -1;
-}
-
-static void *do_idle_thread(void *vchan)
-{
- struct ast_channel *chan = vchan;
- struct zt_pvt *pvt = chan->tech_pvt;
- struct ast_frame *f;
- char ex[80];
- /* Wait up to 30 seconds for an answer */
- int newms, ms = 30000;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Initiating idle call on channel %s\n", chan->name);
- snprintf(ex, sizeof(ex), "%d/%s", pvt->channel, pvt->pri->idledial);
- if (ast_call(chan, ex, 0)) {
- ast_log(LOG_WARNING, "Idle dial failed on '%s' to '%s'\n", chan->name, ex);
- ast_hangup(chan);
- return NULL;
- }
- while((newms = ast_waitfor(chan, ms)) > 0) {
- f = ast_read(chan);
- if (!f) {
- /* Got hangup */
- break;
- }
- if (f->frametype == AST_FRAME_CONTROL) {
- switch(f->subclass) {
- case AST_CONTROL_ANSWER:
- /* Launch the PBX */
- ast_copy_string(chan->exten, pvt->pri->idleext, sizeof(chan->exten));
- ast_copy_string(chan->context, pvt->pri->idlecontext, sizeof(chan->context));
- chan->priority = 1;
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "Idle channel '%s' answered, sending to %s@%s\n", chan->name, chan->exten, chan->context);
- ast_pbx_run(chan);
- /* It's already hungup, return immediately */
- return NULL;
- case AST_CONTROL_BUSY:
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "Idle channel '%s' busy, waiting...\n", chan->name);
- break;
- case AST_CONTROL_CONGESTION:
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "Idle channel '%s' congested, waiting...\n", chan->name);
- break;
- };
- }
- ast_frfree(f);
- ms = newms;
- }
-#if 0
- printf("Hanging up '%s'\n", chan->name);
-#endif
- /* Hangup the channel since nothing happend */
- ast_hangup(chan);
- return NULL;
-}
-
-#ifndef PRI_RESTART
-#error "Upgrade your libpri"
-#endif
-static void zt_pri_message(struct pri *pri, char *s)
-{
- int x, y;
- int dchan = -1, span = -1;
- int dchancount = 0;
-
- if (pri) {
- for (x = 0; x < NUM_SPANS; x++) {
- for (y = 0; y < NUM_DCHANS; y++) {
- if (pris[x].dchans[y])
- dchancount++;
-
- if (pris[x].dchans[y] == pri)
- dchan = y;
- }
- if (dchan >= 0) {
- span = x;
- break;
- }
- dchancount = 0;
- }
- if ((dchan >= 0) && (span >= 0)) {
- if (dchancount > 1)
- ast_verbose("[Span %d D-Channel %d]%s", span, dchan, s);
- else
- ast_verbose("%s", s);
- } else
- ast_verbose("PRI debug error: could not find pri associated it with debug message output\n");
- } else
- ast_verbose("%s", s);
-
- ast_mutex_lock(&pridebugfdlock);
-
- if (pridebugfd >= 0)
- write(pridebugfd, s, strlen(s));
-
- ast_mutex_unlock(&pridebugfdlock);
-}
-
-static void zt_pri_error(struct pri *pri, char *s)
-{
- int x, y;
- int dchan = -1, span = -1;
- int dchancount = 0;
-
- if (pri) {
- for (x = 0; x < NUM_SPANS; x++) {
- for (y = 0; y < NUM_DCHANS; y++) {
- if (pris[x].dchans[y])
- dchancount++;
-
- if (pris[x].dchans[y] == pri)
- dchan = y;
- }
- if (dchan >= 0) {
- span = x;
- break;
- }
- dchancount = 0;
- }
- if ((dchan >= 0) && (span >= 0)) {
- if (dchancount > 1)
- ast_log(LOG_WARNING, "[Span %d D-Channel %d] PRI: %s", span, dchan, s);
- else
- ast_verbose("%s", s);
- } else
- ast_verbose("PRI debug error: could not find pri associated it with debug message output\n");
- } else
- ast_log(LOG_WARNING, "%s", s);
-
- ast_mutex_lock(&pridebugfdlock);
-
- if (pridebugfd >= 0)
- write(pridebugfd, s, strlen(s));
-
- ast_mutex_unlock(&pridebugfdlock);
-}
-
-static int pri_check_restart(struct zt_pri *pri)
-{
- do {
- pri->resetpos++;
- } while((pri->resetpos < pri->numchans) &&
- (!pri->pvts[pri->resetpos] ||
- pri->pvts[pri->resetpos]->call ||
- pri->pvts[pri->resetpos]->resetting));
- if (pri->resetpos < pri->numchans) {
- /* Mark the channel as resetting and restart it */
- pri->pvts[pri->resetpos]->resetting = 1;
- pri_reset(pri->pri, PVT_TO_CHANNEL(pri->pvts[pri->resetpos]));
- } else {
- pri->resetting = 0;
- time(&pri->lastreset);
- }
- return 0;
-}
-
-static int pri_hangup_all(struct zt_pvt *p, struct zt_pri *pri)
-{
- int x;
- int redo;
- ast_mutex_unlock(&pri->lock);
- ast_mutex_lock(&p->lock);
- do {
- redo = 0;
- for (x=0;x<3;x++) {
- while(p->subs[x].owner && ast_mutex_trylock(&p->subs[x].owner->lock)) {
- redo++;
- ast_mutex_unlock(&p->lock);
- usleep(1);
- ast_mutex_lock(&p->lock);
- }
- if (p->subs[x].owner) {
- ast_queue_hangup(p->subs[x].owner);
- ast_mutex_unlock(&p->subs[x].owner->lock);
- }
- }
- } while (redo);
- ast_mutex_unlock(&p->lock);
- ast_mutex_lock(&pri->lock);
- return 0;
-}
-char * redirectingreason2str(int redirectingreason)
-{
- switch (redirectingreason) {
- case 0:
- return "UNKNOWN";
- case 1:
- return "BUSY";
- case 2:
- return "NO_REPLY";
- case 0xF:
- return "UNCONDITIONAL";
- default:
- return "NOREDIRECT";
- }
-}
-
-static void apply_plan_to_number(char *buf, size_t size, const struct zt_pri *pri, const char *number, const int plan)
-{
- switch (plan) {
- case PRI_INTERNATIONAL_ISDN: /* Q.931 dialplan == 0x11 international dialplan => prepend international prefix digits */
- snprintf(buf, size, "%s%s", pri->internationalprefix, number);
- break;
- case PRI_NATIONAL_ISDN: /* Q.931 dialplan == 0x21 national dialplan => prepend national prefix digits */
- snprintf(buf, size, "%s%s", pri->nationalprefix, number);
- break;
- case PRI_LOCAL_ISDN: /* Q.931 dialplan == 0x41 local dialplan => prepend local prefix digits */
- snprintf(buf, size, "%s%s", pri->localprefix, number);
- break;
- case PRI_PRIVATE: /* Q.931 dialplan == 0x49 private dialplan => prepend private prefix digits */
- snprintf(buf, size, "%s%s", pri->privateprefix, number);
- break;
- case PRI_UNKNOWN: /* Q.931 dialplan == 0x00 unknown dialplan => prepend unknown prefix digits */
- snprintf(buf, size, "%s%s", pri->unknownprefix, number);
- break;
- default: /* other Q.931 dialplan => don't twiddle with callingnum */
- snprintf(buf, size, "%s", number);
- break;
- }
-}
-
-static void *pri_dchannel(void *vpri)
-{
- struct zt_pri *pri = vpri;
- pri_event *e;
- struct pollfd fds[NUM_DCHANS];
- int res;
- int chanpos = 0;
- int x;
- int haveidles;
- int activeidles;
- int nextidle = -1;
- struct ast_channel *c;
- struct timeval tv, lowest, *next;
- struct timeval lastidle = { 0, 0 };
- int doidling=0;
- char *cc;
- char idlen[80];
- struct ast_channel *idle;
- pthread_t p;
- time_t t;
- int i, which=-1;
- int numdchans;
- int cause=0;
- struct zt_pvt *crv;
- pthread_t threadid;
- pthread_attr_t attr;
- char ani2str[6];
- char plancallingnum[256];
- char plancallingani[256];
- char calledtonstr[10];
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- gettimeofday(&lastidle, NULL);
- if (!ast_strlen_zero(pri->idledial) && !ast_strlen_zero(pri->idleext)) {
- /* Need to do idle dialing, check to be sure though */
- cc = strchr(pri->idleext, '@');
- if (cc) {
- *cc = '\0';
- cc++;
- ast_copy_string(pri->idlecontext, cc, sizeof(pri->idlecontext));
-#if 0
- /* Extensions may not be loaded yet */
- if (!ast_exists_extension(NULL, pri->idlecontext, pri->idleext, 1, NULL))
- ast_log(LOG_WARNING, "Extension '%s @ %s' does not exist\n", pri->idleext, pri->idlecontext);
- else
-#endif
- doidling = 1;
- } else
- ast_log(LOG_WARNING, "Idle dial string '%s' lacks '@context'\n", pri->idleext);
- }
- for(;;) {
- for (i=0;i<NUM_DCHANS;i++) {
- if (!pri->dchannels[i])
- break;
- fds[i].fd = pri->fds[i];
- fds[i].events = POLLIN | POLLPRI;
- fds[i].revents = 0;
- }
- numdchans = i;
- time(&t);
- ast_mutex_lock(&pri->lock);
- if (pri->switchtype != PRI_SWITCH_GR303_TMC && (pri->resetinterval > 0)) {
- if (pri->resetting && pri_is_up(pri)) {
- if (pri->resetpos < 0)
- pri_check_restart(pri);
- } else {
- if (!pri->resetting && (t - pri->lastreset) >= pri->resetinterval) {
- pri->resetting = 1;
- pri->resetpos = -1;
- }
- }
- }
- /* Look for any idle channels if appropriate */
- if (doidling && pri_is_up(pri)) {
- nextidle = -1;
- haveidles = 0;
- activeidles = 0;
- for (x=pri->numchans;x>=0;x--) {
- if (pri->pvts[x] && !pri->pvts[x]->owner &&
- !pri->pvts[x]->call) {
- if (haveidles < pri->minunused) {
- haveidles++;
- } else if (!pri->pvts[x]->resetting) {
- nextidle = x;
- break;
- }
- } else if (pri->pvts[x] && pri->pvts[x]->owner && pri->pvts[x]->isidlecall)
- activeidles++;
- }
-#if 0
- printf("nextidle: %d, haveidles: %d, minunsed: %d\n",
- nextidle, haveidles, minunused);
- printf("nextidle: %d, haveidles: %d, ms: %ld, minunsed: %d\n",
- nextidle, haveidles, ast_tvdiff_ms(ast_tvnow(), lastidle), minunused);
-#endif
- if (nextidle > -1) {
- if (ast_tvdiff_ms(ast_tvnow(), lastidle) > 1000) {
- /* Don't create a new idle call more than once per second */
- snprintf(idlen, sizeof(idlen), "%d/%s", pri->pvts[nextidle]->channel, pri->idledial);
- idle = zt_request("Zap", AST_FORMAT_ULAW, idlen, &cause);
- if (idle) {
- pri->pvts[nextidle]->isidlecall = 1;
- if (ast_pthread_create(&p, NULL, do_idle_thread, idle)) {
- ast_log(LOG_WARNING, "Unable to start new thread for idle channel '%s'\n", idle->name);
- zt_hangup(idle);
- }
- } else
- ast_log(LOG_WARNING, "Unable to request channel 'Zap/%s' for idle call\n", idlen);
- gettimeofday(&lastidle, NULL);
- }
- } else if ((haveidles < pri->minunused) &&
- (activeidles > pri->minidle)) {
- /* Mark something for hangup if there is something
- that can be hungup */
- for (x=pri->numchans;x>=0;x--) {
- /* find a candidate channel */
- if (pri->pvts[x] && pri->pvts[x]->owner && pri->pvts[x]->isidlecall) {
- pri->pvts[x]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- haveidles++;
- /* Stop if we have enough idle channels or
- can't spare any more active idle ones */
- if ((haveidles >= pri->minunused) ||
- (activeidles <= pri->minidle))
- break;
- }
- }
- }
- }
- /* Start with reasonable max */
- lowest = ast_tv(60, 0);
- for (i=0; i<NUM_DCHANS; i++) {
- /* Find lowest available d-channel */
- if (!pri->dchannels[i])
- break;
- if ((next = pri_schedule_next(pri->dchans[i]))) {
- /* We need relative time here */
- tv = ast_tvsub(*next, ast_tvnow());
- if (tv.tv_sec < 0) {
- tv = ast_tv(0,0);
- }
- if (doidling || pri->resetting) {
- if (tv.tv_sec > 1) {
- tv = ast_tv(1, 0);
- }
- } else {
- if (tv.tv_sec > 60) {
- tv = ast_tv(60, 0);
- }
- }
- } else if (doidling || pri->resetting) {
- /* Make sure we stop at least once per second if we're
- monitoring idle channels */
- tv = ast_tv(1,0);
- } else {
- /* Don't poll for more than 60 seconds */
- tv = ast_tv(60, 0);
- }
- if (!i || ast_tvcmp(tv, lowest) < 0) {
- lowest = tv;
- }
- }
- ast_mutex_unlock(&pri->lock);
-
- e = NULL;
- res = poll(fds, numdchans, lowest.tv_sec * 1000 + lowest.tv_usec / 1000);
-
- ast_mutex_lock(&pri->lock);
- if (!res) {
- for (which=0;which<NUM_DCHANS;which++) {
- if (!pri->dchans[which])
- break;
- /* Just a timeout, run the scheduler */
- e = pri_schedule_run(pri->dchans[which]);
- if (e)
- break;
- }
- } else if (res > -1) {
- for (which=0;which<NUM_DCHANS;which++) {
- if (!pri->dchans[which])
- break;
- if (fds[which].revents & POLLPRI) {
- /* Check for an event */
- x = 0;
- res = ioctl(pri->fds[which], ZT_GETEVENT, &x);
- if (x)
- ast_log(LOG_NOTICE, "PRI got event: %s (%d) on %s D-channel of span %d\n", event2str(x), x, pri_order(which), pri->span);
- /* Keep track of alarm state */
- if (x == ZT_EVENT_ALARM) {
- pri->dchanavail[which] &= ~(DCHAN_NOTINALARM | DCHAN_UP);
- pri_find_dchan(pri);
- } else if (x == ZT_EVENT_NOALARM) {
- pri->dchanavail[which] |= DCHAN_NOTINALARM;
- pri_restart(pri->dchans[which]);
- }
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Got event %s (%d) on D-channel for span %d\n", event2str(x), x, pri->span);
- } else if (fds[which].revents & POLLIN) {
- e = pri_check_event(pri->dchans[which]);
- }
- if (e)
- break;
- }
- } else if (errno != EINTR)
- ast_log(LOG_WARNING, "pri_event returned error %d (%s)\n", errno, strerror(errno));
-
- if (e) {
- if (pri->debug)
- pri_dump_event(pri->dchans[which], e);
- if (e->e != PRI_EVENT_DCHAN_DOWN)
- pri->dchanavail[which] |= DCHAN_UP;
- switch(e->e) {
- case PRI_EVENT_DCHAN_UP:
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "%s D-Channel on span %d up\n", pri_order(which), pri->span);
- pri->dchanavail[which] |= DCHAN_UP;
- if (!pri->pri) pri_find_dchan(pri);
-
- /* Note presense of D-channel */
- time(&pri->lastreset);
-
- /* Restart in 5 seconds */
- if (pri->resetinterval > -1) {
- pri->lastreset -= pri->resetinterval;
- pri->lastreset += 5;
- }
- pri->resetting = 0;
- /* Take the channels from inalarm condition */
- for (i=0; i<pri->numchans; i++)
- if (pri->pvts[i]) {
- pri->pvts[i]->inalarm = 0;
- }
- break;
- case PRI_EVENT_DCHAN_DOWN:
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "%s D-Channel on span %d down\n", pri_order(which), pri->span);
- pri->dchanavail[which] &= ~DCHAN_UP;
- pri_find_dchan(pri);
- if (!pri_is_up(pri)) {
- pri->resetting = 0;
- /* Hangup active channels and put them in alarm mode */
- for (i=0; i<pri->numchans; i++) {
- struct zt_pvt *p = pri->pvts[i];
- if (p) {
- if (p->call) {
- if (p->pri && p->pri->pri) {
- pri_hangup(p->pri->pri, p->call, -1);
- pri_destroycall(p->pri->pri, p->call);
- p->call = NULL;
- } else
- ast_log(LOG_WARNING, "The PRI Call have not been destroyed\n");
- }
- if (p->realcall) {
- pri_hangup_all(p->realcall, pri);
- } else if (p->owner)
- p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- p->inalarm = 1;
- }
- }
- }
- break;
- case PRI_EVENT_RESTART:
- if (e->restart.channel > -1) {
- chanpos = pri_find_principle(pri, e->restart.channel);
- if (chanpos < 0)
- ast_log(LOG_WARNING, "Restart requested on odd/unavailable channel number %d/%d on span %d\n",
- PRI_SPAN(e->restart.channel), PRI_CHANNEL(e->restart.channel), pri->span);
- else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "B-channel %d/%d restarted on span %d\n",
- PRI_SPAN(e->restart.channel), PRI_CHANNEL(e->restart.channel), pri->span);
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- if (pri->pvts[chanpos]->call) {
- pri_destroycall(pri->pri, pri->pvts[chanpos]->call);
- pri->pvts[chanpos]->call = NULL;
- }
- /* Force soft hangup if appropriate */
- if (pri->pvts[chanpos]->realcall)
- pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
- else if (pri->pvts[chanpos]->owner)
- pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_2 "Restart on requested on entire span %d\n", pri->span);
- for (x=0;x < pri->numchans;x++)
- if (pri->pvts[x]) {
- ast_mutex_lock(&pri->pvts[x]->lock);
- if (pri->pvts[x]->call) {
- pri_destroycall(pri->pri, pri->pvts[x]->call);
- pri->pvts[x]->call = NULL;
- }
- if (pri->pvts[chanpos]->realcall)
- pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
- else if (pri->pvts[x]->owner)
- pri->pvts[x]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_mutex_unlock(&pri->pvts[x]->lock);
- }
- }
- break;
- case PRI_EVENT_KEYPAD_DIGIT:
- chanpos = pri_find_principle(pri, e->digit.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "KEYPAD_DIGITs received on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->digit.channel), PRI_CHANNEL(e->digit.channel), pri->span);
- } else {
- chanpos = pri_fixup_principle(pri, chanpos, e->digit.call);
- if (chanpos > -1) {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- /* queue DTMF frame if the PBX for this call was already started (we're forwarding KEYPAD_DIGITs further on */
- if (pri->overlapdial && pri->pvts[chanpos]->call==e->digit.call && pri->pvts[chanpos]->owner) {
- /* how to do that */
- int digitlen = strlen(e->digit.digits);
- char digit;
- int i;
- for (i=0; i<digitlen; i++) {
- digit = e->digit.digits[i];
- {
- struct ast_frame f = { AST_FRAME_DTMF, digit, };
- zap_queue_frame(pri->pvts[chanpos], &f, pri);
- }
- }
- }
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- }
- break;
-
- case PRI_EVENT_INFO_RECEIVED:
- chanpos = pri_find_principle(pri, e->ring.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "INFO received on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->ring.channel), PRI_CHANNEL(e->ring.channel), pri->span);
- } else {
- chanpos = pri_fixup_principle(pri, chanpos, e->ring.call);
- if (chanpos > -1) {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- /* queue DTMF frame if the PBX for this call was already started (we're forwarding INFORMATION further on */
- if (pri->overlapdial && pri->pvts[chanpos]->call==e->ring.call && pri->pvts[chanpos]->owner) {
- /* how to do that */
- int digitlen = strlen(e->ring.callednum);
- char digit;
- int i;
- for (i=0; i<digitlen; i++) {
- digit = e->ring.callednum[i];
- {
- struct ast_frame f = { AST_FRAME_DTMF, digit, };
- zap_queue_frame(pri->pvts[chanpos], &f, pri);
- }
- }
- }
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- }
- break;
- case PRI_EVENT_RING:
- crv = NULL;
- if (e->ring.channel == -1)
- chanpos = pri_find_empty_chan(pri, 1);
- else
- chanpos = pri_find_principle(pri, e->ring.channel);
- /* if no channel specified find one empty */
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Ring requested on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->ring.channel), PRI_CHANNEL(e->ring.channel), pri->span);
- } else {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- if (pri->pvts[chanpos]->owner) {
- if (pri->pvts[chanpos]->call == e->ring.call) {
- ast_log(LOG_WARNING, "Duplicate setup requested on channel %d/%d already in use on span %d\n",
- PRI_SPAN(e->ring.channel), PRI_CHANNEL(e->ring.channel), pri->span);
- break;
- } else {
- ast_log(LOG_WARNING, "Ring requested on channel %d/%d already in use on span %d. Hanging up owner.\n",
- PRI_SPAN(e->ring.channel), PRI_CHANNEL(e->ring.channel), pri->span);
- if (pri->pvts[chanpos]->realcall)
- pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
- else
- pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- chanpos = -1;
- }
- }
- if (chanpos > -1)
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- if ((chanpos < 0) && (e->ring.flexible))
- chanpos = pri_find_empty_chan(pri, 1);
- if (chanpos > -1) {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- if (pri->switchtype == PRI_SWITCH_GR303_TMC) {
- /* Should be safe to lock CRV AFAIK while bearer is still locked */
- crv = pri_find_crv(pri, pri_get_crv(pri->pri, e->ring.call, NULL));
- if (crv)
- ast_mutex_lock(&crv->lock);
- if (!crv || crv->owner) {
- pri->pvts[chanpos]->call = NULL;
- if (crv) {
- if (crv->owner)
- crv->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_log(LOG_WARNING, "Call received for busy CRV %d on span %d\n", pri_get_crv(pri->pri, e->ring.call, NULL), pri->span);
- } else
- ast_log(LOG_NOTICE, "Call received for unconfigured CRV %d on span %d\n", pri_get_crv(pri->pri, e->ring.call, NULL), pri->span);
- pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_INVALID_CALL_REFERENCE);
- if (crv)
- ast_mutex_unlock(&crv->lock);
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- break;
- }
- }
- pri->pvts[chanpos]->call = e->ring.call;
- apply_plan_to_number(plancallingnum, sizeof(plancallingnum), pri, e->ring.callingnum, e->ring.callingplan);
- if (pri->pvts[chanpos]->use_callerid) {
- ast_shrink_phone_number(plancallingnum);
- ast_copy_string(pri->pvts[chanpos]->cid_num, plancallingnum, sizeof(pri->pvts[chanpos]->cid_num));
-#ifdef PRI_ANI
- if (!ast_strlen_zero(e->ring.callingani)) {
- apply_plan_to_number(plancallingani, sizeof(plancallingani), pri, e->ring.callingani, e->ring.callingplanani);
- ast_shrink_phone_number(plancallingani);
- ast_copy_string(pri->pvts[chanpos]->cid_ani, plancallingani, sizeof(pri->pvts[chanpos]->cid_ani));
- } else {
- pri->pvts[chanpos]->cid_ani[0] = '\0';
- }
-#endif
- ast_copy_string(pri->pvts[chanpos]->cid_name, e->ring.callingname, sizeof(pri->pvts[chanpos]->cid_name));
- pri->pvts[chanpos]->cid_ton = e->ring.callingplan; /* this is the callingplan (TON/NPI), e->ring.callingplan>>4 would be the TON */
- } else {
- pri->pvts[chanpos]->cid_num[0] = '\0';
- pri->pvts[chanpos]->cid_ani[0] = '\0';
- pri->pvts[chanpos]->cid_name[0] = '\0';
- pri->pvts[chanpos]->cid_ton = 0;
- }
- apply_plan_to_number(pri->pvts[chanpos]->rdnis, sizeof(pri->pvts[chanpos]->rdnis), pri,
- e->ring.redirectingnum, e->ring.callingplanrdnis);
- /* If immediate=yes go to s|1 */
- if (pri->pvts[chanpos]->immediate) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Going to extension s|1 because of immediate=yes\n");
- pri->pvts[chanpos]->exten[0] = 's';
- pri->pvts[chanpos]->exten[1] = '\0';
- }
- /* Get called number */
- else if (!ast_strlen_zero(e->ring.callednum)) {
- ast_copy_string(pri->pvts[chanpos]->exten, e->ring.callednum, sizeof(pri->pvts[chanpos]->exten));
- ast_copy_string(pri->pvts[chanpos]->dnid, e->ring.callednum, sizeof(pri->pvts[chanpos]->dnid));
- } else
- pri->pvts[chanpos]->exten[0] = '\0';
- /* Set DNID on all incoming calls -- even immediate */
- if (!ast_strlen_zero(e->ring.callednum))
- ast_copy_string(pri->pvts[chanpos]->dnid, e->ring.callednum, sizeof(pri->pvts[chanpos]->dnid));
- /* No number yet, but received "sending complete"? */
- if (e->ring.complete && (ast_strlen_zero(e->ring.callednum))) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Going to extension s|1 because of Complete received\n");
- pri->pvts[chanpos]->exten[0] = 's';
- pri->pvts[chanpos]->exten[1] = '\0';
- }
- /* Make sure extension exists (or in overlap dial mode, can exist) */
- if ((pri->overlapdial && ast_canmatch_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) ||
- ast_exists_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) {
- /* Setup law */
- int law;
- if (pri->switchtype != PRI_SWITCH_GR303_TMC) {
- /* Set to audio mode at this point */
- law = 1;
- if (ioctl(pri->pvts[chanpos]->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &law) == -1)
- ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d\n", pri->pvts[chanpos]->channel, law);
- }
- if (e->ring.layer1 == PRI_LAYER_1_ALAW)
- law = ZT_LAW_ALAW;
- else
- law = ZT_LAW_MULAW;
- res = zt_setlaw(pri->pvts[chanpos]->subs[SUB_REAL].zfd, law);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pri->pvts[chanpos]->channel);
- res = set_actual_gain(pri->pvts[chanpos]->subs[SUB_REAL].zfd, 0, pri->pvts[chanpos]->rxgain, pri->pvts[chanpos]->txgain, law);
- if (res < 0)
- ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pri->pvts[chanpos]->channel);
- if (e->ring.complete || !pri->overlapdial)
- /* Just announce proceeding */
- pri_proceeding(pri->pri, e->ring.call, PVT_TO_CHANNEL(pri->pvts[chanpos]), 0);
- else {
- if (pri->switchtype != PRI_SWITCH_GR303_TMC)
- pri_need_more_info(pri->pri, e->ring.call, PVT_TO_CHANNEL(pri->pvts[chanpos]), 1);
- else
- pri_answer(pri->pri, e->ring.call, PVT_TO_CHANNEL(pri->pvts[chanpos]), 1);
- }
- /* Get the use_callingpres state */
- pri->pvts[chanpos]->callingpres = e->ring.callingpres;
-
- /* Start PBX */
- if (pri->overlapdial && ast_matchmore_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) {
- /* Release the PRI lock while we create the channel */
- ast_mutex_unlock(&pri->lock);
- if (crv) {
- /* Set bearer and such */
- pri_assign_bearer(crv, pri, pri->pvts[chanpos]);
- c = zt_new(crv, AST_STATE_RESERVED, 0, SUB_REAL, law, e->ring.ctype);
- pri->pvts[chanpos]->owner = &inuse;
- ast_log(LOG_DEBUG, "Started up crv %d:%d on bearer channel %d\n", pri->trunkgroup, crv->channel, crv->bearer->channel);
- } else {
- c = zt_new(pri->pvts[chanpos], AST_STATE_RESERVED, 0, SUB_REAL, law, e->ring.ctype);
- }
- if (!ast_strlen_zero(e->ring.callingsubaddr)) {
- pbx_builtin_setvar_helper(c, "CALLINGSUBADDR", e->ring.callingsubaddr);
- }
- if(e->ring.ani2 >= 0) {
- snprintf(ani2str, 5, "%.2d", e->ring.ani2);
- pbx_builtin_setvar_helper(c, "ANI2", ani2str);
- }
-
-#ifdef SUPPORT_USERUSER
- if (!ast_strlen_zero(e->ring.useruserinfo)) {
- pbx_builtin_setvar_helper(c, "USERUSERINFO", e->ring.useruserinfo);
- }
-#endif
-
- snprintf(calledtonstr, sizeof(calledtonstr)-1, "%d", e->ring.calledplan);
- pbx_builtin_setvar_helper(c, "CALLEDTON", calledtonstr);
- if (e->ring.redirectingreason >= 0)
- pbx_builtin_setvar_helper(c, "PRIREDIRECTREASON", redirectingreason2str(e->ring.redirectingreason));
-
- ast_mutex_lock(&pri->lock);
- if (c && !ast_pthread_create(&threadid, &attr, ss_thread, c)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Accepting overlap call from '%s' to '%s' on channel %d/%d, span %d\n",
- plancallingnum, !ast_strlen_zero(pri->pvts[chanpos]->exten) ? pri->pvts[chanpos]->exten : "<unspecified>",
- pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
- } else {
- ast_log(LOG_WARNING, "Unable to start PBX on channel %d/%d, span %d\n",
- pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
- if (c)
- ast_hangup(c);
- else {
- pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_SWITCH_CONGESTION);
- pri->pvts[chanpos]->call = NULL;
- }
- }
- } else {
- ast_mutex_unlock(&pri->lock);
- /* Release PRI lock while we create the channel */
- c = zt_new(pri->pvts[chanpos], AST_STATE_RING, 1, SUB_REAL, law, e->ring.ctype);
- ast_mutex_lock(&pri->lock);
- if (c) {
- char calledtonstr[10];
- if(e->ring.ani2 >= 0) {
- snprintf(ani2str, 5, "%d", e->ring.ani2);
- pbx_builtin_setvar_helper(c, "ANI2", ani2str);
- }
-
-#ifdef SUPPORT_USERUSER
- if (!ast_strlen_zero(e->ring.useruserinfo)) {
- pbx_builtin_setvar_helper(c, "USERUSERINFO", e->ring.useruserinfo);
- }
-#endif
-
- if (e->ring.redirectingreason >= 0)
- pbx_builtin_setvar_helper(c, "PRIREDIRECTREASON", redirectingreason2str(e->ring.redirectingreason));
-
- snprintf(calledtonstr, sizeof(calledtonstr)-1, "%d", e->ring.calledplan);
- pbx_builtin_setvar_helper(c, "CALLEDTON", calledtonstr);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Accepting call from '%s' to '%s' on channel %d/%d, span %d\n",
- plancallingnum, pri->pvts[chanpos]->exten,
- pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
- zt_enable_ec(pri->pvts[chanpos]);
- } else {
- ast_log(LOG_WARNING, "Unable to start PBX on channel %d/%d, span %d\n",
- pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
- pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_SWITCH_CONGESTION);
- pri->pvts[chanpos]->call = NULL;
- }
- }
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Extension '%s' in context '%s' from '%s' does not exist. Rejecting call on channel %d/%d, span %d\n",
- pri->pvts[chanpos]->exten, pri->pvts[chanpos]->context, pri->pvts[chanpos]->cid_num, pri->pvts[chanpos]->logicalspan,
- pri->pvts[chanpos]->prioffset, pri->span);
- pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_UNALLOCATED);
- pri->pvts[chanpos]->call = NULL;
- pri->pvts[chanpos]->exten[0] = '\0';
- }
- if (crv)
- ast_mutex_unlock(&crv->lock);
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- } else
- pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_REQUESTED_CHAN_UNAVAIL);
- break;
- case PRI_EVENT_RINGING:
- chanpos = pri_find_principle(pri, e->ringing.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Ringing requested on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->ringing.channel), PRI_CHANNEL(e->ringing.channel), pri->span);
- chanpos = -1;
- }
- if (chanpos > -1) {
- chanpos = pri_fixup_principle(pri, chanpos, e->ringing.call);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Ringing requested on channel %d/%d not in use on span %d\n",
- PRI_SPAN(e->ringing.channel), PRI_CHANNEL(e->ringing.channel), pri->span);
- chanpos = -1;
- } else {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- if (ast_strlen_zero(pri->pvts[chanpos]->dop.dialstr)) {
- zt_enable_ec(pri->pvts[chanpos]);
- pri->pvts[chanpos]->subs[SUB_REAL].needringing = 1;
- pri->pvts[chanpos]->alerting = 1;
- } else
- ast_log(LOG_DEBUG, "Deferring ringing notification because of extra digits to dial...\n");
-#ifdef PRI_PROGRESS_MASK
- if (e->ringing.progressmask & PRI_PROG_INBAND_AVAILABLE) {
-#else
- if (e->ringing.progress == 8) {
-#endif
- /* Now we can do call progress detection */
- if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
- /* RINGING detection isn't required because we got ALERTING signal */
- ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features & ~DSP_PROGRESS_RINGING);
- pri->pvts[chanpos]->dsp_features = 0;
- }
- }
-
-#ifdef SUPPORT_USERUSER
- if (!ast_strlen_zero(e->ringing.useruserinfo)) {
- pbx_builtin_setvar_helper(pri->pvts[chanpos]->owner, "USERUSERINFO", e->ringing.useruserinfo);
- }
-#endif
-
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- }
- break;
- case PRI_EVENT_PROGRESS:
- /* Get chan value if e->e is not PRI_EVNT_RINGING */
- chanpos = pri_find_principle(pri, e->proceeding.channel);
- if (chanpos > -1) {
-#ifdef PRI_PROGRESS_MASK
- if ((!pri->pvts[chanpos]->progress) || (e->proceeding.progressmask & PRI_PROG_INBAND_AVAILABLE)) {
-#else
- if ((!pri->pvts[chanpos]->progress) || (e->proceeding.progress == 8)) {
-#endif
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROGRESS, };
-
- if (e->proceeding.cause > -1) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "PROGRESS with cause code %d received\n", e->proceeding.cause);
-
- /* Work around broken, out of spec USER_BUSY cause in a progress message */
- if (e->proceeding.cause == AST_CAUSE_USER_BUSY) {
- if (pri->pvts[chanpos]->owner) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "PROGRESS with 'user busy' received, signaling AST_CONTROL_BUSY instead of AST_CONTROL_PROGRESS\n");
-
- pri->pvts[chanpos]->owner->hangupcause = e->proceeding.cause;
- f.subclass = AST_CONTROL_BUSY;
- }
- }
- }
-
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- ast_log(LOG_DEBUG, "Queuing frame from PRI_EVENT_PROGRESS on channel %d/%d span %d\n",
- pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset,pri->span);
- zap_queue_frame(pri->pvts[chanpos], &f, pri);
-#ifdef PRI_PROGRESS_MASK
- if (e->proceeding.progressmask & PRI_PROG_INBAND_AVAILABLE) {
-#else
- if (e->proceeding.progress == 8) {
-#endif
- /* Now we can do call progress detection */
- if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
- ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
- pri->pvts[chanpos]->dsp_features = 0;
- }
- }
- pri->pvts[chanpos]->progress = 1;
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- }
- break;
- case PRI_EVENT_PROCEEDING:
- chanpos = pri_find_principle(pri, e->proceeding.channel);
- if (chanpos > -1) {
- if (!pri->pvts[chanpos]->proceeding) {
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROCEEDING, };
-
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- ast_log(LOG_DEBUG, "Queuing frame from PRI_EVENT_PROCEEDING on channel %d/%d span %d\n",
- pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset,pri->span);
- zap_queue_frame(pri->pvts[chanpos], &f, pri);
-#ifdef PRI_PROGRESS_MASK
- if (e->proceeding.progressmask & PRI_PROG_INBAND_AVAILABLE) {
-#else
- if (e->proceeding.progress == 8) {
-#endif
- /* Now we can do call progress detection */
- if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
- ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
- pri->pvts[chanpos]->dsp_features = 0;
- }
- /* Bring voice path up */
- f.subclass = AST_CONTROL_PROGRESS;
- zap_queue_frame(pri->pvts[chanpos], &f, pri);
- }
- pri->pvts[chanpos]->proceeding = 1;
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- }
- break;
- case PRI_EVENT_FACNAME:
- chanpos = pri_find_principle(pri, e->facname.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Facility Name requested on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->facname.channel), PRI_CHANNEL(e->facname.channel), pri->span);
- chanpos = -1;
- }
- if (chanpos > -1) {
- chanpos = pri_fixup_principle(pri, chanpos, e->facname.call);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Facility Name requested on channel %d/%d not in use on span %d\n",
- PRI_SPAN(e->facname.channel), PRI_CHANNEL(e->facname.channel), pri->span);
- chanpos = -1;
- } else {
- /* Re-use *69 field for PRI */
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- ast_copy_string(pri->pvts[chanpos]->lastcid_num, e->facname.callingnum, sizeof(pri->pvts[chanpos]->lastcid_num));
- ast_copy_string(pri->pvts[chanpos]->lastcid_name, e->facname.callingname, sizeof(pri->pvts[chanpos]->lastcid_name));
- pri->pvts[chanpos]->subs[SUB_REAL].needcallerid =1;
- zt_enable_ec(pri->pvts[chanpos]);
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- }
- break;
- case PRI_EVENT_ANSWER:
- chanpos = pri_find_principle(pri, e->answer.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Answer on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->answer.channel), PRI_CHANNEL(e->answer.channel), pri->span);
- chanpos = -1;
- }
- if (chanpos > -1) {
- chanpos = pri_fixup_principle(pri, chanpos, e->answer.call);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Answer requested on channel %d/%d not in use on span %d\n",
- PRI_SPAN(e->answer.channel), PRI_CHANNEL(e->answer.channel), pri->span);
- chanpos = -1;
- } else {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- /* Now we can do call progress detection */
-
- /* We changed this so it turns on the DSP no matter what... progress or no progress.
- * By this time, we need DTMF detection and other features that were previously disabled
- * -- Matt F */
- if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
- ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
- pri->pvts[chanpos]->dsp_features = 0;
- }
- if (pri->pvts[chanpos]->realcall && (pri->pvts[chanpos]->realcall->sig == SIG_FXSKS)) {
- ast_log(LOG_DEBUG, "Starting up GR-303 trunk now that we got CONNECT...\n");
- x = ZT_START;
- res = ioctl(pri->pvts[chanpos]->subs[SUB_REAL].zfd, ZT_HOOK, &x);
- if (res < 0) {
- if (errno != EINPROGRESS) {
- ast_log(LOG_WARNING, "Unable to start channel: %s\n", strerror(errno));
- }
- }
- } else if (!ast_strlen_zero(pri->pvts[chanpos]->dop.dialstr)) {
- pri->pvts[chanpos]->dialing = 1;
- /* Send any "w" waited stuff */
- res = ioctl(pri->pvts[chanpos]->subs[SUB_REAL].zfd, ZT_DIAL, &pri->pvts[chanpos]->dop);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", pri->pvts[chanpos]->channel);
- pri->pvts[chanpos]->dop.dialstr[0] = '\0';
- } else
- ast_log(LOG_DEBUG, "Sent deferred digit string: %s\n", pri->pvts[chanpos]->dop.dialstr);
- pri->pvts[chanpos]->dop.dialstr[0] = '\0';
- } else if (pri->pvts[chanpos]->confirmanswer) {
- ast_log(LOG_DEBUG, "Waiting on answer confirmation on channel %d!\n", pri->pvts[chanpos]->channel);
- } else {
- pri->pvts[chanpos]->subs[SUB_REAL].needanswer =1;
- /* Enable echo cancellation if it's not on already */
- zt_enable_ec(pri->pvts[chanpos]);
- }
-
-#ifdef SUPPORT_USERUSER
- if (!ast_strlen_zero(e->answer.useruserinfo)) {
- pbx_builtin_setvar_helper(pri->pvts[chanpos]->owner, "USERUSERINFO", e->answer.useruserinfo);
- }
-#endif
-
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- }
- break;
- case PRI_EVENT_HANGUP:
- chanpos = pri_find_principle(pri, e->hangup.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Hangup requested on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
- chanpos = -1;
- }
- if (chanpos > -1) {
- chanpos = pri_fixup_principle(pri, chanpos, e->hangup.call);
- if (chanpos > -1) {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- if (!pri->pvts[chanpos]->alreadyhungup) {
- /* we're calling here zt_hangup so once we get there we need to clear p->call after calling pri_hangup */
- pri->pvts[chanpos]->alreadyhungup = 1;
- if (pri->pvts[chanpos]->realcall)
- pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
- else if (pri->pvts[chanpos]->owner) {
- /* Queue a BUSY instead of a hangup if our cause is appropriate */
- pri->pvts[chanpos]->owner->hangupcause = e->hangup.cause;
- switch(e->hangup.cause) {
- case PRI_CAUSE_USER_BUSY:
- pri->pvts[chanpos]->subs[SUB_REAL].needbusy =1;
- break;
- case PRI_CAUSE_CALL_REJECTED:
- case PRI_CAUSE_NETWORK_OUT_OF_ORDER:
- case PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION:
- case PRI_CAUSE_SWITCH_CONGESTION:
- case PRI_CAUSE_DESTINATION_OUT_OF_ORDER:
- case PRI_CAUSE_NORMAL_TEMPORARY_FAILURE:
- pri->pvts[chanpos]->subs[SUB_REAL].needcongestion =1;
- break;
- default:
- pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- }
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d/%d, span %d got hangup\n",
- pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
- } else {
- pri_hangup(pri->pri, pri->pvts[chanpos]->call, e->hangup.cause);
- pri->pvts[chanpos]->call = NULL;
- }
- if (e->hangup.cause == PRI_CAUSE_REQUESTED_CHAN_UNAVAIL) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Forcing restart of channel %d/%d on span %d since channel reported in use\n",
- PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
- pri_reset(pri->pri, PVT_TO_CHANNEL(pri->pvts[chanpos]));
- pri->pvts[chanpos]->resetting = 1;
- }
- if (e->hangup.aoc_units > -1)
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d/%d, span %d received AOC-E charging %d unit%s\n",
- pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span, (int)e->hangup.aoc_units, (e->hangup.aoc_units == 1) ? "" : "s");
-
-#ifdef SUPPORT_USERUSER
- if (!ast_strlen_zero(e->hangup.useruserinfo)) {
- pbx_builtin_setvar_helper(pri->pvts[chanpos]->owner, "USERUSERINFO", e->hangup.useruserinfo);
- }
-#endif
-
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- } else {
- ast_log(LOG_WARNING, "Hangup on bad channel %d/%d on span %d\n",
- PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
- }
- }
- break;
-#ifndef PRI_EVENT_HANGUP_REQ
-#error please update libpri
-#endif
- case PRI_EVENT_HANGUP_REQ:
- chanpos = pri_find_principle(pri, e->hangup.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Hangup REQ requested on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
- chanpos = -1;
- }
- if (chanpos > -1) {
- chanpos = pri_fixup_principle(pri, chanpos, e->hangup.call);
- if (chanpos > -1) {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- if (pri->pvts[chanpos]->realcall)
- pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
- else if (pri->pvts[chanpos]->owner) {
- pri->pvts[chanpos]->owner->hangupcause = e->hangup.cause;
- switch(e->hangup.cause) {
- case PRI_CAUSE_USER_BUSY:
- pri->pvts[chanpos]->subs[SUB_REAL].needbusy =1;
- break;
- case PRI_CAUSE_CALL_REJECTED:
- case PRI_CAUSE_NETWORK_OUT_OF_ORDER:
- case PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION:
- case PRI_CAUSE_SWITCH_CONGESTION:
- case PRI_CAUSE_DESTINATION_OUT_OF_ORDER:
- case PRI_CAUSE_NORMAL_TEMPORARY_FAILURE:
- pri->pvts[chanpos]->subs[SUB_REAL].needcongestion =1;
- break;
- default:
- pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d/%d, span %d got hangup request\n", PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
- if (e->hangup.aoc_units > -1)
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d/%d, span %d received AOC-E charging %d unit%s\n",
- pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span, (int)e->hangup.aoc_units, (e->hangup.aoc_units == 1) ? "" : "s");
- } else {
- pri_hangup(pri->pri, pri->pvts[chanpos]->call, e->hangup.cause);
- pri->pvts[chanpos]->call = NULL;
- }
- if (e->hangup.cause == PRI_CAUSE_REQUESTED_CHAN_UNAVAIL) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Forcing restart of channel %d/%d span %d since channel reported in use\n",
- PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
- pri_reset(pri->pri, PVT_TO_CHANNEL(pri->pvts[chanpos]));
- pri->pvts[chanpos]->resetting = 1;
- }
-
-#ifdef SUPPORT_USERUSER
- if (!ast_strlen_zero(e->hangup.useruserinfo)) {
- pbx_builtin_setvar_helper(pri->pvts[chanpos]->owner, "USERUSERINFO", e->hangup.useruserinfo);
- }
-#endif
-
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- } else {
- ast_log(LOG_WARNING, "Hangup REQ on bad channel %d/%d on span %d\n", PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
- }
- }
- break;
- case PRI_EVENT_HANGUP_ACK:
- chanpos = pri_find_principle(pri, e->hangup.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Hangup ACK requested on unconfigured channel number %d/%d span %d\n",
- PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
- chanpos = -1;
- }
- if (chanpos > -1) {
- chanpos = pri_fixup_principle(pri, chanpos, e->hangup.call);
- if (chanpos > -1) {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- pri->pvts[chanpos]->call = NULL;
- pri->pvts[chanpos]->resetting = 0;
- if (pri->pvts[chanpos]->owner) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d/%d, span %d got hangup ACK\n", PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
- }
-
-#ifdef SUPPORT_USERUSER
- if (!ast_strlen_zero(e->hangup.useruserinfo)) {
- pbx_builtin_setvar_helper(pri->pvts[chanpos]->owner, "USERUSERINFO", e->hangup.useruserinfo);
- }
-#endif
-
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- }
- break;
- case PRI_EVENT_CONFIG_ERR:
- ast_log(LOG_WARNING, "PRI Error: %s\n", e->err.err);
- break;
- case PRI_EVENT_RESTART_ACK:
- chanpos = pri_find_principle(pri, e->restartack.channel);
- if (chanpos < 0) {
- /* Sometime switches (e.g. I421 / British Telecom) don't give us the
- channel number, so we have to figure it out... This must be why
- everybody resets exactly a channel at a time. */
- for (x=0;x<pri->numchans;x++) {
- if (pri->pvts[x] && pri->pvts[x]->resetting) {
- chanpos = x;
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- ast_log(LOG_DEBUG, "Assuming restart ack is really for channel %d/%d span %d\n", pri->pvts[chanpos]->logicalspan,
- pri->pvts[chanpos]->prioffset, pri->span);
- if (pri->pvts[chanpos]->realcall)
- pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
- else if (pri->pvts[chanpos]->owner) {
- ast_log(LOG_WARNING, "Got restart ack on channel %d/%d with owner on span %d\n", pri->pvts[chanpos]->logicalspan,
- pri->pvts[chanpos]->prioffset, pri->span);
- pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- }
- pri->pvts[chanpos]->resetting = 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "B-channel %d/%d successfully restarted on span %d\n", pri->pvts[chanpos]->logicalspan,
- pri->pvts[chanpos]->prioffset, pri->span);
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- if (pri->resetting)
- pri_check_restart(pri);
- break;
- }
- }
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Restart ACK requested on strange channel %d/%d span %d\n",
- PRI_SPAN(e->restartack.channel), PRI_CHANNEL(e->restartack.channel), pri->span);
- }
- chanpos = -1;
- }
- if (chanpos > -1) {
- if (pri->pvts[chanpos]) {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- if (pri->pvts[chanpos]->realcall)
- pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
- else if (pri->pvts[chanpos]->owner) {
- ast_log(LOG_WARNING, "Got restart ack on channel %d/%d span %d with owner\n",
- PRI_SPAN(e->restartack.channel), PRI_CHANNEL(e->restartack.channel), pri->span);
- pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- }
- pri->pvts[chanpos]->resetting = 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "B-channel %d/%d successfully restarted on span %d\n", pri->pvts[chanpos]->logicalspan,
- pri->pvts[chanpos]->prioffset, pri->span);
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- if (pri->resetting)
- pri_check_restart(pri);
- }
- }
- break;
- case PRI_EVENT_SETUP_ACK:
- chanpos = pri_find_principle(pri, e->setup_ack.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Received SETUP_ACKNOWLEDGE on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->setup_ack.channel), PRI_CHANNEL(e->setup_ack.channel), pri->span);
- } else {
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- pri->pvts[chanpos]->setup_ack = 1;
- /* Send any queued digits */
- for (x=0;x<strlen(pri->pvts[chanpos]->dialdest);x++) {
- ast_log(LOG_DEBUG, "Sending pending digit '%c'\n", pri->pvts[chanpos]->dialdest[x]);
- pri_information(pri->pri, pri->pvts[chanpos]->call,
- pri->pvts[chanpos]->dialdest[x]);
- }
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- break;
- case PRI_EVENT_NOTIFY:
- chanpos = pri_find_principle(pri, e->notify.channel);
- if (chanpos < 0) {
- ast_log(LOG_WARNING, "Received NOTIFY on unconfigured channel %d/%d span %d\n",
- PRI_SPAN(e->notify.channel), PRI_CHANNEL(e->notify.channel), pri->span);
- } else {
- struct ast_frame f = { AST_FRAME_CONTROL, };
- ast_mutex_lock(&pri->pvts[chanpos]->lock);
- switch(e->notify.info) {
- case PRI_NOTIFY_REMOTE_HOLD:
- f.subclass = AST_CONTROL_HOLD;
- zap_queue_frame(pri->pvts[chanpos], &f, pri);
- break;
- case PRI_NOTIFY_REMOTE_RETRIEVAL:
- f.subclass = AST_CONTROL_UNHOLD;
- zap_queue_frame(pri->pvts[chanpos], &f, pri);
- break;
- }
- ast_mutex_unlock(&pri->pvts[chanpos]->lock);
- }
- break;
- default:
- ast_log(LOG_DEBUG, "Event: %d\n", e->e);
- }
- }
- ast_mutex_unlock(&pri->lock);
- }
- /* Never reached */
- return NULL;
-}
-
-static int start_pri(struct zt_pri *pri)
-{
- int res, x;
- ZT_PARAMS p;
- ZT_BUFFERINFO bi;
- struct zt_spaninfo si;
- int i;
-
- for (i=0;i<NUM_DCHANS;i++) {
- if (!pri->dchannels[i])
- break;
- pri->fds[i] = open("/dev/zap/channel", O_RDWR, 0600);
- x = pri->dchannels[i];
- if ((pri->fds[i] < 0) || (ioctl(pri->fds[i],ZT_SPECIFY,&x) == -1)) {
- ast_log(LOG_ERROR, "Unable to open D-channel %d (%s)\n", x, strerror(errno));
- return -1;
- }
- res = ioctl(pri->fds[i], ZT_GET_PARAMS, &p);
- if (res) {
- zt_close(pri->fds[i]);
- pri->fds[i] = -1;
- ast_log(LOG_ERROR, "Unable to get parameters for D-channel %d (%s)\n", x, strerror(errno));
- return -1;
- }
- if (p.sigtype != ZT_SIG_HDLCFCS) {
- zt_close(pri->fds[i]);
- pri->fds[i] = -1;
- ast_log(LOG_ERROR, "D-channel %d is not in HDLC/FCS mode. See /etc/zaptel.conf\n", x);
- return -1;
- }
- memset(&si, 0, sizeof(si));
- res = ioctl(pri->fds[i], ZT_SPANSTAT, &si);
- if (res) {
- zt_close(pri->fds[i]);
- pri->fds[i] = -1;
- ast_log(LOG_ERROR, "Unable to get span state for D-channel %d (%s)\n", x, strerror(errno));
- }
- if (!si.alarms)
- pri->dchanavail[i] |= DCHAN_NOTINALARM;
- else
- pri->dchanavail[i] &= ~DCHAN_NOTINALARM;
- bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.numbufs = 32;
- bi.bufsize = 1024;
- if (ioctl(pri->fds[i], ZT_SET_BUFINFO, &bi)) {
- ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d\n", x);
- zt_close(pri->fds[i]);
- pri->fds[i] = -1;
- return -1;
- }
- pri->dchans[i] = pri_new(pri->fds[i], pri->nodetype, pri->switchtype);
- /* Force overlap dial if we're doing GR-303! */
- if (pri->switchtype == PRI_SWITCH_GR303_TMC)
- pri->overlapdial = 1;
- pri_set_overlapdial(pri->dchans[i],pri->overlapdial);
- /* Enslave to master if appropriate */
- if (i)
- pri_enslave(pri->dchans[0], pri->dchans[i]);
- if (!pri->dchans[i]) {
- zt_close(pri->fds[i]);
- pri->fds[i] = -1;
- ast_log(LOG_ERROR, "Unable to create PRI structure\n");
- return -1;
- }
- pri_set_debug(pri->dchans[i], DEFAULT_PRI_DEBUG);
- pri_set_nsf(pri->dchans[i], pri->nsf);
-#ifdef PRI_GETSET_TIMERS
- for (x = 0; x < PRI_MAX_TIMERS; x++) {
- if (pritimers[x] != 0)
- pri_set_timer(pri->dchans[i], x, pritimers[x]);
- }
-#endif
- }
- /* Assume primary is the one we use */
- pri->pri = pri->dchans[0];
- pri->resetpos = -1;
- if (ast_pthread_create(&pri->master, NULL, pri_dchannel, pri)) {
- for (i=0;i<NUM_DCHANS;i++) {
- if (!pri->dchannels[i])
- break;
- zt_close(pri->fds[i]);
- pri->fds[i] = -1;
- }
- ast_log(LOG_ERROR, "Unable to spawn D-channel: %s\n", strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static char *complete_span_helper(char *line, char *word, int pos, int state, int rpos)
-{
- int span=1;
- char tmp[50];
- if (pos != rpos)
- return 0;
- while(span <= NUM_SPANS) {
- if (span > state && pris[span-1].pri)
- break;
- span++;
- }
- if (span <= NUM_SPANS) {
- snprintf(tmp, sizeof(tmp), "%d", span);
- return strdup(tmp);
- } else
- return NULL;
-}
-
-static char *complete_span_4(char *line, char *word, int pos, int state)
-{
- return complete_span_helper(line,word,pos,state,3);
-}
-
-static char *complete_span_5(char *line, char *word, int pos, int state)
-{
- return complete_span_helper(line,word,pos,state,4);
-}
-
-static int handle_pri_set_debug_file(int fd, int argc, char **argv)
-{
- int myfd;
-
- if (!strncasecmp(argv[1], "set", 3)) {
- if (argc < 5)
- return RESULT_SHOWUSAGE;
-
- if (ast_strlen_zero(argv[4]))
- return RESULT_SHOWUSAGE;
-
- myfd = open(argv[4], O_CREAT|O_WRONLY);
- if (myfd < 0) {
- ast_cli(fd, "Unable to open '%s' for writing\n", argv[4]);
- return RESULT_SUCCESS;
- }
-
- ast_mutex_lock(&pridebugfdlock);
-
- if (pridebugfd >= 0)
- close(pridebugfd);
-
- pridebugfd = myfd;
- ast_copy_string(pridebugfilename,argv[4],sizeof(pridebugfilename));
-
- ast_mutex_unlock(&pridebugfdlock);
-
- ast_cli(fd, "PRI debug output will be sent to '%s'\n", argv[4]);
- } else {
- /* Assume it is unset */
- ast_mutex_lock(&pridebugfdlock);
- close(pridebugfd);
- pridebugfd = -1;
- ast_cli(fd, "PRI debug output to file disabled\n");
- ast_mutex_unlock(&pridebugfdlock);
- }
-
- return RESULT_SUCCESS;
-}
-
-static int handle_pri_debug(int fd, int argc, char *argv[])
-{
- int span;
- int x;
- if (argc < 4) {
- return RESULT_SHOWUSAGE;
- }
- span = atoi(argv[3]);
- if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid span %s. Should be a number %d to %d\n", argv[3], 1, NUM_SPANS);
- return RESULT_SUCCESS;
- }
- if (!pris[span-1].pri) {
- ast_cli(fd, "No PRI running on span %d\n", span);
- return RESULT_SUCCESS;
- }
- for (x=0;x<NUM_DCHANS;x++) {
- if (pris[span-1].dchans[x])
- pri_set_debug(pris[span-1].dchans[x], PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE);
- }
- ast_cli(fd, "Enabled debugging on span %d\n", span);
- return RESULT_SUCCESS;
-}
-
-
-
-static int handle_pri_no_debug(int fd, int argc, char *argv[])
-{
- int span;
- int x;
- if (argc < 5)
- return RESULT_SHOWUSAGE;
- span = atoi(argv[4]);
- if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid span %s. Should be a number %d to %d\n", argv[4], 1, NUM_SPANS);
- return RESULT_SUCCESS;
- }
- if (!pris[span-1].pri) {
- ast_cli(fd, "No PRI running on span %d\n", span);
- return RESULT_SUCCESS;
- }
- for (x=0;x<NUM_DCHANS;x++) {
- if (pris[span-1].dchans[x])
- pri_set_debug(pris[span-1].dchans[x], 0);
- }
- ast_cli(fd, "Disabled debugging on span %d\n", span);
- return RESULT_SUCCESS;
-}
-
-static int handle_pri_really_debug(int fd, int argc, char *argv[])
-{
- int span;
- int x;
- if (argc < 5)
- return RESULT_SHOWUSAGE;
- span = atoi(argv[4]);
- if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid span %s. Should be a number %d to %d\n", argv[4], 1, NUM_SPANS);
- return RESULT_SUCCESS;
- }
- if (!pris[span-1].pri) {
- ast_cli(fd, "No PRI running on span %d\n", span);
- return RESULT_SUCCESS;
- }
- for (x=0;x<NUM_DCHANS;x++) {
- if (pris[span-1].dchans[x])
- pri_set_debug(pris[span-1].dchans[x], (PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_STATE));
- }
- ast_cli(fd, "Enabled EXTENSIVE debugging on span %d\n", span);
- return RESULT_SUCCESS;
-}
-
-static void build_status(char *s, size_t len, int status, int active)
-{
- if (!s || len < 1) {
- return;
- }
- s[0] = '\0';
- if (status & DCHAN_PROVISIONED)
- strncat(s, "Provisioned, ", len - strlen(s) - 1);
- if (!(status & DCHAN_NOTINALARM))
- strncat(s, "In Alarm, ", len - strlen(s) - 1);
- if (status & DCHAN_UP)
- strncat(s, "Up", len - strlen(s) - 1);
- else
- strncat(s, "Down", len - strlen(s) - 1);
- if (active)
- strncat(s, ", Active", len - strlen(s) - 1);
- else
- strncat(s, ", Standby", len - strlen(s) - 1);
- s[len - 1] = '\0';
-}
-
-static int handle_pri_show_span(int fd, int argc, char *argv[])
-{
- int span;
- int x;
- char status[256];
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- span = atoi(argv[3]);
- if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid span %s. Should be a number %d to %d\n", argv[4], 1, NUM_SPANS);
- return RESULT_SUCCESS;
- }
- if (!pris[span-1].pri) {
- ast_cli(fd, "No PRI running on span %d\n", span);
- return RESULT_SUCCESS;
- }
- for(x=0;x<NUM_DCHANS;x++) {
- if (pris[span-1].dchannels[x]) {
-#ifdef PRI_DUMP_INFO_STR
- char *info_str = NULL;
-#endif
- ast_cli(fd, "%s D-channel: %d\n", pri_order(x), pris[span-1].dchannels[x]);
- build_status(status, sizeof(status), pris[span-1].dchanavail[x], pris[span-1].dchans[x] == pris[span-1].pri);
- ast_cli(fd, "Status: %s\n", status);
-#ifdef PRI_DUMP_INFO_STR
- info_str = pri_dump_info_str(pris[span-1].pri);
- if (info_str) {
- ast_cli(fd, "%s", info_str);
- free(info_str);
- }
-#else
- pri_dump_info(pris[span-1].pri);
-#endif
- ast_cli(fd, "\n");
- }
- }
- return RESULT_SUCCESS;
-}
-
-static int handle_pri_show_debug(int fd, int argc, char *argv[])
-{
- int x;
- int span;
- int count=0;
- int debug=0;
-
- for(span=0;span<NUM_SPANS;span++) {
- if (pris[span].pri) {
- for(x=0;x<NUM_DCHANS;x++) {
- debug=0;
- if (pris[span].dchans[x]) {
- debug = pri_get_debug(pris[span].dchans[x]);
- ast_cli(fd, "Span %d: Debug: %s\tIntense: %s\n", span+1, (debug&PRI_DEBUG_Q931_STATE)? "Yes" : "No" ,(debug&PRI_DEBUG_Q921_RAW)? "Yes" : "No" );
- count++;
- }
- }
- }
-
- }
- ast_mutex_lock(&pridebugfdlock);
- if (pridebugfd >= 0)
- ast_cli(fd, "Logging PRI debug to file %s\n", pridebugfilename);
- ast_mutex_unlock(&pridebugfdlock);
-
- if (!count)
- ast_cli(fd, "No debug set or no PRI running\n");
- return RESULT_SUCCESS;
-}
-
-static char pri_debug_help[] =
- "Usage: pri debug span <span>\n"
- " Enables debugging on a given PRI span\n";
-
-static char pri_no_debug_help[] =
- "Usage: pri no debug span <span>\n"
- " Disables debugging on a given PRI span\n";
-
-static char pri_really_debug_help[] =
- "Usage: pri intensive debug span <span>\n"
- " Enables debugging down to the Q.921 level\n";
-
-static char pri_show_span_help[] =
- "Usage: pri show span <span>\n"
- " Displays PRI Information\n";
-
-static struct ast_cli_entry zap_pri_cli[] = {
- { { "pri", "debug", "span", NULL }, handle_pri_debug,
- "Enables PRI debugging on a span", pri_debug_help, complete_span_4 },
- { { "pri", "no", "debug", "span", NULL }, handle_pri_no_debug,
- "Disables PRI debugging on a span", pri_no_debug_help, complete_span_5 },
- { { "pri", "intense", "debug", "span", NULL }, handle_pri_really_debug,
- "Enables REALLY INTENSE PRI debugging", pri_really_debug_help, complete_span_5 },
- { { "pri", "show", "span", NULL }, handle_pri_show_span,
- "Displays PRI Information", pri_show_span_help, complete_span_4 },
- { { "pri", "show", "debug", NULL }, handle_pri_show_debug,
- "Displays current PRI debug settings" },
- { { "pri", "set", "debug", "file", NULL }, handle_pri_set_debug_file,
- "Sends PRI debug output to the specified file" },
- { { "pri", "unset", "debug", "file", NULL }, handle_pri_set_debug_file,
- "Ends PRI debug output to file" },
-};
-
-#endif /* ZAPATA_PRI */
-
-
-#ifdef ZAPATA_R2
-static int handle_r2_no_debug(int fd, int argc, char *argv[])
-{
- int chan;
- struct zt_pvt *tmp = NULL;;
- if (argc < 5)
- return RESULT_SHOWUSAGE;
- chan = atoi(argv[4]);
- if ((chan < 1) || (chan > NUM_SPANS)) {
- ast_cli(fd, "Invalid channel %s. Should be a number greater than 0\n", argv[4]);
- return RESULT_SUCCESS;
- }
- tmp = iflist;
- while(tmp) {
- if (tmp->channel == chan) {
- if (tmp->r2) {
- mfcr2_set_debug(tmp->r2, 0);
- ast_cli(fd, "Disabled R2 debugging on channel %d\n", chan);
- return RESULT_SUCCESS;
- }
- break;
- }
- tmp = tmp->next;
- }
- if (tmp)
- ast_cli(fd, "No R2 running on channel %d\n", chan);
- else
- ast_cli(fd, "No such zap channel %d\n", chan);
- return RESULT_SUCCESS;
-}
-
-static int handle_r2_debug(int fd, int argc, char *argv[])
-{
- int chan;
- struct zt_pvt *tmp = NULL;;
- if (argc < 4) {
- return RESULT_SHOWUSAGE;
- }
- chan = atoi(argv[3]);
- if ((chan < 1) || (chan > NUM_SPANS)) {
- ast_cli(fd, "Invalid channel %s. Should be a number greater than 0\n", argv[3]);
- return RESULT_SUCCESS;
- }
- tmp = iflist;
- while(tmp) {
- if (tmp->channel == chan) {
- if (tmp->r2) {
- mfcr2_set_debug(tmp->r2, 0xFFFFFFFF);
- ast_cli(fd, "Enabled R2 debugging on channel %d\n", chan);
- return RESULT_SUCCESS;
- }
- break;
- }
- tmp = tmp->next;
- }
- if (tmp)
- ast_cli(fd, "No R2 running on channel %d\n", chan);
- else
- ast_cli(fd, "No such zap channel %d\n", chan);
- return RESULT_SUCCESS;
-}
-static char r2_debug_help[] =
- "Usage: r2 debug channel <channel>\n"
- " Enables R2 protocol level debugging on a given channel\n";
-
-static char r2_no_debug_help[] =
- "Usage: r2 no debug channel <channel>\n"
- " Enables R2 protocol level debugging on a given channel\n";
-
-static struct ast_cli_entry zap_r2_cli[] = {
- { { "r2", "debug", "channel", NULL }, handle_r2_debug,
- "Enables R2 debugging on a channel", r2_debug_help },
- { { "r2", "no", "debug", "channel", NULL }, handle_r2_no_debug,
- "Disables R2 debugging on a channel", r2_no_debug_help },
-};
-
-#endif
-
-static int zap_destroy_channel(int fd, int argc, char **argv)
-{
- int channel = 0;
- struct zt_pvt *tmp = NULL;
- struct zt_pvt *prev = NULL;
-
- if (argc != 4) {
- return RESULT_SHOWUSAGE;
- }
- channel = atoi(argv[3]);
-
- tmp = iflist;
- while (tmp) {
- if (tmp->channel == channel) {
- destroy_channel(prev, tmp, 1);
- return RESULT_SUCCESS;
- }
- prev = tmp;
- tmp = tmp->next;
- }
- return RESULT_FAILURE;
-}
-
-static int zap_show_channels(int fd, int argc, char **argv)
-{
-#define FORMAT "%7s %-10.10s %-15.15s %-10.10s %-20.20s\n"
-#define FORMAT2 "%7s %-10.10s %-15.15s %-10.10s %-20.20s\n"
- struct zt_pvt *tmp = NULL;
- char tmps[20] = "";
- ast_mutex_t *lock;
- struct zt_pvt *start;
-#ifdef ZAPATA_PRI
- int trunkgroup;
- struct zt_pri *pri=NULL;
- int x;
-#endif
-
- lock = &iflock;
- start = iflist;
-
-#ifdef ZAPATA_PRI
- if (argc == 4) {
- if ((trunkgroup = atoi(argv[3])) < 1)
- return RESULT_SHOWUSAGE;
- for (x=0;x<NUM_SPANS;x++) {
- if (pris[x].trunkgroup == trunkgroup) {
- pri = pris + x;
- break;
- }
- }
- if (pri) {
- start = pri->crvs;
- lock = &pri->lock;
- } else {
- ast_cli(fd, "No such trunk group %d\n", trunkgroup);
- return RESULT_FAILURE;
- }
- } else
-#endif
- if (argc != 3)
- return RESULT_SHOWUSAGE;
-
- ast_mutex_lock(lock);
-#ifdef ZAPATA_PRI
- ast_cli(fd, FORMAT2, pri ? "CRV" : "Chan", "Extension", "Context", "Language", "MusicOnHold");
-#else
- ast_cli(fd, FORMAT2, "Chan", "Extension", "Context", "Language", "MusicOnHold");
-#endif
-
- tmp = start;
- while (tmp) {
- if (tmp->channel > 0) {
- snprintf(tmps, sizeof(tmps), "%d", tmp->channel);
- } else
- ast_copy_string(tmps, "pseudo", sizeof(tmps));
- ast_cli(fd, FORMAT, tmps, tmp->exten, tmp->context, tmp->language, tmp->musicclass);
- tmp = tmp->next;
- }
- ast_mutex_unlock(lock);
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-static int zap_show_channel(int fd, int argc, char **argv)
-{
- int channel;
- struct zt_pvt *tmp = NULL;
- ZT_CONFINFO ci;
- ZT_PARAMS ps;
- int x;
- ast_mutex_t *lock;
- struct zt_pvt *start;
-#ifdef ZAPATA_PRI
- char *c;
- int trunkgroup;
- struct zt_pri *pri=NULL;
-#endif
-
- lock = &iflock;
- start = iflist;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-#ifdef ZAPATA_PRI
- if ((c = strchr(argv[3], ':'))) {
- if (sscanf(argv[3], "%d:%d", &trunkgroup, &channel) != 2)
- return RESULT_SHOWUSAGE;
- if ((trunkgroup < 1) || (channel < 1))
- return RESULT_SHOWUSAGE;
- for (x=0;x<NUM_SPANS;x++) {
- if (pris[x].trunkgroup == trunkgroup) {
- pri = pris + x;
- break;
- }
- }
- if (pri) {
- start = pri->crvs;
- lock = &pri->lock;
- } else {
- ast_cli(fd, "No such trunk group %d\n", trunkgroup);
- return RESULT_FAILURE;
- }
- } else
-#endif
- channel = atoi(argv[3]);
-
- ast_mutex_lock(lock);
- tmp = start;
- while (tmp) {
- if (tmp->channel == channel) {
-#ifdef ZAPATA_PRI
- if (pri)
- ast_cli(fd, "Trunk/CRV: %d/%d\n", trunkgroup, tmp->channel);
- else
-#endif
- ast_cli(fd, "Channel: %d\n", tmp->channel);
- ast_cli(fd, "File Descriptor: %d\n", tmp->subs[SUB_REAL].zfd);
- ast_cli(fd, "Span: %d\n", tmp->span);
- ast_cli(fd, "Extension: %s\n", tmp->exten);
- ast_cli(fd, "Dialing: %s\n", tmp->dialing ? "yes" : "no");
- ast_cli(fd, "Context: %s\n", tmp->context);
- ast_cli(fd, "Caller ID: %s\n", tmp->cid_num);
- ast_cli(fd, "Calling TON: %d\n", tmp->cid_ton);
- ast_cli(fd, "Caller ID name: %s\n", tmp->cid_name);
- ast_cli(fd, "Destroy: %d\n", tmp->destroy);
- ast_cli(fd, "InAlarm: %d\n", tmp->inalarm);
- ast_cli(fd, "Signalling Type: %s\n", sig2str(tmp->sig));
- ast_cli(fd, "Radio: %d\n", tmp->radio);
- ast_cli(fd, "Owner: %s\n", tmp->owner ? tmp->owner->name : "<None>");
- ast_cli(fd, "Real: %s%s%s\n", tmp->subs[SUB_REAL].owner ? tmp->subs[SUB_REAL].owner->name : "<None>", tmp->subs[SUB_REAL].inthreeway ? " (Confed)" : "", tmp->subs[SUB_REAL].linear ? " (Linear)" : "");
- ast_cli(fd, "Callwait: %s%s%s\n", tmp->subs[SUB_CALLWAIT].owner ? tmp->subs[SUB_CALLWAIT].owner->name : "<None>", tmp->subs[SUB_CALLWAIT].inthreeway ? " (Confed)" : "", tmp->subs[SUB_CALLWAIT].linear ? " (Linear)" : "");
- ast_cli(fd, "Threeway: %s%s%s\n", tmp->subs[SUB_THREEWAY].owner ? tmp->subs[SUB_THREEWAY].owner->name : "<None>", tmp->subs[SUB_THREEWAY].inthreeway ? " (Confed)" : "", tmp->subs[SUB_THREEWAY].linear ? " (Linear)" : "");
- ast_cli(fd, "Confno: %d\n", tmp->confno);
- ast_cli(fd, "Propagated Conference: %d\n", tmp->propconfno);
- ast_cli(fd, "Real in conference: %d\n", tmp->inconference);
- ast_cli(fd, "DSP: %s\n", tmp->dsp ? "yes" : "no");
- ast_cli(fd, "Relax DTMF: %s\n", tmp->dtmfrelax ? "yes" : "no");
- ast_cli(fd, "Dialing/CallwaitCAS: %d/%d\n", tmp->dialing, tmp->callwaitcas);
- ast_cli(fd, "Default law: %s\n", tmp->law == ZT_LAW_MULAW ? "ulaw" : tmp->law == ZT_LAW_ALAW ? "alaw" : "unknown");
- ast_cli(fd, "Fax Handled: %s\n", tmp->faxhandled ? "yes" : "no");
- ast_cli(fd, "Pulse phone: %s\n", tmp->pulsedial ? "yes" : "no");
- ast_cli(fd, "Echo Cancellation: %d taps%s, currently %s\n", tmp->echocancel, tmp->echocanbridged ? "" : " unless TDM bridged", tmp->echocanon ? "ON" : "OFF");
- if (tmp->master)
- ast_cli(fd, "Master Channel: %d\n", tmp->master->channel);
- for (x=0;x<MAX_SLAVES;x++) {
- if (tmp->slaves[x])
- ast_cli(fd, "Slave Channel: %d\n", tmp->slaves[x]->channel);
- }
-#ifdef ZAPATA_PRI
- if (tmp->pri) {
- ast_cli(fd, "PRI Flags: ");
- if (tmp->resetting)
- ast_cli(fd, "Resetting ");
- if (tmp->call)
- ast_cli(fd, "Call ");
- if (tmp->bearer)
- ast_cli(fd, "Bearer ");
- ast_cli(fd, "\n");
- if (tmp->logicalspan)
- ast_cli(fd, "PRI Logical Span: %d\n", tmp->logicalspan);
- else
- ast_cli(fd, "PRI Logical Span: Implicit\n");
- }
-
-#endif
-#ifdef ZAPATA_R2
- if (tmp->r2) {
- ast_cli(fd, "R2 Flags: ");
- if (tmp->r2blocked)
- ast_cli(fd, "Blocked ");
- if (tmp->hasr2call)
- ast_cli(fd, "Call ");
- ast_cli(fd, "\n");
- }
-#endif
- memset(&ci, 0, sizeof(ci));
- ps.channo = tmp->channel;
- if (tmp->subs[SUB_REAL].zfd > -1) {
- if (!ioctl(tmp->subs[SUB_REAL].zfd, ZT_GETCONF, &ci)) {
- ast_cli(fd, "Actual Confinfo: Num/%d, Mode/0x%04x\n", ci.confno, ci.confmode);
- }
-#ifdef ZT_GETCONFMUTE
- if (!ioctl(tmp->subs[SUB_REAL].zfd, ZT_GETCONFMUTE, &x)) {
- ast_cli(fd, "Actual Confmute: %s\n", x ? "Yes" : "No");
- }
-#endif
- if (ioctl(tmp->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &ps) < 0) {
- ast_log(LOG_WARNING, "Failed to get parameters on channel %d\n", tmp->channel);
- } else {
- ast_cli(fd, "Hookstate (FXS only): %s\n", ps.rxisoffhook ? "Offhook" : "Onhook");
- }
- }
- ast_mutex_unlock(lock);
- return RESULT_SUCCESS;
- }
- tmp = tmp->next;
- }
-
- ast_cli(fd, "Unable to find given channel %d\n", channel);
- ast_mutex_unlock(lock);
- return RESULT_FAILURE;
-}
-
-static char zap_show_cadences_help[] =
-"Usage: zap show cadences\n"
-" Shows all cadences currently defined\n";
-
-static int handle_zap_show_cadences(int fd, int argc, char *argv[])
-{
- int i, j;
- for (i=0;i<num_cadence;i++) {
- char output[1024];
- char tmp[16], tmp2[64];
- snprintf(tmp, sizeof(tmp), "r%d: ", i + 1);
- term_color(output, tmp, COLOR_GREEN, COLOR_BLACK, sizeof(output));
-
- for (j=0;j<16;j++) {
- if (cadences[i].ringcadence[j] == 0)
- break;
- snprintf(tmp, sizeof(tmp), "%d", cadences[i].ringcadence[j]);
- if (cidrings[i] * 2 - 1 == j)
- term_color(tmp2, tmp, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp2) - 1);
- else
- term_color(tmp2, tmp, COLOR_GREEN, COLOR_BLACK, sizeof(tmp2) - 1);
- if (j != 0)
- strncat(output, ",", sizeof(output) - strlen(output) - 1);
- strncat(output, tmp2, sizeof(output) - strlen(output) - 1);
- }
- ast_cli(fd,"%s\n",output);
- }
- return 0;
-}
-
-/* Based on irqmiss.c */
-static int zap_show_status(int fd, int argc, char *argv[]) {
- #define FORMAT "%-40.40s %-10.10s %-10d %-10d %-10d\n"
- #define FORMAT2 "%-40.40s %-10.10s %-10.10s %-10.10s %-10.10s\n"
-
- int span;
- int res;
- char alarms[50];
-
- int ctl;
- ZT_SPANINFO s;
-
- ctl = open("/dev/zap/ctl", O_RDWR);
- if (ctl < 0) {
- fprintf(stderr, "Unable to open /dev/zap/ctl: %s\n", strerror(errno));
- ast_cli(fd, "No Zaptel interface found.\n");
- return RESULT_FAILURE;
- }
- ast_cli(fd,FORMAT2, "Description", "Alarms","IRQ","bpviol","CRC4");
-
- for (span=1;span < ZT_MAX_SPANS;++span) {
- s.spanno = span;
- res = ioctl(ctl, ZT_SPANSTAT, &s);
- if (res) {
- continue;
- }
- alarms[0] = '\0';
- if (s.alarms > 0) {
- if (s.alarms & ZT_ALARM_BLUE)
- strcat(alarms,"BLU/");
- if (s.alarms & ZT_ALARM_YELLOW)
- strcat(alarms, "YEL/");
- if (s.alarms & ZT_ALARM_RED)
- strcat(alarms, "RED/");
- if (s.alarms & ZT_ALARM_LOOPBACK)
- strcat(alarms,"LB/");
- if (s.alarms & ZT_ALARM_RECOVER)
- strcat(alarms,"REC/");
- if (s.alarms & ZT_ALARM_NOTOPEN)
- strcat(alarms, "NOP/");
- if (!strlen(alarms))
- strcat(alarms, "UUU/");
- if (strlen(alarms)) {
- /* Strip trailing / */
- alarms[strlen(alarms)-1]='\0';
- }
- } else {
- if (s.numchans)
- strcpy(alarms, "OK");
- else
- strcpy(alarms, "UNCONFIGURED");
- }
-
- ast_cli(fd, FORMAT, s.desc, alarms, s.irqmisses, s.bpvcount, s.crc4count);
- }
- close(ctl);
-
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-static char show_channels_usage[] =
- "Usage: zap show channels\n"
- " Shows a list of available channels\n";
-
-static char show_channel_usage[] =
- "Usage: zap show channel <chan num>\n"
- " Detailed information about a given channel\n";
-
-static char zap_show_status_usage[] =
- "Usage: zap show status\n"
- " Shows a list of Zaptel cards with status\n";
-
-static char destroy_channel_usage[] =
- "Usage: zap destroy channel <chan num>\n"
- " DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING. Immediately removes a given channel, whether it is in use or not\n";
-
-static struct ast_cli_entry zap_cli[] = {
- { { "zap", "show", "cadences", NULL }, handle_zap_show_cadences,
- "List cadences", zap_show_cadences_help },
- { {"zap", "show", "channels", NULL}, zap_show_channels,
- "Show active zapata channels", show_channels_usage },
- { {"zap", "show", "channel", NULL}, zap_show_channel,
- "Show information on a channel", show_channel_usage },
- { {"zap", "destroy", "channel", NULL}, zap_destroy_channel,
- "Destroy a channel", destroy_channel_usage },
- { {"zap", "show", "status", NULL}, zap_show_status,
- "Show all Zaptel cards status", zap_show_status_usage },
-};
-
-#define TRANSFER 0
-#define HANGUP 1
-
-static int zap_fake_event(struct zt_pvt *p, int mode)
-{
- if (p) {
- switch(mode) {
- case TRANSFER:
- p->fake_event = ZT_EVENT_WINKFLASH;
- break;
- case HANGUP:
- p->fake_event = ZT_EVENT_ONHOOK;
- break;
- default:
- ast_log(LOG_WARNING, "I don't know how to handle transfer event with this: %d on channel %s\n",mode, p->owner->name);
- }
- }
- return 0;
-}
-static struct zt_pvt *find_channel(int channel)
-{
- struct zt_pvt *p = iflist;
- while(p) {
- if (p->channel == channel) {
- break;
- }
- p = p->next;
- }
- return p;
-}
-
-static int action_zapdndon(struct mansession *s, struct message *m)
-{
- struct zt_pvt *p = NULL;
- char *channel = astman_get_header(m, "ZapChannel");
- if (ast_strlen_zero(channel)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- p = find_channel(atoi(channel));
- if (!p) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- p->dnd = 1;
- astman_send_ack(s, m, "DND Enabled");
- return 0;
-}
-
-static int action_zapdndoff(struct mansession *s, struct message *m)
-{
- struct zt_pvt *p = NULL;
- char *channel = astman_get_header(m, "ZapChannel");
- if (ast_strlen_zero(channel)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- p = find_channel(atoi(channel));
- if (!p) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- p->dnd = 0;
- astman_send_ack(s, m, "DND Disabled");
- return 0;
-}
-
-static int action_transfer(struct mansession *s, struct message *m)
-{
- struct zt_pvt *p = NULL;
- char *channel = astman_get_header(m, "ZapChannel");
- if (ast_strlen_zero(channel)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- p = find_channel(atoi(channel));
- if (!p) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- zap_fake_event(p,TRANSFER);
- astman_send_ack(s, m, "ZapTransfer");
- return 0;
-}
-
-static int action_transferhangup(struct mansession *s, struct message *m)
-{
- struct zt_pvt *p = NULL;
- char *channel = astman_get_header(m, "ZapChannel");
- if (ast_strlen_zero(channel)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- p = find_channel(atoi(channel));
- if (!p) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- zap_fake_event(p,HANGUP);
- astman_send_ack(s, m, "ZapHangup");
- return 0;
-}
-
-static int action_zapdialoffhook(struct mansession *s, struct message *m)
-{
- struct zt_pvt *p = NULL;
- char *channel = astman_get_header(m, "ZapChannel");
- char *number = astman_get_header(m, "Number");
- int i;
- if (ast_strlen_zero(channel)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- if (ast_strlen_zero(number)) {
- astman_send_error(s, m, "No number specified");
- return 0;
- }
- p = find_channel(atoi(channel));
- if (!p) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- if (!p->owner) {
- astman_send_error(s, m, "Channel does not have it's owner");
- return 0;
- }
- for (i=0; i<strlen(number); i++) {
- struct ast_frame f = { AST_FRAME_DTMF, number[i] };
- zap_queue_frame(p, &f, NULL);
- }
- astman_send_ack(s, m, "ZapDialOffhook");
- return 0;
-}
-
-static int action_zapshowchannels(struct mansession *s, struct message *m)
-{
- struct zt_pvt *tmp = NULL;
- char *id = astman_get_header(m, "ActionID");
- char idText[256] = "";
-
- astman_send_ack(s, m, "Zapata channel status will follow");
- if (!ast_strlen_zero(id))
- snprintf(idText, sizeof(idText) - 1, "ActionID: %s\r\n", id);
-
- ast_mutex_lock(&iflock);
-
- tmp = iflist;
- while (tmp) {
- if (tmp->channel > 0) {
- int alarm = get_alarms(tmp);
- ast_cli(s->fd,
- "Event: ZapShowChannels\r\n"
- "Channel: %d\r\n"
- "Signalling: %s\r\n"
- "Context: %s\r\n"
- "DND: %s\r\n"
- "Alarm: %s\r\n"
- "%s"
- "\r\n",
- tmp->channel, sig2str(tmp->sig), tmp->context,
- tmp->dnd ? "Enabled" : "Disabled",
- alarm2str(alarm), idText);
- }
-
- tmp = tmp->next;
- }
-
- ast_mutex_unlock(&iflock);
-
- ast_cli(s->fd,
- "Event: ZapShowChannelsComplete\r\n"
- "%s"
- "\r\n",
- idText);
- return 0;
-}
-
-static int __unload_module(void)
-{
- int x = 0;
- struct zt_pvt *p, *pl;
-#ifdef ZAPATA_PRI
- int i;
- for(i=0;i<NUM_SPANS;i++) {
- if (pris[i].master != AST_PTHREADT_NULL)
- pthread_cancel(pris[i].master);
- }
- ast_cli_unregister_multiple(zap_pri_cli, sizeof(zap_pri_cli) / sizeof(zap_pri_cli[0]));
-#endif
-#ifdef ZAPATA_R2
- ast_cli_unregister_multiple(zap_r2_cli, sizeof(zap_r2_cli) / sizeof(zap_r2_cli[0]));
-#endif
- ast_cli_unregister_multiple(zap_cli, sizeof(zap_cli) / sizeof(zap_cli[0]));
- ast_manager_unregister( "ZapDialOffhook" );
- ast_manager_unregister( "ZapHangup" );
- ast_manager_unregister( "ZapTransfer" );
- ast_manager_unregister( "ZapDNDoff" );
- ast_manager_unregister( "ZapDNDon" );
- ast_manager_unregister("ZapShowChannels");
- ast_channel_unregister(&zap_tech);
- if (!ast_mutex_lock(&iflock)) {
- /* Hangup all interfaces if they have an owner */
- p = iflist;
- while(p) {
- if (p->owner)
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- p = p->next;
- }
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
- pthread_cancel(monitor_thread);
- pthread_kill(monitor_thread, SIGURG);
- pthread_join(monitor_thread, NULL);
- }
- monitor_thread = AST_PTHREADT_STOP;
- ast_mutex_unlock(&monlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-
- if (!ast_mutex_lock(&iflock)) {
- /* Destroy all the interfaces and free their memory */
- p = iflist;
- while(p) {
- /* Free any callerid */
- if (p->cidspill)
- free(p->cidspill);
- /* Close the zapata thingy */
- if (p->subs[SUB_REAL].zfd > -1)
- zt_close(p->subs[SUB_REAL].zfd);
- pl = p;
- p = p->next;
- x++;
- /* Free associated memory */
- if(pl)
- destroy_zt_pvt(&pl);
- ast_verbose(VERBOSE_PREFIX_3 "Unregistered channel %d\n", x);
- }
- iflist = NULL;
- ifcount = 0;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-#ifdef ZAPATA_PRI
- for(i=0;i<NUM_SPANS;i++) {
- if (pris[i].master && (pris[i].master != AST_PTHREADT_NULL))
- pthread_join(pris[i].master, NULL);
- zt_close(pris[i].fds[i]);
- }
-#endif
- return 0;
-}
-
-int unload_module()
-{
-#ifdef ZAPATA_PRI
- int y;
- for (y=0;y<NUM_SPANS;y++)
- ast_mutex_destroy(&pris[y].lock);
-#endif
- return __unload_module();
-}
-
-static int setup_zap(int reload)
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- struct zt_pvt *tmp;
- char *chan;
- char *c;
- char *ringc;
- int start, finish,x;
- int y;
- int found_pseudo = 0;
- int cur_radio = 0;
-#ifdef ZAPATA_PRI
- int spanno;
- int i;
- int logicalspan;
- int trunkgroup;
- int dchannels[NUM_DCHANS];
- struct zt_pri *pri;
-#endif
-
- cfg = ast_config_load(config);
-
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_ERROR, "Unable to load config %s\n", config);
- return -1;
- }
-
-
- if (ast_mutex_lock(&iflock)) {
- /* It's a little silly to lock it, but we mind as well just to be sure */
- ast_log(LOG_ERROR, "Unable to lock interface list???\n");
- return -1;
- }
-#ifdef ZAPATA_PRI
- if (!reload) {
- /* Process trunkgroups first */
- v = ast_variable_browse(cfg, "trunkgroups");
- while(v) {
- if (!strcasecmp(v->name, "trunkgroup")) {
- trunkgroup = atoi(v->value);
- if (trunkgroup > 0) {
- if ((c = strchr(v->value, ','))) {
- i = 0;
- memset(dchannels, 0, sizeof(dchannels));
- while(c && (i < NUM_DCHANS)) {
- dchannels[i] = atoi(c + 1);
- if (dchannels[i] < 0) {
- ast_log(LOG_WARNING, "D-channel for trunk group %d must be a postiive number at line %d of zapata.conf\n", trunkgroup, v->lineno);
- } else
- i++;
- c = strchr(c + 1, ',');
- }
- if (i) {
- if (pri_create_trunkgroup(trunkgroup, dchannels)) {
- ast_log(LOG_WARNING, "Unable to create trunk group %d with Primary D-channel %d at line %d of zapata.conf\n", trunkgroup, dchannels[0], v->lineno);
- } else if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Created trunk group %d with Primary D-channel %d and %d backup%s\n", trunkgroup, dchannels[0], i - 1, (i == 1) ? "" : "s");
- } else
- ast_log(LOG_WARNING, "Trunk group %d lacks any valid D-channels at line %d of zapata.conf\n", trunkgroup, v->lineno);
- } else
- ast_log(LOG_WARNING, "Trunk group %d lacks a primary D-channel at line %d of zapata.conf\n", trunkgroup, v->lineno);
- } else
- ast_log(LOG_WARNING, "Trunk group identifier must be a positive integer at line %d of zapata.conf\n", v->lineno);
- } else if (!strcasecmp(v->name, "spanmap")) {
- spanno = atoi(v->value);
- if (spanno > 0) {
- if ((c = strchr(v->value, ','))) {
- trunkgroup = atoi(c + 1);
- if (trunkgroup > 0) {
- if ((c = strchr(c + 1, ',')))
- logicalspan = atoi(c + 1);
- else
- logicalspan = 0;
- if (logicalspan >= 0) {
- if (pri_create_spanmap(spanno - 1, trunkgroup, logicalspan)) {
- ast_log(LOG_WARNING, "Failed to map span %d to trunk group %d (logical span %d)\n", spanno, trunkgroup, logicalspan);
- } else if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Mapped span %d to trunk group %d (logical span %d)\n", spanno, trunkgroup, logicalspan);
- } else
- ast_log(LOG_WARNING, "Logical span must be a postive number, or '0' (for unspecified) at line %d of zapata.conf\n", v->lineno);
- } else
- ast_log(LOG_WARNING, "Trunk group must be a postive number at line %d of zapata.conf\n", v->lineno);
- } else
- ast_log(LOG_WARNING, "Missing trunk group for span map at line %d of zapata.conf\n", v->lineno);
- } else
- ast_log(LOG_WARNING, "Span number must be a postive integer at line %d of zapata.conf\n", v->lineno);
- } else {
- ast_log(LOG_NOTICE, "Ignoring unknown keyword '%s' in trunkgroups\n", v->name);
- }
- v = v->next;
- }
- }
-#endif
- v = ast_variable_browse(cfg, "channels");
- while(v) {
- /* Create the interface list */
- if (!strcasecmp(v->name, "channel")
-#ifdef ZAPATA_PRI
- || !strcasecmp(v->name, "crv")
-#endif
- ) {
- if (reload == 0) {
- if (cur_signalling < 0) {
- ast_log(LOG_ERROR, "Signalling must be specified before any channels are.\n");
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- }
- c = v->value;
-
-#ifdef ZAPATA_PRI
- pri = NULL;
- if (!strcasecmp(v->name, "crv")) {
- if (sscanf(c, "%d:%n", &trunkgroup, &y) != 1) {
- ast_log(LOG_WARNING, "CRV must begin with trunkgroup followed by a colon at line %d\n", v->lineno);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- if (trunkgroup < 1) {
- ast_log(LOG_WARNING, "CRV trunk group must be a postive number at line %d\n", v->lineno);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- c+=y;
- for (y=0;y<NUM_SPANS;y++) {
- if (pris[y].trunkgroup == trunkgroup) {
- pri = pris + y;
- break;
- }
- }
- if (!pri) {
- ast_log(LOG_WARNING, "No such trunk group %d at CRV declaration at line %d\n", trunkgroup, v->lineno);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- }
-#endif
- chan = strsep(&c, ",");
- while(chan) {
- if (sscanf(chan, "%d-%d", &start, &finish) == 2) {
- /* Range */
- } else if (sscanf(chan, "%d", &start)) {
- /* Just one */
- finish = start;
- } else if (!strcasecmp(chan, "pseudo")) {
- finish = start = CHAN_PSEUDO;
- found_pseudo = 1;
- } else {
- ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'\n", v->value, chan);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- if (finish < start) {
- ast_log(LOG_WARNING, "Sillyness: %d < %d\n", start, finish);
- x = finish;
- finish = start;
- start = x;
- }
- for (x=start;x<=finish;x++) {
-#ifdef ZAPATA_PRI
- tmp = mkintf(x, cur_signalling, cur_radio, pri, reload);
-#else
- tmp = mkintf(x, cur_signalling, cur_radio, NULL, reload);
-#endif
-
- if (tmp) {
- if (option_verbose > 2) {
-#ifdef ZAPATA_PRI
- if (pri)
- ast_verbose(VERBOSE_PREFIX_3 "%s CRV %d:%d, %s signalling\n", reload ? "Reconfigured" : "Registered", trunkgroup,x, sig2str(tmp->sig));
- else
-#endif
- ast_verbose(VERBOSE_PREFIX_3 "%s channel %d, %s signalling\n", reload ? "Reconfigured" : "Registered", x, sig2str(tmp->sig));
- }
- } else {
- if (reload == 1)
- ast_log(LOG_ERROR, "Unable to reconfigure channel '%s'\n", v->value);
- else
- ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- }
- chan = strsep(&c, ",");
- }
- } else if (!strcasecmp(v->name, "usedistinctiveringdetection")) {
- if (ast_true(v->value))
- usedistinctiveringdetection = 1;
- } else if (!strcasecmp(v->name, "dring1context")) {
- ast_copy_string(drings.ringContext[0].contextData,v->value,sizeof(drings.ringContext[0].contextData));
- } else if (!strcasecmp(v->name, "dring2context")) {
- ast_copy_string(drings.ringContext[1].contextData,v->value,sizeof(drings.ringContext[1].contextData));
- } else if (!strcasecmp(v->name, "dring3context")) {
- ast_copy_string(drings.ringContext[2].contextData,v->value,sizeof(drings.ringContext[2].contextData));
- } else if (!strcasecmp(v->name, "dring1")) {
- ringc = v->value;
- sscanf(ringc, "%d,%d,%d", &drings.ringnum[0].ring[0], &drings.ringnum[0].ring[1], &drings.ringnum[0].ring[2]);
- } else if (!strcasecmp(v->name, "dring2")) {
- ringc = v->value;
- sscanf(ringc,"%d,%d,%d", &drings.ringnum[1].ring[0], &drings.ringnum[1].ring[1], &drings.ringnum[1].ring[2]);
- } else if (!strcasecmp(v->name, "dring3")) {
- ringc = v->value;
- sscanf(ringc, "%d,%d,%d", &drings.ringnum[2].ring[0], &drings.ringnum[2].ring[1], &drings.ringnum[2].ring[2]);
- } else if (!strcasecmp(v->name, "usecallerid")) {
- use_callerid = ast_true(v->value);
- } else if (!strcasecmp(v->name, "cidsignalling")) {
- if (!strcasecmp(v->value, "bell"))
- cid_signalling = CID_SIG_BELL;
- else if (!strcasecmp(v->value, "v23"))
- cid_signalling = CID_SIG_V23;
- else if (!strcasecmp(v->value, "dtmf"))
- cid_signalling = CID_SIG_DTMF;
- else if (ast_true(v->value))
- cid_signalling = CID_SIG_BELL;
- } else if (!strcasecmp(v->name, "cidstart")) {
- if (!strcasecmp(v->value, "ring"))
- cid_start = CID_START_RING;
- else if (!strcasecmp(v->value, "polarity"))
- cid_start = CID_START_POLARITY;
- else if (ast_true(v->value))
- cid_start = CID_START_RING;
- } else if (!strcasecmp(v->name, "threewaycalling")) {
- threewaycalling = ast_true(v->value);
- } else if (!strcasecmp(v->name, "cancallforward")) {
- cancallforward = ast_true(v->value);
- } else if (!strcasecmp(v->name, "relaxdtmf")) {
- if (ast_true(v->value))
- relaxdtmf = DSP_DIGITMODE_RELAXDTMF;
- else
- relaxdtmf = 0;
- } else if (!strcasecmp(v->name, "mailbox")) {
- ast_copy_string(mailbox, v->value, sizeof(mailbox));
- } else if (!strcasecmp(v->name, "adsi")) {
- adsi = ast_true(v->value);
- } else if (!strcasecmp(v->name, "transfer")) {
- transfer = ast_true(v->value);
- } else if (!strcasecmp(v->name, "canpark")) {
- canpark = ast_true(v->value);
- } else if (!strcasecmp(v->name, "echocancelwhenbridged")) {
- echocanbridged = ast_true(v->value);
- } else if (!strcasecmp(v->name, "busydetect")) {
- busydetect = ast_true(v->value);
- } else if (!strcasecmp(v->name, "busycount")) {
- busycount = atoi(v->value);
- } else if (!strcasecmp(v->name, "busypattern")) {
- if (sscanf(v->value, "%d,%d", &busy_tonelength, &busy_quietlength) != 2) {
- ast_log(LOG_ERROR, "busypattern= expects busypattern=tonelength,quietlength\n");
- }
- } else if (!strcasecmp(v->name, "callprogress")) {
- if (ast_true(v->value))
- callprogress |= 1;
- else
- callprogress &= ~1;
- } else if (!strcasecmp(v->name, "faxdetect")) {
- if (!strcasecmp(v->value, "incoming")) {
- callprogress |= 4;
- callprogress &= ~2;
- } else if (!strcasecmp(v->value, "outgoing")) {
- callprogress &= ~4;
- callprogress |= 2;
- } else if (!strcasecmp(v->value, "both") || ast_true(v->value))
- callprogress |= 6;
- else
- callprogress &= ~6;
- } else if (!strcasecmp(v->name, "echocancel")) {
- if (!ast_strlen_zero(v->value)) {
- y = atoi(v->value);
- } else
- y = 0;
- if ((y == 32) || (y == 64) || (y == 128) || (y == 256))
- echocancel = y;
- else {
- echocancel = ast_true(v->value);
- if (echocancel)
- echocancel=128;
- }
- } else if (!strcasecmp(v->name, "echotraining")) {
- if (sscanf(v->value, "%d", &y) == 1) {
- if ((y < 10) || (y > 4000)) {
- ast_log(LOG_WARNING, "Echo training time must be within the range of 10 to 2000 ms at line %d\n", v->lineno);
- } else {
- echotraining = y;
- }
- } else if (ast_true(v->value)) {
- echotraining = 400;
- } else
- echotraining = 0;
- } else if (!strcasecmp(v->name, "hidecallerid")) {
- hidecallerid = ast_true(v->value);
- } else if (!strcasecmp(v->name, "pulsedial")) {
- pulse = ast_true(v->value);
- } else if (!strcasecmp(v->name, "callreturn")) {
- callreturn = ast_true(v->value);
- } else if (!strcasecmp(v->name, "callwaiting")) {
- callwaiting = ast_true(v->value);
- } else if (!strcasecmp(v->name, "callwaitingcallerid")) {
- callwaitingcallerid = ast_true(v->value);
- } else if (!strcasecmp(v->name, "context")) {
- ast_copy_string(context, v->value, sizeof(context));
- } else if (!strcasecmp(v->name, "language")) {
- ast_copy_string(language, v->value, sizeof(language));
- } else if (!strcasecmp(v->name, "progzone")) {
- ast_copy_string(progzone, v->value, sizeof(progzone));
- } else if (!strcasecmp(v->name, "musiconhold")) {
- ast_copy_string(musicclass, v->value, sizeof(musicclass));
- } else if (!strcasecmp(v->name, "stripmsd")) {
- stripmsd = atoi(v->value);
- } else if (!strcasecmp(v->name, "jitterbuffers")) {
- numbufs = atoi(v->value);
- } else if (!strcasecmp(v->name, "group")) {
- cur_group = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "callgroup")) {
- cur_callergroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "pickupgroup")) {
- cur_pickupgroup = ast_get_group(v->value);
- } else if (!strcasecmp(v->name, "immediate")) {
- immediate = ast_true(v->value);
- } else if (!strcasecmp(v->name, "transfertobusy")) {
- transfertobusy = ast_true(v->value);
- } else if (!strcasecmp(v->name, "rxgain")) {
- if (sscanf(v->value, "%f", &rxgain) != 1) {
- ast_log(LOG_WARNING, "Invalid rxgain: %s\n", v->value);
- }
- } else if (!strcasecmp(v->name, "txgain")) {
- if (sscanf(v->value, "%f", &txgain) != 1) {
- ast_log(LOG_WARNING, "Invalid txgain: %s\n", v->value);
- }
- } else if (!strcasecmp(v->name, "tonezone")) {
- if (sscanf(v->value, "%d", &tonezone) != 1) {
- ast_log(LOG_WARNING, "Invalid tonezone: %s\n", v->value);
- }
- } else if (!strcasecmp(v->name, "callerid")) {
- if (!strcasecmp(v->value, "asreceived")) {
- cid_num[0] = '\0';
- cid_name[0] = '\0';
- } else {
- ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
- }
- } else if (!strcasecmp(v->name, "useincomingcalleridonzaptransfer")) {
- zaptrcallerid = ast_true(v->value);
- } else if (!strcasecmp(v->name, "restrictcid")) {
- restrictcid = ast_true(v->value);
- } else if (!strcasecmp(v->name, "usecallingpres")) {
- use_callingpres = ast_true(v->value);
- } else if (!strcasecmp(v->name, "accountcode")) {
- ast_copy_string(accountcode, v->value, sizeof(accountcode));
- } else if (!strcasecmp(v->name, "amaflags")) {
- y = ast_cdr_amaflags2int(v->value);
- if (y < 0)
- ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
- else
- amaflags = y;
- } else if(!reload){
- if (!strcasecmp(v->name, "signalling")) {
- if (!strcasecmp(v->value, "em")) {
- cur_signalling = SIG_EM;
- } else if (!strcasecmp(v->value, "em_e1")) {
- cur_signalling = SIG_EM_E1;
- } else if (!strcasecmp(v->value, "em_w")) {
- cur_signalling = SIG_EMWINK;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "fxs_ls")) {
- cur_signalling = SIG_FXSLS;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "fxs_gs")) {
- cur_signalling = SIG_FXSGS;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "fxs_ks")) {
- cur_signalling = SIG_FXSKS;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "fxo_ls")) {
- cur_signalling = SIG_FXOLS;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "fxo_gs")) {
- cur_signalling = SIG_FXOGS;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "fxo_ks")) {
- cur_signalling = SIG_FXOKS;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "fxs_rx")) {
- cur_signalling = SIG_FXSKS;
- cur_radio = 1;
- } else if (!strcasecmp(v->value, "fxo_rx")) {
- cur_signalling = SIG_FXOLS;
- cur_radio = 1;
- } else if (!strcasecmp(v->value, "fxs_tx")) {
- cur_signalling = SIG_FXSLS;
- cur_radio = 1;
- } else if (!strcasecmp(v->value, "fxo_tx")) {
- cur_signalling = SIG_FXOGS;
- cur_radio = 1;
- } else if (!strcasecmp(v->value, "em_rx")) {
- cur_signalling = SIG_EM;
- cur_radio = 1;
- } else if (!strcasecmp(v->value, "em_tx")) {
- cur_signalling = SIG_EM;
- cur_radio = 1;
- } else if (!strcasecmp(v->value, "em_rxtx")) {
- cur_signalling = SIG_EM;
- cur_radio = 2;
- } else if (!strcasecmp(v->value, "em_txrx")) {
- cur_signalling = SIG_EM;
- cur_radio = 2;
- } else if (!strcasecmp(v->value, "sf")) {
- cur_signalling = SIG_SF;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "sf_w")) {
- cur_signalling = SIG_SFWINK;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "sf_featd")) {
- cur_signalling = SIG_FEATD;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "sf_featdmf")) {
- cur_signalling = SIG_FEATDMF;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "sf_featb")) {
- cur_signalling = SIG_SF_FEATB;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "sf")) {
- cur_signalling = SIG_SF;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "sf_rx")) {
- cur_signalling = SIG_SF;
- cur_radio = 1;
- } else if (!strcasecmp(v->value, "sf_tx")) {
- cur_signalling = SIG_SF;
- cur_radio = 1;
- } else if (!strcasecmp(v->value, "sf_rxtx")) {
- cur_signalling = SIG_SF;
- cur_radio = 2;
- } else if (!strcasecmp(v->value, "sf_txrx")) {
- cur_signalling = SIG_SF;
- cur_radio = 2;
- } else if (!strcasecmp(v->value, "featd")) {
- cur_signalling = SIG_FEATD;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "featdmf")) {
- cur_signalling = SIG_FEATDMF;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "featdmf_ta")) {
- cur_signalling = SIG_FEATDMF_TA;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "e911")) {
- cur_signalling = SIG_E911;
- cur_radio = 0;
- } else if (!strcasecmp(v->value, "featb")) {
- cur_signalling = SIG_FEATB;
- cur_radio = 0;
-#ifdef ZAPATA_PRI
- } else if (!strcasecmp(v->value, "pri_net")) {
- cur_radio = 0;
- cur_signalling = SIG_PRI;
- pritype = PRI_NETWORK;
- } else if (!strcasecmp(v->value, "pri_cpe")) {
- cur_signalling = SIG_PRI;
- cur_radio = 0;
- pritype = PRI_CPE;
- } else if (!strcasecmp(v->value, "gr303fxoks_net")) {
- cur_signalling = SIG_GR303FXOKS;
- cur_radio = 0;
- pritype = PRI_NETWORK;
- } else if (!strcasecmp(v->value, "gr303fxsks_cpe")) {
- cur_signalling = SIG_GR303FXSKS;
- cur_radio = 0;
- pritype = PRI_CPE;
-#endif
-#ifdef ZAPATA_R2
- } else if (!strcasecmp(v->value, "r2")) {
- cur_signalling = SIG_R2;
- cur_radio = 0;
-#endif
- } else {
- ast_log(LOG_ERROR, "Unknown signalling method '%s'\n", v->value);
- }
-#ifdef ZAPATA_R2
- } else if (!strcasecmp(v->name, "r2country")) {
- r2prot = str2r2prot(v->value);
- if (r2prot < 0) {
- ast_log(LOG_WARNING, "Unknown R2 Country '%s' at line %d.\n", v->value, v->lineno);
- }
-#endif
-#ifdef ZAPATA_PRI
- } else if (!strcasecmp(v->name, "pridialplan")) {
- if (!strcasecmp(v->value, "national")) {
- dialplan = PRI_NATIONAL_ISDN + 1;
- } else if (!strcasecmp(v->value, "unknown")) {
- dialplan = PRI_UNKNOWN + 1;
- } else if (!strcasecmp(v->value, "private")) {
- dialplan = PRI_PRIVATE + 1;
- } else if (!strcasecmp(v->value, "international")) {
- dialplan = PRI_INTERNATIONAL_ISDN + 1;
- } else if (!strcasecmp(v->value, "local")) {
- dialplan = PRI_LOCAL_ISDN + 1;
- } else if (!strcasecmp(v->value, "dynamic")) {
- dialplan = -1;
- } else {
- ast_log(LOG_WARNING, "Unknown PRI dialplan '%s' at line %d.\n", v->value, v->lineno);
- }
- } else if (!strcasecmp(v->name, "prilocaldialplan")) {
- if (!strcasecmp(v->value, "national")) {
- localdialplan = PRI_NATIONAL_ISDN + 1;
- } else if (!strcasecmp(v->value, "unknown")) {
- localdialplan = PRI_UNKNOWN + 1;
- } else if (!strcasecmp(v->value, "private")) {
- localdialplan = PRI_PRIVATE + 1;
- } else if (!strcasecmp(v->value, "international")) {
- localdialplan = PRI_INTERNATIONAL_ISDN + 1;
- } else if (!strcasecmp(v->value, "local")) {
- localdialplan = PRI_LOCAL_ISDN + 1;
- } else if (!strcasecmp(v->value, "dynamic")) {
- localdialplan = -1;
- } else {
- ast_log(LOG_WARNING, "Unknown PRI dialplan '%s' at line %d.\n", v->value, v->lineno);
- }
- } else if (!strcasecmp(v->name, "switchtype")) {
- if (!strcasecmp(v->value, "national"))
- switchtype = PRI_SWITCH_NI2;
- else if (!strcasecmp(v->value, "ni1"))
- switchtype = PRI_SWITCH_NI1;
- else if (!strcasecmp(v->value, "dms100"))
- switchtype = PRI_SWITCH_DMS100;
- else if (!strcasecmp(v->value, "4ess"))
- switchtype = PRI_SWITCH_ATT4ESS;
- else if (!strcasecmp(v->value, "5ess"))
- switchtype = PRI_SWITCH_LUCENT5E;
- else if (!strcasecmp(v->value, "euroisdn"))
- switchtype = PRI_SWITCH_EUROISDN_E1;
- else if (!strcasecmp(v->value, "qsig"))
- switchtype = PRI_SWITCH_QSIG;
- else {
- ast_log(LOG_ERROR, "Unknown switchtype '%s'\n", v->value);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- } else if (!strcasecmp(v->name, "nsf")) {
- if (!strcasecmp(v->value, "sdn"))
- nsf = PRI_NSF_SDN;
- else if (!strcasecmp(v->value, "megacom"))
- nsf = PRI_NSF_MEGACOM;
- else if (!strcasecmp(v->value, "accunet"))
- nsf = PRI_NSF_ACCUNET;
- else if (!strcasecmp(v->value, "none"))
- nsf = PRI_NSF_NONE;
- else {
- ast_log(LOG_WARNING, "Unknown network-specific facility '%s'\n", v->value);
- nsf = PRI_NSF_NONE;
- }
- } else if (!strcasecmp(v->name, "priindication")) {
- if (!strcasecmp(v->value, "outofband"))
- priindication_oob = 1;
- else if (!strcasecmp(v->value, "inband"))
- priindication_oob = 0;
- else
- ast_log(LOG_WARNING, "'%s' is not a valid pri indication value, should be 'inband' or 'outofband' at line %d\n",
- v->value, v->lineno);
- } else if (!strcasecmp(v->name, "priexclusive")) {
- cur_priexclusive = ast_true(v->value);
- } else if (!strcasecmp(v->name, "internationalprefix")) {
- ast_copy_string(internationalprefix, v->value, sizeof(internationalprefix));
- } else if (!strcasecmp(v->name, "nationalprefix")) {
- ast_copy_string(nationalprefix, v->value, sizeof(nationalprefix));
- } else if (!strcasecmp(v->name, "localprefix")) {
- ast_copy_string(localprefix, v->value, sizeof(localprefix));
- } else if (!strcasecmp(v->name, "privateprefix")) {
- ast_copy_string(privateprefix, v->value, sizeof(privateprefix));
- } else if (!strcasecmp(v->name, "unknownprefix")) {
- ast_copy_string(unknownprefix, v->value, sizeof(unknownprefix));
- } else if (!strcasecmp(v->name, "resetinterval")) {
- if (!strcasecmp(v->value, "never"))
- resetinterval = -1;
- else if( atoi(v->value) >= 60 )
- resetinterval = atoi(v->value);
- else
- ast_log(LOG_WARNING, "'%s' is not a valid reset interval, should be >= 60 seconds or 'never' at line %d\n",
- v->value, v->lineno);
- } else if (!strcasecmp(v->name, "minunused")) {
- minunused = atoi(v->value);
- } else if (!strcasecmp(v->name, "idleext")) {
- ast_copy_string(idleext, v->value, sizeof(idleext));
- } else if (!strcasecmp(v->name, "idledial")) {
- ast_copy_string(idledial, v->value, sizeof(idledial));
- } else if (!strcasecmp(v->name, "overlapdial")) {
- overlapdial = ast_true(v->value);
- } else if (!strcasecmp(v->name, "pritimer")) {
-#ifdef PRI_GETSET_TIMERS
- char *timerc;
- int timer, timeridx;
- c = v->value;
- timerc = strsep(&c, ",");
- if (timerc) {
- timer = atoi(c);
- if (!timer)
- ast_log(LOG_WARNING, "'%s' is not a valid value for an ISDN timer\n", timerc);
- else {
- if ((timeridx = pri_timer2idx(timerc)) >= 0)
- pritimers[timeridx] = timer;
- else
- ast_log(LOG_WARNING, "'%s' is not a valid ISDN timer\n", timerc);
- }
- } else
- ast_log(LOG_WARNING, "'%s' is not a valid ISDN timer configuration string\n", v->value);
-
- } else if (!strcasecmp(v->name, "facilityenable")) {
- facilityenable = ast_true(v->value);
-#endif /* PRI_GETSET_TIMERS */
-#endif /* ZAPATA_PRI */
- } else if (!strcasecmp(v->name, "cadence")) {
- /* setup to scan our argument */
- int element_count, c[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- int i;
- struct zt_ring_cadence new_cadence;
- int cid_location = -1;
- int firstcadencepos = 0;
- char original_args[80];
- int cadence_is_ok = 1;
-
- ast_copy_string(original_args, v->value, sizeof(original_args));
- /* 16 cadences allowed (8 pairs) */
- element_count = sscanf(v->value, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11], &c[12], &c[13], &c[14], &c[15]);
-
- /* Cadence must be even (on/off) */
- if (element_count % 2 == 1) {
- ast_log(LOG_ERROR, "Must be a silence duration for each ring duration: %s\n",original_args);
- cadence_is_ok = 0;
- }
-
- /* Ring cadences cannot be negative */
- for (i=0;i<element_count;i++) {
- if (c[i] == 0) {
- ast_log(LOG_ERROR, "Ring or silence duration cannot be zero: %s\n", original_args);
- cadence_is_ok = 0;
- break;
- } else if (c[i] < 0) {
- if (i % 2 == 1) {
- /* Silence duration, negative possibly okay */
- if (cid_location == -1) {
- cid_location = i;
- c[i] *= -1;
- } else {
- ast_log(LOG_ERROR, "CID location specified twice: %s\n",original_args);
- cadence_is_ok = 0;
- break;
- }
- } else {
- if (firstcadencepos == 0) {
- firstcadencepos = i; /* only recorded to avoid duplicate specification */
- /* duration will be passed negative to the zaptel driver */
- } else {
- ast_log(LOG_ERROR, "First cadence position specified twice: %s\n",original_args);
- cadence_is_ok = 0;
- break;
- }
- }
- }
- }
-
- /* Substitute our scanned cadence */
- for (i=0;i<16;i++) {
- new_cadence.ringcadence[i] = c[i];
- }
-
- if (cadence_is_ok) {
- /* ---we scanned it without getting annoyed; now some sanity checks--- */
- if (element_count < 2) {
- ast_log(LOG_ERROR, "Minimum cadence is ring,pause: %s\n", original_args);
- } else {
- if (cid_location == -1) {
- /* user didn't say; default to first pause */
- cid_location = 1;
- } else {
- /* convert element_index to cidrings value */
- cid_location = (cid_location + 1) / 2;
- }
- /* ---we like their cadence; try to install it--- */
- if (!user_has_defined_cadences++)
- /* this is the first user-defined cadence; clear the default user cadences */
- num_cadence = 0;
- if ((num_cadence+1) >= NUM_CADENCE_MAX)
- ast_log(LOG_ERROR, "Already %d cadences; can't add another: %s\n", NUM_CADENCE_MAX, original_args);
- else {
- cadences[num_cadence] = new_cadence;
- cidrings[num_cadence++] = cid_location;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "cadence 'r%d' added: %s\n",num_cadence,original_args);
- }
- }
- }
- } else if (!strcasecmp(v->name, "ringtimeout")) {
- ringt_base = (atoi(v->value) * 8) / READ_SIZE;
- } else if (!strcasecmp(v->name, "prewink")) {
- cur_prewink = atoi(v->value);
- } else if (!strcasecmp(v->name, "preflash")) {
- cur_preflash = atoi(v->value);
- } else if (!strcasecmp(v->name, "wink")) {
- cur_wink = atoi(v->value);
- } else if (!strcasecmp(v->name, "flash")) {
- cur_flash = atoi(v->value);
- } else if (!strcasecmp(v->name, "start")) {
- cur_start = atoi(v->value);
- } else if (!strcasecmp(v->name, "rxwink")) {
- cur_rxwink = atoi(v->value);
- } else if (!strcasecmp(v->name, "rxflash")) {
- cur_rxflash = atoi(v->value);
- } else if (!strcasecmp(v->name, "debounce")) {
- cur_debounce = atoi(v->value);
- } else if (!strcasecmp(v->name, "toneduration")) {
- int toneduration;
- int ctlfd;
- int res;
- struct zt_dialparams dps;
-
- ctlfd = open("/dev/zap/ctl", O_RDWR);
- if (ctlfd == -1) {
- ast_log(LOG_ERROR, "Unable to open /dev/zap/ctl to set toneduration\n");
- return -1;
- }
-
- toneduration = atoi(v->value);
- if (toneduration > -1) {
- dps.dtmf_tonelen = dps.mfv1_tonelen = toneduration;
- res = ioctl(ctlfd, ZT_SET_DIALPARAMS, &dps);
- if (res < 0) {
- ast_log(LOG_ERROR, "Invalid tone duration: %d ms\n", toneduration);
- return -1;
- }
- }
- close(ctlfd);
- } else if (!strcasecmp(v->name, "polarityonanswerdelay")) {
- polarityonanswerdelay = atoi(v->value);
- } else if (!strcasecmp(v->name, "answeronpolarityswitch")) {
- answeronpolarityswitch = ast_true(v->value);
- } else if (!strcasecmp(v->name, "hanguponpolarityswitch")) {
- hanguponpolarityswitch = ast_true(v->value);
- } else if (!strcasecmp(v->name, "sendcalleridafter")) {
- sendcalleridafter = atoi(v->value);
- } else if (!strcasecmp(v->name, "defaultcic")) {
- ast_copy_string(defaultcic, v->value, sizeof(defaultcic));
- } else if (!strcasecmp(v->name, "defaultozz")) {
- ast_copy_string(defaultozz, v->value, sizeof(defaultozz));
- }
- } else
- ast_log(LOG_WARNING, "Ignoring %s\n", v->name);
- v = v->next;
- }
- if (!found_pseudo && reload == 0) {
-
- /* Make sure pseudo isn't a member of any groups if
- we're automatically making it. */
- cur_group = 0;
- cur_callergroup = 0;
- cur_pickupgroup = 0;
-
- tmp = mkintf(CHAN_PSEUDO, cur_signalling, cur_radio, NULL, reload);
-
- if (tmp) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Automatically generated pseudo channel\n");
- } else {
- ast_log(LOG_WARNING, "Unable to register pseudo channel!\n");
- }
- }
- ast_mutex_unlock(&iflock);
- ast_config_destroy(cfg);
-#ifdef ZAPATA_PRI
- if (!reload) {
- for (x=0;x<NUM_SPANS;x++) {
- if (pris[x].pvts[0]) {
- if (start_pri(pris + x)) {
- ast_log(LOG_ERROR, "Unable to start D-channel on span %d\n", x + 1);
- return -1;
- } else if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Starting D-Channel on span %d\n", x + 1);
- }
- }
- }
-#endif
- /* And start the monitor for the first time */
- restart_monitor();
- return 0;
-}
-
-int load_module(void)
-{
- int res;
-
-#ifdef ZAPATA_PRI
- int y,i;
- memset(pris, 0, sizeof(pris));
- for (y=0;y<NUM_SPANS;y++) {
- ast_mutex_init(&pris[y].lock);
- pris[y].offset = -1;
- pris[y].master = AST_PTHREADT_NULL;
- for (i=0;i<NUM_DCHANS;i++)
- pris[y].fds[i] = -1;
- }
- pri_set_error(zt_pri_error);
- pri_set_message(zt_pri_message);
-#endif
- res = setup_zap(0);
- /* Make sure we can register our Zap channel type */
- if(res) {
- return -1;
- }
- if (ast_channel_register(&zap_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- __unload_module();
- return -1;
- }
-#ifdef ZAPATA_PRI
- ast_cli_register_multiple(zap_pri_cli, sizeof(zap_pri_cli) / sizeof(zap_pri_cli[0]));
-#endif
-#ifdef ZAPATA_R2
- ast_cli_register_multiple(zap_r2_cli, sizeof(zap_r2_cli) / sizeof(zap_r2_cli[0]));
-#endif
- ast_cli_register_multiple(zap_cli, sizeof(zap_cli) / sizeof(zap_cli[0]));
-
- memset(round_robin, 0, sizeof(round_robin));
- ast_manager_register( "ZapTransfer", 0, action_transfer, "Transfer Zap Channel" );
- ast_manager_register( "ZapHangup", 0, action_transferhangup, "Hangup Zap Channel" );
- ast_manager_register( "ZapDialOffhook", 0, action_zapdialoffhook, "Dial over Zap channel while offhook" );
- ast_manager_register( "ZapDNDon", 0, action_zapdndon, "Toggle Zap channel Do Not Disturb status ON" );
- ast_manager_register( "ZapDNDoff", 0, action_zapdndoff, "Toggle Zap channel Do Not Disturb status OFF" );
- ast_manager_register("ZapShowChannels", 0, action_zapshowchannels, "Show status zapata channels");
-
- return res;
-}
-
-static int zt_sendtext(struct ast_channel *c, const char *text)
-{
-#define END_SILENCE_LEN 400
-#define HEADER_MS 50
-#define TRAILER_MS 5
-#define HEADER_LEN ((HEADER_MS + TRAILER_MS) * 8)
-#define ASCII_BYTES_PER_CHAR 80
-
- unsigned char *buf,*mybuf;
- struct zt_pvt *p = c->tech_pvt;
- struct pollfd fds[1];
- int size,res,fd,len,x;
- int bytes=0;
- /* Initial carrier (imaginary) */
- float cr = 1.0;
- float ci = 0.0;
- float scont = 0.0;
- int index;
-
- index = zt_get_index(c, p, 0);
- if (index < 0) {
- ast_log(LOG_WARNING, "Huh? I don't exist?\n");
- return -1;
- }
- if (!text[0]) return(0); /* if nothing to send, dont */
- if ((!p->tdd) && (!p->mate)) return(0); /* if not in TDD mode, just return */
- if (p->mate)
- buf = malloc(((strlen(text) + 1) * ASCII_BYTES_PER_CHAR) + END_SILENCE_LEN + HEADER_LEN);
- else
- buf = malloc(((strlen(text) + 1) * TDD_BYTES_PER_CHAR) + END_SILENCE_LEN);
- if (!buf) {
- ast_log(LOG_ERROR, "MALLOC FAILED\n");
- return -1;
- }
- mybuf = buf;
- if (p->mate) {
- int codec = AST_LAW(p);
- for (x=0;x<HEADER_MS;x++) { /* 50 ms of Mark */
- PUT_CLID_MARKMS;
- }
- /* Put actual message */
- for (x=0;text[x];x++) {
- PUT_CLID(text[x]);
- }
- for (x=0;x<TRAILER_MS;x++) { /* 5 ms of Mark */
- PUT_CLID_MARKMS;
- }
- len = bytes;
- buf = mybuf;
- }
- else {
- len = tdd_generate(p->tdd,buf,text);
- if (len < 1) {
- ast_log(LOG_ERROR, "TDD generate (len %d) failed!!\n",(int)strlen(text));
- free(mybuf);
- return -1;
- }
- }
- memset(buf + len,0x7f,END_SILENCE_LEN);
- len += END_SILENCE_LEN;
- fd = p->subs[index].zfd;
- while(len) {
- if (ast_check_hangup(c)) {
- free(mybuf);
- return -1;
- }
- size = len;
- if (size > READ_SIZE)
- size = READ_SIZE;
- fds[0].fd = fd;
- fds[0].events = POLLOUT | POLLPRI;
- fds[0].revents = 0;
- res = poll(fds, 1, -1);
- if (!res) {
- ast_log(LOG_DEBUG, "poll (for write) ret. 0 on channel %d\n", p->channel);
- continue;
- }
- /* if got exception */
- if (fds[0].revents & POLLPRI) return -1;
- if (!(fds[0].revents & POLLOUT)) {
- ast_log(LOG_DEBUG, "write fd not ready on channel %d\n", p->channel);
- continue;
- }
- res = write(fd, buf, size);
- if (res != size) {
- if (res == -1) {
- free(mybuf);
- return -1;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Write returned %d (%s) on channel %d\n", res, strerror(errno), p->channel);
- break;
- }
- len -= size;
- buf += size;
- }
- free(mybuf);
- return(0);
-}
-
-
-int reload(void)
-{
- int res = 0;
-
- res = setup_zap(1);
- if (res) {
- ast_log(LOG_WARNING, "Reload of chan_zap.so is unsuccessful!\n");
- return -1;
- }
- return 0;
-}
-
-int usecount()
-{
- return usecnt;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/channels/gentone-ulaw.c b/1.2-netsec/channels/gentone-ulaw.c
deleted file mode 100644
index b290d76c7..000000000
--- a/1.2-netsec/channels/gentone-ulaw.c
+++ /dev/null
@@ -1,157 +0,0 @@
-/* Generate a header file for a particular
- single or double frequency */
-
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#define CLIP 32635
-#define BIAS 0x84
-static float loudness=16384.0;
-
-static int calc_samples(int freq)
-{
- int x, samples;
- /* Calculate the number of samples at 8000hz sampling
- we need to have this wave form */
- samples = 8000;
- /* Take out common 2's up to six times */
- for (x=0;x<6;x++)
- if (!(freq % 2)) {
- freq /= 2;
- samples /= 2;
- }
- /* Take out common 5's (up to three times */
- for (x=0;x<3;x++)
- if (!(freq % 5)) {
- freq /= 5;
- samples /=5;
- }
- /* No more common factors. */
- return samples;
-}
-
-/*
-** This routine converts from linear to ulaw
-**
-** Craig Reese: IDA/Supercomputing Research Center
-** Joe Campbell: Department of Defense
-** 29 September 1989
-**
-** References:
-** 1) CCITT Recommendation G.711 (very difficult to follow)
-** 2) "A New Digital Technique for Implementation of Any
-** Continuous PCM Companding Law," Villeret, Michel,
-** et al. 1973 IEEE Int. Conf. on Communications, Vol 1,
-** 1973, pg. 11.12-11.17
-** 3) MIL-STD-188-113,"Interoperability and Performance Standards
-** for Analog-to_Digital Conversion Techniques,"
-** 17 February 1987
-**
-** Input: Signed 16 bit linear sample
-** Output: 8 bit ulaw sample
-*/
-
-#define ZEROTRAP /* turn on the trap as per the MIL-STD */
-#define BIAS 0x84 /* define the add-in bias for 16 bit samples */
-#define CLIP 32635
-
-static unsigned char linear2ulaw(short sample) {
-static int exp_lut[256] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
- 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
- int sign, exponent, mantissa;
- unsigned char ulawbyte;
-
- /* Get the sample into sign-magnitude. */
- sign = (sample >> 8) & 0x80; /* set aside the sign */
- if (sign != 0) sample = -sample; /* get magnitude */
- if (sample > CLIP) sample = CLIP; /* clip the magnitude */
-
- /* Convert from 16 bit linear to ulaw. */
- sample = sample + BIAS;
- exponent = exp_lut[(sample >> 7) & 0xFF];
- mantissa = (sample >> (exponent + 3)) & 0x0F;
- ulawbyte = ~(sign | (exponent << 4) | mantissa);
-#ifdef ZEROTRAP
- if (ulawbyte == 0) ulawbyte = 0x02; /* optional CCITT trap */
-#endif
-
- return(ulawbyte);
-}
-
-int main(int argc, char *argv[])
-{
- FILE *f;
- int freq1, freq2;
- float wlen1, wlen2;
- float val;
- int x, samples1, samples2, samples=0;
- char fn[256];
- if (argc < 3) {
- fprintf(stderr, "Usage: gensound <name> <freq1> [freq2]\n");
- exit(1);
- }
- freq1 = atoi(argv[2]);
- if (argc > 3)
- freq2 = atoi(argv[3]);
- else
- freq2 = 0;
- wlen1 = 8000.0/(float)freq1;
- samples1 = calc_samples(freq1);
- printf("Wavelength 1 (in samples): %10.5f\n", wlen1);
- printf("Minimum samples (1): %d (%f.3 wavelengths)\n", samples1, samples1 / wlen1);
- if (freq2) {
- wlen2 = 8000.0/(float)freq2;
- samples2 = calc_samples(freq2);
- printf("Wavelength 1 (in samples): %10.5f\n", wlen2);
- printf("Minimum samples (1): %d (%f.3 wavelengths)\n", samples2, samples2 / wlen2);
- }
- samples = samples1;
- if (freq2) {
- while(samples % samples2)
- samples += samples1;
- }
- printf("Need %d samples\n", samples);
- snprintf(fn, sizeof(fn), "%s.h", argv[1]);
- if ((f = fopen(fn, "w"))) {
- if (freq2)
- fprintf(f, "/* %s: Generated from frequencies %d and %d \n"
- " by gentone. %d samples */\n", fn, freq1, freq2, samples);
- else
- fprintf(f, "/* %s: Generated from frequency %d\n"
- " by gentone. %d samples */\n", fn, freq1, samples);
- fprintf(f, "static unsigned char %s[%d] = {\n\t", argv[1], samples);
- for (x=0;x<samples;x++) {
- val = loudness * sin((freq1 * 2.0 * M_PI * x)/8000.0);
- if (freq2)
- val += loudness * sin((freq2 * 2.0 * M_PI * x)/8000.0);
- fprintf(f, "%3d, ", (int) linear2ulaw(val));
- if (!((x+1) % 8))
- fprintf(f, "\n\t");
- }
- if (x % 15)
- fprintf(f, "\n");
- fprintf(f, "};\n");
- fclose(f);
- printf("Wrote %s\n", fn);
- } else {
- fprintf(stderr, "Unable to open %s for writing\n", fn);
- return 1;
- }
- return 0;
-}
diff --git a/1.2-netsec/channels/gentone.c b/1.2-netsec/channels/gentone.c
deleted file mode 100644
index 29bd88e91..000000000
--- a/1.2-netsec/channels/gentone.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/* Generate a header file for a particular
- single or double frequency */
-
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#define CLIP 32635
-#define BIAS 0x84
-static float loudness=16384.0;
-
-static int calc_samples(int freq)
-{
- int x, samples;
- /* Calculate the number of samples at 8000hz sampling
- we need to have this wave form */
- samples = 8000;
- /* Take out common 2's up to six times */
- for (x=0;x<6;x++)
- if (!(freq % 2)) {
- freq /= 2;
- samples /= 2;
- }
- /* Take out common 5's (up to three times */
- for (x=0;x<3;x++)
- if (!(freq % 5)) {
- freq /= 5;
- samples /=5;
- }
- /* No more common factors. */
- return samples;
-}
-
-int main(int argc, char *argv[])
-{
- FILE *f;
- int freq1, freq2;
- float wlen1, wlen2;
- float val;
- int x, samples1, samples2=0, samples=0;
- char fn[256];
- if (argc < 3) {
- fprintf(stderr, "Usage: gensound <name> <freq1> [freq2]\n");
- exit(1);
- }
- freq1 = atoi(argv[2]);
- if (argc > 3)
- freq2 = atoi(argv[3]);
- else
- freq2 = 0;
- wlen1 = 8000.0/(float)freq1;
- samples1 = calc_samples(freq1);
- printf("Wavelength 1 (in samples): %10.5f\n", wlen1);
- printf("Minimum samples (1): %d (%f.3 wavelengths)\n", samples1, samples1 / wlen1);
- if (freq2) {
- wlen2 = 8000.0/(float)freq2;
- samples2 = calc_samples(freq2);
- printf("Wavelength 1 (in samples): %10.5f\n", wlen2);
- printf("Minimum samples (1): %d (%f.3 wavelengths)\n", samples2, samples2 / wlen2);
- }
- samples = samples1;
- if (freq2) {
- while(samples % samples2)
- samples += samples1;
- }
- printf("Need %d samples\n", samples);
- snprintf(fn, sizeof(fn), "%s.h", argv[1]);
- if ((f = fopen(fn, "w"))) {
- if (freq2)
- fprintf(f, "/* %s: Generated from frequencies %d and %d \n"
- " by gentone. %d samples */\n", fn, freq1, freq2, samples);
- else
- fprintf(f, "/* %s: Generated from frequency %d\n"
- " by gentone. %d samples */\n", fn, freq1, samples);
- fprintf(f, "static short %s[%d] = {\n\t", argv[1], samples);
- for (x=0;x<samples;x++) {
- val = loudness * sin((freq1 * 2.0 * M_PI * x)/8000.0);
- if (freq2)
- val += loudness * sin((freq2 * 2.0 * M_PI * x)/8000.0);
- fprintf(f, "%5d, ", (int)val);
- if (!((x+1) % 8))
- fprintf(f, "\n\t");
- }
- if (x % 15)
- fprintf(f, "\n");
- fprintf(f, "};\n");
- fclose(f);
- printf("Wrote %s\n", fn);
- } else {
- fprintf(stderr, "Unable to open %s for writing\n", fn);
- return 1;
- }
- return 0;
-}
diff --git a/1.2-netsec/channels/h323/ChangeLog b/1.2-netsec/channels/h323/ChangeLog
deleted file mode 100644
index ddbf08193..000000000
--- a/1.2-netsec/channels/h323/ChangeLog
+++ /dev/null
@@ -1,43 +0,0 @@
-Build
- -- Hold lock when creating new H.323 channel to sync the audio channels
- -- Decrement usage counter when appropriate
- -- Actually unregister everything in unload_module
- -- Add IP based authentication using 'host'in type=user's
-0.1.0
- -- Intergration into the mainline Asterisk codebase
- -- Remove reduandant debug info
- -- Add Caller*id support
- -- Inband DTMF
- -- Retool port usage (to avoid possible seg fault condition)
-0.0.6
- -- Configurable support for user-input (DTMF)
- -- Reworked Gatekeeper support
- -- Native bridging (but is still broken, help!)
- -- Locally implement a non-broken G.723.1 Capability
- -- Utilize the cleaner RTP method implemented by Mark
- -- AllowGkRouted, thanks to Panny from http://hotlinks.co.uk
- -- Clened up inbound call flow
- -- Prefix, E.164 and Gateway support
- -- Multi-homed support
- -- Killed more seg's
-0.0.5
- -- Added H.323 Alias support
- -- Clened up inbound call flow
- -- Fixed RTP port logic
- -- Stomped on possible seg fault conditions thanks to Iain Stevenson
-0.0.4
- -- Fixed one-way audio on inbound calls. Found
- race condition in monitor thread.
-
-0.0.3
- -- Changed name to chan_h323
- -- Also renamed file names to futher avoid confusion
-
-0.0.2
- -- First public offering
- -- removed most hardcoded values
- -- lots of changes to alias/exension operation
-
-0.0.1
- -- initial build, lots of hardcoded crap
- -- Proof of concept for External RTP
diff --git a/1.2-netsec/channels/h323/INSTALL.openh323 b/1.2-netsec/channels/h323/INSTALL.openh323
deleted file mode 100644
index f46c37905..000000000
--- a/1.2-netsec/channels/h323/INSTALL.openh323
+++ /dev/null
@@ -1,18 +0,0 @@
-To build Open H.323 see:
-
-http://www.openh323.org/build.html#unix
-
-You only need to do 'make opt'. Anything else you will be simply waisting time and HD space.
-Also, you will notice they never tell you to 'make install' so don't do it.
-
-
-On FreeBSD, the Makefiles are configured to
-locate the compiled openh323 port, if it has
-been built. Here is one way to build
-openh323 and ptlib on such that the Makefiles
-find it:
- # cd /usr/ports/net/openh323
- # make
-It is not necessary to install the port. The
-asterisk makefiles do not use any files
-installed by the port.
diff --git a/1.2-netsec/channels/h323/Makefile b/1.2-netsec/channels/h323/Makefile
deleted file mode 100644
index 0e9266164..000000000
--- a/1.2-netsec/channels/h323/Makefile
+++ /dev/null
@@ -1,41 +0,0 @@
-#
-# Makefile
-#
-# Make file for OpenH323 support layer
-#
-
-# Verify those options with main Makefile
-STDCCFLAGS += -DNDEBUG
-STDCCFLAGS += $(shell grep ^DEBUG_THREADS ../../Makefile | sed -e "s/^DEBUG_THREADS[ ]*=//" -e "s/\([^\#]*\)\#.*/\1/")
-STDCCFLAGS += -I../../include
-STDCCFLAGS += -Wmissing-prototypes
-STDCCFLAGS += -fPIC
-#OPTCCFLAGS +=
-CFLAGS += -pipe
-TARGET += libchanh323.a
-TARGET += Makefile.ast
-SOURCES = ast_h323.cxx
-OBJDIR = .
-
-ifndef OPENH323DIR
-OPENH323DIR=$(HOME)/openh323
-endif
-
-include $(OPENH323DIR)/openh323u.mak
-
-$(SOURCES):: $(SOURCES:.cxx=.cpp)
- ln -f $< $@
-
-$(SOURCES):: Makefile ../../Makefile
- touch $(SOURCES)
-
-libchanh323.a: $(OBJS)
- ar crv $@ $(OBJS)
-
-Makefile.ast: FORCE
- @echo H323CFLAGS = $(STDCCFLAGS) $(OPTCCFLAGS) $(CFLAGS) >$@.tmp
- @echo H323LDFLAGS = $(CFLAGS) $(LDFLAGS) >>$@.tmp
- @echo H323LDLIBS = $(LDLIBS) $(ENDLDLIBS) $(ENDLDFLAGS) >>$@.tmp
- @if [ -r $@ ] && cmp -s $@ $@.tmp; then rm -f $@.tmp; else mv -f $@.tmp $@; fi
-
-FORCE:
diff --git a/1.2-netsec/channels/h323/README b/1.2-netsec/channels/h323/README
deleted file mode 100644
index ff94bc42e..000000000
--- a/1.2-netsec/channels/h323/README
+++ /dev/null
@@ -1,142 +0,0 @@
- Open H.323 Channel Driver for Asterisk
- By Jeremy McNamara
- For The NuFone Network
-
- First public release on November 10th, 2002
-
- Dependancies: openssl-0.9.6b+
- openssl-devel-0.9.6b+
- expat-1.95+
- expat-dev-1.95+
-
-Tested with Open H.323 version v1.17.1, PWLib v1.9.0 and GCC v3.2.2. Usage of any
-other versions is not supported.
-
-NOTICE: Whatever you do, DO NOT USE distrubution specific installs
-of Open H.323 and PWLib. In fact, you should check to make sure
-your distro did not install them for you without your knowledge.
-
-
-To compile this code
---------------------
-Once PWLib and Open H.323 have been compiled per their specific build
-instructions, issue a make in the asterisk/channels/h323 directory with
-argument used to build PWLib and OpenH323 (for example, make opt), then go
-back to the Asterisk source top level directory and issue a make install.
-
-
-The most common compile error
-----------------------------
-If you receive ANYTHING that says 'undefined symbol' you are experiencing
-typical version skew. For example:
-
-libh323_linux_x86_r.so.1: undefined symbol: GetNumberValueAt__C14PAbstractArrayi
-
-You need to search and destroy every version of libh323 and libpt then
-completely recompile everything
-
-Example commands to make sure everything gets cleaned and then
-rebult in proper order:
-
-cd /path/to/pwlib
-./configure
-make clean opt
-cd /path/to/openh323
-./configure
-make clean opt
-cd /path/to/asterisk/channels/h323
-make opt
-cd /path/to/asterisk
-make install
-
-
-Most common run-time error
--------------------------
-libpt_linux_x86_r.so.1: cannot open shared object file: No such
-file or directory
-
-You have not set the LD_LIBRARY_PATH environment variable.
-
-Example environment for sh/bash:
-
-PWLIBDIR=$HOME/pwlib
-export PWLIBDIR
-OPENH323DIR=$HOME/openh323
-export OPENH323DIR
-LD_LIBRARY_PATH=$PWLIBDIR/lib:$OPENH323DIR/lib
-export LD_LIBRARY_PATH
-
-We recomend puting the above directives into your /etc/profile so
-you do not have to remember to export those values every time you
-want to recompile. Make sure to logout and log back in, so your
-envrionment can pick up the new variables.
-
-
-Upgrading Asterisk
------------------
-After you cvs update (or make update) Asterisk you have to go into
-asterisk/channels/h323 and issue a make clean all, before compiling the
-rest of asterisk. Doing this process every time you upgrade Asterisk
-will ensure a sane build.
-
-
-Dialing an H.323 channel
-------------------------
-Without a gatekeeper:
-exten => _1NXXNXXXXXX,1,Dial,H323/${EXTEN}@peer
-or
-exten => _1NXXNXXXXXX,1,Dial,H323/${EXTEN}@ip.or.hostname
-
-'peer' is defined in h323.conf as:
-
-[peer]
-type=peer
-host=1.2.3.4
-disallow=all
-allow=ulaw
-
-Using a gatekeeper:
-exten => _1NXXNXXXXXX,1,Dial,H323/${EXTEN}
-
-When using a gatekeeper you cannot utilize the type=peer features,
-since the H.323 spec states that when a Gatekeeper is part of an H.323 network,
-the Gatekeeper shall be used for all communication.
-
-
-Developer Contact
-----------------
-If you have trouble contact 'JerJer' in #Asterisk on
-irc.freenode.net and/or send reasonable debug information to support@nufone.net.
-
-If are lucky enough to segfault this code please run a
-backtrace and send the gory details. Segmentation faults are not
-tolerated, no matter what Distro you run (even debian)!
-
-a simple bt example:
-
-# /usr/sbin/asterisk -vvvgc
-...
-[chan_h323.so]
-Segmentation Fault (core dumped)
-
-# ls core.*
-core.1976
-
-# gdb /usr/sbin/asterisk core.1976
-...lots of useless garbage here...
-(gdb) bt
-
-Send whatever shows up right after the 'bt'
-
-Also, a full debug screen output is almost needed. Make sure you are
-in the full console mode (-c) and turn on 'h.323 debug' or worst case
-senerio 'h.323 trace 4'. A nice way to capture debug info is with
-script (man script).
-
-If you are motivated to update/fix this code please submit a
-disclaimer along with the patch to the Asterisk bug
-tracker: http://bugs.digium.com/
-
-
-Jeremy McNamara
-The NuFone Network
diff --git a/1.2-netsec/channels/h323/TODO b/1.2-netsec/channels/h323/TODO
deleted file mode 100644
index b72a9f1d1..000000000
--- a/1.2-netsec/channels/h323/TODO
+++ /dev/null
@@ -1,14 +0,0 @@
-The NuFone Network's Open H.323 Channel Driver for Asterisk
-
- TODO:
-
- - Fix Gatekeeper re-registration seg (HELP)
-
- - Track down why calls to invalid extensions always
- get sent to 's' in context 'default'
-
- - H.323 Native Bridging
-
- - Gatekeeping support (started)
-
- - Acutally implement the options for broken H.323 stacks
diff --git a/1.2-netsec/channels/h323/ast_h323.cpp b/1.2-netsec/channels/h323/ast_h323.cpp
deleted file mode 100644
index bb4145088..000000000
--- a/1.2-netsec/channels/h323/ast_h323.cpp
+++ /dev/null
@@ -1,1532 +0,0 @@
-#define _GNU_SOURCE
-/*
- * ast_h323.cpp
- *
- * OpenH323 Channel Driver for ASTERISK PBX.
- * By Jeremy McNamara
- * For The NuFone Network
- *
- * chan_h323 has been derived from code created by
- * Michael Manousos and Mark Spencer
- *
- * This file is part of the chan_h323 driver for Asterisk
- *
- * chan_h323 is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * chan_h323 is distributed WITHOUT ANY WARRANTY; without even
- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Version Info: $Id$
- */
-#include <arpa/inet.h>
-
-#include <list>
-#include <string>
-#include <algorithm>
-
-#include <ptlib.h>
-#include <h323.h>
-#include <h323pdu.h>
-#include <mediafmt.h>
-#include <lid.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#ifdef __cplusplus
-}
-#endif
-
-#include "chan_h323.h"
-#include "ast_h323.h"
-
-/* PWlib Required Components */
-#define MAJOR_VERSION 1
-#define MINOR_VERSION 0
-#define BUILD_TYPE ReleaseCode
-#define BUILD_NUMBER 0
-
-/** Counter for the number of connections */
-int channelsOpen;
-
-/* DTMF Mode */
-int mode = H323_DTMF_RFC2833;
-
-/**
- * We assume that only one endPoint should exist.
- * The application cannot run the h323_end_point_create() more than once
- * FIXME: Singleton this, for safety
- */
-MyH323EndPoint *endPoint = NULL;
-
-/** PWLib entry point */
-MyProcess *localProcess = NULL;
-
-class PAsteriskLog : public PObject, public iostream {
- PCLASSINFO(PAsteriskLog, PObject);
-
- public:
- PAsteriskLog() : iostream(cout.rdbuf()) { init(&buffer); }
- ~PAsteriskLog() { flush(); }
-
- private:
- PAsteriskLog(const PAsteriskLog &) : iostream(cout.rdbuf()) { }
- PAsteriskLog & operator=(const PAsteriskLog &) { return *this; }
-
- class Buffer : public streambuf {
- public:
- virtual int overflow(int=EOF);
- virtual int underflow();
- virtual int sync();
- PString string;
- } buffer;
- friend class Buffer;
-};
-
-static PAsteriskLog *logstream = NULL;
-
-int PAsteriskLog::Buffer::overflow(int c)
-{
- if (pptr() >= epptr()) {
- int ppos = pptr() - pbase();
- char *newptr = string.GetPointer(string.GetSize() + 2000);
- setp(newptr, newptr + string.GetSize() - 1);
- pbump(ppos);
- }
- if (c != EOF) {
- *pptr() = (char)c;
- pbump(1);
- }
- return 0;
-}
-
-int PAsteriskLog::Buffer::underflow()
-{
- return EOF;
-}
-
-int PAsteriskLog::Buffer::sync()
-{
- char *str = strdup(string);
- char *s, *s1;
- char c;
-
- /* Pass each line with different ast_verbose() call */
- for (s = str; s && *s; s = s1) {
- s1 = strchr(s, '\n');
- if (!s1)
- s1 = s + strlen(s);
- else
- s1++;
- c = *s1;
- *s1 = '\0';
- ast_verbose("%s", s);
- *s1 = c;
- }
- free(str);
-
- string = PString();
- char *base = string.GetPointer(2000);
- setp(base, base + string.GetSize() - 1);
- return 0;
-}
-
-#define cout (*logstream)
-
-MyProcess::MyProcess(): PProcess("The NuFone Network's", "H.323 Channel Driver for Asterisk",
- MAJOR_VERSION, MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER)
-{
- /* Fix missed one in PWLib */
- PX_firstTimeStart = FALSE;
- Resume();
-}
-
-void MyProcess::Main()
-{
- cout << " == Creating H.323 Endpoint" << endl;
- endPoint = new MyH323EndPoint();
- /* Due to a bug in the H.323 recomendation/stack we should request a sane
- amount of bandwidth from the GK - this function is ignored if not using a GK
- We are requesting 128 (64k in each direction), which is the worst case codec. */
- endPoint->SetInitialBandwidth(1280);
-
- PTrace::Initialise(0, NULL, PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);
- PTrace::SetStream(logstream);
-}
-
-void PAssertFunc(const char *msg)
-{
- ast_log(LOG_ERROR, "%s\n", msg);
- /* XXX: Probably we need to crash here */
-}
-
-H323_REGISTER_CAPABILITY(H323_G7231Capability, OPAL_G7231);
-H323_REGISTER_CAPABILITY(AST_G729Capability, OPAL_G729);
-H323_REGISTER_CAPABILITY(AST_G729ACapability, OPAL_G729A);
-
-H323_G7231Capability::H323_G7231Capability(BOOL annexA_)
- : H323AudioCapability(7, 4)
-{
- annexA = annexA_;
-}
-
-PObject::Comparison H323_G7231Capability::Compare(const PObject & obj) const
-{
- Comparison result = H323AudioCapability::Compare(obj);
- if (result != EqualTo) {
- return result;
- }
- PINDEX otherAnnexA = ((const H323_G7231Capability &)obj).annexA;
- if (annexA < otherAnnexA) {
- return LessThan;
- }
- if (annexA > otherAnnexA) {
- return GreaterThan;
- }
- return EqualTo;
-}
-
-PObject * H323_G7231Capability::Clone() const
-{
- return new H323_G7231Capability(*this);
-}
-
-PString H323_G7231Capability::GetFormatName() const
-{
- return OPAL_G7231;
-}
-
-unsigned H323_G7231Capability::GetSubType() const
-{
- return H245_AudioCapability::e_g7231;
-}
-
-BOOL H323_G7231Capability::OnSendingPDU(H245_AudioCapability & cap,
- unsigned packetSize) const
-{
- cap.SetTag(H245_AudioCapability::e_g7231);
- H245_AudioCapability_g7231 & g7231 = cap;
- g7231.m_maxAl_sduAudioFrames = packetSize;
- g7231.m_silenceSuppression = annexA;
- return TRUE;
-}
-
-BOOL H323_G7231Capability::OnReceivedPDU(const H245_AudioCapability & cap,
- unsigned & packetSize)
-{
- if (cap.GetTag() != H245_AudioCapability::e_g7231) {
- return FALSE;
- }
- const H245_AudioCapability_g7231 & g7231 = cap;
- packetSize = g7231.m_maxAl_sduAudioFrames;
- annexA = g7231.m_silenceSuppression;
- return TRUE;
-}
-
-H323Codec * H323_G7231Capability::CreateCodec(H323Codec::Direction direction) const
-{
- return NULL;
-}
-
-AST_G729Capability::AST_G729Capability()
- : H323AudioCapability(24, 2)
-{
-}
-
-PObject * AST_G729Capability::Clone() const
-{
- return new AST_G729Capability(*this);
-}
-
-unsigned AST_G729Capability::GetSubType() const
-{
- return H245_AudioCapability::e_g729;
-}
-
-PString AST_G729Capability::GetFormatName() const
-{
- return OPAL_G729;
-}
-
-H323Codec * AST_G729Capability::CreateCodec(H323Codec::Direction direction) const
-{
- return NULL;
-}
-
-AST_G729ACapability::AST_G729ACapability()
- : H323AudioCapability(24, 6)
-{
-}
-
-PObject * AST_G729ACapability::Clone() const
-{
- return new AST_G729ACapability(*this);
-}
-
-unsigned AST_G729ACapability::GetSubType() const
-{
- return H245_AudioCapability::e_g729AnnexA;
-}
-
-PString AST_G729ACapability::GetFormatName() const
-{
- return OPAL_G729A;
-}
-
-H323Codec * AST_G729ACapability::CreateCodec(H323Codec::Direction direction) const
-{
- return NULL;
-}
-
-/** MyH323EndPoint
- */
-MyH323EndPoint::MyH323EndPoint()
- : H323EndPoint()
-{
- // Capabilities will be negotiated on per-connection basis
- capabilities.RemoveAll();
-}
-
-/** The fullAddress parameter is used directly in the MakeCall method so
- * the General form for the fullAddress argument is :
- * [alias@][transport$]host[:port]
- * default values: alias = the same value as host.
- * transport = ip.
- * port = 1720.
- */
-int MyH323EndPoint::MakeCall(const PString & dest, PString & token, unsigned int *callReference, call_options_t *opts)
-{
- PString fullAddress;
- MyH323Connection * connection;
-
- /* Determine whether we are using a gatekeeper or not. */
- if (GetGatekeeper()) {
- fullAddress = dest;
- if (h323debug) {
- cout << " -- Making call to " << fullAddress << " using gatekeeper." << endl;
- }
- } else {
- fullAddress = dest;
- if (h323debug) {
- cout << " -- Making call to " << fullAddress << " without gatekeeper." << endl;
- }
- }
- if (!(connection = (MyH323Connection *)H323EndPoint::MakeCallLocked(fullAddress, token, opts))) {
- if (h323debug) {
- cout << "Error making call to \"" << fullAddress << '"' << endl;
- }
- return 1;
- }
- *callReference = connection->GetCallReference();
-
- if (opts->cid_num) {
- connection->ast_cid_num = PString(opts->cid_num);
- }
- if (opts->cid_name) {
- connection->ast_cid_name = PString(opts->cid_name);
- connection->SetLocalPartyName(connection->ast_cid_name);
- }
-
- connection->dtmfCodec = (RTP_DataFrame::PayloadTypes)opts->dtmfcodec;
-
- if (h323debug) {
- cout << "\t-- " << GetLocalUserName() << " is calling host " << fullAddress << endl;
- cout << "\t-- Call token is " << (const char *)token << endl;
- cout << "\t-- Call reference is " << *callReference << endl;
- cout << "\t-- DTMF Payload is " << connection->dtmfCodec << endl;
- }
- connection->Unlock();
- return 0;
-}
-
-void MyH323EndPoint::SetEndpointTypeInfo( H225_EndpointType & info ) const
-{
- H323EndPoint::SetEndpointTypeInfo(info);
-
- if (terminalType == e_GatewayOnly){
- info.RemoveOptionalField(H225_EndpointType::e_terminal);
- info.IncludeOptionalField(H225_EndpointType::e_gateway);
- }
-
- info.m_gateway.IncludeOptionalField(H225_GatewayInfo::e_protocol);
- info.m_gateway.m_protocol.SetSize(1);
- H225_SupportedProtocols &protocol=info.m_gateway.m_protocol[0];
- protocol.SetTag(H225_SupportedProtocols::e_voice);
- PINDEX as=SupportedPrefixes.GetSize();
- ((H225_VoiceCaps &)protocol).m_supportedPrefixes.SetSize(as);
- for (PINDEX p=0; p<as; p++) {
- H323SetAliasAddress(SupportedPrefixes[p], ((H225_VoiceCaps &)protocol).m_supportedPrefixes[p].m_prefix, H225_AliasAddress::e_dialedDigits);
- }
-}
-
-void MyH323EndPoint::SetGateway(void)
-{
- terminalType = e_GatewayOnly;
-}
-
-BOOL MyH323EndPoint::ClearCall(const PString & token, H323Connection::CallEndReason reason)
-{
- if (h323debug) {
- cout << "\t-- ClearCall: Request to clear call with token " << token << ", cause " << reason << endl;
- }
- return H323EndPoint::ClearCall(token, reason);
-}
-
-BOOL MyH323EndPoint::ClearCall(const PString & token)
-{
- if (h323debug) {
- cout << "\t-- ClearCall: Request to clear call with token " << token << endl;
- }
- return H323EndPoint::ClearCall(token, H323Connection::EndedByLocalUser);
-}
-
-void MyH323EndPoint::SendUserTone(const PString &token, char tone)
-{
- H323Connection *connection = NULL;
-
- connection = FindConnectionWithLock(token);
- if (connection != NULL) {
- connection->SendUserInputTone(tone, 500);
- connection->Unlock();
- }
-}
-
-void MyH323EndPoint::OnClosedLogicalChannel(H323Connection & connection, const H323Channel & channel)
-{
- channelsOpen--;
- if (h323debug) {
- cout << "\t\tchannelsOpen = " << channelsOpen << endl;
- }
- H323EndPoint::OnClosedLogicalChannel(connection, channel);
-}
-
-BOOL MyH323EndPoint::OnConnectionForwarded(H323Connection & connection,
- const PString & forwardParty,
- const H323SignalPDU & pdu)
- {
- if (h323debug) {
- cout << "\t-- Call Forwarded to " << forwardParty << endl;
- }
- return FALSE;
- }
-
-BOOL MyH323EndPoint::ForwardConnection(H323Connection & connection,
- const PString & forwardParty,
- const H323SignalPDU & pdu)
-{
- if (h323debug) {
- cout << "\t-- Forwarding call to " << forwardParty << endl;
- }
- return H323EndPoint::ForwardConnection(connection, forwardParty, pdu);
-}
-
-void MyH323EndPoint::OnConnectionEstablished(H323Connection & connection, const PString & estCallToken)
-{
- if (h323debug) {
- cout << "\t=-= In OnConnectionEstablished for call " << connection.GetCallReference() << endl;
- cout << "\t\t-- Connection Established with \"" << connection.GetRemotePartyName() << "\"" << endl;
- }
- on_connection_established(connection.GetCallReference(), (const char *)connection.GetCallToken());
-}
-
-/** OnConnectionCleared callback function is called upon the dropping of an established
- * H323 connection.
- */
-void MyH323EndPoint::OnConnectionCleared(H323Connection & connection, const PString & clearedCallToken)
-{
- PString remoteName = connection.GetRemotePartyName();
-
- switch (connection.GetCallEndReason()) {
- case H323Connection::EndedByCallForwarded:
- if (h323debug) {
- cout << "-- " << remoteName << " has forwarded the call" << endl;
- }
- break;
- case H323Connection::EndedByRemoteUser:
- if (h323debug) {
- cout << "-- " << remoteName << " has cleared the call" << endl;
- }
- break;
- case H323Connection::EndedByCallerAbort:
- if (h323debug) {
- cout << "-- " << remoteName << " has stopped calling" << endl;
- }
- break;
- case H323Connection::EndedByRefusal:
- if (h323debug) {
- cout << "-- " << remoteName << " did not accept your call" << endl;
- }
- break;
- case H323Connection::EndedByRemoteBusy:
- if (h323debug) {
- cout << "-- " << remoteName << " was busy" << endl;
- }
- break;
- case H323Connection::EndedByRemoteCongestion:
- if (h323debug) {
- cout << "-- Congested link to " << remoteName << endl;
- }
- break;
- case H323Connection::EndedByNoAnswer:
- if (h323debug) {
- cout << "-- " << remoteName << " did not answer your call" << endl;
- }
- break;
- case H323Connection::EndedByTransportFail:
- if (h323debug) {
- cout << "-- Call with " << remoteName << " ended abnormally" << endl;
- }
- break;
- case H323Connection::EndedByCapabilityExchange:
- if (h323debug) {
- cout << "-- Could not find common codec with " << remoteName << endl;
- }
- break;
- case H323Connection::EndedByNoAccept:
- if (h323debug) {
- cout << "-- Did not accept incoming call from " << remoteName << endl;
- }
- break;
- case H323Connection::EndedByAnswerDenied:
- if (h323debug) {
- cout << "-- Refused incoming call from " << remoteName << endl;
- }
- break;
- case H323Connection::EndedByNoUser:
- if (h323debug) {
- cout << "-- Remote endpoint could not find user: " << remoteName << endl;
- }
- break;
- case H323Connection::EndedByNoBandwidth:
- if (h323debug) {
- cout << "-- Call to " << remoteName << " aborted, insufficient bandwidth." << endl;
- }
- break;
- case H323Connection::EndedByUnreachable:
- if (h323debug) {
- cout << "-- " << remoteName << " could not be reached." << endl;
- }
- break;
- case H323Connection::EndedByHostOffline:
- if (h323debug) {
- cout << "-- " << remoteName << " is not online." << endl;
- }
- break;
- case H323Connection::EndedByNoEndPoint:
- if (h323debug) {
- cout << "-- No phone running for " << remoteName << endl;
- }
- break;
- case H323Connection::EndedByConnectFail:
- if (h323debug) {
- cout << "-- Transport error calling " << remoteName << endl;
- }
- break;
- default:
- if (h323debug)
- cout << " -- Call with " << remoteName << " completed (" << connection.GetCallEndReason() << ")" << endl;
-
- }
-
- if (connection.IsEstablished()) {
- if (h323debug) {
- cout << "\t-- Call duration " << setprecision(0) << setw(5) << (PTime() - connection.GetConnectionStartTime()) << endl;
- }
- }
- /* Invoke the PBX application registered callback */
- on_connection_cleared(connection.GetCallReference(), clearedCallToken);
- return;
-}
-
-H323Connection * MyH323EndPoint::CreateConnection(unsigned callReference, void *o)
-{
- unsigned options = 0;
- call_options_t *opts = (call_options_t *)o;
-
- if (opts && opts->noFastStart) {
- options |= H323Connection::FastStartOptionDisable;
- } else {
- options |= H323Connection::FastStartOptionEnable;
- }
- if (opts && opts->noH245Tunneling) {
- options |= H323Connection::H245TunnelingOptionDisable;
- } else {
- options |= H323Connection::H245TunnelingOptionEnable;
- }
-/* Disable until I can figure out the proper way to deal with this */
-#if 0
- if (opts->noSilenceSuppression) {
- options |= H323Connection::SilenceSuppresionOptionDisable;
- } else {
- options |= H323Connection::SilenceSUppressionOptionEnable;
- }
-#endif
- return new MyH323Connection(*this, callReference, options);
-}
-
-/* MyH323Connection Implementation */
-MyH323Connection::MyH323Connection(MyH323EndPoint & ep, unsigned callReference,
- unsigned options)
- : H323Connection(ep, callReference, options)
-{
- cause = -1;
- if (h323debug) {
- cout << " == New H.323 Connection created." << endl;
- }
- return;
-}
-
-MyH323Connection::~MyH323Connection()
-{
- if (h323debug) {
- cout << " == H.323 Connection deleted." << endl;
- }
- return;
-}
-
-BOOL MyH323Connection::OnReceivedProgress(const H323SignalPDU &pdu)
-{
- BOOL isInband;
- unsigned pi;
-
- if (!H323Connection::OnReceivedProgress(pdu)) {
- return FALSE;
- }
-
- if (!pdu.GetQ931().GetProgressIndicator(pi))
- pi = 0;
- if (h323debug) {
- cout << "\t- Progress Indicator: " << pi << endl;
- }
-
- switch(pi) {
- case Q931::ProgressNotEndToEndISDN:
- case Q931::ProgressInbandInformationAvailable:
- isInband = TRUE;
- break;
- default:
- isInband = FALSE;
- }
- on_progress(GetCallReference(), (const char *)GetCallToken(), isInband);
-
- return connectionState != ShuttingDownConnection;
-}
-
-H323Connection::AnswerCallResponse MyH323Connection::OnAnswerCall(const PString & caller,
- const H323SignalPDU & setupPDU,
- H323SignalPDU & /*connectPDU*/)
-{
- unsigned pi;
-
- if (h323debug) {
- cout << "\t=-= In OnAnswerCall for call " << GetCallReference() << endl;
- }
-
- if (connectionState == ShuttingDownConnection)
- return H323Connection::AnswerCallDenied;
-
- if (!setupPDU.GetQ931().GetProgressIndicator(pi)) {
- pi = 0;
- }
- if (h323debug) {
- cout << "\t\t- Progress Indicator: " << pi << endl;
- }
- if (progressAlert) {
- pi = progressAlert;
- } else if (pi == Q931::ProgressOriginNotISDN) {
- pi = Q931::ProgressInbandInformationAvailable;
- }
- if (pi) {
- alertingPDU->GetQ931().SetProgressIndicator(pi);
- }
- if (h323debug) {
- cout << "\t\t- Inserting PI of " << pi << " into ALERTING message" << endl;
- }
-
- if (!on_answer_call(GetCallReference(), (const char *)GetCallToken())) {
- return H323Connection::AnswerCallDenied;
- }
- /* The call will be answered later with "AnsweringCall()" function.
- */
- return H323Connection::AnswerCallDeferredWithMedia;
-}
-
-BOOL MyH323Connection::OnAlerting(const H323SignalPDU & alertingPDU, const PString & username)
-{
- if (h323debug) {
- cout << "\t=-= In OnAlerting for call " << GetCallReference()
- << ": sessionId=" << sessionId << endl;
- cout << "\t-- Ringing phone for \"" << username << "\"" << endl;
- }
-
- if (on_progress) {
- BOOL isInband;
- unsigned alertingPI;
-
- if (!alertingPDU.GetQ931().GetProgressIndicator(alertingPI)) {
- alertingPI = 0;
- }
- if (h323debug) {
- cout << "\t\t- Progress Indicator: " << alertingPI << endl;
- }
-
- switch(alertingPI) {
- case Q931::ProgressNotEndToEndISDN:
- case Q931::ProgressInbandInformationAvailable:
- isInband = TRUE;
- break;
- default:
- isInband = FALSE;
- }
- on_progress(GetCallReference(), (const char *)GetCallToken(), isInband);
- }
- on_chan_ringing(GetCallReference(), (const char *)GetCallToken() );
- return connectionState != ShuttingDownConnection;
-}
-
-BOOL MyH323Connection::OnReceivedSignalSetup(const H323SignalPDU & setupPDU)
-{
- call_details_t cd;
- PString sourceE164;
- PString destE164;
- PString sourceName;
- PString sourceAliases;
- PString destAliases;
- PIPSocket::Address Ip;
- WORD sourcePort;
- char *s, *s1;
-
- if (h323debug) {
- cout << ("\t--Received SETUP message\n");
- }
-
- if (connectionState == ShuttingDownConnection)
- return FALSE;
-
- sourceAliases = setupPDU.GetSourceAliases();
- destAliases = setupPDU.GetDestinationAlias();
-
- sourceE164 = "";
- setupPDU.GetSourceE164(sourceE164);
- sourceName = "";
- sourceName=setupPDU.GetQ931().GetDisplayName();
- destE164 = "";
- setupPDU.GetDestinationE164(destE164);
-
- /* Convert complex strings */
- // FIXME: deal more than one source alias
- if ((s = strchr(sourceAliases, ' ')) != NULL) {
- *s = '\0';
- }
- if ((s = strchr(sourceAliases, '\t')) != NULL) {
- *s = '\0';
- }
- if ((s1 = strchr(destAliases, ' ')) != NULL) {
- *s1 = '\0';
- }
- if ((s1 = strchr(destAliases, '\t')) != NULL) {
- *s1 = '\0';
- }
-
- memset(&cd, 0, sizeof(cd));
- cd.call_reference = GetCallReference();
- cd.call_token = strdup((const char *)GetCallToken());
- cd.call_source_aliases = strdup((const char *)sourceAliases);
- cd.call_dest_alias = strdup((const char *)destAliases);
- cd.call_source_e164 = strdup((const char *)sourceE164);
- cd.call_dest_e164 = strdup((const char *)destE164);
- cd.call_source_name = strdup((const char *)sourceName);
-
- GetSignallingChannel()->GetRemoteAddress().GetIpAndPort(Ip, sourcePort);
- cd.sourceIp = strdup((const char *)Ip.AsString());
-
- /* Notify Asterisk of the request */
- call_options_t *res = on_incoming_call(&cd);
-
- if (!res) {
- if (h323debug) {
- cout << " -- Call Failed" << endl;
- }
- return FALSE;
- }
-
- progressSetup = res->progress_setup;
- progressAlert = res->progress_alert;
- dtmfCodec = (RTP_DataFrame::PayloadTypes)res->dtmfcodec;
-
-
- return H323Connection::OnReceivedSignalSetup(setupPDU);
-}
-
-BOOL MyH323Connection::OnSendSignalSetup(H323SignalPDU & setupPDU)
-{
- call_details_t cd;
- char *s, *s1;
-
- if (h323debug) {
- cout << " -- Sending SETUP message" << endl;
- }
-
- if (connectionState == ShuttingDownConnection)
- return FALSE;
-
- if (!ast_cid_num.IsEmpty()) {
- setupPDU.GetQ931().SetCallingPartyNumber(ast_cid_num);
- }
-
- if (!ast_cid_name.IsEmpty()) {
- setupPDU.GetQ931().SetDisplayName(ast_cid_name);
- }
-
- sourceAliases = setupPDU.GetSourceAliases();
- destAliases = setupPDU.GetDestinationAlias();
-
- sourceE164 = "";
- setupPDU.GetSourceE164(sourceE164);
- destE164 = "";
- setupPDU.GetDestinationE164(destE164);
-
- /* Convert complex strings */
- // FIXME: deal more than one source alias
-
- if ((s = strchr(sourceAliases, ' ')) != NULL) {
- *s = '\0';
- }
- if ((s = strchr(sourceAliases, '\t')) != NULL) {
- *s = '\0';
- }
- if ((s1 = strchr(destAliases, ' ')) != NULL) {
- *s1 = '\0';
- }
- if ((s1 = strchr(destAliases, '\t')) != NULL) {
- *s1 = '\0';
- }
-
- memset(&cd, 0, sizeof(cd));
- cd.call_reference = GetCallReference();
- cd.call_token = strdup((const char *)GetCallToken());
- cd.call_source_aliases = strdup((const char *)sourceAliases);
- cd.call_dest_alias = strdup((const char *)destAliases);
- cd.call_source_e164 = strdup((const char *)sourceE164);
- cd.call_dest_e164 = strdup((const char *)destE164);
-
- int res = on_outgoing_call(&cd);
- if (!res) {
- if (h323debug) {
- cout << "\t-- Call Failed" << endl;
- }
- return FALSE;
- }
-
- if (progressSetup) {
- setupPDU.GetQ931().SetProgressIndicator(progressSetup);
- }
- return H323Connection::OnSendSignalSetup(setupPDU);
-}
-
-BOOL MyH323Connection::OnSendReleaseComplete(H323SignalPDU & releaseCompletePDU)
-{
- if (h323debug) {
- cout << "\t-- Sending RELEASE COMPLETE" << endl;
- }
- if (cause > 0)
- releaseCompletePDU.GetQ931().SetCause((Q931::CauseValues)cause);
- return H323Connection::OnSendReleaseComplete(releaseCompletePDU);
-}
-
-BOOL MyH323Connection::OnReceivedFacility(const H323SignalPDU & pdu)
-{
- if (h323debug) {
- cout << "\t-- Received Facility message... " << endl;
- }
- return H323Connection::OnReceivedFacility(pdu);
-}
-
-void MyH323Connection::OnReceivedReleaseComplete(const H323SignalPDU & pdu)
-{
- if (h323debug) {
- cout << "\t-- Received RELEASE COMPLETE message..." << endl;
- }
- if (on_hangup)
- on_hangup(GetCallReference(), (const char *)GetCallToken(), pdu.GetQ931().GetCause());
- return H323Connection::OnReceivedReleaseComplete(pdu);
-}
-
-BOOL MyH323Connection::OnClosingLogicalChannel(H323Channel & channel)
-{
- if (h323debug) {
- cout << "\t-- Closing logical channel..." << endl;
- }
- return H323Connection::OnClosingLogicalChannel(channel);
-}
-
-void MyH323Connection::SendUserInputTone(char tone, unsigned duration)
-{
- if (h323debug) {
- cout << "\t-- Sending user input tone (" << tone << ") to remote" << endl;
- }
- on_send_digit(GetCallReference(), tone, (const char *)GetCallToken());
- H323Connection::SendUserInputTone(tone, duration);
-}
-
-void MyH323Connection::OnUserInputTone(char tone, unsigned duration, unsigned logicalChannel, unsigned rtpTimestamp)
-{
- if (mode == H323_DTMF_INBAND) {
- if (h323debug) {
- cout << "\t-- Received user input tone (" << tone << ") from remote" << endl;
- }
- on_send_digit(GetCallReference(), tone, (const char *)GetCallToken());
- }
- H323Connection::OnUserInputTone(tone, duration, logicalChannel, rtpTimestamp);
-}
-
-void MyH323Connection::OnUserInputString(const PString &value)
-{
- if (mode == H323_DTMF_RFC2833) {
- if (h323debug) {
- cout << "\t-- Received user input string (" << value << ") from remote." << endl;
- }
- on_send_digit(GetCallReference(), value[0], (const char *)GetCallToken());
- }
-}
-
-void MyH323Connection::OnSendCapabilitySet(H245_TerminalCapabilitySet & pdu)
-{
- PINDEX i;
-
- H323Connection::OnSendCapabilitySet(pdu);
-
- H245_ArrayOf_CapabilityTableEntry & tables = pdu.m_capabilityTable;
- for(i = 0; i < tables.GetSize(); i++)
- {
- H245_CapabilityTableEntry & entry = tables[i];
- if (entry.HasOptionalField(H245_CapabilityTableEntry::e_capability)) {
- H245_Capability & cap = entry.m_capability;
- if (cap.GetTag() == H245_Capability::e_receiveRTPAudioTelephonyEventCapability) {
- H245_AudioTelephonyEventCapability & atec = cap;
- atec.m_dynamicRTPPayloadType = dtmfCodec;
- on_set_rfc2833_payload(GetCallReference(), (const char *)GetCallToken(), (int)dtmfCodec);
- if (h323debug) {
- cout << "\t-- Transmitting RFC2833 on payload " <<
- atec.m_dynamicRTPPayloadType << endl;
- }
- }
- }
- }
-}
-
-void MyH323Connection::OnSetLocalCapabilities()
-{
- if (on_setcapabilities)
- on_setcapabilities(GetCallReference(), (const char *)callToken);
-}
-
-BOOL MyH323Connection::OnReceivedCapabilitySet(const H323Capabilities & remoteCaps,
- const H245_MultiplexCapability * muxCap,
- H245_TerminalCapabilitySetReject & reject)
-{
- if (!H323Connection::OnReceivedCapabilitySet(remoteCaps, muxCap, reject)) {
- return FALSE;
- }
-
- const H323Capability * cap = remoteCaps.FindCapability(H323_UserInputCapability::SubTypeNames[H323_UserInputCapability::SignalToneRFC2833]);
- if (cap != NULL) {
- RTP_DataFrame::PayloadTypes pt = ((H323_UserInputCapability*)cap)->GetPayloadType();
- on_set_rfc2833_payload(GetCallReference(), (const char *)GetCallToken(), (int)pt);
- if (h323debug) {
- cout << "\t-- Inbound RFC2833 on payload " << pt << endl;
- }
- }
- return TRUE;
-}
-
-H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capability & capability,
- H323Channel::Directions dir,
- unsigned sessionID,
- const H245_H2250LogicalChannelParameters * /*param*/,
- RTP_QOS * /*param*/ )
-{
- return new MyH323_ExternalRTPChannel(*this, capability, dir, sessionID);
-}
-
-/** This callback function is invoked once upon creation of each
- * channel for an H323 session
- */
-BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
-{
- /* Increase the count of channels we have open */
- channelsOpen++;
-
- if (h323debug) {
- cout << "\t-- Started logical channel: ";
- cout << ((channel.GetDirection()==H323Channel::IsTransmitter)?"sending ":((channel.GetDirection()==H323Channel::IsReceiver)?"receiving ":" "));
- cout << (const char *)(channel.GetCapability()).GetFormatName() << endl;
- cout << "\t\t-- channelsOpen = " << channelsOpen << endl;
- }
- return connectionState != ShuttingDownConnection;
-}
-
-void MyH323Connection::SetCapabilities(int cap, int dtmfMode)
-{
- int g711Frames = 20;
-// int gsmFrames = 4;
- PINDEX lastcap = -1; /* last common capability index */
-
-#if 0
- if (cap & AST_FORMAT_SPEEX) {
- /* Not real sure if Asterisk acutally supports all
- of the various different bit rates so add them
- all and figure it out later*/
-
- localCapabilities.SetCapability(0, 0, new SpeexNarrow2AudioCapability());
- localCapabilities.SetCapability(0, 0, new SpeexNarrow3AudioCapability());
- localCapabilities.SetCapability(0, 0, new SpeexNarrow4AudioCapability());
- localCapabilities.SetCapability(0, 0, new SpeexNarrow5AudioCapability());
- localCapabilities.SetCapability(0, 0, new SpeexNarrow6AudioCapability());
- }
-#endif
- if (cap & AST_FORMAT_G729A) {
- AST_G729ACapability *g729aCap;
- AST_G729Capability *g729Cap;
- lastcap = localCapabilities.SetCapability(0, 0, g729aCap = new AST_G729ACapability);
- lastcap = localCapabilities.SetCapability(0, 0, g729Cap = new AST_G729Capability);
- }
-
- if (cap & AST_FORMAT_G723_1) {
- H323_G7231Capability *g7231Cap;
- lastcap = localCapabilities.SetCapability(0, 0, g7231Cap = new H323_G7231Capability);
- }
-#if 0
- if (cap & AST_FORMAT_GSM) {
- H323_GSM0610Capability *gsmCap;
- lastcap = localCapabilities.SetCapability(0, 0, gsmCap = new H323_GSM0610Capability);
- gsmCap->SetTxFramesInPacket(gsmFrames);
- }
-#endif
- if (cap & AST_FORMAT_ULAW) {
- H323_G711Capability *g711uCap;
- lastcap = localCapabilities.SetCapability(0, 0, g711uCap = new H323_G711Capability(H323_G711Capability::muLaw));
- g711uCap->SetTxFramesInPacket(g711Frames);
- }
-
- if (cap & AST_FORMAT_ALAW) {
- H323_G711Capability *g711aCap;
- lastcap = localCapabilities.SetCapability(0, 0, g711aCap = new H323_G711Capability(H323_G711Capability::ALaw));
- g711aCap->SetTxFramesInPacket(g711Frames);
- }
-
- lastcap++;
- lastcap = localCapabilities.SetCapability(0, lastcap, new H323_UserInputCapability(H323_UserInputCapability::HookFlashH245));
-
- lastcap++;
- mode = dtmfMode;
- if (dtmfMode == H323_DTMF_INBAND) {
- localCapabilities.SetCapability(0, lastcap, new H323_UserInputCapability(H323_UserInputCapability::SignalToneH245));
- sendUserInputMode = SendUserInputAsTone;
- } else {
- localCapabilities.SetCapability(0, lastcap, new H323_UserInputCapability(H323_UserInputCapability::SignalToneRFC2833));
- sendUserInputMode = SendUserInputAsInlineRFC2833;
- }
-
- if (h323debug) {
- cout << "Allowed Codecs:\n\t" << setprecision(2) << localCapabilities << endl;
- }
-}
-
-/* MyH323_ExternalRTPChannel */
-MyH323_ExternalRTPChannel::MyH323_ExternalRTPChannel(MyH323Connection & connection,
- const H323Capability & capability,
- Directions direction,
- unsigned id)
- : H323_ExternalRTPChannel::H323_ExternalRTPChannel(connection, capability, direction, id)
-{
- struct rtp_info *info;
-
- /* Determine the Local (A side) IP Address and port */
- info = on_external_rtp_create(connection.GetCallReference(), (const char *)connection.GetCallToken());
- if (!info) {
- cout << "\tERROR: on_external_rtp_create failure" << endl;
- return;
- } else {
- localIpAddr = info->addr;
- localPort = info->port;
- /* tell the H.323 stack */
- SetExternalAddress(H323TransportAddress(localIpAddr, localPort), H323TransportAddress(localIpAddr, localPort + 1));
- /* clean up allocated memory */
- free(info);
- }
-
- /* Get the payload code */
- OpalMediaFormat format(capability.GetFormatName(), FALSE);
- payloadCode = format.GetPayloadType();
-}
-
-MyH323_ExternalRTPChannel::~MyH323_ExternalRTPChannel()
-{
- if (h323debug) {
- cout << "\tExternalRTPChannel Destroyed" << endl;
- }
-}
-
-BOOL MyH323_ExternalRTPChannel::Start(void)
-{
- /* Call ancestor first */
- if (!H323_ExternalRTPChannel::Start()) {
- return FALSE;
- }
-
- if (h323debug) {
- cout << "\t\tExternal RTP Session Starting" << endl;
- cout << "\t\tRTP channel id " << sessionID << " parameters:" << endl;
- }
-
- /* Collect the remote information */
- H323_ExternalRTPChannel::GetRemoteAddress(remoteIpAddr, remotePort);
-
- if (h323debug) {
- cout << "\t\t-- remoteIpAddress: " << remoteIpAddr << endl;
- cout << "\t\t-- remotePort: " << remotePort << endl;
- cout << "\t\t-- ExternalIpAddress: " << localIpAddr << endl;
- cout << "\t\t-- ExternalPort: " << localPort << endl;
- }
- /* Notify Asterisk of remote RTP information */
- on_start_rtp_channel(connection.GetCallReference(), (const char *)remoteIpAddr.AsString(), remotePort,
- (const char *)connection.GetCallToken(), (int)payloadCode);
- return TRUE;
-}
-
-BOOL MyH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param)
-{
- PIPSocket::Address remoteIpAddress;
- WORD remotePort;
-
- if (h323debug) {
- cout << " MyH323_ExternalRTPChannel::OnReceivedAckPDU" << endl;
- }
-
- if (H323_ExternalRTPChannel::OnReceivedAckPDU(param)) {
- GetRemoteAddress(remoteIpAddress, remotePort);
- if (h323debug) {
- cout << " -- remoteIpAddress: " << remoteIpAddress << endl;
- cout << " -- remotePort: " << remotePort << endl;
- }
- on_start_rtp_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(),
- remotePort, (const char *)connection.GetCallToken(), (int)payloadCode);
- return TRUE;
- }
- return FALSE;
-}
-
-/** IMPLEMENTATION OF C FUNCTIONS */
-
-/**
- * The extern "C" directive takes care for
- * the ANSI-C representation of linkable symbols
- */
-
-extern "C" {
-
-int h323_end_point_exist(void)
-{
- if (!endPoint) {
- return 0;
- }
- return 1;
-}
-
-void h323_end_point_create(void)
-{
- channelsOpen = 0;
- logstream = new PAsteriskLog();
- localProcess = new MyProcess();
- localProcess->Main();
-}
-
-void h323_gk_urq(void)
-{
- if (!h323_end_point_exist()) {
- cout << " ERROR: [h323_gk_urq] No Endpoint, this is bad" << endl;
- return;
- }
- endPoint->RemoveGatekeeper();
-}
-
-void h323_debug(int flag, unsigned level)
-{
- if (flag) {
- PTrace:: SetLevel(level);
- } else {
- PTrace:: SetLevel(0);
- }
-}
-
-/** Installs the callback functions on behalf of the PBX application */
-void h323_callback_register(setup_incoming_cb ifunc,
- setup_outbound_cb sfunc,
- on_rtp_cb rtpfunc,
- start_rtp_cb lfunc,
- clear_con_cb clfunc,
- chan_ringing_cb rfunc,
- con_established_cb efunc,
- send_digit_cb dfunc,
- answer_call_cb acfunc,
- progress_cb pgfunc,
- rfc2833_cb dtmffunc,
- hangup_cb hangupfunc,
- setcapabilities_cb capabilityfunc)
-{
- on_incoming_call = ifunc;
- on_outgoing_call = sfunc;
- on_external_rtp_create = rtpfunc;
- on_start_rtp_channel = lfunc;
- on_connection_cleared = clfunc;
- on_chan_ringing = rfunc;
- on_connection_established = efunc;
- on_send_digit = dfunc;
- on_answer_call = acfunc;
- on_progress = pgfunc;
- on_set_rfc2833_payload = dtmffunc;
- on_hangup = hangupfunc;
- on_setcapabilities = capabilityfunc;
-}
-
-/**
- * Add capability to the capability table of the end point.
- */
-int h323_set_capabilities(const char *token, int cap, int dtmfMode)
-{
- MyH323Connection *conn;
-
- if (!h323_end_point_exist()) {
- cout << " ERROR: [h323_set_capablities] No Endpoint, this is bad" << endl;
- return 1;
- }
- if (!token || !*token) {
- cout << " ERROR: [h323_set_capabilities] Invalid call token specified." << endl;
- return 1;
- }
-
- PString myToken(token);
- conn = (MyH323Connection *)endPoint->FindConnectionWithLock(myToken);
- if (!conn) {
- cout << " ERROR: [h323_set_capabilities] Unable to find connection " << token << endl;
- return 1;
- }
- conn->SetCapabilities(cap, dtmfMode);
- conn->Unlock();
-
- return 0;
-}
-
-/** Start the H.323 listener */
-int h323_start_listener(int listenPort, struct sockaddr_in bindaddr)
-{
-
- if (!h323_end_point_exist()) {
- cout << "ERROR: [h323_start_listener] No Endpoint, this is bad!" << endl;
- return 1;
- }
-
- PIPSocket::Address interfaceAddress(bindaddr.sin_addr);
- if (!listenPort) {
- listenPort = 1720;
- }
- /** H.323 listener */
- H323ListenerTCP *tcpListener;
- tcpListener = new H323ListenerTCP(*endPoint, interfaceAddress, (WORD)listenPort);
- if (!endPoint->StartListener(tcpListener)) {
- cout << "ERROR: Could not open H.323 listener port on " << ((H323ListenerTCP *) tcpListener)->GetListenerPort() << endl;
- delete tcpListener;
- return 1;
-
- }
- cout << " == H.323 listener started" << endl;
- return 0;
-};
-
-int h323_set_alias(struct oh323_alias *alias)
-{
- char *p;
- char *num;
- PString h323id(alias->name);
- PString e164(alias->e164);
- char *prefix;
-
- if (!h323_end_point_exist()) {
- cout << "ERROR: [h323_set_alias] No Endpoint, this is bad!" << endl;
- return 1;
- }
-
- cout << "== Adding alias \"" << h323id << "\" to endpoint" << endl;
- endPoint->AddAliasName(h323id);
- endPoint->RemoveAliasName(localProcess->GetUserName());
-
- if (!e164.IsEmpty()) {
- cout << "== Adding E.164 \"" << e164 << "\" to endpoint" << endl;
- endPoint->AddAliasName(e164);
- }
- if (strlen(alias->prefix)) {
- p = prefix = strdup(alias->prefix);
- while((num = strsep(&p, ",")) != (char *)NULL) {
- cout << "== Adding Prefix \"" << num << "\" to endpoint" << endl;
- endPoint->SupportedPrefixes += PString(num);
- endPoint->SetGateway();
- }
- if (prefix)
- free(prefix);
- }
- return 0;
-}
-
-void h323_set_id(char *id)
-{
- PString h323id(id);
-
- if (h323debug) {
- cout << " == Using '" << h323id << "' as our H.323ID for this call" << endl;
- }
- /* EVIL HACK */
- endPoint->SetLocalUserName(h323id);
-}
-
-void h323_show_tokens(void)
-{
- cout << "Current call tokens: " << setprecision(2) << endPoint->GetAllConnections() << endl;
-}
-
-/** Establish Gatekeeper communiations, if so configured,
- * register aliases for the H.323 endpoint to respond to.
- */
-int h323_set_gk(int gatekeeper_discover, char *gatekeeper, char *secret)
-{
- PString gkName = PString(gatekeeper);
- PString pass = PString(secret);
- H323TransportUDP *rasChannel;
-
- if (!h323_end_point_exist()) {
- cout << "ERROR: [h323_set_gk] No Endpoint, this is bad!" << endl;
- return 1;
- }
-
- if (!gatekeeper) {
- cout << "Error: Gatekeeper cannot be NULL" << endl;
- return 1;
- }
- if (strlen(secret)) {
- endPoint->SetGatekeeperPassword(pass);
- }
- if (gatekeeper_discover) {
- /* discover the gk using multicast */
- if (endPoint->DiscoverGatekeeper(new H323TransportUDP(*endPoint))) {
- cout << "== Using " << (endPoint->GetGatekeeper())->GetName() << " as our Gatekeeper." << endl;
- } else {
- cout << "Warning: Could not find a gatekeeper." << endl;
- return 1;
- }
- } else {
- rasChannel = new H323TransportUDP(*endPoint);
-
- if (!rasChannel) {
- cout << "Error: No RAS Channel, this is bad" << endl;
- return 1;
- }
- if (endPoint->SetGatekeeper(gkName, rasChannel)) {
- cout << "== Using " << (endPoint->GetGatekeeper())->GetName() << " as our Gatekeeper." << endl;
- } else {
- cout << "Error registering with gatekeeper \"" << gkName << "\". " << endl;
- /* XXX Maybe we should fire a new thread to attempt to re-register later and not kill asterisk here? */
- return 1;
- }
- }
- return 0;
-}
-
-/** Send a DTMF tone over the H323Connection with the
- * specified token.
- */
-void h323_send_tone(const char *call_token, char tone)
-{
- if (!h323_end_point_exist()) {
- cout << "ERROR: [h323_send_tone] No Endpoint, this is bad!" << endl;
- return;
- }
- PString token = PString(call_token);
- endPoint->SendUserTone(token, tone);
-}
-
-/** Make a call to the remote endpoint.
- */
-int h323_make_call(char *dest, call_details_t *cd, call_options_t *call_options)
-{
- int res;
- PString token;
- PString host(dest);
-
- if (!h323_end_point_exist()) {
- return 1;
- }
-
- res = endPoint->MakeCall(host, token, &cd->call_reference, call_options);
- memcpy((char *)(cd->call_token), (const unsigned char *)token, token.GetLength());
- return res;
-};
-
-int h323_clear_call(const char *call_token, int cause)
-{
- H225_ReleaseCompleteReason dummy;
- H323Connection::CallEndReason r = H323Connection::EndedByLocalUser;
- MyH323Connection *connection;
- const PString currentToken(call_token);
-
- if (!h323_end_point_exist()) {
- return 1;
- }
-
- if (cause) {
- r = H323TranslateToCallEndReason((Q931::CauseValues)(cause), dummy);
- }
-
- connection = (MyH323Connection *)endPoint->FindConnectionWithLock(currentToken);
- if (connection) {
- connection->SetCause(cause);
- connection->SetCallEndReason(r);
- connection->Unlock();
- }
- endPoint->ClearCall(currentToken, r);
- return 0;
-};
-
-/* Send Alerting PDU to H.323 caller */
-int h323_send_alerting(const char *token)
-{
- const PString currentToken(token);
- H323Connection * connection;
-
- if (h323debug) {
- cout << "\tSending alerting\n" << endl;
- }
- connection = endPoint->FindConnectionWithLock(currentToken);
- if (!connection) {
- cout << "No connection found for " << token << endl;
- return -1;
- }
- connection->AnsweringCall(H323Connection::AnswerCallPending);
- connection->Unlock();
- return 0;
-
-}
-
-/* Send Progress PDU to H.323 caller */
-int h323_send_progress(const char *token)
-{
- const PString currentToken(token);
- H323Connection * connection;
-
- connection = endPoint->FindConnectionWithLock(currentToken);
- if (!connection) {
- cout << "No connection found for " << token << endl;
- return -1;
- }
- connection->AnsweringCall(H323Connection::AnswerCallDeferredWithMedia);
- connection->Unlock();
- return 0;
-}
-
-/** This function tells the h.323 stack to either
- answer or deny an incoming call */
-int h323_answering_call(const char *token, int busy)
-{
- const PString currentToken(token);
- H323Connection * connection;
-
- connection = endPoint->FindConnectionWithLock(currentToken);
-
- if (!connection) {
- cout << "No connection found for " << token << endl;
- return -1;
- }
- if (!busy) {
- if (h323debug) {
- cout << "\tAnswering call " << token << endl;
- }
- connection->AnsweringCall(H323Connection::AnswerCallNow);
- } else {
- if (h323debug) {
- cout << "\tdenying call " << token << endl;
- }
- connection->AnsweringCall(H323Connection::AnswerCallDenied);
- }
- connection->Unlock();
- return 0;
-}
-
-int h323_show_codec(int fd, int argc, char *argv[])
-{
- cout << "Allowed Codecs:\n\t" << setprecision(2) << endPoint->GetCapabilities() << endl;
- return 0;
-}
-
-int h323_soft_hangup(const char *data)
-{
- PString token(data);
- BOOL result;
- cout << "Soft hangup" << endl;
- result = endPoint->ClearCall(token);
- return result;
-}
-
-/* alas, this doesn't work :( */
-void h323_native_bridge(const char *token, const char *them, char *capability)
-{
- H323Channel *channel;
- MyH323Connection *connection = (MyH323Connection *)endPoint->FindConnectionWithLock(token);
-
- if (!connection) {
- cout << "ERROR: No connection found, this is bad\n";
- return;
- }
-
- cout << "Native Bridge: them [" << them << "]" << endl;
-
- channel = connection->FindChannel(connection->sessionId, TRUE);
- connection->bridging = TRUE;
- connection->CloseLogicalChannelNumber(channel->GetNumber());
-
- connection->Unlock();
- return;
-
-}
-
-#undef cout
-void h323_end_process(void)
-{
- if (endPoint) {
- endPoint->ClearAllCalls();
- endPoint->RemoveListener(NULL);
- delete endPoint;
- endPoint = NULL;
- }
- if (localProcess) {
- delete localProcess;
- localProcess = NULL;
- }
- PTrace::SetLevel(0);
- PTrace::SetStream(&cout);
- if (logstream) {
- delete logstream;
- logstream = NULL;
- }
-}
-
-} /* extern "C" */
-
diff --git a/1.2-netsec/channels/h323/ast_h323.h b/1.2-netsec/channels/h323/ast_h323.h
deleted file mode 100644
index 5bab9fc3b..000000000
--- a/1.2-netsec/channels/h323/ast_h323.h
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * ast_h323.h
- *
- * OpenH323 Channel Driver for ASTERISK PBX.
- * By Jeremy McNamara
- * For The NuFone Network
- *
- * This code has been derived from code created by
- * Michael Manousos and Mark Spencer
- *
- * This file is part of the chan_h323 driver for Asterisk
- *
- * chan_h323 is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * chan_h323 is distributed WITHOUT ANY WARRANTY; without even
- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Version Info: $Id$
- */
-
-#ifndef AST_H323_H
-#define AST_H323_H
-
-/** These need to be redefined here because the C++
- side of this driver is blind to the asterisk headers */
-/*! G.723.1 compression */
-#define AST_FORMAT_G723_1 (1 << 0)
-/*! GSM compression */
-#define AST_FORMAT_GSM (1 << 1)
-/*! Raw mu-law data (G.711) */
-#define AST_FORMAT_ULAW (1 << 2)
-/*! Raw A-law data (G.711) */
-#define AST_FORMAT_ALAW (1 << 3)
-/*! MPEG-2 layer 3 */
-#define AST_FORMAT_MP3 (1 << 4)
-/*! ADPCM (whose?) */
-#define AST_FORMAT_ADPCM (1 << 5)
-/*! Raw 16-bit Signed Linear (8000 Hz) PCM */
-#define AST_FORMAT_SLINEAR (1 << 6)
-/*! LPC10, 180 samples/frame */
-#define AST_FORMAT_LPC10 (1 << 7)
-/*! G.729A audio */
-#define AST_FORMAT_G729A (1 << 8)
-/*! SpeeX Free Compression */
-#define AST_FORMAT_SPEEX (1 << 9)
-/*! ILBC Free Codec */
-#define AST_FORMAT_ILBC (1 << 10)
-
-/**This class describes the G.723.1 codec capability.
- */
-class H323_G7231Capability : public H323AudioCapability
-{
- PCLASSINFO(H323_G7231Capability, H323AudioCapability);
- public:
- H323_G7231Capability(BOOL annexA = TRUE);
- Comparison Compare(const PObject & obj) const;
- PObject * Clone() const;
- virtual H323Codec * CreateCodec(H323Codec::Direction direction) const;
- unsigned GetSubType() const;
- PString GetFormatName() const;
- BOOL OnSendingPDU(H245_AudioCapability & pdu, unsigned packetSize) const;
- BOOL OnReceivedPDU(const H245_AudioCapability & pdu, unsigned & packetSize);
- protected:
- BOOL annexA;
-};
-
-/**This class describes the (fake) G729 codec capability.
- */
-class AST_G729Capability : public H323AudioCapability
-{
- PCLASSINFO(AST_G729Capability, H323AudioCapability);
-
- public:
- AST_G729Capability();
- /* Create a copy of the object. */
- virtual PObject * Clone() const;
-
- /* Create the codec instance, allocating resources as required. */
- virtual H323Codec * CreateCodec(H323Codec::Direction direction) const;
-
- /* Get the sub-type of the capability. This is a code dependent on the
- main type of the capability.
-
- This returns one of the four possible combinations of mode and speed
- using the enum values of the protocol ASN H245_AudioCapability class. */
- virtual unsigned GetSubType() const;
-
- /* Get the name of the media data format this class represents. */
- virtual PString GetFormatName() const;
-
-};
-
-/* This class describes the VoiceAge G729A codec capability. */
-class AST_G729ACapability : public H323AudioCapability
-{
- PCLASSINFO(AST_G729ACapability, H323AudioCapability);
-
- public:
- /* Create a new G.729A capability. */
- AST_G729ACapability();
-
- /* Create a copy of the object. */
- virtual PObject * Clone() const;
- /* Create the codec instance, allocating resources as required. */
- virtual H323Codec * CreateCodec(H323Codec::Direction direction) const;
-
- /* Get the sub-type of the capability. This is a code dependent on the
- main type of the capability.
-
- This returns one of the four possible combinations of mode and speed
- using the enum values of the protocol ASN H245_AudioCapability class. */
- virtual unsigned GetSubType() const;
-
- /* Get the name of the media data format this class represents. */
- virtual PString GetFormatName() const;
-};
-
-class MyH323EndPoint : public H323EndPoint {
-
- PCLASSINFO(MyH323EndPoint, H323EndPoint);
-
- public:
- MyH323EndPoint();
- int MakeCall(const PString &, PString &, unsigned int *, call_options_t *opts);
- BOOL ClearCall(const PString &, H323Connection::CallEndReason reason);
- BOOL ClearCall(const PString &);
-
- void OnClosedLogicalChannel(H323Connection &, const H323Channel &);
- void OnConnectionEstablished(H323Connection &, const PString &);
- void OnConnectionCleared(H323Connection &, const PString &);
- H323Connection * CreateConnection(unsigned, void *);
- void SendUserTone(const PString &, char);
- BOOL OnConnectionForwarded(H323Connection &, const PString &, const H323SignalPDU &);
- BOOL ForwardConnection(H323Connection &, const PString &, const H323SignalPDU &);
- void SetEndpointTypeInfo( H225_EndpointType & info ) const;
- void SetGateway(void);
- PStringArray SupportedPrefixes;
-};
-
-class MyH323Connection : public H323Connection {
-
- PCLASSINFO(MyH323Connection, H323Connection);
-
- public:
- MyH323Connection(MyH323EndPoint &, unsigned, unsigned);
- ~MyH323Connection();
- H323Channel * CreateRealTimeLogicalChannel(const H323Capability &,
- H323Channel::Directions,
- unsigned,
- const H245_H2250LogicalChannelParameters *,
- RTP_QOS *);
- H323Connection::AnswerCallResponse OnAnswerCall(const PString &,
- const H323SignalPDU &,
- H323SignalPDU &);
- void OnReceivedReleaseComplete(const H323SignalPDU &);
- BOOL OnAlerting(const H323SignalPDU &, const PString &);
- BOOL OnSendReleaseComplete(H323SignalPDU &);
- BOOL OnReceivedSignalSetup(const H323SignalPDU &);
- BOOL OnReceivedFacility(const H323SignalPDU &);
- BOOL OnSendSignalSetup(H323SignalPDU &);
- BOOL OnStartLogicalChannel(H323Channel &);
- BOOL OnClosingLogicalChannel(H323Channel &);
- void SendUserInputTone(char, unsigned);
- void OnUserInputTone(char, unsigned, unsigned, unsigned);
- void OnUserInputString(const PString &value);
- BOOL OnReceivedProgress(const H323SignalPDU &);
- void OnSendCapabilitySet(H245_TerminalCapabilitySet &);
- void OnSetLocalCapabilities();
- void SetCapabilities(int, int);
- BOOL OnReceivedCapabilitySet(const H323Capabilities &, const H245_MultiplexCapability *,
- H245_TerminalCapabilitySetReject &);
- void SetCause(int _cause) { cause = _cause; };
-
- PString sourceAliases;
- PString destAliases;
- PString sourceE164;
- PString destE164;
-
- WORD sessionId;
- BOOL bridging;
-
- unsigned progressSetup;
- unsigned progressAlert;
- int cause;
-
- RTP_DataFrame::PayloadTypes dtmfCodec;
-
- PString ast_cid_num;
- PString ast_cid_name;
-};
-
-class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel {
-
- PCLASSINFO(MyH323_ExternalRTPChannel, H323_ExternalRTPChannel);
-
- public:
- MyH323_ExternalRTPChannel(
- MyH323Connection & connection,
- const H323Capability & capability,
- Directions direction,
- unsigned sessionID);
-
- ~MyH323_ExternalRTPChannel();
-
- /* Overrides */
- BOOL Start(void);
- BOOL OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param);
-
- protected:
- BYTE payloadCode;
-
- PIPSocket::Address localIpAddr;
- PIPSocket::Address remoteIpAddr;
- WORD localPort;
- WORD remotePort;
-};
-
-/**
- * The MyProcess is a necessary descendant PProcess class so that the H323EndPoint
- * objected to be created from within that class. (Solves the who owns main() problem).
- */
-class MyProcess : public PProcess {
-
- PCLASSINFO(MyProcess, PProcess);
-
- public:
- MyProcess();
- void Main();
-};
-
-#endif /* !defined AST_H323_H */
diff --git a/1.2-netsec/channels/h323/chan_h323.h b/1.2-netsec/channels/h323/chan_h323.h
deleted file mode 100644
index 1ca681c77..000000000
--- a/1.2-netsec/channels/h323/chan_h323.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * chan_h323.h
- *
- * OpenH323 Channel Driver for ASTERISK PBX.
- * By Jeremy McNamara
- * For The NuFone Network
- *
- * This code has been derived from code created by
- * Michael Manousos and Mark Spencer
- *
- * This file is part of the chan_h323 driver for Asterisk
- *
- * chan_h323 is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * chan_h323 is distributed WITHOUT ANY WARRANTY; without even
- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Version Info: $Id$
- */
-
-#include <arpa/inet.h>
-
-/** call_option struct holds various bits
- * of information for each call */
-typedef struct call_options {
- char cid_num[80];
- char cid_name[80];
- int noFastStart;
- int noH245Tunneling;
- int noSilenceSuppression;
- int progress_setup;
- int progress_alert;
- int progress_audio;
- int dtmfcodec;
- int dtmfmode;
- int capability;
- int bridge;
- int nat;
-} call_options_t;
-
-/* structure to hold the valid asterisk users */
-struct oh323_user {
- char name[80];
- char context[80];
- char secret[80];
- char callerid[80];
- char accountcode[AST_MAX_ACCOUNT_CODE];
- int amaflags;
- int host;
- struct sockaddr_in addr;
- struct ast_ha *ha;
- call_options_t options;
- struct oh323_user *next;
-};
-
-/* structure to hold the valid asterisk peers
- All peers are registered to a GK if there is one */
-struct oh323_peer {
- char name[80];
- char mailbox[80];
- int delme;
- struct sockaddr_in addr;
- struct ast_ha *ha;
- call_options_t options;
- struct oh323_peer *next;
-};
-
-/* structure to hold the H.323 aliases which get registered to
- the H.323 endpoint and gatekeeper */
-struct oh323_alias {
- char name[80];
- char e164[20]; /* tells a GK to route this E.164 to this alias */
- char prefix[500]; /* tells a GK this alias supports these prefixes */
- char secret[20]; /* the H.235 password to send to the GK for authentication */
- char context[80];
- struct oh323_alias *next;
-};
-
-/** call_details struct call detail records
- to asterisk for processing and used for matching up
- asterisk channels to acutal h.323 connections */
-typedef struct call_details {
- unsigned int call_reference;
- char *call_token;
- char *call_source_aliases;
- char *call_dest_alias;
- char *call_source_name;
- char *call_source_e164;
- char *call_dest_e164;
- int presentation;
- int screening;
- char *sourceIp;
-} call_details_t;
-
-typedef struct rtp_info {
- char addr[32];
- unsigned int port;
-} rtp_info_t;
-
-/* This is a callback prototype function, called pass
- DTMF down the RTP. */
-typedef int (*send_digit_cb)(unsigned, char, const char *);
-extern send_digit_cb on_send_digit;
-
-/* This is a callback prototype function, called to collect
- the external RTP port from Asterisk. */
-typedef rtp_info_t *(*on_rtp_cb)(unsigned, const char *);
-extern on_rtp_cb on_external_rtp_create;
-
-/* This is a callback prototype function, called to send
- the remote IP and RTP port from H.323 to Asterisk */
-typedef void (*start_rtp_cb)(unsigned int, const char *, int, const char *, int);
-extern start_rtp_cb on_start_rtp_channel;
-
-/* This is a callback that happens when call progress is
- * made, and handles inband progress */
-typedef int (*progress_cb)(unsigned, const char *, int);
-extern progress_cb on_progress;
-
-/* This is a callback prototype function, called upon
- an incoming call happens. */
-typedef call_options_t *(*setup_incoming_cb)(call_details_t *);
-extern setup_incoming_cb on_incoming_call;
-
-/* This is a callback prototype function, called upon
- an outbound call. */
-typedef int (*setup_outbound_cb)(call_details_t *);
-extern setup_outbound_cb on_outgoing_call;
-
-/* This is a callback prototype function, called when
- OnAlerting is invoked */
-typedef void (*chan_ringing_cb)(unsigned, const char *);
-extern chan_ringing_cb on_chan_ringing;
-
-/* This is a callback protoype function, called when
- OnConnectionEstablished is inovked */
-typedef void (*con_established_cb)(unsigned, const char *);
-extern con_established_cb on_connection_established;
-
-/* This is a callback prototype function, called when
- OnConnectionCleared callback is invoked */
-typedef void (*clear_con_cb)(unsigned, const char *);
-extern clear_con_cb on_connection_cleared;
-
-/* This is a callback prototype function, called when
- an H.323 call is answered */
-typedef int (*answer_call_cb)(unsigned, const char *);
-extern answer_call_cb on_answer_call;
-
-/* This is a callback prototype function, called when
- we know which RTP payload type RFC2833 will be
- transmitted */
-typedef void (*rfc2833_cb)(unsigned, const char *, int);
-extern rfc2833_cb on_set_rfc2833_payload;
-
-typedef void (*hangup_cb)(unsigned, const char *, int);
-extern hangup_cb on_hangup;
-
-typedef void (*setcapabilities_cb)(unsigned, const char *);
-extern setcapabilities_cb on_setcapabilities;
-
-/* debug flag */
-extern int h323debug;
-
-#define H323_DTMF_RFC2833 (1 << 0)
-#define H323_DTMF_INBAND (1 << 1)
-
-#ifndef BOOL
-#define BOOL int
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- void h323_gk_urq(void);
- void h323_end_point_create(void);
- void h323_end_process(void);
- int h323_end_point_exist(void);
-
- void h323_debug(int, unsigned);
-
- /* callback function handler*/
- void h323_callback_register(setup_incoming_cb,
- setup_outbound_cb,
- on_rtp_cb,
- start_rtp_cb,
- clear_con_cb,
- chan_ringing_cb,
- con_established_cb,
- send_digit_cb,
- answer_call_cb,
- progress_cb,
- rfc2833_cb,
- hangup_cb,
- setcapabilities_cb);
- int h323_set_capabilities(const char *, int, int);
- int h323_set_alias(struct oh323_alias *);
- int h323_set_gk(int, char *, char *);
- void h323_set_id(char *);
- void h323_show_tokens(void);
-
- /* H323 listener related funcions */
- int h323_start_listener(int, struct sockaddr_in);
-
- void h323_native_bridge(const char *, const char *, char *);
-
- /* Send a DTMF tone to remote endpoint */
- void h323_send_tone(const char *call_token, char tone);
-
- /* H323 create and destroy sessions */
- int h323_make_call(char *dest, call_details_t *cd, call_options_t *);
- int h323_clear_call(const char *, int cause);
-
- /* H.323 alerting and progress */
- int h323_send_alerting(const char *token);
- int h323_send_progress(const char *token);
- int h323_answering_call(const char *token, int);
- int h323_soft_hangup(const char *data);
- int h323_show_codec(int fd, int argc, char *argv[]);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/1.2-netsec/channels/h323/h323.conf.sample b/1.2-netsec/channels/h323/h323.conf.sample
deleted file mode 100644
index 42858ed74..000000000
--- a/1.2-netsec/channels/h323/h323.conf.sample
+++ /dev/null
@@ -1,123 +0,0 @@
-; The NuFone Network's
-; Open H.323 driver configuration
-;
-[general]
-port = 1720
-bindaddr = 1.2.3.4 ; this SHALL contain a single, valid IP address for this machine
-;tos=lowdelay
-;
-; You may specify a global default AMA flag for iaxtel calls. It must be
-; one of 'default', 'omit', 'billing', or 'documentation'. These flags
-; are used in the generation of call detail records.
-;
-;amaflags = default
-;
-; You may specify a default account for Call Detail Records in addition
-; to specifying on a per-user basis
-;
-;accountcode=lss0101
-;
-; You can fine tune codecs here using "allow" and "disallow" clauses
-; with specific codecs. Use "all" to represent all formats.
-;
-disallow=all
-;allow=all ; turns on all installed codecs
-;disallow=g723.1 ; Hm... Proprietary, don't use it...
-allow=gsm ; Always allow GSM, it's cool :)
-;
-; User-Input Mode (DTMF)
-;
-; valid entries are: rfc2833, inband
-; default is rfc2833
-;dtmfmode=rfc2833
-;
-; Default RTP Payload to send RFC2833 DTMF on. This is used to
-; interoperate with broken gateways which cannot successfully
-; negotiate a RFC2833 payload type in the TerminalCapabilitySet.
-;
-; You may also specify on either a per-peer or per-user basis below.
-;dtmfcodec=101
-;
-; Set the gatekeeper
-; DISCOVER - Find the Gk address using multicast
-; DISABLE - Disable the use of a GK
-; <IP address> or <Host name> - The acutal IP address or hostname of your GK
-;gatekeeper = DISABLE
-;
-;
-; Tell Asterisk whether or not to accept Gatekeeper
-; routed calls or not. Normally this should always
-; be set to yes, unless you want to have finer control
-; over which users are allowed access to Asterisk.
-; Default: YES
-;
-;AllowGKRouted = yes
-;
-; Optionally you can determine a user by Source IP versus its H.323 alias.
-; Default behavour is to determine user by H.323 alias.
-;UserByAlias=no
-;
-; Default context gets used in siutations where you are using
-; the GK routed model or no type=user was found. This gives you
-; the ability to either play an invalid message or to simply not
-; use user authentication at all.
-;
-;context=default
-;
-; H.323 Alias definitions
-;
-; Type 'h323' will register aliases to the endpoint
-; and Gatekeeper, if there is one.
-;
-; Example: if someone calls time@your.asterisk.box.com
-; Asterisk will send the call to the extension 'time'
-; in the context default
-;
-; [default]
-; exten => time,1,Answer
-; exten => time,2,Playback,current-time
-;
-; Keyword's 'prefix' and 'e164' are only make sense when
-; used with a gatekeeper. You can specify either a prefix
-; or E.164 this endpoint is responsible for terminating.
-;
-; Example: The H.323 alias 'det-gw' will tell the gatekeeper
-; to route any call with the prefix 1248 to this alias. Keyword
-; e164 is used when you want to specifiy a full telephone
-; number. So a call to the number 18102341212 would be
-; routed to the H.323 alias 'time'.
-;
-;[time]
-;type=h323
-;e164=18102341212
-;context=default
-;
-;[det-gw]
-;type=h323
-;prefix=1248,1313
-;context=detroit
-;
-;
-; Inbound H.323 calls from BillyBob would land in the incoming
-; context with a maximum of 4 concurrent incoming calls
-;
-;
-; Note: If keyword 'incominglimit' are omitted Asterisk will not
-; enforce any maximum number of concurrent calls.
-;
-;[BillyBob]
-;type=user
-;host=192.168.1.1
-;context=incoming
-;incominglimit=4
-;
-;
-; Outbound H.323 call to Larry using SlowStart
-;
-[Larry]
-type=peer
-host=192.168.2.1
-noFastStart=yes
-
-
-
diff --git a/1.2-netsec/channels/iax2-parser.c b/1.2-netsec/channels/iax2-parser.c
deleted file mode 100644
index 3ef80a39c..000000000
--- a/1.2-netsec/channels/iax2-parser.c
+++ /dev/null
@@ -1,951 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Implementation of Inter-Asterisk eXchange Protocol, v 2
- *
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/frame.h"
-#include "asterisk/utils.h"
-#include "asterisk/unaligned.h"
-#include "iax2.h"
-#include "iax2-parser.h"
-#include "iax2-provision.h"
-
-static int frames = 0;
-static int iframes = 0;
-static int oframes = 0;
-
-static void internaloutput(const char *str)
-{
- fputs(str, stdout);
-}
-
-static void internalerror(const char *str)
-{
- fprintf(stderr, "WARNING: %s", str);
-}
-
-static void (*outputf)(const char *str) = internaloutput;
-static void (*errorf)(const char *str) = internalerror;
-
-static void dump_addr(char *output, int maxlen, void *value, int len)
-{
- struct sockaddr_in sin;
- char iabuf[INET_ADDRSTRLEN];
- if (len == (int)sizeof(sin)) {
- memcpy(&sin, value, len);
- snprintf(output, maxlen, "IPV4 %s:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- } else {
- snprintf(output, maxlen, "Invalid Address");
- }
-}
-
-static void dump_string(char *output, int maxlen, void *value, int len)
-{
- maxlen--;
- if (maxlen > len)
- maxlen = len;
- strncpy(output, value, maxlen);
- output[maxlen] = '\0';
-}
-
-static void dump_prefs(char *output, int maxlen, void *value, int len)
-{
- struct ast_codec_pref pref;
- int total_len = 0;
-
- maxlen--;
- total_len = maxlen;
-
- if (maxlen > len)
- maxlen = len;
-
- strncpy(output, value, maxlen);
- output[maxlen] = '\0';
-
- ast_codec_pref_convert(&pref, output, total_len, 0);
- memset(output,0,total_len);
- ast_codec_pref_string(&pref, output, total_len);
-}
-
-static void dump_int(char *output, int maxlen, void *value, int len)
-{
- if (len == (int)sizeof(unsigned int))
- snprintf(output, maxlen, "%lu", (unsigned long)ntohl(get_unaligned_uint32(value)));
- else
- ast_copy_string(output, "Invalid INT", maxlen);
-}
-
-static void dump_short(char *output, int maxlen, void *value, int len)
-{
- if (len == (int)sizeof(unsigned short))
- snprintf(output, maxlen, "%d", ntohs(get_unaligned_uint16(value)));
- else
- ast_copy_string(output, "Invalid SHORT", maxlen);
-}
-
-static void dump_byte(char *output, int maxlen, void *value, int len)
-{
- if (len == (int)sizeof(unsigned char))
- snprintf(output, maxlen, "%d", *((unsigned char *)value));
- else
- ast_copy_string(output, "Invalid BYTE", maxlen);
-}
-
-static void dump_datetime(char *output, int maxlen, void *value, int len)
-{
- struct tm tm;
- unsigned long val = (unsigned long) ntohl(get_unaligned_uint32(value));
- if (len == (int)sizeof(unsigned int)) {
- tm.tm_sec = (val & 0x1f) << 1;
- tm.tm_min = (val >> 5) & 0x3f;
- tm.tm_hour = (val >> 11) & 0x1f;
- tm.tm_mday = (val >> 16) & 0x1f;
- tm.tm_mon = ((val >> 21) & 0x0f) - 1;
- tm.tm_year = ((val >> 25) & 0x7f) + 100;
- strftime(output, maxlen, "%Y-%m-%d %T", &tm);
- } else
- ast_copy_string(output, "Invalid DATETIME format!", maxlen);
-}
-
-static void dump_ipaddr(char *output, int maxlen, void *value, int len)
-{
- struct sockaddr_in sin;
- char iabuf[INET_ADDRSTRLEN];
- if (len == (int)sizeof(unsigned int)) {
- memcpy(&sin.sin_addr, value, len);
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr);
- snprintf(output, maxlen, "%s", iabuf);
- } else
- ast_copy_string(output, "Invalid IPADDR", maxlen);
-}
-
-
-static void dump_prov_flags(char *output, int maxlen, void *value, int len)
-{
- char buf[256] = "";
- if (len == (int)sizeof(unsigned int))
- snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(get_unaligned_uint32(value)),
- iax_provflags2str(buf, sizeof(buf), ntohl(get_unaligned_uint32(value))));
- else
- ast_copy_string(output, "Invalid INT", maxlen);
-}
-
-static void dump_samprate(char *output, int maxlen, void *value, int len)
-{
- char tmp[256]="";
- int sr;
- if (len == (int)sizeof(unsigned short)) {
- sr = ntohs(*((unsigned short *)value));
- if (sr & IAX_RATE_8KHZ)
- strcat(tmp, ",8khz");
- if (sr & IAX_RATE_11KHZ)
- strcat(tmp, ",11.025khz");
- if (sr & IAX_RATE_16KHZ)
- strcat(tmp, ",16khz");
- if (sr & IAX_RATE_22KHZ)
- strcat(tmp, ",22.05khz");
- if (sr & IAX_RATE_44KHZ)
- strcat(tmp, ",44.1khz");
- if (sr & IAX_RATE_48KHZ)
- strcat(tmp, ",48khz");
- if (strlen(tmp))
- ast_copy_string(output, &tmp[1], maxlen);
- else
- ast_copy_string(output, "None Specified!\n", maxlen);
- } else
- ast_copy_string(output, "Invalid SHORT", maxlen);
-
-}
-
-static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len);
-static void dump_prov(char *output, int maxlen, void *value, int len)
-{
- dump_prov_ies(output, maxlen, value, len);
-}
-
-static struct iax2_ie {
- int ie;
- char *name;
- void (*dump)(char *output, int maxlen, void *value, int len);
-} ies[] = {
- { IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string },
- { IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string },
- { IAX_IE_CALLING_ANI, "ANI", dump_string },
- { IAX_IE_CALLING_NAME, "CALLING NAME", dump_string },
- { IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string },
- { IAX_IE_USERNAME, "USERNAME", dump_string },
- { IAX_IE_PASSWORD, "PASSWORD", dump_string },
- { IAX_IE_CAPABILITY, "CAPABILITY", dump_int },
- { IAX_IE_FORMAT, "FORMAT", dump_int },
- { IAX_IE_LANGUAGE, "LANGUAGE", dump_string },
- { IAX_IE_VERSION, "VERSION", dump_short },
- { IAX_IE_ADSICPE, "ADSICPE", dump_short },
- { IAX_IE_DNID, "DNID", dump_string },
- { IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short },
- { IAX_IE_CHALLENGE, "CHALLENGE", dump_string },
- { IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string },
- { IAX_IE_RSA_RESULT, "RSA RESULT", dump_string },
- { IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr },
- { IAX_IE_REFRESH, "REFRESH", dump_short },
- { IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short },
- { IAX_IE_CALLNO, "CALL NUMBER", dump_short },
- { IAX_IE_CAUSE, "CAUSE", dump_string },
- { IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte },
- { IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short },
- { IAX_IE_AUTOANSWER, "AUTO ANSWER REQ" },
- { IAX_IE_TRANSFERID, "TRANSFER ID", dump_int },
- { IAX_IE_RDNIS, "REFERRING DNIS", dump_string },
- { IAX_IE_PROVISIONING, "PROVISIONING", dump_prov },
- { IAX_IE_AESPROVISIONING, "AES PROVISIONG" },
- { IAX_IE_DATETIME, "DATE TIME", dump_datetime },
- { IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string },
- { IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string },
- { IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short },
- { IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int },
- { IAX_IE_FWBLOCKDATA, "FW BLOCK DATA" },
- { IAX_IE_PROVVER, "PROVISIONG VER", dump_int },
- { IAX_IE_CALLINGPRES, "CALLING PRESNTN", dump_byte },
- { IAX_IE_CALLINGTON, "CALLING TYPEOFNUM", dump_byte },
- { IAX_IE_CALLINGTNS, "CALLING TRANSITNET", dump_short },
- { IAX_IE_SAMPLINGRATE, "SAMPLINGRATE", dump_samprate },
- { IAX_IE_CAUSECODE, "CAUSE CODE", dump_byte },
- { IAX_IE_ENCRYPTION, "ENCRYPTION", dump_short },
- { IAX_IE_ENCKEY, "ENCRYPTION KEY" },
- { IAX_IE_CODEC_PREFS, "CODEC_PREFS", dump_prefs },
- { IAX_IE_RR_JITTER, "RR_JITTER", dump_int },
- { IAX_IE_RR_LOSS, "RR_LOSS", dump_int },
- { IAX_IE_RR_PKTS, "RR_PKTS", dump_int },
- { IAX_IE_RR_DELAY, "RR_DELAY", dump_short },
- { IAX_IE_RR_DROPPED, "RR_DROPPED", dump_int },
- { IAX_IE_RR_OOO, "RR_OUTOFORDER", dump_int },
-};
-
-static struct iax2_ie prov_ies[] = {
- { PROV_IE_USEDHCP, "USEDHCP" },
- { PROV_IE_IPADDR, "IPADDR", dump_ipaddr },
- { PROV_IE_SUBNET, "SUBNET", dump_ipaddr },
- { PROV_IE_GATEWAY, "GATEWAY", dump_ipaddr },
- { PROV_IE_PORTNO, "BINDPORT", dump_short },
- { PROV_IE_USER, "USERNAME", dump_string },
- { PROV_IE_PASS, "PASSWORD", dump_string },
- { PROV_IE_LANG, "LANGUAGE", dump_string },
- { PROV_IE_TOS, "TYPEOFSERVICE", dump_byte },
- { PROV_IE_FLAGS, "FLAGS", dump_prov_flags },
- { PROV_IE_FORMAT, "FORMAT", dump_int },
- { PROV_IE_AESKEY, "AESKEY" },
- { PROV_IE_SERVERIP, "SERVERIP", dump_ipaddr },
- { PROV_IE_SERVERPORT, "SERVERPORT", dump_short },
- { PROV_IE_NEWAESKEY, "NEWAESKEY" },
- { PROV_IE_PROVVER, "PROV VERSION", dump_int },
- { PROV_IE_ALTSERVER, "ALTSERVERIP", dump_ipaddr },
-};
-
-const char *iax_ie2str(int ie)
-{
- int x;
- for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
- if (ies[x].ie == ie)
- return ies[x].name;
- }
- return "Unknown IE";
-}
-
-
-static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len)
-{
- int ielen;
- int ie;
- int x;
- int found;
- char interp[80];
- char tmp[256];
- if (len < 2)
- return;
- strcpy(output, "\n");
- maxlen -= strlen(output); output += strlen(output);
- while(len > 2) {
- ie = iedata[0];
- ielen = iedata[1];
- if (ielen + 2> len) {
- snprintf(tmp, (int)sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
- ast_copy_string(output, tmp, maxlen);
- maxlen -= strlen(output);
- output += strlen(output);
- return;
- }
- found = 0;
- for (x=0;x<(int)sizeof(prov_ies) / (int)sizeof(prov_ies[0]); x++) {
- if (prov_ies[x].ie == ie) {
- if (prov_ies[x].dump) {
- prov_ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
- snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", prov_ies[x].name, interp);
- ast_copy_string(output, tmp, maxlen);
- maxlen -= strlen(output); output += strlen(output);
- } else {
- if (ielen)
- snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
- else
- strcpy(interp, "Present");
- snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", prov_ies[x].name, interp);
- ast_copy_string(output, tmp, maxlen);
- maxlen -= strlen(output); output += strlen(output);
- }
- found++;
- }
- }
- if (!found) {
- snprintf(tmp, (int)sizeof(tmp), " Unknown Prov IE %03d : Present\n", ie);
- ast_copy_string(output, tmp, maxlen);
- maxlen -= strlen(output); output += strlen(output);
- }
- iedata += (2 + ielen);
- len -= (2 + ielen);
- }
-}
-
-static void dump_ies(unsigned char *iedata, int len)
-{
- int ielen;
- int ie;
- int x;
- int found;
- char interp[1024];
- char tmp[1024];
- if (len < 2)
- return;
- while(len > 2) {
- ie = iedata[0];
- ielen = iedata[1];
- if (ielen + 2> len) {
- snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
- outputf(tmp);
- return;
- }
- found = 0;
- for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
- if (ies[x].ie == ie) {
- if (ies[x].dump) {
- ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
- snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
- outputf(tmp);
- } else {
- if (ielen)
- snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
- else
- strcpy(interp, "Present");
- snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
- outputf(tmp);
- }
- found++;
- }
- }
- if (!found) {
- snprintf(tmp, (int)sizeof(tmp), " Unknown IE %03d : Present\n", ie);
- outputf(tmp);
- }
- iedata += (2 + ielen);
- len -= (2 + ielen);
- }
- outputf("\n");
-}
-
-void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen)
-{
- const char *frames[] = {
- "(0?)",
- "DTMF ",
- "VOICE ",
- "VIDEO ",
- "CONTROL",
- "NULL ",
- "IAX ",
- "TEXT ",
- "IMAGE ",
- "HTML ",
- "CNG " };
- const char *iaxs[] = {
- "(0?)",
- "NEW ",
- "PING ",
- "PONG ",
- "ACK ",
- "HANGUP ",
- "REJECT ",
- "ACCEPT ",
- "AUTHREQ",
- "AUTHREP",
- "INVAL ",
- "LAGRQ ",
- "LAGRP ",
- "REGREQ ",
- "REGAUTH",
- "REGACK ",
- "REGREJ ",
- "REGREL ",
- "VNAK ",
- "DPREQ ",
- "DPREP ",
- "DIAL ",
- "TXREQ ",
- "TXCNT ",
- "TXACC ",
- "TXREADY",
- "TXREL ",
- "TXREJ ",
- "QUELCH ",
- "UNQULCH",
- "POKE ",
- "PAGE ",
- "MWI ",
- "UNSPRTD",
- "TRANSFR",
- "PROVISN",
- "FWDWNLD",
- "FWDATA "
- };
- const char *cmds[] = {
- "(0?)",
- "HANGUP ",
- "RING ",
- "RINGING",
- "ANSWER ",
- "BUSY ",
- "TKOFFHK",
- "OFFHOOK" };
- struct ast_iax2_full_hdr *fh;
- char retries[20];
- char class2[20];
- char subclass2[20];
- const char *class;
- const char *subclass;
- char *dir;
- char tmp[512];
- char iabuf[INET_ADDRSTRLEN];
-
- switch(rx) {
- case 0:
- dir = "Tx";
- break;
- case 2:
- dir = "TE";
- break;
- case 3:
- dir = "RD";
- break;
- default:
- dir = "Rx";
- break;
- }
- if (f) {
- fh = f->data;
- snprintf(retries, sizeof(retries), "%03d", f->retries);
- } else {
- fh = fhi;
- if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
- strcpy(retries, "Yes");
- else
- strcpy(retries, " No");
- }
- if (!(ntohs(fh->scallno) & IAX_FLAG_FULL)) {
- /* Don't mess with mini-frames */
- return;
- }
- if (fh->type >= (int)sizeof(frames)/(int)sizeof(frames[0])) {
- snprintf(class2, sizeof(class2), "(%d?)", fh->type);
- class = class2;
- } else {
- class = frames[(int)fh->type];
- }
- if (fh->type == AST_FRAME_DTMF) {
- sprintf(subclass2, "%c", fh->csub);
- subclass = subclass2;
- } else if (fh->type == AST_FRAME_IAX) {
- if (fh->csub >= (int)sizeof(iaxs)/(int)sizeof(iaxs[0])) {
- snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
- subclass = subclass2;
- } else {
- subclass = iaxs[(int)fh->csub];
- }
- } else if (fh->type == AST_FRAME_CONTROL) {
- if (fh->csub >= (int)sizeof(cmds)/(int)sizeof(cmds[0])) {
- snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
- subclass = subclass2;
- } else {
- subclass = cmds[(int)fh->csub];
- }
- } else {
- snprintf(subclass2, sizeof(subclass2), "%d", fh->csub);
- subclass = subclass2;
- }
- snprintf(tmp, sizeof(tmp),
- "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
- dir,
- retries, fh->oseqno, fh->iseqno, class, subclass);
- outputf(tmp);
- snprintf(tmp, sizeof(tmp),
- " Timestamp: %05lums SCall: %5.5d DCall: %5.5d [%s:%d]\n",
- (unsigned long)ntohl(fh->ts),
- ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port));
- outputf(tmp);
- if (fh->type == AST_FRAME_IAX)
- dump_ies(fh->iedata, datalen);
-}
-
-int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, void *data, int datalen)
-{
- char tmp[256];
- if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
- snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
- errorf(tmp);
- return -1;
- }
- ied->buf[ied->pos++] = ie;
- ied->buf[ied->pos++] = datalen;
- memcpy(ied->buf + ied->pos, data, datalen);
- ied->pos += datalen;
- return 0;
-}
-
-int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
-{
- return iax_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
-}
-
-int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
-{
- unsigned int newval;
- newval = htonl(value);
- return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
-}
-
-int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
-{
- unsigned short newval;
- newval = htons(value);
- return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
-}
-
-int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, char *str)
-{
- return iax_ie_append_raw(ied, ie, str, strlen(str));
-}
-
-int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
-{
- return iax_ie_append_raw(ied, ie, &dat, 1);
-}
-
-int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)
-{
- return iax_ie_append_raw(ied, ie, NULL, 0);
-}
-
-void iax_set_output(void (*func)(const char *))
-{
- outputf = func;
-}
-
-void iax_set_error(void (*func)(const char *))
-{
- errorf = func;
-}
-
-int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen)
-{
- /* Parse data into information elements */
- int len;
- int ie;
- char tmp[256];
- memset(ies, 0, (int)sizeof(struct iax_ies));
- ies->msgcount = -1;
- ies->firmwarever = -1;
- ies->calling_ton = -1;
- ies->calling_tns = -1;
- ies->calling_pres = -1;
- ies->samprate = IAX_RATE_8KHZ;
- while(datalen >= 2) {
- ie = data[0];
- len = data[1];
- if (len > datalen - 2) {
- errorf("Information element length exceeds message size\n");
- return -1;
- }
- switch(ie) {
- case IAX_IE_CALLED_NUMBER:
- ies->called_number = (char *)data + 2;
- break;
- case IAX_IE_CALLING_NUMBER:
- ies->calling_number = (char *)data + 2;
- break;
- case IAX_IE_CALLING_ANI:
- ies->calling_ani = (char *)data + 2;
- break;
- case IAX_IE_CALLING_NAME:
- ies->calling_name = (char *)data + 2;
- break;
- case IAX_IE_CALLED_CONTEXT:
- ies->called_context = (char *)data + 2;
- break;
- case IAX_IE_USERNAME:
- ies->username = (char *)data + 2;
- break;
- case IAX_IE_PASSWORD:
- ies->password = (char *)data + 2;
- break;
- case IAX_IE_CODEC_PREFS:
- ies->codec_prefs = (char *)data + 2;
- break;
- case IAX_IE_CAPABILITY:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else
- ies->capability = ntohl(get_unaligned_uint32(data + 2));
- break;
- case IAX_IE_FORMAT:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else
- ies->format = ntohl(get_unaligned_uint32(data + 2));
- break;
- case IAX_IE_LANGUAGE:
- ies->language = (char *)data + 2;
- break;
- case IAX_IE_VERSION:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->version = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_ADSICPE:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->adsicpe = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_SAMPLINGRATE:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->samprate = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_DNID:
- ies->dnid = (char *)data + 2;
- break;
- case IAX_IE_RDNIS:
- ies->rdnis = (char *)data + 2;
- break;
- case IAX_IE_AUTHMETHODS:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->authmethods = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_ENCRYPTION:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting encryption to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->encmethods = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_CHALLENGE:
- ies->challenge = (char *)data + 2;
- break;
- case IAX_IE_MD5_RESULT:
- ies->md5_result = (char *)data + 2;
- break;
- case IAX_IE_RSA_RESULT:
- ies->rsa_result = (char *)data + 2;
- break;
- case IAX_IE_APPARENT_ADDR:
- ies->apparent_addr = ((struct sockaddr_in *)(data + 2));
- break;
- case IAX_IE_REFRESH:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting refresh to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->refresh = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_DPSTATUS:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting dpstatus to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->dpstatus = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_CALLNO:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting callno to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->callno = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_CAUSE:
- ies->cause = (char *)data + 2;
- break;
- case IAX_IE_CAUSECODE:
- if (len != 1) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
- errorf(tmp);
- } else {
- ies->causecode = data[2];
- }
- break;
- case IAX_IE_IAX_UNKNOWN:
- if (len == 1)
- ies->iax_unknown = data[2];
- else {
- snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
- errorf(tmp);
- }
- break;
- case IAX_IE_MSGCOUNT:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->msgcount = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_AUTOANSWER:
- ies->autoanswer = 1;
- break;
- case IAX_IE_MUSICONHOLD:
- ies->musiconhold = 1;
- break;
- case IAX_IE_TRANSFERID:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else
- ies->transferid = ntohl(get_unaligned_uint32(data + 2));
- break;
- case IAX_IE_DATETIME:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else
- ies->datetime = ntohl(get_unaligned_uint32(data + 2));
- break;
- case IAX_IE_FIRMWAREVER:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->firmwarever = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_DEVICETYPE:
- ies->devicetype = (char *)data + 2;
- break;
- case IAX_IE_SERVICEIDENT:
- ies->serviceident = (char *)data + 2;
- break;
- case IAX_IE_FWBLOCKDESC:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else
- ies->fwdesc = ntohl(get_unaligned_uint32(data + 2));
- break;
- case IAX_IE_FWBLOCKDATA:
- ies->fwdata = data + 2;
- ies->fwdatalen = len;
- break;
- case IAX_IE_ENCKEY:
- ies->enckey = data + 2;
- ies->enckeylen = len;
- break;
- case IAX_IE_PROVVER:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else {
- ies->provverpres = 1;
- ies->provver = ntohl(get_unaligned_uint32(data + 2));
- }
- break;
- case IAX_IE_CALLINGPRES:
- if (len == 1)
- ies->calling_pres = data[2];
- else {
- snprintf(tmp, (int)sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
- errorf(tmp);
- }
- break;
- case IAX_IE_CALLINGTON:
- if (len == 1)
- ies->calling_ton = data[2];
- else {
- snprintf(tmp, (int)sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
- errorf(tmp);
- }
- break;
- case IAX_IE_CALLINGTNS:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->calling_tns = ntohs(get_unaligned_uint16(data + 2));
- break;
- case IAX_IE_RR_JITTER:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else {
- ies->rr_jitter = ntohl(get_unaligned_uint32(data + 2));
- }
- break;
- case IAX_IE_RR_LOSS:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else {
- ies->rr_loss = ntohl(get_unaligned_uint32(data + 2));
- }
- break;
- case IAX_IE_RR_PKTS:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else {
- ies->rr_pkts = ntohl(get_unaligned_uint32(data + 2));
- }
- break;
- case IAX_IE_RR_DELAY:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else {
- ies->rr_delay = ntohs(get_unaligned_uint16(data + 2));
- }
- break;
- case IAX_IE_RR_DROPPED:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else {
- ies->rr_dropped = ntohl(get_unaligned_uint32(data + 2));
- }
- break;
- case IAX_IE_RR_OOO:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else {
- ies->rr_ooo = ntohl(get_unaligned_uint32(data + 2));
- }
- break;
- default:
- snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
- outputf(tmp);
- }
- /* Overwrite information element with 0, to null terminate previous portion */
- data[0] = 0;
- datalen -= (len + 2);
- data += (len + 2);
- }
- /* Null-terminate last field */
- *data = '\0';
- if (datalen) {
- errorf("Invalid information element contents, strange boundary\n");
- return -1;
- }
- return 0;
-}
-
-void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f)
-{
- fr->af.frametype = f->frametype;
- fr->af.subclass = f->subclass;
- fr->af.mallocd = 0; /* Our frame is static relative to the container */
- fr->af.datalen = f->datalen;
- fr->af.samples = f->samples;
- fr->af.offset = AST_FRIENDLY_OFFSET;
- fr->af.src = f->src;
- fr->af.delivery.tv_sec = 0;
- fr->af.delivery.tv_usec = 0;
- fr->af.data = fr->afdata;
- if (fr->af.datalen) {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- /* We need to byte-swap slinear samples from network byte order */
- if ((fr->af.frametype == AST_FRAME_VOICE) && (fr->af.subclass == AST_FORMAT_SLINEAR)) {
- ast_swapcopy_samples(fr->af.data, f->data, fr->af.samples);
- } else
-#endif
- memcpy(fr->af.data, f->data, fr->af.datalen);
- }
-}
-
-struct iax_frame *iax_frame_new(int direction, int datalen)
-{
- struct iax_frame *fr;
- fr = malloc((int)sizeof(struct iax_frame) + datalen);
- if (fr) {
- fr->direction = direction;
- fr->retrans = -1;
- frames++;
- if (fr->direction == DIRECTION_INGRESS)
- iframes++;
- else
- oframes++;
- }
- return fr;
-}
-
-void iax_frame_free(struct iax_frame *fr)
-{
- /* Note: does not remove from scheduler! */
- if (fr->direction == DIRECTION_INGRESS)
- iframes--;
- else if (fr->direction == DIRECTION_OUTGRESS)
- oframes--;
- else {
- errorf("Attempt to double free frame detected\n");
- return;
- }
- fr->direction = 0;
- free(fr);
- frames--;
-}
-
-int iax_get_frames(void) { return frames; }
-int iax_get_iframes(void) { return iframes; }
-int iax_get_oframes(void) { return oframes; }
diff --git a/1.2-netsec/channels/iax2-parser.h b/1.2-netsec/channels/iax2-parser.h
deleted file mode 100644
index dd90682c2..000000000
--- a/1.2-netsec/channels/iax2-parser.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Asterisk -- A telephony toolkit for Linux.
- *
- * Implementation of Inter-Asterisk eXchange
- *
- * Copyright (C) 2003, Digium
- *
- * Mark Spencer <markster@digium.com>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-/*!\file
- * \brief Implementation of the IAX2 protocol
- */
-
-#ifndef _IAX2_PARSER_H
-#define _IAX2_PARSER_H
-
-struct iax_ies {
- char *called_number;
- char *calling_number;
- char *calling_ani;
- char *calling_name;
- int calling_ton;
- int calling_tns;
- int calling_pres;
- char *called_context;
- char *username;
- char *password;
- unsigned int capability;
- unsigned int format;
- char *codec_prefs;
- char *language;
- int version;
- unsigned short adsicpe;
- char *dnid;
- char *rdnis;
- unsigned int authmethods;
- unsigned int encmethods;
- char *challenge;
- char *md5_result;
- char *rsa_result;
- struct sockaddr_in *apparent_addr;
- unsigned short refresh;
- unsigned short dpstatus;
- unsigned short callno;
- char *cause;
- unsigned char causecode;
- unsigned char iax_unknown;
- int msgcount;
- int autoanswer;
- int musiconhold;
- unsigned int transferid;
- unsigned int datetime;
- char *devicetype;
- char *serviceident;
- int firmwarever;
- unsigned int fwdesc;
- unsigned char *fwdata;
- unsigned char fwdatalen;
- unsigned char *enckey;
- unsigned char enckeylen;
- unsigned int provver;
- unsigned short samprate;
- int provverpres;
- unsigned int rr_jitter;
- unsigned int rr_loss;
- unsigned int rr_pkts;
- unsigned short rr_delay;
- unsigned int rr_dropped;
- unsigned int rr_ooo;
-};
-
-#define DIRECTION_INGRESS 1
-#define DIRECTION_OUTGRESS 2
-
-struct iax_frame {
-#ifdef LIBIAX
- struct iax_session *session;
- struct iax_event *event;
-#else
- int sockfd;
-#endif
-
- /* /Our/ call number */
- unsigned short callno;
- /* /Their/ call number */
- unsigned short dcallno;
- /* Start of raw frame (outgoing only) */
- void *data;
- /* Length of frame (outgoing only) */
- int datalen;
- /* How many retries so far? */
- int retries;
- /* Outgoing relative timestamp (ms) */
- unsigned int ts;
- /* How long to wait before retrying */
- int retrytime;
- /* Are we received out of order? */
- int outoforder;
- /* Have we been sent at all yet? */
- int sentyet;
- /* Outgoing Packet sequence number */
- int oseqno;
- /* Next expected incoming packet sequence number */
- int iseqno;
- /* Non-zero if should be sent to transfer peer */
- int transfer;
- /* Non-zero if this is the final message */
- int final;
- /* Ingress or outgres */
- int direction;
- /* Retransmission ID */
- int retrans;
- /* Easy linking */
- struct iax_frame *next;
- struct iax_frame *prev;
- /* Actual, isolated frame header */
- struct ast_frame af;
- unsigned char unused[AST_FRIENDLY_OFFSET];
- unsigned char afdata[0]; /* Data for frame */
-};
-
-struct iax_ie_data {
- unsigned char buf[1024];
- int pos;
-};
-
-/* Choose a different function for output */
-extern void iax_set_output(void (*output)(const char *data));
-/* Choose a different function for errors */
-extern void iax_set_error(void (*output)(const char *data));
-extern void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen);
-
-extern const char *iax_ie2str(int ie);
-
-extern int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, void *data, int datalen);
-extern int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, struct sockaddr_in *sin);
-extern int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value);
-extern int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value);
-extern int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, char *str);
-extern int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat);
-extern int iax_ie_append(struct iax_ie_data *ied, unsigned char ie);
-extern int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen);
-
-extern int iax_get_frames(void);
-extern int iax_get_iframes(void);
-extern int iax_get_oframes(void);
-
-extern void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f);
-extern struct iax_frame *iax_frame_new(int direction, int datalen);
-extern void iax_frame_free(struct iax_frame *fr);
-#endif
diff --git a/1.2-netsec/channels/iax2-provision.c b/1.2-netsec/channels/iax2-provision.c
deleted file mode 100644
index c1b6f4b3d..000000000
--- a/1.2-netsec/channels/iax2-provision.c
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief IAX Provisioning Protocol
- *
- */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <sys/socket.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/cli.h"
-#include "asterisk/lock.h"
-#include "asterisk/frame.h"
-#include "asterisk/options.h"
-#include "asterisk/md5.h"
-#include "asterisk/astdb.h"
-#include "asterisk/utils.h"
-#include "iax2.h"
-#include "iax2-provision.h"
-#include "iax2-parser.h"
-
-#ifndef IPTOS_MINCOST
-#define IPTOS_MINCOST 0x02
-#endif
-
-static int provinit = 0;
-
-struct iax_template {
- int dead;
- char name[80];
- char src[80];
- struct iax_template *next;
- char user[20];
- char pass[20];
- char lang[10];
- unsigned short port;
- unsigned int server;
- unsigned short serverport;
- unsigned int altserver;
- unsigned int flags;
- unsigned int format;
- int tos;
-} *templates;
-
-static struct iax_flag {
- char *name;
- int value;
-} iax_flags[] = {
- { "register", PROV_FLAG_REGISTER },
- { "secure", PROV_FLAG_SECURE },
- { "heartbeat", PROV_FLAG_HEARTBEAT },
- { "debug", PROV_FLAG_DEBUG },
- { "disablecid", PROV_FLAG_DIS_CALLERID },
- { "disablecw", PROV_FLAG_DIS_CALLWAIT },
- { "disablecidcw", PROV_FLAG_DIS_CIDCW },
- { "disable3way", PROV_FLAG_DIS_THREEWAY },
-};
-
-char *iax_provflags2str(char *buf, int buflen, unsigned int flags)
-{
- int x;
- if (!buf || buflen < 1) {
- return(NULL);
- }
- buf[0] = '\0';
- for (x=0;x<sizeof(iax_flags) / sizeof(iax_flags[0]); x++) {
- if (flags & iax_flags[x].value){
- strncat(buf, iax_flags[x].name, buflen - strlen(buf) - 1);
- strncat(buf, ",", buflen - strlen(buf) - 1);
- }
- }
- if (strlen(buf))
- buf[strlen(buf) - 1] = '\0';
- else
- strncpy(buf, "none", buflen - 1);
- return buf;
-}
-
-static unsigned int iax_str2flags(const char *buf)
-{
- int x;
- int len;
- int found;
- unsigned int flags = 0;
- char *e;
- while(buf && *buf) {
- e = strchr(buf, ',');
- if (e)
- len = e - buf;
- else
- len = 0;
- found = 0;
- for (x=0;x<sizeof(iax_flags) / sizeof(iax_flags[0]); x++) {
- if ((len && !strncasecmp(iax_flags[x].name, buf, len)) ||
- (!len && !strcasecmp(iax_flags[x].name, buf))) {
- flags |= iax_flags[x].value;
- break;
- }
- }
- if (e) {
- buf = e + 1;
- while(*buf && (*buf < 33))
- buf++;
- } else
- break;
- }
- return flags;
-}
-AST_MUTEX_DEFINE_STATIC(provlock);
-
-static struct iax_template *iax_template_find(const char *s, int allowdead)
-{
- struct iax_template *cur;
- cur = templates;
- while(cur) {
- if (!strcasecmp(s, cur->name)) {
- if (!allowdead && cur->dead)
- cur = NULL;
- break;
- }
- cur = cur->next;
- }
- return cur;
-}
-
-char *iax_prov_complete_template(char *line, char *word, int pos, int state)
-{
- struct iax_template *c;
- int which=0;
- char *ret;
- ast_mutex_lock(&provlock);
- c = templates;
- while(c) {
- if (!strncasecmp(word, c->name, strlen(word))) {
- if (++which > state)
- break;
- }
- c = c->next;
- }
- if (c) {
- ret = strdup(c->name);
- } else
- ret = NULL;
- ast_mutex_unlock(&provlock);
- return ret;
-}
-
-static unsigned int prov_ver_calc(struct iax_ie_data *provdata)
-{
- struct MD5Context md5;
- unsigned int tmp[4];
- MD5Init(&md5);
- MD5Update(&md5, provdata->buf, provdata->pos);
- MD5Final((unsigned char *)tmp, &md5);
- return tmp[0] ^ tmp[1] ^ tmp[2] ^ tmp[3];
-}
-
-int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
-{
- struct iax_template *cur;
- unsigned int sig;
- char tmp[40];
- memset(provdata, 0, sizeof(*provdata));
- ast_mutex_lock(&provlock);
- cur = iax_template_find(template, 1);
- /* If no match, try searching for '*' */
- if (!cur)
- cur = iax_template_find("*", 1);
- if (cur) {
- /* found it -- add information elements as appropriate */
- if (force || strlen(cur->user))
- iax_ie_append_str(provdata, PROV_IE_USER, cur->user);
- if (force || strlen(cur->pass))
- iax_ie_append_str(provdata, PROV_IE_PASS, cur->pass);
- if (force || strlen(cur->lang))
- iax_ie_append_str(provdata, PROV_IE_LANG, cur->lang);
- if (force || cur->port)
- iax_ie_append_short(provdata, PROV_IE_PORTNO, cur->port);
- if (force || cur->server)
- iax_ie_append_int(provdata, PROV_IE_SERVERIP, cur->server);
- if (force || cur->serverport)
- iax_ie_append_short(provdata, PROV_IE_SERVERPORT, cur->serverport);
- if (force || cur->altserver)
- iax_ie_append_int(provdata, PROV_IE_ALTSERVER, cur->altserver);
- if (force || cur->flags)
- iax_ie_append_int(provdata, PROV_IE_FLAGS, cur->flags);
- if (force || cur->format)
- iax_ie_append_int(provdata, PROV_IE_FORMAT, cur->format);
- if (force || cur->tos)
- iax_ie_append_byte(provdata, PROV_IE_TOS, cur->tos);
-
- /* Calculate checksum of message so far */
- sig = prov_ver_calc(provdata);
- if (signature)
- *signature = sig;
- /* Store signature */
- iax_ie_append_int(provdata, PROV_IE_PROVVER, sig);
- /* Cache signature for later verification so we need not recalculate all this */
- snprintf(tmp, sizeof(tmp), "v0x%08x", sig);
- ast_db_put("iax/provisioning/cache", template, tmp);
- } else
- ast_db_put("iax/provisioning/cache", template, "u");
- ast_mutex_unlock(&provlock);
- return cur ? 0 : -1;
-}
-
-int iax_provision_version(unsigned int *version, const char *template, int force)
-{
- char tmp[80] = "";
- struct iax_ie_data ied;
- int ret=0;
- memset(&ied, 0, sizeof(ied));
-
- ast_mutex_lock(&provlock);
- ast_db_get("iax/provisioning/cache", template, tmp, sizeof(tmp));
- if (sscanf(tmp, "v%x", version) != 1) {
- if (strcmp(tmp, "u")) {
- ret = iax_provision_build(&ied, version, template, force);
- if (ret)
- ast_log(LOG_DEBUG, "Unable to create provisioning packet for '%s'\n", template);
- } else
- ret = -1;
- } else if (option_debug)
- ast_log(LOG_DEBUG, "Retrieved cached version '%s' = '%08x'\n", tmp, *version);
- ast_mutex_unlock(&provlock);
- return ret;
-}
-
-static int iax_template_parse(struct iax_template *cur, struct ast_config *cfg, char *s, char *def)
-{
- struct ast_variable *v;
- int foundportno = 0;
- int foundserverportno = 0;
- int x;
- struct in_addr ia;
- struct hostent *hp;
- struct ast_hostent h;
- struct iax_template *src, tmp;
- char *t;
- if (def) {
- t = ast_variable_retrieve(cfg, s ,"template");
- src = NULL;
- if (t && strlen(t)) {
- src = iax_template_find(t, 0);
- if (!src)
- ast_log(LOG_WARNING, "Unable to find base template '%s' for creating '%s'. Trying '%s'\n", t, s, def);
- else
- def = t;
- }
- if (!src) {
- src = iax_template_find(def, 0);
- if (!src)
- ast_log(LOG_WARNING, "Unable to locate default base template '%s' for creating '%s', omitting.", def, s);
- }
- if (!src)
- return -1;
- ast_mutex_lock(&provlock);
- /* Backup old data */
- memcpy(&tmp, cur, sizeof(tmp));
- /* Restore from src */
- memcpy(cur, src, sizeof(tmp));
- /* Restore important headers */
- memcpy(cur->name, tmp.name, sizeof(cur->name));
- cur->dead = tmp.dead;
- cur->next = tmp.next;
- ast_mutex_unlock(&provlock);
- }
- if (def)
- strncpy(cur->src, def, sizeof(cur->src) - 1);
- else
- cur->src[0] = '\0';
- v = ast_variable_browse(cfg, s);
- while(v) {
- if (!strcasecmp(v->name, "port") || !strcasecmp(v->name, "serverport")) {
- if ((sscanf(v->value, "%d", &x) == 1) && (x > 0) && (x < 65535)) {
- if (!strcasecmp(v->name, "port")) {
- cur->port = x;
- foundportno = 1;
- } else {
- cur->serverport = x;
- foundserverportno = 1;
- }
- } else
- ast_log(LOG_WARNING, "Ignoring invalid %s '%s' for '%s' at line %d\n", v->name, v->value, s, v->lineno);
- } else if (!strcasecmp(v->name, "server") || !strcasecmp(v->name, "altserver")) {
- hp = ast_gethostbyname(v->value, &h);
- if (hp) {
- memcpy(&ia, hp->h_addr, sizeof(ia));
- if (!strcasecmp(v->name, "server"))
- cur->server = ntohl(ia.s_addr);
- else
- cur->altserver = ntohl(ia.s_addr);
- } else
- ast_log(LOG_WARNING, "Ignoring invalid %s '%s' for '%s' at line %d\n", v->name, v->value, s, v->lineno);
- } else if (!strcasecmp(v->name, "codec")) {
- if ((x = ast_getformatbyname(v->value)) > 0) {
- cur->format = x;
- } else
- ast_log(LOG_WARNING, "Ignoring invalid codec '%s' for '%s' at line %d\n", v->value, s, v->lineno);
- } else if (!strcasecmp(v->name, "tos")) {
- if (sscanf(v->value, "%d", &x) == 1)
- cur->tos = x & 0xff;
- else if (!strcasecmp(v->value, "lowdelay"))
- cur->tos = IPTOS_LOWDELAY;
- else if (!strcasecmp(v->value, "throughput"))
- cur->tos = IPTOS_THROUGHPUT;
- else if (!strcasecmp(v->value, "reliability"))
- cur->tos = IPTOS_RELIABILITY;
- else if (!strcasecmp(v->value, "mincost"))
- cur->tos = IPTOS_MINCOST;
- else if (!strcasecmp(v->value, "none"))
- cur->tos = 0;
- else
- ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
- } else if (!strcasecmp(v->name, "user")) {
- strncpy(cur->user, v->value, sizeof(cur->user) - 1);
- if (strcmp(cur->user, v->value))
- ast_log(LOG_WARNING, "Truncating username from '%s' to '%s' for '%s' at line %d\n", v->value, cur->user, s, v->lineno);
- } else if (!strcasecmp(v->name, "pass")) {
- strncpy(cur->pass, v->value, sizeof(cur->pass) - 1);
- if (strcmp(cur->pass, v->value))
- ast_log(LOG_WARNING, "Truncating password from '%s' to '%s' for '%s' at line %d\n", v->value, cur->pass, s, v->lineno);
- } else if (!strcasecmp(v->name, "language")) {
- strncpy(cur->lang, v->value, sizeof(cur->lang) - 1);
- if (strcmp(cur->lang, v->value))
- ast_log(LOG_WARNING, "Truncating language from '%s' to '%s' for '%s' at line %d\n", v->value, cur->lang, s, v->lineno);
- } else if (!strcasecmp(v->name, "flags")) {
- cur->flags = iax_str2flags(v->value);
- } else if (!strncasecmp(v->name, "flags", 5) && strchr(v->name, '+')) {
- cur->flags |= iax_str2flags(v->value);
- } else if (!strncasecmp(v->name, "flags", 5) && strchr(v->name, '-')) {
- cur->flags &= ~iax_str2flags(v->value);
- } else if (strcasecmp(v->name, "template")) {
- ast_log(LOG_WARNING, "Unknown keyword '%s' in definition of '%s' at line %d\n", v->name, s, v->lineno);
- }
- v = v->next;
- }
- if (!foundportno)
- cur->port = IAX_DEFAULT_PORTNO;
- if (!foundserverportno)
- cur->serverport = IAX_DEFAULT_PORTNO;
- return 0;
-}
-
-static int iax_process_template(struct ast_config *cfg, char *s, char *def)
-{
- /* Find an already existing one if there */
- struct iax_template *cur;
- int mallocd = 0;
- cur = templates;
- while(cur) {
- if (!strcasecmp(cur->name, s))
- break;
- cur = cur->next;
- }
- if (!cur) {
- mallocd = 1;
- cur = malloc(sizeof(struct iax_template));
- if (!cur) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- return -1;
- }
- /* Initialize entry */
- memset(cur, 0, sizeof(*cur));
- strncpy(cur->name, s, sizeof(cur->name) - 1);
- cur->dead = 1;
- }
- if (!iax_template_parse(cur, cfg, s, def))
- cur->dead = 0;
-
- /* Link if we're mallocd */
- if (mallocd) {
- ast_mutex_lock(&provlock);
- cur->next = templates;
- templates = cur;
- ast_mutex_unlock(&provlock);
- }
- return 0;
-}
-
-static char show_provisioning_usage[] =
-"Usage: iax show provisioning [template]\n"
-" Lists all known IAX provisioning templates or a\n"
-" specific one if specified.\n";
-
-static const char *ifthere(const char *s)
-{
- if (strlen(s))
- return s;
- else
- return "<unspecified>";
-}
-
-static const char *iax_server(char *a, int alen, unsigned int addr)
-{
- struct in_addr ia;
- if (!addr)
- return "<unspecified>";
- ia.s_addr = htonl(addr);
- return ast_inet_ntoa(a, alen, ia);
-}
-
-
-static int iax_show_provisioning(int fd, int argc, char *argv[])
-{
- struct iax_template *cur;
- char iabuf[80]; /* Has to be big enough for 'flags' too */
- int found = 0;
- if ((argc != 3) && (argc != 4))
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&provlock);
- for (cur = templates;cur;cur = cur->next) {
- if ((argc == 3) || (!strcasecmp(argv[3], cur->name))) {
- if (found) ast_cli(fd, "\n");
- ast_cli(fd, "== %s ==\n", cur->name);
- ast_cli(fd, "Base Templ: %s\n", strlen(cur->src) ? cur->src : "<none>");
- ast_cli(fd, "Username: %s\n", ifthere(cur->user));
- ast_cli(fd, "Secret: %s\n", ifthere(cur->pass));
- ast_cli(fd, "Language: %s\n", ifthere(cur->lang));
- ast_cli(fd, "Bind Port: %d\n", cur->port);
- ast_cli(fd, "Server: %s\n", iax_server(iabuf, sizeof(iabuf), cur->server));
- ast_cli(fd, "Server Port: %d\n", cur->serverport);
- ast_cli(fd, "Alternate: %s\n", iax_server(iabuf, sizeof(iabuf), cur->altserver));
- ast_cli(fd, "Flags: %s\n", iax_provflags2str(iabuf, sizeof(iabuf), cur->flags));
- ast_cli(fd, "Format: %s\n", ast_getformatname(cur->format));
- ast_cli(fd, "TOS: %d\n", cur->tos);
- found++;
- }
- }
- ast_mutex_unlock(&provlock);
- if (!found) {
- if (argc == 3)
- ast_cli(fd, "No provisioning templates found\n");
- else
- ast_cli(fd, "No provisioning template matching '%s' found\n", argv[3]);
- }
- return RESULT_SUCCESS;
-}
-
-static struct ast_cli_entry cli_show_provisioning =
- { { "iax2", "show", "provisioning", NULL }, iax_show_provisioning, "Show iax provisioning", show_provisioning_usage, iax_prov_complete_template };
-
-static int iax_provision_init(void)
-{
- ast_cli_register(&cli_show_provisioning);
- provinit = 1;
- return 0;
-}
-
-int iax_provision_unload(void)
-{
- provinit = 0;
- ast_cli_unregister(&cli_show_provisioning);
- return 0;
-}
-
-int iax_provision_reload(void)
-{
- struct ast_config *cfg;
- struct iax_template *cur, *prev, *next;
- char *cat;
- int found = 0;
- if (!provinit)
- iax_provision_init();
- /* Mark all as dead. No need for locking */
- cur = templates;
- while(cur) {
- cur->dead = 1;
- cur = cur->next;
- }
- cfg = ast_config_load("iaxprov.conf");
- if (cfg) {
- /* Load as appropriate */
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (strcasecmp(cat, "general")) {
- iax_process_template(cfg, cat, found ? "default" : NULL);
- found++;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Loaded provisioning template '%s'\n", cat);
- }
- cat = ast_category_browse(cfg, cat);
- }
- ast_config_destroy(cfg);
- } else
- ast_log(LOG_NOTICE, "No IAX provisioning configuration found, IAX provisioning disabled.\n");
- ast_mutex_lock(&provlock);
- /* Drop dead entries while locked */
- prev = NULL;
- cur = templates;
- while(cur) {
- next = cur->next;
- if (cur->dead) {
- if (prev)
- prev->next = next;
- else
- templates = next;
- free(cur);
- } else
- prev = cur;
- cur = next;
- }
- ast_mutex_unlock(&provlock);
- /* Purge cached signature DB entries */
- ast_db_deltree("iax/provisioning/cache", NULL);
- return 0;
-
-}
diff --git a/1.2-netsec/channels/iax2-provision.h b/1.2-netsec/channels/iax2-provision.h
deleted file mode 100644
index 343341fa3..000000000
--- a/1.2-netsec/channels/iax2-provision.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * IAX Provisioning Protocol
- *
- * Sub-information elements
- *
- * Copyright (C) 2003, Digium
- *
- * Mark Spencer <markster@digium.com>
- *
- */
-
-/*! \file
- * \brief IAX2 Provisioning protocol
- */
-
-#include "iax2-parser.h"
-
-#define PROV_IE_USEDHCP 1 /* Presense only */
-#define PROV_IE_IPADDR 2 /* 32-bit */
-#define PROV_IE_SUBNET 3 /* 32-bit */
-#define PROV_IE_GATEWAY 4 /* 32-bit */
-#define PROV_IE_PORTNO 5 /* 16-bit */
-#define PROV_IE_USER 6 /* < 20 bytes */
-#define PROV_IE_PASS 7 /* < 20 bytes */
-#define PROV_IE_SERVERUSER 8 /* < 20 bytes */
-#define PROV_IE_SERVERPASS 9 /* < 20 bytes */
-#define PROV_IE_LANG 10 /* < 10 bytes */
-#define PROV_IE_TOS 11 /* 8-bits */
-#define PROV_IE_FLAGS 12 /* 32-bits */
-#define PROV_IE_FORMAT 13 /* 32-bits */
-#define PROV_IE_AESKEY 14 /* 128-bits */
-#define PROV_IE_SERVERIP 15 /* 32-bits */
-#define PROV_IE_SERVERPORT 16 /* 16-bits */
-#define PROV_IE_NEWAESKEY 17 /* 128-bits */
-#define PROV_IE_PROVVER 18 /* 32-bits */
-#define PROV_IE_ALTSERVER 19 /* 32-bits */
-
-#define PROV_FLAG_REGISTER (1 << 0)
-#define PROV_FLAG_SECURE (1 << 1)
-#define PROV_FLAG_HEARTBEAT (1 << 2)
-#define PROV_FLAG_DEBUG (1 << 3)
-
-#define PROV_FLAG_DIS_CALLERID (1 << 4) /* Caller-ID Disabled */
-#define PROV_FLAG_DIS_CALLWAIT (1 << 5) /* Caller-ID / Call Waiting Disable */
-#define PROV_FLAG_DIS_CIDCW (1 << 6) /* CID/CW Disabled */
-#define PROV_FLAG_DIS_THREEWAY (1 << 7) /* Three-way calling, transfer disabled */
-
-extern char *iax_provflags2str(char *buf, int buflen, unsigned int flags);
-extern int iax_provision_reload(void);
-extern int iax_provision_unload(void);
-extern int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force);
-extern int iax_provision_version(unsigned int *signature, const char *template, int force);
-extern char *iax_prov_complete_template(char *line, char *word, int pos, int state);
diff --git a/1.2-netsec/channels/iax2.h b/1.2-netsec/channels/iax2.h
deleted file mode 100644
index c6b44628d..000000000
--- a/1.2-netsec/channels/iax2.h
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Asterisk -- A telephony toolkit for Linux.
- *
- * Implementation of Inter-Asterisk eXchange
- *
- * Copyright (C) 2003, Digium
- *
- * Mark Spencer <markster@linux-support.net>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-#ifndef _IAX2_H
-#define _IAX2_H
-
-/* Max version of IAX protocol we support */
-#define IAX_PROTO_VERSION 2
-
-#define IAX_MAX_CALLS 32768
-
-#define IAX_FLAG_FULL 0x8000
-
-#define IAX_FLAG_RETRANS 0x8000
-
-#define IAX_FLAG_SC_LOG 0x80
-
-#define IAX_MAX_SHIFT 0x1F
-
-#define IAX_WINDOW 64
-
-/* Subclass for AST_FRAME_IAX */
-#define IAX_COMMAND_NEW 1
-#define IAX_COMMAND_PING 2
-#define IAX_COMMAND_PONG 3
-#define IAX_COMMAND_ACK 4
-#define IAX_COMMAND_HANGUP 5
-#define IAX_COMMAND_REJECT 6
-#define IAX_COMMAND_ACCEPT 7
-#define IAX_COMMAND_AUTHREQ 8
-#define IAX_COMMAND_AUTHREP 9
-#define IAX_COMMAND_INVAL 10
-#define IAX_COMMAND_LAGRQ 11
-#define IAX_COMMAND_LAGRP 12
-#define IAX_COMMAND_REGREQ 13 /* Registration request */
-#define IAX_COMMAND_REGAUTH 14 /* Registration authentication required */
-#define IAX_COMMAND_REGACK 15 /* Registration accepted */
-#define IAX_COMMAND_REGREJ 16 /* Registration rejected */
-#define IAX_COMMAND_REGREL 17 /* Force release of registration */
-#define IAX_COMMAND_VNAK 18 /* If we receive voice before valid first voice frame, send this */
-#define IAX_COMMAND_DPREQ 19 /* Request status of a dialplan entry */
-#define IAX_COMMAND_DPREP 20 /* Request status of a dialplan entry */
-#define IAX_COMMAND_DIAL 21 /* Request a dial on channel brought up TBD */
-#define IAX_COMMAND_TXREQ 22 /* Transfer Request */
-#define IAX_COMMAND_TXCNT 23 /* Transfer Connect */
-#define IAX_COMMAND_TXACC 24 /* Transfer Accepted */
-#define IAX_COMMAND_TXREADY 25 /* Transfer ready */
-#define IAX_COMMAND_TXREL 26 /* Transfer release */
-#define IAX_COMMAND_TXREJ 27 /* Transfer reject */
-#define IAX_COMMAND_QUELCH 28 /* Stop audio/video transmission */
-#define IAX_COMMAND_UNQUELCH 29 /* Resume audio/video transmission */
-#define IAX_COMMAND_POKE 30 /* Like ping, but does not require an open connection */
-#define IAX_COMMAND_PAGE 31 /* Paging description */
-#define IAX_COMMAND_MWI 32 /* Stand-alone message waiting indicator */
-#define IAX_COMMAND_UNSUPPORT 33 /* Unsupported message received */
-#define IAX_COMMAND_TRANSFER 34 /* Request remote transfer */
-#define IAX_COMMAND_PROVISION 35 /* Provision device */
-#define IAX_COMMAND_FWDOWNL 36 /* Download firmware */
-#define IAX_COMMAND_FWDATA 37 /* Firmware Data */
-
-#define IAX_DEFAULT_REG_EXPIRE 60 /* By default require re-registration once per minute */
-
-#define IAX_LINGER_TIMEOUT 10 /* How long to wait before closing bridged call */
-
-#define IAX_DEFAULT_PORTNO 4569
-
-/* IAX Information elements */
-#define IAX_IE_CALLED_NUMBER 1 /* Number/extension being called - string */
-#define IAX_IE_CALLING_NUMBER 2 /* Calling number - string */
-#define IAX_IE_CALLING_ANI 3 /* Calling number ANI for billing - string */
-#define IAX_IE_CALLING_NAME 4 /* Name of caller - string */
-#define IAX_IE_CALLED_CONTEXT 5 /* Context for number - string */
-#define IAX_IE_USERNAME 6 /* Username (peer or user) for authentication - string */
-#define IAX_IE_PASSWORD 7 /* Password for authentication - string */
-#define IAX_IE_CAPABILITY 8 /* Actual codec capability - unsigned int */
-#define IAX_IE_FORMAT 9 /* Desired codec format - unsigned int */
-#define IAX_IE_LANGUAGE 10 /* Desired language - string */
-#define IAX_IE_VERSION 11 /* Protocol version - short */
-#define IAX_IE_ADSICPE 12 /* CPE ADSI capability - short */
-#define IAX_IE_DNID 13 /* Originally dialed DNID - string */
-#define IAX_IE_AUTHMETHODS 14 /* Authentication method(s) - short */
-#define IAX_IE_CHALLENGE 15 /* Challenge data for MD5/RSA - string */
-#define IAX_IE_MD5_RESULT 16 /* MD5 challenge result - string */
-#define IAX_IE_RSA_RESULT 17 /* RSA challenge result - string */
-#define IAX_IE_APPARENT_ADDR 18 /* Apparent address of peer - struct sockaddr_in */
-#define IAX_IE_REFRESH 19 /* When to refresh registration - short */
-#define IAX_IE_DPSTATUS 20 /* Dialplan status - short */
-#define IAX_IE_CALLNO 21 /* Call number of peer - short */
-#define IAX_IE_CAUSE 22 /* Cause - string */
-#define IAX_IE_IAX_UNKNOWN 23 /* Unknown IAX command - byte */
-#define IAX_IE_MSGCOUNT 24 /* How many messages waiting - short */
-#define IAX_IE_AUTOANSWER 25 /* Request auto-answering -- none */
-#define IAX_IE_MUSICONHOLD 26 /* Request musiconhold with QUELCH -- none or string */
-#define IAX_IE_TRANSFERID 27 /* Transfer Request Identifier -- int */
-#define IAX_IE_RDNIS 28 /* Referring DNIS -- string */
-#define IAX_IE_PROVISIONING 29 /* Provisioning info */
-#define IAX_IE_AESPROVISIONING 30 /* AES Provisioning info */
-#define IAX_IE_DATETIME 31 /* Date/Time */
-#define IAX_IE_DEVICETYPE 32 /* Device Type -- string */
-#define IAX_IE_SERVICEIDENT 33 /* Service Identifier -- string */
-#define IAX_IE_FIRMWAREVER 34 /* Firmware revision -- u16 */
-#define IAX_IE_FWBLOCKDESC 35 /* Firmware block description -- u32 */
-#define IAX_IE_FWBLOCKDATA 36 /* Firmware block of data -- raw */
-#define IAX_IE_PROVVER 37 /* Provisioning Version (u32) */
-#define IAX_IE_CALLINGPRES 38 /* Calling presentation (u8) */
-#define IAX_IE_CALLINGTON 39 /* Calling type of number (u8) */
-#define IAX_IE_CALLINGTNS 40 /* Calling transit network select (u16) */
-#define IAX_IE_SAMPLINGRATE 41 /* Supported sampling rates (u16) */
-#define IAX_IE_CAUSECODE 42 /* Hangup cause (u8) */
-#define IAX_IE_ENCRYPTION 43 /* Encryption format (u16) */
-#define IAX_IE_ENCKEY 44 /* Encryption key (raw) */
-#define IAX_IE_CODEC_PREFS 45 /* Codec Negotiation */
-
-#define IAX_IE_RR_JITTER 46 /* Received jitter (as in RFC1889) u32 */
-#define IAX_IE_RR_LOSS 47 /* Received loss (high byte loss pct, low 24 bits loss count, as in rfc1889 */
-#define IAX_IE_RR_PKTS 48 /* Received frames (total frames received) u32 */
-#define IAX_IE_RR_DELAY 49 /* Max playout delay for received frames (in ms) u16 */
-#define IAX_IE_RR_DROPPED 50 /* Dropped frames (presumably by jitterbuf) u32 */
-#define IAX_IE_RR_OOO 51 /* Frames received Out of Order u32 */
-
-
-#define IAX_AUTH_PLAINTEXT (1 << 0)
-#define IAX_AUTH_MD5 (1 << 1)
-#define IAX_AUTH_RSA (1 << 2)
-
-#define IAX_ENCRYPT_AES128 (1 << 0)
-
-#define IAX_META_TRUNK 1 /* Trunk meta-message */
-#define IAX_META_VIDEO 2 /* Video frame */
-
-#define IAX_META_TRUNK_SUPERMINI 0 /* This trunk frame contains classic supermini frames */
-#define IAX_META_TRUNK_MINI 1 /* This trunk frame contains trunked mini frames */
-
-#define IAX_RATE_8KHZ (1 << 0) /* 8khz sampling (default if absent) */
-#define IAX_RATE_11KHZ (1 << 1) /* 11.025khz sampling */
-#define IAX_RATE_16KHZ (1 << 2) /* 16khz sampling */
-#define IAX_RATE_22KHZ (1 << 3) /* 22.05khz sampling */
-#define IAX_RATE_44KHZ (1 << 4) /* 44.1khz sampling */
-#define IAX_RATE_48KHZ (1 << 5) /* 48khz sampling */
-
-#define IAX_DPSTATUS_EXISTS (1 << 0)
-#define IAX_DPSTATUS_CANEXIST (1 << 1)
-#define IAX_DPSTATUS_NONEXISTENT (1 << 2)
-#define IAX_DPSTATUS_IGNOREPAT (1 << 14)
-#define IAX_DPSTATUS_MATCHMORE (1 << 15)
-
-/* Full frames are always delivered reliably */
-struct ast_iax2_full_hdr {
- unsigned short scallno; /* Source call number -- high bit must be 1 */
- unsigned short dcallno; /* Destination call number -- high bit is 1 if retransmission */
- unsigned int ts; /* 32-bit timestamp in milliseconds (from 1st transmission) */
- unsigned char oseqno; /* Packet number (outgoing) */
- unsigned char iseqno; /* Packet number (next incoming expected) */
- unsigned char type; /* Frame type */
- unsigned char csub; /* Compressed subclass */
- unsigned char iedata[0];
-} __attribute__ ((__packed__));
-
-/* Full frames are always delivered reliably */
-struct ast_iax2_full_enc_hdr {
- unsigned short scallno; /* Source call number -- high bit must be 1 */
- unsigned short dcallno; /* Destination call number -- high bit is 1 if retransmission */
- unsigned char encdata[0];
-} __attribute__ ((__packed__));
-
-/* Mini header is used only for voice frames -- delivered unreliably */
-struct ast_iax2_mini_hdr {
- unsigned short callno; /* Source call number -- high bit must be 0, rest must be non-zero */
- unsigned short ts; /* 16-bit Timestamp (high 16 bits from last ast_iax2_full_hdr) */
- /* Frametype implicitly VOICE_FRAME */
- /* subclass implicit from last ast_iax2_full_hdr */
- unsigned char data[0];
-} __attribute__ ((__packed__));
-
-/* Mini header is used only for voice frames -- delivered unreliably */
-struct ast_iax2_mini_enc_hdr {
- unsigned short callno; /* Source call number -- high bit must be 0, rest must be non-zero */
- unsigned char encdata[0];
-} __attribute__ ((__packed__));
-
-struct ast_iax2_meta_hdr {
- unsigned short zeros; /* Zeros field -- must be zero */
- unsigned char metacmd; /* Meta command */
- unsigned char cmddata; /* Command Data */
- unsigned char data[0];
-} __attribute__ ((__packed__));
-
-struct ast_iax2_video_hdr {
- unsigned short zeros; /* Zeros field -- must be zero */
- unsigned short callno; /* Video call number */
- unsigned short ts; /* Timestamp and mark if present */
- unsigned char data[0];
-} __attribute__ ((__packed__));
-
-struct ast_iax2_meta_trunk_hdr {
- unsigned int ts; /* 32-bit timestamp for all messages */
- unsigned char data[0];
-} __attribute__ ((__packed__));
-
-struct ast_iax2_meta_trunk_entry {
- unsigned short callno; /* Call number */
- unsigned short len; /* Length of data for this callno */
-} __attribute__ ((__packed__));
-
-/* When trunktimestamps are used, we use this format instead */
-struct ast_iax2_meta_trunk_mini {
- unsigned short len;
- struct ast_iax2_mini_hdr mini; /* this is an actual miniframe */
-} __attribute__ ((__packed__));
-
-#define IAX_FIRMWARE_MAGIC 0x69617879
-
-struct ast_iax2_firmware_header {
- unsigned int magic; /* Magic number */
- unsigned short version; /* Software version */
- unsigned char devname[16]; /* Device */
- unsigned int datalen; /* Data length of file beyond header */
- unsigned char chksum[16]; /* Checksum of all data */
- unsigned char data[0];
-} __attribute__ ((__packed__));
-#endif
diff --git a/1.2-netsec/channels/misdn/Makefile b/1.2-netsec/channels/misdn/Makefile
deleted file mode 100644
index e0e18cf85..000000000
--- a/1.2-netsec/channels/misdn/Makefile
+++ /dev/null
@@ -1,72 +0,0 @@
-#
-# Makefile
-#
-# Make file for chan_misdn support
-#
-
-# Verify those options with main Makefile
-CFLAGS += -pipe -c -DMISDNUSER_JOLLY
-SOURCES = isdn_lib.c isdn_msg_parser.c
-OBJDIR = .
-OBJS = isdn_lib.o isdn_msg_parser.o
-
-
-all: chan_misdn_lib.a
-
-
-%.o: %.c
- $(CC) $(CFLAGS) -o $@ $<
-
-
-chan_misdn_lib.a: $(OBJS)
- ar crv $@ $(OBJS)
-
-misdn: test_preempt
- if [ ! -d lib ] ; then \
- mkdir lib; \
- cd lib ; \
- wget http://isdn.jolly.de/download/v3.1/mISDN_for_PBX4Linux-3.0.tar.gz ;\
- tar xzf mISDN_for_PBX4Linux-3.0.tar.gz; \
- wget http://isdn.jolly.de/download/v3.1/mISDNuser_for_PBX4Linux-3.0.tar.gz ;\
- tar xzf mISDNuser_for_PBX4Linux-3.0.tar.gz ;\
- cd mISDN; patch -p1 <../../mISDN.patch; \
- cd ../mISDNuser ; patch -p1 <../../mISDNuser.patch; \
- fi
- cd lib/mISDN ; make install
- cd lib/mISDNuser ; make install
-
-LINUX=/lib/modules/$(uname -r)/build
-GCCVERSION=$(shell $(CC) --version | grep GCC | cut -d " " -f 3 | cut -d "." -f 1)
-
-test_preempt:
- @if grep 'CONFIG_DEBUG_SPINLOCK=y' $(LINUX)/.config ; then \
- echo -e "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!\nDisable the DEBUG_SPINLOCK Setting in your Kernel Config.\n with this option set, mISDN will not work! \n\n" ;\
- read ; \
- exit 1 ; \
- fi
- @if grep 'CONFIG_DEBUG_SPINLOCK_SLEEP=y' $(LINUX)/.config ; then \
- echo -e "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!\nDisable the DEBUG_SPINLOCK_SLEEP Setting in your Kernel Config.\n with this option set, mISDN will not work! \n\n" ;\
- read ; \
- exit 1 ; \
- fi
- @if grep 'CONFIG_SMP=y' $(LINUX)/.config ; then \
- echo -e "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!\nDisable the SMP Setting in your Kernel Config.\n\n" ; \
- read ; \
- exit 1 ; \
- fi
- @if test "$(GCCVERSION)" -gt 3 ; then \
- echo -e "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!\nYou're using GCC 4! Please downgrade to gcc-3.x and type:\nexport CC=gcc-3.x\nbefore issuing make again.\nyou won't have success with gcc-4!\n\n" ; \
- read ; \
- exit 1 ; \
- fi
-
-
-
-FORCE:
-
-clean:
- rm -rf *.a *.o *.so
-
-misdn_clean:
- rm -rf lib
-
diff --git a/1.2-netsec/channels/misdn/chan_misdn_config.h b/1.2-netsec/channels/misdn/chan_misdn_config.h
deleted file mode 100644
index 250a74e54..000000000
--- a/1.2-netsec/channels/misdn/chan_misdn_config.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Chan_Misdn -- Channel Driver for Asterisk
- *
- * Interface to mISDN
- *
- * Copyright (C) 2004, Christian Richter
- *
- * Christian Richter <crich@beronet.com>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-
-
-#ifndef CHAN_MISDN_CONFIG_H
-#define CHAN_MISDN_CONFIG_H
-
-#define BUFFERSIZE 512
-
-enum misdn_cfg_elements {
-
- /* port config items */
- MISDN_CFG_FIRST = 0,
- MISDN_CFG_PTP, /* int (bool) */
- MISDN_CFG_GROUPNAME, /* char[] */
- MISDN_CFG_RXGAIN, /* int */
- MISDN_CFG_TXGAIN, /* int */
- MISDN_CFG_TE_CHOOSE_CHANNEL, /* int (bool) */
- MISDN_CFG_CONTEXT, /* char[] */
- MISDN_CFG_LANGUAGE, /* char[] */
- MISDN_CFG_CALLERID, /* char[] */
- MISDN_CFG_METHOD, /* char[] */
- MISDN_CFG_DIALPLAN, /* int */
- MISDN_CFG_LOCALDIALPLAN, /* int */
- MISDN_CFG_NATPREFIX, /* char[] */
- MISDN_CFG_INTERNATPREFIX, /* char[] */
- MISDN_CFG_PRES, /* int (bool) */
- MISDN_CFG_ALWAYS_IMMEDIATE, /* int (bool) */
- MISDN_CFG_IMMEDIATE, /* int (bool) */
- MISDN_CFG_HOLD_ALLOWED, /* int (bool) */
- MISDN_CFG_EARLY_BCONNECT, /* int (bool) */
- MISDN_CFG_USE_CALLINGPRES, /* int (bool) */
- MISDN_CFG_ECHOCANCEL, /* int */
- MISDN_CFG_ECHOCANCELWHENBRIDGED, /* int (bool) */
- MISDN_CFG_ECHOTRAINING, /* int (bool) */
- MISDN_CFG_CALLGROUP, /* ast_group_t */
- MISDN_CFG_PICKUPGROUP, /* ast_group_t */
- MISDN_CFG_MSNS, /* char[] */
- MISDN_CFG_LAST,
-
- /* general config items */
- MISDN_GEN_FIRST,
- MISDN_GEN_DEBUG, /* int */
- MISDN_GEN_TRACEFILE, /* char[] */
- MISDN_GEN_TRACE_CALLS, /* int (bool) */
- MISDN_GEN_TRACE_DIR, /* char[] */
- MISDN_GEN_BRIDGING, /* int (bool) */
- MISDN_GEN_STOP_TONE, /* int (bool) */
- MISDN_GEN_APPEND_DIGITS2EXTEN, /* int (bool) */
- MISDN_GEN_L1_INFO_OK, /* int (bool) */
- MISDN_GEN_CLEAR_L3, /* int (bool) */
- MISDN_GEN_DYNAMIC_CRYPT, /* int (bool) */
- MISDN_GEN_CRYPT_PREFIX, /* char[] */
- MISDN_GEN_CRYPT_KEYS, /* char[] */
- MISDN_GEN_LAST
-};
-
-enum misdn_cfg_method {
- METHOD_STANDARD = 0,
- METHOD_ROUND_ROBIN
-};
-
-/* you must call misdn_cfg_init before any other function of this header file */
-void misdn_cfg_init(int max_ports);
-void misdn_cfg_reload(void);
-void misdn_cfg_destroy(void);
-
-/* if you requst a general config element, the port value is ignored. if the requested
- * value is not available, or the buffer is too small, the buffer will be nulled (in
- * case of a char* only its first byte will be nulled). */
-void misdn_cfg_get(int port, enum misdn_cfg_elements elem, void* buf, int bufsize);
-
-/* fills the buffer with a ',' separated list of all active ports */
-void misdn_cfg_get_ports_string(char *ports);
-
-/* fills the buffer with a nice printable string representation of the config element */
-void misdn_cfg_get_config_string(int port, enum misdn_cfg_elements elem, char* buf, int bufsize);
-
-/* returns the next available port number. returns -1 if the last one was reached. */
-int misdn_cfg_get_next_port(int port);
-int misdn_cfg_get_next_port_spin(int port);
-
-int misdn_cfg_is_msn_valid(int port, char* msn);
-int misdn_cfg_is_port_valid(int port);
-int misdn_cfg_is_group_method(char *group, enum misdn_cfg_method meth);
-
-#endif
diff --git a/1.2-netsec/channels/misdn/ie.c b/1.2-netsec/channels/misdn/ie.c
deleted file mode 100644
index 4d1815f65..000000000
--- a/1.2-netsec/channels/misdn/ie.c
+++ /dev/null
@@ -1,1621 +0,0 @@
-
-/*
- * Chan_Misdn -- Channel Driver for Asterisk
- *
- * Interface to mISDN
- *
- * Copyright (C) 2005, Christian Richter
- *
- * Christian Richter <crich@beronet.com>
- *
- * heaviliy patched from jollys ie.cpp, jolly gave me ALL
- * rights for this code, i can even have my own copyright on it.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-/*
- the pointer of enc_ie_* always points to the IE itself
- if qi is not NULL (TE-mode), offset is set
-*/
-
-
-#include <string.h>
-
-
-#include "isdn_lib_intern.h"
-
-#include <mISDNuser/mISDNlib.h>
-#include <mISDNuser/isdn_net.h>
-#include <mISDNuser/l3dss1.h>
-#include <mISDNuser/net_l3.h>
-
-
-#define CENTREX_FAC 0x88
-#define CENTREX_ID 0xa1
-
-#define MISDN_IE_DEBG 0
-
-/* support stuff */
-static void strnncpy(unsigned char *dest, unsigned char *src, int len, int dst_len)
-{
- if (len > dst_len-1)
- len = dst_len-1;
- strncpy((char *)dest, (char *)src, len);
- dest[len] = '\0';
-}
-
-
-/* IE_COMPLETE */
-void enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-
- if (complete<0 || complete>1)
- {
- printf("%s: ERROR: complete(%d) is out of range.\n", __FUNCTION__, complete);
- return;
- }
-
- if (complete)
- if (MISDN_IE_DEBG) printf(" complete=%d\n", complete);
-
- if (complete)
- {
- p = msg_put(msg, 1);
- if (nt)
- {
- *ntmode = p;
- } else
- qi->sending_complete = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_COMPLETE;
- }
-}
-
-void dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete, int nt, struct misdn_bchannel *bc)
-{
- *complete = 0;
- if (!nt)
- {
- if (qi->sending_complete)
- *complete = 1;
- } else
- if (p)
- *complete = 1;
-
- if (*complete)
- if (MISDN_IE_DEBG) printf(" complete=%d\n", *complete);
-}
-
-
-/* IE_BEARER */
-void enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (coding<0 || coding>3)
- {
- printf("%s: ERROR: coding(%d) is out of range.\n", __FUNCTION__, coding);
- return;
- }
- if (capability<0 || capability>31)
- {
- printf("%s: ERROR: capability(%d) is out of range.\n", __FUNCTION__, capability);
- return;
- }
- if (mode<0 || mode>3)
- {
- printf("%s: ERROR: mode(%d) is out of range.\n", __FUNCTION__, mode);
- return;
- }
- if (rate<0 || rate>31)
- {
- printf("%s: ERROR: rate(%d) is out of range.\n", __FUNCTION__, rate);
- return;
- }
- if (multi>127)
- {
- printf("%s: ERROR: multi(%d) is out of range.\n", __FUNCTION__, multi);
- return;
- }
- if (user>31)
- {
- printf("%s: ERROR: user L1(%d) is out of range.\n", __FUNCTION__, rate);
- return;
- }
- if (rate!=24 && multi>=0)
- {
- printf("%s: WARNING: multi(%d) is only possible if rate(%d) would be 24.\n", __FUNCTION__, multi, rate);
- multi = -1;
- }
-
- if (MISDN_IE_DEBG) printf(" coding=%d capability=%d mode=%d rate=%d multi=%d user=%d\n", coding, capability, mode, rate, multi, user);
-
- l = 2 + (multi>=0) + (user>=0);
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->bearer_capability = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_BEARER;
- p[1] = l;
- p[2] = 0x80 + (coding<<5) + capability;
- p[3] = 0x80 + (mode<<5) + rate;
- if (multi >= 0)
- p[4] = 0x80 + multi;
- if (user >= 0)
- p[4+(multi>=0)] = 0xa0 + user;
-}
-
-void dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *capability, int *mode, int *rate, int *multi, int *user,
- int *async, int *urate, int *stopbits, int *dbits, int *parity, int nt, struct misdn_bchannel *bc)
-{
- int octet;
- *coding = -1;
- *capability = -1;
- *mode = -1;
- *rate = -1;
- *multi = -1;
- *user = -1;
- *async = -1;
- *urate = -1;
- *stopbits = -1;
- *dbits = -1;
- *parity = -1;
-
- if (!nt)
- {
- p = NULL;
- if (qi->llc)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->llc + 1;
- else if (qi->bearer_capability)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->bearer_capability + 1;
- }
- if (!p)
- return;
- if (p[0] < 2)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *coding = (p[1]&0x60) >> 5;
- *capability = p[1] & 0x1f;
- octet = 2;
- if (!(p[1] & 0x80))
- octet++;
-
- if (p[0] < octet)
- goto done;
-
- *mode = (p[octet]&0x60) >> 5;
- *rate = p[octet] & 0x1f;
-
- octet++;
-
- if (p[0] < octet)
- goto done;
-
- if (*rate == 0x18) {
- /* Rate multiplier only present if 64Kb/s base rate */
- *multi = p[octet++] & 0x7f;
- }
-
- if (p[0] < octet)
- goto done;
-
- /* Start L1 info */
- if ((p[octet] & 0x60) == 0x20) {
- *user = p[octet] & 0x1f;
-
- if (p[0] <= octet)
- goto done;
-
- if (p[octet++] & 0x80)
- goto l2;
-
- *async = !!(p[octet] & 0x40);
- /* 0x20 is inband negotiation */
- *urate = p[octet] & 0x1f;
-
- if (p[0] <= octet)
- goto done;
-
- if (p[octet++] & 0x80)
- goto l2;
-
- /* Ignore next byte for now: Intermediate rate, NIC, flow control */
-
- if (p[0] <= octet)
- goto done;
-
- if (p[octet++] & 0x80)
- goto l2;
-
- /* And the next one. Header, multiframe, mode, assignor/ee, negotiation */
-
- if (p[0] <= octet)
- goto done;
-
- if (!p[octet++] & 0x80)
- goto l2;
-
- /* Wheee. V.110 speed information */
-
- *stopbits = (p[octet] & 0x60) >> 5;
- *dbits = (p[octet] & 0x18) >> 3;
- *parity = p[octet] & 7;
-
- octet++;
- }
- l2: /* Nobody seems to want the rest so we don't bother (yet) */
- done:
- if (MISDN_IE_DEBG) printf(" coding=%d capability=%d mode=%d rate=%d multi=%d user=%d async=%d urate=%d stopbits=%d dbits=%d parity=%d\n", *coding, *capability, *mode, *rate, *multi, *user, *async, *urate, *stopbits, *dbits, *parity);
-}
-
-
-/* IE_CALL_ID */
-void enc_ie_call_id(unsigned char **ntmode, msg_t *msg, unsigned char *callid, int callid_len, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- char debug[25];
- int i;
-
- if (!callid || callid_len<=0)
- {
- return;
- }
- if (callid_len>8)
- {
- printf("%s: ERROR: callid_len(%d) is out of range.\n", __FUNCTION__, callid_len);
- return;
- }
-
- i = 0;
- while(i < callid_len)
- {
- if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", callid[i]);
- i++;
- }
-
- if (MISDN_IE_DEBG) printf(" callid%s\n", debug);
-
- l = callid_len;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->call_id = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_CALL_ID;
- p[1] = l;
- memcpy(p+2, callid, callid_len);
-}
-
-void dec_ie_call_id(unsigned char *p, Q931_info_t *qi, unsigned char *callid, int *callid_len, int nt, struct misdn_bchannel *bc)
-{
- char debug[25];
- int i;
-
- *callid_len = -1;
-
- if (!nt)
- {
- p = NULL;
- if (qi->call_id)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->call_id + 1;
- }
- if (!p)
- return;
- if (p[0] > 8)
- {
- printf("%s: ERROR: IE too long (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *callid_len = p[0];
- memcpy(callid, p+1, *callid_len);
-
- i = 0;
- while(i < *callid_len)
- {
- if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", callid[i]);
- i++;
- }
-
- if (MISDN_IE_DEBG) printf(" callid%s\n", debug);
-}
-
-
-/* IE_CALLED_PN */
-void enc_ie_called_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, unsigned char *number, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (type<0 || type>7)
- {
- printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
- return;
- }
- if (plan<0 || plan>15)
- {
- printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
- return;
- }
- if (!number[0])
- {
- printf("%s: ERROR: number is not given.\n", __FUNCTION__);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d number='%s'\n", type, plan, number);
-
- l = 1+strlen((char *)number);
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->called_nr = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_CALLED_PN;
- p[1] = l;
- p[2] = 0x80 + (type<<4) + plan;
- strncpy((char *)p+3, (char *)number, strlen((char *)number));
-}
-
-void dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, unsigned char *number, int number_len, int nt, struct misdn_bchannel *bc)
-{
- *type = -1;
- *plan = -1;
- *number = '\0';
-
- if (!nt)
- {
- p = NULL;
- if (qi->called_nr)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->called_nr + 1;
- }
- if (!p)
- return;
- if (p[0] < 2)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *type = (p[1]&0x70) >> 4;
- *plan = p[1] & 0xf;
- strnncpy(number, p+2, p[0]-1, number_len);
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d number='%s'\n", *type, *plan, number);
-}
-
-
-/* IE_CALLING_PN */
-void enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (type<0 || type>7)
- {
- printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
- return;
- }
- if (plan<0 || plan>15)
- {
- printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
- return;
- }
- if (present>3)
- {
- printf("%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);
- return;
- }
- if (present >= 0) if (screen<0 || screen>3)
- {
- printf("%s: ERROR: screen(%d) is out of range.\n", __FUNCTION__, screen);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d screen=%d number='%s'\n", type, plan, present, screen, number);
-
- l = 1;
- if (number) if (number[0])
- l += strlen((char *)number);
- if (present >= 0)
- l += 1;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->calling_nr = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_CALLING_PN;
- p[1] = l;
- if (present >= 0)
- {
- p[2] = 0x00 + (type<<4) + plan;
- p[3] = 0x80 + (present<<5) + screen;
- if (number) if (number[0])
- strncpy((char *)p+4, (char *)number, strlen((char *)number));
- } else
- {
- p[2] = 0x80 + (type<<4) + plan;
- if (number) if (number[0])
- strncpy((char *)p+3, (char *)number, strlen((char *)number));
- }
-}
-
-void dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len, int nt, struct misdn_bchannel *bc)
-{
- *type = -1;
- *plan = -1;
- *present = -1;
- *screen = -1;
- *number = '\0';
-
- if (!nt)
- {
- p = NULL;
- if (qi->calling_nr)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->calling_nr + 1;
- }
- if (!p)
- return;
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *type = (p[1]&0x70) >> 4;
- *plan = p[1] & 0xf;
- if (!(p[1] & 0x80))
- {
- if (p[0] < 2)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
- *present = (p[2]&0x60) >> 5;
- *screen = p[2] & 0x3;
- strnncpy(number, p+3, p[0]-2, number_len);
- } else
- {
- strnncpy(number, p+2, p[0]-1, number_len);
- /* SPECIAL workarround for IBT software bug */
- /* if (number[0]==0x80) */
- /* strcpy((char *)number, (char *)number+1); */
- }
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d screen=%d number='%s'\n", *type, *plan, *present, *screen, number);
-}
-
-
-/* IE_CONNECTED_PN */
-void enc_ie_connected_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (type<0 || type>7)
- {
- printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
- return;
- }
- if (plan<0 || plan>15)
- {
- printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
- return;
- }
- if (present>3)
- {
- printf("%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);
- return;
- }
- if (present >= 0) if (screen<0 || screen>3)
- {
- printf("%s: ERROR: screen(%d) is out of range.\n", __FUNCTION__, screen);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d screen=%d number='%s'\n", type, plan, present, screen, number);
-
- l = 1;
- if (number) if (number[0])
- l += strlen((char *)number);
- if (present >= 0)
- l += 1;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->connected_nr = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_CONNECT_PN;
- p[1] = l;
- if (present >= 0)
- {
- p[2] = 0x00 + (type<<4) + plan;
- p[3] = 0x80 + (present<<5) + screen;
- if (number) if (number[0])
- strncpy((char *)p+4, (char *)number, strlen((char *)number));
- } else
- {
- p[2] = 0x80 + (type<<4) + plan;
- if (number) if (number[0])
- strncpy((char *)p+3, (char *)number, strlen((char *)number));
- }
-}
-
-void dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len, int nt, struct misdn_bchannel *bc)
-{
- *type = -1;
- *plan = -1;
- *present = -1;
- *screen = -1;
- *number = '\0';
-
- if (!nt)
- {
- p = NULL;
- if (qi->connected_nr)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->connected_nr + 1;
- }
- if (!p)
- return;
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *type = (p[1]&0x70) >> 4;
- *plan = p[1] & 0xf;
- if (!(p[1] & 0x80))
- {
- if (p[0] < 2)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
- *present = (p[2]&0x60) >> 5;
- *screen = p[2] & 0x3;
- strnncpy(number, p+3, p[0]-2, number_len);
- } else
- {
- strnncpy(number, p+2, p[0]-1, number_len);
- }
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d screen=%d number='%s'\n", *type, *plan, *present, *screen, number);
-}
-
-
-/* IE_CAUSE */
-void enc_ie_cause(unsigned char **ntmode, msg_t *msg, int location, int cause, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (location<0 || location>7)
- {
- printf("%s: ERROR: location(%d) is out of range.\n", __FUNCTION__, location);
- return;
- }
- if (cause<0 || cause>127)
- {
- printf("%s: ERROR: cause(%d) is out of range.\n", __FUNCTION__, cause);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" location=%d cause=%d\n", location, cause);
-
- l = 2;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->cause = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_CAUSE;
- p[1] = l;
- p[2] = 0x80 + location;
- p[3] = 0x80 + cause;
-}
-void enc_ie_cause_standalone(unsigned char **ntmode, msg_t *msg, int location, int cause, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p = msg_put(msg, 4);
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- if (ntmode)
- *ntmode = p+1;
- else
- qi->cause = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_CAUSE;
- p[1] = 2;
- p[2] = 0x80 + location;
- p[3] = 0x80 + cause;
-}
-
-
-void dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *cause, int nt, struct misdn_bchannel *bc)
-{
- *location = -1;
- *cause = -1;
-
- if (!nt)
- {
- p = NULL;
- if (qi->cause)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->cause + 1;
- }
- if (!p)
- return;
- if (p[0] < 2)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *location = p[1] & 0x0f;
- *cause = p[2] & 0x7f;
-
- if (MISDN_IE_DEBG) printf(" location=%d cause=%d\n", *location, *cause);
-}
-
-
-/* IE_CHANNEL_ID */
-void enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive, int channel, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
- struct misdn_stack *stack=get_stack_by_bc(bc);
- int pri = stack->pri;
-
- if (exclusive<0 || exclusive>1)
- {
- printf("%s: ERROR: exclusive(%d) is out of range.\n", __FUNCTION__, exclusive);
- return;
- }
- if ((channel<0 || channel>0xff)
- || (!pri && (channel>2 && channel<0xff))
- || (pri && (channel>31 && channel<0xff))
- || (pri && channel==16))
- {
- printf("%s: ERROR: channel(%d) is out of range.\n", __FUNCTION__, channel);
- return;
- }
-
- /* if (MISDN_IE_DEBG) printf(" exclusive=%d channel=%d\n", exclusive, channel); */
-
-
- if (!pri)
- {
- /* BRI */
- l = 1;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->channel_id = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_CHANNEL_ID;
- p[1] = l;
- if (channel == 0xff)
- channel = 3;
- p[2] = 0x80 + (exclusive<<3) + channel;
- /* printf(" exclusive=%d channel=%d\n", exclusive, channel); */
- } else
- {
- /* PRI */
- if (channel == 0) /* no channel */
- return; /* IE not present */
-/* if (MISDN_IE_DEBG) printf("channel = %d\n", channel); */
- if (channel == 0xff) /* any channel */
- {
- l = 1;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->channel_id = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_CHANNEL_ID;
- p[1] = l;
- p[2] = 0x80 + 0x20 + 0x03;
-/* if (MISDN_IE_DEBG) printf("%02x\n", p[2]); */
- return; /* end */
- }
- l = 3;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->channel_id = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_CHANNEL_ID;
- p[1] = l;
- p[2] = 0x80 + 0x20 + (exclusive<<3) + 0x01;
- p[3] = 0x80 + 3; /* CCITT, Number, B-type */
- p[4] = 0x80 + channel;
-/* if (MISDN_IE_DEBG) printf("%02x %02x %02x\n", p[2], p[3], p[4]); */
- }
-}
-
-void dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive, int *channel, int nt, struct misdn_bchannel *bc)
-{
- struct misdn_stack *stack=get_stack_by_bc(bc);
- int pri =stack->pri;
-
- *exclusive = -1;
- *channel = -1;
-
- if (!nt)
- {
- p = NULL;
- if (qi->channel_id)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->channel_id + 1;
- }
- if (!p)
- return;
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- if (p[1] & 0x40)
- {
- printf("%s: ERROR: refering to channels of other interfaces is not supported.\n", __FUNCTION__);
- return;
- }
- if (p[1] & 0x04)
- {
- printf("%s: ERROR: using d-channel is not supported.\n", __FUNCTION__);
- return;
- }
-
- *exclusive = (p[1]&0x08) >> 3;
- if (!pri)
- {
- /* BRI */
- if (p[1] & 0x20)
- {
- printf("%s: ERROR: extended channel ID with non PRI interface.\n", __FUNCTION__);
- return;
- }
- *channel = p[1] & 0x03;
- if (*channel == 3)
- *channel = 0xff;
- } else
- {
- /* PRI */
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short for PRI (%d).\n", __FUNCTION__, p[0]);
- return;
- }
- if (!(p[1] & 0x20))
- {
- printf("%s: ERROR: basic channel ID with PRI interface.\n", __FUNCTION__);
- return;
- }
- if ((p[1]&0x03) == 0x00)
- {
- /* no channel */
- *channel = 0;
- return;
- }
- if ((p[1]&0x03) == 0x03)
- {
- /* any channel */
- *channel = 0xff;
- return;
- }
- if (p[0] < 3)
- {
- printf("%s: ERROR: IE too short for PRI with channel(%d).\n", __FUNCTION__, p[0]);
- return;
- }
- if (p[2] & 0x10)
- {
- printf("%s: ERROR: channel map not supported.\n", __FUNCTION__);
- return;
- }
- *channel = p[3] & 0x7f;
- if ( (*channel<1) | (*channel==16) | (*channel>31))
- {
- printf("%s: ERROR: PRI interface channel out of range (%d).\n", __FUNCTION__, *channel);
- return;
- }
-/* if (MISDN_IE_DEBG) printf("%02x %02x %02x\n", p[1], p[2], p[3]); */
- }
-
- if (MISDN_IE_DEBG) printf(" exclusive=%d channel=%d\n", *exclusive, *channel);
-}
-
-
-/* IE_DATE */
-void enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- struct tm *tm;
-
- tm = localtime(&ti);
- if (!tm)
- {
- printf("%s: ERROR: gettimeofday() returned NULL.\n", __FUNCTION__);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" year=%d month=%d day=%d hour=%d minute=%d\n", tm->tm_year%100, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min);
-
- l = 5;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->date = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_DATE;
- p[1] = l;
- p[2] = tm->tm_year % 100;
- p[3] = tm->tm_mon + 1;
- p[4] = tm->tm_mday;
- p[5] = tm->tm_hour;
- p[6] = tm->tm_min;
-}
-
-
-/* IE_DISPLAY */
-void enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *display, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (!display[0])
- {
- printf("%s: ERROR: display text not given.\n", __FUNCTION__);
- return;
- }
-
- if (strlen((char *)display) > 80)
- {
- printf("%s: WARNING: display text too long (max 80 chars), cutting.\n", __FUNCTION__);
- display[80] = '\0';
- }
-
- /* if (MISDN_IE_DEBG) printf(" display='%s' (len=%d)\n", display, strlen((char *)display)); */
-
- l = strlen((char *)display);
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->display = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_DISPLAY;
- p[1] = l;
- strncpy((char *)p+2, (char *)display, strlen((char *)display));
-}
-
-void dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *display, int display_len, int nt, struct misdn_bchannel *bc)
-{
- *display = '\0';
-
- if (!nt)
- {
- p = NULL;
- if (qi->display)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->display + 1;
- }
- if (!p)
- return;
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- strnncpy(display, p+1, p[0], display_len);
-
- if (MISDN_IE_DEBG) printf(" display='%s'\n", display);
-}
-
-
-/* IE_KEYPAD */
-void enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *keypad, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (!keypad[0])
- {
- printf("%s: ERROR: keypad info not given.\n", __FUNCTION__);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" keypad='%s'\n", keypad);
-
- l = strlen((char *)keypad);
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->keypad = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_KEYPAD;
- p[1] = l;
- strncpy((char *)p+2, (char *)keypad, strlen((char *)keypad));
-}
-
-void dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keypad, int keypad_len, int nt, struct misdn_bchannel *bc)
-{
- *keypad = '\0';
-
- if (!nt)
- {
- p = NULL;
- if (qi->keypad)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->keypad + 1;
- }
- if (!p)
- return;
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- strnncpy(keypad, p+1, p[0], keypad_len);
-
- if (MISDN_IE_DEBG) printf(" keypad='%s'\n", keypad);
-}
-
-
-/* IE_NOTIFY */
-void enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (notify<0 || notify>0x7f)
- {
- printf("%s: ERROR: notify(%d) is out of range.\n", __FUNCTION__, notify);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" notify=%d\n", notify);
-
- l = 1;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->notify = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_NOTIFY;
- p[1] = l;
- p[2] = 0x80 + notify;
-}
-
-void dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify, int nt, struct misdn_bchannel *bc)
-{
- *notify = -1;
-
- if (!nt)
- {
- p = NULL;
- if (qi->notify)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->notify + 1;
- }
- if (!p)
- return;
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *notify = p[1] & 0x7f;
-
- if (MISDN_IE_DEBG) printf(" notify=%d\n", *notify);
-}
-
-
-/* IE_PROGRESS */
-void enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (coding<0 || coding>0x03)
- {
- printf("%s: ERROR: coding(%d) is out of range.\n", __FUNCTION__, coding);
- return;
- }
- if (location<0 || location>0x0f)
- {
- printf("%s: ERROR: location(%d) is out of range.\n", __FUNCTION__, location);
- return;
- }
- if (progress<0 || progress>0x7f)
- {
- printf("%s: ERROR: progress(%d) is out of range.\n", __FUNCTION__, progress);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" coding=%d location=%d progress=%d\n", coding, location, progress);
-
- l = 2;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->progress = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_PROGRESS;
- p[1] = l;
- p[2] = 0x80 + (coding<<5) + location;
- p[3] = 0x80 + progress;
-}
-
-void dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress, int nt, struct misdn_bchannel *bc)
-{
- *coding = -1;
- *location = -1;
- //*progress = -1;
- *progress = 0;
-
- if (!nt)
- {
- p = NULL;
- if (qi->progress)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->progress + 1;
- }
- if (!p)
- return;
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *coding = (p[1]&0x60) >> 5;
- *location = p[1] & 0x0f;
- *progress = p[2] & 0x7f;
-
- if (MISDN_IE_DEBG) printf(" coding=%d location=%d progress=%d\n", *coding, *location, *progress);
-}
-
-
-/* IE_REDIR_NR (redirecting = during MT_SETUP) */
-void enc_ie_redir_nr(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, int reason, unsigned char *number, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- if (type<0 || type>7)
- {
- printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
- return;
- }
- if (plan<0 || plan>15)
- {
- printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
- return;
- }
- if (present > 3)
- {
- printf("%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);
- return;
- }
- if (present >= 0) if (screen<0 || screen>3)
- {
- printf("%s: ERROR: screen(%d) is out of range.\n", __FUNCTION__, screen);
- return;
- }
- if (reason > 0x0f)
- {
- printf("%s: ERROR: reason(%d) is out of range.\n", __FUNCTION__, reason);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d screen=%d readon=%d number='%s'\n", type, plan, present, screen, reason, number);
-
- l = 1;
- if (number)
- l += strlen((char *)number);
- if (present >= 0)
- {
- l += 1;
- if (reason >= 0)
- l += 1;
- }
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->redirect_nr = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_REDIR_NR;
- p[1] = l;
- if (present >= 0)
- {
- if (reason >= 0)
- {
- p[2] = 0x00 + (type<<4) + plan;
- p[3] = 0x00 + (present<<5) + screen;
- p[4] = 0x80 + reason;
- if (number)
- strncpy((char *)p+5, (char *)number, strlen((char *)number));
- } else
- {
- p[2] = 0x00 + (type<<4) + plan;
- p[3] = 0x80 + (present<<5) + screen;
- if (number)
- strncpy((char *)p+4, (char *)number, strlen((char *)number));
- }
- } else
- {
- p[2] = 0x80 + (type<<4) + plan;
- if (number) if (number[0])
- strncpy((char *)p+3, (char *)number, strlen((char *)number));
- }
-}
-
-void dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, int *reason, unsigned char *number, int number_len, int nt, struct misdn_bchannel *bc)
-{
- *type = -1;
- *plan = -1;
- *present = -1;
- *screen = -1;
- *reason = -1;
- *number = '\0';
-
- if (!nt)
- {
- p = NULL;
- if (qi->redirect_nr)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_nr + 1;
- }
- if (!p)
- return;
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *type = (p[1]&0x70) >> 4;
- *plan = p[1] & 0xf;
- if (!(p[1] & 0x80))
- {
- *present = (p[2]&0x60) >> 5;
- *screen = p[2] & 0x3;
- if (!(p[2] & 0x80))
- {
- *reason = p[3] & 0x0f;
- strnncpy(number, p+4, p[0]-3, number_len);
- } else
- {
- strnncpy(number, p+3, p[0]-2, number_len);
- }
- } else
- {
- strnncpy(number, p+2, p[0]-1, number_len);
- }
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d screen=%d reason=%d number='%s'\n", *type, *plan, *present, *screen, *reason, number);
-}
-
-
-/* IE_REDIR_DN (redirection = during MT_NOTIFY) */
-void enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, unsigned char *number, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
-/* Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); */
- int l;
-
- if (type<0 || type>7)
- {
- printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
- return;
- }
- if (plan<0 || plan>15)
- {
- printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
- return;
- }
- if (present > 3)
- {
- printf("%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d number='%s'\n", type, plan, present, number);
-
- l = 1;
- if (number)
- l += strlen((char *)number);
- if (present >= 0)
- l += 1;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
-/* #warning REINSERT redir_dn, when included in te-mode */
- /*qi->redir_dn = p - (unsigned char *)qi - sizeof(Q931_info_t)*/;
- p[0] = IE_REDIR_DN;
- p[1] = l;
- if (present >= 0)
- {
- p[2] = 0x00 + (type<<4) + plan;
- p[3] = 0x80 + (present<<5);
- if (number)
- strncpy((char *)p+4, (char *)number, strlen((char *)number));
- } else
- {
- p[2] = 0x80 + (type<<4) + plan;
- if (number)
- strncpy((char *)p+3, (char *)number, strlen((char *)number));
- }
-}
-
-void dec_ie_redir_dn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, unsigned char *number, int number_len, int nt, struct misdn_bchannel *bc)
-{
- *type = -1;
- *plan = -1;
- *present = -1;
- *number = '\0';
-
- if (!nt)
- {
- p = NULL;
-/* #warning REINSERT redir_dn, when included in te-mode */
-/* if (qi->redir_dn) */
-/* p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redir_dn + 1; */
- }
- if (!p)
- return;
- if (p[0] < 1)
- {
- printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
- return;
- }
-
- *type = (p[1]&0x70) >> 4;
- *plan = p[1] & 0xf;
- if (!(p[1] & 0x80))
- {
- *present = (p[2]&0x60) >> 5;
- strnncpy(number, p+3, p[0]-2, number_len);
- } else
- {
- strnncpy(number, p+2, p[0]-1, number_len);
- }
-
- if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d number='%s'\n", *type, *plan, *present, number);
-}
-
-
-/* IE_FACILITY */
-void enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- char debug[768];
- int i;
-
- if (!facility || facility_len<=0)
- {
- return;
- }
-
- i = 0;
- while(i < facility_len)
- {
- if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", facility[i]);
- i++;
- }
-
- if (MISDN_IE_DEBG) printf(" facility%s\n", debug);
-
- l = facility_len;
- p = msg_put(msg, l+2);
- if (nt)
- *ntmode = p+1;
- else
- qi->facility = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_FACILITY;
- p[1] = l;
- memcpy(p+2, facility, facility_len);
-}
-
-void dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *facility, int *facility_len, int nt, struct misdn_bchannel *bc)
-{
- int i;
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- *facility_len = 0;
-
- if (!nt)
- {
- p = NULL;
- if (qi->facility)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->facility + 1;
- }
- if (!p)
- return;
-
- *facility_len = p[0];
- memcpy(facility, p+1, *facility_len);
-
- i = 0;
- while(i < *facility_len)
- {
- cb_log(3, stack->port, " %02x", facility[i]);
- i++;
- }
- cb_log(3, stack->port, " facility\n");
-}
-
-
-/* facility for siemens CENTEX (known parts implemented only) */
-void enc_facility_centrex(unsigned char **ntmode, msg_t *msg, unsigned char *cnip, int setup, int nt, struct misdn_bchannel *bc)
-{
- unsigned char centrex[256];
- int i = 0;
-
- if (!cnip)
- return;
-
- /* centrex facility */
- centrex[i++] = CENTREX_FAC;
- centrex[i++] = CENTREX_ID;
-
- /* cnip */
- if (strlen((char *)cnip) > 15)
- {
-/* if (options.deb & DEBUG_PORT) */
- if (MISDN_IE_DEBG) printf("%s: CNIP/CONP text too long (max 13 chars), cutting.\n", __FUNCTION__);
- cnip[15] = '\0';
- }
- /* dunno what the 8 bytes mean */
- if (setup)
- {
- centrex[i++] = 0x17;
- centrex[i++] = 0x02;
- centrex[i++] = 0x02;
- centrex[i++] = 0x44;
- centrex[i++] = 0x18;
- centrex[i++] = 0x02;
- centrex[i++] = 0x01;
- centrex[i++] = 0x09;
- } else
- {
- centrex[i++] = 0x18;
- centrex[i++] = 0x02;
- centrex[i++] = 0x02;
- centrex[i++] = 0x81;
- centrex[i++] = 0x09;
- centrex[i++] = 0x02;
- centrex[i++] = 0x01;
- centrex[i++] = 0x0a;
- }
-
- centrex[i++] = 0x80;
- centrex[i++] = strlen((char *)cnip);
- strcpy((char *)(&centrex[i]), (char *)cnip);
- i += strlen((char *)cnip);
- if (MISDN_IE_DEBG) printf(" cnip='%s'\n", cnip);
-
- /* encode facility */
- enc_ie_facility(ntmode, msg, centrex, i, nt , bc);
-}
-
-void dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len, int nt, struct misdn_bchannel *bc)
-{
- unsigned char centrex[256];
- char debug[768];
- int facility_len = 0;
- int i = 0, j;
- *cnip = '\0';
-
- dec_ie_facility(p, qi, centrex, &facility_len, nt, bc);
- if (facility_len >= 2)
- {
- if (centrex[i++] != CENTREX_FAC)
- return;
- if (centrex[i++] != CENTREX_ID)
- return;
- }
-
- /* loop sub IEs of facility */
- while(facility_len > i+1)
- {
- if (centrex[i+1]+i+1 > facility_len)
- {
- printf("%s: ERROR: short read of centrex facility.\n", __FUNCTION__);
- return;
- }
- switch(centrex[i])
- {
- case 0x80:
- strnncpy(cnip, &centrex[i+2], centrex[i+1], cnip_len);
- if (MISDN_IE_DEBG) printf(" CENTREX cnip='%s'\n", cnip);
- break;
-
- default:
- j = 0;
- while(j < centrex[i+1])
- {
- if (MISDN_IE_DEBG) printf(debug+(j*3), " %02x", centrex[i+1+j]);
- i++;
- }
- if (MISDN_IE_DEBG) printf(" CENTREX unknown=0x%2x len=%d%s\n", centrex[i], centrex[i+1], debug);
- }
- i += 1+centrex[i+1];
- }
-}
-
-
-
-
-/* facility for siemens CENTEX (known parts implemented only) */
-void enc_facility_calldeflect(unsigned char **ntmode, msg_t *msg, unsigned char *nr, int nt, struct misdn_bchannel *bc)
-{
- unsigned char fac[256];
-
- if (!nr)
- return;
-
- /* calldeflect facility */
-
- /* cnip */
- if (strlen((char *)nr) > 15)
- {
-/* if (options.deb & DEBUG_PORT) */
- if (MISDN_IE_DEBG) printf("%s: NR text too long (max 13 chars), cutting.\n", __FUNCTION__);
- nr[15] = '\0';
- }
-
- fac[0]=0; // len
- fac[1]=0; //len
- fac[2]=0x01; // Use D-Chan
- fac[3]=0; // Keypad len
- fac[4]=31; // user user data? len = 31 = 29 + 2
- fac[5]=0x1c; // magic?
- fac[6]=0x1d; // strlen destination + 18 = 29
- fac[7]=0x91; // ..
- fac[8]=0xA1;
- fac[9]=0x1A; // strlen destination + 15 = 26
- fac[10]=0x02;
- fac[11]=0x01;
- fac[12]=0x70;
- fac[13]=0x02;
- fac[14]=0x01;
- fac[15]=0x0d;
- fac[16]=0x30;
- fac[17]=0x12; // strlen destination + 7 = 18
- fac[18]=0x30; // ...hm 0x30
- fac[19]=0x0d; // strlen destination + 2
- fac[20]=0x80; // CLIP
- fac[21]=0x0b; // strlen destination
- fac[22]=0x01; // destination start
- fac[23]=0x01; //
- fac[24]=0x01; //
- fac[25]=0x01; //
- fac[26]=0x01; //
- fac[27]=0x01; //
- fac[28]=0x01; //
- fac[29]=0x01; //
- fac[30]=0x01; //
- fac[31]=0x01; //
- fac[32]=0x01; //
- fac[33]=0x01; // 0x1 = sending complete
- fac[34]=0x01;
- fac[35]=0x01;
-
- memcpy((unsigned char *)fac+22,nr,strlen(nr));
- fac[22+strlen( nr)]=0x01; // fill with 0x01 if number is only 6 numbers (local call)
- fac[23+strlen(nr)]=0x01;
- fac[24+strlen(nr)]=0x01;
- fac[25+strlen(nr)]=0x01;
- fac[26+strlen(nr)]=0x01;
-
- fac[6]=18+strlen(nr);
- fac[9]=15+strlen(nr);
- fac[17]=7+strlen(nr);
- fac[19]=2+strlen(nr);
- fac[21]=strlen(nr);
-
- enc_ie_facility(ntmode, msg, &fac[4], 36-4, nt , bc);
-}
-
-
-/* IE_USERUSER */
-void enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len, int nt, struct misdn_bchannel *bc)
-{
- unsigned char *p;
- Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
- int l;
-
- char debug[768];
- int i;
-
- if (protocol<0 || protocol>127)
- {
- printf("%s: ERROR: protocol(%d) is out of range.\n", __FUNCTION__, protocol);
- return;
- }
- if (!user || user_len<=0)
- {
- return;
- }
-
- i = 0;
- while(i < user_len)
- {
- if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", user[i]);
- i++;
- }
-
- if (MISDN_IE_DEBG) printf(" protocol=%d user-user%s\n", protocol, debug);
-
- l = user_len;
- p = msg_put(msg, l+3);
- if (nt)
- *ntmode = p+1;
- else
- qi->useruser = p - (unsigned char *)qi - sizeof(Q931_info_t);
- p[0] = IE_USER_USER;
- p[1] = l;
- p[2] = 0x80 + protocol;
- memcpy(p+3, user, user_len);
-}
-
-void dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len, int nt, struct misdn_bchannel *bc)
-{
- char debug[768];
- int i;
-
- *user_len = 0;
- *protocol = -1;
-
- if (!nt)
- {
- p = NULL;
- if (qi->useruser)
- p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->useruser + 1;
- }
- if (!p)
- return;
-
- *user_len = p[0]-1;
- if (p[0] < 1)
- return;
- *protocol = p[1];
- memcpy(user, p+2, (*user_len<=128)?*(user_len):128); /* clip to 128 maximum */
-
- i = 0;
- while(i < *user_len)
- {
- if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", user[i]);
- i++;
- }
- debug[i*3] = '\0';
-
- if (MISDN_IE_DEBG) printf(" protocol=%d user-user%s\n", *protocol, debug);
-}
-
-
diff --git a/1.2-netsec/channels/misdn/isdn_lib.c b/1.2-netsec/channels/misdn/isdn_lib.c
deleted file mode 100644
index aa1d51cea..000000000
--- a/1.2-netsec/channels/misdn/isdn_lib.c
+++ /dev/null
@@ -1,3308 +0,0 @@
-/*
- * Chan_Misdn -- Channel Driver for Asterisk
- *
- * Interface to mISDN
- *
- * Copyright (C) 2004, Christian Richter
- *
- * Christian Richter <crich@beronet.com>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-#include "isdn_lib_intern.h"
-
-
-int misdn_ibuf_freecount(void *buf)
-{
- return ibuf_freecount( (ibuffer_t*)buf);
-}
-
-int misdn_ibuf_usedcount(void *buf)
-{
- return ibuf_usedcount( (ibuffer_t*)buf);
-}
-
-void misdn_ibuf_memcpy_r(char *to, void *buf, int len)
-{
- ibuf_memcpy_r( to, (ibuffer_t*)buf, len);
-}
-
-void misdn_ibuf_memcpy_w(void *buf, char *from, int len)
-{
- ibuf_memcpy_w((ibuffer_t*)buf, from, len);
-}
-
-struct misdn_stack* get_misdn_stack( void );
-
-
-int misdn_lib_is_ptp(int port)
-{
- struct misdn_stack *stack=get_misdn_stack();
- for ( ; stack; stack=stack->next) {
- if (stack->port == port) return stack->ptp;
- }
- return -1;
-}
-
-
-struct misdn_stack* get_stack_by_bc(struct misdn_bchannel *bc)
-{
- struct misdn_stack *stack=get_misdn_stack();
-
- if (!bc) return NULL;
-
- for ( ; stack; stack=stack->next) {
- int i;
- for (i=0; i <stack->b_num; i++) {
- if ( bc->port == stack->port) return stack;
- }
- }
-
- return NULL;
-}
-
-
-void get_show_stack_details(int port, char *buf)
-{
- struct misdn_stack *stack=get_misdn_stack();
-
- for ( ; stack; stack=stack->next) {
- if (stack->port == port) break;
- }
-
- if (stack) {
- sprintf(buf, "* Stack Addr: Port %d Type %s Prot. %s L2Link %s L1Link:%s", stack->upper_id & IF_CONTRMASK, stack->mode==NT_MODE?"NT":"TE", stack->ptp?"PTP":"PMP", stack->l2link?"UP":"DOWN", stack->l1link?"UP":"DOWN");
- } else {
- buf[0]=0;
- }
-
-}
-
-
-static int nt_err_cnt =0 ;
-
-enum global_states {
- MISDN_INITIALIZING,
- MISDN_INITIALIZED
-} ;
-
-static enum global_states global_state=MISDN_INITIALIZING;
-
-
-#include <mISDNuser/net_l2.h>
-#include <mISDNuser/tone.h>
-#include <unistd.h>
-#include <semaphore.h>
-#include <pthread.h>
-#include <signal.h>
-
-#include "isdn_lib.h"
-
-
-struct misdn_lib {
- int midev;
- int midev_nt;
-
- pthread_t event_thread;
- pthread_t event_handler_thread;
-
- void *user_data;
-
- msg_queue_t upqueue;
- msg_queue_t activatequeue;
-
- sem_t new_msg;
-
- struct misdn_stack *stack_list;
-} ;
-
-#ifndef ECHOCAN_ON
-#define ECHOCAN_ON 123
-#define ECHOCAN_OFF 124
-#endif
-
-#define MISDN_DEBUG 0
-
-struct misdn_bchannel *find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id);
-
-int setup_bc(struct misdn_bchannel *bc);
-
-int manager_isdn_handler(iframe_t *frm ,msg_t *msg);
-
-int misdn_lib_port_restart(int port);
-
-extern struct isdn_msg msgs_g[];
-
-#define ISDN_PID_L3_B_USER 0x430000ff
-#define ISDN_PID_L4_B_USER 0x440000ff
-
-/* #define MISDN_IBUF_SIZE 1024 */
-#define MISDN_IBUF_SIZE 512
-
-/* Fine Tuning of Inband Signalling time */
-#define TONE_ALERT_CNT 41 /* 1 Sec */
-#define TONE_ALERT_SILENCE_CNT 200 /* 4 Sec */
-
-#define TONE_BUSY_CNT 20 /* ? */
-#define TONE_BUSY_SILENCE_CNT 48 /* ? */
-
-static int entity;
-
-static struct misdn_lib *glob_mgr;
-
-unsigned char tone_425_flip[TONE_425_SIZE];
-unsigned char tone_silence_flip[TONE_SILENCE_SIZE];
-
-static void misdn_lib_isdn_event_catcher(void *arg);
-static int handle_event_nt(void *dat, void *arg);
-
-
-void stack_holder_add(struct misdn_stack *stack, struct misdn_bchannel *holder);
-void stack_holder_remove(struct misdn_stack *stack, struct misdn_bchannel *holder);
-struct misdn_bchannel *stack_holder_find(struct misdn_stack *stack, unsigned long l3id);
-
-/* from isdn_lib.h */
-int init_bc(struct misdn_stack * stack, struct misdn_bchannel *bc, int midev, int port, int bidx, char *msn, int firsttime);
-struct misdn_stack* stack_te_init(int midev, int port, int ptp);
-void stack_te_destroy(struct misdn_stack* stack);
- /* user iface */
-int te_lib_init( void ) ; /* returns midev */
-void te_lib_destroy(int midev) ;
-struct misdn_bchannel *manager_find_bc_by_pid(int pid);
-struct misdn_bchannel *manager_find_bc_holded(struct misdn_bchannel* bc);
-unsigned char * manager_flip_buf_bits ( unsigned char * buf , int len);
-void manager_ph_control_block(struct misdn_bchannel *bc, int c1, void *c2, int c2_len);
-void manager_clean_bc(struct misdn_bchannel *bc );
-void manager_bchannel_setup (struct misdn_bchannel *bc);
-void manager_bchannel_cleanup (struct misdn_bchannel *bc);
-
-int isdn_msg_get_index(struct isdn_msg msgs[], msg_t *frm, int nt);
-enum event_e isdn_msg_get_event(struct isdn_msg msgs[], msg_t *frm, int nt);
-int isdn_msg_parse_event(struct isdn_msg msgs[], msg_t *frm, struct misdn_bchannel *bc, int nt);
-char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt);
-msg_t * isdn_msg_build_event(struct isdn_msg msgs[], struct misdn_bchannel *bc, enum event_e event, int nt);
-void ec_chunk( struct misdn_bchannel *bc, unsigned char *rxchunk, unsigned char *txchunk, int chunk_size);
- /* end */
-int bchdev_echocancel_activate(struct misdn_bchannel* dev);
-void bchdev_echocancel_deactivate(struct misdn_bchannel* dev);
-/* end */
-
-
-static char *bearer2str(int cap) {
- static char *bearers[]={
- "Speech",
- "Audio 3.1k",
- "Unres Digital",
- "Res Digital",
- "Unknown Bearer"
- };
-
- switch (cap) {
- case INFO_CAPABILITY_SPEECH:
- return bearers[0];
- break;
- case INFO_CAPABILITY_AUDIO_3_1K:
- return bearers[1];
- break;
- case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:
- return bearers[2];
- break;
- case INFO_CAPABILITY_DIGITAL_RESTRICTED:
- return bearers[3];
- break;
- default:
- return bearers[4];
- break;
- }
-}
-
-
-static char flip_table[256];
-
-void init_flip_bits(void)
-{
- int i,k;
-
- for (i = 0 ; i < 256 ; i++) {
- unsigned char sample = 0 ;
- for (k = 0; k<8; k++) {
- if ( i & 1 << k ) sample |= 0x80 >> k;
- }
- flip_table[i] = sample;
- }
-}
-
-static unsigned char * flip_buf_bits ( unsigned char * buf , int len)
-{
- int i;
- char * start = buf;
-
- for (i = 0 ; i < len; i++) {
- buf[i] = flip_table[buf[i]];
- }
-
- return start;
-}
-
-
-
-
-msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
-{
- int i = 0;
- msg_t *dmsg;
-
- while(i < 10)
- {
- dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
- if (dmsg)
- return(dmsg);
-
- if (!i)
- printf("cannot allocate memory, trying again...\n");
- i++;
- usleep(300000);
- }
- printf("cannot allocate memory, system overloaded.\n");
- exit(-1);
-}
-
-
-
-msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
-{
- int i = 0;
- msg_t *dmsg;
- Q931_info_t *qi;
- iframe_t *frm;
-
- if (!ntmode)
- size = sizeof(Q931_info_t)+2;
-
- while(i < 10) {
- if (ntmode) {
- dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
- if (dmsg) {
- return(dmsg);
- }
- } else {
- dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
- if (dmsg)
- {
- memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
- frm = (iframe_t *)dmsg->data;
- frm->prim = prim;
- frm->dinfo = dinfo;
- qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
- qi->type = mt;
- return(dmsg);
- }
- }
-
- if (!i) printf("cannot allocate memory, trying again...\n");
- i++;
- usleep(300000);
- }
- printf("cannot allocate memory, system overloaded.\n");
- exit(-1);
-}
-
-
-int send_msg (int midev, struct misdn_bchannel *bc, msg_t *dmsg)
-{
- iframe_t *frm;
- frm = (iframe_t *)dmsg->data;
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- frm->addr = (stack->upper_id & IF_ADDRMASK) | IF_DOWN ;
- frm->dinfo = bc->l3_id;
-
- frm->len = (dmsg->len) - mISDN_HEADER_LEN;
-
- mISDN_write(midev, dmsg->data, dmsg->len, TIMEOUT_1SEC);
-
- free_msg(dmsg);
-
- return 0;
-}
-
-
-static int mypid=0;
-
-int misdn_cap_is_speech(int cap)
-/** Poor mans version **/
-{
- if ( (cap != INFO_CAPABILITY_DIGITAL_UNRESTRICTED) &&
- (cap != INFO_CAPABILITY_DIGITAL_RESTRICTED) ) return 1;
- return 0;
-}
-
-int misdn_inband_avail(struct misdn_bchannel *bc)
-{
-
- /*if ! early_bconnect we have never inband available*/
- if ( ! bc->early_bconnect ) return 0;
-
- switch (bc->progress_indicator) {
- case INFO_PI_INBAND_AVAILABLE:
- case INFO_PI_CALL_NOT_E2E_ISDN:
- case INFO_PI_CALLED_NOT_ISDN:
- return 1;
- default:
- return 0;
- }
- return 0;
-}
-
-
-void dump_chan_list(struct misdn_stack *stack)
-{
- int i;
-
- for (i=0; i <stack->b_num; i++) {
- cb_log(3, stack->port, "Idx:%d stack->cchan:%d Chan:%d\n",i,stack->channels[i], i+1);
- }
-}
-
-
-
-
-static int find_free_chan_in_stack(struct misdn_stack *stack, int channel)
-{
- int i;
-
- if (channel < 0 || channel > MAX_BCHANS) {
- cb_log(4, stack->port, " !! out of bound call to find_free_chan_in_stack! (port:%d ch:%d)\n", stack->port, channel);
- return 0;
- }
-
- channel--;
-
- for (i = 0; i < stack->b_num; i++) {
- if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
- if (!stack->channels[i]) {
- cb_log (4, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
- stack->channels[i] = 1;
- return i+1;
- }
- }
- }
-
- cb_log (4, stack->port, " !! NO FREE CHAN IN STACK\n");
- dump_chan_list(stack);
-
- return 0;
-}
-
-int empty_chan_in_stack(struct misdn_stack *stack, int channel)
-{
- cb_log (4, stack?stack->port:0, " --> empty chan %d\n",channel);
- stack->channels[channel-1] = 0;
- dump_chan_list(stack);
- return 0;
-}
-
-
-void empty_bc(struct misdn_bchannel *bc)
-{
- bc->state=STATE_NOTHING;
-
- bc->channel = 0;
- bc->in_use = 0;
-
- bc->send_dtmf=0;
- bc->nodsp=0;
- bc->nojitter=0;
-
- bc->time_usec=0;
-
- bc->rxgain=0;
- bc->txgain=0;
-
- bc->crypt=0;
- bc->curptx=0; bc->curprx=0;
-
- bc->crypt_key[0] = 0;
-
- bc->tone=TONE_NONE;
- bc->tone_cnt2 = bc->tone_cnt=0;
-
- bc->dnumplan=NUMPLAN_UNKNOWN;
- bc->onumplan=NUMPLAN_UNKNOWN;
- bc->rnumplan=NUMPLAN_UNKNOWN;
-
-
- bc->active = 0;
-
- bc->early_bconnect = 1;
-
- bc->ec_enable = 0;
- bc->ec_deftaps = 128;
- bc->ec_whenbridged = 0;
- bc->ec_training = 1;
-
-
- bc->orig=0;
-
- bc->cause=16;
- bc->out_cause=16;
- bc->pres=0 ; /* screened */
-
- bc->evq=EVENT_NOTHING;
-
- bc->progress_coding=0;
- bc->progress_location=0;
- bc->progress_indicator=0;
-
-/** Set Default Bearer Caps **/
- bc->capability=INFO_CAPABILITY_SPEECH;
- bc->law=INFO_CODEC_ALAW;
- bc->mode=0;
- bc->rate=0;
- bc->user1=0;
- bc->async=0;
- bc->urate=0;
-
-
-
- bc->info_dad[0] = 0;
- bc->display[0] = 0;
- bc->infos_pending[0] = 0;
- bc->oad[0] = 0;
- bc->dad[0] = 0;
- bc->orig_dad[0] = 0;
-
- bc->facility=FACILITY_NONE;
- bc->facility_calldeflect_nr[0]=0;
-
- bc->te_choose_channel = 0;
-}
-
-
-int clean_up_bc(struct misdn_bchannel *bc)
-{
- int ret=0;
- unsigned char buff[32];
- struct misdn_stack * stack;
-
- if (!bc ) return -1;
- stack=get_stack_by_bc(bc);
- if (!stack) return -1;
-
- if (!bc->upset) {
- cb_log(5, stack->port, "$$$ Already cleaned up bc with stid :%x\n", bc->b_stid);
- return -1;
- }
-
- cb_log(5, stack->port, "$$$ Cleaning up bc with stid :%x\n", bc->b_stid);
-
-
- if ( misdn_cap_is_speech(bc->capability) && bc->ec_enable) {
- manager_ec_disable(bc);
- }
-
- mISDN_write_frame(stack->midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
-
-
- bc->b_stid = 0;
-
- bc->upset=0;
-
- return ret;
-}
-
-
-
-void clear_l3(struct misdn_stack *stack)
-{
- int i;
- for (i=0; i<stack->b_num; i++) {
- if (global_state == MISDN_INITIALIZED) {
- cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data);
- empty_chan_in_stack(stack,i+1);
- empty_bc(&stack->bc[i]);
- clean_up_bc(&stack->bc[i]);
-
- }
-
- }
-}
-
-int set_chan_in_stack(struct misdn_stack *stack, int channel)
-{
- stack->channels[channel-1] = 1;
-
- return 0;
-}
-
-int chan_in_stack_free(struct misdn_stack *stack, int channel)
-{
- if (stack->channels[channel-1])
- return 0;
-
- return 1;
-}
-
-
-
-static int newteid=0;
-
-#ifdef MISDNUSER_JOLLY
-#define MAXPROCS 0x100
-#else
-#define MAXPROCS 0x10
-#endif
-
-
-int misdn_lib_get_l1_up(struct misdn_stack *stack)
-{
- /* Pull Up L1 if we have JOLLY */
- iframe_t act;
- act.prim = PH_ACTIVATE | REQUEST;
- act.addr = (stack->upper_id & IF_ADDRMASK) | IF_DOWN ;
- act.dinfo = 0;
- act.len = 0;
-
- return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
-
-}
-
-int misdn_lib_get_l2_up(struct misdn_stack *stack)
-{
-
- if (stack->ptp && (stack->mode == NT_MODE) ) {
- msg_t *dmsg;
- /* L2 */
- dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0);
-
- if (stack->nst.manager_l3(&stack->nst, dmsg))
- free_msg(dmsg);
-
- } else {
- iframe_t act;
-
- act.prim = DL_ESTABLISH | REQUEST;
-
- act.addr = (stack->upper_id & IF_ADDRMASK) | IF_DOWN;
- act.dinfo = 0;
- act.len = 0;
- return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
- }
-
- return 0;
-}
-
-
-int misdn_lib_get_l2_status(struct misdn_stack *stack)
-{
- iframe_t act;
-
-#ifdef DL_STATUS
- act.prim = DL_STATUS | REQUEST;
-#else
- act.prim = DL_ESTABLISH | REQUEST;
-#endif
- act.addr = (stack->upper_id & IF_ADDRMASK) | IF_DOWN;
- act.dinfo = 0;
- act.len = 0;
- return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
-}
-
-
-static int create_process (int midev, struct misdn_bchannel *bc) {
- iframe_t ncr;
- int l3_id;
- int i;
- struct misdn_stack *stack=get_stack_by_bc(bc);
- int free_chan;
-
- if (stack->mode == NT_MODE) {
- free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0);
- if (!free_chan) return -1;
- bc->channel=free_chan;
-
- for (i=0; i <= MAXPROCS; i++)
- if (stack->procids[i]==0) break;
-
- if (i== MAXPROCS) {
- cb_log(0, stack->port, "Couldnt Create New ProcId Port:%d\n",stack->port);
- return -1;
- }
- stack->procids[i]=1;
-
-#ifdef MISDNUSER_JOLLY
- l3_id = 0xff00 | i;
-#else
- l3_id = 0xfff0 | i;
-#endif
-
- ncr.prim = CC_NEW_CR | REQUEST;
- ncr.addr = (stack->upper_id & IF_ADDRMASK) | IF_DOWN ;
- ncr.dinfo = l3_id;
- ncr.len = 0;
-
- bc->l3_id = l3_id;
- if (mypid>5000) mypid=0;
- bc->pid=mypid++;
-
- cb_log(3, stack->port, " --> new_l3id %x\n",l3_id);
-
- } else {
- if (stack->ptp || bc->te_choose_channel) {
- /* we know exactly which channels are in use */
- free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0);
- if (!free_chan) return -1;
- bc->channel=free_chan;
- } else {
- /* other phones could have made a call also on this port (ptmp) */
- bc->channel=0xff;
- }
-
-
- /* if we are in te-mode, we need to create a process first */
- if (newteid++ > 0xffff)
- newteid = 0x0001;
-
- l3_id = (entity<<16) | newteid;
- /* preparing message */
- ncr.prim = CC_NEW_CR | REQUEST;
- ncr.addr = (stack->upper_id & IF_ADDRMASK) | IF_DOWN ;
- ncr.dinfo =l3_id;
- ncr.len = 0;
- /* send message */
-
- bc->l3_id = l3_id;
- if (mypid>5000) mypid=0;
- bc->pid=mypid++;
-
- cb_log(3, stack->port, "--> new_l3id %x\n",l3_id);
-
- mISDN_write(midev, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
- }
-
- return l3_id;
-}
-
-
-void misdn_lib_setup_bc(struct misdn_bchannel *bc)
-{
- setup_bc(bc);
-}
-
-
-int setup_bc(struct misdn_bchannel *bc)
-{
- unsigned char buff[1025];
-
- mISDN_pid_t pid;
- int ret;
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- int midev=stack->midev;
- int channel=bc->channel-1-(bc->channel>16);
- int b_stid=stack->b_stids[channel>=0?channel:0];
-
-
- if (bc->nodsp )
- clean_up_bc(bc);
-
- if ( !misdn_cap_is_speech(bc->capability))
- clean_up_bc(bc);
-
-
- if (bc->upset) {
- cb_log(4, stack->port, "$$$ bc already upsetted stid :%x\n", b_stid);
- return -1;
- }
-
- cb_log(5, stack->port, "$$$ Setting up bc with stid :%x\n", b_stid);
-
- if (b_stid <= 0) {
- cb_log(0, stack->port," -- Stid <=0 at the moment on port:%d channel:%d\n",stack->port,channel);
- return 1;
- }
-
-
- bc->b_stid = b_stid;
-
- {
- layer_info_t li;
- memset(&li, 0, sizeof(li));
-
- li.object_id = -1;
- li.extentions = 0;
-
- li.st = bc->b_stid; /* given idx */
-
-
- if ( misdn_cap_is_speech(bc->capability) && !bc->nodsp && bc->async != 1) {
- cb_log(4, stack->port,"setup_bc: with dsp\n");
- {
- int l = sizeof(li.name);
- strncpy(li.name, "B L4", l);
- li.name[l-1] = 0;
- }
- li.pid.layermask = ISDN_LAYER((4));
- li.pid.protocol[4] = ISDN_PID_L4_B_USER;
-
- } else {
- cb_log(4, stack->port,"setup_bc: without dsp\n");
- {
- int l = sizeof(li.name);
- strncpy(li.name, "B L3", l);
- li.name[l-1] = 0;
- }
- li.pid.layermask = ISDN_LAYER((3));
- li.pid.protocol[3] = ISDN_PID_L3_B_USER;
- }
-
- ret = mISDN_new_layer(midev, &li);
- if (ret <= 0) {
- cb_log(0, stack->port,"New Layer Err: %d %s port:%d\n",ret,strerror(errno), stack->port);
- return(-EINVAL);
- }
-
- bc->layer_id = ret;
- }
-
- memset(&pid, 0, sizeof(pid));
-
- bc->addr = ( bc->layer_id & IF_ADDRMASK) | IF_DOWN;
- cb_log(4, stack->port," --> Got Adr %x\n", bc->addr);
- cb_log(4, stack->port," --> Channel is %d\n", bc->channel);
-
-
- if (bc->async == 1 || bc->nodsp) {
- cb_log(4, stack->port," --> TRANSPARENT Mode (no DSP, no HDLC)\n");
- pid.protocol[1] = ISDN_PID_L1_B_64TRANS;
- pid.protocol[2] = ISDN_PID_L2_B_TRANS;
- pid.protocol[3] = ISDN_PID_L3_B_USER;
- pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3));
-
- } else if ( misdn_cap_is_speech(bc->capability)) {
- cb_log(4, stack->port," --> TRANSPARENT Mode\n");
- pid.protocol[1] = ISDN_PID_L1_B_64TRANS;
- pid.protocol[2] = ISDN_PID_L2_B_TRANS;
- pid.protocol[3] = ISDN_PID_L3_B_DSP;
- pid.protocol[4] = ISDN_PID_L4_B_USER;
- pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) | ISDN_LAYER((4));
-
- } else {
- cb_log(4, stack->port," --> HDLC Mode\n");
- pid.protocol[1] = ISDN_PID_L1_B_64HDLC ;
- pid.protocol[2] = ISDN_PID_L2_B_TRANS ;
- pid.protocol[3] = ISDN_PID_L3_B_USER;
- pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) ;
- }
-
- ret = mISDN_set_stack(midev, bc->b_stid, &pid);
-
-
- if (ret){
- cb_log(5, stack->port,"$$$ Set Stack Err: %d %s\n",ret,strerror(errno));
-
- mISDN_write_frame(midev, buff, bc->addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
- return(-EINVAL);
- }
-
- bc->upset=1;
-
- return 0;
-}
-
-
-
-/** IFACE **/
-int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, int port, int bidx, char *msn, int firsttime)
-{
- unsigned char buff[1025];
- iframe_t *frm = (iframe_t *)buff;
- int ret;
-
- if (!bc) return -1;
-
- cb_log(4, port, "Init.BC %d on port:%d\n",bidx, port);
-
- memset(bc, 0,sizeof(struct misdn_bchannel));
-
- if (msn) {
- int l = sizeof(bc->msn);
- strncpy(bc->msn,msn, l);
- bc->msn[l-1] = 0;
- }
-
-
- empty_bc(bc);
- bc->upset=0;
- bc->port=stack->port;
- bc->nt=stack->mode==NT_MODE?1:0;
-
- {
- ibuffer_t* ibuf= init_ibuffer(MISDN_IBUF_SIZE);
- ibuffer_t* mbuf= init_ibuffer(MISDN_IBUF_SIZE);
-
- if (!ibuf) return -1;
- if (!mbuf) return -1;
-
- clear_ibuffer( ibuf);
- clear_ibuffer( mbuf);
-
- ibuf->rsem=malloc(sizeof(sem_t));
- mbuf->rsem=malloc(sizeof(sem_t));
-
- bc->astbuf=ibuf;
- bc->misdnbuf=mbuf;
-
- if (sem_init(ibuf->rsem,1,0)<0)
- sem_init(ibuf->rsem,0,0);
- if (sem_init(mbuf->rsem,1,0)< 0)
- sem_init(mbuf->rsem,0,0);
-
- }
-
-
-
-
- {
- stack_info_t *stinf;
- ret = mISDN_get_stack_info(midev, stack->port, buff, sizeof(buff));
- if (ret < 0) {
- cb_log(0, port, "%s: Cannot get stack info for port:%d (ret=%d)\n", __FUNCTION__, port, ret);
- return -1;
- }
-
- stinf = (stack_info_t *)&frm->data.p;
-
- cb_log(4, port, " --> Child %x\n",stinf->child[bidx]);
- }
-
- return 0;
-}
-
-
-
-struct misdn_stack * stack_nt_init(struct misdn_stack *stack, int midev, int port)
-{
- int ret;
- layer_info_t li;
- interface_info_t ii;
-
-
- cb_log(4, port, "Init. Stack on port:%d\n",port);
- stack->mode = NT_MODE;
-
- stack->lower_id = mISDN_get_layerid(midev, stack->d_stid, 1);
- if (stack->lower_id <= 0) {
- cb_log(0, port, "%s: Cannot get layer(%d) id of port:%d\n", __FUNCTION__, 1, port);
- return(NULL);
- }
-
-
- memset(&li, 0, sizeof(li));
- {
- int l = sizeof(li.name);
- strncpy(li.name,"net l2", l);
- li.name[l-1] = 0;
- }
- li.object_id = -1;
- li.extentions = 0;
- li.pid.protocol[2] = ISDN_PID_L2_LAPD_NET;
- li.pid.layermask = ISDN_LAYER((2));
- li.st = stack->d_stid;
-
-
- stack->upper_id = mISDN_new_layer(midev, &li);
- if (stack->upper_id <= 0) {
- cb_log(0, port, "%s: Cannot add layer %d of port:%d\n", __FUNCTION__, 2, port);
- return(NULL);
- }
-
- cb_log(4, port, "NT Stacks upper_id %x\n",stack->upper_id);
-
- memset(&ii, 0, sizeof(ii));
- ii.extentions = EXT_IF_EXCLUSIV;
- ii.owner = stack->upper_id;
- ii.peer = stack->lower_id;
- ii.stat = IF_DOWN;
- ret = mISDN_connect(midev, &ii);
- if (ret) {
- cb_log(0, port, "%s: Cannot connect layer %d of port:%d exclusively.\n", __FUNCTION__, 2, port);
- return(NULL);
- }
-
- /* create nst (nt-mode only) */
- {
- memset(&stack->nst, 0, sizeof(net_stack_t));
- memset(&stack->mgr, 0, sizeof(manager_t));
-
- stack->mgr.nst = &stack->nst;
- stack->nst.manager = &stack->mgr;
-
- stack->nst.l3_manager = handle_event_nt;
- stack->nst.device = midev;
- stack->nst.cardnr = port;
- stack->nst.d_stid = stack->d_stid;
-
-#ifdef MISDNUSER_JOLLY
- stack->nst.feature = FEATURE_NET_HOLD;
- if (stack->ptp)
- stack->nst.feature |= FEATURE_NET_PTP;
- if (stack->pri)
- stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
-#endif
-
- stack->nst.l1_id = stack->lower_id;
- stack->nst.l2_id = stack->upper_id;
-
- msg_queue_init(&stack->nst.down_queue);
-
- Isdnl2Init(&stack->nst);
- Isdnl3Init(&stack->nst);
- }
-
- misdn_lib_get_l1_up(stack);
-
- if (stack->ptp) {
- misdn_lib_get_l2_up(stack);
- stack->l2link=0;
- }
-
-
- return stack;
-}
-
-
-struct misdn_stack* stack_te_init( int midev, int port, int ptp )
-{
- int ret;
- unsigned char buff[1025];
- iframe_t *frm = (iframe_t *)buff;
- stack_info_t *stinf;
- int i;
- layer_info_t li;
- interface_info_t ii;
- struct misdn_stack *stack = malloc(sizeof(struct misdn_stack));
- if (!stack ) return NULL;
-
-
- //cb_log(2, "Init. Stack on port:%d\n",port);
- cb_log(4, port, "Init. Stack on port:%d\n",port);
-
- memset(stack,0,sizeof(struct misdn_stack));
-
- for (i=0; i<MAX_BCHANS + 1; i++ ) stack->channels[i]=0;
-
- stack->port=port;
- stack->midev=midev;
- stack->ptp=ptp;
-
- stack->holding=NULL;
- stack->pri=0;
-
- msg_queue_init(&stack->downqueue);
-
- /* query port's requirements */
- ret = mISDN_get_stack_info(midev, port, buff, sizeof(buff));
- if (ret < 0) {
- cb_log(0, port, "%s: Cannot get stack info for port:%d (ret=%d)\n", __FUNCTION__, port, ret);
- return(NULL);
- }
-
- stinf = (stack_info_t *)&frm->data.p;
-
- stack->d_stid = stinf->id;
- stack->b_num = stinf->childcnt;
-
- for (i=0; i<stinf->childcnt; i++)
- stack->b_stids[i] = stinf->child[i];
-
- switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK) {
- case ISDN_PID_L0_TE_S0:
- //cb_log(2, "TE Stack\n");
- stack->mode = TE_MODE;
- break;
- case ISDN_PID_L0_NT_S0:
- cb_log(4, port, "NT Stack\n");
-
- return stack_nt_init(stack,midev,port);
- break;
-
- case ISDN_PID_L0_TE_U:
- break;
- case ISDN_PID_L0_NT_U:
- break;
- case ISDN_PID_L0_TE_UP2:
- break;
- case ISDN_PID_L0_NT_UP2:
- break;
- case ISDN_PID_L0_TE_E1:
- cb_log(4, port, "TE S2M Stack\n");
- stack->mode = TE_MODE;
- stack->pri=1;
- break;
- case ISDN_PID_L0_NT_E1:
- cb_log(4, port, "TE S2M Stack\n");
- stack->mode = NT_MODE;
- stack->pri=1;
-
- return stack_nt_init(stack,midev,port);
- break;
- default:
- cb_log(0, port, "unknown port(%d) type 0x%08x\n", port, stinf->pid.protocol[0]);
-
- }
-
- if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP ) { /* || (nt&&ptp) || pri */
- stack->ptp = 1;
- } else {
- stack->ptp = 0;
- }
-
- stack->lower_id = mISDN_get_layerid(midev, stack->d_stid, 3);
- if (stack->lower_id <= 0) {
- cb_log(0, stack->port, "No lower Id port:%d\n", stack->port);
- return(NULL);
- }
-
- memset(&li, 0, sizeof(li));
- {
- int l = sizeof(li.name);
- strncpy(li.name, "user L4", l);
- li.name[l-1] = 0;
- }
- li.object_id = -1;
- li.extentions = 0;
-
- li.pid.protocol[4] = ISDN_PID_L4_CAPI20;
-
- li.pid.layermask = ISDN_LAYER((4));
- li.st = stack->d_stid;
- stack->upper_id = mISDN_new_layer(midev, &li);
-
- if (stack->upper_id <= 0) {
- cb_log(0, stack->port, "No Upper ID port:%d\n",stack->port);
- return(NULL);
- }
-
- memset(&ii, 0, sizeof(ii));
- ii.extentions = EXT_IF_EXCLUSIV | EXT_IF_CREATE;
- ii.owner = stack->upper_id;
- ii.peer = stack->lower_id;
- ii.stat = IF_DOWN;
- ret = mISDN_connect(midev, &ii);
- if (ret) {
- cb_log(0, stack->port, "No Connect port:%d\n", stack->port);
- return NULL;
- }
-
- misdn_lib_get_l1_up(stack);
- misdn_lib_get_l2_status(stack);
-
- /* initially, we assume that the link is NOT up */
- stack->l2link = 0;
- stack->l1link = 0;
-
- stack->next=NULL;
-
- return stack;
-
-}
-
-void stack_te_destroy(struct misdn_stack* stack)
-{
- char buf[1024];
- if (!stack) return;
-
- if (stack->lower_id)
- mISDN_write_frame(stack->midev, buf, stack->lower_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
-
- if (stack->upper_id)
- mISDN_write_frame(stack->midev, buf, stack->upper_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
-}
-
-
-struct misdn_stack * find_stack_by_addr(int addr)
-{
- struct misdn_stack *stack;
-
- for (stack=glob_mgr->stack_list;
- stack;
- stack=stack->next) {
- if ( stack->upper_id == addr) return stack;
- }
-
- return NULL;
-}
-
-
-struct misdn_stack * find_stack_by_port(int port)
-{
- struct misdn_stack *stack;
-
- for (stack=glob_mgr->stack_list;
- stack;
- stack=stack->next)
- if (stack->port == port) return stack;
-
- return NULL;
-}
-
-struct misdn_stack * find_stack_by_mgr(manager_t* mgr_nt)
-{
- struct misdn_stack *stack;
-
- for (stack=glob_mgr->stack_list;
- stack;
- stack=stack->next)
- if ( &stack->mgr == mgr_nt) return stack;
-
- return NULL;
-}
-
-struct misdn_bchannel *find_bc_by_masked_l3id(struct misdn_stack *stack, unsigned long l3id, unsigned long mask)
-{
- int i;
- for (i=0; i<stack->b_num; i++) {
- if ( (stack->bc[i].l3_id & mask) == (l3id & mask)) return &stack->bc[i] ;
- }
- return stack_holder_find(stack,l3id);
-}
-
-
-struct misdn_bchannel *find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id)
-{
- int i;
- for (i=0; i<stack->b_num; i++) {
- if (stack->bc[i].l3_id == l3id) return &stack->bc[i] ;
- }
- return stack_holder_find(stack,l3id);
-}
-
-struct misdn_bchannel *find_bc_holded(struct misdn_stack *stack)
-{
- int i;
- for (i=0; i<stack->b_num; i++) {
- if (stack->bc[i].holded ) return &stack->bc[i] ;
- }
- return NULL;
-}
-
-
-struct misdn_bchannel *find_bc_by_addr(unsigned long addr)
-{
- int port = addr & IF_CONTRMASK;
- struct misdn_stack* stack;
- int i;
-
-
- for (stack=glob_mgr->stack_list;
- stack;
- stack=stack->next) {
-
- if (stack->port == port) {
- for (i=0; i< stack->b_num; i++) {
- if (stack->bc[i].addr==addr) {
- return &stack->bc[i];
- }
- }
- }
- }
-
- return NULL;
-}
-
-
-
-
-int handle_event ( struct misdn_bchannel *bc, enum event_e event, iframe_t *frm)
-{
- struct misdn_stack *stack=get_stack_by_bc(bc);
- if (stack->mode == TE_MODE) {
- switch (event) {
-
- case EVENT_CONNECT_ACKNOWLEDGE:
- manager_bchannel_activate(bc);
- break;
- case EVENT_CONNECT:
-
- if ( *bc->crypt_key ) {
- cb_log(4, stack->port, "ENABLING BLOWFISH port:%d channel:%d oad%d:%s dad%d:%s\n", stack->port, bc->channel, bc->onumplan,bc->oad, bc->dnumplan,bc->dad);
-
- manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
- }
- case EVENT_SETUP:
- if (bc->channel>0 && bc->channel<255)
- set_chan_in_stack(stack, bc->channel);
- break;
- case EVENT_ALERTING:
- case EVENT_PROGRESS:
- case EVENT_PROCEEDING:
- case EVENT_SETUP_ACKNOWLEDGE:
-
- {
- struct misdn_stack *stack=find_stack_by_port(frm->addr&IF_CONTRMASK);
- if (!stack) return -1;
-
- if (bc->channel == 0xff) {
- bc->channel=find_free_chan_in_stack(stack, 0);
- if (!bc->channel) {
- cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n");
- break;
- }
- }
-
- if (stack->mode == TE_MODE) {
- setup_bc(bc);
- }
- }
-
- default:
- break;
- }
- } else { /** NT MODE **/
-
- }
- return 0;
-}
-
-int handle_new_process(struct misdn_stack *stack, iframe_t *frm)
-{
-
- struct misdn_bchannel* bc=misdn_lib_get_free_bc(frm->addr&IF_CONTRMASK, 0);
-
- if (!bc) {
- cb_log(0, 0, " --> !! lib: No free channel!\n");
- return -1;
- }
-
- cb_log(4, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo);
- bc->l3_id=frm->dinfo;
-
- if (mypid>5000) mypid=0;
- bc->pid=mypid++;
- return 0;
-}
-
-int handle_cr ( iframe_t *frm)
-{
- struct misdn_stack *stack=find_stack_by_port(frm->addr&IF_CONTRMASK);
-
- if (!stack) return -1;
-
- switch (frm->prim) {
- case CC_NEW_CR|INDICATION:
- cb_log(4, stack->port, " --> lib: NEW_CR Ind with l3id:%x port:%d\n",frm->dinfo, stack->port);
- handle_new_process(stack, frm);
- return 1;
- case CC_NEW_CR|CONFIRM:
- return 1;
- case CC_NEW_CR|REQUEST:
- return 1;
- case CC_RELEASE_CR|REQUEST:
- return 1;
- case CC_RELEASE_CR|CONFIRM:
- break;
- case CC_RELEASE_CR|INDICATION:
- cb_log(4, stack->port, " --> lib: RELEASE_CR Ind with l3id:%x\n",frm->dinfo);
- {
- struct misdn_bchannel *bc=find_bc_by_l3id(stack, frm->dinfo);
- struct misdn_bchannel dummybc;
-
- if (!bc) {
- cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on port:%d\n", frm->dinfo, stack->port);
- memset (&dummybc,0,sizeof(dummybc));
- dummybc.port=stack->port;
- dummybc.l3_id=frm->dinfo;
- bc=&dummybc;
- }
-
- if (bc) {
- cb_log(4, stack->port, " --> lib: CLEANING UP l3id: %x\n",frm->dinfo);
- empty_chan_in_stack(stack,bc->channel);
- empty_bc(bc);
- clean_up_bc(bc);
- dump_chan_list(stack);
- bc->pid = 0;
- cb_event(EVENT_CLEANUP, bc, glob_mgr->user_data);
-
- if (bc->stack_holder) {
- cb_log(4,stack->port, "REMOVEING Holder\n");
- stack_holder_remove( stack, bc);
- free(bc);
- }
- }
- else {
- if (stack->mode == NT_MODE)
- cb_log(4, stack->port, "BC with dinfo: %x not found.. (prim was %x and addr %x)\n",frm->dinfo, frm->prim, frm->addr);
- }
-
- return 1;
- }
- break;
- }
-
- return 0;
-}
-
-
-/*Emptys bc if it's reserved (no SETUP out yet)*/
-void misdn_lib_release(struct misdn_bchannel *bc)
-{
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- if (!stack) {
- cb_log(1,0,"misdn_release: No Stack found\n");
- return;
- }
-
- if (bc->channel>=0) {
- empty_chan_in_stack(stack,bc->channel);
- empty_bc(bc);
- }
- clean_up_bc(bc);
-}
-
-
-
-
-int misdn_lib_get_port_up (int port)
-{ /* Pull Up L1 if we have JOLLY */
- struct misdn_stack *stack;
-
- for (stack=glob_mgr->stack_list;
- stack;
- stack=stack->next) {
-
- if (stack->port == port) {
-
- if (!stack->l1link)
- misdn_lib_get_l1_up(stack);
- if (!stack->l2link)
- misdn_lib_get_l2_up(stack);
-
- return 0;
- }
- }
- return 0;
-}
-
-
-int misdn_lib_send_facility(struct misdn_bchannel *bc, enum facility_type fac, void *data)
-{
- bc->facility=fac;
- strcpy(bc->facility_calldeflect_nr,(char*)data);
-
- misdn_lib_send_event(bc,EVENT_FACILITY);
- return 0;
-}
-
-
-int misdn_lib_port_up(int port)
-{
- struct misdn_stack *stack;
-
- for (stack=glob_mgr->stack_list;
- stack;
- stack=stack->next) {
-
- if (stack->port == port) {
- if (stack->mode == NT_MODE) {
- if (stack->l1link)
- return 1;
- else
- return 0;
- } else {
- if (stack->l1link)
- return 1;
- else
- return 0;
- }
-
- }
- }
-
- return -1;
-}
-
-
-int
-handle_event_nt(void *dat, void *arg)
-{
- manager_t *mgr = (manager_t *)dat;
- msg_t *msg = (msg_t *)arg;
-#ifdef MISDNUSER_JOLLY
- mISDNuser_head_t *hh;
-#else
- mISDN_head_t *hh;
-#endif
- struct misdn_stack *stack=find_stack_by_mgr(mgr);
- int port;
-
- if (!msg || !mgr)
- return(-EINVAL);
-
-#ifdef MISDNUSER_JOLLY
- hh=(mISDNuser_head_t*)msg->data;
-#else
- hh=(mISDN_head_t*)msg->data;
-#endif
-
- port=hh->dinfo & IF_CONTRMASK;
-
- cb_log(4, stack->port, " --> lib: prim %x dinfo %x port: %d\n",hh->prim, hh->dinfo ,stack->port);
-
- {
- switch(hh->prim){
-
- case CC_RETRIEVE|INDICATION:
- {
- iframe_t frm; /* fake te frm to add callref to global callreflist */
- frm.dinfo = hh->dinfo;
- frm.addr=stack->upper_id;
- frm.prim = CC_NEW_CR|INDICATION;
-
- if (handle_cr(&frm)< 0) {
- msg_t *dmsg;
- cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo);
- dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
- stack->nst.manager_l3(&stack->nst, dmsg);
- free_msg(msg);
- return 0;
- }
-
- struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
- cb_event(EVENT_NEW_BC, bc, glob_mgr->user_data);
- struct misdn_bchannel *hold_bc=stack_holder_find(stack,bc->l3_id);
- if (hold_bc) {
- cb_log(4, stack->port, "REMOVEING Holder\n");
- stack_holder_remove(stack, hold_bc);
- free(hold_bc);
- }
-
- }
-
- break;
-
-
- case CC_SETUP|CONFIRM:
- {
- struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
- int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE));
-
- cb_log(4, bc?stack->port:0, " --> lib: Event_ind:SETUP CONFIRM [NT] : new L3ID is %x\n",l3id );
-
- if (!bc) { cb_log(4, 0, "Bc Not found (after SETUP CONFIRM)\n"); return 0; }
-
- bc->l3_id=l3id;
- cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data);
- }
- free_msg(msg);
- return 0;
-
- case CC_SETUP|INDICATION:
- {
- iframe_t frm; /* fake te frm to add callref to global callreflist */
- frm.dinfo = hh->dinfo;
- frm.addr=stack->upper_id;
- frm.prim = CC_NEW_CR|INDICATION;
-
- if (handle_cr(&frm)< 0) {
- msg_t *dmsg;
- cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo);
- dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
- stack->nst.manager_l3(&stack->nst, dmsg);
- free_msg(msg);
- return 0;
- }
- }
- break;
-
-
- case CC_CONNECT|INDICATION:
- case CC_ALERTING|INDICATION:
- case CC_PROCEEDING|INDICATION:
-
- {
- struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
-
- if (!bc) {
- msg_t *dmsg;
- cb_log(0, stack->port,"!!!! We didn't found our bc, dinfo:%x port:%d\n",hh->dinfo, stack->port);
-
- cb_log(0, stack->port, "Releaseing call %x (No free Chan for you..)\n", hh->dinfo);
- dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
- stack->nst.manager_l3(&stack->nst, dmsg);
- free_msg(msg);
- return 0;
-
- }
-
- setup_bc(bc);
- }
- break;
- case CC_DISCONNECT|INDICATION:
- {
- struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
- if (!bc) {
- bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000);
- if (bc) { //repair reject bug
- int myprocid=bc->l3_id&0x0000ffff;
- hh->dinfo=(hh->dinfo&0xffff0000)|myprocid;
- cb_log(4,stack->port,"Repaired reject Bug, new dinfo: %x\n",hh->dinfo);
- }
- }
- }
- break;
-
- case CC_RELEASE_COMPLETE|INDICATION:
- break;
-
- case CC_SUSPEND|INDICATION:
- {
- msg_t *dmsg;
- cb_log(4, stack->port, " --> Got Suspend, sending Reject for now\n");
- dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST,MT_SUSPEND_REJECT, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
- stack->nst.manager_l3(&stack->nst, dmsg);
- free_msg(msg);
- return 0;
- }
- break;
- case CC_RESUME|INDICATION:
- break;
-
- case CC_RELEASE|CONFIRM:
- {
- struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
- cb_log(4, stack->port, " --> RELEASE CONFIRM, sending RELEASE_COMPLETE\n");
- if (bc) misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
- }
- hh->prim=CC_RELEASE|INDICATION;
- break;
- case CC_RELEASE|INDICATION:
- break;
-
- case CC_RELEASE_CR|INDICATION:
- {
- struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
- struct misdn_bchannel dummybc;
- iframe_t frm; /* fake te frm to remove callref from global callreflist */
- frm.dinfo = hh->dinfo;
- frm.addr=stack->upper_id;
- frm.prim = CC_RELEASE_CR|INDICATION;
- cb_log(4, stack->port, " --> Faking Realease_cr for %x\n",frm.addr);
- /** removing procid **/
-
- if (!bc) {
- cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on port:%d\n", hh->dinfo, stack->port);
- memset (&dummybc,0,sizeof(dummybc));
- dummybc.port=stack->port;
- dummybc.l3_id=hh->dinfo;
- bc=&dummybc;
- }
-
- if (bc) {
-#ifdef MISDNUSER_JOLLY
- if ( (bc->l3_id & 0xff00) == 0xff00) {
- cb_log(4, stack->port, " --> Removing Process Id:%x on port:%d\n", bc->l3_id&0xff, stack->port);
- stack->procids[bc->l3_id&0xff] = 0 ;
- }
-#else
- if ( (bc->l3_id & 0xfff0) == 0xfff0) {
- cb_log(4, stack->port, " --> Removing Process Id:%x on port:%d\n", bc->l3_id&0xf, stack->port);
- stack->procids[bc->l3_id&0xf] = 0 ;
-
- }
-
-#endif
-
- }
- else cb_log(0, stack->port, "Couldnt find BC so I couldnt remove the Process!!!! this is bad Port:%d\n", stack->port );
-
- handle_cr(&frm);
- free_msg(msg);
- return 0 ;
- }
-
- break;
-
- case CC_NEW_CR|INDICATION:
- /* Got New CR for bchan, for now I handle this one in */
- /* connect_ack, Need to be changed */
- {
- struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
- int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE));
- if (!bc) { cb_log(0, 0, " --> In NEW_CR: didn't found bc ??\n"); return -1;};
-#ifdef MISDNUSER_JOLLY
- if (((l3id&0xff00)!=0xff00) && ((bc->l3_id&0xff00)==0xff00)) {
- cb_log(4, stack->port, " --> Removing Process Id:%x on port:%d\n", 0xff&bc->l3_id, stack->port);
- stack->procids[bc->l3_id&0xff] = 0 ;
- }
-#else
- if (((l3id&0xfff0)!=0xfff0) && ((bc->l3_id&0xfff0)==0xfff0)) {
- cb_log(4, stack->port, "Removing Process Id:%x on port:%d\n", 0xf&bc->l3_id, stack->port);
- stack->procids[bc->l3_id&0xf] = 0 ;
- }
-
-#endif
- cb_log(4, stack->port, "lib: Event_ind:CC_NEW_CR : very new L3ID is %x\n",l3id );
-
- bc->l3_id =l3id;
- cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data);
-
-
- free_msg(msg);
- return 0;
- }
-
- case DL_ESTABLISH | INDICATION:
- case DL_ESTABLISH | CONFIRM:
- {
- cb_log(4, stack->port, "%% GOT L2 Activate Info port:%d\n",stack->port);
- stack->l2link = 1;
-
- free_msg(msg);
- return 0;
- }
- break;
-
- case DL_RELEASE | INDICATION:
- case DL_RELEASE | CONFIRM:
- {
- cb_log(4, stack->port, "%% GOT L2 DeActivate Info port:%d\n",stack->port);
- stack->l2link = 0;
-
- /** Clean the L3 here **/
- if (cb_clearl3_true())
- clear_l3(stack);
-
- free_msg(msg);
- return 0;
- }
- break;
- }
- }
-
-
-
- {
- /* Parse Events and fire_up to App. */
- struct misdn_bchannel *bc;
- struct misdn_bchannel dummybc;
-
- enum event_e event = isdn_msg_get_event(msgs_g, msg, 1);
-
- bc=find_bc_by_l3id(stack, hh->dinfo);
-
- if (!bc) {
-
- cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on port:%d\n", hh->dinfo, stack->port);
- memset (&dummybc,0,sizeof(dummybc));
- dummybc.port=stack->port;
- dummybc.l3_id=hh->dinfo;
- bc=&dummybc;
- }
- if (bc ) {
- isdn_msg_parse_event(msgs_g,msg,bc, 1);
-
- if(!isdn_get_info(msgs_g,event,1)) {
- cb_log(4, stack->port, "Unknown Event Ind: prim %x dinfo %x\n",hh->prim, hh->dinfo);
- } else {
- cb_event(event, bc, glob_mgr->user_data);
- }
-
-
- } else {
- cb_log(4, stack->port, "No BC found with l3id: prim %x dinfo %x\n",hh->prim, hh->dinfo);
- }
-
- free_msg(msg);
- }
-
-
- return 0;
-}
-
-
-int handle_timers(msg_t* msg)
-{
- iframe_t *frm= (iframe_t*)msg->data;
- struct misdn_stack *stack;
-
- /* Timer Stuff */
- switch (frm->prim) {
- case MGR_INITTIMER | CONFIRM:
- case MGR_ADDTIMER | CONFIRM:
- case MGR_DELTIMER | CONFIRM:
- case MGR_REMOVETIMER | CONFIRM:
- free_msg(msg);
- return(1);
- }
-
-
-
- if (frm->prim==(MGR_TIMER | INDICATION) ) {
- for (stack = glob_mgr->stack_list;
- stack;
- stack = stack->next) {
- itimer_t *it;
-
- if (stack->mode != NT_MODE) continue;
-
- it = stack->nst.tlist;
- /* find timer */
- for(it=stack->nst.tlist;
- it;
- it=it->next) {
- if (it->id == (int)frm->addr)
- break;
- }
- if (it) {
- int ret;
- ret = mISDN_write_frame(stack->midev, msg->data, frm->addr,
- MGR_TIMER | RESPONSE, 0, 0, NULL, TIMEOUT_1SEC);
- test_and_clear_bit(FLG_TIMER_RUNING, (long unsigned int *)&it->Flags);
- ret = it->function(it->data);
- free_msg(msg);
- return 1;
- }
- }
-
- cb_log(0, 0, "Timer Msg without Timer ??\n");
- free_msg(msg);
- return 1;
- }
-
- return 0;
-}
-
-
-
-
-static int do_tone(struct misdn_bchannel *bc, int len)
-{
- char buf[4096 + mISDN_HEADER_LEN];
- iframe_t *frm= (iframe_t*)buf;
- int r;
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- if (bc->tone == TONE_NONE) return 0;
-
- frm->prim = DL_DATA|REQUEST;
- frm->dinfo = 0;
- frm->addr = bc->addr | IF_DOWN;
-
- bc->tone_cnt+=len;
-
- if (bc->tone_cnt < TONE_425_SIZE) return 1;
-
- switch(bc->tone) {
- case TONE_DIAL:
- {
- frm->len = TONE_425_SIZE;
- memcpy(&buf[mISDN_HEADER_LEN], tone_425_flip,TONE_425_SIZE);
-
- r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_1SEC);
- if (r<frm->len) {
- perror("Error written less than told bytes :(\n");
- }
- }
- break;
-
- case TONE_ALERTING:
- bc->tone_cnt2++;
-
- if (bc->tone_cnt2 <= TONE_ALERT_CNT) {
- frm->len = TONE_425_SIZE;
- memcpy(&buf[mISDN_HEADER_LEN], tone_425_flip,TONE_425_SIZE);
- r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_1SEC);
- if (r<frm->len) {
- perror("Error written less than told bytes :(\n");
- }
- } else if (bc->tone_cnt2 <= (TONE_ALERT_SILENCE_CNT)) {
- frm->len = TONE_SILENCE_SIZE;
- memcpy(&buf[mISDN_HEADER_LEN], tone_silence_flip ,TONE_SILENCE_SIZE);
- r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_1SEC);
- } else {
- bc->tone_cnt2=-1;
- }
- break;
- case TONE_BUSY:
- bc->tone_cnt2++;
-
- if (bc->tone_cnt2 <= TONE_BUSY_CNT) {
- frm->len = TONE_425_SIZE;
- memcpy(&buf[mISDN_HEADER_LEN], tone_425_flip,TONE_425_SIZE);
- r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_1SEC);
- if (r<frm->len) {
- perror("Error written less than told bytes :(\n");
- }
- } else if (bc->tone_cnt2 <= (TONE_BUSY_SILENCE_CNT)) {
- frm->len = TONE_SILENCE_SIZE;
- memcpy(&buf[mISDN_HEADER_LEN], tone_silence_flip ,TONE_SILENCE_SIZE);
- r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_1SEC);
- } else {
- bc->tone_cnt2=-1;
- }
- break;
- case TONE_FILE:
- break;
- case TONE_NONE:
- return 0;
- }
-
- bc->tone_cnt -= TONE_425_SIZE ;
- return 1;
-}
-
-
-
-int handle_bchan(msg_t *msg)
-{
- iframe_t *frm= (iframe_t*)msg->data;
- struct misdn_bchannel *bc;
-
- bc=find_bc_by_addr(frm->addr);
-
- if (!bc) return 0 ;
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- if (!stack) return 0;
-
- switch (frm->prim) {
- case PH_ACTIVATE | INDICATION:
- case DL_ESTABLISH | INDICATION:
- cb_log(4, stack->port, "BCHAN: ACT Ind\n");
- free_msg(msg);
- return 1;
-
- case PH_ACTIVATE | CONFIRM:
- case DL_ESTABLISH | CONFIRM:
- cb_log(4, stack->port, "BCHAN: bchan ACT Confirm\n");
- free_msg(msg);
-
- return 1;
-
- case PH_DEACTIVATE | INDICATION:
- case DL_RELEASE | INDICATION:
- cb_log (4, stack->port, "BCHAN: DeACT Ind\n");
- free_msg(msg);
- return 1;
-
- case PH_DEACTIVATE | CONFIRM:
- case DL_RELEASE | CONFIRM:
- cb_log(4, stack->port, "BCHAN: DeACT Conf\n");
- free_msg(msg);
- return 1;
-
- case PH_CONTROL|INDICATION:
- {
- unsigned long cont = *((unsigned long *)&frm->data.p);
-
- cb_log(4, stack->port, "PH_CONTROL: port:%d channel:%d oad%d:%s dad%d:%s \n", stack->port, bc->channel, bc->onumplan,bc->oad, bc->dnumplan,bc->dad);
-
- if ((cont&~DTMF_TONE_MASK) == DTMF_TONE_VAL) {
- int dtmf = cont & DTMF_TONE_MASK;
- cb_log(4, stack->port, " --> DTMF TONE: %c\n",dtmf);
- bc->dtmf=dtmf;
- cb_event(EVENT_DTMF_TONE, bc, glob_mgr->user_data);
-
- free_msg(msg);
- return 1;
- }
- if (cont == BF_REJECT) {
- cb_log(4, stack->port, " --> BF REJECT\n");
- free_msg(msg);
- return 1;
- }
- if (cont == BF_ACCEPT) {
- cb_log(4, stack->port, " --> BF ACCEPT\n");
- free_msg(msg);
- return 1;
- }
- }
- break;
-
- case PH_DATA|INDICATION:
- case DL_DATA|INDICATION:
- {
- bc->bframe = (void*)&frm->data.i;
- bc->bframe_len = frm->len;
-
- /** Anyway flip the bufbits **/
- if ( misdn_cap_is_speech(bc->capability) )
- flip_buf_bits(bc->bframe, bc->bframe_len);
-
-
-#if MISDN_DEBUG
- cb_log(0, stack->port, "DL_DATA INDICATION Len %d\n", frm->len);
-#endif
-
- if (bc->active && frm->len > 0) {
- if ( !do_tone(bc, frm->len) ) {
-
- if ( misdn_cap_is_speech(bc->capability)) {
- if ( !bc->nojitter ) {
- char buf[4096 + mISDN_HEADER_LEN];
- iframe_t *txfrm= (iframe_t*)buf;
- int len, r;
-
- len = ibuf_usedcount(bc->misdnbuf);
-
- if (len < frm->len) {
- /** send nothing
- * till we are synced
- **/
- } else {
-
- txfrm->prim = DL_DATA|REQUEST;
- txfrm->dinfo = 0;
- txfrm->addr = bc->addr; /* | IF_DOWN; */
- txfrm->len = frm->len;
- ibuf_memcpy_r(&buf[mISDN_HEADER_LEN], bc->misdnbuf,frm->len);
- cb_log(9, stack->port, "Transmitting %d samples 2 misdn\n", txfrm->len);
-
- r=mISDN_write(stack->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 );
-
- }
-
- }
- }
-
- cb_event( EVENT_BCHAN_DATA, bc, glob_mgr->user_data);
- }
- }
- free_msg(msg);
- return 1;
- }
-
-
- case PH_DATA | CONFIRM:
- case DL_DATA|CONFIRM:
-#if MISDN_DEBUG
- cb_log(0, stack->port, "Data confirmed\n");
-#endif
- free_msg(msg);
- return 1;
- break;
- case DL_DATA|RESPONSE:
-#if MISDN_DEBUG
- cb_log(0, stack->port, "Data response\n");
-#endif
- break;
-
- case DL_DATA | REQUEST:
- break;
- }
-
- return 0;
-}
-
-
-
-int handle_frm_nt(msg_t *msg)
-{
- iframe_t *frm= (iframe_t*)msg->data;
- struct misdn_stack *stack;
- int err=0;
-
- stack=find_stack_by_addr((frm->addr & IF_ADDRMASK ) );
-
- if (!stack || stack->mode != NT_MODE) {
- return 0;
- }
-
-
- if ((err=stack->nst.l1_l2(&stack->nst,msg))) {
-
- if (nt_err_cnt > 0 ) {
- if (nt_err_cnt < 100) {
- nt_err_cnt++;
- cb_log(0, stack->port, "NT Stack sends us error: %d port:%d\n", err,stack->port);
- } else if (nt_err_cnt < 105){
- cb_log(0, stack->port, "NT Stack sends us error: %d port:%d over 100 times, so I'll stop this message\n", err,stack->port);
- nt_err_cnt = - 1;
- }
- }
- free_msg(msg);
- return 1;
-
- }
-
- return 1;
-}
-
-
-int handle_frm(msg_t *msg)
-{
- iframe_t *frm = (iframe_t*) msg->data;
- struct misdn_stack *stack=find_stack_by_addr(frm->addr & IF_ADDRMASK);
-
- if (!stack || stack->mode != TE_MODE) {
- return 0;
- }
-
- {
- struct misdn_bchannel *bc;
-
- if(handle_cr(frm)) {
- free_msg(msg);
- return 1;
- }
-
- bc=find_bc_by_l3id(stack, frm->dinfo);
-
- if (bc ) {
- enum event_e event = isdn_msg_get_event(msgs_g, msg, 0);
- enum event_response_e response=RESPONSE_OK;
-
- isdn_msg_parse_event(msgs_g,msg,bc, 0);
-
- /** Preprocess some Events **/
- handle_event(bc, event, frm);
- /* shoot up event to App: */
- cb_log(5, stack->port, "lib Got Prim: Addr %x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo);
-
- if(!isdn_get_info(msgs_g,event,0))
- cb_log(0, stack->port, "Unknown Event Ind: Addr:%x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo);
- else
- response=cb_event(event, bc, glob_mgr->user_data);
-#if 1
- if (event == EVENT_SETUP) {
- switch (response) {
- case RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE:
- cb_log(0, stack->port, "TOTALY IGNORING SETUP: port:%d\n", frm->addr&IF_CONTRMASK);
- break;
- case RESPONSE_IGNORE_SETUP:
- /* I think we should send CC_RELEASE_CR, but am not sure*/
- empty_chan_in_stack(stack, bc->channel);
- empty_bc(bc);
-
- cb_log(0, stack->port, "GOT IGNORE SETUP: port:%d\n", frm->addr&IF_CONTRMASK);
- break;
- case RESPONSE_OK:
- cb_log(4, stack->port, "GOT SETUP OK: port:%d\n", frm->addr&IF_CONTRMASK);
- break;
- default:
- break;
- }
- }
-
- cb_log(5, stack->port, "Freeing Msg on prim:%x port:%d\n",frm->prim, frm->addr&IF_CONTRMASK);
- free_msg(msg);
- return 1;
-#endif
-
- } else {
- cb_log(0, stack->port, "NO BC FOR STACK: port:%d\n", frm->addr&IF_CONTRMASK);
- }
-
- }
- cb_log(4, stack->port, "TE_FRM_HANDLER: Returning 0 on prim:%x port:%d\n",frm->prim, frm->addr&IF_CONTRMASK);
-
- return 0;
-}
-
-
-int handle_l1(msg_t *msg)
-{
- iframe_t *frm = (iframe_t*) msg->data;
- struct misdn_stack *stack = find_stack_by_port(frm->addr & IF_CONTRMASK);
- int i ;
-
- if (!stack) return 0 ;
-
- switch (frm->prim) {
- case PH_ACTIVATE | CONFIRM:
- case PH_ACTIVATE | INDICATION:
- cb_log (1, stack->port, "L1: PH L1Link Up! port:%d\n",stack->port);
- stack->l1link=1;
-
- if (stack->mode==NT_MODE) {
-
- if (stack->nst.l1_l2(&stack->nst, msg))
- free_msg(msg);
- } else {
- free_msg(msg);
- }
-
- for (i=0;i<stack->b_num; i++) {
- if (stack->bc[i].evq != EVENT_NOTHING) {
- cb_log(4, stack->port, "Fireing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0));
- misdn_lib_send_event(&stack->bc[i],stack->bc[i].evq);
- stack->bc[i].evq=EVENT_NOTHING;
- }
-
- }
-
- return 1;
- case PH_DEACTIVATE | CONFIRM:
- case PH_DEACTIVATE | INDICATION:
- cb_log (1, stack->port, "L1: PH L1Link Down! port:%d\n",stack->port);
-
- for (i=0; i<stack->b_num; i++) {
- if (global_state == MISDN_INITIALIZED) {
- cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data);
- }
-
- }
-
- if (stack->mode==NT_MODE) {
- if (stack->nst.l1_l2(&stack->nst, msg))
- free_msg(msg);
-
- } else {
- free_msg(msg);
- }
-
- stack->l1link=0;
- stack->l2link=0;
-
- return 1;
- }
-
- return 0;
-}
-
-int handle_l2(msg_t *msg)
-{
- iframe_t *frm = (iframe_t*) msg->data;
- struct misdn_stack *stack = find_stack_by_addr(frm->addr & IF_ADDRMASK);
-
- if (!stack) return 0 ;
-
- switch(frm->prim) {
-
-#ifdef DL_STATUS
- case DL_STATUS | INDICATION:
- case DL_STATUS | CONFIRM:
- cb_log (3, stack->port, "L2: DL_STATUS! port:%d\n", stack->port);
-
- switch (frm->dinfo) {
- case SDL_ESTAB:
- cb_log (4, stack->port, " --> SDL_ESTAB port:%d\n", stack->port);
- stack->l1link=1;
- goto dl_estab;
- case SDL_REL:
- cb_log (4, stack->port, " --> SDL_REL port:%d\n", stack->port);
- stack->l1link=0;
- misdn_lib_get_l2_up(stack);
- goto dl_rel;
- }
- break;
-#endif
-
-
- case DL_ESTABLISH | INDICATION:
- case DL_ESTABLISH | CONFIRM:
-#ifdef DL_STATUS
- dl_estab:
-#endif
- {
- cb_log (3, stack->port, "L2: L2Link Up! port:%d\n", stack->port);
- stack->l2link=1;
- free_msg(msg);
- return 1;
- }
- break;
-
- case DL_RELEASE | INDICATION:
- case DL_RELEASE | CONFIRM:
-#ifdef DL_STATUS
- dl_rel:
-#endif
- {
- cb_log (3, stack->port, "L2: L2Link Down! port:%d\n", stack->port);
- stack->l2link=0;
-
- free_msg(msg);
- return 1;
- }
- break;
- }
- return 0;
-}
-
-
-int handle_mgmt(msg_t *msg)
-{
- iframe_t *frm = (iframe_t*) msg->data;
-
- if ( (frm->prim & 0x0f0000) == 0x0f0000) {
- cb_log(5, 0, "$$$ MGMT FRAME: prim %x addr %x dinfo %x\n",frm->prim, frm->addr, frm->dinfo) ;
- free_msg(msg);
- return 1;
- }
-
- return 0;
-}
-
-
-msg_t *fetch_msg(int midev)
-{
- msg_t *msg=alloc_msg(MAX_MSG_SIZE);
- int r;
- fd_set rdfs;
-
- if (!msg) {
- cb_log(0, 0, "fetch_msg: alloc msg failed !!");
- return NULL;
- }
-
- FD_ZERO(&rdfs);
- FD_SET(midev,&rdfs);
-
- mISDN_select(FD_SETSIZE, &rdfs, NULL, NULL, NULL);
-
- if (FD_ISSET(midev, &rdfs)) {
-
- r=mISDN_read(midev,msg->data,MAX_MSG_SIZE,0);
- msg->len=r;
-
- if (r==0) {
- free_msg(msg); /* danger, cauz usualy freeing in main_loop */
- printf ("Got empty Msg?\n");
- return NULL;
- }
-
- return msg;
- } else {
- printf ("Select timeout\n");
- }
-
- return NULL;
-}
-
-
-static void misdn_lib_isdn_event_catcher(void *arg)
-{
- struct misdn_lib *mgr = arg;
- int zero_frm=0 , fff_frm=0 ;
- int midev= mgr->midev;
- int port;
-
- //cb_log(5, 0, "In event_catcher thread\n");
-
- while (1) {
- msg_t *msg = fetch_msg(midev);
- iframe_t *frm;
-
-
- if (!msg) continue;
-
- frm = (iframe_t*) msg->data;
- port = frm->addr&IF_CONTRMASK;
-
- /** When we make a call from NT2Ast we get this frames **/
- if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) {
- zero_frm++;
- free_msg(msg);
- continue;
- } else {
- if (zero_frm) {
- cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm);
- zero_frm = 0 ;
- }
- }
-
- /** I get this sometimes after setup_bc **/
- if (frm->len == 0 && frm->dinfo == 0 && frm->prim == 0xffffffff ) {
- fff_frm++;
- free_msg(msg);
- continue;
- } else {
- if (fff_frm) {
- cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm);
- fff_frm = 0 ;
- }
- }
-
- manager_isdn_handler(frm, msg);
- }
-
-}
-
-
-/** App Interface **/
-
-int te_lib_init() {
- char buff[1025];
- iframe_t *frm=(iframe_t*)buff;
- int midev=mISDN_open();
- int ret;
-
- memset(buff,0,1025);
-
- if (midev<=0) return midev;
-
-/* create entity for layer 3 TE-mode */
- mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
- ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC);
-
- if (ret < mISDN_HEADER_LEN) {
- noentity:
- fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n",strerror(errno));
- exit(-1);
- }
-
- entity = frm->dinfo & 0xffff ;
-
- if (!entity)
- goto noentity;
-
- return midev;
-
-}
-
-void te_lib_destroy(int midev)
-{
- char buf[1024];
- mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC);
-
- cb_log(4, 0, "Entetity deleted\n");
- mISDN_close(midev);
- cb_log(4, 0, "midev closed\n");
-}
-
-
-
-void misdn_lib_transfer(struct misdn_bchannel* holded_bc)
-{
- holded_bc->holded=0;
-}
-
-struct misdn_bchannel *manager_find_bc_by_pid(int pid)
-{
- struct misdn_stack *stack;
- int i;
-
- for (stack=glob_mgr->stack_list;
- stack;
- stack=stack->next) {
- for (i=0; i<stack->b_num; i++)
- if (stack->bc[i].pid == pid) return &stack->bc[i];
- }
-
- return NULL;
-}
-
-struct misdn_bchannel *manager_find_bc_holded(struct misdn_bchannel* bc)
-{
- struct misdn_stack *stack=get_stack_by_bc(bc);
- return find_bc_holded(stack);
-}
-
-
-
-struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel)
-{
- struct misdn_stack *stack;
- int i;
-
- if (channel < 0 || channel > MAX_BCHANS)
- return NULL;
-
- for (stack=glob_mgr->stack_list; stack; stack=stack->next) {
-
- if (stack->port == port) {
- if (channel > 0) {
- if (channel <= stack->b_num) {
- for (i = 0; i < stack->b_num; i++) {
- if (stack->bc[i].in_use && stack->bc[i].channel == channel) {
- return NULL;
- }
- }
- } else
- return NULL;
- }
- for (i = 0; i < stack->b_num; i++) {
- if (!stack->bc[i].in_use) {
- stack->bc[i].channel = channel;
- stack->bc[i].channel_preselected = channel?1:0;
- stack->bc[i].in_use = 1;
- return &stack->bc[i];
- }
- }
- return NULL;
- }
- }
- return NULL;
-}
-
-void misdn_lib_log_ies(struct misdn_bchannel *bc)
-{
- if (!bc) return;
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- if (!stack) return;
-
- cb_log(2, stack->port, " --> mode:%s cause:%d ocause:%d rad:%s\n", stack->mode==NT_MODE?"NT":"TE", bc->cause, bc->out_cause, bc->rad);
-
- cb_log(2, stack->port,
- " --> info_dad:%s onumplan:%c dnumplan:%c rnumplan:%c\n",
- bc->info_dad,
- bc->onumplan>=0?'0'+bc->onumplan:' ',
- bc->dnumplan>=0?'0'+bc->dnumplan:' ',
- bc->rnumplan>=0?'0'+bc->rnumplan:' '
- );
-
- cb_log(2, stack->port, " --> channel:%d caps:%s pi:%x keypad:%s\n", bc->channel, bearer2str(bc->capability),bc->progress_indicator, bc->keypad);
-
- cb_log(3, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1);
-
- cb_log(3, stack->port, " --> pid:%d addr:%x l3id:%x\n", bc->pid, bc->addr, bc->l3_id);
-
- cb_log(4, stack->port, " --> bc:%x h:%d sh:%d\n", bc, bc->holded, bc->stack_holder);
-}
-
-int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
-{
- msg_t *msg;
- int err = -1 ;
-
- if (!bc) goto ERR;
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- if ( stack->mode == NT_MODE && !stack->l1link) {
- /** Queue Event **/
- bc->evq=event;
- cb_log(1, stack->port, "Queueing Event %s because L1 is down (btw. Activating L1)\n", isdn_get_info(msgs_g, event, 0));
- { /* Pull Up L1 */
- iframe_t act;
- act.prim = PH_ACTIVATE | REQUEST;
- act.addr = (stack->upper_id & IF_ADDRMASK) | IF_DOWN ;
- act.dinfo = 0;
- act.len = 0;
- mISDN_write(glob_mgr->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
- }
-
- return 0;
- }
-
- cb_log(1, stack->port, "I SEND:%s oad:%s dad:%s port:%d\n", isdn_get_info(msgs_g, event, 0), bc->oad, bc->dad, stack->port);
- misdn_lib_log_ies(bc);
-
- switch (event) {
- case EVENT_SETUP:
- if (create_process(glob_mgr->midev, bc)<0) {
- cb_log(0, stack->port, " No free channel at the moment @ send_event\n");
- err=-ENOCHAN;
- goto ERR;
- }
- break;
-
- case EVENT_CONNECT:
- case EVENT_PROGRESS:
- case EVENT_ALERTING:
- case EVENT_PROCEEDING:
- case EVENT_SETUP_ACKNOWLEDGE:
- case EVENT_RETRIEVE_ACKNOWLEDGE:
-
- if (stack->mode == NT_MODE) {
- if (bc->channel <=0 ) { /* else we have the channel already */
- bc->channel = find_free_chan_in_stack(stack, 0);
- if (!bc->channel) {
- cb_log(0, stack->port, " No free channel at the moment\n");
- err=-ENOCHAN;
- goto ERR;
- }
- }
- /* Its that i generate channels */
- }
-
- setup_bc(bc);
-
-
- if ( event == EVENT_CONNECT ) {
- if ( *bc->crypt_key ) {
- cb_log(4, stack->port, " --> ENABLING BLOWFISH port:%d channel:%d oad%d:%s dad%d:%s \n", stack->port, bc->channel, bc->onumplan,bc->oad, bc->dnumplan,bc->dad);
-
- manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
- }
-
- if ( misdn_cap_is_speech(bc->capability)) {
- if (!bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0);
-
- if (bc->ec_enable) manager_ec_enable(bc);
-
- if (bc->txgain != 0) {
- cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain);
- manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
- }
-
- if ( bc->rxgain != 0 ) {
- cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain);
- manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
- }
- }
- }
-
- if (event == EVENT_RETRIEVE_ACKNOWLEDGE) {
- manager_bchannel_activate(bc);
- }
-
- break;
-
- case EVENT_HOLD_ACKNOWLEDGE:
- {
- struct misdn_bchannel *holded_bc=malloc(sizeof(struct misdn_bchannel));
-
- memcpy(holded_bc,bc,sizeof(struct misdn_bchannel));
-
- holded_bc->holded=1;
- stack_holder_add(stack,holded_bc);
-
- if (stack->mode == NT_MODE) {
- empty_chan_in_stack(stack,bc->channel);
- empty_bc(bc);
- clean_up_bc(bc);
- }
-
- /** we set it up later at RETRIEVE_ACK again.**/
- holded_bc->upset=0;
- holded_bc->active=0;
-
- cb_event( EVENT_NEW_BC, holded_bc, glob_mgr->user_data);
- }
- break;
-
- case EVENT_RELEASE:
- break;
-
- case EVENT_RELEASE_COMPLETE:
- empty_chan_in_stack(stack,bc->channel);
- empty_bc(bc);
- clean_up_bc(bc);
- break;
-
- case EVENT_CONNECT_ACKNOWLEDGE:
-
- if (misdn_cap_is_speech(bc->capability)) {
- if ( !bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0);
- if (bc->ec_enable) manager_ec_enable(bc);
- if ( bc->txgain != 0 ) {
- cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain);
- manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
- }
- if ( bc->rxgain != 0 ) {
- cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain);
- manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
- }
- }
- break;
-
- default:
- break;
- }
-
- /* Later we should think about sending bchannel data directly to misdn. */
- msg = isdn_msg_build_event(msgs_g, bc, event, stack->mode==NT_MODE?1:0);
- msg_queue_tail(&stack->downqueue, msg);
- sem_post(&glob_mgr->new_msg);
-
- return 0;
-
- ERR:
- return -1;
-}
-
-
-
-int manager_isdn_handler(iframe_t *frm ,msg_t *msg)
-{
-
- if (frm->dinfo==(signed long)0xffffffff && frm->prim==(PH_DATA|CONFIRM)) {
- printf("SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n");
- }
-
- if (handle_timers(msg))
- return 0 ;
-
- if (handle_mgmt(msg))
- return 0 ;
-
- if (handle_l2(msg))
- return 0 ;
-
- /* Its important to handle l1 AFTER l2 */
- if (handle_l1(msg))
- return 0 ;
-
- if (handle_bchan(msg))
- return 0 ;
-
- /** Handle L2/3 Signalling after bchans **/
- if (handle_frm_nt(msg))
- return 0 ;
-
- if (handle_frm(msg))
- return 0 ;
-
- cb_log(0, frm->addr&IF_CONTRMASK, "Unhandled Message: prim %x len %d from addr %x, dinfo %x on port: %d\n",frm->prim, frm->len, frm->addr, frm->dinfo, frm->addr&IF_CONTRMASK);
-
- free_msg(msg);
-
- return 0;
-}
-
-
-
-
-int misdn_lib_get_port_info(int port)
-{
- msg_t *msg=alloc_msg(MAX_MSG_SIZE);
- iframe_t *frm;
- struct misdn_stack *stack=find_stack_by_port(port);
- if (!msg) {
- cb_log(0, port, "misgn_lib_get_port: alloc_msg failed!\n");
- return -1;
- }
- frm=(iframe_t*)msg->data;
- if (!stack ) {
- cb_log(0, port, "There is no Stack on Port:%d\n",port);
- return -1;
- }
- /* activate bchannel */
- frm->prim = CC_STATUS_ENQUIRY | REQUEST;
- frm->addr = stack->upper_id;
- frm->dinfo = 0;
- frm->len = 0;
-
- msg_queue_tail(&glob_mgr->activatequeue, msg);
- sem_post(&glob_mgr->new_msg);
-
-
- return 0;
-}
-
-int misdn_lib_port_restart(int port)
-{
- struct misdn_stack *stack=find_stack_by_port(port);
-
- cb_log(0, port, "Restarting Port:%d\n",port);
- if (stack) {
- cb_log(0, port, "Stack:%p\n",stack);
-
-
- clear_l3(stack);
-
- {
- msg_t *msg=alloc_msg(MAX_MSG_SIZE);
- iframe_t *frm;
-
- if (!msg) {
- cb_log(0, port, "port_restart: alloc_msg fialed\n");
- return -1;
- }
-
- frm=(iframe_t*)msg->data;
- /* we must activate if we are deactivated */
- /* activate bchannel */
-
- frm->prim = DL_RELEASE | REQUEST;
-
- frm->addr = stack->upper_id ;
- frm->dinfo = 0;
- frm->len = 0;
- msg_queue_tail(&glob_mgr->activatequeue, msg);
- sem_post(&glob_mgr->new_msg);
- }
- return 0;
-
- stack_te_destroy(stack);
-
- {
- struct misdn_stack *tmpstack;
- struct misdn_stack *newstack=stack_te_init(stack->midev ,port, stack->ptp);
-
-
- if (stack == glob_mgr->stack_list) {
- struct misdn_stack *n=glob_mgr->stack_list->next;
- glob_mgr->stack_list = newstack ;
- glob_mgr->stack_list->next = n;
- } else {
- for (tmpstack=glob_mgr->stack_list;
- tmpstack->next;
- tmpstack=tmpstack->next)
- if (tmpstack->next == stack) break;
-
- if (!tmpstack->next) {
- cb_log(0, port, "Stack to restart not found\n");
- return 0;
- } else {
- struct misdn_stack *n=tmpstack->next->next;
- tmpstack->next=newstack;
- newstack->next=n;
- }
- }
-
- {
- int i;
- for(i=0;i<newstack->b_num; i++) {
- int r;
- if ((r=init_bc(newstack, &newstack->bc[i], newstack->midev,port,i, "", 1))<0) {
- cb_log(0, port, "Got Err @ init_bc :%d\n",r);
- return 0;
- }
- }
- }
-
- free(stack);
- }
- }
-
- return 0;
-}
-
-
-
-sem_t handler_started;
-
-void manager_event_handler(void *arg)
-{
- sem_post(&handler_started);
- while (1) {
- struct misdn_stack *stack;
- msg_t *msg;
-
- /** wait for events **/
- sem_wait(&glob_mgr->new_msg);
-
- for (msg=msg_dequeue(&glob_mgr->activatequeue);
- msg;
- msg=msg_dequeue(&glob_mgr->activatequeue)
- )
- {
-
- iframe_t *frm = (iframe_t*) msg->data ;
-
- switch ( frm->prim) {
- case MGR_SETSTACK | REQUEST :
- break;
- default:
- mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
- free_msg(msg);
- }
- }
-
- for (stack=glob_mgr->stack_list;
- stack;
- stack=stack->next ) {
- while ( (msg=msg_dequeue(&stack->downqueue)) ) {
-
- if (stack->mode == NT_MODE ){
-
- if (stack->nst.manager_l3(&stack->nst, msg))
- cb_log(0, stack->port, "Error@ Sending Message in NT-Stack.\n");
-
- } else {
- if (msg) {
- iframe_t *frm = (iframe_t *)msg->data;
- struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo);
-
- if (bc) send_msg(glob_mgr->midev, bc, msg);
- }
- }
- }
- }
- }
-}
-
-
-int misdn_lib_maxports_get() { /** BE AWARE WE HAVE NO CB_LOG HERE! **/
-
- int i = mISDN_open();
- int max=0;
-
- if (i<0)
- return -1;
-
- max = mISDN_get_stack_count(i);
-
- mISDN_close(i);
-
- return max;
-}
-
-int misdn_lib_init(char *portlist, struct misdn_lib_iface *iface, void *user_data)
-{
- struct misdn_lib *mgr=calloc(1, sizeof(struct misdn_lib));
- char *tok, *tokb;
- char plist[1024];
- int midev;
- int port_count=0;
-
- cb_log = iface->cb_log;
- cb_event = iface->cb_event;
- cb_clearl3_true = iface->cb_clearl3_true;
-
- glob_mgr = mgr;
-
- msg_init();
- debug_init(0 , NULL, NULL, NULL);
-
- if (!portlist || (*portlist == 0) ) return 1;
-
- init_flip_bits();
-
- {
- strncpy(plist,portlist, 1024);
- plist[1023] = 0;
- }
-
- memcpy(tone_425_flip,tone_425,TONE_425_SIZE);
- flip_buf_bits(tone_425_flip,TONE_425_SIZE);
-
- memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE);
- flip_buf_bits(tone_silence_flip,TONE_SILENCE_SIZE);
-
- midev=te_lib_init();
- mgr->midev=midev;
-
- port_count=mISDN_get_stack_count(midev);
-
- msg_queue_init(&mgr->activatequeue);
-
- if (sem_init(&mgr->new_msg, 1, 0)<0)
- sem_init(&mgr->new_msg, 0, 0);
-
- for (tok=strtok_r(plist," ,",&tokb );
- tok;
- tok=strtok_r(NULL," ,",&tokb)) {
- int port = atoi(tok);
- struct misdn_stack *stack;
- static int first=1;
- int ptp=0;
-
- if (strstr(tok, "ptp"))
- ptp=1;
-
- if (port > port_count) {
- cb_log(0, port, "Couldn't Initialize Port:%d since we have only %d ports\n",port, port_count);
- exit(1);
- }
- stack=stack_te_init(midev, port, ptp);
-
-
-
- if (!stack) {
- perror("init_stack");
- exit(1);
- }
-
- if (stack && first) {
- mgr->stack_list=stack;
- first=0;
- {
- int i;
- for(i=0;i<stack->b_num; i++) {
- int r;
- if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) {
- cb_log(0, port, "Got Err @ init_bc :%d\n",r);
- exit(1);
- }
- }
- }
-
- continue;
- }
-
- if (stack) {
- struct misdn_stack * help;
- for ( help=mgr->stack_list; help; help=help->next )
- if (help->next == NULL) break;
-
-
- help->next=stack;
-
- {
- int i;
- for(i=0;i<stack->b_num; i++) {
- int r;
- if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "",1 ))<0) {
- cb_log(0, port, "Got Err @ init_bc :%d\n",r);
- exit(1);
- }
- }
- }
- }
-
- }
-
- if (sem_init(&handler_started, 1, 0)<0)
- sem_init(&handler_started, 0, 0);
-
- cb_log(4, 0, "Starting Event Handler\n");
- pthread_create( &mgr->event_handler_thread, NULL,(void*)manager_event_handler, mgr);
-
- sem_wait(&handler_started) ;
- cb_log(4, 0, "Starting Event Catcher\n");
- pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr);
-
- cb_log(4, 0, "Event Catcher started\n");
-
- global_state= MISDN_INITIALIZED;
-
- return (mgr == NULL);
-}
-
-
-
-void misdn_lib_destroy()
-{
- struct misdn_stack *help;
- int i;
-
- for ( help=glob_mgr->stack_list; help; help=help->next ) {
- for(i=0;i<help->b_num; i++) {
- char buf[1024];
-
- mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
- help->bc[i].addr = 0;
- }
-
-
- cb_log (1, help->port, "Destroying port:%d\n", help->port);
- stack_te_destroy(help);
- }
-
- if (global_state == MISDN_INITIALIZED) {
- cb_log(4, 0, "Killing Handler Thread\n");
- if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) {
- cb_log(4, 0, "Joining Handler Thread\n");
- pthread_join(glob_mgr->event_handler_thread, NULL);
- }
-
-
- cb_log(4, 0, "Killing Main Thread\n");
- if ( pthread_cancel(glob_mgr->event_thread) == 0 ) {
- cb_log(4, 0, "Joining Main Thread\n");
- pthread_join(glob_mgr->event_thread, NULL);
- }
- }
-
- cb_log(1, 0, "Closing mISDN device\n");
- te_lib_destroy(glob_mgr->midev);
-}
-
-
-char *manager_isdn_get_info(enum event_e event)
-{
- return isdn_get_info(msgs_g , event, 0);
-}
-
-
-
-
-void manager_bchannel_activate(struct misdn_bchannel *bc)
-{
- msg_t *msg=alloc_msg(MAX_MSG_SIZE);
- iframe_t *frm;
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- if (!msg) {
- cb_log(0, stack->port, "bchannel_activate: alloc_msg failed !");
- return ;
- }
-
- frm=(iframe_t*)msg->data;
- /* we must activate if we are deactivated */
- clear_ibuffer(bc->misdnbuf);
- clear_ibuffer(bc->astbuf);
-
-
- if (bc->active) return;
-
- cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr);
-
- /* activate bchannel */
- frm->prim = DL_ESTABLISH | REQUEST;
- frm->addr = bc->addr ;
- frm->dinfo = 0;
- frm->len = 0;
-
- msg_queue_tail(&glob_mgr->activatequeue, msg);
- sem_post(&glob_mgr->new_msg);
-
- bc->active=1;
-
- return ;
-
-}
-
-
-void manager_bchannel_deactivate(struct misdn_bchannel * bc)
-{
- iframe_t dact;
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
- if (!bc->active) return;
-
- cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr);
-
- bc->tone=TONE_NONE;
-
- dact.prim = DL_RELEASE | REQUEST;
- dact.addr = bc->addr;
- dact.dinfo = 0;
- dact.len = 0;
-
- mISDN_write(stack->midev, &dact, mISDN_HEADER_LEN+dact.len, TIMEOUT_1SEC);
- clear_ibuffer(bc->misdnbuf);
- clear_ibuffer(bc->astbuf);
- bc->active=0;
-
- return;
-}
-
-
-int manager_tx2misdn_frm(struct misdn_bchannel *bc, void *data, int len)
-{
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
- if (!bc->active) return -1;
-
- if ( misdn_cap_is_speech(bc->capability) )
- flip_buf_bits(data,len);
-
- if ( !bc->nojitter && misdn_cap_is_speech(bc->capability) ) {
- if (len > ibuf_freecount(bc->misdnbuf)) {
- len=ibuf_freecount(bc->misdnbuf);
- }
- ibuf_memcpy_w(bc->misdnbuf, (unsigned char*)data, len);
- } else {
- char buf[4096 + mISDN_HEADER_LEN];
- iframe_t *frm= (iframe_t*)buf;
- int r;
-
- frm->prim = DL_DATA|REQUEST;
- frm->dinfo = 0;
- frm->addr = bc->addr | IF_DOWN;
- frm->len = len;
- memcpy(&buf[mISDN_HEADER_LEN], data,len);
-
-
-
- if ( misdn_cap_is_speech(bc->capability))
- cb_log(4, stack->port, "Writing %d bytes\n",len);
-
- cb_log(9, stack->port, "Wrinting %d bytes 2 mISDN\n",len);
- r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT);
- }
-
- return 0;
-}
-
-
-
-
-void manager_send_tone (struct misdn_bchannel *bc, enum tone_e tone)
-{
- if (tone != TONE_NONE) manager_bchannel_activate(bc);
- bc->tone=tone;
- bc->tone_cnt2=-1;
- bc->tone_cnt=0;
-}
-
-
-
-/*
- * send control information to the channel (dsp-module)
- */
-void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2)
-{
- unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+sizeof(int)];
- iframe_t *ctrl = (iframe_t *)buffer; /* preload data */
- unsigned long *d = (unsigned long *)&ctrl->data.p;
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- ctrl->prim = PH_CONTROL | REQUEST;
- ctrl->addr = bc->addr;
- ctrl->dinfo = 0;
- ctrl->len = sizeof(unsigned long)*2;
- *d++ = c1;
- *d++ = c2;
- mISDN_write(stack->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
-}
-
-/*
- * send control information to the channel (dsp-module)
- */
-void manager_ph_control_block(struct misdn_bchannel *bc, int c1, void *c2, int c2_len)
-{
- unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len];
- iframe_t *ctrl = (iframe_t *)buffer;
- unsigned long *d = (unsigned long *)&ctrl->data.p;
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- ctrl->prim = PH_CONTROL | REQUEST;
- ctrl->addr = bc->addr;
- ctrl->dinfo = 0;
- ctrl->len = sizeof(unsigned long) + c2_len;
- *d++ = c1;
- memcpy(d, c2, c2_len);
- mISDN_write(stack->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
-}
-
-
-
-
-void manager_clean_bc(struct misdn_bchannel *bc )
-{
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- if (bc->state == STATE_CONNECTED)
- misdn_lib_send_event(bc,EVENT_DISCONNECT);
-
- empty_chan_in_stack(stack, bc->channel);
- empty_bc(bc);
-
- misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
-}
-
-
-void stack_holder_add(struct misdn_stack *stack, struct misdn_bchannel *holder)
-{
- struct misdn_bchannel *help;
- cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id);
-
- holder->stack_holder=1;
-
- if (!stack ) return ;
-
- holder->next=NULL;
-
- if (!stack->holding) {
- stack->holding = holder;
- return;
- }
-
- for (help=stack->holding;
- help;
- help=help->next) {
- if (!help->next) {
- help->next=holder;
- }
- }
-
-}
-
-void stack_holder_remove(struct misdn_stack *stack, struct misdn_bchannel *holder)
-{
- struct misdn_bchannel *h1;
-
- if (!holder->stack_holder) return;
-
- cb_log(4,stack->port, "*HOLDER: remove %x\n",holder->l3_id);
- if (!stack || ! stack->holding) return;
-
- if (holder == stack->holding) {
- stack->holding = stack->holding->next;
- return;
- }
-
- for (h1=stack->holding;
- h1;
- h1=h1->next) {
- if (h1->next == holder) {
- h1->next=h1->next->next;
- return ;
- }
- }
-}
-
-
-struct misdn_bchannel *stack_holder_find(struct misdn_stack *stack, unsigned long l3id)
-{
- struct misdn_bchannel *help;
-
- cb_log(4,stack?stack->port:0, "*HOLDER: find %x\n",l3id);
-
- if (!stack) return NULL;
-
- for (help=stack->holding;
- help;
- help=help->next) {
- if (help->l3_id == l3id) {
- cb_log(4,stack->port, "*HOLDER: found bc\n");
- return help;
- }
- }
-
- cb_log(4,stack->port, "*HOLDER: find nothing\n");
- return NULL;
-}
-
-
-
-void manager_ec_enable(struct misdn_bchannel *bc)
-{
- int ec_arr[2];
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- cb_log(1, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d training:%d\n",bc->ec_deftaps, bc->ec_training);
-
- switch (bc->ec_deftaps) {
- case 4:
- case 8:
- case 16:
- case 32:
- case 64:
- case 128:
- case 256:
- case 512:
- case 1024:
- cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps);
- break;
- default:
- cb_log(0, stack->port, "Taps should be power of 2\n");
- bc->ec_deftaps=128;
- }
-
- ec_arr[0]=bc->ec_deftaps;
- ec_arr[1]=bc->ec_training;
-
- manager_ph_control_block(bc, ECHOCAN_ON, ec_arr, sizeof(ec_arr));
-}
-
-
-
-void manager_ec_disable(struct misdn_bchannel *bc)
-{
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- cb_log(1, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n");
- manager_ph_control(bc, ECHOCAN_OFF, 0);
-}
-
-struct misdn_stack* get_misdn_stack() {
- return glob_mgr->stack_list;
-}
-
-
-
-void misdn_lib_bridge( struct misdn_bchannel * bc1, struct misdn_bchannel *bc2) {
- manager_ph_control(bc1, CMX_RECEIVE_OFF, 0);
- manager_ph_control(bc2, CMX_RECEIVE_OFF, 0);
-
- manager_ph_control(bc1, CMX_CONF_JOIN, (bc1->pid<<1) +1);
- manager_ph_control(bc2, CMX_CONF_JOIN, (bc1->pid<<1) +1);
-}
-
-void misdn_lib_split_bridge( struct misdn_bchannel * bc1, struct misdn_bchannel *bc2)
-{
-
- manager_ph_control(bc1, CMX_RECEIVE_ON, 0) ;
- manager_ph_control(bc2, CMX_RECEIVE_ON, 0);
-
- manager_ph_control(bc1, CMX_CONF_SPLIT, (bc1->pid<<1) +1);
- manager_ph_control(bc2, CMX_CONF_SPLIT, (bc1->pid<<1) +1);
-
-}
diff --git a/1.2-netsec/channels/misdn/isdn_lib.h b/1.2-netsec/channels/misdn/isdn_lib.h
deleted file mode 100644
index 28a4fe7b6..000000000
--- a/1.2-netsec/channels/misdn/isdn_lib.h
+++ /dev/null
@@ -1,367 +0,0 @@
-/*
- * Chan_Misdn -- Channel Driver for Asterisk
- *
- * Interface to mISDN
- *
- * Copyright (C) 2004, Christian Richter
- *
- * Christian Richter <crich@beronet.com>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-#ifndef TE_LIB
-#define TE_LIB
-
-/** For initialization usage **/
-/* typedef int ie_nothing_t ;*/
-/** end of init usage **/
-
-
-#define MAX_BCHANS 30
-
-enum bc_state_e {
- STATE_NOTHING=0,
- STATE_NULL,
- STATE_CALL_INIT,
- STATE_CONNECTED,
- STATE_HOLD_ACKNOWLEDGE
-};
-
-
-enum tone_e {
- TONE_NONE=0,
- TONE_DIAL,
- TONE_ALERTING,
- TONE_BUSY,
- TONE_FILE
-};
-
-enum misdn_err_e {
- ENOCHAN=1
-};
-
-
-
-enum mISDN_NUMBER_PLAN {
- NUMPLAN_UNINITIALIZED=-1,
- NUMPLAN_INTERNATIONAL=0x1,
- NUMPLAN_NATIONAL=0x2,
- NUMPLAN_SUBSCRIBER=0x4,
- NUMPLAN_UNKNOWN=0x0
-};
-
-
-enum event_response_e {
- RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE,
- RESPONSE_IGNORE_SETUP,
- RESPONSE_ERR,
- RESPONSE_OK
-};
-
-
-
-enum event_e {
- EVENT_NOTHING,
- EVENT_BCHAN_DATA,
- EVENT_CLEANUP,
- EVENT_PROCEEDING,
- EVENT_PROGRESS,
- EVENT_SETUP,
- EVENT_ALERTING,
- EVENT_CONNECT,
- EVENT_SETUP_ACKNOWLEDGE,
- EVENT_CONNECT_ACKNOWLEDGE ,
- EVENT_USER_INFORMATION,
- EVENT_SUSPEND_REJECT,
- EVENT_RESUME_REJECT,
- EVENT_HOLD,
- EVENT_SUSPEND,
- EVENT_RESUME,
- EVENT_HOLD_ACKNOWLEDGE,
- EVENT_SUSPEND_ACKNOWLEDGE,
- EVENT_RESUME_ACKNOWLEDGE,
- EVENT_HOLD_REJECT,
- EVENT_RETRIEVE,
- EVENT_RETRIEVE_ACKNOWLEDGE,
- EVENT_RETRIEVE_REJECT,
- EVENT_DISCONNECT,
- EVENT_RESTART,
- EVENT_RELEASE,
- EVENT_RELEASE_COMPLETE,
- EVENT_FACILITY,
- EVENT_NOTIFY,
- EVENT_STATUS_ENQUIRY,
- EVENT_INFORMATION,
- EVENT_STATUS,
- EVENT_TIMEOUT,
- EVENT_DTMF_TONE,
- EVENT_NEW_L3ID,
- EVENT_NEW_BC,
- EVENT_UNKNOWN
-};
-
-
-enum ie_name_e {
- IE_DUMMY,
- IE_LAST
-};
-
-enum { /* bearer capability */
- INFO_CAPABILITY_SPEECH=0,
- INFO_CAPABILITY_AUDIO_3_1K=0x10 ,
- INFO_CAPABILITY_AUDIO_7K=0x11 ,
- INFO_CAPABILITY_VIDEO =0x18,
- INFO_CAPABILITY_DIGITAL_UNRESTRICTED =0x8,
- INFO_CAPABILITY_DIGITAL_RESTRICTED =0x09,
- INFO_CAPABILITY_DIGITAL_UNRESTRICTED_TONES
-};
-
-enum { /* progress indicators */
- INFO_PI_CALL_NOT_E2E_ISDN =0x01,
- INFO_PI_CALLED_NOT_ISDN =0x02,
- INFO_PI_CALLER_NOT_ISDN =0x03,
- INFO_PI_CALLER_RETURNED_TO_ISDN =0x04,
- INFO_PI_INBAND_AVAILABLE =0x08,
- INFO_PI_DELAY_AT_INTERF =0x0a,
- INFO_PI_INTERWORKING_WITH_PUBLIC =0x10,
- INFO_PI_INTERWORKING_NO_RELEASE =0x11,
- INFO_PI_INTERWORKING_NO_RELEASE_PRE_ANSWER =0x12,
- INFO_PI_INTERWORKING_NO_RELEASE_POST_ANSWER =0x13
-};
-
-enum { /*CODECS*/
- INFO_CODEC_ULAW=2,
- INFO_CODEC_ALAW=3
-};
-
-
-enum layer_e {
- L3,
- L2,
- L1,
- UNKNOWN
-};
-
-enum facility_type {
- FACILITY_NONE,
- FACILITY_CALLDEFLECT
-};
-
-
-
-
-struct misdn_bchannel {
-
- int nt;
- int port;
- /** init stuff **/
- int b_stid;
- /* int b_addr; */
- int layer_id;
-
-
-
- /** var stuff**/
- int l3_id;
- int pid;
- int ces;
-
- int channel;
- int channel_preselected;
-
- int in_use;
- int addr;
-
- unsigned char * bframe;
- int bframe_len;
- int time_usec;
-
-
- void *astbuf;
- void *misdnbuf;
-
-
- int te_choose_channel;
- int early_bconnect;
-
- /* dtmf digit */
- int dtmf;
- int send_dtmf;
-
- /* wether we should use jollys dsp or not */
- int nodsp;
-
- /* wether we should use our jitter buf system or not */
- int nojitter;
-
- enum mISDN_NUMBER_PLAN dnumplan;
- enum mISDN_NUMBER_PLAN rnumplan;
- enum mISDN_NUMBER_PLAN onumplan;
-
- int progress_coding;
- int progress_location;
- int progress_indicator;
-
- enum facility_type facility;
- char facility_calldeflect_nr[15];
-
- enum event_e evq;
-
- /*** CRYPTING STUFF ***/
-
- int crypt;
- int curprx;
- int curptx;
- char crypt_key[255];
-
- int crypt_state;
-
- /*char ast_dtmf_buf[255];
- char misdn_dtmf_buf[255]; */
-
- /*** CRYPTING STUFF END***/
-
- int active;
- int upset;
-
- enum tone_e tone;
- int tone_cnt;
- int tone_cnt2;
-
- enum bc_state_e state;
-
- int holded;
- int stack_holder;
-
- int pres;
- int screen;
-
- int capability;
- int law;
- /** V110 Stuff **/
- int rate;
- int mode;
-
- int user1;
- int urate;
- int async;
- /* V110 */
-
- unsigned char display[84];
- unsigned char msn[32];
- unsigned char oad[32];
- unsigned char rad[32];
- unsigned char dad[32];
- unsigned char orig_dad[32];
- unsigned char keypad[32];
-
- unsigned char info_dad[64];
- unsigned char infos_pending[64];
- unsigned char info_keypad[32];
- unsigned char clisub[24];
- unsigned char cldsub[24];
- unsigned char fac[132];
- unsigned char uu[256];
-
- int cause;
- int out_cause;
-
- /* struct misdn_bchannel hold_bc; */
-
- /** list stuf **/
-
- int ec_enable;
- int ec_deftaps;
- int ec_whenbridged;
- int ec_training;
-
- int orig;
-
- int txgain;
- int rxgain;
-
- struct misdn_bchannel *next;
-};
-
-
-enum event_response_e (*cb_event) (enum event_e event, struct misdn_bchannel *bc, void *user_data);
-void (*cb_log) (int level, int port, char *tmpl, ...);
-int (*cb_clearl3_true)(void);
-
-struct misdn_lib_iface {
-
- enum event_response_e (*cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data);
- void (*cb_log)(int level, int port, char *tmpl, ...);
- int (*cb_clearl3_true)(void);
-};
-
-/***** USER IFACE **********/
-
-int misdn_lib_init(char *portlist, struct misdn_lib_iface* iface, void *user_data);
-int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event );
-void misdn_lib_destroy(void);
-
-void misdn_lib_log_ies(struct misdn_bchannel *bc);
-
-char *manager_isdn_get_info(enum event_e event);
-
-void misdn_lib_transfer(struct misdn_bchannel* holded_bc);
-
-struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel);
-
-void manager_bchannel_activate(struct misdn_bchannel *bc);
-void manager_bchannel_deactivate(struct misdn_bchannel * bc);
-int manager_tx2misdn_frm(struct misdn_bchannel *bc, void *data, int len);
-void manager_send_tone (struct misdn_bchannel *bc, enum tone_e tone);
-
-void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2);
-
-
-int misdn_lib_port_restart(int port);
-int misdn_lib_get_port_info(int port);
-
-int misdn_lib_port_up(int port);
-
-int misdn_lib_get_port_up (int port) ;
-
-int misdn_lib_maxports_get(void) ;
-
-void misdn_lib_release(struct misdn_bchannel *bc);
-
-int misdn_cap_is_speech(int cap);
-int misdn_inband_avail(struct misdn_bchannel *bc);
-
-int misdn_lib_send_facility(struct misdn_bchannel *bc, enum facility_type fac, void *data);
-
-
-void manager_ec_enable(struct misdn_bchannel *bc);
-void manager_ec_disable(struct misdn_bchannel *bc);
-
-void get_show_stack_details(int port, char *buf);
-
-
-/** Ibuf interface **/
-int misdn_ibuf_usedcount(void *buf);
-int misdn_ibuf_freecount(void *buf);
-void misdn_ibuf_memcpy_r(char *to, void *from, int len);
-void misdn_ibuf_memcpy_w(void *buf, char *from, int len);
-
-/** Ibuf interface End **/
-
-void misdn_lib_setup_bc(struct misdn_bchannel *bc);
-
-void misdn_lib_bridge( struct misdn_bchannel * bc1, struct misdn_bchannel *bc2);
-void misdn_lib_split_bridge( struct misdn_bchannel * bc1, struct misdn_bchannel *bc2);
-
-
-int misdn_lib_is_ptp(int port);
-
-#define PRI_TRANS_CAP_SPEECH 0x0
-#define PRI_TRANS_CAP_DIGITAL 0x08
-#define PRI_TRANS_CAP_RESTRICTED_DIGITAL 0x09
-#define PRI_TRANS_CAP_3_1K_AUDIO 0x10
-#define PRI_TRANS_CAP_7K_AUDIO 0x11
-
-#endif
diff --git a/1.2-netsec/channels/misdn/isdn_lib_intern.h b/1.2-netsec/channels/misdn/isdn_lib_intern.h
deleted file mode 100644
index 0305a2dad..000000000
--- a/1.2-netsec/channels/misdn/isdn_lib_intern.h
+++ /dev/null
@@ -1,99 +0,0 @@
-#ifndef ISDN_LIB_INTERN
-#define ISDN_LIB_INTER
-
-
-#include <mISDNuser/mISDNlib.h>
-#include <mISDNuser/isdn_net.h>
-#include <mISDNuser/l3dss1.h>
-#include <mISDNuser/net_l3.h>
-
-#include <pthread.h>
-
-#include "isdn_lib.h"
-
-
-
-
-
-#ifndef mISDNUSER_HEAD_SIZE
-
-#ifdef MISDNUSER_JOLLY
-#define mISDNUSER_HEAD_SIZE (sizeof(mISDNuser_head_t))
-#else
-#define mISDNUSER_HEAD_SIZE (sizeof(mISDN_head_t))
-#endif
-#endif
-
-
-ibuffer_t *astbuf;
-ibuffer_t *misdnbuf;
-
-
-struct isdn_msg {
- unsigned long misdn_msg;
-
- enum layer_e layer;
- enum event_e event;
-
- void (*msg_parser)(struct isdn_msg *msgs, msg_t *msg, struct misdn_bchannel *bc, int nt);
- msg_t *(*msg_builder)(struct isdn_msg *msgs, struct misdn_bchannel *bc, int nt);
- void (*msg_printer)(struct isdn_msg *msgs);
-
- char *info;
-
-} ;
-
-/* for isdn_msg_parser.c */
-msg_t *create_l3msg(int prim, int mt, int dinfo , int size, int nt);
-
-
-
-struct misdn_stack {
- /** is first element because &nst equals &mISDNlist **/
- net_stack_t nst;
- manager_t mgr;
-
- int d_stid;
-
- int b_num;
-
- int b_stids[MAX_BCHANS + 1];
-
- int ptp;
- int lower_id;
- int upper_id;
-
- int l2link;
-
- time_t l2establish;
-
- int l1link;
- int midev;
-
- enum mode_e {NT_MODE, TE_MODE} mode;
-
- int pri;
-
-
- int procids[0x100+1];
-
- msg_queue_t downqueue;
- int busy;
-
- int port;
- struct misdn_bchannel bc[MAX_BCHANS + 1];
-
- struct misdn_bchannel* bc_list;
-
- int channels[MAX_BCHANS + 1];
-
-
- struct misdn_bchannel *holding; /* Queue which holds holded channels :) */
-
- struct misdn_stack *next;
-};
-
-
-struct misdn_stack* get_stack_by_bc(struct misdn_bchannel *bc);
-
-#endif
diff --git a/1.2-netsec/channels/misdn/isdn_msg_parser.c b/1.2-netsec/channels/misdn/isdn_msg_parser.c
deleted file mode 100644
index 9b59f8685..000000000
--- a/1.2-netsec/channels/misdn/isdn_msg_parser.c
+++ /dev/null
@@ -1,1356 +0,0 @@
-/*
- * Chan_Misdn -- Channel Driver for Asterisk
- *
- * Interface to mISDN
- *
- * Copyright (C) 2004, Christian Richter
- *
- * Christian Richter <crich@beronet.com>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-
-#include "isdn_lib.h"
-#include "ie.c"
-
-
-void parse_proceeding (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- CALL_PROCEEDING_t *proceeding=(CALL_PROCEEDING_t*)((unsigned long)msg->data+ HEADER_LEN);
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
- {
- int exclusive, channel;
- dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)proceeding, &exclusive, &channel, nt,bc);
-
- if (channel==0xff) /* any channel */
- channel=-1;
-
- /* ALERT: is that everytime true ? */
- if (channel > 0 && stack->mode == NT_MODE)
- bc->channel = channel;
- }
-
- dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)proceeding, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
-
-#if DEBUG
- printf("Parsing PROCEEDING Msg\n");
-#endif
-}
-msg_t *build_proceeding (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- CALL_PROCEEDING_t *proceeding;
- msg_t *msg =(msg_t*)create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, bc?bc->l3_id:-1, sizeof(CALL_PROCEEDING_t) ,nt);
-
- proceeding=(CALL_PROCEEDING_t*)((msg->data+HEADER_LEN));
-
- enc_ie_channel_id(&proceeding->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
-
- if (nt)
- enc_ie_progress(&proceeding->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
-
-
-#if DEBUG
- printf("Building PROCEEDING Msg\n");
-#endif
- return msg;
-}
-void print_proceeding (struct isdn_msg msgs[])
-{
-}
-
-void parse_alerting (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- ALERTING_t *alerting=(ALERTING_t*)((unsigned long)(msg->data+HEADER_LEN));
- //Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);
-
- dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)alerting, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
-
-#if DEBUG
- printf("Parsing ALERTING Msg\n");
-#endif
-
-
-}
-msg_t *build_alerting (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- ALERTING_t *alerting;
- msg_t *msg =(msg_t*)create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, bc?bc->l3_id:-1, sizeof(ALERTING_t) ,nt);
-
- alerting=(ALERTING_t*)((msg->data+HEADER_LEN));
-
- enc_ie_channel_id(&alerting->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
-
- if (nt)
- enc_ie_progress(&alerting->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
-#if DEBUG
- printf("Building ALERTING Msg\n");
-#endif
- return msg;
-}
-void print_alerting (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_progress (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- PROGRESS_t *progress=(PROGRESS_t*)((unsigned long)(msg->data+HEADER_LEN));
- //Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);
-
- dec_ie_progress(progress->PROGRESS, (Q931_info_t *)progress, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
-
-#if DEBUG
- printf("Parsing PROGRESS Msg\n");
-#endif
-}
-
-msg_t *build_progress (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- PROGRESS_t *progress;
- msg_t *msg =(msg_t*)create_l3msg(CC_PROGRESS | REQUEST, MT_PROGRESS, bc?bc->l3_id:-1, sizeof(PROGRESS_t) ,nt);
-
- progress=(PROGRESS_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building PROGRESS Msg\n");
-#endif
- return msg;
-}
-void print_progress (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_setup (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- SETUP_t *setup= (SETUP_t*)((unsigned long)msg->data+HEADER_LEN);
- Q931_info_t *qi=(Q931_info_t*)((unsigned long)msg->data+HEADER_LEN);
-
-#if DEBUG
- printf("Parsing SETUP Msg\n");
-#endif
- {
- int type,plan,present, screen;
- char id[32];
- dec_ie_calling_pn(setup->CALLING_PN, qi, &type, &plan, &present, &screen, (unsigned char *)id, sizeof(id), nt,bc);
-
- bc->onumplan=type;
- strcpy(bc->oad, id);
- switch (present) {
- case 0:
-// cb_log(3, bc->stack->port, " --> Pres:0\n");
- bc->pres=0; /* screened */
- break;
- case 1:
-// cb_log(3, bc->stack->port, " --> Pres:1\n");
- bc->pres=1; /* not screened */
- break;
- default:
-// cb_log(3, bc->stack->port, " --> Pres:%d\n",present);
- bc->pres=0;
- }
- switch (screen) {
- case 0:
-// cb_log(4, bc->stack->port, " --> Screen:0\n");
- break;
- default:
-// cb_log(4, bc->stack->port, " --> Screen:%d\n",screen);
- ;
- }
- }
- {
- int type, plan;
- char number[32];
- dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)setup, &type, &plan, (unsigned char *)number, sizeof(number), nt,bc);
- strcpy(bc->dad, number);
- bc->dnumplan=type;
- }
- {
- char keypad[32];
- dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)setup, (unsigned char *)keypad, sizeof(keypad), nt,bc);
- strcpy(bc->keypad, keypad);
- }
-
- {
- int sending_complete;
- dec_ie_complete(setup->COMPLETE, (Q931_info_t *)setup, &sending_complete, nt,bc);
- }
-
- {
- int type, plan, present, screen, reason;
- char id[32];
- dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)setup, &type, &plan, &present, &screen, &reason, (unsigned char *)id, sizeof(id), nt,bc);
-
- strcpy(bc->rad, id);
- bc->rnumplan=type;
-// cb_log(3, bc->stack->port, " --> Redirecting number (REDIR_NR): '%s'\n", id);
- }
- {
- int coding, capability, mode, rate, multi, user, async, urate, stopbits, dbits, parity;
- dec_ie_bearer(setup->BEARER, (Q931_info_t *)setup, &coding, &capability, &mode, &rate, &multi, &user, &async, &urate, &stopbits, &dbits, &parity, nt,bc);
- switch (capability) {
- case -1: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
-// cb_log(2, bc->stack->port, " --> cap -1 -> digital\n");
- break;
- case 0: bc->capability=INFO_CAPABILITY_SPEECH;
-// cb_log(2, bc->stack->port, " --> cap speech\n");
- break;
- case 8: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
- bc->user1 = user;
- bc->async = async;
- bc->urate = urate;
-
- bc->rate = rate;
- bc->mode = mode;
-
-// cb_log(2, bc->stack->port, " --> cap unres Digital (user l1 %d, async %d, user rate %d\n", user, async, urate);
- break;
- case 9: bc->capability=INFO_CAPABILITY_DIGITAL_RESTRICTED;
-// cb_log(2, bc->stack->port, " --> cap res Digital\n");
- break;
- default:
-// cb_log(2, bc->stack->port, " --> cap Else\n");
- break;
- }
-
- switch(user) {
- case 2:
- bc->law=INFO_CODEC_ULAW;
- break;
- case 3:
- bc->law=INFO_CODEC_ALAW;
- break;
- default:
- bc->law=INFO_CODEC_ALAW;
-
- }
-
- bc->capability=capability;
- }
- {
- int exclusive, channel;
- dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)setup, &exclusive, &channel, nt,bc);
- if (channel==0xff) /* any channel */
- channel=-1;
-
- if (channel > 0)
- bc->channel = channel;
- }
-
- dec_ie_progress(setup->PROGRESS, (Q931_info_t *)setup, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
-
-}
-
-#define ANY_CHANNEL 0xff /* IE attribut for 'any channel' */
-msg_t *build_setup (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- SETUP_t *setup;
- msg_t *msg =(msg_t*)create_l3msg(CC_SETUP | REQUEST, MT_SETUP, bc?bc->l3_id:-1, sizeof(SETUP_t) ,nt);
-
- setup=(SETUP_t*)((msg->data+HEADER_LEN));
-
-// cb_log(2, bc->stack->port, " --> oad %s dad %s channel %d\n",bc->oad, bc->dad,bc->channel);
- if (bc->channel == 0 || bc->channel == ANY_CHANNEL || bc->channel==-1)
- enc_ie_channel_id(&setup->CHANNEL_ID, msg, 0, bc->channel, nt,bc);
- else
- enc_ie_channel_id(&setup->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
-
- {
- int type=bc->onumplan,plan=1,present=bc->pres,screen=bc->screen;
- enc_ie_calling_pn(&setup->CALLING_PN, msg, type, plan, present,
- screen, bc->oad, nt, bc);
- }
-
- {
- if (bc->dad[0])
- enc_ie_called_pn(&setup->CALLED_PN, msg, bc->dnumplan, 1, bc->dad, nt,bc);
- }
-
- if (*bc->display) {
- enc_ie_display(&setup->DISPLAY, msg, bc->display, nt,bc);
- }
-
- {
- int coding=0, capability, mode=0 /* 2 for packet ! */
- ,user, rate=0x10;
-
- switch (bc->law) {
- case INFO_CODEC_ULAW: user=2;
- break;
- case INFO_CODEC_ALAW: user=3;
- break;
- default:
- user=3;
- }
-
- switch (bc->capability) {
- case INFO_CAPABILITY_SPEECH: capability = 0;
- break;
- case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: capability = 8;
- user=-1;
- break;
- case INFO_CAPABILITY_DIGITAL_RESTRICTED: capability = 9;
- user=-1;
- break;
- default:
- capability=bc->capability;
- }
-
-
-
- enc_ie_bearer(&setup->BEARER, msg, coding, capability, mode, rate, -1, user, nt,bc);
- }
-
-#if DEBUG
- printf("Building SETUP Msg\n");
-#endif
- return msg;
-}
-
-void print_setup (struct isdn_msg msgs[])
-{
-}
-
-void parse_connect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- CONNECT_t *connect=(CONNECT_t*)((unsigned long)(msg->data+HEADER_LEN));
-
- bc->ces = connect->ces;
- bc->ces = connect->ces;
-
- dec_ie_progress(connect->PROGRESS, (Q931_info_t *)connect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
-
-#if DEBUG
- printf("Parsing CONNECT Msg\n");
-#endif
-}
-msg_t *build_connect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- CONNECT_t *connect;
- msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, bc?bc->l3_id:-1, sizeof(CONNECT_t) ,nt);
-
- connect=(CONNECT_t*)((msg->data+HEADER_LEN));
-
- if (nt) {
- time_t now;
- time(&now);
- enc_ie_date(&connect->DATE, msg, now, nt,bc);
- }
-
- {
- int type=0, plan=1, present=2, screen=0;
- enc_ie_connected_pn(&connect->CONNECT_PN, msg, type,plan, present, screen, (unsigned char*) bc->dad , nt , bc);
- }
-
-#if DEBUG
- printf("Building CONNECT Msg\n");
-#endif
- return msg;
-}
-void print_connect (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_setup_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- SETUP_ACKNOWLEDGE_t *setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((unsigned long)(msg->data+HEADER_LEN));
-
- {
- int exclusive, channel;
- dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)setup_acknowledge, &exclusive, &channel, nt,bc);
-
- if (channel==0xff) /* any channel */
- channel=-1;
-
- if (channel > 0)
- bc->channel = channel;
- }
-
- dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)setup_acknowledge, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
-#if DEBUG
- printf("Parsing SETUP_ACKNOWLEDGE Msg\n");
-#endif
-
-
-}
-msg_t *build_setup_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- SETUP_ACKNOWLEDGE_t *setup_acknowledge;
- msg_t *msg =(msg_t*)create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(SETUP_ACKNOWLEDGE_t) ,nt);
-
- setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
-
- enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
-
- if (nt)
- enc_ie_progress(&setup_acknowledge->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
-
-#if DEBUG
- printf("Building SETUP_ACKNOWLEDGE Msg\n");
-#endif
- return msg;
-}
-
-void print_setup_acknowledge (struct isdn_msg msgs[])
-{
-}
-
-void parse_connect_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing CONNECT_ACKNOWLEDGE Msg\n");
-#endif
-
-
-}
-msg_t *build_connect_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
- msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, bc?bc->l3_id:-1, sizeof(CONNECT_ACKNOWLEDGE_t) ,nt);
-
- connect_acknowledge=(CONNECT_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
-
- enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
-
-#if DEBUG
- printf("Building CONNECT_ACKNOWLEDGE Msg\n");
-#endif
- return msg;
-}
-void print_connect_acknowledge (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_user_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing USER_INFORMATION Msg\n");
-#endif
-
-
-}
-msg_t *build_user_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- USER_INFORMATION_t *user_information;
- msg_t *msg =(msg_t*)create_l3msg(CC_USER_INFORMATION | REQUEST, MT_USER_INFORMATION, bc?bc->l3_id:-1, sizeof(USER_INFORMATION_t) ,nt);
-
- user_information=(USER_INFORMATION_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building USER_INFORMATION Msg\n");
-#endif
- return msg;
-}
-void print_user_information (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_suspend_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing SUSPEND_REJECT Msg\n");
-#endif
-
-
-}
-msg_t *build_suspend_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- SUSPEND_REJECT_t *suspend_reject;
- msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, bc?bc->l3_id:-1, sizeof(SUSPEND_REJECT_t) ,nt);
-
- suspend_reject=(SUSPEND_REJECT_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building SUSPEND_REJECT Msg\n");
-#endif
- return msg;
-}
-void print_suspend_reject (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_resume_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing RESUME_REJECT Msg\n");
-#endif
-
-
-}
-msg_t *build_resume_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RESUME_REJECT_t *resume_reject;
- msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, bc?bc->l3_id:-1, sizeof(RESUME_REJECT_t) ,nt);
-
- resume_reject=(RESUME_REJECT_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building RESUME_REJECT Msg\n");
-#endif
- return msg;
-}
-void print_resume_reject (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_hold (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing HOLD Msg\n");
-#endif
-
-
-}
-msg_t *build_hold (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- HOLD_t *hold;
- msg_t *msg =(msg_t*)create_l3msg(CC_HOLD | REQUEST, MT_HOLD, bc?bc->l3_id:-1, sizeof(HOLD_t) ,nt);
-
- hold=(HOLD_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building HOLD Msg\n");
-#endif
- return msg;
-}
-void print_hold (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_suspend (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing SUSPEND Msg\n");
-#endif
-
-
-}
-msg_t *build_suspend (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- SUSPEND_t *suspend;
- msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND | REQUEST, MT_SUSPEND, bc?bc->l3_id:-1, sizeof(SUSPEND_t) ,nt);
-
- suspend=(SUSPEND_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building SUSPEND Msg\n");
-#endif
- return msg;
-}
-void print_suspend (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_resume (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing RESUME Msg\n");
-#endif
-
-
-}
-msg_t *build_resume (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RESUME_t *resume;
- msg_t *msg =(msg_t*)create_l3msg(CC_RESUME | REQUEST, MT_RESUME, bc?bc->l3_id:-1, sizeof(RESUME_t) ,nt);
-
- resume=(RESUME_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building RESUME Msg\n");
-#endif
- return msg;
-}
-void print_resume (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_hold_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing HOLD_ACKNOWLEDGE Msg\n");
-#endif
-
-
-}
-msg_t *build_hold_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- HOLD_ACKNOWLEDGE_t *hold_acknowledge;
- msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(HOLD_ACKNOWLEDGE_t) ,nt);
-
- hold_acknowledge=(HOLD_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building HOLD_ACKNOWLEDGE Msg\n");
-#endif
- return msg;
-}
-void print_hold_acknowledge (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_suspend_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing SUSPEND_ACKNOWLEDGE Msg\n");
-#endif
-
-
-}
-msg_t *build_suspend_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
- msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(SUSPEND_ACKNOWLEDGE_t) ,nt);
-
- suspend_acknowledge=(SUSPEND_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building SUSPEND_ACKNOWLEDGE Msg\n");
-#endif
- return msg;
-}
-void print_suspend_acknowledge (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_resume_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing RESUME_ACKNOWLEDGE Msg\n");
-#endif
-
-
-}
-msg_t *build_resume_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RESUME_ACKNOWLEDGE_t *resume_acknowledge;
- msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(RESUME_ACKNOWLEDGE_t) ,nt);
-
- resume_acknowledge=(RESUME_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building RESUME_ACKNOWLEDGE Msg\n");
-#endif
- return msg;
-}
-void print_resume_acknowledge (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_hold_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing HOLD_REJECT Msg\n");
-#endif
-
-
-}
-msg_t *build_hold_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- HOLD_REJECT_t *hold_reject;
- msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, bc?bc->l3_id:-1, sizeof(HOLD_REJECT_t) ,nt);
-
- hold_reject=(HOLD_REJECT_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building HOLD_REJECT Msg\n");
-#endif
- return msg;
-}
-void print_hold_reject (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_retrieve (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing RETRIEVE Msg\n");
-#endif
-
-
-}
-msg_t *build_retrieve (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RETRIEVE_t *retrieve;
- msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE | REQUEST, MT_RETRIEVE, bc?bc->l3_id:-1, sizeof(RETRIEVE_t) ,nt);
-
- retrieve=(RETRIEVE_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building RETRIEVE Msg\n");
-#endif
- return msg;
-}
-void print_retrieve (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_retrieve_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing RETRIEVE_ACKNOWLEDGE Msg\n");
-#endif
-
-
-}
-msg_t *build_retrieve_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
- msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(RETRIEVE_ACKNOWLEDGE_t) ,nt);
-
- retrieve_acknowledge=(RETRIEVE_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
-
- enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
-#if DEBUG
- printf("Building RETRIEVE_ACKNOWLEDGE Msg\n");
-#endif
- return msg;
-}
-void print_retrieve_acknowledge (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_retrieve_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing RETRIEVE_REJECT Msg\n");
-#endif
-
-
-}
-msg_t *build_retrieve_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RETRIEVE_REJECT_t *retrieve_reject;
- msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, bc?bc->l3_id:-1, sizeof(RETRIEVE_REJECT_t) ,nt);
-
- retrieve_reject=(RETRIEVE_REJECT_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building RETRIEVE_REJECT Msg\n");
-#endif
- return msg;
-}
-void print_retrieve_reject (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_disconnect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- DISCONNECT_t *disconnect=(DISCONNECT_t*)((unsigned long)(msg->data+HEADER_LEN));
- int location;
-
- dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)(disconnect), &location, &bc->cause, nt,bc);
-
- dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)disconnect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
-#if DEBUG
- printf("Parsing DISCONNECT Msg\n");
-#endif
-
-
-}
-msg_t *build_disconnect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- DISCONNECT_t *disconnect;
- msg_t *msg =(msg_t*)create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, bc?bc->l3_id:-1, sizeof(DISCONNECT_t) ,nt);
-
- disconnect=(DISCONNECT_t*)((msg->data+HEADER_LEN));
-
- enc_ie_cause(&disconnect->CAUSE, msg, (nt)?1:0, bc->out_cause,nt,bc);
- if (nt) enc_ie_progress(&disconnect->PROGRESS, msg, 0, nt?1:5, 8 ,nt,bc);
-
-#if DEBUG
- printf("Building DISCONNECT Msg\n");
-#endif
- return msg;
-}
-void print_disconnect (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_restart (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RESTART_t *restart=(RESTART_t*)((unsigned long)(msg->data+HEADER_LEN));
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
-#if DEBUG
- printf("Parsing RESTART Msg\n");
-#endif
-
- {
- int exclusive, channel;
- dec_ie_channel_id(restart->CHANNEL_ID, (Q931_info_t *)restart, &exclusive, &channel, nt,bc);
- if (channel==0xff) /* any channel */
- channel=-1;
- cb_log(0, stack->port, "CC_RESTART Request on channel:%d on port:%d\n",stack->port);
- }
-
-
-}
-msg_t *build_restart (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RESTART_t *restart;
- msg_t *msg =(msg_t*)create_l3msg(CC_RESTART | REQUEST, MT_RESTART, bc?bc->l3_id:-1, sizeof(RESTART_t) ,nt);
-
- restart=(RESTART_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building RESTART Msg\n");
-#endif
- return msg;
-}
-void print_restart (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_release (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RELEASE_t *release=(RELEASE_t*)((unsigned long)(msg->data+HEADER_LEN));
- int location;
-
- dec_ie_cause(release->CAUSE, (Q931_info_t *)(release), &location, &bc->cause, nt,bc);
-#if DEBUG
- printf("Parsing RELEASE Msg\n");
-#endif
-
-
-}
-msg_t *build_release (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RELEASE_t *release;
- msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, bc?bc->l3_id:-1, sizeof(RELEASE_t) ,nt);
-
- release=(RELEASE_t*)((msg->data+HEADER_LEN));
-
-
- enc_ie_cause(&release->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
-
-#if DEBUG
- printf("Building RELEASE Msg\n");
-#endif
- return msg;
-}
-void print_release (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_release_complete (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RELEASE_COMPLETE_t *release_complete=(RELEASE_COMPLETE_t*)((unsigned long)(msg->data+HEADER_LEN));
- int location;
- iframe_t *frm = (iframe_t*) msg->data;
-
- struct misdn_stack *stack=get_stack_by_bc(bc);
-
-#ifdef MISDNUSER_JOLLY
- mISDNuser_head_t *hh;
- hh=(mISDNuser_head_t*)msg->data;
-#else
- mISDN_head_t *hh;
- hh=(mISDN_head_t*)msg->data;
-#endif
-
- if (nt) {
- if (hh->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
- cb_log(0, stack->port, "CC_RELEASE_COMPLETE|CONFIRM [NT] port:%d\n",stack->port);
- return;
- }
- } else {
- if (frm->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
- cb_log(0, stack->port, "CC_RELEASE_COMPLETE|CONFIRM [TE] port:%d\n",stack->port);
- return;
- }
- }
- dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)(release_complete), &location, &bc->cause, nt,bc);
-
-
-#if DEBUG
- printf("Parsing RELEASE_COMPLETE Msg\n");
-#endif
-
-
-}
-msg_t *build_release_complete (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- RELEASE_COMPLETE_t *release_complete;
- msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, bc?bc->l3_id:-1, sizeof(RELEASE_COMPLETE_t) ,nt);
-
- release_complete=(RELEASE_COMPLETE_t*)((msg->data+HEADER_LEN));
-
- enc_ie_cause(&release_complete->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
-
-#if DEBUG
- printf("Building RELEASE_COMPLETE Msg\n");
-#endif
- return msg;
-}
-void print_release_complete (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_facility (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- FACILITY_t *facility=(FACILITY_t*)((unsigned long)(msg->data+HEADER_LEN));
- Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);
-
-
-#if DEBUG
- printf("Parsing FACILITY Msg\n");
-#endif
-
- {
- char fac[128];
- int facility_len;
-
- dec_ie_facility(facility->FACILITY, qi, fac, &facility_len, nt, bc);
- }
-
-
-}
-msg_t *build_facility (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- FACILITY_t *facility;
- msg_t *msg =(msg_t*)create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, bc?bc->l3_id:-1, sizeof(FACILITY_t) ,nt);
-
- facility=(FACILITY_t*)((msg->data+HEADER_LEN));
-
- {
- if (*bc->display) {
- printf("Sending %s as Display\n", bc->display);
- enc_ie_display(&facility->DISPLAY, msg, bc->display, nt,bc);
- }
-
-
-
- switch ( bc->facility ) {
- case FACILITY_CALLDEFLECT:
- enc_facility_calldeflect(&facility->FACILITY, msg, bc->facility_calldeflect_nr, nt, bc);
-
- break;
- case FACILITY_NONE:
- break;
- }
-
- }
-
-#if DEBUG
- printf("Building FACILITY Msg\n");
-#endif
- return msg;
-}
-void print_facility (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_notify (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing NOTIFY Msg\n");
-#endif
-
-
-}
-msg_t *build_notify (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- NOTIFY_t *notify;
- msg_t *msg =(msg_t*)create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, bc?bc->l3_id:-1, sizeof(NOTIFY_t) ,nt);
-
- notify=(NOTIFY_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building NOTIFY Msg\n");
-#endif
- return msg;
-}
-void print_notify (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_status_enquiry (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing STATUS_ENQUIRY Msg\n");
-#endif
-
-
-}
-msg_t *build_status_enquiry (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- STATUS_ENQUIRY_t *status_enquiry;
- msg_t *msg =(msg_t*)create_l3msg(CC_STATUS_ENQUIRY | REQUEST, MT_STATUS_ENQUIRY, bc?bc->l3_id:-1, sizeof(STATUS_ENQUIRY_t) ,nt);
-
- status_enquiry=(STATUS_ENQUIRY_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building STATUS_ENQUIRY Msg\n");
-#endif
- return msg;
-}
-void print_status_enquiry (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- INFORMATION_t *information=(INFORMATION_t*)((unsigned long)(msg->data+HEADER_LEN));
-
- {
- int type, plan;
- char number[32];
- char keypad[32];
- dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *)information, &type, &plan, (unsigned char *)number, sizeof(number), nt,bc);
- dec_ie_keypad(information->KEYPAD, (Q931_info_t *)information, (unsigned char *)keypad, sizeof(keypad), nt,bc);
- strcpy(bc->info_dad, number);
- strcpy(bc->keypad,keypad);
-
- }
-#if DEBUG
- printf("Parsing INFORMATION Msg\n");
-#endif
-
-
-}
-msg_t *build_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- INFORMATION_t *information;
- msg_t *msg =(msg_t*)create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, bc?bc->l3_id:-1, sizeof(INFORMATION_t) ,nt);
-
- information=(INFORMATION_t*)((msg->data+HEADER_LEN));
-
- {
- enc_ie_called_pn(&information->CALLED_PN, msg, 0, 1, bc->info_dad, nt,bc);
- }
-
- {
- if (*bc->display) {
- printf("Sending %s as Display\n", bc->display);
- enc_ie_display(&information->DISPLAY, msg, bc->display, nt,bc);
- }
- }
-
-#if DEBUG
- printf("Building INFORMATION Msg\n");
-#endif
- return msg;
-}
-void print_information (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_status (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- STATUS_t *status=(STATUS_t*)((unsigned long)(msg->data+HEADER_LEN));
- int location;
-
- dec_ie_cause(status->CAUSE, (Q931_info_t *)(status), &location, &bc->cause, nt,bc);
- ;
-
-#if DEBUG
- printf("Parsing STATUS Msg\n");
-#endif
-
-
-}
-msg_t *build_status (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- STATUS_t *status;
- msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS, bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt);
-
- status=(STATUS_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building STATUS Msg\n");
-#endif
- return msg;
-}
-void print_status (struct isdn_msg msgs[])
-{
-}
-
-
-void parse_timeout (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
-#if DEBUG
- printf("Parsing STATUS Msg\n");
-#endif
-
-
-}
-msg_t *build_timeout (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
-{
- int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
- STATUS_t *status;
- msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS, bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt);
-
- status=(STATUS_t*)((msg->data+HEADER_LEN));
-
-#if DEBUG
- printf("Building STATUS Msg\n");
-#endif
- return msg;
-}
-void print_timeout (struct isdn_msg msgs[])
-{
-}
-
-
-/************************************/
-
-
-
-
-/** Msg Array **/
-
-struct isdn_msg msgs_g[] = {
- {CC_PROCEEDING,L3,EVENT_PROCEEDING,
- parse_proceeding,build_proceeding,print_proceeding,
- "PROCEEDING"},
- {CC_ALERTING,L3,EVENT_ALERTING,
- parse_alerting,build_alerting,print_alerting,
- "ALERTING"},
- {CC_PROGRESS,L3,EVENT_PROGRESS,
- parse_progress,build_progress,print_progress,
- "PROGRESS"},
- {CC_SETUP,L3,EVENT_SETUP,
- parse_setup,build_setup,print_setup,
- "SETUP"},
- {CC_CONNECT,L3,EVENT_CONNECT,
- parse_connect,build_connect,print_connect,
- "CONNECT"},
- {CC_SETUP_ACKNOWLEDGE,L3,EVENT_SETUP_ACKNOWLEDGE,
- parse_setup_acknowledge,build_setup_acknowledge,print_setup_acknowledge,
- "SETUP_ACKNOWLEDGE"},
- {CC_CONNECT_ACKNOWLEDGE ,L3,EVENT_CONNECT_ACKNOWLEDGE ,
- parse_connect_acknowledge ,build_connect_acknowledge ,print_connect_acknowledge ,
- "CONNECT_ACKNOWLEDGE "},
- {CC_USER_INFORMATION,L3,EVENT_USER_INFORMATION,
- parse_user_information,build_user_information,print_user_information,
- "USER_INFORMATION"},
- {CC_SUSPEND_REJECT,L3,EVENT_SUSPEND_REJECT,
- parse_suspend_reject,build_suspend_reject,print_suspend_reject,
- "SUSPEND_REJECT"},
- {CC_RESUME_REJECT,L3,EVENT_RESUME_REJECT,
- parse_resume_reject,build_resume_reject,print_resume_reject,
- "RESUME_REJECT"},
- {CC_HOLD,L3,EVENT_HOLD,
- parse_hold,build_hold,print_hold,
- "HOLD"},
- {CC_SUSPEND,L3,EVENT_SUSPEND,
- parse_suspend,build_suspend,print_suspend,
- "SUSPEND"},
- {CC_RESUME,L3,EVENT_RESUME,
- parse_resume,build_resume,print_resume,
- "RESUME"},
- {CC_HOLD_ACKNOWLEDGE,L3,EVENT_HOLD_ACKNOWLEDGE,
- parse_hold_acknowledge,build_hold_acknowledge,print_hold_acknowledge,
- "HOLD_ACKNOWLEDGE"},
- {CC_SUSPEND_ACKNOWLEDGE,L3,EVENT_SUSPEND_ACKNOWLEDGE,
- parse_suspend_acknowledge,build_suspend_acknowledge,print_suspend_acknowledge,
- "SUSPEND_ACKNOWLEDGE"},
- {CC_RESUME_ACKNOWLEDGE,L3,EVENT_RESUME_ACKNOWLEDGE,
- parse_resume_acknowledge,build_resume_acknowledge,print_resume_acknowledge,
- "RESUME_ACKNOWLEDGE"},
- {CC_HOLD_REJECT,L3,EVENT_HOLD_REJECT,
- parse_hold_reject,build_hold_reject,print_hold_reject,
- "HOLD_REJECT"},
- {CC_RETRIEVE,L3,EVENT_RETRIEVE,
- parse_retrieve,build_retrieve,print_retrieve,
- "RETRIEVE"},
- {CC_RETRIEVE_ACKNOWLEDGE,L3,EVENT_RETRIEVE_ACKNOWLEDGE,
- parse_retrieve_acknowledge,build_retrieve_acknowledge,print_retrieve_acknowledge,
- "RETRIEVE_ACKNOWLEDGE"},
- {CC_RETRIEVE_REJECT,L3,EVENT_RETRIEVE_REJECT,
- parse_retrieve_reject,build_retrieve_reject,print_retrieve_reject,
- "RETRIEVE_REJECT"},
- {CC_DISCONNECT,L3,EVENT_DISCONNECT,
- parse_disconnect,build_disconnect,print_disconnect,
- "DISCONNECT"},
- {CC_RESTART,L3,EVENT_RESTART,
- parse_restart,build_restart,print_restart,
- "RESTART"},
- {CC_RELEASE,L3,EVENT_RELEASE,
- parse_release,build_release,print_release,
- "RELEASE"},
- {CC_RELEASE_COMPLETE,L3,EVENT_RELEASE_COMPLETE,
- parse_release_complete,build_release_complete,print_release_complete,
- "RELEASE_COMPLETE"},
- {CC_FACILITY,L3,EVENT_FACILITY,
- parse_facility,build_facility,print_facility,
- "FACILITY"},
- {CC_NOTIFY,L3,EVENT_NOTIFY,
- parse_notify,build_notify,print_notify,
- "NOTIFY"},
- {CC_STATUS_ENQUIRY,L3,EVENT_STATUS_ENQUIRY,
- parse_status_enquiry,build_status_enquiry,print_status_enquiry,
- "STATUS_ENQUIRY"},
- {CC_INFORMATION,L3,EVENT_INFORMATION,
- parse_information,build_information,print_information,
- "INFORMATION"},
- {CC_STATUS,L3,EVENT_STATUS,
- parse_status,build_status,print_status,
- "STATUS"},
- {CC_TIMEOUT,L3,EVENT_TIMEOUT,
- parse_timeout,build_timeout,print_timeout,
- "TIMEOUT"},
- {0,0,0,NULL,NULL,NULL,NULL}
-};
-
-#define msgs_max (sizeof(msgs_g)/sizeof(struct isdn_msg))
-
-/** INTERFACE FCTS ***/
-int isdn_msg_get_index(struct isdn_msg msgs[], msg_t *msg, int nt)
-{
- int i;
-
- if (nt){
-#ifdef MISDNUSER_JOLLY
- mISDNuser_head_t *hh = (mISDNuser_head_t*)msg->data;
-#else
- mISDN_head_t *hh = (mISDN_head_t*)msg->data;
-#endif
-
- for (i=0; i< msgs_max -1; i++)
- if ( (hh->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
-
- } else {
- iframe_t *frm = (iframe_t*)msg->data;
-
- for (i=0; i< msgs_max -1; i++)
- if ( (frm->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
- }
-
- return -1;
-}
-
-int isdn_msg_get_index_by_event(struct isdn_msg msgs[], enum event_e event, int nt)
-{
- int i;
- for (i=0; i< msgs_max; i++)
- if ( event == msgs[i].event) return i;
-
- cb_log(4,0, "get_index: EVENT NOT FOUND!!\n");
-
- return -1;
-}
-
-enum event_e isdn_msg_get_event(struct isdn_msg msgs[], msg_t *msg, int nt)
-{
- int i=isdn_msg_get_index(msgs, msg, nt);
- if(i>=0) return msgs[i].event;
- return EVENT_UNKNOWN;
-}
-
-char * isdn_msg_get_info(struct isdn_msg msgs[], msg_t *msg, int nt)
-{
- int i=isdn_msg_get_index(msgs, msg, nt);
- if(i>=0) return msgs[i].info;
- return NULL;
-}
-
-
-char EVENT_CLEAN_INFO[] = "CLEAN_UP";
-char EVENT_DTMF_TONE_INFO[] = "DTMF_TONE";
-char EVENT_NEW_L3ID_INFO[] = "NEW_L3ID";
-char EVENT_NEW_BC_INFO[] = "NEW_BC";
-char EVENT_BCHAN_DATA_INFO[] = "BCHAN_DATA";
-
-char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
-{
- int i=isdn_msg_get_index_by_event(msgs, event, nt);
-
- if(i>=0) return msgs[i].info;
-
- if (event == EVENT_CLEANUP) return EVENT_CLEAN_INFO;
- if (event == EVENT_DTMF_TONE) return EVENT_DTMF_TONE_INFO;
- if (event == EVENT_NEW_L3ID) return EVENT_NEW_L3ID_INFO;
- if (event == EVENT_NEW_BC) return EVENT_NEW_BC_INFO;
- if (event == EVENT_BCHAN_DATA) return EVENT_BCHAN_DATA_INFO;
-
- return NULL;
-}
-
-int isdn_msg_parse_event(struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
-{
- int i=isdn_msg_get_index(msgs, msg, nt);
- if(i<0) return -1;
-
- msgs[i].msg_parser(msgs, msg, bc, nt);
- return 0;
-}
-
-msg_t * isdn_msg_build_event(struct isdn_msg msgs[], struct misdn_bchannel *bc, enum event_e event, int nt)
-{
- int i=isdn_msg_get_index_by_event(msgs, event, nt);
- if(i<0) return NULL;
-
- return msgs[i].msg_builder(msgs, bc, nt);
-}
-
diff --git a/1.2-netsec/channels/misdn/mISDN.patch b/1.2-netsec/channels/misdn/mISDN.patch
deleted file mode 100644
index 681c5fa79..000000000
--- a/1.2-netsec/channels/misdn/mISDN.patch
+++ /dev/null
@@ -1,2500 +0,0 @@
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/arith.h mISDN/drivers/isdn/hardware/mISDN/arith.h
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/arith.h 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/arith.h 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,347 @@
-+#ifndef _ZAPTEL_ARITH_H
-+#define _ZAPTEL_ARITH_H
-+/*
-+ * Handy add/subtract functions to operate on chunks of shorts.
-+ * Feel free to add customizations for additional architectures
-+ *
-+ */
-+
-+#ifdef CONFIG_ZAPTEL_MMX
-+#ifdef ZT_CHUNKSIZE
-+static inline void __ACSS(volatile short *dst, const short *src)
-+{
-+ __asm__ __volatile__ (
-+ "movq 0(%0), %%mm0;\n"
-+ "movq 0(%1), %%mm1;\n"
-+ "movq 8(%0), %%mm2;\n"
-+ "movq 8(%1), %%mm3;\n"
-+ "paddsw %%mm1, %%mm0;\n"
-+ "paddsw %%mm3, %%mm2;\n"
-+ "movq %%mm0, 0(%0);\n"
-+ "movq %%mm2, 8(%0);\n"
-+ : "=r" (dst)
-+ : "r" (src), "0" (dst)
-+ : "memory"
-+#if CLOBBERMMX
-+ , "%mm0", "%mm1", "%mm2", "%mm3"
-+#endif
-+ );
-+
-+}
-+static inline void __SCSS(volatile short *dst, const short *src)
-+{
-+ __asm__ __volatile__ (
-+ "movq 0(%0), %%mm0;\n"
-+ "movq 0(%1), %%mm1;\n"
-+ "movq 8(%0), %%mm2;\n"
-+ "movq 8(%1), %%mm3;\n"
-+ "psubsw %%mm1, %%mm0;\n"
-+ "psubsw %%mm3, %%mm2;\n"
-+ "movq %%mm0, 0(%0);\n"
-+ "movq %%mm2, 8(%0);\n"
-+ : "=r" (dst)
-+ : "r" (src), "0" (dst)
-+ : "memory"
-+#if CLOBBERMMX
-+ , "%mm0", "%mm1", "%mm2", "%mm3"
-+#endif
-+ );
-+
-+}
-+
-+#if (ZT_CHUNKSIZE == 8)
-+#define ACSS(a,b) __ACSS(a,b)
-+#define SCSS(a,b) __SCSS(a,b)
-+#elif (ZT_CHUNKSIZE > 8)
-+static inline void ACSS(volatile short *dst, const short *src)
-+{
-+ int x;
-+ for (x=0;x<ZT_CHUNKSIZE;x+=8)
-+ __ACSS(dst + x, src + x);
-+}
-+static inline void SCSS(volatile short *dst, const short *src)
-+{
-+ int x;
-+ for (x=0;x<ZT_CHUNKSIZE;x+=8)
-+ __SCSS(dst + x, src + x);
-+}
-+#else
-+#error No MMX for ZT_CHUNKSIZE < 8
-+#endif
-+#endif
-+static inline int CONVOLVE(const int *coeffs, const short *hist, int len)
-+{
-+ int sum;
-+ /* Divide length by 16 */
-+ len >>= 4;
-+
-+ /* Clear our accumulator, mm4 */
-+
-+ /*
-+
-+ For every set of eight...
-+
-+ Load 16 coefficients into four registers...
-+ Shift each word right 16 to make them shorts...
-+ Pack the resulting shorts into two registers...
-+ With the coefficients now in mm0 and mm2, load the
-+ history into mm1 and mm3...
-+ Multiply/add mm1 into mm0, and mm3 into mm2...
-+ Add mm2 into mm0 (without saturation, alas). Now we have two half-results.
-+ Accumulate in mm4 (again, without saturation, alas)
-+ */
-+ __asm__ (
-+ "pxor %%mm4, %%mm4;\n"
-+ "mov %1, %%edi;\n"
-+ "mov %2, %%esi;\n"
-+ "mov %3, %%ecx;\n"
-+ "1:"
-+ "movq 0(%%edi), %%mm0;\n"
-+ "movq 8(%%edi), %%mm1;\n"
-+ "movq 16(%%edi), %%mm2;\n"
-+ "movq 24(%%edi), %%mm3;\n"
-+ /* can't use 4/5 since 4 is the accumulator for us */
-+ "movq 32(%%edi), %%mm6;\n"
-+ "movq 40(%%edi), %%mm7;\n"
-+ "psrad $16, %%mm0;\n"
-+ "psrad $16, %%mm1;\n"
-+ "psrad $16, %%mm2;\n"
-+ "psrad $16, %%mm3;\n"
-+ "psrad $16, %%mm6;\n"
-+ "psrad $16, %%mm7;\n"
-+ "packssdw %%mm1, %%mm0;\n"
-+ "packssdw %%mm3, %%mm2;\n"
-+ "packssdw %%mm7, %%mm6;\n"
-+ "movq 0(%%esi), %%mm1;\n"
-+ "movq 8(%%esi), %%mm3;\n"
-+ "movq 16(%%esi), %%mm7;\n"
-+ "pmaddwd %%mm1, %%mm0;\n"
-+ "pmaddwd %%mm3, %%mm2;\n"
-+ "pmaddwd %%mm7, %%mm6;\n"
-+ "paddd %%mm6, %%mm4;\n"
-+ "paddd %%mm2, %%mm4;\n"
-+ "paddd %%mm0, %%mm4;\n"
-+ /* Come back and do for the last few bytes */
-+ "movq 48(%%edi), %%mm6;\n"
-+ "movq 56(%%edi), %%mm7;\n"
-+ "psrad $16, %%mm6;\n"
-+ "psrad $16, %%mm7;\n"
-+ "packssdw %%mm7, %%mm6;\n"
-+ "movq 24(%%esi), %%mm7;\n"
-+ "pmaddwd %%mm7, %%mm6;\n"
-+ "paddd %%mm6, %%mm4;\n"
-+ "add $64, %%edi;\n"
-+ "add $32, %%esi;\n"
-+ "dec %%ecx;\n"
-+ "jnz 1b;\n"
-+ "movq %%mm4, %%mm0;\n"
-+ "psrlq $32, %%mm0;\n"
-+ "paddd %%mm0, %%mm4;\n"
-+ "movd %%mm4, %0;\n"
-+ : "=r" (sum)
-+ : "r" (coeffs), "r" (hist), "r" (len)
-+ : "%ecx", "%edi", "%esi"
-+ );
-+
-+ return sum;
-+}
-+
-+static inline void UPDATE(volatile int *taps, const short *history, const int nsuppr, const int ntaps)
-+{
-+ int i;
-+ int correction;
-+ for (i=0;i<ntaps;i++) {
-+ correction = history[i] * nsuppr;
-+ taps[i] += correction;
-+ }
-+}
-+
-+static inline void UPDATE2(volatile int *taps, volatile short *taps_short, const short *history, const int nsuppr, const int ntaps)
-+{
-+ int i;
-+ int correction;
-+#if 0
-+ ntaps >>= 4;
-+ /* First, load up taps, */
-+ __asm__ (
-+ "pxor %%mm4, %%mm4;\n"
-+ "mov %0, %%edi;\n"
-+ "mov %1, %%esi;\n"
-+ "mov %3, %%ecx;\n"
-+ "1:"
-+ "jnz 1b;\n"
-+ "movq %%mm4, %%mm0;\n"
-+ "psrlq $32, %%mm0;\n"
-+ "paddd %%mm0, %%mm4;\n"
-+ "movd %%mm4, %0;\n"
-+ : "=r" (taps), "=r" (taps_short)
-+ : "r" (history), "r" (nsuppr), "r" (ntaps), "0" (taps)
-+ : "%ecx", "%edi", "%esi"
-+ );
-+#endif
-+#if 1
-+ for (i=0;i<ntaps;i++) {
-+ correction = history[i] * nsuppr;
-+ taps[i] += correction;
-+ taps_short[i] = taps[i] >> 16;
-+ }
-+#endif
-+}
-+
-+static inline int CONVOLVE2(const short *coeffs, const short *hist, int len)
-+{
-+ int sum;
-+ /* Divide length by 16 */
-+ len >>= 4;
-+
-+ /* Clear our accumulator, mm4 */
-+
-+ /*
-+
-+ For every set of eight...
-+ Load in eight coefficients and eight historic samples, multliply add and
-+ accumulate the result
-+ */
-+ __asm__ (
-+ "pxor %%mm4, %%mm4;\n"
-+ "mov %1, %%edi;\n"
-+ "mov %2, %%esi;\n"
-+ "mov %3, %%ecx;\n"
-+ "1:"
-+ "movq 0(%%edi), %%mm0;\n"
-+ "movq 8(%%edi), %%mm2;\n"
-+ "movq 0(%%esi), %%mm1;\n"
-+ "movq 8(%%esi), %%mm3;\n"
-+ "pmaddwd %%mm1, %%mm0;\n"
-+ "pmaddwd %%mm3, %%mm2;\n"
-+ "paddd %%mm2, %%mm4;\n"
-+ "paddd %%mm0, %%mm4;\n"
-+ "movq 16(%%edi), %%mm0;\n"
-+ "movq 24(%%edi), %%mm2;\n"
-+ "movq 16(%%esi), %%mm1;\n"
-+ "movq 24(%%esi), %%mm3;\n"
-+ "pmaddwd %%mm1, %%mm0;\n"
-+ "pmaddwd %%mm3, %%mm2;\n"
-+ "paddd %%mm2, %%mm4;\n"
-+ "paddd %%mm0, %%mm4;\n"
-+ "add $32, %%edi;\n"
-+ "add $32, %%esi;\n"
-+ "dec %%ecx;\n"
-+ "jnz 1b;\n"
-+ "movq %%mm4, %%mm0;\n"
-+ "psrlq $32, %%mm0;\n"
-+ "paddd %%mm0, %%mm4;\n"
-+ "movd %%mm4, %0;\n"
-+ : "=r" (sum)
-+ : "r" (coeffs), "r" (hist), "r" (len)
-+ : "%ecx", "%edi", "%esi"
-+ );
-+
-+ return sum;
-+}
-+static inline short MAX16(const short *y, int len, int *pos)
-+{
-+ int k;
-+ short max = 0;
-+ int bestpos = 0;
-+ for (k=0;k<len;k++) {
-+ if (max < y[k]) {
-+ bestpos = k;
-+ max = y[k];
-+ }
-+ }
-+ *pos = (len - 1 - bestpos);
-+ return max;
-+}
-+
-+
-+
-+#else
-+
-+#ifdef ZT_CHUNKSIZE
-+static inline void ACSS(short *dst, short *src)
-+{
-+ int x,sum;
-+ /* Add src to dst with saturation, storing in dst */
-+ for (x=0;x<ZT_CHUNKSIZE;x++) {
-+ sum = dst[x]+src[x];
-+ if (sum > 32767)
-+ sum = 32767;
-+ else if (sum < -32768)
-+ sum = -32768;
-+ dst[x] = sum;
-+ }
-+}
-+
-+static inline void SCSS(short *dst, short *src)
-+{
-+ int x,sum;
-+ /* Add src to dst with saturation, storing in dst */
-+ for (x=0;x<ZT_CHUNKSIZE;x++) {
-+ sum = dst[x]-src[x];
-+ if (sum > 32767)
-+ sum = 32767;
-+ else if (sum < -32768)
-+ sum = -32768;
-+ dst[x] = sum;
-+ }
-+}
-+
-+#endif /* ZT_CHUNKSIZE */
-+
-+static inline int CONVOLVE(const int *coeffs, const short *hist, int len)
-+{
-+ int x;
-+ int sum = 0;
-+ for (x=0;x<len;x++)
-+ sum += (coeffs[x] >> 16) * hist[x];
-+ return sum;
-+}
-+
-+static inline int CONVOLVE2(const short *coeffs, const short *hist, int len)
-+{
-+ int x;
-+ int sum = 0;
-+ for (x=0;x<len;x++)
-+ sum += coeffs[x] * hist[x];
-+ return sum;
-+}
-+
-+static inline void UPDATE(int *taps, const short *history, const int nsuppr, const int ntaps)
-+{
-+ int i;
-+ int correction;
-+ for (i=0;i<ntaps;i++) {
-+ correction = history[i] * nsuppr;
-+ taps[i] += correction;
-+ }
-+}
-+
-+static inline void UPDATE2(int *taps, short *taps_short, const short *history, const int nsuppr, const int ntaps)
-+{
-+ int i;
-+ int correction;
-+ for (i=0;i<ntaps;i++) {
-+ correction = history[i] * nsuppr;
-+ taps[i] += correction;
-+ taps_short[i] = taps[i] >> 16;
-+ }
-+}
-+
-+static inline short MAX16(const short *y, int len, int *pos)
-+{
-+ int k;
-+ short max = 0;
-+ int bestpos = 0;
-+ for (k=0;k<len;k++) {
-+ if (max < y[k]) {
-+ bestpos = k;
-+ max = y[k];
-+ }
-+ }
-+ *pos = (len - 1 - bestpos);
-+ return max;
-+}
-+
-+#endif /* MMX */
-+#endif /* _ZAPTEL_ARITH_H */
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/biquad.h mISDN/drivers/isdn/hardware/mISDN/biquad.h
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/biquad.h 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/biquad.h 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,73 @@
-+/*
-+ * SpanDSP - a series of DSP components for telephony
-+ *
-+ * biquad.h - General telephony bi-quad section routines (currently this just
-+ * handles canonic/type 2 form)
-+ *
-+ * Written by Steve Underwood <steveu@coppice.org>
-+ *
-+ * Copyright (C) 2001 Steve Underwood
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+typedef struct
-+{
-+ int32_t gain;
-+ int32_t a1;
-+ int32_t a2;
-+ int32_t b1;
-+ int32_t b2;
-+
-+ int32_t z1;
-+ int32_t z2;
-+} biquad2_state_t;
-+
-+static inline void biquad2_init (biquad2_state_t *bq,
-+ int32_t gain,
-+ int32_t a1,
-+ int32_t a2,
-+ int32_t b1,
-+ int32_t b2)
-+{
-+ bq->gain = gain;
-+ bq->a1 = a1;
-+ bq->a2 = a2;
-+ bq->b1 = b1;
-+ bq->b2 = b2;
-+
-+ bq->z1 = 0;
-+ bq->z2 = 0;
-+}
-+/*- End of function --------------------------------------------------------*/
-+
-+static inline int16_t biquad2 (biquad2_state_t *bq, int16_t sample)
-+{
-+ int32_t y;
-+ int32_t z0;
-+
-+ z0 = sample*bq->gain + bq->z1*bq->a1 + bq->z2*bq->a2;
-+ y = z0 + bq->z1*bq->b1 + bq->z2*bq->b2;
-+
-+ bq->z2 = bq->z1;
-+ bq->z1 = z0 >> 15;
-+ y >>= 15;
-+ return y;
-+}
-+/*- End of function --------------------------------------------------------*/
-+/*- End of file ------------------------------------------------------------*/
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/dsp_cancel.c mISDN/drivers/isdn/hardware/mISDN/dsp_cancel.c
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/dsp_cancel.c 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/dsp_cancel.c 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,390 @@
-+/* $Id: mISDN_echo_cancel.patch,v 1.1 2005/11/07 16:01:31 nadi Exp $
-+ *
-+ * Simple but fast Echo cancellation for mISDN_dsp.
-+ *
-+ * Copyright Andreas Eversberg (jolly@jolly.de)
-+ *
-+ * This software may be used and distributed according to the terms
-+ * of the GNU General Public License, incorporated herein by reference.
-+ *
-+ */
-+
-+#include "layer1.h"
-+#include "helper.h"
-+#include "debug.h"
-+#include "dsp.h"
-+
-+
-+/*
-+ * how this works:
-+ *
-+ *
-+ *
-+ */
-+void bchdev_echocancel_chunk(dsp_t* dev, uint8_t *rxchunk, uint8_t *txchunk, uint16_t size);
-+int bchdev_echocancel_activate(dsp_t* dev, int deftaps, int train);
-+void bchdev_echocancel_deactivate(dsp_t* dev);
-+
-+
-+
-+
-+
-+
-+static char flip_table[256];
-+
-+void dsp_cancel_init_flip_bits()
-+{
-+ int i,k;
-+
-+ for (i = 0 ; i < 256 ; i++) {
-+ unsigned char sample = 0 ;
-+ for (k = 0; k<8; k++) {
-+ if ( i & 1 << k ) sample |= 0x80 >> k;
-+ }
-+ flip_table[i] = sample;
-+ }
-+}
-+
-+static unsigned char * flip_buf_bits ( unsigned char * buf , int len)
-+{
-+ int i;
-+ char * start = buf;
-+
-+ for (i = 0 ; i < len; i++) {
-+ buf[i] = flip_table[buf[i]];
-+ }
-+
-+ return start;
-+}
-+
-+
-+
-+void
-+dsp_cancel_tx(dsp_t *dsp, u8 *data, int len)
-+{
-+ if (!dsp ) return ;
-+ if (!data) return;
-+
-+ if (dsp->txbuflen + len < ECHOCAN_BUFLEN) {
-+ memcpy(&dsp->txbuf[dsp->txbuflen],data,len);
-+ dsp->txbuflen+=len;
-+ } else {
-+ printk("ECHOCAN: TXBUF Overflow len:%d newlen:%d\n",dsp->txbuflen,len);
-+ dsp->txbuflen=0;
-+ }
-+
-+}
-+
-+void
-+dsp_cancel_rx(dsp_t *dsp, u8 *data, int len)
-+{
-+ if (!dsp ) return ;
-+ if (!data) return;
-+
-+ if (len <= dsp->txbuflen) {
-+ char tmp[ECHOCAN_BUFLEN];
-+
-+ int delta=dsp->txbuflen-len;
-+
-+ memcpy(tmp,&dsp->txbuf[len],delta);
-+
-+ flip_buf_bits(data,len);
-+ flip_buf_bits(dsp->txbuf,len);
-+ bchdev_echocancel_chunk(dsp, data, dsp->txbuf, len);
-+ flip_buf_bits(data,len);
-+
-+ memcpy(dsp->txbuf,tmp,delta);
-+ dsp->txbuflen=delta;
-+ //dsp->txbuflen=0;
-+
-+ //bchdev_echocancel_chunk(dsp, dsp->txbuf, data, len);
-+ } else {
-+ printk("ECHOCAN: TXBUF Underrun len:%d newlen:%d\n",dsp->txbuflen,len);
-+ }
-+
-+}
-+
-+int
-+dsp_cancel_init(dsp_t *dsp, int deftaps, int training, int delay)
-+{
-+
-+ if (!dsp) return -1;
-+
-+ printk("DSP_CANCEL_INIT called\n");
-+
-+ if (delay < 0)
-+ {
-+ printk("Disabling EC\n");
-+ dsp->cancel_enable = 0;
-+
-+ dsp->txbuflen=0;
-+
-+ bchdev_echocancel_deactivate(dsp);
-+
-+ return(0);
-+ }
-+
-+ dsp->txbuflen=0;
-+ dsp->rxbuflen=0;
-+
-+
-+ bchdev_echocancel_activate(dsp,deftaps, training);
-+
-+ printk("Enabling EC\n");
-+ dsp->cancel_enable = 1;
-+ return(0);
-+}
-+
-+
-+
-+
-+
-+/*****************************************************/
-+#define __ECHO_STATE_MUTE (1 << 8)
-+#define ECHO_STATE_IDLE (0)
-+#define ECHO_STATE_PRETRAINING (1 | (__ECHO_STATE_MUTE))
-+#define ECHO_STATE_STARTTRAINING (2 | (__ECHO_STATE_MUTE))
-+#define ECHO_STATE_AWAITINGECHO (3 | (__ECHO_STATE_MUTE))
-+#define ECHO_STATE_TRAINING (4 | (__ECHO_STATE_MUTE))
-+#define ECHO_STATE_ACTIVE (5)
-+
-+#define AMI_MASK 0x55
-+
-+
-+static unsigned char linear2alaw (short 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 short int alaw2linear (uint8_t 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);
-+}
-+
-+
-+/** @return string of given echo cancellation state */
-+char* bchdev_echocancel_statestr(uint16_t state)
-+{
-+ switch(state) {
-+ case ECHO_STATE_IDLE:
-+ return "idle";
-+ break;
-+ case ECHO_STATE_PRETRAINING:
-+ return "pre-training";
-+ break;
-+ case ECHO_STATE_STARTTRAINING:
-+ return "transmit impulse";
-+ break;
-+ case ECHO_STATE_AWAITINGECHO:
-+ return "awaiting echo";
-+ break;
-+ case ECHO_STATE_TRAINING:
-+ return "training start";
-+ break;
-+ case ECHO_STATE_ACTIVE:
-+ return "training finished";
-+ break;
-+ default:
-+ return "unknown";
-+ }
-+}
-+
-+/** Changes state of echo cancellation to given state */
-+void bchdev_echocancel_setstate(dsp_t* dev, uint16_t state)
-+{
-+ char* statestr = bchdev_echocancel_statestr(state);
-+
-+ printk("bchdev: echo cancel state %d (%s)\n", state & 0xff, statestr);
-+ if (state == ECHO_STATE_ACTIVE)
-+ printk("bchdev: %d taps trained\n", dev->echolastupdate);
-+ dev->echostate = state;
-+}
-+
-+static int buf_size=0;
-+static int ec_timer=2000;
-+//static int ec_timer=1000;
-+
-+
-+/** Activates echo cancellation for the given bch_dev, device must have been locked before! */
-+int bchdev_echocancel_activate(dsp_t* dev, int deftaps, int training)
-+{
-+ int taps;
-+
-+ if (! dev) return -EINVAL;
-+
-+ if (dev->ec && dev->ecdis_rd && dev->ecdis_wr) {
-+ // already active
-+ return 0;
-+ }
-+
-+ if (deftaps>0) {
-+ taps=deftaps;
-+ } else {
-+ taps=128;
-+ }
-+
-+
-+ switch (buf_size) {
-+ case 0: taps += 0; break;
-+ case 1: taps += 256-128; break;
-+ case 2: taps += 512-128; break;
-+ default: taps += 1024-128;
-+ }
-+
-+ if (!dev->ec) dev->ec = echo_can_create(taps, 0);
-+ if (!dev->ec) {
-+ return -ENOMEM;
-+ }
-+
-+ dev->echolastupdate = 0;
-+
-+ if (!training) {
-+ dev->echotimer=0;
-+ bchdev_echocancel_setstate(dev, ECHO_STATE_IDLE);
-+ } else {
-+ if (training<10)
-+ training= ec_timer;
-+
-+ dev->echotimer = training;
-+ bchdev_echocancel_setstate(dev, ECHO_STATE_PRETRAINING);
-+
-+ }
-+
-+ if (!dev->ecdis_rd) dev->ecdis_rd = kmalloc(sizeof(echo_can_disable_detector_state_t), GFP_KERNEL);
-+ if (!dev->ecdis_rd) {
-+ kfree(dev->ec); dev->ec = NULL;
-+ return -ENOMEM;
-+ }
-+ echo_can_disable_detector_init(dev->ecdis_rd);
-+
-+ if (!dev->ecdis_wr) dev->ecdis_wr = kmalloc(sizeof(echo_can_disable_detector_state_t), GFP_KERNEL);
-+ if (!dev->ecdis_wr) {
-+ kfree(dev->ec); dev->ec = NULL;
-+ kfree(dev->ecdis_rd); dev->ecdis_rd = NULL;
-+ return -ENOMEM;
-+ }
-+ echo_can_disable_detector_init(dev->ecdis_wr);
-+
-+ return 0;
-+}
-+
-+/** Deactivates echo cancellation for the given bch_dev, device must have been locked before! */
-+void bchdev_echocancel_deactivate(dsp_t* dev)
-+{
-+ if (! dev) return;
-+
-+ //chan_misdn_log("bchdev: deactivating echo cancellation on port=%04x, chan=%02x\n", dev->stack->port, dev->channel);
-+
-+ if (dev->ec) echo_can_free(dev->ec);
-+ dev->ec = NULL;
-+
-+ dev->echolastupdate = 0;
-+ dev->echotimer = 0;
-+ bchdev_echocancel_setstate(dev, ECHO_STATE_IDLE);
-+
-+ if (dev->ecdis_rd) kfree(dev->ecdis_rd);
-+ dev->ecdis_rd = NULL;
-+
-+ if (dev->ecdis_wr) kfree(dev->ecdis_wr);
-+ dev->ecdis_wr = NULL;
-+}
-+
-+/** Processes one TX- and one RX-packet with echocancellation */
-+void bchdev_echocancel_chunk(dsp_t* dev, uint8_t *rxchunk, uint8_t *txchunk, uint16_t size)
-+{
-+ int16_t rxlin, txlin;
-+ uint16_t pos;
-+
-+ /* Perform echo cancellation on a chunk if requested */
-+ if (dev->ec) {
-+ if (dev->echostate & __ECHO_STATE_MUTE) {
-+ if (dev->echostate == ECHO_STATE_STARTTRAINING) {
-+ // Transmit impulse now
-+ txchunk[0] = linear2alaw(16384);
-+ memset(txchunk+1, 0, size-1);
-+ bchdev_echocancel_setstate(dev, ECHO_STATE_TRAINING); //AWAITINGECHO);
-+ } else {
-+ // train the echo cancellation
-+ for (pos = 0; pos < size; pos++) {
-+ rxlin = alaw2linear(rxchunk[pos]);
-+ txlin = alaw2linear(txchunk[pos]);
-+ if (dev->echostate == ECHO_STATE_PRETRAINING) {
-+ if (dev->echotimer <= 0) {
-+ dev->echotimer = 0;
-+ bchdev_echocancel_setstate(dev, ECHO_STATE_STARTTRAINING);
-+ } else {
-+ dev->echotimer--;
-+ }
-+ }
-+ if ((dev->echostate == ECHO_STATE_AWAITINGECHO) && (txlin > 8000)) {
-+ dev->echolastupdate = 0;
-+ bchdev_echocancel_setstate(dev, ECHO_STATE_TRAINING);
-+ }
-+ if (dev->echostate == ECHO_STATE_TRAINING) {
-+ if (echo_can_traintap(dev->ec, dev->echolastupdate++, rxlin)) {
-+ bchdev_echocancel_setstate(dev, ECHO_STATE_ACTIVE);
-+ }
-+ }
-+
-+ rxchunk[pos] = linear2alaw(0);
-+ txchunk[pos] = linear2alaw(0);
-+ }
-+ }
-+ } else {
-+ for (pos = 0; pos < size; pos++) {
-+ rxlin = alaw2linear(rxchunk[pos]);
-+ txlin = alaw2linear(txchunk[pos]);
-+
-+ if (echo_can_disable_detector_update(dev->ecdis_rd, rxlin) ||
-+ echo_can_disable_detector_update(dev->ecdis_wr, txlin)) {
-+ bchdev_echocancel_deactivate(dev);
-+ printk("EC: Fax detected, EC disabled\n");
-+ return ;
-+ } else {
-+ rxlin = echo_can_update(dev->ec, txlin, rxlin);
-+ rxchunk[pos] = linear2alaw(rxlin);
-+ }
-+ }
-+ }
-+ }
-+}
-+
-+/******************************************************/
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/dsp_core.c mISDN/drivers/isdn/hardware/mISDN/dsp_core.c
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/dsp_core.c 2005-01-29 17:15:21.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/dsp_core.c 2005-12-02 09:57:08.000000000 +0100
-@@ -42,17 +42,11 @@
- * v |
- * +-----+-------------+-----+
- * |(3)(4) |
-- * | |
-- * | |
- * | CMX |
- * | |
-- * | |
-- * | |
-- * | |
- * | +-------------+
- * | | ^
- * | | |
-- * | | |
- * |+---------+| +----+----+
- * ||(1) || |(5) |
- * || || | |
-@@ -62,7 +56,6 @@
- * |+----+----+| +----+----+
- * +-----+-----+ ^
- * | |
-- * | |
- * v |
- * +----+----+ +----+----+
- * |(5) | |(2) |
-@@ -74,8 +67,18 @@
- * | ^
- * | |
- * v |
-+ * +----+-------------+----+
-+ * |(7) |
-+ * | |
-+ * | Echo Cancellation |
-+ * | |
-+ * | |
-+ * +----+-------------+----+
-+ * | ^
-+ * | |
-+ * v |
- * +----+----+ +----+----+
-- * |(7) | |(7) |
-+ * |(8) | |(8) |
- * | | | |
- * | Encrypt | | Decrypt |
- * | | | |
-@@ -115,6 +118,13 @@
- * data to/form upper layer may be swithed on/off individually without loosing
- * features of CMX, Tones and DTMF.
- *
-+ * Echo Cancellation: Sometimes we like to cancel echo from the interface.
-+ * Note that a VoIP call may not have echo caused by the IP phone. The echo
-+ * is generated by the telephone line connected to it. Because the delay
-+ * is high, it becomes an echo. RESULT: Echo Cachelation is required if
-+ * both echo AND delay is applied to an interface.
-+ * Remember that software CMX always generates a more or less delay.
-+ *
- * If all used features can be realized in hardware, and if transmit and/or
- * receive data ist disabled, the card may not send/receive any data at all.
- * Not receiving is usefull if only announcements are played. Not sending is
-@@ -215,6 +225,9 @@
- printk(KERN_ERR "%s: failed to create tx packet\n", __FUNCTION__);
- return;
- }
-+ /* if echo cancellation is enabled */
-+ if (dsp->cancel_enable)
-+ dsp_cancel_tx(dsp, nskb->data, nskb->len);
- /* crypt if enabled */
- if (dsp->bf_enable)
- dsp_bf_encrypt(dsp, nskb->data, nskb->len);
-@@ -380,6 +393,34 @@
- if (dsp_debug & DEBUG_DSP_CMX)
- dsp_cmx_debug(dsp);
- break;
-+ case ECHOCAN_ON: /* turn echo calcellation on */
-+
-+ if (len<4) {
-+ ret = -EINVAL;
-+ break;
-+ }
-+ int ec_arr[2];
-+
-+ memcpy(&ec_arr,data,sizeof(ec_arr));
-+
-+
-+ printk("data[0]: %d data[1]: %d, len :%d\n",ec_arr[0],
-+ ec_arr[1] ,len);
-+
-+ if (dsp_debug & DEBUG_DSP_CORE)
-+ printk(KERN_DEBUG "%s: turn echo cancelation on (delay=%d attenuation-shift=%d\n", __FUNCTION__, ec_arr[0], ec_arr[1]);
-+
-+ ret = dsp_cancel_init(dsp, ec_arr[0], ec_arr[1] ,1);
-+
-+ dsp_cmx_hardware(dsp->conf, dsp);
-+ break;
-+ case ECHOCAN_OFF: /* turn echo calcellation off */
-+ if (dsp_debug & DEBUG_DSP_CORE)
-+ printk(KERN_DEBUG "%s: turn echo cancelation off\n", __FUNCTION__);
-+
-+ ret = dsp_cancel_init(dsp, 0,0,-1);
-+ dsp_cmx_hardware(dsp->conf, dsp);
-+ break;
- case BF_ENABLE_KEY: /* turn blowfish on */
- if (len<4 || len>56) {
- ret = -EINVAL;
-@@ -522,6 +563,9 @@
- /* decrypt if enabled */
- if (dsp->bf_enable)
- dsp_bf_decrypt(dsp, skb->data, skb->len);
-+ /* if echo cancellation is enabled */
-+ if (dsp->cancel_enable)
-+ dsp_cancel_rx(dsp, skb->data, skb->len);
- /* check if dtmf soft decoding is turned on */
- if (dsp->dtmf.software) {
- digits = dsp_dtmf_goertzel_decode(dsp, skb->data, skb->len, (dsp_options&DSP_OPT_ULAW)?1:0);
-@@ -919,6 +963,9 @@
- dsp_audio_generate_ulaw_samples();
- dsp_audio_generate_volume_changes();
-
-+
-+ dsp_cancel_init_flip_bits();
-+
- /* init global lock */
- lock_HW_init(&dsp_lock);
-
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/dsp.h mISDN/drivers/isdn/hardware/mISDN/dsp.h
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/dsp.h 2005-01-29 17:15:31.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/dsp.h 2005-12-02 09:57:08.000000000 +0100
-@@ -40,6 +40,13 @@
- #include "memdbg.h"
- #endif
-
-+#include "ecdis.h"
-+#include "mec2.h"
-+
-+//#include "mec.h"
-+//#include "mec3.h"
-+
-+
- extern int dsp_options;
- extern int dsp_debug;
-
-@@ -109,6 +116,8 @@
-
- #define DSP_DTMF_NPOINTS 102
-
-+#define ECHOCAN_BUFLEN 4*128
-+
- typedef struct _dtmf_t {
- int software; /* dtmf uses software decoding */
- int hardware; /* dtmf uses hardware decoding */
-@@ -120,6 +129,13 @@
- } dtmf_t;
-
-
-+/**************
-+ *Cancel Stuff*
-+ ***************/
-+
-+void dsp_cancel_init_flip_bits(void);
-+
-+
- /***************
- * tones stuff *
- ***************/
-@@ -200,6 +216,25 @@
- u8 bf_crypt_inring[16];
- u8 bf_data_out[9];
- int bf_sync;
-+
-+ /* echo cancellation stuff */
-+ int cancel_enable;
-+ echo_can_state_t* ec; /**< == NULL: echo cancellation disabled;
-+ != NULL: echo cancellation enabled */
-+
-+ echo_can_disable_detector_state_t* ecdis_rd;
-+ echo_can_disable_detector_state_t* ecdis_wr;
-+
-+ uint16_t echotimer;
-+ uint16_t echostate;
-+ uint16_t echolastupdate;
-+
-+ char txbuf[ECHOCAN_BUFLEN];
-+ int txbuflen;
-+
-+ char rxbuf[ECHOCAN_BUFLEN];
-+ int rxbuflen;
-+
- } dsp_t;
-
- /* functions */
-@@ -228,4 +263,8 @@
- extern int dsp_bf_init(dsp_t *dsp, const u8 *key, unsigned int keylen);
- extern void dsp_bf_cleanup(dsp_t *dsp);
-
-+extern void dsp_cancel_tx(dsp_t *dsp, u8 *data, int len);
-+extern void dsp_cancel_rx(dsp_t *dsp, u8 *data, int len);
-+extern int dsp_cancel_init(dsp_t *dsp, int taps, int training, int delay);
-+
-
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/ec.c mISDN/drivers/isdn/hardware/mISDN/ec.c
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/ec.c 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/ec.c 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,105 @@
-+#include "mec2.h"
-+#include "ec.h"
-+
-+
-+
-+#define __ECHO_STATE_MUTE (1 << 8)
-+#define ECHO_STATE_IDLE (0)
-+#define ECHO_STATE_PRETRAINING (1 | (__ECHO_STATE_MUTE))
-+#define ECHO_STATE_STARTTRAINING (2 | (__ECHO_STATE_MUTE))
-+#define ECHO_STATE_AWAITINGECHO (3 | (__ECHO_STATE_MUTE))
-+#define ECHO_STATE_TRAINING (4 | (__ECHO_STATE_MUTE))
-+#define ECHO_STATE_ACTIVE (5)
-+
-+#define AMI_MASK 0x55
-+
-+static unsigned char linear2alaw (short 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 short int alaw2linear (uint8_t 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);
-+}
-+
-+
-+void ec_chunk(struct echo_can_s *echo_can, unsigned char *rxchunk, const unsigned char *txchunk, int chunk_size)
-+{
-+ short rxlin, txlin;
-+ int x;
-+ //unsigned long flags;
-+ /* Perform echo cancellation on a chunk if necessary */
-+ if (echo_can->ec) {
-+ if (echo_can->echostate & __ECHO_STATE_MUTE) {
-+ /* Special stuff for training the echo can */
-+ for (x=0;x< chunk_size;x++) {
-+ rxlin = alaw2linear(rxchunk[x]);
-+ txlin = alaw2linear(txchunk[x]);
-+ if (echo_can->echostate == ECHO_STATE_PRETRAINING) {
-+ if (--echo_can->echotimer <= 0) {
-+ echo_can->echotimer = 0;
-+ echo_can->echostate = ECHO_STATE_STARTTRAINING;
-+ }
-+ }
-+ if ((echo_can->echostate == ECHO_STATE_AWAITINGECHO) && (txlin > 8000)) {
-+ echo_can->echolastupdate = 0;
-+ echo_can->echostate = ECHO_STATE_TRAINING;
-+ }
-+ if (echo_can->echostate == ECHO_STATE_TRAINING) {
-+ if (echo_can_traintap(echo_can->ec, echo_can->echolastupdate++, rxlin)) {
-+#if 0
-+ printf("Finished training (%d taps trained)!\n", echo_can->echolastupdate);
-+#endif
-+ echo_can->echostate = ECHO_STATE_ACTIVE;
-+ }
-+ }
-+ rxlin = 0;
-+ rxchunk[x] = linear2alaw((int)rxlin);
-+ }
-+ } else {
-+ for (x=0;x<chunk_size;x++) {
-+ rxlin = alaw2linear(rxchunk[x]);
-+ rxlin = echo_can_update(echo_can->ec, alaw2linear(txchunk[x]), rxlin);
-+ rxchunk[x] = linear2alaw((int)rxlin);
-+ }
-+ }
-+ }
-+}
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/ecdis.h mISDN/drivers/isdn/hardware/mISDN/ecdis.h
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/ecdis.h 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/ecdis.h 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,118 @@
-+/*
-+ * SpanDSP - a series of DSP components for telephony
-+ *
-+ * ec_disable_detector.h - A detector which should eventually meet the
-+ * G.164/G.165 requirements for detecting the
-+ * 2100Hz echo cancellor disable tone.
-+ *
-+ * Written by Steve Underwood <steveu@coppice.org>
-+ *
-+ * Copyright (C) 2001 Steve Underwood
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#include "biquad.h"
-+
-+typedef struct
-+{
-+ biquad2_state_t notch;
-+ int notch_level;
-+ int channel_level;
-+ int tone_present;
-+ int tone_cycle_duration;
-+ int good_cycles;
-+ int hit;
-+} echo_can_disable_detector_state_t;
-+
-+
-+#define FALSE 0
-+#define TRUE (!FALSE)
-+
-+static inline void echo_can_disable_detector_init (echo_can_disable_detector_state_t *det)
-+{
-+ /* Elliptic notch */
-+ /* This is actually centred at 2095Hz, but gets the balance we want, due
-+ to the asymmetric walls of the notch */
-+ biquad2_init (&det->notch,
-+ (int32_t) (-0.7600000*32768.0),
-+ (int32_t) (-0.1183852*32768.0),
-+ (int32_t) (-0.5104039*32768.0),
-+ (int32_t) ( 0.1567596*32768.0),
-+ (int32_t) ( 1.0000000*32768.0));
-+
-+ det->channel_level = 0;
-+ det->notch_level = 0;
-+ det->tone_present = FALSE;
-+ det->tone_cycle_duration = 0;
-+ det->good_cycles = 0;
-+ det->hit = 0;
-+}
-+/*- End of function --------------------------------------------------------*/
-+
-+static inline int echo_can_disable_detector_update (echo_can_disable_detector_state_t *det,
-+ int16_t amp)
-+{
-+ int16_t notched;
-+
-+ notched = biquad2 (&det->notch, amp);
-+ /* Estimate the overall energy in the channel, and the energy in
-+ the notch (i.e. overall channel energy - tone energy => noise).
-+ Use abs instead of multiply for speed (is it really faster?).
-+ Damp the overall energy a little more for a stable result.
-+ Damp the notch energy a little less, so we don't damp out the
-+ blip every time the phase reverses */
-+ det->channel_level += ((abs(amp) - det->channel_level) >> 5);
-+ det->notch_level += ((abs(notched) - det->notch_level) >> 4);
-+ if (det->channel_level > 280)
-+ {
-+ /* There is adequate energy in the channel. Is it mostly at 2100Hz? */
-+ if (det->notch_level*6 < det->channel_level)
-+ {
-+ /* The notch says yes, so we have the tone. */
-+ if (!det->tone_present)
-+ {
-+ /* Do we get a kick every 450+-25ms? */
-+ if (det->tone_cycle_duration >= 425*8
-+ &&
-+ det->tone_cycle_duration <= 475*8)
-+ {
-+ det->good_cycles++;
-+ if (det->good_cycles > 2)
-+ det->hit = TRUE;
-+ }
-+ det->tone_cycle_duration = 0;
-+ }
-+ det->tone_present = TRUE;
-+ }
-+ else
-+ {
-+ det->tone_present = FALSE;
-+ }
-+ det->tone_cycle_duration++;
-+ }
-+ else
-+ {
-+ det->tone_present = FALSE;
-+ det->tone_cycle_duration = 0;
-+ det->good_cycles = 0;
-+ }
-+ return det->hit;
-+}
-+/*- End of function --------------------------------------------------------*/
-+/*- End of file ------------------------------------------------------------*/
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/ec.h mISDN/drivers/isdn/hardware/mISDN/ec.h
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/ec.h 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/ec.h 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,12 @@
-+
-+
-+
-+struct echo_can_s {
-+ int echostate;
-+ int echotimer;
-+ int echolastupdate;
-+ echo_can_state_t *ec;
-+};
-+
-+
-+
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/hfc_multi.c mISDN/drivers/isdn/hardware/mISDN/hfc_multi.c
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/hfc_multi.c 2005-01-31 18:24:03.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/hfc_multi.c 2005-12-02 09:57:08.000000000 +0100
-@@ -136,7 +136,7 @@
- static int nt_t1_count[] = { 480, 240, 120, 60, 30, 15, 8, 4 };
- #define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
- #define CLKDEL_NT 0x0c /* CLKDEL in NT mode (0x60 MUST not be included!) */
--static u_char silence = 0xff; /* silence by LAW */
-+static u_char mysilence = 0xff; /* silence by LAW */
-
- /* enable 32 bit fifo access (PC usage) */
- #define FIFO_32BIT_ACCESS
-@@ -903,11 +903,11 @@
- bch->tx_idx = bch->tx_len = 0;
- }
- /* now we have no more data, so in case of transparent,
-- * we set the last byte in fifo to 'silence' in case we will get
-+ * we set the last byte in fifo to 'mysilence' in case we will get
- * no more data at all. this prevents sending an undefined value.
- */
- if (!hdlc)
-- HFC_outb_(hc, A_FIFO_DATA0_NOINC, silence);
-+ HFC_outb_(hc, A_FIFO_DATA0_NOINC, mysilence);
- }
-
-
-@@ -1551,7 +1551,7 @@
- HFC_outb(hc, A_IRQ_MSK, 0);
- HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
- HFC_wait(hc);
-- HFC_outb_(hc, A_FIFO_DATA0_NOINC, silence); /* tx silence */
-+ HFC_outb_(hc, A_FIFO_DATA0_NOINC, mysilence); /* tx silence */
- /* enable RX fifo */
- HFC_outb(hc, R_FIFO, (ch<<1)|1);
- HFC_wait(hc);
-@@ -1692,7 +1692,7 @@
-
- /* if off */
- if (len <= 0) {
-- HFC_outb_(hc, A_FIFO_DATA0_NOINC, silence);
-+ HFC_outb_(hc, A_FIFO_DATA0_NOINC, mysilence);
- if (hc->chan[ch].slot_tx>=0) {
- if (debug & DEBUG_HFCMULTI_MODE)
- printk(KERN_DEBUG "%s: connecting PCM due to no more TONE: channel %d slot_tx %d\n", __FUNCTION__, ch, hc->chan[ch].slot_tx);
-@@ -2183,7 +2183,7 @@
- ret = 0;
- break;
-
-- /* set silence */
-+ /* set mysilence */
- case HW_SPL_LOOP_OFF:
- if (debug & DEBUG_HFCMULTI_MSG)
- printk(KERN_DEBUG "%s: HW_SPL_LOOP_OFF\n", __FUNCTION__);
-@@ -2799,7 +2799,13 @@
- if (debug & DEBUG_HFCMULTI_INIT)
- printk(KERN_DEBUG "setup_pci(): investigating card entry %d (looking for type %d)\n", i, hc->type);
- inuse:
-+
-+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
-+ tmp_dev = pci_get_subsys(id_list[i].vendor_id, id_list[i].device_id, id_list[i].vendor_sub, id_list[i].device_sub, tmp_dev);
-+#else
- tmp_dev = pci_find_subsys(id_list[i].vendor_id, id_list[i].device_id, id_list[i].vendor_sub, id_list[i].device_sub, tmp_dev);
-+#endif
-+
- if (tmp_dev) {
- /* skip if already in use */
- list_for_each_entry_safe(hc_tmp, next, &HFCM_obj.ilist, list) {
-@@ -3318,9 +3324,9 @@
- hc->type = type[HFC_cnt] & 0xff;
- if (type[HFC_cnt] & 0x100) {
- test_and_set_bit(HFC_CHIP_ULAW, &hc->chip);
-- silence = 0xff; /* ulaw silence */
-+ mysilence = 0xff; /* ulaw silence */
- } else
-- silence = 0x2a; /* alaw silence */
-+ mysilence = 0x2a; /* alaw silence */
- if (type[HFC_cnt] & 0x200)
- test_and_set_bit(HFC_CHIP_DTMF, &hc->chip);
- // if ((type[HFC_cnt]&0x400) && hc->type==4)
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/l3_udss1.c mISDN/drivers/isdn/hardware/mISDN/l3_udss1.c
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/l3_udss1.c 2005-03-26 11:21:39.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/l3_udss1.c 2005-12-02 09:57:08.000000000 +0100
-@@ -1202,6 +1202,14 @@
- err = check_infoelements(pc, skb, ie_PROGRESS);
- if (err)
- l3dss1_std_ie_err(pc, err);
-+ /* START: patch by steinwej - http://www.beronet.com/bugs/bug_view_page.php?bug_id=0000095 */
-+ /* clear T310 if running */
-+ L3DelTimer(&pc->timer);
-+ if (pc->t303skb) {
-+ dev_kfree_skb(pc->t303skb);
-+ pc->t303skb = NULL;
-+ }
-+ /* END */
- if (ERR_IE_COMPREHENSION != err) {
- if (mISDN_l3up(pc, CC_PROGRESS | INDICATION, skb))
- dev_kfree_skb(skb);
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/Makefile mISDN/drivers/isdn/hardware/mISDN/Makefile
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/Makefile 2005-06-05 14:44:10.000000000 +0200
-+++ mISDN/drivers/isdn/hardware/mISDN/Makefile 2005-12-05 19:03:11.000000000 +0100
-@@ -30,6 +30,7 @@
-
- ifdef CONFIG_MISDN_SPEEDFAX
- obj-$(CONFIG_MISDN_DRV) += sedlfax.o
-+obj-$(CONFIG_MISDN_DRV) += faxl3.o
- endif
-
- ifdef CONFIG_MISDN_W6692
-@@ -70,8 +71,6 @@
- asn1_basic_service.o asn1_address.o asn1_enc.o capi_enc.o \
- supp_serv.o
- mISDN_dtmf-objs := dtmf.o
--mISDN_dsp-objs := dsp_core.o dsp_cmx.o dsp_tones.o dsp_dtmf.o dsp_audio.o dsp_blowfish.o
-+mISDN_dsp-objs := dsp_core.o dsp_cmx.o dsp_tones.o dsp_dtmf.o dsp_audio.o dsp_blowfish.o dsp_cancel.o
- mISDN_x25dte-objs := x25_dte.o x25_l3.o
- I4LmISDN-objs := i4l_mISDN.o
--
--include Rules.mISDN
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/Makefile.v2.6 mISDN/drivers/isdn/hardware/mISDN/Makefile.v2.6
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/Makefile.v2.6 2005-06-05 14:44:10.000000000 +0200
-+++ mISDN/drivers/isdn/hardware/mISDN/Makefile.v2.6 2005-12-02 09:57:08.000000000 +0100
-@@ -71,6 +71,6 @@
- asn1_basic_service.o asn1_address.o asn1_enc.o capi_enc.o \
- supp_serv.o
- mISDN_dtmf-objs := dtmf.o
--mISDN_dsp-objs := dsp_core.o dsp_cmx.o dsp_tones.o dsp_dtmf.o dsp_audio.o dsp_blowfish.o
-+mISDN_dsp-objs := dsp_core.o dsp_cmx.o dsp_tones.o dsp_dtmf.o dsp_audio.o dsp_blowfish.o dsp_cancel.o
- mISDN_x25dte-objs := x25_dte.o x25_l3.o
- I4LmISDN-objs := i4l_mISDN.o
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/mec2_const.h mISDN/drivers/isdn/hardware/mISDN/mec2_const.h
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/mec2_const.h 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/mec2_const.h 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,25 @@
-+/*
-+ Important constants for tuning mec2 echo can
-+ */
-+#ifndef _MEC2_CONST_H
-+#define _MEC2_CONST_H
-+
-+
-+/* Convergence speed -- higher means slower */
-+#define DEFAULT_BETA1_I 2048
-+#define DEFAULT_SIGMA_LY_I 7
-+#define DEFAULT_SIGMA_LU_I 7
-+#define DEFAULT_ALPHA_ST_I 5
-+#define DEFAULT_ALPHA_YT_I 5
-+#define DEFAULT_CUTOFF_I 128
-+#define DEFAULT_HANGT 600
-+#define DEFAULT_SUPPR_I 16
-+#define MIN_UPDATE_THRESH_I 4096
-+#define DEFAULT_M 16
-+#define SUPPR_FLOOR -64
-+#define SUPPR_CEIL -24
-+#define RES_SUPR_FACTOR -20
-+#define AGGRESSIVE_HCNTR 160 /* 20ms */
-+
-+#endif /* _MEC2_CONST_H */
-+
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/mec2.h mISDN/drivers/isdn/hardware/mISDN/mec2.h
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/mec2.h 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/mec2.h 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,409 @@
-+/*
-+ * Mark's Second Echo Canceller
-+ *
-+ * Copyright (C) 2002, Digium, Inc.
-+ *
-+ * This program is free software and may be used and
-+ * distributed according to the terms of the GNU
-+ * General Public License, incorporated herein by
-+ * reference.
-+ *
-+ */
-+#ifndef _MARK2_ECHO_H
-+#define _MARK2_ECHO_H
-+
-+#ifdef __KERNEL__
-+#include <linux/kernel.h>
-+#include <linux/slab.h>
-+#define MALLOC(a) kmalloc((a), GFP_KERNEL)
-+#define FREE(a) kfree(a)
-+#else
-+#include <stdlib.h>
-+#include <unistd.h>
-+#include <stdint.h>
-+#include <string.h>
-+#include <math.h>
-+#define MALLOC(a) malloc(a)
-+#define FREE(a) free(a)
-+#endif
-+
-+/* Get optimized routines for math */
-+#include "arith.h"
-+
-+#ifndef NULL
-+#define NULL 0
-+#endif
-+#ifndef FALSE
-+#define FALSE 0
-+#endif
-+#ifndef TRUE
-+#define TRUE (!FALSE)
-+#endif
-+
-+#include "mec2_const.h"
-+
-+/* Circular buffer definition */
-+typedef struct {
-+ int idx_d;
-+ int size_d;
-+ short *buf_d; /* Twice as large as we need */
-+} echo_can_cb_s;
-+
-+// class definition
-+//
-+typedef struct {
-+ /* Echo canceller definition */
-+
-+ /* absolute time */
-+ int i_d;
-+
-+ /* pre-computed constants */
-+
-+ int N_d;
-+ int beta2_i;
-+
-+ // declare accumulators for power computations
-+ //
-+ int Ly_i;
-+ int Lu_i;
-+
-+ // declare an accumulator for the near-end signal detector
-+ //
-+ int s_tilde_i;
-+ int HCNTR_d;
-+
-+ // circular buffers and coefficients
-+ //
-+ int *a_i;
-+ short *a_s;
-+ echo_can_cb_s y_s;
-+ echo_can_cb_s s_s;
-+ echo_can_cb_s u_s;
-+ echo_can_cb_s y_tilde_s;
-+ int y_tilde_i;
-+
-+ /* Max memory */
-+ short max_y_tilde;
-+ int max_y_tilde_pos;
-+
-+} echo_can_state_t;
-+
-+static inline void init_cb_s(echo_can_cb_s *cb, int len, void *where)
-+{
-+ cb->buf_d = (short *)where;
-+ cb->idx_d = 0;
-+ cb->size_d = len;
-+}
-+
-+static inline void add_cc_s(echo_can_cb_s *cb, short newval)
-+{
-+ /* Can't use modulus because N+M isn't a power of two (generally) */
-+ cb->idx_d--;
-+ if (cb->idx_d < (int)0)
-+ {cb->idx_d += cb->size_d;}
-+ /* Load two copies into memory */
-+ cb->buf_d[cb->idx_d] = newval;
-+ cb->buf_d[cb->idx_d + cb->size_d] = newval;
-+}
-+
-+static inline short get_cc_s(echo_can_cb_s *cb, int pos)
-+{
-+ /* Load two copies into memory */
-+ return cb->buf_d[cb->idx_d + pos];
-+}
-+
-+static inline void init_cc(echo_can_state_t *ec, int N, int maxy, int maxu) {
-+
-+ void *ptr = ec;
-+ unsigned long tmp;
-+ /* double-word align past end of state */
-+ ptr += sizeof(echo_can_state_t);
-+ tmp = (unsigned long)ptr;
-+ tmp += 3;
-+ tmp &= ~3L;
-+ ptr = (void *)tmp;
-+
-+ // reset parameters
-+ //
-+ ec->N_d = N;
-+ ec->beta2_i = DEFAULT_BETA1_I;
-+
-+ // allocate coefficient memory
-+ //
-+ ec->a_i = ptr;
-+ ptr += (sizeof(int) * ec->N_d);
-+ ec->a_s = ptr;
-+ ptr += (sizeof(short) * ec->N_d);
-+
-+ /* Reset Y circular buffer (short version) */
-+ init_cb_s(&ec->y_s, maxy, ptr);
-+ ptr += (sizeof(short) * (maxy) * 2);
-+
-+ /* Reset Sig circular buffer (short version for FIR filter) */
-+ init_cb_s(&ec->s_s, (1 << DEFAULT_ALPHA_ST_I), ptr);
-+ ptr += (sizeof(short) * (1 << DEFAULT_ALPHA_ST_I) * 2);
-+
-+ init_cb_s(&ec->u_s, maxu, ptr);
-+ ptr += (sizeof(short) * maxu * 2);
-+
-+ // allocate a buffer for the reference signal power computation
-+ //
-+ init_cb_s(&ec->y_tilde_s, ec->N_d, ptr);
-+
-+
-+ // reset absolute time
-+ //
-+ ec->i_d = (int)0;
-+
-+ // reset the power computations (for y and u)
-+ //
-+ ec->Ly_i = DEFAULT_CUTOFF_I;
-+ ec->Lu_i = DEFAULT_CUTOFF_I;
-+
-+ // reset the near-end speech detector
-+ //
-+ ec->s_tilde_i = 0;
-+ ec->HCNTR_d = (int)0;
-+
-+ // exit gracefully
-+ //
-+}
-+
-+static inline void echo_can_free(echo_can_state_t *ec)
-+{
-+ FREE(ec);
-+}
-+
-+static inline short echo_can_update(echo_can_state_t *ec, short iref, short isig) {
-+
-+ /* declare local variables that are used more than once
-+ */
-+ int k;
-+ int rs;
-+ short u;
-+ int Py_i;
-+ int two_beta_i;
-+
-+ /***************************************************************************
-+ //
-+ // flow A on pg. 428
-+ //
-+ ***************************************************************************/
-+
-+ /* eq. (16): high-pass filter the input to generate the next value;
-+ // push the current value into the circular buffer
-+ //
-+ // sdc_im1_d = sdc_d;
-+ // sdc_d = sig;
-+ // s_i_d = sdc_d;
-+ // s_d = s_i_d;
-+ // s_i_d = (float)(1.0 - gamma_d) * s_i_d
-+ + (float)(0.5 * (1.0 - gamma_d)) * (sdc_d - sdc_im1_d); */
-+
-+
-+ /* Delete last sample from power estimate */
-+ ec->y_tilde_i -= abs(get_cc_s(&ec->y_s, (1 << DEFAULT_ALPHA_YT_I) - 1 )) >> DEFAULT_ALPHA_YT_I;
-+ /* push the reference data onto the circular buffer */
-+ add_cc_s(&ec->y_s, iref);
-+
-+ /* eq. (2): compute r in fixed-point */
-+ rs = CONVOLVE2(ec->a_s, ec->y_s.buf_d + ec->y_s.idx_d, ec->N_d);
-+ rs >>= 15;
-+
-+ /* eq. (3): compute the output value (see figure 3) and the error
-+ // note: the error is the same as the output signal when near-end
-+ // speech is not present
-+ */
-+ u = isig - rs;
-+
-+ add_cc_s(&ec->u_s, u);
-+
-+
-+
-+ /* Delete oldest part of received s_tilde */
-+ ec->s_tilde_i -= abs(get_cc_s(&ec->s_s, (1 << DEFAULT_ALPHA_ST_I) - 1 ));
-+
-+ /* push the signal on the circular buffer, too */
-+ add_cc_s(&ec->s_s, isig);
-+ ec->s_tilde_i += abs(isig);
-+ ec->y_tilde_i += abs(iref) >> DEFAULT_ALPHA_YT_I;
-+
-+ /* Add to our list of recent y_tilde's */
-+ add_cc_s(&ec->y_tilde_s, ec->y_tilde_i);
-+
-+ /****************************************************************************
-+ //
-+ // flow B on pg. 428
-+ //
-+ ****************************************************************************/
-+
-+ /* compute the new convergence factor
-+ */
-+ Py_i = (ec->Ly_i >> DEFAULT_SIGMA_LY_I) * (ec->Ly_i >> DEFAULT_SIGMA_LY_I);
-+ Py_i >>= 15;
-+ if (ec->HCNTR_d > 0) {
-+ Py_i = (1 << 15);
-+ }
-+
-+#if 0
-+ printf("Py: %e, Py_i: %e\n", Py, Py_i * AMPL_SCALE_1);
-+#endif
-+
-+ /* Vary rate of adaptation depending on position in the file
-+ // Do not do this for the first (DEFAULT_UPDATE_TIME) secs after speech
-+ // has begun of the file to allow the echo cancellor to estimate the
-+ // channel accurately
-+ */
-+#if 0
-+ if (ec->start_speech_d != 0 ){
-+ if ( ec->i_d > (DEFAULT_T0 + ec->start_speech_d)*(SAMPLE_FREQ) ){
-+ ec->beta2_d = max_cc_float(MIN_BETA,
-+ DEFAULT_BETA1 * exp((-1/DEFAULT_TAU)*((ec->i_d/(float)SAMPLE_FREQ) -
-+ DEFAULT_T0 -
-+ ec->start_speech_d)));
-+ }
-+ }
-+ else {ec->beta2_d = DEFAULT_BETA1;}
-+#endif
-+
-+ ec->beta2_i = DEFAULT_BETA1_I; /* Fixed point, inverted */
-+
-+ two_beta_i = (ec->beta2_i * Py_i) >> 15; /* Fixed point version, inverted */
-+ if (!two_beta_i)
-+ two_beta_i++;
-+
-+ /* Update Lu_i (Suppressed power estimate) */
-+ ec->Lu_i -= abs(get_cc_s(&ec->u_s, (1 << DEFAULT_SIGMA_LU_I) - 1 )) ;
-+ ec->Lu_i += abs(u);
-+
-+ /* eq. (10): update power estimate of the reference
-+ */
-+ ec->Ly_i -= abs(get_cc_s(&ec->y_s, (1 << DEFAULT_SIGMA_LY_I) - 1)) ;
-+ ec->Ly_i += abs(iref);
-+
-+ if (ec->Ly_i < DEFAULT_CUTOFF_I)
-+ ec->Ly_i = DEFAULT_CUTOFF_I;
-+
-+#if 0
-+ printf("Float: %e, Int: %e\n", ec->Ly_d, (ec->Ly_i >> DEFAULT_SIGMA_LY_I) * AMPL_SCALE_1);
-+#endif
-+
-+ if (ec->y_tilde_i > ec->max_y_tilde) {
-+ /* New highest y_tilde with full life */
-+ ec->max_y_tilde = ec->y_tilde_i;
-+ ec->max_y_tilde_pos = ec->N_d - 1;
-+ } else if (--ec->max_y_tilde_pos < 0) {
-+ /* Time to find new max y tilde... */
-+ ec->max_y_tilde = MAX16(ec->y_tilde_s.buf_d + ec->y_tilde_s.idx_d, ec->N_d, &ec->max_y_tilde_pos);
-+ }
-+
-+ if ((ec->s_tilde_i >> (DEFAULT_ALPHA_ST_I - 1)) > ec->max_y_tilde)
-+ {
-+ ec->HCNTR_d = DEFAULT_HANGT;
-+ }
-+ else if (ec->HCNTR_d > (int)0)
-+ {
-+ ec->HCNTR_d--;
-+ }
-+
-+ /* update coefficients if no near-end speech and we have enough signal
-+ * to bother trying to update.
-+ */
-+ if (!ec->HCNTR_d && !(ec->i_d % DEFAULT_M) &&
-+ (ec->Lu_i > MIN_UPDATE_THRESH_I)) {
-+ // loop over all filter coefficients
-+ //
-+ for (k=0; k<ec->N_d; k++) {
-+
-+ // eq. (7): compute an expectation over M_d samples
-+ //
-+ int grad2;
-+ grad2 = CONVOLVE2(ec->u_s.buf_d + ec->u_s.idx_d,
-+ ec->y_s.buf_d + ec->y_s.idx_d + k, DEFAULT_M);
-+ // eq. (7): update the coefficient
-+ //
-+ ec->a_i[k] += grad2 / two_beta_i;
-+ ec->a_s[k] = ec->a_i[k] >> 16;
-+ }
-+ }
-+
-+ /* paragraph below eq. (15): if no near-end speech,
-+ // check for residual error suppression
-+ */
-+#ifndef NO_ECHO_SUPPRESSOR
-+#ifdef AGGRESSIVE_SUPPRESSOR
-+ if ((ec->HCNTR_d < AGGRESSIVE_HCNTR) && (ec->Ly_i > (ec->Lu_i << 1))) {
-+ u = u * (ec->Lu_i >> DEFAULT_SIGMA_LU_I) / ((ec->Ly_i >> (DEFAULT_SIGMA_LY_I)) + 1);
-+ u = u * (ec->Lu_i >> DEFAULT_SIGMA_LU_I) / ((ec->Ly_i >> (DEFAULT_SIGMA_LY_I)) + 1);
-+ }
-+#else
-+ if ((ec->HCNTR_d == 0) && ((ec->Ly_i/(ec->Lu_i + 1)) > DEFAULT_SUPPR_I)) {
-+ u = u * (ec->Lu_i >> DEFAULT_SIGMA_LU_I) / ((ec->Ly_i >> (DEFAULT_SIGMA_LY_I + 2)) + 1);
-+ }
-+#endif
-+#endif
-+
-+#if 0
-+ if ((ec->HCNTR_d == 0) && ((ec->Lu_d/ec->Ly_d) < DEFAULT_SUPPR) &&
-+ (ec->Lu_d/ec->Ly_d > EC_MIN_DB_VALUE)) {
-+ suppr_factor = (10/(float)(SUPPR_FLOOR-SUPPR_CEIL))*log(ec->Lu_d/ec->Ly_d)
-+ - SUPPR_CEIL/(float)(SUPPR_FLOOR - SUPPR_CEIL);
-+
-+ u_suppr = pow(10.0,(suppr_factor)*RES_SUPR_FACTOR/10.0)*u_suppr;
-+
-+ }
-+#endif
-+ ec->i_d++;
-+ return u;
-+}
-+
-+static inline echo_can_state_t *echo_can_create(int len, int adaption_mode)
-+{
-+ echo_can_state_t *ec;
-+ int maxy;
-+ int maxu;
-+ maxy = len + DEFAULT_M;
-+ maxu = DEFAULT_M;
-+ if (maxy < (1 << DEFAULT_ALPHA_YT_I))
-+ maxy = (1 << DEFAULT_ALPHA_YT_I);
-+ if (maxy < (1 << DEFAULT_SIGMA_LY_I))
-+ maxy = (1 << DEFAULT_SIGMA_LY_I);
-+ if (maxu < (1 << DEFAULT_SIGMA_LU_I))
-+ maxu = (1 << DEFAULT_SIGMA_LU_I);
-+ ec = (echo_can_state_t *)MALLOC(sizeof(echo_can_state_t) +
-+ 4 + /* align */
-+ sizeof(int) * len + /* a_i */
-+ sizeof(short) * len + /* a_s */
-+ 2 * sizeof(short) * (maxy) + /* y_s */
-+ 2 * sizeof(short) * (1 << DEFAULT_ALPHA_ST_I) + /* s_s */
-+ 2 * sizeof(short) * (maxu) + /* u_s */
-+ 2 * sizeof(short) * len); /* y_tilde_s */
-+ if (ec) {
-+ memset(ec, 0, sizeof(echo_can_state_t) +
-+ 4 + /* align */
-+ sizeof(int) * len + /* a_i */
-+ sizeof(short) * len + /* a_s */
-+ 2 * sizeof(short) * (maxy) + /* y_s */
-+ 2 * sizeof(short) * (1 << DEFAULT_ALPHA_ST_I) + /* s_s */
-+ 2 * sizeof(short) * (maxu) + /* u_s */
-+ 2 * sizeof(short) * len); /* y_tilde_s */
-+ init_cc(ec, len, maxy, maxu);
-+ }
-+ return ec;
-+}
-+
-+static inline int echo_can_traintap(echo_can_state_t *ec, int pos, short val)
-+{
-+ /* Reset hang counter to avoid adjustments after
-+ initial forced training */
-+ ec->HCNTR_d = ec->N_d << 1;
-+ if (pos >= ec->N_d)
-+ return 1;
-+ ec->a_i[pos] = val << 17;
-+ ec->a_s[pos] = val << 1;
-+ if (++pos >= ec->N_d)
-+ return 1;
-+ return 0;
-+}
-+
-+#endif
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/mec3.h mISDN/drivers/isdn/hardware/mISDN/mec3.h
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/mec3.h 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/mec3.h 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,243 @@
-+/*
-+ * Mark's Third Echo Canceller
-+ *
-+ * Copyright (C) 2003, Digium, Inc.
-+ *
-+ * This program is free software and may be used
-+ * and distributed under the terms of the GNU General Public
-+ * License, incorporated herein by reference.
-+ *
-+ * Dedicated to the crew of the Columbia, STS-107 for their
-+ * bravery and courageous sacrifice for science.
-+ *
-+ */
-+
-+#ifndef _MARK3_ECHO_H
-+#define _MARK3_ECHO_H
-+
-+
-+
-+#ifdef __KERNEL__
-+#include <linux/kernel.h>
-+#include <linux/slab.h>
-+#define MALLOC(a) kmalloc((a), GFP_KERNEL)
-+#define FREE(a) kfree(a)
-+#else
-+#include <stdlib.h>
-+#include <unistd.h>
-+#include <stdint.h>
-+#include <string.h>
-+#include <math.h>
-+#define MALLOC(a) malloc(a)
-+#define FREE(a) free(a)
-+#endif
-+
-+/* Features */
-+
-+/*
-+ * DO_BACKUP -- Backup coefficients, and revert in the presense of double talk to try to prevent
-+ * them from diverging during the ramp-up before the DTD kicks in
-+ */
-+/* #define DO_BACKUP */
-+
-+#define STEP_SHIFT 2 /* Convergence rate higher = slower / better (as a shift) */
-+
-+#define SIGMA_REF_PWR 655 /* Keep denominator from being 0 */
-+
-+#define MIN_TX_ENERGY 256 /* Must have at least this much reference */
-+#define MIN_RX_ENERGY 32 /* Must have at least this much receive energy */
-+
-+#define MAX_ATTENUATION_SHIFT 6 /* Maximum amount of loss we care about */
-+#define MAX_BETA 1024
-+
-+#define SUPPR_SHIFT 4 /* Amount of loss at which we suppress audio */
-+
-+#define HANG_TIME 600 /* Hangover time */
-+
-+#define NTAPS 2048 /* Maximum number of echo can taps */
-+
-+#define BACKUP 256 /* Backup every this number of samples */
-+
-+#define POWER_OFFSET 5 /* Shift power by this amount to be sure we don't overflow the
-+ reference power. Higher = less likely to overflow, lower = more accurage */
-+
-+#include "arith.h"
-+
-+typedef struct {
-+ short buf[NTAPS * 2];
-+ short max;
-+ int maxexp;
-+} cbuf_s;
-+
-+typedef struct {
-+ short a_s[NTAPS]; /* Coefficients in shorts */
-+ int a_i[NTAPS]; /* Coefficients in ints*/
-+#ifdef DO_BACKUP
-+ int b_i[NTAPS]; /* Coefficients (backup1) */
-+ int c_i[NTAPS]; /* Coefficients (backup2) */
-+#endif
-+ cbuf_s ref; /* Reference excitation */
-+ cbuf_s sig; /* Signal (echo + near end + noise) */
-+ cbuf_s e; /* Error */
-+ int refpwr; /* Reference power */
-+ int taps; /* Number of taps */
-+ int tappwr; /* Power of taps */
-+ int hcntr; /* Hangtime counter */
-+ int pos; /* Position in curcular buffers */
-+ int backup; /* Backup timer */
-+} echo_can_state_t;
-+
-+static inline void echo_can_free(echo_can_state_t *ec)
-+{
-+ FREE(ec);
-+}
-+
-+static inline void buf_add(cbuf_s *b, short sample, int pos, int taps)
-+{
-+ /* Store and keep track of maxima */
-+ int x;
-+ b->buf[pos] = sample;
-+ b->buf[pos + taps] = sample;
-+ if (sample > b->max) {
-+ b->max = sample;
-+ b->maxexp = taps;
-+ } else {
-+ b->maxexp--;
-+ if (!b->maxexp) {
-+ b->max = 0;
-+ for (x=0;x<taps;x++)
-+ if (b->max < abs(b->buf[pos + x])) {
-+ b->max = abs(b->buf[pos + x]);
-+ b->maxexp = x + 1;
-+ }
-+ }
-+ }
-+}
-+
-+static inline short echo_can_update(echo_can_state_t *ec, short ref, short sig)
-+{
-+ int x;
-+ short u;
-+ int refpwr;
-+ int beta; /* Factor */
-+ int se; /* Simulated echo */
-+#ifdef DO_BACKUP
-+ if (!ec->backup) {
-+ /* Backup coefficients periodically */
-+ ec->backup = BACKUP;
-+ memcpy(ec->c_i,ec->b_i,sizeof(ec->c_i));
-+ memcpy(ec->b_i,ec->a_i,sizeof(ec->b_i));
-+ } else
-+ ec->backup--;
-+#endif
-+ /* Remove old samples from reference power calculation */
-+ ec->refpwr -= ((ec->ref.buf[ec->pos] * ec->ref.buf[ec->pos]) >> POWER_OFFSET);
-+
-+ /* Store signal and reference */
-+ buf_add(&ec->ref, ref, ec->pos, ec->taps);
-+ buf_add(&ec->sig, sig, ec->pos, ec->taps);
-+
-+ /* Add new reference power */
-+ ec->refpwr += ((ec->ref.buf[ec->pos] * ec->ref.buf[ec->pos]) >> POWER_OFFSET);
-+
-+
-+ /* Calculate simulated echo */
-+ se = CONVOLVE2(ec->a_s, ec->ref.buf + ec->pos, ec->taps);
-+ se >>= 15;
-+
-+ u = sig - se;
-+ if (ec->hcntr)
-+ ec->hcntr--;
-+
-+ /* Store error */
-+ buf_add(&ec->e, sig, ec->pos, ec->taps);
-+ if ((ec->ref.max > MIN_TX_ENERGY) &&
-+ (ec->sig.max > MIN_RX_ENERGY) &&
-+ (ec->e.max > (ec->ref.max >> MAX_ATTENUATION_SHIFT))) {
-+ /* We have sufficient energy */
-+ if (ec->sig.max < (ec->ref.max >> 1)) {
-+ /* No double talk */
-+ if (!ec->hcntr) {
-+ refpwr = ec->refpwr >> (16 - POWER_OFFSET);
-+ if (refpwr < SIGMA_REF_PWR)
-+ refpwr = SIGMA_REF_PWR;
-+ beta = (u << 16) / refpwr;
-+ beta >>= STEP_SHIFT;
-+ if (beta > MAX_BETA)
-+ beta = 0;
-+ if (beta < -MAX_BETA)
-+ beta = 0;
-+ /* Update coefficients */
-+ for (x=0;x<ec->taps;x++) {
-+ ec->a_i[x] += beta * ec->ref.buf[ec->pos + x];
-+ ec->a_s[x] = ec->a_i[x] >> 16;
-+ }
-+ }
-+ } else {
-+#ifdef DO_BACKUP
-+ if (!ec->hcntr) {
-+ /* Our double talk detector is turning on for the first time. Revert
-+ our coefficients, since we're probably well into the double talk by now */
-+ memcpy(ec->a_i, ec->c_i, sizeof(ec->a_i));
-+ for (x=0;x<ec->taps;x++) {
-+ ec->a_s[x] = ec->a_i[x] >> 16;
-+ }
-+ }
-+#endif
-+ /* Reset hang-time counter, and prevent backups */
-+ ec->hcntr = HANG_TIME;
-+#ifdef DO_BACKUP
-+ ec->backup = BACKUP;
-+#endif
-+ }
-+ }
-+#ifndef NO_ECHO__SUPPRESSOR
-+ if (ec->e.max < (ec->ref.max >> SUPPR_SHIFT)) {
-+ /* Suppress residual echo */
-+ u *= u;
-+ u >>= 16;
-+ }
-+#endif
-+ ec->pos--;
-+ if (ec->pos < 0)
-+ ec->pos = ec->taps-1;
-+ return u;
-+}
-+
-+static inline echo_can_state_t *echo_can_create(int taps, int adaption_mode)
-+{
-+ echo_can_state_t *ec;
-+ int x;
-+
-+ //taps = NTAPS;
-+ ec = MALLOC(sizeof(echo_can_state_t));
-+ if (ec) {
-+ memset(ec, 0, sizeof(echo_can_state_t));
-+ ec->taps = taps;
-+ ec->pos = ec->taps-1;
-+ for (x=0;x<31;x++) {
-+ if ((1 << x) >= ec->taps) {
-+ ec->tappwr = x;
-+ break;
-+ }
-+ }
-+ }
-+ return ec;
-+}
-+
-+static inline int echo_can_traintap(echo_can_state_t *ec, int pos, short val)
-+{
-+ /* Reset hang counter to avoid adjustments after
-+ initial forced training */
-+ ec->hcntr = ec->taps << 1;
-+ if (pos >= ec->taps)
-+ return 1;
-+ ec->a_i[pos] = val << 17;
-+ ec->a_s[pos] = val << 1;
-+ if (++pos >= ec->taps)
-+ return 1;
-+ return 0;
-+}
-+
-+
-+#endif
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/mec.h mISDN/drivers/isdn/hardware/mISDN/mec.h
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/mec.h 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/drivers/isdn/hardware/mISDN/mec.h 2005-12-02 09:57:08.000000000 +0100
-@@ -0,0 +1,308 @@
-+/*
-+ * Mark's Echo Canceller
-+ *
-+ * Mark Spencer <markster@linux-support.net>
-+ *
-+ * Simple, LMS Echo Canceller with double talk detection.
-+ * Partly based on the TI App note:
-+ * "Digital Voice Echo Canceller with a TMS 32020"
-+ *
-+ * Special additional thanks to:
-+ * Jim Dixon (Lambda Telecommunications)
-+ * Iman Ghobrial (Adtran, Inc.)
-+ *
-+ * Copyright (C) 2001, Linux Support Services, Inc.
-+ *
-+ * This program is free software and may be used and
-+ * distributed according to the terms of the GNU
-+ * General Public License, incorporated herein by
-+ * reference.
-+ *
-+ */
-+
-+#ifndef _MEC_H
-+#define _MEC_H
-+
-+/* You have to express the size of the echo canceller in taps as
-+ a power of 2 (6 = 64 taps, 7 = 128 taps, 8 = 256 taps) */
-+#define NUM_TAPS_POW2 6 /* Size of echo canceller in power of 2 (taps) */
-+#define NUM_TAPS (1 << NUM_TAPS_POW2) /* Actual number of taps */
-+#define TAP_MASK (NUM_TAPS-1)
-+
-+
-+#define SIGMA_LU_POW NUM_TAPS_POW2
-+#define SIGMA_LY_POW NUM_TAPS_POW2
-+#define SIGMA_YT_POW (NUM_TAPS_POW2 - 1)
-+#define SIGMA_ST_POW (NUM_TAPS_POW2 - 1)
-+
-+#define BETA_POW 8
-+
-+#define CUTOFF_S 4
-+
-+/* The higher you make this, the better the quality, but the more CPU time required */
-+#define MIN_QUALITY 100
-+
-+/* This optimization saves a lot of processor but may degrade quality */
-+#define OPTIMIZEDIV
-+
-+#if 0
-+/* This converges much more slowly but saves processor */
-+#define MIN_UPDATE 256
-+#define MIN_SKIP 8
-+#endif
-+
-+#define HANG_T 600 /* 600 samples, or 75ms */
-+
-+typedef struct mark_ec {
-+ /* Circular position */
-+ int cpos;
-+ short y[NUM_TAPS]; /* Last N samples (relative to cpos) transmitted */
-+ short y_abs[NUM_TAPS]; /* Last N samples (relative to cpos) transmitted (abs value) */
-+ short s[NUM_TAPS]; /* Last N samples (relative to cpos) received */
-+ short s_abs[NUM_TAPS]; /* Last N samples (relative to cpos) received (abs value) */
-+ short u[NUM_TAPS]; /* Last N samples (relative to cpos) with echo removed */
-+ short u_abs[NUM_TAPS]; /* Last N samples (relative to cpos) with echo removed */
-+
-+ int Ly; /* tx power */
-+ int Lu; /* Power of echo-cancelled output */
-+
-+ int Ty[NUM_TAPS]; /* Short term power estimate of transmit */
-+ int Ts; /* Short term power estimate of received signal */
-+
-+ int a[NUM_TAPS]; /* Tap weight coefficients (not relative) */
-+
-+ short sdc[NUM_TAPS]; /* Near end signal before High Pass Filter */
-+
-+ int samples; /* Sample count */
-+ int pass; /* Number of passes we've made */
-+
-+ int hangt;
-+
-+ int lastmax; /* Optimize maximum search */
-+ int maxTy; /* Maximum Ty */
-+} echo_can_state_t;
-+
-+#define INLINE inline
-+
-+#ifdef __KERNEL__
-+#include <linux/kernel.h>
-+#include <linux/slab.h>
-+#define MALLOC(a) kmalloc((a), GFP_KERNEL)
-+#define FREE(a) kfree((a))
-+#else
-+#include <stdlib.h>
-+#include <unistd.h>
-+#include <stdint.h>
-+#include <string.h>
-+#define MALLOC(a) malloc(a)
-+#define FREE(a) free(a)
-+#endif
-+
-+static INLINE echo_can_state_t *echo_can_create(int len, int adaption_mode)
-+{
-+ echo_can_state_t *ec;
-+ /* Uhm, we're only one length, sorry. */
-+ ec = MALLOC(sizeof(echo_can_state_t));
-+ if (ec)
-+ memset(ec, 0, sizeof(*ec));
-+ return ec;
-+}
-+
-+#define PASSPOS 32000
-+#undef PASSPOS
-+
-+static INLINE void echo_can_free(echo_can_state_t *ec)
-+{
-+ FREE(ec);
-+}
-+
-+static INLINE int16_t echo_can_update(echo_can_state_t *ec, int16_t tx, int16_t rx)
-+{
-+ /* Process a sample, where tx is the near end and rx is the far end + echo */
-+
-+ int suppr;
-+ int nsuppr;
-+ short rxabs, txabs;
-+ register int Lu;
-+ register int x;
-+ register int pos;
-+ register int r_hat; /* Estimated echo */
-+ int oldrxabs;
-+ int oldtxabs;
-+ int oldsupprabs;
-+ int supprabs;
-+#ifdef MIN_UPDATE
-+ int totalupd;
-+#endif
-+
-+ txabs = abs(tx);
-+ rxabs = abs(rx);
-+
-+ ec->pass++;
-+
-+ r_hat = 0;
-+
-+ /* Load next value */
-+ ec->y[ec->cpos] = tx;
-+
-+ /* Load next abs value */
-+ oldtxabs = ec->y_abs[ec->cpos];
-+ ec->y_abs[ec->cpos] = txabs;
-+
-+ /* Bring in receive value (near-end signal) */
-+ ec->sdc[ec->cpos] = rx;
-+
-+ /* Bring in receive value absolute value */
-+ oldrxabs = ec->s_abs[ec->cpos];
-+ ec->s_abs[ec->cpos] = rxabs;
-+
-+ Lu = ec->Lu | 1;
-+
-+#if 0
-+ /* Apply first order high pass filter (3 dB @ 160 Hz) */
-+ tx = ec->s[ec->cpos] = (1.0-DEFGAMMA) * ec->s[(ec->cpos - 1) & TAP_MASK] +
-+ 0.5 * (1.0-DEFGAMMA) * ( ec->sdc[(ec->cpos - 1) & TAP_MASK] - ec->sdc[(ec->cpos - 2) & TAP_MASK]);
-+#endif
-+
-+ /* Estimate echo */
-+ pos = ec->cpos;
-+ for (x=0;x<NUM_TAPS;x++) {
-+ r_hat += ec->a[x] * ec->y[pos];
-+ /* Go backwards in time and loop around circular buffer */
-+ pos = (pos - 1) & TAP_MASK;
-+ }
-+
-+ r_hat >>= 16;
-+
-+ if (ec->hangt > 0)
-+ ec->hangt--;
-+
-+ /* printf("rx: %F, rhat: %F\n", rx, r_hat); */
-+ /* Calculate suppressed amount */
-+ suppr = rx - r_hat;
-+
-+ if (ec->pass > NUM_TAPS) {
-+ /* Have to have enough taps to start with */
-+ if (ec->maxTy > ec->Ts) {
-+ /* There is no near-end speech detected */
-+ if (!ec->hangt) {
-+ /* We're not in the hang-time from the end of near-end speech */
-+ if ((ec->Ly > 1024) && ((ec->Ly / Lu) < MIN_QUALITY)) {
-+#ifdef OPTIMIZEDIV
-+ /* We both have enough signal on the transmit */
-+ nsuppr = (suppr << 18) / ec->Ly;
-+
-+ if (nsuppr > 32767)
-+ nsuppr = 32767;
-+ if (nsuppr < -32768)
-+ nsuppr = -32768;
-+
-+ nsuppr /= ec->Ly;
-+#else
-+ /* We both have enough signal on the transmit */
-+ nsuppr = (suppr << 16) / ec->Ly;
-+
-+ if (nsuppr > 32767)
-+ nsuppr = 32767;
-+ if (nsuppr < -32768)
-+ nsuppr = -32768;
-+
-+#endif
-+
-+ /* Update coefficients */
-+ pos = ec->cpos;
-+#ifdef MIN_UPDATE
-+ totalupd =0;
-+#endif
-+ for (x=0;x<NUM_TAPS;x++) {
-+ register int adj;
-+ adj = ec->y[pos] * nsuppr;
-+#ifndef OPTIMIZEDIV
-+ adj /= ec->Ly;
-+ adj >>= BETA_POW;
-+#else
-+ adj >>= BETA_POW + 2;
-+#endif
-+#ifdef PASSPOS
-+ if (ec->pass > PASSPOS)
-+ printf("tx: %d, old %d: %d, adj %d, nsuppr: %d, power: %d\n", tx, x, ec->a[x], adj, nsuppr, ec->Ly);
-+#endif
-+ ec->a[x] += adj;
-+#ifdef MIN_UPDATE
-+ totalupd += abs(adj);
-+#endif
-+ /* Go backwards in time and loop around circular buffer */
-+ pos = (pos - 1) & TAP_MASK;
-+ }
-+#ifdef MIN_UPDATE
-+ /* If we didn't update at least this much, delay for many more taps */
-+ if (totalupd < MIN_UPDATE) {
-+ ec->hangt += MIN_SKIP;
-+ }
-+#endif
-+ }
-+
-+ }
-+ } else
-+ /* Near end speech detected */
-+ ec->hangt = HANG_T;
-+ }
-+
-+ /* Save supression and absolute values */
-+ supprabs = abs(suppr);
-+ oldsupprabs = ec->u_abs[ec->cpos];
-+ ec->u[ec->cpos] = suppr;
-+ ec->u_abs[ec->cpos] = supprabs;
-+
-+ /* Update tx power */
-+ ec->Ly += (txabs >> SIGMA_LY_POW) - (oldtxabs >> SIGMA_LY_POW);
-+
-+ /* Update rx power */
-+ ec->Lu += (supprabs >> SIGMA_LU_POW) - (oldsupprabs >> SIGMA_LU_POW);
-+
-+ /* Short term power of tx */
-+ ec->Ty[ec->cpos] = ec->Ty[(ec->cpos - 1) & TAP_MASK] +
-+ ((txabs >> SIGMA_YT_POW ) - (oldtxabs >> SIGMA_YT_POW));
-+
-+ /* Keep track of highest */
-+ if (ec->lastmax == ec->cpos) {
-+ register int maxTy = 0;
-+ /* Have to loop through and find the new highest since our old highest expired */
-+ /* Estimate echo */
-+ pos = ec->cpos;
-+ for (x=0;x<NUM_TAPS;x++) {
-+ if (ec->Ty[pos] > maxTy)
-+ maxTy = ec->Ty[pos];
-+ /* Go backwards in time and loop around circular buffer */
-+ pos = (pos - 1) & TAP_MASK;
-+ }
-+ ec->maxTy = maxTy;
-+ } else {
-+ /* Just keep the highest */
-+ if (ec->Ty[ec->cpos] > ec->maxTy) {
-+ ec->maxTy = ec->Ty[ec->cpos];
-+ ec->lastmax = ec->cpos;
-+ }
-+ }
-+ ec->Ts += (rxabs >> SIGMA_ST_POW) - (oldrxabs >> SIGMA_ST_POW) ;
-+
-+ /* Increment position memory */
-+ ec->cpos = (ec->cpos + 1 ) & TAP_MASK;
-+
-+ return suppr;
-+}
-+
-+static inline int echo_can_traintap(echo_can_state_t *ec, int pos, short val)
-+{
-+ /* Reset hang counter to avoid adjustments after
-+ initial forced training */
-+ ec->hangt = NUM_TAPS << 1;
-+ if (pos >= NUM_TAPS)
-+ return 1;
-+ ec->a[pos] = val << 17;
-+ if (++pos >= NUM_TAPS)
-+ return 1;
-+ return 0;
-+}
-+
-+#endif
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/sedl_fax.c mISDN/drivers/isdn/hardware/mISDN/sedl_fax.c
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/sedl_fax.c 2004-08-27 21:27:40.000000000 +0200
-+++ mISDN/drivers/isdn/hardware/mISDN/sedl_fax.c 2005-12-02 09:57:08.000000000 +0100
-@@ -811,8 +811,8 @@
- return(err);
- }
-
-- printk(KERN_INFO "mISDN: sedlpci found adapter %s at %s\n",
-- (char *) ent->driver_data, pdev->slot_name);
-+/* printk(KERN_INFO "mISDN: sedlpci found adapter %s at %s\n",
-+ (char *) ent->driver_data, pdev->slot_name); */
-
- card->cfg = pci_resource_start(pdev, 0);
- card->irq = pdev->irq;
-diff -u -r -P /tmp/mISDN/drivers/isdn/hardware/mISDN/w6692.c mISDN/drivers/isdn/hardware/mISDN/w6692.c
---- /tmp/mISDN/drivers/isdn/hardware/mISDN/w6692.c 2004-08-27 21:27:40.000000000 +0200
-+++ mISDN/drivers/isdn/hardware/mISDN/w6692.c 2005-12-02 09:57:08.000000000 +0100
-@@ -1502,8 +1502,8 @@
- return(err);
- }
-
-- printk(KERN_INFO "mISDN_w6692: found adapter %s at %s\n",
-- (char *) ent->driver_data, pdev->slot_name);
-+/* printk(KERN_INFO "mISDN_w6692: found adapter %s at %s\n",
-+ (char *) ent->driver_data, pdev->slot_name); */
-
- card->addr = pci_resource_start(pdev, 1);
- card->irq = pdev->irq;
-diff -u -r -P /tmp/mISDN/include/linux/mISDNif.h mISDN/include/linux/mISDNif.h
---- /tmp/mISDN/include/linux/mISDNif.h 2005-02-05 11:18:17.000000000 +0100
-+++ mISDN/include/linux/mISDNif.h 2005-12-02 09:57:08.000000000 +0100
-@@ -173,6 +173,8 @@
- #define BF_DISABLE 0x2315
- #define BF_ACCEPT 0x2316
- #define BF_REJECT 0x2317
-+#define ECHOCAN_ON 0x2318
-+#define ECHOCAN_OFF 0x2319
- #define HW_POTS_ON 0x1001
- #define HW_POTS_OFF 0x1002
- #define HW_POTS_SETMICVOL 0x1100
-diff -u -r -P /tmp/mISDN/Makefile mISDN/Makefile
---- /tmp/mISDN/Makefile 1970-01-01 01:00:00.000000000 +0100
-+++ mISDN/Makefile 2005-12-05 19:08:57.000000000 +0100
-@@ -0,0 +1,54 @@
-+BASEDIR=$(shell pwd)
-+
-+
-+INSTALL_PREFIX := /
-+export INSTALL_PREFIX
-+
-+#PATH to linux source/headers
-+#LINUX=/usr/src/linux
-+LINUX=/lib/modules/$(shell uname -r)/build
-+
-+MISDNDIR=$(BASEDIR)
-+MISDN_SRC=$(MISDNDIR)/drivers/isdn/hardware/mISDN
-+
-+########################################
-+# USER CONFIGS END
-+########################################
-+
-+CONFIGS+=CONFIG_MISDN_DRV=m CONFIG_MISDN_DSP=m
-+CONFIGS+=CONFIG_MISDN_HFCMULTI=m
-+CONFIGS+=CONFIG_MISDN_HFCPCI=m
-+CONFIGS+=CONFIG_MISDN_HFCUSB=m
-+#CONFIGS+=CONFIG_MISDN_AVM_FRITZ=m
-+
-+
-+MINCLUDES+=-I$(MISDNDIR)/include
-+
-+all:
-+ @echo
-+ @echo "Makeing mISDN"
-+ @echo "============="
-+ @echo
-+ cp $(MISDNDIR)/drivers/isdn/hardware/mISDN/Makefile.v2.6 $(MISDNDIR)/drivers/isdn/hardware/mISDN/Makefile
-+
-+ cd $(LINUX) ; make SUBDIRS=$(MISDN_SRC) modules $(CONFIGS) LINUXINCLUDE="$(MINCLUDES) -I$(LINUX)/include"
-+
-+
-+
-+install: all
-+ cd $(LINUX) ; make SUBDIRS=$(MISDN_SRC) modules_install
-+ cp $(MISDNDIR)/include/linux/*.h $(INSTALL_PREFIX)/usr/include/linux/
-+ depmod
-+
-+.PHONY: install all clean
-+
-+clean:
-+ rm -rf drivers/isdn/hardware/mISDN/*.o
-+ rm -rf drivers/isdn/hardware/mISDN/*.ko
-+ rm -rf *~
-+ find . -iname ".*.cmd" -exec rm -rf {} \;
-+ find . -iname ".*.d" -exec rm -rf {} \;
-+ find . -iname "*.mod.c" -exec rm -rf {} \;
-+ find . -iname "*.mod" -exec rm -rf {} \;
-+
-+
diff --git a/1.2-netsec/channels/misdn/mISDNuser.patch b/1.2-netsec/channels/misdn/mISDNuser.patch
deleted file mode 100644
index a5a70acc8..000000000
--- a/1.2-netsec/channels/misdn/mISDNuser.patch
+++ /dev/null
@@ -1,271 +0,0 @@
-diff -u -r -P /tmp/mISDNuser/example/Makefile mISDNuser/example/Makefile
---- /tmp/mISDNuser/example/Makefile 2004-08-28 14:31:02.000000000 +0200
-+++ mISDNuser/example/Makefile 2005-12-05 18:57:10.000000000 +0100
-@@ -3,6 +3,11 @@
-
- all: $(PROGS)
-
-+install:
-+ for i in $(PROGS) ; do \
-+ install -m 755 $$i $(INSTALL_PREFIX)/usr/bin ;\
-+ done
-+
- testcon: testcon.o $(mISDNLIB)
-
- testnet: testnet.o $(mISDNLIB)
-@@ -26,7 +31,7 @@
-
-
- clean:
-- rm -f *.o *~ DEADJOE
-+ rm -f *.o *.so *~ DEADJOE
- rm -f loadfirm logger testcon testcon_l2 testnet
-
- distclean: clean
-diff -u -r -P /tmp/mISDNuser/i4lnet/Makefile mISDNuser/i4lnet/Makefile
---- /tmp/mISDNuser/i4lnet/Makefile 2004-08-28 14:27:53.000000000 +0200
-+++ mISDNuser/i4lnet/Makefile 2005-12-05 18:57:40.000000000 +0100
-@@ -1,9 +1,18 @@
-
--all: libisdnnet.a
-+all: libisdnnet.a libisdnnet.so
-+
-+install:
-+ install -m 644 libisdnnet.so $(INSTALL_PREFIX)/usr/lib/
-+ cp *.h $(INSTALL_PREFIX)/usr/include/mISDNuser/
-+
-
- ISDNNETOBJ = net_if.o isdn_debug.o isdn_msg.o fsm.o net_l2.o tei.o net_l3.o \
- manager.o tone.o bchannel.o g711.o
-
-+libisdnnet.so: $(ISDNNETOBJ)
-+ rm -f $@
-+ $(CC) -shared -Xlinker -x -o $@ $(ISDNNETOBJ)
-+
- libisdnnet.a: $(ISDNNETOBJ)
- rm -f $@
- ar cr $@ $(ISDNNETOBJ)
-@@ -33,7 +42,7 @@
- g711.o: g711.c $(INCLUDEDIR)/g711.h
-
- clean:
-- rm -f *.o *~ DEADJOE
-+ rm -f *.o *.so *~ DEADJOE
- rm -f libisdnnet.a
-
- distclean: clean
-diff -u -r -P /tmp/mISDNuser/i4lnet/net_if.c mISDNuser/i4lnet/net_if.c
---- /tmp/mISDNuser/i4lnet/net_if.c 2004-12-05 18:23:40.000000000 +0100
-+++ mISDNuser/i4lnet/net_if.c 2005-11-14 09:27:58.000000000 +0100
-@@ -1,7 +1,7 @@
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
--#include <asm/bitops.h>
-+#include "net_l2.h"
- #include "isdn_net.h"
- #include "bchannel.h"
- #include "helper.h"
-diff -u -r -P /tmp/mISDNuser/i4lnet/net_l2.c mISDNuser/i4lnet/net_l2.c
---- /tmp/mISDNuser/i4lnet/net_l2.c 2004-12-05 23:22:15.000000000 +0100
-+++ mISDNuser/i4lnet/net_l2.c 2005-11-14 09:27:58.000000000 +0100
-@@ -32,18 +32,6 @@
-
- #define L2_STATE_COUNT (ST_L2_8+1)
-
--static char *strL2State[] =
--{
-- "ST_L2_1",
-- "ST_L2_2",
-- "ST_L2_3",
-- "ST_L2_4",
-- "ST_L2_5",
-- "ST_L2_6",
-- "ST_L2_7",
-- "ST_L2_8",
--};
--
- enum {
- EV_L2_UI,
- EV_L2_SABME,
-diff -u -r -P /tmp/mISDNuser/i4lnet/net_l2.h mISDNuser/i4lnet/net_l2.h
---- /tmp/mISDNuser/i4lnet/net_l2.h 2004-12-05 00:47:10.000000000 +0100
-+++ mISDNuser/i4lnet/net_l2.h 2005-11-14 09:27:58.000000000 +0100
-@@ -9,7 +9,6 @@
- #ifndef NET_L2_H
- #define NET_L2_H
-
--#include <asm/bitops.h>
- #include "mISDNlib.h"
- #include "isdn_net.h"
- #include "fsm.h"
-@@ -118,4 +117,31 @@
- #define FLG_LAPD_NET 18
- #define FLG_TEI_T201_1 19
-
-+
-+/* Simple replacement for the NON-ATOMIC routines which asm/bitops.h
-+ was providing. */
-+static inline int test_bit(int bit, unsigned long *word)
-+{
-+ return !!((*word) & (1<<bit));
-+}
-+static inline int test_and_clear_bit(int bit, unsigned long *word)
-+{
-+ int ret = !!((*word) & (1<<bit));
-+ *word &= ~(1<<bit);
-+ return ret;
-+}
-+static inline int test_and_set_bit(int bit, unsigned long *word)
-+{
-+ int ret = !!((*word) & (1<<bit));
-+ *word |= 1<<bit;
-+ return ret;
-+}
-+static inline void clear_bit(int bit, unsigned long *word)
-+{
-+ *word &= ~(1<<bit);
-+}
-+static inline void set_bit(int bit, unsigned long *word)
-+{
-+ *word |= 1<<bit;
-+}
- #endif
-diff -u -r -P /tmp/mISDNuser/i4lnet/net_l3.c mISDNuser/i4lnet/net_l3.c
---- /tmp/mISDNuser/i4lnet/net_l3.c 2005-04-30 17:32:06.000000000 +0200
-+++ mISDNuser/i4lnet/net_l3.c 2005-11-14 09:27:58.000000000 +0100
-@@ -9,7 +9,6 @@
- */
-
- #include <stdlib.h>
--#include <asm/bitops.h>
- #include "mISDNlib.h"
- #include "net_l2.h"
- #include "net_l3.h"
-diff -u -r -P /tmp/mISDNuser/lib/Makefile mISDNuser/lib/Makefile
---- /tmp/mISDNuser/lib/Makefile 2004-08-28 14:28:38.000000000 +0200
-+++ mISDNuser/lib/Makefile 2005-12-05 18:57:27.000000000 +0100
-@@ -1,7 +1,18 @@
-
--all: libmISDN.a
-+all: libmISDN.a libmISDN.so
-
--libmISDN.a: device.o layer.o stack.o status.o
-+install:
-+ install -m 644 libmISDN.so $(INSTALL_PREFIX)/usr/lib/
-+
-+LIBMISDN_OBJS=device.o layer.o stack.o status.o
-+
-+libmISDN.so: $(LIBMISDN_OBJS)
-+ rm -f $@
-+ $(CC) -shared -Xlinker -x -o $@ $(LIBMISDN_OBJS)
-+
-+
-+
-+libmISDN.a: $(LIBMISDN_OBJS)
- rm -f $@
- ar -r $@ $^
- ar -s $@
-@@ -12,9 +23,8 @@
- status.o : status.c ../include/mISDNlib.h
-
- clean:
-- rm -f *.o *~ DEADJOE
-+ rm -f *.o *.so *~ DEADJOE
- rm -f libmISDN.a
-
- distclean: clean
- rm -f *.a
--
-diff -u -r -P /tmp/mISDNuser/Makefile mISDNuser/Makefile
---- /tmp/mISDNuser/Makefile 2004-08-28 14:30:55.000000000 +0200
-+++ mISDNuser/Makefile 2005-12-05 19:16:52.000000000 +0100
-@@ -1,10 +1,26 @@
-+#
-+# Set this to your local copy of mISDN
-+#
-+MISDNDIR := /usr/src/mISDN
-+
-+#
-+# Change this to create an install prefix for the shared libs, programms and
-+# includes
-+#
-+INSTALL_PREFIX := /
-+export INSTALL_PREFIX
-+
-+MISDNINCLUDEDIR := $(MISDNDIR)/include
-+export MISDNINCLUDEDIR
-+
- mISDN_DIR := $(PWD)
- export mISDN_DIR
-
- INCLUDEDIR := $(mISDN_DIR)/include
- export INCLUDEDIR
-
--CFLAGS:= -g -Wall -O2 -I $(INCLUDEDIR)
-+CFLAGS:= -g -Wall -O2 -I $(INCLUDEDIR) -I $(MISDNINCLUDEDIR)
-+CFLAGS+= -D CLOSE_REPORT=1
- export CFLAGS
-
- mISDNLIB := $(PWD)/lib/libmISDN.a
-@@ -20,9 +36,20 @@
-
- LIBS := lib/libmISDN.a
-
--all:
-+all: test_misdn_includes
- make TARGET=$@ subdirs
-
-+
-+install_path:
-+ mkdir -p $(INSTALL_PREFIX)/usr/bin/
-+ mkdir -p $(INSTALL_PREFIX)/usr/lib/mISDNuser/
-+ mkdir -p $(INSTALL_PREFIX)/usr/include/mISDNuser/
-+
-+install: install_path all
-+ make TARGET=install subdirs
-+ cp include/*.h $(INSTALL_PREFIX)/usr/include/mISDNuser/
-+
-+
- subdirs:
- set -e; for i in $(SUBDIRS) ; do $(MAKE) -C $$i $(TARGET); done
-
-@@ -61,3 +88,8 @@
- voiparchiv: ARCHIVNAME := $(ARCHIVDIR)/$(MAINDIR)_voip-$(VERSION).tar.bz2
- voiparchiv: archiv
-
-+
-+test_misdn_includes:
-+ @if ! echo "#include <linux/mISDNif.h>" | gcc -I$(MISDNINCLUDEDIR) -C -E - >/tmp/muh ; then echo -e "\n\nYou either don't seem to have installed mISDN properly\nor you haven't set the MISDNDIR variable in this very Makefile.\n\nPlease either install mISDN or set the MISDNDIR properly\n"; exit 1; fi
-+
-+
-diff -u -r -P /tmp/mISDNuser/tenovis/Makefile mISDNuser/tenovis/Makefile
---- /tmp/mISDNuser/tenovis/Makefile 2004-08-28 14:29:27.000000000 +0200
-+++ mISDNuser/tenovis/Makefile 2005-12-05 18:51:05.000000000 +0100
-@@ -10,6 +10,11 @@
-
- all: sublib $(PROGS)
-
-+install:
-+ for i in $(PROGS) ; do \
-+ install -m 755 $$i $(INSTALL_PREFIX)/usr/bin ;\
-+ done
-+
- testlib: testlib.o $(TENOVISLIB) $(mISDNLIB)
-
- tstlib: tstlib.o $(TENOVISLIB) $(mISDNLIB)
-diff -u -r -P /tmp/mISDNuser/voip/Makefile mISDNuser/voip/Makefile
---- /tmp/mISDNuser/voip/Makefile 2004-08-28 14:29:53.000000000 +0200
-+++ mISDNuser/voip/Makefile 2005-12-05 18:50:39.000000000 +0100
-@@ -24,6 +24,11 @@
-
- all: $(PROGRAMMS)
-
-+install:
-+ for i in $(PROGRAMMS) ; do \
-+ install -m 755 $$i $(INSTALL_PREFIX)/usr/bin ;\
-+ done
-+
- INTERNET_PORT = 2074
-
- CARGS = -DInternet_Port=$(INTERNET_PORT)
diff --git a/1.2-netsec/channels/misdn/portinfo.c b/1.2-netsec/channels/misdn/portinfo.c
deleted file mode 100644
index c7add95fb..000000000
--- a/1.2-netsec/channels/misdn/portinfo.c
+++ /dev/null
@@ -1,197 +0,0 @@
-
-
-#include "isdn_lib.h"
-
-
-/*
- * global function to show all available isdn ports
- */
-void isdn_port_info(void)
-{
- int err;
- int i, ii, p;
- int useable, nt, pri;
- unsigned char buff[1025];
- iframe_t *frm = (iframe_t *)buff;
- stack_info_t *stinf;
- int device;
-
- /* open mISDN */
- if ((device = mISDN_open()) < 0)
- {
- fprintf(stderr, "mISDN_open() failed: ret=%d errno=%d (%s) Check for mISDN modules and device.\n", device, errno, strerror(errno));
- exit(-1);
- }
-
- /* get number of stacks */
- i = 1;
- ii = mISDN_get_stack_count(device);
- printf("\n");
- if (ii <= 0)
- {
- printf("Found no card. Please be sure to load card drivers.\n");
- }
-
- /* loop the number of cards and get their info */
- while(i <= ii)
- {
- err = mISDN_get_stack_info(device, i, buff, sizeof(buff));
- if (err <= 0)
- {
- fprintf(stderr, "mISDN_get_stack_info() failed: port=%d err=%d\n", i, err);
- break;
- }
- stinf = (stack_info_t *)&frm->data.p;
-
- nt = pri = 0;
- useable = 1;
-
- /* output the port info */
- printf("Port %2d: ", i);
- switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK)
- {
- case ISDN_PID_L0_TE_S0:
- printf("TE-mode BRI S/T interface line (for phone lines)");
-#if 0
- if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_S0_HFC & ISDN_PID_FEATURE_MASK)
- printf(" HFC multiport card");
-#endif
- break;
- case ISDN_PID_L0_NT_S0:
- nt = 1;
- printf("NT-mode BRI S/T interface port (for phones)");
-#if 0
- if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_S0_HFC & ISDN_PID_FEATURE_MASK)
- printf(" HFC multiport card");
-#endif
- break;
- case ISDN_PID_L0_TE_U:
- printf("TE-mode BRI U interface line");
- break;
- case ISDN_PID_L0_NT_U:
- nt = 1;
- printf("NT-mode BRI U interface port");
- break;
- case ISDN_PID_L0_TE_UP2:
- printf("TE-mode BRI Up2 interface line");
- break;
- case ISDN_PID_L0_NT_UP2:
- nt = 1;
- printf("NT-mode BRI Up2 interface port");
- break;
- case ISDN_PID_L0_TE_E1:
- pri = 1;
- printf("TE-mode PRI E1 interface line (for phone lines)");
-#if 0
- if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_E1_HFC & ISDN_PID_FEATURE_MASK)
- printf(" HFC-E1 card");
-#endif
- break;
- case ISDN_PID_L0_NT_E1:
- nt = 1;
- pri = 1;
- printf("NT-mode PRI E1 interface port (for phones)");
-#if 0
- if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_E1_HFC & ISDN_PID_FEATURE_MASK)
- printf(" HFC-E1 card");
-#endif
- break;
- default:
- useable = 0;
- printf("unknown type 0x%08x",stinf->pid.protocol[0]);
- }
- printf("\n");
-
- if (nt)
- {
- if (stinf->pid.protocol[1] == 0)
- {
- useable = 0;
- printf(" -> Missing layer 1 NT-mode protocol.\n");
- }
- p = 2;
- while(p <= MAX_LAYER_NR) {
- if (stinf->pid.protocol[p])
- {
- useable = 0;
- printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for NT lib.\n", p, stinf->pid.protocol[p]);
- }
- p++;
- }
- if (useable)
- {
- if (pri)
- printf(" -> Interface is Point-To-Point (PRI).\n");
- else
- printf(" -> Interface can be Poin-To-Point/Multipoint.\n");
- }
- } else
- {
- if (stinf->pid.protocol[1] == 0)
- {
- useable = 0;
- printf(" -> Missing layer 1 protocol.\n");
- }
- if (stinf->pid.protocol[2] == 0)
- {
- useable = 0;
- printf(" -> Missing layer 2 protocol.\n");
- }
- if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP)
- {
- printf(" -> Interface is Poin-To-Point.\n");
- }
- if (stinf->pid.protocol[3] == 0)
- {
- useable = 0;
- printf(" -> Missing layer 3 protocol.\n");
- } else
- {
- printf(" -> Protocol: ");
- switch(stinf->pid.protocol[3] & ~ISDN_PID_FEATURE_MASK)
- {
- case ISDN_PID_L3_DSS1USER:
- printf("DSS1 (Euro ISDN)");
- break;
-
- default:
- useable = 0;
- printf("unknown protocol 0x%08x",stinf->pid.protocol[3]);
- }
- printf("\n");
- }
- p = 4;
- while(p <= MAX_LAYER_NR) {
- if (stinf->pid.protocol[p])
- {
- useable = 0;
- printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for TE lib.\n", p, stinf->pid.protocol[p]);
- }
- p++;
- }
- printf(" -> childcnt: %d\n",stinf->childcnt);
- }
-
- if (!useable)
- printf(" * Port NOT useable for PBX\n");
-
- printf("--------\n");
-
- i++;
- }
- printf("\n");
-
- /* close mISDN */
- if ((err = mISDN_close(device)))
- {
- fprintf(stderr, "mISDN_close() failed: err=%d '%s'\n", err, strerror(err));
- exit(-1);
- }
-}
-
-
-int main()
-{
- isdn_port_info();
- return 0;
-}
diff --git a/1.2-netsec/channels/ring10.h b/1.2-netsec/channels/ring10.h
deleted file mode 100644
index f45f8dbb9..000000000
--- a/1.2-netsec/channels/ring10.h
+++ /dev/null
@@ -1,1752 +0,0 @@
-/*! \file
- * \brief Signed 16-bit audio data
- *
- * Source: /home/markster/ring10.raw
- *
- * Copyright (C) 1999-2005, Digium, Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short ring10[] = {
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 0x82a0, 0x8dc7, 0x607e, 0xc0c6, 0x2bd3,
-0x8df5, 0x828d, 0x0716, 0xaca6, 0xcefe, 0x41df, 0xd185, 0x8aa3, 0x8b1a, 0x789b,
-0x82a2, 0x804f, 0x7ea8, 0x8113, 0x7f7d, 0x7fff, 0x801e, 0x801d, 0x7f32, 0x82ec,
-0x83e1, 0x7fb0, 0x7f71, 0x80de, 0x7f3d, 0x7fe3, 0x81b4, 0x7c37, 0x8553, 0x7b29,
-0x7ede, 0xde6e, 0x0e64, 0xf9f4, 0x015e, 0x00f6, 0xfe56, 0x0019, 0xf8bb, 0xfd90,
-0x08cc, 0x05ab, 0xfd0b, 0xf9c6, 0xf875, 0xf789, 0xfc74, 0x032e, 0xf97a, 0xf4bb,
-0x0212, 0x006e, 0x03df, 0x17c5, 0x0f50, 0xfb23, 0xfdbd, 0xf7cf, 0xdf5b, 0xe2d3,
-0xf111, 0xef27, 0x11c5, 0x33a4, 0x168d, 0x0145, 0x0494, 0xe85c, 0xdac3, 0xf0c7,
-0xeea8, 0x0023, 0x3036, 0x252a, 0xffb7, 0x01d1, 0xf637, 0xd506, 0xe8eb, 0xf5ff,
-0xe5ca, 0x1ec5, 0x3fa4, 0x0e3c, 0x1570, 0x2b37, 0xea23, 0xca43, 0xf392, 0xdf0e,
-0xde40, 0x2e7c, 0x276f, 0x035c, 0x2ccc, 0x1acf, 0xcf4a, 0xeb5b, 0x0fb1, 0xe01a,
-0x0c69, 0x3a97, 0xfb54, 0x0751, 0x20f1, 0xdce9, 0xd2a2, 0x19b3, 0x096f, 0xf1b6,
-0x38de, 0x1f70, 0xf32b, 0x2569, 0x0650, 0xc3d7, 0xf1ad, 0x1aa5, 0xe87e, 0x0c7f,
-0x406d, 0xffaa, 0x0ba8, 0x2e02, 0xe545, 0xcebb, 0x10fc, 0x0102, 0xded8, 0x2b7c,
-0x2053, 0xec6f, 0x266e, 0x1770, 0xcb63, 0xf18e, 0x2015, 0xe6ef, 0xfe64, 0x3700,
-0xf628, 0xfb00, 0x2e43, 0xee48, 0xcd4a, 0x1867, 0x0ec3, 0xdd77, 0x2291, 0x1c80,
-0xe325, 0x19b7, 0x1719, 0xcb88, 0xeded, 0x258c, 0xe7e8, 0xf0c6, 0x2d21, 0xf3d5,
-0xf494, 0x290d, 0xef7b, 0xca28, 0x12c8, 0x0d8d, 0xd5f3, 0x171d, 0x1994, 0xe0c0,
-0x1348, 0x1929, 0xcf9b, 0xe6fb, 0x20ae, 0xe921, 0xed2b, 0x2c54, 0xf96e, 0xf19f,
-0x21b6, 0xf12e, 0xc8b4, 0x0907, 0x0964, 0xd049, 0x0eb8, 0x1fa6, 0xe6b5, 0x0cec,
-0x16b6, 0xcd0c, 0xda57, 0x17c9, 0xe440, 0xe2a2, 0x2b4d, 0xffa2, 0xec7e, 0x1ee9,
-0xf674, 0xbfcb, 0xf769, 0x0402, 0xcfe8, 0x104b, 0x2734, 0xe7e9, 0x07d9, 0x19f4,
-0xd032, 0xd00b, 0x0e46, 0xe17d, 0xe2d8, 0x3456, 0x0781, 0xed01, 0x238d, 0xfa72,
-0xbb51, 0xf543, 0x050b, 0xccd5, 0x1491, 0x3358, 0xedad, 0x10c4, 0x283b, 0xd051,
-0xc9e9, 0x11f8, 0xe2cb, 0xe534, 0x43aa, 0x1090, 0xf11b, 0x3267, 0x02c3, 0xb72d,
-0xf9ac, 0x0fbd, 0xce45, 0x1d7b, 0x4389, 0xef2e, 0x1593, 0x348e, 0xd0cb, 0xca8c,
-0x1f61, 0xe981, 0xdef7, 0x4774, 0x15ae, 0xefab, 0x3b28, 0x0a9e, 0xb2f6, 0xf9e9,
-0x1976, 0xcc08, 0x15ab, 0x4534, 0xee6c, 0x159b, 0x3753, 0xcf09, 0xc69a, 0x2270,
-0xf15c, 0xdee6, 0x48ce, 0x1af4, 0xf169, 0x3da0, 0x0d68, 0xb573, 0xff9e, 0x20ba,
-0xcbfe, 0x142d, 0x4879, 0xed49, 0x1434, 0x3d96, 0xd714, 0xca99, 0x298b, 0xf708,
-0xd92c, 0x4632, 0x1acc, 0xea6e, 0x3d2c, 0x1412, 0xb534, 0xfbfa, 0x24f9, 0xcd72,
-0x0df9, 0x48f8, 0xeb87, 0x0bca, 0x3dd5, 0xd6cc, 0xc015, 0x2605, 0xfa87, 0xd1a9,
-0x40d0, 0x1c59, 0xe0de, 0x34f9, 0x14c6, 0xaf61, 0xf2a5, 0x23e6, 0xc929, 0x01be,
-0x4423, 0xe53b, 0x0182, 0x3c3a, 0xd758, 0xbb9d, 0x1fa9, 0xf454, 0xc611, 0x36e8,
-0x18f7, 0xdac9, 0x2e8a, 0x126d, 0xac14, 0xead6, 0x2215, 0xc990, 0xf9f5, 0x43cb,
-0xea01, 0xfcbf, 0x38fd, 0xd9f3, 0xb7cd, 0x1bc4, 0xfd41, 0xca56, 0x31e3, 0x1d4b,
-0xdca2, 0x2a9f, 0x1c24, 0xb8aa, 0xeb59, 0x25d5, 0xd2d0, 0xfa10, 0x44fa, 0xefe0,
-0xfced, 0x3ef4, 0xe9a1, 0xbdf0, 0x19ac, 0x0198, 0xca6f, 0x2f04, 0x25b6, 0xe187,
-0x29ba, 0x250a, 0xbe42, 0xe40e, 0x24ef, 0xd75d, 0xf476, 0x44f8, 0xf719, 0xf7a1,
-0x3c94, 0xf20e, 0xbcdf, 0x16a3, 0x07e8, 0xc8d4, 0x2a3e, 0x2b3f, 0xdf4e, 0x235d,
-0x2c92, 0xc2c7, 0xdf39, 0x2873, 0xd790, 0xea2a, 0x47fd, 0xfd0e, 0xf0e3, 0x3bd8,
-0xf4e9, 0xb265, 0x0c2c, 0x0751, 0xc302, 0x29bb, 0x37bd, 0xe138, 0x1e0c, 0x2d09,
-0xbddb, 0xd246, 0x24c4, 0xd87a, 0xe5df, 0x4ff6, 0x08d6, 0xf0d8, 0x3d61, 0xf8bf,
-0xaede, 0x0a36, 0x0df3, 0xc0f5, 0x23ec, 0x3e92, 0xe3d7, 0x1cad, 0x348e, 0xc0d6,
-0xcd4e, 0x265c, 0xd9b6, 0xdf83, 0x510e, 0x0c41, 0xeece, 0x4153, 0xfeeb, 0xa9f6,
-0x04b3, 0x12a4, 0xbf2f, 0x20d1, 0x42f4, 0xe1b1, 0x1b1e, 0x3980, 0xc2b4, 0xcb50,
-0x2b74, 0xded0, 0xd835, 0x4e7a, 0x0b46, 0xe555, 0x4015, 0x0517, 0xaa54, 0x0504,
-0x1932, 0xbc34, 0x1a77, 0x48b1, 0xe0bb, 0x149b, 0x3ba7, 0xc34a, 0xc481, 0x2bc2,
-0xe401, 0xd20e, 0x4f53, 0x1389, 0xe3b7, 0x418b, 0x0a15, 0xa70d, 0x0024, 0x1f9f,
-0xbf65, 0x142d, 0x4a81, 0xe0ca, 0x1152, 0x4325, 0xcb03, 0xc18a, 0x2b95, 0xeb45,
-0xcf92, 0x4c54, 0x18ad, 0xe08b, 0x3f12, 0x1264, 0xa9fc, 0xfd97, 0x246f, 0xbf86,
-0x0ce2, 0x4e7c, 0xe4f3, 0x0c20, 0x44e0, 0xd069, 0xbdcb, 0x2b8e, 0xf32d, 0xcad4,
-0x464f, 0x1e76, 0xdf62, 0x3b07, 0x17ea, 0xaafb, 0xf5a0, 0x2835, 0xc7c2, 0x0842,
-0x4d2b, 0xe634, 0x03ef, 0x42bc, 0xd7f2, 0xbb73, 0x2662, 0xf892, 0xc8b3, 0x3e30,
-0x1f20, 0xdcca, 0x354a, 0x1c6b, 0xaf75, 0xf0f7, 0x2963, 0xc908, 0xfdbf, 0x4c3c,
-0xebe5, 0x00e3, 0x44c4, 0xdf15, 0xb9e9, 0x243b, 0x00e9, 0xcb76, 0x3b53, 0x248e,
-0xdc27, 0x2fcb, 0x22e5, 0xb66c, 0xec96, 0x2b19, 0xd0ef, 0xf97b, 0x48ae, 0xecc0,
-0xf8b4, 0x411d, 0xe769, 0xb9f7, 0x1c41, 0x0022, 0xc369, 0x2ced, 0x23ac, 0xd8eb,
-0x2522, 0x232a, 0xb611, 0xe19f, 0x2738, 0xd013, 0xece5, 0x434c, 0xf00e, 0xefcc,
-0x3b79, 0xeb32, 0xb19c, 0x135e, 0x04ef, 0xc1b9, 0x27a8, 0x2992, 0xd7b3, 0x1ba5,
-0x2481, 0xb8c5, 0xd97d, 0x246f, 0xd113, 0xe45d, 0x4486, 0xf7f7, 0xeb36, 0x395a,
-0xf122, 0xaea5, 0x0c28, 0x05eb, 0xbde4, 0x2585, 0x36a2, 0xde67, 0x1b86, 0x2dac,
-0xbd03, 0xd2b8, 0x2624, 0xd8b8, 0xe802, 0x521b, 0x0855, 0xefbc, 0x4048, 0xfad2,
-0xafe2, 0x0fb1, 0x12b2, 0xc62c, 0x2c2a, 0x43f5, 0xe562, 0x1fcb, 0x3791, 0xc2ac,
-0xd4d1, 0x2dfd, 0xde0a, 0xe53f, 0x5578, 0x0f49, 0xf2b6, 0x4609, 0x0105, 0xabf5,
-0x09a8, 0x157e, 0xc286, 0x23e7, 0x425f, 0xe36a, 0x1d93, 0x3580, 0xbf80, 0xcaf2,
-0x2a04, 0xf16e, 0xd92b, 0x0eaa, 0xf1a7, 0x1ddb, 0x5b52, 0x0665, 0xd2e3, 0x15f8,
-0xf606, 0x9d42, 0xdba7, 0xf312, 0xd349, 0x21ed, 0x576a, 0x34e8, 0x2450, 0x2679,
-0xdc01, 0xb506, 0xcb0f, 0xa454, 0xccf3, 0x2c13, 0x1673, 0xf8ca, 0x4ff1, 0x63ac,
-0xec26, 0xd77c, 0xf1f9, 0xc268, 0xb11a, 0xdfe4, 0x02e7, 0x10f5, 0x3512, 0x19dd,
-0x0edc, 0x3568, 0xf6f7, 0xbe10, 0xda93, 0xf4fe, 0xda03, 0xe293, 0x15dd, 0x15f3,
-0x1ba5, 0x1521, 0x12e8, 0x23ab, 0x0fc3, 0xdb3e, 0xb671, 0xe960, 0xe13c, 0xc695,
-0x1a81, 0x3d23, 0x1c56, 0x190d, 0x4234, 0x1970, 0xd784, 0xd86b, 0xb5e8, 0xc9f3,
-0xeb89, 0xe344, 0x17ae, 0x5713, 0x37fc, 0xffe2, 0x36b3, 0x1dfe, 0xb963, 0xbf9c,
-0xc9a1, 0xcc7b, 0xe409, 0x08a6, 0x2077, 0x3b4d, 0x3cba, 0x0553, 0x220e, 0x226e,
-0xd219, 0xb7ec, 0xcb8b, 0xdf2a, 0xd0c7, 0xf5be, 0x2ff0, 0x42a6, 0x3c24, 0x25ae,
-0x2d6d, 0x0d94, 0xde80, 0xb78b, 0xb12b, 0xdf7a, 0xde33, 0x0046, 0x47b1, 0x5170,
-0x29c0, 0x2945, 0x3ab5, 0xf08f, 0xc806, 0xc229, 0xbbf4, 0xe40d, 0xf365, 0x0bfe,
-0x448d, 0x5cd8, 0x1e52, 0x10ba, 0x3908, 0xefa4, 0xc243, 0xcf89, 0xd02d, 0xde92,
-0xf8e0, 0x191e, 0x2f7b, 0x48e6, 0x1e38, 0x1074, 0x3785, 0xf8be, 0xbd1c, 0xc06b,
-0xdc36, 0xdb97, 0xe3c0, 0x2042, 0x37c5, 0x36ff, 0x1b73, 0x2064, 0x2c9a, 0xefa2,
-0xbf0c, 0xb7f0, 0xe221, 0xe243, 0xd998, 0x2263, 0x4bae, 0x3596, 0x18aa, 0x3763,
-0x27d0, 0xdcc6, 0xcacc, 0xc06f, 0xd83d, 0xecfe, 0xeefa, 0x1ffa, 0x5052, 0x393f,
-0x0af5, 0x3c9e, 0x316b, 0xd2df, 0xc575, 0xd3c8, 0xddd2, 0xdf98, 0xfbd7, 0x2929,
-0x4879, 0x4052, 0x160c, 0x3708, 0x2b31, 0xdac6, 0xc0c3, 0xcfc0, 0xe71d, 0xddec,
-0x0145, 0x3847, 0x457c, 0x356b, 0x214a, 0x3a5f, 0x1474, 0xd892, 0xc579, 0xc6a7,
-0xe77a, 0xe4dc, 0x00ab, 0x3b89, 0x4eba, 0x290a, 0x16ea, 0x3dc6, 0x0956, 0xcc12,
-0xc3bd, 0xc9e9, 0xe4be, 0xe60b, 0x0561, 0x3707, 0x4c82, 0x2444, 0x1406, 0x3a8e,
-0xff5b, 0xc494, 0xbf9f, 0xcb26, 0xdfef, 0xe755, 0x1060, 0x334f, 0x40e5, 0x1f87,
-0x16b9, 0x33e8, 0xfa6e, 0xc670, 0xb774, 0xcc17, 0xe18f, 0xdd0f, 0x102c, 0x3f0d,
-0x4098, 0x1b95, 0x24b2, 0x315a, 0xe9d8, 0xc459, 0xb314, 0xc524, 0xe2a6, 0xe1cf,
-0x100a, 0x44af, 0x455c, 0x1551, 0x264f, 0x2ab1, 0xd681, 0xb90c, 0xb4d6, 0xc68d,
-0xddac, 0xef74, 0x1f57, 0x4357, 0x4192, 0x0e60, 0x1bcb, 0x20fd, 0xd477, 0xb435,
-0xb3e3, 0xcdc3, 0xd9c4, 0xef97, 0x2384, 0x3b60, 0x34c9, 0x119d, 0x1f15, 0x0fb3,
-0xd15d, 0xb30d, 0xa9e3, 0xd431, 0xdc02, 0xe98a, 0x2987, 0x4204, 0x290c, 0x1181,
-0x2d0c, 0x0800, 0xcb55, 0xb8f5, 0xaaa6, 0xd49f, 0xe57c, 0xf063, 0x281c, 0x4c65,
-0x2d19, 0x0cd2, 0x2ddb, 0xfefe, 0xc171, 0xbd4c, 0xb7c2, 0xd4c5, 0xe6f3, 0x0040,
-0x2b86, 0x4b6d, 0x2ed1, 0x0ce3, 0x2d97, 0x01f9, 0xc2ad, 0xb8fc, 0xc53e, 0xe1cf,
-0xea35, 0x0eb0, 0x38b8, 0x4a3b, 0x2a1e, 0x1457, 0x2a1e, 0xfbca, 0xcdf1, 0xbc93,
-0xcc0b, 0xec27, 0xeb05, 0x144b, 0x4443, 0x496d, 0x2233, 0x2180, 0x30b2, 0xf03c,
-0xcced, 0xbf0d, 0xcc55, 0xeec3, 0xf367, 0x186f, 0x45cd, 0x4e7d, 0x215a, 0x2485,
-0x3122, 0xe7a8, 0xc40a, 0xbf85, 0xd4dd, 0xebe8, 0xf32b, 0x2121, 0x49bb, 0x4c61,
-0x1af5, 0x1f88, 0x2c32, 0xe8c5, 0xc512, 0xc0b7, 0xdbf9, 0xe9ea, 0xf2f4, 0x2584,
-0x43e2, 0x3e1b, 0x19cf, 0x28d2, 0x2442, 0xe27b, 0xc589, 0xbe8a, 0xdddc, 0xe567,
-0xed4e, 0x27f2, 0x48cd, 0x3505, 0x0e88, 0x2cd5, 0x207d, 0xda54, 0xc1cf, 0xb8c1,
-0xd925, 0xe569, 0xefd0, 0x2723, 0x4dd1, 0x38b2, 0x0de5, 0x2d90, 0x155b, 0xca06,
-0xbab6, 0xbf37, 0xdd46, 0xe3fd, 0xfb50, 0x2e5d, 0x487b, 0x343e, 0x0abe, 0x25e9,
-0x0f65, 0xcb83, 0xb474, 0xbc50, 0xe2ab, 0xe1df, 0xfd3e, 0x3672, 0x458b, 0x294e,
-0x10fd, 0x2afa, 0x027f, 0xcae8, 0xb95b, 0xbc6f, 0xe536, 0xe3af, 0xfd1c, 0x3b18,
-0x4cb1, 0x23ff, 0x13eb, 0x3353, 0xfb34, 0xc4aa, 0xb71a, 0xb9f2, 0xe1d7, 0xe97f,
-0x058d, 0x3a0f, 0x4fcd, 0x2408, 0x11a3, 0x2fb9, 0xf271, 0xbb7f, 0xb447, 0xc317,
-0xde44, 0xe56a, 0x110a, 0x3ccc, 0x494a, 0x1f80, 0x11af, 0x26a1, 0xeb09, 0xbcd0,
-0xaf90, 0xc8d4, 0xe63f, 0xe47d, 0x1435, 0x3f4f, 0x3fbe, 0x17c7, 0x1a4f, 0x2393,
-0xe191, 0xbfa1, 0xb0e4, 0xc7c9, 0xe2d9, 0xe363, 0x1625, 0x4320, 0x3da9, 0x11c4,
-0x1e02, 0x1d1b, 0xd6be, 0xbe96, 0xb123, 0xc8a4, 0xe6ce, 0xef2e, 0x1c03, 0x4584,
-0x3fd1, 0x1006, 0x20d8, 0x197b, 0xcf64, 0xb99e, 0xb693, 0xd396, 0xe8eb, 0xfb01,
-0x2aca, 0x4b38, 0x3f87, 0x0de0, 0x1f2f, 0x1503, 0xd574, 0xba46, 0xb72d, 0xf07a,
-0xfa16, 0xf608, 0x29c0, 0x3a7e, 0x42a7, 0x43ac, 0x2717, 0xec6f, 0xd732, 0xc1ac,
-0xa146, 0xef37, 0x122b, 0x05c1, 0x5c67, 0x8e8c, 0x3d5e, 0x0043, 0x00d0, 0xb9ef,
-0xa38d, 0xc8dd, 0xc921, 0x15c9, 0x5fe3, 0x531a, 0x477d, 0x5852, 0x1b9f, 0xb930,
-0xd1b6, 0xde60, 0xbcce, 0xe7f7, 0x16b1, 0x2aeb, 0x4605, 0x3592, 0xfe8c, 0x0c1d,
-0x1b24, 0xd084, 0xd667, 0x2736, 0x06f7, 0xdfa7, 0x1976, 0x0df9, 0xc5e8, 0x032b,
-0x324e, 0xea0e, 0x1ab4, 0x46e4, 0xf72e, 0x0369, 0x0ef3, 0xbe35, 0xbd17, 0x10fd,
-0xfb35, 0xeb3f, 0x4e43, 0x2da4, 0xfe31, 0x2f50, 0xf64c, 0xafd6, 0xe267, 0xfd01,
-0xca77, 0x1087, 0x48c1, 0xfcf4, 0x1bb0, 0x31af, 0xd234, 0xc0cb, 0x054e, 0xec6b,
-0xce29, 0x29db, 0x1bb4, 0xf0fd, 0x3608, 0x12eb, 0xbb40, 0xeaa8, 0x190f, 0xce00,
-0xed59, 0x39ef, 0xf1f0, 0xfb2a, 0x3535, 0xe3b3, 0xbf33, 0x1a9b, 0x013b, 0xc2ab,
-0x2976, 0x21e0, 0xd3d8, 0x1ca6, 0x14ae, 0xb242, 0xe538, 0x2958, 0xd98c, 0xf279,
-0x4106, 0xf13e, 0xf68b, 0x3379, 0xe023, 0xb4a8, 0x104b, 0x0685, 0xcca4, 0x2e61,
-0x2d96, 0xe2b8, 0x26ac, 0x2510, 0xc114, 0xd9e5, 0x1f91, 0xdbc9, 0xe515, 0x40bd,
-0x0693, 0xff44, 0x3c5e, 0xf664, 0xb8dc, 0x0b37, 0x1314, 0xc29c, 0x161f, 0x3582,
-0xe32e, 0x17c0, 0x2de6, 0xc7c1, 0xcfeb, 0x23a6, 0xe644, 0xe65f, 0x4256, 0xf765,
-0xe698, 0x4148, 0xfbe1, 0xa6b4, 0x03fa, 0x1c92, 0xcb85, 0x1a54, 0x37af, 0xe830,
-0x1b0b, 0x255d, 0xc13f, 0xd3d9, 0x205e, 0xde69, 0xe2ab, 0x48d5, 0x0931, 0xee2f,
-0x3d79, 0x0658, 0xb36c, 0xf59e, 0x11f4, 0xd042, 0x110b, 0x2e1b, 0xe763, 0x2269,
-0x3bda, 0xcefb, 0xd37b, 0x2d7f, 0xe9d7, 0xd48e, 0x3fd2, 0x0e86, 0xea62, 0x3cd5,
-0x11e0, 0xc1dc, 0x08e0, 0x1f68, 0xd3f1, 0x1fc8, 0x3da6, 0xe12f, 0x1d62, 0x4060,
-0xccb6, 0xd211, 0x316f, 0xf370, 0xe20e, 0x4657, 0x1280, 0xf30a, 0x3df0, 0x07fc,
-0xb956, 0x023e, 0x1978, 0xcbba, 0x137d, 0x3ff7, 0xecbc, 0x1698, 0x3f29, 0xdf9f,
-0xcc1c, 0x1bdc, 0xef17, 0xd3da, 0x346b, 0x1296, 0xeb25, 0x3885, 0x190f, 0xbf13,
-0xfb71, 0x1df2, 0xc509, 0xffa2, 0x3a66, 0xe5fd, 0x04f6, 0x36be, 0xda99, 0xc67e,
-0x1fc2, 0xef95, 0xcfa8, 0x39df, 0x0f1a, 0xd986, 0x2d7b, 0x0e88, 0xb2a2, 0xf40f,
-0x1bd3, 0xc95c, 0x0511, 0x408d, 0xec48, 0x03d2, 0x3281, 0xd7a0, 0xb9a0, 0x13ab,
-0xf02d, 0xc92c, 0x3af6, 0x26c0, 0xe5f8, 0x2de7, 0x18b9, 0xafd8, 0xddbf, 0x15bc,
-0xc4d3, 0xf6dc, 0x4b73, 0xf89f, 0x018a, 0x3c4e, 0xdf11, 0xb20d, 0x12d7, 0xf511,
-0xbf7e, 0x33aa, 0x286f, 0xe309, 0x3107, 0x1f74, 0xb1c3, 0xe10f, 0x1fd3, 0xc7d4,
-0xef6e, 0x4b78, 0xf32f, 0xf8e5, 0x43cb, 0xe7da, 0xaf46, 0x115a, 0xfeb2, 0xbf7a,
-0x2e9a, 0x2ed7, 0xde2f, 0x2807, 0x259c, 0xb09f, 0xd3d4, 0x2606, 0xd544, 0xeb3d,
-0x5107, 0xfecf, 0xf63f, 0x4304, 0xedfe, 0xae0d, 0x0d7f, 0x0957, 0xc47d, 0x2f62,
-0x3b51, 0xdfea, 0x2a01, 0x3390, 0xb825, 0xd3e9, 0x29f1, 0xd82e, 0xe2e3, 0x509a,
-0x061c, 0xf530, 0x48b1, 0xf740, 0xabeb, 0x0d93, 0x0ed4, 0xbed0, 0x274e, 0x3e3b,
-0xddc2, 0x2168, 0x35a1, 0xbbb0, 0xcedb, 0x2b94, 0xdd5b, 0xdd2d, 0x4e6a, 0x068d,
-0xe741, 0x3eef, 0xfe34, 0xad12, 0x0bb7, 0x1a73, 0xbea5, 0x1c31, 0x4269, 0xdc1a,
-0x1611, 0x37d6, 0xc048, 0xcaa3, 0x2f7e, 0xe59c, 0xd94c, 0x4ed8, 0x0af6, 0xe225,
-0x3c84, 0xfd49, 0xa4b2, 0x048d, 0x1ed5, 0xc496, 0x1caa, 0x4641, 0xddd4, 0x1578,
-0x37dc, 0xc13b, 0xcab7, 0x30dc, 0xfec0, 0xd462, 0x1387, 0x07dd, 0x14c1, 0x4b92,
-0x0d74, 0xda49, 0x12de, 0x02fe, 0xb8fe, 0xeaae, 0x0363, 0xdab0, 0x23b0, 0x68fb,
-0x3681, 0x1351, 0x29fc, 0xf22e, 0xb781, 0xd225, 0xc11d, 0xd7d8, 0x354d, 0x26b8,
-0x09af, 0x60fa, 0x5f8c, 0xe302, 0xde80, 0xff6a, 0xbb95, 0xafec, 0x029f, 0x161d,
-0x0fee, 0x3924, 0x2b6c, 0x1ed5, 0x24fe, 0xec7b, 0xc1fe, 0xe22b, 0xfbcd, 0xdc4d,
-0xf3f7, 0x210f, 0x1d01, 0x1305, 0x1342, 0x1f6c, 0x0852, 0xfea5, 0xdd42, 0xc083,
-0xf243, 0xde95, 0xd818, 0x23f7, 0x3eab, 0x0891, 0x1381, 0x52fd, 0xff10, 0xc983,
-0xe091, 0xc3b8, 0xcafc, 0xe7d7, 0xfc8d, 0x2043, 0x559d, 0x2c2e, 0x0418, 0x4485,
-0x0b4c, 0xb4e5, 0xc68e, 0xddbf, 0xd0b6, 0xdc81, 0x1e4b, 0x2d10, 0x365b, 0x2c50,
-0x170a, 0x303e, 0x0a60, 0xcc89, 0xb88a, 0xdbc7, 0xe3e7, 0xcdd2, 0x0b38, 0x3c7e,
-0x392b, 0x254c, 0x3272, 0x2fc9, 0xf0ee, 0xd4d8, 0xb5b4, 0xc03b, 0xdef0, 0xd8e9,
-0x0edc, 0x533e, 0x46e4, 0x0fc4, 0x358a, 0x34b8, 0xd1c3, 0xbf29, 0xbb64, 0xbeea,
-0xdb1c, 0xf31b, 0x17f1, 0x44fa, 0x4bfb, 0x0a36, 0x1fe2, 0x2ce9, 0xcf0d, 0xb605,
-0xc6c6, 0xcc96, 0xcf30, 0xf9cd, 0x25fb, 0x36d1, 0x4086, 0x1499, 0x21d8, 0x287f,
-0xde77, 0xb0fd, 0xba6d, 0xe0f5, 0xd3e4, 0xee77, 0x3561, 0x4077, 0x2baa, 0x1d38,
-0x3753, 0x1587, 0xd2e2, 0xb252, 0xb44b, 0xe5a7, 0xdbb5, 0xe778, 0x3790, 0x55cb,
-0x234e, 0x10ab, 0x42e9, 0x083e, 0xc15a, 0xc2a9, 0xbe30, 0xd7d1, 0xe76a, 0xfa22,
-0x2b37, 0x53cb, 0x29a6, 0x0950, 0x4086, 0x0f68, 0xbba0, 0xb824, 0xcc9c, 0xd743,
-0xd665, 0x06ae, 0x3597, 0x44f1, 0x2854, 0x19d4, 0x3395, 0xfe8f, 0xc1b9, 0xad2d,
-0xc39d, 0xde05, 0xd850, 0x0bf2, 0x4266, 0x457f, 0x1d4b, 0x2284, 0x337f, 0xe442,
-0xbc43, 0xb8ba, 0xc33a, 0xe0e4, 0xe8f8, 0x10b5, 0x4262, 0x4afc, 0x1744, 0x1d2b,
-0x3125, 0xe2b5, 0xbcb6, 0xbdea, 0xccfd, 0xdfe5, 0xefed, 0x1bae, 0x3f5e, 0x451d,
-0x167c, 0x1ea7, 0x2848, 0xdf70, 0xbb35, 0xbbfc, 0xd959, 0xe266, 0xec2b, 0x20e3,
-0x435c, 0x3878, 0x0fee, 0x25e8, 0x1ba1, 0xdaf0, 0xc061, 0xb76f, 0xdd9c, 0xe727,
-0xece4, 0x247e, 0x48ee, 0x303d, 0x099a, 0x320b, 0x19b9, 0xd0b8, 0xc508, 0xbe20,
-0xd52c, 0xe430, 0xf5f1, 0x21d1, 0x4aae, 0x3670, 0x0bc4, 0x349a, 0x16c6, 0xc9e1,
-0xbb8f, 0xc44e, 0xdbed, 0xde26, 0x03b2, 0x34c9, 0x4689, 0x30a8, 0x17ea, 0x33bd,
-0x0b87, 0xcd79, 0xb9b9, 0xc3c1, 0xe227, 0xdffc, 0x07ae, 0x3deb, 0x4732, 0x25e8,
-0x1ef9, 0x370f, 0xfb29, 0xcc78, 0xbf32, 0xc5c0, 0xe807, 0xe571, 0x074b, 0x4121,
-0x4902, 0x1968, 0x206c, 0x3da5, 0xf467, 0xc9c7, 0xc240, 0xc6d8, 0xe2b1, 0xeca9,
-0x0f7d, 0x3a80, 0x4ac1, 0x1bda, 0x1cdc, 0x3836, 0xee35, 0xc32e, 0xc0a2, 0xce3e,
-0xdfd7, 0xe9c8, 0x162c, 0x3eb5, 0x48b0, 0x1a61, 0x1e8f, 0x2cf5, 0xe5c6, 0xbb80,
-0xb378, 0xd228, 0xe3dd, 0xeba5, 0x2266, 0x46f5, 0x3e1f, 0x13fa, 0x26ea, 0x21ec,
-0xd925, 0xbdc7, 0xb66d, 0xd76b, 0xe81e, 0xf025, 0x269d, 0x4d69, 0x3d40, 0x1027,
-0x2c58, 0x1cc9, 0xd265, 0xbfd4, 0xbabe, 0xd919, 0xe822, 0xf931, 0x2bc9, 0x4c69,
-0x3d20, 0x158d, 0x31ca, 0x1821, 0xce8a, 0xb8af, 0xba0f, 0xdfb6, 0xe677, 0xfd3b,
-0x385e, 0x53d9, 0x3764, 0x14a8, 0x30af, 0x0a51, 0xcb95, 0xbad7, 0xbc48, 0xe366,
-0xea7e, 0x06cf, 0x3f08, 0x53c7, 0x2fe0, 0x189d, 0x383f, 0x00fd, 0xc5f3, 0xbf0d,
-0xc38f, 0xe4a3, 0xecee, 0x0ef5, 0x432c, 0x54a7, 0x2a15, 0x190d, 0x3675, 0xf7bc,
-0xc3e0, 0xbc22, 0xc381, 0xe210, 0xec59, 0x15ed, 0x4300, 0x4fd8, 0x269c, 0x1bda,
-0x324a, 0xed57, 0xbb9c, 0xb705, 0xceb8, 0xeb30, 0xed72, 0x1baa, 0x48ad, 0x4bd3,
-0x1fde, 0x1ea9, 0x2826, 0xe505, 0xc2b3, 0xb577, 0xceec, 0xeeb9, 0xef73, 0x1fd5,
-0x4c99, 0x41f7, 0x12c7, 0x24ad, 0x22eb, 0xd504, 0xbfe3, 0xba2a, 0xd063, 0xea6f,
-0xf037, 0x1c9c, 0x4acf, 0x430c, 0x0b68, 0x200d, 0x1c9e, 0xcce4, 0xb9ad, 0xbc29,
-0xd211, 0xe475, 0xfc21, 0x2910, 0x443b, 0x3a83, 0x0ef1, 0x2295, 0x15ac, 0xd00d,
-0xb774, 0xbaff, 0xded3, 0xe41e, 0xf945, 0x331e, 0x49b7, 0x3276, 0x128d, 0x28c7,
-0x08f2, 0xce8e, 0xbb2e, 0xb907, 0xe4c0, 0xe9f8, 0xf98a, 0x3323, 0x4a75, 0x2718,
-0x0ddc, 0x3369, 0x0795, 0xc936, 0xc192, 0xc3cc, 0xe2b9, 0xe583, 0xfce9, 0x312f,
-0x4951, 0x266f, 0x0ffe, 0x3698, 0x0679, 0xca63, 0xc301, 0xc844, 0xde4c, 0xe26e,
-0x076e, 0x3283, 0x4507, 0x259a, 0x11af, 0x30ff, 0xfd1c, 0xc1b2, 0xb384, 0xc924,
-0xe414, 0xde8f, 0x0781, 0x295f, 0x51b4, 0x5b09, 0x17c9, 0xf17b, 0xd9cd, 0xb11a,
-0x8396, 0xbd98, 0x073f, 0x0598, 0x5258, 0x7bf8, 0x3dd3, 0x096d, 0xe7f8, 0xa966,
-0x9271, 0xc3c7, 0xb173, 0xf5d9, 0x6db2, 0x3b89, 0x2231, 0x4aaf, 0x1c3b, 0xc115,
-0xcb06, 0xd460, 0xbb98, 0x03f6, 0xf9d7, 0xecaf, 0x4aa5, 0x27cf, 0xcf8c, 0x0764,
-0x3489, 0xd9cb, 0xf31b, 0x39b5, 0xebc3, 0xeb7f, 0x1192, 0xceee, 0xbd72, 0x16f9,
-0x1b5a, 0xf888, 0x4a44, 0x34a8, 0xedd8, 0x18bb, 0xf8d6, 0xa74c, 0xd19c, 0x139c,
-0xeaf7, 0x0d0b, 0x5317, 0x0e81, 0x0c44, 0x35bd, 0xe010, 0xb51d, 0x075b, 0xfc77,
-0xc9ae, 0x2b95, 0x35a1, 0xf0e8, 0x2c61, 0x2481, 0xc370, 0xe826, 0x20b5, 0xd95a,
-0xf832, 0x43e0, 0xf261, 0xf7ef, 0x414e, 0xf14b, 0xbf9e, 0x1c6c, 0x1380, 0xd3d1,
-0x2650, 0x1f52, 0xd592, 0x1ddb, 0x2414, 0xc347, 0xebd1, 0x3e70, 0xf240, 0xeb89,
-0x3d66, 0xf738, 0xe57b, 0x2fe8, 0xf22d, 0xbd68, 0x1e7b, 0x2466, 0xd858, 0x2613,
-0x3122, 0xdc86, 0x16b9, 0x277b, 0xc324, 0xdb13, 0x2c78, 0xe8ab, 0xed0b, 0x49bb,
-0x0342, 0xf02a, 0x3b6c, 0xf7d9, 0xb9c6, 0x0fd8, 0x1192, 0xc763, 0x12e5, 0x2738,
-0xe26c, 0x1a89, 0x2a72, 0xcd72, 0xdca7, 0x27a9, 0xe962, 0xd98a, 0x271e, 0xf948,
-0xe783, 0x29f0, 0x000e, 0xc137, 0x064c, 0x17e6, 0xcd48, 0x0efb, 0x329b, 0xdc50,
-0xf9d6, 0x28fd, 0xd866, 0xc34b, 0x13df, 0xefa3, 0xdcbf, 0x3578, 0x09a7, 0xe33f,
-0x2c3f, 0x02a6, 0xaa76, 0xf3eb, 0x1870, 0xc21d, 0x029e, 0x3d07, 0xedbb, 0x0a92,
-0x33dc, 0xd94f, 0xc985, 0x15a5, 0xdf1c, 0xd3f5, 0x3f5e, 0x0fca, 0xe50f, 0x3b04,
-0x1a3d, 0xb99b, 0xf6d1, 0x1c75, 0xcc21, 0x0987, 0x3e95, 0xed51, 0x0dcf, 0x3b32,
-0xd980, 0xc6f7, 0x280e, 0xf587, 0xd3c2, 0x4871, 0x233c, 0xe02f, 0x3039, 0x183d,
-0xaecf, 0xf137, 0x2776, 0xcc66, 0x0bf0, 0x5162, 0xeddf, 0x088c, 0x4536, 0xd457,
-0xb205, 0x2315, 0xf51a, 0xc60d, 0x4281, 0x2682, 0xe5d9, 0x3aad, 0x1cab, 0xb02d,
-0xf294, 0x20af, 0xbecb, 0x0084, 0x4c16, 0xeaf2, 0x054e, 0x449f, 0xdf02, 0xbd48,
-0x25bf, 0xfda9, 0xcb15, 0x3a93, 0x1e9b, 0xddd4, 0x3408, 0x1f70, 0xb333, 0xf3df,
-0x32ab, 0xd133, 0x014e, 0x52b2, 0xf138, 0xfe00, 0x4260, 0xe1f2, 0xbbac, 0x28bf,
-0x0404, 0xcc81, 0x4649, 0x2e56, 0xdee8, 0x3677, 0x23ef, 0xabc0, 0xea62, 0x3159,
-0xcf59, 0xfdcf, 0x575a, 0xf403, 0xfe40, 0x4759, 0xe094, 0xb225, 0x1ffa, 0xfefc,
-0xc26f, 0x3a61, 0x2be1, 0xdb44, 0x2efe, 0x2504, 0xadcb, 0xe074, 0x2713, 0xc6d3,
-0xecc2, 0x48d6, 0xea4d, 0xf2ec, 0x43a0, 0xe1fc, 0xaa5f, 0x1825, 0xffd7, 0xba38,
-0x2bdb, 0x24a3, 0xce10, 0x1cd8, 0x1cfc, 0xab2e, 0xdc4d, 0x276d, 0xca22, 0xeb01,
-0x4a08, 0xeb0e, 0xe94c, 0x3cd7, 0xe45f, 0xa6c6, 0x0f8c, 0x066f, 0xc2d2, 0x2a01,
-0x2aea, 0xd9bf, 0x251a, 0x2933, 0xb64d, 0xd9b5, 0x26a1, 0xd2ba, 0xe822, 0x4af1,
-0xfec7, 0xf323, 0x3fdf, 0xf78e, 0xb4c1, 0x0f7f, 0x0e1c, 0xc7ce, 0x25fb, 0x3129,
-0xdeb5, 0x2268, 0x3385, 0xc266, 0xd9b6, 0x2efc, 0xddb0, 0xe00f, 0x45ac, 0x0168,
-0xea8d, 0x3cd9, 0xfeda, 0xb603, 0x13c5, 0x166b, 0xc192, 0x1f5a, 0x3804, 0xda94,
-0x15a3, 0x35b3, 0xc729, 0xd3ae, 0x2e68, 0xe359, 0xde70, 0x4764, 0x0725, 0xe6b1,
-0x3882, 0xfed4, 0xad23, 0x0819, 0x16c2, 0xc15b, 0x1c91, 0x4358, 0xe49c, 0x1162,
-0x35d1, 0xc8f8, 0xc74f, 0x2676, 0xe0e9, 0xd0d7, 0x4b09, 0x1cea, 0xedea, 0x3f3b,
-0x11f4, 0xb09a, 0xfc73, 0x177b, 0xba40, 0x109f, 0x4fcb, 0xf285, 0x1d0f, 0x3dc2,
-0xc588, 0xc98d, 0x329a, 0xfd8a, 0xcc33, 0x1573, 0x1810, 0x1532, 0x434e, 0x102d,
-0xd555, 0x08d4, 0x0011, 0xb77c, 0xec37, 0x098c, 0xd4fc, 0x2033, 0x7926, 0x32be,
-0xfe95, 0x28ab, 0xef9c, 0xa428, 0xcffc, 0xcbdf, 0xd07c, 0x3681, 0x2f87, 0x0680,
-0x626e, 0x5e9c, 0xd624, 0xd9e4, 0x080a, 0xadfe, 0xa2f5, 0x12af, 0x142c, 0xffde,
-0x3703, 0x3570, 0x269e, 0x24fb, 0xe8a1, 0xb7ec, 0xe753, 0xf82a, 0xce4d, 0x001a,
-0x2e98, 0x1f84, 0x0eb8, 0x1beb, 0x2603, 0xfcff, 0xfd98, 0xd8c0, 0xc719, 0xfc52,
-0xddd2, 0xe3ec, 0x2ee0, 0x4393, 0x042b, 0x1929, 0x569a, 0xef83, 0xc35d, 0xd9e5,
-0xc6ce, 0xd1e0, 0xed86, 0x0b2a, 0x23b2, 0x504c, 0x20ad, 0x029d, 0x3b72, 0xf5a5,
-0xad6b, 0xbe54, 0xddfc, 0xd162, 0xddcd, 0x2952, 0x324b, 0x3156, 0x1d3f, 0x12f5,
-0x235b, 0xf27f, 0xc001, 0xb250, 0xdfdd, 0xe3f3, 0xd455, 0x14e4, 0x3c06, 0x3326,
-0x1a60, 0x30e7, 0x24a0, 0xe2c3, 0xcd08, 0xb21c, 0xc75c, 0xdc66, 0xe088, 0x1e09,
-0x54ef, 0x4197, 0x0dca, 0x356f, 0x22ce, 0xcaf2, 0xc0ce, 0xbc3d, 0xcfda, 0xe59b,
-0xfe5c, 0x27b1, 0x4caa, 0x45a1, 0x0add, 0x274f, 0x1c6c, 0xcde6, 0xc343, 0xd011,
-0xdf48, 0xe021, 0x0b0c, 0x335a, 0x3c8e, 0x345d, 0x0d86, 0x278e, 0x1b8f, 0xdc12,
-0xbc28, 0xc6ff, 0xead3, 0xdba0, 0xfdee, 0x39b8, 0x3f03, 0x2143, 0x1858, 0x376b,
-0x021b, 0xcaa8, 0xbb59, 0xc6f6, 0xef67, 0xe041, 0xf9ba, 0x3cd7, 0x4cfd, 0x168d,
-0x1037, 0x3fec, 0xf71d, 0xbed3, 0xc8d6, 0xcbc6, 0xdd8f, 0xea8c, 0x09b1, 0x2e92,
-0x4701, 0x1829, 0x091c, 0x3ad7, 0xfd4b, 0xb999, 0xbe68, 0xdc50, 0xdc39, 0xd663,
-0x1009, 0x330e, 0x37f3, 0x1ad3, 0x1cca, 0x3476, 0xf66a, 0xc5e8, 0xbb6f, 0xd5e8,
-0xe008, 0xd5ea, 0x10b5, 0x3f63, 0x3725, 0x1102, 0x2911, 0x3855, 0xe9cb, 0xc610,
-0xc44b, 0xd547, 0xdd89, 0xe4aa, 0x195d, 0x4084, 0x3d9b, 0x10ab, 0x2a1f, 0x3667,
-0xe38c, 0xc1a0, 0xc4c5, 0xdd94, 0xe21b, 0xe99c, 0x1f49, 0x4312, 0x3b69, 0x0f14,
-0x2b3d, 0x2eaa, 0xdeab, 0xc00a, 0xc634, 0xe225, 0xe0e3, 0xf311, 0x2b9a, 0x44fd,
-0x3881, 0x11ee, 0x2f2a, 0x2428, 0xdc87, 0xc347, 0xc2d0, 0xe6e0, 0xe5b0, 0xf196,
-0x2d4e, 0x4a97, 0x3366, 0x1388, 0x3ae0, 0x1bf8, 0xd058, 0xc212, 0xc09b, 0xdbf3,
-0xe25c, 0xfa1f, 0x3093, 0x4e94, 0x31f0, 0x12fe, 0x3bde, 0x11ad, 0xc841, 0xb8bd,
-0xbe0b, 0xdd25, 0xdd7e, 0x0138, 0x3ac9, 0x4ccb, 0x2ba2, 0x1359, 0x3033, 0xfbc6,
-0xc14d, 0xb543, 0xbd7e, 0xdcf8, 0xde2b, 0x0754, 0x388b, 0x409a, 0x1e0d, 0x134a,
-0x2ba8, 0xeee4, 0xbe5b, 0xafaf, 0xbb90, 0xe059, 0xde74, 0x0736, 0x3d1c, 0x4310,
-0x16f1, 0x1686, 0x2f2a, 0xe9de, 0xbe17, 0xb446, 0xc0ca, 0xdd27, 0xe1a0, 0x0ccd,
-0x3c13, 0x4661, 0x1949, 0x196a, 0x2a50, 0xdf8d, 0xb6a7, 0xb25a, 0xc8aa, 0xdf0e,
-0xe6dc, 0x19c8, 0x411d, 0x423f, 0x15db, 0x1a0d, 0x2316, 0xdf69, 0xba97, 0xb2a9,
-0xd092, 0xe29a, 0xebf2, 0x2556, 0x4a3b, 0x3fb1, 0x16cb, 0x2603, 0x1c1b, 0xd67d,
-0xbcf3, 0xb765, 0xdad1, 0xea4b, 0xf176, 0x27e4, 0x4d31, 0x3b4c, 0x0fab, 0x2ad5,
-0x1a4d, 0xd10b, 0xbc49, 0xba78, 0xda1f, 0xe903, 0xffda, 0x308c, 0x4a2f, 0x38ce,
-0x11cc, 0x299c, 0x105c, 0xcdc3, 0xba31, 0xc03e, 0xe616, 0xe849, 0xfec7, 0x37e1,
-0x4e98, 0x3198, 0x12d8, 0x2aeb, 0x03e5, 0xcb29, 0xbccb, 0xc232, 0xe734, 0xeb9c,
-0x07ed, 0x3d12, 0x4b48, 0x2515, 0x14e8, 0x330c, 0xfd19, 0xc86d, 0xc241, 0xca17,
-0xe64b, 0xe918, 0x09ed, 0x3ba3, 0x4eee, 0x25e2, 0x167a, 0x38a6, 0xffcf, 0xcb0e,
-0xc615, 0xd055, 0xe3d3, 0xeafc, 0x1602, 0x3e86, 0x49c2, 0x257e, 0x2166, 0x3bcd,
-0xfc55, 0xc4ad, 0xbb87, 0xd6e3, 0xe7a1, 0xe64f, 0x1ddd, 0x4682, 0x4516, 0x1dee,
-0x1dc5, 0x2b0d, 0xed86, 0xc590, 0xb97d, 0xd84f, 0xec06, 0xe368, 0x1c7f, 0x4cee,
-0x3f07, 0x13c3, 0x289d, 0x28fb, 0xdcf0, 0xc5b7, 0xbdb7, 0xd4a7, 0xec46, 0xecd0,
-0x1bda, 0x48cc, 0x4019, 0x0cd7, 0x23a7, 0x2698, 0xd5be, 0xbc3e, 0xb90e, 0xcc6c,
-0xddf3, 0xf12b, 0x24f1, 0x4448, 0x3b5c, 0x118e, 0x2441, 0x1c2b, 0xd270, 0xb368,
-0xb6c7, 0xdd46, 0xdf51, 0xefbb, 0x3138, 0x49d2, 0x3667, 0x1864, 0x2b86, 0x1073,
-0xd35e, 0xbbf4, 0xb47a, 0xdfb4, 0xe8bb, 0xf6b2, 0x353a, 0x4fd4, 0x2e9f, 0x12a8,
-0x323d, 0x07c8, 0xcb04, 0xc1fa, 0xbd57, 0xdf17, 0xe6e8, 0xfa82, 0x3052, 0x4c63,
-0x2d83, 0x12bf, 0x3366, 0x0318, 0xc6dd, 0xbd85, 0xbc4f, 0xd9e1, 0xe604, 0x0814,
-0x34df, 0x4a09, 0x2d9d, 0x148f, 0x2e79, 0xfba1, 0xc12c, 0xb277, 0xbf95, 0xdeb7,
-0xe211, 0x10bc, 0x423c, 0x4956, 0x24f7, 0x1571, 0x2434, 0xebbb, 0xc333, 0xb587,
-0xc733, 0xedc0, 0xebba, 0x0854, 0x3f2e, 0x6f7e, 0x4a81, 0x0e5e, 0x03fe, 0xcb43,
-0xa313, 0xa8c3, 0xd5fe, 0x0fe0, 0x3ce3, 0x6922, 0x5cb3, 0x4541, 0x10b8, 0xc5c1,
-0xb7c8, 0xca44, 0xca38, 0xd7f7, 0x38e7, 0x4e53, 0x1cb5, 0x3dfb, 0x3d19, 0x06ab,
-0xeda0, 0xe9ef, 0xd83d, 0xf9bf, 0x0ebe, 0xca2a, 0x0a79, 0x510e, 0xf01d, 0xe7eb,
-0x3be6, 0x1a2e, 0xf989, 0x353e, 0x099c, 0xe538, 0x16d7, 0xd697, 0xa93c, 0x0407,
-0x1bee, 0xf75f, 0x46c6, 0x50e3, 0xf430, 0x1813, 0x169b, 0xaf5d, 0xc57c, 0x0fb5,
-0xe638, 0xf7e9, 0x459c, 0x122e, 0x0654, 0x352e, 0xfc93, 0xc262, 0xf99c, 0x072c,
-0xc8f1, 0x0bf2, 0x32cd, 0xf85b, 0x1790, 0x25c1, 0xde96, 0xd882, 0x18ea, 0xe834,
-0xd77c, 0x3995, 0x1231, 0xeab1, 0x28e3, 0x0cfc, 0xc5ef, 0xf7bd, 0x18f1, 0xd03e,
-0x057e, 0x320a, 0xe5e4, 0x07c7, 0x2d5d, 0xd88a, 0xc884, 0x2072, 0xfd6c, 0xd3d0,
-0x2a59, 0x1066, 0xe564, 0x22a2, 0x047a, 0xb2ee, 0xeaad, 0x1c28, 0xcc6c, 0xf7e5,
-0x3c36, 0xee88, 0xfbfb, 0x3085, 0xddf6, 0xb28a, 0x0aaf, 0xf456, 0xbc45, 0x223a,
-0x21ed, 0xe31c, 0x2214, 0x1882, 0xb51a, 0xdbdc, 0x18ba, 0xc1ce, 0xe1c3, 0x397c,
-0xed39, 0xf426, 0x3690, 0xe68c, 0xb498, 0x0e83, 0x00c5, 0xc494, 0x1ef7, 0x1b31,
-0xdc33, 0x1f84, 0x1b7f, 0xb9c1, 0xdc07, 0x2246, 0xd5fb, 0xeaf7, 0x4a41, 0x042a,
-0xed8c, 0x29a9, 0xf4c4, 0xbbf5, 0xffbd, 0x02b3, 0xd089, 0x2a98, 0x349a, 0xe5f4,
-0x231d, 0x3682, 0xc042, 0xc757, 0x28ee, 0xe56b, 0xda47, 0x3eac, 0x0d7c, 0xfc17,
-0x4512, 0x05d1, 0xbb63, 0x0fc8, 0x0da5, 0xb98f, 0x1ecc, 0x3aea, 0xdbbd, 0x1bd6,
-0x4041, 0xd007, 0xd35e, 0x2aaf, 0xea38, 0xe711, 0x3e4a, 0xfa47, 0xef65, 0x3f02,
-0xf730, 0xae98, 0x0fae, 0x1e19, 0xc953, 0x1ea3, 0x3db2, 0xe20d, 0x1043, 0x2d87,
-0xc8ab, 0xca8a, 0x2270, 0xe769, 0xe021, 0x4751, 0x0a42, 0xed5b, 0x468e, 0x0a0e,
-0xa823, 0xfc1e, 0x19ce, 0xc19e, 0x0fd8, 0x3c33, 0xe854, 0x1d91, 0x3f3f, 0xd03c,
-0xd290, 0x2d60, 0xe292, 0xd443, 0x4229, 0x0590, 0xe446, 0x3c78, 0x0d2e, 0xbba0,
-0x0b10, 0x1fdc, 0xccc6, 0x142f, 0x3174, 0xdc18, 0x1061, 0x371b, 0xd368, 0xd200,
-0x2d59, 0xf1a5, 0xdc23, 0x3edd, 0x0fb6, 0xe812, 0x2f6f, 0x0a77, 0xb941, 0xfe00,
-0x1d36, 0xcc9c, 0x11f2, 0x404a, 0xe70a, 0x0abc, 0x3965, 0xd3be, 0xbed2, 0x1fe7,
-0xee09, 0xd03e, 0x3f07, 0x1799, 0xe33b, 0x342f, 0x1443, 0xb44b, 0xf906, 0x1979,
-0xbeaf, 0x0a9f, 0x45b3, 0xe73c, 0x0a6f, 0x3e78, 0xd655, 0xc03d, 0x2087, 0xeb0b,
-0xcf7a, 0x4395, 0x1915, 0xe1a6, 0x34d0, 0x134e, 0xac96, 0xeeeb, 0x1aa0, 0xc459,
-0x0965, 0x4852, 0xe8bd, 0x0151, 0x3569, 0xd16f, 0xb855, 0x1c6f, 0xed54, 0xcabb,
-0x428e, 0x1dfb, 0xdf3c, 0x323b, 0x15f0, 0xab84, 0xe597, 0x18a2, 0xc34f, 0x0120,
-0x48dd, 0xedf1, 0x07d1, 0x3f6b, 0xd521, 0xb0ac, 0x1903, 0xf0c7, 0xc122, 0x3959,
-0x22ad, 0xe010, 0x2ec7, 0x1837, 0xaaf6, 0xe170, 0x1e2b, 0xc7b9, 0xfdb5, 0x4c53,
-0xebef, 0xfb34, 0x3ee4, 0xdef9, 0xb297, 0x1b34, 0xfd76, 0xc42a, 0x391e, 0x2b29,
-0xde3f, 0x2dc8, 0x2491, 0xb2a5, 0xe544, 0x2b06, 0xcad8, 0xf507, 0x54ba, 0xf673,
-0xfa92, 0x48ca, 0xe9a8, 0xafd3, 0x1ef7, 0x084a, 0xc383, 0x3a6e, 0x3354, 0xdbff,
-0x2c3f, 0x2b2a, 0xb115, 0xe1c4, 0x348d, 0xd2d5, 0xf3b1, 0x5801, 0xf84b, 0xf5dc,
-0x4897, 0xeba9, 0xac5a, 0x1d11, 0x0bb4, 0xbcd7, 0x32ed, 0x3809, 0xdc0a, 0x2aa8,
-0x3035, 0xb63c, 0xddf9, 0x3359, 0xe1e6, 0xdc8c, 0x1666, 0xf007, 0x2428, 0x5dbe,
-0x00c2, 0xd781, 0x22f0, 0xf405, 0xa1af, 0xed74, 0xf64b, 0xd808, 0x304e, 0x5c2f,
-0x2e87, 0x2aaf, 0x32b5, 0xdc5e, 0xbf90, 0xd852, 0xad5b, 0xdde3, 0x38e2, 0x1923,
-0x04d1, 0x62c4, 0x5bb8, 0xe529, 0xeaaf, 0xfd61, 0xc422, 0xc0df, 0xfa6b, 0x0d7b,
-0x16ff, 0x3f3e, 0x1d78, 0x1a46, 0x3b1d, 0xf55f, 0xc829, 0xeeb5, 0x0157, 0xdd55,
-0xf41a, 0x20b5, 0x1533, 0x2329, 0x1f7c, 0x1523, 0x1e43, 0x1419, 0xdc00, 0xbfc2,
-0xfbcf, 0xe187, 0xd1ef, 0x2a18, 0x3c8b, 0x1862, 0x2179, 0x4380, 0x06a1, 0xdc67,
-0xe0e4, 0xb854, 0xda4e, 0xf2b5, 0xe744, 0x1f54, 0x57ea, 0x2932, 0xfa55, 0x3961,
-0x0fd9, 0xbac6, 0xcdda, 0xd258, 0xcf89, 0xe3ab, 0x0707, 0x1a3e, 0x3967, 0x30cc,
-0x0264, 0x2d4f, 0x1e6c, 0xcc01, 0xb70b, 0xd1c4, 0xdac0, 0xca7b, 0xfba8, 0x26c2,
-0x371b, 0x359b, 0x23c6, 0x2fb4, 0x0da1, 0xd9bd, 0xae9d, 0xb89c, 0xdb61, 0xcb90,
-0x0132, 0x482d, 0x42cd, 0x1e49, 0x2e1f, 0x3691, 0xe7fa, 0xc93c, 0xba66, 0xbb0a,
-0xe251, 0xe472, 0x0383, 0x3f08, 0x4cc8, 0x1215, 0x1c80, 0x3b71, 0xe4f3, 0xc431,
-0xcbb0, 0xc403, 0xd2f9, 0xf12b, 0x1313, 0x2f50, 0x4774, 0x1313, 0x18c4, 0x4058,
-0xed5d, 0xb643, 0xc25a, 0xd92a, 0xcdc3, 0xe267, 0x25f0, 0x37bf, 0x38e3, 0x1db0,
-0x2909, 0x2dab, 0xe635, 0xb3fb, 0xb52f, 0xe71a, 0xdad1, 0xdbe5, 0x2dd4, 0x4a45,
-0x2f11, 0x15fc, 0x375b, 0x1edc, 0xd95e, 0xc7dd, 0xb91d, 0xdb9a, 0xe8d2, 0xea7d,
-0x243c, 0x50aa, 0x347a, 0x0b10, 0x3f2c, 0x24ae, 0xc984, 0xc48d, 0xccec, 0xd726,
-0xda77, 0xf845, 0x2782, 0x491b, 0x3bb7, 0x1233, 0x3698, 0x200c, 0xcd29, 0xb25f,
-0xc2ef, 0xdd85, 0xd457, 0xfe96, 0x3830, 0x43f0, 0x2e94, 0x1a60, 0x3369, 0x07e9,
-0xcb4f, 0xb645, 0xba73, 0xdbb8, 0xdb8f, 0xffae, 0x3a33, 0x48d7, 0x2211, 0x15da,
-0x362f, 0xfbd5, 0xc39a, 0xb7fb, 0xc2cf, 0xe1cd, 0xe2d2, 0x0604, 0x36c9, 0x495d,
-0x209d, 0x15d2, 0x37e6, 0xf91a, 0xc431, 0xbe00, 0xccf7, 0xe3be, 0xe90a, 0x14f8,
-0x3bed, 0x4775, 0x22c5, 0x1a55, 0x2eb8, 0xf7ab, 0xcbee, 0xbb0a, 0xd4b7, 0xea3e,
-0xe43a, 0x18fd, 0x455e, 0x429e, 0x1d75, 0x27b4, 0x2e04, 0xeadd, 0xca0c, 0xb834,
-0xcf7e, 0xebe8, 0xec12, 0x1d2b, 0x4ce6, 0x4388, 0x1410, 0x2882, 0x2863, 0xdbfa,
-0xc201, 0xbc64, 0xd1a8, 0xe40d, 0xf23c, 0x21f6, 0x44ac, 0x3ed5, 0x105b, 0x1f33,
-0x1ab9, 0xd393, 0xb879, 0xb8a2, 0xd559, 0xdf87, 0xf31b, 0x2555, 0x3b7c, 0x3066,
-0x0f9b, 0x206c, 0x1043, 0xd352, 0xb6fe, 0xb4ae, 0xdacb, 0xdd79, 0xed28, 0x2944,
-0x40cc, 0x26e3, 0x1073, 0x2c6d, 0x0a8e, 0xd1fe, 0xbe7c, 0xb79c, 0xdbb0, 0xe28f,
-0xf1b8, 0x2782, 0x45d6, 0x288a, 0x146e, 0x3752, 0x08d7, 0xccea, 0xc003, 0xbd89,
-0xda98, 0xe4f4, 0x0193, 0x3341, 0x4c65, 0x29eb, 0x1665, 0x385c, 0x0502, 0xcaf3,
-0xbfdd, 0xc859, 0xe1b4, 0xe85f, 0x0f40, 0x394b, 0x49b1, 0x2907, 0x1adb, 0x324c,
-0xf922, 0xc6e9, 0xb961, 0xcbdd, 0xe7b2, 0xe6bd, 0x11f6, 0x3fef, 0x46fb, 0x1df6,
-0x1d0f, 0x2f40, 0xeef5, 0xc4a6, 0xb575, 0xcb9f, 0xe637, 0xea22, 0x1afc, 0x450f,
-0x486c, 0x1ca2, 0x2081, 0x27c1, 0xe170, 0xbe81, 0xb610, 0xd4bd, 0xe951, 0xed82,
-0x22d8, 0x4920, 0x44fd, 0x1967, 0x24be, 0x230d, 0xdd5b, 0xbd48, 0xb2b2, 0xd74f,
-0xebd6, 0xf51e, 0x2d0e, 0x4f15, 0x406d, 0x18ea, 0x2d32, 0x1b37, 0xd68b, 0xc044,
-0xb935, 0xdd2b, 0xe8ca, 0xf474, 0x309b, 0x54b6, 0x3c42, 0x14ba, 0x347b, 0x1910,
-0xd0a8, 0xbcba, 0xb8c9, 0xdc46, 0xe9fe, 0xfff4, 0x3532, 0x5389, 0x3988, 0x14af,
-0x3504, 0x102d, 0xc848, 0xb929, 0xbe6f, 0xdd0e, 0xe430, 0x059c, 0x3ba7, 0x4f58,
-0x2e33, 0x10f0, 0x2a2f, 0xfdb9, 0xc2f6, 0xafbb, 0xbb99, 0xe4f6, 0xe5f2, 0x07f0,
-0x3ce6, 0x4606, 0x2206, 0x1803, 0x2b80, 0xee52, 0xc24f, 0xb46d, 0xbb4a, 0xe32e,
-0xe633, 0x0953, 0x4238, 0x4b00, 0x1a28, 0x1723, 0x280d, 0xe191, 0xbf29, 0xb512,
-0xbb95, 0xe083, 0xee77, 0x11e1, 0x3d02, 0x4905, 0x18fb, 0x175c, 0x25d3, 0xdaba,
-0xb4bd, 0xb51c, 0xcc2b, 0xe1c5, 0xed1f, 0x1d15, 0x42ae, 0x42e0, 0x12aa, 0x15c7,
-0x1ce6, 0xdd86, 0xbb2e, 0xb339, 0xd4c6, 0xe6a3, 0xee5c, 0x246d, 0x4599, 0x378a,
-0x117f, 0x247f, 0x1587, 0xd40f, 0xc211, 0xba12, 0xda04, 0xe9d2, 0xf097, 0x2593,
-0x4a0d, 0x33f2, 0x0e58, 0x2f92, 0x1796, 0xd23e, 0xc5d1, 0xbd1d, 0xd6a8, 0xea03,
-0xfd4b, 0x2b76, 0x4d07, 0x372b, 0x12c1, 0x3610, 0x1455, 0xc9fa, 0xc082, 0xc65f,
-0xdbf3, 0xe5fa, 0x0864, 0x3695, 0x4d6d, 0x3441, 0x13be, 0x2f2f, 0x090c, 0xce34,
-0xb830, 0xc505, 0xfada, 0xec81, 0xfb68, 0x2eba, 0x319e, 0x3ce2, 0x44fb, 0x1d01,
-0xdd9d, 0xd66a, 0xb232, 0xa016, 0xf64b, 0xfff6, 0x09d5, 0x7376, 0x8570, 0x20f6,
-0xfe82, 0xf200, 0x9a52, 0xa325, 0xc4f5, 0xcbde, 0x2c79, 0x67bb, 0x4c8f, 0x46a8,
-0x523c, 0xf79d, 0xabd0, 0xda12, 0xcc15, 0xb71c, 0xf62d, 0x1e60, 0x327a, 0x4b18,
-0x2770, 0xf598, 0x157f, 0x094e, 0xbe89, 0xebf7, 0x2a77, 0xf098, 0xe9ee, 0x28e2,
-0xf32a, 0xc056, 0x237c, 0x271d, 0xe4a4, 0x3978, 0x35ba, 0xe536, 0x10f5, 0xfdaa,
-0xa68b, 0xd3ea, 0x212f, 0xea07, 0x08a6, 0x5e96, 0x0ae2, 0x07c6, 0x37b6, 0xd70c,
-0xb092, 0xfe7d, 0xf21a, 0xcad9, 0x34d2, 0x36e9, 0xf083, 0x37da, 0x22a5, 0xbc01,
-0xdc00, 0x1395, 0xd553, 0xe5e3, 0x3bac, 0xfd08, 0xfe92, 0x3f5c, 0xee23, 0xbc45,
-0x0d39, 0x0a9c, 0xc61a, 0x146f, 0x2951, 0xdb39, 0x171e, 0x293d, 0xc2e7, 0xdd20,
-0x32b9, 0xe330, 0xd7b9, 0x3cc5, 0xf7d9, 0xdcad, 0x311b, 0xf1df, 0xb0b8, 0x105b,
-0x1a8c, 0xca51, 0x1be5, 0x2f80, 0xd616, 0x11ca, 0x2652, 0xbc4e, 0xcb96, 0x21a7,
-0xe4b4, 0xe253, 0x4487, 0x0196, 0xe674, 0x3516, 0xfb04, 0xb3bc, 0xfeb8, 0x1079,
-0xc24e, 0x088e, 0x3298, 0xe80b, 0x14c1, 0x2ed3, 0xd1a8, 0xcf82, 0x2207, 0xee50,
-0xcf02, 0x2dec, 0x08af, 0xe42a, 0x344d, 0x0fb2, 0xb971, 0xfa3f, 0x1df7, 0xd32e,
-0x11cc, 0x3722, 0xda30, 0x07ac, 0x3d3f, 0xd7ab, 0xc34d, 0x271b, 0xfe76, 0xdbb3,
-0x3d61, 0x18ed, 0xed9b, 0x3389, 0x0c14, 0xba7c, 0xf987, 0x187e, 0xcd50, 0x1066,
-0x476b, 0xf480, 0x1314, 0x42bb, 0xe5fe, 0xc3be, 0x1389, 0xf39f, 0xd575, 0x3648,
-0x1e47, 0xf2fa, 0x3e74, 0x234a, 0xbf4c, 0xf288, 0x221b, 0xc710, 0xfa3c, 0x5035,
-0xfb9e, 0x0502, 0x44eb, 0xeee6, 0xc43e, 0x1d61, 0xfb1c, 0xc9de, 0x3c74, 0x2aae,
-0xe190, 0x3674, 0x2619, 0xaff2, 0xe8b6, 0x2937, 0xc78c, 0xf5df, 0x540b, 0xfb05,
-0x020b, 0x434b, 0xe0e6, 0xacc1, 0x10fc, 0xf91d, 0xbcee, 0x3592, 0x3566, 0xe36e,
-0x337d, 0x30bf, 0xb32f, 0xd426, 0x2162, 0xc820, 0xe042, 0x4c56, 0xfe46, 0xf61f,
-0x4a89, 0xf803, 0xad4d, 0x11a6, 0x0a6c, 0xb6d1, 0x253a, 0x3311, 0xd5a0, 0x2667,
-0x3498, 0xb800, 0xd872, 0x2f83, 0xd41e, 0xe4e1, 0x5463, 0xf738, 0xea30, 0x492c,
-0xf007, 0xaab2, 0x16ec, 0x11da, 0xc262, 0x2e37, 0x3e3b, 0xdd03, 0x22dd, 0x30e8,
-0xb674, 0xd170, 0x2e2c, 0xdcd6, 0xe399, 0x56b9, 0x04f1, 0xea52, 0x4a44, 0xfd31,
-0xa60d, 0x09bf, 0x162d, 0xbcc9, 0x1f55, 0x4352, 0xde68, 0x1cd9, 0x3c0d, 0xbf98,
-0xc8d8, 0x2a1f, 0xdc64, 0xd503, 0x4d6c, 0x0785, 0xe7a8, 0x476e, 0xff01, 0xa5cd,
-0x064f, 0x17bf, 0xbe55, 0x1800, 0x3b7b, 0xd4d9, 0x10f0, 0x3690, 0xbf8d, 0xc71e,
-0x297a, 0xe393, 0xd729, 0x47fe, 0x0285, 0xda51, 0x391b, 0xfeb3, 0xa48e, 0xfbc3,
-0x19a9, 0xc3a0, 0x108e, 0x3eae, 0xdebc, 0x0f12, 0x36a2, 0xc4c0, 0xbf91, 0x1e2f,
-0xe5de, 0xd395, 0x4354, 0x10d5, 0xe319, 0x39c0, 0x0a87, 0xace4, 0xf7d2, 0x18b7,
-0xc582, 0x0b6f, 0x3da5, 0xe290, 0x0dde, 0x3c3e, 0xcfe6, 0xc55b, 0x253d, 0xeca1,
-0xcf94, 0x3b7a, 0x0f41, 0xdf74, 0x366b, 0x1370, 0xb644, 0xfb14, 0x1f1e, 0xc7c9,
-0x07b4, 0x41e9, 0xe70d, 0x071d, 0x3d77, 0xdb66, 0xc478, 0x265f, 0xf916, 0xd180,
-0x3ee6, 0x1beb, 0xdeb9, 0x31d9, 0x191a, 0xb479, 0xf52c, 0x2801, 0xccf7, 0x03d4,
-0x4bd7, 0xedac, 0x016a, 0x3a65, 0xd6fc, 0xbe27, 0x2266, 0x07f4, 0xd0c6, 0x0dcf,
-0x1281, 0x0eb0, 0x45e8, 0x1d9a, 0xd8e3, 0x05c1, 0x084a, 0xb5be, 0xdaec, 0x09a2,
-0xe1b9, 0x11ee, 0x6086, 0x43d5, 0x17db, 0x2892, 0xfb50, 0xb60e, 0xc9f7, 0xc054,
-0xc68d, 0x23e0, 0x2ffe, 0x062b, 0x4e99, 0x701f, 0xf80e, 0xd329, 0xff2c, 0xcb90,
-0xa2d6, 0xed8c, 0x1910, 0x0699, 0x2f80, 0x3089, 0x1d1c, 0x374f, 0x03b2, 0xc14c,
-0xd8b6, 0xfb3d, 0xd617, 0xe1a7, 0x22a2, 0x2021, 0x1a55, 0x1dcb, 0x2025, 0x150c,
-0x0753, 0xe11c, 0xb5ad, 0xeb4f, 0xe450, 0xcc01, 0x1b1d, 0x3faa, 0x18aa, 0x0e6d,
-0x4970, 0x17e5, 0xcba3, 0xd80b, 0xbb23, 0xc5d9, 0xe755, 0xf01c, 0x158e, 0x5028,
-0x3e7d, 0xfcdb, 0x3482, 0x21eb, 0xbae5, 0xbfbe, 0xd2fb, 0xcfc4, 0xd821, 0x0aca,
-0x27bb, 0x3924, 0x3d1e, 0x0e86, 0x271a, 0x205b, 0xd16c, 0xaf53, 0xc9df, 0xe377,
-0xce6f, 0xfa21, 0x34f1, 0x4083, 0x3410, 0x259d, 0x319d, 0x06b6, 0xd9dc, 0xb750,
-0xb2df, 0xde42, 0xd8e4, 0xfe96, 0x4970, 0x54f6, 0x25ba, 0x2520, 0x3c2e, 0xedea,
-0xc061, 0xba0d, 0xba48, 0xde9c, 0xeb84, 0x0af2, 0x401e, 0x56b2, 0x1aa5, 0x0f66,
-0x36cf, 0xe844, 0xb80e, 0xc1dd, 0xc246, 0xcece, 0xe9fe, 0x177a, 0x32d2, 0x4547,
-0x1818, 0x0c52, 0x30b6, 0xec12, 0xaf1a, 0xb2f2, 0xcfa8, 0xd2b1, 0xdf9e, 0x2116,
-0x3ab2, 0x35ab, 0x1b48, 0x247c, 0x25e1, 0xdedd, 0xb1e5, 0xaf2b, 0xdb4a, 0xe17b,
-0xdfc7, 0x27da, 0x4f71, 0x34be, 0x0ed1, 0x2d58, 0x1ef5, 0xd091, 0xc1bb, 0xbe47,
-0xd524, 0xeaee, 0xf469, 0x2112, 0x4cf4, 0x3d3e, 0x0aff, 0x304c, 0x281a, 0xcdc7,
-0xbbed, 0xd088, 0xe04a, 0xdeea, 0xfee9, 0x2f94, 0x47fc, 0x3dff, 0x1a27, 0x31e9,
-0x1deb, 0xd894, 0xbec6, 0xc6e8, 0xe5fc, 0xe340, 0x014d, 0x3cd1, 0x4e2f, 0x32bd,
-0x1d0c, 0x372e, 0x0af1, 0xce88, 0xc502, 0xc97d, 0xe495, 0xeb9c, 0x0798, 0x374a,
-0x4e4d, 0x2a7e, 0x16b3, 0x3ddd, 0x08ed, 0xc949, 0xc5ee, 0xce08, 0xdf28, 0xe8b7,
-0x0fe9, 0x3689, 0x490a, 0x2817, 0x1714, 0x38c1, 0x0109, 0xc527, 0xc1af, 0xd087,
-0xdced, 0xe41e, 0x12dc, 0x3476, 0x3cd2, 0x201b, 0x1cbb, 0x2e40, 0xf269, 0xc5fe,
-0xb844, 0xcaac, 0xdf7f, 0xe02f, 0x0f09, 0x373a, 0x383b, 0x13eb, 0x21ef, 0x2cbc,
-0xe41a, 0xc568, 0xb82e, 0xc319, 0xdca2, 0xe63b, 0x0f93, 0x3ca2, 0x4202, 0x11af,
-0x2392, 0x2ac6, 0xd906, 0xb7d3, 0xb715, 0xce35, 0xdb89, 0xef49, 0x2213, 0x3ff6,
-0x3f4b, 0x14d9, 0x2398, 0x1f27, 0xd7ab, 0xb866, 0xb50a, 0xd74b, 0xe11e, 0xf58b,
-0x2ece, 0x467f, 0x3963, 0x1933, 0x2caa, 0x1426, 0xd5d8, 0xbe81, 0xb620, 0xdf76,
-0xe789, 0xf65e, 0x349f, 0x505c, 0x3366, 0x16ea, 0x3646, 0x0f5a, 0xd18a, 0xc1b2,
-0xb7f7, 0xdd2a, 0xeb2f, 0xfd79, 0x30f5, 0x516e, 0x31d6, 0x12af, 0x388a, 0x0be7,
-0xca82, 0xbdf0, 0xbc89, 0xda3c, 0xe687, 0x06e8, 0x3695, 0x5204, 0x3323, 0x158c,
-0x3447, 0x05f1, 0xca02, 0xb88d, 0xc1cf, 0xe381, 0xea5c, 0x110d, 0x40c6, 0x4e27,
-0x2a69, 0x1e8c, 0x30b5, 0xf349, 0xc5eb, 0xb6f0, 0xc440, 0xe7cd, 0xebf2, 0x1281,
-0x4308, 0x4ce7, 0x1f25, 0x1bf5, 0x2d5c, 0xe897, 0xc291, 0xb85f, 0xc6be, 0xe556,
-0xf257, 0x1cc0, 0x442d, 0x4d14, 0x200a, 0x1f36, 0x26a6, 0xdf96, 0xbef2, 0xb898,
-0xd0e1, 0xe9a1, 0xf513, 0x2536, 0x486a, 0x4666, 0x1bd4, 0x216e, 0x1a61, 0xd966,
-0xbfd6, 0xb46f, 0xd414, 0xeb0f, 0xf5c1, 0x2917, 0x4b03, 0x3b01, 0x120a, 0x279d,
-0x127b, 0xce60, 0xc0b2, 0xbaa1, 0xd93a, 0xea16, 0xf79d, 0x29e1, 0x4e28, 0x3952,
-0x0c9b, 0x2918, 0x0da3, 0xc8e3, 0xbf5d, 0xbd5b, 0xd7be, 0xe6b5, 0xff78, 0x2bfe,
-0x474e, 0x30ea, 0x0afb, 0x2996, 0x09da, 0xc618, 0xb66b, 0xc002, 0xde8f, 0xe009,
-0x0068, 0x34b1, 0x479e, 0x290d, 0x1057, 0x2cf4, 0x0037, 0xc901, 0xba19, 0xc161,
-0xe4c1, 0xe626, 0x06b7, 0x3bce, 0x46e6, 0x1fc6, 0x1c43, 0x37dd, 0xf4a3, 0xc6e9,
-0xc0da, 0xc57a, 0xe45d, 0xe96e, 0x0b68, 0x3e09, 0x4c53, 0x1c9e, 0x1978, 0x350c,
-0xec82, 0xc2fd, 0xc069, 0xc683, 0xdf64, 0xee42, 0x1619, 0x39da, 0x4685, 0x1dc8,
-0x1c78, 0x2de4, 0xe52f, 0xbb56, 0xb88c, 0xd10f, 0xe424, 0xed39, 0x226e, 0x45c9,
-0x4373, 0x1798, 0x1d16, 0x2213, 0xe050, 0xbf9c, 0xb315, 0xd32f, 0xe7c5, 0xec31,
-0x23d2, 0x48dd, 0x38f4, 0x0de0, 0x25fc, 0x1996, 0xcef8, 0xbc82, 0xb55a, 0xd59c,
-0xe89f, 0xefe0, 0x23a4, 0x4993, 0x37a4, 0x0c32, 0x2be5, 0x17d1, 0xcddd, 0xc07a,
-0xb8e9, 0xd329, 0xe54b, 0xfb4e, 0x2cfc, 0x4d3a, 0x3bad, 0x0fee, 0x2b2b, 0x1047,
-0xc712, 0xb4f7, 0xbbf0, 0xdc5f, 0xe2f3, 0xfef6, 0x224e, 0x4c36, 0x6c76, 0x2b5c,
-0xfa57, 0xe594, 0xbdb1, 0x8b0a, 0xa7ca, 0x0160, 0x0786, 0x400c, 0x8424, 0x5796,
-0x1be9, 0xf540, 0xbdf9, 0x9768, 0xc4df, 0xbd3d, 0xdd3d, 0x63d3, 0x4e65, 0x1fea,
-0x4e57, 0x38bb, 0xd91b, 0xcd56, 0xe3ad, 0xbffd, 0xfbd6, 0x0607, 0xdb8e, 0x3ccb,
-0x4192, 0xd6b0, 0xf73b, 0x42bf, 0xeff1, 0xe330, 0x3dbd, 0xfa84, 0xdccf, 0x13df,
-0xde74, 0xb718, 0x0b45, 0x28d2, 0xfb25, 0x3fa0, 0x4276, 0xedb2, 0x1335, 0x0954,
-0xadc9, 0xc6fc, 0x1522, 0xf53c, 0xfe45, 0x4b87, 0x18e7, 0x04a7, 0x3412, 0xee3f,
-0xb321, 0xfd48, 0x04c9, 0xc508, 0x15a8, 0x372c, 0xeb2f, 0x165c, 0x2ca0, 0xce55,
-0xd34d, 0x1c95, 0xe2fd, 0xdd7e, 0x3294, 0xf905, 0xe452, 0x34a4, 0x04d0, 0xbdd7,
-0x0a01, 0x1d14, 0xce45, 0x0c02, 0x2888, 0xd716, 0x03dc, 0x2b4a, 0xd5cd, 0xd68c,
-0x2ef2, 0xfc10, 0xda6f, 0x316f, 0x0773, 0xda8e, 0x2215, 0x0507, 0xb6f3, 0xfe70,
-0x2a5d, 0xd6c8, 0x0b84, 0x4188, 0xe8c4, 0xfdd0, 0x2ec5, 0xd794, 0xc3a2, 0x2279,
-0xf779, 0xd09d, 0x423d, 0x27fc, 0xe6f8, 0x2f40, 0x1b5a, 0xbc8b, 0xf157, 0x1fb4,
-0xcaa0, 0xfa3a, 0x4232, 0xf922, 0x0ecb, 0x3f09, 0xe3ee, 0xc318, 0x1cef, 0xfdc1,
-0xca4c, 0x2a22, 0x20f1, 0xe87d, 0x279c, 0x1afc, 0xbe72, 0xe720, 0x2220, 0xd1d4,
-0xf6a7, 0x4e3e, 0xf5f4, 0xecca, 0x3b54, 0xf567, 0xb06f, 0x0a45, 0x0b98, 0xc973,
-0x28f0, 0x2f21, 0xdfeb, 0x24a0, 0x2810, 0xaef4, 0xd207, 0x2ab3, 0xcd51, 0xdc82,
-0x4ca3, 0xfdde, 0xef82, 0x40ab, 0xf143, 0xac33, 0x082b, 0xfdac, 0xb9b7, 0x28f3,
-0x2b71, 0xd054, 0x2723, 0x3651, 0xb6cf, 0xd176, 0x2ba8, 0xd75d, 0xdb92, 0x450f,
-0xfd8f, 0xec9c, 0x3e23, 0xf598, 0xaf02, 0x111a, 0x135a, 0xbd2d, 0x2334, 0x3d0a,
-0xd3d8, 0x1768, 0x3bb0, 0xbab9, 0xc676, 0x311a, 0xe06f, 0xd889, 0x5018, 0x070b,
-0xe756, 0x4942, 0xfd09, 0x9d71, 0x0bcc, 0x1bed, 0xb4ce, 0x1c66, 0x47ec, 0xdc5f,
-0x1b74, 0x4238, 0xc481, 0xcf1b, 0x32f5, 0xe1ce, 0xda85, 0x4e4d, 0x0437, 0xe474,
-0x4777, 0x07ed, 0xaff9, 0x127d, 0x24cd, 0xc370, 0x199d, 0x3e29, 0xd8bf, 0x14fd,
-0x3d8b, 0xc8ea, 0xd1b6, 0x3766, 0xecd3, 0xda6f, 0x4fa7, 0x0ce7, 0xdddd, 0x4019,
-0x0c05, 0xaedb, 0x0dbc, 0x2b4c, 0xcdd3, 0x1ddc, 0x470d, 0xe283, 0x1764, 0x40d4,
-0xcabb, 0xcd66, 0x3585, 0xf1c2, 0xdda9, 0x4ffb, 0x11e4, 0xe28a, 0x415d, 0x12d2,
-0xb486, 0x055e, 0x1fd4, 0xc66e, 0x12ca, 0x417e, 0xe4e2, 0x1229, 0x3e2a, 0xd10c,
-0xc800, 0x29e0, 0xed4e, 0xd10c, 0x3fcc, 0x11a3, 0xe1f9, 0x3ad7, 0x16ca, 0xb727,
-0x0155, 0x2400, 0xc8c6, 0x0c22, 0x40bf, 0xe1dc, 0x06e9, 0x3e89, 0xd924, 0xc59a,
-0x27a2, 0xf22c, 0xcfad, 0x3f51, 0x14cd, 0xda51, 0x2f15, 0x1235, 0xae68, 0xedef,
-0x1983, 0xc602, 0x06d9, 0x46e6, 0xe9de, 0x01cd, 0x3928, 0xd470, 0xb512, 0x15ff,
-0xec31, 0xc9cd, 0x3f78, 0x243a, 0xe15e, 0x29ed, 0x1245, 0xaba1, 0xe5e9, 0x199e,
-0xc296, 0xfe39, 0x4ac5, 0xeb5f, 0xfa56, 0x3c11, 0xd94f, 0xae50, 0x1511, 0xf001,
-0xbde3, 0x36c2, 0x230d, 0xd7fe, 0x2c17, 0x1e3a, 0xaa06, 0xe31f, 0x226e, 0xc144,
-0xf626, 0x4f4e, 0xeb1e, 0xf4dd, 0x3e8c, 0xdc0a, 0xaf47, 0x1e56, 0xfed8, 0xc48e,
-0x3d56, 0x2b0f, 0xd682, 0x2918, 0x1dec, 0xa955, 0xe5bb, 0x2b6b, 0xc9b8, 0xfa77,
-0x56f8, 0xf481, 0xfb61, 0x4479, 0xdf2e, 0xabca, 0x1c70, 0xffe7, 0xbc88, 0x3a59,
-0x3826, 0xe054, 0x2f4b, 0x2c11, 0xb1dd, 0xe03e, 0x2b29, 0xc998, 0xf18d, 0x59ee,
-0xf7ac, 0xf73d, 0x4d8e, 0xed67, 0xb1d8, 0x21a9, 0x1848, 0xccda, 0x07a8, 0xffcd,
-0xfa23, 0x5aea, 0x3797, 0xd62f, 0x0ab0, 0x245e, 0xb225, 0xc27c, 0x09d2, 0xd863,
-0xfe56, 0x5bb6, 0x4ddb, 0x2aa0, 0x3bda, 0x0b4a, 0xc172, 0xdcc2, 0xc178, 0xb04a,
-0x211f, 0x3a69, 0xf99a, 0x3316, 0x7dfa, 0x1afe, 0xd954, 0x046d, 0xdf49, 0xb051,
-0xdb3e, 0x09de, 0x0f9f, 0x347e, 0x2f84, 0x0af2, 0x3895, 0x1ade, 0xc5b6, 0xd468,
-0xfe63, 0xe6d0, 0xddae, 0x14b5, 0x175e, 0x16c3, 0x1fae, 0x122e, 0x1fcb, 0x16f5,
-0xef7f, 0xbe99, 0xdd8a, 0xf61b, 0xc6ce, 0x019a, 0x43c3, 0x2909, 0x1168, 0x39ad,
-0x2f76, 0xde14, 0xddd2, 0xc963, 0xbd2a, 0xea45, 0xea62, 0x0266, 0x4616, 0x4e1c,
-0x015e, 0x18de, 0x36f6, 0xcf20, 0xb656, 0xd210, 0xd017, 0xd8b3, 0xfb2f, 0x1950,
-0x2b27, 0x3c69, 0x095e, 0x0ec5, 0x2d9c, 0xe85e, 0xb75b, 0xc4ac, 0xe1a3, 0xcfe0,
-0xdf2a, 0x1a10, 0x3183, 0x376b, 0x1d4c, 0x237d, 0x185c, 0xe4f3, 0xbf7b, 0xab18,
-0xcfc2, 0xd346, 0xe11c, 0x2903, 0x45ea, 0x24aa, 0x102b, 0x353d, 0x080f, 0xc677,
-0xbdeb, 0xb32e, 0xd477, 0xe331, 0xef66, 0x2325, 0x4c5c, 0x27b3, 0xfaf5, 0x3106,
-0x1252, 0xc709, 0xca81, 0xcbe5, 0xd04d, 0xdd4e, 0xfd3c, 0x1a5f, 0x3c21, 0x2935,
-0x0252, 0x3750, 0x1e8e, 0xc8e4, 0xb83e, 0xd48f, 0xdc6e, 0xce04, 0x0585, 0x31bc,
-0x360a, 0x2009, 0x14c2, 0x394e, 0x10a3, 0xc93d, 0xafa5, 0xd6b1, 0xef04, 0xcd94,
-0x0467, 0x48be, 0x4051, 0x1437, 0x1fb5, 0x3cd3, 0xf79e, 0xcc8f, 0xc153, 0xcd1f,
-0xeeb7, 0xe37c, 0x03cf, 0x4174, 0x4958, 0x1000, 0x1d3b, 0x4853, 0xf289, 0xbea9,
-0xc9e2, 0xd4e7, 0xde7b, 0xe633, 0x1461, 0x3e75, 0x4911, 0x1b5a, 0x2106, 0x4059,
-0xf467, 0xbf92, 0xc1f8, 0xd995, 0xdcf6, 0xe0ba, 0x1eb5, 0x4600, 0x4167, 0x1d25,
-0x2ef9, 0x3639, 0xe56b, 0xc105, 0xc027, 0xd70a, 0xe1eb, 0xea01, 0x247e, 0x4c66,
-0x3f10, 0x14c8, 0x3245, 0x3094, 0xdd32, 0xc132, 0xc147, 0xd9a1, 0xe18c, 0xeeb8,
-0x2824, 0x4a69, 0x395c, 0x1015, 0x3040, 0x238d, 0xd48a, 0xc21b, 0xc53b, 0xdc6d,
-0xe1ce, 0xf6ef, 0x2ad6, 0x46b7, 0x34da, 0x1114, 0x34eb, 0x1e8c, 0xd361, 0xbe8c,
-0xc1c6, 0xe012, 0xdf71, 0xf81f, 0x3359, 0x4a06, 0x2d71, 0x1454, 0x38da, 0x0f58,
-0xccf4, 0xbea1, 0xbbb5, 0xdb25, 0xe2c4, 0xfd77, 0x3627, 0x5121, 0x2c35, 0x15a0,
-0x3989, 0x0018, 0xc03f, 0xbaf5, 0xc3cd, 0xe02b, 0xe6c9, 0x0e3d, 0x3eb5, 0x4d58,
-0x26cb, 0x1318, 0x2fe0, 0xf891, 0xc27d, 0xb828, 0xc71e, 0xe21d, 0xe699, 0x15c5,
-0x4058, 0x45ef, 0x2262, 0x1985, 0x28bc, 0xeca7, 0xc32c, 0xb7e4, 0xcfc1, 0xea07,
-0xe4ac, 0x173a, 0x461c, 0x3eba, 0x15fa, 0x2087, 0x2703, 0xe29a, 0xc4b3, 0xb600,
-0xc8f7, 0xe687, 0xe9ba, 0x15c4, 0x426b, 0x3e74, 0x0edd, 0x1f75, 0x23b8, 0xd925,
-0xc0ab, 0xba1f, 0xcb2d, 0xe095, 0xeca2, 0x1990, 0x40e5, 0x3c5d, 0x1023, 0x24d2,
-0x1ebd, 0xd280, 0xbab7, 0xba30, 0xd226, 0xe0d0, 0xf39a, 0x22d6, 0x4063, 0x34fc,
-0x0f3b, 0x2825, 0x190f, 0xd310, 0xbcd9, 0xbd2e, 0xd80b, 0xdd5a, 0xf3ce, 0x2b22,
-0x4783, 0x32fb, 0x13a4, 0x3361, 0x1484, 0xcf84, 0xc067, 0xc184, 0xdb6a, 0xe3e8,
-0x0230, 0x3122, 0x4768, 0x320a, 0x16c1, 0x3427, 0x0aed, 0xc9bb, 0xba81, 0xc328,
-0xe12c, 0xe1e3, 0x07e1, 0x3ec1, 0x4f67, 0x2ddc, 0x15f0, 0x2f32, 0xfe24, 0xc964,
-0xbbfd, 0xc754, 0xe848, 0xe9ef, 0x1196, 0x41b3, 0x4b5f, 0x2760, 0x1f91, 0x35ce,
-0xf3d5, 0xc722, 0xbfad, 0xcade, 0xe85a, 0xeaa5, 0x1660, 0x4809, 0x4c60, 0x1f11,
-0x212f, 0x36b0, 0xefd1, 0xc764, 0xbc28, 0xc837, 0xe455, 0xec50, 0x1c88, 0x4b3c,
-0x4de3, 0x2041, 0x28c6, 0x32d7, 0xe1ea, 0xbea7, 0xbd29, 0xd1a9, 0xe60c, 0xf02d,
-0x2433, 0x4c51, 0x4811, 0x1816, 0x23ce, 0x292b, 0xdf35, 0xbcec, 0xb6b3, 0xd50d,
-0xe49a, 0xee6a, 0x2b0c, 0x4b27, 0x39f9, 0x15f5, 0x29d8, 0x1859, 0xd36e, 0xc04c,
-0xb5ab, 0xd4b0, 0xe461, 0xec0c, 0x2803, 0x4fb2, 0x371f, 0x0f49, 0x2de8, 0x1063,
-0xc7dd, 0xbbcc, 0xb195, 0xcdad, 0xe2b5, 0xf6ed, 0x29d0, 0x4ac5, 0x31e4, 0x0aa9,
-0x2acb, 0x0735, 0xbe72, 0xb39c, 0xb620, 0xd1d9, 0xdc5c, 0xfcdd, 0x307a, 0x46be,
-0x2c7c, 0x0a2b, 0x22ab, 0xfca8, 0xc0ac, 0xafc4, 0xb815, 0xde74, 0xe13f, 0x0269,
-0x370e, 0x4107, 0x21c4, 0x13c8, 0x26a3, 0xf061, 0xc3ac, 0xb5ad, 0xbbea, 0xe2b6,
-0xe314, 0x03cd, 0x3a8a, 0x453e, 0x1c0b, 0x167a, 0x2afd, 0xe8ae, 0xc330, 0xbb1d,
-0xbd71, 0xdff6, 0xea8c, 0x0cd6, 0x3cc1, 0x4b59, 0x1e08, 0x1762, 0x288a, 0xe327,
-0xbcf5, 0xbc04, 0xcc41, 0xe3b8, 0xf214, 0x1f63, 0x40b7, 0x4556, 0x1932, 0x14e9,
-0x22d4, 0xe5af, 0xc176, 0xbaf1, 0xd516, 0xeaa3, 0xed1a, 0x10a5, 0x4490, 0x6d0e,
-0x387d, 0x06ad, 0xf979, 0xc011, 0x9e3c, 0xad92, 0xe582, 0x1234, 0x4531, 0x6a71,
-0x4d3b, 0x3443, 0xfe14, 0xbf35, 0xb76f, 0xcbe7, 0xc8b4, 0xe9aa, 0x501f, 0x43d8,
-0x1d18, 0x4560, 0x2e0d, 0xf4de, 0xea75, 0xe7b7, 0xd73f, 0x0fdc, 0x11cd, 0xd145,
-0x29c3, 0x44d4, 0xdad6, 0xf4f0, 0x3e51, 0x092e, 0x07b6, 0x43ce, 0xfd5a, 0xf591,
-0x1f19, 0xc2ea, 0xb2d7, 0x198e, 0x140f, 0xfa53, 0x5e12, 0x4564, 0xf1ae, 0x2e33,
-0x0b49, 0xa4bb, 0xdaed, 0x1485, 0xdc90, 0x0cbf, 0x4f0d, 0x0854, 0x15b5, 0x3b75,
-0xe6b5, 0xbe4e, 0x0981, 0xfc23, 0xc6c6, 0x22a2, 0x2984, 0xf1db, 0x27f9, 0x1ab0,
-0xc60e, 0xe49e, 0x21a8, 0xd681, 0xe953, 0x41f4, 0xf337, 0xeb9d, 0x3560, 0xf514,
-0xbd12, 0x135a, 0x1144, 0xc99f, 0x21e0, 0x2271, 0xd155, 0x1a35, 0x25a3, 0xbec7,
-0xdc7d, 0x31ed, 0xe802, 0xe46d, 0x3ef6, 0xfc72, 0xeb7d, 0x2fc5, 0xecf1, 0xb132,
-0x0d6d, 0x171d, 0xcaf3, 0x20be, 0x36cd, 0xdeff, 0x1430, 0x2c97, 0xc49c, 0xcab8,
-0x247c, 0xe2b5, 0xd3f1, 0x3d93, 0x0c22, 0xee37, 0x3907, 0x01ea, 0xb32c, 0x07e5,
-0x153f, 0xb7d0, 0x0a61, 0x333d, 0xdb8a, 0x1138, 0x3892, 0xcfca, 0xccd1, 0x2831,
-0xeb12, 0xd73f, 0x357e, 0xfe1d, 0xe21b, 0x300a, 0xfded, 0xaf91, 0xffaf, 0x1ba1,
-0xc5b1, 0x0c52, 0x3c73, 0xe33f, 0xfac8, 0x2338, 0xd7bc, 0xc7f4, 0x0f99, 0xe739,
-0xd9e0, 0x3980, 0x0e6d, 0xe382, 0x335e, 0x15f9, 0xae82, 0xe698, 0x1c86, 0xca1d,
-0xf6f1, 0x34d2, 0xf14d, 0x0fec, 0x3c9a, 0xdef1, 0xc8df, 0x20f3, 0xea68, 0xc50a,
-0x33ef, 0x1185, 0xd7d4, 0x2ebc, 0x2178, 0xc1c1, 0xf72b, 0x2354, 0xd2eb, 0x0168,
-0x30db, 0xe0a6, 0x05a6, 0x3bad, 0xdc09, 0xc45f, 0x276d, 0xfd11, 0xcf0a, 0x363e,
-0x204b, 0xe4d0, 0x2851, 0x199c, 0xbc3c, 0xe9df, 0x1c38, 0xcf05, 0x03b3, 0x4c0e,
-0xf6ee, 0x068d, 0x44a0, 0xe3e0, 0xb163, 0x17fa, 0xfdee, 0xc709, 0x37cd, 0x2e63,
-0xea1c, 0x3531, 0x2ca0, 0xbf9e, 0xeeec, 0x2b06, 0xc5f7, 0xf1c8, 0x5385, 0xfc84,
-0x0002, 0x49cb, 0xf52b, 0xbfbf, 0x204d, 0x04c6, 0xc649, 0x35e9, 0x30b9, 0xe658,
-0x31b2, 0x2cb7, 0xb96b, 0xe5a8, 0x2f24, 0xd410, 0xf6ab, 0x5771, 0x04b9, 0xfc36,
-0x3ec2, 0xecd7, 0xb28a, 0x1904, 0x0954, 0xc24d, 0x3764, 0x3ade, 0xddf2, 0x29ce,
-0x3445, 0xb4d5, 0xd352, 0x2d79, 0xd037, 0xe09a, 0x535a, 0x01a5, 0xf095, 0x48ef,
-0xf767, 0xa8aa, 0x11b3, 0x097b, 0xb15c, 0x2a36, 0x3db4, 0xd6cd, 0x24b8, 0x3712,
-0xb430, 0xcdb4, 0x2b60, 0xd3aa, 0xe09b, 0x53eb, 0xfc4a, 0xea6b, 0x4b2a, 0xf90e,
-0xa8c8, 0x1124, 0x129b, 0xbaac, 0x269d, 0x4030, 0xda96, 0x20e1, 0x3a2e, 0xbd1c,
-0xd0d8, 0x3158, 0xdd88, 0xdee5, 0x57dc, 0x0a22, 0xeb70, 0x4be8, 0x027e, 0xa602,
-0x0680, 0x1714, 0xbfed, 0x242e, 0x47b1, 0xe011, 0x1d8e, 0x3eca, 0xc029, 0xc616,
-0x2e06, 0xe28f, 0xd4aa, 0x4f9e, 0x0f06, 0xe649, 0x438d, 0x0564, 0xa6f1, 0x02f6,
-0x1bd3, 0xc020, 0x18b7, 0x4204, 0xd71b, 0x0fc8, 0x3e52, 0xc2b8, 0xbf78, 0x2bd7,
-0xe6d3, 0xce7b, 0x47d7, 0x0a5d, 0xd7d4, 0x39c7, 0x074e, 0xa273, 0xfc77, 0x1fef,
-0xbcf9, 0x0cec, 0x426a, 0xd4f2, 0x044f, 0x3d93, 0xc6ea, 0xbcdf, 0x2bd1, 0xed0b,
-0xce10, 0x43d0, 0x0ca2, 0xd5d2, 0x35c4, 0x0c15, 0xa646, 0xfa2d, 0x2097, 0xc0dd,
-0x0c2b, 0x439b, 0xdc9c, 0x059f, 0x3b30, 0xca4a, 0xbbcb, 0x2337, 0xe7a3, 0xc717,
-0x3dae, 0x1491, 0xdc09, 0x3229, 0x0f3e, 0xac38, 0xf62a, 0x25d7, 0xcda9, 0xe86a,
-0x0ccd, 0xe87d, 0x2a51, 0x46ee, 0xea42, 0xe40d, 0x22b1, 0xd631, 0xa84b, 0xf868,
-0xe4f9, 0xdc35, 0x395d, 0x50be, 0x1fd6, 0x25ac, 0x1e57, 0xc641, 0xc358, 0xd0f2,
-0xac56, 0xf1aa, 0x385d, 0x08e0, 0x0c0c, 0x6c90, 0x3d9a, 0xd534, 0xf575, 0xf32f,
-0xb660, 0xc715, 0x00c3, 0x060a, 0x1cc0, 0x3bee, 0x0fef, 0x2648, 0x390e, 0xe520,
-0xcaa4, 0xfc07, 0xfa8c, 0xcfc3, 0xff3b, 0x2146, 0x0eaa, 0x22f7, 0x21eb, 0x22a5,
-0x2b3f, 0x140f, 0xd035, 0xce0d, 0x018b, 0xcdfd, 0xe402, 0x4024, 0x35a0, 0x11b4,
-0x30f7, 0x48c6, 0xfc36, 0xe429, 0xd9e4, 0xb819, 0xe9ae, 0xecf6, 0xeaac, 0x339b,
-0x5af6, 0x18c2, 0x0a7d, 0x49f9, 0xfaf8, 0xba8d, 0xd5ae, 0xd0dc, 0xd43b, 0xee6d,
-0x117b, 0x23d1, 0x46ee, 0x29ad, 0x0339, 0x3a96, 0x1314, 0xc110, 0xbad0, 0xd9cf,
-0xd706, 0xcd74, 0x0d91, 0x315e, 0x3f9c, 0x359b, 0x2190, 0x2aef, 0x0433, 0xcdb2,
-0xa574, 0xc711, 0xe12e, 0xcf40, 0x197f, 0x5324, 0x3d77, 0x20a5, 0x375c, 0x2d03,
-0xe262, 0xca54, 0xb0b0, 0xc640, 0xed6e, 0xe3a9, 0x14a7, 0x559a, 0x4789, 0x0af5,
-0x2c0d, 0x3078, 0xd574, 0xc8f1, 0xc60c, 0xc4a3, 0xddbb, 0xf434, 0x12bf, 0x3a4f,
-0x46b5, 0x0de9, 0x28f8, 0x3a3e, 0xd862, 0xb36e, 0xc4b9, 0xd290, 0xcc9e, 0xf150,
-0x28e5, 0x36b7, 0x3727, 0x1942, 0x296a, 0x1f3b, 0xd304, 0xaa50, 0xb7e0, 0xe064,
-0xcd60, 0xe774, 0x36d2, 0x4354, 0x256f, 0x16b9, 0x32a9, 0x04e9, 0xc94b, 0xbd89,
-0xb4e8, 0xde63, 0xe6b3, 0xefc2, 0x2c99, 0x4d30, 0x244c, 0x0dd9, 0x4013, 0x0a25,
-0xbf81, 0xc647, 0xc8d3, 0xd098, 0xddd7, 0x0729, 0x2f46, 0x49fe, 0x3186, 0x11dd,
-0x33c9, 0x0a1a, 0xc455, 0xb4fe, 0xcbf9, 0xe01f, 0xd9c3, 0x0d63, 0x3ca9, 0x40e4,
-0x2597, 0x1f85, 0x2fee, 0xf6c7, 0xc763, 0xb733, 0xcbd2, 0xe734, 0xe337, 0x11ef,
-0x4379, 0x4377, 0x1865, 0x216c, 0x32c8, 0xee0c, 0xca47, 0xc04a, 0xd076, 0xe70b,
-0xebed, 0x16a9, 0x3f81, 0x44ae, 0x16f6, 0x2266, 0x31f0, 0xe6d6, 0xc30d, 0xc333,
-0xd87e, 0xe495, 0xf14b, 0x1f91, 0x3ab4, 0x3a37, 0x1822, 0x291b, 0x2bcf, 0xea2c,
-0xc762, 0xbf57, 0xdd08, 0xe181, 0xec7b, 0x28f2, 0x456d, 0x366d, 0x1d72, 0x3891,
-0x2266, 0xe229, 0xcd55, 0xbe26, 0xdad8, 0xe6b2, 0xf1ad, 0x2a59, 0x4ce7, 0x346f,
-0x18da, 0x3eb3, 0x1a5c, 0xd0e6, 0xc45c, 0xbfe1, 0xd4d3, 0xe11f, 0x014a, 0x2f81,
-0x4863, 0x3408, 0x1268, 0x31f4, 0x0ec8, 0xca3c, 0xb9fc, 0xc1dc, 0xdd52, 0xe093,
-0x05ff, 0x33c3, 0x43d7, 0x2da7, 0x1671, 0x2bf0, 0x0034, 0xc97d, 0xb0c3, 0xbe5e,
-0xe43b, 0xdb68, 0x0387, 0x3ae6, 0x3ee7, 0x1b43, 0x174b, 0x2d76, 0xf26e, 0xc68d,
-0xb289, 0xbb76, 0xe0fe, 0xde57, 0x0305, 0x3b0e, 0x44f7, 0x17e8, 0x1ae0, 0x2e9e,
-0xe6b9, 0xc23e, 0xb5b3, 0xbe35, 0xde8a, 0xe55c, 0x0e04, 0x3e2d, 0x4749, 0x1891,
-0x1cce, 0x2c46, 0xe31a, 0xbc10, 0xb2be, 0xc7d4, 0xe1b0, 0xec58, 0x1b5f, 0x42a4,
-0x4577, 0x18af, 0x206d, 0x2610, 0xe0cf, 0xbee7, 0xb63b, 0xd3ec, 0xe4ab, 0xed6c,
-0x253f, 0x4a99, 0x42a8, 0x18da, 0x2a90, 0x2130, 0xd967, 0xc013, 0xb623, 0xd3d0,
-0xe7d4, 0xf7c7, 0x2d1b, 0x4df4, 0x3dfe, 0x18d3, 0x2e94, 0x12e1, 0xceb7, 0xbc8b,
-0xb721, 0xd9e6, 0xe7b6, 0xfe42, 0x37c7, 0x5256, 0x3916, 0x14fa, 0x2b19, 0x0829,
-0xcbbc, 0xbc11, 0xba4e, 0xe0c8, 0xec3c, 0x04ba, 0x39d7, 0x4f48, 0x314f, 0x1b2a,
-0x320f, 0xfbd4, 0xc7ad, 0xbe46, 0xbcb0, 0xdfec, 0xea9d, 0x0a76, 0x3eae, 0x51ce,
-0x28b8, 0x15c7, 0x32b1, 0xf736, 0xc436, 0xbbe2, 0xc2bd, 0xe357, 0xecf4, 0x10c4,
-0x40f6, 0x524e, 0x25cd, 0x19ce, 0x301e, 0xec1e, 0xbc6a, 0xbace, 0xd1d8, 0xe825,
-0xec23, 0x1b1b, 0x4400, 0x482a, 0x1bce, 0x1896, 0x260d, 0xe7f6, 0xc325, 0xb5e4,
-0xd101, 0xeabf, 0xea0d, 0x1d52, 0x47b3, 0x3cf0, 0x1282, 0x235d, 0x2050, 0xd9ae,
-0xc4d9, 0xb970, 0xd086, 0xe87d, 0xea86, 0x1b23, 0x48b1, 0x3c02, 0x0e92, 0x2cb2,
-0x2472, 0xd2cb, 0xbff8, 0xbc43, 0xce22, 0xe2d3, 0xf745, 0x2364, 0x47bb, 0x3e11,
-0x1209, 0x2f53, 0x1fb0, 0xcfac, 0xba0d, 0xbeea, 0xd8e3, 0xde1c, 0xf854, 0x2f24,
-0x49ea, 0x387f, 0x14be, 0x2de7, 0x1304, 0xd01b, 0xb948, 0xbc56, 0xe0d1, 0xe484,
-0xff93, 0x3655, 0x488a, 0x2bf5, 0x16ba, 0x3637, 0x07aa, 0xcf32, 0xc24d, 0xc063,
-0xe449, 0xe713, 0x01e8, 0x3b25, 0x4f83, 0x26c5, 0x1640, 0x3ab8, 0xff8c, 0xc83c,
-0xbf7c, 0xc052, 0xdf32, 0xe807, 0x09ef, 0x390f, 0x4d01, 0x25f5, 0x19b1, 0x3685,
-0xf201, 0xbb2e, 0xb561, 0xc59a, 0xdeac, 0xe81d, 0x110d, 0x2f0d, 0x5faf, 0x5bc4,
-0x12fe, 0xf615, 0xda50, 0xa9ae, 0x886f, 0xcd18, 0x0718, 0x09f1, 0x5bb7, 0x7af7,
-0x3e15, 0x0a73, 0xe799, 0xa715, 0x9c71, 0xc971, 0xb0a1, 0x07a7, 0x6f82, 0x3163,
-0x2a82, 0x5398, 0x14c9, 0xbfc2, 0xd8b3, 0xd540, 0xc5ce, 0x0fda, 0xf099, 0xf1a7,
-0x518e, 0x1c60, 0xcd84, 0x19da, 0x35b8, 0xd346, 0x03a1, 0x377b, 0xdf14, 0xefc5,
-0x0c59, 0xc206, 0xc448, 0x2196, 0x11ee, 0xfe70, 0x4f48, 0x1fa8, 0xeb2d, 0x1d5b,
-0xeaf2, 0x9f51, 0xdaef, 0x10e0, 0xe2b8, 0x140e, 0x4a7c, 0x0548, 0x11c6, 0x2b5c,
-0xd063, 0xb9e9, 0x0c49, 0xee9f, 0xcd6b, 0x32da, 0x2204, 0xe702, 0x2c36, 0x195d,
-0xbc4d, 0xef56, 0x1ea6, 0xd1a8, 0xfb24, 0x33f8, 0xe2fa, 0xffb5, 0x3ccd, 0xe4cb,
-0xca25, 0x2563, 0x0355, 0xd2da, 0x2bb0, 0x137a, 0xd6ec, 0x2218, 0x1b95, 0xc3b7,
-0xf854, 0x3722, 0xe6e8, 0xf671, 0x3596, 0xec18, 0xf030, 0x2d9c, 0xe6e7, 0xc2e9,
-0x26d5, 0x1a49, 0xd733, 0x2bbd, 0x26a1, 0xdab2, 0x1ba0, 0x23f0, 0xc355, 0xe703,
-0x2bce, 0xdc49, 0xf190, 0x496d, 0xfc6e, 0xf386, 0x3dfc, 0xf7e9, 0xbcff, 0x1444,
-0x0996, 0xc579, 0x1fc6, 0x2a9c, 0xe722, 0x261f, 0x2af6, 0xc74c, 0xe3b8, 0x2a8b,
-0xe105, 0xe8c4, 0x3bef, 0xfd9f, 0xefc2, 0x313f, 0xf888, 0xbeed, 0x0f0d, 0x10ba,
-0xcf13, 0x2814, 0x3a0d, 0xdf51, 0x0dca, 0x2f8f, 0xccfa, 0xc831, 0x1d1f, 0xe940,
-0xe8cf, 0x4a93, 0x0d52, 0xef83, 0x3c76, 0xfaba, 0xa5dd, 0x0126, 0x112f, 0xbdc7,
-0x1a61, 0x422a, 0xe9fb, 0x1b1a, 0x3694, 0xc9c9, 0xce2b, 0x1ef2, 0xd732, 0xdc7b,
-0x46da, 0xff7f, 0xe9fc, 0x46e1, 0x05ac, 0xaeb6, 0x0663, 0x159d, 0xc012, 0x1316,
-0x34ba, 0xdd94, 0x12fd, 0x31f6, 0xc596, 0xcbff, 0x2ae2, 0xe4d5, 0xd6c1, 0x4927,
-0x0b3d, 0xdd77, 0x3926, 0x07d1, 0xa2d2, 0xfb2e, 0x211d, 0xc317, 0x1769, 0x4b14,
-0xe280, 0x1326, 0x411c, 0xc1e2, 0xbac5, 0x2cf6, 0xe603, 0xcb4b, 0x4ed8, 0x191b,
-0xe401, 0x458d, 0x1545, 0xac87, 0x005f, 0x1e4a, 0xba9b, 0x0cc0, 0x467e, 0xe1cf,
-0x11da, 0x478e, 0xd350, 0xc70d, 0x31c1, 0xf201, 0xce1e, 0x434c, 0x12d6, 0xdd0b,
-0x3986, 0x1337, 0xaf6d, 0x006c, 0x2ca7, 0xc8ff, 0x0c23, 0x4bde, 0xe11d, 0x0318,
-0x41ef, 0xd0e5, 0xbd29, 0x3042, 0xf8a0, 0xd014, 0x4ad2, 0x1b53, 0xda3d, 0x3aa3,
-0x14be, 0xa4bb, 0xf7a1, 0x2b27, 0xc43a, 0x0948, 0x507e, 0xe296, 0x0297, 0x45db,
-0xd510, 0xb990, 0x273a, 0xf430, 0xc750, 0x3f4c, 0x1a85, 0xdb6a, 0x3993, 0x1ab4,
-0xadf3, 0xf5f6, 0x280d, 0xc5fc, 0xfe8a, 0x4668, 0xe58d, 0x011c, 0x457a, 0xdfc7,
-0xbebe, 0x255e, 0xfae1, 0xcb02, 0x3a3a, 0x1b49, 0xd635, 0x2c90, 0x1a6d, 0xb0f1,
-0xf0b7, 0x2851, 0xcb11, 0xfd3b, 0x4815, 0xe902, 0xf73a, 0x3af3, 0xde3a, 0xb633,
-0x1a27, 0xfae7, 0xc8e7, 0x3373, 0x1efa, 0xdab3, 0x2af8, 0x1f54, 0xb3a4, 0xe5bd,
-0x2010, 0xc657, 0xef33, 0x4332, 0xf32a, 0xf8bc, 0x3a43, 0xe716, 0xb380, 0x1025,
-0xf94b, 0xbff8, 0x2cbe, 0x2722, 0xd958, 0x2238, 0x24de, 0xb4e0, 0xd8e0, 0x219f,
-0xcbf4, 0xec3e, 0x4cc4, 0xf5db, 0xee65, 0x3cb1, 0xe88f, 0xad6b, 0x15fb, 0x0312,
-0xbe65, 0x3207, 0x3441, 0xd731, 0x1ee6, 0x2923, 0xb321, 0xd7af, 0x26e1, 0xce3a,
-0xeb73, 0x52d6, 0xfb3a, 0xed11, 0x3fa2, 0xeb93, 0xa537, 0x0fde, 0x078b, 0xbcc7,
-0x2dd2, 0x39bf, 0xde73, 0x2216, 0x2ba5, 0xb204, 0xd113, 0x2873, 0xd059, 0xe433,
-0x5331, 0x00f5, 0xede6, 0x41c9, 0xf3f8, 0xaa8c, 0x0f24, 0x06be, 0xb5e6, 0x29e9,
-0x39f4, 0xda5d, 0x25b6, 0x2b84, 0xb07f, 0xd942, 0x36fe, 0xe8ec, 0xcdd1, 0x1733,
-0x0849, 0x1aa1, 0x4558, 0xfb48, 0xd3ef, 0x11bd, 0xef48, 0xb142, 0xf697, 0xfdea,
-0xd64a, 0x32a6, 0x6fed, 0x25f8, 0x0b17, 0x2a5c, 0xdff3, 0xaef4, 0xd4ec, 0xbcba,
-0xe25d, 0x44cb, 0x234b, 0x1321, 0x73ba, 0x4da9, 0xced4, 0xe817, 0x007f, 0xa908,
-0xb5df, 0x1df6, 0x1875, 0x0e2c, 0x3ec1, 0x2fcd, 0x272d, 0x2290, 0xe25c, 0xc07e,
-0xf134, 0xfb4d, 0xd6f2, 0x0ad3, 0x3447, 0x223c, 0x13f1, 0x2272, 0x269f, 0x025a,
-0x0161, 0xd722, 0xd224, 0x0308, 0xde38, 0xef78, 0x3c18, 0x42ed, 0x0555, 0x290a,
-0x5400, 0xe6be, 0xca2d, 0xdae9, 0xc68f, 0xd7d0, 0xf47c, 0x10ed, 0x3184, 0x5941,
-0x1cf6, 0x0891, 0x3a35, 0xeb6f, 0xae39, 0xc817, 0xe6f7, 0xd6ef, 0xebb0, 0x3372,
-0x35f1, 0x34dd, 0x1e90, 0x16f7, 0x21a1, 0xf074, 0xc287, 0xb8c4, 0xe82d, 0xe6eb,
-0xdb90, 0x1e19, 0x40af, 0x3208, 0x1a9a, 0x320f, 0x1b9a, 0xdeff, 0xcf46, 0xb4a3,
-0xcbd7, 0xdf68, 0xe59a, 0x22fe, 0x55b5, 0x3892, 0x0be2, 0x396b, 0x1a98, 0xc635,
-0xc146, 0xc092, 0xd361, 0xe7eb, 0x0383, 0x2879, 0x4c6a, 0x3c0d, 0x05ca, 0x2976,
-0x14a9, 0xc798, 0xc116, 0xd2d8, 0xdd50, 0xdcd3, 0x0b09, 0x2bce, 0x3653, 0x2ab8,
-0x0a52, 0x2aa9, 0x14b7, 0xd401, 0xb890, 0xcc60, 0xea88, 0xd5e4, 0xfe7d, 0x383b,
-0x3ade, 0x1b88, 0x1ad7, 0x3ed1, 0x075f, 0xcd9c, 0xbbc4, 0xcbe8, 0xeb85, 0xd822,
-0xfbc3, 0x3e44, 0x459b, 0x10ea, 0x17ee, 0x43df, 0xf7f9, 0xc0a0, 0xc419, 0xcf1f,
-0xdea4, 0xe05f, 0x0678, 0x330f, 0x42d4, 0x111c, 0x0fba, 0x3f57, 0xf9a8, 0xb669,
-0xbe1b, 0xe146, 0xdd9a, 0xd4be, 0x11a3, 0x389d, 0x37d6, 0x13b2, 0x1c70, 0x3370,
-0xf10c, 0xc063, 0xb6e6, 0xd48a, 0xdc66, 0xd809, 0x1789, 0x3f92, 0x3566, 0x0e0f,
-0x231e, 0x2ea3, 0xde28, 0xbb31, 0xba09, 0xcf05, 0xd866, 0xdfc8, 0x18f1, 0x3ecd,
-0x369b, 0x0a8f, 0x2386, 0x2af2, 0xda2a, 0xb79e, 0xb7d0, 0xd687, 0xde35, 0xe721,
-0x22ba, 0x4574, 0x3572, 0x0dd3, 0x2e06, 0x263b, 0xd7ab, 0xbfc7, 0xc2f6, 0xdf1b,
-0xe1c3, 0xf1d5, 0x2cb4, 0x4e1c, 0x37cd, 0x115d, 0x35cd, 0x1fe6, 0xd779, 0xc301,
-0xc58e, 0xe72d, 0xe5ce, 0xf960, 0x335a, 0x4fb4, 0x357b, 0x1898, 0x426e, 0x1cc2,
-0xd473, 0xc727, 0xc831, 0xe1fb, 0xe68f, 0x072e, 0x3da1, 0x58d4, 0x39ac, 0x1d25,
-0x4338, 0x1401, 0xcf2b, 0xbee6, 0xca41, 0xe875, 0xe64f, 0x1316, 0x4982, 0x5236,
-0x2f67, 0x2085, 0x38b8, 0xfd01, 0xc7c8, 0xba93, 0xc979, 0xebc7, 0xea26, 0x168d,
-0x477d, 0x4817, 0x212b, 0x1fdd, 0x335a, 0xef3e, 0xc484, 0xb895, 0xc9b8, 0xec42,
-0xe805, 0x136b, 0x4a61, 0x4971, 0x17b6, 0x1f6a, 0x2f97, 0xe4b1, 0xc086, 0xb999,
-0xcac9, 0xe5fd, 0xee0c, 0x1807, 0x412f, 0x460f, 0x166d, 0x1f4c, 0x29b3, 0xdc64,
-0xb965, 0xb861, 0xd211, 0xe147, 0xeb99, 0x2193, 0x450f, 0x3ce4, 0x113e, 0x1f63,
-0x1c84, 0xd769, 0xb874, 0xb487, 0xd682, 0xe1c9, 0xed74, 0x24b0, 0x43a4, 0x33ba,
-0x0e1c, 0x2413, 0x10f7, 0xcdd3, 0xb977, 0xb8d7, 0xdbc4, 0xe37c, 0xf175, 0x272e,
-0x457d, 0x2d0a, 0x07d0, 0x297e, 0x0f41, 0xca51, 0xb9f7, 0xbc9a, 0xdaa7, 0xddfe,
-0xf766, 0x2c64, 0x4532, 0x2d7b, 0x0dd9, 0x2cf4, 0x0c17, 0xc90f, 0xb4bc, 0xc07f,
-0xe270, 0xdce1, 0xfc63, 0x371a, 0x4749, 0x2579, 0x1187, 0x2dc1, 0xff1f, 0xc7eb,
-0xb7f0, 0xc150, 0xe209, 0xe0bb, 0x0562, 0x39a6, 0x419b, 0x18df, 0x11d0, 0x32b0,
-0xf640, 0xc162, 0xbaa8, 0xc92a, 0xe355, 0xdf42, 0x07ce, 0x3de6, 0x485f, 0x1a8d,
-0x15e0, 0x345d, 0xf2a7, 0xc2b4, 0xbc48, 0xcb43, 0xe331, 0xe771, 0x171d, 0x41c7,
-0x46e8, 0x1e6a, 0x1d99, 0x3169, 0xea47, 0xbb34, 0xb612, 0xcfe5, 0xe372, 0xe4f4,
-0x1dce, 0x4978, 0x4538, 0x1abb, 0x1ff9, 0x2726, 0xe2ee, 0xbf5a, 0xb642, 0xd6a7,
-0xeb65, 0xe981, 0x26c2, 0x5246, 0x3d0f, 0x142e, 0x2f6c, 0x28fc, 0xda88, 0xc3aa,
-0xbdbe, 0xd749, 0xeb54, 0xf1e0, 0x25cd, 0x526c, 0x41ba, 0x10bf, 0x2fe6, 0x2449,
-0xd374, 0xbfc4, 0xbbe2, 0xd283, 0xe25c, 0xf99f, 0x2cef, 0x4ac7, 0x3ddf, 0x17d9,
-0x3082, 0x1925, 0xce89, 0xb6a1, 0xbc50, 0xe283, 0xe474, 0xfd8d, 0x3bcc, 0x4e96,
-0x33c3, 0x167a, 0x2e47, 0x0a43, 0xcef1, 0xbc29, 0xba3d, 0xe1a3, 0xe5f7, 0xfe7c,
-0x39db, 0x4bea, 0x270e, 0x128b, 0x30de, 0xfb59, 0xc505, 0xbdab, 0xbd60, 0xe0c5,
-0xe64a, 0x0171, 0x35c3, 0x47fc, 0x21b5, 0x11b5, 0x30fa, 0xf4fc, 0xc06e, 0xbaa3,
-0xbc7a, 0xd83f, 0xe4e1, 0x0b66, 0x373d, 0x497a, 0x2421, 0x109c, 0x26f1, 0xecb6,
-0xbadf, 0xb11f, 0xc45d, 0xdf59, 0xe4b2, 0x1641, 0x3f59, 0x42bc, 0x1c1c, 0x129c,
-0x1bee, 0xe133, 0xbe64, 0xb1ad, 0xcc9f, 0xec32, 0xe986, 0x19ae, 0x44e5, 0x3a19,
-0x0e88, 0x1ade, 0x1f2c, 0xdec4, 0xc3cc, 0xb2ef, 0xdaab, 0xfd08, 0xe6a7, 0x1123,
-0x3704, 0x3898, 0x3ad4, 0x346f, 0xfe92, 0xd1d3, 0xcc04, 0x9cbd, 0xc135, 0x02eb,
-0xf63b, 0x365b, 0x8b58, 0x58ad, 0x0415, 0x0488, 0xcf1c, 0x8e64, 0xb611, 0xc2c4,
-0xeda1, 0x4ea8, 0x63da, 0x49bb, 0x50ec, 0x3618, 0xc859, 0xb818, 0xe010, 0xbc83,
-0xd14a, 0x1ad8, 0x32a9, 0x4030, 0x4434, 0x0f51, 0xf80f, 0x1895, 0xeaf8, 0xc48d,
-0x175a, 0x2702, 0xe895, 0x0fd2, 0x2756, 0xcf30, 0xdfad, 0x3a11, 0xfb80, 0xfa5f,
-0x565f, 0x121d, 0xf290, 0x2352, 0xddf3, 0xa5f4, 0xfe06, 0x187b, 0xde96, 0x3a13,
-0x5105, 0xf698, 0x255a, 0x212e, 0xb7a3, 0xc5a7, 0x10d7, 0xdeff, 0xe90b, 0x551a,
-0x1708, 0xfd81, 0x42e8, 0xf9ae, 0xb328, 0xf8c8, 0x0cd4, 0xc910, 0x1398, 0x3cf8,
-0xe89b, 0x1c9d, 0x36c1, 0xcb0b, 0xcca6, 0x2759, 0xf1e2, 0xd264, 0x3d80, 0x146d,
-0xe372, 0x36c2, 0x0ab3, 0xb2ef, 0x0a0e, 0x2e96, 0xc7be, 0x0dcf, 0x4ba5, 0xdcd8,
-0xff1f, 0x391f, 0xcf51, 0xc4c3, 0x314b, 0xfef3, 0xd680, 0x41c6, 0x156e, 0xdd3b,
-0x2eeb, 0x0886, 0xa9c9, 0xf3a6, 0x247e, 0xc927, 0x069f, 0x4a37, 0xe895, 0x0061,
-0x378e, 0xd6a1, 0xb348, 0x1688, 0xf810, 0xc498, 0x323f, 0x1fc5, 0xe066, 0x29b3,
-0x139d, 0xadbb, 0xe71a, 0x2c44, 0xcae3, 0xe8e1, 0x3f89, 0xe822, 0xf034, 0x367a,
-0xdf30, 0xb32c, 0x1aba, 0x0281, 0xcc1b, 0x36c4, 0x14ca, 0xc6d5, 0x2590, 0x1c08,
-0xa351, 0xd7ce, 0x2a74, 0xd59f, 0xf3fa, 0x477e, 0xf4e0, 0xf8ff, 0x3121, 0xdc01,
-0xb775, 0x150c, 0xfcd8, 0xcc0d, 0x38c8, 0x2ece, 0xe423, 0x2849, 0x29b5, 0xc302,
-0xda74, 0x1f47, 0xdd2f, 0xf247, 0x3ab2, 0xf2d7, 0x006a, 0x4787, 0xf2b8, 0xbc9f,
-0x1f1c, 0x0ac7, 0xbde9, 0x23df, 0x2b4d, 0xd869, 0x1cf2, 0x2e59, 0xc8ac, 0xe6ca,
-0x2cef, 0xd907, 0xf197, 0x4b23, 0xf20c, 0xef15, 0x4469, 0xf156, 0xb2a9, 0x1bfd,
-0x127b, 0xca28, 0x306d, 0x3438, 0xdf08, 0x20cf, 0x27a1, 0xb9c7, 0xd8d7, 0x2741,
-0xd309, 0xe588, 0x5056, 0x03d5, 0xef96, 0x4207, 0xfd8d, 0xae5f, 0x03b5, 0x0589,
-0xbd38, 0x23af, 0x3a76, 0xe095, 0x2023, 0x3839, 0xc165, 0xd4ca, 0x2de1, 0xd781,
-0xe09b, 0x50bd, 0x0340, 0xea0c, 0x4022, 0xf840, 0xad2c, 0x1331, 0x12e3, 0xc260,
-0x2f2a, 0x3b6c, 0xd12c, 0x18a4, 0x3197, 0xb77c, 0xd13d, 0x2bd2, 0xd972, 0xe616,
-0x52eb, 0x041e, 0xeb26, 0x3bdc, 0xf119, 0xa2b2, 0x06d5, 0x1049, 0xbd97, 0x289f,
-0x44ee, 0xdf14, 0x1d7f, 0x34ac, 0xb7bb, 0xc690, 0x278a, 0xda25, 0xdff9, 0x579a,
-0x080c, 0xe6ec, 0x4374, 0xfcbd, 0xa5be, 0x078c, 0x146b, 0xbb5b, 0x2164, 0x4262,
-0xdc47, 0x1e50, 0x39f8, 0xbce7, 0xcbb4, 0x2afe, 0xdc45, 0xdb5e, 0x5409, 0x0b3a,
-0xe53c, 0x4358, 0x02ae, 0xa896, 0x0857, 0x1af8, 0xc23a, 0x2352, 0x496b, 0xdfb5,
-0x197e, 0x3ce3, 0xbe54, 0xc506, 0x3012, 0xe677, 0xd704, 0x5217, 0x11ee, 0xe2e7,
-0x3fe4, 0x06fa, 0xa5a3, 0xfdcd, 0x181f, 0xbb44, 0x1747, 0x4a1f, 0xdca9, 0x10d6,
-0x4291, 0xc4a6, 0xbd25, 0x2a87, 0xe605, 0xcbf6, 0x4b38, 0x15fb, 0xe0ad, 0x3f35,
-0x0d36, 0xa652, 0x0068, 0x234a, 0xbde1, 0x11e2, 0x4aeb, 0xdbe0, 0x0a9d, 0x4344,
-0xcb41, 0xbfb5, 0x3005, 0xef5d, 0xcc1b, 0x497b, 0x1516, 0xd825, 0x3b8a, 0x1677,
-0xabc7, 0xfeb9, 0x2dcb, 0xc484, 0x08d9, 0x4f69, 0xe275, 0x041d, 0x4846, 0xd81a,
-0xc055, 0x3307, 0xfcca, 0xce29, 0x4a68, 0x20cb, 0xd8f3, 0x379a, 0x1b24, 0xaf02,
-0xfaf5, 0x36a2, 0xdc0c, 0xf2c4, 0x1be5, 0xefab, 0x3121, 0x54a4, 0xf198, 0xe7b1,
-0x2ba4, 0xe144, 0xad6e, 0x0105, 0xf0a8, 0xe331, 0x4379, 0x5911, 0x2529, 0x2cc9,
-0x279d, 0xcce3, 0xc4aa, 0xd6d0, 0xaebe, 0xee7a, 0x3b83, 0x0e08, 0x0c23, 0x6c6b,
-0x4249, 0xd2d0, 0xee99, 0xf0dc, 0xb1d9, 0xc315, 0x0097, 0x05b2, 0x198e, 0x3a21,
-0x0a87, 0x19af, 0x3001, 0xda73, 0xbf3b, 0xf320, 0xf1e8, 0xce48, 0xfde9, 0x1c97,
-0x092a, 0x1c03, 0x1996, 0x174f, 0x1e06, 0x0784, 0xc7d4, 0xc266, 0xf6c0, 0xcc3e,
-0xdd41, 0x35c9, 0x3070, 0x0e9b, 0x2df6, 0x46cc, 0xf777, 0xdb3b, 0xd86d, 0xb2ad,
-0xdad5, 0xea97, 0xeb13, 0x2dfd, 0x5bf5, 0x1d45, 0x0c80, 0x4c6b, 0xf9d2, 0xb332,
-0xd3b1, 0xcca7, 0xc90a, 0xeeb9, 0x1637, 0x2142, 0x4501, 0x2b65, 0x034c, 0x35ee,
-0x0df0, 0xbcaf, 0xb962, 0xda48, 0xd509, 0xd169, 0x125a, 0x2f7e, 0x3ce9, 0x31e9,
-0x1f9f, 0x25c3, 0xf9ce, 0xc7fa, 0xa4bc, 0xc4e4, 0xde14, 0xd114, 0x1820, 0x4ec1,
-0x3955, 0x1716, 0x2ffb, 0x23e1, 0xd401, 0xc118, 0xaea8, 0xc267, 0xe761, 0xe650,
-0x166b, 0x5317, 0x4508, 0x02ef, 0x256f, 0x2a58, 0xc9bf, 0xbfb1, 0xc690, 0xc4c0,
-0xdb5a, 0xfc3e, 0x1d56, 0x406f, 0x4672, 0x07f9, 0x258b, 0x3563, 0xd0af, 0xad4b,
-0xc62c, 0xd7ec, 0xd118, 0xfacb, 0x32c8, 0x3cf8, 0x3893, 0x1827, 0x2a88, 0x2056,
-0xd2e0, 0xa9a8, 0xbc95, 0xe82d, 0xd209, 0xed42, 0x4049, 0x4bca, 0x27a4, 0x17b5,
-0x33c7, 0x048c, 0xc896, 0xbbc4, 0xb5e8, 0xde55, 0xe670, 0xf26e, 0x319d, 0x5284,
-0x20bb, 0x0a37, 0x3f54, 0x0425, 0xb7b6, 0xbeac, 0xc4a7, 0xd10a, 0xdf90, 0x067a,
-0x32d8, 0x4def, 0x29e9, 0x0de0, 0x33b8, 0x00f9, 0xbb53, 0xb44c, 0xca99, 0xdcb3,
-0xdf0d, 0x140a, 0x4211, 0x47c0, 0x2741, 0x1ffe, 0x3026, 0xf2ee, 0xc44d, 0xb8c2,
-0xcbde, 0xe86b, 0xed77, 0x1b4d, 0x47ee, 0x4766, 0x1ae9, 0x2386, 0x33e9, 0xea57,
-0xc4ae, 0xc182, 0xd3ec, 0xeae1, 0xf2fa, 0x1c99, 0x46ce, 0x4849, 0x16e5, 0x2357,
-0x2d0d, 0xe171, 0xc2b4, 0xc619, 0xdb43, 0xe861, 0xf96a, 0x2580, 0x41a1, 0x3fcc,
-0x14f6, 0x245e, 0x2692, 0xe3d9, 0xc4b2, 0xc084, 0xdcfb, 0xe481, 0xf277, 0x26e8,
-0x4453, 0x3677, 0x1401, 0x2eb5, 0x1c61, 0xda3a, 0xc536, 0xbbc2, 0xd95f, 0xe409,
-0xf088, 0x24e3, 0x4a50, 0x36ef, 0x1343, 0x3794, 0x1bd7, 0xd0b1, 0xbf04, 0xc0c0,
-0xd999, 0xe102, 0xfe57, 0x307b, 0x4c60, 0x3446, 0x110b, 0x34af, 0x1719, 0xd246,
-0xbe92, 0xc661, 0xdf01, 0xde95, 0x04b9, 0x34ae, 0x44b2, 0x2c3e, 0x140f, 0x311d,
-0x09e5, 0xcd57, 0xb673, 0xc4ea, 0xe8e6, 0xdfae, 0x02f2, 0x3c51, 0x460d, 0x2037,
-0x160e, 0x33a4, 0xffd5, 0xd044, 0xbb77, 0xbff6, 0xe547, 0xe2d3, 0x02a5, 0x3927,
-0x483e, 0x1e84, 0x18a8, 0x35a4, 0xf428, 0xc4b4, 0xb810, 0xbe31, 0xdf3f, 0xe3b9,
-0x070a, 0x3a6e, 0x4a01, 0x1d3d, 0x19b7, 0x312f, 0xe9ed, 0xb9d2, 0xb185, 0xc27d,
-0xdf74, 0xeaac, 0x163c, 0x40b2, 0x480f, 0x196b, 0x1a68, 0x2946, 0xe387, 0xbd44,
-0xb687, 0xcdd3, 0xe1c0, 0xe73f, 0x19c6, 0x454e, 0x4471, 0x1517, 0x1f37, 0x2415,
-0xde12, 0xbc28, 0xb193, 0xce92, 0xe199, 0xeb2a, 0x208d, 0x45c9, 0x3dfd, 0x140f,
-0x2554, 0x1b8d, 0xd3e4, 0xb631, 0xaeee, 0xd2a0, 0xe032, 0xeefc, 0x2bad, 0x4d46,
-0x3a27, 0x0f3b, 0x24c9, 0x111e, 0xcdbf, 0xb6b5, 0xb194, 0xd7c9, 0xe60a, 0xf93b,
-0x2f30, 0x4968, 0x3246, 0x1306, 0x2d46, 0x06e7, 0xc785, 0xba49, 0xb9ab, 0xde3a,
-0xe629, 0xff26, 0x3a02, 0x5456, 0x30f0, 0x10ea, 0x3149, 0x0578, 0xc92c, 0xbe07,
-0xc00c, 0xe26f, 0xec57, 0x0aaf, 0x3ec0, 0x560f, 0x2fbd, 0x16da, 0x3543, 0xfe12,
-0xc441, 0xbe1e, 0xce80, 0xec2a, 0xeeda, 0x1761, 0x467e, 0x531c, 0x2945, 0x16f3,
-0x30b3, 0xfa85, 0xc82a, 0xb95b, 0xd0b9, 0xf0bf, 0xecf0, 0x1a23, 0x4acc, 0x48e2,
-0x1c65, 0x1e4d, 0x2902, 0xe8e0, 0xc9c2, 0xbc2f, 0xd2c0, 0xf22e, 0xed1c, 0x1844,
-0x4b01, 0x4776, 0x146e, 0x2125, 0x2832, 0xde1c, 0xc52b, 0xbd52, 0xcf76, 0xec76,
-0xf496, 0x1c9f, 0x4726, 0x432c, 0x116f, 0x25e7, 0x2766, 0xd731, 0xbc99, 0xc162,
-0xd7c6, 0xe12d, 0xf3c2, 0x27ac, 0x489f, 0x3fb7, 0x11f9, 0x23e3, 0x1dd1, 0xd9f9,
-0xbc81, 0xbc41, 0xe051, 0xe6f9, 0xf6af, 0x2df2, 0x4613, 0x2fe6, 0x12b9, 0x303c,
-0x120f, 0xd130, 0xc1da, 0xbc62, 0xdb80, 0xe279, 0xf4be, 0x2c52, 0x4660, 0x275e,
-0x0d1c, 0x3149, 0x075f, 0xc931, 0xbf24, 0xbaf3, 0xd888, 0xe2cc, 0xfb8b, 0x2cb6,
-0x4a52, 0x29ea, 0x0caa, 0x3097, 0xff78, 0xbdf9, 0xb45b, 0xc1cb, 0xdd4e, 0xe310,
-0x068a, 0x24f2, 0x54ac, 0x60d2, 0x1650, 0xf4c6, 0xe059, 0xb014, 0x83b1, 0xbc91,
-0x02f9, 0x0157, 0x4fca, 0x7cb3, 0x41bb, 0x0df7, 0xea9f, 0xace6, 0x957f, 0xc6c1,
-0xb25c, 0xf25c, 0x6d4a, 0x3c23, 0x2274, 0x5314, 0x2754, 0xc59a, 0xd13d, 0xdf25,
-0xc110, 0x097d, 0xfee9, 0xe7e9, 0x4a58, 0x3073, 0xd0cf, 0x0834, 0x3f47, 0xde37,
-0xefad, 0x3de0, 0xef24, 0xe80f, 0x1519, 0xd4ff, 0xbae7, 0x160b, 0x1ed5, 0xf6f3,
-0x4a32, 0x391f, 0xed02, 0x1a95, 0x0194, 0xa798, 0xcdb4, 0x1870, 0xed7d, 0x0805,
-0x5609, 0x1649, 0x0c10, 0x37fb, 0xe698, 0xb602, 0x0ab1, 0x02bc, 0xc982, 0x29a0,
-0x3592, 0xeb4c, 0x26a0, 0x2b39, 0xc51e, 0xe028, 0x25df, 0xdd3d, 0xeb89, 0x3c7d,
-0xf25b, 0xf2a8, 0x40cd, 0xf67a, 0xbd91, 0x18e1, 0x1367, 0xcbf7, 0x1e2b, 0x2469,
-0xd608, 0x16f8, 0x2a0b, 0xc927, 0xe2cc, 0x37b1, 0xf346, 0xe694, 0x382d, 0xf93e,
-0xe10a, 0x2a89, 0xf6d1, 0xba9a, 0x1681, 0x2591, 0xd24e, 0x187c, 0x2fad, 0xd8f6,
-0x0b46, 0x2ae5, 0xc8c2, 0xd38a, 0x2a7a, 0xe7b1, 0xdcb3, 0x3e95, 0x03d8, 0xe5e1,
-0x3718, 0x0451, 0xb6fc, 0x05d7, 0x1636, 0xc589, 0x0c0d, 0x2d31, 0xe2a5, 0x145e,
-0x2ff3, 0xd16c, 0xd748, 0x2961, 0xeee4, 0xd89a, 0x2f77, 0x0413, 0xe432, 0x2a18,
-0x07e4, 0xbf90, 0xffac, 0x1a5c, 0xce43, 0x0eae, 0x3e2a, 0xe525, 0xfcdf, 0x3412,
-0xe19f, 0xc0d0, 0x160c, 0xf679, 0xdaf7, 0x3d0f, 0x184f, 0xe643, 0x3314, 0x0d97,
-0xa9d1, 0xf210, 0x1e09, 0xc374, 0x0591, 0x4995, 0xef24, 0x05bf, 0x3aa6, 0xdaf6,
-0xc1a1, 0x198b, 0xe5e1, 0xce1f, 0x40dc, 0x134c, 0xddc5, 0x3b68, 0x1d73, 0xb2c0,
-0xf385, 0x2228, 0xc6a9, 0xff0d, 0x4056, 0xea16, 0x071a, 0x3ca3, 0xd74b, 0xbcb1,
-0x210f, 0xf2c1, 0xcb2c, 0x414d, 0x1f07, 0xd958, 0x2f24, 0x195a, 0xa747, 0xe84d,
-0x2605, 0xc501, 0xff0e, 0x4e0a, 0xea48, 0x02a4, 0x46c5, 0xd723, 0xafda, 0x23af,
-0xf6a4, 0xbc7c, 0x3c45, 0x26f8, 0xdc74, 0x367d, 0x2543, 0xb0bd, 0xed3e, 0x27e5,
-0xc333, 0xf8e2, 0x4d51, 0xeb5f, 0xfefc, 0x4865, 0xe34b, 0xb937, 0x2748, 0x0266,
-0xc562, 0x3a6b, 0x25b1, 0xd774, 0x2daa, 0x2313, 0xb311, 0xef4a, 0x32e8, 0xcf60,
-0xf8b2, 0x51fb, 0xee07, 0xf368, 0x44ab, 0xe548, 0xb2da, 0x24f2, 0x07b3, 0xc446,
-0x3bc4, 0x2db3, 0xd779, 0x2ee4, 0x281e, 0xace1, 0xe4c5, 0x335a, 0xceab, 0xf17b,
-0x55c7, 0xf4d4, 0xf24d, 0x4603, 0xeb3d, 0xaf65, 0x1bbf, 0x08f3, 0xbf31, 0x300f,
-0x30d1, 0xd9cf, 0x29ba, 0x2ead, 0xb5b6, 0xdd53, 0x2dff, 0xcf0d, 0xe2d2, 0x4b14,
-0xf7cf, 0xf104, 0x48fe, 0xf5f9, 0xb102, 0x175c, 0x0bd9, 0xbcb2, 0x27b4, 0x336a,
-0xd7be, 0x2088, 0x3408, 0xbf37, 0xdc20, 0x3264, 0xdb9f, 0xe60e, 0x5013, 0xffb1,
-0xe856, 0x4281, 0xff01, 0xb10f, 0x1094, 0x176a, 0xc863, 0x243b, 0x390b, 0xdf6d,
-0x1d95, 0x3900, 0xc65f, 0xd25c, 0x2c3a, 0xe187, 0xdbeb, 0x465f, 0x0986, 0xeb79,
-0x4044, 0x0711, 0xb0da, 0x0496, 0x1513, 0xc287, 0x187b, 0x3c78, 0xe032, 0x1521,
-0x3c5f, 0xccc3, 0xcce1, 0x2b96, 0xe4ca, 0xd2ba, 0x430a, 0x0aa2, 0xdffc, 0x3ad9,
-0x0be5, 0xaea0, 0x03b6, 0x1ba6, 0xbbed, 0x0db5, 0x4113, 0xdc05, 0x05bb, 0x3a65,
-0xcc55, 0xc14b, 0x25ec, 0xe783, 0xd1d2, 0x4965, 0x1616, 0xdbb4, 0x3263, 0x0a8b,
-0xa569, 0xf7cf, 0x1f57, 0xc4d2, 0x1559, 0x517f, 0xea47, 0x0848, 0x3a1f, 0xc9f1,
-0xbb1e, 0x266f, 0xea60, 0xcd1c, 0x4d59, 0x23a6, 0xe328, 0x3b46, 0x19d2, 0xabe2,
-0xf47d, 0x1e1a, 0xbcd3, 0x09ed, 0x4fb3, 0xe964, 0x0dbc, 0x485b, 0xd3bb, 0xbbbe,
-0x2722, 0xffc5, 0xce39, 0x0d09, 0xfe2c, 0x112d, 0x596c, 0x16f5, 0xd170, 0x12a7,
-0x07ab, 0xa521, 0xd945, 0x0290, 0xcf7b, 0x0c60, 0x5af6, 0x3c64, 0x1c78, 0x2c17,
-0xf082, 0xb62e, 0xcf0c, 0xac7d, 0xba75, 0x27ac, 0x23af, 0xf129, 0x473d, 0x6f3b,
-0xefd4, 0xd0fc, 0xfcb5, 0xc5fa, 0xa532, 0xe2aa, 0x08ff, 0x0704, 0x304a, 0x21e6,
-0x0f85, 0x38c1, 0x010f, 0xbcdf, 0xd894, 0xf8ab, 0xd8c7, 0xe36a, 0x1b7a, 0x178e,
-0x1a72, 0x1741, 0x157f, 0x1dd4, 0x0dfe, 0xe47e, 0xbdd3, 0xf139, 0xe9ae, 0xc861,
-0x198e, 0x432e, 0x1c93, 0x1246, 0x4ca3, 0x23d4, 0xd5a3, 0xdda1, 0xc097, 0xcd1a,
-0xeddd, 0xed1a, 0x1738, 0x5658, 0x41b1, 0xfba0, 0x3319, 0x2a1d, 0xc048, 0xc0cf,
-0xd583, 0xd4c9, 0xdb7a, 0x070a, 0x2588, 0x3798, 0x3aa9, 0x0add, 0x25af, 0x2337,
-0xd4c2, 0xb504, 0xca8a, 0xe4dd, 0xd039, 0xf1df, 0x2bb9, 0x3c1d, 0x3426, 0x22ac,
-0x331f, 0x0f10, 0xdc7d, 0xbbe1, 0xb47c, 0xdb63, 0xd984, 0xfcbd, 0x450f, 0x5431,
-0x271a, 0x210b, 0x3c62, 0xf43d, 0xc565, 0xc201, 0xc114, 0xe4f6, 0xee9b, 0x085b,
-0x3cf5, 0x5653, 0x1e82, 0x0d52, 0x38a8, 0xf608, 0xc456, 0xce8b, 0xcfd1, 0xda08,
-0xf0f6, 0x16f4, 0x3014, 0x4610, 0x1a46, 0x0c35, 0x36d1, 0xfb60, 0xbc9c, 0xbcea,
-0xdb0c, 0xda74, 0xdb6c, 0x17ce, 0x3715, 0x33b3, 0x13c8, 0x1e7d, 0x290c, 0xe55b,
-0xb756, 0xb135, 0xdad6, 0xde70, 0xd336, 0x1782, 0x43a0, 0x29e5, 0x03f8, 0x2c8f,
-0x2768, 0xd396, 0xc0e1, 0xbc23, 0xccce, 0xdf32, 0xe829, 0x16bf, 0x4610, 0x3567,
-0x012e, 0x312c, 0x3059, 0xcf4c, 0xbc48, 0xcf7d, 0xdb0c, 0xd4f7, 0xefe3, 0x2327,
-0x3f5e, 0x34bf, 0x11d9, 0x3885, 0x2a09, 0xd700, 0xbd59, 0xc753, 0xde26, 0xd765,
-0xf612, 0x31cc, 0x45d3, 0x2d56, 0x17c3, 0x3e94, 0x16b7, 0xce82, 0xc389, 0xc8ab,
-0xdd9d, 0xdd82, 0xfe36, 0x3550, 0x4d5b, 0x2a45, 0x1384, 0x3ff2, 0x0ef3, 0xc81d,
-0xbe61, 0xcce9, 0xe4aa, 0xe0ab, 0x0699, 0x385e, 0x486b, 0x2294, 0x15f0, 0x3d85,
-0x01db, 0xc686, 0xc116, 0xcff5, 0xe34d, 0xe14b, 0x10c9, 0x3f07, 0x466b, 0x1f0d,
-0x1d05, 0x3ab5, 0xf8ef, 0xc8ce, 0xc05e, 0xd357, 0xe7d4, 0xe29f, 0x13df, 0x471a,
-0x4a47, 0x1c4c, 0x297f, 0x3e3f, 0xed74, 0xc6f8, 0xbfdc, 0xccde, 0xe3d5, 0xeaa0,
-0x19ee, 0x4b1b, 0x4d49, 0x1865, 0x2976, 0x37a0, 0xe1a2, 0xb9e8, 0xba35, 0xd299,
-0xde2b, 0xecfc, 0x27c6, 0x4ae2, 0x4564, 0x19a4, 0x28b5, 0x2426, 0xd885, 0xbc0a,
-0xb90e, 0xd777, 0xe284, 0xf34a, 0x2d9a, 0x4813, 0x38b9, 0x14ee, 0x2c67, 0x1894,
-0xd324, 0xbc7e, 0xb3bc, 0xda55, 0xe3e2, 0xef0a, 0x2fd7, 0x4da0, 0x2e6a, 0x0ee2,
-0x326e, 0x0fc1, 0xcb23, 0xbee7, 0xb82c, 0xdaac, 0xe70d, 0xf676, 0x2c96, 0x4efe,
-0x3180, 0x0f59, 0x3430, 0x0900, 0xc464, 0xbdf3, 0xbfd4, 0xdc18, 0xe54f, 0x02ac,
-0x346a, 0x4ca2, 0x2bdb, 0x0ba0, 0x2ca5, 0x00e4, 0xc0c2, 0xb4ae, 0xbea2, 0xdd3b,
-0xe1b5, 0x05e5, 0x36cd, 0x455d, 0x228c, 0x0f39, 0x2721, 0xf06a, 0xbe3c, 0xb625,
-0xc315, 0xe0db, 0xe130, 0x0824, 0x3af9, 0x4450, 0x1a04, 0x1254, 0x2a20, 0xeab7,
-0xbec0, 0xb857, 0xc3f1, 0xdf5a, 0xe831, 0x122e, 0x3daa, 0x44fa, 0x18f6, 0x1739,
-0x28bb, 0xe41d, 0xbbf3, 0xb89c, 0xcff6, 0xe5c1, 0xea00, 0x1c60, 0x45d5, 0x43ef,
-0x1c06, 0x2434, 0x292a, 0xe39e, 0xc2cb, 0xbd71, 0xd5c4, 0xe95c, 0xf5d3, 0x2a36,
-0x4b75, 0x403d, 0x1c75, 0x32bf, 0x27ef, 0xdda2, 0xcb76, 0xc7c5, 0xdb1a, 0xe84b,
-0xf612, 0x2b74, 0x5112, 0x4137, 0x18a7, 0x3889, 0x2791, 0xd8ed, 0xc90a, 0xc6c8,
-0xd83c, 0xe5cf, 0x01d1, 0x32e1, 0x4e08, 0x3e77, 0x1bcc, 0x39cc, 0x1bcb, 0xcf7c,
-0xbfad, 0xc693, 0xe1af, 0xe44a, 0x0379, 0x3b80, 0x5122, 0x34da, 0x12cd, 0x2ff7,
-0x0b3f, 0xcb7c, 0xb95e, 0xc0f4, 0xe555, 0xe1ce, 0x01a1, 0x3cc9, 0x475e, 0x2196,
-0x156a, 0x33d5, 0xf97d, 0xc4c1, 0xb9ed, 0xbd90, 0xe1db, 0xe24b, 0x021d, 0x3cfa,
-0x4dca, 0x1ea3, 0x12f7, 0x33e9, 0xf159, 0xbf15, 0xb984, 0xbdf4, 0xd9dc, 0xe483,
-0x0d28, 0x3bb5, 0x4aee, 0x1fcf, 0x1792, 0x2e75, 0xe773, 0xb55d, 0xaeed, 0xc525,
-0xdc07, 0xe07a, 0x162d, 0x403a, 0x41df, 0x18e6, 0x1816, 0x22ca, 0xe0d7, 0xba3f,
-0xab7d, 0xc6d9, 0xe296, 0xe464, 0x1a6b, 0x45ec, 0x3cb4, 0x1203, 0x21d7, 0x1e19,
-0xd553, 0xc042, 0xb44a, 0xca17, 0xe29f, 0xe893, 0x1a35, 0x457e, 0x3ca4, 0x0eee,
-0x274f, 0x1dc0, 0xd010, 0xbe2a, 0xb43a, 0xca4c, 0xe2e4, 0xf448, 0x246d, 0x4965,
-0x3fdb, 0x10f7, 0x25b8, 0x162e, 0xcca7, 0xb882, 0xb947, 0xd7a5, 0xe438, 0xfea1,
-0x33b7, 0x4cfe, 0x3b14, 0x1175, 0x24b7, 0x0bf7, 0xcecd, 0xbc06, 0xbdfc, 0xe81e,
-0xee24, 0x01b0, 0x3af8, 0x476e, 0x28b0, 0x20d9, 0x3412, 0xf8f1, 0xc8c9, 0xbcf1,
-0xbe75, 0xed66, 0xf061, 0x0477, 0x2e04, 0x4a13, 0x58d9, 0x3473, 0x0a86, 0xde23,
-0xc927, 0xa391, 0xa85a, 0xfd01, 0x01c0, 0x26a1, 0x8016, 0x6b60, 0x1f2e, 0x05f0,
-0xdab1, 0x948b, 0xb8c2, 0xc47d, 0xcb07, 0x3e6c, 0x61b3, 0x38d1, 0x421e, 0x423b,
-0xe147, 0xbac6, 0xe0e9, 0xbe22, 0xd9dd, 0x0b3a, 0x03de, 0x31f4, 0x40dc, 0xf8e0,
-0xf398, 0x2cdd, 0xec3a, 0xc582, 0x25ea, 0x1c58, 0xd8cd, 0x0700, 0x13d5, 0xbffb,
-0xdfbf, 0x2eeb, 0xf5a6, 0x0a90, 0x5506, 0x0dfc, 0xf5d4, 0x194f, 0xd0b1, 0xa469,
-0xf944, 0x0659, 0xe225, 0x3e8d, 0x4455, 0xf804, 0x285d, 0x16e8, 0xac54, 0xcbe6,
-0x0dc1, 0xcfa2, 0xef3a, 0x51ba, 0x0cea, 0x02d9, 0x4169, 0xec8e, 0xb42c, 0x04b3,
-0xfdcb, 0xc5c1, 0x233b, 0x2fa0, 0xe530, 0x27ec, 0x2937, 0xc096, 0xdeaa, 0x2435,
-0xe010, 0xe6f7, 0x3e0a, 0xfd91, 0xeb2e, 0x333b, 0xf30c, 0xb2be, 0x1250, 0x1fd9,
-0xc7fa, 0x1877, 0x3b5d, 0xdbdb, 0x0644, 0x23bb, 0xbdc0, 0xcc54, 0x2f0c, 0xf1f3,
-0xe57b, 0x48e5, 0x082c, 0xe598, 0x360e, 0xf80f, 0xa876, 0x0659, 0x1b42, 0xc57b,
-0x1fb9, 0x48cb, 0xe657, 0x1591, 0x3682, 0xcb26, 0xccd4, 0x2692, 0xe8fa, 0xda38,
-0x445f, 0x1220, 0xf0e0, 0x3d8f, 0x09d0, 0xb6bc, 0x00e1, 0x260a, 0xd188, 0x0576,
-0x3935, 0xef31, 0x1179, 0x33e9, 0xd401, 0xcde0, 0x2d56, 0xfa21, 0xdbb0, 0x4a3c,
-0x1c17, 0xdc92, 0x334e, 0x1ceb, 0xb17d, 0xebbf, 0x27e0, 0xd919, 0x0f7e, 0x4a4b,
-0xf20c, 0x107b, 0x3a20, 0xcab0, 0xba0a, 0x24cb, 0xf1fa, 0xcaf2, 0x3f6a, 0x2005,
-0xe495, 0x30ba, 0x16ef, 0xb7a7, 0xec01, 0x1401, 0xc9b7, 0x05b6, 0x393b, 0xe12d,
-0x07bf, 0x44cb, 0xdee8, 0xbd85, 0x23f1, 0xfc20, 0xc5f2, 0x2bd6, 0x194b, 0xdfc0,
-0x26e3, 0x160b, 0xba3e, 0xf25d, 0x2457, 0xcdc4, 0x004b, 0x4634, 0xe4dc, 0xf4a7,
-0x3d04, 0xdcc3, 0xb397, 0x1fb0, 0x0021, 0xcbc7, 0x37a0, 0x223d, 0xdd2e, 0x2e4a,
-0x1e22, 0xae9d, 0xea89, 0x28db, 0xc94f, 0xf4c9, 0x4a0c, 0xf565, 0xfefa, 0x4525,
-0xee89, 0xbfb1, 0x1b8b, 0xfa5c, 0xc436, 0x2f51, 0x24ca, 0xdfcd, 0x2cf4, 0x2a31,
-0xbd55, 0xe94e, 0x2b96, 0xd147, 0xee2f, 0x4235, 0xf2bf, 0xf601, 0x3b75, 0xe821,
-0xb876, 0x1f6c, 0x056a, 0xc597, 0x378b, 0x2e60, 0xd377, 0x1e9d, 0x283c, 0xb892,
-0xdee1, 0x2781, 0xd1f0, 0xf4ba, 0x554c, 0x0123, 0xf9be, 0x420b, 0xea52, 0xaa76,
-0x121d, 0x04f0, 0xbdca, 0x333f, 0x4315, 0xe753, 0x27d8, 0x325a, 0xb873, 0xd272,
-0x2388, 0xcf65, 0xe913, 0x57fe, 0x07f4, 0xf542, 0x4773, 0xf6c7, 0xab18, 0x11a2,
-0x0c42, 0xb926, 0x2816, 0x3c96, 0xde7c, 0x28fb, 0x3ab1, 0xb843, 0xd1f6, 0x2e08,
-0xd30e, 0xdd67, 0x552d, 0x04b1, 0xe6f1, 0x4408, 0xfac7, 0xa436, 0x0956, 0x1138,
-0xb9e0, 0x267a, 0x42e3, 0xd676, 0x199d, 0x3443, 0xb086, 0xc200, 0x28e5, 0xda7a,
-0xd827, 0x53d9, 0x0bab, 0xe3c1, 0x40a6, 0xfc98, 0xa29e, 0x018f, 0x1105, 0xb6e7,
-0x1b43, 0x498c, 0xdd00, 0x1541, 0x4138, 0xc0de, 0xbf2e, 0x283d, 0xe09c, 0xce50,
-0x4aa8, 0x1053, 0xdfdb, 0x3f0a, 0x0676, 0xa0c4, 0xfe21, 0x1b86, 0xb753, 0x10a7,
-0x4958, 0xd934, 0x0821, 0x3f0a, 0xc34f, 0xba57, 0x2b9e, 0xe817, 0xc7b8, 0x46a9,
-0x0faa, 0xd39d, 0x38e6, 0x0b67, 0x9f2e, 0xfa87, 0x2298, 0xbafd, 0x0a31, 0x466b,
-0xd41d, 0xfd51, 0x3a2b, 0xc101, 0xb40d, 0x2b20, 0xef1f, 0xc9c0, 0x46b9, 0x10a8,
-0xce9c, 0x3371, 0x097d, 0x9c55, 0xf5c4, 0x3090, 0xd2df, 0xecd4, 0x147e, 0xe806,
-0x2e2d, 0x4ebd, 0xe525, 0xe179, 0x26a7, 0xd61d, 0xaa44, 0x0053, 0xe8dc, 0xe136,
-0x46b6, 0x57fc, 0x24b5, 0x2da9, 0x235d, 0xcd31, 0xca81, 0xd1c7, 0xaf26, 0xfdb0,
-0x3bad, 0x09ac, 0x1da0, 0x74cf, 0x3a9c, 0xd9e6, 0xf662, 0xf1b3, 0xb74e, 0xc78b,
-0x079d, 0x1303, 0x25f7, 0x3f88, 0x14f4, 0x2459, 0x2c9b, 0xdd69, 0xc8da, 0xfb0c,
-0xfc56, 0xd94a, 0x0b6d, 0x29c0, 0x150a, 0x22e5, 0x1d92, 0x18ef, 0x1cfc, 0x0c23,
-0xcdc3, 0xcd7b, 0x0116, 0xd225, 0xea05, 0x3ecf, 0x321c, 0x114b, 0x3429, 0x4818,
-0xf80f, 0xe0f6, 0xd86d, 0xb88f, 0xe34c, 0xec85, 0xf335, 0x37f0, 0x5dfb, 0x1c42,
-0x11db, 0x4f23, 0xfc26, 0xba44, 0xd5aa, 0xd324, 0xd1fd, 0xf17c, 0x1856, 0x276a,
-0x4692, 0x286a, 0x0ba3, 0x3d7b, 0x1150, 0xc1ac, 0xbdf0, 0xe136, 0xd542, 0xcf26,
-0x1384, 0x2faf, 0x3870, 0x2e2c, 0x2318, 0x28d4, 0xfdee, 0xcb16, 0xa730, 0xc88d,
-0xdb00, 0xceb6, 0x1995, 0x4d9d, 0x384a, 0x1a5c, 0x3253, 0x2473, 0xd8f1, 0xc53c,
-0xafa7, 0xc440, 0xe9ed, 0xe807, 0x176e, 0x51f8, 0x4372, 0x074b, 0x2912, 0x2b6d,
-0xcf1e, 0xc37a, 0xc518, 0xc3a3, 0xdc9c, 0xfa3e, 0x1a98, 0x40fa, 0x4783, 0x0983,
-0x2539, 0x3545, 0xd15a, 0xad3e, 0xc7ca, 0xd8f8, 0xd06d, 0xf96a, 0x3340, 0x3d0f,
-0x375f, 0x19a1, 0x2cbe, 0x2480, 0xd619, 0xaa0f, 0xbfde, 0xe9c8, 0xd157, 0xf05e,
-0x42af, 0x4a8c, 0x2ada, 0x1e55, 0x372a, 0x09e1, 0xcd35, 0xbbbe, 0xb8fb, 0xe193,
-0xe480, 0xf329, 0x3476, 0x51aa, 0x233d, 0x1102, 0x44ce, 0x08c4, 0xbbca, 0xc158,
-0xc692, 0xd1e1, 0xdde2, 0x0656, 0x33cd, 0x4f74, 0x2ddc, 0x0f4d, 0x394e, 0x09e6,
-0xbe5c, 0xb5ad, 0xcc4d, 0xdc27, 0xdab2, 0x1043, 0x3ea4, 0x479b, 0x2b41, 0x1d61,
-0x308b, 0xf8bb, 0xc464, 0xb735, 0xcd64, 0xe75e, 0xe437, 0x161f, 0x4870, 0x48ad,
-0x1c9b, 0x1ea2, 0x33d1, 0xf0d7, 0xc828, 0xc0cf, 0xd2aa, 0xe99c, 0xeb83, 0x1a23,
-0x47fe, 0x4a7b, 0x1905, 0x1e38, 0x324a, 0xe958, 0xc1e9, 0xc325, 0xd7e4, 0xe635,
-0xf2dc, 0x2267, 0x3faa, 0x415f, 0x1a59, 0x202f, 0x2852, 0xe889, 0xc4bd, 0xbe6c,
-0xdab6, 0xe56a, 0xef10, 0x26eb, 0x4556, 0x3a6e, 0x180a, 0x2a09, 0x1fb9, 0xde8b,
-0xc5cf, 0xb9e8, 0xd7a7, 0xe7b9, 0xedd9, 0x2300, 0x49df, 0x37d1, 0x12a8, 0x2f9a,
-0x18aa, 0xce1b, 0xbdb0, 0xbc6b, 0xd29e, 0xdeee, 0xf71a, 0x2781, 0x45f4, 0x339d,
-0x0ccf, 0x2b8f, 0x12d6, 0xc8e8, 0xb6b6, 0xbda1, 0xd3af, 0xd912, 0xfe42, 0x2d6d,
-0x3ef8, 0x304b, 0x1689, 0x29cf, 0x067c, 0xcba1, 0xb57d, 0xbede, 0xdf90, 0xdc36,
-0xfffb, 0x3465, 0x3c40, 0x2128, 0x1a44, 0x31e1, 0xfd23, 0xcc9c, 0xbac3, 0xbc48,
-0xdd17, 0xde23, 0xfd31, 0x3137, 0x4362, 0x1eee, 0x18fc, 0x32b8, 0xf20e, 0xc5cc,
-0xbb44, 0xbdcc, 0xd9bd, 0xe2e3, 0x076b, 0x353c, 0x4892, 0x1e7b, 0x18f6, 0x30cf,
-0xea76, 0xbae7, 0xb387, 0xc4fa, 0xdcc0, 0xe7b8, 0x15fe, 0x3d5b, 0x45ed, 0x199f,
-0x192d, 0x2670, 0xe39c, 0xbd23, 0xb49a, 0xce79, 0xe000, 0xe7b3, 0x1c0b, 0x42fb,
-0x4231, 0x1500, 0x214f, 0x24b7, 0xddd0, 0xbdaf, 0xb443, 0xd1d6, 0xe488, 0xf035,
-0x248c, 0x481a, 0x412e, 0x17e3, 0x2a09, 0x1e55, 0xd730, 0xbb6d, 0xb458, 0xd6fe,
-0xe4f4, 0xf65d, 0x30dd, 0x50e1, 0x3ee0, 0x15ff, 0x2a77, 0x133f, 0xd208, 0xbb41,
-0xb5d0, 0xdc9b, 0xea0f, 0xfe2e, 0x33e8, 0x4ec6, 0x3729, 0x17b0, 0x327e, 0x0ae7,
-0xcbb1, 0xbd40, 0xbbb0, 0xe021, 0xe92f, 0x0274, 0x3a54, 0x53fa, 0x3201, 0x1417,
-0x340a, 0x073d, 0xcaf8, 0xbd21, 0xbddc, 0xdfe9, 0xebda, 0x0cee, 0x3df0, 0x5410,
-0x3025, 0x16c7, 0x32e0, 0xfb90, 0xc1f6, 0xbac8, 0xcb01, 0xe852, 0xeb00, 0x14bb,
-0x4362, 0x4e09, 0x267e, 0x175e, 0x2ea6, 0xf673, 0xc679, 0xb7ca, 0xce42, 0xef38,
-0xea88, 0x19da, 0x4c19, 0x4976, 0x1f9b, 0x2155, 0x2984, 0xe747, 0xc939, 0xbc60,
-0xced0, 0xf05b, 0xef4a, 0x1a1b, 0x4d06, 0x49db, 0x1707, 0x21a4, 0x261f, 0xdb58,
-0xc42f, 0xbd07, 0xcd03, 0xeb57, 0xf6f1, 0x1fe4, 0x4885, 0x45cb, 0x1391, 0x2121,
-0x232c, 0xd7ec, 0xbd29, 0xbf59, 0xd799, 0xe575, 0xf6b7, 0x28c6, 0x4774, 0x3e39,
-0x1137, 0x1ef7, 0x1744, 0xd610, 0xbc35, 0xb9e4, 0xdd70, 0xe860, 0xf41e, 0x2929,
-0x4423, 0x2e1c, 0x110a, 0x2d77, 0x0e41, 0xced2, 0xc1cd, 0xbb1d, 0xd9b8, 0xe41e,
-0xf4ed, 0x2b8f, 0x4959, 0x2b92, 0x0f36, 0x32ac, 0x0962, 0xc983, 0xc063, 0xbadd,
-0xd65d, 0xe557, 0xfe42, 0x2c4a, 0x49b0, 0x2cc4, 0x11af, 0x335e, 0x0099, 0xbfb6,
-0xb950, 0xc282, 0xda13, 0xe2c3, 0x0c6b, 0x2301, 0x3d0d, 0x5b32, 0x2bf1, 0xf816,
-0xd811, 0xc694, 0x94e5, 0xa76b, 0x02b3, 0xf90f, 0x23f0, 0x863b, 0x6a8b, 0x1164,
-0xf826, 0xd412, 0x8d7c, 0xade7, 0xbb44, 0xce06, 0x446e, 0x60cd, 0x37d3, 0x464b,
-0x4603, 0xdb1a, 0xadc9, 0xd748, 0xbb79, 0xd2d1, 0x0130, 0x0928, 0x3b0a, 0x4390,
-0x0002, 0xef18, 0x25c7, 0xf662, 0xbcac, 0x1201, 0x1f14, 0xda32, 0xff28, 0x1fbe,
-0xd1ed, 0xd6db, 0x389e, 0x0dbf, 0xf3fb, 0x488e, 0x1c7e, 0xe70e, 0x1374, 0xed9e,
-0xa6a3, 0xedff, 0x24fa, 0xe3d7, 0x2454, 0x55ff, 0xfbf6, 0x19ad, 0x27e2, 0xbe48,
-0xc206, 0x1296, 0xe45b, 0xdd35, 0x4db6, 0x1c33, 0xef46, 0x4348, 0x0b24, 0xb5eb,
-0xf732, 0x126a, 0xcd2b, 0x063c, 0x37c5, 0xec01, 0x18d9, 0x3cc8, 0xd616, 0xd2bc,
-0x273a, 0xf84b, 0xd381, 0x30e7, 0x1385, 0xdff9, 0x30f4, 0x18b0, 0xc10e, 0x0696,
-0x364d, 0xd762, 0xfbf8, 0x3d8c, 0xe397, 0xf63d, 0x3932, 0xe0e0, 0xc7fb, 0x31c6,
-0x0e47, 0xd472, 0x33f1, 0x19cb, 0xd9b6, 0x297e, 0x174d, 0xb770, 0xf385, 0x2b80,
-0xd844, 0x020b, 0x44ae, 0xecdc, 0xffc6, 0x3c84, 0xe59b, 0xc239, 0x1b9c, 0x03d8,
-0xcdfc, 0x284d, 0x2050, 0xe856, 0x29ba, 0x1da6, 0xc79c, 0xf13e, 0x2a8b, 0xdb89,
-0xe7cf, 0x315a, 0xf321, 0xf5f9, 0x332c, 0xf230, 0xc508, 0x1566, 0x093d, 0xce9a,
-0x23e7, 0x1dac, 0xd1bc, 0x1aa1, 0x2c3b, 0xbf9a, 0xd5cb, 0x286f, 0xe374, 0xeccb,
-0x3bb8, 0xfa4b, 0xf5e8, 0x2f2d, 0xe9fe, 0xbb23, 0x0ce2, 0xff3a, 0xc469, 0x2484,
-0x2c01, 0xe186, 0x1b3d, 0x26db, 0xc966, 0xd43c, 0x0cf6, 0xd3cc, 0xeaf1, 0x349d,
-0xf49e, 0xfa1b, 0x3da3, 0xf2ae, 0xb5a2, 0x09f1, 0x0303, 0xbee6, 0x1c15, 0x2f77,
-0xe137, 0x187e, 0x2a96, 0xc3d0, 0xd414, 0x1e88, 0xd685, 0xe774, 0x4a59, 0xfa19,
-0xe6e2, 0x3f71, 0xf365, 0xa657, 0x0aac, 0x0b27, 0xbbf9, 0x22a4, 0x3896, 0xdde2,
-0x1ea6, 0x2ddb, 0xb6a3, 0xcf13, 0x234d, 0xd209, 0xdfcd, 0x4de4, 0x0530, 0xf235,
-0x458e, 0xfe1c, 0xaf9c, 0x04ff, 0x0ba8, 0xc04a, 0x1dfe, 0x3a8f, 0xe44e, 0x1ebd,
-0x3786, 0xc838, 0xd340, 0x2d49, 0xe462, 0xdc75, 0x4606, 0x05e5, 0xe8d6, 0x3e07,
-0x0367, 0xb349, 0x0d09, 0x1be3, 0xc56a, 0x2148, 0x4004, 0xd8d7, 0x1595, 0x3a7d,
-0xc56d, 0xd126, 0x3261, 0xe7bb, 0xe124, 0x5308, 0x0eb8, 0xeb26, 0x437a, 0x042c,
-0xaf26, 0x0eb2, 0x218d, 0xc6ad, 0x22c2, 0x4ab9, 0xe2d2, 0x1874, 0x40cd, 0xca8d,
-0xc838, 0x2e68, 0xedb9, 0xd7fa, 0x4c7a, 0x1526, 0xe7cb, 0x4150, 0x0c9e, 0xae99,
-0x0430, 0x20bb, 0xc1b5, 0x1187, 0x47d4, 0xe4da, 0x1440, 0x42ec, 0xcdff, 0xc6df,
-0x2c13, 0xec08, 0xd2d5, 0x46ed, 0x0ef1, 0xdd36, 0x3d9e, 0x0f6f, 0xadf9, 0x0331,
-0x2434, 0xc516, 0x0f43, 0x4485, 0xde32, 0x0700, 0x3d61, 0xce91, 0xbeff, 0x2926,
-0xf4fa, 0xd134, 0x41a9, 0x1664, 0xdc49, 0x34e2, 0x1333, 0xace3, 0xf361, 0x1f70,
-0xc693, 0x0699, 0x47e9, 0xe934, 0x0537, 0x4024, 0xd7ae, 0xba09, 0x1da8, 0xf1cd,
-0xcbb4, 0x3981, 0x188e, 0xddeb, 0x326b, 0x1892, 0xb095, 0xf130, 0x20bc, 0xc29d,
-0xf9a7, 0x3f9b, 0xe3d4, 0xfb7a, 0x3e64, 0xdf3d, 0xbe59, 0x2395, 0xf6d6, 0xc4b9,
-0x3386, 0x1936, 0xd767, 0x2b7a, 0x1dd1, 0xb547, 0xeefe, 0x2814, 0xcaa5, 0xf817,
-0x487c, 0xeb89, 0xf26b, 0x397c, 0xdf7f, 0xb39b, 0x1c04, 0xfe68, 0xc54d, 0x349f,
-0x2a68, 0xdbdd, 0x22d6, 0x1ddd, 0xb0a0, 0xe0fa, 0x21cc, 0xc993, 0xf898, 0x52ec,
-0xf689, 0xf70a, 0x426a, 0xe741, 0xaf61, 0x151d, 0xf921, 0xc0cc, 0x3886, 0x3002,
-0xdf54, 0x2dc5, 0x25fe, 0xb022, 0xe019, 0x2b01, 0xdc46, 0xdf34, 0x113b, 0xf3ef,
-0x2b9e, 0x5380, 0xf6a9, 0xdedb, 0x2143, 0xe2d9, 0xa1ed, 0xf09b, 0xf0dc, 0xdb67,
-0x3407, 0x5e55, 0x32ca, 0x27e1, 0x25c5, 0xd709, 0xc36a, 0xcfc9, 0xa7f8, 0xea51,
-0x3bd7, 0x0e16, 0x0801, 0x6978, 0x4f5b, 0xdcee, 0xefc1, 0xfe47, 0xbe36, 0xbc03,
-0xf6fb, 0x0a54, 0x1b49, 0x3bd0, 0x15ec, 0x2382, 0x3cb2, 0xeb19, 0xc5aa, 0xedb7,
-0xf957, 0xd7a6, 0xf768, 0x22e7, 0x17a3, 0x2061, 0x1ba7, 0x1fd9, 0x23d8, 0x0c01,
-0xd667, 0xc4b5, 0xfb1e, 0xd994, 0xd7e9, 0x3398, 0x3e92, 0x166b, 0x27af, 0x4ec2,
-0x0515, 0xd7d3, 0xde1a, 0xb994, 0xdcbe, 0xf079, 0xeced, 0x2d31, 0x5f61, 0x253a,
-0x040a, 0x4aa6, 0x0dcf, 0xb7f1, 0xcf3e, 0xd1b1, 0xcf61, 0xe63f, 0x105c, 0x26cc,
-0x431a, 0x31ef, 0x089d, 0x3279, 0x1505, 0xc9c8, 0xbc77, 0xd253, 0xdbe3, 0xd185,
-0x028c, 0x2ef7, 0x3d5b, 0x2ff3, 0x2436, 0x2ecc, 0xffae, 0xd27d, 0xae72, 0xb7bb,
-0xda8b, 0xd2ea, 0x0b5f, 0x4d03, 0x43e6, 0x19f3, 0x2a63, 0x2e3d, 0xdc83, 0xc2d3,
-0xb8a6, 0xbf1e, 0xe681, 0xe9fe, 0x0c02, 0x47ed, 0x4b9b, 0x0b96, 0x1c09, 0x3193,
-0xdad3, 0xc2e7, 0xcba3, 0xc7a2, 0xd979, 0xf765, 0x1768, 0x34eb, 0x4272, 0x0e6d,
-0x1cba, 0x35bf, 0xe2f7, 0xb4ec, 0xc2dc, 0xdbc9, 0xd4b0, 0xeaf5, 0x2a04, 0x3d45,
-0x3135, 0x163c, 0x29bf, 0x1de9, 0xd862, 0xb512, 0xbc25, 0xe60f, 0xdb2d, 0xe4e1,
-0x2e4c, 0x46ed, 0x2280, 0x0c95, 0x3390, 0x0dba, 0xc912, 0xc227, 0xbe99, 0xd9c1,
-0xe290, 0xed33, 0x2239, 0x44f4, 0x1ed4, 0x0166, 0x3720, 0x122c, 0xc1e5, 0xbe0b,
-0xcc00, 0xd5f1, 0xd17f, 0xf3b3, 0x23a2, 0x3db4, 0x2624, 0x0cc4, 0x33e1, 0x1023,
-0xc9ae, 0xb631, 0xc8cd, 0xdd8a, 0xceea, 0xfaf7, 0x3621, 0x3ded, 0x1ca5, 0x1b0d,
-0x3ba6, 0x0216, 0xce92, 0xc394, 0xc90e, 0xdd1a, 0xd9c7, 0x0438, 0x3a3b, 0x43f5,
-0x193b, 0x1b93, 0x427f, 0xfe8c, 0xc66d, 0xc591, 0xd58c, 0xe393, 0xe1bc, 0x0fe2,
-0x3df6, 0x448e, 0x1c8a, 0x21c0, 0x3e71, 0xf9bd, 0xc96f, 0xc456, 0xd5d9, 0xe4b5,
-0xe922, 0x1ce5, 0x418b, 0x417b, 0x1d09, 0x2518, 0x341d, 0xf03a, 0xcbea, 0xc1e1,
-0xd6e8, 0xe7f3, 0xe55f, 0x1d2e, 0x4954, 0x3f9e, 0x1b23, 0x31e7, 0x3163, 0xe580,
-0xcb7b, 0xbe90, 0xd27b, 0xe98e, 0xede5, 0x22f3, 0x51cc, 0x440f, 0x174a, 0x3744,
-0x308b, 0xdab4, 0xc2e8, 0xc03f, 0xd50d, 0xe3f9, 0xf766, 0x2e0e, 0x4fbc, 0x4269,
-0x17f2, 0x2ec2, 0x1f55, 0xd524, 0xbca2, 0xbb93, 0xda21, 0xe34e, 0xfad1, 0x31b6,
-0x47da, 0x36e7, 0x19ff, 0x2ef6, 0x0ef3, 0xd0a0, 0xb94c, 0xb54a, 0xdd97, 0xe171,
-0xf86b, 0x35bc, 0x47ba, 0x2983, 0x1694, 0x3324, 0x023b, 0xc961, 0xbc03, 0xb2d4,
-0xd7d9, 0xe2e7, 0xf9f7, 0x3391, 0x4b1a, 0x23f3, 0x1255, 0x2f9f, 0xf2dd, 0xbf1b,
-0xb8c8, 0xb595, 0xd67b, 0xe49e, 0x04eb, 0x3553, 0x491e, 0x20bc, 0x101c, 0x2d09,
-0xefb9, 0xbc9b, 0xb456, 0xbc74, 0xdcb8, 0xe7e3, 0x1085, 0x3e2d, 0x4862, 0x20a4,
-0x178e, 0x24e7, 0xe5be, 0xbfc5, 0xb5ac, 0xc6ce, 0xe4c1, 0xe9df, 0x156b, 0x41e6,
-0x4347, 0x169b, 0x1dcf, 0x2537, 0xdbdb, 0xbd60, 0xb4ac, 0xc74f, 0xe58f, 0xf1d1,
-0x1bdb, 0x438d, 0x41e3, 0x1215, 0x1c5f, 0x197b, 0xd34e, 0xbb05, 0xb7f2, 0xd3b2,
-0xe362, 0xf0f9, 0x2581, 0x46a8, 0x3c22, 0x115f, 0x2009, 0x122f, 0xd304, 0xbd34,
-0xb54b, 0xd890, 0xe911, 0xf7d8, 0x2be6, 0x4644, 0x3124, 0x11c4, 0x2d7b, 0x0ee0,
-0xcfc2, 0xc445, 0xbf59, 0xdf01, 0xe6a3, 0xf6fe, 0x2fa7, 0x4f24, 0x32c6, 0x10fe,
-0x360f, 0x14d0, 0xd1fe, 0xc5f6, 0xc3cd, 0xdf16, 0xe84d, 0x00f9, 0x3302, 0x4f34,
-0x330f, 0x190f, 0x3c38, 0x0f70, 0xcd2f, 0xc1c9, 0xccf8, 0xe5e1, 0xe528, 0x0d0a,
-0x3fdc, 0x4c89, 0x2965, 0x1572, 0x3558, 0x0773, 0xcf30, 0xbe56, 0xcfa1, 0xeeb4,
-0xe390, 0x0d40, 0x446b, 0x47d6, 0x22c9, 0x1f4d, 0x33f7, 0xf611, 0xcd9c, 0xbd57,
-0xc66d, 0xec7d, 0xe7bf, 0x0df9, 0x474d, 0x4b43, 0x1b2f, 0x1f2d, 0x35f1, 0xea3c,
-0xc455, 0xbc6b, 0xc16f, 0xe41e, 0xef9d, 0x16e5, 0x457b, 0x4d9b, 0x1df1, 0x2052,
-0x310e, 0xe35e, 0xbd3b, 0xbe4a, 0xd17b, 0xe63a, 0xf0dd, 0x2445, 0x4bde, 0x4c1f,
-0x20d2, 0x25a1, 0x2da1, 0xe9a8, 0xc288, 0xb909, 0xd9c6, 0xee3e, 0xf6a6, 0x2ef9,
-0x50a3, 0x43ee, 0x1dd3, 0x2eed, 0x2309, 0xe027, 0xcabc, 0xbd16, 0xdbde, 0xee25,
-0xf339, 0x2c27, 0x5390, 0x40a0, 0x1b96, 0x375c, 0x1d2b, 0xd734, 0xc78b, 0xb807,
-0xd541, 0xecee, 0xfe54, 0x2fa0, 0x5361, 0x3f28, 0x1522, 0x3393, 0x1266, 0xc88d,
-0xbc85, 0xb8d2, 0xd4a8, 0xe5ab, 0x0438, 0x3396, 0x4c0c, 0x33cd, 0x0a79, 0x2169,
-0xfe45, 0xc2f1, 0xb2f9, 0xb954, 0xe0e9, 0xe165, 0x029e, 0x2aa5, 0x318e, 0x465f,
-0x33d0, 0x0444, 0xd0f3, 0xc734, 0xa46c, 0x9309, 0xec1b, 0xfbdf, 0x010e, 0x6440,
-0x7e13, 0x1ed8, 0xeedd, 0xe7dd, 0x9c36, 0x94bd, 0xaeea, 0xb4e6, 0x08d9, 0x4ccc,
-0x44d3, 0x3995, 0x43b3, 0xfbc8, 0xa9f8, 0xbc47, 0xb7e9, 0xb05c, 0xd4b9, 0x0205,
-0x2fad, 0x38f1, 0x145d, 0xf759, 0x0aec, 0xf6cf, 0xb93a, 0xdb0a, 0x14b9, 0xe52f,
-0xdb64, 0x2275, 0xfc04, 0xc169, 0x1482, 0x2708, 0xda58, 0x13ad, 0x34f3, 0xe68c,
-0xf5c6, 0x0b27, 0xbfca, 0xc11f, 0x1a39, 0xf895, 0xf15a, 0x535e, 0x1fbe, 0xfd1c,
-0x2fab, 0xeb46, 0xb207, 0xf114, 0xfe7d, 0xd0f4, 0x2a5f, 0x4be3, 0xf98f, 0x2db3,
-0x365b, 0xcbe5, 0xd12f, 0x160e, 0xe93e, 0xe29c, 0x4478, 0x1d6f, 0x0413, 0x49f1,
-0x0cdb, 0xc582, 0x08ff, 0x1ce3, 0xd295, 0x10d4, 0x44fb, 0xeff9, 0x15bb, 0x4310,
-0xddfd, 0xd8c9, 0x34f7, 0xfaaf, 0xd716, 0x4457, 0x1cff, 0xe28a, 0x3514, 0x1237,
-0xb5a9, 0x01cc, 0x3075, 0xd90a, 0x1130, 0x4b8f, 0xf1cd, 0x0fee, 0x37f4, 0xcf77,
-0xc32c, 0x262d, 0xfb1f, 0xde11, 0x4cfa, 0x220f, 0xe7b6, 0x379f, 0x1630, 0xb473,
-0xeb2b, 0x1f40, 0xcdde, 0xfb49, 0x44ba, 0xf7a8, 0x0b44, 0x3ad4, 0xdf56, 0xbc11,
-0x192e, 0xfdae, 0xc1e6, 0x2be2, 0x260a, 0xe13b, 0x285b, 0x1e09, 0xb912, 0xe471,
-0x2223, 0xd36d, 0xfe2f, 0x46c5, 0xe36b, 0xf7a8, 0x4755, 0xdf55, 0xa7b3, 0x1a23,
-0x0b84, 0xc893, 0x2faf, 0x2991, 0xe2bb, 0x2481, 0x13cb, 0xb383, 0xe0a3, 0x1702,
-0xc7e4, 0xf45d, 0x4b67, 0xf6a6, 0xf97a, 0x3e6f, 0xecd9, 0xadf3, 0xfeb4, 0xfd06,
-0xc788, 0x1f7a, 0x200a, 0xe5ba, 0x31ba, 0x2511, 0xb3da, 0xe100, 0x2776, 0xc990,
-0xe1ba, 0x44f0, 0xef0a, 0xe6e3, 0x3c2c, 0xf024, 0xb397, 0x1376, 0x054e, 0xc2a5,
-0x2c7f, 0x2067, 0xc5d1, 0x227f, 0x2507, 0xa6ee, 0xd8b4, 0x2da2, 0xd0d2, 0xe5d2,
-0x4ae3, 0xf3c8, 0xec01, 0x3d1d, 0xe4c8, 0xa76d, 0x0cd7, 0x02fe, 0xc051, 0x2a3f,
-0x2ff4, 0xd96d, 0x206e, 0x2cdb, 0xbcc2, 0xcfce, 0x1d9e, 0xd936, 0xe286, 0x3c62,
-0xf899, 0xf161, 0x4188, 0xfacc, 0xb89c, 0x13b2, 0x0f18, 0xbfc2, 0x1908, 0x2b9b,
-0xdd40, 0x1c58, 0x31c8, 0xcc18, 0xe1de, 0x3029, 0xe1a2, 0xeab8, 0x4814, 0xf8bb,
-0xec3b, 0x41cd, 0xfd3d, 0xbb42, 0x1ab1, 0x1bc5, 0xd03f, 0x2b94, 0x39e6, 0xe56b,
-0x20f6, 0x302f, 0xc7e3, 0xe07e, 0x304b, 0xe35d, 0xef37, 0x556b, 0x0a77, 0xf3f3,
-0x471e, 0x0715, 0xb6bf, 0x0a15, 0x15a7, 0xc8f0, 0x27ce, 0x49e1, 0xef3f, 0x24d8,
-0x3fc8, 0xcf85, 0xd3a9, 0x2981, 0xe391, 0xe1e2, 0x5568, 0x1a44, 0xf6f8, 0x47a5,
-0x0bb1, 0xb4f6, 0x0758, 0x180f, 0xc264, 0x1c7f, 0x4997, 0xe7b6, 0x1790, 0x3eec,
-0xcc71, 0xc989, 0x25c5, 0xe0ff, 0xd5eb, 0x4cb5, 0x1585, 0xe9fb, 0x3f4e, 0x079f,
-0xa4e8, 0xf8b6, 0x18b7, 0xbe0e, 0x140f, 0x4dcd, 0xe6f8, 0x106e, 0x3e48, 0xc659,
-0xb8d1, 0x1fc6, 0xe2f7, 0xcafc, 0x4b21, 0x1aac, 0xddf9, 0x38ef, 0x0d86, 0xa172,
-0xefb8, 0x1ae3, 0xb8b9, 0x022b, 0x4952, 0xe3b7, 0x0763, 0x3fb6, 0xcaa1, 0xb546,
-0x2034, 0xe7b3, 0xc26e, 0x4341, 0x1b44, 0xd872, 0x37f9, 0x158c, 0xa302, 0xed16,
-0x212e, 0xbda6, 0x0112, 0x4eb5, 0xe481, 0x0180, 0x448c, 0xd2be, 0xb34a, 0x2659,
-0xf969, 0xc3e7, 0x4253, 0x2498, 0xd3ac, 0x2f84, 0x1c93, 0xa86a, 0xeae4, 0x2be9,
-0xc824, 0xfb1e, 0x5254, 0xeb1f, 0xf85a, 0x40c6, 0xd602, 0xacc6, 0x20d2, 0xfcc1,
-0xbfa1, 0x3d9b, 0x2b83, 0xd669, 0x2fcc, 0x202d, 0xa65f, 0xe170, 0x2e20, 0xdd4c,
-0xe4e8, 0x1128, 0xe9c6, 0x2b2e, 0x54f5, 0xec68, 0xd881, 0x25b3, 0xe44f, 0x9e7f,
-0xf130, 0xeb8e, 0xd492, 0x3413, 0x5451, 0x26e6, 0x289d, 0x2623, 0xcf51, 0xbd9d,
-0xcfb5, 0xa20d, 0xdfe7, 0x36b7, 0x0cc4, 0x056d, 0x65fe, 0x4dbe, 0xdc03, 0xeb0b,
-0xf3c5, 0xb95e, 0xbfab, 0xf463, 0x0575, 0x1cd4, 0x3d59, 0x1332, 0x1c9e, 0x36b2,
-0xe6ff, 0xc1d2, 0xebab, 0xf875, 0xd9ed, 0xf751, 0x1ec8, 0x177a, 0x1fdf, 0x14b0,
-0x158a, 0x1d8b, 0x09a1, 0xd3cc, 0xc301, 0xfa03, 0xda41, 0xd913, 0x31d2, 0x3bcd,
-0x1398, 0x2276, 0x47f0, 0x04ad, 0xdb13, 0xde05, 0xbc40, 0xe0b4, 0xf233, 0xedf8,
-0x2b4d, 0x5c62, 0x258d, 0x04db, 0x4756, 0x0b9d, 0xbaa9, 0xd2dc, 0xd3e6, 0xd2e5,
-0xeb10, 0x1044, 0x260b, 0x4492, 0x307c, 0x0989, 0x37e3, 0x1952, 0xc9b1, 0xbe5d,
-0xd980, 0xdd51, 0xcfb1, 0x0665, 0x3440, 0x3f66, 0x32e5, 0x2caa, 0x3828, 0x04a2,
-0xd6f3, 0xb98c, 0xc152, 0xdc75, 0xd7fc, 0x131d, 0x50a8, 0x4584, 0x218f, 0x39e9,
-0x3a8c, 0xe3c0, 0xca56, 0xc147, 0xc3c0, 0xe3a0, 0xec33, 0x13df, 0x4aaa, 0x4c83,
-0x117c, 0x2896, 0x399a, 0xdc86, 0xc6f6, 0xcd47, 0xc6ce, 0xd9cc, 0xf86e, 0x19ad,
-0x3a91, 0x491f, 0x123e, 0x24d9, 0x3cde, 0xe11b, 0xb37c, 0xc2df, 0xd7a4, 0xd130,
-0xef29, 0x2c49, 0x3d20, 0x37d9, 0x16ea, 0x291c, 0x26ac, 0xda1f, 0xaaed, 0xb607,
-0xe686, 0xd568, 0xe17d, 0x337f, 0x4b43, 0x2881, 0x1389, 0x38c7, 0x12c8, 0xcd26,
-0xbcc3, 0xb56e, 0xdd1b, 0xe483, 0xea42, 0x2a90, 0x51ed, 0x261e, 0x0805, 0x4126,
-0x1494, 0xbddc, 0xbaf3, 0xc450, 0xd324, 0xd5cd, 0xf712, 0x2ef6, 0x4d20, 0x2af3,
-0x0e0c, 0x3762, 0x0ac6, 0xbe79, 0xae49, 0xc076, 0xd8d1, 0xd3ec, 0x0029, 0x3a43,
-0x4756, 0x22ca, 0x1958, 0x35d2, 0xf721, 0xbeb2, 0xb3fe, 0xbef0, 0xda1f, 0xdc92,
-0x07d3, 0x4050, 0x4bd0, 0x19d3, 0x154a, 0x3522, 0xefeb, 0xbbc4, 0xb715, 0xc994,
-0xdf48, 0xe0b3, 0x1046, 0x40b6, 0x462c, 0x16f6, 0x1aab, 0x3230, 0xe981, 0xbd2a,
-0xbab3, 0xd2a2, 0xe5c9, 0xe97f, 0x1c0b, 0x466f, 0x4272, 0x167d, 0x2642, 0x3042,
-0xe930, 0xc684, 0xbe13, 0xdccc, 0xed63, 0xea9d, 0x2413, 0x5441, 0x43f9, 0x180c,
-0x36e2, 0x2e3f, 0xdd7b, 0xc957, 0xc358, 0xdaa2, 0xeec1, 0xf6ba, 0x27c0, 0x5560,
-0x448c, 0x1635, 0x38ef, 0x285a, 0xd524, 0xc336, 0xc6ef, 0xdd82, 0xe86a, 0x024a,
-0x3514, 0x5243, 0x4024, 0x1679, 0x30ad, 0x19cb, 0xd2e3, 0xbea4, 0xc57f, 0xe4e0,
-0xe5d6, 0xfff4, 0x3873, 0x4af7, 0x2f8e, 0x188b, 0x3243, 0x0881, 0xcd5e, 0xbb93,
-0xbf31, 0xe52f, 0xe3f9, 0xfc94, 0x39c7, 0x4714, 0x1d41, 0x169d, 0x38c9, 0xfecd,
-0xcb1a, 0xc0fc, 0xbdbe, 0xdc75, 0xe1b5, 0xfaa7, 0x3213, 0x48a1, 0x1b68, 0x15dc,
-0x3a99, 0xf55f, 0xc01b, 0xbf71, 0xc2a6, 0xd4e4, 0xdf4d, 0x066a, 0x3170, 0x40f1,
-0x1a26, 0x18e0, 0x342c, 0xedf9, 0xba41, 0xb3b4, 0xc38e, 0xd795, 0xe02b, 0x10cf,
-0x387d, 0x3bf9, 0x151b, 0x1afe, 0x254b, 0xde99, 0xbc43, 0xb3bd, 0xc921, 0xde4a,
-0xe189, 0x1332, 0x3ec6, 0x3af6, 0x0d82, 0x1fcf, 0x23ba, 0xd6bf, 0xb847, 0xb180,
-0xcc73, 0xe0cc, 0xeb2b, 0x1cb5, 0x417e, 0x395b, 0x0e37, 0x260e, 0x1c37, 0xceea,
-0xb693, 0xb466, 0xd44d, 0xde55, 0xeccf, 0x28e9, 0x4c64, 0x3a26, 0x1085, 0x2a16,
-0x12d5, 0xcc04, 0xb7f6, 0xb4e4, 0xda25, 0xe424, 0xf801, 0x3387, 0x4c82, 0x2ff0,
-0x133d, 0x33da, 0x0a6a, 0xc653, 0xba9f, 0xb9a4, 0xdb0d, 0xe2d3, 0xfd70, 0x3932,
-0x535b, 0x2ec6, 0x131d, 0x36f2, 0x041c, 0xc4de, 0xbc13, 0xbb88, 0xdb49, 0xe632,
-0x0792, 0x3bf9, 0x5215, 0x2df5, 0x197b, 0x38ba, 0xfc1c, 0xc000, 0xb9c1, 0xc559,
-0xe3b9, 0xea55, 0x13bb, 0x45e0, 0x506f, 0x2598, 0x1a8a, 0x31d4, 0xf25d, 0xc2c1,
-0xb752, 0xc926, 0xeaa3, 0xebad, 0x18ac, 0x4b3a, 0x4b14, 0x1dc9, 0x246e, 0x2f24,
-0xe2ff, 0xc4be, 0xbca8, 0xccb7, 0xee7a, 0xf1d7, 0x1fad, 0x5446, 0x4e8c, 0x1a55,
-0x2bfd, 0x2de3, 0xdbcc, 0xc7c4, 0xc19e, 0xcdf0, 0xeebf, 0x0347, 0x2b46, 0x50aa,
-0x4efc, 0x1ae7, 0x2bc2, 0x29fc, 0xd661, 0xbcdd, 0xc496, 0xddc3, 0xe917, 0xff6c,
-0x336f, 0x4f83, 0x433f, 0x1820, 0x2877, 0x176c, 0xd63d, 0xbf37, 0xbd41, 0xe3e4,
-0xec70, 0xfccc, 0x35e8, 0x4cad, 0x2f68, 0x12a7, 0x2fac, 0x08d7, 0xcd76, 0xc4f5,
-0xbf59, 0xdfbb, 0xe9f3, 0xfd34, 0x3194, 0x4aa3, 0x2767, 0x0f36, 0x33c2, 0x0048,
-0xc54f, 0xc2fd, 0xbd10, 0xd605, 0xe41c, 0xff51, 0x2a83, 0x4801, 0x28e6, 0x0aff,
-0x2f62, 0xfdb7, 0xbd39, 0xb775, 0xc18e, 0xd7dc, 0xe021, 0x0a7d, 0x33af, 0x423a,
-0x2081, 0x0d26, 0x28f2, 0xf6aa, 0xc604, 0xb20f, 0xca22, 0xf929, 0xe0c9, 0xfe41,
-0x2c91, 0x285c, 0x3479, 0x40e1, 0x11dd, 0xd23c, 0xd207, 0xa861, 0xa807, 0xfe96,
-0xf904, 0x0d6b, 0x7934, 0x78f8, 0x0f08, 0xfce1, 0xe859, 0x8e1b, 0xa714, 0xc4a3,
-0xd05d, 0x3229, 0x6379, 0x4af3, 0x48ea, 0x4a2d, 0xe67d, 0xa875, 0xd782, 0xc120,
-0xb7cb, 0xfb9f, 0x1f2e, 0x34e8, 0x4bf0, 0x20cd, 0xf0b2, 0x1643, 0x0563, 0xbcd0,
-0xf27f, 0x2741, 0xe7cd, 0xef58, 0x2d5f, 0xebc6, 0xc657, 0x2de0, 0x1cb6, 0xe47e,
-0x4360, 0x2d6e, 0xe23e, 0x16ee, 0xf98d, 0xa445, 0xddbb, 0x207f, 0xe2c0, 0x123e,
-0x5bce, 0x016d, 0x1099, 0x3582, 0xc93d, 0xb242, 0x0573, 0xeaa3, 0xcd42, 0x3ec8,
-0x2edf, 0xedf6, 0x39f9, 0x19b8, 0xb85b, 0xe3bc, 0x1369, 0xd1a8, 0xf1db, 0x3e71,
-0xf679, 0x05fa, 0x4211, 0xe5a8, 0xbfbb, 0x17fb, 0x0686, 0xc767, 0x1e4b, 0x24e5,
-0xdea8, 0x2460, 0x26bf, 0xbfbf, 0xebef, 0x3662, 0xdb5b, 0xe735, 0x478f, 0xf36f,
-0xe6aa, 0x3a12, 0xedab, 0xb885, 0x2168, 0x1a11, 0xd137, 0x2b7c, 0x29a9, 0xd6be,
-0x2004, 0x24d0, 0xb744, 0xddad, 0x2f52, 0xe201, 0xeeef, 0x4b3b, 0xfc02, 0xef7b,
-0x3d92, 0xf6b9, 0xb6be, 0x0b17, 0x0d77, 0xc534, 0x191c, 0x30b3, 0xe945, 0x23b0,
-0x2f3b, 0xc9bb, 0xd7dc, 0x269c, 0xe46c, 0xd902, 0x3766, 0x0212, 0xeb25, 0x39af,
-0x03e0, 0xb8e7, 0x077c, 0x169d, 0xcc6f, 0x1b10, 0x2e0e, 0xd19a, 0x0fd8, 0x38f6,
-0xca91, 0xc8f9, 0x29d6, 0xf078, 0xdd5c, 0x3b96, 0x09ef, 0xf001, 0x3507, 0xfbb1,
-0xb660, 0x03d5, 0x0e0a, 0xc387, 0x17f0, 0x3e5b, 0xe93c, 0x15a4, 0x38a5, 0xd46a,
-0xc5fe, 0x1360, 0xe4bc, 0xda9b, 0x39bc, 0x0c8d, 0xef2a, 0x3f9f, 0x0fdb, 0xb193,
-0xf8d2, 0x1694, 0xb855, 0xffea, 0x4558, 0xed39, 0x083b, 0x3cd1, 0xda45, 0xc36d,
-0x1e6e, 0xe476, 0xc765, 0x430f, 0x19a5, 0xde45, 0x3c55, 0x16d3, 0xa619, 0xf171,
-0x1f0a, 0xbe1b, 0x04f9, 0x4d9d, 0xeec4, 0x0d1f, 0x3e78, 0xccbe, 0xb49f, 0x1d9b,
-0xeb29, 0xc2b6, 0x448d, 0x28e1, 0xe2a4, 0x3aab, 0x21b9, 0xad2c, 0xe5d9, 0x1d14,
-0xbe21, 0xf5ec, 0x4db1, 0xef99, 0x030b, 0x4e45, 0xe3cc, 0xb105, 0x20c5, 0xfc50,
-0xb9ac, 0x35e2, 0x2898, 0xd9cf, 0x3397, 0x236d, 0xace6, 0xea90, 0x2c38, 0xc65d,
-0xf7eb, 0x5313, 0xe39f, 0xf211, 0x477a, 0xdbe9, 0xad7a, 0x1ffa, 0x0017, 0xc201,
-0x3906, 0x27ff, 0xd56a, 0x2d70, 0x20b7, 0xa843, 0xe22b, 0x2d3a, 0xc8d1, 0xeff9,
-0x5809, 0xf171, 0xf1ca, 0x4aa1, 0xe752, 0xa7f6, 0x1531, 0x03a8, 0xbd38, 0x3515,
-0x35e4, 0xd873, 0x2cec, 0x2fa3, 0xaedb, 0xd92e, 0x2cc6, 0xccea, 0xe531, 0x5116,
-0xf947, 0xf6dd, 0x4ce8, 0xef45, 0xaeac, 0x190f, 0x0bfc, 0xbc68, 0x2afb, 0x3612,
-0xd723, 0x2687, 0x3899, 0xbdfb, 0xda26, 0x3069, 0xdbaf, 0xe6bf, 0x5016, 0x0057,
-0xf1d5, 0x480e, 0xf64b, 0xad29, 0x13a0, 0x16f4, 0xc33e, 0x2614, 0x4041, 0xe193,
-0x201a, 0x3648, 0xc1be, 0xd35e, 0x2aee, 0xe031, 0xe3b6, 0x52de, 0x0b18, 0xedc3,
-0x4b67, 0x084a, 0xaf95, 0x0ccc, 0x1af7, 0xc089, 0x19da, 0x4369, 0xe6d2, 0x1d97,
-0x422d, 0xcfe2, 0xd1f7, 0x2e93, 0xe6d4, 0xd904, 0x4acc, 0x0d46, 0xe47d, 0x425b,
-0x0eb4, 0xb1bb, 0x06af, 0x2009, 0xc469, 0x12a4, 0x3fee, 0xdd98, 0x0e0f, 0x3d40,
-0xcdb1, 0xc9b2, 0x2f38, 0xedc8, 0xcf7d, 0x42ef, 0x1026, 0xd9af, 0x3710, 0x1033,
-0xad12, 0xfd62, 0x2285, 0xc358, 0x0c72, 0x48be, 0xe51c, 0x0a9a, 0x2ff8, 0xbdc8,
-0xc28d, 0x2cc9, 0xfec9, 0xc7ca, 0x13e5, 0x17e1, 0x02ca, 0x35c6, 0x0fac, 0xcd93,
-0xf8c0, 0xfbac, 0xbba6, 0xe67f, 0x0735, 0xd6a6, 0x1bde, 0x7350, 0x2eb9, 0xfad9,
-0x2334, 0xeee4, 0xa104, 0xc9e5, 0xcf89, 0xd376, 0x2f8b, 0x2f58, 0x13f9, 0x6199,
-0x5172, 0xd760, 0xdae6, 0x0109, 0xaaab, 0x9f01, 0x11f6, 0x1c74, 0xff8b, 0x303b,
-0x3d89, 0x2a49, 0x1900, 0xe5d6, 0xbb94, 0xe00a, 0xeeb6, 0xce23, 0x0253, 0x3291,
-0x20e8, 0x0d77, 0x2650, 0x2ac1, 0xf46d, 0xf971, 0xdbe5, 0xc599, 0xf13a, 0xdd86,
-0xebfb, 0x30a4, 0x422d, 0x0726, 0x20e1, 0x53cf, 0xe990, 0xbf8d, 0xd717, 0xc738,
-0xcc12, 0xed69, 0x1207, 0x2679, 0x4b59, 0x2072, 0x0f6e, 0x3b3c, 0xef93, 0xaf82,
-0xc07e, 0xdcf5, 0xccea, 0xe17b, 0x31b5, 0x3ad1, 0x3673, 0x24ae, 0x1fad, 0x2260,
-0xf0dd, 0xc29e, 0xb494, 0xe43c, 0xe377, 0xdb2b, 0x2318, 0x45fc, 0x34e0, 0x20c4,
-0x3ea5, 0x232d, 0xdb31, 0xcc1d, 0xb320, 0xc65a, 0xdf18, 0xea47, 0x25f0, 0x5cd4,
-0x4386, 0x10e7, 0x3d78, 0x214b, 0xc538, 0xbca9, 0xbe8b, 0xcd16, 0xe049, 0x05f5,
-0x2fe8, 0x5197, 0x45f2, 0x0fc2, 0x2f2f, 0x1971, 0xc5a7, 0xb7fc, 0xca80, 0xd975,
-0xd7df, 0x0c99, 0x3a4e, 0x3fc6, 0x30e6, 0x13a0, 0x2b87, 0x0f79, 0xcd82, 0xaf27,
-0xc107, 0xe381, 0xd5f3, 0x035c, 0x44e6, 0x44fc, 0x1db9, 0x1e95, 0x3a4e, 0xf713,
-0xc17f, 0xb545, 0xc44b, 0xea43, 0xe0b2, 0x034f, 0x458e, 0x4e96, 0x1557, 0x1819,
-0x3caa, 0xeb53, 0xb81f, 0xc29d, 0xcb34, 0xd827, 0xea2e, 0x153f, 0x3683, 0x4599,
-0x17a8, 0x1025, 0x3238, 0xefae, 0xb3df, 0xb7d0, 0xd811, 0xd6f7, 0xd85a, 0x1792,
-0x3a94, 0x35ea, 0x1657, 0x21c8, 0x243d, 0xdfb1, 0xbb30, 0xb0e9, 0xceed, 0xddbf,
-0xdff2, 0x1be1, 0x44e0, 0x3265, 0x0879, 0x260d, 0x1f6a, 0xcd4c, 0xba1b, 0xbafd,
-0xcb3d, 0xd899, 0xeb07, 0x19d6, 0x3c13, 0x3544, 0x08ed, 0x2407, 0x1daa, 0xcd68,
-0xb792, 0xbf01, 0xd1c2, 0xd611, 0xf34b, 0x259b, 0x3b2f, 0x2f39, 0x1053, 0x2d78,
-0x1a05, 0xd265, 0xba97, 0xc02a, 0xdab7, 0xd903, 0xf86d, 0x2ff9, 0x403d, 0x28d3,
-0x14a1, 0x34af, 0x0a0e, 0xcda4, 0xc3ac, 0xc13a, 0xdd8d, 0xe2ea, 0xfd27, 0x2eb2,
-0x45ac, 0x26be, 0x14ec, 0x3dd9, 0x06bc, 0xc81d, 0xc6e2, 0xc719, 0xd8c3, 0xe5c7,
-0x0b66, 0x32c9, 0x4b92, 0x2cb4, 0x19ce, 0x3c10, 0x0272, 0xc5eb, 0xbb96, 0xccd7,
-0xe07a, 0xdfbb, 0x160a, 0x4341, 0x4749, 0x2676, 0x21c7, 0x2fd3, 0xf0d0, 0xc6ee,
-0xb624, 0xcad8, 0xe85f, 0xe7c5, 0x1d81, 0x4b84, 0x45af, 0x1eba, 0x2c0d, 0x30c1,
-0xe4ba, 0xca8d, 0xbdbe, 0xcc89, 0xed50, 0xf3dd, 0x2203, 0x5159, 0x4cd1, 0x1b22,
-0x2e08, 0x3255, 0xe28f, 0xc7e6, 0xc2e3, 0xd510, 0xe8de, 0xfa14, 0x2846, 0x4a33,
-0x4c04, 0x1fed, 0x2f64, 0x2cdb, 0xe195, 0xc51d, 0xc13f, 0xdb62, 0xe696, 0xfa3e,
-0x31bd, 0x4d3c, 0x4355, 0x2150, 0x33b3, 0x204a, 0xe0d7, 0xc877, 0xbdd9, 0xdeff,
-0xeb46, 0x0024, 0x3a0c, 0x5485, 0x3c57, 0x1fe4, 0x3a57, 0x110e, 0xd1f0, 0xc4f8,
-0xbfae, 0xe303, 0xf0e8, 0x0757, 0x3795, 0x525c, 0x364d, 0x163e, 0x3411, 0x078d,
-0xc95e, 0xbed3, 0xc146, 0xdd79, 0xe8cb, 0x0fb0, 0x3b8b, 0x4b40, 0x2f52, 0x1708,
-0x2c9b, 0xf6f7, 0xc33e, 0xb8f8, 0xc0a0, 0xe27b, 0xe6d8, 0x0c22, 0x3d9b, 0x4878,
-0x24a6, 0x186c, 0x2467, 0xe600, 0xc014, 0xb323, 0xbc0b, 0xe0eb, 0xe8da, 0x0f11,
-0x3cef, 0x40c5, 0x12df, 0x1430, 0x227a, 0xdb2e, 0xb8c4, 0xb5de, 0xc528, 0xdd7a,
-0xe824, 0x13d4, 0x3e15, 0x4384, 0x124e, 0x1469, 0x1e10, 0xd6df, 0xb7fb, 0xb8e3,
-0xcdaf, 0xdd42, 0xecbb, 0x1e7d, 0x3c6f, 0x378a, 0x1149, 0x1e8a, 0x1b08, 0xd447,
-0xb3c7, 0xb0b3, 0xd341, 0xe16d, 0xebda, 0x22db, 0x4450, 0x345d, 0x0fcd, 0x27aa,
-0x137c, 0xcfd2, 0xc241, 0xbb1b, 0xd538, 0xe771, 0xf62c, 0x297f, 0x4c37, 0x3271,
-0x103e, 0x360c, 0x143c, 0xc8cb, 0xc2e2, 0xc46f, 0xd919, 0xe83f, 0x0316, 0x2e44,
-0x49f7, 0x320d, 0x1102, 0x34eb, 0x0f20, 0xc998, 0xc1e5, 0xc68b, 0xd8b7, 0xe3aa,
-0x0e51, 0x3839, 0x473d, 0x306d, 0x1936, 0x313b, 0x023a, 0xca3b, 0xb9cb, 0xc4e8,
-0xe9a8, 0xe8e8, 0x0e4f, 0x4390, 0x4a72, 0x23d2, 0x1d52, 0x31ca, 0xf0b0, 0xc813,
-0xbd25, 0xc202, 0xe6ea, 0xee18, 0x12c8, 0x4476, 0x4b2e, 0x198b, 0x19a1, 0x2fcc,
-0xe518, 0xbf8d, 0xbe9e, 0xcb6d, 0xe622, 0xee0e, 0x167e, 0x3fbf, 0x46fb, 0x1a7d,
-0x1f4e, 0x2d08, 0xe17f, 0xbedd, 0xbaa3, 0xcc16, 0xe196, 0xeedc, 0x21cc, 0x44ed,
-0x4348, 0x1a18, 0x2363, 0x242e, 0xdc65, 0xbd61, 0xb300, 0xcfa0, 0xe712, 0xe5c7,
-0x169f, 0x5f17, 0x7299, 0x2bb1, 0x0b65, 0xe2fd, 0x9b1c, 0xa3b5, 0xaeb5, 0xe147,
-0x3787, 0x593a, 0x5290, 0x4a3c, 0x2e69, 0xcbb4, 0xa91f, 0xc5a3, 0xbd85, 0xd07b,
-0x1055, 0x3d01, 0x2411, 0x222c, 0x2b1a, 0x0b05, 0xffdc, 0xe3f2, 0xcf8c, 0xf390,
-0x15ad, 0xd9f5, 0xc944, 0x2d37, 0x09de, 0xc93f, 0x0d00, 0x229d, 0x0eb5, 0x31fb,
-0x193d, 0xdefd, 0x0b6e, 0xe2b8, 0x80c1, 0xd2cb, 0x1719, 0xe9c2, 0x3008, 0x6a8a,
-0xfee8, 0x01bc, 0x299a, 0xb39d, 0xa48f, 0x0798, 0xe5e9, 0xddfa, 0x41e1, 0x17dc,
-0xf43b, 0x3829, 0x05c3, 0xbd89, 0xf1bc, 0x0dab, 0xcd37, 0xfad8, 0x2e14, 0xf080,
-0x107b, 0x24ea, 0xd852, 0xd4a0, 0x17fd, 0xfd24, 0xd818, 0x2b57, 0x168d, 0xdb81,
-0x1759, 0x0cdb, 0xc867, 0xf2e6, 0x257d, 0xe349, 0xfff1, 0x39a1, 0xe33d, 0xee45,
-0x2b9d, 0xe388, 0xc702, 0x21a8, 0x103e, 0xda0f, 0x2f4b, 0x1b70, 0xd6c1, 0x1b55,
-0x104d, 0xb577, 0xe811, 0x28c6, 0xe0aa, 0xfee3, 0x4403, 0xf56f, 0xf711, 0x2c32,
-0xe60a, 0xbd96, 0x0d61, 0x048f, 0xce3d, 0x272f, 0x325d, 0xf1c7, 0x2094, 0x1ff0,
-0xc860, 0xe30a, 0x2515, 0xdac5, 0xe92d, 0x441f, 0x0548, 0xfb76, 0x3d79, 0xfd5c,
-0xbecb, 0x1149, 0x13f9, 0xd214, 0x2a6f, 0x3388, 0xe6f8, 0x2190, 0x2948, 0xc4a5,
-0xdd42, 0x2f43, 0xe6af, 0xf03f, 0x54db, 0x13d9, 0xfca6, 0x3215, 0xf506, 0xc57a,
-0x12c0, 0x0f9f, 0xd3cc, 0x322e, 0x4301, 0xf273, 0x23ab, 0x356e, 0xd3b2, 0xd051,
-0x21b7, 0xf281, 0xecda, 0x4489, 0x12f0, 0x0242, 0x4407, 0x06d1, 0xbafe, 0x0b6c,
-0x1d26, 0xc6ee, 0x19bc, 0x44e9, 0xe86d, 0x13b7, 0x39ca, 0xd446, 0xd119, 0x2941,
-0xee93, 0xe7c5, 0x4bc2, 0x0643, 0xe908, 0x4535, 0x0444, 0xaaed, 0x0a10, 0x21a1,
-0xc807, 0x1964, 0x41d6, 0xe77b, 0x16b3, 0x34e4, 0xc869, 0xc8dc, 0x2196, 0xe4ba,
-0xdb97, 0x4973, 0x106a, 0xe7d9, 0x3cc5, 0x0a39, 0xa769, 0xf083, 0x1925, 0xc4c2,
-0x075d, 0x3c4a, 0xe3ca, 0x0d28, 0x38d3, 0xc8d1, 0xbd34, 0x29a4, 0xea91, 0xbfc6,
-0x3ad0, 0x0fbe, 0xd348, 0x3125, 0x0f03, 0xa6a3, 0xf4e3, 0x222b, 0xbe73, 0x00e2,
-0x3cfa, 0xd671, 0xff6d, 0x3893, 0xc753, 0xb6c9, 0x236e, 0xec95, 0xc571, 0x3925,
-0x1324, 0xdbd6, 0x2c09, 0x07a8, 0xaa2d, 0xf242, 0x1fa6, 0xc716, 0x042c, 0x441c,
-0xe490, 0xffd3, 0x3dc4, 0xdc2a, 0xb9f6, 0x1f30, 0xfbb0, 0xca2e, 0x371c, 0x2003,
-0xddf1, 0x31fa, 0x2307, 0xb4d8, 0xf004, 0x2cbc, 0xc878, 0xf7c6, 0x4caf, 0xed6b,
-0xfe78, 0x48e2, 0xe5f3, 0xb861, 0x209c, 0xffdd, 0xc990, 0x3a8f, 0x2235, 0xd8df,
-0x3307, 0x26fb, 0xb85c, 0xf04e, 0x2cb8, 0xd049, 0xfa7c, 0x49ae, 0xedac, 0xfa25,
-0x3f7d, 0xe587, 0xbae6, 0x1de2, 0x03f4, 0xc964, 0x35b0, 0x2bf3, 0xdcc1, 0x287a,
-0x2509, 0xb53e, 0xdd34, 0x21f5, 0xd014, 0xf4e6, 0x5327, 0xfbed, 0xf63d, 0x422a,
-0xebde, 0xadff, 0x109b, 0x03c0, 0xc66e, 0x34a1, 0x371f, 0xe1e5, 0x266b, 0x298a,
-0xb6ec, 0xdb6e, 0x2815, 0xd421, 0xf019, 0x5352, 0xff26, 0xf3f2, 0x43a2, 0xf389,
-0xb155, 0x11bc, 0x093e, 0xc3cf, 0x2cd7, 0x37d3, 0xe04d, 0x22e3, 0x2ecd, 0xb8a8,
-0xd4f6, 0x2b5c, 0xd879, 0xe9c1, 0x5345, 0x0074, 0xeb1b, 0x3d0d, 0xf0a8, 0xa78e,
-0x0f83, 0x1369, 0xc523, 0x2e80, 0x3d4c, 0xdb13, 0x1e41, 0x2ecc, 0xb34d, 0xd013,
-0x2f65, 0xd81e, 0xe458, 0x57d2, 0x0406, 0xebe0, 0x457a, 0xf7e1, 0xa66e, 0x0b6f,
-0x0e7a, 0xb8d1, 0x251b, 0x3fe1, 0xdd7d, 0x20b9, 0x3687, 0xbb17, 0xd0b9, 0x2e06,
-0xd6de, 0xd8c9, 0x50ce, 0x0665, 0xe605, 0x3fce, 0xfc63, 0xac6f, 0x0f4a, 0x249e,
-0xcfcc, 0xfc68, 0x0488, 0xeb03, 0x4794, 0x43ec, 0xda83, 0xf3bd, 0x2644, 0xc019,
-0xac19, 0xfdb7, 0xdae0, 0xebc8, 0x4a7e, 0x4842, 0x204b, 0x2f4a, 0x0bd7, 0xb466,
-0xc7b6, 0xc25a, 0x9ff5, 0xfeaa, 0x3147, 0xf5d6, 0x1606, 0x7098, 0x2536, 0xcb1f,
-0xef7c, 0xd8bb, 0xa610, 0xc6a6, 0xf94d, 0x01cf, 0x2326, 0x2e92, 0xfa36, 0x1b23,
-0x1fee, 0xc9e0, 0xbf64, 0xf0f7, 0xebf9, 0xcd60, 0xfed7, 0x1727, 0x0a34, 0x1723,
-0x0a36, 0x0e7b, 0x18aa, 0xfc64, 0xb854, 0xc985, 0xfdd8, 0xc68b, 0xea58, 0x3e80,
-0x2a34, 0x0ba2, 0x2d28, 0x367f, 0xec1b, 0xe1de, 0xce20, 0xb654, 0xf084, 0xed7d,
-0xf556, 0x44c2, 0x5de8, 0x118c, 0x103a, 0x43c2, 0xea97, 0xbbb3, 0xd781, 0xd5a7,
-0xe105, 0xfd04, 0x1bc6, 0x2dbd, 0x4a4e, 0x2262, 0x090c, 0x37f3, 0x0697, 0xc337,
-0xc445, 0xe70d, 0xe217, 0xdb53, 0x1953, 0x38c9, 0x40c1, 0x2ede, 0x22c3, 0x260c,
-0xfc8c, 0xcfd4, 0xb0e1, 0xd39e, 0xe34c, 0xdae1, 0x253f, 0x508f, 0x342f, 0x1aa5,
-0x3628, 0x1e6e, 0xd753, 0xc9cd, 0xb7c4, 0xd23c, 0xef41, 0xeb30, 0x1cc2, 0x523c,
-0x3c38, 0x02b5, 0x29f9, 0x28a2, 0xd759, 0xd1f8, 0xd1bf, 0xd245, 0xe508, 0xfe91,
-0x19fc, 0x3b30, 0x3d9b, 0x0a4c, 0x2fd0, 0x37f4, 0xdc8c, 0xbe49, 0xd7b4, 0xe591,
-0xd3af, 0xfd0f, 0x3070, 0x36f1, 0x325e, 0x18a4, 0x3386, 0x27ca, 0xdc73, 0xb513,
-0xcdc8, 0xf809, 0xd5d9, 0xf013, 0x4334, 0x4964, 0x2395, 0x1b7b, 0x3c5a, 0x0fe4,
-0xd7a3, 0xc6c6, 0xc6b6, 0xf0cf, 0xeb7d, 0xf80b, 0x3914, 0x525a, 0x2445, 0x1417,
-0x4928, 0x0ff5, 0xc35d, 0xc78a, 0xd244, 0xdff9, 0xe35e, 0x07df, 0x35ae, 0x4ba7,
-0x2974, 0x1106, 0x3cf3, 0x0fec, 0xc4b4, 0xb9c7, 0xd562, 0xe489, 0xd970, 0x0e52,
-0x3f61, 0x43d6, 0x27aa, 0x2131, 0x364b, 0xfd16, 0xc955, 0xb961, 0xcde0, 0xe8ce,
-0xe024, 0x0e4f, 0x4544, 0x4582, 0x18cd, 0x22be, 0x3a77, 0xf22e, 0xc4f3, 0xbabf,
-0xcce0, 0xe32e, 0xe352, 0x12f7, 0x43a1, 0x4666, 0x1401, 0x1c0c, 0x30e6, 0xe619,
-0xbb56, 0xbb95, 0xd491, 0xe00b, 0xe61a, 0x17a4, 0x3b47, 0x3b00, 0x10e7, 0x1c7e,
-0x2707, 0xe361, 0xb750, 0xb2d2, 0xd7be, 0xdb41, 0xe145, 0x2096, 0x40ed, 0x319a,
-0x118b, 0x2924, 0x1a2e, 0xd6af, 0xba5f, 0xad6c, 0xd2c9, 0xe064, 0xe67c, 0x25df,
-0x4ea4, 0x3357, 0x0fc7, 0x312c, 0x1020, 0xc418, 0xb5ff, 0xb68a, 0xd4f7, 0xe2ef,
-0xfb14, 0x2e11, 0x4c3e, 0x3280, 0x08fc, 0x2966, 0x0e36, 0xc69d, 0xb3ba, 0xbf26,
-0xde72, 0xe461, 0x0918, 0x3887, 0x4967, 0x313c, 0x1236, 0x2763, 0x0526, 0xcb44,
-0xb35a, 0xc8b5, 0xed8f, 0xdf83, 0x05bf, 0x41b2, 0x4548, 0x20ab, 0x1a30, 0x2bd9,
-0xf884, 0xce0f, 0xb377, 0xc10c, 0xede8, 0xe5b7, 0x0520, 0x42f2, 0x4b64, 0x19c0,
-0x1a50, 0x2fd7, 0xee52, 0xc8d4, 0xbcea, 0xc661, 0xe5d5, 0xe9b8, 0x0e4b, 0x42da,
-0x4c23, 0x187a, 0x1ba9, 0x2fdd, 0xe89e, 0xbcad, 0xb84a, 0xd201, 0xe619, 0xeba8,
-0x1a61, 0x40ef, 0x41b7, 0x151a, 0x1cbf, 0x2b05, 0xea44, 0xc1f8, 0xbc6c, 0xdb3c,
-0xe422, 0xe69f, 0x208e, 0x4881, 0x3cc7, 0x1503, 0x2aa9, 0x27ed, 0xe431, 0xc5cc,
-0xbdfa, 0xdd9a, 0xe8e9, 0xf074, 0x2496, 0x4a59, 0x3e74, 0x1374, 0x2e8f, 0x252c,
-0xd82c, 0xba66, 0xbeda, 0xe1cc, 0xe3a5, 0xf456, 0x3043, 0x4df4, 0x382a, 0x0d8b,
-0x25d9, 0x1516, 0xd249, 0xb805, 0xbbdd, 0xe317, 0xe31f, 0xf717, 0x307f, 0x4438,
-0x2ce7, 0x1089, 0x29b8, 0x060d, 0xc757, 0xb6c7, 0xb848, 0xdd4c, 0xde36, 0xf60e,
-0x341a, 0x45f6, 0x1fc8, 0x0b03, 0x2ed5, 0xff75, 0xc14a, 0xb3bb, 0xb4dc, 0xd6d2,
-0xdc36, 0xfbb0, 0x356c, 0x49c3, 0x2300, 0x0fe9, 0x2f18, 0xf499, 0xb802, 0xb1b2,
-0xc06f, 0xdc85, 0xde22, 0x0805, 0x3cc1, 0x488e, 0x1f2e, 0x11d7, 0x2c64, 0xf3b1,
-0xbd78, 0xadbb, 0xc5eb, 0xe451, 0xde57, 0x0e82, 0x4140, 0x4137, 0x1916, 0x1b84,
-0x28d4, 0xe639, 0xc1a0, 0xb2e7, 0xc697, 0xe4be, 0xdf87, 0x10dc, 0x49b4, 0x457d,
-0x1479, 0x2405, 0x2b0f, 0xdcbe, 0xbefc, 0xb3a9, 0xc6dd, 0xe60b, 0xed45, 0x1b13,
-0x497b, 0x4531, 0x1324, 0x24b0, 0x243c, 0xd210, 0xb83d, 0xb984, 0xd0bc, 0xe2a6,
-0xf3b7, 0x2766, 0x4a82, 0x4204, 0x133f, 0x22b4, 0x1b4e, 0xd4a3, 0xba37, 0xbaaf,
-0xdf26, 0xea12, 0xf84b, 0x3177, 0x4e17, 0x39af, 0x193b, 0x308a, 0x13c1, 0xd6b0,
-0xc5d3, 0xbffc, 0xe599, 0xeec6, 0xff4d, 0x38ac, 0x5167, 0x346a, 0x1b9d, 0x376a,
-0x0ce4, 0xd4a8, 0xc78f, 0xc195, 0xe4f4, 0xf0f5, 0x07bb, 0x3cdc, 0x5981, 0x3510,
-0x1b26, 0x3a31, 0x03fb, 0xca72, 0xc53e, 0xcd25, 0xecab, 0xf768, 0x193e, 0x437d,
-0x53af, 0x2c6f, 0x15b8, 0x31bf, 0xff10, 0xcc99, 0xc147, 0xd348, 0xee05, 0xee95,
-0x1782, 0x2f2b, 0x4b20, 0x5a80, 0x2b14, 0xfd25, 0xdd6a, 0xccb5, 0x9c77, 0xbb91,
-0x0abb, 0xfa6d, 0x308d, 0x8b3b, 0x6386, 0x0f1b, 0x0366, 0xd9a6, 0x969a, 0xbb36,
-0xbe42, 0xd650, 0x4a43, 0x5e11, 0x39f6, 0x4e5f, 0x3f3f, 0xd1f7, 0xbac7, 0xda01,
-0xb75e, 0xdb85, 0x0689, 0x0f50, 0x402d, 0x3a48, 0xf492, 0xf3ba, 0x232e, 0xe3c2,
-0xc221, 0x1c7e, 0x103b, 0xda32, 0x0d99, 0x12a9, 0xc374, 0xe4a9, 0x2fee, 0xef59,
-0xf571, 0x4551, 0x09ce, 0xee4d, 0x190c, 0xdd87, 0xa5eb, 0xf5c9, 0x0d02, 0xd8dd,
-0x32e0, 0x4556, 0xf27b, 0x272d, 0x1a0f, 0xac2d, 0xc929, 0x0d48, 0xd065, 0xe73f,
-0x4fb6, 0x0a4b, 0xfcc1, 0x4512, 0xed54, 0xb2b9, 0x0350, 0xfc0b, 0xbed7, 0x1926,
-0x2f0c, 0xe1a6, 0x2871, 0x338a, 0xc365, 0xd8fc, 0x2261, 0xe12a, 0xda5e, 0x3836,
-0x02a6, 0xeb2d, 0x3c29, 0xfc95, 0xb47f, 0x126c, 0x2240, 0xc4df, 0x1301, 0x42d9,
-0xddbd, 0x05c8, 0x2ff4, 0xc609, 0xc9ef, 0x2ebd, 0xf193, 0xda07, 0x46da, 0x0cd3,
-0xe052, 0x39eb, 0x0085, 0xa3df, 0xfdbd, 0x1d67, 0xc36d, 0x1321, 0x461a, 0xe3db,
-0x121d, 0x3bc5, 0xce7e, 0xc611, 0x1e92, 0xe869, 0xd146, 0x3d6e, 0x12f6, 0xe781,
-0x3a2e, 0x100e, 0xb4c0, 0xf87f, 0x2451, 0xce12, 0xfd54, 0x3b61, 0xe9af, 0x0485,
-0x363a, 0xd7a5, 0xc531, 0x26b6, 0xfb26, 0xd3af, 0x4024, 0x13d3, 0xcf38, 0x31ca,
-0x1fe6, 0xacba, 0xe830, 0x28d0, 0xd67b, 0x03f4, 0x4390, 0xeff5, 0x0d9b, 0x3cdc,
-0xd2ef, 0xbce5, 0x1df5, 0xf194, 0xcc0a, 0x3c7b, 0x22be, 0xe9d0, 0x37e4, 0x1f21,
-0xbf6a, 0xed14, 0x13f9, 0xccad, 0xfeed, 0x36f2, 0xe931, 0x0bd9, 0x4870, 0xe9a7,
-0xc649, 0x2406, 0x009e, 0xc7de, 0x28c6, 0x1d14, 0xe19d, 0x2d2e, 0x24eb, 0xc1ae,
-0xf293, 0x2948, 0xd034, 0xfc36, 0x4c80, 0xed33, 0xf76a, 0x4574, 0xe546, 0xb51f,
-0x205e, 0x01e4, 0xc8f6, 0x3c9b, 0x2dfd, 0xe000, 0x3231, 0x23e4, 0xac3f, 0xe1e2,
-0x2470, 0xc806, 0xf279, 0x51f9, 0xfc93, 0xfd3d, 0x471f, 0xf14b, 0xb564, 0x0d8d,
-0xf7a1, 0xbaf7, 0x2ae2, 0x3330, 0xe3cf, 0x2876, 0x2f9d, 0xbe99, 0xd8ed, 0x2066,
-0xcc5b, 0xe037, 0x444b, 0xfc55, 0xf1ae, 0x3dee, 0xedb1, 0xa9f3, 0x0f58, 0x052a,
-0xb88b, 0x286b, 0x32e9, 0xd191, 0x1a2d, 0x2b19, 0xb1ba, 0xd055, 0x2574, 0xcd9d,
-0xe17a, 0x4f5d, 0xf991, 0xe9c8, 0x4424, 0xee22, 0xa03f, 0x0b3e, 0x0833, 0xb2f6,
-0x25d7, 0x3fb5, 0xd971, 0x1eca, 0x3552, 0xb55f, 0xc5ed, 0x2341, 0xd2b5, 0xd7c1,
-0x523e, 0x069d, 0xe63d, 0x453d, 0xfaec, 0xa137, 0x0414, 0x12c4, 0xb981, 0x1bb8,
-0x4054, 0xdb21, 0x1feb, 0x3f6a, 0xbc6b, 0xcb19, 0x2eaa, 0xdddc, 0xd782, 0x53f0,
-0x0db9, 0xe5f5, 0x4ae5, 0x09f1, 0xaaaa, 0x08ea, 0x1b96, 0xc280, 0x22c4, 0x4ce0,
-0xe24f, 0x1cfe, 0x4491, 0xc23a, 0xc424, 0x2faf, 0xe9a8, 0xd606, 0x50b8, 0x16c3,
-0xe5a3, 0x41e4, 0x0b1a, 0xa940, 0xfef6, 0x1bdf, 0xbfb1, 0x1607, 0x4e4e, 0xe252,
-0x116e, 0x44af, 0xc71f, 0xbeed, 0x2c56, 0xed57, 0xd13f, 0x46da, 0x1220, 0xdf44,
-0x3fcf, 0x0e72, 0xa687, 0xfe99, 0x22c2, 0xc0f4, 0x10f5, 0x4ab0, 0xdcc9, 0x0862,
-0x42d3, 0xcce8, 0xbf2b, 0x2c4a, 0xf130, 0xcf23, 0x47a0, 0x1557, 0xd894, 0x3b17,
-0x15eb, 0xac91, 0xfc3e, 0x2839, 0xc889, 0x0a6b, 0x4a0a, 0xe524, 0x0571, 0x40a3,
-0xd642, 0xc2d3, 0x2b1c, 0xfa19, 0xd4f9, 0x465b, 0x1ef6, 0xe106, 0x371e, 0x15ec,
-0xb185, 0xfc2f, 0x2898, 0xcc97, 0x0b55, 0x4c1f, 0xebc4, 0x08bc, 0x3f08, 0xd705,
-0xc599, 0x2bb5, 0x081d, 0xcd96, 0x0d3b, 0x0ffa, 0x0823, 0x3f09, 0x1a45, 0xdad9,
-0x0662, 0x07b7, 0xbb6a, 0xde9a, 0x0740, 0xda46, 0x0e1e, 0x6549, 0x38b1, 0x04bd,
-0x2510, 0xf943, 0xad98, 0xc9a0, 0xca5c, 0xcaba, 0x22c9, 0x2b10, 0x01f0, 0x511a,
-0x637c, 0xe409, 0xcfea, 0xff1b, 0xbae4, 0x9b34, 0xfafc, 0x154f, 0xfdb5, 0x2da1,
-0x2e82, 0x1b20, 0x2472, 0xf46c, 0xbc6b, 0xd8c3, 0xf895, 0xcd65, 0xe4ee, 0x20c1,
-0x1821, 0x08d6, 0x178c, 0x2a03, 0x07e8, 0xfe05, 0xe136, 0xbccf, 0xeb99, 0xdae7,
-0xd3aa, 0x1d70, 0x3e94, 0x094b, 0x0900, 0x5434, 0x0901, 0xc4b1, 0xdc6e, 0xc832,
-0xca7f, 0xe370, 0xfc55, 0x19fb, 0x5037, 0x3174, 0xfe1c, 0x3bdc, 0x1079, 0xb5a5,
-0xbd97, 0xde91, 0xd7dc, 0xd8e9, 0x1ed3, 0x2fd7, 0x3373, 0x2e1c, 0x130d, 0x2861,
-0x0ada, 0xcec0, 0xaf81, 0xd3f1, 0xe991, 0xcbf7, 0x0636, 0x408c, 0x3d14, 0x22da,
-0x2e7f, 0x334f, 0xf091, 0xd23f, 0xb6f6, 0xbe39, 0xe0ea, 0xdac6, 0x0ab7, 0x52de,
-0x5241, 0x1a28, 0x36a7, 0x3ee4, 0xdc10, 0xbfb1, 0xc06c, 0xc69f, 0xdf82, 0xf62e,
-0x1f54, 0x4e25, 0x578d, 0x17a6, 0x26c4, 0x37fc, 0xe05d, 0xc099, 0xcd8c, 0xd886,
-0xd8c3, 0xfcba, 0x2d83, 0x3fa6, 0x48bb, 0x1e77, 0x2a31, 0x31eb, 0xe98e, 0xbcf5,
-0xc196, 0xe4e4, 0xdb34, 0xf4b5, 0x398d, 0x47e8, 0x3526, 0x2168, 0x3d9a, 0x20eb,
-0xddcb, 0xbe09, 0xb85c, 0xe775, 0xe3f6, 0xedd1, 0x3731, 0x576a, 0x2d99, 0x1229,
-0x4011, 0x0fb4, 0xc58a, 0xc2e0, 0xc163, 0xd8b3, 0xe485, 0xfbc4, 0x28a2, 0x4aba,
-0x2b57, 0x06a4, 0x385f, 0x150e, 0xc2cd, 0xb65c, 0xcd33, 0xde60, 0xd4fe, 0x0096,
-0x3507, 0x45bc, 0x2781, 0x142c, 0x33ba, 0x049c, 0xc775, 0xb39c, 0xc6ec, 0xe39b,
-0xd75b, 0x0203, 0x3c34, 0x4589, 0x1c2f, 0x171d, 0x336b, 0xeff6, 0xbf31, 0xb8c6,
-0xc21c, 0xde19, 0xe412, 0x0b3a, 0x399a, 0x4631, 0x1799, 0x116c, 0x3085, 0xeefe,
-0xbcec, 0xb922, 0xcdc6, 0xe051, 0xe2d7, 0x10d0, 0x38e1, 0x3dfb, 0x1356, 0x1516,
-0x2876, 0xe6f8, 0xbb6a, 0xb636, 0xd128, 0xdda0, 0xdf16, 0x11df, 0x387e, 0x338c,
-0x0c5c, 0x211c, 0x2422, 0xdca8, 0xbf10, 0xb435, 0xcd32, 0xde18, 0xe25f, 0x144e,
-0x3fe0, 0x3472, 0x0753, 0x2b41, 0x27e8, 0xd555, 0xc117, 0xbddb, 0xcb8c, 0xdaa8,
-0xee16, 0x185e, 0x406a, 0x394d, 0x0e4c, 0x3224, 0x2283, 0xcee6, 0xb78f, 0xbe46,
-0xd600, 0xd73a, 0xf882, 0x2db5, 0x4253, 0x3500, 0x1558, 0x2eee, 0x13ba, 0xd1b3,
-0xb80a, 0xbd32, 0xe28d, 0xdf23, 0xfd44, 0x3980, 0x4ace, 0x2d3f, 0x18f4, 0x34ae,
-0x039f, 0xcc97, 0xbb5e, 0xbe2a, 0xe6fa, 0xe555, 0x023b, 0x3de8, 0x4db4, 0x2192,
-0x1578, 0x3a68, 0xfe29, 0xc84a, 0xbd0b, 0xc1ef, 0xe3a9, 0xe936, 0x0a3b, 0x3ab4,
-0x505a, 0x260d, 0x1903, 0x39c0, 0xf9ac, 0xc53b, 0xbc41, 0xcc45, 0xe5fc, 0xe843,
-0x15b8, 0x436d, 0x4dae, 0x24c5, 0x212b, 0x33f2, 0xf1b2, 0xc3a3, 0xb509, 0xcd57,
-0xe8db, 0xeb7c, 0x1d1e, 0x4aef, 0x4a01, 0x1af5, 0x24c7, 0x2df1, 0xe4a5, 0xc1ae,
-0xb8ad, 0xd2c8, 0xe887, 0xee7b, 0x21d0, 0x4d5f, 0x4806, 0x171f, 0x2854, 0x27e5,
-0xdd26, 0xc075, 0xb9c1, 0xd6dc, 0xe94e, 0xf760, 0x2a99, 0x4d0c, 0x4405, 0x1751,
-0x2a63, 0x1e7d, 0xd670, 0xba60, 0xb674, 0xde00, 0xe8fc, 0xf57e, 0x3121, 0x51b2,
-0x3a66, 0x11d4, 0x29d9, 0x107f, 0xd01f, 0xbbd1, 0xb864, 0xe08f, 0xea2a, 0xfafd,
-0x34de, 0x5038, 0x3061, 0x1294, 0x3316, 0x07d3, 0xc6ab, 0xbd82, 0xc0f2, 0xe421,
-0xebe4, 0x0398, 0x39c6, 0x54a2, 0x2e8b, 0x0e55, 0x3308, 0x0648, 0xc5ad, 0xbd8e,
-0xc53c, 0xdfb2, 0xe8b4, 0x0f4a, 0x3d14, 0x4caa, 0x2bf1, 0x15bf, 0x2e89, 0xf945,
-0xc136, 0xb890, 0xcaeb, 0xe950, 0xe7bf, 0x115d, 0x451b, 0x4aa1, 0x20cd, 0x1684,
-0x2a91, 0xf0a3, 0xc5b7, 0xb815, 0xc9bf, 0xee16, 0xea12, 0x117d, 0x470b, 0x42c7,
-0x113f, 0x1b7c, 0x2b91, 0xe191, 0xc212, 0xbd24, 0xc84b, 0xe419, 0xe8c1, 0x104f,
-0x440c, 0x4662, 0x1122, 0x20a6, 0x2d8e, 0xda8b, 0xbcf3, 0xc089, 0xcbf5, 0xde1c,
-0xf3c0, 0x2135, 0x414e, 0x3fd9, 0x15e1, 0x26f5, 0x292e, 0xdc7e, 0xb937, 0xb924,
-0xd769, 0xe06d, 0xee92, 0x2aa0, 0x48ae, 0x379d, 0x15e3, 0x2afa, 0x167d, 0xd370,
-0xbfeb, 0xb8aa, 0xd8da, 0xe695, 0xf331, 0x2abe, 0x4918, 0x2e1c, 0x0f19, 0x32cf,
-0x0f46, 0xc822, 0xbf6b, 0xbca2, 0xdadc, 0xe628, 0xf835, 0x2cf1, 0x4b03, 0x2c10,
-0x0df9, 0x358e, 0x0a2c, 0xc678, 0xc06b, 0xc05f, 0xd849, 0xe170, 0x02e1, 0x3324,
-0x4bd0, 0x2fc8, 0x13c8, 0x3314, 0x0029, 0xbf2e, 0xb455, 0xc1d3, 0xe027, 0xe480,
-0x0a7f, 0x2c7a, 0x5506, 0x634d, 0x2129, 0xfadf, 0xe1b5, 0xb620, 0x8bd2, 0xbfae,
-0x0a2a, 0x0d5d, 0x5240, 0x8109, 0x4e83, 0x15cf, 0xf367, 0xba2c, 0x9d5f, 0xcd2e,
-0xbdc8, 0xf85d, 0x6f35, 0x4484, 0x29e8, 0x54f0, 0x2a04, 0xcc06, 0xd6d5, 0xe253,
-0xc387, 0x09da, 0xff4a, 0xebc6, 0x4eb3, 0x2edb, 0xcfcc, 0x0b9a, 0x3d1b, 0xdc1f,
-0xf4a1, 0x3fae, 0xeb9b, 0xe915, 0x13be, 0xcb86, 0xb940, 0x1643, 0x18ee, 0xf7d9,
-0x4acf, 0x30df, 0xe6dc, 0x16fe, 0xf4d5, 0x9c55, 0xcc79, 0x10aa, 0xe384, 0x0496,
-0x4c2c, 0x0504, 0xff4c, 0x2d7e, 0xd93d, 0xacb4, 0x00e4, 0xf5af, 0xc18e, 0x2289,
-0x2a64, 0xe0a9, 0x2089, 0x21b8, 0xbaf3, 0xdd89, 0x1ea4, 0xd2e4, 0xe648, 0x37ea,
-0xec35, 0xe993, 0x35d6, 0xed2e, 0xbadd, 0x15b4, 0x0a9d, 0xc841, 0x1a7c, 0x191c,
-0xcaef, 0x0f4e, 0x1fff, 0xbfae, 0xe155, 0x3460, 0xeb55, 0xe0b6, 0x3048, 0xf2f2,
-0xddca, 0x235a, 0xee7f, 0xb7cc, 0x15dd, 0x2097, 0xce52, 0x180f, 0x2dcf, 0xd499,
-0x0857, 0x29b8, 0xc4c2, 0xd000, 0x28ff, 0xe652, 0xde94, 0x43c5, 0x05e6, 0xe425,
-0x356a, 0xfee7, 0xb2c1, 0x0914, 0x1584, 0xbe7b, 0x0e5a, 0x368a, 0xe276, 0x1274,
-0x3391, 0xd008, 0xd357, 0x26c2, 0xec06, 0xdd61, 0x39e2, 0x0868, 0xe6f9, 0x3207,
-0x091c, 0xbc0e, 0x0582, 0x1f6d, 0xd133, 0x1cab, 0x4d57, 0xeb81, 0x02e3, 0x3712,
-0xde41, 0xc71f, 0x212b, 0xfb67, 0xe7a1, 0x504a, 0x23ac, 0xedd8, 0x3eb6, 0x157e,
-0xad36, 0xfc30, 0x2995, 0xcb86, 0x10c5, 0x529b, 0xf7a7, 0x15fe, 0x4546, 0xdc21,
-0xcaba, 0x26eb, 0xe984, 0xd493, 0x4c8e, 0x16e6, 0xe56c, 0x463b, 0x1cf9, 0xb4a9,
-0xfd71, 0x24ab, 0xc8a4, 0x09c8, 0x41c1, 0xe4ff, 0x0a9c, 0x3d28, 0xd226, 0xc16f,
-0x2d0a, 0xf732, 0xcb2f, 0x42b2, 0x1d8f, 0xd5f3, 0x2c26, 0x1649, 0xa7c7, 0xed21,
-0x286f, 0xc688, 0x04e2, 0x51dd, 0xe73b, 0x0013, 0x46f0, 0xd1e8, 0xab29, 0x260f,
-0xf7aa, 0xbdee, 0x402d, 0x25c0, 0xda8b, 0x3989, 0x21df, 0xa95c, 0xf0ed, 0x290b,
-0xbd3d, 0xfb44, 0x4eba, 0xe63a, 0xfecd, 0x4a1d, 0xe177, 0xbc6f, 0x2af3, 0xfdf2,
-0xc4cf, 0x3b3d, 0x1ebb, 0xd4a0, 0x319d, 0x221e, 0xaf94, 0xf1b0, 0x3313, 0xcaf9,
-0xf7f2, 0x4fd1, 0xeb5b, 0xf54e, 0x3faa, 0xd925, 0xb016, 0x2624, 0x012e, 0xc2f3,
-0x3e16, 0x255d, 0xce61, 0x2b67, 0x1e8d, 0xa020, 0xe075, 0x2e2f, 0xc930, 0xf3f3,
-0x4f96, 0xe6da, 0xef8a, 0x43fb, 0xdd85, 0xab7b, 0x2022, 0xfe5f, 0xba39, 0x346d,
-0x27b4, 0xd20a, 0x2bfd, 0x2882, 0xae6f, 0xe3d3, 0x2b38, 0xc9c6, 0xef8e, 0x49d8,
-0xeade, 0xf2c2, 0x46de, 0xe8ca, 0xb2fe, 0x208e, 0x0855, 0xc5c4, 0x338e, 0x29eb,
-0xd645, 0x257e, 0x260c, 0xb7e2, 0xebef, 0x3365, 0xd6d8, 0xf811, 0x518d, 0xf457,
-0xf134, 0x4558, 0xf41a, 0xb66e, 0x1a28, 0x0bd1, 0xcaa3, 0x31f9, 0x3045, 0xe17a,
-0x2ad4, 0x2f2d, 0xbd2b, 0xe13e, 0x2cfe, 0xd3bd, 0xea52, 0x4fb4, 0x020e, 0xf40a,
-0x4278, 0xf8f7, 0xb45e, 0x127c, 0x0af1, 0xc2d1, 0x2b03, 0x36f1, 0xdd10, 0x20d2,
-0x35ec, 0xc074, 0xd7bd, 0x2eef, 0xd9db, 0xe543, 0x52c9, 0x05cf, 0xec53, 0x41bb,
-0xfa65, 0xaf2a, 0x15c6, 0x1274, 0xbe0e, 0x2c97, 0x448e, 0xdd59, 0x1c74, 0x3817,
-0xbb2b, 0xcf5b, 0x2f9a, 0xdc0c, 0xe4f0, 0x586d, 0x096c, 0xe913, 0x42c2, 0xf921,
-0xa4d2, 0x0f94, 0x157d, 0xbee7, 0x2a97, 0x46c2, 0xe0bf, 0x1d38, 0x3786, 0xb9af,
-0xcb2a, 0x2dd9, 0xd952, 0xdcbe, 0x5596, 0x0bab, 0xea4b, 0x4531, 0xffe2, 0xa78b,
-0x0c61, 0x136f, 0xb532, 0x2148, 0x44ae, 0xd96e, 0x195c, 0x392c, 0xb898, 0xc8e9,
-0x3388, 0xef92, 0xcd85, 0x0ef6, 0xf796, 0x13e1, 0x506a, 0x028d, 0xcd42, 0x14f5,
-0xf58e, 0x9d81, 0xe29f, 0xfb3c, 0xcd66, 0x1bbf, 0x6302, 0x30d7, 0x14e4, 0x29bc,
-0xdf14, 0xae5e, 0xce80, 0xabdc, 0xca7e, 0x3503, 0x1ee4, 0xf688, 0x5aac, 0x62a7,
-0xd87d, 0xd4d5, 0xfc76, 0xb6dd, 0xa5b5, 0xf6e7, 0x0b99, 0x0665, 0x381b, 0x1f19,
-0x1206, 0x2ed5, 0xebdd, 0xb56d, 0xde2e, 0xf87e, 0xce4d, 0xed47, 0x2439, 0x121c,
-0x1266, 0x1483, 0x16c8, 0x10fd, 0x0650, 0xd754, 0xbaff, 0xf7e2, 0xda39, 0xcd45,
-0x2986, 0x40dc, 0x0e53, 0x182a, 0x50a1, 0x01de, 0xcb6e, 0xdc62, 0xb781, 0xcfc4,
-0xee54, 0xf542, 0x2240, 0x5981, 0x2c5e, 0xf8e5, 0x3e3b, 0x0d29, 0xaf98, 0xc3b7,
-0xd787, 0xd3b1, 0xe2e2, 0x19c0, 0x28df, 0x3943, 0x2fe3, 0x081e, 0x2922, 0x0f78,
-0xc962, 0xb6cc, 0xd979, 0xe6a6, 0xd121, 0x07cf, 0x3500, 0x3ad0, 0x2c2a, 0x2624,
-0x2c95, 0xfb6f, 0xd7be, 0xb61f, 0xc05e, 0xe300, 0xd931, 0x0c0c, 0x4eae, 0x4878,
-0x15a7, 0x2a43, 0x31b1, 0xdd24, 0xc4ea, 0xbda7, 0xc680, 0xe6be, 0xf0c6, 0x13f8,
-0x45f0, 0x4cdc, 0x09ee, 0x185b, 0x3039, 0xdd40, 0xc562, 0xd19d, 0xd51e, 0xdcc7,
-0xfbf1, 0x1f9a, 0x3311, 0x4108, 0x10a0, 0x1d6d, 0x368a, 0xebc0, 0xbacd, 0xc61c,
-0xe6be, 0xd8c6, 0xecc7, 0x2b4f, 0x3ad6, 0x3234, 0x16aa, 0x312b, 0x2c20, 0xe5cf,
-0xbf0c, 0xc2d3, 0xef02, 0xde96, 0xe42b, 0x3264, 0x4f6e, 0x2b87, 0x1502, 0x434e,
-0x2169, 0xd824, 0xcd4a, 0xcbe5, 0xe67d, 0xe8bc, 0xf5fe, 0x2bd2, 0x4fbf, 0x2b2a,
-0x05aa, 0x4482, 0x2857, 0xcb20, 0xc28b, 0xdaa2, 0xe5a8, 0xd616, 0xfaa0, 0x2fc3,
-0x4640, 0x2ce5, 0x0f5a, 0x3ab7, 0x1944, 0xcda3, 0xbbcb, 0xcda1, 0xe22a, 0xd491,
-0x0143, 0x3873, 0x3fbe, 0x22bb, 0x1736, 0x3ae6, 0x0407, 0xc3a8, 0xb9c4, 0xc437,
-0xdc67, 0xd7ba, 0x00f1, 0x3801, 0x41a0, 0x1951, 0x11c6, 0x35de, 0xf7fb, 0xbeac,
-0xb811, 0xc658, 0xdc21, 0xd8e4, 0x060e, 0x39e5, 0x4146, 0x14d2, 0x16dd, 0x36f4,
-0xed6d, 0xba86, 0xb9b4, 0xcb20, 0xdd7e, 0xdfe1, 0x0f15, 0x3b82, 0x3e9b, 0x1158,
-0x1b8a, 0x323f, 0xe8e2, 0xbdfb, 0xb835, 0xd09f, 0xddf2, 0xdd36, 0x148a, 0x40d3,
-0x3e5f, 0x13a7, 0x2794, 0x2f4a, 0xde17, 0xbd25, 0xb6e3, 0xcb99, 0xdc56, 0xe6b9,
-0x1ce9, 0x4836, 0x40a4, 0x1189, 0x2c70, 0x2966, 0xd436, 0xb74c, 0xb722, 0xd074,
-0xdc0f, 0xf37b, 0x2f67, 0x4c6c, 0x3aa1, 0x13df, 0x2e82, 0x1863, 0xcd4e, 0xbc3f,
-0xbce0, 0xd9c4, 0xe1be, 0xfb8d, 0x359d, 0x4c01, 0x3625, 0x17b8, 0x32ce, 0x1032,
-0xcc89, 0xbc30, 0xbdba, 0xe2ec, 0xe81c, 0x005e, 0x3db9, 0x512c, 0x2c97, 0x17fc,
-0x380c, 0x06f5, 0xcdb1, 0xc0d4, 0xbe6b, 0xe241, 0xead9, 0x05a4, 0x3a27, 0x518a,
-0x2c10, 0x187d, 0x3809, 0xfd0c, 0xc4ac, 0xbff0, 0xc939, 0xe3de, 0xe907, 0x0ded,
-0x3e36, 0x4e75, 0x2456, 0x1759, 0x31b3, 0xf547, 0xc449, 0xba76, 0xcb7c, 0xe629,
-0xeb17, 0x17cc, 0x43ae, 0x4970, 0x1dfb, 0x1c5c, 0x2c1b, 0xe97c, 0xc40d, 0xbedd,
-0xd492, 0xe90c, 0xea14, 0x18aa, 0x44ec, 0x43bf, 0x15aa, 0x2421, 0x2f68, 0xe453,
-0xc2c4, 0xbef4, 0xd4c2, 0xe5c8, 0xf22d, 0x2430, 0x475e, 0x4461, 0x187f, 0x2916,
-0x2d8a, 0xe382, 0xc1ee, 0xc2fa, 0xe144, 0xe6ea, 0xf400, 0x30a7, 0x50eb, 0x4265,
-0x1b39, 0x2f67, 0x2260, 0xde78, 0xc61b, 0xc3e2, 0xe4c5, 0xea6e, 0xf9b7, 0x32e4,
-0x4b24, 0x330a, 0x1529, 0x377b, 0x1ad4, 0xd298, 0xc471, 0xc39e, 0xdfcf, 0xe493,
-0xf83e, 0x339f, 0x5169, 0x3178, 0x0fe4, 0x3634, 0x10e7, 0xcad8, 0xc188, 0xc0cb,
-0xd97a, 0xe36b, 0x01cf, 0x3255, 0x49ca, 0x2dc9, 0x1019, 0x33a3, 0x059a, 0xbd42,
-0xb33f, 0xbe30, 0xd9b3, 0xdc31, 0x0338, 0x37ee, 0x44ae, 0x224f, 0x0cf2, 0x27ab,
-0xf5dc, 0xbd67, 0xaf02, 0xbe02, 0xde1c, 0xd738, 0x02b2, 0x3eba, 0x4074, 0x174f,
-0x1829, 0x2c82, 0xe72a, 0xbf61, 0xb6b3, 0xbe85, 0xe2b1, 0xe25f, 0x05c1, 0x4181,
-0x4a2b, 0x1512, 0x1a96, 0x326a, 0xe3c7, 0xbc8c, 0xb7af, 0xbd6f, 0xd849, 0xe90a,
-0x150e, 0x3ed0, 0x469e, 0x176f, 0x1b23, 0x2908, 0xdb26, 0xb2f3, 0xb1f8, 0xca6a,
-0xdb06, 0xe6a5, 0x1fb9, 0x4383, 0x3e5d, 0x1596, 0x1e94, 0x1cb0, 0xd8cf, 0xba95,
-0xaec4, 0xcef4, 0xe43f, 0xeaf7, 0x2443, 0x4766, 0x336a, 0x0e32, 0x27a3, 0x1356,
-0xcd5d, 0xc150, 0xb6ba, 0xd1d8, 0xe528, 0xee84, 0x2426, 0x4adf, 0x3667, 0x10cd,
-0x310e, 0x1388, 0xcbbb, 0xc47e, 0xbd1f, 0xd491, 0xe98e, 0x0244, 0x3289, 0x53b3,
-0x3eb9, 0x1566, 0x3290, 0x11e3, 0xcc07, 0xc004, 0xc4fd, 0xe223, 0xed0a, 0x10ae,
-0x3ff0, 0x5037, 0x36e6, 0x164f, 0x29a1, 0x0284, 0xcdb8, 0xbdcd, 0xc637, 0xed96,
-0xeeb1, 0x0cd0, 0x4050, 0x49bb, 0x239a, 0x1780, 0x2eab, 0xf6b6, 0xce3d, 0xbc38,
-0xc8a0, 0x00e6, 0xefad, 0x0021, 0x33f9, 0x3ae3, 0x3cd3, 0x3fb1, 0x1838, 0xd924,
-0xd541, 0xaecf, 0xa5de, 0xf7be, 0xfc4c, 0x140b, 0x790a, 0x7937, 0x1616, 0xfecc,
-0xe9f4, 0x93de, 0xa330, 0xc0f0, 0xcf7e, 0x2cbc, 0x6286, 0x4ccf, 0x462d, 0x450f,
-0xe74f, 0xa99c, 0xd6b1, 0xc669, 0xba55, 0xfefe, 0x25a9, 0x3149, 0x43ec, 0x1f26,
-0xede2, 0x0adf, 0xff6f, 0xbdad, 0xf121, 0x2c23, 0xf18d, 0xf0cc, 0x2718, 0xe6c1,
-0xbbba, 0x1d92, 0x14c7, 0xde85, 0x3e57, 0x31f4, 0xe295, 0x0f8d, 0xf992, 0xa267,
-0xd117, 0x1bec, 0xe179, 0x07c9, 0x5af9, 0x03a7, 0x02e9, 0x3014, 0xd04d, 0xa794,
-0xfb7e, 0xf282, 0xc715, 0x36b9, 0x3764, 0xea25, 0x307a, 0x1cb0, 0xb2ec, 0xd406,
-0x117c, 0xd2a9, 0xea54, 0x43e9, 0xfc21, 0xfaa3, 0x3fc1, 0xeafd, 0xb060, 0x0b4c,
-0x0ff9, 0xc461, 0x1954, 0x3040, 0xd984, 0x1601, 0x2825, 0xbc3f, 0xdbce, 0x3875,
-0xe248, 0xdd2e, 0x4e02, 0xfd2c, 0xd91c, 0x3749, 0xf658, 0xaa69, 0x13e1, 0x2498,
-0xcc14, 0x21ba, 0x3a26, 0xdb15, 0x1623, 0x2c3d, 0xba40, 0xcd2e, 0x2cf5, 0xe4ae,
-0xe186, 0x52e0, 0x0d31, 0xe5cf, 0x3778, 0xffc1, 0xac3d, 0xfddf, 0x1bac, 0xc8ec,
-0x14d4, 0x4029, 0xe79d, 0x15d6, 0x3792, 0xcc34, 0xca86, 0x3225, 0xf50a, 0xcf32,
-0x3e28, 0x12b9, 0xe181, 0x364b, 0x1002, 0xb4c9, 0x031c, 0x26d6, 0xd0a9, 0x1e6a,
-0x443a, 0xd350, 0x08d3, 0x41ed, 0xc7a2, 0xb99c, 0x2fe3, 0xff21, 0xdc75, 0x4839,
-0x19bb, 0xe84c, 0x32f7, 0x01b7, 0xaddf, 0xfef1, 0x1e1c, 0xcae8, 0x16e4, 0x4bda,
-0xecbb, 0x0caf, 0x3f24, 0xe0dc, 0xc4bc, 0x18da, 0xf67e, 0xdd77, 0x3908, 0x10f4,
-0xed5b, 0x4369, 0x1b8d, 0xb980, 0x0190, 0x297a, 0xc6e3, 0x009e, 0x4462, 0xea33,
-0x0155, 0x3cba, 0xe27f, 0xcbef, 0x2bda, 0xf9a0, 0xd4bc, 0x439f, 0x150b, 0xd559,
-0x344d, 0x1a5b, 0xaf57, 0xf935, 0x2de0, 0xcf9a, 0x0979, 0x49a9, 0xea95, 0x051a,
-0x3cdb, 0xd6df, 0xbc25, 0x2174, 0xf28b, 0xc89b, 0x4222, 0x2645, 0xdfc1, 0x315e,
-0x201e, 0xb2fc, 0xe3d4, 0x181b, 0xc442, 0xfd80, 0x4a43, 0xed31, 0xff1f, 0x4381,
-0xdf06, 0xb4dc, 0x1fd7, 0xf6dc, 0xbffe, 0x3a30, 0x24f3, 0xd6d6, 0x297b, 0x1c5d,
-0xaf37, 0xedb8, 0x286b, 0xc61d, 0xfe95, 0x515b, 0xe559, 0xf3c9, 0x4090, 0xd830,
-0xae85, 0x1db8, 0xf7ec, 0xc607, 0x3f9f, 0x264d, 0xd94a, 0x2a8a, 0x1485, 0xa002,
-0xdeaf, 0x235b, 0xc381, 0xfa49, 0x5796, 0xefa6, 0xf6b9, 0x4056, 0xd904, 0xa813,
-0x17bf, 0xf931, 0xbf26, 0x3e31, 0x2c1d, 0xd50a, 0x2d55, 0x22b9, 0xa846, 0xdf9f,
-0x28c5, 0xc598, 0xef6b, 0x51e5, 0xf17d, 0xfa6e, 0x46ce, 0xddcb, 0xac63, 0x1bcf,
-0xff42, 0xc08e, 0x3b8a, 0x30ab, 0xd540, 0x2b2a, 0x2b14, 0xb01e, 0xe003, 0x2eb4,
-0xd207, 0xf705, 0x5a04, 0xf5f1, 0xf4f2, 0x49c1, 0xe735, 0xac7d, 0x1ff2, 0x0bc1,
-0xc150, 0x3a15, 0x3cd0, 0xdc44, 0x29ee, 0x3079, 0xb504, 0xdcbb, 0x2cd7, 0xcfca,
-0xeed8, 0x5c84, 0xfe19, 0xf346, 0x4ec0, 0xf24e, 0xa9a2, 0x1b01, 0x120e, 0xbf61,
-0x31bd, 0x3ed0, 0xdca8, 0x27d7, 0x3553, 0xb79f, 0xddc0, 0x376a, 0xd743, 0xea45,
-0x592a, 0xf9f4, 0xe94c, 0x4a1d, 0xf552, 0xa9a1, 0x19d2, 0x14c6, 0xbc9b, 0x2b11,
-0x3913, 0xd2dc, 0x1f02, 0x340a, 0xb6b6, 0xd426, 0x33f8, 0xd9a8, 0xdc7f, 0x5123,
-0xfd3a, 0xde46, 0x40ce, 0xfa10, 0xa997, 0x14a8, 0x1bb4, 0xc08d, 0x2376, 0x3d24,
-0xd503, 0x166b, 0x35f1, 0xbc86, 0xd0fa, 0x36e8, 0xf1a1, 0xd628, 0x16ed, 0xf145,
-0x0d1a, 0x55e9, 0x09b3, 0xd0ea, 0x189e, 0xfae5, 0xa1d9, 0xe581, 0xfd1f, 0xd241,
-0x1ffa, 0x5b9f, 0x2d05, 0x1f94, 0x316b, 0xe330, 0xba22, 0xd9ab, 0xb354, 0xcfaa,
-0x3059, 0x1e34, 0xfcfc, 0x565e, 0x623a, 0xe738, 0xe027, 0xfe57, 0xc099, 0xb327,
-0xf470, 0x0c3c, 0x0e38, 0x38fd, 0x1a11, 0x0892, 0x3339, 0xf5c3, 0xbab1, 0xe297,
-0xf843, 0xce95, 0xe620, 0x1c2a, 0x09ee, 0x1283, 0x1b02, 0x1187, 0x188b, 0x0e86,
-0xd87e, 0xb652, 0xeca9, 0xdb2d, 0xc7dd, 0x1fe5, 0x379e, 0x0fd2, 0x1c45, 0x4c2e,
-0x1316, 0xd85d, 0xdfc8, 0xb6df, 0xc87f, 0xeb35, 0xe54a, 0x1628, 0x57e4, 0x3419,
-0xff6c, 0x4156, 0x1c74, 0xb5b4, 0xca06, 0xd49b, 0xc6db, 0xdff3, 0x0f42, 0x1c9b,
-0x38c2, 0x3cc3, 0x059b, 0x2a27, 0x2699, 0xce85, 0xb4f9, 0xd393, 0xdea9, 0xcdb3,
-0x03e7, 0x3281, 0x3d54, 0x3c61, 0x2583, 0x2ce2, 0x0c86, 0xdb4d, 0xb3bf, 0xbb9c,
-0xe353, 0xd3fa, 0x034f, 0x4cdb, 0x4ab4, 0x21fa, 0x2b59, 0x391f, 0xeb27, 0xc6cb,
-0xb8e4, 0xba9a, 0xe811, 0xec0e, 0x0c31, 0x4bdb, 0x5772, 0x163d, 0x1a19, 0x3f4d,
-0xe9e8, 0xc3a2, 0xce2a, 0xc788, 0xd9f4, 0xf83e, 0x1bc6, 0x3ce8, 0x5548, 0x1db0,
-0x1a55, 0x4521, 0xf1e2, 0xb3ab, 0xc2fd, 0xdbe1, 0xd800, 0xed52, 0x2c30, 0x402d,
-0x430b, 0x23ff, 0x260b, 0x2f76, 0xea68, 0xb3d7, 0xb28e, 0xe14a, 0xdd06, 0xe066,
-0x33b3, 0x51ec, 0x33b4, 0x1667, 0x3052, 0x1b77, 0xd41e, 0xc1bd, 0xb6c4, 0xd7a4,
-0xeae0, 0xe9c9, 0x2119, 0x50ee, 0x3348, 0x0504, 0x35a7, 0x2224, 0xc555, 0xbad4,
-0xc362, 0xd0c4, 0xdade, 0xf6c3, 0x247a, 0x463c, 0x3726, 0x098e, 0x2ae9, 0x1a2f,
-0xc9d7, 0xb0fe, 0xc012, 0xdaac, 0xd5e1, 0xf9b0, 0x351f, 0x47da, 0x2cc6, 0x10fb,
-0x2d9f, 0x068e, 0xc5e3, 0xb7fe, 0xc297, 0xe2b0, 0xe422, 0x01db, 0x36ef, 0x48cb,
-0x23b7, 0x10de, 0x3507, 0x0307, 0xc7bf, 0xbff3, 0xc77c, 0xe128, 0xe56e, 0x0857,
-0x3924, 0x4aaf, 0x2249, 0x103e, 0x31eb, 0xfa7b, 0xc42a, 0xbff2, 0xca69, 0xdf50,
-0xe715, 0x1070, 0x37d6, 0x4303, 0x1eac, 0x16ba, 0x3184, 0xf739, 0xc4f5, 0xba46,
-0xcd7e, 0xe4d0, 0xe592, 0x10ee, 0x3d09, 0x4044, 0x17ce, 0x2016, 0x2f3f, 0xe9e5,
-0xc633, 0xbad5, 0xc6f9, 0xdeac, 0xe624, 0x121c, 0x413b, 0x4301, 0x1783, 0x29fd,
-0x2ba5, 0xdaa4, 0xbe2e, 0xbb8e, 0xcbc8, 0xdde4, 0xf1e9, 0x21db, 0x439b, 0x4190,
-0x172e, 0x27a0, 0x21f8, 0xd636, 0xbad8, 0xb8bf, 0xd096, 0xdf64, 0xf8a8, 0x2b93,
-0x443b, 0x3b96, 0x185e, 0x26da, 0x10a6, 0xd167, 0xbdb5, 0xb977, 0xdb3a, 0xe708,
-0xfa86, 0x2f52, 0x4806, 0x3265, 0x17a3, 0x31bc, 0x0e05, 0xd510, 0xc461, 0xbd66,
-0xe192, 0xed77, 0x0119, 0x32ba, 0x50ed, 0x31ea, 0x16d3, 0x36ec, 0x0732, 0xcfc7,
-0xc460, 0xc184, 0xdf83, 0xea58, 0x0626, 0x3550, 0x5246, 0x2def, 0x16cd, 0x3427,
-0xfd3a, 0xc953, 0xbd3c, 0xc544, 0xe4ec, 0xf153, 0x166b, 0x3e10, 0x4e6d, 0x26d4,
-0x1968, 0x2f16, 0xf428, 0xcae0, 0xbedd, 0xccf8, 0xe956, 0xefa2, 0x1950, 0x4297,
-0x4a75, 0x1de5, 0x1955, 0x29ba, 0xeb91, 0xc61c, 0xbb12, 0xce33, 0xe7ce, 0xefe6,
-0x18c6, 0x3e32, 0x43c5, 0x1922, 0x1cc3, 0x20fd, 0xde2b, 0xbf55, 0xb70b, 0xd16f,
-0xe788, 0xef8e, 0x20c4, 0x4654, 0x3d93, 0x11d7, 0x1d2e, 0x15c5, 0xd810, 0xc122,
-0xb7df, 0xd5bd, 0xe934, 0xf5a0, 0x24cd, 0x4321, 0x356b, 0x10be, 0x2522, 0x0e25,
-0xcdbf, 0xc120, 0xbd1c, 0xd9ef, 0xe950, 0xf8ec, 0x2940, 0x4a04, 0x31e9, 0x09bb,
-0x2935, 0x0de2, 0xcd32, 0xc3e0, 0xc0ad, 0xd96f, 0xebee, 0x0617, 0x2f65, 0x4a9d,
-0x32b8, 0x104d, 0x2b20, 0x042c, 0xc6fe, 0xc0fc, 0xccb1, 0xe4c6, 0xe7e5, 0x0a2f,
-0x3646, 0x44a9, 0x27ed, 0x0f84, 0x2482, 0xf9ba, 0xc9c9, 0xbc46, 0xc6f1, 0xe7c9,
-0xe7b4, 0x0935, 0x38ab, 0x3dfb, 0x17f4, 0x1202, 0x2366, 0xe8cf, 0xc894, 0xc02b,
-0xc4e7, 0xe682, 0xe9b4, 0x07dc, 0x39bc, 0x4323, 0x1255, 0x11a3, 0x2383, 0xde38,
-0xc201, 0xc28c, 0xc797, 0xe30e, 0xf319, 0x11aa, 0x3329, 0x3e07, 0x11d9, 0x1242,
-0x2173, 0xdd6c, 0xbc12, 0xbfc4, 0xd3cc, 0xe301, 0xf14f, 0x1ed7, 0x3c0b, 0x3bbe,
-0x150a, 0x16d9, 0x1504, 0xded6, 0xc844, 0xc0c3, 0xdedd, 0xf0d7, 0xf666, 0x25d8,
-0x4424, 0x33d0, 0x130e, 0x2876, 0x1370, 0xd7a6, 0xcf17, 0xc604, 0xdfb9, 0xf3d2,
-0xfde9, 0x29bc, 0x4a3a, 0x328f, 0x0b59, 0x293f, 0x0f84, 0xd398, 0xd04b, 0xc938,
-0xdc96, 0xf077, 0x05ff, 0x2a1d, 0x46e9, 0x33e3, 0x0e06, 0x27af, 0x084b, 0xcbee,
-0xc5ed, 0xce50, 0xe4ec, 0xee95, 0x0fc4, 0x3481, 0x4291, 0x2ab8, 0x0ee7, 0x217a,
-0xfbca, 0xd072, 0xc584, 0xcdc2, 0xeeae, 0xf284, 0x0beb, 0x2a91, 0x499c, 0x4ab9,
-0x1751, 0xfb4e, 0xdff4, 0xc548, 0xaa11, 0xcb25, 0x079b, 0x0c5f, 0x3e98, 0x6247,
-0x3e07, 0x0f43, 0xf0e4, 0xca5f, 0xb34f, 0xd401, 0xc893, 0xf3d1, 0x4c26, 0x308b,
-0x22b3, 0x41c0, 0x2279, 0xdc8b, 0xdff8, 0xe310, 0xcceb, 0x027f, 0xf615, 0xee06,
-0x3db0, 0x2392, 0xe01d, 0x1366, 0x3415, 0xe34c, 0xf6fc, 0x29c3, 0xe8c4, 0xee7a,
-0x0fa2, 0xddee, 0xd84b, 0x1d1b, 0x1722, 0xff58, 0x3ac2, 0x1f74, 0xf03f, 0x1870,
-0xfcd6, 0xbff1, 0xe68f, 0x1180, 0xed1f, 0x0a12, 0x3895, 0x07ec, 0x0a31, 0x24b3,
-0xe648, 0xc9fc, 0x0734, 0xf757, 0xd412, 0x1f4f, 0x1e8b, 0xee37, 0x1f0e, 0x1be3,
-0xd43a, 0xefa3, 0x194b, 0xddce, 0xf237, 0x287d, 0xeedf, 0xf88e, 0x2f7f, 0xf704,
-0xd874, 0x1c88, 0x0972, 0xd8d5, 0x1702, 0x0f28, 0xe05e, 0x15f4, 0x1a7c, 0xd9ff,
-0xf6eb, 0x29b0, 0xf002, 0xf068, 0x23d5, 0xf4b8, 0xf046, 0x1d23, 0xf157, 0xd110,
-0x1519, 0x14cc, 0xdede, 0x142d, 0x1a12, 0xe515, 0x0b1c, 0x1636, 0xd4d5, 0xe629,
-0x1cf8, 0xe7c6, 0xea58, 0x2b1f, 0xfc3e, 0xeeea, 0x236a, 0xfb53, 0xcfca, 0x089d,
-0x0488, 0xd160, 0x0a55, 0x141d, 0xe5cd, 0x107d, 0x186d, 0xd8c8, 0xeaf7, 0x1870,
-0xe826, 0xe955, 0x18d7, 0xf4b0, 0xf2f4, 0x198f, 0xf637, 0xd898, 0x0a60, 0x099d,
-0xe121, 0x112c, 0x19f0, 0xe9f0, 0x0257, 0x16f3, 0xea68, 0xe825, 0x11db, 0xf73d,
-0xf784, 0x22c2, 0x01a7, 0xfa94, 0x2329, 0xff98, 0xd3ac, 0x066b, 0x0f20, 0xe092,
-0x0cc3, 0x1ddc, 0xf6f5, 0x1320, 0x1de5, 0xe877, 0xf111, 0x167b, 0xeabe, 0xf59b,
-0x2682, 0xf99e, 0xf763, 0x2689, 0x0359, 0xdfbd, 0x0e98, 0x0da2, 0xe78d, 0x0e20,
-0x0ddb, 0xeff0, 0x11e2, 0x1312, 0xe459, 0xf4b0, 0x1704, 0xee92, 0xf4ab, 0x1ec2,
-0xfc20, 0xf450, 0x169f, 0xfcad, 0xdbac, 0x0468, 0x089e, 0xe794, 0x0e53, 0x118e,
-0xefe9, 0x0e4a, 0x169a, 0xe1da, 0xebc0, 0x15eb, 0xefcb, 0xf2ee, 0x1beb, 0xfce8,
-0xfa9c, 0x1c17, 0xffdb, 0xe6b1, 0x0fc5, 0x065c, 0xe6be, 0x10a6, 0x0c31, 0xefee,
-0x1306, 0x13f9, 0xe94c, 0xfe45, 0x19f0, 0xf32a, 0xfe85, 0x1905, 0xf62a, 0xfd6b,
-0x1747, 0xf729, 0xeaea, 0x11d1, 0x0593, 0xf301, 0x1786, 0x0b5f, 0xf124, 0x0940,
-0x0668, 0xe6ec, 0xfe96, 0x1506, 0xf474, 0x04f3, 0x1923, 0xf708, 0xfe00, 0x1197,
-0xf0a5, 0xe784, 0x0dcb, 0xff73, 0xf084, 0x1476, 0x091e, 0xf640, 0x0af0, 0x0286,
-0xe773, 0xfd6b, 0x0efa, 0xf175, 0xf89a, 0x07af, 0xf9a6, 0x0516, 0x128d, 0x00ff,
-0xfb4e, 0x0ed0, 0xfc70, 0xe60e, 0xf53d, 0xf46c, 0xf494, 0x0bff, 0x1551, 0x06e1,
-0x0c9f, 0x0f55, 0xefab, 0xed70, 0xf731, 0xf0fe, 0xfd13, 0x0d56, 0x068f, 0x0174,
-0x0fee, 0xffe4, 0xea15, 0xfb9a, 0xffd4, 0xf166, 0xfe33, 0x0e6f, 0xfeb8, 0x0068,
-0x0cad, 0xf543, 0xef47, 0x0118, 0xf5be, 0xeb4f, 0x04dc, 0x09b3, 0xf586, 0x0081,
-0x05bb, 0xf123, 0xf60d, 0x03d9, 0xf8d9, 0xfe28, 0x0dac, 0xfb79, 0xf27c, 0xfe7f,
-0xf2c5, 0xeeb0, 0x04d2, 0x030d, 0xfb07, 0x0e9e, 0x0d11, 0xf686, 0xfc94, 0xffbf,
-0xed59, 0xf589, 0x05ab, 0xfa48, 0xffa7, 0x10c1, 0x014b, 0xfa25, 0x09af, 0xfdfc,
-0xf0ef, 0x03b9, 0x0400, 0xf635, 0x063f, 0x0b0b, 0xf9ca, 0x03dd, 0x0d8d, 0xfce6,
-0x00df, 0x0f4b, 0x024e, 0xff59, 0x0dc5, 0x0159, 0xf654, 0x067a, 0x0580, 0xfe5c,
-0x0e74, 0x0f97, 0x0220, 0x099e, 0x09f1, 0xf6cc, 0xfa19, 0x04a0, 0xfb69, 0x0199,
-0x10a2, 0x0726, 0x02f2, 0x0c0d, 0x00c5, 0xf7e4, 0x056d, 0x020c, 0xf921, 0x0880,
-0x0a05, 0xfc9b, 0x05b1, 0x0ba8, 0xfd73, 0x0126, 0x0afa, 0xfedb, 0xfe8e, 0x0754,
-0xff08, 0x010e, 0x0a12, 0xff2a, 0xfc7a, 0x0965, 0x0306, 0xfbf9, 0x0735, 0x05c2,
-0xfdbe, 0x020b, 0x01d4, 0xfd23, 0x035d, 0x0690, 0x0006, 0x0536, 0x0b42, 0x02fd,
-0x0048, 0x04d9, 0xffac, 0xfb96, 0x0522, 0x06ea, 0x01a3, 0x0640, 0x0721, 0x02e7,
-0x04ad, 0x0494, 0xfe70, 0x009e, 0x0380, 0xfafb, 0xfecf, 0x0890, 0x0224, 0xffd6,
-0x0613, 0x005f, 0xfada, 0x0129, 0xfdf3, 0xf949, 0x014d, 0x006d, 0xfa91, 0x0029,
-0x002c, 0xf7d8, 0xff02, 0x0615, 0xfbc4, 0xfc2b, 0x035b, 0xfb89, 0xf601, 0xfa4f,
-0xfabf, 0xfbd9, 0x00a3, 0xfe0a, 0xfbd4, 0x0009, 0xfe8b, 0xf866, 0xf96c, 0xfcbd,
-0xf750, 0xf6d5, 0xfee5, 0xfea6, 0xfc47, 0x00a5, 0x013f, 0xfaa4, 0xf910, 0xf98a,
-0xf6f0, 0xfa55, 0xfc01, 0xfac1, 0xff53, 0x001d, 0xfac1, 0xfb9d, 0xfef2, 0xf9c9,
-0xf9ce, 0xff10, 0xfabf, 0xfab8, 0xfe59, 0xfa05, 0xfa90, 0x00a1, 0xff54, 0xfdbe,
-0x0243, 0xff6b, 0xfac6, 0xfde2, 0xfc78, 0xf927, 0xfc12, 0xfe2f, 0xfc8a, 0xfe15,
-0x00a9, 0xff55, 0x0011, 0x0049, 0xfbfb, 0xfa18, 0xfd23, 0xfbc7, 0xf7ac, 0xfd25,
-0x019e, 0x0030, 0x02a9, 0x0344, 0x0053, 0x0036, 0x003f, 0xfc42, 0xfd77, 0x047f,
-0x022f, 0xffd5, 0x0747, 0x065b, 0xffcd, 0x058c, 0x0801, 0x00b8, 0x029f, 0x057c,
-0x0228, 0x02a9, 0x03ae, 0x0336, 0x052e, 0x06d3, 0x0355, 0x0367, 0x097b, 0x0767,
-0x040b, 0x0708, 0x062b, 0x00f3, 0x010e, 0x0624, 0x0661, 0x0641, 0x0870, 0x08cf,
-0x095c, 0x0672, 0x0114, 0x0064, 0x0450, 0x0372, 0x00f0, 0x074e, 0x0927, 0x0375,
-0x04d0, 0x06fa, 0x0278, 0x00e0, 0x023e, 0x0105, 0x0392, 0x0478, 0x01dc, 0x0633,
-0x06ad, 0x0137, 0x035b, 0x071e, 0x039a, 0x00b9, 0x0238, 0x0257, 0x03b3, 0x032c,
-0x00b5, 0x062b, 0x0920, 0x0425, 0x05d7, 0x09b0, 0x0457, 0x011e, 0x02cb, 0x0112,
-0x01e7, 0x03e0, 0x04a0, 0x09f0, 0x0993, 0x025d, 0x03ab, 0x06f0, 0x01ce, 0xffa9,
-0x0343, 0x03bf, 0x02bc, 0x0192, 0x0175, 0x03f8, 0x025f, 0xfe13, 0xffaf, 0x037b,
-0x017f, 0xff0d, 0x010c, 0x01cc, 0xff47, 0xfda7, 0xff79, 0xffc8, 0xfd08, 0xfdcd,
-0x01e5, 0x03c0, 0x00fa, 0xfdf8, 0xfdb9, 0xff87, 0xff9b, 0xfbe2, 0xfeae, 0x0380,
-0x0014, 0xfe6f, 0x0115, 0x0048, 0xfe1d, 0xff3b, 0xff7b, 0xff0a, 0x0012, 0xfed0,
-0xfed6, 0xffe0, 0xfcbf, 0xfbdb, 0x005d, 0xffb1, 0xf9ae, 0xfb2b, 0x0004, 0xff44,
-0xfc6c, 0xfb62, 0xfdf8, 0xff0d, 0xfbbb, 0xfae7, 0xfd8a, 0xfd70, 0xfaee, 0xfbe3,
-0xfdf3, 0xfc89, 0xfa9a, 0xfb6e, 0xfd82, 0xfcb8, 0xfaa3, 0xfc2a, 0xfeb9, 0xfc5c,
-0xf8a1, 0xfb85, 0x000c, 0xfee7, 0xfbc5, 0xfc1f, 0xfee8, 0xfdac, 0xfae0, 0xfc8b,
-0xfef5, 0xfebd, 0xfdf5, 0xfec1, 0x0023, 0xff0f, 0xfc4a, 0xfdd7, 0x00f5, 0xfea6,
-0xfd0c, 0x002f, 0x0087, 0xfc77, 0xfc93, 0x0024, 0x013b, 0x00dc, 0xfdb0, 0xfcbd,
-0x0060, 0xfed8, 0xfc65, 0xfff5, 0x0160, 0xfef8, 0x0045, 0x0243, 0x0065, 0xfff6,
-0x0124, 0x00f9, 0x00f5, 0x00ae, 0xff8e, 0x00df, 0x02e1, 0xffa3, 0xfea2, 0x0390,
-0x035d, 0xff35, 0xff1f, 0x009b, 0x0048, 0xffed, 0x0005, 0xfff7, 0x0019, 0xff23,
-0xfe36, 0xff91, 0x0112, 0x0088, 0xfff6, 0x00fa, 0x00a3, 0xfe18, 0xfe82, 0x01b6,
-0x00ae, 0xfead, 0x018f, 0x02ef, 0x0126, 0x002b, 0xffb6, 0x01e3, 0x0382, 0x00b0,
-0x00bd, 0x0402, 0x024e, 0x0002, 0x02e3, 0x0327, 0x00b6, 0x01cf, 0x02ca, 0x0250,
-0x0280, 0x01bd, 0x021d, 0x04f6, 0x0340, 0xfee9, 0x0095, 0x0305, 0x00bc, 0x012c,
-0x04fc, 0x0469, 0x0257, 0x027e, 0x0242, 0x01ad, 0x014b, 0x00c3, 0x0147, 0x037a,
-0x036a, 0x00b5, 0x0068, 0x0121, 0xff9a, 0xfec8, 0x0143, 0x0151, 0xfd18, 0xfced,
-0xffbd, 0x0066, 0x007d, 0xff3b, 0xfdd4, 0xfe9a, 0xff0d, 0xfdc1, 0xfe33, 0xffd7,
-0xfd45, 0xfbe9, 0xffc6, 0xff2d, 0xfb3e, 0xfd69, 0x0057, 0xff59, 0xffc4, 0x00ad,
-0x0017, 0xffc4, 0xfde4, 0xfc22, 0xfe08, 0x004b, 0xffd4, 0x0028, 0x0265, 0x00fa,
-0xfdc5, 0xfe0b, 0xff0e, 0xfe78, 0xfdca, 0xfe74, 0xff9b, 0x005c, 0x0106, 0x00eb,
-0x015c, 0x01a8, 0xff52, 0xfee2, 0x00ee, 0xffbe, 0xfec8, 0x010d, 0x01ab, 0x00d9,
-0x0106, 0x010d, 0x00e8, 0x0118, 0x00e8, 0x012b, 0x02b4, 0x0211, 0xff7a, 0xff8e,
-0x0115, 0x0100, 0x00de, 0x02dd, 0x0379, 0x00f9, 0xffd1, 0x0018, 0xfff6, 0xfffa,
-0x000c, 0xfff1, 0x0004, 0x0012, 0xffc4, 0x009c, 0x010c, 0xfffb, 0xffe4, 0x001a,
-0xfff2, 0xfffc, 0x0012, 0xffe2, 0x0015, 0x015a, 0x0257, 0x01c9, 0x004d, 0xfff9,
-0xffdd, 0x0059, 0x019b, 0x004f, 0x0095, 0x030f, 0x0191, 0xff96, 0x015d, 0x0296,
-0x01ee, 0x0205, 0x01f5, 0x0220, 0x0303, 0x0276, 0x01b6, 0x02a2, 0x02f4, 0x01f9,
-0x0209, 0x01e3, 0x0073, 0x00ad, 0x0219, 0x0205, 0x00f2, 0x000a, 0xffc0, 0x00c9,
-0x0105, 0xffac, 0x007c, 0x0198, 0x0051, 0xffcf, 0x001b, 0xfff4, 0x0001, 0x0002,
-0xfffe, 0xfffb, 0x0005, 0xfffd, 0xfff3, 0x0025, 0xff14, 0xfe3b, 0xffa5, 0xfffc,
-0xfee0, 0xff17, 0xffe8, 0x0010, 0xffec, 0x0017, 0xffe5, 0xff21, 0xfef3, 0xfef8,
-0xff4b, 0x002c, 0xffc0, 0xfee9, 0xffc3, 0x001f, 0xff65, 0xffbc, 0x001d, 0xfff2,
-000000, 0x0003, 0xfffc, 0xfffc, 0x000a, 0xffec, 0x0015, 0x0095, 0x002c, 0xffc9,
-0x006a, 0x0078, 0xfff2, 0xfffb, 0x0006, 0xfffa, 0x0002, 0xfffd, 0x0004, 0xfff4,
-0x0010, 0xfff2, 0xfff7, 0x003a, 0xfeb1, 0xfe3a, 0xfff4, 0x0020, 0xffde, 0x0015,
-0xfff6, 000000, 0x0002, 0xfffc, 0x0001, 0xfffe, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000 };
diff --git a/1.2-netsec/chanvars.c b/1.2-netsec/chanvars.c
deleted file mode 100644
index d01c9260b..000000000
--- a/1.2-netsec/chanvars.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Channel Variables
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/chanvars.h"
-#include "asterisk/logger.h"
-#include "asterisk/strings.h"
-
-struct ast_var_t *ast_var_assign(const char *name, const char *value)
-{
- int i;
- struct ast_var_t *var;
-
- var = calloc(sizeof(struct ast_var_t) + strlen(name) + 1 + strlen(value) + 1, sizeof(char));
-
- if (var == NULL) {
- ast_log(LOG_WARNING, "Out of memory\n");
- return NULL;
- }
-
- i = strlen(name) + 1;
- ast_copy_string(var->name, name, i);
- var->value = var->name + i;
- ast_copy_string(var->value, value, strlen(value) + 1);
-
- return var;
-}
-
-void ast_var_delete(struct ast_var_t *var)
-{
- if (var)
- free(var);
-}
-
-char *ast_var_name(struct ast_var_t *var)
-{
- char *name;
-
- if (var == NULL)
- return NULL;
- if (var->name == NULL)
- return NULL;
- /* Return the name without the initial underscores */
- if (var->name[0] == '_') {
- if (var->name[1] == '_')
- name = (char*)&(var->name[2]);
- else
- name = (char*)&(var->name[1]);
- } else
- name = var->name;
- return name;
-}
-
-char *ast_var_full_name(struct ast_var_t *var)
-{
- return (var ? var->name : NULL);
-}
-
-char *ast_var_value(struct ast_var_t *var)
-{
- return (var ? var->value : NULL);
-}
-
-
diff --git a/1.2-netsec/cli.c b/1.2-netsec/cli.c
deleted file mode 100644
index e2a646d5b..000000000
--- a/1.2-netsec/cli.c
+++ /dev/null
@@ -1,1386 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Standard Command Line Interface
- *
- */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/signal.h>
-#include <stdio.h>
-#include <signal.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/cli.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/channel.h"
-#include "asterisk/manager.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-/* For rl_filename_completion */
-#include "editline/readline/readline.h"
-/* For module directory */
-#include "asterisk/version.h"
-
-extern const char *ast_build_hostname;
-extern const char *ast_build_kernel;
-extern const char *ast_build_machine;
-extern const char *ast_build_os;
-extern const char *ast_build_date;
-extern const char *ast_build_user;
-
-extern unsigned long global_fin, global_fout;
-
-void ast_cli(int fd, char *fmt, ...)
-{
- char *stuff;
- int res = 0;
- va_list ap;
-
- va_start(ap, fmt);
- res = vasprintf(&stuff, fmt, ap);
- va_end(ap);
- if (res == -1) {
- ast_log(LOG_ERROR, "Out of memory\n");
- } else {
- ast_carefulwrite(fd, stuff, strlen(stuff), 100);
- free(stuff);
- }
-}
-
-AST_MUTEX_DEFINE_STATIC(clilock);
-
-struct ast_cli_entry *helpers = NULL;
-
-static char load_help[] =
-"Usage: load <module name>\n"
-" Loads the specified module into Asterisk.\n";
-
-static char unload_help[] =
-"Usage: unload [-f|-h] <module name>\n"
-" Unloads the specified module from Asterisk. The -f\n"
-" option causes the module to be unloaded even if it is\n"
-" in use (may cause a crash) and the -h module causes the\n"
-" module to be unloaded even if the module says it cannot, \n"
-" which almost always will cause a crash.\n";
-
-static char help_help[] =
-"Usage: help [topic]\n"
-" When called with a topic as an argument, displays usage\n"
-" information on the given command. If called without a\n"
-" topic, it provides a list of commands.\n";
-
-static char chanlist_help[] =
-"Usage: show channels [concise|verbose]\n"
-" Lists currently defined channels and some information about them. If\n"
-" 'concise' is specified, the format is abridged and in a more easily\n"
-" machine parsable format. If 'verbose' is specified, the output includes\n"
-" more and longer fields.\n";
-
-static char reload_help[] =
-"Usage: reload [module ...]\n"
-" Reloads configuration files for all listed modules which support\n"
-" reloading, or for all supported modules if none are listed.\n";
-
-static char set_verbose_help[] =
-"Usage: set verbose <level>\n"
-" Sets level of verbose messages to be displayed. 0 means\n"
-" no messages should be displayed. Equivalent to -v[v[v...]]\n"
-" on startup\n";
-
-static char set_debug_help[] =
-"Usage: set debug <level>\n"
-" Sets level of core debug messages to be displayed. 0 means\n"
-" no messages should be displayed. Equivalent to -d[d[d...]]\n"
-" on startup.\n";
-
-static char softhangup_help[] =
-"Usage: soft hangup <channel>\n"
-" Request that a channel be hung up. The hangup takes effect\n"
-" the next time the driver reads or writes from the channel\n";
-
-static int handle_load(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- if (ast_load_resource(argv[1])) {
- ast_cli(fd, "Unable to load module %s\n", argv[1]);
- return RESULT_FAILURE;
- }
- return RESULT_SUCCESS;
-}
-
-static int handle_reload(int fd, int argc, char *argv[])
-{
- int x;
- int res;
- if (argc < 1)
- return RESULT_SHOWUSAGE;
- if (argc > 1) {
- for (x=1;x<argc;x++) {
- res = ast_module_reload(argv[x]);
- switch(res) {
- case 0:
- ast_cli(fd, "No such module '%s'\n", argv[x]);
- break;
- case 1:
- ast_cli(fd, "Module '%s' does not support reload\n", argv[x]);
- break;
- }
- }
- } else
- ast_module_reload(NULL);
- return RESULT_SUCCESS;
-}
-
-static int handle_set_verbose(int fd, int argc, char *argv[])
-{
- int val = 0;
- int oldval = 0;
-
- /* Has a hidden 'at least' argument */
- if ((argc != 3) && (argc != 4))
- return RESULT_SHOWUSAGE;
- if ((argc == 4) && strcasecmp(argv[2], "atleast"))
- return RESULT_SHOWUSAGE;
- oldval = option_verbose;
- if (argc == 3)
- option_verbose = atoi(argv[2]);
- else {
- val = atoi(argv[3]);
- if (val > option_verbose)
- option_verbose = val;
- }
- if (oldval != option_verbose && option_verbose > 0)
- ast_cli(fd, "Verbosity was %d and is now %d\n", oldval, option_verbose);
- else if (oldval > 0 && option_verbose > 0)
- ast_cli(fd, "Verbosity is at least %d\n", option_verbose);
- else if (oldval > 0 && option_verbose == 0)
- ast_cli(fd, "Verbosity is now OFF\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_set_debug(int fd, int argc, char *argv[])
-{
- int val = 0;
- int oldval = 0;
- /* Has a hidden 'at least' argument */
- if ((argc != 3) && (argc != 4))
- return RESULT_SHOWUSAGE;
- if ((argc == 4) && strcasecmp(argv[2], "atleast"))
- return RESULT_SHOWUSAGE;
- oldval = option_debug;
- if (argc == 3)
- option_debug = atoi(argv[2]);
- else {
- val = atoi(argv[3]);
- if (val > option_debug)
- option_debug = val;
- }
- if (oldval != option_debug && option_debug > 0)
- ast_cli(fd, "Core debug was %d and is now %d\n", oldval, option_debug);
- else if (oldval > 0 && option_debug > 0)
- ast_cli(fd, "Core debug is at least %d\n", option_debug);
- else if (oldval > 0 && option_debug == 0)
- ast_cli(fd, "Core debug is now OFF\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_unload(int fd, int argc, char *argv[])
-{
- int x;
- int force=AST_FORCE_SOFT;
- if (argc < 2)
- return RESULT_SHOWUSAGE;
- for (x=1;x<argc;x++) {
- if (argv[x][0] == '-') {
- switch(argv[x][1]) {
- case 'f':
- force = AST_FORCE_FIRM;
- break;
- case 'h':
- force = AST_FORCE_HARD;
- break;
- default:
- return RESULT_SHOWUSAGE;
- }
- } else if (x != argc - 1)
- return RESULT_SHOWUSAGE;
- else if (ast_unload_resource(argv[x], force)) {
- ast_cli(fd, "Unable to unload resource %s\n", argv[x]);
- return RESULT_FAILURE;
- }
- }
- return RESULT_SUCCESS;
-}
-
-#define MODLIST_FORMAT "%-30s %-40.40s %-10d\n"
-#define MODLIST_FORMAT2 "%-30s %-40.40s %-10s\n"
-
-AST_MUTEX_DEFINE_STATIC(climodentrylock);
-static int climodentryfd = -1;
-
-static int modlist_modentry(const char *module, const char *description, int usecnt, const char *like)
-{
- /* Comparing the like with the module */
- if (strcasestr(module, like) ) {
- ast_cli(climodentryfd, MODLIST_FORMAT, module, description, usecnt);
- return 1;
- }
- return 0;
-}
-
-static char modlist_help[] =
-"Usage: show modules [like keyword]\n"
-" Shows Asterisk modules currently in use, and usage statistics.\n";
-
-static char version_help[] =
-"Usage: show version\n"
-" Shows Asterisk version information.\n";
-
-static char uptime_help[] =
-"Usage: show uptime [seconds]\n"
-" Shows Asterisk uptime information.\n"
-" The seconds word returns the uptime in seconds only.\n";
-
-static char *format_uptimestr(time_t timeval)
-{
- int years = 0, weeks = 0, days = 0, hours = 0, mins = 0, secs = 0;
- char timestr[256]="";
- int bytes = 0;
- int maxbytes = 0;
- int offset = 0;
-#define SECOND (1)
-#define MINUTE (SECOND*60)
-#define HOUR (MINUTE*60)
-#define DAY (HOUR*24)
-#define WEEK (DAY*7)
-#define YEAR (DAY*365)
-#define ESS(x) ((x == 1) ? "" : "s")
-
- maxbytes = sizeof(timestr);
- if (timeval < 0)
- return NULL;
- if (timeval > YEAR) {
- years = (timeval / YEAR);
- timeval -= (years * YEAR);
- if (years > 0) {
- snprintf(timestr + offset, maxbytes, "%d year%s, ", years, ESS(years));
- bytes = strlen(timestr + offset);
- offset += bytes;
- maxbytes -= bytes;
- }
- }
- if (timeval > WEEK) {
- weeks = (timeval / WEEK);
- timeval -= (weeks * WEEK);
- if (weeks > 0) {
- snprintf(timestr + offset, maxbytes, "%d week%s, ", weeks, ESS(weeks));
- bytes = strlen(timestr + offset);
- offset += bytes;
- maxbytes -= bytes;
- }
- }
- if (timeval > DAY) {
- days = (timeval / DAY);
- timeval -= (days * DAY);
- if (days > 0) {
- snprintf(timestr + offset, maxbytes, "%d day%s, ", days, ESS(days));
- bytes = strlen(timestr + offset);
- offset += bytes;
- maxbytes -= bytes;
- }
- }
- if (timeval > HOUR) {
- hours = (timeval / HOUR);
- timeval -= (hours * HOUR);
- if (hours > 0) {
- snprintf(timestr + offset, maxbytes, "%d hour%s, ", hours, ESS(hours));
- bytes = strlen(timestr + offset);
- offset += bytes;
- maxbytes -= bytes;
- }
- }
- if (timeval > MINUTE) {
- mins = (timeval / MINUTE);
- timeval -= (mins * MINUTE);
- if (mins > 0) {
- snprintf(timestr + offset, maxbytes, "%d minute%s, ", mins, ESS(mins));
- bytes = strlen(timestr + offset);
- offset += bytes;
- maxbytes -= bytes;
- }
- }
- secs = timeval;
-
- if (secs > 0) {
- snprintf(timestr + offset, maxbytes, "%d second%s", secs, ESS(secs));
- }
-
- return timestr ? strdup(timestr) : NULL;
-}
-
-static int handle_showuptime(int fd, int argc, char *argv[])
-{
- time_t curtime, tmptime;
- char *timestr;
- int printsec;
-
- printsec = ((argc == 3) && (!strcasecmp(argv[2],"seconds")));
- if ((argc != 2) && (!printsec))
- return RESULT_SHOWUSAGE;
-
- time(&curtime);
- if (ast_startuptime) {
- tmptime = curtime - ast_startuptime;
- if (printsec) {
- ast_cli(fd, "System uptime: %lu\n",(u_long)tmptime);
- } else {
- timestr = format_uptimestr(tmptime);
- if (timestr) {
- ast_cli(fd, "System uptime: %s\n", timestr);
- free(timestr);
- }
- }
- }
- if (ast_lastreloadtime) {
- tmptime = curtime - ast_lastreloadtime;
- if (printsec) {
- ast_cli(fd, "Last reload: %lu\n", (u_long) tmptime);
- } else {
- timestr = format_uptimestr(tmptime);
- if ((timestr) && (!printsec)) {
- ast_cli(fd, "Last reload: %s\n", timestr);
- free(timestr);
- }
- }
- }
- return RESULT_SUCCESS;
-}
-
-static int handle_modlist(int fd, int argc, char *argv[])
-{
- char *like = "";
- if (argc == 3)
- return RESULT_SHOWUSAGE;
- else if (argc >= 4) {
- if (strcmp(argv[2],"like"))
- return RESULT_SHOWUSAGE;
- like = argv[3];
- }
-
- ast_mutex_lock(&climodentrylock);
- climodentryfd = fd;
- ast_cli(fd, MODLIST_FORMAT2, "Module", "Description", "Use Count");
- ast_cli(fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like));
- climodentryfd = -1;
- ast_mutex_unlock(&climodentrylock);
- return RESULT_SUCCESS;
-}
-#undef MODLIST_FORMAT
-#undef MODLIST_FORMAT2
-
-static int handle_version(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, "Asterisk %s built by %s @ %s on a %s running %s on %s\n",
- ASTERISK_VERSION, ast_build_user, ast_build_hostname,
- ast_build_machine, ast_build_os, ast_build_date);
- return RESULT_SUCCESS;
-}
-
-static int handle_chanlist(int fd, int argc, char *argv[])
-{
-#define FORMAT_STRING "%-20.20s %-20.20s %-7.7s %-30.30s\n"
-#define FORMAT_STRING2 "%-20.20s %-20.20s %-7.7s %-30.30s\n"
-#define CONCISE_FORMAT_STRING "%s:%s:%s:%d:%s:%s:%s:%s:%s:%d:%s:%s\n"
-#define VERBOSE_FORMAT_STRING "%-20.20s %-20.20s %-16.16s %4d %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
-#define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
-
- struct ast_channel *c = NULL, *bc = NULL;
- char durbuf[10] = "-";
- char locbuf[40];
- char appdata[40];
- int duration;
- int durh, durm, durs;
- int numchans = 0, concise = 0, verbose = 0;
-
- concise = (argc == 3 && (!strcasecmp(argv[2],"concise")));
- verbose = (argc == 3 && (!strcasecmp(argv[2],"verbose")));
-
- if (argc < 2 || argc > 3 || (argc == 3 && !concise && !verbose))
- return RESULT_SHOWUSAGE;
-
- if (!concise && !verbose)
- ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)");
- else if (verbose)
- ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data",
- "CallerID", "Duration", "Accountcode", "BridgedTo");
- while ((c = ast_channel_walk_locked(c)) != NULL) {
- bc = ast_bridged_channel(c);
- if ((concise || verbose) && c->cdr && !ast_tvzero(c->cdr->start)) {
- duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
- if (verbose) {
- durh = duration / 3600;
- durm = (duration % 3600) / 60;
- durs = duration % 60;
- snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs);
- } else {
- snprintf(durbuf, sizeof(durbuf), "%d", duration);
- }
- } else {
- durbuf[0] = '\0';
- }
- if (concise) {
- ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
- c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "" ): "",
- (c->cid.cid_num && !ast_strlen_zero(c->cid.cid_num)) ? c->cid.cid_num : "",
- (c->accountcode && !ast_strlen_zero(c->accountcode)) ? c->accountcode : "", c->amaflags,
- durbuf, bc ? bc->name : "(None)");
- } else if (verbose) {
- ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
- c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)",
- (c->cid.cid_num && !ast_strlen_zero(c->cid.cid_num)) ? c->cid.cid_num : "", durbuf,
- (c->accountcode && !ast_strlen_zero(c->accountcode)) ? c->accountcode : "", bc ? bc->name : "(None)");
- } else {
- if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten))
- snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority);
- else
- strcpy(locbuf, "(None)");
- if (c->appl) {
- snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, c->data ? c->data : "");
- } else {
- strcpy(appdata, "(None)");
- }
- ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
- }
- numchans++;
- ast_mutex_unlock(&c->lock);
- }
- if (!concise) {
- ast_cli(fd, "%d active channel%s\n", numchans, (numchans!=1) ? "s" : "");
- if (option_maxcalls)
- ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n", ast_active_calls(), option_maxcalls, (ast_active_calls()!=1) ? "s" : "", ((float)ast_active_calls() / (float)option_maxcalls) * 100.0);
- else
- ast_cli(fd, "%d active call%s\n", ast_active_calls(), (ast_active_calls()!=1) ? "s" : "");
- }
- return RESULT_SUCCESS;
-
-#undef FORMAT_STRING
-#undef FORMAT_STRING2
-#undef CONCISE_FORMAT_STRING
-#undef VERBOSE_FORMAT_STRING
-#undef VERBOSE_FORMAT_STRING2
-}
-
-static char showchan_help[] =
-"Usage: show channel <channel>\n"
-" Shows lots of information about the specified channel.\n";
-
-static char debugchan_help[] =
-"Usage: debug channel <channel>\n"
-" Enables debugging on a specific channel.\n";
-
-static char debuglevel_help[] =
-"Usage: debug level <level> [filename]\n"
-" Set debug to specified level (0 to disable). If filename\n"
-"is specified, debugging will be limited to just that file.\n";
-
-static char nodebugchan_help[] =
-"Usage: no debug channel <channel>\n"
-" Disables debugging on a specific channel.\n";
-
-static char commandcomplete_help[] =
-"Usage: _command complete \"<line>\" text state\n"
-" This function is used internally to help with command completion and should.\n"
-" never be called by the user directly.\n";
-
-static char commandnummatches_help[] =
-"Usage: _command nummatches \"<line>\" text \n"
-" This function is used internally to help with command completion and should.\n"
-" never be called by the user directly.\n";
-
-static char commandmatchesarray_help[] =
-"Usage: _command matchesarray \"<line>\" text \n"
-" This function is used internally to help with command completion and should.\n"
-" never be called by the user directly.\n";
-
-static int handle_softhangup(int fd, int argc, char *argv[])
-{
- struct ast_channel *c=NULL;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- c = ast_get_channel_by_name_locked(argv[2]);
- if (c) {
- ast_cli(fd, "Requested Hangup on channel '%s'\n", c->name);
- ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
- ast_mutex_unlock(&c->lock);
- } else
- ast_cli(fd, "%s is not a known channel\n", argv[2]);
- return RESULT_SUCCESS;
-}
-
-static char *__ast_cli_generator(char *text, char *word, int state, int lock);
-
-static int handle_commandmatchesarray(int fd, int argc, char *argv[])
-{
- char *buf, *obuf;
- int buflen = 2048;
- int len = 0;
- char **matches;
- int x, matchlen;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- buf = malloc(buflen);
- if (!buf)
- return RESULT_FAILURE;
- buf[len] = '\0';
- matches = ast_cli_completion_matches(argv[2], argv[3]);
- if (matches) {
- for (x=0; matches[x]; x++) {
-#if 0
- printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]);
-#endif
- matchlen = strlen(matches[x]) + 1;
- if (len + matchlen >= buflen) {
- buflen += matchlen * 3;
- obuf = buf;
- buf = realloc(obuf, buflen);
- if (!buf)
- /* Out of memory... Just free old buffer and be done */
- free(obuf);
- }
- if (buf)
- len += sprintf( buf + len, "%s ", matches[x]);
- free(matches[x]);
- matches[x] = NULL;
- }
- free(matches);
- }
-#if 0
- printf("array for '%s' %s got '%s'\n", argv[2], argv[3], buf);
-#endif
-
- if (buf) {
- ast_cli(fd, "%s%s",buf, AST_CLI_COMPLETE_EOF);
- free(buf);
- } else
- ast_cli(fd, "NULL\n");
-
- return RESULT_SUCCESS;
-}
-
-
-
-static int handle_commandnummatches(int fd, int argc, char *argv[])
-{
- int matches = 0;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- matches = ast_cli_generatornummatches(argv[2], argv[3]);
-
-#if 0
- printf("Search for '%s' %s got '%d'\n", argv[2], argv[3], matches);
-#endif
- ast_cli(fd, "%d", matches);
-
- return RESULT_SUCCESS;
-}
-
-static int handle_commandcomplete(int fd, int argc, char *argv[])
-{
- char *buf;
-#if 0
- printf("Search for %d args: '%s', '%s', '%s', '%s'\n", argc, argv[0], argv[1], argv[2], argv[3]);
-#endif
- if (argc != 5)
- return RESULT_SHOWUSAGE;
- buf = __ast_cli_generator(argv[2], argv[3], atoi(argv[4]), 0);
-#if 0
- printf("Search for '%s' %s %d got '%s'\n", argv[2], argv[3], atoi(argv[4]), buf);
-#endif
- if (buf) {
- ast_cli(fd, buf);
- free(buf);
- } else
- ast_cli(fd, "NULL\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_debuglevel(int fd, int argc, char *argv[])
-{
- int newlevel;
- char *filename = "<any>";
- if ((argc < 3) || (argc > 4))
- return RESULT_SHOWUSAGE;
- if (sscanf(argv[2], "%d", &newlevel) != 1)
- return RESULT_SHOWUSAGE;
- option_debug = newlevel;
- if (argc == 4) {
- filename = argv[3];
- ast_copy_string(debug_filename, filename, sizeof(debug_filename));
- } else {
- debug_filename[0] = '\0';
- }
- ast_cli(fd, "Debugging level set to %d, file '%s'\n", newlevel, filename);
- return RESULT_SUCCESS;
-}
-
-#define DEBUGCHAN_FLAG 0x80000000
-/* XXX todo: merge next two functions!!! */
-static int handle_debugchan(int fd, int argc, char *argv[])
-{
- struct ast_channel *c=NULL;
- int is_all;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
-
- is_all = !strcasecmp("all", argv[2]);
- if (is_all) {
- global_fin |= DEBUGCHAN_FLAG;
- global_fout |= DEBUGCHAN_FLAG;
- c = ast_channel_walk_locked(NULL);
- } else {
- c = ast_get_channel_by_name_locked(argv[2]);
- if (c == NULL)
- ast_cli(fd, "No such channel %s\n", argv[2]);
- }
- while(c) {
- if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) {
- c->fin |= DEBUGCHAN_FLAG;
- c->fout |= DEBUGCHAN_FLAG;
- ast_cli(fd, "Debugging enabled on channel %s\n", c->name);
- }
- ast_mutex_unlock(&c->lock);
- if (!is_all)
- break;
- c = ast_channel_walk_locked(c);
- }
- ast_cli(fd, "Debugging on new channels is enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_nodebugchan(int fd, int argc, char *argv[])
-{
- struct ast_channel *c=NULL;
- int is_all;
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- is_all = !strcasecmp("all", argv[3]);
- if (is_all) {
- global_fin &= ~DEBUGCHAN_FLAG;
- global_fout &= ~DEBUGCHAN_FLAG;
- c = ast_channel_walk_locked(NULL);
- } else {
- c = ast_get_channel_by_name_locked(argv[3]);
- if (c == NULL)
- ast_cli(fd, "No such channel %s\n", argv[3]);
- }
- while(c) {
- if ((c->fin & DEBUGCHAN_FLAG) || (c->fout & DEBUGCHAN_FLAG)) {
- c->fin &= ~DEBUGCHAN_FLAG;
- c->fout &= ~DEBUGCHAN_FLAG;
- ast_cli(fd, "Debugging disabled on channel %s\n", c->name);
- }
- ast_mutex_unlock(&c->lock);
- if (!is_all)
- break;
- c = ast_channel_walk_locked(c);
- }
- ast_cli(fd, "Debugging on new channels is disabled\n");
- return RESULT_SUCCESS;
-}
-
-
-
-static int handle_showchan(int fd, int argc, char *argv[])
-{
- struct ast_channel *c=NULL;
- struct timeval now;
- char buf[2048];
- char cdrtime[256];
- long elapsed_seconds=0;
- int hour=0, min=0, sec=0;
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- now = ast_tvnow();
- c = ast_get_channel_by_name_locked(argv[2]);
- if (!c) {
- ast_cli(fd, "%s is not a known channel\n", argv[2]);
- return RESULT_SUCCESS;
- }
- if(c->cdr) {
- elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
- hour = elapsed_seconds / 3600;
- min = (elapsed_seconds % 3600) / 60;
- sec = elapsed_seconds % 60;
- snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec);
- } else
- strcpy(cdrtime, "N/A");
- ast_cli(fd,
- " -- General --\n"
- " Name: %s\n"
- " Type: %s\n"
- " UniqueID: %s\n"
- " Caller ID: %s\n"
- " Caller ID Name: %s\n"
- " DNID Digits: %s\n"
- " State: %s (%d)\n"
- " Rings: %d\n"
- " NativeFormat: %d\n"
- " WriteFormat: %d\n"
- " ReadFormat: %d\n"
- "1st File Descriptor: %d\n"
- " Frames in: %d%s\n"
- " Frames out: %d%s\n"
- " Time to Hangup: %ld\n"
- " Elapsed Time: %s\n"
- " Direct Bridge: %s\n"
- "Indirect Bridge: %s\n"
- " -- PBX --\n"
- " Context: %s\n"
- " Extension: %s\n"
- " Priority: %d\n"
- " Call Group: %d\n"
- " Pickup Group: %d\n"
- " Application: %s\n"
- " Data: %s\n"
- " Blocking in: %s\n",
- c->name, c->type, c->uniqueid,
- (c->cid.cid_num ? c->cid.cid_num : "(N/A)"),
- (c->cid.cid_name ? c->cid.cid_name : "(N/A)"),
- (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ), ast_state2str(c->_state), c->_state, c->rings, c->nativeformats, c->writeformat, c->readformat,
- c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
- c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
- cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>",
- c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
- ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
- (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
-
- if(pbx_builtin_serialize_variables(c,buf,sizeof(buf)))
- ast_cli(fd," Variables:\n%s\n",buf);
- if(c->cdr && ast_cdr_serialize_variables(c->cdr,buf, sizeof(buf), '=', '\n', 1))
- ast_cli(fd," CDR Variables:\n%s\n",buf);
-
- ast_mutex_unlock(&c->lock);
- return RESULT_SUCCESS;
-}
-
-static char *complete_show_channels(char *line, char *word, int pos, int state)
-{
- static char *choices[] = { "concise", "verbose" };
- int match = 0;
- int x;
- if (pos != 2)
- return NULL;
- for (x=0;x<sizeof(choices) / sizeof(choices[0]);x++) {
- if (!strncasecmp(word, choices[x], strlen(word))) {
- match++;
- if (match > state) return strdup(choices[x]);
- }
- }
- return NULL;
-}
-
-static char *complete_ch_helper(char *line, char *word, int pos, int state, int rpos)
-{
- struct ast_channel *c = NULL;
- int which=0;
- char *ret = NULL;
-
- if (pos != rpos)
- return NULL;
- while ( (c = ast_channel_walk_locked(c)) != NULL) {
- if (!strncasecmp(word, c->name, strlen(word))) {
- if (++which > state) {
- ret = strdup(c->name);
- ast_mutex_unlock(&c->lock);
- break;
- }
- }
- ast_mutex_unlock(&c->lock);
- }
- return ret;
-}
-
-static char *complete_ch_3(char *line, char *word, int pos, int state)
-{
- return complete_ch_helper(line, word, pos, state, 2);
-}
-
-static char *complete_ch_4(char *line, char *word, int pos, int state)
-{
- return complete_ch_helper(line, word, pos, state, 3);
-}
-
-static char *complete_mod_2(char *line, char *word, int pos, int state)
-{
- return ast_module_helper(line, word, pos, state, 1, 1);
-}
-
-static char *complete_mod_4(char *line, char *word, int pos, int state)
-{
- return ast_module_helper(line, word, pos, state, 3, 0);
-}
-
-static char *complete_fn(char *line, char *word, int pos, int state)
-{
- char *c;
- char filename[256];
- if (pos != 1)
- return NULL;
- if (word[0] == '/')
- ast_copy_string(filename, word, sizeof(filename));
- else
- snprintf(filename, sizeof(filename), "%s/%s", (char *)ast_config_AST_MODULE_DIR, word);
- c = (char*)filename_completion_function(filename, state);
- if (c && word[0] != '/')
- c += (strlen((char*)ast_config_AST_MODULE_DIR) + 1);
- return c ? strdup(c) : c;
-}
-
-static int handle_help(int fd, int argc, char *argv[]);
-
-static struct ast_cli_entry builtins[] = {
- /* Keep alphabetized, with longer matches first (example: abcd before abc) */
- { { "_command", "complete", NULL }, handle_commandcomplete, "Command complete", commandcomplete_help },
- { { "_command", "nummatches", NULL }, handle_commandnummatches, "Returns number of command matches", commandnummatches_help },
- { { "_command", "matchesarray", NULL }, handle_commandmatchesarray, "Returns command matches array", commandmatchesarray_help },
- { { "debug", "channel", NULL }, handle_debugchan, "Enable debugging on a channel", debugchan_help, complete_ch_3 },
- { { "debug", "level", NULL }, handle_debuglevel, "Set global debug level", debuglevel_help },
- { { "help", NULL }, handle_help, "Display help list, or specific help on a command", help_help },
- { { "load", NULL }, handle_load, "Load a dynamic module by name", load_help, complete_fn },
- { { "no", "debug", "channel", NULL }, handle_nodebugchan, "Disable debugging on a channel", nodebugchan_help, complete_ch_4 },
- { { "reload", NULL }, handle_reload, "Reload configuration", reload_help, complete_mod_2 },
- { { "set", "debug", NULL }, handle_set_debug, "Set level of debug chattiness", set_debug_help },
- { { "set", "verbose", NULL }, handle_set_verbose, "Set level of verboseness", set_verbose_help },
- { { "show", "channel", NULL }, handle_showchan, "Display information on a specific channel", showchan_help, complete_ch_3 },
- { { "show", "channels", NULL }, handle_chanlist, "Display information on channels", chanlist_help, complete_show_channels },
- { { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help },
- { { "show", "modules", "like", NULL }, handle_modlist, "List modules and info", modlist_help, complete_mod_4 },
- { { "show", "uptime", NULL }, handle_showuptime, "Show uptime information", uptime_help },
- { { "show", "version", NULL }, handle_version, "Display version info", version_help },
- { { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch_3 },
- { { "unload", NULL }, handle_unload, "Unload a dynamic module by name", unload_help, complete_fn },
- { { NULL }, NULL, NULL, NULL }
-};
-
-static struct ast_cli_entry *find_cli(char *cmds[], int exact)
-{
- int x;
- int y;
- int match;
- struct ast_cli_entry *e=NULL;
-
- for (e=helpers;e;e=e->next) {
- match = 1;
- for (y=0;match && cmds[y]; y++) {
- if (!e->cmda[y] && !exact)
- break;
- if (!e->cmda[y] || strcasecmp(e->cmda[y], cmds[y]))
- match = 0;
- }
- if ((exact > -1) && e->cmda[y])
- match = 0;
- if (match)
- break;
- }
- if (e)
- return e;
- for (x=0;builtins[x].cmda[0];x++) {
- /* start optimistic */
- match = 1;
- for (y=0;match && cmds[y]; y++) {
- /* If there are no more words in the candidate command, then we're
- there. */
- if (!builtins[x].cmda[y] && !exact)
- break;
- /* If there are no more words in the command (and we're looking for
- an exact match) or there is a difference between the two words,
- then this is not a match */
- if (!builtins[x].cmda[y] || strcasecmp(builtins[x].cmda[y], cmds[y]))
- match = 0;
- }
- /* If more words are needed to complete the command then this is not
- a candidate (unless we're looking for a really inexact answer */
- if ((exact > -1) && builtins[x].cmda[y])
- match = 0;
- if (match)
- return &builtins[x];
- }
- return NULL;
-}
-
-static void join(char *dest, size_t destsize, char *w[], int tws)
-{
- int x;
- /* Join words into a string */
- if (!dest || destsize < 1) {
- return;
- }
- dest[0] = '\0';
- for (x=0;w[x];x++) {
- if (x)
- strncat(dest, " ", destsize - strlen(dest) - 1);
- strncat(dest, w[x], destsize - strlen(dest) - 1);
- }
- if (tws && !ast_strlen_zero(dest))
- strncat(dest, " ", destsize - strlen(dest) - 1);
-}
-
-static void join2(char *dest, size_t destsize, char *w[])
-{
- int x;
- /* Join words into a string */
- if (!dest || destsize < 1) {
- return;
- }
- dest[0] = '\0';
- for (x=0;w[x];x++) {
- strncat(dest, w[x], destsize - strlen(dest) - 1);
- }
-}
-
-static char *find_best(char *argv[])
-{
- static char cmdline[80];
- int x;
- /* See how close we get, then print the */
- char *myargv[AST_MAX_CMD_LEN];
- for (x=0;x<AST_MAX_CMD_LEN;x++)
- myargv[x]=NULL;
- for (x=0;argv[x];x++) {
- myargv[x] = argv[x];
- if (!find_cli(myargv, -1))
- break;
- }
- join(cmdline, sizeof(cmdline), myargv, 0);
- return cmdline;
-}
-
-int ast_cli_unregister(struct ast_cli_entry *e)
-{
- struct ast_cli_entry *cur, *l=NULL;
- ast_mutex_lock(&clilock);
- cur = helpers;
- while(cur) {
- if (e == cur) {
- if (e->inuse) {
- ast_log(LOG_WARNING, "Can't remove command that is in use\n");
- } else {
- /* Rewrite */
- if (l)
- l->next = e->next;
- else
- helpers = e->next;
- e->next = NULL;
- break;
- }
- }
- l = cur;
- cur = cur->next;
- }
- ast_mutex_unlock(&clilock);
- return 0;
-}
-
-int ast_cli_register(struct ast_cli_entry *e)
-{
- struct ast_cli_entry *cur, *l=NULL;
- char fulle[80] ="", fulltst[80] ="";
- static int len;
- ast_mutex_lock(&clilock);
- join2(fulle, sizeof(fulle), e->cmda);
- if (find_cli(e->cmda, -1)) {
- ast_mutex_unlock(&clilock);
- ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
- return -1;
- }
- cur = helpers;
- while(cur) {
- join2(fulltst, sizeof(fulltst), cur->cmda);
- len = strlen(fulltst);
- if (strlen(fulle) < len)
- len = strlen(fulle);
- if (strncasecmp(fulle, fulltst, len) < 0) {
- if (l) {
- e->next = l->next;
- l->next = e;
- } else {
- e->next = helpers;
- helpers = e;
- }
- break;
- }
- l = cur;
- cur = cur->next;
- }
- if (!cur) {
- if (l)
- l->next = e;
- else
- helpers = e;
- e->next = NULL;
- }
- ast_mutex_unlock(&clilock);
- return 0;
-}
-
-/*
- * register/unregister an array of entries.
- */
-void ast_cli_register_multiple(struct ast_cli_entry *e, int len)
-{
- int i;
-
- for (i=0; i < len; i++)
- ast_cli_register(e + i);
-}
-
-void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
-{
- int i;
-
- for (i=0; i < len; i++)
- ast_cli_unregister(e + i);
-}
-
-static int help_workhorse(int fd, char *match[])
-{
- char fullcmd1[80] = "";
- char fullcmd2[80] = "";
- char matchstr[80];
- char *fullcmd = NULL;
- struct ast_cli_entry *e, *e1, *e2;
- e1 = builtins;
- e2 = helpers;
- if (match)
- join(matchstr, sizeof(matchstr), match, 0);
- while(e1->cmda[0] || e2) {
- if (e2)
- join(fullcmd2, sizeof(fullcmd2), e2->cmda, 0);
- if (e1->cmda[0])
- join(fullcmd1, sizeof(fullcmd1), e1->cmda, 0);
- if (!e1->cmda[0] ||
- (e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
- /* Use e2 */
- e = e2;
- fullcmd = fullcmd2;
- /* Increment by going to next */
- e2 = e2->next;
- } else {
- /* Use e1 */
- e = e1;
- fullcmd = fullcmd1;
- e1++;
- }
- /* Hide commands that start with '_' */
- if (fullcmd[0] == '_')
- continue;
- if (match) {
- if (strncasecmp(matchstr, fullcmd, strlen(matchstr))) {
- continue;
- }
- }
- ast_cli(fd, "%25.25s %s\n", fullcmd, e->summary);
- }
- return 0;
-}
-
-static int handle_help(int fd, int argc, char *argv[]) {
- struct ast_cli_entry *e;
- char fullcmd[80];
- if ((argc < 1))
- return RESULT_SHOWUSAGE;
- if (argc > 1) {
- e = find_cli(argv + 1, 1);
- if (e) {
- if (e->usage)
- ast_cli(fd, "%s", e->usage);
- else {
- join(fullcmd, sizeof(fullcmd), argv+1, 0);
- ast_cli(fd, "No help text available for '%s'.\n", fullcmd);
- }
- } else {
- if (find_cli(argv + 1, -1)) {
- return help_workhorse(fd, argv + 1);
- } else {
- join(fullcmd, sizeof(fullcmd), argv+1, 0);
- ast_cli(fd, "No such command '%s'.\n", fullcmd);
- }
- }
- } else {
- return help_workhorse(fd, NULL);
- }
- return RESULT_SUCCESS;
-}
-
-static char *parse_args(char *s, int *argc, char *argv[], int max, int *trailingwhitespace)
-{
- char *dup, *cur;
- int x = 0;
- int quoted = 0;
- int escaped = 0;
- int whitespace = 1;
-
- *trailingwhitespace = 0;
- if (!(dup = strdup(s)))
- return NULL;
-
- cur = dup;
- while (*s) {
- if ((*s == '"') && !escaped) {
- quoted = !quoted;
- if (quoted & whitespace) {
- /* If we're starting a quoted string, coming off white space, start a new argument */
- if (x >= (max - 1)) {
- ast_log(LOG_WARNING, "Too many arguments, truncating\n");
- break;
- }
- argv[x++] = cur;
- whitespace = 0;
- }
- escaped = 0;
- } else if (((*s == ' ') || (*s == '\t')) && !(quoted || escaped)) {
- /* If we are not already in whitespace, and not in a quoted string or
- processing an escape sequence, and just entered whitespace, then
- finalize the previous argument and remember that we are in whitespace
- */
- if (!whitespace) {
- *(cur++) = '\0';
- whitespace = 1;
- }
- } else if ((*s == '\\') && !escaped) {
- escaped = 1;
- } else {
- if (whitespace) {
- /* If we are coming out of whitespace, start a new argument */
- if (x >= (max - 1)) {
- ast_log(LOG_WARNING, "Too many arguments, truncating\n");
- break;
- }
- argv[x++] = cur;
- whitespace = 0;
- }
- *(cur++) = *s;
- escaped = 0;
- }
- s++;
- }
- /* Null terminate */
- *(cur++) = '\0';
- argv[x] = NULL;
- *argc = x;
- *trailingwhitespace = whitespace;
- return dup;
-}
-
-/* This returns the number of unique matches for the generator */
-int ast_cli_generatornummatches(char *text, char *word)
-{
- int matches = 0, i = 0;
- char *buf = NULL, *oldbuf = NULL;
-
- while ( (buf = ast_cli_generator(text, word, i++)) ) {
- if (!oldbuf || strcmp(buf,oldbuf))
- matches++;
- if (oldbuf)
- free(oldbuf);
- oldbuf = buf;
- }
- if (oldbuf)
- free(oldbuf);
- return matches;
-}
-
-char **ast_cli_completion_matches(char *text, char *word)
-{
- char **match_list = NULL, *retstr, *prevstr;
- size_t match_list_len, max_equal, which, i;
- int matches = 0;
-
- match_list_len = 1;
- while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
- if (matches + 1 >= match_list_len) {
- match_list_len <<= 1;
- match_list = realloc(match_list, match_list_len * sizeof(char *));
- }
- match_list[++matches] = retstr;
- }
-
- if (!match_list)
- return (char **) NULL;
-
- which = 2;
- prevstr = match_list[1];
- max_equal = strlen(prevstr);
- for (; which <= matches; which++) {
- for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++)
- continue;
- max_equal = i;
- }
-
- retstr = malloc(max_equal + 1);
- (void) strncpy(retstr, match_list[1], max_equal);
- retstr[max_equal] = '\0';
- match_list[0] = retstr;
-
- if (matches + 1 >= match_list_len)
- match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
- match_list[matches + 1] = (char *) NULL;
-
- return (match_list);
-}
-
-static char *__ast_cli_generator(char *text, char *word, int state, int lock)
-{
- char *argv[AST_MAX_ARGS];
- struct ast_cli_entry *e, *e1, *e2;
- int x;
- int matchnum=0;
- char *dup, *res;
- char fullcmd1[80] = "";
- char fullcmd2[80] = "";
- char matchstr[80] = "";
- char *fullcmd = NULL;
- int tws;
-
- if ((dup = parse_args(text, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws))) {
- join(matchstr, sizeof(matchstr), argv, tws);
- if (lock)
- ast_mutex_lock(&clilock);
- e1 = builtins;
- e2 = helpers;
- while(e1->cmda[0] || e2) {
- if (e2)
- join(fullcmd2, sizeof(fullcmd2), e2->cmda, tws);
- if (e1->cmda[0])
- join(fullcmd1, sizeof(fullcmd1), e1->cmda, tws);
- if (!e1->cmda[0] ||
- (e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
- /* Use e2 */
- e = e2;
- fullcmd = fullcmd2;
- /* Increment by going to next */
- e2 = e2->next;
- } else {
- /* Use e1 */
- e = e1;
- fullcmd = fullcmd1;
- e1++;
- }
- if ((fullcmd[0] != '_') && !strncasecmp(matchstr, fullcmd, strlen(matchstr))) {
- /* We contain the first part of one or more commands */
- /* Now, what we're supposed to return is the next word... */
- if (!ast_strlen_zero(word) && x>0) {
- res = e->cmda[x-1];
- } else {
- res = e->cmda[x];
- }
- if (res) {
- matchnum++;
- if (matchnum > state) {
- if (lock)
- ast_mutex_unlock(&clilock);
- free(dup);
- return strdup(res);
- }
- }
- }
- if (e->generator && !strncasecmp(matchstr, fullcmd, strlen(fullcmd)) &&
- (matchstr[strlen(fullcmd)] < 33)) {
- /* We have a command in its entirity within us -- theoretically only one
- command can have this occur */
- fullcmd = e->generator(matchstr, word, (!ast_strlen_zero(word) ? (x - 1) : (x)), state);
- if (fullcmd) {
- if (lock)
- ast_mutex_unlock(&clilock);
- free(dup);
- return fullcmd;
- }
- }
-
- }
- if (lock)
- ast_mutex_unlock(&clilock);
- free(dup);
- }
- return NULL;
-}
-
-char *ast_cli_generator(char *text, char *word, int state)
-{
- return __ast_cli_generator(text, word, state, 1);
-}
-
-int ast_cli_command(int fd, char *s)
-{
- char *argv[AST_MAX_ARGS];
- struct ast_cli_entry *e;
- int x;
- char *dup;
- int tws;
-
- if ((dup = parse_args(s, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws))) {
- /* We need at least one entry, or ignore */
- if (x > 0) {
- ast_mutex_lock(&clilock);
- e = find_cli(argv, 0);
- if (e)
- e->inuse++;
- ast_mutex_unlock(&clilock);
- if (e) {
- switch(e->handler(fd, x, argv)) {
- case RESULT_SHOWUSAGE:
- if (e->usage)
- ast_cli(fd, "%s", e->usage);
- else
- ast_cli(fd, "%s", "Invalid usage, but no usage information available.\n");
- break;
- }
- } else
- ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv));
- if (e) {
- ast_mutex_lock(&clilock);
- e->inuse--;
- ast_mutex_unlock(&clilock);
- }
- }
- free(dup);
- } else {
- ast_log(LOG_WARNING, "Out of memory\n");
- return -1;
- }
- return 0;
-}
diff --git a/1.2-netsec/codecs/Makefile b/1.2-netsec/codecs/Makefile
deleted file mode 100644
index d1feb8a54..000000000
--- a/1.2-netsec/codecs/Makefile
+++ /dev/null
@@ -1,134 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Makefile for codec modules
-#
-# Copyright (C) 1999-2005, Digium
-#
-# Mark Spencer <markster@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-ifeq (${OSARCH},CYGWIN)
-CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
-CYGSOLIB=-L.. -L. -lasterisk.dll
-else
-CFLAGS+=-fPIC
-endif
-
-ifneq ($(wildcard g723.1/coder.c),)
- MODG723=codec_g723_1.so
- LIBG723=g723.1/libg723.a
-endif
-
-ifneq ($(wildcard g723.1b/coder2.c),)
- MODG723+=codec_g723_1b.so
- LIBG723B=g723.1b/libg723b.a
-endif
-
-UI_SPEEX=$(wildcard $(CROSS_COMPILE_TARGET)/usr/include/speex.h)
-UIS_SPEEX=$(wildcard $(CROSS_COMPILE_TARGET)/usr/include/speex/speex.h)
-ULI_SPEEX=$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/speex.h)
-ULIS_SPEEX=$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/speex/speex.h)
-ifneq (${UI_SPEEX},)
- MODSPEEX=codec_speex.so
- LIBSPEEX+=-lspeex -lm
-endif
-ifneq (${UIS_SPEEX},)
- MODSPEEX=codec_speex.so
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/speex
- LIBSPEEX+=-lspeex -lm
-endif
-ifneq (${ULI_SPEEX},)
- MODSPEEX=codec_speex.so
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include
- LIBSPEEX=-L$(CROSS_COMPILE_TARGET)/usr/local/lib
- LIBSPEEX+=-lspeex -lm
-endif
-ifneq (${ULIS_SPEEX},)
- MODSPEEX=codec_speex.so
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include/speex
- LIBSPEEX=-L$(CROSS_COMPILE_TARGET)/usr/local/lib
- LIBSPEEX+=-lspeex -lm
-endif
-
-ifneq ($(wildcard ilbc/iLBC_decode.h),)
- MODILBC=codec_ilbc.so
- LIBILBC=ilbc/libilbc.a
-endif
-
-
-LIBGSM=gsm/lib/libgsm.a
-LIBGSMT=gsm/lib/libgsm.a
-LIBLPC10=lpc10/liblpc10.a
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-CODECS+=$(MODG723) $(MODSPEEX) $(MODILBC) codec_gsm.so codec_lpc10.so \
- codec_adpcm.so codec_ulaw.so codec_alaw.so codec_a_mu.so \
- codec_g726.so
-
-all: depend $(CODECS)
-
-clean:
- rm -f *.so *.o .depend
- [ ! -d g723.1 ] || $(MAKE) -C g723.1 clean
- [ ! -d g723.1b ] || $(MAKE) -C g723.1b clean
- $(MAKE) -C gsm clean
- $(MAKE) -C lpc10 clean
- $(MAKE) -C ilbc clean
-
-$(LIBG723):
- $(MAKE) -C g723.1 all
-
-$(LIBGSM):
- $(MAKE) -C gsm lib/libgsm.a
-
-$(LIBG723B):
- $(MAKE) -C g723.1b all
-
-$(LIBLPC10):
- $(MAKE) -C lpc10 all
-
-$(LIBILBC):
- $(MAKE) -C ilbc all
-
-$(MODILBC): codec_ilbc.o $(LIBILBC)
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBILBC)
-
-codec_g723_1.so : codec_g723_1.o $(LIBG723)
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBG723)
-
-codec_g723_1b.o : codec_g723_1.c
- $(CC) -c -o $@ $(CFLAGS) -DANNEX_B -Dsingle $<
-
-codec_g723_1b.so : codec_g723_1b.o $(LIBG723B)
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBG723B) -lm
-
-codec_gsm.so: codec_gsm.o $(LIBGSMT)
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBGSM)
-
-$(MODSPEEX): codec_speex.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBSPEEX)
-
-codec_lpc10.so: codec_lpc10.o $(LIBLPC10)
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBLPC10) -lm
-
-%.so : %.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-install: all
- for x in $(CODECS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
diff --git a/1.2-netsec/codecs/adpcm_slin_ex.h b/1.2-netsec/codecs/adpcm_slin_ex.h
deleted file mode 100644
index c3f86c72d..000000000
--- a/1.2-netsec/codecs/adpcm_slin_ex.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*! \file
- * adpcm_slin_ex.h --
- *
- * \brief 4-bit ADPCM data, 20 milliseconds worth at 8 kHz.
- *
- * Source: g723.example
- *
- * Copyright (C) 2001-2005, Digium, Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char adpcm_slin_ex[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
diff --git a/1.2-netsec/codecs/codec_a_mu.c b/1.2-netsec/codecs/codec_a_mu.c
deleted file mode 100644
index a3c8cc264..000000000
--- a/1.2-netsec/codecs/codec_a_mu.c
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief codec_a_mu.c - translate between alaw and ulaw directly
- *
- * \ingroup codecs
- */
-
-#include <fcntl.h>
-#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/channel.h"
-#include "asterisk/alaw.h"
-#include "asterisk/ulaw.h"
-
-#define BUFFER_SIZE 8096 /* size for the translation buffers */
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt = 0;
-
-static char *tdesc = "A-law and Mulaw direct Coder/Decoder";
-
-static unsigned char mu2a[256];
-static unsigned char a2mu[256];
-
-/* Sample frame data (Mu data is okay) */
-
-#include "ulaw_slin_ex.h"
-
-/*
- * Private workspace for translating signed linear signals to alaw.
- */
-
-struct alaw_encoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
- unsigned char outbuf[BUFFER_SIZE]; /* Encoded alaw, two nibbles to a word */
- int tail;
-};
-
-/*
- * Private workspace for translating laws.
- */
-
-struct ulaw_encoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
- unsigned char outbuf[BUFFER_SIZE]; /* Encoded ulaw values */
- int tail;
-};
-
-static struct ast_translator_pvt *
-alawtoulaw_new (void)
-{
- struct ulaw_encoder_pvt *tmp;
- tmp = malloc (sizeof (struct ulaw_encoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- tmp->tail = 0;
- localusecnt++;
- ast_update_use_count ();
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-static struct ast_translator_pvt *
-ulawtoalaw_new (void)
-{
- struct alaw_encoder_pvt *tmp;
- tmp = malloc (sizeof (struct alaw_encoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- localusecnt++;
- ast_update_use_count ();
- tmp->tail = 0;
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-static int
-alawtoulaw_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct ulaw_encoder_pvt *tmp = (struct ulaw_encoder_pvt *) pvt;
- int x;
- unsigned char *b;
-
- if ((tmp->tail + f->datalen)> sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
-
- /* Reset ssindex and signal to frame's specified values */
- b = f->data;
- for (x=0;x<f->datalen;x++)
- tmp->outbuf[tmp->tail + x] = a2mu[b[x]];
-
- tmp->tail += f->datalen;
- return 0;
-}
-
-static struct ast_frame *
-alawtoulaw_frameout (struct ast_translator_pvt *pvt)
-{
- struct ulaw_encoder_pvt *tmp = (struct ulaw_encoder_pvt *) pvt;
-
- if (!tmp->tail)
- return NULL;
-
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_ULAW;
- tmp->f.datalen = tmp->tail;
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->tail = 0;
- return &tmp->f;
-}
-
-static int
-ulawtoalaw_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct alaw_encoder_pvt *tmp = (struct alaw_encoder_pvt *) pvt;
- int x;
- unsigned char *s;
- if (tmp->tail + f->datalen >= sizeof(tmp->outbuf))
- {
- ast_log (LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- s = f->data;
- for (x=0;x<f->datalen;x++)
- tmp->outbuf[x+tmp->tail] = mu2a[s[x]];
- tmp->tail += f->datalen;
- return 0;
-}
-
-/*
- * LinToalaw_FrameOut
- * Convert a buffer of raw 16-bit signed linear PCM to a buffer
- * of 4-bit alaw packed two to a byte (Big Endian).
- *
- * Results:
- * Foo
- *
- * Side effects:
- * Leftover inbuf data gets packed, tail gets updated.
- */
-
-static struct ast_frame *
-ulawtoalaw_frameout (struct ast_translator_pvt *pvt)
-{
- struct alaw_encoder_pvt *tmp = (struct alaw_encoder_pvt *) pvt;
-
- if (tmp->tail) {
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_ALAW;
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->f.datalen = tmp->tail;
- tmp->tail = 0;
- return &tmp->f;
- } else return NULL;
-}
-
-
-/*
- * alawToLin_Sample
- */
-
-static struct ast_frame *
-alawtoulaw_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_ALAW;
- f.datalen = sizeof (ulaw_slin_ex);
- f.samples = sizeof(ulaw_slin_ex);
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = ulaw_slin_ex;
- return &f;
-}
-
-static struct ast_frame *
-ulawtoalaw_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_ULAW;
- f.datalen = sizeof (ulaw_slin_ex);
- f.samples = sizeof(ulaw_slin_ex);
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = ulaw_slin_ex;
- return &f;
-}
-
-
-/*
- * alaw_Destroy
- * Destroys a private workspace.
- *
- * Results:
- * It's gone!
- *
- * Side effects:
- * None.
- */
-
-static void
-alaw_destroy (struct ast_translator_pvt *pvt)
-{
- free (pvt);
- localusecnt--;
- ast_update_use_count ();
-}
-
-/*
- * The complete translator for alawToLin.
- */
-
-static struct ast_translator alawtoulaw = {
- "alawtoulaw",
- AST_FORMAT_ALAW,
- AST_FORMAT_ULAW,
- alawtoulaw_new,
- alawtoulaw_framein,
- alawtoulaw_frameout,
- alaw_destroy,
- /* NULL */
- alawtoulaw_sample
-};
-
-/*
- * The complete translator for LinToalaw.
- */
-
-static struct ast_translator ulawtoalaw = {
- "ulawtoalaw",
- AST_FORMAT_ULAW,
- AST_FORMAT_ALAW,
- ulawtoalaw_new,
- ulawtoalaw_framein,
- ulawtoalaw_frameout,
- alaw_destroy,
- /* NULL */
- ulawtoalaw_sample
-};
-
-int
-unload_module (void)
-{
- int res;
- ast_mutex_lock (&localuser_lock);
- res = ast_unregister_translator (&ulawtoalaw);
- if (!res)
- res = ast_unregister_translator (&alawtoulaw);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock (&localuser_lock);
- return res;
-}
-
-int
-load_module (void)
-{
- int res;
- int x;
- for (x=0;x<256;x++) {
- mu2a[x] = AST_LIN2A(AST_MULAW(x));
- a2mu[x] = AST_LIN2MU(AST_ALAW(x));
- }
- res = ast_register_translator (&alawtoulaw);
- if (!res)
- res = ast_register_translator (&ulawtoalaw);
- else
- ast_unregister_translator (&alawtoulaw);
- return res;
-}
-
-/*
- * Return a description of this module.
- */
-
-char *
-description (void)
-{
- return tdesc;
-}
-
-int
-usecount (void)
-{
- int res;
- STANDARD_USECOUNT (res);
- return res;
-}
-
-char *
-key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/codec_adpcm.c b/1.2-netsec/codecs/codec_adpcm.c
deleted file mode 100644
index 187c42442..000000000
--- a/1.2-netsec/codecs/codec_adpcm.c
+++ /dev/null
@@ -1,655 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Based on frompcm.c and topcm.c from the Emiliano MIPL browser/
- * interpreter. See http://www.bsdtelephony.com.mx
- *
- * Copyright (c) 2001 - 2005 Digium, Inc.
- * All rights reserved.
- *
- * Karl Sackett <krs@linux-support.net>, 2001-03-21
- *
- * 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 codec_adpcm.c - translate between signed linear and Dialogic ADPCM
- *
- * \ingroup codecs
- */
-
-#include <fcntl.h>
-#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/translate.h"
-#include "asterisk/channel.h"
-
-/* define NOT_BLI to use a faster but not bit-level identical version */
-/* #define NOT_BLI */
-
-#define BUFFER_SIZE 8096 /* size for the translation buffers */
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt = 0;
-
-static char *tdesc = "Adaptive Differential PCM Coder/Decoder";
-
-static int useplc = 0;
-
-/* Sample frame data */
-
-#include "slin_adpcm_ex.h"
-#include "adpcm_slin_ex.h"
-
-/*
- * Step size index shift table
- */
-
-static int indsft[8] = { -1, -1, -1, -1, 2, 4, 6, 8 };
-
-/*
- * Step size table, where stpsz[i]=floor[16*(11/10)^i]
- */
-
-static int stpsz[49] = {
- 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73,
- 80, 88, 97, 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279,
- 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876, 963,
- 1060, 1166, 1282, 1411, 1552
-};
-
-/*
- * Decoder/Encoder state
- * States for both encoder and decoder are synchronized
- */
-struct adpcm_state {
- int ssindex;
- int signal;
- int zero_count;
- int next_flag;
-};
-
-/*
- * Decode(encoded)
- * Decodes the encoded nibble from the adpcm file.
- *
- * Results:
- * Returns the encoded difference.
- *
- * Side effects:
- * Sets the index to the step size table for the next encode.
- */
-
-static inline short
-decode(int encoded, struct adpcm_state* state)
-{
- int diff;
- int step;
- int sign;
-
- step = stpsz[state->ssindex];
-
- sign = encoded & 0x08;
- encoded &= 0x07;
-#ifdef NOT_BLI
- diff = (((encoded << 1) + 1) * step) >> 3;
-#else /* BLI code */
- diff = step >> 3;
- if (encoded & 4) diff += step;
- if (encoded & 2) diff += step >> 1;
- if (encoded & 1) diff += step >> 2;
- if ((encoded >> 1) & step & 0x1)
- diff++;
-#endif
- if (sign)
- diff = -diff;
-
- if (state->next_flag & 0x1)
- state->signal -= 8;
- else if (state->next_flag & 0x2)
- state->signal += 8;
-
- state->signal += diff;
-
- if (state->signal > 2047)
- state->signal = 2047;
- else if (state->signal < -2047)
- state->signal = -2047;
-
- state->next_flag = 0;
-
-#ifdef AUTO_RETURN
- if (encoded)
- state->zero_count = 0;
- else if (++(state->zero_count) == 24)
- {
- state->zero_count = 0;
- if (state->signal > 0)
- state->next_flag = 0x1;
- else if (state->signal < 0)
- state->next_flag = 0x2;
- }
-#endif
-
- state->ssindex += indsft[encoded];
- if (state->ssindex < 0)
- state->ssindex = 0;
- else if (state->ssindex > 48)
- state->ssindex = 48;
-
- return state->signal << 4;
-}
-
-/*
- * Adpcm
- * Takes a signed linear signal and encodes it as ADPCM
- * For more information see http://support.dialogic.com/appnotes/adpcm.pdf
- *
- * Results:
- * Foo.
- *
- * Side effects:
- * signal gets updated with each pass.
- */
-
-static inline int
-adpcm(short csig, struct adpcm_state* state)
-{
- int diff;
- int step;
- int encoded;
-
- /*
- * Clip csig if too large or too small
- */
- csig >>= 4;
-
- step = stpsz[state->ssindex];
- diff = csig - state->signal;
-
-#ifdef NOT_BLI
- if (diff < 0)
- {
- encoded = (-diff << 2) / step;
- if (encoded > 7)
- encoded = 7;
- encoded |= 0x08;
- }
- else
- {
- encoded = (diff << 2) / step;
- if (encoded > 7)
- encoded = 7;
- }
-#else /* BLI code */
- if (diff < 0)
- {
- encoded = 8;
- diff = -diff;
- }
- else
- encoded = 0;
- if (diff >= step)
- {
- encoded |= 4;
- diff -= step;
- }
- step >>= 1;
- if (diff >= step)
- {
- encoded |= 2;
- diff -= step;
- }
- step >>= 1;
- if (diff >= step)
- encoded |= 1;
-#endif /* NOT_BLI */
-
- /* feedback to state */
- decode(encoded, state);
-
- return encoded;
-}
-
-/*
- * Private workspace for translating signed linear signals to ADPCM.
- */
-
-struct adpcm_encoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
- short inbuf[BUFFER_SIZE]; /* Unencoded signed linear values */
- unsigned char outbuf[BUFFER_SIZE]; /* Encoded ADPCM, two nibbles to a word */
- struct adpcm_state state;
- int tail;
-};
-
-/*
- * Private workspace for translating ADPCM signals to signed linear.
- */
-
-struct adpcm_decoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
- short outbuf[BUFFER_SIZE]; /* Decoded signed linear values */
- struct adpcm_state state;
- int tail;
- plc_state_t plc;
-};
-
-/*
- * AdpcmToLin_New
- * Create a new instance of adpcm_decoder_pvt.
- *
- * Results:
- * Returns a pointer to the new instance.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_translator_pvt *
-adpcmtolin_new (void)
-{
- struct adpcm_decoder_pvt *tmp;
- tmp = malloc (sizeof (struct adpcm_decoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- tmp->tail = 0;
- plc_init(&tmp->plc);
- localusecnt++;
- ast_update_use_count ();
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-/*
- * LinToAdpcm_New
- * Create a new instance of adpcm_encoder_pvt.
- *
- * Results:
- * Returns a pointer to the new instance.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_translator_pvt *
-lintoadpcm_new (void)
-{
- struct adpcm_encoder_pvt *tmp;
- tmp = malloc (sizeof (struct adpcm_encoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- localusecnt++;
- ast_update_use_count ();
- tmp->tail = 0;
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-/*
- * AdpcmToLin_FrameIn
- * Take an input buffer with packed 4-bit ADPCM values and put decoded PCM in outbuf,
- * if there is room left.
- *
- * Results:
- * Foo
- *
- * Side effects:
- * tmp->tail is the number of packed values in the buffer.
- */
-
-static int
-adpcmtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *) pvt;
- int x;
- unsigned char *b;
-
- if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
- if((tmp->tail + 160) > sizeof(tmp->outbuf) / 2) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- if(useplc) {
- plc_fillin(&tmp->plc, tmp->outbuf+tmp->tail, 160);
- tmp->tail += 160;
- }
- return 0;
- }
-
- if (f->datalen * 4 + tmp->tail * 2 > sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
-
- b = f->data;
-
- for (x=0;x<f->datalen;x++) {
- tmp->outbuf[tmp->tail++] = decode((b[x] >> 4) & 0xf, &tmp->state);
- tmp->outbuf[tmp->tail++] = decode(b[x] & 0x0f, &tmp->state);
- }
-
- if(useplc) plc_rx(&tmp->plc, tmp->outbuf+tmp->tail-f->datalen*2, f->datalen*2);
-
- return 0;
-}
-
-/*
- * AdpcmToLin_FrameOut
- * Convert 4-bit ADPCM encoded signals to 16-bit signed linear.
- *
- * Results:
- * Converted signals are placed in tmp->f.data, tmp->f.datalen
- * and tmp->f.samples are calculated.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_frame *
-adpcmtolin_frameout (struct ast_translator_pvt *pvt)
-{
- struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *) pvt;
-
- if (!tmp->tail)
- return NULL;
-
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SLINEAR;
- tmp->f.datalen = tmp->tail *2;
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->tail = 0;
- return &tmp->f;
-}
-
-/*
- * LinToAdpcm_FrameIn
- * Fill an input buffer with 16-bit signed linear PCM values.
- *
- * Results:
- * None.
- *
- * Side effects:
- * tmp->tail is number of signal values in the input buffer.
- */
-
-static int
-lintoadpcm_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *) pvt;
-
- if ((tmp->tail + f->datalen / 2) < (sizeof (tmp->inbuf) / 2))
- {
- memcpy (&tmp->inbuf[tmp->tail], f->data, f->datalen);
- tmp->tail += f->datalen / 2;
- }
- else
- {
- ast_log (LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- return 0;
-}
-
-/*
- * LinToAdpcm_FrameOut
- * Convert a buffer of raw 16-bit signed linear PCM to a buffer
- * of 4-bit ADPCM packed two to a byte (Big Endian).
- *
- * Results:
- * Foo
- *
- * Side effects:
- * Leftover inbuf data gets packed, tail gets updated.
- */
-
-static struct ast_frame *
-lintoadpcm_frameout (struct ast_translator_pvt *pvt)
-{
- struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *) pvt;
- int i_max, i;
-
- if (tmp->tail < 2) return NULL;
-
-
- i_max = tmp->tail & ~1; /* atomic size is 2 samples */
-
- /* What is this, state debugging? should be #ifdef'd then
- tmp->outbuf[0] = tmp->ssindex & 0xff;
- tmp->outbuf[1] = (tmp->signal >> 8) & 0xff;
- tmp->outbuf[2] = (tmp->signal & 0xff);
- tmp->outbuf[3] = tmp->zero_count;
- tmp->outbuf[4] = tmp->next_flag;
- */
- for (i = 0; i < i_max; i+=2)
- {
- tmp->outbuf[i/2] =
- (adpcm(tmp->inbuf[i ], &tmp->state) << 4) |
- (adpcm(tmp->inbuf[i+1], &tmp->state) );
- };
-
-
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_ADPCM;
- tmp->f.samples = i_max;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->f.datalen = i_max / 2;
-
- /*
- * If there is a signal left over (there should be no more than
- * one) move it to the beginning of the input buffer.
- */
-
- if (tmp->tail == i_max)
- tmp->tail = 0;
- else
- {
- tmp->inbuf[0] = tmp->inbuf[tmp->tail];
- tmp->tail = 1;
- }
- return &tmp->f;
-}
-
-
-/*
- * AdpcmToLin_Sample
- */
-
-static struct ast_frame *
-adpcmtolin_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_ADPCM;
- f.datalen = sizeof (adpcm_slin_ex);
- f.samples = sizeof(adpcm_slin_ex) * 2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = adpcm_slin_ex;
- return &f;
-}
-
-/*
- * LinToAdpcm_Sample
- */
-
-static struct ast_frame *
-lintoadpcm_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = sizeof (slin_adpcm_ex);
- /* Assume 8000 Hz */
- f.samples = sizeof (slin_adpcm_ex) / 2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = slin_adpcm_ex;
- return &f;
-}
-
-/*
- * Adpcm_Destroy
- * Destroys a private workspace.
- *
- * Results:
- * It's gone!
- *
- * Side effects:
- * None.
- */
-
-static void
-adpcm_destroy (struct ast_translator_pvt *pvt)
-{
- free (pvt);
- localusecnt--;
- ast_update_use_count ();
-}
-
-/*
- * The complete translator for ADPCMToLin.
- */
-
-static struct ast_translator adpcmtolin = {
- "adpcmtolin",
- AST_FORMAT_ADPCM,
- AST_FORMAT_SLINEAR,
- adpcmtolin_new,
- adpcmtolin_framein,
- adpcmtolin_frameout,
- adpcm_destroy,
- /* NULL */
- adpcmtolin_sample
-};
-
-/*
- * The complete translator for LinToADPCM.
- */
-
-static struct ast_translator lintoadpcm = {
- "lintoadpcm",
- AST_FORMAT_SLINEAR,
- AST_FORMAT_ADPCM,
- lintoadpcm_new,
- lintoadpcm_framein,
- lintoadpcm_frameout,
- adpcm_destroy,
- /* NULL */
- lintoadpcm_sample
-};
-
-static void
-parse_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
- if ((cfg = ast_config_load("codecs.conf"))) {
- if ((var = ast_variable_browse(cfg, "plc"))) {
- while (var) {
- if (!strcasecmp(var->name, "genericplc")) {
- useplc = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "codec_adpcm: %susing generic PLC\n", useplc ? "" : "not ");
- }
- var = var->next;
- }
- }
- ast_config_destroy(cfg);
- }
-}
-
-int
-reload(void)
-{
- parse_config();
- return 0;
-}
-
-int
-unload_module (void)
-{
- int res;
- ast_mutex_lock (&localuser_lock);
- res = ast_unregister_translator (&lintoadpcm);
- if (!res)
- res = ast_unregister_translator (&adpcmtolin);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock (&localuser_lock);
- return res;
-}
-
-int
-load_module (void)
-{
- int res;
- parse_config();
- res = ast_register_translator (&adpcmtolin);
- if (!res)
- res = ast_register_translator (&lintoadpcm);
- else
- ast_unregister_translator (&adpcmtolin);
- return res;
-}
-
-/*
- * Return a description of this module.
- */
-
-char *
-description (void)
-{
- return tdesc;
-}
-
-int
-usecount (void)
-{
- int res;
- STANDARD_USECOUNT (res);
- return res;
-}
-
-char *
-key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/codec_alaw.c b/1.2-netsec/codecs/codec_alaw.c
deleted file mode 100644
index 86e3a6592..000000000
--- a/1.2-netsec/codecs/codec_alaw.c
+++ /dev/null
@@ -1,428 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief codec_alaw.c - translate between signed linear and alaw
- *
- * \ingroup codecs
- */
-
-#include <fcntl.h>
-#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/translate.h"
-#include "asterisk/channel.h"
-#include "asterisk/alaw.h"
-
-#define BUFFER_SIZE 8096 /* size for the translation buffers */
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt = 0;
-
-static char *tdesc = "A-law Coder/Decoder";
-
-static int useplc = 0;
-
-/* Sample frame data (Mu data is okay) */
-
-#include "slin_ulaw_ex.h"
-#include "ulaw_slin_ex.h"
-
-/*!
- * \brief Private workspace for translating signed linear signals to alaw.
- */
-struct alaw_encoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /*!< Space to build offset */
- unsigned char outbuf[BUFFER_SIZE]; /*!< Encoded alaw, two nibbles to a word */
- int tail;
-};
-
-/*!
- * \brief Private workspace for translating alaw signals to signed linear.
- */
-struct alaw_decoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
- short outbuf[BUFFER_SIZE]; /* Decoded signed linear values */
- int tail;
- plc_state_t plc;
-};
-
-/*!
- * \brief alawToLin_New
- * Create a new instance of alaw_decoder_pvt.
- *
- * Results:
- * Returns a pointer to the new instance.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_translator_pvt * alawtolin_new (void)
-{
- struct alaw_decoder_pvt *tmp;
- tmp = malloc (sizeof (struct alaw_decoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- tmp->tail = 0;
- plc_init(&tmp->plc);
- localusecnt++;
- ast_update_use_count ();
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-/*!
- * \brief LinToalaw_New
- * Create a new instance of alaw_encoder_pvt.
- *
- * Results:
- * Returns a pointer to the new instance.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_translator_pvt * lintoalaw_new (void)
-{
- struct alaw_encoder_pvt *tmp;
- tmp = malloc (sizeof (struct alaw_encoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- localusecnt++;
- ast_update_use_count ();
- tmp->tail = 0;
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-/*!
- * \brief alawToLin_FrameIn
- * Fill an input buffer with packed 4-bit alaw values if there is room
- * left.
- *
- * Results:
- * Foo
- *
- * Side effects:
- * tmp->tail is the number of packed values in the buffer.
- */
-
-static int
-alawtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct alaw_decoder_pvt *tmp = (struct alaw_decoder_pvt *) pvt;
- int x;
- unsigned char *b;
-
- if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
- if((tmp->tail + 160) * 2 > sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- if(useplc) {
- plc_fillin(&tmp->plc, tmp->outbuf+tmp->tail, 160);
- tmp->tail += 160;
- }
- return 0;
- }
-
- if ((tmp->tail + f->datalen) * 2 > sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
-
- /* Reset ssindex and signal to frame's specified values */
- b = f->data;
- for (x=0;x<f->datalen;x++)
- tmp->outbuf[tmp->tail + x] = AST_ALAW(b[x]);
-
- if(useplc) plc_rx(&tmp->plc, tmp->outbuf+tmp->tail, f->datalen);
-
- tmp->tail += f->datalen;
- return 0;
-}
-
-/*!
- * \brief alawToLin_FrameOut
- * Convert 4-bit alaw encoded signals to 16-bit signed linear.
- *
- * Results:
- * Converted signals are placed in tmp->f.data, tmp->f.datalen
- * and tmp->f.samples are calculated.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_frame * alawtolin_frameout (struct ast_translator_pvt *pvt)
-{
- struct alaw_decoder_pvt *tmp = (struct alaw_decoder_pvt *) pvt;
-
- if (!tmp->tail)
- return NULL;
-
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SLINEAR;
- tmp->f.datalen = tmp->tail *2;
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->tail = 0;
- return &tmp->f;
-}
-
-/*!
- * \brief LinToalaw_FrameIn
- * Fill an input buffer with 16-bit signed linear PCM values.
- *
- * Results:
- * None.
- *
- * Side effects:
- * tmp->tail is number of signal values in the input buffer.
- */
-
-static int lintoalaw_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct alaw_encoder_pvt *tmp = (struct alaw_encoder_pvt *) pvt;
- int x;
- short *s;
- if (tmp->tail + f->datalen/2 >= sizeof(tmp->outbuf))
- {
- ast_log (LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- s = f->data;
- for (x=0;x<f->datalen/2;x++)
- tmp->outbuf[x+tmp->tail] = AST_LIN2A(s[x]);
- tmp->tail += f->datalen/2;
- return 0;
-}
-
-/*!
- * \brief LinToalaw_FrameOut
- * Convert a buffer of raw 16-bit signed linear PCM to a buffer
- * of 4-bit alaw packed two to a byte (Big Endian).
- *
- * Results:
- * Foo
- *
- * Side effects:
- * Leftover inbuf data gets packed, tail gets updated.
- */
-
-static struct ast_frame * lintoalaw_frameout (struct ast_translator_pvt *pvt)
-{
- struct alaw_encoder_pvt *tmp = (struct alaw_encoder_pvt *) pvt;
-
- if (tmp->tail) {
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_ALAW;
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->f.datalen = tmp->tail;
- tmp->tail = 0;
- return &tmp->f;
- } else return NULL;
-}
-
-
-/*!
- * \brief alawToLin_Sample
- */
-
-static struct ast_frame * alawtolin_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_ALAW;
- f.datalen = sizeof (ulaw_slin_ex);
- f.samples = sizeof(ulaw_slin_ex);
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = ulaw_slin_ex;
- return &f;
-}
-
-/*!
- * \brief LinToalaw_Sample
- */
-
-static struct ast_frame * lintoalaw_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = sizeof (slin_ulaw_ex);
- /* Assume 8000 Hz */
- f.samples = sizeof (slin_ulaw_ex) / 2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = slin_ulaw_ex;
- return &f;
-}
-
-/*!
- * \brief alaw_Destroy
- * Destroys a private workspace.
- *
- * Results:
- * It's gone!
- *
- * Side effects:
- * None.
- */
-
-static void alaw_destroy (struct ast_translator_pvt *pvt)
-{
- free (pvt);
- localusecnt--;
- ast_update_use_count ();
-}
-
-/*!
- * \brief The complete translator for alawToLin.
- */
-
-static struct ast_translator alawtolin = {
- "alawtolin",
- AST_FORMAT_ALAW,
- AST_FORMAT_SLINEAR,
- alawtolin_new,
- alawtolin_framein,
- alawtolin_frameout,
- alaw_destroy,
- /* NULL */
- alawtolin_sample
-};
-
-/*!
- * \brief The complete translator for LinToalaw.
- */
-
-static struct ast_translator lintoalaw = {
- "lintoalaw",
- AST_FORMAT_SLINEAR,
- AST_FORMAT_ALAW,
- lintoalaw_new,
- lintoalaw_framein,
- lintoalaw_frameout,
- alaw_destroy,
- /* NULL */
- lintoalaw_sample
-};
-
-static void parse_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
-
- if ((cfg = ast_config_load("codecs.conf"))) {
- if ((var = ast_variable_browse(cfg, "plc"))) {
- while (var) {
- if (!strcasecmp(var->name, "genericplc")) {
- useplc = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "codec_alaw: %susing generic PLC\n", useplc ? "" : "not ");
- }
- var = var->next;
- }
- }
- ast_config_destroy(cfg);
- }
-}
-
-int reload(void)
-{
- parse_config();
- return 0;
-}
-
-int unload_module (void)
-{
- int res;
- ast_mutex_lock (&localuser_lock);
- res = ast_unregister_translator (&lintoalaw);
- if (!res)
- res = ast_unregister_translator (&alawtolin);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock (&localuser_lock);
- return res;
-}
-
-int load_module (void)
-{
- int res;
- parse_config();
- res = ast_register_translator (&alawtolin);
- if (!res)
- res = ast_register_translator (&lintoalaw);
- else
- ast_unregister_translator (&alawtolin);
- return res;
-}
-
-/*
- * Return a description of this module.
- */
-
-char * description (void)
-{
- return tdesc;
-}
-
-int usecount (void)
-{
- int res;
- STANDARD_USECOUNT (res);
- return res;
-}
-
-char * key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/codec_g723_1.c b/1.2-netsec/codecs/codec_g723_1.c
deleted file mode 100644
index 67d9b51b0..000000000
--- a/1.2-netsec/codecs/codec_g723_1.c
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * The G.723.1 code is not included in the Asterisk distribution because
- * it is covered with patents, and in spite of statements to the contrary,
- * the "technology" is extremely expensive to license.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Translate between signed linear and G.723.1
- *
- * \ingroup codecs
- */
-
-#define TYPE_HIGH 0x0
-#define TYPE_LOW 0x1
-#define TYPE_SILENCE 0x2
-#define TYPE_DONTSEND 0x3
-#define TYPE_MASK 0x3
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/translate.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-
-#ifdef ANNEX_B
-#include "g723.1b/typedef2.h"
-#include "g723.1b/cst2.h"
-#include "g723.1b/coder2.h"
-#include "g723.1b/decod2.h"
-#include "g723.1b/deccng2.h"
-#include "g723.1b/codcng2.h"
-#include "g723.1b/vad2.h"
-#else
-#include "g723.1/typedef.h"
-#include "g723.1/cst_lbc.h"
-#include "g723.1/coder.h"
-#include "g723.1/decod.h"
-#include "g723.1/dec_cng.h"
-#include "g723.1/cod_cng.h"
-#include "g723.1/vad.h"
-#endif
-
-/* Sample frame data */
-#include "slin_g723_ex.h"
-#include "g723_slin_ex.h"
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt=0;
-
-#ifdef ANNEX_B
-static char *tdesc = "Annex B (floating point) G.723.1/PCM16 Codec Translator";
-#else
-static char *tdesc = "Annex A (fixed point) G.723.1/PCM16 Codec Translator";
-#endif
-
-/* Globals */
-Flag UsePf = True;
-Flag UseHp = True;
-Flag UseVx = True;
-
-enum Crate WrkRate = Rate63;
-
-struct g723_encoder_pvt {
- struct cod_state cod;
- struct ast_frame f;
- /* Space to build offset */
- char offset[AST_FRIENDLY_OFFSET];
- /* Buffer for our outgoing frame */
- char outbuf[8000];
- /* Enough to store a full second */
- short buf[8000];
- int tail;
-};
-
-struct g723_decoder_pvt {
- struct dec_state dec;
- struct ast_frame f;
- /* Space to build offset */
- char offset[AST_FRIENDLY_OFFSET];
- /* Enough to store a full second */
- short buf[8000];
- int tail;
-};
-
-static struct ast_translator_pvt *g723tolin_new(void)
-{
- struct g723_decoder_pvt *tmp;
- tmp = malloc(sizeof(struct g723_decoder_pvt));
- if (tmp) {
- Init_Decod(&tmp->dec);
- Init_Dec_Cng(&tmp->dec);
- tmp->tail = 0;
- localusecnt++;
- ast_update_use_count();
- }
- return (struct ast_translator_pvt *)tmp;
-}
-
-static struct ast_frame *lintog723_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = sizeof(slin_g723_ex);
- /* Assume 8000 Hz */
- f.samples = sizeof(slin_g723_ex)/2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = slin_g723_ex;
- return &f;
-}
-
-static struct ast_frame *g723tolin_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_G723_1;
- f.datalen = sizeof(g723_slin_ex);
- /* All frames are 30 ms long */
- f.samples = 240;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = g723_slin_ex;
- return &f;
-}
-
-static struct ast_translator_pvt *lintog723_new(void)
-{
- struct g723_encoder_pvt *tmp;
- tmp = malloc(sizeof(struct g723_encoder_pvt));
- if (tmp) {
- Init_Coder(&tmp->cod);
- /* Init Comfort Noise Functions */
- if( UseVx ) {
- Init_Vad(&tmp->cod);
- Init_Cod_Cng(&tmp->cod);
- }
- localusecnt++;
- ast_update_use_count();
- tmp->tail = 0;
- }
- return (struct ast_translator_pvt *)tmp;
-}
-
-static struct ast_frame *g723tolin_frameout(struct ast_translator_pvt *pvt)
-{
- struct g723_decoder_pvt *tmp = (struct g723_decoder_pvt *)pvt;
- if (!tmp->tail)
- return NULL;
- /* Signed linear is no particular frame size, so just send whatever
- we have in the buffer in one lump sum */
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SLINEAR;
- tmp->f.datalen = tmp->tail * 2;
- /* Assume 8000 Hz */
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->buf;
- /* Reset tail pointer */
- tmp->tail = 0;
-
-#if 0
- /* Save the frames */
- {
- static int fd2 = -1;
- if (fd2 == -1) {
- fd2 = open("g723.example", O_WRONLY | O_CREAT | O_TRUNC, 0644);
- }
- write(fd2, tmp->f.data, tmp->f.datalen);
- }
-#endif
- return &tmp->f;
-}
-
-static int g723_len(unsigned char buf)
-{
- switch(buf & TYPE_MASK) {
- case TYPE_DONTSEND:
- return 0;
- break;
- case TYPE_SILENCE:
- return 4;
- break;
- case TYPE_HIGH:
- return 24;
- break;
- case TYPE_LOW:
- return 20;
- break;
- default:
- ast_log(LOG_WARNING, "Badly encoded frame (%d)\n", buf & TYPE_MASK);
- }
- return -1;
-}
-
-static int g723tolin_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct g723_decoder_pvt *tmp = (struct g723_decoder_pvt *)pvt;
- int len = 0;
- int res;
-#ifdef ANNEX_B
- FLOAT tmpdata[Frame];
- int x;
-#endif
- while(len < f->datalen) {
- /* Assuming there's space left, decode into the current buffer at
- the tail location */
- res = g723_len(((unsigned char *)f->data + len)[0]);
- if (res < 0) {
- ast_log(LOG_WARNING, "Invalid data\n");
- return -1;
- }
- if (res + len > f->datalen) {
- ast_log(LOG_WARNING, "Measured length exceeds frame length\n");
- return -1;
- }
- if (tmp->tail + Frame < sizeof(tmp->buf)/2) {
-#ifdef ANNEX_B
- Decod(&tmp->dec, tmpdata, f->data + len, 0);
- for (x=0;x<Frame;x++)
- (tmp->buf + tmp->tail)[x] = (short)(tmpdata[x]);
-#else
- Decod(&tmp->dec, tmp->buf + tmp->tail, f->data + len, 0);
-#endif
- tmp->tail+=Frame;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- len += res;
- }
- return 0;
-}
-
-static int lintog723_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- /* Just add the frames to our stream */
- /* XXX We should look at how old the rest of our stream is, and if it
- is too old, then we should overwrite it entirely, otherwise we can
- get artifacts of earlier talk that do not belong */
- struct g723_encoder_pvt *tmp = (struct g723_encoder_pvt *)pvt;
- if (tmp->tail + f->datalen/2 < sizeof(tmp->buf) / 2) {
- memcpy(&tmp->buf[tmp->tail], f->data, f->datalen);
- tmp->tail += f->datalen/2;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_frame *lintog723_frameout(struct ast_translator_pvt *pvt)
-{
- struct g723_encoder_pvt *tmp = (struct g723_encoder_pvt *)pvt;
-#ifdef ANNEX_B
- int x;
- FLOAT tmpdata[Frame];
-#endif
- int cnt=0;
- /* We can't work on anything less than a frame in size */
- if (tmp->tail < Frame)
- return NULL;
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_G723_1;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.samples = 0;
- tmp->f.mallocd = 0;
- while(tmp->tail >= Frame) {
- /* Encode a frame of data */
- if (cnt + 24 >= sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return NULL;
- }
-#ifdef ANNEX_B
- for (x=0;x<Frame;x++)
- tmpdata[x] = tmp->buf[x];
- Coder(&tmp->cod, tmpdata, tmp->outbuf + cnt);
-#else
- Coder(&tmp->cod, tmp->buf, tmp->outbuf + cnt);
-#endif
- /* Assume 8000 Hz */
- tmp->f.samples += 240;
- cnt += g723_len(tmp->outbuf[cnt]);
- tmp->tail -= Frame;
- /* Move the data at the end of the buffer to the front */
- if (tmp->tail)
- memmove(tmp->buf, tmp->buf + Frame, tmp->tail * 2);
- }
- tmp->f.datalen = cnt;
- tmp->f.data = tmp->outbuf;
-#if 0
- /* Save to a g723 sample output file... */
- {
- static int fd = -1;
- int delay = htonl(30);
- short size;
- if (fd < 0)
- fd = open("trans.g723", O_WRONLY | O_CREAT | O_TRUNC, 0644);
- if (fd < 0)
- ast_log(LOG_WARNING, "Unable to create demo\n");
- write(fd, &delay, 4);
- size = htons(tmp->f.datalen);
- write(fd, &size, 2);
- write(fd, tmp->f.data, tmp->f.datalen);
- }
-#endif
- return &tmp->f;
-}
-
-static void g723_destroy(struct ast_translator_pvt *pvt)
-{
- free(pvt);
- localusecnt--;
- ast_update_use_count();
-}
-
-static struct ast_translator g723tolin =
-#ifdef ANNEX_B
- { "g723tolinb",
-#else
- { "g723tolin",
-#endif
- AST_FORMAT_G723_1, AST_FORMAT_SLINEAR,
- g723tolin_new,
- g723tolin_framein,
- g723tolin_frameout,
- g723_destroy,
- g723tolin_sample
- };
-
-static struct ast_translator lintog723 =
-#ifdef ANNEX_B
- { "lintog723b",
-#else
- { "lintog723",
-#endif
- AST_FORMAT_SLINEAR, AST_FORMAT_G723_1,
- lintog723_new,
- lintog723_framein,
- lintog723_frameout,
- g723_destroy,
- lintog723_sample
- };
-
-int unload_module(void)
-{
- int res;
- ast_mutex_lock(&localuser_lock);
- res = ast_unregister_translator(&lintog723);
- if (!res)
- res = ast_unregister_translator(&g723tolin);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock(&localuser_lock);
- return res;
-}
-
-int load_module(void)
-{
- int res;
- res=ast_register_translator(&g723tolin);
- if (!res)
- res=ast_register_translator(&lintog723);
- else
- ast_unregister_translator(&g723tolin);
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key(void)
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/codec_g726.c b/1.2-netsec/codecs/codec_g726.c
deleted file mode 100644
index 81ec1e1ac..000000000
--- a/1.2-netsec/codecs/codec_g726.c
+++ /dev/null
@@ -1,1092 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Based on frompcm.c and topcm.c from the Emiliano MIPL browser/
- * interpreter. See http://www.bsdtelephony.com.mx
- *
- * 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 codec_g726.c - translate between signed linear and ITU G.726-32kbps
- *
- * \ingroup codecs
- */
-
-#include <fcntl.h>
-#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/translate.h"
-#include "asterisk/channel.h"
-
-#define WANT_ASM
-#include "log2comp.h"
-
-/* define NOT_BLI to use a faster but not bit-level identical version */
-/* #define NOT_BLI */
-
-#if defined(NOT_BLI)
-# if defined(_MSC_VER)
-typedef __int64 sint64;
-# elif defined(__GNUC__)
-typedef long long sint64;
-# else
-# error 64-bit integer type is not defined for your compiler/platform
-# endif
-#endif
-
-#define BUFFER_SIZE 8096 /* size for the translation buffers */
-#define BUF_SHIFT 5
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt = 0;
-
-static char *tdesc = "ITU G.726-32kbps G726 Transcoder";
-
-static int useplc = 0;
-
-/* Sample frame data */
-
-#include "slin_g726_ex.h"
-#include "g726_slin_ex.h"
-
-/*
- * The following is the definition of the state structure
- * used by the G.721/G.723 encoder and decoder to preserve their internal
- * state between successive calls. The meanings of the majority
- * of the state structure fields are explained in detail in the
- * CCITT Recommendation G.721. The field names are essentially indentical
- * to variable names in the bit level description of the coding algorithm
- * included in this Recommendation.
- */
-struct g726_state {
- long yl; /* Locked or steady state step size multiplier. */
- int yu; /* Unlocked or non-steady state step size multiplier. */
- int dms; /* Short term energy estimate. */
- int dml; /* Long term energy estimate. */
- int ap; /* Linear weighting coefficient of 'yl' and 'yu'. */
-
- int a[2]; /* Coefficients of pole portion of prediction filter.
- * stored as fixed-point 1==2^14 */
- int b[6]; /* Coefficients of zero portion of prediction filter.
- * stored as fixed-point 1==2^14 */
- int pk[2]; /* Signs of previous two samples of a partially
- * reconstructed signal.
- */
- int dq[6]; /* Previous 6 samples of the quantized difference signal
- * stored as fixed point 1==2^12,
- * or in internal floating point format */
- int sr[2]; /* Previous 2 samples of the quantized difference signal
- * stored as fixed point 1==2^12,
- * or in internal floating point format */
- int td; /* delayed tone detect, new in 1988 version */
-};
-
-
-
-static int qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400};
-/*
- * Maps G.721 code word to reconstructed scale factor normalized log
- * magnitude values.
- */
-static int _dqlntab[16] = {-2048, 4, 135, 213, 273, 323, 373, 425,
- 425, 373, 323, 273, 213, 135, 4, -2048};
-
-/* Maps G.721 code word to log of scale factor multiplier. */
-static int _witab[16] = {-12, 18, 41, 64, 112, 198, 355, 1122,
- 1122, 355, 198, 112, 64, 41, 18, -12};
-/*
- * Maps G.721 code words to a set of values whose long and short
- * term averages are computed and then compared to give an indication
- * how stationary (steady state) the signal is.
- */
-static int _fitab[16] = {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00,
- 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0};
-
-/* Deprecated
-static int power2[15] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80,
- 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000};
-*/
-
-/*
- * g72x_init_state()
- *
- * This routine initializes and/or resets the g726_state structure
- * pointed to by 'state_ptr'.
- * All the initial state values are specified in the CCITT G.721 document.
- */
-static void g726_init_state(struct g726_state *state_ptr)
-{
- int cnta;
-
- state_ptr->yl = 34816;
- state_ptr->yu = 544;
- state_ptr->dms = 0;
- state_ptr->dml = 0;
- state_ptr->ap = 0;
- for (cnta = 0; cnta < 2; cnta++)
- {
- state_ptr->a[cnta] = 0;
- state_ptr->pk[cnta] = 0;
-#ifdef NOT_BLI
- state_ptr->sr[cnta] = 1;
-#else
- state_ptr->sr[cnta] = 32;
-#endif
- }
- for (cnta = 0; cnta < 6; cnta++)
- {
- state_ptr->b[cnta] = 0;
-#ifdef NOT_BLI
- state_ptr->dq[cnta] = 1;
-#else
- state_ptr->dq[cnta] = 32;
-#endif
- }
- state_ptr->td = 0;
-}
-
-/*
- * quan()
- *
- * quantizes the input val against the table of integers.
- * It returns i if table[i - 1] <= val < table[i].
- *
- * Using linear search for simple coding.
- */
-static int quan(int val, int *table, int size)
-{
- int i;
-
- for (i = 0; i < size && val >= *table; ++i, ++table)
- ;
- return (i);
-}
-
-#ifdef NOT_BLI /* faster non-identical version */
-
-/*
- * predictor_zero()
- *
- * computes the estimated signal from 6-zero predictor.
- *
- */
-static int predictor_zero(struct g726_state *state_ptr)
-{ /* divide by 2 is necessary here to handle negative numbers correctly */
- int i;
- sint64 sezi;
- for (sezi = 0, i = 0; i < 6; i++) /* ACCUM */
- sezi += (sint64)state_ptr->b[i] * state_ptr->dq[i];
- return (int)(sezi >> 13) / 2 /* 2^14 */;
-}
-
-/*
- * predictor_pole()
- *
- * computes the estimated signal from 2-pole predictor.
- *
- */
-static int predictor_pole(struct g726_state *state_ptr)
-{ /* divide by 2 is necessary here to handle negative numbers correctly */
- return (int)(((sint64)state_ptr->a[1] * state_ptr->sr[1] +
- (sint64)state_ptr->a[0] * state_ptr->sr[0]) >> 13) / 2 /* 2^14 */;
-}
-
-#else /* NOT_BLI - identical version */
-/*
- * fmult()
- *
- * returns the integer product of the fixed-point number "an" (1==2^12) and
- * "floating point" representation (4-bit exponent, 6-bit mantessa) "srn".
- */
-static int fmult(int an, int srn)
-{
- int anmag, anexp, anmant;
- int wanexp, wanmant;
- int retval;
-
- anmag = (an > 0) ? an : ((-an) & 0x1FFF);
- anexp = ilog2(anmag) - 5;
- anmant = (anmag == 0) ? 32 :
- (anexp >= 0) ? anmag >> anexp : anmag << -anexp;
- wanexp = anexp + ((srn >> 6) & 0xF) - 13;
-
- wanmant = (anmant * (srn & 077) + 0x30) >> 4;
- retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) :
- (wanmant >> -wanexp);
-
- return (((an ^ srn) < 0) ? -retval : retval);
-}
-
-static int predictor_zero(struct g726_state *state_ptr)
-{
- int i;
- int sezi;
- for (sezi = 0, i = 0; i < 6; i++) /* ACCUM */
- sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]);
- return sezi;
-}
-
-static int predictor_pole(struct g726_state *state_ptr)
-{
- return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) +
- fmult(state_ptr->a[0] >> 2, state_ptr->sr[0]));
-}
-
-#endif /* NOT_BLI */
-
-/*
- * step_size()
- *
- * computes the quantization step size of the adaptive quantizer.
- *
- */
-static int step_size(struct g726_state *state_ptr)
-{
- int y;
- int dif;
- int al;
-
- if (state_ptr->ap >= 256)
- return (state_ptr->yu);
- else {
- y = state_ptr->yl >> 6;
- dif = state_ptr->yu - y;
- al = state_ptr->ap >> 2;
- if (dif > 0)
- y += (dif * al) >> 6;
- else if (dif < 0)
- y += (dif * al + 0x3F) >> 6;
- return (y);
- }
-}
-
-/*
- * quantize()
- *
- * Given a raw sample, 'd', of the difference signal and a
- * quantization step size scale factor, 'y', this routine returns the
- * ADPCM codeword to which that sample gets quantized. The step
- * size scale factor division operation is done in the log base 2 domain
- * as a subtraction.
- */
-static int quantize(
- int d, /* Raw difference signal sample */
- int y, /* Step size multiplier */
- int *table, /* quantization table */
- int size) /* table size of integers */
-{
- int dqm; /* Magnitude of 'd' */
- int exp; /* Integer part of base 2 log of 'd' */
- int mant; /* Fractional part of base 2 log */
- int dl; /* Log of magnitude of 'd' */
- int dln; /* Step size scale factor normalized log */
- int i;
-
- /*
- * LOG
- *
- * Compute base 2 log of 'd', and store in 'dl'.
- */
- dqm = abs(d);
- exp = ilog2(dqm);
- if (exp < 0)
- exp = 0;
- mant = ((dqm << 7) >> exp) & 0x7F; /* Fractional portion. */
- dl = (exp << 7) | mant;
-
- /*
- * SUBTB
- *
- * "Divide" by step size multiplier.
- */
- dln = dl - (y >> 2);
-
- /*
- * QUAN
- *
- * Obtain codword i for 'd'.
- */
- i = quan(dln, table, size);
- if (d < 0) /* take 1's complement of i */
- return ((size << 1) + 1 - i);
- else if (i == 0) /* take 1's complement of 0 */
- return ((size << 1) + 1); /* new in 1988 */
- else
- return (i);
-}
-
-/*
- * reconstruct()
- *
- * Returns reconstructed difference signal 'dq' obtained from
- * codeword 'i' and quantization step size scale factor 'y'.
- * Multiplication is performed in log base 2 domain as addition.
- */
-static int reconstruct(
- int sign, /* 0 for non-negative value */
- int dqln, /* G.72x codeword */
- int y) /* Step size multiplier */
-{
- int dql; /* Log of 'dq' magnitude */
- int dex; /* Integer part of log */
- int dqt;
- int dq; /* Reconstructed difference signal sample */
-
- dql = dqln + (y >> 2); /* ADDA */
-
- if (dql < 0) {
-#ifdef NOT_BLI
- return (sign) ? -1 : 1;
-#else
- return (sign) ? -0x8000 : 0;
-#endif
- } else { /* ANTILOG */
- dex = (dql >> 7) & 15;
- dqt = 128 + (dql & 127);
-#ifdef NOT_BLI
- dq = ((dqt << 19) >> (14 - dex));
- return (sign) ? -dq : dq;
-#else
- dq = (dqt << 7) >> (14 - dex);
- return (sign) ? (dq - 0x8000) : dq;
-#endif
- }
-}
-
-/*
- * update()
- *
- * updates the state variables for each output code
- */
-static void update(
- int code_size, /* distinguish 723_40 with others */
- int y, /* quantizer step size */
- int wi, /* scale factor multiplier */
- int fi, /* for long/short term energies */
- int dq, /* quantized prediction difference */
- int sr, /* reconstructed signal */
- int dqsez, /* difference from 2-pole predictor */
- struct g726_state *state_ptr) /* coder state pointer */
-{
- int cnt;
- int mag; /* Adaptive predictor, FLOAT A */
-#ifndef NOT_BLI
- int exp;
-#endif
- int a2p=0; /* LIMC */
- int a1ul; /* UPA1 */
- int pks1; /* UPA2 */
- int fa1;
- int tr; /* tone/transition detector */
- int ylint, thr2, dqthr;
- int ylfrac, thr1;
- int pk0;
-
- pk0 = (dqsez < 0) ? 1 : 0; /* needed in updating predictor poles */
-
-#ifdef NOT_BLI
- mag = abs(dq / 0x1000); /* prediction difference magnitude */
-#else
- mag = dq & 0x7FFF; /* prediction difference magnitude */
-#endif
- /* TRANS */
- ylint = state_ptr->yl >> 15; /* exponent part of yl */
- ylfrac = (state_ptr->yl >> 10) & 0x1F; /* fractional part of yl */
- thr1 = (32 + ylfrac) << ylint; /* threshold */
- thr2 = (ylint > 9) ? 31 << 10 : thr1; /* limit thr2 to 31 << 10 */
- dqthr = (thr2 + (thr2 >> 1)) >> 1; /* dqthr = 0.75 * thr2 */
- if (state_ptr->td == 0) /* signal supposed voice */
- tr = 0;
- else if (mag <= dqthr) /* supposed data, but small mag */
- tr = 0; /* treated as voice */
- else /* signal is data (modem) */
- tr = 1;
-
- /*
- * Quantizer scale factor adaptation.
- */
-
- /* FUNCTW & FILTD & DELAY */
- /* update non-steady state step size multiplier */
- state_ptr->yu = y + ((wi - y) >> 5);
-
- /* LIMB */
- if (state_ptr->yu < 544) /* 544 <= yu <= 5120 */
- state_ptr->yu = 544;
- else if (state_ptr->yu > 5120)
- state_ptr->yu = 5120;
-
- /* FILTE & DELAY */
- /* update steady state step size multiplier */
- state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6);
-
- /*
- * Adaptive predictor coefficients.
- */
- if (tr == 1) { /* reset a's and b's for modem signal */
- state_ptr->a[0] = 0;
- state_ptr->a[1] = 0;
- state_ptr->b[0] = 0;
- state_ptr->b[1] = 0;
- state_ptr->b[2] = 0;
- state_ptr->b[3] = 0;
- state_ptr->b[4] = 0;
- state_ptr->b[5] = 0;
- } else { /* update a's and b's */
- pks1 = pk0 ^ state_ptr->pk[0]; /* UPA2 */
-
- /* update predictor pole a[1] */
- a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7);
- if (dqsez != 0) {
- fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0];
- if (fa1 < -8191) /* a2p = function of fa1 */
- a2p -= 0x100;
- else if (fa1 > 8191)
- a2p += 0xFF;
- else
- a2p += fa1 >> 5;
-
- if (pk0 ^ state_ptr->pk[1])
- /* LIMC */
- if (a2p <= -12160)
- a2p = -12288;
- else if (a2p >= 12416)
- a2p = 12288;
- else
- a2p -= 0x80;
- else if (a2p <= -12416)
- a2p = -12288;
- else if (a2p >= 12160)
- a2p = 12288;
- else
- a2p += 0x80;
- }
-
- /* TRIGB & DELAY */
- state_ptr->a[1] = a2p;
-
- /* UPA1 */
- /* update predictor pole a[0] */
- state_ptr->a[0] -= state_ptr->a[0] >> 8;
- if (dqsez != 0) {
- if (pks1 == 0)
- state_ptr->a[0] += 192;
- else
- state_ptr->a[0] -= 192;
- }
- /* LIMD */
- a1ul = 15360 - a2p;
- if (state_ptr->a[0] < -a1ul)
- state_ptr->a[0] = -a1ul;
- else if (state_ptr->a[0] > a1ul)
- state_ptr->a[0] = a1ul;
-
- /* UPB : update predictor zeros b[6] */
- for (cnt = 0; cnt < 6; cnt++) {
- if (code_size == 5) /* for 40Kbps G.723 */
- state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9;
- else /* for G.721 and 24Kbps G.723 */
- state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8;
- if (mag)
- { /* XOR */
- if ((dq ^ state_ptr->dq[cnt]) >= 0)
- state_ptr->b[cnt] += 128;
- else
- state_ptr->b[cnt] -= 128;
- }
- }
- }
-
- for (cnt = 5; cnt > 0; cnt--)
- state_ptr->dq[cnt] = state_ptr->dq[cnt-1];
-#ifdef NOT_BLI
- state_ptr->dq[0] = dq;
-#else
- /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */
- if (mag == 0) {
- state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400;
- } else {
- exp = ilog2(mag) + 1;
- state_ptr->dq[0] = (dq >= 0) ?
- (exp << 6) + ((mag << 6) >> exp) :
- (exp << 6) + ((mag << 6) >> exp) - 0x400;
- }
-#endif
-
- state_ptr->sr[1] = state_ptr->sr[0];
-#ifdef NOT_BLI
- state_ptr->sr[0] = sr;
-#else
- /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */
- if (sr == 0) {
- state_ptr->sr[0] = 0x20;
- } else if (sr > 0) {
- exp = ilog2(sr) + 1;
- state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp);
- } else if (sr > -0x8000) {
- mag = -sr;
- exp = ilog2(mag) + 1;
- state_ptr->sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400;
- } else
- state_ptr->sr[0] = 0x20 - 0x400;
-#endif
-
- /* DELAY A */
- state_ptr->pk[1] = state_ptr->pk[0];
- state_ptr->pk[0] = pk0;
-
- /* TONE */
- if (tr == 1) /* this sample has been treated as data */
- state_ptr->td = 0; /* next one will be treated as voice */
- else if (a2p < -11776) /* small sample-to-sample correlation */
- state_ptr->td = 1; /* signal may be data */
- else /* signal is voice */
- state_ptr->td = 0;
-
- /*
- * Adaptation speed control.
- */
- state_ptr->dms += (fi - state_ptr->dms) >> 5; /* FILTA */
- state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7); /* FILTB */
-
- if (tr == 1)
- state_ptr->ap = 256;
- else if (y < 1536) /* SUBTC */
- state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
- else if (state_ptr->td == 1)
- state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
- else if (abs((state_ptr->dms << 2) - state_ptr->dml) >=
- (state_ptr->dml >> 3))
- state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
- else
- state_ptr->ap += (-state_ptr->ap) >> 4;
-}
-
-/*
- * g726_decode()
- *
- * Description:
- *
- * Decodes a 4-bit code of G.726-32 encoded data of i and
- * returns the resulting linear PCM, A-law or u-law value.
- * return -1 for unknown out_coding value.
- */
-static int g726_decode(int i, struct g726_state *state_ptr)
-{
- int sezi, sez, se; /* ACCUM */
- int y; /* MIX */
- int sr; /* ADDB */
- int dq;
- int dqsez;
-
- i &= 0x0f; /* mask to get proper bits */
-#ifdef NOT_BLI
- sezi = predictor_zero(state_ptr);
- sez = sezi;
- se = sezi + predictor_pole(state_ptr); /* estimated signal */
-#else
- sezi = predictor_zero(state_ptr);
- sez = sezi >> 1;
- se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */
-#endif
-
- y = step_size(state_ptr); /* dynamic quantizer step size */
-
- dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized diff. */
-
-#ifdef NOT_BLI
- sr = se + dq; /* reconst. signal */
- dqsez = dq + sez; /* pole prediction diff. */
-#else
- sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */
- dqsez = sr - se + sez; /* pole prediction diff. */
-#endif
-
- update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
-
-#ifdef NOT_BLI
- return (sr >> 10); /* sr was 26-bit dynamic range */
-#else
- return (sr << 2); /* sr was 14-bit dynamic range */
-#endif
-}
-
-/*
- * g726_encode()
- *
- * Encodes the input vale of linear PCM, A-law or u-law data sl and returns
- * the resulting code. -1 is returned for unknown input coding value.
- */
-static int g726_encode(int sl, struct g726_state *state_ptr)
-{
- int sezi, se, sez; /* ACCUM */
- int d; /* SUBTA */
- int sr; /* ADDB */
- int y; /* MIX */
- int dqsez; /* ADDC */
- int dq, i;
-
-#ifdef NOT_BLI
- sl <<= 10; /* 26-bit dynamic range */
-
- sezi = predictor_zero(state_ptr);
- sez = sezi;
- se = sezi + predictor_pole(state_ptr); /* estimated signal */
-#else
- sl >>= 2; /* 14-bit dynamic range */
-
- sezi = predictor_zero(state_ptr);
- sez = sezi >> 1;
- se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */
-#endif
-
- d = sl - se; /* estimation difference */
-
- /* quantize the prediction difference */
- y = step_size(state_ptr); /* quantizer step size */
-#ifdef NOT_BLI
- d /= 0x1000;
-#endif
- i = quantize(d, y, qtab_721, 7); /* i = G726 code */
-
- dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */
-
-#ifdef NOT_BLI
- sr = se + dq; /* reconst. signal */
- dqsez = dq + sez; /* pole prediction diff. */
-#else
- sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */
- dqsez = sr - se + sez; /* pole prediction diff. */
-#endif
-
- update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
-
- return (i);
-}
-
-/*
- * Private workspace for translating signed linear signals to G726.
- */
-
-struct g726_encoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
- unsigned char outbuf[BUFFER_SIZE]; /* Encoded G726, two nibbles to a word */
- unsigned char next_flag;
- struct g726_state g726;
- int tail;
-};
-
-/*
- * Private workspace for translating G726 signals to signed linear.
- */
-
-struct g726_decoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
- short outbuf[BUFFER_SIZE]; /* Decoded signed linear values */
- struct g726_state g726;
- int tail;
- plc_state_t plc;
-};
-
-/*
- * G726ToLin_New
- * Create a new instance of g726_decoder_pvt.
- *
- * Results:
- * Returns a pointer to the new instance.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_translator_pvt *
-g726tolin_new (void)
-{
- struct g726_decoder_pvt *tmp;
- tmp = malloc (sizeof (struct g726_decoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- tmp->tail = 0;
- plc_init(&tmp->plc);
- localusecnt++;
- g726_init_state(&tmp->g726);
- ast_update_use_count ();
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-/*
- * LinToG726_New
- * Create a new instance of g726_encoder_pvt.
- *
- * Results:
- * Returns a pointer to the new instance.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_translator_pvt *
-lintog726_new (void)
-{
- struct g726_encoder_pvt *tmp;
- tmp = malloc (sizeof (struct g726_encoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- localusecnt++;
- tmp->tail = 0;
- g726_init_state(&tmp->g726);
- ast_update_use_count ();
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-/*
- * G726ToLin_FrameIn
- * Fill an input buffer with packed 4-bit G726 values if there is room
- * left.
- *
- * Results:
- * Foo
- *
- * Side effects:
- * tmp->tail is the number of packed values in the buffer.
- */
-
-static int
-g726tolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct g726_decoder_pvt *tmp = (struct g726_decoder_pvt *) pvt;
- unsigned char *b;
- int x;
-
- if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
- if((tmp->tail + 160) > BUFFER_SIZE) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- if(useplc) {
- plc_fillin(&tmp->plc, tmp->outbuf+tmp->tail, 160);
- tmp->tail += 160;
- }
- return 0;
- }
-
- b = f->data;
- for (x=0;x<f->datalen;x++) {
- if (tmp->tail >= BUFFER_SIZE) {
- ast_log(LOG_WARNING, "Out of buffer space!\n");
- return -1;
- }
- tmp->outbuf[tmp->tail++] = g726_decode((b[x] >> 4) & 0xf, &tmp->g726);
- if (tmp->tail >= BUFFER_SIZE) {
- ast_log(LOG_WARNING, "Out of buffer space!\n");
- return -1;
- }
- tmp->outbuf[tmp->tail++] = g726_decode(b[x] & 0x0f, &tmp->g726);
- }
-
- if(useplc) plc_rx(&tmp->plc, tmp->outbuf+tmp->tail-f->datalen*2, f->datalen*2);
-
- return 0;
-}
-
-/*
- * G726ToLin_FrameOut
- * Convert 4-bit G726 encoded signals to 16-bit signed linear.
- *
- * Results:
- * Converted signals are placed in tmp->f.data, tmp->f.datalen
- * and tmp->f.samples are calculated.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_frame *
-g726tolin_frameout (struct ast_translator_pvt *pvt)
-{
- struct g726_decoder_pvt *tmp = (struct g726_decoder_pvt *) pvt;
-
- if (!tmp->tail)
- return NULL;
-
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SLINEAR;
- tmp->f.datalen = tmp->tail * 2;
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->tail = 0;
- return &tmp->f;
-}
-
-/*
- * LinToG726_FrameIn
- * Fill an input buffer with 16-bit signed linear PCM values.
- *
- * Results:
- * None.
- *
- * Side effects:
- * tmp->tail is number of signal values in the input buffer.
- */
-
-static int
-lintog726_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct g726_encoder_pvt *tmp = (struct g726_encoder_pvt *) pvt;
- short *s = f->data;
- int samples = f->datalen / 2;
- int x;
- for (x=0;x<samples;x++) {
- if (tmp->next_flag & 0x80) {
- if (tmp->tail >= BUFFER_SIZE) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- tmp->outbuf[tmp->tail++] = ((tmp->next_flag & 0xf)<< 4) | g726_encode(s[x], &tmp->g726);
- tmp->next_flag = 0;
- } else {
- tmp->next_flag = 0x80 | g726_encode(s[x], &tmp->g726);
- }
- }
- return 0;
-}
-
-/*
- * LinToG726_FrameOut
- * Convert a buffer of raw 16-bit signed linear PCM to a buffer
- * of 4-bit G726 packed two to a byte (Big Endian).
- *
- * Results:
- * Foo
- *
- * Side effects:
- * Leftover inbuf data gets packed, tail gets updated.
- */
-
-static struct ast_frame *
-lintog726_frameout (struct ast_translator_pvt *pvt)
-{
- struct g726_encoder_pvt *tmp = (struct g726_encoder_pvt *) pvt;
-
- if (!tmp->tail)
- return NULL;
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_G726;
- tmp->f.samples = tmp->tail * 2;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->f.datalen = tmp->tail;
-
- tmp->tail = 0;
- return &tmp->f;
-}
-
-
-/*
- * G726ToLin_Sample
- */
-
-static struct ast_frame *
-g726tolin_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_G726;
- f.datalen = sizeof (g726_slin_ex);
- f.samples = sizeof(g726_slin_ex) * 2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = g726_slin_ex;
- return &f;
-}
-
-/*
- * LinToG726_Sample
- */
-
-static struct ast_frame *
-lintog726_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = sizeof (slin_g726_ex);
- /* Assume 8000 Hz */
- f.samples = sizeof (slin_g726_ex) / 2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = slin_g726_ex;
- return &f;
-}
-
-/*
- * G726_Destroy
- * Destroys a private workspace.
- *
- * Results:
- * It's gone!
- *
- * Side effects:
- * None.
- */
-
-static void
-g726_destroy (struct ast_translator_pvt *pvt)
-{
- free (pvt);
- localusecnt--;
- ast_update_use_count ();
-}
-
-/*
- * The complete translator for G726ToLin.
- */
-
-static struct ast_translator g726tolin = {
- "g726tolin",
- AST_FORMAT_G726,
- AST_FORMAT_SLINEAR,
- g726tolin_new,
- g726tolin_framein,
- g726tolin_frameout,
- g726_destroy,
- /* NULL */
- g726tolin_sample
-};
-
-/*
- * The complete translator for LinToG726.
- */
-
-static struct ast_translator lintog726 = {
- "lintog726",
- AST_FORMAT_SLINEAR,
- AST_FORMAT_G726,
- lintog726_new,
- lintog726_framein,
- lintog726_frameout,
- g726_destroy,
- /* NULL */
- lintog726_sample
-};
-
-static void
-parse_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
- if ((cfg = ast_config_load("codecs.conf"))) {
- if ((var = ast_variable_browse(cfg, "plc"))) {
- while (var) {
- if (!strcasecmp(var->name, "genericplc")) {
- useplc = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "codec_g726: %susing generic PLC\n", useplc ? "" : "not ");
- }
- var = var->next;
- }
- }
- ast_config_destroy(cfg);
- }
-}
-
-int
-reload(void)
-{
- parse_config();
- return 0;
-}
-
-int
-unload_module (void)
-{
- int res;
- ast_mutex_lock (&localuser_lock);
- res = ast_unregister_translator (&lintog726);
- if (!res)
- res = ast_unregister_translator (&g726tolin);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock (&localuser_lock);
- return res;
-}
-
-int
-load_module (void)
-{
- int res;
- parse_config();
- res = ast_register_translator (&g726tolin);
- if (!res)
- res = ast_register_translator (&lintog726);
- else
- ast_unregister_translator (&g726tolin);
- return res;
-}
-
-/*
- * Return a description of this module.
- */
-
-char *
-description (void)
-{
- return tdesc;
-}
-
-int
-usecount (void)
-{
- int res;
- STANDARD_USECOUNT (res);
- return res;
-}
-
-char *
-key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/codec_gsm.c b/1.2-netsec/codecs/codec_gsm.c
deleted file mode 100644
index 65800476e..000000000
--- a/1.2-netsec/codecs/codec_gsm.c
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * The GSM code is from TOAST. Copyright information for that package is available
- * in the GSM directory.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Translate between signed linear and Global System for Mobile Communications (GSM)
- *
- * \ingroup codecs
- */
-
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/translate.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-
-#include "gsm/inc/gsm.h"
-#include "../formats/msgsm.h"
-
-/* Sample frame data */
-#include "slin_gsm_ex.h"
-#include "gsm_slin_ex.h"
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt=0;
-
-static char *tdesc = "GSM/PCM16 (signed linear) Codec Translator";
-
-static int useplc = 0;
-
-struct ast_translator_pvt {
- gsm gsm;
- struct ast_frame f;
- /* Space to build offset */
- char offset[AST_FRIENDLY_OFFSET];
- /* Buffer for our outgoing frame */
- short outbuf[8000];
- /* Enough to store a full second */
- short buf[8000];
- int tail;
- plc_state_t plc;
-};
-
-#define gsm_coder_pvt ast_translator_pvt
-
-static struct ast_translator_pvt *gsm_new(void)
-{
- struct gsm_coder_pvt *tmp;
- tmp = malloc(sizeof(struct gsm_coder_pvt));
- if (tmp) {
- if (!(tmp->gsm = gsm_create())) {
- free(tmp);
- tmp = NULL;
- }
- tmp->tail = 0;
- plc_init(&tmp->plc);
- localusecnt++;
- }
- return tmp;
-}
-
-static struct ast_frame *lintogsm_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = sizeof(slin_gsm_ex);
- /* Assume 8000 Hz */
- f.samples = sizeof(slin_gsm_ex)/2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = slin_gsm_ex;
- return &f;
-}
-
-static struct ast_frame *gsmtolin_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_GSM;
- f.datalen = sizeof(gsm_slin_ex);
- /* All frames are 20 ms long */
- f.samples = 160;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = gsm_slin_ex;
- return &f;
-}
-
-static struct ast_frame *gsmtolin_frameout(struct ast_translator_pvt *tmp)
-{
- if (!tmp->tail)
- return NULL;
- /* Signed linear is no particular frame size, so just send whatever
- we have in the buffer in one lump sum */
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SLINEAR;
- tmp->f.datalen = tmp->tail * 2;
- /* Assume 8000 Hz */
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->buf;
- /* Reset tail pointer */
- tmp->tail = 0;
-
- return &tmp->f;
-}
-
-static int gsmtolin_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
-{
- /* Assuming there's space left, decode into the current buffer at
- the tail location. Read in as many frames as there are */
- int x;
- unsigned char data[66];
- int msgsm=0;
-
- if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
- if((tmp->tail + 160) > sizeof(tmp->buf) / 2) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- if(useplc) {
- plc_fillin(&tmp->plc, tmp->buf+tmp->tail, 160);
- tmp->tail += 160;
- }
- return 0;
- }
-
- if ((f->datalen % 33) && (f->datalen % 65)) {
- ast_log(LOG_WARNING, "Huh? A GSM frame that isn't a multiple of 33 or 65 bytes long from %s (%d)?\n", f->src, f->datalen);
- return -1;
- }
-
- if (f->datalen % 65 == 0)
- msgsm = 1;
-
- for (x=0;x<f->datalen;x+=(msgsm ? 65 : 33)) {
- if (msgsm) {
- /* Translate MSGSM format to Real GSM format before feeding in */
- conv65(f->data + x, data);
- if (tmp->tail + 320 < sizeof(tmp->buf)/2) {
- if (gsm_decode(tmp->gsm, data, tmp->buf + tmp->tail)) {
- ast_log(LOG_WARNING, "Invalid GSM data (1)\n");
- return -1;
- }
- tmp->tail+=160;
- if (gsm_decode(tmp->gsm, data + 33, tmp->buf + tmp->tail)) {
- ast_log(LOG_WARNING, "Invalid GSM data (2)\n");
- return -1;
- }
- tmp->tail+=160;
- } else {
- ast_log(LOG_WARNING, "Out of (MS) buffer space\n");
- return -1;
- }
- } else {
- if (tmp->tail + 160 < sizeof(tmp->buf)/2) {
- if (gsm_decode(tmp->gsm, f->data + x, tmp->buf + tmp->tail)) {
- ast_log(LOG_WARNING, "Invalid GSM data\n");
- return -1;
- }
- tmp->tail+=160;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- }
- }
-
- /* just add the last 20ms frame; there must have been at least one */
- if(useplc) plc_rx(&tmp->plc, tmp->buf+tmp->tail-160, 160);
-
- return 0;
-}
-
-static int lintogsm_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
-{
- /* Just add the frames to our stream */
- /* XXX We should look at how old the rest of our stream is, and if it
- is too old, then we should overwrite it entirely, otherwise we can
- get artifacts of earlier talk that do not belong */
- if (tmp->tail + f->datalen/2 < sizeof(tmp->buf) / 2) {
- memcpy((tmp->buf + tmp->tail), f->data, f->datalen);
- tmp->tail += f->datalen/2;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_frame *lintogsm_frameout(struct ast_translator_pvt *tmp)
-{
- int x=0;
- /* We can't work on anything less than a frame in size */
- if (tmp->tail < 160)
- return NULL;
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_GSM;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- while(tmp->tail >= 160) {
- if ((x+1) * 33 >= sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- break;
- }
- /* Encode a frame of data */
- gsm_encode(tmp->gsm, tmp->buf, ((gsm_byte *) tmp->outbuf) + (x * 33));
- /* Assume 8000 Hz -- 20 ms */
- tmp->tail -= 160;
- /* Move the data at the end of the buffer to the front */
- if (tmp->tail)
- memmove(tmp->buf, tmp->buf + 160, tmp->tail * 2);
- x++;
- }
- tmp->f.datalen = x * 33;
- tmp->f.samples = x * 160;
- return &tmp->f;
-}
-
-static void gsm_destroy_stuff(struct ast_translator_pvt *pvt)
-{
- if (pvt->gsm)
- gsm_destroy(pvt->gsm);
- free(pvt);
- localusecnt--;
-}
-
-static struct ast_translator gsmtolin =
- { "gsmtolin",
- AST_FORMAT_GSM, AST_FORMAT_SLINEAR,
- gsm_new,
- gsmtolin_framein,
- gsmtolin_frameout,
- gsm_destroy_stuff,
- gsmtolin_sample
- };
-
-static struct ast_translator lintogsm =
- { "lintogsm",
- AST_FORMAT_SLINEAR, AST_FORMAT_GSM,
- gsm_new,
- lintogsm_framein,
- lintogsm_frameout,
- gsm_destroy_stuff,
- lintogsm_sample
- };
-
-
-static void parse_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
- if ((cfg = ast_config_load("codecs.conf"))) {
- if ((var = ast_variable_browse(cfg, "plc"))) {
- while (var) {
- if (!strcasecmp(var->name, "genericplc")) {
- useplc = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "codec_gsm: %susing generic PLC\n", useplc ? "" : "not ");
- }
- var = var->next;
- }
- }
- ast_config_destroy(cfg);
- }
-}
-
-int reload(void)
-{
- parse_config();
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
- ast_mutex_lock(&localuser_lock);
- res = ast_unregister_translator(&lintogsm);
- if (!res)
- res = ast_unregister_translator(&gsmtolin);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock(&localuser_lock);
- return res;
-}
-
-int load_module(void)
-{
- int res;
- parse_config();
- res=ast_register_translator(&gsmtolin);
- if (!res)
- res=ast_register_translator(&lintogsm);
- else
- ast_unregister_translator(&gsmtolin);
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/codec_ilbc.c b/1.2-netsec/codecs/codec_ilbc.c
deleted file mode 100644
index 3f415c8dd..000000000
--- a/1.2-netsec/codecs/codec_ilbc.c
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * The iLBC code is from The IETF code base and is copyright The Internet Society (2004)
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Translate between signed linear and Internet Low Bitrate Codec
- *
- * \ingroup codecs
- */
-
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/translate.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-
-#include "ilbc/iLBC_encode.h"
-#include "ilbc/iLBC_decode.h"
-
-/* Sample frame data */
-#include "slin_ilbc_ex.h"
-#include "ilbc_slin_ex.h"
-
-#define USE_ILBC_ENHANCER 0
-#define ILBC_MS 30
-/* #define ILBC_MS 20 */
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt=0;
-
-static char *tdesc = "iLBC/PCM16 (signed linear) Codec Translator";
-
-struct ast_translator_pvt {
- iLBC_Enc_Inst_t enc;
- iLBC_Dec_Inst_t dec;
- struct ast_frame f;
- /* Space to build offset */
- char offset[AST_FRIENDLY_OFFSET];
- /* Buffer for our outgoing frame */
- short outbuf[8000];
- /* Enough to store a full second */
- short buf[8000];
- int tail;
-};
-
-#define ilbc_coder_pvt ast_translator_pvt
-
-static struct ast_translator_pvt *lintoilbc_new(void)
-{
- struct ilbc_coder_pvt *tmp;
- tmp = malloc(sizeof(struct ilbc_coder_pvt));
- if (tmp) {
- /* Shut valgrind up */
- memset(&tmp->enc, 0, sizeof(tmp->enc));
- initEncode(&tmp->enc, ILBC_MS);
- tmp->tail = 0;
- localusecnt++;
- }
- return tmp;
-}
-
-static struct ast_translator_pvt *ilbctolin_new(void)
-{
- struct ilbc_coder_pvt *tmp;
- tmp = malloc(sizeof(struct ilbc_coder_pvt));
- if (tmp) {
- /* Shut valgrind up */
- memset(&tmp->dec, 0, sizeof(tmp->dec));
- initDecode(&tmp->dec, ILBC_MS, USE_ILBC_ENHANCER);
- tmp->tail = 0;
- localusecnt++;
- }
- return tmp;
-}
-
-static struct ast_frame *lintoilbc_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = sizeof(slin_ilbc_ex);
- /* Assume 8000 Hz */
- f.samples = sizeof(slin_ilbc_ex)/2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = slin_ilbc_ex;
- return &f;
-}
-
-static struct ast_frame *ilbctolin_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_ILBC;
- f.datalen = sizeof(ilbc_slin_ex);
- /* All frames are 30 ms long */
- f.samples = 240;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = ilbc_slin_ex;
- return &f;
-}
-
-static struct ast_frame *ilbctolin_frameout(struct ast_translator_pvt *tmp)
-{
- if (!tmp->tail)
- return NULL;
- /* Signed linear is no particular frame size, so just send whatever
- we have in the buffer in one lump sum */
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SLINEAR;
- tmp->f.datalen = tmp->tail * 2;
- /* Assume 8000 Hz */
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->buf;
- /* Reset tail pointer */
- tmp->tail = 0;
-
- return &tmp->f;
-}
-
-static int ilbctolin_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
-{
- /* Assuming there's space left, decode into the current buffer at
- the tail location. Read in as many frames as there are */
- int x,i;
- float tmpf[240];
-
- if (f->datalen == 0) { /* native PLC */
- if (tmp->tail + 240 < sizeof(tmp->buf)/2) {
- iLBC_decode(tmpf, NULL, &tmp->dec, 0);
- for (i=0;i<240;i++)
- tmp->buf[tmp->tail + i] = tmpf[i];
- tmp->tail+=240;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- }
-
- if (f->datalen % 50) {
- ast_log(LOG_WARNING, "Huh? An ilbc frame that isn't a multiple of 50 bytes long from %s (%d)?\n", f->src, f->datalen);
- return -1;
- }
-
- for (x=0;x<f->datalen;x+=50) {
- if (tmp->tail + 240 < sizeof(tmp->buf)/2) {
- iLBC_decode(tmpf, f->data + x, &tmp->dec, 1);
- for (i=0;i<240;i++)
- tmp->buf[tmp->tail + i] = tmpf[i];
- tmp->tail+=240;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- }
- return 0;
-}
-
-static int lintoilbc_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
-{
- /* Just add the frames to our stream */
- /* XXX We should look at how old the rest of our stream is, and if it
- is too old, then we should overwrite it entirely, otherwise we can
- get artifacts of earlier talk that do not belong */
- if (tmp->tail + f->datalen/2 < sizeof(tmp->buf) / 2) {
- memcpy((tmp->buf + tmp->tail), f->data, f->datalen);
- tmp->tail += f->datalen/2;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_frame *lintoilbc_frameout(struct ast_translator_pvt *tmp)
-{
- int x=0,i;
- float tmpf[240];
- /* We can't work on anything less than a frame in size */
- if (tmp->tail < 240)
- return NULL;
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_ILBC;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- while(tmp->tail >= 240) {
- if ((x+1) * 50 >= sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- break;
- }
- for (i=0;i<240;i++)
- tmpf[i] = tmp->buf[i];
- /* Encode a frame of data */
- iLBC_encode(((unsigned char *)(tmp->outbuf)) + (x * 50), tmpf, &tmp->enc);
- /* Assume 8000 Hz -- 20 ms */
- tmp->tail -= 240;
- /* Move the data at the end of the buffer to the front */
- if (tmp->tail)
- memmove(tmp->buf, tmp->buf + 240, tmp->tail * 2);
- x++;
- }
- tmp->f.datalen = x * 50;
- tmp->f.samples = x * 240;
-#if 0
- {
- static int fd = -1;
- if (fd == -1) {
- fd = open("ilbc.out", O_CREAT|O_TRUNC|O_WRONLY, 0666);
- write(fd, tmp->f.data, tmp->f.datalen);
- close(fd);
- }
- }
-#endif
- return &tmp->f;
-}
-
-static void ilbc_destroy_stuff(struct ast_translator_pvt *pvt)
-{
- free(pvt);
- localusecnt--;
-}
-
-static struct ast_translator ilbctolin =
- { "ilbctolin",
- AST_FORMAT_ILBC, AST_FORMAT_SLINEAR,
- ilbctolin_new,
- ilbctolin_framein,
- ilbctolin_frameout,
- ilbc_destroy_stuff,
- ilbctolin_sample
- };
-
-static struct ast_translator lintoilbc =
- { "lintoilbc",
- AST_FORMAT_SLINEAR, AST_FORMAT_ILBC,
- lintoilbc_new,
- lintoilbc_framein,
- lintoilbc_frameout,
- ilbc_destroy_stuff,
- lintoilbc_sample
- };
-
-int unload_module(void)
-{
- int res;
- ast_mutex_lock(&localuser_lock);
- res = ast_unregister_translator(&lintoilbc);
- if (!res)
- res = ast_unregister_translator(&ilbctolin);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock(&localuser_lock);
- return res;
-}
-
-int load_module(void)
-{
- int res;
- res=ast_register_translator(&ilbctolin);
- if (!res)
- res=ast_register_translator(&lintoilbc);
- else
- ast_unregister_translator(&ilbctolin);
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/codec_lpc10.c b/1.2-netsec/codecs/codec_lpc10.c
deleted file mode 100644
index 8eeecdef0..000000000
--- a/1.2-netsec/codecs/codec_lpc10.c
+++ /dev/null
@@ -1,431 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * The lpc10 code is from a library used by nautilus, modified to be a bit
- * nicer to the compiler.
- * See http://www.arl.wustl.edu/~jaf/
- *
- * 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 Translate between signed linear and LPC10 (Linear Predictor Code)
- *
- * \ingroup codecs
- */
-
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/translate.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-
-#include "lpc10/lpc10.h"
-
-/* Sample frame data */
-#include "slin_lpc10_ex.h"
-#include "lpc10_slin_ex.h"
-
-/* We use a very strange format here... I have no idea why... The frames are 180
- samples long, which isn't even an even number of milliseconds... Not only that
- but we hvae to waste two bits of each frame to keep them ending on a byte boundary
- because the frames are 54 bits long */
-
-#define LPC10_BYTES_IN_COMPRESSED_FRAME (LPC10_BITS_IN_COMPRESSED_FRAME + 7)/8
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt=0;
-
-static char *tdesc = "LPC10 2.4kbps (signed linear) Voice Coder";
-
-static int useplc = 0;
-
-struct ast_translator_pvt {
- union {
- struct lpc10_encoder_state *enc;
- struct lpc10_decoder_state *dec;
- } lpc10;
- struct ast_frame f;
- /* Space to build offset */
- char offset[AST_FRIENDLY_OFFSET];
- /* Buffer for our outgoing frame */
- short outbuf[8000];
- /* Enough to store a full second */
- short buf[8000];
- int tail;
- int longer;
- plc_state_t plc; /* god only knows why I bothered to implement PLC for LPC10 :) */
-};
-
-#define lpc10_coder_pvt ast_translator_pvt
-
-static struct ast_translator_pvt *lpc10_enc_new(void)
-{
- struct lpc10_coder_pvt *tmp;
- tmp = malloc(sizeof(struct lpc10_coder_pvt));
- if (tmp) {
- if (!(tmp->lpc10.enc = create_lpc10_encoder_state())) {
- free(tmp);
- tmp = NULL;
- }
- tmp->tail = 0;
- tmp->longer = 0;
- localusecnt++;
- }
- return tmp;
-}
-
-static struct ast_translator_pvt *lpc10_dec_new(void)
-{
- struct lpc10_coder_pvt *tmp;
- tmp = malloc(sizeof(struct lpc10_coder_pvt));
- if (tmp) {
- if (!(tmp->lpc10.dec = create_lpc10_decoder_state())) {
- free(tmp);
- tmp = NULL;
- }
- tmp->tail = 0;
- tmp->longer = 0;
- plc_init(&tmp->plc);
- localusecnt++;
- }
- return tmp;
-}
-static struct ast_frame *lintolpc10_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = sizeof(slin_lpc10_ex);
- /* Assume 8000 Hz */
- f.samples = LPC10_SAMPLES_PER_FRAME;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = slin_lpc10_ex;
- return &f;
-}
-
-static struct ast_frame *lpc10tolin_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_LPC10;
- f.datalen = sizeof(lpc10_slin_ex);
- /* All frames are 22 ms long (maybe a little more -- why did he choose
- LPC10_SAMPLES_PER_FRAME sample frames anyway?? */
- f.samples = LPC10_SAMPLES_PER_FRAME;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = lpc10_slin_ex;
- return &f;
-}
-
-static struct ast_frame *lpc10tolin_frameout(struct ast_translator_pvt *tmp)
-{
- if (!tmp->tail)
- return NULL;
- /* Signed linear is no particular frame size, so just send whatever
- we have in the buffer in one lump sum */
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SLINEAR;
- tmp->f.datalen = tmp->tail * 2;
- /* Assume 8000 Hz */
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->buf;
- /* Reset tail pointer */
- tmp->tail = 0;
-
-#if 0
- /* Save a sample frame */
- { static int samplefr = 0;
- if (samplefr == 80) {
- int fd;
- fd = open("lpc10.example", O_WRONLY | O_CREAT, 0644);
- write(fd, tmp->f.data, tmp->f.datalen);
- close(fd);
- }
- samplefr++;
- }
-#endif
- return &tmp->f;
-}
-
-static void extract_bits(INT32 *bits, unsigned char *c)
-{
- int x;
- for (x=0;x<LPC10_BITS_IN_COMPRESSED_FRAME;x++) {
- if (*c & (0x80 >> (x & 7)))
- bits[x] = 1;
- else
- bits[x] = 0;
- if ((x & 7) == 7)
- c++;
- }
-}
-
-static void build_bits(unsigned char *c, INT32 *bits)
-{
- unsigned char mask=0x80;
- int x;
- *c = 0;
- for (x=0;x<LPC10_BITS_IN_COMPRESSED_FRAME;x++) {
- if (bits[x])
- *c |= mask;
- mask = mask >> 1;
- if ((x % 8)==7) {
- c++;
- *c = 0;
- mask = 0x80;
- }
- }
-}
-
-static int lpc10tolin_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
-{
- /* Assuming there's space left, decode into the current buffer at
- the tail location */
- int x;
- int len=0;
- float tmpbuf[LPC10_SAMPLES_PER_FRAME];
- short *sd;
- INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME];
-
- if(f->datalen == 0) { /* perform PLC with nominal framesize of LPC10_SAMPLES_PER_FRAME */
- if((tmp->tail + LPC10_SAMPLES_PER_FRAME) > sizeof(tmp->buf)/2) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- if(useplc) {
- plc_fillin(&tmp->plc, tmp->buf+tmp->tail, LPC10_SAMPLES_PER_FRAME);
- tmp->tail += LPC10_SAMPLES_PER_FRAME;
- }
- return 0;
- }
-
- while(len + LPC10_BYTES_IN_COMPRESSED_FRAME <= f->datalen) {
- if (tmp->tail + LPC10_SAMPLES_PER_FRAME < sizeof(tmp->buf)/2) {
- sd = tmp->buf + tmp->tail;
- extract_bits(bits, f->data + len);
- if (lpc10_decode(bits, tmpbuf, tmp->lpc10.dec)) {
- ast_log(LOG_WARNING, "Invalid lpc10 data\n");
- return -1;
- }
- for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++) {
- /* Convert to a real between -1.0 and 1.0 */
- sd[x] = 32768.0 * tmpbuf[x];
- }
-
- if(useplc) plc_rx(&tmp->plc, tmp->buf + tmp->tail, LPC10_SAMPLES_PER_FRAME);
-
- tmp->tail+=LPC10_SAMPLES_PER_FRAME;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- len += LPC10_BYTES_IN_COMPRESSED_FRAME;
- }
- if (len != f->datalen)
- printf("Decoded %d, expected %d\n", len, f->datalen);
- return 0;
-}
-
-static int lintolpc10_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
-{
- /* Just add the frames to our stream */
- /* XXX We should look at how old the rest of our stream is, and if it
- is too old, then we should overwrite it entirely, otherwise we can
- get artifacts of earlier talk that do not belong */
- if (tmp->tail + f->datalen < sizeof(tmp->buf) / 2) {
- memcpy((tmp->buf + tmp->tail), f->data, f->datalen);
- tmp->tail += f->datalen/2;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_frame *lintolpc10_frameout(struct ast_translator_pvt *tmp)
-{
- int x;
- int consumed = 0;
- float tmpbuf[LPC10_SAMPLES_PER_FRAME];
- INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME];
- /* We can't work on anything less than a frame in size */
- if (tmp->tail < LPC10_SAMPLES_PER_FRAME)
- return NULL;
- /* Start with an empty frame */
- tmp->f.samples = 0;
- tmp->f.datalen = 0;
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_LPC10;
- while(tmp->tail >= LPC10_SAMPLES_PER_FRAME) {
- if (tmp->f.datalen + LPC10_BYTES_IN_COMPRESSED_FRAME > sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return NULL;
- }
- /* Encode a frame of data */
- for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++) {
- tmpbuf[x] = (float)tmp->buf[x+consumed] / 32768.0;
- }
- lpc10_encode(tmpbuf, bits, tmp->lpc10.enc);
- build_bits(((unsigned char *)tmp->outbuf) + tmp->f.datalen, bits);
- tmp->f.datalen += LPC10_BYTES_IN_COMPRESSED_FRAME;
- tmp->f.samples += LPC10_SAMPLES_PER_FRAME;
- /* Use one of the two left over bits to record if this is a 22 or 23 ms frame...
- important for IAX use */
- tmp->longer = 1 - tmp->longer;
-#if 0 /* what the heck was this for? */
- ((char *)(tmp->f.data))[consumed - 1] |= tmp->longer;
-#endif
- tmp->tail -= LPC10_SAMPLES_PER_FRAME;
- consumed += LPC10_SAMPLES_PER_FRAME;
- }
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- /* Move the data at the end of the buffer to the front */
- if (tmp->tail)
- memmove(tmp->buf, tmp->buf + consumed, tmp->tail * 2);
-#if 0
- /* Save a sample frame */
- { static int samplefr = 0;
- if (samplefr == 0) {
- int fd;
- fd = open("lpc10.example", O_WRONLY | O_CREAT, 0644);
- write(fd, tmp->f.data, tmp->f.datalen);
- close(fd);
- }
- samplefr++;
- }
-#endif
- return &tmp->f;
-}
-
-static void lpc10_destroy(struct ast_translator_pvt *pvt)
-{
- /* Enc and DEC are both just allocated, so they can be freed */
- free(pvt->lpc10.enc);
- free(pvt);
- localusecnt--;
-}
-
-static struct ast_translator lpc10tolin =
- { "lpc10tolin",
- AST_FORMAT_LPC10, AST_FORMAT_SLINEAR,
- lpc10_dec_new,
- lpc10tolin_framein,
- lpc10tolin_frameout,
- lpc10_destroy,
- lpc10tolin_sample
- };
-
-static struct ast_translator lintolpc10 =
- { "lintolpc10",
- AST_FORMAT_SLINEAR, AST_FORMAT_LPC10,
- lpc10_enc_new,
- lintolpc10_framein,
- lintolpc10_frameout,
- lpc10_destroy,
- lintolpc10_sample
- };
-
-static void parse_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
- if ((cfg = ast_config_load("codecs.conf"))) {
- if ((var = ast_variable_browse(cfg, "plc"))) {
- while (var) {
- if (!strcasecmp(var->name, "genericplc")) {
- useplc = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "codec_lpc10: %susing generic PLC\n", useplc ? "" : "not ");
- }
- var = var->next;
- }
- }
- ast_config_destroy(cfg);
- }
-}
-
-int reload(void)
-{
- parse_config();
- return 0;
-}
-
-
-int unload_module(void)
-{
- int res;
- ast_mutex_lock(&localuser_lock);
- res = ast_unregister_translator(&lintolpc10);
- if (!res)
- res = ast_unregister_translator(&lpc10tolin);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock(&localuser_lock);
- return res;
-}
-
-int load_module(void)
-{
- int res;
- parse_config();
- res=ast_register_translator(&lpc10tolin);
- if (!res)
- res=ast_register_translator(&lintolpc10);
- else
- ast_unregister_translator(&lpc10tolin);
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/codec_speex.c b/1.2-netsec/codecs/codec_speex.c
deleted file mode 100644
index 24a6704a9..000000000
--- a/1.2-netsec/codecs/codec_speex.c
+++ /dev/null
@@ -1,613 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Translate between signed linear and Speex (Open Codec)
- *
- * http://www.speex.org
- * \note This work was motivated by Jeremy McNamara
- * hacked to be configurable by anthm and bkw 9/28/2004
- * \ingroup codecs
- */
-
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <stdio.h>
-#include <speex.h>
-
-/* We require a post 1.1.8 version of Speex to enable preprocessing
- and better type handling */
-#ifdef _SPEEX_TYPES_H
-#include <speex/speex_preprocess.h>
-#endif
-
-static int quality = 3;
-static int complexity = 2;
-static int enhancement = 0;
-static int vad = 0;
-static int vbr = 0;
-static float vbr_quality = 4;
-static int abr = 0;
-static int dtx = 0;
-
-static int preproc = 0;
-static int pp_vad = 0;
-static int pp_agc = 0;
-static float pp_agc_level = 8000;
-static int pp_denoise = 0;
-static int pp_dereverb = 0;
-static float pp_dereverb_decay = 0.4;
-static float pp_dereverb_level = 0.3;
-
-#define TYPE_SILENCE 0x2
-#define TYPE_HIGH 0x0
-#define TYPE_LOW 0x1
-#define TYPE_MASK 0x3
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/translate.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-
-/* Sample frame data */
-#include "slin_speex_ex.h"
-#include "speex_slin_ex.h"
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt=0;
-
-static char *tdesc = "Speex/PCM16 (signed linear) Codec Translator";
-
-struct ast_translator_pvt {
- void *speex;
- struct ast_frame f;
- SpeexBits bits;
- int framesize;
- /* Space to build offset */
- char offset[AST_FRIENDLY_OFFSET];
-#ifdef _SPEEX_TYPES_H
- SpeexPreprocessState *pp;
- /* Buffer for our outgoing frame */
- spx_int16_t outbuf[8000];
- /* Enough to store a full second */
- spx_int16_t buf[8000];
-#else
- short outbuf[8000];
- short buf[8000];
-#endif
-
- int tail;
- int silent_state;
-};
-
-#define speex_coder_pvt ast_translator_pvt
-
-static struct ast_translator_pvt *lintospeex_new(void)
-{
- struct speex_coder_pvt *tmp;
- tmp = malloc(sizeof(struct speex_coder_pvt));
- if (tmp) {
- if (!(tmp->speex = speex_encoder_init(&speex_nb_mode))) {
- free(tmp);
- tmp = NULL;
- } else {
- speex_bits_init(&tmp->bits);
- speex_bits_reset(&tmp->bits);
- speex_encoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize);
- speex_encoder_ctl(tmp->speex, SPEEX_SET_COMPLEXITY, &complexity);
-#ifdef _SPEEX_TYPES_H
- if (preproc) {
- tmp->pp = speex_preprocess_state_init(tmp->framesize, 8000);
- speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_VAD, &pp_vad);
- speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC, &pp_agc);
- speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC_LEVEL, &pp_agc_level);
- speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DENOISE, &pp_denoise);
- speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB, &pp_dereverb);
- speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &pp_dereverb_decay);
- speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &pp_dereverb_level);
- }
-#endif
- if (!abr && !vbr) {
- speex_encoder_ctl(tmp->speex, SPEEX_SET_QUALITY, &quality);
- if (vad)
- speex_encoder_ctl(tmp->speex, SPEEX_SET_VAD, &vad);
- }
- if (vbr) {
- speex_encoder_ctl(tmp->speex, SPEEX_SET_VBR, &vbr);
- speex_encoder_ctl(tmp->speex, SPEEX_SET_VBR_QUALITY, &vbr_quality);
- }
- if (abr) {
- speex_encoder_ctl(tmp->speex, SPEEX_SET_ABR, &abr);
- }
- if (dtx)
- speex_encoder_ctl(tmp->speex, SPEEX_SET_DTX, &dtx);
- tmp->tail = 0;
- tmp->silent_state = 0;
- }
- localusecnt++;
- }
- return tmp;
-}
-
-static struct ast_translator_pvt *speextolin_new(void)
-{
- struct speex_coder_pvt *tmp;
- tmp = malloc(sizeof(struct speex_coder_pvt));
- if (tmp) {
- if (!(tmp->speex = speex_decoder_init(&speex_nb_mode))) {
- free(tmp);
- tmp = NULL;
- } else {
- speex_bits_init(&tmp->bits);
- speex_decoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize);
- if (enhancement)
- speex_decoder_ctl(tmp->speex, SPEEX_SET_ENH, &enhancement);
- tmp->tail = 0;
- }
- localusecnt++;
- }
- return tmp;
-}
-
-static struct ast_frame *lintospeex_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = sizeof(slin_speex_ex);
- /* Assume 8000 Hz */
- f.samples = sizeof(slin_speex_ex)/2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = slin_speex_ex;
- return &f;
-}
-
-static struct ast_frame *speextolin_sample(void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SPEEX;
- f.datalen = sizeof(speex_slin_ex);
- /* All frames are 20 ms long */
- f.samples = 160;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = speex_slin_ex;
- return &f;
-}
-
-static struct ast_frame *speextolin_frameout(struct ast_translator_pvt *tmp)
-{
- if (!tmp->tail)
- return NULL;
- /* Signed linear is no particular frame size, so just send whatever
- we have in the buffer in one lump sum */
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SLINEAR;
- tmp->f.datalen = tmp->tail * 2;
- /* Assume 8000 Hz */
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->buf;
- /* Reset tail pointer */
- tmp->tail = 0;
- return &tmp->f;
-}
-
-static int speextolin_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
-{
- /* Assuming there's space left, decode into the current buffer at
- the tail location. Read in as many frames as there are */
- int x;
- int res;
-#ifdef _SPEEX_TYPES_H
- spx_int16_t out[1024];
-#else
- float fout[1024];
-#endif
-
- if (f->datalen == 0) { /* Native PLC interpolation */
- if (tmp->tail + tmp->framesize > sizeof(tmp->buf) / 2) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
-#ifdef _SPEEX_TYPES_H
- speex_decode_int(tmp->speex, NULL, tmp->buf + tmp->tail);
-#else
- speex_decode(tmp->speex, NULL, fout);
- for (x=0;x<tmp->framesize;x++) {
- tmp->buf[tmp->tail + x] = fout[x];
- }
-#endif
- tmp->tail += tmp->framesize;
- return 0;
- }
-
- /* Read in bits */
- speex_bits_read_from(&tmp->bits, f->data, f->datalen);
- for(;;) {
-#ifdef _SPEEX_TYPES_H
- res = speex_decode_int(tmp->speex, &tmp->bits, out);
-#else
- res = speex_decode(tmp->speex, &tmp->bits, fout);
-#endif
- if (res < 0)
- break;
- if (tmp->tail + tmp->framesize < sizeof(tmp->buf) / 2) {
- for (x=0;x<tmp->framesize;x++) {
-#ifdef _SPEEX_TYPES_H
- tmp->buf[tmp->tail + x] = out[x];
-#else
- tmp->buf[tmp->tail + x] = fout[x];
-#endif
- }
- tmp->tail += tmp->framesize;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
-
- }
- return 0;
-}
-
-static int lintospeex_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
-{
- /* Just add the frames to our stream */
- /* XXX We should look at how old the rest of our stream is, and if it
- is too old, then we should overwrite it entirely, otherwise we can
- get artifacts of earlier talk that do not belong */
- if (tmp->tail + f->datalen/2 < sizeof(tmp->buf) / 2) {
- memcpy((tmp->buf + tmp->tail), f->data, f->datalen);
- tmp->tail += f->datalen/2;
- } else {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_frame *lintospeex_frameout(struct ast_translator_pvt *tmp)
-{
-#ifndef _SPEEX_TYPES_H
- float fbuf[1024];
- int x;
-#endif
- int len;
- int y=0;
- int is_speech=1;
- /* We can't work on anything less than a frame in size */
- if (tmp->tail < tmp->framesize)
- return NULL;
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SPEEX;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- speex_bits_reset(&tmp->bits);
- while(tmp->tail >= tmp->framesize) {
-#ifdef _SPEEX_TYPES_H
- /* Preprocess audio */
- if(preproc)
- is_speech = speex_preprocess(tmp->pp, tmp->buf, NULL);
- /* Encode a frame of data */
- if (is_speech) {
- /* If DTX enabled speex_encode returns 0 during silence */
- is_speech = speex_encode_int(tmp->speex, tmp->buf, &tmp->bits) || !dtx;
- } else {
- /* 5 zeros interpreted by Speex as silence (submode 0) */
- speex_bits_pack(&tmp->bits, 0, 5);
- }
-#else
- /* Convert to floating point */
- for (x=0;x<tmp->framesize;x++)
- fbuf[x] = tmp->buf[x];
- /* Encode a frame of data */
- is_speech = speex_encode(tmp->speex, fbuf, &tmp->bits) || !dtx;
-#endif
- /* Assume 8000 Hz -- 20 ms */
- tmp->tail -= tmp->framesize;
- /* Move the data at the end of the buffer to the front */
- if (tmp->tail)
- memmove(tmp->buf, tmp->buf + tmp->framesize, tmp->tail * 2);
- y++;
- }
-
- /* Use AST_FRAME_CNG to signify the start of any silence period */
- if (!is_speech) {
- if (tmp->silent_state) {
- return NULL;
- } else {
- tmp->silent_state = 1;
- speex_bits_reset(&tmp->bits);
- tmp->f.frametype = AST_FRAME_CNG;
- }
- } else {
- tmp->silent_state = 0;
- }
-
- /* Terminate bit stream */
- speex_bits_pack(&tmp->bits, 15, 5);
- len = speex_bits_write(&tmp->bits, (char *)tmp->outbuf, sizeof(tmp->outbuf));
- tmp->f.datalen = len;
- tmp->f.samples = y * 160;
-#if 0
- {
- static int fd = -1;
- if (fd < 0) {
- fd = open("speex.raw", O_WRONLY|O_TRUNC|O_CREAT);
- if (fd > -1) {
- write(fd, tmp->f.data, tmp->f.datalen);
- close(fd);
- }
- }
- }
-#endif
- return &tmp->f;
-}
-
-static void speextolin_destroy(struct ast_translator_pvt *pvt)
-{
- speex_decoder_destroy(pvt->speex);
- speex_bits_destroy(&pvt->bits);
- free(pvt);
- localusecnt--;
-}
-
-static void lintospeex_destroy(struct ast_translator_pvt *pvt)
-{
-#ifdef _SPEEX_TYPES_H
- if (preproc)
- speex_preprocess_state_destroy(pvt->pp);
-#endif
- speex_encoder_destroy(pvt->speex);
- speex_bits_destroy(&pvt->bits);
- free(pvt);
- localusecnt--;
-}
-
-static struct ast_translator speextolin =
- { "speextolin",
- AST_FORMAT_SPEEX, AST_FORMAT_SLINEAR,
- speextolin_new,
- speextolin_framein,
- speextolin_frameout,
- speextolin_destroy,
- speextolin_sample
- };
-
-static struct ast_translator lintospeex =
- { "lintospeex",
- AST_FORMAT_SLINEAR, AST_FORMAT_SPEEX,
- lintospeex_new,
- lintospeex_framein,
- lintospeex_frameout,
- lintospeex_destroy,
- lintospeex_sample
- };
-
-
-static void parse_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
- int res;
- float res_f;
-
- if ((cfg = ast_config_load("codecs.conf"))) {
- if ((var = ast_variable_browse(cfg, "speex"))) {
- while (var) {
- if (!strcasecmp(var->name, "quality")) {
- res = abs(atoi(var->value));
- if (res > -1 && res < 11) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting Quality to %d\n",res);
- ast_mutex_lock(&localuser_lock);
- quality = res;
- ast_mutex_unlock(&localuser_lock);
- } else
- ast_log(LOG_ERROR,"Error Quality must be 0-10\n");
- } else if (!strcasecmp(var->name, "complexity")) {
- res = abs(atoi(var->value));
- if (res > -1 && res < 11) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting Complexity to %d\n",res);
- ast_mutex_lock(&localuser_lock);
- complexity = res;
- ast_mutex_unlock(&localuser_lock);
- } else
- ast_log(LOG_ERROR,"Error! Complexity must be 0-10\n");
- } else if (!strcasecmp(var->name, "vbr_quality")) {
- if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0 && res_f <= 10) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting VBR Quality to %f\n",res_f);
- ast_mutex_lock(&localuser_lock);
- vbr_quality = res_f;
- ast_mutex_unlock(&localuser_lock);
- } else
- ast_log(LOG_ERROR,"Error! VBR Quality must be 0-10\n");
- } else if (!strcasecmp(var->name, "abr_quality")) {
- ast_log(LOG_ERROR,"Error! ABR Quality setting obsolete, set ABR to desired bitrate\n");
- } else if (!strcasecmp(var->name, "enhancement")) {
- ast_mutex_lock(&localuser_lock);
- enhancement = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Perceptual Enhancement Mode. [%s]\n",enhancement ? "on" : "off");
- ast_mutex_unlock(&localuser_lock);
- } else if (!strcasecmp(var->name, "vbr")) {
- ast_mutex_lock(&localuser_lock);
- vbr = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: VBR Mode. [%s]\n",vbr ? "on" : "off");
- ast_mutex_unlock(&localuser_lock);
- } else if (!strcasecmp(var->name, "abr")) {
- res = abs(atoi(var->value));
- if (res >= 0) {
- if (option_verbose > 2) {
- if (res > 0)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting ABR target bitrate to %d\n",res);
- else
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Disabling ABR\n");
- }
- ast_mutex_lock(&localuser_lock);
- abr = res;
- ast_mutex_unlock(&localuser_lock);
- } else
- ast_log(LOG_ERROR,"Error! ABR target bitrate must be >= 0\n");
- } else if (!strcasecmp(var->name, "vad")) {
- ast_mutex_lock(&localuser_lock);
- vad = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: VAD Mode. [%s]\n",vad ? "on" : "off");
- ast_mutex_unlock(&localuser_lock);
- } else if (!strcasecmp(var->name, "dtx")) {
- ast_mutex_lock(&localuser_lock);
- dtx = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: DTX Mode. [%s]\n",dtx ? "on" : "off");
- ast_mutex_unlock(&localuser_lock);
- } else if (!strcasecmp(var->name, "preprocess")) {
- ast_mutex_lock(&localuser_lock);
- preproc = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessing. [%s]\n",preproc ? "on" : "off");
- ast_mutex_unlock(&localuser_lock);
- } else if (!strcasecmp(var->name, "pp_vad")) {
- ast_mutex_lock(&localuser_lock);
- pp_vad = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor VAD. [%s]\n",pp_vad ? "on" : "off");
- ast_mutex_unlock(&localuser_lock);
- } else if (!strcasecmp(var->name, "pp_agc")) {
- ast_mutex_lock(&localuser_lock);
- pp_agc = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor AGC. [%s]\n",pp_agc ? "on" : "off");
- ast_mutex_unlock(&localuser_lock);
- } else if (!strcasecmp(var->name, "pp_agc_level")) {
- if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor AGC Level to %f\n",res_f);
- ast_mutex_lock(&localuser_lock);
- pp_agc_level = res_f;
- ast_mutex_unlock(&localuser_lock);
- } else
- ast_log(LOG_ERROR,"Error! Preprocessor AGC Level must be >= 0\n");
- } else if (!strcasecmp(var->name, "pp_denoise")) {
- ast_mutex_lock(&localuser_lock);
- pp_denoise = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor Denoise. [%s]\n",pp_denoise ? "on" : "off");
- ast_mutex_unlock(&localuser_lock);
- } else if (!strcasecmp(var->name, "pp_dereverb")) {
- ast_mutex_lock(&localuser_lock);
- pp_dereverb = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor Dereverb. [%s]\n",pp_dereverb ? "on" : "off");
- ast_mutex_unlock(&localuser_lock);
- } else if (!strcasecmp(var->name, "pp_dereverb_decay")) {
- if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor Dereverb Decay to %f\n",res_f);
- ast_mutex_lock(&localuser_lock);
- pp_dereverb_decay = res_f;
- ast_mutex_unlock(&localuser_lock);
- } else
- ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Decay must be >= 0\n");
- } else if (!strcasecmp(var->name, "pp_dereverb_level")) {
- if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor Dereverb Level to %f\n",res_f);
- ast_mutex_lock(&localuser_lock);
- pp_dereverb_level = res_f;
- ast_mutex_unlock(&localuser_lock);
- } else
- ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Level must be >= 0\n");
- }
- var = var->next;
- }
- }
- ast_config_destroy(cfg);
- }
-}
-
-int reload(void)
-{
- parse_config();
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
- ast_mutex_lock(&localuser_lock);
- res = ast_unregister_translator(&lintospeex);
- if (!res)
- res = ast_unregister_translator(&speextolin);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock(&localuser_lock);
- return res;
-}
-
-int load_module(void)
-{
- int res;
- parse_config();
- res=ast_register_translator(&speextolin);
- if (!res)
- res=ast_register_translator(&lintospeex);
- else
- ast_unregister_translator(&speextolin);
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/codec_ulaw.c b/1.2-netsec/codecs/codec_ulaw.c
deleted file mode 100644
index 79a1657b9..000000000
--- a/1.2-netsec/codecs/codec_ulaw.c
+++ /dev/null
@@ -1,445 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief codec_ulaw.c - translate between signed linear and ulaw
- *
- * \ingroup codecs
- */
-
-#include <fcntl.h>
-#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/translate.h"
-#include "asterisk/channel.h"
-#include "asterisk/ulaw.h"
-
-#define BUFFER_SIZE 8096 /* size for the translation buffers */
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt = 0;
-
-static char *tdesc = "Mu-law Coder/Decoder";
-
-static int useplc = 0;
-
-/* Sample frame data */
-
-#include "slin_ulaw_ex.h"
-#include "ulaw_slin_ex.h"
-
-/*
- * Private workspace for translating signed linear signals to ulaw.
- */
-
-struct ulaw_encoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
- unsigned char outbuf[BUFFER_SIZE]; /* Encoded ulaw, two nibbles to a word */
- int tail;
-};
-
-/*
- * Private workspace for translating ulaw signals to signed linear.
- */
-
-struct ulaw_decoder_pvt
-{
- struct ast_frame f;
- char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
- short outbuf[BUFFER_SIZE]; /* Decoded signed linear values */
- int tail;
- plc_state_t plc;
-};
-
-/*
- * ulawToLin_New
- * Create a new instance of ulaw_decoder_pvt.
- *
- * Results:
- * Returns a pointer to the new instance.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_translator_pvt *
-ulawtolin_new (void)
-{
- struct ulaw_decoder_pvt *tmp;
- tmp = malloc (sizeof (struct ulaw_decoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- tmp->tail = 0;
- plc_init(&tmp->plc);
- localusecnt++;
- ast_update_use_count ();
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-/*
- * LinToulaw_New
- * Create a new instance of ulaw_encoder_pvt.
- *
- * Results:
- * Returns a pointer to the new instance.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_translator_pvt *
-lintoulaw_new (void)
-{
- struct ulaw_encoder_pvt *tmp;
- tmp = malloc (sizeof (struct ulaw_encoder_pvt));
- if (tmp)
- {
- memset(tmp, 0, sizeof(*tmp));
- localusecnt++;
- ast_update_use_count ();
- tmp->tail = 0;
- }
- return (struct ast_translator_pvt *) tmp;
-}
-
-/*
- * ulawToLin_FrameIn
- * Fill an input buffer with packed 4-bit ulaw values if there is room
- * left.
- *
- * Results:
- * Foo
- *
- * Side effects:
- * tmp->tail is the number of packed values in the buffer.
- */
-
-static int
-ulawtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct ulaw_decoder_pvt *tmp = (struct ulaw_decoder_pvt *) pvt;
- int x;
- unsigned char *b;
-
- if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
- if((tmp->tail + 160) * 2 > sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- if(useplc) {
- plc_fillin(&tmp->plc, tmp->outbuf+tmp->tail, 160);
- tmp->tail += 160;
- }
- return 0;
- }
-
- if ((tmp->tail + f->datalen) * 2 > sizeof(tmp->outbuf)) {
- ast_log(LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
-
- /* Reset ssindex and signal to frame's specified values */
- b = f->data;
- for (x=0;x<f->datalen;x++)
- tmp->outbuf[tmp->tail + x] = AST_MULAW(b[x]);
-
- if(useplc) plc_rx(&tmp->plc, tmp->outbuf+tmp->tail, f->datalen);
-
- tmp->tail += f->datalen;
- return 0;
-}
-
-/*
- * ulawToLin_FrameOut
- * Convert 4-bit ulaw encoded signals to 16-bit signed linear.
- *
- * Results:
- * Converted signals are placed in tmp->f.data, tmp->f.datalen
- * and tmp->f.samples are calculated.
- *
- * Side effects:
- * None.
- */
-
-static struct ast_frame *
-ulawtolin_frameout (struct ast_translator_pvt *pvt)
-{
- struct ulaw_decoder_pvt *tmp = (struct ulaw_decoder_pvt *) pvt;
-
- if (!tmp->tail)
- return NULL;
-
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_SLINEAR;
- tmp->f.datalen = tmp->tail *2;
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->tail = 0;
- return &tmp->f;
-}
-
-/*
- * LinToulaw_FrameIn
- * Fill an input buffer with 16-bit signed linear PCM values.
- *
- * Results:
- * None.
- *
- * Side effects:
- * tmp->tail is number of signal values in the input buffer.
- */
-
-static int
-lintoulaw_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
- struct ulaw_encoder_pvt *tmp = (struct ulaw_encoder_pvt *) pvt;
- int x;
- short *s;
- if (tmp->tail + f->datalen/2 >= sizeof(tmp->outbuf))
- {
- ast_log (LOG_WARNING, "Out of buffer space\n");
- return -1;
- }
- s = f->data;
- for (x=0;x<f->datalen/2;x++)
- tmp->outbuf[x+tmp->tail] = AST_LIN2MU(s[x]);
- tmp->tail += f->datalen/2;
- return 0;
-}
-
-/*
- * LinToulaw_FrameOut
- * Convert a buffer of raw 16-bit signed linear PCM to a buffer
- * of 4-bit ulaw packed two to a byte (Big Endian).
- *
- * Results:
- * Foo
- *
- * Side effects:
- * Leftover inbuf data gets packed, tail gets updated.
- */
-
-static struct ast_frame *
-lintoulaw_frameout (struct ast_translator_pvt *pvt)
-{
- struct ulaw_encoder_pvt *tmp = (struct ulaw_encoder_pvt *) pvt;
-
- if (tmp->tail) {
- tmp->f.frametype = AST_FRAME_VOICE;
- tmp->f.subclass = AST_FORMAT_ULAW;
- tmp->f.samples = tmp->tail;
- tmp->f.mallocd = 0;
- tmp->f.offset = AST_FRIENDLY_OFFSET;
- tmp->f.src = __PRETTY_FUNCTION__;
- tmp->f.data = tmp->outbuf;
- tmp->f.datalen = tmp->tail;
- tmp->tail = 0;
- return &tmp->f;
- } else return NULL;
-}
-
-
-/*
- * ulawToLin_Sample
- */
-
-static struct ast_frame *
-ulawtolin_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_ULAW;
- f.datalen = sizeof (ulaw_slin_ex);
- f.samples = sizeof(ulaw_slin_ex);
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = ulaw_slin_ex;
- return &f;
-}
-
-/*
- * LinToulaw_Sample
- */
-
-static struct ast_frame *
-lintoulaw_sample (void)
-{
- static struct ast_frame f;
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.datalen = sizeof (slin_ulaw_ex);
- /* Assume 8000 Hz */
- f.samples = sizeof (slin_ulaw_ex) / 2;
- f.mallocd = 0;
- f.offset = 0;
- f.src = __PRETTY_FUNCTION__;
- f.data = slin_ulaw_ex;
- return &f;
-}
-
-/*
- * ulaw_Destroy
- * Destroys a private workspace.
- *
- * Results:
- * It's gone!
- *
- * Side effects:
- * None.
- */
-
-static void
-ulaw_destroy (struct ast_translator_pvt *pvt)
-{
- free (pvt);
- localusecnt--;
- ast_update_use_count ();
-}
-
-/*
- * The complete translator for ulawToLin.
- */
-
-static struct ast_translator ulawtolin = {
- "ulawtolin",
- AST_FORMAT_ULAW,
- AST_FORMAT_SLINEAR,
- ulawtolin_new,
- ulawtolin_framein,
- ulawtolin_frameout,
- ulaw_destroy,
- /* NULL */
- ulawtolin_sample
-};
-
-/*
- * The complete translator for LinToulaw.
- */
-
-static struct ast_translator lintoulaw = {
- "lintoulaw",
- AST_FORMAT_SLINEAR,
- AST_FORMAT_ULAW,
- lintoulaw_new,
- lintoulaw_framein,
- lintoulaw_frameout,
- ulaw_destroy,
- /* NULL */
- lintoulaw_sample
-};
-
-static void
-parse_config(void)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
- if ((cfg = ast_config_load("codecs.conf"))) {
- if ((var = ast_variable_browse(cfg, "plc"))) {
- while (var) {
- if (!strcasecmp(var->name, "genericplc")) {
- useplc = ast_true(var->value) ? 1 : 0;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "codec_ulaw: %susing generic PLC\n", useplc ? "" : "not ");
- }
- var = var->next;
- }
- }
- ast_config_destroy(cfg);
- }
-}
-
-int
-reload(void)
-{
- parse_config();
- return 0;
-}
-
-
-int
-unload_module (void)
-{
- int res;
- ast_mutex_lock (&localuser_lock);
- res = ast_unregister_translator (&lintoulaw);
- if (!res)
- res = ast_unregister_translator (&ulawtolin);
- if (localusecnt)
- res = -1;
- ast_mutex_unlock (&localuser_lock);
- return res;
-}
-
-int
-load_module (void)
-{
- int res;
- parse_config();
- res = ast_register_translator (&ulawtolin);
- if (!res)
- res = ast_register_translator (&lintoulaw);
- else
- ast_unregister_translator (&ulawtolin);
- return res;
-}
-
-/*
- * Return a description of this module.
- */
-
-char *
-description (void)
-{
- return tdesc;
-}
-
-int
-usecount (void)
-{
- int res;
- STANDARD_USECOUNT (res);
- return res;
-}
-
-char *
-key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/codecs/g723_slin_ex.h b/1.2-netsec/codecs/g723_slin_ex.h
deleted file mode 100644
index 0bae82d38..000000000
--- a/1.2-netsec/codecs/g723_slin_ex.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*! \file
- * \brief 8-bit raw data
- *
- * Source: g723.example
- *
- * Copyright (C) 1999-2005, Digium, Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char g723_slin_ex[] = {
-0x4c, 0x34, 0xc2, 0xd9, 0x81, 0x80, 0xa8, 0x50, 0xd7, 0x8d,
-0x8, 0x80, 0xf0, 0xb4, 0x40, 0x53, 0xe3, 0xe1, 0x63, 0x4e,
-0x1a, 0x37, 0xd6, 0x0037 };
diff --git a/1.2-netsec/codecs/g726_slin_ex.h b/1.2-netsec/codecs/g726_slin_ex.h
deleted file mode 100644
index 80cbf00f4..000000000
--- a/1.2-netsec/codecs/g726_slin_ex.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*! \file
- * adpcm_slin_ex.h --
- *
- * \brief 4-bit G.726 data, 20 milliseconds worth at 8 kHz.
- *
- * Source: g726.example
- *
- * Copyright (C) 2001-2005, Digium, Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char g726_slin_ex[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
diff --git a/1.2-netsec/codecs/gsm/COPYRIGHT b/1.2-netsec/codecs/gsm/COPYRIGHT
deleted file mode 100644
index eba0e523b..000000000
--- a/1.2-netsec/codecs/gsm/COPYRIGHT
+++ /dev/null
@@ -1,16 +0,0 @@
-Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann,
-Technische Universitaet Berlin
-
-Any use of this software is permitted provided that this notice is not
-removed and that neither the authors nor the Technische Universitaet Berlin
-are deemed to have made any representations as to the suitability of this
-software for any purpose nor are held responsible for any defects of
-this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
-
-As a matter of courtesy, the authors request to be informed about uses
-this software has found, about bugs in this software, and about any
-improvements that may be of general interest.
-
-Berlin, 28.11.1994
-Jutta Degener
-Carsten Bormann
diff --git a/1.2-netsec/codecs/gsm/Makefile b/1.2-netsec/codecs/gsm/Makefile
deleted file mode 100644
index d6eb94bb8..000000000
--- a/1.2-netsec/codecs/gsm/Makefile
+++ /dev/null
@@ -1,583 +0,0 @@
-# Copyright 1992-1996 by Jutta Degener and Carsten Bormann, Technische
-# Universitaet Berlin. See the accompanying file "COPYRIGHT" for
-# details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
-
-# Machine- or installation dependent flags you should configure to port
-
-SASR = -DSASR
-######### Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1)
-
-#MULHACK = -DUSE_FLOAT_MUL
-######### Define this if your host multiplies floats faster than integers,
-######### e.g. on a SPARCstation.
-
-#FAST = -DFAST
-######### Define together with USE_FLOAT_MUL to enable the GSM library's
-######### approximation option for incorrect, but good-enough results.
-
-# LTP_CUT = -DLTP_CUT
-LTP_CUT =
-######### Define to enable the GSM library's long-term correlation
-######### approximation option---faster, but worse; works for
-######### both integer and floating point multiplications.
-######### This flag is still in the experimental stage.
-
-WAV49 = -DWAV49
-#WAV49 =
-######### Define to enable the GSM library's option to pack GSM frames
-######### in the style used by the WAV #49 format. If you want to write
-######### a tool that produces .WAV files which contain GSM-encoded data,
-######### define this, and read about the GSM_OPT_WAV49 option in the
-######### manual page on gsm_option(3).
-
-#K6OPT = -DK6OPT
-#K6OPT =
-######### Define 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. The compile will
-######### probably require gcc.
-
-ifneq (${OSARCH},Darwin)
-ifneq (${OSARCH},SunOS)
-ifneq (${PROC},x86_64)
-ifneq (${PROC},ultrasparc)
-ifneq ($(shell uname -m),ppc)
-ifneq ($(shell uname -m),ppc64)
-ifneq ($(shell uname -m),alpha)
-ifneq ($(shell uname -m),armv4l)
-ifneq (${PROC},sparc64)
-ifneq (${PROC},arm)
-ifneq (${PROC},ppc)
-ifneq (${PROC},ppc64)
-OPTIMIZE+=-march=$(PROC)
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-
-#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
-#This works for even old (2.96) versions of gcc and provides a small boost either way.
-#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
-#So we go lowest common available by gcc and go a step down, still a step up from
-#the default as we now have a better instruction set to work with. - Belgarath
-ifeq (${PROC},ultrasparc)
-OPTIMIZE+=-mcpu=v8 -mtune=$(PROC) -O3
-endif
-
-PG =
-#PG = -g -pg
-######### Profiling flags. If you don't know what that means, leave it blank.
-
-# Choose a compiler. The code works both with ANSI and K&R-C.
-# Use -DNeedFunctionPrototypes to compile with, -UNeedFunctionPrototypes to
-# compile without, function prototypes in the header files.
-#
-# You can use the -DSTUPID_COMPILER to circumvent some compilers'
-# static limits regarding the number of subexpressions in a statement.
-
-# CC = cc
-# CCFLAGS = -c -DSTUPID_COMPILER
-
-# CC = /usr/lang/acc
-# CCFLAGS = -c -O
-
-CC ?= gcc
-CCFLAGS += -c -DNeedFunctionPrototypes=1 -funroll-loops $(OPTIMIZE)
-ifneq ($(findstring CYGWIN,${OSARCH}),CYGWIN)
-CCFLAGS += -fPIC
-endif
-
-
-LD = $(CC)
-
-# LD = gcc
-# LDFLAGS =
-
-
-# If your compiler needs additional flags/libraries, regardless of
-# the source compiled, configure them here.
-
-# CCINC = -I/usr/gnu/lib/gcc-2.1/gcc-lib/sparc-sun-sunos4.1.2/2.1/include
-######### Includes needed by $(CC)
-
-# LDINC = -L/usr/gnu/lib/gcc-2.1/gcc-lib/sparc-sun-sunos4.1.2/2.1
-######### Library paths needed by $(LD)
-
-# LDLIB = -lgcc
-######### Additional libraries needed by $(LD)
-
-
-# Where do you want to install libraries, binaries, a header file
-# and the manual pages?
-#
-# Leave INSTALL_ROOT empty (or just don't execute "make install") to
-# not install gsm and toast outside of this directory.
-
-INSTALL_ROOT =
-
-# Where do you want to install the gsm library, header file, and manpages?
-#
-# Leave GSM_INSTALL_ROOT empty to not install the GSM library outside of
-# this directory.
-
-GSM_INSTALL_ROOT = $(INSTALL_ROOT)
-GSM_INSTALL_LIB = $(GSM_INSTALL_ROOT)/lib
-GSM_INSTALL_INC = $(GSM_INSTALL_ROOT)/inc
-GSM_INSTALL_MAN = $(GSM_INSTALL_ROOT)/man/man3
-
-
-# Where do you want to install the toast binaries and their manpage?
-#
-# Leave TOAST_INSTALL_ROOT empty to not install the toast binaries outside
-# of this directory.
-
-TOAST_INSTALL_ROOT = $(INSTALL_ROOT)
-TOAST_INSTALL_BIN = $(TOAST_INSTALL_ROOT)/bin
-TOAST_INSTALL_MAN = $(TOAST_INSTALL_ROOT)/man/man1
-
-# Other tools
-
-SHELL = /bin/sh
-LN = ln
-BASENAME = basename
-AR = ar
-ARFLAGS = cr
-RMFLAGS = -f
-FIND = find
-COMPRESS = compress
-COMPRESSFLAGS =
-# RANLIB = true
-RANLIB = ranlib
-
-#
-# You shouldn't have to configure below this line if you're porting.
-#
-
-
-# Local Directories
-
-ROOT = .
-ADDTST = $(ROOT)/add-test
-TST = $(ROOT)/tst
-MAN = $(ROOT)/man
-BIN = $(ROOT)/bin
-SRC = $(ROOT)/src
-LIB = $(ROOT)/lib
-TLS = $(ROOT)/tls
-INC = $(ROOT)/inc
-
-# Flags
-
-DEBUG = -DNDEBUG
-######### Remove -DNDEBUG to enable assertions.
-
-CFLAGS += $(PG) $(CCFLAGS) $(SASR) $(DEBUG) $(MULHACK) $(FAST) \
- $(LTP_CUT) $(WAV49) $(K6OPT) $(CCINC) -I$(INC)
-######### It's $(CC) $(CFLAGS)
-
-LFLAGS = $(PG) $(LDFLAGS) $(LDINC)
-######### It's $(LD) $(LFLAGS)
-
-
-# Targets
-
-LIBGSM = $(LIB)/libgsm.a
-LIBGSMSO= $(LIB)/libgsm.so
-
-TOAST = $(BIN)/toast
-UNTOAST = $(BIN)/untoast
-TCAT = $(BIN)/tcat
-
-# Headers
-
-GSM_HEADERS = $(INC)/gsm.h
-
-HEADERS = $(INC)/proto.h \
- $(INC)/unproto.h \
- $(INC)/config.h \
- $(INC)/private.h \
- $(INC)/gsm.h \
- $(INC)/toast.h \
- $(TLS)/taste.h
-
-# Sources
-
-GSM_SOURCES = $(SRC)/add.c \
- $(SRC)/code.c \
- $(SRC)/debug.c \
- $(SRC)/decode.c \
- $(SRC)/long_term.c \
- $(SRC)/lpc.c \
- $(SRC)/preprocess.c \
- $(SRC)/rpe.c \
- $(SRC)/gsm_destroy.c \
- $(SRC)/gsm_decode.c \
- $(SRC)/gsm_encode.c \
- $(SRC)/gsm_explode.c \
- $(SRC)/gsm_implode.c \
- $(SRC)/gsm_create.c \
- $(SRC)/gsm_print.c \
- $(SRC)/gsm_option.c \
- $(SRC)/short_term.c \
- $(SRC)/table.c
-ifeq (${OSARCH},Linux)
-ifneq ($(shell uname -m),x86_64)
-ifneq ($(shell uname -m),ppc)
-ifneq ($(shell uname -m),ppc64)
-ifneq ($(shell uname -m),alpha)
-ifneq ($(shell uname -m),armv4l)
-ifneq ($(shell uname -m),sparc64)
-ifneq (${PROC},arm)
-GSM_SOURCES+= $(SRC)/k6opt.s
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-
-TOAST_SOURCES = $(SRC)/toast.c \
- $(SRC)/toast_lin.c \
- $(SRC)/toast_ulaw.c \
- $(SRC)/toast_alaw.c \
- $(SRC)/toast_audio.c
-
-SOURCES = $(GSM_SOURCES) \
- $(TOAST_SOURCES) \
- $(ADDTST)/add_test.c \
- $(TLS)/sour.c \
- $(TLS)/ginger.c \
- $(TLS)/sour1.dta \
- $(TLS)/sour2.dta \
- $(TLS)/bitter.c \
- $(TLS)/bitter.dta \
- $(TLS)/taste.c \
- $(TLS)/sweet.c \
- $(TST)/cod2lin.c \
- $(TST)/cod2txt.c \
- $(TST)/gsm2cod.c \
- $(TST)/lin2cod.c \
- $(TST)/lin2txt.c
-
-# Object files
-
-GSM_OBJECTS = $(SRC)/add.o \
- $(SRC)/code.o \
- $(SRC)/debug.o \
- $(SRC)/decode.o \
- $(SRC)/long_term.o \
- $(SRC)/lpc.o \
- $(SRC)/preprocess.o \
- $(SRC)/rpe.o \
- $(SRC)/gsm_destroy.o \
- $(SRC)/gsm_decode.o \
- $(SRC)/gsm_encode.o \
- $(SRC)/gsm_explode.o \
- $(SRC)/gsm_implode.o \
- $(SRC)/gsm_create.o \
- $(SRC)/gsm_print.o \
- $(SRC)/gsm_option.o \
- $(SRC)/short_term.o \
- $(SRC)/table.o
-
-ifeq (${OSARCH},Linux)
-ifneq ($(shell uname -m), x86_64)
-ifneq ($(shell uname -m), ppc)
-ifneq ($(shell uname -m), ppc64)
-ifneq ($(shell uname -m), alpha)
-ifneq ($(shell uname -m), sparc64)
-ifneq ($(shell uname -m), armv4l)
-GSM_OBJECTS+= $(SRC)/k6opt.o
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-
-TOAST_OBJECTS = $(SRC)/toast.o \
- $(SRC)/toast_lin.o \
- $(SRC)/toast_ulaw.o \
- $(SRC)/toast_alaw.o \
- $(SRC)/toast_audio.o
-
-OBJECTS = $(GSM_OBJECTS) $(TOAST_OBJECTS)
-
-# Manuals
-
-GSM_MANUALS = $(MAN)/gsm.3 \
- $(MAN)/gsm_explode.3 \
- $(MAN)/gsm_option.3 \
- $(MAN)/gsm_print.3
-
-TOAST_MANUALS = $(MAN)/toast.1
-
-MANUALS = $(GSM_MANUALS) $(TOAST_MANUALS) $(MAN)/bitter.1
-
-# Other stuff in the distribution
-
-STUFF = ChangeLog \
- INSTALL \
- MACHINES \
- MANIFEST \
- Makefile \
- README \
- $(ADDTST)/add_test.dta \
- $(TLS)/bitter.dta \
- $(TST)/run
-
-
-# Install targets
-
-GSM_INSTALL_TARGETS = \
- $(GSM_INSTALL_LIB)/libgsm.a \
- $(GSM_INSTALL_INC)/gsm.h \
- $(GSM_INSTALL_MAN)/gsm.3 \
- $(GSM_INSTALL_MAN)/gsm_explode.3 \
- $(GSM_INSTALL_MAN)/gsm_option.3 \
- $(GSM_INSTALL_MAN)/gsm_print.3
-
-TOAST_INSTALL_TARGETS = \
- $(TOAST_INSTALL_BIN)/toast \
- $(TOAST_INSTALL_BIN)/tcat \
- $(TOAST_INSTALL_BIN)/untoast \
- $(TOAST_INSTALL_MAN)/toast.1
-
-
-# Default rules
-
-.c.o:
- $(CC) $(CFLAGS) $?
- @-mv `$(BASENAME) $@` $@ > /dev/null 2>&1
-
-# Target rules
-
-all: $(LIBGSM) $(LIBGSMSO) $(TOAST) $(TCAT) $(UNTOAST)
- @-echo $(ROOT): Done.
-
-tst: $(TST)/lin2cod $(TST)/cod2lin $(TOAST) $(TST)/test-result
- @-echo tst: Done.
-
-addtst: $(ADDTST)/add $(ADDTST)/add_test.dta
- $(ADDTST)/add < $(ADDTST)/add_test.dta > /dev/null
- @-echo addtst: Done.
-
-misc: $(TLS)/sweet $(TLS)/bitter $(TLS)/sour $(TLS)/ginger \
- $(TST)/lin2txt $(TST)/cod2txt $(TST)/gsm2cod
- @-echo misc: Done.
-
-install: toastinstall gsminstall
- @-echo install: Done.
-
-
-# The basic API: libgsm
-
-$(LIBGSMSO): $(LIB) $(GSM_OBJECTS)
- $(LD) -o $@.1.0.10 -shared -Xlinker -soname -Xlinker libgsm.so.1 $(GSM_OBJECTS) -lc
- ln -fs libgsm.so.1.0.10 lib/libgsm.so.1
- ln -fs libgsm.so.1.0.10 lib/libgsm.so
-
-$(LIBGSM): $(LIB) $(GSM_OBJECTS)
- -rm $(RMFLAGS) $(LIBGSM)
- $(AR) $(ARFLAGS) $(LIBGSM) $(GSM_OBJECTS)
- $(RANLIB) $(LIBGSM)
-
-
-# Toast, Untoast and Tcat -- the compress-like frontends to gsm.
-
-$(TOAST): $(BIN) $(TOAST_OBJECTS) $(LIBGSM)
- $(LD) $(LFLAGS) -o $(TOAST) $(TOAST_OBJECTS) $(LIBGSMSO) $(LDLIB)
-
-$(UNTOAST): $(BIN) $(TOAST)
- -rm $(RMFLAGS) $(UNTOAST)
- $(LN) toast $(UNTOAST)
-
-$(TCAT): $(BIN) $(TOAST)
- -rm $(RMFLAGS) $(TCAT)
- $(LN) toast $(TCAT)
-
-
-# The local bin and lib directories
-
-$(BIN):
- if [ ! -d $(BIN) ] ; then mkdir $(BIN) ; fi
-
-$(LIB):
- if [ ! -d $(LIB) ] ; then mkdir $(LIB) ; fi
-
-
-# Installation
-
-gsminstall:
- -if [ x"$(GSM_INSTALL_ROOT)" != x ] ; then \
- $(MAKE) $(GSM_INSTALL_TARGETS) ; \
- fi
-
-toastinstall:
- -if [ x"$(TOAST_INSTALL_ROOT)" != x ]; then \
- $(MAKE) $(TOAST_INSTALL_TARGETS); \
- fi
-
-gsmuninstall:
- -if [ x"$(GSM_INSTALL_ROOT)" != x ] ; then \
- rm $(RMFLAGS) $(GSM_INSTALL_TARGETS) ; \
- fi
-
-toastuninstall:
- -if [ x"$(TOAST_INSTALL_ROOT)" != x ] ; then \
- rm $(RMFLAGS) $(TOAST_INSTALL_TARGETS); \
- fi
-
-$(TOAST_INSTALL_BIN)/toast: $(TOAST)
- -rm $@
- cp $(TOAST) $@
- chmod 755 $@
-
-$(TOAST_INSTALL_BIN)/untoast: $(TOAST_INSTALL_BIN)/toast
- -rm $@
- ln $? $@
-
-$(TOAST_INSTALL_BIN)/tcat: $(TOAST_INSTALL_BIN)/toast
- -rm $@
- ln $? $@
-
-$(TOAST_INSTALL_MAN)/toast.1: $(MAN)/toast.1
- -rm $@
- cp $? $@
- chmod 444 $@
-
-$(GSM_INSTALL_MAN)/gsm.3: $(MAN)/gsm.3
- -rm $@
- cp $? $@
- chmod 444 $@
-
-$(GSM_INSTALL_MAN)/gsm_option.3: $(MAN)/gsm_option.3
- -rm $@
- cp $? $@
- chmod 444 $@
-
-$(GSM_INSTALL_MAN)/gsm_explode.3: $(MAN)/gsm_explode.3
- -rm $@
- cp $? $@
- chmod 444 $@
-
-$(GSM_INSTALL_MAN)/gsm_print.3: $(MAN)/gsm_print.3
- -rm $@
- cp $? $@
- chmod 444 $@
-
-$(GSM_INSTALL_INC)/gsm.h: $(INC)/gsm.h
- -rm $@
- cp $? $@
- chmod 444 $@
-
-$(GSM_INSTALL_LIB)/libgsm.a: $(LIBGSM)
- -rm $@
- cp $? $@
- chmod 444 $@
-
-
-# Distribution
-
-dist: gsm-1.0.tar.Z
- @echo dist: Done.
-
-gsm-1.0.tar.Z: $(STUFF) $(SOURCES) $(HEADERS) $(MANUALS)
- ( cd $(ROOT)/..; \
- tar cvf - `cat $(ROOT)/gsm-1.0/MANIFEST \
- | sed '/^#/d'` \
- ) | $(COMPRESS) $(COMPRESSFLAGS) > $(ROOT)/gsm-1.0.tar.Z
-
-# Clean
-
-uninstall: toastuninstall gsmuninstall
- @-echo uninstall: Done.
-
-semi-clean:
- -rm $(RMFLAGS) */*.o \
- $(TST)/lin2cod $(TST)/lin2txt \
- $(TST)/cod2lin $(TST)/cod2txt \
- $(TST)/gsm2cod \
- $(TST)/*.*.*
- -$(FIND) . \( -name core -o -name foo \) \
- -print | xargs rm $(RMFLAGS)
-
-clean: semi-clean
- -rm $(RMFLAGS) $(LIBGSM) $(ADDTST)/add \
- $(TOAST) $(TCAT) $(UNTOAST) \
- $(ROOT)/gsm-1.0.tar.Z
- rm -rf lib
-
-# Two tools that helped me generate gsm_encode.c and gsm_decode.c,
-# but aren't generally needed to port this.
-
-$(TLS)/sweet: $(TLS)/sweet.o $(TLS)/taste.o
- $(LD) $(LFLAGS) -o $(TLS)/sweet \
- $(TLS)/sweet.o $(TLS)/taste.o $(LDLIB)
-
-$(TLS)/bitter: $(TLS)/bitter.o $(TLS)/taste.o
- $(LD) $(LFLAGS) -o $(TLS)/bitter \
- $(TLS)/bitter.o $(TLS)/taste.o $(LDLIB)
-
-# A version of the same family that Jeff Chilton used to implement
-# the WAV #49 GSM format.
-
-$(TLS)/ginger: $(TLS)/ginger.o $(TLS)/taste.o
- $(LD) $(LFLAGS) -o $(TLS)/ginger \
- $(TLS)/ginger.o $(TLS)/taste.o $(LDLIB)
-
-$(TLS)/sour: $(TLS)/sour.o $(TLS)/taste.o
- $(LD) $(LFLAGS) -o $(TLS)/sour \
- $(TLS)/sour.o $(TLS)/taste.o $(LDLIB)
-
-# Run $(ADDTST)/add < $(ADDTST)/add_test.dta to make sure the
-# basic arithmetic functions work as intended.
-
-$(ADDTST)/add: $(ADDTST)/add_test.o
- $(LD) $(LFLAGS) -o $(ADDTST)/add $(ADDTST)/add_test.o $(LDLIB)
-
-
-# Various conversion programs between linear, text, .gsm and the code
-# format used by the tests we ran (.cod). We paid for the test data,
-# so I guess we can't just provide them with this package. Still,
-# if you happen to have them lying around, here's the code.
-#
-# You can use gsm2cod | cod2txt independently to look at what's
-# coded inside the compressed frames, although this shouldn't be
-# hard to roll on your own using the gsm_print() function from
-# the API.
-
-
-$(TST)/test-result: $(TST)/lin2cod $(TST)/cod2lin $(TOAST) $(TST)/run
- ( cd $(TST); ./run )
-
-$(TST)/lin2txt: $(TST)/lin2txt.o $(LIBGSM)
- $(LD) $(LFLAGS) -o $(TST)/lin2txt \
- $(TST)/lin2txt.o $(LIBGSM) $(LDLIB)
-
-$(TST)/lin2cod: $(TST)/lin2cod.o $(LIBGSM)
- $(LD) $(LFLAGS) -o $(TST)/lin2cod \
- $(TST)/lin2cod.o $(LIBGSM) $(LDLIB)
-
-$(TST)/gsm2cod: $(TST)/gsm2cod.o $(LIBGSM)
- $(LD) $(LFLAGS) -o $(TST)/gsm2cod \
- $(TST)/gsm2cod.o $(LIBGSM) $(LDLIB)
-
-$(TST)/cod2txt: $(TST)/cod2txt.o $(LIBGSM)
- $(LD) $(LFLAGS) -o $(TST)/cod2txt \
- $(TST)/cod2txt.o $(LIBGSM) $(LDLIB)
-
-$(TST)/cod2lin: $(TST)/cod2lin.o $(LIBGSM)
- $(LD) $(LFLAGS) -o $(TST)/cod2lin \
- $(TST)/cod2lin.o $(LIBGSM) $(LDLIB)
diff --git a/1.2-netsec/codecs/gsm/README b/1.2-netsec/codecs/gsm/README
deleted file mode 100644
index cb6af85cf..000000000
--- a/1.2-netsec/codecs/gsm/README
+++ /dev/null
@@ -1,37 +0,0 @@
-
-GSM 06.10 13 kbit/s RPE/LTP speech compression available
---------------------------------------------------------
-
-The Communications and Operating Systems Research Group (KBS) at the
-Technische Universitaet Berlin is currently working on a set of
-UNIX-based tools for computer-mediated telecooperation that will be
-made freely available.
-
-As part of this effort we are publishing an implementation of the
-European GSM 06.10 provisional standard for full-rate speech
-transcoding, prI-ETS 300 036, which uses RPE/LTP (residual pulse
-excitation/long term prediction) coding at 13 kbit/s.
-
-GSM 06.10 compresses frames of 160 13-bit samples (8 kHz sampling
-rate, i.e. a frame rate of 50 Hz) into 260 bits; for compatibility
-with typical UNIX applications, our implementation turns frames of 160
-16-bit linear samples into 33-byte frames (1650 Bytes/s).
-The quality of the algorithm is good enough for reliable speaker
-recognition; even music often survives transcoding in recognizable
-form (given the bandwidth limitations of 8 kHz sampling rate).
-
-The interfaces offered are a front end modelled after compress(1), and
-a library API. Compression and decompression run faster than realtime
-on most SPARCstations. The implementation has been verified against the
-ETSI standard test patterns.
-
-Jutta Degener (jutta@cs.tu-berlin.de)
-Carsten Bormann (cabo@cs.tu-berlin.de)
-
-Communications and Operating Systems Research Group, TU Berlin
-Fax: +49.30.31425156, Phone: +49.30.31424315
-
---
-Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
-Universitaet Berlin. See the accompanying file "COPYRIGHT" for
-details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
diff --git a/1.2-netsec/codecs/gsm/inc/config.h b/1.2-netsec/codecs/gsm/inc/config.h
deleted file mode 100644
index e0b0632be..000000000
--- a/1.2-netsec/codecs/gsm/inc/config.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/*$Header$*/
-
-#ifndef CONFIG_H
-#define CONFIG_H
-
-#if 0
-efine SIGHANDLER_T int /* signal handlers are void */
-efine HAS_SYSV_SIGNAL 1 /* sigs not blocked/reset? */
-#endif
-
-#define HAS_STDLIB_H 1 /* /usr/include/stdlib.h */
-#if 0
-efine HAS_LIMITS_H 1 /* /usr/include/limits.h */
-#endif
-#define HAS_FCNTL_H 1 /* /usr/include/fcntl.h */
-#if 0
-efine HAS_ERRNO_DECL 1 /* errno.h declares errno */
-#endif
-
-#define HAS_FSTAT 1 /* fstat syscall */
-#define HAS_FCHMOD 1 /* fchmod syscall */
-#define HAS_CHMOD 1 /* chmod syscall */
-#define HAS_FCHOWN 1 /* fchown syscall */
-#define HAS_CHOWN 1 /* chown syscall */
-#if 0
-efine HAS__FSETMODE 1 /* _fsetmode -- set file mode */
-#endif
-
-#define HAS_STRING_H 1 /* /usr/include/string.h */
-#if 0
-efine HAS_STRINGS_H 1 /* /usr/include/strings.h */
-#endif
-
-#define HAS_UNISTD_H 1 /* /usr/include/unistd.h */
-#define HAS_UTIME 1 /* POSIX utime(path, times) */
-#if 0
-efine HAS_UTIMES 1 /* use utimes() syscall instead */
-#endif
-#define HAS_UTIME_H 1 /* UTIME header file */
-#if 0
-efine HAS_UTIMBUF 1 /* struct utimbuf */
-efine HAS_UTIMEUSEC 1 /* microseconds in utimbuf? */
-#endif
-
-#endif /* CONFIG_H */
diff --git a/1.2-netsec/codecs/gsm/inc/gsm.h b/1.2-netsec/codecs/gsm/inc/gsm.h
deleted file mode 100644
index 81065e512..000000000
--- a/1.2-netsec/codecs/gsm/inc/gsm.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/*$Header$*/
-
-#ifndef GSM_H
-#define GSM_H
-
-#ifdef __cplusplus
-# define NeedFunctionPrototypes 1
-#endif
-
-#if __STDC__
-# define NeedFunctionPrototypes 1
-#endif
-
-#ifdef _NO_PROTO
-# undef NeedFunctionPrototypes
-#endif
-
-#ifdef NeedFunctionPrototypes
-# include <stdio.h> /* for FILE * */
-#endif
-
-#undef GSM_P
-#if NeedFunctionPrototypes
-# define GSM_P( protos ) protos
-#else
-# define GSM_P( protos ) ( /* protos */ )
-#endif
-
-/*
- * Interface
- */
-
-typedef struct gsm_state * gsm;
-typedef short gsm_signal; /* signed 16 bit */
-typedef unsigned char gsm_byte;
-typedef gsm_byte gsm_frame[33]; /* 33 * 8 bits */
-
-#define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */
-
-#define GSM_PATCHLEVEL 10
-#define GSM_MINOR 0
-#define GSM_MAJOR 1
-
-#define GSM_OPT_VERBOSE 1
-#define GSM_OPT_FAST 2
-#define GSM_OPT_LTP_CUT 3
-#define GSM_OPT_WAV49 4
-#define GSM_OPT_FRAME_INDEX 5
-#define GSM_OPT_FRAME_CHAIN 6
-
-extern gsm gsm_create GSM_P((void));
-extern void gsm_destroy GSM_P((gsm));
-
-extern int gsm_print GSM_P((FILE *, gsm, gsm_byte *));
-extern int gsm_option GSM_P((gsm, int, int *));
-
-extern void gsm_encode GSM_P((gsm, gsm_signal *, gsm_byte *));
-extern int gsm_decode GSM_P((gsm, gsm_byte *, gsm_signal *));
-
-extern int gsm_explode GSM_P((gsm, gsm_byte *, gsm_signal *));
-extern void gsm_implode GSM_P((gsm, gsm_signal *, gsm_byte *));
-
-#undef GSM_P
-
-#endif /* GSM_H */
diff --git a/1.2-netsec/codecs/gsm/inc/private.h b/1.2-netsec/codecs/gsm/inc/private.h
deleted file mode 100644
index b7115ae51..000000000
--- a/1.2-netsec/codecs/gsm/inc/private.h
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/*$Header$*/
-
-#ifndef PRIVATE_H
-#define PRIVATE_H
-
-typedef short word; /* 16 bit signed int */
-typedef long longword; /* 32 bit signed int */
-
-typedef unsigned short uword; /* unsigned word */
-typedef unsigned long ulongword; /* unsigned longword */
-
-struct gsm_state {
-
- word dp0[ 280 ];
-
- word z1; /* preprocessing.c, Offset_com. */
- longword L_z2; /* Offset_com. */
- int mp; /* Preemphasis */
-
- word u[8]; /* short_term_aly_filter.c */
- word LARpp[2][8]; /* */
- word j; /* */
-
- word ltp_cut; /* long_term.c, LTP crosscorr. */
- word nrp; /* 40 */ /* long_term.c, synthesis */
- word v[9]; /* short_term.c, synthesis */
- word msr; /* decoder.c, Postprocessing */
-
- char verbose; /* only used if !NDEBUG */
- char fast; /* only used if FAST */
-
- char wav_fmt; /* only used if WAV49 defined */
- unsigned char frame_index; /* odd/even chaining */
- unsigned char frame_chain; /* half-byte to carry forward */
-};
-
-
-#define MIN_WORD (-32767 - 1)
-#define MAX_WORD 32767
-
-#define MIN_LONGWORD (-2147483647 - 1)
-#define MAX_LONGWORD 2147483647
-
-#ifdef SASR /* flag: >> is a signed arithmetic shift right */
-#undef SASR
-#define SASR(x, by) ((x) >> (by))
-#else
-#define SASR(x, by) ((x) >= 0 ? (x) >> (by) : (~(-((x) + 1) >> (by))))
-#endif /* SASR */
-
-#include "proto.h"
-
-/*
- * Prototypes from add.c
- */
-extern word gsm_mult P((word a, word b));
-extern longword gsm_L_mult P((word a, word b));
-extern word gsm_mult_r P((word a, word b));
-
-extern word gsm_div P((word num, word denum));
-
-extern word gsm_add P(( word a, word b ));
-extern longword gsm_L_add P(( longword a, longword b ));
-
-extern word gsm_sub P((word a, word b));
-extern longword gsm_L_sub P((longword a, longword b));
-
-extern word gsm_abs P((word a));
-
-extern word gsm_norm P(( longword a ));
-
-extern longword gsm_L_asl P((longword a, int n));
-extern word gsm_asl P((word a, int n));
-
-extern longword gsm_L_asr P((longword a, int n));
-extern word gsm_asr P((word a, int n));
-
-/*
- * Inlined functions from add.h
- */
-
-/*
- * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *) \
- * (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15))
- */
-#define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \
- (SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))
-
-# define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \
- (SASR( ((longword)(a) * (longword)(b)), 15 ))
-
-# define GSM_L_MULT(a, b) /* word a, word b */ \
- (((longword)(a) * (longword)(b)) << 1)
-
-#if defined(__GNUC__) && defined(__i386__)
-
-static __inline__ int GSM_L_ADD(int a, int b)
-{
- __asm__ __volatile__(
-
- "addl %2,%0; jno 0f; movl $0x7fffffff,%0; adcl $0,%0; 0:"
- : "=r" (a)
- : "0" (a), "ir" (b)
- : "cc"
- );
- return(a);
-}
-
-static __inline__ short GSM_ADD(short a, short b)
-{
- __asm__ __volatile__(
- "addw %2,%0; jno 0f; movw $0x7fff,%0; adcw $0,%0; 0:"
- : "=r" (a)
- : "0" (a), "ir" (b)
- : "cc"
- );
- return(a);
-}
-
-static __inline__ short GSM_SUB(short a, short b)
-{
- __asm__ __volatile__(
- "subw %2,%0; jno 0f; movw $0x7fff,%0; adcw $0,%0; 0:"
- : "=r" (a)
- : "0" (a), "ir" (b)
- : "cc"
- );
- return(a);
-}
-
-#else
-
-# define GSM_L_ADD(a, b) \
- ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \
- : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
- >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \
- : ((b) <= 0 ? (a) + (b) \
- : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \
- ? MAX_LONGWORD : utmp))
-
-/*
- * # define GSM_ADD(a, b) \
- * ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \
- * ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
- */
-/* Nonportable, but faster: */
-
-# define GSM_ADD(a, b) ({ \
- register longword ltmp; \
- ltmp = (longword) (a) + (longword) (b); \
- ((ulongword) (ltmp - MIN_WORD) > MAX_WORD - MIN_WORD ? \
- (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp); \
- })
-
-#define GSM_SUB(a, b) ({ \
- register longword ltmp; \
- ltmp = (longword) (a) - (longword) (b); \
- (ltmp >= MAX_WORD ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp); \
- })
-
-#endif
-
-# define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
-
-/* Use these if necessary:
-
-# define GSM_MULT_R(a, b) gsm_mult_r(a, b)
-# define GSM_MULT(a, b) gsm_mult(a, b)
-# define GSM_L_MULT(a, b) gsm_L_mult(a, b)
-
-# define GSM_L_ADD(a, b) gsm_L_add(a, b)
-# define GSM_ADD(a, b) gsm_add(a, b)
-# define GSM_SUB(a, b) gsm_sub(a, b)
-
-# define GSM_ABS(a) gsm_abs(a)
-
-*/
-
-/*
- * More prototypes from implementations..
- */
-extern void Gsm_Coder P((
- struct gsm_state * S,
- word * s, /* [0..159] samples IN */
- word * LARc, /* [0..7] LAR coefficients OUT */
- word * Nc, /* [0..3] LTP lag OUT */
- word * bc, /* [0..3] coded LTP gain OUT */
- word * Mc, /* [0..3] RPE grid selection OUT */
- word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
- word * xMc /* [13*4] normalized RPE samples OUT */));
-
-extern void Gsm_Long_Term_Predictor P(( /* 4x for 160 samples */
- struct gsm_state * S,
- word * d, /* [0..39] residual signal IN */
- word * dp, /* [-120..-1] d' IN */
- word * e, /* [0..40] OUT */
- word * dpp, /* [0..40] OUT */
- word * Nc, /* correlation lag OUT */
- word * bc /* gain factor OUT */));
-
-extern void Gsm_LPC_Analysis P((
- struct gsm_state * S,
- word * s, /* 0..159 signals IN/OUT */
- word * LARc)); /* 0..7 LARc's OUT */
-
-extern void Gsm_Preprocess P((
- struct gsm_state * S,
- word * s, word * so));
-
-extern void Gsm_Encoding P((
- struct gsm_state * S,
- word * e,
- word * ep,
- word * xmaxc,
- word * Mc,
- word * xMc));
-
-extern void Gsm_Short_Term_Analysis_Filter P((
- struct gsm_state * S,
- word * LARc, /* coded log area ratio [0..7] IN */
- word * d /* st res. signal [0..159] IN/OUT */));
-
-extern void Gsm_Decoder P((
- struct gsm_state * S,
- word * LARcr, /* [0..7] IN */
- word * Ncr, /* [0..3] IN */
- word * bcr, /* [0..3] IN */
- word * Mcr, /* [0..3] IN */
- word * xmaxcr, /* [0..3] IN */
- word * xMcr, /* [0..13*4] IN */
- word * s)); /* [0..159] OUT */
-
-extern void Gsm_Decoding P((
- struct gsm_state * S,
- word xmaxcr,
- word Mcr,
- word * xMcr, /* [0..12] IN */
- word * erp)); /* [0..39] OUT */
-
-extern void Gsm_Long_Term_Synthesis_Filtering P((
- struct gsm_state* S,
- word Ncr,
- word bcr,
- word * erp, /* [0..39] IN */
- word * drp)); /* [-120..-1] IN, [0..40] OUT */
-
-void Gsm_RPE_Decoding P((
- struct gsm_state *S,
- word xmaxcr,
- word Mcr,
- word * xMcr, /* [0..12], 3 bits IN */
- word * erp)); /* [0..39] OUT */
-
-void Gsm_RPE_Encoding P((
- struct gsm_state * S,
- word * e, /* -5..-1][0..39][40..44 IN/OUT */
- word * xmaxc, /* OUT */
- word * Mc, /* OUT */
- word * xMc)); /* [0..12] OUT */
-
-extern void Gsm_Short_Term_Synthesis_Filter P((
- struct gsm_state * S,
- word * LARcr, /* log area ratios [0..7] IN */
- word * drp, /* received d [0...39] IN */
- word * s)); /* signal s [0..159] OUT */
-
-extern void Gsm_Update_of_reconstructed_short_time_residual_signal P((
- word * dpp, /* [0...39] IN */
- word * ep, /* [0...39] IN */
- word * dp)); /* [-120...-1] IN/OUT */
-
-/*
- * Tables from table.c
- */
-#ifndef GSM_TABLE_C
-
-extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8];
-extern word gsm_INVA[8];
-extern word gsm_DLB[4], gsm_QLB[4];
-extern word gsm_H[11];
-extern word gsm_NRFAC[8];
-extern word gsm_FAC[8];
-
-#endif /* GSM_TABLE_C */
-
-/*
- * Debugging
- */
-#ifdef NDEBUG
-
-# define gsm_debug_words(a, b, c, d) /* nil */
-# define gsm_debug_longwords(a, b, c, d) /* nil */
-# define gsm_debug_word(a, b) /* nil */
-# define gsm_debug_longword(a, b) /* nil */
-
-#else /* !NDEBUG => DEBUG */
-
- extern void gsm_debug_words P((char * name, int, int, word *));
- extern void gsm_debug_longwords P((char * name, int, int, longword *));
- extern void gsm_debug_longword P((char * name, longword));
- extern void gsm_debug_word P((char * name, word));
-
-#endif /* !NDEBUG */
-
-#include "unproto.h"
-
-#endif /* PRIVATE_H */
diff --git a/1.2-netsec/codecs/gsm/inc/proto.h b/1.2-netsec/codecs/gsm/inc/proto.h
deleted file mode 100644
index 87cf05e8a..000000000
--- a/1.2-netsec/codecs/gsm/inc/proto.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/*$Header$*/
-
-#ifndef PROTO_H
-#define PROTO_H
-
-#if __cplusplus
-# define NeedFunctionPrototypes 1
-#endif
-
-#if __STDC__
-# define NeedFunctionPrototypes 1
-#endif
-
-#ifdef _NO_PROTO
-# undef NeedFunctionPrototypes
-#endif
-
-#undef P /* gnu stdio.h actually defines this... */
-#undef P0
-#undef P1
-#undef P2
-#undef P3
-#undef P4
-#undef P5
-#undef P6
-#undef P7
-#undef P8
-
-#if NeedFunctionPrototypes
-
-# define P( protos ) protos
-
-# define P0() (void)
-# define P1(x, a) (a)
-# define P2(x, a, b) (a, b)
-# define P3(x, a, b, c) (a, b, c)
-# define P4(x, a, b, c, d) (a, b, c, d)
-# define P5(x, a, b, c, d, e) (a, b, c, d, e)
-# define P6(x, a, b, c, d, e, f) (a, b, c, d, e, f)
-# define P7(x, a, b, c, d, e, f, g) (a, b, c, d, e, f, g)
-# define P8(x, a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h)
-
-#else /* !NeedFunctionPrototypes */
-
-# define P( protos ) ( /* protos */ )
-
-# define P0() ()
-# define P1(x, a) x a;
-# define P2(x, a, b) x a; b;
-# define P3(x, a, b, c) x a; b; c;
-# define P4(x, a, b, c, d) x a; b; c; d;
-# define P5(x, a, b, c, d, e) x a; b; c; d; e;
-# define P6(x, a, b, c, d, e, f) x a; b; c; d; e; f;
-# define P7(x, a, b, c, d, e, f, g) x a; b; c; d; e; f; g;
-# define P8(x, a, b, c, d, e, f, g, h) x a; b; c; d; e; f; g; h;
-
-#endif /* !NeedFunctionPrototypes */
-
-#endif /* PROTO_H */
diff --git a/1.2-netsec/codecs/gsm/inc/unproto.h b/1.2-netsec/codecs/gsm/inc/unproto.h
deleted file mode 100644
index ccd565109..000000000
--- a/1.2-netsec/codecs/gsm/inc/unproto.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/*$Header$*/
-
-#ifdef PROTO_H /* sic */
-#undef PROTO_H
-
-#undef P
-#undef P0
-#undef P1
-#undef P2
-#undef P3
-#undef P4
-#undef P5
-#undef P6
-#undef P7
-#undef P8
-
-#endif /* PROTO_H */
diff --git a/1.2-netsec/codecs/gsm/src/add.c b/1.2-netsec/codecs/gsm/src/add.c
deleted file mode 100644
index 21ccfabe7..000000000
--- a/1.2-netsec/codecs/gsm/src/add.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-/*
- * See private.h for the more commonly used macro versions.
- */
-
-#include <stdio.h>
-#include <assert.h>
-
-#include "private.h"
-#include "gsm.h"
-#include "proto.h"
-
-#define saturate(x) \
- ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x))
-
-word gsm_add P2((a,b), word a, word b)
-{
- longword sum = (longword)a + (longword)b;
- return saturate(sum);
-}
-
-word gsm_sub P2((a,b), word a, word b)
-{
- longword diff = (longword)a - (longword)b;
- return saturate(diff);
-}
-
-word gsm_mult P2((a,b), word a, word b)
-{
- if (a == MIN_WORD && b == MIN_WORD) return MAX_WORD;
- else return SASR( (longword)a * (longword)b, 15 );
-}
-
-word gsm_mult_r P2((a,b), word a, word b)
-{
- if (b == MIN_WORD && a == MIN_WORD) return MAX_WORD;
- else {
- longword prod = (longword)a * (longword)b + 16384;
- prod >>= 15;
- return prod & 0xFFFF;
- }
-}
-
-word gsm_abs P1((a), word a)
-{
- return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a;
-}
-
-longword gsm_L_mult P2((a,b),word a, word b)
-{
- assert( a != MIN_WORD || b != MIN_WORD );
- return ((longword)a * (longword)b) << 1;
-}
-
-longword gsm_L_add P2((a,b), longword a, longword b)
-{
- if (a < 0) {
- if (b >= 0) return a + b;
- else {
- ulongword A = (ulongword)-(a + 1) + (ulongword)-(b + 1);
- return A >= MAX_LONGWORD ? MIN_LONGWORD :-(longword)A-2;
- }
- }
- else if (b <= 0) return a + b;
- else {
- ulongword A = (ulongword)a + (ulongword)b;
- return A > MAX_LONGWORD ? MAX_LONGWORD : A;
- }
-}
-
-longword gsm_L_sub P2((a,b), longword a, longword b)
-{
- if (a >= 0) {
- if (b >= 0) return a - b;
- else {
- /* a>=0, b<0 */
-
- ulongword A = (ulongword)a + -(b + 1);
- return A >= MAX_LONGWORD ? MAX_LONGWORD : (A + 1);
- }
- }
- else if (b <= 0) return a - b;
- else {
- /* a<0, b>0 */
-
- ulongword A = (ulongword)-(a + 1) + b;
- return A >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)A - 1;
- }
-}
-
-static unsigned char const bitoff[ 256 ] = {
- 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-word gsm_norm P1((a), longword a )
-/*
- * the number of left shifts needed to normalize the 32 bit
- * variable L_var1 for positive values on the interval
- *
- * with minimum of
- * minimum of 1073741824 (01000000000000000000000000000000) and
- * maximum of 2147483647 (01111111111111111111111111111111)
- *
- *
- * and for negative values on the interval with
- * minimum of -2147483648 (-10000000000000000000000000000000) and
- * maximum of -1073741824 ( -1000000000000000000000000000000).
- *
- * in order to normalize the result, the following
- * operation must be done: L_norm_var1 = L_var1 << norm( L_var1 );
- *
- * (That's 'ffs', only from the left, not the right..)
- */
-{
- assert(a != 0);
-
- if (a < 0) {
- if (a <= -1073741824) return 0;
- a = ~a;
- }
-
- return a & 0xffff0000
- ? ( a & 0xff000000
- ? -1 + bitoff[ 0xFF & (a >> 24) ]
- : 7 + bitoff[ 0xFF & (a >> 16) ] )
- : ( a & 0xff00
- ? 15 + bitoff[ 0xFF & (a >> 8) ]
- : 23 + bitoff[ 0xFF & a ] );
-}
-
-longword gsm_L_asl P2((a,n), longword a, int n)
-{
- if (n >= 32) return 0;
- if (n <= -32) return -(a < 0);
- if (n < 0) return gsm_L_asr(a, -n);
- return a << n;
-}
-
-word gsm_asl P2((a,n), word a, int n)
-{
- if (n >= 16) return 0;
- if (n <= -16) return -(a < 0);
- if (n < 0) return gsm_asr(a, -n);
- return a << n;
-}
-
-longword gsm_L_asr P2((a,n), longword a, int n)
-{
- if (n >= 32) return -(a < 0);
- if (n <= -32) return 0;
- if (n < 0) return a << -n;
-
-# ifdef SASR
- return a >> n;
-# else
- if (a >= 0) return a >> n;
- else return -(longword)( -(ulongword)a >> n );
-# endif
-}
-
-word gsm_asr P2((a,n), word a, int n)
-{
- if (n >= 16) return -(a < 0);
- if (n <= -16) return 0;
- if (n < 0) return a << -n;
-
-# ifdef SASR
- return a >> n;
-# else
- if (a >= 0) return a >> n;
- else return -(word)( -(uword)a >> n );
-# endif
-}
-
-/*
- * (From p. 46, end of section 4.2.5)
- *
- * NOTE: The following lines gives [sic] one correct implementation
- * of the div(num, denum) arithmetic operation. Compute div
- * which is the integer division of num by denum: with denum
- * >= num > 0
- */
-
-word gsm_div P2((num,denum), word num, word denum)
-{
- longword L_num = num;
- longword L_denum = denum;
- word div = 0;
- int k = 15;
-
- /* The parameter num sometimes becomes zero.
- * Although this is explicitly guarded against in 4.2.5,
- * we assume that the result should then be zero as well.
- */
-
- /* assert(num != 0); */
-
- assert(num >= 0 && denum >= num);
- if (num == 0)
- return 0;
-
- while (k--) {
- div <<= 1;
- L_num <<= 1;
-
- if (L_num >= L_denum) {
- L_num -= L_denum;
- div++;
- }
- }
-
- return div;
-}
diff --git a/1.2-netsec/codecs/gsm/src/code.c b/1.2-netsec/codecs/gsm/src/code.c
deleted file mode 100644
index 6358330e5..000000000
--- a/1.2-netsec/codecs/gsm/src/code.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include "config.h"
-
-#ifdef HAS_STRING_H
-#include <string.h>
-#else
-# include "proto.h"
- extern char * memcpy P((char *, char *, int));
-#endif
-
-#include "private.h"
-#include "gsm.h"
-#include "proto.h"
-
-/*
- * 4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER
- */
-
-void Gsm_Coder P8((S,s,LARc,Nc,bc,Mc,xmaxc,xMc),
-
- struct gsm_state * S,
-
- word * s, /* [0..159] samples IN */
-
-/*
- * The RPE-LTD coder works on a frame by frame basis. The length of
- * the frame is equal to 160 samples. Some computations are done
- * once per frame to produce at the output of the coder the
- * LARc[1..8] parameters which are the coded LAR coefficients and
- * also to realize the inverse filtering operation for the entire
- * frame (160 samples of signal d[0..159]). These parts produce at
- * the output of the coder:
- */
-
- word * LARc, /* [0..7] LAR coefficients OUT */
-
-/*
- * Procedure 4.2.11 to 4.2.18 are to be executed four times per
- * frame. That means once for each sub-segment RPE-LTP analysis of
- * 40 samples. These parts produce at the output of the coder:
- */
-
- word * Nc, /* [0..3] LTP lag OUT */
- word * bc, /* [0..3] coded LTP gain OUT */
- word * Mc, /* [0..3] RPE grid selection OUT */
- word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
- word * xMc /* [13*4] normalized RPE samples OUT */
-)
-{
- int k;
- word * dp = S->dp0 + 120; /* [ -120...-1 ] */
- word * dpp = dp; /* [ 0...39 ] */
-
- static word e[50];
-
- word so[160];
-
-#if !(defined(__GNUC__) && defined(__i386__))
- longword ltmp;
-#endif
-
- Gsm_Preprocess (S, s, so);
- Gsm_LPC_Analysis (S, so, LARc);
- Gsm_Short_Term_Analysis_Filter (S, LARc, so);
-
- for (k = 0; k <= 3; k++, xMc += 13) {
-
- Gsm_Long_Term_Predictor ( S,
- so+k*40, /* d [0..39] IN */
- dp, /* dp [-120..-1] IN */
- e + 5, /* e [0..39] OUT */
- dpp, /* dpp [0..39] OUT */
- Nc++,
- bc++);
-
- Gsm_RPE_Encoding ( S,
- e + 5, /* e ][0..39][ IN/OUT */
- xmaxc++, Mc++, xMc );
- /*
- * Gsm_Update_of_reconstructed_short_time_residual_signal
- * ( dpp, e + 5, dp );
- */
-
- { register int i;
- for (i = 0; i <= 39; i++)
- dp[ i ] = GSM_ADD( e[5 + i], dpp[i] );
- }
- dp += 40;
- dpp += 40;
-
- }
- (void)memcpy( (char *)S->dp0, (char *)(S->dp0 + 160),
- 120 * sizeof(*S->dp0) );
-}
diff --git a/1.2-netsec/codecs/gsm/src/debug.c b/1.2-netsec/codecs/gsm/src/debug.c
deleted file mode 100644
index 22dfa8082..000000000
--- a/1.2-netsec/codecs/gsm/src/debug.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include "private.h"
-
-#ifndef NDEBUG
-
-/* If NDEBUG _is_ defined and no debugging should be performed,
- * calls to functions in this module are #defined to nothing
- * in private.h.
- */
-
-#include <stdio.h>
-#include "proto.h"
-
-void gsm_debug_words P4( (name, from, to, ptr),
- char * name,
- int from,
- int to,
- word * ptr)
-{
- int nprinted = 0;
-
- fprintf( stderr, "%s [%d .. %d]: ", name, from, to );
- while (from <= to) {
- fprintf(stderr, "%d ", ptr[ from ] );
- from++;
- if (nprinted++ >= 7) {
- nprinted = 0;
- if (from < to) putc('\n', stderr);
- }
- }
- putc('\n', stderr);
-}
-
-void gsm_debug_longwords P4( (name, from, to, ptr),
- char * name,
- int from,
- int to,
- longword * ptr)
-{
- int nprinted = 0;
-
- fprintf( stderr, "%s [%d .. %d]: ", name, from, to );
- while (from <= to) {
-
- fprintf(stderr, "%d ", ptr[ from ] );
- from++;
- if (nprinted++ >= 7) {
- nprinted = 0;
- if (from < to) putc('\n', stderr);
- }
- }
- putc('\n', stderr);
-}
-
-void gsm_debug_longword P2( (name, value),
- char * name,
- longword value )
-{
- fprintf(stderr, "%s: %d\n", name, (long)value );
-}
-
-void gsm_debug_word P2( (name, value),
- char * name,
- word value )
-{
- fprintf(stderr, "%s: %d\n", name, (long)value);
-}
-
-#endif
diff --git a/1.2-netsec/codecs/gsm/src/decode.c b/1.2-netsec/codecs/gsm/src/decode.c
deleted file mode 100644
index 7d56bf96c..000000000
--- a/1.2-netsec/codecs/gsm/src/decode.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include <stdio.h>
-
-#include "private.h"
-#include "gsm.h"
-#include "proto.h"
-
-/*
- * 4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER
- */
-
-static void Postprocessing P2((S,s),
- struct gsm_state * S,
- register word * s)
-{
- register int k;
- register word msr = S->msr;
- register word tmp;
-
- for (k = 160; k--; s++) {
- tmp = GSM_MULT_R( msr, 28180 );
- msr = GSM_ADD(*s, tmp); /* Deemphasis */
- *s = GSM_ADD(msr, msr) & 0xFFF8; /* Truncation & Upscaling */
- }
- S->msr = msr;
-}
-
-void Gsm_Decoder P8((S,LARcr, Ncr,bcr,Mcr,xmaxcr,xMcr,s),
- struct gsm_state * S,
-
- word * LARcr, /* [0..7] IN */
-
- word * Ncr, /* [0..3] IN */
- word * bcr, /* [0..3] IN */
- word * Mcr, /* [0..3] IN */
- word * xmaxcr, /* [0..3] IN */
- word * xMcr, /* [0..13*4] IN */
-
- word * s) /* [0..159] OUT */
-{
- int j, k;
- word erp[40], wt[160];
- word * drp = S->dp0 + 120;
-
- for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) {
-
- Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp );
- Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp );
-
- for (k = 0; k <= 39; k++) wt[ j * 40 + k ] = drp[ k ];
- }
-
- Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s );
- Postprocessing(S, s);
-}
diff --git a/1.2-netsec/codecs/gsm/src/gsm_create.c b/1.2-netsec/codecs/gsm/src/gsm_create.c
deleted file mode 100644
index a59aa2f2a..000000000
--- a/1.2-netsec/codecs/gsm/src/gsm_create.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-static char const ident[] = "$Header$";
-
-#include "config.h"
-
-#ifdef HAS_STRING_H
-#include <string.h>
-#else
-# include "proto.h"
- extern char * memset P((char *, int, int));
-#endif
-
-#ifdef HAS_STDLIB_H
-# include <stdlib.h>
-#else
-# ifdef HAS_MALLOC_H
-# include <malloc.h>
-# else
- extern char * malloc();
-# endif
-#endif
-
-#include <stdio.h>
-
-#include "gsm.h"
-#include "private.h"
-#include "proto.h"
-
-gsm gsm_create P0()
-{
- gsm r;
-
- r = (gsm)malloc(sizeof(struct gsm_state));
- if (!r) return r;
-
- memset((char *)r, 0, sizeof(*r));
- r->nrp = 40;
-
- return r;
-}
diff --git a/1.2-netsec/codecs/gsm/src/gsm_decode.c b/1.2-netsec/codecs/gsm/src/gsm_decode.c
deleted file mode 100644
index 7318ba2d4..000000000
--- a/1.2-netsec/codecs/gsm/src/gsm_decode.c
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include "private.h"
-
-#include "gsm.h"
-#include "proto.h"
-
-int gsm_decode P3((s, c, target), gsm s, gsm_byte * c, gsm_signal * target)
-{
- word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
-
-#ifdef WAV49
- if (s->wav_fmt) {
-
- uword sr = 0;
-
- s->frame_index = !s->frame_index;
- if (s->frame_index) {
-
- sr = *c++;
- LARc[0] = sr & 0x3f; sr >>= 6;
- sr |= (uword)*c++ << 2;
- LARc[1] = sr & 0x3f; sr >>= 6;
- sr |= (uword)*c++ << 4;
- LARc[2] = sr & 0x1f; sr >>= 5;
- LARc[3] = sr & 0x1f; sr >>= 5;
- sr |= (uword)*c++ << 2;
- LARc[4] = sr & 0xf; sr >>= 4;
- LARc[5] = sr & 0xf; sr >>= 4;
- sr |= (uword)*c++ << 2; /* 5 */
- LARc[6] = sr & 0x7; sr >>= 3;
- LARc[7] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[0] = sr & 0x7f; sr >>= 7;
- bc[0] = sr & 0x3; sr >>= 2;
- Mc[0] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[0] = sr & 0x3f; sr >>= 6;
- xmc[0] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[1] = sr & 0x7; sr >>= 3;
- xmc[2] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[3] = sr & 0x7; sr >>= 3;
- xmc[4] = sr & 0x7; sr >>= 3;
- xmc[5] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 10 */
- xmc[6] = sr & 0x7; sr >>= 3;
- xmc[7] = sr & 0x7; sr >>= 3;
- xmc[8] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[9] = sr & 0x7; sr >>= 3;
- xmc[10] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[11] = sr & 0x7; sr >>= 3;
- xmc[12] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[1] = sr & 0x7f; sr >>= 7;
- bc[1] = sr & 0x3; sr >>= 2;
- Mc[1] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[1] = sr & 0x3f; sr >>= 6;
- xmc[13] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 15 */
- xmc[14] = sr & 0x7; sr >>= 3;
- xmc[15] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[16] = sr & 0x7; sr >>= 3;
- xmc[17] = sr & 0x7; sr >>= 3;
- xmc[18] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[19] = sr & 0x7; sr >>= 3;
- xmc[20] = sr & 0x7; sr >>= 3;
- xmc[21] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[22] = sr & 0x7; sr >>= 3;
- xmc[23] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[24] = sr & 0x7; sr >>= 3;
- xmc[25] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4; /* 20 */
- Nc[2] = sr & 0x7f; sr >>= 7;
- bc[2] = sr & 0x3; sr >>= 2;
- Mc[2] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[2] = sr & 0x3f; sr >>= 6;
- xmc[26] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[27] = sr & 0x7; sr >>= 3;
- xmc[28] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[29] = sr & 0x7; sr >>= 3;
- xmc[30] = sr & 0x7; sr >>= 3;
- xmc[31] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[32] = sr & 0x7; sr >>= 3;
- xmc[33] = sr & 0x7; sr >>= 3;
- xmc[34] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 25 */
- xmc[35] = sr & 0x7; sr >>= 3;
- xmc[36] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[37] = sr & 0x7; sr >>= 3;
- xmc[38] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[3] = sr & 0x7f; sr >>= 7;
- bc[3] = sr & 0x3; sr >>= 2;
- Mc[3] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[3] = sr & 0x3f; sr >>= 6;
- xmc[39] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[40] = sr & 0x7; sr >>= 3;
- xmc[41] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2; /* 30 */
- xmc[42] = sr & 0x7; sr >>= 3;
- xmc[43] = sr & 0x7; sr >>= 3;
- xmc[44] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[45] = sr & 0x7; sr >>= 3;
- xmc[46] = sr & 0x7; sr >>= 3;
- xmc[47] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[48] = sr & 0x7; sr >>= 3;
- xmc[49] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[50] = sr & 0x7; sr >>= 3;
- xmc[51] = sr & 0x7; sr >>= 3;
-
- s->frame_chain = sr & 0xf;
- }
- else {
- sr = s->frame_chain;
- sr |= (uword)*c++ << 4; /* 1 */
- LARc[0] = sr & 0x3f; sr >>= 6;
- LARc[1] = sr & 0x3f; sr >>= 6;
- sr = *c++;
- LARc[2] = sr & 0x1f; sr >>= 5;
- sr |= (uword)*c++ << 3;
- LARc[3] = sr & 0x1f; sr >>= 5;
- LARc[4] = sr & 0xf; sr >>= 4;
- sr |= (uword)*c++ << 2;
- LARc[5] = sr & 0xf; sr >>= 4;
- LARc[6] = sr & 0x7; sr >>= 3;
- LARc[7] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 5 */
- Nc[0] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[0] = sr & 0x3; sr >>= 2;
- Mc[0] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[0] = sr & 0x3f; sr >>= 6;
- xmc[0] = sr & 0x7; sr >>= 3;
- xmc[1] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[2] = sr & 0x7; sr >>= 3;
- xmc[3] = sr & 0x7; sr >>= 3;
- xmc[4] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[5] = sr & 0x7; sr >>= 3;
- xmc[6] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2; /* 10 */
- xmc[7] = sr & 0x7; sr >>= 3;
- xmc[8] = sr & 0x7; sr >>= 3;
- xmc[9] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[10] = sr & 0x7; sr >>= 3;
- xmc[11] = sr & 0x7; sr >>= 3;
- xmc[12] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[1] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[1] = sr & 0x3; sr >>= 2;
- Mc[1] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[1] = sr & 0x3f; sr >>= 6;
- xmc[13] = sr & 0x7; sr >>= 3;
- xmc[14] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 15 */
- xmc[15] = sr & 0x7; sr >>= 3;
- xmc[16] = sr & 0x7; sr >>= 3;
- xmc[17] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[18] = sr & 0x7; sr >>= 3;
- xmc[19] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[20] = sr & 0x7; sr >>= 3;
- xmc[21] = sr & 0x7; sr >>= 3;
- xmc[22] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[23] = sr & 0x7; sr >>= 3;
- xmc[24] = sr & 0x7; sr >>= 3;
- xmc[25] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[2] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1; /* 20 */
- bc[2] = sr & 0x3; sr >>= 2;
- Mc[2] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[2] = sr & 0x3f; sr >>= 6;
- xmc[26] = sr & 0x7; sr >>= 3;
- xmc[27] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[28] = sr & 0x7; sr >>= 3;
- xmc[29] = sr & 0x7; sr >>= 3;
- xmc[30] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[31] = sr & 0x7; sr >>= 3;
- xmc[32] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[33] = sr & 0x7; sr >>= 3;
- xmc[34] = sr & 0x7; sr >>= 3;
- xmc[35] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 25 */
- xmc[36] = sr & 0x7; sr >>= 3;
- xmc[37] = sr & 0x7; sr >>= 3;
- xmc[38] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[3] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[3] = sr & 0x3; sr >>= 2;
- Mc[3] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[3] = sr & 0x3f; sr >>= 6;
- xmc[39] = sr & 0x7; sr >>= 3;
- xmc[40] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[41] = sr & 0x7; sr >>= 3;
- xmc[42] = sr & 0x7; sr >>= 3;
- xmc[43] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 30 */
- xmc[44] = sr & 0x7; sr >>= 3;
- xmc[45] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[46] = sr & 0x7; sr >>= 3;
- xmc[47] = sr & 0x7; sr >>= 3;
- xmc[48] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[49] = sr & 0x7; sr >>= 3;
- xmc[50] = sr & 0x7; sr >>= 3;
- xmc[51] = sr & 0x7; sr >>= 3;
- }
- }
- else
-#endif
- {
- /* GSM_MAGIC = (*c >> 4) & 0xF; */
-
- if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1;
-
- LARc[0] = (*c++ & 0xF) << 2; /* 1 */
- LARc[0] |= (*c >> 6) & 0x3;
- LARc[1] = *c++ & 0x3F;
- LARc[2] = (*c >> 3) & 0x1F;
- LARc[3] = (*c++ & 0x7) << 2;
- LARc[3] |= (*c >> 6) & 0x3;
- LARc[4] = (*c >> 2) & 0xF;
- LARc[5] = (*c++ & 0x3) << 2;
- LARc[5] |= (*c >> 6) & 0x3;
- LARc[6] = (*c >> 3) & 0x7;
- LARc[7] = *c++ & 0x7;
- Nc[0] = (*c >> 1) & 0x7F;
- bc[0] = (*c++ & 0x1) << 1;
- bc[0] |= (*c >> 7) & 0x1;
- Mc[0] = (*c >> 5) & 0x3;
- xmaxc[0] = (*c++ & 0x1F) << 1;
- xmaxc[0] |= (*c >> 7) & 0x1;
- xmc[0] = (*c >> 4) & 0x7;
- xmc[1] = (*c >> 1) & 0x7;
- xmc[2] = (*c++ & 0x1) << 2;
- xmc[2] |= (*c >> 6) & 0x3;
- xmc[3] = (*c >> 3) & 0x7;
- xmc[4] = *c++ & 0x7;
- xmc[5] = (*c >> 5) & 0x7;
- xmc[6] = (*c >> 2) & 0x7;
- xmc[7] = (*c++ & 0x3) << 1; /* 10 */
- xmc[7] |= (*c >> 7) & 0x1;
- xmc[8] = (*c >> 4) & 0x7;
- xmc[9] = (*c >> 1) & 0x7;
- xmc[10] = (*c++ & 0x1) << 2;
- xmc[10] |= (*c >> 6) & 0x3;
- xmc[11] = (*c >> 3) & 0x7;
- xmc[12] = *c++ & 0x7;
- Nc[1] = (*c >> 1) & 0x7F;
- bc[1] = (*c++ & 0x1) << 1;
- bc[1] |= (*c >> 7) & 0x1;
- Mc[1] = (*c >> 5) & 0x3;
- xmaxc[1] = (*c++ & 0x1F) << 1;
- xmaxc[1] |= (*c >> 7) & 0x1;
- xmc[13] = (*c >> 4) & 0x7;
- xmc[14] = (*c >> 1) & 0x7;
- xmc[15] = (*c++ & 0x1) << 2;
- xmc[15] |= (*c >> 6) & 0x3;
- xmc[16] = (*c >> 3) & 0x7;
- xmc[17] = *c++ & 0x7;
- xmc[18] = (*c >> 5) & 0x7;
- xmc[19] = (*c >> 2) & 0x7;
- xmc[20] = (*c++ & 0x3) << 1;
- xmc[20] |= (*c >> 7) & 0x1;
- xmc[21] = (*c >> 4) & 0x7;
- xmc[22] = (*c >> 1) & 0x7;
- xmc[23] = (*c++ & 0x1) << 2;
- xmc[23] |= (*c >> 6) & 0x3;
- xmc[24] = (*c >> 3) & 0x7;
- xmc[25] = *c++ & 0x7;
- Nc[2] = (*c >> 1) & 0x7F;
- bc[2] = (*c++ & 0x1) << 1; /* 20 */
- bc[2] |= (*c >> 7) & 0x1;
- Mc[2] = (*c >> 5) & 0x3;
- xmaxc[2] = (*c++ & 0x1F) << 1;
- xmaxc[2] |= (*c >> 7) & 0x1;
- xmc[26] = (*c >> 4) & 0x7;
- xmc[27] = (*c >> 1) & 0x7;
- xmc[28] = (*c++ & 0x1) << 2;
- xmc[28] |= (*c >> 6) & 0x3;
- xmc[29] = (*c >> 3) & 0x7;
- xmc[30] = *c++ & 0x7;
- xmc[31] = (*c >> 5) & 0x7;
- xmc[32] = (*c >> 2) & 0x7;
- xmc[33] = (*c++ & 0x3) << 1;
- xmc[33] |= (*c >> 7) & 0x1;
- xmc[34] = (*c >> 4) & 0x7;
- xmc[35] = (*c >> 1) & 0x7;
- xmc[36] = (*c++ & 0x1) << 2;
- xmc[36] |= (*c >> 6) & 0x3;
- xmc[37] = (*c >> 3) & 0x7;
- xmc[38] = *c++ & 0x7;
- Nc[3] = (*c >> 1) & 0x7F;
- bc[3] = (*c++ & 0x1) << 1;
- bc[3] |= (*c >> 7) & 0x1;
- Mc[3] = (*c >> 5) & 0x3;
- xmaxc[3] = (*c++ & 0x1F) << 1;
- xmaxc[3] |= (*c >> 7) & 0x1;
- xmc[39] = (*c >> 4) & 0x7;
- xmc[40] = (*c >> 1) & 0x7;
- xmc[41] = (*c++ & 0x1) << 2;
- xmc[41] |= (*c >> 6) & 0x3;
- xmc[42] = (*c >> 3) & 0x7;
- xmc[43] = *c++ & 0x7; /* 30 */
- xmc[44] = (*c >> 5) & 0x7;
- xmc[45] = (*c >> 2) & 0x7;
- xmc[46] = (*c++ & 0x3) << 1;
- xmc[46] |= (*c >> 7) & 0x1;
- xmc[47] = (*c >> 4) & 0x7;
- xmc[48] = (*c >> 1) & 0x7;
- xmc[49] = (*c++ & 0x1) << 2;
- xmc[49] |= (*c >> 6) & 0x3;
- xmc[50] = (*c >> 3) & 0x7;
- xmc[51] = *c & 0x7; /* 33 */
- }
-
- Gsm_Decoder(s, LARc, Nc, bc, Mc, xmaxc, xmc, target);
-
- return 0;
-}
diff --git a/1.2-netsec/codecs/gsm/src/gsm_destroy.c b/1.2-netsec/codecs/gsm/src/gsm_destroy.c
deleted file mode 100644
index 4807c0acd..000000000
--- a/1.2-netsec/codecs/gsm/src/gsm_destroy.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include "gsm.h"
-#include "config.h"
-#include "proto.h"
-
-#ifdef HAS_STDLIB_H
-# include <stdlib.h>
-#else
-# ifdef HAS_MALLOC_H
-# include <malloc.h>
-# else
- extern void free();
-# endif
-#endif
-
-void gsm_destroy P1((S), gsm S)
-{
- if (S) free((char *)S);
-}
diff --git a/1.2-netsec/codecs/gsm/src/gsm_encode.c b/1.2-netsec/codecs/gsm/src/gsm_encode.c
deleted file mode 100644
index 62338300e..000000000
--- a/1.2-netsec/codecs/gsm/src/gsm_encode.c
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include "private.h"
-#include "gsm.h"
-#include "proto.h"
-
-void gsm_encode P3((s, source, c), gsm s, gsm_signal * source, gsm_byte * c)
-{
- word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
-
- Gsm_Coder(s, source, LARc, Nc, bc, Mc, xmaxc, xmc);
-
-
- /* variable size
-
- GSM_MAGIC 4
-
- LARc[0] 6
- LARc[1] 6
- LARc[2] 5
- LARc[3] 5
- LARc[4] 4
- LARc[5] 4
- LARc[6] 3
- LARc[7] 3
-
- Nc[0] 7
- bc[0] 2
- Mc[0] 2
- xmaxc[0] 6
- xmc[0] 3
- xmc[1] 3
- xmc[2] 3
- xmc[3] 3
- xmc[4] 3
- xmc[5] 3
- xmc[6] 3
- xmc[7] 3
- xmc[8] 3
- xmc[9] 3
- xmc[10] 3
- xmc[11] 3
- xmc[12] 3
-
- Nc[1] 7
- bc[1] 2
- Mc[1] 2
- xmaxc[1] 6
- xmc[13] 3
- xmc[14] 3
- xmc[15] 3
- xmc[16] 3
- xmc[17] 3
- xmc[18] 3
- xmc[19] 3
- xmc[20] 3
- xmc[21] 3
- xmc[22] 3
- xmc[23] 3
- xmc[24] 3
- xmc[25] 3
-
- Nc[2] 7
- bc[2] 2
- Mc[2] 2
- xmaxc[2] 6
- xmc[26] 3
- xmc[27] 3
- xmc[28] 3
- xmc[29] 3
- xmc[30] 3
- xmc[31] 3
- xmc[32] 3
- xmc[33] 3
- xmc[34] 3
- xmc[35] 3
- xmc[36] 3
- xmc[37] 3
- xmc[38] 3
-
- Nc[3] 7
- bc[3] 2
- Mc[3] 2
- xmaxc[3] 6
- xmc[39] 3
- xmc[40] 3
- xmc[41] 3
- xmc[42] 3
- xmc[43] 3
- xmc[44] 3
- xmc[45] 3
- xmc[46] 3
- xmc[47] 3
- xmc[48] 3
- xmc[49] 3
- xmc[50] 3
- xmc[51] 3
- */
-
-#ifdef WAV49
-
- if (s->wav_fmt) {
- s->frame_index = !s->frame_index;
- if (s->frame_index) {
-
- uword sr;
-
- sr = 0;
- sr = sr >> 6 | LARc[0] << 10;
- sr = sr >> 6 | LARc[1] << 10;
- *c++ = sr >> 4;
- sr = sr >> 5 | LARc[2] << 11;
- *c++ = sr >> 7;
- sr = sr >> 5 | LARc[3] << 11;
- sr = sr >> 4 | LARc[4] << 12;
- *c++ = sr >> 6;
- sr = sr >> 4 | LARc[5] << 12;
- sr = sr >> 3 | LARc[6] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | LARc[7] << 13;
- sr = sr >> 7 | Nc[0] << 9;
- *c++ = sr >> 5;
- sr = sr >> 2 | bc[0] << 14;
- sr = sr >> 2 | Mc[0] << 14;
- sr = sr >> 6 | xmaxc[0] << 10;
- *c++ = sr >> 3;
- sr = sr >> 3 | xmc[0] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[1] << 13;
- sr = sr >> 3 | xmc[2] << 13;
- sr = sr >> 3 | xmc[3] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[4] << 13;
- sr = sr >> 3 | xmc[5] << 13;
- sr = sr >> 3 | xmc[6] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[7] << 13;
- sr = sr >> 3 | xmc[8] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[9] << 13;
- sr = sr >> 3 | xmc[10] << 13;
- sr = sr >> 3 | xmc[11] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[12] << 13;
- sr = sr >> 7 | Nc[1] << 9;
- *c++ = sr >> 5;
- sr = sr >> 2 | bc[1] << 14;
- sr = sr >> 2 | Mc[1] << 14;
- sr = sr >> 6 | xmaxc[1] << 10;
- *c++ = sr >> 3;
- sr = sr >> 3 | xmc[13] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[14] << 13;
- sr = sr >> 3 | xmc[15] << 13;
- sr = sr >> 3 | xmc[16] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[17] << 13;
- sr = sr >> 3 | xmc[18] << 13;
- sr = sr >> 3 | xmc[19] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[20] << 13;
- sr = sr >> 3 | xmc[21] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[22] << 13;
- sr = sr >> 3 | xmc[23] << 13;
- sr = sr >> 3 | xmc[24] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[25] << 13;
- sr = sr >> 7 | Nc[2] << 9;
- *c++ = sr >> 5;
- sr = sr >> 2 | bc[2] << 14;
- sr = sr >> 2 | Mc[2] << 14;
- sr = sr >> 6 | xmaxc[2] << 10;
- *c++ = sr >> 3;
- sr = sr >> 3 | xmc[26] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[27] << 13;
- sr = sr >> 3 | xmc[28] << 13;
- sr = sr >> 3 | xmc[29] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[30] << 13;
- sr = sr >> 3 | xmc[31] << 13;
- sr = sr >> 3 | xmc[32] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[33] << 13;
- sr = sr >> 3 | xmc[34] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[35] << 13;
- sr = sr >> 3 | xmc[36] << 13;
- sr = sr >> 3 | xmc[37] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[38] << 13;
- sr = sr >> 7 | Nc[3] << 9;
- *c++ = sr >> 5;
- sr = sr >> 2 | bc[3] << 14;
- sr = sr >> 2 | Mc[3] << 14;
- sr = sr >> 6 | xmaxc[3] << 10;
- *c++ = sr >> 3;
- sr = sr >> 3 | xmc[39] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[40] << 13;
- sr = sr >> 3 | xmc[41] << 13;
- sr = sr >> 3 | xmc[42] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[43] << 13;
- sr = sr >> 3 | xmc[44] << 13;
- sr = sr >> 3 | xmc[45] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[46] << 13;
- sr = sr >> 3 | xmc[47] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[48] << 13;
- sr = sr >> 3 | xmc[49] << 13;
- sr = sr >> 3 | xmc[50] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[51] << 13;
- sr = sr >> 4;
- *c = sr >> 8;
- s->frame_chain = *c;
- }
- else {
- uword sr;
-
- sr = 0;
- sr = sr >> 4 | s->frame_chain << 12;
- sr = sr >> 6 | LARc[0] << 10;
- *c++ = sr >> 6;
- sr = sr >> 6 | LARc[1] << 10;
- *c++ = sr >> 8;
- sr = sr >> 5 | LARc[2] << 11;
- sr = sr >> 5 | LARc[3] << 11;
- *c++ = sr >> 6;
- sr = sr >> 4 | LARc[4] << 12;
- sr = sr >> 4 | LARc[5] << 12;
- *c++ = sr >> 6;
- sr = sr >> 3 | LARc[6] << 13;
- sr = sr >> 3 | LARc[7] << 13;
- *c++ = sr >> 8;
- sr = sr >> 7 | Nc[0] << 9;
- sr = sr >> 2 | bc[0] << 14;
- *c++ = sr >> 7;
- sr = sr >> 2 | Mc[0] << 14;
- sr = sr >> 6 | xmaxc[0] << 10;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[0] << 13;
- sr = sr >> 3 | xmc[1] << 13;
- sr = sr >> 3 | xmc[2] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[3] << 13;
- sr = sr >> 3 | xmc[4] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[5] << 13;
- sr = sr >> 3 | xmc[6] << 13;
- sr = sr >> 3 | xmc[7] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[8] << 13;
- sr = sr >> 3 | xmc[9] << 13;
- sr = sr >> 3 | xmc[10] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[11] << 13;
- sr = sr >> 3 | xmc[12] << 13;
- *c++ = sr >> 8;
- sr = sr >> 7 | Nc[1] << 9;
- sr = sr >> 2 | bc[1] << 14;
- *c++ = sr >> 7;
- sr = sr >> 2 | Mc[1] << 14;
- sr = sr >> 6 | xmaxc[1] << 10;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[13] << 13;
- sr = sr >> 3 | xmc[14] << 13;
- sr = sr >> 3 | xmc[15] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[16] << 13;
- sr = sr >> 3 | xmc[17] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[18] << 13;
- sr = sr >> 3 | xmc[19] << 13;
- sr = sr >> 3 | xmc[20] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[21] << 13;
- sr = sr >> 3 | xmc[22] << 13;
- sr = sr >> 3 | xmc[23] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[24] << 13;
- sr = sr >> 3 | xmc[25] << 13;
- *c++ = sr >> 8;
- sr = sr >> 7 | Nc[2] << 9;
- sr = sr >> 2 | bc[2] << 14;
- *c++ = sr >> 7;
- sr = sr >> 2 | Mc[2] << 14;
- sr = sr >> 6 | xmaxc[2] << 10;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[26] << 13;
- sr = sr >> 3 | xmc[27] << 13;
- sr = sr >> 3 | xmc[28] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[29] << 13;
- sr = sr >> 3 | xmc[30] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[31] << 13;
- sr = sr >> 3 | xmc[32] << 13;
- sr = sr >> 3 | xmc[33] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[34] << 13;
- sr = sr >> 3 | xmc[35] << 13;
- sr = sr >> 3 | xmc[36] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[37] << 13;
- sr = sr >> 3 | xmc[38] << 13;
- *c++ = sr >> 8;
- sr = sr >> 7 | Nc[3] << 9;
- sr = sr >> 2 | bc[3] << 14;
- *c++ = sr >> 7;
- sr = sr >> 2 | Mc[3] << 14;
- sr = sr >> 6 | xmaxc[3] << 10;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[39] << 13;
- sr = sr >> 3 | xmc[40] << 13;
- sr = sr >> 3 | xmc[41] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[42] << 13;
- sr = sr >> 3 | xmc[43] << 13;
- *c++ = sr >> 8;
- sr = sr >> 3 | xmc[44] << 13;
- sr = sr >> 3 | xmc[45] << 13;
- sr = sr >> 3 | xmc[46] << 13;
- *c++ = sr >> 7;
- sr = sr >> 3 | xmc[47] << 13;
- sr = sr >> 3 | xmc[48] << 13;
- sr = sr >> 3 | xmc[49] << 13;
- *c++ = sr >> 6;
- sr = sr >> 3 | xmc[50] << 13;
- sr = sr >> 3 | xmc[51] << 13;
- *c++ = sr >> 8;
- }
- }
-
- else
-
-#endif /* WAV49 */
- {
-
- *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */
- | ((LARc[0] >> 2) & 0xF);
- *c++ = ((LARc[0] & 0x3) << 6)
- | (LARc[1] & 0x3F);
- *c++ = ((LARc[2] & 0x1F) << 3)
- | ((LARc[3] >> 2) & 0x7);
- *c++ = ((LARc[3] & 0x3) << 6)
- | ((LARc[4] & 0xF) << 2)
- | ((LARc[5] >> 2) & 0x3);
- *c++ = ((LARc[5] & 0x3) << 6)
- | ((LARc[6] & 0x7) << 3)
- | (LARc[7] & 0x7);
- *c++ = ((Nc[0] & 0x7F) << 1)
- | ((bc[0] >> 1) & 0x1);
- *c++ = ((bc[0] & 0x1) << 7)
- | ((Mc[0] & 0x3) << 5)
- | ((xmaxc[0] >> 1) & 0x1F);
- *c++ = ((xmaxc[0] & 0x1) << 7)
- | ((xmc[0] & 0x7) << 4)
- | ((xmc[1] & 0x7) << 1)
- | ((xmc[2] >> 2) & 0x1);
- *c++ = ((xmc[2] & 0x3) << 6)
- | ((xmc[3] & 0x7) << 3)
- | (xmc[4] & 0x7);
- *c++ = ((xmc[5] & 0x7) << 5) /* 10 */
- | ((xmc[6] & 0x7) << 2)
- | ((xmc[7] >> 1) & 0x3);
- *c++ = ((xmc[7] & 0x1) << 7)
- | ((xmc[8] & 0x7) << 4)
- | ((xmc[9] & 0x7) << 1)
- | ((xmc[10] >> 2) & 0x1);
- *c++ = ((xmc[10] & 0x3) << 6)
- | ((xmc[11] & 0x7) << 3)
- | (xmc[12] & 0x7);
- *c++ = ((Nc[1] & 0x7F) << 1)
- | ((bc[1] >> 1) & 0x1);
- *c++ = ((bc[1] & 0x1) << 7)
- | ((Mc[1] & 0x3) << 5)
- | ((xmaxc[1] >> 1) & 0x1F);
- *c++ = ((xmaxc[1] & 0x1) << 7)
- | ((xmc[13] & 0x7) << 4)
- | ((xmc[14] & 0x7) << 1)
- | ((xmc[15] >> 2) & 0x1);
- *c++ = ((xmc[15] & 0x3) << 6)
- | ((xmc[16] & 0x7) << 3)
- | (xmc[17] & 0x7);
- *c++ = ((xmc[18] & 0x7) << 5)
- | ((xmc[19] & 0x7) << 2)
- | ((xmc[20] >> 1) & 0x3);
- *c++ = ((xmc[20] & 0x1) << 7)
- | ((xmc[21] & 0x7) << 4)
- | ((xmc[22] & 0x7) << 1)
- | ((xmc[23] >> 2) & 0x1);
- *c++ = ((xmc[23] & 0x3) << 6)
- | ((xmc[24] & 0x7) << 3)
- | (xmc[25] & 0x7);
- *c++ = ((Nc[2] & 0x7F) << 1) /* 20 */
- | ((bc[2] >> 1) & 0x1);
- *c++ = ((bc[2] & 0x1) << 7)
- | ((Mc[2] & 0x3) << 5)
- | ((xmaxc[2] >> 1) & 0x1F);
- *c++ = ((xmaxc[2] & 0x1) << 7)
- | ((xmc[26] & 0x7) << 4)
- | ((xmc[27] & 0x7) << 1)
- | ((xmc[28] >> 2) & 0x1);
- *c++ = ((xmc[28] & 0x3) << 6)
- | ((xmc[29] & 0x7) << 3)
- | (xmc[30] & 0x7);
- *c++ = ((xmc[31] & 0x7) << 5)
- | ((xmc[32] & 0x7) << 2)
- | ((xmc[33] >> 1) & 0x3);
- *c++ = ((xmc[33] & 0x1) << 7)
- | ((xmc[34] & 0x7) << 4)
- | ((xmc[35] & 0x7) << 1)
- | ((xmc[36] >> 2) & 0x1);
- *c++ = ((xmc[36] & 0x3) << 6)
- | ((xmc[37] & 0x7) << 3)
- | (xmc[38] & 0x7);
- *c++ = ((Nc[3] & 0x7F) << 1)
- | ((bc[3] >> 1) & 0x1);
- *c++ = ((bc[3] & 0x1) << 7)
- | ((Mc[3] & 0x3) << 5)
- | ((xmaxc[3] >> 1) & 0x1F);
- *c++ = ((xmaxc[3] & 0x1) << 7)
- | ((xmc[39] & 0x7) << 4)
- | ((xmc[40] & 0x7) << 1)
- | ((xmc[41] >> 2) & 0x1);
- *c++ = ((xmc[41] & 0x3) << 6) /* 30 */
- | ((xmc[42] & 0x7) << 3)
- | (xmc[43] & 0x7);
- *c++ = ((xmc[44] & 0x7) << 5)
- | ((xmc[45] & 0x7) << 2)
- | ((xmc[46] >> 1) & 0x3);
- *c++ = ((xmc[46] & 0x1) << 7)
- | ((xmc[47] & 0x7) << 4)
- | ((xmc[48] & 0x7) << 1)
- | ((xmc[49] >> 2) & 0x1);
- *c++ = ((xmc[49] & 0x3) << 6)
- | ((xmc[50] & 0x7) << 3)
- | (xmc[51] & 0x7);
-
- }
-}
diff --git a/1.2-netsec/codecs/gsm/src/gsm_explode.c b/1.2-netsec/codecs/gsm/src/gsm_explode.c
deleted file mode 100644
index a906fc2ed..000000000
--- a/1.2-netsec/codecs/gsm/src/gsm_explode.c
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include "private.h"
-#include "gsm.h"
-#include "proto.h"
-
-int gsm_explode P3((s, c, target), gsm s, gsm_byte * c, gsm_signal * target)
-{
-# define LARc target
-# define Nc *((gsm_signal (*) [17])(target + 8))
-# define bc *((gsm_signal (*) [17])(target + 9))
-# define Mc *((gsm_signal (*) [17])(target + 10))
-# define xmaxc *((gsm_signal (*) [17])(target + 11))
-
-
-#ifdef WAV49
- if (s->wav_fmt) {
-
- uword sr = 0;
-
- if (s->frame_index == 1) {
-
- sr = *c++;
- LARc[0] = sr & 0x3f; sr >>= 6;
- sr |= (uword)*c++ << 2;
- LARc[1] = sr & 0x3f; sr >>= 6;
- sr |= (uword)*c++ << 4;
- LARc[2] = sr & 0x1f; sr >>= 5;
- LARc[3] = sr & 0x1f; sr >>= 5;
- sr |= (uword)*c++ << 2;
- LARc[4] = sr & 0xf; sr >>= 4;
- LARc[5] = sr & 0xf; sr >>= 4;
- sr |= (uword)*c++ << 2; /* 5 */
- LARc[6] = sr & 0x7; sr >>= 3;
- LARc[7] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[0] = sr & 0x7f; sr >>= 7;
- bc[0] = sr & 0x3; sr >>= 2;
- Mc[0] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[0] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (target + 12)
- xmc[0] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[1] = sr & 0x7; sr >>= 3;
- xmc[2] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[3] = sr & 0x7; sr >>= 3;
- xmc[4] = sr & 0x7; sr >>= 3;
- xmc[5] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 10 */
- xmc[6] = sr & 0x7; sr >>= 3;
- xmc[7] = sr & 0x7; sr >>= 3;
- xmc[8] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[9] = sr & 0x7; sr >>= 3;
- xmc[10] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[11] = sr & 0x7; sr >>= 3;
- xmc[12] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[1] = sr & 0x7f; sr >>= 7;
- bc[1] = sr & 0x3; sr >>= 2;
- Mc[1] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[1] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (target + 29 - 13)
-
- xmc[13] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 15 */
- xmc[14] = sr & 0x7; sr >>= 3;
- xmc[15] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[16] = sr & 0x7; sr >>= 3;
- xmc[17] = sr & 0x7; sr >>= 3;
- xmc[18] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[19] = sr & 0x7; sr >>= 3;
- xmc[20] = sr & 0x7; sr >>= 3;
- xmc[21] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[22] = sr & 0x7; sr >>= 3;
- xmc[23] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[24] = sr & 0x7; sr >>= 3;
- xmc[25] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4; /* 20 */
- Nc[2] = sr & 0x7f; sr >>= 7;
- bc[2] = sr & 0x3; sr >>= 2;
- Mc[2] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[2] = sr & 0x3f; sr >>= 6;
-
-#undef xmc
-#define xmc (target + 46 - 26)
-
- xmc[26] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[27] = sr & 0x7; sr >>= 3;
- xmc[28] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[29] = sr & 0x7; sr >>= 3;
- xmc[30] = sr & 0x7; sr >>= 3;
- xmc[31] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[32] = sr & 0x7; sr >>= 3;
- xmc[33] = sr & 0x7; sr >>= 3;
- xmc[34] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 25 */
- xmc[35] = sr & 0x7; sr >>= 3;
- xmc[36] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[37] = sr & 0x7; sr >>= 3;
- xmc[38] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[3] = sr & 0x7f; sr >>= 7;
- bc[3] = sr & 0x3; sr >>= 2;
- Mc[3] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[3] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (target + 63 - 39)
-
- xmc[39] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[40] = sr & 0x7; sr >>= 3;
- xmc[41] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2; /* 30 */
- xmc[42] = sr & 0x7; sr >>= 3;
- xmc[43] = sr & 0x7; sr >>= 3;
- xmc[44] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[45] = sr & 0x7; sr >>= 3;
- xmc[46] = sr & 0x7; sr >>= 3;
- xmc[47] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[48] = sr & 0x7; sr >>= 3;
- xmc[49] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[50] = sr & 0x7; sr >>= 3;
- xmc[51] = sr & 0x7; sr >>= 3;
-
- s->frame_chain = sr & 0xf;
- }
- else {
- sr = s->frame_chain;
- sr |= (uword)*c++ << 4; /* 1 */
- LARc[0] = sr & 0x3f; sr >>= 6;
- LARc[1] = sr & 0x3f; sr >>= 6;
- sr = *c++;
- LARc[2] = sr & 0x1f; sr >>= 5;
- sr |= (uword)*c++ << 3;
- LARc[3] = sr & 0x1f; sr >>= 5;
- LARc[4] = sr & 0xf; sr >>= 4;
- sr |= (uword)*c++ << 2;
- LARc[5] = sr & 0xf; sr >>= 4;
- LARc[6] = sr & 0x7; sr >>= 3;
- LARc[7] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 5 */
- Nc[0] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[0] = sr & 0x3; sr >>= 2;
- Mc[0] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[0] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (target + 12)
- xmc[0] = sr & 0x7; sr >>= 3;
- xmc[1] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[2] = sr & 0x7; sr >>= 3;
- xmc[3] = sr & 0x7; sr >>= 3;
- xmc[4] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[5] = sr & 0x7; sr >>= 3;
- xmc[6] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2; /* 10 */
- xmc[7] = sr & 0x7; sr >>= 3;
- xmc[8] = sr & 0x7; sr >>= 3;
- xmc[9] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[10] = sr & 0x7; sr >>= 3;
- xmc[11] = sr & 0x7; sr >>= 3;
- xmc[12] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[1] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[1] = sr & 0x3; sr >>= 2;
- Mc[1] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[1] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (target + 29 - 13)
-
- xmc[13] = sr & 0x7; sr >>= 3;
- xmc[14] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 15 */
- xmc[15] = sr & 0x7; sr >>= 3;
- xmc[16] = sr & 0x7; sr >>= 3;
- xmc[17] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[18] = sr & 0x7; sr >>= 3;
- xmc[19] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[20] = sr & 0x7; sr >>= 3;
- xmc[21] = sr & 0x7; sr >>= 3;
- xmc[22] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[23] = sr & 0x7; sr >>= 3;
- xmc[24] = sr & 0x7; sr >>= 3;
- xmc[25] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[2] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1; /* 20 */
- bc[2] = sr & 0x3; sr >>= 2;
- Mc[2] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[2] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (target + 46 - 26)
- xmc[26] = sr & 0x7; sr >>= 3;
- xmc[27] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[28] = sr & 0x7; sr >>= 3;
- xmc[29] = sr & 0x7; sr >>= 3;
- xmc[30] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[31] = sr & 0x7; sr >>= 3;
- xmc[32] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[33] = sr & 0x7; sr >>= 3;
- xmc[34] = sr & 0x7; sr >>= 3;
- xmc[35] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 25 */
- xmc[36] = sr & 0x7; sr >>= 3;
- xmc[37] = sr & 0x7; sr >>= 3;
- xmc[38] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[3] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[3] = sr & 0x3; sr >>= 2;
- Mc[3] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[3] = sr & 0x3f; sr >>= 6;
-
-#undef xmc
-#define xmc (target + 63 - 39)
-
- xmc[39] = sr & 0x7; sr >>= 3;
- xmc[40] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[41] = sr & 0x7; sr >>= 3;
- xmc[42] = sr & 0x7; sr >>= 3;
- xmc[43] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 30 */
- xmc[44] = sr & 0x7; sr >>= 3;
- xmc[45] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[46] = sr & 0x7; sr >>= 3;
- xmc[47] = sr & 0x7; sr >>= 3;
- xmc[48] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[49] = sr & 0x7; sr >>= 3;
- xmc[50] = sr & 0x7; sr >>= 3;
- xmc[51] = sr & 0x7; sr >>= 3;
- }
- }
- else
-#endif
- {
- /* GSM_MAGIC = (*c >> 4) & 0xF; */
-
- if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1;
-
- LARc[0] = (*c++ & 0xF) << 2; /* 1 */
- LARc[0] |= (*c >> 6) & 0x3;
- LARc[1] = *c++ & 0x3F;
- LARc[2] = (*c >> 3) & 0x1F;
- LARc[3] = (*c++ & 0x7) << 2;
- LARc[3] |= (*c >> 6) & 0x3;
- LARc[4] = (*c >> 2) & 0xF;
- LARc[5] = (*c++ & 0x3) << 2;
- LARc[5] |= (*c >> 6) & 0x3;
- LARc[6] = (*c >> 3) & 0x7;
- LARc[7] = *c++ & 0x7;
-
- Nc[0] = (*c >> 1) & 0x7F;
-
- bc[0] = (*c++ & 0x1) << 1;
- bc[0] |= (*c >> 7) & 0x1;
-
- Mc[0] = (*c >> 5) & 0x3;
-
- xmaxc[0] = (*c++ & 0x1F) << 1;
- xmaxc[0] |= (*c >> 7) & 0x1;
-
-#undef xmc
-#define xmc (target + 12)
-
- xmc[0] = (*c >> 4) & 0x7;
- xmc[1] = (*c >> 1) & 0x7;
- xmc[2] = (*c++ & 0x1) << 2;
- xmc[2] |= (*c >> 6) & 0x3;
- xmc[3] = (*c >> 3) & 0x7;
- xmc[4] = *c++ & 0x7;
- xmc[5] = (*c >> 5) & 0x7;
- xmc[6] = (*c >> 2) & 0x7;
- xmc[7] = (*c++ & 0x3) << 1; /* 10 */
- xmc[7] |= (*c >> 7) & 0x1;
- xmc[8] = (*c >> 4) & 0x7;
- xmc[9] = (*c >> 1) & 0x7;
- xmc[10] = (*c++ & 0x1) << 2;
- xmc[10] |= (*c >> 6) & 0x3;
- xmc[11] = (*c >> 3) & 0x7;
- xmc[12] = *c++ & 0x7;
-
- Nc[1] = (*c >> 1) & 0x7F;
-
- bc[1] = (*c++ & 0x1) << 1;
- bc[1] |= (*c >> 7) & 0x1;
-
- Mc[1] = (*c >> 5) & 0x3;
-
- xmaxc[1] = (*c++ & 0x1F) << 1;
- xmaxc[1] |= (*c >> 7) & 0x1;
-
-#undef xmc
-#define xmc (target + 29 - 13)
-
- xmc[13] = (*c >> 4) & 0x7;
- xmc[14] = (*c >> 1) & 0x7;
- xmc[15] = (*c++ & 0x1) << 2;
- xmc[15] |= (*c >> 6) & 0x3;
- xmc[16] = (*c >> 3) & 0x7;
- xmc[17] = *c++ & 0x7;
- xmc[18] = (*c >> 5) & 0x7;
- xmc[19] = (*c >> 2) & 0x7;
- xmc[20] = (*c++ & 0x3) << 1;
- xmc[20] |= (*c >> 7) & 0x1;
- xmc[21] = (*c >> 4) & 0x7;
- xmc[22] = (*c >> 1) & 0x7;
- xmc[23] = (*c++ & 0x1) << 2;
- xmc[23] |= (*c >> 6) & 0x3;
- xmc[24] = (*c >> 3) & 0x7;
- xmc[25] = *c++ & 0x7;
-
- Nc[2] = (*c >> 1) & 0x7F;
-
- bc[2] = (*c++ & 0x1) << 1; /* 20 */
- bc[2] |= (*c >> 7) & 0x1;
-
- Mc[2] = (*c >> 5) & 0x3;
-
- xmaxc[2] = (*c++ & 0x1F) << 1;
- xmaxc[2] |= (*c >> 7) & 0x1;
-
-#undef xmc
-#define xmc (target + 46 - 26)
-
- xmc[26] = (*c >> 4) & 0x7;
- xmc[27] = (*c >> 1) & 0x7;
- xmc[28] = (*c++ & 0x1) << 2;
- xmc[28] |= (*c >> 6) & 0x3;
- xmc[29] = (*c >> 3) & 0x7;
- xmc[30] = *c++ & 0x7;
- xmc[31] = (*c >> 5) & 0x7;
- xmc[32] = (*c >> 2) & 0x7;
- xmc[33] = (*c++ & 0x3) << 1;
- xmc[33] |= (*c >> 7) & 0x1;
- xmc[34] = (*c >> 4) & 0x7;
- xmc[35] = (*c >> 1) & 0x7;
- xmc[36] = (*c++ & 0x1) << 2;
- xmc[36] |= (*c >> 6) & 0x3;
- xmc[37] = (*c >> 3) & 0x7;
- xmc[38] = *c++ & 0x7;
-
- Nc[3] = (*c >> 1) & 0x7F;
-
- bc[3] = (*c++ & 0x1) << 1;
- bc[3] |= (*c >> 7) & 0x1;
-
- Mc[3] = (*c >> 5) & 0x3;
-
- xmaxc[3] = (*c++ & 0x1F) << 1;
- xmaxc[3] |= (*c >> 7) & 0x1;
-
-#undef xmc
-#define xmc (target + 63 - 39)
-
- xmc[39] = (*c >> 4) & 0x7;
- xmc[40] = (*c >> 1) & 0x7;
- xmc[41] = (*c++ & 0x1) << 2;
- xmc[41] |= (*c >> 6) & 0x3;
- xmc[42] = (*c >> 3) & 0x7;
- xmc[43] = *c++ & 0x7; /* 30 */
- xmc[44] = (*c >> 5) & 0x7;
- xmc[45] = (*c >> 2) & 0x7;
- xmc[46] = (*c++ & 0x3) << 1;
- xmc[46] |= (*c >> 7) & 0x1;
- xmc[47] = (*c >> 4) & 0x7;
- xmc[48] = (*c >> 1) & 0x7;
- xmc[49] = (*c++ & 0x1) << 2;
- xmc[49] |= (*c >> 6) & 0x3;
- xmc[50] = (*c >> 3) & 0x7;
- xmc[51] = *c & 0x7; /* 33 */
- }
-
- return 0;
-}
diff --git a/1.2-netsec/codecs/gsm/src/gsm_implode.c b/1.2-netsec/codecs/gsm/src/gsm_implode.c
deleted file mode 100644
index 453b8cf39..000000000
--- a/1.2-netsec/codecs/gsm/src/gsm_implode.c
+++ /dev/null
@@ -1,515 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include "private.h"
-
-#include "gsm.h"
-#include "proto.h"
-
-void gsm_implode P3((s, source, c), gsm s, gsm_signal * source, gsm_byte * c)
-{
- /* variable size index
-
- GSM_MAGIC 4 -
-
- LARc[0] 6 0
- LARc[1] 6 1
- LARc[2] 5 2
- LARc[3] 5 3
- LARc[4] 4 4
- LARc[5] 4 5
- LARc[6] 3 6
- LARc[7] 3 7
-
- Nc[0] 7 8
- bc[0] 2 9
- Mc[0] 2 10
- xmaxc[0] 6 11
- xmc[0] 3 12
- xmc[1] 3 13
- xmc[2] 3 14
- xmc[3] 3 15
- xmc[4] 3 16
- xmc[5] 3 17
- xmc[6] 3 18
- xmc[7] 3 19
- xmc[8] 3 20
- xmc[9] 3 21
- xmc[10] 3 22
- xmc[11] 3 23
- xmc[12] 3 24
-
- Nc[1] 7 25
- bc[1] 2 26
- Mc[1] 2 27
- xmaxc[1] 6 28
- xmc[13] 3 29
- xmc[14] 3 30
- xmc[15] 3 31
- xmc[16] 3 32
- xmc[17] 3 33
- xmc[18] 3 34
- xmc[19] 3 35
- xmc[20] 3 36
- xmc[21] 3 37
- xmc[22] 3 38
- xmc[23] 3 39
- xmc[24] 3 40
- xmc[25] 3 41
-
- Nc[2] 7 42
- bc[2] 2 43
- Mc[2] 2 44
- xmaxc[2] 6 45
- xmc[26] 3 46
- xmc[27] 3 47
- xmc[28] 3 48
- xmc[29] 3 49
- xmc[30] 3 50
- xmc[31] 3 51
- xmc[32] 3 52
- xmc[33] 3 53
- xmc[34] 3 54
- xmc[35] 3 55
- xmc[36] 3 56
- xmc[37] 3 57
- xmc[38] 3 58
-
- Nc[3] 7 59
- bc[3] 2 60
- Mc[3] 2 61
- xmaxc[3] 6 62
- xmc[39] 3 63
- xmc[40] 3 64
- xmc[41] 3 65
- xmc[42] 3 66
- xmc[43] 3 67
- xmc[44] 3 68
- xmc[45] 3 69
- xmc[46] 3 70
- xmc[47] 3 71
- xmc[48] 3 72
- xmc[49] 3 73
- xmc[50] 3 74
- xmc[51] 3 75
- */
-
- /* There are 76 parameters per frame. The first eight are
- * unique. The remaining 68 are four identical subframes of
- * 17 parameters each. gsm_implode converts from a representation
- * of these parameters as values in one array of signed words
- * to the "packed" version of a GSM frame.
- */
-
-# define LARc source
-# define Nc *((gsm_signal (*) [17])(source + 8))
-# define bc *((gsm_signal (*) [17])(source + 9))
-# define Mc *((gsm_signal (*) [17])(source + 10))
-# define xmaxc *((gsm_signal (*) [17])(source + 11))
-
-#ifdef WAV49
- if (s->wav_fmt) {
-
- uword sr = 0;
- if (s->frame_index == 0) {
-
- sr = *c++;
- LARc[0] = sr & 0x3f; sr >>= 6;
- sr |= (uword)*c++ << 2;
- LARc[1] = sr & 0x3f; sr >>= 6;
- sr |= (uword)*c++ << 4;
- LARc[2] = sr & 0x1f; sr >>= 5;
- LARc[3] = sr & 0x1f; sr >>= 5;
- sr |= (uword)*c++ << 2;
- LARc[4] = sr & 0xf; sr >>= 4;
- LARc[5] = sr & 0xf; sr >>= 4;
- sr |= (uword)*c++ << 2; /* 5 */
- LARc[6] = sr & 0x7; sr >>= 3;
- LARc[7] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[0] = sr & 0x7f; sr >>= 7;
- bc[0] = sr & 0x3; sr >>= 2;
- Mc[0] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[0] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (source + 12)
- xmc[0] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[1] = sr & 0x7; sr >>= 3;
- xmc[2] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[3] = sr & 0x7; sr >>= 3;
- xmc[4] = sr & 0x7; sr >>= 3;
- xmc[5] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 10 */
- xmc[6] = sr & 0x7; sr >>= 3;
- xmc[7] = sr & 0x7; sr >>= 3;
- xmc[8] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[9] = sr & 0x7; sr >>= 3;
- xmc[10] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[11] = sr & 0x7; sr >>= 3;
- xmc[12] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[1] = sr & 0x7f; sr >>= 7;
- bc[1] = sr & 0x3; sr >>= 2;
- Mc[1] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[1] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (source + 29 - 13)
- xmc[13] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 15 */
- xmc[14] = sr & 0x7; sr >>= 3;
- xmc[15] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[16] = sr & 0x7; sr >>= 3;
- xmc[17] = sr & 0x7; sr >>= 3;
- xmc[18] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[19] = sr & 0x7; sr >>= 3;
- xmc[20] = sr & 0x7; sr >>= 3;
- xmc[21] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[22] = sr & 0x7; sr >>= 3;
- xmc[23] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[24] = sr & 0x7; sr >>= 3;
- xmc[25] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4; /* 20 */
- Nc[2] = sr & 0x7f; sr >>= 7;
- bc[2] = sr & 0x3; sr >>= 2;
- Mc[2] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[2] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (source + 46 - 26)
- xmc[26] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[27] = sr & 0x7; sr >>= 3;
- xmc[28] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[29] = sr & 0x7; sr >>= 3;
- xmc[30] = sr & 0x7; sr >>= 3;
- xmc[31] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[32] = sr & 0x7; sr >>= 3;
- xmc[33] = sr & 0x7; sr >>= 3;
- xmc[34] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 25 */
- xmc[35] = sr & 0x7; sr >>= 3;
- xmc[36] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[37] = sr & 0x7; sr >>= 3;
- xmc[38] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[3] = sr & 0x7f; sr >>= 7;
- bc[3] = sr & 0x3; sr >>= 2;
- Mc[3] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[3] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (source + 63 - 39)
-
- xmc[39] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[40] = sr & 0x7; sr >>= 3;
- xmc[41] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2; /* 30 */
- xmc[42] = sr & 0x7; sr >>= 3;
- xmc[43] = sr & 0x7; sr >>= 3;
- xmc[44] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[45] = sr & 0x7; sr >>= 3;
- xmc[46] = sr & 0x7; sr >>= 3;
- xmc[47] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[48] = sr & 0x7; sr >>= 3;
- xmc[49] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[50] = sr & 0x7; sr >>= 3;
- xmc[51] = sr & 0x7; sr >>= 3;
-
- s->frame_chain = sr & 0xf;
- }
- else {
- sr = s->frame_chain;
- sr |= (uword)*c++ << 4; /* 1 */
- LARc[0] = sr & 0x3f; sr >>= 6;
- LARc[1] = sr & 0x3f; sr >>= 6;
- sr = *c++;
- LARc[2] = sr & 0x1f; sr >>= 5;
- sr |= (uword)*c++ << 3;
- LARc[3] = sr & 0x1f; sr >>= 5;
- LARc[4] = sr & 0xf; sr >>= 4;
- sr |= (uword)*c++ << 2;
- LARc[5] = sr & 0xf; sr >>= 4;
- LARc[6] = sr & 0x7; sr >>= 3;
- LARc[7] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 5 */
- Nc[0] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[0] = sr & 0x3; sr >>= 2;
- Mc[0] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[0] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (source + 12)
- xmc[0] = sr & 0x7; sr >>= 3;
- xmc[1] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[2] = sr & 0x7; sr >>= 3;
- xmc[3] = sr & 0x7; sr >>= 3;
- xmc[4] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[5] = sr & 0x7; sr >>= 3;
- xmc[6] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2; /* 10 */
- xmc[7] = sr & 0x7; sr >>= 3;
- xmc[8] = sr & 0x7; sr >>= 3;
- xmc[9] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[10] = sr & 0x7; sr >>= 3;
- xmc[11] = sr & 0x7; sr >>= 3;
- xmc[12] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[1] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[1] = sr & 0x3; sr >>= 2;
- Mc[1] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[1] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (source + 29 - 13)
- xmc[13] = sr & 0x7; sr >>= 3;
- xmc[14] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 15 */
- xmc[15] = sr & 0x7; sr >>= 3;
- xmc[16] = sr & 0x7; sr >>= 3;
- xmc[17] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[18] = sr & 0x7; sr >>= 3;
- xmc[19] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[20] = sr & 0x7; sr >>= 3;
- xmc[21] = sr & 0x7; sr >>= 3;
- xmc[22] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[23] = sr & 0x7; sr >>= 3;
- xmc[24] = sr & 0x7; sr >>= 3;
- xmc[25] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[2] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1; /* 20 */
- bc[2] = sr & 0x3; sr >>= 2;
- Mc[2] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[2] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (source + 46 - 26)
- xmc[26] = sr & 0x7; sr >>= 3;
- xmc[27] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[28] = sr & 0x7; sr >>= 3;
- xmc[29] = sr & 0x7; sr >>= 3;
- xmc[30] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[31] = sr & 0x7; sr >>= 3;
- xmc[32] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[33] = sr & 0x7; sr >>= 3;
- xmc[34] = sr & 0x7; sr >>= 3;
- xmc[35] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 25 */
- xmc[36] = sr & 0x7; sr >>= 3;
- xmc[37] = sr & 0x7; sr >>= 3;
- xmc[38] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[3] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[3] = sr & 0x3; sr >>= 2;
- Mc[3] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[3] = sr & 0x3f; sr >>= 6;
-#undef xmc
-#define xmc (source + 63 - 39)
-
- xmc[39] = sr & 0x7; sr >>= 3;
- xmc[40] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[41] = sr & 0x7; sr >>= 3;
- xmc[42] = sr & 0x7; sr >>= 3;
- xmc[43] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 30 */
- xmc[44] = sr & 0x7; sr >>= 3;
- xmc[45] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[46] = sr & 0x7; sr >>= 3;
- xmc[47] = sr & 0x7; sr >>= 3;
- xmc[48] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[49] = sr & 0x7; sr >>= 3;
- xmc[50] = sr & 0x7; sr >>= 3;
- xmc[51] = sr & 0x7; sr >>= 3;
- }
- }
- else
-#endif
- {
-
- *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */
- | ((LARc[0] >> 2) & 0xF);
- *c++ = ((LARc[0] & 0x3) << 6)
- | (LARc[1] & 0x3F);
- *c++ = ((LARc[2] & 0x1F) << 3)
- | ((LARc[3] >> 2) & 0x7);
- *c++ = ((LARc[3] & 0x3) << 6)
- | ((LARc[4] & 0xF) << 2)
- | ((LARc[5] >> 2) & 0x3);
- *c++ = ((LARc[5] & 0x3) << 6)
- | ((LARc[6] & 0x7) << 3)
- | (LARc[7] & 0x7);
-
-
- *c++ = ((Nc[0] & 0x7F) << 1)
-
-
- | ((bc[0] >> 1) & 0x1);
- *c++ = ((bc[0] & 0x1) << 7)
-
-
- | ((Mc[0] & 0x3) << 5)
-
- | ((xmaxc[0] >> 1) & 0x1F);
- *c++ = ((xmaxc[0] & 0x1) << 7)
-
-#undef xmc
-#define xmc (source + 12)
-
- | ((xmc[0] & 0x7) << 4)
- | ((xmc[1] & 0x7) << 1)
- | ((xmc[2] >> 2) & 0x1);
- *c++ = ((xmc[2] & 0x3) << 6)
- | ((xmc[3] & 0x7) << 3)
- | (xmc[4] & 0x7);
- *c++ = ((xmc[5] & 0x7) << 5) /* 10 */
- | ((xmc[6] & 0x7) << 2)
- | ((xmc[7] >> 1) & 0x3);
- *c++ = ((xmc[7] & 0x1) << 7)
- | ((xmc[8] & 0x7) << 4)
- | ((xmc[9] & 0x7) << 1)
- | ((xmc[10] >> 2) & 0x1);
- *c++ = ((xmc[10] & 0x3) << 6)
- | ((xmc[11] & 0x7) << 3)
- | (xmc[12] & 0x7);
-
-
- *c++ = ((Nc[1] & 0x7F) << 1)
-
-
- | ((bc[1] >> 1) & 0x1);
- *c++ = ((bc[1] & 0x1) << 7)
-
-
- | ((Mc[1] & 0x3) << 5)
-
-
- | ((xmaxc[1] >> 1) & 0x1F);
- *c++ = ((xmaxc[1] & 0x1) << 7)
-
-#undef xmc
-#define xmc (source + 29 - 13)
-
- | ((xmc[13] & 0x7) << 4)
- | ((xmc[14] & 0x7) << 1)
- | ((xmc[15] >> 2) & 0x1);
- *c++ = ((xmc[15] & 0x3) << 6)
- | ((xmc[16] & 0x7) << 3)
- | (xmc[17] & 0x7);
- *c++ = ((xmc[18] & 0x7) << 5)
- | ((xmc[19] & 0x7) << 2)
- | ((xmc[20] >> 1) & 0x3);
- *c++ = ((xmc[20] & 0x1) << 7)
- | ((xmc[21] & 0x7) << 4)
- | ((xmc[22] & 0x7) << 1)
- | ((xmc[23] >> 2) & 0x1);
- *c++ = ((xmc[23] & 0x3) << 6)
- | ((xmc[24] & 0x7) << 3)
- | (xmc[25] & 0x7);
-
-
- *c++ = ((Nc[2] & 0x7F) << 1) /* 20 */
-
-
- | ((bc[2] >> 1) & 0x1);
- *c++ = ((bc[2] & 0x1) << 7)
-
-
- | ((Mc[2] & 0x3) << 5)
-
-
- | ((xmaxc[2] >> 1) & 0x1F);
- *c++ = ((xmaxc[2] & 0x1) << 7)
-
-#undef xmc
-#define xmc (source + 46 - 26)
-
- | ((xmc[26] & 0x7) << 4)
- | ((xmc[27] & 0x7) << 1)
- | ((xmc[28] >> 2) & 0x1);
- *c++ = ((xmc[28] & 0x3) << 6)
- | ((xmc[29] & 0x7) << 3)
- | (xmc[30] & 0x7);
- *c++ = ((xmc[31] & 0x7) << 5)
- | ((xmc[32] & 0x7) << 2)
- | ((xmc[33] >> 1) & 0x3);
- *c++ = ((xmc[33] & 0x1) << 7)
- | ((xmc[34] & 0x7) << 4)
- | ((xmc[35] & 0x7) << 1)
- | ((xmc[36] >> 2) & 0x1);
- *c++ = ((xmc[36] & 0x3) << 6)
- | ((xmc[37] & 0x7) << 3)
- | (xmc[38] & 0x7);
-
-
- *c++ = ((Nc[3] & 0x7F) << 1)
-
-
- | ((bc[3] >> 1) & 0x1);
- *c++ = ((bc[3] & 0x1) << 7)
-
-
- | ((Mc[3] & 0x3) << 5)
-
-
- | ((xmaxc[3] >> 1) & 0x1F);
- *c++ = ((xmaxc[3] & 0x1) << 7)
-
-#undef xmc
-#define xmc (source + 63 - 39)
-
- | ((xmc[39] & 0x7) << 4)
- | ((xmc[40] & 0x7) << 1)
- | ((xmc[41] >> 2) & 0x1);
- *c++ = ((xmc[41] & 0x3) << 6) /* 30 */
- | ((xmc[42] & 0x7) << 3)
- | (xmc[43] & 0x7);
- *c++ = ((xmc[44] & 0x7) << 5)
- | ((xmc[45] & 0x7) << 2)
- | ((xmc[46] >> 1) & 0x3);
- *c++ = ((xmc[46] & 0x1) << 7)
- | ((xmc[47] & 0x7) << 4)
- | ((xmc[48] & 0x7) << 1)
- | ((xmc[49] >> 2) & 0x1);
- *c++ = ((xmc[49] & 0x3) << 6)
- | ((xmc[50] & 0x7) << 3)
- | (xmc[51] & 0x7);
- }
-}
diff --git a/1.2-netsec/codecs/gsm/src/gsm_option.c b/1.2-netsec/codecs/gsm/src/gsm_option.c
deleted file mode 100644
index 280780132..000000000
--- a/1.2-netsec/codecs/gsm/src/gsm_option.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include "private.h"
-
-#include "gsm.h"
-#include "proto.h"
-
-int gsm_option P3((r, opt, val), gsm r, int opt, int * val)
-{
- int result = -1;
-
- switch (opt) {
- case GSM_OPT_LTP_CUT:
-#ifdef LTP_CUT
- result = r->ltp_cut;
- if (val) r->ltp_cut = *val;
-#endif
- break;
-
- case GSM_OPT_VERBOSE:
-#ifndef NDEBUG
- result = r->verbose;
- if (val) r->verbose = *val;
-#endif
- break;
-
- case GSM_OPT_FAST:
-
-#if defined(FAST) && defined(USE_FLOAT_MUL)
- result = r->fast;
- if (val) r->fast = !!*val;
-#endif
- break;
-
- case GSM_OPT_FRAME_CHAIN:
-
-#ifdef WAV49
- result = r->frame_chain;
- if (val) r->frame_chain = *val;
-#endif
- break;
-
- case GSM_OPT_FRAME_INDEX:
-
-#ifdef WAV49
- result = r->frame_index;
- if (val) r->frame_index = *val;
-#endif
- break;
-
- case GSM_OPT_WAV49:
-
-#ifdef WAV49
- result = r->wav_fmt;
- if (val) r->wav_fmt = !!*val;
-#endif
- break;
-
- default:
- break;
- }
- return result;
-}
diff --git a/1.2-netsec/codecs/gsm/src/gsm_print.c b/1.2-netsec/codecs/gsm/src/gsm_print.c
deleted file mode 100644
index af745bc48..000000000
--- a/1.2-netsec/codecs/gsm/src/gsm_print.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include <stdio.h>
-
-#include "private.h"
-
-#include "gsm.h"
-#include "proto.h"
-
-int gsm_print P3((f, s, c), FILE * f, gsm s, gsm_byte * c)
-{
- word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
-
- /* GSM_MAGIC = (*c >> 4) & 0xF; */
-
- if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1;
-
- LARc[0] = (*c++ & 0xF) << 2; /* 1 */
- LARc[0] |= (*c >> 6) & 0x3;
- LARc[1] = *c++ & 0x3F;
- LARc[2] = (*c >> 3) & 0x1F;
- LARc[3] = (*c++ & 0x7) << 2;
- LARc[3] |= (*c >> 6) & 0x3;
- LARc[4] = (*c >> 2) & 0xF;
- LARc[5] = (*c++ & 0x3) << 2;
- LARc[5] |= (*c >> 6) & 0x3;
- LARc[6] = (*c >> 3) & 0x7;
- LARc[7] = *c++ & 0x7;
-
-
- Nc[0] = (*c >> 1) & 0x7F;
- bc[0] = (*c++ & 0x1) << 1;
- bc[0] |= (*c >> 7) & 0x1;
- Mc[0] = (*c >> 5) & 0x3;
- xmaxc[0] = (*c++ & 0x1F) << 1;
- xmaxc[0] |= (*c >> 7) & 0x1;
- xmc[0] = (*c >> 4) & 0x7;
- xmc[1] = (*c >> 1) & 0x7;
- xmc[2] = (*c++ & 0x1) << 2;
- xmc[2] |= (*c >> 6) & 0x3;
- xmc[3] = (*c >> 3) & 0x7;
- xmc[4] = *c++ & 0x7;
- xmc[5] = (*c >> 5) & 0x7;
- xmc[6] = (*c >> 2) & 0x7;
- xmc[7] = (*c++ & 0x3) << 1; /* 10 */
- xmc[7] |= (*c >> 7) & 0x1;
- xmc[8] = (*c >> 4) & 0x7;
- xmc[9] = (*c >> 1) & 0x7;
- xmc[10] = (*c++ & 0x1) << 2;
- xmc[10] |= (*c >> 6) & 0x3;
- xmc[11] = (*c >> 3) & 0x7;
- xmc[12] = *c++ & 0x7;
-
- Nc[1] = (*c >> 1) & 0x7F;
- bc[1] = (*c++ & 0x1) << 1;
- bc[1] |= (*c >> 7) & 0x1;
- Mc[1] = (*c >> 5) & 0x3;
- xmaxc[1] = (*c++ & 0x1F) << 1;
- xmaxc[1] |= (*c >> 7) & 0x1;
- xmc[13] = (*c >> 4) & 0x7;
- xmc[14] = (*c >> 1) & 0x7;
- xmc[15] = (*c++ & 0x1) << 2;
- xmc[15] |= (*c >> 6) & 0x3;
- xmc[16] = (*c >> 3) & 0x7;
- xmc[17] = *c++ & 0x7;
- xmc[18] = (*c >> 5) & 0x7;
- xmc[19] = (*c >> 2) & 0x7;
- xmc[20] = (*c++ & 0x3) << 1;
- xmc[20] |= (*c >> 7) & 0x1;
- xmc[21] = (*c >> 4) & 0x7;
- xmc[22] = (*c >> 1) & 0x7;
- xmc[23] = (*c++ & 0x1) << 2;
- xmc[23] |= (*c >> 6) & 0x3;
- xmc[24] = (*c >> 3) & 0x7;
- xmc[25] = *c++ & 0x7;
-
-
- Nc[2] = (*c >> 1) & 0x7F;
- bc[2] = (*c++ & 0x1) << 1; /* 20 */
- bc[2] |= (*c >> 7) & 0x1;
- Mc[2] = (*c >> 5) & 0x3;
- xmaxc[2] = (*c++ & 0x1F) << 1;
- xmaxc[2] |= (*c >> 7) & 0x1;
- xmc[26] = (*c >> 4) & 0x7;
- xmc[27] = (*c >> 1) & 0x7;
- xmc[28] = (*c++ & 0x1) << 2;
- xmc[28] |= (*c >> 6) & 0x3;
- xmc[29] = (*c >> 3) & 0x7;
- xmc[30] = *c++ & 0x7;
- xmc[31] = (*c >> 5) & 0x7;
- xmc[32] = (*c >> 2) & 0x7;
- xmc[33] = (*c++ & 0x3) << 1;
- xmc[33] |= (*c >> 7) & 0x1;
- xmc[34] = (*c >> 4) & 0x7;
- xmc[35] = (*c >> 1) & 0x7;
- xmc[36] = (*c++ & 0x1) << 2;
- xmc[36] |= (*c >> 6) & 0x3;
- xmc[37] = (*c >> 3) & 0x7;
- xmc[38] = *c++ & 0x7;
-
- Nc[3] = (*c >> 1) & 0x7F;
- bc[3] = (*c++ & 0x1) << 1;
- bc[3] |= (*c >> 7) & 0x1;
- Mc[3] = (*c >> 5) & 0x3;
- xmaxc[3] = (*c++ & 0x1F) << 1;
- xmaxc[3] |= (*c >> 7) & 0x1;
-
- xmc[39] = (*c >> 4) & 0x7;
- xmc[40] = (*c >> 1) & 0x7;
- xmc[41] = (*c++ & 0x1) << 2;
- xmc[41] |= (*c >> 6) & 0x3;
- xmc[42] = (*c >> 3) & 0x7;
- xmc[43] = *c++ & 0x7; /* 30 */
- xmc[44] = (*c >> 5) & 0x7;
- xmc[45] = (*c >> 2) & 0x7;
- xmc[46] = (*c++ & 0x3) << 1;
- xmc[46] |= (*c >> 7) & 0x1;
- xmc[47] = (*c >> 4) & 0x7;
- xmc[48] = (*c >> 1) & 0x7;
- xmc[49] = (*c++ & 0x1) << 2;
- xmc[49] |= (*c >> 6) & 0x3;
- xmc[50] = (*c >> 3) & 0x7;
- xmc[51] = *c & 0x7; /* 33 */
-
- fprintf(f,
- "LARc:\t%2.2d %2.2d %2.2d %2.2d %2.2d %2.2d %2.2d %2.2d\n",
- LARc[0],LARc[1],LARc[2],LARc[3],LARc[4],LARc[5],LARc[6],LARc[7]);
-
- fprintf(f, "#1: Nc %4.4d bc %d Mc %d xmaxc %d\n",
- Nc[0], bc[0], Mc[0], xmaxc[0]);
- fprintf(f,
-"\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n",
- xmc[0],xmc[1],xmc[2],xmc[3],xmc[4],xmc[5],xmc[6],
- xmc[7],xmc[8],xmc[9],xmc[10],xmc[11],xmc[12] );
-
- fprintf(f, "#2: Nc %4.4d bc %d Mc %d xmaxc %d\n",
- Nc[1], bc[1], Mc[1], xmaxc[1]);
- fprintf(f,
-"\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n",
- xmc[13+0],xmc[13+1],xmc[13+2],xmc[13+3],xmc[13+4],xmc[13+5],
- xmc[13+6], xmc[13+7],xmc[13+8],xmc[13+9],xmc[13+10],xmc[13+11],
- xmc[13+12] );
-
- fprintf(f, "#3: Nc %4.4d bc %d Mc %d xmaxc %d\n",
- Nc[2], bc[2], Mc[2], xmaxc[2]);
- fprintf(f,
-"\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n",
- xmc[26+0],xmc[26+1],xmc[26+2],xmc[26+3],xmc[26+4],xmc[26+5],
- xmc[26+6], xmc[26+7],xmc[26+8],xmc[26+9],xmc[26+10],xmc[26+11],
- xmc[26+12] );
-
- fprintf(f, "#4: Nc %4.4d bc %d Mc %d xmaxc %d\n",
- Nc[3], bc[3], Mc[3], xmaxc[3]);
- fprintf(f,
-"\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n",
- xmc[39+0],xmc[39+1],xmc[39+2],xmc[39+3],xmc[39+4],xmc[39+5],
- xmc[39+6], xmc[39+7],xmc[39+8],xmc[39+9],xmc[39+10],xmc[39+11],
- xmc[39+12] );
-
- return 0;
-}
diff --git a/1.2-netsec/codecs/gsm/src/k6opt.h b/1.2-netsec/codecs/gsm/src/k6opt.h
deleted file mode 100644
index 16ea2ac8d..000000000
--- a/1.2-netsec/codecs/gsm/src/k6opt.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* k6opt.h vector functions optimized for MMX extensions to x86
- *
- * Copyright (C) 1999 by Stanley J. Brooks <stabro@megsinet.net>
- *
- * Any use of this software is permitted provided that this notice is not
- * removed and that neither the authors nor the Technische Universitaet Berlin
- * are deemed to have made any representations as to the suitability of this
- * software for any purpose nor are held responsible for any defects of
- * this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE;
- * not even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.
- *
- * Chicago, 03.12.1999
- * Stanley J. Brooks
- */
-
-extern void Weighting_filter P2((e, x),
- const word * e, /* signal [-5..0.39.44] IN */
- word * x /* signal [0..39] OUT */
-)
-;
-
-extern longword k6maxcc P3((wt,dp,Nc_out),
- const word *wt,
- const word *dp,
- word * Nc_out /* OUT */
-)
-;
-/*
- * k6maxmin(p,n,out[])
- * input p[n] is array of shorts (require n>0)
- * returns (long) maximum absolute value..
- * if out!=NULL, also returns out[0] the maximum and out[1] the minimum
- */
-extern longword k6maxmin P3((p,n,out),
- const word *p,
- int n,
- word *out /* out[0] is max, out[1] is min */
-)
-;
-
-extern longword k6iprod P3((p,q,n),
- const word *p,
- const word *q,
- int n
-)
-;
-
-/*
- * k6vsraw(p,n,bits)
- * input p[n] is array of shorts (require n>0)
- * shift/round each to the right by bits>=0 bits.
- */
-extern void k6vsraw P3((p,n,bits),
- const word *p,
- int n,
- int bits
-)
-;
-
-/*
- * k6vsllw(p,n,bits)
- * input p[n] is array of shorts (require n>0)
- * shift each to the left by bits>=0 bits.
- */
-extern void k6vsllw P3((p,n,bits),
- const word *p,
- int n,
- int bits
-)
-;
-
-#if 1 /* there isn't any significant speed gain from mmx here: */
-extern void Short_term_analysis_filteringx P4((u0,rp0,k_n,s),
- register word * u0,
- register word * rp0, /* [0..7] IN */
- register int k_n, /* k_end - k_start */
- register word * s /* [0..n-1] IN/OUT */
-)
-;
-/*
-#define Short_term_analysis_filtering Short_term_analysis_filteringx
-*/
-#endif
diff --git a/1.2-netsec/codecs/gsm/src/k6opt.s b/1.2-netsec/codecs/gsm/src/k6opt.s
deleted file mode 100644
index d84d54cbf..000000000
--- a/1.2-netsec/codecs/gsm/src/k6opt.s
+++ /dev/null
@@ -1,739 +0,0 @@
- .file "k6opt.s"
- .version "01.01"
-/* gcc2_compiled.: */
-.section .rodata
- .align 4
- .type coefs,@object
- .size coefs,24
-coefs:
- .value -134
- .value -374
- .value 0
- .value 2054
- .value 5741
- .value 8192
- .value 5741
- .value 2054
- .value 0
- .value -374
- .value -134
- .value 0
-.text
- .align 4
-/* void Weighting_filter (const short *e, short *x) */
-.globl Weighting_filter
- .type Weighting_filter,@function
-Weighting_filter:
- pushl %ebp
- movl %esp,%ebp
- pushl %edi
- pushl %esi
- pushl %ebx
- movl 12(%ebp),%edi
- movl 8(%ebp),%ebx
- addl $-10,%ebx
- emms
- movl $0x1000,%eax; movd %eax,%mm5 /* for rounding */
- movq coefs,%mm1
- movq coefs+8,%mm2
- movq coefs+16,%mm3
- xorl %esi,%esi
- .p2align 2
-.L21:
- movq (%ebx,%esi,2),%mm0
- pmaddwd %mm1,%mm0
-
- movq 8(%ebx,%esi,2),%mm4
- pmaddwd %mm2,%mm4
- paddd %mm4,%mm0
-
- movq 16(%ebx,%esi,2),%mm4
- pmaddwd %mm3,%mm4
- paddd %mm4,%mm0
-
- movq %mm0,%mm4
- punpckhdq %mm0,%mm4 /* mm4 has high int32 of mm0 dup'd */
- paddd %mm4,%mm0;
-
- paddd %mm5,%mm0 /* add for roundoff */
- psrad $13,%mm0
- packssdw %mm0,%mm0
- movd %mm0,%eax /* ax has result */
- movw %ax,(%edi,%esi,2)
- incl %esi
- cmpl $39,%esi
- jle .L21
- emms
- popl %ebx
- popl %esi
- popl %edi
- leave
- ret
-.Lfe1:
- .size Weighting_filter,.Lfe1-Weighting_filter
-
-.macro ccstep n
-.if \n
- movq \n(%edi),%mm1
- movq \n(%esi),%mm2
-.else
- movq (%edi),%mm1
- movq (%esi),%mm2
-.endif
- pmaddwd %mm2,%mm1
- paddd %mm1,%mm0
-.endm
-
- .align 4
-/* long k6maxcc(const short *wt, const short *dp, short *Nc_out) */
-.globl k6maxcc
- .type k6maxcc,@function
-k6maxcc:
- pushl %ebp
- movl %esp,%ebp
- pushl %edi
- pushl %esi
- pushl %ebx
- emms
- movl 8(%ebp),%edi
- movl 12(%ebp),%esi
- movl $0,%edx /* will be maximum inner-product */
- movl $40,%ebx
- movl %ebx,%ecx /* will be index of max inner-product */
- subl $80,%esi
- .p2align 2
-.L41:
- movq (%edi),%mm0
- movq (%esi),%mm2
- pmaddwd %mm2,%mm0
- ccstep 8
- ccstep 16
- ccstep 24
- ccstep 32
- ccstep 40
- ccstep 48
- ccstep 56
- ccstep 64
- ccstep 72
-
- movq %mm0,%mm1
- punpckhdq %mm0,%mm1 /* mm1 has high int32 of mm0 dup'd */
- paddd %mm1,%mm0;
- movd %mm0,%eax /* eax has result */
-
- cmpl %edx,%eax
- jle .L40
- movl %eax,%edx
- movl %ebx,%ecx
- .p2align 2
-.L40:
- subl $2,%esi
- incl %ebx
- cmpl $120,%ebx
- jle .L41
- movl 16(%ebp),%eax
- movw %cx,(%eax)
- movl %edx,%eax
- emms
- popl %ebx
- popl %esi
- popl %edi
- leave
- ret
-.Lfe2:
- .size k6maxcc,.Lfe2-k6maxcc
-
-
- .align 4
-/* long k6iprod (const short *p, const short *q, int n) */
-.globl k6iprod
- .type k6iprod,@function
-k6iprod:
- pushl %ebp
- movl %esp,%ebp
- pushl %edi
- pushl %esi
- emms
- pxor %mm0,%mm0
- movl 8(%ebp),%esi
- movl 12(%ebp),%edi
- movl 16(%ebp),%eax
- leal -32(%esi,%eax,2),%edx /* edx = top - 32 */
-
- cmpl %edx,%esi; ja .L202
-
- .p2align 2
-.L201:
- ccstep 0
- ccstep 8
- ccstep 16
- ccstep 24
-
- addl $32,%esi
- addl $32,%edi
- cmpl %edx,%esi; jbe .L201
-
- .p2align 2
-.L202:
- addl $24,%edx /* now edx = top-8 */
- cmpl %edx,%esi; ja .L205
-
- .p2align 2
-.L203:
- ccstep 0
-
- addl $8,%esi
- addl $8,%edi
- cmpl %edx,%esi; jbe .L203
-
- .p2align 2
-.L205:
- addl $4,%edx /* now edx = top-4 */
- cmpl %edx,%esi; ja .L207
-
- movd (%edi),%mm1
- movd (%esi),%mm2
- pmaddwd %mm2,%mm1
- paddd %mm1,%mm0
-
- addl $4,%esi
- addl $4,%edi
-
- .p2align 2
-.L207:
- addl $2,%edx /* now edx = top-2 */
- cmpl %edx,%esi; ja .L209
-
- movswl (%edi),%eax
- movd %eax,%mm1
- movswl (%esi),%eax
- movd %eax,%mm2
- pmaddwd %mm2,%mm1
- paddd %mm1,%mm0
-
- .p2align 2
-.L209:
- movq %mm0,%mm1
- punpckhdq %mm0,%mm1 /* mm1 has high int32 of mm0 dup'd */
- paddd %mm1,%mm0;
- movd %mm0,%eax /* eax has result */
-
- emms
- popl %esi
- popl %edi
- leave
- ret
-.Lfe3:
- .size k6iprod,.Lfe3-k6iprod
-
-
- .align 4
-/* void k6vsraw P3((short *p, int n, int bits) */
-.globl k6vsraw
- .type k6vsraw,@function
-k6vsraw:
- pushl %ebp
- movl %esp,%ebp
- pushl %esi
- movl 8(%ebp),%esi
- movl 16(%ebp),%ecx
- andl %ecx,%ecx; jle .L399
- movl 12(%ebp),%eax
- leal -16(%esi,%eax,2),%edx /* edx = top - 16 */
- emms
- movd %ecx,%mm3
- movq ones,%mm2
- psllw %mm3,%mm2; psrlw $1,%mm2
- cmpl %edx,%esi; ja .L306
-
- .p2align 2
-.L302: /* 8 words per iteration */
- movq (%esi),%mm0
- movq 8(%esi),%mm1
- paddsw %mm2,%mm0
- psraw %mm3,%mm0;
- paddsw %mm2,%mm1
- psraw %mm3,%mm1;
- movq %mm0,(%esi)
- movq %mm1,8(%esi)
- addl $16,%esi
- cmpl %edx,%esi
- jbe .L302
-
- .p2align 2
-.L306:
- addl $12,%edx /* now edx = top-4 */
- cmpl %edx,%esi; ja .L310
-
- .p2align 2
-.L308: /* do up to 6 words, two at a time */
- movd (%esi),%mm0
- paddsw %mm2,%mm0
- psraw %mm3,%mm0;
- movd %mm0,(%esi)
- addl $4,%esi
- cmpl %edx,%esi
- jbe .L308
-
- .p2align 2
-.L310:
- addl $2,%edx /* now edx = top-2 */
- cmpl %edx,%esi; ja .L315
-
- movzwl (%esi),%eax
- movd %eax,%mm0
- paddsw %mm2,%mm0
- psraw %mm3,%mm0;
- movd %mm0,%eax
- movw %ax,(%esi)
-
- .p2align 2
-.L315:
- emms
-.L399:
- popl %esi
- leave
- ret
-.Lfe4:
- .size k6vsraw,.Lfe4-k6vsraw
-
- .align 4
-/* void k6vsllw P3((short *p, int n, int bits) */
-.globl k6vsllw
- .type k6vsllw,@function
-k6vsllw:
- pushl %ebp
- movl %esp,%ebp
- pushl %esi
- movl 8(%ebp),%esi
- movl 16(%ebp),%ecx
- andl %ecx,%ecx; jle .L499
- movl 12(%ebp),%eax
- leal -16(%esi,%eax,2),%edx /* edx = top - 16 */
- emms
- movd %ecx,%mm3
- cmpl %edx,%esi; ja .L406
-
- .p2align 2
-.L402: /* 8 words per iteration */
- movq (%esi),%mm0
- movq 8(%esi),%mm1
- psllw %mm3,%mm0;
- psllw %mm3,%mm1;
- movq %mm0,(%esi)
- movq %mm1,8(%esi)
- addl $16,%esi
- cmpl %edx,%esi
- jbe .L402
-
- .p2align 2
-.L406:
- addl $12,%edx /* now edx = top-4 */
- cmpl %edx,%esi; ja .L410
-
- .p2align 2
-.L408: /* do up to 6 words, two at a time */
- movd (%esi),%mm0
- psllw %mm3,%mm0;
- movd %mm0,(%esi)
- addl $4,%esi
- cmpl %edx,%esi
- jbe .L408
-
- .p2align 2
-.L410:
- addl $2,%edx /* now edx = top-2 */
- cmpl %edx,%esi; ja .L415
-
- movzwl (%esi),%eax
- movd %eax,%mm0
- psllw %mm3,%mm0;
- movd %mm0,%eax
- movw %ax,(%esi)
-
- .p2align 2
-.L415:
- emms
-.L499:
- popl %esi
- leave
- ret
-.Lfe5:
- .size k6vsllw,.Lfe5-k6vsllw
-
-
-.section .rodata
- .align 4
- .type extremes,@object
- .size extremes,8
-extremes:
- .long 0x80008000
- .long 0x7fff7fff
- .type ones,@object
- .size ones,8
-ones:
- .long 0x00010001
- .long 0x00010001
-
-.text
- .align 4
-/* long k6maxmin (const short *p, int n, short *out) */
-.globl k6maxmin
- .type k6maxmin,@function
-k6maxmin:
- pushl %ebp
- movl %esp,%ebp
- pushl %esi
- emms
- movl 8(%ebp),%esi
- movl 12(%ebp),%eax
- leal -8(%esi,%eax,2),%edx
-
- cmpl %edx,%esi
- jbe .L52
- movd extremes,%mm0
- movd extremes+4,%mm1
- jmp .L58
-
- .p2align 2
-.L52:
- movq (%esi),%mm0 /* mm0 will be max's */
- movq %mm0,%mm1 /* mm1 will be min's */
- addl $8,%esi
- cmpl %edx,%esi
- ja .L56
-
- .p2align 2
-.L54:
- movq (%esi),%mm2
-
- movq %mm2,%mm3
- pcmpgtw %mm0,%mm3 /* mm3 is bitmask for words where mm2 > mm0 */
- movq %mm3,%mm4
- pand %mm2,%mm3 /* mm3 is mm2 masked to new max's */
- pandn %mm0,%mm4 /* mm4 is mm0 masked to its max's */
- por %mm3,%mm4
- movq %mm4,%mm0 /* now mm0 is updated max's */
-
- movq %mm1,%mm3
- pcmpgtw %mm2,%mm3 /* mm3 is bitmask for words where mm2 < mm1 */
- pand %mm3,%mm2 /* mm2 is mm2 masked to new min's */
- pandn %mm1,%mm3 /* mm3 is mm1 masked to its min's */
- por %mm3,%mm2
- movq %mm2,%mm1 /* now mm1 is updated min's */
-
- addl $8,%esi
- cmpl %edx,%esi
- jbe .L54
-
- .p2align 2
-.L56: /* merge down the 4-word max/mins to lower 2 words */
-
- movq %mm0,%mm2
- psrlq $32,%mm2
- movq %mm2,%mm3
- pcmpgtw %mm0,%mm3 /* mm3 is bitmask for words where mm2 > mm0 */
- pand %mm3,%mm2 /* mm2 is mm2 masked to new max's */
- pandn %mm0,%mm3 /* mm3 is mm0 masked to its max's */
- por %mm3,%mm2
- movq %mm2,%mm0 /* now mm0 is updated max's */
-
- movq %mm1,%mm2
- psrlq $32,%mm2
- movq %mm1,%mm3
- pcmpgtw %mm2,%mm3 /* mm3 is bitmask for words where mm2 < mm1 */
- pand %mm3,%mm2 /* mm2 is mm2 masked to new min's */
- pandn %mm1,%mm3 /* mm3 is mm1 masked to its min's */
- por %mm3,%mm2
- movq %mm2,%mm1 /* now mm1 is updated min's */
-
- .p2align 2
-.L58:
- addl $4,%edx /* now dx = top-4 */
- cmpl %edx,%esi
- ja .L62
- /* here, there are >= 2 words of input remaining */
- movd (%esi),%mm2
-
- movq %mm2,%mm3
- pcmpgtw %mm0,%mm3 /* mm3 is bitmask for words where mm2 > mm0 */
- movq %mm3,%mm4
- pand %mm2,%mm3 /* mm3 is mm2 masked to new max's */
- pandn %mm0,%mm4 /* mm4 is mm0 masked to its max's */
- por %mm3,%mm4
- movq %mm4,%mm0 /* now mm0 is updated max's */
-
- movq %mm1,%mm3
- pcmpgtw %mm2,%mm3 /* mm3 is bitmask for words where mm2 < mm1 */
- pand %mm3,%mm2 /* mm2 is mm2 masked to new min's */
- pandn %mm1,%mm3 /* mm3 is mm1 masked to its min's */
- por %mm3,%mm2
- movq %mm2,%mm1 /* now mm1 is updated min's */
-
- addl $4,%esi
-
- .p2align 2
-.L62:
- /* merge down the 2-word max/mins to 1 word */
-
- movq %mm0,%mm2
- psrlq $16,%mm2
- movq %mm2,%mm3
- pcmpgtw %mm0,%mm3 /* mm3 is bitmask for words where mm2 > mm0 */
- pand %mm3,%mm2 /* mm2 is mm2 masked to new max's */
- pandn %mm0,%mm3 /* mm3 is mm0 masked to its max's */
- por %mm3,%mm2
- movd %mm2,%ecx /* cx is max so far */
-
- movq %mm1,%mm2
- psrlq $16,%mm2
- movq %mm1,%mm3
- pcmpgtw %mm2,%mm3 /* mm3 is bitmask for words where mm2 < mm1 */
- pand %mm3,%mm2 /* mm2 is mm2 masked to new min's */
- pandn %mm1,%mm3 /* mm3 is mm1 masked to its min's */
- por %mm3,%mm2
- movd %mm2,%eax /* ax is min so far */
-
- addl $2,%edx /* now dx = top-2 */
- cmpl %edx,%esi
- ja .L65
-
- /* here, there is one word of input left */
- cmpw (%esi),%cx
- jge .L64
- movw (%esi),%cx
- .p2align 2
-.L64:
- cmpw (%esi),%ax
- jle .L65
- movw (%esi),%ax
-
- .p2align 2
-.L65: /* (finally!) cx is the max, ax the min */
- movswl %cx,%ecx
- movswl %ax,%eax
-
- movl 16(%ebp),%edx /* ptr to output max,min vals */
- andl %edx,%edx; jz .L77
- movw %cx,(%edx) /* max */
- movw %ax,2(%edx) /* min */
- .p2align 2
-.L77:
- /* now calculate max absolute val */
- negl %eax
- cmpl %ecx,%eax
- jge .L81
- movl %ecx,%eax
- .p2align 2
-.L81:
- emms
- popl %esi
- leave
- ret
-.Lfe6:
- .size k6maxmin,.Lfe6-k6maxmin
-
-/* void Short_term_analysis_filtering (short *u0, const short *rp0, int kn, short *s) */
- .equiv pm_u0,8
- .equiv pm_rp0,12
- .equiv pm_kn,16
- .equiv pm_s,20
- .equiv lv_u_top,-4
- .equiv lv_s_top,-8
- .equiv lv_rp,-40 /* local version of rp0 with each word twice */
- .align 4
-.globl Short_term_analysis_filteringx
- .type Short_term_analysis_filteringx,@function
-Short_term_analysis_filteringx:
- pushl %ebp
- movl %esp,%ebp
- subl $40,%esp
- pushl %edi
- pushl %esi
-
- movl pm_rp0(%ebp),%esi;
- leal lv_rp(%ebp),%edi;
- cld
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- emms
- movl $0x4000,%eax;
- movd %eax,%mm4;
- punpckldq %mm4,%mm4 /* (0x00004000,0x00004000) for rounding dword product pairs */
-
- movl pm_u0(%ebp),%eax
- addl $16,%eax
- movl %eax,lv_u_top(%ebp) /* UTOP */
- movl pm_s(%ebp),%edx /* edx is local s ptr throughout below */
- movl pm_kn(%ebp),%eax
- leal (%edx,%eax,2),%eax
- movl %eax,lv_s_top(%ebp)
- cmpl %eax,%edx
- jae .L179
- .p2align 2
-.L181:
- leal lv_rp(%ebp),%esi /* RP */
- movl pm_u0(%ebp),%edi /* U */
- movw (%edx),%ax /* (0,DI) */
- roll $16,%eax
- movw (%edx),%ax /* (DI,DI) */
- .p2align 2
-.L185: /* RP is %esi */
- movl %eax,%ecx
- movw (%edi),%ax /* (DI,U) */
- movd (%esi),%mm3 /* mm3 is (0,0,RP,RP) */
- movw %cx,(%edi)
-
- movd %eax,%mm2 /* mm2 is (0,0,DI,U) */
- rorl $16,%eax
- movd %eax,%mm1 /* mm1 is (0,0,U,DI) */
-
- movq %mm1,%mm0
- pmullw %mm3,%mm0
- pmulhw %mm3,%mm1
- punpcklwd %mm1,%mm0 /* mm0 is (RP*U,RP*DI) */
- paddd %mm4,%mm0 /* mm4 is 0x00004000,0x00004000 */
- psrad $15,%mm0 /* (RP*U,RP*DI) adjusted */
- packssdw %mm0,%mm0 /* (*,*,RP*U,RP*DI) adjusted and saturated to word */
- paddsw %mm2,%mm0 /* mm0 is (?,?, DI', U') */
- movd %mm0,%eax /* (DI,U') */
-
- addl $2,%edi
- addl $4,%esi
- cmpl lv_u_top(%ebp),%edi
- jb .L185
-
- rorl $16,%eax
- movw %ax,(%edx) /* last DI goes to *s */
- addl $2,%edx /* next s */
- cmpl lv_s_top(%ebp),%edx
- jb .L181
- .p2align 2
-.L179:
- emms
- popl %esi
- popl %edi
- leave
- ret
-.Lfe7:
- .size Short_term_analysis_filteringx,.Lfe7-Short_term_analysis_filteringx
-
-.end
-
-/* 'as' macro's seem to be case-insensitive */
-.macro STEP n
-.if \n
- movd \n(%esi),%mm3 /* mm3 is (0,0,RP,RP) */
-.else
- movd (%esi),%mm3 /* mm3 is (0,0,RP,RP) */
-.endif
- movq %mm5,%mm1;
- movd %mm4,%ecx; movw %cx,%ax /* (DI,U) */
- psllq $48,%mm1; psrlq $16,%mm4; por %mm1,%mm4
- psllq $48,%mm0; psrlq $16,%mm5; por %mm0,%mm5
-
- movd %eax,%mm2 /* mm2 is (0,0,DI,U) */
- rorl $16,%eax
- movd %eax,%mm1 /* mm1 is (0,0,U,DI) */
-
- movq %mm1,%mm0
- pmullw %mm3,%mm0
- pmulhw %mm3,%mm1
- punpcklwd %mm1,%mm0 /* mm0 is (RP*U,RP*DI) */
- paddd %mm6,%mm0 /* mm6 is 0x00004000,0x00004000 */
- psrad $15,%mm0 /* (RP*U,RP*DI) adjusted */
- packssdw %mm0,%mm0 /* (*,*,RP*U,RP*DI) adjusted and saturated to word */
- paddsw %mm2,%mm0 /* mm0 is (?,?, DI', U') */
- movd %mm0,%eax /* (DI,U') */
-.endm
-
-/* void Short_term_analysis_filtering (short *u0, const short *rp0, int kn, short *s) */
- .equiv pm_u0,8
- .equiv pm_rp0,12
- .equiv pm_kn,16
- .equiv pm_s,20
- .equiv lv_rp_top,-4
- .equiv lv_s_top,-8
- .equiv lv_rp,-40 /* local version of rp0 with each word twice */
- .align 4
-.globl Short_term_analysis_filteringx
- .type Short_term_analysis_filteringx,@function
-Short_term_analysis_filteringx:
- pushl %ebp
- movl %esp,%ebp
- subl $56,%esp
- pushl %edi
- pushl %esi
- pushl %ebx
-
- movl pm_rp0(%ebp),%esi;
- leal lv_rp(%ebp),%edi;
- cld
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- lodsw; stosw; stosw
- movl %edi,lv_rp_top(%ebp)
- emms
-
- movl $0x4000,%eax;
- movd %eax,%mm6;
- punpckldq %mm6,%mm6 /* (0x00004000,0x00004000) for rounding dword product pairs */
-
- movl pm_u0(%ebp),%ebx
- movq (%ebx),%mm4; movq 8(%ebx),%mm5 /* the 8 u's */
- movl pm_s(%ebp),%edx /* edx is local s ptr throughout below */
- movl pm_kn(%ebp),%eax
- leal (%edx,%eax,2),%eax
- movl %eax,lv_s_top(%ebp)
- cmpl %eax,%edx
- jae .L179
- .p2align 2
-.L181:
- leal lv_rp(%ebp),%esi /* RP */
- movw (%edx),%ax /* (0,DI) */
- roll $16,%eax
- movw (%edx),%ax /* (DI,DI) */
- movd %eax,%mm0
- .p2align 2
-.L185: /* RP is %esi */
- step 0
- step 4
- step 8
- step 12
-/*
- step 16
- step 20
- step 24
- step 28
-*/
- addl $16,%esi
- cmpl lv_rp_top(%ebp),%esi
- jb .L185
-
- rorl $16,%eax
- movw %ax,(%edx) /* last DI goes to *s */
- addl $2,%edx /* next s */
- cmpl lv_s_top(%ebp),%edx
- jb .L181
-.L179:
- movq %mm4,(%ebx); movq %mm5,8(%ebx) /* the 8 u's */
- emms
- popl %ebx
- popl %esi
- popl %edi
- leave
- ret
-.Lfe7:
- .size Short_term_analysis_filteringx,.Lfe7-Short_term_analysis_filteringx
- .ident "GCC: (GNU) 2.95.2 19991109 (Debian GNU/Linux)"
diff --git a/1.2-netsec/codecs/gsm/src/long_term.c b/1.2-netsec/codecs/gsm/src/long_term.c
deleted file mode 100644
index 98f64aa2a..000000000
--- a/1.2-netsec/codecs/gsm/src/long_term.c
+++ /dev/null
@@ -1,952 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include <stdio.h>
-#include <assert.h>
-
-#include "private.h"
-
-#include "gsm.h"
-#include "proto.h"
-#ifdef K6OPT
-#include "k6opt.h"
-#endif
-/*
- * 4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION
- */
-
-
-/*
- * This module computes the LTP gain (bc) and the LTP lag (Nc)
- * for the long term analysis filter. This is done by calculating a
- * maximum of the cross-correlation function between the current
- * sub-segment short term residual signal d[0..39] (output of
- * the short term analysis filter; for simplification the index
- * of this array begins at 0 and ends at 39 for each sub-segment of the
- * RPE-LTP analysis) and the previous reconstructed short term
- * residual signal dp[ -120 .. -1 ]. A dynamic scaling must be
- * performed to avoid overflow.
- */
-
- /* The next procedure exists in six versions. First two integer
- * version (if USE_FLOAT_MUL is not defined); then four floating
- * point versions, twice with proper scaling (USE_FLOAT_MUL defined),
- * once without (USE_FLOAT_MUL and FAST defined, and fast run-time
- * option used). Every pair has first a Cut version (see the -C
- * option to toast or the LTP_CUT option to gsm_option()), then the
- * uncut one. (For a detailed explanation of why this is altogether
- * a bad idea, see Henry Spencer and Geoff Collyer, ``#ifdef Considered
- * Harmful''.)
- */
-
-#ifndef USE_FLOAT_MUL
-
-#ifdef LTP_CUT
-
-static void Cut_Calculation_of_the_LTP_parameters P5((st, d,dp,bc_out,Nc_out),
-
- struct gsm_state * st,
-
- register word * d, /* [0..39] IN */
- register word * dp, /* [-120..-1] IN */
- word * bc_out, /* OUT */
- word * Nc_out /* OUT */
-)
-{
- register int k, lambda;
- word Nc, bc;
- word wt[40];
-
- longword L_result;
- longword L_max, L_power;
- word R, S, dmax, scal, best_k;
- word ltp_cut;
-
- register word temp, wt_k;
-
- /* Search of the optimum scaling of d[0..39].
- */
- dmax = 0;
- for (k = 0; k <= 39; k++) {
- temp = d[k];
- temp = GSM_ABS( temp );
- if (temp > dmax) {
- dmax = temp;
- best_k = k;
- }
- }
- temp = 0;
- if (dmax == 0) scal = 0;
- else {
- assert(dmax > 0);
- temp = gsm_norm( (longword)dmax << 16 );
- }
- if (temp > 6) scal = 0;
- else scal = 6 - temp;
- assert(scal >= 0);
-
- /* Search for the maximum cross-correlation and coding of the LTP lag
- */
- L_max = 0;
- Nc = 40; /* index for the maximum cross-correlation */
- wt_k = SASR(d[best_k], scal);
-
- for (lambda = 40; lambda <= 120; lambda++) {
- L_result = (longword)wt_k * dp[best_k - lambda];
- if (L_result > L_max) {
- Nc = lambda;
- L_max = L_result;
- }
- }
- *Nc_out = Nc;
- L_max <<= 1;
-
- /* Rescaling of L_max
- */
- assert(scal <= 100 && scal >= -100);
- L_max = L_max >> (6 - scal); /* sub(6, scal) */
-
- assert( Nc <= 120 && Nc >= 40);
-
- /* Compute the power of the reconstructed short term residual
- * signal dp[..]
- */
- L_power = 0;
- for (k = 0; k <= 39; k++) {
-
- register longword L_temp;
-
- L_temp = SASR( dp[k - Nc], 3 );
- L_power += L_temp * L_temp;
- }
- L_power <<= 1; /* from L_MULT */
-
- /* Normalization of L_max and L_power
- */
-
- if (L_max <= 0) {
- *bc_out = 0;
- return;
- }
- if (L_max >= L_power) {
- *bc_out = 3;
- return;
- }
-
- temp = gsm_norm( L_power );
-
- R = SASR( L_max << temp, 16 );
- S = SASR( L_power << temp, 16 );
-
- /* Coding of the LTP gain
- */
-
- /* Table 4.3a must be used to obtain the level DLB[i] for the
- * quantization of the LTP gain b to get the coded version bc.
- */
- for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
- *bc_out = bc;
-}
-
-#endif /* LTP_CUT */
-
-static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
- register word * d, /* [0..39] IN */
- register word * dp, /* [-120..-1] IN */
- word * bc_out, /* OUT */
- word * Nc_out /* OUT */
-)
-{
- register int k, lambda;
- word Nc, bc;
- word wt[40];
-
- longword L_max, L_power;
- word R, S, dmax, scal;
- register word temp;
-
- /* Search of the optimum scaling of d[0..39].
- */
- dmax = 0;
-
- for (k = 0; k <= 39; k++) {
- temp = d[k];
- temp = GSM_ABS( temp );
- if (temp > dmax) dmax = temp;
- }
-
- temp = 0;
- if (dmax == 0) scal = 0;
- else {
- assert(dmax > 0);
- temp = gsm_norm( (longword)dmax << 16 );
- }
-
- if (temp > 6) scal = 0;
- else scal = 6 - temp;
-
- assert(scal >= 0);
-
- /* Initialization of a working array wt
- */
-
- for (k = 0; k <= 39; k++) wt[k] = SASR( d[k], scal );
-
- /* Search for the maximum cross-correlation and coding of the LTP lag
- */
-# ifdef K6OPT
- L_max = k6maxcc(wt,dp,&Nc);
-# else
- L_max = 0;
- Nc = 40; /* index for the maximum cross-correlation */
-
- for (lambda = 40; lambda <= 120; lambda++) {
-
-# undef STEP
-# define STEP(k) (longword)wt[k] * dp[k - lambda]
-
- register longword L_result;
-
- L_result = STEP(0) ; L_result += STEP(1) ;
- L_result += STEP(2) ; L_result += STEP(3) ;
- L_result += STEP(4) ; L_result += STEP(5) ;
- L_result += STEP(6) ; L_result += STEP(7) ;
- L_result += STEP(8) ; L_result += STEP(9) ;
- L_result += STEP(10) ; L_result += STEP(11) ;
- L_result += STEP(12) ; L_result += STEP(13) ;
- L_result += STEP(14) ; L_result += STEP(15) ;
- L_result += STEP(16) ; L_result += STEP(17) ;
- L_result += STEP(18) ; L_result += STEP(19) ;
- L_result += STEP(20) ; L_result += STEP(21) ;
- L_result += STEP(22) ; L_result += STEP(23) ;
- L_result += STEP(24) ; L_result += STEP(25) ;
- L_result += STEP(26) ; L_result += STEP(27) ;
- L_result += STEP(28) ; L_result += STEP(29) ;
- L_result += STEP(30) ; L_result += STEP(31) ;
- L_result += STEP(32) ; L_result += STEP(33) ;
- L_result += STEP(34) ; L_result += STEP(35) ;
- L_result += STEP(36) ; L_result += STEP(37) ;
- L_result += STEP(38) ; L_result += STEP(39) ;
-
- if (L_result > L_max) {
-
- Nc = lambda;
- L_max = L_result;
- }
- }
-# endif
- *Nc_out = Nc;
-
- L_max <<= 1;
-
- /* Rescaling of L_max
- */
- assert(scal <= 100 && scal >= -100);
- L_max = L_max >> (6 - scal); /* sub(6, scal) */
-
- assert( Nc <= 120 && Nc >= 40);
-
- /* Compute the power of the reconstructed short term residual
- * signal dp[..]
- */
- L_power = 0;
- for (k = 0; k <= 39; k++) {
-
- register longword L_temp;
-
- L_temp = SASR( dp[k - Nc], 3 );
- L_power += L_temp * L_temp;
- }
- L_power <<= 1; /* from L_MULT */
-
- /* Normalization of L_max and L_power
- */
-
- if (L_max <= 0) {
- *bc_out = 0;
- return;
- }
- if (L_max >= L_power) {
- *bc_out = 3;
- return;
- }
-
- temp = gsm_norm( L_power );
-
- R = SASR( L_max << temp, 16 );
- S = SASR( L_power << temp, 16 );
-
- /* Coding of the LTP gain
- */
-
- /* Table 4.3a must be used to obtain the level DLB[i] for the
- * quantization of the LTP gain b to get the coded version bc.
- */
- for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
- *bc_out = bc;
-}
-
-#else /* USE_FLOAT_MUL */
-
-#ifdef LTP_CUT
-
-static void Cut_Calculation_of_the_LTP_parameters P5((st, d,dp,bc_out,Nc_out),
- struct gsm_state * st, /* IN */
- register word * d, /* [0..39] IN */
- register word * dp, /* [-120..-1] IN */
- word * bc_out, /* OUT */
- word * Nc_out /* OUT */
-)
-{
- register int k, lambda;
- word Nc, bc;
- word ltp_cut;
-
- float wt_float[40];
- float dp_float_base[120], * dp_float = dp_float_base + 120;
-
- longword L_max, L_power;
- word R, S, dmax, scal;
- register word temp;
-
- /* Search of the optimum scaling of d[0..39].
- */
- dmax = 0;
-
- for (k = 0; k <= 39; k++) {
- temp = d[k];
- temp = GSM_ABS( temp );
- if (temp > dmax) dmax = temp;
- }
-
- temp = 0;
- if (dmax == 0) scal = 0;
- else {
- assert(dmax > 0);
- temp = gsm_norm( (longword)dmax << 16 );
- }
-
- if (temp > 6) scal = 0;
- else scal = 6 - temp;
-
- assert(scal >= 0);
- ltp_cut = (longword)SASR(dmax, scal) * st->ltp_cut / 100;
-
-
- /* Initialization of a working array wt
- */
-
- for (k = 0; k < 40; k++) {
- register word w = SASR( d[k], scal );
- if (w < 0 ? w > -ltp_cut : w < ltp_cut) {
- wt_float[k] = 0.0;
- }
- else {
- wt_float[k] = w;
- }
- }
- for (k = -120; k < 0; k++) dp_float[k] = dp[k];
-
- /* Search for the maximum cross-correlation and coding of the LTP lag
- */
- L_max = 0;
- Nc = 40; /* index for the maximum cross-correlation */
-
- for (lambda = 40; lambda <= 120; lambda += 9) {
-
- /* Calculate L_result for l = lambda .. lambda + 9.
- */
- register float *lp = dp_float - lambda;
-
- register float W;
- register float a = lp[-8], b = lp[-7], c = lp[-6],
- d = lp[-5], e = lp[-4], f = lp[-3],
- g = lp[-2], h = lp[-1];
- register float E;
- register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
- S5 = 0, S6 = 0, S7 = 0, S8 = 0;
-
-# undef STEP
-# define STEP(K, a, b, c, d, e, f, g, h) \
- if ((W = wt_float[K]) != 0.0) { \
- E = W * a; S8 += E; \
- E = W * b; S7 += E; \
- E = W * c; S6 += E; \
- E = W * d; S5 += E; \
- E = W * e; S4 += E; \
- E = W * f; S3 += E; \
- E = W * g; S2 += E; \
- E = W * h; S1 += E; \
- a = lp[K]; \
- E = W * a; S0 += E; } else (a = lp[K])
-
-# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
-# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
-# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
-# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
-# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
-# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
-# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
-# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
-
- STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
- STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
-
- STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
- STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
-
- STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
- STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
-
- STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
- STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
-
- STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
- STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
-
- if (S0 > L_max) { L_max = S0; Nc = lambda; }
- if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
- if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
- if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
- if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
- if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
- if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
- if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
- if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
-
- }
- *Nc_out = Nc;
-
- L_max <<= 1;
-
- /* Rescaling of L_max
- */
- assert(scal <= 100 && scal >= -100);
- L_max = L_max >> (6 - scal); /* sub(6, scal) */
-
- assert( Nc <= 120 && Nc >= 40);
-
- /* Compute the power of the reconstructed short term residual
- * signal dp[..]
- */
- L_power = 0;
- for (k = 0; k <= 39; k++) {
-
- register longword L_temp;
-
- L_temp = SASR( dp[k - Nc], 3 );
- L_power += L_temp * L_temp;
- }
- L_power <<= 1; /* from L_MULT */
-
- /* Normalization of L_max and L_power
- */
-
- if (L_max <= 0) {
- *bc_out = 0;
- return;
- }
- if (L_max >= L_power) {
- *bc_out = 3;
- return;
- }
-
- temp = gsm_norm( L_power );
-
- R = SASR( L_max << temp, 16 );
- S = SASR( L_power << temp, 16 );
-
- /* Coding of the LTP gain
- */
-
- /* Table 4.3a must be used to obtain the level DLB[i] for the
- * quantization of the LTP gain b to get the coded version bc.
- */
- for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
- *bc_out = bc;
-}
-
-#endif /* LTP_CUT */
-
-static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
- register word * d, /* [0..39] IN */
- register word * dp, /* [-120..-1] IN */
- word * bc_out, /* OUT */
- word * Nc_out /* OUT */
-)
-{
- register int k, lambda;
- word Nc, bc;
-
- float wt_float[40];
- float dp_float_base[120], * dp_float = dp_float_base + 120;
-
- longword L_max, L_power;
- word R, S, dmax, scal;
- register word temp;
-
- /* Search of the optimum scaling of d[0..39].
- */
- dmax = 0;
-
- for (k = 0; k <= 39; k++) {
- temp = d[k];
- temp = GSM_ABS( temp );
- if (temp > dmax) dmax = temp;
- }
-
- temp = 0;
- if (dmax == 0) scal = 0;
- else {
- assert(dmax > 0);
- temp = gsm_norm( (longword)dmax << 16 );
- }
-
- if (temp > 6) scal = 0;
- else scal = 6 - temp;
-
- assert(scal >= 0);
-
- /* Initialization of a working array wt
- */
-
- for (k = 0; k < 40; k++) wt_float[k] = SASR( d[k], scal );
- for (k = -120; k < 0; k++) dp_float[k] = dp[k];
-
- /* Search for the maximum cross-correlation and coding of the LTP lag
- */
- L_max = 0;
- Nc = 40; /* index for the maximum cross-correlation */
-
- for (lambda = 40; lambda <= 120; lambda += 9) {
-
- /* Calculate L_result for l = lambda .. lambda + 9.
- */
- register float *lp = dp_float - lambda;
-
- register float W;
- register float a = lp[-8], b = lp[-7], c = lp[-6],
- d = lp[-5], e = lp[-4], f = lp[-3],
- g = lp[-2], h = lp[-1];
- register float E;
- register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
- S5 = 0, S6 = 0, S7 = 0, S8 = 0;
-
-# undef STEP
-# define STEP(K, a, b, c, d, e, f, g, h) \
- W = wt_float[K]; \
- E = W * a; S8 += E; \
- E = W * b; S7 += E; \
- E = W * c; S6 += E; \
- E = W * d; S5 += E; \
- E = W * e; S4 += E; \
- E = W * f; S3 += E; \
- E = W * g; S2 += E; \
- E = W * h; S1 += E; \
- a = lp[K]; \
- E = W * a; S0 += E
-
-# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
-# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
-# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
-# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
-# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
-# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
-# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
-# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
-
- STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
- STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
-
- STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
- STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
-
- STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
- STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
-
- STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
- STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
-
- STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
- STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
-
- if (S0 > L_max) { L_max = S0; Nc = lambda; }
- if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
- if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
- if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
- if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
- if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
- if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
- if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
- if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
- }
- *Nc_out = Nc;
-
- L_max <<= 1;
-
- /* Rescaling of L_max
- */
- assert(scal <= 100 && scal >= -100);
- L_max = L_max >> (6 - scal); /* sub(6, scal) */
-
- assert( Nc <= 120 && Nc >= 40);
-
- /* Compute the power of the reconstructed short term residual
- * signal dp[..]
- */
- L_power = 0;
- for (k = 0; k <= 39; k++) {
-
- register longword L_temp;
-
- L_temp = SASR( dp[k - Nc], 3 );
- L_power += L_temp * L_temp;
- }
- L_power <<= 1; /* from L_MULT */
-
- /* Normalization of L_max and L_power
- */
-
- if (L_max <= 0) {
- *bc_out = 0;
- return;
- }
- if (L_max >= L_power) {
- *bc_out = 3;
- return;
- }
-
- temp = gsm_norm( L_power );
-
- R = SASR( L_max << temp, 16 );
- S = SASR( L_power << temp, 16 );
-
- /* Coding of the LTP gain
- */
-
- /* Table 4.3a must be used to obtain the level DLB[i] for the
- * quantization of the LTP gain b to get the coded version bc.
- */
- for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
- *bc_out = bc;
-}
-
-#ifdef FAST
-#ifdef LTP_CUT
-
-static void Cut_Fast_Calculation_of_the_LTP_parameters P5((st,
- d,dp,bc_out,Nc_out),
- struct gsm_state * st, /* IN */
- register word * d, /* [0..39] IN */
- register word * dp, /* [-120..-1] IN */
- word * bc_out, /* OUT */
- word * Nc_out /* OUT */
-)
-{
- register int k, lambda;
- register float wt_float;
- word Nc, bc;
- word wt_max, best_k, ltp_cut;
-
- float dp_float_base[120], * dp_float = dp_float_base + 120;
-
- register float L_result, L_max, L_power;
-
- wt_max = 0;
-
- for (k = 0; k < 40; ++k) {
- if ( d[k] > wt_max) wt_max = d[best_k = k];
- else if (-d[k] > wt_max) wt_max = -d[best_k = k];
- }
-
- assert(wt_max >= 0);
- wt_float = (float)wt_max;
-
- for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
-
- /* Search for the maximum cross-correlation and coding of the LTP lag
- */
- L_max = 0;
- Nc = 40; /* index for the maximum cross-correlation */
-
- for (lambda = 40; lambda <= 120; lambda++) {
- L_result = wt_float * dp_float[best_k - lambda];
- if (L_result > L_max) {
- Nc = lambda;
- L_max = L_result;
- }
- }
-
- *Nc_out = Nc;
- if (L_max <= 0.) {
- *bc_out = 0;
- return;
- }
-
- /* Compute the power of the reconstructed short term residual
- * signal dp[..]
- */
- dp_float -= Nc;
- L_power = 0;
- for (k = 0; k < 40; ++k) {
- register float f = dp_float[k];
- L_power += f * f;
- }
-
- if (L_max >= L_power) {
- *bc_out = 3;
- return;
- }
-
- /* Coding of the LTP gain
- * Table 4.3a must be used to obtain the level DLB[i] for the
- * quantization of the LTP gain b to get the coded version bc.
- */
- lambda = L_max / L_power * 32768.;
- for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
- *bc_out = bc;
-}
-
-#endif /* LTP_CUT */
-
-static void Fast_Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
- register word * d, /* [0..39] IN */
- register word * dp, /* [-120..-1] IN */
- word * bc_out, /* OUT */
- word * Nc_out /* OUT */
-)
-{
- register int k, lambda;
- word Nc, bc;
-
- float wt_float[40];
- float dp_float_base[120], * dp_float = dp_float_base + 120;
-
- register float L_max, L_power;
-
- for (k = 0; k < 40; ++k) wt_float[k] = (float)d[k];
- for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
-
- /* Search for the maximum cross-correlation and coding of the LTP lag
- */
- L_max = 0;
- Nc = 40; /* index for the maximum cross-correlation */
-
- for (lambda = 40; lambda <= 120; lambda += 9) {
-
- /* Calculate L_result for l = lambda .. lambda + 9.
- */
- register float *lp = dp_float - lambda;
-
- register float W;
- register float a = lp[-8], b = lp[-7], c = lp[-6],
- d = lp[-5], e = lp[-4], f = lp[-3],
- g = lp[-2], h = lp[-1];
- register float E;
- register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
- S5 = 0, S6 = 0, S7 = 0, S8 = 0;
-
-# undef STEP
-# define STEP(K, a, b, c, d, e, f, g, h) \
- W = wt_float[K]; \
- E = W * a; S8 += E; \
- E = W * b; S7 += E; \
- E = W * c; S6 += E; \
- E = W * d; S5 += E; \
- E = W * e; S4 += E; \
- E = W * f; S3 += E; \
- E = W * g; S2 += E; \
- E = W * h; S1 += E; \
- a = lp[K]; \
- E = W * a; S0 += E
-
-# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
-# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
-# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
-# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
-# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
-# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
-# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
-# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
-
- STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
- STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
-
- STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
- STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
-
- STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
- STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
-
- STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
- STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
-
- STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
- STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
-
- if (S0 > L_max) { L_max = S0; Nc = lambda; }
- if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
- if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
- if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
- if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
- if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
- if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
- if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
- if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
- }
- *Nc_out = Nc;
-
- if (L_max <= 0.) {
- *bc_out = 0;
- return;
- }
-
- /* Compute the power of the reconstructed short term residual
- * signal dp[..]
- */
- dp_float -= Nc;
- L_power = 0;
- for (k = 0; k < 40; ++k) {
- register float f = dp_float[k];
- L_power += f * f;
- }
-
- if (L_max >= L_power) {
- *bc_out = 3;
- return;
- }
-
- /* Coding of the LTP gain
- * Table 4.3a must be used to obtain the level DLB[i] for the
- * quantization of the LTP gain b to get the coded version bc.
- */
- lambda = L_max / L_power * 32768.;
- for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
- *bc_out = bc;
-}
-
-#endif /* FAST */
-#endif /* USE_FLOAT_MUL */
-
-
-/* 4.2.12 */
-
-static void Long_term_analysis_filtering P6((bc,Nc,dp,d,dpp,e),
- word bc, /* IN */
- word Nc, /* IN */
- register word * dp, /* previous d [-120..-1] IN */
- register word * d, /* d [0..39] IN */
- register word * dpp, /* estimate [0..39] OUT */
- register word * e /* long term res. signal [0..39] OUT */
-)
-/*
- * In this part, we have to decode the bc parameter to compute
- * the samples of the estimate dpp[0..39]. The decoding of bc needs the
- * use of table 4.3b. The long term residual signal e[0..39]
- * is then calculated to be fed to the RPE encoding section.
- */
-{
- register int k;
-
-# undef STEP
-# define STEP(BP) \
- for (k = 0; k <= 39; k++) { \
- dpp[k] = GSM_MULT_R( BP, dp[k - Nc]); \
- e[k] = GSM_SUB( d[k], dpp[k] ); \
- }
-
- switch (bc) {
- case 0: STEP( 3277 ); break;
- case 1: STEP( 11469 ); break;
- case 2: STEP( 21299 ); break;
- case 3: STEP( 32767 ); break;
- }
-}
-
-void Gsm_Long_Term_Predictor P7((S,d,dp,e,dpp,Nc,bc), /* 4x for 160 samples */
-
- struct gsm_state * S,
-
- word * d, /* [0..39] residual signal IN */
- word * dp, /* [-120..-1] d' IN */
-
- word * e, /* [0..39] OUT */
- word * dpp, /* [0..39] OUT */
- word * Nc, /* correlation lag OUT */
- word * bc /* gain factor OUT */
-)
-{
- assert( d ); assert( dp ); assert( e );
- assert( dpp); assert( Nc ); assert( bc );
-
-#if defined(FAST) && defined(USE_FLOAT_MUL)
- if (S->fast)
-#if defined (LTP_CUT)
- if (S->ltp_cut)
- Cut_Fast_Calculation_of_the_LTP_parameters(S,
- d, dp, bc, Nc);
- else
-#endif /* LTP_CUT */
- Fast_Calculation_of_the_LTP_parameters(d, dp, bc, Nc );
- else
-#endif /* FAST & USE_FLOAT_MUL */
-#ifdef LTP_CUT
- if (S->ltp_cut)
- Cut_Calculation_of_the_LTP_parameters(S, d, dp, bc, Nc);
- else
-#endif
- Calculation_of_the_LTP_parameters(d, dp, bc, Nc);
-
- Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e );
-}
-
-/* 4.3.2 */
-void Gsm_Long_Term_Synthesis_Filtering P5((S,Ncr,bcr,erp,drp),
- struct gsm_state * S,
-
- word Ncr,
- word bcr,
- register word * erp, /* [0..39] IN */
- register word * drp /* [-120..-1] IN, [-120..40] OUT */
-)
-/*
- * This procedure uses the bcr and Ncr parameter to realize the
- * long term synthesis filtering. The decoding of bcr needs
- * table 4.3b.
- */
-{
- register int k;
- word brp, drpp, Nr;
-
- /* Check the limits of Nr.
- */
- Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;
- S->nrp = Nr;
- assert(Nr >= 40 && Nr <= 120);
-
- /* Decoding of the LTP gain bcr
- */
- brp = gsm_QLB[ bcr ];
-
- /* Computation of the reconstructed short term residual
- * signal drp[0..39]
- */
- assert(brp != MIN_WORD);
-
- for (k = 0; k <= 39; k++) {
- drpp = GSM_MULT_R( brp, drp[ k - Nr ] );
- drp[k] = GSM_ADD( erp[k], drpp );
- }
-
- /*
- * Update of the reconstructed short term residual signal
- * drp[ -1..-120 ]
- */
-
- for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];
-}
diff --git a/1.2-netsec/codecs/gsm/src/lpc.c b/1.2-netsec/codecs/gsm/src/lpc.c
deleted file mode 100644
index a8e9192ba..000000000
--- a/1.2-netsec/codecs/gsm/src/lpc.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include <stdio.h>
-#include <assert.h>
-
-#include "private.h"
-
-#include "gsm.h"
-#include "proto.h"
-
-#ifdef K6OPT
-#include "k6opt.h"
-#endif
-
-#undef P
-
-/*
- * 4.2.4 .. 4.2.7 LPC ANALYSIS SECTION
- */
-
-/* 4.2.4 */
-
-
-static void Autocorrelation P2((s, L_ACF),
- word * s, /* [0..159] IN/OUT */
- longword * L_ACF) /* [0..8] OUT */
-/*
- * The goal is to compute the array L_ACF[k]. The signal s[i] must
- * be scaled in order to avoid an overflow situation.
- */
-{
- register int k, i;
-
- word temp, smax, scalauto;
-
-#ifdef USE_FLOAT_MUL
- float float_s[160];
-#endif
-
- /* Dynamic scaling of the array s[0..159]
- */
-
- /* Search for the maximum.
- */
-#ifndef K6OPT
- smax = 0;
- for (k = 0; k <= 159; k++) {
- temp = GSM_ABS( s[k] );
- if (temp > smax) smax = temp;
- }
-#else
- {
- longword lmax;
- lmax = k6maxmin(s,160,NULL);
- smax = (lmax > MAX_WORD) ? MAX_WORD : lmax;
- }
-#endif
- /* Computation of the scaling factor.
- */
- if (smax == 0) scalauto = 0;
- else {
- assert(smax > 0);
- scalauto = 4 - gsm_norm( (longword)smax << 16 );/* sub(4,..) */
- }
-
- /* Scaling of the array s[0...159]
- */
-
- if (scalauto > 0) {
-# ifndef K6OPT
-
-# ifdef USE_FLOAT_MUL
-# define SCALE(n) \
- case n: for (k = 0; k <= 159; k++) \
- float_s[k] = (float) \
- (s[k] = GSM_MULT_R(s[k], 16384 >> (n-1)));\
- break;
-# else
-# define SCALE(n) \
- case n: for (k = 0; k <= 159; k++) \
- s[k] = GSM_MULT_R( s[k], 16384 >> (n-1) );\
- break;
-# endif /* USE_FLOAT_MUL */
-
- switch (scalauto) {
- SCALE(1)
- SCALE(2)
- SCALE(3)
- SCALE(4)
- }
-# undef SCALE
-
-# else /* K6OPT */
- k6vsraw(s,160,scalauto);
-# endif
- }
-# ifdef USE_FLOAT_MUL
- else for (k = 0; k <= 159; k++) float_s[k] = (float) s[k];
-# endif
-
- /* Compute the L_ACF[..].
- */
-#ifndef K6OPT
- {
-# ifdef USE_FLOAT_MUL
- register float * sp = float_s;
- register float sl = *sp;
-
-# define STEP(k) L_ACF[k] += (longword)(sl * sp[ -(k) ]);
-# else
- word * sp = s;
- word sl = *sp;
-
-# define STEP(k) L_ACF[k] += ((longword)sl * sp[ -(k) ]);
-# endif
-
-# define NEXTI sl = *++sp
-
-
- for (k = 9; k--; L_ACF[k] = 0) ;
-
- STEP (0);
- NEXTI;
- STEP(0); STEP(1);
- NEXTI;
- STEP(0); STEP(1); STEP(2);
- NEXTI;
- STEP(0); STEP(1); STEP(2); STEP(3);
- NEXTI;
- STEP(0); STEP(1); STEP(2); STEP(3); STEP(4);
- NEXTI;
- STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5);
- NEXTI;
- STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6);
- NEXTI;
- STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6); STEP(7);
-
- for (i = 8; i <= 159; i++) {
-
- NEXTI;
-
- STEP(0);
- STEP(1); STEP(2); STEP(3); STEP(4);
- STEP(5); STEP(6); STEP(7); STEP(8);
- }
-
- for (k = 9; k--; L_ACF[k] <<= 1) ;
-
- }
-
-#else
- {
- int k;
- for (k=0; k<9; k++) {
- L_ACF[k] = 2*k6iprod(s,s+k,160-k);
- }
- }
-#endif
- /* Rescaling of the array s[0..159]
- */
- if (scalauto > 0) {
- assert(scalauto <= 4);
-#ifndef K6OPT
- for (k = 160; k--; *s++ <<= scalauto) ;
-# else /* K6OPT */
- k6vsllw(s,160,scalauto);
-# endif
- }
-}
-
-#if defined(USE_FLOAT_MUL) && defined(FAST)
-
-static void Fast_Autocorrelation P2((s, L_ACF),
- word * s, /* [0..159] IN/OUT */
- longword * L_ACF) /* [0..8] OUT */
-{
- register int k, i;
- float f_L_ACF[9];
- float scale;
-
- float s_f[160];
- register float *sf = s_f;
-
- for (i = 0; i < 160; ++i) sf[i] = s[i];
- for (k = 0; k <= 8; k++) {
- register float L_temp2 = 0;
- register float *sfl = sf - k;
- for (i = k; i < 160; ++i) L_temp2 += sf[i] * sfl[i];
- f_L_ACF[k] = L_temp2;
- }
- scale = MAX_LONGWORD / f_L_ACF[0];
-
- for (k = 0; k <= 8; k++) {
- L_ACF[k] = f_L_ACF[k] * scale;
- }
-}
-#endif /* defined (USE_FLOAT_MUL) && defined (FAST) */
-
-/* 4.2.5 */
-
-static void Reflection_coefficients P2( (L_ACF, r),
- longword * L_ACF, /* 0...8 IN */
- register word * r /* 0...7 OUT */
-)
-{
- register int i, m, n;
- register word temp;
- word ACF[9]; /* 0..8 */
- word P[ 9]; /* 0..8 */
- word K[ 9]; /* 2..8 */
-
- /* Schur recursion with 16 bits arithmetic.
- */
-
- if (L_ACF[0] == 0) {
- for (i = 8; i--; *r++ = 0) ;
- return;
- }
-
- assert( L_ACF[0] != 0 );
- temp = gsm_norm( L_ACF[0] );
-
- assert(temp >= 0 && temp < 32);
-
- /* ? overflow ? */
- for (i = 0; i <= 8; i++) ACF[i] = SASR( L_ACF[i] << temp, 16 );
-
- /* Initialize array P[..] and K[..] for the recursion.
- */
-
- for (i = 1; i <= 7; i++) K[ i ] = ACF[ i ];
- for (i = 0; i <= 8; i++) P[ i ] = ACF[ i ];
-
- /* Compute reflection coefficients
- */
- for (n = 1; n <= 8; n++, r++) {
-
- temp = P[1];
- temp = GSM_ABS(temp);
- if (P[0] < temp) {
- for (i = n; i <= 8; i++) *r++ = 0;
- return;
- }
-
- *r = gsm_div( temp, P[0] );
-
- assert(*r >= 0);
- if (P[1] > 0) *r = -*r; /* r[n] = sub(0, r[n]) */
- assert (*r != MIN_WORD);
- if (n == 8) return;
-
- /* Schur recursion
- */
- temp = GSM_MULT_R( P[1], *r );
- P[0] = GSM_ADD( P[0], temp );
-
- for (m = 1; m <= 8 - n; m++) {
- temp = GSM_MULT_R( K[ m ], *r );
- P[m] = GSM_ADD( P[ m+1 ], temp );
-
- temp = GSM_MULT_R( P[ m+1 ], *r );
- K[m] = GSM_ADD( K[ m ], temp );
- }
- }
-}
-
-/* 4.2.6 */
-
-static void Transformation_to_Log_Area_Ratios P1((r),
- register word * r /* 0..7 IN/OUT */
-)
-/*
- * The following scaling for r[..] and LAR[..] has been used:
- *
- * r[..] = integer( real_r[..]*32768. ); -1 <= real_r < 1.
- * LAR[..] = integer( real_LAR[..] * 16384 );
- * with -1.625 <= real_LAR <= 1.625
- */
-{
- register word temp;
- register int i;
-
-
- /* Computation of the LAR[0..7] from the r[0..7]
- */
- for (i = 1; i <= 8; i++, r++) {
-
- temp = *r;
- temp = GSM_ABS(temp);
- assert(temp >= 0);
-
- if (temp < 22118) {
- temp >>= 1;
- } else if (temp < 31130) {
- assert( temp >= 11059 );
- temp -= 11059;
- } else {
- assert( temp >= 26112 );
- temp -= 26112;
- temp <<= 2;
- }
-
- *r = *r < 0 ? -temp : temp;
- assert( *r != MIN_WORD );
- }
-}
-
-/* 4.2.7 */
-
-static void Quantization_and_coding P1((LAR),
- register word * LAR /* [0..7] IN/OUT */
-)
-{
- register word temp;
-
-
- /* This procedure needs four tables; the following equations
- * give the optimum scaling for the constants:
- *
- * A[0..7] = integer( real_A[0..7] * 1024 )
- * B[0..7] = integer( real_B[0..7] * 512 )
- * MAC[0..7] = maximum of the LARc[0..7]
- * MIC[0..7] = minimum of the LARc[0..7]
- */
-
-# undef STEP
-# define STEP( A, B, MAC, MIC ) \
- temp = GSM_MULT( A, *LAR ); \
- temp = GSM_ADD( temp, B ); \
- temp = GSM_ADD( temp, 256 ); \
- temp = SASR( temp, 9 ); \
- *LAR = temp>MAC ? MAC - MIC : (temp<MIC ? 0 : temp - MIC); \
- LAR++;
-
- STEP( 20480, 0, 31, -32 );
- STEP( 20480, 0, 31, -32 );
- STEP( 20480, 2048, 15, -16 );
- STEP( 20480, -2560, 15, -16 );
-
- STEP( 13964, 94, 7, -8 );
- STEP( 15360, -1792, 7, -8 );
- STEP( 8534, -341, 3, -4 );
- STEP( 9036, -1144, 3, -4 );
-
-# undef STEP
-}
-
-void Gsm_LPC_Analysis P3((S, s,LARc),
- struct gsm_state *S,
- word * s, /* 0..159 signals IN/OUT */
- word * LARc) /* 0..7 LARc's OUT */
-{
- longword L_ACF[9];
-
-#if defined(USE_FLOAT_MUL) && defined(FAST)
- if (S->fast) Fast_Autocorrelation (s, L_ACF );
- else
-#endif
- Autocorrelation (s, L_ACF );
- Reflection_coefficients (L_ACF, LARc );
- Transformation_to_Log_Area_Ratios (LARc);
- Quantization_and_coding (LARc);
-}
diff --git a/1.2-netsec/codecs/gsm/src/preprocess.c b/1.2-netsec/codecs/gsm/src/preprocess.c
deleted file mode 100644
index 03746f9c3..000000000
--- a/1.2-netsec/codecs/gsm/src/preprocess.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include <stdio.h>
-#include <assert.h>
-
-#include "private.h"
-
-#include "gsm.h"
-#include "proto.h"
-
-/* 4.2.0 .. 4.2.3 PREPROCESSING SECTION
- *
- * After A-law to linear conversion (or directly from the
- * Ato D converter) the following scaling is assumed for
- * input to the RPE-LTP algorithm:
- *
- * in: 0.1.....................12
- * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*
- *
- * Where S is the sign bit, v a valid bit, and * a "don't care" bit.
- * The original signal is called sop[..]
- *
- * out: 0.1................... 12
- * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0
- */
-
-
-void Gsm_Preprocess P3((S, s, so),
- struct gsm_state * S,
- word * s,
- word * so ) /* [0..159] IN/OUT */
-{
-
- word z1 = S->z1;
- longword L_z2 = S->L_z2;
- word mp = S->mp;
-
- word s1;
-
-
- word SO;
-
- ulongword utmp; /* for L_ADD */
-
- register int k = 160;
-
- while (k--) {
-
- /* 4.2.1 Downscaling of the input signal
- */
- /* SO = SASR( *s, 3 ) << 2;*/
- SO = SASR( *s, 1 ) & ~3;
- s++;
-
- assert (SO >= -0x4000); /* downscaled by */
- assert (SO <= 0x3FFC); /* previous routine. */
-
-
- /* 4.2.2 Offset compensation
- *
- * This part implements a high-pass filter and requires extended
- * arithmetic precision for the recursive part of this filter.
- * The input of this procedure is the array so[0...159] and the
- * output the array sof[ 0...159 ].
- */
- /* Compute the non-recursive part
- */
-
- s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */
- z1 = SO;
-
- assert(s1 != MIN_WORD);
-
- /* SJB Remark: float might be faster than the mess that follows */
-
- /* Compute the recursive part
- */
-
- /* Execution of a 31 bv 16 bits multiplication
- */
- {
- word msp;
-#ifndef __GNUC__
- word lsp;
-#endif
- longword L_s2;
- longword L_temp;
-
- L_s2 = s1;
- L_s2 <<= 15;
-#ifndef __GNUC__
- msp = SASR( L_z2, 15 );
- lsp = L_z2 & 0x7fff; /* gsm_L_sub(L_z2,(msp<<15)); */
-
- L_s2 += GSM_MULT_R( lsp, 32735 );
- L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/
- L_z2 = GSM_L_ADD( L_temp, L_s2 );
- /* above does L_z2 = L_z2 * 0x7fd5/0x8000 + L_s2 */
-#else
- L_z2 = ((long long)L_z2*32735 + 0x4000)>>15;
- /* alternate (ansi) version of above line does slightly different rounding:
- * L_temp = L_z2 >> 9;
- * L_temp += L_temp >> 5;
- * L_temp = (++L_temp) >> 1;
- * L_z2 = L_z2 - L_temp;
- */
- L_z2 = GSM_L_ADD(L_z2,L_s2);
-#endif
- /* Compute sof[k] with rounding
- */
- L_temp = GSM_L_ADD( L_z2, 16384 );
-
- /* 4.2.3 Preemphasis
- */
-
- msp = GSM_MULT_R( mp, -28180 );
- mp = SASR( L_temp, 15 );
- *so++ = GSM_ADD( mp, msp );
- }
- }
-
- S->z1 = z1;
- S->L_z2 = L_z2;
- S->mp = mp;
-}
diff --git a/1.2-netsec/codecs/gsm/src/rpe.c b/1.2-netsec/codecs/gsm/src/rpe.c
deleted file mode 100644
index 8be0c0772..000000000
--- a/1.2-netsec/codecs/gsm/src/rpe.c
+++ /dev/null
@@ -1,490 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include <stdio.h>
-#include <assert.h>
-
-#include "private.h"
-
-#include "gsm.h"
-#include "proto.h"
-
-/* 4.2.13 .. 4.2.17 RPE ENCODING SECTION
- */
-
-/* 4.2.13 */
-#ifdef K6OPT
-#include "k6opt.h"
-#else
-static void Weighting_filter P2((e, x),
- register word * e, /* signal [-5..0.39.44] IN */
- word * x /* signal [0..39] OUT */
-)
-/*
- * The coefficients of the weighting filter are stored in a table
- * (see table 4.4). The following scaling is used:
- *
- * H[0..10] = integer( real_H[ 0..10] * 8192 );
- */
-{
- /* word wt[ 50 ]; */
-
- register longword L_result;
- register int k /* , i */ ;
-
- /* Initialization of a temporary working array wt[0...49]
- */
-
- /* for (k = 0; k <= 4; k++) wt[k] = 0;
- * for (k = 5; k <= 44; k++) wt[k] = *e++;
- * for (k = 45; k <= 49; k++) wt[k] = 0;
- *
- * (e[-5..-1] and e[40..44] are allocated by the caller,
- * are initially zero and are not written anywhere.)
- */
- e -= 5;
-
- /* Compute the signal x[0..39]
- */
- for (k = 0; k <= 39; k++) {
-
- L_result = 8192 >> 1;
-
- /* for (i = 0; i <= 10; i++) {
- * L_temp = GSM_L_MULT( wt[k+i], gsm_H[i] );
- * L_result = GSM_L_ADD( L_result, L_temp );
- * }
- */
-
-#undef STEP
-#define STEP( i, H ) (e[ k + i ] * (longword)H)
-
- /* Every one of these multiplications is done twice --
- * but I don't see an elegant way to optimize this.
- * Do you?
- */
-
-#ifdef STUPID_COMPILER
- L_result += STEP( 0, -134 ) ;
- L_result += STEP( 1, -374 ) ;
- /* + STEP( 2, 0 ) */
- L_result += STEP( 3, 2054 ) ;
- L_result += STEP( 4, 5741 ) ;
- L_result += STEP( 5, 8192 ) ;
- L_result += STEP( 6, 5741 ) ;
- L_result += STEP( 7, 2054 ) ;
- /* + STEP( 8, 0 ) */
- L_result += STEP( 9, -374 ) ;
- L_result += STEP( 10, -134 ) ;
-#else
- L_result +=
- STEP( 0, -134 )
- + STEP( 1, -374 )
- /* + STEP( 2, 0 ) */
- + STEP( 3, 2054 )
- + STEP( 4, 5741 )
- + STEP( 5, 8192 )
- + STEP( 6, 5741 )
- + STEP( 7, 2054 )
- /* + STEP( 8, 0 ) */
- + STEP( 9, -374 )
- + STEP(10, -134 )
- ;
-#endif
-
- /* L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x2) *)
- * L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x4) *)
- *
- * x[k] = SASR( L_result, 16 );
- */
-
- /* 2 adds vs. >>16 => 14, minus one shift to compensate for
- * those we lost when replacing L_MULT by '*'.
- */
-
- L_result = SASR( L_result, 13 );
- x[k] = ( L_result < MIN_WORD ? MIN_WORD
- : (L_result > MAX_WORD ? MAX_WORD : L_result ));
- }
-}
-#endif /* K6OPT */
-
-/* 4.2.14 */
-
-static void RPE_grid_selection P3((x,xM,Mc_out),
- word * x, /* [0..39] IN */
- word * xM, /* [0..12] OUT */
- word * Mc_out /* OUT */
-)
-/*
- * The signal x[0..39] is used to select the RPE grid which is
- * represented by Mc.
- */
-{
- /* register word temp1; */
- register int /* m, */ i;
- register longword L_result, L_temp;
- longword EM; /* xxx should be L_EM? */
- word Mc;
-
- longword L_common_0_3;
-
- EM = 0;
- Mc = 0;
-
- /* for (m = 0; m <= 3; m++) {
- * L_result = 0;
- *
- *
- * for (i = 0; i <= 12; i++) {
- *
- * temp1 = SASR( x[m + 3*i], 2 );
- *
- * assert(temp1 != MIN_WORD);
- *
- * L_temp = GSM_L_MULT( temp1, temp1 );
- * L_result = GSM_L_ADD( L_temp, L_result );
- * }
- *
- * if (L_result > EM) {
- * Mc = m;
- * EM = L_result;
- * }
- * }
- */
-
-#undef STEP
-#define STEP( m, i ) L_temp = SASR( x[m + 3 * i], 2 ); \
- L_result += L_temp * L_temp;
-
- /* common part of 0 and 3 */
-
- L_result = 0;
- STEP( 0, 1 ); STEP( 0, 2 ); STEP( 0, 3 ); STEP( 0, 4 );
- STEP( 0, 5 ); STEP( 0, 6 ); STEP( 0, 7 ); STEP( 0, 8 );
- STEP( 0, 9 ); STEP( 0, 10); STEP( 0, 11); STEP( 0, 12);
- L_common_0_3 = L_result;
-
- /* i = 0 */
-
- STEP( 0, 0 );
- L_result <<= 1; /* implicit in L_MULT */
- EM = L_result;
-
- /* i = 1 */
-
- L_result = 0;
- STEP( 1, 0 );
- STEP( 1, 1 ); STEP( 1, 2 ); STEP( 1, 3 ); STEP( 1, 4 );
- STEP( 1, 5 ); STEP( 1, 6 ); STEP( 1, 7 ); STEP( 1, 8 );
- STEP( 1, 9 ); STEP( 1, 10); STEP( 1, 11); STEP( 1, 12);
- L_result <<= 1;
- if (L_result > EM) {
- Mc = 1;
- EM = L_result;
- }
-
- /* i = 2 */
-
- L_result = 0;
- STEP( 2, 0 );
- STEP( 2, 1 ); STEP( 2, 2 ); STEP( 2, 3 ); STEP( 2, 4 );
- STEP( 2, 5 ); STEP( 2, 6 ); STEP( 2, 7 ); STEP( 2, 8 );
- STEP( 2, 9 ); STEP( 2, 10); STEP( 2, 11); STEP( 2, 12);
- L_result <<= 1;
- if (L_result > EM) {
- Mc = 2;
- EM = L_result;
- }
-
- /* i = 3 */
-
- L_result = L_common_0_3;
- STEP( 3, 12 );
- L_result <<= 1;
- if (L_result > EM) {
- Mc = 3;
- EM = L_result;
- }
-
- /**/
-
- /* Down-sampling by a factor 3 to get the selected xM[0..12]
- * RPE sequence.
- */
- for (i = 0; i <= 12; i ++) xM[i] = x[Mc + 3*i];
- *Mc_out = Mc;
-}
-
-/* 4.12.15 */
-
-static void APCM_quantization_xmaxc_to_exp_mant P3((xmaxc,exp_out,mant_out),
- word xmaxc, /* IN */
- word * exp_out, /* OUT */
- word * mant_out ) /* OUT */
-{
- word exp, mant;
-
- /* Compute exponent and mantissa of the decoded version of xmaxc
- */
-
- exp = 0;
- if (xmaxc > 15) exp = SASR(xmaxc, 3) - 1;
- mant = xmaxc - (exp << 3);
-
- if (mant == 0) {
- exp = -4;
- mant = 7;
- }
- else {
- while (mant <= 7) {
- mant = mant << 1 | 1;
- exp--;
- }
- mant -= 8;
- }
-
- assert( exp >= -4 && exp <= 6 );
- assert( mant >= 0 && mant <= 7 );
-
- *exp_out = exp;
- *mant_out = mant;
-}
-
-static void APCM_quantization P5((xM,xMc,mant_out,exp_out,xmaxc_out),
- word * xM, /* [0..12] IN */
-
- word * xMc, /* [0..12] OUT */
- word * mant_out, /* OUT */
- word * exp_out, /* OUT */
- word * xmaxc_out /* OUT */
-)
-{
- int i, itest;
-
- word xmax, xmaxc, temp, temp1, temp2;
- word exp, mant;
-
-
- /* Find the maximum absolute value xmax of xM[0..12].
- */
-
- xmax = 0;
- for (i = 0; i <= 12; i++) {
- temp = xM[i];
- temp = GSM_ABS(temp);
- if (temp > xmax) xmax = temp;
- }
-
- /* Qantizing and coding of xmax to get xmaxc.
- */
-
- exp = 0;
- temp = SASR( xmax, 9 );
- itest = 0;
-
- for (i = 0; i <= 5; i++) {
-
- itest |= (temp <= 0);
- temp = SASR( temp, 1 );
-
- assert(exp <= 5);
- if (itest == 0) exp++; /* exp = add (exp, 1) */
- }
-
- assert(exp <= 6 && exp >= 0);
- temp = exp + 5;
-
- assert(temp <= 11 && temp >= 0);
- xmaxc = gsm_add( SASR(xmax, temp), exp << 3 );
-
- /* Quantizing and coding of the xM[0..12] RPE sequence
- * to get the xMc[0..12]
- */
-
- APCM_quantization_xmaxc_to_exp_mant( xmaxc, &exp, &mant );
-
- /* This computation uses the fact that the decoded version of xmaxc
- * can be calculated by using the exponent and the mantissa part of
- * xmaxc (logarithmic table).
- * So, this method avoids any division and uses only a scaling
- * of the RPE samples by a function of the exponent. A direct
- * multiplication by the inverse of the mantissa (NRFAC[0..7]
- * found in table 4.5) gives the 3 bit coded version xMc[0..12]
- * of the RPE samples.
- */
-
-
- /* Direct computation of xMc[0..12] using table 4.5
- */
-
- assert( exp <= 4096 && exp >= -4096);
- assert( mant >= 0 && mant <= 7 );
-
- temp1 = 6 - exp; /* normalization by the exponent */
- temp2 = gsm_NRFAC[ mant ]; /* inverse mantissa */
-
- for (i = 0; i <= 12; i++) {
-
- assert(temp1 >= 0 && temp1 < 16);
-
- temp = xM[i] << temp1;
- temp = GSM_MULT( temp, temp2 );
- temp = SASR(temp, 12);
- xMc[i] = temp + 4; /* see note below */
- }
-
- /* NOTE: This equation is used to make all the xMc[i] positive.
- */
-
- *mant_out = mant;
- *exp_out = exp;
- *xmaxc_out = xmaxc;
-}
-
-/* 4.2.16 */
-
-static void APCM_inverse_quantization P4((xMc,mant,exp,xMp),
- register word * xMc, /* [0..12] IN */
- word mant,
- word exp,
- register word * xMp) /* [0..12] OUT */
-/*
- * This part is for decoding the RPE sequence of coded xMc[0..12]
- * samples to obtain the xMp[0..12] array. Table 4.6 is used to get
- * the mantissa of xmaxc (FAC[0..7]).
- */
-{
- int i;
- word temp, temp1, temp2, temp3;
-
- assert( mant >= 0 && mant <= 7 );
-
- temp1 = gsm_FAC[ mant ]; /* see 4.2-15 for mant */
- temp2 = gsm_sub( 6, exp ); /* see 4.2-15 for exp */
- temp3 = gsm_asl( 1, gsm_sub( temp2, 1 ));
-
- for (i = 13; i--;) {
-
- assert( *xMc <= 7 && *xMc >= 0 ); /* 3 bit unsigned */
-
- /* temp = gsm_sub( *xMc++ << 1, 7 ); */
- temp = (*xMc++ << 1) - 7; /* restore sign */
- assert( temp <= 7 && temp >= -7 ); /* 4 bit signed */
-
- temp <<= 12; /* 16 bit signed */
- temp = GSM_MULT_R( temp1, temp );
- temp = GSM_ADD( temp, temp3 );
- *xMp++ = gsm_asr( temp, temp2 );
- }
-}
-
-/* 4.2.17 */
-
-static void RPE_grid_positioning P3((Mc,xMp,ep),
- word Mc, /* grid position IN */
- register word * xMp, /* [0..12] IN */
- register word * ep /* [0..39] OUT */
-)
-/*
- * This procedure computes the reconstructed long term residual signal
- * ep[0..39] for the LTP analysis filter. The inputs are the Mc
- * which is the grid position selection and the xMp[0..12] decoded
- * RPE samples which are upsampled by a factor of 3 by inserting zero
- * values.
- */
-{
- int i = 13;
-
- assert(0 <= Mc && Mc <= 3);
-
- switch (Mc) {
- case 3: *ep++ = 0;
- case 2: do {
- *ep++ = 0;
- case 1: *ep++ = 0;
- case 0: *ep++ = *xMp++;
- } while (--i);
- }
- while (++Mc < 4) *ep++ = 0;
-
- /*
-
- int i, k;
- for (k = 0; k <= 39; k++) ep[k] = 0;
- for (i = 0; i <= 12; i++) {
- ep[ Mc + (3*i) ] = xMp[i];
- }
- */
-}
-
-/* 4.2.18 */
-
-/* This procedure adds the reconstructed long term residual signal
- * ep[0..39] to the estimated signal dpp[0..39] from the long term
- * analysis filter to compute the reconstructed short term residual
- * signal dp[-40..-1]; also the reconstructed short term residual
- * array dp[-120..-41] is updated.
- */
-
-#if 0 /* Has been inlined in code.c */
-void Gsm_Update_of_reconstructed_short_time_residual_signal P3((dpp, ep, dp),
- word * dpp, /* [0...39] IN */
- word * ep, /* [0...39] IN */
- word * dp) /* [-120...-1] IN/OUT */
-{
- int k;
-
- for (k = 0; k <= 79; k++)
- dp[ -120 + k ] = dp[ -80 + k ];
-
- for (k = 0; k <= 39; k++)
- dp[ -40 + k ] = gsm_add( ep[k], dpp[k] );
-}
-#endif /* Has been inlined in code.c */
-
-void Gsm_RPE_Encoding P5((S,e,xmaxc,Mc,xMc),
-
- struct gsm_state * S,
-
- word * e, /* -5..-1][0..39][40..44 IN/OUT */
- word * xmaxc, /* OUT */
- word * Mc, /* OUT */
- word * xMc) /* [0..12] OUT */
-{
- word x[40];
- word xM[13], xMp[13];
- word mant, exp;
-
- Weighting_filter(e, x);
- RPE_grid_selection(x, xM, Mc);
-
- APCM_quantization( xM, xMc, &mant, &exp, xmaxc);
- APCM_inverse_quantization( xMc, mant, exp, xMp);
-
- RPE_grid_positioning( *Mc, xMp, e );
-
-}
-
-void Gsm_RPE_Decoding P5((S, xmaxcr, Mcr, xMcr, erp),
- struct gsm_state * S,
-
- word xmaxcr,
- word Mcr,
- word * xMcr, /* [0..12], 3 bits IN */
- word * erp /* [0..39] OUT */
-)
-{
- word exp, mant;
- word xMp[ 13 ];
-
- APCM_quantization_xmaxc_to_exp_mant( xmaxcr, &exp, &mant );
- APCM_inverse_quantization( xMcr, mant, exp, xMp );
- RPE_grid_positioning( Mcr, xMp, erp );
-
-}
diff --git a/1.2-netsec/codecs/gsm/src/short_term.c b/1.2-netsec/codecs/gsm/src/short_term.c
deleted file mode 100644
index c8c0c1b2b..000000000
--- a/1.2-netsec/codecs/gsm/src/short_term.c
+++ /dev/null
@@ -1,448 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-#include <stdio.h>
-#include <assert.h>
-
-#include "private.h"
-
-#include "gsm.h"
-#include "proto.h"
-#ifdef K6OPT
-#include "k6opt.h"
-
-#define Short_term_analysis_filtering Short_term_analysis_filteringx
-
-#endif
-/*
- * SHORT TERM ANALYSIS FILTERING SECTION
- */
-
-/* 4.2.8 */
-
-static void Decoding_of_the_coded_Log_Area_Ratios P2((LARc,LARpp),
- word * LARc, /* coded log area ratio [0..7] IN */
- word * LARpp) /* out: decoded .. */
-{
- register word temp1 /* , temp2 */;
-
- /* This procedure requires for efficient implementation
- * two tables.
- *
- * INVA[1..8] = integer( (32768 * 8) / real_A[1..8])
- * MIC[1..8] = minimum value of the LARc[1..8]
- */
-
- /* Compute the LARpp[1..8]
- */
-
- /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {
- *
- * temp1 = GSM_ADD( *LARc, *MIC ) << 10;
- * temp2 = *B << 1;
- * temp1 = GSM_SUB( temp1, temp2 );
- *
- * assert(*INVA != MIN_WORD);
- *
- * temp1 = GSM_MULT_R( *INVA, temp1 );
- * *LARpp = GSM_ADD( temp1, temp1 );
- * }
- */
-
-#undef STEP
-#define STEP( B, MIC, INVA ) \
- temp1 = GSM_ADD( *LARc++, MIC ) << 10; \
- temp1 = GSM_SUB( temp1, B << 1 ); \
- temp1 = GSM_MULT_R( INVA, temp1 ); \
- *LARpp++ = GSM_ADD( temp1, temp1 );
-
- STEP( 0, -32, 13107 );
- STEP( 0, -32, 13107 );
- STEP( 2048, -16, 13107 );
- STEP( -2560, -16, 13107 );
-
- STEP( 94, -8, 19223 );
- STEP( -1792, -8, 17476 );
- STEP( -341, -4, 31454 );
- STEP( -1144, -4, 29708 );
-
- /* NOTE: the addition of *MIC is used to restore
- * the sign of *LARc.
- */
-}
-
-/* 4.2.9 */
-/* Computation of the quantized reflection coefficients
- */
-
-/* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8]
- */
-
-/*
- * Within each frame of 160 analyzed speech samples the short term
- * analysis and synthesis filters operate with four different sets of
- * coefficients, derived from the previous set of decoded LARs(LARpp(j-1))
- * and the actual set of decoded LARs (LARpp(j))
- *
- * (Initial value: LARpp(j-1)[1..8] = 0.)
- */
-
-static void Coefficients_0_12 P3((LARpp_j_1, LARpp_j, LARp),
- register word * LARpp_j_1,
- register word * LARpp_j,
- register word * LARp)
-{
- register int i;
-
- for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) {
- *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
- *LARp = GSM_ADD( *LARp, SASR( *LARpp_j_1, 1));
- }
-}
-
-static void Coefficients_13_26 P3((LARpp_j_1, LARpp_j, LARp),
- register word * LARpp_j_1,
- register word * LARpp_j,
- register word * LARp)
-{
- register int i;
- for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
- *LARp = GSM_ADD( SASR( *LARpp_j_1, 1), SASR( *LARpp_j, 1 ));
- }
-}
-
-static void Coefficients_27_39 P3((LARpp_j_1, LARpp_j, LARp),
- register word * LARpp_j_1,
- register word * LARpp_j,
- register word * LARp)
-{
- register int i;
-
- for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
- *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
- *LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 ));
- }
-}
-
-
-static void Coefficients_40_159 P2((LARpp_j, LARp),
- register word * LARpp_j,
- register word * LARp)
-{
- register int i;
-
- for (i = 1; i <= 8; i++, LARp++, LARpp_j++)
- *LARp = *LARpp_j;
-}
-
-/* 4.2.9.2 */
-
-static void LARp_to_rp P1((LARp),
- register word * LARp) /* [0..7] IN/OUT */
-/*
- * The input of this procedure is the interpolated LARp[0..7] array.
- * The reflection coefficients, rp[i], are used in the analysis
- * filter and in the synthesis filter.
- */
-{
- register int i;
- register word temp;
-
- for (i = 1; i <= 8; i++, LARp++) {
-
- /* temp = GSM_ABS( *LARp );
- *
- * if (temp < 11059) temp <<= 1;
- * else if (temp < 20070) temp += 11059;
- * else temp = GSM_ADD( temp >> 2, 26112 );
- *
- * *LARp = *LARp < 0 ? -temp : temp;
- */
-
- if (*LARp < 0) {
- temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp);
- *LARp = - ((temp < 11059) ? temp << 1
- : ((temp < 20070) ? temp + 11059
- : GSM_ADD( temp >> 2, 26112 )));
- } else {
- temp = *LARp;
- *LARp = (temp < 11059) ? temp << 1
- : ((temp < 20070) ? temp + 11059
- : GSM_ADD( temp >> 2, 26112 ));
- }
- }
-}
-
-
-/* 4.2.10 */
-#ifndef Short_term_analysis_filtering
-
-/* SJB Remark:
- * I tried 2 MMX versions of this function, neither is significantly
- * faster than the C version which follows. MMX might be useful if
- * one were processing 2 input streams in parallel.
- */
-static void Short_term_analysis_filtering P4((u0,rp0,k_n,s),
- register word * u0,
- register word * rp0, /* [0..7] IN */
- register int k_n, /* k_end - k_start */
- register word * s /* [0..n-1] IN/OUT */
-)
-/*
- * This procedure computes the short term residual signal d[..] to be fed
- * to the RPE-LTP loop from the s[..] signal and from the local rp[..]
- * array (quantized reflection coefficients). As the call of this
- * procedure can be done in many ways (see the interpolation of the LAR
- * coefficient), it is assumed that the computation begins with index
- * k_start (for arrays d[..] and s[..]) and stops with index k_end
- * (k_start and k_end are defined in 4.2.9.1). This procedure also
- * needs to keep the array u0[0..7] in memory for each call.
- */
-{
- register word * u_top = u0 + 8;
- register word * s_top = s + k_n;
-
- while (s < s_top) {
- register word *u, *rp ;
- register longword di, u_out;
- di = u_out = *s;
- for (rp=rp0, u=u0; u<u_top;) {
- register longword ui, rpi;
- ui = *u;
- *u++ = u_out;
- rpi = *rp++;
- u_out = ui + (((rpi*di)+0x4000)>>15);
- di = di + (((rpi*ui)+0x4000)>>15);
- /* make the common case fastest: */
- if ((u_out == (word)u_out) && (di == (word)di)) continue;
- /* otherwise do slower fixup (saturation) */
- if (u_out>MAX_WORD) u_out=MAX_WORD;
- else if (u_out<MIN_WORD) u_out=MIN_WORD;
- if (di>MAX_WORD) di=MAX_WORD;
- else if (di<MIN_WORD) di=MIN_WORD;
- }
- *s++ = di;
- }
-}
-#endif
-
-#if defined(USE_FLOAT_MUL) && defined(FAST)
-
-static void Fast_Short_term_analysis_filtering P4((u,rp,k_n,s),
- register word * u;
- register word * rp, /* [0..7] IN */
- register int k_n, /* k_end - k_start */
- register word * s /* [0..n-1] IN/OUT */
-)
-{
- register int i;
-
- float uf[8],
- rpf[8];
-
- register float scalef = 3.0517578125e-5;
- register float sav, di, temp;
-
- for (i = 0; i < 8; ++i) {
- uf[i] = u[i];
- rpf[i] = rp[i] * scalef;
- }
- for (; k_n--; s++) {
- sav = di = *s;
- for (i = 0; i < 8; ++i) {
- register float rpfi = rpf[i];
- register float ufi = uf[i];
-
- uf[i] = sav;
- temp = rpfi * di + ufi;
- di += rpfi * ufi;
- sav = temp;
- }
- *s = di;
- }
- for (i = 0; i < 8; ++i) u[i] = uf[i];
-}
-#endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */
-
-/*
- * SJB Remark: modified Short_term_synthesis_filtering() below
- * for significant (abt 35%) speedup of decompression.
- * (gcc-2.95, k6 cpu)
- * Please don't change this without benchmarking decompression
- * to see that you haven't harmed speed.
- * This function burns most of CPU time for untoasting.
- * Unfortunately, didn't see any good way to benefit from mmx.
- */
-static void Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),
- struct gsm_state * S,
- register word * rrp, /* [0..7] IN */
- register int k, /* k_end - k_start */
- register word * wt, /* [0..k-1] IN */
- register word * sr /* [0..k-1] OUT */
-)
-{
- register word * v = S->v;
- register int i;
- register longword sri;
-
- while (k--) {
- sri = *wt++;
- for (i = 8; i--;) {
- register longword tmp1, tmp2;
-
- /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );
- */
- tmp1 = rrp[i];
- tmp2 = v[i];
-
- tmp2 = (( tmp1 * tmp2 + 16384) >> 15) ;
- /* saturation done below */
- sri -= tmp2;
- if (sri != (word)sri) {
- sri = (sri<0)? MIN_WORD:MAX_WORD;
- }
- /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );
- */
-
- tmp1 = (( tmp1 * sri + 16384) >> 15) ;
- /* saturation done below */
- tmp1 += v[i];
- if (tmp1 != (word)tmp1) {
- tmp1 = (tmp1<0)? MIN_WORD:MAX_WORD;
- }
- v[i+1] = tmp1;
- }
- *sr++ = v[0] = sri;
- }
-}
-
-
-#if defined(FAST) && defined(USE_FLOAT_MUL)
-
-static void Fast_Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),
- struct gsm_state * S,
- register word * rrp, /* [0..7] IN */
- register int k, /* k_end - k_start */
- register word * wt, /* [0..k-1] IN */
- register word * sr /* [0..k-1] OUT */
-)
-{
- register word * v = S->v;
- register int i;
-
- float va[9], rrpa[8];
- register float scalef = 3.0517578125e-5, temp;
-
- for (i = 0; i < 8; ++i) {
- va[i] = v[i];
- rrpa[i] = (float)rrp[i] * scalef;
- }
- while (k--) {
- register float sri = *wt++;
- for (i = 8; i--;) {
- sri -= rrpa[i] * va[i];
- if (sri < -32768.) sri = -32768.;
- else if (sri > 32767.) sri = 32767.;
-
- temp = va[i] + rrpa[i] * sri;
- if (temp < -32768.) temp = -32768.;
- else if (temp > 32767.) temp = 32767.;
- va[i+1] = temp;
- }
- *sr++ = va[0] = sri;
- }
- for (i = 0; i < 9; ++i) v[i] = va[i];
-}
-
-#endif /* defined(FAST) && defined(USE_FLOAT_MUL) */
-
-void Gsm_Short_Term_Analysis_Filter P3((S,LARc,s),
-
- struct gsm_state * S,
-
- word * LARc, /* coded log area ratio [0..7] IN */
- word * s /* signal [0..159] IN/OUT */
-)
-{
- word * LARpp_j = S->LARpp[ S->j ];
- word * LARpp_j_1 = S->LARpp[ S->j ^= 1 ];
-
- word LARp[8];
-int i;
-#undef FILTER
-#if defined(FAST) && defined(USE_FLOAT_MUL)
-# define FILTER (* (S->fast \
- ? Fast_Short_term_analysis_filtering \
- : Short_term_analysis_filtering ))
-
-#else
-# define FILTER Short_term_analysis_filtering
-#endif
-
- Decoding_of_the_coded_Log_Area_Ratios( LARc, LARpp_j );
-
- Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
- LARp_to_rp( LARp );
- FILTER( S->u, LARp, 13, s);
-
- Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
- LARp_to_rp( LARp );
- FILTER( S->u, LARp, 14, s + 13);
-
- Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
- LARp_to_rp( LARp );
- FILTER( S->u, LARp, 13, s + 27);
-
- Coefficients_40_159( LARpp_j, LARp);
- LARp_to_rp( LARp );
- FILTER( S->u, LARp, 120, s + 40);
-
-}
-
-void Gsm_Short_Term_Synthesis_Filter P4((S, LARcr, wt, s),
- struct gsm_state * S,
-
- word * LARcr, /* received log area ratios [0..7] IN */
- word * wt, /* received d [0..159] IN */
-
- word * s /* signal s [0..159] OUT */
-)
-{
- word * LARpp_j = S->LARpp[ S->j ];
- word * LARpp_j_1 = S->LARpp[ S->j ^=1 ];
-
- word LARp[8];
-
-#undef FILTER
-#if defined(FAST) && defined(USE_FLOAT_MUL)
-
-# define FILTER (* (S->fast \
- ? Fast_Short_term_synthesis_filtering \
- : Short_term_synthesis_filtering ))
-#else
-# define FILTER Short_term_synthesis_filtering
-#endif
-
- Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j );
-
- Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
- LARp_to_rp( LARp );
- FILTER( S, LARp, 13, wt, s );
-
- Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
- LARp_to_rp( LARp );
- FILTER( S, LARp, 14, wt + 13, s + 13 );
-
- Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
- LARp_to_rp( LARp );
- FILTER( S, LARp, 13, wt + 27, s + 27 );
-
- Coefficients_40_159( LARpp_j, LARp );
- LARp_to_rp( LARp );
- FILTER(S, LARp, 120, wt + 40, s + 40);
-}
diff --git a/1.2-netsec/codecs/gsm/src/table.c b/1.2-netsec/codecs/gsm/src/table.c
deleted file mode 100644
index 16a04118c..000000000
--- a/1.2-netsec/codecs/gsm/src/table.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
- * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
- * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
- */
-
-/* $Header$ */
-
-/* Most of these tables are inlined at their point of use.
- */
-
-/* 4.4 TABLES USED IN THE FIXED POINT IMPLEMENTATION OF THE RPE-LTP
- * CODER AND DECODER
- *
- * (Most of them inlined, so watch out.)
- */
-
-#define GSM_TABLE_C
-#include "private.h"
-#include "gsm.h"
-
-/* Table 4.1 Quantization of the Log.-Area Ratios
- */
-/* i 1 2 3 4 5 6 7 8 */
-word gsm_A[8] = {20480, 20480, 20480, 20480, 13964, 15360, 8534, 9036};
-word gsm_B[8] = { 0, 0, 2048, -2560, 94, -1792, -341, -1144};
-word gsm_MIC[8] = { -32, -32, -16, -16, -8, -8, -4, -4 };
-word gsm_MAC[8] = { 31, 31, 15, 15, 7, 7, 3, 3 };
-
-
-/* Table 4.2 Tabulation of 1/A[1..8]
- */
-word gsm_INVA[8]={ 13107, 13107, 13107, 13107, 19223, 17476, 31454, 29708 };
-
-
-/* Table 4.3a Decision level of the LTP gain quantizer
- */
-/* bc 0 1 2 3 */
-word gsm_DLB[4] = { 6554, 16384, 26214, 32767 };
-
-
-/* Table 4.3b Quantization levels of the LTP gain quantizer
- */
-/* bc 0 1 2 3 */
-word gsm_QLB[4] = { 3277, 11469, 21299, 32767 };
-
-
-/* Table 4.4 Coefficients of the weighting filter
- */
-/* i 0 1 2 3 4 5 6 7 8 9 10 */
-word gsm_H[11] = {-134, -374, 0, 2054, 5741, 8192, 5741, 2054, 0, -374, -134 };
-
-
-/* Table 4.5 Normalized inverse mantissa used to compute xM/xmax
- */
-/* i 0 1 2 3 4 5 6 7 */
-word gsm_NRFAC[8] = { 29128, 26215, 23832, 21846, 20165, 18725, 17476, 16384 };
-
-
-/* Table 4.6 Normalized direct mantissa used to compute xM/xmax
- */
-/* i 0 1 2 3 4 5 6 7 */
-word gsm_FAC[8] = { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 };
diff --git a/1.2-netsec/codecs/gsm_slin_ex.h b/1.2-netsec/codecs/gsm_slin_ex.h
deleted file mode 100644
index 2f001abec..000000000
--- a/1.2-netsec/codecs/gsm_slin_ex.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*! \file
- * \brief 8-bit raw data
- *
- * Source: gsm.example
- *
- * Copyright (C) 1999-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char gsm_slin_ex[] = {
-0xda, 0xa6, 0xac, 0x2d, 0xa3, 0x50, 000, 0x49, 0x24, 0x92,
-0x49, 0x24, 0x50, 0x40, 0x49, 0x24, 0x92, 0x37, 0x24, 0x52,
-000, 0x49, 0x24, 0x92, 0x47, 0x24, 0x50, 0x80, 0x46, 0xe3,
-0x6d, 0xb8, 0xdc };
diff --git a/1.2-netsec/codecs/ilbc/FrameClassify.c b/1.2-netsec/codecs/ilbc/FrameClassify.c
deleted file mode 100644
index c982fd667..000000000
--- a/1.2-netsec/codecs/ilbc/FrameClassify.c
+++ /dev/null
@@ -1,110 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- FrameClassify.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include "iLBC_define.h"
-#include "FrameClassify.h"
-
-/*---------------------------------------------------------------*
- * Classification of subframes to localize start state
- *--------------------------------------------------------------*/
-
-int FrameClassify( /* index to the max-energy sub-frame */
- iLBC_Enc_Inst_t *iLBCenc_inst,
- /* (i/o) the encoder state structure */
- float *residual /* (i) lpc residual signal */
-) {
- float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;
- int n, l, max_ssqEn_n;
- const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,
- (float)1.0,(float)0.9,(float)0.8};
- const float sampEn_win[5]={(float)1.0/(float)6.0,
- (float)2.0/(float)6.0, (float)3.0/(float)6.0,
- (float)4.0/(float)6.0, (float)5.0/(float)6.0};
-
- /* init the front and back energies to zero */
-
- memset(fssqEn, 0, NSUB_MAX*sizeof(float));
- memset(bssqEn, 0, NSUB_MAX*sizeof(float));
-
- /* Calculate front of first seqence */
-
- n=0;
- pp=residual;
-
-
- for (l=0; l<5; l++) {
- fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
- pp++;
- }
- for (l=5; l<SUBL; l++) {
- fssqEn[n] += (*pp) * (*pp);
- pp++;
- }
-
- /* Calculate front and back of all middle sequences */
-
- for (n=1; n<iLBCenc_inst->nsub-1; n++) {
- pp=residual+n*SUBL;
- for (l=0; l<5; l++) {
- fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
- bssqEn[n] += (*pp) * (*pp);
- pp++;
- }
- for (l=5; l<SUBL-5; l++) {
- fssqEn[n] += (*pp) * (*pp);
- bssqEn[n] += (*pp) * (*pp);
- pp++;
- }
- for (l=SUBL-5; l<SUBL; l++) {
- fssqEn[n] += (*pp) * (*pp);
- bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
- pp++;
- }
- }
-
- /* Calculate back of last seqence */
-
- n=iLBCenc_inst->nsub-1;
- pp=residual+n*SUBL;
- for (l=0; l<SUBL-5; l++) {
- bssqEn[n] += (*pp) * (*pp);
- pp++;
- }
- for (l=SUBL-5; l<SUBL; l++) {
- bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
- pp++;
- }
-
- /* find the index to the weighted 80 sample with
- most energy */
-
- if (iLBCenc_inst->mode==20) l=1;
- else l=0;
-
- max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];
- max_ssqEn_n=1;
- for (n=2; n<iLBCenc_inst->nsub; n++) {
-
- l++;
-
-
- if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {
- max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *
- ssqEn_win[l];
- max_ssqEn_n=n;
- }
- }
-
- return max_ssqEn_n;
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/FrameClassify.h b/1.2-netsec/codecs/ilbc/FrameClassify.h
deleted file mode 100644
index 35cbd325b..000000000
--- a/1.2-netsec/codecs/ilbc/FrameClassify.h
+++ /dev/null
@@ -1,26 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- FrameClassify.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-
-
-#ifndef __iLBC_FRAMECLASSIFY_H
-#define __iLBC_FRAMECLASSIFY_H
-
-int FrameClassify( /* index to the max-energy sub-frame */
- iLBC_Enc_Inst_t *iLBCenc_inst,
- /* (i/o) the encoder state structure */
- float *residual /* (i) lpc residual signal */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/LPCdecode.c b/1.2-netsec/codecs/ilbc/LPCdecode.c
deleted file mode 100644
index f4bc9896d..000000000
--- a/1.2-netsec/codecs/ilbc/LPCdecode.c
+++ /dev/null
@@ -1,152 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- LPC_decode.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-#include <string.h>
-
-#include "helpfun.h"
-#include "lsf.h"
-#include "iLBC_define.h"
-#include "LPCdecode.h"
-#include "constants.h"
-
-/*---------------------------------------------------------------*
- * interpolation of lsf coefficients for the decoder
- *--------------------------------------------------------------*/
-
-void LSFinterpolate2a_dec(
- float *a, /* (o) lpc coefficients for a sub-frame */
- float *lsf1, /* (i) first lsf coefficient vector */
-
-
- float *lsf2, /* (i) second lsf coefficient vector */
- float coef, /* (i) interpolation weight */
- int length /* (i) length of lsf vectors */
-){
- float lsftmp[LPC_FILTERORDER];
-
- interpolate(lsftmp, lsf1, lsf2, coef, length);
- lsf2a(a, lsftmp);
-}
-
-/*---------------------------------------------------------------*
- * obtain dequantized lsf coefficients from quantization index
- *--------------------------------------------------------------*/
-
-void SimplelsfDEQ(
- float *lsfdeq, /* (o) dequantized lsf coefficients */
- int *index, /* (i) quantization index */
- int lpc_n /* (i) number of LPCs */
-){
- int i, j, pos, cb_pos;
-
- /* decode first LSF */
-
- pos = 0;
- cb_pos = 0;
- for (i = 0; i < LSF_NSPLIT; i++) {
- for (j = 0; j < dim_lsfCbTbl[i]; j++) {
- lsfdeq[pos + j] = lsfCbTbl[cb_pos +
- (long)(index[i])*dim_lsfCbTbl[i] + j];
- }
- pos += dim_lsfCbTbl[i];
- cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
- }
-
- if (lpc_n>1) {
-
- /* decode last LSF */
-
- pos = 0;
- cb_pos = 0;
- for (i = 0; i < LSF_NSPLIT; i++) {
- for (j = 0; j < dim_lsfCbTbl[i]; j++) {
- lsfdeq[LPC_FILTERORDER + pos + j] =
- lsfCbTbl[cb_pos +
- (long)(index[LSF_NSPLIT + i])*
- dim_lsfCbTbl[i] + j];
- }
- pos += dim_lsfCbTbl[i];
- cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
- }
- }
-}
-
-/*----------------------------------------------------------------*
-
-
- * obtain synthesis and weighting filters form lsf coefficients
- *---------------------------------------------------------------*/
-
-void DecoderInterpolateLSF(
- float *syntdenum, /* (o) synthesis filter coefficients */
- float *weightdenum, /* (o) weighting denumerator
- coefficients */
- float *lsfdeq, /* (i) dequantized lsf coefficients */
- int length, /* (i) length of lsf coefficient vector */
- iLBC_Dec_Inst_t *iLBCdec_inst
- /* (i) the decoder state structure */
-){
- int i, pos, lp_length;
- float lp[LPC_FILTERORDER + 1], *lsfdeq2;
-
- lsfdeq2 = lsfdeq + length;
- lp_length = length + 1;
-
- if (iLBCdec_inst->mode==30) {
- /* sub-frame 1: Interpolation between old and first */
-
- LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq,
- lsf_weightTbl_30ms[0], length);
- memcpy(syntdenum,lp,lp_length*sizeof(float));
- bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM,
- lp_length);
-
- /* sub-frames 2 to 6: interpolation between first
- and last LSF */
-
- pos = lp_length;
- for (i = 1; i < 6; i++) {
- LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2,
- lsf_weightTbl_30ms[i], length);
- memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
- bwexpand(weightdenum + pos, lp,
- LPC_CHIRP_WEIGHTDENUM, lp_length);
- pos += lp_length;
- }
- }
- else {
- pos = 0;
- for (i = 0; i < iLBCdec_inst->nsub; i++) {
- LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold,
- lsfdeq, lsf_weightTbl_20ms[i], length);
- memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
- bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM,
- lp_length);
- pos += lp_length;
- }
- }
-
- /* update memory */
-
-
-
- if (iLBCdec_inst->mode==30)
- memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2,
- length*sizeof(float));
- else
- memcpy(iLBCdec_inst->lsfdeqold, lsfdeq,
- length*sizeof(float));
-
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/LPCdecode.h b/1.2-netsec/codecs/ilbc/LPCdecode.h
deleted file mode 100644
index 1f55a622e..000000000
--- a/1.2-netsec/codecs/ilbc/LPCdecode.h
+++ /dev/null
@@ -1,44 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- LPC_decode.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_LPC_DECODE_H
-#define __iLBC_LPC_DECODE_H
-
-void LSFinterpolate2a_dec(
-
-
- float *a, /* (o) lpc coefficients for a sub-frame */
- float *lsf1, /* (i) first lsf coefficient vector */
- float *lsf2, /* (i) second lsf coefficient vector */
- float coef, /* (i) interpolation weight */
- int length /* (i) length of lsf vectors */
-);
-
-void SimplelsfDEQ(
- float *lsfdeq, /* (o) dequantized lsf coefficients */
- int *index, /* (i) quantization index */
- int lpc_n /* (i) number of LPCs */
-);
-
-void DecoderInterpolateLSF(
- float *syntdenum, /* (o) synthesis filter coefficients */
- float *weightdenum, /* (o) weighting denumerator
- coefficients */
- float *lsfdeq, /* (i) dequantized lsf coefficients */
- int length, /* (i) length of lsf coefficient vector */
- iLBC_Dec_Inst_t *iLBCdec_inst
- /* (i) the decoder state structure */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/LPCencode.c b/1.2-netsec/codecs/ilbc/LPCencode.c
deleted file mode 100644
index 4d5fcff21..000000000
--- a/1.2-netsec/codecs/ilbc/LPCencode.c
+++ /dev/null
@@ -1,228 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- LPCencode.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <string.h>
-
-
-
-#include "iLBC_define.h"
-#include "LPCencode.h"
-#include "helpfun.h"
-#include "lsf.h"
-#include "constants.h"
-
-/*----------------------------------------------------------------*
- * lpc analysis (subrutine to LPCencode)
- *---------------------------------------------------------------*/
-
-static void SimpleAnalysis(
- float *lsf, /* (o) lsf coefficients */
- float *data, /* (i) new data vector */
- iLBC_Enc_Inst_t *iLBCenc_inst
- /* (i/o) the encoder state structure */
-){
- int k, is;
- float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1];
- float lp2[LPC_FILTERORDER + 1];
- float r[LPC_FILTERORDER + 1];
-
- is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;
- memcpy(iLBCenc_inst->lpc_buffer+is,data,
- iLBCenc_inst->blockl*sizeof(float));
-
- /* No lookahead, last window is asymmetric */
-
- for (k = 0; k < iLBCenc_inst->lpc_n; k++) {
-
- is = LPC_LOOKBACK;
-
- if (k < (iLBCenc_inst->lpc_n - 1)) {
- window(temp, lpc_winTbl,
- iLBCenc_inst->lpc_buffer, BLOCKL_MAX);
- } else {
- window(temp, lpc_asymwinTbl,
- iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX);
- }
-
- autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER);
- window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1);
-
- levdurb(lp, temp, r, LPC_FILTERORDER);
- bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1);
-
- a2lsf(lsf + k*LPC_FILTERORDER, lp2);
- }
- is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;
- memmove(iLBCenc_inst->lpc_buffer,
- iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is,
- is*sizeof(float));
-}
-
-/*----------------------------------------------------------------*
-
-
- * lsf interpolator and conversion from lsf to a coefficients
- * (subrutine to SimpleInterpolateLSF)
- *---------------------------------------------------------------*/
-
-static void LSFinterpolate2a_enc(
- float *a, /* (o) lpc coefficients */
- float *lsf1,/* (i) first set of lsf coefficients */
- float *lsf2,/* (i) second set of lsf coefficients */
- float coef, /* (i) weighting coefficient to use between
- lsf1 and lsf2 */
- long length /* (i) length of coefficient vectors */
-){
- float lsftmp[LPC_FILTERORDER];
-
- interpolate(lsftmp, lsf1, lsf2, coef, length);
- lsf2a(a, lsftmp);
-}
-
-/*----------------------------------------------------------------*
- * lsf interpolator (subrutine to LPCencode)
- *---------------------------------------------------------------*/
-
-static void SimpleInterpolateLSF(
- float *syntdenum, /* (o) the synthesis filter denominator
- resulting from the quantized
- interpolated lsf */
- float *weightdenum, /* (o) the weighting filter denominator
- resulting from the unquantized
- interpolated lsf */
- float *lsf, /* (i) the unquantized lsf coefficients */
- float *lsfdeq, /* (i) the dequantized lsf coefficients */
- float *lsfold, /* (i) the unquantized lsf coefficients of
- the previous signal frame */
- float *lsfdeqold, /* (i) the dequantized lsf coefficients of
- the previous signal frame */
- int length, /* (i) should equate LPC_FILTERORDER */
- iLBC_Enc_Inst_t *iLBCenc_inst
- /* (i/o) the encoder state structure */
-){
- int i, pos, lp_length;
- float lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2;
-
- lsf2 = lsf + length;
- lsfdeq2 = lsfdeq + length;
- lp_length = length + 1;
-
- if (iLBCenc_inst->mode==30) {
- /* sub-frame 1: Interpolation between old and first
- set of lsf coefficients */
-
- LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq,
- lsf_weightTbl_30ms[0], length);
- memcpy(syntdenum,lp,lp_length*sizeof(float));
- LSFinterpolate2a_enc(lp, lsfold, lsf,
-
-
- lsf_weightTbl_30ms[0], length);
- bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
-
- /* sub-frame 2 to 6: Interpolation between first
- and second set of lsf coefficients */
-
- pos = lp_length;
- for (i = 1; i < iLBCenc_inst->nsub; i++) {
- LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2,
- lsf_weightTbl_30ms[i], length);
- memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
-
- LSFinterpolate2a_enc(lp, lsf, lsf2,
- lsf_weightTbl_30ms[i], length);
- bwexpand(weightdenum + pos, lp,
- LPC_CHIRP_WEIGHTDENUM, lp_length);
- pos += lp_length;
- }
- }
- else {
- pos = 0;
- for (i = 0; i < iLBCenc_inst->nsub; i++) {
- LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq,
- lsf_weightTbl_20ms[i], length);
- memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
- LSFinterpolate2a_enc(lp, lsfold, lsf,
- lsf_weightTbl_20ms[i], length);
- bwexpand(weightdenum+pos, lp,
- LPC_CHIRP_WEIGHTDENUM, lp_length);
- pos += lp_length;
- }
- }
-
- /* update memory */
-
- if (iLBCenc_inst->mode==30) {
- memcpy(lsfold, lsf2, length*sizeof(float));
- memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));
- }
- else {
- memcpy(lsfold, lsf, length*sizeof(float));
- memcpy(lsfdeqold, lsfdeq, length*sizeof(float));
- }
-}
-
-/*----------------------------------------------------------------*
- * lsf quantizer (subrutine to LPCencode)
- *---------------------------------------------------------------*/
-
-static void SimplelsfQ(
- float *lsfdeq, /* (o) dequantized lsf coefficients
- (dimension FILTERORDER) */
- int *index, /* (o) quantization index */
- float *lsf, /* (i) the lsf coefficient vector to be
-
-
- quantized (dimension FILTERORDER ) */
- int lpc_n /* (i) number of lsf sets to quantize */
-){
- /* Quantize first LSF with memoryless split VQ */
- SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT,
- dim_lsfCbTbl, size_lsfCbTbl);
-
- if (lpc_n==2) {
- /* Quantize second LSF with memoryless split VQ */
- SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT,
- lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT,
- dim_lsfCbTbl, size_lsfCbTbl);
- }
-}
-
-/*----------------------------------------------------------------*
- * lpc encoder
- *---------------------------------------------------------------*/
-
-void LPCencode(
- float *syntdenum, /* (i/o) synthesis filter coefficients
- before/after encoding */
- float *weightdenum, /* (i/o) weighting denumerator
- coefficients before/after
- encoding */
- int *lsf_index, /* (o) lsf quantization index */
- float *data, /* (i) lsf coefficients to quantize */
- iLBC_Enc_Inst_t *iLBCenc_inst
- /* (i/o) the encoder state structure */
-){
- float lsf[LPC_FILTERORDER * LPC_N_MAX];
- float lsfdeq[LPC_FILTERORDER * LPC_N_MAX];
- int change=0;
-
- SimpleAnalysis(lsf, data, iLBCenc_inst);
- SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n);
- change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n);
- SimpleInterpolateLSF(syntdenum, weightdenum,
- lsf, lsfdeq, iLBCenc_inst->lsfold,
- iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst);
-}
-
-
-
diff --git a/1.2-netsec/codecs/ilbc/LPCencode.h b/1.2-netsec/codecs/ilbc/LPCencode.h
deleted file mode 100644
index 5712163c2..000000000
--- a/1.2-netsec/codecs/ilbc/LPCencode.h
+++ /dev/null
@@ -1,29 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- LPCencode.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_LPCENCOD_H
-#define __iLBC_LPCENCOD_H
-
-void LPCencode(
- float *syntdenum, /* (i/o) synthesis filter coefficients
- before/after encoding */
- float *weightdenum, /* (i/o) weighting denumerator coefficients
- before/after encoding */
- int *lsf_index, /* (o) lsf quantization index */
- float *data, /* (i) lsf coefficients to quantize */
- iLBC_Enc_Inst_t *iLBCenc_inst
- /* (i/o) the encoder state structure */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/Makefile b/1.2-netsec/codecs/ilbc/Makefile
deleted file mode 100644
index 1540c140f..000000000
--- a/1.2-netsec/codecs/ilbc/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-ARCH=$(PROC)
-CFLAGS+=-Wall -O3 -funroll-loops
-ifneq (${OSARCH},CYGWIN)
-CFLAGS += -fPIC
-endif
-LIB=libilbc.a
-
-OBJS= anaFilter.o iCBSearch.o packing.o \
- constants.o gainquant.o iLBC_decode.o StateConstructW.o \
- createCB.o getCBvec.o iLBC_encode.o StateSearchW.o doCPLC.o \
- helpfun.o syntFilter.o enhancer.o hpInput.o LPCdecode.o \
- filter.o hpOutput.o LPCencode.o FrameClassify.o iCBConstruct.o lsf.o
-
-all: $(LIB)
-
-
-$(LIB): $(OBJS)
- ar cr $(LIB) $(OBJS)
- ranlib $(LIB)
-
-clean:
- rm -f $(LIB) *.o
-
-install:
-
diff --git a/1.2-netsec/codecs/ilbc/StateConstructW.c b/1.2-netsec/codecs/ilbc/StateConstructW.c
deleted file mode 100644
index e48fe035d..000000000
--- a/1.2-netsec/codecs/ilbc/StateConstructW.c
+++ /dev/null
@@ -1,76 +0,0 @@
-
-/******************************************************************
-
-
-
- iLBC Speech Coder ANSI-C Source Code
-
- StateConstructW.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-#include <string.h>
-
-#include "iLBC_define.h"
-#include "StateConstructW.h"
-#include "constants.h"
-#include "filter.h"
-
-/*----------------------------------------------------------------*
- * decoding of the start state
- *---------------------------------------------------------------*/
-
-void StateConstructW(
- int idxForMax, /* (i) 6-bit index for the quantization of
- max amplitude */
- int *idxVec, /* (i) vector of quantization indexes */
- float *syntDenum, /* (i) synthesis filter denumerator */
- float *out, /* (o) the decoded state vector */
- int len /* (i) length of a state vector */
-){
- float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp,
- numerator[LPC_FILTERORDER+1];
- float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout;
- int k,tmpi;
-
- /* decoding of the maximum value */
-
- maxVal = state_frgqTbl[idxForMax];
- maxVal = (float)pow(10,maxVal)/(float)4.5;
-
- /* initialization of buffers and coefficients */
-
- memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));
- memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));
- for (k=0; k<LPC_FILTERORDER; k++) {
- numerator[k]=syntDenum[LPC_FILTERORDER-k];
- }
- numerator[LPC_FILTERORDER]=syntDenum[0];
- tmp = &tmpbuf[LPC_FILTERORDER];
- fout = &foutbuf[LPC_FILTERORDER];
-
- /* decoding of the sample values */
-
- for (k=0; k<len; k++) {
- tmpi = len-1-k;
- /* maxVal = 1/scal */
-
-
- tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]];
- }
-
- /* circular convolution with all-pass filter */
-
- memset(tmp+len, 0, len*sizeof(float));
- ZeroPoleFilter(tmp, numerator, syntDenum, 2*len,
- LPC_FILTERORDER, fout);
- for (k=0;k<len;k++) {
- out[k] = fout[len-1-k]+fout[2*len-1-k];
- }
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/StateConstructW.h b/1.2-netsec/codecs/ilbc/StateConstructW.h
deleted file mode 100644
index bf9332b4a..000000000
--- a/1.2-netsec/codecs/ilbc/StateConstructW.h
+++ /dev/null
@@ -1,27 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- StateConstructW.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_STATECONSTRUCTW_H
-#define __iLBC_STATECONSTRUCTW_H
-
-void StateConstructW(
- int idxForMax, /* (i) 6-bit index for the quantization of
- max amplitude */
- int *idxVec, /* (i) vector of quantization indexes */
- float *syntDenum, /* (i) synthesis filter denumerator */
- float *out, /* (o) the decoded state vector */
- int len /* (i) length of a state vector */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/StateSearchW.c b/1.2-netsec/codecs/ilbc/StateSearchW.c
deleted file mode 100644
index b87b9f3c6..000000000
--- a/1.2-netsec/codecs/ilbc/StateSearchW.c
+++ /dev/null
@@ -1,194 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- StateSearchW.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-#include <string.h>
-
-#include "iLBC_define.h"
-#include "StateSearchW.h"
-#include "constants.h"
-#include "filter.h"
-#include "helpfun.h"
-
-/*----------------------------------------------------------------*
- * predictive noise shaping encoding of scaled start state
- * (subrutine for StateSearchW)
- *---------------------------------------------------------------*/
-
-void AbsQuantW(
- iLBC_Enc_Inst_t *iLBCenc_inst,
- /* (i) Encoder instance */
- float *in, /* (i) vector to encode */
- float *syntDenum, /* (i) denominator of synthesis filter */
- float *weightDenum, /* (i) denominator of weighting filter */
- int *out, /* (o) vector of quantizer indexes */
- int len, /* (i) length of vector to encode and
- vector of quantizer indexes */
- int state_first /* (i) position of start state in the
- 80 vec */
-){
- float *syntOut;
- float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS];
- float toQ, xq;
- int n;
- int index;
-
- /* initialization of buffer for filtering */
-
- memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float));
-
-
-
- /* initialization of pointer for filtering */
-
- syntOut = &syntOutBuf[LPC_FILTERORDER];
-
- /* synthesis and weighting filters on input */
-
- if (state_first) {
- AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER);
- } else {
- AllPoleFilter (in, weightDenum,
- iLBCenc_inst->state_short_len-SUBL,
- LPC_FILTERORDER);
- }
-
- /* encoding loop */
-
- for (n=0; n<len; n++) {
-
- /* time update of filter coefficients */
-
- if ((state_first)&&(n==SUBL)){
- syntDenum += (LPC_FILTERORDER+1);
- weightDenum += (LPC_FILTERORDER+1);
-
- /* synthesis and weighting filters on input */
- AllPoleFilter (&in[n], weightDenum, len-n,
- LPC_FILTERORDER);
-
- } else if ((state_first==0)&&
- (n==(iLBCenc_inst->state_short_len-SUBL))) {
- syntDenum += (LPC_FILTERORDER+1);
- weightDenum += (LPC_FILTERORDER+1);
-
- /* synthesis and weighting filters on input */
- AllPoleFilter (&in[n], weightDenum, len-n,
- LPC_FILTERORDER);
-
- }
-
- /* prediction of synthesized and weighted input */
-
- syntOut[n] = 0.0;
- AllPoleFilter (&syntOut[n], weightDenum, 1,
- LPC_FILTERORDER);
-
- /* quantization */
-
- toQ = in[n]-syntOut[n];
- sort_sq(&xq, &index, toQ, state_sq3Tbl, 8);
- out[n]=index;
- syntOut[n] = state_sq3Tbl[out[n]];
-
- /* update of the prediction filter */
-
-
-
- AllPoleFilter(&syntOut[n], weightDenum, 1,
- LPC_FILTERORDER);
- }
-}
-
-/*----------------------------------------------------------------*
- * encoding of start state
- *---------------------------------------------------------------*/
-
-void StateSearchW(
- iLBC_Enc_Inst_t *iLBCenc_inst,
- /* (i) Encoder instance */
- float *residual,/* (i) target residual vector */
- float *syntDenum, /* (i) lpc synthesis filter */
- float *weightDenum, /* (i) weighting filter denuminator */
- int *idxForMax, /* (o) quantizer index for maximum
- amplitude */
- int *idxVec, /* (o) vector of quantization indexes */
- int len, /* (i) length of all vectors */
- int state_first /* (i) position of start state in the
- 80 vec */
-){
- float dtmp, maxVal;
- float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS];
- float *tmp, numerator[1+LPC_FILTERORDER];
- float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout;
- int k;
- float qmax, scal;
-
- /* initialization of buffers and filter coefficients */
-
- memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));
- memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));
- for (k=0; k<LPC_FILTERORDER; k++) {
- numerator[k]=syntDenum[LPC_FILTERORDER-k];
- }
- numerator[LPC_FILTERORDER]=syntDenum[0];
- tmp = &tmpbuf[LPC_FILTERORDER];
- fout = &foutbuf[LPC_FILTERORDER];
-
- /* circular convolution with the all-pass filter */
-
- memcpy(tmp, residual, len*sizeof(float));
- memset(tmp+len, 0, len*sizeof(float));
- ZeroPoleFilter(tmp, numerator, syntDenum, 2*len,
- LPC_FILTERORDER, fout);
- for (k=0; k<len; k++) {
- fout[k] += fout[k+len];
- }
-
- /* identification of the maximum amplitude value */
-
- maxVal = fout[0];
-
-
- for (k=1; k<len; k++) {
-
- if (fout[k]*fout[k] > maxVal*maxVal){
- maxVal = fout[k];
- }
- }
- maxVal=(float)fabs(maxVal);
-
- /* encoding of the maximum amplitude value */
-
- if (maxVal < 10.0) {
- maxVal = 10.0;
- }
- maxVal = (float)log10(maxVal);
- sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64);
-
- /* decoding of the maximum amplitude representation value,
- and corresponding scaling of start state */
-
- maxVal=state_frgqTbl[*idxForMax];
- qmax = (float)pow(10,maxVal);
- scal = (float)(4.5)/qmax;
- for (k=0; k<len; k++){
- fout[k] *= scal;
- }
-
- /* predictive noise shaping encoding of scaled start state */
-
- AbsQuantW(iLBCenc_inst, fout,syntDenum,
- weightDenum,idxVec, len, state_first);
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/StateSearchW.h b/1.2-netsec/codecs/ilbc/StateSearchW.h
deleted file mode 100644
index 7b91476d9..000000000
--- a/1.2-netsec/codecs/ilbc/StateSearchW.h
+++ /dev/null
@@ -1,48 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- StateSearchW.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_STATESEARCHW_H
-#define __iLBC_STATESEARCHW_H
-
-void AbsQuantW(
- iLBC_Enc_Inst_t *iLBCenc_inst,
- /* (i) Encoder instance */
- float *in, /* (i) vector to encode */
- float *syntDenum, /* (i) denominator of synthesis filter */
- float *weightDenum, /* (i) denominator of weighting filter */
- int *out, /* (o) vector of quantizer indexes */
- int len, /* (i) length of vector to encode and
- vector of quantizer indexes */
- int state_first /* (i) position of start state in the
- 80 vec */
-);
-
-void StateSearchW(
- iLBC_Enc_Inst_t *iLBCenc_inst,
- /* (i) Encoder instance */
- float *residual,/* (i) target residual vector */
- float *syntDenum, /* (i) lpc synthesis filter */
- float *weightDenum, /* (i) weighting filter denuminator */
- int *idxForMax, /* (o) quantizer index for maximum
- amplitude */
- int *idxVec, /* (o) vector of quantization indexes */
- int len, /* (i) length of all vectors */
- int state_first /* (i) position of start state in the
-
-
- 80 vec */
-);
-
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/anaFilter.c b/1.2-netsec/codecs/ilbc/anaFilter.c
deleted file mode 100644
index f88fefaa0..000000000
--- a/1.2-netsec/codecs/ilbc/anaFilter.c
+++ /dev/null
@@ -1,71 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- anaFilter.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <string.h>
-#include "anaFilter.h"
-#include "iLBC_define.h"
-
-/*----------------------------------------------------------------*
- * LP analysis filter.
-
-
- *---------------------------------------------------------------*/
-
-void anaFilter(
- float *In, /* (i) Signal to be filtered */
- float *a, /* (i) LP parameters */
- int len,/* (i) Length of signal */
- float *Out, /* (o) Filtered signal */
- float *mem /* (i/o) Filter state */
-){
- int i, j;
- float *po, *pi, *pm, *pa;
-
- po = Out;
-
- /* Filter first part using memory from past */
-
- for (i=0; i<LPC_FILTERORDER; i++) {
- pi = &In[i];
- pm = &mem[LPC_FILTERORDER-1];
- pa = a;
- *po=0.0;
- for (j=0; j<=i; j++) {
- *po+=(*pa++)*(*pi--);
- }
- for (j=i+1; j<LPC_FILTERORDER+1; j++) {
-
- *po+=(*pa++)*(*pm--);
- }
- po++;
- }
-
- /* Filter last part where the state is entierly
- in the input vector */
-
- for (i=LPC_FILTERORDER; i<len; i++) {
- pi = &In[i];
- pa = a;
- *po=0.0;
- for (j=0; j<LPC_FILTERORDER+1; j++) {
- *po+=(*pa++)*(*pi--);
- }
- po++;
- }
-
- /* Update state vector */
-
- memcpy(mem, &In[len-LPC_FILTERORDER],
- LPC_FILTERORDER*sizeof(float));
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/anaFilter.h b/1.2-netsec/codecs/ilbc/anaFilter.h
deleted file mode 100644
index 5b18b7065..000000000
--- a/1.2-netsec/codecs/ilbc/anaFilter.h
+++ /dev/null
@@ -1,26 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- anaFilter.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_ANAFILTER_H
-#define __iLBC_ANAFILTER_H
-
-void anaFilter(
- float *In, /* (i) Signal to be filtered */
- float *a, /* (i) LP parameters */
- int len,/* (i) Length of signal */
- float *Out, /* (o) Filtered signal */
- float *mem /* (i/o) Filter state */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/constants.c b/1.2-netsec/codecs/ilbc/constants.c
deleted file mode 100644
index c466c0f7b..000000000
--- a/1.2-netsec/codecs/ilbc/constants.c
+++ /dev/null
@@ -1,729 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- constants.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include "iLBC_define.h"
-
-/* ULP bit allocation */
-
- /* 20 ms frame */
-
-const iLBC_ULP_Inst_t ULP_20msTbl = {
- /* LSF */
- { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0},
- {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},
- /* Start state location, gain and samples */
- {2,0,0,0,0},
- {1,0,0,0,0},
- {6,0,0,0,0},
- {0,1,2,0,0},
- /* extra CB index and extra CB gain */
- {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
- {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},
- /* CB index and CB gain */
- { {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
- {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},
- {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},
- {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}},
- { {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},
- {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},
- {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},
- {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}
-};
-
- /* 30 ms frame */
-
-const iLBC_ULP_Inst_t ULP_30msTbl = {
- /* LSF */
- { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0},
-
-
- {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}},
- /* Start state location, gain and samples */
- {3,0,0,0,0},
- {1,0,0,0,0},
- {6,0,0,0,0},
- {0,1,2,0,0},
- /* extra CB index and extra CB gain */
- {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
- {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},
- /* CB index and CB gain */
- { {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
- {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},
- {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},
- {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}},
- { {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}},
- {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},
- {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}},
- {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}}
-};
-
-/* HP Filters */
-
-float hpi_zero_coefsTbl[3] = {
- (float)0.92727436, (float)-1.8544941, (float)0.92727436
-};
-float hpi_pole_coefsTbl[3] = {
- (float)1.0, (float)-1.9059465, (float)0.9114024
-};
-float hpo_zero_coefsTbl[3] = {
- (float)0.93980581, (float)-1.8795834, (float)0.93980581
-};
-float hpo_pole_coefsTbl[3] = {
- (float)1.0, (float)-1.9330735, (float)0.93589199
-};
-
-/* LP Filter */
-
-float lpFilt_coefsTbl[FILTERORDER_DS]={
- (float)-0.066650, (float)0.125000, (float)0.316650,
- (float)0.414063, (float)0.316650,
- (float)0.125000, (float)-0.066650
-};
-
-/* State quantization tables */
-
-float state_sq3Tbl[8] = {
- (float)-3.719849, (float)-2.177490, (float)-1.130005,
- (float)-0.309692, (float)0.444214, (float)1.329712,
- (float)2.436279, (float)3.983887
-};
-
-float state_frgqTbl[64] = {
- (float)1.000085, (float)1.071695, (float)1.140395,
- (float)1.206868, (float)1.277188, (float)1.351503,
-
-
- (float)1.429380, (float)1.500727, (float)1.569049,
- (float)1.639599, (float)1.707071, (float)1.781531,
- (float)1.840799, (float)1.901550, (float)1.956695,
- (float)2.006750, (float)2.055474, (float)2.102787,
- (float)2.142819, (float)2.183592, (float)2.217962,
- (float)2.257177, (float)2.295739, (float)2.332967,
- (float)2.369248, (float)2.402792, (float)2.435080,
- (float)2.468598, (float)2.503394, (float)2.539284,
- (float)2.572944, (float)2.605036, (float)2.636331,
- (float)2.668939, (float)2.698780, (float)2.729101,
- (float)2.759786, (float)2.789834, (float)2.818679,
- (float)2.848074, (float)2.877470, (float)2.906899,
- (float)2.936655, (float)2.967804, (float)3.000115,
- (float)3.033367, (float)3.066355, (float)3.104231,
- (float)3.141499, (float)3.183012, (float)3.222952,
- (float)3.265433, (float)3.308441, (float)3.350823,
- (float)3.395275, (float)3.442793, (float)3.490801,
- (float)3.542514, (float)3.604064, (float)3.666050,
- (float)3.740994, (float)3.830749, (float)3.938770,
- (float)4.101764
-};
-
-/* CB tables */
-
-int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44},
- {108,108,108}, {108,108,108}, {108,108,108}};
-int stMemLTbl=85;
-int memLfTbl[NASUB_MAX]={147,147,147,147};
-
-/* expansion filter(s) */
-
-float cbfiltersTbl[CB_FILTERLEN]={
- (float)-0.034180, (float)0.108887, (float)-0.184326,
- (float)0.806152, (float)0.713379, (float)-0.144043,
- (float)0.083740, (float)-0.033691
-};
-
-/* Gain Quantization */
-
-float gain_sq3Tbl[8]={
- (float)-1.000000, (float)-0.659973, (float)-0.330017,
- (float)0.000000, (float)0.250000, (float)0.500000,
- (float)0.750000, (float)1.00000};
-
-float gain_sq4Tbl[16]={
- (float)-1.049988, (float)-0.900024, (float)-0.750000,
- (float)-0.599976, (float)-0.450012, (float)-0.299988,
- (float)-0.150024, (float)0.000000, (float)0.150024,
- (float)0.299988, (float)0.450012, (float)0.599976,
- (float)0.750000, (float)0.900024, (float)1.049988,
- (float)1.200012};
-
-float gain_sq5Tbl[32]={
- (float)0.037476, (float)0.075012, (float)0.112488,
-
-
- (float)0.150024, (float)0.187500, (float)0.224976,
- (float)0.262512, (float)0.299988, (float)0.337524,
- (float)0.375000, (float)0.412476, (float)0.450012,
- (float)0.487488, (float)0.525024, (float)0.562500,
- (float)0.599976, (float)0.637512, (float)0.674988,
- (float)0.712524, (float)0.750000, (float)0.787476,
- (float)0.825012, (float)0.862488, (float)0.900024,
- (float)0.937500, (float)0.974976, (float)1.012512,
- (float)1.049988, (float)1.087524, (float)1.125000,
- (float)1.162476, (float)1.200012};
-
-/* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */
-float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={
- (float)0.000000, (float)0.000000, (float)0.000000,
-(float)1.000000,
- (float)0.000000, (float)0.000000, (float)0.000000,
- (float)0.015625, (float)-0.076904, (float)0.288330,
-(float)0.862061,
- (float)-0.106445, (float)0.018799, (float)-0.015625,
- (float)0.023682, (float)-0.124268, (float)0.601563,
-(float)0.601563,
- (float)-0.124268, (float)0.023682, (float)-0.023682,
- (float)0.018799, (float)-0.106445, (float)0.862061,
-(float)0.288330,
- (float)-0.076904, (float)0.015625, (float)-0.018799};
-
-float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0,
- (float)200.0, (float)280.0, (float)360.0,
- (float)440.0, (float)520.0, (float)600.0};
-
-/* LPC analysis and quantization */
-
-int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4};
-int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};
-
-
-float lsfmeanTbl[LPC_FILTERORDER] = {
- (float)0.281738, (float)0.445801, (float)0.663330,
- (float)0.962524, (float)1.251831, (float)1.533081,
- (float)1.850586, (float)2.137817, (float)2.481445,
- (float)2.777344};
-
-float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0,
-(float)(2.0/3.0),
- (float)(1.0/3.0), (float)0.0, (float)0.0};
-
-float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0),
- (float)(1.0/4.0), (float)(0.0)};
-
-/* Hanning LPC window */
-float lpc_winTbl[BLOCKL_MAX]={
- (float)0.000183, (float)0.000671, (float)0.001526,
- (float)0.002716, (float)0.004242, (float)0.006104,
- (float)0.008301, (float)0.010834, (float)0.013702,
-
-
- (float)0.016907, (float)0.020416, (float)0.024261,
- (float)0.028442, (float)0.032928, (float)0.037750,
- (float)0.042877, (float)0.048309, (float)0.054047,
- (float)0.060089, (float)0.066437, (float)0.073090,
- (float)0.080017, (float)0.087219, (float)0.094727,
- (float)0.102509, (float)0.110535, (float)0.118835,
- (float)0.127411, (float)0.136230, (float)0.145294,
- (float)0.154602, (float)0.164154, (float)0.173920,
- (float)0.183899, (float)0.194122, (float)0.204529,
- (float)0.215149, (float)0.225952, (float)0.236938,
- (float)0.248108, (float)0.259460, (float)0.270966,
- (float)0.282654, (float)0.294464, (float)0.306396,
- (float)0.318481, (float)0.330688, (float)0.343018,
- (float)0.355438, (float)0.367981, (float)0.380585,
- (float)0.393280, (float)0.406067, (float)0.418884,
- (float)0.431763, (float)0.444702, (float)0.457672,
- (float)0.470673, (float)0.483704, (float)0.496735,
- (float)0.509766, (float)0.522797, (float)0.535828,
- (float)0.548798, (float)0.561768, (float)0.574677,
- (float)0.587524, (float)0.600342, (float)0.613068,
- (float)0.625732, (float)0.638306, (float)0.650787,
- (float)0.663147, (float)0.675415, (float)0.687561,
- (float)0.699585, (float)0.711487, (float)0.723206,
- (float)0.734802, (float)0.746216, (float)0.757477,
- (float)0.768585, (float)0.779480, (float)0.790192,
- (float)0.800720, (float)0.811005, (float)0.821106,
- (float)0.830994, (float)0.840668, (float)0.850067,
- (float)0.859253, (float)0.868225, (float)0.876892,
- (float)0.885345, (float)0.893524, (float)0.901428,
- (float)0.909058, (float)0.916412, (float)0.923492,
- (float)0.930267, (float)0.936768, (float)0.942963,
- (float)0.948853, (float)0.954437, (float)0.959717,
- (float)0.964691, (float)0.969360, (float)0.973694,
- (float)0.977692, (float)0.981384, (float)0.984741,
- (float)0.987762, (float)0.990479, (float)0.992828,
- (float)0.994873, (float)0.996552, (float)0.997925,
- (float)0.998932, (float)0.999603, (float)0.999969,
- (float)0.999969, (float)0.999603, (float)0.998932,
- (float)0.997925, (float)0.996552, (float)0.994873,
- (float)0.992828, (float)0.990479, (float)0.987762,
- (float)0.984741, (float)0.981384, (float)0.977692,
- (float)0.973694, (float)0.969360, (float)0.964691,
- (float)0.959717, (float)0.954437, (float)0.948853,
- (float)0.942963, (float)0.936768, (float)0.930267,
- (float)0.923492, (float)0.916412, (float)0.909058,
- (float)0.901428, (float)0.893524, (float)0.885345,
- (float)0.876892, (float)0.868225, (float)0.859253,
- (float)0.850067, (float)0.840668, (float)0.830994,
- (float)0.821106, (float)0.811005, (float)0.800720,
- (float)0.790192, (float)0.779480, (float)0.768585,
- (float)0.757477, (float)0.746216, (float)0.734802,
- (float)0.723206, (float)0.711487, (float)0.699585,
- (float)0.687561, (float)0.675415, (float)0.663147,
- (float)0.650787, (float)0.638306, (float)0.625732,
-
-
- (float)0.613068, (float)0.600342, (float)0.587524,
- (float)0.574677, (float)0.561768, (float)0.548798,
- (float)0.535828, (float)0.522797, (float)0.509766,
- (float)0.496735, (float)0.483704, (float)0.470673,
- (float)0.457672, (float)0.444702, (float)0.431763,
- (float)0.418884, (float)0.406067, (float)0.393280,
- (float)0.380585, (float)0.367981, (float)0.355438,
- (float)0.343018, (float)0.330688, (float)0.318481,
- (float)0.306396, (float)0.294464, (float)0.282654,
- (float)0.270966, (float)0.259460, (float)0.248108,
- (float)0.236938, (float)0.225952, (float)0.215149,
- (float)0.204529, (float)0.194122, (float)0.183899,
- (float)0.173920, (float)0.164154, (float)0.154602,
- (float)0.145294, (float)0.136230, (float)0.127411,
- (float)0.118835, (float)0.110535, (float)0.102509,
- (float)0.094727, (float)0.087219, (float)0.080017,
- (float)0.073090, (float)0.066437, (float)0.060089,
- (float)0.054047, (float)0.048309, (float)0.042877,
- (float)0.037750, (float)0.032928, (float)0.028442,
- (float)0.024261, (float)0.020416, (float)0.016907,
- (float)0.013702, (float)0.010834, (float)0.008301,
- (float)0.006104, (float)0.004242, (float)0.002716,
- (float)0.001526, (float)0.000671, (float)0.000183
-};
-
-/* Asymmetric LPC window */
-float lpc_asymwinTbl[BLOCKL_MAX]={
- (float)0.000061, (float)0.000214, (float)0.000458,
- (float)0.000824, (float)0.001282, (float)0.001831,
- (float)0.002472, (float)0.003235, (float)0.004120,
- (float)0.005066, (float)0.006134, (float)0.007294,
- (float)0.008545, (float)0.009918, (float)0.011383,
- (float)0.012939, (float)0.014587, (float)0.016357,
- (float)0.018219, (float)0.020172, (float)0.022217,
- (float)0.024353, (float)0.026611, (float)0.028961,
- (float)0.031372, (float)0.033905, (float)0.036530,
- (float)0.039276, (float)0.042084, (float)0.044983,
- (float)0.047974, (float)0.051086, (float)0.054260,
- (float)0.057526, (float)0.060883, (float)0.064331,
- (float)0.067871, (float)0.071503, (float)0.075226,
- (float)0.079010, (float)0.082916, (float)0.086884,
- (float)0.090942, (float)0.095062, (float)0.099304,
- (float)0.103607, (float)0.107971, (float)0.112427,
- (float)0.116974, (float)0.121582, (float)0.126282,
- (float)0.131073, (float)0.135895, (float)0.140839,
- (float)0.145813, (float)0.150879, (float)0.156006,
- (float)0.161224, (float)0.166504, (float)0.171844,
- (float)0.177246, (float)0.182709, (float)0.188263,
- (float)0.193848, (float)0.199524, (float)0.205231,
- (float)0.211029, (float)0.216858, (float)0.222778,
- (float)0.228729, (float)0.234741, (float)0.240814,
- (float)0.246918, (float)0.253082, (float)0.259308,
- (float)0.265564, (float)0.271881, (float)0.278259,
- (float)0.284668, (float)0.291107, (float)0.297607,
-
-
- (float)0.304138, (float)0.310730, (float)0.317322,
- (float)0.323975, (float)0.330658, (float)0.337372,
- (float)0.344147, (float)0.350922, (float)0.357727,
- (float)0.364594, (float)0.371460, (float)0.378357,
- (float)0.385284, (float)0.392212, (float)0.399170,
- (float)0.406158, (float)0.413177, (float)0.420197,
- (float)0.427246, (float)0.434296, (float)0.441376,
- (float)0.448456, (float)0.455536, (float)0.462646,
- (float)0.469757, (float)0.476868, (float)0.483978,
- (float)0.491089, (float)0.498230, (float)0.505341,
- (float)0.512451, (float)0.519592, (float)0.526703,
- (float)0.533813, (float)0.540924, (float)0.548004,
- (float)0.555084, (float)0.562164, (float)0.569244,
- (float)0.576294, (float)0.583313, (float)0.590332,
- (float)0.597321, (float)0.604309, (float)0.611267,
- (float)0.618195, (float)0.625092, (float)0.631989,
- (float)0.638855, (float)0.645660, (float)0.652466,
- (float)0.659241, (float)0.665985, (float)0.672668,
- (float)0.679352, (float)0.685974, (float)0.692566,
- (float)0.699127, (float)0.705658, (float)0.712128,
- (float)0.718536, (float)0.724945, (float)0.731262,
- (float)0.737549, (float)0.743805, (float)0.750000,
- (float)0.756134, (float)0.762238, (float)0.768280,
- (float)0.774261, (float)0.780182, (float)0.786072,
- (float)0.791870, (float)0.797638, (float)0.803314,
- (float)0.808960, (float)0.814514, (float)0.820038,
- (float)0.825470, (float)0.830841, (float)0.836151,
- (float)0.841400, (float)0.846558, (float)0.851654,
- (float)0.856689, (float)0.861633, (float)0.866516,
- (float)0.871338, (float)0.876068, (float)0.880737,
- (float)0.885315, (float)0.889801, (float)0.894226,
- (float)0.898560, (float)0.902832, (float)0.907013,
- (float)0.911102, (float)0.915100, (float)0.919037,
- (float)0.922882, (float)0.926636, (float)0.930328,
- (float)0.933899, (float)0.937408, (float)0.940796,
- (float)0.944122, (float)0.947357, (float)0.950470,
- (float)0.953522, (float)0.956482, (float)0.959351,
- (float)0.962097, (float)0.964783, (float)0.967377,
- (float)0.969849, (float)0.972229, (float)0.974518,
- (float)0.976715, (float)0.978821, (float)0.980835,
- (float)0.982727, (float)0.984528, (float)0.986237,
- (float)0.987854, (float)0.989380, (float)0.990784,
- (float)0.992096, (float)0.993317, (float)0.994415,
- (float)0.995422, (float)0.996338, (float)0.997162,
- (float)0.997864, (float)0.998474, (float)0.998962,
- (float)0.999390, (float)0.999695, (float)0.999878,
- (float)0.999969, (float)0.999969, (float)0.996918,
- (float)0.987701, (float)0.972382, (float)0.951050,
- (float)0.923889, (float)0.891022, (float)0.852631,
- (float)0.809021, (float)0.760406, (float)0.707092,
- (float)0.649445, (float)0.587799, (float)0.522491,
- (float)0.453979, (float)0.382690, (float)0.309021,
- (float)0.233459, (float)0.156433, (float)0.078461
-};
-
-
-
-/* Lag window for LPC */
-float lpc_lagwinTbl[LPC_FILTERORDER + 1]={
- (float)1.000100, (float)0.998890, (float)0.995569,
- (float)0.990057, (float)0.982392,
- (float)0.972623, (float)0.960816, (float)0.947047,
- (float)0.931405, (float)0.913989, (float)0.894909};
-
-/* LSF quantization*/
-float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = {
-(float)0.155396, (float)0.273193, (float)0.451172,
-(float)0.390503, (float)0.648071, (float)1.002075,
-(float)0.440186, (float)0.692261, (float)0.955688,
-(float)0.343628, (float)0.642334, (float)1.071533,
-(float)0.318359, (float)0.491577, (float)0.670532,
-(float)0.193115, (float)0.375488, (float)0.725708,
-(float)0.364136, (float)0.510376, (float)0.658691,
-(float)0.297485, (float)0.527588, (float)0.842529,
-(float)0.227173, (float)0.365967, (float)0.563110,
-(float)0.244995, (float)0.396729, (float)0.636475,
-(float)0.169434, (float)0.300171, (float)0.520264,
-(float)0.312866, (float)0.464478, (float)0.643188,
-(float)0.248535, (float)0.429932, (float)0.626099,
-(float)0.236206, (float)0.491333, (float)0.817139,
-(float)0.334961, (float)0.625122, (float)0.895752,
-(float)0.343018, (float)0.518555, (float)0.698608,
-(float)0.372803, (float)0.659790, (float)0.945435,
-(float)0.176880, (float)0.316528, (float)0.581421,
-(float)0.416382, (float)0.625977, (float)0.805176,
-(float)0.303223, (float)0.568726, (float)0.915039,
-(float)0.203613, (float)0.351440, (float)0.588135,
-(float)0.221191, (float)0.375000, (float)0.614746,
-(float)0.199951, (float)0.323364, (float)0.476074,
-(float)0.300781, (float)0.433350, (float)0.566895,
-(float)0.226196, (float)0.354004, (float)0.507568,
-(float)0.300049, (float)0.508179, (float)0.711670,
-(float)0.312012, (float)0.492676, (float)0.763428,
-(float)0.329956, (float)0.541016, (float)0.795776,
-(float)0.373779, (float)0.604614, (float)0.928833,
-(float)0.210571, (float)0.452026, (float)0.755249,
-(float)0.271118, (float)0.473267, (float)0.662476,
-(float)0.285522, (float)0.436890, (float)0.634399,
-(float)0.246704, (float)0.565552, (float)0.859009,
-(float)0.270508, (float)0.406250, (float)0.553589,
-(float)0.361450, (float)0.578491, (float)0.813843,
-(float)0.342651, (float)0.482788, (float)0.622437,
-(float)0.340332, (float)0.549438, (float)0.743164,
-(float)0.200439, (float)0.336304, (float)0.540894,
-(float)0.407837, (float)0.644775, (float)0.895142,
-(float)0.294678, (float)0.454834, (float)0.699097,
-(float)0.193115, (float)0.344482, (float)0.643188,
-(float)0.275757, (float)0.420776, (float)0.598755,
-(float)0.380493, (float)0.608643, (float)0.861084,
-(float)0.222778, (float)0.426147, (float)0.676514,
-
-
-(float)0.407471, (float)0.700195, (float)1.053101,
-(float)0.218384, (float)0.377197, (float)0.669922,
-(float)0.313232, (float)0.454102, (float)0.600952,
-(float)0.347412, (float)0.571533, (float)0.874146,
-(float)0.238037, (float)0.405396, (float)0.729492,
-(float)0.223877, (float)0.412964, (float)0.822021,
-(float)0.395264, (float)0.582153, (float)0.743896,
-(float)0.247925, (float)0.485596, (float)0.720581,
-(float)0.229126, (float)0.496582, (float)0.907715,
-(float)0.260132, (float)0.566895, (float)1.012695,
-(float)0.337402, (float)0.611572, (float)0.978149,
-(float)0.267822, (float)0.447632, (float)0.769287,
-(float)0.250610, (float)0.381714, (float)0.530029,
-(float)0.430054, (float)0.805054, (float)1.221924,
-(float)0.382568, (float)0.544067, (float)0.701660,
-(float)0.383545, (float)0.710327, (float)1.149170,
-(float)0.271362, (float)0.529053, (float)0.775513,
-(float)0.246826, (float)0.393555, (float)0.588623,
-(float)0.266846, (float)0.422119, (float)0.676758,
-(float)0.311523, (float)0.580688, (float)0.838623,
-(float)1.331177, (float)1.576782, (float)1.779541,
-(float)1.160034, (float)1.401978, (float)1.768188,
-(float)1.161865, (float)1.525146, (float)1.715332,
-(float)0.759521, (float)0.913940, (float)1.119873,
-(float)0.947144, (float)1.121338, (float)1.282471,
-(float)1.015015, (float)1.557007, (float)1.804932,
-(float)1.172974, (float)1.402100, (float)1.692627,
-(float)1.087524, (float)1.474243, (float)1.665405,
-(float)0.899536, (float)1.105225, (float)1.406250,
-(float)1.148438, (float)1.484741, (float)1.796265,
-(float)0.785645, (float)1.209839, (float)1.567749,
-(float)0.867798, (float)1.166504, (float)1.450684,
-(float)0.922485, (float)1.229858, (float)1.420898,
-(float)0.791260, (float)1.123291, (float)1.409546,
-(float)0.788940, (float)0.966064, (float)1.340332,
-(float)1.051147, (float)1.272827, (float)1.556641,
-(float)0.866821, (float)1.181152, (float)1.538818,
-(float)0.906738, (float)1.373535, (float)1.607910,
-(float)1.244751, (float)1.581421, (float)1.933838,
-(float)0.913940, (float)1.337280, (float)1.539673,
-(float)0.680542, (float)0.959229, (float)1.662720,
-(float)0.887207, (float)1.430542, (float)1.800781,
-(float)0.912598, (float)1.433594, (float)1.683960,
-(float)0.860474, (float)1.060303, (float)1.455322,
-(float)1.005127, (float)1.381104, (float)1.706909,
-(float)0.800781, (float)1.363892, (float)1.829102,
-(float)0.781860, (float)1.124390, (float)1.505981,
-(float)1.003662, (float)1.471436, (float)1.684692,
-(float)0.981323, (float)1.309570, (float)1.618042,
-(float)1.228760, (float)1.554321, (float)1.756470,
-(float)0.734375, (float)0.895752, (float)1.225586,
-(float)0.841797, (float)1.055664, (float)1.249268,
-(float)0.920166, (float)1.119385, (float)1.486206,
-(float)0.894409, (float)1.539063, (float)1.828979,
-
-
-(float)1.283691, (float)1.543335, (float)1.858276,
-(float)0.676025, (float)0.933105, (float)1.490845,
-(float)0.821289, (float)1.491821, (float)1.739868,
-(float)0.923218, (float)1.144653, (float)1.580566,
-(float)1.057251, (float)1.345581, (float)1.635864,
-(float)0.888672, (float)1.074951, (float)1.353149,
-(float)0.942749, (float)1.195435, (float)1.505493,
-(float)1.492310, (float)1.788086, (float)2.039673,
-(float)1.070313, (float)1.634399, (float)1.860962,
-(float)1.253296, (float)1.488892, (float)1.686035,
-(float)0.647095, (float)0.864014, (float)1.401855,
-(float)0.866699, (float)1.254883, (float)1.453369,
-(float)1.063965, (float)1.532593, (float)1.731323,
-(float)1.167847, (float)1.521484, (float)1.884033,
-(float)0.956055, (float)1.502075, (float)1.745605,
-(float)0.928711, (float)1.288574, (float)1.479614,
-(float)1.088013, (float)1.380737, (float)1.570801,
-(float)0.905029, (float)1.186768, (float)1.371948,
-(float)1.057861, (float)1.421021, (float)1.617432,
-(float)1.108276, (float)1.312500, (float)1.501465,
-(float)0.979492, (float)1.416992, (float)1.624268,
-(float)1.276001, (float)1.661011, (float)2.007935,
-(float)0.993042, (float)1.168579, (float)1.331665,
-(float)0.778198, (float)0.944946, (float)1.235962,
-(float)1.223755, (float)1.491333, (float)1.815674,
-(float)0.852661, (float)1.350464, (float)1.722290,
-(float)1.134766, (float)1.593140, (float)1.787354,
-(float)1.051392, (float)1.339722, (float)1.531006,
-(float)0.803589, (float)1.271240, (float)1.652100,
-(float)0.755737, (float)1.143555, (float)1.639404,
-(float)0.700928, (float)0.837280, (float)1.130371,
-(float)0.942749, (float)1.197876, (float)1.669800,
-(float)0.993286, (float)1.378296, (float)1.566528,
-(float)0.801025, (float)1.095337, (float)1.298950,
-(float)0.739990, (float)1.032959, (float)1.383667,
-(float)0.845703, (float)1.072266, (float)1.543823,
-(float)0.915649, (float)1.072266, (float)1.224487,
-(float)1.021973, (float)1.226196, (float)1.481323,
-(float)0.999878, (float)1.204102, (float)1.555908,
-(float)0.722290, (float)0.913940, (float)1.340210,
-(float)0.673340, (float)0.835938, (float)1.259521,
-(float)0.832397, (float)1.208374, (float)1.394165,
-(float)0.962158, (float)1.576172, (float)1.912842,
-(float)1.166748, (float)1.370850, (float)1.556763,
-(float)0.946289, (float)1.138550, (float)1.400391,
-(float)1.035034, (float)1.218262, (float)1.386475,
-(float)1.393799, (float)1.717773, (float)2.000244,
-(float)0.972656, (float)1.260986, (float)1.760620,
-(float)1.028198, (float)1.288452, (float)1.484619,
-(float)0.773560, (float)1.258057, (float)1.756714,
-(float)1.080322, (float)1.328003, (float)1.742676,
-(float)0.823975, (float)1.450806, (float)1.917725,
-(float)0.859009, (float)1.016602, (float)1.191895,
-(float)0.843994, (float)1.131104, (float)1.645020,
-
-
-(float)1.189697, (float)1.702759, (float)1.894409,
-(float)1.346680, (float)1.763184, (float)2.066040,
-(float)0.980469, (float)1.253784, (float)1.441650,
-(float)1.338135, (float)1.641968, (float)1.932739,
-(float)1.223267, (float)1.424194, (float)1.626465,
-(float)0.765747, (float)1.004150, (float)1.579102,
-(float)1.042847, (float)1.269165, (float)1.647461,
-(float)0.968750, (float)1.257568, (float)1.555786,
-(float)0.826294, (float)0.993408, (float)1.275146,
-(float)0.742310, (float)0.950439, (float)1.430542,
-(float)1.054321, (float)1.439819, (float)1.828003,
-(float)1.072998, (float)1.261719, (float)1.441895,
-(float)0.859375, (float)1.036377, (float)1.314819,
-(float)0.895752, (float)1.267212, (float)1.605591,
-(float)0.805420, (float)0.962891, (float)1.142334,
-(float)0.795654, (float)1.005493, (float)1.468506,
-(float)1.105347, (float)1.313843, (float)1.584839,
-(float)0.792236, (float)1.221802, (float)1.465698,
-(float)1.170532, (float)1.467651, (float)1.664063,
-(float)0.838257, (float)1.153198, (float)1.342163,
-(float)0.968018, (float)1.198242, (float)1.391235,
-(float)1.250122, (float)1.623535, (float)1.823608,
-(float)0.711670, (float)1.058350, (float)1.512085,
-(float)1.204834, (float)1.454468, (float)1.739136,
-(float)1.137451, (float)1.421753, (float)1.620117,
-(float)0.820435, (float)1.322754, (float)1.578247,
-(float)0.798706, (float)1.005005, (float)1.213867,
-(float)0.980713, (float)1.324951, (float)1.512939,
-(float)1.112305, (float)1.438843, (float)1.735596,
-(float)1.135498, (float)1.356689, (float)1.635742,
-(float)1.101318, (float)1.387451, (float)1.686523,
-(float)0.849854, (float)1.276978, (float)1.523438,
-(float)1.377930, (float)1.627563, (float)1.858154,
-(float)0.884888, (float)1.095459, (float)1.287476,
-(float)1.289795, (float)1.505859, (float)1.756592,
-(float)0.817505, (float)1.384155, (float)1.650513,
-(float)1.446655, (float)1.702148, (float)1.931885,
-(float)0.835815, (float)1.023071, (float)1.385376,
-(float)0.916626, (float)1.139038, (float)1.335327,
-(float)0.980103, (float)1.174072, (float)1.453735,
-(float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408,
-(float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904,
-(float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477,
-(float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083,
-(float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196,
-(float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396,
-(float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854,
-(float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408,
-(float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987,
-(float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666,
-(float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434,
-(float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781,
-(float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416,
-(float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288,
-
-
-(float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672,
-(float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890,
-(float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508,
-(float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206,
-(float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086,
-(float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223,
-(float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101,
-(float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703,
-(float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094,
-(float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450,
-(float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704,
-(float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653,
-(float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723,
-(float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634,
-(float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494,
-(float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370,
-(float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542,
-(float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091,
-(float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346,
-(float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219,
-(float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810,
-(float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914,
-(float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198,
-(float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104,
-(float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892,
-(float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852,
-(float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199,
-(float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286,
-(float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127,
-(float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748,
-(float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676,
-(float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910,
-(float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555,
-(float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023,
-(float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851,
-(float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014,
-(float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307,
-(float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637,
-(float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643,
-(float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968,
-(float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562,
-(float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646,
-(float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818,
-(float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466,
-(float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945,
-(float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941,
-(float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618,
-(float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922,
-(float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794,
-(float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570,
-(float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595,
-(float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673,
-(float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925,
-(float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984,
-
-
-(float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904,
-(float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256,
-(float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279,
-(float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602,
-(float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331,
-(float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999,
-(float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096,
-(float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234,
-(float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771,
-(float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076,
-(float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058,
-(float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623,
-(float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284,
-(float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021,
-(float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693,
-(float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760,
-(float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676,
-(float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834,
-(float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058,
-(float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929,
-(float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892,
-(float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417,
-(float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149,
-(float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666,
-(float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521,
-(float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646,
-(float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247,
-(float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583,
-(float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876,
-(float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465,
-(float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253,
-(float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234,
-(float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402,
-(float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406,
-(float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807,
-(float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414,
-(float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991,
-(float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290,
-(float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414,
-(float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647,
-(float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145,
-(float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520,
-(float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117,
-(float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576,
-(float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705,
-(float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007,
-(float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964,
-(float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073,
-(float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873,
-(float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558,
-(float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791,
-(float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857,
-(float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050,
-(float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127,
-
-
-(float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545,
-(float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259,
-(float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993,
-(float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912,
-(float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757,
-(float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143
-};
-
-
diff --git a/1.2-netsec/codecs/ilbc/constants.h b/1.2-netsec/codecs/ilbc/constants.h
deleted file mode 100644
index e27754d8f..000000000
--- a/1.2-netsec/codecs/ilbc/constants.h
+++ /dev/null
@@ -1,74 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- constants.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-
-
-******************************************************************/
-
-#ifndef __iLBC_CONSTANTS_H
-#define __iLBC_CONSTANTS_H
-
-#include "iLBC_define.h"
-
-
-/* ULP bit allocation */
-
-extern const iLBC_ULP_Inst_t ULP_20msTbl;
-extern const iLBC_ULP_Inst_t ULP_30msTbl;
-
-/* high pass filters */
-
-extern float hpi_zero_coefsTbl[];
-extern float hpi_pole_coefsTbl[];
-extern float hpo_zero_coefsTbl[];
-extern float hpo_pole_coefsTbl[];
-
-/* low pass filters */
-extern float lpFilt_coefsTbl[];
-
-/* LPC analysis and quantization */
-
-extern float lpc_winTbl[];
-extern float lpc_asymwinTbl[];
-extern float lpc_lagwinTbl[];
-extern float lsfCbTbl[];
-extern float lsfmeanTbl[];
-extern int dim_lsfCbTbl[];
-extern int size_lsfCbTbl[];
-extern float lsf_weightTbl_30ms[];
-extern float lsf_weightTbl_20ms[];
-
-/* state quantization tables */
-
-extern float state_sq3Tbl[];
-extern float state_frgqTbl[];
-
-/* gain quantization tables */
-
-extern float gain_sq3Tbl[];
-extern float gain_sq4Tbl[];
-extern float gain_sq5Tbl[];
-
-/* adaptive codebook definitions */
-
-extern int search_rangeTbl[5][CB_NSTAGES];
-extern int memLfTbl[];
-extern int stMemLTbl;
-extern float cbfiltersTbl[CB_FILTERLEN];
-
-
-
-/* enhancer definitions */
-
-extern float polyphaserTbl[];
-extern float enh_plocsTbl[];
-
-#endif
-
diff --git a/1.2-netsec/codecs/ilbc/createCB.c b/1.2-netsec/codecs/ilbc/createCB.c
deleted file mode 100644
index a7efd9380..000000000
--- a/1.2-netsec/codecs/ilbc/createCB.c
+++ /dev/null
@@ -1,216 +0,0 @@
-
-
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- createCB.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include "iLBC_define.h"
-#include "createCB.h"
-#include "constants.h"
-#include <string.h>
-#include <math.h>
-
-/*----------------------------------------------------------------*
- * Construct an additional codebook vector by filtering the
- * initial codebook buffer. This vector is then used to expand
- * the codebook with an additional section.
- *---------------------------------------------------------------*/
-
-void filteredCBvecs(
- float *cbvectors, /* (o) Codebook vectors for the
- higher section */
- float *mem, /* (i) Buffer to create codebook
- vector from */
- int lMem /* (i) Length of buffer */
-){
- int j, k;
- float *pp, *pp1;
- float tempbuff2[CB_MEML+CB_FILTERLEN];
- float *pos;
-
- memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float));
- memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float));
- memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0,
- (CB_HALFFILTERLEN+1)*sizeof(float));
-
- /* Create codebook vector for higher section by filtering */
-
- /* do filtering */
- pos=cbvectors;
- memset(pos, 0, lMem*sizeof(float));
- for (k=0; k<lMem; k++) {
- pp=&tempbuff2[k];
- pp1=&cbfiltersTbl[CB_FILTERLEN-1];
- for (j=0;j<CB_FILTERLEN;j++) {
- (*pos)+=(*pp++)*(*pp1--);
- }
- pos++;
- }
-}
-
-
-
-/*----------------------------------------------------------------*
- * Search the augmented part of the codebook to find the best
- * measure.
- *----------------------------------------------------------------*/
-
-void searchAugmentedCB(
- int low, /* (i) Start index for the search */
- int high, /* (i) End index for the search */
- int stage, /* (i) Current stage */
- int startIndex, /* (i) Codebook index for the first
- aug vector */
- float *target, /* (i) Target vector for encoding */
- float *buffer, /* (i) Pointer to the end of the buffer for
- augmented codebook construction */
- float *max_measure, /* (i/o) Currently maximum measure */
- int *best_index,/* (o) Currently the best index */
- float *gain, /* (o) Currently the best gain */
- float *energy, /* (o) Energy of augmented codebook
- vectors */
- float *invenergy/* (o) Inv energy of augmented codebook
- vectors */
-) {
- int icount, ilow, j, tmpIndex;
- float *pp, *ppo, *ppi, *ppe, crossDot, alfa;
- float weighted, measure, nrjRecursive;
- float ftmp;
-
- /* Compute the energy for the first (low-5)
- noninterpolated samples */
- nrjRecursive = (float) 0.0;
- pp = buffer - low + 1;
- for (j=0; j<(low-5); j++) {
- nrjRecursive += ( (*pp)*(*pp) );
- pp++;
- }
- ppe = buffer - low;
-
-
- for (icount=low; icount<=high; icount++) {
-
- /* Index of the codebook vector used for retrieving
- energy values */
- tmpIndex = startIndex+icount-20;
-
- ilow = icount-4;
-
- /* Update the energy recursively to save complexity */
- nrjRecursive = nrjRecursive + (*ppe)*(*ppe);
- ppe--;
- energy[tmpIndex] = nrjRecursive;
-
- /* Compute cross dot product for the first (low-5)
- samples */
- crossDot = (float) 0.0;
-
-
- pp = buffer-icount;
- for (j=0; j<ilow; j++) {
- crossDot += target[j]*(*pp++);
- }
-
- /* interpolation */
- alfa = (float) 0.2;
- ppo = buffer-4;
- ppi = buffer-icount-4;
- for (j=ilow; j<icount; j++) {
- weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);
- ppo++;
- ppi++;
- energy[tmpIndex] += weighted*weighted;
- crossDot += target[j]*weighted;
- alfa += (float)0.2;
- }
-
- /* Compute energy and cross dot product for the
- remaining samples */
- pp = buffer - icount;
- for (j=icount; j<SUBL; j++) {
- energy[tmpIndex] += (*pp)*(*pp);
- crossDot += target[j]*(*pp++);
- }
-
- if (energy[tmpIndex]>0.0) {
- invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS);
- } else {
- invenergy[tmpIndex] = (float) 0.0;
- }
-
- if (stage==0) {
- measure = (float)-10000000.0;
-
- if (crossDot > 0.0) {
- measure = crossDot*crossDot*invenergy[tmpIndex];
- }
- }
- else {
- measure = crossDot*crossDot*invenergy[tmpIndex];
- }
-
- /* check if measure is better */
- ftmp = crossDot*invenergy[tmpIndex];
-
- if ((measure>*max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
- *best_index = tmpIndex;
- *max_measure = measure;
- *gain = ftmp;
- }
- }
-}
-
-
-
-
-/*----------------------------------------------------------------*
- * Recreate a specific codebook vector from the augmented part.
- *
- *----------------------------------------------------------------*/
-
-void createAugmentedVec(
- int index, /* (i) Index for the augmented vector
- to be created */
- float *buffer, /* (i) Pointer to the end of the buffer for
- augmented codebook construction */
- float *cbVec/* (o) The construced codebook vector */
-) {
- int ilow, j;
- float *pp, *ppo, *ppi, alfa, alfa1, weighted;
-
- ilow = index-5;
-
- /* copy the first noninterpolated part */
-
- pp = buffer-index;
- memcpy(cbVec,pp,sizeof(float)*index);
-
- /* interpolation */
-
- alfa1 = (float)0.2;
- alfa = 0.0;
- ppo = buffer-5;
- ppi = buffer-index-5;
- for (j=ilow; j<index; j++) {
- weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);
- ppo++;
- ppi++;
- cbVec[j] = weighted;
- alfa += alfa1;
- }
-
- /* copy the second noninterpolated part */
-
- pp = buffer - index;
- memcpy(cbVec+index,pp,sizeof(float)*(SUBL-index));
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/createCB.h b/1.2-netsec/codecs/ilbc/createCB.h
deleted file mode 100644
index 10150ee07..000000000
--- a/1.2-netsec/codecs/ilbc/createCB.h
+++ /dev/null
@@ -1,56 +0,0 @@
-
-/******************************************************************
-
-
-
- iLBC Speech Coder ANSI-C Source Code
-
- createCB.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_CREATECB_H
-#define __iLBC_CREATECB_H
-
-void filteredCBvecs(
- float *cbvectors, /* (o) Codebook vector for the
- higher section */
- float *mem, /* (i) Buffer to create codebook
- vectors from */
- int lMem /* (i) Length of buffer */
-);
-
-void searchAugmentedCB(
- int low, /* (i) Start index for the search */
- int high, /* (i) End index for the search */
- int stage, /* (i) Current stage */
- int startIndex, /* (i) CB index for the first
- augmented vector */
- float *target, /* (i) Target vector for encoding */
- float *buffer, /* (i) Pointer to the end of the
- buffer for augmented codebook
- construction */
- float *max_measure, /* (i/o) Currently maximum measure */
- int *best_index,/* (o) Currently the best index */
- float *gain, /* (o) Currently the best gain */
- float *energy, /* (o) Energy of augmented
- codebook vectors */
- float *invenergy/* (o) Inv energy of aug codebook
- vectors */
-);
-
-void createAugmentedVec(
- int index, /* (i) Index for the aug vector
- to be created */
- float *buffer, /* (i) Pointer to the end of the
- buffer for augmented codebook
- construction */
- float *cbVec /* (o) The construced codebook vector */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/doCPLC.c b/1.2-netsec/codecs/ilbc/doCPLC.c
deleted file mode 100644
index bb4b56c10..000000000
--- a/1.2-netsec/codecs/ilbc/doCPLC.c
+++ /dev/null
@@ -1,259 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- doCPLC.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "iLBC_define.h"
-#include "doCPLC.h"
-
-/*----------------------------------------------------------------*
- * Compute cross correlation and pitch gain for pitch prediction
- * of last subframe at given lag.
- *---------------------------------------------------------------*/
-
-static void compCorr(
- float *cc, /* (o) cross correlation coefficient */
- float *gc, /* (o) gain */
- float *pm,
- float *buffer, /* (i) signal buffer */
- int lag, /* (i) pitch lag */
- int bLen, /* (i) length of buffer */
- int sRange /* (i) correlation search length */
-){
-
-
- int i;
- float ftmp1, ftmp2, ftmp3;
-
- /* Guard against getting outside buffer */
- if ((bLen-sRange-lag)<0) {
- sRange=bLen-lag;
- }
-
- ftmp1 = 0.0;
- ftmp2 = 0.0;
- ftmp3 = 0.0;
- for (i=0; i<sRange; i++) {
- ftmp1 += buffer[bLen-sRange+i] *
- buffer[bLen-sRange+i-lag];
- ftmp2 += buffer[bLen-sRange+i-lag] *
- buffer[bLen-sRange+i-lag];
- ftmp3 += buffer[bLen-sRange+i] *
- buffer[bLen-sRange+i];
- }
-
- if (ftmp2 > 0.0) {
- *cc = ftmp1*ftmp1/ftmp2;
- *gc = (float)fabs(ftmp1/ftmp2);
- *pm=(float)fabs(ftmp1)/
- ((float)sqrt(ftmp2)*(float)sqrt(ftmp3));
- }
- else {
- *cc = 0.0;
- *gc = 0.0;
- *pm=0.0;
- }
-}
-
-/*----------------------------------------------------------------*
- * Packet loss concealment routine. Conceals a residual signal
- * and LP parameters. If no packet loss, update state.
- *---------------------------------------------------------------*/
-
-void doThePLC(
- float *PLCresidual, /* (o) concealed residual */
- float *PLClpc, /* (o) concealed LP parameters */
- int PLI, /* (i) packet loss indicator
- 0 - no PL, 1 = PL */
- float *decresidual, /* (i) decoded residual */
- float *lpc, /* (i) decoded LPC (only used for no PL) */
- int inlag, /* (i) pitch lag */
- iLBC_Dec_Inst_t *iLBCdec_inst
- /* (i/o) decoder instance */
-){
- int lag=20, randlag;
- float gain, maxcc;
- float use_gain;
- float gain_comp, maxcc_comp, per, max_per;
- int i, pick, use_lag;
-
-
- float ftmp, randvec[BLOCKL_MAX], pitchfact, energy;
-
- /* Packet Loss */
-
- if (PLI == 1) {
-
- iLBCdec_inst->consPLICount += 1;
-
- /* if previous frame not lost,
- determine pitch pred. gain */
-
- if (iLBCdec_inst->prevPLI != 1) {
-
- /* Search around the previous lag to find the
- best pitch period */
-
- lag=inlag-3;
- compCorr(&maxcc, &gain, &max_per,
- iLBCdec_inst->prevResidual,
- lag, iLBCdec_inst->blockl, 60);
- for (i=inlag-2;i<=inlag+3;i++) {
- compCorr(&maxcc_comp, &gain_comp, &per,
- iLBCdec_inst->prevResidual,
- i, iLBCdec_inst->blockl, 60);
-
- if (maxcc_comp>maxcc) {
- maxcc=maxcc_comp;
- gain=gain_comp;
- lag=i;
- max_per=per;
- }
- }
-
- }
-
- /* previous frame lost, use recorded lag and periodicity */
-
- else {
- lag=iLBCdec_inst->prevLag;
- max_per=iLBCdec_inst->per;
- }
-
- /* downscaling */
-
- use_gain=1.0;
- if (iLBCdec_inst->consPLICount*iLBCdec_inst->blockl>320)
- use_gain=(float)0.9;
- else if (iLBCdec_inst->consPLICount*
- iLBCdec_inst->blockl>2*320)
- use_gain=(float)0.7;
- else if (iLBCdec_inst->consPLICount*
- iLBCdec_inst->blockl>3*320)
- use_gain=(float)0.5;
- else if (iLBCdec_inst->consPLICount*
-
-
- iLBCdec_inst->blockl>4*320)
- use_gain=(float)0.0;
-
- /* mix noise and pitch repeatition */
- ftmp=(float)sqrt(max_per);
- if (ftmp>(float)0.7)
- pitchfact=(float)1.0;
- else if (ftmp>(float)0.4)
- pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4);
- else
- pitchfact=0.0;
-
-
- /* avoid repetition of same pitch cycle */
- use_lag=lag;
- if (lag<80) {
- use_lag=2*lag;
- }
-
- /* compute concealed residual */
-
- energy = 0.0;
- for (i=0; i<iLBCdec_inst->blockl; i++) {
-
- /* noise component */
-
- iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) &
- (0x80000000L-1);
- randlag = 50 + ((signed long) iLBCdec_inst->seed)%70;
- pick = i - randlag;
-
- if (pick < 0) {
- randvec[i] =
- iLBCdec_inst->prevResidual[
- iLBCdec_inst->blockl+pick];
- } else {
- randvec[i] = randvec[pick];
- }
-
- /* pitch repeatition component */
- pick = i - use_lag;
-
- if (pick < 0) {
- PLCresidual[i] =
- iLBCdec_inst->prevResidual[
- iLBCdec_inst->blockl+pick];
- } else {
- PLCresidual[i] = PLCresidual[pick];
- }
-
- /* mix random and periodicity component */
-
- if (i<80)
- PLCresidual[i] = use_gain*(pitchfact *
-
-
- PLCresidual[i] +
- ((float)1.0 - pitchfact) * randvec[i]);
- else if (i<160)
- PLCresidual[i] = (float)0.95*use_gain*(pitchfact *
- PLCresidual[i] +
- ((float)1.0 - pitchfact) * randvec[i]);
- else
- PLCresidual[i] = (float)0.9*use_gain*(pitchfact *
- PLCresidual[i] +
- ((float)1.0 - pitchfact) * randvec[i]);
-
- energy += PLCresidual[i] * PLCresidual[i];
- }
-
- /* less than 30 dB, use only noise */
-
- if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) {
- gain=0.0;
- for (i=0; i<iLBCdec_inst->blockl; i++) {
- PLCresidual[i] = randvec[i];
- }
- }
-
- /* use old LPC */
-
- memcpy(PLClpc,iLBCdec_inst->prevLpc,
- (LPC_FILTERORDER+1)*sizeof(float));
-
- }
-
- /* no packet loss, copy input */
-
- else {
- memcpy(PLCresidual, decresidual,
- iLBCdec_inst->blockl*sizeof(float));
- memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float));
- iLBCdec_inst->consPLICount = 0;
- }
-
- /* update state */
-
- if (PLI) {
- iLBCdec_inst->prevLag = lag;
- iLBCdec_inst->per=max_per;
- }
-
- iLBCdec_inst->prevPLI = PLI;
- memcpy(iLBCdec_inst->prevLpc, PLClpc,
- (LPC_FILTERORDER+1)*sizeof(float));
- memcpy(iLBCdec_inst->prevResidual, PLCresidual,
- iLBCdec_inst->blockl*sizeof(float));
-}
-
-
-
-
diff --git a/1.2-netsec/codecs/ilbc/doCPLC.h b/1.2-netsec/codecs/ilbc/doCPLC.h
deleted file mode 100644
index a619f0def..000000000
--- a/1.2-netsec/codecs/ilbc/doCPLC.h
+++ /dev/null
@@ -1,32 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- doCPLC.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-
-
-******************************************************************/
-
-#ifndef __iLBC_DOLPC_H
-#define __iLBC_DOLPC_H
-
-void doThePLC(
- float *PLCresidual, /* (o) concealed residual */
- float *PLClpc, /* (o) concealed LP parameters */
- int PLI, /* (i) packet loss indicator
- 0 - no PL, 1 = PL */
- float *decresidual, /* (i) decoded residual */
- float *lpc, /* (i) decoded LPC (only used for no PL) */
- int inlag, /* (i) pitch lag */
- iLBC_Dec_Inst_t *iLBCdec_inst
- /* (i/o) decoder instance */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/enhancer.c b/1.2-netsec/codecs/ilbc/enhancer.c
deleted file mode 100644
index 7c7829802..000000000
--- a/1.2-netsec/codecs/ilbc/enhancer.c
+++ /dev/null
@@ -1,665 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- enhancer.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-#include <string.h>
-#include "iLBC_define.h"
-#include "enhancer.h"
-#include "constants.h"
-#include "filter.h"
-
-/*----------------------------------------------------------------*
-
-
- * Find index in array such that the array element with said
- * index is the element of said array closest to "value"
- * according to the squared-error criterion
- *---------------------------------------------------------------*/
-
-static void NearestNeighbor(
- int *index, /* (o) index of array element closest
- to value */
- float *array, /* (i) data array */
- float value,/* (i) value */
- int arlength/* (i) dimension of data array */
-){
- int i;
- float bestcrit,crit;
-
- crit=array[0]-value;
- bestcrit=crit*crit;
- *index=0;
- for (i=1; i<arlength; i++) {
- crit=array[i]-value;
- crit=crit*crit;
-
- if (crit<bestcrit) {
- bestcrit=crit;
- *index=i;
- }
- }
-}
-
-/*----------------------------------------------------------------*
- * compute cross correlation between sequences
- *---------------------------------------------------------------*/
-
-static void mycorr1(
- float* corr, /* (o) correlation of seq1 and seq2 */
- float* seq1, /* (i) first sequence */
- int dim1, /* (i) dimension first seq1 */
- const float *seq2, /* (i) second sequence */
- int dim2 /* (i) dimension seq2 */
-){
- int i,j;
-
- for (i=0; i<=dim1-dim2; i++) {
- corr[i]=0.0;
- for (j=0; j<dim2; j++) {
- corr[i] += seq1[i+j] * seq2[j];
- }
- }
-}
-
-/*----------------------------------------------------------------*
- * upsample finite array assuming zeros outside bounds
- *---------------------------------------------------------------*/
-
-
-
-static void enh_upsample(
- float* useq1, /* (o) upsampled output sequence */
- float* seq1,/* (i) unupsampled sequence */
- int dim1, /* (i) dimension seq1 */
- int hfl /* (i) polyphase filter length=2*hfl+1 */
-){
- float *pu,*ps;
- int i,j,k,q,filterlength,hfl2;
- const float *polyp[ENH_UPS0]; /* pointers to
- polyphase columns */
- const float *pp;
-
- /* define pointers for filter */
-
- filterlength=2*hfl+1;
-
- if ( filterlength > dim1 ) {
- hfl2=(int) (dim1/2);
- for (j=0; j<ENH_UPS0; j++) {
- polyp[j]=polyphaserTbl+j*filterlength+hfl-hfl2;
- }
- hfl=hfl2;
- filterlength=2*hfl+1;
- }
- else {
- for (j=0; j<ENH_UPS0; j++) {
- polyp[j]=polyphaserTbl+j*filterlength;
- }
- }
-
- /* filtering: filter overhangs left side of sequence */
-
- pu=useq1;
- for (i=hfl; i<filterlength; i++) {
- for (j=0; j<ENH_UPS0; j++) {
- *pu=0.0;
- pp = polyp[j];
- ps = seq1+i;
- for (k=0; k<=i; k++) {
- *pu += *ps-- * *pp++;
- }
- pu++;
- }
- }
-
- /* filtering: simple convolution=inner products */
-
- for (i=filterlength; i<dim1; i++) {
- for (j=0;j<ENH_UPS0; j++){
- *pu=0.0;
- pp = polyp[j];
- ps = seq1+i;
- for (k=0; k<filterlength; k++) {
- *pu += *ps-- * *pp++;
-
-
- }
- pu++;
- }
- }
-
- /* filtering: filter overhangs right side of sequence */
-
- for (q=1; q<=hfl; q++) {
- for (j=0; j<ENH_UPS0; j++) {
- *pu=0.0;
- pp = polyp[j]+q;
- ps = seq1+dim1-1;
- for (k=0; k<filterlength-q; k++) {
- *pu += *ps-- * *pp++;
- }
- pu++;
- }
- }
-}
-
-
-/*----------------------------------------------------------------*
- * find segment starting near idata+estSegPos that has highest
- * correlation with idata+centerStartPos through
- * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a
- * resolution of ENH_UPSO times the original of the original
- * sampling rate
- *---------------------------------------------------------------*/
-
-static void refiner(
- float *seg, /* (o) segment array */
- float *updStartPos, /* (o) updated start point */
- float* idata, /* (i) original data buffer */
- int idatal, /* (i) dimension of idata */
- int centerStartPos, /* (i) beginning center segment */
- float estSegPos,/* (i) estimated beginning other segment */
- float period /* (i) estimated pitch period */
-){
- int estSegPosRounded,searchSegStartPos,searchSegEndPos,corrdim;
- int tloc,tloc2,i,st,en,fraction;
- float vect[ENH_VECTL],corrVec[ENH_CORRDIM],maxv;
- float corrVecUps[ENH_CORRDIM*ENH_UPS0];
-
- /* defining array bounds */
-
- estSegPosRounded=(int)(estSegPos - 0.5);
-
- searchSegStartPos=estSegPosRounded-ENH_SLOP;
-
- if (searchSegStartPos<0) {
- searchSegStartPos=0;
- }
- searchSegEndPos=estSegPosRounded+ENH_SLOP;
-
-
-
- if (searchSegEndPos+ENH_BLOCKL >= idatal) {
- searchSegEndPos=idatal-ENH_BLOCKL-1;
- }
- corrdim=searchSegEndPos-searchSegStartPos+1;
-
- /* compute upsampled correlation (corr33) and find
- location of max */
-
- mycorr1(corrVec,idata+searchSegStartPos,
- corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL);
- enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0);
- tloc=0; maxv=corrVecUps[0];
- for (i=1; i<ENH_UPS0*corrdim; i++) {
-
- if (corrVecUps[i]>maxv) {
- tloc=i;
- maxv=corrVecUps[i];
- }
- }
-
- /* make vector can be upsampled without ever running outside
- bounds */
-
- *updStartPos= (float)searchSegStartPos +
- (float)tloc/(float)ENH_UPS0+(float)1.0;
- tloc2=(int)(tloc/ENH_UPS0);
-
- if (tloc>tloc2*ENH_UPS0) {
- tloc2++;
- }
- st=searchSegStartPos+tloc2-ENH_FL0;
-
- if (st<0) {
- memset(vect,0,-st*sizeof(float));
- memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float));
- }
- else {
- en=st+ENH_VECTL;
-
- if (en>idatal) {
- memcpy(vect, &idata[st],
- (ENH_VECTL-(en-idatal))*sizeof(float));
- memset(&vect[ENH_VECTL-(en-idatal)], 0,
- (en-idatal)*sizeof(float));
- }
- else {
- memcpy(vect, &idata[st], ENH_VECTL*sizeof(float));
- }
- }
- fraction=tloc2*ENH_UPS0-tloc;
-
- /* compute the segment (this is actually a convolution) */
-
- mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction,
-
-
- 2*ENH_FL0+1);
-}
-
-/*----------------------------------------------------------------*
- * find the smoothed output data
- *---------------------------------------------------------------*/
-
-static void smath(
- float *odata, /* (o) smoothed output */
- float *sseq,/* (i) said second sequence of waveforms */
- int hl, /* (i) 2*hl+1 is sseq dimension */
- float alpha0/* (i) max smoothing energy fraction */
-){
- int i,k;
- float w00,w10,w11,A,B,C,*psseq,err,errs;
- float surround[BLOCKL_MAX]; /* shape contributed by other than
- current */
- float wt[2*ENH_HL+1]; /* waveform weighting to get
- surround shape */
- float denom;
-
- /* create shape of contribution from all waveforms except the
- current one */
-
- for (i=1; i<=2*hl+1; i++) {
- wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2)));
- }
- wt[hl]=0.0; /* for clarity, not used */
- for (i=0; i<ENH_BLOCKL; i++) {
- surround[i]=sseq[i]*wt[0];
- }
- for (k=1; k<hl; k++) {
- psseq=sseq+k*ENH_BLOCKL;
- for(i=0;i<ENH_BLOCKL; i++) {
- surround[i]+=psseq[i]*wt[k];
- }
- }
- for (k=hl+1; k<=2*hl; k++) {
- psseq=sseq+k*ENH_BLOCKL;
- for(i=0;i<ENH_BLOCKL; i++) {
- surround[i]+=psseq[i]*wt[k];
- }
- }
-
- /* compute some inner products */
-
- w00 = w10 = w11 = 0.0;
- psseq=sseq+hl*ENH_BLOCKL; /* current block */
- for (i=0; i<ENH_BLOCKL;i++) {
- w00+=psseq[i]*psseq[i];
- w11+=surround[i]*surround[i];
- w10+=surround[i]*psseq[i];
- }
-
-
-
- if (fabs(w11) < 1.0) {
- w11=1.0;
- }
- C = (float)sqrt( w00/w11);
-
- /* first try enhancement without power-constraint */
-
- errs=0.0;
- psseq=sseq+hl*ENH_BLOCKL;
- for (i=0; i<ENH_BLOCKL; i++) {
- odata[i]=C*surround[i];
- err=psseq[i]-odata[i];
- errs+=err*err;
- }
-
- /* if constraint violated by first try, add constraint */
-
- if (errs > alpha0 * w00) {
- if ( w00 < 1) {
- w00=1;
- }
- denom = (w11*w00-w10*w10)/(w00*w00);
-
- if (denom > 0.0001) { /* eliminates numerical problems
- for if smooth */
- A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom);
- B = -alpha0/2 - A * w10/w00;
- B = B+1;
- }
- else { /* essentially no difference between cycles;
- smoothing not needed */
- A= 0.0;
- B= 1.0;
- }
-
- /* create smoothed sequence */
-
- psseq=sseq+hl*ENH_BLOCKL;
- for (i=0; i<ENH_BLOCKL; i++) {
- odata[i]=A*surround[i]+B*psseq[i];
- }
- }
-}
-
-/*----------------------------------------------------------------*
- * get the pitch-synchronous sample sequence
- *---------------------------------------------------------------*/
-
-static void getsseq(
- float *sseq, /* (o) the pitch-synchronous sequence */
- float *idata, /* (i) original data */
- int idatal, /* (i) dimension of data */
- int centerStartPos, /* (i) where current block starts */
- float *period, /* (i) rough-pitch-period array */
-
-
- float *plocs, /* (i) where periods of period array
- are taken */
- int periodl, /* (i) dimension period array */
- int hl /* (i) 2*hl+1 is the number of sequences */
-){
- int i,centerEndPos,q;
- float blockStartPos[2*ENH_HL+1];
- int lagBlock[2*ENH_HL+1];
- float plocs2[ENH_PLOCSL];
- float *psseq;
-
- centerEndPos=centerStartPos+ENH_BLOCKL-1;
-
- /* present */
-
- NearestNeighbor(lagBlock+hl,plocs,
- (float)0.5*(centerStartPos+centerEndPos),periodl);
-
- blockStartPos[hl]=(float)centerStartPos;
- psseq=sseq+ENH_BLOCKL*hl;
- memcpy(psseq, idata+centerStartPos, ENH_BLOCKL*sizeof(float));
-
- /* past */
-
- for (q=hl-1; q>=0; q--) {
- blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]];
- NearestNeighbor(lagBlock+q,plocs,
- blockStartPos[q]+
- ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl);
-
-
- if (blockStartPos[q]-ENH_OVERHANG>=0) {
- refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata,
- idatal, centerStartPos, blockStartPos[q],
- period[lagBlock[q+1]]);
- } else {
- psseq=sseq+q*ENH_BLOCKL;
- memset(psseq, 0, ENH_BLOCKL*sizeof(float));
- }
- }
-
- /* future */
-
- for (i=0; i<periodl; i++) {
- plocs2[i]=plocs[i]-period[i];
- }
- for (q=hl+1; q<=2*hl; q++) {
- NearestNeighbor(lagBlock+q,plocs2,
- blockStartPos[q-1]+ENH_BLOCKL_HALF,periodl);
-
- blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];
- if (blockStartPos[q]+ENH_BLOCKL+ENH_OVERHANG<idatal) {
- refiner(sseq+ENH_BLOCKL*q, blockStartPos+q, idata,
- idatal, centerStartPos, blockStartPos[q],
-
-
- period[lagBlock[q]]);
- }
- else {
- psseq=sseq+q*ENH_BLOCKL;
- memset(psseq, 0, ENH_BLOCKL*sizeof(float));
- }
- }
-}
-
-/*----------------------------------------------------------------*
- * perform enhancement on idata+centerStartPos through
- * idata+centerStartPos+ENH_BLOCKL-1
- *---------------------------------------------------------------*/
-
-static void enhancer(
- float *odata, /* (o) smoothed block, dimension blockl */
- float *idata, /* (i) data buffer used for enhancing */
- int idatal, /* (i) dimension idata */
- int centerStartPos, /* (i) first sample current block
- within idata */
- float alpha0, /* (i) max correction-energy-fraction
- (in [0,1]) */
- float *period, /* (i) pitch period array */
- float *plocs, /* (i) locations where period array
- values valid */
- int periodl /* (i) dimension of period and plocs */
-){
- float sseq[(2*ENH_HL+1)*ENH_BLOCKL];
-
- /* get said second sequence of segments */
-
- getsseq(sseq,idata,idatal,centerStartPos,period,
- plocs,periodl,ENH_HL);
-
- /* compute the smoothed output from said second sequence */
-
- smath(odata,sseq,ENH_HL,alpha0);
-
-}
-
-/*----------------------------------------------------------------*
- * cross correlation
- *---------------------------------------------------------------*/
-
-float xCorrCoef(
- float *target, /* (i) first array */
- float *regressor, /* (i) second array */
- int subl /* (i) dimension arrays */
-){
- int i;
- float ftmp1, ftmp2;
-
- ftmp1 = 0.0;
- ftmp2 = 0.0;
-
-
- for (i=0; i<subl; i++) {
- ftmp1 += target[i]*regressor[i];
- ftmp2 += regressor[i]*regressor[i];
- }
-
- if (ftmp1 > 0.0) {
- return (float)(ftmp1*ftmp1/ftmp2);
- }
- else {
- return (float)0.0;
- }
-}
-
-/*----------------------------------------------------------------*
- * interface for enhancer
- *---------------------------------------------------------------*/
-
-int enhancerInterface(
- float *out, /* (o) enhanced signal */
- float *in, /* (i) unenhanced signal */
- iLBC_Dec_Inst_t *iLBCdec_inst /* (i) buffers etc */
-){
- float *enh_buf, *enh_period;
- int iblock, isample;
- int lag=0, ilag, i, ioffset;
- float cc, maxcc;
- float ftmp1, ftmp2;
- float *inPtr, *enh_bufPtr1, *enh_bufPtr2;
- float plc_pred[ENH_BLOCKL];
-
- float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2];
- int inLen=ENH_NBLOCKS*ENH_BLOCKL+120;
- int start, plc_blockl, inlag;
-
- enh_buf=iLBCdec_inst->enh_buf;
- enh_period=iLBCdec_inst->enh_period;
-
- memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl],
- (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float));
-
- memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in,
- iLBCdec_inst->blockl*sizeof(float));
-
- if (iLBCdec_inst->mode==30)
- plc_blockl=ENH_BLOCKL;
- else
- plc_blockl=40;
-
- /* when 20 ms frame, move processing one block */
- ioffset=0;
- if (iLBCdec_inst->mode==20) ioffset=1;
-
- i=3-ioffset;
- memmove(enh_period, &enh_period[i],
-
-
- (ENH_NBLOCKS_TOT-i)*sizeof(float));
-
- /* Set state information to the 6 samples right before
- the samples to be downsampled. */
-
- memcpy(lpState,
- enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126,
- 6*sizeof(float));
-
- /* Down sample a factor 2 to save computations */
-
- DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120,
- lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL,
- lpState, downsampled);
-
- /* Estimate the pitch in the down sampled domain. */
- for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) {
-
- lag = 10;
- maxcc = xCorrCoef(downsampled+60+iblock*
- ENH_BLOCKL_HALF, downsampled+60+iblock*
- ENH_BLOCKL_HALF-lag, ENH_BLOCKL_HALF);
- for (ilag=11; ilag<60; ilag++) {
- cc = xCorrCoef(downsampled+60+iblock*
- ENH_BLOCKL_HALF, downsampled+60+iblock*
- ENH_BLOCKL_HALF-ilag, ENH_BLOCKL_HALF);
-
- if (cc > maxcc) {
- maxcc = cc;
- lag = ilag;
- }
- }
-
- /* Store the estimated lag in the non-downsampled domain */
- enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2;
-
-
- }
-
-
- /* PLC was performed on the previous packet */
- if (iLBCdec_inst->prev_enh_pl==1) {
-
- inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset];
-
- lag = inlag-1;
- maxcc = xCorrCoef(in, in+lag, plc_blockl);
- for (ilag=inlag; ilag<=inlag+1; ilag++) {
- cc = xCorrCoef(in, in+ilag, plc_blockl);
-
- if (cc > maxcc) {
- maxcc = cc;
- lag = ilag;
- }
- }
-
-
-
- enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag;
-
- /* compute new concealed residual for the old lookahead,
- mix the forward PLC with a backward PLC from
- the new frame */
-
- inPtr=&in[lag-1];
-
- enh_bufPtr1=&plc_pred[plc_blockl-1];
-
- if (lag>plc_blockl) {
- start=plc_blockl;
- } else {
- start=lag;
- }
-
- for (isample = start; isample>0; isample--) {
- *enh_bufPtr1-- = *inPtr--;
- }
-
- enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
- for (isample = (plc_blockl-1-lag); isample>=0; isample--)
-{
- *enh_bufPtr1-- = *enh_bufPtr2--;
- }
-
- /* limit energy change */
- ftmp2=0.0;
- ftmp1=0.0;
- for (i=0;i<plc_blockl;i++) {
- ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]*
- enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i];
- ftmp1+=plc_pred[i]*plc_pred[i];
- }
- ftmp1=(float)sqrt(ftmp1/(float)plc_blockl);
- ftmp2=(float)sqrt(ftmp2/(float)plc_blockl);
- if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) {
- for (i=0;i<plc_blockl-10;i++) {
- plc_pred[i]*=(float)2.0*ftmp2/ftmp1;
- }
- for (i=plc_blockl-10;i<plc_blockl;i++) {
- plc_pred[i]*=(float)(i-plc_blockl+10)*
- ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+
- (float)2.0*ftmp2/ftmp1;
- }
- }
-
- enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
- for (i=0; i<plc_blockl; i++) {
- ftmp1 = (float) (i+1) / (float) (plc_blockl+1);
- *enh_bufPtr1 *= ftmp1;
- *enh_bufPtr1 += ((float)1.0-ftmp1)*
- plc_pred[plc_blockl-1-i];
- enh_bufPtr1--;
- }
-
-
- }
-
- if (iLBCdec_inst->mode==20) {
- /* Enhancer with 40 samples delay */
- for (iblock = 0; iblock<2; iblock++) {
- enhancer(out+iblock*ENH_BLOCKL, enh_buf,
- ENH_BUFL, (5+iblock)*ENH_BLOCKL+40,
- ENH_ALPHA0, enh_period, enh_plocsTbl,
- ENH_NBLOCKS_TOT);
- }
- } else if (iLBCdec_inst->mode==30) {
- /* Enhancer with 80 samples delay */
- for (iblock = 0; iblock<3; iblock++) {
- enhancer(out+iblock*ENH_BLOCKL, enh_buf,
- ENH_BUFL, (4+iblock)*ENH_BLOCKL,
- ENH_ALPHA0, enh_period, enh_plocsTbl,
- ENH_NBLOCKS_TOT);
- }
- }
-
- return (lag*2);
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/enhancer.h b/1.2-netsec/codecs/ilbc/enhancer.h
deleted file mode 100644
index aa37b1843..000000000
--- a/1.2-netsec/codecs/ilbc/enhancer.h
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- enhancer.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __ENHANCER_H
-#define __ENHANCER_H
-
-#include "iLBC_define.h"
-
-float xCorrCoef(
- float *target, /* (i) first array */
- float *regressor, /* (i) second array */
- int subl /* (i) dimension arrays */
-);
-
-int enhancerInterface(
- float *out, /* (o) the enhanced recidual signal */
- float *in, /* (i) the recidual signal to enhance */
- iLBC_Dec_Inst_t *iLBCdec_inst
- /* (i/o) the decoder state structure */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/filter.c b/1.2-netsec/codecs/ilbc/filter.c
deleted file mode 100644
index f4ba63386..000000000
--- a/1.2-netsec/codecs/ilbc/filter.c
+++ /dev/null
@@ -1,168 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- filter.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-
-
-#include "iLBC_define.h"
-#include "filter.h"
-
-/*----------------------------------------------------------------*
- * all-pole filter
- *---------------------------------------------------------------*/
-
-void AllPoleFilter(
- float *InOut, /* (i/o) on entrance InOut[-orderCoef] to
- InOut[-1] contain the state of the
- filter (delayed samples). InOut[0] to
- InOut[lengthInOut-1] contain the filter
- input, on en exit InOut[-orderCoef] to
- InOut[-1] is unchanged and InOut[0] to
- InOut[lengthInOut-1] contain filtered
- samples */
- float *Coef,/* (i) filter coefficients, Coef[0] is assumed
- to be 1.0 */
- int lengthInOut,/* (i) number of input/output samples */
- int orderCoef /* (i) number of filter coefficients */
-){
- int n,k;
-
- for(n=0;n<lengthInOut;n++){
- for(k=1;k<=orderCoef;k++){
- *InOut -= Coef[k]*InOut[-k];
- }
- InOut++;
- }
-}
-
-/*----------------------------------------------------------------*
- * all-zero filter
- *---------------------------------------------------------------*/
-
-void AllZeroFilter(
- float *In, /* (i) In[0] to In[lengthInOut-1] contain
- filter input samples */
- float *Coef,/* (i) filter coefficients (Coef[0] is assumed
- to be 1.0) */
- int lengthInOut,/* (i) number of input/output samples */
- int orderCoef, /* (i) number of filter coefficients */
- float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1]
- contain the filter state, on exit Out[0]
- to Out[lengthInOut-1] contain filtered
- samples */
-){
- int n,k;
-
- for(n=0;n<lengthInOut;n++){
- *Out = Coef[0]*In[0];
- for(k=1;k<=orderCoef;k++){
- *Out += Coef[k]*In[-k];
- }
-
-
- Out++;
- In++;
- }
-}
-
-/*----------------------------------------------------------------*
- * pole-zero filter
- *---------------------------------------------------------------*/
-
-void ZeroPoleFilter(
- float *In, /* (i) In[0] to In[lengthInOut-1] contain
- filter input samples In[-orderCoef] to
- In[-1] contain state of all-zero
- section */
- float *ZeroCoef,/* (i) filter coefficients for all-zero
- section (ZeroCoef[0] is assumed to
- be 1.0) */
- float *PoleCoef,/* (i) filter coefficients for all-pole section
- (ZeroCoef[0] is assumed to be 1.0) */
- int lengthInOut,/* (i) number of input/output samples */
- int orderCoef, /* (i) number of filter coefficients */
- float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1]
- contain state of all-pole section. On
- exit Out[0] to Out[lengthInOut-1]
- contain filtered samples */
-){
- AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out);
- AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef);
-}
-
-/*----------------------------------------------------------------*
- * downsample (LP filter and decimation)
- *---------------------------------------------------------------*/
-
-void DownSample (
- float *In, /* (i) input samples */
- float *Coef, /* (i) filter coefficients */
- int lengthIn, /* (i) number of input samples */
- float *state, /* (i) filter state */
- float *Out /* (o) downsampled output */
-){
- float o;
- float *Out_ptr = Out;
- float *Coef_ptr, *In_ptr;
- float *state_ptr;
- int i, j, stop;
-
- /* LP filter and decimate at the same time */
-
- for (i = DELAY_DS; i < lengthIn; i+=FACTOR_DS)
- {
- Coef_ptr = &Coef[0];
- In_ptr = &In[i];
- state_ptr = &state[FILTERORDER_DS-2];
-
-
-
- o = (float)0.0;
-
- stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS;
-
- for (j = 0; j < stop; j++)
- {
- o += *Coef_ptr++ * (*In_ptr--);
- }
- for (j = i + 1; j < FILTERORDER_DS; j++)
- {
- o += *Coef_ptr++ * (*state_ptr--);
- }
-
- *Out_ptr++ = o;
- }
-
- /* Get the last part (use zeros as input for the future) */
-
- for (i=(lengthIn+FACTOR_DS); i<(lengthIn+DELAY_DS);
- i+=FACTOR_DS) {
-
- o=(float)0.0;
-
- if (i<lengthIn) {
- Coef_ptr = &Coef[0];
- In_ptr = &In[i];
- for (j=0; j<FILTERORDER_DS; j++) {
- o += *Coef_ptr++ * (*Out_ptr--);
- }
- } else {
- Coef_ptr = &Coef[i-lengthIn];
- In_ptr = &In[lengthIn-1];
- for (j=0; j<FILTERORDER_DS-(i-lengthIn); j++) {
- o += *Coef_ptr++ * (*In_ptr--);
- }
- }
- *Out_ptr++ = o;
- }
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/filter.h b/1.2-netsec/codecs/ilbc/filter.h
deleted file mode 100644
index 95d3b5445..000000000
--- a/1.2-netsec/codecs/ilbc/filter.h
+++ /dev/null
@@ -1,73 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- filter.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_FILTER_H
-#define __iLBC_FILTER_H
-
-void AllPoleFilter(
- float *InOut, /* (i/o) on entrance InOut[-orderCoef] to
- InOut[-1] contain the state of the
- filter (delayed samples). InOut[0] to
- InOut[lengthInOut-1] contain the filter
- input, on en exit InOut[-orderCoef] to
- InOut[-1] is unchanged and InOut[0] to
- InOut[lengthInOut-1] contain filtered
- samples */
- float *Coef,/* (i) filter coefficients, Coef[0] is assumed
- to be 1.0 */
- int lengthInOut,/* (i) number of input/output samples */
- int orderCoef /* (i) number of filter coefficients */
-);
-
-
-
-void AllZeroFilter(
- float *In, /* (i) In[0] to In[lengthInOut-1] contain
- filter input samples */
- float *Coef,/* (i) filter coefficients (Coef[0] is assumed
- to be 1.0) */
- int lengthInOut,/* (i) number of input/output samples */
- int orderCoef, /* (i) number of filter coefficients */
- float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1]
- contain the filter state, on exit Out[0]
- to Out[lengthInOut-1] contain filtered
- samples */
-);
-
-void ZeroPoleFilter(
- float *In, /* (i) In[0] to In[lengthInOut-1] contain filter
- input samples In[-orderCoef] to In[-1]
- contain state of all-zero section */
- float *ZeroCoef,/* (i) filter coefficients for all-zero
- section (ZeroCoef[0] is assumed to
- be 1.0) */
- float *PoleCoef,/* (i) filter coefficients for all-pole section
- (ZeroCoef[0] is assumed to be 1.0) */
- int lengthInOut,/* (i) number of input/output samples */
- int orderCoef, /* (i) number of filter coefficients */
- float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1]
- contain state of all-pole section. On
- exit Out[0] to Out[lengthInOut-1]
- contain filtered samples */
-);
-
-void DownSample (
- float *In, /* (i) input samples */
- float *Coef, /* (i) filter coefficients */
- int lengthIn, /* (i) number of input samples */
- float *state, /* (i) filter state */
- float *Out /* (o) downsampled output */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/gainquant.c b/1.2-netsec/codecs/ilbc/gainquant.c
deleted file mode 100644
index 33dc19474..000000000
--- a/1.2-netsec/codecs/ilbc/gainquant.c
+++ /dev/null
@@ -1,107 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- gainquant.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-
-
-******************************************************************/
-
-#include <string.h>
-#include <math.h>
-#include "constants.h"
-#include "gainquant.h"
-#include "filter.h"
-
-/*----------------------------------------------------------------*
- * quantizer for the gain in the gain-shape coding of residual
- *---------------------------------------------------------------*/
-
-float gainquant(/* (o) quantized gain value */
- float in, /* (i) gain value */
- float maxIn,/* (i) maximum of gain value */
- int cblen, /* (i) number of quantization indices */
- int *index /* (o) quantization index */
-){
- int i, tindex;
- float minmeasure,measure, *cb, scale;
-
- /* ensure a lower bound on the scaling factor */
-
- scale=maxIn;
-
- if (scale<0.1) {
- scale=(float)0.1;
- }
-
- /* select the quantization table */
-
- if (cblen == 8) {
- cb = gain_sq3Tbl;
- } else if (cblen == 16) {
- cb = gain_sq4Tbl;
- } else {
- cb = gain_sq5Tbl;
- }
-
- /* select the best index in the quantization table */
-
- minmeasure=10000000.0;
- tindex=0;
- for (i=0; i<cblen; i++) {
- measure=(in-scale*cb[i])*(in-scale*cb[i]);
-
- if (measure<minmeasure) {
- tindex=i;
- minmeasure=measure;
- }
- }
- *index=tindex;
-
- /* return the quantized value */
-
-
-
- return scale*cb[tindex];
-}
-
-/*----------------------------------------------------------------*
- * decoder for quantized gains in the gain-shape coding of
- * residual
- *---------------------------------------------------------------*/
-
-float gaindequant( /* (o) quantized gain value */
- int index, /* (i) quantization index */
- float maxIn,/* (i) maximum of unquantized gain */
- int cblen /* (i) number of quantization indices */
-){
- float scale;
-
- /* obtain correct scale factor */
-
- scale=(float)fabs(maxIn);
-
- if (scale<0.1) {
- scale=(float)0.1;
- }
-
- /* select the quantization table and return the decoded value */
-
- if (cblen==8) {
- return scale*gain_sq3Tbl[index];
- } else if (cblen==16) {
- return scale*gain_sq4Tbl[index];
- }
- else if (cblen==32) {
- return scale*gain_sq5Tbl[index];
- }
-
- return 0.0;
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/gainquant.h b/1.2-netsec/codecs/ilbc/gainquant.h
deleted file mode 100644
index f613b3565..000000000
--- a/1.2-netsec/codecs/ilbc/gainquant.h
+++ /dev/null
@@ -1,31 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- gainquant.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_GAINQUANT_H
-#define __iLBC_GAINQUANT_H
-
-float gainquant(/* (o) quantized gain value */
- float in, /* (i) gain value */
- float maxIn,/* (i) maximum of gain value */
- int cblen, /* (i) number of quantization indices */
- int *index /* (o) quantization index */
-);
-
-float gaindequant( /* (o) quantized gain value */
- int index, /* (i) quantization index */
- float maxIn,/* (i) maximum of unquantized gain */
- int cblen /* (i) number of quantization indices */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/getCBvec.c b/1.2-netsec/codecs/ilbc/getCBvec.c
deleted file mode 100644
index 081abb216..000000000
--- a/1.2-netsec/codecs/ilbc/getCBvec.c
+++ /dev/null
@@ -1,181 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- getCBvec.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include "iLBC_define.h"
-#include "getCBvec.h"
-#include "constants.h"
-#include <string.h>
-
-/*----------------------------------------------------------------*
- * Construct codebook vector for given index.
- *---------------------------------------------------------------*/
-
-void getCBvec(
- float *cbvec, /* (o) Constructed codebook vector */
- float *mem, /* (i) Codebook buffer */
- int index, /* (i) Codebook index */
- int lMem, /* (i) Length of codebook buffer */
- int cbveclen/* (i) Codebook vector length */
-){
- int j, k, n, memInd, sFilt;
- float tmpbuf[CB_MEML];
- int base_size;
- int ilow, ihigh;
- float alfa, alfa1;
-
- /* Determine size of codebook sections */
-
- base_size=lMem-cbveclen+1;
-
- if (cbveclen==SUBL) {
- base_size+=cbveclen/2;
- }
-
- /* No filter -> First codebook section */
-
-
-
- if (index<lMem-cbveclen+1) {
-
- /* first non-interpolated vectors */
-
- k=index+cbveclen;
- /* get vector */
- memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float));
-
- } else if (index < base_size) {
-
- k=2*(index-(lMem-cbveclen+1))+cbveclen;
-
- ihigh=k/2;
- ilow=ihigh-5;
-
- /* Copy first noninterpolated part */
-
- memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float));
-
- /* interpolation */
-
- alfa1=(float)0.2;
- alfa=0.0;
- for (j=ilow; j<ihigh; j++) {
- cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+
- alfa*mem[lMem-k+j];
- alfa+=alfa1;
- }
-
- /* Copy second noninterpolated part */
-
- memcpy(cbvec+ihigh, mem+lMem-k+ihigh,
- (cbveclen-ihigh)*sizeof(float));
-
- }
-
- /* Higher codebbok section based on filtering */
-
- else {
-
- /* first non-interpolated vectors */
-
- if (index-base_size<lMem-cbveclen+1) {
- float tempbuff2[CB_MEML+CB_FILTERLEN+1];
- float *pos;
- float *pp, *pp1;
-
- memset(tempbuff2, 0,
- CB_HALFFILTERLEN*sizeof(float));
- memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
- lMem*sizeof(float));
- memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
- (CB_HALFFILTERLEN+1)*sizeof(float));
-
-
-
- k=index-base_size+cbveclen;
- sFilt=lMem-k;
- memInd=sFilt+1-CB_HALFFILTERLEN;
-
- /* do filtering */
- pos=cbvec;
- memset(pos, 0, cbveclen*sizeof(float));
- for (n=0; n<cbveclen; n++) {
- pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN];
- pp1=&cbfiltersTbl[CB_FILTERLEN-1];
- for (j=0; j<CB_FILTERLEN; j++) {
- (*pos)+=(*pp++)*(*pp1--);
- }
- pos++;
- }
- }
-
- /* interpolated vectors */
-
- else {
- float tempbuff2[CB_MEML+CB_FILTERLEN+1];
-
- float *pos;
- float *pp, *pp1;
- int i;
-
- memset(tempbuff2, 0,
- CB_HALFFILTERLEN*sizeof(float));
- memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
- lMem*sizeof(float));
- memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
- (CB_HALFFILTERLEN+1)*sizeof(float));
-
- k=2*(index-base_size-
- (lMem-cbveclen+1))+cbveclen;
- sFilt=lMem-k;
- memInd=sFilt+1-CB_HALFFILTERLEN;
-
- /* do filtering */
- pos=&tmpbuf[sFilt];
- memset(pos, 0, k*sizeof(float));
- for (i=0; i<k; i++) {
- pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN];
- pp1=&cbfiltersTbl[CB_FILTERLEN-1];
- for (j=0; j<CB_FILTERLEN; j++) {
- (*pos)+=(*pp++)*(*pp1--);
- }
- pos++;
- }
-
- ihigh=k/2;
- ilow=ihigh-5;
-
-
-
- /* Copy first noninterpolated part */
-
- memcpy(cbvec, tmpbuf+lMem-k/2,
- ilow*sizeof(float));
-
- /* interpolation */
-
- alfa1=(float)0.2;
- alfa=0.0;
- for (j=ilow; j<ihigh; j++) {
- cbvec[j]=((float)1.0-alfa)*
- tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j];
- alfa+=alfa1;
- }
-
- /* Copy second noninterpolated part */
-
- memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh,
- (cbveclen-ihigh)*sizeof(float));
- }
- }
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/getCBvec.h b/1.2-netsec/codecs/ilbc/getCBvec.h
deleted file mode 100644
index 8b1f8c85c..000000000
--- a/1.2-netsec/codecs/ilbc/getCBvec.h
+++ /dev/null
@@ -1,28 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- getCBvec.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_GETCBVEC_H
-#define __iLBC_GETCBVEC_H
-
-
-
-void getCBvec(
- float *cbvec, /* (o) Constructed codebook vector */
- float *mem, /* (i) Codebook buffer */
- int index, /* (i) Codebook index */
- int lMem, /* (i) Length of codebook buffer */
- int cbveclen/* (i) Codebook vector length */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/helpfun.c b/1.2-netsec/codecs/ilbc/helpfun.c
deleted file mode 100644
index 02d83c971..000000000
--- a/1.2-netsec/codecs/ilbc/helpfun.c
+++ /dev/null
@@ -1,308 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- helpfun.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-
-#include "iLBC_define.h"
-#include "helpfun.h"
-#include "constants.h"
-
-/*----------------------------------------------------------------*
- * calculation of auto correlation
- *---------------------------------------------------------------*/
-
-void autocorr(
- float *r, /* (o) autocorrelation vector */
- const float *x, /* (i) data vector */
- int N, /* (i) length of data vector */
- int order /* largest lag for calculated
- autocorrelations */
-){
- int lag, n;
- float sum;
-
- for (lag = 0; lag <= order; lag++) {
- sum = 0;
- for (n = 0; n < N - lag; n++) {
- sum += x[n] * x[n+lag];
- }
- r[lag] = sum;
- }
-}
-
-
-
-/*----------------------------------------------------------------*
- * window multiplication
- *---------------------------------------------------------------*/
-
-void window(
- float *z, /* (o) the windowed data */
- const float *x, /* (i) the original data vector */
- const float *y, /* (i) the window */
- int N /* (i) length of all vectors */
-){
- int i;
-
- for (i = 0; i < N; i++) {
- z[i] = x[i] * y[i];
- }
-}
-
-/*----------------------------------------------------------------*
- * levinson-durbin solution for lpc coefficients
- *---------------------------------------------------------------*/
-
-void levdurb(
- float *a, /* (o) lpc coefficient vector starting
- with 1.0 */
- float *k, /* (o) reflection coefficients */
- float *r, /* (i) autocorrelation vector */
- int order /* (i) order of lpc filter */
-){
- float sum, alpha;
- int m, m_h, i;
-
- a[0] = 1.0;
-
- if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */
- for (i = 0; i < order; i++) {
- k[i] = 0;
- a[i+1] = 0;
- }
- } else {
- a[1] = k[0] = -r[1]/r[0];
- alpha = r[0] + r[1] * k[0];
- for (m = 1; m < order; m++){
- sum = r[m + 1];
- for (i = 0; i < m; i++){
- sum += a[i+1] * r[m - i];
- }
- k[m] = -sum / alpha;
- alpha += k[m] * sum;
- m_h = (m + 1) >> 1;
- for (i = 0; i < m_h; i++){
- sum = a[i+1] + k[m] * a[m - i];
- a[m - i] += k[m] * a[i+1];
- a[i+1] = sum;
-
-
- }
- a[m+1] = k[m];
- }
- }
-}
-
-/*----------------------------------------------------------------*
- * interpolation between vectors
- *---------------------------------------------------------------*/
-
-void interpolate(
- float *out, /* (o) the interpolated vector */
- float *in1, /* (i) the first vector for the
- interpolation */
- float *in2, /* (i) the second vector for the
- interpolation */
- float coef, /* (i) interpolation weights */
- int length /* (i) length of all vectors */
-){
- int i;
- float invcoef;
-
- invcoef = (float)1.0 - coef;
- for (i = 0; i < length; i++) {
- out[i] = coef * in1[i] + invcoef * in2[i];
- }
-}
-
-/*----------------------------------------------------------------*
- * lpc bandwidth expansion
- *---------------------------------------------------------------*/
-
-void bwexpand(
- float *out, /* (o) the bandwidth expanded lpc
- coefficients */
- float *in, /* (i) the lpc coefficients before bandwidth
- expansion */
- float coef, /* (i) the bandwidth expansion factor */
- int length /* (i) the length of lpc coefficient vectors */
-){
- int i;
- float chirp;
-
- chirp = coef;
-
- out[0] = in[0];
- for (i = 1; i < length; i++) {
- out[i] = chirp * in[i];
- chirp *= coef;
- }
-}
-
-/*----------------------------------------------------------------*
- * vector quantization
-
-
- *---------------------------------------------------------------*/
-
-void vq(
- float *Xq, /* (o) the quantized vector */
- int *index, /* (o) the quantization index */
- const float *CB,/* (i) the vector quantization codebook */
- float *X, /* (i) the vector to quantize */
- int n_cb, /* (i) the number of vectors in the codebook */
- int dim /* (i) the dimension of all vectors */
-){
- int i, j;
- int pos, minindex;
- float dist, tmp, mindist;
-
- pos = 0;
- mindist = FLOAT_MAX;
- minindex = 0;
- for (j = 0; j < n_cb; j++) {
- dist = X[0] - CB[pos];
- dist *= dist;
- for (i = 1; i < dim; i++) {
- tmp = X[i] - CB[pos + i];
- dist += tmp*tmp;
- }
-
- if (dist < mindist) {
- mindist = dist;
- minindex = j;
- }
- pos += dim;
- }
- for (i = 0; i < dim; i++) {
- Xq[i] = CB[minindex*dim + i];
- }
- *index = minindex;
-}
-
-/*----------------------------------------------------------------*
- * split vector quantization
- *---------------------------------------------------------------*/
-
-void SplitVQ(
- float *qX, /* (o) the quantized vector */
- int *index, /* (o) a vector of indexes for all vector
- codebooks in the split */
- float *X, /* (i) the vector to quantize */
- const float *CB,/* (i) the quantizer codebook */
- int nsplit, /* the number of vector splits */
- const int *dim, /* the dimension of X and qX */
- const int *cbsize /* the number of vectors in the codebook */
-){
- int cb_pos, X_pos, i;
-
- cb_pos = 0;
-
-
- X_pos= 0;
- for (i = 0; i < nsplit; i++) {
- vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos,
- cbsize[i], dim[i]);
- X_pos += dim[i];
- cb_pos += dim[i] * cbsize[i];
- }
-}
-
-/*----------------------------------------------------------------*
- * scalar quantization
- *---------------------------------------------------------------*/
-
-void sort_sq(
- float *xq, /* (o) the quantized value */
- int *index, /* (o) the quantization index */
- float x, /* (i) the value to quantize */
- const float *cb,/* (i) the quantization codebook */
- int cb_size /* (i) the size of the quantization codebook */
-){
- int i;
-
- if (x <= cb[0]) {
- *index = 0;
- *xq = cb[0];
- } else {
- i = 0;
- while ((x > cb[i]) && i < cb_size - 1) {
- i++;
- }
-
- if (x > ((cb[i] + cb[i - 1])/2)) {
- *index = i;
- *xq = cb[i];
- } else {
- *index = i - 1;
- *xq = cb[i - 1];
- }
- }
-}
-
-/*----------------------------------------------------------------*
- * check for stability of lsf coefficients
- *---------------------------------------------------------------*/
-
-int LSF_check( /* (o) 1 for stable lsf vectors and 0 for
- nonstable ones */
- float *lsf, /* (i) a table of lsf vectors */
- int dim, /* (i) the dimension of each lsf vector */
- int NoAn /* (i) the number of lsf vectors in the
- table */
-){
- int k,n,m, Nit=2, change=0,pos;
- float tmp;
-
-
- static float eps=(float)0.039; /* 50 Hz */
- static float eps2=(float)0.0195;
- static float maxlsf=(float)3.14; /* 4000 Hz */
- static float minlsf=(float)0.01; /* 0 Hz */
-
- /* LSF separation check*/
-
- for (n=0; n<Nit; n++) { /* Run through a couple of times */
- for (m=0; m<NoAn; m++) { /* Number of analyses per frame */
- for (k=0; k<(dim-1); k++) {
- pos=m*dim+k;
-
- if ((lsf[pos+1]-lsf[pos])<eps) {
-
- if (lsf[pos+1]<lsf[pos]) {
- tmp=lsf[pos+1];
- lsf[pos+1]= lsf[pos]+eps2;
- lsf[pos]= lsf[pos+1]-eps2;
- } else {
- lsf[pos]-=eps2;
- lsf[pos+1]+=eps2;
- }
- change=1;
- }
-
- if (lsf[pos]<minlsf) {
- lsf[pos]=minlsf;
- change=1;
- }
-
- if (lsf[pos]>maxlsf) {
- lsf[pos]=maxlsf;
- change=1;
- }
- }
- }
- }
-
- return change;
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/helpfun.h b/1.2-netsec/codecs/ilbc/helpfun.h
deleted file mode 100644
index 291a761d9..000000000
--- a/1.2-netsec/codecs/ilbc/helpfun.h
+++ /dev/null
@@ -1,101 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- helpfun.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_HELPFUN_H
-#define __iLBC_HELPFUN_H
-
-void autocorr(
- float *r, /* (o) autocorrelation vector */
- const float *x, /* (i) data vector */
- int N, /* (i) length of data vector */
- int order /* largest lag for calculated
- autocorrelations */
-);
-
-void window(
- float *z, /* (o) the windowed data */
- const float *x, /* (i) the original data vector */
- const float *y, /* (i) the window */
- int N /* (i) length of all vectors */
-);
-
-
-
-void levdurb(
- float *a, /* (o) lpc coefficient vector starting
- with 1.0 */
- float *k, /* (o) reflection coefficients */
- float *r, /* (i) autocorrelation vector */
- int order /* (i) order of lpc filter */
-);
-
-void interpolate(
- float *out, /* (o) the interpolated vector */
- float *in1, /* (i) the first vector for the
- interpolation */
- float *in2, /* (i) the second vector for the
- interpolation */
- float coef, /* (i) interpolation weights */
- int length /* (i) length of all vectors */
-);
-
-void bwexpand(
- float *out, /* (o) the bandwidth expanded lpc
- coefficients */
- float *in, /* (i) the lpc coefficients before bandwidth
- expansion */
- float coef, /* (i) the bandwidth expansion factor */
- int length /* (i) the length of lpc coefficient vectors */
-);
-
-void vq(
- float *Xq, /* (o) the quantized vector */
- int *index, /* (o) the quantization index */
- const float *CB,/* (i) the vector quantization codebook */
- float *X, /* (i) the vector to quantize */
- int n_cb, /* (i) the number of vectors in the codebook */
- int dim /* (i) the dimension of all vectors */
-);
-
-void SplitVQ(
- float *qX, /* (o) the quantized vector */
- int *index, /* (o) a vector of indexes for all vector
- codebooks in the split */
- float *X, /* (i) the vector to quantize */
- const float *CB,/* (i) the quantizer codebook */
- int nsplit, /* the number of vector splits */
- const int *dim, /* the dimension of X and qX */
- const int *cbsize /* the number of vectors in the codebook */
-);
-
-
-void sort_sq(
- float *xq, /* (o) the quantized value */
- int *index, /* (o) the quantization index */
- float x, /* (i) the value to quantize */
- const float *cb,/* (i) the quantization codebook */
-
-
- int cb_size /* (i) the size of the quantization codebook */
-);
-
-int LSF_check( /* (o) 1 for stable lsf vectors and 0 for
- nonstable ones */
- float *lsf, /* (i) a table of lsf vectors */
- int dim, /* (i) the dimension of each lsf vector */
- int NoAn /* (i) the number of lsf vectors in the
- table */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/hpInput.c b/1.2-netsec/codecs/ilbc/hpInput.c
deleted file mode 100644
index 16b98f3df..000000000
--- a/1.2-netsec/codecs/ilbc/hpInput.c
+++ /dev/null
@@ -1,60 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- hpInput.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include "constants.h"
-#include "hpInput.h"
-
-/*----------------------------------------------------------------*
- * Input high-pass filter
- *---------------------------------------------------------------*/
-
-void hpInput(
- float *In, /* (i) vector to filter */
- int len, /* (i) length of vector to filter */
- float *Out, /* (o) the resulting filtered vector */
- float *mem /* (i/o) the filter state */
-){
- int i;
- float *pi, *po;
-
- /* all-zero section*/
-
- pi = &In[0];
- po = &Out[0];
- for (i=0; i<len; i++) {
- *po = hpi_zero_coefsTbl[0] * (*pi);
- *po += hpi_zero_coefsTbl[1] * mem[0];
- *po += hpi_zero_coefsTbl[2] * mem[1];
-
- mem[1] = mem[0];
- mem[0] = *pi;
- po++;
-
-
- pi++;
-
- }
-
- /* all-pole section*/
-
- po = &Out[0];
- for (i=0; i<len; i++) {
- *po -= hpi_pole_coefsTbl[1] * mem[2];
- *po -= hpi_pole_coefsTbl[2] * mem[3];
-
- mem[3] = mem[2];
- mem[2] = *po;
- po++;
- }
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/hpInput.h b/1.2-netsec/codecs/ilbc/hpInput.h
deleted file mode 100644
index 1de47003f..000000000
--- a/1.2-netsec/codecs/ilbc/hpInput.h
+++ /dev/null
@@ -1,27 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- hpInput.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-
-
-#ifndef __iLBC_HPINPUT_H
-#define __iLBC_HPINPUT_H
-
-void hpInput(
- float *In, /* (i) vector to filter */
- int len, /* (i) length of vector to filter */
- float *Out, /* (o) the resulting filtered vector */
- float *mem /* (i/o) the filter state */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/hpOutput.c b/1.2-netsec/codecs/ilbc/hpOutput.c
deleted file mode 100644
index fdc0f6db9..000000000
--- a/1.2-netsec/codecs/ilbc/hpOutput.c
+++ /dev/null
@@ -1,59 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- hpOutput.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-
-
-******************************************************************/
-
-#include "constants.h"
-#include "hpOutput.h"
-/*----------------------------------------------------------------*
- * Output high-pass filter
- *---------------------------------------------------------------*/
-
-void hpOutput(
- float *In, /* (i) vector to filter */
- int len,/* (i) length of vector to filter */
- float *Out, /* (o) the resulting filtered vector */
- float *mem /* (i/o) the filter state */
-){
- int i;
- float *pi, *po;
-
- /* all-zero section*/
-
- pi = &In[0];
- po = &Out[0];
- for (i=0; i<len; i++) {
- *po = hpo_zero_coefsTbl[0] * (*pi);
- *po += hpo_zero_coefsTbl[1] * mem[0];
- *po += hpo_zero_coefsTbl[2] * mem[1];
-
- mem[1] = mem[0];
- mem[0] = *pi;
- po++;
- pi++;
-
- }
-
- /* all-pole section*/
-
- po = &Out[0];
- for (i=0; i<len; i++) {
- *po -= hpo_pole_coefsTbl[1] * mem[2];
- *po -= hpo_pole_coefsTbl[2] * mem[3];
-
- mem[3] = mem[2];
- mem[2] = *po;
- po++;
- }
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/hpOutput.h b/1.2-netsec/codecs/ilbc/hpOutput.h
deleted file mode 100644
index 8092947a1..000000000
--- a/1.2-netsec/codecs/ilbc/hpOutput.h
+++ /dev/null
@@ -1,25 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- hpOutput.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_HPOUTPUT_H
-#define __iLBC_HPOUTPUT_H
-
-void hpOutput(
- float *In, /* (i) vector to filter */
- int len,/* (i) length of vector to filter */
- float *Out, /* (o) the resulting filtered vector */
- float *mem /* (i/o) the filter state */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/iCBConstruct.c b/1.2-netsec/codecs/ilbc/iCBConstruct.c
deleted file mode 100644
index dbee586c2..000000000
--- a/1.2-netsec/codecs/ilbc/iCBConstruct.c
+++ /dev/null
@@ -1,108 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- iCBConstruct.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-
-#include "iLBC_define.h"
-#include "iCBConstruct.h"
-#include "gainquant.h"
-#include "getCBvec.h"
-
-/*----------------------------------------------------------------*
- * Convert the codebook indexes to make the search easier
- *---------------------------------------------------------------*/
-
-
-
-void index_conv_enc(
- int *index /* (i/o) Codebook indexes */
-){
- int k;
-
- for (k=1; k<CB_NSTAGES; k++) {
-
- if ((index[k]>=108)&&(index[k]<172)) {
- index[k]-=64;
- } else if (index[k]>=236) {
- index[k]-=128;
- } else {
- /* ERROR */
- }
- }
-}
-
-void index_conv_dec(
- int *index /* (i/o) Codebook indexes */
-){
- int k;
-
- for (k=1; k<CB_NSTAGES; k++) {
-
- if ((index[k]>=44)&&(index[k]<108)) {
- index[k]+=64;
- } else if ((index[k]>=108)&&(index[k]<128)) {
- index[k]+=128;
- } else {
- /* ERROR */
- }
- }
-}
-
-/*----------------------------------------------------------------*
- * Construct decoded vector from codebook and gains.
- *---------------------------------------------------------------*/
-
-void iCBConstruct(
- float *decvector, /* (o) Decoded vector */
- int *index, /* (i) Codebook indices */
- int *gain_index,/* (i) Gain quantization indices */
- float *mem, /* (i) Buffer for codevector construction */
- int lMem, /* (i) Length of buffer */
- int veclen, /* (i) Length of vector */
- int nStages /* (i) Number of codebook stages */
-){
- int j,k;
- float gain[CB_NSTAGES];
- float cbvec[SUBL];
-
- /* gain de-quantization */
-
- gain[0] = gaindequant(gain_index[0], 1.0, 32);
-
-
- if (nStages > 1) {
- gain[1] = gaindequant(gain_index[1],
- (float)fabs(gain[0]), 16);
- }
- if (nStages > 2) {
- gain[2] = gaindequant(gain_index[2],
- (float)fabs(gain[1]), 8);
- }
-
- /* codebook vector construction and construction of
- total vector */
-
- getCBvec(cbvec, mem, index[0], lMem, veclen);
- for (j=0;j<veclen;j++){
- decvector[j] = gain[0]*cbvec[j];
- }
- if (nStages > 1) {
- for (k=1; k<nStages; k++) {
- getCBvec(cbvec, mem, index[k], lMem, veclen);
- for (j=0;j<veclen;j++) {
- decvector[j] += gain[k]*cbvec[j];
- }
- }
- }
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/iCBConstruct.h b/1.2-netsec/codecs/ilbc/iCBConstruct.h
deleted file mode 100644
index be218c347..000000000
--- a/1.2-netsec/codecs/ilbc/iCBConstruct.h
+++ /dev/null
@@ -1,38 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
-
-
- iCBConstruct.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_ICBCONSTRUCT_H
-#define __iLBC_ICBCONSTRUCT_H
-
-void index_conv_enc(
- int *index /* (i/o) Codebook indexes */
-);
-
-void index_conv_dec(
- int *index /* (i/o) Codebook indexes */
-);
-
-void iCBConstruct(
- float *decvector, /* (o) Decoded vector */
- int *index, /* (i) Codebook indices */
- int *gain_index,/* (i) Gain quantization indices */
- float *mem, /* (i) Buffer for codevector construction */
- int lMem, /* (i) Length of buffer */
- int veclen, /* (i) Length of vector */
- int nStages /* (i) Number of codebook stages */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/iCBSearch.c b/1.2-netsec/codecs/ilbc/iCBSearch.c
deleted file mode 100644
index c047297e3..000000000
--- a/1.2-netsec/codecs/ilbc/iCBSearch.c
+++ /dev/null
@@ -1,480 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- iCBSearch.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-#include <string.h>
-
-#include "iLBC_define.h"
-#include "iCBSearch.h"
-#include "gainquant.h"
-#include "createCB.h"
-#include "filter.h"
-#include "constants.h"
-
-/*----------------------------------------------------------------*
- * Search routine for codebook encoding and gain quantization.
- *---------------------------------------------------------------*/
-
-void iCBSearch(
- iLBC_Enc_Inst_t *iLBCenc_inst,
- /* (i) the encoder state structure */
- int *index, /* (o) Codebook indices */
- int *gain_index,/* (o) Gain quantization indices */
- float *intarget,/* (i) Target vector for encoding */
- float *mem, /* (i) Buffer for codebook construction */
- int lMem, /* (i) Length of buffer */
- int lTarget, /* (i) Length of vector */
- int nStages, /* (i) Number of codebook stages */
- float *weightDenum, /* (i) weighting filter coefficients */
- float *weightState, /* (i) weighting filter state */
- int block /* (i) the sub-block number */
-){
- int i, j, icount, stage, best_index, range, counter;
- float max_measure, gain, measure, crossDot, ftmp;
- float gains[CB_NSTAGES];
- float target[SUBL];
- int base_index, sInd, eInd, base_size;
- int sIndAug=0, eIndAug=0;
- float buf[CB_MEML+SUBL+2*LPC_FILTERORDER];
-
-
- float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128];
- float *pp, *ppi=0, *ppo=0, *ppe=0;
- float cbvectors[CB_MEML];
- float tene, cene, cvec[SUBL];
- float aug_vec[SUBL];
-
- memset(cvec,0,SUBL*sizeof(float));
-
- /* Determine size of codebook sections */
-
- base_size=lMem-lTarget+1;
-
- if (lTarget==SUBL) {
- base_size=lMem-lTarget+1+lTarget/2;
- }
-
- /* setup buffer for weighting */
-
- memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER);
- memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float));
- memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float));
-
- /* weighting */
-
- AllPoleFilter(buf+LPC_FILTERORDER, weightDenum,
- lMem+lTarget, LPC_FILTERORDER);
-
- /* Construct the codebook and target needed */
-
- memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float));
-
- tene=0.0;
- for (i=0; i<lTarget; i++) {
- tene+=target[i]*target[i];
- }
-
- /* Prepare search over one more codebook section. This section
- is created by filtering the original buffer with a filter. */
-
- filteredCBvecs(cbvectors, buf+LPC_FILTERORDER, lMem);
-
- /* The Main Loop over stages */
-
- for (stage=0; stage<nStages; stage++) {
-
- range = search_rangeTbl[block][stage];
-
- /* initialize search measure */
-
- max_measure = (float)-10000000.0;
- gain = (float)0.0;
- best_index = 0;
-
- /* Compute cross dot product between the target
-
-
- and the CB memory */
-
- crossDot=0.0;
- pp=buf+LPC_FILTERORDER+lMem-lTarget;
- for (j=0; j<lTarget; j++) {
- crossDot += target[j]*(*pp++);
- }
-
- if (stage==0) {
-
- /* Calculate energy in the first block of
- 'lTarget' sampels. */
- ppe = energy;
- ppi = buf+LPC_FILTERORDER+lMem-lTarget-1;
- ppo = buf+LPC_FILTERORDER+lMem-1;
-
- *ppe=0.0;
- pp=buf+LPC_FILTERORDER+lMem-lTarget;
- for (j=0; j<lTarget; j++) {
- *ppe+=(*pp)*(*pp);
- pp++;
- }
-
- if (*ppe>0.0) {
- invenergy[0] = (float) 1.0 / (*ppe + EPS);
- } else {
- invenergy[0] = (float) 0.0;
- }
- ppe++;
-
- measure=(float)-10000000.0;
-
- if (crossDot > 0.0) {
- measure = crossDot*crossDot*invenergy[0];
- }
- }
- else {
- measure = crossDot*crossDot*invenergy[0];
- }
-
- /* check if measure is better */
- ftmp = crossDot*invenergy[0];
-
- if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
- best_index = 0;
- max_measure = measure;
- gain = ftmp;
- }
-
- /* loop over the main first codebook section,
- full search */
-
- for (icount=1; icount<range; icount++) {
-
- /* calculate measure */
-
-
-
- crossDot=0.0;
- pp = buf+LPC_FILTERORDER+lMem-lTarget-icount;
-
- for (j=0; j<lTarget; j++) {
- crossDot += target[j]*(*pp++);
- }
-
- if (stage==0) {
- *ppe++ = energy[icount-1] + (*ppi)*(*ppi) -
- (*ppo)*(*ppo);
- ppo--;
- ppi--;
-
- if (energy[icount]>0.0) {
- invenergy[icount] =
- (float)1.0/(energy[icount]+EPS);
- } else {
- invenergy[icount] = (float) 0.0;
- }
-
- measure=(float)-10000000.0;
-
- if (crossDot > 0.0) {
- measure = crossDot*crossDot*invenergy[icount];
- }
- }
- else {
- measure = crossDot*crossDot*invenergy[icount];
- }
-
- /* check if measure is better */
- ftmp = crossDot*invenergy[icount];
-
- if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
- best_index = icount;
- max_measure = measure;
- gain = ftmp;
- }
- }
-
- /* Loop over augmented part in the first codebook
- * section, full search.
- * The vectors are interpolated.
- */
-
- if (lTarget==SUBL) {
-
- /* Search for best possible cb vector and
- compute the CB-vectors' energy. */
- searchAugmentedCB(20, 39, stage, base_size-lTarget/2,
- target, buf+LPC_FILTERORDER+lMem,
- &max_measure, &best_index, &gain, energy,
- invenergy);
-
-
- }
-
- /* set search range for following codebook sections */
-
- base_index=best_index;
-
- /* unrestricted search */
-
- if (CB_RESRANGE == -1) {
- sInd=0;
- eInd=range-1;
- sIndAug=20;
- eIndAug=39;
- }
-
- /* restriced search around best index from first
- codebook section */
-
- else {
- /* Initialize search indices */
- sIndAug=0;
- eIndAug=0;
- sInd=base_index-CB_RESRANGE/2;
- eInd=sInd+CB_RESRANGE;
-
- if (lTarget==SUBL) {
-
- if (sInd<0) {
-
- sIndAug = 40 + sInd;
- eIndAug = 39;
- sInd=0;
-
- } else if ( base_index < (base_size-20) ) {
-
- if (eInd > range) {
- sInd -= (eInd-range);
- eInd = range;
- }
- } else { /* base_index >= (base_size-20) */
-
- if (sInd < (base_size-20)) {
- sIndAug = 20;
- sInd = 0;
- eInd = 0;
- eIndAug = 19 + CB_RESRANGE;
-
- if(eIndAug > 39) {
- eInd = eIndAug-39;
- eIndAug = 39;
- }
- } else {
- sIndAug = 20 + sInd - (base_size-20);
- eIndAug = 39;
-
-
- sInd = 0;
- eInd = CB_RESRANGE - (eIndAug-sIndAug+1);
- }
- }
-
- } else { /* lTarget = 22 or 23 */
-
- if (sInd < 0) {
- eInd -= sInd;
- sInd = 0;
- }
-
- if(eInd > range) {
- sInd -= (eInd - range);
- eInd = range;
- }
- }
- }
-
- /* search of higher codebook section */
-
- /* index search range */
- counter = sInd;
- sInd += base_size;
- eInd += base_size;
-
-
- if (stage==0) {
- ppe = energy+base_size;
- *ppe=0.0;
-
- pp=cbvectors+lMem-lTarget;
- for (j=0; j<lTarget; j++) {
- *ppe+=(*pp)*(*pp);
- pp++;
- }
-
- ppi = cbvectors + lMem - 1 - lTarget;
- ppo = cbvectors + lMem - 1;
-
- for (j=0; j<(range-1); j++) {
- *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo);
- ppo--;
- ppi--;
- ppe++;
- }
- }
-
- /* loop over search range */
-
- for (icount=sInd; icount<eInd; icount++) {
-
- /* calculate measure */
-
- crossDot=0.0;
-
-
- pp=cbvectors + lMem - (counter++) - lTarget;
-
- for (j=0;j<lTarget;j++) {
- crossDot += target[j]*(*pp++);
- }
-
- if (energy[icount]>0.0) {
- invenergy[icount] =(float)1.0/(energy[icount]+EPS);
- } else {
- invenergy[icount] =(float)0.0;
- }
-
- if (stage==0) {
-
- measure=(float)-10000000.0;
-
- if (crossDot > 0.0) {
- measure = crossDot*crossDot*
- invenergy[icount];
- }
- }
- else {
- measure = crossDot*crossDot*invenergy[icount];
- }
-
- /* check if measure is better */
- ftmp = crossDot*invenergy[icount];
-
- if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
- best_index = icount;
- max_measure = measure;
- gain = ftmp;
- }
- }
-
- /* Search the augmented CB inside the limited range. */
-
- if ((lTarget==SUBL)&&(sIndAug!=0)) {
- searchAugmentedCB(sIndAug, eIndAug, stage,
- 2*base_size-20, target, cbvectors+lMem,
- &max_measure, &best_index, &gain, energy,
- invenergy);
- }
-
- /* record best index */
-
- index[stage] = best_index;
-
- /* gain quantization */
-
- if (stage==0){
-
- if (gain<0.0){
- gain = 0.0;
-
-
- }
-
- if (gain>CB_MAXGAIN) {
- gain = (float)CB_MAXGAIN;
- }
- gain = gainquant(gain, 1.0, 32, &gain_index[stage]);
- }
- else {
- if (stage==1) {
- gain = gainquant(gain, (float)fabs(gains[stage-1]),
- 16, &gain_index[stage]);
- } else {
- gain = gainquant(gain, (float)fabs(gains[stage-1]),
- 8, &gain_index[stage]);
- }
- }
-
- /* Extract the best (according to measure)
- codebook vector */
-
- if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) {
-
- if (index[stage]<base_size) {
- pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage];
- } else {
- pp=cbvectors+lMem-lTarget-
- index[stage]+base_size;
- }
- } else {
-
- if (index[stage]<base_size) {
- if (index[stage]<(base_size-20)) {
- pp=buf+LPC_FILTERORDER+lMem-
- lTarget-index[stage];
- } else {
- createAugmentedVec(index[stage]-base_size+40,
- buf+LPC_FILTERORDER+lMem,aug_vec);
- pp=aug_vec;
- }
- } else {
- int filterno, position;
-
- filterno=index[stage]/base_size;
- position=index[stage]-filterno*base_size;
-
-
- if (position<(base_size-20)) {
- pp=cbvectors+filterno*lMem-lTarget-
- index[stage]+filterno*base_size;
- } else {
- createAugmentedVec(
- index[stage]-(filterno+1)*base_size+40,
- cbvectors+filterno*lMem,aug_vec);
- pp=aug_vec;
-
-
- }
- }
- }
-
- /* Subtract the best codebook vector, according
- to measure, from the target vector */
-
- for (j=0;j<lTarget;j++) {
- cvec[j] += gain*(*pp);
- target[j] -= gain*(*pp++);
- }
-
- /* record quantized gain */
-
- gains[stage]=gain;
-
- }/* end of Main Loop. for (stage=0;... */
-
- /* Gain adjustment for energy matching */
- cene=0.0;
- for (i=0; i<lTarget; i++) {
- cene+=cvec[i]*cvec[i];
- }
- j=gain_index[0];
-
- for (i=gain_index[0]; i<32; i++) {
- ftmp=cene*gain_sq5Tbl[i]*gain_sq5Tbl[i];
-
- if ((ftmp<(tene*gains[0]*gains[0])) &&
- (gain_sq5Tbl[j]<(2.0*gains[0]))) {
- j=i;
- }
- }
- gain_index[0]=j;
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/iCBSearch.h b/1.2-netsec/codecs/ilbc/iCBSearch.h
deleted file mode 100644
index 989f6ec03..000000000
--- a/1.2-netsec/codecs/ilbc/iCBSearch.h
+++ /dev/null
@@ -1,35 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- iCBSearch.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_ICBSEARCH_H
-#define __iLBC_ICBSEARCH_H
-
-void iCBSearch(
- iLBC_Enc_Inst_t *iLBCenc_inst,
- /* (i) the encoder state structure */
- int *index, /* (o) Codebook indices */
- int *gain_index,/* (o) Gain quantization indices */
- float *intarget,/* (i) Target vector for encoding */
- float *mem, /* (i) Buffer for codebook construction */
- int lMem, /* (i) Length of buffer */
- int lTarget, /* (i) Length of vector */
- int nStages, /* (i) Number of codebook stages */
- float *weightDenum, /* (i) weighting filter coefficients */
-
-
- float *weightState, /* (i) weighting filter state */
- int block /* (i) the sub-block number */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/iLBC_decode.c b/1.2-netsec/codecs/ilbc/iLBC_decode.c
deleted file mode 100644
index 22bfff792..000000000
--- a/1.2-netsec/codecs/ilbc/iLBC_decode.c
+++ /dev/null
@@ -1,619 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- iLBC_decode.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-#include <stdlib.h>
-
-#include "iLBC_define.h"
-#include "iLBC_decode.h"
-#include "StateConstructW.h"
-#include "LPCdecode.h"
-#include "iCBConstruct.h"
-#include "doCPLC.h"
-#include "helpfun.h"
-#include "constants.h"
-#include "packing.h"
-#include "string.h"
-#include "enhancer.h"
-#include "hpOutput.h"
-#include "syntFilter.h"
-
-/*----------------------------------------------------------------*
- * Initiation of decoder instance.
- *---------------------------------------------------------------*/
-
-short initDecode( /* (o) Number of decoded
- samples */
- iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */
- int mode, /* (i) frame size mode */
- int use_enhancer /* (i) 1 to use enhancer
- 0 to run without
- enhancer */
-){
- int i;
-
- iLBCdec_inst->mode = mode;
-
- if (mode==30) {
- iLBCdec_inst->blockl = BLOCKL_30MS;
- iLBCdec_inst->nsub = NSUB_30MS;
- iLBCdec_inst->nasub = NASUB_30MS;
- iLBCdec_inst->lpc_n = LPC_N_30MS;
-
-
- iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;
- iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;
- iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS;
- /* ULP init */
- iLBCdec_inst->ULP_inst=&ULP_30msTbl;
- }
- else if (mode==20) {
- iLBCdec_inst->blockl = BLOCKL_20MS;
- iLBCdec_inst->nsub = NSUB_20MS;
- iLBCdec_inst->nasub = NASUB_20MS;
- iLBCdec_inst->lpc_n = LPC_N_20MS;
- iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;
- iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;
- iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS;
- /* ULP init */
- iLBCdec_inst->ULP_inst=&ULP_20msTbl;
- }
- else {
- exit(2);
- }
-
- memset(iLBCdec_inst->syntMem, 0,
- LPC_FILTERORDER*sizeof(float));
- memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl,
- LPC_FILTERORDER*sizeof(float));
-
- memset(iLBCdec_inst->old_syntdenum, 0,
- ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float));
- for (i=0; i<NSUB_MAX; i++)
- iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0;
-
- iLBCdec_inst->last_lag = 20;
-
- iLBCdec_inst->prevLag = 120;
- iLBCdec_inst->per = 0.0;
- iLBCdec_inst->consPLICount = 0;
- iLBCdec_inst->prevPLI = 0;
- iLBCdec_inst->prevLpc[0] = 1.0;
- memset(iLBCdec_inst->prevLpc+1,0,
- LPC_FILTERORDER*sizeof(float));
- memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float));
- iLBCdec_inst->seed=777;
-
- memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));
-
- iLBCdec_inst->use_enhancer = use_enhancer;
- memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));
- for (i=0;i<ENH_NBLOCKS_TOT;i++)
- iLBCdec_inst->enh_period[i]=(float)40.0;
-
- iLBCdec_inst->prev_enh_pl = 0;
-
- return (iLBCdec_inst->blockl);
-}
-
-
-
-/*----------------------------------------------------------------*
- * frame residual decoder function (subrutine to iLBC_decode)
- *---------------------------------------------------------------*/
-
-static void Decode(
- iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state
- structure */
- float *decresidual, /* (o) decoded residual frame */
- int start, /* (i) location of start
- state */
- int idxForMax, /* (i) codebook index for the
- maximum value */
- int *idxVec, /* (i) codebook indexes for the
- samples in the start
- state */
- float *syntdenum, /* (i) the decoded synthesis
- filter coefficients */
- int *cb_index, /* (i) the indexes for the
- adaptive codebook */
- int *gain_index, /* (i) the indexes for the
- corresponding gains */
- int *extra_cb_index, /* (i) the indexes for the
- adaptive codebook part
- of start state */
- int *extra_gain_index, /* (i) the indexes for the
- corresponding gains */
- int state_first /* (i) 1 if non adaptive part
- of start state comes
- first 0 if that part
- comes last */
-){
- float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];
- int k, meml_gotten, Nfor, Nback, i;
- int diff, start_pos;
- int subcount, subframe;
-
- diff = STATE_LEN - iLBCdec_inst->state_short_len;
-
- if (state_first == 1) {
- start_pos = (start-1)*SUBL;
- } else {
- start_pos = (start-1)*SUBL + diff;
- }
-
- /* decode scalar part of start state */
-
- StateConstructW(idxForMax, idxVec,
- &syntdenum[(start-1)*(LPC_FILTERORDER+1)],
- &decresidual[start_pos], iLBCdec_inst->state_short_len);
-
-
- if (state_first) { /* put adaptive part in the end */
-
-
-
- /* setup memory */
-
- memset(mem, 0,
- (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float));
- memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len,
- decresidual+start_pos,
- iLBCdec_inst->state_short_len*sizeof(float));
-
- /* construct decoded vector */
-
- iCBConstruct(
- &decresidual[start_pos+iLBCdec_inst->state_short_len],
- extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl,
- stMemLTbl, diff, CB_NSTAGES);
-
- }
- else {/* put adaptive part in the beginning */
-
- /* create reversed vectors for prediction */
-
- for (k=0; k<diff; k++) {
- reverseDecresidual[k] =
- decresidual[(start+1)*SUBL-1-
- (k+iLBCdec_inst->state_short_len)];
- }
-
- /* setup memory */
-
- meml_gotten = iLBCdec_inst->state_short_len;
- for (k=0; k<meml_gotten; k++){
- mem[CB_MEML-1-k] = decresidual[start_pos + k];
- }
- memset(mem, 0, (CB_MEML-k)*sizeof(float));
-
- /* construct decoded vector */
-
- iCBConstruct(reverseDecresidual, extra_cb_index,
- extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,
- diff, CB_NSTAGES);
-
- /* get decoded residual from reversed vector */
-
- for (k=0; k<diff; k++) {
- decresidual[start_pos-1-k] = reverseDecresidual[k];
- }
- }
-
- /* counter for predicted sub-frames */
-
- subcount=0;
-
- /* forward prediction of sub-frames */
-
- Nfor = iLBCdec_inst->nsub-start-1;
-
-
-
- if ( Nfor > 0 ){
-
- /* setup memory */
-
- memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));
- memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,
- STATE_LEN*sizeof(float));
-
- /* loop over sub-frames to encode */
-
- for (subframe=0; subframe<Nfor; subframe++) {
-
- /* construct decoded vector */
-
- iCBConstruct(&decresidual[(start+1+subframe)*SUBL],
- cb_index+subcount*CB_NSTAGES,
- gain_index+subcount*CB_NSTAGES,
- mem+CB_MEML-memLfTbl[subcount],
- memLfTbl[subcount], SUBL, CB_NSTAGES);
-
- /* update memory */
-
- memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
- memcpy(mem+CB_MEML-SUBL,
- &decresidual[(start+1+subframe)*SUBL],
- SUBL*sizeof(float));
-
- subcount++;
-
- }
-
- }
-
- /* backward prediction of sub-frames */
-
- Nback = start-1;
-
- if ( Nback > 0 ) {
-
- /* setup memory */
-
- meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start);
-
- if ( meml_gotten > CB_MEML ) {
- meml_gotten=CB_MEML;
- }
- for (k=0; k<meml_gotten; k++) {
- mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];
- }
- memset(mem, 0, (CB_MEML-k)*sizeof(float));
-
- /* loop over subframes to decode */
-
-
-
- for (subframe=0; subframe<Nback; subframe++) {
-
- /* construct decoded vector */
-
- iCBConstruct(&reverseDecresidual[subframe*SUBL],
- cb_index+subcount*CB_NSTAGES,
- gain_index+subcount*CB_NSTAGES,
- mem+CB_MEML-memLfTbl[subcount], memLfTbl[subcount],
- SUBL, CB_NSTAGES);
-
- /* update memory */
-
- memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
- memcpy(mem+CB_MEML-SUBL,
- &reverseDecresidual[subframe*SUBL],
- SUBL*sizeof(float));
-
- subcount++;
- }
-
- /* get decoded residual from reversed vector */
-
- for (i=0; i<SUBL*Nback; i++)
- decresidual[SUBL*Nback - i - 1] =
- reverseDecresidual[i];
- }
-}
-
-/*----------------------------------------------------------------*
- * main decoder function
- *---------------------------------------------------------------*/
-
-void iLBC_decode(
- float *decblock, /* (o) decoded signal block */
- unsigned char *bytes, /* (i) encoded signal bits */
- iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state
- structure */
- int mode /* (i) 0: bad packet, PLC,
- 1: normal */
-){
- float data[BLOCKL_MAX];
- float lsfdeq[LPC_FILTERORDER*LPC_N_MAX];
- float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1];
- float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1];
- int k, i, start, idxForMax, pos, lastpart, ulp;
- int lag, ilag;
- float cc, maxcc;
- int idxVec[STATE_LEN];
- int check;
- int gain_index[NASUB_MAX*CB_NSTAGES],
- extra_gain_index[CB_NSTAGES];
- int cb_index[CB_NSTAGES*NASUB_MAX], extra_cb_index[CB_NSTAGES];
- int lsf_i[LSF_NSPLIT*LPC_N_MAX];
- int state_first;
-
-
- int last_bit;
- unsigned char *pbytes;
- float weightdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];
- int order_plus_one;
- float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
- float decresidual[BLOCKL_MAX];
-
- if (mode>0) { /* the data are good */
-
- /* decode data */
-
- pbytes=bytes;
- pos=0;
-
- /* Set everything to zero before decoding */
-
- for (k=0; k<LSF_NSPLIT*LPC_N_MAX; k++) {
- lsf_i[k]=0;
- }
- start=0;
- state_first=0;
- idxForMax=0;
- for (k=0; k<iLBCdec_inst->state_short_len; k++) {
- idxVec[k]=0;
- }
- for (k=0; k<CB_NSTAGES; k++) {
- extra_cb_index[k]=0;
- }
- for (k=0; k<CB_NSTAGES; k++) {
- extra_gain_index[k]=0;
- }
- for (i=0; i<iLBCdec_inst->nasub; i++) {
- for (k=0; k<CB_NSTAGES; k++) {
- cb_index[i*CB_NSTAGES+k]=0;
- }
- }
- for (i=0; i<iLBCdec_inst->nasub; i++) {
- for (k=0; k<CB_NSTAGES; k++) {
- gain_index[i*CB_NSTAGES+k]=0;
- }
- }
-
- /* loop over ULP classes */
-
- for (ulp=0; ulp<3; ulp++) {
-
- /* LSF */
- for (k=0; k<LSF_NSPLIT*iLBCdec_inst->lpc_n; k++){
- unpack( &pbytes, &lastpart,
- iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos);
- packcombine(&lsf_i[k], lastpart,
- iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]);
- }
-
-
-
- /* Start block info */
-
- unpack( &pbytes, &lastpart,
- iLBCdec_inst->ULP_inst->start_bits[ulp], &pos);
- packcombine(&start, lastpart,
- iLBCdec_inst->ULP_inst->start_bits[ulp]);
-
- unpack( &pbytes, &lastpart,
- iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos);
- packcombine(&state_first, lastpart,
- iLBCdec_inst->ULP_inst->startfirst_bits[ulp]);
-
- unpack( &pbytes, &lastpart,
- iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos);
- packcombine(&idxForMax, lastpart,
- iLBCdec_inst->ULP_inst->scale_bits[ulp]);
-
- for (k=0; k<iLBCdec_inst->state_short_len; k++) {
- unpack( &pbytes, &lastpart,
- iLBCdec_inst->ULP_inst->state_bits[ulp], &pos);
- packcombine(idxVec+k, lastpart,
- iLBCdec_inst->ULP_inst->state_bits[ulp]);
- }
-
- /* 23/22 (20ms/30ms) sample block */
-
- for (k=0; k<CB_NSTAGES; k++) {
- unpack( &pbytes, &lastpart,
- iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp],
- &pos);
- packcombine(extra_cb_index+k, lastpart,
- iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]);
- }
- for (k=0; k<CB_NSTAGES; k++) {
- unpack( &pbytes, &lastpart,
- iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp],
- &pos);
- packcombine(extra_gain_index+k, lastpart,
- iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]);
- }
-
- /* The two/four (20ms/30ms) 40 sample sub-blocks */
-
- for (i=0; i<iLBCdec_inst->nasub; i++) {
- for (k=0; k<CB_NSTAGES; k++) {
- unpack( &pbytes, &lastpart,
- iLBCdec_inst->ULP_inst->cb_index[i][k][ulp],
- &pos);
- packcombine(cb_index+i*CB_NSTAGES+k, lastpart,
- iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]);
- }
- }
-
- for (i=0; i<iLBCdec_inst->nasub; i++) {
-
-
- for (k=0; k<CB_NSTAGES; k++) {
- unpack( &pbytes, &lastpart,
-
- iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp],
- &pos);
- packcombine(gain_index+i*CB_NSTAGES+k, lastpart,
- iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]);
- }
- }
- }
- /* Extract last bit. If it is 1 this indicates an
- empty/lost frame */
- unpack( &pbytes, &last_bit, 1, &pos);
-
- /* Check for bit errors or empty/lost frames */
- if (start<1)
- mode = 0;
- if (iLBCdec_inst->mode==20 && start>3)
- mode = 0;
- if (iLBCdec_inst->mode==30 && start>5)
- mode = 0;
- if (last_bit==1)
- mode = 0;
-
- if (mode==1) { /* No bit errors was detected,
- continue decoding */
-
- /* adjust index */
- index_conv_dec(cb_index);
-
- /* decode the lsf */
-
- SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n);
- check=LSF_check(lsfdeq, LPC_FILTERORDER,
- iLBCdec_inst->lpc_n);
- DecoderInterpolateLSF(syntdenum, weightdenum,
- lsfdeq, LPC_FILTERORDER, iLBCdec_inst);
-
- Decode(iLBCdec_inst, decresidual, start, idxForMax,
- idxVec, syntdenum, cb_index, gain_index,
- extra_cb_index, extra_gain_index,
- state_first);
-
- /* preparing the plc for a future loss! */
-
- doThePLC(PLCresidual, PLClpc, 0, decresidual,
- syntdenum +
- (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1),
- (*iLBCdec_inst).last_lag, iLBCdec_inst);
-
-
- memcpy(decresidual, PLCresidual,
- iLBCdec_inst->blockl*sizeof(float));
- }
-
-
-
- }
-
- if (mode == 0) {
- /* the data is bad (either a PLC call
- * was made or a severe bit error was detected)
- */
-
- /* packet loss conceal */
-
- memset(zeros, 0, BLOCKL_MAX*sizeof(float));
-
- one[0] = 1;
- memset(one+1, 0, LPC_FILTERORDER*sizeof(float));
-
- start=0;
-
- doThePLC(PLCresidual, PLClpc, 1, zeros, one,
- (*iLBCdec_inst).last_lag, iLBCdec_inst);
- memcpy(decresidual, PLCresidual,
- iLBCdec_inst->blockl*sizeof(float));
-
- order_plus_one = LPC_FILTERORDER + 1;
- for (i = 0; i < iLBCdec_inst->nsub; i++) {
- memcpy(syntdenum+(i*order_plus_one), PLClpc,
- order_plus_one*sizeof(float));
- }
- }
-
- if (iLBCdec_inst->use_enhancer == 1) {
-
- /* post filtering */
-
- iLBCdec_inst->last_lag =
- enhancerInterface(data, decresidual, iLBCdec_inst);
-
- /* synthesis filtering */
-
- if (iLBCdec_inst->mode==20) {
- /* Enhancer has 40 samples delay */
- i=0;
- syntFilter(data + i*SUBL,
- iLBCdec_inst->old_syntdenum +
- (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1),
- SUBL, iLBCdec_inst->syntMem);
- for (i=1; i < iLBCdec_inst->nsub; i++) {
- syntFilter(data + i*SUBL,
- syntdenum + (i-1)*(LPC_FILTERORDER+1),
- SUBL, iLBCdec_inst->syntMem);
- }
- } else if (iLBCdec_inst->mode==30) {
- /* Enhancer has 80 samples delay */
- for (i=0; i < 2; i++) {
- syntFilter(data + i*SUBL,
-
-
- iLBCdec_inst->old_syntdenum +
- (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1),
- SUBL, iLBCdec_inst->syntMem);
- }
- for (i=2; i < iLBCdec_inst->nsub; i++) {
- syntFilter(data + i*SUBL,
- syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL,
- iLBCdec_inst->syntMem);
- }
- }
-
- } else {
-
- /* Find last lag */
- lag = 20;
- maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL],
- &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL);
-
- for (ilag=21; ilag<120; ilag++) {
- cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL],
- &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag],
- ENH_BLOCKL);
-
- if (cc > maxcc) {
- maxcc = cc;
- lag = ilag;
- }
- }
- iLBCdec_inst->last_lag = lag;
-
- /* copy data and run synthesis filter */
-
- memcpy(data, decresidual,
- iLBCdec_inst->blockl*sizeof(float));
- for (i=0; i < iLBCdec_inst->nsub; i++) {
- syntFilter(data + i*SUBL,
- syntdenum + i*(LPC_FILTERORDER+1), SUBL,
- iLBCdec_inst->syntMem);
- }
- }
-
- /* high pass filtering on output if desired, otherwise
- copy to out */
-
- hpOutput(data, iLBCdec_inst->blockl,
- decblock,iLBCdec_inst->hpomem);
-
- /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/
-
- memcpy(iLBCdec_inst->old_syntdenum, syntdenum,
-
- iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float));
-
- iLBCdec_inst->prev_enh_pl=0;
-
-
-
- if (mode==0) { /* PLC was used */
- iLBCdec_inst->prev_enh_pl=1;
- }
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/iLBC_decode.h b/1.2-netsec/codecs/ilbc/iLBC_decode.h
deleted file mode 100644
index 0d5c905cd..000000000
--- a/1.2-netsec/codecs/ilbc/iLBC_decode.h
+++ /dev/null
@@ -1,40 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- iLBC_decode.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_ILBCDECODE_H
-#define __iLBC_ILBCDECODE_H
-
-#include "iLBC_define.h"
-
-short initDecode( /* (o) Number of decoded
- samples */
- iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */
- int mode, /* (i) frame size mode */
- int use_enhancer /* (i) 1 to use enhancer
- 0 to run without
- enhancer */
-);
-
-void iLBC_decode(
- float *decblock, /* (o) decoded signal block */
- unsigned char *bytes, /* (i) encoded signal bits */
- iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state
- structure */
- int mode /* (i) 0: bad packet, PLC,
- 1: normal */
-);
-
-
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/iLBC_define.h b/1.2-netsec/codecs/ilbc/iLBC_define.h
deleted file mode 100644
index 73a90ed66..000000000
--- a/1.2-netsec/codecs/ilbc/iLBC_define.h
+++ /dev/null
@@ -1,201 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- iLBC_define.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-#include <string.h>
-
-#ifndef __iLBC_ILBCDEFINE_H
-#define __iLBC_ILBCDEFINE_H
-
-/* general codec settings */
-
-#define FS (float)8000.0
-#define BLOCKL_20MS 160
-#define BLOCKL_30MS 240
-#define BLOCKL_MAX 240
-#define NSUB_20MS 4
-#define NSUB_30MS 6
-#define NSUB_MAX 6
-#define NASUB_20MS 2
-#define NASUB_30MS 4
-#define NASUB_MAX 4
-#define SUBL 40
-#define STATE_LEN 80
-#define STATE_SHORT_LEN_30MS 58
-#define STATE_SHORT_LEN_20MS 57
-
-/* LPC settings */
-
-#define LPC_FILTERORDER 10
-#define LPC_CHIRP_SYNTDENUM (float)0.9025
-#define LPC_CHIRP_WEIGHTDENUM (float)0.4222
-#define LPC_LOOKBACK 60
-#define LPC_N_20MS 1
-#define LPC_N_30MS 2
-#define LPC_N_MAX 2
-#define LPC_ASYMDIFF 20
-#define LPC_BW (float)60.0
-#define LPC_WN (float)1.0001
-#define LSF_NSPLIT 3
-
-#define LSF_NUMBER_OF_STEPS 4
-#define LPC_HALFORDER (LPC_FILTERORDER/2)
-
-/* cb settings */
-
-#define CB_NSTAGES 3
-#define CB_EXPAND 2
-#define CB_MEML 147
-#define CB_FILTERLEN 2*4
-#define CB_HALFFILTERLEN 4
-#define CB_RESRANGE 34
-#define CB_MAXGAIN (float)1.3
-
-/* enhancer */
-
-#define ENH_BLOCKL 80 /* block length */
-#define ENH_BLOCKL_HALF (ENH_BLOCKL/2)
-#define ENH_HL 3 /* 2*ENH_HL+1 is number blocks
- in said second sequence */
-#define ENH_SLOP 2 /* max difference estimated and
- correct pitch period */
-#define ENH_PLOCSL 20 /* pitch-estimates and pitch-
- locations buffer length */
-#define ENH_OVERHANG 2
-#define ENH_UPS0 4 /* upsampling rate */
-#define ENH_FL0 3 /* 2*FLO+1 is the length of
- each filter */
-#define ENH_VECTL (ENH_BLOCKL+2*ENH_FL0)
-#define ENH_CORRDIM (2*ENH_SLOP+1)
-#define ENH_NBLOCKS (BLOCKL_MAX/ENH_BLOCKL)
-#define ENH_NBLOCKS_EXTRA 5
-#define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS +
- ENH_NBLOCKS_EXTRA */
-#define ENH_BUFL (ENH_NBLOCKS_TOT)*ENH_BLOCKL
-#define ENH_ALPHA0 (float)0.05
-
-/* Down sampling */
-
-#define FILTERORDER_DS 7
-#define DELAY_DS 3
-#define FACTOR_DS 2
-
-/* bit stream defs */
-
-#define NO_OF_BYTES_20MS 38
-#define NO_OF_BYTES_30MS 50
-#define NO_OF_WORDS_20MS 19
-#define NO_OF_WORDS_30MS 25
-#define STATE_BITS 3
-#define BYTE_LEN 8
-#define ULP_CLASSES 3
-
-/* help parameters */
-
-
-#define FLOAT_MAX (float)1.0e37
-#define EPS (float)2.220446049250313e-016
-#define PI (float)3.14159265358979323846
-#define MIN_SAMPLE -32768
-#define MAX_SAMPLE 32767
-#define TWO_PI (float)6.283185307
-#define PI2 (float)0.159154943
-
-/* type definition encoder instance */
-typedef struct iLBC_ULP_Inst_t_ {
- int lsf_bits[6][ULP_CLASSES+2];
- int start_bits[ULP_CLASSES+2];
- int startfirst_bits[ULP_CLASSES+2];
- int scale_bits[ULP_CLASSES+2];
- int state_bits[ULP_CLASSES+2];
- int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2];
- int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2];
- int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
- int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
-} iLBC_ULP_Inst_t;
-
-/* type definition encoder instance */
-typedef struct iLBC_Enc_Inst_t_ {
-
- /* flag for frame size mode */
- int mode;
-
- /* basic parameters for different frame sizes */
- int blockl;
- int nsub;
- int nasub;
- int no_of_bytes, no_of_words;
- int lpc_n;
- int state_short_len;
- const iLBC_ULP_Inst_t *ULP_inst;
-
- /* analysis filter state */
- float anaMem[LPC_FILTERORDER];
-
- /* old lsf parameters for interpolation */
- float lsfold[LPC_FILTERORDER];
- float lsfdeqold[LPC_FILTERORDER];
-
- /* signal buffer for LP analysis */
- float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];
-
- /* state of input HP filter */
- float hpimem[4];
-
-} iLBC_Enc_Inst_t;
-
-/* type definition decoder instance */
-typedef struct iLBC_Dec_Inst_t_ {
-
-
- /* flag for frame size mode */
- int mode;
-
- /* basic parameters for different frame sizes */
- int blockl;
- int nsub;
- int nasub;
- int no_of_bytes, no_of_words;
- int lpc_n;
- int state_short_len;
- const iLBC_ULP_Inst_t *ULP_inst;
-
- /* synthesis filter state */
- float syntMem[LPC_FILTERORDER];
-
- /* old LSF for interpolation */
- float lsfdeqold[LPC_FILTERORDER];
-
- /* pitch lag estimated in enhancer and used in PLC */
- int last_lag;
-
- /* PLC state information */
- int prevLag, consPLICount, prevPLI, prev_enh_pl;
- float prevLpc[LPC_FILTERORDER+1];
- float prevResidual[NSUB_MAX*SUBL];
- float per;
- unsigned long seed;
-
- /* previous synthesis filter parameters */
- float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];
-
- /* state of output HP filter */
- float hpomem[4];
-
- /* enhancer state information */
- int use_enhancer;
- float enh_buf[ENH_BUFL];
- float enh_period[ENH_NBLOCKS_TOT];
-
-} iLBC_Dec_Inst_t;
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/iLBC_encode.c b/1.2-netsec/codecs/ilbc/iLBC_encode.c
deleted file mode 100644
index bd1496498..000000000
--- a/1.2-netsec/codecs/ilbc/iLBC_encode.c
+++ /dev/null
@@ -1,514 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- iLBC_encode.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "iLBC_define.h"
-#include "iLBC_encode.h"
-#include "LPCencode.h"
-#include "FrameClassify.h"
-#include "StateSearchW.h"
-#include "StateConstructW.h"
-#include "helpfun.h"
-#include "constants.h"
-#include "packing.h"
-#include "iCBSearch.h"
-#include "iCBConstruct.h"
-#include "hpInput.h"
-#include "anaFilter.h"
-#include "syntFilter.h"
-
-/*----------------------------------------------------------------*
- * Initiation of encoder instance.
- *---------------------------------------------------------------*/
-
-short initEncode( /* (o) Number of bytes
- encoded */
- iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */
- int mode /* (i) frame size mode */
-){
- iLBCenc_inst->mode = mode;
- if (mode==30) {
- iLBCenc_inst->blockl = BLOCKL_30MS;
- iLBCenc_inst->nsub = NSUB_30MS;
-
-
- iLBCenc_inst->nasub = NASUB_30MS;
- iLBCenc_inst->lpc_n = LPC_N_30MS;
- iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS;
- iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS;
- iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS;
- /* ULP init */
- iLBCenc_inst->ULP_inst=&ULP_30msTbl;
- }
- else if (mode==20) {
- iLBCenc_inst->blockl = BLOCKL_20MS;
- iLBCenc_inst->nsub = NSUB_20MS;
- iLBCenc_inst->nasub = NASUB_20MS;
- iLBCenc_inst->lpc_n = LPC_N_20MS;
- iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS;
- iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS;
- iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS;
- /* ULP init */
- iLBCenc_inst->ULP_inst=&ULP_20msTbl;
- }
- else {
- exit(2);
- }
-
- memset((*iLBCenc_inst).anaMem, 0,
- LPC_FILTERORDER*sizeof(float));
- memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl,
- LPC_FILTERORDER*sizeof(float));
- memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl,
- LPC_FILTERORDER*sizeof(float));
- memset((*iLBCenc_inst).lpc_buffer, 0,
- (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float));
- memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float));
-
- return (iLBCenc_inst->no_of_bytes);
-}
-
-/*----------------------------------------------------------------*
- * main encoder function
- *---------------------------------------------------------------*/
-
-void iLBC_encode(
- unsigned char *bytes, /* (o) encoded data bits iLBC */
- float *block, /* (o) speech vector to
- encode */
- iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder
- state */
-){
-
- float data[BLOCKL_MAX];
- float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX];
-
- int start, idxForMax, idxVec[STATE_LEN];
- float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];
- int n, k, meml_gotten, Nfor, Nback, i, pos;
-
-
- int gain_index[CB_NSTAGES*NASUB_MAX],
- extra_gain_index[CB_NSTAGES];
- int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES];
- int lsf_i[LSF_NSPLIT*LPC_N_MAX];
- unsigned char *pbytes;
- int diff, start_pos, state_first;
- float en1, en2;
- int index, ulp, firstpart;
- int subcount, subframe;
- float weightState[LPC_FILTERORDER];
- float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
- float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
- float decresidual[BLOCKL_MAX];
-
- /* high pass filtering of input signal if such is not done
- prior to calling this function */
-
- hpInput(block, iLBCenc_inst->blockl,
- data, (*iLBCenc_inst).hpimem);
-
- /* otherwise simply copy */
-
- /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/
-
- /* LPC of hp filtered input data */
-
- LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst);
-
-
- /* inverse filter to get residual */
-
- for (n=0; n<iLBCenc_inst->nsub; n++) {
- anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)],
- SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem);
- }
-
- /* find state location */
-
- start = FrameClassify(iLBCenc_inst, residual);
-
- /* check if state should be in first or last part of the
- two subframes */
-
- diff = STATE_LEN - iLBCenc_inst->state_short_len;
- en1 = 0;
- index = (start-1)*SUBL;
- for (i = 0; i < iLBCenc_inst->state_short_len; i++) {
- en1 += residual[index+i]*residual[index+i];
- }
- en2 = 0;
- index = (start-1)*SUBL+diff;
- for (i = 0; i < iLBCenc_inst->state_short_len; i++) {
- en2 += residual[index+i]*residual[index+i];
- }
-
-
-
-
- if (en1 > en2) {
- state_first = 1;
- start_pos = (start-1)*SUBL;
- } else {
- state_first = 0;
- start_pos = (start-1)*SUBL + diff;
- }
-
- /* scalar quantization of state */
-
- StateSearchW(iLBCenc_inst, &residual[start_pos],
- &syntdenum[(start-1)*(LPC_FILTERORDER+1)],
- &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax,
- idxVec, iLBCenc_inst->state_short_len, state_first);
-
- StateConstructW(idxForMax, idxVec,
- &syntdenum[(start-1)*(LPC_FILTERORDER+1)],
- &decresidual[start_pos], iLBCenc_inst->state_short_len);
-
- /* predictive quantization in state */
-
- if (state_first) { /* put adaptive part in the end */
-
- /* setup memory */
-
- memset(mem, 0,
- (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float));
- memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len,
- decresidual+start_pos,
- iLBCenc_inst->state_short_len*sizeof(float));
- memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
-
- /* encode sub-frames */
-
- iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index,
- &residual[start_pos+iLBCenc_inst->state_short_len],
- mem+CB_MEML-stMemLTbl,
- stMemLTbl, diff, CB_NSTAGES,
- &weightdenum[start*(LPC_FILTERORDER+1)],
- weightState, 0);
-
- /* construct decoded vector */
-
- iCBConstruct(
- &decresidual[start_pos+iLBCenc_inst->state_short_len],
- extra_cb_index, extra_gain_index,
- mem+CB_MEML-stMemLTbl,
- stMemLTbl, diff, CB_NSTAGES);
-
- }
- else { /* put adaptive part in the beginning */
-
-
-
- /* create reversed vectors for prediction */
-
- for (k=0; k<diff; k++) {
- reverseResidual[k] = residual[(start+1)*SUBL-1
- -(k+iLBCenc_inst->state_short_len)];
- }
-
- /* setup memory */
-
- meml_gotten = iLBCenc_inst->state_short_len;
- for (k=0; k<meml_gotten; k++) {
- mem[CB_MEML-1-k] = decresidual[start_pos + k];
- }
- memset(mem, 0, (CB_MEML-k)*sizeof(float));
- memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
-
- /* encode sub-frames */
-
- iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index,
- reverseResidual, mem+CB_MEML-stMemLTbl, stMemLTbl,
- diff, CB_NSTAGES,
- &weightdenum[(start-1)*(LPC_FILTERORDER+1)],
- weightState, 0);
-
- /* construct decoded vector */
-
- iCBConstruct(reverseDecresidual, extra_cb_index,
- extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,
- diff, CB_NSTAGES);
-
- /* get decoded residual from reversed vector */
-
- for (k=0; k<diff; k++) {
- decresidual[start_pos-1-k] = reverseDecresidual[k];
- }
- }
-
- /* counter for predicted sub-frames */
-
- subcount=0;
-
- /* forward prediction of sub-frames */
-
- Nfor = iLBCenc_inst->nsub-start-1;
-
-
- if ( Nfor > 0 ) {
-
- /* setup memory */
-
- memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));
- memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,
- STATE_LEN*sizeof(float));
- memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
-
-
-
- /* loop over sub-frames to encode */
-
- for (subframe=0; subframe<Nfor; subframe++) {
-
- /* encode sub-frame */
-
- iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES,
- gain_index+subcount*CB_NSTAGES,
- &residual[(start+1+subframe)*SUBL],
- mem+CB_MEML-memLfTbl[subcount],
- memLfTbl[subcount], SUBL, CB_NSTAGES,
- &weightdenum[(start+1+subframe)*
- (LPC_FILTERORDER+1)],
- weightState, subcount+1);
-
- /* construct decoded vector */
-
- iCBConstruct(&decresidual[(start+1+subframe)*SUBL],
- cb_index+subcount*CB_NSTAGES,
- gain_index+subcount*CB_NSTAGES,
- mem+CB_MEML-memLfTbl[subcount],
- memLfTbl[subcount], SUBL, CB_NSTAGES);
-
- /* update memory */
-
- memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
- memcpy(mem+CB_MEML-SUBL,
- &decresidual[(start+1+subframe)*SUBL],
- SUBL*sizeof(float));
- memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
-
- subcount++;
- }
- }
-
-
- /* backward prediction of sub-frames */
-
- Nback = start-1;
-
-
- if ( Nback > 0 ) {
-
- /* create reverse order vectors */
-
- for (n=0; n<Nback; n++) {
- for (k=0; k<SUBL; k++) {
- reverseResidual[n*SUBL+k] =
- residual[(start-1)*SUBL-1-n*SUBL-k];
- reverseDecresidual[n*SUBL+k] =
- decresidual[(start-1)*SUBL-1-n*SUBL-k];
- }
- }
-
-
-
- /* setup memory */
-
- meml_gotten = SUBL*(iLBCenc_inst->nsub+1-start);
-
-
- if ( meml_gotten > CB_MEML ) {
- meml_gotten=CB_MEML;
- }
- for (k=0; k<meml_gotten; k++) {
- mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];
- }
- memset(mem, 0, (CB_MEML-k)*sizeof(float));
- memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
-
- /* loop over sub-frames to encode */
-
- for (subframe=0; subframe<Nback; subframe++) {
-
- /* encode sub-frame */
-
- iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES,
- gain_index+subcount*CB_NSTAGES,
- &reverseResidual[subframe*SUBL],
- mem+CB_MEML-memLfTbl[subcount],
- memLfTbl[subcount], SUBL, CB_NSTAGES,
- &weightdenum[(start-2-subframe)*
- (LPC_FILTERORDER+1)],
- weightState, subcount+1);
-
- /* construct decoded vector */
-
- iCBConstruct(&reverseDecresidual[subframe*SUBL],
- cb_index+subcount*CB_NSTAGES,
- gain_index+subcount*CB_NSTAGES,
- mem+CB_MEML-memLfTbl[subcount],
- memLfTbl[subcount], SUBL, CB_NSTAGES);
-
- /* update memory */
-
- memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
- memcpy(mem+CB_MEML-SUBL,
- &reverseDecresidual[subframe*SUBL],
- SUBL*sizeof(float));
- memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
-
- subcount++;
-
- }
-
- /* get decoded residual from reversed vector */
-
- for (i=0; i<SUBL*Nback; i++) {
- decresidual[SUBL*Nback - i - 1] =
-
-
- reverseDecresidual[i];
- }
- }
- /* end encoding part */
-
- /* adjust index */
- index_conv_enc(cb_index);
-
- /* pack bytes */
-
- pbytes=bytes;
- pos=0;
-
- /* loop over the 3 ULP classes */
-
- for (ulp=0; ulp<3; ulp++) {
-
- /* LSF */
- for (k=0; k<LSF_NSPLIT*iLBCenc_inst->lpc_n; k++) {
- packsplit(&lsf_i[k], &firstpart, &lsf_i[k],
- iLBCenc_inst->ULP_inst->lsf_bits[k][ulp],
- iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+
- iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+
- iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]);
- dopack( &pbytes, firstpart,
- iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos);
- }
-
- /* Start block info */
-
- packsplit(&start, &firstpart, &start,
- iLBCenc_inst->ULP_inst->start_bits[ulp],
- iLBCenc_inst->ULP_inst->start_bits[ulp]+
- iLBCenc_inst->ULP_inst->start_bits[ulp+1]+
- iLBCenc_inst->ULP_inst->start_bits[ulp+2]);
- dopack( &pbytes, firstpart,
- iLBCenc_inst->ULP_inst->start_bits[ulp], &pos);
-
- packsplit(&state_first, &firstpart, &state_first,
- iLBCenc_inst->ULP_inst->startfirst_bits[ulp],
- iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+
- iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+
- iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]);
- dopack( &pbytes, firstpart,
- iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos);
-
- packsplit(&idxForMax, &firstpart, &idxForMax,
- iLBCenc_inst->ULP_inst->scale_bits[ulp],
- iLBCenc_inst->ULP_inst->scale_bits[ulp]+
- iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+
- iLBCenc_inst->ULP_inst->scale_bits[ulp+2]);
- dopack( &pbytes, firstpart,
- iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos);
-
-
-
- for (k=0; k<iLBCenc_inst->state_short_len; k++) {
- packsplit(idxVec+k, &firstpart, idxVec+k,
- iLBCenc_inst->ULP_inst->state_bits[ulp],
- iLBCenc_inst->ULP_inst->state_bits[ulp]+
- iLBCenc_inst->ULP_inst->state_bits[ulp+1]+
- iLBCenc_inst->ULP_inst->state_bits[ulp+2]);
- dopack( &pbytes, firstpart,
- iLBCenc_inst->ULP_inst->state_bits[ulp], &pos);
- }
-
- /* 23/22 (20ms/30ms) sample block */
-
- for (k=0;k<CB_NSTAGES;k++) {
- packsplit(extra_cb_index+k, &firstpart,
- extra_cb_index+k,
- iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp],
- iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+
- iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+
- iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]);
- dopack( &pbytes, firstpart,
- iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp],
- &pos);
- }
-
- for (k=0;k<CB_NSTAGES;k++) {
- packsplit(extra_gain_index+k, &firstpart,
- extra_gain_index+k,
- iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp],
- iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+
- iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+
- iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]);
- dopack( &pbytes, firstpart,
- iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp],
- &pos);
- }
-
- /* The two/four (20ms/30ms) 40 sample sub-blocks */
-
- for (i=0; i<iLBCenc_inst->nasub; i++) {
- for (k=0; k<CB_NSTAGES; k++) {
- packsplit(cb_index+i*CB_NSTAGES+k, &firstpart,
- cb_index+i*CB_NSTAGES+k,
- iLBCenc_inst->ULP_inst->cb_index[i][k][ulp],
- iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+
- iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+
- iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]);
- dopack( &pbytes, firstpart,
- iLBCenc_inst->ULP_inst->cb_index[i][k][ulp],
- &pos);
- }
- }
-
- for (i=0; i<iLBCenc_inst->nasub; i++) {
- for (k=0; k<CB_NSTAGES; k++) {
-
-
- packsplit(gain_index+i*CB_NSTAGES+k, &firstpart,
- gain_index+i*CB_NSTAGES+k,
- iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp],
- iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+
- iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+
- iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]);
- dopack( &pbytes, firstpart,
- iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp],
- &pos);
- }
- }
- }
-
- /* set the last bit to zero (otherwise the decoder
- will treat it as a lost frame) */
- dopack( &pbytes, 0, 1, &pos);
-}
-
-
-
diff --git a/1.2-netsec/codecs/ilbc/iLBC_encode.h b/1.2-netsec/codecs/ilbc/iLBC_encode.h
deleted file mode 100644
index 3628e7545..000000000
--- a/1.2-netsec/codecs/ilbc/iLBC_encode.h
+++ /dev/null
@@ -1,37 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- iLBC_encode.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_ILBCENCODE_H
-#define __iLBC_ILBCENCODE_H
-
-#include "iLBC_define.h"
-
-short initEncode( /* (o) Number of bytes
- encoded */
- iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */
- int mode /* (i) frame size mode */
-);
-
-void iLBC_encode(
-
-
- unsigned char *bytes, /* (o) encoded data bits iLBC */
- float *block, /* (o) speech vector to
- encode */
- iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder
- state */
-);
-
-#endif
-
-
-
diff --git a/1.2-netsec/codecs/ilbc/lsf.c b/1.2-netsec/codecs/ilbc/lsf.c
deleted file mode 100644
index 055c21cb5..000000000
--- a/1.2-netsec/codecs/ilbc/lsf.c
+++ /dev/null
@@ -1,264 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- lsf.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <string.h>
-#include <math.h>
-
-#include "iLBC_define.h"
-#include "lsf.h"
-
-/*----------------------------------------------------------------*
- * conversion from lpc coefficients to lsf coefficients
- *---------------------------------------------------------------*/
-
-void a2lsf(
- float *freq,/* (o) lsf coefficients */
- float *a /* (i) lpc coefficients */
-){
- float steps[LSF_NUMBER_OF_STEPS] =
- {(float)0.00635, (float)0.003175, (float)0.0015875,
- (float)0.00079375};
- float step;
- int step_idx;
- int lsp_index;
- float p[LPC_HALFORDER];
- float q[LPC_HALFORDER];
- float p_pre[LPC_HALFORDER];
-
-
- float q_pre[LPC_HALFORDER];
- float old_p, old_q, *old;
- float *pq_coef;
- float omega, old_omega;
- int i;
- float hlp, hlp1, hlp2, hlp3, hlp4, hlp5;
-
- for (i=0; i<LPC_HALFORDER; i++) {
- p[i] = (float)-1.0 * (a[i + 1] + a[LPC_FILTERORDER - i]);
- q[i] = a[LPC_FILTERORDER - i] - a[i + 1];
- }
-
- p_pre[0] = (float)-1.0 - p[0];
- p_pre[1] = - p_pre[0] - p[1];
- p_pre[2] = - p_pre[1] - p[2];
- p_pre[3] = - p_pre[2] - p[3];
- p_pre[4] = - p_pre[3] - p[4];
- p_pre[4] = p_pre[4] / 2;
-
- q_pre[0] = (float)1.0 - q[0];
- q_pre[1] = q_pre[0] - q[1];
- q_pre[2] = q_pre[1] - q[2];
- q_pre[3] = q_pre[2] - q[3];
- q_pre[4] = q_pre[3] - q[4];
- q_pre[4] = q_pre[4] / 2;
-
- omega = 0.0;
- old_omega = 0.0;
-
- old_p = FLOAT_MAX;
- old_q = FLOAT_MAX;
-
- /* Here we loop through lsp_index to find all the
- LPC_FILTERORDER roots for omega. */
-
- for (lsp_index = 0; lsp_index<LPC_FILTERORDER; lsp_index++) {
-
- /* Depending on lsp_index being even or odd, we
- alternatively solve the roots for the two LSP equations. */
-
-
- if ((lsp_index & 0x1) == 0) {
- pq_coef = p_pre;
- old = &old_p;
- } else {
- pq_coef = q_pre;
- old = &old_q;
- }
-
- /* Start with low resolution grid */
-
- for (step_idx = 0, step = steps[step_idx];
- step_idx < LSF_NUMBER_OF_STEPS;){
-
-
-
- /* cos(10piw) + pq(0)cos(8piw) + pq(1)cos(6piw) +
- pq(2)cos(4piw) + pq(3)cod(2piw) + pq(4) */
-
- hlp = (float)cos(omega * TWO_PI);
- hlp1 = (float)2.0 * hlp + pq_coef[0];
- hlp2 = (float)2.0 * hlp * hlp1 - (float)1.0 +
- pq_coef[1];
- hlp3 = (float)2.0 * hlp * hlp2 - hlp1 + pq_coef[2];
- hlp4 = (float)2.0 * hlp * hlp3 - hlp2 + pq_coef[3];
- hlp5 = hlp * hlp4 - hlp3 + pq_coef[4];
-
-
- if (((hlp5 * (*old)) <= 0.0) || (omega >= 0.5)){
-
- if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){
-
- if (fabs(hlp5) >= fabs(*old)) {
- freq[lsp_index] = omega - step;
- } else {
- freq[lsp_index] = omega;
- }
-
-
- if ((*old) >= 0.0){
- *old = (float)-1.0 * FLOAT_MAX;
- } else {
- *old = FLOAT_MAX;
- }
-
- omega = old_omega;
- step_idx = 0;
-
- step_idx = LSF_NUMBER_OF_STEPS;
- } else {
-
- if (step_idx == 0) {
- old_omega = omega;
- }
-
- step_idx++;
- omega -= steps[step_idx];
-
- /* Go back one grid step */
-
- step = steps[step_idx];
- }
- } else {
-
- /* increment omega until they are of different sign,
- and we know there is at least one root between omega
- and old_omega */
- *old = hlp5;
- omega += step;
- }
-
-
- }
- }
-
- for (i = 0; i<LPC_FILTERORDER; i++) {
- freq[i] = freq[i] * TWO_PI;
- }
-}
-
-/*----------------------------------------------------------------*
- * conversion from lsf coefficients to lpc coefficients
- *---------------------------------------------------------------*/
-
-void lsf2a(
- float *a_coef, /* (o) lpc coefficients */
- float *freq /* (i) lsf coefficients */
-){
- int i, j;
- float hlp;
- float p[LPC_HALFORDER], q[LPC_HALFORDER];
- float a[LPC_HALFORDER + 1], a1[LPC_HALFORDER],
- a2[LPC_HALFORDER];
- float b[LPC_HALFORDER + 1], b1[LPC_HALFORDER],
- b2[LPC_HALFORDER];
-
- for (i=0; i<LPC_FILTERORDER; i++) {
- freq[i] = freq[i] * PI2;
- }
-
- /* Check input for ill-conditioned cases. This part is not
- found in the TIA standard. It involves the following 2 IF
- blocks. If "freq" is judged ill-conditioned, then we first
- modify freq[0] and freq[LPC_HALFORDER-1] (normally
- LPC_HALFORDER = 10 for LPC applications), then we adjust
- the other "freq" values slightly */
-
-
- if ((freq[0] <= 0.0) || (freq[LPC_FILTERORDER - 1] >= 0.5)){
-
-
- if (freq[0] <= 0.0) {
- freq[0] = (float)0.022;
- }
-
-
- if (freq[LPC_FILTERORDER - 1] >= 0.5) {
- freq[LPC_FILTERORDER - 1] = (float)0.499;
- }
-
- hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) /
- (float) (LPC_FILTERORDER - 1);
-
- for (i=1; i<LPC_FILTERORDER; i++) {
- freq[i] = freq[i - 1] + hlp;
- }
-
-
- }
-
- memset(a1, 0, LPC_HALFORDER*sizeof(float));
- memset(a2, 0, LPC_HALFORDER*sizeof(float));
- memset(b1, 0, LPC_HALFORDER*sizeof(float));
- memset(b2, 0, LPC_HALFORDER*sizeof(float));
- memset(a, 0, (LPC_HALFORDER+1)*sizeof(float));
- memset(b, 0, (LPC_HALFORDER+1)*sizeof(float));
-
- /* p[i] and q[i] compute cos(2*pi*omega_{2j}) and
- cos(2*pi*omega_{2j-1} in eqs. 4.2.2.2-1 and 4.2.2.2-2.
- Note that for this code p[i] specifies the coefficients
- used in .Q_A(z) while q[i] specifies the coefficients used
- in .P_A(z) */
-
- for (i=0; i<LPC_HALFORDER; i++) {
- p[i] = (float)cos(TWO_PI * freq[2 * i]);
- q[i] = (float)cos(TWO_PI * freq[2 * i + 1]);
- }
-
- a[0] = 0.25;
- b[0] = 0.25;
-
- for (i= 0; i<LPC_HALFORDER; i++) {
- a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];
- b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];
- a2[i] = a1[i];
- a1[i] = a[i];
- b2[i] = b1[i];
- b1[i] = b[i];
- }
-
- for (j=0; j<LPC_FILTERORDER; j++) {
-
- if (j == 0) {
- a[0] = 0.25;
- b[0] = -0.25;
- } else {
- a[0] = b[0] = 0.0;
- }
-
- for (i=0; i<LPC_HALFORDER; i++) {
- a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];
- b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];
- a2[i] = a1[i];
- a1[i] = a[i];
- b2[i] = b1[i];
- b1[i] = b[i];
- }
-
- a_coef[j + 1] = 2 * (a[LPC_HALFORDER] + b[LPC_HALFORDER]);
- }
-
- a_coef[0] = 1.0;
-
-
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/lsf.h b/1.2-netsec/codecs/ilbc/lsf.h
deleted file mode 100644
index ec43cacda..000000000
--- a/1.2-netsec/codecs/ilbc/lsf.h
+++ /dev/null
@@ -1,30 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- lsf.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-
-
-******************************************************************/
-
-#ifndef __iLBC_LSF_H
-#define __iLBC_LSF_H
-
-void a2lsf(
- float *freq,/* (o) lsf coefficients */
- float *a /* (i) lpc coefficients */
-);
-
-void lsf2a(
- float *a_coef, /* (o) lpc coefficients */
- float *freq /* (i) lsf coefficients */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/packing.c b/1.2-netsec/codecs/ilbc/packing.c
deleted file mode 100644
index 3071032e0..000000000
--- a/1.2-netsec/codecs/ilbc/packing.c
+++ /dev/null
@@ -1,175 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- packing.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include <math.h>
-#include <stdlib.h>
-
-#include "iLBC_define.h"
-#include "constants.h"
-#include "helpfun.h"
-#include "packing.h"
-#include "string.h"
-
-/*----------------------------------------------------------------*
- * splitting an integer into first most significant bits and
- * remaining least significant bits
- *---------------------------------------------------------------*/
-
-void packsplit(
- int *index, /* (i) the value to split */
- int *firstpart, /* (o) the value specified by most
- significant bits */
- int *rest, /* (o) the value specified by least
- significant bits */
- int bitno_firstpart, /* (i) number of bits in most
- significant part */
- int bitno_total /* (i) number of bits in full range
- of value */
-){
- int bitno_rest = bitno_total-bitno_firstpart;
-
-
-
- *firstpart = *index>>(bitno_rest);
- *rest = *index-(*firstpart<<(bitno_rest));
-}
-
-/*----------------------------------------------------------------*
- * combining a value corresponding to msb's with a value
- * corresponding to lsb's
- *---------------------------------------------------------------*/
-
-void packcombine(
- int *index, /* (i/o) the msb value in the
- combined value out */
- int rest, /* (i) the lsb value */
- int bitno_rest /* (i) the number of bits in the
- lsb part */
-){
- *index = *index<<bitno_rest;
- *index += rest;
-}
-
-/*----------------------------------------------------------------*
- * packing of bits into bitstream, i.e., vector of bytes
- *---------------------------------------------------------------*/
-
-void dopack(
- unsigned char **bitstream, /* (i/o) on entrance pointer to
- place in bitstream to pack
- new data, on exit pointer
- to place in bitstream to
- pack future data */
- int index, /* (i) the value to pack */
- int bitno, /* (i) the number of bits that the
- value will fit within */
- int *pos /* (i/o) write position in the
- current byte */
-){
- int posLeft;
-
- /* Clear the bits before starting in a new byte */
-
- if ((*pos)==0) {
- **bitstream=0;
- }
-
- while (bitno>0) {
-
- /* Jump to the next byte if end of this byte is reached*/
-
- if (*pos==8) {
- *pos=0;
- (*bitstream)++;
- **bitstream=0;
- }
-
-
-
- posLeft=8-(*pos);
-
- /* Insert index into the bitstream */
-
- if (bitno <= posLeft) {
- **bitstream |= (unsigned char)(index<<(posLeft-bitno));
- *pos+=bitno;
- bitno=0;
- } else {
- **bitstream |= (unsigned char)(index>>(bitno-posLeft));
-
- *pos=8;
- index-=((index>>(bitno-posLeft))<<(bitno-posLeft));
-
- bitno-=posLeft;
- }
- }
-}
-
-/*----------------------------------------------------------------*
- * unpacking of bits from bitstream, i.e., vector of bytes
- *---------------------------------------------------------------*/
-
-void unpack(
- unsigned char **bitstream, /* (i/o) on entrance pointer to
- place in bitstream to
- unpack new data from, on
- exit pointer to place in
- bitstream to unpack future
- data from */
- int *index, /* (o) resulting value */
- int bitno, /* (i) number of bits used to
- represent the value */
- int *pos /* (i/o) read position in the
- current byte */
-){
- int BitsLeft;
-
- *index=0;
-
- while (bitno>0) {
-
- /* move forward in bitstream when the end of the
- byte is reached */
-
- if (*pos==8) {
- *pos=0;
- (*bitstream)++;
- }
-
- BitsLeft=8-(*pos);
-
- /* Extract bits to index */
-
-
-
- if (BitsLeft>=bitno) {
- *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno));
-
- *pos+=bitno;
- bitno=0;
- } else {
-
- if ((8-bitno)>0) {
- *index+=((((**bitstream)<<(*pos)) & 0xFF)>>
- (8-bitno));
- *pos=8;
- } else {
- *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<<
- (bitno-8));
- *pos=8;
- }
- bitno-=BitsLeft;
- }
- }
-}
-
-
diff --git a/1.2-netsec/codecs/ilbc/packing.h b/1.2-netsec/codecs/ilbc/packing.h
deleted file mode 100644
index ed114b1c1..000000000
--- a/1.2-netsec/codecs/ilbc/packing.h
+++ /dev/null
@@ -1,67 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- packing.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __PACKING_H
-#define __PACKING_H
-
-void packsplit(
- int *index, /* (i) the value to split */
- int *firstpart, /* (o) the value specified by most
- significant bits */
- int *rest, /* (o) the value specified by least
- significant bits */
- int bitno_firstpart, /* (i) number of bits in most
- significant part */
- int bitno_total /* (i) number of bits in full range
- of value */
-);
-
-void packcombine(
- int *index, /* (i/o) the msb value in the
- combined value out */
- int rest, /* (i) the lsb value */
- int bitno_rest /* (i) the number of bits in the
- lsb part */
-);
-
-void dopack(
- unsigned char **bitstream, /* (i/o) on entrance pointer to
- place in bitstream to pack
- new data, on exit pointer
- to place in bitstream to
- pack future data */
- int index, /* (i) the value to pack */
- int bitno, /* (i) the number of bits that the
- value will fit within */
- int *pos /* (i/o) write position in the
- current byte */
-);
-
-void unpack(
- unsigned char **bitstream, /* (i/o) on entrance pointer to
-
-
- place in bitstream to
- unpack new data from, on
- exit pointer to place in
- bitstream to unpack future
- data from */
- int *index, /* (o) resulting value */
- int bitno, /* (i) number of bits used to
- represent the value */
- int *pos /* (i/o) read position in the
- current byte */
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc/syntFilter.c b/1.2-netsec/codecs/ilbc/syntFilter.c
deleted file mode 100644
index bb7f7a559..000000000
--- a/1.2-netsec/codecs/ilbc/syntFilter.c
+++ /dev/null
@@ -1,108 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- syntFilter.c
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#include "iLBC_define.h"
-#include "syntFilter.h"
-
-/*----------------------------------------------------------------*
- * LP synthesis filter.
- *---------------------------------------------------------------*/
-
-void syntFilter(
- float *Out, /* (i/o) Signal to be filtered */
- float *a, /* (i) LP parameters */
- int len, /* (i) Length of signal */
- float *mem /* (i/o) Filter state */
-){
- int i, j;
- float *po, *pi, *pa, *pm;
-
- po=Out;
-
- /* Filter first part using memory from past */
-
- for (i=0; i<LPC_FILTERORDER; i++) {
- pi=&Out[i-1];
- pa=&a[1];
- pm=&mem[LPC_FILTERORDER-1];
- for (j=1; j<=i; j++) {
- *po-=(*pa++)*(*pi--);
- }
- for (j=i+1; j<LPC_FILTERORDER+1; j++) {
- *po-=(*pa++)*(*pm--);
- }
- po++;
- }
-
- /* Filter last part where the state is entierly in
- the output vector */
-
- for (i=LPC_FILTERORDER; i<len; i++) {
-
-
- pi=&Out[i-1];
- pa=&a[1];
- for (j=1; j<LPC_FILTERORDER+1; j++) {
- *po-=(*pa++)*(*pi--);
- }
- po++;
- }
-
- /* Update state vector */
-
- memcpy(mem, &Out[len-LPC_FILTERORDER],
- LPC_FILTERORDER*sizeof(float));
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/1.2-netsec/codecs/ilbc/syntFilter.h b/1.2-netsec/codecs/ilbc/syntFilter.h
deleted file mode 100644
index c155fdb0b..000000000
--- a/1.2-netsec/codecs/ilbc/syntFilter.h
+++ /dev/null
@@ -1,27 +0,0 @@
-
-/******************************************************************
-
- iLBC Speech Coder ANSI-C Source Code
-
- syntFilter.h
-
- Copyright (C) The Internet Society (2004).
- All Rights Reserved.
-
-******************************************************************/
-
-#ifndef __iLBC_SYNTFILTER_H
-#define __iLBC_SYNTFILTER_H
-
-void syntFilter(
- float *Out, /* (i/o) Signal to be filtered */
- float *a, /* (i) LP parameters */
- int len, /* (i) Length of signal */
- float *mem /* (i/o) Filter state */
-
-
-);
-
-#endif
-
-
diff --git a/1.2-netsec/codecs/ilbc_slin_ex.h b/1.2-netsec/codecs/ilbc_slin_ex.h
deleted file mode 100644
index b9f4bd4e8..000000000
--- a/1.2-netsec/codecs/ilbc_slin_ex.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*! \file
- * \brief Raw 8-bit data
- *
- * Source: ilbc.out
- *
- * Copyright (C) 1999-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char ilbc_slin_ex[] = {
-0xff, 0xa0, 0xff, 0xfa, 0xf, 0x60, 0x12, 0x11, 0xa2, 0x47,
-0x22, 0x8c, 00, 00, 0x1, 0x2, 0x80, 0x43, 0xa0, 0x40,
-0x33, 0xff, 0xcf, 0xc0, 0xf3, 0xf3, 0x3f, 0x8f, 0x3f, 0xff,
-0xff, 0xff, 0xff, 0xfc, 0xf9, 0xe5, 0x55, 0x78, 0xb, 0xca,
-0xe1, 0x27, 0x94, 0x7b, 0xa8, 0x91, 0x2c, 0x36, 0x8, 0x56 };
diff --git a/1.2-netsec/codecs/log2comp.h b/1.2-netsec/codecs/log2comp.h
deleted file mode 100644
index 56f2d8305..000000000
--- a/1.2-netsec/codecs/log2comp.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*! \file
- * \brief log2comp.h - various base 2 log computation versions
- *
- * Asterisk -- A telephony toolkit for Linux.
- *
- * \author Alex Volkov <codepro@usa.net>
- *
- * Copyright (c) 2004 - 2005, Digium Inc.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- *
- * Define WANT_ASM before including this file to use assembly
- * whenever possible
- */
-
-#if defined(_MSC_VER)
-# define inline __inline
-#elif defined(__GNUC__)
-# define inline __inline__
-#else
-# define inline
-#endif
-
-#if defined(WANT_ASM) && defined(_MSC_VER) && defined(_M_IX86)
-/* MS C Inline Asm */
-# pragma warning( disable : 4035 )
-static inline int ilog2(int val) { __asm
-{
- xor eax, eax
- dec eax
- bsr eax, val
-}}
-# pragma warning( default : 4035 )
-#elif defined(WANT_ASM) && defined(__GNUC__) && (defined(__i386__) || defined(i386))
-/* GNU Inline Asm */
-static inline int ilog2(int val)
-{
- int a;
- __asm__
- ("\
- xorl %0, %0 ;\
- decl %0 ;\
- bsrl %1, %0 ;\
- "
- : "=r" (a)
- : "mr" (val)
- : "cc"
- );
- return a;
-}
-#elif defined(WANT_ASM) && defined(__GNUC__) && defined(__powerpc__)
-static inline int ilog2(int val)
-{
- int a;
- __asm__ ("cntlzw %0,%1"
- : "=r" (a)
- : "r" (val)
- );
- return 31-a;
-}
-#else
-/* no ASM for this compiler and/or platform */
-/* rather slow base 2 log computation
- * Using looped shift.
- */
-static inline int ilog2(int val)
-{
- int i;
- for (i = -1; val; ++i, val >>= 1)
- ;
- return (i);
-}
-#endif
diff --git a/1.2-netsec/codecs/lpc10/Makefile b/1.2-netsec/codecs/lpc10/Makefile
deleted file mode 100644
index b56a59ba4..000000000
--- a/1.2-netsec/codecs/lpc10/Makefile
+++ /dev/null
@@ -1,75 +0,0 @@
-#
-# Makefile for LPC-10 speech coder library (unix)
-#
-
-# default C compiler
-CC?= gcc
-
-#
-# These definitions for CFLAGS and LIB_TARGET_DIR are used when one
-# runs make in the lpc10 directory, without environment variables that
-# override them. When make is run in this directory from a makefile
-# for an application that uses the LPC10 coder, there are environment
-# variables set for CFLAGS and LIB_TARGET_DIR that override these
-# definitions.
-#
-
-LIB_TARGET_DIR = .
-
-#
-# -I$(LIB_TARGET_DIR) option needed so that #include "machine.h"
-# directives can find the machine.h file.
-#
-
-WARNINGS = -Wall -Wno-comment -Wno-error
-CFLAGS += $(OPTIMIZE) -I$(LIB_TARGET_DIR) $(WARNINGS)
-ifneq (${OSARCH},CYGWIN)
-CFLAGS += -fPIC
-endif
-#CFLAGS+= $(shell if uname -m | grep -q 86; then echo "-mpentium" ; fi)
-
-#fix for PPC processors and ALPHA, And UltraSparc too
-ifneq ($(OSARCH),Darwin)
-ifneq ($(findstring BSD,${OSARCH}),BSD)
-ifneq ($(PROC),ppc)
-ifneq ($(PROC),x86_64)
-ifneq ($(PROC),alpha)
-#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
-#This works for even old (2.96) versions of gcc and provides a small boost either way.
-#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.
-#So we go lowest common available by gcc and go a step down, still a step up from
-#the default as we now have a better instruction set to work with. - Belgarath
-ifeq ($(PROC),ultrasparc)
- CFLAGS+= -mtune=$(PROC) -mcpu=v8 -O3 -fomit-frame-pointer
-else
-ifneq ($(OSARCH),SunOS)
-ifneq ($(OSARCH),arm)
-# CFLAGS+= -march=$(PROC)
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-
-LIB = $(LIB_TARGET_DIR)/liblpc10.a
-
-.PHONY: all clean
-
-all: $(LIB)
-
-OBJ= f2clib.o analys.o bsynz.o chanwr.o dcbias.o decode.o \
- deemp.o difmag.o dyptrk.o encode.o energy.o ham84.o \
- hp100.o invert.o irc2pc.o ivfilt.o lpcdec.o lpcenc.o \
- lpcini.o lpfilt.o median.o mload.o onset.o pitsyn.o \
- placea.o placev.o preemp.o prepro.o random.o rcchk.o \
- synths.o tbdm.o voicin.o vparms.o
-
-$(LIB): $(OBJ)
- $(AR) cr $@ $(OBJ)
- ranlib $@
-
-clean:
- -rm -f *.o $(LIB)
diff --git a/1.2-netsec/codecs/lpc10/README b/1.2-netsec/codecs/lpc10/README
deleted file mode 100644
index 30abe4c97..000000000
--- a/1.2-netsec/codecs/lpc10/README
+++ /dev/null
@@ -1,89 +0,0 @@
-Tue Aug 20 16:19:51 CDT 1996
-Andy Fingerhut (jaf@arl.wustl.edu)
-
-In release 1.4, there are quite a few hand modifications to the C code
-that was automatically created from the Fortran code with f2c. They
-are all summarized in change log comments at the beginning of the
-changed files. All of the original files from f2c were checked in to
-RCS before modification, so it is possible to see exactly what changes
-were made, for the extremely curious. That precaution was also for my
-benefit, in case I ever recompile the Fortran sources, and want to
-make similar changes to that new C source code.
-
-Below is the README file for this directory included with the 1.3
-release of the LPC-10 package. A few parts of it are a little out of
-date, but it is correct for the most part.
-
-
-Sun Jul 7 15:30:31 CDT 1996
-Andy Fingerhut (jaf@arl.wustl.edu)
-
-To create the LPC-10 library, copy the appropriate makefile to the
-proper name for easy use, e.g., for Unix, copy makefile.unx to the
-file "Makefile". The file makefile.dos has been used with some
-version of the 'nmake' utility that comes with the Microsoft C
-compiler (the same one used for Nautilus v1.5a, which I believe
-specifies Microsoft C version 7.0 or later).
-
-Then edit the file lpc10.h in the directory above. It should already
-be set up to work properly on any Unix compiler for which "int" is 32
-bits and "short" is 16 bits, and under the Microsoft C compiler
-configured so that "long" is 32 bits and "int" is 16 bits. There must
-be a typedef for the two types INT32 and INT16 in that file. You
-should choose types that compile to those sizes using your compiler,
-because there are places in the LPC-10 code that expect INT16's to
-have exactly 16 bits (at least, I *think* they must be no larger), and
-INT32's to have exactly 32 bits.
-
-
-A few notes on how these files were created
--------------------------------------------
-
-(This section is mostly for my benefit, so I can remember what I did.
-You don't need to read it if you just want to use this package. It
-might be useful to read it if you change the Fortran sources and want
-to recreate a usable library of C sources. -- Andy)
-
-These C sources were created automatically from the Fortran sources
-using f2c, for the most part. Listed below are the extra
-modifications that were made after this automatic conversion. Many of
-them were made so that it was not necessary to install f2c in order to
-use this LPC-10 coder.
-
-1.
-
-Put all of those files that were necessary for only the coder, rather
-than an application that uses the coder, into this subdirectory called
-lpc10.
-
-2.
-
-Copied f2c.h from the f2c distribution into this subdirectory. Some
-modifications were made to the "typedef" statements in this file, to
-explicitly indicate the sizes (in bits) that different integer types
-should be. The types INT32 and INT16 must be defined in a file called
-lpc10.h in the directory above. Created the file f2clib.c, containing
-only the functions pow_ii(), r_sign(), and i_nint() from the f2c
-library.
-
-3.
-
-The f2c output originally had a file called contrl_com.c, that defined
-a small structure containing a few variables that were used in many
-different functions of the LPC10 code. Every file containing
-functions that used it defined it as "extern", while contrl_com.c
-actually allocated storage for the structure. Bill Dorsey, one of the
-lead developers of Nautilus, said that the Microsoft C compiler had
-problems either compiling this file, or linking it with all of the
-other compiled files, so he just eliminated that file and removed the
-"extern" keyword from the one of the files that declared it that way.
-The file chosen (arbitrarily) was analys.c.
-
-4.
-
-Copied the makefiles for Unix and Microsoft C from the Nautilus v1.5a
-distribution into the lpc10 directory. Modified them to take out
-references to Nautilus. These makefiles don't create an executable,
-but a library of compiled functions called liblpc10.a (Unix) or
-LPC10.LIB (DOS). This library can be used when linking an executable
-that calls the functions lpcini_(), lpcenc_(), and lpcdec_().
diff --git a/1.2-netsec/codecs/lpc10/analys.c b/1.2-netsec/codecs/lpc10/analys.c
deleted file mode 100644
index 3fa21f22b..000000000
--- a/1.2-netsec/codecs/lpc10/analys.c
+++ /dev/null
@@ -1,649 +0,0 @@
-/*
-
-$Log$
-Revision 1.16 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.15 2003/09/19 01:20:22 markster
-Code cleanups (bug #66)
-
-Revision 1.2 2003/09/19 01:20:22 markster
-Code cleanups (bug #66)
-
-Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:16:01 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:29:08 jaf
- * Initial revision
- *
-
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int analys_(real *speech, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_encoder_state *st);
-/* comlen contrl_ 12 */
-/*:ref: preemp_ 14 5 6 6 4 6 6 */
-/*:ref: onset_ 14 7 6 4 4 4 4 4 4 */
-/*:ref: placev_ 14 11 4 4 4 4 4 4 4 4 4 4 4 */
-/*:ref: lpfilt_ 14 4 6 6 4 4 */
-/*:ref: ivfilt_ 14 5 6 6 4 4 6 */
-/*:ref: tbdm_ 14 8 6 4 4 4 6 4 4 4 */
-/*:ref: voicin_ 14 12 4 6 6 4 4 6 6 4 6 4 4 4 */
-/*:ref: dyptrk_ 14 6 6 4 4 4 4 4 */
-/*:ref: placea_ 14 9 4 4 4 4 4 4 4 4 4 */
-/*:ref: dcbias_ 14 3 4 6 6 */
-/*:ref: energy_ 14 3 4 6 6 */
-/*:ref: mload_ 14 6 4 4 4 6 6 6 */
-/*:ref: invert_ 14 4 4 6 6 6 */
-/*:ref: rcchk_ 14 3 4 6 6 */
-/*:ref: initonset_ 14 0 */
-/*:ref: initvoicin_ 14 0 */
-/*:ref: initdyptrk_ 14 0 */
-/* Rerunning f2c -P may change prototypes or declarations. */
-#endif
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-/* Common Block Declarations */
-
-extern struct {
- integer order, lframe;
- logical corrp;
-} contrl_;
-
-#define contrl_1 contrl_
-
-/* Table of constant values */
-
-static integer c__10 = 10;
-static integer c__181 = 181;
-static integer c__720 = 720;
-static integer c__3 = 3;
-static integer c__90 = 90;
-static integer c__156 = 156;
-static integer c__307 = 307;
-static integer c__462 = 462;
-static integer c__312 = 312;
-static integer c__60 = 60;
-static integer c__1 = 1;
-
-/* ****************************************************************** */
-
-/* ANALYS Version 55 */
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.2 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:16:01 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:29:08 jaf
- * Initial revision
- * */
-/* Revision 1.9 1996/05/23 19:41:07 jaf */
-/* Commented out some unnecessary lines that were reading uninitialized */
-/* values. */
-
-/* Revision 1.8 1996/03/27 23:57:55 jaf */
-/* Added some comments about which indices of the local buffers INBUF, */
-/* LPBUF, etc., get read or modified by some of the subroutine calls. I */
-/* just did this while trying to figure out the discrepancy between the */
-/* embedded code compiled with all local variables implicitly saved, and */
-/* without. */
-
-/* I added some debugging write statements in hopes of finding a problem. */
-/* None of them ever printed anything while running with the long input */
-/* speech file dam9.spd provided in the distribution. */
-
-/* Revision 1.7 1996/03/27 18:06:20 jaf */
-/* Commented out access to MAXOSP, which is just a debugging variable */
-/* that was defined in the COMMON block CONTRL in contrl.fh. */
-
-/* Revision 1.6 1996/03/26 19:31:33 jaf */
-/* Commented out trace statements. */
-
-/* Revision 1.5 1996/03/21 15:19:35 jaf */
-/* Added comments for ENTRY PITDEC. */
-
-/* Revision 1.4 1996/03/19 20:54:27 jaf */
-/* Added a line to INITANALYS. See comments there. */
-
-/* Revision 1.3 1996/03/19 20:52:49 jaf */
-/* Rearranged the order of the local variables quite a bit, to separate */
-/* them into groups of "constants", "locals that don't need to be saved */
-/* from one call to the next", and "local that do need to be saved from */
-/* one call to the next". */
-
-/* Several locals in the last set should have been given initial values, */
-/* but weren't. I gave them all initial values of 0. */
-
-/* Added a separate ENTRY INITANALYS that initializes all local state */
-/* that should be, and also calls the corresponding entries of the */
-/* subroutines called by ANALYS that also have local state. */
-
-/* There used to be DATA statements in ANALYS. I got rid of most of */
-/* them, and added a local logical variable FIRST that calls the entry */
-/* INITANALYS on the first call to ANALYS. This is just so that one need */
-/* not remember to call INITANALYS first in order for the state to be */
-/* initialized. */
-
-/* Revision 1.2 1996/03/11 23:29:32 jaf */
-/* Added several comments with my own personal questions about the */
-/* Fortran 77 meaning of the parameters passed to the subroutine PREEMP. */
-
-/* Revision 1.1 1996/02/07 14:42:29 jaf */
-/* Initial revision */
-
-
-/* ****************************************************************** */
-
-/* SUBROUTINE ANALYS */
-
-/* Input: */
-/* SPEECH */
-/* Indices 1 through LFRAME read. */
-/* Output: */
-/* VOICE */
-/* Indices 1 through 2 written. */
-/* PITCH */
-/* Written in subroutine DYPTRK, and then perhaps read and written */
-/* some more. */
-/* RMS */
-/* Written. */
-/* RC */
-/* Indices 1 through ORDER written (ORDER defined in contrl.fh). */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this filter, or */
-/* reinitialize its state for any other reason, call the ENTRY */
-/* INITANALYS. */
-
-
-/* ENTRY PITDEC */
-
-/* Input: */
-/* PITCH - Encoded pitch index */
-/* Output: */
-/* PTAU - Decoded pitch period */
-
-/* This entry has no local state. It accesses a "constant" array */
-/* declared in ANALYS. */
-
-/* Subroutine */ int analys_(real *speech, integer *voice, integer
- *pitch, real *rms, real *rc, struct lpc10_encoder_state *st)
-{
- /* Initialized data */
-
- static integer tau[60] = { 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
- 35,36,37,38,39,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,
- 74,76,78,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,
- 140,144,148,152,156 };
- static integer buflim[4] = { 181,720,25,720 };
- static real precoef = .9375f;
-
- /* System generated locals */
- integer i__1;
-
- /* Local variables */
- real amdf[60];
- integer half;
- real abuf[156];
- real *bias;
- extern /* Subroutine */ int tbdm_(real *, integer *, integer *, integer *,
- real *, integer *, integer *, integer *);
- integer *awin;
- integer midx, ewin[6] /* was [2][3] */;
- real ivrc[2], temp;
- real *zpre;
- integer *vwin;
- integer i__, j, lanal;
- extern /* Subroutine */ int rcchk_(integer *, real *, real *), mload_(
- integer *, integer *, integer *, real *, real *, real *);
- real *inbuf, *pebuf;
- real *lpbuf, *ivbuf;
- real *rcbuf;
- integer *osbuf;
- extern /* Subroutine */ int onset_(real *, integer *, integer *, integer *
- , integer *, integer *, integer *, struct lpc10_encoder_state *);
- integer *osptr;
- extern int dcbias_(integer *, real *, real *);
- integer ipitch;
- integer *obound;
- extern /* Subroutine */ int preemp_(real *, real *, integer *, real *,
- real *), voicin_(integer *, real *, real *, integer *, integer *,
- real *, real *, integer *, real *, integer *, integer *, integer *,
- struct lpc10_encoder_state *);
- integer *voibuf;
- integer mintau;
- real *rmsbuf;
- extern /* Subroutine */ int lpfilt_(real *, real *, integer *, integer *),
- ivfilt_(real *, real *, integer *, integer *, real *), energy_(
- integer *, real *, real *), invert_(integer *, real *, real *,
- real *);
- integer minptr, maxptr;
- extern /* Subroutine */ int dyptrk_(real *, integer *, integer *, integer
- *, integer *, integer *, struct lpc10_encoder_state *);
- real phi[100] /* was [10][10] */, psi[10];
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.2 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:16:01 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:29:08 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Arguments to ANALYS */
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.2 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:16:01 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:29:08 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:05:55 jaf */
-/* Commented out the common block variables that are not needed by the */
-/* embedded version. */
-
-/* Revision 1.2 1996/03/26 19:34:50 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:44:09 jaf */
-/* Initial revision */
-
-/* LPC Processing control variables: */
-
-/* *** Read-only: initialized in setup */
-
-/* Files for Speech, Parameter, and Bitstream Input & Output, */
-/* and message and debug outputs. */
-
-/* Here are the only files which use these variables: */
-
-/* lpcsim.f setup.f trans.f error.f vqsetup.f */
-
-/* Many files which use fdebug are not listed, since it is only used in */
-/* those other files conditionally, to print trace statements. */
-/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* LPC order, Frame size, Quantization rate, Bits per frame, */
-/* Error correction */
-/* Subroutine SETUP is the only place where order is assigned a value, */
-/* and that value is 10. It could increase efficiency 1% or so to */
-/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
-*/
-/* a variable in a COMMON block, since it is used in many places in the */
-/* core of the coding and decoding routines. Actually, I take that back.
-*/
-/* At least when compiling with f2c, the upper bound of DO loops is */
-/* stored in a local variable before the DO loop begins, and then that is
-*/
-/* compared against on each iteration. */
-/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
-/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
-/* is used in only a few places, and never in the core coding and */
-/* decoding routines, so it could be eliminated entirely. */
-/* nbits is similar to quant, and is given a value of 54 in SETUP. */
-/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
-/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
-/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
-*/
-/* a constant or a variable, since it is only examined once per frame. */
-/* Leaving it as a variable that is set to .TRUE. seems like a good */
-/* idea, since it does enable some error-correction capability for */
-/* unvoiced frames, with no change in the coding rate, and no noticeable
-*/
-/* quality difference in the decoded speech. */
-/* integer quant, nbits */
-/* *** Read/write: variables for debugging, not needed for LPC algorithm
-*/
-
-/* Current frame, Unstable frames, Output clip count, Max onset buffer,
-*/
-/* Debug listing detail level, Line count on listing page */
-
-/* nframe is not needed for an embedded LPC10 at all. */
-/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
-/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
-/* an application, I would recommend removing the call to ERROR in RCCHK,
-*/
-/* and remove ERROR and nunsfm completely. */
-/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
-*/
-/* sread.f. When LPC10 is embedded into an application, one might want */
-/* to cause it to be incremented in a routine that takes the output of */
-/* SYNTHS and sends it to an audio device. It could be optionally */
-/* displayed, for those that might want to know what it is. */
-/* maxosp is never initialized to 0 in SETUP, although it probably should
-*/
-/* be, and it is updated in subroutine ANALYS. I doubt that its value */
-/* would be of much interest to an application in which LPC10 is */
-/* embedded. */
-/* listl and lincnt are not needed for an embedded LPC10 at all. */
-/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* common /contrl/ quant, nbits */
-/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* Arguments to entry PITDEC (below) */
-/* Parameters/constants */
-/* Constants */
-/* NF = Number of frames */
-/* AF = Frame in which analysis is done */
-/* OSLEN = Length of the onset buffer */
-/* LTAU = Number of pitch lags */
-/* SBUFL, SBUFH = Start and end index of speech buffers */
-/* LBUFL, LBUFH = Start and end index of LPF speech buffer */
-/* MINWIN, MAXWIN = Min and Max length of voicing (and analysis) windows
-*/
-/* PWLEN, PWINH, PWINL = Length, upper and lower limits of pitch window
- */
-/* DVWINL, DVWINH = Default lower and upper limits of voicing window */
-/* The tables TAU and BUFLIM, and the variable PRECOEF, are not */
-/* Fortran PARAMETER's, but they are initialized with DATA */
-/* statements, and never modified. Thus, they need not have SAVE */
-/* statements for them to keep their values from one invocation to
-*/
-/* the next. */
-/* Local variables that need not be saved */
-/* Local state */
-/* Data Buffers */
-/* INBUF Raw speech (with DC bias removed each frame) */
-/* PEBUF Preemphasized speech */
-/* LPBUF Low pass speech buffer */
-/* IVBUF Inverse filtered speech */
-/* OSBUF Indexes of onsets in speech buffers */
-/* VWIN Voicing window indices */
-/* AWIN Analysis window indices */
-/* EWIN Energy window indices */
-/* VOIBUF Voicing decisions on windows in VWIN */
-/* RMSBUF RMS energy */
-/* RCBUF Reflection Coefficients */
-
-/* Pitch is handled separately from the above parameters. */
-/* The following variables deal with pitch: */
-/* MIDX Encoded initial pitch estimate for analysis frame */
-/* IPITCH Initial pitch computed for frame AF (decoded from MIDX) */
-/* PITCH The encoded pitch value (index into TAU) for the present */
-/* frame (delayed and smoothed by Dyptrack) */
- /* Parameter adjustments */
- if (speech) {
- --speech;
- }
- if (voice) {
- --voice;
- }
- if (rc) {
- --rc;
- }
-
- /* Function Body */
-
-/* Calculations are done on future frame due to requirements */
-/* of the pitch tracker. Delay RMS and RC's 2 frames to give */
-/* current frame parameters on return. */
-/* Update all buffers */
-
- inbuf = &(st->inbuf[0]);
- pebuf = &(st->pebuf[0]);
- lpbuf = &(st->lpbuf[0]);
- ivbuf = &(st->ivbuf[0]);
- bias = &(st->bias);
- osbuf = &(st->osbuf[0]);
- osptr = &(st->osptr);
- obound = &(st->obound[0]);
- vwin = &(st->vwin[0]);
- awin = &(st->awin[0]);
- voibuf = &(st->voibuf[0]);
- rmsbuf = &(st->rmsbuf[0]);
- rcbuf = &(st->rcbuf[0]);
- zpre = &(st->zpre);
-
- i__1 = 720 - contrl_1.lframe;
- for (i__ = 181; i__ <= i__1; ++i__) {
- inbuf[i__ - 181] = inbuf[contrl_1.lframe + i__ - 181];
- pebuf[i__ - 181] = pebuf[contrl_1.lframe + i__ - 181];
- }
- i__1 = 540 - contrl_1.lframe;
- for (i__ = 229; i__ <= i__1; ++i__) {
- ivbuf[i__ - 229] = ivbuf[contrl_1.lframe + i__ - 229];
- }
- i__1 = 720 - contrl_1.lframe;
- for (i__ = 25; i__ <= i__1; ++i__) {
- lpbuf[i__ - 25] = lpbuf[contrl_1.lframe + i__ - 25];
- }
- j = 1;
- i__1 = (*osptr) - 1;
- for (i__ = 1; i__ <= i__1; ++i__) {
- if (osbuf[i__ - 1] > contrl_1.lframe) {
- osbuf[j - 1] = osbuf[i__ - 1] - contrl_1.lframe;
- ++j;
- }
- }
- *osptr = j;
- voibuf[0] = voibuf[2];
- voibuf[1] = voibuf[3];
- for (i__ = 1; i__ <= 2; ++i__) {
- vwin[(i__ << 1) - 2] = vwin[((i__ + 1) << 1) - 2] - contrl_1.lframe;
- vwin[(i__ << 1) - 1] = vwin[((i__ + 1) << 1) - 1] - contrl_1.lframe;
- awin[(i__ << 1) - 2] = awin[((i__ + 1) << 1) - 2] - contrl_1.lframe;
- awin[(i__ << 1) - 1] = awin[((i__ + 1) << 1) - 1] - contrl_1.lframe;
-/* EWIN(*,J) is unused for J .NE. AF, so the following shift is
-*/
-/* unnecessary. It also causes error messages when the C versio
-n */
-/* of the code created from this by f2c is run with Purify. It
-*/
-/* correctly complains that uninitialized memory is being read.
-*/
-/* EWIN(1,I) = EWIN(1,I+1) - LFRAME */
-/* EWIN(2,I) = EWIN(2,I+1) - LFRAME */
- obound[i__ - 1] = obound[i__];
- voibuf[i__ * 2] = voibuf[(i__ + 1) * 2];
- voibuf[(i__ << 1) + 1] = voibuf[((i__ + 1) << 1) + 1];
- rmsbuf[i__ - 1] = rmsbuf[i__];
- i__1 = contrl_1.order;
- for (j = 1; j <= i__1; ++j) {
- rcbuf[j + i__ * 10 - 11] = rcbuf[j + (i__ + 1) * 10 - 11];
- }
- }
-/* Copy input speech, scale to sign+12 bit integers */
-/* Remove long term DC bias. */
-/* If the average value in the frame was over 1/4096 (after current
-*/
-/* BIAS correction), then subtract that much more from samples in */
-/* next frame. If the average value in the frame was under */
-/* -1/4096, add 1/4096 more to samples in next frame. In all other
-*/
-/* cases, keep BIAS the same. */
- temp = 0.f;
- i__1 = contrl_1.lframe;
- for (i__ = 1; i__ <= i__1; ++i__) {
- inbuf[720 - contrl_1.lframe + i__ - 181] = speech[i__] * 4096.f -
- (*bias);
- temp += inbuf[720 - contrl_1.lframe + i__ - 181];
- }
- if (temp > (real) contrl_1.lframe) {
- *bias += 1;
- }
- if (temp < (real) (-contrl_1.lframe)) {
- *bias += -1;
- }
-/* Place Voicing Window */
- i__ = 721 - contrl_1.lframe;
- preemp_(&inbuf[i__ - 181], &pebuf[i__ - 181], &contrl_1.lframe, &precoef,
- zpre);
- onset_(pebuf, osbuf, osptr, &c__10, &c__181, &c__720, &contrl_1.lframe, st);
-
-/* MAXOSP is just a debugging variable. */
-
-/* MAXOSP = MAX( MAXOSP, OSPTR ) */
-
- placev_(osbuf, osptr, &c__10, &obound[2], vwin, &c__3, &contrl_1.lframe,
- &c__90, &c__156, &c__307, &c__462);
-/* The Pitch Extraction algorithm estimates the pitch for a frame
-*/
-/* of speech by locating the minimum of the average magnitude difference
- */
-/* function (AMDF). The AMDF operates on low-pass, inverse filtered */
-/* speech. (The low-pass filter is an 800 Hz, 19 tap, equiripple, FIR
-*/
-/* filter and the inverse filter is a 2nd-order LPC filter.) The pitch
-*/
-/* estimate is later refined by dynamic programming (DYPTRK). However,
-*/
-/* since some of DYPTRK's parameters are a function of the voicing */
-/* decisions, a voicing decision must precede the final pitch estimation.
-*/
-/* See subroutines LPFILT, IVFILT, and TBDM. */
-/* LPFILT reads indices LBUFH-LFRAME-29 = 511 through LBUFH = 720 */
-/* of INBUF, and writes indices LBUFH+1-LFRAME = 541 through LBUFH
-*/
-/* = 720 of LPBUF. */
- lpfilt_(&inbuf[228], &lpbuf[384], &c__312, &contrl_1.lframe);
-/* IVFILT reads indices (PWINH-LFRAME-7) = 353 through PWINH = 540
-*/
-/* of LPBUF, and writes indices (PWINH-LFRAME+1) = 361 through */
-/* PWINH = 540 of IVBUF. */
- ivfilt_(&lpbuf[204], ivbuf, &c__312, &contrl_1.lframe, ivrc);
-/* TBDM reads indices PWINL = 229 through */
-/* (PWINL-1)+MAXWIN+(TAU(LTAU)-TAU(1))/2 = 452 of IVBUF, and writes
-*/
-/* indices 1 through LTAU = 60 of AMDF. */
- tbdm_(ivbuf, &c__156, tau, &c__60, amdf, &minptr, &maxptr, &mintau);
-/* Voicing decisions are made for each half frame of input speech.
-*/
-/* An initial voicing classification is made for each half of the */
-/* analysis frame, and the voicing decisions for the present frame */
-/* are finalized. See subroutine VOICIN. */
-/* The voicing detector (VOICIN) classifies the input signal as */
-/* unvoiced (including silence) or voiced using the AMDF windowed */
-/* maximum-to-minimum ratio, the zero crossing rate, energy measures, */
-/* reflection coefficients, and prediction gains. */
-/* The pitch and voicing rules apply smoothing and isolated */
-/* corrections to the pitch and voicing estimates and, in the process,
-*/
-/* introduce two frames of delay into the corrected pitch estimates and
-*/
-/* voicing decisions. */
- for (half = 1; half <= 2; ++half) {
- voicin_(&vwin[4], inbuf, lpbuf, buflim, &half, &amdf[minptr - 1], &
- amdf[maxptr - 1], &mintau, ivrc, obound, voibuf, &c__3, st);
- }
-/* Find the minimum cost pitch decision over several frames */
-/* given the current voicing decision and the AMDF array */
- dyptrk_(amdf, &c__60, &minptr, &voibuf[7], pitch, &midx, st);
- ipitch = tau[midx - 1];
-/* Place spectrum analysis and energy windows */
- placea_(&ipitch, voibuf, &obound[2], &c__3, vwin, awin, ewin, &
- contrl_1.lframe, &c__156);
-/* Remove short term DC bias over the analysis window, Put result in ABUF
-*/
- lanal = awin[5] + 1 - awin[4];
- dcbias_(&lanal, &pebuf[awin[4] - 181], abuf);
-/* ABUF(1:LANAL) is now defined. It is equal to */
-/* PEBUF(AWIN(1,AF):AWIN(2,AF)) corrected for short term DC bias. */
-/* Compute RMS over integer number of pitch periods within the */
-/* analysis window. */
-/* Note that in a hardware implementation this computation may be */
-/* simplified by using diagonal elements of PHI computed by MLOAD. */
- i__1 = ewin[5] - ewin[4] + 1;
- energy_(&i__1, &abuf[ewin[4] - awin[4]], &rmsbuf[2]);
-/* Matrix load and invert, check RC's for stability */
- mload_(&contrl_1.order, &c__1, &lanal, abuf, phi, psi);
- invert_(&contrl_1.order, phi, psi, &rcbuf[20]);
- rcchk_(&contrl_1.order, &rcbuf[10], &rcbuf[20]);
-/* Set return parameters */
- voice[1] = voibuf[2];
- voice[2] = voibuf[3];
- *rms = rmsbuf[0];
- i__1 = contrl_1.order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- rc[i__] = rcbuf[i__ - 1];
- }
- return 0;
-} /* analys_ */
diff --git a/1.2-netsec/codecs/lpc10/bsynz.c b/1.2-netsec/codecs/lpc10/bsynz.c
deleted file mode 100644
index 5971a1a22..000000000
--- a/1.2-netsec/codecs/lpc10/bsynz.c
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:18:55 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:58 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int bsynz_(real *coef, integer *ip, integer *iv, real *sout, real *rms, real *ratio, real *g2pass, struct lpc10_decoder_state *st);
-/* comlen contrl_ 12 */
-/*:ref: random_ 4 0 */
-#endif
-
-/* Common Block Declarations */
-
-extern struct {
- integer order, lframe;
- logical corrp;
-} contrl_;
-
-#define contrl_1 contrl_
-
-/* ***************************************************************** */
-
-/* BSYNZ Version 54 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:18:55 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:58 jaf
- * Initial revision
- * */
-/* Revision 1.4 1996/03/27 18:11:22 jaf */
-/* Changed the range of NOISE printed out in the debugging statements, */
-/* even though they are commented out. I didn't discover this until I */
-/* tried comparing two different versions of the LPC-10 coder, each with */
-/* full tracing enabled. */
-
-/* Revision 1.3 1996/03/26 19:33:23 jaf */
-/* Commented out trace statements. */
-
-/* Revision 1.2 1996/03/20 17:12:54 jaf */
-/* Added comments about which indices of array arguments are read or */
-/* written. */
-
-/* Rearranged local variable declarations to indicate which need to be */
-/* saved from one invocation to the next. Added entry INITBSYNZ to */
-/* reinitialize the local state variables, if desired. */
-
-/* Revision 1.1 1996/02/07 14:43:15 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* Synthesize One Pitch Epoch */
-
-/* Input: */
-/* COEF - Predictor coefficients */
-/* Indices 1 through ORDER read. */
-/* IP - Pitch period (number of samples to synthesize) */
-/* IV - Voicing for the current epoch */
-/* RMS - Energy for the current epoch */
-/* RATIO - Energy slope for plosives */
-/* G2PASS- Sharpening factor for 2 pass synthesis */
-/* Output: */
-/* SOUT - Synthesized speech */
-/* Indices 1 through IP written. */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this filter, or */
-/* reinitialize its state for any other reason, call the ENTRY */
-/* INITBSYNZ. */
-
-/* Subroutine */ int bsynz_(real *coef, integer *ip, integer *iv,
- real *sout, real *rms, real *ratio, real *g2pass,
- struct lpc10_decoder_state *st)
-{
- /* Initialized data */
-
- integer *ipo;
- real *rmso;
- static integer kexc[25] = { 8,-16,26,-48,86,-162,294,-502,718,-728,184,
- 672,-610,-672,184,728,718,502,294,162,86,48,26,16,8 };
- real *exc;
- real *exc2;
- real *lpi1;
- real *lpi2;
- real *lpi3;
- real *hpi1;
- real *hpi2;
- real *hpi3;
-
- /* System generated locals */
- integer i__1, i__2;
- real r__1, r__2;
-
- /* Builtin functions */
- double sqrt(doublereal);
-
- /* Local variables */
- real gain, xssq;
- integer i__, j, k;
- real noise[166], pulse;
- integer px;
- real sscale;
- extern integer random_(struct lpc10_decoder_state *);
- real xy, sum, ssq;
- real lpi0, hpi0;
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:18:55 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:58 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Arguments */
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:18:55 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:58 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:05:55 jaf */
-/* Commented out the common block variables that are not needed by the */
-/* embedded version. */
-
-/* Revision 1.2 1996/03/26 19:34:50 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:44:09 jaf */
-/* Initial revision */
-
-/* LPC Processing control variables: */
-
-/* *** Read-only: initialized in setup */
-
-/* Files for Speech, Parameter, and Bitstream Input & Output, */
-/* and message and debug outputs. */
-
-/* Here are the only files which use these variables: */
-
-/* lpcsim.f setup.f trans.f error.f vqsetup.f */
-
-/* Many files which use fdebug are not listed, since it is only used in */
-/* those other files conditionally, to print trace statements. */
-/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* LPC order, Frame size, Quantization rate, Bits per frame, */
-/* Error correction */
-/* Subroutine SETUP is the only place where order is assigned a value, */
-/* and that value is 10. It could increase efficiency 1% or so to */
-/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
-*/
-/* a variable in a COMMON block, since it is used in many places in the */
-/* core of the coding and decoding routines. Actually, I take that back.
-*/
-/* At least when compiling with f2c, the upper bound of DO loops is */
-/* stored in a local variable before the DO loop begins, and then that is
-*/
-/* compared against on each iteration. */
-/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
-/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
-/* is used in only a few places, and never in the core coding and */
-/* decoding routines, so it could be eliminated entirely. */
-/* nbits is similar to quant, and is given a value of 54 in SETUP. */
-/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
-/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
-/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
-*/
-/* a constant or a variable, since it is only examined once per frame. */
-/* Leaving it as a variable that is set to .TRUE. seems like a good */
-/* idea, since it does enable some error-correction capability for */
-/* unvoiced frames, with no change in the coding rate, and no noticeable
-*/
-/* quality difference in the decoded speech. */
-/* integer quant, nbits */
-/* *** Read/write: variables for debugging, not needed for LPC algorithm
-*/
-
-/* Current frame, Unstable frames, Output clip count, Max onset buffer,
-*/
-/* Debug listing detail level, Line count on listing page */
-
-/* nframe is not needed for an embedded LPC10 at all. */
-/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
-/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
-/* an application, I would recommend removing the call to ERROR in RCCHK,
-*/
-/* and remove ERROR and nunsfm completely. */
-/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
-*/
-/* sread.f. When LPC10 is embedded into an application, one might want */
-/* to cause it to be incremented in a routine that takes the output of */
-/* SYNTHS and sends it to an audio device. It could be optionally */
-/* displayed, for those that might want to know what it is. */
-/* maxosp is never initialized to 0 in SETUP, although it probably should
-*/
-/* be, and it is updated in subroutine ANALYS. I doubt that its value */
-/* would be of much interest to an application in which LPC10 is */
-/* embedded. */
-/* listl and lincnt are not needed for an embedded LPC10 at all. */
-/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* common /contrl/ quant, nbits */
-/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* Function return value definitions */
-/* Parameters/constants */
-/* KEXC is not a Fortran PARAMETER, but it is an array initialized
-*/
-/* with a DATA statement that is never modified. */
-/* Local variables that need not be saved */
-/* NOISE is declared with range (1:MAXPIT+MAXORD), but only indices
-*/
-/* ORDER+1 through ORDER+IP are ever used, and I think that IP */
-/* .LE. MAXPIT. Why not declare it to be in the range (1:MAXPIT) */
-/* and use that range? */
-/* Local state */
-/* I believe that only indices 1 through ORDER of EXC need to be */
-/* saved from one invocation to the next, but we may as well save */
-/* the whole array. */
-/* None of these local variables were given initial values in the */
-/* original code. I'm guessing that 0 is a reasonable initial */
-/* value for all of them. */
- /* Parameter adjustments */
- if (coef) {
- --coef;
- }
- if (sout) {
- --sout;
- }
-
- /* Function Body */
- ipo = &(st->ipo);
- exc = &(st->exc[0]);
- exc2 = &(st->exc2[0]);
- lpi1 = &(st->lpi1);
- lpi2 = &(st->lpi2);
- lpi3 = &(st->lpi3);
- hpi1 = &(st->hpi1);
- hpi2 = &(st->hpi2);
- hpi3 = &(st->hpi3);
- rmso = &(st->rmso_bsynz);
-
-/* MAXPIT+MAXORD=166 */
-/* Calculate history scale factor XY and scale filter state */
-/* Computing MIN */
- r__1 = *rmso / (*rms + 1e-6f);
- xy = min(r__1,8.f);
- *rmso = *rms;
- i__1 = contrl_1.order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- exc2[i__ - 1] = exc2[*ipo + i__ - 1] * xy;
- }
- *ipo = *ip;
- if (*iv == 0) {
-/* Generate white noise for unvoiced */
- i__1 = *ip;
- for (i__ = 1; i__ <= i__1; ++i__) {
- exc[contrl_1.order + i__ - 1] = (real) (random_(st) / 64);
- }
-/* Impulse doublet excitation for plosives */
-/* (RANDOM()+32768) is in the range 0 to 2**16-1. Therefore the
- */
-/* following expression should be evaluated using integers with
-at */
-/* least 32 bits (16 isn't enough), and PX should be in the rang
-e */
-/* ORDER+1+0 through ORDER+1+(IP-2) .EQ. ORDER+IP-1. */
- px = (random_(st) + 32768) * (*ip - 1) / 65536 + contrl_1.order + 1;
- r__1 = *ratio / 4 * 1.f;
- pulse = r__1 * 342;
- if (pulse > 2e3f) {
- pulse = 2e3f;
- }
- exc[px - 1] += pulse;
- exc[px] -= pulse;
-/* Load voiced excitation */
- } else {
- sscale = sqrt((real) (*ip)) / 6.928f;
- i__1 = *ip;
- for (i__ = 1; i__ <= i__1; ++i__) {
- exc[contrl_1.order + i__ - 1] = 0.f;
- if (i__ <= 25) {
- exc[contrl_1.order + i__ - 1] = sscale * kexc[i__ - 1];
- }
- lpi0 = exc[contrl_1.order + i__ - 1];
- r__2 = exc[contrl_1.order + i__ - 1] * .125f + *lpi1 * .75f;
- r__1 = r__2 + *lpi2 * .125f;
- exc[contrl_1.order + i__ - 1] = r__1 + *lpi3 * 0.f;
- *lpi3 = *lpi2;
- *lpi2 = *lpi1;
- *lpi1 = lpi0;
- }
- i__1 = *ip;
- for (i__ = 1; i__ <= i__1; ++i__) {
- noise[contrl_1.order + i__ - 1] = random_(st) * 1.f / 64;
- hpi0 = noise[contrl_1.order + i__ - 1];
- r__2 = noise[contrl_1.order + i__ - 1] * -.125f + *hpi1 * .25f;
- r__1 = r__2 + *hpi2 * -.125f;
- noise[contrl_1.order + i__ - 1] = r__1 + *hpi3 * 0.f;
- *hpi3 = *hpi2;
- *hpi2 = *hpi1;
- *hpi1 = hpi0;
- }
- i__1 = *ip;
- for (i__ = 1; i__ <= i__1; ++i__) {
- exc[contrl_1.order + i__ - 1] += noise[contrl_1.order + i__ - 1];
- }
- }
-/* Synthesis filters: */
-/* Modify the excitation with all-zero filter 1 + G*SUM */
- xssq = 0.f;
- i__1 = *ip;
- for (i__ = 1; i__ <= i__1; ++i__) {
- k = contrl_1.order + i__;
- sum = 0.f;
- i__2 = contrl_1.order;
- for (j = 1; j <= i__2; ++j) {
- sum += coef[j] * exc[k - j - 1];
- }
- sum *= *g2pass;
- exc2[k - 1] = sum + exc[k - 1];
- }
-/* Synthesize using the all pole filter 1 / (1 - SUM) */
- i__1 = *ip;
- for (i__ = 1; i__ <= i__1; ++i__) {
- k = contrl_1.order + i__;
- sum = 0.f;
- i__2 = contrl_1.order;
- for (j = 1; j <= i__2; ++j) {
- sum += coef[j] * exc2[k - j - 1];
- }
- exc2[k - 1] = sum + exc2[k - 1];
- xssq += exc2[k - 1] * exc2[k - 1];
- }
-/* Save filter history for next epoch */
- i__1 = contrl_1.order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- exc[i__ - 1] = exc[*ip + i__ - 1];
- exc2[i__ - 1] = exc2[*ip + i__ - 1];
- }
-/* Apply gain to match RMS */
- r__1 = *rms * *rms;
- ssq = r__1 * *ip;
- gain = sqrt(ssq / xssq);
- i__1 = *ip;
- for (i__ = 1; i__ <= i__1; ++i__) {
- sout[i__] = gain * exc2[contrl_1.order + i__ - 1];
- }
- return 0;
-} /* bsynz_ */
diff --git a/1.2-netsec/codecs/lpc10/chanwr.c b/1.2-netsec/codecs/lpc10/chanwr.c
deleted file mode 100644
index f35efd179..000000000
--- a/1.2-netsec/codecs/lpc10/chanwr.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:20:24 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Revision 1.1 1996/08/19 22:40:31 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-/* *********************************************************************** */
-
-/* CHANL Version 49 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:20:24 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Revision 1.1 1996/08/19 22:40:31 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/21 15:14:57 jaf */
-/* Added comments about which indices of argument arrays are read or */
-/* written, and about the one bit of local state in CHANWR. CHANRD */
-/* has no local state. */
-
-/* Revision 1.2 1996/03/13 18:55:10 jaf */
-/* Comments added explaining which of the local variables of this */
-/* subroutine need to be saved from one invocation to the next, and which */
-/* do not. */
-
-/* Revision 1.1 1996/02/07 14:43:31 jaf */
-/* Initial revision */
-
-
-/* *********************************************************************** */
-
-/* CHANWR: */
-/* Place quantized parameters into bitstream */
-
-/* Input: */
-/* ORDER - Number of reflection coefficients (not really variable) */
-/* IPITV - Quantized pitch/voicing parameter */
-/* IRMS - Quantized energy parameter */
-/* IRC - Quantized reflection coefficients */
-/* Indices 1 through ORDER read. */
-/* Output: */
-/* IBITS - Serial bitstream */
-/* Indices 1 through 54 written. */
-/* Bit 54, the SYNC bit, alternates from one call to the next. */
-
-/* Subroutine CHANWR maintains one bit of local state from one call to */
-/* the next, in the variable ISYNC. I believe that this one bit is only */
-/* intended to allow a receiver to resynchronize its interpretation of */
-/* the bit stream, by looking for which of the 54 bits alternates every */
-/* frame time. This is just a simple framing mechanism that is not */
-/* useful when other, higher overhead framing mechanisms are used to */
-/* transmit the coded frames. */
-
-/* I'm not going to make an entry to reinitialize this bit, since it */
-/* doesn't help a receiver much to know whether the first sync bit is a 0 */
-/* or a 1. It needs to examine several frames in sequence to have */
-/* reasonably good assurance that its framing is correct. */
-
-
-/* CHANRD: */
-/* Reconstruct parameters from bitstream */
-
-/* Input: */
-/* ORDER - Number of reflection coefficients (not really variable) */
-/* IBITS - Serial bitstream */
-/* Indices 1 through 53 read (SYNC bit is ignored). */
-/* Output: */
-/* IPITV - Quantized pitch/voicing parameter */
-/* IRMS - Quantized energy parameter */
-/* IRC - Quantized reflection coefficients */
-/* Indices 1 through ORDER written */
-
-/* Entry CHANRD has no local state. */
-
-
-
-/* IBITS is 54 bits of LPC data ordered as follows: */
-/* R1-0, R2-0, R3-0, P-0, A-0, */
-/* R1-1, R2-1, R3-1, P-1, A-1, */
-/* R1-2, R4-0, R3-2, A-2, P-2, R4-1, */
-/* R1-3, R2-2, R3-3, R4-2, A-3, */
-/* R1-4, R2-3, R3-4, R4-3, A-4, */
-/* P-3, R2-4, R7-0, R8-0, P-4, R4-4, */
-/* R5-0, R6-0, R7-1,R10-0, R8-1, */
-/* R5-1, R6-1, R7-2, R9-0, P-5, */
-/* R5-2, R6-2,R10-1, R8-2, P-6, R9-1, */
-/* R5-3, R6-3, R7-3, R9-2, R8-3, SYNC */
-/* Subroutine */ int chanwr_0_(int n__, integer *order, integer *ipitv,
- integer *irms, integer *irc, integer *ibits,
- struct lpc10_encoder_state *st)
-{
- /* Initialized data */
-
- integer *isync;
- static integer bit[10] = { 2,4,8,8,8,8,16,16,16,16 };
- static integer iblist[53] = { 13,12,11,1,2,13,12,11,1,2,13,10,11,2,1,10,
- 13,12,11,10,2,13,12,11,10,2,1,12,7,6,1,10,9,8,7,4,6,9,8,7,5,1,9,8,
- 4,6,1,5,9,8,7,5,6 };
-
- /* System generated locals */
- integer i__1;
-
- /* Local variables */
- integer itab[13], i__;
-
-/* Arguments */
-/* Parameters/constants */
-/* These arrays are not Fortran PARAMETER's, but they are defined */
-/* by DATA statements below, and their contents are never altered.
-*/
-/* Local variables that need not be saved */
-/* Local state */
-/* ISYNC is only used by CHANWR, not by ENTRY CHANRD. */
-
- /* Parameter adjustments */
- --irc;
- --ibits;
-
- /* Function Body */
- switch(n__) {
- case 1: goto L_chanrd;
- }
-
- isync = &(st->isync);
-
-/* ***********************************************************************
- */
-/* Place quantized parameters into bitstream */
-/* ***********************************************************************
- */
-/* Place parameters into ITAB */
- itab[0] = *ipitv;
- itab[1] = *irms;
- itab[2] = 0;
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- itab[i__ + 2] = irc[*order + 1 - i__] & 32767;
- }
-/* Put 54 bits into IBITS array */
- for (i__ = 1; i__ <= 53; ++i__) {
- ibits[i__] = itab[iblist[i__ - 1] - 1] & 1;
- itab[iblist[i__ - 1] - 1] /= 2;
- }
- ibits[54] = *isync & 1;
- *isync = 1 - *isync;
- return 0;
-/* ***********************************************************************
- */
-/* Reconstruct parameters from bitstream */
-/* ***********************************************************************
- */
-
-L_chanrd:
-/* Reconstruct ITAB */
- for (i__ = 1; i__ <= 13; ++i__) {
- itab[i__ - 1] = 0;
- }
- for (i__ = 1; i__ <= 53; ++i__) {
- itab[iblist[54 - i__ - 1] - 1] = (itab[iblist[54 - i__ - 1] - 1] << 1)
- + ibits[54 - i__];
- }
-/* Sign extend RC's */
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- if ((itab[i__ + 2] & bit[i__ - 1]) != 0) {
- itab[i__ + 2] -= bit[i__ - 1] << 1;
- }
- }
-/* Restore variables */
- *ipitv = itab[0];
- *irms = itab[1];
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- irc[i__] = itab[*order + 4 - i__ - 1];
- }
- return 0;
-} /* chanwr_ */
-
-/* Subroutine */ int chanwr_(integer *order, integer *ipitv, integer *irms,
- integer *irc, integer *ibits, struct lpc10_encoder_state *st)
-{
- return chanwr_0_(0, order, ipitv, irms, irc, ibits, st);
- }
-
-/* Subroutine */ int chanrd_(integer *order, integer *ipitv, integer *irms,
- integer *irc, integer *ibits)
-{
- return chanwr_0_(1, order, ipitv, irms, irc, ibits, 0);
- }
diff --git a/1.2-netsec/codecs/lpc10/dcbias.c b/1.2-netsec/codecs/lpc10/dcbias.c
deleted file mode 100644
index 62d774428..000000000
--- a/1.2-netsec/codecs/lpc10/dcbias.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:40:23 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int dcbias_(integer *len, real *speech, real *sigout);
-#endif
-
-/* ********************************************************************* */
-
-/* DCBIAS Version 50 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:40:23 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/18 21:19:22 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 16:44:53 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:44:21 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* Calculate and remove DC bias from buffer. */
-
-/* Input: */
-/* LEN - Length of speech buffers */
-/* SPEECH - Input speech buffer */
-/* Indices 1 through LEN read. */
-/* Output: */
-/* SIGOUT - Output speech buffer */
-/* Indices 1 through LEN written */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int dcbias_(integer *len, real *speech, real *sigout)
-{
- /* System generated locals */
- integer i__1;
-
- /* Local variables */
- real bias;
- integer i__;
-
-/* Arguments */
-/* Local variables that need not be saved */
- /* Parameter adjustments */
- --sigout;
- --speech;
-
- /* Function Body */
- bias = 0.f;
- i__1 = *len;
- for (i__ = 1; i__ <= i__1; ++i__) {
- bias += speech[i__];
- }
- bias /= *len;
- i__1 = *len;
- for (i__ = 1; i__ <= i__1; ++i__) {
- sigout[i__] = speech[i__] - bias;
- }
- return 0;
-} /* dcbias_ */
-
diff --git a/1.2-netsec/codecs/lpc10/decode.c b/1.2-netsec/codecs/lpc10/decode.c
deleted file mode 100644
index 8a1661647..000000000
--- a/1.2-netsec/codecs/lpc10/decode.c
+++ /dev/null
@@ -1,625 +0,0 @@
-/*
-
-$Log$
-Revision 1.16 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.15 2003/09/19 01:20:22 markster
-Code cleanups (bug #66)
-
-Revision 1.2 2003/09/19 01:20:22 markster
-Code cleanups (bug #66)
-
-Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:22:39 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:38 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st);
-/* comlen contrl_ 12 */
-/*:ref: ham84_ 14 3 4 4 4 */
-/*:ref: median_ 4 3 4 4 4 */
-#endif
-
-/* Common Block Declarations */
-
-extern struct {
- integer order, lframe;
- logical corrp;
-} contrl_;
-
-#define contrl_1 contrl_
-
-/* Table of constant values */
-
-static integer c__2 = 2;
-
-/* ***************************************************************** */
-
-/* DECODE Version 54 */
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.2 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:22:39 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:38 jaf
- * Initial revision
- * */
-/* Revision 1.5 1996/05/23 20:06:03 jaf */
-/* Assigned PITCH a "default" value on the first call, since otherwise it */
-/* would be left uninitialized. */
-
-/* Revision 1.4 1996/03/26 19:35:18 jaf */
-/* Commented out trace statements. */
-
-/* Revision 1.3 1996/03/21 21:10:50 jaf */
-/* Added entry INITDECODE to reinitialize the local state of subroutine */
-/* DECODE. */
-
-/* Revision 1.2 1996/03/21 21:04:50 jaf */
-/* Determined which local variables should be saved from one invocation */
-/* to the next, and guessed initial values for some that should have been */
-/* saved, but weren't given initial values. Many of the arrays are */
-/* "constants", and many local variables are only used if the "global" */
-/* variable CORRP is .TRUE. */
-
-/* Added comments explaining which indices of array arguments are read or */
-/* written. */
-
-/* Revision 1.1 1996/02/12 03:21:10 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* This subroutine provides error correction and decoding */
-/* for all LPC parameters */
-
-/* Input: */
-/* IPITV - Index value of pitch */
-/* IRMS - Coded Energy */
-/* CORRP - Error correction: */
-/* If FALSE, parameters are decoded directly with no delay. If TRUE, */
-/* most important parameter bits are protected by Hamming code and */
-/* median smoothed. This requires an additional frame of delay. */
-/* Input/Output: */
-/* IRC - Coded Reflection Coefficients */
-/* Indices 1 through ORDER always read, then written. */
-/* Output: */
-/* VOICE - Half frame voicing decisions */
-/* Indices 1 through 2 written. */
-/* PITCH - Decoded pitch */
-/* RMS - Energy */
-/* RC - Reflection coefficients */
-/* Indices 1 through ORDER written. */
-
-/* NOTE: Zero RC's should be done more directly, but this would affect */
-/* coded parameter printout. */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this filter, or */
-/* reinitialize its state for any other reason, call the ENTRY */
-/* INITDECODE. */
-
-/* Subroutine */ int decode_(integer *ipitv, integer *irms,
- integer *irc, integer *voice, integer *pitch, real *rms, real *rc,
- struct lpc10_decoder_state *st)
-{
- /* Initialized data */
-
- logical *first;
- static integer ethrs = 2048;
- static integer ethrs1 = 128;
- static integer ethrs2 = 1024;
- static integer ethrs3 = 2048;
- static integer ivtab[32] = { 24960,24960,24960,24960,25480,25480,25483,
- 25480,16640,1560,1560,1560,16640,1816,1563,1560,24960,24960,24859,
- 24856,26001,25881,25915,25913,1560,1560,7800,3640,1561,1561,3643,
- 3641 };
- static real corth[32] /* was [4][8] */ = { 32767.f,10.f,5.f,0.f,
- 32767.f,8.f,4.f,0.f,32.f,6.4f,3.2f,0.f,32.f,6.4f,3.2f,0.f,32.f,
- 11.2f,6.4f,0.f,32.f,11.2f,6.4f,0.f,16.f,5.6f,3.2f,0.f,16.f,5.6f,
- 3.2f,0.f };
- static integer detau[128] = { 0,0,0,3,0,3,3,31,0,3,3,21,3,3,29,30,0,3,3,
- 20,3,25,27,26,3,23,58,22,3,24,28,3,0,3,3,3,3,39,33,32,3,37,35,36,
- 3,38,34,3,3,42,46,44,50,40,48,3,54,3,56,3,52,3,3,1,0,3,3,108,3,78,
- 100,104,3,84,92,88,156,80,96,3,3,74,70,72,66,76,68,3,62,3,60,3,64,
- 3,3,1,3,116,132,112,148,152,3,3,140,3,136,3,144,3,3,1,124,120,128,
- 3,3,3,3,1,3,3,3,1,3,1,1,1 };
- static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,
- 384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,
- 92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,
- 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
- static integer detab7[32] = { 4,11,18,25,32,39,46,53,60,66,72,77,82,87,92,
- 96,101,104,108,111,114,115,117,119,121,122,123,124,125,126,127,
- 127 };
- static real descl[8] = { .6953f,.625f,.5781f,.5469f,.5312f,.5391f,.4688f,
- .3828f };
- integer *ivp2h;
- static integer deadd[8] = { 1152,-2816,-1536,-3584,-1280,-2432,768,-1920 }
- ;
- static integer qb[8] = { 511,511,1023,1023,1023,1023,2047,4095 };
- static integer nbit[10] = { 8,8,5,5,4,4,4,4,3,2 };
- static integer zrc[10] = { 0,0,0,0,0,3,0,2,0,0 };
- static integer bit[5] = { 2,4,8,16,32 };
- integer *iovoic;
- integer *iavgp;
- integer *iptold;
- integer *erate;
- integer *drc;
- integer *dpit;
- integer *drms;
-
- /* System generated locals */
- integer i__1, i__2;
-
- /* Builtin functions */
- integer pow_ii(integer *, integer *);
-
- /* Local variables */
- extern /* Subroutine */ int ham84_(integer *, integer *, integer *);
- integer ipit, iout, i__, icorf, index, ivoic, ixcor, i1, i2, i4;
- extern integer median_(integer *, integer *, integer *);
- integer ishift, errcnt, lsb;
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.2 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:22:39 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:38 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Arguments */
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.2 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:22:39 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:38 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:05:55 jaf */
-/* Commented out the common block variables that are not needed by the */
-/* embedded version. */
-
-/* Revision 1.2 1996/03/26 19:34:50 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:44:09 jaf */
-/* Initial revision */
-
-/* LPC Processing control variables: */
-
-/* *** Read-only: initialized in setup */
-
-/* Files for Speech, Parameter, and Bitstream Input & Output, */
-/* and message and debug outputs. */
-
-/* Here are the only files which use these variables: */
-
-/* lpcsim.f setup.f trans.f error.f vqsetup.f */
-
-/* Many files which use fdebug are not listed, since it is only used in */
-/* those other files conditionally, to print trace statements. */
-/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* LPC order, Frame size, Quantization rate, Bits per frame, */
-/* Error correction */
-/* Subroutine SETUP is the only place where order is assigned a value, */
-/* and that value is 10. It could increase efficiency 1% or so to */
-/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
-*/
-/* a variable in a COMMON block, since it is used in many places in the */
-/* core of the coding and decoding routines. Actually, I take that back.
-*/
-/* At least when compiling with f2c, the upper bound of DO loops is */
-/* stored in a local variable before the DO loop begins, and then that is
-*/
-/* compared against on each iteration. */
-/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
-/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
-/* is used in only a few places, and never in the core coding and */
-/* decoding routines, so it could be eliminated entirely. */
-/* nbits is similar to quant, and is given a value of 54 in SETUP. */
-/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
-/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
-/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
-*/
-/* a constant or a variable, since it is only examined once per frame. */
-/* Leaving it as a variable that is set to .TRUE. seems like a good */
-/* idea, since it does enable some error-correction capability for */
-/* unvoiced frames, with no change in the coding rate, and no noticeable
-*/
-/* quality difference in the decoded speech. */
-/* integer quant, nbits */
-/* *** Read/write: variables for debugging, not needed for LPC algorithm
-*/
-
-/* Current frame, Unstable frames, Output clip count, Max onset buffer,
-*/
-/* Debug listing detail level, Line count on listing page */
-
-/* nframe is not needed for an embedded LPC10 at all. */
-/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
-/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
-/* an application, I would recommend removing the call to ERROR in RCCHK,
-*/
-/* and remove ERROR and nunsfm completely. */
-/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
-*/
-/* sread.f. When LPC10 is embedded into an application, one might want */
-/* to cause it to be incremented in a routine that takes the output of */
-/* SYNTHS and sends it to an audio device. It could be optionally */
-/* displayed, for those that might want to know what it is. */
-/* maxosp is never initialized to 0 in SETUP, although it probably should
-*/
-/* be, and it is updated in subroutine ANALYS. I doubt that its value */
-/* would be of much interest to an application in which LPC10 is */
-/* embedded. */
-/* listl and lincnt are not needed for an embedded LPC10 at all. */
-/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* common /contrl/ quant, nbits */
-/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* Function return value definitions */
-
-/* Parameters/constants */
-
-/* The variables below that are not Fortran PARAMETER's are */
-/* initialized with DATA statements, and then never modified. */
-/* The following are used regardless of CORRP's value. */
-
-/* DETAU, NBIT, QB, DEADD, DETAB7, RMST, DESCL */
-
-/* The following are used only if CORRP is .TRUE. */
-
-/* ETHRS, ETHRS1, ETHRS2, ETHRS3, IVTAB, BIT, CORTH, ZRC */
-
-/* Local variables that need not be saved */
-
-/* The following are used regardless of CORRP's value */
-/* The following are used only if CORRP is .TRUE. */
-
-/* Local state */
-
-/* The following are used regardless of CORRP's value */
-/* The following are used only if CORRP is .TRUE. */
-/* I am guessing the initial values for IVP2H, IOVOIC, DRC, DPIT, */
-/* and DRMS. They should be checked to see if they are reasonable.
-*/
-/* I'm also guessing for ERATE, but I think 0 is the right initial
-*/
-/* value. */
- /* Parameter adjustments */
- if (irc) {
- --irc;
- }
- if (voice) {
- --voice;
- }
- if (rc) {
- --rc;
- }
-
- /* Function Body */
-
- iptold = &(st->iptold);
- first = &(st->first);
- ivp2h = &(st->ivp2h);
- iovoic = &(st->iovoic);
- iavgp = &(st->iavgp);
- erate = &(st->erate);
- drc = &(st->drc[0]);
- dpit = &(st->dpit[0]);
- drms = &(st->drms[0]);
-
-/* DATA statements for "constants" defined above. */
-/* IF (LISTL.GE.3) WRITE(FDEBUG,800) IPITV,IRMS,(IRC(J),J=1,ORDER) */
-/* 800 FORMAT(1X,' <<ERRCOR IN>>',T32,6X,I6,I5,T50,10I8) */
-/* If no error correction, do pitch and voicing then jump to decode */
- i4 = detau[*ipitv];
- if (! contrl_1.corrp) {
- voice[1] = 1;
- voice[2] = 1;
- if (*ipitv <= 1) {
- voice[1] = 0;
- }
- if (*ipitv == 0 || *ipitv == 2) {
- voice[2] = 0;
- }
- *pitch = i4;
- if (*pitch <= 4) {
- *pitch = *iptold;
- }
- if (voice[1] == 1 && voice[2] == 1) {
- *iptold = *pitch;
- }
- if (voice[1] != voice[2]) {
- *pitch = *iptold;
- }
- goto L900;
- }
-/* Do error correction pitch and voicing */
- if (i4 > 4) {
- dpit[0] = i4;
- ivoic = 2;
- *iavgp = (*iavgp * 15 + i4 + 8) / 16;
- } else {
- ivoic = i4;
- dpit[0] = *iavgp;
- }
- drms[0] = *irms;
- i__1 = contrl_1.order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- drc[i__ * 3 - 3] = irc[i__];
- }
-/* Determine index to IVTAB from V/UV decision */
-/* If error rate is high then use alternate table */
- index = (*ivp2h << 4) + (*iovoic << 2) + ivoic + 1;
- i1 = ivtab[index - 1];
- ipit = i1 & 3;
- icorf = i1 / 8;
- if (*erate < ethrs) {
- icorf /= 64;
- }
-/* Determine error rate: 4=high 1=low */
- ixcor = 4;
- if (*erate < ethrs3) {
- ixcor = 3;
- }
- if (*erate < ethrs2) {
- ixcor = 2;
- }
- if (*erate < ethrs1) {
- ixcor = 1;
- }
-/* Voice/unvoice decision determined from bits 0 and 1 of IVTAB */
- voice[1] = icorf / 2 & 1;
- voice[2] = icorf & 1;
-/* Skip decoding on first frame because present data not yet available */
- if (*first) {
- *first = FALSE_;
-/* Assign PITCH a "default" value on the first call, since */
-/* otherwise it would be left uninitialized. The two lines
-*/
-/* below were copied from above, since it seemed like a */
-/* reasonable thing to do for the first call. */
- *pitch = i4;
- if (*pitch <= 4) {
- *pitch = *iptold;
- }
- goto L500;
- }
-/* If bit 4 of ICORF is set then correct RMS and RC(1) - RC(4). */
-/* Determine error rate and correct errors using a Hamming 8,4 code */
-/* during transition or unvoiced frame. If IOUT is negative, */
-/* more than 1 error occurred, use previous frame's parameters. */
- if ((icorf & bit[3]) != 0) {
- errcnt = 0;
- lsb = drms[1] & 1;
- index = (drc[22] << 4) + drms[1] / 2;
- ham84_(&index, &iout, &errcnt);
- drms[1] = drms[2];
- if (iout >= 0) {
- drms[1] = (iout << 1) + lsb;
- }
- for (i__ = 1; i__ <= 4; ++i__) {
- if (i__ == 1) {
- i1 = ((drc[25] & 7) << 1) + (drc[28] & 1);
- } else {
- i1 = drc[(9 - i__) * 3 - 2] & 15;
- }
- i2 = drc[(5 - i__) * 3 - 2] & 31;
- lsb = i2 & 1;
- index = (i1 << 4) + i2 / 2;
- ham84_(&index, &iout, &errcnt);
- if (iout >= 0) {
- iout = (iout << 1) + lsb;
- if ((iout & 16) == 16) {
- iout += -32;
- }
- } else {
- iout = drc[(5 - i__) * 3 - 1];
- }
- drc[(5 - i__) * 3 - 2] = iout;
- }
-/* Determine error rate */
- *erate = *erate * .96875f + errcnt * 102;
- }
-/* Get unsmoothed RMS, RC's, and PITCH */
- *irms = drms[1];
- i__1 = contrl_1.order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- irc[i__] = drc[i__ * 3 - 2];
- }
- if (ipit == 1) {
- dpit[1] = dpit[2];
- }
- if (ipit == 3) {
- dpit[1] = dpit[0];
- }
- *pitch = dpit[1];
-/* If bit 2 of ICORF is set then smooth RMS and RC's, */
- if ((icorf & bit[1]) != 0) {
- if ((i__1 = drms[1] - drms[0], (real) abs(i__1)) >= corth[ixcor + 3]
- && (i__2 = drms[1] - drms[2], (real) abs(i__2)) >= corth[
- ixcor + 3]) {
- *irms = median_(&drms[2], &drms[1], drms);
- }
- for (i__ = 1; i__ <= 6; ++i__) {
- if ((i__1 = drc[i__ * 3 - 2] - drc[i__ * 3 - 3], (real) abs(i__1))
- >= corth[ixcor + ((i__ + 2) << 2) - 5] && (i__2 = drc[i__ *
- 3 - 2] - drc[i__ * 3 - 1], (real) abs(i__2)) >= corth[
- ixcor + ((i__ + 2) << 2) - 5]) {
- irc[i__] = median_(&drc[i__ * 3 - 1], &drc[i__ * 3 - 2], &drc[
- i__ * 3 - 3]);
- }
- }
- }
-/* If bit 3 of ICORF is set then smooth pitch */
- if ((icorf & bit[2]) != 0) {
- if ((i__1 = dpit[1] - dpit[0], (real) abs(i__1)) >= corth[ixcor - 1]
- && (i__2 = dpit[1] - dpit[2], (real) abs(i__2)) >= corth[
- ixcor - 1]) {
- *pitch = median_(&dpit[2], &dpit[1], dpit);
- }
- }
-/* If bit 5 of ICORF is set then RC(5) - RC(10) are loaded with */
-/* values so that after quantization bias is removed in decode */
-/* the values will be zero. */
-L500:
- if ((icorf & bit[4]) != 0) {
- i__1 = contrl_1.order;
- for (i__ = 5; i__ <= i__1; ++i__) {
- irc[i__] = zrc[i__ - 1];
- }
- }
-/* House keeping - one frame delay */
- *iovoic = ivoic;
- *ivp2h = voice[2];
- dpit[2] = dpit[1];
- dpit[1] = dpit[0];
- drms[2] = drms[1];
- drms[1] = drms[0];
- i__1 = contrl_1.order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- drc[i__ * 3 - 1] = drc[i__ * 3 - 2];
- drc[i__ * 3 - 2] = drc[i__ * 3 - 3];
- }
-L900:
-/* IF (LISTL.GE.3)WRITE(FDEBUG,801)VOICE,PITCH,IRMS,(IRC(J),J=1,ORDER) */
-/* 801 FORMAT(1X,'<<ERRCOR OUT>>',T32,2I3,I6,I5,T50,10I8) */
-/* Decode RMS */
- *irms = rmst[(31 - *irms) * 2];
-/* Decode RC(1) and RC(2) from log-area-ratios */
-/* Protect from illegal coded value (-16) caused by bit errors */
- for (i__ = 1; i__ <= 2; ++i__) {
- i2 = irc[i__];
- i1 = 0;
- if (i2 < 0) {
- i1 = 1;
- i2 = -i2;
- if (i2 > 15) {
- i2 = 0;
- }
- }
- i2 = detab7[i2 * 2];
- if (i1 == 1) {
- i2 = -i2;
- }
- ishift = 15 - nbit[i__ - 1];
- irc[i__] = i2 * pow_ii(&c__2, &ishift);
- }
-/* Decode RC(3)-RC(10) to sign plus 14 bits */
- i__1 = contrl_1.order;
- for (i__ = 3; i__ <= i__1; ++i__) {
- i2 = irc[i__];
- ishift = 15 - nbit[i__ - 1];
- i2 *= pow_ii(&c__2, &ishift);
- i2 += qb[i__ - 3];
- irc[i__] = i2 * descl[i__ - 3] + deadd[i__ - 3];
- }
-/* IF (LISTL.GE.3) WRITE(FDEBUG,811) IRMS, (IRC(I),I=1,ORDER) */
-/* 811 FORMAT(1X,'<<DECODE OUT>>',T45,I4,1X,10I8) */
-/* Scale RMS and RC's to reals */
- *rms = (real) (*irms);
- i__1 = contrl_1.order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- rc[i__] = irc[i__] / 16384.f;
- }
- return 0;
-} /* decode_ */
diff --git a/1.2-netsec/codecs/lpc10/deemp.c b/1.2-netsec/codecs/lpc10/deemp.c
deleted file mode 100644
index 067bd1137..000000000
--- a/1.2-netsec/codecs/lpc10/deemp.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:23:46 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:34 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int deemp_(real *x, integer *n, struct lpc10_decoder_state *st);
-#endif
-
-/* ***************************************************************** */
-
-/* DEEMP Version 48 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:23:46 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:34 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/20 15:54:37 jaf */
-/* Added comments about which indices of array arguments are read or */
-/* written. */
-
-/* Added entry INITDEEMP to reinitialize the local state variables, if */
-/* desired. */
-
-/* Revision 1.2 1996/03/14 22:11:13 jaf */
-/* Comments added explaining which of the local variables of this */
-/* subroutine need to be saved from one invocation to the next, and which */
-/* do not. */
-
-/* Revision 1.1 1996/02/07 14:44:53 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* De-Emphasize output speech with 1 / ( 1 - .75z**-1 ) */
-/* cascaded with 200 Hz high pass filter */
-/* ( 1 - 1.9998z**-1 + z**-2 ) / ( 1 - 1.75z**-1 + .78z**-2 ) */
-
-/* WARNING! The coefficients above may be out of date with the code */
-/* below. Either that, or some kind of transformation was performed */
-/* on the coefficients above to create the code below. */
-
-/* Input: */
-/* N - Number of samples */
-/* Input/Output: */
-/* X - Speech */
-/* Indices 1 through N are read before being written. */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this filter, or */
-/* reinitialize its state for any other reason, call the ENTRY */
-/* INITDEEMP. */
-
-/* Subroutine */ int deemp_(real *x, integer *n, struct lpc10_decoder_state *st)
-{
- /* Initialized data */
-
- real *dei1;
- real *dei2;
- real *deo1;
- real *deo2;
- real *deo3;
-
- /* System generated locals */
- integer i__1;
- real r__1;
-
- /* Local variables */
- integer k;
- real dei0;
-
-/* Arguments */
-/* Local variables that need not be saved */
-/* Local state */
-/* All of the locals saved below were not given explicit initial */
-/* values in the original code. I think 0 is a safe choice. */
- /* Parameter adjustments */
- if (x) {
- --x;
- }
-
- /* Function Body */
-
- dei1 = &(st->dei1);
- dei2 = &(st->dei2);
- deo1 = &(st->deo1);
- deo2 = &(st->deo2);
- deo3 = &(st->deo3);
-
- i__1 = *n;
- for (k = 1; k <= i__1; ++k) {
- dei0 = x[k];
- r__1 = x[k] - *dei1 * 1.9998f + *dei2;
- x[k] = r__1 + *deo1 * 2.5f - *deo2 * 2.0925f + *deo3 * .585f;
- *dei2 = *dei1;
- *dei1 = dei0;
- *deo3 = *deo2;
- *deo2 = *deo1;
- *deo1 = x[k];
- }
- return 0;
-} /* deemp_ */
diff --git a/1.2-netsec/codecs/lpc10/difmag.c b/1.2-netsec/codecs/lpc10/difmag.c
deleted file mode 100644
index d8d854fae..000000000
--- a/1.2-netsec/codecs/lpc10/difmag.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:32:31 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int difmag_(real *speech, integer *lpita, integer *tau, integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *maxptr);
-#endif
-
-/* ********************************************************************** */
-
-/* DIFMAG Version 49 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:14 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:32:31 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/15 23:09:39 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 14:41:31 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:45:04 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* Compute Average Magnitude Difference Function */
-
-/* Inputs: */
-/* SPEECH - Low pass filtered speech */
-/* Indices MIN_N1 through MAX_N1+LPITA-1 are read, where */
-/* MIN_N1 = (MAXLAG - MAX_TAU)/2+1 MAX_TAU = max of TAU(I) for I=1,LTAU
-*/
-/* MAX_N1 = (MAXLAG - MIN_TAU)/2+1 MIN_TAU = min of TAU(I) for I=1,LTAU
-*/
-/* LPITA - Length of speech buffer */
-/* TAU - Table of lags */
-/* Indices 1 through LTAU read. */
-/* LTAU - Number of lag values to compute */
-/* MAXLAG - Maximum possible lag value */
-/* Outputs: */
-/* (All of these outputs are also read, but only after being written.) */
-/* AMDF - Average Magnitude Difference for each lag in TAU */
-/* Indices 1 through LTAU written */
-/* MINPTR - Index of minimum AMDF value */
-/* MAXPTR - Index of maximum AMDF value */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int difmag_(real *speech, integer *lpita, integer *tau,
- integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *
- maxptr)
-{
- /* System generated locals */
- integer i__1, i__2;
- real r__1;
-
- /* Local variables */
- integer i__, j, n1, n2;
- real sum;
-
-/* Arguments */
-/* Local variables that need not be saved */
-/* Local state */
-/* None */
- /* Parameter adjustments */
- --amdf;
- --tau;
- --speech;
-
- /* Function Body */
- *minptr = 1;
- *maxptr = 1;
- i__1 = *ltau;
- for (i__ = 1; i__ <= i__1; ++i__) {
- n1 = (*maxlag - tau[i__]) / 2 + 1;
- n2 = n1 + *lpita - 1;
- sum = 0.f;
- i__2 = n2;
- for (j = n1; j <= i__2; j += 4) {
- sum += (r__1 = speech[j] - speech[j + tau[i__]], abs(r__1));
- }
- amdf[i__] = sum;
- if (amdf[i__] < amdf[*minptr]) {
- *minptr = i__;
- }
- if (amdf[i__] > amdf[*maxptr]) {
- *maxptr = i__;
- }
- }
- return 0;
-} /* difmag_ */
-
diff --git a/1.2-netsec/codecs/lpc10/dyptrk.c b/1.2-netsec/codecs/lpc10/dyptrk.c
deleted file mode 100644
index 4a4b1a14f..000000000
--- a/1.2-netsec/codecs/lpc10/dyptrk.c
+++ /dev/null
@@ -1,405 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:25:29 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:26 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int dyptrk_(real *amdf, integer *ltau, integer *minptr, integer *voice, integer *pitch, integer *midx, struct lpc10_encoder_state *st);
-/* comlen contrl_ 12 */
-#endif
-
-/* Common Block Declarations */
-
-extern struct {
- integer order, lframe;
- logical corrp;
-} contrl_;
-
-#define contrl_1 contrl_
-
-/* ********************************************************************* */
-
-/* DYPTRK Version 52 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:25:29 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:26 jaf
- * Initial revision
- * */
-/* Revision 1.5 1996/03/26 19:35:35 jaf */
-/* Commented out trace statements. */
-
-/* Revision 1.4 1996/03/19 18:03:22 jaf */
-/* Replaced the initialization "DATA P/60*DEPTH*0/" with "DATA P/120*0/", */
-/* because apparently Fortran (or at least f2c) can't handle expressions */
-/* like that. */
-
-/* Revision 1.3 1996/03/19 17:38:32 jaf */
-/* Added comments about the local variables that should be saved from one */
-/* invocation to the next. None of them were given initial values in the */
-/* original code, but from my testing, it appears that initializing them */
-/* all to 0 works. */
-
-/* Added entry INITDYPTRK to reinitialize these local variables. */
-
-/* Revision 1.2 1996/03/13 16:32:17 jaf */
-/* Comments added explaining which of the local variables of this */
-/* subroutine need to be saved from one invocation to the next, and which */
-/* do not. */
-
-/* WARNING! Some of them that should are never given initial values in */
-/* this code. Hopefully, Fortran 77 defines initial values for them, but */
-/* even so, giving them explicit initial values is preferable. */
-
-/* Revision 1.1 1996/02/07 14:45:14 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* Dynamic Pitch Tracker */
-
-/* Input: */
-/* AMDF - Average Magnitude Difference Function array */
-/* Indices 1 through LTAU read, and MINPTR */
-/* LTAU - Number of lags in AMDF */
-/* MINPTR - Location of minimum AMDF value */
-/* VOICE - Voicing decision */
-/* Output: */
-/* PITCH - Smoothed pitch value, 2 frames delayed */
-/* MIDX - Initial estimate of current frame pitch */
-/* Compile time constant: */
-/* DEPTH - Number of frames to trace back */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this filter, or */
-/* reinitialize its state for any other reason, call the ENTRY */
-/* INITDYPTRK. */
-
-/* Subroutine */ int dyptrk_(real *amdf, integer *ltau, integer *
- minptr, integer *voice, integer *pitch, integer *midx,
- struct lpc10_encoder_state *st)
-{
- /* Initialized data */
-
- real *s;
- integer *p;
- integer *ipoint;
- real *alphax;
-
- /* System generated locals */
- integer i__1;
-
- /* Local variables */
- integer pbar;
- real sbar;
- integer path[2], iptr, i__, j;
- real alpha, minsc, maxsc;
-
-/* Arguments */
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:25:29 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:26 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:05:55 jaf */
-/* Commented out the common block variables that are not needed by the */
-/* embedded version. */
-
-/* Revision 1.2 1996/03/26 19:34:50 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:44:09 jaf */
-/* Initial revision */
-
-/* LPC Processing control variables: */
-
-/* *** Read-only: initialized in setup */
-
-/* Files for Speech, Parameter, and Bitstream Input & Output, */
-/* and message and debug outputs. */
-
-/* Here are the only files which use these variables: */
-
-/* lpcsim.f setup.f trans.f error.f vqsetup.f */
-
-/* Many files which use fdebug are not listed, since it is only used in */
-/* those other files conditionally, to print trace statements. */
-/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* LPC order, Frame size, Quantization rate, Bits per frame, */
-/* Error correction */
-/* Subroutine SETUP is the only place where order is assigned a value, */
-/* and that value is 10. It could increase efficiency 1% or so to */
-/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
-*/
-/* a variable in a COMMON block, since it is used in many places in the */
-/* core of the coding and decoding routines. Actually, I take that back.
-*/
-/* At least when compiling with f2c, the upper bound of DO loops is */
-/* stored in a local variable before the DO loop begins, and then that is
-*/
-/* compared against on each iteration. */
-/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
-/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
-/* is used in only a few places, and never in the core coding and */
-/* decoding routines, so it could be eliminated entirely. */
-/* nbits is similar to quant, and is given a value of 54 in SETUP. */
-/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
-/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
-/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
-*/
-/* a constant or a variable, since it is only examined once per frame. */
-/* Leaving it as a variable that is set to .TRUE. seems like a good */
-/* idea, since it does enable some error-correction capability for */
-/* unvoiced frames, with no change in the coding rate, and no noticeable
-*/
-/* quality difference in the decoded speech. */
-/* integer quant, nbits */
-/* *** Read/write: variables for debugging, not needed for LPC algorithm
-*/
-
-/* Current frame, Unstable frames, Output clip count, Max onset buffer,
-*/
-/* Debug listing detail level, Line count on listing page */
-
-/* nframe is not needed for an embedded LPC10 at all. */
-/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
-/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
-/* an application, I would recommend removing the call to ERROR in RCCHK,
-*/
-/* and remove ERROR and nunsfm completely. */
-/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
-*/
-/* sread.f. When LPC10 is embedded into an application, one might want */
-/* to cause it to be incremented in a routine that takes the output of */
-/* SYNTHS and sends it to an audio device. It could be optionally */
-/* displayed, for those that might want to know what it is. */
-/* maxosp is never initialized to 0 in SETUP, although it probably should
-*/
-/* be, and it is updated in subroutine ANALYS. I doubt that its value */
-/* would be of much interest to an application in which LPC10 is */
-/* embedded. */
-/* listl and lincnt are not needed for an embedded LPC10 at all. */
-/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* common /contrl/ quant, nbits */
-/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* Parameters/constants */
-/* Local variables that need not be saved */
-/* Note that PATH is only used for debugging purposes, and can be */
-/* removed. */
-/* Local state */
-/* It would be a bit more "general" to define S(LTAU), if Fortran */
-/* allows the argument of a function to be used as the dimension of
-*/
-/* a local array variable. */
-/* IPOINT is always in the range 0 to DEPTH-1. */
-/* WARNING! */
-
-/* In the original version of this subroutine, IPOINT, ALPHAX, */
-/* every element of S, and potentially any element of P with the */
-/* second index value .NE. IPTR were read without being given */
-/* initial values (all indices of P with second index equal to */
-/* IPTR are all written before being read in this subroutine). */
-
-/* From examining the code carefully, it appears that all of these
-*/
-/* should be saved from one invocation to the next. */
-
-/* I've run lpcsim with the "-l 6" option to see all of the */
-/* debugging information that is printed out by this subroutine */
-/* below, and it appears that S, P, IPOINT, and ALPHAX are all */
-/* initialized to 0 (these initial values would likely be different
-*/
-/* on different platforms, compilers, etc.). Given that the output
-*/
-/* of the coder sounds reasonable, I'm going to initialize these */
-/* variables to 0 explicitly. */
-
- s = &(st->s[0]);
- p = &(st->p[0]);
- ipoint = &(st->ipoint);
- alphax = &(st->alphax);
-
-
- /* Parameter adjustments */
- if (amdf) {
- --amdf;
- }
-
- /* Function Body */
-
-/* Calculate the confidence factor ALPHA, used as a threshold slope in
-*/
-/* SEESAW. If unvoiced, set high slope so that every point in P array
-*/
-/* is marked as a potential pitch frequency. A scaled up version (ALPHAX
-)*/
-/* is used to maintain arithmetic precision. */
- if (*voice == 1) {
- *alphax = *alphax * .75f + amdf[*minptr] / 2.f;
- } else {
- *alphax *= .984375f;
- }
- alpha = *alphax / 16;
- if (*voice == 0 && *alphax < 128.f) {
- alpha = 8.f;
- }
-/* SEESAW: Construct a pitch pointer array and intermediate winner functio
-n*/
-/* Left to right pass: */
- iptr = *ipoint + 1;
- p[iptr * 60 - 60] = 1;
- i__ = 1;
- pbar = 1;
- sbar = s[0];
- i__1 = *ltau;
- for (i__ = 1; i__ <= i__1; ++i__) {
- sbar += alpha;
- if (sbar < s[i__ - 1]) {
- s[i__ - 1] = sbar;
- p[i__ + iptr * 60 - 61] = pbar;
- } else {
- sbar = s[i__ - 1];
- p[i__ + iptr * 60 - 61] = i__;
- pbar = i__;
- }
- }
-/* Right to left pass: */
- i__ = pbar - 1;
- sbar = s[i__];
- while(i__ >= 1) {
- sbar += alpha;
- if (sbar < s[i__ - 1]) {
- s[i__ - 1] = sbar;
- p[i__ + iptr * 60 - 61] = pbar;
- } else {
- pbar = p[i__ + iptr * 60 - 61];
- i__ = pbar;
- sbar = s[i__ - 1];
- }
- --i__;
- }
-/* Update S using AMDF */
-/* Find maximum, minimum, and location of minimum */
- s[0] += amdf[1] / 2;
- minsc = s[0];
- maxsc = minsc;
- *midx = 1;
- i__1 = *ltau;
- for (i__ = 2; i__ <= i__1; ++i__) {
- s[i__ - 1] += amdf[i__] / 2;
- if (s[i__ - 1] > maxsc) {
- maxsc = s[i__ - 1];
- }
- if (s[i__ - 1] < minsc) {
- *midx = i__;
- minsc = s[i__ - 1];
- }
- }
-/* Subtract MINSC from S to prevent overflow */
- i__1 = *ltau;
- for (i__ = 1; i__ <= i__1; ++i__) {
- s[i__ - 1] -= minsc;
- }
- maxsc -= minsc;
-/* Use higher octave pitch if significant null there */
- j = 0;
- for (i__ = 20; i__ <= 40; i__ += 10) {
- if (*midx > i__) {
- if (s[*midx - i__ - 1] < maxsc / 4) {
- j = i__;
- }
- }
- }
- *midx -= j;
-/* TRACE: look back two frames to find minimum cost pitch estimate */
- j = *ipoint;
- *pitch = *midx;
- for (i__ = 1; i__ <= 2; ++i__) {
- j = j % 2 + 1;
- *pitch = p[*pitch + j * 60 - 61];
- path[i__ - 1] = *pitch;
- }
-
-/* The following statement subtracts one from IPOINT, mod DEPTH. I
-*/
-/* think the author chose to add DEPTH-1, instead of subtracting 1,
-*/
-/* because then it will work even if MOD doesn't work as desired on
-*/
-/* negative arguments. */
-
- *ipoint = (*ipoint + 1) % 2;
- return 0;
-} /* dyptrk_ */
diff --git a/1.2-netsec/codecs/lpc10/encode.c b/1.2-netsec/codecs/lpc10/encode.c
deleted file mode 100644
index 109a42264..000000000
--- a/1.2-netsec/codecs/lpc10/encode.c
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:32:21 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int encode_(integer *voice, integer *pitch, real *rms, real *rc, integer *ipitch, integer *irms, integer *irc);
-/* comlen contrl_ 12 */
-#endif
-
-/* Common Block Declarations */
-
-extern struct {
- integer order, lframe;
- logical corrp;
-} contrl_;
-
-#define contrl_1 contrl_
-
-/* Table of constant values */
-
-static integer c__2 = 2;
-
-/* ***************************************************************** */
-
-/* ENCODE Version 54 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:32:21 jaf
- * Initial revision
- * */
-/* Revision 1.5 1996/03/26 19:35:50 jaf */
-/* Commented out trace statements. */
-
-/* Revision 1.4 1996/03/21 00:26:29 jaf */
-/* Added the comment that this subroutine has no local state. */
-
-/* In the last check-in, I forgot to mention that I had added comments */
-/* explaining which indices of array arguments are read or written. */
-
-/* Revision 1.3 1996/03/21 00:22:39 jaf */
-/* Added comments explaining that all local arrays are effectively */
-/* constants. */
-
-/* Revision 1.2 1996/03/13 18:48:33 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:45:29 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* Quantize LPC parameters for transmission */
-
-/* INPUTS: */
-/* VOICE - Half frame voicing decisions */
-/* Indices 1 through 2 read. */
-/* PITCH - Pitch */
-/* RMS - Energy */
-/* RC - Reflection coefficients */
-/* Indices 1 through ORDER read. */
-/* CORRP - Error Correction: TRUE = yes, FALSE = none */
-/* (this is defined in file control.fh) */
-/* OUTPUTS: */
-/* IPITCH - Coded pitch and voicing */
-/* IRMS - Quantized energy */
-/* IRC - Quantized reflection coefficients */
-/* Indices 1 through MAX(ORDER,2) written. */
-/* If CORRP is .TRUE., then indices 1 through 10 written */
-/* for unvoiced frames. */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int encode_(integer *voice, integer *pitch, real *rms, real *
- rc, integer *ipitch, integer *irms, integer *irc)
-{
- /* Initialized data */
-
- static integer enctab[16] = { 0,7,11,12,13,10,6,1,14,9,5,2,3,4,8,15 };
- static integer entau[60] = { 19,11,27,25,29,21,23,22,30,14,15,7,39,38,46,
- 42,43,41,45,37,53,49,51,50,54,52,60,56,58,26,90,88,92,84,86,82,83,
- 81,85,69,77,73,75,74,78,70,71,67,99,97,113,112,114,98,106,104,108,
- 100,101,76 };
- static integer enadd[8] = { 1920,-768,2432,1280,3584,1536,2816,-1152 };
- static real enscl[8] = { .0204f,.0167f,.0145f,.0147f,.0143f,.0135f,.0125f,
- .0112f };
- static integer enbits[8] = { 6,5,4,4,4,4,3,3 };
- static integer entab6[64] = { 0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,
- 3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,9,9,
- 9,10,10,11,11,12,13,14,15 };
- static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,
- 384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,
- 92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,
- 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
-
- /* System generated locals */
- integer i__1, i__2;
-
- /* Builtin functions */
- integer pow_ii(integer *, integer *);
-
- /* Local variables */
- integer idel, nbit, i__, j, i2, i3, mrk;
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:32:21 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Arguments */
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:32:21 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:05:55 jaf */
-/* Commented out the common block variables that are not needed by the */
-/* embedded version. */
-
-/* Revision 1.2 1996/03/26 19:34:50 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:44:09 jaf */
-/* Initial revision */
-
-/* LPC Processing control variables: */
-
-/* *** Read-only: initialized in setup */
-
-/* Files for Speech, Parameter, and Bitstream Input & Output, */
-/* and message and debug outputs. */
-
-/* Here are the only files which use these variables: */
-
-/* lpcsim.f setup.f trans.f error.f vqsetup.f */
-
-/* Many files which use fdebug are not listed, since it is only used in */
-/* those other files conditionally, to print trace statements. */
-/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* LPC order, Frame size, Quantization rate, Bits per frame, */
-/* Error correction */
-/* Subroutine SETUP is the only place where order is assigned a value, */
-/* and that value is 10. It could increase efficiency 1% or so to */
-/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
-*/
-/* a variable in a COMMON block, since it is used in many places in the */
-/* core of the coding and decoding routines. Actually, I take that back.
-*/
-/* At least when compiling with f2c, the upper bound of DO loops is */
-/* stored in a local variable before the DO loop begins, and then that is
-*/
-/* compared against on each iteration. */
-/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
-/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
-/* is used in only a few places, and never in the core coding and */
-/* decoding routines, so it could be eliminated entirely. */
-/* nbits is similar to quant, and is given a value of 54 in SETUP. */
-/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
-/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
-/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
-*/
-/* a constant or a variable, since it is only examined once per frame. */
-/* Leaving it as a variable that is set to .TRUE. seems like a good */
-/* idea, since it does enable some error-correction capability for */
-/* unvoiced frames, with no change in the coding rate, and no noticeable
-*/
-/* quality difference in the decoded speech. */
-/* integer quant, nbits */
-/* *** Read/write: variables for debugging, not needed for LPC algorithm
-*/
-
-/* Current frame, Unstable frames, Output clip count, Max onset buffer,
-*/
-/* Debug listing detail level, Line count on listing page */
-
-/* nframe is not needed for an embedded LPC10 at all. */
-/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
-/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
-/* an application, I would recommend removing the call to ERROR in RCCHK,
-*/
-/* and remove ERROR and nunsfm completely. */
-/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
-*/
-/* sread.f. When LPC10 is embedded into an application, one might want */
-/* to cause it to be incremented in a routine that takes the output of */
-/* SYNTHS and sends it to an audio device. It could be optionally */
-/* displayed, for those that might want to know what it is. */
-/* maxosp is never initialized to 0 in SETUP, although it probably should
-*/
-/* be, and it is updated in subroutine ANALYS. I doubt that its value */
-/* would be of much interest to an application in which LPC10 is */
-/* embedded. */
-/* listl and lincnt are not needed for an embedded LPC10 at all. */
-/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* common /contrl/ quant, nbits */
-/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* Parameters/constants */
-/* These arrays are not Fortran PARAMETER's, but they are defined */
-/* by DATA statements below, and their contents are never altered.
-*/
-/* Local variables that need not be saved */
- /* Parameter adjustments */
- --irc;
- --rc;
- --voice;
-
- /* Function Body */
-/* Scale RMS and RC's to integers */
- *irms = *rms;
- i__1 = contrl_1.order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- irc[i__] = rc[i__] * 32768.f;
- }
-/* IF(LISTL.GE.3)WRITE(FDEBUG,800)VOICE,PITCH,IRMS,(IRC(I),I=1,ORDER) */
-/* 800 FORMAT(1X,/,' <<ENCODE IN>>',T32,2I3,I6,I5,T50,10I8) */
-/* Encode pitch and voicing */
- if (voice[1] != 0 && voice[2] != 0) {
- *ipitch = entau[*pitch - 1];
- } else {
- if (contrl_1.corrp) {
- *ipitch = 0;
- if (voice[1] != voice[2]) {
- *ipitch = 127;
- }
- } else {
- *ipitch = (voice[1] << 1) + voice[2];
- }
- }
-/* Encode RMS by binary table search */
- j = 32;
- idel = 16;
- *irms = min(*irms,1023);
- while(idel > 0) {
- if (*irms > rmst[j - 1]) {
- j -= idel;
- }
- if (*irms < rmst[j - 1]) {
- j += idel;
- }
- idel /= 2;
- }
- if (*irms > rmst[j - 1]) {
- --j;
- }
- *irms = 31 - j / 2;
-/* Encode RC(1) and (2) as log-area-ratios */
- for (i__ = 1; i__ <= 2; ++i__) {
- i2 = irc[i__];
- mrk = 0;
- if (i2 < 0) {
- i2 = -i2;
- mrk = 1;
- }
- i2 /= 512;
- i2 = min(i2,63);
- i2 = entab6[i2];
- if (mrk != 0) {
- i2 = -i2;
- }
- irc[i__] = i2;
- }
-/* Encode RC(3) - (10) linearly, remove bias then scale */
- i__1 = contrl_1.order;
- for (i__ = 3; i__ <= i__1; ++i__) {
- i2 = irc[i__] / 2;
- i2 = (i2 + enadd[contrl_1.order + 1 - i__ - 1]) * enscl[
- contrl_1.order + 1 - i__ - 1];
-/* Computing MIN */
- i__2 = max(i2,-127);
- i2 = min(i__2,127);
- nbit = enbits[contrl_1.order + 1 - i__ - 1];
- i3 = 0;
- if (i2 < 0) {
- i3 = -1;
- }
- i2 /= pow_ii(&c__2, &nbit);
- if (i3 == -1) {
- --i2;
- }
- irc[i__] = i2;
- }
-/* Protect the most significant bits of the most */
-/* important parameters during non-voiced frames. */
-/* RC(1) - RC(4) are protected using 20 parity bits */
-/* replacing RC(5) - RC(10). */
- if (contrl_1.corrp) {
- if (*ipitch == 0 || *ipitch == 127) {
- irc[5] = enctab[(irc[1] & 30) / 2];
- irc[6] = enctab[(irc[2] & 30) / 2];
- irc[7] = enctab[(irc[3] & 30) / 2];
- irc[8] = enctab[(*irms & 30) / 2];
- irc[9] = enctab[(irc[4] & 30) / 2] / 2;
- irc[10] = enctab[(irc[4] & 30) / 2] & 1;
- }
- }
-/* IF(LISTL.GE.3)WRITE(FDEBUG,801)VOICE,IPITCH,IRMS,(IRC(J),J=1,ORDER) */
-/* 801 FORMAT(1X,'<<ENCODE OUT>>',T32,2I3,I6,I5,T50,10I8) */
- return 0;
-} /* encode_ */
-
diff --git a/1.2-netsec/codecs/lpc10/energy.c b/1.2-netsec/codecs/lpc10/energy.c
deleted file mode 100644
index baa6f57ca..000000000
--- a/1.2-netsec/codecs/lpc10/energy.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:32:17 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int energy_(integer *len, real *speech, real *rms);
-#endif
-
-/* ********************************************************************* */
-
-/* ENERGY Version 50 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:32:17 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/18 21:17:41 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 16:46:02 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:45:40 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* Compute RMS energy. */
-
-/* Input: */
-/* LEN - Length of speech buffer */
-/* SPEECH - Speech buffer */
-/* Indices 1 through LEN read. */
-/* Output: */
-/* RMS - Root Mean Square energy */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int energy_(integer *len, real *speech, real *rms)
-{
- /* System generated locals */
- integer i__1;
-
- /* Builtin functions */
- double sqrt(doublereal);
-
- /* Local variables */
- integer i__;
-
-/* Arguments */
-/* Local variables that need not be saved */
- /* Parameter adjustments */
- --speech;
-
- /* Function Body */
- *rms = 0.f;
- i__1 = *len;
- for (i__ = 1; i__ <= i__1; ++i__) {
- *rms += speech[i__] * speech[i__];
- }
- *rms = sqrt(*rms / *len);
- return 0;
-} /* energy_ */
-
diff --git a/1.2-netsec/codecs/lpc10/f2c.h b/1.2-netsec/codecs/lpc10/f2c.h
deleted file mode 100644
index e50d642e0..000000000
--- a/1.2-netsec/codecs/lpc10/f2c.h
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:26:28 jaf
- * Any typedef defining a type that was used in lpc10_encoder_state or
- * lpc10_decoder_state struct's was commented out here and added to
- * lpc10.h.
- *
- * Revision 1.1 1996/08/19 22:32:13 jaf
- * Initial revision
- *
-
-*/
-
-/*
- * f2c.h
- *
- * SCCS ID: @(#)f2c.h 1.2 96/05/19
- */
-
-/* f2c.h -- Standard Fortran to C header file */
-
-/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
-
- - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
-
-#ifndef F2C_INCLUDE
-#define F2C_INCLUDE
-
-#include "lpc10.h"
-
-/*typedef long int integer;*/
-/*typedef INT32 integer;*/
-/*typedef short int shortint;*/
-/*typedef INT16 shortint;*/
-/*typedef float real;*/
-/* doublereal only used for function arguments to sqrt, exp, etc. */
-typedef double doublereal;
-/* 32 bits seems wasteful, but there really aren't that many logical
- * variables around, and making them 32 bits could avoid word
- * alignment problems, perhaps. */
-/*typedef long int logical;*/
-/*typedef INT32 logical;*/
-/* The following types are not used in the translated C code for the
- * LPC-10 coder, but they might be needed by the definitions down
- * below, so they don't cause compilation errors. */
-typedef char *address;
-typedef struct { real r, i; } complex;
-typedef struct { doublereal r, i; } doublecomplex;
-typedef short int shortlogical;
-typedef char logical1;
-typedef char integer1;
-/* typedef long long longint; */ /* system-dependent */
-
-#define TRUE_ (1)
-#define FALSE_ (0)
-
-/* Extern is for use with -E */
-#ifndef Extern
-#define Extern extern
-#endif
-
-/* I/O stuff */
-
-#ifdef f2c_i2
-/* for -i2 */
-typedef short flag;
-typedef short ftnlen;
-typedef short ftnint;
-#else
-typedef long int flag;
-typedef long int ftnlen;
-typedef long int ftnint;
-#endif
-
-/*external read, write*/
-typedef struct
-{ flag cierr;
- ftnint ciunit;
- flag ciend;
- char *cifmt;
- ftnint cirec;
-} cilist;
-
-/*internal read, write*/
-typedef struct
-{ flag icierr;
- char *iciunit;
- flag iciend;
- char *icifmt;
- ftnint icirlen;
- ftnint icirnum;
-} icilist;
-
-/*open*/
-typedef struct
-{ flag oerr;
- ftnint ounit;
- char *ofnm;
- ftnlen ofnmlen;
- char *osta;
- char *oacc;
- char *ofm;
- ftnint orl;
- char *oblnk;
-} olist;
-
-/*close*/
-typedef struct
-{ flag cerr;
- ftnint cunit;
- char *csta;
-} cllist;
-
-/*rewind, backspace, endfile*/
-typedef struct
-{ flag aerr;
- ftnint aunit;
-} alist;
-
-/* inquire */
-typedef struct
-{ flag inerr;
- ftnint inunit;
- char *infile;
- ftnlen infilen;
- ftnint *inex; /*parameters in standard's order*/
- ftnint *inopen;
- ftnint *innum;
- ftnint *innamed;
- char *inname;
- ftnlen innamlen;
- char *inacc;
- ftnlen inacclen;
- char *inseq;
- ftnlen inseqlen;
- char *indir;
- ftnlen indirlen;
- char *infmt;
- ftnlen infmtlen;
- char *inform;
- ftnint informlen;
- char *inunf;
- ftnlen inunflen;
- ftnint *inrecl;
- ftnint *innrec;
- char *inblank;
- ftnlen inblanklen;
-} inlist;
-
-#define VOID void
-
-union Multitype { /* for multiple entry points */
- integer1 g;
- shortint h;
- integer i;
- /* longint j; */
- real r;
- doublereal d;
- complex c;
- doublecomplex z;
- };
-
-typedef union Multitype Multitype;
-
-/*typedef long int Long;*/ /* No longer used; formerly in Namelist */
-
-struct Vardesc { /* for Namelist */
- char *name;
- char *addr;
- ftnlen *dims;
- int type;
- };
-typedef struct Vardesc Vardesc;
-
-struct Namelist {
- char *name;
- Vardesc **vars;
- int nvars;
- };
-typedef struct Namelist Namelist;
-
-#define abs(x) ((x) >= 0 ? (x) : -(x))
-#define dabs(x) (doublereal)abs(x)
-#define min(a,b) ((a) <= (b) ? (a) : (b))
-#define max(a,b) ((a) >= (b) ? (a) : (b))
-#define dmin(a,b) (doublereal)min(a,b)
-#define dmax(a,b) (doublereal)max(a,b)
-
-/* procedure parameter types for -A and -C++ */
-
-#define F2C_proc_par_types 1
-#ifdef __cplusplus
-typedef int /* Unknown procedure type */ (*U_fp)(...);
-typedef shortint (*J_fp)(...);
-typedef integer (*I_fp)(...);
-typedef real (*R_fp)(...);
-typedef doublereal (*D_fp)(...), (*E_fp)(...);
-typedef /* Complex */ VOID (*C_fp)(...);
-typedef /* Double Complex */ VOID (*Z_fp)(...);
-typedef logical (*L_fp)(...);
-typedef shortlogical (*K_fp)(...);
-typedef /* Character */ VOID (*H_fp)(...);
-typedef /* Subroutine */ int (*S_fp)(...);
-#else
-typedef int /* Unknown procedure type */ (*U_fp)(VOID);
-typedef shortint (*J_fp)(VOID);
-typedef integer (*I_fp)(VOID);
-typedef real (*R_fp)(VOID);
-typedef doublereal (*D_fp)(VOID), (*E_fp)(VOID);
-typedef /* Complex */ VOID (*C_fp)(VOID);
-typedef /* Double Complex */ VOID (*Z_fp)(VOID);
-typedef logical (*L_fp)(VOID);
-typedef shortlogical (*K_fp)(VOID);
-typedef /* Character */ VOID (*H_fp)(VOID);
-typedef /* Subroutine */ int (*S_fp)(VOID);
-#endif
-/* E_fp is for real functions when -R is not specified */
-typedef VOID C_f; /* complex function */
-typedef VOID H_f; /* character function */
-typedef VOID Z_f; /* double complex function */
-typedef doublereal E_f; /* real function with -R not specified */
-
-/* undef any lower-case symbols that your C compiler predefines, e.g.: */
-
-#ifndef Skip_f2c_Undefs
-#undef cray
-#undef gcos
-#undef mc68010
-#undef mc68020
-#undef mips
-#undef pdp11
-#undef sgi
-#undef sparc
-#undef sun
-#undef sun2
-#undef sun3
-#undef sun4
-#undef u370
-#undef u3b
-#undef u3b2
-#undef u3b5
-#undef unix
-#undef vax
-#endif
-
-#ifdef KR_headers
-extern integer pow_ii(ap, bp);
-extern double r_sign(a,b);
-extern integer i_nint(x);
-#else
-extern integer pow_ii(integer *ap, integer *bp);
-extern double r_sign(real *a, real *b);
-extern integer i_nint(real *x);
-
-#endif
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int bsynz_(real *coef, integer *ip, integer *iv,
- real *sout, real *rms, real *ratio, real *g2pass,
- struct lpc10_decoder_state *st);
-extern int chanwr_(integer *order, integer *ipitv, integer *irms,
- integer *irc, integer *ibits, struct lpc10_encoder_state *st);
-extern int chanrd_(integer *order, integer *ipitv, integer *irms,
- integer *irc, integer *ibits);
-extern int chanwr_0_(int n__, integer *order, integer *ipitv,
- integer *irms, integer *irc, integer *ibits,
- struct lpc10_encoder_state *st);
-extern int dcbias_(integer *len, real *speech, real *sigout);
-extern int decode_(integer *ipitv, integer *irms, integer *irc,
- integer *voice, integer *pitch, real *rms,
- real *rc, struct lpc10_decoder_state *st);
-extern int deemp_(real *x, integer *n, struct lpc10_decoder_state *st);
-extern int difmag_(real *speech, integer *lpita, integer *tau, integer *ltau,
- integer *maxlag, real *amdf, integer *minptr, integer *maxptr);
-extern int dyptrk_(real *amdf, integer *ltau, integer *
- minptr, integer *voice, integer *pitch, integer *midx,
- struct lpc10_encoder_state *st);
-extern int encode_(integer *voice, integer *pitch, real *rms, real *rc,
- integer *ipitch, integer *irms, integer *irc);
-extern int energy_(integer *len, real *speech, real *rms);
-extern int ham84_(integer *input, integer *output, integer *errcnt);
-extern int hp100_(real *speech, integer *start, integer *end,
- struct lpc10_encoder_state *st);
-extern int inithp100_(void);
-extern int invert_(integer *order, real *phi, real *psi, real *rc);
-extern int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pass);
-extern int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real *ivrc);
-extern int lpcdec_(integer *bits, real *speech);
-extern int initlpcdec_(void);
-extern int lpcenc_(real *speech, integer *bits);
-extern int initlpcenc_(void);
-extern int lpfilt_(real *inbuf, real *lpbuf, integer *len, integer *nsamp);
-extern integer median_(integer *d1, integer *d2, integer *d3);
-extern int mload_(integer *order, integer *awins, integer *awinf, real *speech, real *phi, real *psi);
-extern int onset_(real *pebuf, integer *osbuf, integer *osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *lframe, struct lpc10_encoder_state *st);
-extern int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st);
-extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin);
-extern int placev_(integer *osbuf, integer *osptr, integer *oslen, integer *obound, integer *vwin, integer *af, integer *lframe, integer *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh);
-extern int preemp_(real *inbuf, real *pebuf, integer *nsamp, real *coef, real *z__);
-extern int prepro_(real *speech, integer *length,
- struct lpc10_encoder_state *st);
-extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st);
-extern integer random_(struct lpc10_decoder_state *st);
-extern int rcchk_(integer *order, real *rc1f, real *rc2f);
-extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st);
-extern int tbdm_(real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau);
-extern int voicin_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd, integer *mintau, real *ivrc, integer *obound, integer *voibuf, integer *af, struct lpc10_encoder_state *st);
-extern int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__);
-
-#endif
-
-
-#endif /* ! defined F2C_INCLUDE */
diff --git a/1.2-netsec/codecs/lpc10/f2clib.c b/1.2-netsec/codecs/lpc10/f2clib.c
deleted file mode 100644
index e72c307c6..000000000
--- a/1.2-netsec/codecs/lpc10/f2clib.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
-
-$Log$
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:32:10 jaf
- * Initial revision
- *
-
-*/
-
-/*
- * f2clib.c
- *
- * SCCS ID: @(#)f2clib.c 1.2 96/05/19
- */
-
-#include "f2c.h"
-
-#ifdef KR_headers
-integer pow_ii(ap, bp) integer *ap, *bp;
-#else
-integer pow_ii(integer *ap, integer *bp)
-#endif
-{
- integer pow, x, n;
- unsigned long u;
-
- x = *ap;
- n = *bp;
-
- if (n <= 0) {
- if (n == 0 || x == 1)
- return 1;
- if (x != -1)
- return x == 0 ? 1/x : 0;
- n = -n;
- }
- u = n;
- for(pow = 1; ; )
- {
- if(u & 01)
- pow *= x;
- if(u >>= 1)
- x *= x;
- else
- break;
- }
- return(pow);
- }
-
-
-
-#ifdef KR_headers
-double r_sign(a,b) real *a, *b;
-#else
-double r_sign(real *a, real *b)
-#endif
-{
-double x;
-x = (*a >= 0 ? *a : - *a);
-return( *b >= 0 ? x : -x);
-}
-
-
-
-#ifdef KR_headers
-double floor();
-integer i_nint(x) real *x;
-#else
-#undef abs
-#include "math.h"
-integer i_nint(real *x)
-#endif
-{
-return( (*x)>=0 ?
- floor(*x + .5) : -floor(.5 - *x) );
-}
diff --git a/1.2-netsec/codecs/lpc10/ham84.c b/1.2-netsec/codecs/lpc10/ham84.c
deleted file mode 100644
index 9281d75d2..000000000
--- a/1.2-netsec/codecs/lpc10/ham84.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:32:07 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int ham84_(integer *input, integer *output, integer *errcnt);
-#endif
-
-/* ***************************************************************** */
-
-/* HAM84 Version 45G */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:32:07 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/21 15:26:00 jaf */
-/* Put comment header in standard form. */
-
-/* Revision 1.2 1996/03/13 22:00:13 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:47:04 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* Hamming 8,4 Decoder - can correct 1 out of seven bits */
-/* and can detect up to two errors. */
-
-/* Input: */
-/* INPUT - Seven bit data word, 4 bits parameter and */
-/* 4 bits parity information */
-/* Input/Output: */
-/* ERRCNT - Sums errors detected by Hamming code */
-/* Output: */
-/* OUTPUT - 4 corrected parameter bits */
-
-/* This subroutine is entered with an eight bit word in INPUT. The 8th */
-/* bit is parity and is stripped off. The remaining 7 bits address the */
-/* hamming 8,4 table and the output OUTPUT from the table gives the 4 */
-/* bits of corrected data. If bit 4 is set, no error was detected. */
-/* ERRCNT is the number of errors counted. */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int ham84_(integer *input, integer *output, integer *errcnt)
-{
- /* Initialized data */
-
- static integer dactab[128] = { 16,0,0,3,0,5,14,7,0,9,14,11,14,13,30,14,0,
- 9,2,7,4,7,7,23,9,25,10,9,12,9,14,7,0,5,2,11,5,21,6,5,8,11,11,27,
- 12,5,14,11,2,1,18,2,12,5,2,7,12,9,2,11,28,12,12,15,0,3,3,19,4,13,
- 6,3,8,13,10,3,13,29,14,13,4,1,10,3,20,4,4,7,10,9,26,10,4,13,10,15,
- 8,1,6,3,6,5,22,6,24,8,8,11,8,13,6,15,1,17,2,1,4,1,6,15,8,1,10,15,
- 12,15,15,31 };
-
- integer i__, j, parity;
-
-/* Arguments */
-/* Parameters/constants */
-/* Local variables that need not be saved */
-/* Determine parity of input word */
- parity = *input & 255;
- parity ^= parity / 16;
- parity ^= parity / 4;
- parity ^= parity / 2;
- parity &= 1;
- i__ = dactab[*input & 127];
- *output = i__ & 15;
- j = i__ & 16;
- if (j != 0) {
-/* No errors detected in seven bits */
- if (parity != 0) {
- ++(*errcnt);
- }
- } else {
-/* One or two errors detected */
- ++(*errcnt);
- if (parity == 0) {
-/* Two errors detected */
- ++(*errcnt);
- *output = -1;
- }
- }
- return 0;
-} /* ham84_ */
-
diff --git a/1.2-netsec/codecs/lpc10/hp100.c b/1.2-netsec/codecs/lpc10/hp100.c
deleted file mode 100644
index 7693a4764..000000000
--- a/1.2-netsec/codecs/lpc10/hp100.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:28:05 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:04 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int hp100_(real *speech, integer *start, integer *end,
- struct lpc10_encoder_state *st);
-extern int inithp100_(void);
-#endif
-
-/* ********************************************************************* */
-
-/* HP100 Version 55 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:28:05 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:32:04 jaf
- * Initial revision
- * */
-/* Revision 1.6 1996/03/15 16:45:25 jaf */
-/* Rearranged a few comments. */
-
-/* Revision 1.5 1996/03/14 23:20:54 jaf */
-/* Added comments about when INITHP100 should be used. */
-
-/* Revision 1.4 1996/03/14 23:08:08 jaf */
-/* Added an entry named INITHP100 that initializes the local state of */
-/* subroutine HP100. */
-
-/* Revision 1.3 1996/03/14 22:09:20 jaf */
-/* Comments added explaining which of the local variables of this */
-/* subroutine need to be saved from one invocation to the next, and which */
-/* do not. */
-
-/* Revision 1.2 1996/02/12 15:05:54 jaf */
-/* Added lots of comments explaining why I changed one line, which was a */
-/* declaration with initializations. */
-
-/* Revision 1.1 1996/02/07 14:47:12 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* 100 Hz High Pass Filter */
-
-/* Jan 92 - corrected typo (1.937148 to 1.935715), */
-/* rounded coefficients to 7 places, */
-/* corrected and merged gain (.97466**4), */
-/* merged numerator into first two sections. */
-
-/* Input: */
-/* start, end - Range of samples to filter */
-/* Input/Output: */
-/* speech(end) - Speech data. */
-/* Indices start through end are read and modified. */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this filter, or */
-/* reinitialize its state for any other reason, call the ENTRY */
-/* INITHP100. */
-/* Subroutine */ int hp100_(real *speech, integer *start, integer *end,
- struct lpc10_encoder_state *st)
-{
- /* Temporary local copies of variables in lpc10_encoder_state.
- I've only created these because it might cause the loop below
- to execute a bit faster to access local variables, rather than
- variables in the lpc10_encoder_state structure. It is just a
- guess that it will be faster. */
-
- real z11;
- real z21;
- real z12;
- real z22;
-
- /* System generated locals */
- integer i__1;
-
- /* Local variables */
- integer i__;
- real si, err;
-
-/* Arguments */
-/* Local variables that need not be saved */
-/* Local state */
- /* Parameter adjustments */
- if (speech) {
- --speech;
- }
-
- /* Function Body */
-
- z11 = st->z11;
- z21 = st->z21;
- z12 = st->z12;
- z22 = st->z22;
-
- i__1 = *end;
- for (i__ = *start; i__ <= i__1; ++i__) {
- si = speech[i__];
- err = si + z11 * 1.859076f - z21 * .8648249f;
- si = err - z11 * 2.f + z21;
- z21 = z11;
- z11 = err;
- err = si + z12 * 1.935715f - z22 * .9417004f;
- si = err - z12 * 2.f + z22;
- z22 = z12;
- z12 = err;
- speech[i__] = si * .902428f;
- }
-
- st->z11 = z11;
- st->z21 = z21;
- st->z12 = z12;
- st->z22 = z22;
-
- return 0;
-} /* hp100_ */
diff --git a/1.2-netsec/codecs/lpc10/invert.c b/1.2-netsec/codecs/lpc10/invert.c
deleted file mode 100644
index 1eb1079ee..000000000
--- a/1.2-netsec/codecs/lpc10/invert.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:32:00 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int invert_(integer *order, real *phi, real *psi, real *rc);
-#endif
-
-/* **************************************************************** */
-
-/* INVERT Version 45G */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:32:00 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/18 20:52:47 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 16:51:32 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Eliminated a comment from the original, describing a local array X */
-/* that appeared nowhere in the code. */
-
-/* Revision 1.1 1996/02/07 14:47:20 jaf */
-/* Initial revision */
-
-
-/* **************************************************************** */
-
-/* Invert a covariance matrix using Choleski decomposition method. */
-
-/* Input: */
-/* ORDER - Analysis order */
-/* PHI(ORDER,ORDER) - Covariance matrix */
-/* Indices (I,J) read, where ORDER .GE. I .GE. J .GE. 1.*/
-/* All other indices untouched. */
-/* PSI(ORDER) - Column vector to be predicted */
-/* Indices 1 through ORDER read. */
-/* Output: */
-/* RC(ORDER) - Pseudo reflection coefficients */
-/* Indices 1 through ORDER written, and then possibly read.
-*/
-/* Internal: */
-/* V(ORDER,ORDER) - Temporary matrix */
-/* Same indices written as read from PHI. */
-/* Many indices may be read and written again after */
-/* initially being copied from PHI, but all indices */
-/* are written before being read. */
-
-/* NOTE: Temporary matrix V is not needed and may be replaced */
-/* by PHI if the original PHI values do not need to be preserved. */
-
-/* Subroutine */ int invert_(integer *order, real *phi, real *psi, real *rc)
-{
- /* System generated locals */
- integer phi_dim1, phi_offset, i__1, i__2, i__3;
- real r__1, r__2;
-
- /* Local variables */
- real save;
- integer i__, j, k;
- real v[100] /* was [10][10] */;
-
-/* Arguments */
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:32:00 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Parameters/constants */
-/* Local variables that need not be saved */
-/* Decompose PHI into V * D * V' where V is a triangular matrix whose */
-/* main diagonal elements are all 1, V' is the transpose of V, and */
-/* D is a vector. Here D(n) is stored in location V(n,n). */
- /* Parameter adjustments */
- --rc;
- --psi;
- phi_dim1 = *order;
- phi_offset = phi_dim1 + 1;
- phi -= phi_offset;
-
- /* Function Body */
- i__1 = *order;
- for (j = 1; j <= i__1; ++j) {
- i__2 = *order;
- for (i__ = j; i__ <= i__2; ++i__) {
- v[i__ + j * 10 - 11] = phi[i__ + j * phi_dim1];
- }
- i__2 = j - 1;
- for (k = 1; k <= i__2; ++k) {
- save = v[j + k * 10 - 11] * v[k + k * 10 - 11];
- i__3 = *order;
- for (i__ = j; i__ <= i__3; ++i__) {
- v[i__ + j * 10 - 11] -= v[i__ + k * 10 - 11] * save;
- }
- }
-/* Compute intermediate results, which are similar to RC's */
- if ((r__1 = v[j + j * 10 - 11], abs(r__1)) < 1e-10f) {
- goto L100;
- }
- rc[j] = psi[j];
- i__2 = j - 1;
- for (k = 1; k <= i__2; ++k) {
- rc[j] -= rc[k] * v[j + k * 10 - 11];
- }
- v[j + j * 10 - 11] = 1.f / v[j + j * 10 - 11];
- rc[j] *= v[j + j * 10 - 11];
-/* Computing MAX */
-/* Computing MIN */
- r__2 = rc[j];
- r__1 = min(r__2,.999f);
- rc[j] = max(r__1,-.999f);
- }
- return 0;
-/* Zero out higher order RC's if algorithm terminated early */
-L100:
- i__1 = *order;
- for (i__ = j; i__ <= i__1; ++i__) {
- rc[i__] = 0.f;
- }
-/* Back substitute for PC's (if needed) */
-/* 110 DO J = ORDER,1,-1 */
-/* PC(J) = RC(J) */
-/* DO I = 1,J-1 */
-/* PC(J) = PC(J) - PC(I)*V(J,I) */
-/* END DO */
-/* END DO */
- return 0;
-} /* invert_ */
-
diff --git a/1.2-netsec/codecs/lpc10/irc2pc.c b/1.2-netsec/codecs/lpc10/irc2pc.c
deleted file mode 100644
index 412feb72a..000000000
--- a/1.2-netsec/codecs/lpc10/irc2pc.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:31:56 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pass);
-#endif
-
-/* ***************************************************************** */
-
-/* IRC2PC Version 48 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:31:56 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/20 15:47:19 jaf */
-/* Added comments about which indices of array arguments are read or */
-/* written. */
-
-/* Revision 1.2 1996/03/14 16:59:04 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:47:27 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* Convert Reflection Coefficients to Predictor Coeficients */
-
-/* Inputs: */
-/* RC - Reflection coefficients */
-/* Indices 1 through ORDER read. */
-/* ORDER - Number of RC's */
-/* GPRIME - Excitation modification gain */
-/* Outputs: */
-/* PC - Predictor coefficients */
-/* Indices 1 through ORDER written. */
-/* Indices 1 through ORDER-1 are read after being written. */
-/* G2PASS - Excitation modification sharpening factor */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int irc2pc_(real *rc, real *pc, integer *order, real *gprime,
- real *g2pass)
-{
- /* System generated locals */
- integer i__1, i__2;
-
- /* Builtin functions */
- double sqrt(doublereal);
-
- /* Local variables */
- real temp[10];
- integer i__, j;
-
-/* Arguments */
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:31:56 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Local variables that need not be saved */
- /* Parameter adjustments */
- --pc;
- --rc;
-
- /* Function Body */
- *g2pass = 1.f;
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- *g2pass *= 1.f - rc[i__] * rc[i__];
- }
- *g2pass = *gprime * sqrt(*g2pass);
- pc[1] = rc[1];
- i__1 = *order;
- for (i__ = 2; i__ <= i__1; ++i__) {
- i__2 = i__ - 1;
- for (j = 1; j <= i__2; ++j) {
- temp[j - 1] = pc[j] - rc[i__] * pc[i__ - j];
- }
- i__2 = i__ - 1;
- for (j = 1; j <= i__2; ++j) {
- pc[j] = temp[j - 1];
- }
- pc[i__] = rc[i__];
- }
- return 0;
-} /* irc2pc_ */
-
diff --git a/1.2-netsec/codecs/lpc10/ivfilt.c b/1.2-netsec/codecs/lpc10/ivfilt.c
deleted file mode 100644
index f964064e8..000000000
--- a/1.2-netsec/codecs/lpc10/ivfilt.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
-
-$Log$
-Revision 1.16 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.15 2003/09/19 01:20:22 markster
-Code cleanups (bug #66)
-
-Revision 1.2 2003/09/19 01:20:22 markster
-Code cleanups (bug #66)
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:31:53 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real *ivrc);
-#endif
-
-/* ********************************************************************* */
-
-/* IVFILT Version 48 */
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.2 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:31:53 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/15 21:36:29 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 00:01:00 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:47:34 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* 2nd order inverse filter, speech is decimated 4:1 */
-
-/* Input: */
-/* LEN - Length of speech buffers */
-/* NSAMP - Number of samples to filter */
-/* LPBUF - Low pass filtered speech buffer */
-/* Indices LEN-NSAMP-7 through LEN read. */
-/* Output: */
-/* IVBUF - Inverse filtered speech buffer */
-/* Indices LEN-NSAMP+1 through LEN written. */
-/* IVRC - Inverse filter reflection coefficients (for voicing) */
-/* Indices 1 and 2 both written (also read, but only after writing).
-*/
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *
- nsamp, real *ivrc)
-{
- /* System generated locals */
- integer i__1;
-
- /* Local variables */
- integer i__, j, k;
- real r__[3], pc1, pc2;
-
-/* Arguments */
-/* Local variables that need not be saved */
-/* Local state */
-/* None */
-/* Calculate Autocorrelations */
- /* Parameter adjustments */
- --ivbuf;
- --lpbuf;
- --ivrc;
-
- /* Function Body */
- for (i__ = 1; i__ <= 3; ++i__) {
- r__[i__ - 1] = 0.f;
- k = (i__ - 1) << 2;
- i__1 = *len;
- for (j = (i__ << 2) + *len - *nsamp; j <= i__1; j += 2) {
- r__[i__ - 1] += lpbuf[j] * lpbuf[j - k];
- }
- }
-/* Calculate predictor coefficients */
- pc1 = 0.f;
- pc2 = 0.f;
- ivrc[1] = 0.f;
- ivrc[2] = 0.f;
- if (r__[0] > 1e-10f) {
- ivrc[1] = r__[1] / r__[0];
- ivrc[2] = (r__[2] - ivrc[1] * r__[1]) / (r__[0] - ivrc[1] * r__[1]);
- pc1 = ivrc[1] - ivrc[1] * ivrc[2];
- pc2 = ivrc[2];
- }
-/* Inverse filter LPBUF into IVBUF */
- i__1 = *len;
- for (i__ = *len + 1 - *nsamp; i__ <= i__1; ++i__) {
- ivbuf[i__] = lpbuf[i__] - pc1 * lpbuf[i__ - 4] - pc2 * lpbuf[i__ - 8];
- }
- return 0;
-} /* ivfilt_ */
-
diff --git a/1.2-netsec/codecs/lpc10/lpc10.h b/1.2-netsec/codecs/lpc10/lpc10.h
deleted file mode 100644
index 99c64c624..000000000
--- a/1.2-netsec/codecs/lpc10/lpc10.h
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
-
-$Log$
-Revision 1.18 2004/08/31 13:32:11 markster
-Merge NetBSD and Courtesty tone with modifications (bug #2329)
-
-Revision 1.17 2003/10/26 18:50:49 markster
-Make it build and run on MacOS X
-
-Revision 1.3 2003/10/26 18:50:49 markster
-Make it build and run on MacOS X
-
-Revision 1.2 2003/04/23 19:13:35 markster
-More OpenBSD patches
-
-Revision 1.1.1.2 2003/03/16 22:37:30 matteo
-dom mar 16 23:37:23 CET 2003
-
-Revision 1.2 2003/03/16 16:09:48 markster
-Mere James's cleanups for fewer build warnings
-
-Revision 1.1 2000/01/05 00:20:06 markster
-Add broken lpc10 code... It's not too far from working I don't think...
-
- * Revision 1.1 1996/08/19 22:47:31 jaf
- * Initial revision
- *
-
-*/
-
-#ifndef __LPC10_H__
-#define __LPC10_H__
-
-#define LPC10_SAMPLES_PER_FRAME 180
-#define LPC10_BITS_IN_COMPRESSED_FRAME 54
-
-
-/*
-
- The "#if defined"'s in this file are by no means intended to be
- complete. They are what Nautilus uses, which has been successfully
- compiled under DOS with the Microsoft C compiler, and under a few
- versions of Unix with the GNU C compiler.
-
- */
-
-#if defined(unix) || defined(__unix__) || defined(__NetBSD__)
-typedef short INT16;
-typedef int INT32;
-#endif
-
-
-#if defined(__MSDOS__) || defined(MSDOS)
-typedef int INT16;
-typedef long INT32;
-#endif
-
-#if defined(__APPLE__)
-typedef short INT16;
-typedef int INT32;
-#endif
-
-
-/* The initial values for every member of this structure is 0, except
- where noted in comments. */
-
-/* These two lines are copied from f2c.h. There should be a more
- elegant way of doing this than having the same declarations in two
- files. */
-
-typedef float real;
-typedef INT32 integer;
-typedef INT32 logical;
-typedef INT16 shortint;
-
-struct lpc10_encoder_state {
- /* State used only by function hp100 */
- real z11;
- real z21;
- real z12;
- real z22;
-
- /* State used by function analys */
- real inbuf[540], pebuf[540];
- real lpbuf[696], ivbuf[312];
- real bias;
- integer osbuf[10]; /* no initial value necessary */
- integer osptr; /* initial value 1 */
- integer obound[3];
- integer vwin[6] /* was [2][3] */; /* initial value vwin[4] = 307; vwin[5] = 462; */
- integer awin[6] /* was [2][3] */; /* initial value awin[4] = 307; awin[5] = 462; */
- integer voibuf[8] /* was [2][4] */;
- real rmsbuf[3];
- real rcbuf[30] /* was [10][3] */;
- real zpre;
-
-
- /* State used by function onset */
- real n;
- real d__; /* initial value 1.f */
- real fpc; /* no initial value necessary */
- real l2buf[16];
- real l2sum1;
- integer l2ptr1; /* initial value 1 */
- integer l2ptr2; /* initial value 9 */
- integer lasti; /* no initial value necessary */
- logical hyst; /* initial value FALSE_ */
-
- /* State used by function voicin */
- real dither; /* initial value 20.f */
- real snr;
- real maxmin;
- real voice[6] /* was [2][3] */; /* initial value is probably unnecessary */
- integer lbve, lbue, fbve, fbue;
- integer ofbue, sfbue;
- integer olbue, slbue;
- /* Initial values:
- lbve = 3000;
- fbve = 3000;
- fbue = 187;
- ofbue = 187;
- sfbue = 187;
- lbue = 93;
- olbue = 93;
- slbue = 93;
- snr = (real) (fbve / fbue << 6);
- */
-
- /* State used by function dyptrk */
- real s[60];
- integer p[120] /* was [60][2] */;
- integer ipoint;
- real alphax;
-
- /* State used by function chanwr */
- integer isync;
-
-};
-
-
-struct lpc10_decoder_state {
-
- /* State used by function decode */
- integer iptold; /* initial value 60 */
- logical first; /* initial value TRUE_ */
- integer ivp2h;
- integer iovoic;
- integer iavgp; /* initial value 60 */
- integer erate;
- integer drc[30] /* was [3][10] */;
- integer dpit[3];
- integer drms[3];
-
- /* State used by function synths */
- real buf[360];
- integer buflen; /* initial value 180 */
-
- /* State used by function pitsyn */
- integer ivoico; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
- integer ipito; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
- real rmso; /* initial value 1.f */
- real rco[10]; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
- integer jsamp; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
- logical first_pitsyn; /* initial value TRUE_ */
-
- /* State used by function bsynz */
- integer ipo;
- real exc[166];
- real exc2[166];
- real lpi1;
- real lpi2;
- real lpi3;
- real hpi1;
- real hpi2;
- real hpi3;
- real rmso_bsynz;
-
- /* State used by function random */
- integer j; /* initial value 2 */
- integer k; /* initial value 5 */
- shortint y[5]; /* initial value { -21161,-8478,30892,-10216,16950 } */
-
- /* State used by function deemp */
- real dei1;
- real dei2;
- real deo1;
- real deo2;
- real deo3;
-
-};
-
-
-
-/*
-
- Calling sequence:
-
- Call create_lpc10_encoder_state(), which returns a pointer to an
- already initialized lpc10_encoder_state structure.
-
- lpc10_encode reads indices 0 through (LPC10_SAMPLES_PER_FRAME-1) of
- array speech[], and writes indices 0 through
- (LPC10_BITS_IN_COMPRESSED_FRAME-1) of array bits[], and both reads
- and writes the lpc10_encoder_state structure contents. The
- lpc10_encoder_state structure should *not* be initialized for every
- frame of encoded speech. Once at the beginning of execution, done
- automatically for you by create_lpc10_encoder_state(), is enough.
-
- init_lpc10_encoder_state() reinitializes the lpc10_encoder_state
- structure. This might be useful if you are finished processing one
- sound sample, and want to reuse the same lpc10_encoder_state
- structure to process another sound sample. There might be other
- uses as well.
-
- Note that the comments in the lpc10/lpcenc.c file imply that indices
- 1 through 180 of array speech[] are read. These comments were
- written for the Fortran version of the code, before it was
- automatically converted to C by the conversion program f2c. f2c
- seems to use the convention that the pointers to arrays passed as
- function arguments point to the first index used in the Fortran
- code, whatever index that might be (usually 1), and then it modifies
- the pointer inside of the function, like so:
-
- if (speech) {
- --speech;
- }
-
- So that the code can access the first value at index 1 and the last
- at index 180. This makes the translated C code "closer" to the
- original Fortran code.
-
- The calling sequence for the decoder is similar to the encoder. The
- only significant difference is that the array bits[] is read
- (indices 0 through (LPC10_BITS_IN_COMPRESSED_FRAME-1)), and the
- array speech[] is written (indices 0 through
- (LPC10_SAMPLES_PER_FRAME-1)).
-
- */
-
-struct lpc10_encoder_state * create_lpc10_encoder_state (void);
-void init_lpc10_encoder_state (struct lpc10_encoder_state *st);
-int lpc10_encode (real *speech, INT32 *bits, struct lpc10_encoder_state *st);
-
-struct lpc10_decoder_state * create_lpc10_decoder_state (void);
-void init_lpc10_decoder_state (struct lpc10_decoder_state *st);
-int lpc10_decode (INT32 *bits, real *speech, struct lpc10_decoder_state *st);
-
-#endif /* __LPC10_H__ */
diff --git a/1.2-netsec/codecs/lpc10/lpcdec.c b/1.2-netsec/codecs/lpc10/lpcdec.c
deleted file mode 100644
index 39be6e452..000000000
--- a/1.2-netsec/codecs/lpc10/lpcdec.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:30:11 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Changed name of function from lpcenc_ to lpc10_encode, simply to make
- * all lpc10 functions have more consistent naming with each other.
- *
- * Revision 1.1 1996/08/19 22:31:48 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int lpcdec_(integer *bits, real *speech);
-extern int initlpcdec_(void);
-/* comlen contrl_ 12 */
-/*:ref: chanrd_ 14 5 4 4 4 4 4 */
-/*:ref: decode_ 14 7 4 4 4 4 4 6 6 */
-/*:ref: synths_ 14 6 4 4 6 6 6 4 */
-/*:ref: initdecode_ 14 0 */
-/*:ref: initsynths_ 14 0 */
-#endif
-
-/* Common Block Declarations */
-
-extern struct {
- integer order, lframe;
- logical corrp;
-} contrl_;
-
-#define contrl_1 contrl_
-
-/* Table of constant values */
-
-static integer c__10 = 10;
-
-/* ***************************************************************** */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:30:11 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Changed name of function from lpcenc_ to lpc10_encode, simply to make
- * all lpc10 functions have more consistent naming with each other.
- *
- * Revision 1.1 1996/08/19 22:31:48 jaf
- * Initial revision
- * */
-/* Revision 1.1 1996/03/28 00:03:00 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* Decode 54 bits to one frame of 180 speech samples. */
-
-/* Input: */
-/* BITS - 54 encoded bits, stored 1 per array element. */
-/* Indices 1 through 53 read (SYNC bit ignored). */
-/* Output: */
-/* SPEECH - Speech encoded as real values in the range [-1,+1]. */
-/* Indices 1 through 180 written. */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this filter, or */
-/* reinitialize its state for any other reason, call the ENTRY */
-/* INITLPCDEC. */
-
-/* Subroutine */ int lpc10_decode(integer *bits, real *speech,
- struct lpc10_decoder_state *st)
-{
- integer irms, voice[2], pitch, ipitv;
- extern /* Subroutine */ int decode_(integer *, integer *, integer *,
- integer *, integer *, real *, real *, struct lpc10_decoder_state *);
- real rc[10];
- extern /* Subroutine */ int chanrd_(integer *, integer *, integer *,
- integer *, integer *), synths_(integer *,
- integer *, real *, real *, real *, integer *,
- struct lpc10_decoder_state *);
- integer irc[10], len;
- real rms;
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:30:11 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Changed name of function from lpcenc_ to lpc10_encode, simply to make
- * all lpc10 functions have more consistent naming with each other.
- *
- * Revision 1.1 1996/08/19 22:31:48 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Arguments */
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:30:11 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Changed name of function from lpcenc_ to lpc10_encode, simply to make
- * all lpc10 functions have more consistent naming with each other.
- *
- * Revision 1.1 1996/08/19 22:31:48 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:05:55 jaf */
-/* Commented out the common block variables that are not needed by the */
-/* embedded version. */
-
-/* Revision 1.2 1996/03/26 19:34:50 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:44:09 jaf */
-/* Initial revision */
-
-/* LPC Processing control variables: */
-
-/* *** Read-only: initialized in setup */
-
-/* Files for Speech, Parameter, and Bitstream Input & Output, */
-/* and message and debug outputs. */
-
-/* Here are the only files which use these variables: */
-
-/* lpcsim.f setup.f trans.f error.f vqsetup.f */
-
-/* Many files which use fdebug are not listed, since it is only used in */
-/* those other files conditionally, to print trace statements. */
-/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* LPC order, Frame size, Quantization rate, Bits per frame, */
-/* Error correction */
-/* Subroutine SETUP is the only place where order is assigned a value, */
-/* and that value is 10. It could increase efficiency 1% or so to */
-/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
-*/
-/* a variable in a COMMON block, since it is used in many places in the */
-/* core of the coding and decoding routines. Actually, I take that back.
-*/
-/* At least when compiling with f2c, the upper bound of DO loops is */
-/* stored in a local variable before the DO loop begins, and then that is
-*/
-/* compared against on each iteration. */
-/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
-/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
-/* is used in only a few places, and never in the core coding and */
-/* decoding routines, so it could be eliminated entirely. */
-/* nbits is similar to quant, and is given a value of 54 in SETUP. */
-/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
-/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
-/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
-*/
-/* a constant or a variable, since it is only examined once per frame. */
-/* Leaving it as a variable that is set to .TRUE. seems like a good */
-/* idea, since it does enable some error-correction capability for */
-/* unvoiced frames, with no change in the coding rate, and no noticeable
-*/
-/* quality difference in the decoded speech. */
-/* integer quant, nbits */
-/* *** Read/write: variables for debugging, not needed for LPC algorithm
-*/
-
-/* Current frame, Unstable frames, Output clip count, Max onset buffer,
-*/
-/* Debug listing detail level, Line count on listing page */
-
-/* nframe is not needed for an embedded LPC10 at all. */
-/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
-/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
-/* an application, I would recommend removing the call to ERROR in RCCHK,
-*/
-/* and remove ERROR and nunsfm completely. */
-/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
-*/
-/* sread.f. When LPC10 is embedded into an application, one might want */
-/* to cause it to be incremented in a routine that takes the output of */
-/* SYNTHS and sends it to an audio device. It could be optionally */
-/* displayed, for those that might want to know what it is. */
-/* maxosp is never initialized to 0 in SETUP, although it probably should
-*/
-/* be, and it is updated in subroutine ANALYS. I doubt that its value */
-/* would be of much interest to an application in which LPC10 is */
-/* embedded. */
-/* listl and lincnt are not needed for an embedded LPC10 at all. */
-/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* common /contrl/ quant, nbits */
-/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* Local variables that need not be saved */
-/* Uncoded speech parameters */
-/* Coded speech parameters */
-/* Others */
-/* Local state */
-/* None */
- /* Parameter adjustments */
- if (bits) {
- --bits;
- }
- if (speech) {
- --speech;
- }
-
- /* Function Body */
-
- chanrd_(&c__10, &ipitv, &irms, irc, &bits[1]);
- decode_(&ipitv, &irms, irc, voice, &pitch, &rms, rc, st);
- synths_(voice, &pitch, &rms, rc, &speech[1], &len, st);
- return 0;
-} /* lpcdec_ */
diff --git a/1.2-netsec/codecs/lpc10/lpcenc.c b/1.2-netsec/codecs/lpc10/lpcenc.c
deleted file mode 100644
index 09924bd9e..000000000
--- a/1.2-netsec/codecs/lpc10/lpcenc.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:31:21 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Changed name of function from lpcenc_ to lpc10_encode, simply to make
- * all lpc10 functions have more consistent naming with each other.
- *
- * Revision 1.1 1996/08/19 22:31:44 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int lpcenc_(real *speech, integer *bits);
-extern int initlpcenc_(void);
-/*:ref: prepro_ 14 2 6 4 */
-/*:ref: analys_ 14 5 6 4 4 6 6 */
-/*:ref: encode_ 14 7 4 4 6 6 4 4 4 */
-/*:ref: chanwr_ 14 5 4 4 4 4 4 */
-/*:ref: initprepro_ 14 0 */
-/*:ref: initanalys_ 14 0 */
-#endif
-
-/* Table of constant values */
-
-static integer c__180 = 180;
-static integer c__10 = 10;
-
-/* ***************************************************************** */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:31:21 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Changed name of function from lpcenc_ to lpc10_encode, simply to make
- * all lpc10 functions have more consistent naming with each other.
- *
- * Revision 1.1 1996/08/19 22:31:44 jaf
- * Initial revision
- * */
-/* Revision 1.2 1996/03/28 00:01:22 jaf */
-/* Commented out some trace statements. */
-
-/* Revision 1.1 1996/03/28 00:00:27 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* Encode one frame of 180 speech samples to 54 bits. */
-
-/* Input: */
-/* SPEECH - Speech encoded as real values in the range [-1,+1]. */
-/* Indices 1 through 180 read, and modified (by PREPRO). */
-/* Output: */
-/* BITS - 54 encoded bits, stored 1 per array element. */
-/* Indices 1 through 54 written. */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this filter, or */
-/* reinitialize its state for any other reason, call the ENTRY */
-/* INITLPCENC. */
-
-/* Subroutine */ int lpc10_encode(real *speech, integer *bits,
- struct lpc10_encoder_state *st)
-{
- integer irms, voice[2], pitch, ipitv;
- real rc[10];
- extern /* Subroutine */ int encode_(integer *, integer *, real *, real *,
- integer *, integer *, integer *), chanwr_(integer *, integer *,
- integer *, integer *, integer *, struct lpc10_encoder_state *),
- analys_(real *, integer *,
- integer *, real *, real *, struct lpc10_encoder_state *),
- prepro_(real *, integer *, struct lpc10_encoder_state *);
- integer irc[10];
- real rms;
-
-/* Arguments */
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:31:21 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Changed name of function from lpcenc_ to lpc10_encode, simply to make
- * all lpc10 functions have more consistent naming with each other.
- *
- * Revision 1.1 1996/08/19 22:31:44 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Local variables that need not be saved */
-/* Uncoded speech parameters */
-/* Coded speech parameters */
-/* Local state */
-/* None */
- /* Parameter adjustments */
- if (speech) {
- --speech;
- }
- if (bits) {
- --bits;
- }
-
- /* Function Body */
- prepro_(&speech[1], &c__180, st);
- analys_(&speech[1], voice, &pitch, &rms, rc, st);
- encode_(voice, &pitch, &rms, rc, &ipitv, &irms, irc);
- chanwr_(&c__10, &ipitv, &irms, irc, &bits[1], st);
- return 0;
-} /* lpcenc_ */
diff --git a/1.2-netsec/codecs/lpc10/lpcini.c b/1.2-netsec/codecs/lpc10/lpcini.c
deleted file mode 100644
index 12880466f..000000000
--- a/1.2-netsec/codecs/lpc10/lpcini.c
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
-
-$Log$
-Revision 1.18 2003/10/21 18:08:11 markster
-Fix include order
-
-Revision 1.5 2003/10/21 18:08:11 markster
-Fix include order
-
-Revision 1.4 2003/10/21 02:57:29 markster
-FreeBSD patch, take 2
-
-Revision 1.3 2003/10/16 21:11:30 martinp
-Revert the previous patch since it's braking compilation
-
-Revision 1.1 2003/02/12 13:59:15 matteo
-Initial revision
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:35:41 jaf
- * Added functions for allocating and initializing lpc10_encoder_state
- * and lpc10_decoder_state structures.
- *
- * Revision 1.1 1996/08/19 22:31:40 jaf
- * Initial revision
- *
-
-*/
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int lpcini_(void);
-/* comlen contrl_ 12 */
-/*:ref: initlpcenc_ 14 0 */
-/*:ref: initlpcdec_ 14 0 */
-#endif
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include <stdlib.h>
-#include "f2c.h"
-
-/* Common Block Declarations */
-
-struct {
- integer order, lframe;
- logical corrp;
-} contrl_;
-
-#define contrl_1 contrl_
-
-/* ***************************************************************** */
-
-/* $Log$
- * Revision 1.18 2003/10/21 18:08:11 markster
- * Fix include order
- *
-/* Revision 1.5 2003/10/21 18:08:11 markster
-/* Fix include order
-/*
-/* Revision 1.4 2003/10/21 02:57:29 markster
-/* FreeBSD patch, take 2
-/*
-/* Revision 1.3 2003/10/16 21:11:30 martinp
-/* Revert the previous patch since it's braking compilation
-/*
-/* Revision 1.1 2003/02/12 13:59:15 matteo
-/* Initial revision
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:35:41 jaf
- * Added functions for allocating and initializing lpc10_encoder_state
- * and lpc10_decoder_state structures.
- *
- * Revision 1.1 1996/08/19 22:31:40 jaf
- * Initial revision
- * */
-/* Revision 1.1 1996/03/28 00:04:05 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* Initialize COMMON block variables used by LPC-10 encoder and decoder, */
-/* and call initialization routines for both of them. */
-
-/* Subroutine */ int lpcini_(void)
-{
-
-/* $Log$
- * Revision 1.18 2003/10/21 18:08:11 markster
- * Fix include order
- *
-/* Revision 1.5 2003/10/21 18:08:11 markster
-/* Fix include order
-/*
-/* Revision 1.4 2003/10/21 02:57:29 markster
-/* FreeBSD patch, take 2
-/*
-/* Revision 1.3 2003/10/16 21:11:30 martinp
-/* Revert the previous patch since it's braking compilation
-/*
-/* Revision 1.1 2003/02/12 13:59:15 matteo
-/* Initial revision
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:35:41 jaf
- * Added functions for allocating and initializing lpc10_encoder_state
- * and lpc10_decoder_state structures.
- *
- * Revision 1.1 1996/08/19 22:31:40 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* $Log$
- * Revision 1.18 2003/10/21 18:08:11 markster
- * Fix include order
- *
-/* Revision 1.5 2003/10/21 18:08:11 markster
-/* Fix include order
-/*
-/* Revision 1.4 2003/10/21 02:57:29 markster
-/* FreeBSD patch, take 2
-/*
-/* Revision 1.3 2003/10/16 21:11:30 martinp
-/* Revert the previous patch since it's braking compilation
-/*
-/* Revision 1.1 2003/02/12 13:59:15 matteo
-/* Initial revision
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:35:41 jaf
- * Added functions for allocating and initializing lpc10_encoder_state
- * and lpc10_decoder_state structures.
- *
- * Revision 1.1 1996/08/19 22:31:40 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:05:55 jaf */
-/* Commented out the common block variables that are not needed by the */
-/* embedded version. */
-
-/* Revision 1.2 1996/03/26 19:34:50 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:44:09 jaf */
-/* Initial revision */
-
-/* LPC Processing control variables: */
-
-/* *** Read-only: initialized in setup */
-
-/* Files for Speech, Parameter, and Bitstream Input & Output, */
-/* and message and debug outputs. */
-
-/* Here are the only files which use these variables: */
-
-/* lpcsim.f setup.f trans.f error.f vqsetup.f */
-
-/* Many files which use fdebug are not listed, since it is only used in */
-/* those other files conditionally, to print trace statements. */
-/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* LPC order, Frame size, Quantization rate, Bits per frame, */
-/* Error correction */
-/* Subroutine SETUP is the only place where order is assigned a value, */
-/* and that value is 10. It could increase efficiency 1% or so to */
-/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
-*/
-/* a variable in a COMMON block, since it is used in many places in the */
-/* core of the coding and decoding routines. Actually, I take that back.
-*/
-/* At least when compiling with f2c, the upper bound of DO loops is */
-/* stored in a local variable before the DO loop begins, and then that is
-*/
-/* compared against on each iteration. */
-/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
-/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
-/* is used in only a few places, and never in the core coding and */
-/* decoding routines, so it could be eliminated entirely. */
-/* nbits is similar to quant, and is given a value of 54 in SETUP. */
-/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
-/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
-/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
-*/
-/* a constant or a variable, since it is only examined once per frame. */
-/* Leaving it as a variable that is set to .TRUE. seems like a good */
-/* idea, since it does enable some error-correction capability for */
-/* unvoiced frames, with no change in the coding rate, and no noticeable
-*/
-/* quality difference in the decoded speech. */
-/* integer quant, nbits */
-/* *** Read/write: variables for debugging, not needed for LPC algorithm
-*/
-
-/* Current frame, Unstable frames, Output clip count, Max onset buffer,
-*/
-/* Debug listing detail level, Line count on listing page */
-
-/* nframe is not needed for an embedded LPC10 at all. */
-/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
-/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
-/* an application, I would recommend removing the call to ERROR in RCCHK,
-*/
-/* and remove ERROR and nunsfm completely. */
-/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
-*/
-/* sread.f. When LPC10 is embedded into an application, one might want */
-/* to cause it to be incremented in a routine that takes the output of */
-/* SYNTHS and sends it to an audio device. It could be optionally */
-/* displayed, for those that might want to know what it is. */
-/* maxosp is never initialized to 0 in SETUP, although it probably should
-*/
-/* be, and it is updated in subroutine ANALYS. I doubt that its value */
-/* would be of much interest to an application in which LPC10 is */
-/* embedded. */
-/* listl and lincnt are not needed for an embedded LPC10 at all. */
-/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* common /contrl/ quant, nbits */
-/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
- contrl_1.order = 10;
- contrl_1.lframe = 180;
- contrl_1.corrp = TRUE_;
- return 0;
-} /* lpcini_ */
-
-
-
-/* Allocate memory for, and initialize, the state that needs to be
- kept from encoding one frame to the next for a single
- LPC-10-compressed audio stream. Return 0 if malloc fails,
- otherwise return pointer to new structure. */
-
-struct lpc10_encoder_state *
-create_lpc10_encoder_state()
-{
- struct lpc10_encoder_state *st;
-
- st = (struct lpc10_encoder_state *)
- malloc((unsigned) sizeof (struct lpc10_encoder_state));
- if (st != 0) {
- init_lpc10_encoder_state(st);
- }
- return (st);
-}
-
-
-
-void init_lpc10_encoder_state(struct lpc10_encoder_state *st)
-{
- int i;
-
- lpcini_();
-
- /* State used only by function hp100 */
- st->z11 = 0.0f;
- st->z21 = 0.0f;
- st->z12 = 0.0f;
- st->z22 = 0.0f;
-
- /* State used by function analys */
- for (i = 0; i < 540; i++) {
- st->inbuf[i] = 0.0f;
- st->pebuf[i] = 0.0f;
- }
- for (i = 0; i < 696; i++) {
- st->lpbuf[i] = 0.0f;
- }
- for (i = 0; i < 312; i++) {
- st->ivbuf[i] = 0.0f;
- }
- st->bias = 0.0f;
- /* integer osbuf[10]; /* no initial value necessary */
- st->osptr = 1;
- for (i = 0; i < 3; i++) {
- st->obound[i] = 0;
- }
- st->vwin[4] = 307;
- st->vwin[5] = 462;
- st->awin[4] = 307;
- st->awin[5] = 462;
- for (i = 0; i < 8; i++) {
- st->voibuf[i] = 0;
- }
- for (i = 0; i < 3; i++) {
- st->rmsbuf[i] = 0.0f;
- }
- for (i = 0; i < 30; i++) {
- st->rcbuf[i] = 0.0f;
- }
- st->zpre = 0.0f;
-
-
- /* State used by function onset */
- st->n = 0.0f;
- st->d__ = 1.0f;
- /* real fpc; /* no initial value necessary */
- for (i = 0; i < 16; i++) {
- st->l2buf[i] = 0.0f;
- }
- st->l2sum1 = 0.0f;
- st->l2ptr1 = 1;
- st->l2ptr2 = 9;
- /* integer lasti; /* no initial value necessary */
- st->hyst = FALSE_;
-
- /* State used by function voicin */
- st->dither = 20.0f;
- st->maxmin = 0.0f;
- for (i = 0; i < 6; i++) {
- st->voice[i] = 0.0f;
- }
- st->lbve = 3000;
- st->fbve = 3000;
- st->fbue = 187;
- st->ofbue = 187;
- st->sfbue = 187;
- st->lbue = 93;
- st->olbue = 93;
- st->slbue = 93;
- st->snr = (real) (st->fbve / st->fbue << 6);
-
- /* State used by function dyptrk */
- for (i = 0; i < 60; i++) {
- st->s[i] = 0.0f;
- }
- for (i = 0; i < 120; i++) {
- st->p[i] = 0;
- }
- st->ipoint = 0;
- st->alphax = 0.0f;
-
- /* State used by function chanwr */
- st->isync = 0;
-
-}
-
-
-
-/* Allocate memory for, and initialize, the state that needs to be
- kept from decoding one frame to the next for a single
- LPC-10-compressed audio stream. Return 0 if malloc fails,
- otherwise return pointer to new structure. */
-
-struct lpc10_decoder_state *
-create_lpc10_decoder_state()
-{
- struct lpc10_decoder_state *st;
-
- st = (struct lpc10_decoder_state *)
- malloc((unsigned) sizeof (struct lpc10_decoder_state));
- if (st != 0) {
- init_lpc10_decoder_state(st);
- }
- return (st);
-}
-
-
-
-void init_lpc10_decoder_state(struct lpc10_decoder_state *st)
-{
- int i;
-
- lpcini_();
-
- /* State used by function decode */
- st->iptold = 60;
- st->first = TRUE_;
- st->ivp2h = 0;
- st->iovoic = 0;
- st->iavgp = 60;
- st->erate = 0;
- for (i = 0; i < 30; i++) {
- st->drc[i] = 0;
- }
- for (i = 0; i < 3; i++) {
- st->dpit[i] = 0;
- st->drms[i] = 0;
- }
-
- /* State used by function synths */
- for (i = 0; i < 360; i++) {
- st->buf[i] = 0.0f;
- }
- st->buflen = 180;
-
- /* State used by function pitsyn */
- /* ivoico; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
- /* ipito; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
- st->rmso = 1.0f;
- /* rco[10]; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
- /* integer jsamp; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
- st->first_pitsyn = TRUE_;
-
- /* State used by function bsynz */
- st->ipo = 0;
- for (i = 0; i < 166; i++) {
- st->exc[i] = 0.0f;
- st->exc2[i] = 0.0f;
- }
- st->lpi1 = 0.0f;
- st->lpi2 = 0.0f;
- st->lpi3 = 0.0f;
- st->hpi1 = 0.0f;
- st->hpi2 = 0.0f;
- st->hpi3 = 0.0f;
- st->rmso_bsynz = 0.0f;
-
- /* State used by function random */
- st->j = 2;
- st->k = 5;
- st->y[0] = (shortint) -21161;
- st->y[1] = (shortint) -8478;
- st->y[2] = (shortint) 30892;
- st->y[3] = (shortint) -10216;
- st->y[4] = (shortint) 16950;
-
- /* State used by function deemp */
- st->dei1 = 0.0f;
- st->dei2 = 0.0f;
- st->deo1 = 0.0f;
- st->deo2 = 0.0f;
- st->deo3 = 0.0f;
-}
diff --git a/1.2-netsec/codecs/lpc10/lpfilt.c b/1.2-netsec/codecs/lpc10/lpfilt.c
deleted file mode 100644
index f83e40155..000000000
--- a/1.2-netsec/codecs/lpc10/lpfilt.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:31:35 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int lpfilt_(real *inbuf, real *lpbuf, integer *len, integer *nsamp);
-#endif
-
-/* *********************************************************************** */
-
-/* LPFILT Version 55 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:31:35 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/15 16:53:49 jaf */
-/* Just put comment header in standard form. */
-
-/* Revision 1.2 1996/03/12 23:58:06 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:47:44 jaf */
-/* Initial revision */
-
-
-/* *********************************************************************** */
-
-/* 31 Point Equiripple FIR Low-Pass Filter */
-/* Linear phase, delay = 15 samples */
-
-/* Passband: ripple = 0.25 dB, cutoff = 800 Hz */
-/* Stopband: atten. = 40. dB, cutoff = 1240 Hz */
-
-/* Inputs: */
-/* LEN - Length of speech buffers */
-/* NSAMP - Number of samples to filter */
-/* INBUF - Input speech buffer */
-/* Indices len-nsamp-29 through len are read. */
-/* Output: */
-/* LPBUF - Low passed speech buffer (must be different array than INBUF) */
-/* Indices len+1-nsamp through len are written. */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int lpfilt_(real *inbuf, real *lpbuf, integer *len, integer *
- nsamp)
-{
- /* System generated locals */
- integer i__1;
-
- /* Local variables */
- integer j;
- real t;
-
-/* Arguments */
-/* Parameters/constants */
-/* Local variables that need not be saved */
-/* Local state */
-/* None */
- /* Parameter adjustments */
- --lpbuf;
- --inbuf;
-
- /* Function Body */
- i__1 = *len;
- for (j = *len + 1 - *nsamp; j <= i__1; ++j) {
- t = (inbuf[j] + inbuf[j - 30]) * -.0097201988f;
- t += (inbuf[j - 1] + inbuf[j - 29]) * -.0105179986f;
- t += (inbuf[j - 2] + inbuf[j - 28]) * -.0083479648f;
- t += (inbuf[j - 3] + inbuf[j - 27]) * 5.860774e-4f;
- t += (inbuf[j - 4] + inbuf[j - 26]) * .0130892089f;
- t += (inbuf[j - 5] + inbuf[j - 25]) * .0217052232f;
- t += (inbuf[j - 6] + inbuf[j - 24]) * .0184161253f;
- t += (inbuf[j - 7] + inbuf[j - 23]) * 3.39723e-4f;
- t += (inbuf[j - 8] + inbuf[j - 22]) * -.0260797087f;
- t += (inbuf[j - 9] + inbuf[j - 21]) * -.0455563702f;
- t += (inbuf[j - 10] + inbuf[j - 20]) * -.040306855f;
- t += (inbuf[j - 11] + inbuf[j - 19]) * 5.029835e-4f;
- t += (inbuf[j - 12] + inbuf[j - 18]) * .0729262903f;
- t += (inbuf[j - 13] + inbuf[j - 17]) * .1572008878f;
- t += (inbuf[j - 14] + inbuf[j - 16]) * .2247288674f;
- t += inbuf[j - 15] * .250535965f;
- lpbuf[j] = t;
- }
- return 0;
-} /* lpfilt_ */
-
diff --git a/1.2-netsec/codecs/lpc10/median.c b/1.2-netsec/codecs/lpc10/median.c
deleted file mode 100644
index ed4e2819d..000000000
--- a/1.2-netsec/codecs/lpc10/median.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:31:31 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern integer median_(integer *d1, integer *d2, integer *d3);
-#endif
-
-/* ********************************************************************* */
-
-/* MEDIAN Version 45G */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:31:31 jaf
- * Initial revision
- * */
-/* Revision 1.2 1996/03/14 22:30:22 jaf */
-/* Just rearranged the comments and local variable declarations a bit. */
-
-/* Revision 1.1 1996/02/07 14:47:53 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* Find median of three values */
-
-/* Input: */
-/* D1,D2,D3 - Three input values */
-/* Output: */
-/* MEDIAN - Median value */
-
-integer median_(integer *d1, integer *d2, integer *d3)
-{
- /* System generated locals */
- integer ret_val;
-
-/* Arguments */
- ret_val = *d2;
- if (*d2 > *d1 && *d2 > *d3) {
- ret_val = *d1;
- if (*d3 > *d1) {
- ret_val = *d3;
- }
- } else if (*d2 < *d1 && *d2 < *d3) {
- ret_val = *d1;
- if (*d3 < *d1) {
- ret_val = *d3;
- }
- }
- return ret_val;
-} /* median_ */
-
diff --git a/1.2-netsec/codecs/lpc10/mload.c b/1.2-netsec/codecs/lpc10/mload.c
deleted file mode 100644
index 749646097..000000000
--- a/1.2-netsec/codecs/lpc10/mload.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:31:25 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int mload_(integer *order, integer *awins, integer *awinf, real *speech, real *phi, real *psi);
-#endif
-
-/* ***************************************************************** */
-
-/* MLOAD Version 48 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:31:25 jaf
- * Initial revision
- * */
-/* Revision 1.5 1996/03/27 23:59:51 jaf */
-/* Added some more accurate comments about which indices of the argument */
-/* array SPEECH are read. I thought that this might be the cause of a */
-/* problem I've been having, but it isn't. */
-
-/* Revision 1.4 1996/03/26 19:16:53 jaf */
-/* Commented out the code at the end that copied the lower triangular */
-/* half of PHI into the upper triangular half (making the resulting */
-/* matrix symmetric). The upper triangular half was never used by later */
-/* code in subroutine ANALYS. */
-
-/* Revision 1.3 1996/03/18 21:16:00 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 16:47:41 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:48:01 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* Load a covariance matrix. */
-
-/* Input: */
-/* ORDER - Analysis order */
-/* AWINS - Analysis window start */
-/* AWINF - Analysis window finish */
-/* SPEECH(AWINF) - Speech buffer */
-/* Indices MIN(AWINS, AWINF-(ORDER-1)) through */
-/* MAX(AWINF, AWINS+(ORDER-1)) read. */
-/* As long as (AWINF-AWINS) .GE. (ORDER-1), */
-/* this is just indices AWINS through AWINF. */
-/* Output: */
-/* PHI(ORDER,ORDER) - Covariance matrix */
-/* Lower triangular half and diagonal written, and read.*/
-/* Upper triangular half untouched. */
-/* PSI(ORDER) - Prediction vector */
-/* Indices 1 through ORDER written, */
-/* and most are read after that. */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int mload_(integer *order, integer *awins, integer *awinf,
- real *speech, real *phi, real *psi)
-{
- /* System generated locals */
- integer phi_dim1, phi_offset, i__1, i__2;
-
- /* Local variables */
- integer c__, i__, r__, start;
-
-/* Arguments */
-/* Local variables that need not be saved */
-/* Load first column of triangular covariance matrix PHI */
- /* Parameter adjustments */
- --psi;
- phi_dim1 = *order;
- phi_offset = phi_dim1 + 1;
- phi -= phi_offset;
- --speech;
-
- /* Function Body */
- start = *awins + *order;
- i__1 = *order;
- for (r__ = 1; r__ <= i__1; ++r__) {
- phi[r__ + phi_dim1] = 0.f;
- i__2 = *awinf;
- for (i__ = start; i__ <= i__2; ++i__) {
- phi[r__ + phi_dim1] += speech[i__ - 1] * speech[i__ - r__];
- }
- }
-/* Load last element of vector PSI */
- psi[*order] = 0.f;
- i__1 = *awinf;
- for (i__ = start; i__ <= i__1; ++i__) {
- psi[*order] += speech[i__] * speech[i__ - *order];
- }
-/* End correct to get additional columns of PHI */
- i__1 = *order;
- for (r__ = 2; r__ <= i__1; ++r__) {
- i__2 = r__;
- for (c__ = 2; c__ <= i__2; ++c__) {
- phi[r__ + c__ * phi_dim1] = phi[r__ - 1 + (c__ - 1) * phi_dim1] -
- speech[*awinf + 1 - r__] * speech[*awinf + 1 - c__] +
- speech[start - r__] * speech[start - c__];
- }
- }
-/* End correct to get additional elements of PSI */
- i__1 = *order - 1;
- for (c__ = 1; c__ <= i__1; ++c__) {
- psi[c__] = phi[c__ + 1 + phi_dim1] - speech[start - 1] * speech[start
- - 1 - c__] + speech[*awinf] * speech[*awinf - c__];
- }
-/* Copy lower triangular section into upper (why bother?) */
-/* I'm commenting this out, since the upper triangular half of PHI
-*/
-/* is never used by later code, unless a sufficiently high level of
-*/
-/* tracing is turned on. */
-/* DO R = 1,ORDER */
-/* DO C = 1,R-1 */
-/* PHI(C,R) = PHI(R,C) */
-/* END DO */
-/* END DO */
- return 0;
-} /* mload_ */
-
diff --git a/1.2-netsec/codecs/lpc10/onset.c b/1.2-netsec/codecs/lpc10/onset.c
deleted file mode 100644
index b8037a84d..000000000
--- a/1.2-netsec/codecs/lpc10/onset.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:37:55 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:31:18 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int onset_(real *pebuf, integer *osbuf, integer *osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *lframe, struct lpc10_encoder_state *st);
-#endif
-
-/* Table of constant values */
-
-static real c_b2 = 1.f;
-
-/* ****************************************************************** */
-
-/* ONSET Version 49 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:37:55 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:31:18 jaf
- * Initial revision
- * */
-/* Revision 1.5 1996/03/15 16:41:01 jaf */
-/* Just rearranged INITONSET assignment orders to be consistent with */
-/* order of DATA statements in ONSET. */
-
-/* Revision 1.4 1996/03/15 15:48:27 jaf */
-/* Changed some comments, and only reordered the DATA statements (their */
-/* meaning wasn't changed). */
-
-/* Revision 1.3 1996/03/14 23:53:06 jaf */
-/* Added an entry INITONSET that reinitializes the local state variables */
-/* of subroutine ONSET. */
-
-/* Rearranged quite a few comments, adding more explaining which */
-/* arguments were inputs, and how the modified ones can be changed. */
-
-/* Revision 1.2 1996/03/12 23:53:00 jaf */
-/* Lots of comments added about the local state of this subroutine that */
-/* must be saved from one invocation to the next. */
-
-/* One constant 180 replaced with LFRAME, which should be "more general", */
-/* even though it would probably require many more changes than this to */
-/* get this coder to work for other frame sizes. */
-
-/* Revision 1.1 1996/02/07 14:48:09 jaf */
-/* Initial revision */
-
-
-/* ****************************************************************** */
-
-/* Floating point version */
-
-
-/* Detection of onsets in (or slightly preceding) the futuremost frame */
-/* of speech. */
-
-
-/* Input: */
-/* PEBUF(SBUFL:SBUFH) - Preemphasized speech */
-/* Indices SBUFH-LFRAME through SBUFH are read. */
-/* OSLEN - Maximum number of onsets that can be stored in OSBUF. */
-/* SBUFL, SBUFH - Range of PEBUF */
-/* LFRAME - length of a frame, in samples */
-/* Input/Output: */
-/* OSBUF(OSLEN) - Buffer which holds sorted indexes of onsets */
-/* Indices A through B are modified, where A */
-/* is the original value of OSPTR, and B is the final */
-/* value of OSPTR-1. B is at most OSLEN. */
-/* OSPTR - Free pointer into OSBUF */
-/* Initial value should be .LE. OSLEN+1. */
-/* If so, final value grows by one for each new onset */
-/* found, and final value will be .LE. OSLEN+1. */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this subroutine, or */
-/* reinitialize its state for any other reason, call the ENTRY INITONSET. */
-
-/* Subroutine */ int onset_(real *pebuf, integer *osbuf, integer *
- osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *
- lframe, struct lpc10_encoder_state *st)
-{
- /* Initialized data */
-
- real *n;
- real *d__;
- real *l2buf;
- real *l2sum1;
- integer *l2ptr1;
- integer *l2ptr2;
- logical *hyst;
-
- /* System generated locals */
- integer pebuf_offset, i__1;
- real r__1;
-
- /* Builtin functions */
- double r_sign(real *, real *);
-
- /* Local variables */
- integer i__;
- integer *lasti;
- real l2sum2;
- real *fpc;
-
-/* Arguments */
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:37:55 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:31:18 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Parameters/constants */
-/* Parameters for onset detection algorithm: */
-/* L2 Threshold for filtered slope of FPC (function of L2WID!) */
-/* L2LAG Lag due to both filters which compute filtered slope of FPC */
-/* L2WID Width of the filter which computes the slope of FPC */
-/* OSHYST The number of samples of slope(FPC) which must be below */
-/* the threshold before a new onset may be declared. */
-/* Local variables that need not be saved */
-/* Local state */
-/* Variables */
-/* N, D Numerator and denominator of prediction filters */
-/* FPC Current prediction coefs */
-/* L2BUF, L2SUM1, L2SUM2 State of slope filter */
-/* The only "significant" change I've made is to change L2SUM2 out
-*/
-/* of the list of local variables that need to be saved, since it */
-/* didn't need to be. */
-/* L2SUM1 need not be, but avoiding saving it would require a small
-*/
-/* change to the body of the code. See comments below for an */
-/* example of how the code could be changed to avoid saving L2SUM1.
-*/
-/* FPC and LASTI are saved from one invocation to the next, but */
-/* they are not given initial values. This is acceptable, because
-*/
-/* FPC will be assigned a value the first time that this function */
-/* is called after D is initialized to 1, since the formula to */
-/* change D will not change it to 0 in one step, and the IF (D */
-/* .NE. 0) statement will execute its THEN part, initializing FPC.
-*/
-
-/* LASTI's value will not be used until HYST is .TRUE., and */
-/* whenever HYST is changed from its initial value of .FALSE., */
-/* LASTI is assigned a value. */
-/* In a C version of this coder, it would be nice if all of these */
-/* saved things, in this and all other subroutines, could be stored
-*/
-/* in a single struct lpc10_coder_state_t, initialized with a call
-*/
-/* to a function like lpc10_init(&lpc10_coder_state). In this way,
-*/
-/* a program that used these functions could conveniently alternate
-*/
-/* coding more than one distinct audio stream. */
-
- n = &(st->n);
- d__ = &(st->d__);
- fpc = &(st->fpc);
- l2buf = &(st->l2buf[0]);
- l2sum1 = &(st->l2sum1);
- l2ptr1 = &(st->l2ptr1);
- l2ptr2 = &(st->l2ptr2);
- lasti = &(st->lasti);
- hyst = &(st->hyst);
-
- /* Parameter adjustments */
- if (osbuf) {
- --osbuf;
- }
- if (pebuf) {
- pebuf_offset = *sbufl;
- pebuf -= pebuf_offset;
- }
-
- /* Function Body */
-
-/* The following line subtracted a hard-coded "180" from LASTI, */
-/* instead of using a variable like LFRAME or a constant like */
-/* MAXFRM. I changed it to LFRAME, for "generality". */
- if (*hyst) {
- *lasti -= *lframe;
- }
- i__1 = *sbufh;
- for (i__ = *sbufh - *lframe + 1; i__ <= i__1; ++i__) {
-/* Compute FPC; Use old FPC on divide by zero; Clamp FPC to +/- 1.
-*/
- *n = (pebuf[i__] * pebuf[i__ - 1] + (*n) * 63.f) / 64.f;
-/* Computing 2nd power */
- r__1 = pebuf[i__ - 1];
- *d__ = (r__1 * r__1 + (*d__) * 63.f) / 64.f;
- if ((*d__) != 0.f) {
- if (abs(*n) > (*d__)) {
- *fpc = r_sign(&c_b2, n);
- } else {
- *fpc = (*n) / (*d__);
- }
- }
-/* Filter FPC */
-/* In order to allow L2SUM1 not to be saved from one invocation
-of */
-/* this subroutine to the next, one could change the sequence of
- */
-/* assignments below, up to the IF statement, to the following.
- In */
-/* addition, the initial value of L2PTR2 should be changed to */
-/* L2WID/2 instead of L2WID/2+1. */
-
-/* L2SUM1 = L2BUF(L2PTR2) */
-/* L2PTR2 = MOD(L2PTR2,L2WID)+1 */
-/* L2SUM1 = L2SUM1 - L2BUF(L2PTR2) + FPC */
-/* L2BUF(L2PTR2) = L2SUM1 */
-
-/* * The following lines didn't change from the original: */
-/* L2SUM2 = L2BUF(L2PTR1) */
-/* L2BUF(L2PTR1) = FPC */
-/* L2PTR1 = MOD(L2PTR1,L2WID)+1 */
-
- l2sum2 = l2buf[*l2ptr1 - 1];
- *l2sum1 = *l2sum1 - l2buf[*l2ptr2 - 1] + *fpc;
- l2buf[*l2ptr2 - 1] = *l2sum1;
- l2buf[*l2ptr1 - 1] = *fpc;
- *l2ptr1 = *l2ptr1 % 16 + 1;
- *l2ptr2 = *l2ptr2 % 16 + 1;
- if ((r__1 = *l2sum1 - l2sum2, abs(r__1)) > 1.7f) {
- if (! (*hyst)) {
-/* Ignore if buffer full */
- if (*osptr <= *oslen) {
- osbuf[*osptr] = i__ - 9;
- ++(*osptr);
- }
- *hyst = TRUE_;
- }
- *lasti = i__;
-/* After one onset detection, at least OSHYST sample times m
-ust go */
-/* by before another is allowed to occur. */
- } else if ((*hyst) && i__ - *lasti >= 10) {
- *hyst = FALSE_;
- }
- }
- return 0;
-} /* onset_ */
diff --git a/1.2-netsec/codecs/lpc10/pitsyn.c b/1.2-netsec/codecs/lpc10/pitsyn.c
deleted file mode 100644
index 3152ce44b..000000000
--- a/1.2-netsec/codecs/lpc10/pitsyn.c
+++ /dev/null
@@ -1,583 +0,0 @@
-/*
-
-$Log$
-Revision 1.16 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.15 2003/11/23 22:14:32 markster
-Various warning cleanups
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:40:12 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:31:12 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st);
-#endif
-
-/* ***************************************************************** */
-
-/* PITSYN Version 53 */
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/11/23 22:14:32 markster
-/* Various warning cleanups
-/*
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:40:12 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:31:12 jaf
- * Initial revision
- * */
-/* Revision 1.2 1996/03/25 18:49:07 jaf */
-/* Added commments about which indices of array arguments are read or */
-/* written. */
-
-/* Rearranged local variable declarations to indicate which need to be */
-/* saved from one invocation to the next. Added entry INITPITSYN to */
-/* reinitialize local state variables, if desired. */
-
-/* Added lots of comments about proving that the maximum number of pitch */
-/* periods (NOUT) that can be returned is 16. The call to STOP that */
-/* could happen if NOUT got too large was removed as a result. */
-
-/* Also proved that the total number of samples returned from N calls, */
-/* each with identical values of LFRAME, will always be in the range */
-/* N*LFRAME-MAXPIT+1 to N*LFRAME. */
-
-/* Revision 1.1 1996/02/07 14:48:18 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* Synthesize a single pitch epoch */
-
-/* Input: */
-/* ORDER - Synthesis order (number of RC's) */
-/* VOICE - Half frame voicing decisions */
-/* Indices 1 through 2 read. */
-/* LFRAME - Length of speech buffer */
-/* Input/Output: */
-/* PITCH - Pitch */
-/* This value should be in the range MINPIT (20) to MAXPIT */
-/* (156), inclusive. */
-/* PITCH can be modified under some conditions. */
-/* RMS - Energy (can be modified) */
-/* RMS is changed to 1 if the value passed in is less than 1. */
-/* RC - Reflection coefficients */
-/* Indices 1 through ORDER can be temporarily overwritten with */
-/* RCO, and then replaced with original values, under some */
-/* conditions. */
-/* Output: */
-/* IVUV - Pitch epoch voicing decisions */
-/* Indices (I) of IVUV, IPITI, and RMSI are written, */
-/* and indices (J,I) of RCI are written, */
-/* where I ranges from 1 to NOUT, and J ranges from 1 to ORDER. */
-/* IPITI - Pitch epoch length */
-/* RMSI - Pitch epoch energy */
-/* RCI - Pitch epoch RC's */
-/* NOUT - Number of pitch periods in this frame */
-/* This is at least 0, at least 1 if MAXPIT .LT. LFRAME (this */
-/* is currently true on every call), and can never be more than */
-/* (LFRAME+MAXPIT-1)/PITCH, which is currently 16 with */
-/* LFRAME=180, MAXPIT=156, and PITCH .GE. 20, as SYNTHS */
-/* guarantees when it calls this subroutine. */
-/* RATIO - Previous to present energy ratio */
-/* Always assigned a value. */
-
-/* Subroutine */ int pitsyn_(integer *order, integer *voice,
- integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv,
- integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio,
- struct lpc10_decoder_state *st)
-{
- /* Initialized data */
-
- real *rmso;
- logical *first;
-
- /* System generated locals */
- integer rci_dim1 = 0, rci_offset, i__1, i__2;
- real r__1;
-
- /* Builtin functions */
- double log(doublereal), exp(doublereal);
-
- /* Local variables */
- real alrn, alro, yarc[10], prop;
- integer i__, j, vflag, jused, lsamp;
- integer *jsamp;
- real slope;
- integer *ipito;
- real uvpit;
- integer ip, nl, ivoice;
- integer *ivoico;
- integer istart;
- real *rco;
- real xxy;
-
-/* Arguments */
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/11/23 22:14:32 markster
-/* Various warning cleanups
-/*
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:40:12 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:31:12 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Local variables that need not be saved */
-/* LSAMP is initialized in the IF (FIRST) THEN clause, but it is */
-/* not used the first time through, and it is given a value before
-*/
-/* use whenever FIRST is .FALSE., so it appears unnecessary to */
-/* assign it a value when FIRST is .TRUE. */
-/* Local state */
-/* FIRST - .TRUE. only on first call to PITSYN. */
-/* IVOICO - Previous VOICE(2) value. */
-/* IPITO - Previous PITCH value. */
-/* RMSO - Previous RMS value. */
-/* RCO - Previous RC values. */
-
-/* JSAMP - If this routine is called N times with identical values of */
-/* LFRAME, then the total length of all pitch periods returned */
-/* is always N*LFRAME-JSAMP, and JSAMP is always in the range 0
-*/
-/* to MAXPIT-1 (see below for why this is so). Thus JSAMP is */
-/* the number of samples "left over" from the previous call to */
-/* PITSYN, that haven't been "used" in a pitch period returned */
-/* from this subroutine. Every time this subroutine is called,
-*/
-/* it returns pitch periods with a total length of at most */
-/* LFRAME+JSAMP. */
-
-/* IVOICO, IPITO, RCO, and JSAMP need not be assigned an initial value */
-/* with a DATA statement, because they are always initialized on the */
-/* first call to PITSYN. */
-
-/* FIRST and RMSO should be initialized with DATA statements, because */
-/* even on the first call, they are used before being initialized. */
- /* Parameter adjustments */
- if (rc) {
- --rc;
- }
- if (rci) {
- rci_dim1 = *order;
- rci_offset = rci_dim1 + 1;
- rci -= rci_offset;
- }
- if (voice) {
- --voice;
- }
- if (ivuv) {
- --ivuv;
- }
- if (ipiti) {
- --ipiti;
- }
- if (rmsi) {
- --rmsi;
- }
-
- /* Function Body */
- ivoico = &(st->ivoico);
- ipito = &(st->ipito);
- rmso = &(st->rmso);
- rco = &(st->rco[0]);
- jsamp = &(st->jsamp);
- first = &(st->first_pitsyn);
-
- if (*rms < 1.f) {
- *rms = 1.f;
- }
- if (*rmso < 1.f) {
- *rmso = 1.f;
- }
- uvpit = 0.f;
- *ratio = *rms / (*rmso + 8.f);
- if (*first) {
- lsamp = 0;
- ivoice = voice[2];
- if (ivoice == 0) {
- *pitch = *lframe / 4;
- }
- *nout = *lframe / *pitch;
- *jsamp = *lframe - *nout * *pitch;
-
-/* SYNTHS only calls this subroutine with PITCH in the range
-20 */
-/* to 156. LFRAME = MAXFRM = 180, so NOUT is somewhere in th
-e */
-/* range 1 to 9. */
-
-/* JSAMP is "LFRAME mod PITCH", so it is in the range 0 to */
-/* (PITCH-1), or 0 to MAXPIT-1=155, after the first call. */
-
- i__1 = *nout;
- for (i__ = 1; i__ <= i__1; ++i__) {
- i__2 = *order;
- for (j = 1; j <= i__2; ++j) {
- rci[j + i__ * rci_dim1] = rc[j];
- }
- ivuv[i__] = ivoice;
- ipiti[i__] = *pitch;
- rmsi[i__] = *rms;
- }
- *first = FALSE_;
- } else {
- vflag = 0;
- lsamp = *lframe + *jsamp;
- slope = (*pitch - *ipito) / (real) lsamp;
- *nout = 0;
- jused = 0;
- istart = 1;
- if (voice[1] == *ivoico && voice[2] == voice[1]) {
- if (voice[2] == 0) {
-/* SSUV - - 0 , 0 , 0 */
- *pitch = *lframe / 4;
- *ipito = *pitch;
- if (*ratio > 8.f) {
- *rmso = *rms;
- }
- }
-/* SSVC - - 1 , 1 , 1 */
- slope = (*pitch - *ipito) / (real) lsamp;
- ivoice = voice[2];
- } else {
- if (*ivoico != 1) {
- if (*ivoico == voice[1]) {
-/* UV2VC2 - - 0 , 0 , 1 */
- nl = lsamp - *lframe / 4;
- } else {
-/* UV2VC1 - - 0 , 1 , 1 */
- nl = lsamp - *lframe * 3 / 4;
- }
- ipiti[1] = nl / 2;
- ipiti[2] = nl - ipiti[1];
- ivuv[1] = 0;
- ivuv[2] = 0;
- rmsi[1] = *rmso;
- rmsi[2] = *rmso;
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- rci[i__ + rci_dim1] = rco[i__ - 1];
- rci[i__ + (rci_dim1 << 1)] = rco[i__ - 1];
- rco[i__ - 1] = rc[i__];
- }
- slope = 0.f;
- *nout = 2;
- *ipito = *pitch;
- jused = nl;
- istart = nl + 1;
- ivoice = 1;
- } else {
- if (*ivoico != voice[1]) {
-/* VC2UV1 - - 1 , 0 , 0 */
- lsamp = *lframe / 4 + *jsamp;
- } else {
-/* VC2UV2 - - 1 , 1 , 0 */
- lsamp = *lframe * 3 / 4 + *jsamp;
- }
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- yarc[i__ - 1] = rc[i__];
- rc[i__] = rco[i__ - 1];
- }
- ivoice = 1;
- slope = 0.f;
- vflag = 1;
- }
- }
-/* Here is the value of most variables that are used below, depending
-on */
-/* the values of IVOICO, VOICE(1), and VOICE(2). VOICE(1) and VOICE(2
-) */
-/* are input arguments, and IVOICO is the value of VOICE(2) on the */
-/* previous call (see notes for the IF (NOUT .NE. 0) statement near th
-e */
-/* end). Each of these three values is either 0 or 1. These three */
-/* values below are given as 3-bit long strings, in the order IVOICO,
-*/
-/* VOICE(1), and VOICE(2). It appears that the code above assumes tha
-t */
-/* the bit sequences 010 and 101 never occur, but I wonder whether a
-*/
-/* large enough number of bit errors in the channel could cause such a
- */
-/* thing to happen, and if so, could that cause NOUT to ever go over 1
-1? */
-
-/* Note that all of the 180 values in the table are really LFRAME, but
- */
-/* 180 has fewer characters, and it makes the table a little more */
-/* concrete. If LFRAME is ever changed, keep this in mind. Similarly
-, */
-/* 135's are 3*LFRAME/4, and 45's are LFRAME/4. If LFRAME is not a */
-/* multiple of 4, then the 135 for NL-JSAMP is actually LFRAME-LFRAME/
-4, */
-/* and the 45 for NL-JSAMP is actually LFRAME-3*LFRAME/4. */
-
-/* Note that LSAMP-JSAMP is given as the variable. This was just for
-*/
-/* brevity, to avoid adding "+JSAMP" to all of the column entries. */
-/* Similarly for NL-JSAMP. */
-
-/* Variable | 000 001 011,010 111 110 100,101 */
-/* ------------+-------------------------------------------------- */
-/* ISTART | 1 NL+1 NL+1 1 1 1 */
-/* LSAMP-JSAMP | 180 180 180 180 135 45 */
-/* IPITO | 45 PITCH PITCH oldPITCH oldPITCH oldPITCH */
-/* SLOPE | 0 0 0 seebelow 0 0 */
-/* JUSED | 0 NL NL 0 0 0 */
-/* PITCH | 45 PITCH PITCH PITCH PITCH PITCH */
-/* NL-JSAMP | -- 135 45 -- -- -- */
-/* VFLAG | 0 0 0 0 1 1 */
-/* NOUT | 0 2 2 0 0 0 */
-/* IVOICE | 0 1 1 1 1 1 */
-
-/* while_loop | once once once once twice twice */
-
-/* ISTART | -- -- -- -- JUSED+1 JUSED+1 */
-/* LSAMP-JSAMP | -- -- -- -- 180 180 */
-/* IPITO | -- -- -- -- oldPITCH oldPITCH */
-/* SLOPE | -- -- -- -- 0 0 */
-/* JUSED | -- -- -- -- ?? ?? */
-/* PITCH | -- -- -- -- PITCH PITCH */
-/* NL-JSAMP | -- -- -- -- -- -- */
-/* VFLAG | -- -- -- -- 0 0 */
-/* NOUT | -- -- -- -- ?? ?? */
-/* IVOICE | -- -- -- -- 0 0 */
-
-
-/* UVPIT is always 0.0 on the first pass through the DO WHILE (.TRUE.)
- */
-/* loop below. */
-
-/* The only possible non-0 value of SLOPE (in column 111) is */
-/* (PITCH-IPITO)/FLOAT(LSAMP) */
-
-/* Column 101 is identical to 100. Any good properties we can prove
-*/
-/* for 100 will also hold for 101. Similarly for 010 and 011. */
-
-/* SYNTHS calls this subroutine with PITCH restricted to the range 20
-to */
-/* 156. IPITO is similarly restricted to this range, after the first
-*/
-/* call. IP below is also restricted to this range, given the */
-/* definitions of IPITO, SLOPE, UVPIT, and that I is in the range ISTA
-RT */
-/* to LSAMP. */
-
- while(TRUE_) {
-
-/* JUSED is the total length of all pitch periods curr
-ently */
-/* in the output arrays, in samples. */
-
-/* An invariant of the DO I = ISTART,LSAMP loop below,
- under */
-/* the condition that IP is always in the range 1 thro
-ugh */
-/* MAXPIT, is: */
-
-/* (I - MAXPIT) .LE. JUSED .LE. (I-1) */
-
-/* Note that the final value of I is LSAMP+1, so that
-after */
-/* the DO loop is complete, we know: */
-
-/* (LSAMP - MAXPIT + 1) .LE. JUSED .LE. LSAMP */
-
- i__1 = lsamp;
- for (i__ = istart; i__ <= i__1; ++i__) {
- r__1 = *ipito + slope * i__;
- ip = r__1 + .5f;
- if (uvpit != 0.f) {
- ip = uvpit;
- }
- if (ip <= i__ - jused) {
- ++(*nout);
-
-/* The following check is no longer nece
-ssary, now that */
-/* we can prove that NOUT will never go
-over 16. */
-
-/* IF (NOUT .GT. 16) STOP 'PITSYN: too many epochs'
-*/
-
- ipiti[*nout] = ip;
- *pitch = ip;
- ivuv[*nout] = ivoice;
- jused += ip;
- prop = (jused - ip / 2) / (real) lsamp;
- i__2 = *order;
- for (j = 1; j <= i__2; ++j) {
- alro = log((rco[j - 1] + 1) / (1 - rco[j - 1]));
- alrn = log((rc[j] + 1) / (1 - rc[j]));
- xxy = alro + prop * (alrn - alro);
- xxy = exp(xxy);
- rci[j + *nout * rci_dim1] = (xxy - 1) / (xxy + 1);
- }
- rmsi[*nout] = log(*rmso) + prop * (log(*rms) - log(*rmso));
- rmsi[*nout] = exp(rmsi[*nout]);
- }
- }
- if (vflag != 1) {
- goto L100;
- }
-
-/* I want to prove what range UVPIT must lie in after
-the */
-/* assignments to it below. To do this, I must determ
-ine */
-/* what range (LSAMP-ISTART) must lie in, after the */
-/* assignments to ISTART and LSAMP below. */
-
-/* Let oldLSAMP be the value of LSAMP at this point in
- the */
-/* execution. This is 135+JSAMP in state 110, or 45+J
-SAMP in */
-/* states 100 or 101. */
-
-/* Given the loop invariant on JUSED above, we know th
-at: */
-
-/* (oldLSAMP - MAXPIT + 1) .LE. JUSED .LE. oldLSAMP */
-
-/* ISTART is one more than this. */
-
-/* Let newLSAMP be the value assigned to LSAMP below.
- This */
-/* is 180+JSAMP. Thus (newLSAMP-oldLSAMP) is either 4
-5 or */
-/* 135, depending on the state. */
-
-/* Thus, the range of newLSAMP-ISTART is: */
-
-/* (newLSAMP-(oldLSAMP+1)) .LE. newLSAMP-ISTART */
-/* .LE. (newLSAMP-(oldLSAMP - MAXPIT + 2)) */
-
-/* or: */
-
-/* 46 .LE. newLSAMP-ISTART .LE. 133+MAXPIT .EQ. 289 */
-
-/* Therefore, UVPIT is in the range 23 to 144 after th
-e first */
-/* assignment to UVPIT below, and after the conditiona
-l */
-/* assignment, it is in the range 23 to 90. */
-
-/* The important thing is that it is in the range 20 t
-o 156, */
-/* so that in the loop above, IP is always in this ran
-ge. */
-
- vflag = 0;
- istart = jused + 1;
- lsamp = *lframe + *jsamp;
- slope = 0.f;
- ivoice = 0;
- uvpit = (real) ((lsamp - istart) / 2);
- if (uvpit > 90.f) {
- uvpit /= 2;
- }
- *rmso = *rms;
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- rc[i__] = yarc[i__ - 1];
- rco[i__ - 1] = yarc[i__ - 1];
- }
- }
-L100:
- *jsamp = lsamp - jused;
- }
-/* Given that the maximum pitch period MAXPIT .LT. LFRAME (this is
-*/
-/* currently true on every call, since SYNTHS always sets */
-/* LFRAME=180), NOUT will always be .GE. 1 at this point. */
- if (*nout != 0) {
- *ivoico = voice[2];
- *ipito = *pitch;
- *rmso = *rms;
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- rco[i__ - 1] = rc[i__];
- }
- }
- return 0;
-} /* pitsyn_ */
diff --git a/1.2-netsec/codecs/lpc10/placea.c b/1.2-netsec/codecs/lpc10/placea.c
deleted file mode 100644
index 9464fb792..000000000
--- a/1.2-netsec/codecs/lpc10/placea.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
-
-$Log$
-Revision 1.16 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.15 2003/09/19 01:20:22 markster
-Code cleanups (bug #66)
-
-Revision 1.2 2003/09/19 01:20:22 markster
-Code cleanups (bug #66)
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.3 2001/04/12 21:27:53 markh
-app_record now supports wildcards of sort so your output file is not overwritten every time it's run. File.h got a documentation update on the ast_fileexists to include the return call. Watch out for the placea.c placev.c code, it's updates have not been tested yet. Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:31:07 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin);
-#endif
-
-/* *********************************************************************** */
-
-/* PLACEA Version 48 */
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.2 2003/09/19 01:20:22 markster
-/* Code cleanups (bug #66)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.3 2001/04/12 21:27:53 markh
-/* app_record now supports wildcards of sort so your output file is not overwritten every time it's run. File.h got a documentation update on the ast_fileexists to include the return call. Watch out for the placea.c placev.c code, it's updates have not been tested yet. Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:31:07 jaf
- * Initial revision
- * */
-/* Revision 1.5 1996/03/19 20:41:55 jaf */
-/* Added some conditions satisfied by the output values in EWIN. */
-
-/* Revision 1.4 1996/03/19 20:24:17 jaf */
-/* Added some conditions satisfied by the output values in AWIN. */
-
-/* Revision 1.3 1996/03/18 21:40:04 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 16:43:09 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:48:31 jaf */
-/* Initial revision */
-
-
-/* *********************************************************************** */
-/* Input: */
-/* IPITCH */
-/* VOIBUF */
-/* Indices (2,AF-2), (1,AF-1), (2,AF-1), (1,AF), and (2,AF) read.*/
-/* All other indices untouched. */
-/* OBOUND */
-/* AF */
-/* VWIN */
-/* Indices (1,AF) and (2,AF) read. */
-/* All other indices untouched. */
-/* LFRAME */
-/* MAXWIN */
-/* Input/Output: */
-/* AWIN */
-/* Index (1,AF-1) read. */
-/* Indices (1,AF) and (2,AF) written, and then read. */
-/* All other indices untouched. */
-/* In all cases (except possibly one), the final values will */
-/* satisfy the condition: AWIN(2,AF)-AWIN(1,AF)+1 = MAXWIN. */
-/* In that other case, */
-/* AWIN(1,AF)=VWIN(1,AF) and AWIN(2,AF)=VWIN(2,AF). */
-/* Output: */
-/* EWIN */
-/* Indices (1,AF) and (2,AF) written. */
-/* All other indices untouched. */
-/* In all cases, the final values will satisfy the condition: */
-/* AWIN(1,AF) .LE. EWIN(1,AF) .LE. EWIN(2,AF) .LE. AWIN(2,AF) */
-/* In other words, the energy window is a sub-window of */
-/* the analysis window. */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int placea_(integer *ipitch, integer *voibuf, integer *
- obound, integer *af, integer *vwin, integer *awin, integer *ewin,
- integer *lframe, integer *maxwin)
-{
- /* System generated locals */
- real r__1;
-
- /* Builtin functions */
- integer i_nint(real *);
-
- /* Local variables */
- logical allv, winv;
- integer i__, j, k, l, hrange;
- logical ephase;
- integer lrange;
-
-/* Arguments */
-/* Local variables that need not be saved */
- /* Parameter adjustments */
- ewin -= 3;
- awin -= 3;
- vwin -= 3;
- --voibuf;
-
- /* Function Body */
- lrange = (*af - 2) * *lframe + 1;
- hrange = *af * *lframe;
-/* Place the Analysis window based on the voicing window */
-/* placement, onsets, tentative voicing decision, and pitch. */
-
-/* Case 1: Sustained Voiced Speech */
-/* If the five most recent voicing decisions are */
-/* voiced, then the window is placed phase-synchronously with the */
-/* previous window, as close to the present voicing window if possible.
-*/
-/* If onsets bound the voicing window, then preference is given to */
-/* a phase-synchronous placement which does not overlap these onsets. */
-
-/* Case 2: Voiced Transition */
-/* If at least one voicing decision in AF is voicied, and there are no
-*/
-/* onsets, then the window is placed as in case 1. */
-
-/* Case 3: Unvoiced Speech or Onsets */
-/* If both voicing decisions in AF are unvoiced, or there are onsets, */
-/* then the window is placed coincident with the voicing window. */
-
-/* Note: During phase-synchronous placement of windows, the length */
-/* is not altered from MAXWIN, since this would defeat the purpose */
-/* of phase-synchronous placement. */
-/* Check for case 1 and case 2 */
- allv = voibuf[((*af - 2) << 1) + 2] == 1;
- allv = allv && voibuf[((*af - 1) << 1) + 1] == 1;
- allv = allv && voibuf[((*af - 1) << 1) + 2] == 1;
- allv = allv && voibuf[(*af << 1) + 1] == 1;
- allv = allv && voibuf[(*af << 1) + 2] == 1;
- winv = voibuf[(*af << 1) + 1] == 1 || voibuf[(*af << 1) + 2] == 1;
- if (allv || (winv && *obound == 0)) {
-/* APHASE: Phase synchronous window placement. */
-/* Get minimum lower index of the window. */
- i__ = (lrange + *ipitch - 1 - awin[((*af - 1) << 1) + 1]) / *ipitch;
- i__ *= *ipitch;
- i__ += awin[((*af - 1) << 1) + 1];
-/* L = the actual length of this frame's analysis window. */
- l = *maxwin;
-/* Calculate the location where a perfectly centered window would star
-t. */
- k = (vwin[(*af << 1) + 1] + vwin[(*af << 1) + 2] + 1 - l) / 2;
-/* Choose the actual location to be the pitch multiple closest to this
-. */
- r__1 = (real) (k - i__) / *ipitch;
- awin[(*af << 1) + 1] = i__ + i_nint(&r__1) * *ipitch;
- awin[(*af << 1) + 2] = awin[(*af << 1) + 1] + l - 1;
-/* If there is an onset bounding the right of the voicing window and t
-he */
-/* analysis window overlaps that, then move the analysis window backwa
-rd */
-/* to avoid this onset. */
- if (*obound >= 2 && awin[(*af << 1) + 2] > vwin[(*af << 1) + 2]) {
- awin[(*af << 1) + 1] -= *ipitch;
- awin[(*af << 1) + 2] -= *ipitch;
- }
-/* Similarly for the left of the voicing window. */
- if ((*obound == 1 || *obound == 3) && awin[(*af << 1) + 1] < vwin[(*
- af << 1) + 1]) {
- awin[(*af << 1) + 1] += *ipitch;
- awin[(*af << 1) + 2] += *ipitch;
- }
-/* If this placement puts the analysis window above HRANGE, then */
-/* move it backward an integer number of pitch periods. */
- while(awin[(*af << 1) + 2] > hrange) {
- awin[(*af << 1) + 1] -= *ipitch;
- awin[(*af << 1) + 2] -= *ipitch;
- }
-/* Similarly if the placement puts the analysis window below LRANGE.
-*/
- while(awin[(*af << 1) + 1] < lrange) {
- awin[(*af << 1) + 1] += *ipitch;
- awin[(*af << 1) + 2] += *ipitch;
- }
-/* Make Energy window be phase-synchronous. */
- ephase = TRUE_;
-/* Case 3 */
- } else {
- awin[(*af << 1) + 1] = vwin[(*af << 1) + 1];
- awin[(*af << 1) + 2] = vwin[(*af << 1) + 2];
- ephase = FALSE_;
- }
-/* RMS is computed over an integer number of pitch periods in the analysis
- */
-/*window. When it is not placed phase-synchronously, it is placed as clos
-e*/
-/* as possible to onsets. */
- j = (awin[(*af << 1) + 2] - awin[(*af << 1) + 1] + 1) / *ipitch * *ipitch;
- if (j == 0 || ! winv) {
- ewin[(*af << 1) + 1] = vwin[(*af << 1) + 1];
- ewin[(*af << 1) + 2] = vwin[(*af << 1) + 2];
- } else if (! ephase && *obound == 2) {
- ewin[(*af << 1) + 1] = awin[(*af << 1) + 2] - j + 1;
- ewin[(*af << 1) + 2] = awin[(*af << 1) + 2];
- } else {
- ewin[(*af << 1) + 1] = awin[(*af << 1) + 1];
- ewin[(*af << 1) + 2] = awin[(*af << 1) + 1] + j - 1;
- }
- return 0;
-} /* placea_ */
-
diff --git a/1.2-netsec/codecs/lpc10/placev.c b/1.2-netsec/codecs/lpc10/placev.c
deleted file mode 100644
index a11319cb1..000000000
--- a/1.2-netsec/codecs/lpc10/placev.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.3 2001/04/12 21:27:53 markh
-app_record now supports wildcards of sort so your output file is not overwritten every time it's run. File.h got a documentation update on the ast_fileexists to include the return call. Watch out for the placea.c placev.c code, it's updates have not been tested yet. Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:31:02 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int placev_(integer *osbuf, integer *osptr, integer *oslen, integer *obound, integer *vwin, integer *af, integer *lframe, integer *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh);
-#endif
-
-/* ****************************************************************** */
-
-/* PLACEV Version 48 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.3 2001/04/12 21:27:53 markh
-/* app_record now supports wildcards of sort so your output file is not overwritten every time it's run. File.h got a documentation update on the ast_fileexists to include the return call. Watch out for the placea.c placev.c code, it's updates have not been tested yet. Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:31:02 jaf
- * Initial revision
- * */
-/* Revision 1.6 1996/03/19 20:42:19 jaf */
-/* Added some conditions satisfied by the output values in VWIN. */
-
-/* Revision 1.5 1996/03/19 18:37:56 jaf */
-/* Strengthened the specification of which indices of VWIN are read and */
-/* written. */
-
-/* Revision 1.4 1996/03/15 16:38:33 jaf */
-/* One tiny comment added. */
-
-/* Revision 1.3 1996/03/15 16:36:13 jaf */
-/* Added comments giving In/Out status of arguments. */
-
-/* Revision 1.2 1996/03/12 23:56:01 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:48:39 jaf */
-/* Initial revision */
-
-
-/* ****************************************************************** */
-
-/* Input: */
-/* OSBUF Buffer which holds sorted indexes of onsets */
-/* I believe that only indices 1 through OSPTR-1 can be read. */
-/* OSLEN */
-/* OSPTR Free pointer into OSBUF */
-/* AF */
-/* LFRAME */
-/* MINWIN */
-/* MAXWIN */
-/* DVWINL */
-/* DVWINH (This argument is never used. Should it be?) */
-/* Input/Output: */
-/* VWIN Buffer of Voicing Window Positions (Modified) */
-/* Index (2,AF-1) is read. */
-/* Indices (1,AF) and (2,AF) are written, */
-/* and then possibly read. */
-/* All other indices are unused. */
-/* In all cases, the final values will satsify the condition:*/
-/* VWIN(2,AF)-VWIN(1,AF)+1 .LE. MAXWIN */
-/* I'm not certain yet, but they may also satisfy: */
-/* MINWIN .LE. VWIN(2,AF)-VWIN(1,AF)+1 */
-/* Output: */
-/* OBOUND This variable is set by this procedure and used */
-/* in placing analysis windows (PLACEA). Bit 1 */
-/* indicates whether an onset bounds the left side */
-/* of the voicing window, and bit 2 indicates whether */
-/* an onset bounds the right side of the voicing window. */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int placev_(integer *osbuf, integer *osptr, integer *oslen,
- integer *obound, integer *vwin, integer *af, integer *lframe, integer
- *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh)
-{
- /* System generated locals */
- integer i__1, i__2;
-
- /* Local variables */
- logical crit;
- integer i__, q, osptr1, hrange, lrange;
-
-/* Arguments */
-/* Local variables that need not be saved */
-/* Variables */
-/* LRANGE, HRANGE Range in which window is placed */
-/* OSPTR1 OSPTR excluding samples in 3F */
-/* Local state */
-/* None */
-/* Voicing Window Placement */
-
-/* __________________ __________________ ______________ */
-/* | | | */
-/* | 1F | 2F | 3F ... */
-/* |__________________|__________________|______________ */
-
-/* Previous | */
-/* Window | */
-/* ...________| */
-
-/* | | */
-/* ------>| This window's placement range |<------ */
-/* | | */
-
-/* There are three cases. Note that these are different from those */
-/* given in the LPC-10e phase 1 report. */
-
-/* 1. If there are no onsets in this range, then the voicing window */
-/* is centered in the pitch window. If such a placement is not within
-*/
-/* the window's placement range, then the window is placed in the left-
-*/
-/* most portion of the placement range. Its length is always MAXWIN. */
-
-/* 2. If the first onset is in 2F and there is sufficient room to place
- */
-/* the window immediately before this onset, then the window is placed
-*/
-/* there, and its length is set to the maximum possible under these */
-/* constraints. */
-
-/* "Critical Region Exception": If there is another onset in 2F */
-/* such that a window can be placed between the two onsets, the */
-/* window is placed there (ie, as in case 3). */
-
-/* 3. Otherwise, the window is placed immediately after the onset. The
- */
-/* window's length */
-/* is the longest length that can fit in the range under these constraint
-s,*/
-/* except that the window may be shortened even further to avoid overlapp
-ing*/
-/* other onsets in the placement range. In any case, the window's length
-*/
-/* is at least MINWIN. */
-
-/* Note that the values of MINWIN and LFRAME must be chosen such */
-/* that case 2 = false implies case 3 = true. This means that */
-/* MINWIN <= LFRAME/2. If this were not the case, then a fourth case */
-/* would have to be added for when the window cannot fit either before
-*/
-/* or after the onset. */
-
-/* Note also that onsets which weren't in 2F last time may be in 1F this
- */
-/* time, due to the filter delays in computing onsets. The result is tha
-t*/
-/* occasionally a voicing window will overlap that onset. The only way
-*/
-/* to circumvent this problem is to add more delay in processing input
-*/
-/* speech. In the trade-off between delay and window-placement, window
-*/
-/* placement lost. */
-/* Compute the placement range */
- /* Parameter adjustments */
- --osbuf;
- vwin -= 3;
-
- /* Function Body */
-/* Computing MAX */
- i__1 = vwin[((*af - 1) << 1) + 2] + 1, i__2 = (*af - 2) * *lframe + 1;
- lrange = max(i__1,i__2);
- hrange = *af * *lframe;
-/* Compute OSPTR1, so the following code only looks at relevant onsets. */
- for (osptr1 = *osptr - 1; osptr1 >= 1; --osptr1) {
- if (osbuf[osptr1] <= hrange) {
- goto L90;
- }
- }
-L90:
- ++osptr1;
-/* Check for case 1 first (fast case): */
- if (osptr1 <= 1 || osbuf[osptr1 - 1] < lrange) {
-/* Computing MAX */
- i__1 = vwin[((*af - 1) << 1) + 2] + 1;
- vwin[(*af << 1) + 1] = max(i__1,*dvwinl);
- vwin[(*af << 1) + 2] = vwin[(*af << 1) + 1] + *maxwin - 1;
- *obound = 0;
- } else {
-/* Search backward in OSBUF for first onset in range. */
-/* This code relies on the above check being performed first. */
- for (q = osptr1 - 1; q >= 1; --q) {
- if (osbuf[q] < lrange) {
- goto L100;
- }
- }
-L100:
- ++q;
-/* Check for case 2 (placement before onset): */
-/* Check for critical region exception: */
- i__1 = osptr1 - 1;
- for (i__ = q + 1; i__ <= i__1; ++i__) {
- if (osbuf[i__] - osbuf[q] >= *minwin) {
- crit = TRUE_;
- goto L105;
- }
- }
- crit = FALSE_;
-L105:
-/* Computing MAX */
- i__1 = (*af - 1) * *lframe, i__2 = lrange + *minwin - 1;
- if (! crit && osbuf[q] > max(i__1,i__2)) {
- vwin[(*af << 1) + 2] = osbuf[q] - 1;
-/* Computing MAX */
- i__1 = lrange, i__2 = vwin[(*af << 1) + 2] - *maxwin + 1;
- vwin[(*af << 1) + 1] = max(i__1,i__2);
- *obound = 2;
-/* Case 3 (placement after onset) */
- } else {
- vwin[(*af << 1) + 1] = osbuf[q];
-L110:
- ++q;
- if (q >= osptr1) {
- goto L120;
- }
- if (osbuf[q] > vwin[(*af << 1) + 1] + *maxwin) {
- goto L120;
- }
- if (osbuf[q] < vwin[(*af << 1) + 1] + *minwin) {
- goto L110;
- }
- vwin[(*af << 1) + 2] = osbuf[q] - 1;
- *obound = 3;
- return 0;
-L120:
-/* Computing MIN */
- i__1 = vwin[(*af << 1) + 1] + *maxwin - 1;
- vwin[(*af << 1) + 2] = min(i__1,hrange);
- *obound = 1;
- }
- }
- return 0;
-} /* placev_ */
-
diff --git a/1.2-netsec/codecs/lpc10/preemp.c b/1.2-netsec/codecs/lpc10/preemp.c
deleted file mode 100644
index cc27f7baa..000000000
--- a/1.2-netsec/codecs/lpc10/preemp.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:30:58 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int preemp_(real *inbuf, real *pebuf, integer *nsamp, real *coef, real *z__);
-#endif
-
-/* ******************************************************************* */
-
-/* PREEMP Version 55 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:30:58 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/14 23:16:29 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/11 23:23:34 jaf */
-/* Added a bunch of comments to an otherwise simple subroutine. */
-
-/* Revision 1.1 1996/02/07 14:48:48 jaf */
-/* Initial revision */
-
-
-/* ******************************************************************* */
-
-/* Preemphasize speech with a single-zero filter. */
-/* (When coef = .9375, preemphasis is as in LPC43.) */
-
-/* Inputs: */
-/* NSAMP - Number of samples to filter */
-/* INBUF - Input speech buffer */
-/* Indices 1 through NSAMP are read. */
-/* COEF - Preemphasis coefficient */
-/* Input/Output: */
-/* Z - Filter state */
-/* Output: */
-/* PEBUF - Preemphasized speech buffer (can be equal to INBUF) */
-/* Indices 1 through NSAMP are modified. */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int preemp_(real *inbuf, real *pebuf, integer *nsamp, real *
- coef, real *z__)
-{
- /* System generated locals */
- integer i__1;
-
- /* Local variables */
- real temp;
- integer i__;
-
-/* Arguments */
-/* Local variables */
-
-/* None of these need to have their values saved from one */
-/* invocation to the next. */
-
-/* Logically, this subroutine computes the output sequence */
-/* pebuf(1:nsamp) defined by: */
-
-/* pebuf(i) = inbuf(i) - coef * inbuf(i-1) */
-
-/* where inbuf(0) is defined by the value of z given as input to */
-/* this subroutine. */
-
-/* What is this filter's frequency response and phase response? */
-
-/* Why is this filter applied to the speech? */
-
-/* Could it be more efficient to apply multiple filters */
-/* simultaneously, by combining them into one equivalent filter? */
-
-/* Are there ever cases when "factoring" one high-order filter into
-*/
-/* multiple smaller-order filter actually reduces the number of */
-/* arithmetic operations needed to perform them? */
-/* When I first read this subroutine, I didn't understand why the */
-/* variable temp was used. It seemed that the statements in the do
-*/
-/* loop could be replaced with the following: */
-
-/* pebuf(i) = inbuf(i) - coef * z */
-/* z = inbuf(i) */
-
-/* The reason for temp is so that even if pebuf and inbuf are the */
-/* same arrays in memory (i.e., they are aliased), then this */
-/* subroutine will still work correctly. I didn't realize this */
-/* until seeing the comment after PEBUF above that says "(can be */
-/* equal to INBUF)". */
- /* Parameter adjustments */
- --pebuf;
- --inbuf;
-
- /* Function Body */
- i__1 = *nsamp;
- for (i__ = 1; i__ <= i__1; ++i__) {
- temp = inbuf[i__] - *coef * *z__;
- *z__ = inbuf[i__];
- pebuf[i__] = temp;
-/* L10: */
- }
- return 0;
-} /* preemp_ */
-
diff --git a/1.2-netsec/codecs/lpc10/prepro.c b/1.2-netsec/codecs/lpc10/prepro.c
deleted file mode 100644
index 8f3d5380e..000000000
--- a/1.2-netsec/codecs/lpc10/prepro.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:40:51 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:54 jaf
- * Initial revision
- *
- */
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int prepro_(real *speech, integer *length,
- struct lpc10_encoder_state *st);
-/*:ref: hp100_ 14 3 6 4 4 */
-/*:ref: inithp100_ 14 0 */
-#endif
-
-/* Table of constant values */
-
-static integer c__1 = 1;
-
-/* ********************************************************************* */
-
-/* PREPRO Version 48 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:40:51 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:54 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/14 23:22:56 jaf */
-/* Added comments about when INITPREPRO should be used. */
-
-/* Revision 1.2 1996/03/14 23:09:27 jaf */
-/* Added an entry named INITPREPRO that initializes the local state of */
-/* this subroutine, and those it calls (if any). */
-
-/* Revision 1.1 1996/02/07 14:48:54 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* Pre-process input speech: */
-
-/* Inputs: */
-/* LENGTH - Number of SPEECH samples */
-/* Input/Output: */
-/* SPEECH(LENGTH) - Speech data. */
-/* Indices 1 through LENGTH are read and modified. */
-
-/* This subroutine has no local state maintained from one call to the */
-/* next, but HP100 does. If you want to switch to using a new audio */
-/* stream for this filter, or reinitialize its state for any other */
-/* reason, call the ENTRY INITPREPRO. */
-
-/* Subroutine */ int prepro_(real *speech, integer *length,
- struct lpc10_encoder_state *st)
-{
- extern /* Subroutine */ int hp100_(real *, integer *, integer *, struct lpc10_encoder_state *);
-
-/* Arguments */
-/* High Pass Filter at 100 Hz */
- /* Parameter adjustments */
- if (speech) {
- --speech;
- }
-
- /* Function Body */
- hp100_(&speech[1], &c__1, length, st);
- return 0;
-} /* prepro_ */
diff --git a/1.2-netsec/codecs/lpc10/random.c b/1.2-netsec/codecs/lpc10/random.c
deleted file mode 100644
index ef5876f15..000000000
--- a/1.2-netsec/codecs/lpc10/random.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:41:32 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:49 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern integer random_(struct lpc10_decoder_state *st);
-#endif
-
-/* ********************************************************************** */
-
-/* RANDOM Version 49 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:41:32 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:49 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/20 16:13:54 jaf */
-/* Rearranged comments a little bit, and added comments explaining that */
-/* even though there is local state here, there is no need to create an */
-/* ENTRY for reinitializing it. */
-
-/* Revision 1.2 1996/03/14 22:25:29 jaf */
-/* Just rearranged the comments and local variable declarations a bit. */
-
-/* Revision 1.1 1996/02/07 14:49:01 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* Pseudo random number generator based on Knuth, Vol 2, p. 27. */
-
-/* Function Return: */
-/* RANDOM - Integer variable, uniformly distributed over -32768 to 32767 */
-
-/* This subroutine maintains local state from one call to the next. */
-/* In the context of the LPC10 coder, there is no reason to reinitialize */
-/* this local state when switching between audio streams, because its */
-/* results are only used to generate noise for unvoiced frames. */
-
-integer random_(struct lpc10_decoder_state *st)
-{
- /* Initialized data */
-
- integer *j;
- integer *k;
- shortint *y;
-
- /* System generated locals */
- integer ret_val;
-
-/* Parameters/constants */
-/* Local state */
-/* The following is a 16 bit 2's complement addition, */
-/* with overflow checking disabled */
-
- j = &(st->j);
- k = &(st->k);
- y = &(st->y[0]);
-
- y[*k - 1] += y[*j - 1];
- ret_val = y[*k - 1];
- --(*k);
- if (*k <= 0) {
- *k = 5;
- }
- --(*j);
- if (*j <= 0) {
- *j = 5;
- }
- return ret_val;
-} /* random_ */
-
diff --git a/1.2-netsec/codecs/lpc10/rcchk.c b/1.2-netsec/codecs/lpc10/rcchk.c
deleted file mode 100644
index 16fe9b930..000000000
--- a/1.2-netsec/codecs/lpc10/rcchk.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:30:41 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int rcchk_(integer *order, real *rc1f, real *rc2f);
-#endif
-
-/* ********************************************************************* */
-
-/* RCCHK Version 45G */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:30:41 jaf
- * Initial revision
- * */
-/* Revision 1.4 1996/03/27 18:13:47 jaf */
-/* Commented out a call to subroutine ERROR. */
-
-/* Revision 1.3 1996/03/18 15:48:53 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 16:55:22 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:49:08 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* Check RC's, repeat previous frame's RC's if unstable */
-
-/* Input: */
-/* ORDER - Number of RC's */
-/* RC1F - Previous frame's RC's */
-/* Indices 1 through ORDER may be read. */
-/* Input/Output: */
-/* RC2F - Present frame's RC's */
-/* Indices 1 through ORDER may be read, and written. */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int rcchk_(integer *order, real *rc1f, real *rc2f)
-{
- /* System generated locals */
- integer i__1;
- real r__1;
-
- /* Local variables */
- integer i__;
-
-/* Arguments */
-/* Local variables that need not be saved */
- /* Parameter adjustments */
- --rc2f;
- --rc1f;
-
- /* Function Body */
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- if ((r__1 = rc2f[i__], abs(r__1)) > .99f) {
- goto L10;
- }
- }
- return 0;
-/* Note: In version embedded in other software, all calls to ERROR
-*/
-/* should probably be removed. */
-L10:
-
-/* This call to ERROR is only needed for debugging purposes. */
-
-/* CALL ERROR('RCCHK',2,I) */
- i__1 = *order;
- for (i__ = 1; i__ <= i__1; ++i__) {
- rc2f[i__] = rc1f[i__];
- }
- return 0;
-} /* rcchk_ */
-
diff --git a/1.2-netsec/codecs/lpc10/synths.c b/1.2-netsec/codecs/lpc10/synths.c
deleted file mode 100644
index 736d54b65..000000000
--- a/1.2-netsec/codecs/lpc10/synths.c
+++ /dev/null
@@ -1,425 +0,0 @@
-/*
-
-$Log$
-Revision 1.16 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.15 2003/09/27 02:45:37 markster
-Fix various compiler warnings (bug #322)
-
-Revision 1.2 2003/09/27 02:45:37 markster
-Fix various compiler warnings (bug #322)
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:39 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:42:59 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:33 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st);
-/* comlen contrl_ 12 */
-/*:ref: pitsyn_ 14 12 4 4 4 6 6 4 4 4 6 6 4 6 */
-/*:ref: irc2pc_ 14 5 6 6 4 6 6 */
-/*:ref: bsynz_ 14 7 6 4 4 6 6 6 6 */
-/*:ref: deemp_ 14 2 6 4 */
-/*:ref: initpitsyn_ 14 0 */
-/*:ref: initbsynz_ 14 0 */
-/*:ref: initdeemp_ 14 0 */
-#endif
-
-/* Common Block Declarations */
-
-extern struct {
- integer order, lframe;
- logical corrp;
-} contrl_;
-
-#define contrl_1 contrl_
-
-/* Table of constant values */
-
-static real c_b2 = .7f;
-
-/* ***************************************************************** */
-
-/* SYNTHS Version 54 */
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/27 02:45:37 markster
-/* Fix various compiler warnings (bug #322)
-/*
-/* Revision 1.2 2003/09/27 02:45:37 markster
-/* Fix various compiler warnings (bug #322)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:42:59 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:33 jaf
- * Initial revision
- * */
-/* Revision 1.5 1996/03/26 19:31:58 jaf */
-/* Commented out trace statements. */
-
-/* Revision 1.4 1996/03/25 19:41:01 jaf */
-/* Changed so that MAXFRM samples are always returned in the output array */
-/* SPEECH. */
-
-/* This required delaying the returned samples by MAXFRM sample times, */
-/* and remembering any "left over" samples returned by PITSYN from one */
-/* call of SYNTHS to the next. */
-
-/* Changed size of SPEECH from 2*MAXFRM to MAXFRM. Removed local */
-/* variable SOUT. Added local state variables BUF and BUFLEN. */
-
-/* Revision 1.3 1996/03/25 19:20:10 jaf */
-/* Added comments about the range of possible return values for argument */
-/* K, and increased the size of the arrays filled in by PITSYN from 11 to */
-/* 16, as has been already done inside of PITSYN. */
-
-/* Revision 1.2 1996/03/22 00:18:18 jaf */
-/* Added comments explaining meanings of input and output parameters, and */
-/* indicating which array indices can be read or written. */
-
-/* Added entry INITSYNTHS, which does nothing except call the */
-/* corresponding initialization entries for subroutines PITSYN, BSYNZ, */
-/* and DEEMP. */
-
-/* Revision 1.1 1996/02/07 14:49:44 jaf */
-/* Initial revision */
-
-
-/* ***************************************************************** */
-
-/* The note below is from the distributed version of the LPC10 coder. */
-/* The version of the code below has been modified so that SYNTHS always */
-/* has a constant frame length output of MAXFRM. */
-
-/* Also, BSYNZ and DEEMP need not be modified to work on variable */
-/* positions within an array. It is only necessary to pass the first */
-/* index desired as the array argument. What actually gets passed is the */
-/* address of that array position, which the subroutine treats as the */
-/* first index of the array. */
-
-/* This technique is used in subroutine ANALYS when calling PREEMP, so it */
-/* appears that multiple people wrote different parts of this LPC10 code, */
-/* and that they didn't necessarily have equivalent knowledge of Fortran */
-/* (not surprising). */
-
-/* NOTE: There is excessive buffering here, BSYNZ and DEEMP should be */
-/* changed to operate on variable positions within SOUT. Also, */
-/* the output length parameter is bogus, and PITSYN should be */
-/* rewritten to allow a constant frame length output. */
-
-/* Input: */
-/* VOICE - Half frame voicing decisions */
-/* Indices 1 through 2 read. */
-/* Input/Output: */
-/* PITCH - Pitch */
-/* PITCH is restricted to range 20 to 156, inclusive, */
-/* before calling subroutine PITSYN, and then PITSYN */
-/* can modify it further under some conditions. */
-/* RMS - Energy */
-/* Only use is for debugging, and passed to PITSYN. */
-/* See comments there for how it can be modified. */
-/* RC - Reflection coefficients */
-/* Indices 1 through ORDER restricted to range -.99 to .99, */
-/* before calling subroutine PITSYN, and then PITSYN */
-/* can modify it further under some conditions. */
-/* Output: */
-/* SPEECH - Synthesized speech samples. */
-/* Indices 1 through the final value of K are written. */
-/* K - Number of samples placed into array SPEECH. */
-/* This is always MAXFRM. */
-
-/* Subroutine */ int synths_(integer *voice, integer *pitch, real *
- rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st)
-{
- /* Initialized data */
-
- real *buf;
- integer *buflen;
-
- /* System generated locals */
- integer i__1;
- real r__1, r__2;
-
- /* Local variables */
- real rmsi[16];
- integer nout, ivuv[16], i__, j;
- extern /* Subroutine */ int deemp_(real *, integer *, struct lpc10_decoder_state *);
- real ratio;
- integer ipiti[16];
- real g2pass;
- real pc[10];
- extern /* Subroutine */ int pitsyn_(integer *, integer *, integer *, real
- *, real *, integer *, integer *, integer *, real *, real *,
- integer *, real *, struct lpc10_decoder_state *);
- real rci[160] /* was [10][16] */;
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/27 02:45:37 markster
-/* Fix various compiler warnings (bug #322)
-/*
-/* Revision 1.2 2003/09/27 02:45:37 markster
-/* Fix various compiler warnings (bug #322)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:42:59 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:33 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:03:47 jaf */
-/* Removed definitions for any constants that were no longer used. */
-
-/* Revision 1.2 1996/03/26 19:34:33 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:43:51 jaf */
-/* Initial revision */
-
-/* LPC Configuration parameters: */
-/* Frame size, Prediction order, Pitch period */
-/* Arguments */
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/09/27 02:45:37 markster
-/* Fix various compiler warnings (bug #322)
-/*
-/* Revision 1.2 2003/09/27 02:45:37 markster
-/* Fix various compiler warnings (bug #322)
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:39 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:42:59 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_decoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_decoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:33 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:05:55 jaf */
-/* Commented out the common block variables that are not needed by the */
-/* embedded version. */
-
-/* Revision 1.2 1996/03/26 19:34:50 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:44:09 jaf */
-/* Initial revision */
-
-/* LPC Processing control variables: */
-
-/* *** Read-only: initialized in setup */
-
-/* Files for Speech, Parameter, and Bitstream Input & Output, */
-/* and message and debug outputs. */
-
-/* Here are the only files which use these variables: */
-
-/* lpcsim.f setup.f trans.f error.f vqsetup.f */
-
-/* Many files which use fdebug are not listed, since it is only used in */
-/* those other files conditionally, to print trace statements. */
-/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* LPC order, Frame size, Quantization rate, Bits per frame, */
-/* Error correction */
-/* Subroutine SETUP is the only place where order is assigned a value, */
-/* and that value is 10. It could increase efficiency 1% or so to */
-/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
-*/
-/* a variable in a COMMON block, since it is used in many places in the */
-/* core of the coding and decoding routines. Actually, I take that back.
-*/
-/* At least when compiling with f2c, the upper bound of DO loops is */
-/* stored in a local variable before the DO loop begins, and then that is
-*/
-/* compared against on each iteration. */
-/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
-/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
-/* is used in only a few places, and never in the core coding and */
-/* decoding routines, so it could be eliminated entirely. */
-/* nbits is similar to quant, and is given a value of 54 in SETUP. */
-/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
-/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
-/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
-*/
-/* a constant or a variable, since it is only examined once per frame. */
-/* Leaving it as a variable that is set to .TRUE. seems like a good */
-/* idea, since it does enable some error-correction capability for */
-/* unvoiced frames, with no change in the coding rate, and no noticeable
-*/
-/* quality difference in the decoded speech. */
-/* integer quant, nbits */
-/* *** Read/write: variables for debugging, not needed for LPC algorithm
-*/
-
-/* Current frame, Unstable frames, Output clip count, Max onset buffer,
-*/
-/* Debug listing detail level, Line count on listing page */
-
-/* nframe is not needed for an embedded LPC10 at all. */
-/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
-/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
-/* an application, I would recommend removing the call to ERROR in RCCHK,
-*/
-/* and remove ERROR and nunsfm completely. */
-/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
-*/
-/* sread.f. When LPC10 is embedded into an application, one might want */
-/* to cause it to be incremented in a routine that takes the output of */
-/* SYNTHS and sends it to an audio device. It could be optionally */
-/* displayed, for those that might want to know what it is. */
-/* maxosp is never initialized to 0 in SETUP, although it probably should
-*/
-/* be, and it is updated in subroutine ANALYS. I doubt that its value */
-/* would be of much interest to an application in which LPC10 is */
-/* embedded. */
-/* listl and lincnt are not needed for an embedded LPC10 at all. */
-/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* common /contrl/ quant, nbits */
-/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* Parameters/constants */
-/* Local variables that need not be saved */
-/* Local state */
-/* BUF is a buffer of speech samples that would have been returned
-*/
-/* by the older version of SYNTHS, but the newer version doesn't, */
-/* so that the newer version can always return MAXFRM samples on */
-/* every call. This has the effect of delaying the return of */
-/* samples for one additional frame time. */
-
-/* Indices 1 through BUFLEN contain samples that are left over from
-*/
-/* the last call to SYNTHS. Given the way that PITSYN works, */
-/* BUFLEN should always be in the range MAXFRM-MAXPIT+1 through */
-/* MAXFRM, inclusive, after a call to SYNTHS is complete. */
-
-/* On the first call to SYNTHS (or the first call after */
-/* reinitializing with the entry INITSYNTHS), BUFLEN is MAXFRM, and
-*/
-/* a frame of silence is always returned. */
- /* Parameter adjustments */
- if (voice) {
- --voice;
- }
- if (rc) {
- --rc;
- }
- if (speech) {
- --speech;
- }
-
- /* Function Body */
- buf = &(st->buf[0]);
- buflen = &(st->buflen);
-
-/* Computing MAX */
- i__1 = min(*pitch,156);
- *pitch = max(i__1,20);
- i__1 = contrl_1.order;
- for (i__ = 1; i__ <= i__1; ++i__) {
-/* Computing MAX */
-/* Computing MIN */
- r__2 = rc[i__];
- r__1 = min(r__2,.99f);
- rc[i__] = max(r__1,-.99f);
- }
- pitsyn_(&contrl_1.order, &voice[1], pitch, rms, &rc[1], &contrl_1.lframe,
- ivuv, ipiti, rmsi, rci, &nout, &ratio, st);
- if (nout > 0) {
- i__1 = nout;
- for (j = 1; j <= i__1; ++j) {
-
-/* Add synthesized speech for pitch period J to the en
-d of */
-/* BUF. */
-
- irc2pc_(&rci[j * 10 - 10], pc, &contrl_1.order, &c_b2, &g2pass);
- bsynz_(pc, &ipiti[j - 1], &ivuv[j - 1], &buf[*buflen], &rmsi[j - 1]
- , &ratio, &g2pass, st);
- deemp_(&buf[*buflen], &ipiti[j - 1], st);
- *buflen += ipiti[j - 1];
- }
-
-/* Copy first MAXFRM samples from BUF to output array SPEECH
-*/
-/* (scaling them), and then remove them from the beginning of
- */
-/* BUF. */
-
- for (i__ = 1; i__ <= 180; ++i__) {
- speech[i__] = buf[i__ - 1] / 4096.f;
- }
- *k = 180;
- *buflen += -180;
- i__1 = *buflen;
- for (i__ = 1; i__ <= i__1; ++i__) {
- buf[i__ - 1] = buf[i__ + 179];
- }
- }
- return 0;
-} /* synths_ */
diff --git a/1.2-netsec/codecs/lpc10/tbdm.c b/1.2-netsec/codecs/lpc10/tbdm.c
deleted file mode 100644
index 2ed6e34cf..000000000
--- a/1.2-netsec/codecs/lpc10/tbdm.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:40 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:30:26 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int tbdm_(real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau);
-/*:ref: difmag_ 14 8 6 4 4 4 4 6 4 4 */
-#endif
-
-/* ********************************************************************** */
-
-/* TBDM Version 49 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:40 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:30:26 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/18 22:14:00 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 14:48:37 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:49:54 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/*TURBO DIFMAG: Compute High Resolution Average Magnitude Difference Function
-*/
-
-/* Note: There are several constants in here that appear to depend on a */
-/* particular TAU table. That's not a problem for the LPC10 coder, but */
-/* watch out if you change the contents of TAU in the subroutine ANALYS. */
-
-/* Input: */
-/* SPEECH - Low pass filtered speech */
-/* Indices 1 through MAX+LPITA-1 are read, where: */
-/* MAX = (TAU(LTAU)-TAU(1))/2+1 */
-/* (If TAU(1) .LT. 39, then larger indices could be read */
-/* by the last call to DIFMAG below.) */
-/* LPITA - Length of speech buffer */
-/* TAU - Table of lags, sorted in increasing order. */
-/* Indices 1 through LTAU read. */
-/* LTAU - Number of lag values to compute */
-/* Output: */
-/* AMDF - Average Magnitude Difference for each lag in TAU */
-/* Indices 1 through LTAU written, and several might then be read.*/
-/* MINPTR - Index of minimum AMDF value */
-/* MAXPTR - Index of maximum AMDF value within +/- 1/2 octave of min */
-/* MINTAU - Lag corresponding to minimum AMDF value */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int tbdm_(real *speech, integer *lpita, integer *tau,
- integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *
- mintau)
-{
- /* System generated locals */
- integer i__1, i__2, i__3, i__4;
-
- /* Local variables */
- real amdf2[6];
- integer minp2, ltau2, maxp2, i__;
- extern /* Subroutine */ int difmag_(real *, integer *, integer *, integer
- *, integer *, real *, integer *, integer *);
- integer minamd, ptr, tau2[6];
-
-/* Arguments */
-/* REAL SPEECH(LPITA+TAU(LTAU)), AMDF(LTAU) */
-/* Stupid TOAST doesn't understand expressions */
-/* Local variables that need not be saved */
-/* Local state */
-/* None */
-/* Compute full AMDF using log spaced lags, find coarse minimum */
- /* Parameter adjustments */
- --speech;
- --amdf;
- --tau;
-
- /* Function Body */
- difmag_(&speech[1], lpita, &tau[1], ltau, &tau[*ltau], &amdf[1], minptr,
- maxptr);
- *mintau = tau[*minptr];
- minamd = amdf[*minptr];
-/* Build table containing all lags within +/- 3 of the AMDF minimum */
-/* excluding all that have already been computed */
- ltau2 = 0;
- ptr = *minptr - 2;
-/* Computing MAX */
- i__1 = *mintau - 3;
-/* Computing MIN */
- i__3 = *mintau + 3, i__4 = tau[*ltau] - 1;
- i__2 = min(i__3,i__4);
- for (i__ = max(i__1,41); i__ <= i__2; ++i__) {
- while(tau[ptr] < i__) {
- ++ptr;
- }
- if (tau[ptr] != i__) {
- ++ltau2;
- tau2[ltau2 - 1] = i__;
- }
- }
-/* Compute AMDF of the new lags, if there are any, and choose one */
-/* if it is better than the coarse minimum */
- if (ltau2 > 0) {
- difmag_(&speech[1], lpita, tau2, &ltau2, &tau[*ltau], amdf2, &minp2, &
- maxp2);
- if (amdf2[minp2 - 1] < (real) minamd) {
- *mintau = tau2[minp2 - 1];
- minamd = amdf2[minp2 - 1];
- }
- }
-/* Check one octave up, if there are any lags not yet computed */
- if (*mintau >= 80) {
- i__ = *mintau / 2;
- if ((i__ & 1) == 0) {
- ltau2 = 2;
- tau2[0] = i__ - 1;
- tau2[1] = i__ + 1;
- } else {
- ltau2 = 1;
- tau2[0] = i__;
- }
- difmag_(&speech[1], lpita, tau2, &ltau2, &tau[*ltau], amdf2, &minp2, &
- maxp2);
- if (amdf2[minp2 - 1] < (real) minamd) {
- *mintau = tau2[minp2 - 1];
- minamd = amdf2[minp2 - 1];
- *minptr += -20;
- }
- }
-/* Force minimum of the AMDF array to the high resolution minimum */
- amdf[*minptr] = (real) minamd;
-/* Find maximum of AMDF within 1/2 octave of minimum */
-/* Computing MAX */
- i__2 = *minptr - 5;
- *maxptr = max(i__2,1);
-/* Computing MIN */
- i__1 = *minptr + 5;
- i__2 = min(i__1,*ltau);
- for (i__ = *maxptr + 1; i__ <= i__2; ++i__) {
- if (amdf[i__] > amdf[*maxptr]) {
- *maxptr = i__;
- }
- }
- return 0;
-} /* tbdm_ */
-
diff --git a/1.2-netsec/codecs/lpc10/voicin.c b/1.2-netsec/codecs/lpc10/voicin.c
deleted file mode 100644
index 45bb5d0d3..000000000
--- a/1.2-netsec/codecs/lpc10/voicin.c
+++ /dev/null
@@ -1,786 +0,0 @@
-/*
-
-$Log$
-Revision 1.16 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.15 2003/11/23 22:14:32 markster
-Various warning cleanups
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:40 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.2 1996/08/20 20:45:00 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:14 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int voicin_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd, integer *mintau, real *ivrc, integer *obound, integer *voibuf, integer *af, struct lpc10_encoder_state *st);
-/* comlen contrl_ 12 */
-/*:ref: vparms_ 14 14 4 6 6 4 4 6 4 4 4 4 6 6 6 6 */
-#endif
-
-/* Common Block Declarations */
-
-extern struct {
- integer order, lframe;
- logical corrp;
-} contrl_;
-
-#define contrl_1 contrl_
-
-/****************************************************************************/
-
-/* VOICIN Version 52 */
-
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/11/23 22:14:32 markster
-/* Various warning cleanups
-/*
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:40 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:45:00 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:14 jaf
- * Initial revision
- * */
-/* Revision 1.10 1996/03/29 17:59:14 jaf */
-/* Avoided using VALUE(9), although it shouldn't affect the function of */
-/* the code at all, because it was always multiplied by VDC(9,SNRL), */
-/* which is 0 for all values of SNRL. Still, if VALUE(9) had an initial */
-/* value of IEEE NaN, it might cause trouble (I don't know how IEEE */
-/* defines Nan * 0. It should either be NaN or 0.) */
-
-/* Revision 1.9 1996/03/29 17:54:46 jaf */
-/* Added a few comments about the accesses made to argument array VOIBUF */
-/* and the local saved array VOICE. */
-
-/* Revision 1.8 1996/03/27 18:19:54 jaf */
-/* Added an assignment to VSTATE that does not affect the function of the */
-/* program at all. The only reason I put it in was so that the tracing */
-/* statements at the end, when enabled, will print a consistent value for */
-/* VSTATE when HALF .EQ. 1, rather than a garbage value that could change */
-/* from one call to the next. */
-
-/* Revision 1.7 1996/03/26 20:00:06 jaf */
-/* Removed the inclusion of the file "vcomm.fh", and put its contents */
-/* into this file. It was included nowhere else but here. */
-
-/* Revision 1.6 1996/03/26 19:38:09 jaf */
-/* Commented out trace statements. */
-
-/* Revision 1.5 1996/03/19 20:43:45 jaf */
-/* Added comments about which indices of OBOUND and VOIBUF can be */
-/* accessed, and whether they are read or written. VOIBUF is fairly */
-/* messy. */
-
-/* Revision 1.4 1996/03/19 15:00:58 jaf */
-/* Moved the DATA statements for the *VDC* variables later, as it is */
-/* apparently illegal to have DATA statements before local variable */
-/* declarations. */
-
-/* Revision 1.3 1996/03/19 00:10:49 jaf */
-/* Heavily commented the local variables that are saved from one */
-/* invocation to the next, and how the local variable FIRST is used to */
-/* avoid the need to assign most of them initial values with DATA */
-/* statements. */
-
-/* A few should be initialized, but aren't. I've guessed initial values */
-/* for two of these, SFBUE and SLBUE, and I've convinced myself that for */
-/* VOICE, the effects of uninitialized values will die out after 2 or 3 */
-/* frame times. It would still be good to choose initial values for */
-/* these, but I don't know what reasonable values would be (0 comes to */
-/* mind). */
-
-/* Revision 1.2 1996/03/13 16:09:28 jaf */
-/* Comments added explaining which of the local variables of this */
-/* subroutine need to be saved from one invocation to the next, and which */
-/* do not. */
-
-/* WARNING! Some of them that should are never given initial values in */
-/* this code. Hopefully, Fortran 77 defines initial values for them, but */
-/* even so, giving them explicit initial values is preferable. */
-
-/* WARNING! VALUE(9) is used, but never assigned a value. It should */
-/* probably be eliminated from the code. */
-
-/* Revision 1.1 1996/02/07 14:50:28 jaf */
-/* Initial revision */
-
-
-/****************************************************************************/
-
-/* Voicing Detection (VOICIN) makes voicing decisions for each half */
-/* frame of input speech. Tentative voicing decisions are made two frames*/
-/* in the future (2F) for each half frame. These decisions are carried */
-/* through one frame in the future (1F) to the present (P) frame where */
-/* they are examined and smoothed, resulting in the final voicing */
-/* decisions for each half frame. */
-/* The voicing parameter (signal measurement) column vector (VALUE) */
-/* is based on a rectangular window of speech samples determined by the */
-/* window placement algorithm. The voicing parameter vector contains the*/
-/* AMDF windowed maximum-to-minimum ratio, the zero crossing rate, energy*/
-/* measures, reflection coefficients, and prediction gains. The voicing */
-/* window is placed to avoid contamination of the voicing parameter vector*/
-/* with speech onsets. */
-/* The input signal is then classified as unvoiced (including */
-/* silence) or voiced. This decision is made by a linear discriminant */
-/* function consisting of a dot product of the voicing decision */
-/* coefficient (VDC) row vector with the measurement column vector */
-/* (VALUE). The VDC vector is 2-dimensional, each row vector is optimized*/
-/* for a particular signal-to-noise ratio (SNR). So, before the dot */
-/* product is performed, the SNR is estimated to select the appropriate */
-/* VDC vector. */
-/* The smoothing algorithm is a modified median smoother. The */
-/* voicing discriminant function is used by the smoother to determine how*/
-/* strongly voiced or unvoiced a signal is. The smoothing is further */
-/* modified if a speech onset and a voicing decision transition occur */
-/* within one half frame. In this case, the voicing decision transition */
-/* is extended to the speech onset. For transmission purposes, there are*/
-/* constraints on the duration and transition of voicing decisions. The */
-/* smoother takes these constraints into account. */
-/* Finally, the energy estimates are updated along with the dither */
-/* threshold used to calculate the zero crossing rate (ZC). */
-
-/* Inputs: */
-/* VWIN - Voicing window limits */
-/* The indices read of arrays VWIN, INBUF, LPBUF, and BUFLIM */
-/* are the same as those read by subroutine VPARMS. */
-/* INBUF - Input speech buffer */
-/* LPBUF - Low-pass filtered speech buffer */
-/* BUFLIM - INBUF and LPBUF limits */
-/* HALF - Present analysis half frame number */
-/* MINAMD - Minimum value of the AMDF */
-/* MAXAMD - Maximum value of the AMDF */
-/* MINTAU - Pointer to the lag of the minimum AMDF value */
-/* IVRC(2) - Inverse filter's RC's */
-/* Only index 2 of array IVRC read under normal operation. */
-/* (Index 1 is also read when debugging is turned on.) */
-/* OBOUND - Onset boundary descriptions */
-/* Indices 1 through 3 read if (HALF .NE. 1), otherwise untouched.
-*/
-/* AF - The analysis frame number */
-/* Output: */
-/* VOIBUF(2,0:AF) - Buffer of voicing decisions */
-/* Index (HALF,3) written. */
-/* If (HALF .EQ. 1), skip down to "Read (HALF,3)" below. */
-/* Indices (1,2), (2,1), (1,2), and (2,2) read. */
-/* One of the following is then done: */
-/* read (1,3) and possibly write (1,2) */
-/* read (1,3) and write (1,2) or (2,2) */
-/* write (2,1) */
-/* write (2,1) or (1,2) */
-/* read (1,0) and (1,3) and then write (2,2) or (1,1) */
-/* no reads or writes on VOIBUF */
-/* Finally, read (HALF,3) */
-/* Internal: */
-/* QS - Ratio of preemphasized to full-band energies */
-/* RC1 - First reflection coefficient */
-/* AR_B - Product of the causal forward and reverse pitch prediction gain
-s*/
-/* AR_F - Product of the noncausal forward and rev. pitch prediction gain
-s*/
-/* ZC - Zero crossing rate */
-/* DITHER - Zero crossing threshold level */
-/* MAXMIN - AMDF's 1 octave windowed maximum-to-minimum ratio */
-/* MINPTR - Location of minimum AMDF value */
-/* NVDC - Number of elements in each VDC vector */
-/* NVDCL - Number of VDC vectors */
-/* VDCL - SNR values corresponding to the set of VDC's */
-/* VDC - 2-D voicing decision coefficient vector */
-/* VALUE(9) - Voicing Parameters */
-/* VOICE(2,3)- History of LDA results */
-/* On every call when (HALF .EQ. 1), VOICE(*,I+1) is */
-/* shifted back to VOICE(*,I), for I=1,2. */
-/* VOICE(HALF,3) is written on every call. */
-/* Depending on several conditions, one or more of */
-/* (1,1), (1,2), (2,1), and (2,2) might then be read. */
-/* LBE - Ratio of low-band instantaneous to average energies */
-/* FBE - Ratio of full-band instantaneous to average energies */
-/* LBVE - Low band voiced energy */
-/* LBUE - Low band unvoiced energy */
-/* FBVE - Full band voiced energy */
-/* FBUE - Full band unvoiced energy */
-/* OFBUE - Previous full-band unvoiced energy */
-/* OLBUE - Previous low-band unvoiced energy */
-/* REF - Reference energy for initialization and DITHER threshold */
-/* SNR - Estimate of signal-to-noise ratio */
-/* SNR2 - Estimate of low-band signal-to-noise ratio */
-/* SNRL - SNR level number */
-/* OT - Onset transition present */
-/* VSTATE - Decimal interpretation of binary voicing classifications */
-/* FIRST - First call flag */
-
-/* This subroutine maintains local state from one call to the next. If */
-/* you want to switch to using a new audio stream for this filter, or */
-/* reinitialize its state for any other reason, call the ENTRY */
-/* INITVOICIN. */
-
-/* Subroutine */ int voicin_(integer *vwin, real *inbuf, real *
- lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd,
- integer *mintau, real *ivrc, integer *obound, integer *voibuf,
- integer *af, struct lpc10_encoder_state *st)
-{
- /* Initialized data */
-
- real *dither;
- static real vdc[100] /* was [10][10] */ = { 0.f,1714.f,-110.f,
- 334.f,-4096.f,-654.f,3752.f,3769.f,0.f,1181.f,0.f,874.f,-97.f,
- 300.f,-4096.f,-1021.f,2451.f,2527.f,0.f,-500.f,0.f,510.f,-70.f,
- 250.f,-4096.f,-1270.f,2194.f,2491.f,0.f,-1500.f,0.f,500.f,-10.f,
- 200.f,-4096.f,-1300.f,2e3f,2e3f,0.f,-2e3f,0.f,500.f,0.f,0.f,
- -4096.f,-1300.f,2e3f,2e3f,0.f,-2500.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
- 0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
- 0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
- 0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f };
- static integer nvdcl = 5;
- static real vdcl[10] = { 600.f,450.f,300.f,200.f,0.f,0.f,0.f,0.f,0.f,0.f }
- ;
-
- /* System generated locals */
- integer inbuf_offset = 0, lpbuf_offset = 0, i__1, i__2;
- real r__1, r__2;
-
- /* Builtin functions */
- integer i_nint(real *);
- double sqrt(doublereal);
-
- /* Local variables */
- real ar_b__, ar_f__;
- integer *lbve, *lbue, *fbve, *fbue;
- integer snrl, i__;
- integer *ofbue, *sfbue;
- real *voice;
- integer *olbue, *slbue;
- real value[9];
- integer zc;
- logical ot;
- real qs;
- real *maxmin;
- integer vstate;
- real rc1;
- extern /* Subroutine */ int vparms_(integer *, real *, real *, integer *,
- integer *, real *, integer *, integer *, integer *, integer *,
- real *, real *, real *, real *);
- integer fbe, lbe;
- real *snr;
- real snr2;
-
-/* Global Variables: */
-/* Arguments */
-/* $Log$
- * Revision 1.16 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.15 2003/11/23 22:14:32 markster
-/* Various warning cleanups
-/*
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:40 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.2 1996/08/20 20:45:00 jaf
- * Removed all static local variables that were SAVE'd in the Fortran
- * code, and put them in struct lpc10_encoder_state that is passed as an
- * argument.
- *
- * Removed init function, since all initialization is now done in
- * init_lpc10_encoder_state().
- *
- * Revision 1.1 1996/08/19 22:30:14 jaf
- * Initial revision
- * */
-/* Revision 1.3 1996/03/29 22:05:55 jaf */
-/* Commented out the common block variables that are not needed by the */
-/* embedded version. */
-
-/* Revision 1.2 1996/03/26 19:34:50 jaf */
-/* Added comments indicating which constants are not needed in an */
-/* application that uses the LPC-10 coder. */
-
-/* Revision 1.1 1996/02/07 14:44:09 jaf */
-/* Initial revision */
-
-/* LPC Processing control variables: */
-
-/* *** Read-only: initialized in setup */
-
-/* Files for Speech, Parameter, and Bitstream Input & Output, */
-/* and message and debug outputs. */
-
-/* Here are the only files which use these variables: */
-
-/* lpcsim.f setup.f trans.f error.f vqsetup.f */
-
-/* Many files which use fdebug are not listed, since it is only used in */
-/* those other files conditionally, to print trace statements. */
-/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* LPC order, Frame size, Quantization rate, Bits per frame, */
-/* Error correction */
-/* Subroutine SETUP is the only place where order is assigned a value, */
-/* and that value is 10. It could increase efficiency 1% or so to */
-/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
-*/
-/* a variable in a COMMON block, since it is used in many places in the */
-/* core of the coding and decoding routines. Actually, I take that back.
-*/
-/* At least when compiling with f2c, the upper bound of DO loops is */
-/* stored in a local variable before the DO loop begins, and then that is
-*/
-/* compared against on each iteration. */
-/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
-/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
-/* is used in only a few places, and never in the core coding and */
-/* decoding routines, so it could be eliminated entirely. */
-/* nbits is similar to quant, and is given a value of 54 in SETUP. */
-/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
-/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
-/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
-*/
-/* a constant or a variable, since it is only examined once per frame. */
-/* Leaving it as a variable that is set to .TRUE. seems like a good */
-/* idea, since it does enable some error-correction capability for */
-/* unvoiced frames, with no change in the coding rate, and no noticeable
-*/
-/* quality difference in the decoded speech. */
-/* integer quant, nbits */
-/* *** Read/write: variables for debugging, not needed for LPC algorithm
-*/
-
-/* Current frame, Unstable frames, Output clip count, Max onset buffer,
-*/
-/* Debug listing detail level, Line count on listing page */
-
-/* nframe is not needed for an embedded LPC10 at all. */
-/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
-/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
-/* an application, I would recommend removing the call to ERROR in RCCHK,
-*/
-/* and remove ERROR and nunsfm completely. */
-/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
-*/
-/* sread.f. When LPC10 is embedded into an application, one might want */
-/* to cause it to be incremented in a routine that takes the output of */
-/* SYNTHS and sends it to an audio device. It could be optionally */
-/* displayed, for those that might want to know what it is. */
-/* maxosp is never initialized to 0 in SETUP, although it probably should
-*/
-/* be, and it is updated in subroutine ANALYS. I doubt that its value */
-/* would be of much interest to an application in which LPC10 is */
-/* embedded. */
-/* listl and lincnt are not needed for an embedded LPC10 at all. */
-/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
-/* common /contrl/ quant, nbits */
-/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
-/* Parameters/constants */
-/* Voicing coefficient and Linear Discriminant Analysis variables:
-*/
-/* Max number of VDC's and VDC levels */
-/* The following are not Fortran PARAMETER's, but they are */
-/* initialized with DATA statements, and never modified. */
-/* Actual number of VDC's and levels */
-/* Local variables that need not be saved */
-/* Note: */
-
-/* VALUE(1) through VALUE(8) are assigned values, but VALUE(9) */
-/* never is. Yet VALUE(9) is read in the loop that begins "DO I =
-*/
-/* 1, 9" below. I believe that this doesn't cause any problems in
-*/
-/* this subroutine, because all VDC(9,*) array elements are 0, and
-*/
-/* this is what is multiplied by VALUE(9) in all cases. Still, it
-*/
-/* would save a multiplication to change the loop to "DO I = 1, 8".
-*/
-/* Local state */
-/* WARNING! */
-
-/* VOICE, SFBUE, and SLBUE should be saved from one invocation to */
-/* the next, but they are never given an initial value. */
-
-/* Does Fortran 77 specify some default initial value, like 0, or */
-/* is it undefined? If it is undefined, then this code should be */
-/* corrected to specify an initial value. */
-
-/* For VOICE, note that it is "shifted" in the statement that */
-/* begins "IF (HALF .EQ. 1) THEN" below. Also, uninitialized */
-/* values in the VOICE array can only affect entries in the VOIBUF
-*/
-/* array that are for the same frame, or for an older frame. Thus
-*/
-/* the effects of uninitialized values in VOICE cannot linger on */
-/* for more than 2 or 3 frame times. */
-
-/* For SFBUE and SLBUE, the effects of uninitialized values can */
-/* linger on for many frame times, because their previous values */
-/* are exponentially decayed. Thus it is more important to choose
-*/
-/* initial values for these variables. I would guess that a */
-/* reasonable initial value for SFBUE is REF/16, the same as used */
-/* for FBUE and OFBUE. Similarly, SLBUE can be initialized to */
-/* REF/32, the same as for LBUE and OLBUE. */
-
-/* These guessed initial values should be validated by re-running */
-/* the modified program on some audio samples. */
-
-/* Declare and initialize filters: */
-
- dither = (&st->dither);
- snr = (&st->snr);
- maxmin = (&st->maxmin);
- voice = (&st->voice[0]);
- lbve = (&st->lbve);
- lbue = (&st->lbue);
- fbve = (&st->fbve);
- fbue = (&st->fbue);
- ofbue = (&st->ofbue);
- olbue = (&st->olbue);
- sfbue = (&st->sfbue);
- slbue = (&st->slbue);
-
- /* Parameter adjustments */
- if (vwin) {
- --vwin;
- }
- if (buflim) {
- --buflim;
- }
- if (inbuf) {
- inbuf_offset = buflim[1];
- inbuf -= inbuf_offset;
- }
- if (lpbuf) {
- lpbuf_offset = buflim[3];
- lpbuf -= lpbuf_offset;
- }
- if (ivrc) {
- --ivrc;
- }
- if (obound) {
- --obound;
- }
- if (voibuf) {
- --voibuf;
- }
-
- /* Function Body */
-
-/* The following variables are saved from one invocation to the */
-/* next, but are not initialized with DATA statements. This is */
-/* acceptable, because FIRST is initialized ot .TRUE., and the */
-/* first time that this subroutine is then called, they are all */
-/* given initial values. */
-
-/* SNR */
-/* LBVE, LBUE, FBVE, FBUE, OFBUE, OLBUE */
-
-/* MAXMIN is initialized on the first call, assuming that HALF */
-/* .EQ. 1 on first call. This is how ANALYS calls this subroutine.
-*/
-
-/* Voicing Decision Parameter vector (* denotes zero coefficient): */
-
-/* * MAXMIN */
-/* LBE/LBVE */
-/* ZC */
-/* RC1 */
-/* QS */
-/* IVRC2 */
-/* aR_B */
-/* aR_F */
-/* * LOG(LBE/LBVE) */
-/* Define 2-D voicing decision coefficient vector according to the voicin
-g*/
-/* parameter order above. Each row (VDC vector) is optimized for a speci
-fic*/
-/* SNR. The last element of the vector is the constant. */
-/* E ZC RC1 Qs IVRC2 aRb aRf c */
-
-/* The VOICE array contains the result of the linear discriminant functio
-n*/
-/* (analog values). The VOIBUF array contains the hard-limited binary
-*/
-/* voicing decisions. The VOICE and VOIBUF arrays, according to FORTRAN
- */
-/* memory allocation, are addressed as: */
-
-/* (half-frame number, future-frame number) */
-
-/* | Past | Present | Future1 | Future2 | */
-/* | 1,0 | 2,0 | 1,1 | 2,1 | 1,2 | 2,2 | 1,3 | 2,3 | ---> time */
-
-/* Update linear discriminant function history each frame: */
- if (*half == 1) {
- voice[0] = voice[2];
- voice[1] = voice[3];
- voice[2] = voice[4];
- voice[3] = voice[5];
- *maxmin = *maxamd / max(*minamd,1.f);
- }
-/* Calculate voicing parameters twice per frame: */
- vparms_(&vwin[1], &inbuf[inbuf_offset], &lpbuf[lpbuf_offset], &buflim[1],
- half, dither, mintau, &zc, &lbe, &fbe, &qs, &rc1, &ar_b__, &
- ar_f__);
-/* Estimate signal-to-noise ratio to select the appropriate VDC vector.
-*/
-/* The SNR is estimated as the running average of the ratio of the */
-/* running average full-band voiced energy to the running average */
-/* full-band unvoiced energy. SNR filter has gain of 63. */
- r__1 = (*snr + *fbve / (real) max(*fbue,1)) * 63 / 64.f;
- *snr = (real) i_nint(&r__1);
- snr2 = *snr * *fbue / max(*lbue,1);
-/* Quantize SNR to SNRL according to VDCL thresholds. */
- snrl = 1;
- i__1 = nvdcl - 1;
- for (snrl = 1; snrl <= i__1; ++snrl) {
- if (snr2 > vdcl[snrl - 1]) {
- goto L69;
- }
- }
-/* (Note: SNRL = NVDCL here) */
-L69:
-/* Linear discriminant voicing parameters: */
- value[0] = *maxmin;
- value[1] = (real) lbe / max(*lbve,1);
- value[2] = (real) zc;
- value[3] = rc1;
- value[4] = qs;
- value[5] = ivrc[2];
- value[6] = ar_b__;
- value[7] = ar_f__;
-/* Evaluation of linear discriminant function: */
- voice[*half + 3] = vdc[snrl * 10 - 1];
- for (i__ = 1; i__ <= 8; ++i__) {
- voice[*half + 3] += vdc[i__ + snrl * 10 - 11] * value[i__ - 1];
- }
-/* Classify as voiced if discriminant > 0, otherwise unvoiced */
-/* Voicing decision for current half-frame: 1 = Voiced; 0 = Unvoiced */
- if (voice[*half + 3] > 0.f) {
- voibuf[*half + 6] = 1;
- } else {
- voibuf[*half + 6] = 0;
- }
-/* Skip voicing decision smoothing in first half-frame: */
-/* Give a value to VSTATE, so that trace statements below will print
-*/
-/* a consistent value from one call to the next when HALF .EQ. 1. */
-/* The value of VSTATE is not used for any other purpose when this is
-*/
-/* true. */
- vstate = -1;
- if (*half == 1) {
- goto L99;
- }
-/* Voicing decision smoothing rules (override of linear combination): */
-
-/* Unvoiced half-frames: At least two in a row. */
-/* -------------------- */
-
-/* Voiced half-frames: At least two in a row in one frame. */
-/* ------------------- Otherwise at least three in a row. */
-/* (Due to the way transition frames are encoded) */
-
-/* In many cases, the discriminant function determines how to smooth. */
-/* In the following chart, the decisions marked with a * may be overridden
-.*/
-
-/* Voicing override of transitions at onsets: */
-/* If a V/UV or UV/V voicing decision transition occurs within one-half
-*/
-/* frame of an onset bounding a voicing window, then the transition is */
-/* moved to occur at the onset. */
-
-/* P 1F */
-/* ----- ----- */
-/* 0 0 0 0 */
-/* 0 0 0* 1 (If there is an onset there) */
-/* 0 0 1* 0* (Based on 2F and discriminant distance) */
-/* 0 0 1 1 */
-/* 0 1* 0 0 (Always) */
-/* 0 1* 0* 1 (Based on discriminant distance) */
-/* 0* 1 1 0* (Based on past, 2F, and discriminant distance) */
-/* 0 1* 1 1 (If there is an onset there) */
-/* 1 0* 0 0 (If there is an onset there) */
-/* 1 0 0 1 */
-/* 1 0* 1* 0 (Based on discriminant distance) */
-/* 1 0* 1 1 (Always) */
-/* 1 1 0 0 */
-/* 1 1 0* 1* (Based on 2F and discriminant distance) */
-/* 1 1 1* 0 (If there is an onset there) */
-/* 1 1 1 1 */
-
-/* Determine if there is an onset transition between P and 1F. */
-/* OT (Onset Transition) is true if there is an onset between */
-/* P and 1F but not after 1F. */
- ot = ((obound[1] & 2) != 0 || obound[2] == 1) && (obound[3] & 1) == 0;
-/* Multi-way dispatch on voicing decision history: */
- vstate = (voibuf[3] << 3) + (voibuf[4] << 2) + (voibuf[5] << 1) + voibuf[
- 6];
- switch (vstate + 1) {
- case 1: goto L99;
- case 2: goto L1;
- case 3: goto L2;
- case 4: goto L99;
- case 5: goto L4;
- case 6: goto L5;
- case 7: goto L6;
- case 8: goto L7;
- case 9: goto L8;
- case 10: goto L99;
- case 11: goto L10;
- case 12: goto L11;
- case 13: goto L99;
- case 14: goto L13;
- case 15: goto L14;
- case 16: goto L99;
- }
-L1:
- if (ot && voibuf[7] == 1) {
- voibuf[5] = 1;
- }
- goto L99;
-L2:
- if (voibuf[7] == 0 || voice[2] < -voice[3]) {
- voibuf[5] = 0;
- } else {
- voibuf[6] = 1;
- }
- goto L99;
-L4:
- voibuf[4] = 0;
- goto L99;
-L5:
- if (voice[1] < -voice[2]) {
- voibuf[4] = 0;
- } else {
- voibuf[5] = 1;
- }
- goto L99;
-/* VOIBUF(2,0) must be 0 */
-L6:
- if (voibuf[1] == 1 || voibuf[7] == 1 || voice[3] > voice[0]) {
- voibuf[6] = 1;
- } else {
- voibuf[3] = 1;
- }
- goto L99;
-L7:
- if (ot) {
- voibuf[4] = 0;
- }
- goto L99;
-L8:
- if (ot) {
- voibuf[4] = 1;
- }
- goto L99;
-L10:
- if (voice[2] < -voice[1]) {
- voibuf[5] = 0;
- } else {
- voibuf[4] = 1;
- }
- goto L99;
-L11:
- voibuf[4] = 1;
- goto L99;
-L13:
- if (voibuf[7] == 0 && voice[3] < -voice[2]) {
- voibuf[6] = 0;
- } else {
- voibuf[5] = 1;
- }
- goto L99;
-L14:
- if (ot && voibuf[7] == 0) {
- voibuf[5] = 0;
- }
-/* GOTO 99 */
-L99:
-/* Now update parameters: */
-/* ---------------------- */
-
-/* During unvoiced half-frames, update the low band and full band unvoice
-d*/
-/* energy estimates (LBUE and FBUE) and also the zero crossing */
-/* threshold (DITHER). (The input to the unvoiced energy filters is */
-/* restricted to be less than 10dB above the previous inputs of the */
-/* filters.) */
-/* During voiced half-frames, update the low-pass (LBVE) and all-pass */
-/* (FBVE) voiced energy estimates. */
- if (voibuf[*half + 6] == 0) {
-/* Computing MIN */
- i__1 = fbe, i__2 = *ofbue * 3;
- r__1 = (*sfbue * 63 + (min(i__1,i__2) << 3)) / 64.f;
- *sfbue = i_nint(&r__1);
- *fbue = *sfbue / 8;
- *ofbue = fbe;
-/* Computing MIN */
- i__1 = lbe, i__2 = *olbue * 3;
- r__1 = (*slbue * 63 + (min(i__1,i__2) << 3)) / 64.f;
- *slbue = i_nint(&r__1);
- *lbue = *slbue / 8;
- *olbue = lbe;
- } else {
- r__1 = (*lbve * 63 + lbe) / 64.f;
- *lbve = i_nint(&r__1);
- r__1 = (*fbve * 63 + fbe) / 64.f;
- *fbve = i_nint(&r__1);
- }
-/* Set dither threshold to yield proper zero crossing rates in the */
-/* presence of low frequency noise and low level signal input. */
-/* NOTE: The divisor is a function of REF, the expected energies. */
-/* Computing MIN */
-/* Computing MAX */
- r__2 = sqrt((real) (*lbue * *lbve)) * 64 / 3000;
- r__1 = max(r__2,1.f);
- *dither = min(r__1,20.f);
-/* Voicing decisions are returned in VOIBUF. */
- return 0;
-} /* voicin_ */
diff --git a/1.2-netsec/codecs/lpc10/vparms.c b/1.2-netsec/codecs/lpc10/vparms.c
deleted file mode 100644
index b9e602930..000000000
--- a/1.2-netsec/codecs/lpc10/vparms.c
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
-
-$Log$
-Revision 1.15 2004/06/26 03:50:14 markster
-Merge source cleanups (bug #1911)
-
-Revision 1.14 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-mer feb 12 14:56:57 CET 2003
-
-Revision 1.2 2000/01/05 08:20:40 markster
-Some OSS fixes and a few lpc changes to make it actually work
-
- * Revision 1.1 1996/08/19 22:30:04 jaf
- * Initial revision
- *
-
-*/
-
-/* -- translated by f2c (version 19951025).
- You must link the resulting object file with the libraries:
- -lf2c -lm (in that order)
-*/
-
-#include "f2c.h"
-
-#ifdef P_R_O_T_O_T_Y_P_E_S
-extern int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__);
-#endif
-
-/* Table of constant values */
-
-static real c_b2 = 1.f;
-
-/* ********************************************************************* */
-
-/* VPARMS Version 50 */
-
-/* $Log$
- * Revision 1.15 2004/06/26 03:50:14 markster
- * Merge source cleanups (bug #1911)
- *
-/* Revision 1.14 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
-/* mer feb 12 14:56:57 CET 2003
-/*
-/* Revision 1.2 2000/01/05 08:20:40 markster
-/* Some OSS fixes and a few lpc changes to make it actually work
-/*
- * Revision 1.1 1996/08/19 22:30:04 jaf
- * Initial revision
- * */
-/* Revision 1.6 1996/03/29 18:01:16 jaf */
-/* Added some more comments about the range of INBUF and LPBUF that can */
-/* be read. Note that it is possible for index VWIN(2)+1 to be read from */
-/* INBUF, which might be outside of its defined range, although that will */
-/* require more careful checking. */
-
-/* Revision 1.5 1996/03/19 00:02:02 jaf */
-/* I just noticed that the argument DITHER is modified inside of this */
-/* subroutine. Comments were added explaining the possible final values. */
-
-/* Revision 1.4 1996/03/18 22:22:59 jaf */
-/* Finishing the job I said I did with the last check-in comments. */
-
-/* Revision 1.3 1996/03/18 22:22:17 jaf */
-/* Just added a few comments about which array indices of the arguments */
-/* are used, and mentioning that this subroutine has no local state. */
-
-/* Revision 1.2 1996/03/13 15:02:58 jaf */
-/* Comments added explaining that none of the local variables of this */
-/* subroutine need to be saved from one invocation to the next. */
-
-/* Revision 1.1 1996/02/07 14:50:42 jaf */
-/* Initial revision */
-
-
-/* ********************************************************************* */
-
-/* Calculate voicing parameters: */
-
-/* Input: */
-/* VWIN - Voicing window limits */
-/* Indices 1 through 2 read. */
-/* INBUF - Input speech buffer */
-/* Indices START-1 through STOP read, */
-/* where START and STOP are defined in the code (only written once).
-*/
-/* Note that STOP can be as large as VWIN(2)+1 ! */
-/* LPBUF - Low pass filtered speech */
-/* Indices START-MINTAU through STOP+MINTAU read, */
-/* where START and STOP are defined in the code (only written once).
-*/
-/* BUFLIM - Array bounds for INBUF and LPBUF */
-/* Indices 1 through 4 read. */
-/* HALF - Half frame (1 or 2) */
-/* MINTAU - Lag corresponding to minimum AMDF value (pitch estimate) */
-/* Input/Output: */
-/* DITHER - Zero crossing threshold */
-/* The resulting value might be the negation of the input */
-/* value. It might always be the same as the input value, */
-/* if the DO loop below always executes an even number of times. */
-/* Output: (all of them are written on every call) */
-/* ZC - Zero crossing rate */
-/* LBE - Low band energy (sum of magnitudes - SM) */
-/* FBE - Full band energy (SM) */
-/* QS - Ratio of 6 dB/oct preemphasized energy to full band energy */
-/* RC1 - First reflection coefficient */
-/* AR_B - Product of the causal forward and reverse pitch */
-/* prediction gains */
-/* AR_F - Product of the noncausal forward and reverse pitch */
-/* prediction gains */
-/* Internal: */
-/* OLDSGN - Previous sign of dithered signal */
-/* VLEN - Length of voicing window */
-/* START - Lower address of current half of voicing window */
-/* STOP - Upper address of current half of voicing window */
-/* E_0 - Energy of LPF speech (sum of squares - SS) */
-/* E_B - Energy of LPF speech backward one pitch period (SS) */
-/* E_F - Energy of LPF speech forward one pitch period (SS) */
-/* R_B - Autocovariance of LPF speech backward one pitch period */
-/* R_F - Autocovariance of LPF speech forward one pitch period */
-/* LP_RMS - Energy of LPF speech (sum of magnitudes - SM) */
-/* AP_RMS - Energy of all-pass speech (SM) */
-/* E_PRE - Energy of 6dB preemphasized speech (SM) */
-/* E0AP - Energy of all-pass speech (SS) */
-
-/* This subroutine has no local state. */
-
-/* Subroutine */ int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer
- *buflim, integer *half, real *dither, integer *mintau, integer *zc,
- integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *
- ar_f__)
-{
- /* System generated locals */
- integer inbuf_offset, lpbuf_offset, i__1;
- real r__1, r__2;
-
- /* Builtin functions */
- double r_sign(real *, real *);
- integer i_nint(real *);
-
- /* Local variables */
- integer vlen, stop, i__;
- real e_pre__;
- integer start;
- real ap_rms__, e_0__, oldsgn, lp_rms__, e_b__, e_f__, r_b__, r_f__, e0ap;
-
-/* Arguments */
-/* Local variables that need not be saved */
-/* Calculate zero crossings (ZC) and several energy and correlation */
-/* measures on low band and full band speech. Each measure is taken */
-/* over either the first or the second half of the voicing window, */
-/* depending on the variable HALF. */
- /* Parameter adjustments */
- --vwin;
- --buflim;
- lpbuf_offset = buflim[3];
- lpbuf -= lpbuf_offset;
- inbuf_offset = buflim[1];
- inbuf -= inbuf_offset;
-
- /* Function Body */
- lp_rms__ = 0.f;
- ap_rms__ = 0.f;
- e_pre__ = 0.f;
- e0ap = 0.f;
- *rc1 = 0.f;
- e_0__ = 0.f;
- e_b__ = 0.f;
- e_f__ = 0.f;
- r_f__ = 0.f;
- r_b__ = 0.f;
- *zc = 0;
- vlen = vwin[2] - vwin[1] + 1;
- start = vwin[1] + (*half - 1) * vlen / 2 + 1;
- stop = start + vlen / 2 - 1;
-
-/* I'll use the symbol HVL in the table below to represent the value */
-/* VLEN/2. Note that if VLEN is odd, then HVL should be rounded down, */
-/* i.e., HVL = (VLEN-1)/2. */
-
-/* HALF START STOP */
-
-/* 1 VWIN(1)+1 VWIN(1)+HVL */
-/* 2 VWIN(1)+HVL+1 VWIN(1)+2*HVL */
-
-/* Note that if VLEN is even and HALF is 2, then STOP will be */
-/* VWIN(1)+VLEN = VWIN(2)+1. That could be bad, if that index of INBUF */
-/* is undefined. */
-
- r__1 = inbuf[start - 1] - *dither;
- oldsgn = r_sign(&c_b2, &r__1);
- i__1 = stop;
- for (i__ = start; i__ <= i__1; ++i__) {
- lp_rms__ += (r__1 = lpbuf[i__], abs(r__1));
- ap_rms__ += (r__1 = inbuf[i__], abs(r__1));
- e_pre__ += (r__1 = inbuf[i__] - inbuf[i__ - 1], abs(r__1));
-/* Computing 2nd power */
- r__1 = inbuf[i__];
- e0ap += r__1 * r__1;
- *rc1 += inbuf[i__] * inbuf[i__ - 1];
-/* Computing 2nd power */
- r__1 = lpbuf[i__];
- e_0__ += r__1 * r__1;
-/* Computing 2nd power */
- r__1 = lpbuf[i__ - *mintau];
- e_b__ += r__1 * r__1;
-/* Computing 2nd power */
- r__1 = lpbuf[i__ + *mintau];
- e_f__ += r__1 * r__1;
- r_f__ += lpbuf[i__] * lpbuf[i__ + *mintau];
- r_b__ += lpbuf[i__] * lpbuf[i__ - *mintau];
- r__1 = inbuf[i__] + *dither;
- if (r_sign(&c_b2, &r__1) != oldsgn) {
- ++(*zc);
- oldsgn = -oldsgn;
- }
- *dither = -(*dither);
- }
-/* Normalized short-term autocovariance coefficient at unit sample delay
- */
- *rc1 /= max(e0ap,1.f);
-/* Ratio of the energy of the first difference signal (6 dB/oct preemphas
-is)*/
-/* to the energy of the full band signal */
-/* Computing MAX */
- r__1 = ap_rms__ * 2.f;
- *qs = e_pre__ / max(r__1,1.f);
-/* aR_b is the product of the forward and reverse prediction gains, */
-/* looking backward in time (the causal case). */
- *ar_b__ = r_b__ / max(e_b__,1.f) * (r_b__ / max(e_0__,1.f));
-/* aR_f is the same as aR_b, but looking forward in time (non causal case
-).*/
- *ar_f__ = r_f__ / max(e_f__,1.f) * (r_f__ / max(e_0__,1.f));
-/* Normalize ZC, LBE, and FBE to old fixed window length of 180. */
-/* (The fraction 90/VLEN has a range of .58 to 1) */
- r__2 = (real) (*zc << 1);
- r__1 = r__2 * (90.f / vlen);
- *zc = i_nint(&r__1);
-/* Computing MIN */
- r__1 = lp_rms__ / 4 * (90.f / vlen);
- i__1 = i_nint(&r__1);
- *lbe = min(i__1,32767);
-/* Computing MIN */
- r__1 = ap_rms__ / 4 * (90.f / vlen);
- i__1 = i_nint(&r__1);
- *fbe = min(i__1,32767);
- return 0;
-} /* vparms_ */
-
diff --git a/1.2-netsec/codecs/lpc10_slin_ex.h b/1.2-netsec/codecs/lpc10_slin_ex.h
deleted file mode 100644
index cf9f05999..000000000
--- a/1.2-netsec/codecs/lpc10_slin_ex.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*! \file
- * \brief 8-bit raw data
- *
- * Source: example.lpc10
- *
- * Copyright (C) 1999-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char lpc10_slin_ex[] = {
-0x1, 0x8, 0x31, 0x8, 0x31, 0x80, 0x30 };
diff --git a/1.2-netsec/codecs/slin_adpcm_ex.h b/1.2-netsec/codecs/slin_adpcm_ex.h
deleted file mode 100644
index 801549a3c..000000000
--- a/1.2-netsec/codecs/slin_adpcm_ex.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*! \file
- * \brief slin_adpcm_ex.h --
- *
- * Signed 16-bit audio data, 10 milliseconds worth at 8 kHz.
- *
- * Source: g723.example
- *
- * Copyright (C) 2001-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short slin_adpcm_ex[] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
-};
diff --git a/1.2-netsec/codecs/slin_g723_ex.h b/1.2-netsec/codecs/slin_g723_ex.h
deleted file mode 100644
index c6dccd776..000000000
--- a/1.2-netsec/codecs/slin_g723_ex.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*! \file
- * \brief Signed 16-bit audio data
- *
- * Source: g723.example
- *
- * Copyright (C) 1999-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short slin_g723_ex[] = {
-0x0873, 0x06d9, 0x038c, 0x0588, 0x0409, 0x033d, 0x0311, 0xff6c, 0xfeef, 0xfd3e,
-0xfdff, 0xff7a, 0xff6d, 0xffec, 0xff36, 0xfd62, 0xfda7, 0xfc6c, 0xfe67, 0xffe1,
-0x003d, 0x01cc, 0x0065, 0x002a, 0xff83, 0xfed9, 0xffba, 0xfece, 0xff42, 0xff16,
-0xfe85, 0xff31, 0xff02, 0xfdff, 0xfe32, 0xfe3f, 0xfed5, 0xff65, 0xffd4, 0x005b,
-0xff88, 0xff01, 0xfebd, 0xfe95, 0xff46, 0xffe1, 0x00e2, 0x0165, 0x017e, 0x01c9,
-0x0182, 0x0146, 0x00f9, 0x00ab, 0x006f, 0xffe8, 0xffd8, 0xffc4, 0xffb2, 0xfff9,
-0xfffe, 0x0023, 0x0018, 0x000b, 0x001a, 0xfff7, 0x0014, 0x000b, 0x0004, 0x000b,
-0xfff1, 0xff4f, 0xff3f, 0xff42, 0xff5e, 0xffd4, 0x0014, 0x0067, 0x0051, 0x003b,
-0x0034, 0xfff9, 0x000d, 0xff54, 0xff54, 0xff52, 0xff3f, 0xffcc, 0xffe6, 0x00fc,
-0x00fa, 0x00e4, 0x00f3, 0x0021, 0x0011, 0xffa1, 0xffab, 0xffdb, 0xffa5, 0x0009,
-0xffd2, 0xffe6, 0x0007, 0x0096, 0x00e4, 0x00bf, 0x00ce, 0x0048, 0xffe8, 0xffab,
-0xff8f, 0xffc3, 0xffc1, 0xfffc, 0x0002, 0xfff1, 0x000b, 0x00a7, 0x00c5, 0x00cc,
-0x015e, 0x00e4, 0x0094, 0x0029, 0xffc7, 0xffc3, 0xff86, 0xffe4, 0xffe6, 0xffec,
-0x000f, 0xffe3, 0x0028, 0x004b, 0xffaf, 0xffcb, 0xfedd, 0xfef8, 0xfe83, 0xfeba,
-0xff94, 0xff94, 0xffbe, 0xffa8, 0xff0d, 0xff32, 0xff58, 0x0021, 0x0087, 0x00be,
-0x0115, 0x007e, 0x0052, 0xfff0, 0xffc9, 0xffe8, 0xffc4, 0x0014, 0xfff0, 0xfff5,
-0xfffe, 0xffda, 0x000b, 0x0010, 0x006f, 0x006f, 0x0052, 0x0045, 0xffee, 0xffea,
-0xffcb, 0xffdf, 0xfffc, 0xfff0, 0x0012, 0xfff7, 0xfffe, 0x0018, 0x0050, 0x0066,
-0x0047, 0x0028, 0xfff7, 0xffe8, 0xffec, 0x0007, 0x001d, 0x0016, 0x00c4, 0x0093,
-0x007d, 0x0052, 0x00a5, 0x0091, 0x003c, 0x0041, 0xffd1, 0xffda, 0xffc6, 0xfff0,
-0x001d, 0xfffe, 0x0024, 0xffee, 0xfff3, 0xfff0, 0xffea, 0x0012, 0xfff3, 0xfff7,
-0xffda, 0xffca, 0xffda, 0xffdf, 0xfff3, 0xfff7, 0xff54, 0xff7c, 0xff8c, 0xffb9,
-0x0012, 0x0012, 0x004c, 0x0007, 0xff50, 0xff66, 0xff54, 0xffa9, 0xffdc, 0xfff9,
-0x0038, 0xfff9, 0x00d2, 0x0096, 0x008a, 0x0079, 0xfff5, 0x0019, 0xffad, 0xfffc };
diff --git a/1.2-netsec/codecs/slin_g726_ex.h b/1.2-netsec/codecs/slin_g726_ex.h
deleted file mode 100644
index 8dad39cbd..000000000
--- a/1.2-netsec/codecs/slin_g726_ex.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*! \file
- * \brief slin_adpcm_ex.h --
- *
- * Signed 16-bit audio data, 10 milliseconds worth at 8 kHz.
- *
- * Source: g726.example
- *
- * Copyright (C) 2001-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short slin_g726_ex[] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
-};
diff --git a/1.2-netsec/codecs/slin_gsm_ex.h b/1.2-netsec/codecs/slin_gsm_ex.h
deleted file mode 100644
index 7ac281800..000000000
--- a/1.2-netsec/codecs/slin_gsm_ex.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*! \file
- * \brief Signed 16-bit audio data
- *
- * Source: gsm.example
- *
- * Copyright (C) 1999-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short slin_gsm_ex[] = {
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 0xfff8, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 0x0008, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-0x0008, 000000, 000000, 000000, 0xfff8, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 0x0008, 000000, 000000, 000000 };
diff --git a/1.2-netsec/codecs/slin_ilbc_ex.h b/1.2-netsec/codecs/slin_ilbc_ex.h
deleted file mode 100644
index b89655c6b..000000000
--- a/1.2-netsec/codecs/slin_ilbc_ex.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*! \file
- * \brief Signed 16-bit audio data
- *
- * Source: gsm.example
- *
- * Copyright (C) 1999-2005, Digium Inc
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short slin_ilbc_ex[] = {
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 0xfff8, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 0x0008, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-0x0008, 000000, 000000, 000000, 0xfff8, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 0x0008, 000000, 000000, 000000 };
diff --git a/1.2-netsec/codecs/slin_lpc10_ex.h b/1.2-netsec/codecs/slin_lpc10_ex.h
deleted file mode 100644
index 169e9a9e1..000000000
--- a/1.2-netsec/codecs/slin_lpc10_ex.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*! \file
- * \brief Signed 16-bit audio data
- *
- * Source: example.slin
- *
- * Copyright (C) 1999-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short slin_lpc10_ex[] = {
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000,
-000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000, 000000 };
diff --git a/1.2-netsec/codecs/slin_speex_ex.h b/1.2-netsec/codecs/slin_speex_ex.h
deleted file mode 100644
index 0c6258c37..000000000
--- a/1.2-netsec/codecs/slin_speex_ex.h
+++ /dev/null
@@ -1,262 +0,0 @@
-/*! \file
- * \brief Signed 16-bit audio data, 500ms of speech at 8kHz to ensure no DTX triggered
- *
- * Source: speex.example
- *
- * Copyright (C) 1999-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short slin_speex_ex[] = {
-0x4a00, 0xa700, 0x6d00, 0x4900, 0x5800, 0x3e00, 0x1b00, 0x1400, 0xf9ff, 0xe4ff, 0x0a00, 0xf0ff, 0xbbff, 0x0200, 0x0800, 0xd6ff,
-0xf1ff, 0x1200, 0x0500, 0x1000, 0x0f00, 0x0700, 0x4100, 0x2800, 0xf4ff, 0x2900, 0x3100, 0xf4ff, 0xefff, 0xdaff, 0xdaff, 0xc2ff,
-0xa5ff, 0xccff, 0xd4ff, 0xc7ff, 0xe6ff, 0x0600, 0x0c00, 0x1900, 0x1200, 0x0d00, 0x2900, 0x1e00, 0xf4ff, 0x0000, 0x1200, 0xf5ff,
-0xe5ff, 0x0000, 0x0000, 0xf1ff, 0x0300, 0x0b00, 0xfdff, 0x0500, 0x0f00, 0x0600, 0x0d00, 0x0f00, 0x0000, 0xfdff, 0xfcff, 0xe5ff,
-0xdcff, 0xe0ff, 0xafff, 0xb2ff, 0xe4ff, 0xceff, 0xe2ff, 0x0000, 0x1600, 0x2600, 0x2400, 0x3f00, 0x4a00, 0x3d00, 0x2b00, 0x2f00,
-0x4300, 0x1000, 0x0300, 0x0700, 0xe9ff, 0xf3ff, 0xebff, 0xd9ff, 0xe5ff, 0xf9ff, 0xeeff, 0xe9ff, 0x0500, 0x0a00, 0x0300, 0x0800,
-0x1800, 0x1c00, 0x1000, 0x1300, 0x0d00, 0x0400, 0x0200, 0xf9ff, 0xe4ff, 0xe6ff, 0xe0ff, 0xd9ff, 0xecff, 0xf2ff, 0xe8ff, 0xfdff,
-0x1100, 0x0d00, 0x0b00, 0x1100, 0x1100, 0x1200, 0x0c00, 0x0400, 0x0900, 0x0d00, 0x0100, 0xfdff, 0x0000, 0xfdff, 0x0000, 0xffff,
-0xf5ff, 0xfcff, 0x0600, 0xfeff, 0x0000, 0x0300, 0x1300, 0x1700, 0x0300, 0x0700, 0xf0ff, 0xe1ff, 0xd7ff, 0xd1ff, 0xc6ff, 0xc2ff,
-0xf2ff, 0xf0ff, 0xecff, 0x0700, 0x3200, 0x2d00, 0x0400, 0x2200, 0x2900, 0x1900, 0x2400, 0x0500, 0x1900, 0x1f00, 0xfeff, 0x0d00,
-0x0600, 0xebff, 0xf5ff, 0x0600, 0xebff, 0xe3ff, 0x0c00, 0x0d00, 0xefff, 0x1100, 0x3a00, 0x0700, 0x1700, 0x2f00, 0xf7ff, 0x0700,
-0x2600, 0xd9ff, 0xb8ff, 0xeaff, 0xbeff, 0x9eff, 0xc7ff, 0xccff, 0xc4ff, 0xeeff, 0x0000, 0xfdff, 0x1200, 0x1d00, 0x3100, 0x3600,
-0x2d00, 0x3c00, 0x4700, 0x3000, 0x2000, 0x2300, 0x1800, 0x0900, 0xffff, 0xeaff, 0xe7ff, 0xe8ff, 0xd3ff, 0xc5ff, 0xe1ff, 0xedff,
-0xe4ff, 0xfaff, 0xe3ff, 0xacff, 0xcdff, 0xd4ff, 0xabff, 0xa6ff, 0xdaff, 0x0500, 0xf1ff, 0xfaff, 0x3800, 0x7000, 0x4100, 0x1c00,
-0x4b00, 0x5300, 0x3a00, 0x2a00, 0x1400, 0x2000, 0x1c00, 0x1500, 0x0500, 0xf6ff, 0x0000, 0x1300, 0xfaff, 0xe9ff, 0x0000, 0x0a00,
-0xfcff, 0xfaff, 0x1000, 0x1200, 0x0900, 0x0c00, 0x0400, 0x0000, 0x0800, 0xffff, 0xe7ff, 0xe2ff, 0xe6ff, 0xd5ff, 0xdaff, 0xe0ff,
-0xdcff, 0xeeff, 0x0200, 0xfbff, 0x0000, 0x1000, 0x1100, 0x1500, 0x1900, 0x1400, 0x1900, 0x1c00, 0x1500, 0x1000, 0x0d00, 0x0b00,
-0x0700, 0x0200, 0xf6ff, 0xf5ff, 0xf9ff, 0xecff, 0xe8ff, 0xeeff, 0xf4ff, 0xf4ff, 0xeeff, 0xecff, 0xebff, 0xd7ff, 0xd8ff, 0xeaff,
-0xe0ff, 0xddff, 0x0100, 0x0500, 0xf8ff, 0x1800, 0x2d00, 0x1d00, 0x1a00, 0x2100, 0x1f00, 0x1f00, 0x1a00, 0x0f00, 0x0300, 0x0d00,
-0x0e00, 0xfeff, 0x0000, 0xfeff, 0x0000, 0x0000, 0xf1ff, 0xfaff, 0x0a00, 0x0100, 0xf5ff, 0x0300, 0x0e00, 0x0300, 0x0200, 0x0000,
-0x0800, 0x0700, 0xf8ff, 0xf5ff, 0xf1ff, 0xefff, 0xe9ff, 0xe0ff, 0xe0ff, 0xedff, 0xf0ff, 0xedff, 0xfcff, 0xffff, 0xfdff, 0x0a00,
-0x0f00, 0x0e00, 0x0f00, 0x1700, 0x1400, 0x0700, 0x0500, 0x0800, 0x0000, 0x0200, 0x0400, 0xfaff, 0xffff, 0x0200, 0xfaff, 0xfbff,
-0x0300, 0x0400, 0x0400, 0x0100, 0xe7ff, 0xd4ff, 0xdbff, 0xe2ff, 0xe0ff, 0xd0ff, 0xe7ff, 0x0700, 0xf2ff, 0x0000, 0x2d00, 0x2000,
-0x1800, 0x2c00, 0x1f00, 0x2600, 0x2200, 0x0e00, 0x0e00, 0x0000, 0x0400, 0x0800, 0x0300, 0xfbff, 0x0500, 0x1d00, 0x0000, 0xfbff,
-0x2e00, 0x2500, 0x0600, 0x1c00, 0x2600, 0x1600, 0x0e00, 0x0200, 0xf9ff, 0x0000, 0xe1ff, 0xc0ff, 0xd5ff, 0xc9ff, 0xb6ff, 0xbcff,
-0xccff, 0xc9ff, 0xcbff, 0xe5ff, 0xeaff, 0xf0ff, 0xfeff, 0x0000, 0x0b00, 0x1f00, 0x2000, 0x1b00, 0x2000, 0x2400, 0x1800, 0x1200,
-0x1700, 0x0c00, 0x0b00, 0x0d00, 0xfdff, 0xf5ff, 0x0000, 0xf9ff, 0xefff, 0xfaff, 0xf7ff, 0xf0ff, 0xe7ff, 0xcbff, 0xd1ff, 0xedff,
-0xf5ff, 0xfcff, 0xfeff, 0x1e00, 0x3200, 0x2200, 0x3800, 0x4f00, 0x3800, 0x2c00, 0x4000, 0x3e00, 0x2e00, 0x2900, 0x1200, 0x0500,
-0x0700, 0x0000, 0xf2ff, 0xf2ff, 0xf8ff, 0xf5ff, 0xf7ff, 0xeaff, 0xefff, 0x0100, 0xfcff, 0xf9ff, 0x0000, 0x0700, 0xf9ff, 0xf2ff,
-0xf9ff, 0xf0ff, 0xf1ff, 0xe7ff, 0xddff, 0xe1ff, 0xddff, 0xd9ff, 0xdaff, 0xe1ff, 0xe2ff, 0xe5ff, 0xe5ff, 0xf0ff, 0xfaff, 0xf4ff,
-0xfdff, 0x1100, 0x0e00, 0x0e00, 0x1800, 0x1600, 0x1200, 0x1400, 0x1500, 0x1200, 0x0b00, 0x0600, 0x0c00, 0x0500, 0x0100, 0x0b00,
-0x0200, 0xfaff, 0xffff, 0xf9ff, 0xe8ff, 0xd0ff, 0xc9ff, 0xd5ff, 0xe0ff, 0xe6ff, 0xedff, 0xf5ff, 0x1100, 0x1300, 0x1f00, 0x3600,
-0x2900, 0x2200, 0x2c00, 0x3700, 0x2d00, 0x2000, 0x1a00, 0x0800, 0xfaff, 0xfcff, 0xf6ff, 0xf2ff, 0xebff, 0xf7ff, 0x0200, 0xf1ff,
-0xf5ff, 0x0d00, 0x0900, 0xf9ff, 0x1000, 0x2000, 0x0a00, 0xf9ff, 0xffff, 0xf9ff, 0xf2ff, 0xeeff, 0xdbff, 0xd8ff, 0xdbff, 0xdaff,
-0xdaff, 0xdfff, 0xe6ff, 0xecff, 0xedff, 0xf0ff, 0x0500, 0x0900, 0x0400, 0x0f00, 0x2600, 0x2700, 0x2200, 0x2b00, 0x1700, 0x1100,
-0x2a00, 0x2200, 0x0c00, 0x0200, 0x0100, 0x0200, 0xfeff, 0xfaff, 0xf7ff, 0xf3ff, 0xf1ff, 0xf5ff, 0xf6ff, 0xe8ff, 0xd3ff, 0xcdff,
-0xdbff, 0xebff, 0xedff, 0xf0ff, 0xfbff, 0x1400, 0x1700, 0x2000, 0x3400, 0x2700, 0x1a00, 0x2100, 0x2e00, 0x2900, 0x1e00, 0x0c00,
-0xfbff, 0xfbff, 0xf9ff, 0xf3ff, 0xf4ff, 0xe8ff, 0xecff, 0x0300, 0xf8ff, 0xf4ff, 0x0100, 0x0600, 0xf7ff, 0x0900, 0x1e00, 0x0f00,
-0x0900, 0x0700, 0x0000, 0x0000, 0x0000, 0xf5ff, 0xebff, 0xefff, 0xf3ff, 0xeeff, 0xf0ff, 0xf1ff, 0xefff, 0xf0ff, 0xf6ff, 0xfcff,
-0xf9ff, 0xf8ff, 0xfbff, 0x0300, 0x0900, 0x0800, 0x0900, 0x0100, 0x0200, 0x0c00, 0x0e00, 0x0300, 0xfdff, 0xfcff, 0xfbff, 0xfbff,
-0xf9ff, 0xf3ff, 0xf3ff, 0xecff, 0xf6ff, 0xfbff, 0xf4ff, 0xecff, 0xd6ff, 0xdcff, 0xf1ff, 0xf1ff, 0xeeff, 0xf6ff, 0x0600, 0x0a00,
-0x1000, 0x1e00, 0x1b00, 0x1100, 0x1800, 0x2800, 0x2500, 0x2600, 0x1c00, 0x0e00, 0x0900, 0x0e00, 0x0800, 0x0200, 0xfaff, 0xf5ff,
-0x0300, 0xf8ff, 0xfcff, 0x0500, 0x0500, 0x0000, 0xfaff, 0x0b00, 0x1c00, 0x0d00, 0xfdff, 0x0200, 0x0100, 0xfbff, 0xf5ff, 0xe8ff,
-0xe8ff, 0xecff, 0xdaff, 0xd1ff, 0xddff, 0xdeff, 0xd8ff, 0xdeff, 0xedff, 0xf3ff, 0xf8ff, 0x0100, 0x1100, 0x2300, 0x2800, 0x3100,
-0x3200, 0x3500, 0x3a00, 0x3e00, 0x3400, 0x2700, 0x2100, 0x1400, 0x0900, 0xf7ff, 0xfaff, 0xf3ff, 0xe2ff, 0xeaff, 0xe3ff, 0xdfff,
-0xd7ff, 0xc9ff, 0xdaff, 0xe4ff, 0xe0ff, 0xe4ff, 0xefff, 0xf4ff, 0xf6ff, 0x0000, 0x0100, 0x0000, 0x0600, 0x0c00, 0x0c00, 0x1000,
-0x1900, 0x1600, 0x1500, 0x1600, 0x1100, 0x1400, 0x1200, 0x1300, 0x0900, 0x0d00, 0x1400, 0x0e00, 0x1900, 0x1400, 0x0900, 0x0600,
-0x1600, 0x1900, 0x0800, 0x0300, 0x0000, 0xf5ff, 0xedff, 0xeaff, 0xdbff, 0xdcff, 0xcbff, 0xb7ff, 0xbfff, 0xc3ff, 0xc2ff, 0xbfff,
-0xcbff, 0xdaff, 0xe7ff, 0xf9ff, 0x0600, 0x1b00, 0x2c00, 0x2900, 0x3d00, 0x4b00, 0x4700, 0x4b00, 0x4a00, 0x4300, 0x3700, 0x3300,
-0x1f00, 0x1400, 0x1000, 0x0f00, 0x0c00, 0x0000, 0xf6ff, 0xe7ff, 0xe7ff, 0xdeff, 0xd3ff, 0xe1ff, 0xdeff, 0xd9ff, 0xe0ff, 0xe8ff,
-0xf1ff, 0xeaff, 0xe8ff, 0xf5ff, 0xf7ff, 0xf6ff, 0xf7ff, 0xf4ff, 0xf8ff, 0xfcff, 0x0100, 0xfcff, 0xf7ff, 0x0100, 0x0600, 0x0100,
-0x0700, 0x0200, 0x0c00, 0x1000, 0x0e00, 0x1c00, 0x1a00, 0x1a00, 0x1800, 0x2200, 0x1f00, 0x1600, 0x1700, 0x0b00, 0xfbff, 0xfcff,
-0xeaff, 0xd6ff, 0xdfff, 0xcbff, 0xc0ff, 0xc0ff, 0xbcff, 0xc1ff, 0xc5ff, 0xd1ff, 0xdaff, 0xecff, 0xffff, 0xfeff, 0x1000, 0x2700,
-0x2400, 0x2400, 0x3800, 0x3600, 0x3100, 0x3300, 0x2800, 0x2000, 0x1e00, 0x1d00, 0x0800, 0x0400, 0x1600, 0x0900, 0x0000, 0x0d00,
-0x0100, 0xefff, 0xf1ff, 0xedff, 0xe0ff, 0xe6ff, 0xf5ff, 0xe1ff, 0xdaff, 0xf3ff, 0xf6ff, 0xeeff, 0xf1ff, 0xf9ff, 0xfbff, 0x0000,
-0x0700, 0x0900, 0x0d00, 0x1c00, 0x1d00, 0x1b00, 0x1a00, 0x2500, 0x2500, 0x1a00, 0x1600, 0x0e00, 0x0c00, 0x0b00, 0x0500, 0x0100,
-0x0200, 0x0000, 0xfbff, 0xfcff, 0xfdff, 0xfcff, 0xfcff, 0xf9ff, 0xf6ff, 0xf3ff, 0xeaff, 0xe6ff, 0xecff, 0xe8ff, 0xdfff, 0xe6ff,
-0xddff, 0xdaff, 0xecff, 0xefff, 0xf2ff, 0xfdff, 0x0100, 0xffff, 0x0800, 0x1700, 0x1000, 0x1300, 0x2100, 0x1b00, 0x1800, 0x1a00,
-0x1200, 0x1000, 0x2000, 0x1100, 0x0000, 0x0700, 0x0500, 0xfdff, 0xfcff, 0x0300, 0xf2ff, 0xeaff, 0xe1ff, 0xcdff, 0xd2ff, 0xe0ff,
-0xe0ff, 0xd5ff, 0xdfff, 0xf3ff, 0xf7ff, 0xfcff, 0x1100, 0x1800, 0x1900, 0x2100, 0x2600, 0x2800, 0x2900, 0x2d00, 0x2400, 0x1b00,
-0x1a00, 0x1000, 0x0800, 0x0500, 0xfcff, 0xf1ff, 0xf4ff, 0xf6ff, 0xf2ff, 0xf6ff, 0xffff, 0xffff, 0x0000, 0x0a00, 0x0a00, 0xfbff,
-0x0200, 0x0700, 0xf9ff, 0xf2ff, 0xeaff, 0xedff, 0xdfff, 0xd9ff, 0xe3ff, 0xd8ff, 0xdbff, 0xddff, 0xe2ff, 0xefff, 0xf6ff, 0xffff,
-0x0000, 0x0d00, 0x1500, 0x1600, 0x2200, 0x2800, 0x2700, 0x2900, 0x3700, 0x2d00, 0x2500, 0x2c00, 0x2900, 0x1100, 0x0600, 0xfdff,
-0xedff, 0xeaff, 0xddff, 0xcfff, 0xc9ff, 0xc0ff, 0xa8ff, 0xa8ff, 0xbeff, 0xceff, 0xd6ff, 0xe1ff, 0xf4ff, 0x1000, 0x1100, 0x1e00,
-0x3e00, 0x3c00, 0x3c00, 0x3d00, 0x3e00, 0x3300, 0x3000, 0x2b00, 0x1300, 0x0b00, 0x0600, 0xfaff, 0xf6ff, 0xf4ff, 0xe9ff, 0xedff,
-0x0000, 0xf8ff, 0xfbff, 0x0400, 0x0300, 0x0a00, 0x1400, 0x1300, 0x0100, 0x0b00, 0x0400, 0xf9ff, 0xf8ff, 0xeeff, 0xe9ff, 0xdeff,
-0xe1ff, 0xdaff, 0xd7ff, 0xe5ff, 0xd2ff, 0xd3ff, 0xe3ff, 0xe7ff, 0xedff, 0xf5ff, 0x0000, 0x0600, 0x1300, 0x1f00, 0x1c00, 0x2600,
-0x2b00, 0x3100, 0x2d00, 0x3100, 0x2e00, 0x2600, 0x1900, 0x1100, 0x0400, 0xf3ff, 0xf3ff, 0xdcff, 0xdbff, 0xddff, 0xd2ff, 0xccff,
-0xbbff, 0xc3ff, 0xe4ff, 0xf4ff, 0xf6ff, 0xfbff, 0x1600, 0x2100, 0x1600, 0x2000, 0x2500, 0x1b00, 0x2700, 0x2100, 0x1400, 0x0d00,
-0x1300, 0x0800, 0xfbff, 0xf8ff, 0xecff, 0xeeff, 0x0000, 0xefff, 0xeeff, 0xfcff, 0x0000, 0xfeff, 0x0600, 0x0700, 0x0200, 0x1400,
-0x1600, 0x0700, 0x0d00, 0x1400, 0x0e00, 0x0900, 0x0b00, 0x0500, 0xfaff, 0x0600, 0x0000, 0xf2ff, 0xfaff, 0xf6ff, 0xe9ff, 0xecff,
-0xecff, 0xe2ff, 0xe7ff, 0xf3ff, 0xf6ff, 0xf4ff, 0x0000, 0x0000, 0xffff, 0x1400, 0x0f00, 0x0f00, 0x1500, 0x1400, 0x1100, 0x1200,
-0x0c00, 0x0400, 0x0500, 0xffff, 0x0200, 0xfbff, 0xf5ff, 0xfeff, 0xf5ff, 0xe5ff, 0xe3ff, 0xe4ff, 0xe6ff, 0x0a00, 0xffff, 0xf3ff,
-0x0900, 0x0d00, 0xfbff, 0x0700, 0x0c00, 0xffff, 0x1200, 0x1e00, 0xfdff, 0x0700, 0x1c00, 0x1200, 0x0f00, 0x1200, 0x1500, 0xfbff,
-0x1200, 0x2300, 0xf9ff, 0x0300, 0x0d00, 0xf2ff, 0xf2ff, 0xf5ff, 0xd8ff, 0xd0ff, 0xddff, 0xd8ff, 0xc4ff, 0xdbff, 0xe0ff, 0xd6ff,
-0xecff, 0xd8ff, 0xf7ff, 0x1100, 0xffff, 0x1500, 0x2a00, 0x1c00, 0x1800, 0x2200, 0x1500, 0x0800, 0x1d00, 0x1600, 0x0800, 0x1300,
-0x0500, 0xecff, 0x1100, 0x0a00, 0x1700, 0x0900, 0xffff, 0x2700, 0x1b00, 0x0b00, 0x1400, 0x1200, 0xecff, 0x1000, 0x1800, 0xdfff,
-0xfbff, 0xf1ff, 0x9bff, 0x90ff, 0x97ff, 0x81ff, 0xf2ff, 0xf9ff, 0x8cff, 0xcbff, 0x3300, 0x0200, 0x1300, 0x4f00, 0x1600, 0x2700,
-0x7400, 0x4000, 0x2a00, 0x4e00, 0x4b00, 0x1800, 0x2b00, 0x3900, 0x1c00, 0x2500, 0x1000, 0xf1ff, 0xf9ff, 0xf5ff, 0xdbff, 0xdbff,
-0x0000, 0x0b00, 0xd7ff, 0xcbff, 0xecff, 0xdfff, 0xebff, 0xe5ff, 0xafff, 0xdfff, 0xe5ff, 0xbeff, 0xc9ff, 0x0000, 0xe0ff, 0xcdff,
-0x1d00, 0x1b00, 0xefff, 0x1c00, 0x2100, 0x1100, 0x3200, 0x3400, 0x1d00, 0x2d00, 0x2600, 0x3b00, 0x3600, 0x4200, 0x0a00, 0x0000,
-0x5f00, 0x4000, 0x0000, 0x1000, 0x2800, 0xeaff, 0xd9ff, 0xcdff, 0xf8ff, 0x8400, 0xc1ff, 0xbefe, 0x56ff, 0x7fff, 0xe5fe, 0xf5ff,
-0x3600, 0x4aff, 0x24ff, 0x6800, 0xdf00, 0x1600, 0x6d00, 0x7b00, 0xf200, 0xd500, 0x0700, 0x2300, 0x3500, 0x0600, 0xeaff, 0xd1ff,
-0x95ff, 0xd5ff, 0x0300, 0xbcff, 0xe0ff, 0x0000, 0x2500, 0x3100, 0xdf00, 0x6700, 0x0300, 0x6900, 0x2a00, 0x3f00, 0x0400, 0x7dff,
-0x58ff, 0xb2ff, 0x7bff, 0x71ff, 0xa1ff, 0x7dff, 0xd0ff, 0x1700, 0x0000, 0x0700, 0x5900, 0x4b00, 0x4b00, 0x4700, 0xf8ff, 0x4300,
-0x5e00, 0x0d00, 0xdaff, 0x1300, 0x0e00, 0x0f00, 0x2d00, 0xeaff, 0x1400, 0x6200, 0x3a00, 0xe3ff, 0x0c00, 0x1600, 0xfbff, 0xe8ff,
-0xfbff, 0x6700, 0xe3ff, 0x8eff, 0xf2fe, 0x25fe, 0x9bfe, 0x54ff, 0x94ff, 0x94ff, 0x7dff, 0x3000, 0x9401, 0xce01, 0x5601, 0x0e01,
-0xd300, 0x4f01, 0xdf00, 0x6fff, 0x25ff, 0x79ff, 0x5eff, 0x51ff, 0xd4ff, 0xbaff, 0x1b00, 0xbe00, 0x4a00, 0xf3ff, 0x2800, 0x4500,
-0x5e00, 0x1800, 0x84ff, 0x8aff, 0xc7ff, 0xc2ff, 0x8aff, 0xd7fe, 0x16ff, 0x0000, 0x1300, 0xf7ff, 0xbcff, 0xc3ff, 0x5500, 0x7c00,
-0x5a00, 0x5400, 0x2d00, 0x2d00, 0x2b00, 0xf9ff, 0xfcff, 0x0500, 0xddff, 0x1d00, 0x6600, 0x7a00, 0x9200, 0x3700, 0x0e00, 0x5600,
-0x2500, 0xcfff, 0xfdff, 0xe3ff, 0xc5ff, 0xcdff, 0x00ff, 0x67ff, 0xb100, 0x3200, 0x3200, 0xc800, 0xcdff, 0xaaff, 0x4dff, 0x42fd,
-0xc4fd, 0x3500, 0x2a00, 0x99ff, 0x1d00, 0xe500, 0x4e02, 0xf802, 0x6f01, 0xd4ff, 0x4f00, 0x7300, 0x88ff, 0x20ff, 0x81fe, 0x9afe,
-0xb2ff, 0x6800, 0x9100, 0x9700, 0x3001, 0x5500, 0xf4ff, 0xa400, 0xb2ff, 0xdeff, 0x1500, 0x05ff, 0x4fff, 0xe6ff, 0xaaff, 0xc9ff,
-0x0000, 0xafff, 0xeeff, 0x8200, 0x1800, 0xc7ff, 0xf1ff, 0xd5ff, 0x3000, 0x1d00, 0x50ff, 0x89ff, 0x82ff, 0x7cff, 0x2000, 0x1d00,
-0x0d00, 0x9500, 0x8c00, 0x2d00, 0x5b00, 0x2200, 0xf8ff, 0x6700, 0x7800, 0x3e00, 0xa800, 0x9100, 0xbfff, 0xccff, 0xdaff, 0x9bff,
-0x8400, 0x98ff, 0xa4fe, 0xddff, 0x1200, 0x2e00, 0xf100, 0x3500, 0x73ff, 0x99ff, 0xd1fd, 0x97fd, 0x0500, 0x7800, 0x3400, 0xc700,
-0xfc00, 0x8201, 0x6002, 0x8201, 0xb5ff, 0xaeff, 0xa5ff, 0x15ff, 0x90ff, 0x53ff, 0xccfe, 0x8eff, 0x9d00, 0xef00, 0x0601, 0xf300,
-0xa4ff, 0x5cff, 0x0b00, 0xfcff, 0x0d00, 0xd9ff, 0x3cff, 0x60ff, 0x5400, 0x3400, 0x2b00, 0x4800, 0xbbff, 0x0300, 0x5a00, 0xf5ff,
-0xc7ff, 0xe5ff, 0x91ff, 0xfeff, 0x0000, 0x51ff, 0xa8ff, 0x57ff, 0x74ff, 0x3a00, 0x6500, 0x5400, 0x0e00, 0x2900, 0x3800, 0x3d00,
-0x3300, 0x1100, 0x4400, 0x7200, 0x5c00, 0x6f00, 0x4c00, 0xc8ff, 0xa6ff, 0xc4ff, 0x9bff, 0x6a00, 0x1000, 0xccfe, 0xc6ff, 0x7e00,
-0x8aff, 0x6b00, 0xae00, 0x7bff, 0x71ff, 0xa0fd, 0x05fd, 0xc5ff, 0x5001, 0x1801, 0x9a01, 0x3f01, 0x1701, 0xc102, 0xd901, 0x83ff,
-0x35ff, 0xa7fe, 0x52fe, 0x98ff, 0x9eff, 0xcbfe, 0x90ff, 0xe100, 0x4801, 0xa001, 0x5101, 0x59ff, 0x04ff, 0xc3ff, 0x1800, 0x4400,
-0xe7ff, 0x22ff, 0x1dff, 0x4000, 0x2c00, 0x4b00, 0x7800, 0xa3ff, 0xd9ff, 0x7b00, 0x1a00, 0xb7ff, 0xb4ff, 0x70ff, 0xb6ff, 0x2200,
-0xc9ff, 0x35ff, 0xaeff, 0x2b00, 0x4700, 0x5100, 0xe6ff, 0x1100, 0x5900, 0x0500, 0xf0ff, 0x2300, 0x5b00, 0xbd00, 0xec00, 0xc500,
-0x8200, 0x93ff, 0x39ff, 0xafff, 0xbfff, 0x5200, 0x9cff, 0x49fe, 0x7fff, 0xa600, 0xfcff, 0xaa00, 0x7000, 0xf8fe, 0x64fe, 0xf7fc,
-0x73fd, 0x2100, 0xa001, 0xe501, 0x4a02, 0x3701, 0xe500, 0x7402, 0x6601, 0xb5ff, 0x5eff, 0x69fe, 0x40fe, 0xc8ff, 0xe6ff, 0x1cff,
-0xd1ff, 0xc900, 0x6601, 0xdf01, 0xf300, 0x67ff, 0xdcfe, 0x50ff, 0x2500, 0x7400, 0x0900, 0x42ff, 0x32ff, 0xe2ff, 0x2e00, 0x8700,
-0x2800, 0x84ff, 0xd4ff, 0x5a00, 0x1000, 0xc1ff, 0xafff, 0x62ff, 0xa7ff, 0x2700, 0x1100, 0xc5ff, 0xe2ff, 0xeeff, 0xb8ff, 0x3200,
-0x8b00, 0x0d00, 0x2600, 0x7b00, 0xf4ff, 0x6dff, 0x3d00, 0x9600, 0x8800, 0x2201, 0xa500, 0xf1ff, 0xe7ff, 0x9fff, 0x70ff, 0xe9ff,
-0x3a00, 0x5fff, 0xe8fe, 0x52ff, 0x0f00, 0x8e00, 0xb300, 0x3800, 0x1aff, 0x77fe, 0x13fd, 0x9afc, 0x6dff, 0xe301, 0x5602, 0x9902,
-0x3b01, 0xa6ff, 0x1501, 0x1a02, 0xa300, 0xebff, 0x1aff, 0xe6fd, 0x09ff, 0x6700, 0x5800, 0xefff, 0x4500, 0xd100, 0x6601, 0x5301,
-0x5600, 0x0eff, 0x9dfe, 0x91ff, 0x2400, 0x8500, 0xd7ff, 0xeffe, 0x39ff, 0xddff, 0x8c00, 0xa500, 0x0c00, 0x86ff, 0xd0ff, 0x2f00,
-0x1200, 0xf1ff, 0xbfff, 0x88ff, 0xd1ff, 0x4900, 0x2100, 0xbcff, 0xb1ff, 0x9aff, 0xf1ff, 0x8300, 0x6400, 0x3b00, 0x3e00, 0x2400,
-0xa3ff, 0x0000, 0x8200, 0x4b00, 0xa800, 0xe600, 0x0300, 0x2cff, 0x82ff, 0x0b00, 0x4300, 0x5600, 0xa9ff, 0xcdfe, 0x15ff, 0x6700,
-0xed00, 0x8a00, 0xe3ff, 0x74fe, 0xe3fc, 0xd1fc, 0x98fe, 0x2601, 0x7b02, 0x8d02, 0x8001, 0x3f00, 0xd300, 0x9501, 0xfe00, 0xeeff,
-0x50ff, 0x67fe, 0x81fe, 0xe8ff, 0x4900, 0x1200, 0x6800, 0xc000, 0xc200, 0x0c01, 0xb100, 0x7bff, 0x2fff, 0x91ff, 0xd6ff, 0xfeff,
-0xfeff, 0x63ff, 0x35ff, 0x0700, 0x7100, 0x6600, 0x4400, 0xceff, 0x9cff, 0x1100, 0x4500, 0xdfff, 0xabff, 0x96ff, 0x96ff, 0x1000,
-0x5b00, 0x0f00, 0xc2ff, 0xe3ff, 0xfdff, 0x3a00, 0x9000, 0x4c00, 0x1400, 0xe6ff, 0xe2ff, 0xc0ff, 0xf3ff, 0x4300, 0x1a00, 0x5100,
-0x7300, 0x3100, 0xc2ff, 0xebff, 0x5a00, 0x1e00, 0xafff, 0x3aff, 0x3cff, 0x80ff, 0x5a00, 0xf500, 0xffff, 0x57ff, 0x39ff, 0xe8fd,
-0x65fd, 0x65ff, 0x7d01, 0xfb01, 0x5b02, 0x7501, 0x9aff, 0x6000, 0x7701, 0x6b00, 0x94ff, 0x31ff, 0xe2fd, 0x85fe, 0x9300, 0xab00,
-0x4900, 0x9300, 0x5900, 0x3b00, 0x0701, 0x9000, 0x47ff, 0x4eff, 0x6cff, 0xedff, 0x5c00, 0x0000, 0x33ff, 0x81ff, 0x6200, 0x7400,
-0x9b00, 0x3400, 0x67ff, 0x94ff, 0x3100, 0x2800, 0xfeff, 0xfdff, 0xa3ff, 0x9fff, 0x2100, 0x2400, 0xebff, 0xf5ff, 0xe4ff, 0xe0ff,
-0x3f00, 0x5100, 0x1600, 0x1a00, 0xe7ff, 0xe0ff, 0xd4ff, 0x0000, 0x1200, 0x0500, 0x5b00, 0xc200, 0x5000, 0xcbff, 0x3b00, 0xe5ff,
-0x9fff, 0xf0ff, 0xd4ff, 0x76ff, 0x40ff, 0x2200, 0x8c00, 0x0f00, 0x5700, 0x5fff, 0xdffc, 0xfbfc, 0xe8ff, 0xc501, 0xa202, 0xbc02,
-0x6300, 0x49ff, 0x0b01, 0x7001, 0x6f00, 0xe2ff, 0x72fe, 0x84fd, 0x7dff, 0xcc00, 0x7300, 0x7c00, 0x5e00, 0xf1ff, 0xa200, 0x2101,
-0xd4ff, 0x46ff, 0x5eff, 0x82ff, 0x4800, 0x7d00, 0xd2ff, 0x71ff, 0xe3ff, 0x1b00, 0x7b00, 0x5c00, 0xc4ff, 0x84ff, 0x76ff, 0xe5ff,
-0x2b00, 0x3500, 0x1500, 0xe2ff, 0x99ff, 0x73ff, 0x9bff, 0xc7ff, 0xc8ff, 0x0000, 0x2d00, 0x4100, 0x3400, 0x2600, 0xf1ff, 0xd6ff,
-0x0900, 0x1300, 0xe0ff, 0x5c00, 0xbc00, 0x4700, 0x2500, 0xd5ff, 0x5eff, 0xb5ff, 0x4800, 0x3200, 0x0a00, 0x5bff, 0x91ff, 0x9b00,
-0x7000, 0x6400, 0x0800, 0xa7fd, 0x41fc, 0x8dfe, 0x3c01, 0x0102, 0x4b03, 0x0002, 0x58ff, 0x8b00, 0xc401, 0xad00, 0x5c00, 0x7aff,
-0x8efd, 0x85fe, 0x5600, 0x4000, 0x5700, 0xd200, 0xa700, 0xd400, 0xbb01, 0x7500, 0x1bff, 0x11ff, 0x47ff, 0x0700, 0x7500, 0x3c00,
-0x67ff, 0x05ff, 0x91ff, 0x4300, 0x6700, 0x3300, 0x1200, 0x94ff, 0x8dff, 0x1e00, 0xd6ff, 0x98ff, 0xafff, 0x9bff, 0x55ff, 0x97ff,
-0xaeff, 0x86ff, 0xc1ff, 0x2f00, 0x5200, 0x7100, 0x7600, 0xfdff, 0x9fff, 0xc3ff, 0xe5ff, 0xd9ff, 0x1500, 0x7e00, 0x3c00, 0x8200,
-0x5900, 0x60ff, 0x8cff, 0x1e00, 0x3400, 0x4300, 0x3800, 0x1dff, 0xbffe, 0xd2ff, 0xcf00, 0xff00, 0x5c00, 0x36ff, 0xd4fd, 0x85fc,
-0x18fe, 0xa301, 0x2e02, 0xfc01, 0x9d02, 0xf400, 0x4400, 0xbf01, 0xea00, 0x40ff, 0x83ff, 0x05ff, 0x5afe, 0xc5ff, 0x5100, 0xa4ff,
-0x8f00, 0x8501, 0x2501, 0x2e01, 0xd300, 0x21ff, 0xe0fe, 0xd1ff, 0x0400, 0x5a00, 0xd2ff, 0x62ff, 0xcfff, 0xc0ff, 0xfbff, 0x2b00,
-0xf9ff, 0xd6ff, 0xf7ff, 0xfbff, 0xb7ff, 0xc6ff, 0x2eff, 0x52ff, 0x3900, 0x1500, 0xc2ff, 0xf0ff, 0xc6ff, 0xccff, 0x7f00, 0x9500,
-0x0200, 0x0b00, 0x0000, 0x98ff, 0xa3ff, 0xb9ff, 0xacff, 0x4600, 0x8a00, 0x9300, 0x1300, 0x94ff, 0xd4ff, 0x2a00, 0x1301, 0xce00,
-0x78ff, 0xa7fe, 0xa1fe, 0x76ff, 0xe200, 0xfe00, 0xecff, 0xadff, 0x6fff, 0xe4fd, 0x2afd, 0x51ff, 0x3f01, 0x8c01, 0x9202, 0xac01,
-0xf4ff, 0x0d01, 0x7601, 0x0800, 0xd5ff, 0xafff, 0x9cfe, 0x2dff, 0x2200, 0x85ff, 0xbdff, 0xd500, 0xc000, 0xd300, 0x2701, 0x0700,
-0x12ff, 0xb6ff, 0xf5ff, 0xebff, 0x7900, 0xc7ff, 0x4dff, 0x5c00, 0x9800, 0xf9ff, 0xa4ff, 0xa4ff, 0x6bff, 0xafff, 0x2a00, 0xceff,
-0xc2ff, 0xc6ff, 0xb9ff, 0x3600, 0x5a00, 0xdbff, 0xa1ff, 0xe1ff, 0x1500, 0x3e00, 0x5d00, 0x0400, 0xccff, 0x2000, 0x1900, 0xa7ff,
-0x77ff, 0x9dff, 0xfdff, 0x4a00, 0xcd00, 0x0300, 0x8bff, 0x0000, 0xf0ff, 0xa100, 0xbf00, 0xdaff, 0x04ff, 0x2aff, 0x76ff, 0xe1ff,
-0x8b00, 0x8100, 0x3700, 0x4700, 0x2fff, 0x1ffd, 0xd7fd, 0x6a00, 0x6c01, 0x9301, 0x9c01, 0x5900, 0x3c00, 0x9f01, 0x6201, 0xbfff,
-0x28ff, 0x69ff, 0x63ff, 0xf5ff, 0x0a00, 0x2cff, 0x91ff, 0x9e00, 0x1c01, 0x0d01, 0x7900, 0xa9ff, 0x3aff, 0x2b00, 0x3500, 0xc4ff,
-0xc5ff, 0x77ff, 0xb8ff, 0x9600, 0xaa00, 0xd4ff, 0x97ff, 0xdfff, 0xc3ff, 0x1a00, 0xf9ff, 0x65ff, 0x81ff, 0xa7ff, 0xd0ff, 0x2a00,
-0x0600, 0x0800, 0x2d00, 0xebff, 0x2000, 0x6d00, 0x6a00, 0x5900, 0x5700, 0x0c00, 0x85ff, 0x9bff, 0xe4ff, 0x0400, 0x4000, 0xd7ff,
-0x0f00, 0x1f00, 0xf2ff, 0xb800, 0x6c00, 0xacff, 0x59ff, 0x2eff, 0x5fff, 0x1f00, 0x5200, 0x1f00, 0x2700, 0x3e00, 0xcdfe, 0x09fd,
-0x87fd, 0x2300, 0x0802, 0x8401, 0x2f01, 0x7c00, 0x9c00, 0x0302, 0xb301, 0x8fff, 0xc2fe, 0x25ff, 0x0000, 0x6e00, 0xabff, 0xedfe,
-0x54ff, 0xa800, 0xa301, 0x4801, 0x1900, 0x8eff, 0xf2ff, 0x7000, 0x6c00, 0xc6ff, 0x02ff, 0x34ff, 0x0000, 0x6c00, 0x4f00, 0x55ff,
-0x65ff, 0x3c00, 0x4d00, 0x1d00, 0x81ff, 0x49ff, 0xaaff, 0x2300, 0x1600, 0xaaff, 0x92ff, 0xb7ff, 0x7100, 0x4900, 0xf8ff, 0x4900,
-0x5700, 0x9f00, 0xa100, 0x5b00, 0xb6ff, 0x8bff, 0x0700, 0x3300, 0x3e00, 0xa2ff, 0x99ff, 0x2e00, 0x1200, 0x9500, 0x9200, 0xceff,
-0x99ff, 0xa9ff, 0x77ff, 0x5fff, 0xc7ff, 0x1c00, 0x1b00, 0x5400, 0x9fff, 0xd8fd, 0xe8fc, 0xaefe, 0x7301, 0x8a01, 0xd700, 0x6b00,
-0x6600, 0xfa01, 0x9d02, 0x5e00, 0xddfe, 0x75ff, 0x1f00, 0x8500, 0x6dff, 0x3ffe, 0xc4fe, 0x7200, 0x5401, 0xe600, 0x2900, 0xd8ff,
-0x6900, 0xe800, 0x9400, 0xd8ff, 0x45ff, 0x6aff, 0xedff, 0xf4ff, 0xf3ff, 0x8cff, 0x7aff, 0x1e00, 0x3a00, 0xfcff, 0xc7ff, 0xbbff,
-0xd1ff, 0x1300, 0x1c00, 0xc1ff, 0xbfff, 0xd6ff, 0x1300, 0x5100, 0xf7ff, 0x77ff, 0xe4ff, 0x9000, 0xa400, 0x9a00, 0x5300, 0xacff,
-0xa5ff, 0x3a00, 0x3800, 0x0000, 0xe2ff, 0xe3ff, 0x4300, 0xc400, 0x5e00, 0x90ff, 0xb4ff, 0x3a00, 0xf6ff, 0x8eff, 0x86ff, 0xcbfe,
-0x49ff, 0xe400, 0x7f00, 0x5cff, 0x80fe, 0x61fd, 0x78fe, 0xf601, 0x4001, 0xabff, 0xc500, 0xe000, 0xf201, 0x0c03, 0x7e00, 0x6ffe,
-0xceff, 0x7100, 0xd0ff, 0x6dff, 0x5cfe, 0x4afe, 0x5800, 0x6d01, 0x0e00, 0xc7ff, 0x2e00, 0x2a00, 0xc800, 0xe500, 0x89ff, 0x3cff,
-0x5900, 0x1a00, 0xcfff, 0x0b00, 0x71ff, 0x87ff, 0x7000, 0x3100, 0x95ff, 0xe1ff, 0x0000, 0xe9ff, 0x4700, 0x0300, 0x7aff, 0xf1ff,
-0x3700, 0xc9ff, 0xfcff, 0x0000, 0xd0ff, 0x6800, 0x9500, 0xdfff, 0xfaff, 0xe7ff, 0xe9ff, 0x9600, 0x1700, 0xbbff, 0x0b00, 0x5300,
-0x9000, 0x9c00, 0x1900, 0x97ff, 0xd7ff, 0x6100, 0x2400, 0xbdfe, 0xe0fe, 0xb0ff, 0xb0ff, 0x6400, 0x5500, 0x0dff, 0xdafe, 0x38fe,
-0xe1fd, 0x6200, 0x3801, 0xeaff, 0xe200, 0xf901, 0xd901, 0x4802, 0x8001, 0x25ff, 0xd7ff, 0xfa00, 0x7bff, 0xc8fe, 0xe4fe, 0x76fe,
-0xb4ff, 0xa800, 0xd5ff, 0xa7ff, 0x4d00, 0x6d00, 0x6e00, 0xb600, 0xe3ff, 0xc3ff, 0x6600, 0x1b00, 0xa3ff, 0xc0ff, 0xbaff, 0x90ff,
-0x0a00, 0x1c00, 0x99ff, 0x0900, 0x5000, 0xd6ff, 0x0e00, 0x7400, 0x1f00, 0xf5ff, 0x0d00, 0xc3ff, 0xe6ff, 0x4400, 0xebff, 0x9dff,
-0xdfff, 0x5a00, 0x1c00, 0x80ff, 0xd4ff, 0x1f00, 0x1200, 0x4e00, 0x6f00, 0xd900, 0x7d00, 0x9aff, 0xdbff, 0x4000, 0x2300, 0xd1ff,
-0xa3ff, 0x89ff, 0x74ff, 0xbdff, 0xb5ff, 0xe8ff, 0x4900, 0x0b00, 0xc6ff, 0x5aff, 0x6dfe, 0xc6fe, 0x3400, 0x6700, 0x2300, 0x9500,
-0xa300, 0x2901, 0x0a02, 0xf200, 0x7fff, 0x3800, 0x7e00, 0xedff, 0xb8ff, 0x0fff, 0xeafe, 0xdeff, 0x4500, 0xdcff, 0xcaff, 0x0d00,
-0x3d00, 0x7b00, 0x7c00, 0xffff, 0xf5ff, 0x2600, 0x1500, 0xe2ff, 0xd8ff, 0xc6ff, 0xb8ff, 0xf7ff, 0xf6ff, 0xd4ff, 0xf7ff, 0x1300,
-0xf7ff, 0x0800, 0xf3ff, 0xbbff, 0xb5ff, 0xfcff, 0xcaff, 0xc4ff, 0xfcff, 0xd2ff, 0xfeff, 0x2500, 0x2000, 0x0400, 0x0000, 0x0200,
-0x1000, 0x1e00, 0x1900, 0x2a00, 0x1600, 0x2e00, 0x5500, 0x1b00, 0x1f00, 0x1200, 0x2600, 0x6600, 0x3700, 0xfbff, 0x2200, 0x1300,
-0xffff, 0xfbff, 0xcaff, 0x97ff, 0x9eff, 0x95ff, 0x9aff, 0xceff, 0xa2ff, 0x6fff, 0xabff, 0x0000, 0x2400, 0x0c00, 0xf2ff, 0x0f00,
-0x6100, 0x7500, 0x4200, 0xfeff, 0x1c00, 0x5a00, 0x4a00, 0x2300, 0x0b00, 0x0f00, 0x0900, 0x1900, 0xfcff, 0xe0ff, 0xfdff, 0x1200,
-0x1100, 0x1200, 0x1700, 0x1800, 0x1500, 0x1500, 0x0500, 0xf7ff, 0xf9ff, 0x0800, 0xffff, 0x0300, 0x0000, 0xccff, 0xdaff, 0x0200,
-0xe5ff, 0xa7ff, 0x9cff, 0xb4ff, 0xd0ff, 0xcaff, 0xdbff, 0xc9ff, 0xd3ff, 0x0a00, 0x0500, 0x0600, 0x1500, 0x1400, 0x2d00, 0x5900,
-0x3000, 0x0900, 0x1300, 0x0800, 0x2000, 0x3600, 0x0500, 0x0000, 0xf6ff, 0x0700, 0x1900, 0xf5ff, 0x1000, 0x1300, 0xcdff, 0xbdff,
-0xd7ff, 0xe0ff, 0xd6ff, 0xe6ff, 0xbfff, 0xdfff, 0x3500, 0x1700, 0x0000, 0x2900, 0x4c00, 0x4600, 0x4500, 0x4a00, 0x2100, 0x3c00,
-0x4000, 0x0a00, 0xeeff, 0xedff, 0xe6ff, 0xe1ff, 0xe0ff, 0xeeff, 0x0100, 0x0a00, 0x1300, 0x0900, 0x0500, 0x0c00, 0x0600, 0xf2ff,
-0xecff, 0xe1ff, 0xe3ff, 0xe2ff, 0xe6ff, 0xe6ff, 0xf8ff, 0x0500, 0x0200, 0x0800, 0xe2ff, 0xdfff, 0x0000, 0x0300, 0xffff, 0x0000,
-0x1200, 0x1300, 0x0600, 0x0c00, 0xfcff, 0x1200, 0x1000, 0xfcff, 0x0800, 0x0900, 0xfbff, 0xf6ff, 0xfeff, 0xfbff, 0xfeff, 0xf1ff,
-0xfbff, 0x0400, 0x0600, 0x1700, 0x2500, 0x0e00, 0xdbff, 0xb8ff, 0xc9ff, 0xcfff, 0xb2ff, 0xbeff, 0xcdff, 0xc7ff, 0xe2ff, 0x0500,
-0x2400, 0x1600, 0x2300, 0x3900, 0x4c00, 0x5400, 0x4200, 0x3a00, 0x3100, 0x3e00, 0x2e00, 0x0800, 0xf6ff, 0xf2ff, 0xf7ff, 0xfaff,
-0xf7ff, 0xf3ff, 0x0600, 0x0f00, 0x0300, 0xffff, 0xf9ff, 0xe6ff, 0x0a00, 0x1f00, 0x0a00, 0x0300, 0xf8ff, 0xecff, 0xf2ff, 0xfdff,
-0xccff, 0xbbff, 0xe5ff, 0xe6ff, 0xb3ff, 0xc7ff, 0x0000, 0xfaff, 0xf2ff, 0x0d00, 0x1000, 0x0e00, 0x2300, 0x1c00, 0x0f00, 0x1c00,
-0x1700, 0x0b00, 0x1000, 0x0c00, 0x0400, 0x0100, 0x0200, 0x0300, 0x0000, 0xfdff, 0x0300, 0x0500, 0x0700, 0x0a00, 0x0600, 0x0400,
-0x0100, 0xf5ff, 0xecff, 0xf2ff, 0xf5ff, 0xecff, 0x0200, 0xfdff, 0xe0ff, 0x0800, 0x1b00, 0x0300, 0x0000, 0x0700, 0x0500, 0x0400,
-0x0100, 0xf0ff, 0xefff, 0x0100, 0xfcff, 0xfaff, 0x0700, 0x0600, 0x0e00, 0x1500, 0x0800, 0x0500, 0x0d00, 0x1100, 0x0800, 0x0a00,
-0x0600, 0xf8ff, 0xfdff, 0x0400, 0x2200, 0x2800, 0x1500, 0x0f00, 0x1800, 0x0e00, 0xfcff, 0xf9ff, 0xefff, 0xe5ff, 0xc5ff, 0xb4ff,
-0xc3ff, 0xcfff, 0xcbff, 0xcdff, 0xe4ff, 0xf7ff, 0x0300, 0x1300, 0xffff, 0xf8ff, 0x0e00, 0x0900, 0xfeff, 0xfeff, 0xfeff, 0xfbff,
-0x0300, 0x0a00, 0x0a00, 0x0f00, 0x1100, 0x0d00, 0x0800, 0x0e00, 0x1600, 0x0d00, 0x0900, 0x0900, 0x0100, 0x0200, 0x0000, 0xebff,
-0xfbff, 0x0200, 0xdeff, 0xf8ff, 0x0c00, 0xf8ff, 0xefff, 0x0100, 0x0000, 0x0200, 0x0500, 0x0f00, 0x1900, 0x2400, 0x2d00, 0x1b00,
-0x1500, 0x1b00, 0x1e00, 0x1200, 0x0100, 0x0000, 0xfeff, 0x0200, 0x0400, 0xfeff, 0xfaff, 0x0200, 0x0b00, 0x1d00, 0x2e00, 0x0100,
-0xf7ff, 0x0d00, 0x0300, 0xf7ff, 0xfbff, 0xf5ff, 0xeaff, 0xe8ff, 0xc9ff, 0xccff, 0xe2ff, 0xe2ff, 0xdeff, 0xe5ff, 0xf0ff, 0xfaff,
-0x0900, 0x0700, 0xe8ff, 0xedff, 0x0300, 0xfdff, 0xf3ff, 0xf8ff, 0x0e00, 0x0b00, 0x1800, 0x1200, 0x0100, 0x0f00, 0x1300, 0x1100,
-0x0e00, 0x1700, 0x1500, 0x0800, 0x0500, 0xf1ff, 0xe5ff, 0xe3ff, 0xd9ff, 0xceff, 0xc6ff, 0xbeff, 0xe5ff, 0xf2ff, 0xebff, 0xf1ff,
-0x0200, 0xffff, 0x0900, 0x1000, 0x1000, 0x1300, 0x2a00, 0x3700, 0x2c00, 0x3000, 0x3000, 0x2300, 0x2100, 0x2500, 0x1d00, 0x1700,
-0x1b00, 0x1800, 0x1800, 0x1900, 0x0f00, 0x0a00, 0x1300, 0x1e00, 0x1600, 0x0f00, 0xffff, 0x0200, 0xf2ff, 0xe3ff, 0xdfff, 0xdbff,
-0xd5ff, 0xc2ff, 0xb8ff, 0xb3ff, 0xbaff, 0xc4ff, 0xc9ff, 0xd1ff, 0xe4ff, 0xfcff, 0xfbff, 0xfeff, 0x0c00, 0x0c00, 0x1300, 0x2200,
-0x2300, 0x2100, 0x2b00, 0x3700, 0x2c00, 0x2d00, 0x2d00, 0x2300, 0x2800, 0x2300, 0x1300, 0x1800, 0x1000, 0xedff, 0xe1ff, 0xd6ff,
-0xbcff, 0xb8ff, 0xb3ff, 0x98ff, 0x9bff, 0xb7ff, 0xcfff, 0xd6ff, 0xe5ff, 0xecff, 0xf5ff, 0x0000, 0x0600, 0x1600, 0x1100, 0x1a00,
-0x3100, 0x3700, 0x3800, 0x3700, 0x3b00, 0x3900, 0x3700, 0x3200, 0x3400, 0x3600, 0x2e00, 0x2800, 0x2700, 0x1e00, 0x1800, 0x1800,
-0x1000, 0x1400, 0x0900, 0xfcff, 0xf7ff, 0xf1ff, 0xe4ff, 0xd7ff, 0xd7ff, 0xd2ff, 0xc1ff, 0xc1ff, 0xc8ff, 0xc3ff, 0xc5ff, 0xd6ff,
-0xddff, 0xdfff, 0xf0ff, 0x0000, 0x0300, 0x0300, 0x0900, 0x0a00, 0x1700, 0x2200, 0x1700, 0x2000, 0x3100, 0x3200, 0x3300, 0x2e00,
-0x2800, 0x1d00, 0x2600, 0x2200, 0x1800, 0x1300, 0x0200, 0xf0ff, 0xd3ff, 0xc8ff, 0xc0ff, 0xbbff, 0xbbff, 0xb4ff, 0xaaff, 0xbaff,
-0xd7ff, 0xe9ff, 0xf2ff, 0xfcff, 0x0500, 0x1000, 0x1900, 0x1a00, 0x2100, 0x1b00, 0x1d00, 0x2a00, 0x1d00, 0x1000, 0x0b00, 0x0c00,
-0x0b00, 0x0600, 0x0100, 0x0400, 0x0900, 0x0900, 0x0600, 0x0500, 0x0800, 0x0f00, 0x1100, 0xfcff, 0x0900, 0x0c00, 0x0400, 0x0500,
-0x0000, 0xf8ff, 0xf3ff, 0xf7ff, 0xefff, 0xe7ff, 0xeeff, 0xf1ff, 0xf2ff, 0xf5ff, 0xfbff, 0xfdff, 0xffff, 0x0000, 0x0100, 0x0000,
-0xfeff, 0xffff, 0x0000, 0x0000, 0x0100, 0xffff, 0x0000, 0x0400, 0x0500, 0x0200, 0xffff, 0x0000, 0xfeff, 0xfcff, 0xfbff, 0xf7ff,
-0xf3ff, 0xf1ff, 0xf6ff, 0xf1ff, 0xf4ff, 0xf7ff, 0xfaff, 0xfeff, 0x0700, 0x0e00, 0x1300, 0x1e00, 0x2000, 0x2200, 0x2000, 0x2200,
-0x1d00, 0x1c00, 0x1d00, 0x1b00, 0x1600, 0x1b00, 0x1900, 0x1200, 0x0d00, 0x0a00, 0x0500, 0x0000, 0xebff, 0xddff, 0xe1ff, 0xe0ff,
-0xddff, 0xdcff, 0xdeff, 0xdeff, 0xe6ff, 0xebff, 0xeeff, 0xf4ff, 0xffff, 0x0100, 0x0a00, 0x0b00, 0x0100, 0x0600, 0x1600, 0x0e00,
-0x0a00, 0x1100, 0x1500, 0x1000, 0x1000, 0x0d00, 0x0b00, 0x0900, 0x0500, 0xfbff, 0xffff, 0x0200, 0x0000, 0x0100, 0x0100, 0x0200,
-0xfbff, 0x0000, 0xfaff, 0xf4ff, 0xedff, 0xedff, 0xe9ff, 0xe4ff, 0xe2ff, 0xdeff, 0xdbff, 0xe0ff, 0xe0ff, 0xe3ff, 0xe9ff, 0xf3ff,
-0xf7ff, 0x0700, 0x0b00, 0x0000, 0x0f00, 0x1b00, 0x1700, 0x1600, 0x2100, 0x2600, 0x2700, 0x2e00, 0x2600, 0x2300, 0x2000, 0x1800,
-0x0e00, 0x0b00, 0x0200, 0x0300, 0xf3ff, 0xe2ff, 0xe0ff, 0xe0ff, 0xe1ff, 0xdeff, 0xe3ff, 0xe4ff, 0xf2ff, 0xf1ff, 0xfcff, 0xf9ff,
-0xf8ff, 0x0000, 0x0300, 0x0900, 0x0a00, 0x0e00, 0x0300, 0x0600, 0x0400, 0x0400, 0x0100, 0x0200, 0x0000, 0x0000, 0xffff, 0xfcff,
-0x0100, 0x0100, 0x0300, 0x0400, 0x0800, 0x0500, 0x0500, 0x0000, 0xfaff, 0xffff, 0x0100, 0xfcff, 0xfeff, 0x0000, 0xfcff, 0xf6ff,
-0xf5ff, 0xf3ff, 0xf3ff, 0xf0ff, 0xf7ff, 0xfcff, 0x0100, 0x0e00, 0x1800, 0x1900, 0x1d00, 0x2800, 0x2400, 0x2000, 0x2400, 0x2000,
-0x1400, 0x0d00, 0x0000, 0xf9ff, 0xeeff, 0xe7ff, 0xe6ff, 0xe3ff, 0xe0ff, 0xdbff, 0xe6ff, 0xeeff, 0xf4ff, 0xfdff, 0xfeff, 0xffff,
-0x0000, 0x0400, 0x0000, 0x0500, 0x0500, 0x0900, 0x0500, 0x0600, 0x0c00, 0x0d00, 0x1200, 0x0c00, 0x0d00, 0x0a00, 0x0d00, 0x0b00,
-0x0500, 0x0100, 0x0100, 0xfeff, 0xfdff, 0xfaff, 0xfaff, 0xfaff, 0xfbff, 0xf9ff, 0xf8ff, 0xf8ff, 0xf7ff, 0xf8ff, 0xf6ff, 0xf3ff,
-0xf8ff, 0xf6ff, 0xf4ff, 0xf2ff, 0xf1ff, 0xefff, 0xf5ff, 0xf3ff, 0xf6ff, 0xfcff, 0xfdff, 0xfcff, 0xffff, 0x0100, 0x0000, 0x0000,
-0x0400, 0x1000, 0x1000, 0x1300, 0x1700, 0x1e00, 0x1400, 0x1200, 0x1400, 0x0e00, 0x1400, 0x1100, 0x0600, 0xfbff, 0xf3ff, 0xe9ff,
-0xebff, 0xe8ff, 0xe2ff, 0xe7ff, 0xebff, 0xf1ff, 0xf5ff, 0xfeff, 0x0100, 0xffff, 0xfaff, 0xfdff, 0xfeff, 0xfeff, 0xfeff, 0xffff,
-0x0900, 0x0c00, 0x1100, 0x1400, 0x1100, 0x1200, 0x0d00, 0x0b00, 0x0f00, 0x0f00, 0x0a00, 0x0600, 0xfeff, 0x0000, 0xfeff, 0xf9ff,
-0xfcff, 0xfaff, 0xf8ff, 0xfbff, 0xfeff, 0xf9ff, 0xfcff, 0xf7ff, 0xfbff, 0xf5ff, 0xfcff, 0x0900, 0x0000, 0x0a00, 0x0600, 0xfeff,
-0xfbff, 0x1700, 0x1000, 0x0800, 0x1100, 0x0800, 0xf2ff, 0x0400, 0x0300, 0x0000, 0x1d00, 0x1b00, 0x0b00, 0xf1ff, 0xd8ff, 0xddff,
-0xeeff, 0xdfff, 0xd0ff, 0xf0ff, 0xf3ff, 0xf4ff, 0x0300, 0x1000, 0xf9ff, 0xf3ff, 0x1000, 0x1e00, 0x0e00, 0xfdff, 0xfaff, 0xfdff,
-0x1100, 0xfeff, 0x1d00, 0x3100, 0x0300, 0xf8ff, 0x0c00, 0x1700, 0x1300, 0x0200, 0xfdff, 0x0900, 0x0800, 0xf8ff, 0xf9ff, 0xfaff,
-0xf3ff, 0x0400, 0xfcff, 0xf5ff, 0x0100, 0xfaff, 0xe3ff, 0xe4ff, 0xf8ff, 0x0000, 0x0300, 0xf1ff, 0xe1ff, 0x0000, 0xf7ff, 0xf4ff,
-0xefff, 0xdfff, 0x0900, 0x1600, 0xe0ff, 0xf5ff, 0x1500, 0x0900, 0xfdff, 0x0300, 0x1200, 0x1900, 0xffff, 0x0e00, 0x3e00, 0x3400,
-0xe3ff, 0xfbff, 0x2c00, 0xfdff, 0xe5ff, 0x0300, 0x0800, 0x0200, 0xe5ff, 0xe0ff, 0x0900, 0x1500, 0xdeff, 0xe1ff, 0xf8ff, 0xe0ff,
-0xddff, 0x1500, 0x1f00, 0xecff, 0x0c00, 0x6aff, 0x0700, 0x2600, 0xecfe, 0xac01, 0x8500, 0xa9fe, 0xa200, 0x6700, 0xb8ff, 0x8f00,
-0xf9ff, 0xa1ff, 0xd100, 0xc1fe, 0x8900, 0x4a01, 0x6dfe, 0xf9ff, 0x1301, 0xb1ff, 0xbaff, 0xac00, 0x1401, 0x7bfe, 0x16ff, 0x8e01,
-0x92ff, 0x03ff, 0x7202, 0xedff, 0x58fe, 0x6b00, 0x0300, 0xc6ff, 0x5600, 0xadff, 0xd5ff, 0xe800, 0x85ff, 0x16ff, 0xd000, 0x2600,
-0xacff, 0x3f00, 0x47fe, 0x6000, 0x3b02, 0xc1fe, 0x56fe, 0x3001, 0xc2ff, 0xfffe, 0xf4ff, 0x2400, 0x5000, 0x1f00, 0x38ff, 0x0200,
-0x6800, 0xc800, 0x45ff, 0xb1ff, 0xeb00, 0x0100, 0xaaff, 0x0f00, 0x7f00, 0x2400, 0x8d00, 0xa5ff, 0x0600, 0xa501, 0xa5ff, 0x67ff,
-0xb700, 0x0e00, 0xa6ff, 0xe1ff, 0x0c00, 0xf4ff, 0xf1ff, 0x29ff, 0x0cff, 0xb1ff, 0x2fff, 0xfffe, 0xe0ff, 0x1900, 0xe1ff, 0x1600,
-0x5b00, 0x6200, 0x7d00, 0x1f00, 0x1300, 0x6100, 0x4500, 0xf3ff, 0xb400, 0x7800, 0x5d00, 0x1600, 0x4500, 0x4700, 0x1200, 0x0a00,
-0xd5ff, 0x5a00, 0x3400, 0xf4ff, 0x3600, 0xbeff, 0xe1ff, 0x0300, 0xb6ff, 0xa5ff, 0xc2ff, 0x98ff, 0xc5ff, 0x2100, 0xdbff, 0x2d00,
-0x1400, 0xd4ff, 0x2e00, 0x0a00, 0xfaff, 0x0a00, 0x0300, 0xd9ff, 0xc3ff, 0x6600, 0x1d00, 0x80ff, 0x0700, 0x2300, 0x0eff, 0xacff,
-0x0500, 0xacff, 0x1400, 0x4600, 0x5000, 0x6400, 0xad00, 0x4900, 0x2c00, 0x7900, 0x3000, 0xc7ff, 0xbbff, 0x8cff, 0xa3ff, 0x5800,
-0xcfff, 0xddfe, 0x8fff, 0xc3ff, 0x78fe, 0x51ff, 0xceff, 0x62ff, 0x2b00, 0xbd00, 0x7300, 0xe000, 0x7901, 0x8900, 0x6e00, 0xf000,
-0x5100, 0xd5ff, 0xcfff, 0xacff, 0xe1ff, 0xc400, 0x71ff, 0xbffd, 0xacff, 0xfdff, 0x5dfe, 0x43ff, 0xa000, 0x9b00, 0xab00, 0x1f01,
-0x0b01, 0x7e01, 0x1f01, 0xddff, 0xfcff, 0x3200, 0x3fff, 0x16ff, 0x1500, 0xc7ff, 0xddfe, 0x64ff, 0xe6fe, 0x4efe, 0x26ff, 0x4dff,
-0x30ff, 0x2800, 0x2401, 0xe300, 0x6301, 0xdf01, 0xa801, 0xb001, 0x5701, 0xc500, 0x8100, 0x3600, 0xa7ff, 0xd6ff, 0x6100, 0x0eff,
-0x82fe, 0x9eff, 0xa8ff, 0x03ff, 0x97ff, 0x7300, 0x8200, 0x6600, 0x6000, 0x6700, 0x7c00, 0xdeff, 0x2fff, 0x57ff, 0x83ff, 0x26ff,
-0xf3fe, 0x37ff, 0x49ff, 0xe6fe, 0x04ff, 0x66ff, 0x8dff, 0xa6ff, 0x0100, 0x8300, 0xbc00, 0xf200, 0x2501, 0x6301, 0x6601, 0x2b01,
-0xed00, 0xbe00, 0x6400, 0x2400, 0x2f00, 0x0d00, 0xe0ff, 0xe5ff, 0xbeff, 0xc4ff, 0x0e00, 0x0600, 0xebff, 0xfbff, 0xd1ff, 0xa5ff,
-0x7eff, 0x48ff, 0x2dff, 0x35ff, 0x19ff, 0x62ff, 0x30ff, 0x40ff, 0xbfff, 0x6fff, 0x7eff, 0x0600, 0xe4ff, 0xbaff, 0x4000, 0xae00,
-0x8f00, 0x8500, 0xab00, 0xd500, 0xa900, 0x5800, 0x4d00, 0x4a00, 0x1f00, 0xe3ff, 0xd5ff, 0x0500, 0x0e00, 0x5eff, 0xbfff, 0x9500 };
diff --git a/1.2-netsec/codecs/slin_ulaw_ex.h b/1.2-netsec/codecs/slin_ulaw_ex.h
deleted file mode 100644
index 9af79eba2..000000000
--- a/1.2-netsec/codecs/slin_ulaw_ex.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*! \file
- * \brief slin_ulaw_ex.h --
- *
- * Signed 16-bit audio data, 10 milliseconds worth at 8 kHz.
- *
- * Source: g723.example
- *
- * Copyright (C) 2001-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static signed short slin_ulaw_ex[] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
-};
diff --git a/1.2-netsec/codecs/speex_slin_ex.h b/1.2-netsec/codecs/speex_slin_ex.h
deleted file mode 100644
index 404743799..000000000
--- a/1.2-netsec/codecs/speex_slin_ex.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*! \file
- * \brief Random Data data
- *
- * Source: speex.raw
- *
- * Copyright (C) 1999-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char speex_slin_ex[] = {
-0x2e, 0x8e, 0x0f, 0x9a, 0x20, 0000, 0x01, 0x7f, 0xff, 0xff,
-0xff, 0xff, 0xff, 0x91, 0000, 0xbf, 0xff, 0xff, 0xff, 0xff,
-0xff, 0xdc, 0x80, 0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-0x98, 0x7f, 0xff, 0xff, 0xff, 0xe8, 0xff, 0xf7, 0x80 };
diff --git a/1.2-netsec/codecs/ulaw_slin_ex.h b/1.2-netsec/codecs/ulaw_slin_ex.h
deleted file mode 100644
index 9f0417a6b..000000000
--- a/1.2-netsec/codecs/ulaw_slin_ex.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*! \file
- * \brief ulaw_slin_ex.h --
- *
- * 4-bit ADPCM data, 20 milliseconds worth at 8 kHz.
- *
- * Source: g723.example
- *
- * Copyright (C) 2001-2005, Digium Inc.
- *
- * Distributed under the terms of the GNU General Public License
- *
- */
-
-static unsigned char ulaw_slin_ex[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
diff --git a/1.2-netsec/coef_in.h b/1.2-netsec/coef_in.h
deleted file mode 100644
index 9aba022f6..000000000
--- a/1.2-netsec/coef_in.h
+++ /dev/null
@@ -1,13 +0,0 @@
- { { 1.8229206611e-04,-7.8997325866e-01,2.2401819940e+00,-4.6751353581e+00,5.5080745712e+00,-5.0571565772e+00,2.6215820004e+00,0.0000000000e+00,
- }, { 9.8532175289e-02,-5.6297236492e-02,3.3146713415e-01,-9.2239200436e-01,1.4844365184e+00,-2.0183258642e+00,2.0074154497e+00,0.0000000000e+00,
- }, }, { { 1.8229206610e-04,-7.8997325866e-01,7.7191410839e-01,-2.8075643964e+00,1.6948618347e+00,-3.0367273700e+00,9.0333559408e-01,0.0000000000e+00,
- }, { 9.8531161839e-02,-5.6297236492e-02,1.1421579050e-01,-4.8122536483e-01,4.0121072432e-01,-7.4834487567e-01,6.9170822332e-01,0.0000000000e+00,
- }, }, { { 1.8229206611e-04,-7.8997325866e-01,2.9003821430e+00,-6.1082779024e+00,7.7169345751e+00,-6.6075999680e+00,3.3941838836e+00,0.0000000000e+00,
- }, { 9.8539686961e-02,-5.6297236492e-02,4.2915323820e-01,-1.2609358633e+00,2.2399213250e+00,-2.9928879142e+00,2.5990173742e+00,0.0000000000e+00,
- }, }, { { 1.8229206610e-04,-7.8997325866e-01,-7.7191410839e-01,-2.8075643964e+00,-1.6948618347e+00,-3.0367273700e+00,-9.0333559408e-01,0.0000000000e+00,
- }, { 9.8531161839e-02,-5.6297236492e-02,-1.1421579050e-01,-4.8122536483e-01,-4.0121072432e-01,-7.4834487567e-01,-6.9170822332e-01,0.0000000000e+00,
- }, }, { { 1.8229206611e-04,-7.8997325866e-01,2.5782298908e+00,-5.3629717478e+00,6.5890882172e+00,-5.8012914776e+00,3.0171839130e+00,0.0000000000e+00,
- }, { 9.8534230718e-02,-5.6297236492e-02,3.8148618075e-01,-1.0848760410e+00,1.8441165168e+00,-2.4860666655e+00,2.3103384142e+00,0.0000000000e+00,
- }, }, { { 1.8229206610e-04,-7.8997325866e-01,-3.8715051001e-01,-2.6192408538e+00,-8.3977994034e-01,-2.8329897913e+00,-4.5306444352e-01,0.0000000000e+00,
- }, { 9.8531160936e-02,-5.6297236492e-02,-5.7284484199e-02,-4.3673866734e-01,-1.9564766257e-01,-6.2028156584e-01,-3.4692356122e-01,0.0000000000e+00,
- }, },
diff --git a/1.2-netsec/coef_out.h b/1.2-netsec/coef_out.h
deleted file mode 100644
index d80f5c490..000000000
--- a/1.2-netsec/coef_out.h
+++ /dev/null
@@ -1,4 +0,0 @@
- { 1.3868644653e-08,-6.3283665042e-01,4.0895057217e+00,-1.1020074592e+01,1.5850766191e+01,-1.2835109292e+01,5.5477477340e+00,0.0000000000e+00,
- }, { 3.1262119724e-03,-7.8390522307e-03,8.5209627801e-02,-4.0804129163e-01,1.1157139955e+00,-1.8767603680e+00,1.8916395224e+00,0.0000000000e+00
- },
-
diff --git a/1.2-netsec/config.c b/1.2-netsec/config.c
deleted file mode 100644
index 1fe14a40c..000000000
--- a/1.2-netsec/config.c
+++ /dev/null
@@ -1,1080 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Configuration File Parser
- *
- * Includes the Asterisk Realtime API - ARA
- * See README.realtime
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <sys/stat.h>
-#define AST_INCLUDE_GLOB 1
-#ifdef AST_INCLUDE_GLOB
-#if defined(__Darwin__) || defined(__CYGWIN__)
-#define GLOB_ABORTED GLOB_ABEND
-#endif
-# include <glob.h>
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/config.h"
-#include "asterisk/cli.h"
-#include "asterisk/lock.h"
-#include "asterisk/options.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/channel.h"
-#include "asterisk/app.h"
-
-#define MAX_NESTED_COMMENTS 128
-#define COMMENT_START ";--"
-#define COMMENT_END "--;"
-#define COMMENT_META ';'
-#define COMMENT_TAG '-'
-
-static char *extconfig_conf = "extconfig.conf";
-
-static struct ast_config_map {
- struct ast_config_map *next;
- char *name;
- char *driver;
- char *database;
- char *table;
- char stuff[0];
-} *config_maps = NULL;
-
-AST_MUTEX_DEFINE_STATIC(config_lock);
-static struct ast_config_engine *config_engine_list;
-
-#define MAX_INCLUDE_LEVEL 10
-
-struct ast_comment {
- struct ast_comment *next;
- char cmt[0];
-};
-
-struct ast_category {
- char name[80];
- int ignored; /* do not let user of the config see this category */
- struct ast_variable *root;
- struct ast_variable *last;
- struct ast_category *next;
-};
-
-struct ast_config {
- struct ast_category *root;
- struct ast_category *last;
- struct ast_category *current;
- struct ast_category *last_browse; /* used to cache the last category supplied via category_browse */
- int include_level;
- int max_include_level;
-};
-
-struct ast_variable *ast_variable_new(const char *name, const char *value)
-{
- struct ast_variable *variable;
-
- int length = strlen(name) + strlen(value) + 2 + sizeof(struct ast_variable);
- variable = malloc(length);
- if (variable) {
- memset(variable, 0, length);
- variable->name = variable->stuff;
- variable->value = variable->stuff + strlen(name) + 1;
- strcpy(variable->name,name);
- strcpy(variable->value,value);
- }
-
- return variable;
-}
-
-void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
-{
- if (category->last)
- category->last->next = variable;
- else
- category->root = variable;
- category->last = variable;
-}
-
-void ast_variables_destroy(struct ast_variable *v)
-{
- struct ast_variable *vn;
-
- while(v) {
- vn = v;
- v = v->next;
- free(vn);
- }
-}
-
-struct ast_variable *ast_variable_browse(const struct ast_config *config, const char *category)
-{
- struct ast_category *cat = NULL;
-
- if (category && config->last_browse && (config->last_browse->name == category))
- cat = config->last_browse;
- else
- cat = ast_category_get(config, category);
-
- if (cat)
- return cat->root;
- else
- return NULL;
-}
-
-char *ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
-{
- struct ast_variable *v;
-
- if (category) {
- for (v = ast_variable_browse(config, category); v; v = v->next) {
- if (!strcasecmp(variable, v->name))
- return v->value;
- }
- } else {
- struct ast_category *cat;
-
- for (cat = config->root; cat; cat = cat->next)
- for (v = cat->root; v; v = v->next)
- if (!strcasecmp(variable, v->name))
- return v->value;
- }
-
- return NULL;
-}
-
-static struct ast_variable *variable_clone(const struct ast_variable *old)
-{
- struct ast_variable *new = ast_variable_new(old->name, old->value);
-
- if (new) {
- new->lineno = old->lineno;
- new->object = old->object;
- new->blanklines = old->blanklines;
- /* TODO: clone comments? */
- }
-
- return new;
-}
-
-static void move_variables(struct ast_category *old, struct ast_category *new)
-{
- struct ast_variable *var;
- struct ast_variable *next;
-
- next = old->root;
- old->root = NULL;
- for (var = next; var; var = next) {
- next = var->next;
- var->next = NULL;
- ast_variable_append(new, var);
- }
-}
-
-struct ast_category *ast_category_new(const char *name)
-{
- struct ast_category *category;
-
- category = malloc(sizeof(struct ast_category));
- if (category) {
- memset(category, 0, sizeof(struct ast_category));
- ast_copy_string(category->name, name, sizeof(category->name));
- }
-
- return category;
-}
-
-static struct ast_category *category_get(const struct ast_config *config, const char *category_name, int ignored)
-{
- struct ast_category *cat;
-
- for (cat = config->root; cat; cat = cat->next) {
- if (cat->name == category_name && (ignored || !cat->ignored))
- return cat;
- }
-
- for (cat = config->root; cat; cat = cat->next) {
- if (!strcasecmp(cat->name, category_name) && (ignored || !cat->ignored))
- return cat;
- }
-
- return NULL;
-}
-
-struct ast_category *ast_category_get(const struct ast_config *config, const char *category_name)
-{
- return category_get(config, category_name, 0);
-}
-
-int ast_category_exist(const struct ast_config *config, const char *category_name)
-{
- return !!ast_category_get(config, category_name);
-}
-
-void ast_category_append(struct ast_config *config, struct ast_category *category)
-{
- if (config->last)
- config->last->next = category;
- else
- config->root = category;
- config->last = category;
- config->current = category;
-}
-
-void ast_category_destroy(struct ast_category *cat)
-{
- ast_variables_destroy(cat->root);
- free(cat);
-}
-
-static struct ast_category *next_available_category(struct ast_category *cat)
-{
- for (; cat && cat->ignored; cat = cat->next);
-
- return cat;
-}
-
-char *ast_category_browse(struct ast_config *config, const char *prev)
-{
- struct ast_category *cat = NULL;
-
- if (prev && config->last_browse && (config->last_browse->name == prev))
- cat = config->last_browse->next;
- else if (!prev && config->root)
- cat = config->root;
- else if (prev) {
- for (cat = config->root; cat; cat = cat->next) {
- if (cat->name == prev) {
- cat = cat->next;
- break;
- }
- }
- if (!cat) {
- for (cat = config->root; cat; cat = cat->next) {
- if (!strcasecmp(cat->name, prev)) {
- cat = cat->next;
- break;
- }
- }
- }
- }
-
- if (cat)
- cat = next_available_category(cat);
-
- config->last_browse = cat;
- if (cat)
- return cat->name;
- else
- return NULL;
-}
-
-struct ast_variable *ast_category_detach_variables(struct ast_category *cat)
-{
- struct ast_variable *v;
-
- v = cat->root;
- cat->root = NULL;
-
- return v;
-}
-
-void ast_category_rename(struct ast_category *cat, const char *name)
-{
- ast_copy_string(cat->name, name, sizeof(cat->name));
-}
-
-static void inherit_category(struct ast_category *new, const struct ast_category *base)
-{
- struct ast_variable *var;
-
- for (var = base->root; var; var = var->next) {
- struct ast_variable *v;
-
- v = variable_clone(var);
- if (v)
- ast_variable_append(new, v);
- }
-}
-
-struct ast_config *ast_config_new(void)
-{
- struct ast_config *config;
-
- config = malloc(sizeof(*config));
- if (config) {
- memset(config, 0, sizeof(*config));
- config->max_include_level = MAX_INCLUDE_LEVEL;
- }
-
- return config;
-}
-
-void ast_config_destroy(struct ast_config *cfg)
-{
- struct ast_category *cat, *catn;
-
- if (!cfg)
- return;
-
- cat = cfg->root;
- while(cat) {
- ast_variables_destroy(cat->root);
- catn = cat;
- cat = cat->next;
- free(catn);
- }
- free(cfg);
-}
-
-struct ast_category *ast_config_get_current_category(const struct ast_config *cfg)
-{
- return cfg->current;
-}
-
-void ast_config_set_current_category(struct ast_config *cfg, const struct ast_category *cat)
-{
- /* cast below is just to silence compiler warning about dropping "const" */
- cfg->current = (struct ast_category *) cat;
-}
-
-static int process_text_line(struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile)
-{
- char *c;
- char *cur = buf;
- struct ast_variable *v;
- char cmd[512], exec_file[512];
- int object, do_exec, do_include;
-
- /* Actually parse the entry */
- if (cur[0] == '[') {
- struct ast_category *newcat = NULL;
- char *catname;
-
- /* A category header */
- c = strchr(cur, ']');
- if (!c) {
- ast_log(LOG_WARNING, "parse error: no closing ']', line %d of %s\n", lineno, configfile);
- return -1;
- }
- *c++ = '\0';
- cur++;
- if (*c++ != '(')
- c = NULL;
- catname = cur;
- *cat = newcat = ast_category_new(catname);
- if (!newcat) {
- ast_log(LOG_WARNING, "Out of memory, line %d of %s\n", lineno, configfile);
- return -1;
- }
- /* If there are options or categories to inherit from, process them now */
- if (c) {
- if (!(cur = strchr(c, ')'))) {
- ast_log(LOG_WARNING, "parse error: no closing ')', line %d of %s\n", lineno, configfile);
- return -1;
- }
- *cur = '\0';
- while ((cur = strsep(&c, ","))) {
- if (!strcasecmp(cur, "!")) {
- (*cat)->ignored = 1;
- } else if (!strcasecmp(cur, "+")) {
- *cat = category_get(cfg, catname, 1);
- if (!*cat) {
- ast_config_destroy(cfg);
- if (newcat)
- ast_category_destroy(newcat);
- ast_log(LOG_WARNING, "Category addition requested, but category '%s' does not exist, line %d of %s\n", catname, lineno, configfile);
- return -1;
- }
- if (newcat) {
- move_variables(newcat, *cat);
- ast_category_destroy(newcat);
- newcat = NULL;
- }
- } else {
- struct ast_category *base;
-
- base = category_get(cfg, cur, 1);
- if (!base) {
- ast_log(LOG_WARNING, "Inheritance requested, but category '%s' does not exist, line %d of %s\n", cur, lineno, configfile);
- return -1;
- }
- inherit_category(*cat, base);
- }
- }
- }
- if (newcat)
- ast_category_append(cfg, *cat);
- } else if (cur[0] == '#') {
- /* A directive */
- cur++;
- c = cur;
- while(*c && (*c > 32)) c++;
- if (*c) {
- *c = '\0';
- c++;
- /* Find real argument */
- while(*c && (*c < 33)) c++;
- if (!*c)
- c = NULL;
- } else
- c = NULL;
- do_include = !strcasecmp(cur, "include");
- if(!do_include)
- do_exec = !strcasecmp(cur, "exec");
- else
- do_exec = 0;
- if (do_exec && !option_exec_includes) {
- ast_log(LOG_WARNING, "Cannot perform #exec unless execincludes option is enabled in asterisk.conf (options section)!\n");
- do_exec = 0;
- }
- if (do_include || do_exec) {
- if (c) {
- /* Strip off leading and trailing "'s and <>'s */
- while((*c == '<') || (*c == '>') || (*c == '\"')) c++;
- /* Get rid of leading mess */
- cur = c;
- while (!ast_strlen_zero(cur)) {
- c = cur + strlen(cur) - 1;
- if ((*c == '>') || (*c == '<') || (*c == '\"'))
- *c = '\0';
- else
- break;
- }
- /* #exec </path/to/executable>
- We create a tmp file, then we #include it, then we delete it. */
- if (do_exec) {
- snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%d.%ld", (int)time(NULL), (long)pthread_self());
- snprintf(cmd, sizeof(cmd), "%s > %s 2>&1", cur, exec_file);
- ast_safe_system(cmd);
- cur = exec_file;
- } else
- exec_file[0] = '\0';
- /* A #include */
- do_include = ast_config_internal_load(cur, cfg) ? 1 : 0;
- if(!ast_strlen_zero(exec_file))
- unlink(exec_file);
- if(!do_include)
- return 0;
-
- } else {
- ast_log(LOG_WARNING, "Directive '#%s' needs an argument (%s) at line %d of %s\n",
- do_exec ? "exec" : "include",
- do_exec ? "/path/to/executable" : "filename",
- lineno,
- configfile);
- }
- }
- else
- ast_log(LOG_WARNING, "Unknown directive '%s' at line %d of %s\n", cur, lineno, configfile);
- } else {
- /* Just a line (variable = value) */
- if (!*cat) {
- ast_log(LOG_WARNING,
- "parse error: No category context for line %d of %s\n", lineno, configfile);
- return -1;
- }
- c = strchr(cur, '=');
- if (c) {
- *c = 0;
- c++;
- /* Ignore > in => */
- if (*c== '>') {
- object = 1;
- c++;
- } else
- object = 0;
- v = ast_variable_new(ast_strip(cur), ast_strip(c));
- if (v) {
- v->lineno = lineno;
- v->object = object;
- /* Put and reset comments */
- v->blanklines = 0;
- ast_variable_append(*cat, v);
- } else {
- ast_log(LOG_WARNING, "Out of memory, line %d\n", lineno);
- return -1;
- }
- } else {
- ast_log(LOG_WARNING, "No '=' (equal sign) in line %d of %s\n", lineno, configfile);
- }
-
- }
- return 0;
-}
-
-static struct ast_config *config_text_file_load(const char *database, const char *table, const char *filename, struct ast_config *cfg)
-{
- char fn[256];
- char buf[8192];
- char *new_buf, *comment_p, *process_buf;
- FILE *f;
- int lineno=0;
- int comment = 0, nest[MAX_NESTED_COMMENTS];
- struct ast_category *cat = NULL;
- int count = 0;
- struct stat statbuf;
-
- cat = ast_config_get_current_category(cfg);
-
- if (filename[0] == '/') {
- ast_copy_string(fn, filename, sizeof(fn));
- } else {
- snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, filename);
- }
-
-#ifdef AST_INCLUDE_GLOB
- {
- int glob_ret;
- glob_t globbuf;
- globbuf.gl_offs = 0; /* initialize it to silence gcc */
-#ifdef SOLARIS
- glob_ret = glob(fn, GLOB_NOCHECK, NULL, &globbuf);
-#else
- glob_ret = glob(fn, GLOB_NOMAGIC|GLOB_BRACE, NULL, &globbuf);
-#endif
- if (glob_ret == GLOB_NOSPACE)
- ast_log(LOG_WARNING,
- "Glob Expansion of pattern '%s' failed: Not enough memory\n", fn);
- else if (glob_ret == GLOB_ABORTED)
- ast_log(LOG_WARNING,
- "Glob Expansion of pattern '%s' failed: Read error\n", fn);
- else {
- /* loop over expanded files */
- int i;
- for (i=0; i<globbuf.gl_pathc; i++) {
- ast_copy_string(fn, globbuf.gl_pathv[i], sizeof(fn));
-#endif
- do {
- if (stat(fn, &statbuf))
- continue;
-
- if (!S_ISREG(statbuf.st_mode)) {
- ast_log(LOG_WARNING, "'%s' is not a regular file, ignoring\n", fn);
- continue;
- }
- if ((option_verbose > 1) && !option_debug) {
- ast_verbose(VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
- fflush(stdout);
- }
- if (!(f = fopen(fn, "r"))) {
- if (option_debug)
- ast_log(LOG_DEBUG, "No file to parse: %s\n", fn);
- else if (option_verbose > 1)
- ast_verbose( "Not found (%s)\n", strerror(errno));
- continue;
- }
- count++;
- if (option_debug)
- ast_log(LOG_DEBUG, "Parsing %s\n", fn);
- else if (option_verbose > 1)
- ast_verbose("Found\n");
- while(!feof(f)) {
- lineno++;
- if (fgets(buf, sizeof(buf), f)) {
- new_buf = buf;
- if (comment)
- process_buf = NULL;
- else
- process_buf = buf;
- while ((comment_p = strchr(new_buf, COMMENT_META))) {
- if ((comment_p > new_buf) && (*(comment_p-1) == '\\')) {
- /* Yuck, gotta memmove */
- memmove(comment_p - 1, comment_p, strlen(comment_p) + 1);
- new_buf = comment_p;
- } else if(comment_p[1] == COMMENT_TAG && comment_p[2] == COMMENT_TAG && (comment_p[3] != '-')) {
- /* Meta-Comment start detected ";--" */
- if (comment < MAX_NESTED_COMMENTS) {
- *comment_p = '\0';
- new_buf = comment_p + 3;
- comment++;
- nest[comment-1] = lineno;
- } else {
- ast_log(LOG_ERROR, "Maximum nest limit of %d reached.\n", MAX_NESTED_COMMENTS);
- }
- } else if ((comment_p >= new_buf + 2) &&
- (*(comment_p - 1) == COMMENT_TAG) &&
- (*(comment_p - 2) == COMMENT_TAG)) {
- /* Meta-Comment end detected */
- comment--;
- new_buf = comment_p + 1;
- if (!comment) {
- /* Back to non-comment now */
- if (process_buf) {
- /* Actually have to move what's left over the top, then continue */
- char *oldptr;
- oldptr = process_buf + strlen(process_buf);
- memmove(oldptr, new_buf, strlen(new_buf) + 1);
- new_buf = oldptr;
- } else
- process_buf = new_buf;
- }
- } else {
- if (!comment) {
- /* If ; is found, and we are not nested in a comment,
- we immediately stop all comment processing */
- *comment_p = '\0';
- new_buf = comment_p;
- } else
- new_buf = comment_p + 1;
- }
- }
- if (process_buf) {
- char *buf = ast_strip(process_buf);
- if (!ast_strlen_zero(buf)) {
- if (process_text_line(cfg, &cat, buf, lineno, filename)) {
- cfg = NULL;
- break;
- }
- }
- }
- }
- }
- fclose(f);
- } while(0);
- if (comment) {
- ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment]);
- }
-#ifdef AST_INCLUDE_GLOB
- if (!cfg)
- break;
- }
- globfree(&globbuf);
- }
- }
-#endif
- if (count == 0)
- return NULL;
-
- return cfg;
-}
-
-int config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator)
-{
- FILE *f;
- char fn[256];
- char date[256]="";
- time_t t;
- struct ast_variable *var;
- struct ast_category *cat;
- int blanklines = 0;
-
- if (configfile[0] == '/') {
- ast_copy_string(fn, configfile, sizeof(fn));
- } else {
- snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
- }
- time(&t);
- ast_copy_string(date, ctime(&t), sizeof(date));
-#ifdef __CYGWIN__
- if ((f = fopen(fn, "w+"))) {
-#else
- if ((f = fopen(fn, "w"))) {
-#endif
- if ((option_verbose > 1) && !option_debug)
- ast_verbose( VERBOSE_PREFIX_2 "Saving '%s': ", fn);
- fprintf(f, ";!\n");
- fprintf(f, ";! Automatically generated configuration file\n");
- fprintf(f, ";! Filename: %s (%s)\n", configfile, fn);
- fprintf(f, ";! Generator: %s\n", generator);
- fprintf(f, ";! Creation Date: %s", date);
- fprintf(f, ";!\n");
- cat = cfg->root;
- while(cat) {
- /* Dump section with any appropriate comment */
- fprintf(f, "[%s]\n", cat->name);
- var = cat->root;
- while(var) {
- if (var->sameline)
- fprintf(f, "%s %s %s ; %s\n", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
- else
- fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
- if (var->blanklines) {
- blanklines = var->blanklines;
- while (blanklines--)
- fprintf(f, "\n");
- }
-
- var = var->next;
- }
-#if 0
- /* Put an empty line */
- fprintf(f, "\n");
-#endif
- cat = cat->next;
- }
- } else {
- if (option_debug)
- printf("Unable to open for writing: %s\n", fn);
- else if (option_verbose > 1)
- printf( "Unable to write (%s)", strerror(errno));
- return -1;
- }
- fclose(f);
- return 0;
-}
-
-static void clear_config_maps(void)
-{
- struct ast_config_map *map;
-
- ast_mutex_lock(&config_lock);
-
- while (config_maps) {
- map = config_maps;
- config_maps = config_maps->next;
- free(map);
- }
-
- ast_mutex_unlock(&config_lock);
-}
-
-static int append_mapping(char *name, char *driver, char *database, char *table)
-{
- struct ast_config_map *map;
- int length;
-
- length = sizeof(*map);
- length += strlen(name) + 1;
- length += strlen(driver) + 1;
- length += strlen(database) + 1;
- if (table)
- length += strlen(table) + 1;
- map = malloc(length);
-
- if (!map)
- return -1;
-
- memset(map, 0, length);
- map->name = map->stuff;
- strcpy(map->name, name);
- map->driver = map->name + strlen(map->name) + 1;
- strcpy(map->driver, driver);
- map->database = map->driver + strlen(map->driver) + 1;
- strcpy(map->database, database);
- if (table) {
- map->table = map->database + strlen(map->database) + 1;
- strcpy(map->table, table);
- }
- map->next = config_maps;
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n",
- map->name, map->driver, map->database, map->table ? map->table : map->name);
-
- config_maps = map;
- return 0;
-}
-
-void read_config_maps(void)
-{
- struct ast_config *config, *configtmp;
- struct ast_variable *v;
- char *driver, *table, *database, *stringp;
-
- clear_config_maps();
-
- configtmp = ast_config_new();
- configtmp->max_include_level = 1;
- config = ast_config_internal_load(extconfig_conf, configtmp);
- if (!config) {
- ast_config_destroy(configtmp);
- return;
- }
-
- for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
- stringp = v->value;
- driver = strsep(&stringp, ",");
- database = strsep(&stringp, ",");
- table = strsep(&stringp, ",");
-
- if (!strcmp(v->name, extconfig_conf)) {
- ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
- continue;
- }
-
- if (!strcmp(v->name, "asterisk.conf")) {
- ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n");
- continue;
- }
-
- if (!strcmp(v->name, "logger.conf")) {
- ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n");
- continue;
- }
-
- if (!driver || !database)
- continue;
- if (!strcasecmp(v->name, "sipfriends")) {
- ast_log(LOG_WARNING, "The 'sipfriends' table is obsolete, update your config to use sipusers and sippeers, though they can point to the same table.\n");
- append_mapping("sipusers", driver, database, table ? table : "sipfriends");
- append_mapping("sippeers", driver, database, table ? table : "sipfriends");
- } else if (!strcasecmp(v->name, "iaxfriends")) {
- ast_log(LOG_WARNING, "The 'iaxfriends' table is obsolete, update your config to use iaxusers and iaxpeers, though they can point to the same table.\n");
- append_mapping("iaxusers", driver, database, table ? table : "iaxfriends");
- append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends");
- } else
- append_mapping(v->name, driver, database, table);
- }
-
- ast_config_destroy(config);
-}
-
-int ast_config_engine_register(struct ast_config_engine *new)
-{
- struct ast_config_engine *ptr;
-
- ast_mutex_lock(&config_lock);
-
- if (!config_engine_list) {
- config_engine_list = new;
- } else {
- for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
- ptr->next = new;
- }
-
- ast_mutex_unlock(&config_lock);
- ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
-
- return 1;
-}
-
-int ast_config_engine_deregister(struct ast_config_engine *del)
-{
- struct ast_config_engine *ptr, *last=NULL;
-
- ast_mutex_lock(&config_lock);
-
- for (ptr = config_engine_list; ptr; ptr=ptr->next) {
- if (ptr == del) {
- if (last)
- last->next = ptr->next;
- else
- config_engine_list = ptr->next;
- break;
- }
- last = ptr;
- }
-
- ast_mutex_unlock(&config_lock);
-
- return 0;
-}
-
-/*--- find_engine: Find realtime engine for realtime family */
-static struct ast_config_engine *find_engine(const char *family, char *database, int dbsiz, char *table, int tabsiz)
-{
- struct ast_config_engine *eng, *ret = NULL;
- struct ast_config_map *map;
-
- ast_mutex_lock(&config_lock);
-
- for (map = config_maps; map; map = map->next) {
- if (!strcasecmp(family, map->name)) {
- if (database)
- ast_copy_string(database, map->database, dbsiz);
- if (table)
- ast_copy_string(table, map->table ? map->table : family, tabsiz);
- break;
- }
- }
-
- /* Check if the required driver (engine) exist */
- if (map) {
- for (eng = config_engine_list; !ret && eng; eng = eng->next) {
- if (!strcasecmp(eng->name, map->driver))
- ret = eng;
- }
- }
-
- ast_mutex_unlock(&config_lock);
-
- /* if we found a mapping, but the engine is not available, then issue a warning */
- if (map && !ret)
- ast_log(LOG_WARNING, "Realtime mapping for '%s' found to engine '%s', but the engine is not available\n", map->name, map->driver);
-
- return ret;
-}
-
-static struct ast_config_engine text_file_engine = {
- .name = "text",
- .load_func = config_text_file_load,
-};
-
-struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg)
-{
- char db[256];
- char table[256];
- struct ast_config_engine *loader = &text_file_engine;
- struct ast_config *result;
-
- if (cfg->include_level == cfg->max_include_level) {
- ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
- return NULL;
- }
-
- cfg->include_level++;
-
- if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
- struct ast_config_engine *eng;
-
- eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
-
-
- if (eng && eng->load_func) {
- loader = eng;
- } else {
- eng = find_engine("global", db, sizeof(db), table, sizeof(table));
- if (eng && eng->load_func)
- loader = eng;
- }
- }
-
- result = loader->load_func(db, table, filename, cfg);
-
- if (result)
- result->include_level--;
-
- return result;
-}
-
-struct ast_config *ast_config_load(const char *filename)
-{
- struct ast_config *cfg;
- struct ast_config *result;
-
- cfg = ast_config_new();
- if (!cfg)
- return NULL;
-
- result = ast_config_internal_load(filename, cfg);
- if (!result)
- ast_config_destroy(cfg);
-
- return result;
-}
-
-struct ast_variable *ast_load_realtime(const char *family, ...)
-{
- struct ast_config_engine *eng;
- char db[256]="";
- char table[256]="";
- struct ast_variable *res=NULL;
- va_list ap;
-
- va_start(ap, family);
- eng = find_engine(family, db, sizeof(db), table, sizeof(table));
- if (eng && eng->realtime_func)
- res = eng->realtime_func(db, table, ap);
- va_end(ap);
-
- return res;
-}
-
-/*--- ast_check_realtime: Check if realtime engine is configured for family */
-int ast_check_realtime(const char *family)
-{
- struct ast_config_engine *eng;
-
- eng = find_engine(family, NULL, 0, NULL, 0);
- if (eng)
- return 1;
- return 0;
-
-}
-
-struct ast_config *ast_load_realtime_multientry(const char *family, ...)
-{
- struct ast_config_engine *eng;
- char db[256]="";
- char table[256]="";
- struct ast_config *res=NULL;
- va_list ap;
-
- va_start(ap, family);
- eng = find_engine(family, db, sizeof(db), table, sizeof(table));
- if (eng && eng->realtime_multi_func)
- res = eng->realtime_multi_func(db, table, ap);
- va_end(ap);
-
- return res;
-}
-
-int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...)
-{
- struct ast_config_engine *eng;
- int res = -1;
- char db[256]="";
- char table[256]="";
- va_list ap;
-
- va_start(ap, lookup);
- eng = find_engine(family, db, sizeof(db), table, sizeof(table));
- if (eng && eng->update_func)
- res = eng->update_func(db, table, keyfield, lookup, ap);
- va_end(ap);
-
- return res;
-}
-
-static int config_command(int fd, int argc, char **argv)
-{
- struct ast_config_engine *eng;
- struct ast_config_map *map;
-
- ast_mutex_lock(&config_lock);
-
- ast_cli(fd, "\n\n");
- for (eng = config_engine_list; eng; eng = eng->next) {
- ast_cli(fd, "\nConfig Engine: %s\n", eng->name);
- for (map = config_maps; map; map = map->next)
- if (!strcasecmp(map->driver, eng->name)) {
- ast_cli(fd, "===> %s (db=%s, table=%s)\n", map->name, map->database,
- map->table ? map->table : map->name);
- }
- }
- ast_cli(fd,"\n\n");
-
- ast_mutex_unlock(&config_lock);
-
- return 0;
-}
-
-static char show_config_help[] =
- "Usage: show config mappings\n"
- " Shows the filenames to config engines.\n";
-
-static struct ast_cli_entry config_command_struct = {
- { "show", "config", "mappings", NULL }, config_command, "Show Config mappings (file names to config engines)", show_config_help, NULL
-};
-
-int register_config_cli()
-{
- return ast_cli_register(&config_command_struct);
-}
diff --git a/1.2-netsec/configs/adsi.conf.sample b/1.2-netsec/configs/adsi.conf.sample
deleted file mode 100644
index 0f36f80da..000000000
--- a/1.2-netsec/configs/adsi.conf.sample
+++ /dev/null
@@ -1,8 +0,0 @@
-;
-; Sample ADSI Configuration file
-;
-[intro]
-alignment = center
-greeting => Welcome to the
-greeting => Asterisk
-greeting => Open Source PBX
diff --git a/1.2-netsec/configs/adtranvofr.conf.sample b/1.2-netsec/configs/adtranvofr.conf.sample
deleted file mode 100644
index dc7bcfc7c..000000000
--- a/1.2-netsec/configs/adtranvofr.conf.sample
+++ /dev/null
@@ -1,39 +0,0 @@
-;
-; Voice over Frame Relay (Adtran style)
-;
-; Configuration file
-
-[interfaces]
-;
-; Default language
-;
-;language=en
-;
-; Lines for which we are the user termination. They accept incoming
-; and outgoing calls. We use the default context on the first 8 lines
-; used by internal phones.
-;
-context=default
-;user => voice00
-;user => voice01
-;user => voice02
-;user => voice03
-;user => voice04
-;user => voice05
-;user => voice06
-;user => voice07
-; Calls on 16 and 17 come from the outside world, so they get
-; a little bit special treatment
-context=remote
-;user => voice16
-;user => voice17
-;
-; Next we have lines which we only accept calls on, and typically
-; do not send outgoing calls on (i.e. these are where we are the
-; network termination)
-;
-;network => voice08
-;network => voice09
-;network => voice10
-;network => voice11
-;network => voice12
diff --git a/1.2-netsec/configs/agents.conf.sample b/1.2-netsec/configs/agents.conf.sample
deleted file mode 100644
index c47100b18..000000000
--- a/1.2-netsec/configs/agents.conf.sample
+++ /dev/null
@@ -1,80 +0,0 @@
-[general]
-;
-; Define whether callbacklogins should be stored in astdb for
-; persistence. Persistent logins will be reloaded after
-; Asterisk restarts.
-;
-persistentagents=yes
-;
-; Agent configuration
-;
-;
-[agents]
-;
-; Define autologoff times if appropriate. This is how long
-; the phone has to ring with no answer before the agent is
-; automatically logged off (in seconds)
-;
-;autologoff=15
-;
-; Define ackcall to require an acknowledgement by '#' when
-; an agent logs in using agentcallbacklogin. Default is "no".
-;
-;ackcall=no
-;
-; Define wrapuptime. This is the minimum amount of time when
-; after disconnecting before the caller can receive a new call
-; note this is in milliseconds.
-;
-;wrapuptime=5000
-;
-; Define the default musiconhold for agents
-; musiconhold => music_class
-;
-;musiconhold => default
-;
-; Define updatecdr. This is whether or not to change the source
-; channel in the CDR record for this call to agent/agent_id so
-; that we know which agent generates the call
-;
-;updatecdr=no
-;
-; Group memberships for agents (may change in mid-file)
-;
-;group=3
-;group=1,2
-;group=
-;
-; --------------------------------------------------
-; This section is devoted to recording agent's calls
-; The keywords are global to the chan_agent channel driver
-;
-; Enable recording calls addressed to agents. It's turned off by default.
-;recordagentcalls=yes
-;
-; The format to be used to record the calls: wav, gsm, wav49.
-; By default its "wav".
-;recordformat=gsm
-;
-; Insert into CDR userfield a name of the the created recording
-; By default it's turned off.
-;createlink=yes
-;
-; The text to be added to the name of the recording. Allows forming a url link.
-;urlprefix=http://localhost/calls/
-;
-; The optional directory to save the conversations in. The default is
-; /var/spool/asterisk/monitor
-;savecallsin=/var/calls
-;
-; An optional custom beep sound file to play to always-connected agents.
-;custom_beep=beep
-;
-; --------------------------------------------------
-;
-; This section contains the agent definitions, in the form:
-;
-; agent => agentid,agentpassword,name
-;
-;agent => 1001,4321,Mark Spencer
-;agent => 1002,4321,Will Meadows
diff --git a/1.2-netsec/configs/alarmreceiver.conf.sample b/1.2-netsec/configs/alarmreceiver.conf.sample
deleted file mode 100644
index bf767dea3..000000000
--- a/1.2-netsec/configs/alarmreceiver.conf.sample
+++ /dev/null
@@ -1,80 +0,0 @@
-;
-; alarmreceiver.conf
-;
-; Sample configuration file for the Asterisk alarm receiver application.
-;
-
-
-[general]
-
-;
-; Specify a timestamp format for the metadata section of the event files
-; Default is %a %b %d, %Y @ %H:%M:%S %Z
-
-timestampformat = %a %b %d, %Y @ %H:%M:%S %Z
-
-;
-; Specify a command to execute when the caller hangs up
-;
-; Default is none
-;
-
-;eventcmd = yourprogram -yourargs ...
-
-;
-; Specify a spool directory for the event files. This setting is required
-; if you want the app to be useful. Event files written to the spool
-; directory will be of the template event-XXXXXX, where XXXXXX is a random
-; and unique alphanumeric string.
-;
-; Default is none, and the events will be dropped on the floor.
-;
-
-eventspooldir = /tmp
-
-;
-; The alarmreceiver app can either log the events one-at-a-time to individual
-; files in the spool directory, or it can store them until the caller
-; disconnects and write them all to one file.
-;
-; The default setting for logindividualevents is no.
-;
-
-logindividualevents = no
-
-;
-; The timeout for receiving the first DTMF digit is adjustable from 1000 msec.
-; to 10000 msec. The default is 2000 msec. Note: if you wish to test the
-; receiver by entering digits manually, set this to a reasonable time out
-; like 10000 milliseconds.
-
-fdtimeout = 2000
-
-;
-; The timeout for receiving subsequent DTMF digits is adjustable from
-; 110 msec. to 4000 msec. The default is 200 msec. Note: if you wish to test
-; the receiver by entering digits manually, set this to a reasonable time out
-; like 4000 milliseconds.
-;
-
-sdtimeout = 200
-
-;
-; The loudness of the ACK and Kissoff tones is adjustable from 100 to 8192.
-; The default is 8192. This shouldn't need to be messed with, but is included
-; just in case there are problems with signal levels.
-;
-
-loudness = 8192
-
-;
-; The db-family setting allows the user to capture statistics on the number of
-; calls, and the errors the alarm receiver sees. The default is for no
-; db-family name to be defined and the database logging to be turned off.
-;
-
-;db-family = yourfamily:
-
-;
-; End of alarmreceiver.conf
-;
diff --git a/1.2-netsec/configs/alsa.conf.sample b/1.2-netsec/configs/alsa.conf.sample
deleted file mode 100644
index 98819250b..000000000
--- a/1.2-netsec/configs/alsa.conf.sample
+++ /dev/null
@@ -1,31 +0,0 @@
-;
-; Open Sound System Console Driver Configuration File
-;
-[general]
-;
-; Automatically answer incoming calls on the console? Choose yes if
-; for example you want to use this as an intercom.
-;
-autoanswer=yes
-;
-; Default context (is overridden with @context syntax)
-;
-context=local
-;
-; Default extension to call
-;
-extension=s
-;
-; Default language
-;
-;language=en
-;
-; Silence supression can be enabled when sound is over a certain threshold.
-; The value for the threshold should probably be between 500 and 2000 or so,
-; but your mileage may vary. Use the echo test to evaluate the best setting.
-;silencesuppression = yes
-;silencethreshold = 1000
-;
-; To set which ALSA device to use, change this parameter
-;input_device=hw:0,0
-;output_device=default
diff --git a/1.2-netsec/configs/asterisk.adsi b/1.2-netsec/configs/asterisk.adsi
deleted file mode 100644
index a275502ac..000000000
--- a/1.2-netsec/configs/asterisk.adsi
+++ /dev/null
@@ -1,159 +0,0 @@
-;
-; Asterisk default ADSI script
-;
-;
-; Begin with the preamble requirements
-;
-DESCRIPTION "Asterisk PBX" ; Name of vendor
-VERSION 0x00 ; Version of stuff
-;SECURITY "_AST" ; Security code
-SECURITY 0X9BDBF7AC ; Security code
-FDN 0x0000000F ; Descriptor number
-
-;
-; Flags
-;
-FLAG "nocallwaiting"
-
-;
-; Predefined strings
-;
-DISPLAY "titles" IS "** Asterisk PBX **"
-DISPLAY "talkingto" IS "Call active." JUSTIFY LEFT
-DISPLAY "callname" IS "$Call1p" JUSTIFY LEFT
-DISPLAY "callnum" IS "$Call1s" JUSTIFY LEFT
-DISPLAY "incoming" IS "Incoming call!" JUSTIFY LEFT
-DISPLAY "ringing" IS "Calling... " JUSTIFY LEFT
-DISPLAY "callended" IS "Call ended." JUSTIFY LEFT
-DISPLAY "missedcall" IS "Missed call." JUSTIFY LEFT
-DISPLAY "busy" IS "Busy." JUSTIFY LEFT
-DISPLAY "reorder" IS "Reorder." JUSTIFY LEFT
-DISPLAY "cwdisabled" IS "Callwait disabled"
-DISPLAY "empty" IS "asdf"
-
-;
-; Begin soft key definitions
-;
-KEY "callfwd" IS "CallFwd" OR "Call Forward"
- OFFHOOK
- VOICEMODE
- WAITDIALTONE
- SENDDTMF "*60"
- GOTO "offHook"
-ENDKEY
-
-KEY "vmail_OH" IS "VMail" OR "Voicemail"
- OFFHOOK
- VOICEMODE
- WAITDIALTONE
- SENDDTMF "8500"
-ENDKEY
-
-KEY "vmail" IS "VMail" OR "Voicemail"
- SENDDTMF "8500"
-ENDKEY
-
-KEY "backspace" IS "BackSpc" OR "Backspace"
- BACKSPACE
-ENDKEY
-
-KEY "cwdisable" IS "CWDsble" OR "Disable Call Wait"
- SENDDTMF "*70"
- SETFLAG "nocallwaiting"
- SHOWDISPLAY "cwdisabled" AT 4
- TIMERCLEAR
- TIMERSTART 1
-ENDKEY
-
-KEY "cidblock" IS "CIDBlk" OR "Block Callerid"
- SENDDTMF "*67"
- SETFLAG "nocallwaiting"
-ENDKEY
-
-;
-; Begin main subroutine
-;
-
-SUB "main" IS
- IFEVENT NEARANSWER THEN
- CLEAR
- SHOWDISPLAY "titles" AT 1 NOUPDATE
- SHOWDISPLAY "talkingto" AT 2 NOUPDATE
- SHOWDISPLAY "callname" AT 3
- SHOWDISPLAY "callnum" AT 4
- GOTO "stableCall"
- ENDIF
- IFEVENT OFFHOOK THEN
- CLEAR
- CLEARFLAG "nocallwaiting"
- CLEARDISPLAY
- SHOWDISPLAY "titles" AT 1
- SHOWKEYS "vmail"
- SHOWKEYS "cidblock"
- SHOWKEYS "cwdisable" UNLESS "nocallwaiting"
- GOTO "offHook"
- ENDIF
- IFEVENT IDLE THEN
- CLEAR
- SHOWDISPLAY "titles" AT 1
- SHOWKEYS "vmail_OH"
- ENDIF
- IFEVENT CALLERID THEN
- CLEAR
-; SHOWDISPLAY "titles" AT 1 NOUPDATE
-; SHOWDISPLAY "incoming" AT 2 NOUPDATE
- SHOWDISPLAY "callname" AT 3 NOUPDATE
- SHOWDISPLAY "callnum" AT 4
- ENDIF
- IFEVENT RING THEN
- CLEAR
- SHOWDISPLAY "titles" AT 1 NOUPDATE
- SHOWDISPLAY "incoming" AT 2
- ENDIF
- IFEVENT ENDOFRING THEN
- SHOWDISPLAY "missedcall" AT 2
- CLEAR
- SHOWDISPLAY "titles" AT 1
- SHOWKEYS "vmail_OH"
- ENDIF
- IFEVENT TIMER THEN
- CLEAR
- SHOWDISPLAY "empty" AT 4
- ENDIF
-ENDSUB
-
-SUB "offHook" IS
- IFEVENT FARRING THEN
- CLEAR
- SHOWDISPLAY "titles" AT 1 NOUPDATE
- SHOWDISPLAY "ringing" AT 2 NOUPDATE
- SHOWDISPLAY "callname" at 3 NOUPDATE
- SHOWDISPLAY "callnum" at 4
- ENDIF
- IFEVENT FARANSWER THEN
- CLEAR
- SHOWDISPLAY "talkingto" AT 2
- GOTO "stableCall"
- ENDIF
- IFEVENT BUSY THEN
- CLEAR
- SHOWDISPLAY "titles" AT 1 NOUPDATE
- SHOWDISPLAY "busy" AT 2 NOUPDATE
- SHOWDISPLAY "callname" at 3 NOUPDATE
- SHOWDISPLAY "callnum" at 4
- ENDIF
- IFEVENT REORDER THEN
- CLEAR
- SHOWDISPLAY "titles" AT 1 NOUPDATE
- SHOWDISPLAY "reorder" AT 2 NOUPDATE
- SHOWDISPLAY "callname" at 3 NOUPDATE
- SHOWDISPLAY "callnum" at 4
- ENDIF
-ENDSUB
-
-SUB "stableCall" IS
- IFEVENT REORDER THEN
- SHOWDISPLAY "callended" AT 2
- ENDIF
-ENDSUB
-
diff --git a/1.2-netsec/configs/cdr.conf.sample b/1.2-netsec/configs/cdr.conf.sample
deleted file mode 100644
index 331b6ed9a..000000000
--- a/1.2-netsec/configs/cdr.conf.sample
+++ /dev/null
@@ -1,51 +0,0 @@
-;
-; Asterisk Call Detail Record engine configuration
-;
-; CDR is Call Detail Record, which provides logging services via a variety of
-; pluggable backend modules. Detailed call information can be recorded to
-; databases, files, etc. Useful for billing, fraud prevention, compliance with
-; Sarbanes-Oxley aka The Enron Act, QOS evaluations, and more.
-;
-
-[general]
-
-; Define whether or not to use CDR logging. Setting this to "no" will override
-; any loading of backend CDR modules. Default is "yes".
-;enable=yes
-
-; Define the CDR batch mode, where instead of posting the CDR at the end of
-; every call, the data will be stored in a buffer to help alleviate load on the
-; asterisk server. Default is "no".
-;
-; WARNING WARNING WARNING
-; Use of batch mode may result in data loss after unsafe asterisk termination
-; ie. software crash, power failure, kill -9, etc.
-; WARNING WARNING WARNING
-;
-;batch=no
-
-; Define the maximum number of CDRs to accumulate in the buffer before posting
-; them to the backend engines. 'batch' must be set to 'yes'. Default is 100.
-;size=100
-
-; Define the maximum time to accumulate CDRs in the buffer before posting them
-; to the backend engines. If this time limit is reached, then it will post the
-; records, regardless of the value defined for 'size'. 'batch' must be set to
-; 'yes'. Note that time is in seconds. Default is 300 (5 minutes).
-;time=300
-
-; The CDR engine uses the internal asterisk scheduler to determine when to post
-; records. Posting can either occure inside the scheduler thread, or a new
-; thread can be spawned for the submission of every batch. For small batches,
-; it might be acceptable to just use the scheduler thread, so set this to "yes".
-; For large batches, say anything over size=10, a new thread is recommended, so
-; set this to "no". Default is "no".
-;scheduleronly=no
-
-; When shutting down asterisk, you can block until the CDRs are submitted. If
-; you don't, then data will likely be lost. You can always check the size of
-; the CDR batch buffer with the CLI "cdr status" command. To enable blocking on
-; submission of CDR data during asterisk shutdown, set this to "yes". Default
-; is "yes".
-;safeshutdown=yes
-
diff --git a/1.2-netsec/configs/cdr_custom.conf.sample b/1.2-netsec/configs/cdr_custom.conf.sample
deleted file mode 100644
index 4af17c37b..000000000
--- a/1.2-netsec/configs/cdr_custom.conf.sample
+++ /dev/null
@@ -1,6 +0,0 @@
-;
-; Mappings for custom config file
-;
-[mappings]
-Master.csv => "${CDR(clid)}","${CDR(src)}","${CDR(dst)}","${CDR(dcontext)}","${CDR(channel)}","${CDR(dstchannel)}","${CDR(lastapp)}","${CDR(lastdata)}","${CDR(start)}","${CDR(answer)}","${CDR(end)}","${CDR(duration)}","${CDR(billsec)}","${CDR(disposition)}","${CDR(amaflags)}","${CDR(accountcode)}","${CDR(uniqueid)}","${CDR(userfield)}"
-
diff --git a/1.2-netsec/configs/cdr_manager.conf.sample b/1.2-netsec/configs/cdr_manager.conf.sample
deleted file mode 100644
index 1d7984ba4..000000000
--- a/1.2-netsec/configs/cdr_manager.conf.sample
+++ /dev/null
@@ -1,6 +0,0 @@
-;
-; Asterisk Call Management CDR
-;
-[general]
-enabled = no
-
diff --git a/1.2-netsec/configs/cdr_odbc.conf.sample b/1.2-netsec/configs/cdr_odbc.conf.sample
deleted file mode 100644
index 6245e37eb..000000000
--- a/1.2-netsec/configs/cdr_odbc.conf.sample
+++ /dev/null
@@ -1,12 +0,0 @@
-;
-; cdr_odbc.conf
-;
-
-;[global]
-;dsn=MySQL-test
-;username=username
-;password=password
-;loguniqueid=yes
-;dispositionstring=yes
-;table=cdr ;"cdr" is default table name
-;usegmtime=no ; set to "yes" to log in GMT
diff --git a/1.2-netsec/configs/cdr_pgsql.conf.sample b/1.2-netsec/configs/cdr_pgsql.conf.sample
deleted file mode 100644
index 0784c7b08..000000000
--- a/1.2-netsec/configs/cdr_pgsql.conf.sample
+++ /dev/null
@@ -1,9 +0,0 @@
-; Sample Asterisk config file for CDR logging to PostgresSQL
-
-[global]
-;hostname=localhost
-;port=5432
-;dbname=asterisk
-;password=password
-;user=postgres
-;table=cdr ;SQL table where CDRs will be inserted
diff --git a/1.2-netsec/configs/cdr_tds.conf.sample b/1.2-netsec/configs/cdr_tds.conf.sample
deleted file mode 100644
index 9fffec099..000000000
--- a/1.2-netsec/configs/cdr_tds.conf.sample
+++ /dev/null
@@ -1,9 +0,0 @@
-; Sample Asterisk config file for CDR logging to FreeTDS
-
-;[global]
-;hostname=fs.malico.loc
-;port=1433
-;dbname=MalicoHN
-;user=mangUsr
-;password=
-;charset=BIG5
diff --git a/1.2-netsec/configs/codecs.conf.sample b/1.2-netsec/configs/codecs.conf.sample
deleted file mode 100644
index c8caeab60..000000000
--- a/1.2-netsec/configs/codecs.conf.sample
+++ /dev/null
@@ -1,65 +0,0 @@
-[speex]
-; CBR encoding quality [0..10]
-; used only when vbr = false
-quality => 3
-
-; codec complexity [0..10]
-; tradeoff between cpu/quality
-complexity => 2
-
-; perceptual enhancement [true / false]
-; improves clarity of decoded speech
-enhancement => true
-
-; voice activity detection [true / false]
-; reduces bitrate when no voice detected, used only for CBR
-; (implicit in VBR/ABR)
-vad => true
-
-; variable bit rate [true / false]
-; uses bit rate proportionate to voice complexity
-vbr => true
-
-; available bit rate [bps, 0 = off]
-; encoding quality modulated to match this target bit rate
-; not recommended with dtx or pp_vad - may cause bandwidth spikes
-abr => 0
-
-; VBR encoding quality [0-10]
-; floating-point values allowed
-vbr_quality => 4
-
-; discontinuous transmission [true / false]
-; stops transmitting completely when silence is detected
-; pp_vad is far more effective but more CPU intensive
-dtx => false
-
-; preprocessor configuration
-; these options only affect Speex v1.1.8 or newer
-
-; enable preprocessor [true / false]
-; allows dsp functionality below but incurs CPU overhead
-preprocess => false
-
-; preproc voice activity detection [true / false]
-; more advanced equivalent of DTX, based on voice frequencies
-pp_vad => false
-
-; preproc automatic gain control [true / false]
-pp_agc => false
-pp_agc_level => 8000
-
-; preproc denoiser [true / false]
-pp_denoise => false
-
-; preproc dereverb [true / false]
-pp_dereverb => false
-pp_dereverb_decay => 0.4
-pp_dereverb_level => 0.3
-
-
-[plc]
-; for all codecs which do not support native PLC
-; this determines whether to perform generic PLC
-; there is a minor performance penalty for this
-genericplc => true
diff --git a/1.2-netsec/configs/dnsmgr.conf.sample b/1.2-netsec/configs/dnsmgr.conf.sample
deleted file mode 100644
index e34dbcf0a..000000000
--- a/1.2-netsec/configs/dnsmgr.conf.sample
+++ /dev/null
@@ -1,5 +0,0 @@
-[general]
-;enable=yes ; enable creation of managed DNS lookups
- ; default is 'no'
-;refreshinterval=1200 ; refresh managed DNS lookups every <n> seconds
- ; default is 300 (5 minutes) \ No newline at end of file
diff --git a/1.2-netsec/configs/dundi.conf.sample b/1.2-netsec/configs/dundi.conf.sample
deleted file mode 100644
index a3c8c77d9..000000000
--- a/1.2-netsec/configs/dundi.conf.sample
+++ /dev/null
@@ -1,239 +0,0 @@
-;
-; DUNDi configuration file
-;
-; For more information about DUNDi, see http://www.dundi.com
-;
-;
-[general]
-;
-; The "general" section contains general parameters relating
-; to the operation of the dundi client and server.
-;
-; The first part should be your complete contact information
-; should someone else in your peer group need to contact you.
-;
-;department=Your Department
-;organization=Your Company, Inc.
-;locality=Your City
-;stateprov=ST
-;country=US
-;email=your@email.com
-;phone=+12565551212
-;
-;
-; Specify bind address and port number. Default is
-; 4520
-;
-;bindaddr=0.0.0.0
-;port=4520
-;
-; Our entity identifier (Should generally be the MAC address of the
-; machine it's running on. Defaults to the first eth address, but you
-; can override it here, as long as you set it to the MAC of *something*
-; you own!)
-;
-;entityid=00:07:E9:3B:76:60
-;
-; Peers shall cache our query responses for the specified time,
-; given in seconds. Default is 3600.
-;
-;cachetime=3600
-;
-; This defines the max depth in which to search the DUNDi system.
-; Note that the maximum time that we will wait for a response is
-; (2000 + 200 * ttl) ms.
-;
-ttl=32
-;
-; If we don't get ACK to our DPDISCOVER within 2000ms, and autokill is set
-; to yes, then we cancel the whole thing (that's enough time for one
-; retransmission only). This is used to keep things from stalling for a long
-; time for a host that is not available, but would be ill advised for bad
-; connections. In addition to 'yes' or 'no' you can also specify a number
-; of milliseconds. See 'qualify' for individual peers to turn on for just
-; a specific peer.
-;
-autokill=yes
-;
-; pbx_dundi creates a rotating key called "secret", under the family
-; 'secretpath'. The default family is dundi (resulting in
-; the key being held at dundi/secret).
-;
-;secretpath=dundi
-;
-; The 'storehistory' option (also changeable at runtime with
-; 'dundi store history' and 'dundi no store history') will
-; cause the DUNDi engine to keep track of the last several
-; queries and the amount of time each query took to execute
-; for the purpose of tracking slow nodes. This option is
-; off by default due to performance impacts.
-;
-;storehistory=yes
-
-[mappings]
-;
-; The "mappings" section maps DUNDi contexts
-; to contexts on the local asterisk system. Remember
-; that numbers that are made available under the e164
-; DUNDi context are regulated by the DUNDi General Peering
-; Agreement (GPA) if you are a member of the DUNDi E.164
-; Peering System.
-;
-; dundi_context => local_context,weight,tech,dest[,options]]
-;
-; 'dundi_context' is the name of the context being requested
-; within the DUNDi request
-;
-; 'local_context' is the name of the context on the local system
-; in which numbers can be looked up for which responses shall be given.
-;
-; 'weight' is the weight to use for the responses provided from this
-; mapping. The number must be >= 0 and < 60000. Since it is totally
-; valid to receive multiple reponses to a query, responses received
-; with a lower weight are tried first. Note that the weight has a
-; special meaning in the e164 context - see the GPA for more details.
-;
-; 'tech' is the technology to use (IAX, SIP, H323)
-;
-; 'dest' is the destination to supply for reaching that number. The
-; following variables can be used in the destination string and will
-; be automatically substituted:
-; ${NUMBER}: The number being requested
-; ${IPADDR}: The IP address to connect to
-; ${SECRET}: The current rotating secret key to be used
-;
-; Further options may include:
-;
-; nounsolicited: No unsolicited calls of any type permitted via this
-; route
-; nocomunsolicit: No commercial unsolicited calls permitted via
-; this route
-; residential: This number is known to be a residence
-; commercial: This number is known to be a business
-; mobile: This number is known to be a mobile phone
-; nocomunsolicit: No commercial unsolicited calls permitted via
-; this route
-; nopartial: Do not search for partial matches
-;
-; There *must* exist an entry in mappings for DUNDi to respond
-; to any request, although it may be empty.
-;
-;e164 => dundi-e164-canonical,0,IAX2,dundi:${SECRET}@${IPADDR}/${NUMBER},nounsolicited,nocomunsolicit,nopartial
-;e164 => dundi-e164-customers,100,IAX2,dundi:${SECRET}@${IPADDR}/${NUMBER},nounsolicited,nocomunsolicit,nopartial
-;e164 => dundi-e164-via-pstn,400,IAX2,dundi:${SECRET}@${IPADDR}/${NUMBER},nounsolicited,nocomunsolicit,nopartial
-
-;digexten => default,0,IAX2,guest@lappy/${NUMBER}
-;asdf =>
-
-
-;
-;
-; The remaining sections represent the peers
-; that we fundamentally trust. The section name
-; represents the name and optionally at a specific
-; DUNDi context if you want the trust to be established
-; for only a specific DUNDi context.
-;
-; inkey - What key they will be authenticating to us with
-;
-; outkey - What key we use to authenticate to them
-;
-; host - What their host is
-;
-; order - What search order to use. May be 'primary', 'secondary',
-; 'tertiary' or 'quartiary'. In large systems, it is beneficial
-; to only query one up-stream host in order to maximize caching
-; value. Adding one with primary and one with secondary gives you
-; redundancy without sacraficing performance.
-;
-; include - Includes this peer when searching a particular context
-; for lookup (set "all" to perform all lookups with that
-; host. This is also the context in which peers are permitted
-; to precache.
-;
-; noinclude - Disincludes this peer when searching a particular context
-; for lookup (set "all" to perform no lookups with that
-; host.
-;
-; permit - Permits this peer to search a given DUNDi context on
-; the local system. Set "all" to permit this host to
-; lookup all contexts. This is also a context for which
-; we will create/forward PRECACHE commands.
-;
-; deny - Denies this peer to search a given DUNDi context on
-; the local system. Set "all" to deny this host to
-; lookup all contexts.
-;
-; model - inbound, outbound, or symmetric for whether we receive
-; requests only, transmit requests only, or do both.
-;
-; precache - Utilize/Permit precaching with this peer (to pre
-; cache means to provide an answer when no request
-; was made and is used so that machines with few
-; routes can push those routes up a to a higher level).
-; outgoing means we send precache routes to this peer,
-; incoming means we permit this peer to send us
-; precache routes. symmetric means we do both.
-;
-; Note: You cannot mix symmetric/outbound model with symmetric/inbound
-; precache, nor can you mix symmetric/inbound model with symmetric/outbound
-; precache.
-;
-;
-; The '*' peer is special and matches an unspecified entity
-;
-
-;
-; Sample Primary e164 DUNDi peer
-;
-;[00:50:8B:F3:75:BB]
-;model = symmetric
-;host = 64.215.96.114
-;inkey = digium
-;outkey = misery
-;include = e164
-;permit = e164
-;qualify = yes
-
-;
-; Sample Secondary e164 DUNDi peer
-;
-;[00:A0:C9:96:92:84]
-;model = symmetric
-;host = misery.digium.com
-;inkey = misery
-;outkey = ourkey
-;include = e164
-;permit = e164
-;qualify = yes
-;order = secondary
-
-;
-; Sample "push mode" downstream host
-;
-;[00:0C:76:96:75:28]
-;model = inbound
-;host = dynamic
-;precache = inbound
-;inkey = littleguy
-;outkey = ourkey
-;include = e164 ; In this case used only for precaching
-;permit = e164
-;qualify = yes
-
-;
-; Sample "push mode" upstream host
-;
-;[00:07:E9:3B:76:60]
-;model = outbound
-;precache = outbound
-;host = 216.207.245.34
-;register = yes
-;inkey = dhcp34
-;permit = all ; In this case used only for precaching
-;include = all
-;qualify = yes
-;outkey=foo
-
-;[*]
-;
diff --git a/1.2-netsec/configs/enum.conf.sample b/1.2-netsec/configs/enum.conf.sample
deleted file mode 100644
index 8d7054a24..000000000
--- a/1.2-netsec/configs/enum.conf.sample
+++ /dev/null
@@ -1,22 +0,0 @@
-;
-; ENUM Configuration for resolving phone numbers over DNS
-;
-; Sample config for Asterisk
-; This file is reloaded at "reload enum" in the CLI
-;
-[general]
-;
-; The search list for domains may be customized. Domains are searched
-; in the order they are listed here.
-;
-search => e164.arpa
-;
-; If you'd like to use the E.164.org public ENUM registery in addition
-; to the official e164.arpa one, uncomment the following line
-;
-;search => e164.org
-;
-; As there are more H323 drivers available you have to select to which
-; drive a H323 URI will map. Default is "H323".
-;
-h323driver => H323
diff --git a/1.2-netsec/configs/extconfig.conf.sample b/1.2-netsec/configs/extconfig.conf.sample
deleted file mode 100644
index 1cf923fb3..000000000
--- a/1.2-netsec/configs/extconfig.conf.sample
+++ /dev/null
@@ -1,51 +0,0 @@
-;
-; Static and realtime external configuration
-; engine configuration
-;
-; Please read doc/README.extconfig for basic table
-; formatting information.
-;
-[settings]
-;
-; Static configuration files:
-;
-; file.conf => driver,database[,table]
-;
-; maps a particular configuration file to the given
-; database driver, database and table (or uses the
-; name of the file as the table if not specified)
-;
-;uncomment to load queues.conf via the odbc engine.
-;
-;queues.conf => odbc,asterisk,ast_config
-;
-; The following files CANNOT be loaded from Realtime storage:
-; asterisk.conf
-; extconfig.conf (this file)
-; logger.conf
-;
-; Additionally, the following files cannot be loaded from
-; Realtime storage unless the storage driver is loaded
-; early using 'preload' statements in modules.conf:
-; manager.conf
-; cdr.conf
-; rtp.conf
-;
-;
-; Realtime configuration engine
-;
-; maps a particular family of realtime
-; configuration to a given database driver,
-; database and table (or uses the name of
-; the family if the table is not specified
-;
-;example => odbc,asterisk,alttable
-;iaxusers => odbc,asterisk
-;iaxpeers => odbc,asterisk
-;sipusers => odbc,asterisk
-;sippeers => odbc,asterisk
-;voicemail => odbc,asterisk
-;extensions => odbc,asterisk
-;queues => odbc,asterisk
-;queue_members => odbc,asterisk
-
diff --git a/1.2-netsec/configs/extensions.ael.sample b/1.2-netsec/configs/extensions.ael.sample
deleted file mode 100644
index 87fe58039..000000000
--- a/1.2-netsec/configs/extensions.ael.sample
+++ /dev/null
@@ -1,62 +0,0 @@
-//
-// Example AEL config file
-//
-
-macro std-exten-ael( ext , dev ) {
- Dial(${dev}/${ext},20);
- switch(${DIALSTATUS}) {
- case BUSY:
- Voicemail(b${ext});
- break;
- default:
- Voicemail(u${ext});
- };
- catch a {
- VoiceMailMain(${ext});
- return;
- };
-};
-
-context ael-demo {
- s => {
- Wait(1);
- Answer();
- TIMEOUT(digit)=5;
- TIMEOUT(response)=10;
-restart:
- Background(demo-congrats);
-instructions:
- for (x=0; ${x} < 3; x=${x} + 1) {
- Background(demo-instruct);
- WaitExten();
- };
- };
- 2 => {
- Background(demo-moreinfo);
- goto s|instructions;
- };
- 3 => {
- LANGUAGE()=fr;
- goto s|restart;
- };
- 500 => {
- Playback(demo-abouttotry);
- Dial(IAX2/guest@misery.digium.com);
- Playback(demo-nogo);
- goto s|instructions;
- };
- 600 => {
- Playback(demo-echotest);
- Echo();
- Playback(demo-echodone);
- goto s|instructions;
- };
- _1234 => &std-exten-ael(${EXTEN}, "IAX2");
- # => {
- Playback(demo-thanks);
- Hangup();
- };
- t => jump #;
- i => Playback(invalid);
-};
-
diff --git a/1.2-netsec/configs/extensions.conf.sample b/1.2-netsec/configs/extensions.conf.sample
deleted file mode 100644
index d773cbbc3..000000000
--- a/1.2-netsec/configs/extensions.conf.sample
+++ /dev/null
@@ -1,492 +0,0 @@
-;
-; Static extension configuration file, used by
-; the pbx_config module. This is where you configure all your
-; inbound and outbound calls in Asterisk.
-;
-; This configuration file is reloaded
-; - With the "extensions reload" command in the CLI
-; - With the "reload" command (that reloads everything) in the CLI
-
-;
-; The "General" category is for certain variables.
-;
-[general]
-;
-; If static is set to no, or omitted, then the pbx_config will rewrite
-; this file when extensions are modified. Remember that all comments
-; made in the file will be lost when that happens.
-;
-; XXX Not yet implemented XXX
-;
-static=yes
-;
-; if static=yes and writeprotect=no, you can save dialplan by
-; CLI command 'save dialplan' too
-;
-writeprotect=no
-;
-; If autofallthrough is set, then if an extension runs out of
-; things to do, it will terminate the call with BUSY, CONGESTION
-; or HANGUP depending on Asterisk's best guess (strongly recommended).
-;
-; If autofallthrough is not set, then if an extension runs out of
-; things to do, asterisk will wait for a new extension to be dialed
-; (this is the original behavior of Asterisk 1.0 and earlier).
-;
-autofallthrough=yes
-;
-; If clearglobalvars is set, global variables will be cleared
-; and reparsed on an extensions reload, or Asterisk reload.
-;
-; If clearglobalvars is not set, then global variables will persist
-; through reloads, and even if deleted from the extensions.conf or
-; one if its included files, will remain set to the previous value.
-;
-clearglobalvars=no
-;
-; If priorityjumping is set to 'yes', then applications that support
-; 'jumping' to a different priority based on the result of their operations
-; will do so (this is backwards compatible behavior with pre-1.2 releases
-; of Asterisk). Individual applications can also be requested to do this
-; by passing a 'j' option in their arguments.
-;
-priorityjumping=no
-;
-; You can include other config files, use the #include command
-; (without the ';'). Note that this is different from the "include" command
-; that includes contexts within other contexts. The #include command works
-; in all asterisk configuration files.
-;#include "filename.conf"
-
-; The "Globals" category contains global variables that can be referenced
-; in the dialplan with ${VARIABLE} or ${ENV(VARIABLE)} for Environmental
-; variables,
-; ${${VARIABLE}} or ${text${VARIABLE}} or any hybrid
-;
-[globals]
-CONSOLE=Console/dsp ; Console interface for demo
-;CONSOLE=Zap/1
-;CONSOLE=Phone/phone0
-IAXINFO=guest ; IAXtel username/password
-;IAXINFO=myuser:mypass
-TRUNK=Zap/g2 ; Trunk interface
-;
-; Note the 'g2' in the TRUNK variable above. It specifies which group (defined
-; in zapata.conf) to dial, i.e. group 2, and how to choose a channel to use in
-; the specified group. The four possible options are:
-;
-; g: select the lowest-numbered non-busy Zap channel
-; (aka. ascending sequential hunt group).
-; G: select the highest-numbered non-busy Zap channel
-; (aka. descending sequential hunt group).
-; r: use a round-robin search, starting at the next highest channel than last
-; time (aka. ascending rotary hunt group).
-; R: use a round-robin search, starting at the next lowest channel than last
-; time (aka. descending rotary hunt group).
-;
-TRUNKMSD=1 ; MSD digits to strip (usually 1 or 0)
-;TRUNK=IAX2/user:pass@provider
-
-;
-; Any category other than "General" and "Globals" represent
-; extension contexts, which are collections of extensions.
-;
-; Extension names may be numbers, letters, or combinations
-; thereof. If an extension name is prefixed by a '_'
-; character, it is interpreted as a pattern rather than a
-; literal. In patterns, some characters have special meanings:
-;
-; X - any digit from 0-9
-; Z - any digit from 1-9
-; N - any digit from 2-9
-; [1235-9] - any digit in the brackets (in this example, 1,2,3,5,6,7,8,9)
-; . - wildcard, matches anything remaining (e.g. _9011. matches
-; anything starting with 9011 excluding 9011 itself)
-; ! - wildcard, causes the matching process to complete as soon as
-; it can unambiguously determine that no other matches are possible
-;
-; For example the extension _NXXXXXX would match normal 7 digit dialings,
-; while _1NXXNXXXXXX would represent an area code plus phone number
-; preceeded by a one.
-;
-; Each step of an extension is ordered by priority, which must
-; always start with 1 to be considered a valid extension. The priority
-; "next" or "n" means the previous priority plus one, regardless of whether
-; the previous priority was associated with the current extension or not.
-; The priority "same" or "s" means the same as the previously specified
-; priority, again regardless of whether the previous entry was for the
-; same extension. Priorities may be immediately followed by a plus sign
-; and another integer to add that amount (most useful with 's' or 'n').
-; Priorities may then also have an alias, or label, in
-; parenthesis after their name which can be used in goto situations
-;
-; Contexts contain several lines, one for each step of each
-; extension, which can take one of two forms as listed below,
-; with the first form being preferred. One may include another
-; context in the current one as well, optionally with a
-; date and time. Included contexts are included in the order
-; they are listed.
-;
-;[context]
-;exten => someexten,priority[+offset][(alias)],application(arg1,arg2,...)
-;exten => someexten,priority[+offset][(alias)],application,arg1|arg2...
-;
-; Timing list for includes is
-;
-; <time range>|<days of week>|<days of month>|<months>
-;
-;include => daytime|9:00-17:00|mon-fri|*|*
-;
-; ignorepat can be used to instruct drivers to not cancel dialtone upon
-; receipt of a particular pattern. The most commonly used example is
-; of course '9' like this:
-;
-;ignorepat => 9
-;
-; so that dialtone remains even after dialing a 9.
-;
-
-;
-; Sample entries for extensions.conf
-;
-;
-[dundi-e164-canonical]
-;
-; List canonical entries here
-;
-;exten => 12564286000,1,Macro(std-exten,6000,IAX2/foo)
-;exten => _125642860XX,1,Dial(IAX2/otherbox/${EXTEN:7})
-
-[dundi-e164-customers]
-;
-; If you are an ITSP or Reseller, list your customers here.
-;
-;exten => _12564286000,1,Dial(SIP/customer1)
-;exten => _12564286001,1,Dial(IAX2/customer2)
-
-[dundi-e164-via-pstn]
-;
-; If you are freely delivering calls to the PSTN, list them here
-;
-;exten => _1256428XXXX,1,Dial(Zap/g2/${EXTEN:7}) ; Expose all of 256-428
-;exten => _1256325XXXX,1,Dial(Zap/g2/${EXTEN:7}) ; Ditto for 256-325
-
-[dundi-e164-local]
-;
-; Context to put your dundi IAX2 or SIP user in for
-; full access
-;
-include => dundi-e164-canonical
-include => dundi-e164-customers
-include => dundi-e164-via-pstn
-
-[dundi-e164-switch]
-;
-; Just a wrapper for the switch
-;
-switch => DUNDi/e164
-
-[dundi-e164-lookup]
-;
-; Locally to lookup, try looking for a local E.164 solution
-; then try DUNDi if we don't have one.
-;
-include => dundi-e164-local
-include => dundi-e164-switch
-;
-; DUNDi can also be implemented as a Macro instead of using
-; the Local channel driver.
-;
-[macro-dundi-e164]
-;
-; ARG1 is the extension to Dial
-;
-exten => s,1,Goto(${ARG1},1)
-include => dundi-e164-lookup
-
-;
-; Here are the entries you need to participate in the IAXTEL
-; call routing system. Most IAXTEL numbers begin with 1-700, but
-; there are exceptions. For more information, and to sign
-; up, please go to www.gnophone.com or www.iaxtel.com
-;
-[iaxtel700]
-exten => _91700XXXXXXX,1,Dial(IAX2/${IAXINFO}@iaxtel.com/${EXTEN:1}@iaxtel)
-
-;
-; The SWITCH statement permits a server to share the dialplain with
-; another server. Use with care: Reciprocal switch statements are not
-; allowed (e.g. both A -> B and B -> A), and the switched server needs
-; to be on-line or else dialing can be severly delayed.
-;
-[iaxprovider]
-;switch => IAX2/user:[key]@myserver/mycontext
-
-[trunkint]
-;
-; International long distance through trunk
-;
-exten => _9011.,1,Macro(dundi-e164,${EXTEN:4})
-exten => _9011.,n,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
-
-[trunkld]
-;
-; Long distance context accessed through trunk
-;
-exten => _91NXXNXXXXXX,1,Macro(dundi-e164,${EXTEN:1})
-exten => _91NXXNXXXXXX,n,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
-
-[trunklocal]
-;
-; Local seven-digit dialing accessed through trunk interface
-;
-exten => _9NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
-
-[trunktollfree]
-;
-; Long distance context accessed through trunk interface
-;
-exten => _91800NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
-exten => _91888NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
-exten => _91877NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
-exten => _91866NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
-
-[international]
-;
-; Master context for international long distance
-;
-ignorepat => 9
-include => longdistance
-include => trunkint
-
-[longdistance]
-;
-; Master context for long distance
-;
-ignorepat => 9
-include => local
-include => trunkld
-
-[local]
-;
-; Master context for local, toll-free, and iaxtel calls only
-;
-ignorepat => 9
-include => default
-include => parkedcalls
-include => trunklocal
-include => iaxtel700
-include => trunktollfree
-include => iaxprovider
-;
-; You can use an alternative switch type as well, to resolve
-; extensions that are not known here, for example with remote
-; IAX switching you transparently get access to the remote
-; Asterisk PBX
-;
-; switch => IAX2/user:password@bigserver/local
-;
-; An "lswitch" is like a switch but is literal, in that
-; variable substitution is not performed at load time
-; but is passed to the switch directly (presumably to
-; be substituted in the switch routine itself)
-;
-; lswitch => Loopback/12${EXTEN}@othercontext
-;
-; An "eswitch" is like a switch but the evaluation of
-; variable substitution is performed at runtime before
-; being passed to the switch routine.
-;
-; eswitch => IAX2/context@${CURSERVER}
-
-[macro-stdexten];
-;
-; Standard extension macro:
-; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well
-; ${ARG2} - Device(s) to ring
-;
-exten => s,1,Dial(${ARG2},20) ; Ring the interface, 20 seconds maximum
-exten => s,2,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
-
-exten => s-NOANSWER,1,Voicemail(u${ARG1}) ; If unavailable, send to voicemail w/ unavail announce
-exten => s-NOANSWER,2,Goto(default,s,1) ; If they press #, return to start
-
-exten => s-BUSY,1,Voicemail(b${ARG1}) ; If busy, send to voicemail w/ busy announce
-exten => s-BUSY,2,Goto(default,s,1) ; If they press #, return to start
-
-exten => _s-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
-
-exten => a,1,VoicemailMain(${ARG1}) ; If they press *, send the user into VoicemailMain
-
-[macro-stdPrivacyexten];
-;
-; Standard extension macro:
-; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well
-; ${ARG2} - Device(s) to ring
-; ${ARG3} - Optional DONTCALL context name to jump to (assumes the s,1 extension-priority)
-; ${ARG4} - Optional TORTURE context name to jump to (assumes the s,1 extension-priority)`
-;
-exten => s,1,Dial(${ARG2},20|p) ; Ring the interface, 20 seconds maximum, call screening option (or use P for databased call screening)
-exten => s,2,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
-
-exten => s-NOANSWER,1,Voicemail(u${ARG1}) ; If unavailable, send to voicemail w/ unavail announce
-exten => s-NOANSWER,2,Goto(default,s,1) ; If they press #, return to start
-
-exten => s-BUSY,1,Voicemail(b${ARG1}) ; If busy, send to voicemail w/ busy announce
-exten => s-BUSY,2,Goto(default,s,1) ; If they press #, return to start
-
-exten => s-DONTCALL,1,Goto(${ARG3},s,1) ; Callee chose to send this call to a polite "Don't call again" script.
-
-exten => s-TORTURE,1,Goto(${ARG4},s,1) ; Callee chose to send this call to a telemarketer torture script.
-
-exten => _s-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
-
-exten => a,1,VoicemailMain(${ARG1}) ; If they press *, send the user into VoicemailMain
-
-[demo]
-;
-; We start with what to do when a call first comes in.
-;
-exten => s,1,Wait,1 ; Wait a second, just for fun
-exten => s,n,Answer ; Answer the line
-exten => s,n,Set(TIMEOUT(digit)=5) ; Set Digit Timeout to 5 seconds
-exten => s,n,Set(TIMEOUT(response)=10) ; Set Response Timeout to 10 seconds
-exten => s,n(restart),BackGround(demo-congrats) ; Play a congratulatory message
-exten => s,n(instruct),BackGround(demo-instruct) ; Play some instructions
-exten => s,n,WaitExten ; Wait for an extension to be dialed.
-
-exten => 2,1,BackGround(demo-moreinfo) ; Give some more information.
-exten => 2,n,Goto(s,instruct)
-
-exten => 3,1,Set(LANGUAGE()=fr) ; Set language to french
-exten => 3,n,Goto(s,restart) ; Start with the congratulations
-
-exten => 1000,1,Goto(default,s,1)
-;
-; We also create an example user, 1234, who is on the console and has
-; voicemail, etc.
-;
-exten => 1234,1,Playback(transfer,skip) ; "Please hold while..."
- ; (but skip if channel is not up)
-exten => 1234,n,Macro(stdexten,1234,${CONSOLE})
-
-exten => 1235,1,Voicemail(u1234) ; Right to voicemail
-
-exten => 1236,1,Dial(Console/dsp) ; Ring forever
-exten => 1236,n,Voicemail(u1234) ; Unless busy
-
-;
-; # for when they're done with the demo
-;
-exten => #,1,Playback(demo-thanks) ; "Thanks for trying the demo"
-exten => #,n,Hangup ; Hang them up.
-
-;
-; A timeout and "invalid extension rule"
-;
-exten => t,1,Goto(#,1) ; If they take too long, give up
-exten => i,1,Playback(invalid) ; "That's not valid, try again"
-
-;
-; Create an extension, 500, for dialing the
-; Asterisk demo.
-;
-exten => 500,1,Playback(demo-abouttotry); Let them know what's going on
-exten => 500,n,Dial(IAX2/guest@misery.digium.com/s@default) ; Call the Asterisk demo
-exten => 500,n,Playback(demo-nogo) ; Couldn't connect to the demo site
-exten => 500,n,Goto(s,6) ; Return to the start over message.
-
-;
-; Create an extension, 600, for evaulating echo latency.
-;
-exten => 600,1,Playback(demo-echotest) ; Let them know what's going on
-exten => 600,n,Echo ; Do the echo test
-exten => 600,n,Playback(demo-echodone) ; Let them know it's over
-exten => 600,n,Goto(s,6) ; Start over
-
-;
-; Give voicemail at extension 8500
-;
-exten => 8500,1,VoicemailMain
-exten => 8500,n,Goto(s,6)
-;
-; Here's what a phone entry would look like (IXJ for example)
-;
-;exten => 1265,1,Dial(Phone/phone0,15)
-;exten => 1265,n,Goto(s,5)
-
-;[mainmenu]
-;
-; Example "main menu" context with submenu
-;
-;exten => s,1,Answer
-;exten => s,n,Background(thanks) ; "Thanks for calling press 1 for sales, 2 for support, ..."
-;exten => s,n,WaitExten
-;exten => 1,1,Goto(submenu,s,1)
-;exten => 2,1,Hangup
-;include => default
-;
-;[submenu]
-;exten => s,1,Ringing ; Make them comfortable with 2 seconds of ringback
-;exten => s,n,Wait,2
-;exten => s,n,Background(submenuopts) ; "Thanks for calling the sales department. Press 1 for steve, 2 for..."
-;exten => s,n,WaitExten
-;exten => 1,1,Goto(default,steve,1)
-;exten => 2,1,Goto(default,mark,2)
-
-[default]
-;
-; By default we include the demo. In a production system, you
-; probably don't want to have the demo there.
-;
-include => demo
-
-;
-; Extensions like the two below can be used for FWD, Nikotel, sipgate etc.
-; Note that you must have a [sipprovider] section in sip.conf whereas
-; the otherprovider.net example does not require such a peer definition
-;
-;exten => _41X.,1,Dial(SIP/${EXTEN:2}@sipprovider,,r)
-;exten => _42X.,1,Dial(SIP/user:passwd@${EXTEN:2}@otherprovider.net,30,rT)
-
-; Real extensions would go here. Generally you want real extensions to be
-; 4 or 5 digits long (although there is no such requirement) and start with a
-; single digit that is fairly large (like 6 or 7) so that you have plenty of
-; room to overlap extensions and menu options without conflict. You can alias
-; them with names, too, and use global variables
-
-;exten => 6245,hint,SIP/Grandstream1&SIP/Xlite1,Joe Schmoe ; Channel hints for presence
-;exten => 6245,1,Dial(SIP/Grandstream1,20,rt) ; permit transfer
-;exten => 6245,n(dial),Dial(${HINT},20,rtT) ; Use hint as listed
-;exten => 6245,n,Voicemail(u6245) ; Voicemail (unavailable)
-;exten => 6245,s+1,Hangup ; s+1, same as n
-;exten => 6245,dial+101,Voicemail(b6245) ; Voicemail (busy)
-;exten => 6361,1,Dial(IAX2/JaneDoe,,rm) ; ring without time limit
-;exten => 6389,1,Dial(MGCP/aaln/1@192.168.0.14)
-;exten => 6394,1,Dial(Local/6275/n) ; this will dial ${MARK}
-
-;exten => 6275,1,Macro(stdexten,6275,${MARK}) ; assuming ${MARK} is something like Zap/2
-;exten => mark,1,Goto(6275|1) ; alias mark to 6275
-;exten => 6536,1,Macro(stdexten,6236,${WIL}) ; Ditto for wil
-;exten => wil,1,Goto(6236|1)
-;
-; Some other handy things are an extension for checking voicemail via
-; voicemailmain
-;
-;exten => 8500,1,VoicemailMain
-;exten => 8500,n,Hangup
-;
-; Or a conference room (you'll need to edit meetme.conf to enable this room)
-;
-;exten => 8600,1,Meetme(1234)
-;
-; Or playing an announcement to the called party, as soon it answers
-;
-;exten = 8700,1,Dial(${MARK},30,A(/path/to/my/announcemsg))
-;
-; For more information on applications, just type "show applications" at your
-; friendly Asterisk CLI prompt.
-;
-; 'show application <command>' will show details of how you
-; use that particular application in this file, the dial plan.
-;
diff --git a/1.2-netsec/configs/features.conf.sample b/1.2-netsec/configs/features.conf.sample
deleted file mode 100644
index 346d65192..000000000
--- a/1.2-netsec/configs/features.conf.sample
+++ /dev/null
@@ -1,32 +0,0 @@
-;
-; Sample Parking configuration
-;
-
-[general]
-parkext => 700 ; What ext. to dial to park
-parkpos => 701-720 ; What extensions to park calls on
-context => parkedcalls ; Which context parked calls are in
-;parkingtime => 45 ; Number of seconds a call can be parked for
- ; (default is 45 seconds)
-;transferdigittimeout => 3 ; Number of seconds to wait between digits when transfering a call
-;courtesytone = beep ; Sound file to play to the parked caller
- ; when someone dials a parked call
-;xfersound = beep ; to indicate an attended transfer is complete
-;xferfailsound = beeperr ; to indicate a failed transfer
-;adsipark = yes ; if you want ADSI parking announcements
-;findslot => next ; Continue to the 'next' parking space. Defaults to 'first' available
-;pickupexten = *8 ; Configure the pickup extension. Default is *8
-;featuredigittimeout = 500 ; Max time (ms) between digits for
- ; feature activation. Default is 500
-
-
-[featuremap]
-;blindxfer => #1 ; Blind transfer
-;disconnect => *0 ; Disconnect
-;automon => *1 ; One Touch Record
-;atxfer => *2 ; Attended transfer
-
-[applicationmap]
-;testfeature => #9,callee,Playback,tt-monkeys ;Play tt-monkeys to
- ;callee if #9 was pressed
-
diff --git a/1.2-netsec/configs/festival.conf.sample b/1.2-netsec/configs/festival.conf.sample
deleted file mode 100644
index 774f1a16c..000000000
--- a/1.2-netsec/configs/festival.conf.sample
+++ /dev/null
@@ -1,35 +0,0 @@
-;
-; Festival Configuration
-;
-[general]
-;
-; Host which runs the festival server (default : localhost);
-;
-;host=localhost
-;
-; Port on host where the festival server runs (default : 1314)
-;
-;port=1314
-;
-; Use cache (yes, no - defaults to no)
-;
-;usecache=yes
-;
-; If usecache=yes, a directory to store waveform cache files.
-; The cache is never cleared (yet), so you must take care of cleaning it
-; yourself (just delete any or all files from the cache).
-; THIS DIRECTORY *MUST* EXIST and must be writable from the asterisk process.
-; Defaults to /tmp/
-;
-;cachedir=/var/lib/asterisk/festivalcache/
-;
-; Festival command to send to the server.
-; Defaults to: (tts_textasterisk "%s" 'file)(quit)\n
-; %s is replaced by the desired text to say. The command MUST end with a
-; (quit) directive, or the cache handling mechanism will hang. Do not
-; forget the \n at the end.
-;
-;festivalcommand=(tts_textasterisk "%s" 'file)(quit)\n
-;
-;
-
diff --git a/1.2-netsec/configs/iax.conf.sample b/1.2-netsec/configs/iax.conf.sample
deleted file mode 100644
index 26d637d8d..000000000
--- a/1.2-netsec/configs/iax.conf.sample
+++ /dev/null
@@ -1,418 +0,0 @@
-
-; Inter-Asterisk eXchange driver definition
-;
-; This configuration is re-read at reload
-; or with the CLI command
-; reload chan_iax2.so
-;
-; General settings, like port number to bind to, and
-; an option address (the default is to bind to all
-; local addresses).
-;
-[general]
-;bindport=4569 ; bindport and bindaddr may be specified
-; ; NOTE: bindport must be specified BEFORE bindaddr
-; ; or may be specified on a specific bindaddr if followed by
-; ; colon and port (e.g. bindaddr=192.168.0.1:4569)
-;bindaddr=192.168.0.1 ; more than once to bind to multiple
-; ; addresses, but the first will be the
-; ; default
-;
-; Set iaxcompat to yes if you plan to use layered switches or
-; some other scenario which may cause some delay when doing a
-; lookup in the dialplan. It incurs a small performance hit to
-; enable it. This option causes Asterisk to spawn a separate thread
-; when it receives an IAX DPREQ (Dialplan Request) instead of
-; blocking while it waits for a response.
-;
-;iaxcompat=yes
-;
-; Disable UDP checksums (if nochecksums is set, then no checkums will
-; be calculated/checked on systems supporting this feature)
-;
-;nochecksums=no
-;
-;
-; For increased security against brute force password attacks
-; enable "delayreject" which will delay the sending of authentication
-; reject for REGREQ or AUTHREP if there is a password.
-;
-;delayreject=yes
-;
-; You may specify a global default AMA flag for iaxtel calls. It must be
-; one of 'default', 'omit', 'billing', or 'documentation'. These flags
-; are used in the generation of call detail records.
-;
-;amaflags=default
-;
-; You may specify a default account for Call Detail Records in addition
-; to specifying on a per-user basis
-;
-;accountcode=lss0101
-;
-; You may specify a global default language for users.
-; Can be specified also on a per-user basis
-; If omitted, will fallback to english
-;
-;language=en
-;
-; Specify bandwidth of low, medium, or high to control which codecs are used
-; in general.
-;
-bandwidth=low
-;
-; You can also fine tune codecs here using "allow" and "disallow" clauses
-; with specific codecs. Use "all" to represent all formats.
-;
-;allow=all ; same as bandwidth=high
-;disallow=g723.1 ; Hm... Proprietary, don't use it...
-disallow=lpc10 ; Icky sound quality... Mr. Roboto.
-;allow=gsm ; Always allow GSM, it's cool :)
-;
-
-; You can adjust several parameters relating to the jitter buffer.
-; The jitter buffer's function is to compensate for varying
-; network delay.
-;
-; There are presently two jitterbuffer implementations available for Asterisk
-; and chan_iax2; the classic and the new, channel/application independent
-; implementation. These are controlled at compile-time. The new jitterbuffer
-; additionally has support for PLC which greatly improves quality as the
-; jitterbuffer adapts size, and in compensating for lost packets.
-;
-; All the jitter buffer settings except dropcount are in milliseconds.
-; The jitter buffer works for INCOMING audio - the outbound audio
-; will be dejittered by the jitter buffer at the other end.
-;
-; jitterbuffer=yes|no: global default as to whether you want
-; the jitter buffer at all.
-;
-; forcejitterbuffer=yes|no: in the ideal world, when we bridge VoIP channels
-; we don't want to do jitterbuffering on the switch, since the endpoints
-; can each handle this. However, some endpoints may have poor jitterbuffers
-; themselves, so this option will force * to always jitterbuffer, even in this
-; case.
-; [This option presently applies only to the new jitterbuffer implementation]
-;
-; dropcount: the jitter buffer is sized such that no more than "dropcount"
-; frames would have been "too late" over the last 2 seconds.
-; Set to a small number. "3" represents 1.5% of frames dropped
-; [This option is not applicable to, and ignored by the new jitterbuffer implementation]
-;
-; maxjitterbuffer: a maximum size for the jitter buffer.
-; Setting a reasonable maximum here will prevent the call delay
-; from rising to silly values in extreme situations; you'll hear
-; SOMETHING, even though it will be jittery.
-;
-; resyncthreshold: when the jitterbuffer notices a significant change in delay
-; that continues over a few frames, it will resync, assuming that the change in
-; delay was caused by a timestamping mix-up. The threshold for noticing a
-; change in delay is measured as twice the measured jitter plus this resync
-; threshold.
-; Resyncing can be disabled by setting this parameter to -1.
-; [This option presently applies only to the new jitterbuffer implementation]
-;
-; maxjitterinterps: the maximum number of interpolation frames the jitterbuffer
-; should return in a row. Since some clients do not send CNG/DTX frames to
-; indicate silence, the jitterbuffer will assume silence has begun after
-; returning this many interpolations. This prevents interpolating throughout
-; a long silence.
-; [This option presently applies only to the new jitterbuffer implementation]
-;
-; maxexcessbuffer: If conditions improve after a period of high jitter,
-; the jitter buffer can end up bigger than necessary. If it ends up
-; more than "maxexcessbuffer" bigger than needed, Asterisk will start
-; gradually decreasing the amount of jitter buffering.
-; [This option is not applicable to, and ignored by the new jitterbuffer implementation]
-;
-; minexcessbuffer: Sets a desired mimimum amount of headroom in
-; the jitter buffer. If Asterisk has less headroom than this, then
-; it will start gradually increasing the amount of jitter buffering.
-; [This option is not applicable to, and ignored by the new jitterbuffer implementation]
-;
-; jittershrinkrate: when the jitter buffer is being gradually shrunk
-; (or enlarged), how many millisecs shall we take off per 20ms frame
-; received? Use a small number, or you will be able to hear it
-; changing. An example: if you set this to 2, then the jitter buffer
-; size will change by 100 millisecs per second.
-; [This option is not applicable to, and ignored by the new jitterbuffer implementation]
-
-jitterbuffer=no
-forcejitterbuffer=no
-;dropcount=2
-;maxjitterbuffer=1000
-;maxjitterinterps=10
-;resyncthreshold=1000
-;maxexcessbuffer=80
-;minexcessbuffer=10
-;jittershrinkrate=1
-
-;trunkfreq=20 ; How frequently to send trunk msgs (in ms)
-
-; Should we send timestamps for the individual sub-frames within trunk frames?
-; There is a small bandwidth use for these (less than 1kbps/call), but they
-; ensure that frame timestamps get sent end-to-end properly. If both ends of
-; all your trunks go directly to TDM, _and_ your trunkfreq equals the frame
-; length for your codecs, you can probably suppress these. The receiver must
-; also support this feature, although they do not also need to have it enabled.
-;
-; trunktimestamps=yes
-;
-; Minimum and maximum amounts of time that IAX peers can request as
-; a registration expiration interval (in seconds).
-; minregexpire = 60
-; maxregexpire = 60
-;
-; We can register with another IAX server to let him know where we are
-; in case we have a dynamic IP address for example
-;
-; Register with tormenta using username marko and password secretpass
-;
-;register => marko:secretpass@tormenta.linux-support.net
-;
-; Register joe at remote host with no password
-;
-;register => joe@remotehost:5656
-;
-; Register marko at tormenta.linux-support.net using RSA key "torkey"
-;
-;register => marko:[torkey]@tormenta.linux-support.net
-;
-; Sample Registration for iaxtel
-;
-; Visit http://www.iaxtel.com to register with iaxtel. Replace "user"
-; and "pass" with your username and password for iaxtel. Incoming
-; calls arrive at the "s" extension of "default" context.
-;
-;register => user:pass@iaxtel.com
-;
-; Sample Registration for IAX + FWD
-;
-; To register using IAX with FWD, it must be enabled by visiting the URL
-; http://www.fwdnet.net/index.php?section_id=112
-;
-; Note that you need an extension in you default context which matches
-; your free world dialup number. Please replace "FWDNumber" with your
-; FWD number and "passwd" with your password.
-;
-;register => FWDNumber:passwd@iax.fwdnet.net
-;
-;
-; You can disable authentication debugging to reduce the amount of
-; debugging traffic.
-;
-;authdebug=no
-;
-; Finally, you can set values for your TOS bits to help improve
-; performance. Valid values are:
-; lowdelay -- Minimize delay
-; throughput -- Maximize throughput
-; reliability -- Maximize reliability
-; mincost -- Minimize cost
-; none -- No flags
-;
-tos=lowdelay
-;
-; If mailboxdetail is set to "yes", the user receives
-; the actual new/old message counts, not just a yes/no
-; as to whether they have messages. this can be set on
-; a per-peer basis as well
-;
-;mailboxdetail=yes
-;
-; If regcontext is specified, Asterisk will dynamically create and destroy
-; a NoOp priority 1 extension for a given peer who registers or unregisters
-; with us. The actual extension is the 'regexten' parameter of the registering
-; peer or its name if 'regexten' is not provided. More than one regexten
-; may be supplied if they are separated by '&'. Patterns may be used in
-; regexten.
-;
-;regcontext=iaxregistrations
-;
-; If we don't get ACK to our NEW within 2000ms, and autokill is set to yes,
-; then we cancel the whole thing (that's enough time for one retransmission
-; only). This is used to keep things from stalling for a long time for a host
-; that is not available, but would be ill advised for bad connections. In
-; addition to 'yes' or 'no' you can also specify a number of milliseconds.
-; See 'qualify' for individual peers to turn on for just a specific peer.
-;
-autokill=yes
-;
-; codecpriority controls the codec negotiation of an inbound IAX call.
-; This option is inherited to all user entities. It can also be defined
-; in each user entity separately which will override the setting in general.
-;
-; The valid values are:
-;
-; caller - Consider the callers preferred order ahead of the host's.
-; host - Consider the host's preferred order ahead of the caller's.
-; disabled - Disable the consideration of codec preference alltogether.
-; (this is the original behaviour before preferences were added)
-; reqonly - Same as disabled, only do not consider capabilities if
-; the requested format is not available the call will only
-; be accepted if the requested format is available.
-;
-; The default value is 'host'
-;
-;codecpriority=host
-
-;rtcachefriends=yes ; Cache realtime friends by adding them to the internal list
- ; just like friends added from the config file only on a
- ; as-needed basis? (yes|no)
-
-;rtupdate=yes ; Send registry updates to database using realtime? (yes|no)
- ; If set to yes, when a IAX2 peer registers successfully, the ip address,
- ; the origination port, the registration period, and the username of
- ; the peer will be set to database via realtime. If not present, defaults to 'yes'.
-
-;rtautoclear=yes ; Auto-Expire friends created on the fly on the same schedule
- ; as if it had just registered? (yes|no|<seconds>)
- ; If set to yes, when the registration expires, the friend will vanish from
- ; the configuration until requested again. If set to an integer,
- ; friends expire within this number of seconds instead of the
- ; registration interval.
-
-;rtignoreexpire=yes ; When reading a peer from Realtime, if the peer's registration
- ; has expired based on its registration interval, used the stored
- ; address information regardless. (yes|no)
-
-; Guest sections for unauthenticated connection attempts. Just specify an
-; empty secret, or provide no secret section.
-;
-[guest]
-type=user
-context=default
-callerid="Guest IAX User"
-
-;
-; Trust Caller*ID Coming from iaxtel.com
-;
-[iaxtel]
-type=user
-context=default
-auth=rsa
-inkeys=iaxtel
-
-;
-; Trust Caller*ID Coming from iax.fwdnet.net
-;
-[iaxfwd]
-type=user
-context=default
-auth=rsa
-inkeys=freeworlddialup
-
-;
-; Trust callerid delivered over DUNDi/e164
-;
-;
-;[dundi]
-;type=user
-;dbsecret=dundi/secret
-;context=dundi-e164-local
-
-;
-; Further user sections may be added, specifying a context and a secret used
-; for connections with that given authentication name. Limited IP based
-; access control is allowed by use of "allow" and "deny" keywords. Multiple
-; rules are permitted. Multiple permitted contexts may be specified, in
-; which case the first will be the default. You can also override caller*ID
-; so that when you receive a call you set the Caller*ID to be what you want
-; instead of trusting what the remote user provides
-;
-; There are three authentication methods that are supported: md5, plaintext,
-; and rsa. The least secure is "plaintext", which sends passwords cleartext
-; across the net. "md5" uses a challenge/response md5 sum arrangement, but
-; still requires both ends have plain text access to the secret. "rsa" allows
-; unidirectional secret knowledge through public/private keys. If "rsa"
-; authentication is used, "inkeys" is a list of acceptable public keys on the
-; local system that can be used to authenticate the remote peer, separated by
-; the ":" character. "outkey" is a single, private key to use to authenticate
-; to the other side. Public keys are named /var/lib/asterisk/keys/<name>.pub
-; while private keys are named /var/lib/asterisk/keys/<name>.key. Private
-; keys should always be 3DES encrypted.
-;
-;
-; NOTE: All hostnames and IP addresses in this file are for example purposes
-; only; you should not expect any of them to actually be available for
-; your use.
-;
-;
-;[markster]
-;type=user
-;context=default
-;context=local
-;auth=md5,plaintext,rsa
-;secret=markpasswd
-;setvar=foo=bar
-;dbsecret=mysecrets/place ; Secrets can be stored in astdb, too
-;notransfer=yes ; Disable IAX native transfer
-;jitterbuffer=yes ; Override global setting an enable jitter buffer
-; ; for this user
-;callerid="Mark Spencer" <(256) 428-6275>
-;deny=0.0.0.0/0.0.0.0
-;accountcode=markster0101
-;permit=209.16.236.73/255.255.255.0
-;language=en ; Use english as default language
-;
-; Peers may also be specified, with a secret and
-; a remote hostname.
-;
-[demo]
-type=peer
-username=asterisk
-secret=supersecret
-host=216.207.245.47
-;sendani=no
-;host=asterisk.linux-support.net
-;port=5036
-;mask=255.255.255.255
-;qualify=yes ; Make sure this peer is alive
-;qualifysmoothing = yes ; use an average of the last two PONG
- ; results to reduce falsly detected LAGGED hosts
- ; Default: Off
-;qualifyfreqok = 60000 ; how frequently to ping the peer when
- ; everything seems to be ok, in milliseconds
-;qualifyfreqnotok = 10000 ; how frequently to ping the peer when it's
- ; either LAGGED or UNAVAILABLE, in milliseconds
-;jitterbuffer=no ; Turn off jitter buffer for this peer
-
-;
-; Peers can remotely register as well, so that they can be mobile. Default
-; IP's can also optionally be given but are not required. Caller*ID can be
-; suggested to the other side as well if it is for example a phone instead of
-; another PBX.
-;
-
-;[dynamichost]
-;host=dynamic
-;secret=mysecret
-;mailbox=1234 ; Notify about mailbox 1234
-;inkeys=key1:key2
-;peercontext=local ; Default context to request for calls to peer
-;defaultip=216.207.245.34
-;callerid="Some Host" <(256) 428-6011>
-;
-
-;
-;[biggateway]
-;type=peer
-;host=192.168.0.1
-;context=*
-;secret=myscret
-;trunk=yes ; Use IAX2 trunking with this host
-;timezone=America/New_York ; Set a timezone for the date/time IE
-;
-
-;
-; Friends are a short cut for creating a user and
-; a peer with the same values.
-;
-;[marko]
-;type=friend
-;host=dynamic
-;regexten=1234
-;secret=moofoo
-;context=default
-;permit=0.0.0.0/0.0.0.0
-
diff --git a/1.2-netsec/configs/iaxprov.conf.sample b/1.2-netsec/configs/iaxprov.conf.sample
deleted file mode 100644
index ad13166ed..000000000
--- a/1.2-netsec/configs/iaxprov.conf.sample
+++ /dev/null
@@ -1,83 +0,0 @@
-;
-; IAX2 Provisioning Information
-;
-; Contains provisioning information for templates and for specific service
-; entries.
-;
-; Templates provide a group of settings from which provisioning takes place.
-; A template may be based upon any template that has been specified before
-; it. If the template that an entry is based on is not specified then it is
-; presumed to be 'default' (unless it is the first of course).
-;
-; Templates which begin with 'si-' are used for provisioning units with
-; specific service identifiers. For example the entry "si-000364000126"
-; would be used when the device with the corresponding service identifier of
-; "000364000126" attempts to register or make a call.
-;
-[default]
-;
-; The port number the device should use to bind to. The default is 4569.
-;
-;port=4569
-;
-; server is our PRIMARY server for registration and placing calls
-;
-;server=192.168.69.3
-;
-; altserver is the BACKUP server for registration and placing calls in the
-; event the primary server is unavailable.
-;
-;altserver=192.168.69.4
-;
-; port is the port number to use for IAX2 outbound. The connections to the
-; server and altserver -- default is of course 4569.
-;serverport=4569
-;
-; language is the preferred language for the device
-;
-;language=en
-;
-; codec is the requested codec. The iaxy supports ulaw and adpcm
-;
-codec=ulaw
-;
-; flags is a comma separated list of flags which the device should
-; use and may contain any of the following keywords:
-;
-; "register" - Register with server
-; "secure" - Do not accept calls / provisioning not originated by the server
-; "heartbeat" - Generate status packets on port 9999 sent to 255.255.255.255
-; "debug" - Output extra debugging to port 9999
-;
-; Note that use can use += and -= to adjust parameters
-;
-flags=register,heartbeat
-;
-; tos is the requested type of service setting and may be one a number or
-; 'lowdelay','throughput','reliability','mincost' or 'none'
-;
-tos=lowdelay
-;
-; Example iaxy provisioning
-;
-;[si-000364000126]
-;user=iaxy
-;pass=bitsy
-;flags += debug
-
-;[si-000364000127]
-;user=iaxy2
-;pass=bitsy2
-;template=si-000364000126
-;flags += debug
-
-;
-;[*]
-;
-; If specified, the '*' provisioning is used for all devices which do not
-; have another provisioning entry within the file. If unspecified, no
-; provisioning will take place for devices which have no entry. DO NOT
-; USE A '*' PROVISIONING ENTRY UNLESS YOU KNOW WHAT YOU'RE DOING.
-;
-;template=default
-
diff --git a/1.2-netsec/configs/indications.conf.sample b/1.2-netsec/configs/indications.conf.sample
deleted file mode 100644
index d70ac60ed..000000000
--- a/1.2-netsec/configs/indications.conf.sample
+++ /dev/null
@@ -1,611 +0,0 @@
-; indications.conf
-; Configuration file for location specific tone indications
-; used by the pbx_indications module.
-;
-; NOTE:
-; When adding countries to this file, please keep them in alphabetical
-; order according to the 2-character country codes!
-;
-; The [general] category is for certain global variables.
-; All other categories are interpreted as location specific indications
-;
-;
-[general]
-country=us ; default location
-
-
-; [example]
-; description = string
-; The full name of your country, in English.
-; alias = iso[,iso]*
-; List of other countries 2-letter iso codes, which have the same
-; tone indications.
-; ringcadence = num[,num]*
-; List of durations the physical bell rings.
-; dial = tonelist
-; Set of tones to be played when one picks up the hook.
-; busy = tonelist
-; Set of tones played when the receiving end is busy.
-; congestion = tonelist
-; Set of tones played when there is some congestion (on the network?)
-; callwaiting = tonelist
-; Set of tones played when there is a call waiting in the background.
-; dialrecall = tonelist
-; Not well defined; many phone systems play a recall dial tone after hook
-; flash.
-; record = tonelist
-; Set of tones played when call recording is in progress.
-; info = tonelist
-; Set of tones played with special information messages (e.g., "number is
-; out of service")
-; 'name' = tonelist
-; Every other variable will be available as a shortcut for the "PlayList" command
-; but will not be used automatically by Asterisk.
-;
-;
-; The tonelist itself is defined by a comma-separated sequence of elements.
-; Each element consist of a frequency (f) with an optional duration (in ms)
-; attached to it (f/duration). The frequency component may be a mixture of two
-; frequencies (f1+f2) or a frequency modulated by another frequency (f1*f2).
-; The implicit modulation depth is fixed at 90%, though.
-; If the list element starts with a !, that element is NOT repeated,
-; therefore, only if all elements start with !, the tonelist is time-limited,
-; all others will repeat indefinitely.
-;
-; concisely:
-; element = [!]freq[+|*freq2][/duration]
-; tonelist = element[,element]*
-;
-; Please note that SPACES ARE NOT ALLOWED in tone lists!
-;
-
-[at]
-description = Austria
-ringcadence = 1000,5000
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-dial = 420
-busy = 420/400,0/400
-ring = 420/1000,0/5000
-congestion = 420/200,0/200
-callwaiting = 420/40,0/1960
-dialrecall = 420
-; RECORDTONE - not specified
-record = 1400/80,0/14920
-info = 950/330,1450/330,1850/330,0/1000
-stutter = 380+420
-
-[au]
-description = Australia
-; Reference http://www.acif.org.au/__data/page/3303/S002_2001.pdf
-; Normal Ring
-ringcadence = 400,200,400,2000
-; Distinctive Ring 1 - Forwarded Calls
-; 400,400,200,200,400,1400
-; Distinctive Ring 2 - Selective Ring 2 + Operator + Recall
-; 400,400,200,2000
-; Distinctive Ring 3 - Multiple Subscriber Number 1
-; 200,200,400,2200
-; Distinctive Ring 4 - Selective Ring 1 + Centrex
-; 400,2600
-; Distinctive Ring 5 - Selective Ring 3
-; 400,400,200,400,200,1400
-; Distinctive Ring 6 - Multiple Subscriber Number 2
-; 200,400,200,200,400,1600
-; Distinctive Ring 7 - Multiple Subscriber Number 3 + Data Privacy
-; 200,400,200,400,200,1600
-; Tones
-dial = 413+438
-busy = 425/375,0/375
-ring = 413+438/400,0/200,413+438/400,0/2000
-; XXX Congestion: Should reduce by 10 db every other cadence XXX
-congestion = 425/375,0/375,420/375,0/375
-callwaiting = 425/200,0/200,425/200,0/4400
-dialrecall = 413+438
-; Record tone used for Call Intrusion/Recording or Conference
-record = !425/1000,!0/15000,425/360,0/15000
-info = 425/2500,0/500
-; Other Australian Tones
-; The STD "pips" indicate the call is not an untimed local call
-std = !525/100,!0/100,!525/100,!0/100,!525/100,!0/100,!525/100,!0/100,!525/100
-; Facility confirmation tone (eg. Call Forward Activated)
-facility = 425
-; Message Waiting "stutter" dialtone
-stutter = 413+438/100,0/40
-; Ringtone for calls to Telstra mobiles
-ringmobile = 400+450/400,0/200,400+450/400,0/2000
-
-[br]
-description = Brazil
-ringcadence = 1000,4000
-dial = 425
-busy = 425/250,0/250
-ring = 425/1000,0/4000
-congestion = 425/250,0/250,425/750,0/250
-callwaiting = 425/50,0/1000
-; Dialrecall not used in Brazil standard (using UK standard)
-dialrecall = 350+440
-; Record tone is not used in Brazil, use busy tone
-record = 425/250,0/250
-; Info not used in Brazil standard (using UK standard)
-info = 950/330,1400/330,1800/330
-stutter = 350+440
-
-[be]
-description = Belgium
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1000,3000
-dial = 425
-busy = 425/500,0/500
-ring = 425/1000,0/3000
-congestion = 425/167,0/167
-callwaiting = 1400/175,0/175,1400/175,0/3500
-; DIALRECALL - not specified
-dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440"
-; RECORDTONE - not specified
-record = 1400/500,0/15000
-info = 900/330,1400/330,1800/330,0/1000
-stutter = 425/1000,0/250
-
-[ch]
-description = Switzerland
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1000,4000
-dial = 425
-busy = 425/500,0/500
-ring = 425/1000,0/4000
-congestion = 425/200,0/200
-callwaiting = 425/200,0/200,425/200,0/4000
-; DIALRECALL - not specified
-dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
-; RECORDTONE - not specified
-record = 1400/80,0/15000
-info = 950/330,1400/330,1800/330,0/1000
-stutter = 425+340/1100,0/1100
-
-[cl]
-description = Chile
-; According to specs from Telefonica CTC Chile
-ringcadence = 1000,3000
-dial = 400
-busy = 400/500,0/500
-ring = 400/1000,0/3000
-congestion = 400/200,0/200
-callwaiting = 400/250,0/8750
-dialrecall = !400/100,!0/100,!400/100,!0/100,!400/100,!0/100,400
-record = 1400/500,0/15000
-info = 950/333,1400/333,1800/333,0/1000
-stutter = !400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,400
-
-[cn]
-description = China
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1000,4000
-dial = 450
-busy = 450/350,0/350
-ring = 450/1000,0/4000
-congestion = 450/700,0/700
-callwaiting = 450/400,0/4000
-dialrecall = 450
-record = 950/400,0/10000
-info = 450/100,0/100,450/100,0/100,450/100,0/100,450/400,0/400
-; STUTTER - not specified
-stutter = 450+425
-
-[cz]
-description = Czech Republic
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1000,4000
-dial = 425/330,0/330,425/660,0/660
-busy = 425/330,0/330
-ring = 425/1000,0/4000
-congestion = 425/165,0/165
-callwaiting = 425/330,0/9000
-; DIALRECALL - not specified
-dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425/330,0/330,425/660,0/660
-; RECORDTONE - not specified
-record = 1400/500,0/14000
-info = 950/330,0/30,1400/330,0/30,1800/330,0/1000
-; STUTTER - not specified
-stutter = 425/450,0/50
-
-[de]
-description = Germany
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1000,4000
-dial = 425
-busy = 425/480,0/480
-ring = 425/1000,0/4000
-congestion = 425/240,0/240
-callwaiting = !425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,0
-; DIALRECALL - not specified
-dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
-; RECORDTONE - not specified
-record = 1400/80,0/15000
-info = 950/330,1400/330,1800/330,0/1000
-stutter = 425+400
-
-[dk]
-description = Denmark
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1000,4000
-dial = 425
-busy = 425/500,0/500
-ring = 425/1000,0/4000
-congestion = 425/200,0/200
-callwaiting = !425/200,!0/600,!425/200,!0/3000,!425/200,!0/200,!425/200,0
-; DIALRECALL - not specified
-dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
-; RECORDTONE - not specified
-record = 1400/80,0/15000
-info = 950/330,1400/330,1800/330,0/1000
-; STUTTER - not specified
-stutter = 425/450,0/50
-
-[ee]
-description = Estonia
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1000,4000
-dial = 425
-busy = 425/300,0/300
-ring = 425/1000,0/4000
-congestion = 425/200,0/200
-; CALLWAIT not in accordance to ITU
-callwaiting = 950/650,0/325,950/325,0/30,1400/1300,0/2600
-; DIALRECALL - not specified
-dialrecall = 425/650,0/25
-; RECORDTONE - not specified
-record = 1400/500,0/15000
-; INFO not in accordance to ITU
-info = 950/650,0/325,950/325,0/30,1400/1300,0/2600
-; STUTTER not specified
-stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
-
-[es]
-description = Spain
-ringcadence = 1500,3000
-dial = 425
-busy = 425/200,0/200
-ring = 425/1500,0/3000
-congestion = 425/200,0/200,425/200,0/200,425/200,0/600
-callwaiting = 425/175,0/175,425/175,0/3500
-dialrecall = !425/200,!0/200,!425/200,!0/200,!425/200,!0/200,425
-record = 1400/500,0/15000
-info = 950/330,0/1000
-dialout = 500
-
-
-[fi]
-description = Finland
-ringcadence = 1000,4000
-dial = 425
-busy = 425/300,0/300
-ring = 425/1000,0/4000
-congestion = 425/200,0/200
-callwaiting = 425/150,0/150,425/150,0/8000
-dialrecall = 425/650,0/25
-record = 1400/500,0/15000
-info = 950/650,0/325,950/325,0/30,1400/1300,0/2600
-stutter = 425/650,0/25
-
-[fr]
-description = France
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1500,3500
-; Dialtone can also be 440+330
-dial = 440
-busy = 440/500,0/500
-ring = 440/1500,0/3500
-; CONGESTION - not specified
-congestion = 440/250,0/250
-callwait = 440/300,0/10000
-; DIALRECALL - not specified
-dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
-; RECORDTONE - not specified
-record = 1400/500,0/15000
-info = !950/330,!1400/330,!1800/330
-stutter = !440/100,!0/100,!440/100,!0/100,!440/100,!0/100,!440/100,!0/100,!440/100,!0/100,!440/100,!0/100,440
-
-[gr]
-description = Greece
-ringcadence = 1000,4000
-dial = 425/200,0/300,425/700,0/800
-busy = 425/300,0/300
-ring = 425/1000,0/4000
-congestion = 425/200,0/200
-callwaiting = 425/150,0/150,425/150,0/8000
-dialrecall = 425/650,0/25
-record = 1400/400,0/15000
-info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
-stutter = 425/650,0/25
-
-[hu]
-description = Hungary
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1250,3750
-dial = 425
-busy = 425/300,0/300
-ring = 425/1250,0/3750
-congestion = 425/300,0/300
-callwaiting = 425/40,0/1960
-dialrecall = 425+450
-; RECORDTONE - not specified
-record = 1400/400,0/15000
-info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
-stutter = 350+375+400
-
-[it]
-description = Italy
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1000,4000
-dial = 425/200,0/200,425/600,0/1000
-busy = 425/500,0/500
-ring = 425/1000,0/4000
-congestion = 425/200,0/200
-callwaiting = 425/400,0/100,425/250,0/100,425/150,0/14000
-dialrecall = 470/400,425/400
-record = 1400/400,0/15000
-info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
-stutter = 470/400,425/400
-
-[lt]
-description = Lithuania
-ringcadence = 1000,4000
-dial = 425
-busy = 425/350,0/350
-ring = 425/1000,0/4000
-congestion = 425/200,0/200
-callwaiting = 425/150,0/150,425/150,0/4000
-; DIALRECALL - not specified
-dialrecall = 425/500,0/50
-; RECORDTONE - not specified
-record = 1400/500,0/15000
-info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
-; STUTTER - not specified
-stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
-
-[mx]
-description = Mexico
-ringcadence = 2000,4000
-dial = 425
-busy = 425/250,0/250
-ring = 425/1000,0/4000
-congestion = 425/250,0/250
-callwaiting = 425/200,0/600,425/200,0/10000
-dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
-record = 1400/500,0/15000
-info = 950/330,0/30,1400/330,0/30,1800/330,0/1000
-stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
-
-[nl]
-description = Netherlands
-; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
-ringcadence = 1000,4000
-; Most of these 425's can also be 450's
-dial = 425
-busy = 425/500,0/500
-ring = 425/1000,0/4000
-congestion = 425/250,0/250
-callwaiting = 425/500,0/9500
-; DIALRECALL - not specified
-dialrecall = 425/500,0/50
-; RECORDTONE - not specified
-record = 1400/500,0/15000
-info = 950/330,1400/330,1800/330,0/1000
-stutter = 425/500,0/50
-
-[no]
-description = Norway
-ringcadence = 1000,4000
-dial = 425
-busy = 425/500,0/500
-ring = 425/1000,0/4000
-congestion = 425/200,0/200
-callwaiting = 425/200,0/600,425/200,0/10000
-dialrecall = 470/400,425/400
-record = 1400/400,0/15000
-info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
-stutter = 470/400,425/400
-
-[nz]
-description = New Zealand
-;NOTE - the ITU has different tonesets for NZ, but according to some residents there,
-; this is, indeed, the correct way to do it.
-ringcadence = 400,200,400,2000
-dial = 400
-busy = 400/250,0/250
-ring = 400+450/400,0/200,400+450/400,0/2000
-congestion = 400/375,0/375
-callwaiting = !400/200,!0/3000,!400/200,!0/3000,!400/200,!0/3000,!400/200
-dialrecall = !400/100!0/100,!400/100,!0/100,!400/100,!0/100,400
-record = 1400/425,0/15000
-info = 400/750,0/100,400/750,0/100,400/750,0/100,400/750,0/400
-stutter = !400/100!0/100,!400/100,!0/100,!400/100,!0/100,!400/100!0/100,!400/100,!0/100,!400/100,!0/100,400
-
-[pl]
-description = Poland
-ringcadence = 1000,4000
-dial = 425
-busy = 425/500,0/500
-ring = 425/1000,0/4000
-congestion = 425/500,0/500
-callwaiting = 425/150,0/150,425/150,0/4000
-; DIALRECALL - not specified
-dialrecall = 425/500,0/50
-; RECORDTONE - not specified
-record = 1400/500,0/15000
-; 950/1400/1800 3x0.33 on 1.0 off repeated 3 times
-info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000
-; STUTTER - not specified
-stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
-
-[pt]
-description = Portugal
-ringcadence = 1000,5000
-dial = 425
-busy = 425/500,0/500
-ring = 425/1000,0/5000
-congestion = 425/200,0/200
-callwaiting = 440/300,0/10000
-dialrecall = 425/1000,0/200
-record = 1400/500,0/15000
-info = 950/330,1400/330,1800/330,0/1000
-stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
-
-[ru]
-description = Russia / ex Soviet Union
-ringcadence = 800,3200
-dial = 425
-busy = 425/350,0/350
-ring = 425/800,0/3200
-congestion = 425/350,0/350
-callwaiting = 425/200,0/5000
-dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
-record = 1400/500,0/15000
-info = !950/330,!1400/330,!1800/330,0
-
-[se]
-description = Sweden
-ringcadence = 1000,5000
-dial = 425
-busy = 425/250,0/250
-ring = 425/1000,0/5000
-congestion = 425/250,0/750
-callwaiting = 425/200,0/500,425/200,0/9100
-dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
-record = 1400/500,0/15000
-info = !950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,0
-stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
-; stutter = 425/320,0/20 ; Real swedish standard, not used for now
-
-[sg]
-description = Singapore
-; Singapore
-; Reference: http://www.ida.gov.sg/idaweb/doc/download/I397/ida_ts_pstn1_i4r2.pdf
-; Frequency specs are: 425 Hz +/- 20Hz; 24 Hz +/- 2Hz; modulation depth 100%; SIT +/- 50Hz
-ringcadence = 400,200,400,2000
-dial = 425
-ring = 425*24/400,0/200,425*24/400,0/2000 ; modulation should be 100%, not 90%
-busy = 425/750,0/750
-congestion = 425/250,0/250
-callwaiting = 425*24/300,0/200,425*24/300,0/3200
-stutter = !425/200,!0/200,!425/600,!0/200,!425/200,!0/200,!425/600,!0/200,!425/200,!0/200,!425/600,!0/200,!425/200,!0/200,!425/600,!0/200,425
-info = 950/330,1400/330,1800/330,0/1000 ; not currently in use acc. to reference
-dialrecall = 425*24/500,0/500,425/500,0/2500 ; unspecified in IDA reference, use repeating Holding Tone A,B
-record = 1400/500,0/15000 ; unspecified in IDA reference, use 0.5s tone every 15s
-; additionally defined in reference
-nutone = 425/2500,0/500
-intrusion = 425/250,0/2000
-warning = 425/624,0/4376 ; end of period tone, warning
-acceptance = 425/125,0/125
-holdinga = !425*24/500,!0/500 ; followed by holdingb
-holdingb = !425/500,!0/2500
-
-[uk]
-description = United Kingdom
-ringcadence = 400,200,400,2000
-; These are the official tones taken from BT SIN350. The actual tones
-; used by BT include some volume differences so sound slightly different
-; from Asterisk-generated ones.
-dial = 350+440
-; Special dial is the intermittent dial tone heard when, for example,
-; you have a divert active on the line
-specialdial = 350+440/750,440/750
-; Busy is also called "Engaged"
-busy = 400/375,0/375
-; "Congestion" is the Beep-bip engaged tone
-congestion = 400/400,0/350,400/225,0/525
-; "Special Congestion" is not used by BT very often if at all
-specialcongestion = 400/200,1004/300
-unobtainable = 400
-ring = 400+450/400,0/200,400+450/400,0/2000
-callwaiting = 400/100,0/4000
-; BT seem to use "Special Call Waiting" rather than just "Call Waiting" tones
-specialcallwaiting = 400/250,0/250,400/250,0/250,400/250,0/5000
-; "Pips" used by BT on payphones. (Sounds wrong, but this is what BT claim it
-; is and I've not used a payphone for years)
-creditexpired = 400/125,0/125
-; These two are used to confirm/reject service requests on exchanges that
-; don't do voice announcements.
-confirm = 1400
-switching = 400/200,0/400,400/2000,0/400
-; This is the three rising tones Doo-dah-dee "Special Information Tone",
-; usually followed by the BT woman saying an appropriate message.
-info = 950/330,0/15,1400/330,0/15,1800/330,0/1000
-; Not listed in SIN350
-record = 1400/500,0/60000
-stutter = 350+440/750,440/750
-
-[us]
-description = United States / North America
-ringcadence = 2000,4000
-dial = 350+440
-busy = 480+620/500,0/500
-ring = 440+480/2000,0/4000
-congestion = 480+620/250,0/250
-callwaiting = 440/300,0/10000
-dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
-record = 1400/500,0/15000
-info = !950/330,!1400/330,!1800/330,0
-stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
-
-[us-old]
-description = United States Circa 1950/ North America
-ringcadence = 2000,4000
-dial = 600*120
-busy = 500*100/500,0/500
-ring = 420*40/2000,0/4000
-congestion = 500*100/250,0/250
-callwaiting = 440/300,0/10000
-dialrecall = !600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,600*120
-record = 1400/500,0/15000
-info = !950/330,!1400/330,!1800/330,0
-stutter = !600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,600*120
-
-[tw]
-description = Taiwan
-; http://nemesis.lonestar.org/reference/telecom/signaling/dialtone.html
-; http://nemesis.lonestar.org/reference/telecom/signaling/busy.html
-; http://www.iproducts.com.tw/ee/kylink/06ky-1000a.htm
-; http://www.pbx-manufacturer.com/ky120dx.htm
-; http://www.nettwerked.net/tones.txt
-; http://www.cisco.com/univercd/cc/td/doc/product/tel_pswt/vco_prod/taiw_sup/taiw2.htm
-;
-; busy tone 480+620Hz 0.5 sec. on ,0.5 sec. off
-; reorder tone 480+620Hz 0.25 sec. on,0.25 sec. off
-; ringing tone 440+480Hz 1 sec. on ,2 sec. off
-;
-ringcadence = 1000,4000
-dial = 350+440
-busy = 480+620/500,0/500
-ring = 440+480/1000,0/2000
-congestion = 480+620/250,0/250
-callwaiting = 350+440/250,0/250,350+440/250,0/3250
-dialrecall = 300/1500,0/500
-record = 1400/500,0/15000
-info = !950/330,!1400/330,!1800/330,0
-stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
-
-[za]
-description = South Africa
-; http://www.cisco.com/univercd/cc/td/doc/product/tel_pswt/vco_prod/safr_sup/saf02.htm
-; (definitions for other countries can also be found there)
-; Note, though, that South Africa uses two switch types in their network --
-; Alcatel switches -- mainly in the Western Cape, and Siemens elsewhere.
-; The former use 383+417 in dial, ringback etc. The latter use 400*33
-; I've provided both, uncomment the ones you prefer
-ringcadence = 400,200,400,2000
-; dial/ring/callwaiting for the Siemens switches:
-dial = 400*33
-ring = 400*33/400,0/200,400*33/400,0/2000
-callwaiting = 400*33/250,0/250,400*33/250,0/250,400*33/250,0/250,400*33/250,0/250
-; dial/ring/callwaiting for the Alcatel switches:
-; dial = 383+417
-; ring = 383+417/400,0/200,383+417/400,0/2000
-; callwaiting = 383+417/250,0/250,383+417/250,0/250,383+417/250,0/250,383+417/250,0/250
-congestion = 400/250,0/250
-busy = 400/500,0/500
-dialrecall = 350+440
-; XXX Not sure about the RECORDTONE
-record = 1400/500,0/10000
-info = 950/330,1400/330,1800/330,0/330
-stutter = !400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,400*33
diff --git a/1.2-netsec/configs/logger.conf.sample b/1.2-netsec/configs/logger.conf.sample
deleted file mode 100644
index f2ff0ea7e..000000000
--- a/1.2-netsec/configs/logger.conf.sample
+++ /dev/null
@@ -1,69 +0,0 @@
-;
-; Logging Configuration
-;
-; In this file, you configure logging to files or to
-; the syslog system.
-;
-; "logger reload" at the CLI will reload configuration
-; of the logging system.
-
-[general]
-; Customize the display of debug message time stamps
-; this example is the ISO 8601 date format (yyyy-mm-dd HH:MM:SS)
-; see strftime(3) Linux manual for format specifiers
-;dateformat=%F %T
-;
-; This appends the hostname to the name of the log files.
-;appendhostname = yes
-;
-; This determines whether or not we log queue events to a file
-; (defaults to yes).
-;queue_log = no
-;
-; This determines whether or not we log generic events to a file
-; (defaults to yes).
-;event_log = no
-;
-;
-; For each file, specify what to log.
-;
-; For console logging, you set options at start of
-; Asterisk with -v for verbose and -d for debug
-; See 'asterisk -h' for more information.
-;
-; Directory for log files is configures in asterisk.conf
-; option astlogdir
-;
-[logfiles]
-;
-; Format is "filename" and then "levels" of debugging to be included:
-; debug
-; notice
-; warning
-; error
-; verbose
-; dtmf
-;
-; Special filename "console" represents the system console
-;
-; We highly recommend that you DO NOT turn on debug mode if you are simply
-; running a production system. Debug mode turns on a LOT of extra messages,
-; most of which you are unlikely to understand without an understanding of
-; the underlying code. Do NOT report debug messages as code issues, unless
-; you have a specific issue that you are attempting to debug. They are
-; messages for just that -- debugging -- and do not rise to the level of
-; something that merit your attention as an Asterisk administrator. Debug
-; messages are also very verbose and can and do fill up logfiles quickly;
-; this is another reason not to have debug mode on a production system unless
-; you are in the process of debugging a specific issue.
-;
-;debug => debug
-console => notice,warning,error
-;console => notice,warning,error,debug
-messages => notice,warning,error
-;full => notice,warning,error,debug,verbose
-
-;syslog keyword : This special keyword logs to syslog facility
-;
-;syslog.local0 => notice,warning,error
-;
diff --git a/1.2-netsec/configs/manager.conf.sample b/1.2-netsec/configs/manager.conf.sample
deleted file mode 100644
index ff37f8a1b..000000000
--- a/1.2-netsec/configs/manager.conf.sample
+++ /dev/null
@@ -1,37 +0,0 @@
-;
-; AMI - The Asterisk Manager Interface
-;
-; Third party application call management support and PBX event supervision
-;
-; This configuration file is read every time someone logs in
-;
-; Use the "show manager commands" at the CLI to list available manager commands
-; and their authorization levels.
-;
-; "show manager command <command>" will show a help text.
-;
-; ---------------------------- SECURITY NOTE -------------------------------
-; Note that you should not enable the AMI on a public IP address. If needed,
-; block this TCP port with iptables (or another FW software) and reach it
-; with IPsec, SSH, or SSL vpn tunnel
-;
-[general]
-enabled = no
-port = 5038
-bindaddr = 0.0.0.0
-;displayconnects = yes
-
-;[mark]
-;secret = mysecret
-;deny=0.0.0.0/0.0.0.0
-;permit=209.16.236.73/255.255.255.0
-;
-; If the device connected via this user accepts input slowly,
-; the timeout for writes to it can be increased to keep it
-; from being disconnected (value is in milliseconds)
-;
-; writetimeout = 100
-;
-; Authorization for various classes
-;read = system,call,log,verbose,command,agent,user
-;write = system,call,log,verbose,command,agent,user
diff --git a/1.2-netsec/configs/meetme.conf.sample b/1.2-netsec/configs/meetme.conf.sample
deleted file mode 100644
index 308ec0772..000000000
--- a/1.2-netsec/configs/meetme.conf.sample
+++ /dev/null
@@ -1,21 +0,0 @@
-;
-; Configuration file for MeetMe simple conference rooms for Asterisk of course.
-;
-; This configuration file is read every time you call app meetme()
-
-[general]
-;audiobuffers=32 ; The number of 20ms audio buffers to be used
- ; when feeding audio frames from non-Zap channels
- ; into the conference; larger numbers will allow
- ; for the conference to 'de-jitter' audio that arrives
- ; at different timing than the conference's timing
- ; source, but can also allow for latency in hearing
- ; the audio from the speaker. Minimum value is 2,
- ; maximum value is 32.
-;
-[rooms]
-;
-; Usage is conf => confno[,pin][,adminpin]
-;
-;conf => 1234
-;conf => 2345,9938
diff --git a/1.2-netsec/configs/mgcp.conf.sample b/1.2-netsec/configs/mgcp.conf.sample
deleted file mode 100644
index cf7b2c916..000000000
--- a/1.2-netsec/configs/mgcp.conf.sample
+++ /dev/null
@@ -1,75 +0,0 @@
-;
-; MGCP Configuration for Asterisk
-;
-[general]
-;port = 2427
-;bindaddr = 0.0.0.0
-
-;[dlinkgw]
-;host = 192.168.0.64
-;context = default
-;canreinvite = no
-;line => aaln/2
-;line => aaln/1
-
-;; The MGCP channel supports the following service codes:
-;; # - Transfer
-;; *67 - Calling Number Delivery Blocking
-;; *70 - Cancel Call Waiting
-;; *72 - Call Forwarding Activation
-;; *73 - Call Forwarding Deactivation
-;; *78 - Do Not Disturb Activation
-;; *79 - Do Not Disturb Deactivation
-;; *8 - Call pick-up
-;
-; known to work with Swissvoice IP10s
-;[192.168.1.20]
-;context=local
-;host=192.168.1.20
-;callerid = "John Doe" <123>
-;callgroup=0
-;pickupgroup=0
-;nat=no
-;threewaycalling=yes
-;transfer=yes ; transfer requires threewaycalling=yes. Use FLASH to transfer
-;callwaiting=yes ; this might be a cause of trouble for ip10s
-;cancallforward=yes
-;line => aaln/1
-;
-
-;[dph100]
-;
-; Supporting the DPH100M requires defining DLINK_BUGGY_FIRMWARE in
-; chan_mgcp.c in addition to enabling the slowsequence mode due to
-; bugs in the D-Link firmware
-;
-;context=local
-;host=dynamic
-;dtmfmode=none ; DTMF Mode can be 'none', 'rfc2833', or 'inband' or
- ; 'hybrid' which starts in none and moves to inband. Default is none.
-;slowsequence=yes ; The DPH100M does not follow MGCP standards for sequencing
-;line => aaln/1
-
-; known to work with wave7optics FTTH LMGs
-;[192.168.1.20]
-;accountcode = 1000 ; record this in cdr as account identification for billing
-;amaflags = billing ; record this in cdr as flagged for 'billing', 'documentation', or 'omit'
-;context = local
-;host = 192.168.1.20
-;wcardep = aaln/* ; enables wildcard endpoint and sets it to 'aaln/*' another common format is '*'
-;callerid = "Duane Cox" <123> ; now lets setup line 1 using per endpoint configuration...
-;callwaiting = no
-;callreturn = yes
-;cancallforward = yes
-;canreinvite = no
-;transfer = no
-;dtmfmode = inband
-;line => aaln/1 ; now lets save this config to line1 aka aaln/1
-;callerid = "Duane Cox" <456> ; now lets setup line 2
-;callwaiting = no
-;callreturn = yes
-;cancallforward = yes
-;canreinvite = no
-;transfer = no
-;dtmfmode = inband
-;line => aaln/2 ; now lets save this config to line2 aka aaln/2
diff --git a/1.2-netsec/configs/misdn.conf.sample b/1.2-netsec/configs/misdn.conf.sample
deleted file mode 100644
index 8957e2fa6..000000000
--- a/1.2-netsec/configs/misdn.conf.sample
+++ /dev/null
@@ -1,267 +0,0 @@
-;
-; chan_misdn sample config
-;
-
-; general section:
-;
-; for debugging and general setup, things that are not bound to port groups
-;
-
-[general]
-
-; set debugging flag:
-; 0 - No Debug
-; 1 - mISDN Messages and * - Messages, and * - State changes
-; 2 - Messages + Message specific Informations (e.g. bearer capability)
-; 3 - very Verbose, the above + lots of Driver specific infos
-; 4 - even more Verbose than 3
-;
-; default value: 0
-;
-debug=0
-
-; the big trace
-;
-; default value: [not set]
-;
-;tracefile=/var/log/misdn.trace
-
-; single call trace files
-; set to true if you want to have them
-; they depend on debug level
-;
-; default values: trace_calls : false
-; trace_dir : /var/log/
-;
-trace_calls=false
-trace_dir=/var/log/
-
-; set to yes if you want mISDN_dsp to bridge the calls in HW
-;
-; default value: yes
-;
-bridging=yes
-
-; stops dialtone after getting first digit on nt Port
-;
-; default value: yes
-;
-stop_tone_after_first_digit=yes
-
-; wether to append overlapdialed Digits to Extension or not
-;
-; default value: yes
-;
-append_digits2exten=yes
-
-; set this to yes if you have jollys mISDN which sends correct L1 Infos
-;
-; default value: yes
-;
-l1_info_ok=yes
-
-; set this to yes if you want to clear the l3 in case the l2 deactivates
-; some environments have a flickering l2 which causes this option to
-; damage active calls .. highly experimental
-;
-; default value: no
-;
-clear_l3=no
-
-; set the method to use for channel selection:
-; standard - always choose the first free channel with the lowest number
-; round_robin - use the round robin algorithm to select a channel. use this
-; if you want to balance your load.
-;
-; default value: standard
-;
-method=standard
-
-;;; CRYPTION STUFF
-
-; Wether to look for dynamic crypting attempt
-;
-; default value: no
-;
-dynamic_crypt=no
-
-; crypt_prefix, what is used for crypting Protocol
-;
-; default value: [not set]
-;
-crypt_prefix=**
-
-; Keys for cryption, you reference them in the dialplan
-; later also in dynamic encr.
-;
-; default value: [not set]
-;
-crypt_keys=test,muh
-
-; users sections:
-;
-; name your sections as you which but not "general" !
-; the secions are Groups, you can dial out in extensions.conf
-; with Dial(mISDN/g:extern/101) where extern is a section name,
-; chan_misdn tries every port in this section to find a
-; new free channel
-;
-
-; The default section is not a group section, it just contains config elements
-; which are inherited by group sections.
-;
-
-[default]
-
-; define your default context here
-;
-; default value: default
-;
-context=misdn
-
-; language
-;
-; default value: en
-;
-language=en
-
-; Prefixes for national and international, those are put before the
-; oad if an according dialplan is set by the other end.
-;
-; default values: nationalprefix : 0
-; internationalprefix : 00
-;
-nationalprefix=0
-internationalprefix=00
-
-; set rx/tx gains between -8 and 8 to change the RX/TX Gain
-;
-; default values: rxgain: 0
-; txgain: 0
-;
-rxgain=0
-txgain=0
-
-; some telcos espacially in NL seem to need this set to yes, also in
-; switzerland this seems to be important
-;
-; default value: no
-;
-te_choose_channel=no
-
-; dialplan options:
-;
-; 0 - unknown
-; 1 - National
-; 2 - International
-; 4 - Subscriber
-;
-; This setting is used for outgoing calls
-;
-; default value: 0
-;
-dialplan=0
-
-; This is only for asterisk head and will result in only considering
-; misdn.confs and misdn_set_opts callingpresentation informations if set to no.
-; Otherwise asterisks callingpresentation overwrites misdn.confs settings.
-;
-; default value: yes
-;
-use_callingpres=yes
-
-; uncomment the following to get into s extension at extension conf
-; there you can use DigitTimeout if you can't or don't want to use
-; isdn overlap dial.
-; note: This will jump into the s exten for every exten!
-;
-; default value: no
-;
-;always_immediate=no
-
-; uncomment the following if you want callers which called exactly the
-; base number (so no extension is set) jump to the s extension.
-; if the user dials something more it jumps to the correct extension
-; instead
-;
-; default value: no
-;
-;immediate=no
-
-; uncomment the following to have hold and retrieve support
-;
-; default value: no
-;
-;hold_allowed=yes
-
-; Pickup and Callgroup
-;
-; deafult values: not set = 0
-;
-;callgroup=1
-;pickupgroup=1
-
-; Allows/Screens Callerid
-;
-; possible values: allowed,not_screened
-;
-; be aware, if you set to allowed you need to set a correct
-; callerid in the dialplan or set it here in the misdn.conf
-; Some Telcos don't care about wrong callerids, others do !
-;
-; default value: allowed
-;
-;presentation=not_screened
-
-; this enables echocancellation, with the given number of taps
-; be aware, move this setting only to outgoing portgroups!
-; A value of zero turns echocancellation off.
-;
-; possible values are: 0,32,64,128,256,yes(=128),no(=0)
-;
-; default value: no
-;
-;echocancel=no
-
-; this disables echocancellation when the call is bridged between
-; mISDN channels
-;
-; default value: no
-;
-echocancelwhenbridged=no
-
-; Set this to no to disable echotraining
-;
-; default value: yes
-;
-echotraining=yes
-
-[intern]
-; define your ports, e.g. 1,2 (depends on mISDN-driver loading order)
-ports=1,2
-; context where to go to when incoming Call on one of the above ports
-context=Intern
-
-[internPP]
-; if you want to have pp Protocol on one nt Port, you need
-; to add a ptp directly after the portnumber, you can still add
-; more ports and multiple ptp adds in your config.
-ports=3ptp
-
-[first_extern]
-; again port defs
-ports=4
-; again a context for incomming calls
-context=Extern1
-; msns for te ports, listen on those numbers on the above ports, and
-; indicate the incoming calls to asterisk
-; here you can give a comma seperated list or simply an '*' for
-; any msn.
-msns=*
-
-; here an example with given msns
-[second_extern]
-ports=5
-context=Extern2
-callerid=15
-msns=102,144,101,104
diff --git a/1.2-netsec/configs/modem.conf.sample b/1.2-netsec/configs/modem.conf.sample
deleted file mode 100644
index 4bcd58abb..000000000
--- a/1.2-netsec/configs/modem.conf.sample
+++ /dev/null
@@ -1,92 +0,0 @@
-;
-; isdn4linux
-;
-; Configuration file
-;
-[interfaces]
-;
-; By default, incoming calls should come in on the "remote" context
-;
-context=remote
-;
-; Modem Drivers to load
-;
-driver=aopen ; modem by AOpen
-;driver=i4l ; isdn4linux - an alternative to i4l is to use chan_capi
-;
-; Default language
-;
-;language=en
-;
-; We can optionally override the auto detection. This is necessary
-; particularly if asterisk does not know about our kind of modem.
-;
-;type=autodetect
-;type=aopen
-;
-; We can strip a given number of digits on outgoing dialing, so, for example
-; you can have it dial "8871042" when given "98871042".
-;
-stripmsd=0
-;
-; Type of dialing
-;
-dialtype=tone
-;dialtype=pulse
-;
-; Mode selection. "Immediate" means that as soon as you dial, you're connected
-; and the line is considered up. "Ring" means we wait until the ring cadence
-; occurs at least once. "Answer" means we wait until the other end picks up.
-;
-;mode=answer
-;mode=ring
-mode=immediate
-;
-; List all devices we can use.
-;
-;device => /dev/ttyS3
-;
-; ISDN example (using i4l)
-;
-;msn=39907835
-;device => /dev/ttyI0
-
-;===============
-; More complex ISDN example
-;
-; A single device which listens to 3 MSNs
-; the wildcard '*' can be used when all MSN's should be accepted.
-; (The incoming number can be used to go directly into the extension
-; with the matching number. I.e. if MSN 33 is called, (context,33)
-; will tried first, than (context,s) and finally (default,s).
-;
-;msn=50780020
-;incomingmsn=50780020,50780021,50780022
-;device => /dev/ttyI2
-;
-; If set, only these numbers are allowed to be set as A number
-; when making an outbound call. callerid is used to set A
-; number.
-;outgoingmsn=50780023,50780024
-;
-
-; Set DTMF-detection/generation mode to:
-; asterisk: Let Asterisk do inband detection (default)
-; i4l: Use the inband detection made by ISDN4Linux
-; none: Don't detect inband DTMF
-; both: Transmit using both in-band and out of band (generation only)
-;
-; You may specify either one mode, or the detection/generation mode
-; individually separated by a '/'.
-;
-;dtmfmode=asterisk ; Detect using Asterisk
-;dtmfmode=asterisk/both ; Detect using Asterisk, generate w/ both
-; two other devices, which are in group '1' and are used when an
-; outgoing dial used: exten => s,1,Dial,Modem/g1:1234|60|r
-; (we do not need more outgoing devices, since ISDN2 has only 2 channels.)
-; Lines can be in more than one group (0-63); comma separated list.
-;
-group=1 ; group=1,2,3,9-12
-;msn=50780023
-;device => /dev/ttyI3
-;device => /dev/ttyI4
diff --git a/1.2-netsec/configs/modules.conf.sample b/1.2-netsec/configs/modules.conf.sample
deleted file mode 100644
index 418433688..000000000
--- a/1.2-netsec/configs/modules.conf.sample
+++ /dev/null
@@ -1,53 +0,0 @@
-;
-; Asterisk configuration file
-;
-; Module Loader configuration file
-;
-
-[modules]
-autoload=yes
-;
-; Any modules that need to be loaded before the Asterisk core has been
-; initialized (just after the logger has been initialized) can be loaded
-; using 'preload'. This will frequently be needed if you wish to map all
-; module configuration files into Realtime storage, since the Realtime
-; driver will need to be loaded before the modules using those configuration
-; files are initialized.
-;
-; An example of loading ODBC support would be:
-;preload => res_odbc.so
-;preload => res_config_odbc.so
-;
-; If you want, load the GTK console right away.
-; Don't load the KDE console since
-; it's not as sophisticated right now.
-;
-noload => pbx_gtkconsole.so
-;load => pbx_gtkconsole.so
-noload => pbx_kdeconsole.so
-;
-; Intercom application is obsoleted by
-; chan_oss. Don't load it.
-;
-noload => app_intercom.so
-;
-; The 'modem' channel driver and its subdrivers are
-; obsolete, don't load them.
-;
-noload => chan_modem.so
-noload => chan_modem_aopen.so
-noload => chan_modem_bestdata.so
-noload => chan_modem_i4l.so
-;
-load => res_musiconhold.so
-;
-; Load either OSS or ALSA, not both
-; By default, load OSS only (automatically) and do not load ALSA
-;
-noload => chan_alsa.so
-;noload => chan_oss.so
-;
-; Module names listed in "global" section will have symbols globally
-; exported to modules loaded after them.
-;
-[global]
diff --git a/1.2-netsec/configs/musiconhold.conf.sample b/1.2-netsec/configs/musiconhold.conf.sample
deleted file mode 100644
index 6b3e7b694..000000000
--- a/1.2-netsec/configs/musiconhold.conf.sample
+++ /dev/null
@@ -1,64 +0,0 @@
-;
-; Music on Hold -- Sample Configuration
-;
-
-[default]
-mode=quietmp3
-directory=/var/lib/asterisk/mohmp3
-
-; valid mode options:
-; quietmp3 -- default
-; mp3 -- loud
-; mp3nb -- unbuffered
-; quietmp3nb -- quiet unbuffered
-; custom -- run a custom application
-; files -- read files from a directory in any Asterisk supported format
-
-;[manual]
-;mode=custom
-; Note that with mode=custom, a directory is not required, such as when reading
-; from a stream.
-;directory=/var/lib/asterisk/mohmp3
-;application=/usr/bin/mpg123 -q -r 8000 -f 8192 -b 2048 --mono -s
-
-;[ulawstream]
-;mode=custom
-;application=/usr/bin/streamplayer 192.168.100.52 888
-;format=ulaw
-
-; mpg123 on Solaris does not always exit properly; madplay may be a better
-; choice
-;[solaris]
-;mode=custom
-;directory=/var/lib/asterisk/mohmp3
-;application=/site/sw/bin/madplay -Q -o raw:- --mono -R 8000 -a -12
-;
-
-;
-; File-based (native) music on hold
-;
-; This plays files directly from the specified directory, no external
-; processes are required. Files are played in normal sorting order
-; (same as a sorted directory listing), and no volume or other
-; sound adjustments are available. If the file is available in
-; the same format as the channel's codec, then it will be played
-; without transcoding (same as Playback would do in the dialplan).
-; Files can be present in as many formats as you wish, and the
-; 'best' format will be chosen at playback time.
-;
-; NOTE:
-; If you are not using "autoload" in modules.conf, then you
-; must ensure that the format modules for any formats you wish
-; to use are loaded _before_ res_musiconhold. If you do not do
-; this, res_musiconhold will skip the files it is not able to
-; understand when it loads.
-;
-
-;[native]
-;mode=files
-;directory=/var/lib/asterisk/moh-native
-;
-;[native-random]
-;mode=files
-;directory=/var/lib/asterisk/moh-native
-;random=yes ; Play the files in a random order
diff --git a/1.2-netsec/configs/osp.conf.sample b/1.2-netsec/configs/osp.conf.sample
deleted file mode 100644
index e7e04036a..000000000
--- a/1.2-netsec/configs/osp.conf.sample
+++ /dev/null
@@ -1,64 +0,0 @@
-;
-; Open Settlement Protocol Sample Configuration File
-;
-;
-; This file contains configuration of providers that
-; are used by the OSP subsystem of Asterisk. The section
-; "general" is reserved for global options. Each other
-; section declares an OSP Provider. The provider "default"
-; is used when no provider is otherwise specified.
-;
-[general]
-;
-; Should hardware accelleration be enabled? May not be changed
-; on a reload.
-;
-;accelerate=yes
-;
-; Defines the token format that Asterisk can validate.
-; 0 - signed tokens only
-; 1 - unsigned tokens only
-; 2 - both signed and unsigned
-; The defaults to 0, i.e. the Asterisk can validate signed tokens only.
-;
-;tokenformat=0
-
-;[default]
-;
-; All paths are presumed to be under /var/lib/asterisk/keys unless
-; the path begins with '/'
-;
-; Specify the private keyfile. If unspecified, defaults to the name
-; of the section followed by "-privatekey.pem" (e.g. default-privatekey.pem)
-;
-;privatekey=pkey.pem
-;
-; Specify the local certificate file. If unspecified, defaults to
-; the name of the section followed by "-localcert.pem"
-;
-;localcert=localcert.pem
-;
-; Specify one or more Certificate Authority keys. If none are listed,
-; a single one is added with the name "-cacert.pem"
-;
-;cacert=cacert_0.pem
-;
-; Specific parameters can be tuned as well:
-;
-; maxconnections: Max number of simultaneous connections to the provider (default=20)
-; retrydelay: Extra delay between retries (default=0)
-; retrylimit: Max number of retries before giving up (default=2)
-; timeout: Timeout for response in milliseconds (default=500)
-;
-;maxconnections=20
-;retrydelay=0
-;retrylimit=2
-;timeout=500
-;
-; List all service points for this provider
-;
-;servicepoint=http://osptestserver.transnexus.com:1080/osp
-;
-; Set the "source" for requesting authorization
-;
-;source=foo
diff --git a/1.2-netsec/configs/oss.conf.sample b/1.2-netsec/configs/oss.conf.sample
deleted file mode 100644
index 148a2a656..000000000
--- a/1.2-netsec/configs/oss.conf.sample
+++ /dev/null
@@ -1,39 +0,0 @@
-;
-; Open Sound System Console Driver Configuration File
-;
-[general]
-;
-; Automatically answer incoming calls on the console? Choose yes if
-; for example you want to use this as an intercom.
-;
-autoanswer=yes
-;
-; Default context (is overridden with @context syntax)
-;
-context=local
-;
-; Set overridecontext to yes if you want the context specified above
-; to override what someone places on the command line.
-;
-;overridecontext=yes
-;
-; Default extension to call
-;
-extension=s
-;
-; Default language
-;
-;language=en
-;
-; Silence supression can be enabled when sound is over a certain threshold.
-; The value for the threshold should probably be between 500 and 2000 or so,
-; but your mileage may vary. Use the echo test to evaluate the best setting.
-;silencesuppression = yes
-;silencethreshold = 1000
-;
-; On half-duplex cards, the driver attempts to switch back and forth between
-; read and write modes. Unfortunately, this fails sometimes on older hardware.
-; To prevent the driver from switching (ie. only play files on your speakers),
-; then set the playbackonly option to yes. Default is no. Note this option has
-; no effect on full-duplex cards.
-;playbackonly=no
diff --git a/1.2-netsec/configs/phone.conf.sample b/1.2-netsec/configs/phone.conf.sample
deleted file mode 100644
index ca028f9a1..000000000
--- a/1.2-netsec/configs/phone.conf.sample
+++ /dev/null
@@ -1,47 +0,0 @@
-;
-; Linux Telephony Interface
-;
-; Configuration file
-;
-[interfaces]
-;
-; Select a mode, either the phone jack provides dialtone, reads digits,
-; then starts PBX with the given extension (dialtone mode), or
-; immediately provides the PBX without reading any digits or providing
-; any dialtone (this is the immediate mode, the default). Also, you
-; can set the mode to "fxo" if you have a linejack to make it operate
-; properly.
-;
-mode=immediate
-;mode=dialtone
-;mode=fxo
-;
-; You can decide which format to use by default, "g723.1" or "slinear".
-; XXX Be careful, sometimes the card causes kernel panics when running
-; in signed linear mode for some reason... XXX
-;
-format=slinear
-;format=g723.1
-;
-; And set the echo cancellation to "off", "low", "medium", and "high".
-; This is not supported on all phones.
-;
-echocancel=medium
-;
-; You can optionally use VAD/CNG silence supression
-;
-;silencesupression=yes
-;
-; List all devices we can use. Contexts may also be specified
-;
-;context=local
-;
-; You can set txgain and rxgain for each device in the same way as context.
-; If you want to change default gain value (1.0 =~ 100%) for device, simple
-; add txgain or rxgain line before device line. But rememeber, if you change
-; volume all cards listed below will be affected by these values. You can
-; use float values (1.0, 0.5, 2.0) or percentage values (100%, 150%, 50%).
-;
-;txgain=100%
-;rxgain=1.0
-;device => /dev/phone0
diff --git a/1.2-netsec/configs/privacy.conf.sample b/1.2-netsec/configs/privacy.conf.sample
deleted file mode 100644
index 0236bccb7..000000000
--- a/1.2-netsec/configs/privacy.conf.sample
+++ /dev/null
@@ -1,3 +0,0 @@
-[general]
-
-maxretries = 2 ;How many chances the caller has to enter their number
diff --git a/1.2-netsec/configs/queues.conf.sample b/1.2-netsec/configs/queues.conf.sample
deleted file mode 100644
index ba7a082b5..000000000
--- a/1.2-netsec/configs/queues.conf.sample
+++ /dev/null
@@ -1,200 +0,0 @@
-[general]
-;
-; Global settings for call queues
-;
-; Persistent Members
-; Store each dynamic agent in each queue in the astdb so that
-; when asterisk is restarted, each agent will be automatically
-; readded into their recorded queues. Default is 'yes'.
-;
-persistentmembers = yes
-;
-; Note that a timeout to fail out of a queue may be passed as part of
-; an application call from extensions.conf:
-; Queue(queuename|[options]|[optionalurl]|[announceoverride]|[timeout])
-; example: Queue(dave|t|||45)
-
-;[markq]
-;
-; A sample call queue
-;
-; Musiconhold sets which music applies for this particular
-; call queue (configure classes in musiconhold.conf)
-;
-;musiconhold = default
-;
-; An announcement may be specified which is played for the member as
-; soon as they answer a call, typically to indicate to them which queue
-; this call should be answered as, so that agents or members who are
-; listening to more than one queue can differentiated how they should
-; engage the customer
-;
-;announce = queue-markq
-;
-; A strategy may be specified. Valid strategies include:
-;
-; ringall - ring all available channels until one answers (default)
-; roundrobin - take turns ringing each available interface
-; leastrecent - ring interface which was least recently called by this queue
-; fewestcalls - ring the one with fewest completed calls from this queue
-; random - ring random interface
-; rrmemory - round robin with memory, remember where we left off last ring pass
-;
-;strategy = ringall
-;
-; Second settings for service level (default 0)
-; Used for service level statistics (calls answered within service level time
-; frame)
-;servicelevel = 60
-;
-; A context may be specified, in which if the user types a SINGLE
-; digit extension while they are in the queue, they will be taken out
-; of the queue and sent to that extension in this context.
-;
-;context = qoutcon
-;
-; How long do we let the phone ring before we consider this a timeout...
-;
-;timeout = 15
-;
-; How long do we wait before trying all the members again?
-;
-;retry = 5
-;
-; Weight of queue - when compared to other queues, higher weights get
-; first shot at available channels when the same channel is included in
-; more than one queue.
-;
-;weight=0
-;
-; After a successful call, how long to wait before sending a potentially
-; free member another call (default is 0, or no delay)
-;
-;wrapuptime=15
-;
-; Maximum number of people waiting in the queue (0 for unlimited)
-;
-;maxlen = 0
-;
-;
-; How often to announce queue position and/or estimated holdtime to caller (0=off)
-;
-;announce-frequency = 90
-;
-;
-; How often to make any periodic announcement (see periodic-announce)
-;
-;periodic-announce-frequency=60
-;
-; Should we include estimated hold time in position announcements?
-; Either yes, no, or only once.
-; Hold time will be announced as the estimated time,
-; or "less than 2 minutes" when appropriate.
-;
-;announce-holdtime = yes|no|once
-
-;
-; What's the rounding time for the seconds?
-; If this is non-zero, then we announce the seconds as well as the minutes
-; rounded to this value.
-;
-; announce-round-seconds = 10
-;
-; Use these sound files in making position/holdtime announcements. The
-; defaults are as listed below -- change only if you need to.
-;
-;queue-youarenext = queue-youarenext ; ("You are now first in line.")
-;queue-thereare = queue-thereare ; ("There are")
-;queue-callswaiting = queue-callswaiting ; ("calls waiting.")
-;queue-holdtime = queue-holdtime ; ("The current est. holdtime is")
-;queue-minutes = queue-minutes ; ("minutes.")
-;queue-seconds = queue-seconds ; ("seconds.")
-;queue-thankyou = queue-thankyou ; ("Thank you for your patience.")
-;queue-lessthan = queue-less-than ; ("less than")
-;queue-reporthold = queue-reporthold ; ("Hold time")
-;periodic-announce = queue-periodic-announce ; ("All reps busy / wait for next")
-;
-; Calls may be recorded using Asterisk's monitor resource
-; This can be enabled from within the Queue application, starting recording
-; when the call is actually picked up; thus, only successful calls are
-; recorded, and you are not recording while people are listening to MOH.
-; To enable monitoring, simply specify "monitor-format"; it will be disabled
-; otherwise.
-;
-; You can specify the monitor filename with by calling
-; Set(MONITOR_FILENAME=foo)
-; Otherwise it will use MONITOR_FILENAME=${UNIQUEID}
-;
-; monitor-format = gsm|wav|wav49
-;
-; If you wish to have the two files joined together when the call ends, set this
-; to yes.
-;
-; monitor-join = yes
-;
-; This setting controls whether callers can join a queue with no members. There
-; are three choices:
-;
-; yes - callers can join a queue with no members or only unavailable members
-; no - callers cannot join a queue with no members
-; strict - callers cannot join a queue with no members or only unavailable
-; members
-;
-; joinempty = yes
-;
-; If you wish to remove callers from the queue when new callers cannot join,
-; set this setting to one of the same choices for 'joinempty'
-;
-; leavewhenempty = yes
-;
-;
-; If this is set to yes, the following manager events will be generated:
-; AgentCalled, AgentDump, AgentConnect, AgentComplete
-; (may generate some extra manager events, but probably ones you want)
-;
-; eventwhencalled = yes
-;
-; If this is set to no, the following manager events will be generated:
-; QueueMemberStatus
-; (may generate a WHOLE LOT of extra manager events)
-;
-; eventmemberstatusoff = no
-;
-; If you wish to report the caller's hold time to the member before they are
-; connected to the caller, set this to yes.
-;
-; reportholdtime = no
-;
-;
-; If you wish to have a delay before the member is connected to the caller (or
-; before the member hears any announcement messages), set this to the number of
-; seconds to delay.
-;
-; memberdelay = 0
-;
-; If timeoutrestart is set to yes, then the timeout for an agent to answer is
-; reset if a BUSY or CONGESTION is received. This can be useful if agents
-; are able to cancel a call with reject or similar.
-;
-; timeoutrestart = no
-;
-; Each member of this call queue is listed on a separate line in
-; the form technology/dialstring. "member" means a normal member of a
-; queue. An optional penalty may be specified after a comma, such that
-; entries with higher penalties are considered last.
-;
-;member => Zap/1
-;member => Zap/2
-;member => Agent/1001
-;member => Agent/1002
-
-;
-; Note that using agent groups is probably not what you want. Strategies do
-; not propagate down to the Agent system so if you want round robin, least
-; recent, etc, you should list all the agents in this file individually and not
-; use agent groups.
-;
-;member => Agent/@1 ; Any agent in group 1
-;member => Agent/:1,1 ; Any agent in group 1, wait for first
- ; available, but consider with penalty
-
diff --git a/1.2-netsec/configs/res_odbc.conf.sample b/1.2-netsec/configs/res_odbc.conf.sample
deleted file mode 100644
index 59d5c68c3..000000000
--- a/1.2-netsec/configs/res_odbc.conf.sample
+++ /dev/null
@@ -1,31 +0,0 @@
-;;; odbc setup file
-
-; ENV is a global set of environmental variables that will get set.
-; Note that all environmental variables can be seen by all connections,
-; so you can't have different values for different connections.
-[ENV]
-INFORMIXSERVER => my_special_database
-INFORMIXDIR => /opt/informix
-
-; All other sections are arbitrary names for database connections.
-
-[asterisk]
-enabled => yes
-dsn => asterisk
-;username => myuser
-;password => mypass
-pre-connect => yes
-
-
-[mysql2]
-enabled => no
-dsn => MySQL-asterisk
-username => myuser
-password => mypass
-pre-connect => yes
-
-
-
-
-
-
diff --git a/1.2-netsec/configs/rpt.conf.sample b/1.2-netsec/configs/rpt.conf.sample
deleted file mode 100644
index a66e50b92..000000000
--- a/1.2-netsec/configs/rpt.conf.sample
+++ /dev/null
@@ -1,180 +0,0 @@
-; Radio Repeater / Remote Base configuration file (for use with app_rpt)
-; As of app_rpt version 0.36, 10/26/2005
-;
-
-;[000] ; Node ID of first repeater
-
-;rxchannel = Zap/1 ; Rx audio/signalling channel
-; Note: if you use a unified interface (tx/rx on one channel), only
-; specify the rxchannel and the txchannel will be assumed from the rxchannel
-;txchannel = Zap/2 ; Tx audio/signalling channel
-;functions = functions-repeater ; DTMF function list
-;; specify this for a different function list then local when on link
-;;link_functions = functions-different ; DTMF function list for link
-;;phone_functions = functions-phone ; (optional) different functions for 'P' mode
-;;dphone_functions = functions-dphone ; (optional) different functions for 'D' mode
-;;nodes = nodes-different ; (optional) different node list
-;tonezone = us ; use US tones (default)
-;context = default ; dialing context for phone
-;callerid = "WB6NIL Repeater" <(213) 555-0123> ; Callerid for phone calls
-;idrecording = wb6nil ; id recording
-;accountcode=RADIO ; account code (optional)
-;funcchar = * ; function lead-in character (defaults to '*')
-;endchar = # ; command mode end character (defaults to '#')
-;;nobusyout=yes ; (optional) Do not busy-out reverse-patch when
- ; normal patch in use
-;hangtime=1000 ; squelch tail hang time (in ms) (optional)
-;totime=100000 ; transmit time-out time (in ms) (optional)
-;idtime=30000 ; id interval time (in ms) (optional)
-;politeid=30000 ; time in milliseconds before ID timer
- ; expires to try and ID in the tail.
- ; (optional, default is 30000).
-;idtalkover=|iwb6nil/rpt ; Talkover ID (optional) default is none
-;unlinkedct=ct2 ; unlinked courtesy tone (optional) default is none
-
-; The default values for hangtime, time-out time, and id interval time are
-; 5 seconds (5000 ms), 3 minutes (180000 ms), and 5 minutes (300000 ms)
-; respectively
-
-;[001] ; Node ID of first repeater
-
-;rxchannel = Zap/3 ; Rx audio/signalling channel
-; Note: if you use a unified interface (tx/rx on one channel), only
-; specify the rxchannel and the txchannel will be assumed from the rxchannel
-;txchannel = Zap/4 ; Tx audio/signalling channel
-;functions = functions-repeater ; DTMF function list
-;; specify this for a different function list then local when on link
-;;link_functions = functions-different ; DTMF function list for link
-;;phone_functions = functions-phone ; (optional) different functions for 'P' mode
-;;dphone_functions = functions-dphone ; (optional) different functions for 'D' mode
-;;nodes = nodes-different ; (optional) different node list
-;tonezone = us ; use US tones (default)
-;context = default ; dialing context for phone
-;callerid = "WB6NIL Repeater" <(213) 555-0123> ; Callerid for phone calls
-;idrecording = wb6nil ; id recording
-;accountcode=RADIO ; account code (optional)
-;funcchar = * ; function lead-in character (defaults to '*')
-;endchar = # ; command mode end character (defaults to '#')
-;;nobusyout=yes ; (optional) Do not busy-out reverse-patch when
- ; normal patch in use
-;hangtime=1000 ; squelch tail hang time (in ms) (optional)
-;totime=100000 ; transmit time-out time (in ms) (optional)
-;idtime=30000 ; id interval time (in ms) (optional)
-;politeid=30000 ; time in milliseconds before ID timer
- ; expires to try and ID in the tail.
- ; (optional, default is 30000).
-;idtalkover=|iwb6nil/rpt ; Talkover ID (optional) default is none
-;unlinkedct=ct2 ; unlinked courtesy tone (optional) default is none
-
-;[002] ; Node ID of remote base
-
-;rxchannel = Zap/5 ; Rx audio/signalling channel
-; Note: if you use a unified interface (tx/rx on one channel), only
-; specify the rxchannel and the txchannel will be assumed from the rxchannel
-;txchannel = Zap/6 ; Tx audio/signalling channel
-;functions = functions-remote
-;remote = ft897 ; Set remote=y for dumb remote or
- ; remote=ft897 for Yaesu FT-897 or
- ; remote=rbi for Doug Hall RBI1
-;iobase = 0x378 ; Specify IO port for parallel port (optional)
-
-;[functions-repeater]
-;1=ilink,1 ; Specific link disconnect
-;2=ilink,2 ; Specific Link connect - monitor only
-;3=ilink,3 ; Specific Link connect - transceive
-;4=ilink,4 ; Enter command mode on a specific link
-;7=ilink,5 ; Link status
-;;XX=ilink,6 ; Disconnect all links (not used here)
-
-;80=status,1 ; System info
-;81=status,2 ; Time
-;82=status,3 ; app_rpt.c Version
-
-;6=autopatchup ; Autopatch up
-;0=autopatchdn ; Autopatch down
-
-;90=cop,1 ; System warm boot
-;91=cop,2 ; System enable
-;92=cop,3 ; System disable
-
-;[functions-remote]
-
-;0=remote,1 ; Retrieve Memory
-;1=remote,2 ; Set freq.
-;2=remote,3 ; Set Rx PL tone.
-;40=remote,100 ; Rx PL off
-;41=remote,101 ; Rx PL on
-;42=remote,102 ; Tx PL off
-;43=remote,103 ; Tx PL on
-;44=remote,104 ; Low Pwr
-;45=remote,105 ; Med Pwr
-;46=remote,106 ; Hi Pwr
-;5=remote,5 ; Status
-
-;[telemetry]
-
-; Telemetry entries are shared across all repeaters
-; Can be a tone sequence, morse string, or a file
-;
-; |t - Tone escape sequence
-;
-; Tone sequences consist of 1 or more 4-tuple entries (freq1, freq2, duration, amplitude)
-; Single frequencies are created by setting freq1 or freq2 to zero.
-;
-; |m - Morse escape sequence
-;
-; Sends Morse code at the telemetry amplitude and telemetry frequency as defined in the
-; [morse] section.
-;
-; Follow with an alphanumeric string
-;
-; |i - Morse ID escape sequence
-;
-; Sends Morse code at the ID amplitude and ID frequency as defined in the
-; [morse] section.
-;
-; Follow with an alphanumeric string
-
-
-;ct1=|t(350,0,100,2048)(500,0,100,2048)(660,0,100,2048)
-;ct2=|t(660,880,150,2048)
-;ct3=|t(440,0,150,2048)
-;ct4=|t(550,0,150,2048)
-;ct5=|t(660,0,150,2048)
-;ct6=|t(880,0,150,2048)
-;ct7=|t(660,440,150,2048)
-;ct8=|t(700,1100,150,2048)
-;remotetx=|t(2000,0,75,2048)(0,0,75,0)(1600,0,75,2048);
-;remotemon=|t(1600,0,75,2048)
-;cmdmode=|t(900,903,200,2048)
-;functcomplete=|t(1000,0,100,2048)(0,0,100,0)(1000,0,100,2048)
-
-
-;[morse]
-
-;speed=20 ; Approximate speed in WPM
-;frequency=800 ; Morse Telemetry Frequency
-;amplitude=4096 ; Morse Telemetry Amplitude
-;idfrequency=330 ; Morse ID Frequency
-;idamplitude=2048 ; Morse ID Amplitude
-
-;[nodes]
-
-;000 = context_A@foo.bar.com/1234,foo.bar.com
-;001 = context_B@baz.waldo.com/4321,baz.waldo.com
-;002 = context_C@pepper.salt.com/5678,pepper.salt.com,y ; this is a remote
-
-;of course, you can also specify these with domain names, but why rely
-;on DNS working unnecessarily?
-
-;[memory]
-
-;; this example gives you 146.460, simplex, 100.0 HZ PL, hi-power, transmit PL
-;00 = 146.460,100.0,sht
-;; this example gives you 146.940, minus offset, 100.0 HZ PL, low-power, no PL
-;01 = 146.940,100.0,-l
-
-; The format for these entries is: Receive-Freq,Receive-PL,Attrbutes
-; Attributes: l=low power, m=medium power, h=high power, -=minus offset,
-; s=simplex, +=plus offset, t=tx PL enable, r=rx PL enable
-
diff --git a/1.2-netsec/configs/rtp.conf.sample b/1.2-netsec/configs/rtp.conf.sample
deleted file mode 100644
index fa16f0d93..000000000
--- a/1.2-netsec/configs/rtp.conf.sample
+++ /dev/null
@@ -1,20 +0,0 @@
-;
-; RTP Configuration
-;
-[general]
-;
-; RTP start and RTP end configure start and end addresses
-;
-; Defaults are rtpstart=5000 and rtpend=31000
-;
-rtpstart=10000
-rtpend=20000
-;
-; Whether to enable or disable UDP checksums on RTP traffic
-;
-;rtpchecksums=no
-;
-; The amount of time a DTMF digit with no 'end' marker should be
-; allowed to continue (in 'samples', 1/8000 of a second)
-;
-;dtmftimeout=3000
diff --git a/1.2-netsec/configs/sip.conf.sample b/1.2-netsec/configs/sip.conf.sample
deleted file mode 100644
index 3d9299c05..000000000
--- a/1.2-netsec/configs/sip.conf.sample
+++ /dev/null
@@ -1,441 +0,0 @@
-;
-; SIP Configuration example for Asterisk
-;
-; Syntax for specifying a SIP device in extensions.conf is
-; SIP/devicename where devicename is defined in a section below.
-;
-; You may also use
-; SIP/username@domain to call any SIP user on the Internet
-; (Don't forget to enable DNS SRV records if you want to use this)
-;
-; If you define a SIP proxy as a peer below, you may call
-; SIP/proxyhostname/user or SIP/user@proxyhostname
-; where the proxyhostname is defined in a section below
-;
-; Useful CLI commands to check peers/users:
-; sip show peers Show all SIP peers (including friends)
-; sip show users Show all SIP users (including friends)
-; sip show registry Show status of hosts we register with
-;
-; sip debug Show all SIP messages
-;
-; reload chan_sip.so Reload configuration file
-; Active SIP peers will not be reconfigured
-;
-
-[general]
-context=default ; Default context for incoming calls
-;allowguest=no ; Allow or reject guest calls (default is yes, this can also be set to 'osp'
- ; if asterisk was compiled with OSP support.
-;realm=mydomain.tld ; Realm for digest authentication
- ; defaults to "asterisk"
- ; Realms MUST be globally unique according to RFC 3261
- ; Set this to your host name or domain name
-bindport=5060 ; UDP Port to bind to (SIP standard port is 5060)
-bindaddr=0.0.0.0 ; IP address to bind to (0.0.0.0 binds to all)
-srvlookup=yes ; Enable DNS SRV lookups on outbound calls
- ; Note: Asterisk only uses the first host
- ; in SRV records
- ; Disabling DNS SRV lookups disables the
- ; ability to place SIP calls based on domain
- ; names to some other SIP users on the Internet
-
-;domain=mydomain.tld ; Set default domain for this host
- ; If configured, Asterisk will only allow
- ; INVITE and REFER to non-local domains
- ; Use "sip show domains" to list local domains
-;domain=mydomain.tld,mydomain-incoming
- ; Add domain and configure incoming context
- ; for external calls to this domain
-;domain=1.2.3.4 ; Add IP address as local domain
- ; You can have several "domain" settings
-;allowexternalinvites=no ; Disable INVITE and REFER to non-local domains
- ; Default is yes
-;autodomain=yes ; Turn this on to have Asterisk add local host
- ; name and local IP to domain list.
-;pedantic=yes ; Enable slow, pedantic checking for Pingtel
- ; and multiline formatted headers for strict
- ; SIP compatibility (defaults to "no")
-;tos=184 ; Set IP QoS to either a keyword or numeric val
-;tos=lowdelay ; lowdelay,throughput,reliability,mincost,none
-;maxexpiry=3600 ; Max length of incoming registration we allow
-;defaultexpiry=120 ; Default length of incoming/outoing registration
-;notifymimetype=text/plain ; Allow overriding of mime type in MWI NOTIFY
-;checkmwi=10 ; Default time between mailbox checks for peers
-;vmexten=voicemail ; dialplan extension to reach mailbox sets the
- ; Message-Account in the MWI notify message
- ; defaults to "asterisk"
-;videosupport=yes ; Turn on support for SIP video
-;recordhistory=yes ; Record SIP history by default
- ; (see sip history / sip no history)
-
-;disallow=all ; First disallow all codecs
-;allow=ulaw ; Allow codecs in order of preference
-;allow=ilbc ;
-;musicclass=default ; Sets the default music on hold class for all SIP calls
- ; This may also be set for individual users/peers
-;language=en ; Default language setting for all users/peers
- ; This may also be set for individual users/peers
-;relaxdtmf=yes ; Relax dtmf handling
-;rtptimeout=60 ; Terminate call if 60 seconds of no RTP activity
- ; when we're not on hold
-;rtpholdtimeout=300 ; Terminate call if 300 seconds of no RTP activity
- ; when we're on hold (must be > rtptimeout)
-;trustrpid = no ; If Remote-Party-ID should be trusted
-;sendrpid = yes ; If Remote-Party-ID should be sent
-;progressinband=never ; If we should generate in-band ringing always
- ; use 'never' to never use in-band signalling, even in cases
- ; where some buggy devices might not render it
-;useragent=Asterisk PBX ; Allows you to change the user agent string
-;promiscredir = no ; If yes, allows 302 or REDIR to non-local SIP address
- ; Note that promiscredir when redirects are made to the
- ; local system will cause loops since SIP is incapable
- ; of performing a "hairpin" call.
-;usereqphone = no ; If yes, ";user=phone" is added to uri that contains
- ; a valid phone number
-;dtmfmode = rfc2833 ; Set default dtmfmode for sending DTMF. Default: rfc2833
- ; Other options:
- ; info : SIP INFO messages
- ; inband : Inband audio (requires 64 kbit codec -alaw, ulaw)
- ; auto : Use rfc2833 if offered, inband otherwise
-
-;compactheaders = yes ; send compact sip headers.
-;sipdebug = yes ; Turn on SIP debugging by default, from
- ; the moment the channel loads this configuration
-;subscribecontext = default ; Set a specific context for SUBSCRIBE requests
- ; Useful to limit subscriptions to local extensions
- ; Settable per peer/user also
-;notifyringing = yes ; Notify subscriptions on RINGING state
-
-;
-; If regcontext is specified, Asterisk will dynamically create and destroy a
-; NoOp priority 1 extension for a given peer who registers or unregisters with
-; us. The actual extension is the 'regexten' parameter of the registering
-; peer or its name if 'regexten' is not provided. More than one regexten may
-; be supplied if they are separated by '&'. Patterns may be used in regexten.
-;
-;regcontext=sipregistrations
-;
-; Asterisk can register as a SIP user agent to a SIP proxy (provider)
-; Format for the register statement is:
-; register => user[:secret[:authuser]]@host[:port][/extension]
-;
-; If no extension is given, the 's' extension is used. The extension needs to
-; be defined in extensions.conf to be able to accept calls from this SIP proxy
-; (provider).
-;
-; host is either a host name defined in DNS or the name of a section defined
-; below.
-;
-; Examples:
-;
-;register => 1234:password@mysipprovider.com
-;
-; This will pass incoming calls to the 's' extension
-;
-;
-;register => 2345:password@sip_proxy/1234
-;
-; Register 2345 at sip provider 'sip_proxy'. Calls from this provider
-; connect to local extension 1234 in extensions.conf, default context,
-; unless you configure a [sip_proxy] section below, and configure a
-; context.
-; Tip 1: Avoid assigning hostname to a sip.conf section like [provider.com]
-; Tip 2: Use separate type=peer and type=user sections for SIP providers
-; (instead of type=friend) if you have calls in both directions
-
-;registertimeout=20 ; retry registration calls every 20 seconds (default)
-;registerattempts=10 ; Number of registration attempts before we give up
- ; 0 = continue forever, hammering the other server until it
- ; accepts the registration
- ; Default is 0 tries, continue forever
-;callevents=no ; generate manager events when sip ua performs events (e.g. hold)
-
-;----------------------------------------- NAT SUPPORT ------------------------
-; The externip, externhost and localnet settings are used if you use Asterisk
-; behind a NAT device to communicate with services on the outside.
-
-;externip = 200.201.202.203 ; Address that we're going to put in outbound SIP messages
- ; if we're behind a NAT
-
- ; The externip and localnet is used
- ; when registering and communicating with other proxies
- ; that we're registered with
-;externhost=foo.dyndns.net ; Alternatively you can specify an
- ; external host, and Asterisk will
- ; perform DNS queries periodically. Not
- ; recommended for production
- ; environments! Use externip instead
-;externrefresh=10 ; How often to refresh externhost if
- ; used
- ; You may add multiple local networks. A reasonable set of defaults
- ; are:
-;localnet=192.168.0.0/255.255.0.0; All RFC 1918 addresses are local networks
-;localnet=10.0.0.0/255.0.0.0 ; Also RFC1918
-;localnet=172.16.0.0/12 ; Another RFC1918 with CIDR notation
-;localnet=169.254.0.0/255.255.0.0 ;Zero conf local network
-
-; The nat= setting is used when Asterisk is on a public IP, communicating with
-; devices hidden behind a NAT device (broadband router). If you have one-way
-; audio problems, you usually have problems with your NAT configuration or your
-; firewall's support of SIP+RTP ports. You configure Asterisk choice of RTP
-; ports for incoming audio in rtp.conf
-;
-;nat=no ; Global NAT settings (Affects all peers and users)
- ; yes = Always ignore info and assume NAT
- ; no = Use NAT mode only according to RFC3581
- ; never = Never attempt NAT mode or RFC3581 support
- ; route = Assume NAT, don't send rport
- ; (work around more UNIDEN bugs)
-
-;rtcachefriends=yes ; Cache realtime friends by adding them to the internal list
- ; just like friends added from the config file only on a
- ; as-needed basis? (yes|no)
-
-;rtupdate=yes ; Send registry updates to database using realtime? (yes|no)
- ; If set to yes, when a SIP UA registers successfully, the ip address,
- ; the origination port, the registration period, and the username of
- ; the UA will be set to database via realtime. If not present, defaults to 'yes'.
-
-;rtautoclear=yes ; Auto-Expire friends created on the fly on the same schedule
- ; as if it had just registered? (yes|no|<seconds>)
- ; If set to yes, when the registration expires, the friend will vanish from
- ; the configuration until requested again. If set to an integer,
- ; friends expire within this number of seconds instead of the
- ; registration interval.
-
-;ignoreregexpire=yes ; Enabling this setting has two functions:
- ;
- ; For non-realtime peers, when their registration expires, the information
- ; will _not_ be removed from memory or the Asterisk database; if you attempt
- ; to place a call to the peer, the existing information will be used in spite
- ; of it having expired
- ;
- ; For realtime peers, when the peer is retrieved from realtime storage,
- ; the registration information will be used regardless of whether
- ; it has expired or not; if it expires while the realtime peer is still in
- ; memory (due to caching or other reasons), the information will not be
- ; removed from realtime storage
-
-; Incoming INVITE and REFER messages can be matched against a list of 'allowed'
-; domains, each of which can direct the call to a specific context if desired.
-; By default, all domains are accepted and sent to the default context or the
-; context associated with the user/peer placing the call.
-; Domains can be specified using:
-; domain=<domain>[,<context>]
-; Examples:
-; domain=myasterisk.dom
-; domain=customer.com,customer-context
-;
-; In addition, all the 'default' domains associated with a server should be
-; added if incoming request filtering is desired.
-; autodomain=yes
-;
-; To disallow requests for domains not serviced by this server:
-; allowexternaldomains=no
-
-; fromdomain=mydomain.tld ; When making outbound SIP INVITEs to
- ; non-peers, use your primary domain "identity"
- ; for From: headers instead of just your IP
- ; address. This is to be polite and
- ; it may be a mandatory requirement for some
- ; destinations which do not have a prior
- ; account relationship with your server.
-
-[authentication]
-; Global credentials for outbound calls, i.e. when a proxy challenges your
-; Asterisk server for authentication. These credentials override
-; any credentials in peer/register definition if realm is matched.
-;
-; This way, Asterisk can authenticate for outbound calls to other
-; realms. We match realm on the proxy challenge and pick an set of
-; credentials from this list
-; Syntax:
-; auth = <user>:<secret>@<realm>
-; auth = <user>#<md5secret>@<realm>
-; Example:
-;auth=mark:topsecret@digium.com
-;
-; You may also add auth= statements to [peer] definitions
-; Peer auth= override all other authentication settings if we match on realm
-
-;------------------------------------------------------------------------------
-; Users and peers have different settings available. Friends have all settings,
-; since a friend is both a peer and a user
-;
-; User config options: Peer configuration:
-; -------------------- -------------------
-; context context
-; permit permit
-; deny deny
-; secret secret
-; md5secret md5secret
-; dtmfmode dtmfmode
-; canreinvite canreinvite
-; nat nat
-; callgroup callgroup
-; pickupgroup pickupgroup
-; language language
-; allow allow
-; disallow disallow
-; insecure insecure
-; trustrpid trustrpid
-; progressinband progressinband
-; promiscredir promiscredir
-; useclientcode useclientcode
-; accountcode accountcode
-; setvar setvar
-; callerid callerid
-; amaflags amaflags
-; call-limit call-limit
-; restrictcid restrictcid
-; subscribecontext subscribecontext
-; mailbox
-; username
-; template
-; fromdomain
-; regexten
-; fromuser
-; host
-; port
-; qualify
-; defaultip
-; rtptimeout
-; rtpholdtimeout
-; sendrpid
-
-;[sip_proxy]
-; For incoming calls only. Example: FWD (Free World Dialup)
-; We match on IP address of the proxy for incoming calls
-; since we can not match on username (caller id)
-;type=peer
-;context=from-fwd
-;host=fwd.pulver.com
-
-;[sip_proxy-out]
-;type=peer ; we only want to call out, not be called
-;secret=guessit
-;username=yourusername ; Authentication user for outbound proxies
-;fromuser=yourusername ; Many SIP providers require this!
-;fromdomain=provider.sip.domain
-;host=box.provider.com
-;usereqphone=yes ; This provider requires ";user=phone" on URI
-;call-limit=5 ; permit only 5 simultaneous outgoing calls to this peer
-
-;------------------------------------------------------------------------------
-; Definitions of locally connected SIP phones
-;
-; type = user a device that authenticates to us by "from" field to place calls
-; type = peer a device we place calls to or that calls us and we match by host
-; type = friend two configurations (peer+user) in one
-;
-; For local phones, type=friend works most of the time
-;
-; If you have one-way audio, you propably have NAT problems.
-; If Asterisk is on a public IP, and the phone is inside of a NAT device
-; you will need to configure nat option for those phones.
-; Also, turn on qualify=yes to keep the nat session open
-
-;[grandstream1]
-;type=friend
-;context=from-sip ; Where to start in the dialplan when this phone calls
-;callerid=John Doe <1234> ; Full caller ID, to override the phones config
-;host=192.168.0.23 ; we have a static but private IP address
- ; No registration allowed
-;nat=no ; there is not NAT between phone and Asterisk
-;canreinvite=yes ; allow RTP voice traffic to bypass Asterisk
-;dtmfmode=info ; either RFC2833 or INFO for the BudgeTone
-;call-limit=1 ; permit only 1 outgoing call and 1 incoming call at a time
- ; from the phone to asterisk
- ; (1 for the explicit peer, 1 for the explicit user,
- ; remember that a friend equals 1 peer and 1 user in
- ; memory)
-;mailbox=1234@default ; mailbox 1234 in voicemail context "default"
-;disallow=all ; need to disallow=all before we can use allow=
-;allow=ulaw ; Note: In user sections the order of codecs
- ; listed with allow= does NOT matter!
-;allow=alaw
-;allow=g723.1 ; Asterisk only supports g723.1 pass-thru!
-;allow=g729 ; Pass-thru only unless g729 license obtained
-;astdb=chan2ext/SIP/grandstream1=1234 ; ensures an astDB entry exists
-
-
-;[xlite1]
-; Turn off silence suppression in X-Lite ("Transmit Silence"=YES)!
-; Note that Xlite sends NAT keep-alive packets, so qualify=yes is not needed
-;type=friend
-;regexten=1234 ; When they register, create extension 1234
-;callerid="Jane Smith" <5678>
-;host=dynamic ; This device needs to register
-;nat=yes ; X-Lite is behind a NAT router
-;canreinvite=no ; Typically set to NO if behind NAT
-;disallow=all
-;allow=gsm ; GSM consumes far less bandwidth than ulaw
-;allow=ulaw
-;allow=alaw
-;mailbox=1234@default,1233@default ; Subscribe to status of multiple mailboxes
-
-
-;[snom]
-;type=friend ; Friends place calls and receive calls
-;context=from-sip ; Context for incoming calls from this user
-;secret=blah
-;subscribecontext=localextensions ; Only allow SUBSCRIBE for local extensions
-;language=de ; Use German prompts for this user
-;host=dynamic ; This peer register with us
-;dtmfmode=inband ; Choices are inband, rfc2833, or info
-;defaultip=192.168.0.59 ; IP used until peer registers
-;mailbox=1234@context,2345 ; Mailbox(-es) for message waiting indicator
-;vmexten=voicemail ; dialplan extension to reach mailbox
- ; sets the Message-Account in the MWI notify message
- ; defaults to global vmexten which defaults to "asterisk"
-;restrictcid=yes ; To have the callerid restriced -> sent as ANI
-;disallow=all
-;allow=ulaw ; dtmfmode=inband only works with ulaw or alaw!
-
-
-;[polycom]
-;type=friend ; Friends place calls and receive calls
-;context=from-sip ; Context for incoming calls from this user
-;secret=blahpoly
-;host=dynamic ; This peer register with us
-;dtmfmode=rfc2833 ; Choices are inband, rfc2833, or info
-;username=polly ; Username to use in INVITE until peer registers
- ; Normally you do NOT need to set this parameter
-;disallow=all
-;allow=ulaw ; dtmfmode=inband only works with ulaw or alaw!
-;progressinband=no ; Polycom phones don't work properly with "never"
-
-
-;[pingtel]
-;type=friend
-;secret=blah
-;host=dynamic
-;insecure=port ; Allow matching of peer by IP address without matching port number
-;insecure=invite ; Do not require authentication of incoming INVITEs
-;insecure=port,invite ; (both)
-;qualify=1000 ; Consider it down if it's 1 second to reply
- ; Helps with NAT session
- ; qualify=yes uses default value
-;callgroup=1,3-4 ; We are in caller groups 1,3,4
-;pickupgroup=1,3-5 ; We can do call pick-p for call group 1,3,4,5
-;defaultip=192.168.0.60 ; IP address to use if peer has not registred
-
-;[cisco1]
-;type=friend
-;secret=blah
-;qualify=200 ; Qualify peer is no more than 200ms away
-;nat=yes ; This phone may be natted
- ; Send SIP and RTP to the IP address that packet is
- ; received from instead of trusting SIP headers
-;host=dynamic ; This device registers with us
-;canreinvite=no ; Asterisk by default tries to redirect the
- ; RTP media stream (audio) to go directly from
- ; the caller to the callee. Some devices do not
- ; support this (especially if one of them is
- ; behind a NAT).
-;defaultip=192.168.0.4 ; IP address to use until registration
-;username=goran ; Username to use when calling this device before registration
- ; Normally you do NOT need to set this parameter
-;setvar=CUSTID=5678 ; Channel variable to be set for all calls from this device
-
diff --git a/1.2-netsec/configs/sip_notify.conf.sample b/1.2-netsec/configs/sip_notify.conf.sample
deleted file mode 100644
index 8b10da555..000000000
--- a/1.2-netsec/configs/sip_notify.conf.sample
+++ /dev/null
@@ -1,22 +0,0 @@
-[polycom-check-cfg]
-Event=>check-sync
-Content-Length=>0
-
-; Untested
-[sipura-check-cfg]
-Event=>resync
-Content-Length=>0
-
-; Untested
-[grandstream-check-cfg]
-Event=>sys-control
-
-; Untested
-[cisco-check-cfg]
-Event=>check-sync
-Content-Length=>0
-
-; Untested - from Snom docs
-[reboot-snom]
-Event=>reboot
-Content-Length=>0
diff --git a/1.2-netsec/configs/skinny.conf.sample b/1.2-netsec/configs/skinny.conf.sample
deleted file mode 100644
index d57923d85..000000000
--- a/1.2-netsec/configs/skinny.conf.sample
+++ /dev/null
@@ -1,55 +0,0 @@
-;
-; Skinny Configuration for Asterisk
-;
-[general]
-port = 2000 ; Port to bind to, default tcp/2000
-bindaddr = 0.0.0.0 ; Address to bind to
-dateFormat = M-D-Y ; M,D,Y in any order (5 chars max)
-keepAlive = 120
-
-; allow = all
-; disallow =
-
-
-; Typical config for 12SP+
-;[florian]
-;device=SEP00D0BA847E6B
-;model=12SP ; Specific model of device, for button templates
- ; Valid models: 12SP, 30VIP, 7910, 7920 (so far)
-;version=P002G204 ; Thanks critch
-;context=did
-;line => 120 ; Dial(Skinny/120@florian)
-
-
-; Typical config for a 7910
-;[duba] ; Device name
-;model=7910 ; Device model
-;device=SEP0007EB463101 ; Offical identifier
-;version=P002F202 ; Firmware version identifier
-;host=192.168.1.144 ;
-;permit=192.168.0/24 ; Optional, used for authentication
-;nat=0
-;callerid="George W. Bush" <202-456-1414>
-;mailbox=500
-;callwaiting=1
-;transfer=1
-;threewaycalling=1
-;context=default
-;line => 500 ; Dial(Skinny/500@duba)
-
-; Typical config for a 7940 / ATA
-;[support]
-;device=SEP0007EB463121
-;nat=0
-;callerid="Customer Support" <810-234-1212>
-;mailbox=100
-;context=inbound
-;linelabel="Support Line" ; Displays next to the line button on 7940's and 7960s
-;line => 100
-;callerid="John Chambers" <408-526-4000>
-;context=did
-;linelabel="John"
-;mailbox=110
-;line => 110
-
-
diff --git a/1.2-netsec/configs/telcordia-1.adsi b/1.2-netsec/configs/telcordia-1.adsi
deleted file mode 100644
index 1486aa95e..000000000
--- a/1.2-netsec/configs/telcordia-1.adsi
+++ /dev/null
@@ -1,83 +0,0 @@
-;
-; Asterisk default ADSI script
-;
-;
-; Begin with the preamble requirements
-;
-DESCRIPTION "Telcordia Demo" ; Name of vendor
-VERSION 0x02 ; Version of stuff
-;SECURITY "_AST" ; Security code
-SECURITY 0x0000 ; Security code
-FDN 0x0000000f ; Descriptor number
-
-;
-; Predefined strings
-;
-DISPLAY "talkingto" IS "Talking To" "$Call1p" WRAP
-DISPLAY "titles" IS "20th Century IQ Svc"
-DISPLAY "newcall" IS "New Call From" "$Call1p" WRAP
-DISPLAY "ringing" IS "Ringing"
-
-;
-; Begin state definitions
-;
-STATE "callup" ; Call is currently up
-STATE "inactive" ; No active call
-
-;
-; Begin soft key definitions
-;
-KEY "CB_OH" IS "Block" OR "Call Block"
- OFFHOOK
- VOICEMODE
- WAITDIALTONE
- SENDDTMF "*60"
- SUBSCRIPT "offHook"
-ENDKEY
-
-KEY "CB" IS "Block" OR "Call Block"
- SENDDTMF "*60"
-ENDKEY
-
-;
-; Begin main subroutine
-;
-
-SUB "main" IS
- IFEVENT NEARANSWER THEN
- CLEAR
- SHOWDISPLAY "talkingto" AT 1
- GOTO "stableCall"
- ENDIF
- IFEVENT OFFHOOK THEN
- CLEAR
- SHOWDISPLAY "titles" AT 1
- SHOWKEYS "CB"
- GOTO "offHook"
- ENDIF
- IFEVENT IDLE THEN
- CLEAR
- SHOWDISPLAY "titles" AT 1
- SHOWKEYS "CB_OH"
- ENDIF
- IFEVENT CALLERID THEN
- CLEAR
- SHOWDISPLAY "newcall" AT 1
- ENDIF
-ENDSUB
-
-SUB "offHook" IS
- IFEVENT FARRING THEN
- CLEAR
- SHOWDISPLAY "ringing" AT 1
- ENDIF
- IFEVENT FARANSWER THEN
- CLEAR
- SHOWDISPLAY "talkingto" AT 1
- GOTO "stableCall"
- ENDIF
-ENDSUB
-
-SUB "stableCall" IS
-
-ENDSUB
diff --git a/1.2-netsec/configs/voicemail.conf.sample b/1.2-netsec/configs/voicemail.conf.sample
deleted file mode 100644
index fa362c95d..000000000
--- a/1.2-netsec/configs/voicemail.conf.sample
+++ /dev/null
@@ -1,213 +0,0 @@
-;
-; Voicemail Configuration
-;
-
-;
-; NOTE: Asterisk has to edit this file to change a user's password. This does
-; note currently work with the "#include <file>" directive for Asterisk
-; configuration files. Do not use it with this configuration file.
-;
-
-[general]
-; Default formats for writing Voicemail
-;format=g723sf|wav49|wav
-format=wav49|gsm|wav
-;
-; WARNING:
-; If you change the list of formats that you record voicemail in
-; when you have mailboxes that contain messages, you _MUST_ absolutely
-; manually go through those mailboxes and convert/delete/add the
-; the message files so that they appear to have been stored using
-; your new format list. If you don't do this, very unpleasant
-; things may happen to your users while they are retrieving and
-; manipulating their voicemail.
-;
-; In other words: don't change the format list on a production system
-; unless you are _VERY_ sure that you know what you are doing and are
-; prepared for the consequences.
-;
-; Who the e-mail notification should appear to come from
-serveremail=asterisk
-;serveremail=asterisk@linux-support.net
-; Should the email contain the voicemail as an attachment
-attach=yes
-; Maximum number of messages per folder. If not specified, a default value
-; (100) is used. Maximum value for this option is 9999.
-;maxmsg=100
-; Maximum length of a voicemail message in seconds
-;maxmessage=180
-; Minimum length of a voicemail message in seconds for the message to be kept
-; The default is no minimum.
-;minmessage=3
-; Maximum length of greetings in seconds
-;maxgreet=60
-; How many miliseconds to skip forward/back when rew/ff in message playback
-skipms=3000
-; How many seconds of silence before we end the recording
-maxsilence=10
-; Silence threshold (what we consider silence, the lower, the more sensitive)
-silencethreshold=128
-; Max number of failed login attempts
-maxlogins=3
-; If you need to have an external program, i.e. /usr/bin/myapp called when a
-; voicemail is left, delivered, or your voicemailbox is checked, uncomment
-; this:
-;externnotify=/usr/bin/myapp
-; If you need to have an external program, i.e. /usr/bin/myapp called when a
-; voicemail password is changed, uncomment this:
-;externpass=/usr/bin/myapp
-; For the directory, you can override the intro file if you want
-;directoryintro=dir-intro
-; The character set for voicemail messages can be specified here
-;charset=ISO-8859-1
-; The ADSI feature descriptor number to download to
-;adsifdn=0000000F
-; The ADSI security lock code
-;adsisec=9BDBF7AC
-; The ADSI voicemail application version number.
-;adsiver=1
-; Skip the "[PBX]:" string from the message title
-;pbxskip=yes
-; Change the From: string
-;fromstring=The Asterisk PBX
-; Permit finding entries for forward/compose from the directory
-;usedirectory=yes
-;
-; Change the from, body and/or subject, variables:
-; VM_NAME, VM_DUR, VM_MSGNUM, VM_MAILBOX, VM_CALLERID, VM_CIDNUM,
-; VM_CIDNAME, VM_DATE
-;
-; Note: The emailbody config row can only be up to 512 characters due to a
-; limitation in the Asterisk configuration subsystem.
-;emailsubject=[PBX]: New message ${VM_MSGNUM} in mailbox ${VM_MAILBOX}
-; The following definition is very close to the default, but the default shows
-; just the CIDNAME, if it is not null, otherise just the CIDNUM, or "an unknown
-; caller", if they are both null.
-;emailbody=Dear ${VM_NAME}:\n\n\tjust wanted to let you know you were just left a ${VM_DUR} long message (number ${VM_MSGNUM})\nin mailbox ${VM_MAILBOX} from ${VM_CALLERID}, on ${VM_DATE}, so you might\nwant to check it when you get a chance. Thanks!\n\n\t\t\t\t--Asterisk\n
-;
-; You can also change the Pager From: string, the pager body and/or subject.
-; The above defined variables also can be used here
-;pagerfromstring=The Asterisk PBX
-;pagersubject=New VM
-;pagerbody=New ${VM_DUR} long msg in box ${VM_MAILBOX}\nfrom ${VM_CALLERID}, on ${VM_DATE}
-;
-; Set the date format on outgoing mails. Valid arguments can be found on the
-; strftime(3) man page
-;
-; Default
-emaildateformat=%A, %B %d, %Y at %r
-; 24h date format
-;emaildateformat=%A, %d %B %Y at %H:%M:%S
-;
-; You can override the default program to send e-mail if you wish, too
-;
-;mailcmd=/usr/sbin/sendmail -t
-;
-; Users may be located in different timezones, or may have different
-; message announcements for their introductory message when they enter
-; the voicemail system. Set the message and the timezone each user
-; hears here. Set the user into one of these zones with the tz= attribute
-; in the options field of the mailbox. Of course, language substitution
-; still applies here so you may have several directory trees that have
-; alternate language choices.
-;
-; Look in /usr/share/zoneinfo/ for names of timezones.
-; Look at the manual page for strftime for a quick tutorial on how the
-; variable substitution is done on the values below.
-;
-; Supported values:
-; 'filename' filename of a soundfile (single ticks around the filename
-; required)
-; ${VAR} variable substitution
-; A or a Day of week (Saturday, Sunday, ...)
-; B or b or h Month name (January, February, ...)
-; d or e numeric day of month (first, second, ..., thirty-first)
-; Y Year
-; I or l Hour, 12 hour clock
-; H Hour, 24 hour clock (single digit hours preceded by "oh")
-; k Hour, 24 hour clock (single digit hours NOT preceded by "oh")
-; M Minute, with 00 pronounced as "o'clock"
-; N Minute, with 00 pronounced as "hundred" (US military time)
-; P or p AM or PM
-; Q "today", "yesterday" or ABdY
-; (*note: not standard strftime value)
-; q "" (for today), "yesterday", weekday, or ABdY
-; (*note: not standard strftime value)
-; R 24 hour time, including minute
-;
-;
-
-;
-; Each mailbox is listed in the form <mailbox>=<password>,<name>,<email>,<pager_email>,<options>
-; if the e-mail is specified, a message will be sent when a message is
-; received, to the given mailbox. If pager is specified, a message will be
-; sent there as well. If the password is prefixed by '-', then it is
-; considered to be unchangable.
-;
-; Advanced options example is extension 4069
-; NOTE: All options can be expressed globally in the general section, and
-; overriden in the per-mailbox settings, unless listed otherwise.
-;
-; tz=central ; Timezone from zonemessages above. Irrelevant if envelope=no.
-; attach=yes ; Attach the voicemail to the notification email *NOT* the pager email
-; saycid=yes ; Say the caller id information before the message. If not described,
- ; or set to no, it will be in the envelope
-; cidinternalcontexts=intern ; Internal Context for Name Playback instead of extension digits when saying caller id.
-; sayduration=no ; Turn on/off the duration information before the message. [ON by default]
-; saydurationm=2 ; Specify the minimum duration to say. Default is 2 minutes
-; dialout=fromvm ; Context to dial out from [option 4 from the advanced menu]
- ; if not listed, dialing out will not be permitted
-sendvoicemail=yes ; Context to Send voicemail from [option 5 from the advanced menu]
- ; if not listed, sending messages from inside voicemail will not be
- ; permitted
-; searchcontexts=yes ; Current default behavior is to search only the default context
- ; if one is not specified. The older behavior was to search all contexts.
- ; This option restores the old behavior [DEFAULT=no]
-; callback=fromvm ; Context to call back from
- ; if not listed, calling the sender back will not be permitted
-; review=yes ; Allow sender to review/rerecord their message before saving it [OFF by default
-; operator=yes ; Allow sender to hit 0 before/after/during leaving a voicemail to
- ; reach an operator [OFF by default]
-; envelope=no ; Turn on/off envelope playback before message playback. [ON by default]
- ; This does NOT affect option 3,3 from the advanced options menu
-; delete=yes ; After notification, the voicemail is deleted from the server. [per-mailbox only]
- ; This is intended for use with users who wish to receive their voicemail ONLY by email.
- ; Note: deletevoicemail is provided as an equivalent option for Realtime configuration.
-; nextaftercmd=yes ; Skips to the next message after hitting 7 or 9 to delete/save current message.
- ; [global option only at this time]
-; forcename=yes ; Forces a new user to record their name. A new user is
- ; determined by the password being the same as
- ; the mailbox number. The default is "no".
-; forcegreetings=no ; This is the same as forcename, except for recording
- ; greetings. The default is "no".
-; hidefromdir=yes ; Hide this mailbox from the directory produced by app_directory
- ; The default is "no".
-
-[zonemessages]
-eastern=America/New_York|'vm-received' Q 'digits/at' IMp
-central=America/Chicago|'vm-received' Q 'digits/at' IMp
-central24=America/Chicago|'vm-received' q 'digits/at' H N 'hours'
-military=Zulu|'vm-received' q 'digits/at' H N 'hours' 'phonetic/z_p'
-
-[default]
-; Define maximum number of messages per folder for partcular context.
-;maxmsg=50
-
-1234 => 4242,Example Mailbox,root@localhost
-;4200 => 9855,Mark Spencer,markster@linux-support.net,mypager@digium.com,attach=no|serveremail=myaddy@digium.com|tz=central|maxmsg=10
-;4300 => 3456,Ben Rigas,ben@american-computer.net
-;4310 => -5432,Sales,sales@marko.net
-;4069 => 6522,Matt Brooks,matt@marko.net,,|tz=central|attach=yes|saycid=yes|dialout=fromvm|callback=fromvm|review=yes|operator=yes|envelope=yes|sayduration=yes|saydurationm=1
-;4073 => 1099,Bianca Paige,bianca@biancapaige.com,,delete=1
-;4110 => 3443,Rob Flynn,rflynn@blueridge.net
-
-
-;
-; Mailboxes may be organized into multiple contexts for
-; voicemail virtualhosting
-;
-
-[other]
-;The intro can be customized on a per-context basis
-;directoryintro=dir-company2
-1234 => 5678,Company2 User,root@localhost
diff --git a/1.2-netsec/configs/vpb.conf.sample b/1.2-netsec/configs/vpb.conf.sample
deleted file mode 100644
index d16283802..000000000
--- a/1.2-netsec/configs/vpb.conf.sample
+++ /dev/null
@@ -1,108 +0,0 @@
-;
-; V6PCI/V12PCI config file for VoiceTronix Hardware
-;
-; Options for [general] section
-;
-; type = v12pci|v6pci|v4pci
-; cards = number of cards
-; To use Asterisk indication tones
-; indication = 1
-; none,-24db,-18db only for use with OpenLine4
-; ecsuppthres = 0|2048|4096
-; Inter Digit Delay timeout for when collecting DTMF tones for dialling
-; from a Station port, in ms
-; dtmfidd = 3000
-; To use Asterisk DTMF detection
-; ast-dtmf-det=1
-; Used with ast-dtmf-det
-; relaxdtmf=1
-; When a native bridge occurs between 2 vpb channels, it will only break
-; the connection for '#' and '*'
-; break-for-dtmf=no
-; Set the maximum period between received rings, default 4000ms
-; timer_period_ring=4000
-;
-; Options for [interface] section
-; board = board_number (1, 2, 3, ...)
-; channel = channel_number (1,2,3...)
-; mode = fxo|immediate|dialtone -- for type of line and line handling
-; context = starting context
-; echocancel = on|off (on by default of v4pci, off by default for others)
-; callerid = on|off|v23|bell (on => to collect caller ID if available between 1st/2nd rings using vpb functions)
-; (v23|bell => collect caller ID using asterisk functions)
-; Or for use with FXS channels a '"name" <location>' format can be used to set the channels CID
-;
-; UseLoopDrop = 0|1 (enables the use of Loop Drop detection, on by default in
-; some cases spurious loop-drops can cause unexpected
-; hangup detection)
-;
-; Gain settings
-; txgain => Transmit Software Gain (-12 => 12)
-; rxgain => Receive Software Gain (-12 => 12)
-; txhwgain => Transmit hardware gain (-12 => 12)
-; rxhwgain => Receive Hardware gain (-12 => 12)
-;
-; These are advanced settings and only mentioned for fullnes.
-; bal1 => Hybrid balance codec register 1
-; bal2 => Hybrid balance codec register 2
-; bal3 => Hybrid balance codec register 3
-;
-; Dial translations - if you want a pause or hook-flash in your dial string
-; you can use "w" for pause (wait) or "f" for "hook-flash", eg:
-; exten => _9XXX,1,Dial(vpb/g1/ww${EXTEN:${TRUNKMSD}})
-;
-;
-
-[general]
-type = v12pci
-;type = v6pci
-;type = v4pci
-cards = 1
-
-[interfaces]
-
-board = 1
-echocancel = on
-
-
-; For OpenLine4 cards
-;context = demo
-;mode = fxo
-;channel = 1
-;channel = 2
-;channel = 3
-;channel = 4
-
-; For OpenSwith12 with jumpers at factory default
-context = demo
-mode = fxo
-channel = 9
-channel = 10
-channel = 11
-channel = 12
-
-context = local
-mode = dialtone
-channel = 1
-channel = 2
-channel = 3
-channel = 4
-channel = 5
-channel = 6
-channel = 7
-channel = 8
-;
-; For OpenSwitch6
-; Note that V6PCI channel numbers start at 7!
-;context = demo
-;mode = fxo
-;channel = 7
-;channel = 8
-
-;mode = dialtone
-;channel = 9
-;channel = 10
-;channel = 11
-;channel = 12
-
-
diff --git a/1.2-netsec/configs/zapata.conf.sample b/1.2-netsec/configs/zapata.conf.sample
deleted file mode 100644
index 06aa48283..000000000
--- a/1.2-netsec/configs/zapata.conf.sample
+++ /dev/null
@@ -1,569 +0,0 @@
-;
-; Zapata telephony interface
-;
-; Configuration file
-;
-; You need to restart Asterisk to re-configure the Zap channel
-; CLI> reload chan_zap.so
-; will reload the configuration file,
-; but not all configuration options are
-; re-configured during a reload.
-
-
-
-[trunkgroups]
-;
-; Trunk groups are used for NFAS or GR-303 connections.
-;
-; Group: Defines a trunk group.
-; group => <trunkgroup>,<dchannel>[,<backup1>...]
-;
-; trunkgroup is the numerical trunk group to create
-; dchannel is the zap channel which will have the
-; d-channel for the trunk.
-; backup1 is an optional list of backup d-channels.
-;
-;trunkgroup => 1,24,48
-;trunkgroup => 1,24
-;
-; Spanmap: Associates a span with a trunk group
-; spanmap => <zapspan>,<trunkgroup>[,<logicalspan>]
-;
-; zapspan is the zap span number to associate
-; trunkgroup is the trunkgroup (specified above) for the mapping
-; logicalspan is the logical span number within the trunk group to use.
-; if unspecified, no logical span number is used.
-;
-;spanmap => 1,1,1
-;spanmap => 2,1,2
-;spanmap => 3,1,3
-;spanmap => 4,1,4
-
-[channels]
-;
-; Default language
-;
-;language=en
-;
-; Default context
-;
-context=default
-;
-; Switchtype: Only used for PRI.
-;
-; national: National ISDN 2 (default)
-; dms100: Nortel DMS100
-; 4ess: AT&T 4ESS
-; 5ess: Lucent 5ESS
-; euroisdn: EuroISDN
-; ni1: Old National ISDN 1
-; qsig: Q.SIG
-;
-switchtype=national
-;
-; Some switches (AT&T especially) require network specific facility IE
-; supported values are currently 'none', 'sdn', 'megacom', 'accunet'
-;
-;nsf=none
-;
-; PRI Dialplan: Only RARELY used for PRI.
-;
-; unknown: Unknown
-; private: Private ISDN
-; local: Local ISDN
-; national: National ISDN
-; international: International ISDN
-;
-;pridialplan=national
-;
-; PRI Local Dialplan: Only RARELY used for PRI (sets the calling number's numbering plan)
-;
-; unknown: Unknown
-; private: Private ISDN
-; local: Local ISDN
-; national: National ISDN
-; international: International ISDN
-;
-;prilocaldialplan=national
-;
-; PRI callerid prefixes based on the given TON/NPI (dialplan)
-; This is especially needed for euroisdn E1-PRIs
-;
-; sample 1 for Germany
-;internationalprefix = 00
-;nationalprefix = 0
-;localprefix = 0711
-;privateprefix = 07115678
-;unknownprefix =
-;
-; sample 2 for Germany
-;internationalprefix = +
-;nationalprefix = +49
-;localprefix = +49711
-;privateprefix = +497115678
-;unknownprefix =
-;
-; PRI resetinterval: sets the time in seconds between restart of unused
-; channels, defaults to 3600; minimum 60 seconds. Some PBXs don't like
-; channel restarts. so set the interval to a very long interval e.g. 100000000
-; or 'never' to disable *entirely*.
-;
-;resetinterval = 3600
-;
-; Overlap dialing mode (sending overlap digits)
-;
-;overlapdial=yes
-;
-; PRI Out of band indications.
-; Enable this to report Busy and Congestion on a PRI using out-of-band
-; notification. Inband indication, as used by Asterisk doesn't seem to work
-; with all telcos.
-;
-; outofband: Signal Busy/Congestion out of band with RELEASE/DISCONNECT
-; inband: Signal Busy/Congestion using in-band tones
-;
-; priindication = outofband
-;
-; If you need to override the existing channels selection routine and force all
-; PRI channels to be marked as exclusively selected, set this to yes.
-; priexclusive = yes
-;
-; ISDN Timers
-; All of the ISDN timers and counters that are used are configurable. Specify
-; the timer name, and its value (in ms for timers).
-;
-; pritimer => t200,1000
-; pritimer => t313,4000
-;
-; To enable transmission of facility-based ISDN supplementary services (such
-; as caller name from CPE over facility), enable this option.
-; facilityenable = yes
-;
-;
-; Signalling method (default is fxs). Valid values:
-; em: E & M
-; em_w: E & M Wink
-; featd: Feature Group D (The fake, Adtran style, DTMF)
-; featdmf: Feature Group D (The real thing, MF (domestic, US))
-; featdmf_ta: Feature Group D (The real thing, MF (domestic, US)) through
-; a Tandem Access point
-; featb: Feature Group B (MF (domestic, US))
-; fxs_ls: FXS (Loop Start)
-; fxs_gs: FXS (Ground Start)
-; fxs_ks: FXS (Kewl Start)
-; fxo_ls: FXO (Loop Start)
-; fxo_gs: FXO (Ground Start)
-; fxo_ks: FXO (Kewl Start)
-; pri_cpe: PRI signalling, CPE side
-; pri_net: PRI signalling, Network side
-; gr303fxoks_net: GR-303 Signalling, FXO Loopstart, Network side
-; gr303fxsks_cpe: GR-303 Signalling, FXS Loopstart, CPE side
-; sf: SF (Inband Tone) Signalling
-; sf_w: SF Wink
-; sf_featd: SF Feature Group D (The fake, Adtran style, DTMF)
-; sf_featdmf: SF Feature Group D (The real thing, MF (domestic, US))
-; sf_featb: SF Feature Group B (MF (domestic, US))
-; e911: E911 (MF) style signalling
-;
-; The following are used for Radio interfaces:
-; fxs_rx: Receive audio/COR on an FXS kewlstart interface (FXO at the
-; channel bank)
-; fxs_tx: Transmit audio/PTT on an FXS loopstart interface (FXO at the
-; channel bank)
-; fxo_rx: Receive audio/COR on an FXO loopstart interface (FXS at the
-; channel bank)
-; fxo_tx: Transmit audio/PTT on an FXO groundstart interface (FXS at
-; the channel bank)
-; em_rx: Receive audio/COR on an E&M interface (1-way)
-; em_tx: Transmit audio/PTT on an E&M interface (1-way)
-; em_txrx: Receive audio/COR AND Transmit audio/PTT on an E&M interface
-; (2-way)
-; em_rxtx: Same as em_txrx (for our dyslexic friends)
-; sf_rx: Receive audio/COR on an SF interface (1-way)
-; sf_tx: Transmit audio/PTT on an SF interface (1-way)
-; sf_txrx: Receive audio/COR AND Transmit audio/PTT on an SF interface
-; (2-way)
-; sf_rxtx: Same as sf_txrx (for our dyslexic friends)
-;
-signalling=fxo_ls
-;
-; For Feature Group D Tandem access, to set the default CIC and OZZ use these
-; parameters:
-;defaultozz=0000
-;defaultcic=303
-;
-; A variety of timing parameters can be specified as well
-; Including:
-; prewink: Pre-wink time (default 50ms)
-; preflash: Pre-flash time (default 50ms)
-; wink: Wink time (default 150ms)
-; flash: Flash time (default 750ms)
-; start: Start time (default 1500ms)
-; rxwink: Receiver wink time (default 300ms)
-; rxflash: Receiver flashtime (default 1250ms)
-; debounce: Debounce timing (default 600ms)
-;
-rxwink=300 ; Atlas seems to use long (250ms) winks
-;
-; How long generated tones (DTMF and MF) will be played on the channel
-; (in miliseconds)
-;toneduration=100
-;
-; Whether or not to do distinctive ring detection on FXO lines
-;
-;usedistinctiveringdetection=yes
-
-;
-; Whether or not to use caller ID
-;
-usecallerid=yes
-;
-; Type of caller ID signalling in use
-; bell = bell202 as used in US
-; v23 = v23 as used in the UK
-; dtmf = DTMF as used in Denmark, Sweden and Netherlands
-;
-;cidsignalling=bell
-;
-; What signals the start of caller ID
-; ring = a ring signals the start
-; polarity = polarity reversal signals the start
-;
-;cidstart=ring
-;
-; Whether or not to hide outgoing caller ID (Override with *67 or *82)
-;
-hidecallerid=no
-;
-; Whether or not to enable call waiting on FXO lines
-;
-callwaiting=yes
-;
-; Whether or not restrict outgoing caller ID (will be sent as ANI only, not
-; available for the user)
-; Mostly use with FXS ports
-;
-;restrictcid=no
-;
-; Whether or not use the caller ID presentation for the outgoing call that the
-; calling switch is sending.
-;
-usecallingpres=yes
-;
-; Some countries (UK) have ring tones with different ring tones (ring-ring),
-; which means the callerid needs to be set later on, and not just after
-; the first ring, as per the default.
-;
-;sendcalleridafter=1
-;
-;
-; Support Caller*ID on Call Waiting
-;
-callwaitingcallerid=yes
-;
-; Support three-way calling
-;
-threewaycalling=yes
-;
-; Support flash-hook call transfer (requires three way calling)
-; Also enables call parking (overrides the 'canpark' parameter)
-;
-transfer=yes
-;
-; Allow call parking
-; ('canpark=no' is overridden by 'transfer=yes')
-;
-canpark=yes
-;
-; Support call forward variable
-;
-cancallforward=yes
-;
-; Whether or not to support Call Return (*69)
-;
-callreturn=yes
-;
-; Stutter dialtone support: If a mailbox is specified without a voicemail
-; context, then when voicemail is received in a mailbox in the default
-; voicemail context in voicemail.conf, taking the phone off hook will cause a
-; stutter dialtone instead of a normal one.
-;
-; If a mailbox is specified *with* a voicemail context, the same will result
-; if voicemail recieved in mailbox in the specified voicemail context.
-;
-; for default voicemail context, the example below is fine:
-;
-;mailbox=1234
-;
-; for any other voicemail context, the following will produce the stutter tone:
-;
-;mailbox=1234@context
-;
-; Enable echo cancellation
-; Use either "yes", "no", or a power of two from 32 to 256 if you wish to
-; actually set the number of taps of cancellation.
-;
-echocancel=yes
-;
-; Generally, it is not necessary (and in fact undesirable) to echo cancel when
-; the circuit path is entirely TDM. You may, however, reverse this behavior
-; by enabling the echo cancel during pure TDM bridging below.
-;
-echocancelwhenbridged=yes
-;
-; In some cases, the echo canceller doesn't train quickly enough and there
-; is echo at the beginning of the call. Enabling echo training will cause
-; asterisk to briefly mute the channel, send an impulse, and use the impulse
-; response to pre-train the echo canceller so it can start out with a much
-; closer idea of the actual echo. Value may be "yes", "no", or a number of
-; milliseconds to delay before training (default = 400)
-;
-;echotraining=yes
-;echotraining=800
-;
-; If you are having trouble with DTMF detection, you can relax the DTMF
-; detection parameters. Relaxing them may make the DTMF detector more likely
-; to have "talkoff" where DTMF is detected when it shouldn't be.
-;
-;relaxdtmf=yes
-;
-; You may also set the default receive and transmit gains (in dB)
-;
-rxgain=0.0
-txgain=0.0
-;
-; Logical groups can be assigned to allow outgoing rollover. Groups range
-; from 0 to 63, and multiple groups can be specified.
-;
-group=1
-;
-; Ring groups (a.k.a. call groups) and pickup groups. If a phone is ringing
-; and it is a member of a group which is one of your pickup groups, then
-; you can answer it by picking up and dialing *8#. For simple offices, just
-; make these both the same
-;
-callgroup=1
-pickupgroup=1
-
-;
-; Specify whether the channel should be answered immediately or if the simple
-; switch should provide dialtone, read digits, etc.
-;
-immediate=no
-;
-; Specify whether flash-hook transfers to 'busy' channels should complete or
-; return to the caller performing the transfer (default is yes).
-;
-;transfertobusy=no
-;
-; CallerID can be set to "asreceived" or a specific number if you want to
-; override it. Note that "asreceived" only applies to trunk interfaces.
-;
-;callerid=2564286000
-;
-; AMA flags affects the recording of Call Detail Records. If specified
-; it may be 'default', 'omit', 'billing', or 'documentation'.
-;
-;amaflags=default
-;
-; Channels may be associated with an account code to ease
-; billing
-;
-;accountcode=lss0101
-;
-; ADSI (Analog Display Services Interface) can be enabled on a per-channel
-; basis if you have (or may have) ADSI compatible CPE equipment
-;
-;adsi=yes
-;
-; On trunk interfaces (FXS) and E&M interfaces (E&M, Wink, Feature Group D
-; etc, it can be useful to perform busy detection either in an effort to
-; detect hangup or for detecting busies. This enables listening for
-; the beep-beep busy pattern.
-;
-;busydetect=yes
-;
-; If busydetect is enabled, it is also possible to specify how many busy tones
-; to wait for before hanging up. The default is 4, but better results can be
-; achieved if set to 6 or even 8. Mind that the higher the number, the more
-; time that will be needed to hangup a channel, but lowers the probability
-; that you will get random hangups.
-;
-;busycount=4
-;
-; If busydetect is enabled, it is also possible to specify the cadence of your
-; busy signal. In many countries, it is 500msec on, 500msec off. Without
-; busypattern specified, we'll accept any regular sound-silence pattern that
-; repeats <busycount> times as a busy signal. If you specify busypattern,
-; then we'll further check the length of the sound (tone) and silence, which
-; will further reduce the chance of a false positive.
-;
-;busypattern=500,500
-;
-; NOTE: In the Asterisk Makefile you'll find further options to tweak the busy
-; detector. If your country has a busy tone with the same length tone and
-; silence (as many countries do), consider defining the
-; -DBUSYDETECT_COMPARE_TONE_AND_SILENCE option.
-;
-; Use a polarity reversal to mark when a outgoing call is answered by the
-; remote party.
-;
-;answeronpolarityswitch=yes
-;
-; In some countries, a polarity reversal is used to signal the disconnect of a
-; phone line. If the hanguponpolarityswitch option is selected, the call will
-; be considered "hung up" on a polarity reversal.
-;
-;hanguponpolarityswitch=yes
-;
-; On trunk interfaces (FXS) it can be useful to attempt to follow the progress
-; of a call through RINGING, BUSY, and ANSWERING. If turned on, call
-; progress attempts to determine answer, busy, and ringing on phone lines.
-; This feature is HIGHLY EXPERIMENTAL and can easily detect false answers,
-; so don't count on it being very accurate.
-;
-; Few zones are supported at the time of this writing, but may be selected
-; with "progzone"
-;
-; This feature can also easily detect false hangups. The symptoms of this is
-; being disconnected in the middle of a call for no reason.
-;
-;callprogress=yes
-;progzone=us
-;
-; FXO (FXS signalled) devices must have a timeout to determine whe there was a
-; hangup before the line was answered. This value can be tweaked to shorten
-; how long it takes before Zap considers a non-ringing line to have hungup.
-;
-;ringtimeout=8000
-;
-; For FXO (FXS signalled) devices, whether to use pulse dial instead of DTMF
-;
-;pulsedial=yes
-;
-; For fax detection, uncomment one of the following lines. The default is *OFF*
-;
-;faxdetect=both
-;faxdetect=incoming
-;faxdetect=outgoing
-;faxdetect=no
-;
-; Select which class of music to use for music on hold. If not specified
-; then the default will be used.
-;
-;musiconhold=default
-;
-; PRI channels can have an idle extension and a minunused number. So long as
-; at least "minunused" channels are idle, chan_zap will try to call "idledial"
-; on them, and then dump them into the PBX in the "idleext" extension (which
-; is of the form exten@context). When channels are needed the "idle" calls
-; are disconnected (so long as there are at least "minidle" calls still
-; running, of course) to make more channels available. The primary use of
-; this is to create a dynamic service, where idle channels are bundled through
-; multilink PPP, thus more efficiently utilizing combined voice/data services
-; than conventional fixed mappings/muxings.
-;
-;idledial=6999
-;idleext=6999@dialout
-;minunused=2
-;minidle=1
-;
-; Configure jitter buffers in zapata (each one is 20ms, default is 4)
-;
-;jitterbuffers=4
-;
-; You can define your own custom ring cadences here. You can define up to 8
-; pairs. If the silence is negative, it indicates where the callerid spill is
-; to be placed. Also, if you define any custom cadences, the default cadences
-; will be turned off.
-;
-; Syntax is: cadence=ring,silence[,ring,silence[...]]
-;
-; These are the default cadences:
-;
-;cadence=125,125,2000,-4000
-;cadence=250,250,500,1000,250,250,500,-4000
-;cadence=125,125,125,125,125,-4000
-;cadence=1000,500,2500,-5000
-;
-; Each channel consists of the channel number or range. It inherits the
-; parameters that were specified above its declaration.
-;
-; For GR-303, CRV's are created like channels except they must start with the
-; trunk group followed by a colon, e.g.:
-;
-; crv => 1:1
-; crv => 2:1-2,5-8
-;
-;
-;callerid="Green Phone"<(256) 428-6121>
-;channel => 1
-;callerid="Black Phone"<(256) 428-6122>
-;channel => 2
-;callerid="CallerID Phone" <(256) 428-6123>
-;callerid="CallerID Phone" <(630) 372-1564>
-;callerid="CallerID Phone" <(256) 704-4666>
-;channel => 3
-;callerid="Pac Tel Phone" <(256) 428-6124>
-;channel => 4
-;callerid="Uniden Dead" <(256) 428-6125>
-;channel => 5
-;callerid="Cortelco 2500" <(256) 428-6126>
-;channel => 6
-;callerid="Main TA 750" <(256) 428-6127>
-;channel => 44
-;
-; For example, maybe we have some other channels which start out in a
-; different context and use E & M signalling instead.
-;
-;context=remote
-;sigalling=em
-;channel => 15
-;channel => 16
-
-;signalling=em_w
-;
-; All those in group 0 I'll use for outgoing calls
-;
-; Strip most significant digit (9) before sending
-;
-;stripmsd=1
-;callerid=asreceived
-;group=0
-;signalling=fxs_ls
-;channel => 45
-
-;signalling=fxo_ls
-;group=1
-;callerid="Joe Schmoe" <(256) 428-6131>
-;channel => 25
-;callerid="Megan May" <(256) 428-6132>
-;channel => 26
-;callerid="Suzy Queue" <(256) 428-6233>
-;channel => 27
-;callerid="Larry Moe" <(256) 428-6234>
-;channel => 28
-;
-; Sample PRI (CPE) config: Specify the switchtype, the signalling as either
-; pri_cpe or pri_net for CPE or Network termination, and generally you will
-; want to create a single "group" for all channels of the PRI.
-;
-; switchtype = national
-; signalling = pri_cpe
-; group = 2
-; channel => 1-23
-
-;
-
-; Used for distintive ring support for x100p.
-; You can see the dringX patterns is to set any one of the dringXcontext fields
-; and they will be printed on the console when an inbound call comes in.
-;
-;dring1=95,0,0
-;dring1context=internal1
-;dring2=325,95,0
-;dring2context=internal2
-; If no pattern is matched here is where we go.
-;context=default
-;channel => 1
-
diff --git a/1.2-netsec/contrib/README.festival b/1.2-netsec/contrib/README.festival
deleted file mode 100644
index 24912827c..000000000
--- a/1.2-netsec/contrib/README.festival
+++ /dev/null
@@ -1,47 +0,0 @@
-
-app_festival is an application that allows one to send text-to-speech commands
-to a background festival server, and to obtain the resulting waveform which
-gets sent down to the respective channel. app_festival also employs a waveform
-cache, so invariant text-to-speech strings ("Please press 1 for instructions")
-do not need to be dynamically generated all the time.
-
-You need :
-
-1) festival, patched to produce 8khz waveforms on output. Patch for Festival
-1.4.2 RELEASE are included. The patch adds a new command to festival
-(asterisk_tts).
-
-It is possible to run Festival without patches in the source-code. Just
-add this to your /etc/festival.scm or /usr/share/festival/festival/scm:
-
- (define (tts_textasterisk string mode)
- "(tts_textasterisk STRING MODE)
- Apply tts to STRING. This function is specifically designed for
- use in server mode so a single function call may synthesize the string.
- This function name may be added to the server safe functions."
- (let ((wholeutt (utt.synth (eval (list 'Utterance 'Text string)))))
- (utt.wave.resample wholeutt 8000)
- (utt.wave.rescale wholeutt 5)
- (utt.send.wave.client wholeutt)))
-
-[See the comment with subject "Using Debian
- festival >= 1.4.3-15 (no recompiling needed!)" on
- http://www.voip-info.org/wiki-Asterisk+festival+installation for the
- original mentioning of it]
-
-2) You may wish to obtain and install the asterisk-perl
-module by James Golovich <james@gnuinter.net>, from
-either CPAN, or his site: http://asterisk.gnuinter.net,
-as this contains a good example of how variable text
-can be tts'd via asterisk, namely the examples/tts-*.agi
-files there. It has been noted that the current expression
-evaluation capabilities of asterisk are not best suited
-for the generation and manipulation of text. AGI scripting
-can be ideal for these sorts of needs. For simpler usage,
-fixed, pre-recorded messages may be more amenable for your
-purposes.
-
-3) Before running asterisk, you have to run festival-server with a command
-like :
-
-/usr/local/festival/bin/festival --server > /dev/null 2>&1 &
diff --git a/1.2-netsec/contrib/asterisk-doxygen-header b/1.2-netsec/contrib/asterisk-doxygen-header
deleted file mode 100644
index a8eebd6c3..000000000
--- a/1.2-netsec/contrib/asterisk-doxygen-header
+++ /dev/null
@@ -1,10 +0,0 @@
-<HTML>
- <HEAD>
- <TITLE>Asterisk.org: Developer Documentation ($date)</TITLE>
- <LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
- </HEAD>
- <BODY BGCOLOR="#FFFFFF">
-<div><font size="2" align="right">$datetime</font></div>
-
-<h2>Asterisk developer's documentation</h2>
-<hr/>
diff --git a/1.2-netsec/contrib/asterisk-ices.xml b/1.2-netsec/contrib/asterisk-ices.xml
deleted file mode 100644
index abc028c75..000000000
--- a/1.2-netsec/contrib/asterisk-ices.xml
+++ /dev/null
@@ -1,93 +0,0 @@
-<?xml version="1.0"?>
-<ices>
-
- <!-- run in background -->
- <background>0</background>
- <!-- where logs go. -->
- <logpath>/var/log/ices</logpath>
- <logfile>ices.log</logfile>
- <!-- 1=error, 2=warn, 3=infoa ,4=debug -->
- <loglevel>4</loglevel>
- <!-- logfile is ignored if this is set to 1 -->
- <consolelog>0</consolelog>
-
- <!-- optional filename to write process id to -->
- <!-- <pidfile>/home/ices/ices.pid</pidfile> -->
-
- <stream>
- <!-- metadata used for stream listing -->
- <metadata>
- <name>Example stream name</name>
- <genre>Example genre</genre>
- <description>A short description of your stream</description>
- <url>http://mysite.org</url>
- </metadata>
-
- <!-- Input module.
-
- This example uses the 'oss' module. It takes input from the
- OSS audio device (e.g. line-in), and processes it for live
- encoding. -->
- <input>
- <module>stdinpcm</module>
- <param name="rate">8000</param>
- <param name="channels">1</param>
- <!-- Read metadata (from stdin by default, or -->
- <!-- filename defined below (if the latter, only on SIGUSR1) -->
- <param name="metadata">1</param>
- <param name="metadatafilename">test</param>
- </input>
-
- <!-- Stream instance.
-
- You may have one or more instances here. This allows you to
- send the same input data to one or more servers (or to different
- mountpoints on the same server). Each of them can have different
- parameters. This is primarily useful for a) relaying to multiple
- independent servers, and b) encoding/reencoding to multiple
- bitrates.
-
- If one instance fails (for example, the associated server goes
- down, etc), the others will continue to function correctly.
- This example defines a single instance doing live encoding at
- low bitrate. -->
-
- <instance>
- <!-- Server details.
-
- You define hostname and port for the server here, along
- with the source password and mountpoint. -->
-
- <hostname>localhost</hostname>
- <port>8000</port>
- <password>temppass</password>
- <mount>/example.ogg</mount>
- <yp>1</yp> <!-- allow stream to be advertised on YP, default 0 -->
-
- <!-- Live encoding/reencoding:
-
- channels and samplerate currently MUST match the channels
- and samplerate given in the parameters to the oss input
- module above or the remsaple/downmix section below. -->
-
- <encode>
- <quality>0</quality>
- <samplerate>8000</samplerate>
- <channels>1</channels>
- </encode>
-
- <!-- stereo->mono downmixing, enabled by setting this to 1 -->
- <downmix>0</downmix>
-
- <!-- resampling.
-
- Set to the frequency (in Hz) you wish to resample to, -->
-
- <!-- <resample>
- <in-rate>44100</in-rate>
- <out-rate>22050</out-rate>
- </resample> -->
- </instance>
-
- </stream>
-</ices>
diff --git a/1.2-netsec/contrib/asterisk-ng-doxygen b/1.2-netsec/contrib/asterisk-ng-doxygen
deleted file mode 100644
index 8cf834d4a..000000000
--- a/1.2-netsec/contrib/asterisk-ng-doxygen
+++ /dev/null
@@ -1,1228 +0,0 @@
-# Doxyfile 1.4.2
-
-# This file describes the settings to be used by the documentation system
-# doxygen (www.doxygen.org) for a project
-#
-# All text after a hash (#) is considered a comment and will be ignored
-# The format is:
-# TAG = value [value, ...]
-# For lists items can also be appended using:
-# TAG += value [value, ...]
-# Values that contain spaces should be placed between quotes (" ")
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-
-# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
-# by quotes) that should identify the project.
-
-PROJECT_NAME = "Asterisk - the Open Source PBX"
-
-
-# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
-# base path where the generated documentation will be put.
-# If a relative path is entered, it will be relative to the location
-# where doxygen was started. If left blank the current directory will be used.
-
-OUTPUT_DIRECTORY = doc/api
-
-# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
-# 4096 sub-directories (in 2 levels) under the output directory of each output
-# format and will distribute the generated files over these directories.
-# Enabling this option can be useful when feeding doxygen a huge amount of
-# source files, where putting all generated files in the same directory would
-# otherwise cause performance problems for the file system.
-
-CREATE_SUBDIRS = NO
-
-# The OUTPUT_LANGUAGE tag is used to specify the language in which all
-# documentation generated by doxygen is written. Doxygen will use this
-# information to generate all constant output in the proper language.
-# The default language is English, other supported languages are:
-# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish,
-# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese,
-# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian,
-# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish,
-# Swedish, and Ukrainian.
-
-OUTPUT_LANGUAGE = English
-
-# This tag can be used to specify the encoding used in the generated output.
-# The encoding is not always determined by the language that is chosen,
-# but also whether or not the output is meant for Windows or non-Windows users.
-# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES
-# forces the Windows encoding (this is the default for the Windows binary),
-# whereas setting the tag to NO uses a Unix-style encoding (the default for
-# all platforms other than Windows).
-
-USE_WINDOWS_ENCODING = NO
-
-# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
-# include brief member descriptions after the members that are listed in
-# the file and class documentation (similar to JavaDoc).
-# Set to NO to disable this.
-
-BRIEF_MEMBER_DESC = YES
-
-# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
-# the brief description of a member or function before the detailed description.
-# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
-# brief descriptions will be completely suppressed.
-
-REPEAT_BRIEF = YES
-
-# This tag implements a quasi-intelligent brief description abbreviator
-# that is used to form the text in various listings. Each string
-# in this list, if found as the leading text of the brief description, will be
-# stripped from the text and the result after processing the whole list, is
-# used as the annotated text. Otherwise, the brief description is used as-is.
-# If left blank, the following values are used ("$name" is automatically
-# replaced with the name of the entity): "The $name class" "The $name widget"
-# "The $name file" "is" "provides" "specifies" "contains"
-# "represents" "a" "an" "the"
-
-ABBREVIATE_BRIEF =
-
-# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
-# Doxygen will generate a detailed section even if there is only a brief
-# description.
-
-ALWAYS_DETAILED_SEC = NO
-
-# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
-# inherited members of a class in the documentation of that class as if those
-# members were ordinary class members. Constructors, destructors and assignment
-# operators of the base classes will not be shown.
-
-INLINE_INHERITED_MEMB = NO
-
-# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
-# path before files name in the file list and in the header files. If set
-# to NO the shortest path that makes the file name unique will be used.
-
-FULL_PATH_NAMES = NO
-
-# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
-# can be used to strip a user-defined part of the path. Stripping is
-# only done if one of the specified strings matches the left-hand part of
-# the path. The tag can be used to show relative paths in the file list.
-# If left blank the directory from which doxygen is run is used as the
-# path to strip.
-
-STRIP_FROM_PATH =
-
-# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
-# the path mentioned in the documentation of a class, which tells
-# the reader which header file to include in order to use a class.
-# If left blank only the name of the header file containing the class
-# definition is used. Otherwise one should specify the include paths that
-# are normally passed to the compiler using the -I flag.
-
-STRIP_FROM_INC_PATH =
-
-# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
-# (but less readable) file names. This can be useful is your file systems
-# doesn't support long names like on DOS, Mac, or CD-ROM.
-
-SHORT_NAMES = NO
-
-# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
-# will interpret the first line (until the first dot) of a JavaDoc-style
-# comment as the brief description. If set to NO, the JavaDoc
-# comments will behave just like the Qt-style comments (thus requiring an
-# explicit @brief command for a brief description.
-
-JAVADOC_AUTOBRIEF = NO
-
-# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
-# treat a multi-line C++ special comment block (i.e. a block of //! or ///
-# comments) as a brief description. This used to be the default behaviour.
-# The new default is to treat a multi-line C++ comment block as a detailed
-# description. Set this tag to YES if you prefer the old behaviour instead.
-
-MULTILINE_CPP_IS_BRIEF = NO
-
-# If the DETAILS_AT_TOP tag is set to YES then Doxygen
-# will output the detailed description near the top, like JavaDoc.
-# If set to NO, the detailed description appears after the member
-# documentation.
-
-DETAILS_AT_TOP = NO
-
-# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
-# member inherits the documentation from any documented member that it
-# re-implements.
-
-INHERIT_DOCS = YES
-
-# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
-# tag is set to YES, then doxygen will reuse the documentation of the first
-# member in the group (if any) for the other members of the group. By default
-# all members of a group must be documented explicitly.
-
-DISTRIBUTE_GROUP_DOC = NO
-
-# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
-# a new page for each member. If set to NO, the documentation of a member will
-# be part of the file/class/namespace that contains it.
-
-SEPARATE_MEMBER_PAGES = NO
-
-# The TAB_SIZE tag can be used to set the number of spaces in a tab.
-# Doxygen uses this value to replace tabs by spaces in code fragments.
-
-TAB_SIZE = 3
-
-# This tag can be used to specify a number of aliases that acts
-# as commands in the documentation. An alias has the form "name=value".
-# For example adding "sideeffect=\par Side Effects:\n" will allow you to
-# put the command \sideeffect (or @sideeffect) in the documentation, which
-# will result in a user-defined paragraph with heading "Side Effects:".
-# You can put \n's in the value part of an alias to insert newlines.
-
-ALIASES =
-
-# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
-# sources only. Doxygen will then generate output that is more tailored for C.
-# For instance, some of the names that are used will be different. The list
-# of all members will be omitted, etc.
-
-OPTIMIZE_OUTPUT_FOR_C = YES
-
-# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources
-# only. Doxygen will then generate output that is more tailored for Java.
-# For instance, namespaces will be presented as packages, qualified scopes
-# will look different, etc.
-
-OPTIMIZE_OUTPUT_JAVA = NO
-
-# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
-# the same type (for instance a group of public functions) to be put as a
-# subgroup of that type (e.g. under the Public Functions section). Set it to
-# NO to prevent subgrouping. Alternatively, this can be done per class using
-# the \nosubgrouping command.
-
-SUBGROUPING = YES
-
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-
-# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
-# documentation are documented, even if no documentation was available.
-# Private class members and static file members will be hidden unless
-# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
-
-EXTRACT_ALL = YES
-
-# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
-# will be included in the documentation.
-
-EXTRACT_PRIVATE = NO
-
-# If the EXTRACT_STATIC tag is set to YES all static members of a file
-# will be included in the documentation.
-
-EXTRACT_STATIC = YES
-
-# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
-# defined locally in source files will be included in the documentation.
-# If set to NO only classes defined in header files are included.
-
-EXTRACT_LOCAL_CLASSES = YES
-
-# This flag is only useful for Objective-C code. When set to YES local
-# methods, which are defined in the implementation section but not in
-# the interface are included in the documentation.
-# If set to NO (the default) only methods in the interface are included.
-
-EXTRACT_LOCAL_METHODS = NO
-
-# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
-# undocumented members of documented classes, files or namespaces.
-# If set to NO (the default) these members will be included in the
-# various overviews, but no documentation section is generated.
-# This option has no effect if EXTRACT_ALL is enabled.
-
-HIDE_UNDOC_MEMBERS = NO
-
-# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
-# undocumented classes that are normally visible in the class hierarchy.
-# If set to NO (the default) these classes will be included in the various
-# overviews. This option has no effect if EXTRACT_ALL is enabled.
-
-HIDE_UNDOC_CLASSES = NO
-
-# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
-# friend (class|struct|union) declarations.
-# If set to NO (the default) these declarations will be included in the
-# documentation.
-
-HIDE_FRIEND_COMPOUNDS = NO
-
-# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
-# documentation blocks found inside the body of a function.
-# If set to NO (the default) these blocks will be appended to the
-# function's detailed documentation block.
-
-HIDE_IN_BODY_DOCS = NO
-
-# The INTERNAL_DOCS tag determines if documentation
-# that is typed after a \internal command is included. If the tag is set
-# to NO (the default) then the documentation will be excluded.
-# Set it to YES to include the internal documentation.
-
-INTERNAL_DOCS = NO
-
-# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
-# file names in lower-case letters. If set to YES upper-case letters are also
-# allowed. This is useful if you have classes or files whose names only differ
-# in case and if your file system supports case sensitive file names. Windows
-# and Mac users are advised to set this option to NO.
-
-CASE_SENSE_NAMES = YES
-
-# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
-# will show members with their full class and namespace scopes in the
-# documentation. If set to YES the scope will be hidden.
-
-HIDE_SCOPE_NAMES = YES
-
-# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
-# will put a list of the files that are included by a file in the documentation
-# of that file.
-
-SHOW_INCLUDE_FILES = YES
-
-# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
-# is inserted in the documentation for inline members.
-
-INLINE_INFO = YES
-
-# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
-# will sort the (detailed) documentation of file and class members
-# alphabetically by member name. If set to NO the members will appear in
-# declaration order.
-
-SORT_MEMBER_DOCS = YES
-
-# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
-# brief documentation of file, namespace and class members alphabetically
-# by member name. If set to NO (the default) the members will appear in
-# declaration order.
-
-SORT_BRIEF_DOCS = YES
-
-# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
-# sorted by fully-qualified names, including namespaces. If set to
-# NO (the default), the class list will be sorted only by class name,
-# not including the namespace part.
-# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
-# Note: This option applies only to the class list, not to the
-# alphabetical list.
-
-SORT_BY_SCOPE_NAME = NO
-
-# The GENERATE_TODOLIST tag can be used to enable (YES) or
-# disable (NO) the todo list. This list is created by putting \todo
-# commands in the documentation.
-
-GENERATE_TODOLIST = YES
-
-# The GENERATE_TESTLIST tag can be used to enable (YES) or
-# disable (NO) the test list. This list is created by putting \test
-# commands in the documentation.
-
-GENERATE_TESTLIST = YES
-
-# The GENERATE_BUGLIST tag can be used to enable (YES) or
-# disable (NO) the bug list. This list is created by putting \bug
-# commands in the documentation.
-
-GENERATE_BUGLIST = YES
-
-# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
-# disable (NO) the deprecated list. This list is created by putting
-# \deprecated commands in the documentation.
-
-GENERATE_DEPRECATEDLIST= YES
-
-# The ENABLED_SECTIONS tag can be used to enable conditional
-# documentation sections, marked by \if sectionname ... \endif.
-
-ENABLED_SECTIONS =
-
-# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
-# the initial value of a variable or define consists of for it to appear in
-# the documentation. If the initializer consists of more lines than specified
-# here it will be hidden. Use a value of 0 to hide initializers completely.
-# The appearance of the initializer of individual variables and defines in the
-# documentation can be controlled using \showinitializer or \hideinitializer
-# command in the documentation regardless of this setting.
-
-MAX_INITIALIZER_LINES = 5
-
-# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
-# at the bottom of the documentation of classes and structs. If set to YES the
-# list will mention the files that were used to generate the documentation.
-
-SHOW_USED_FILES = YES
-
-# If the sources in your project are distributed over multiple directories
-# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
-# in the documentation.
-
-SHOW_DIRECTORIES = YES
-
-# The FILE_VERSION_FILTER tag can be used to specify a program or script that
-# doxygen should invoke to get the current version for each file (typically from the
-# version control system). Doxygen will invoke the program by executing (via
-# popen()) the command <command> <input-file>, where <command> is the value of
-# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
-# provided by doxygen. Whatever the progam writes to standard output
-# is used as the file version. See the manual for examples.
-
-FILE_VERSION_FILTER =
-
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-
-# The QUIET tag can be used to turn on/off the messages that are generated
-# by doxygen. Possible values are YES and NO. If left blank NO is used.
-
-QUIET = NO
-
-# The WARNINGS tag can be used to turn on/off the warning messages that are
-# generated by doxygen. Possible values are YES and NO. If left blank
-# NO is used.
-
-WARNINGS = YES
-
-# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
-# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
-# automatically be disabled.
-
-WARN_IF_UNDOCUMENTED = YES
-
-# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
-# potential errors in the documentation, such as not documenting some
-# parameters in a documented function, or documenting parameters that
-# don't exist or using markup commands wrongly.
-
-WARN_IF_DOC_ERROR = YES
-
-# This WARN_NO_PARAMDOC option can be abled to get warnings for
-# functions that are documented, but have no documentation for their parameters
-# or return value. If set to NO (the default) doxygen will only warn about
-# wrong or incomplete parameter documentation, but not about the absence of
-# documentation.
-
-WARN_NO_PARAMDOC = NO
-
-# The WARN_FORMAT tag determines the format of the warning messages that
-# doxygen can produce. The string should contain the $file, $line, and $text
-# tags, which will be replaced by the file and line number from which the
-# warning originated and the warning text. Optionally the format may contain
-# $version, which will be replaced by the version of the file (if it could
-# be obtained via FILE_VERSION_FILTER)
-
-WARN_FORMAT =
-
-# The WARN_LOGFILE tag can be used to specify a file to which warning
-# and error messages should be written. If left blank the output is written
-# to stderr.
-
-WARN_LOGFILE =
-
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-
-# The INPUT tag can be used to specify the files and/or directories that contain
-# documented source files. You may enter file names like "myfile.cpp" or
-# directories like "/usr/src/myproject". Separate the files or directories
-# with spaces.
-
-INPUT = ./ \
- include \
- include/asterisk \
- channels \
- funcs \
- stdtime \
- apps \
- cdr \
- codecs \
- formats \
- pbx \
- res
-
-# If the value of the INPUT tag contains directories, you can use the
-# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
-# and *.h) to filter out the source-files in the directories. If left
-# blank the following patterns are tested:
-# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
-# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm
-
-FILE_PATTERNS = *.c \
- *.h
-
-# The RECURSIVE tag can be used to turn specify whether or not subdirectories
-# should be searched for input files as well. Possible values are YES and NO.
-# If left blank NO is used.
-
-RECURSIVE = NO
-
-# The EXCLUDE tag can be used to specify files and/or directories that should
-# excluded from the INPUT source files. This way you can easily exclude a
-# subdirectory from a directory tree whose root is specified with the INPUT tag.
-
-EXCLUDE =
-
-# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
-# directories that are symbolic links (a Unix filesystem feature) are excluded
-# from the input.
-
-EXCLUDE_SYMLINKS = NO
-
-# If the value of the INPUT tag contains directories, you can use the
-# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
-# certain files from those directories.
-
-EXCLUDE_PATTERNS =
-
-# The EXAMPLE_PATH tag can be used to specify one or more files or
-# directories that contain example code fragments that are included (see
-# the \include command).
-
-EXAMPLE_PATH = ./ \
- doc \
- configs
-
-# If the value of the EXAMPLE_PATH tag contains directories, you can use the
-# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
-# and *.h) to filter out the source-files in the directories. If left
-# blank all files are included.
-
-EXAMPLE_PATTERNS =
-
-# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
-# searched for input files to be used with the \include or \dontinclude
-# commands irrespective of the value of the RECURSIVE tag.
-# Possible values are YES and NO. If left blank NO is used.
-
-EXAMPLE_RECURSIVE = NO
-
-# The IMAGE_PATH tag can be used to specify one or more files or
-# directories that contain image that are included in the documentation (see
-# the \image command).
-
-IMAGE_PATH = images
-
-# The INPUT_FILTER tag can be used to specify a program that doxygen should
-# invoke to filter for each input file. Doxygen will invoke the filter program
-# by executing (via popen()) the command <filter> <input-file>, where <filter>
-# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
-# input file. Doxygen will then use the output that the filter program writes
-# to standard output. If FILTER_PATTERNS is specified, this tag will be
-# ignored.
-
-INPUT_FILTER =
-
-# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
-# basis. Doxygen will compare the file name with each pattern and apply the
-# filter if there is a match. The filters are a list of the form:
-# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
-# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER
-# is applied to all files.
-
-FILTER_PATTERNS =
-
-# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
-# INPUT_FILTER) will be used to filter the input files when producing source
-# files to browse (i.e. when SOURCE_BROWSER is set to YES).
-
-FILTER_SOURCE_FILES = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-
-# If the SOURCE_BROWSER tag is set to YES then a list of source files will
-# be generated. Documented entities will be cross-referenced with these sources.
-# Note: To get rid of all source code in the generated output, make sure also
-# VERBATIM_HEADERS is set to NO.
-
-SOURCE_BROWSER = YES
-
-# Setting the INLINE_SOURCES tag to YES will include the body
-# of functions and classes directly in the documentation.
-
-INLINE_SOURCES = YES
-
-# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
-# doxygen to hide any special comment blocks from generated source code
-# fragments. Normal C and C++ comments will always remain visible.
-
-STRIP_CODE_COMMENTS = NO
-
-# If the REFERENCED_BY_RELATION tag is set to YES (the default)
-# then for each documented function all documented
-# functions referencing it will be listed.
-
-REFERENCED_BY_RELATION = YES
-
-# If the REFERENCES_RELATION tag is set to YES (the default)
-# then for each documented function all documented entities
-# called/used by that function will be listed.
-
-REFERENCES_RELATION = YES
-
-# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
-# will generate a verbatim copy of the header file for each class for
-# which an include is specified. Set to NO to disable this.
-
-VERBATIM_HEADERS = YES
-
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-
-# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
-# of all compounds will be generated. Enable this if the project
-# contains a lot of classes, structs, unions or interfaces.
-
-ALPHABETICAL_INDEX = YES
-
-# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
-# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
-# in which this list will be split (can be a number in the range [1..20])
-
-COLS_IN_ALPHA_INDEX = 5
-
-# In case all classes in a project start with a common prefix, all
-# classes will be put under the same header in the alphabetical index.
-# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
-# should be ignored while generating the index headers.
-
-IGNORE_PREFIX =
-
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
-# generate HTML output.
-
-GENERATE_HTML = YES
-
-# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `html' will be used as the default path.
-
-HTML_OUTPUT =
-
-# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
-# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
-# doxygen will generate files with .html extension.
-
-HTML_FILE_EXTENSION = .html
-
-# The HTML_HEADER tag can be used to specify a personal HTML header for
-# each generated HTML page. If it is left blank doxygen will generate a
-# standard header.
-
-HTML_HEADER = contrib/asterisk-doxygen-header
-
-# The HTML_FOOTER tag can be used to specify a personal HTML footer for
-# each generated HTML page. If it is left blank doxygen will generate a
-# standard footer.
-
-HTML_FOOTER =
-
-# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
-# style sheet that is used by each HTML page. It can be used to
-# fine-tune the look of the HTML output. If the tag is left blank doxygen
-# will generate a default style sheet. Note that doxygen will try to copy
-# the style sheet file to the HTML output directory, so don't put your own
-# stylesheet in the HTML output directory as well, or it will be erased!
-
-HTML_STYLESHEET =
-
-# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
-# files or namespaces will be aligned in HTML using tables. If set to
-# NO a bullet list will be used.
-
-HTML_ALIGN_MEMBERS = YES
-
-# If the GENERATE_HTMLHELP tag is set to YES, additional index files
-# will be generated that can be used as input for tools like the
-# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
-# of the generated HTML documentation.
-
-GENERATE_HTMLHELP = NO
-
-# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
-# be used to specify the file name of the resulting .chm file. You
-# can add a path in front of the file if the result should not be
-# written to the html output directory.
-
-CHM_FILE =
-
-# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
-# be used to specify the location (absolute path including file name) of
-# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
-# the HTML help compiler on the generated index.hhp.
-
-HHC_LOCATION =
-
-# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
-# controls if a separate .chi index file is generated (YES) or that
-# it should be included in the master .chm file (NO).
-
-GENERATE_CHI = NO
-
-# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
-# controls whether a binary table of contents is generated (YES) or a
-# normal table of contents (NO) in the .chm file.
-
-BINARY_TOC = NO
-
-# The TOC_EXPAND flag can be set to YES to add extra items for group members
-# to the contents of the HTML help documentation and to the tree view.
-
-TOC_EXPAND = NO
-
-# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
-# top of each HTML page. The value NO (the default) enables the index and
-# the value YES disables it.
-
-DISABLE_INDEX = NO
-
-# This tag can be used to set the number of enum values (range [1..20])
-# that doxygen will group on one line in the generated HTML documentation.
-
-ENUM_VALUES_PER_LINE = 4
-
-# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be
-# generated containing a tree-like index structure (just like the one that
-# is generated for HTML Help). For this to work a browser that supports
-# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+,
-# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are
-# probably better off using the HTML help feature.
-
-GENERATE_TREEVIEW = YES
-
-# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
-# used to set the initial width (in pixels) of the frame in which the tree
-# is shown.
-
-TREEVIEW_WIDTH = 250
-
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
-# generate Latex output.
-
-GENERATE_LATEX = NO
-
-# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `latex' will be used as the default path.
-
-LATEX_OUTPUT =
-
-# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
-# invoked. If left blank `latex' will be used as the default command name.
-
-LATEX_CMD_NAME = latex
-
-# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
-# generate index for LaTeX. If left blank `makeindex' will be used as the
-# default command name.
-
-MAKEINDEX_CMD_NAME = makeindex
-
-# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
-# LaTeX documents. This may be useful for small projects and may help to
-# save some trees in general.
-
-COMPACT_LATEX = NO
-
-# The PAPER_TYPE tag can be used to set the paper type that is used
-# by the printer. Possible values are: a4, a4wide, letter, legal and
-# executive. If left blank a4wide will be used.
-
-PAPER_TYPE = a4wide
-
-# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
-# packages that should be included in the LaTeX output.
-
-EXTRA_PACKAGES =
-
-# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
-# the generated latex document. The header should contain everything until
-# the first chapter. If it is left blank doxygen will generate a
-# standard header. Notice: only use this tag if you know what you are doing!
-
-LATEX_HEADER =
-
-# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
-# is prepared for conversion to pdf (using ps2pdf). The pdf file will
-# contain links (just like the HTML output) instead of page references
-# This makes the output suitable for online browsing using a pdf viewer.
-
-PDF_HYPERLINKS = NO
-
-# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
-# plain latex in the generated Makefile. Set this option to YES to get a
-# higher quality PDF documentation.
-
-USE_PDFLATEX = NO
-
-# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
-# command to the generated LaTeX files. This will instruct LaTeX to keep
-# running if errors occur, instead of asking the user for help.
-# This option is also used when generating formulas in HTML.
-
-LATEX_BATCHMODE = NO
-
-# If LATEX_HIDE_INDICES is set to YES then doxygen will not
-# include the index chapters (such as File Index, Compound Index, etc.)
-# in the output.
-
-LATEX_HIDE_INDICES = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
-# The RTF output is optimized for Word 97 and may not look very pretty with
-# other RTF readers or editors.
-
-GENERATE_RTF = NO
-
-# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `rtf' will be used as the default path.
-
-RTF_OUTPUT =
-
-# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
-# RTF documents. This may be useful for small projects and may help to
-# save some trees in general.
-
-COMPACT_RTF = NO
-
-# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
-# will contain hyperlink fields. The RTF file will
-# contain links (just like the HTML output) instead of page references.
-# This makes the output suitable for online browsing using WORD or other
-# programs which support those fields.
-# Note: wordpad (write) and others do not support links.
-
-RTF_HYPERLINKS = NO
-
-# Load stylesheet definitions from file. Syntax is similar to doxygen's
-# config file, i.e. a series of assignments. You only have to provide
-# replacements, missing definitions are set to their default value.
-
-RTF_STYLESHEET_FILE =
-
-# Set optional variables used in the generation of an rtf document.
-# Syntax is similar to doxygen's config file.
-
-RTF_EXTENSIONS_FILE =
-
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
-# generate man pages
-
-GENERATE_MAN = NO
-
-# The MAN_OUTPUT tag is used to specify where the man pages will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `man' will be used as the default path.
-
-MAN_OUTPUT =
-
-# The MAN_EXTENSION tag determines the extension that is added to
-# the generated man pages (default is the subroutine's section .3)
-
-MAN_EXTENSION =
-
-# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
-# then it will generate one additional man file for each entity
-# documented in the real man page(s). These additional files
-# only source the real man page, but without them the man command
-# would be unable to find the correct page. The default is NO.
-
-MAN_LINKS = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_XML tag is set to YES Doxygen will
-# generate an XML file that captures the structure of
-# the code including all documentation.
-
-GENERATE_XML = NO
-
-# The XML_OUTPUT tag is used to specify where the XML pages will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `xml' will be used as the default path.
-
-XML_OUTPUT = xml
-
-# The XML_SCHEMA tag can be used to specify an XML schema,
-# which can be used by a validating XML parser to check the
-# syntax of the XML files.
-
-XML_SCHEMA =
-
-# The XML_DTD tag can be used to specify an XML DTD,
-# which can be used by a validating XML parser to check the
-# syntax of the XML files.
-
-XML_DTD =
-
-# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
-# dump the program listings (including syntax highlighting
-# and cross-referencing information) to the XML output. Note that
-# enabling this will significantly increase the size of the XML output.
-
-XML_PROGRAMLISTING = YES
-
-#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
-# generate an AutoGen Definitions (see autogen.sf.net) file
-# that captures the structure of the code including all
-# documentation. Note that this feature is still experimental
-# and incomplete at the moment.
-
-GENERATE_AUTOGEN_DEF = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_PERLMOD tag is set to YES Doxygen will
-# generate a Perl module file that captures the structure of
-# the code including all documentation. Note that this
-# feature is still experimental and incomplete at the
-# moment.
-
-GENERATE_PERLMOD = NO
-
-# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
-# the necessary Makefile rules, Perl scripts and LaTeX code to be able
-# to generate PDF and DVI output from the Perl module output.
-
-PERLMOD_LATEX = NO
-
-# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
-# nicely formatted so it can be parsed by a human reader. This is useful
-# if you want to understand what is going on. On the other hand, if this
-# tag is set to NO the size of the Perl module output will be much smaller
-# and Perl will parse it just the same.
-
-PERLMOD_PRETTY = YES
-
-# The names of the make variables in the generated doxyrules.make file
-# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
-# This is useful so different doxyrules.make files included by the same
-# Makefile don't overwrite each other's variables.
-
-PERLMOD_MAKEVAR_PREFIX =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-
-# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
-# evaluate all C-preprocessor directives found in the sources and include
-# files.
-
-ENABLE_PREPROCESSING = YES
-
-# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
-# names in the source code. If set to NO (the default) only conditional
-# compilation will be performed. Macro expansion can be done in a controlled
-# way by setting EXPAND_ONLY_PREDEF to YES.
-
-MACRO_EXPANSION = YES
-
-# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
-# then the macro expansion is limited to the macros specified with the
-# PREDEFINED and EXPAND_AS_PREDEFINED tags.
-
-EXPAND_ONLY_PREDEF = YES
-
-# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
-# in the INCLUDE_PATH (see below) will be search if a #include is found.
-
-SEARCH_INCLUDES = YES
-
-# The INCLUDE_PATH tag can be used to specify one or more directories that
-# contain include files that are not input files but should be processed by
-# the preprocessor.
-
-INCLUDE_PATH =
-
-# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
-# patterns (like *.h and *.hpp) to filter out the header-files in the
-# directories. If left blank, the patterns specified with FILE_PATTERNS will
-# be used.
-
-INCLUDE_FILE_PATTERNS =
-
-# The PREDEFINED tag can be used to specify one or more macro names that
-# are defined before the preprocessor is started (similar to the -D option of
-# gcc). The argument of the tag is a list of macros of the form: name
-# or name=definition (no spaces). If the definition and the = are
-# omitted =1 is assumed. To prevent a macro definition from being
-# undefined via #undef or recursively expanded use the := operator
-# instead of the = operator.
-
-PREDEFINED = __GNUC__
-
-# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
-# this tag can be used to specify a list of macro names that should be expanded.
-# The macro definition that is found in the sources will be used.
-# Use the PREDEFINED tag if you want to use a different macro definition.
-
-EXPAND_AS_DEFINED =
-
-# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
-# doxygen's preprocessor will remove all function-like macros that are alone
-# on a line, have an all uppercase name, and do not end with a semicolon. Such
-# function macros are typically used for boiler-plate code, and will confuse
-# the parser if not removed.
-
-SKIP_FUNCTION_MACROS = YES
-
-#---------------------------------------------------------------------------
-# Configuration::additions related to external references
-#---------------------------------------------------------------------------
-
-# The TAGFILES option can be used to specify one or more tagfiles.
-# Optionally an initial location of the external documentation
-# can be added for each tagfile. The format of a tag file without
-# this location is as follows:
-# TAGFILES = file1 file2 ...
-# Adding location for the tag files is done as follows:
-# TAGFILES = file1=loc1 "file2 = loc2" ...
-# where "loc1" and "loc2" can be relative or absolute paths or
-# URLs. If a location is present for each tag, the installdox tool
-# does not have to be run to correct the links.
-# Note that each tag file must have a unique name
-# (where the name does NOT include the path)
-# If a tag file is not located in the directory in which doxygen
-# is run, you must also specify the path to the tagfile here.
-
-TAGFILES =
-
-# When a file name is specified after GENERATE_TAGFILE, doxygen will create
-# a tag file that is based on the input files it reads.
-
-GENERATE_TAGFILE =
-
-# If the ALLEXTERNALS tag is set to YES all external classes will be listed
-# in the class index. If set to NO only the inherited external classes
-# will be listed.
-
-ALLEXTERNALS = NO
-
-# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
-# in the modules index. If set to NO, only the current project's groups will
-# be listed.
-
-EXTERNAL_GROUPS = YES
-
-# The PERL_PATH should be the absolute path and name of the perl script
-# interpreter (i.e. the result of `which perl').
-
-PERL_PATH = /usr/bin/perl
-
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-
-# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
-# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
-# or super classes. Setting the tag to NO turns the diagrams off. Note that
-# this option is superseded by the HAVE_DOT option below. This is only a
-# fallback. It is recommended to install and use dot, since it yields more
-# powerful graphs.
-
-CLASS_DIAGRAMS = NO
-
-# If set to YES, the inheritance and collaboration graphs will hide
-# inheritance and usage relations if the target is undocumented
-# or is not a class.
-
-HIDE_UNDOC_RELATIONS = YES
-
-# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
-# available from the path. This tool is part of Graphviz, a graph visualization
-# toolkit from AT&T and Lucent Bell Labs. The other options in this section
-# have no effect if this option is set to NO (the default)
-
-#Created by Asterisk Makefile
-#HAVE_DOT = NO
-
-# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for each documented class showing the direct and
-# indirect inheritance relations. Setting this tag to YES will force the
-# the CLASS_DIAGRAMS tag to NO.
-
-CLASS_GRAPH = YES
-
-# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for each documented class showing the direct and
-# indirect implementation dependencies (inheritance, containment, and
-# class references variables) of the class with other documented classes.
-
-COLLABORATION_GRAPH = YES
-
-# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for groups, showing the direct groups dependencies
-
-GROUP_GRAPHS = YES
-
-# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
-# collaboration diagrams in a style similar to the OMG's Unified Modeling
-# Language.
-
-UML_LOOK = NO
-
-# If set to YES, the inheritance and collaboration graphs will show the
-# relations between templates and their instances.
-
-TEMPLATE_RELATIONS = YES
-
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
-# tags are set to YES then doxygen will generate a graph for each documented
-# file showing the direct and indirect include dependencies of the file with
-# other documented files.
-
-INCLUDE_GRAPH = YES
-
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
-# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
-# documented header file showing the documented files that directly or
-# indirectly include this file.
-
-INCLUDED_BY_GRAPH = YES
-
-# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will
-# generate a call dependency graph for every global function or class method.
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable call graphs for selected
-# functions only using the \callgraph command.
-
-CALL_GRAPH = NO
-
-# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
-# will graphical hierarchy of all classes instead of a textual one.
-
-GRAPHICAL_HIERARCHY = YES
-
-# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
-# then doxygen will show the dependencies a directory has on other directories
-# in a graphical way. The dependency relations are determined by the #include
-# relations between the files in the directories.
-
-DIRECTORY_GRAPH = YES
-
-# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
-# generated by dot. Possible values are png, jpg, or gif
-# If left blank png will be used.
-
-DOT_IMAGE_FORMAT = png
-
-# The tag DOT_PATH can be used to specify the path where the dot tool can be
-# found. If left blank, it is assumed the dot tool can be found in the path.
-
-DOT_PATH =
-
-# The DOTFILE_DIRS tag can be used to specify one or more directories that
-# contain dot files that are included in the documentation (see the
-# \dotfile command).
-
-DOTFILE_DIRS =
-
-# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width
-# (in pixels) of the graphs generated by dot. If a graph becomes larger than
-# this value, doxygen will try to truncate the graph, so that it fits within
-# the specified constraint. Beware that most browsers cannot cope with very
-# large images.
-
-MAX_DOT_GRAPH_WIDTH = 1024
-
-# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height
-# (in pixels) of the graphs generated by dot. If a graph becomes larger than
-# this value, doxygen will try to truncate the graph, so that it fits within
-# the specified constraint. Beware that most browsers cannot cope with very
-# large images.
-
-MAX_DOT_GRAPH_HEIGHT = 1024
-
-# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
-# graphs generated by dot. A depth value of 3 means that only nodes reachable
-# from the root by following a path via at most 3 edges will be shown. Nodes
-# that lay further from the root node will be omitted. Note that setting this
-# option to 1 or 2 may greatly reduce the computation time needed for large
-# code bases. Also note that a graph may be further truncated if the graph's
-# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH
-# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default),
-# the graph is not depth-constrained.
-
-MAX_DOT_GRAPH_DEPTH = 0
-
-# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
-# background. This is disabled by default, which results in a white background.
-# Warning: Depending on the platform used, enabling this option may lead to
-# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
-# read).
-
-DOT_TRANSPARENT = NO
-
-# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
-# files in one run (i.e. multiple -o and -T options on the command line). This
-# makes dot run faster, but since only newer versions of dot (>1.8.10)
-# support this, this feature is disabled by default.
-
-DOT_MULTI_TARGETS = NO
-
-# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
-# generate a legend page explaining the meaning of the various boxes and
-# arrows in the dot generated graphs.
-
-GENERATE_LEGEND = YES
-
-# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
-# remove the intermediate dot files that are used to generate
-# the various graphs.
-
-DOT_CLEANUP = YES
-
-#---------------------------------------------------------------------------
-# Configuration::additions related to the search engine
-#---------------------------------------------------------------------------
-
-# The SEARCHENGINE tag specifies whether or not a search engine should be
-# used. If set to NO the values of all tags below this one will be ignored.
-
-SEARCHENGINE = NO
diff --git a/1.2-netsec/contrib/festival-1.4.1-diff b/1.2-netsec/contrib/festival-1.4.1-diff
deleted file mode 100644
index 23702a3a1..000000000
--- a/1.2-netsec/contrib/festival-1.4.1-diff
+++ /dev/null
@@ -1,76 +0,0 @@
-diff -ruN festival/lib/tts.scm myfestival/lib/tts.scm
---- festival/lib/tts.scm Sun May 30 16:40:00 1999
-+++ myfestival/lib/tts.scm Wed Apr 17 22:29:34 2002
-@@ -200,6 +200,15 @@
- (utt.synth
- (eval (list 'Utterance 'Text string)))))
-
-+(define (tts_textasterisk string mode)
-+ "(tts_textasterisk STRING MODE)
-+Apply tts to STRING. This function is specifically designed for
-+use in server mode so a single function call may synthesize the string.
-+This function name maybe added to the server safe functions."
-+ (utt.send.wave.asterisk
-+ (utt.synth
-+ (eval (list 'Utterance 'Text string)))))
-+
- (define (tts_return_to_client)
- "(tts_return_to_client)
- This function is called by clients who wish to return waveforms of
-diff -ruN festival/src/arch/festival/wave.cc myfestival/src/arch/festival/wave.cc
---- festival/src/arch/festival/wave.cc Sat Jun 12 10:30:30 1999
-+++ myfestival/src/arch/festival/wave.cc Thu Apr 18 10:55:32 2002
-@@ -375,6 +375,38 @@
- type = "nist";
- else
- type = get_c_string(ltype);
-+
-+ w->save(tmpfile,type);
-+ write(ft_server_socket,"WV\n",3);
-+ socket_send_file(ft_server_socket,tmpfile);
-+ unlink(tmpfile);
-+
-+ return utt;
-+}
-+
-+static LISP utt_send_wave_asterisk(LISP utt)
-+{
-+ // Send the waveform to a client (must be acting as server)
-+ EST_Utterance *u = utterance(utt);
-+ EST_Wave *w;
-+ EST_String tmpfile = make_tmp_filename();
-+ LISP ltype;
-+ EST_String type;
-+
-+ w = get_utt_wave(u);
-+ if (ft_server_socket == -1)
-+ {
-+ cerr << "utt_send_wave_client: not in server mode" << endl;
-+ festival_error();
-+ }
-+
-+ ltype = ft_get_param("Wavefiletype");
-+ if (ltype == NIL)
-+ type = "nist";
-+ else
-+ type = get_c_string(ltype);
-+ w->resample(8000);
-+ w->rescale(5);
- w->save(tmpfile,type);
- write(ft_server_socket,"WV\n",3);
- socket_send_file(ft_server_socket,tmpfile);
-@@ -434,6 +466,13 @@
- "(utt.send.wave.client UTT)\n\
- Sends wave in UTT to client. If not in server mode gives an error\n\
- Note the client must be expecting to receive the waveform.");
-+
-+ init_subr_1("utt.send.wave.asterisk",utt_send_wave_asterisk,
-+ "(utt.send.wave.asterisk UTT)\n\
-+ Sends wave in UTT to client. If not in server mode gives an error\n\
-+ Note the client must be expecting to receive the waveform. The waveform\n\
-+ is rescaled and resampled according to what asterisk needs");
-+
- init_subr_2("utt.save.f0",utt_save_f0,
- "(utt.save.f0 UTT FILENAME)\n\
- Save F0 of UTT as esps track file in FILENAME.");
-
diff --git a/1.2-netsec/contrib/festival-1.4.2.diff b/1.2-netsec/contrib/festival-1.4.2.diff
deleted file mode 100644
index d5d1e5d54..000000000
--- a/1.2-netsec/contrib/festival-1.4.2.diff
+++ /dev/null
@@ -1,75 +0,0 @@
-diff -u -r festival-1.4.2/lib/tts.scm festival-1.4.2-asterisk/lib/tts.scm
---- festival-1.4.2/lib/tts.scm Wed Jan 8 09:54:14 2003
-+++ festival-1.4.2-asterisk/lib/tts.scm Tue Jan 7 08:51:44 2003
-@@ -236,6 +236,15 @@
- (utt.synth
- (eval (list 'Utterance 'Text string))))))
-
-+(define (tts_textasterisk string mode)
-+ "(tts_textasterisk STRING MODE)
-+Apply tts to STRING. This function is specifically designed for
-+use in server mode so a single function call may synthesize the string.
-+This function name may be added to the server safe functions."
-+ (utt.send.wave.asterisk
-+ (utt.synth
-+ (eval (list 'Utterance 'Text string)))))
-+
- (define (tts_return_to_client)
- "(tts_return_to_client)
- This function is called by clients who wish to return waveforms of
-diff -u -r festival-1.4.2/src/arch/festival/wave.cc festival-1.4.2-asterisk/src/arch/festival/wave.cc
---- festival-1.4.2/src/arch/festival/wave.cc Mon Jun 4 07:40:10 2001
-+++ festival-1.4.2-asterisk/src/arch/festival/wave.cc Tue Jan 7 08:53:09 2003
-@@ -377,6 +377,38 @@
- type = "nist";
- else
- type = get_c_string(ltype);
-+
-+ w->save(tmpfile,type);
-+ write(ft_server_socket,"WV\n",3);
-+ socket_send_file(ft_server_socket,tmpfile);
-+ unlink(tmpfile);
-+
-+ return utt;
-+}
-+
-+static LISP utt_send_wave_asterisk(LISP utt)
-+{
-+ // Send the waveform to a client (must be acting as server)
-+ EST_Utterance *u = utterance(utt);
-+ EST_Wave *w;
-+ EST_String tmpfile = make_tmp_filename();
-+ LISP ltype;
-+ EST_String type;
-+
-+ w = get_utt_wave(u);
-+ if (ft_server_socket == -1)
-+ {
-+ cerr << "utt_send_wave_client: not in server mode" << endl;
-+ festival_error();
-+ }
-+
-+ ltype = ft_get_param("Wavefiletype");
-+ if (ltype == NIL)
-+ type = "nist";
-+ else
-+ type = get_c_string(ltype);
-+ w->resample(8000);
-+ w->rescale(5);
- w->save(tmpfile,type);
- write(ft_server_socket,"WV\n",3);
- socket_send_file(ft_server_socket,tmpfile);
-@@ -454,6 +486,13 @@
- "(utt.send.wave.client UTT)\n\
- Sends wave in UTT to client. If not in server mode gives an error\n\
- Note the client must be expecting to receive the waveform.");
-+
-+ init_subr_1("utt.send.wave.asterisk",utt_send_wave_asterisk,
-+ "(utt.send.wave.asterisk UTT)\n\
-+ Sends wave in UTT to client. If not in server mode gives an error\n\
-+ Note the client must be expecting to receive the waveform. The waveform\n\
-+ is rescaled and resampled according to what asterisk needs");
-+
- init_subr_1("send_sexpr_to_client", send_sexpr_to_client,
- "(send_sexpr_to_client SEXPR)\n\
- Sends given sexpression to currently connected client.");
diff --git a/1.2-netsec/contrib/festival-1.4.3.diff b/1.2-netsec/contrib/festival-1.4.3.diff
deleted file mode 100644
index 13a9d92b8..000000000
--- a/1.2-netsec/contrib/festival-1.4.3.diff
+++ /dev/null
@@ -1,93 +0,0 @@
-diff -u -r festival-1.4.3/lib/tts.scm festival-1.4.3-asterisk/lib/tts.scm
---- festival-1.4.3/lib/tts.scm 2003-01-09 07:39:22.000000000 -0800
-+++ festival-1.4.3-asterisk/lib/tts.scm 2003-08-14 12:07:00.000000000 -0700
-@@ -234,6 +234,17 @@
- (utt.synth
- (eval (list 'Utterance 'Text string))))))
-
-+;; begin tts_textasterisk
-+(define (tts_textasterisk string mode)
-+ "(tts_textasterisk STRING MODE)
-+Apply tts to STRING. This function is specifically designed for
-+use in server mode so a single function call may synthesize the string.
-+This function name may be added to the server safe functions."
-+ (utt.send.wave.asterisk
-+ (utt.synth
-+ (eval (list 'Utterance 'Text string)))))
-+;; end tts_textasterisk
-+
- (define (tts_return_to_client)
- "(tts_return_to_client)
- This function is called by clients who wish to return waveforms of
-diff -u -r festival-1.4.3/src/arch/festival/wave.cc festival-1.4.3-asterisk/src/arch/festival/wave.cc
---- festival-1.4.3/src/arch/festival/wave.cc 2003-01-13 11:09:55.000000000 -0800
-+++ festival-1.4.3-asterisk/src/arch/festival/wave.cc 2003-08-14 12:10:53.000000000 -0700
-@@ -381,6 +381,7 @@
- type = "nist";
- else
- type = get_c_string(ltype);
-+
- w->save(tmpfile,type);
- #ifdef WIN32
- send(ft_server_socket,"WV\n",3,0);
-@@ -393,6 +394,44 @@
- return utt;
- }
-
-+// begin utt_send_wave_asterisk()
-+static LISP utt_send_wave_asterisk(LISP utt)
-+{
-+ // Send the waveform to a client (must be acting as server)
-+ EST_Utterance *u = utterance(utt);
-+ EST_Wave *w;
-+ EST_String tmpfile = make_tmp_filename();
-+ LISP ltype;
-+ EST_String type;
-+
-+ w = get_utt_wave(u);
-+ if (ft_server_socket == -1)
-+ {
-+ cerr << "utt_send_wave_client: not in server mode" << endl;
-+ festival_error();
-+ }
-+
-+ ltype = ft_get_param("Wavefiletype");
-+ if (ltype == NIL)
-+ type = "nist";
-+ else
-+ type = get_c_string(ltype);
-+ w->resample(8000);
-+ w->rescale(5);
-+
-+ w->save(tmpfile,type);
-+#ifdef WIN32
-+ send(ft_server_socket,"WV\n",3,0);
-+#else
-+ write(ft_server_socket,"WV\n",3);
-+#endif
-+ socket_send_file(ft_server_socket,tmpfile);
-+ unlink(tmpfile);
-+
-+ return utt;
-+}
-+// end utt_send_wave_asterisk()
-+
- static LISP send_sexpr_to_client(LISP l)
- {
- EST_String tmpfile = make_tmp_filename();
-@@ -465,6 +504,15 @@
- "(utt.send.wave.client UTT)\n\
- Sends wave in UTT to client. If not in server mode gives an error\n\
- Note the client must be expecting to receive the waveform.");
-+
-+// begin asterisk mod
-+ init_subr_1("utt.send.wave.asterisk",utt_send_wave_asterisk,
-+ "(utt.send.wave.asterisk UTT)\n\
-+ Sends wave in UTT to client. If not in server mode gives an error\n\
-+ Note the client must be expecting to receive the waveform. The waveform\n\
-+ is rescaled and resampled according to what asterisk needs");
-+// end asterisk mod
-+
- init_subr_1("send_sexpr_to_client", send_sexpr_to_client,
- "(send_sexpr_to_client SEXPR)\n\
- Sends given sexpression to currently connected client.");
diff --git a/1.2-netsec/contrib/festival-1.95.diff b/1.2-netsec/contrib/festival-1.95.diff
deleted file mode 100644
index 2035d7f0f..000000000
--- a/1.2-netsec/contrib/festival-1.95.diff
+++ /dev/null
@@ -1,107 +0,0 @@
-diff -ur festival-195orig/festival/lib/multisyn/multisyn_pauses.scm festival-195/festival/lib/multisyn/multisyn_pauses.scm
---- festival-195orig/festival/lib/multisyn/multisyn_pauses.scm 2004-06-21 08:19:30.000000000 -0600
-+++ festival-195/festival/lib/multisyn/multisyn_pauses.scm 2005-01-12 18:53:27.000000000 -0700
-@@ -85,8 +85,8 @@
- (let ((silence (car (cadr (car (PhoneSet.description '(silences))))))
- (seg (item.relation (find_last_seg word) 'Segment))
- pause_item)
-- (format t " inserting pause after: %s.\n" (item.name seg))
-- (format t " Inserting pause\n")
-+; (format t " inserting pause after: %s.\n" (item.name seg))
-+; (format t " Inserting pause\n")
- ; if next seg is not silence insert one.
- (if (or (not (item.next seg))
- (not (string-equal (item.name (item.next seg)) silence)))
-diff -ur festival-195orig/festival/lib/tts.scm festival-195/festival/lib/tts.scm
---- festival-195orig/festival/lib/tts.scm 2003-04-20 10:42:28.000000000 -0600
-+++ festival-195/festival/lib/tts.scm 2005-01-04 09:21:31.000000000 -0700
-@@ -235,6 +235,17 @@
- (utt.synth
- (eval (list 'Utterance 'Text string))))))
-
-+;; begin tts_textasterisk
-+(define (tts_textasterisk string mode)
-+ "(tts_textasterisk STRING MODE)
-+Apply tts to STRING. This function is specifically designed for
-+use in server mode so a single function call may synthesize the string.
-+This function name may be added to the server safe functions."
-+ (utt.send.wave.asterisk
-+ (utt.synth
-+ (eval (list 'Utterance 'Text string)))))
-+;; end tts_textasterisk
-+
- (define (tts_return_to_client)
- "(tts_return_to_client)
- This function is called by clients who wish to return waveforms of
-diff -ur festival-195orig/festival/src/arch/festival/wave.cc festival-195/festival/src/arch/festival/wave.cc
---- festival-195orig/festival/src/arch/festival/wave.cc 2004-06-21 14:52:42.000000000 -0600
-+++ festival-195/festival/src/arch/festival/wave.cc 2005-01-04 09:26:24.000000000 -0700
-@@ -482,6 +482,7 @@
- type = "nist";
- else
- type = get_c_string(ltype);
-+
- w->save(tmpfile,type);
- #ifdef WIN32
- send(ft_server_socket,"WV\n",3,0);
-@@ -494,6 +495,44 @@
- return utt;
- }
-
-+// begin utt_send_wave_asterisk()
-+static LISP utt_send_wave_asterisk(LISP utt)
-+{
-+ // Send the waveform to a client (must be acting as server)
-+ EST_Utterance *u = utterance(utt);
-+ EST_Wave *w;
-+ EST_String tmpfile = make_tmp_filename();
-+ LISP ltype;
-+ EST_String type;
-+
-+ w = get_utt_wave(u);
-+ if (ft_server_socket == -1)
-+ {
-+ cerr << "utt_send_wave_asterisk: not in server mode" << endl;
-+ festival_error();
-+ }
-+
-+ ltype = ft_get_param("Wavefiletype");
-+ if (ltype == NIL)
-+ type = "nist";
-+ else
-+ type = get_c_string(ltype);
-+ w->resample(8000);
-+ w->rescale(5);
-+
-+ w->save(tmpfile,type);
-+#ifdef WIN32
-+ send(ft_server_socket,"WV\n",3,0);
-+#else
-+ write(ft_server_socket,"WV\n",3);
-+#endif
-+ socket_send_file(ft_server_socket,tmpfile);
-+ unlink(tmpfile);
-+
-+ return utt;
-+}
-+// end utt_send_wave_asterisk()
-+
- static LISP send_sexpr_to_client(LISP l)
- {
- EST_String tmpfile = make_tmp_filename();
-@@ -595,6 +634,15 @@
- "(utt.send.wave.client UTT)\n\
- Sends wave in UTT to client. If not in server mode gives an error\n\
- Note the client must be expecting to receive the waveform.");
-+
-+// begin asterisk mod
-+ init_subr_1("utt.send.wave.asterisk",utt_send_wave_asterisk,
-+ "(utt.send.wave.asterisk UTT)\n\
-+ Sends wave in UTT to client. If not in server mode gives an error\n\
-+ Note the client must be expecting to receive the waveform. The waveform\n\
-+ is rescaled and resampled according to what asterisk needs");
-+// end asterisk mod
-+
- init_subr_1("send_sexpr_to_client", send_sexpr_to_client,
- "(send_sexpr_to_client SEXPR)\n\
- Sends given sexpression to currently connected client.");
diff --git a/1.2-netsec/contrib/firmware/iax/iaxy.bin b/1.2-netsec/contrib/firmware/iax/iaxy.bin
deleted file mode 100644
index 6f06c4cdb..000000000
--- a/1.2-netsec/contrib/firmware/iax/iaxy.bin
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/contrib/i18n.testsuite.conf b/1.2-netsec/contrib/i18n.testsuite.conf
deleted file mode 100644
index 8c4d1f705..000000000
--- a/1.2-netsec/contrib/i18n.testsuite.conf
+++ /dev/null
@@ -1,136 +0,0 @@
-; Test Internationalisation of SayNumber()
-; #include this into a suitable context
-; English
-exten => 841,1,Answer
-exten => 841,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 841,3,SetLanguage(en)
-exten => 841,4,SayNumber(183) ; one hundred eighty three (NB UK English would say one hundred & eighty three)
-exten => 841,5,Wait,1
-exten => 841,6,SayUnixTime() ; Say current date & time in "ABdY 'digits/at' IMp" format
-; French
-exten => 842,1,Answer
-exten => 842,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 842,3,SetLanguage(fr)
-exten => 842,4,SayNumber(1) ; one
-exten => 842,5,Wait,1
-exten => 842,6,SayNumber(1,f) ; one (feminine)
-exten => 842,7,Wait,1
-exten => 842,8,SayNumber(181) ; hundred eighty three
-exten => 842,9,Wait,1
-exten => 842,10,SayNumber(281) ; two hundred eighty three
-exten => 842,11,Wait,1
-exten => 842,12,SayNumber(1061) ; thousand sixty three
-exten => 842,13,Wait,1
-exten => 842,14,SayNumber(2061) ; two thousand sixty three
-exten => 842,15,Wait,1
-exten => 842,16,SayUnixTime()
-; Spanish
-exten => 843,1,Answer
-exten => 843,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 843,3,SetLanguage(es)
-exten => 843,4,Playback(digits/hundred)
-exten => 843,5,Wait,1
-exten => 843,6,SayNumber(1) ; one
-exten => 843,7,Wait,1
-exten => 843,8,SayNumber(1,f) ; one (feminine)
-exten => 843,9,Wait,1
-exten => 843,10,SayNumber(11) ; "dieci uno"
-exten => 843,11,Wait,1
-exten => 843,12,SayNumber(21) ; "veinti uno"
-exten => 843,13,Wait,1
-exten => 843,14,SayNumber(31) ; "thirty & one"
-exten => 843,15,Wait,1
-exten => 843,16,SayNumber(100) ; "cien"
-exten => 843,17,Wait,1
-exten => 843,18,SayNumber(101) ; "ciento uno"
-exten => 843,19,Wait,1
-exten => 843,20,SayNumber(200) ; "twohundred"
-exten => 843,21,Wait,1
-exten => 843,22,SayNumber(1000000) ; one million
-exten => 843,23,Wait,1
-exten => 843,24,SayNumber(2000000) ; two millions
-exten => 843,25,Wait,1
-exten => 843,26,SayUnixTime()
-; Portuguese
-exten => 844,1,Answer
-exten => 844,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 844,3,SetLanguage(pt)
-exten => 844,4,SayNumber(1) ; one
-exten => 844,5,Wait,1
-exten => 844,6,SayNumber(1,f) ; one (feminine)
-exten => 844,7,Wait,1
-exten => 844,8,SayNumber(2) ; two
-exten => 844,9,Wait,1
-exten => 844,10,SayNumber(2,f) ; two (feminine)
-exten => 844,11,Wait,1
-exten => 844,12,SayNumber(183) ; hundred& eighty three
-exten => 844,13,Wait,1
-exten => 844,14,SayUnixTime()
-; Italian
-exten => 845,1,Answer
-exten => 845,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 845,3,SetLanguage(it)
-exten => 845,4,SayNumber(21) ; "twentyone"
-exten => 845,5,Wait,1
-exten => 845,6,SayNumber(183) ; hundred eighty three
-exten => 845,7,Wait,1
-exten => 845,8,SayNumber(283) ; two hundred eighty three
-exten => 845,9,SayNumber(1063) ; thousand sixty three
-exten => 845,10,Wait,1
-exten => 845,11,SayNumber(2063) ; two thousands sixty three
-exten => 845,12,Wait,1
-exten => 845,13,SayUnixTime()
-; Dutch
-exten => 846,1,Answer
-exten => 846,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 846,3,SetLanguage(nl)
-exten => 846,4,SayUnixTime(||ABdY'digits/at'R)
-exten => 846,5,Wait,1
-; Danish
-exten => 847,1,Answer
-exten => 847,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 847,3,SetLanguage(da)
-exten => 847,4,SayNumber(68) ; eight-& sixty
-exten => 847,5,Wait,1
-exten => 847,6,SayNumber(2034) ; two thousand & four-& thirty
-exten => 847,7,Wait,1
-exten => 847,8,SayNumber(1000000) ; one million
-exten => 847,9,Wait,1
-exten => 847,10,SayNumber(2000000) ; two millions
-exten => 847,11,Wait,1
-exten => 847,12,SayUnixTime()
-; German
-exten => 848,1,Answer
-exten => 848,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 848,3,SetLanguage(de)
-exten => 848,4,SayNumber(68) ; eight-& sixty
-exten => 848,5,Wait,1
-exten => 848,6,SayNumber(100) ; "hundert"
-exten => 848,7,Wait,1
-exten => 848,8,SayNumber(101) ; "einhundert-einS"
-exten => 848,9,Wait,1
-exten => 848,10,SayNumber(1000) ; "tausend"
-exten => 848,11,Wait,1
-exten => 848,12,SayNumber(1001) ; "eintausend-einS" X tausend-einS
-exten => 848,13,Wait,1
-exten => 848,14,SayNumber(2134) ; two thousand one hundred four-& thirty
-exten => 848,15,Wait,1
-exten => 848,16,SayNumber(1001000) ; one million one thousand X million tausend
-exten => 848,17,Wait,1
-exten => 848,18,SayNumber(2002000) ; two millions two thousand
-exten => 848,19,Wait,1
-exten => 848,20,SayUnixTime()
-; Swedish
-exten => 849,1,Answer
-exten => 849,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 849,3,SetLanguage(se)
-exten => 849,4,SayUnixTime()
-exten => 849,5,Wait,1
-; Temp
-exten => 850,1,Answer
-exten => 850,2,Wait,1 ; Allow VoIP sessions time to initialise
-exten => 850,3,SetLanguage(de)
-exten => 850,4,Playback(digits/1)
-exten => 850,5,Wait,1
-exten => 850,6,Playback(digits/de-eins)
-exten => 850,7,Wait,1
diff --git a/1.2-netsec/contrib/init.d/rc.debian.asterisk b/1.2-netsec/contrib/init.d/rc.debian.asterisk
deleted file mode 100755
index 16e7706fd..000000000
--- a/1.2-netsec/contrib/init.d/rc.debian.asterisk
+++ /dev/null
@@ -1,85 +0,0 @@
-#! /bin/sh
-# $Id: asterisk,v 1.3 2005/11/17 22:30:01 Gregory Boehnlein <damin@nacs.net>
-#
-# asterisk start the asterisk PBX
-#
-# Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net>
-# - Updated Version to 1.3
-# - Reversed behavior of LD_ASSUME_KERNEL=2.4.1
-# - Added detailed failure messages
-#
-# Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
-# - Updated Version to 1.2
-# - Added test for safe_asterisk
-# - Changed "stop gracefully" to "stop now"
-# - Added support for -U and -G command line options
-# - Modified "reload" to call asterisk -rx 'reload'
-
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-NAME=asterisk
-DESC="Asterisk PBX"
-# Full path to asterisk binary
-DAEMON=/usr/sbin/asterisk
-
-# Full path to safe_asterisk script
-SAFE_ASTERISK=/usr/sbin/safe_asterisk
-
-# Uncomment this ONLY if you know what you are doing.
-# export LD_ASSUME_KERNEL=2.4.1
-
-# Uncomment the following and set them to the user/groups that you
-# want to run Asterisk as. NOTE: this requires substantial work to
-# be sure that Asterisk's environment has permission to write the
-# files required for its operation, including logs, its comm
-# socket, the asterisk database, etc.
-#AST_USER="asterisk"
-#AST_GROUP="asterisk"
-
-if ! [ -x $DAEMON ] ; then
- echo "ERROR: /usr/sbin/asterisk not found"
- exit 0
-fi
-
-if ! [ -d /etc/asterisk ] ; then
- echo "ERROR: /etc/asterisk directory not found"
- exit 0
-fi
-
-set -e
-
-case "$1" in
- start)
- echo -n "Starting $DESC: "
- if [ -f $SAFE_ASTERISK ] ; then
- DAEMON=$SAFE_ASTERISK
- fi
- if [ $AST_USER ] ; then
- ASTARGS="-U $AST_USER"
- fi
- if [ $AST_GROUP ] ; then
- ASTARGS="`echo $ASTARGS` -G $AST_GROUP"
- fi
- start-stop-daemon --start --exec $DAEMON -- $ASTARGS
- echo "$NAME."
- ;;
- stop)
- echo -n "Stopping $DESC: "
- $DAEMON -rx 'stop now' > /dev/null 2> /dev/null && echo -n "$NAME"
- echo "."
- exit 0
- ;;
- reload)
- echo "Reloading $DESC configuration files."
- $DAEMON -rx 'reload' > /dev/null 2> /dev/null
- ;;
- restart|force-reload)
- $DAEMON -rx 'restart gracefully' > /dev/null 2> /dev/null && echo -n "$NAME"
- ;;
- *)
- N=/etc/init.d/$NAME
- echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
- exit 1
- ;;
-esac
-
-exit 0
diff --git a/1.2-netsec/contrib/init.d/rc.gentoo.asterisk b/1.2-netsec/contrib/init.d/rc.gentoo.asterisk
deleted file mode 100755
index ae7520066..000000000
--- a/1.2-netsec/contrib/init.d/rc.gentoo.asterisk
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/sbin/runscript
-
-depend() {
- need net logger
-}
-
-start() {
- ebegin "Starting Asterisk"
- /usr/sbin/asterisk
- eend $? "Failed to start Asterisk"
-}
-
-stop() {
- ebegin "Stopping Asterisk"
- kill $(cat /var/run/asterisk.pid)
- eend $? "Failed to stop Asterisk"
-}
diff --git a/1.2-netsec/contrib/init.d/rc.mandrake.asterisk b/1.2-netsec/contrib/init.d/rc.mandrake.asterisk
deleted file mode 100755
index 702de53dc..000000000
--- a/1.2-netsec/contrib/init.d/rc.mandrake.asterisk
+++ /dev/null
@@ -1,183 +0,0 @@
-#!/bin/sh
-#
-# asterisk: Starts the asterisk service
-#
-# Version: @(#) /etc/rc.d/init.d/asterisk 1.0
-#
-# chkconfig: 2345 95 10
-# description: Starts the asterisk service
-#
-# processname: asterisk
-#
-
-TTY=9 # TTY (if you want one) for Asterisk to run on
-CONSOLE=yes # Whether or not you want a console
-NOTIFY=root # Who to notify about crashes
-DUMPDROP=/tmp
-HOSTNAME=`hostname`
-if [ 0`readlink $0` = "0" ]; then
- CONFIGFILE=/etc/sysconfig/`basename $0`
-else
- CONFIG0=`readlink $0`
- CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
-fi
-
-# Setup environment
-cd /usr/src
-if [ -f /usr/lib/asterisk/modules/chan_h323.so -a `grep -c ^noload=chan_h323.so /etc/asterisk/modules.conf` -eq 0 ]; then
- OPENH323DIR=/usr/src/h323/openh323
- PWLIBDIR=/usr/src/h323/pwlib
-else
- OPENH323DIR=/usr/src/oh323/openh323
- PWLIBDIR=/usr/src/oh323/pwlib
-fi
-
-# Put overrides in /etc/sysconfig/asterisk
-[ -f $CONFIGFILE ] && . $CONFIGFILE
-
-LD_LIBRARY_PATH=$OPENH323DIR/lib:$PWLIBDIR/lib
-export OPENH323DIR PWLIBDIR LD_LIBRARY_PATH
-
-# Source function library.
-. /etc/rc.d/init.d/functions
-
-#
-# Don't fork when running "safely"
-#
-ASTARGS="-p"
-if [ "$TTY" != "" ]; then
- if [ -c /dev/tty${TTY} ]; then
- TTY=tty${TTY}
- elif [ -c /dev/vc/${TTY} ]; then
- TTY=vc/${TTY}
- else
- echo "Cannot find your TTY (${TTY})" >&2
- exit 1
- fi
- ASTARGS="${ASTARGS} -vvv"
- if [ "$CONSOLE" != "no" ]; then
- ASTARGS="${ASTARGS} -c"
- fi
-fi
-if [ ! -w ${DUMPDROP} ]; then
- echo "Cannot write to ${DUMPDROP}" >&2
- exit 1
-fi
-
-#
-# Let Asterisk dump core
-#
-ulimit -c unlimited
-
-#launch_asterisk()
-#{
-#}
-
-SIGMSG=("None", "Hangup" "Interrupt" "Quit" "Illegal instruction" "Trace trap" "IOT Trap" "Bus Error" "Floating-point exception" "Killed" "User-defined signal 1" "Segmentation violation" "User-defined signal 2" "Broken pipe" "Alarm clock" "Termination" "Stack fault")
-
-run_asterisk()
-{
- while :; do
-
- if [ "$TTY" != "" ]; then
- cd /tmp
- stty sane < /dev/${TTY}
- asterisk ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY}
- else
- cd /tmp
- asterisk ${ASTARGS}
- fi
- EXITSTATUS=$?
- echo "Asterisk ended with exit status $EXITSTATUS"
- if [ "$EXITSTATUS" = "0" ]; then
- # Properly shutdown....
- echo "Asterisk shutdown normally."
- exit 0
- elif [ $EXITSTATUS -gt 128 ]; then
- EXITSIGNAL=$(($EXITSTATUS - 128))
- EXITMSG=${SIGMSG[$EXITSIGNAL]}
- echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG."
- if [ "$NOTIFY" != "" ]; then
- echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG. Might want to take a peek." | \
- mail -s "Asterisk Died ($HOSTNAME)" $NOTIFY
- fi
- if [ -f /tmp/core ]; then
- mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
- fi
- else
- echo "Asterisk died with code $EXITSTATUS. Aborting."
- if [ -f /tmp/core ]; then
- mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
- fi
- exit 0
- fi
- echo "Automatically restarting Asterisk."
- done
-}
-
-case "$1" in
- start)
- gprintf "Starting asterisk: "
- run_asterisk >/dev/null 2>&1 &
- sleep 2 # Give it time to die
- succeeded=`pidof asterisk|awk '{print NF}'`
- if [ $succeeded = "0" ]; then
- failure
- else
- success
- fi
- echo
- ;;
- stop)
- gprintf "Stopping asterisk: "
- asterisk -r -x "stop gracefully" >/dev/null 2>&1
- killall -9 mpg123 2>/dev/null
- success
- echo
- ;;
- restart)
- $0 stop
- usleep 100000
- $0 start
- ;;
- reload)
- gprintf "Reloading asterisk: "
- asterisk -r -x "reload" >/dev/null 2>&1
- success
- echo
- ;;
- stopnow)
- gprintf "Stopping asterisk: "
- asterisk -r -x "stop now" >/dev/null 2>&1
- success
- echo
- ;;
- restartnow)
- $0 stopnow
- $0 start
- ;;
- fullrestart)
- $0 stop
- service zaptel restart
- $0 start
- ;;
- fullrestartnow)
- $0 stopnow
- service zaptel restart
- $0 start
- ;;
- status)
- succeeded=`pidof asterisk|awk '{print NF}'`
- if [ $succeeded = "0" ]; then
- echo "Asterisk is not running"
- else
- echo "Asterisk is currently running with $succeeded threads"
- fi
- ;;
- *)
- gprintf "*** Usage: $0 {start|stop[now]|reload|[full]restart[now]|status}\n"
- exit 1
-esac
-
-exit 0
-
diff --git a/1.2-netsec/contrib/init.d/rc.mandrake.zaptel b/1.2-netsec/contrib/init.d/rc.mandrake.zaptel
deleted file mode 100755
index c5c26000e..000000000
--- a/1.2-netsec/contrib/init.d/rc.mandrake.zaptel
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/sh
-#
-# zaptel: Loads Asterisk modules
-#
-# Version: @(#) /etc/rc.d/init.d/zaptel 1.0
-#
-# chkconfig: 2345 90 10
-# description: Loads and unloads zaptel modules at boot time and shutdown.
-#
-# hide: true
-
-# Source function library.
-. /etc/rc.d/init.d/functions
-
-# Default modules - override in /etc/sysconfig/zaptel
-######################################
-MODULES="usb-uhci zaptel wcfxo wcusb"
-######################################
-
-[ -f /etc/sysconfig/`basename $0` ] && . /etc/sysconfig/`basename $0`
-
-function probe() {
- gprintf " $1"
- modprobe -i $1
- # It has to be in the module list, otherwise something is wrong
- if lsmod | grep -c ^$1 >/dev/null; then
- success
- else
- failure
- fi
- echo
-}
-
-function unprobe() {
- gprintf " $1"
- rmmod $1 >/dev/null 2>&1
- # If it's still in the module list after removing it, there's something wrong.
- if lsmod | grep -c ^$1 >/dev/null; then
- failure
- else
- success
- fi
- echo
-}
-
-function reverse_modules() {
- tmp=$MODULES
- MODULES=''
- for i in $tmp; do
- MODULES="$i $MODULES" ;
- done
-}
-
-# See how we were called.
-case "$1" in
- start)
- gprintf "Loading Asterisk modules:\n"
- for i in $MODULES; do
- probe $i
- usleep 100000 ;
- done
- ztcfg
- ;;
- stop)
- gprintf "Unloading Asterisk modules:\n"
- reverse_modules
- for i in $MODULES; do
- unprobe $i
- usleep 100000 ;
- done
- ;;
- status)
- #ztcfg -vv
- OK=1
- gprintf "Checking Asterisk modules"
- for i in $MODULES; do
- if [ `lsmod | grep -c $i` -eq 0 ]; then
- OK=0
- fi
- done
- if [ $OK -gt 0 ]; then
- success
- else
- failure
- fi
- echo
- ;;
- restart)
- $0 stop
- $0 start
- ;;
- *)
- gprintf "*** Usage: $0 {start|stop|status|restart}\n"
- exit 1
-esac
-
-exit 0
-
diff --git a/1.2-netsec/contrib/init.d/rc.redhat.asterisk b/1.2-netsec/contrib/init.d/rc.redhat.asterisk
deleted file mode 100755
index 1ef812463..000000000
--- a/1.2-netsec/contrib/init.d/rc.redhat.asterisk
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/bin/sh
-# $Id: asterisk,v 1.3 2005/11/17 22:30:01 Gregory Boehnlein <damin@nacs.net>
-#
-# asterisk Starts, Stops and Reloads Asterisk.
-#
-# chkconfig: 2345 40 60
-# description: Asterisk PBX and telephony daemon.
-# processname: asterisk
-# pidfile: /var/run/asterisk.pid
-#
-# Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net>
-# - Updated Version to 1.3
-# - Reversed behavior of LD_ASSUME_KERNEL=2.4.1
-# - Added detailed failure messages
-#
-# Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
-# - Updated Version to 1.2
-# - Added test for safe_asterisk
-# - Verified SIGTERM issued by "killproc" ensures "stop gracefully"
-# - Added support for -U and -G command line options
-# - Modified "reload" to call asterisk -rx 'reload'
-
-# Source function library.
-. /etc/rc.d/init.d/functions
-
-if ! [ -x /usr/sbin/asterisk ] ; then
- echo "ERROR: /usr/sbin/asterisk not found"
- exit 0
-fi
-
-if ! [ -d /etc/asterisk ] ; then
- echo "ERROR: /etc/asterisk directory not found"
- exit 0
-fi
-
-# Uncomment this ONLY if you know what you are doing.
-# export LD_ASSUME_KERNEL=2.4.1
-
-# Full path to asterisk binary
-DAEMON=/usr/sbin/asterisk
-
-# Full path to safe_asterisk script
-SAFE_ASTERISK=/usr/sbin/safe_asterisk
-
-# Uncomment the following and set them to the user/groups that you
-# want to run Asterisk as. NOTE: this requires substantial work to
-# be sure that Asterisk's environment has permission to write the
-# files required for its operation, including logs, its comm
-# socket, the asterisk database, etc.
-#AST_USER="asterisk"
-#AST_GROUP="asterisk"
-
-RETVAL=0
-
-start() {
- # Start daemons.
- echo -n $"Starting asterisk: "
- if [ -f $SAFE_ASTERISK ] ; then
- DAEMON=$SAFE_ASTERISK
- fi
- if [ $AST_USER ] ; then
- ASTARGS="-U $AST_USER"
- fi
- if [ $AST_GROUP ] ; then
- ASTARGS="`echo $ASTARGS` -G $AST_GROUP"
- fi
- daemon $DAEMON $ASTARGS
- RETVAL=$?
- [ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
- echo
- return $RETVAL
-}
-
-stop() {
- # Stop daemons.
- echo -n $"Shutting down asterisk: "
- killproc asterisk
- RETVAL=$?
- [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
- echo
- return $RETVAL
-}
-
-restart() {
- stop
- start
-}
-
-reload() {
- $DAEMON -rx 'reload' > /dev/null 2> /dev/null
-}
-
-# See how we were called.
-case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- restart
- ;;
- reload)
- reload
- ;;
- condrestart)
- [ -f /var/lock/subsys/asterisk ] && restart || :
- ;;
- status)
- status asterisk
- ;;
- *)
- echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"
- exit 1
-esac
-
-exit $?
diff --git a/1.2-netsec/contrib/init.d/rc.slackware.asterisk b/1.2-netsec/contrib/init.d/rc.slackware.asterisk
deleted file mode 100755
index 676345909..000000000
--- a/1.2-netsec/contrib/init.d/rc.slackware.asterisk
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/bin/sh
-#
-# Start/stop/restart Asterisk PBX
-#
-# Version: 1.0 - Paul Belanger <pabelanger@gmail.com>
-#
-# 03.29.2005 - Initial Version
-#
-
-asterisk_start() {
- if [ -x /usr/sbin/asterisk ]; then
- echo "Starting Asterisk /usr/sbin/asterisk"
- /usr/sbin/asterisk
- fi
-}
-
-asterisk_stop() {
- # If there is no PID file, ignore this request...
- if [ -r /var/run/asterisk.pid ]; then
- killall asterisk
- fi
-}
-
-asterisk_restart() {
- asterisk_stop
- asterisk_start
-}
-
-case "$1" in
- 'start')
- asterisk_start
- ;;
- 'stop')
- asterisk_stop
- ;;
- 'restart')
- asterisk_restart
- ;;
- *)
- echo "usage $0 start|stop|restart" ;;
-esac
-
diff --git a/1.2-netsec/contrib/scripts/README.messages-expire b/1.2-netsec/contrib/scripts/README.messages-expire
deleted file mode 100644
index 12f2b0e9c..000000000
--- a/1.2-netsec/contrib/scripts/README.messages-expire
+++ /dev/null
@@ -1,20 +0,0 @@
-messages-expire.pl
-
-messages-expire finds messages more than X days old and deletes them.
-Because the older messages will be the lower numbers in the folder (msg0000
-will be older than msg0005), just deleting msg0000 will not work.
-expire-messages then runs a routine that goes into every folder in every
-mailbox to reorganize. If the folder contains msg0000, no action is taken.
-If the folder does not, the rename routine takes the oldest message and
-names it msg0000, the next oldest message and names it msg0001 and so on.
-
-The file deletion is done by the -exec parameter to 'find'. It would be far
-more efficient to take the output from 'find' and just reorganize the
-directories from which we deleted a file. Something for the future...
-
-Keep in mind that messages are deleted at the beginning of the script you
-will have mailbox trouble if you check messages before the script
-reorganizes your mailbox.
-
-To use it, make sure the paths are right. Adjust $age (originally set to
-31) if necessary.
diff --git a/1.2-netsec/contrib/scripts/agents.php b/1.2-netsec/contrib/scripts/agents.php
deleted file mode 100644
index 51f8bdee3..000000000
--- a/1.2-netsec/contrib/scripts/agents.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-ob_implicit_flush(false);
-
-$username = "drmac";
-$secret = "secret";
-
-$socket = fsockopen("127.0.0.1","5038", $errornum, $errorstr);
-
-$agents = array();
-$curr_agent = "";
-$better_status = array( 'AGENT_UNKNOWN' => 'Unknown',
- 'AGENT_IDLE' => 'Idle',
- 'AGENT_ONCALL' => 'On Call',
- 'AGENT_LOGGEDOFF' => 'Not Logged In' );
-
-if(!$socket) {
- print "Couldn't open socket. Error #" . $errornum . ": " . $errorstr;
-} else {
- fputs($socket, "Action: Login\r\n");
- fputs($socket, "UserName: $username\r\n");
- fputs($socket, "Secret: $secret\r\n\r\n");
- fputs($socket, "Action: Agents\r\n\r\n");
- fputs($socket, "Action: Logoff\r\n\r\n");
-
- while(!feof($socket)) {
- $info = fscanf($socket, "%s\t%s\r\n");
- switch($info[0]) {
- case "Agent:":
- $curr_agent = $info[1];
- $agents[$curr_agent] = array();
- break;
- case "Name:":
- $agents[$curr_agent]['Name'] = $info[1];
- break;
- case "Status:":
- $agents[$curr_agent]['Status'] = $better_status[$info[1]];
- break;
- case "LoggedInChan:":
- $agents[$curr_agent]['LoggedInChan'] = $info[1];
- break;
- case "LoggedInTime:":
- if($info[1] != "0") {
- $agents[$curr_agent]['LoggedInTime'] = date("D, M d Y g:ia", $info[1]);
- } else {
- $agents[$curr_agent]['LoggedInTime'] = "n/a";
- }
- break;
- case "TalkingTo:":
- $agents[$curr_agent]['TalkingTo'] = $info[1];
- break;
- default:
- break;
- }
- }
- fclose($socket);
-
- print "<html><head><title>Agents Status</title></head>\n<body>\n";
- print "<table width=\"800px\" border=\"1\">\n";
- print " <tr><th>Agent #</th><th>Agent Name</th><th>Agent Location</th><th>Agent Status</th><th>Agent Talking To</th><th>Agent Login Time</th></tr>\n";
-
- foreach( $agents as $agent=>$curr ) {
- print " <tr>\n <td>" . $agent . "</td>\n";
- print " <td>" . $curr['Name'] . "</td>\n";
- print " <td>" . $curr['LoggedInChan'] . "</td>\n";
- print " <td>" . $curr['Status'] . "</td>\n";
- print " <td>" . $curr['TalkingTo'] . "</td>\n";
- print " <td>" . $curr['LoggedInTime'] . "</td>\n </tr>\n";
- }
-
- print "</table>\n</body>\n</html>\n";
-}
-?>
diff --git a/1.2-netsec/contrib/scripts/ast_grab_core b/1.2-netsec/contrib/scripts/ast_grab_core
deleted file mode 100644
index 8f405ebdd..000000000
--- a/1.2-netsec/contrib/scripts/ast_grab_core
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/bin/sh
-# $Id$
-# lame quickie script to snarf a core of a hung asterisk process.
-# bugs to ast_grab_core, blinky-lights.org (derrick daugherty)
-
-DATE=`date +%Y%m%d%H%M`
-DUMPDIR=/var/tmp
-HOSTNAME=`hostname`
-ADMINEMAIL="root@localhost"
-
-#the following should be improved
-if [ -e /etc/asterisk/asterisk.conf ]; then
- RUNDIR=`awk -F"=>" '/astrundir/ {print $2}' /etc/asterisk/asterisk.conf`
- PID=`cat ${RUNDIR}/asterisk.pid`
-elif [ -e /var/run/asterisk.pid ] ; then
- PID=`cat /var/run/asterisk.pid`
-else
- echo Could not find an asterisk.conf definition for astrundir, using \'ps\'
- echo to try and determine process ID. This is not reliable.
- PID=`ps auxwf|grep asterisk|grep vv|head -1|awk '{print $2}'`
-fi
-
-echo Snarfing asterisk core, this could take a few seconds depending
-echo on how much memory is in use.
-echo
-echo \*\*\* WARNING \*\*\* If the system is not already locked this will cause the
-echo \*\*\* WARNING \*\*\* process to STOP while memory is dumped to disk.
-echo
-
-/usr/bin/gdb > /dev/null << EOF
- attach ${PID}
- gcore ${DUMPDIR}/asterisk_${DATE}.core.${PID}
- detach
- quit
-EOF
-
-echo Snarfed! ${DUMPDIR}/asterisk_${DATE}.core.${PID}
-echo
-
-
-echo Trying for a backtrace of the captured core.
-/usr/bin/gdb /usr/sbin/asterisk ${DUMPDIR}/asterisk_${DATE}.core.${PID} > /tmp/gdb_dump.${PID} 2> /dev/null << EOF
-set prompt \n
-echo --------------------------------------------------------------------------------\n
-echo INFO THREAD
-info thread
-echo --------------------------------------------------------------------------------\n
-echo THREAD APPLY ALL BT
-thread apply all bt
-echo --------------------------------------------------------------------------------\n
-echo THREAD APPLY ALL BT FULL
-thread apply all bt full
-quit
-EOF
-echo Done trying for a bt.
-
-
-echo Notifying admins of the core.
-/usr/bin/mail -s "${HOSTNAME} core dumped at ${DUMPDIR}/asterisk_${DATE}.core.${PID}" ${ADMINEMAIL} < /tmp/gdb_dump.${PID}
-/bin/rm /tmp/gdb_dump.${PID}
-echo Done.
-echo
-echo Reproducible deadlocks should be posted with a full backtrace and instructions
-echo to reproduce the issue at http://bugs.digium.com/ Thanks!
diff --git a/1.2-netsec/contrib/scripts/astgenkey b/1.2-netsec/contrib/scripts/astgenkey
deleted file mode 100644
index 637604896..000000000
--- a/1.2-netsec/contrib/scripts/astgenkey
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/bin/sh
-#
-# Usage: astgenkey [ -q ] [ -n ] [keyname]
-#
-DES3=-des3
-if [ "$1" = "-q" ]; then
- QUIET='y'
- if [ "$2" = "-n" ]; then
- DES3=
- KEY=$3
- else
- KEY=$2
- fi
-elif [ "$1" = "-n" ]; then
- DES3=
- if [ "$2" = "-q" ]; then
- QUIET='y'
- KEY=$3
- else
- KEY=$2
- fi
-else
- KEY=$1
-fi
-
-if [ "$QUIET" != 'y' ]; then
- echo ""
- echo "This script generates an RSA private and public key pair"
- echo "in PEM format for use by Asterisk. You will be asked to"
- echo "enter a passcode for your key multiple times. Please"
- echo "enter the same code each time. The resulting files will"
- echo "need to be moved to /var/lib/asterisk/keys if you want"
- echo "to use them, and any private keys (.key files) will"
- echo "need to be initialized at runtime either by running"
- echo "Asterisk with the '-i' option, or with the 'init keys'"
- echo "command once Asterisk is running."
- echo ""
- echo "Press ENTER to continue or ^C to cancel."
- read BLAH
-fi
-
-while [ "$KEY" = "" ]; do
- echo -n "Enter key name: "
- read KEY
-done
-
-rm -f ${KEY}.key ${KEY}.pub
-
-echo "Generating SSL key '$KEY': "
-openssl genrsa -out ${KEY}.key ${DES3} 1024
-openssl rsa -in ${KEY}.key -pubout -out ${KEY}.pub
-
-if [ -f "${KEY}.key" ] && [ -f "${KEY}.pub" ]; then
- if [ "$QUIET" != 'y' ]; then
- echo "Key creation successful."
- echo "Public key: ${KEY}.pub"
- echo "Private key: ${KEY}.key"
- fi
-else
- echo "Unknown error creating keys."
-fi
diff --git a/1.2-netsec/contrib/scripts/astgenkey.8 b/1.2-netsec/contrib/scripts/astgenkey.8
deleted file mode 100644
index 6dc793eb1..000000000
--- a/1.2-netsec/contrib/scripts/astgenkey.8
+++ /dev/null
@@ -1,129 +0,0 @@
-.\" $Header$
-.\"
-.\" transcript compatibility for postscript use.
-.\"
-.\" synopsis: .P! <file.ps>
-.\"
-.de P!
-.fl
-\!!1 setgray
-.fl
-\\&.\"
-.fl
-\!!0 setgray
-.fl \" force out current output buffer
-\!!save /psv exch def currentpoint translate 0 0 moveto
-\!!/showpage{}def
-.fl \" prolog
-.sy sed \-e 's/^/!/' \\$1\" bring in postscript file
-\!!psv restore
-.
-.de pF
-.ie \\*(f1 .ds f1 \\n(.f
-.el .ie \\*(f2 .ds f2 \\n(.f
-.el .ie \\*(f3 .ds f3 \\n(.f
-.el .ie \\*(f4 .ds f4 \\n(.f
-.el .tm ? font overflow
-.ft \\$1
-..
-.de fP
-.ie !\\*(f4 \{\
-. ft \\*(f4
-. ds f4\"
-' br \}
-.el .ie !\\*(f3 \{\
-. ft \\*(f3
-. ds f3\"
-' br \}
-.el .ie !\\*(f2 \{\
-. ft \\*(f2
-. ds f2\"
-' br \}
-.el .ie !\\*(f1 \{\
-. ft \\*(f1
-. ds f1\"
-' br \}
-.el .tm ? font underflow
-..
-.ds f1\"
-.ds f2\"
-.ds f3\"
-.ds f4\"
-'\" t
-.ta 8n 16n 24n 32n 40n 48n 56n 64n 72n
-.TH ASTGENKEY 8 "May 14th, 2005" "Asterisk" "Linux Programmer's Manual"
-.SH NAME
-.B astgenkey
--- generates keys for for Asterisk IAX2 RSA authentication
-.SH SYNOPSIS
-.PP
-.B astgenkey
-[ -q ] [ -n ] [ \fIkeyname\fP ]
-
-.SH DESCRIPTION
-.B genzaptelconf
-This script generates an RSA private and public key pair in PEM format
-for use by Asterisk. The private key should be kept a secret, as it can
-be used to fake your system's identity. Thus by default (without the
-option
-.I -n
-) the script will create a passphrase-encrypted copy of your secret key:
-without entering the passphrase you won't be able to use it.
-
-However if you want to use such a key with Asterisk, you'll have to start
-it interactively, because the scripts that start asterisk can't use that
-encrypted key.
-
-The key is identified by a name. If you don't write the name on the
-command-line you'll be prompted for one. The outputs of the script are:
-
-.I name\fB.pub
-.RS
-The public key: not secret. Send this to the other side.
-.RE
-
-.I name\fB.key
-.RS
-The private key: secret.
-.RE
-
-Those files should be copied to
-.I /var/lib/asterisk/keys
-
-(The private key: on your system. The public key: on other systems)
-
-To see the currently-installed keys from the asterisk CLI, use the command
-
-.RS
-show keys
-.RE
-
-.SH OPTIONS
-.B -q
-.RS
-Run quietly.
-.RE
-
-.B -n
-.RS
-Don't encrypt the private key.
-.RE
-
-.SH FILES
-.I /var/lib/asterisk/keys
-.RS
-.RE
-
-.SH "SEE ALSO"
-asterisk(8), genrsa(1), rsa(1),
-
-http://www.voip-info.org/wiki-Asterisk+iax+rsa+auth
-
-.SH "AUTHOR"
-This manual page was written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
-Permission is granted to copy, distribute and/or modify this document under
-the terms of the GNU General Public License, Version 2 any
-later version published by the Free Software Foundation.
-
-On Debian systems, the complete text of the GNU General Public
-License can be found in /usr/share/common-licenses/GPL.
diff --git a/1.2-netsec/contrib/scripts/astxs b/1.2-netsec/contrib/scripts/astxs
deleted file mode 100644
index c525537ae..000000000
--- a/1.2-netsec/contrib/scripts/astxs
+++ /dev/null
@@ -1,157 +0,0 @@
-#!/usr/bin/perl
-
-my $astdir = $ENV{ASTSRC} || "/usr/src/asterisk";
-
-
-sub esystem($) {
- my $cmd = shift;
- print "$cmd\n";
- system($cmd);
-}
-sub usage($) {
- my $str = shift;
- print "\n$str\n\n";
- print "Usage $0 [ <module.c> [-set=<varname>:<value>] [-append=<varname>:<value>] [-install] ] | [-help] \n\n";
-
- print "varnames of interest:
-===============================================================================
-'INCLUDES' 'ASTLIBDIR' 'AGI_DIR' 'ASTVARRUNDIR' 'CC' 'ASTETCDIR' 'EXTOBJ'
-'ASTSPOOLDIR' 'ASTLOGDIR' 'MODULES_DIR' 'ASTSBINDIR' 'ASTHEADERDIR' 'LDFLAGS'
-'ASTVARLIBDIR' 'ASTBINDIR' 'INSTALL_PREFIX' 'ASTCONFPATH' 'ASTSRC' 'CFLAGS'
-===============================================================================
-";
-
- exit;
-
-}
-
-
-my %avars = ();
-my %svars = ();
-my %vars = ();
-
-
-
-
-my %args = ();
-
-
-foreach(@ARGV) {
-
- if(/^\-set=([^\:]+):(.*)/) {
- $svars{$1} = $2;
- }
- elsif(/^\-append=([^\:]+):(.*)/) {
- $avars{$1} .= " $2";
- }
- elsif(/^\-([^\=]+)=(.*)/) {
- $args{$1} = $2;
- }
- elsif(/^\-([^\=]+)$/) {
- $args{$1}++;
- }
- else {
- push(@{$args{plain}},$_);
- }
-}
-
-if($args{help} or $args{h}) {
- usage "Help";
-}
-
-
-my $pwd = `/bin/pwd`;
-chomp($pwd);
-
-$vars{astdir} ||= $astdir;
-
-chdir($vars{astdir});
-my $type = $args{type} || "apps";
-my $env = `make ${type}_env`;
-chdir($pwd);
-
-foreach(split("\n",$env)) {
- my($var,$val) = /([^\=]+)\=(.*)/;
- $vars{$var} = $val;
-}
-
-
-
-
-foreach(keys %svars) {
- $vars{$_} = $svars{$_};
-}
-
-foreach(keys %avars) {
- $vars{$_} .= $avars{$_};
-}
-
-
-if($args{print}) {
- print "$vars{$args{print}}";
- exit;
-}
-
-
-my($base,$ext);
-my $cfile = $args{plain}->[0];
-
-
-if($cfile =~ /http:\/\/.*?\/([^\/]+)$/) {
-
- my $f = $1;
- if(! -d "/tmp/astbld") {
- mkdir("/tmp/astbld");
- }
- my $pwd = `pwd`;
- chomp $pwd;
- chdir("/tmp/astbld");
- system("/bin/rm $f");
- system("wget $cfile");
- chdir($pwd);
- $cfile = "/tmp/astbld/$f";
-
-
-}
-
-
-
-if($cfile) {
- ($base,$ext) = $cfile =~ /^([^\.]+)\.(.+)/;
-}
-
-if($ext eq "so") {
- unless($args{linkonly}) {
- $args{installonly}++;
- }
-} elsif($ext ne "c") {
- usage "Bad Input File";
-}
-
-
-my $bad=0;
-
-$bad = esystem("$vars{CC} -I${astdir} -I${astdir}/include $vars{CFLAGS} -c ${base}.c -o ${base}.o") unless($args{linkonly} or $args{installonly});
-exit -1 if($bad);
-exit if($args{nolink});
-
-
-
-$vars{MAINOBJ} ||= "$base.o";
-$bad = esystem("$vars{CC} $vars{SOLINK} -o ${base}.so $vars{LDFLAGS} $vars{MAINOBJ} $vars{EXTOBJ}") if(!$bad and !$args{installonly});
-exit -1 if($bad);
-
-if(($args{install} or $args{installonly}) and $vars{MODULES_DIR}) {
- my $file = "${base}.so";
- my ($mod) = $file =~ /([^\/]*)$/;
-
- if($args{autoload}) {
- $bad = esystem("/usr/sbin/asterisk -rx 'unload $mod'");
- }
- $bad = esystem("/bin/cp -p ${base}.so $vars{MODULES_DIR}") if(!$bad);
-
- if($args{autoload}) {
- $bad = esystem("/usr/sbin/asterisk -rx 'load $mod'");
- }
-}
-
diff --git a/1.2-netsec/contrib/scripts/autosupport b/1.2-netsec/contrib/scripts/autosupport
deleted file mode 100644
index e13d839dc..000000000
--- a/1.2-netsec/contrib/scripts/autosupport
+++ /dev/null
@@ -1,155 +0,0 @@
-#!/bin/sh
-#
-# Collect support information
-#
-# Copyright (C) 2005, Digium, Inc.
-#
-# Written by John Bigelow (support@digium.com)
-#
-# Distributed under the terms of the GNU General Public
-# License
-#
-
-OUTPUT=$HOME/digiuminfo
-
-if [ $UID -ne 0 ]; then
-
- echo "You must be root to run this."
-
-exit 1
-fi
-
-echo
-echo "This will gather information about your system such as:"
-echo "pci listing, dmesg, running processes, and kernel version"
-echo "To continue press 'y', to quit press any other key"
-read ans
-
-if [ "$ans" = "y" ]; then
-
- rm -f $OUTPUT
-
- echo "------------------" >> $OUTPUT;
- echo "PCI LIST " >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- lspci -vb >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
- echo "------------------" >> $OUTPUT;
- echo "INTERRUPTS" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- cat /proc/interrupts >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
- echo "------------------" >> $OUTPUT;
- echo "DMESG OUTPUT" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- dmesg >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
- echo "------------------" >> $OUTPUT;
- echo "RUNNING PROCESSES" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- ps aux >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
- echo "------------------" >> $OUTPUT;
- echo "KERNEL VERSION" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- uname -a >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
- echo "------------------" >> $OUTPUT;
- echo "CPU INFO" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- cat /proc/cpuinfo >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
- echo "------------------" >> $OUTPUT;
- echo "HDPARM STATUS" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- hdparm /dev/hda >> $OUTPUT;
- hdparm -i /dev/hda >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
- echo "------------------" >> $OUTPUT;
- echo "ZAPTEL CONFIG" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- grep -v '^#' /etc/zaptel.conf >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
- echo "------------------" >> $OUTPUT;
- echo "ZAPATA CONFIG" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- grep -v '^;' /etc/asterisk/zapata.conf >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
- echo "------------------" >> $OUTPUT;
- echo "EXTENSIONS CONFIG" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
- grep -v '^;' /etc/asterisk/extensions.conf >> $OUTPUT;
- echo >> $OUTPUT;
- echo >> $OUTPUT;
-
-else
- echo "terminated";
-exit
-fi
-
-echo
-echo "Digium may require root level access to the system to help debug";
-echo "the problem you are experiencing. Do you want to provide login";
-echo "information at this time?";
-echo "Press 'y' for yes and any other key to exit and save the previous info collected"
-read login
-
-if [ "$login" = "y" ]; then
-
- echo "------------------" >> $OUTPUT;
- echo "LOGIN INFORMATION" >> $OUTPUT;
- echo "------------------" >> $OUTPUT;
-
- echo
- echo "What is your root password?"
- read rootpass
-
- echo
- echo "Root pass: "$rootpass >> $OUTPUT
-
- echo
- echo "What is your PUBLIC IP address?"
- read ip
-
- echo "IP address: "$ip >> $OUTPUT
-
- echo
- echo "Please provide any other login information that the technician"
- echo "may need to know to login to the system'(press enter if not)'"
- read adinfo
-
- echo "Additional login info: "$adinfo >> $OUTPUT
-
- echo
- echo "All information has been stored in $OUTPUT,"
- echo "Please attach this file to an email ticket you already"
- echo "have open with Digium Tech Support."
-
-else
- echo
- echo "All information except login info has been stored in $OUTPUT,"
- echo "Please send this file to an email ticket you already"
- echo "have open with Digium Tech Support."
-exit
-fi
-
-
-
diff --git a/1.2-netsec/contrib/scripts/autosupport.8 b/1.2-netsec/contrib/scripts/autosupport.8
deleted file mode 100644
index e356fcdbb..000000000
--- a/1.2-netsec/contrib/scripts/autosupport.8
+++ /dev/null
@@ -1,41 +0,0 @@
-.TH AUTOSUPPORT 8 "Jul 5th, 2005" "Asterisk" "Linux Programmer's Manual"
-.SH NAME
-.B autosupport
-\(em interactive script to provide Digium[tm]'s support with information
-.SH SYNOPSIS
-.PP
-.B autosupport
-
-.SH DESCRIPTION
-.B autoasupport
-is a script that is normally run by a user contacting Digium's support
-to automate gathering support information.
-
-It will probe the system for some configuration and run-time information,
-and will also prompt the user for some optional access information (IP
-address, login and password).
-
-The information is written to /root/digiuminfo which the user is expected
-to attach to a support ticket to Digium.
-
-The script must be run as root as it reads Asterisk's configuration and
-the disk information using hdparm(8).
-
-.SH FILES
-.B /root/digiuminfo
-.RS
-The output of the script goes there
-.RE
-
-.SH SEE ALSO
-asterisk(8)
-
-.SH "AUTHOR"
-autosupport was written by John Bigelow <support@digium.com>.
-This manual page was written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
-Permission is granted to copy, distribute and/or modify this document under
-the terms of the GNU General Public License, Version 2 any
-later version published by the Free Software Foundation.
-
-On Debian systems, the complete text of the GNU General Public
-License can be found in /usr/share/common-licenses/GPL.
diff --git a/1.2-netsec/contrib/scripts/iax-friends.sql b/1.2-netsec/contrib/scripts/iax-friends.sql
deleted file mode 100644
index 717a27d07..000000000
--- a/1.2-netsec/contrib/scripts/iax-friends.sql
+++ /dev/null
@@ -1,15 +0,0 @@
-#
-# Table structure for table `iaxfriends`
-#
-
-CREATE TABLE `iaxfriends` (
- `name` varchar(40) NOT NULL default '',
- `secret` varchar(40) NOT NULL default '',
- `context` varchar(40) NOT NULL default '',
- `ipaddr` varchar(20) NOT NULL default '',
- `port` int(6) NOT NULL default '0',
- `regseconds` int(11) NOT NULL default '0',
- `accountcode` varchar(20) NOT NULL default '',
- PRIMARY KEY (`name`)
-) TYPE=MyISAM;
-
diff --git a/1.2-netsec/contrib/scripts/loadtest.tcl b/1.2-netsec/contrib/scripts/loadtest.tcl
deleted file mode 100644
index 9c50be338..000000000
--- a/1.2-netsec/contrib/scripts/loadtest.tcl
+++ /dev/null
@@ -1,148 +0,0 @@
-#!/usr/bin/tclsh
-#
-# Usage (as root):
-#
-# $ tclsh loadtest.tcl
-#
-# Copyleft 2005 by Chris Maj <cmaj_at_freedomcorpse_dot_com>
-#
-# Create a (huge) bunch of call files to dial via pbx_spool.
-# Defaults are selected with 'Enter' and, if all defaults
-# are selected, you'll dial Zap/1/s into default|s|1
-#
-
-
-# where Asterisk's pbx/pbx_spool.c will be looking for work
-set SPOOLDIR /var/spool/asterisk/outgoing
-# pbx_spool is fairly aggresive, so make files here first
-set TEMPDIR /tmp
-
-if { ![file writable $SPOOLDIR] } {
- puts "Do you need to be root to write to $SPOOLDIR ?"
- exit
-}
-
-if { ![file readable $TEMPDIR] } {
- puts "Do you need to be root to read from $TEMPDIR ?"
- exit
-}
-
-if { ![file writable $TEMPDIR] } {
- puts "Do you need to be root to write to $TEMPDIR ?"
- exit
-}
-
-# gets some input from the user
-proc get {var_ default_ prompt_} {
- global $var_
- puts $prompt_
- if { $default_ != "" } {
- puts -nonewline "(default: $default_) ? "
- } else {
- puts -nonewline "? "
- }
- flush stdout
- gets stdin $var_
- if { [set $var_] == "" && $default_ != "" } {
- set $var_ $default_
- }
-}
-
-# puts the user requested channels into a neat, ordered list
-proc splitchans {inch_} {
- global changroup
- set outch [list]
- foreach range [split $inch_ {, }] {
- set start [lindex [split $range -] 0]
- set stop [lindex [split $range -] end]
- if { [string is digit $start] && [string is digit $stop] } {
- set ::changroup "channel"
- for {set ch $start} {$ch <= $stop} {incr ch} {
- if { [lsearch $outch $ch] == -1 } {
- lappend outch $ch
- }
- }
- } else {
- set ::changroup "group"
- foreach ch [split $range -] {
- lappend outch $ch
- }
- }
- }
- return [lsort -dictionary $outch]
-}
-
-# writes out a file in the temporary directory,
-# then changes the mtime of the file before
-# sticking it into the outgoing spool directory
-# (where pbx_spool will be looking)
-proc spool {channel_ callcnt_ when_} {
- set callstr "
-Channel: $::technology/$channel_/$::destination
-Context: $::context
-Extension: $::extension
-Priority: $::priority
-WaitTime: $::timeout
-RetryTime: $::retrytime
-MaxRetries: $::maxretries
-Callerid: $::clid
-SetVar: $::astvar
-Account: $::account
-"
- set fn "loadtest.call$callcnt_.ch$channel_"
- set fd [open $::TEMPDIR/$fn w]
- puts $fd $callstr
- close $fd
- file mtime $::TEMPDIR/$fn $when_
- file rename -force $::TEMPDIR/$fn $::SPOOLDIR/$fn
-}
-
-# prompt the user for some info
-get technology "Zap" "\nEnter technology type
-Zap, IAX, SIP, etc."
-get chans "1" "\nEnter channel(s) or group to test in formats like
-2\n1-4\n3 5 7 9\n1-23,25-47,49-71,73-95\ng4\ng2,g1"
-set channels [splitchans $chans]
-
-get destination "s" "\nEnter destination number"
-get context "default" "\nEnter context"
-get extension "s" "\nEnter extension"
-get priority "1" "\nEnter priority"
-get timeout "45" "\nEnter timeout for call to be answered in seconds"
-get maxretries "0" "\nEnter maximum number of retries"
-
-if { $maxretries > 0 } {
- get retrytime "300" "\nEnter time between retries in seconds"
-} else {
- set retrytime 300
-}
-
-get clid "" "\nEnter callerid"
-get astvar "" "\nEnter some extra variables"
-get account "loadtest" "\nEnter account code"
-get calls "1" "\nEnter number of test calls per $changroup"
-get period "60" "\nEnter period between placing calls on a particular $changroup in seconds"
-
-if { [llength $channels] > 1 } {
- get rate "0" "\nEnter period between placing each call in seconds
-0 will send a call on each $changroup every $period seconds
-1 will send a call on $changroup [lindex $channels 0] at [expr {$period + 0}]s, [lindex $channels 1] at [expr {$period + 1 }]s, etc.
-5 will send a call on $changroup [lindex $channels 0] at [expr {$period + 0}]s, [lindex $channels 1] at [expr {$period + 5 }]s, etc."
-} else {
- set rate 0
-}
-
-puts -nonewline "\nCreating spooled call files... "
-set now [clock seconds]
-set spoolcnt 0
-set spinner [list / - \\ |]
-for {set i 0} {$i < $calls} {incr i} {
- foreach ch $channels {
- set chidx [lsearch $channels $ch]
- spool $ch [incr spoolcnt] [expr {$now + ($i * $period) + ($rate * $chidx)}]
- puts -nonewline "\b"
- puts -nonewline [lindex $spinner [expr {$spoolcnt % 4}]]
- flush stdout
- }
-}
-puts "\b$spoolcnt calls placed into $SPOOLDIR !"
diff --git a/1.2-netsec/contrib/scripts/lookup.agi b/1.2-netsec/contrib/scripts/lookup.agi
deleted file mode 100644
index 4b682b837..000000000
--- a/1.2-netsec/contrib/scripts/lookup.agi
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/perl
-#
-# Use Reverse Lookups to populate valuable information
-#
-# Copyright (C) 2005 Digium, Inc.
-#
-# Mark Spencer <markster@digium.com>
-#
-# Based on work of Joe Fratantoni - BrakeDanceJ - Joe@UnrealDestination.com.
-#
-# This program is Free Software distributed under the terms of the GNU
-# General Public License version 2. See LICENSE for details.
-#
-#
-use LWP::UserAgent;
-my %AGI;
-my $debug = 0;
-$|=1;
-sub url_decode {
- my @args = @_;
- s/%([0-9A-F]{2})/chr hex $1/egios for @args;
- s/\"//egios for @args;
- return wantarray ? @args : $args[0];
-}
-
-while(<STDIN>) {
- chomp;
- last unless length($_);
- if (/^agi_(\w+)\:\s+(.*)$/) {
- $AGI{$1} = $2;
- }
-}
-
-alarm(4);
-my $number = $AGI{'callerid'};
-$number =~ /(\d+)/;
-$number = $1;
-die("You must specify a number") unless $number;
-my $ua = LWP::UserAgent->new;
-$ua->agent("Asterisk");
-my $req = HTTP::Request->new(POST => 'http://www.411.com/10668/search/Reverse_Phone');
-$req->content_type('application/x-www-form-urlencoded');
-$req->content("phone=$number");
-my $res = $ua->request($req);
-if ($res->is_success) {
- my $first, $last, $address, $street, $house, $city, $state, $zip, $phone;
- if ($res->content =~ /PAGE: PHONE_NOT_FOUND/) {
- # Limited Information
- $res->content =~ /is a \s+([A-Za-z -]*), ([A-Z]{2}) \s+based phone number and the registered carrier is (.*)\.\s+/;
- ($city, $state, $last) =
- map { url_decode($_) } ($1, $2, $3);
- $cidname = "$city, $state";
- } else {
- # Full Information
- $res->content =~ /RM_HTML_FIRST_ESC_=(.*)&_RM_HTML_LAST_ESC_=(.*)&_RM_HTML_ADDRESS_ESC_=(.*)&_RM_HTML_STREET_ESC_=(.*)&_RM_HTML_HOUSE_ESC_=(.*)&_RM_HTML_CITY_ESC_=(.*)&_RM_HTML_STATE_ESC_=(.*)&_RM_HTML_ZIP_ESC_=(.*)&_RM_HTML_PHONE_ESC_=(.*)&CITY=(.*)&STATE=(.*)/;
- ($first, $last, $address, $street, $house, $city, $state, $zip, $phone) =
- map { url_decode($_) } ($1, $2, $3, $4, $5, $6, $7, $8, $9);
- my $cidname = $last;
- if ($first) {
- $cidname = $first . " " . $last;
- } else {
- $cidname = $last;
- }
- }
- print STDOUT "SET VARIABLE CALLERID(name) \"$cidname\"\n";
- <STDIN>;
- print STDOUT "SET VARIABLE CALLER_ZIP \"$zip\"\n";
- <STDIN>;
- print STDOUT "SET VARIABLE CALLER_STATE \"$state\"\n";
- <STDIN>;
- print STDOUT "SET VARIABLE CALLER_CITY \"$city\"\n";
- <STDIN>;
- print STDOUT "SET VARIABLE CALLER_ADDRESS \"$address\"\n";
- <STDIN>;
- print STDOUT "SET VARIABLE CALLER_LAST \"$last\"\n";
- <STDIN>;
- print STDOUT "SET VARIABLE CALLER_FIRST \"$first\"\n";
- <STDIN>;
- print STDERR "First: $first\n" .
- "Last: $last\n" .
- "Address: $address\n" .
- "Street: $street\n" .
- "House: $house\n" .
- "City: $city\n" .
- "State: $state\n" .
- "Zip: $zip\n" .
- "Phone: $phone\n" if $debug;
-} else {
- print STDERR $res->status_line . "\n";
-}
diff --git a/1.2-netsec/contrib/scripts/managerproxy.pl b/1.2-netsec/contrib/scripts/managerproxy.pl
deleted file mode 100644
index 1c2c05c82..000000000
--- a/1.2-netsec/contrib/scripts/managerproxy.pl
+++ /dev/null
@@ -1,242 +0,0 @@
-#!/usr/bin/perl -w
-#
-# Simple Asterisk Manager Proxy, Version 1.01
-# 2004-09-26
-# Copyright (c) 2004 David C. Troy &lt;dave@popvox.com>
-#
-# This code is based on Flash Operator Panel 'op_server.pl'
-# by Nicolá³ Gudiñ¯¬
-#  Copyright (C) 2004.
-#
-# David C. Troy &lt;dave@popvox.com>
-# Nicol᳠Gudi񯠼nicolas@house.com.ar>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License.
-#
-# Security consideration: This script will open your manager port
-# for unauthenticated logins. Be careful out there :-)
-#############################
-
-#############################
-# Perl Prerequisites
-#############################
-use strict;
-use IO::Socket;
-use IO::Select;
-use POSIX qw(setsid);
-
-#############################
-# User Configurable Options
-#############################
-# Configuration for logging in to your asterisk server
-# Check you Asterisk config file "manager.conf" for details
-my $manager_host = '127.0.0.1';
-my $manager_port = 5038;
-my $manager_user = 'your_username';
-my $manager_secret = 'your_secret';
-# Port For this proxy
-my $listen_port = 1234;
-my $manager_pid = "/var/run/asterisk_managerproxy.pid";
-
-#############################
-# Declarations
-#############################
-my %proxy_clients;
-my $O;
-my $p;
-my @S;
-my %blocks;
-my $debug = 0;
-
-$SIG{PIPE} = 'IGNORE';
-$SIG{INT} = 'close_all';
-$SIG{USR1} = 'list_clients';
-
-if (defined($ARGV[0]))
-{
- if ($ARGV[0] eq "-d")
- {
- defined(my $pid = fork) or die "Can't Fork: $!";
- exit if $pid;
- setsid or die "Can't start a new session: $!";
- open MYPIDFILE, ">$manager_pid";
- print MYPIDFILE $$;
- close MYPIDFILE;
- }
-} else {
- $debug = 1;
-}
-
-
-# Connect to manager
-$p =
- new IO::Socket::INET->new(
- PeerAddr => $manager_host,
- PeerPort => $manager_port,
- Proto => "tcp",
- Type => SOCK_STREAM
- )
- or die "\nCould not connect to Asterisk Manager Port at $manager_host\n";
-
-$p->autoflush(1);
-
-# Login to Manager
-send_command_to_manager( "Action: Login\r\nUsername: $manager_user\r\nSecret: $manager_secret\r\n\r\n" );
-
-# Start up listener for new connections
-my $m =
- new IO::Socket::INET(Listen => 1, LocalPort => $listen_port, ReuseAddr => 1)
- or die "\nCan't listen to port $listen_port\n";
-$O = new IO::Select();
-$O->add($m);
-$O->add($p);
-$/ = "\0";
-
-sub manager_reconnect()
-{
- my $attempt = 1;
- my $total_attempts = 60;
-
- do
- {
- log_debug("** Attempt reconnection to manager port # $attempt", 16);
- $p =
- new IO::Socket::INET->new(
- PeerAddr => $manager_host,
- PeerPort => $manager_port,
- Proto => "tcp",
- Type => SOCK_STREAM
- );
- $attempt++;
- if ($attempt > $total_attempts)
- {
- die("!! Could not reconnect to Asterisk Manager port");
- }
- sleep(10); # wait 10 seconds before trying to reconnect
- } until $p;
- $O->add($p);
- send_command_to_manager(
- "Action: Login\r\nUsername: $manager_user\r\nSecret: $manager_secret\r\n\r\n"
- );
-}
-
-# Loop, continuously processing new connections, input from those connections, and input from Manager conn
-while (1)
-{
- while (@S = $O->can_read)
- {
- foreach (@S)
- {
- if ($_ == $m)
- {
- log_debug("** New client connection", 16);
- my $C = $m->accept;
- $proxy_clients{$C} = \$C;
- print "New Connection: $C\n" if $debug;
- $O->add($C);
- } else {
- # It's not a new client connection
- my $i;
- my $R = sysread($_, $i, 2); # 2048; interleave every two bytes?
- if (defined($R) && $R == 0)
- {
- # Confirm it's really dead by trying to write to it?
- my $T = syswrite($_, ' ', 2); # 2048
- if (!defined($T))
- {
- # connection went away...
- $O->remove($_);
- $_->close;
-
- # If we lost the socket for the Asterisk Mgr, then reconnect
- if ($_ == $p)
- {
- log_debug(
- "** Asterisk Manager connection lost!!!!!",
- 16);
- manager_reconnect();
- } else {
- # Remove handle from proxy_clients hash
- print "Closed Connection: $_\n" if $debug;
- delete $proxy_clients{$_};
- }
- }
- }
- else # Socket is active and we are ready to read something from it
- {
- $blocks{$_} .= $i;
- next if ($blocks{$_} !~ /\r\n\r\n$/);
- # do a 'next' unless we have completed a block; we are not ready to continue
-
- # Process the completed block
- # If block is from asterisk, send to clients
- if ($_ == $p) {
- # block is from asterisk, send to clients
- print "asterisk: $_\n$blocks{$_}" if $debug;
- my $cnt = 0;
- foreach my $client (values %proxy_clients) {
- print "writing to $$client...\n" if $debug;
- syswrite($$client, $blocks{$_});
- $cnt++;
- }
- print "sent block to $cnt clients\n" if $debug;
- } else {
- # Blocks are from clients, send to asterisk
- syswrite($p, $blocks{$_});
- print "client: $_\n$blocks{$_}\n" if $debug;
- }
- delete $blocks{$_};
-
- } # end if read succeeded
- } # end if new client connection
- } # end foreach @S -> can read
- } # while can read
-} # endless loop
-
-sub close_all
-{
- log_debug("Exiting...", 0);
-
- foreach my $hd ($O->handles)
- {
- $O->remove($hd);
- close($hd);
- }
-
- exit(0);
-}
-
-sub send_command_to_manager
-{
- my $comando = shift;
- if (defined $p)
- {
- my @lineas = split("\r\n", $comando);
- foreach my $linea (@lineas)
- {
- syswrite($p, "$linea\r\n");
- log_debug("-> $linea", 2);
- }
- log_debug(" ", 2);
- syswrite($p, "\r\n");
- }
-}
-
-sub log_debug
-{
- my $texto = shift;
- $texto =~ s/\0//g;
- print "$texto\n" if $debug;
-}
-
-sub list_clients()
-{
- my $cnt = 0;
- foreach my $client (values %proxy_clients) {
- print "client: $$client\n";
- $cnt++;
- }
- print "$cnt clients.\n\n";
-}
-
diff --git a/1.2-netsec/contrib/scripts/messages-expire.pl b/1.2-netsec/contrib/scripts/messages-expire.pl
deleted file mode 100644
index 993997899..000000000
--- a/1.2-netsec/contrib/scripts/messages-expire.pl
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/perl
-#
-# Script to expire voicemail after a specified number of days
-# by Steve Creel <screel@turbs.com>
-#
-
-# Directory housing the voicemail spool for asterisk
-$dir = "/var/spool/asterisk/voicemail";
-
-# Context for which the script should be running
-$context = "default";
-
-# Age (Delete files older than $age days old)
-$age = 31;
-
-# Age for unheard messages (Defaults to same age for all messages)
-# Set to 0 to not delete unheard messages
-$unheardage = $age;
-
-
-# Delete all files older than $age and $unheardage
-# (named msg????.??? to get the audio and txt files,
-# but we don't delete greetings or the user's name)
-
-if($age==$unheardage) {
-
- # Save time by doing one find if we're treating everything the same
- system('find '.$dir.'/'.$context.' -name msg????.??? -mtime +'.$age.' -exec rm {} \; -exec echo Deleted {} \;');
-
-} else {
-
- # Find everything not in a folder called 'INBOX' and delete it after $age days
- system('find '.$dir.'/'.$context.' -path \'*INBOX*\' -prune -o -name msg????.??? -mtime +'.$age.' -exec rm {} \; -exec echo Deleted {} \;');
-
- # If unheardage is set to 0, we won't delete any unheard messages
- if($unheardage > 0) {
-
- # Delete things that are in a folder called INBOX after $unheardage days
- system('find '.$dir.'/'.$context.' -path \'*INBOX*\' -name msg????.??? -mtime +'.$unheardage.' -exec rm {} \; -exec echo Deleted {} \;');
-
- }
-}
-
-# For testing - what number to we start when we renumber?
-$start = "0";
-
-# Rename to msg and a 4 digit number, 0 padded.
-$fnbase = sprintf "msg%04d", $start;
-
-# Make $dir include the context too
-$dir.="/".$context;
-
-( -d $dir ) || die "Can't read list of mailboxes ($dir): $!\n";
-@mailboxes = `ls -A1 $dir`;
-chomp(@mailboxes);
-
-$save_fnbase = $fnbase;
-
-foreach $mailbox (@mailboxes) {
-
- ( -d $dir."/".$mailbox) || die "Can't read list of folders (".$dir."/".$mailbox."): $!\n";
- @folders = `ls -A1 $dir/$mailbox`;
- chomp(@folders);
-
- foreach $folder (@folders) {
- if (-d $dir."/".$mailbox."/".$folder) {
- ( -d $dir."/".$mailbox."/".$folder) || die "Can't read list of messages (".$dir."/".$mailbox."/".$folder.") $!\n";
- @files = `ls -A1 $dir/$mailbox/$folder/`;
-
- # Sort so everything is in proper order.
- @files = sort @files;
- chomp(@files);
-
- # If there is still (after deleting old files earlier in the
- # script) a msg0000.txt, we don't need to shuffle anything
- # in this folder.
- if (-f $dir."/".$mailbox."/".$folder."/msg0000.txt") { next; }
-
- foreach $ext (("WAV", "wav", "gsm", "txt")) {
- # Reset the fnbase for each file type
- $fnbase = $save_fnbase;
-
- foreach $file (@files) {
- if ( $file =~ /$ext/ ) {
- chdir($dir."/".$mailbox."/".$folder."/") || die "Can't change folder: $!";
- print "Renaming: ".$dir."/".$mailbox."/".$folder."/".$file." to ".$fnbase.".".$ext."\n";
- rename($file, $fnbase.".".$ext) || die "Cannot rename: $!";
- $fnbase++;
- }
- }
- }
- }
- }
-}
-
-__END__ \ No newline at end of file
diff --git a/1.2-netsec/contrib/scripts/postgres_cdr.sql b/1.2-netsec/contrib/scripts/postgres_cdr.sql
deleted file mode 100644
index a4701bd77..000000000
--- a/1.2-netsec/contrib/scripts/postgres_cdr.sql
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/*
- * Id: postgres_cdr.sql,v 1.8.2.11 2003/10/10 11:15:43 pnixon Exp $
- *
- * --- Peter Nixon [ codemonkey@peternixon.net ]
- *
- * This is a PostgreSQL schema for doing CDR accounting with Asterisk
- *
- * The calls will automatically be logged as long as the module is loaded.
- *
- */
-
-
-CREATE TABLE cdr (
- AcctId BIGSERIAL PRIMARY KEY,
- calldate TIMESTAMP with time zone NOT NULL DEFAULT now(),
- clid VARCHAR(80) NOT NULL default '',
- src VARCHAR(80) NOT NULL default '',
- dst VARCHAR(80) NOT NULL default '',
- dcontext VARCHAR(80) NOT NULL default '',
- channel VARCHAR(80) NOT NULL default '',
- dstchannel VARCHAR(80) NOT NULL default '',
- lastapp VARCHAR(80) NOT NULL default '',
- lastdata VARCHAR(80) NOT NULL default '',
- duration INTEGER NOT NULL default '0',
- billsec INTEGER NOT NULL default '0',
- disposition VARCHAR(45) NOT NULL default '',
- amaflags INTEGER NOT NULL default '0',
- accountcode VARCHAR(20) NOT NULL default '',
- uniqueid VARCHAR(32) NOT NULL default '',
- userfield VARCHAR(255) NOT NULL default ''
-);
-
diff --git a/1.2-netsec/contrib/scripts/qview.pl b/1.2-netsec/contrib/scripts/qview.pl
deleted file mode 100644
index 940e474f7..000000000
--- a/1.2-netsec/contrib/scripts/qview.pl
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/usr/bin/perl
-#
-# Asterisk Queue Viewer
-# Uses management interface to query call queues on a machine
-# (C) 2003 David C. Troy -- dave@toad.net
-#
-# This program is free software, distributed under the terms of the
-# GNU General Public License
-#
-
-use IO::Socket;
-use CGI qw(:standard);
-use CGI::Carp qw/fatalsToBrowser/;
-
-$host = "asterisk.yourdomain.com";
-$port = 5038;
-$user = "manager_user";
-$secret = "Manager_secret";
-$EOL = "\015\012";
-$BLANK = $EOL x 2;
-$queue = param('queue');
-
-$remote = IO::Socket::INET->new(
- Proto => 'tcp', # protocol
- PeerAddr=> $host, # Address of server
- PeerPort=> $port, # port of server
- Reuse => 1
- ) or die "$!";
-
-$remote->autoflush(1); # Send immediately
-
-# Login and get our booty from Asterisk
-$logres = send_cmd("Action: Login${EOL}Username: $user${EOL}Secret: $secret$BLANK");
-$qinfo = send_cmd("Action: queues$BLANK$EOL");
-$logres = send_cmd("Action: Logoff$BLANK");
-close $remote; # Close socket
-
-my %qcalls = map { /(\S+)\s+has (\d+) calls.*?\n\n/sg; } $qinfo;
-my %qmax = map { /(\S+)\s+has \d+ calls \(max (\S+)\).*?\n\n/sg; } $qinfo;
-my %qstrat = map { /(\S+)\s+has \d+ calls \(max \S+\) in (\S+) strategy.*?\n\n/sg; } $qinfo;
-my %qmems = map { /(\S+)\s+has \d+ calls.*?Members:.*?\s{6}(.*?)\s{3}\S*?\s*?Callers/sg; } $qinfo;
-my %qcallers = map { /(\S+)\s+has \d+ calls.*?([No ]*Callers.*?)\n\n/sg; } $qinfo;
-
-print header();
-print start_html(-head=>meta({-http_equiv=>'Refresh', -content=>'120'}),
- -title=>"PBX Queue Viewer",
- -style=>{'src'=>'/pbxinfo.css'});
-print "<table width=850><tr>";
-
-$col = 0;
-
-foreach $q (keys %qcalls) {
-
- $mems = $qmems{$q};
- $mems =~ s/ //g;
- $mems =~ s/\n/<br>\n/g;
- $callers = $qcallers{$q};
- $callers =~ s/ //g;
- $callers =~ s/Callers:.*\n//g;
- $callers =~ s/\n/<br>/g;
-
- print qq{<td valign=top width=48%><table width=100%>
-<tr><th colspan=2><A HREF=/mrtg/qmon-$q.html>$q</A>&nbsp;&nbsp;$qcalls{$q} calls (max $qmax{$q}), $qstrat{$q} strategy</th></tr>
-<tr><td valign=top width=55%>$mems</td><td valign=top width=45%>$callers</td></tr>
-</table></td>
-};
-
- print "</tr><tr>" if $col;
- $col = 0 if $col++;
-
-}
-
-print "</table>";
-
-print end_html();
-
-exit(0);
-
-sub read_conn {
-
- my $buf="";
- while (<$remote>) {
- last if $_ eq $EOL;
- s/$EOL/\n/g;
- $buf .= $_;
- }
-
- return $buf
-}
-
-sub send_cmd {
- my $cmd = @_[0];
-
- my $buf="";
- print $remote $cmd;
-
- $buf = read_conn();
-
- return $buf;
-}
diff --git a/1.2-netsec/contrib/scripts/retrieve_extensions_from_mysql.pl b/1.2-netsec/contrib/scripts/retrieve_extensions_from_mysql.pl
deleted file mode 100644
index ca195cfe5..000000000
--- a/1.2-netsec/contrib/scripts/retrieve_extensions_from_mysql.pl
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/usr/bin/perl -Tw
-# Use these commands to create the appropriate tables in MySQL
-# If flags is 1 then this record is not included in the output extensions file
-#
-#CREATE TABLE extensions (
-# context CHAR(20) DEFAULT 'default' NOT NULL,
-# extension CHAR(20) NOT NULL,
-# priority INT(2) DEFAULT '1' NOT NULL,
-# application CHAR(20) NOT NULL,
-# args CHAR(50),
-# descr TEXT,
-# flags INT(1) DEFAULT '0' NOT NULL,
-# PRIMARY KEY(context, extension, priority)
-#);
-#
-#CREATE TABLE globals (
-# variable CHAR(20) NOT NULL,
-# value CHAR(50) NOT NULL,
-# PRIMARY KEY(variable, value)
-#);
-
-use DBI;
-################### BEGIN OF CONFIGURATION ####################
-
-# the name of the extensions table
-$table_name = "extensions";
-# the name of the globals table
-$global_table_name = "globals";
-# the path to the extensions.conf file
-# WARNING: this file will be substituted by the output of this program
-$extensions_conf = "/etc/asterisk/extensions.conf";
-# the name of the box the MySQL database is running on
-$hostname = "localhost";
-# the name of the database our tables are kept
-$database = "user";
-# username to connect to the database
-$username = "";
-# password to connect to the database
-$password = "";
-
-################### END OF CONFIGURATION #######################
-
-open EXTEN, ">$extensions_conf" || die "Cannot create/overwrite extensions file: $extensions_conf\n";
-
-$dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password");
-$statement = "SELECT * from $global_table_name order by variable";
-my $result = $dbh->selectall_arrayref($statement);
-unless ($result) {
- # check for errors after every single database call
- print "dbh->selectall_arrayref($statement) failed!\n";
- print "DBI::err=[$DBI::err]\n";
- print "DBI::errstr=[$DBI::errstr]\n";
- exit;
-}
-my @resultSet = @{$result};
-if ( $#resultSet > -1 ) {
- print EXTEN "[globals]\n";
- foreach $row (@{ $result }) {
- my @result = @{ $row };
- print EXTEN "$result[0] = $result[1]\n";
- }
- print EXTEN "\n";
-}
-
-$statement = "SELECT context from $table_name group by context";
-
-$result = $dbh->selectall_arrayref($statement);
-unless ($result) {
- # check for errors after every single database call
- print "dbh->selectall_arrayref($statement) failed!\n";
- print "DBI::err=[$DBI::err]\n";
- print "DBI::errstr=[$DBI::errstr]\n";
-}
-
-@resultSet = @{$result};
-if ( $#resultSet == -1 ) {
- print "No extensions defined in $table_name\n";
- exit;
-}
-
-foreach my $row ( @{ $result } ) {
- my $context = @{ $row }[0];
- print EXTEN "[$context]\n";
- $statement = "SELECT * from $table_name where context='$context' order by extension, priority";
- my $result = $dbh->selectall_arrayref($statement);
- unless ($result) {
- # check for errors after every single database call
- print "dbh->selectall_arrayref($statement) failed!\n";
- print "DBI::err=[$DBI::err]\n";
- print "DBI::errstr=[$DBI::errstr]\n";
- exit;
- }
-
- my @resSet = @{$result};
- if ( $#resSet == -1 ) {
- print "no results\n";
- exit;
- }
- foreach my $row ( @{ $result } ) {
- my @result = @{ $row };
- if ($result[6] == 0) {
- print EXTEN "exten => $result[1],$result[2],$result[3]";
- print EXTEN "($result[4])" if defined $result[4];
- print EXTEN "\t" if not defined $result[4];
- print EXTEN "\t; $result[5]" if defined $result[5];
- print EXTEN "\n";
- }
- }
- print EXTEN "\n";
-}
-
-exit 0;
-
diff --git a/1.2-netsec/contrib/scripts/retrieve_extensions_from_sql.pl b/1.2-netsec/contrib/scripts/retrieve_extensions_from_sql.pl
deleted file mode 100644
index cf17d0351..000000000
--- a/1.2-netsec/contrib/scripts/retrieve_extensions_from_sql.pl
+++ /dev/null
@@ -1,158 +0,0 @@
-#!/usr/bin/perl -Tw
-# Author: Peter Nixon <codemonkey@peternixon.net>
-# Date: April 2004
-# Copy Policy: GNU Public Licence Version 2 or later
-# URL: http://www.peternixon.net/code/
-# Supported: PostgreSQL, Oracle, MySQL
-# Copyright: 2004 Peter Nixon <codemonkey@petenixon.net>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# $Id$
-#
-# Use these commands to create the appropriate SQL tables
-# If flags is 1 then the record is not included in the output extensions file
-#
-#CREATE TABLE extensions (
-# context VARCHAR(20) DEFAULT 'default' NOT NULL,
-# extension VARCHAR(20) NOT NULL,
-# priority INTEGER DEFAULT '1' NOT NULL,
-# application VARCHAR(20) NOT NULL,
-# args VARCHAR(50),
-# descr TEXT,
-# flags BOOLEAN DEFAULT '0' NOT NULL,
-# PRIMARY KEY(context, extension, priority)
-#);
-
-#CREATE TABLE globals (
-# variable VARCHAR(20) NOT NULL,
-# value VARCHAR(50) NOT NULL,
-# PRIMARY KEY(variable, value)
-#);
-
-use strict; # Make sure we write decent perl code
-
-require DBI; # We need database drivers for this thing to work
-
-################### BEGIN OF CONFIGURATION ####################
-
-my $table_name = "extensions"; # name of the extensions table
-my $global_table_name = "globals"; # name of the globals table
-my $extensions_conf = "/etc/asterisk/extensions.conf"; # path to extensions.conf
-# WARNING: this file will be substituted by the output of this program
-my $dbbrand = "Pg"; # Hint: "mysql" or any other Perl DBI driver.
-my $hostname = "localhost"; # The SQL server's hostname or IP
-my $database = "peter"; # the name of the database our tables are kept
-my $username = "peter"; # username to connect to the database
-my $password = ""; # password to connect to the database
-my $verbose = 1; # Verbosity Level (0 - 2)
-
-################### END OF CONFIGURATION #######################
-
-# You should not need to edit anything below here
-my $dbh;
-
-sub db_connect {
- if ($verbose > 1) { print "DEBUG: Connecting to Database Host: $hostname\n" }
- if ($hostname eq 'localhost') {
- if ($verbose > 1) { print "DEBUG: SQL server is on localhost so using UNIX socket instead of network socket.\n" }
- $dbh = DBI->connect("DBI:$dbbrand:dbname=$database", "$username", "$password")
- or die "Couldn't connect to database: " . DBI->errstr;
- }
- else {
- $dbh = DBI->connect("DBI:$dbbrand:dbname=$database;host=$hostname", "$username", "$password")
- or die "Couldn't connect to database: " . DBI->errstr;
- }
-}
-
-sub db_disconnect {
- if ($verbose > 1) { print "DEBUG: Disconnecting from Database Host: $hostname\n" }
- $dbh->disconnect
- or warn "Disconnection failed: $DBI::errstr\n";
-}
-
-sub get_globals {
- if ($verbose > 0) { print "Checking Database for [global] variables\n"; }
- my $sth = $dbh->prepare("SELECT variable, value FROM $global_table_name ORDER BY variable")
- or die "Couldn't prepare statement: " . $dbh->errstr;
-
- $sth->execute() # Execute the query
- or die "Couldn't execute SELECT statement: " . $sth->errstr;
-
- if ($sth->rows > 0) {
- print EXTEN "[globals]\n";
- while (my @global = $sth->fetchrow_array()) {
- print EXTEN "$global[0] = $global[1]\n";
- }
- print EXTEN "\n";
- } else {
- print "WARNING: You have no global variables set\n";
- }
- $sth->finish;
-}
-
-sub get_contexts {
- if ($verbose > 0) { print "Checking Database for contexts\n"; }
- my $sth = $dbh->prepare("SELECT context FROM $table_name GROUP BY context")
- or die "Couldn't prepare statement: " . $dbh->errstr;
-
- $sth->execute() # Execute the query
- or die "Couldn't execute SELECT statement: " . $sth->errstr;
-
- if ($sth->rows > 0) {
- while (my @context = $sth->fetchrow_array()) {
- print EXTEN "[$context[0]]\n";
- &get_extensions($context[0]);
- print EXTEN "\n";
- }
- print EXTEN "\n";
- } else {
- print "WARNING: You have no contexts defined in the $table_name table\n";
- }
- $sth->finish;
-}
-
-sub get_extensions {
- my $context = $_[0]; my @extension;
- if ($verbose > 0) { print " Checking Database for [$context] extensions\n"; }
- my $sth = $dbh->prepare("SELECT extension, priority, application, args, descr FROM $table_name WHERE context='$context' AND flags = '0' ORDER BY extension, priority")
- or die "Couldn't prepare statement: " . $dbh->errstr;
-
- $sth->execute() # Execute the query
- or die "Couldn't execute SELECT statement: " . $sth->errstr;
-
- if ($sth->rows > 0) {
- while (@extension = $sth->fetchrow_array()) {
- print EXTEN "exten => $extension[0],$extension[1],$extension[2]";
- print EXTEN "($extension[3])" if defined $extension[3];
- print EXTEN " ; $extension[4]" if defined $extension[4];
- print EXTEN "\n";
- }
- } else {
- print "WARNING: You have no extensions for [$context]\n";
- }
- $sth->finish;
-}
-
-
-sub main {
- open EXTEN, ">$extensions_conf" || die "Cannot create/overwrite extensions file: $extensions_conf\n";
- &db_connect;
- &get_globals;
- &get_contexts;
- &db_disconnect;
- close EXTEN; # Close the file handle
- if ($verbose > 0) { print "New $extensions_conf successfully written.\n"; }
- return 1;
-}
-
-
-exit &main();
diff --git a/1.2-netsec/contrib/scripts/retrieve_sip_conf_from_mysql.pl b/1.2-netsec/contrib/scripts/retrieve_sip_conf_from_mysql.pl
deleted file mode 100644
index 03395a125..000000000
--- a/1.2-netsec/contrib/scripts/retrieve_sip_conf_from_mysql.pl
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/usr/bin/perl -Tw
-# Retrieves the sip user/peer entries from the database
-# Use these commands to create the appropriate tables in MySQL
-#
-#CREATE TABLE sip (id INT(11) DEFAULT -1 NOT NULL,keyword VARCHAR(20) NOT NULL,data VARCHAR(50) NOT NULL, flags INT(1) DEFAULT 0 NOT NULL,PRIMARY KEY (id,keyword));
-#
-# if flags = 1 then the records are not included in the output file
-
-use DBI;
-################### BEGIN OF CONFIGURATION ####################
-
-# the name of the extensions table
-$table_name = "sip";
-# the path to the extensions.conf file
-# WARNING: this file will be substituted by the output of this program
-$sip_conf = "/etc/asterisk/sip_additional.conf";
-# the name of the box the MySQL database is running on
-$hostname = "localhost";
-# the name of the database our tables are kept
-$database = "sip";
-# username to connect to the database
-$username = "root";
-# password to connect to the database
-$password = "";
-
-################### END OF CONFIGURATION #######################
-
-$additional = "";
-
-open EXTEN, ">$sip_conf" || die "Cannot create/overwrite extensions file: $sip_conf\n";
-
-$dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password");
-$statement = "SELECT keyword,data from $table_name where id=0 and keyword <> 'account' and flags <> 1";
-my $result = $dbh->selectall_arrayref($statement);
-unless ($result) {
- # check for errors after every single database call
- print "dbh->selectall_arrayref($statement) failed!\n";
- print "DBI::err=[$DBI::err]\n";
- print "DBI::errstr=[$DBI::errstr]\n";
- exit;
-}
-my @resultSet = @{$result};
-if ( $#resultSet > -1 ) {
- foreach $row (@{ $result }) {
- my @result = @{ $row };
- $additional .= $result[0]."=".$result[1]."\n";
- }
-}
-
-$statement = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
-
-$result = $dbh->selectall_arrayref($statement);
-unless ($result) {
- # check for errors after every single database call
- print "dbh->selectall_arrayref($statement) failed!\n";
- print "DBI::err=[$DBI::err]\n";
- print "DBI::errstr=[$DBI::errstr]\n";
-}
-
-@resultSet = @{$result};
-if ( $#resultSet == -1 ) {
- print "No sip accounts defined in $table_name\n";
- exit;
-}
-
-foreach my $row ( @{ $result } ) {
- my $account = @{ $row }[0];
- my $id = @{ $row }[1];
- print EXTEN "[$account]\n";
- $statement = "SELECT keyword,data from $table_name where id=$id and keyword <> 'account' and flags <> 1 order by keyword";
- my $result = $dbh->selectall_arrayref($statement);
- unless ($result) {
- # check for errors after every single database call
- print "dbh->selectall_arrayref($statement) failed!\n";
- print "DBI::err=[$DBI::err]\n";
- print "DBI::errstr=[$DBI::errstr]\n";
- exit;
- }
-
- my @resSet = @{$result};
- if ( $#resSet == -1 ) {
- print "no results\n";
- exit;
- }
- foreach my $row ( @{ $result } ) {
- my @result = @{ $row };
- print EXTEN "$result[0]=$result[1]\n";
- }
- print EXTEN "$additional\n";
-}
-
-exit 0;
-
diff --git a/1.2-netsec/contrib/scripts/safe_asterisk b/1.2-netsec/contrib/scripts/safe_asterisk
deleted file mode 100644
index 2cfab55da..000000000
--- a/1.2-netsec/contrib/scripts/safe_asterisk
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/bin/sh
-CLIARGS="$*" # Grab any args passed to safe_asterisk
-TTY=9 # TTY (if you want one) for Asterisk to run on
-CONSOLE=yes # Whether or not you want a console
-#NOTIFY=ben@alkaloid.net # Who to notify about crashes
-MACHINE=`hostname` # To specify which machine has crashed when getting the mail
-DUMPDROP=/tmp
-ASTSBINDIR=__ASTERISK_SBIN_DIR__
-#
-# Don't fork when running "safely"
-#
-ASTARGS=""
-if [ "$TTY" != "" ]; then
- if [ -c /dev/tty${TTY} ]; then
- TTY=tty${TTY}
- elif [ -c /dev/vc/${TTY} ]; then
- TTY=vc/${TTY}
- else
- echo "Cannot find your TTY (${TTY})" >&2
- exit 1
- fi
- ASTARGS="${ASTARGS} -vvvg"
- if [ "$CONSOLE" != "no" ]; then
- ASTARGS="${ASTARGS} -c"
- fi
-fi
-if [ ! -w ${DUMPDROP} ]; then
- echo "Cannot write to ${DUMPDROP}" >&2
- exit 1
-fi
-
-#
-# Let Asterisk dump core
-#
-ulimit -c unlimited
-
-#launch_asterisk()
-#{
-#}
-
-run_asterisk()
-{
- while :; do
-
- if [ "$TTY" != "" ]; then
- cd /tmp
- stty sane < /dev/${TTY}
- ${ASTSBINDIR}/asterisk ${CLIARGS} ${ASTARGS} >& /dev/${TTY} < /dev/${TTY}
- else
- cd /tmp
- ${ASTSBINDIR}/asterisk ${CLIARGS} ${ASTARGS}
- fi
- EXITSTATUS=$?
- echo "Asterisk ended with exit status $EXITSTATUS"
- if [ "$EXITSTATUS" = "0" ]; then
- # Properly shutdown....
- echo "Asterisk shutdown normally."
- exit 0
- elif [ $EXITSTATUS -gt 128 ]; then
- let EXITSIGNAL=EXITSTATUS-128
- echo "Asterisk exited on signal $EXITSIGNAL."
- if [ "$NOTIFY" != "" ]; then
- echo "Asterisk on $MACHINE exited on signal $EXITSIGNAL. Might want to take a peek." | \
- mail -s "Asterisk Died" $NOTIFY
- fi
- if [ -f /tmp/core ]; then
- mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
- fi
- else
- if [ "${EXITSTATUS}" = "0" ]; then
- echo "Asterisk ended normally. Aborting."
- exit 0
- else
- echo "Asterisk died with code $EXITSTATUS."
- if [ -f /tmp/core ]; then
- mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
- fi
- fi
- fi
- echo "Automatically restarting Asterisk."
- sleep 4
- done
-}
-
-run_asterisk &
diff --git a/1.2-netsec/contrib/scripts/safe_asterisk.8 b/1.2-netsec/contrib/scripts/safe_asterisk.8
deleted file mode 100644
index 277fa5f8d..000000000
--- a/1.2-netsec/contrib/scripts/safe_asterisk.8
+++ /dev/null
@@ -1,62 +0,0 @@
-.TH SAFE_ASTERISK 8 "Jun 30th, 2005" "Asterisk" "Linux Programmer's Manual"
-.SH NAME
-.B safe_asterisk
-\(em A wrapper to run the asterisk executable in a loop
-.SH SYNOPSIS
-.PP
-.B safe_asterisk
-.I [ asterisk_params ]
-
-.SH DESCRIPTION
-.B safe_asterisk
-is a script that runs asterisk in a loop, which can be useful if you
-fear asterisk may crash.
-
-The script does not run in the background like a standard service. Rather,
-it runs in its own linux virtual console (9, by default).
-It also uses the option '-c' of asterisk(8) to avoid detaching asterisk
-from that terminal.
-
-safe_asterisk also runs asterisk with unlimited core file size, and thus
-asterisk will dump core in case of a crash.
-
-To get a "picture" of console 9, from another terminal (e.g: from a
-remote shell session) you can use:
-
- screendump 9
-
-The init script of the Debian package should be able to run safe_asterisk
-as the asterisk service, if so configured. See coments in
-/etc/default/asterisk
-
-.SH FILES
-.B /tmp
-.RS
-safe_asterisk runs in that directory, rather than in / as usual.
-.RE
-
-.B /tmp/core
-.RS
-If core files were generated there, they may be
-.RE
-
-.SH BUGS
-While showing the output on a console is useful, using screen(1) as
-the terminal may be better.
-
-The script does not read configuration from standard location under /etc
-
-It uses fixed locations under /tmp , and thus may be exposed to a
-symlink attacks.
-
-.SH SEE ALSO
-asterisk(8), screendump(9)
-
-.SH "AUTHOR"
-This manual page was written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
-Permission is granted to copy, distribute and/or modify this document under
-the terms of the GNU General Public License, Version 2 any
-later version published by the Free Software Foundation.
-
-On Debian systems, the complete text of the GNU General Public
-License can be found in /usr/share/common-licenses/GPL.
diff --git a/1.2-netsec/contrib/scripts/sip-friends.sql b/1.2-netsec/contrib/scripts/sip-friends.sql
deleted file mode 100644
index 15d7cb393..000000000
--- a/1.2-netsec/contrib/scripts/sip-friends.sql
+++ /dev/null
@@ -1,14 +0,0 @@
-#
-# Table structure for table `sipfriends`
-#
-
-CREATE TABLE `sipfriends` (
- `name` varchar(40) NOT NULL default '',
- `secret` varchar(40) NOT NULL default '',
- `context` varchar(40) NOT NULL default '',
- `username` varchar(40) default '',
- `ipaddr` varchar(20) NOT NULL default '',
- `port` int(6) NOT NULL default '0',
- `regseconds` int(11) NOT NULL default '0',
- PRIMARY KEY (`name`)
-) TYPE=MyISAM;
diff --git a/1.2-netsec/contrib/scripts/vmail.cgi b/1.2-netsec/contrib/scripts/vmail.cgi
deleted file mode 100644
index 4ac1c8579..000000000
--- a/1.2-netsec/contrib/scripts/vmail.cgi
+++ /dev/null
@@ -1,1099 +0,0 @@
-#!/usr/bin/perl
-#
-# Web based Voicemail for Asterisk
-#
-# Copyright (C) 2002, Linux Support Services, Inc.
-#
-# Distributed under the terms of the GNU General Public License
-#
-# Written by Mark Spencer <markster@linux-support.net>
-#
-# (icky, I know.... if you know better perl please help!)
-#
-#
-# Synchronization added by GDS Partners (www.gdspartners.com)
-# Stojan Sljivic (stojan.sljivic@gdspartners.com)
-#
-use CGI qw/:standard/;
-use Carp::Heavy;
-use CGI::Carp qw(fatalsToBrowser);
-use DBI;
-use Fcntl qw ( O_WRONLY O_CREAT O_EXCL );
-use Time::HiRes qw ( usleep );
-
-$context=""; # Define here your by default context (so you dont need to put voicemail@context in the login
-
-@validfolders = ( "INBOX", "Old", "Work", "Family", "Friends", "Cust1", "Cust2", "Cust3", "Cust4", "Cust5" );
-
-%formats = (
- "wav" => {
- name => "Uncompressed WAV",
- mime => "audio/x-wav",
- pref => 1
- },
- "WAV" => {
- name => "GSM Compressed WAV",
- mime => "audio/x-wav",
- pref => 2
- },
- "gsm" => {
- name => "Raw GSM Audio",
- mime => "audio/x-gsm",
- pref => 3
- }
-);
-
-$astpath = "/_asterisk";
-
-$stdcontainerstart = "<table align=center width=600><tr><td>\n";
-$footer = "<hr><font size=-1><a href=\"http://www.asterisk.org\">The Asterisk Open Source PBX</a> Copyright 2004, <a href=\"http://www.digium.com\">Digium, Inc.</a></a>";
-$stdcontainerend = "</td></tr><tr><td align=right>$footer</td></tr></table>\n";
-
-sub lock_path() {
-
- my($path) = @_;
- my $rand;
- my $rfile;
- my $start;
- my $res;
-
- $rand = rand 99999999;
- $rfile = "$path/.lock-$rand";
-
- sysopen(RFILE, $rfile, O_WRONLY | O_CREAT | O_EXCL, 0666) or return -1;
- close(RFILE);
-
- $res = link($rfile, "$path/.lock");
- $start = time;
- if ($res == 0) {
- while (($res == 0) && (time - $start <= 5)) {
- $res = link($rfile, "$path/.lock");
- usleep(1);
- }
- }
- unlink($rfile);
-
- if ($res == 0) {
- return -1;
- } else {
- return 0;
- }
-}
-
-sub unlock_path() {
-
- my($path) = @_;
-
- unlink("$path/.lock");
-}
-
-sub untaint() {
-
- my($data) = @_;
-
- if ($data =~ /^([-\@\w.]+)$/) {
- $data = $1;
- } else {
- die "Security violation.";
- }
-
- return $data;
-}
-
-sub login_screen() {
- print header;
- my ($message) = @_;
- print <<_EOH;
-
-<TITLE>Asterisk Web-Voicemail</TITLE>
-<BODY BGCOLOR="white">
-$stdcontainerstart
-<FORM METHOD="post">
-<input type=hidden name="action" value="login">
-<table align=center>
-<tr><td valign=top align=center rowspan=6><img align=center src="$astpath/animlogo.gif"></td></tr>
-<tr><td align=center colspan=2><font size=+2>Comedian Mail Login</font></td></tr>
-<tr><td align=center colspan=2><font size=+1>$message</font></td></tr>
-<tr><td>Mailbox:</td><td><input type=text name="mailbox"></td></tr>
-<tr><td>Password:</td><td><input type=password name="password"></td></tr>
-<tr><td align=right colspan=2><input value="Login" type=submit></td></tr>
-<input type=hidden name="context" value="$context">
-</table>
-</FORM>
-$stdcontainerend
-</BODY>\n
-_EOH
-
-}
-
-sub check_login()
-{
- local ($filename, $startcat) = @_;
- local ($mbox, $context) = split(/\@/, param('mailbox'));
- local $pass = param('password');
- local $category = $startcat;
- local @fields;
- local $tmp;
- local (*VMAIL);
- if (!$category) {
- $category = "general";
- }
- if (!$context) {
- $context = param('context');
- }
- if (!$context) {
- $context = "default";
- }
- if (!$filename) {
- $filename = "/etc/asterisk/voicemail.conf";
- }
-# print header;
-# print "Including <h2>$filename</h2> while in <h2>$category</h2>...\n";
- open(VMAIL, "<$filename") || die("Bleh, no $filename");
- while(<VMAIL>) {
- chomp;
- if (/include\s\"([^\"]+)\"$/) {
- ($tmp, $category) = &check_login("/etc/asterisk/$1", $category);
- if (length($tmp)) {
-# print "Got '$tmp'\n";
- return ($tmp, $category);
- }
- } elsif (/\[(.*)\]/) {
- $category = $1;
- } elsif ($category eq "general") {
- if (/([^\s]+)\s*\=\s*(.*)/) {
- if ($1 eq "dbname") {
- $dbname = $2;
- } elsif ($1 eq "dbpass") {
- $dbpass = $2;
- } elsif ($1 eq "dbhost") {
- $dbhost = $2;
- } elsif ($1 eq "dbuser") {
- $dbuser = $2;
- }
- }
- if ($dbname and $dbpass and $dbhost and $dbuser) {
-
- # db variables are present. Use db for authentication.
- my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
- my $sth = $dbh->prepare(qq{select fullname,context from voicemail where mailbox='$mbox' and password='$pass' and context='$context'});
- $sth->execute();
- if (($fullname, $category) = $sth->fetchrow_array()) {;
- return ($fullname ? $fullname : "Extension $mbox in $context",$category);
- }
- }
- } elsif (($category ne "general") && ($category ne "zonemessages")) {
- if (/([^\s]+)\s*\=\>?\s*(.*)/) {
- @fields = split(/\,\s*/, $2);
-# print "<p>Mailbox is $1\n";
- if (($mbox eq $1) && (($pass eq $fields[0]) || ("-${pass}" eq $fields[0])) && ($context eq $category)) {
- return ($fields[1] ? $fields[1] : "Extension $mbox in $context", $category);
- }
- }
- }
- }
- close(VMAIL);
- return ("", $category);
-}
-
-sub validmailbox()
-{
- local ($context, $mbox, $filename, $startcat) = @_;
- local $category = $startcat;
- local @fields;
- local (*VMAIL);
- if (!$context) {
- $context = param('context');
- }
- if (!$context) {
- $context = "default";
- }
- if (!$filename) {
- $filename = "/etc/asterisk/voicemail.conf";
- }
- if (!$category) {
- $category = "general";
- }
- open(VMAIL, "<$filename") || die("Bleh, no $filename");
- while(<VMAIL>) {
- chomp;
- if (/include\s\"([^\"]+)\"$/) {
- ($tmp, $category) = &validmailbox($mbox, $context, "/etc/asterisk/$1");
- if ($tmp) {
- return ($tmp, $category);
- }
- } elsif (/\[(.*)\]/) {
- $category = $1;
- } elsif ($category eq "general") {
- if (/([^\s]+)\s*\=\s*(.*)/) {
- if ($1 eq "dbname") {
- $dbname = $2;
- } elsif ($1 eq "dbpass") {
- $dbpass = $2;
- } elsif ($1 eq "dbhost") {
- $dbhost = $2;
- } elsif ($1 eq "dbuser") {
- $dbuser = $2;
- }
- }
- if ($dbname and $dbpass and $dbhost and $dbuser) {
-
- # db variables are present. Use db for authentication.
- my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
- my $sth = $dbh->prepare(qq{select fullname,context from voicemail where mailbox='$mbox' and password='$pass' and context='$context'});
- $sth->execute();
- if (($fullname, $category) = $sth->fetchrow_array()) {;
- return ($fullname ? $fullname : "unknown", $category);
- }
- }
- } elsif (($category ne "general") && ($category ne "zonemessages") && ($category eq $context)) {
- if (/([^\s]+)\s*\=\>?\s*(.*)/) {
- @fields = split(/\,\s*/, $2);
- if (($mbox eq $1) && ($context eq $category)) {
- return ($fields[2] ? $fields[2] : "unknown", $category);
- }
- }
- }
- }
- return ("", $category);
-}
-
-sub mailbox_options()
-{
- local($context, $current, $filename, $category) = @_;
- local (*VMAIL);
- local $tmp2;
- local $tmp;
- if (!$filename) {
- $filename = "/etc/asterisk/voicemail.conf";
- }
- if (!$category) {
- $category = "general";
- }
-# print header;
-# print "Including <h2>$filename</h2> while in <h2>$category</h2>...\n";
- open(VMAIL, "<$filename") || die("Bleh, no voicemail.conf");
- while(<VMAIL>) {
- chomp;
- s/\;.*$//;
- if (/include\s\"([^\"]+)\"$/) {
- ($tmp2, $category) = &mailbox_options($context, $current, "/etc/asterisk/$1", $category);
-# print "Got '$tmp2'...\n";
- $tmp .= $tmp2;
- } elsif (/\[(.*)\]/) {
- $category = $1;
- } elsif ($category eq "general") {
- if (/([^\s]+)\s*\=\s*(.*)/) {
- if ($1 eq "dbname") {
- $dbname = $2;
- } elsif ($1 eq "dbpass") {
- $dbpass = $2;
- } elsif ($1 eq "dbhost") {
- $dbhost = $2;
- } elsif ($1 eq "dbuser") {
- $dbuser = $2;
- }
- }
- if ($dbname and $dbpass and $dbhost and $dbuser) {
-
- # db variables are present. Use db for authentication.
- my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
- my $sth = $dbh->prepare(qq{select mailbox,fullname,context from voicemail where context='$context' order by mailbox});
- $sth->execute();
- while (($mailbox, $fullname, $category) = $sth->fetchrow_array()) {
- $text = $mailbox;
- if ($fullname) {
- $text .= " (".$fullname.")";
- }
- if ($mailbox eq $current) {
- $tmp .= "<OPTION SELECTED>$text</OPTION>\n";
- } else {
- $tmp .= "<OPTION>$text</OPTION>\n";
- }
- }
- return ($tmp, $category);
- }
- } elsif (($category ne "general") && ($category ne "zonemessages")) {
- if (/([^\s]+)\s*\=\>?\s*(.*)/) {
- @fields = split(/\,\s*/, $2);
- $text = "$1";
- if ($fields[1]) {
- $text .= " ($fields[1])";
- }
- if ($1 eq $current) {
- $tmp .= "<OPTION SELECTED>$text</OPTION>\n";
- } else {
- $tmp .= "<OPTION>$text</OPTION>\n";
- }
-
- }
- }
- }
- close(VMAIL);
- return ($tmp, $category);
-}
-
-sub mailbox_list()
-{
- local ($name, $context, $current) = @_;
- local $tmp;
- local $text;
- local $tmp;
- local $opts;
- if (!$context) {
- $context = "default";
- }
- $tmp = "<SELECT name=\"$name\">\n";
- ($opts) = &mailbox_options($context, $current);
- $tmp .= $opts;
- $tmp .= "</SELECT>\n";
-
-}
-
-sub msgcount()
-{
- my ($context, $mailbox, $folder) = @_;
- my $path = "/var/spool/asterisk/voicemail/$context/$mailbox/$folder";
- if (opendir(DIR, $path)) {
- my @msgs = grep(/^msg....\.txt$/, readdir(DIR));
- closedir(DIR);
- return sprintf "%d", $#msgs + 1;
- }
- return "0";
-}
-
-sub msgcountstr()
-{
- my ($context, $mailbox, $folder) = @_;
- my $count = &msgcount($context, $mailbox, $folder);
- if ($count > 1) {
- "$count messages";
- } elsif ($count > 0) {
- "$count message";
- } else {
- "no messages";
- }
-}
-sub messages()
-{
- my ($context, $mailbox, $folder) = @_;
- my $path = "/var/spool/asterisk/voicemail/$context/$mailbox/$folder";
- if (opendir(DIR, $path)) {
- my @msgs = sort grep(/^msg....\.txt$/, readdir(DIR));
- closedir(DIR);
- return map { s/^msg(....)\.txt$/$1/; $_ } @msgs;
- }
- return ();
-}
-
-sub getcookie()
-{
- my ($var) = @_;
- return cookie($var);
-}
-
-sub makecookie()
-{
- my ($format) = @_;
- cookie(-name => "format", -value =>["$format"], -expires=>"+1y");
-}
-
-sub getfields()
-{
- my ($context, $mailbox, $folder, $msg) = @_;
- my $fields;
- if (open(MSG, "</var/spool/asterisk/voicemail/$context/$mailbox/$folder/msg${msg}.txt")) {
- while(<MSG>) {
- s/\#.*$//g;
- if (/^(\w+)\s*\=\s*(.*)$/) {
- $fields->{$1} = $2;
- }
- }
- close(MSG);
- $fields->{'msgid'} = $msg;
- } else { print "<BR>Unable to open '$msg' in '$mailbox', '$folder'\n<B>"; }
- $fields;
-}
-
-sub message_prefs()
-{
- my ($nextaction, $msgid) = @_;
- my $folder = param('folder');
- my $mbox = param('mailbox');
- my $context = param('context');
- my $passwd = param('password');
- my $format = param('format');
- if (!$format) {
- $format = &getcookie('format');
- }
- print header;
- print <<_EOH;
-
-<TITLE>Asterisk Web-Voicemail: Preferences</TITLE>
-<BODY BGCOLOR="white">
-$stdcontainerstart
-<FORM METHOD="post">
-<table width=100% align=center>
-<tr><td align=right colspan=3><font size=+2>Web Voicemail Preferences</font></td></tr>
-<tr><td align=left><font size=+1>Preferred&nbsp;Audio&nbsp;Format:</font></td><td colspan=2></td></tr>
-_EOH
-
-foreach $fmt (sort { $formats{$a}->{'pref'} <=> $formats{$b}->{'pref'} } keys %formats) {
- my $clicked = "checked" if $fmt eq $format;
- print "<tr><td></td><td align=left><input type=radio name=\"format\" $clicked value=\"$fmt\"></td><td width=100%>&nbsp;$formats{$fmt}->{name}</td></tr>\n";
-}
-
-print <<_EOH;
-<tr><td align=right colspan=3><input type=submit value="save settings..."></td></tr>
-</table>
-<input type=hidden name="action" value="$nextaction">
-<input type=hidden name="folder" value="$folder">
-<input type=hidden name="mailbox" value="$mbox">
-<input type=hidden name="context" value="$context">
-<input type=hidden name="password" value="$passwd">
-<input type=hidden name="msgid" value="$msgid">
-$stdcontainerend
-</BODY>\n
-_EOH
-
-}
-
-sub message_play()
-{
- my ($message, $msgid) = @_;
- my $folder = param('folder');
- my ($mbox, $context) = split(/\@/, param('mailbox'));
- my $passwd = param('password');
- my $format = param('format');
-
- my $fields;
- if (!$context) {
- $context = param('context');
- }
- if (!$context) {
- $context = "default";
- }
-
- my $folders = &folder_list('newfolder', $context, $mbox, $folder);
- my $mailboxes = &mailbox_list('forwardto', $context, $mbox);
- if (!$format) {
- $format = &getcookie('format');
- }
- if (!$format) {
- &message_prefs("play", $msgid);
- } else {
- print header(-cookie => &makecookie($format));
- $fields = &getfields($context, $mbox, $folder, $msgid);
- if (!$fields) {
- print "<BR>Bah!\n";
- return;
- }
- my $duration = $fields->{'duration'};
- if ($duration) {
- $duration = sprintf "%d:%02d", $duration/60, $duration % 60;
- } else {
- $duration = "<i>Unknown</i>";
- }
- print <<_EOH;
-
-<TITLE>Asterisk Web-Voicemail: $folder Message $msgid</TITLE>
-<BODY BGCOLOR="white">
-$stdcontainerstart
-<FORM METHOD="post">
-<table width=100% align=center>
-<tr><td align=right colspan=3><font size=+1>$folder Message $msgid</font></td></tr>
-_EOH
-
- print <<_EOH;
-<tr><td align=center colspan=3>
-<table>
- <tr><td colspan=2 align=center><font size=+1>$folder <b>$msgid</b></font></td></tr>
- <tr><td><b>Message:</b></td><td>$msgid</td></tr>\n
- <tr><td><b>Mailbox:</b></td><td>$mbox\@$context</td></tr>\n
- <tr><td><b>Folder:</b></td><td>$folder</td></tr>\n
- <tr><td><b>From:</b></td><td>$fields->{callerid}</td></tr>\n
- <tr><td><b>Duration:</b></td><td>$duration</td></tr>\n
- <tr><td><b>Original Date:</b></td><td>$fields->{origdate}</td></tr>\n
- <tr><td><b>Original Mailbox:</b></td><td>$fields->{origmailbox}</td></tr>\n
- <tr><td><b>Caller Channel:</b></td><td>$fields->{callerchan}</td></tr>\n
- <tr><td align=center colspan=2>
- <input name="action" type=submit value="index">&nbsp;
- <input name="action" type=submit value="delete ">&nbsp;
- <input name="action" type=submit value="forward to -> ">&nbsp;
- $mailboxes&nbsp;
- <input name="action" type=submit value="save to ->">
- $folders&nbsp;
- <input name="action" type=submit value="play ">
- <input name="action" type=submit value="download">
-</td></tr>
-<tr><td colspan=2 align=center>
-<embed width=400 height=40 src="vmail.cgi?action=audio&folder=$folder&mailbox=$mbox&context=$context&password=$passwd&msgid=$msgid&format=$format&dontcasheme=$$.$format" autostart=yes loop=false></embed>
-</td></tr></table>
-</td></tr>
-</table>
-<input type=hidden name="folder" value="$folder">
-<input type=hidden name="mailbox" value="$mbox">
-<input type=hidden name="context" value="$context">
-<input type=hidden name="password" value="$passwd">
-<input type=hidden name="msgid" value="$msgid">
-$stdcontainerend
-</BODY>\n
-_EOH
- }
-}
-
-sub message_audio()
-{
- my ($forcedownload) = @_;
- my $folder = &untaint(param('folder'));
- my $msgid = &untaint(param('msgid'));
- my $mailbox = &untaint(param('mailbox'));
- my $context = &untaint(param('context'));
- my $format = param('format');
- if (!$format) {
- $format = &getcookie('format');
- }
- &untaint($format);
-
- my $path = "/var/spool/asterisk/voicemail/$context/$mailbox/$folder/msg${msgid}.$format";
-
- $msgid =~ /^\d\d\d\d$/ || die("Msgid Liar ($msgid)!");
- grep(/^${format}$/, keys %formats) || die("Format Liar ($format)!");
-
- # Mailbox and folder are already verified
- if (open(AUDIO, "<$path")) {
- $size = -s $path;
- $|=1;
- if ($forcedownload) {
- print header(-type=>$formats{$format}->{'mime'}, -Content_length => $size, -attachment => "msg${msgid}.$format");
- } else {
- print header(-type=>$formats{$format}->{'mime'}, -Content_length => $size);
- }
-
- while(($amt = sysread(AUDIO, $data, 4096)) > 0) {
- syswrite(STDOUT, $data, $amt);
- }
- close(AUDIO);
- } else {
- die("Hrm, can't seem to open $path\n");
- }
-}
-
-sub message_index()
-{
- my ($folder, $message) = @_;
- my ($mbox, $context) = split(/\@/, param('mailbox'));
- my $passwd = param('password');
- my $message2;
- my $msgcount;
- my $hasmsg;
- my $newmessages, $oldmessages;
- my $format = param('format');
- if (!$format) {
- $format = &getcookie('format');
- }
- if (!$context) {
- $context = param('context');
- }
- if (!$context) {
- $context = "default";
- }
- if ($folder) {
- $msgcount = &msgcountstr($context, $mbox, $folder);
- $message2 = "&nbsp;&nbsp;&nbsp;Folder '$folder' has " . &msgcountstr($context, $mbox, $folder);
- } else {
- $newmessages = &msgcount($context, $mbox, "INBOX");
- $oldmessages = &msgcount($context, $mbox, "Old");
- if (($newmessages > 0) || ($oldmessages < 1)) {
- $folder = "INBOX";
- } else {
- $folder = "Old";
- }
- $message2 = "You have";
- if ($newmessages > 0) {
- $message2 .= " <b>$newmessages</b> NEW";
- if ($oldmessages > 0) {
- $message2 .= "and <b>$oldmessages</b> OLD";
- if ($oldmessages != 1) {
- $message2 .= " messages.";
- } else {
- $message2 .= "message.";
- }
- } else {
- if ($newmessages != 1) {
- $message2 .= " messages.";
- } else {
- $message2 .= " message.";
- }
- }
- } else {
- if ($oldmessages > 0) {
- $message2 .= " <b>$oldmessages</b> OLD";
- if ($oldmessages != 1) {
- $message2 .= " messages.";
- } else {
- $message2 .= " message.";
- }
- } else {
- $message2 .= " <b>no</b> messages.";
- }
- }
- }
-
- my $folders = &folder_list('newfolder', $context, $mbox, $folder);
- my $cfolders = &folder_list('changefolder', $context, $mbox, $folder);
- my $mailboxes = &mailbox_list('forwardto', $context, $mbox);
- print header(-cookie => &makecookie($format));
- print <<_EOH;
-
-<TITLE>Asterisk Web-Voicemail: $mbox\@$context $folder</TITLE>
-<BODY BGCOLOR="white">
-$stdcontainerstart
-<FORM METHOD="post">
-<table width=100% align=center>
-<tr><td align=center colspan=2><font size=+2><I>$message</I></font></td></tr>
-<tr><td align=right colspan=2><font size=+1><b>$folder</b> Messages</font> <input type=submit name="action" value="change to ->">$cfolders</td></tr>
-<tr><td align=left colspan=2><font size=+1>$message2</font></td></tr>
-</table>
-<table width=100% align=center cellpadding=0 cellspacing=0>
-_EOH
-
-print "<tr><td>&nbsp;Msg</td><td>&nbsp;From</td><td>&nbsp;Duration</td><td>&nbsp;Date</td><td>&nbsp;</td></tr>\n";
-print "<tr><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td></td></tr>\n";
-foreach $msg (&messages($context, $mbox, $folder)) {
-
- $fields = &getfields($context, $mbox, $folder, $msg);
- $duration = $fields->{'duration'};
- if ($duration) {
- $duration = sprintf "%d:%02d", $duration / 60, $duration % 60;
- } else {
- $duration = "<i>Unknown</i>";
- }
- $hasmsg++;
- print "<tr><td><input type=checkbox name=\"msgselect\" value=\"$msg\">&nbsp;<b>$msg</b></td><td>$fields->{'callerid'}</td><td>$duration</td><td>$fields->{'origdate'}</td><td><input name='play$msg' alt=\"Play message $msg\" border=0 type=image align=left src=\"$astpath/play.gif\"></td></tr>\n";
-
-}
-if (!$hasmsg) {
- print "<tr><td colspan=4 align=center><P><b><i>No messages</i></b><P></td></tr>";
-}
-
-print <<_EOH;
-</table>
-<table width=100% align=center>
-<tr><td align=right colspan=2>
- <input type="submit" name="action" value="refresh">&nbsp;
-_EOH
-
-if ($hasmsg) {
-print <<_EOH;
- <input type="submit" name="action" value="delete">&nbsp;
- <input type="submit" name="action" value="save to ->">
- $folders&nbsp;
- <input type="submit" name="action" value="forward to ->">
- $mailboxes
-_EOH
-}
-
-print <<_EOH;
-</td></tr>
-<tr><td align=right colspan=2>
- <input type="submit" name="action" value="preferences">
- <input type="submit" name="action" value="logout">
-</td></tr>
-</table>
-<input type=hidden name="folder" value="$folder">
-<input type=hidden name="mailbox" value="$mbox">
-<input type=hidden name="context" value="$context">
-<input type=hidden name="password" value="$passwd">
-</FORM>
-$stdcontainerend
-</BODY>\n
-_EOH
-}
-
-sub validfolder()
-{
- my ($folder) = @_;
- return grep(/^$folder$/, @validfolders);
-}
-
-sub folder_list()
-{
- my ($name, $context, $mbox, $selected) = @_;
- my $f;
- my $count;
- my $tmp = "<SELECT name=\"$name\">\n";
- foreach $f (@validfolders) {
- $count = &msgcount($context, $mbox, $f);
- if ($f eq $selected) {
- $tmp .= "<OPTION SELECTED>$f ($count)</OPTION>\n";
- } else {
- $tmp .= "<OPTION>$f ($count)</OPTION>\n";
- }
- }
- $tmp .= "</SELECT>";
-}
-
-sub message_rename()
-{
- my ($context, $mbox, $oldfolder, $old, $newfolder, $new) = @_;
- my $oldfile, $newfile;
- return if ($old eq $new) && ($oldfolder eq $newfolder);
-
- if ($context =~ /^(\w+)$/) {
- $context = $1;
- } else {
- die("Invalid Context<BR>\n");
- }
-
- if ($mbox =~ /^(\w+)$/) {
- $mbox = $1;
- } else {
- die ("Invalid mailbox<BR>\n");
- }
-
- if ($oldfolder =~ /^(\w+)$/) {
- $oldfolder = $1;
- } else {
- die("Invalid old folder<BR>\n");
- }
-
- if ($newfolder =~ /^(\w+)$/) {
- $newfolder = $1;
- } else {
- die("Invalid new folder ($newfolder)<BR>\n");
- }
-
- if ($old =~ /^(\d\d\d\d)$/) {
- $old = $1;
- } else {
- die("Invalid old Message<BR>\n");
- }
-
- if ($new =~ /^(\d\d\d\d)$/) {
- $new = $1;
- } else {
- die("Invalid old Message<BR>\n");
- }
-
- my $path = "/var/spool/asterisk/voicemail/$context/$mbox/$newfolder";
- $path =~ /^(.*)$/;
- $path = $1;
- mkdir $path, 0770;
- my $path = "/var/spool/asterisk/voicemail/$context/$mbox/$oldfolder";
- opendir(DIR, $path) || die("Unable to open directory\n");
- my @files = grep /^msg${old}\.\w+$/, readdir(DIR);
- closedir(DIR);
- foreach $oldfile (@files) {
- my $tmp = $oldfile;
- if ($tmp =~ /^(msg${old}.\w+)$/) {
- $tmp = $1;
- $oldfile = $path . "/$tmp";
- $tmp =~ s/msg${old}/msg${new}/;
- $newfile = "/var/spool/asterisk/voicemail/$context/$mbox/$newfolder/$tmp";
-# print "Renaming $oldfile to $newfile<BR>\n";
- rename($oldfile, $newfile);
- }
- }
-}
-
-sub file_copy()
-{
- my ($orig, $new) = @_;
- my $res;
- my $data;
- $orig =~ /^(.*)$/;
- $orig = $1;
- $new =~ /^(.*)$/;
- $new = $1;
- open(IN, "<$orig") || die("Unable to open '$orig'\n");
- open(OUT, ">$new") || DIE("Unable to open '$new'\n");
- while(($res = sysread(IN, $data, 4096)) > 0) {
- syswrite(OUT, $data, $res);
- }
- close(OUT);
- close(IN);
-}
-
-sub message_copy()
-{
- my ($context, $mbox, $newmbox, $oldfolder, $old, $new) = @_;
- my $oldfile, $newfile;
- return if ($mbox eq $newmbox);
-
- if ($mbox =~ /^(\w+)$/) {
- $mbox = $1;
- } else {
- die ("Invalid mailbox<BR>\n");
- }
-
- if ($newmbox =~ /^(\w+)$/) {
- $newmbox = $1;
- } else {
- die ("Invalid new mailbox<BR>\n");
- }
-
- if ($oldfolder =~ /^(\w+)$/) {
- $oldfolder = $1;
- } else {
- die("Invalid old folder<BR>\n");
- }
-
- if ($old =~ /^(\d\d\d\d)$/) {
- $old = $1;
- } else {
- die("Invalid old Message<BR>\n");
- }
-
- if ($new =~ /^(\d\d\d\d)$/) {
- $new = $1;
- } else {
- die("Invalid old Message<BR>\n");
- }
-
- my $path = "/var/spool/asterisk/voicemail/$context/$newmbox";
- $path =~ /^(.*)$/;
- $path = $1;
- mkdir $path, 0770;
- my $path = "/var/spool/asterisk/voicemail/$context/$newmbox/INBOX";
- $path =~ /^(.*)$/;
- $path = $1;
- mkdir $path, 0770;
- my $path = "/var/spool/asterisk/voicemail/$context/$mbox/$oldfolder";
- opendir(DIR, $path) || die("Unable to open directory\n");
- my @files = grep /^msg${old}\.\w+$/, readdir(DIR);
- closedir(DIR);
- foreach $oldfile (@files) {
- my $tmp = $oldfile;
- if ($tmp =~ /^(msg${old}.\w+)$/) {
- $tmp = $1;
- $oldfile = $path . "/$tmp";
- $tmp =~ s/msg${old}/msg${new}/;
- $newfile = "/var/spool/asterisk/voicemail/$context/$newmbox/INBOX/$tmp";
-# print "Copying $oldfile to $newfile<BR>\n";
- &file_copy($oldfile, $newfile);
- }
- }
-}
-
-sub message_delete()
-{
- my ($context, $mbox, $folder, $msg) = @_;
- if ($mbox =~ /^(\w+)$/) {
- $mbox = $1;
- } else {
- die ("Invalid mailbox<BR>\n");
- }
- if ($context =~ /^(\w+)$/) {
- $context = $1;
- } else {
- die ("Invalid context<BR>\n");
- }
- if ($folder =~ /^(\w+)$/) {
- $folder = $1;
- } else {
- die("Invalid folder<BR>\n");
- }
- if ($msg =~ /^(\d\d\d\d)$/) {
- $msg = $1;
- } else {
- die("Invalid Message<BR>\n");
- }
- my $path = "/var/spool/asterisk/voicemail/$context/$mbox/$folder";
- opendir(DIR, $path) || die("Unable to open directory\n");
- my @files = grep /^msg${msg}\.\w+$/, readdir(DIR);
- closedir(DIR);
- foreach $oldfile (@files) {
- if ($oldfile =~ /^(msg${msg}.\w+)$/) {
- $oldfile = $path . "/$1";
-# print "Deleting $oldfile<BR>\n";
- unlink($oldfile);
- }
- }
-}
-
-sub message_forward()
-{
- my ($toindex, @msgs) = @_;
- my $folder = param('folder');
- my ($mbox, $context) = split(/\@/, param('mailbox'));
- my $newmbox = param('forwardto');
- my $msg;
- my $msgcount;
- if (!$context) {
- $context = param('context');
- }
- if (!$context) {
- $context = "default";
- }
- $newmbox =~ s/(\w+)(\s+.*)?$/$1/;
- if (!&validmailbox($context, $newmbox)) {
- die("Bah! Not a valid mailbox '$newmbox'\n");
- return "";
- }
-
- my $txt;
- $context = &untaint($context);
- $newmbox = &untaint($newmbox);
- my $path = "/var/spool/asterisk/voicemail/$context/$newmbox/INBOX";
- if (&lock_path($path) == 0) {
- $msgcount = &msgcount($context, $newmbox, "INBOX");
-
- if ($newmbox ne $mbox) {
-# print header;
- foreach $msg (@msgs) {
-# print "Forwarding $msg from $mbox to $newmbox<BR>\n";
- &message_copy($context, $mbox, $newmbox, $folder, $msg, sprintf "%04d", $msgcount);
- $msgcount++;
- }
- $txt = "Forwarded messages " . join(', ', @msgs) . "to $newmbox";
- } else {
- $txt = "Can't forward messages to yourself!\n";
- }
- &unlock_path($path);
- } else {
- $txt = "Cannot forward messages: Unable to lock path.\n";
- }
- if ($toindex) {
- &message_index($folder, $txt);
- } else {
- &message_play($txt, $msgs[0]);
- }
-}
-
-sub message_delete_or_move()
-{
- my ($toindex, $del, @msgs) = @_;
- my $txt;
- my $path;
- my $y, $x;
- my $folder = param('folder');
- my $newfolder = param('newfolder') unless $del;
- $newfolder =~ s/^(\w+)\s+.*$/$1/;
- my ($mbox, $context) = split(/\@/, param('mailbox'));
- if (!$context) {
- $context = param('context');
- }
- if (!$context) {
- $context = "default";
- }
- my $passwd = param('password');
- $context = &untaint($context);
- $mbox = &untaint($mbox);
- $folder = &untaint($folder);
- my $path = "/var/spool/asterisk/voicemail/$context/$mbox/$folder";
- if (&lock_path($path) == 0) {
- my $msgcount = &msgcount($context, $mbox, $folder);
- my $omsgcount = &msgcount($context, $mbox, $newfolder) if $newfolder;
- # print header;
- if ($newfolder ne $folder) {
- $y = 0;
- for ($x=0;$x<$msgcount;$x++) {
- my $msg = sprintf "%04d", $x;
- my $newmsg = sprintf "%04d", $y;
- if (grep(/^$msg$/, @msgs)) {
- if ($newfolder) {
- &message_rename($context, $mbox, $folder, $msg, $newfolder, sprintf "%04d", $omsgcount);
- $omsgcount++;
- } else {
- &message_delete($context, $mbox, $folder, $msg);
- }
- } else {
- &message_rename($context, $mbox, $folder, $msg, $folder, $newmsg);
- $y++;
- }
- }
- if ($del) {
- $txt = "Deleted messages " . join (', ', @msgs);
- } else {
- $txt = "Moved messages " . join (', ', @msgs) . " to $newfolder";
- }
- } else {
- $txt = "Can't move a message to the same folder they're in already";
- }
- &unlock_path($path);
- } else {
- $txt = "Cannot move/delete messages: Unable to lock path.\n";
- }
- # Not as many messages now
- $msgcount--;
- if ($toindex || ($msgs[0] >= $msgcount)) {
- &message_index($folder, $txt);
- } else {
- &message_play($txt, $msgs[0]);
- }
-}
-
-if (param()) {
- my $folder = param('folder');
- my $changefolder = param('changefolder');
- $changefolder =~ s/(\w+)\s+.*$/$1/;
-
- my $newfolder = param('newfolder');
- $newfolder =~ s/^(\w+)\s+.*$/$1/;
- if ($newfolder && !&validfolder($newfolder)) {
- print header;
- die("Bah! new folder '$newfolder' isn't a folder.");
- }
- $action = param('action');
- $msgid = param('msgid');
- if (!$action) {
- my ($tmp) = grep /^play\d\d\d\d\.x$/, param;
- if ($tmp =~ /^play(\d\d\d\d)/) {
- $msgid = $1;
- $action = "play";
- } else {
- print header;
- print "No message?<BR>\n";
- return;
- }
- }
- @msgs = param('msgselect');
- @msgs = ($msgid) unless @msgs;
- {
- ($mailbox) = &check_login();
- if (length($mailbox)) {
- if ($action eq 'login') {
- &message_index($folder, "Welcome, $mailbox");
- } elsif (($action eq 'refresh') || ($action eq 'index')) {
- &message_index($folder, "Welcome, $mailbox");
- } elsif ($action eq 'change to ->') {
- if (&validfolder($changefolder)) {
- $folder = $changefolder;
- &message_index($folder, "Welcome, $mailbox");
- } else {
- die("Bah! Not a valid change to folder '$changefolder'\n");
- }
- } elsif ($action eq 'play') {
- &message_play("$mailbox $folder $msgid", $msgid);
- } elsif ($action eq 'preferences') {
- &message_prefs("refresh", $msgid);
- } elsif ($action eq 'download') {
- &message_audio(1);
- } elsif ($action eq 'play ') {
- &message_audio(0);
- } elsif ($action eq 'audio') {
- &message_audio(0);
- } elsif ($action eq 'delete') {
- &message_delete_or_move(1, 1, @msgs);
- } elsif ($action eq 'delete ') {
- &message_delete_or_move(0, 1, @msgs);
- } elsif ($action eq 'forward to ->') {
- &message_forward(1, @msgs);
- } elsif ($action eq 'forward to -> ') {
- &message_forward(0, @msgs);
- } elsif ($action eq 'save to ->') {
- &message_delete_or_move(1, 0, @msgs);
- } elsif ($action eq 'save to -> ') {
- &message_delete_or_move(0, 0, @msgs);
- } elsif ($action eq 'logout') {
- &login_screen("Logged out!\n");
- }
- } else {
- sleep(1);
- &login_screen("Login Incorrect!\n");
- }
- }
-} else {
- &login_screen("\&nbsp;");
-}
diff --git a/1.2-netsec/contrib/scripts/vmdb.sql b/1.2-netsec/contrib/scripts/vmdb.sql
deleted file mode 100644
index 59238c659..000000000
--- a/1.2-netsec/contrib/scripts/vmdb.sql
+++ /dev/null
@@ -1,11 +0,0 @@
-drop table if exists users;
-create table users (
-context VARCHAR(80) NOT NULL,
-mailbox VARCHAR(80) NOT NULL,
-password VARCHAR(80) NOT NULL DEFAULT '',
-fullname VARCHAR(80) NOT NULL DEFAULT '',
-email VARCHAR(80) NOT NULL DEFAULT '',
-pager VARCHAR(80) NOT NULL DEFAULT '',
-options VARCHAR(160) NOT NULL DEFAULT '',
-PRIMARY KEY (context, mailbox)
-);
diff --git a/1.2-netsec/contrib/thirdparty/spexxilbcfix_xlite.reg b/1.2-netsec/contrib/thirdparty/spexxilbcfix_xlite.reg
deleted file mode 100644
index 821fd5e2b..000000000
--- a/1.2-netsec/contrib/thirdparty/spexxilbcfix_xlite.reg
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/contrib/thirdparty/spexxilbcfix_xpro.reg b/1.2-netsec/contrib/thirdparty/spexxilbcfix_xpro.reg
deleted file mode 100644
index 472dcb44f..000000000
--- a/1.2-netsec/contrib/thirdparty/spexxilbcfix_xpro.reg
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/contrib/utils/README.rawplayer b/1.2-netsec/contrib/utils/README.rawplayer
deleted file mode 100644
index 146898a5c..000000000
--- a/1.2-netsec/contrib/utils/README.rawplayer
+++ /dev/null
@@ -1,37 +0,0 @@
-rawplayer is a simple C applet to stream raw music files in place of mpg123
-
-INSTALL
-
-compile the .c file and install:
-gcc -O2 rawplayer.c -o /usr/bin/rawplayer
-
-
-
-Converting MP3 to RAW
-
-Make track01.mp3 into track01.raw with sox (if compiled with mp3 support).
-sox -c 1 track01.mp3 -t raw -r 8000 -c 1 -s -w track01.raw
-
-Otherwise, use whatever app to turn track01.mp3 into track01.wav then use sox on the wav.
-sox -c 1 track01.wav -t raw -r 8000 -c 1 -s -w track01.raw
-
-
-Once you have the raw files put them in any dir on your system (eg /var/lib/asterisk/holdmusic_raw).
-and set up a class in musiconhold.conf like so:
-
-[classes]
-default => custom:/var/lib/asterisk/holdmusic_raw,/usr/bin/rawplayer
-
-
-This is the most efficient way to implement moh because no cpu usage is required to
-explode the very compressed mp3 data then downsample the music to the 8khz mono on the fly
-instead the data is already stored on the disk in the format that asterisk needs it to be
-and the player does little more than pick up frames from the file and hand them to right
-to the asterisk pipe where the audio is shared into all the channels who require it.
-
-
-If you have cpu to spare and want a simple mp3 solution consider the format_mp3 from
-asterisk-addons and the files based moh.
-
-
-
diff --git a/1.2-netsec/contrib/utils/rawplayer.c b/1.2-netsec/contrib/utils/rawplayer.c
deleted file mode 100644
index 61944a885..000000000
--- a/1.2-netsec/contrib/utils/rawplayer.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- Rawplayer.c simple raw file stdout player
- (c) Anthony C Minessale II <anthmct@yahoo.com>
-*/
-
-#define BUFLEN 320
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-static int deliver_file(char *path, int fdout) {
- int fd = 0, bytes = 0;
- short buf[BUFLEN];
-
- if ((fd = open(path,O_RDONLY))) {
- while ((bytes=read(fd, buf, BUFLEN))) {
- write(fdout, buf, bytes);
- }
- if(fd)
- close(fd);
- } else
- return -1;
-
- return 0;
-}
-
-
-int main(int argc, char *argv[]) {
- int x = 0, fdout = 0;
- fdout = fileno(stdout);
- for (;;)
- for (x = 1; x < argc ; x++) {
- if(deliver_file(argv[x], fdout))
- exit(1);
- }
-}
-
diff --git a/1.2-netsec/contrib/valgrind-RedHat-8.0.supp b/1.2-netsec/contrib/valgrind-RedHat-8.0.supp
deleted file mode 100644
index a404d43fa..000000000
--- a/1.2-netsec/contrib/valgrind-RedHat-8.0.supp
+++ /dev/null
@@ -1,41 +0,0 @@
-#This valgrind suppresion file is supposed to be working with
-#Red Hat Linux release 8.0 (Psyche)
-#You can use it by calling valgrind this way:
-#cd /usr/src/asterisk
-#valgrind --gdb-attach=yes --suppressions=valgrind-RedHat-8.0.supp asterisk -vvv
-
-{
- library_1
- PThread
- fun:pthread_error
- fun:__pthread_mutex_destroy
- obj:/lib/i686/libc-2.2.93.so
-}
-
-{
- library 2
- Cond
- fun:elf_dynamic_do_rel.7
- fun:_dl_relocate_object_internal
- obj:/lib/i686/libc-2.2.93.so
- fun:_dl_catch_error_internal
-}
-
-#==21922== Thread 16:
-#==21922== Syscall param ioctl(generic) contains uninitialised or
-#unaddressable byte(s)
-#==21922== at 0x420D3454: (within /lib/i686/libc-2.2.93.so)
-#==21922== by 0x8058D45: ast_call (channel.c:1356)
-#==21922== by 0x463027A7: ??? (app_dial.c:472)
-#==21922== by 0x805E2AE: pbx_exec (pbx.c:318)
-#==21922== Address 0x0 is not stack'd, malloc'd or free'd
-
-{
- ioctl(........,NULL);
- Param
- ioctl(generic)
- obj:/lib/i686/libc-2.2.93.so
- fun:ast_call
- fun:
- fun:pbx_exec
-}
diff --git a/1.2-netsec/cryptostub.c b/1.2-netsec/cryptostub.c
deleted file mode 100644
index 4d2809e0d..000000000
--- a/1.2-netsec/cryptostub.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#include <unistd.h>
-#include <stdlib.h>
-
-#include "asterisk/crypto.h"
-#include "asterisk/logger.h"
-
-/* Hrm, I wonder if the compiler is smart enough to only create two functions
- for all these... I could force it to only make two, but those would be some
- really nasty looking casts. */
-
-static struct ast_key *stub_ast_key_get(const char *kname, int ktype)
-{
- ast_log(LOG_NOTICE, "Crypto support not loaded!\n");
- return NULL;
-}
-
-static int stub_ast_check_signature(struct ast_key *key, const char *msg, const char *sig)
-{
- ast_log(LOG_NOTICE, "Crypto support not loaded!\n");
- return -1;
-}
-
-static int stub_ast_check_signature_bin(struct ast_key *key, const char *msg, int msglen, const unsigned char *sig)
-{
- ast_log(LOG_NOTICE, "Crypto support not loaded!\n");
- return -1;
-}
-
-static int stub_ast_sign(struct ast_key *key, char *msg, char *sig)
-{
- ast_log(LOG_NOTICE, "Crypto support not loaded!\n");
- return -1;
-}
-
-static int stub_ast_sign_bin(struct ast_key *key, const char *msg, int msglen, unsigned char *sig)
-{
- ast_log(LOG_NOTICE, "Crypto support not loaded!\n");
- return -1;
-}
-
-static int stub_ast_encdec_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key)
-{
- ast_log(LOG_NOTICE, "Crypto support not loaded!\n");
- return -1;
-}
-
-struct ast_key *(*ast_key_get)(const char *key, int type) =
- stub_ast_key_get;
-
-int (*ast_check_signature)(struct ast_key *key, const char *msg, const char *sig) =
- stub_ast_check_signature;
-
-int (*ast_check_signature_bin)(struct ast_key *key, const char *msg, int msglen, const unsigned char *sig) =
- stub_ast_check_signature_bin;
-
-int (*ast_sign)(struct ast_key *key, char *msg, char *sig) =
- stub_ast_sign;
-
-int (*ast_sign_bin)(struct ast_key *key, const char *msg, int msglen, unsigned char *sig) =
- stub_ast_sign_bin;
-
-int (*ast_encrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key) =
- stub_ast_encdec_bin;
-
-int (*ast_decrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key) =
- stub_ast_encdec_bin;
diff --git a/1.2-netsec/cygwin/Makefile b/1.2-netsec/cygwin/Makefile
deleted file mode 100644
index 124628f9c..000000000
--- a/1.2-netsec/cygwin/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-OBJS=cygloader.o
-all: $(OBJS)
-$(OBJS) : %.o: %.c
- $(CC) $< -o asterisk.exe
-clean:
- rm -f asterisk.exe
diff --git a/1.2-netsec/cygwin/cygloader.c b/1.2-netsec/cygwin/cygloader.c
deleted file mode 100644
index 0d48c0f6c..000000000
--- a/1.2-netsec/cygwin/cygloader.c
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <unistd.h>
-#include <dlfcn.h>
-#include <stdio.h>
-
-#define OK 0
-#define MODULE_NOT_FOUND 1
-#define INVALID_NUMBER_ARGUMENTS 2
-
-int main(int argc, char **argv) {
- /* Asterisk entry point */
- char* error = NULL;
- int (*ast_main)(int argc, char **argv);
-
- void *handle = dlopen ("asterisk.dll", RTLD_GLOBAL);
- if (handle == NULL) {
- fputs (dlerror(), stderr);
- fputs ("\r\n", stderr);
- return MODULE_NOT_FOUND;
- }
- printf("\r\nAsterisk module loaded successfully");
- ast_main = dlsym(handle, "main");
- if ((error = dlerror()) != NULL) {
- fputs("Asterisk main not found", stderr);
- fputs(error, stderr);
- exit(1);
- }
- printf("\r\nAsterisk entry point found");
- /* run asterisk main */
- (*ast_main)(argc, argv);
- dlclose(handle);
- printf("\r\nAsterisk stopped");
- return OK;
-}
diff --git a/1.2-netsec/db.c b/1.2-netsec/db.c
deleted file mode 100644
index 6d9e2b620..000000000
--- a/1.2-netsec/db.c
+++ /dev/null
@@ -1,597 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief ASTdb Management
- *
- *
- * DB3 is licensed under Sleepycat Public License and is thus incompatible
- * with GPL. To avoid having to make another exception (and complicate
- * licensing even further) we elect to use DB1 which is BSD licensed
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <dirent.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/app.h"
-#include "asterisk/dsp.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/astdb.h"
-#include "asterisk/cli.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-#include "asterisk/manager.h"
-#include "db1-ast/include/db.h"
-
-#ifdef __CYGWIN__
-#define dbopen __dbopen
-#endif
-
-static DB *astdb;
-AST_MUTEX_DEFINE_STATIC(dblock);
-
-static int dbinit(void)
-{
- if (!astdb) {
- if (!(astdb = dbopen((char *)ast_config_AST_DB, O_CREAT | O_RDWR, 0664, DB_BTREE, NULL))) {
- ast_log(LOG_WARNING, "Unable to open Asterisk database\n");
- }
- }
- if (astdb)
- return 0;
- return -1;
-}
-
-
-static inline int keymatch(const char *key, const char *prefix)
-{
- int preflen = strlen(prefix);
- if (!preflen)
- return 1;
- if (!strcasecmp(key, prefix))
- return 1;
- if ((strlen(key) > preflen) && !strncasecmp(key, prefix, preflen)) {
- if (key[preflen] == '/')
- return 1;
- }
- return 0;
-}
-
-static inline int subkeymatch(const char *key, const char *suffix)
-{
- int suffixlen = strlen(suffix);
- if (suffixlen) {
- const char *subkey = key + strlen(key) - suffixlen;
- if (subkey < key)
- return 0;
- if (!strcasecmp(subkey, suffix))
- return 1;
- }
- return 0;
-}
-
-int ast_db_deltree(const char *family, const char *keytree)
-{
- char prefix[256];
- DBT key, data;
- char *keys;
- int res;
- int pass;
-
- if (family) {
- if (keytree) {
- snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
- } else {
- snprintf(prefix, sizeof(prefix), "/%s", family);
- }
- } else if (keytree) {
- return -1;
- } else {
- prefix[0] = '\0';
- }
-
- ast_mutex_lock(&dblock);
- if (dbinit()) {
- ast_mutex_unlock(&dblock);
- return -1;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- pass = 0;
- while (!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
- if (key.size) {
- keys = key.data;
- keys[key.size - 1] = '\0';
- } else {
- keys = "<bad key>";
- }
- if (keymatch(keys, prefix)) {
- astdb->del(astdb, &key, 0);
- }
- }
- astdb->sync(astdb, 0);
- ast_mutex_unlock(&dblock);
- return 0;
-}
-
-int ast_db_put(const char *family, const char *keys, char *value)
-{
- char fullkey[256];
- DBT key, data;
- int res, fullkeylen;
-
- ast_mutex_lock(&dblock);
- if (dbinit()) {
- ast_mutex_unlock(&dblock);
- return -1;
- }
-
- fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = fullkey;
- key.size = fullkeylen + 1;
- data.data = value;
- data.size = strlen(value) + 1;
- res = astdb->put(astdb, &key, &data, 0);
- astdb->sync(astdb, 0);
- ast_mutex_unlock(&dblock);
- if (res)
- ast_log(LOG_WARNING, "Unable to put value '%s' for key '%s' in family '%s'\n", value, keys, family);
- return res;
-}
-
-int ast_db_get(const char *family, const char *keys, char *value, int valuelen)
-{
- char fullkey[256] = "";
- DBT key, data;
- int res, fullkeylen;
-
- ast_mutex_lock(&dblock);
- if (dbinit()) {
- ast_mutex_unlock(&dblock);
- return -1;
- }
-
- fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- memset(value, 0, valuelen);
- key.data = fullkey;
- key.size = fullkeylen + 1;
-
- res = astdb->get(astdb, &key, &data, 0);
-
- ast_mutex_unlock(&dblock);
-
- /* Be sure to NULL terminate our data either way */
- if (res) {
- ast_log(LOG_DEBUG, "Unable to find key '%s' in family '%s'\n", keys, family);
- } else {
-#if 0
- printf("Got value of size %d\n", data.size);
-#endif
- if (data.size) {
- ((char *)data.data)[data.size - 1] = '\0';
- /* Make sure that we don't write too much to the dst pointer or we don't read too much from the source pointer */
- strncpy(value, data.data, (valuelen > data.size) ? data.size : valuelen);
- value[valuelen - 1] = '\0';
- } else {
- ast_log(LOG_NOTICE, "Strange, empty value for /%s/%s\n", family, keys);
- }
- }
- return res;
-}
-
-int ast_db_del(const char *family, const char *keys)
-{
- char fullkey[256];
- DBT key;
- int res, fullkeylen;
-
- ast_mutex_lock(&dblock);
- if (dbinit()) {
- ast_mutex_unlock(&dblock);
- return -1;
- }
-
- fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
- memset(&key, 0, sizeof(key));
- key.data = fullkey;
- key.size = fullkeylen + 1;
-
- res = astdb->del(astdb, &key, 0);
- astdb->sync(astdb, 0);
-
- ast_mutex_unlock(&dblock);
-
- if (res)
- ast_log(LOG_DEBUG, "Unable to find key '%s' in family '%s'\n", keys, family);
- return res;
-}
-
-static int database_put(int fd, int argc, char *argv[])
-{
- int res;
- if (argc != 5)
- return RESULT_SHOWUSAGE;
- res = ast_db_put(argv[2], argv[3], argv[4]);
- if (res) {
- ast_cli(fd, "Failed to update entry\n");
- } else {
- ast_cli(fd, "Updated database successfully\n");
- }
- return RESULT_SUCCESS;
-}
-
-static int database_get(int fd, int argc, char *argv[])
-{
- int res;
- char tmp[256];
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- res = ast_db_get(argv[2], argv[3], tmp, sizeof(tmp));
- if (res) {
- ast_cli(fd, "Database entry not found.\n");
- } else {
- ast_cli(fd, "Value: %s\n", tmp);
- }
- return RESULT_SUCCESS;
-}
-
-static int database_del(int fd, int argc, char *argv[])
-{
- int res;
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- res = ast_db_del(argv[2], argv[3]);
- if (res) {
- ast_cli(fd, "Database entry does not exist.\n");
- } else {
- ast_cli(fd, "Database entry removed.\n");
- }
- return RESULT_SUCCESS;
-}
-
-static int database_deltree(int fd, int argc, char *argv[])
-{
- int res;
- if ((argc < 3) || (argc > 4))
- return RESULT_SHOWUSAGE;
- if (argc == 4) {
- res = ast_db_deltree(argv[2], argv[3]);
- } else {
- res = ast_db_deltree(argv[2], NULL);
- }
- if (res) {
- ast_cli(fd, "Database entries do not exist.\n");
- } else {
- ast_cli(fd, "Database entries removed.\n");
- }
- return RESULT_SUCCESS;
-}
-
-static int database_show(int fd, int argc, char *argv[])
-{
- char prefix[256];
- DBT key, data;
- char *keys, *values;
- int res;
- int pass;
-
- if (argc == 4) {
- /* Family and key tree */
- snprintf(prefix, sizeof(prefix), "/%s/%s", argv[2], argv[3]);
- } else if (argc == 3) {
- /* Family only */
- snprintf(prefix, sizeof(prefix), "/%s", argv[2]);
- } else if (argc == 2) {
- /* Neither */
- prefix[0] = '\0';
- } else {
- return RESULT_SHOWUSAGE;
- }
- ast_mutex_lock(&dblock);
- if (dbinit()) {
- ast_mutex_unlock(&dblock);
- ast_cli(fd, "Database unavailable\n");
- return RESULT_SUCCESS;
- }
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- pass = 0;
- while (!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
- if (key.size) {
- keys = key.data;
- keys[key.size - 1] = '\0';
- } else {
- keys = "<bad key>";
- }
- if (data.size) {
- values = data.data;
- values[data.size - 1]='\0';
- } else {
- values = "<bad value>";
- }
- if (keymatch(keys, prefix)) {
- ast_cli(fd, "%-50s: %-25s\n", keys, values);
- }
- }
- ast_mutex_unlock(&dblock);
- return RESULT_SUCCESS;
-}
-
-static int database_showkey(int fd, int argc, char *argv[])
-{
- char suffix[256];
- DBT key, data;
- char *keys, *values;
- int res;
- int pass;
-
- if (argc == 3) {
- /* Key only */
- snprintf(suffix, sizeof(suffix), "/%s", argv[2]);
- } else {
- return RESULT_SHOWUSAGE;
- }
- ast_mutex_lock(&dblock);
- if (dbinit()) {
- ast_mutex_unlock(&dblock);
- ast_cli(fd, "Database unavailable\n");
- return RESULT_SUCCESS;
- }
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- pass = 0;
- while (!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
- if (key.size) {
- keys = key.data;
- keys[key.size - 1] = '\0';
- } else {
- keys = "<bad key>";
- }
- if (data.size) {
- values = data.data;
- values[data.size - 1]='\0';
- } else {
- values = "<bad value>";
- }
- if (subkeymatch(keys, suffix)) {
- ast_cli(fd, "%-50s: %-25s\n", keys, values);
- }
- }
- ast_mutex_unlock(&dblock);
- return RESULT_SUCCESS;
-}
-
-struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree)
-{
- char prefix[256];
- DBT key, data;
- char *keys, *values;
- int res;
- int pass;
- struct ast_db_entry *last = NULL;
- struct ast_db_entry *cur, *ret=NULL;
-
- if (!ast_strlen_zero(family)) {
- if (!ast_strlen_zero(keytree)) {
- /* Family and key tree */
- snprintf(prefix, sizeof(prefix), "/%s/%s", family, prefix);
- } else {
- /* Family only */
- snprintf(prefix, sizeof(prefix), "/%s", family);
- }
- } else {
- prefix[0] = '\0';
- }
- ast_mutex_lock(&dblock);
- if (dbinit()) {
- ast_mutex_unlock(&dblock);
- ast_log(LOG_WARNING, "Database unavailable\n");
- return NULL;
- }
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- pass = 0;
- while (!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
- if (key.size) {
- keys = key.data;
- keys[key.size - 1] = '\0';
- } else {
- keys = "<bad key>";
- }
- if (data.size) {
- values = data.data;
- values[data.size - 1] = '\0';
- } else {
- values = "<bad value>";
- }
- if (keymatch(keys, prefix)) {
- cur = malloc(sizeof(struct ast_db_entry) + strlen(keys) + strlen(values) + 2);
- if (cur) {
- cur->next = NULL;
- cur->key = cur->data + strlen(values) + 1;
- strcpy(cur->data, values);
- strcpy(cur->key, keys);
- if (last) {
- last->next = cur;
- } else {
- ret = cur;
- }
- last = cur;
- }
- }
- }
- ast_mutex_unlock(&dblock);
- return ret;
-}
-
-void ast_db_freetree(struct ast_db_entry *dbe)
-{
- struct ast_db_entry *last;
- while (dbe) {
- last = dbe;
- dbe = dbe->next;
- free(last);
- }
-}
-
-static char database_show_usage[] =
-"Usage: database show [family [keytree]]\n"
-" Shows Asterisk database contents, optionally restricted\n"
-"to a given family, or family and keytree.\n";
-
-static char database_showkey_usage[] =
-"Usage: database showkey <keytree>\n"
-" Shows Asterisk database contents, restricted to a given key.\n";
-
-static char database_put_usage[] =
-"Usage: database put <family> <key> <value>\n"
-" Adds or updates an entry in the Asterisk database for\n"
-"a given family, key, and value.\n";
-
-static char database_get_usage[] =
-"Usage: database get <family> <key>\n"
-" Retrieves an entry in the Asterisk database for a given\n"
-"family and key.\n";
-
-static char database_del_usage[] =
-"Usage: database del <family> <key>\n"
-" Deletes an entry in the Asterisk database for a given\n"
-"family and key.\n";
-
-static char database_deltree_usage[] =
-"Usage: database deltree <family> [keytree]\n"
-" Deletes a family or specific keytree within a family\n"
-"in the Asterisk database.\n";
-
-struct ast_cli_entry cli_database_show =
-{ { "database", "show", NULL }, database_show, "Shows database contents", database_show_usage };
-
-struct ast_cli_entry cli_database_showkey =
-{ { "database", "showkey", NULL }, database_showkey, "Shows database contents", database_showkey_usage };
-
-struct ast_cli_entry cli_database_get =
-{ { "database", "get", NULL }, database_get, "Gets database value", database_get_usage };
-
-struct ast_cli_entry cli_database_put =
-{ { "database", "put", NULL }, database_put, "Adds/updates database value", database_put_usage };
-
-struct ast_cli_entry cli_database_del =
-{ { "database", "del", NULL }, database_del, "Removes database key/value", database_del_usage };
-
-struct ast_cli_entry cli_database_deltree =
-{ { "database", "deltree", NULL }, database_deltree, "Removes database keytree/values", database_deltree_usage };
-
-static int manager_dbput(struct mansession *s, struct message *m)
-{
- char *family = astman_get_header(m, "Family");
- char *key = astman_get_header(m, "Key");
- char *val = astman_get_header(m, "Val");
- int res;
-
- if (!strlen(family)) {
- astman_send_error(s, m, "No family specified");
- return 0;
- }
- if (!strlen(key)) {
- astman_send_error(s, m, "No key specified");
- return 0;
- }
- if (!strlen(val)) {
- astman_send_error(s, m, "No val specified");
- return 0;
- }
-
- res = ast_db_put(family, key, val);
- if (res) {
- astman_send_error(s, m, "Failed to update entry");
- } else {
- astman_send_ack(s, m, "Updated database successfully");
- }
- return 0;
-}
-
-static int manager_dbget(struct mansession *s, struct message *m)
-{
- char *id = astman_get_header(m,"ActionID");
- char idText[256] = "";
- char *family = astman_get_header(m, "Family");
- char *key = astman_get_header(m, "Key");
- char tmp[256];
- int res;
-
- if (!strlen(family)) {
- astman_send_error(s, m, "No family specified.");
- return 0;
- }
- if (!strlen(key)) {
- astman_send_error(s, m, "No key specified.");
- return 0;
- }
-
- if (!ast_strlen_zero(id))
- snprintf(idText, sizeof(idText) ,"ActionID: %s\r\n", id);
-
- res = ast_db_get(family, key, tmp, sizeof(tmp));
- if (res) {
- astman_send_error(s, m, "Database entry not found");
- } else {
- astman_send_ack(s, m, "Result will follow");
- ast_cli(s->fd, "Event: DBGetResponse\r\n"
- "Family: %s\r\n"
- "Key: %s\r\n"
- "Val: %s\r\n"
- "%s"
- "\r\n",
- family, key, tmp, idText);
- }
- return 0;
-}
-
-int astdb_init(void)
-{
- dbinit();
- ast_cli_register(&cli_database_show);
- ast_cli_register(&cli_database_showkey);
- ast_cli_register(&cli_database_get);
- ast_cli_register(&cli_database_put);
- ast_cli_register(&cli_database_del);
- ast_cli_register(&cli_database_deltree);
- ast_manager_register("DBGet", EVENT_FLAG_SYSTEM, manager_dbget, "Get DB Entry");
- ast_manager_register("DBPut", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry");
- return 0;
-}
diff --git a/1.2-netsec/db1-ast/Makefile b/1.2-netsec/db1-ast/Makefile
deleted file mode 100644
index 0aa9fdb02..000000000
--- a/1.2-netsec/db1-ast/Makefile
+++ /dev/null
@@ -1,77 +0,0 @@
-# @(#)Makefile 8.9 (Berkeley) 7/14/94
-
-LIBDB= libdb1.a
-ARCH=$(shell uname -m)
-ifeq ($(ARCH),alpha)
-SOVER=2.1
-else
-SOVER=2
-endif
-#Added support for UltraSparc - Belgarath
-ifeq ($(ARCH),sparc64)
-PROC=ultrasparc
-CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
-endif
-
-LIBDBSO=libdb.so.$(SOVER)
-PROG= db_dump185
-OBJ1= hash.o hash_bigkey.o hash_buf.o hash_func.o hash_log2.o hash_page.o \
- ndbm.o
-OBJ2= bt_close.o bt_conv.o bt_debug.o bt_delete.o bt_get.o bt_open.o \
- bt_overflow.o bt_page.o bt_put.o bt_search.o bt_seq.o bt_split.o \
- bt_utils.o
-OBJ3= db.o
-OBJ4= mpool.o
-OBJ5= rec_close.o rec_delete.o rec_get.o rec_open.o rec_put.o rec_search.o \
- rec_seq.o rec_utils.o
-MISC=
-OBJS= $(OBJ1) $(OBJ2) $(OBJ3) $(OBJ4) $(OBJ5) $(MISC)
-SHOBJS= $(patsubst %.o,%.os,$(OBJS))
-
-all: $(LIBDB) #$(LIBDBSO) $(PROG)
-
-$(LIBDB): $(OBJS)
- rm -f $@
- ar cq $@ $(OBJS)
- ranlib $@
-
-$(LIBDBSO): $(SHOBJS)
- $(CC) -Wl,-O1 -Wl,--version-script=libdb.map -Wl,-soname=$(LIBDBSO) -shared -o $@ $^
- ln -sf $@ libdb.so
-
-$(PROG): db_dump185.o $(LIBDBSO)
- $(CC) -o $@ db_dump185.o -L. -ldb
-
-clean:
- rm -f $(LIBDB) $(LIBDBSO) $(OBJS) $(SHOBJS)
-
-OORG= -O2
-CL= $(CC) -Wall -c -D__DBINTERFACE_PRIVATE $(OORG) -I. -Iinclude
-
-OSTYPE=$(shell uname -s)
-ifeq ($(OSTYPE),SunOS)
-CL+=-I../include -I../include/solaris-compat -DSOLARIS
-endif
-
-db_dump185.o: db_dump185.c
- $(CL) -o $@ $<
-%.o: hash/%.c
- $(CL) -Ihash -o $@ $<
-%.os: hash/%.c
- $(CL) -Ihash -fPIC -o $@ $<
-%.o: btree/%.c
- $(CL) -Ibtree -o $@ $<
-%.os: btree/%.c
- $(CL) -Ibtree -fPIC -o $@ $<
-db.o: db/db.c
- $(CL) -o $@ $<
-db.os: db/db.c
- $(CL) -fPIC -o $@ $<
-mpool.o: mpool/mpool.c
- $(CL) -o $@ $<
-mpool.os: mpool/mpool.c
- $(CL) -fPIC -o $@ $<
-%.o: recno/%.c
- $(CL) -Irecno -o $@ $<
-%.os: recno/%.c
- $(CL) -Irecno -fPIC -o $@ $<
diff --git a/1.2-netsec/db1-ast/btree/bt_close.c b/1.2-netsec/db1-ast/btree/bt_close.c
deleted file mode 100644
index 27f9ab660..000000000
--- a/1.2-netsec/db1-ast/btree/bt_close.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_close.c 8.7 (Berkeley) 8/17/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <db.h>
-#include "btree.h"
-
-static int bt_meta __P((BTREE *));
-
-/*
- * BT_CLOSE -- Close a btree.
- *
- * Parameters:
- * dbp: pointer to access method
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__bt_close(dbp)
- DB *dbp;
-{
- BTREE *t;
- int fd;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /* Sync the tree. */
- if (__bt_sync(dbp, 0) == RET_ERROR)
- return (RET_ERROR);
-
- /* Close the memory pool. */
- if (mpool_close(t->bt_mp) == RET_ERROR)
- return (RET_ERROR);
-
- /* Free random memory. */
- if (t->bt_cursor.key.data != NULL) {
- free(t->bt_cursor.key.data);
- t->bt_cursor.key.size = 0;
- t->bt_cursor.key.data = NULL;
- }
- if (t->bt_rkey.data) {
- free(t->bt_rkey.data);
- t->bt_rkey.size = 0;
- t->bt_rkey.data = NULL;
- }
- if (t->bt_rdata.data) {
- free(t->bt_rdata.data);
- t->bt_rdata.size = 0;
- t->bt_rdata.data = NULL;
- }
-
- fd = t->bt_fd;
- free(t);
- free(dbp);
- return (close(fd) ? RET_ERROR : RET_SUCCESS);
-}
-
-/*
- * BT_SYNC -- sync the btree to disk.
- *
- * Parameters:
- * dbp: pointer to access method
- *
- * Returns:
- * RET_SUCCESS, RET_ERROR.
- */
-int
-__bt_sync(dbp, flags)
- const DB *dbp;
- u_int flags;
-{
- BTREE *t;
- int status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /* Sync doesn't currently take any flags. */
- if (flags != 0) {
- errno = EINVAL;
- return (RET_ERROR);
- }
-
- if (F_ISSET(t, B_INMEM | B_RDONLY) || !F_ISSET(t, B_MODIFIED))
- return (RET_SUCCESS);
-
- if (F_ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR)
- return (RET_ERROR);
-
- if ((status = mpool_sync(t->bt_mp)) == RET_SUCCESS)
- F_CLR(t, B_MODIFIED);
-
- return (status);
-}
-
-/*
- * BT_META -- write the tree meta data to disk.
- *
- * Parameters:
- * t: tree
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-static int
-bt_meta(t)
- BTREE *t;
-{
- BTMETA m;
- void *p;
-
- if ((p = mpool_get(t->bt_mp, P_META, 0)) == NULL)
- return (RET_ERROR);
-
- /* Fill in metadata. */
- m.magic = BTREEMAGIC;
- m.version = BTREEVERSION;
- m.psize = t->bt_psize;
- m.free = t->bt_free;
- m.nrecs = t->bt_nrecs;
- m.flags = F_ISSET(t, SAVEMETA);
-
- memmove(p, &m, sizeof(BTMETA));
- mpool_put(t->bt_mp, p, MPOOL_DIRTY);
- return (RET_SUCCESS);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_conv.c b/1.2-netsec/db1-ast/btree/bt_conv.c
deleted file mode 100644
index 1cb208b14..000000000
--- a/1.2-netsec/db1-ast/btree/bt_conv.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_conv.c 8.5 (Berkeley) 8/17/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
-
-#include <stdio.h>
-
-#include <db.h>
-#include "btree.h"
-
-static void mswap __P((PAGE *));
-
-/*
- * __BT_BPGIN, __BT_BPGOUT --
- * Convert host-specific number layout to/from the host-independent
- * format stored on disk.
- *
- * Parameters:
- * t: tree
- * pg: page number
- * h: page to convert
- */
-void
-__bt_pgin(t, pg, pp)
- void *t;
- pgno_t pg;
- void *pp;
-{
- PAGE *h;
- indx_t i, top;
- u_char flags;
- char *p;
-
- if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
- return;
- if (pg == P_META) {
- mswap(pp);
- return;
- }
-
- h = pp;
- M_32_SWAP(h->pgno);
- M_32_SWAP(h->prevpg);
- M_32_SWAP(h->nextpg);
- M_32_SWAP(h->flags);
- M_16_SWAP(h->lower);
- M_16_SWAP(h->upper);
-
- top = NEXTINDEX(h);
- if ((h->flags & P_TYPE) == P_BINTERNAL)
- for (i = 0; i < top; i++) {
- M_16_SWAP(h->linp[i]);
- p = (char *)GETBINTERNAL(h, i);
- P_32_SWAP(p);
- p += sizeof(u_int32_t);
- P_32_SWAP(p);
- p += sizeof(pgno_t);
- if (*(u_char *)p & P_BIGKEY) {
- p += sizeof(u_char);
- P_32_SWAP(p);
- p += sizeof(pgno_t);
- P_32_SWAP(p);
- }
- }
- else if ((h->flags & P_TYPE) == P_BLEAF)
- for (i = 0; i < top; i++) {
- M_16_SWAP(h->linp[i]);
- p = (char *)GETBLEAF(h, i);
- P_32_SWAP(p);
- p += sizeof(u_int32_t);
- P_32_SWAP(p);
- p += sizeof(u_int32_t);
- flags = *(u_char *)p;
- if (flags & (P_BIGKEY | P_BIGDATA)) {
- p += sizeof(u_char);
- if (flags & P_BIGKEY) {
- P_32_SWAP(p);
- p += sizeof(pgno_t);
- P_32_SWAP(p);
- }
- if (flags & P_BIGDATA) {
- p += sizeof(u_int32_t);
- P_32_SWAP(p);
- p += sizeof(pgno_t);
- P_32_SWAP(p);
- }
- }
- }
-}
-
-void
-__bt_pgout(t, pg, pp)
- void *t;
- pgno_t pg;
- void *pp;
-{
- PAGE *h;
- indx_t i, top;
- u_char flags;
- char *p;
-
- if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
- return;
- if (pg == P_META) {
- mswap(pp);
- return;
- }
-
- h = pp;
- top = NEXTINDEX(h);
- if ((h->flags & P_TYPE) == P_BINTERNAL)
- for (i = 0; i < top; i++) {
- p = (char *)GETBINTERNAL(h, i);
- P_32_SWAP(p);
- p += sizeof(u_int32_t);
- P_32_SWAP(p);
- p += sizeof(pgno_t);
- if (*(u_char *)p & P_BIGKEY) {
- p += sizeof(u_char);
- P_32_SWAP(p);
- p += sizeof(pgno_t);
- P_32_SWAP(p);
- }
- M_16_SWAP(h->linp[i]);
- }
- else if ((h->flags & P_TYPE) == P_BLEAF)
- for (i = 0; i < top; i++) {
- p = (char *)GETBLEAF(h, i);
- P_32_SWAP(p);
- p += sizeof(u_int32_t);
- P_32_SWAP(p);
- p += sizeof(u_int32_t);
- flags = *(u_char *)p;
- if (flags & (P_BIGKEY | P_BIGDATA)) {
- p += sizeof(u_char);
- if (flags & P_BIGKEY) {
- P_32_SWAP(p);
- p += sizeof(pgno_t);
- P_32_SWAP(p);
- }
- if (flags & P_BIGDATA) {
- p += sizeof(u_int32_t);
- P_32_SWAP(p);
- p += sizeof(pgno_t);
- P_32_SWAP(p);
- }
- }
- M_16_SWAP(h->linp[i]);
- }
-
- M_32_SWAP(h->pgno);
- M_32_SWAP(h->prevpg);
- M_32_SWAP(h->nextpg);
- M_32_SWAP(h->flags);
- M_16_SWAP(h->lower);
- M_16_SWAP(h->upper);
-}
-
-/*
- * MSWAP -- Actually swap the bytes on the meta page.
- *
- * Parameters:
- * p: page to convert
- */
-static void
-mswap(pg)
- PAGE *pg;
-{
- char *p;
-
- p = (char *)pg;
- P_32_SWAP(p); /* magic */
- p += sizeof(u_int32_t);
- P_32_SWAP(p); /* version */
- p += sizeof(u_int32_t);
- P_32_SWAP(p); /* psize */
- p += sizeof(u_int32_t);
- P_32_SWAP(p); /* free */
- p += sizeof(u_int32_t);
- P_32_SWAP(p); /* nrecs */
- p += sizeof(u_int32_t);
- P_32_SWAP(p); /* flags */
- p += sizeof(u_int32_t);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_debug.c b/1.2-netsec/db1-ast/btree/bt_debug.c
deleted file mode 100644
index 443f2bf99..000000000
--- a/1.2-netsec/db1-ast/btree/bt_debug.c
+++ /dev/null
@@ -1,329 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_debug.c 8.5 (Berkeley) 8/17/94";
-#endif /* LIBC_SCCS and not lint */
-
-#ifdef DEBUG
-#include <sys/param.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <db.h>
-#include "btree.h"
-
-/*
- * BT_DUMP -- Dump the tree
- *
- * Parameters:
- * dbp: pointer to the DB
- */
-void
-__bt_dump(dbp)
- DB *dbp;
-{
- BTREE *t;
- PAGE *h;
- pgno_t i;
- char *sep;
-
- t = dbp->internal;
- (void)fprintf(stderr, "%s: pgsz %d",
- F_ISSET(t, B_INMEM) ? "memory" : "disk", t->bt_psize);
- if (F_ISSET(t, R_RECNO))
- (void)fprintf(stderr, " keys %lu", t->bt_nrecs);
-#undef X
-#define X(flag, name) \
- if (F_ISSET(t, flag)) { \
- (void)fprintf(stderr, "%s%s", sep, name); \
- sep = ", "; \
- }
- if (t->flags != 0) {
- sep = " flags (";
- X(R_FIXLEN, "FIXLEN");
- X(B_INMEM, "INMEM");
- X(B_NODUPS, "NODUPS");
- X(B_RDONLY, "RDONLY");
- X(R_RECNO, "RECNO");
- X(B_METADIRTY,"METADIRTY");
- (void)fprintf(stderr, ")\n");
- }
-#undef X
-
- for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) {
- __bt_dpage(h);
- (void)mpool_put(t->bt_mp, h, 0);
- }
-}
-
-/*
- * BT_DMPAGE -- Dump the meta page
- *
- * Parameters:
- * h: pointer to the PAGE
- */
-void
-__bt_dmpage(h)
- PAGE *h;
-{
- BTMETA *m;
- char *sep;
-
- m = (BTMETA *)h;
- (void)fprintf(stderr, "magic %lx\n", m->magic);
- (void)fprintf(stderr, "version %lu\n", m->version);
- (void)fprintf(stderr, "psize %lu\n", m->psize);
- (void)fprintf(stderr, "free %lu\n", m->free);
- (void)fprintf(stderr, "nrecs %lu\n", m->nrecs);
- (void)fprintf(stderr, "flags %lu", m->flags);
-#undef X
-#define X(flag, name) \
- if (m->flags & flag) { \
- (void)fprintf(stderr, "%s%s", sep, name); \
- sep = ", "; \
- }
- if (m->flags) {
- sep = " (";
- X(B_NODUPS, "NODUPS");
- X(R_RECNO, "RECNO");
- (void)fprintf(stderr, ")");
- }
-}
-
-/*
- * BT_DNPAGE -- Dump the page
- *
- * Parameters:
- * n: page number to dump.
- */
-void
-__bt_dnpage(dbp, pgno)
- DB *dbp;
- pgno_t pgno;
-{
- BTREE *t;
- PAGE *h;
-
- t = dbp->internal;
- if ((h = mpool_get(t->bt_mp, pgno, 0)) != NULL) {
- __bt_dpage(h);
- (void)mpool_put(t->bt_mp, h, 0);
- }
-}
-
-/*
- * BT_DPAGE -- Dump the page
- *
- * Parameters:
- * h: pointer to the PAGE
- */
-void
-__bt_dpage(h)
- PAGE *h;
-{
- BINTERNAL *bi;
- BLEAF *bl;
- RINTERNAL *ri;
- RLEAF *rl;
- indx_t cur, top;
- char *sep;
-
- (void)fprintf(stderr, " page %d: (", h->pgno);
-#undef X
-#define X(flag, name) \
- if (h->flags & flag) { \
- (void)fprintf(stderr, "%s%s", sep, name); \
- sep = ", "; \
- }
- sep = "";
- X(P_BINTERNAL, "BINTERNAL") /* types */
- X(P_BLEAF, "BLEAF")
- X(P_RINTERNAL, "RINTERNAL") /* types */
- X(P_RLEAF, "RLEAF")
- X(P_OVERFLOW, "OVERFLOW")
- X(P_PRESERVE, "PRESERVE");
- (void)fprintf(stderr, ")\n");
-#undef X
-
- (void)fprintf(stderr, "\tprev %2d next %2d", h->prevpg, h->nextpg);
- if (h->flags & P_OVERFLOW)
- return;
-
- top = NEXTINDEX(h);
- (void)fprintf(stderr, " lower %3d upper %3d nextind %d\n",
- h->lower, h->upper, top);
- for (cur = 0; cur < top; cur++) {
- (void)fprintf(stderr, "\t[%03d] %4d ", cur, h->linp[cur]);
- switch (h->flags & P_TYPE) {
- case P_BINTERNAL:
- bi = GETBINTERNAL(h, cur);
- (void)fprintf(stderr,
- "size %03d pgno %03d", bi->ksize, bi->pgno);
- if (bi->flags & P_BIGKEY)
- (void)fprintf(stderr, " (indirect)");
- else if (bi->ksize)
- (void)fprintf(stderr,
- " {%.*s}", (int)bi->ksize, bi->bytes);
- break;
- case P_RINTERNAL:
- ri = GETRINTERNAL(h, cur);
- (void)fprintf(stderr, "entries %03d pgno %03d",
- ri->nrecs, ri->pgno);
- break;
- case P_BLEAF:
- bl = GETBLEAF(h, cur);
- if (bl->flags & P_BIGKEY)
- (void)fprintf(stderr,
- "big key page %lu size %u/",
- *(pgno_t *)bl->bytes,
- *(u_int32_t *)(bl->bytes + sizeof(pgno_t)));
- else if (bl->ksize)
- (void)fprintf(stderr, "%s/", bl->bytes);
- if (bl->flags & P_BIGDATA)
- (void)fprintf(stderr,
- "big data page %lu size %u",
- *(pgno_t *)(bl->bytes + bl->ksize),
- *(u_int32_t *)(bl->bytes + bl->ksize +
- sizeof(pgno_t)));
- else if (bl->dsize)
- (void)fprintf(stderr, "%.*s",
- (int)bl->dsize, bl->bytes + bl->ksize);
- break;
- case P_RLEAF:
- rl = GETRLEAF(h, cur);
- if (rl->flags & P_BIGDATA)
- (void)fprintf(stderr,
- "big data page %lu size %u",
- *(pgno_t *)rl->bytes,
- *(u_int32_t *)(rl->bytes + sizeof(pgno_t)));
- else if (rl->dsize)
- (void)fprintf(stderr,
- "%.*s", (int)rl->dsize, rl->bytes);
- break;
- }
- (void)fprintf(stderr, "\n");
- }
-}
-#endif
-
-#ifdef STATISTICS
-/*
- * BT_STAT -- Gather/print the tree statistics
- *
- * Parameters:
- * dbp: pointer to the DB
- */
-void
-__bt_stat(dbp)
- DB *dbp;
-{
- extern u_long bt_cache_hit, bt_cache_miss, bt_pfxsaved, bt_rootsplit;
- extern u_long bt_sortsplit, bt_split;
- BTREE *t;
- PAGE *h;
- pgno_t i, pcont, pinternal, pleaf;
- u_long ifree, lfree, nkeys;
- int levels;
-
- t = dbp->internal;
- pcont = pinternal = pleaf = 0;
- nkeys = ifree = lfree = 0;
- for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) {
- switch (h->flags & P_TYPE) {
- case P_BINTERNAL:
- case P_RINTERNAL:
- ++pinternal;
- ifree += h->upper - h->lower;
- break;
- case P_BLEAF:
- case P_RLEAF:
- ++pleaf;
- lfree += h->upper - h->lower;
- nkeys += NEXTINDEX(h);
- break;
- case P_OVERFLOW:
- ++pcont;
- break;
- }
- (void)mpool_put(t->bt_mp, h, 0);
- }
-
- /* Count the levels of the tree. */
- for (i = P_ROOT, levels = 0 ;; ++levels) {
- h = mpool_get(t->bt_mp, i, 0);
- if (h->flags & (P_BLEAF|P_RLEAF)) {
- if (levels == 0)
- levels = 1;
- (void)mpool_put(t->bt_mp, h, 0);
- break;
- }
- i = F_ISSET(t, R_RECNO) ?
- GETRINTERNAL(h, 0)->pgno :
- GETBINTERNAL(h, 0)->pgno;
- (void)mpool_put(t->bt_mp, h, 0);
- }
-
- (void)fprintf(stderr, "%d level%s with %ld keys",
- levels, levels == 1 ? "" : "s", nkeys);
- if (F_ISSET(t, R_RECNO))
- (void)fprintf(stderr, " (%ld header count)", t->bt_nrecs);
- (void)fprintf(stderr,
- "\n%lu pages (leaf %ld, internal %ld, overflow %ld)\n",
- pinternal + pleaf + pcont, pleaf, pinternal, pcont);
- (void)fprintf(stderr, "%ld cache hits, %ld cache misses\n",
- bt_cache_hit, bt_cache_miss);
- (void)fprintf(stderr, "%ld splits (%ld root splits, %ld sort splits)\n",
- bt_split, bt_rootsplit, bt_sortsplit);
- pleaf *= t->bt_psize - BTDATAOFF;
- if (pleaf)
- (void)fprintf(stderr,
- "%.0f%% leaf fill (%ld bytes used, %ld bytes free)\n",
- ((double)(pleaf - lfree) / pleaf) * 100,
- pleaf - lfree, lfree);
- pinternal *= t->bt_psize - BTDATAOFF;
- if (pinternal)
- (void)fprintf(stderr,
- "%.0f%% internal fill (%ld bytes used, %ld bytes free\n",
- ((double)(pinternal - ifree) / pinternal) * 100,
- pinternal - ifree, ifree);
- if (bt_pfxsaved)
- (void)fprintf(stderr, "prefix checking removed %lu bytes.\n",
- bt_pfxsaved);
-}
-#endif
diff --git a/1.2-netsec/db1-ast/btree/bt_delete.c b/1.2-netsec/db1-ast/btree/bt_delete.c
deleted file mode 100644
index 9908a7c3e..000000000
--- a/1.2-netsec/db1-ast/btree/bt_delete.c
+++ /dev/null
@@ -1,657 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_delete.c 8.13 (Berkeley) 7/28/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <db.h>
-#include "btree.h"
-
-static int __bt_bdelete __P((BTREE *, const DBT *));
-static int __bt_curdel __P((BTREE *, const DBT *, PAGE *, u_int));
-static int __bt_pdelete __P((BTREE *, PAGE *));
-static int __bt_relink __P((BTREE *, PAGE *));
-static int __bt_stkacq __P((BTREE *, PAGE **, CURSOR *));
-
-/*
- * __bt_delete
- * Delete the item(s) referenced by a key.
- *
- * Return RET_SPECIAL if the key is not found.
- */
-int
-__bt_delete(dbp, key, flags)
- const DB *dbp;
- const DBT *key;
- u_int flags;
-{
- BTREE *t;
- CURSOR *c;
- PAGE *h;
- int status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /* Check for change to a read-only tree. */
- if (F_ISSET(t, B_RDONLY)) {
- errno = EPERM;
- return (RET_ERROR);
- }
-
- switch (flags) {
- case 0:
- status = __bt_bdelete(t, key);
- break;
- case R_CURSOR:
- /*
- * If flags is R_CURSOR, delete the cursor. Must already
- * have started a scan and not have already deleted it.
- */
- c = &t->bt_cursor;
- if (F_ISSET(c, CURS_INIT)) {
- if (F_ISSET(c, CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE))
- return (RET_SPECIAL);
- if ((h = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL)
- return (RET_ERROR);
-
- /*
- * If the page is about to be emptied, we'll need to
- * delete it, which means we have to acquire a stack.
- */
- if (NEXTINDEX(h) == 1)
- if (__bt_stkacq(t, &h, &t->bt_cursor))
- return (RET_ERROR);
-
- status = __bt_dleaf(t, NULL, h, c->pg.index);
-
- if (NEXTINDEX(h) == 0 && status == RET_SUCCESS) {
- if (__bt_pdelete(t, h))
- return (RET_ERROR);
- } else
- mpool_put(t->bt_mp,
- h, status == RET_SUCCESS ? MPOOL_DIRTY : 0);
- break;
- }
- /* FALLTHROUGH */
- default:
- errno = EINVAL;
- return (RET_ERROR);
- }
- if (status == RET_SUCCESS)
- F_SET(t, B_MODIFIED);
- return (status);
-}
-
-/*
- * __bt_stkacq --
- * Acquire a stack so we can delete a cursor entry.
- *
- * Parameters:
- * t: tree
- * hp: pointer to current, pinned PAGE pointer
- * c: pointer to the cursor
- *
- * Returns:
- * 0 on success, 1 on failure
- */
-static int
-__bt_stkacq(t, hp, c)
- BTREE *t;
- PAGE **hp;
- CURSOR *c;
-{
- BINTERNAL *bi;
- EPG *e;
- EPGNO *parent;
- PAGE *h;
- indx_t index = 0;
- pgno_t pgno;
- recno_t nextpg, prevpg;
- int exact, level;
-
- /*
- * Find the first occurrence of the key in the tree. Toss the
- * currently locked page so we don't hit an already-locked page.
- */
- h = *hp;
- mpool_put(t->bt_mp, h, 0);
- if ((e = __bt_search(t, &c->key, &exact)) == NULL)
- return (1);
- h = e->page;
-
- /* See if we got it in one shot. */
- if (h->pgno == c->pg.pgno)
- goto ret;
-
- /*
- * Move right, looking for the page. At each move we have to move
- * up the stack until we don't have to move to the next page. If
- * we have to change pages at an internal level, we have to fix the
- * stack back up.
- */
- while (h->pgno != c->pg.pgno) {
- if ((nextpg = h->nextpg) == P_INVALID)
- break;
- mpool_put(t->bt_mp, h, 0);
-
- /* Move up the stack. */
- for (level = 0; (parent = BT_POP(t)) != NULL; ++level) {
- /* Get the parent page. */
- if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL)
- return (1);
-
- /* Move to the next index. */
- if (parent->index != NEXTINDEX(h) - 1) {
- index = parent->index + 1;
- BT_PUSH(t, h->pgno, index);
- break;
- }
- mpool_put(t->bt_mp, h, 0);
- }
-
- /* Restore the stack. */
- while (level--) {
- /* Push the next level down onto the stack. */
- bi = GETBINTERNAL(h, index);
- pgno = bi->pgno;
- BT_PUSH(t, pgno, 0);
-
- /* Lose the currently pinned page. */
- mpool_put(t->bt_mp, h, 0);
-
- /* Get the next level down. */
- if ((h = mpool_get(t->bt_mp, pgno, 0)) == NULL)
- return (1);
- index = 0;
- }
- mpool_put(t->bt_mp, h, 0);
- if ((h = mpool_get(t->bt_mp, nextpg, 0)) == NULL)
- return (1);
- }
-
- if (h->pgno == c->pg.pgno)
- goto ret;
-
- /* Reacquire the original stack. */
- mpool_put(t->bt_mp, h, 0);
- if ((e = __bt_search(t, &c->key, &exact)) == NULL)
- return (1);
- h = e->page;
-
- /*
- * Move left, looking for the page. At each move we have to move
- * up the stack until we don't have to change pages to move to the
- * next page. If we have to change pages at an internal level, we
- * have to fix the stack back up.
- */
- while (h->pgno != c->pg.pgno) {
- if ((prevpg = h->prevpg) == P_INVALID)
- break;
- mpool_put(t->bt_mp, h, 0);
-
- /* Move up the stack. */
- for (level = 0; (parent = BT_POP(t)) != NULL; ++level) {
- /* Get the parent page. */
- if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL)
- return (1);
-
- /* Move to the next index. */
- if (parent->index != 0) {
- index = parent->index - 1;
- BT_PUSH(t, h->pgno, index);
- break;
- }
- mpool_put(t->bt_mp, h, 0);
- }
-
- /* Restore the stack. */
- while (level--) {
- /* Push the next level down onto the stack. */
- bi = GETBINTERNAL(h, index);
- pgno = bi->pgno;
-
- /* Lose the currently pinned page. */
- mpool_put(t->bt_mp, h, 0);
-
- /* Get the next level down. */
- if ((h = mpool_get(t->bt_mp, pgno, 0)) == NULL)
- return (1);
-
- index = NEXTINDEX(h) - 1;
- BT_PUSH(t, pgno, index);
- }
- mpool_put(t->bt_mp, h, 0);
- if ((h = mpool_get(t->bt_mp, prevpg, 0)) == NULL)
- return (1);
- }
-
-
-ret: mpool_put(t->bt_mp, h, 0);
- return ((*hp = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL);
-}
-
-/*
- * __bt_bdelete --
- * Delete all key/data pairs matching the specified key.
- *
- * Parameters:
- * t: tree
- * key: key to delete
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found.
- */
-static int
-__bt_bdelete(t, key)
- BTREE *t;
- const DBT *key;
-{
- EPG *e;
- PAGE *h;
- int deleted, exact, redo;
-
- deleted = 0;
-
- /* Find any matching record; __bt_search pins the page. */
-loop: if ((e = __bt_search(t, key, &exact)) == NULL)
- return (deleted ? RET_SUCCESS : RET_ERROR);
- if (!exact) {
- mpool_put(t->bt_mp, e->page, 0);
- return (deleted ? RET_SUCCESS : RET_SPECIAL);
- }
-
- /*
- * Delete forward, then delete backward, from the found key. If
- * there are duplicates and we reach either side of the page, do
- * the key search again, so that we get them all.
- */
- redo = 0;
- h = e->page;
- do {
- if (__bt_dleaf(t, key, h, e->index)) {
- mpool_put(t->bt_mp, h, 0);
- return (RET_ERROR);
- }
- if (F_ISSET(t, B_NODUPS)) {
- if (NEXTINDEX(h) == 0) {
- if (__bt_pdelete(t, h))
- return (RET_ERROR);
- } else
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- return (RET_SUCCESS);
- }
- deleted = 1;
- } while (e->index < NEXTINDEX(h) && __bt_cmp(t, key, e) == 0);
-
- /* Check for right-hand edge of the page. */
- if (e->index == NEXTINDEX(h))
- redo = 1;
-
- /* Delete from the key to the beginning of the page. */
- while (e->index-- > 0) {
- if (__bt_cmp(t, key, e) != 0)
- break;
- if (__bt_dleaf(t, key, h, e->index) == RET_ERROR) {
- mpool_put(t->bt_mp, h, 0);
- return (RET_ERROR);
- }
- if (e->index == 0)
- redo = 1;
- }
-
- /* Check for an empty page. */
- if (NEXTINDEX(h) == 0) {
- if (__bt_pdelete(t, h))
- return (RET_ERROR);
- goto loop;
- }
-
- /* Put the page. */
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
-
- if (redo)
- goto loop;
- return (RET_SUCCESS);
-}
-
-/*
- * __bt_pdelete --
- * Delete a single page from the tree.
- *
- * Parameters:
- * t: tree
- * h: leaf page
- *
- * Returns:
- * RET_SUCCESS, RET_ERROR.
- *
- * Side-effects:
- * mpool_put's the page
- */
-static int
-__bt_pdelete(t, h)
- BTREE *t;
- PAGE *h;
-{
- BINTERNAL *bi;
- PAGE *pg;
- EPGNO *parent;
- indx_t cnt, index, *ip, offset;
- u_int32_t nksize;
- char *from;
-
- /*
- * Walk the parent page stack -- a LIFO stack of the pages that were
- * traversed when we searched for the page where the delete occurred.
- * Each stack entry is a page number and a page index offset. The
- * offset is for the page traversed on the search. We've just deleted
- * a page, so we have to delete the key from the parent page.
- *
- * If the delete from the parent page makes it empty, this process may
- * continue all the way up the tree. We stop if we reach the root page
- * (which is never deleted, it's just not worth the effort) or if the
- * delete does not empty the page.
- */
- while ((parent = BT_POP(t)) != NULL) {
- /* Get the parent page. */
- if ((pg = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL)
- return (RET_ERROR);
-
- index = parent->index;
- bi = GETBINTERNAL(pg, index);
-
- /* Free any overflow pages. */
- if (bi->flags & P_BIGKEY &&
- __ovfl_delete(t, bi->bytes) == RET_ERROR) {
- mpool_put(t->bt_mp, pg, 0);
- return (RET_ERROR);
- }
-
- /*
- * Free the parent if it has only the one key and it's not the
- * root page. If it's the rootpage, turn it back into an empty
- * leaf page.
- */
- if (NEXTINDEX(pg) == 1) {
- if (pg->pgno == P_ROOT) {
- pg->lower = BTDATAOFF;
- pg->upper = t->bt_psize;
- pg->flags = P_BLEAF;
- } else {
- if (__bt_relink(t, pg) || __bt_free(t, pg))
- return (RET_ERROR);
- continue;
- }
- } else {
- /* Pack remaining key items at the end of the page. */
- nksize = NBINTERNAL(bi->ksize);
- from = (char *)pg + pg->upper;
- memmove(from + nksize, from, (char *)bi - from);
- pg->upper += nksize;
-
- /* Adjust indices' offsets, shift the indices down. */
- offset = pg->linp[index];
- for (cnt = index, ip = &pg->linp[0]; cnt--; ++ip)
- if (ip[0] < offset)
- ip[0] += nksize;
- for (cnt = NEXTINDEX(pg) - index; --cnt; ++ip)
- ip[0] = ip[1] < offset ? ip[1] + nksize : ip[1];
- pg->lower -= sizeof(indx_t);
- }
-
- mpool_put(t->bt_mp, pg, MPOOL_DIRTY);
- break;
- }
-
- /* Free the leaf page, as long as it wasn't the root. */
- if (h->pgno == P_ROOT) {
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- return (RET_SUCCESS);
- }
- return (__bt_relink(t, h) || __bt_free(t, h));
-}
-
-/*
- * __bt_dleaf --
- * Delete a single record from a leaf page.
- *
- * Parameters:
- * t: tree
- * key: referenced key
- * h: page
- * index: index on page to delete
- *
- * Returns:
- * RET_SUCCESS, RET_ERROR.
- */
-int
-__bt_dleaf(t, key, h, index)
- BTREE *t;
- const DBT *key;
- PAGE *h;
- u_int index;
-{
- BLEAF *bl;
- indx_t cnt, *ip, offset;
- u_int32_t nbytes;
- void *to;
- char *from;
-
- /* If this record is referenced by the cursor, delete the cursor. */
- if (F_ISSET(&t->bt_cursor, CURS_INIT) &&
- !F_ISSET(&t->bt_cursor, CURS_ACQUIRE) &&
- t->bt_cursor.pg.pgno == h->pgno && t->bt_cursor.pg.index == index &&
- __bt_curdel(t, key, h, index))
- return (RET_ERROR);
-
- /* If the entry uses overflow pages, make them available for reuse. */
- to = bl = GETBLEAF(h, index);
- if (bl->flags & P_BIGKEY && __ovfl_delete(t, bl->bytes) == RET_ERROR)
- return (RET_ERROR);
- if (bl->flags & P_BIGDATA &&
- __ovfl_delete(t, bl->bytes + bl->ksize) == RET_ERROR)
- return (RET_ERROR);
-
- /* Pack the remaining key/data items at the end of the page. */
- nbytes = NBLEAF(bl);
- from = (char *)h + h->upper;
- memmove(from + nbytes, from, (char *)to - from);
- h->upper += nbytes;
-
- /* Adjust the indices' offsets, shift the indices down. */
- offset = h->linp[index];
- for (cnt = index, ip = &h->linp[0]; cnt--; ++ip)
- if (ip[0] < offset)
- ip[0] += nbytes;
- for (cnt = NEXTINDEX(h) - index; --cnt; ++ip)
- ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1];
- h->lower -= sizeof(indx_t);
-
- /* If the cursor is on this page, adjust it as necessary. */
- if (F_ISSET(&t->bt_cursor, CURS_INIT) &&
- !F_ISSET(&t->bt_cursor, CURS_ACQUIRE) &&
- t->bt_cursor.pg.pgno == h->pgno && t->bt_cursor.pg.index > index)
- --t->bt_cursor.pg.index;
-
- return (RET_SUCCESS);
-}
-
-/*
- * __bt_curdel --
- * Delete the cursor.
- *
- * Parameters:
- * t: tree
- * key: referenced key (or NULL)
- * h: page
- * index: index on page to delete
- *
- * Returns:
- * RET_SUCCESS, RET_ERROR.
- */
-static int
-__bt_curdel(t, key, h, index)
- BTREE *t;
- const DBT *key;
- PAGE *h;
- u_int index;
-{
- CURSOR *c;
- EPG e;
- PAGE *pg;
- int curcopy, status;
-
- /*
- * If there are duplicates, move forward or backward to one.
- * Otherwise, copy the key into the cursor area.
- */
- c = &t->bt_cursor;
- F_CLR(c, CURS_AFTER | CURS_BEFORE | CURS_ACQUIRE);
-
- curcopy = 0;
- if (!F_ISSET(t, B_NODUPS)) {
- /*
- * We're going to have to do comparisons. If we weren't
- * provided a copy of the key, i.e. the user is deleting
- * the current cursor position, get one.
- */
- if (key == NULL) {
- e.page = h;
- e.index = index;
- if ((status = __bt_ret(t, &e,
- &c->key, &c->key, NULL, NULL, 1)) != RET_SUCCESS)
- return (status);
- curcopy = 1;
- key = &c->key;
- }
- /* Check previous key, if not at the beginning of the page. */
- if (index > 0) {
- e.page = h;
- e.index = index - 1;
- if (__bt_cmp(t, key, &e) == 0) {
- F_SET(c, CURS_BEFORE);
- goto dup2;
- }
- }
- /* Check next key, if not at the end of the page. */
- if (index < NEXTINDEX(h) - 1) {
- e.page = h;
- e.index = index + 1;
- if (__bt_cmp(t, key, &e) == 0) {
- F_SET(c, CURS_AFTER);
- goto dup2;
- }
- }
- /* Check previous key if at the beginning of the page. */
- if (index == 0 && h->prevpg != P_INVALID) {
- if ((pg = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL)
- return (RET_ERROR);
- e.page = pg;
- e.index = NEXTINDEX(pg) - 1;
- if (__bt_cmp(t, key, &e) == 0) {
- F_SET(c, CURS_BEFORE);
- goto dup1;
- }
- mpool_put(t->bt_mp, pg, 0);
- }
- /* Check next key if at the end of the page. */
- if (index == NEXTINDEX(h) - 1 && h->nextpg != P_INVALID) {
- if ((pg = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL)
- return (RET_ERROR);
- e.page = pg;
- e.index = 0;
- if (__bt_cmp(t, key, &e) == 0) {
- F_SET(c, CURS_AFTER);
-dup1: mpool_put(t->bt_mp, pg, 0);
-dup2: c->pg.pgno = e.page->pgno;
- c->pg.index = e.index;
- return (RET_SUCCESS);
- }
- mpool_put(t->bt_mp, pg, 0);
- }
- }
- e.page = h;
- e.index = index;
- if (curcopy || (status =
- __bt_ret(t, &e, &c->key, &c->key, NULL, NULL, 1)) == RET_SUCCESS) {
- F_SET(c, CURS_ACQUIRE);
- return (RET_SUCCESS);
- }
- return (status);
-}
-
-/*
- * __bt_relink --
- * Link around a deleted page.
- *
- * Parameters:
- * t: tree
- * h: page to be deleted
- */
-static int
-__bt_relink(t, h)
- BTREE *t;
- PAGE *h;
-{
- PAGE *pg;
-
- if (h->nextpg != P_INVALID) {
- if ((pg = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL)
- return (RET_ERROR);
- pg->prevpg = h->prevpg;
- mpool_put(t->bt_mp, pg, MPOOL_DIRTY);
- }
- if (h->prevpg != P_INVALID) {
- if ((pg = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL)
- return (RET_ERROR);
- pg->nextpg = h->nextpg;
- mpool_put(t->bt_mp, pg, MPOOL_DIRTY);
- }
- return (0);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_get.c b/1.2-netsec/db1-ast/btree/bt_get.c
deleted file mode 100644
index 74824c73f..000000000
--- a/1.2-netsec/db1-ast/btree/bt_get.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_get.c 8.6 (Berkeley) 7/20/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stddef.h>
-#include <stdio.h>
-
-#include <db.h>
-#include "btree.h"
-
-/*
- * __BT_GET -- Get a record from the btree.
- *
- * Parameters:
- * dbp: pointer to access method
- * key: key to find
- * data: data to return
- * flag: currently unused
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found.
- */
-int
-__bt_get(dbp, key, data, flags)
- const DB *dbp;
- const DBT *key;
- DBT *data;
- u_int flags;
-{
- BTREE *t;
- EPG *e;
- int exact, status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /* Get currently doesn't take any flags. */
- if (flags) {
- errno = EINVAL;
- return (RET_ERROR);
- }
-
- if ((e = __bt_search(t, key, &exact)) == NULL)
- return (RET_ERROR);
- if (!exact) {
- mpool_put(t->bt_mp, e->page, 0);
- return (RET_SPECIAL);
- }
-
- status = __bt_ret(t, e, NULL, NULL, data, &t->bt_rdata, 0);
-
- /*
- * If the user is doing concurrent access, we copied the
- * key/data, toss the page.
- */
- if (F_ISSET(t, B_DB_LOCK))
- mpool_put(t->bt_mp, e->page, 0);
- else
- t->bt_pinned = e->page;
- return (status);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_open.c b/1.2-netsec/db1-ast/btree/bt_open.c
deleted file mode 100644
index 8c2f48ebf..000000000
--- a/1.2-netsec/db1-ast/btree/bt_open.c
+++ /dev/null
@@ -1,458 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_open.c 8.10 (Berkeley) 8/17/94";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * Implementation of btree access method for 4.4BSD.
- *
- * The design here was originally based on that of the btree access method
- * used in the Postgres database system at UC Berkeley. This implementation
- * is wholly independent of the Postgres code.
- */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <db.h>
-#include "btree.h"
-
-#ifdef DEBUG
-#undef MINPSIZE
-#define MINPSIZE 128
-#endif
-
-static int byteorder __P((void));
-static int nroot __P((BTREE *));
-static int tmp __P((void));
-
-/*
- * __BT_OPEN -- Open a btree.
- *
- * Creates and fills a DB struct, and calls the routine that actually
- * opens the btree.
- *
- * Parameters:
- * fname: filename (NULL for in-memory trees)
- * flags: open flag bits
- * mode: open permission bits
- * b: BTREEINFO pointer
- *
- * Returns:
- * NULL on failure, pointer to DB on success.
- *
- */
-DB *
-__bt_open(fname, flags, mode, openinfo, dflags)
- const char *fname;
- int flags, mode, dflags;
- const BTREEINFO *openinfo;
-{
- struct stat sb;
- BTMETA m;
- BTREE *t;
- BTREEINFO b;
- DB *dbp;
- pgno_t ncache;
- ssize_t nr;
- int machine_lorder;
-
- t = NULL;
-
- /*
- * Intention is to make sure all of the user's selections are okay
- * here and then use them without checking. Can't be complete, since
- * we don't know the right page size, lorder or flags until the backing
- * file is opened. Also, the file's page size can cause the cachesize
- * to change.
- */
- machine_lorder = byteorder();
- if (openinfo) {
- b = *openinfo;
-
- /* Flags: R_DUP. */
- if (b.flags & ~(R_DUP))
- goto einval;
-
- /*
- * Page size must be indx_t aligned and >= MINPSIZE. Default
- * page size is set farther on, based on the underlying file
- * transfer size.
- */
- if (b.psize &&
- (b.psize < MINPSIZE || b.psize > MAX_PAGE_OFFSET + 1 ||
- b.psize & (sizeof(indx_t) - 1)))
- goto einval;
-
- /* Minimum number of keys per page; absolute minimum is 2. */
- if (b.minkeypage) {
- if (b.minkeypage < 2)
- goto einval;
- } else
- b.minkeypage = DEFMINKEYPAGE;
-
- /* If no comparison, use default comparison and prefix. */
- if (b.compare == NULL) {
- b.compare = __bt_defcmp;
- if (b.prefix == NULL)
- b.prefix = __bt_defpfx;
- }
-
- if (b.lorder == 0)
- b.lorder = machine_lorder;
- } else {
- b.compare = __bt_defcmp;
- b.cachesize = 0;
- b.flags = 0;
- b.lorder = machine_lorder;
- b.minkeypage = DEFMINKEYPAGE;
- b.prefix = __bt_defpfx;
- b.psize = 0;
- }
-
- /* Check for the ubiquitous PDP-11. */
- if (b.lorder != BIG_ENDIAN && b.lorder != LITTLE_ENDIAN)
- goto einval;
-
- /* Allocate and initialize DB and BTREE structures. */
- if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL)
- goto err;
- memset(t, 0, sizeof(BTREE));
- t->bt_fd = -1; /* Don't close unopened fd on error. */
- t->bt_lorder = b.lorder;
- t->bt_order = NOT;
- t->bt_cmp = b.compare;
- t->bt_pfx = b.prefix;
- t->bt_rfd = -1;
-
- if ((t->bt_dbp = dbp = (DB *)malloc(sizeof(DB))) == NULL)
- goto err;
- memset(t->bt_dbp, 0, sizeof(DB));
- if (t->bt_lorder != machine_lorder)
- F_SET(t, B_NEEDSWAP);
-
- dbp->type = DB_BTREE;
- dbp->internal = t;
- dbp->close = __bt_close;
- dbp->del = __bt_delete;
- dbp->fd = __bt_fd;
- dbp->get = __bt_get;
- dbp->put = __bt_put;
- dbp->seq = __bt_seq;
- dbp->sync = __bt_sync;
-
- /*
- * If no file name was supplied, this is an in-memory btree and we
- * open a backing temporary file. Otherwise, it's a disk-based tree.
- */
- if (fname) {
- switch (flags & O_ACCMODE) {
- case O_RDONLY:
- F_SET(t, B_RDONLY);
- break;
- case O_RDWR:
- break;
- case O_WRONLY:
- default:
- goto einval;
- }
-
- if ((t->bt_fd = open(fname, flags, mode)) < 0)
- goto err;
-
- } else {
- if ((flags & O_ACCMODE) != O_RDWR)
- goto einval;
- if ((t->bt_fd = tmp()) == -1)
- goto err;
- F_SET(t, B_INMEM);
- }
-
- if (fcntl(t->bt_fd, F_SETFD, 1) == -1)
- goto err;
-
- if (fstat(t->bt_fd, &sb))
- goto err;
- if (sb.st_size) {
- if ((nr = read(t->bt_fd, &m, sizeof(BTMETA))) < 0)
- goto err;
- if (nr != sizeof(BTMETA))
- goto eftype;
-
- /*
- * Read in the meta-data. This can change the notion of what
- * the lorder, page size and flags are, and, when the page size
- * changes, the cachesize value can change too. If the user
- * specified the wrong byte order for an existing database, we
- * don't bother to return an error, we just clear the NEEDSWAP
- * bit.
- */
- if (m.magic == BTREEMAGIC)
- F_CLR(t, B_NEEDSWAP);
- else {
- F_SET(t, B_NEEDSWAP);
- M_32_SWAP(m.magic);
- M_32_SWAP(m.version);
- M_32_SWAP(m.psize);
- M_32_SWAP(m.free);
- M_32_SWAP(m.nrecs);
- M_32_SWAP(m.flags);
- }
- if (m.magic != BTREEMAGIC || m.version != BTREEVERSION)
- goto eftype;
- if (m.psize < MINPSIZE || m.psize > MAX_PAGE_OFFSET + 1 ||
- m.psize & (sizeof(indx_t) - 1))
- goto eftype;
- if (m.flags & ~SAVEMETA)
- goto eftype;
- b.psize = m.psize;
- F_SET(t, m.flags);
- t->bt_free = m.free;
- t->bt_nrecs = m.nrecs;
- } else {
- /*
- * Set the page size to the best value for I/O to this file.
- * Don't overflow the page offset type.
- */
- if (b.psize == 0) {
-#ifdef _STATBUF_ST_BLKSIZE
- b.psize = sb.st_blksize;
-#endif
- if (b.psize < MINPSIZE)
- b.psize = MINPSIZE;
- if (b.psize > MAX_PAGE_OFFSET + 1)
- b.psize = MAX_PAGE_OFFSET + 1;
- }
-
- /* Set flag if duplicates permitted. */
- if (!(b.flags & R_DUP))
- F_SET(t, B_NODUPS);
-
- t->bt_free = P_INVALID;
- t->bt_nrecs = 0;
- F_SET(t, B_METADIRTY);
- }
-
- t->bt_psize = b.psize;
-
- /* Set the cache size; must be a multiple of the page size. */
- if (b.cachesize && b.cachesize & (b.psize - 1))
- b.cachesize += (~b.cachesize & (b.psize - 1)) + 1;
- if (b.cachesize < b.psize * MINCACHE)
- b.cachesize = b.psize * MINCACHE;
-
- /* Calculate number of pages to cache. */
- ncache = (b.cachesize + t->bt_psize - 1) / t->bt_psize;
-
- /*
- * The btree data structure requires that at least two keys can fit on
- * a page, but other than that there's no fixed requirement. The user
- * specified a minimum number per page, and we translated that into the
- * number of bytes a key/data pair can use before being placed on an
- * overflow page. This calculation includes the page header, the size
- * of the index referencing the leaf item and the size of the leaf item
- * structure. Also, don't let the user specify a minkeypage such that
- * a key/data pair won't fit even if both key and data are on overflow
- * pages.
- */
- t->bt_ovflsize = (t->bt_psize - BTDATAOFF) / b.minkeypage -
- (sizeof(indx_t) + NBLEAFDBT(0, 0));
- if (t->bt_ovflsize < NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t))
- t->bt_ovflsize =
- NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t);
-
- /* Initialize the buffer pool. */
- if ((t->bt_mp =
- mpool_open(NULL, t->bt_fd, t->bt_psize, ncache)) == NULL)
- goto err;
- if (!F_ISSET(t, B_INMEM))
- mpool_filter(t->bt_mp, __bt_pgin, __bt_pgout, t);
-
- /* Create a root page if new tree. */
- if (nroot(t) == RET_ERROR)
- goto err;
-
- /* Global flags. */
- if (dflags & DB_LOCK)
- F_SET(t, B_DB_LOCK);
- if (dflags & DB_SHMEM)
- F_SET(t, B_DB_SHMEM);
- if (dflags & DB_TXN)
- F_SET(t, B_DB_TXN);
-
- return (dbp);
-
-einval: errno = EINVAL;
- goto err;
-
-eftype: errno = EFTYPE;
- goto err;
-
-err: if (t) {
- if (t->bt_dbp)
- free(t->bt_dbp);
- if (t->bt_fd != -1)
- (void)close(t->bt_fd);
- free(t);
- }
- return (NULL);
-}
-
-/*
- * NROOT -- Create the root of a new tree.
- *
- * Parameters:
- * t: tree
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-static int
-nroot(t)
- BTREE *t;
-{
- PAGE *meta, *root;
- pgno_t npg;
-
- if ((meta = mpool_get(t->bt_mp, 0, 0)) != NULL) {
- mpool_put(t->bt_mp, meta, 0);
- return (RET_SUCCESS);
- }
- if (errno != EINVAL) /* It's OK to not exist. */
- return (RET_ERROR);
- errno = 0;
-
- if ((meta = mpool_new(t->bt_mp, &npg)) == NULL)
- return (RET_ERROR);
-
- if ((root = mpool_new(t->bt_mp, &npg)) == NULL)
- return (RET_ERROR);
-
- if (npg != P_ROOT)
- return (RET_ERROR);
- root->pgno = npg;
- root->prevpg = root->nextpg = P_INVALID;
- root->lower = BTDATAOFF;
- root->upper = t->bt_psize;
- root->flags = P_BLEAF;
- memset(meta, 0, t->bt_psize);
- mpool_put(t->bt_mp, meta, MPOOL_DIRTY);
- mpool_put(t->bt_mp, root, MPOOL_DIRTY);
- return (RET_SUCCESS);
-}
-
-static int
-tmp()
-{
- sigset_t set, oset;
- int fd;
- const char *envtmp;
- char *path;
- static const char fmt[] = "%s/bt.XXXXXX";
- size_t n;
-
- envtmp = getenv("TMPDIR");
- if (!envtmp)
- envtmp = "/tmp";
- n = strlen (envtmp) + sizeof fmt;
-#ifdef __GNUC__
- path = __builtin_alloca(n);
-#else
- path = malloc(n);
-#endif
- (void)snprintf(path, n, fmt, envtmp ? envtmp : "/tmp");
-
- (void)sigfillset(&set);
- (void)sigprocmask(SIG_BLOCK, &set, &oset);
- if ((fd = mkstemp(path)) != -1)
- (void)unlink(path);
- (void)sigprocmask(SIG_SETMASK, &oset, NULL);
-#ifndef __GNUC__
- free(path);
-#endif
- return(fd);
-}
-
-static int
-byteorder()
-{
- u_int32_t x;
- u_char *p;
-
- x = 0x01020304;
- p = (u_char *)&x;
- switch (*p) {
- case 1:
- return (BIG_ENDIAN);
- case 4:
- return (LITTLE_ENDIAN);
- default:
- return (0);
- }
-}
-
-int
-__bt_fd(dbp)
- const DB *dbp;
-{
- BTREE *t;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /* In-memory database can't have a file descriptor. */
- if (F_ISSET(t, B_INMEM)) {
- errno = ENOENT;
- return (-1);
- }
- return (t->bt_fd);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_overflow.c b/1.2-netsec/db1-ast/btree/bt_overflow.c
deleted file mode 100644
index b28b8e047..000000000
--- a/1.2-netsec/db1-ast/btree/bt_overflow.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_overflow.c 8.5 (Berkeley) 7/16/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <db.h>
-#include "btree.h"
-
-/*
- * Big key/data code.
- *
- * Big key and data entries are stored on linked lists of pages. The initial
- * reference is byte string stored with the key or data and is the page number
- * and size. The actual record is stored in a chain of pages linked by the
- * nextpg field of the PAGE header.
- *
- * The first page of the chain has a special property. If the record is used
- * by an internal page, it cannot be deleted and the P_PRESERVE bit will be set
- * in the header.
- *
- * XXX
- * A single DBT is written to each chain, so a lot of space on the last page
- * is wasted. This is a fairly major bug for some data sets.
- */
-
-/*
- * __OVFL_GET -- Get an overflow key/data item.
- *
- * Parameters:
- * t: tree
- * p: pointer to { pgno_t, u_int32_t }
- * buf: storage address
- * bufsz: storage size
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__ovfl_get(t, p, ssz, buf, bufsz)
- BTREE *t;
- void *p;
- size_t *ssz;
- void **buf;
- size_t *bufsz;
-{
- PAGE *h;
- pgno_t pg;
- size_t nb, plen;
- u_int32_t sz;
-
- memmove(&pg, p, sizeof(pgno_t));
- memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t));
- *ssz = sz;
-
-#ifdef DEBUG
- if (pg == P_INVALID || sz == 0)
- abort();
-#endif
- /* Make the buffer bigger as necessary. */
- if (*bufsz < sz) {
- *buf = (char *)(*buf == NULL ? malloc(sz) : realloc(*buf, sz));
- if (*buf == NULL)
- return (RET_ERROR);
- *bufsz = sz;
- }
-
- /*
- * Step through the linked list of pages, copying the data on each one
- * into the buffer. Never copy more than the data's length.
- */
- plen = t->bt_psize - BTDATAOFF;
- for (p = *buf;; p = (char *)p + nb, pg = h->nextpg) {
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (RET_ERROR);
-
- nb = MIN(sz, plen);
- memmove(p, (char *)h + BTDATAOFF, nb);
- mpool_put(t->bt_mp, h, 0);
-
- if ((sz -= nb) == 0)
- break;
- }
- return (RET_SUCCESS);
-}
-
-/*
- * __OVFL_PUT -- Store an overflow key/data item.
- *
- * Parameters:
- * t: tree
- * data: DBT to store
- * pgno: storage page number
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__ovfl_put(t, dbt, pg)
- BTREE *t;
- const DBT *dbt;
- pgno_t *pg;
-{
- PAGE *h, *last;
- void *p;
- pgno_t npg;
- size_t nb, plen;
- u_int32_t sz;
-
- /*
- * Allocate pages and copy the key/data record into them. Store the
- * number of the first page in the chain.
- */
- plen = t->bt_psize - BTDATAOFF;
- for (last = NULL, p = dbt->data, sz = dbt->size;;
- p = (char *)p + plen, last = h) {
- if ((h = __bt_new(t, &npg)) == NULL)
- return (RET_ERROR);
-
- h->pgno = npg;
- h->nextpg = h->prevpg = P_INVALID;
- h->flags = P_OVERFLOW;
- h->lower = h->upper = 0;
-
- nb = MIN(sz, plen);
- memmove((char *)h + BTDATAOFF, p, nb);
-
- if (last) {
- last->nextpg = h->pgno;
- mpool_put(t->bt_mp, last, MPOOL_DIRTY);
- } else
- *pg = h->pgno;
-
- if ((sz -= nb) == 0) {
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- break;
- }
- }
- return (RET_SUCCESS);
-}
-
-/*
- * __OVFL_DELETE -- Delete an overflow chain.
- *
- * Parameters:
- * t: tree
- * p: pointer to { pgno_t, u_int32_t }
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__ovfl_delete(t, p)
- BTREE *t;
- void *p;
-{
- PAGE *h;
- pgno_t pg;
- size_t plen;
- u_int32_t sz;
-
- memmove(&pg, p, sizeof(pgno_t));
- memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t));
-
-#ifdef DEBUG
- if (pg == P_INVALID || sz == 0)
- abort();
-#endif
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (RET_ERROR);
-
- /* Don't delete chains used by internal pages. */
- if (h->flags & P_PRESERVE) {
- mpool_put(t->bt_mp, h, 0);
- return (RET_SUCCESS);
- }
-
- /* Step through the chain, calling the free routine for each page. */
- for (plen = t->bt_psize - BTDATAOFF;; sz -= plen) {
- pg = h->nextpg;
- __bt_free(t, h);
- if (sz <= plen)
- break;
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (RET_ERROR);
- }
- return (RET_SUCCESS);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_page.c b/1.2-netsec/db1-ast/btree/bt_page.c
deleted file mode 100644
index ce9cbf15a..000000000
--- a/1.2-netsec/db1-ast/btree/bt_page.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_page.c 8.3 (Berkeley) 7/14/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <stdio.h>
-
-#include <db.h>
-#include "btree.h"
-
-/*
- * __bt_free --
- * Put a page on the freelist.
- *
- * Parameters:
- * t: tree
- * h: page to free
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- *
- * Side-effect:
- * mpool_put's the page.
- */
-int
-__bt_free(t, h)
- BTREE *t;
- PAGE *h;
-{
- /* Insert the page at the head of the free list. */
- h->prevpg = P_INVALID;
- h->nextpg = t->bt_free;
- t->bt_free = h->pgno;
- F_SET(t, B_METADIRTY);
-
- /* Make sure the page gets written back. */
- return (mpool_put(t->bt_mp, h, MPOOL_DIRTY));
-}
-
-/*
- * __bt_new --
- * Get a new page, preferably from the freelist.
- *
- * Parameters:
- * t: tree
- * npg: storage for page number.
- *
- * Returns:
- * Pointer to a page, NULL on error.
- */
-PAGE *
-__bt_new(t, npg)
- BTREE *t;
- pgno_t *npg;
-{
- PAGE *h;
-
- if (t->bt_free != P_INVALID &&
- (h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) {
- *npg = t->bt_free;
- t->bt_free = h->nextpg;
- F_SET(t, B_METADIRTY);
- return (h);
- }
- return (mpool_new(t->bt_mp, npg));
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_put.c b/1.2-netsec/db1-ast/btree/bt_put.c
deleted file mode 100644
index 3f3807531..000000000
--- a/1.2-netsec/db1-ast/btree/bt_put.c
+++ /dev/null
@@ -1,321 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_put.c 8.8 (Berkeley) 7/26/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <db.h>
-#include "btree.h"
-
-static EPG *bt_fast __P((BTREE *, const DBT *, const DBT *, int *));
-
-/*
- * __BT_PUT -- Add a btree item to the tree.
- *
- * Parameters:
- * dbp: pointer to access method
- * key: key
- * data: data
- * flag: R_NOOVERWRITE
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is already in the
- * tree and R_NOOVERWRITE specified.
- */
-int
-__bt_put(dbp, key, data, flags)
- const DB *dbp;
- DBT *key;
- const DBT *data;
- u_int flags;
-{
- BTREE *t;
- DBT tkey, tdata;
- EPG *e = 0;
- PAGE *h;
- indx_t index, nxtindex;
- pgno_t pg;
- u_int32_t nbytes;
- int dflags, exact, status;
- char *dest, db[NOVFLSIZE], kb[NOVFLSIZE];
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /* Check for change to a read-only tree. */
- if (F_ISSET(t, B_RDONLY)) {
- errno = EPERM;
- return (RET_ERROR);
- }
-
- switch (flags) {
- case 0:
- case R_NOOVERWRITE:
- break;
- case R_CURSOR:
- /*
- * If flags is R_CURSOR, put the cursor. Must already
- * have started a scan and not have already deleted it.
- */
- if (F_ISSET(&t->bt_cursor, CURS_INIT) &&
- !F_ISSET(&t->bt_cursor,
- CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE))
- break;
- /* FALLTHROUGH */
- default:
- errno = EINVAL;
- return (RET_ERROR);
- }
-
- /*
- * If the key/data pair won't fit on a page, store it on overflow
- * pages. Only put the key on the overflow page if the pair are
- * still too big after moving the data to an overflow page.
- *
- * XXX
- * If the insert fails later on, the overflow pages aren't recovered.
- */
- dflags = 0;
- if (key->size + data->size > t->bt_ovflsize) {
- if (key->size > t->bt_ovflsize) {
-storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR)
- return (RET_ERROR);
- tkey.data = kb;
- tkey.size = NOVFLSIZE;
- memmove(kb, &pg, sizeof(pgno_t));
- memmove(kb + sizeof(pgno_t),
- &key->size, sizeof(u_int32_t));
- dflags |= P_BIGKEY;
- key = &tkey;
- }
- if (key->size + data->size > t->bt_ovflsize) {
- if (__ovfl_put(t, data, &pg) == RET_ERROR)
- return (RET_ERROR);
- tdata.data = db;
- tdata.size = NOVFLSIZE;
- memmove(db, &pg, sizeof(pgno_t));
- memmove(db + sizeof(pgno_t),
- &data->size, sizeof(u_int32_t));
- dflags |= P_BIGDATA;
- data = &tdata;
- }
- if (key->size + data->size > t->bt_ovflsize)
- goto storekey;
- }
-
- /* Replace the cursor. */
- if (flags == R_CURSOR) {
- if ((h = mpool_get(t->bt_mp, t->bt_cursor.pg.pgno, 0)) == NULL)
- return (RET_ERROR);
- index = t->bt_cursor.pg.index;
- goto delete;
- }
-
- /*
- * Find the key to delete, or, the location at which to insert.
- * Bt_fast and __bt_search both pin the returned page.
- */
- if (t->bt_order == NOT || (e = bt_fast(t, key, data, &exact)) == NULL)
- if ((e = __bt_search(t, key, &exact)) == NULL)
- return (RET_ERROR);
- h = e->page;
- index = e->index;
-
- /*
- * Add the key/data pair to the tree. If an identical key is already
- * in the tree, and R_NOOVERWRITE is set, an error is returned. If
- * R_NOOVERWRITE is not set, the key is either added (if duplicates are
- * permitted) or an error is returned.
- */
- switch (flags) {
- case R_NOOVERWRITE:
- if (!exact)
- break;
- mpool_put(t->bt_mp, h, 0);
- return (RET_SPECIAL);
- default:
- if (!exact || !F_ISSET(t, B_NODUPS))
- break;
- /*
- * !!!
- * Note, the delete may empty the page, so we need to put a
- * new entry into the page immediately.
- */
-delete: if (__bt_dleaf(t, key, h, index) == RET_ERROR) {
- mpool_put(t->bt_mp, h, 0);
- return (RET_ERROR);
- }
- break;
- }
-
- /*
- * If not enough room, or the user has put a ceiling on the number of
- * keys permitted in the page, split the page. The split code will
- * insert the key and data and unpin the current page. If inserting
- * into the offset array, shift the pointers up.
- */
- nbytes = NBLEAFDBT(key->size, data->size);
- if ((u_int32_t) (h->upper - h->lower) < nbytes + sizeof(indx_t)) {
- if ((status = __bt_split(t, h, key,
- data, dflags, nbytes, index)) != RET_SUCCESS)
- return (status);
- goto success;
- }
-
- if (index < (nxtindex = NEXTINDEX(h)))
- memmove(h->linp + index + 1, h->linp + index,
- (nxtindex - index) * sizeof(indx_t));
- h->lower += sizeof(indx_t);
-
- h->linp[index] = h->upper -= nbytes;
- dest = (char *)h + h->upper;
- WR_BLEAF(dest, key, data, dflags);
-
- /* If the cursor is on this page, adjust it as necessary. */
- if (F_ISSET(&t->bt_cursor, CURS_INIT) &&
- !F_ISSET(&t->bt_cursor, CURS_ACQUIRE) &&
- t->bt_cursor.pg.pgno == h->pgno && t->bt_cursor.pg.index >= index)
- ++t->bt_cursor.pg.index;
-
- if (t->bt_order == NOT) {
- if (h->nextpg == P_INVALID) {
- if (index == NEXTINDEX(h) - 1) {
- t->bt_order = FORWARD;
- t->bt_last.index = index;
- t->bt_last.pgno = h->pgno;
- }
- } else if (h->prevpg == P_INVALID) {
- if (index == 0) {
- t->bt_order = BACK;
- t->bt_last.index = 0;
- t->bt_last.pgno = h->pgno;
- }
- }
- }
-
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
-
-success:
- if (flags == R_SETCURSOR)
- __bt_setcur(t, e->page->pgno, e->index);
-
- F_SET(t, B_MODIFIED);
- return (RET_SUCCESS);
-}
-
-#ifdef STATISTICS
-u_long bt_cache_hit, bt_cache_miss;
-#endif
-
-/*
- * BT_FAST -- Do a quick check for sorted data.
- *
- * Parameters:
- * t: tree
- * key: key to insert
- *
- * Returns:
- * EPG for new record or NULL if not found.
- */
-static EPG *
-bt_fast(t, key, data, exactp)
- BTREE *t;
- const DBT *key, *data;
- int *exactp;
-{
- PAGE *h;
- u_int32_t nbytes;
- int cmp;
-
- if ((h = mpool_get(t->bt_mp, t->bt_last.pgno, 0)) == NULL) {
- t->bt_order = NOT;
- return (NULL);
- }
- t->bt_cur.page = h;
- t->bt_cur.index = t->bt_last.index;
-
- /*
- * If won't fit in this page or have too many keys in this page,
- * have to search to get split stack.
- */
- nbytes = NBLEAFDBT(key->size, data->size);
- if ((u_int32_t) (h->upper - h->lower) < nbytes + sizeof(indx_t))
- goto miss;
-
- if (t->bt_order == FORWARD) {
- if (t->bt_cur.page->nextpg != P_INVALID)
- goto miss;
- if (t->bt_cur.index != NEXTINDEX(h) - 1)
- goto miss;
- if ((cmp = __bt_cmp(t, key, &t->bt_cur)) < 0)
- goto miss;
- t->bt_last.index = cmp ? ++t->bt_cur.index : t->bt_cur.index;
- } else {
- if (t->bt_cur.page->prevpg != P_INVALID)
- goto miss;
- if (t->bt_cur.index != 0)
- goto miss;
- if ((cmp = __bt_cmp(t, key, &t->bt_cur)) > 0)
- goto miss;
- t->bt_last.index = 0;
- }
- *exactp = cmp == 0;
-#ifdef STATISTICS
- ++bt_cache_hit;
-#endif
- return (&t->bt_cur);
-
-miss:
-#ifdef STATISTICS
- ++bt_cache_miss;
-#endif
- t->bt_order = NOT;
- mpool_put(t->bt_mp, h, 0);
- return (NULL);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_search.c b/1.2-netsec/db1-ast/btree/bt_search.c
deleted file mode 100644
index 485afcbbf..000000000
--- a/1.2-netsec/db1-ast/btree/bt_search.c
+++ /dev/null
@@ -1,213 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_search.c 8.8 (Berkeley) 7/31/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <stdio.h>
-
-#include <db.h>
-#include "btree.h"
-
-static int __bt_snext __P((BTREE *, PAGE *, const DBT *, int *));
-static int __bt_sprev __P((BTREE *, PAGE *, const DBT *, int *));
-
-/*
- * __bt_search --
- * Search a btree for a key.
- *
- * Parameters:
- * t: tree to search
- * key: key to find
- * exactp: pointer to exact match flag
- *
- * Returns:
- * The EPG for matching record, if any, or the EPG for the location
- * of the key, if it were inserted into the tree, is entered into
- * the bt_cur field of the tree. A pointer to the field is returned.
- */
-EPG *
-__bt_search(t, key, exactp)
- BTREE *t;
- const DBT *key;
- int *exactp;
-{
- PAGE *h;
- indx_t base, index, lim;
- pgno_t pg;
- int cmp;
-
- BT_CLR(t);
- for (pg = P_ROOT;;) {
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (NULL);
-
- /* Do a binary search on the current page. */
- t->bt_cur.page = h;
- for (base = 0, lim = NEXTINDEX(h); lim; lim >>= 1) {
- t->bt_cur.index = index = base + (lim >> 1);
- if ((cmp = __bt_cmp(t, key, &t->bt_cur)) == 0) {
- if (h->flags & P_BLEAF) {
- *exactp = 1;
- return (&t->bt_cur);
- }
- goto next;
- }
- if (cmp > 0) {
- base = index + 1;
- --lim;
- }
- }
-
- /*
- * If it's a leaf page, we're almost done. If no duplicates
- * are allowed, or we have an exact match, we're done. Else,
- * it's possible that there were matching keys on this page,
- * which later deleted, and we're on a page with no matches
- * while there are matches on other pages. If at the start or
- * end of a page, check the adjacent page.
- */
- if (h->flags & P_BLEAF) {
- if (!F_ISSET(t, B_NODUPS)) {
- if (base == 0 &&
- h->prevpg != P_INVALID &&
- __bt_sprev(t, h, key, exactp))
- return (&t->bt_cur);
- if (base == NEXTINDEX(h) &&
- h->nextpg != P_INVALID &&
- __bt_snext(t, h, key, exactp))
- return (&t->bt_cur);
- }
- *exactp = 0;
- t->bt_cur.index = base;
- return (&t->bt_cur);
- }
-
- /*
- * No match found. Base is the smallest index greater than
- * key and may be zero or a last + 1 index. If it's non-zero,
- * decrement by one, and record the internal page which should
- * be a parent page for the key. If a split later occurs, the
- * inserted page will be to the right of the saved page.
- */
- index = base ? base - 1 : base;
-
-next: BT_PUSH(t, h->pgno, index);
- pg = GETBINTERNAL(h, index)->pgno;
- mpool_put(t->bt_mp, h, 0);
- }
-}
-
-/*
- * __bt_snext --
- * Check for an exact match after the key.
- *
- * Parameters:
- * t: tree
- * h: current page
- * key: key
- * exactp: pointer to exact match flag
- *
- * Returns:
- * If an exact match found.
- */
-static int
-__bt_snext(t, h, key, exactp)
- BTREE *t;
- PAGE *h;
- const DBT *key;
- int *exactp;
-{
- EPG e;
-
- /*
- * Get the next page. The key is either an exact
- * match, or not as good as the one we already have.
- */
- if ((e.page = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL)
- return (0);
- e.index = 0;
- if (__bt_cmp(t, key, &e) == 0) {
- mpool_put(t->bt_mp, h, 0);
- t->bt_cur = e;
- *exactp = 1;
- return (1);
- }
- mpool_put(t->bt_mp, e.page, 0);
- return (0);
-}
-
-/*
- * __bt_sprev --
- * Check for an exact match before the key.
- *
- * Parameters:
- * t: tree
- * h: current page
- * key: key
- * exactp: pointer to exact match flag
- *
- * Returns:
- * If an exact match found.
- */
-static int
-__bt_sprev(t, h, key, exactp)
- BTREE *t;
- PAGE *h;
- const DBT *key;
- int *exactp;
-{
- EPG e;
-
- /*
- * Get the previous page. The key is either an exact
- * match, or not as good as the one we already have.
- */
- if ((e.page = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL)
- return (0);
- e.index = NEXTINDEX(e.page) - 1;
- if (__bt_cmp(t, key, &e) == 0) {
- mpool_put(t->bt_mp, h, 0);
- t->bt_cur = e;
- *exactp = 1;
- return (1);
- }
- mpool_put(t->bt_mp, e.page, 0);
- return (0);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_seq.c b/1.2-netsec/db1-ast/btree/bt_seq.c
deleted file mode 100644
index 5ba7b0301..000000000
--- a/1.2-netsec/db1-ast/btree/bt_seq.c
+++ /dev/null
@@ -1,460 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_seq.c 8.7 (Berkeley) 7/20/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <db.h>
-#include "btree.h"
-
-static int __bt_first __P((BTREE *, const DBT *, EPG *, int *));
-static int __bt_seqadv __P((BTREE *, EPG *, int));
-static int __bt_seqset __P((BTREE *, EPG *, DBT *, int));
-
-/*
- * Sequential scan support.
- *
- * The tree can be scanned sequentially, starting from either end of the
- * tree or from any specific key. A scan request before any scanning is
- * done is initialized as starting from the least node.
- */
-
-/*
- * __bt_seq --
- * Btree sequential scan interface.
- *
- * Parameters:
- * dbp: pointer to access method
- * key: key for positioning and return value
- * data: data return value
- * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV.
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key.
- */
-int
-__bt_seq(dbp, key, data, flags)
- const DB *dbp;
- DBT *key, *data;
- u_int flags;
-{
- BTREE *t;
- EPG e;
- int status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /*
- * If scan uninitialized as yet, or starting at a specific record, set
- * the scan to a specific key. Both __bt_seqset and __bt_seqadv pin
- * the page the cursor references if they're successful.
- */
- switch (flags) {
- case R_NEXT:
- case R_PREV:
- if (F_ISSET(&t->bt_cursor, CURS_INIT)) {
- status = __bt_seqadv(t, &e, flags);
- break;
- }
- /* FALLTHROUGH */
- case R_FIRST:
- case R_LAST:
- case R_CURSOR:
- status = __bt_seqset(t, &e, key, flags);
- break;
- default:
- errno = EINVAL;
- return (RET_ERROR);
- }
-
- if (status == RET_SUCCESS) {
- __bt_setcur(t, e.page->pgno, e.index);
-
- status =
- __bt_ret(t, &e, key, &t->bt_rkey, data, &t->bt_rdata, 0);
-
- /*
- * If the user is doing concurrent access, we copied the
- * key/data, toss the page.
- */
- if (F_ISSET(t, B_DB_LOCK))
- mpool_put(t->bt_mp, e.page, 0);
- else
- t->bt_pinned = e.page;
- }
- return (status);
-}
-
-/*
- * __bt_seqset --
- * Set the sequential scan to a specific key.
- *
- * Parameters:
- * t: tree
- * ep: storage for returned key
- * key: key for initial scan position
- * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV
- *
- * Side effects:
- * Pins the page the cursor references.
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key.
- */
-static int
-__bt_seqset(t, ep, key, flags)
- BTREE *t;
- EPG *ep;
- DBT *key;
- int flags;
-{
- PAGE *h;
- pgno_t pg;
- int exact;
-
- /*
- * Find the first, last or specific key in the tree and point the
- * cursor at it. The cursor may not be moved until a new key has
- * been found.
- */
- switch (flags) {
- case R_CURSOR: /* Keyed scan. */
- /*
- * Find the first instance of the key or the smallest key
- * which is greater than or equal to the specified key.
- */
- if (key->data == NULL || key->size == 0) {
- errno = EINVAL;
- return (RET_ERROR);
- }
- return (__bt_first(t, key, ep, &exact));
- case R_FIRST: /* First record. */
- case R_NEXT:
- /* Walk down the left-hand side of the tree. */
- for (pg = P_ROOT;;) {
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (RET_ERROR);
-
- /* Check for an empty tree. */
- if (NEXTINDEX(h) == 0) {
- mpool_put(t->bt_mp, h, 0);
- return (RET_SPECIAL);
- }
-
- if (h->flags & (P_BLEAF | P_RLEAF))
- break;
- pg = GETBINTERNAL(h, 0)->pgno;
- mpool_put(t->bt_mp, h, 0);
- }
- ep->page = h;
- ep->index = 0;
- break;
- case R_LAST: /* Last record. */
- case R_PREV:
- /* Walk down the right-hand side of the tree. */
- for (pg = P_ROOT;;) {
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (RET_ERROR);
-
- /* Check for an empty tree. */
- if (NEXTINDEX(h) == 0) {
- mpool_put(t->bt_mp, h, 0);
- return (RET_SPECIAL);
- }
-
- if (h->flags & (P_BLEAF | P_RLEAF))
- break;
- pg = GETBINTERNAL(h, NEXTINDEX(h) - 1)->pgno;
- mpool_put(t->bt_mp, h, 0);
- }
-
- ep->page = h;
- ep->index = NEXTINDEX(h) - 1;
- break;
- }
- return (RET_SUCCESS);
-}
-
-/*
- * __bt_seqadvance --
- * Advance the sequential scan.
- *
- * Parameters:
- * t: tree
- * flags: R_NEXT, R_PREV
- *
- * Side effects:
- * Pins the page the new key/data record is on.
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key.
- */
-static int
-__bt_seqadv(t, ep, flags)
- BTREE *t;
- EPG *ep;
- int flags;
-{
- CURSOR *c;
- PAGE *h;
- indx_t index = 0;
- pgno_t pg;
- int exact;
-
- /*
- * There are a couple of states that we can be in. The cursor has
- * been initialized by the time we get here, but that's all we know.
- */
- c = &t->bt_cursor;
-
- /*
- * The cursor was deleted where there weren't any duplicate records,
- * so the key was saved. Find out where that key would go in the
- * current tree. It doesn't matter if the returned key is an exact
- * match or not -- if it's an exact match, the record was added after
- * the delete so we can just return it. If not, as long as there's
- * a record there, return it.
- */
- if (F_ISSET(c, CURS_ACQUIRE))
- return (__bt_first(t, &c->key, ep, &exact));
-
- /* Get the page referenced by the cursor. */
- if ((h = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL)
- return (RET_ERROR);
-
- /*
- * Find the next/previous record in the tree and point the cursor at
- * it. The cursor may not be moved until a new key has been found.
- */
- switch (flags) {
- case R_NEXT: /* Next record. */
- /*
- * The cursor was deleted in duplicate records, and moved
- * forward to a record that has yet to be returned. Clear
- * that flag, and return the record.
- */
- if (F_ISSET(c, CURS_AFTER))
- goto usecurrent;
- index = c->pg.index;
- if (++index == NEXTINDEX(h)) {
- pg = h->nextpg;
- mpool_put(t->bt_mp, h, 0);
- if (pg == P_INVALID)
- return (RET_SPECIAL);
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (RET_ERROR);
- index = 0;
- }
- break;
- case R_PREV: /* Previous record. */
- /*
- * The cursor was deleted in duplicate records, and moved
- * backward to a record that has yet to be returned. Clear
- * that flag, and return the record.
- */
- if (F_ISSET(c, CURS_BEFORE)) {
-usecurrent: F_CLR(c, CURS_AFTER | CURS_BEFORE);
- ep->page = h;
- ep->index = c->pg.index;
- return (RET_SUCCESS);
- }
- index = c->pg.index;
- if (index == 0) {
- pg = h->prevpg;
- mpool_put(t->bt_mp, h, 0);
- if (pg == P_INVALID)
- return (RET_SPECIAL);
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (RET_ERROR);
- index = NEXTINDEX(h) - 1;
- } else
- --index;
- break;
- }
-
- ep->page = h;
- ep->index = index;
- return (RET_SUCCESS);
-}
-
-/*
- * __bt_first --
- * Find the first entry.
- *
- * Parameters:
- * t: the tree
- * key: the key
- * erval: return EPG
- * exactp: pointer to exact match flag
- *
- * Returns:
- * The first entry in the tree greater than or equal to key,
- * or RET_SPECIAL if no such key exists.
- */
-static int
-__bt_first(t, key, erval, exactp)
- BTREE *t;
- const DBT *key;
- EPG *erval;
- int *exactp;
-{
- PAGE *h;
- EPG *ep, save;
- pgno_t pg;
-
- /*
- * Find any matching record; __bt_search pins the page.
- *
- * If it's an exact match and duplicates are possible, walk backwards
- * in the tree until we find the first one. Otherwise, make sure it's
- * a valid key (__bt_search may return an index just past the end of a
- * page) and return it.
- */
- if ((ep = __bt_search(t, key, exactp)) == NULL)
- return (RET_SPECIAL);
- if (*exactp) {
- if (F_ISSET(t, B_NODUPS)) {
- *erval = *ep;
- return (RET_SUCCESS);
- }
-
- /*
- * Walk backwards, as long as the entry matches and there are
- * keys left in the tree. Save a copy of each match in case
- * we go too far.
- */
- save = *ep;
- h = ep->page;
- do {
- if (save.page->pgno != ep->page->pgno) {
- mpool_put(t->bt_mp, save.page, 0);
- save = *ep;
- } else
- save.index = ep->index;
-
- /*
- * Don't unpin the page the last (or original) match
- * was on, but make sure it's unpinned if an error
- * occurs.
- */
- if (ep->index == 0) {
- if (h->prevpg == P_INVALID)
- break;
- if (h->pgno != save.page->pgno)
- mpool_put(t->bt_mp, h, 0);
- if ((h = mpool_get(t->bt_mp,
- h->prevpg, 0)) == NULL) {
- if (h->pgno == save.page->pgno)
- mpool_put(t->bt_mp,
- save.page, 0);
- return (RET_ERROR);
- }
- ep->page = h;
- ep->index = NEXTINDEX(h);
- }
- --ep->index;
- } while (__bt_cmp(t, key, ep) == 0);
-
- /*
- * Reach here with the last page that was looked at pinned,
- * which may or may not be the same as the last (or original)
- * match page. If it's not useful, release it.
- */
- if (h->pgno != save.page->pgno)
- mpool_put(t->bt_mp, h, 0);
-
- *erval = save;
- return (RET_SUCCESS);
- }
-
- /* If at the end of a page, find the next entry. */
- if (ep->index == NEXTINDEX(ep->page)) {
- h = ep->page;
- pg = h->nextpg;
- mpool_put(t->bt_mp, h, 0);
- if (pg == P_INVALID)
- return (RET_SPECIAL);
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (RET_ERROR);
- ep->index = 0;
- ep->page = h;
- }
- *erval = *ep;
- return (RET_SUCCESS);
-}
-
-/*
- * __bt_setcur --
- * Set the cursor to an entry in the tree.
- *
- * Parameters:
- * t: the tree
- * pgno: page number
- * index: page index
- */
-void
-__bt_setcur(t, pgno, index)
- BTREE *t;
- pgno_t pgno;
- u_int index;
-{
- /* Lose any already deleted key. */
- if (t->bt_cursor.key.data != NULL) {
- free(t->bt_cursor.key.data);
- t->bt_cursor.key.size = 0;
- t->bt_cursor.key.data = NULL;
- }
- F_CLR(&t->bt_cursor, CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE);
-
- /* Update the cursor. */
- t->bt_cursor.pg.pgno = pgno;
- t->bt_cursor.pg.index = index;
- F_SET(&t->bt_cursor, CURS_INIT);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_split.c b/1.2-netsec/db1-ast/btree/bt_split.c
deleted file mode 100644
index e6bd540b4..000000000
--- a/1.2-netsec/db1-ast/btree/bt_split.c
+++ /dev/null
@@ -1,829 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_split.c 8.9 (Berkeley) 7/26/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <db.h>
-#include "btree.h"
-
-static int bt_broot __P((BTREE *, PAGE *, PAGE *, PAGE *));
-static PAGE *bt_page
- __P((BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t));
-static int bt_preserve __P((BTREE *, pgno_t));
-static PAGE *bt_psplit
- __P((BTREE *, PAGE *, PAGE *, PAGE *, indx_t *, size_t));
-static PAGE *bt_root
- __P((BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t));
-static int bt_rroot __P((BTREE *, PAGE *, PAGE *, PAGE *));
-static recno_t rec_total __P((PAGE *));
-
-#ifdef STATISTICS
-u_long bt_rootsplit, bt_split, bt_sortsplit, bt_pfxsaved;
-#endif
-
-/*
- * __BT_SPLIT -- Split the tree.
- *
- * Parameters:
- * t: tree
- * sp: page to split
- * key: key to insert
- * data: data to insert
- * flags: BIGKEY/BIGDATA flags
- * ilen: insert length
- * skip: index to leave open
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__bt_split(t, sp, key, data, flags, ilen, argskip)
- BTREE *t;
- PAGE *sp;
- const DBT *key, *data;
- int flags;
- size_t ilen;
- u_int32_t argskip;
-{
- BINTERNAL *bi = 0;
- BLEAF *bl = 0, *tbl;
- DBT a, b;
- EPGNO *parent;
- PAGE *h, *l, *r, *lchild, *rchild;
- indx_t nxtindex;
- u_int16_t skip;
- u_int32_t n, nbytes, nksize = 0;
- int parentsplit;
- char *dest;
-
- /*
- * Split the page into two pages, l and r. The split routines return
- * a pointer to the page into which the key should be inserted and with
- * skip set to the offset which should be used. Additionally, l and r
- * are pinned.
- */
- skip = argskip;
- h = sp->pgno == P_ROOT ?
- bt_root(t, sp, &l, &r, &skip, ilen) :
- bt_page(t, sp, &l, &r, &skip, ilen);
- if (h == NULL)
- return (RET_ERROR);
-
- /*
- * Insert the new key/data pair into the leaf page. (Key inserts
- * always cause a leaf page to split first.)
- */
- h->linp[skip] = h->upper -= ilen;
- dest = (char *)h + h->upper;
- if (F_ISSET(t, R_RECNO))
- WR_RLEAF(dest, data, flags)
- else
- WR_BLEAF(dest, key, data, flags)
-
- /* If the root page was split, make it look right. */
- if (sp->pgno == P_ROOT &&
- (F_ISSET(t, R_RECNO) ?
- bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR)
- goto err2;
-
- /*
- * Now we walk the parent page stack -- a LIFO stack of the pages that
- * were traversed when we searched for the page that split. Each stack
- * entry is a page number and a page index offset. The offset is for
- * the page traversed on the search. We've just split a page, so we
- * have to insert a new key into the parent page.
- *
- * If the insert into the parent page causes it to split, may have to
- * continue splitting all the way up the tree. We stop if the root
- * splits or the page inserted into didn't have to split to hold the
- * new key. Some algorithms replace the key for the old page as well
- * as the new page. We don't, as there's no reason to believe that the
- * first key on the old page is any better than the key we have, and,
- * in the case of a key being placed at index 0 causing the split, the
- * key is unavailable.
- *
- * There are a maximum of 5 pages pinned at any time. We keep the left
- * and right pages pinned while working on the parent. The 5 are the
- * two children, left parent and right parent (when the parent splits)
- * and the root page or the overflow key page when calling bt_preserve.
- * This code must make sure that all pins are released other than the
- * root page or overflow page which is unlocked elsewhere.
- */
- while ((parent = BT_POP(t)) != NULL) {
- lchild = l;
- rchild = r;
-
- /* Get the parent page. */
- if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL)
- goto err2;
-
- /*
- * The new key goes ONE AFTER the index, because the split
- * was to the right.
- */
- skip = parent->index + 1;
-
- /*
- * Calculate the space needed on the parent page.
- *
- * Prefix trees: space hack when inserting into BINTERNAL
- * pages. Retain only what's needed to distinguish between
- * the new entry and the LAST entry on the page to its left.
- * If the keys compare equal, retain the entire key. Note,
- * we don't touch overflow keys, and the entire key must be
- * retained for the next-to-left most key on the leftmost
- * page of each level, or the search will fail. Applicable
- * ONLY to internal pages that have leaf pages as children.
- * Further reduction of the key between pairs of internal
- * pages loses too much information.
- */
- switch (rchild->flags & P_TYPE) {
- case P_BINTERNAL:
- bi = GETBINTERNAL(rchild, 0);
- nbytes = NBINTERNAL(bi->ksize);
- break;
- case P_BLEAF:
- bl = GETBLEAF(rchild, 0);
- nbytes = NBINTERNAL(bl->ksize);
- if (t->bt_pfx && !(bl->flags & P_BIGKEY) &&
- (h->prevpg != P_INVALID || skip > 1)) {
- tbl = GETBLEAF(lchild, NEXTINDEX(lchild) - 1);
- a.size = tbl->ksize;
- a.data = tbl->bytes;
- b.size = bl->ksize;
- b.data = bl->bytes;
- nksize = t->bt_pfx(&a, &b);
- n = NBINTERNAL(nksize);
- if (n < nbytes) {
-#ifdef STATISTICS
- bt_pfxsaved += nbytes - n;
-#endif
- nbytes = n;
- } else
- nksize = 0;
- } else
- nksize = 0;
- break;
- case P_RINTERNAL:
- case P_RLEAF:
- nbytes = NRINTERNAL;
- break;
- default:
- abort();
- }
-
- /* Split the parent page if necessary or shift the indices. */
- if ((u_int32_t) (h->upper - h->lower)
- < nbytes + sizeof(indx_t)) {
- sp = h;
- h = h->pgno == P_ROOT ?
- bt_root(t, h, &l, &r, &skip, nbytes) :
- bt_page(t, h, &l, &r, &skip, nbytes);
- if (h == NULL)
- goto err1;
- parentsplit = 1;
- } else {
- if (skip < (nxtindex = NEXTINDEX(h)))
- memmove(h->linp + skip + 1, h->linp + skip,
- (nxtindex - skip) * sizeof(indx_t));
- h->lower += sizeof(indx_t);
- parentsplit = 0;
- }
-
- /* Insert the key into the parent page. */
- switch (rchild->flags & P_TYPE) {
- case P_BINTERNAL:
- h->linp[skip] = h->upper -= nbytes;
- dest = (char *)h + h->linp[skip];
- memmove(dest, bi, nbytes);
- ((BINTERNAL *)dest)->pgno = rchild->pgno;
- break;
- case P_BLEAF:
- h->linp[skip] = h->upper -= nbytes;
- dest = (char *)h + h->linp[skip];
- WR_BINTERNAL(dest, nksize ? nksize : bl->ksize,
- rchild->pgno, bl->flags & P_BIGKEY);
- memmove(dest, bl->bytes, nksize ? nksize : bl->ksize);
- if (bl->flags & P_BIGKEY &&
- bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR)
- goto err1;
- break;
- case P_RINTERNAL:
- /*
- * Update the left page count. If split
- * added at index 0, fix the correct page.
- */
- if (skip > 0)
- dest = (char *)h + h->linp[skip - 1];
- else
- dest = (char *)l + l->linp[NEXTINDEX(l) - 1];
- ((RINTERNAL *)dest)->nrecs = rec_total(lchild);
- ((RINTERNAL *)dest)->pgno = lchild->pgno;
-
- /* Update the right page count. */
- h->linp[skip] = h->upper -= nbytes;
- dest = (char *)h + h->linp[skip];
- ((RINTERNAL *)dest)->nrecs = rec_total(rchild);
- ((RINTERNAL *)dest)->pgno = rchild->pgno;
- break;
- case P_RLEAF:
- /*
- * Update the left page count. If split
- * added at index 0, fix the correct page.
- */
- if (skip > 0)
- dest = (char *)h + h->linp[skip - 1];
- else
- dest = (char *)l + l->linp[NEXTINDEX(l) - 1];
- ((RINTERNAL *)dest)->nrecs = NEXTINDEX(lchild);
- ((RINTERNAL *)dest)->pgno = lchild->pgno;
-
- /* Update the right page count. */
- h->linp[skip] = h->upper -= nbytes;
- dest = (char *)h + h->linp[skip];
- ((RINTERNAL *)dest)->nrecs = NEXTINDEX(rchild);
- ((RINTERNAL *)dest)->pgno = rchild->pgno;
- break;
- default:
- abort();
- }
-
- /* Unpin the held pages. */
- if (!parentsplit) {
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- break;
- }
-
- /* If the root page was split, make it look right. */
- if (sp->pgno == P_ROOT &&
- (F_ISSET(t, R_RECNO) ?
- bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR)
- goto err1;
-
- mpool_put(t->bt_mp, lchild, MPOOL_DIRTY);
- mpool_put(t->bt_mp, rchild, MPOOL_DIRTY);
- }
-
- /* Unpin the held pages. */
- mpool_put(t->bt_mp, l, MPOOL_DIRTY);
- mpool_put(t->bt_mp, r, MPOOL_DIRTY);
-
- /* Clear any pages left on the stack. */
- return (RET_SUCCESS);
-
- /*
- * If something fails in the above loop we were already walking back
- * up the tree and the tree is now inconsistent. Nothing much we can
- * do about it but release any memory we're holding.
- */
-err1: mpool_put(t->bt_mp, lchild, MPOOL_DIRTY);
- mpool_put(t->bt_mp, rchild, MPOOL_DIRTY);
-
-err2: mpool_put(t->bt_mp, l, 0);
- mpool_put(t->bt_mp, r, 0);
- __dbpanic(t->bt_dbp);
- return (RET_ERROR);
-}
-
-/*
- * BT_PAGE -- Split a non-root page of a btree.
- *
- * Parameters:
- * t: tree
- * h: root page
- * lp: pointer to left page pointer
- * rp: pointer to right page pointer
- * skip: pointer to index to leave open
- * ilen: insert length
- *
- * Returns:
- * Pointer to page in which to insert or NULL on error.
- */
-static PAGE *
-bt_page(t, h, lp, rp, skip, ilen)
- BTREE *t;
- PAGE *h, **lp, **rp;
- indx_t *skip;
- size_t ilen;
-{
- PAGE *l, *r, *tp;
- pgno_t npg;
-
-#ifdef STATISTICS
- ++bt_split;
-#endif
- /* Put the new right page for the split into place. */
- if ((r = __bt_new(t, &npg)) == NULL)
- return (NULL);
- r->pgno = npg;
- r->lower = BTDATAOFF;
- r->upper = t->bt_psize;
- r->nextpg = h->nextpg;
- r->prevpg = h->pgno;
- r->flags = h->flags & P_TYPE;
-
- /*
- * If we're splitting the last page on a level because we're appending
- * a key to it (skip is NEXTINDEX()), it's likely that the data is
- * sorted. Adding an empty page on the side of the level is less work
- * and can push the fill factor much higher than normal. If we're
- * wrong it's no big deal, we'll just do the split the right way next
- * time. It may look like it's equally easy to do a similar hack for
- * reverse sorted data, that is, split the tree left, but it's not.
- * Don't even try.
- */
- if (h->nextpg == P_INVALID && *skip == NEXTINDEX(h)) {
-#ifdef STATISTICS
- ++bt_sortsplit;
-#endif
- h->nextpg = r->pgno;
- r->lower = BTDATAOFF + sizeof(indx_t);
- *skip = 0;
- *lp = h;
- *rp = r;
- return (r);
- }
-
- /* Put the new left page for the split into place. */
- if ((l = (PAGE *)malloc(t->bt_psize)) == NULL) {
- mpool_put(t->bt_mp, r, 0);
- return (NULL);
- }
-#ifdef PURIFY
- memset(l, 0xff, t->bt_psize);
-#endif
- l->pgno = h->pgno;
- l->nextpg = r->pgno;
- l->prevpg = h->prevpg;
- l->lower = BTDATAOFF;
- l->upper = t->bt_psize;
- l->flags = h->flags & P_TYPE;
-
- /* Fix up the previous pointer of the page after the split page. */
- if (h->nextpg != P_INVALID) {
- if ((tp = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) {
- free(l);
- /* XXX mpool_free(t->bt_mp, r->pgno); */
- return (NULL);
- }
- tp->prevpg = r->pgno;
- mpool_put(t->bt_mp, tp, MPOOL_DIRTY);
- }
-
- /*
- * Split right. The key/data pairs aren't sorted in the btree page so
- * it's simpler to copy the data from the split page onto two new pages
- * instead of copying half the data to the right page and compacting
- * the left page in place. Since the left page can't change, we have
- * to swap the original and the allocated left page after the split.
- */
- tp = bt_psplit(t, h, l, r, skip, ilen);
-
- /* Move the new left page onto the old left page. */
- memmove(h, l, t->bt_psize);
- if (tp == l)
- tp = h;
- free(l);
-
- *lp = h;
- *rp = r;
- return (tp);
-}
-
-/*
- * BT_ROOT -- Split the root page of a btree.
- *
- * Parameters:
- * t: tree
- * h: root page
- * lp: pointer to left page pointer
- * rp: pointer to right page pointer
- * skip: pointer to index to leave open
- * ilen: insert length
- *
- * Returns:
- * Pointer to page in which to insert or NULL on error.
- */
-static PAGE *
-bt_root(t, h, lp, rp, skip, ilen)
- BTREE *t;
- PAGE *h, **lp, **rp;
- indx_t *skip;
- size_t ilen;
-{
- PAGE *l, *r, *tp;
- pgno_t lnpg, rnpg;
-
-#ifdef STATISTICS
- ++bt_split;
- ++bt_rootsplit;
-#endif
- /* Put the new left and right pages for the split into place. */
- if ((l = __bt_new(t, &lnpg)) == NULL ||
- (r = __bt_new(t, &rnpg)) == NULL)
- return (NULL);
- l->pgno = lnpg;
- r->pgno = rnpg;
- l->nextpg = r->pgno;
- r->prevpg = l->pgno;
- l->prevpg = r->nextpg = P_INVALID;
- l->lower = r->lower = BTDATAOFF;
- l->upper = r->upper = t->bt_psize;
- l->flags = r->flags = h->flags & P_TYPE;
-
- /* Split the root page. */
- tp = bt_psplit(t, h, l, r, skip, ilen);
-
- *lp = l;
- *rp = r;
- return (tp);
-}
-
-/*
- * BT_RROOT -- Fix up the recno root page after it has been split.
- *
- * Parameters:
- * t: tree
- * h: root page
- * l: left page
- * r: right page
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-static int
-bt_rroot(t, h, l, r)
- BTREE *t;
- PAGE *h, *l, *r;
-{
- char *dest;
-
- /* Insert the left and right keys, set the header information. */
- h->linp[0] = h->upper = t->bt_psize - NRINTERNAL;
- dest = (char *)h + h->upper;
- WR_RINTERNAL(dest,
- l->flags & P_RLEAF ? NEXTINDEX(l) : rec_total(l), l->pgno);
-
- h->linp[1] = h->upper -= NRINTERNAL;
- dest = (char *)h + h->upper;
- WR_RINTERNAL(dest,
- r->flags & P_RLEAF ? NEXTINDEX(r) : rec_total(r), r->pgno);
-
- h->lower = BTDATAOFF + 2 * sizeof(indx_t);
-
- /* Unpin the root page, set to recno internal page. */
- h->flags &= ~P_TYPE;
- h->flags |= P_RINTERNAL;
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
-
- return (RET_SUCCESS);
-}
-
-/*
- * BT_BROOT -- Fix up the btree root page after it has been split.
- *
- * Parameters:
- * t: tree
- * h: root page
- * l: left page
- * r: right page
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-static int
-bt_broot(t, h, l, r)
- BTREE *t;
- PAGE *h, *l, *r;
-{
- BINTERNAL *bi;
- BLEAF *bl;
- u_int32_t nbytes;
- char *dest;
-
- /*
- * If the root page was a leaf page, change it into an internal page.
- * We copy the key we split on (but not the key's data, in the case of
- * a leaf page) to the new root page.
- *
- * The btree comparison code guarantees that the left-most key on any
- * level of the tree is never used, so it doesn't need to be filled in.
- */
- nbytes = NBINTERNAL(0);
- h->linp[0] = h->upper = t->bt_psize - nbytes;
- dest = (char *)h + h->upper;
- WR_BINTERNAL(dest, 0, l->pgno, 0);
-
- switch (h->flags & P_TYPE) {
- case P_BLEAF:
- bl = GETBLEAF(r, 0);
- nbytes = NBINTERNAL(bl->ksize);
- h->linp[1] = h->upper -= nbytes;
- dest = (char *)h + h->upper;
- WR_BINTERNAL(dest, bl->ksize, r->pgno, 0);
- memmove(dest, bl->bytes, bl->ksize);
-
- /*
- * If the key is on an overflow page, mark the overflow chain
- * so it isn't deleted when the leaf copy of the key is deleted.
- */
- if (bl->flags & P_BIGKEY &&
- bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR)
- return (RET_ERROR);
- break;
- case P_BINTERNAL:
- bi = GETBINTERNAL(r, 0);
- nbytes = NBINTERNAL(bi->ksize);
- h->linp[1] = h->upper -= nbytes;
- dest = (char *)h + h->upper;
- memmove(dest, bi, nbytes);
- ((BINTERNAL *)dest)->pgno = r->pgno;
- break;
- default:
- abort();
- }
-
- /* There are two keys on the page. */
- h->lower = BTDATAOFF + 2 * sizeof(indx_t);
-
- /* Unpin the root page, set to btree internal page. */
- h->flags &= ~P_TYPE;
- h->flags |= P_BINTERNAL;
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
-
- return (RET_SUCCESS);
-}
-
-/*
- * BT_PSPLIT -- Do the real work of splitting the page.
- *
- * Parameters:
- * t: tree
- * h: page to be split
- * l: page to put lower half of data
- * r: page to put upper half of data
- * pskip: pointer to index to leave open
- * ilen: insert length
- *
- * Returns:
- * Pointer to page in which to insert.
- */
-static PAGE *
-bt_psplit(t, h, l, r, pskip, ilen)
- BTREE *t;
- PAGE *h, *l, *r;
- indx_t *pskip;
- size_t ilen;
-{
- BINTERNAL *bi;
- BLEAF *bl;
- CURSOR *c;
- RLEAF *rl;
- PAGE *rval;
- void *src = 0;
- indx_t full, half, nxt, off, skip, top, used;
- u_int32_t nbytes;
- int bigkeycnt, isbigkey;
-
- /*
- * Split the data to the left and right pages. Leave the skip index
- * open. Additionally, make some effort not to split on an overflow
- * key. This makes internal page processing faster and can save
- * space as overflow keys used by internal pages are never deleted.
- */
- bigkeycnt = 0;
- skip = *pskip;
- full = t->bt_psize - BTDATAOFF;
- half = full / 2;
- used = 0;
- for (nxt = off = 0, top = NEXTINDEX(h); nxt < top; ++off) {
- if (skip == off) {
- nbytes = ilen;
- isbigkey = 0; /* XXX: not really known. */
- } else
- switch (h->flags & P_TYPE) {
- case P_BINTERNAL:
- src = bi = GETBINTERNAL(h, nxt);
- nbytes = NBINTERNAL(bi->ksize);
- isbigkey = bi->flags & P_BIGKEY;
- break;
- case P_BLEAF:
- src = bl = GETBLEAF(h, nxt);
- nbytes = NBLEAF(bl);
- isbigkey = bl->flags & P_BIGKEY;
- break;
- case P_RINTERNAL:
- src = GETRINTERNAL(h, nxt);
- nbytes = NRINTERNAL;
- isbigkey = 0;
- break;
- case P_RLEAF:
- src = rl = GETRLEAF(h, nxt);
- nbytes = NRLEAF(rl);
- isbigkey = 0;
- break;
- default:
- abort();
- }
-
- /*
- * If the key/data pairs are substantial fractions of the max
- * possible size for the page, it's possible to get situations
- * where we decide to try and copy too much onto the left page.
- * Make sure that doesn't happen.
- */
- if ((skip <= off && used + nbytes + sizeof(indx_t) >= full)
- || nxt == top - 1) {
- --off;
- break;
- }
-
- /* Copy the key/data pair, if not the skipped index. */
- if (skip != off) {
- ++nxt;
-
- l->linp[off] = l->upper -= nbytes;
- memmove((char *)l + l->upper, src, nbytes);
- }
-
- used += nbytes + sizeof(indx_t);
- if (used >= half) {
- if (!isbigkey || bigkeycnt == 3)
- break;
- else
- ++bigkeycnt;
- }
- }
-
- /*
- * Off is the last offset that's valid for the left page.
- * Nxt is the first offset to be placed on the right page.
- */
- l->lower += (off + 1) * sizeof(indx_t);
-
- /*
- * If splitting the page that the cursor was on, the cursor has to be
- * adjusted to point to the same record as before the split. If the
- * cursor is at or past the skipped slot, the cursor is incremented by
- * one. If the cursor is on the right page, it is decremented by the
- * number of records split to the left page.
- */
- c = &t->bt_cursor;
- if (F_ISSET(c, CURS_INIT) && c->pg.pgno == h->pgno) {
- if (c->pg.index >= skip)
- ++c->pg.index;
- if (c->pg.index < nxt) /* Left page. */
- c->pg.pgno = l->pgno;
- else { /* Right page. */
- c->pg.pgno = r->pgno;
- c->pg.index -= nxt;
- }
- }
-
- /*
- * If the skipped index was on the left page, just return that page.
- * Otherwise, adjust the skip index to reflect the new position on
- * the right page.
- */
- if (skip <= off) {
- skip = 0;
- rval = l;
- } else {
- rval = r;
- *pskip -= nxt;
- }
-
- for (off = 0; nxt < top; ++off) {
- if (skip == nxt) {
- ++off;
- skip = 0;
- }
- switch (h->flags & P_TYPE) {
- case P_BINTERNAL:
- src = bi = GETBINTERNAL(h, nxt);
- nbytes = NBINTERNAL(bi->ksize);
- break;
- case P_BLEAF:
- src = bl = GETBLEAF(h, nxt);
- nbytes = NBLEAF(bl);
- break;
- case P_RINTERNAL:
- src = GETRINTERNAL(h, nxt);
- nbytes = NRINTERNAL;
- break;
- case P_RLEAF:
- src = rl = GETRLEAF(h, nxt);
- nbytes = NRLEAF(rl);
- break;
- default:
- abort();
- }
- ++nxt;
- r->linp[off] = r->upper -= nbytes;
- memmove((char *)r + r->upper, src, nbytes);
- }
- r->lower += off * sizeof(indx_t);
-
- /* If the key is being appended to the page, adjust the index. */
- if (skip == top)
- r->lower += sizeof(indx_t);
-
- return (rval);
-}
-
-/*
- * BT_PRESERVE -- Mark a chain of pages as used by an internal node.
- *
- * Chains of indirect blocks pointed to by leaf nodes get reclaimed when the
- * record that references them gets deleted. Chains pointed to by internal
- * pages never get deleted. This routine marks a chain as pointed to by an
- * internal page.
- *
- * Parameters:
- * t: tree
- * pg: page number of first page in the chain.
- *
- * Returns:
- * RET_SUCCESS, RET_ERROR.
- */
-static int
-bt_preserve(t, pg)
- BTREE *t;
- pgno_t pg;
-{
- PAGE *h;
-
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- return (RET_ERROR);
- h->flags |= P_PRESERVE;
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- return (RET_SUCCESS);
-}
-
-/*
- * REC_TOTAL -- Return the number of recno entries below a page.
- *
- * Parameters:
- * h: page
- *
- * Returns:
- * The number of recno entries below a page.
- *
- * XXX
- * These values could be set by the bt_psplit routine. The problem is that the
- * entry has to be popped off of the stack etc. or the values have to be passed
- * all the way back to bt_split/bt_rroot and it's not very clean.
- */
-static recno_t
-rec_total(h)
- PAGE *h;
-{
- recno_t recs;
- indx_t nxt, top;
-
- for (recs = 0, nxt = 0, top = NEXTINDEX(h); nxt < top; ++nxt)
- recs += GETRINTERNAL(h, nxt)->nrecs;
- return (recs);
-}
diff --git a/1.2-netsec/db1-ast/btree/bt_utils.c b/1.2-netsec/db1-ast/btree/bt_utils.c
deleted file mode 100644
index 1416c7862..000000000
--- a/1.2-netsec/db1-ast/btree/bt_utils.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_utils.c 8.8 (Berkeley) 7/20/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <db.h>
-#include "btree.h"
-
-/*
- * __bt_ret --
- * Build return key/data pair.
- *
- * Parameters:
- * t: tree
- * e: key/data pair to be returned
- * key: user's key structure (NULL if not to be filled in)
- * rkey: memory area to hold key
- * data: user's data structure (NULL if not to be filled in)
- * rdata: memory area to hold data
- * copy: always copy the key/data item
- *
- * Returns:
- * RET_SUCCESS, RET_ERROR.
- */
-int
-__bt_ret(t, e, key, rkey, data, rdata, copy)
- BTREE *t;
- EPG *e;
- DBT *key, *rkey, *data, *rdata;
- int copy;
-{
- BLEAF *bl;
- void *p;
-
- bl = GETBLEAF(e->page, e->index);
-
- /*
- * We must copy big keys/data to make them contiguous. Otherwise,
- * leave the page pinned and don't copy unless the user specified
- * concurrent access.
- */
- if (key == NULL)
- goto dataonly;
-
- if (bl->flags & P_BIGKEY) {
- if (__ovfl_get(t, bl->bytes,
- &key->size, &rkey->data, &rkey->size))
- return (RET_ERROR);
- key->data = rkey->data;
- } else if (copy || F_ISSET(t, B_DB_LOCK)) {
- if (bl->ksize > rkey->size) {
- p = (void *)(rkey->data == NULL ?
- malloc(bl->ksize) : realloc(rkey->data, bl->ksize));
- if (p == NULL)
- return (RET_ERROR);
- rkey->data = p;
- rkey->size = bl->ksize;
- }
- memmove(rkey->data, bl->bytes, bl->ksize);
- key->size = bl->ksize;
- key->data = rkey->data;
- } else {
- key->size = bl->ksize;
- key->data = bl->bytes;
- }
-
-dataonly:
- if (data == NULL)
- return (RET_SUCCESS);
-
- if (bl->flags & P_BIGDATA) {
- if (__ovfl_get(t, bl->bytes + bl->ksize,
- &data->size, &rdata->data, &rdata->size))
- return (RET_ERROR);
- data->data = rdata->data;
- } else if (copy || F_ISSET(t, B_DB_LOCK)) {
- /* Use +1 in case the first record retrieved is 0 length. */
- if (bl->dsize + 1 > rdata->size) {
- p = (void *)(rdata->data == NULL ?
- malloc(bl->dsize + 1) :
- realloc(rdata->data, bl->dsize + 1));
- if (p == NULL)
- return (RET_ERROR);
- rdata->data = p;
- rdata->size = bl->dsize + 1;
- }
- memmove(rdata->data, bl->bytes + bl->ksize, bl->dsize);
- data->size = bl->dsize;
- data->data = rdata->data;
- } else {
- data->size = bl->dsize;
- data->data = bl->bytes + bl->ksize;
- }
-
- return (RET_SUCCESS);
-}
-
-/*
- * __BT_CMP -- Compare a key to a given record.
- *
- * Parameters:
- * t: tree
- * k1: DBT pointer of first arg to comparison
- * e: pointer to EPG for comparison
- *
- * Returns:
- * < 0 if k1 is < record
- * = 0 if k1 is = record
- * > 0 if k1 is > record
- */
-int
-__bt_cmp(t, k1, e)
- BTREE *t;
- const DBT *k1;
- EPG *e;
-{
- BINTERNAL *bi;
- BLEAF *bl;
- DBT k2;
- PAGE *h;
- void *bigkey;
-
- /*
- * The left-most key on internal pages, at any level of the tree, is
- * guaranteed by the following code to be less than any user key.
- * This saves us from having to update the leftmost key on an internal
- * page when the user inserts a new key in the tree smaller than
- * anything we've yet seen.
- */
- h = e->page;
- if (e->index == 0 && h->prevpg == P_INVALID && !(h->flags & P_BLEAF))
- return (1);
-
- bigkey = NULL;
- if (h->flags & P_BLEAF) {
- bl = GETBLEAF(h, e->index);
- if (bl->flags & P_BIGKEY)
- bigkey = bl->bytes;
- else {
- k2.data = bl->bytes;
- k2.size = bl->ksize;
- }
- } else {
- bi = GETBINTERNAL(h, e->index);
- if (bi->flags & P_BIGKEY)
- bigkey = bi->bytes;
- else {
- k2.data = bi->bytes;
- k2.size = bi->ksize;
- }
- }
-
- if (bigkey) {
- if (__ovfl_get(t, bigkey,
- &k2.size, &t->bt_rdata.data, &t->bt_rdata.size))
- return (RET_ERROR);
- k2.data = t->bt_rdata.data;
- }
- return ((*t->bt_cmp)(k1, &k2));
-}
-
-/*
- * __BT_DEFCMP -- Default comparison routine.
- *
- * Parameters:
- * a: DBT #1
- * b: DBT #2
- *
- * Returns:
- * < 0 if a is < b
- * = 0 if a is = b
- * > 0 if a is > b
- */
-int
-__bt_defcmp(a, b)
- const DBT *a, *b;
-{
- register size_t len;
- register u_char *p1, *p2;
-
- /*
- * XXX
- * If a size_t doesn't fit in an int, this routine can lose.
- * What we need is a integral type which is guaranteed to be
- * larger than a size_t, and there is no such thing.
- */
- len = MIN(a->size, b->size);
- for (p1 = a->data, p2 = b->data; len--; ++p1, ++p2)
- if (*p1 != *p2)
- return ((int)*p1 - (int)*p2);
- return ((int)a->size - (int)b->size);
-}
-
-/*
- * __BT_DEFPFX -- Default prefix routine.
- *
- * Parameters:
- * a: DBT #1
- * b: DBT #2
- *
- * Returns:
- * Number of bytes needed to distinguish b from a.
- */
-size_t
-__bt_defpfx(a, b)
- const DBT *a, *b;
-{
- register u_char *p1, *p2;
- register size_t cnt, len;
-
- cnt = 1;
- len = MIN(a->size, b->size);
- for (p1 = a->data, p2 = b->data; len--; ++p1, ++p2, ++cnt)
- if (*p1 != *p2)
- return (cnt);
-
- /* a->size must be <= b->size, or they wouldn't be in this order. */
- return (a->size < b->size ? a->size + 1 : a->size);
-}
diff --git a/1.2-netsec/db1-ast/btree/btree.h b/1.2-netsec/db1-ast/btree/btree.h
deleted file mode 100644
index 1f4a9ec91..000000000
--- a/1.2-netsec/db1-ast/btree/btree.h
+++ /dev/null
@@ -1,391 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)btree.h 8.11 (Berkeley) 8/17/94
- */
-
-/* Macros to set/clear/test flags. */
-#define F_SET(p, f) (p)->flags |= (f)
-#define F_CLR(p, f) (p)->flags &= ~(f)
-#define F_ISSET(p, f) ((p)->flags & (f))
-
-#include <mpool.h>
-
-#define mpool_open __mpool_open
-#define mpool_filter __mpool_filter
-#define mpool_new __mpool_new
-#define mpool_get __mpool_get
-#define mpool_put __mpool_put
-#define mpool_sync __mpool_sync
-#define mpool_close __mpool_close
-
-#define DEFMINKEYPAGE (2) /* Minimum keys per page */
-#define MINCACHE (5) /* Minimum cached pages */
-#define MINPSIZE (512) /* Minimum page size */
-
-/*
- * Page 0 of a btree file contains a copy of the meta-data. This page is also
- * used as an out-of-band page, i.e. page pointers that point to nowhere point
- * to page 0. Page 1 is the root of the btree.
- */
-#define P_INVALID 0 /* Invalid tree page number. */
-#define P_META 0 /* Tree metadata page number. */
-#define P_ROOT 1 /* Tree root page number. */
-
-/*
- * There are five page layouts in the btree: btree internal pages (BINTERNAL),
- * btree leaf pages (BLEAF), recno internal pages (RINTERNAL), recno leaf pages
- * (RLEAF) and overflow pages. All five page types have a page header (PAGE).
- * This implementation requires that values within structures NOT be padded.
- * (ANSI C permits random padding.) If your compiler pads randomly you'll have
- * to do some work to get this package to run.
- */
-typedef struct _page {
- pgno_t pgno; /* this page's page number */
- pgno_t prevpg; /* left sibling */
- pgno_t nextpg; /* right sibling */
-
-#define P_BINTERNAL 0x01 /* btree internal page */
-#define P_BLEAF 0x02 /* leaf page */
-#define P_OVERFLOW 0x04 /* overflow page */
-#define P_RINTERNAL 0x08 /* recno internal page */
-#define P_RLEAF 0x10 /* leaf page */
-#define P_TYPE 0x1f /* type mask */
-#define P_PRESERVE 0x20 /* never delete this chain of pages */
- u_int32_t flags;
-
- indx_t lower; /* lower bound of free space on page */
- indx_t upper; /* upper bound of free space on page */
- indx_t linp[1]; /* indx_t-aligned VAR. LENGTH DATA */
-} PAGE;
-
-/* First and next index. */
-#define BTDATAOFF \
- (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t) + \
- sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t))
-#define NEXTINDEX(p) (((p)->lower - BTDATAOFF) / sizeof(indx_t))
-
-/*
- * For pages other than overflow pages, there is an array of offsets into the
- * rest of the page immediately following the page header. Each offset is to
- * an item which is unique to the type of page. The h_lower offset is just
- * past the last filled-in index. The h_upper offset is the first item on the
- * page. Offsets are from the beginning of the page.
- *
- * If an item is too big to store on a single page, a flag is set and the item
- * is a { page, size } pair such that the page is the first page of an overflow
- * chain with size bytes of item. Overflow pages are simply bytes without any
- * external structure.
- *
- * The page number and size fields in the items are pgno_t-aligned so they can
- * be manipulated without copying. (This presumes that 32 bit items can be
- * manipulated on this system.)
- */
-#define LALIGN(n) (((n) + sizeof(pgno_t) - 1) & ~(sizeof(pgno_t) - 1))
-#define NOVFLSIZE (sizeof(pgno_t) + sizeof(u_int32_t))
-
-/*
- * For the btree internal pages, the item is a key. BINTERNALs are {key, pgno}
- * pairs, such that the key compares less than or equal to all of the records
- * on that page. For a tree without duplicate keys, an internal page with two
- * consecutive keys, a and b, will have all records greater than or equal to a
- * and less than b stored on the page associated with a. Duplicate keys are
- * somewhat special and can cause duplicate internal and leaf page records and
- * some minor modifications of the above rule.
- */
-typedef struct _binternal {
- u_int32_t ksize; /* key size */
- pgno_t pgno; /* page number stored on */
-#define P_BIGDATA 0x01 /* overflow data */
-#define P_BIGKEY 0x02 /* overflow key */
- u_char flags;
- char bytes[1]; /* data */
-} BINTERNAL;
-
-/* Get the page's BINTERNAL structure at index indx. */
-#define GETBINTERNAL(pg, indx) \
- ((BINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
-
-/* Get the number of bytes in the entry. */
-#define NBINTERNAL(len) \
- LALIGN(sizeof(u_int32_t) + sizeof(pgno_t) + sizeof(u_char) + (len))
-
-/* Copy a BINTERNAL entry to the page. */
-#define WR_BINTERNAL(p, size, pgno, flags) { \
- *(u_int32_t *)p = size; \
- p += sizeof(u_int32_t); \
- *(pgno_t *)p = pgno; \
- p += sizeof(pgno_t); \
- *(u_char *)p = flags; \
- p += sizeof(u_char); \
-}
-
-/*
- * For the recno internal pages, the item is a page number with the number of
- * keys found on that page and below.
- */
-typedef struct _rinternal {
- recno_t nrecs; /* number of records */
- pgno_t pgno; /* page number stored below */
-} RINTERNAL;
-
-/* Get the page's RINTERNAL structure at index indx. */
-#define GETRINTERNAL(pg, indx) \
- ((RINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
-
-/* Get the number of bytes in the entry. */
-#define NRINTERNAL \
- LALIGN(sizeof(recno_t) + sizeof(pgno_t))
-
-/* Copy a RINTERNAL entry to the page. */
-#define WR_RINTERNAL(p, nrecs, pgno) { \
- *(recno_t *)p = nrecs; \
- p += sizeof(recno_t); \
- *(pgno_t *)p = pgno; \
-}
-
-/* For the btree leaf pages, the item is a key and data pair. */
-typedef struct _bleaf {
- u_int32_t ksize; /* size of key */
- u_int32_t dsize; /* size of data */
- u_char flags; /* P_BIGDATA, P_BIGKEY */
- char bytes[1]; /* data */
-} BLEAF;
-
-/* Get the page's BLEAF structure at index indx. */
-#define GETBLEAF(pg, indx) \
- ((BLEAF *)((char *)(pg) + (pg)->linp[indx]))
-
-/* Get the number of bytes in the entry. */
-#define NBLEAF(p) NBLEAFDBT((p)->ksize, (p)->dsize)
-
-/* Get the number of bytes in the user's key/data pair. */
-#define NBLEAFDBT(ksize, dsize) \
- LALIGN(sizeof(u_int32_t) + sizeof(u_int32_t) + sizeof(u_char) + \
- (ksize) + (dsize))
-
-/* Copy a BLEAF entry to the page. */
-#define WR_BLEAF(p, key, data, flags) { \
- *(u_int32_t *)p = key->size; \
- p += sizeof(u_int32_t); \
- *(u_int32_t *)p = data->size; \
- p += sizeof(u_int32_t); \
- *(u_char *)p = flags; \
- p += sizeof(u_char); \
- memmove(p, key->data, key->size); \
- p += key->size; \
- memmove(p, data->data, data->size); \
-}
-
-/* For the recno leaf pages, the item is a data entry. */
-typedef struct _rleaf {
- u_int32_t dsize; /* size of data */
- u_char flags; /* P_BIGDATA */
- char bytes[1];
-} RLEAF;
-
-/* Get the page's RLEAF structure at index indx. */
-#define GETRLEAF(pg, indx) \
- ((RLEAF *)((char *)(pg) + (pg)->linp[indx]))
-
-/* Get the number of bytes in the entry. */
-#define NRLEAF(p) NRLEAFDBT((p)->dsize)
-
-/* Get the number of bytes from the user's data. */
-#define NRLEAFDBT(dsize) \
- LALIGN(sizeof(u_int32_t) + sizeof(u_char) + (dsize))
-
-/* Copy a RLEAF entry to the page. */
-#define WR_RLEAF(p, data, flags) { \
- *(u_int32_t *)p = data->size; \
- p += sizeof(u_int32_t); \
- *(u_char *)p = flags; \
- p += sizeof(u_char); \
- memmove(p, data->data, data->size); \
-}
-
-/*
- * A record in the tree is either a pointer to a page and an index in the page
- * or a page number and an index. These structures are used as a cursor, stack
- * entry and search returns as well as to pass records to other routines.
- *
- * One comment about searches. Internal page searches must find the largest
- * record less than key in the tree so that descents work. Leaf page searches
- * must find the smallest record greater than key so that the returned index
- * is the record's correct position for insertion.
- */
-typedef struct _epgno {
- pgno_t pgno; /* the page number */
- indx_t index; /* the index on the page */
-} EPGNO;
-
-typedef struct _epg {
- PAGE *page; /* the (pinned) page */
- indx_t index; /* the index on the page */
-} EPG;
-
-/*
- * About cursors. The cursor (and the page that contained the key/data pair
- * that it referenced) can be deleted, which makes things a bit tricky. If
- * there are no duplicates of the cursor key in the tree (i.e. B_NODUPS is set
- * or there simply aren't any duplicates of the key) we copy the key that it
- * referenced when it's deleted, and reacquire a new cursor key if the cursor
- * is used again. If there are duplicates keys, we move to the next/previous
- * key, and set a flag so that we know what happened. NOTE: if duplicate (to
- * the cursor) keys are added to the tree during this process, it is undefined
- * if they will be returned or not in a cursor scan.
- *
- * The flags determine the possible states of the cursor:
- *
- * CURS_INIT The cursor references *something*.
- * CURS_ACQUIRE The cursor was deleted, and a key has been saved so that
- * we can reacquire the right position in the tree.
- * CURS_AFTER, CURS_BEFORE
- * The cursor was deleted, and now references a key/data pair
- * that has not yet been returned, either before or after the
- * deleted key/data pair.
- * XXX
- * This structure is broken out so that we can eventually offer multiple
- * cursors as part of the DB interface.
- */
-typedef struct _cursor {
- EPGNO pg; /* B: Saved tree reference. */
- DBT key; /* B: Saved key, or key.data == NULL. */
- recno_t rcursor; /* R: recno cursor (1-based) */
-
-#define CURS_ACQUIRE 0x01 /* B: Cursor needs to be reacquired. */
-#define CURS_AFTER 0x02 /* B: Unreturned cursor after key. */
-#define CURS_BEFORE 0x04 /* B: Unreturned cursor before key. */
-#define CURS_INIT 0x08 /* RB: Cursor initialized. */
- u_int8_t flags;
-} CURSOR;
-
-/*
- * The metadata of the tree. The nrecs field is used only by the RECNO code.
- * This is because the btree doesn't really need it and it requires that every
- * put or delete call modify the metadata.
- */
-typedef struct _btmeta {
- u_int32_t magic; /* magic number */
- u_int32_t version; /* version */
- u_int32_t psize; /* page size */
- u_int32_t free; /* page number of first free page */
- u_int32_t nrecs; /* R: number of records */
-
-#define SAVEMETA (B_NODUPS | R_RECNO)
- u_int32_t flags; /* bt_flags & SAVEMETA */
-} BTMETA;
-
-/* The in-memory btree/recno data structure. */
-typedef struct _btree {
- MPOOL *bt_mp; /* memory pool cookie */
-
- DB *bt_dbp; /* pointer to enclosing DB */
-
- EPG bt_cur; /* current (pinned) page */
- PAGE *bt_pinned; /* page pinned across calls */
-
- CURSOR bt_cursor; /* cursor */
-
-#define BT_PUSH(t, p, i) { \
- t->bt_sp->pgno = p; \
- t->bt_sp->index = i; \
- ++t->bt_sp; \
-}
-#define BT_POP(t) (t->bt_sp == t->bt_stack ? NULL : --t->bt_sp)
-#define BT_CLR(t) (t->bt_sp = t->bt_stack)
- EPGNO bt_stack[50]; /* stack of parent pages */
- EPGNO *bt_sp; /* current stack pointer */
-
- DBT bt_rkey; /* returned key */
- DBT bt_rdata; /* returned data */
-
- int bt_fd; /* tree file descriptor */
-
- pgno_t bt_free; /* next free page */
- u_int32_t bt_psize; /* page size */
- indx_t bt_ovflsize; /* cut-off for key/data overflow */
- int bt_lorder; /* byte order */
- /* sorted order */
- enum { NOT, BACK, FORWARD } bt_order;
- EPGNO bt_last; /* last insert */
-
- /* B: key comparison function */
- int (*bt_cmp) __P((const DBT *, const DBT *));
- /* B: prefix comparison function */
- size_t (*bt_pfx) __P((const DBT *, const DBT *));
- /* R: recno input function */
- int (*bt_irec) __P((struct _btree *, recno_t));
-
- FILE *bt_rfp; /* R: record FILE pointer */
- int bt_rfd; /* R: record file descriptor */
-
- caddr_t bt_cmap; /* R: current point in mapped space */
- caddr_t bt_smap; /* R: start of mapped space */
- caddr_t bt_emap; /* R: end of mapped space */
- size_t bt_msize; /* R: size of mapped region. */
-
- recno_t bt_nrecs; /* R: number of records */
- size_t bt_reclen; /* R: fixed record length */
- u_char bt_bval; /* R: delimiting byte/pad character */
-
-/*
- * NB:
- * B_NODUPS and R_RECNO are stored on disk, and may not be changed.
- */
-#define B_INMEM 0x00001 /* in-memory tree */
-#define B_METADIRTY 0x00002 /* need to write metadata */
-#define B_MODIFIED 0x00004 /* tree modified */
-#define B_NEEDSWAP 0x00008 /* if byte order requires swapping */
-#define B_RDONLY 0x00010 /* read-only tree */
-
-#define B_NODUPS 0x00020 /* no duplicate keys permitted */
-#define R_RECNO 0x00080 /* record oriented tree */
-
-#define R_CLOSEFP 0x00040 /* opened a file pointer */
-#define R_EOF 0x00100 /* end of input file reached. */
-#define R_FIXLEN 0x00200 /* fixed length records */
-#define R_MEMMAPPED 0x00400 /* memory mapped file. */
-#define R_INMEM 0x00800 /* in-memory file */
-#define R_MODIFIED 0x01000 /* modified file */
-#define R_RDONLY 0x02000 /* read-only file */
-
-#define B_DB_LOCK 0x04000 /* DB_LOCK specified. */
-#define B_DB_SHMEM 0x08000 /* DB_SHMEM specified. */
-#define B_DB_TXN 0x10000 /* DB_TXN specified. */
- u_int32_t flags;
-} BTREE;
-
-#include "extern.h"
diff --git a/1.2-netsec/db1-ast/btree/extern.h b/1.2-netsec/db1-ast/btree/extern.h
deleted file mode 100644
index ebd9c5492..000000000
--- a/1.2-netsec/db1-ast/btree/extern.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)extern.h 8.10 (Berkeley) 7/20/94
- */
-
-int __bt_close __P((DB *));
-int __bt_cmp __P((BTREE *, const DBT *, EPG *));
-int __bt_crsrdel __P((BTREE *, EPGNO *));
-int __bt_defcmp __P((const DBT *, const DBT *));
-size_t __bt_defpfx __P((const DBT *, const DBT *));
-int __bt_delete __P((const DB *, const DBT *, u_int));
-int __bt_dleaf __P((BTREE *, const DBT *, PAGE *, u_int));
-int __bt_fd __P((const DB *));
-int __bt_free __P((BTREE *, PAGE *));
-int __bt_get __P((const DB *, const DBT *, DBT *, u_int));
-PAGE *__bt_new __P((BTREE *, pgno_t *));
-void __bt_pgin __P((void *, pgno_t, void *));
-void __bt_pgout __P((void *, pgno_t, void *));
-int __bt_push __P((BTREE *, pgno_t, int));
-int __bt_put __P((const DB *dbp, DBT *, const DBT *, u_int));
-int __bt_ret __P((BTREE *, EPG *, DBT *, DBT *, DBT *, DBT *, int));
-EPG *__bt_search __P((BTREE *, const DBT *, int *));
-int __bt_seq __P((const DB *, DBT *, DBT *, u_int));
-void __bt_setcur __P((BTREE *, pgno_t, u_int));
-int __bt_split __P((BTREE *, PAGE *,
- const DBT *, const DBT *, int, size_t, u_int32_t));
-int __bt_sync __P((const DB *, u_int));
-
-int __ovfl_delete __P((BTREE *, void *));
-int __ovfl_get __P((BTREE *, void *, size_t *, void **, size_t *));
-int __ovfl_put __P((BTREE *, const DBT *, pgno_t *));
-
-#ifdef DEBUG
-void __bt_dnpage __P((DB *, pgno_t));
-void __bt_dpage __P((PAGE *));
-void __bt_dump __P((DB *));
-#endif
-#ifdef STATISTICS
-void __bt_stat __P((DB *));
-#endif
diff --git a/1.2-netsec/db1-ast/db/db.c b/1.2-netsec/db1-ast/db/db.c
deleted file mode 100644
index 5a74061e0..000000000
--- a/1.2-netsec/db1-ast/db/db.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)db.c 8.4 (Berkeley) 2/21/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stddef.h>
-#include <stdio.h>
-
-#include <db.h>
-
-#ifndef __APPLE__
-#define dbopen __dbopen
-#endif
-
-DB *
-dbopen(fname, flags, mode, type, openinfo)
- const char *fname;
- int flags, mode;
- DBTYPE type;
- const void *openinfo;
-{
-
-#define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN)
-#define USE_OPEN_FLAGS \
- (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \
- O_RDWR | O_SHLOCK | O_TRUNC)
-
- if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0)
- switch (type) {
- case DB_BTREE:
- return (__bt_open(fname, flags & USE_OPEN_FLAGS,
- mode, openinfo, flags & DB_FLAGS));
- case DB_HASH:
- return (__hash_open(fname, flags & USE_OPEN_FLAGS,
- mode, openinfo, flags & DB_FLAGS));
- case DB_RECNO:
- return (__rec_open(fname, flags & USE_OPEN_FLAGS,
- mode, openinfo, flags & DB_FLAGS));
- }
- errno = EINVAL;
- return (NULL);
-}
-#ifndef __APPLE__
-#undef dbopen
-#define weak_alias(original, alias) \
- asm (".weak " #alias "\n" #alias " = " #original);
-weak_alias (__dbopen, dbopen)
-#endif
-
-static int
-__dberr __P((void))
-{
- return (RET_ERROR);
-}
-
-/*
- * __DBPANIC -- Stop.
- *
- * Parameters:
- * dbp: pointer to the DB structure.
- */
-void
-__dbpanic(dbp)
- DB *dbp;
-{
- /* The only thing that can succeed is a close. */
- dbp->del = (int (*)__P((const struct __db *,
- const DBT *, u_int))) __dberr;
- dbp->get = (int (*)__P((const struct __db *,
- const DBT *, DBT *, u_int))) __dberr;
- dbp->put = (int (*)__P((const struct __db *,
- DBT *, const DBT *, u_int))) __dberr;
- dbp->seq = (int (*)__P((const struct __db *,
- DBT *, DBT *, u_int))) __dberr;
- dbp->sync = (int (*)__P((const struct __db *, u_int))) __dberr;
- dbp->fd = (int (*)__P((const struct __db *))) __dberr;
-}
diff --git a/1.2-netsec/db1-ast/hash/README b/1.2-netsec/db1-ast/hash/README
deleted file mode 100644
index f29ccf7e1..000000000
--- a/1.2-netsec/db1-ast/hash/README
+++ /dev/null
@@ -1,72 +0,0 @@
-# @(#)README 8.1 (Berkeley) 6/4/93
-
-This package implements a superset of the hsearch and dbm/ndbm libraries.
-
-Test Programs:
- All test programs which need key/data pairs expect them entered
- with key and data on separate lines
-
- tcreat3.c
- Takes
- bucketsize (bsize),
- fill factor (ffactor), and
- initial number of elements (nelem).
- Creates a hash table named hashtest containing the
- keys/data pairs entered from standard in.
- thash4.c
- Takes
- bucketsize (bsize),
- fill factor (ffactor),
- initial number of elements (nelem)
- bytes of cache (ncached), and
- file from which to read data (fname)
- Creates a table from the key/data pairs on standard in and
- then does a read of each key/data in fname
- tdel.c
- Takes
- bucketsize (bsize), and
- fill factor (ffactor).
- file from which to read data (fname)
- Reads each key/data pair from fname and deletes the
- key from the hash table hashtest
- tseq.c
- Reads the key/data pairs in the file hashtest and writes them
- to standard out.
- tread2.c
- Takes
- butes of cache (ncached).
- Reads key/data pairs from standard in and looks them up
- in the file hashtest.
- tverify.c
- Reads key/data pairs from standard in, looks them up
- in the file hashtest, and verifies that the data is
- correct.
-
-NOTES:
-
-The file search.h is provided for using the hsearch compatible interface
-on BSD systems. On System V derived systems, search.h should appear in
-/usr/include.
-
-The man page ../man/db.3 explains the interface to the hashing system.
-The file hash.ps is a postscript copy of a paper explaining
-the history, implementation, and performance of the hash package.
-
-"bugs" or idiosyncracies
-
-If you have a lot of overflows, it is possible to run out of overflow
-pages. Currently, this will cause a message to be printed on stderr.
-Eventually, this will be indicated by a return error code.
-
-If you are using the ndbm interface and exit without flushing or closing the
-file, you may lose updates since the package buffers all writes. Also,
-the db interface only creates a single database file. To avoid overwriting
-the user's original file, the suffix ".db" is appended to the file name
-passed to dbm_open. Additionally, if your code "knows" about the historic
-.dir and .pag files, it will break.
-
-There is a fundamental difference between this package and the old hsearch.
-Hsearch requires the user to maintain the keys and data in the application's
-allocated memory while hash takes care of all storage management. The down
-side is that the byte strings passed in the ENTRY structure must be null
-terminated (both the keys and the data).
diff --git a/1.2-netsec/db1-ast/hash/extern.h b/1.2-netsec/db1-ast/hash/extern.h
deleted file mode 100644
index 4f1f23d67..000000000
--- a/1.2-netsec/db1-ast/hash/extern.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)extern.h 8.4 (Berkeley) 6/16/94
- */
-
-BUFHEAD *__add_ovflpage __P((HTAB *, BUFHEAD *));
-int __addel __P((HTAB *, BUFHEAD *, const DBT *, const DBT *));
-int __big_delete __P((HTAB *, BUFHEAD *));
-int __big_insert __P((HTAB *, BUFHEAD *, const DBT *, const DBT *));
-int __big_keydata __P((HTAB *, BUFHEAD *, DBT *, DBT *, int));
-int __big_return __P((HTAB *, BUFHEAD *, int, DBT *, int));
-int __big_split __P((HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *,
- int, u_int32_t, SPLIT_RETURN *));
-int __buf_free __P((HTAB *, int, int));
-void __buf_init __P((HTAB *, int));
-u_int32_t __call_hash __P((HTAB *, char *, int));
-int __delpair __P((HTAB *, BUFHEAD *, int));
-int __expand_table __P((HTAB *));
-int __find_bigpair __P((HTAB *, BUFHEAD *, int, char *, int));
-u_int16_t __find_last_page __P((HTAB *, BUFHEAD **));
-void __free_ovflpage __P((HTAB *, BUFHEAD *));
-BUFHEAD *__get_buf __P((HTAB *, u_int32_t, BUFHEAD *, int));
-int __get_page __P((HTAB *, char *, u_int32_t, int, int, int));
-int __ibitmap __P((HTAB *, int, int, int));
-u_int32_t __hash_log2 __P((u_int32_t));
-int __put_page __P((HTAB *, char *, u_int32_t, int, int));
-void __reclaim_buf __P((HTAB *, BUFHEAD *));
-int __split_page __P((HTAB *, u_int32_t, u_int32_t));
-
-/* Default hash routine. */
-extern u_int32_t (*__default_hash) __P((const void *, size_t));
-
-#ifdef HASH_STATISTICS
-extern int hash_accesses, hash_collisions, hash_expansions, hash_overflows;
-#endif
diff --git a/1.2-netsec/db1-ast/hash/hash.c b/1.2-netsec/db1-ast/hash/hash.c
deleted file mode 100644
index 187cdca53..000000000
--- a/1.2-netsec/db1-ast/hash/hash.c
+++ /dev/null
@@ -1,1001 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#ifdef DEBUG
-#include <assert.h>
-#endif
-
-#include "../include/asterisk/compat.h"
-
-#include <db.h>
-#include "hash.h"
-#include "page.h"
-#include "extern.h"
-
-static int alloc_segs __P((HTAB *, int));
-static int flush_meta __P((HTAB *));
-static int hash_access __P((HTAB *, ACTION, DBT *, DBT *));
-static int hash_close __P((DB *));
-static int hash_delete __P((const DB *, const DBT *, u_int32_t));
-static int hash_fd __P((const DB *));
-static int hash_get __P((const DB *, const DBT *, DBT *, u_int32_t));
-static int hash_put __P((const DB *, DBT *, const DBT *, u_int32_t));
-static void *hash_realloc __P((SEGMENT **, int, int));
-static int hash_seq __P((const DB *, DBT *, DBT *, u_int32_t));
-static int hash_sync __P((const DB *, u_int32_t));
-static int hdestroy __P((HTAB *));
-static HTAB *init_hash __P((HTAB *, const char *, HASHINFO *));
-static int init_htab __P((HTAB *, int));
-#if BYTE_ORDER == LITTLE_ENDIAN
-static void swap_header __P((HTAB *));
-static void swap_header_copy __P((HASHHDR *, HASHHDR *));
-#endif
-
-/* Fast arithmetic, relying on powers of 2, */
-#define MOD(x, y) ((x) & ((y) - 1))
-
-#define RETURN_ERROR(ERR, LOC) { save_errno = ERR; goto LOC; }
-
-/* Return values */
-#define SUCCESS (0)
-#define ERROR (-1)
-#define ABNORMAL (1)
-
-#ifdef HASH_STATISTICS
-int hash_accesses, hash_collisions, hash_expansions, hash_overflows;
-#endif
-
-/************************** INTERFACE ROUTINES ***************************/
-/* OPEN/CLOSE */
-
-extern DB *
-__hash_open(file, flags, mode, info, dflags)
- const char *file;
- int flags, mode, dflags;
- const HASHINFO *info; /* Special directives for create */
-{
- HTAB *hashp;
- struct stat statbuf;
- DB *dbp;
- int bpages, hdrsize, new_table, nsegs, save_errno;
-
- if ((flags & O_ACCMODE) == O_WRONLY) {
- errno = EINVAL;
- return (NULL);
- }
-
- if (!(hashp = (HTAB *)calloc(1, sizeof(HTAB))))
- return (NULL);
- hashp->fp = -1;
-
- /*
- * Even if user wants write only, we need to be able to read
- * the actual file, so we need to open it read/write. But, the
- * field in the hashp structure needs to be accurate so that
- * we can check accesses.
- */
- hashp->flags = flags;
-
- new_table = 0;
- if (!file || (flags & O_TRUNC) ||
- (stat(file, &statbuf) && (errno == ENOENT))) {
- if (errno == ENOENT)
- errno = 0; /* Just in case someone looks at errno */
- new_table = 1;
- }
- if (file) {
- if ((hashp->fp = open(file, flags, mode)) == -1)
- RETURN_ERROR(errno, error0);
- (void)fcntl(hashp->fp, F_SETFD, 1);
- }
- if (new_table) {
- if (!(hashp = init_hash(hashp, file, (HASHINFO *)info)))
- RETURN_ERROR(errno, error1);
- } else {
- /* Table already exists */
- if (info && info->hash)
- hashp->hash = info->hash;
- else
- hashp->hash = __default_hash;
-
- hdrsize = read(hashp->fp, &hashp->hdr, sizeof(HASHHDR));
-#if BYTE_ORDER == LITTLE_ENDIAN
- swap_header(hashp);
-#endif
- if (hdrsize == -1)
- RETURN_ERROR(errno, error1);
- if (hdrsize != sizeof(HASHHDR))
- RETURN_ERROR(EFTYPE, error1);
- /* Verify file type, versions and hash function */
- if (hashp->MAGIC != HASHMAGIC)
- RETURN_ERROR(EFTYPE, error1);
-#define OLDHASHVERSION 1
- if (hashp->VERSION != HASHVERSION &&
- hashp->VERSION != OLDHASHVERSION)
- RETURN_ERROR(EFTYPE, error1);
- if (hashp->hash(CHARKEY, sizeof(CHARKEY))
- != (u_int32_t) hashp->H_CHARKEY)
- RETURN_ERROR(EFTYPE, error1);
- /*
- * Figure out how many segments we need. Max_Bucket is the
- * maximum bucket number, so the number of buckets is
- * max_bucket + 1.
- */
- nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) /
- hashp->SGSIZE;
- hashp->nsegs = 0;
- if (alloc_segs(hashp, nsegs))
- /*
- * If alloc_segs fails, table will have been destroyed
- * and errno will have been set.
- */
- return (NULL);
- /* Read in bitmaps */
- bpages = (hashp->SPARES[hashp->OVFL_POINT] +
- (hashp->BSIZE << BYTE_SHIFT) - 1) >>
- (hashp->BSHIFT + BYTE_SHIFT);
-
- hashp->nmaps = bpages;
- (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_int32_t *));
- }
-
- /* Initialize Buffer Manager */
- if (info && info->cachesize)
- __buf_init(hashp, info->cachesize);
- else
- __buf_init(hashp, DEF_BUFSIZE);
-
- hashp->new_file = new_table;
- hashp->save_file = file && (hashp->flags & O_ACCMODE) != O_RDONLY;
- hashp->cbucket = -1;
- if (!(dbp = (DB *)malloc(sizeof(DB)))) {
- save_errno = errno;
- hdestroy(hashp);
- errno = save_errno;
- return (NULL);
- }
- dbp->internal = hashp;
- dbp->close = hash_close;
- dbp->del = hash_delete;
- dbp->fd = hash_fd;
- dbp->get = hash_get;
- dbp->put = hash_put;
- dbp->seq = hash_seq;
- dbp->sync = hash_sync;
- dbp->type = DB_HASH;
-
-#ifdef DEBUG
- (void)fprintf(stderr,
-"%s\n%s%x\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%x\n%s%x\n%s%d\n%s%d\n",
- "init_htab:",
- "TABLE POINTER ", hashp,
- "BUCKET SIZE ", hashp->BSIZE,
- "BUCKET SHIFT ", hashp->BSHIFT,
- "DIRECTORY SIZE ", hashp->DSIZE,
- "SEGMENT SIZE ", hashp->SGSIZE,
- "SEGMENT SHIFT ", hashp->SSHIFT,
- "FILL FACTOR ", hashp->FFACTOR,
- "MAX BUCKET ", hashp->MAX_BUCKET,
- "OVFL POINT ", hashp->OVFL_POINT,
- "LAST FREED ", hashp->LAST_FREED,
- "HIGH MASK ", hashp->HIGH_MASK,
- "LOW MASK ", hashp->LOW_MASK,
- "NSEGS ", hashp->nsegs,
- "NKEYS ", hashp->NKEYS);
-#endif
-#ifdef HASH_STATISTICS
- hash_overflows = hash_accesses = hash_collisions = hash_expansions = 0;
-#endif
- return (dbp);
-
-error1:
- if (hashp != NULL)
- (void)close(hashp->fp);
-
-error0:
- free(hashp);
- errno = save_errno;
- return (NULL);
-}
-
-static int
-hash_close(dbp)
- DB *dbp;
-{
- HTAB *hashp;
- int retval;
-
- if (!dbp)
- return (ERROR);
-
- hashp = (HTAB *)dbp->internal;
- retval = hdestroy(hashp);
- free(dbp);
- return (retval);
-}
-
-static int
-hash_fd(dbp)
- const DB *dbp;
-{
- HTAB *hashp;
-
- if (!dbp)
- return (ERROR);
-
- hashp = (HTAB *)dbp->internal;
- if (hashp->fp == -1) {
- errno = ENOENT;
- return (-1);
- }
- return (hashp->fp);
-}
-
-/************************** LOCAL CREATION ROUTINES **********************/
-static HTAB *
-init_hash(hashp, file, info)
- HTAB *hashp;
- const char *file;
- HASHINFO *info;
-{
-#ifdef _STATBUF_ST_BLKSIZE
- struct stat statbuf;
-#endif
- int nelem;
-
- nelem = 1;
- hashp->NKEYS = 0;
- hashp->LORDER = BYTE_ORDER;
- hashp->BSIZE = DEF_BUCKET_SIZE;
- hashp->BSHIFT = DEF_BUCKET_SHIFT;
- hashp->SGSIZE = DEF_SEGSIZE;
- hashp->SSHIFT = DEF_SEGSIZE_SHIFT;
- hashp->DSIZE = DEF_DIRSIZE;
- hashp->FFACTOR = DEF_FFACTOR;
- hashp->hash = __default_hash;
- memset(hashp->SPARES, 0, sizeof(hashp->SPARES));
- memset(hashp->BITMAPS, 0, sizeof (hashp->BITMAPS));
-
- /* Fix bucket size to be optimal for file system */
-#ifdef _STATBUF_ST_BLKSIZE
- if (file != NULL) {
- if (stat(file, &statbuf))
- return (NULL);
- hashp->BSIZE = statbuf.st_blksize;
- hashp->BSHIFT = __hash_log2(hashp->BSIZE);
- }
-#endif
-
- if (info) {
- if (info->bsize) {
- /* Round pagesize up to power of 2 */
- hashp->BSHIFT = __hash_log2(info->bsize);
- hashp->BSIZE = 1 << hashp->BSHIFT;
- if (hashp->BSIZE > MAX_BSIZE) {
- errno = EINVAL;
- return (NULL);
- }
- }
- if (info->ffactor)
- hashp->FFACTOR = info->ffactor;
- if (info->hash)
- hashp->hash = info->hash;
- if (info->nelem)
- nelem = info->nelem;
- if (info->lorder) {
- if (info->lorder != BIG_ENDIAN &&
- info->lorder != LITTLE_ENDIAN) {
- errno = EINVAL;
- return (NULL);
- }
- hashp->LORDER = info->lorder;
- }
- }
- /* init_htab should destroy the table and set errno if it fails */
- if (init_htab(hashp, nelem))
- return (NULL);
- else
- return (hashp);
-}
-/*
- * This calls alloc_segs which may run out of memory. Alloc_segs will destroy
- * the table and set errno, so we just pass the error information along.
- *
- * Returns 0 on No Error
- */
-static int
-init_htab(hashp, nelem)
- HTAB *hashp;
- int nelem;
-{
- register int nbuckets, nsegs;
- int l2;
-
- /*
- * Divide number of elements by the fill factor and determine a
- * desired number of buckets. Allocate space for the next greater
- * power of two number of buckets.
- */
- nelem = (nelem - 1) / hashp->FFACTOR + 1;
-
- l2 = __hash_log2(MAX(nelem, 2));
- nbuckets = 1 << l2;
-
- hashp->SPARES[l2] = l2 + 1;
- hashp->SPARES[l2 + 1] = l2 + 1;
- hashp->OVFL_POINT = l2;
- hashp->LAST_FREED = 2;
-
- /* First bitmap page is at: splitpoint l2 page offset 1 */
- if (__ibitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0))
- return (-1);
-
- hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1;
- hashp->HIGH_MASK = (nbuckets << 1) - 1;
- hashp->HDRPAGES = ((MAX(sizeof(HASHHDR), MINHDRSIZE) - 1) >>
- hashp->BSHIFT) + 1;
-
- nsegs = (nbuckets - 1) / hashp->SGSIZE + 1;
- nsegs = 1 << __hash_log2(nsegs);
-
- if (nsegs > hashp->DSIZE)
- hashp->DSIZE = nsegs;
- return (alloc_segs(hashp, nsegs));
-}
-
-/********************** DESTROY/CLOSE ROUTINES ************************/
-
-/*
- * Flushes any changes to the file if necessary and destroys the hashp
- * structure, freeing all allocated space.
- */
-static int
-hdestroy(hashp)
- HTAB *hashp;
-{
- int i, save_errno;
-
- save_errno = 0;
-
-#ifdef HASH_STATISTICS
- (void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n",
- hash_accesses, hash_collisions);
- (void)fprintf(stderr, "hdestroy: expansions %ld\n",
- hash_expansions);
- (void)fprintf(stderr, "hdestroy: overflows %ld\n",
- hash_overflows);
- (void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n",
- hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs);
-
- for (i = 0; i < NCACHED; i++)
- (void)fprintf(stderr,
- "spares[%d] = %d\n", i, hashp->SPARES[i]);
-#endif
- /*
- * Call on buffer manager to free buffers, and if required,
- * write them to disk.
- */
- if (__buf_free(hashp, 1, hashp->save_file))
- save_errno = errno;
- if (hashp->dir) {
- free(*hashp->dir); /* Free initial segments */
- /* Free extra segments */
- while (hashp->exsegs--)
- free(hashp->dir[--hashp->nsegs]);
- free(hashp->dir);
- }
- if (flush_meta(hashp) && !save_errno)
- save_errno = errno;
- /* Free Bigmaps */
- for (i = 0; i < hashp->nmaps; i++)
- if (hashp->mapp[i])
- free(hashp->mapp[i]);
-
- if (hashp->fp != -1)
- (void)close(hashp->fp);
-
- free(hashp);
-
- if (save_errno) {
- errno = save_errno;
- return (ERROR);
- }
- return (SUCCESS);
-}
-/*
- * Write modified pages to disk
- *
- * Returns:
- * 0 == OK
- * -1 ERROR
- */
-static int
-hash_sync(dbp, flags)
- const DB *dbp;
- u_int32_t flags;
-{
- HTAB *hashp;
-
- if (flags != 0) {
- errno = EINVAL;
- return (ERROR);
- }
-
- if (!dbp)
- return (ERROR);
-
- hashp = (HTAB *)dbp->internal;
- if (!hashp->save_file)
- return (0);
- if (__buf_free(hashp, 0, 1) || flush_meta(hashp))
- return (ERROR);
- hashp->new_file = 0;
- return (0);
-}
-
-/*
- * Returns:
- * 0 == OK
- * -1 indicates that errno should be set
- */
-static int
-flush_meta(hashp)
- HTAB *hashp;
-{
- HASHHDR *whdrp;
-#if BYTE_ORDER == LITTLE_ENDIAN
- HASHHDR whdr;
-#endif
- int fp, i, wsize;
-
- if (!hashp->save_file)
- return (0);
- hashp->MAGIC = HASHMAGIC;
- hashp->VERSION = HASHVERSION;
- hashp->H_CHARKEY = hashp->hash(CHARKEY, sizeof(CHARKEY));
-
- fp = hashp->fp;
- whdrp = &hashp->hdr;
-#if BYTE_ORDER == LITTLE_ENDIAN
- whdrp = &whdr;
- swap_header_copy(&hashp->hdr, whdrp);
-#endif
- if ((lseek(fp, (off_t)0, SEEK_SET) == -1) ||
- ((wsize = write(fp, whdrp, sizeof(HASHHDR))) == -1))
- return (-1);
- else
- if (wsize != sizeof(HASHHDR)) {
- errno = EFTYPE;
- hashp->errnum = errno;
- return (-1);
- }
- for (i = 0; i < NCACHED; i++)
- if (hashp->mapp[i])
- if (__put_page(hashp, (char *)hashp->mapp[i],
- hashp->BITMAPS[i], 0, 1))
- return (-1);
- return (0);
-}
-
-/*******************************SEARCH ROUTINES *****************************/
-/*
- * All the access routines return
- *
- * Returns:
- * 0 on SUCCESS
- * 1 to indicate an external ERROR (i.e. key not found, etc)
- * -1 to indicate an internal ERROR (i.e. out of memory, etc)
- */
-static int
-hash_get(dbp, key, data, flag)
- const DB *dbp;
- const DBT *key;
- DBT *data;
- u_int32_t flag;
-{
- HTAB *hashp;
-
- hashp = (HTAB *)dbp->internal;
- if (flag) {
- hashp->errnum = errno = EINVAL;
- return (ERROR);
- }
- return (hash_access(hashp, HASH_GET, (DBT *)key, data));
-}
-
-static int
-hash_put(dbp, key, data, flag)
- const DB *dbp;
- DBT *key;
- const DBT *data;
- u_int32_t flag;
-{
- HTAB *hashp;
-
- hashp = (HTAB *)dbp->internal;
- if (flag && flag != R_NOOVERWRITE) {
- hashp->errnum = errno = EINVAL;
- return (ERROR);
- }
- if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
- hashp->errnum = errno = EPERM;
- return (ERROR);
- }
- return (hash_access(hashp, flag == R_NOOVERWRITE ?
- HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data));
-}
-
-static int
-hash_delete(dbp, key, flag)
- const DB *dbp;
- const DBT *key;
- u_int32_t flag; /* Ignored */
-{
- HTAB *hashp;
-
- hashp = (HTAB *)dbp->internal;
- if (flag && flag != R_CURSOR) {
- hashp->errnum = errno = EINVAL;
- return (ERROR);
- }
- if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
- hashp->errnum = errno = EPERM;
- return (ERROR);
- }
- return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL));
-}
-
-/*
- * Assume that hashp has been set in wrapper routine.
- */
-static int
-hash_access(hashp, action, key, val)
- HTAB *hashp;
- ACTION action;
- DBT *key, *val;
-{
- register BUFHEAD *rbufp;
- BUFHEAD *bufp, *save_bufp;
- register u_int16_t *bp;
- register int n, ndx, off, size;
- register char *kp;
- u_int16_t pageno;
-
-#ifdef HASH_STATISTICS
- hash_accesses++;
-#endif
-
- off = hashp->BSIZE;
- size = key->size;
- kp = (char *)key->data;
- rbufp = __get_buf(hashp, __call_hash(hashp, kp, size), NULL, 0);
- if (!rbufp)
- return (ERROR);
- save_bufp = rbufp;
-
- /* Pin the bucket chain */
- rbufp->flags |= BUF_PIN;
- for (bp = (u_int16_t *)rbufp->page, n = *bp++, ndx = 1; ndx < n;)
- if (bp[1] >= REAL_KEY) {
- /* Real key/data pair */
- if (size == off - *bp &&
- memcmp(kp, rbufp->page + *bp, size) == 0)
- goto found;
- off = bp[1];
-#ifdef HASH_STATISTICS
- hash_collisions++;
-#endif
- bp += 2;
- ndx += 2;
- } else if (bp[1] == OVFLPAGE) {
- rbufp = __get_buf(hashp, *bp, rbufp, 0);
- if (!rbufp) {
- save_bufp->flags &= ~BUF_PIN;
- return (ERROR);
- }
- /* FOR LOOP INIT */
- bp = (u_int16_t *)rbufp->page;
- n = *bp++;
- ndx = 1;
- off = hashp->BSIZE;
- } else if (bp[1] < REAL_KEY) {
- if ((ndx =
- __find_bigpair(hashp, rbufp, ndx, kp, size)) > 0)
- goto found;
- if (ndx == -2) {
- bufp = rbufp;
- if (!(pageno =
- __find_last_page(hashp, &bufp))) {
- ndx = 0;
- rbufp = bufp;
- break; /* FOR */
- }
- rbufp = __get_buf(hashp, pageno, bufp, 0);
- if (!rbufp) {
- save_bufp->flags &= ~BUF_PIN;
- return (ERROR);
- }
- /* FOR LOOP INIT */
- bp = (u_int16_t *)rbufp->page;
- n = *bp++;
- ndx = 1;
- off = hashp->BSIZE;
- } else {
- save_bufp->flags &= ~BUF_PIN;
- return (ERROR);
- }
- }
-
- /* Not found */
- switch (action) {
- case HASH_PUT:
- case HASH_PUTNEW:
- if (__addel(hashp, rbufp, key, val)) {
- save_bufp->flags &= ~BUF_PIN;
- return (ERROR);
- } else {
- save_bufp->flags &= ~BUF_PIN;
- return (SUCCESS);
- }
- case HASH_GET:
- case HASH_DELETE:
- default:
- save_bufp->flags &= ~BUF_PIN;
- return (ABNORMAL);
- }
-
-found:
- switch (action) {
- case HASH_PUTNEW:
- save_bufp->flags &= ~BUF_PIN;
- return (ABNORMAL);
- case HASH_GET:
- bp = (u_int16_t *)rbufp->page;
- if (bp[ndx + 1] < REAL_KEY) {
- if (__big_return(hashp, rbufp, ndx, val, 0))
- return (ERROR);
- } else {
- val->data = (u_char *)rbufp->page + (int)bp[ndx + 1];
- val->size = bp[ndx] - bp[ndx + 1];
- }
- break;
- case HASH_PUT:
- if ((__delpair(hashp, rbufp, ndx)) ||
- (__addel(hashp, rbufp, key, val))) {
- save_bufp->flags &= ~BUF_PIN;
- return (ERROR);
- }
- break;
- case HASH_DELETE:
- if (__delpair(hashp, rbufp, ndx))
- return (ERROR);
- break;
- default:
- abort();
- }
- save_bufp->flags &= ~BUF_PIN;
- return (SUCCESS);
-}
-
-static int
-hash_seq(dbp, key, data, flag)
- const DB *dbp;
- DBT *key, *data;
- u_int32_t flag;
-{
- register u_int32_t bucket;
- register BUFHEAD *bufp;
- HTAB *hashp;
- u_int16_t *bp, ndx;
-
- hashp = (HTAB *)dbp->internal;
- if (flag && flag != R_FIRST && flag != R_NEXT) {
- hashp->errnum = errno = EINVAL;
- return (ERROR);
- }
-#ifdef HASH_STATISTICS
- hash_accesses++;
-#endif
- if ((hashp->cbucket < 0) || (flag == R_FIRST)) {
- hashp->cbucket = 0;
- hashp->cndx = 1;
- hashp->cpage = NULL;
- }
-
- for (bp = NULL; !bp || !bp[0]; ) {
- if (!(bufp = hashp->cpage)) {
- for (bucket = hashp->cbucket;
- bucket <= (u_int32_t) hashp->MAX_BUCKET;
- bucket++, hashp->cndx = 1) {
- bufp = __get_buf(hashp, bucket, NULL, 0);
- if (!bufp)
- return (ERROR);
- hashp->cpage = bufp;
- bp = (u_int16_t *)bufp->page;
- if (bp[0])
- break;
- }
- hashp->cbucket = bucket;
- if (hashp->cbucket > hashp->MAX_BUCKET) {
- hashp->cbucket = -1;
- return (ABNORMAL);
- }
- } else
- bp = (u_int16_t *)hashp->cpage->page;
-
-#ifdef DEBUG
- assert(bp);
- assert(bufp);
-#endif
- while (bp[hashp->cndx + 1] == OVFLPAGE) {
- bufp = hashp->cpage =
- __get_buf(hashp, bp[hashp->cndx], bufp, 0);
- if (!bufp)
- return (ERROR);
- bp = (u_int16_t *)(bufp->page);
- hashp->cndx = 1;
- }
- if (!bp[0]) {
- hashp->cpage = NULL;
- ++hashp->cbucket;
- }
- }
- ndx = hashp->cndx;
- if (bp[ndx + 1] < REAL_KEY) {
- if (__big_keydata(hashp, bufp, key, data, 1))
- return (ERROR);
- } else {
- key->data = (u_char *)hashp->cpage->page + bp[ndx];
- key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx];
- data->data = (u_char *)hashp->cpage->page + bp[ndx + 1];
- data->size = bp[ndx] - bp[ndx + 1];
- ndx += 2;
- if (ndx > bp[0]) {
- hashp->cpage = NULL;
- hashp->cbucket++;
- hashp->cndx = 1;
- } else
- hashp->cndx = ndx;
- }
- return (SUCCESS);
-}
-
-/********************************* UTILITIES ************************/
-
-/*
- * Returns:
- * 0 ==> OK
- * -1 ==> Error
- */
-extern int
-__expand_table(hashp)
- HTAB *hashp;
-{
- u_int32_t old_bucket, new_bucket;
- int dirsize, new_segnum, spare_ndx;
-
-#ifdef HASH_STATISTICS
- hash_expansions++;
-#endif
- new_bucket = ++hashp->MAX_BUCKET;
- old_bucket = (hashp->MAX_BUCKET & hashp->LOW_MASK);
-
- new_segnum = new_bucket >> hashp->SSHIFT;
-
- /* Check if we need a new segment */
- if (new_segnum >= hashp->nsegs) {
- /* Check if we need to expand directory */
- if (new_segnum >= hashp->DSIZE) {
- /* Reallocate directory */
- dirsize = hashp->DSIZE * sizeof(SEGMENT *);
- if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1))
- return (-1);
- hashp->DSIZE = dirsize << 1;
- }
- if ((hashp->dir[new_segnum] =
- (SEGMENT)calloc(hashp->SGSIZE, sizeof(SEGMENT))) == NULL)
- return (-1);
- hashp->exsegs++;
- hashp->nsegs++;
- }
- /*
- * If the split point is increasing (MAX_BUCKET's log base 2
- * * increases), we need to copy the current contents of the spare
- * split bucket to the next bucket.
- */
- spare_ndx = __hash_log2(hashp->MAX_BUCKET + 1);
- if (spare_ndx > hashp->OVFL_POINT) {
- hashp->SPARES[spare_ndx] = hashp->SPARES[hashp->OVFL_POINT];
- hashp->OVFL_POINT = spare_ndx;
- }
-
- if (new_bucket > (u_int32_t) hashp->HIGH_MASK) {
- /* Starting a new doubling */
- hashp->LOW_MASK = hashp->HIGH_MASK;
- hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK;
- }
- /* Relocate records to the new bucket */
- return (__split_page(hashp, old_bucket, new_bucket));
-}
-
-/*
- * If realloc guarantees that the pointer is not destroyed if the realloc
- * fails, then this routine can go away.
- */
-static void *
-hash_realloc(p_ptr, oldsize, newsize)
- SEGMENT **p_ptr;
- int oldsize, newsize;
-{
- register void *p;
-
- if ((p = malloc(newsize))) {
- memmove(p, *p_ptr, oldsize);
- memset((char *)p + oldsize, 0, newsize - oldsize);
- free(*p_ptr);
- *p_ptr = p;
- }
- return (p);
-}
-
-extern u_int32_t
-__call_hash(hashp, k, len)
- HTAB *hashp;
- char *k;
- int len;
-{
- int n, bucket;
-
- n = hashp->hash(k, len);
- bucket = n & hashp->HIGH_MASK;
- if (bucket > hashp->MAX_BUCKET)
- bucket = bucket & hashp->LOW_MASK;
- return (bucket);
-}
-
-/*
- * Allocate segment table. On error, destroy the table and set errno.
- *
- * Returns 0 on success
- */
-static int
-alloc_segs(hashp, nsegs)
- HTAB *hashp;
- int nsegs;
-{
- register int i;
- register SEGMENT store;
-
- int save_errno;
-
- if ((hashp->dir =
- (SEGMENT *)calloc(hashp->DSIZE, sizeof(SEGMENT *))) == NULL) {
- save_errno = errno;
- (void)hdestroy(hashp);
- errno = save_errno;
- return (-1);
- }
- /* Allocate segments */
- if ((store =
- (SEGMENT)calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT))) == NULL) {
- save_errno = errno;
- (void)hdestroy(hashp);
- errno = save_errno;
- return (-1);
- }
- for (i = 0; i < nsegs; i++, hashp->nsegs++)
- hashp->dir[i] = &store[i << hashp->SSHIFT];
- return (0);
-}
-
-#if BYTE_ORDER == LITTLE_ENDIAN
-/*
- * Hashp->hdr needs to be byteswapped.
- */
-static void
-swap_header_copy(srcp, destp)
- HASHHDR *srcp, *destp;
-{
- int i;
-
- P_32_COPY(srcp->magic, destp->magic);
- P_32_COPY(srcp->version, destp->version);
- P_32_COPY(srcp->lorder, destp->lorder);
- P_32_COPY(srcp->bsize, destp->bsize);
- P_32_COPY(srcp->bshift, destp->bshift);
- P_32_COPY(srcp->dsize, destp->dsize);
- P_32_COPY(srcp->ssize, destp->ssize);
- P_32_COPY(srcp->sshift, destp->sshift);
- P_32_COPY(srcp->ovfl_point, destp->ovfl_point);
- P_32_COPY(srcp->last_freed, destp->last_freed);
- P_32_COPY(srcp->max_bucket, destp->max_bucket);
- P_32_COPY(srcp->high_mask, destp->high_mask);
- P_32_COPY(srcp->low_mask, destp->low_mask);
- P_32_COPY(srcp->ffactor, destp->ffactor);
- P_32_COPY(srcp->nkeys, destp->nkeys);
- P_32_COPY(srcp->hdrpages, destp->hdrpages);
- P_32_COPY(srcp->h_charkey, destp->h_charkey);
- for (i = 0; i < NCACHED; i++) {
- P_32_COPY(srcp->spares[i], destp->spares[i]);
- P_16_COPY(srcp->bitmaps[i], destp->bitmaps[i]);
- }
-}
-
-static void
-swap_header(hashp)
- HTAB *hashp;
-{
- HASHHDR *hdrp;
- int i;
-
- hdrp = &hashp->hdr;
-
- M_32_SWAP(hdrp->magic);
- M_32_SWAP(hdrp->version);
- M_32_SWAP(hdrp->lorder);
- M_32_SWAP(hdrp->bsize);
- M_32_SWAP(hdrp->bshift);
- M_32_SWAP(hdrp->dsize);
- M_32_SWAP(hdrp->ssize);
- M_32_SWAP(hdrp->sshift);
- M_32_SWAP(hdrp->ovfl_point);
- M_32_SWAP(hdrp->last_freed);
- M_32_SWAP(hdrp->max_bucket);
- M_32_SWAP(hdrp->high_mask);
- M_32_SWAP(hdrp->low_mask);
- M_32_SWAP(hdrp->ffactor);
- M_32_SWAP(hdrp->nkeys);
- M_32_SWAP(hdrp->hdrpages);
- M_32_SWAP(hdrp->h_charkey);
- for (i = 0; i < NCACHED; i++) {
- M_32_SWAP(hdrp->spares[i]);
- M_16_SWAP(hdrp->bitmaps[i]);
- }
-}
-#endif
diff --git a/1.2-netsec/db1-ast/hash/hash.h b/1.2-netsec/db1-ast/hash/hash.h
deleted file mode 100644
index d07db6f07..000000000
--- a/1.2-netsec/db1-ast/hash/hash.h
+++ /dev/null
@@ -1,293 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)hash.h 8.3 (Berkeley) 5/31/94
- */
-
-/* Operations */
-typedef enum {
- HASH_GET, HASH_PUT, HASH_PUTNEW, HASH_DELETE, HASH_FIRST, HASH_NEXT
-} ACTION;
-
-/* Buffer Management structures */
-typedef struct _bufhead BUFHEAD;
-
-struct _bufhead {
- BUFHEAD *prev; /* LRU links */
- BUFHEAD *next; /* LRU links */
- BUFHEAD *ovfl; /* Overflow page buffer header */
- u_int32_t addr; /* Address of this page */
- char *page; /* Actual page data */
- char flags;
-#define BUF_MOD 0x0001
-#define BUF_DISK 0x0002
-#define BUF_BUCKET 0x0004
-#define BUF_PIN 0x0008
-};
-
-#define IS_BUCKET(X) ((X) & BUF_BUCKET)
-
-typedef BUFHEAD **SEGMENT;
-
-/* Hash Table Information */
-typedef struct hashhdr { /* Disk resident portion */
- int magic; /* Magic NO for hash tables */
- int version; /* Version ID */
- u_int32_t lorder; /* Byte Order */
- int bsize; /* Bucket/Page Size */
- int bshift; /* Bucket shift */
- int dsize; /* Directory Size */
- int ssize; /* Segment Size */
- int sshift; /* Segment shift */
- int ovfl_point; /* Where overflow pages are being
- * allocated */
- int last_freed; /* Last overflow page freed */
- int max_bucket; /* ID of Maximum bucket in use */
- int high_mask; /* Mask to modulo into entire table */
- int low_mask; /* Mask to modulo into lower half of
- * table */
- int ffactor; /* Fill factor */
- int nkeys; /* Number of keys in hash table */
- int hdrpages; /* Size of table header */
- int h_charkey; /* value of hash(CHARKEY) */
-#define NCACHED 32 /* number of bit maps and spare
- * points */
- int spares[NCACHED];/* spare pages for overflow */
- u_int16_t bitmaps[NCACHED]; /* address of overflow page
- * bitmaps */
-} HASHHDR;
-
-typedef struct htab { /* Memory resident data structure */
- HASHHDR hdr; /* Header */
- int nsegs; /* Number of allocated segments */
- int exsegs; /* Number of extra allocated
- * segments */
- u_int32_t /* Hash function */
- (*hash)__P((const void *, size_t));
- int flags; /* Flag values */
- int fp; /* File pointer */
- char *tmp_buf; /* Temporary Buffer for BIG data */
- char *tmp_key; /* Temporary Buffer for BIG keys */
- BUFHEAD *cpage; /* Current page */
- int cbucket; /* Current bucket */
- int cndx; /* Index of next item on cpage */
- int errnum; /* Error Number -- for DBM
- * compatibility */
- int new_file; /* Indicates if fd is backing store
- * or no */
- int save_file; /* Indicates whether we need to flush
- * file at
- * exit */
- u_int32_t *mapp[NCACHED]; /* Pointers to page maps */
- int nmaps; /* Initial number of bitmaps */
- int nbufs; /* Number of buffers left to
- * allocate */
- BUFHEAD bufhead; /* Header of buffer lru list */
- SEGMENT *dir; /* Hash Bucket directory */
-} HTAB;
-
-/*
- * Constants
- */
-#define MAX_BSIZE 65536 /* 2^16 */
-#define MIN_BUFFERS 6
-#define MINHDRSIZE 512
-#define DEF_BUFSIZE 65536 /* 64 K */
-#define DEF_BUCKET_SIZE 4096
-#define DEF_BUCKET_SHIFT 12 /* log2(BUCKET) */
-#define DEF_SEGSIZE 256
-#define DEF_SEGSIZE_SHIFT 8 /* log2(SEGSIZE) */
-#define DEF_DIRSIZE 256
-#define DEF_FFACTOR 65536
-#define MIN_FFACTOR 4
-#define SPLTMAX 8
-#define CHARKEY "%$sniglet^&"
-#define NUMKEY 1038583
-#define BYTE_SHIFT 3
-#define INT_TO_BYTE 2
-#define INT_BYTE_SHIFT 5
-#define ALL_SET ((u_int32_t)0xFFFFFFFF)
-#define ALL_CLEAR 0
-
-#define PTROF(X) ((BUFHEAD *)((ptrdiff_t)(X)&~0x3))
-#define ISMOD(X) ((u_int32_t)(ptrdiff_t)(X)&0x1)
-#define DOMOD(X) ((X) = (char *)((ptrdiff_t)(X)|0x1))
-#define ISDISK(X) ((u_int32_t)(ptrdiff_t)(X)&0x2)
-#define DODISK(X) ((X) = (char *)((ptrdiff_t)(X)|0x2))
-
-#define BITS_PER_MAP 32
-
-/* Given the address of the beginning of a big map, clear/set the nth bit */
-#define CLRBIT(A, N) ((A)[(N)/BITS_PER_MAP] &= ~(1<<((N)%BITS_PER_MAP)))
-#define SETBIT(A, N) ((A)[(N)/BITS_PER_MAP] |= (1<<((N)%BITS_PER_MAP)))
-#define ISSET(A, N) ((A)[(N)/BITS_PER_MAP] & (1<<((N)%BITS_PER_MAP)))
-
-/* Overflow management */
-/*
- * Overflow page numbers are allocated per split point. At each doubling of
- * the table, we can allocate extra pages. So, an overflow page number has
- * the top 5 bits indicate which split point and the lower 11 bits indicate
- * which page at that split point is indicated (pages within split points are
- * numberered starting with 1).
- */
-
-#define SPLITSHIFT 11
-#define SPLITMASK 0x7FF
-#define SPLITNUM(N) (((u_int32_t)(N)) >> SPLITSHIFT)
-#define OPAGENUM(N) ((N) & SPLITMASK)
-#define OADDR_OF(S,O) ((u_int32_t)((u_int32_t)(S) << SPLITSHIFT) + (O))
-
-#define BUCKET_TO_PAGE(B) \
- (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__hash_log2((B)+1)-1] : 0)
-#define OADDR_TO_PAGE(B) \
- BUCKET_TO_PAGE ( (1 << SPLITNUM((B))) -1 ) + OPAGENUM((B));
-
-/*
- * page.h contains a detailed description of the page format.
- *
- * Normally, keys and data are accessed from offset tables in the top of
- * each page which point to the beginning of the key and data. There are
- * four flag values which may be stored in these offset tables which indicate
- * the following:
- *
- *
- * OVFLPAGE Rather than a key data pair, this pair contains
- * the address of an overflow page. The format of
- * the pair is:
- * OVERFLOW_PAGE_NUMBER OVFLPAGE
- *
- * PARTIAL_KEY This must be the first key/data pair on a page
- * and implies that page contains only a partial key.
- * That is, the key is too big to fit on a single page
- * so it starts on this page and continues on the next.
- * The format of the page is:
- * KEY_OFF PARTIAL_KEY OVFL_PAGENO OVFLPAGE
- *
- * KEY_OFF -- offset of the beginning of the key
- * PARTIAL_KEY -- 1
- * OVFL_PAGENO - page number of the next overflow page
- * OVFLPAGE -- 0
- *
- * FULL_KEY This must be the first key/data pair on the page. It
- * is used in two cases.
- *
- * Case 1:
- * There is a complete key on the page but no data
- * (because it wouldn't fit). The next page contains
- * the data.
- *
- * Page format it:
- * KEY_OFF FULL_KEY OVFL_PAGENO OVFL_PAGE
- *
- * KEY_OFF -- offset of the beginning of the key
- * FULL_KEY -- 2
- * OVFL_PAGENO - page number of the next overflow page
- * OVFLPAGE -- 0
- *
- * Case 2:
- * This page contains no key, but part of a large
- * data field, which is continued on the next page.
- *
- * Page format it:
- * DATA_OFF FULL_KEY OVFL_PAGENO OVFL_PAGE
- *
- * KEY_OFF -- offset of the beginning of the data on
- * this page
- * FULL_KEY -- 2
- * OVFL_PAGENO - page number of the next overflow page
- * OVFLPAGE -- 0
- *
- * FULL_KEY_DATA
- * This must be the first key/data pair on the page.
- * There are two cases:
- *
- * Case 1:
- * This page contains a key and the beginning of the
- * data field, but the data field is continued on the
- * next page.
- *
- * Page format is:
- * KEY_OFF FULL_KEY_DATA OVFL_PAGENO DATA_OFF
- *
- * KEY_OFF -- offset of the beginning of the key
- * FULL_KEY_DATA -- 3
- * OVFL_PAGENO - page number of the next overflow page
- * DATA_OFF -- offset of the beginning of the data
- *
- * Case 2:
- * This page contains the last page of a big data pair.
- * There is no key, only the tail end of the data
- * on this page.
- *
- * Page format is:
- * DATA_OFF FULL_KEY_DATA <OVFL_PAGENO> <OVFLPAGE>
- *
- * DATA_OFF -- offset of the beginning of the data on
- * this page
- * FULL_KEY_DATA -- 3
- * OVFL_PAGENO - page number of the next overflow page
- * OVFLPAGE -- 0
- *
- * OVFL_PAGENO and OVFLPAGE are optional (they are
- * not present if there is no next page).
- */
-
-#define OVFLPAGE 0
-#define PARTIAL_KEY 1
-#define FULL_KEY 2
-#define FULL_KEY_DATA 3
-#define REAL_KEY 4
-
-/* Short hands for accessing structure */
-#define BSIZE hdr.bsize
-#define BSHIFT hdr.bshift
-#define DSIZE hdr.dsize
-#define SGSIZE hdr.ssize
-#define SSHIFT hdr.sshift
-#define LORDER hdr.lorder
-#define OVFL_POINT hdr.ovfl_point
-#define LAST_FREED hdr.last_freed
-#define MAX_BUCKET hdr.max_bucket
-#define FFACTOR hdr.ffactor
-#define HIGH_MASK hdr.high_mask
-#define LOW_MASK hdr.low_mask
-#define NKEYS hdr.nkeys
-#define HDRPAGES hdr.hdrpages
-#define SPARES hdr.spares
-#define BITMAPS hdr.bitmaps
-#define VERSION hdr.version
-#define MAGIC hdr.magic
-#define NEXT_FREE hdr.next_free
-#define H_CHARKEY hdr.h_charkey
diff --git a/1.2-netsec/db1-ast/hash/hash_bigkey.c b/1.2-netsec/db1-ast/hash/hash_bigkey.c
deleted file mode 100644
index 94c64083f..000000000
--- a/1.2-netsec/db1-ast/hash/hash_bigkey.c
+++ /dev/null
@@ -1,668 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_bigkey.c 8.3 (Berkeley) 5/31/94";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * PACKAGE: hash
- * DESCRIPTION:
- * Big key/data handling for the hashing package.
- *
- * ROUTINES:
- * External
- * __big_keydata
- * __big_split
- * __big_insert
- * __big_return
- * __big_delete
- * __find_last_page
- * Internal
- * collect_key
- * collect_data
- */
-
-#include <sys/param.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef DEBUG
-#include <assert.h>
-#endif
-
-#include <db.h>
-#include "hash.h"
-#include "page.h"
-#include "extern.h"
-
-static int collect_key __P((HTAB *, BUFHEAD *, int, DBT *, int));
-static int collect_data __P((HTAB *, BUFHEAD *, int, int));
-
-/*
- * Big_insert
- *
- * You need to do an insert and the key/data pair is too big
- *
- * Returns:
- * 0 ==> OK
- *-1 ==> ERROR
- */
-extern int
-__big_insert(hashp, bufp, key, val)
- HTAB *hashp;
- BUFHEAD *bufp;
- const DBT *key, *val;
-{
- register u_int16_t *p;
- int key_size, n, val_size;
- u_int16_t space, move_bytes, off;
- char *cp, *key_data, *val_data;
-
- cp = bufp->page; /* Character pointer of p. */
- p = (u_int16_t *)cp;
-
- key_data = (char *)key->data;
- key_size = key->size;
- val_data = (char *)val->data;
- val_size = val->size;
-
- /* First move the Key */
- for (space = FREESPACE(p) - BIGOVERHEAD; key_size;
- space = FREESPACE(p) - BIGOVERHEAD) {
- move_bytes = MIN(space, key_size);
- off = OFFSET(p) - move_bytes;
- memmove(cp + off, key_data, move_bytes);
- key_size -= move_bytes;
- key_data += move_bytes;
- n = p[0];
- p[++n] = off;
- p[0] = ++n;
- FREESPACE(p) = off - PAGE_META(n);
- OFFSET(p) = off;
- p[n] = PARTIAL_KEY;
- bufp = __add_ovflpage(hashp, bufp);
- if (!bufp)
- return (-1);
- n = p[0];
- if (!key_size) {
- if (FREESPACE(p)) {
- move_bytes = MIN(FREESPACE(p), val_size);
- off = OFFSET(p) - move_bytes;
- p[n] = off;
- memmove(cp + off, val_data, move_bytes);
- val_data += move_bytes;
- val_size -= move_bytes;
- p[n - 2] = FULL_KEY_DATA;
- FREESPACE(p) = FREESPACE(p) - move_bytes;
- OFFSET(p) = off;
- } else
- p[n - 2] = FULL_KEY;
- }
- p = (u_int16_t *)bufp->page;
- cp = bufp->page;
- bufp->flags |= BUF_MOD;
- }
-
- /* Now move the data */
- for (space = FREESPACE(p) - BIGOVERHEAD; val_size;
- space = FREESPACE(p) - BIGOVERHEAD) {
- move_bytes = MIN(space, val_size);
- /*
- * Here's the hack to make sure that if the data ends on the
- * same page as the key ends, FREESPACE is at least one.
- */
- if ((int) space == val_size && (size_t) val_size == val->size)
- move_bytes--;
- off = OFFSET(p) - move_bytes;
- memmove(cp + off, val_data, move_bytes);
- val_size -= move_bytes;
- val_data += move_bytes;
- n = p[0];
- p[++n] = off;
- p[0] = ++n;
- FREESPACE(p) = off - PAGE_META(n);
- OFFSET(p) = off;
- if (val_size) {
- p[n] = FULL_KEY;
- bufp = __add_ovflpage(hashp, bufp);
- if (!bufp)
- return (-1);
- cp = bufp->page;
- p = (u_int16_t *)cp;
- } else
- p[n] = FULL_KEY_DATA;
- bufp->flags |= BUF_MOD;
- }
- return (0);
-}
-
-/*
- * Called when bufp's page contains a partial key (index should be 1)
- *
- * All pages in the big key/data pair except bufp are freed. We cannot
- * free bufp because the page pointing to it is lost and we can't get rid
- * of its pointer.
- *
- * Returns:
- * 0 => OK
- *-1 => ERROR
- */
-extern int
-__big_delete(hashp, bufp)
- HTAB *hashp;
- BUFHEAD *bufp;
-{
- register BUFHEAD *last_bfp, *rbufp;
- u_int16_t *bp, pageno;
- int key_done, n;
-
- rbufp = bufp;
- last_bfp = NULL;
- bp = (u_int16_t *)bufp->page;
- pageno = 0;
- key_done = 0;
-
- while (!key_done || (bp[2] != FULL_KEY_DATA)) {
- if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA)
- key_done = 1;
-
- /*
- * If there is freespace left on a FULL_KEY_DATA page, then
- * the data is short and fits entirely on this page, and this
- * is the last page.
- */
- if (bp[2] == FULL_KEY_DATA && FREESPACE(bp))
- break;
- pageno = bp[bp[0] - 1];
- rbufp->flags |= BUF_MOD;
- rbufp = __get_buf(hashp, pageno, rbufp, 0);
- if (last_bfp)
- __free_ovflpage(hashp, last_bfp);
- last_bfp = rbufp;
- if (!rbufp)
- return (-1); /* Error. */
- bp = (u_int16_t *)rbufp->page;
- }
-
- /*
- * If we get here then rbufp points to the last page of the big
- * key/data pair. Bufp points to the first one -- it should now be
- * empty pointing to the next page after this pair. Can't free it
- * because we don't have the page pointing to it.
- */
-
- /* This is information from the last page of the pair. */
- n = bp[0];
- pageno = bp[n - 1];
-
- /* Now, bp is the first page of the pair. */
- bp = (u_int16_t *)bufp->page;
- if (n > 2) {
- /* There is an overflow page. */
- bp[1] = pageno;
- bp[2] = OVFLPAGE;
- bufp->ovfl = rbufp->ovfl;
- } else
- /* This is the last page. */
- bufp->ovfl = NULL;
- n -= 2;
- bp[0] = n;
- FREESPACE(bp) = hashp->BSIZE - PAGE_META(n);
- OFFSET(bp) = hashp->BSIZE - 1;
-
- bufp->flags |= BUF_MOD;
- if (rbufp)
- __free_ovflpage(hashp, rbufp);
- if (last_bfp && last_bfp != rbufp)
- __free_ovflpage(hashp, last_bfp);
-
- hashp->NKEYS--;
- return (0);
-}
-/*
- * Returns:
- * 0 = key not found
- * -1 = get next overflow page
- * -2 means key not found and this is big key/data
- * -3 error
- */
-extern int
-__find_bigpair(hashp, bufp, ndx, key, size)
- HTAB *hashp;
- BUFHEAD *bufp;
- int ndx;
- char *key;
- int size;
-{
- register u_int16_t *bp;
- register char *p;
- int ksize;
- u_int16_t bytes;
- char *kkey;
-
- bp = (u_int16_t *)bufp->page;
- p = bufp->page;
- ksize = size;
- kkey = key;
-
- for (bytes = hashp->BSIZE - bp[ndx];
- bytes <= size && bp[ndx + 1] == PARTIAL_KEY;
- bytes = hashp->BSIZE - bp[ndx]) {
- if (memcmp(p + bp[ndx], kkey, bytes))
- return (-2);
- kkey += bytes;
- ksize -= bytes;
- bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0);
- if (!bufp)
- return (-3);
- p = bufp->page;
- bp = (u_int16_t *)p;
- ndx = 1;
- }
-
- if (bytes != ksize || memcmp(p + bp[ndx], kkey, bytes)) {
-#ifdef HASH_STATISTICS
- ++hash_collisions;
-#endif
- return (-2);
- } else
- return (ndx);
-}
-
-/*
- * Given the buffer pointer of the first overflow page of a big pair,
- * find the end of the big pair
- *
- * This will set bpp to the buffer header of the last page of the big pair.
- * It will return the pageno of the overflow page following the last page
- * of the pair; 0 if there isn't any (i.e. big pair is the last key in the
- * bucket)
- */
-extern u_int16_t
-__find_last_page(hashp, bpp)
- HTAB *hashp;
- BUFHEAD **bpp;
-{
- BUFHEAD *bufp;
- u_int16_t *bp, pageno;
- int n;
-
- bufp = *bpp;
- bp = (u_int16_t *)bufp->page;
- for (;;) {
- n = bp[0];
-
- /*
- * This is the last page if: the tag is FULL_KEY_DATA and
- * either only 2 entries OVFLPAGE marker is explicit there
- * is freespace on the page.
- */
- if (bp[2] == FULL_KEY_DATA &&
- ((n == 2) || (bp[n] == OVFLPAGE) || (FREESPACE(bp))))
- break;
-
- pageno = bp[n - 1];
- bufp = __get_buf(hashp, pageno, bufp, 0);
- if (!bufp)
- return (0); /* Need to indicate an error! */
- bp = (u_int16_t *)bufp->page;
- }
-
- *bpp = bufp;
- if (bp[0] > 2)
- return (bp[3]);
- else
- return (0);
-}
-
-/*
- * Return the data for the key/data pair that begins on this page at this
- * index (index should always be 1).
- */
-extern int
-__big_return(hashp, bufp, ndx, val, set_current)
- HTAB *hashp;
- BUFHEAD *bufp;
- int ndx;
- DBT *val;
- int set_current;
-{
- BUFHEAD *save_p;
- u_int16_t *bp, len, off, save_addr;
- char *tp;
-
- bp = (u_int16_t *)bufp->page;
- while (bp[ndx + 1] == PARTIAL_KEY) {
- bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
- if (!bufp)
- return (-1);
- bp = (u_int16_t *)bufp->page;
- ndx = 1;
- }
-
- if (bp[ndx + 1] == FULL_KEY) {
- bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
- if (!bufp)
- return (-1);
- bp = (u_int16_t *)bufp->page;
- save_p = bufp;
- save_addr = save_p->addr;
- off = bp[1];
- len = 0;
- } else
- if (!FREESPACE(bp)) {
- /*
- * This is a hack. We can't distinguish between
- * FULL_KEY_DATA that contains complete data or
- * incomplete data, so we require that if the data
- * is complete, there is at least 1 byte of free
- * space left.
- */
- off = bp[bp[0]];
- len = bp[1] - off;
- save_p = bufp;
- save_addr = bufp->addr;
- bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
- if (!bufp)
- return (-1);
- bp = (u_int16_t *)bufp->page;
- } else {
- /* The data is all on one page. */
- tp = (char *)bp;
- off = bp[bp[0]];
- val->data = (u_char *)tp + off;
- val->size = bp[1] - off;
- if (set_current) {
- if (bp[0] == 2) { /* No more buckets in
- * chain */
- hashp->cpage = NULL;
- hashp->cbucket++;
- hashp->cndx = 1;
- } else {
- hashp->cpage = __get_buf(hashp,
- bp[bp[0] - 1], bufp, 0);
- if (!hashp->cpage)
- return (-1);
- hashp->cndx = 1;
- if (!((u_int16_t *)
- hashp->cpage->page)[0]) {
- hashp->cbucket++;
- hashp->cpage = NULL;
- }
- }
- }
- return (0);
- }
-
- val->size = collect_data(hashp, bufp, (int)len, set_current);
- if (val->size == (size_t) -1)
- return (-1);
- if (save_p->addr != save_addr) {
- /* We are pretty short on buffers. */
- errno = EINVAL; /* OUT OF BUFFERS */
- return (-1);
- }
- memmove(hashp->tmp_buf, (save_p->page) + off, len);
- val->data = (u_char *)hashp->tmp_buf;
- return (0);
-}
-/*
- * Count how big the total datasize is by recursing through the pages. Then
- * allocate a buffer and copy the data as you recurse up.
- */
-static int
-collect_data(hashp, bufp, len, set)
- HTAB *hashp;
- BUFHEAD *bufp;
- int len, set;
-{
- register u_int16_t *bp;
- register char *p;
- BUFHEAD *xbp;
- u_int16_t save_addr;
- int mylen, totlen;
-
- p = bufp->page;
- bp = (u_int16_t *)p;
- mylen = hashp->BSIZE - bp[1];
- save_addr = bufp->addr;
-
- if (bp[2] == FULL_KEY_DATA) { /* End of Data */
- totlen = len + mylen;
- if (hashp->tmp_buf)
- free(hashp->tmp_buf);
- if ((hashp->tmp_buf = (char *)malloc(totlen)) == NULL)
- return (-1);
- if (set) {
- hashp->cndx = 1;
- if (bp[0] == 2) { /* No more buckets in chain */
- hashp->cpage = NULL;
- hashp->cbucket++;
- } else {
- hashp->cpage =
- __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
- if (!hashp->cpage)
- return (-1);
- else if (!((u_int16_t *)hashp->cpage->page)[0]) {
- hashp->cbucket++;
- hashp->cpage = NULL;
- }
- }
- }
- } else {
- xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
- if (!xbp || ((totlen =
- collect_data(hashp, xbp, len + mylen, set)) < 1))
- return (-1);
- }
- if (bufp->addr != save_addr) {
- errno = EINVAL; /* Out of buffers. */
- return (-1);
- }
- memmove(&hashp->tmp_buf[len], (bufp->page) + bp[1], mylen);
- return (totlen);
-}
-
-/*
- * Fill in the key and data for this big pair.
- */
-extern int
-__big_keydata(hashp, bufp, key, val, set)
- HTAB *hashp;
- BUFHEAD *bufp;
- DBT *key, *val;
- int set;
-{
- key->size = collect_key(hashp, bufp, 0, val, set);
- if (key->size == (size_t) -1)
- return (-1);
- key->data = (u_char *)hashp->tmp_key;
- return (0);
-}
-
-/*
- * Count how big the total key size is by recursing through the pages. Then
- * collect the data, allocate a buffer and copy the key as you recurse up.
- */
-static int
-collect_key(hashp, bufp, len, val, set)
- HTAB *hashp;
- BUFHEAD *bufp;
- int len;
- DBT *val;
- int set;
-{
- BUFHEAD *xbp;
- char *p;
- int mylen, totlen;
- u_int16_t *bp, save_addr;
-
- p = bufp->page;
- bp = (u_int16_t *)p;
- mylen = hashp->BSIZE - bp[1];
-
- save_addr = bufp->addr;
- totlen = len + mylen;
- if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) { /* End of Key. */
- if (hashp->tmp_key != NULL)
- free(hashp->tmp_key);
- if ((hashp->tmp_key = (char *)malloc(totlen)) == NULL)
- return (-1);
- if (__big_return(hashp, bufp, 1, val, set))
- return (-1);
- } else {
- xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
- if (!xbp || ((totlen =
- collect_key(hashp, xbp, totlen, val, set)) < 1))
- return (-1);
- }
- if (bufp->addr != save_addr) {
- errno = EINVAL; /* MIS -- OUT OF BUFFERS */
- return (-1);
- }
- memmove(&hashp->tmp_key[len], (bufp->page) + bp[1], mylen);
- return (totlen);
-}
-
-/*
- * Returns:
- * 0 => OK
- * -1 => error
- */
-extern int
-__big_split(hashp, op, np, big_keyp, addr, obucket, ret)
- HTAB *hashp;
- BUFHEAD *op; /* Pointer to where to put keys that go in old bucket */
- BUFHEAD *np; /* Pointer to new bucket page */
- /* Pointer to first page containing the big key/data */
- BUFHEAD *big_keyp;
- int addr; /* Address of big_keyp */
- u_int32_t obucket;/* Old Bucket */
- SPLIT_RETURN *ret;
-{
- register BUFHEAD *tmpp;
- register u_int16_t *tp;
- BUFHEAD *bp;
- DBT key, val;
- u_int32_t change;
- u_int16_t free_space, n, off;
-
- bp = big_keyp;
-
- /* Now figure out where the big key/data goes */
- if (__big_keydata(hashp, big_keyp, &key, &val, 0))
- return (-1);
- change = (__call_hash(hashp, key.data, key.size) != obucket);
-
- if ((ret->next_addr = __find_last_page(hashp, &big_keyp))) {
- if (!(ret->nextp =
- __get_buf(hashp, ret->next_addr, big_keyp, 0)))
- return (-1);;
- } else
- ret->nextp = NULL;
-
- /* Now make one of np/op point to the big key/data pair */
-#ifdef DEBUG
- assert(np->ovfl == NULL);
-#endif
- if (change)
- tmpp = np;
- else
- tmpp = op;
-
- tmpp->flags |= BUF_MOD;
-#ifdef DEBUG1
- (void)fprintf(stderr,
- "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr,
- (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0));
-#endif
- tmpp->ovfl = bp; /* one of op/np point to big_keyp */
- tp = (u_int16_t *)tmpp->page;
-#ifdef DEBUG
- assert(FREESPACE(tp) >= OVFLSIZE);
-#endif
- n = tp[0];
- off = OFFSET(tp);
- free_space = FREESPACE(tp);
- tp[++n] = (u_int16_t)addr;
- tp[++n] = OVFLPAGE;
- tp[0] = n;
- OFFSET(tp) = off;
- FREESPACE(tp) = free_space - OVFLSIZE;
-
- /*
- * Finally, set the new and old return values. BIG_KEYP contains a
- * pointer to the last page of the big key_data pair. Make sure that
- * big_keyp has no following page (2 elements) or create an empty
- * following page.
- */
-
- ret->newp = np;
- ret->oldp = op;
-
- tp = (u_int16_t *)big_keyp->page;
- big_keyp->flags |= BUF_MOD;
- if (tp[0] > 2) {
- /*
- * There may be either one or two offsets on this page. If
- * there is one, then the overflow page is linked on normally
- * and tp[4] is OVFLPAGE. If there are two, tp[4] contains
- * the second offset and needs to get stuffed in after the
- * next overflow page is added.
- */
- n = tp[4];
- free_space = FREESPACE(tp);
- off = OFFSET(tp);
- tp[0] -= 2;
- FREESPACE(tp) = free_space + OVFLSIZE;
- OFFSET(tp) = off;
- tmpp = __add_ovflpage(hashp, big_keyp);
- if (!tmpp)
- return (-1);
- tp[4] = n;
- } else
- tmpp = big_keyp;
-
- if (change)
- ret->newp = tmpp;
- else
- ret->oldp = tmpp;
- return (0);
-}
diff --git a/1.2-netsec/db1-ast/hash/hash_buf.c b/1.2-netsec/db1-ast/hash/hash_buf.c
deleted file mode 100644
index f47a7b08e..000000000
--- a/1.2-netsec/db1-ast/hash/hash_buf.c
+++ /dev/null
@@ -1,355 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * PACKAGE: hash
- *
- * DESCRIPTION:
- * Contains buffer management
- *
- * ROUTINES:
- * External
- * __buf_init
- * __get_buf
- * __buf_free
- * __reclaim_buf
- * Internal
- * newbuf
- */
-
-#include <sys/param.h>
-
-#include <errno.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifdef DEBUG
-#include <assert.h>
-#endif
-
-#include <db.h>
-#include "hash.h"
-#include "page.h"
-#include "extern.h"
-
-static BUFHEAD *newbuf __P((HTAB *, u_int32_t, BUFHEAD *));
-
-/* Unlink B from its place in the lru */
-#define BUF_REMOVE(B) { \
- (B)->prev->next = (B)->next; \
- (B)->next->prev = (B)->prev; \
-}
-
-/* Insert B after P */
-#define BUF_INSERT(B, P) { \
- (B)->next = (P)->next; \
- (B)->prev = (P); \
- (P)->next = (B); \
- (B)->next->prev = (B); \
-}
-
-#define MRU hashp->bufhead.next
-#define LRU hashp->bufhead.prev
-
-#define MRU_INSERT(B) BUF_INSERT((B), &hashp->bufhead)
-#define LRU_INSERT(B) BUF_INSERT((B), LRU)
-
-/*
- * We are looking for a buffer with address "addr". If prev_bp is NULL, then
- * address is a bucket index. If prev_bp is not NULL, then it points to the
- * page previous to an overflow page that we are trying to find.
- *
- * CAVEAT: The buffer header accessed via prev_bp's ovfl field may no longer
- * be valid. Therefore, you must always verify that its address matches the
- * address you are seeking.
- */
-extern BUFHEAD *
-__get_buf(hashp, addr, prev_bp, newpage)
- HTAB *hashp;
- u_int32_t addr;
- BUFHEAD *prev_bp;
- int newpage; /* If prev_bp set, indicates a new overflow page. */
-{
- register BUFHEAD *bp;
- register u_int32_t is_disk_mask;
- register int is_disk, segment_ndx = 0;
- SEGMENT segp = 0;
-
- is_disk = 0;
- is_disk_mask = 0;
- if (prev_bp) {
- bp = prev_bp->ovfl;
- if (!bp || (bp->addr != addr))
- bp = NULL;
- if (!newpage)
- is_disk = BUF_DISK;
- } else {
- /* Grab buffer out of directory */
- segment_ndx = addr & (hashp->SGSIZE - 1);
-
- /* valid segment ensured by __call_hash() */
- segp = hashp->dir[addr >> hashp->SSHIFT];
-#ifdef DEBUG
- assert(segp != NULL);
-#endif
- bp = PTROF(segp[segment_ndx]);
- is_disk_mask = ISDISK(segp[segment_ndx]);
- is_disk = is_disk_mask || !hashp->new_file;
- }
-
- if (!bp) {
- bp = newbuf(hashp, addr, prev_bp);
- if (!bp ||
- __get_page(hashp, bp->page, addr, !prev_bp, is_disk, 0))
- return (NULL);
- if (!prev_bp)
- segp[segment_ndx] =
- (BUFHEAD *)((ptrdiff_t)bp | is_disk_mask);
- } else {
- BUF_REMOVE(bp);
- MRU_INSERT(bp);
- }
- return (bp);
-}
-
-/*
- * We need a buffer for this page. Either allocate one, or evict a resident
- * one (if we have as many buffers as we're allowed) and put this one in.
- *
- * If newbuf finds an error (returning NULL), it also sets errno.
- */
-static BUFHEAD *
-newbuf(hashp, addr, prev_bp)
- HTAB *hashp;
- u_int32_t addr;
- BUFHEAD *prev_bp;
-{
- register BUFHEAD *bp; /* The buffer we're going to use */
- register BUFHEAD *xbp; /* Temp pointer */
- register BUFHEAD *next_xbp;
- SEGMENT segp;
- int segment_ndx;
- u_int16_t oaddr, *shortp;
-
- oaddr = 0;
- bp = LRU;
- /*
- * If LRU buffer is pinned, the buffer pool is too small. We need to
- * allocate more buffers.
- */
- if (hashp->nbufs || (bp->flags & BUF_PIN)) {
- /* Allocate a new one */
- if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL)
- return (NULL);
-#ifdef PURIFY
- memset(bp, 0xff, sizeof(BUFHEAD));
-#endif
- if ((bp->page = (char *)malloc(hashp->BSIZE)) == NULL) {
- free(bp);
- return (NULL);
- }
-#ifdef PURIFY
- memset(bp->page, 0xff, hashp->BSIZE);
-#endif
- if (hashp->nbufs)
- hashp->nbufs--;
- } else {
- /* Kick someone out */
- BUF_REMOVE(bp);
- /*
- * If this is an overflow page with addr 0, it's already been
- * flushed back in an overflow chain and initialized.
- */
- if ((bp->addr != 0) || (bp->flags & BUF_BUCKET)) {
- /*
- * Set oaddr before __put_page so that you get it
- * before bytes are swapped.
- */
- shortp = (u_int16_t *)bp->page;
- if (shortp[0])
- oaddr = shortp[shortp[0] - 1];
- if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page,
- bp->addr, (int)IS_BUCKET(bp->flags), 0))
- return (NULL);
- /*
- * Update the pointer to this page (i.e. invalidate it).
- *
- * If this is a new file (i.e. we created it at open
- * time), make sure that we mark pages which have been
- * written to disk so we retrieve them from disk later,
- * rather than allocating new pages.
- */
- if (IS_BUCKET(bp->flags)) {
- segment_ndx = bp->addr & (hashp->SGSIZE - 1);
- segp = hashp->dir[bp->addr >> hashp->SSHIFT];
-#ifdef DEBUG
- assert(segp != NULL);
-#endif
-
- if (hashp->new_file &&
- ((bp->flags & BUF_MOD) ||
- ISDISK(segp[segment_ndx])))
- segp[segment_ndx] = (BUFHEAD *)BUF_DISK;
- else
- segp[segment_ndx] = NULL;
- }
- /*
- * Since overflow pages can only be access by means of
- * their bucket, free overflow pages associated with
- * this bucket.
- */
- for (xbp = bp; xbp->ovfl;) {
- next_xbp = xbp->ovfl;
- xbp->ovfl = 0;
- xbp = next_xbp;
-
- /* Check that ovfl pointer is up date. */
- if (IS_BUCKET(xbp->flags) ||
- (oaddr != xbp->addr))
- break;
-
- shortp = (u_int16_t *)xbp->page;
- if (shortp[0])
- /* set before __put_page */
- oaddr = shortp[shortp[0] - 1];
- if ((xbp->flags & BUF_MOD) && __put_page(hashp,
- xbp->page, xbp->addr, 0, 0))
- return (NULL);
- xbp->addr = 0;
- xbp->flags = 0;
- BUF_REMOVE(xbp);
- LRU_INSERT(xbp);
- }
- }
- }
-
- /* Now assign this buffer */
- bp->addr = addr;
-#ifdef DEBUG1
- (void)fprintf(stderr, "NEWBUF1: %d->ovfl was %d is now %d\n",
- bp->addr, (bp->ovfl ? bp->ovfl->addr : 0), 0);
-#endif
- bp->ovfl = NULL;
- if (prev_bp) {
- /*
- * If prev_bp is set, this is an overflow page, hook it in to
- * the buffer overflow links.
- */
-#ifdef DEBUG1
- (void)fprintf(stderr, "NEWBUF2: %d->ovfl was %d is now %d\n",
- prev_bp->addr, (prev_bp->ovfl ? bp->ovfl->addr : 0),
- (bp ? bp->addr : 0));
-#endif
- prev_bp->ovfl = bp;
- bp->flags = 0;
- } else
- bp->flags = BUF_BUCKET;
- MRU_INSERT(bp);
- return (bp);
-}
-
-extern void
-__buf_init(hashp, nbytes)
- HTAB *hashp;
- int nbytes;
-{
- BUFHEAD *bfp;
- int npages;
-
- bfp = &(hashp->bufhead);
- npages = (nbytes + hashp->BSIZE - 1) >> hashp->BSHIFT;
- npages = MAX(npages, MIN_BUFFERS);
-
- hashp->nbufs = npages;
- bfp->next = bfp;
- bfp->prev = bfp;
- /*
- * This space is calloc'd so these are already null.
- *
- * bfp->ovfl = NULL;
- * bfp->flags = 0;
- * bfp->page = NULL;
- * bfp->addr = 0;
- */
-}
-
-extern int
-__buf_free(hashp, do_free, to_disk)
- HTAB *hashp;
- int do_free, to_disk;
-{
- BUFHEAD *bp;
-
- /* Need to make sure that buffer manager has been initialized */
- if (!LRU)
- return (0);
- for (bp = LRU; bp != &hashp->bufhead;) {
- /* Check that the buffer is valid */
- if (bp->addr || IS_BUCKET(bp->flags)) {
- if (to_disk && (bp->flags & BUF_MOD) &&
- __put_page(hashp, bp->page,
- bp->addr, IS_BUCKET(bp->flags), 0))
- return (-1);
- }
- /* Check if we are freeing stuff */
- if (do_free) {
- if (bp->page)
- free(bp->page);
- BUF_REMOVE(bp);
- free(bp);
- bp = LRU;
- } else
- bp = bp->prev;
- }
- return (0);
-}
-
-extern void
-__reclaim_buf(hashp, bp)
- HTAB *hashp;
- BUFHEAD *bp;
-{
- bp->ovfl = 0;
- bp->addr = 0;
- bp->flags = 0;
- BUF_REMOVE(bp);
- LRU_INSERT(bp);
-}
diff --git a/1.2-netsec/db1-ast/hash/hash_func.c b/1.2-netsec/db1-ast/hash/hash_func.c
deleted file mode 100644
index 4ec5def8c..000000000
--- a/1.2-netsec/db1-ast/hash/hash_func.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_func.c 8.2 (Berkeley) 2/21/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <db.h>
-#include "hash.h"
-#include "page.h"
-#include "extern.h"
-
-/* only one of these can be defined */
-/* #define HASH1_EJB 1 */
-/* #define HASH2_PHONG 1 */
-/* #define HASH3_SDBM 1 */
-#define HASH4_TOREK 1
-
-static u_int32_t hashfunc __P((const void *, size_t));
-
-/* Global default hash function */
-u_int32_t (*__default_hash) __P((const void *, size_t)) = hashfunc;
-
-/*
- * HASH FUNCTIONS
- *
- * Assume that we've already split the bucket to which this key hashes,
- * calculate that bucket, and check that in fact we did already split it.
- *
- * This came from ejb's hsearch.
- */
-
-#ifdef HASH1_EJB
-
-#define PRIME1 37
-#define PRIME2 1048583
-
-static u_int32_t
-hashfunc(keyarg, len)
- const void *keyarg;
- register size_t len;
-{
- register const u_char *key;
- register u_int32_t h;
-
- /* Convert string to integer */
- for (key = keyarg, h = 0; len--;)
- h = h * PRIME1 ^ (*key++ - ' ');
- h %= PRIME2;
- return (h);
-}
-
-#endif
-
-#ifdef HASH2_PHONG
-/*
- * Phong's linear congruential hash
- */
-#define dcharhash(h, c) ((h) = 0x63c63cd9*(h) + 0x9c39c33d + (c))
-
-static u_int32_t
-hashfunc(keyarg, len)
- const void *keyarg;
- size_t len;
-{
- register const u_char *e, *key;
- register u_int32_t h;
- register u_char c;
-
- key = keyarg;
- e = key + len;
- for (h = 0; key != e;) {
- c = *key++;
- if (!c && key > e)
- break;
- dcharhash(h, c);
- }
- return (h);
-}
-#endif
-
-#ifdef HASH3_SDBM
-/*
- * This is INCREDIBLY ugly, but fast. We break the string up into 8 byte
- * units. On the first time through the loop we get the "leftover bytes"
- * (strlen % 8). On every other iteration, we perform 8 HASHC's so we handle
- * all 8 bytes. Essentially, this saves us 7 cmp & branch instructions. If
- * this routine is heavily used enough, it's worth the ugly coding.
- *
- * OZ's original sdbm hash
- */
-static u_int32_t
-hashfunc(keyarg, len)
- const void *keyarg;
- register size_t len;
-{
- register const u_char *key;
- register size_t loop;
- register u_int32_t h;
-
-#define HASHC h = *key++ + 65599 * h
-
- h = 0;
- key = keyarg;
- if (len > 0) {
- loop = (len + 8 - 1) >> 3;
-
- switch (len & (8 - 1)) {
- case 0:
- do {
- HASHC;
- /* FALLTHROUGH */
- case 7:
- HASHC;
- /* FALLTHROUGH */
- case 6:
- HASHC;
- /* FALLTHROUGH */
- case 5:
- HASHC;
- /* FALLTHROUGH */
- case 4:
- HASHC;
- /* FALLTHROUGH */
- case 3:
- HASHC;
- /* FALLTHROUGH */
- case 2:
- HASHC;
- /* FALLTHROUGH */
- case 1:
- HASHC;
- } while (--loop);
- }
- }
- return (h);
-}
-#endif
-
-#ifdef HASH4_TOREK
-/* Hash function from Chris Torek. */
-static u_int32_t
-hashfunc(keyarg, len)
- const void *keyarg;
- register size_t len;
-{
- register const u_char *key;
- register size_t loop;
- register u_int32_t h;
-
-#define HASH4a h = (h << 5) - h + *key++;
-#define HASH4b h = (h << 5) + h + *key++;
-#define HASH4 HASH4b
-
- h = 0;
- key = keyarg;
- if (len > 0) {
- loop = (len + 8 - 1) >> 3;
-
- switch (len & (8 - 1)) {
- case 0:
- do {
- HASH4;
- /* FALLTHROUGH */
- case 7:
- HASH4;
- /* FALLTHROUGH */
- case 6:
- HASH4;
- /* FALLTHROUGH */
- case 5:
- HASH4;
- /* FALLTHROUGH */
- case 4:
- HASH4;
- /* FALLTHROUGH */
- case 3:
- HASH4;
- /* FALLTHROUGH */
- case 2:
- HASH4;
- /* FALLTHROUGH */
- case 1:
- HASH4;
- } while (--loop);
- }
- }
- return (h);
-}
-#endif
diff --git a/1.2-netsec/db1-ast/hash/hash_log2.c b/1.2-netsec/db1-ast/hash/hash_log2.c
deleted file mode 100644
index 6bcf9c114..000000000
--- a/1.2-netsec/db1-ast/hash/hash_log2.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_log2.c 8.2 (Berkeley) 5/31/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <db.h>
-
-u_int32_t __hash_log2 __P((u_int32_t));
-
-u_int32_t
-__hash_log2(num)
- u_int32_t num;
-{
- register u_int32_t i, limit;
-
- limit = 1;
- for (i = 0; limit < num; limit = limit << 1, i++);
- return (i);
-}
diff --git a/1.2-netsec/db1-ast/hash/hash_page.c b/1.2-netsec/db1-ast/hash/hash_page.c
deleted file mode 100644
index 1429dd6c3..000000000
--- a/1.2-netsec/db1-ast/hash/hash_page.c
+++ /dev/null
@@ -1,944 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * PACKAGE: hashing
- *
- * DESCRIPTION:
- * Page manipulation for hashing package.
- *
- * ROUTINES:
- *
- * External
- * __get_page
- * __add_ovflpage
- * Internal
- * overflow_page
- * open_temp
- */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#ifdef DEBUG
-#include <assert.h>
-#endif
-
-#include <db.h>
-#include "hash.h"
-#include "page.h"
-#include "extern.h"
-
-static u_int32_t *fetch_bitmap __P((HTAB *, int));
-static u_int32_t first_free __P((u_int32_t));
-static int open_temp __P((HTAB *));
-static u_int16_t overflow_page __P((HTAB *));
-static void putpair __P((char *, const DBT *, const DBT *));
-static void squeeze_key __P((u_int16_t *, const DBT *, const DBT *));
-static int ugly_split
- __P((HTAB *, u_int32_t, BUFHEAD *, BUFHEAD *, int, int));
-
-#define PAGE_INIT(P) { \
- ((u_int16_t *)(P))[0] = 0; \
- ((u_int16_t *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_int16_t); \
- ((u_int16_t *)(P))[2] = hashp->BSIZE; \
-}
-
-/*
- * This is called AFTER we have verified that there is room on the page for
- * the pair (PAIRFITS has returned true) so we go right ahead and start moving
- * stuff on.
- */
-static void
-putpair(p, key, val)
- char *p;
- const DBT *key, *val;
-{
- register u_int16_t *bp, n, off;
-
- bp = (u_int16_t *)p;
-
- /* Enter the key first. */
- n = bp[0];
-
- off = OFFSET(bp) - key->size;
- memmove(p + off, key->data, key->size);
- bp[++n] = off;
-
- /* Now the data. */
- off -= val->size;
- memmove(p + off, val->data, val->size);
- bp[++n] = off;
-
- /* Adjust page info. */
- bp[0] = n;
- bp[n + 1] = off - ((n + 3) * sizeof(u_int16_t));
- bp[n + 2] = off;
-}
-
-/*
- * Returns:
- * 0 OK
- * -1 error
- */
-extern int
-__delpair(hashp, bufp, ndx)
- HTAB *hashp;
- BUFHEAD *bufp;
- register int ndx;
-{
- register u_int16_t *bp, newoff;
- register int n;
- u_int16_t pairlen;
-
- bp = (u_int16_t *)bufp->page;
- n = bp[0];
-
- if (bp[ndx + 1] < REAL_KEY)
- return (__big_delete(hashp, bufp));
- if (ndx != 1)
- newoff = bp[ndx - 1];
- else
- newoff = hashp->BSIZE;
- pairlen = newoff - bp[ndx + 1];
-
- if (ndx != (n - 1)) {
- /* Hard Case -- need to shuffle keys */
- register int i;
- register char *src = bufp->page + (int)OFFSET(bp);
- register char *dst = src + (int)pairlen;
- memmove(dst, src, bp[ndx + 1] - OFFSET(bp));
-
- /* Now adjust the pointers */
- for (i = ndx + 2; i <= n; i += 2) {
- if (bp[i + 1] == OVFLPAGE) {
- bp[i - 2] = bp[i];
- bp[i - 1] = bp[i + 1];
- } else {
- bp[i - 2] = bp[i] + pairlen;
- bp[i - 1] = bp[i + 1] + pairlen;
- }
- }
- }
- /* Finally adjust the page data */
- bp[n] = OFFSET(bp) + pairlen;
- bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_int16_t);
- bp[0] = n - 2;
- hashp->NKEYS--;
-
- bufp->flags |= BUF_MOD;
- return (0);
-}
-/*
- * Returns:
- * 0 ==> OK
- * -1 ==> Error
- */
-extern int
-__split_page(hashp, obucket, nbucket)
- HTAB *hashp;
- u_int32_t obucket, nbucket;
-{
- register BUFHEAD *new_bufp, *old_bufp;
- register u_int16_t *ino;
- register char *np;
- DBT key, val;
- int n, ndx, retval;
- u_int16_t copyto, diff, off, moved;
- char *op;
-
- copyto = (u_int16_t)hashp->BSIZE;
- off = (u_int16_t)hashp->BSIZE;
- old_bufp = __get_buf(hashp, obucket, NULL, 0);
- if (old_bufp == NULL)
- return (-1);
- new_bufp = __get_buf(hashp, nbucket, NULL, 0);
- if (new_bufp == NULL)
- return (-1);
-
- old_bufp->flags |= (BUF_MOD | BUF_PIN);
- new_bufp->flags |= (BUF_MOD | BUF_PIN);
-
- ino = (u_int16_t *)(op = old_bufp->page);
- np = new_bufp->page;
-
- moved = 0;
-
- for (n = 1, ndx = 1; n < ino[0]; n += 2) {
- if (ino[n + 1] < REAL_KEY) {
- retval = ugly_split(hashp, obucket, old_bufp, new_bufp,
- (int)copyto, (int)moved);
- old_bufp->flags &= ~BUF_PIN;
- new_bufp->flags &= ~BUF_PIN;
- return (retval);
-
- }
- key.data = (u_char *)op + ino[n];
- key.size = off - ino[n];
-
- if (__call_hash(hashp, key.data, key.size) == obucket) {
- /* Don't switch page */
- diff = copyto - off;
- if (diff) {
- copyto = ino[n + 1] + diff;
- memmove(op + copyto, op + ino[n + 1],
- off - ino[n + 1]);
- ino[ndx] = copyto + ino[n] - ino[n + 1];
- ino[ndx + 1] = copyto;
- } else
- copyto = ino[n + 1];
- ndx += 2;
- } else {
- /* Switch page */
- val.data = (u_char *)op + ino[n + 1];
- val.size = ino[n] - ino[n + 1];
- putpair(np, &key, &val);
- moved += 2;
- }
-
- off = ino[n + 1];
- }
-
- /* Now clean up the page */
- ino[0] -= moved;
- FREESPACE(ino) = copyto - sizeof(u_int16_t) * (ino[0] + 3);
- OFFSET(ino) = copyto;
-
-#ifdef DEBUG3
- (void)fprintf(stderr, "split %d/%d\n",
- ((u_int16_t *)np)[0] / 2,
- ((u_int16_t *)op)[0] / 2);
-#endif
- /* unpin both pages */
- old_bufp->flags &= ~BUF_PIN;
- new_bufp->flags &= ~BUF_PIN;
- return (0);
-}
-
-/*
- * Called when we encounter an overflow or big key/data page during split
- * handling. This is special cased since we have to begin checking whether
- * the key/data pairs fit on their respective pages and because we may need
- * overflow pages for both the old and new pages.
- *
- * The first page might be a page with regular key/data pairs in which case
- * we have a regular overflow condition and just need to go on to the next
- * page or it might be a big key/data pair in which case we need to fix the
- * big key/data pair.
- *
- * Returns:
- * 0 ==> success
- * -1 ==> failure
- */
-static int
-ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved)
- HTAB *hashp;
- u_int32_t obucket; /* Same as __split_page. */
- BUFHEAD *old_bufp, *new_bufp;
- int copyto; /* First byte on page which contains key/data values. */
- int moved; /* Number of pairs moved to new page. */
-{
- register BUFHEAD *bufp; /* Buffer header for ino */
- register u_int16_t *ino; /* Page keys come off of */
- register u_int16_t *np; /* New page */
- register u_int16_t *op; /* Page keys go on to if they aren't moving */
-
- BUFHEAD *last_bfp; /* Last buf header OVFL needing to be freed */
- DBT key, val;
- SPLIT_RETURN ret;
- u_int16_t n, off, ov_addr, scopyto;
- char *cino; /* Character value of ino */
-
- bufp = old_bufp;
- ino = (u_int16_t *)old_bufp->page;
- np = (u_int16_t *)new_bufp->page;
- op = (u_int16_t *)old_bufp->page;
- last_bfp = NULL;
- scopyto = (u_int16_t)copyto; /* ANSI */
-
- n = ino[0] - 1;
- while (n < ino[0]) {
- if (ino[2] < REAL_KEY && ino[2] != OVFLPAGE) {
- if (__big_split(hashp, old_bufp,
- new_bufp, bufp, bufp->addr, obucket, &ret))
- return (-1);
- old_bufp = ret.oldp;
- if (!old_bufp)
- return (-1);
- op = (u_int16_t *)old_bufp->page;
- new_bufp = ret.newp;
- if (!new_bufp)
- return (-1);
- np = (u_int16_t *)new_bufp->page;
- bufp = ret.nextp;
- if (!bufp)
- return (0);
- cino = (char *)bufp->page;
- ino = (u_int16_t *)cino;
- last_bfp = ret.nextp;
- } else if (ino[n + 1] == OVFLPAGE) {
- ov_addr = ino[n];
- /*
- * Fix up the old page -- the extra 2 are the fields
- * which contained the overflow information.
- */
- ino[0] -= (moved + 2);
- FREESPACE(ino) =
- scopyto - sizeof(u_int16_t) * (ino[0] + 3);
- OFFSET(ino) = scopyto;
-
- bufp = __get_buf(hashp, ov_addr, bufp, 0);
- if (!bufp)
- return (-1);
-
- ino = (u_int16_t *)bufp->page;
- n = 1;
- scopyto = hashp->BSIZE;
- moved = 0;
-
- if (last_bfp)
- __free_ovflpage(hashp, last_bfp);
- last_bfp = bufp;
- }
- /* Move regular sized pairs of there are any */
- off = hashp->BSIZE;
- for (n = 1; (n < ino[0]) && (ino[n + 1] >= REAL_KEY); n += 2) {
- cino = (char *)ino;
- key.data = (u_char *)cino + ino[n];
- key.size = off - ino[n];
- val.data = (u_char *)cino + ino[n + 1];
- val.size = ino[n] - ino[n + 1];
- off = ino[n + 1];
-
- if (__call_hash(hashp, key.data, key.size) == obucket) {
- /* Keep on old page */
- if (PAIRFITS(op, (&key), (&val)))
- putpair((char *)op, &key, &val);
- else {
- old_bufp =
- __add_ovflpage(hashp, old_bufp);
- if (!old_bufp)
- return (-1);
- op = (u_int16_t *)old_bufp->page;
- putpair((char *)op, &key, &val);
- }
- old_bufp->flags |= BUF_MOD;
- } else {
- /* Move to new page */
- if (PAIRFITS(np, (&key), (&val)))
- putpair((char *)np, &key, &val);
- else {
- new_bufp =
- __add_ovflpage(hashp, new_bufp);
- if (!new_bufp)
- return (-1);
- np = (u_int16_t *)new_bufp->page;
- putpair((char *)np, &key, &val);
- }
- new_bufp->flags |= BUF_MOD;
- }
- }
- }
- if (last_bfp)
- __free_ovflpage(hashp, last_bfp);
- return (0);
-}
-
-/*
- * Add the given pair to the page
- *
- * Returns:
- * 0 ==> OK
- * 1 ==> failure
- */
-extern int
-__addel(hashp, bufp, key, val)
- HTAB *hashp;
- BUFHEAD *bufp;
- const DBT *key, *val;
-{
- register u_int16_t *bp, *sop;
- int do_expand;
-
- bp = (u_int16_t *)bufp->page;
- do_expand = 0;
- while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY))
- /* Exception case */
- if (bp[2] == FULL_KEY_DATA && bp[0] == 2)
- /* This is the last page of a big key/data pair
- and we need to add another page */
- break;
- else if (bp[2] < REAL_KEY && bp[bp[0]] != OVFLPAGE) {
- bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
- if (!bufp)
- return (-1);
- bp = (u_int16_t *)bufp->page;
- } else
- /* Try to squeeze key on this page */
- if (FREESPACE(bp) > PAIRSIZE(key, val)) {
- squeeze_key(bp, key, val);
- return (0);
- } else {
- bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
- if (!bufp)
- return (-1);
- bp = (u_int16_t *)bufp->page;
- }
-
- if (PAIRFITS(bp, key, val))
- putpair(bufp->page, key, val);
- else {
- do_expand = 1;
- bufp = __add_ovflpage(hashp, bufp);
- if (!bufp)
- return (-1);
- sop = (u_int16_t *)bufp->page;
-
- if (PAIRFITS(sop, key, val))
- putpair((char *)sop, key, val);
- else
- if (__big_insert(hashp, bufp, key, val))
- return (-1);
- }
- bufp->flags |= BUF_MOD;
- /*
- * If the average number of keys per bucket exceeds the fill factor,
- * expand the table.
- */
- hashp->NKEYS++;
- if (do_expand ||
- (hashp->NKEYS / (hashp->MAX_BUCKET + 1) > hashp->FFACTOR))
- return (__expand_table(hashp));
- return (0);
-}
-
-/*
- *
- * Returns:
- * pointer on success
- * NULL on error
- */
-extern BUFHEAD *
-__add_ovflpage(hashp, bufp)
- HTAB *hashp;
- BUFHEAD *bufp;
-{
- register u_int16_t *sp;
- u_int16_t ndx, ovfl_num;
-#ifdef DEBUG1
- int tmp1, tmp2;
-#endif
- sp = (u_int16_t *)bufp->page;
-
- /* Check if we are dynamically determining the fill factor */
- if (hashp->FFACTOR == DEF_FFACTOR) {
- hashp->FFACTOR = sp[0] >> 1;
- if (hashp->FFACTOR < MIN_FFACTOR)
- hashp->FFACTOR = MIN_FFACTOR;
- }
- bufp->flags |= BUF_MOD;
- ovfl_num = overflow_page(hashp);
-#ifdef DEBUG1
- tmp1 = bufp->addr;
- tmp2 = bufp->ovfl ? bufp->ovfl->addr : 0;
-#endif
- if (!ovfl_num || !(bufp->ovfl = __get_buf(hashp, ovfl_num, bufp, 1)))
- return (NULL);
- bufp->ovfl->flags |= BUF_MOD;
-#ifdef DEBUG1
- (void)fprintf(stderr, "ADDOVFLPAGE: %d->ovfl was %d is now %d\n",
- tmp1, tmp2, bufp->ovfl->addr);
-#endif
- ndx = sp[0];
- /*
- * Since a pair is allocated on a page only if there's room to add
- * an overflow page, we know that the OVFL information will fit on
- * the page.
- */
- sp[ndx + 4] = OFFSET(sp);
- sp[ndx + 3] = FREESPACE(sp) - OVFLSIZE;
- sp[ndx + 1] = ovfl_num;
- sp[ndx + 2] = OVFLPAGE;
- sp[0] = ndx + 2;
-#ifdef HASH_STATISTICS
- hash_overflows++;
-#endif
- return (bufp->ovfl);
-}
-
-/*
- * Returns:
- * 0 indicates SUCCESS
- * -1 indicates FAILURE
- */
-extern int
-__get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap)
- HTAB *hashp;
- char *p;
- u_int32_t bucket;
- int is_bucket, is_disk, is_bitmap;
-{
- register int fd, page, size;
- int rsize;
- u_int16_t *bp;
-
- fd = hashp->fp;
- size = hashp->BSIZE;
-
- if ((fd == -1) || !is_disk) {
- PAGE_INIT(p);
- return (0);
- }
- if (is_bucket)
- page = BUCKET_TO_PAGE(bucket);
- else
- page = OADDR_TO_PAGE(bucket);
- if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) ||
- ((rsize = read(fd, p, size)) == -1))
- return (-1);
- bp = (u_int16_t *)p;
- if (!rsize)
- bp[0] = 0; /* We hit the EOF, so initialize a new page */
- else
- if (rsize != size) {
- errno = EFTYPE;
- return (-1);
- }
- if (!is_bitmap && !bp[0]) {
- PAGE_INIT(p);
- } else
- if (hashp->LORDER != BYTE_ORDER) {
- register int i, max;
-
- if (is_bitmap) {
- max = hashp->BSIZE >> 2; /* divide by 4 */
- for (i = 0; i < max; i++)
- M_32_SWAP(((int *)p)[i]);
- } else {
- M_16_SWAP(bp[0]);
- max = bp[0] + 2;
- for (i = 1; i <= max; i++)
- M_16_SWAP(bp[i]);
- }
- }
- return (0);
-}
-
-/*
- * Write page p to disk
- *
- * Returns:
- * 0 ==> OK
- * -1 ==>failure
- */
-extern int
-__put_page(hashp, p, bucket, is_bucket, is_bitmap)
- HTAB *hashp;
- char *p;
- u_int32_t bucket;
- int is_bucket, is_bitmap;
-{
- register int fd, page, size;
- int wsize;
-
- size = hashp->BSIZE;
- if ((hashp->fp == -1) && open_temp(hashp))
- return (-1);
- fd = hashp->fp;
-
- if (hashp->LORDER != BYTE_ORDER) {
- register int i;
- register int max;
-
- if (is_bitmap) {
- max = hashp->BSIZE >> 2; /* divide by 4 */
- for (i = 0; i < max; i++)
- M_32_SWAP(((int *)p)[i]);
- } else {
- max = ((u_int16_t *)p)[0] + 2;
- for (i = 0; i <= max; i++)
- M_16_SWAP(((u_int16_t *)p)[i]);
- }
- }
- if (is_bucket)
- page = BUCKET_TO_PAGE(bucket);
- else
- page = OADDR_TO_PAGE(bucket);
- if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) ||
- ((wsize = write(fd, p, size)) == -1))
- /* Errno is set */
- return (-1);
- if (wsize != size) {
- errno = EFTYPE;
- return (-1);
- }
- return (0);
-}
-
-#define BYTE_MASK ((1 << INT_BYTE_SHIFT) -1)
-/*
- * Initialize a new bitmap page. Bitmap pages are left in memory
- * once they are read in.
- */
-extern int
-__ibitmap(hashp, pnum, nbits, ndx)
- HTAB *hashp;
- int pnum, nbits, ndx;
-{
- u_int32_t *ip;
- int clearbytes, clearints;
-
- if ((ip = (u_int32_t *)malloc(hashp->BSIZE)) == NULL)
- return (1);
- hashp->nmaps++;
- clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1;
- clearbytes = clearints << INT_TO_BYTE;
- (void)memset((char *)ip, 0, clearbytes);
- (void)memset(((char *)ip) + clearbytes, 0xFF,
- hashp->BSIZE - clearbytes);
- ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK);
- SETBIT(ip, 0);
- hashp->BITMAPS[ndx] = (u_int16_t)pnum;
- hashp->mapp[ndx] = ip;
- return (0);
-}
-
-static u_int32_t
-first_free(map)
- u_int32_t map;
-{
- register u_int32_t i, mask;
-
- mask = 0x1;
- for (i = 0; i < BITS_PER_MAP; i++) {
- if (!(mask & map))
- return (i);
- mask = mask << 1;
- }
- return (i);
-}
-
-static u_int16_t
-overflow_page(hashp)
- HTAB *hashp;
-{
- register u_int32_t *freep = 0;
- register int max_free, offset, splitnum;
- u_int16_t addr;
- int bit, first_page, free_bit, free_page, i, in_use_bits, j;
-#ifdef DEBUG2
- int tmp1, tmp2;
-#endif
- splitnum = hashp->OVFL_POINT;
- max_free = hashp->SPARES[splitnum];
-
- free_page = (max_free - 1) >> (hashp->BSHIFT + BYTE_SHIFT);
- free_bit = (max_free - 1) & ((hashp->BSIZE << BYTE_SHIFT) - 1);
-
- /* Look through all the free maps to find the first free block */
- first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT);
- for ( i = first_page; i <= free_page; i++ ) {
- if (!(freep = (u_int32_t *)hashp->mapp[i]) &&
- !(freep = fetch_bitmap(hashp, i)))
- return (0);
- if (i == free_page)
- in_use_bits = free_bit;
- else
- in_use_bits = (hashp->BSIZE << BYTE_SHIFT) - 1;
-
- if (i == first_page) {
- bit = hashp->LAST_FREED &
- ((hashp->BSIZE << BYTE_SHIFT) - 1);
- j = bit / BITS_PER_MAP;
- bit = bit & ~(BITS_PER_MAP - 1);
- } else {
- bit = 0;
- j = 0;
- }
- for (; bit <= in_use_bits; j++, bit += BITS_PER_MAP)
- if (freep[j] != ALL_SET)
- goto found;
- }
-
- /* No Free Page Found */
- hashp->LAST_FREED = hashp->SPARES[splitnum];
- hashp->SPARES[splitnum]++;
- offset = hashp->SPARES[splitnum] -
- (splitnum ? hashp->SPARES[splitnum - 1] : 0);
-
-#define OVMSG "HASH: Out of overflow pages. Increase page size\n"
- if (offset > SPLITMASK) {
- if (++splitnum >= NCACHED) {
- (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1);
- return (0);
- }
- hashp->OVFL_POINT = splitnum;
- hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1];
- hashp->SPARES[splitnum-1]--;
- offset = 1;
- }
-
- /* Check if we need to allocate a new bitmap page */
- if (free_bit == (hashp->BSIZE << BYTE_SHIFT) - 1) {
- free_page++;
- if (free_page >= NCACHED) {
- (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1);
- return (0);
- }
- /*
- * This is tricky. The 1 indicates that you want the new page
- * allocated with 1 clear bit. Actually, you are going to
- * allocate 2 pages from this map. The first is going to be
- * the map page, the second is the overflow page we were
- * looking for. The init_bitmap routine automatically, sets
- * the first bit of itself to indicate that the bitmap itself
- * is in use. We would explicitly set the second bit, but
- * don't have to if we tell init_bitmap not to leave it clear
- * in the first place.
- */
- if (__ibitmap(hashp,
- (int)OADDR_OF(splitnum, offset), 1, free_page))
- return (0);
- hashp->SPARES[splitnum]++;
-#ifdef DEBUG2
- free_bit = 2;
-#endif
- offset++;
- if (offset > SPLITMASK) {
- if (++splitnum >= NCACHED) {
- (void)write(STDERR_FILENO, OVMSG,
- sizeof(OVMSG) - 1);
- return (0);
- }
- hashp->OVFL_POINT = splitnum;
- hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1];
- hashp->SPARES[splitnum-1]--;
- offset = 0;
- }
- } else {
- /*
- * Free_bit addresses the last used bit. Bump it to address
- * the first available bit.
- */
- free_bit++;
- SETBIT(freep, free_bit);
- }
-
- /* Calculate address of the new overflow page */
- addr = OADDR_OF(splitnum, offset);
-#ifdef DEBUG2
- (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n",
- addr, free_bit, free_page);
-#endif
- return (addr);
-
-found:
- bit = bit + first_free(freep[j]);
- SETBIT(freep, bit);
-#ifdef DEBUG2
- tmp1 = bit;
- tmp2 = i;
-#endif
- /*
- * Bits are addressed starting with 0, but overflow pages are addressed
- * beginning at 1. Bit is a bit addressnumber, so we need to increment
- * it to convert it to a page number.
- */
- bit = 1 + bit + (i * (hashp->BSIZE << BYTE_SHIFT));
- if (bit >= hashp->LAST_FREED)
- hashp->LAST_FREED = bit - 1;
-
- /* Calculate the split number for this page */
- for (i = 0; (i < splitnum) && (bit > hashp->SPARES[i]); i++);
- offset = (i ? bit - hashp->SPARES[i - 1] : bit);
- if (offset >= SPLITMASK)
- return (0); /* Out of overflow pages */
- addr = OADDR_OF(i, offset);
-#ifdef DEBUG2
- (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n",
- addr, tmp1, tmp2);
-#endif
-
- /* Allocate and return the overflow page */
- return (addr);
-}
-
-/*
- * Mark this overflow page as free.
- */
-extern void
-__free_ovflpage(hashp, obufp)
- HTAB *hashp;
- BUFHEAD *obufp;
-{
- register u_int16_t addr;
- u_int32_t *freep;
- int bit_address, free_page, free_bit;
- u_int16_t ndx;
-
- addr = obufp->addr;
-#ifdef DEBUG1
- (void)fprintf(stderr, "Freeing %d\n", addr);
-#endif
- ndx = (((u_int16_t)addr) >> SPLITSHIFT);
- bit_address =
- (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1;
- if (bit_address < hashp->LAST_FREED)
- hashp->LAST_FREED = bit_address;
- free_page = (bit_address >> (hashp->BSHIFT + BYTE_SHIFT));
- free_bit = bit_address & ((hashp->BSIZE << BYTE_SHIFT) - 1);
-
- if (!(freep = hashp->mapp[free_page]))
- freep = fetch_bitmap(hashp, free_page);
-#ifdef DEBUG
- /*
- * This had better never happen. It means we tried to read a bitmap
- * that has already had overflow pages allocated off it, and we
- * failed to read it from the file.
- */
- if (!freep)
- assert(0);
-#endif
- CLRBIT(freep, free_bit);
-#ifdef DEBUG2
- (void)fprintf(stderr, "FREE_OVFLPAGE: ADDR: %d BIT: %d PAGE %d\n",
- obufp->addr, free_bit, free_page);
-#endif
- __reclaim_buf(hashp, obufp);
-}
-
-/*
- * Returns:
- * 0 success
- * -1 failure
- */
-static int
-open_temp(hashp)
- HTAB *hashp;
-{
- sigset_t set, oset;
- static char namestr[] = "_hashXXXXXX";
-
- /* Block signals; make sure file goes away at process exit. */
- (void)sigfillset(&set);
- (void)sigprocmask(SIG_BLOCK, &set, &oset);
- if ((hashp->fp = mkstemp(namestr)) != -1) {
- (void)unlink(namestr);
- (void)fcntl(hashp->fp, F_SETFD, 1);
- }
- (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL);
- return (hashp->fp != -1 ? 0 : -1);
-}
-
-/*
- * We have to know that the key will fit, but the last entry on the page is
- * an overflow pair, so we need to shift things.
- */
-static void
-squeeze_key(sp, key, val)
- u_int16_t *sp;
- const DBT *key, *val;
-{
- register char *p;
- u_int16_t free_space, n, off, pageno;
-
- p = (char *)sp;
- n = sp[0];
- free_space = FREESPACE(sp);
- off = OFFSET(sp);
-
- pageno = sp[n - 1];
- off -= key->size;
- sp[n - 1] = off;
- memmove(p + off, key->data, key->size);
- off -= val->size;
- sp[n] = off;
- memmove(p + off, val->data, val->size);
- sp[0] = n + 2;
- sp[n + 1] = pageno;
- sp[n + 2] = OVFLPAGE;
- FREESPACE(sp) = free_space - PAIRSIZE(key, val);
- OFFSET(sp) = off;
-}
-
-static u_int32_t *
-fetch_bitmap(hashp, ndx)
- HTAB *hashp;
- int ndx;
-{
- if (ndx >= hashp->nmaps)
- return (NULL);
- if ((hashp->mapp[ndx] = (u_int32_t *)malloc(hashp->BSIZE)) == NULL)
- return (NULL);
- if (__get_page(hashp,
- (char *)hashp->mapp[ndx], hashp->BITMAPS[ndx], 0, 1, 1)) {
- free(hashp->mapp[ndx]);
- return (NULL);
- }
- return (hashp->mapp[ndx]);
-}
-
-#ifdef DEBUG4
-int
-print_chain(addr)
- int addr;
-{
- BUFHEAD *bufp;
- short *bp, oaddr;
-
- (void)fprintf(stderr, "%d ", addr);
- bufp = __get_buf(hashp, addr, NULL, 0);
- bp = (short *)bufp->page;
- while (bp[0] && ((bp[bp[0]] == OVFLPAGE) ||
- ((bp[0] > 2) && bp[2] < REAL_KEY))) {
- oaddr = bp[bp[0] - 1];
- (void)fprintf(stderr, "%d ", (int)oaddr);
- bufp = __get_buf(hashp, (int)oaddr, bufp, 0);
- bp = (short *)bufp->page;
- }
- (void)fprintf(stderr, "\n");
-}
-#endif
diff --git a/1.2-netsec/db1-ast/hash/hsearch.c b/1.2-netsec/db1-ast/hash/hsearch.c
deleted file mode 100644
index cc8f7a4aa..000000000
--- a/1.2-netsec/db1-ast/hash/hsearch.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hsearch.c 8.4 (Berkeley) 7/21/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <fcntl.h>
-#include <string.h>
-
-#include <db.h>
-#include "search.h"
-
-static DB *dbp = NULL;
-static ENTRY retval;
-
-extern int
-hcreate(nel)
- u_int nel;
-{
- HASHINFO info;
-
- info.nelem = nel;
- info.bsize = 256;
- info.ffactor = 8;
- info.cachesize = 0;
- info.hash = NULL;
- info.lorder = 0;
- dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0);
- return ((int)dbp);
-}
-
-extern ENTRY *
-hsearch(item, action)
- ENTRY item;
- ACTION action;
-{
- DBT key, val;
- int status;
-
- if (!dbp)
- return (NULL);
- key.data = (u_char *)item.key;
- key.size = strlen(item.key) + 1;
-
- if (action == ENTER) {
- val.data = (u_char *)item.data;
- val.size = strlen(item.data) + 1;
- status = (dbp->put)(dbp, &key, &val, R_NOOVERWRITE);
- if (status)
- return (NULL);
- } else {
- /* FIND */
- status = (dbp->get)(dbp, &key, &val, 0);
- if (status)
- return (NULL);
- else
- item.data = (char *)val.data;
- }
- retval.key = item.key;
- retval.data = item.data;
- return (&retval);
-}
-
-extern void
-hdestroy()
-{
- if (dbp) {
- (void)(dbp->close)(dbp);
- dbp = NULL;
- }
-}
diff --git a/1.2-netsec/db1-ast/hash/ndbm.c b/1.2-netsec/db1-ast/hash/ndbm.c
deleted file mode 100644
index d702f737a..000000000
--- a/1.2-netsec/db1-ast/hash/ndbm.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ndbm.c 8.4 (Berkeley) 7/21/94";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * This package provides a dbm compatible interface to the new hashing
- * package described in db(3).
- */
-
-#include <sys/param.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <ndbm.h>
-#include "hash.h"
-
-/*
- * Returns:
- * *DBM on success
- * NULL on failure
- */
-extern DBM *
-dbm_open(file, flags, mode)
- const char *file;
- int flags, mode;
-{
- DBM *db;
- HASHINFO info;
- const size_t len = strlen(file) + sizeof (DBM_SUFFIX);
-#ifdef __GNUC__
- char path[len];
-#else
- char *path = malloc(len);
- if (path == NULL)
- return NULL;
-#endif
-
- info.bsize = 4096;
- info.ffactor = 40;
- info.nelem = 1;
- info.cachesize = 0;
- info.hash = NULL;
- info.lorder = 0;
- (void)strncpy(path, file, len - 1);
- (void)strncat(path, DBM_SUFFIX, len - strlen(path) - 1);
- db = (DBM *)__hash_open(path, flags, mode, &info, 0);
-#ifndef __GNUC__
- free(path);
-#endif
- return db;
-}
-
-extern void
-dbm_close(db)
- DBM *db;
-{
- (void)(db->close)(db);
-}
-
-/*
- * Returns:
- * DATUM on success
- * NULL on failure
- */
-extern datum
-dbm_fetch(db, key)
- DBM *db;
- datum key;
-{
- datum retdata;
- int status;
- DBT dbtkey, dbtretdata;
-
- dbtkey.data = key.dptr;
- dbtkey.size = key.dsize;
- status = (db->get)(db, &dbtkey, &dbtretdata, 0);
- if (status) {
- dbtretdata.data = NULL;
- dbtretdata.size = 0;
- }
- retdata.dptr = dbtretdata.data;
- retdata.dsize = dbtretdata.size;
- return (retdata);
-}
-
-/*
- * Returns:
- * DATUM on success
- * NULL on failure
- */
-extern datum
-dbm_firstkey(db)
- DBM *db;
-{
- int status;
- datum retkey;
- DBT dbtretkey, dbtretdata;
-
- status = (db->seq)(db, &dbtretkey, &dbtretdata, R_FIRST);
- if (status)
- dbtretkey.data = NULL;
- retkey.dptr = dbtretkey.data;
- retkey.dsize = dbtretkey.size;
- return (retkey);
-}
-
-/*
- * Returns:
- * DATUM on success
- * NULL on failure
- */
-extern datum
-dbm_nextkey(db)
- DBM *db;
-{
- int status;
- datum retkey;
- DBT dbtretkey, dbtretdata;
-
- status = (db->seq)(db, &dbtretkey, &dbtretdata, R_NEXT);
- if (status)
- dbtretkey.data = NULL;
- retkey.dptr = dbtretkey.data;
- retkey.dsize = dbtretkey.size;
- return (retkey);
-}
-/*
- * Returns:
- * 0 on success
- * <0 failure
- */
-extern int
-dbm_delete(db, key)
- DBM *db;
- datum key;
-{
- int status;
- DBT dbtkey;
-
- dbtkey.data = key.dptr;
- dbtkey.size = key.dsize;
- status = (db->del)(db, &dbtkey, 0);
- if (status)
- return (-1);
- else
- return (0);
-}
-
-/*
- * Returns:
- * 0 on success
- * <0 failure
- * 1 if DBM_INSERT and entry exists
- */
-extern int
-dbm_store(db, key, data, flags)
- DBM *db;
- datum key, data;
- int flags;
-{
- DBT dbtkey, dbtdata;
-
- dbtkey.data = key.dptr;
- dbtkey.size = key.dsize;
- dbtdata.data = data.dptr;
- dbtdata.size = data.dsize;
- return ((db->put)(db, &dbtkey, &dbtdata,
- (flags == DBM_INSERT) ? R_NOOVERWRITE : 0));
-}
-
-extern int
-dbm_error(db)
- DBM *db;
-{
- HTAB *hp;
-
- hp = (HTAB *)db->internal;
- return (hp->errnum);
-}
-
-extern int
-dbm_clearerr(db)
- DBM *db;
-{
- HTAB *hp;
-
- hp = (HTAB *)db->internal;
- hp->errnum = 0;
- return (0);
-}
-
-extern int
-dbm_dirfno(db)
- DBM *db;
-{
- return(((HTAB *)db->internal)->fp);
-}
diff --git a/1.2-netsec/db1-ast/hash/page.h b/1.2-netsec/db1-ast/hash/page.h
deleted file mode 100644
index 0fc0d5a3e..000000000
--- a/1.2-netsec/db1-ast/hash/page.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)page.h 8.2 (Berkeley) 5/31/94
- */
-
-/*
- * Definitions for hashing page file format.
- */
-
-/*
- * routines dealing with a data page
- *
- * page format:
- * +------------------------------+
- * p | n | keyoff | datoff | keyoff |
- * +------------+--------+--------+
- * | datoff | free | ptr | --> |
- * +--------+---------------------+
- * | F R E E A R E A |
- * +--------------+---------------+
- * | <---- - - - | data |
- * +--------+-----+----+----------+
- * | key | data | key |
- * +--------+----------+----------+
- *
- * Pointer to the free space is always: p[p[0] + 2]
- * Amount of free space on the page is: p[p[0] + 1]
- */
-
-/*
- * How many bytes required for this pair?
- * 2 shorts in the table at the top of the page + room for the
- * key and room for the data
- *
- * We prohibit entering a pair on a page unless there is also room to append
- * an overflow page. The reason for this it that you can get in a situation
- * where a single key/data pair fits on a page, but you can't append an
- * overflow page and later you'd have to split the key/data and handle like
- * a big pair.
- * You might as well do this up front.
- */
-
-#define PAIRSIZE(K,D) (2*sizeof(u_int16_t) + (K)->size + (D)->size)
-#define BIGOVERHEAD (4*sizeof(u_int16_t))
-#define KEYSIZE(K) (4*sizeof(u_int16_t) + (K)->size);
-#define OVFLSIZE (2*sizeof(u_int16_t))
-#define FREESPACE(P) ((P)[(P)[0]+1])
-#define OFFSET(P) ((P)[(P)[0]+2])
-#define PAIRFITS(P,K,D) \
- (((P)[2] >= REAL_KEY) && \
- (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P)))
-#define PAGE_META(N) (((N)+3) * sizeof(u_int16_t))
-
-typedef struct {
- BUFHEAD *newp;
- BUFHEAD *oldp;
- BUFHEAD *nextp;
- u_int16_t next_addr;
-} SPLIT_RETURN;
diff --git a/1.2-netsec/db1-ast/hash/search.h b/1.2-netsec/db1-ast/hash/search.h
deleted file mode 100644
index 4d3b9143e..000000000
--- a/1.2-netsec/db1-ast/hash/search.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)search.h 8.1 (Berkeley) 6/4/93
- */
-
-/* Backward compatibility to hsearch interface. */
-typedef struct entry {
- char *key;
- char *data;
-} ENTRY;
-
-typedef enum {
- FIND, ENTER
-} ACTION;
-
-int hcreate __P((unsigned int));
-void hdestroy __P((void));
-ENTRY *hsearch __P((ENTRY, ACTION));
diff --git a/1.2-netsec/db1-ast/include/circ-queue.h b/1.2-netsec/db1-ast/include/circ-queue.h
deleted file mode 100644
index 33ba9115b..000000000
--- a/1.2-netsec/db1-ast/include/circ-queue.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)queue.h 8.5 (Berkeley) 8/20/94
- * $FreeBSD: ports/misc/44bsd-more/files/queue.h,v 1.1 2001/01/06 03:41:36 hoek Exp $
- */
-
-/*
- * Circular queue definitions.
- */
-#define CIRCLEQ_HEAD(name, type) \
-struct name { \
- struct type *cqh_first; /* first element */ \
- struct type *cqh_last; /* last element */ \
-}
-
-#define CIRCLEQ_ENTRY(type) \
-struct { \
- struct type *cqe_next; /* next element */ \
- struct type *cqe_prev; /* previous element */ \
-}
-
-/*
- * Circular queue functions.
- */
-#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
-
-#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
-
-#define CIRCLEQ_FOREACH(var, head, field) \
- for((var) = (head)->cqh_first; \
- (var) != (void *)(head); \
- (var) = (var)->field.cqe_next)
-
-#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
- for((var) = (head)->cqh_last; \
- (var) != (void *)(head); \
- (var) = (var)->field.cqe_prev)
-
-#define CIRCLEQ_INIT(head) do { \
- (head)->cqh_first = (void *)(head); \
- (head)->cqh_last = (void *)(head); \
-} while (0)
-
-#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
- (elm)->field.cqe_next = (listelm)->field.cqe_next; \
- (elm)->field.cqe_prev = (listelm); \
- if ((listelm)->field.cqe_next == (void *)(head)) \
- (head)->cqh_last = (elm); \
- else \
- (listelm)->field.cqe_next->field.cqe_prev = (elm); \
- (listelm)->field.cqe_next = (elm); \
-} while (0)
-
-#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
- (elm)->field.cqe_next = (listelm); \
- (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
- if ((listelm)->field.cqe_prev == (void *)(head)) \
- (head)->cqh_first = (elm); \
- else \
- (listelm)->field.cqe_prev->field.cqe_next = (elm); \
- (listelm)->field.cqe_prev = (elm); \
-} while (0)
-
-#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
- (elm)->field.cqe_next = (head)->cqh_first; \
- (elm)->field.cqe_prev = (void *)(head); \
- if ((head)->cqh_last == (void *)(head)) \
- (head)->cqh_last = (elm); \
- else \
- (head)->cqh_first->field.cqe_prev = (elm); \
- (head)->cqh_first = (elm); \
-} while (0)
-
-#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.cqe_next = (void *)(head); \
- (elm)->field.cqe_prev = (head)->cqh_last; \
- if ((head)->cqh_first == (void *)(head)) \
- (head)->cqh_first = (elm); \
- else \
- (head)->cqh_last->field.cqe_next = (elm); \
- (head)->cqh_last = (elm); \
-} while (0)
-
-#define CIRCLEQ_LAST(head) ((head)->cqh_last)
-
-#define CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next)
-
-#define CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev)
-
-#define CIRCLEQ_REMOVE(head, elm, field) do { \
- if ((elm)->field.cqe_next == (void *)(head)) \
- (head)->cqh_last = (elm)->field.cqe_prev; \
- else \
- (elm)->field.cqe_next->field.cqe_prev = \
- (elm)->field.cqe_prev; \
- if ((elm)->field.cqe_prev == (void *)(head)) \
- (head)->cqh_first = (elm)->field.cqe_next; \
- else \
- (elm)->field.cqe_prev->field.cqe_next = \
- (elm)->field.cqe_next; \
-} while (0)
diff --git a/1.2-netsec/db1-ast/include/compat.h b/1.2-netsec/db1-ast/include/compat.h
deleted file mode 100644
index 706e58265..000000000
--- a/1.2-netsec/db1-ast/include/compat.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Values for building 4.4 BSD db routines in the GNU C library. */
-
-#ifndef _compat_h_
-#define _compat_h_
-
-#include <fcntl.h>
-
-/*
- * If you can't provide lock values in the open(2) call. Note, this
- * allows races to happen.
- */
-#ifndef O_EXLOCK /* 4.4BSD extension. */
-#define O_EXLOCK 0
-#endif
-
-#ifndef O_SHLOCK /* 4.4BSD extension. */
-#define O_SHLOCK 0
-#endif
-
-#include <errno.h>
-
-#ifndef EFTYPE
-#define EFTYPE EINVAL /* POSIX 1003.1 format errno. */
-#endif
-
-#include <unistd.h>
-#include <limits.h>
-
-#ifndef _POSIX_VDISABLE /* POSIX 1003.1 disabling char. */
-#define _POSIX_VDISABLE 0 /* Some systems used 0. */
-#endif
-
-#include <termios.h>
-
-#ifndef TCSASOFT /* 4.4BSD extension. */
-#define TCSASOFT 0
-#endif
-
-#include <sys/param.h>
-
-#ifndef MAX /* Usually found in <sys/param.h>. */
-#define MAX(_a,_b) ((_a)<(_b)?(_b):(_a))
-#endif
-#ifndef MIN /* Usually found in <sys/param.h>. */
-#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
-#endif
-
-
-#endif /* compat.h */
diff --git a/1.2-netsec/db1-ast/include/db.h b/1.2-netsec/db1-ast/include/db.h
deleted file mode 100644
index a58724bdd..000000000
--- a/1.2-netsec/db1-ast/include/db.h
+++ /dev/null
@@ -1,250 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)db.h 8.7 (Berkeley) 6/16/94
- */
-
-#ifndef _DB_H
-#define _DB_H 1
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-
-#include <limits.h>
-
-#ifdef __DBINTERFACE_PRIVATE
-#include <compat.h>
-#endif
-
-#ifdef SOLARIS
-#include "solaris-compat/compat.h"
-#endif
-
-#define RET_ERROR -1 /* Return values. */
-#define RET_SUCCESS 0
-#define RET_SPECIAL 1
-
-#ifndef __BIT_TYPES_DEFINED__
-#define __BIT_TYPES_DEFINED__
-#if (!defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__APPLE__))
-typedef __signed char int8_t;
-typedef short int16_t;
-typedef int int32_t;
-typedef unsigned char u_int8_t;
-typedef unsigned short u_int16_t;
-typedef unsigned int u_int32_t;
-#ifdef WE_DONT_NEED_QUADS
-typedef long long int64_t;
-typedef unsigned long long u_int64_t;
-#endif
-#endif /* __FreeBSD__ */
-#endif
-
-#ifdef SOLARIS
-#define __P(p) p
-#define __BEGIN_DECLS
-#define __END_DECLS
-#endif
-
-#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
-typedef u_int32_t pgno_t;
-#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
-typedef u_int16_t indx_t;
-#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
-typedef u_int32_t recno_t;
-
-/* Key/data structure -- a Data-Base Thang. */
-typedef struct {
- void *data; /* data */
- size_t size; /* data length */
-} DBT;
-
-/* Routine flags. */
-#define R_CURSOR 1 /* del, put, seq */
-#define __R_UNUSED 2 /* UNUSED */
-#define R_FIRST 3 /* seq */
-#define R_IAFTER 4 /* put (RECNO) */
-#define R_IBEFORE 5 /* put (RECNO) */
-#define R_LAST 6 /* seq (BTREE, RECNO) */
-#define R_NEXT 7 /* seq */
-#define R_NOOVERWRITE 8 /* put */
-#define R_PREV 9 /* seq (BTREE, RECNO) */
-#define R_SETCURSOR 10 /* put (RECNO) */
-#define R_RECNOSYNC 11 /* sync (RECNO) */
-
-typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
-
-/*
- * !!!
- * The following flags are included in the dbopen(3) call as part of the
- * open(2) flags. In order to avoid conflicts with the open flags, start
- * at the top of the 16 or 32-bit number space and work our way down. If
- * the open flags were significantly expanded in the future, it could be
- * a problem. Wish I'd left another flags word in the dbopen call.
- *
- * !!!
- * None of this stuff is implemented yet. The only reason that it's here
- * is so that the access methods can skip copying the key/data pair when
- * the DB_LOCK flag isn't set.
- */
-#if UINT_MAX > 65535
-#define DB_LOCK 0x20000000 /* Do locking. */
-#define DB_SHMEM 0x40000000 /* Use shared memory. */
-#define DB_TXN 0x80000000 /* Do transactions. */
-#else
-#define DB_LOCK 0x2000 /* Do locking. */
-#define DB_SHMEM 0x4000 /* Use shared memory. */
-#define DB_TXN 0x8000 /* Do transactions. */
-#endif
-
-/* Access method description structure. */
-typedef struct __db {
- DBTYPE type; /* Underlying db type. */
- int (*close) __P((struct __db *));
- int (*del) __P((const struct __db *, const DBT *, u_int));
- int (*get) __P((const struct __db *, const DBT *, DBT *, u_int));
- int (*put) __P((const struct __db *, DBT *, const DBT *, u_int));
- int (*seq) __P((const struct __db *, DBT *, DBT *, u_int));
- int (*sync) __P((const struct __db *, u_int));
- void *internal; /* Access method private. */
- int (*fd) __P((const struct __db *));
-} DB;
-
-#define BTREEMAGIC 0x053162
-#define BTREEVERSION 3
-
-/* Structure used to pass parameters to the btree routines. */
-typedef struct {
-#define R_DUP 0x01 /* duplicate keys */
- u_long flags;
- u_int cachesize; /* bytes to cache */
- int maxkeypage; /* maximum keys per page */
- int minkeypage; /* minimum keys per page */
- u_int psize; /* page size */
- int (*compare) /* comparison function */
- __P((const DBT *, const DBT *));
- size_t (*prefix) /* prefix function */
- __P((const DBT *, const DBT *));
- int lorder; /* byte order */
-} BTREEINFO;
-
-#define HASHMAGIC 0x061561
-#define HASHVERSION 2
-
-/* Structure used to pass parameters to the hashing routines. */
-typedef struct {
- u_int bsize; /* bucket size */
- u_int ffactor; /* fill factor */
- u_int nelem; /* number of elements */
- u_int cachesize; /* bytes to cache */
- u_int32_t /* hash function */
- (*hash) __P((const void *, size_t));
- int lorder; /* byte order */
-} HASHINFO;
-
-/* Structure used to pass parameters to the record routines. */
-typedef struct {
-#define R_FIXEDLEN 0x01 /* fixed-length records */
-#define R_NOKEY 0x02 /* key not required */
-#define R_SNAPSHOT 0x04 /* snapshot the input */
- u_long flags;
- u_int cachesize; /* bytes to cache */
- u_int psize; /* page size */
- int lorder; /* byte order */
- size_t reclen; /* record length (fixed-length records) */
- u_char bval; /* delimiting byte (variable-length records */
- char *bfname; /* btree file name */
-} RECNOINFO;
-
-#ifdef __DBINTERFACE_PRIVATE
-/*
- * Little endian <==> big endian 32-bit swap macros.
- * M_32_SWAP swap a memory location
- * P_32_SWAP swap a referenced memory location
- * P_32_COPY swap from one location to another
- */
-#define M_32_SWAP(a) { \
- u_int32_t _tmp = a; \
- ((char *)&a)[0] = ((char *)&_tmp)[3]; \
- ((char *)&a)[1] = ((char *)&_tmp)[2]; \
- ((char *)&a)[2] = ((char *)&_tmp)[1]; \
- ((char *)&a)[3] = ((char *)&_tmp)[0]; \
-}
-#define P_32_SWAP(a) { \
- u_int32_t _tmp = *(u_int32_t *)a; \
- ((char *)a)[0] = ((char *)&_tmp)[3]; \
- ((char *)a)[1] = ((char *)&_tmp)[2]; \
- ((char *)a)[2] = ((char *)&_tmp)[1]; \
- ((char *)a)[3] = ((char *)&_tmp)[0]; \
-}
-#define P_32_COPY(a, b) { \
- ((char *)&(b))[0] = ((char *)&(a))[3]; \
- ((char *)&(b))[1] = ((char *)&(a))[2]; \
- ((char *)&(b))[2] = ((char *)&(a))[1]; \
- ((char *)&(b))[3] = ((char *)&(a))[0]; \
-}
-
-/*
- * Little endian <==> big endian 16-bit swap macros.
- * M_16_SWAP swap a memory location
- * P_16_SWAP swap a referenced memory location
- * P_16_COPY swap from one location to another
- */
-#define M_16_SWAP(a) { \
- u_int16_t _tmp = a; \
- ((char *)&a)[0] = ((char *)&_tmp)[1]; \
- ((char *)&a)[1] = ((char *)&_tmp)[0]; \
-}
-#define P_16_SWAP(a) { \
- u_int16_t _tmp = *(u_int16_t *)a; \
- ((char *)a)[0] = ((char *)&_tmp)[1]; \
- ((char *)a)[1] = ((char *)&_tmp)[0]; \
-}
-#define P_16_COPY(a, b) { \
- ((char *)&(b))[0] = ((char *)&(a))[1]; \
- ((char *)&(b))[1] = ((char *)&(a))[0]; \
-}
-#endif
-
-__BEGIN_DECLS
-DB *__dbopen __P((const char *, int, int, DBTYPE, const void *));
-DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
-
-#ifdef __DBINTERFACE_PRIVATE
-DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
-DB *__hash_open __P((const char *, int, int, const HASHINFO *, int));
-DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
-void __dbpanic __P((DB *dbp));
-#endif
-__END_DECLS
-
-#endif /* db.h */
diff --git a/1.2-netsec/db1-ast/include/mpool.h b/1.2-netsec/db1-ast/include/mpool.h
deleted file mode 100644
index 0cfc5741c..000000000
--- a/1.2-netsec/db1-ast/include/mpool.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)mpool.h 8.2 (Berkeley) 7/14/94
- */
-
-#ifndef _MPOOL_H
-#define _MPOOL_H 1
-
-#include <sys/queue.h>
-#ifndef CIRCLEQ_HEAD
-#include <circ-queue.h>
-#endif
-
-/*
- * The memory pool scheme is a simple one. Each in-memory page is referenced
- * by a bucket which is threaded in up to two of three ways. All active pages
- * are threaded on a hash chain (hashed by page number) and an lru chain.
- * Inactive pages are threaded on a free chain. Each reference to a memory
- * pool is handed an opaque MPOOL cookie which stores all of this information.
- */
-#define HASHSIZE 128
-#define HASHKEY(pgno) ((pgno - 1) % HASHSIZE)
-
-/* The BKT structures are the elements of the queues. */
-typedef struct _bkt {
- CIRCLEQ_ENTRY(_bkt) hq; /* hash queue */
- CIRCLEQ_ENTRY(_bkt) q; /* lru queue */
- void *page; /* page */
- pgno_t pgno; /* page number */
-
-#define MPOOL_DIRTY 0x01 /* page needs to be written */
-#define MPOOL_PINNED 0x02 /* page is pinned into memory */
- u_int8_t flags; /* flags */
-} BKT;
-
-typedef struct MPOOL {
- CIRCLEQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */
- /* hash queue array */
- CIRCLEQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
- pgno_t curcache; /* current number of cached pages */
- pgno_t maxcache; /* max number of cached pages */
- pgno_t npages; /* number of pages in the file */
- u_long pagesize; /* file page size */
- int fd; /* file descriptor */
- /* page in conversion routine */
- void (*pgin) __P((void *, pgno_t, void *));
- /* page out conversion routine */
- void (*pgout) __P((void *, pgno_t, void *));
- void *pgcookie; /* cookie for page in/out routines */
-#ifdef STATISTICS
- u_long cachehit;
- u_long cachemiss;
- u_long pagealloc;
- u_long pageflush;
- u_long pageget;
- u_long pagenew;
- u_long pageput;
- u_long pageread;
- u_long pagewrite;
-#endif
-} MPOOL;
-
-__BEGIN_DECLS
-MPOOL *__mpool_open __P((void *, int, pgno_t, pgno_t));
-MPOOL *mpool_open __P((void *, int, pgno_t, pgno_t));
-void __mpool_filter __P((MPOOL *, void (*)(void *, pgno_t, void *),
- void (*)(void *, pgno_t, void *), void *));
-void mpool_filter __P((MPOOL *, void (*)(void *, pgno_t, void *),
- void (*)(void *, pgno_t, void *), void *));
-void *__mpool_new __P((MPOOL *, pgno_t *));
-void *mpool_new __P((MPOOL *, pgno_t *));
-void *__mpool_get __P((MPOOL *, pgno_t, u_int));
-void *mpool_get __P((MPOOL *, pgno_t, u_int));
-int __mpool_put __P((MPOOL *, void *, u_int));
-int mpool_put __P((MPOOL *, void *, u_int));
-int __mpool_sync __P((MPOOL *));
-int mpool_sync __P((MPOOL *));
-int __mpool_close __P((MPOOL *));
-int mpool_close __P((MPOOL *));
-#ifdef STATISTICS
-void mpool_stat __P((MPOOL *));
-#endif
-__END_DECLS
-
-#endif /* mpool.h */
diff --git a/1.2-netsec/db1-ast/include/ndbm.h b/1.2-netsec/db1-ast/include/ndbm.h
deleted file mode 100644
index db14dff2e..000000000
--- a/1.2-netsec/db1-ast/include/ndbm.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Margo Seltzer.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ndbm.h 8.1 (Berkeley) 6/2/93
- */
-
-#ifndef _NDBM_H
-#define _NDBM_H 1
-
-#include <db.h>
-
-/* Map dbm interface onto db(3). */
-#define DBM_RDONLY O_RDONLY
-
-/* Flags to dbm_store(). */
-#define DBM_INSERT 0
-#define DBM_REPLACE 1
-
-/*
- * The db(3) support for ndbm(3) always appends this suffix to the
- * file name to avoid overwriting the user's original database.
- */
-#define DBM_SUFFIX ".db"
-
-typedef struct {
- char *dptr;
- int dsize;
-} datum;
-
-typedef DB DBM;
-#define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE
-
-__BEGIN_DECLS
-void dbm_close __P((DBM *));
-int dbm_delete __P((DBM *, datum));
-datum dbm_fetch __P((DBM *, datum));
-datum dbm_firstkey __P((DBM *));
-long dbm_forder __P((DBM *, datum));
-datum dbm_nextkey __P((DBM *));
-DBM *dbm_open __P((const char *, int, int));
-int dbm_store __P((DBM *, datum, datum, int));
-int dbm_dirfno __P((DBM *));
-int dbm_error __P((DBM *));
-int dbm_clearerr __P((DBM *));
-__END_DECLS
-
-#endif /* ndbm.h */
diff --git a/1.2-netsec/db1-ast/libdb.map b/1.2-netsec/db1-ast/libdb.map
deleted file mode 100644
index 87e34c430..000000000
--- a/1.2-netsec/db1-ast/libdb.map
+++ /dev/null
@@ -1,11 +0,0 @@
-GLIBC_2.0 {
- global:
- # the real DB entry point.
- dbopen; __dbopen;
-
- # The compatibility functions.
- dbm_clearerr; dbm_close; dbm_delete; dbm_dirfno; dbm_error;
- dbm_fetch; dbm_firstkey; dbm_nextkey; dbm_open; dbm_store;
- local:
- *;
-};
diff --git a/1.2-netsec/db1-ast/mpool/README b/1.2-netsec/db1-ast/mpool/README
deleted file mode 100644
index 0f01fbcdb..000000000
--- a/1.2-netsec/db1-ast/mpool/README
+++ /dev/null
@@ -1,7 +0,0 @@
-# @(#)README 8.1 (Berkeley) 6/4/93
-
-These are the current memory pool routines.
-They aren't ready for prime time, yet, and
-the interface is expected to change.
-
---keith
diff --git a/1.2-netsec/db1-ast/mpool/mpool.c b/1.2-netsec/db1-ast/mpool/mpool.c
deleted file mode 100644
index eca24e518..000000000
--- a/1.2-netsec/db1-ast/mpool/mpool.c
+++ /dev/null
@@ -1,498 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)mpool.c 8.5 (Berkeley) 7/26/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <db.h>
-
-#define __MPOOLINTERFACE_PRIVATE
-#include <mpool.h>
-
-#undef __APPLE__
-
-#ifndef __APPLE__
-#define mpool_open __mpool_open
-#define mpool_filter __mpool_filter
-#define mpool_new __mpool_new
-#define mpool_get __mpool_get
-#define mpool_put __mpool_put
-#define mpool_sync __mpool_sync
-#define mpool_close __mpool_close
-#endif
-
-static BKT *mpool_bkt __P((MPOOL *));
-static BKT *mpool_look __P((MPOOL *, pgno_t));
-static int mpool_write __P((MPOOL *, BKT *));
-
-/*
- * mpool_open --
- * Initialize a memory pool.
- */
-MPOOL *
-mpool_open(key, fd, pagesize, maxcache)
- void *key;
- int fd;
- pgno_t pagesize, maxcache;
-{
- struct stat sb;
- MPOOL *mp;
- int entry;
-
- /*
- * Get information about the file.
- *
- * XXX
- * We don't currently handle pipes, although we should.
- */
- if (fstat(fd, &sb))
- return (NULL);
- if (!S_ISREG(sb.st_mode)) {
- errno = ESPIPE;
- return (NULL);
- }
-
- /* Allocate and initialize the MPOOL cookie. */
- if ((mp = (MPOOL *)calloc(1, sizeof(MPOOL))) == NULL)
- return (NULL);
- CIRCLEQ_INIT(&mp->lqh);
- for (entry = 0; entry < HASHSIZE; ++entry)
- CIRCLEQ_INIT(&mp->hqh[entry]);
- mp->maxcache = maxcache;
- mp->npages = sb.st_size / pagesize;
- mp->pagesize = pagesize;
- mp->fd = fd;
- return (mp);
-}
-
-/*
- * mpool_filter --
- * Initialize input/output filters.
- */
-void
-mpool_filter(mp, pgin, pgout, pgcookie)
- MPOOL *mp;
- void (*pgin) __P((void *, pgno_t, void *));
- void (*pgout) __P((void *, pgno_t, void *));
- void *pgcookie;
-{
- mp->pgin = pgin;
- mp->pgout = pgout;
- mp->pgcookie = pgcookie;
-}
-
-/*
- * mpool_new --
- * Get a new page of memory.
- */
-void *
-mpool_new(mp, pgnoaddr)
- MPOOL *mp;
- pgno_t *pgnoaddr;
-{
- struct _hqh *head;
- BKT *bp;
-
- if (mp->npages == MAX_PAGE_NUMBER) {
- (void)fprintf(stderr, "mpool_new: page allocation overflow.\n");
- abort();
- }
-#ifdef STATISTICS
- ++mp->pagenew;
-#endif
- /*
- * Get a BKT from the cache. Assign a new page number, attach
- * it to the head of the hash chain, the tail of the lru chain,
- * and return.
- */
- if ((bp = mpool_bkt(mp)) == NULL)
- return (NULL);
- *pgnoaddr = bp->pgno = mp->npages++;
- bp->flags = MPOOL_PINNED;
-
- head = &mp->hqh[HASHKEY(bp->pgno)];
- CIRCLEQ_INSERT_HEAD(head, bp, hq);
- CIRCLEQ_INSERT_TAIL(&mp->lqh, bp, q);
- return (bp->page);
-}
-
-/*
- * mpool_get
- * Get a page.
- */
-void *
-mpool_get(mp, pgno, flags)
- MPOOL *mp;
- pgno_t pgno;
- u_int flags; /* XXX not used? */
-{
- struct _hqh *head;
- BKT *bp;
- off_t off;
- int nr;
-
- /* Check for attempt to retrieve a non-existent page. */
- if (pgno >= mp->npages) {
- errno = EINVAL;
- return (NULL);
- }
-
-#ifdef STATISTICS
- ++mp->pageget;
-#endif
-
- /* Check for a page that is cached. */
- if ((bp = mpool_look(mp, pgno)) != NULL) {
-#ifdef DEBUG
- if (bp->flags & MPOOL_PINNED) {
- (void)fprintf(stderr,
- "mpool_get: page %d already pinned\n", bp->pgno);
- abort();
- }
-#endif
- /*
- * Move the page to the head of the hash chain and the tail
- * of the lru chain.
- */
- head = &mp->hqh[HASHKEY(bp->pgno)];
- CIRCLEQ_REMOVE(head, bp, hq);
- CIRCLEQ_INSERT_HEAD(head, bp, hq);
- CIRCLEQ_REMOVE(&mp->lqh, bp, q);
- CIRCLEQ_INSERT_TAIL(&mp->lqh, bp, q);
-
- /* Return a pinned page. */
- bp->flags |= MPOOL_PINNED;
- return (bp->page);
- }
-
- /* Get a page from the cache. */
- if ((bp = mpool_bkt(mp)) == NULL)
- return (NULL);
-
- /* Read in the contents. */
-#ifdef STATISTICS
- ++mp->pageread;
-#endif
- off = mp->pagesize * pgno;
- if (lseek(mp->fd, off, SEEK_SET) != off)
- return (NULL);
- if ((u_long) (nr = read(mp->fd, bp->page, mp->pagesize))
- != mp->pagesize) {
- if (nr >= 0)
- errno = EFTYPE;
- return (NULL);
- }
-
- /* Set the page number, pin the page. */
- bp->pgno = pgno;
- bp->flags = MPOOL_PINNED;
-
- /*
- * Add the page to the head of the hash chain and the tail
- * of the lru chain.
- */
- head = &mp->hqh[HASHKEY(bp->pgno)];
- CIRCLEQ_INSERT_HEAD(head, bp, hq);
- CIRCLEQ_INSERT_TAIL(&mp->lqh, bp, q);
-
- /* Run through the user's filter. */
- if (mp->pgin != NULL)
- (mp->pgin)(mp->pgcookie, bp->pgno, bp->page);
-
- return (bp->page);
-}
-
-/*
- * mpool_put
- * Return a page.
- */
-int
-mpool_put(mp, page, flags)
- MPOOL *mp;
- void *page;
- u_int flags;
-{
- BKT *bp;
-
-#ifdef STATISTICS
- ++mp->pageput;
-#endif
- bp = (BKT *)((char *)page - sizeof(BKT));
-#ifdef DEBUG
- if (!(bp->flags & MPOOL_PINNED)) {
- (void)fprintf(stderr,
- "mpool_put: page %d not pinned\n", bp->pgno);
- abort();
- }
-#endif
- bp->flags &= ~MPOOL_PINNED;
- bp->flags |= flags & MPOOL_DIRTY;
- return (RET_SUCCESS);
-}
-
-/*
- * mpool_close
- * Close the buffer pool.
- */
-int
-mpool_close(mp)
- MPOOL *mp;
-{
- BKT *bp;
-
- /* Free up any space allocated to the lru pages. */
- while ((bp = mp->lqh.cqh_first) != (void *)&mp->lqh) {
- CIRCLEQ_REMOVE(&mp->lqh, mp->lqh.cqh_first, q);
- free(bp);
- }
-
- /* Free the MPOOL cookie. */
- free(mp);
- return (RET_SUCCESS);
-}
-
-/*
- * mpool_sync
- * Sync the pool to disk.
- */
-int
-mpool_sync(mp)
- MPOOL *mp;
-{
- BKT *bp;
-
- /* Walk the lru chain, flushing any dirty pages to disk. */
- for (bp = mp->lqh.cqh_first;
- bp != (void *)&mp->lqh; bp = bp->q.cqe_next)
- if (bp->flags & MPOOL_DIRTY &&
- mpool_write(mp, bp) == RET_ERROR)
- return (RET_ERROR);
-
- /* Sync the file descriptor. */
- return (fsync(mp->fd) ? RET_ERROR : RET_SUCCESS);
-}
-
-#define __APPLE__
-
-#ifndef __APPLE__
-#undef mpool_open
-#undef mpool_filter
-#undef mpool_new
-#undef mpool_get
-#undef mpool_put
-#undef mpool_close
-#undef mpool_sync
-
-#define weak_alias(original, alias) \
- asm (".weak " #alias "\n" #alias " = " #original);
-weak_alias (__mpool_open, mpool_open)
-weak_alias (__mpool_filter, mpool_filter)
-weak_alias (__mpool_new, mpool_new)
-weak_alias (__mpool_get, mpool_get)
-weak_alias (__mpool_put, mpool_put)
-weak_alias (__mpool_close, mpool_close)
-weak_alias (__mpool_sync, mpool_sync)
-#endif
-
-/*
- * mpool_bkt
- * Get a page from the cache (or create one).
- */
-static BKT *
-mpool_bkt(mp)
- MPOOL *mp;
-{
- struct _hqh *head;
- BKT *bp;
-
- /* If under the max cached, always create a new page. */
- if (mp->curcache < mp->maxcache)
- goto new;
-
- /*
- * If the cache is max'd out, walk the lru list for a buffer we
- * can flush. If we find one, write it (if necessary) and take it
- * off any lists. If we don't find anything we grow the cache anyway.
- * The cache never shrinks.
- */
- for (bp = mp->lqh.cqh_first;
- bp != (void *)&mp->lqh; bp = bp->q.cqe_next)
- if (!(bp->flags & MPOOL_PINNED)) {
- /* Flush if dirty. */
- if (bp->flags & MPOOL_DIRTY &&
- mpool_write(mp, bp) == RET_ERROR)
- return (NULL);
-#ifdef STATISTICS
- ++mp->pageflush;
-#endif
- /* Remove from the hash and lru queues. */
- head = &mp->hqh[HASHKEY(bp->pgno)];
- CIRCLEQ_REMOVE(head, bp, hq);
- CIRCLEQ_REMOVE(&mp->lqh, bp, q);
-#ifdef DEBUG
- { void *spage;
- spage = bp->page;
- memset(bp, 0xff, sizeof(BKT) + mp->pagesize);
- bp->page = spage;
- }
-#endif
- return (bp);
- }
-
-new: if ((bp = (BKT *)malloc(sizeof(BKT) + mp->pagesize)) == NULL)
- return (NULL);
-#ifdef STATISTICS
- ++mp->pagealloc;
-#endif
-#if defined(DEBUG) || defined(PURIFY)
- memset(bp, 0xff, sizeof(BKT) + mp->pagesize);
-#endif
- bp->page = (char *)bp + sizeof(BKT);
- ++mp->curcache;
- return (bp);
-}
-
-/*
- * mpool_write
- * Write a page to disk.
- */
-static int
-mpool_write(mp, bp)
- MPOOL *mp;
- BKT *bp;
-{
- off_t off;
-
-#ifdef STATISTICS
- ++mp->pagewrite;
-#endif
-
- /* Run through the user's filter. */
- if (mp->pgout)
- (mp->pgout)(mp->pgcookie, bp->pgno, bp->page);
-
- off = mp->pagesize * bp->pgno;
- if (lseek(mp->fd, off, SEEK_SET) != off)
- return (RET_ERROR);
- if ((u_long) write(mp->fd, bp->page, mp->pagesize) != mp->pagesize)
- return (RET_ERROR);
-
- bp->flags &= ~MPOOL_DIRTY;
- return (RET_SUCCESS);
-}
-
-/*
- * mpool_look
- * Lookup a page in the cache.
- */
-static BKT *
-mpool_look(mp, pgno)
- MPOOL *mp;
- pgno_t pgno;
-{
- struct _hqh *head;
- BKT *bp;
-
- head = &mp->hqh[HASHKEY(pgno)];
- for (bp = head->cqh_first; bp != (void *)head; bp = bp->hq.cqe_next)
- if (bp->pgno == pgno) {
-#ifdef STATISTICS
- ++mp->cachehit;
-#endif
- return (bp);
- }
-#ifdef STATISTICS
- ++mp->cachemiss;
-#endif
- return (NULL);
-}
-
-#ifdef STATISTICS
-/*
- * mpool_stat
- * Print out cache statistics.
- */
-void
-mpool_stat(mp)
- MPOOL *mp;
-{
- BKT *bp;
- int cnt;
- char *sep;
-
- (void)fprintf(stderr, "%lu pages in the file\n", mp->npages);
- (void)fprintf(stderr,
- "page size %lu, cacheing %lu pages of %lu page max cache\n",
- mp->pagesize, mp->curcache, mp->maxcache);
- (void)fprintf(stderr, "%lu page puts, %lu page gets, %lu page new\n",
- mp->pageput, mp->pageget, mp->pagenew);
- (void)fprintf(stderr, "%lu page allocs, %lu page flushes\n",
- mp->pagealloc, mp->pageflush);
- if (mp->cachehit + mp->cachemiss)
- (void)fprintf(stderr,
- "%.0f%% cache hit rate (%lu hits, %lu misses)\n",
- ((double)mp->cachehit / (mp->cachehit + mp->cachemiss))
- * 100, mp->cachehit, mp->cachemiss);
- (void)fprintf(stderr, "%lu page reads, %lu page writes\n",
- mp->pageread, mp->pagewrite);
-
- sep = "";
- cnt = 0;
- for (bp = mp->lqh.cqh_first;
- bp != (void *)&mp->lqh; bp = bp->q.cqe_next) {
- (void)fprintf(stderr, "%s%d", sep, bp->pgno);
- if (bp->flags & MPOOL_DIRTY)
- (void)fprintf(stderr, "d");
- if (bp->flags & MPOOL_PINNED)
- (void)fprintf(stderr, "P");
- if (++cnt == 10) {
- sep = "\n";
- cnt = 0;
- } else
- sep = ", ";
-
- }
- (void)fprintf(stderr, "\n");
-}
-#endif
diff --git a/1.2-netsec/db1-ast/recno/extern.h b/1.2-netsec/db1-ast/recno/extern.h
deleted file mode 100644
index feed43445..000000000
--- a/1.2-netsec/db1-ast/recno/extern.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)extern.h 8.3 (Berkeley) 6/4/94
- */
-
-#include "../btree/extern.h"
-
-int __rec_close __P((DB *));
-int __rec_delete __P((const DB *, const DBT *, u_int));
-int __rec_dleaf __P((BTREE *, PAGE *, u_int32_t));
-int __rec_fd __P((const DB *));
-int __rec_fmap __P((BTREE *, recno_t));
-int __rec_fout __P((BTREE *));
-int __rec_fpipe __P((BTREE *, recno_t));
-int __rec_get __P((const DB *, const DBT *, DBT *, u_int));
-int __rec_iput __P((BTREE *, recno_t, const DBT *, u_int));
-int __rec_put __P((const DB *dbp, DBT *, const DBT *, u_int));
-int __rec_ret __P((BTREE *, EPG *, recno_t, DBT *, DBT *));
-EPG *__rec_search __P((BTREE *, recno_t, enum SRCHOP));
-int __rec_seq __P((const DB *, DBT *, DBT *, u_int));
-int __rec_sync __P((const DB *, u_int));
-int __rec_vmap __P((BTREE *, recno_t));
-int __rec_vout __P((BTREE *));
-int __rec_vpipe __P((BTREE *, recno_t));
diff --git a/1.2-netsec/db1-ast/recno/rec_close.c b/1.2-netsec/db1-ast/recno/rec_close.c
deleted file mode 100644
index 8a3c4d77d..000000000
--- a/1.2-netsec/db1-ast/recno/rec_close.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rec_close.c 8.6 (Berkeley) 8/18/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/mman.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include <db.h>
-#include "recno.h"
-
-/*
- * __REC_CLOSE -- Close a recno tree.
- *
- * Parameters:
- * dbp: pointer to access method
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__rec_close(dbp)
- DB *dbp;
-{
- BTREE *t;
- int status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- if (__rec_sync(dbp, 0) == RET_ERROR)
- return (RET_ERROR);
-
- /* Committed to closing. */
- status = RET_SUCCESS;
- if (F_ISSET(t, R_MEMMAPPED) && munmap(t->bt_smap, t->bt_msize))
- status = RET_ERROR;
-
- if (!F_ISSET(t, R_INMEM)) {
- if (F_ISSET(t, R_CLOSEFP)) {
- if (fclose(t->bt_rfp))
- status = RET_ERROR;
- } else
- if (close(t->bt_rfd))
- status = RET_ERROR;
- }
-
- if (__bt_close(dbp) == RET_ERROR)
- status = RET_ERROR;
-
- return (status);
-}
-
-/*
- * __REC_SYNC -- sync the recno tree to disk.
- *
- * Parameters:
- * dbp: pointer to access method
- *
- * Returns:
- * RET_SUCCESS, RET_ERROR.
- */
-int
-__rec_sync(dbp, flags)
- const DB *dbp;
- u_int flags;
-{
- struct iovec iov[2];
- BTREE *t;
- DBT data, key;
- off_t off;
- recno_t scursor, trec;
- int status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- if (flags == R_RECNOSYNC)
- return (__bt_sync(dbp, 0));
-
- if (F_ISSET(t, R_RDONLY | R_INMEM) || !F_ISSET(t, R_MODIFIED))
- return (RET_SUCCESS);
-
- /* Read any remaining records into the tree. */
- if (!F_ISSET(t, R_EOF) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR)
- return (RET_ERROR);
-
- /* Rewind the file descriptor. */
- if (lseek(t->bt_rfd, (off_t)0, SEEK_SET) != 0)
- return (RET_ERROR);
-
- /* Save the cursor. */
- scursor = t->bt_cursor.rcursor;
-
- key.size = sizeof(recno_t);
- key.data = &trec;
-
- if (F_ISSET(t, R_FIXLEN)) {
- /*
- * We assume that fixed length records are all fixed length.
- * Any that aren't are either EINVAL'd or corrected by the
- * record put code.
- */
- status = (dbp->seq)(dbp, &key, &data, R_FIRST);
- while (status == RET_SUCCESS) {
- if ((size_t) write(t->bt_rfd, data.data, data.size) != data.size)
- return (RET_ERROR);
- status = (dbp->seq)(dbp, &key, &data, R_NEXT);
- }
- } else {
- iov[1].iov_base = &t->bt_bval;
- iov[1].iov_len = 1;
-
- status = (dbp->seq)(dbp, &key, &data, R_FIRST);
- while (status == RET_SUCCESS) {
- iov[0].iov_base = data.data;
- iov[0].iov_len = data.size;
- if ((size_t) writev(t->bt_rfd, iov, 2) != data.size + 1)
- return (RET_ERROR);
- status = (dbp->seq)(dbp, &key, &data, R_NEXT);
- }
- }
-
- /* Restore the cursor. */
- t->bt_cursor.rcursor = scursor;
-
- if (status == RET_ERROR)
- return (RET_ERROR);
- if ((off = lseek(t->bt_rfd, (off_t)0, SEEK_CUR)) == -1)
- return (RET_ERROR);
- if (ftruncate(t->bt_rfd, off))
- return (RET_ERROR);
- F_CLR(t, R_MODIFIED);
- return (RET_SUCCESS);
-}
diff --git a/1.2-netsec/db1-ast/recno/rec_delete.c b/1.2-netsec/db1-ast/recno/rec_delete.c
deleted file mode 100644
index a16593d4e..000000000
--- a/1.2-netsec/db1-ast/recno/rec_delete.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rec_delete.c 8.7 (Berkeley) 7/14/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <db.h>
-#include "recno.h"
-
-static int rec_rdelete __P((BTREE *, recno_t));
-
-/*
- * __REC_DELETE -- Delete the item(s) referenced by a key.
- *
- * Parameters:
- * dbp: pointer to access method
- * key: key to delete
- * flags: R_CURSOR if deleting what the cursor references
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found.
- */
-int
-__rec_delete(dbp, key, flags)
- const DB *dbp;
- const DBT *key;
- u_int flags;
-{
- BTREE *t;
- recno_t nrec;
- int status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- switch(flags) {
- case 0:
- if ((nrec = *(recno_t *)key->data) == 0)
- goto einval;
- if (nrec > t->bt_nrecs)
- return (RET_SPECIAL);
- --nrec;
- status = rec_rdelete(t, nrec);
- break;
- case R_CURSOR:
- if (!F_ISSET(&t->bt_cursor, CURS_INIT))
- goto einval;
- if (t->bt_nrecs == 0)
- return (RET_SPECIAL);
- status = rec_rdelete(t, t->bt_cursor.rcursor - 1);
- if (status == RET_SUCCESS)
- --t->bt_cursor.rcursor;
- break;
- default:
-einval: errno = EINVAL;
- return (RET_ERROR);
- }
-
- if (status == RET_SUCCESS)
- F_SET(t, B_MODIFIED | R_MODIFIED);
- return (status);
-}
-
-/*
- * REC_RDELETE -- Delete the data matching the specified key.
- *
- * Parameters:
- * tree: tree
- * nrec: record to delete
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found.
- */
-static int
-rec_rdelete(t, nrec)
- BTREE *t;
- recno_t nrec;
-{
- EPG *e;
- PAGE *h;
- int status;
-
- /* Find the record; __rec_search pins the page. */
- if ((e = __rec_search(t, nrec, SDELETE)) == NULL)
- return (RET_ERROR);
-
- /* Delete the record. */
- h = e->page;
- status = __rec_dleaf(t, h, e->index);
- if (status != RET_SUCCESS) {
- mpool_put(t->bt_mp, h, 0);
- return (status);
- }
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- return (RET_SUCCESS);
-}
-
-/*
- * __REC_DLEAF -- Delete a single record from a recno leaf page.
- *
- * Parameters:
- * t: tree
- * index: index on current page to delete
- *
- * Returns:
- * RET_SUCCESS, RET_ERROR.
- */
-int
-__rec_dleaf(t, h, index)
- BTREE *t;
- PAGE *h;
- u_int32_t index;
-{
- RLEAF *rl;
- indx_t *ip, cnt, offset;
- u_int32_t nbytes;
- char *from;
- void *to;
-
- /*
- * Delete a record from a recno leaf page. Internal records are never
- * deleted from internal pages, regardless of the records that caused
- * them to be added being deleted. Pages made empty by deletion are
- * not reclaimed. They are, however, made available for reuse.
- *
- * Pack the remaining entries at the end of the page, shift the indices
- * down, overwriting the deleted record and its index. If the record
- * uses overflow pages, make them available for reuse.
- */
- to = rl = GETRLEAF(h, index);
- if (rl->flags & P_BIGDATA && __ovfl_delete(t, rl->bytes) == RET_ERROR)
- return (RET_ERROR);
- nbytes = NRLEAF(rl);
-
- /*
- * Compress the key/data pairs. Compress and adjust the [BR]LEAF
- * offsets. Reset the headers.
- */
- from = (char *)h + h->upper;
- memmove(from + nbytes, from, (char *)to - from);
- h->upper += nbytes;
-
- offset = h->linp[index];
- for (cnt = &h->linp[index] - (ip = &h->linp[0]); cnt--; ++ip)
- if (ip[0] < offset)
- ip[0] += nbytes;
- for (cnt = &h->linp[NEXTINDEX(h)] - ip; --cnt; ++ip)
- ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1];
- h->lower -= sizeof(indx_t);
- --t->bt_nrecs;
- return (RET_SUCCESS);
-}
diff --git a/1.2-netsec/db1-ast/recno/rec_get.c b/1.2-netsec/db1-ast/recno/rec_get.c
deleted file mode 100644
index 47dd773fb..000000000
--- a/1.2-netsec/db1-ast/recno/rec_get.c
+++ /dev/null
@@ -1,311 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rec_get.c 8.9 (Berkeley) 8/18/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <db.h>
-#include "recno.h"
-
-/*
- * __REC_GET -- Get a record from the btree.
- *
- * Parameters:
- * dbp: pointer to access method
- * key: key to find
- * data: data to return
- * flag: currently unused
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found.
- */
-int
-__rec_get(dbp, key, data, flags)
- const DB *dbp;
- const DBT *key;
- DBT *data;
- u_int flags;
-{
- BTREE *t;
- EPG *e;
- recno_t nrec;
- int status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /* Get currently doesn't take any flags, and keys of 0 are illegal. */
- if (flags || (nrec = *(recno_t *)key->data) == 0) {
- errno = EINVAL;
- return (RET_ERROR);
- }
-
- /*
- * If we haven't seen this record yet, try to find it in the
- * original file.
- */
- if (nrec > t->bt_nrecs) {
- if (F_ISSET(t, R_EOF | R_INMEM))
- return (RET_SPECIAL);
- if ((status = t->bt_irec(t, nrec)) != RET_SUCCESS)
- return (status);
- }
-
- --nrec;
- if ((e = __rec_search(t, nrec, SEARCH)) == NULL)
- return (RET_ERROR);
-
- status = __rec_ret(t, e, 0, NULL, data);
- if (F_ISSET(t, B_DB_LOCK))
- mpool_put(t->bt_mp, e->page, 0);
- else
- t->bt_pinned = e->page;
- return (status);
-}
-
-/*
- * __REC_FPIPE -- Get fixed length records from a pipe.
- *
- * Parameters:
- * t: tree
- * cnt: records to read
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__rec_fpipe(t, top)
- BTREE *t;
- recno_t top;
-{
- DBT data;
- recno_t nrec;
- size_t len;
- int ch;
- u_char *p;
-
- if (t->bt_rdata.size < t->bt_reclen) {
- t->bt_rdata.data = t->bt_rdata.data == NULL ?
- malloc(t->bt_reclen) :
- realloc(t->bt_rdata.data, t->bt_reclen);
- if (t->bt_rdata.data == NULL)
- return (RET_ERROR);
- t->bt_rdata.size = t->bt_reclen;
- }
- data.data = t->bt_rdata.data;
- data.size = t->bt_reclen;
-
- for (nrec = t->bt_nrecs; nrec < top;) {
- len = t->bt_reclen;
- for (p = t->bt_rdata.data;; *p++ = ch)
- if ((ch = getc(t->bt_rfp)) == EOF || !--len) {
- if (ch != EOF)
- *p = ch;
- if (len != 0)
- memset(p, t->bt_bval, len);
- if (__rec_iput(t,
- nrec, &data, 0) != RET_SUCCESS)
- return (RET_ERROR);
- ++nrec;
- break;
- }
- if (ch == EOF)
- break;
- }
- if (nrec < top) {
- F_SET(t, R_EOF);
- return (RET_SPECIAL);
- }
- return (RET_SUCCESS);
-}
-
-/*
- * __REC_VPIPE -- Get variable length records from a pipe.
- *
- * Parameters:
- * t: tree
- * cnt: records to read
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__rec_vpipe(t, top)
- BTREE *t;
- recno_t top;
-{
- DBT data;
- recno_t nrec;
- indx_t len;
- size_t sz;
- int bval, ch;
- u_char *p;
-
- bval = t->bt_bval;
- for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
- for (p = t->bt_rdata.data,
- sz = t->bt_rdata.size;; *p++ = ch, --sz) {
- if ((ch = getc(t->bt_rfp)) == EOF || ch == bval) {
- data.data = t->bt_rdata.data;
- data.size = p - (u_char *)t->bt_rdata.data;
- if (ch == EOF && data.size == 0)
- break;
- if (__rec_iput(t, nrec, &data, 0)
- != RET_SUCCESS)
- return (RET_ERROR);
- break;
- }
- if (sz == 0) {
- len = p - (u_char *)t->bt_rdata.data;
- t->bt_rdata.size += (sz = 256);
- t->bt_rdata.data = t->bt_rdata.data == NULL ?
- malloc(t->bt_rdata.size) :
- realloc(t->bt_rdata.data, t->bt_rdata.size);
- if (t->bt_rdata.data == NULL)
- return (RET_ERROR);
- p = (u_char *)t->bt_rdata.data + len;
- }
- }
- if (ch == EOF)
- break;
- }
- if (nrec < top) {
- F_SET(t, R_EOF);
- return (RET_SPECIAL);
- }
- return (RET_SUCCESS);
-}
-
-/*
- * __REC_FMAP -- Get fixed length records from a file.
- *
- * Parameters:
- * t: tree
- * cnt: records to read
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__rec_fmap(t, top)
- BTREE *t;
- recno_t top;
-{
- DBT data;
- recno_t nrec;
- u_char *sp, *ep, *p;
- size_t len;
-
- if (t->bt_rdata.size < t->bt_reclen) {
- t->bt_rdata.data = t->bt_rdata.data == NULL ?
- malloc(t->bt_reclen) :
- realloc(t->bt_rdata.data, t->bt_reclen);
- if (t->bt_rdata.data == NULL)
- return (RET_ERROR);
- t->bt_rdata.size = t->bt_reclen;
- }
- data.data = t->bt_rdata.data;
- data.size = t->bt_reclen;
-
- sp = (u_char *)t->bt_cmap;
- ep = (u_char *)t->bt_emap;
- for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
- if (sp >= ep) {
- F_SET(t, R_EOF);
- return (RET_SPECIAL);
- }
- len = t->bt_reclen;
- for (p = t->bt_rdata.data;
- sp < ep && len > 0; *p++ = *sp++, --len);
- if (len != 0)
- memset(p, t->bt_bval, len);
- if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS)
- return (RET_ERROR);
- }
- t->bt_cmap = (caddr_t)sp;
- return (RET_SUCCESS);
-}
-
-/*
- * __REC_VMAP -- Get variable length records from a file.
- *
- * Parameters:
- * t: tree
- * cnt: records to read
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__rec_vmap(t, top)
- BTREE *t;
- recno_t top;
-{
- DBT data;
- u_char *sp, *ep;
- recno_t nrec;
- int bval;
-
- sp = (u_char *)t->bt_cmap;
- ep = (u_char *)t->bt_emap;
- bval = t->bt_bval;
-
- for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
- if (sp >= ep) {
- F_SET(t, R_EOF);
- return (RET_SPECIAL);
- }
- for (data.data = sp; sp < ep && *sp != bval; ++sp);
- data.size = sp - (u_char *)data.data;
- if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS)
- return (RET_ERROR);
- ++sp;
- }
- t->bt_cmap = (caddr_t)sp;
- return (RET_SUCCESS);
-}
diff --git a/1.2-netsec/db1-ast/recno/rec_open.c b/1.2-netsec/db1-ast/recno/rec_open.c
deleted file mode 100644
index cf9511e87..000000000
--- a/1.2-netsec/db1-ast/recno/rec_open.c
+++ /dev/null
@@ -1,241 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Mike Olson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rec_open.c 8.10 (Berkeley) 9/1/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include <db.h>
-#include "recno.h"
-
-DB *
-__rec_open(fname, flags, mode, openinfo, dflags)
- const char *fname;
- int flags, mode, dflags;
- const RECNOINFO *openinfo;
-{
- BTREE *t;
- BTREEINFO btopeninfo;
- DB *dbp;
- PAGE *h;
- struct stat sb;
- int rfd = 0, sverrno;
-
- /* Open the user's file -- if this fails, we're done. */
- if (fname != NULL && (rfd = open(fname, flags, mode)) < 0)
- return (NULL);
-
- /* Create a btree in memory (backed by disk). */
- dbp = NULL;
- if (openinfo) {
- if (openinfo->flags & ~(R_FIXEDLEN | R_NOKEY | R_SNAPSHOT))
- goto einval;
- btopeninfo.flags = 0;
- btopeninfo.cachesize = openinfo->cachesize;
- btopeninfo.maxkeypage = 0;
- btopeninfo.minkeypage = 0;
- btopeninfo.psize = openinfo->psize;
- btopeninfo.compare = NULL;
- btopeninfo.prefix = NULL;
- btopeninfo.lorder = openinfo->lorder;
- dbp = __bt_open(openinfo->bfname,
- O_RDWR, S_IRUSR | S_IWUSR, &btopeninfo, dflags);
- } else
- dbp = __bt_open(NULL, O_RDWR, S_IRUSR | S_IWUSR, NULL, dflags);
- if (dbp == NULL)
- goto err;
-
- /*
- * Some fields in the tree structure are recno specific. Fill them
- * in and make the btree structure look like a recno structure. We
- * don't change the bt_ovflsize value, it's close enough and slightly
- * bigger.
- */
- t = dbp->internal;
- if (openinfo) {
- if (openinfo->flags & R_FIXEDLEN) {
- F_SET(t, R_FIXLEN);
- t->bt_reclen = openinfo->reclen;
- if (t->bt_reclen == 0)
- goto einval;
- }
- t->bt_bval = openinfo->bval;
- } else
- t->bt_bval = '\n';
-
- F_SET(t, R_RECNO);
- if (fname == NULL)
- F_SET(t, R_EOF | R_INMEM);
- else
- t->bt_rfd = rfd;
-
- if (fname != NULL) {
- /*
- * In 4.4BSD, stat(2) returns true for ISSOCK on pipes.
- * Unfortunately, that's not portable, so we use lseek
- * and check the errno values.
- */
- errno = 0;
- if (lseek(rfd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) {
- switch (flags & O_ACCMODE) {
- case O_RDONLY:
- F_SET(t, R_RDONLY);
- break;
- default:
- goto einval;
- }
-slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL)
- goto err;
- F_SET(t, R_CLOSEFP);
- t->bt_irec =
- F_ISSET(t, R_FIXLEN) ? __rec_fpipe : __rec_vpipe;
- } else {
- switch (flags & O_ACCMODE) {
- case O_RDONLY:
- F_SET(t, R_RDONLY);
- break;
- case O_RDWR:
- break;
- default:
- goto einval;
- }
-
- if (fstat(rfd, &sb))
- goto err;
- /*
- * Kluge -- we'd like to test to see if the file is too
- * big to mmap. Since, we don't know what size or type
- * off_t's or size_t's are, what the largest unsigned
- * integral type is, or what random insanity the local
- * C compiler will perpetrate, doing the comparison in
- * a portable way is flatly impossible. Hope that mmap
- * fails if the file is too large.
- */
- if (sb.st_size == 0)
- F_SET(t, R_EOF);
- else {
-#ifdef MMAP_NOT_AVAILABLE
- /*
- * XXX
- * Mmap doesn't work correctly on many current
- * systems. In particular, it can fail subtly,
- * with cache coherency problems. Don't use it
- * for now.
- */
- t->bt_msize = sb.st_size;
- if ((t->bt_smap = mmap(NULL, t->bt_msize,
- PROT_READ, MAP_PRIVATE, rfd,
- (off_t)0)) == (caddr_t)-1)
- goto slow;
- t->bt_cmap = t->bt_smap;
- t->bt_emap = t->bt_smap + sb.st_size;
- t->bt_irec = F_ISSET(t, R_FIXLEN) ?
- __rec_fmap : __rec_vmap;
- F_SET(t, R_MEMMAPPED);
-#else
- goto slow;
-#endif
- }
- }
- }
-
- /* Use the recno routines. */
- dbp->close = __rec_close;
- dbp->del = __rec_delete;
- dbp->fd = __rec_fd;
- dbp->get = __rec_get;
- dbp->put = __rec_put;
- dbp->seq = __rec_seq;
- dbp->sync = __rec_sync;
-
- /* If the root page was created, reset the flags. */
- if ((h = mpool_get(t->bt_mp, P_ROOT, 0)) == NULL)
- goto err;
- if ((h->flags & P_TYPE) == P_BLEAF) {
- F_CLR(h, P_TYPE);
- F_SET(h, P_RLEAF);
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- } else
- mpool_put(t->bt_mp, h, 0);
-
- if (openinfo && openinfo->flags & R_SNAPSHOT &&
- !F_ISSET(t, R_EOF | R_INMEM) &&
- t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR)
- goto err;
- return (dbp);
-
-einval: errno = EINVAL;
-err: sverrno = errno;
- if (dbp != NULL)
- (void)__bt_close(dbp);
- if (fname != NULL)
- (void)close(rfd);
- errno = sverrno;
- return (NULL);
-}
-
-int
-__rec_fd(dbp)
- const DB *dbp;
-{
- BTREE *t;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /* In-memory database can't have a file descriptor. */
- if (F_ISSET(t, R_INMEM)) {
- errno = ENOENT;
- return (-1);
- }
- return (t->bt_rfd);
-}
diff --git a/1.2-netsec/db1-ast/recno/rec_put.c b/1.2-netsec/db1-ast/recno/rec_put.c
deleted file mode 100644
index 5454c40e8..000000000
--- a/1.2-netsec/db1-ast/recno/rec_put.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rec_put.c 8.7 (Berkeley) 8/18/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <db.h>
-#include "recno.h"
-
-/*
- * __REC_PUT -- Add a recno item to the tree.
- *
- * Parameters:
- * dbp: pointer to access method
- * key: key
- * data: data
- * flag: R_CURSOR, R_IAFTER, R_IBEFORE, R_NOOVERWRITE
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is
- * already in the tree and R_NOOVERWRITE specified.
- */
-int
-__rec_put(dbp, key, data, flags)
- const DB *dbp;
- DBT *key;
- const DBT *data;
- u_int flags;
-{
- BTREE *t;
- DBT fdata, tdata;
- recno_t nrec;
- int status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- /*
- * If using fixed-length records, and the record is long, return
- * EINVAL. If it's short, pad it out. Use the record data return
- * memory, it's only short-term.
- */
- if (F_ISSET(t, R_FIXLEN) && data->size != t->bt_reclen) {
- if (data->size > t->bt_reclen)
- goto einval;
-
- if (t->bt_rdata.size < t->bt_reclen) {
- t->bt_rdata.data = t->bt_rdata.data == NULL ?
- malloc(t->bt_reclen) :
- realloc(t->bt_rdata.data, t->bt_reclen);
- if (t->bt_rdata.data == NULL)
- return (RET_ERROR);
- t->bt_rdata.size = t->bt_reclen;
- }
- memmove(t->bt_rdata.data, data->data, data->size);
- memset((char *)t->bt_rdata.data + data->size,
- t->bt_bval, t->bt_reclen - data->size);
- fdata.data = t->bt_rdata.data;
- fdata.size = t->bt_reclen;
- } else {
- fdata.data = data->data;
- fdata.size = data->size;
- }
-
- switch (flags) {
- case R_CURSOR:
- if (!F_ISSET(&t->bt_cursor, CURS_INIT))
- goto einval;
- nrec = t->bt_cursor.rcursor;
- break;
- case R_SETCURSOR:
- if ((nrec = *(recno_t *)key->data) == 0)
- goto einval;
- break;
- case R_IAFTER:
- if ((nrec = *(recno_t *)key->data) == 0) {
- nrec = 1;
- flags = R_IBEFORE;
- }
- break;
- case 0:
- case R_IBEFORE:
- if ((nrec = *(recno_t *)key->data) == 0)
- goto einval;
- break;
- case R_NOOVERWRITE:
- if ((nrec = *(recno_t *)key->data) == 0)
- goto einval;
- if (nrec <= t->bt_nrecs)
- return (RET_SPECIAL);
- break;
- default:
-einval: errno = EINVAL;
- return (RET_ERROR);
- }
-
- /*
- * Make sure that records up to and including the put record are
- * already in the database. If skipping records, create empty ones.
- */
- if (nrec > t->bt_nrecs) {
- if (!F_ISSET(t, R_EOF | R_INMEM) &&
- t->bt_irec(t, nrec) == RET_ERROR)
- return (RET_ERROR);
- if (nrec > t->bt_nrecs + 1) {
- if (F_ISSET(t, R_FIXLEN)) {
- if ((tdata.data =
- (void *)malloc(t->bt_reclen)) == NULL)
- return (RET_ERROR);
- tdata.size = t->bt_reclen;
- memset(tdata.data, t->bt_bval, tdata.size);
- } else {
- tdata.data = NULL;
- tdata.size = 0;
- }
- while (nrec > t->bt_nrecs + 1)
- if (__rec_iput(t,
- t->bt_nrecs, &tdata, 0) != RET_SUCCESS)
- return (RET_ERROR);
- if (F_ISSET(t, R_FIXLEN))
- free(tdata.data);
- }
- }
-
- if ((status = __rec_iput(t, nrec - 1, &fdata, flags)) != RET_SUCCESS)
- return (status);
-
- if (flags == R_SETCURSOR)
- t->bt_cursor.rcursor = nrec;
-
- F_SET(t, R_MODIFIED);
- return (__rec_ret(t, NULL, nrec, key, NULL));
-}
-
-/*
- * __REC_IPUT -- Add a recno item to the tree.
- *
- * Parameters:
- * t: tree
- * nrec: record number
- * data: data
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
- */
-int
-__rec_iput(t, nrec, data, flags)
- BTREE *t;
- recno_t nrec;
- const DBT *data;
- u_int flags;
-{
- DBT tdata;
- EPG *e;
- PAGE *h;
- indx_t index, nxtindex;
- pgno_t pg;
- u_int32_t nbytes;
- int dflags, status;
- char *dest, db[NOVFLSIZE];
-
- /*
- * If the data won't fit on a page, store it on indirect pages.
- *
- * XXX
- * If the insert fails later on, these pages aren't recovered.
- */
- if (data->size > t->bt_ovflsize) {
- if (__ovfl_put(t, data, &pg) == RET_ERROR)
- return (RET_ERROR);
- tdata.data = db;
- tdata.size = NOVFLSIZE;
- *(pgno_t *)db = pg;
- *(u_int32_t *)(db + sizeof(pgno_t)) = data->size;
- dflags = P_BIGDATA;
- data = &tdata;
- } else
- dflags = 0;
-
- /* __rec_search pins the returned page. */
- if ((e = __rec_search(t, nrec,
- nrec > t->bt_nrecs || flags == R_IAFTER || flags == R_IBEFORE ?
- SINSERT : SEARCH)) == NULL)
- return (RET_ERROR);
-
- h = e->page;
- index = e->index;
-
- /*
- * Add the specified key/data pair to the tree. The R_IAFTER and
- * R_IBEFORE flags insert the key after/before the specified key.
- *
- * Pages are split as required.
- */
- switch (flags) {
- case R_IAFTER:
- ++index;
- break;
- case R_IBEFORE:
- break;
- default:
- if (nrec < t->bt_nrecs &&
- __rec_dleaf(t, h, index) == RET_ERROR) {
- mpool_put(t->bt_mp, h, 0);
- return (RET_ERROR);
- }
- break;
- }
-
- /*
- * If not enough room, split the page. The split code will insert
- * the key and data and unpin the current page. If inserting into
- * the offset array, shift the pointers up.
- */
- nbytes = NRLEAFDBT(data->size);
- if ((u_int32_t) (h->upper - h->lower) < nbytes + sizeof(indx_t)) {
- status = __bt_split(t, h, NULL, data, dflags, nbytes, index);
- if (status == RET_SUCCESS)
- ++t->bt_nrecs;
- return (status);
- }
-
- if (index < (nxtindex = NEXTINDEX(h)))
- memmove(h->linp + index + 1, h->linp + index,
- (nxtindex - index) * sizeof(indx_t));
- h->lower += sizeof(indx_t);
-
- h->linp[index] = h->upper -= nbytes;
- dest = (char *)h + h->upper;
- WR_RLEAF(dest, data, dflags);
-
- ++t->bt_nrecs;
- F_SET(t, B_MODIFIED);
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
-
- return (RET_SUCCESS);
-}
diff --git a/1.2-netsec/db1-ast/recno/rec_search.c b/1.2-netsec/db1-ast/recno/rec_search.c
deleted file mode 100644
index acc109e99..000000000
--- a/1.2-netsec/db1-ast/recno/rec_search.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rec_search.c 8.4 (Berkeley) 7/14/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdio.h>
-
-#include <db.h>
-#include "recno.h"
-
-/*
- * __REC_SEARCH -- Search a btree for a key.
- *
- * Parameters:
- * t: tree to search
- * recno: key to find
- * op: search operation
- *
- * Returns:
- * EPG for matching record, if any, or the EPG for the location of the
- * key, if it were inserted into the tree.
- *
- * Returns:
- * The EPG for matching record, if any, or the EPG for the location
- * of the key, if it were inserted into the tree, is entered into
- * the bt_cur field of the tree. A pointer to the field is returned.
- */
-EPG *
-__rec_search(t, recno, op)
- BTREE *t;
- recno_t recno;
- enum SRCHOP op;
-{
- register indx_t index;
- register PAGE *h;
- EPGNO *parent;
- RINTERNAL *r;
- pgno_t pg;
- indx_t top;
- recno_t total;
- int sverrno;
-
- BT_CLR(t);
- for (pg = P_ROOT, total = 0;;) {
- if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
- goto err;
- if (h->flags & P_RLEAF) {
- t->bt_cur.page = h;
- t->bt_cur.index = recno - total;
- return (&t->bt_cur);
- }
- for (index = 0, top = NEXTINDEX(h);;) {
- r = GETRINTERNAL(h, index);
- if (++index == top || total + r->nrecs > recno)
- break;
- total += r->nrecs;
- }
-
- BT_PUSH(t, pg, index - 1);
-
- pg = r->pgno;
- switch (op) {
- case SDELETE:
- --GETRINTERNAL(h, (index - 1))->nrecs;
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- break;
- case SINSERT:
- ++GETRINTERNAL(h, (index - 1))->nrecs;
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- break;
- case SEARCH:
- mpool_put(t->bt_mp, h, 0);
- break;
- }
-
- }
- /* Try and recover the tree. */
-err: sverrno = errno;
- if (op != SEARCH)
- while ((parent = BT_POP(t)) != NULL) {
- if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL)
- break;
- if (op == SINSERT)
- --GETRINTERNAL(h, parent->index)->nrecs;
- else
- ++GETRINTERNAL(h, parent->index)->nrecs;
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- }
- errno = sverrno;
- return (NULL);
-}
diff --git a/1.2-netsec/db1-ast/recno/rec_seq.c b/1.2-netsec/db1-ast/recno/rec_seq.c
deleted file mode 100644
index 2f8c7695c..000000000
--- a/1.2-netsec/db1-ast/recno/rec_seq.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rec_seq.c 8.3 (Berkeley) 7/14/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <db.h>
-#include "recno.h"
-
-/*
- * __REC_SEQ -- Recno sequential scan interface.
- *
- * Parameters:
- * dbp: pointer to access method
- * key: key for positioning and return value
- * data: data return value
- * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV.
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key.
- */
-int
-__rec_seq(dbp, key, data, flags)
- const DB *dbp;
- DBT *key, *data;
- u_int flags;
-{
- BTREE *t;
- EPG *e;
- recno_t nrec;
- int status;
-
- t = dbp->internal;
-
- /* Toss any page pinned across calls. */
- if (t->bt_pinned != NULL) {
- mpool_put(t->bt_mp, t->bt_pinned, 0);
- t->bt_pinned = NULL;
- }
-
- switch(flags) {
- case R_CURSOR:
- if ((nrec = *(recno_t *)key->data) == 0)
- goto einval;
- break;
- case R_NEXT:
- if (F_ISSET(&t->bt_cursor, CURS_INIT)) {
- nrec = t->bt_cursor.rcursor + 1;
- break;
- }
- /* FALLTHROUGH */
- case R_FIRST:
- nrec = 1;
- break;
- case R_PREV:
- if (F_ISSET(&t->bt_cursor, CURS_INIT)) {
- if ((nrec = t->bt_cursor.rcursor - 1) == 0)
- return (RET_SPECIAL);
- break;
- }
- /* FALLTHROUGH */
- case R_LAST:
- if (!F_ISSET(t, R_EOF | R_INMEM) &&
- t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR)
- return (RET_ERROR);
- nrec = t->bt_nrecs;
- break;
- default:
-einval: errno = EINVAL;
- return (RET_ERROR);
- }
-
- if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) {
- if (!F_ISSET(t, R_EOF | R_INMEM) &&
- (status = t->bt_irec(t, nrec)) != RET_SUCCESS)
- return (status);
- if (t->bt_nrecs == 0 || nrec > t->bt_nrecs)
- return (RET_SPECIAL);
- }
-
- if ((e = __rec_search(t, nrec - 1, SEARCH)) == NULL)
- return (RET_ERROR);
-
- F_SET(&t->bt_cursor, CURS_INIT);
- t->bt_cursor.rcursor = nrec;
-
- status = __rec_ret(t, e, nrec, key, data);
- if (F_ISSET(t, B_DB_LOCK))
- mpool_put(t->bt_mp, e->page, 0);
- else
- t->bt_pinned = e->page;
- return (status);
-}
diff --git a/1.2-netsec/db1-ast/recno/rec_utils.c b/1.2-netsec/db1-ast/recno/rec_utils.c
deleted file mode 100644
index c4c038046..000000000
--- a/1.2-netsec/db1-ast/recno/rec_utils.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rec_utils.c 8.6 (Berkeley) 7/16/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <db.h>
-#include "recno.h"
-
-/*
- * __rec_ret --
- * Build return data.
- *
- * Parameters:
- * t: tree
- * e: key/data pair to be returned
- * nrec: record number
- * key: user's key structure
- * data: user's data structure
- *
- * Returns:
- * RET_SUCCESS, RET_ERROR.
- */
-int
-__rec_ret(t, e, nrec, key, data)
- BTREE *t;
- EPG *e;
- recno_t nrec;
- DBT *key, *data;
-{
- RLEAF *rl;
- void *p;
-
- if (key == NULL)
- goto dataonly;
-
- /* We have to copy the key, it's not on the page. */
- if (sizeof(recno_t) > t->bt_rkey.size) {
- p = (void *)(t->bt_rkey.data == NULL ?
- malloc(sizeof(recno_t)) :
- realloc(t->bt_rkey.data, sizeof(recno_t)));
- if (p == NULL)
- return (RET_ERROR);
- t->bt_rkey.data = p;
- t->bt_rkey.size = sizeof(recno_t);
- }
- memmove(t->bt_rkey.data, &nrec, sizeof(recno_t));
- key->size = sizeof(recno_t);
- key->data = t->bt_rkey.data;
-
-dataonly:
- if (data == NULL)
- return (RET_SUCCESS);
-
- /*
- * We must copy big keys/data to make them contiguous. Otherwise,
- * leave the page pinned and don't copy unless the user specified
- * concurrent access.
- */
- rl = GETRLEAF(e->page, e->index);
- if (rl->flags & P_BIGDATA) {
- if (__ovfl_get(t, rl->bytes,
- &data->size, &t->bt_rdata.data, &t->bt_rdata.size))
- return (RET_ERROR);
- data->data = t->bt_rdata.data;
- } else if (F_ISSET(t, B_DB_LOCK)) {
- /* Use +1 in case the first record retrieved is 0 length. */
- if (rl->dsize + 1 > t->bt_rdata.size) {
- p = (void *)(t->bt_rdata.data == NULL ?
- malloc(rl->dsize + 1) :
- realloc(t->bt_rdata.data, rl->dsize + 1));
- if (p == NULL)
- return (RET_ERROR);
- t->bt_rdata.data = p;
- t->bt_rdata.size = rl->dsize + 1;
- }
- memmove(t->bt_rdata.data, rl->bytes, rl->dsize);
- data->size = rl->dsize;
- data->data = t->bt_rdata.data;
- } else {
- data->size = rl->dsize;
- data->data = rl->bytes;
- }
- return (RET_SUCCESS);
-}
diff --git a/1.2-netsec/db1-ast/recno/recno.h b/1.2-netsec/db1-ast/recno/recno.h
deleted file mode 100644
index bec772c2f..000000000
--- a/1.2-netsec/db1-ast/recno/recno.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)recno.h 8.1 (Berkeley) 6/4/93
- */
-
-enum SRCHOP { SDELETE, SINSERT, SEARCH}; /* Rec_search operation. */
-
-#include "../btree/btree.h"
-#include "extern.h"
diff --git a/1.2-netsec/devicestate.c b/1.2-netsec/devicestate.c
deleted file mode 100644
index b19709152..000000000
--- a/1.2-netsec/devicestate.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Device state management
- *
- */
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/logger.h"
-#include "asterisk/devicestate.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-
-static const char *devstatestring[] = {
- /* 0 AST_DEVICE_UNKNOWN */ "Unknown", /* Valid, but unknown state */
- /* 1 AST_DEVICE_NOT_INUSE */ "Not in use", /* Not used */
- /* 2 AST_DEVICE IN USE */ "In use", /* In use */
- /* 3 AST_DEVICE_BUSY */ "Busy", /* Busy */
- /* 4 AST_DEVICE_INVALID */ "Invalid", /* Invalid - not known to Asterisk */
- /* 5 AST_DEVICE_UNAVAILABLE */ "Unavailable", /* Unavailable (not registred) */
- /* 6 AST_DEVICE_RINGING */ "Ringing" /* Ring, ring, ring */
-};
-
-/* ast_devstate_cb: A device state watcher (callback) */
-struct devstate_cb {
- void *data;
- ast_devstate_cb_type callback;
- AST_LIST_ENTRY(devstate_cb) list;
-};
-
-static AST_LIST_HEAD_STATIC(devstate_cbs, devstate_cb);
-
-struct state_change {
- AST_LIST_ENTRY(state_change) list;
- char device[1];
-};
-
-static AST_LIST_HEAD_STATIC(state_changes, state_change);
-
-static pthread_t change_thread = AST_PTHREADT_NULL;
-static ast_cond_t change_pending;
-
-/*--- devstate2str: Find devicestate as text message for output */
-const char *devstate2str(int devstate)
-{
- return devstatestring[devstate];
-}
-
-/*--- ast_parse_device_state: Find out if device is active in a call or not */
-int ast_parse_device_state(const char *device)
-{
- struct ast_channel *chan;
- char match[AST_CHANNEL_NAME];
- int res;
-
- ast_copy_string(match, device, sizeof(match)-1);
- strcat(match, "-");
- chan = ast_get_channel_by_name_prefix_locked(match, strlen(match));
-
- if (!chan)
- return AST_DEVICE_UNKNOWN;
-
- if (chan->_state == AST_STATE_RINGING)
- res = AST_DEVICE_RINGING;
- else
- res = AST_DEVICE_INUSE;
-
- ast_mutex_unlock(&chan->lock);
-
- return res;
-}
-
-/*--- ast_device_state: Check device state through channel specific function or generic function */
-int ast_device_state(const char *device)
-{
- char *buf;
- char *tech;
- char *number;
- const struct ast_channel_tech *chan_tech;
- int res = 0;
-
- buf = ast_strdupa(device);
- tech = strsep(&buf, "/");
- number = buf;
- if (!number)
- return AST_DEVICE_INVALID;
-
- chan_tech = ast_get_channel_tech(tech);
- if (!chan_tech)
- return AST_DEVICE_INVALID;
-
- if (!chan_tech->devicestate) /* Does the channel driver support device state notification? */
- return ast_parse_device_state(device); /* No, try the generic function */
- else {
- res = chan_tech->devicestate(number); /* Ask the channel driver for device state */
- if (res == AST_DEVICE_UNKNOWN) {
- res = ast_parse_device_state(device);
- /* at this point we know the device exists, but the channel driver
- could not give us a state; if there is no channel state available,
- it must be 'not in use'
- */
- if (res == AST_DEVICE_UNKNOWN)
- res = AST_DEVICE_NOT_INUSE;
- return res;
- } else
- return res;
- }
-}
-
-/*--- ast_devstate_add: Add device state watcher */
-int ast_devstate_add(ast_devstate_cb_type callback, void *data)
-{
- struct devstate_cb *devcb;
-
- if (!callback)
- return -1;
-
- devcb = calloc(1, sizeof(*devcb));
- if (!devcb)
- return -1;
-
- devcb->data = data;
- devcb->callback = callback;
-
- AST_LIST_LOCK(&devstate_cbs);
- AST_LIST_INSERT_HEAD(&devstate_cbs, devcb, list);
- AST_LIST_UNLOCK(&devstate_cbs);
-
- return 0;
-}
-
-/*--- ast_devstate_del: Remove device state watcher */
-void ast_devstate_del(ast_devstate_cb_type callback, void *data)
-{
- struct devstate_cb *devcb;
-
- AST_LIST_LOCK(&devstate_cbs);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&devstate_cbs, devcb, list) {
- if ((devcb->callback == callback) && (devcb->data == data)) {
- AST_LIST_REMOVE_CURRENT(&devstate_cbs, list);
- free(devcb);
- break;
- }
- }
- AST_LIST_TRAVERSE_SAFE_END;
- AST_LIST_UNLOCK(&devstate_cbs);
-}
-
-/*--- do_state_change: Notify callback watchers of change, and notify PBX core for hint updates */
-static void do_state_change(const char *device)
-{
- int state;
- struct devstate_cb *devcb;
-
- state = ast_device_state(device);
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Changing state for %s - state %d (%s)\n", device, state, devstate2str(state));
-
- AST_LIST_LOCK(&devstate_cbs);
- AST_LIST_TRAVERSE(&devstate_cbs, devcb, list)
- devcb->callback(device, state, devcb->data);
- AST_LIST_UNLOCK(&devstate_cbs);
-
- ast_hint_state_changed(device);
-}
-
-static int __ast_device_state_changed_literal(char *buf)
-{
- char *device, *tmp;
- struct state_change *change = NULL;
-
- device = buf;
- tmp = strrchr(device, '-');
- if (tmp)
- *tmp = '\0';
- if (change_thread != AST_PTHREADT_NULL)
- change = calloc(1, sizeof(*change) + strlen(device));
-
- if (!change) {
- /* we could not allocate a change struct, or */
- /* there is no background thread, so process the change now */
- do_state_change(device);
- } else {
- /* queue the change */
- strcpy(change->device, device);
- AST_LIST_LOCK(&state_changes);
- AST_LIST_INSERT_TAIL(&state_changes, change, list);
- if (AST_LIST_FIRST(&state_changes) == change)
- /* the list was empty, signal the thread */
- ast_cond_signal(&change_pending);
- AST_LIST_UNLOCK(&state_changes);
- }
-
- return 1;
-}
-
-int ast_device_state_changed_literal(const char *dev)
-{
- char *buf;
- buf = ast_strdupa(dev);
- return __ast_device_state_changed_literal(buf);
-}
-
-/*--- ast_device_state_changed: Accept change notification, add it to change queue */
-int ast_device_state_changed(const char *fmt, ...)
-{
- char buf[AST_MAX_EXTENSION];
- va_list ap;
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- return __ast_device_state_changed_literal(buf);
-}
-
-/*--- do_devstate_changes: Go through the dev state change queue and update changes in the dev state thread */
-static void *do_devstate_changes(void *data)
-{
- struct state_change *cur;
-
- AST_LIST_LOCK(&state_changes);
- for(;;) {
- /* the list lock will _always_ be held at this point in the loop */
- cur = AST_LIST_REMOVE_HEAD(&state_changes, list);
- if (cur) {
- /* we got an entry, so unlock the list while we process it */
- AST_LIST_UNLOCK(&state_changes);
- do_state_change(cur->device);
- free(cur);
- AST_LIST_LOCK(&state_changes);
- } else {
- /* there was no entry, so atomically unlock the list and wait for
- the condition to be signalled (returns with the lock held) */
- ast_cond_wait(&change_pending, &state_changes.lock);
- }
- }
-
- return NULL;
-}
-
-/*--- ast_device_state_engine_init: Initialize the device state engine in separate thread */
-int ast_device_state_engine_init(void)
-{
- ast_cond_init(&change_pending, NULL);
- if (ast_pthread_create(&change_thread, NULL, do_devstate_changes, NULL) < 0) {
- ast_log(LOG_ERROR, "Unable to start device state change thread.\n");
- return -1;
- }
-
- return 0;
-}
diff --git a/1.2-netsec/dlfcn.c b/1.2-netsec/dlfcn.c
deleted file mode 100644
index cc6fe40f9..000000000
--- a/1.2-netsec/dlfcn.c
+++ /dev/null
@@ -1,1314 +0,0 @@
-/*
-Copyright (c) 2002 Jorge Acereda <jacereda@users.sourceforge.net> &
- Peter O'Gorman <ogorman@users.sourceforge.net>
-
-Portions may be copyright others, see the AUTHORS file included with this
-distribution.
-
-Maintained by Peter O'Gorman <ogorman@users.sourceforge.net>
-
-Bug Reports and other queries should go to <ogorman@users.sourceforge.net>
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdarg.h>
-#include <limits.h>
-#include <mach-o/dyld.h>
-#include <mach-o/nlist.h>
-#include <mach-o/getsect.h>
-/* Just playing to see if it would compile with the freebsd headers, it does,
- * but because of the different values for RTLD_LOCAL etc, it would break binary
- * compat... oh well
- */
-#ifndef __BSD_VISIBLE
-#define __BSD_VISIBLE 1
-#endif
-
-#include "asterisk/dlfcn-compat.h"
-
-#ifndef dl_restrict
-#define dl_restrict __restrict
-#endif
-/* This is not available on 10.1 */
-#ifndef LC_LOAD_WEAK_DYLIB
-#define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
-#endif
-
-/* With this stuff here, this thing may actually compile/run on 10.0 systems
- * Not that I have a 10.0 system to test it on anylonger
- */
-#ifndef LC_REQ_DYLD
-#define LC_REQ_DYLD 0x80000000
-#endif
-#ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
-#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
-#endif
-#ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR
-#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
-#endif
-#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
-#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
-#endif
-#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
-#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
-#endif
-/* These symbols will be looked for in dyld */
-static const struct mach_header *(*dyld_NSAddImage) (const char *, unsigned long) = 0;
-static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, const char *) = 0;
-static NSSymbol(*dyld_NSLookupSymbolInImage)
- (const struct mach_header *, const char *, unsigned long) = 0;
-
-/* Define this to make dlcompat reuse data block. This way in theory we save
- * a little bit of overhead. However we then couldn't correctly catch excess
- * calls to dlclose(). Hence we don't use this feature
- */
-#undef REUSE_STATUS
-
-/* Size of the internal error message buffer (used by dlerror()) */
-#define ERR_STR_LEN 251
-
-/* Maximum number of search paths supported by getSearchPath */
-#define MAX_SEARCH_PATHS 32
-
-
-#define MAGIC_DYLIB_OFI ((NSObjectFileImage) 'DYOF')
-#define MAGIC_DYLIB_MOD ((NSModule) 'DYMO')
-
-/* internal flags */
-#define DL_IN_LIST 0x01
-
-/* our mutex */
-static pthread_mutex_t dlcompat_mutex;
-/* Our thread specific storage
- */
-static pthread_key_t dlerror_key;
-
-struct dlthread
-{
- int lockcnt;
- unsigned char errset;
- char errstr[ERR_STR_LEN];
-};
-
-/* This is our central data structure. Whenever a module is loaded via
- * dlopen(), we create such a struct.
- */
-struct dlstatus
-{
- struct dlstatus *next; /* pointer to next element in the linked list */
- NSModule module;
- const struct mach_header *lib;
- int refs; /* reference count */
- int mode; /* mode in which this module was loaded */
- dev_t device;
- ino_t inode;
- int flags; /* Any internal flags we may need */
-};
-
-/* Head node of the dlstatus list */
-static struct dlstatus mainStatus = { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 };
-static struct dlstatus *stqueue = &mainStatus;
-
-
-/* Storage for the last error message (used by dlerror()) */
-/* static char err_str[ERR_STR_LEN]; */
-/* static int err_filled = 0; */
-
-/* Prototypes to internal functions */
-static void debug(const char *fmt, ...);
-static void error(const char *str, ...);
-static const char *safegetenv(const char *s);
-static const char *searchList(void);
-static const char *getSearchPath(int i);
-static const char *getFullPath(int i, const char *file);
-static const struct stat *findFile(const char *file, const char **fullPath);
-static int isValidStatus(struct dlstatus *status);
-static inline int isFlagSet(int mode, int flag);
-static struct dlstatus *lookupStatus(const struct stat *sbuf);
-static void insertStatus(struct dlstatus *dls, const struct stat *sbuf);
-static int promoteLocalToGlobal(struct dlstatus *dls);
-static void *reference(struct dlstatus *dls, int mode);
-static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError);
-static struct dlstatus *allocStatus(void);
-static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode);
-static NSSymbol *search_linked_libs(const struct mach_header *mh, const char *symbol);
-static const char *get_lib_name(const struct mach_header *mh);
-static const struct mach_header *get_mach_header_from_NSModule(NSModule * mod);
-static void dlcompat_init_func(void);
-static inline void dolock(void);
-static inline void dounlock(void);
-static void dlerrorfree(void *data);
-static void resetdlerror(void);
-static const struct mach_header *my_find_image(const char *name);
-static const struct mach_header *image_for_address(const void *address);
-static void dlcompat_cleanup(void);
-static inline const char *dyld_error_str(void);
-
-#if FINK_BUILD
-/* Two Global Functions */
-void *dlsym_prepend_underscore(void *handle, const char *symbol);
-void *dlsym_auto_underscore(void *handle, const char *symbol);
-
-/* And their _intern counterparts */
-static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol);
-static void *dlsym_auto_underscore_intern(void *handle, const char *symbol);
-#endif
-
-/* Functions */
-
-static void debug(const char *fmt, ...)
-{
-#if DEBUG > 1
- va_list arg;
- va_start(arg, fmt);
- fprintf(stderr, "DLDEBUG: ");
- vfprintf(stderr, fmt, arg);
- fprintf(stderr, "\n");
- fflush(stderr);
- va_end(arg);
-#endif
-}
-
-static void error(const char *str, ...)
-{
- va_list arg;
- struct dlthread *tss;
- char * err_str;
- va_start(arg, str);
- tss = pthread_getspecific(dlerror_key);
- err_str = tss->errstr;
- strncpy(err_str, "dlcompat: ", ERR_STR_LEN);
- vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
- va_end(arg);
- debug("ERROR: %s\n", err_str);
- tss->errset = 1;
-}
-
-static void warning(const char *str)
-{
-#if DEBUG > 0
- fprintf(stderr, "WARNING: dlcompat: %s\n", str);
-#endif
-}
-
-static const char *safegetenv(const char *s)
-{
- const char *ss = getenv(s);
- return ss ? ss : "";
-}
-
-/* because this is only used for debugging and error reporting functions, we
- * don't really care about how elegant it is... it could use the load
- * commands to find the install name of the library, but...
- */
-static const char *get_lib_name(const struct mach_header *mh)
-{
- unsigned long count = _dyld_image_count();
- unsigned long i;
- const char *val = NULL;
- if (mh)
- {
- for (i = 0; i < count; i++)
- {
- if (mh == _dyld_get_image_header(i))
- {
- val = _dyld_get_image_name(i);
- break;
- }
- }
- }
- return val;
-}
-
-/* Returns the mach_header for the module bu going through all the loaded images
- * and finding the one with the same name as the module. There really ought to be
- * an api for doing this, would be faster, but there isn't one right now
- */
-static const struct mach_header *get_mach_header_from_NSModule(NSModule * mod)
-{
- const char *mod_name = NSNameOfModule(mod);
- struct mach_header *mh = NULL;
- unsigned long count = _dyld_image_count();
- unsigned long i;
- debug("Module name: %s", mod_name);
- for (i = 0; i < count; i++)
- {
- if (!strcmp(mod_name, _dyld_get_image_name(i)))
- {
- mh = _dyld_get_image_header(i);
- break;
- }
- }
- return mh;
-}
-
-
-/* Compute and return a list of all directories that we should search when
- * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
- * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
- * /usr/lib and /lib. Since both of the environments variables can contain a
- * list of colon separated paths, we simply concat them and the two other paths
- * into one big string, which we then can easily parse.
- * Splitting this string into the actual path list is done by getSearchPath()
- */
-static const char *searchList()
-{
- size_t buf_size;
- static char *buf=NULL;
- const char *ldlp = safegetenv("LD_LIBRARY_PATH");
- const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
- const char *stdpath = getenv("DYLD_FALLBACK_LIBRARY_PATH");
- if (!stdpath)
- stdpath = "/usr/local/lib:/lib:/usr/lib";
- if (!buf)
- {
- buf_size = strlen(ldlp) + strlen(dyldlp) + strlen(stdpath) + 4;
- buf = malloc(buf_size);
- snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
- stdpath, '\0');
- }
- return buf;
-}
-
-/* Returns the ith search path from the list as computed by searchList() */
-static const char *getSearchPath(int i)
-{
- static const char *list = 0;
- static char **path = (char **)0;
- static int end = 0;
- static int numsize = MAX_SEARCH_PATHS;
- static char **tmp;
- /* So we can call free() in the "destructor" we use i=-1 to return the alloc'd array */
- if (i == -1)
- {
- return (const char*)path;
- }
- if (!path)
- {
- path = (char **)calloc(MAX_SEARCH_PATHS, sizeof(char **));
- }
- if (!list && !end)
- list = searchList();
- if (i >= (numsize))
- {
- debug("Increasing size for long PATH");
- tmp = (char **)calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
- if (tmp)
- {
- memcpy(tmp, path, sizeof(char **) * numsize);
- free(path);
- path = tmp;
- numsize += MAX_SEARCH_PATHS;
- }
- else
- {
- return 0;
- }
- }
-
- while (!path[i] && !end)
- {
- path[i] = strsep((char **)&list, ":");
-
- if (path[i][0] == 0)
- path[i] = 0;
- end = (list == 0);
- }
- return path[i];
-}
-
-static const char *getFullPath(int i, const char *file)
-{
- static char buf[PATH_MAX];
- const char *path = getSearchPath(i);
- if (path)
- {
- snprintf(buf, PATH_MAX, "%s/%s", path, file);
- }
- return path ? buf : 0;
-}
-
-/* Given a file name, try to determine the full path for that file. Starts
- * its search in the current directory, and then tries all paths in the
- * search list in the order they are specified there.
- */
-static const struct stat *findFile(const char *file, const char **fullPath)
-{
- int i = 0;
- static struct stat sbuf;
- char *fileName;
- debug("finding file %s", file);
- *fullPath = file;
- if (0 == stat(file, &sbuf))
- return &sbuf;
- if (strchr(file, '/'))
- return 0; /* If the path had a / we don't look in env var places */
- fileName = NULL;
- if (!fileName)
- fileName = (char *)file;
- while ((*fullPath = getFullPath(i++, fileName)))
- {
- if (0 == stat(*fullPath, &sbuf))
- return &sbuf;
- }
- ;
- return 0;
-}
-
-/* Determine whether a given dlstatus is valid or not */
-static int isValidStatus(struct dlstatus *status)
-{
- /* Walk the list to verify status is contained in it */
- struct dlstatus *dls = stqueue;
- while (dls && status != dls)
- dls = dls->next;
- if (dls == 0)
- error("invalid handle");
- else if ((dls->module == 0) || (dls->refs == 0))
- error("handle to closed library");
- else
- return TRUE;
- return FALSE;
-}
-
-static inline int isFlagSet(int mode, int flag)
-{
- return (mode & flag) == flag;
-}
-
-static struct dlstatus *lookupStatus(const struct stat *sbuf)
-{
- struct dlstatus *dls = stqueue;
- debug("looking for status");
- while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0
- || sbuf->st_dev != dls->device || sbuf->st_ino != dls->inode))
- dls = dls->next;
- return dls;
-}
-
-static void insertStatus(struct dlstatus *dls, const struct stat *sbuf)
-{
- debug("inserting status");
- dls->inode = sbuf->st_ino;
- dls->device = sbuf->st_dev;
- dls->refs = 0;
- dls->mode = 0;
- if ((dls->flags & DL_IN_LIST) == 0)
- {
- dls->next = stqueue;
- stqueue = dls;
- dls->flags |= DL_IN_LIST;
- }
-}
-
-static struct dlstatus *allocStatus()
-{
- struct dlstatus *dls;
-#ifdef REUSE_STATUS
- dls = stqueue;
- while (dls && dls->module)
- dls = dls->next;
- if (!dls)
-#endif
- dls = malloc(sizeof(*dls));
- dls->flags = 0;
- return dls;
-}
-
-static int promoteLocalToGlobal(struct dlstatus *dls)
-{
- static int (*p) (NSModule module) = 0;
- debug("promoting");
- if (!p)
- _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (unsigned long *)&p);
- return (dls->module == MAGIC_DYLIB_MOD) || (p && p(dls->module));
-}
-
-static void *reference(struct dlstatus *dls, int mode)
-{
- if (dls)
- {
- if (dls->module == MAGIC_DYLIB_MOD && !isFlagSet(mode, RTLD_GLOBAL))
- {
- warning("trying to open a .dylib with RTLD_LOCAL");
- error("unable to open a .dylib with RTLD_LOCAL");
- return NULL;
- }
- if (isFlagSet(mode, RTLD_GLOBAL) &&
- !isFlagSet(dls->mode, RTLD_GLOBAL) && !promoteLocalToGlobal(dls))
- {
- error("unable to promote local module to global");
- return NULL;
- }
- dls->mode |= mode;
- dls->refs++;
- }
- else
- debug("reference called with NULL argument");
-
- return dls;
-}
-
-static const struct mach_header *my_find_image(const char *name)
-{
- const struct mach_header *mh = 0;
- const char *id = NULL;
- int i = _dyld_image_count();
- int j;
- mh = (struct mach_header *)
- dyld_NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
- NSADDIMAGE_OPTION_RETURN_ON_ERROR);
- if (!mh)
- {
- for (j = 0; j < i; j++)
- {
- id = _dyld_get_image_name(j);
- if (!strcmp(id, name))
- {
- mh = _dyld_get_image_header(j);
- break;
- }
- }
- }
- return mh;
-}
-
-/*
- * dyld adds libraries by first adding the directly dependant libraries in link order, and
- * then adding the dependencies for those libraries, so we should do the same... but we don't
- * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
- * any of it's direct dependencies, then it probably isn't there.
- */
-NSSymbol *search_linked_libs(const struct mach_header * mh, const char *symbol)
-{
- int n;
- struct load_command *lc = 0;
- struct mach_header *wh;
- NSSymbol *nssym = 0;
- if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
- {
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
- {
- if ((wh = (struct mach_header *)
- my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
- (char *)lc))))
- {
- if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol))
- {
- nssym = dyld_NSLookupSymbolInImage(wh,
- symbol,
- NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
- NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
- break;
- }
- }
- }
- }
- if ((!nssym) && NSIsSymbolNameDefined(symbol))
- {
- /* I've never seen this debug message...*/
- debug("Symbol \"%s\" is defined but was not found", symbol);
- }
- }
- return nssym;
-}
-
-/* Up to the caller to free() returned string */
-static inline const char *dyld_error_str()
-{
- NSLinkEditErrors dylder;
- int dylderno;
- const char *dylderrstr;
- const char *dyldfile;
- const char* retStr = NULL;
- NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
- if (dylderrstr && strlen(dylderrstr))
- {
- retStr = malloc(strlen(dylderrstr) +1);
- strcpy((char*)retStr,dylderrstr);
- }
- return retStr;
-}
-
-static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError)
-{
- NSSymbol *nssym = 0;
- void *caller = __builtin_return_address(1); /* Be *very* careful about inlining */
- const struct mach_header *caller_mh = 0;
- const char* savedErrorStr = NULL;
- resetdlerror();
-#ifndef RTLD_SELF
-#define RTLD_SELF ((void *) -3)
-#endif
- if (NULL == dls)
- dls = RTLD_SELF;
- if ((RTLD_NEXT == dls) || (RTLD_SELF == dls))
- {
- if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
- {
- caller_mh = image_for_address(caller);
- if (RTLD_SELF == dls)
- {
- /* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE
- * But it appears to work anyway, and looking at the code in dyld_libfuncs.c
- * this is acceptable.
- */
- if (dyld_NSIsSymbolNameDefinedInImage(caller_mh, symbol))
- {
- nssym = dyld_NSLookupSymbolInImage(caller_mh,
- symbol,
- NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
- NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
- }
- }
- if (!nssym)
- {
- if (RTLD_SELF == dls)
- savedErrorStr = dyld_error_str();
- nssym = search_linked_libs(caller_mh, symbol);
- }
- }
- else
- {
- if (canSetError)
- error("RTLD_SELF and RTLD_NEXT are not supported");
- return NULL;
- }
- }
- if (!nssym)
- {
-
- if (RTLD_DEFAULT == dls)
- {
- dls = &mainStatus;
- }
- if (!isValidStatus(dls))
- return NULL;
-
- if (dls->module != MAGIC_DYLIB_MOD)
- {
- nssym = NSLookupSymbolInModule(dls->module, symbol);
- if (!nssym && NSIsSymbolNameDefined(symbol))
- {
- debug("Searching dependencies");
- savedErrorStr = dyld_error_str();
- nssym = search_linked_libs(get_mach_header_from_NSModule(dls->module), symbol);
- }
- }
- else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
- {
- if (dyld_NSIsSymbolNameDefinedInImage(dls->lib, symbol))
- {
- nssym = dyld_NSLookupSymbolInImage(dls->lib,
- symbol,
- NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
- NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
- }
- else if (NSIsSymbolNameDefined(symbol))
- {
- debug("Searching dependencies");
- savedErrorStr = dyld_error_str();
- nssym = search_linked_libs(dls->lib, symbol);
- }
- }
- else if (dls->module == MAGIC_DYLIB_MOD)
- {
- /* Global context, use NSLookupAndBindSymbol */
- if (NSIsSymbolNameDefined(symbol))
- {
- /* There doesn't seem to be a return on error option for this call???
- this is potentially broken, if binding fails, it will improperly
- exit the application. */
- nssym = NSLookupAndBindSymbol(symbol);
- }
- else
- {
- if (savedErrorStr)
- free((char*)savedErrorStr);
- savedErrorStr = malloc(256);
- snprintf((char*)savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);
- }
- }
- }
- /* Error reporting */
- if (!nssym)
- {
- if (!savedErrorStr || !strlen(savedErrorStr))
- {
- if (savedErrorStr)
- free((char*)savedErrorStr);
- savedErrorStr = malloc(256);
- snprintf((char*)savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
- }
- if (canSetError)
- {
- error(savedErrorStr);
- }
- else
- {
- debug(savedErrorStr);
- }
- if (savedErrorStr)
- free((char*)savedErrorStr);
- return NULL;
- }
- return NSAddressOfSymbol(nssym);
-}
-
-static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode)
-{
- NSObjectFileImage ofi = 0;
- NSObjectFileImageReturnCode ofirc;
- struct dlstatus *dls;
- NSLinkEditErrors ler;
- int lerno;
- const char *errstr;
- const char *file;
- void (*init) (void);
- ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
- switch (ofirc)
- {
- case NSObjectFileImageSuccess:
- break;
- case NSObjectFileImageInappropriateFile:
- if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
- {
- if (!isFlagSet(mode, RTLD_GLOBAL))
- {
- warning("trying to open a .dylib with RTLD_LOCAL");
- error("unable to open this file with RTLD_LOCAL");
- return NULL;
- }
- }
- else
- {
- error("opening this file is unsupported on this system");
- return NULL;
- }
- break;
- case NSObjectFileImageFailure:
- error("object file setup failure");
- return NULL;
- case NSObjectFileImageArch:
- error("no object for this architecture");
- return NULL;
- case NSObjectFileImageFormat:
- error("bad object file format");
- return NULL;
- case NSObjectFileImageAccess:
- error("can't read object file");
- return NULL;
- default:
- error("unknown error from NSCreateObjectFileImageFromFile()");
- return NULL;
- }
- dls = lookupStatus(sbuf);
- if (!dls)
- {
- dls = allocStatus();
- }
- if (!dls)
- {
- error("unable to allocate memory");
- return NULL;
- }
- dls->lib = 0;
- if (ofirc == NSObjectFileImageInappropriateFile)
- {
- if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
- {
- debug("Dynamic lib loaded at %ld", dls->lib);
- ofi = MAGIC_DYLIB_OFI;
- dls->module = MAGIC_DYLIB_MOD;
- ofirc = NSObjectFileImageSuccess;
- /* Although it is possible with a bit of work to modify this so it works and
- functions with RTLD_NOW, I don't deem it necessary at the moment */
- }
- if (!(dls->module))
- {
- NSLinkEditError(&ler, &lerno, &file, &errstr);
- if (!errstr || (!strlen(errstr)))
- error("Can't open this file type");
- else
- error(errstr);
- if ((dls->flags & DL_IN_LIST) == 0)
- {
- free(dls);
- }
- return NULL;
- }
- }
- else
- {
- dls->module = NSLinkModule(ofi, path,
- NSLINKMODULE_OPTION_RETURN_ON_ERROR |
- NSLINKMODULE_OPTION_PRIVATE |
- (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0));
- NSDestroyObjectFileImage(ofi);
- if (dls->module)
- {
- dls->lib = get_mach_header_from_NSModule(dls->module);
- }
- }
- if (!dls->module)
- {
- NSLinkEditError(&ler, &lerno, &file, &errstr);
- if ((dls->flags & DL_IN_LIST) == 0)
- {
- free(dls);
- }
- error(errstr);
- return NULL;
- }
-
- insertStatus(dls, sbuf);
- dls = reference(dls, mode);
- if ((init = dlsymIntern(dls, "__init", 0)))
- {
- debug("calling _init()");
- init();
- }
- return dls;
-}
-
-static void dlcompat_init_func(void)
-{
- static int inited = 0;
- if (!inited)
- {
- inited = 1;
- _dyld_func_lookup("__dyld_NSAddImage", (unsigned long *)&dyld_NSAddImage);
- _dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",
- (unsigned long *)&dyld_NSIsSymbolNameDefinedInImage);
- _dyld_func_lookup("__dyld_NSLookupSymbolInImage", (unsigned long *)&dyld_NSLookupSymbolInImage);
- if (pthread_mutex_init(&dlcompat_mutex, NULL))
- exit(1);
- if (pthread_key_create(&dlerror_key, &dlerrorfree))
- exit(1);
- /* And be neat and tidy and clean up after ourselves */
- atexit(dlcompat_cleanup);
- }
-}
-
-#if 0
-#pragma CALL_ON_LOAD dlcompat_init_func
-#endif
-
-static void dlcompat_cleanup(void)
-{
- struct dlstatus *dls;
- struct dlstatus *next;
- char *data;
- data = (char *)searchList();
- if ( data )
- free( data );
- data = (char *)getSearchPath(-1);
- if ( data )
- free( data );
- pthread_mutex_destroy(&dlcompat_mutex);
- pthread_key_delete(dlerror_key);
- next = stqueue;
- while (next && (next != &mainStatus))
- {
- dls = next;
- next = dls->next;
- free(dls);
- }
-}
-
-static void resetdlerror()
-{
- struct dlthread *tss;
- tss = pthread_getspecific(dlerror_key);
- tss->errset = 0;
-}
-
-static void dlerrorfree(void *data)
-{
- free(data);
-}
-
-/* We kind of want a recursive lock here, but meet a little trouble
- * because they are not available pre OS X 10.2, so we fake it
- * using thread specific storage to keep a lock count
- */
-static inline void dolock(void)
-{
- int err = 0;
- struct dlthread *tss;
- tss = pthread_getspecific(dlerror_key);
- if (!tss)
- {
- tss = malloc(sizeof(struct dlthread));
- tss->lockcnt = 0;
- tss->errset = 0;
- if (pthread_setspecific(dlerror_key, tss))
- {
- fprintf(stderr,"dlcompat: pthread_setspecific failed\n");
- exit(1);
- }
- }
- if (!tss->lockcnt)
- err = pthread_mutex_lock(&dlcompat_mutex);
- tss->lockcnt = tss->lockcnt +1;
- if (err)
- exit(err);
-}
-
-static inline void dounlock(void)
-{
- int err = 0;
- struct dlthread *tss;
- tss = pthread_getspecific(dlerror_key);
- tss->lockcnt = tss->lockcnt -1;
- if (!tss->lockcnt)
- err = pthread_mutex_unlock(&dlcompat_mutex);
- if (err)
- exit(err);
-}
-
-void *dlopen(const char *path, int mode)
-{
- const struct stat *sbuf;
- struct dlstatus *dls;
- const char *fullPath;
- dlcompat_init_func(); /* Just in case */
- dolock();
- resetdlerror();
- if (!path)
- {
- dls = &mainStatus;
- goto dlopenok;
- }
- if (!(sbuf = findFile(path, &fullPath)))
- {
- error("file \"%s\" not found", path);
- goto dlopenerror;
- }
- /* Now checks that it hasn't been closed already */
- if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
- {
- /* debug("status found"); */
- dls = reference(dls, mode);
- goto dlopenok;
- }
-#ifdef RTLD_NOLOAD
- if (isFlagSet(mode, RTLD_NOLOAD))
- {
- error("no existing handle and RTLD_NOLOAD specified");
- goto dlopenerror;
- }
-#endif
- if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
- {
- error("how can I load something both RTLD_LAZY and RTLD_NOW?");
- goto dlopenerror;
- }
- dls = loadModule(fullPath, sbuf, mode);
-
- dlopenok:
- dounlock();
- return (void *)dls;
- dlopenerror:
- dounlock();
- return NULL;
-}
-
-#if !FINK_BUILD
-void *dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
-{
- int sym_len = strlen(symbol);
- void *value = NULL;
- char *malloc_sym = NULL;
- dolock();
- malloc_sym = malloc(sym_len + 2);
- if (malloc_sym)
- {
- sprintf(malloc_sym, "_%s", symbol);
- value = dlsymIntern(handle, malloc_sym, 1);
- free(malloc_sym);
- }
- else
- {
- error("Unable to allocate memory");
- goto dlsymerror;
- }
- dounlock();
- return value;
- dlsymerror:
- dounlock();
- return NULL;
-}
-#endif
-
-#if FINK_BUILD
-
-void *dlsym_prepend_underscore(void *handle, const char *symbol)
-{
- void *answer;
- dolock();
- answer = dlsym_prepend_underscore_intern(handle, symbol);
- dounlock();
- return answer;
-}
-
-static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol)
-{
-/*
- * A quick and easy way for porting packages which call dlsym(handle,"sym")
- * If the porter adds -Ddlsym=dlsym_prepend_underscore to the CFLAGS then
- * this function will be called, and will add the required underscore.
- *
- * Note that I haven't figured out yet which should be "standard", prepend
- * the underscore always, or not at all. These global functions need to go away
- * for opendarwin.
- */
- int sym_len = strlen(symbol);
- void *value = NULL;
- char *malloc_sym = NULL;
- malloc_sym = malloc(sym_len + 2);
- if (malloc_sym)
- {
- sprintf(malloc_sym, "_%s", symbol);
- value = dlsymIntern(handle, malloc_sym, 1);
- free(malloc_sym);
- }
- else
- {
- error("Unable to allocate memory");
- }
- return value;
-}
-
-void *dlsym_auto_underscore(void *handle, const char *symbol)
-{
- void *answer;
- dolock();
- answer = dlsym_auto_underscore_intern(handle, symbol);
- dounlock();
- return answer;
-
-}
-static void *dlsym_auto_underscore_intern(void *handle, const char *symbol)
-{
- struct dlstatus *dls = handle;
- void *addr = 0;
- addr = dlsymIntern(dls, symbol, 0);
- if (!addr)
- addr = dlsym_prepend_underscore_intern(handle, symbol);
- return addr;
-}
-
-
-void *dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
-{
- struct dlstatus *dls = handle;
- void *addr = 0;
- dolock();
- addr = dlsymIntern(dls, symbol, 1);
- dounlock();
- return addr;
-}
-#endif
-
-int dlclose(void *handle)
-{
- struct dlstatus *dls = handle;
- dolock();
- resetdlerror();
- if (!isValidStatus(dls))
- {
- goto dlcloseerror;
- }
- if (dls->module == MAGIC_DYLIB_MOD)
- {
- const char *name;
- if (!dls->lib)
- {
- name = "global context";
- }
- else
- {
- name = get_lib_name(dls->lib);
- }
- warning("trying to close a .dylib!");
- error("Not closing \"%s\" - dynamic libraries cannot be closed", name);
- goto dlcloseerror;
- }
- if (!dls->module)
- {
- error("module already closed");
- goto dlcloseerror;
- }
-
- if (dls->refs == 1)
- {
- unsigned long options = 0;
- void (*fini) (void);
- if ((fini = dlsymIntern(dls, "__fini", 0)))
- {
- debug("calling _fini()");
- fini();
- }
-#ifdef __ppc__
- options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
-#endif
-#if 1
-/* Currently, if a module contains c++ static destructors and it is unloaded, we
- * get a segfault in atexit(), due to compiler and dynamic loader differences of
- * opinion, this works around that.
- * I really need a way to figure out from code if this is still necessary.
- */
- if ((const struct section *)NULL !=
- getsectbynamefromheader(get_mach_header_from_NSModule(dls->module),
- "__DATA", "__mod_term_func"))
- {
- options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
- }
-#endif
-#ifdef RTLD_NODELETE
- if (isFlagSet(dls->mode, RTLD_NODELETE))
- options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
-#endif
- if (!NSUnLinkModule(dls->module, options))
- {
- error("unable to unlink module");
- goto dlcloseerror;
- }
- dls->refs--;
- dls->module = 0;
- /* Note: the dlstatus struct dls is neither removed from the list
- * nor is the memory it occupies freed. This shouldn't pose a
- * problem in mostly all cases, though.
- */
- }
- dounlock();
- return 0;
- dlcloseerror:
- dounlock();
- return 1;
-}
-
-const char *dlerror(void)
-{
- struct dlthread *tss;
- char * err_str;
- tss = pthread_getspecific(dlerror_key);
- err_str = tss->errstr;
- tss = pthread_getspecific(dlerror_key);
- if (tss->errset == 0)
- return 0;
- tss->errset = 0;
- return (err_str );
-}
-
-/* Given an address, return the mach_header for the image containing it
- * or zero if the given address is not contained in any loaded images.
- */
-const struct mach_header *image_for_address(const void *address)
-{
- unsigned long i;
- unsigned long j;
- unsigned long count = _dyld_image_count();
- struct mach_header *mh = 0;
- struct load_command *lc = 0;
- unsigned long addr = NULL;
- for (i = 0; i < count; i++)
- {
- addr = (unsigned long)address - _dyld_get_image_vmaddr_slide(i);
- mh = _dyld_get_image_header(i);
- if (mh)
- {
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if (LC_SEGMENT == lc->cmd &&
- addr >= ((struct segment_command *)lc)->vmaddr &&
- addr <
- ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
- {
- goto image_found;
- }
- }
- }
- mh = 0;
- }
- image_found:
- return mh;
-}
-
-int dladdr(const void * dl_restrict p, Dl_info * dl_restrict info)
-{
-/*
- FIXME: USe the routine image_for_address.
-*/
- unsigned long i;
- unsigned long j;
- unsigned long count = _dyld_image_count();
- struct mach_header *mh = 0;
- struct load_command *lc = 0;
- unsigned long addr = NULL;
- unsigned long table_off = (unsigned long)0;
- int found = 0;
- if (!info)
- return 0;
- dolock();
- resetdlerror();
- info->dli_fname = 0;
- info->dli_fbase = 0;
- info->dli_sname = 0;
- info->dli_saddr = 0;
-/* Some of this was swiped from code posted by Douglas Davidson <ddavidso AT apple DOT com>
- * to darwin-development AT lists DOT apple DOT com and slightly modified
- */
- for (i = 0; i < count; i++)
- {
- addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
- mh = _dyld_get_image_header(i);
- if (mh)
- {
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if (LC_SEGMENT == lc->cmd &&
- addr >= ((struct segment_command *)lc)->vmaddr &&
- addr <
- ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
- {
- info->dli_fname = _dyld_get_image_name(i);
- info->dli_fbase = (void *)mh;
- found = 1;
- break;
- }
- }
- if (found)
- break;
- }
- }
- if (!found)
- {
- dounlock();
- return 0;
- }
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if (LC_SEGMENT == lc->cmd)
- {
- if (!strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
- break;
- }
- }
- table_off =
- ((unsigned long)((struct segment_command *)lc)->vmaddr) -
- ((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
- debug("table off %x", table_off);
-
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if (LC_SYMTAB == lc->cmd)
- {
-
- struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
- unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
- struct nlist *nearest = NULL;
- unsigned long diff = 0xffffffff;
- unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
- debug("symtable %x", symtable);
- for (i = 0; i < numsyms; i++)
- {
- /* Ignore the following kinds of Symbols */
- if ((!symtable->n_value) /* Undefined */
- || (symtable->n_type >= N_PEXT) /* Debug symbol */
- || (!(symtable->n_type & N_EXT)) /* Local Symbol */
- )
- {
- symtable++;
- continue;
- }
- if ((addr >= symtable->n_value) && (diff >= (symtable->n_value - addr)))
- {
- diff = (unsigned long)symtable->n_value - addr;
- nearest = symtable;
- }
- symtable++;
- }
- if (nearest)
- {
- info->dli_saddr = nearest->n_value + ((void *)p - addr);
- info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
- }
- }
- }
- dounlock();
- return 1;
-}
-
-
-/*
- * Implement the dlfunc() interface, which behaves exactly the same as
- * dlsym() except that it returns a function pointer instead of a data
- * pointer. This can be used by applications to avoid compiler warnings
- * about undefined behavior, and is intended as prior art for future
- * POSIX standardization. This function requires that all pointer types
- * have the same representation, which is true on all platforms FreeBSD
- * runs on, but is not guaranteed by the C standard.
- */
-#if 0
-dlfunc_t dlfunc(void * dl_restrict handle, const char * dl_restrict symbol)
-{
- union
- {
- void *d;
- dlfunc_t f;
- } rv;
- int sym_len = strlen(symbol);
- char *malloc_sym = NULL;
- dolock();
- malloc_sym = malloc(sym_len + 2);
- if (malloc_sym)
- {
- sprintf(malloc_sym, "_%s", symbol);
- rv.d = dlsymIntern(handle, malloc_sym, 1);
- free(malloc_sym);
- }
- else
- {
- error("Unable to allocate memory");
- goto dlfuncerror;
- }
- dounlock();
- return rv.f;
- dlfuncerror:
- dounlock();
- return NULL;
-}
-#endif
diff --git a/1.2-netsec/dns.c b/1.2-netsec/dns.c
deleted file mode 100644
index 8b26ff377..000000000
--- a/1.2-netsec/dns.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005 Thorsten Lockert
- *
- * Written by Thorsten Lockert <tholo@trollphone.org>
- *
- * Funding provided by Troll Phone Networks AS
- *
- * 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 DNS Support for Asterisk
- *
- * \author Thorsten Lockert <tholo@trollphone.org>
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/dns.h"
-#include "asterisk/endian.h"
-
-#define MAX_SIZE 4096
-
-typedef struct {
- unsigned id :16; /* query identification number */
-#if __BYTE_ORDER == __BIG_ENDIAN
- /* fields in third byte */
- unsigned qr: 1; /* response flag */
- unsigned opcode: 4; /* purpose of message */
- unsigned aa: 1; /* authoritive answer */
- unsigned tc: 1; /* truncated message */
- unsigned rd: 1; /* recursion desired */
- /* fields in fourth byte */
- unsigned ra: 1; /* recursion available */
- unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
- unsigned ad: 1; /* authentic data from named */
- unsigned cd: 1; /* checking disabled by resolver */
- unsigned rcode :4; /* response code */
-#endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __PDP_ENDIAN
- /* fields in third byte */
- unsigned rd :1; /* recursion desired */
- unsigned tc :1; /* truncated message */
- unsigned aa :1; /* authoritive answer */
- unsigned opcode :4; /* purpose of message */
- unsigned qr :1; /* response flag */
- /* fields in fourth byte */
- unsigned rcode :4; /* response code */
- unsigned cd: 1; /* checking disabled by resolver */
- unsigned ad: 1; /* authentic data from named */
- unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
- unsigned ra :1; /* recursion available */
-#endif
- /* remaining bytes */
- unsigned qdcount :16; /* number of question entries */
- unsigned ancount :16; /* number of answer entries */
- unsigned nscount :16; /* number of authority entries */
- unsigned arcount :16; /* number of resource entries */
-} dns_HEADER;
-
-struct dn_answer {
- unsigned short rtype;
- unsigned short class;
- unsigned int ttl;
- unsigned short size;
-} __attribute__ ((__packed__));
-
-static int skip_name(char *s, int len)
-{
- int x = 0;
-
- while (x < len) {
- if (*s == '\0') {
- s++;
- x++;
- break;
- }
- if ((*s & 0xc0) == 0xc0) {
- s += 2;
- x += 2;
- break;
- }
- x += *s + 1;
- s += *s + 1;
- }
- if (x >= len)
- return -1;
- return x;
-}
-
-/*--- dns_parse_answer: Parse DNS lookup result, call callback */
-static int dns_parse_answer(void *context,
- int class, int type, char *answer, int len,
- int (*callback)(void *context, char *answer, int len, char *fullanswer))
-{
- char *fullanswer = answer;
- struct dn_answer *ans;
- dns_HEADER *h;
- int res;
- int x;
-
- h = (dns_HEADER *)answer;
- answer += sizeof(dns_HEADER);
- len -= sizeof(dns_HEADER);
-
- for (x = 0; x < ntohs(h->qdcount); x++) {
- if ((res = skip_name(answer, len)) < 0) {
- ast_log(LOG_WARNING, "Couldn't skip over name\n");
- return -1;
- }
- answer += res + 4; /* Skip name and QCODE / QCLASS */
- len -= res + 4;
- if (len < 0) {
- ast_log(LOG_WARNING, "Strange query size\n");
- return -1;
- }
- }
-
- for (x = 0; x < ntohs(h->ancount); x++) {
- if ((res = skip_name(answer, len)) < 0) {
- ast_log(LOG_WARNING, "Failed skipping name\n");
- return -1;
- }
- answer += res;
- len -= res;
- ans = (struct dn_answer *)answer;
- answer += sizeof(struct dn_answer);
- len -= sizeof(struct dn_answer);
- if (len < 0) {
- ast_log(LOG_WARNING, "Strange result size\n");
- return -1;
- }
- if (len < 0) {
- ast_log(LOG_WARNING, "Length exceeds frame\n");
- return -1;
- }
-
- if (ntohs(ans->class) == class && ntohs(ans->rtype) == type) {
- if (callback) {
- if ((res = callback(context, answer, ntohs(ans->size), fullanswer)) < 0) {
- ast_log(LOG_WARNING, "Failed to parse result\n");
- return -1;
- }
- if (res > 0)
- return 1;
- }
- }
- answer += ntohs(ans->size);
- len -= ntohs(ans->size);
- }
- return 0;
-}
-
-#if defined(res_ninit)
-#define HAS_RES_NINIT
-#else
-AST_MUTEX_DEFINE_STATIC(res_lock);
-#if 0
-#warning "Warning, res_ninit is missing... Could have reentrancy issues"
-#endif
-#endif
-
-/*--- ast_search_dns: Lookup record in DNS */
-int ast_search_dns(void *context,
- const char *dname, int class, int type,
- int (*callback)(void *context, char *answer, int len, char *fullanswer))
-{
-#ifdef HAS_RES_NINIT
- struct __res_state dnsstate;
-#endif
- char answer[MAX_SIZE];
- int res, ret = -1;
-
-#ifdef HAS_RES_NINIT
-#ifdef MAKE_VALGRIND_HAPPY
- memset(&dnsstate, 0, sizeof(dnsstate));
-#endif
- res_ninit(&dnsstate);
- res = res_nsearch(&dnsstate, dname, class, type, (unsigned char *)answer, sizeof(answer));
-#else
- ast_mutex_lock(&res_lock);
- res_init();
- res = res_search(dname, class, type, answer, sizeof(answer));
-#endif
- if (res > 0) {
- if ((res = dns_parse_answer(context, class, type, answer, res, callback)) < 0) {
- ast_log(LOG_WARNING, "DNS Parse error for %s\n", dname);
- ret = -1;
- }
- else if (ret == 0) {
- ast_log(LOG_DEBUG, "No matches found in DNS for %s\n", dname);
- ret = 0;
- }
- else
- ret = 1;
- }
-#ifdef HAS_RES_NINIT
- res_nclose(&dnsstate);
-#else
-#ifndef __APPLE__
- res_close();
-#endif
- ast_mutex_unlock(&res_lock);
-#endif
- return ret;
-}
diff --git a/1.2-netsec/dnsmgr.c b/1.2-netsec/dnsmgr.c
deleted file mode 100644
index f1a9dbe59..000000000
--- a/1.2-netsec/dnsmgr.c
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005-2006, Kevin P. Fleming
- *
- * Kevin P. Fleming <kpfleming@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Background DNS update manager
- *
- */
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <regex.h>
-#include <signal.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/dnsmgr.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/utils.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/options.h"
-#include "asterisk/cli.h"
-
-static struct sched_context *sched;
-static int refresh_sched = -1;
-static pthread_t refresh_thread = AST_PTHREADT_NULL;
-
-struct ast_dnsmgr_entry {
- struct in_addr *result;
- AST_LIST_ENTRY(ast_dnsmgr_entry) list;
- char name[1];
-};
-
-static AST_LIST_HEAD(entry_list, ast_dnsmgr_entry) entry_list;
-
-AST_MUTEX_DEFINE_STATIC(refresh_lock);
-
-#define REFRESH_DEFAULT 300
-
-static int enabled = 0;
-static int refresh_interval;
-
-struct refresh_info {
- struct entry_list *entries;
- int verbose;
- unsigned int regex_present:1;
- regex_t filter;
-};
-
-static struct refresh_info master_refresh_info = {
- .entries = &entry_list,
- .verbose = 0,
-};
-
-struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct in_addr *result)
-{
- struct ast_dnsmgr_entry *entry;
-
- if (!result || ast_strlen_zero(name))
- return NULL;
-
- entry = calloc(1, sizeof(*entry) + strlen(name));
- if (!entry)
- return NULL;
-
- entry->result = result;
- strcpy(entry->name, name);
-
- AST_LIST_LOCK(&entry_list);
- AST_LIST_INSERT_HEAD(&entry_list, entry, list);
- AST_LIST_UNLOCK(&entry_list);
-
- return entry;
-}
-
-void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
-{
- if (!entry)
- return;
-
- AST_LIST_LOCK(&entry_list);
- AST_LIST_REMOVE(&entry_list, entry, list);
- AST_LIST_UNLOCK(&entry_list);
- free(entry);
-}
-
-int ast_dnsmgr_lookup(const char *name, struct in_addr *result, struct ast_dnsmgr_entry **dnsmgr)
-{
- if (ast_strlen_zero(name) || !result || !dnsmgr)
- return -1;
-
- if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name))
- return 0;
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "doing lookup for '%s'\n", name);
-
- /* if it's actually an IP address and not a name,
- there's no need for a managed lookup */
- if (inet_aton(name, result))
- return 0;
-
- /* if the manager is disabled, do a direct lookup and return the result,
- otherwise register a managed lookup for the name */
- if (!enabled) {
- struct ast_hostent ahp;
- struct hostent *hp;
-
- if ((hp = ast_gethostbyname(name, &ahp)))
- memcpy(result, hp->h_addr, sizeof(result));
- return 0;
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_2 "adding manager for '%s'\n", name);
- *dnsmgr = ast_dnsmgr_get(name, result);
- return !*dnsmgr;
- }
-}
-
-static void *do_refresh(void *data)
-{
- for (;;) {
- pthread_testcancel();
- usleep(ast_sched_wait(sched));
- pthread_testcancel();
- ast_sched_runq(sched);
- }
- return NULL;
-}
-
-static int refresh_list(void *data)
-{
- struct refresh_info *info = data;
- struct ast_dnsmgr_entry *entry;
- struct ast_hostent ahp;
- struct hostent *hp;
-
- /* if a refresh or reload is already in progress, exit now */
- if (ast_mutex_trylock(&refresh_lock)) {
- if (info->verbose)
- ast_log(LOG_WARNING, "DNS Manager refresh already in progress.\n");
- return -1;
- }
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_2 "Refreshing DNS lookups.\n");
- AST_LIST_LOCK(info->entries);
- AST_LIST_TRAVERSE(info->entries, entry, list) {
- if (info->regex_present && regexec(&info->filter, entry->name, 0, NULL, 0))
- continue;
-
- if (info->verbose && (option_verbose > 2))
- ast_verbose(VERBOSE_PREFIX_2 "refreshing '%s'\n", entry->name);
-
- if ((hp = ast_gethostbyname(entry->name, &ahp))) {
- /* check to see if it has changed, do callback if requested */
- memcpy(entry->result, hp->h_addr, sizeof(entry->result));
- }
- }
- AST_LIST_UNLOCK(info->entries);
-
- ast_mutex_unlock(&refresh_lock);
-
- /* automatically reschedule based on the interval */
- return refresh_interval * 1000;
-}
-
-void dnsmgr_start_refresh(void)
-{
- if (refresh_sched > -1) {
- ast_sched_del(sched, refresh_sched);
- refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1);
- }
-}
-
-static int do_reload(int loading);
-
-static int handle_cli_reload(int fd, int argc, char *argv[])
-{
- if (argc > 2)
- return RESULT_SHOWUSAGE;
-
- do_reload(0);
- return 0;
-}
-
-static int handle_cli_refresh(int fd, int argc, char *argv[])
-{
- struct refresh_info info = {
- .entries = &entry_list,
- .verbose = 1,
- };
-
- if (argc > 3)
- return RESULT_SHOWUSAGE;
-
- if (argc == 3) {
- if (regcomp(&info.filter, argv[2], REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
- else
- info.regex_present = 1;
- }
-
- refresh_list(&info);
-
- if (info.regex_present)
- regfree(&info.filter);
-
- return 0;
-}
-
-static int handle_cli_status(int fd, int argc, char *argv[])
-{
- int count = 0;
- struct ast_dnsmgr_entry *entry;
-
- if (argc > 2)
- return RESULT_SHOWUSAGE;
-
- ast_cli(fd, "DNS Manager: %s\n", enabled ? "enabled" : "disabled");
- ast_cli(fd, "Refresh Interval: %d seconds\n", refresh_interval);
- AST_LIST_LOCK(&entry_list);
- AST_LIST_TRAVERSE(&entry_list, entry, list)
- count++;
- AST_LIST_UNLOCK(&entry_list);
- ast_cli(fd, "Number of entries: %d\n", count);
-
- return 0;
-}
-
-static struct ast_cli_entry cli_reload = {
- .cmda = { "dnsmgr", "reload", NULL },
- .handler = handle_cli_reload,
- .summary = "Reloads the DNS manager configuration",
- .usage =
- "Usage: dnsmgr reload\n"
- " Reloads the DNS manager configuration.\n"
-};
-
-static struct ast_cli_entry cli_refresh = {
- .cmda = { "dnsmgr", "refresh", NULL },
- .handler = handle_cli_refresh,
- .summary = "Performs an immediate refresh",
- .usage =
- "Usage: dnsmgr refresh [pattern]\n"
- " Peforms an immediate refresh of the managed DNS entries.\n"
- " Optional regular expression pattern is used to filter the entries to refresh.\n",
-};
-
-static struct ast_cli_entry cli_status = {
- .cmda = { "dnsmgr", "status", NULL },
- .handler = handle_cli_status,
- .summary = "Display the DNS manager status",
- .usage =
- "Usage: dnsmgr status\n"
- " Displays the DNS manager status.\n"
-};
-
-int dnsmgr_init(void)
-{
- sched = sched_context_create();
- if (!sched) {
- ast_log(LOG_ERROR, "Unable to create schedule context.\n");
- return -1;
- }
- AST_LIST_HEAD_INIT(&entry_list);
- ast_cli_register(&cli_reload);
- ast_cli_register(&cli_status);
- return do_reload(1);
-}
-
-void dnsmgr_reload(void)
-{
- do_reload(0);
-}
-
-static int do_reload(int loading)
-{
- struct ast_config *config;
- const char *interval_value;
- const char *enabled_value;
- int interval;
- int was_enabled;
- int res = -1;
-
- /* ensure that no refresh cycles run while the reload is in progress */
- ast_mutex_lock(&refresh_lock);
-
- /* reset defaults in preparation for reading config file */
- refresh_interval = REFRESH_DEFAULT;
- was_enabled = enabled;
- enabled = 0;
-
- if (refresh_sched > -1)
- ast_sched_del(sched, refresh_sched);
-
- if ((config = ast_config_load("dnsmgr.conf"))) {
- if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
- enabled = ast_true(enabled_value);
- }
- if ((interval_value = ast_variable_retrieve(config, "general", "refreshinterval"))) {
- if (sscanf(interval_value, "%d", &interval) < 1)
- ast_log(LOG_WARNING, "Unable to convert '%s' to a numeric value.\n", interval_value);
- else if (interval < 0)
- ast_log(LOG_WARNING, "Invalid refresh interval '%d' specified, using default\n", interval);
- else
- refresh_interval = interval;
- }
- ast_config_destroy(config);
- }
-
- if (enabled && refresh_interval)
- ast_log(LOG_NOTICE, "Managed DNS entries will be refreshed every %d seconds.\n", refresh_interval);
-
- /* if this reload enabled the manager, create the background thread
- if it does not exist */
- if (enabled && !was_enabled && (refresh_thread == AST_PTHREADT_NULL)) {
- if (ast_pthread_create(&refresh_thread, NULL, do_refresh, NULL) < 0) {
- ast_log(LOG_ERROR, "Unable to start refresh thread.\n");
- }
- else {
- ast_cli_register(&cli_refresh);
- /* make a background refresh happen right away */
- refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1);
- res = 0;
- }
- }
- /* if this reload disabled the manager and there is a background thread,
- kill it */
- else if (!enabled && was_enabled && (refresh_thread != AST_PTHREADT_NULL)) {
- /* wake up the thread so it will exit */
- pthread_cancel(refresh_thread);
- pthread_kill(refresh_thread, SIGURG);
- pthread_join(refresh_thread, NULL);
- refresh_thread = AST_PTHREADT_NULL;
- ast_cli_unregister(&cli_refresh);
- res = 0;
- }
- else
- res = 0;
-
- ast_mutex_unlock(&refresh_lock);
-
- return res;
-}
diff --git a/1.2-netsec/doc/CODING-GUIDELINES b/1.2-netsec/doc/CODING-GUIDELINES
deleted file mode 100644
index c3c62bfdd..000000000
--- a/1.2-netsec/doc/CODING-GUIDELINES
+++ /dev/null
@@ -1,510 +0,0 @@
-== Asterisk Patch/Coding Guidelines ==
---------------------------------------
-
-We are looking forward to your contributions to Asterisk - the
-Open Source PBX! As Asterisk is a large and in some parts very
-time-sensitive application, the code base needs to conform to
-a common set of coding rules so that many developers can enhance
-and maintain the code. Code also needs to be reviewed and tested
-so that it works and follows the general architecture and guide-
-lines, and is well documented.
-
-Asterisk is published under a dual-licensing scheme by Digium.
-To be accepted into the codebase, all non-trivial changes must be
-disclaimed to Digium or placed in the public domain. For more information
-see http://bugs.digium.com
-
-Patches should be in the form of a unified (-u) diff, made from the directory
-above the top-level Asterisk source directory. For example:
-
-- the base code you are working from is in ~/work/asterisk-base
-- the changes are in ~/work/asterisk-new
-
-~/work$ diff -urN asterisk-base asterisk-new
-
-If you are changing within a fresh SVN working copy, you can create
-a patch with
-$ svn diff <mycodefile>.c
-
-* General rules
----------------
-
-- All code, filenames, function names and comments must be in ENGLISH.
-
-- Don't annotate your changes with comments like "/* JMG 4/20/04 */";
- Comments should explain what the code does, not when something was changed
- or who changed it. If you have done a larger contribution, make sure
- that you are added to the CREDITS file.
-
-- Don't make unnecessary whitespace changes throughout the code.
- If you make changes, submit them to the tracker as separate patches
- that only include whitespace and formatting changes.
-
-- Don't use C++ type (//) comments.
-
-- Try to match the existing formatting of the file you are working on.
-
-- Use spaces instead of tabs when aligning in-line comments or #defines (this makes
- your comments aligned even if the code is viewed with another tabsize)
-
-* Declaration of functions and variables
-----------------------------------------
-
-- Do not declare variables mid-block (e.g. like recent GNU compilers support)
- since it is harder to read and not portable to GCC 2.95 and others.
-
-- Functions and variables that are not intended to be used outside the module
- must be declared static.
-
-- When reading integer numeric input with scanf (or variants), do _NOT_ use '%i'
- unless you specifically want to allow non-base-10 input; '%d' is always a better
- choice, since it will not silently turn numbers with leading zeros into base-8.
-
-- Strings that are coming from input should not be used as a first argument to
- a formatted *printf function.
-
-* Use the internal API
-----------------------
-
-- Make sure you are aware of the string and data handling functions that exist
- within Asterisk to enhance portability and in some cases to produce more
- secure and thread-safe code. Check utils.c/utils.h for these.
-
-
-* Code formatting
------------------
-
-Roughly, Asterisk code formatting guidelines are generally equivalent to the
-following:
-
-# indent -i4 -ts4 -br -brs -cdw -cli0 -ce -nbfda -npcs -nprs -npsl -saf -sai -saw foo.c
-
-this means in verbose:
- -i4: indent level 4
- -ts4: tab size 4
- -br: braces on if line
- -brs: braces on struct decl line
- -cdw: cuddle do while
- -cli0: case indentation 0
- -ce: cuddle else
- -nbfda: dont break function decl args
- -npcs: no space after function call names
- -nprs: no space after parentheses
- -npsl: dont break procedure type
- -saf: space after for
- -sai: space after if
- -saw: space after while
-
-Function calls and arguments should be spaced in a consistent way across
-the codebase.
- GOOD: foo(arg1, arg2);
- GOOD: foo(arg1,arg2); /* Acceptable but not preferred */
- BAD: foo (arg1, arg2);
- BAD: foo( arg1, arg2 );
- BAD: foo(arg1, arg2,arg3);
-
-Don't treat keywords (if, while, do, return) as if they were functions;
-leave space between the keyword and the expression used (if any). For 'return',
-don't even put parentheses around the expression, since they are not
-required.
-
-There is no shortage of whitespace characters :-) Use them when they make
-the code easier to read. For example:
-
- for (str=foo;str;str=str->next)
-
-is harder to read than
-
- for (str = foo; str; str = str->next)
-
-Following are examples of how code should be formatted.
-
-- Functions:
-int foo(int a, char *s)
-{
- return 0;
-}
-
-- If statements:
-if (foo) {
- bar();
-} else {
- blah();
-}
-
-- Case statements:
-switch (foo) {
-case BAR:
- blah();
- break;
-case OTHER:
- other();
- break;
-}
-
-- No nested statements without braces, e.g.:
-
-for (x = 0; x < 5; x++)
- if (foo)
- if (bar)
- baz();
-
-instead do:
-for (x = 0; x < 5; x++) {
- if (foo) {
- if (bar)
- baz();
- }
-}
-
-- Don't build code like this:
-
-if (foo) {
- /* .... 50 lines of code ... */
-} else {
- result = 0;
- return;
-}
-
-Instead, try to minimize the number of lines of code that need to be
-indented, by only indenting the shortest case of the 'if'
-statement, like so:
-
-if !(foo) {
- result = 0;
- return;
-}
-
-.... 50 lines of code ....
-
-When this technique is used properly, it makes functions much easier to read
-and follow, especially those with more than one or two 'setup' operations
-that must succeed for the rest of the function to be able to execute.
-
-- Labels/goto are acceptable
-Proper use of this technique may occasionally result in the need for a
-label/goto combination so that error/failure conditions can exit the
-function while still performing proper cleanup. This is not a bad thing!
-Use of goto in this situation is encouraged, since it removes the need
-for excess code indenting without requiring duplication of cleanup code.
-
-- Never use an uninitialized variable
-Make sure you never use an uninitialized variable. The compiler will
-usually warn you if you do so. However, do not go too far the other way,
-and needlessly initialize variables that do not require it. If the first
-time you use a variable in a function is to store a value there, then
-initializing it at declaration is pointless, and will generate extra
-object code and data in the resulting binary with no purpose. When in doubt,
-trust the compiler to tell you when you need to initialize a variable;
-if it does not warn you, initialization is not needed.
-
-- Do not cast 'void *'
-Do not explicitly cast 'void *' into any other type, nor should you cast any
-other type into 'void *'. Implicit casts to/from 'void *' are explicitly
-allowed by the C specification. This means the results of malloc(), calloc(),
-alloca(), and similar functions do not _ever_ need to be cast to a specific
-type, and when you are passing a pointer to (for example) a callback function
-that accepts a 'void *' you do not need to cast into that type.
-
-* Variable naming
------------------
-
-- Global variables
-Name global variables (or local variables when you have a lot of them or
-are in a long function) something that will make sense to aliens who
-find your code in 100 years. All variable names should be in lower
-case, except when following external APIs or specifications that normally
-use upper- or mixed-case variable names; in that situation, it is
-preferable to follow the external API/specification for ease of
-understanding.
-
-Make some indication in the name of global variables which represent
-options that they are in fact intended to be global.
- e.g.: static char global_something[80]
-
-- Don't use un-necessary typedef's
-Don't use 'typedef' just to shorten the amount of typing; there is no substantial
-benefit in this:
-
-struct foo {
- int bar;
-};
-typedef foo_t struct foo;
-
-In fact, don't use 'variable type' suffixes at all; it's much preferable to
-just type 'struct foo' rather than 'foo_s'.
-
-- Use enums instead of #define where possible
-Use enums rather than long lists of #define-d numeric constants when possible;
-this allows structure members, local variables and function arguments to
-be declared as using the enum's type. For example:
-
-enum option {
- OPT_FOO = 1
- OPT_BAR = 2
- OPT_BAZ = 4
-};
-
-static enum option global_option;
-
-static handle_option(const enum option opt)
-{
- ...
-}
-
-Note: The compiler will _not_ force you to pass an entry from the enum
-as an argument to this function; this recommendation serves only to make
-the code clearer and somewhat self-documenting. In addition, when using
-switch/case blocks that switch on enum values, the compiler will warn
-you if you forget to handle one or more of the enum values, which can be
-handy.
-
-* String handling
------------------
-
-Don't use strncpy for copying whole strings; it does not guarantee that the
-output buffer will be null-terminated. Use ast_copy_string instead, which
-is also slightly more efficient (and allows passing the actual buffer
-size, which makes the code clearer).
-
-Don't use ast_copy_string (or any length-limited copy function) for copying
-fixed (known at compile time) strings into buffers, if the buffer is something
-that has been allocated in the function doing the copying. In that case, you
-know at the time you are writing the code whether the buffer is large enough
-for the fixed string or not, and if it's not, your code won't work anyway!
-Use strcpy() for this operation, or directly set the first two characters
-of the buffer if you are just trying to store a one-character string in the
-buffer. If you are trying to 'empty' the buffer, just store a single
-NULL character ('\0') in the first byte of the buffer; nothing else is
-needed, and any other method is wasteful.
-
-In addition, if the previous operations in the function have already
-determined that the buffer in use is adequately sized to hold the string
-you wish to put into it (even if you did not allocate the buffer yourself),
-use a direct strcpy(), as it can be inlined and optimized to simple
-processor operations, unlike ast_copy_string().
-
-* Use of functions
-------------------
-
-When making applications, always ast_strdupa(data) to a local pointer if
-you intend to parse the incoming data string.
-
- if (data)
- mydata = ast_strdupa(data);
-
-
-- Separating arguments to dialplan applications and functions
-Use ast_app_separate_args() to separate the arguments to your application
-once you have made a local copy of the string.
-
-- Parsing strings with strsep
-Use strsep() for parsing strings when possible; there is no worry about
-'re-entrancy' as with strtok(), and even though it modifies the original
-string (which the man page warns about), in many cases that is exactly
-what you want!
-
-- Create generic code!
-If you do the same or a similar operation more than one time, make it a
-function or macro.
-
-Make sure you are not duplicating any functionality already found in an
-API call somewhere. If you are duplicating functionality found in
-another static function, consider the value of creating a new API call
-which can be shared.
-
-* Handling of pointers and allocations
---------------------------------------
-
-- Dereference or localize pointers
-Always dereference or localize pointers to things that are not yours like
-channel members in a channel that is not associated with the current
-thread and for which you do not have a lock.
- channame = ast_strdupa(otherchan->name);
-
-- Use const on pointer arguments if possible
-Use const on pointer arguments which your function will not be modifying, as this
-allows the compiler to make certain optimizations. In general, use 'const'
-on any argument that you have no direct intention of modifying, as it can
-catch logic/typing errors in your code when you use the argument variable
-in a way that you did not intend.
-
-- Do not create your own linked list code - reuse!
-As a common example of this point, make an effort to use the lockable
-linked-list macros found in include/asterisk/linkedlists.h. They are
-efficient, easy to use and provide every operation that should be
-necessary for managing a singly-linked list (if something is missing,
-let us know!). Just because you see other open-coded list implementations
-in the source tree is no reason to continue making new copies of
-that code... There are also a number of common string manipulation
-and timeval manipulation functions in asterisk/strings.h and asterisk/time.h;
-use them when possible.
-
-- Avoid needless allocations!
-Avoid needless malloc(), strdup() calls. If you only need the value in
-the scope of your function try ast_strdupa() or declare structs on the
-stack and pass a pointer to them. However, be careful to _never_ call
-alloca(), ast_strdupa() or similar functions in the argument list
-of a function you are calling; this can cause very strange stack
-arrangements and produce unexpected behavior.
-
--Allocations for structures
-When allocating/zeroing memory for a structure, try to use code like this:
-
-struct foo *tmp;
-
-...
-
-tmp = malloc(sizeof(*tmp));
-if (tmp)
- memset(tmp, 0, sizeof(*tmp));
-
-This eliminates duplication of the 'struct foo' identifier, which makes the
-code easier to read and also ensures that if it is copy-and-pasted it won't
-require as much editing. In fact, you can even use:
-
-struct foo *tmp;
-
-...
-
-tmp = calloc(1, sizeof(*tmp));
-
-This will allocate and zero the memory in a single operation.
-
-* CLI Commands
---------------
-
-New CLI commands should be named using the module's name, followed by a verb
-and then any parameters that the command needs. For example:
-
-*CLI> iax2 show peer <peername>
-
-not
-
-*CLI> show iax2 peer <peername>
-
-* New dialplan applications/functions
--------------------------------------
-
-There are two methods of adding functionality to the Asterisk
-dialplan: applications and functions. Applications (found generally in
-the apps/ directory) should be collections of code that interact with
-a channel and/or user in some significant way. Functions (which can be
-provided by any type of module) are used when the provided
-functionality is simple... getting/retrieving a value, for
-example. Functions should also be used when the operation is in no way
-related to a channel (a computation or string operation, for example).
-
-Applications are registered and invoked using the
-ast_register_application function; see the apps/app_skel.c file for an
-example.
-
-Functions are registered using 'struct ast_custom_function'
-structures and the ast_custom_function_register function.
-
-* Doxygen API Documentation Guidelines
---------------------------------------
-
-When writing Asterisk API documentation the following format should be
-followed. Do not use the javadoc style.
-
-/*!
- * \brief Do interesting stuff.
- * \param thing1 interesting parameter 1.
- * \param thing2 interesting parameter 2.
- *
- * This function does some interesting stuff.
- *
- * \return zero on success, -1 on error.
- */
-int ast_interesting_stuff(int thing1, int thing2)
-{
- return 0;
-}
-
-Notice the use of the \param, \brief, and \return constructs. These should be
-used to describe the corresponding pieces of the function being documented.
-Also notice the blank line after the last \param directive. All doxygen
-comments must be in one /*! */ block. If the function or struct does not need
-an extended description it can be left out.
-
-Please make sure to review the doxygen manual and make liberal use of the \a,
-\code, \c, \b, \note, \li and \e modifiers as appropriate.
-
-When documenting a 'static' function or an internal structure in a module,
-use the \internal modifier to ensure that the resulting documentation
-explicitly says 'for internal use only'.
-
-Structures should be documented as follows.
-
-/*!
- * \brief A very interesting structure.
- */
-struct interesting_struct
-{
- /*! \brief A data member. */
- int member1;
-
- int member2; /*!< \brief Another data member. */
-}
-
-Note that /*! */ blocks document the construct immediately following them
-unless they are written, /*!< */, in which case they document the construct
-preceding them.
-
-* Finishing up before you submit your code
-------------------------------------------
-
-- Look at the code once more
-When you achieve your desired functionalty, make another few refactor
-passes over the code to optimize it.
-
-- Read the patch
-Before submitting a patch, *read* the actual patch file to be sure that
-all the changes you expect to be there are, and that there are no
-surprising changes you did not expect. During your development, that
-part of Asterisk may have changed, so make sure you compare with the
-latest SVN.
-
-- Listen to advice
-If you are asked to make changes to your patch, there is a good chance
-the changes will introduce bugs, check it even more at this stage.
-Also remember that the bug marshal or co-developer that adds comments
-is only human, they may be in error :-)
-
-- Optimize, optimize, optimize
-If you are going to reuse a computed value, save it in a variable
-instead of recomputing it over and over. This can prevent you from
-making a mistake in subsequent computations, making it easier to correct
-if the formula has an error and may or may not help optimization but
-will at least help readability.
-
-Just an example (so don't over analyze it, that'd be a shame):
-
-const char *prefix = "pre";
-const char *postfix = "post";
-char *newname;
-char *name = "data";
-
-if (name && (newname = alloca(strlen(name) + strlen(prefix) + strlen(postfix) + 3)))
- snprintf(newname, strlen(name) + strlen(prefix) + strlen(postfix) + 3, "%s/%s/%s", prefix, name, postfix);
-
-...vs this alternative:
-
-const char *prefix = "pre";
-const char *postfix = "post";
-char *newname;
-char *name = "data";
-int len = 0;
-
-if (name && (len = strlen(name) + strlen(prefix) + strlen(postfix) + 3) && (newname = alloca(len)))
- snprintf(newname, len, "%s/%s/%s", prefix, name, postfix);
-
-
------------------------------------------------
-Welcome to the Asterisk development community!
-Meet you on the asterisk-dev mailing list.
-Subscribe at http://lists.digium.com!
-
-Mark Spencer, Kevin P. Fleming and
-the Asterisk.org Development Team
diff --git a/1.2-netsec/doc/PEERING b/1.2-netsec/doc/PEERING
deleted file mode 100644
index c1f0b3831..000000000
--- a/1.2-netsec/doc/PEERING
+++ /dev/null
@@ -1,499 +0,0 @@
- DIGIUM GENERAL PEERING AGREEMENT (TM)
- Version 1.0.0, September 2004
- Copyright (C) 2004 Digium, Inc.
- 150 West Park Loop Suite 100, Huntsville, AL 35806 USA
-
- Everyone is permitted to copy and distribute complete verbatim copies
- of this General Peering Agreement provided it is not modified in any
- manner.
-
- ------------------------------------------------------
-
- DIGIUM GENERAL PEERING AGREEMENT
-
- PREAMBLE
-
- For most of the history of telecommunications, the power of being able
-to locate and communicate with another person in a system, be it across
-a hall or around the world, has always centered around a centralized
-authority -- from a local PBX administrator to regional and national
-RBOCs, generally requiring fees, taxes or regulation. By contrast,
-DUNDi is a technology developed to provide users the freedom to
-communicate with each other without the necessity of any centralized
-authority. This General Peering Agreement ("GPA") is used by individual
-parties (each, a "Participant") to allow them to build the E164 trust
-group for the DUNDi protocol.
-
- To protect the usefulness of the E164 trust group for those who use
-it, while keeping the system wholly decentralized, it is necessary to
-replace many of the responsibilities generally afforded to a company or
-government agency, with a set of responsibilities implemented by the
-parties who use the system, themselves. It is the goal of this document
-to provide all the protections necessary to keep the DUNDi E164 trust
-group useful and reliable.
-
- The Participants wish to protect competition, promote innovation and
-value added services and make this service valuable both commercially
-and non-commercially. To that end, this GPA provides special terms and
-conditions outlining some permissible and non-permissible revenue
-sources.
-
- This GPA is independent of any software license or other license
-agreement for a program or technology employing the DUNDi protocol. For
-example, the implementation of DUNDi used by Asterisk is covered under a
-separate license. Each Participant is responsible for compliance with
-any licenses or other agreements governing use of such program or
-technology that they use to peer.
-
- You do not have to execute this GPA to use a program or technology
-employing the DUNDi protocol, however if you do not execute this GPA,
-you will not be able to peer using DUNDi and the E164 context with
-anyone who is a member of the trust group by virtue of their having
-executed this GPA with another member.
-
-The parties to this GPA agree as follows:
-
- 0. DEFINITIONS. As used herein, certain terms shall be defined as
-follows:
-
- (a) The term "DUNDi" means the DUNDi protocol as published by
- Digium, Inc. or its successor in interest with respect to the
- DUNDi protocol specification.
-
- (b) The terms "E.164" and "E164" mean ITU-T specification E.164 as
- published by the International Telecommunications Union (ITU) in
- May, 1997.
-
- (c) The term "Service" refers to any communication facility (e.g.,
- telephone, fax, modem, etc.), identified by an E.164-compatible
- number, and assigned by the appropriate authority in that
- jurisdiction.
-
- (d) The term "Egress Gateway" refers an Internet facility that
- provides a communications path to a Service or Services that may
- not be directly addressable via the Internet.
-
- (e) The term "Route" refers to an Internet address, policies, and
- other characteristics defined by the DUNDi protocol and
- associated with the Service, or the Egress Gateway which
- provides access to the specified Service.
-
- (f) The term "Propagate" means to accept or transmit Service and/or
- Egress Gateway Routes only using the DUNDi protocol and the
- DUNDi context "e164" without regard to case, and does not apply
- to the exchange of information using any other protocol or
- context.
-
- (g) The term "Peering System" means the network of systems that
- Propagate Routes.
-
- (h) The term "Subscriber" means the owner of, or someone who
- contracts to receive, the services identified by an E.164
- number.
-
- (i) The term "Authorizing Individual" means the Subscriber to a
- number who has authorized a Participant to provide Routes
- regarding their services via this Peering System.
-
- (j) The term "Route Authority" refers to a Participant that provides
- an original source of said Route within the Peering System.
- Routes are propagated from the Route Authorities through the
- Peering System and may be cached at intermediate points. There
- may be multiple Route Authorities for any Service.
-
- (k) The term "Participant" (introduced above) refers to any member
- of the Peering System.
-
- (l) The term "Service Provider" refers to the carrier (e.g.,
- exchange carrier, Internet Telephony Service Provider, or other
- reseller) that provides communication facilities for a
- particular Service to a Subscriber, Customer or other End User.
-
- (m) The term "Weight" refers to a numeric quality assigned to a
- Route as per the DUNDi protocol specification. The current
- Weight definitions are shown in Exhibit A.
-
- 1. PEERING. The undersigned Participants agree to Propagate Routes
-with each other and any other member of the Peering System and further
-agree not to Propagate DUNDi Routes with a third party unless they have
-first have executed this GPA (in its unmodified form) with such third
-party. The Participants further agree only to Propagate Routes with
-Participants whom they reasonably believe to be honoring the terms of
-the GPA. Participants may not insert, remove, amend, or otherwise
-modify any of the terms of the GPA.
-
- 2. ACCEPTABLE USE POLICY. The DUNDi protocol contains information
-that reflect a Subscriber's or Egress Gateway's decisions to receive
-calls. In addition to the terms and conditions set forth in this GPA,
-the Participants agree to honor the intent of restrictions encoded in
-the DUNDi protocol. To that end, Participants agree to the following:
-
- (a) A Participant may not utilize or permit the utilization of
- Routes for which the Subscriber or Egress Gateway provider has
- indicated that they do not wish to receive "Unsolicited Calls"
- for the purpose of making an unsolicited phone call on behalf of
- any party or organization.
-
- (b) A Participant may not utilize or permit the utilization of
- Routes which have indicated that they do not wish to receive
- "Unsolicited Commercial Calls" for the purpose of making an
- unsolicited phone call on behalf of a commercial organization.
-
- (c) A Participant may never utilize or permit the utilization of any
- DUNDi route for the purpose of making harassing phone calls.
-
- (d) A Party may not utilize or permit the utilization of DUNDi
- provided Routes for any systematic or random calling of numbers
- (e.g., for the purpose of locating facsimile, modem services, or
- systematic telemarketing).
-
- (e) Initial control signaling for all communication sessions that
- utilize Routes obtained from the Peering System must be sent
- from a member of the Peering System to the Service or Egress
- Gateway identified in the selected Route. For example, 'SIP
- INVITES' and IAX2 "NEW" commands must be sent from the
- requesting DUNDi node to the terminating Service.
-
- (f) A Participant may not disclose any specific Route, Service or
- Participant contact information obtained from the Peering System
- to any party outside of the Peering System except as a
- by-product of facilitating communication in accordance with
- section 2e (e.g., phone books or other databases may not be
- published, but the Internet addresses of the Egress Gateway or
- Service does not need to be obfuscated.)
-
- (g) The DUNDi Protocol requires that each Participant include valid
- contact information about itself (including information about
- nodes connected to each Participant). Participants may use or
- disclose the contact information only to ensure enforcement of
- legal furtherance of this Agreement.
-
- 3. ROUTES. The Participants shall only propagate valid Routes, as
-defined herein, through the Peering System, regardless of the original
-source. The Participants may only provide Routes as set forth below,
-and then only if such Participant has no good faith reason to believe
-such Route to be invalid or unauthorized.
-
- (a) A Participant may provide Routes if each Route has as its
- original source another member of the Peering System who has
- duly executed the GPA and such Routes are provided in accordance
- with this Agreement; provided that the Routes are not modified
- (e.g., with regards to existence, destination, technology or
- Weight); or
-
- (b) A Participant may provide Routes for Services with any Weight
- for which it is the Subscriber; or
-
- (c) A Participant may provide Routes for those Services whose
- Subscriber has authorized the Participant to do so, provided
- that the Participant is able to confirm that the Authorizing
- Individual is the Subscriber through:
-
- i. a written statement of ownership from the Authorizing
- Individual, which the Participant believes in good faith
- to be accurate (e.g., a phone bill with the name of the
- Authorizing Individual and the number in question); or
-
- ii. the Participant's own direct personal knowledge that the
- Authorizing Individual is the Subscriber.
-
- (d) A Participant may provide Routes for Services, with Weight in
- accordance with the Current DUNDi Specification, if it can in
- good faith provide an Egress Gateway to that Service on the
- traditional telephone network without cost to the calling party.
-
- 4. REVOCATION. A Participant must provide a free, easily accessible
-mechanism by which a Subscriber may revoke permission to act as a Route
-Authority for his Service. A Participant must stop acting as a Route
-Authority for that Service within 7 days after:
-
- (a) receipt of a revocation request;
-
- (b) receiving other notice that the Service is no longer valid; or
-
- (c) determination that the Subscriber's information is no longer
- accurate (including that the Subscriber is no longer the service
- owner or the service owner's authorized delegate).
-
- 5. SERVICE FEES. A Participant may charge a fee to act as a Route
-Authority for a Service, with any Weight, provided that no Participant
-may charge a fee to propagate the Route received through the Peering
-System.
-
- 6. TOLL SERVICES. No Participant may provide Routes for any Services
-that require payment from the calling party or their customer for
-communication with the Service. Nothing in this section shall prohibit
-a Participant from providing routes for Services where the calling party
-may later enter into a financial transaction with the called party
-(e.g., a Participant may provide Routes for calling cards services).
-
- 7. QUALITY. A Participant may not intentionally impair communication
-using a Route provided to the Peering System (e.g. by adding delay,
-advertisements, reduced quality). If for any reason a Participant is
-unable to deliver a call via a Route provided to the Peering System,
-that Participant shall return out-of-band Network Congestion
-notification (e.g. "503 Service Unavailable" with SIP protocol or
-"CONGESTION" with IAX protocol).
-
- 8. PROTOCOL COMPLIANCE. Participants agree to Propagate Routes in
-strict compliance with current DUNDi protocol specifications.
-
- 9. ADMINISTRATIVE FEES. A Participant may charge (but is not required
-to charge) another Participant a reasonable fee to cover administrative
-expenses incurred in the execution of this Agreement. A Participant may
-not charge any fee to continue the relationship or to provide Routes to
-another Participant in the Peering System.
-
- 10. CALLER IDENTIFICATION. A Participant will make a good faith effort
-to ensure the accuracy and appropriate nature of any caller
-identification that it transmits via any Route obtained from the Peering
-System. Caller identification shall at least be provided as a valid
-E.164 number.
-
- 11. COMPLIANCE WITH LAWS. The Participants are solely responsible for
-determining to what extent, if any, the obligations set forth in this
-GPA conflict with any laws or regulations their region. A Participant
-may not provide any service or otherwise use DUNDi under this GPA if
-doing so is prohibited by law or regulation, or if any law or regulation
-imposes requirements on the Participant that are inconsistent with the
-terms of this GPA or the Acceptable Use Policy.
-
- 12. WARRANTY. EACH PARTICIPANT WARRANTS TO THE OTHER PARTICIPANTS THAT
-IT MADE, AND WILL CONTINUE TO MAKE, A GOOD FAITH EFFORT TO AUTHENTICATE
-OTHERS IN THE PEERING SYSTEM AND TO PROVIDE ACCURATE INFORMATION IN
-ACCORDANCE WITH THE TERMS OF THIS GPA. THIS WARRANTY IS MADE BETWEEN
-THE PARTICIPANTS, AND THE PARTICIPANTS MAY NOT EXTEND THIS WARRANTY TO
-ANY NON-PARTICIPANT INCLUDING END-USERS.
-
- 13. DISCLAIMER OF WARRANTIES. THE PARTICIPANTS UNDERSTAND AND AGREE
-THAT ANY SERVICE PROVIDED AS A RESULT OF THIS GPA IS "AS IS." EXCEPT FOR
-THOSE WARRANTIES OTHERWISE EXPRESSLY SET FORTH HEREIN, THE PARTICIPANTS
-DISCLAIM ANY REPRESENTATIONS OR WARRANTIES OF ANY KIND OR NATURE,
-EXPRESS OR IMPLIED, AS TO THE CONDITION, VALUE OR QUALITIES OF THE
-SERVICES PROVIDED HEREUNDER, AND SPECIFICALLY DISCLAIM ANY
-REPRESENTATION OR WARRANTY OF MERCHANTABILITY, SUITABILITY OR FITNESS
-FOR A PARTICULAR PURPOSE OR AS TO THE CONDITION OR WORKMANSHIP THEREOF,
-OR THE ABSENCE OF ANY DEFECTS THEREIN, WHETHER LATENT OR PATENT,
-INCLUDING ANY WARRANTIES ARISING FROM A COURSE OF DEALING, USAGE OR
-TRADE PRACTICE. EXCEPT AS EXPRESSLY PROVIDED HEREIN, THE PARTICIPANTS
-EXPRESSLY DISCLAIM ANY REPRESENTATIONS OR WARRANTIES THAT THE PEERING
-SERVICE WILL BE CONTINUOUS, UNINTERRUPTED OR ERROR-FREE, THAT ANY DATA
-SHARED OR OTHERWISE MADE AVAILABLE WILL BE ACCURATE OR COMPLETE OR
-OTHERWISE COMPLETELY SECURE FROM UNAUTHORIZED ACCESS.
-
- 14. LIMITATION OF LIABILITIES. NO PARTICIPANT SHALL BE LIABLE TO ANY
-OTHER PARTICIPANT FOR INCIDENTAL, INDIRECT, CONSEQUENTIAL, SPECIAL,
-PUNITIVE OR EXEMPLARY DAMAGES OF ANY KIND (INCLUDING LOST REVENUES OR
-PROFITS, LOSS OF BUSINESS OR LOSS OF DATA) IN ANY WAY RELATED TO THIS
-GPA, WHETHER IN CONTRACT OR IN TORT, REGARDLESS OF WHETHER SUCH
-PARTICIPANT WAS ADVISED OF THE POSSIBILITY THEREOF.
-
- 15. END-USER AGREEMENTS. The Participants may independently enter
-into agreements with end-users to provide certain services (e.g., fees
-to a Subscriber to originate Routes for that Service). To the extent
-that provision of these services employs the Peering System, the Parties
-will include in their agreements with their end-users terms and
-conditions consistent with the terms of this GPA with respect to the
-exclusion of warranties, limitation of liability and Acceptable Use
-Policy. In no event may a Participant extend the warranty described in
-Section 12 in this GPA to any end-users.
-
- 16. INDEMNIFICATION. Each Participant agrees to defend, indemnify and
-hold harmless the other Participant or third-party beneficiaries to this
-GPA (including their affiliates, successors, assigns, agents and
-representatives and their respective officers, directors and employees)
-from and against any and all actions, suits, proceedings,
-investigations, demands, claims, judgments, liabilities, obligations,
-liens, losses, damages, expenses (including, without limitation,
-attorneys' fees) and any other fees arising out of or relating to (i)
-personal injury or property damage caused by that Participant, its
-employees, agents, servants, or other representatives; (ii) any act or
-omission by the Participant, its employees, agents, servants or other
-representatives, including, but not limited to, unauthorized
-representations or warranties made by the Participant; or (iii) any
-breach by the Participant of any of the terms or conditions of this GPA.
-
- 17. THIRD PARTY BENEFICIARIES. This GPA is intended to benefit those
-Participants who have executed the GPA and who are in the Peering
-System. It is the intent of the Parties to this GPA to give to those
-Participants who are in the Peering System standing to bring any
-necessary legal action to enforce the terms of this GPA.
-
- 18. TERMINATION. Any Participant may terminate this GPA at any time,
-with or without cause. A Participant that terminates must immediately
-cease to Propagate.
-
- 19. CHOICE OF LAW. This GPA and the rights and duties of the Parties
-hereto shall be construed and determined in accordance with the internal
-laws of the State of New York, United States of America, without regard
-to its conflict of laws principles and without application of the United
-Nations Convention on Contracts for the International Sale of Goods.
-
- 20. DISPUTE RESOLUTION. Unless otherwise agreed in writing, the
-exclusive procedure for handling disputes shall be as set forth herein.
-Notwithstanding such procedures, any Participant may, at any time, seek
-injunctive relief in addition to the process described below.
-
- (a) Prior to mediation or arbitration the disputing Participants
- shall seek informal resolution of disputes. The process shall be
- initiated with written notice of one Participant to the other
- describing the dispute with reasonable particularity followed
- with a written response within ten (10) days of receipt of
- notice. Each Participant shall promptly designate an executive
- with requisite authority to resolve the dispute. The informal
- procedure shall commence within ten (10) days of the date of
- response. All reasonable requests for non-privileged information
- reasonably related to the dispute shall be honored. If the
- dispute is not resolved within thirty (30) days of commencement
- of the procedure either Participant may proceed to mediation or
- arbitration pursuant to the rules set forth in (b) or (c) below.
-
- (b) If the dispute has not been resolved pursuant to (a) above or,
- if the disputing Participants fail to commence informal dispute
- resolution pursuant to (a) above, either Participant may, in
- writing and within twenty (20) days of the response date noted
- in (a) above, ask the other Participant to participate in a one
- (1) day mediation with an impartial mediator, and the other
- Participant shall do so. Each Participant will bear its own
- expenses and an equal share of the fees of the mediator. If the
- mediation is not successful the Participants may proceed with
- arbitration pursuant to (c) below.
-
- (c) If the dispute has not been resolved pursuant to (a) or (b)
- above, the dispute shall be promptly referred, no later than one
- (1) year from the date of original notice and subject to
- applicable statute of limitations, to binding arbitration in
- accordance with the UNCITRAL Arbitration Rules in effect on the
- date of this contract. The appointing authority shall be the
- International Centre for Dispute Resolution. The case shall be
- administered by the International Centre for Dispute Resolution
- under its Procedures for Cases under the UNCITRAL Arbitration
- Rules. Each Participant shall bear its own expenses and shall
- share equally in fees of the arbitrator. All arbitrators shall
- have substantial experience in information technology and/or in
- the telecommunications business and shall be selected by the
- disputing participants in accordance with UNCITRAL Arbitration
- Rules. If any arbitrator, once selected is unable or unwilling
- to continue for any reason, replacement shall be filled via the
- process described above and a re-hearing shall be conducted. The
- disputing Participants will provide each other with all
- requested documents and records reasonably related to the
- dispute in a manner that will minimize the expense and
- inconvenience of both parties. Discovery will not include
- depositions or interrogatories except as the arbitrators
- expressly allow upon a showing of need. If disputes arise
- concerning discovery requests, the arbitrators shall have sole
- and complete discretion to resolve the disputes. The parties and
- arbitrator shall be guided in resolving discovery disputes by
- the Federal Rules of Civil Procedure. The Participants agree
- that time of the essence principles shall guide the hearing and
- that the arbitrator shall have the right and authority to issue
- monetary sanctions in the event of unreasonable delay. The
- arbitrator shall deliver a written opinion setting forth
- findings of fact and the rationale for the award within thirty
- (30) days following conclusion of the hearing. The award of the
- arbitrator, which may include legal and equitable relief, but
- which may not include punitive damages, will be final and
- binding upon the disputing Participants, and judgment may be
- entered upon it in accordance with applicable law in any court
- having jurisdiction thereof. In addition to award the
- arbitrator shall have the discretion to award the prevailing
- Participant all or part of its attorneys' fees and costs,
- including fees associated with arbitrator, if the arbitrator
- determines that the positions taken by the other Participant on
- material issues of the dispute were without substantial
- foundation. Any conflict between the UNCITRAL Arbitration Rules
- and the provisions of this GPA shall be controlled by this GPA.
-
- 21. INTEGRATED AGREEMENT. This GPA, constitutes the complete
-integrated agreement between the parties concerning the subject matter
-hereof. All prior and contemporaneous agreements, understandings,
-negotiations or representations, whether oral or in writing, relating to
-the subject matter of this GPA are superseded and canceled in their
-entirety.
-
- 22. WAIVER. No waiver of any of the provisions of this GPA shall be
-deemed or shall constitute a waiver of any other provision of this GPA,
-whether or not similar, nor shall such waiver constitute a continuing
-waiver unless otherwise expressly so provided in writing. The failure
-of either party to enforce at any time any of the provisions of this
-GPA, or the failure to require at any time performance by either party
-of any of the provisions of this GPA, shall in no way be construed to be
-a present or future waiver of such provisions, nor in any way affect the
-ability of a Participant to enforce each and every such provision
-thereafter.
-
- 23. INDEPENDENT CONTRACTORS. Nothing in this GPA shall make the
-Parties partners, joint venturers, or otherwise associated in or with
-the business of the other. Parties are, and shall always remain,
-independent contractors. No Participant shall be liable for any debts,
-accounts, obligations, or other liabilities of the other Participant,
-its agents or employees. No party is authorized to incur debts or other
-obligations of any kind on the part of or as agent for the other. This
-GPA is not a franchise agreement and does not create a franchise
-relationship between the parties, and if any provision of this GPA is
-deemed to create a franchise between the parties, then this GPA shall
-automatically terminate.
-
- 24. CAPTIONS AND HEADINGS. The captions and headings used in this GPA
-are used for convenience only and are not to be given any legal effect.
-
- 25. EXECUTION. This GPA may be executed in counterparts, each of which
-so executed will be deemed to be an original and such counterparts
-together will constitute one and the same Agreement. The Parties shall
-transmit to each other a signed copy of the GPA by any means that
-faithfully reproduces the GPA along with the Signature. For purposes of
-this GPA, the term "signature" shall include digital signatures as
-defined by the jurisdiction of the Participant signing the GPA.
-
- Exhibit A
-
-Weight Range Requirements
-
-0-99 May only be used under authorization of Owner
-
-100-199 May only be used by the Owner's service
- provider, regardless of authorization.
-
-200-299 Reserved -- do not use for e164 context.
-
-300-399 May only be used by the owner of the code under
- which the Owner's number is a part of.
-
-400-499 May be used by any entity providing access via
- direct connectivity to the Public Switched
- Telephone Network.
-
-500-599 May be used by any entity providing access via
- indirect connectivity to the Public Switched
- Telephone Network (e.g. Via another VoIP
- provider)
-
-600- Reserved-- do not use for e164 context.
-
- Participant Participant
-
-Company:
-
-Address:
-
-Email:
-
-
- _________________________ _________________________
- Authorized Signature Authorized Signature
-
-Name:
-
-
-END OF GENERAL PEERING AGREEMENT
-
-------------------------------------------------
-
-How to Peer using this GPA If you wish to exchange routing information
-with parties using the e164 DUNDi context, all you must do is execute
-this GPA with any member of the Peering System and you will become a
-member of the Peering System and be able to make Routes available in
-accordance with this GPA.
-
-DUNDi, IAX, Asterisk and GPA are trademarks of Digium, Inc.
diff --git a/1.2-netsec/doc/README.ael b/1.2-netsec/doc/README.ael
deleted file mode 100644
index e2014a4e1..000000000
--- a/1.2-netsec/doc/README.ael
+++ /dev/null
@@ -1,273 +0,0 @@
-The Asterisk Extension Language
-===================================
-
-Over time, people have been pushing to add features to extensions.conf to make
-it more like a programming language. AEL is intended to provide an actual
-programming language that can be used to write an Asterisk dialplan.
-
-Getting Started
--------------------------
-The AEL parser (pbx_ael.so) is completely separate from the module
-that parses extensions.conf (pbx_config.so). To use AEL, the only thing that
-has to be done is the module pbx_ael.so must be loaded by Asterisk. This will
-be done automatically if using 'autoload=yes' in /etc/asterisk/modules.conf.
-When the module is loaded, it will look for 'extensions.ael' in /etc/asterisk/.
-Both extensions.conf and extensions.ael can be used in conjunction with each
-other if that is what is desired. Some users may want to keep extensions.conf
-for the features that are configured in the 'general' section of
-extensions.conf.
-
-
-Reloading extensions.ael
--------------------------
-To reload extensions.ael, the following command can be issued at the CLI.
-
- *CLI> reload pbx_ael.so
-
-
-Contexts
--------------------------
-Contexts in AEL represent a set of extensions in the same way that they do
-in extensions.conf.
-
-context default {
-
-};
-
-
-Extensions
--------------------------
-To specify an extension in a context, the following syntax is used. If more
-than one application is be called in an extension, they can be listed in order
-inside of a block.
-
-context default {
- 1234 => Playback(tt-monkeys);
- 8000 => {
- NoOp(one);
- NoOp(two);
- NoOp(three);
- };
- _5XXX => NoOp(it's a pattern!);
-};
-
-
-Includes
--------------------------
-Contexts can be included in other contexts. All included contexts are listed
-within a single block.
-
-context default {
- includes {
- local;
- longdistance;
- international;
- };
-};
-
-
-Dialplan Switches
--------------------------
-Switches are listed in their own block within a context.
-
-context default {
- switches {
- DUNDi/e164;
- IAX2/box5;
- };
- eswitches {
- IAX2/context@${CURSERVER};
- };
-};
-
-
-Ignorepat
--------------------------
-ignorepat can be used to instruct channel drivers to not cancel dialtone upon
-receipt of a particular pattern. The most commonly used example is '9'.
-
-context outgoing {
- ignorepat => 9;
-};
-
-
-Variables
--------------------------
-Variables in Asterisk do not have a type, so to define a variable, it just has
-to be specified with a value.
-
-Global variables are set in their own block.
-
-globals {
- CONSOLE=Console/dsp;
- TRUNK=Zap/g2;
-};
-
-Variables can be set within extensions as well.
-
-context foo {
- 555 => {
- x=5;
- y=blah;
- NoOp(x is ${x} and y is ${y} !);
- };
-};
-
-Writing to a dialplan function is treated the same as writing to a variable.
-
-context blah {
- s => {
- CALLERID(name)=ChickenMan;
- NoOp(My name is ${CALLERID(name)} !);
- };
-};
-
-
-Loops
--------------------------
-AEL has implementations of 'for' and 'while' loops.
-
-context loops {
- 1 => {
- for (x=0; ${x} < 3; x=${x} + 1) {
- Verbose(x is ${x} !);
- };
- };
- 2 => {
- y=10;
- while (${y} >= 0) {
- Verbose(y is ${y} !);
- y=${y}-1;
- };
- };
-};
-
-
-Conditionals
--------------------------
-AEL supports if and switch statements. Note that if you have an else
-clause, you MUST place braces around the non-else portion of the if
-statement.
-
-context conditional {
- _8XXX => {
- Dial(SIP/${EXTEN});
- if (${DIALSTATUS} = "BUSY") {
- Voicemail(${EXTEN}|b);
- } else
- Voicemail(${EXTEN}|u);
- };
- _777X => {
- switch (${EXTEN}) {
- case 7771:
- NoOp(You called 7771!);
- break;
- case 7772:
- NoOp(You called 7772!);
- break;
- case 7773:
- NoOp(You called 7773!);
- // fall through
- default:
- NoOp(In the default clause!);
- };
- };
-};
-
-
-goto and labels
--------------------------
-This is an example of how to do a goto in AEL.
-
-context gotoexample {
- s => {
-begin:
- NoOp(Infinite Loop! yay!);
- Wait(1);
- goto begin;
- };
-};
-
-
-Macros
--------------------------
-A macro is defined in its own block like this. The arguments to the macro are
-specified with the name of the macro. They are then reffered to by that same
-name. A catch block can be specified to catch special extensions.
-
-macro std-exten( ext , dev ) {
- Dial(${dev}/${ext},20);
- switch(${DIALSTATUS) {
- case BUSY:
- Voicemail(b${ext});
- break;
- default:
- Voicemail(u${ext});
- };
- catch a {
- VoiceMailMain(${ext});
- return;
- };
-};
-
-A macro is then called by preceeding the macro name with an ampersand.
-
-context example {
- _5XXX => &std-exten(${EXTEN}, "IAX2");
-};
-
-
-Examples
-------------------------
-
-context demo {
- s => {
- Wait(1);
- Answer();
- TIMEOUT(digit)=5;
- TIMEOUT(response)=10;
-restart:
- Background(demo-congrats);
-instructions:
- for (x=0; ${x} < 3; x=${x} + 1) {
- Background(demo-instruct);
- WaitExten();
- };
- };
- 2 => {
- Background(demo-moreinfo);
- goto s|instructions;
- };
- 3 => {
- LANGUAGE()=fr;
- goto s|restart;
- };
- 500 => {
- Playback(demo-abouttotry);
- Dial(IAX2/guest@misery.digium.com);
- Playback(demo-nogo);
- goto s|instructions;
- };
- 600 => {
- Playback(demo-echotest);
- Echo();
- Playback(demo-echodone);
- goto s|instructions;
- };
- # => {
-hangup:
- Playback(demo-thanks);
- Hangup();
- };
- t => goto #|hangup;
- i => Playback(invalid);
-};
-
-
-Syntax Note
-------------------------
-Please note that all opening {'s are on the same line as the keyword. For
-the time being, that syntax is mandatory. We are looking at ways to allow
-other syntax in the future for flexibility, but for now, that is the way
-you must write AEL clauses.
-
diff --git a/1.2-netsec/doc/README.asterisk.conf b/1.2-netsec/doc/README.asterisk.conf
deleted file mode 100644
index 4e210aacd..000000000
--- a/1.2-netsec/doc/README.asterisk.conf
+++ /dev/null
@@ -1,76 +0,0 @@
-Asterisk Main Configuration File
------------------------------------------------------
-Below is a sample of the main Asterisk configuration file,
-asterisk.conf. Note that this file is _not_ provided in
-sample form, because the Makefile creates it when needed
-and does not touch it when it already exists.
-
----------------
-
-[directories]
-; Make sure these directoriess have the right permissions if not
-; running Asterisk as root
-
-; Where the configuration files (except for this one) are located
-astetcdir => /etc/asterisk
-
-; Where the Asterisk loadable modules are located
-astmoddir => /usr/lib/asterisk/modules
-
-; Where additional 'library' elements (scripts, etc.) are located
-astvarlibdir => /var/lib/asterisk
-
-; Where AGI scripts/programs are located
-astagidir => /var/lib/asterisk/agi-bin
-
-; Where spool directories are located
-; Voicemail, monitor, dictation and other apps will create files here
-; and outgoing call files (used with pbx_spool) must be placed here
-astspooldir => /var/spool/asterisk
-
-; Where the Asterisk process ID (pid) file should be created
-astrundir => /var/run/asterisk
-
-; Where the Asterisk log files should be created
-astlogdir => /var/log/asterisk
-
-
-[options]
-;Under "options" you can enter configuration options
-;that you also can set with command line options
-
-verbose = 0 ; Verbosity level for logging (-v)
-debug = 3 ; Debug: "No" or value (1-4)
-nofork=yes | no ; Background execution disabled (-f)
-console= yes | no ; Console mode (-c)
-highpriority = yes | no ; Execute with high priority (-p)
-initcrypto = yes | no ; Initialize crypto at startup (-i)
-nocolor = yes | no ; Disable ANSI colors (-n)
-dumpcore = yes | no ; Dump core on failure (-g)
-quiet = yes | no ; Run quietly (-q)
-timestamp = yes | no ; Force timestamping on log entries to console (-T)
-runuser = asterisk ; User to run asterisk as (-U) NOTE: will require changes to
- ; directory and device permisions
-rungroup = asterisk ; Group to run asterisk as (-G)
-
-;These options have no command line equivalent
-cache_record_files = yes | no ; Cache record() files in another directory until completion
-record_cache_dir = <dir>
-transcode_via_sln = yes | no ; Build transcode paths via SLINEAR
-transmit_silence_during_record = yes | no ; send SLINEAR silence while channel is being recorded
-maxload = 1.0 ; The maximum load average we accept calls for
-maxcalls = 255 ; The maximum number of concurrent calls you want to allow
-execincludes = yes | no ; Allow #exec entries in configuration files
-dontwarn = yes | no ; Don't over-inform the Asterisk sysadm, he's a guru
-
-[files]
-; Changing the following lines may compromise your security
-; Asterisk.ctl is the pipe that is used to connect the remote CLI
-; (asterisk -r) to Asterisk. Changing these settings change the
-; permissions and ownership of this file.
-; The file is created when Asterisk starts, in the "astrundir" above.
-
-;astctlpermissions = 0660
-;astctlowner = root
-;astctlgroup = asterisk
-;astctl = asterisk.ctl
diff --git a/1.2-netsec/doc/README.backtrace b/1.2-netsec/doc/README.backtrace
deleted file mode 100644
index 64d30a357..000000000
--- a/1.2-netsec/doc/README.backtrace
+++ /dev/null
@@ -1,187 +0,0 @@
-This document is to provide information on how to obtain the
-backtraces required on the asterisk bug tracker, available at
-http://bugs.digium.com. The information is required by developers to
-help fix problem with bugs of any kind. Backtraces provide information
-about what was wrong when a program crashed; in our case,
-Asterisk. There are two kind of backtraces (aka 'bt'), which are
-useful: bt and bt full.
-
-First of all, when you start Asterisk, you MUST start it with option
--g (this tells Asterisk to produce a core file if it crashes).
-
-If you start Asterisk with the safe_asterisk script, it automatically
-starts using the option -g.
-
-If you're not sure if Asterisk is running with the -g option, type the
-following command in your shell:
-
-debian:/tmp# ps aux | grep asterisk
-root 17832 0.0 1.2 2348 788 pts/1 S Aug12 0:00 /bin/sh /usr/sbin/safe_asterisk
-root 26686 0.0 2.8 15544 1744 pts/1 S Aug13 0:02 asterisk -vvvg -c
-[...]
-
-The interesting information is located in the last column.
-
-Second, your copy of Asterisk must have been built without
-optimization or the backtrace will be (nearly) unusable. This can be
-done by using 'make dont-optimize' intead of 'make install' to build
-and install the Asterisk binary and modules.
-
-After Asterisk crashes, a core file will be "dumped" in your /tmp/
-directory. To make sure it's really there, you can just type the
-following command in your shell:
-
-debian:/tmp# ls -l /tmp/core.*
--rw------- 1 root root 10592256 Aug 12 19:40 /tmp/core.26252
--rw------- 1 root root 9924608 Aug 12 20:12 /tmp/core.26340
--rw------- 1 root root 10862592 Aug 12 20:14 /tmp/core.26374
--rw------- 1 root root 9105408 Aug 12 20:19 /tmp/core.26426
--rw------- 1 root root 9441280 Aug 12 20:20 /tmp/core.26462
--rw------- 1 root root 8331264 Aug 13 00:32 /tmp/core.26647
-debian:/tmp#
-
-Now that we've verified the core file has been written to disk, the
-final part is to extract 'bt' from the core file. Core files are
-pretty big, don't be scared, it's normal.
-
-*** NOTE: Don't attach core files on the bug tracker, we only need the bt and bt full. ***
-
-For extraction, we use a really nice tool, called gdb. To verify that
-you have gdb installed on your system:
-
-debian:/tmp# gdb -v
-GNU gdb 6.3-debian
-Copyright 2004 Free Software Foundation, Inc.
-GDB is free software, covered by the GNU General Public License, and you are
-welcome to change it and/or distribute copies of it under certain conditions.
-Type "show copying" to see the conditions.
-There is absolutely no warranty for GDB. Type "show warranty" for details.
-This GDB was configured as "i386-linux".
-debian:/tmp#
-
-Which is great, we can continue. If you don't have gdb installed, go install gdb.
-
-Now load the core file in gdb, as follows:
-
-debian:/tmp# gdb -se "asterisk" -c /tmp/core.26252
-[...]
-(You would see a lot of output here.)
-[...]
-Reading symbols from /usr/lib/asterisk/modules/app_externalivr.so...done.
-Loaded symbols for /usr/lib/asterisk/modules/app_externalivr.so
-#0 0x29b45d7e in ?? ()
-(gdb)
-
-Now at the gdb prompt, type: bt
-You would see output similar to:
-(gdb) bt
-#0 0x29b45d7e in ?? ()
-#1 0x08180bf8 in ?? ()
-#2 0xbcdffa58 in ?? ()
-#3 0x08180bf8 in ?? ()
-#4 0xbcdffa60 in ?? ()
-#5 0x08180bf8 in ?? ()
-#6 0x180bf894 in ?? ()
-#7 0x0bf80008 in ?? ()
-#8 0x180b0818 in ?? ()
-#9 0x08068008 in ast_stopstream (tmp=0x40758d38) at file.c:180
-#10 0x000000a0 in ?? ()
-#11 0x000000a0 in ?? ()
-#12 0x00000000 in ?? ()
-#13 0x407513c3 in confcall_careful_stream (conf=0x8180bf8, filename=0x8181de8 "Zap/pseudo-1324221520") at app_meetme.c:262
-#14 0x40751332 in streamconfthread (args=0x8180bf8) at app_meetme.c:1965
-#15 0xbcdffbe0 in ?? ()
-#16 0x40028e51 in pthread_start_thread () from /lib/libpthread.so.0
-#17 0x401ec92a in clone () from /lib/libc.so.6
-(gdb)
-
-
-The bt's output is the information that we need on the bug tracker.
-
-Now do a bt full as follows:
-(gdb) bt full
-#0 0x29b45d7e in ?? ()
-No symbol table info available.
-#1 0x08180bf8 in ?? ()
-No symbol table info available.
-#2 0xbcdffa58 in ?? ()
-No symbol table info available.
-#3 0x08180bf8 in ?? ()
-No symbol table info available.
-#4 0xbcdffa60 in ?? ()
-No symbol table info available.
-#5 0x08180bf8 in ?? ()
-No symbol table info available.
-#6 0x180bf894 in ?? ()
-No symbol table info available.
-#7 0x0bf80008 in ?? ()
-No symbol table info available.
-#8 0x180b0818 in ?? ()
-No symbol table info available.
-#9 0x08068008 in ast_stopstream (tmp=0x40758d38) at file.c:180
-No locals.
-#10 0x000000a0 in ?? ()
-No symbol table info available.
-#11 0x000000a0 in ?? ()
-No symbol table info available.
-#12 0x00000000 in ?? ()
-No symbol table info available.
-#13 0x407513c3 in confcall_careful_stream (conf=0x8180bf8, filename=0x8181de8 "Zap/pseudo-1324221520") at app_meetme.c:262
- f = (struct ast_frame *) 0x8180bf8
- trans = (struct ast_trans_pvt *) 0x0
-#14 0x40751332 in streamconfthread (args=0x8180bf8) at app_meetme.c:1965
-No locals.
-#15 0xbcdffbe0 in ?? ()
-No symbol table info available.
-#16 0x40028e51 in pthread_start_thread () from /lib/libpthread.so.0
-No symbol table info available.
-#17 0x401ec92a in clone () from /lib/libc.so.6
-No symbol table info available.
-(gdb)
-
-We also need gdb's output. That output gives more details compared to
-the simple "bt". So we recommend that you use bt full instead of bt.
-But, if you could include both, we appreciate that.
-
-The final "extraction" would the to know all traces by all
-threads. Even if asterisk runs on the same thread for each calls, it
-could have some new threads created.
-
-To make sure we have the correct informations, just do:
-(gdb) thread apply all bt
-
-Thread 1 (process 26252):
-#0 0x29b45d7e in ?? ()
-#1 0x08180bf8 in ?? ()
-#2 0xbcdffa58 in ?? ()
-#3 0x08180bf8 in ?? ()
-#4 0xbcdffa60 in ?? ()
-#5 0x08180bf8 in ?? ()
-#6 0x180bf894 in ?? ()
-#7 0x0bf80008 in ?? ()
-#8 0x180b0818 in ?? ()
-#9 0x08068008 in ast_stopstream (tmp=0x40758d38) at file.c:180
-#10 0x000000a0 in ?? ()
-#11 0x000000a0 in ?? ()
-#12 0x00000000 in ?? ()
-#13 0x407513c3 in confcall_careful_stream (conf=0x8180bf8, filename=0x8181de8 "Zap/pseudo-1324221520") at app_meetme.c:262
-#14 0x40751332 in streamconfthread (args=0x8180bf8) at app_meetme.c:1965
-#15 0xbcdffbe0 in ?? ()
-#16 0x40028e51 in pthread_start_thread () from /lib/libpthread.so.0
-#17 0x401ec92a in clone () from /lib/libc.so.6
-(gdb)
-
-
-That output tell us crucial informations for threads.
-
-Now, just create a output.txt and dump your "bt full" (and/or "bt")
-AND with "thread apply all bt".
-
-Note: Please ATTACH your output, DO NOT paste it as a note.
-
-And you're ready for upload on bug tracker.
-
-
-Questions or comments regarding this documentation, feel free to pass
-by #asterisk-bugs on FreeNode.
-
diff --git a/1.2-netsec/doc/README.cdr b/1.2-netsec/doc/README.cdr
deleted file mode 100644
index cb9813845..000000000
--- a/1.2-netsec/doc/README.cdr
+++ /dev/null
@@ -1,122 +0,0 @@
-Asterisk billing support - Call Detail Records
-----------------------------------------------
-Asterisk generates Call Detail Records in a database or in a comma
-separated text file.
-
- * cdr_csv supports comma separated text file storage, this is the
- default driver
- * cdr_manager supports CDR information via the AMI, The Asterisk Manager
- interface
- * cdr_odbc supports UnixODBC databases, see http://www.unixodbc.org
- for an updated list of supported databases, from MySQL to MsSQL
- and text files.
- * cdr_tds supports FreeTDS databases (Among them MS SQL)
- NOTE: Please read README.tds for information on possible
- problems with the FreeTDS driver
- * cdr_sqlite supports SQlite
- * cdr_pgsql supports PostgreSQL
-
-In the asterisk-addons cvs archive, there's a cdr_mysql driver for
-MySQL.
-
-
-
-Applications
-------------
-
- * SetAccount Set account code for billing
- * SetAMAFlags Sets AMA flags
- * NoCDR Make sure no CDR is saved for a specific call
- * ResetCDR Reset CDR
- * ForkCDR Save current CDR and start a new CDR for this call
- * Authenticate Authenticates and sets the account code
- * SetCDRUserField Set CDR user field
- * AppendCDRUserField Append data to CDR User field
-
-For more information, use the "show application" command.
-You can set default account codes and AMA flags for devices in
-channel configuration files, like sip.conf, iax.conf etc.
-
-
-Fields of the CDR in Asterisk
------------------------------
-
- 1. accountcode: What account number to use, (string, 20 characters)
- 2. src: Caller*ID number (string, 80 characters)
- 3. dst: Destination extension (string, 80 characters)
- 4. dcontext: Destination context (string, 80 characters)
- 5. clid: Caller*ID with text (80 characters)
- 6. channel: Channel used (80 characters)
- 7. dstchannel: Destination channel if appropriate (80 characters)
- 8. lastapp: Last application if appropriate (80 characters)
- 9. lastdata: Last application data (arguments) (80 characters)
- 10. start: Start of call (date/time)
- 11. answer: Answer of call (date/time)
- 12. end: End of call (date/time)
- 13. duration: Total time in system, in seconds (integer), from dial to hangup
- 14. billsec: Total time call is up, in seconds (integer), from answer to hangup
- 15. disposition: What happened to the call: ANSWERED, NO ANSWER, BUSY
- 16. amaflags: What flags to use: DOCUMENTATION, BILL, IGNORE etc,
- specified on a per channel basis like accountcode.
- 17. user field: A user-defined field, maximum 255 characters
-
-In some cases, uniqueid is appended:
-
- * uniqueid: Unique Channel Identifier (32 characters)
- This needs to be enabled in the source code at compile time
-
-
-ONE IMPORTANT NOTE: If you are trying to collect records on IAX to IAX calls
-you need to be aware that by default, IAX will attempt to transfer calls
-in this situation (if DTMF is not required). When the transfer is completed
-the call is dumped from the middle machine and thus the call detail records
-will report a short call time. If you want detailed records you must
-turn off IAX transfer, but unless your servers are very close together, you
-will definitely get a latency hit from doing so.
-
-____________________________________
-CDR Variables
-------------------------------------
-
-If the channel has a cdr, that cdr record has its own set of variables which
-can be accessed just like channel variables. The following builtin variables
-are available.
-
-${CDR(clid)} Caller ID
-${CDR(src)} Source
-${CDR(dst)} Destination
-${CDR(dcontext)} Destination context
-${CDR(channel)} Channel name
-${CDR(dstchannel)} Destination channel
-${CDR(lastapp)} Last app executed
-${CDR(lastdata)} Last app's arguments
-${CDR(start)} Time the call started.
-${CDR(answer)} Time the call was answered.
-${CDR(end)} Time the call ended.
-${CDR(duration)} Duration of the call.
-${CDR(billsec)} Duration of the call once it was answered.
-${CDR(disposition)} ANSWERED, NO ANSWER, BUSY
-${CDR(amaflags)} DOCUMENTATION, BILL, IGNORE etc
-${CDR(accountcode)} The channel's account code.
-${CDR(uniqueid)} The channel's unique id.
-${CDR(userfield)} The channels uses specified field.
-
-In addition, you can set your own extra variables by using Set(CDR(name)=value).
-
-______________________________
-cdr_csv2
-------------------------------
-
-This module is an experimental new cdr module to demonstrate the cdr vars.
-usage(
-
-*) Create a file called cdr.conf and place it in your /etc/asterisk (or wherever your config files are) in the [cdr_csv2] section.
-*) Add an entry called format to indicate any format you want for the output.
-
-The following format string will emulate the regular cdr file format:
-[cdr_csv2]
-
-format => "${CDR(clid)}","${CDR(src)}","${CDR(dst)}","${CDR(dcontext)}","${CDR(channel)}","${CDR(dstchannel)}","${CDR(lastapp)}","${CDR(lastdata)}","${CDR(start)}","${CDR(answer)}","${CDR(end)}","${CDR(duration)}","${CDR(billsec)}","${CDR(disposition)}","${CDR(amaflags)}","${CDR(accountcode)}","${CDR(uniqueid)}","${CDR(userfield)}"
-
-You can put anything you want as the value of format incuding new cdr vars you make up or any global variables.
-
diff --git a/1.2-netsec/doc/README.cliprompt b/1.2-netsec/doc/README.cliprompt
deleted file mode 100644
index 281d3df5f..000000000
--- a/1.2-netsec/doc/README.cliprompt
+++ /dev/null
@@ -1,28 +0,0 @@
-* Changing the CLI Prompt
--------------------------
-
-The CLI prompt is set with the ASTERISK_PROMPT UNIX environment variable that
-you set from the Unix shell before starting Asterisk
-
-You may include the following variables, that will be replaced by
-the current value by Asterisk:
-
-%d Date (year-month-date)
-%h Full hostname
-%H Short hostname
-%t Time
-%% Percent sign
-%# '#' if Asterisk is run in console mode, '>' if running as remote console
-%Cn[;n] Change terminal foreground (and optional background) color to specified
- A full list of colors may be found in include/asterisk/term.h
-
-On Linux systems, you may also use
-%l1 Load average over past minute
-%l2 Load average over past 5 minutes
-%l3 Load average over past 15 minutes
-%l4 Process fraction (processes running / total processes)
-%l5 The most recently allocated pid
-
-
------
-04-03-26
diff --git a/1.2-netsec/doc/README.configuration b/1.2-netsec/doc/README.configuration
deleted file mode 100644
index 60a077a32..000000000
--- a/1.2-netsec/doc/README.configuration
+++ /dev/null
@@ -1,180 +0,0 @@
-Asterisk Configuration Parser (version 1.1 and later)
------------------------------------------------------
-
-The Asterisk configuration parser in the 1.1 development version (1.2
-stable) and beyond series has been improved in a number of ways. In
-addition to the realtime architecture, we now have the ability to create
-templates in configuration files, and use these as templates when we
-configure phones, voicemail accounts and queues.
-
-These changes are general to the configuration parser, and works in
-all configuration files.
-
-General syntax
---------------
-Asterisk configuration files are defined as follows:
-
- [section]
- label = value
- label2 = value
-
-In some files, (e.g. mgcp.conf, zapata.conf and agents.conf), the syntax
-is a bit different. In these files the syntax is as follows:
-
- [section]
- label1 = value1
- label2 = value2
- object => name
-
- label3 = value3
- label2 = value4
- object2 => name2
-
-In this syntax, we create objects with the settings defined above the object
-creation. Note that settings are inherited from the top, so in the example
-above object2 has inherited the setting for "label1" from the first object.
-
-For template configurations, the syntax for defining a section is changed
-to
- [section](options)
- label = value
-
-The options field is used to define templates, refer to templates and hide
-templates. Any object can be used as a template.
-
-No whitespace is allowed between the closing "]" and the parenthesis "(".
-
-Comments
---------
-All lines that starts with semi-colon ";" is treated as comments
-and is not parsed.
-
-The ";--" is a marker for a multi-line comment. Everything after
-that marker will be treated as a comment until the end-marker "--;"
-is found. Parsing begins directly after the end-marker.
-
- ;This is a comment
- label = value
- ;-- This is
- a comment --;
-
- ;-- Comment --; exten=> 1000,1,dial(SIP/lisa)
-
-Including other files
----------------------
-In all of the configuration files, you may include the content of another
-file with the #include statement. The content of the other file will be
-included at the row that the #include statement occured.
-
- #include myusers.conf
-
-You may also include the output of a program with the #exec directive,
-if you enable it in asterisk.conf
-
-In asterisk.conf, add the execincludes = yes statement in the options
-section:
- [options]
- execincludes=yes
-
-The exec directive is used like this:
-
- #exec /usr/local/bin/myasteriskconfigurator.sh
-
-Adding to an existing section
------------------------------
-
- [section]
- label = value
-
- [section](+)
- label2 = value2
-
-In this case, the plus sign indicates that the second section (with the
-same name) is an addition to the first section. The second section can
-be in another file (by using the #include statement). If the section
-name referred to before the plus is missing, the configuration will fail
-to load.
-
-Defining a template-only section
---------------------------------
- [section](!)
- label = value
-
-The exclamation mark indicates to the config parser that this is a only
-a template and should not itself be used by the Asterisk module for
-configuration. The section can be inherited by other sections (see
-section "Using templates" below) but is not used by itself.
-
-Using templates (or other configuration sections)
--------------------------------------------------
- [section](name[,name])
- label = value
-
-The name within the parenthesis refers to other sections, either
-templates or standard sections. The referred sections are included
-before the configuration engine parses the local settings within the
-section as though their entire contents (and anything they were
-previously based upon) were included in the new section. For example
-consider the following:
-
-[foo]
-permit=192.168.0.2
-host=asdf
-deny=192.168.0.1
-
-[bar]
-permit=192.168.1.2
-host=jkl
-deny=192.168.1.1
-
-[baz](foo,bar)
-permit=192.168.3.1
-host=bnm
-
-The [baz] section will be processed as though it had been written in the
-following way:
-
-[baz]
-permit=192.168.0.2
-host=asdf
-deny=192.168.0.1
-permit=192.168.1.2
-host=jkl
-deny=192.168.1.1
-permit=192.168.3.1
-host=bnm
-
-Additional Examples:
---------------------
-
-(in top-level sip.conf)
-
-[defaults](!)
-type=friend
-nat=yes
-qualify=on
-dtmfmode=rfc2833
-disallow=all
-allow=alaw
-
-#include accounts/*/sip.conf
-
-(in accounts/customer1/sip.conf)
-
-[def-customer1](!,defaults)
-secret=this_is_not_secret
-context=from-customer1
-callerid=Customer 1 <300>
-accountcode=0001
-
-[phone1](def-customer1)
-mailbox=phone1@customer1
-
-[phone2](def-customer1)
-mailbox=phone2@customer1
-
-This example defines two phones - phone1 and phone2 with settings
-inherited from "def-customer1". The "def-customer1" is a template that
-inherits from "defaults", which also is a template.
-
-
diff --git a/1.2-netsec/doc/README.cygwin b/1.2-netsec/doc/README.cygwin
deleted file mode 100644
index fa1f7845d..000000000
--- a/1.2-netsec/doc/README.cygwin
+++ /dev/null
@@ -1,7 +0,0 @@
-Cygwin support is completely experimental and usupported at this time. The current state of cygwin support is that it will compile, and start the cli, but will not yet take calls properly.
-
-To compile with cygwin, you will need at least a standard base cygwin install plus the following packages:
-
-minires
-minires-devel
-
diff --git a/1.2-netsec/doc/README.dundi b/1.2-netsec/doc/README.dundi
deleted file mode 100644
index 89c8d24a1..000000000
--- a/1.2-netsec/doc/README.dundi
+++ /dev/null
@@ -1,26 +0,0 @@
-Distributed Universal Number Directory (DUNDi) (tm)
-===================================================
-http://www.dundi.com
-Mark Spencer, Digium, Inc.
-
-DUNDi is essentially a trusted, peer-to-peer system for being able to
-call any phone number from the Internet. DUNDi works by creating a
-network of nodes called the "DUNDi E.164 Trust Group" which are bound by
-a common peering agreement known as the General Peering Agreement or
-GPA. The GPA legally binds the members of the Trust Group to provide
-good-faith accurate information to the other nodes on the network, and
-provides standards by which the community can insure the integrity of
-the information on the nodes themselves. Unlike ENUM or similar
-systems, DUNDi is explicitly designed to preclude any necessity for a
-single centralized system which could be a source of fees, regulation,
-etc.
-
-You can find the PEERING agreement in the doc directory.
-
-Much less dramatically, DUNDi can also be used within a private
-enterprise to share a dialplan efficiently between multiple nodes,
-without incuring a risk of a single point of failure. In this way,
-administrators can locally add extensions which become immediately
-available to the other nodes in the system.
-
-For more information visit http://www.dundi.com
diff --git a/1.2-netsec/doc/README.enum b/1.2-netsec/doc/README.enum
deleted file mode 100644
index ba8484749..000000000
--- a/1.2-netsec/doc/README.enum
+++ /dev/null
@@ -1,306 +0,0 @@
-README.enum
-
-2005-09-06
-jtodd@loligo.com
-
-The ENUMLOOKUP function is more complex than it first may appear, and
-this guide is to give a general overview and set of examples that may
-be well-suited for the advanced user to evaluate in their
-consideration of ENUM or ENUM-like lookup strategies. This document
-assumes a familiarity with ENUM (RFC3761) or ENUM-like methods, as
-well as familiarity with NAPTR DNS records (RFC2915, RFC3401-3404).
-For an overview of NAPTR records, and the use of NAPTRs in the ENUM
-global phone-number-to-DNS mapping scheme, please see
-http://www.voip-info.org/tiki-index.php?page=ENUM for more detail.
-
-Using ENUM within Asterisk can be simple or complex, depending on how
-many failover methods and redundancy procedures you wish to utilize.
-Implementation of ENUM paths is supposedly defined by the person
-creating the NAPTR records, but the local administrator may choose to
-ignore certain NAPTR response methods (URI types) or prefer some over
-others, which is in contradiction to the RFC. The ENUMLOOKUP method
-simply provides administrators a method for determining NAPTR results
-in either the globally unique ENUM (e164.arpa) DNS tree, or in other
-ENUM-like DNS trees which are not globally unique. The methods to
-actually create channels ("dial") results given by the ENUMLOOKUP
-function is then up to the administrator to implement in a way that
-best suits their environment.
-
-Function: ENUMLOOKUP(<number>[,pointer_type[,options[,zone_suffix]]])
-
- Performs an ENUM tree lookup on the specified number, method type,
- and (optionally) ordinal offset, and returns one of four different values:
-
- 1) post-parsed NAPTR of one method (URI) type
- 2) count of elements of one method (URI) type
- 3) count of all method types
- 4) full URI of method at a particular point in the list of all possible methods
-
-Arguments:
-
-number = telephone number or search string. Only numeric values
-within this string are parsed; all other digits are ignored for
-search, but are re-written during NAPTR regexp expansion.
-
-service_type = tel, sip, h323, iax2, mailto, ...[any other string],
- ALL. Default type is "sip".
- Special name of "ALL" will create a list of method types across
- all NAPTR records for the search number, and then put the results
- in an ordinal list starting with 1. The position <number>
- specified will then be returned, starting with 1 as the first
- record (lowest value) in the list. The service types are not
- hardcoded in Asterisk except for the default (sip) if no other
- service type specified; any method type string (IANA-approved or
- not) may be used except for the string "ALL".
-
-options = optional specifiers.
- c = count. Returns the number of records of this type are returned
- (regardless of order or priority.) If "ALL" is the specified
- service_type, then a count of all methods will be returned for the
- DNS record.
- <integer> = The record in priority/order sequence based on the
- total count of records passed back by the query. If a service_type
- is specified, all entries of that type will be sorted into an
- ordinal list starting with 1 (by order first, then priority).
- The default of <options> is "1"
-
-zone_suffix = allows customization of the ENUM zone. Default is e164.arpa.
-
-
-EXAMPLE USES:
-
-Let's use this ENUM list as an example (note that these examples exist
-in the DNS, and will hopefully remain in place as example
-destinations, but they may change or become invalid over time. The
-end result URIs are not guaranteed to actually work, since some of
-these hostnames or SIP proxies are imaginary. Of course, the tel:
-replies go to directory assistance for New York City and San
-Francisco...) Also note that the complex SIP NAPTR at weight 30 will
-strip off the leading "+" from the dialed string if it exists. This
-is probably a better NAPTR than hard-coding the number into the NAPTR,
-and it is included as a more complex regexp example, though other
-simpler NAPTRs will work just as well.
-
-
-0.2.0.1.1.6.5.1.0.3.1.loligo.com. 3600 IN NAPTR 10 100 "u" "E2U+tel" "!^\\+13015611020$!tel:+12125551212!" .
-0.2.0.1.1.6.5.1.0.3.1.loligo.com. 3600 IN NAPTR 21 100 "u" "E2U+tel" "!^\\+13015611020$!tel:+14155551212!" .
-0.2.0.1.1.6.5.1.0.3.1.loligo.com. 3600 IN NAPTR 25 100 "u" "E2U+sip" "!^\\+13015611020$!sip:2203@sip.fox-den.com!" .
-0.2.0.1.1.6.5.1.0.3.1.loligo.com. 3600 IN NAPTR 26 100 "u" "E2U+sip" "!^\\+13015611020$!sip:1234@sip-2.fox-den.com!" .
-0.2.0.1.1.6.5.1.0.3.1.loligo.com. 3600 IN NAPTR 30 100 "u" "E2U+sip" "!^\\+*([^\\*]*)!sip:\\1@sip-3.fox-den.com!" .
-0.2.0.1.1.6.5.1.0.3.1.loligo.com. 3600 IN NAPTR 55 100 "u" "E2U+mailto" "!^\\+13015611020$!mailto:jtodd@fox-den.com!" .
-
-Example 1: Simplest case, using first SIP return (use all defaults
-except for domain name)
-exten => 100,1,Set(foo=${ENUMLOOKUP(+13015611020,,,loligo.com)})
- returns: ${foo}="2203@sip.fox-den.com"
-
-Example 2: What is the first "tel" pointer type for this number?
-(after sorting by order/preference; default of "1" is assumed in
-options field)
-exten => 100,1,Set(foo=${ENUMLOOKUP(+13015611020,tel,,loligo.com)})
- returns: ${foo}="+12125551212"
-
-Example 3: How many "sip" pointer type entries are there for this number?
-exten => 100,1,Set(foo=${ENUMLOOKUP(+13015611020,sip,c,loligo.com)})
- returns: ${foo}=3
-
-Example 4: For all the "tel" pointer type entries, what is the second
-one in the list? (after sorting by preference)
-exten => 100,1,Set(foo=${ENUMLOOKUP(+13015611020,tel,2,loligo.com)})
- returns: ${foo}="+14155551212"
-
-Example 5: How many NAPTRs (tel, sip, mailto, etc.) are in the list for this number?
-exten => 100,1,Set(foo=${ENUMLOOKUP(+13015611020,ALL,c,loligo.com)})
- returns: ${foo}=6
-
-Example 6: Give back the second full URI in the sorted list of all NAPTR URIs:
-exten => 100,1,Set(foo=${ENUMLOOKUP(+13015611020,ALL,2,loligo.com)})
- returns: ${foo}="tel:+14155551212" [note the "tel:" prefix in the string]
-
-Example 7: Look up first SIP entry for the number in the e164.arpa zone (all defaults)
-exten => 100,1,Set(foo=${ENUMLOOKUP(+437203001721)})
- returns: ${foo}="enum-test@sip.nemox.net" [note: this result is
- subject to change as it is "live" DNS and not under my control]
-
-
-Example 8: Look up the ISN mapping in freenum.org alpha test zone
-exten => 100,1,Set(foo=${ENUMLOOKUP(1234*256,,,freenum.org)})
- returns: ${foo}="1234@204.91.156.10" [note: this result is subject
- to change as it is "live" DNS]
-
-Example 9: Give back the first SIP pointer for a number in the
-enum.yoydynelabs.com zone (invalid lookup)
-exten => 100,1,Set(foo=${ENUMLOOKUP(1234567890,sip,1,enum.yoyodynelabs.com)})
- returns: ${foo}=""
-
-
-Usage notes and subtle features:
-
- a) The use of "+" in lookups is confusing, and warrants further
- explanation. All E.164 numbers ("global phone numbers") by
- definition need a leading "+" during ENUM lookup. If you neglect to
- add a leading "+", you may discover that numbers that seem to exist
- in the DNS aren't getting matched by the system or are returned with
- a null string result. This is due to the NAPTR reply requiring a
- "+" in the regular expression matching sequence. Older versions of
- Asterisk add a "+" from within the code, which may confuse
- administrators converting to the new function. Please ensure that
- all ENUM (e164.arpa) lookups contain a leading "+" before lookup, so
- ensure your lookup includes the leading plus sign. Other DNS trees
- may or may not require a leading "+" - check before using those
- trees, as it is possible the parsed NAPTRs will not provide correct
- results unless you have the correct dialed string. If you get
- console messages like "WARNING[24907]: enum.c:222 parse_naptr: NAPTR
- Regex match failed." then it is very possible that the returned
- NAPTR expects a leading "+" in the search string (or the returned
- NAPTR is mis-formed.)
-
- b) If a query is performed of type "c" ("count") and let's say you
- get back 5 records and then some seconds later a query is made
- against record 5 in the list, it may not be the case that the DNS
- resolver has the same answers as it did a second or two ago - maybe
- there are only 4 records in the list in the newest query. The
- resolver should be the canonical storage location for DNS records,
- since that is the intent of ENUM. However, some obscure future
- cases may have wildly changing NAPTR records within several seconds.
- This is a corner case, and probably only worth noting as a very rare
- circumstance. (note: I do not object to Asterisk's dnsmgr method of
- locally caching DNS replies, but this method needs to honor the TTL
- given by the remote zone master. Currently, the ENUMLOOKUP function
- does not use the dnsmgr method of caching local DNS replies.)
-
- c) If you want strict NAPTR value ordering, then it will be
- necessary to use the "ALL" method to incrementally step through the
- different returned NAPTR pointers. You will need to use string
- manipulation to strip off the returned method types, since the
- results will look like "sip:12125551212" in the returned value.
- This is a non-trivial task, though it is required in order to have
- strict RFC compliance and to comply with the desires of the remote
- party who is presenting NAPTRs in a particular order for a reason.
-
- d) Default behavior for the function (even in event of an error) is
- to move to the next priority, and the result is a null value. Most
- ENUM lookups are going to be failures, and it is the responsibility
- of the dialplan administrator to manage error conditions within
- their dialplan. This is a change from the old app_enumlookup method
- and it's arbitrary priority jumping based on result type or failure.
-
- e) Anything other than digits will be ignored in lookup strings.
- Example: a search string of "+4372030blah01721" will turn into
- 1.2.7.1.0.0.3.0.2.7.3.4.e164.arpa. for the lookup. The NAPTR
- parsing may cause unexpected results if there are strings inside
- your NAPTR lookups.
-
- f) If there exist multiple records with the same weight and order as
- a result of your query, the function will RANDOMLY select a single
- NAPTR from those equal results.
-
- g) Currently, the function ignores the settings in enum.conf as the
- search zone name is now specified within the function, and the H323
- driver can be chosen by the user via the dialplan. There were no
- other values in this file, and so it becomes deprecated.
-
- h) The function will digest and return NAPTRs which use older
- (depricated) style, reversed method strings such as "sip+E2U"
- instead of the more modern "E2U+sip"
-
- i) There is no provision for multi-part methods at this time. If
- there are multiple NAPTRs with (as an example) a method of
- "E2U+voice:sip" and then another NAPTR in the same DNS record with a
- method of ""E2U+sip", the system will treat these both as method
- "sip" and they will be separate records from the perspective of the
- function. Of course, if both records point to the same URI and have
- equal priority/weight (as is often the case) then this will cause no
- serious difficulty, but it bears mentioning.
-
- j) ISN (ITAD Subscriber Number) usage: If the search number is of
- the form ABC*DEF (where ABC and DEF are at least one numeric digit)
- then perform an ISN-style lookup where the lookup is manipulated to
- C.B.A.DEF.domain.tld (all other settings and options apply.) See
- http://www.freenum.org/ for more details on ISN lookups. In the
- unlikely event you wish to avoid ISN re-writes, put an "n" as the
- first digit of the search string - the "n" will be ignored for the search.
-
-
-==EXAMPLES==
-
-All examples below except where noted use "e164.arpa" as the
-referenced domain, which is the default domain name for ENUMLOOKUP.
-All numbers are assumed to not have a leading "+" as dialed by the
-inbound channel, so that character is added where necessary during
-ENUMLOOKUP function calls.
-
-; example 1
-;
-; Assumes North American international dialing (011) prefix.
-; Look up the first SIP result and send the call there, otherwise
-; send the call out a PRI. This is the most simple possible
-; ENUM example, but only uses the first SIP reply in the list of
-; NAPTR(s).
-;
-exten => _011.,1,Set(enumresult=${ENUMLOOKUP(+${EXTEN:3})})
-exten => _011.,n,Dial(SIP/${enumlookup})
-exten => _011.,n,Dial(Zap/g1/${EXTEN})
-;
-; end example 1
-
-; example 2
-;
-; Assumes North American international dialing (011) prefix.
-; Check to see if there are multiple SIP NAPTRs returned by
-; the lookup, and dial each in order. If none work (or none
-; exist) then send the call out a PRI, group 1.
-;
-exten => _011.,1,Set(sipcount=${ENUMLOOKUP(${EXTEN:3},sip,c)}|counter=0)
-exten => _011.,n,While($["${counter}"<"${sipcount}"])
-exten => _011.,n,Set(counter=$[${counter}+1])
-exten => _011.,n,Dial(SIP/${ENUMLOOKUP(+${EXTEN:3},sip,${counter})})
-exten => _011.,n,EndWhile
-exten => _011.,n,Dial(Zap/g1/${EXTEN})
-;
-; end example 2
-
-; example 3
-;
-; This example expects an ${EXTEN} that is an e.164 number (like
-; 14102241145 or 437203001721)
-; Search through e164.arpa and then also search through e164.org
-; to see if there are any valid SIP or IAX termination capabilities.
-; If none, send call out via Zap channel 1.
-;
-; Start first with e164.arpa zone...
-;
-exten => _X.,1,Set(sipcount=${ENUMLOOKUP(+${EXTEN},sip,c)}|counter=0)
-exten => _X.,2,GotoIf($["${counter}"<"${sipcount}"]?3:6)
-exten => _X.,3,Set(counter=$[${counter}+1])
-exten => _X.,4,Dial(SIP/${ENUMLOOKUP(+${EXTEN},sip,${counter})})
-exten => _X.,5,GotoIf($["${counter}"<"${sipcount}"]?3:6)
-;
-exten => _X.,6,Set(iaxcount=${ENUMLOOKUP(+${EXTEN},iax2,c)}|counter=0)
-exten => _X.,7,GotoIf($["${counter}"<"${iaxcount}"]?8:11)
-exten => _X.,8,Set(counter=$[${counter}+1])
-exten => _X.,9,Dial(IAX2/${ENUMLOOKUP(+${EXTEN},iax2,${counter})})
-exten => _X.,10,GotoIf($["${counter}"<"${iaxcount}"]?8:11)
-;
-exten => _X.,11,NoOp("No valid entries in e164.arpa for ${EXTEN} - checking in e164.org")
-;
-; ...then also try e164.org, and look for SIP and IAX NAPTRs...
-;
-exten => _X.,12,Set(sipcount=${ENUMLOOKUP(+${EXTEN},sip,c,e164.org)}|counter=0)
-exten => _X.,13,GotoIf($["${counter}"<"${sipcount}"]?14:17)
-exten => _X.,14,Set(counter=$[${counter}+1])
-exten => _X.,15,Dial(SIP/${ENUMLOOKUP(+${EXTEN},sip,${counter},e164.org)})
-exten => _X.,16,GotoIf($["${counter}"<"${sipcount}"]?14:17)
-;
-exten => _X.,17,Set(iaxcount=${ENUMLOOKUP(+${EXTEN},iax2,c,e164.org)}|counter=0)
-exten => _X.,18,GotoIf($["${counter}"<"${iaxcount}"]?19:22)
-exten => _X.,19,Set(counter=$[${counter}+1])
-exten => _X.,20,Dial(IAX2/${ENUMLOOKUP(+${EXTEN},iax2,${counter},e164.org)})
-exten => _X.,21,GotoIf($["${counter}"<"${iaxcount}"]?19:22)
-;
-; ...then send out PRI.
-;
-exten => _X.,22,NoOp("No valid entries in e164.org for ${EXTEN} - sending out via Zap")
-exten => _X.,23,Dial(Zap/g1/${EXTEN})
-;
-; end example 3
diff --git a/1.2-netsec/doc/README.extconfig b/1.2-netsec/doc/README.extconfig
deleted file mode 100644
index 6b147e573..000000000
--- a/1.2-netsec/doc/README.extconfig
+++ /dev/null
@@ -1,85 +0,0 @@
-Asterisk external configuration
-===============================
-
-The Asterisk external configuration engine is the result of work by
-Anthony Minessale II, Mark Spencer and Constantine Filin.
-
-It is designed to provide a flexible, seamless integration between
-Asterisk's internal configuration structure and external SQL other other
-databases (maybe even LDAP one day).
-
-The external configuration engine is the basis for the ARA, the
-Asterisk Realtime Architecture (see README.realtime for more
-information).
-
-* Configuration
-
-External configuration is configured in /etc/asterisk/extconfig.conf
-allowing you to map any configuration file (static mappings) to
-be pulled from the database, or to map special runtime entries which
-permit the dynamic creation of objects, entities, peers, etc. without
-the necessity of a reload.
-
-Generally speaking, the columns in your tables should line up with the
-fields you would specify in the given entity declaration. If an entry
-would appear more than once, in the column it should be separated by a
-semicolon. For example, an entity that looks like:
-
-[foo]
-host=dynamic
-secret=bar
-context=default
-context=local
-
-could be stored in a table like this:
-
-+------+--------+-------+--------------+----------+-----+-----------+
-| name | host | secret| context | ipaddr | port| regseconds|
-+------+--------+-------+--------------+----------+-----+-----------+
-| foo | dynamic| bar | default;local| 127.0.0.1| 4569| 1096954152|
-+------+--------+-------+--------------+----------+-----+-----------+
-
-Note that for use with IAX or SIP, the table will also need the "name",
-"ipaddr", "port", "regseconds" columns. If you wanted to be able to
-configure the callerid, you could just add a callerid column to the
-table, for example.
-
-A SIP table would look more like this:
-
-+------+--------+-------+----------+-----+------------+----------+
-| name | host | secret| ipaddr | port| regseconds | username |
-+------+--------+-------+----------+-----+------------+----------+
-| foo | dynamic| bar | 127.0.0.1| 4569| 1096954152 | 1234 |
-+------+--------+-------+----------+-----+------------+----------+
-
-in order to store appropriate parameters required for SIP.
-
-A Voicemail table would look more like this:
-
-+----------+---------+----------+----------+-----------+---------------+
-| uniqueid | mailbox | context | password |email | fullname |
-+----------+---------+----------+----------+-----------+---------------+
-| 1 | 1234 | default | 4242 | a@b.com | Joe Schmoe |
-+----------+---------+----------+----------+-----------+---------------+
-
-The uniqueid should be unique to each voicemail user and can be
-autoincrement. It need not have any relation to the mailbox or context.
-
-An extension table would look more like this:
-
-+----------+---------+----------+-------+-----------+
-| context | exten | priority | app | appdata |
-+----------+---------+----------+-------+-----------+
-| default | 1234 | 1 | Dial | Zap/1 |
-+----------+---------+----------+-------+-----------+
-
-In the dialplan you just use the Realtime switch:
-
-[foo]
-switch => Realtime
-
-or:
-
-[bar]
-switch => Realtime/bar@extensions
-
diff --git a/1.2-netsec/doc/README.externalivr b/1.2-netsec/doc/README.externalivr
deleted file mode 100644
index a1d4757e7..000000000
--- a/1.2-netsec/doc/README.externalivr
+++ /dev/null
@@ -1,109 +0,0 @@
-Asterisk External IVR Interface
--------------------------------
-
-If you load app_externalivr.so in your Asterisk instance, you will
-have an ExternalIVR() application available in your dialplan. This
-application implements a simple protocol for bidirectional
-communication with an external process, while simultaneous playing
-audio files to the connected channel (without interruption or
-blocking).
-
-The arguments to ExternalIVR() consist of the command to execute and
-any arguments to pass to it, the same as the System() application
-accepts. The external command will be executed in a child process,
-with its standard file handles connected to the Asterisk process as
-follows:
-
-stdin (0) - DTMF and hangup events will be received on this handle
-stdout (1) - Playback and hangup commands can be sent on this handle
-stderr (2) - Error messages can be sent on this handle
-
-The application will also create an audio generator to play audio to
-the channel, and will start playing silence. When your application
-wants to send audio to the channel, it can send a command (see below)
-to add file(s) to the generator's playlist. The generator will then
-work its way through the list, playing each file in turn until it
-either runs out of files to play, the channel is hung up, or a command
-is received to clear the list and start with a new file. At any time,
-more files can be added to the list and the generator will play them
-in sequence.
-
-While the generator is playing audio (or silence), any DTMF events
-received on the channel will be sent to the child process (see
-below). Note that this can happen at any time, since the generator,
-the child process and the channel thread are all executing
-independently. It is very important that your external application be
-ready to receive events from Asterisk at all times (without blocking),
-or you could cause the channel to become non-responsive.
-
-If the child process dies, ExternalIVR() will notice this and hang up
-the channel immediately (and also send a message to the log).
-
-DTMF (and other) events
------------------------
-
-All events will be newline-terminated strings.
-
-Events send to the child's stdin will be in the following format:
-
-tag,timestamp[,data]
-
-The tag can be one of the following characters:
-
-0-9: DTMF event for keys 0 through 9
-A-D: DTMF event for keys A through D
-*: DTMF event for key *
-#: DTMF event for key #
-H: the channel was hung up by the connected party
-Z: the previous command was unable to be executed (file does not
-exist, etc.)
-T: the play list was interrupted (see below)
-D: a file was dropped from the play list due to interruption (the
-data element will be the dropped file name)
-F: a file has finished playing (the data element will be the file
-name)
-
-The timestamp will be 10 digits long, and will be a decimal
-representation of a standard Unix epoch-based timestamp.
-
-Commands
---------
-
-All commands must be newline-terminated strings.
-
-The child process can send commands on stdout in the following formats:
-
-S,filename
-A,filename
-H,message
-O,option
-
-The 'S' command checks to see if there is a playable audio file with
-the specified name, and if so, clear's the generator's playlist and
-places the file onto the list. Note that the playability check does
-not take into account transcoding requirements, so it is possible for
-the file to not be played even though it was found. If the file cannot
-be found, a 'Z' event (see above) will be sent to the child. If the
-generator is not currently playing silence, then T and D events will
-be sent to the child to signal the playlist interruption and notify
-it of the files that will not be played.
-
-The 'A' command checks to see if there is a playable audio file with
-the specified name, and if so, adds it to the generator's
-playlist. The same playability and exception rules apply as for the
-'S' command.
-
-The 'H' command stops the generator and hangs up the channel, and logs
-the supplied message to the Asterisk log.
-
-The 'O' command allows the child to set/clear options in the
-ExternalIVR() application. The supported options are:
- autoclear/noautoclear:
- Automatically interrupt and clear the playlist upon reception
- of DTMF input.
-
-Errors
-------
-
-Any newline-terminated output generated by the child process on its
-stderr handle will be copied into the Asterisk log.
diff --git a/1.2-netsec/doc/README.h323 b/1.2-netsec/doc/README.h323
deleted file mode 100644
index 9951f6353..000000000
--- a/1.2-netsec/doc/README.h323
+++ /dev/null
@@ -1,23 +0,0 @@
-The Asterisk PBX supports H.323 via two totally separate
-channel drivers.
-
-You can find more information Asterisk's native H.323
-support in /path/to/asterisk/channels/h323/README or
-you can download a third party driver at
-http://www.inaccessnetworks.com/projects/asterisk-oh323
-
-Asterisk's native H.323 is supported and maintained by
-Jeremy McNamara (JerJer in irc). Support for the third
-party H.323 driver is supplied by inAccessNetworks.
-
-If you have trouble with either driver you should direct
-your debug and comments to the appropriate party, making
-sure to be specific in exactly which H.323 driver you are
-running.
-
-Please, read all supplied documentation before contacting
-either party for support. Many issues can be quickly
-resolved by simply following the instructions that are
-provided.
-
-
diff --git a/1.2-netsec/doc/README.iax b/1.2-netsec/doc/README.iax
deleted file mode 100644
index 1a35d6b15..000000000
--- a/1.2-netsec/doc/README.iax
+++ /dev/null
@@ -1,369 +0,0 @@
-Inter-Asterisk eXchange Protocol
-================================
-
-INTRODUCTION
-------------
-
-This document is intended as an introduction to the Inter-Asterisk
-eXchange (or simply IAX) protocol. It provides both a theoretical
-background and practical information on its use.
-
-WHY IAX
--------
-The first question most people are thinking at this point is "Why do you
-need another VoIP protocol? Why didn't you just use SIP or H.323?"
-
-Well, the answer is a fairly complicated one, but in a nutshell it's like
-this... Asterisk is intended as a very flexible and powerful
-communications tool. As such, the primary feature we need from a VoIP
-protocol is the ability to meet our own goals with Asterisk, and one with
-enough flexibility that we could use it as a kind of laboratory for
-inventing and implementing new concepts in the field. Neither H.323 or
-SIP fit the roles we needed, so we developed our own protocol, which,
-while not standards based, provides a number of advantages over both SIP
-and H.323, some of which are:
-
- * Interoperability with NAT/PAT/Masquerade firewalls
- IAX seamlessly interoperates through all sorts of NAT and PAT
- and other firewalls, including the ability to place and
- receive calls, and transfer calls to other stations.
-
- * High performance, low overhead protocol
- When running on low-bandwidth connections, or when running
- large numbers of calls, optimized bandwidth utilization is
- imperative. IAX uses only 4 bytes of overhead
-
- * Internationalization support
- IAX transmits language information, so that remote PBX
- content can be delivered in the native language of the
- calling party.
-
- * Remote dialplan polling
- IAX allows a PBX or IP phone to poll the availability of a
- number from a remote server. This allows PBX dialplans to
- be centralized.
-
- * Flexible authentication
- IAX supports cleartext, md5, and RSA authentication,
- providing flexible security models for outgoing calls and
- registration services.
-
- * Multimedia protocol
- IAX supports the transmission of voice, video, images, text,
- HTML, DTMF, and URL's. Voice menus can be presented in both
- audibly and visually.
-
- * Call statistic gathering
- IAX gathers statistics about network performance (including
- latency and jitter, as well as providing end-to-end latency
- measurement.
-
- * Call parameter communication
- Caller*ID, requested extension, requested context, etc are
- all communicated through the call.
-
- * Single socket design
- IAX's single socket design allows up to 32768 calls to be
- multiplexed.
-
-While we value the importance of standards based (i.e. SIP) call handling,
-hopefully this will provide a reasonable explanation of why we developed
-IAX rather than starting with SIP.
-
-CONFIG FILE CONVENTIONS
------------------------
-Lines beginning with '>' represent lines which might appear in an actual
-configuration file. The '>' is used to help separate them from the
-descriptive text and should not actually be included in the file itself.
-
-Lines within []'s by themselves represent section labels within the
-configuration file. like this:
-
-> [mysection]
-
-Options are set using the "=" sign, for example
-
-> myoption = value
-
-Sometimes an option will have a number of discrete values which it can
-take. In that case, in the documentation, the options will be listed
-within square brackets (the "[" and "]" ones) separated by the pipe symbol
-("|"). For example:
-
-> myoption = [value1|value2|value3]
-
-means the option "myoption" can be assigned a value of "value1", "value2",
-or "value3".
-
-Objects, or pseudo-objects are instantiated using the "=>" construct. For
-example:
-
-> myobject => parameter
-
-creates an object called "myobject" with some parameter whose definition
-would be specific to that object. Note that the config file parser
-considers "=>" and "=" to be equivalent and their use is purely to make
-configuration files more readable and easier to "humanly parse".
-
-The comment character in Asterisk configuration files is the semicolon
-";". The reason it is not "#" is because the "#" symbol can be used as
-parts of extensions and it didn't seem like a good idea to have to escape
-it.
-
-IAX CONFIGURATION IN ASTERISK
------------------------------
-
-Like everything else in Asterisk, IAX's configuration lies in
-/etc/asterisk -- specifically /etc/asterisk/iax.conf
-
-The IAX configuration file is a collection of sections, each of which
-(with the exception of the "general" section) represents an entity within
-the IAX scope.
-
-------------
-
-The first section is typically the "general" section. In this area,
-a number of parameters which affect the entire system are configured.
-Specifically, the default codecs, port and address, jitter behavior, TOS
-bits, and registrations.
-
-The first line of the "general" section is always:
-
-> [general]
-
-Following the first line are a number of other possibilities:
-
-> bindport = <portnum>
-
-This sets the port that IAX will bind to. The default IAX version 1
-port number is 5036. For IAX version 2, that is now the default in
-Asterisk, the default port is 4569.
-It is recommended that this value not be altered in general.
-
-> bindaddr = <ipaddr>
-
-This allows you to bind IAX to a specific local IP address instead of
-binding to all addresses. This could be used to enhance security if, for
-example, you only wanted IAX to be available to users on your LAN.
-
-> bandwidth = [low|medium|high]
-
-The bandwidth selection initializes the codec selection to appropriate
-values for given bandwidths. The "high" selection enables all codecs and
-is recommended only for 10Mbps or higher connections. The "medium"
-bandwidth eliminates signed linear, Mu-law and A-law codecs, leaving only
-the codecs which are 32kbps and smaller (with MP3 as a special case). It
-can be used with broadband connections if desired. "low" eliminates ADPCM
-and MP3 formats, leaving only the G.723.1, GSM, and LPC10.
-
-> allow = [gsm|lpc10|g723.1|adpcm|ulaw|alaw|mp3|slinear|all]
-> disallow = [gsm|lpc10|g723.1|adpcm|ulaw|alaw|mp3|slinear|all]
-
-The "allow" and "disallow" allow you to fine tune the codec selection
-beyond the initial bandwidth selection on a codec-by-codec basis.
-
-The recommended configuration is to select "low" bandwidth and then
-disallow the LPC10 codec just because it doesn't sound very good.
-
-> jitterbuffer = [yes|no]
-> dropcount = <dropamount>
-> maxjitterbuffer = <max>
-> maxexcessbuffer = <max>
-
-These parameters control the operation of the jitter buffer. The
-jitterbuffer should always be enabled unless you expect all your
-connections to be over a LAN.
-* drop count is the maximum number of voice packets to allow to drop
- (out of 100). Useful values are 3-10.
-* maxjitterbuffer is the maximum amount of jitter buffer to permit to be
- used.
-* maxexcessbuffer is the maximum amount of excess jitter buffer
- that is permitted before the jitter buffer is slowly shrunk to eliminate
- latency.
-* minexcessbuffer is the minimum amout of excess jitter buffer
-
-> accountcode = <code>
-> amaflags = [default|omit|billing|documentation]
-
-These parameters affect call detail record generation. The first sets the
-account code for records received with IAX. The account code can be
-overridden on a per-user basis for incoming calls (see below). The
-amaflags controls how the record is labeled ("omit" causes no record to be
-written. "billing" and "documentation" label the records as billing or
-documentation records respectively, and "default" selects the system
-default.
-
-> tos = [lowdelay|throughput|reliability|mincost|none]
-
-IAX can optionally set the TOS (Type of Service) bits to specified values
-to help improve performance in routing. The recommended value is
-"lowdelay", which many routers (including any Linux routers with 2.4
-kernels that have not been altered with ip tables) will give priority to
-these packets, improving voice quality.
-
-> register => <name>[:<secret>]@<host>[:port]
-
-Any number of registry entries may be instantiated in the general
-section. Registration allows Asterisk to notify a remote Asterisk server
-(with a fixed address) what our current address is. In order for
-registration to work, the remote Asterisk server will need to have a
-dynamic peer entry with the same name (and secret if provided).
-
-The name is a required field, and is the remote peer name that we wish to
-identify ourselves as. A secret may be provided as well. The secret is
-generally a shared password between the local server and the remote
-server. However, if the secret is in square brackets ([]'s) then it is
-interpreted as the name of a RSA key to use. In that case, the local Asterisk
-server must have the *private* key (/var/lib/asterisk/keys/<name>.key) and
-the remote server will have to have the corresponding public key.
-
-The "host" is a required field and is the hostname or IP address of the
-remote Asterisk server. The port specification is optional and is by
-default 4569 for iax2 if not specified.
-
-> notransfer = yes | no
-
-If an IAX phone calls another IAX phone by using a Asterisk server,
-Asterisk will transfer the call to go peer to peer. If you do not
-want this, turn on notransfer with a "yes". This is also settable
-for peers and users.
-
--------------
-
-The following sections, after "general" define either users, peers or
-friends. A "user" is someone who connects to us. A "peer" is someone
-that we connect to. A "friend" is simply shorthand for creating a "user"
-and "peer" with identical parameters (i.e. someone who can contact us and
-who we contact).
-
-> [identifier]
-
-The section begins with the identifier in square brackets. The identifier
-should be an alphanumeric string.
-
-> type = [user|peer|friend]
-
-This line tells Asterisk how to interpret this entity. Users are things
-that connect to us, while peers are phones we connect to, and a friend is
-shorthand for creating a user and a peer with identical information
-
-----------------
-User fields:
-
-> context = <context>
-
-One or more context lines may be specified in a user, thus giving the user
-access to place calls in the given contexts. Contexts are used by
-Asterisk to divide dialing plans into logical units each with the ability
-to have numbers interpreted differently, have their own security model,
-auxiliary switch handling, and include other contexts. Most users are
-given access to the default context. Trusted users could be given access
-to the local context for example.
-
-> permit = <ipaddr>/<netmask>
-> deny = <ipaddr>/<netmask>
-
-Permit and deny rules may be applied to users, allowing them to connect
-from certain IP addresses and not others. The permit and deny rules are
-interpreted in sequence and all are evaluated on a given IP address, with
-the final result being the decision. For example:
-
-> permit = 0.0.0.0/0.0.0.0
-> deny = 192.168.0.0/255.255.255.0
-
-would deny anyone in 192.168.0.0 with a netmask of 24 bits (class C),
-whereas:
-
-> deny = 192.168.0.0/24
-> permit = 0.0.0.0/0
-
-would not deny anyone since the final rule would permit anyone, thus
-overriding the denial.
-
-If no permit/deny rules are listed, it is assumed that someone may connect
-from anywhere.
-
-> callerid = <callerid>
-
-You may override the Caller*ID information passed by a user to you (if
-they choose to send it) in order that it always be accurate from the
-perspective of your server.
-
-> auth = [md5|plaintext|rsa]
-
-You may select which authentication methods are permitted to be used by
-the user to authenticate to us. Multiple methods may be specified,
-separated by commas. If md5 or plaintext authentication is selected, a
-secret must be provided. If RSA authentication is specified, then one or
-more key names must be specified with "inkeys"
-
-If no secret is specified and no authentication method is specified, then
-no authentication will be required.
-
-> secret = <secret>
-
-The "secret" line specifies the shared secret for md5 and plaintext
-authentication methods. It is never suggested to use plaintext except in
-some cases for debugging.
-
-> inkeys = key1[:key2...]
-
-The "inkeys" line specifies which keys we can use to authenticate the
-remote peer. If the peer's challenge passes with any of the given keys,
-then we accept its authentication. The key files live in
-/var/lib/asterisk/keys/<name>.pub and are *public keys*. Public keys are
-not typically DES3 encrypted and thus do not usually need initialization.
-
----------------
-Peer configuration
-
-> allow = [gsm|lpc10|g723.1|adpcm|ulaw|alaw|mp3|slinear|all]
-> disallow = [gsm|lpc10|g723.1|adpcm|ulaw|alaw|mp3|slinear|all]
-
-The "allow" and "disallow" may be used to enable or disable specific codec
-support on a per-peer basis.
-
-> host = [<ipaddr>|dynamic]
-
-The host line specifies the hostname or IP address of the remote host, or
-may be the word "dynamic" signifying that the host will register with us
-(see register => in the general section above).
-
-> defaultip = <ipaddr>
-
-If the host uses dynamic registration, Asterisk may still be given a
-default IP address to use when dynamic registration has not been performed
-or has timed out.
-
-> peercontext = <context>
-
-Specifies the context name to be passed to the peer for it to use when routing
-the call through its dial plan. This entry will be used only if a context
-is not included in the IAX2 channel name passed to the Dial command.
-
-> qualify = [yes | no | <value>]
-
-Qualify turns on checking of availability of the remote peer. If the
-peer becomes unavailable, no calls are placed to the peer until
-it is reachable again. This is also helpful in certain NAT situations.
-
-> jitterbuffer = [yes | no]
-
-Turns on or off the jitterbuffer for this peer
-
-> mailbox = <mailbox>[@mailboxcontext]
-
-Specifies a mailbox to check for voicemail notification.
-
-> permit = <ipaddr>/<netmask>
-> deny = <ipaddr>/<netmask>
-
-Permit and deny rules may be applied to users, allowing them to connect
-from certain IP addresses and not others. The permit and deny rules are
-interpreted in sequence and all are evaluated on a given IP address, with
-the final result being the decision. See the user section above
-for examples.
-
-----------------------------------------------------------------------
-For more examples of a configuration, please see the iax.conf.sample in
-your the /configs directory of you source code distribution
diff --git a/1.2-netsec/doc/README.ices b/1.2-netsec/doc/README.ices
deleted file mode 100644
index d75236357..000000000
--- a/1.2-netsec/doc/README.ices
+++ /dev/null
@@ -1,12 +0,0 @@
-Icecast + Asterisk
-==================
-The advent of icecast into Asterisk allows you to do neat things like have
-a caller stream right into an ice-cast stream as well as using chan_local
-to place things like conferences, music on hold, etc. into the stream.
-
-You'll need to specify a config file for the ices encoder. An example is
-included in contrib/asterisk-ices.xml
-
-Anyway hope you like it.
-
-Mark
diff --git a/1.2-netsec/doc/README.jitterbuffer b/1.2-netsec/doc/README.jitterbuffer
deleted file mode 100644
index e5cd81ce0..000000000
--- a/1.2-netsec/doc/README.jitterbuffer
+++ /dev/null
@@ -1,137 +0,0 @@
-The new Jitterbuffer in Asterisk
---------------------------------
-Steve Kann
-
-
-
-The new jitterbuffer, PLC, and the IAX2-integration of the new jitterbuffer
-have been integrated into Asterisk. The jitterbuffer is generic and work is
-going on to implement it in SIP/RTP as well.
-
-Also, we've added a feature called "trunktimestamps", which adds individual
-timestamps to trunked frames within a trunk frame.
-
-Here's how to use this stuff:
-
-1) The new jitterbuffer:
-------------------------
-You must add "jitterbuffer=yes" to either the [general] part of
-iax.conf, or to a peer or a user. (just like the old jitterbuffer).
-Also, you can set "maxjitterbuffer=n", which puts a hard-limit on the size of the
-jitterbuffer of "n milliseconds". It is not necessary to have the new jitterbuffer
-on both sides of a call; it works on the receive side only.
-
-2) PLC:
--------
-The new jitterbuffer detects packet loss. PLC is done to try to recreate these
-lost packets in the codec decoding stage, as the encoded audio is translated to slinear.
-PLC is also used to mask jitterbuffer growth.
-
-This facility is enabled by default in iLBC and speex, as it has no additional cost.
-This facility can be enabled in adpcm, alaw, g726, gsm, lpc10, and ulaw by setting
-genericplc => true in the [plc] section of codecs.conf.
-
-3) Trunktimestamps:
--------------------
-To use this, both sides must be using Asterisk v1.2.
-Setting "trunktimestamps=yes" in iax.conf will cause your box to send 16-bit timestamps
-for each trunked frame inside of a trunk frame. This will enable you to use jitterbuffer
-for an IAX2 trunk, something that was not possible in the old architecture.
-
-The other side must also support this functionality, or else, well, bad things will happen.
-If you don't use trunktimestamps, there's lots of ways the jitterbuffer can get confused because
-timestamps aren't necessarily sent through the trunk correctly.
-
-4) Communication with Asterisk v1.0.x systems
----------------------------------------------
-You can set up communication with v1.0.x systems with the new jitterbuffer, but
-you can't use trunks with trunktimestamps in this communication.
-
-If you are connecting to an Asterisk server with earlier versions of the software (1.0.x),
-do not enable both jitterbuffer and trunking for the involved peers/users
-in order to be able to communicate. Earlier systems will not support trunktimestamps.
-
-You may also compile chan_iax2.c without the new jitterbuffer, enabling the old
-backwards compatible architecture. Look in the source code for instructions.
-
-
-5) Testing and monitoring:
---------------------------
-You can test the effectiveness of PLC and the new jitterbuffer's detection of loss by using
-the new CLI command "iax2 test losspct <n>". This will simulate n percent packet loss
-coming _in_ to chan_iax2. You should find that with PLC and the new JB, 10 percent packet
-loss should lead to just a tiny amount of distortion, while without PLC, it would lead to
-silent gaps in your audio.
-
-"iax2 show netstats" shows you statistics for each iax2 call you have up.
-The columns are "RTT" which is the round-trip time for the last PING, and then a bunch of s
-tats for both the local side (what you're receiving), and the remote side (what the other
-end is telling us they are seeing). The remote stats may not be complete if the remote
-end isn't using the new jitterbuffer.
-
-The stats shown are:
-* Jit: The jitter we have measured (milliseconds)
-* Del: The maximum delay imposed by the jitterbuffer (milliseconds)
-* Lost: The number of packets we've detected as lost.
-* %: The percentage of packets we've detected as lost recently.
-* Drop: The number of packets we've purposely dropped (to lower latency).
-* OOO: The number of packets we've received out-of-order
-* Kpkts: The number of packets we've received / 1000.
-
-Reporting problems
-==================
-
-There's a couple of things that can make calls sound bad using the jitterbuffer:
-
-1) The JB and PLC can make your calls sound better, but they can't fix everything.
-If you lost 10 frames in a row, it can't possibly fix that. It really can't help much
-more than one or two consecutive frames.
-
-2) Bad timestamps: If whatever is generating timestamps to be sent to you generates
-nonsensical timestamps, it can confuse the jitterbuffer. In particular, discontinuities
-in timestamps will really upset it: Things like timestamps sequences which go 0, 20, 40,
-60, 80, 34000, 34020, 34040, 34060... It's going to think you've got about 34 seconds
-of jitter in this case, etc..
-The right solution to this is to find out what's causing the sender to send us such nonsense,
-and fix that. But we should also figure out how to make the receiver more robust in
-cases like this.
-
-chan_iax2 will actually help fix this a bit if it's more than 3 seconds or so, but at
-some point we should try to think of a better way to detect this kind of thing and
-resynchronize.
-
-Different clock rates are handled very gracefully though; it will actually deal with a
-sender sending 20% faster or slower than you expect just fine.
-
-3) Really strange network delays: If your network "pauses" for like 5 seconds, and then
-when it restarts, you are sent some packets that are 5 seconds old, we are going to see
-that as a lot of jitter. We already throw away up to the worst 20 frames like this,
-though, and the "maxjitterbuffer" parameter should put a limit on what we do in this case.
-
-Reporting possible bugs
------------------------
-If you do find bad behaviors, here's the information that will help to diagnose this:
-
-1) Describe
-
-a) the source of the timestamps and frames: i.e. if they're coming from another chan_iax2 box,
-a bridged RTP-based channel, an IAX2 softphone, etc..
-
-b) The network between, in brief (i.e. the internet, a local lan, etc).
-
-c) What is the problem you're seeing.
-
-
-2) Take a look and see what iax2 show netstats is saying about the call, and if it makes sense.
-
-3) a tcpdump of the frames, (or, tethereal output from), so we can see the timestamps and delivery
-times of the frames you're receiving. You can make such a tcpdump with:
-
-tcpdump -s 2048 -w /tmp/example.dump udp and port 4569 [and host <other-end>]
-
-Report bugs in the Asterisk bugtracker, http://bugs.digium.com.
-Please read the bug guidelines before you post a bug.
-
-Have fun!
-
--SteveK
diff --git a/1.2-netsec/doc/README.math b/1.2-netsec/doc/README.math
deleted file mode 100644
index 7718f9e44..000000000
--- a/1.2-netsec/doc/README.math
+++ /dev/null
@@ -1,69 +0,0 @@
-
-Mathematical dialplan function
-
-Yeah, I thought it was a little insane too..
-
-adds:
-
-Sum, Multiply, Divide, Subtract, Modulus, GT, LT, GTE, LTE, EQ functions to Asterisk
-
-All functions follow the same basic pattern for parameters:
-
-parameter 1 = the math expression
-parameter 2 = the type of result
-
-Perform calculation on number 1 to number 2. Valid ops are:
- +,-,/,*,%,<,>,>=,<=,==
-and behave as their C equivalents.
-
-<type_of_result> - wanted type of result:
- f, float - float(default)
- i, int - integer,
- h, hex - hex,
- c, char - char
-
-Each math expression is performed as
-
- Action param1 on param2
-
-eg:
-
- Action = Divide
- Param1 = 10
- Param2 = 2
-
-Results in
-
- Divide 10 by 2
-
-
-Example dialplan:
-
-exten => 11099,1,Set(RV=${MATH(1+20)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(10*2)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(10*2)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(10-2)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(2%10)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(10/0)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(10-200)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(1-20)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(1<20)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(1>=20)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(101>20)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(1==20)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(20<=20)})
-exten => 11099,n,NOOP(${RV})
-exten => 11099,n,Set(RV=${MATH(123%16,int)})
-exten => 11099,n,NOOP(${RV})
diff --git a/1.2-netsec/doc/README.misdn b/1.2-netsec/doc/README.misdn
deleted file mode 100644
index 652ba70cd..000000000
--- a/1.2-netsec/doc/README.misdn
+++ /dev/null
@@ -1,342 +0,0 @@
-mISDN Channel Driver for Asterisk PBX
-======================================
-
-
-This package contains the mISDN Channel Driver for the Asterisk PBX. It
-supports every mISDN Hardware and provides an interface for asterisk.
-
-Features:
----------
-
-* NT and TE mode
-* PP and PMP mode
-* BRI and PRI (with BNE1 and BN2E1 Cards)
-* DTMF Detection in HW+mISDNdsp (much better than asterisks internal!)
-* Display Messages to Phones (which support display msg)
-* HOLD/RETRIEVE/TRANSFER on ISDN Phones : )
-* Screen/ Not Screen User Number
-* Basic EchoCancellation
-* Volume Control
-* Crypting with mISDNdsp (Blowfish)
-* Data (HDLC) callthrough
-* Data Calling (with app_ptyfork +pppd)
-* Echo cancellation
-* Some other
-
-Supported Hardware:
--------------------
-
-chan_misdn supports any mISDN compatible Hardware.
-
-Overview
---------
-
-- Fast Installation Guide
-- Pre-Requisites
-- Compilation
-- Installation
-- Configuration
-- Dial and Options String
-- misdn cli commands
-- Debugging and sending Bugreports
-- Examples
-- Known working Configurations
-- Known Problems
-- Changes
-
-
-Fast Installation Guide
------------------------
-
-It is easy to install mISDN and mISDNuser. Using the Makefile from
-channels/misdn. You just need to type:
-
-cd channels/misdn
-make misdn
-
-Then all the necessary files are fetched from jollys homepage and are patched
-with the Echocanellor.
-
-
-Pre-Requisites
---------------
-
-To compile and install this driver, you'll need at least one mISDN Driver and
-the mISDNuser package. Chan_misdn works with both, the current release version
-and the development (svn trunk) version of Asterisk. mISDNuser and mISDN must
-be fetched from jollys homepage and must be patched with the Echocancellor.
-
-Please Note that mISDN works good for the linux-2.6.x kernels. Some of the
-mISDN drivers do not compile against the 2.4.x or older kernels, you can patch
-them, but than you'll get mysterious errors.
-
-Using Kernels > 2.6.9 works perfect.
-
-Ok so far so good, now follow the compilation instructions.
-
-!! Dont forget to create the /dev/mISDN device node.
-
-Compilation
------------
-
-The compilation of chan_misdn requires a library which will be generated under
-channels/misdn/.
-
-To compile this library you just need to go into this directory and type
-make. Now you can go back to the asterisk source root and type make install
-again, which now should compile and install chan_misdn.
-
-
-
-Installation
-------------
-
-Chan_misdn is automatically installed by the asterisk installation process.
-
-There is a sample init.d script for loading the mISDN modules (mISDN.sample),
-5Asimply copy it to /etc/init.d/ and modify it, there you can enter your cards.
-
-!! Forget to use capi together with chan_misdn.
-
-
-Configuration
--------------
-
-First of all you must configure the mISDN drivers. Each driver module has got
-an options and layermask option, which tells the driver wether to start in
-TE, NT, PP or PMP mode (there are lots more, please read docs in misdn for
-that).
-
-After thinking about the above you'll probably want to configure the
-misdn.conf file which resides in the asterisk config directory (normally
-/etc/asterisk).
-
-- misdn.conf: [general]
-The misdn.conf file contains a "general" Section, and user sections which
-contain misdn port settings and different Asterisk contexts.
-
-The general section contains especially a variable named context with which
-the default context is set. There is also the very important debug variable
-which you can set from the Asterisk cli (command line interface) or in this
-configuration file, bigger numbers will lead to more debug output. There's also a
-tracefile option, which takes a path+filename where debug output is written
-to.
-
-- misdn.conf: [default] section
-The default section is another special section which can contain all the
-options available int the usr/port sections. the user/port section inherit
-their parameters from the default section.
-
-- misdn.conf: user/port sections
-The user sections have names which are unequal to "general". Those sections
-contain the ports variable which mean the mISDN Ports. Here you can add
-multiple ports, comma separated.
-
-Espacially for TE-Mode Ports there is a msns variable. This variable tells the
-chan_misdn driver to listen for incomming calls with the given msns, you can
-insert a '*' as single msn, which leads in getting every incoming call (if
-you want to share on PMP TE S0 with a asterisk and a phone or isdn card you
-should insert here the msns which you'll like to give the Asterisk). Finally
-a context variable resides in the user sections, which tells chan_misdn where
-to send incoming calls to in the Asterisk dial plan (extension.conf).
-
-In NT-Mode Ports there is a new option, directly after the port number you can
-write ptp, this enables PP Mode for this port, please look at misdn.conf.sample for
-an example.
-
-
-Dial and Options String
------------------------
-
-The dial string of chan_misdn got more complex, because we added more features,
-so the generic dial string looks like:
-
-mISDN/<port>|g:<group>/<extension>[/<OPTIONSSTRING>]
-
-The Optionsstring looks Like:
-:<optchar1><OptParam1>:<optchar2><OptParam2>
-
-the ":" character is the delimiter.
-
-The available Optchars are:
- d - Send display text on called phone, text is the optparam
- n - don't detect dtmf tones on called channel
- h - make digital outgoing call
- c - make crypted outgoing call, param is keyindex
- e - perform echo cancelation on this channel,
- takes taps as arguments (32,64,128,256)
- s - send Non Inband DTMF as inband
- vr - rxgain control
- vt - txgain control
-
-
-chan_misdn registers a new dial plan application "misdn_set_opt" when
-loaded. This application takes the Optionsstring as argument. The Syntax is:
-
-misdn_set_opt(<OPTIONSSTRING>)
-
-
-When you set options in the dialstring, the options are set in the external
-channel. When you set options with misdn_set_opt, they are set in the current
-incoming channel. So if you like to use static encryption, the scenario looks
-as follows:
-
-Phone1 --> * Box 1 --> PSTN_TE
-PSTN_TE --> * Box 2 --> Phone2
-
-The Encryption must be done on the PSTN sides, so the dialplan on the boxes
-are:
-
-* Box 1:
-exten => _${CRYPT_PREFIX}X.,1,Dial(mISDN/g:outbound/:c1)
-
-* Box 2:
-exten => ${CRYPT_MSN},1,misdn_set_opt(:c1)
-exten => ${CRYPT_MSN},2,dial(${PHONE2})
-
-
-
-
-misdn cli commands
-------------------
-
-At the Asterisk cli you can try to type in:
-
-misdn <tab> <tab>
-
-Now you should see the misdn cli commands:
-
-- clean
- -> pid (cleans a broken call, use with care, leads often
- to a segmentation fault)
-- send
- -> display (sends a Text Message to a Asterisk channel,
- this channel must be an misdn channel)
-- set
- -> debug (sets debug level)
-- show
- -> config (shows the configuration options)
- -> channels (shows the current active misdn channels)
- -> channel (shows details about the given misdn channels)
- -> stacks (shows the currend ports, there protocols and states)
- -> fullstacks (shows the current active and inactive misdn channels)
-
-- restart
- -> port (restarts given port (L2 Restart) )
-
-- reload (reloads misdn.conf)
-
-You can only use "misdn send display" when an Asterisk channel is created and
-isdn is in the correct state. "correct state" means that you have established a
-call to another phone (mustn't be isdn though).
-
-Then you use it like this:
-
-misdn send display mISDN/1/101 "Hello World!"
-
-where 1 is the Port of the Card where the phone is plugged in, and 101 is the
-msn (callerid) of the Phone to send the text to.
-
-
-
-Debugging and sending bug reports
----------------------------------
-
-If you encounter problems, you should set up the debugging flag, usually debug=1
-should be enough. the messages are divided in asterisk and misdn parts.
-Misdn Debug messages begin with an 'I', asterisk messages begin with an '*',
-the rest is clear I think.
-
-Please take a trace of the problem and open a report in the Asterisk issue
-tracker at http://bugs.digium.com in the "channel drivers" project,
-"chan_misdn" category. Read the bug guidelines to make sure you
-provide all the information needed.
-
-
-Examples
---------
-
-Here are some examples of how to use chan_misdn in the dialplan (extensions.conf):
-
-
-[globals]
-OUT_PORT=1 ; The physical Port of the Card
-OUT_GROUP=ExternE1 ; The Group of Ports defined in misdn.conf
-
-[misdnIn]
-exten => _X.,1,Dial(mISDN/${OUT_PORT}/${EXTEN})
-exten => _0X.,1,Dial(mISDN/g:${OUT_GROUP}/${EXTEN:1})
-exten => _1X.,1,Dial(mISDN/g:${OUT_GROUP}/${EXTEN:1}/:dHello)
-exten => _1X.,1,Dial(mISDN/g:${OUT_GROUP}/${EXTEN:1}/:dHello Test:n)
-
-In the last line you will notice the last argument (Hello), this is sended
-as Display Message to the Phone.
-
-
-Known working configurations
-----------------------------
-
-In this section I'll put working configurations for chan_misdn. Beware It
-seems that between Kernel 2.6.3 and Kernel 2.6.8 there were lots of mISDN
-Bugs. I use Kernel 2.6.9 now, it works quite ok, Kernel 2.6.10+ has changed
-the pci_find_subgsys funktion, so hfc_multi from mISDN doesn't compile against
-it, you can just change pci_find_subsys to pci_get_subsys, this works.
-
-
-- chan_misdn-0.0.3-rc1:
- * linux-kernel >= 2.6.3 (but at least 2.6)
- * asterisk >= v1-0
- * mISDN/mISDNuser since September/04
-
-- chan_misdn-0.0.3-rc3:
- * linux-kernel >= 2.6.3 (but at least 2.6)
- * asterisk >= v1-0.2
- * mISDN/mISDNuser since December/04
-
-- chan_misdn-0.0.3-rc4:
- * linux-kernel >= 2.6.8 (but at least 2.6)
- * asterisk >= v1-0.2
- * mISDN/mISDNuser head on cvs.isdn4linux.de
-
-- chan_misdn-0.0.3-rc6:
- * linux-kernel >= 2.6.8 (but at least 2.6)
- * asterisk >= v1-0.2
- * mISDN/mISDNuser head on cvs.isdn4linux.de
-
-- chan_misdn-0.1.0
- * linux-kernel >= 2.6.8 (but at least 2.6)
- * asterisk >= v1-0.2 , also CVS Head
- * mISDN/mISDNuser (3.0-beta) from isdn.jolly.de
-
-- chan_misdn-0.2.1
- * linux-kernel >= 2.6.8 (but at least 2.6)
- * asterisk >= v1.2 , also CVS Head
- * mISDN/mISDNuser (3.0) from isdn.jolly.de
-
-
-Known Problems
---------------
-
-* When I use mISDN->IAX I cannot make Trunk calls
-
--> You need to use ztdummy as dummy zaptel interface for the iax timing in
-trunking mode, simply grab libpri, zaptel and compile them (i think you need
-to modify the makefile in zaptel to add ztdummy to the defaultly compiled
-modules) then modprobe ztdummy, this resolves the problem.
-
-
-* I cannot hear any tone after succesfull CONNECT to other end
-
--> you forgot to load mISDNdsp, which is now needed by chan_misdn for switching
-and dtmf tone detection
-
-* I have strange ISDN behavior: sometimes I hear the other end, sometimes
-not. Also I get STATUS Events with cause 100, with misdn debugging
-
--> Please update to newest version of chan_misdn and set the te_choose_channel
-option in misdn.conf to yes
-
-Changes
--------
-in the Changes File
-
diff --git a/1.2-netsec/doc/README.mp3 b/1.2-netsec/doc/README.mp3
deleted file mode 100644
index 5c7ca16c7..000000000
--- a/1.2-netsec/doc/README.mp3
+++ /dev/null
@@ -1,19 +0,0 @@
-* Asterisk MP3 Support
-======================
-
-* MP3 Music On Hold
-Asterisk supports mp3 playback for music on hold via the mpg123
-program, available from www.mpg123.de.
-
-The latest release of mpg123 is mpg123 0.59r.
-The latest development release of mpg123 is mpg123 pre0.59s.
-
-Please use mpg123 0.59r. Using mpg123 pre0.59s can/may/will result
-in crashes and/or unreliable playback.
-
-Running "make mpg123" in the Asterisk source directory will
-download and make the working version.
-
-* MP3 Format driver
-A format driver for reading MP3 audio files is available
-in the asterisk-addons SVN repository on svn.digium.com
diff --git a/1.2-netsec/doc/README.mysql b/1.2-netsec/doc/README.mysql
deleted file mode 100644
index 27adaa956..000000000
--- a/1.2-netsec/doc/README.mysql
+++ /dev/null
@@ -1,15 +0,0 @@
-MYSQL LICENSING UPDATE
-======================
-We were recently contacted by MySQL and informed that the MySQL client
-libraries are now under GPL license and not LGPL license as before.
-
-Since Asterisk does allow exceptions to GPL, we are removing MySQL support
-from standard Asterisk. We will, where appropriate, make it available via
-a separate package which will only be usable when Asterisk is used completely
-within GPL (i.e. not in conjunction with G.729, OpenH.323, etc). We
-apologize for the confusion.
-
-You may find this in the new "asterisk-addons" package.
-
-Mark Spencer
-Digium
diff --git a/1.2-netsec/doc/README.odbcstorage b/1.2-netsec/doc/README.odbcstorage
deleted file mode 100644
index 2cba0b4b9..000000000
--- a/1.2-netsec/doc/README.odbcstorage
+++ /dev/null
@@ -1,33 +0,0 @@
-ODBC Voicemail Storage
-======================
-
-ODBC Storage allows you to store voicemail messages within a database
-instead of using a file. This is *not* a full realtime engine and
-*only* supports ODBC. The table description for the "voicemessages"
-table is as follows:
-
-+----------------+-------------+------+-----+---------+-------+
-| Field | Type | Null | Key | Default | Extra |
-+----------------+-------------+------+-----+---------+-------+
-| msgnum | int(11) | YES | | NULL | |
-| dir | varchar(80) | YES | MUL | NULL | |
-| context | varchar(80) | YES | | NULL | |
-| macrocontext | varchar(80) | YES | | NULL | |
-| callerid | varchar(40) | YES | | NULL | |
-| origtime | varchar(40) | YES | | NULL | |
-| duration | varchar(20) | YES | | NULL | |
-| mailboxuser | varchar(80) | YES | | NULL | |*
-| mailboxcontext | varchar(80) | YES | | NULL | |*
-| recording | longblob | YES | | NULL | |
-+----------------+-------------+------+-----+---------+-------+
-
-*=Denotes new fieldnames, define EXTENDED_ODBC_STORAGE in
-apps/Makefile to enable the functionality.
-
-The database name (from /etc/asterisk/res_odbc.conf) is in the
-"odbcstorage" variable in the general section of voicemail.conf.
-
-You may modify the voicemessages table name by using
-odbctable=??? in voicemail.conf
-
-
diff --git a/1.2-netsec/doc/README.privacy b/1.2-netsec/doc/README.privacy
deleted file mode 100644
index 3a990fa4b..000000000
--- a/1.2-netsec/doc/README.privacy
+++ /dev/null
@@ -1,361 +0,0 @@
-Title: Everything About The Privacy Options In The Dial Command That
-You Never Wanted To Know, And Even A Little More On Zapateller and
-PrivacyManager:
-
-by Steve Murphy
-
-
-So, you want to avoid talking to pesky telemarketers/charity
-seekers/poll takers/magazine renewers/etc?
-
-=============
-First of all:
-=============
-
-Try the FTC "Don't call" database, this alone will reduce your
-telemarketing call volume considerably. (see:
-https://www.donotcall.gov/default.aspx ) But, this list won't protect
-from the Charities, previous business relationships, etc.
-
-
-=================================
-Next, Fight against autodialers!!
-=================================
-
-Zapateller detects if callerid is present, and if not, plays the
-da-da-da tones that immediately precede messages like, "I'm sorry,
-the number you have called is no longer in service."
-
-Most humans, even those with unlisted/callerid-blocked numbers, will
-not immediately slam the handset down on the hook the moment they hear
-the three tones. But autodialers seem pretty quick to do this.
-
-I just counted 40 hangups in Zapateller over the last year in my
-CDR's. So, that is possibly 40 different telemarketers/charities that have
-hopefully slashed my back-waters, out-of-the-way, humble home phone
-number from their lists.
-
-I highly advise Zapateller for those seeking the nirvana of "privacy".
-
-
-=======================================
-Next, Fight against the empty CALLERID!
-=======================================
-
-A considerable percentage of the calls you don't want, come from
-sites that do not provide CallerID.
-
-Null callerid's are a fact of life, and could be a friend with an
-unlisted number, or some charity looking for a handout. The
-PrivacyManager application can help here. It will ask the caller to
-enter a 10-digit phone number. They get 3 tries(configurable), and this is
-configurable, with control being passed to priority+101 if they won't
-supply one.
-
-PrivacyManager can't guarantee that the number they supply is any
-good, tho, as there is no way to find out, short of hanging up and
-calling them back. But some answers are obviously wrong. For instance,
-it seems a common practice for telemarketers to use your own number
-instead of giving you theirs. A simple test can detect this. More
-advanced tests would be to look for -555- numbers, numbers that count
-up or down, numbers of all the same digit, etc.
-
-My logs show that 39 have hung up in the PrivacyManager script over
-the last year.
-
-(Note: Demanding all unlisted incoming callers to enter their CID may
-not always be appropriate for all users. Another option might be to
-use call screening. See below.)
-
-==========================
-Next, use a WELCOME MENU !
-==========================
-
-Experience has shown that simply presenting incoming callers with
-a set of options, no matter how simple, will deter them from calling
-you. In the vast majority of situations, a telemarketer will simply
-hang up rather than make a choice and press a key.
-
-This will also immediately foil all autodialers that simply belch a
-message in your ear and hang up.
-
-
-----------------------------------------------
-Example usage of Zapateller and PrivacyManager:
-----------------------------------------------
-
-[homeline]
-exten => s,1,Answer
-exten => s,2,SetVar,repeatcount=0
-exten => s,3,Zapateller,nocallerid
-exten => s,4,PrivacyManager
-exten => s,105,Background(tt-allbusy) ;; do this if they don't enter a number to Privacy Manager
-exten => s,106,Background(tt-somethingwrong)
-exten => s,107,Background(tt-monkeysintro)
-exten => s,108,Background(tt-monkeys)
-exten => s,109,Background(tt-weasels)
-exten => s,110,Hangup
-exten => s,5,GotoIf($[ "${CALLERIDNUM}" = "7773334444" & "${CALLERIDNAME}" : "Privacy Manager" ]?callerid-liar|s|1:s|7)
-
-I suggest using Zapateller at the beginning of the context, before
-anything else, on incoming calls.This can be followed by the
-PrivacyManager App.
-
-Make sure, if you do the PrivacyManager app, that you take care of the
-error condition! or their non-compliance will be rewarded with access
-to the system. In the above, if they can't enter a 10-digit number in
-3 tries, they get the humorous "I'm sorry, but all household members
-are currently helping other telemarketers...", "something is terribly
-wrong", "monkeys have carried them away...", various loud monkey
-screechings, "weasels have...", and a hangup. There are plenty of
-other paths to my torture scripts, I wanted to have some fun.
-
-In nearly all cases now, the telemarketers/charity-seekers that
-usually get thru to my main intro, hang up. I guess they can see it's
-pointless, or the average telemarketer/charity-seeker is instructed
-not to enter options when encountering such systems. Don't know.
-
-===================
-Next: Torture Them!
-===================
-
-I have developed an elaborate script to torture Telemarketers, and
-entertain friends. (See
-http://www.voip-info.org/wiki-Asterisk+Telemarketer+Torture )
-
-While mostly those that call in and traverse my teletorture scripts
-are those we know, and are doing so out of curiosity, there have been
-these others from Jan 1st,2004 thru June 1st, 2004:
-(the numbers may or may not be correct.)
-
-603890zzzz hung up telemarket options.
-"Integrated Sale" called a couple times. hung up in telemarket options
-"UNITED STATES GOV" (-- maybe a military recruiter, trying to lure one of my sons).
-800349zzzz -- hung up in charity intro
-800349zzzz -- hung up in charity choices, intro, about the only one who actually travelled to the bitter bottom of the scripts!
-216377zzzz -- hung up the magazine section
-626757zzzz = "LIR " (pronounced "Liar"?) hung up in telemarket intro, then choices
-757821zzzz -- hung up in new magazine subscription options.
-
-That averages out to maybe 1 a month. That puts into question whether
-the ratio of the amount of labor it took to make the scripts versus
-the benefits of lower call volumes was worth it, but, well, I had fun,
-so what the heck.
-
-but, that's about it. Not a whole lot. But I haven't had to say "NO"
-or "GO AWAY" to any of these folks for about a year now ...!
-
-========================================
- Using Call Screening
-=======================================
-
-Another option is to use call screening in the Dial command. It has
-two main privacy modes, one that remembers the CID of the caller, and
-how the callee wants the call handled, and the other, which does not
-have a "memory".
-
-Turning on these modes in the dial command results in this sequence of
-events, when someone calls you at an extension:
-
-1. The caller calls the Asterisk system, and at some point, selects an
-option or enters an extension number that would dial your extension.
-
-2. Before ringing your extension, the caller is asked to supply an
-introduction. The application asks them: "After the tone, say your
-name". They are allowed 4 seconds of introduction.
-
-3. After that, they are told "Hang on, we will attempt to connect you
-to your party. Depending on your dial options, they will hear ringing
-indications, or get music on hold. I suggest music on hold.
-
-4. Your extension is then dialed. When (and if) you pick up, you are
-told that a caller presenting themselves as <their recorded intro is
-played> is calling, and you have options, like being connected,
-sending them to voicemail, torture, etc.
-
-5. You make your selection, and the call is handled as you chose.
-
-
-There are some variations, and these will be explained in due course.
-
-
-To use these options, set your Dial to something like:
-
-exten => 3,3,Dial(Zap/5r3&Zap/6r3|35|tmPA(beep))
-
-or
-
-exten => 3,3,Dial(Zap/5r3&Zap/6r3|35|tmP(something)A(beep))
-
-or
-
-exten => 3,3,Dial(Zap/5r3&Zap/6r3|35|tmpA(beep))
-
-
-The 't' allows the dialed party to transfer the call using '#'. It's
-optional.
-
-The 'm' is for music on hold. I suggest it. Otherwise, the calling
-party gets to hear all the ringing, and lack thereof. It is generally
-better to use Music On Hold. Lots of folks hang up after the 3rd or
-4th ring, and you might lose the call before you can enter an option!
-
-The 'P' option alone will database everything using the extension as a
-default 'tree'. To get multiple extensions sharing the same database, use
-P(some-shared-key). Also, if the same person has multiple extensions,
-use P(unique-id) on all their dial commands.
-
-Use little 'p' for screening. Every incoming call will include a
-prompt for the callee's choice.
-
-the A(beep), will generate a 'beep' that the callee will hear if they
-choose to talk to the caller. It's kind of a prompt to let the callee
-know that he has to say 'hi'. It's not required, but I find it
-helpful.
-
-When there is no CallerID, P and p options will always record an intro
-for the incoming caller. This intro will be stored temporarily in the
-/var/lib/asterisk/sounds/priv-callerintros dir, under the name
-NOCALLERID_<extension><channelname> and will be erased after the
-callee decides what to do with the call.
-
-Of course, NOCALLERID is not stored in the database. All those with no
-CALLERID will be considered "Unknown".
-
-========================
- The 'N' and 'n' options
-========================
-
-Two other options exist, that act as modifiers to the privacy options
-'P' and 'p'. They are 'N' and 'n'. You can enter them as dialing
-options, but they only affect things if P or p are also in the
-options.
-
-'N' says, "Only screen the call if no CallerID is present". So, if a
-callerID were supplied, it will come straight thru to your extension.
-
-'n' says, "Don't save any introductions". Folks will be asked to
-supply an introduction ("At the tone, say your name") every time they
-call. Their introductions will be removed after the callee makes a
-choice on how to handle the call. Whether the P option or the p option
-is used, the incoming caller will have to supply their intro every
-time they call.
-
-=======================
-Recorded Introductions
-=======================
-
-[Philosophical Side Note:
-The 'P' option stores the CALLERID in the database, along with the
-callee's choice of actions, as a convenience to the CALLEE, whereas
-introductions are stored and re-used for the convenience of the CALLER.]
-
-Unless instructed to not save introductions (see the 'n' option above),
-the screening modes will save the recordings of the caller's names in
-the directory /var/lib/asterisk/sounds/priv-callerintros, if they have
-a CallerID. Just the 10-digit callerid numbers are used as filenames,
-with a ".gsm" at the end.
-
-Having these recordings around can be very useful, however...
-
-First of all, if a callerid is supplied, and a recorded intro for that
-number is already present, the caller is spared the inconvenience of
-having to supply their name, which shortens their call a bit.
-
-Next of all, these intros can be used in voicemail, played over
-loudspeakers, and perhaps other nifty things. For instance:
-
-exten => s,7,System(/usr/bin/play /var/lib/asterisk/sounds/priv-callerintros/${CALLERIDNUM}.gsm&|0)
-
-When a call comes in at the house, the above priority gets executed,
-and the callers intro is played over the phone systems speakers. This
-gives us a hint who is calling.
-
-(Note: the |0 option at the end of the System command above, is a
-local mod I made to the System command. It forces a 0 result code to
-be returned, whether the play command successfully completed or
-not. Therefore, I don't have to ensure that the file exists or
-not. While I've turned this mod into the developers, it hasn't been
-incorporated yet. You might want to write an AGI or shell script to
-handle it a little more intelligently)
-
-And one other thing. You can easily supply your callers with an option
-to listen to, and re-record their introductions. Here's what I did in
-the home system's extensions.conf. (assume that a
-Goto(home-introduction|s|1) exists somewhere in your main menu as an
-option):
-
-[home-introduction]
-exten => s,1,Background,intro-options ;; Script: To hear your Introduction, dial 1.
- ;; to record a new introduction, dial 2.
- ;; to return to the main menu, dial 3.
- ;; to hear what this is all about, dial 4.
-exten => 1,1,Playback,priv-callerintros/${CALLERIDNUM}
-exten => 1,2,Goto(s,1)
-exten => 2,1,Goto(home-introduction-record,s,1)
-exten => 3,1,Goto(homeline,s,7)
-exten => 4,1,Playback,intro-intro ;; Script:
- ;; This may seem a little strange, but it really is a neat
- ;; thing, both for you and for us. I've taped a short introduction
- ;; for many of the folks who normally call us. Using the Caller ID
- ;; from each incoming call, the system plays the introduction
- ;; for that phone number over a speaker, just as the call comes in.
- ;; This helps the folks
- ;; here in the house more quickly determine who is calling.
- ;; and gets the right ones to gravitate to the phone.
- ;; You can listen to, and record a new intro for your phone number
- ;; using this menu.
-exten => 4,2,Goto(s,1)
-exten => t,1,Goto(s,1)
-exten => i,1,Background,invalid
-exten => i,2,Goto(s,1)
-exten => o,1,Goto(s,1)
-
-[home-introduction-record]
-exten => s,1,Background,intro-record-choices ;; Script:
- ;; If you want some advice about recording your
- ;; introduction, dial 1.
- ;; otherwise, dial 2, and introduce yourself after
- ;; the beep.
-exten => 1,1,Playback,intro-record
- ;; Your introduction should be short and sweet and crisp.
- ;; Your introduction will be limited to 4 seconds.
- ;; This is NOT meant to be a voice mail message, so
- ;; please, don't say anything about why you are calling.
- ;; After we are done making the recording, your introduction
- ;; will be saved for playback.
- ;; If you are the only person that would call from this number,
- ;; please state your name. Otherwise, state your business
- ;; or residence name instead. For instance, if you are
- ;; friend of the family, say, Olie McPherson, and both
- ;; you and your kids might call here a lot, you might
- ;; say: "This is the distinguished Olie McPherson Residence!"
- ;; If you are the only person calling, you might say this:
- ;; "This is the illustrious Kermit McFrog! Pick up the Phone, someone!!"
- ;; If you are calling from a business, you might pronounce a more sedate introduction,like,
- ;; "Fritz from McDonalds calling.", or perhaps the more original introduction:
- ;; "John, from the Park County Morgue. You stab 'em, we slab 'em!".
- ;; Just one caution: the kids will hear what you record every time
- ;; you call. So watch your language!
- ;; I will begin recording after the tone.
- ;; When you are done, hit the # key. Gather your thoughts and get
- ;; ready. Remember, the # key will end the recording, and play back
- ;; your intro. Good Luck, and Thank you!"
-exten => 1,2,Goto(2,1)
-exten => 2,1,Background,intro-start
- ;; OK, here we go! After the beep, please give your introduction.
-exten => 2,2,Background,beep
-exten => 2,3,Record,priv-callerintros/${CALLERIDNUM}:gsm|4
-exten => 2,4,Background,priv-callerintros/${CALLERIDNUM}
-exten => 2,5,Goto(home-introduction,s,1)
-exten => t,1,Goto(s,1)
-exten => i,1,Background,invalid
-exten => i,2,Goto(s,1)
-exten => o,1,Goto(s,1)
-
-
-In the above, you'd most likely reword the messages to your liking,
-and maybe do more advanced things with the 'error' conditions (i,o,t priorities),
-but I hope it conveys the idea...
-
-
diff --git a/1.2-netsec/doc/README.realtime b/1.2-netsec/doc/README.realtime
deleted file mode 100644
index 1de651cd0..000000000
--- a/1.2-netsec/doc/README.realtime
+++ /dev/null
@@ -1,111 +0,0 @@
-The Asterisk Realtime Architecture
-----------------------------------
-
-The Asterisk Realtime Architecture is a new set of drivers and
-functions implemented in Asterisk 1.2. The benefits of this
-architecture are many, both from a code management
-standpoint and from an installation perspective.
-
-Additional information on the configuration of Realtime with Asterisk
-can be found in README.extconfig
-
-The ARA is designed to be independent of storage. Currently, most
-drivers are based on SQL, but the architecture should be able to handle
-other storage methods in the future, like LDAP.
-
-The main benefit comes in the database support. In Asterisk v1.0 some
-functions supported MySQL database, some PostgreSQL and other ODBC.
-With the ARA, we have a unified database interface internally in Asterisk,
-so if one function supports database integration, all databases that has a
-realtime driver will be supported in that function.
-
-Currently there are three realtime database drivers:
-
-* ODBC: Support for UnixODBC, integrated into Asterisk
- The UnixODBC subsystem supports many different databases,
- please check www.unixodbc.org for more information.
-* MySQL: Found in the asterisk-addons cvs archive on cvs.digium.com
-* Res_perl: Found in the asterisk-addons cvs archive on cvs.digium.com
-
-
-* Two modes: Static and Realtime
---------------------------------
-The ARA realtime mode is used to dynamically load and update objects.
-This mode is used in the SIP and IAX2 channels, as well as in the voicemail
-system. For SIP and IAX2 this is similar to the v1.0 MYSQL_FRIENDS
-functionality. With the ARA, we now support many more databases for
-dynamic configuration of phones.
-
-The ARA static mode is used to load configuration files. For the Asterisk
-modules that read configurations, there's no difference between a static
-file in the file system, like extensions.conf, and a configuration loaded
-from a database.
-
-* Realtime SIP friends
-----------------------
-The SIP realtime objects are users and peers that are loaded in memory
-when needed, then deleted. This means that Asterisk currently can't handle
-voicemail notification and NAT keepalives for these peers. Other than that,
-most of the functionality works the same way for realtime friends as for
-the ones in static configuration.
-
-There is some work to create a solution for Realtime SIP devices that
-loads from database and stays in memory for the duration of a call or
-a registration, but that work is not integrated into Asterisk yet.
-
-* New function in the dial plan: The Realtime Switch
-----------------------------------------------------
-The realtime switch is more than a port of functionality in v1.0 to the
-new architecture, this is a new feature of Asterisk based on the
-ARA. The realtime switch lets your Asterisk server do database lookups
-of extensions in realtime from your dial plan. You can have many Asterisk
-servers sharing a dynamically updated dial plan in real time with this
-solution.
-
-Note that this switch does _NOT_ support Caller ID matching, only
-extension name/pattern matching.
-
-* So what can you do?
----------------------
-The realtime Architecture lets you store all of your configuration in
-databases and reload it whenever you want. You can force a reload over
-the AMI, Asterisk Manager Interface or by calling Asterisk from a
-shell script with
- asterisk -rx "reload"
-
-You may also dynamically add SIP and IAX devices and extensions
-and making them available without a reload, by using the realtime
-objects and the realtime switch.
-
-
-* Configuration in extconfig.conf
----------------------------------
-You configure the ARA in extconfig.conf (yes, it's a strange name, but
-is was defined in the early days of the realtime architecture and kind
-of stuck). Please see README.extconfig for database schemas.
-
-The part of Asterisk that connects to the ARA use a well defined family
-name to find the proper database driver. The syntax is easy:
- <family> => <realtime driver>,<db name>[,<table>]
-
-The options following the realtime driver identified depends on the
-driver.
-
-Defined well-known family names are:
-
-* sippeers, sipusers SIP peers and users
-* iaxfriends IAX2 peers
-* voicemail Voicemail accounts
-
-There is documentation of the SQL database in the file
-README.extconfig in your Asterisk source code tree, the /doc
-directory.
-
-For voicemail storage with the support of ODBC, there is a
-README.odbcstorage documentation file.
-
-
-* FreeTDS not supported
------------------------
-Due to architectural constraints in the FreeTDS libraries, FreeTDS is not
-supported for use with realtime at this time.
diff --git a/1.2-netsec/doc/README.sms b/1.2-netsec/doc/README.sms
deleted file mode 100644
index 02e38764b..000000000
--- a/1.2-netsec/doc/README.sms
+++ /dev/null
@@ -1,147 +0,0 @@
-* The SMS application
----------------------
-SMS() is an application to handles calls to/from text message capable phones and
-message centres using ETSI ES 201 912 protocol 1 FSK messaging over analog calls.
-
-Basically it allows sending and receiving of text messages over the PSTN. It is
-compatible with BT Text service in the UK and works on ISDN and PSTN lines. It is
-designed to connect to an ISDN or zap interface directly and uses FSK so would
-probably not work over any sort of compressed link (like a VoIP call using GSM codec).
-
-Typical applications include:-
-
-1. Connection to a message centre to send text messages - probably initiated via the
- manager interface or "outgoing" directory
-2. Connection to an POTS line with an SMS capable phone to send messages - probably
- initiated via the manager interface or "outgoing" directory
-3. Acceptance of calls from the message centre (based on CLI) and storage of
- received messages
-4. Acceptance of calls from a POTS line with an SMS capable phone and storage of
- received messages
-
-* Arguments to sms():
-
-- First argument is queue name
-- Second is options:
- a: SMS() is to act as the answering side, and so send the initial FSK frame
- s: SMS() is to act as a service centre side rather than as terminal equipment
-
-- If a third argument is specified, then SMS does not handle the call at all,
- but takes the third argument as a destination number to send an SMS to
-- The forth argument onward is a message to be queued to the number in the
- third argument. All this does is create the file in the me-sc directory.
- If 's' is set then the number is the source
- address and the message placed in the sc-me directory.
-
-All text messages are stored in /var/spool/asterisk/sms
-A log is recorded in /var/log/asterisk/sms
-
-There are two subdirectories called sc-me.<queuename> holding all
-messages from service centre to phone, and me-sc.<queuename> holding all
-messages from phone to service centre.
-
-In each directory are messages in files, one per file, using any filename not
-starting with a dot.
-
-When connected as a service centre, SMS(s) will send all messages waiting in
-the sc-me-<queuename> directory, deleting the files as it goes. Any
-received in this mode are placed in the me-sc-<queuename> directory.
-
-When connected as a client, SMS() will send all messages waiting in the
-me-sc-<queuename> directory, deleting the files as it goes. Any received in
-this mode are placed in the sc-me-<queuename> directory.
-
-Message files created by SMS() use a time stamp/reference based filename.
-
-The format of the sms file is lines that have the form of key=value
-Keys are :
-
-oa Originating Address
- Telephone number, national number if just digits
- Telephone number starting with + then digits for international
- Ignored on sending messages to service centre (CLI used)
-da Destination Address
- Telephone number, national number if just digits
- Telephone number starting with + then digits for international
-scts Service Centre Time Stamp
- In the format YYYY-MM-DD HH:MM:SS
-pid Protocol Identifier (decimal octet value)
-dcs Data coding scheme (decimal octet value)
-mr Message reference (decimal octet value)
-ud The message (see escaping below)
-srr 0/1 Status Report Request
-rp 0/1 Return Path
-vp mins validity period
-
-Omitted fields have default values.
-
-Note that there is special format for ud, ud# instead of ud= which is followed
-by raw hex (2 characters per octet). This is used in output where characters
-other than 10,13,32-126,128-255 are included in the data. In this case a comment (line
-starting ;) is added showing the printable characters
-
-When generating files to send to a service centre, only da and ud need be
-specified. oa is ignored.
-
-When generating files to send to a phone, only oa and ud need be specified. da is ignored.
-
-When receing a message as a service centre, only the destination address is
-sent, so the originating address is set to the callerid.
-
-EXAMPLES
-
-The following are examples of use within the UK using BT Text SMS/landline
-service.
-
-This is a context to use with a manager script.
-
-[smsdial]
-; create and send a text message, expects number+message and
-; connect to 17094009
-exten => _X.,1,SMS(${CALLERIDNUM},,${EXTEN},${CALLERIDNAME})
-exten => _X.,n,SMS(${CALLERIDNUM})
-exten => _X.,n,Hangup
-
-The script sends
-
- action: originate
- callerid: message <from>
- exten: to
- channel: Local/17094009
- context: smsdial
- priority: 1
-
-You put the message as the name of the caller ID (messy, I know), the
-originating number and hence queue name as the number of the caller ID and the
-exten as the number to which the sms is to be sent. The context uses SMS to
-create the message in the queue and then SMS to communicate iwth 17094009 to
-actually send the message.
-
-Note that the 9 on the end of 17094009 is the sub address 9 meaning no sub
-address (BT specific). If a different digit is used then that is the sub
-address for the sending message source address (appended to the outgoing CLI
-by BT).
-
-For incoming calls you can use a context like this :-
-
-[incoming]
-exten => _XXXXXX/_8005875290,1,SMS(${EXTEN:3},a)
-exten => _XXXXXX/_8005875290,n,System(/usr/lib/asterisk/smsin ${EXTEN:3})
-exten => _XXXXXX/_80058752[0-8]0,1,SMS(${EXTEN:3}${CALLERIDNUM:8:1},a)
-exten => _XXXXXX/_80058752[0-8]0,n,System(/usr/lib/asterisk/smsin ${EXTEN>:3}${CALLERIDNUM:8:1})
-exten => _XXXXXX/_80058752[0-8]0,n,Hangup
-
-
-In this case the called number we get from BT is 6 digits (XXXXXX) and we are
-using the last 3 digits as the queue name.
-
-Priority 1 causes the SMS to be received and processed for the incoming call.
-It is from 080058752X0. The two versions handle the queue name as 3 digits (no
-sub address) or 4 digits (with sub address). In both cases, after the call a
-script (smsin) is run - this is optional, but is useful to actually processed
-the received queued SMS. In our case we email them based on the target number.
-Priority 3 hangs up.
-
-If using the CAPI drivers they send the right CLI and so the _800... would be
-_0800...
-
diff --git a/1.2-netsec/doc/README.tds b/1.2-netsec/doc/README.tds
deleted file mode 100644
index e1c27fba3..000000000
--- a/1.2-netsec/doc/README.tds
+++ /dev/null
@@ -1,18 +0,0 @@
-PLEASE NOTE
-
-The cdr_tds module is NOT compatible with version 0.63 of FreeTDS.
-
-The cdr_tds module is known to work with FreeTDS version 0.62.1;
-it should also work with 0.62.2, 0.62.3 and 0.62.4, which are bug
-fix releases.
-
-The cdr_tds module uses the raw "libtds" API of FreeTDS. It appears
-that from 0.63 onwards, this is not considered a published API
-of FreeTDS and is subject to change without notice.
-
-Between 0.62.x and 0.63 of FreeTDS, many incompatible changes
-have been made to the libtds API.
-
-For newer versions of FreeTDS, it is recommended that you use the
-ODBC driver.
-
diff --git a/1.2-netsec/doc/README.variables b/1.2-netsec/doc/README.variables
deleted file mode 100644
index 8d7b8ec61..000000000
--- a/1.2-netsec/doc/README.variables
+++ /dev/null
@@ -1,792 +0,0 @@
-----------------------------
-Asterisk dial plan variables
-----------------------------
-
-There are two levels of parameter evaluation done in the Asterisk
-dial plan in extensions.conf.
-* The first, and most frequently used, is the substitution of variable
- references with their values.
-* Then there are the evaluations of expressions done in $[ .. ].
- This will be discussed below.
-
-Asterisk has user-defined variables and standard variables set
-by various modules in Asterisk. These standard variables are
-listed at the end of this document.
-
-___________________________
-PARAMETER QUOTING:
----------------------------
-
-exten => s,5,BackGround,blabla
-
-The parameter (blabla) can be quoted ("blabla"). In this case, a
-comma does not terminate the field. However, the double quotes
-will be passed down to the Background command, in this example.
-
-Also, characters special to variable substitution, expression evaluation, etc
-(see below), can be quoted. For example, to literally use a $ on the
-string "$1231", quote it with a preceding \. Special characters that must
-be quoted to be used, are [ ] $ " \. (to write \ itself, use \\).
-
-These Double quotes and escapes are evaluated at the level of the
-asterisk config file parser.
-
-Double quotes can also be used inside expressions, as discussed below.
-
-___________________________
-VARIABLES:
----------------------------
-
-Parameter strings can include variables. Variable names are arbitrary strings.
-They are stored in the respective channel structure.
-
-To set a variable to a particular value, do :
-
- exten => 1,2,Set(varname=value)
-
-You can substitute the value of a variable everywhere using ${variablename}.
-For example, to stringwise append $lala to $blabla and store result in $koko,
-do:
-
- exten => 1,2,Set(koko=${blabla}${lala})
-
-
-There are two reference modes - reference by value and reference by name.
-To refer to a variable with its name (as an argument to a function that
-requires a variable), just write the name. To refer to the variable's value,
-enclose it inside ${}. For example, Set takes as the first argument
-(before the =) a variable name, so:
-
- exten => 1,2,Set(koko=lala)
- exten => 1,3,Set(${koko}=blabla)
-
-stores to the variable "koko" the value "lala" and to variable "lala" the
-value "blabla".
-
-In fact, everything contained ${here} is just replaced with the value of
-the variable "here".
-
-____________________
-VARIABLE INHERITANCE
---------------------
-
-Variable names which are prefixed by "_" will be inherited to channels
-that are created in the process of servicing the original channel in
-which the variable was set. When the inheritance takes place, the
-prefix will be removed in the channel inheriting the variable. If the
-name is prefixed by "__" in the channel, then the variable is
-inherited and the "__" will remain intact in the new channel.
-
-In the dialplan, all references to these variables refer to the same
-variable, regardless of having a prefix or not. Note that setting any
-version of the variable removes any other version of the variable,
-regardless of prefix.
-
-Example:
-
-Set(__FOO=bar) ; Sets an inherited version of "FOO" variable
-Set(FOO=bar) ; Removes the inherited version and sets a local
- ; variable.
-
-However,
-
-NoOp(${__FOO}) is identical to NoOp(${FOO})
-
-
-
-___________________________________
-SELECTING CHARACTERS FROM VARIABLES
------------------------------------
-
-The format for selecting characters from a variable can be expressed as:
-
- ${variable_name[:offset[:length]]}
-
-If you want to select the first N characters from the string assigned
-to a variable, simply append a colon and the number of characters to
-skip from the beginning of the string to the variable name.
-
- ;Remove the first character of extension, save in "number" variable
- exten => _9X.,1,Set(number=${EXTEN:1})
-
-Assuming we've dialed 918005551234, the value saved to the 'number' variable
-would be 18005551234. This is useful in situations when we require users to
-dial a number to access an outside line, but do not wish to pass the first
-digit.
-
-If you use a negative offset number, Asterisk starts counting from the end
-of the string and then selects everything after the new position. The following
-example will save the numbers 1234 to the 'number' variable, still assuming
-we've dialed 918005551234.
-
- ;Remove everything before the last four digits of the dialed string
- exten => _9X.,1,Set(number=${EXTEN:-4})
-
-We can also limit the number of characters from our offset position that we
-wish to use. This is done by appending a second colon and length value to the
-variable name. The following example will save the numbers 555 to the 'number'
-variable.
-
- ;Only save the middle numbers 555 from the string 918005551234
- exten => _9X.,1,Set(number=${EXTEN:5:3})
-
-The length value can also be used in conjunction with a negative offset. This
-may be useful if the length of the string is unknown, but the trailing digits
-are. The following example will save the numbers 555 to the 'number' variable,
-even if the string starts with more characters than expected (unlike the
-previous example).
-
- ;Save the numbers 555 to the 'number' variable
- exten => _9X.,1,Set(number=${EXTEN:-7:3})
-
-If a negative length value is entered, it is ignored and Asterisk will match
-to the end of the string.
-___________________________
-EXPRESSIONS:
----------------------------
-
-Everything contained inside a bracket pair prefixed by a $ (like $[this]) is
-considered as an expression and it is evaluated. Evaluation works similar to
-(but is done on a later stage than) variable substitution: the expression
-(including the square brackets) is replaced by the result of the expression
-evaluation.
-
-For example, after the sequence:
-
-exten => 1,1,Set(lala=$[1 + 2])
-exten => 1,2,Set(koko=$[2 * ${lala}])
-
-the value of variable koko is "6".
-
-and, further:
-
-exten => 1,1,Set,(lala=$[ 1 + 2 ]);
-
-will parse as intended. Extra spaces are ignored.
-
-
-______________________________
-SPACES INSIDE VARIABLE VALUES
-------------------------------
-If the variable being evaluated contains spaces, there can be problems.
-
-For these cases, double quotes around text that may contain spaces
-will force the surrounded text to be evaluated as a single token.
-The double quotes will be counted as part of that lexical token.
-
-As an example:
-
-exten => s,6,GotoIf($[ "${CALLERIDNAME}" : "Privacy Manager" ]?callerid-liar|s|1:s|7)
-
-The variable CALLERIDNAME could evaluate to "DELOREAN MOTORS" (with a space)
-but the above will evaluate to:
-
-"DELOREAN MOTORS" : "Privacy Manager"
-
-and will evaluate to 0.
-
-The above without double quotes would have evaluated to:
-
-DELOREAN MOTORS : Privacy Manager
-
-and will result in syntax errors, because token DELOREAN is immediately
-followed by token MOTORS and the expression parser will not know how to
-evaluate this expression, because it does not match its grammar.
-
-_____________________
-OPERATORS
----------------------
-Operators are listed below in order of increasing precedence. Operators
-with equal precedence are grouped within { } symbols.
-
- expr1 | expr2
- Return the evaluation of expr1 if it is neither an empty string
- nor zero; otherwise, returns the evaluation of expr2.
-
- expr1 & expr2
- Return the evaluation of expr1 if neither expression evaluates to
- an empty string or zero; otherwise, returns zero.
-
- expr1 {=, >, >=, <, <=, !=} expr2
- Return the results of integer comparison if both arguments are
- integers; otherwise, returns the results of string comparison
- using the locale-specific collation sequence. The result of each
- comparison is 1 if the specified relation is true, or 0 if the
- relation is false.
-
- expr1 {+, -} expr2
- Return the results of addition or subtraction of integer-valued
- arguments.
-
- expr1 {*, /, %} expr2
- Return the results of multiplication, integer division, or
- remainder of integer-valued arguments.
-
- - expr1
- Return the result of subtracting expr1 from 0.
- This, the unary minus operator, is right associative, and
- has the same precedence as the ! operator.
-
- ! expr1
- Return the result of a logical complement of expr1.
- In other words, if expr1 is null, 0, an empty string,
- or the string "0", return a 1. Otherwise, return a 0.
- It has the same precedence as the unary minus operator, and
- is also right associative.
-
- expr1 : expr2
- The `:' operator matches expr1 against expr2, which must be a
- regular expression. The regular expression is anchored to the
- beginning of the string with an implicit `^'.
-
- If the match succeeds and the pattern contains at least one regu-
- lar expression subexpression `\(...\)', the string correspond-
- ing to `\1' is returned; otherwise the matching operator
- returns the number of characters matched. If the match fails and
- the pattern contains a regular expression subexpression the null
- string is returned; otherwise 0.
-
- Normally, the double quotes wrapping a string are left as part
- of the string. This is disastrous to the : operator. Therefore,
- before the regex match is made, beginning and ending double quote
- characters are stripped from both the pattern and the string.
-
- expr1 =~ expr2
- Exactly the same as the ':' operator, except that the match is
- not anchored to the beginning of the string. Pardon any similarity
- to seemingly similar operators in other programming languages!
- The ":" and "=~" operators share the same precedence.
-
- expr1 ? expr2 :: expr3
- Traditional Conditional operator. If expr1 is a number
- that evaluates to 0 (false), expr3 is result of the this
- expression evaluation. Otherwise, expr2 is the result.
- If expr1 is a string, and evaluates to an empty string,
- or the two characters (""), then expr3 is the
- result. Otherwise, expr2 is the result. In Asterisk, all
- 3 exprs will be "evaluated"; if expr1 is "true", expr2
- will be the result of the "evaluation" of this
- expression. expr3 will be the result otherwise. This
- operator has the lowest precedence.
-
-Parentheses are used for grouping in the usual manner.
-
-Operator precedence is applied as one would expect in any of the C
-or C derived languages.
-
-Examples
-
- "One Thousand Five Hundred" =~ "(T[^ ]+)"
- returns: Thousand
-
- "One Thousand Five Hundred" =~ "T[^ ]+"
- returns: 8
-
- "One Thousand Five Hundred" : "T[^ ]+"
- returns: 0
-
- "8015551212" : "(...)"
- returns: 801
-
- "3075551212":"...(...)"
- returns: 555
-
- ! "One Thousand Five Hundred" =~ "T[^ ]+"
- returns: 0 (because it applies to the string, which is non-null,
- which it turns to "0", and then looks for the pattern
- in the "0", and doesn't find it)
-
- !( "One Thousand Five Hundred" : "T[^ ]+" )
- returns: 1 (because the string doesn't start with a word starting
- with T, so the match evals to 0, and the ! operator
- inverts it to 1 ).
-
- 2 + 8 / 2
- returns 6. (because of operator precedence; the division is done first, then the addition).
-
- 2+8/2
- returns 6. Spaces aren't necessary.
-
-(2+8)/2
- returns 5, of course.
-
-Of course, all of the above examples use constants, but would work the
-same if any of the numeric or string constants were replaced with a
-variable reference ${CALLERIDNUM}, for instance.
-
-__________________________
-NUMBERS VS STRINGS
---------------------------
-
-Tokens consisting only of numbers are converted to 64-bit numbers for
-most of the operators. This means that overflows can occur when the
-numbers get above 18 digits. Warnings will appear in the logs in this
-case.
-___________________________
-CONDITIONALS
----------------------------
-
-There is one conditional application - the conditional goto :
-
- exten => 1,2,gotoif(condition?label1:label2)
-
-If condition is true go to label1, else go to label2. Labels are interpreted
-exactly as in the normal goto command.
-
-"condition" is just a string. If the string is empty or "0", the condition
-is considered to be false, if it's anything else, the condition is true.
-This is designed to be used together with the expression syntax described
-above, eg :
-
- exten => 1,2,gotoif($[${CALLERID} = 123456]?2|1:3|1)
-
-Example of use :
-
-exten => s,2,Set(vara=1)
-exten => s,3,Set(varb=$[${vara} + 2])
-exten => s,4,Set(varc=$[${varb} * 2])
-exten => s,5,GotoIf($[${varc} = 6]?99|1:s|6)
-
-___________________________
-PARSE ERRORS
----------------------------
-
-Syntax errors are now output with 3 lines.
-
-If the extensions.conf file contains a line like:
-
-exten => s,6,GotoIf($[ "${CALLERIDNUM}" = "3071234567" & & "${CALLERIDNAME}" : "Privacy Manager" ]?callerid-liar|s|1:s|7)
-
-You may see an error in /var/log/asterisk/messages like this:
-
-Jul 15 21:27:49 WARNING[1251240752]: ast_yyerror(): syntax error: parse error, unexpected TOK_AND, expecting TOK_MINUS or TOK_LP or TOKEN; Input:
-"3072312154" = "3071234567" & & "Steves Extension" : "Privacy Manager"
- ^
-
-The log line tells you that a syntax error was encountered. It now
-also tells you (in grand standard bison format) that it hit an "AND"
-(&) token unexpectedly, and that was hoping for for a MINUS (-), LP
-(left parenthesis), or a plain token (a string or number).
-
-The next line shows the evaluated expression, and the line after
-that, the position of the parser in the expression when it became confused,
-marked with the "^" character.
-
-___________________________
-NULL STRINGS
----------------------------
-
-Testing to see if a string is null can be done in one of two different ways:
-
- exten => _XX.,1,GotoIf($["${calledid}" != ""]?3)
-
- exten => _XX.,1,GotoIf($[foo${calledid} != foo]?3)
-
-
-The second example above is the way suggested by the WIKI. It will
-work as long as there are no spaces in the evaluated value.
-
-The first way should work in all cases, and indeed, might now
-be the safest way to handle this situation.
-
-___________________________
-WARNING
----------------------------
-
-If you need to do complicated things with strings, asterisk expressions
-is most likely NOT the best way to go about it. AGI scripts are an
-excellent option to this need, and make available the full power of
-whatever language you desire, be it Perl, C, C++, Cobol, RPG, Java,
-Snobol, PL/I, Scheme, Common Lisp, Shell scripts, Tcl, Forth, Modula,
-Pascal, APL, assembler, etc.
-
-----------------------------
-INCOMPATIBILITIES
-----------------------------
-
-The asterisk expression parser has undergone some evolution. It is hoped
-that the changes will be viewed as positive.
-
-The "original" expression parser had a simple, hand-written scanner,
-and a simple bison grammar. This was upgraded to a more involved bison
-grammar, and a hand-written scanner upgraded to allow extra spaces,
-and to generate better error diagnostics. This upgrade required bison
-1.85, and part of the user community felt the pain of having to
-upgrade their bison version.
-
-The next upgrade included new bison and flex input files, and the makefile
-was upgraded to detect current version of both flex and bison, conditionally
-compiling and linking the new files if the versions of flex and bison would
-allow it.
-
-If you have not touched your extensions.conf files in a year or so, the
-above upgrades may cause you some heartburn in certain circumstances, as
-several changes have been made, and these will affect asterisk's behavior on
-legacy extension.conf constructs. The changes have been engineered
-to minimize these conflicts, but there are bound to be problems.
-
-The following list gives some (and most likely, not all) of areas
-of possible concern with "legacy" extension.conf files:
-
-1. Tokens separated by space(s).
- Previously, tokens were separated by spaces. Thus, ' 1 + 1 ' would evaluate
- to the value '2', but '1+1' would evaluate to the string '1+1'. If this
- behavior was depended on, then the expression evaluation will break. '1+1'
- will now evaluate to '2', and something is not going to work right.
- To keep such strings from being evaluated, simply wrap them in double
- quotes: ' "1+1" '
-
-2. The colon operator. In versions previous to double quoting, the
- colon operator takes the right hand string, and using it as a
- regex pattern, looks for it in the left hand string. It is given
- an implicit ^ operator at the beginning, meaning the pattern
- will match only at the beginning of the left hand string.
- If the pattern or the matching string had double quotes around
- them, these could get in the way of the pattern match. Now,
- the wrapping double quotes are stripped from both the pattern
- and the left hand string before applying the pattern. This
- was done because it recognized that the new way of
- scanning the expression doesn't use spaces to separate tokens,
- and the average regex expression is full of operators that
- the scanner will recognize as expression operators. Thus, unless
- the pattern is wrapped in double quotes, there will be trouble.
- For instance, ${VAR1} : (Who|What*)+
- may have have worked before, but unless you wrap the pattern
- in double quotes now, look out for trouble! This is better:
- "${VAR1}" : "(Who|What*)+"
- and should work as previous.
-
-3. Variables and Double Quotes
- Before these changes, if a variable's value contained one or more double
- quotes, it was no reason for concern. It is now!
-
-4. LE, GE, NE operators removed. The code supported these operators,
- but they were not documented. The symbolic operators, <=, >=, and !=
- should be used instead.
-
-5. Added the unary '-' operator. So you can 3+ -4 and get -1.
-
-6. Added the unary '!' operator, which is a logical complement.
- Basically, if the string or number is null, empty, or '0',
- a '1' is returned. Otherwise a '0' is returned.
-
-7. Added the '=~' operator, just in case someone is just looking for
- match anywhere in the string. The only diff with the ':' is that
- match doesn't have to be anchored to the beginning of the string.
-
-8. Added the conditional operator 'expr1 ? true_expr :: false_expr'
- First, all 3 exprs are evaluated, and if expr1 is false, the 'false_expr'
- is returned as the result. See above for details.
-
-9. Unary operators '-' and '!' were made right associative.
-
---------------------------------------------------------
-DEBUGGING HINTS FOR $[ ] EXPRESSIONS
---------------------------------------------------------
-
-There are two utilities you can build to help debug the $[ ] in
-your extensions.conf file.
-
-The first, and most simplistic, is to issue the command:
-
-make testexpr2
-
-in the top level asterisk source directory. This will build a small
-executable, that is able to take the first command line argument, and
-run it thru the expression parser. No variable substitutions will be
-performed. It might be safest to wrap the expression in single
-quotes...
-
-testexpr2 '2*2+2/2'
-
-is an example.
-
-And, in the utils directory, you can say:
-
-make check_expr
-
-and a small program will be built, that will check the file mentioned
-in the first command line argument, for any expressions that might be
-have problems when you move to flex-2.5.31. It was originally
-designed to help spot possible incompatibilities when moving from the
-pre-2.5.31 world to the upgraded version of the lexer.
-
-But one more capability has been added to check_expr, that might make
-it more generally useful. It now does a simple minded evaluation of
-all variables, and then passes the $[] exprs to the parser. If there
-are any parse errors, they will be reported in the log file. You can
-use check_expr to do a quick sanity check of the expressions in your
-extensions.conf file, to see if they pass a crude syntax check.
-
-The "simple-minded" variable substitution replaces ${varname} variable
-references with '555'. You can override the 555 for variable values,
-by entering in var=val arguments after the filename on the command
-line. So...
-
- check_expr /etc/asterisk/extensions.conf CALLERIDNUM=3075551212 DIALSTATUS=TORTURE EXTEN=121
-
-will substitute any ${CALLERIDNUM} variable references with
-3075551212, any ${DIALSTATUS} variable references with 'TORTURE', and
-any ${EXTEN} references with '121'. If there is any fancy stuff
-going on in the reference, like ${EXTEN:2}, then the override will
-not work. Everything in the ${...} has to match. So, to substitute
-#{EXTEN:2} references, you'd best say:
-
- check_expr /etc/asterisk/extensions.conf CALLERIDNUM=3075551212 DIALSTATUS=TORTURE EXTEN:2=121
-
-on stdout, you will see something like:
-
- OK -- $[ "${DIALSTATUS}" = "TORTURE" | "${DIALSTATUS}" = "DONTCALL" ] at line 416
-
-In the expr2_log file that is generated, you will see:
-
- line 416, evaluation of $[ "TORTURE" = "TORTURE" | "TORTURE" = "DONTCALL" ] result: 1
-
-check_expr is a very simplistic algorithm, and it is far from being
-guaranteed to work in all cases, but it is hoped that it will be
-useful.
-
----------------------------------------------------------
-Asterisk standard channel variables
----------------------------------------------------------
-There are a number of variables that are defined or read
-by Asterisk. Here is a list of them. More information is
-available in each application's help text. All these variables
-are in UPPER CASE only.
-
-Variables marked with a * are builtin functions and can't be set,
-only read in the dialplan. Writes to such variables are silently
-ignored.
-
-${ACCOUNTCODE} * Account code (if specified) (Deprecated; use ${CDR(accountcode)})
-${BLINDTRANSFER} The name of the channel on the other side of a blind transfer
-${BRIDGEPEER} Bridged peer
-${CALLERANI} * Caller ANI (PRI channels) (Deprecated; use ${CALLERID(ani)})
-${CALLERID} * Caller ID (Deprecated; use ${CALLERID(all)})
-${CALLERIDNAME} * Caller ID Name only (Deprecated; use ${CALLERID(name)})
-${CALLERIDNUM} * Caller ID Number only (Deprecated; use ${CALLERID(num)})
-${CALLINGANI2} * Caller ANI2 (PRI channels)
-${CALLINGPRES} * Caller ID presentation for incoming calls (PRI channels)
-${CALLINGTNS} * Transit Network Selector (PRI channels)
-${CALLINGTON} * Caller Type of Number (PRI channels)
-${CHANNEL} * Current channel name
-${CONTEXT} * Current context
-${DATETIME} * Current date time in the format: DDMMYYYY-HH:MM:SS (Deprecated; use ${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)})
-${DB_RESULT} Result value of DB_EXISTS() dial plan function
-${DNID} * Dialed Number Identifier (Deprecated; use ${CALLERID(dnid)})
-${EPOCH} * Current unix style epoch
-${EXTEN} * Current extension
-${ENV(VAR)} Environmental variable VAR
-${GOTO_ON_BLINDXFR} Transfer to the specified context/extension/priority
- after a blind transfer (use ^ characters in place of
- | to separate context/extension/priority when setting
- this variable from the dialplan)
-${HANGUPCAUSE} * Asterisk cause of hangup (inbound/outbound)
-${HINT} * Channel hints for this extension
-${HINTNAME} * Suggested Caller*ID name for this extension
-${INVALID_EXTEN} The invalid called extension (used in the "i" extension)
-${LANGUAGE} * Current language (Deprecated; use ${LANGUAGE()})
-${LEN(VAR)} * String length of VAR (integer)
-${PRIORITY} * Current priority in the dialplan
-${PRIREDIRECTREASON} Reason for redirect on PRI, if a call was directed
-${RDNIS} * Redirected Dial Number ID Service (Deprecated; use ${CALLERID(rdnis)})
-${TIMESTAMP} * Current date time in the format: YYYYMMDD-HHMMSS (Deprecated; use ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
-${TRANSFER_CONTEXT} Context for transferred calls
-${UNIQUEID} * Current call unique identifier
-
-Application return values
--------------------------
-In Asterisk 1.2, many applications return the result in a variable
-instead of, as in Asterisk 1.0, changing the dial plan priority (+101).
-For the various status values, see each application's help text.
-
-${AQMSTATUS} * addqueuemember()
-${AVAILSTATUS} * chanisavail()
-${CHECKGROUPSTATUS} * checkgroup()
-${CHECKMD5STATUS} * checkmd5()
-${CPLAYBACKSTATUS} * controlplayback()
-${DIALSTATUS} * dial()
-${DBGETSTATUS} * dbget()
-${ENUMSTATUS} * enumlookup()
-${HASVMSTATUS} * hasnewvoicemail()
-${LOOKUPBLSTATUS} * lookupblacklist()
-${OSPLOOKUPSTATUS} * osplookup()
-${OSPNEXTSTATUS} * ospnext()
-${OSPFINISHSTATUS} * ospfinish()
-${PLAYBACKSTATUS} * playback()
-${PQMSTATUS} * pausequeuemember()
-${PRIVACYMGRSTATUS} * privacymanager()
-${QUEUESTATUS} * queue()
-${RQMSTATUS} * removequeuemember()
-${SENDIMAGESTATUS} * sendimage()
-${SENDTEXTSTATUS} * sendtext()
-${SENDURLSTATUS} * sendurl()
-${SYSTEMSTATUS} * system()
-${TRANSFERSTATUS} * transfer()
-${TXTCIDNAMESTATUS} * txtcidname()
-${UPQMSTATUS} * unpausequeuemember()
-${VMSTATUS} * voicmail()
-${VMBOXEXISTSSTATUS} * vmboxexists()
-${WAITSTATUS} * waitforsilence()
-
-
-Various application variables
------------------------------
-${CURL} * Resulting page content for curl()
-${ENUM} * Result of application EnumLookup
-${EXITCONTEXT} Context to exit to in IVR menu (app background())
- or in the RetryDial() application
-${MONITOR} * Set to "TRUE" if the channel is/has been monitored (app monitor())
-${MONITOR_EXEC} Application to execute after monitoring a call
-${MONITOR_EXEC_ARGS} Arguments to application
-${MONITOR_FILENAME} File for monitoring (recording) calls in queue
-${QUEUE_PRIO} Queue priority
-${QUEUESTATUS} Status of the call, one of:
- (TIMEOUT | FULL | JOINEMPTY | LEAVEEMPTY | JOINUNAVAIL | LEAVEUNAVAIL)
-${RECORDED_FILE} * Recorded file in record()
-${TALK_DETECTED} * Result from talkdetect()
-${TOUCH_MONITOR} The filename base to use with Touch Monitor (auto record)
-${TOUCH_MONITOR_FORMAT} The audio format to use with Touch Monitor (auto record)
-${TXTCIDNAME} * Result of application TXTCIDName
-${VPB_GETDTMF} chan_vpb
-
-The MeetMe Conference Bridge uses the following variables:
-----------------------------------------------------------
-${MEETME_RECORDINGFILE} Name of file for recording a conference with
- the "r" option
-${MEETME_RECORDINGFORMAT} Format of file to be recorded
-${MEETME_EXIT_CONTEXT} Context for exit out of meetme meeting
-${MEETME_AGI_BACKGROUND} AGI script for Meetme (zap only)
-${MEETMESECS} * Number of seconds a user participated in a MeetMe conference
-
-The VoiceMail() application uses the following variables:
----------------------------------------------------------
-${VM_CATEGORY} Sets voicemail category
-${VM_NAME} * Full name in voicemail
-${VM_DUR} * Voicemail duration
-${VM_MSGNUM} * Number of voicemail message in mailbox
-${VM_CALLERID} * Voicemail Caller ID (Person leaving vm)
-${VM_CIDNAME} * Voicemail Caller ID Name
-${VM_CIDNUM} * Voicemail Caller ID Number
-${VM_DATE} * Voicemail Date
-${VM_MESSAGEFILE} * Path to message left by caller
-
-The VMAuthenticate() application uses the following variables:
----------------------------------------------------------
-${AUTH_MAILBOX} * Authenticated mailbox
-${AUTH_CONTEXT} * Authenticated mailbox context
-
-DUNDiLookup() uses the following variables
----------------------------------------------------------
-${DUNDTECH} * The Technology of the result from a call to DUNDiLookup()
-${DUNDDEST} * The Destination of the result from a call to DUNDiLookup()
-
-The Zaptel channel sets the following variables:
----------------------------------------------------------
-${ANI2} * The ANI2 Code provided by the network on the incoming call.
- (ie, Code 29 identifies call as a Prison/Inmate Call)
-${CALLTYPE} * Type of call (Speech, Digital, etc)
-${CALLEDTON} * Type of number for incoming PRI extension
- i.e. 0=unknown, 1=international, 2=domestic, 3=net_specific,
- 4=subscriber, 6=abbreviated, 7=reserved
-${CALLINGSUBADDR} * Called PRI Subaddress
-${FAXEXTEN} * The extension called before being redirected to "fax"
-${PRIREDIRECTREASON} * Reason for redirect, if a call was directed
-
-The SIP channel uses the following variables:
----------------------------------------------------------
-${SIPCALLID} * SIP Call-ID: header verbatim (for logging or CDR matching)
-${SIPDOMAIN} * SIP destination domain of an inbound call (if appropriate)
-${SIPUSERAGENT} * SIP user agent
-${SIPURI} * SIP uri
-${SIP_CODEC} Set the SIP codec for a call
-${SIP_URI_OPTIONS} * additional options to add to the URI for an outgoing call
-
-The Agent channel uses the following variables:
----------------------------------------------------------
-${AGENTMAXLOGINTRIES} Set the maximum number of failed logins
-${AGENTUPDATECDR} Whether to update the CDR record with Agent channel data
-${AGENTGOODBYE} Sound file to use for "Good Bye" when agent logs out
-${AGENTACKCALL} Whether the agent should acknowledge the incoming call
-${AGENTAUTOLOGOFF} Auto logging off for an agent
-${AGENTWRAPUPTIME} Setting the time for wrapup between incoming calls
-${AGENTNUMBER} * Agent number (username) set at login
-${AGENTSTATUS} * Status of login ( fail | on | off )
-${AGENTEXTEN} * Extension for logged in agent
-
-The Dial() application uses the following variables:
----------------------------------------------------------
-${DIALEDPEERNAME} * Dialed peer name
-${DIALEDPEERNUMBER} * Dialed peer number
-${DIALEDTIME} * Time for the call (seconds)
-${ANSWEREDTIME} * Time from dial to answer (seconds)
-${DIALSTATUS} * Status of the call, one of:
- (CHANUNAVAIL | CONGESTION | BUSY | NOANSWER
- | ANSWER | CANCEL | DONTCALL | TORTURE)
-${DYNAMIC_FEATURES} * The list of features (from the [applicationmap] section of
- features.conf) to activate during the call, with feature
- names separated by '#' characters
-${LIMIT_PLAYAUDIO_CALLER} Soundfile for call limits
-${LIMIT_PLAYAUDIO_CALLEE} Soundfile for call limits
-${LIMIT_WARNING_FILE} Soundfile for call limits
-${LIMIT_TIMEOUT_FILE} Soundfile for call limits
-${LIMIT_CONNECT_FILE} Soundfile for call limits
-${OUTBOUND_GROUP} Default groups for peer channels (as in SetGroup)
-* See "show application dial" for more information
-
-The chanisavail() application sets the following variables:
------------------------------------------------------------
-${AVAILCHAN} * the name of the available channel if one was found
-${AVAILORIGCHAN} * the canonical channel name that was used to create the channel
-${AVAILSTATUS} * Status of requested channel
-
-When using macros in the dialplan, these variables are available
----------------------------------------------------------
-${MACRO_EXTEN} * The calling extensions
-${MACRO_CONTEXT} * The calling context
-${MACRO_PRIORITY} * The calling priority
-${MACRO_OFFSET} Offset to add to priority at return from macro
-
-If you compile with OSP support in the SIP channel, these
-variables are used:
----------------------------------------------------------
-${OSPHANDLE} Handle from the OSP Library
-${OSPTECH} OSP Technology from Library
-${OSPDEST} OSP Destination from Library
-${OSPTOKEN} OSP Token to use for call from Library
-${OSPRESULTS} Number of OSP results
-
-____________________________________
-CDR Variables
-------------------------------------
-
-If the channel has a cdr, that cdr record has it's own set of variables which
-can be accessed just like channel variables. The following builtin variables
-are available.
-
-${CDR(clid)} Caller ID
-${CDR(src)} Source
-${CDR(dst)} Destination
-${CDR(dcontext)} Destination context
-${CDR(channel)} Channel name
-${CDR(dstchannel)} Destination channel
-${CDR(lastapp)} Last app executed
-${CDR(lastdata)} Last app's arguments
-${CDR(start)} Time the call started.
-${CDR(answer)} Time the call was answered.
-${CDR(end)} Time the call ended.
-${CDR(duration)} Duration of the call.
-${CDR(billsec)} Duration of the call once it was answered.
-${CDR(disposition)} ANSWERED, NO ANSWER, BUSY
-${CDR(amaflags)} DOCUMENTATION, BILL, IGNORE etc
-${CDR(accountcode)} The channel's account code.
-${CDR(uniqueid)} The channel's unique id.
-${CDR(userfield)} The channels uses specified field.
-
-
-In addition, you can set your own extra variables with a traditional
-Set(CDR(var)=val) to anything you want.
-
-Certain functional variables may be accessed with ${foo(<args>)}. A list
-of these functional variables may be found by typing "show functions"
-at the Asterisk CLI.
diff --git a/1.2-netsec/doc/app_sms.html b/1.2-netsec/doc/app_sms.html
deleted file mode 100644
index 2a076b38b..000000000
--- a/1.2-netsec/doc/app_sms.html
+++ /dev/null
@@ -1,834 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
-</head>
-<body>
-<h1>* Application SMS</h1>
-The SMS module for asterisk was developed by Adrian Kennard, and is an
-implementation of the ETSI specification for landline SMS, ETSI ES 201
-912, which is available from www.etsi.org. Landline SMS is starting to
-be available in various parts of Europe, and is available from BT in
-the UK. However, asterisk would allow gateways to be created in other
-locations such as the US, and use of SMS capable phones such as the
-Magic Messenger. SMS works using analogue or ISDN lines.<br>
-<h2>Background</h2>
-Short Message Service (SMS), or <span style="font-style: italic;">texting</span>
-is very popular between mobile phones. A message can be sent between
-two phones, and normally contains 160 characters. There are ways in
-which various types of data can be encoded in a text message such as
-ring tones, and small graphic, etc. Text messaging is being used for
-voting and competitions, and also SPAM...<br>
-<br>
-Sending a message involves the mobile phone contacting a message centre
-(SMSC) and passing the message to it. The message centre then contacts
-the destination mobile to deliver the message. The SMSC is responsible
-for storing the message and trying to send it until the destination
-mobile is available, or a timeout.<br>
-<br>
-Landline SMS works in basically the same way. You would normally have a
-suitable text capable landline phone, or a separate texting box such as
-a Magic Messenger on your phone line. This sends a message to a message
-centre your telco provides by making a normal call and sending the data
-using 1200 Baud FSK signaling according to the ETSI spec. To receive a
-message the message centre calls the line with a specific calling
-number, and the text capable phone answers the call and receives the
-data using 1200 Baud FSK signaling. This works particularly well in the
-UK as the calling line identity is sent before the first ring, so no
-phones in the house would ring when a message arrives.<br>
-<h2>Typical use with asterisk</h2>
-Sending messages from an asterisk box can be used for a variety of
-reasons, including notification from any monitoring systems, email
-subject lines, etc.<br>
-Receiving messages to an asterisk box is typically used just to email
-the messages to someone appropriate - we email and texts that are
-received to our direct numbers to the appropriate person. Received
-messages could also be used to control applications, manage
-competitions, votes, post items to IRC, anything.<br>
-Using a terminal such as a magic messenger, an asterisk box could ask
-as a message centre sending messages to the terminal, which will beep
-and pop up the message (and remember 100 or so messages in its memory).<br>
-<h2>Terminology</h2>
-<table style="text-align: left;" border="1" cellpadding="2"
- cellspacing="2">
- <tbody>
- <tr>
- <td style="vertical-align: top;">SMS<br>
- </td>
- <td style="vertical-align: top;">Short Message Service<br>
- </td>
- <td style="vertical-align: top;">i.e. text messages<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">SMSC<br>
- </td>
- <td style="vertical-align: top;">Short Message Service Centre<br>
- </td>
- <td style="vertical-align: top;">The system responsible for
-storing and forwarding messages<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">MO<br>
- </td>
- <td style="vertical-align: top;">Mobile Originated<br>
- </td>
- <td style="vertical-align: top;">A message on its way from a
-mobile or landline device to the SMSC<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">MT<br>
- </td>
- <td style="vertical-align: top;">Mobile Terminated<br>
- </td>
- <td style="vertical-align: top;">A message on its way from the
-SMSC to the mobile or landline device<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">RX<br>
- </td>
- <td style="vertical-align: top;">Receive<br>
- </td>
- <td style="vertical-align: top;">A message coming in to the
-asterisk box<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">TX<br>
- </td>
- <td style="vertical-align: top;">Transmit<br>
- </td>
- <td style="vertical-align: top;">A message going out of the
-asterisk box<br>
- </td>
- </tr>
- </tbody>
-</table>
-<h2>Sub address</h2>
-When sending a message to a landline, you simply send to the landline
-number. In the UK, all of the mobile operators (bar one) understand
-sending messages to landlines and pass the messages to the BTText
-system for delivery to the landline.<br>
-<br>
-The specification for landline SMS allows for the possibility of more
-than one device on a single landline. These can be configured with <span
- style="font-style: italic;">Sub addresses</span> which are a single
-digit. To send a message to a specific device the message is sent to
-the landline number with an extra digit appended to the end. The telco
-can define a default sub address (9 in the UK) which is used when the
-extra digit is not appended to the end. When the call comes in, part of
-the calling line ID is the sub address, so that only one device on the
-line answers the call and receives the message.<br>
-<br>
-Sub addresses also work for outgoing messages. Part of the number
-called by the device to send a message is its sub address. Sending from
-the default sub address (9 in the UK) means the message is delivered
-with the <span style="font-style: italic;">sender </span>being the
-normal landline number. Sending from any other sub address makes the <span
- style="font-style: italic;">sender</span> the landline number with an
-extra digit on the end.<br>
-<br>
-Using asterisk, you can make use of the sub addresses for sending and
-receiving messages. Using DDI (DID, i.e. multiple numbers on the line
-on ISDN) you can also make use of many different numbers for SMS.<br>
-<h2>Build / installation</h2>
-<span style="font-weight: bold;">app_sms.c</span> is included in the
-latest cvs. It lives in the asterisk source <span
- style="font-weight: bold;">apps</span> directory and is included in
-the object list (<span style="font-weight: bold;">app_sms.so</span>) in
-<span style="font-weight: bold;">apps/Makefile</span>.<br>
-<span style="font-weight: bold;">smsq.c</span> is a stand alone helper
-application which is used to send SMSs from the command line. It uses
-the <span style="font-weight: bold;">popt</span> library. A line for
-your make file is:-<br>
-<pre>smsq: smsq.c<br> cc -O -o smsq smsq.c -lpopt<br></pre>
-<span style="font-family: monospace;"></span>
-<h2>extensions.conf</h2>
-The following contexts are recommended.<br>
-<pre>; Mobile Terminated, RX. This is used when an incoming call from the SMS arrives, with the queue (called number and sub address) in ${EXTEN}<br>; Running an app after receipt of the text allows the app to find all messages in the queue and handle them, e.g. email them.<br>; The app may be something like smsq --process=somecommand --queue=${EXTEN} to run a command for each received message<br>; See below for usage<br>[smsmtrx]<br>exten = _X.,1, SMS(${EXTEN}|a)<br>exten = _X.,2,System("someapptohandleincomingsms ${EXTEN}")<br>exten = _X.,3,Hangup<br><br>; Mobile originated, RX. This is receiving a message from a device, e.g. a Magic Messenger on a sip extension<br>; Running an app after receipt of the text allows the app to find all messages in the queue and handle then, e.g. sending them to the public SMSC<br>; The app may be something like smsq --process=somecommand --queue=${EXTEN} to run a command for each received message<br>; See below for example usage<br>[smsmorx]<br>exten = _X.,1, SMS(${EXTEN}|sa)<br>exten = _X.,2,System("someapptohandlelocalsms ${EXTEN}")<br>exten = _X.,3,Hangup<span
- style="font-family: sans-serif;"></span><span
- style="font-family: sans-serif;"></span></pre>
-<span style="font-family: sans-serif;"></span><span
- style="font-weight: bold;">smsmtrx</span> is normally accessed by an
-incoming call from the SMSC. In the UK this call is from a CLI of
-080058752X0 where X is the sub address. As such a typical usage in the
-extensions.conf at the point of handling an incoming call is:-<br>
-<pre>exten = _X./8005875290,1,Goto(smsmtrx,${EXTEN},1)<br>exten = _X./_80058752[0-8]0,1,Goto(smsmtrx,${EXTEN}-${CALLERIDNUM:8:1},1)<br></pre>
-Alternatively, if you have the correct national prefix on incoming CLI,
-e.g. using zaphfc, you might use:-<br>
-<pre>exten = _X./08005875290,1,Goto(smsmtrx,${EXTEN},1)<br>exten = _X./_080058752[0-8]0,1,Goto(smsmtrx,${EXTEN}-${CALLERIDNUM:9:1},1)</pre>
-<span style="font-weight: bold;">smsmorx</span> is normally accessed by
-a call from a local sip device connected to a Magic Messenger. It could
-however by that you are operating asterisk as a message centre for
-calls from outside. Either way, you look at the called number and goto
-smsmorx. In the UK, the SMSC number that would be dialed is 1709400X
-where X is the caller sub address. As such typical usage in
-extension.config at the point of handling a call from a sip phone is:-<br>
-<pre>exten = 17094009,1,Goto(smsmorx,${CALLERIDNUM},1)<br>exten = _1709400[0-8],1,Goto(smsmorx,${CALLERIDNUM}-{EXTEN:7:1},1)<br></pre>
-<h2>Using smsq</h2>
-<span style="font-weight: bold;">smsq</span> is a simple helper
-application designed to make it easy to send messages from a command
-line. it is intended to run on the asterisk box and have direct access
-to the queue directories for SMS and for asterisk.<br>
-<br>
-In its simplest form you can send an SMS by a command such as <br>
-<br>
-smsq 0123456789 This is a test to 0123456789<br>
-<br>
-This would create a queue file for a mobile originated TX message in
-queue 0 to send the text "This is a test to 0123456789" to 0123456789.
-It would then place a file in the /var/spool/asterisk/outgoing
-directory to initiate a call to 17094009 (the default message centre in
-smsq) attached to application SMS with argument of the queue name (0).<br>
-<br>
-Normally smsq will queue a message ready to send, and will then create
-a file in the asterisk outgoing directory causing asterisk to actually
-connect to the message centre or device and actually send the pending
-message(s).<br>
-<br>
-Using --process, smsq can however be used on received queues to run a
-command for each file (matching the queue if specified) with various
-environment variables set based on the message (see below);<br>
-<br>
-smsq options:-<br>
-<br>
-<table style="text-align: left;" border="1" cellpadding="2"
- cellspacing="2">
- <tbody>
- <tr>
- <td style="vertical-align: top;">--help</td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Show help text<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--usage<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Show usage<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--queue<br>
- </td>
- <td style="vertical-align: top;">-q<br>
- </td>
- <td style="vertical-align: top;">Specify a specific queue<br>
-In no specified, messages are queued under queue "0"<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--da<br>
- </td>
- <td style="vertical-align: top;">-d<br>
- </td>
- <td style="vertical-align: top;">Specify destination address<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--oa<br>
- </td>
- <td style="vertical-align: top;">-o<br>
- </td>
- <td style="vertical-align: top;">Specify originating address<br>
-This also implies that we are generating a mobile terminated message<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--ud<br>
- </td>
- <td style="vertical-align: top;">-m<br>
- </td>
- <td style="vertical-align: top;">Specify the actual message<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--ud-file<br>
- </td>
- <td style="vertical-align: top;">-f<br>
- </td>
- <td style="vertical-align: top;">Specify a file to be read for
-the context of the message<br>
-A blank filename (e.g. --ud-file= on its own) means read stdin. Very
-useful when using via ssh where command line parsing could mess up the
-message.<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--mt<br>
- </td>
- <td style="vertical-align: top;">-t<br>
- </td>
- <td style="vertical-align: top;">Mobile terminated message to be
-generated<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--mo<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Mobile originated message to be
-generated<br>
-Default<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--tx<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Transmit message<br>
-Default<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--rx<br>
- </td>
- <td style="vertical-align: top;">-r<br>
- </td>
- <td style="vertical-align: top;">Generate a message in the
-receive queue<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--UTF-8<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Treat the file as UTF-8 encoded
-(default) </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--UCS-1<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Treat the file as raw 8 bit
-UCS-1 data, not UTF-8 encoded<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--UCS-2<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Treat the file as raw 16 bit
-bigendian USC-2 data<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--process<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Specific a command to process
-for each file in the queue<br>
-Implies --rx and --mt if not otherwise specified.<br>
-Sets environment variables for every possible variable,
-and also ud, ud8 (USC-1 hex), and ud16 (USC-2 hex) for each call.
-Removes files.<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--motx-channel<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Specify the channel for motx
-calls<br>
-May contain X to use sub address based on queue name or may be full
-number<br>
-Default is Local/1709400X<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--motx-callerid<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Specify the caller ID for motx
-calls<br>
-The default is the queue name without -X suffix<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--motx-wait<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Wait time for motx call<br>
-Default 10<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--motx-delay<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Retry time for motx call<br>
-Default 1<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--motx-retries<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Retries for motx call<br>
-Default 10<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--mttx-channel<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Specify the channel for mttx
-calls<br>
-Default is Local/ and the queue name without -X suffix<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--mtttx-callerid<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Specify the callerid for mttx
-calls<br>
-May include X to use sub address based on queue name or may be full
-number<br>
-Default is 080058752X0<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--mttx-wait<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Wait time for mttx call<br>
-Default 10<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--mttx-delay<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Retry time for mttx call<br>
-Default 30<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--mttx-retries<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Retries for mttx call<br>
-Default 100<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--default-sub-address<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">The default sub address assumed
-(e.g. for X in CLI and dialled numbers as above) when none added (-X)
-to queue<br>
-Default 9<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--no-dial<br>
- </td>
- <td style="vertical-align: top;">-x<br>
- </td>
- <td style="vertical-align: top;">Create queue, but do not dial to
-send message<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--no-wait<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Do not wait if a call appears to
-be in progress<br>
-This could have a small window where a mesdsage is queued but not sent,
-so regular calls to smsq should be done to pick up any missed messages<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--concurrent<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">How many concurrent calls to
-allow (per queue), default 1<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--mr<br>
- </td>
- <td style="vertical-align: top;">-n<br>
- </td>
- <td style="vertical-align: top;">Message reference<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--pid<br>
- </td>
- <td style="vertical-align: top;">-p<br>
- </td>
- <td style="vertical-align: top;">Protocol ID<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--dcs<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Data coding scheme<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--udh<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Specific hex string of user data
-header specified (not including the initial length byte)<br>
-May be a blank string to indicate header is included in the user data
-already but user data header indication to be set.<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--srr<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Status report requested<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--rp<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Return path requested<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--vp<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Specify validity period (seconds)<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--scts<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Specify timestamp
-(YYYY-MM-DDTHH:MM:SS)<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">--spool-dir<br>
- </td>
- <td style="vertical-align: top;"><br>
- </td>
- <td style="vertical-align: top;">Spool dir (in which sms and
-outgoing are found)<br>
-Default /var/spool/asterisk<br>
- </td>
- </tr>
- </tbody>
-</table>
-<p>Other arguments starting '-' or '--' are invalid and will cause an
-error. Any trailing arguments are processed as follows:-<br>
-</p>
-<ul>
- <li>If the message is mobile originating and no destination address
-has been specified, then the first argument is assumed to be a
-destination address</li>
- <li>If the message is mobile terminating and no destination address
-has been specified, then the first argument is assumed to be the queue
-name</li>
- <li>If there is no user data, or user data file specified, then any
-following arguments are assumed to be the message, which are
-concatenated.</li>
- <li>If no user data is specified, then no message is sent. However,
-unless --no-dial is specified, smsq checks for pending messages and
-generates an outgoing anyway</li>
-</ul>
-Note that when smsq attempts to make a file in
-/var/spool/asterisk/outgoing, it checks if there is already a call
-queued for that queue. It will try several filenames, up to the
---concorrent setting. If these files
-exists, then this means asterisk is already queued to send all messages
-for that queue, and so asterisk should pick up the message just queued.
-However, this alone could create a race condition, so if the files
-exist then smsq will wait up to 3 seconds to confirm it still exists or
-if the queued messages have been sent already.
-The --no-wait turns off this behaviour. Basically, this means that if
-you have a lot of messages to send all at
-once, asterisk will not make unlimited concurrent calls to the same
-message centre or device for the same queue. This is because it is
-generally more efficient to make one call and send all of the messages
-one after the other.<br>
-<br>
-smsq can be used with no arguments, or with a queue name only, and it
-will check for any pending messages and cause an outgoing if there are
-any. It only sets up one outgoing call at a time based on the first
-queued message it finds. A outgoing call will normally send all queued
-messages for that queue. One way to use smsq would be to run with no
-queue name (so any queue) every minute or every few seconds to send
-pending message. This is not normally necessary unless --no-dial is
-selected. Note that smsq does only check motx or mttx depending on the
-options selected, so it would need to be called twice as a general
-check.<br>
-<br>
-UTF-8 is used to parse command line arguments for user data, and is the
-default when reading a file. If an invalid UTF-8 sequence is found, it
-is treated as UCS-1 data (i.e, as is).<br>
-<br>
-The --process option causes smsq to scan the specified queue (default
-is mtrx) for messages (matching the queue specified, or any if queue
-not specified) and run a command and delete the file. The command is
-run with a number of environment variables set as follows. Note that
-these are unset if not needed and not just taken from the calling
-environment. This allows simple processing of incoming messages<br>
-<br>
-<table style="text-align: left;" border="1" cellpadding="2"
- cellspacing="2">
- <tbody>
- <tr>
- <td style="vertical-align: top;">$queue<br>
- </td>
- <td style="vertical-align: top;">Set if a queue specified<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">$?srr<br>
- </td>
- <td style="vertical-align: top;">srr is set (to blank) if srr
-defined and has value 1.<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">$?rp<br>
- </td>
- <td style="vertical-align: top;">rp is set (to blank) if rp
-defined and has value 1.<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">$ud<br>
- </td>
- <td style="vertical-align: top;">User data, UTF-8 encoding,
-including any control characters, but with nulls stripped out<br>
-Useful for the content of emails, for example, as it includes any
-newlines, etc.<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">$ude<br>
- </td>
- <td style="vertical-align: top;">User data, escaped UTF-8,
-including all characters, but control characters \n, \r, \t, \f, \xxx
-and \ is escaped as \\<br>
-Useful fGuaranteed one line printable text, so useful in Subject lines
-of emails, etc<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">$ud8<br>
- </td>
- <td style="vertical-align: top;">Hex UCS-1 coding of user data (2
-hex digits per character)<br>
-Present only if all user data is in range U+0000 to U+00FF<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">$ud16<br>
- </td>
- <td style="vertical-align: top;">Hex UCS-2 coding of user data (4
-hex digits per chartacter)<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;"><span style="font-style: italic;">other</span><br>
- </td>
- <td style="vertical-align: top;">Other fields set using their
-field name, e.g. mr, pid, dcs, etc. udh is a hex byte string<br>
- </td>
- </tr>
- </tbody>
-</table>
-<h2>File formats</h2>
-By default all queues are held in a director /var/spool/asterisk/sms.
-Within this directory are sub directories mtrx, mttx, morx, motx which
-hold the received messages and the messages ready to send. Also,
-/var/log/asterisk/sms is a log file of all messages handled.<br>
-<br>
-The file name in each queue directory starts with the queue parameter
-to SMS which is normally the CLI used for an outgoing message or the
-called number on an incoming message, and may have -X (X being sub
-address) appended. If no queue ID is known, then 0 is used by smsq by
-default. After this is a dot, and then any text. Files are scanned for
-matching queue ID and a dot at the start. This means temporary files
-being created can be given a different name not starting with a queue
-(we recommend a . on the start of the file name for temp files).<br>
-<br>
-Files in these queues are in the form of a simple text file where each
-line starts with a keyword and an = and then data. udh and ud have
-options for hex encoding, see below.<br>
-<br>
-UTF-8. The user data (ud) field is treated as being UTF-8 encoded
-unless the DCS is specified indicating 8 bit formart. If 8 bit format
-is specified then the user data is sent as is.<br>
-<br>
-The keywords are as
-follows:-<br>
-<table style="text-align: left;" border="1" cellpadding="2"
- cellspacing="2">
- <tbody>
- <tr>
- <td style="vertical-align: top;">oa</td>
- <td style="vertical-align: top;">Originating address<br>
-The phone number from which the message came<br>
-Present on mobile terminated messages and is the CLI for morx messages<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">da<br>
- </td>
- <td style="vertical-align: top;">Destination Address<br>
-The phone number to which the message is sent<br>
-Present on mobile originated messages<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">scts<br>
- </td>
- <td style="vertical-align: top;">The service centre time stamp<br>
-Format YYYY-MM-DDTHH:MM:SS<br>
-Present on mobile terminated messages<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">pid<br>
- </td>
- <td style="vertical-align: top;">One byte decimal protocol ID<br>
-See GSM specs for more details<br>
-Normally 0 or absent<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">dcs<br>
- </td>
- <td style="vertical-align: top;">One byte decimal data coding
-scheme<br>
-If omitted, a sensible default is used (see below)<br>
-See GSM specs for more details<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">mr<br>
- </td>
- <td style="vertical-align: top;">One byte decimal message
-reference<br>
-Present on mobile originated messages, added by default if absent<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">srr<br>
- </td>
- <td style="vertical-align: top;">0 or 1 for status report request<br>
-Does not work in UK yet, not implemented in app_sms yet<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">rp<br>
- </td>
- <td style="vertical-align: top;">0 or 1 return path<br>
-See GSM specs for details<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">vp<br>
- </td>
- <td style="vertical-align: top;">Validity period in seconds<br>
-Does not work in UK yet<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">udh<br>
- </td>
- <td style="vertical-align: top;">Hex string of user data header
-prepended to the SMS contents, excluding initial length byte.<br>
-Consistent with ud, this is specified as udh# rather than udh=<br>
-If blank, this means that the udhi flag will be set but any user data
-header must be in the ud field<br>
- </td>
- </tr>
- <tr>
- <td style="vertical-align: top;">ud<br>
- </td>
- <td style="vertical-align: top;">User data, may be text, or hex,
-see below<br>
- </td>
- </tr>
- </tbody>
-</table>
-<br>
-udh is specified as as udh# followed by hex (2 hex digits per byte). If
-present, then the user data header indicator bit is set, and the length
-plus the user data header is added to the start of the user data, with
-padding if necessary (to septet boundary in 7 bit format).<br>
-<br>
-User data can hold an USC character codes U+0000 to U+FFFF. Any other
-characters are coded as U+FEFF<br>
-ud can be specified as ud= followed by UTF-8 encoded text if it
-contains no control characters, i.e. only (U+0020 to U+FFFF). Any
-invalid UTF-8 sequences are treated as is (U+0080-U+00FF).<br>
-ud can also be specified as ud# followed by hex (2 hex digits per byte)
-containing characters U+0000 to U+00FF only.<br>
-ud can also be specified as ud## followed by hex (4 hex digits per
-byte) containing UCS-2 characters.<br>
-When written by app_sms (e.g. incoming messages), the file is written
-with ud= if it can be (no control characters). If it cannot, the a
-comment line ;ud= is used to show the user data for human readability
-and ud# or ud## is used.<br>
-<h2>Delivery reports</h2>
-The SMS specification allows for delivery reports. These are requested
-using the srr bit. However, as these do not work in the UK yet they are
-not fully implemented in this application. If anyone has a telco that
-does implement these, please let me know. BT in the UK have a non
-standard way to do this by starting the message with *0#, and so this
-application may have a UK specific bodge in the near future to handle
-these.<br>
-<br>
-The main changes that are proposed for delivery report handling are :-<br>
-<ul>
- <li>New queues for sent messages, one file for each destination
-address and message reference.</li>
- <li>New field in message format, user reference, allowing
-applications to tie up their original message with a report.</li>
- <li>Handling of the delivery confirmation/rejection and connecting to
-the outgoing message - the received message file would then have fields
-for the original outgoing message and user reference allowing
-applications to handle confirmations better.<br>
- </li>
-</ul>
-<br>
-</body>
-</html>
diff --git a/1.2-netsec/doc/apps.txt b/1.2-netsec/doc/apps.txt
deleted file mode 100644
index c9696a1a5..000000000
--- a/1.2-netsec/doc/apps.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-Asterisk applications register themselves with ast_application_register.
-They should have a short, unique name, and an exec function which takes
-as its arguments a channel and some data that might be useful for callback
-stuff. Remember to keep track of how many and which channels are using
-your application so that should the module need to be unloaded
-(particularly force unloaded), you will be able to ast_softhangup all the
-channels. An application should *never* call ast_hangup on the channel
-that it is running on (although it could conceivably hang up other
-channels that it allocates). See app_playback.c as an example of a simple
-application.
diff --git a/1.2-netsec/doc/cdr.txt b/1.2-netsec/doc/cdr.txt
deleted file mode 100644
index 02dc7d1db..000000000
--- a/1.2-netsec/doc/cdr.txt
+++ /dev/null
@@ -1,171 +0,0 @@
-Call data records can be stored in many different databases or even CSV text.
-
-MSSQL: Asterisk can currently store CDRs into an MSSQL database in
- two different ways: cdr_odbc.c or cdr_tds.c
-
- Call Data Records can be stored using unixODBC (which requires
- the FreeTDS package) [cdr_odbc.c] or directly by using just the
- FreeTDS package [cdr_tds.c] The following provide some
- examples known to get asterisk working with mssql.
- NOTE: Only choose one db connector.
-
- ODBC [cdr_odbc.c]:
- Compile, configure, and install the latest unixODBC package:
- tar -zxvf unixODBC-2.2.9.tar.gz &&
- cd unixODBC-2.2.9 &&
- ./configure --sysconfdir=/etc --prefix=/usr --disable-gui &&
- make &&
- make install
-
- Compile, configure, and install the latest FreeTDS package:
- tar -zxvf freetds-0.62.4.tar.gz &&
- cd freetds-0.62.4 &&
- ./configure --prefix=/usr --with-tdsver=7.0 \
- --with-unixodbc=/usr/lib &&
- make &&
- make install
-
- Compile, or recompile, asterisk so that it will now add support
- for cdr_odbc.c
-
- make clean &&
- make update &&
- make &&
- make install
-
- Setup odbc configuration files. These are working examples
- from my system. You will need to modify for your setup.
- You are not required to store usernames or passwords here.
-
- /etc/odbcinst.ini
- [FreeTDS]
- Description = FreeTDS ODBC driver for MSSQL
- Driver = /usr/lib/libtdsodbc.so
- Setup = /usr/lib/libtdsS.so
- FileUsage = 1
-
- /etc/odbc.ini
- [MSSQL-asterisk]
- description = Asterisk ODBC for MSSQL
- driver = FreeTDS
- server = 192.168.1.25
- port = 1433
- database = voipdb
- tds_version = 7.0
- language = us_english
-
- Only install one database connector. Do not confuse asterisk
- by using both ODBC (cdr_odbc.c) and FreeTDS (cdr_tds.c).
- This command will erase the contents of cdr_tds.conf
-
- [ -f /etc/asterisk/cdr_tds.conf ] > /etc/asterisk/cdr_tds.conf
-
- NOTE: unixODBC requires the freeTDS package, but asterisk does
- not call freeTDS directly.
-
- Setup cdr_odbc configuration files. These are working samples
- from my system. You will need to modify for your setup. Define
- your usernames and passwords here, secure file as well.
-
- /etc/asterisk/cdr_odbc.conf
- [global]
- dsn=MSSQL-asterisk
- username=voipdbuser
- password=voipdbpass
- loguniqueid=yes
-
- And finally, create the 'cdr' table in your mssql database.
-
- CREATE TABLE cdr (
- [calldate] [datetime] NOT NULL ,
- [clid] [varchar] (80) NOT NULL ,
- [src] [varchar] (80) NOT NULL ,
- [dst] [varchar] (80) NOT NULL ,
- [dcontext] [varchar] (80) NOT NULL ,
- [channel] [varchar] (80) NOT NULL ,
- [dstchannel] [varchar] (80) NOT NULL ,
- [lastapp] [varchar] (80) NOT NULL ,
- [lastdata] [varchar] (80) NOT NULL ,
- [duration] [int] NOT NULL ,
- [billsec] [int] NOT NULL ,
- [disposition] [varchar] (45) NOT NULL ,
- [amaflags] [int] NOT NULL ,
- [accountcode] [varchar] (20) NOT NULL ,
- [uniqueid] [varchar] (32) NOT NULL ,
- [userfield] [varchar] (255) NOT NULL
- )
-
- Start asterisk in verbose mode, you should see that asterisk
- logs a connection to the database and will now record every
- call to the database when it's complete.
-
- TDS [cdr_tds.c]:
- Compile, configure, and install the latest FreeTDS package:
- tar -zxvf freetds-0.62.4.tar.gz &&
- cd freetds-0.62.4 &&
- ./configure --prefix=/usr --with-tdsver=7.0
- make &&
- make install
-
- Compile, or recompile, asterisk so that it will now add support
- for cdr_tds.c (Currently only asterisk SVN supports cdr_tds.c)
-
- make clean &&
- make update &&
- make &&
- make install
-
- Only install one database connector. Do not confuse asterisk
- by using both ODBC (cdr_odbc.c) and FreeTDS (cdr_tds.c).
- This command will erase the contents of cdr_odbc.conf
-
- [ -f /etc/asterisk/cdr_odbc.conf ] > /etc/asterisk/cdr_odbc.conf
-
- Setup cdr_tds configuration files. These are working samples
- from my system. You will need to modify for your setup. Define
- your usernames and passwords here, secure file as well.
-
- /etc/asterisk/cdr_tds.conf
- [global]
- hostname=192.168.1.25
- port=1433
- dbname=voipdb
- user=voipdbuser
- password=voipdpass
- charset=BIG5
-
- And finally, create the 'cdr' table in your mssql database.
-
- CREATE TABLE cdr (
- [accountcode] [varchar] (20) NULL ,
- [src] [varchar] (80) NULL ,
- [dst] [varchar] (80) NULL ,
- [dcontext] [varchar] (80) NULL ,
- [clid] [varchar] (80) NULL ,
- [channel] [varchar] (80) NULL ,
- [dstchannel] [varchar] (80) NULL ,
- [lastapp] [varchar] (80) NULL ,
- [lastdata] [varchar] (80) NULL ,
- [start] [datetime] NULL ,
- [answer] [datetime] NULL ,
- [end] [datetime] NULL ,
- [duration] [int] NULL ,
- [billsec] [int] NULL ,
- [disposition] [varchar] (20) NULL ,
- [amaflags] [varchar] (16) NULL ,
- [uniqueid] [varchar] (32) NULL
- )
-
- Start asterisk in verbose mode, you should see that asterisk
- logs a connection to the database and will now record every
- call to the database when it's complete.
-
-MYSQL:
-
-PGSQL:
-
-SQLLITE:
-
--------------------------------------------------------------------------------
-
-08/02/2004 : Duane Cox <dcox@illicom.net> - added mssql information
diff --git a/1.2-netsec/doc/channel.txt b/1.2-netsec/doc/channel.txt
deleted file mode 100644
index 4cef6a4c6..000000000
--- a/1.2-netsec/doc/channel.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-Implementing a Channel
-======================
-
-* What is a channel?
-
-A channel is a unit which brings in a call to the Asterisk PBX. A channel
-could be connected to a real telephone (like the Internet Phone Jack) or
-to a logical call (like an Internet phone call). Asterisk makes no
-distinction between "FXO" and "FXS" style channels (that is, it doesn't
-distinguish between telephone lines and telephones).
-
-Every call is placed or received on a distinct channel. Asterisk uses a
-channel driver (typically named chan_xxx.so) to support each type of
-hardware.
-
-* What do I need to create a channel?
-
-In order to support a new piece of hardware you need to write a channel
-driver. The easiest way to do so is to look at an existing channel driver
-and model your own code after it.
-
-* What's the general architecture?
-
-Typically, a channel reads a configuration file on startup which tells it
-something about the hardware it's going to be servicing. Then, it
-launches a thread which monitors all the idle channels (See the chan_modem
-or the chan_ixj for an example of this). When a "RING" or equivalent is
-detected, the monitoring thread should allocate a channel structure and
-assign all the callbacks to it (see ixj_new, for example), and then call
-ast_pbx_start on that channel. ast_pbx_start will launch a new thread to
-handle the channel as long as the call is up, so once pbx_start has
-successfully been run, the monitor should no longer monitor that channel.
-The PBX thread will use the channel, reading, writing, calling, etc., and
-multiplexing that channel with others using select() on the channel's
-file descriptor (if your channel doesn't have an associated file
-descriptor, you'll need to emulate one somehow, perhaps along the lines of
-what the translator API does with its channel.
-
-When the PBX is finished with the line, it will hang up the line, at which
-point it the hardware should again be monitored by the monitoring thread.
diff --git a/1.2-netsec/doc/extensions.txt b/1.2-netsec/doc/extensions.txt
deleted file mode 100644
index bab08d319..000000000
--- a/1.2-netsec/doc/extensions.txt
+++ /dev/null
@@ -1,58 +0,0 @@
-The Asterisk dialplan
-=====================
-
-The Asterisk dialplan is divided into contexts. A context is simply a group
-of extensions. For each "line" that should be able to be called, an extension
-must be added to a context. Then, you configure the calling "line" to have
-access to this context.
-
-If you change the dialplan, you can use the Asterisk CLI command
-"extensions reload" to load the new dialplan without disrupting
-service in your PBX.
-
-Extensions are routed according to priority and may be based on any set
-of characters (a-z), digits, #, and *. Please note that when matching a
-pattern, "N", "X", and "Z" are interpreted as classes of digits.
-
-For each extension, several actions may be listed and must be given a unique
-priority. When each action completes, the call continunes at the next priority
-(except for some modules which use explicitly GOTO's).
-
-When each action completes, it generally moves to the next priority (except for
-some modules which use explicitly GOTO's.
-
-Extensions frequently have data they pass to the executing application
-(most frequently a string). You can see the available dialplan applications
-by entering the "show applications" command in the CLI.
-
-In this version of Asterisk, dialplan functions are added. These can
-be used as arguments to any application. For a list of the installed
-functions in your Asterisk, use the "show functions" command.
-
-* Example dial plan
-
-The example dial plan, in the configs/extensions.conf.sample file
-is installed as extensions.conf if you run "make samples" after
-installation of Asterisk. This file includes many more instructions
-and examples than this file, so it's worthwile to read it.
-
-* Special extensions
-
-There are some extensions with important meanings:
-
- s: What to do when an extension context is entered (unless
- overridden by the low level channel interface)
- This is used in macros, and some special cases.
- "s" is not a generic catch-all wildcard extension.
- i: What to do if an invalid extension is entered
- h: The hangup extension, executed at hangup
- t: What to do if nothing is entered in the requisite amount
- of time.
- T: This is the extension that is executed when the 'absolute'
- timeout is reached. See "show function TIMEOUT" for more
- information on setting timeouts.
-
-And finally, the extension context "default" is used when either a) an
-extension context is deleted while an extension is in use, or b) a specific
-starting extension handler has not been defined (unless overridden by the
-low level channel interface).
diff --git a/1.2-netsec/doc/iax.txt b/1.2-netsec/doc/iax.txt
deleted file mode 100644
index 48bb3e10e..000000000
--- a/1.2-netsec/doc/iax.txt
+++ /dev/null
@@ -1,55 +0,0 @@
-Inter-Asterisk eXchange Protocol
-================================
-
-Usage:
-======
-The format for the dialing string on Asterisk is:
-IAX/[user@]peer[:exten[@context]]
-
-(Note, []'s denote optional fields). The peer is either an IP address
-or a peer as specified in the /etc/asterisk/iax.conf file. Exten is
-an optional requested extension (otherwise "s" will be used), and
-"context" is an optional context to request. The user is an optional
-username specified in the peer's iax.conf. If the user is not specified,
-the peer will select one.
-
-Protocol and rationale:
-=======================
-IAX is a simple, low overhead and low bandwidth VoIP protocol designed to
-allow multiple Asterisk PBX's to communicate with one another without
-the overhead of more complex protocols like H.323. Payload is sent with
-a header overhead of only 4 octets. Control functions (and one payload packet
-per minute or so) is sent with a more complex header of 12 octets.
-
-IAX is slightly stateful.
-
-IAX contains two kinds of packets: The full header packet type, which
-contains much information about the frame, in addition to its contents,
-and the mini header type, which is used only for non-reliable voice
-packet delivery.
-
-All packets are immediately transmitted. Packets are received, but not
-delivered to the actual channels until a given time quantum has passed, in
-order to try to eliminate jitter.
-
-All full header packets must be ackd (except, obviously for the ACK packets
-themselves and not so obviously for hangup packets). The "timestamp" field of
-ack packets is not the normal offset, but rather a quote of the timestamp as
-included with the original packet that you're acking, and likewise the
-seqno field is the seqno of the packet you're acking, not your own seqno,
-and you do not increment your own sequence number. ACKing is based on the
-sequence number.
-
-See iax.h for a description of the frame formats.
-
-IAX internal frames use the AST_FRAME_IAX type. The subclass of these
-frames is the IAX control number, as seen in iax.h. The first frame sent
-must be an AST_FRAME_IAX with the control AST_IAX_CONTROL_NEW.
-
-The AST_IAX_CONTROL_NEW establishes a new connection.
-
-The first frame sent MUST be an AST_CONTROL_NEW to start a connection.
-
-IAX connnections may require authentication using either simple plaintext
-passwords or an md5 challenge/response pair.
-
diff --git a/1.2-netsec/doc/linkedlists.README b/1.2-netsec/doc/linkedlists.README
deleted file mode 100644
index 340933548..000000000
--- a/1.2-netsec/doc/linkedlists.README
+++ /dev/null
@@ -1,98 +0,0 @@
-As of 2004-12-23, this documentation is no longer maintained. The doxygen documentation
-generated from linkedlists.h should be referred to in its place, as it is more complete
-and better maintained.
-
-2nd version, implemented as macros.
-
- include <asterisk/linkedlists.h>
-
-AST_LIST_ENTRY declares pointers inside the object structure :
-
- struct ast_var_t {
- char *name;
- char *value;
- AST_LIST_ENTRY(ast_var_t) listpointers;
- };
-
-AST_LIST_HEAD declares a head structure, which is initialized
-to AST_LIST_HEAD_NULL :
-
- AST_LIST_HEAD(head, ast_var_t) head
-
-Next, we declare a pointer to this structure :
-
- struct headtype *headp = head;
-
-AST_LIST_INIT initializes the head pointer to a null value
-
- AST_LIST_INIT(headp);
-
-AST_LIST_INSERT_HEAD inserts an element to the head of the list :
-
- struct ast_var_t *node;
-
- node=malloc(sizeof(struct ast_var_t));
- (...we fill data in struct....)
- data->name=malloc(100);
- strcpy(data->name,"lalalalaa");
- etc etc
-
- (then we insert the node in the head of the list :)
-
- AST_LIST_INSERT_HEAD(headp,node,listpointers);
-
-AST_LIST_INSERT_HEAD_AFTER inserts an element after another :
-
- struct ast_var_t *node1;
- ...
- AST_LIST_INSERT_AFTER(node,node1,listpointers);
-
-AST_LIST_REMOVE removes an arbitrary element from the head:
-
- AST_LIST_REMOVE(headp,node1,ast_var_t,listpointers);
-
-AST_LIST_REMOVE_HEAD removes the entry at the head of the list and
-returns a pointer to the removed entry:
-
- AST_LIST_REMOVE_HEAD(headp,node,listpointers);
-
-AST_LIST_FIRST returns a pointer to the first element of the list;
-
- struct ast_var_t *firstnode;
- firstnode=AST_LIST_FIRST(headp);
-
-AST_LIST_NEXT returns a pointer to the next element :
-
- struct ast_var_t *nextnode;
- nextnode=AST_LIST_NEXT(firstnode,listpointers);
-
-AST_LIST_TRAVERSE traverses all elements of the list :
-
- struct ast_var_t *node;
-
- AST_LIST_TRAVERSE(headp,node,listpointers) {
- printf("%s\n",node->name);
- }
-
-AST_LIST_EMPTY evaluates to a true condition if there are no elements on
-the list.
-
-To completely delete a list :
-
- struct ast_var_t *vardata;
-
- while (!AST_LIST_EMPTY(headp)) { /* List Deletion. */
- vardata = AST_LIST_REMOVE_HEAD(head, ast_var_t, listpointers);
- free(vardata->name);
- free(vardata->value);
- }
-
-AST_LIST_LOCK returns true if it can lock the list, AST_LIST_UNLOCK unlocks
-the list :
-
-if (AST_LIST_LOCK(headp)) {
- ...do all list operations here...
- AST_LIST_UNLOCK(headp);
-} else {
- ast_log(LOG_WARNING,"List locked bla bla bla\n");
-}
diff --git a/1.2-netsec/doc/localchannel.txt b/1.2-netsec/doc/localchannel.txt
deleted file mode 100644
index f96ea15ec..000000000
--- a/1.2-netsec/doc/localchannel.txt
+++ /dev/null
@@ -1,49 +0,0 @@
-The Local channel
------------------
-
-chan_local is a pseudo-channel. Use of this channel simply loops calls back into the dialplan in a different context. Useful for recursive routing.
-
-* Syntax:
-
- Local/extension@context[/n]
-
-Adding "/n" at the end of the string will make the Local channel not do a native transfer (the "n" stands for "n"o release) upon the remote end answering the line. This is an esoteric, but important feature if you expect the Local channel to handle calls exactly like a normal channel. If you do not have the "no release" feature set, then as soon as the destination (inside of the Local channel) answers the line, the variables and dial plan will revert back to that of the original call, and the Local channel will become a zombie and be removed from the active channels list. This is desirable in some circumstances, but can result in unexpected dialplan behavior if you are doing fancy things with variables in your call handling.
-
-* Purpose:
-
-The Local channel construct can be used to establish dialing into any part of the dialplan.
-
-Imagine you have a TE410P in your box. You want to do something for which you must use a Dial statement (for instance when dropping files in /var/spool/outgoing) but you do want to be able to use your dialplans least-cost-routes or other intelligent stuff. What you could do before we had chan_local was create a cross-link between two ports of the TE410P and then Dial out one port and in the other. This way you could control where the call was going.
-
-Of course, this was a nasty hack, and to make it more sensible, chan_local was built.
-
-The "Local" channel driver allows you to convert an arbitrary extension into a channel. It is used in a variety of places, including agents, etc.
-
-This also allows us to hop to contexts like a GoSub routine; See examples below.
-
-Examples:
----------
-
-[inbound] ; here falls all incoming calls
-exten => s,1,Answer
-exten => s,2,Dial(local/200@internal,30,r)
-exten => s,3,Playback(sorrynoanswer)
-exten => s,4,Hangup
-
-[internal] ; here where our phones falls for default
-exten => 200,1,Dial(sip/blah)
-exten => 200,102,VoiceMail(${EXTEN}@default)
-
-exten => 201,1,Dial(zap/1)
-exten => 201,102,VoiceMail(${EXTEN}@default)
-
-exten => _0.,1,Dial(Zap/g1/${EXTEN:1}) ; outgoing calls with 0+number
-
-
-Caveats:
-If you use chan_local from a call-file and you want to pass channel variables into your context, make sure you append the '/n', because otherwise chan_local will 'optimize' itself out of the call-path, and the variables will get lost. i.e.
-
- Local/00531234567@pbx becomes Local/00531234567@pbx/n
-
-----------
-2004-01-17
diff --git a/1.2-netsec/doc/manager.txt b/1.2-netsec/doc/manager.txt
deleted file mode 100644
index bd5df8077..000000000
--- a/1.2-netsec/doc/manager.txt
+++ /dev/null
@@ -1,297 +0,0 @@
-The Asterisk Manager TCP/IP API - AMI
-=====================================
-
-The manager is a client/server model over TCP. With the manager interface,
-you'll be able to control the PBX, originate calls, check mailbox status,
-monitor channels and queues as well as execute Asterisk commands.
-
-AMI is the standard management interface into your Asterisk server.
-You configure AMI in manager.conf. By default, AMI is available on
-TCP port 5038 if you enable it in manager.conf.
-
-AMI receive commands, called "actions". These generate a "response"
-from Asterisk. Asterisk will also send "Events" containing various
-information messages about changes within Asterisk. Some actions
-generate an initial response and data in the form list of events.
-This format is created to make sure that extensive reports do not
-block the manager interface fully.
-
-Management users are configured in the configuration file manager.conf and are
-given permissions for read and write, where write represents their ability
-to perform this class of "action", and read represents their ability to
-receive this class of "event".
-
-The Asterisk manager interface in version 1.0.x of Asterisk is
-not very well standardized. Work is under way to change this
-to Asterisk 1.2. If you develop AMI applications, treat the headers
-in Actions, Events and Responses as local to that particular
-message. There is no cross-message standardization of headers.
-
-If you develop applications, please try to reuse existing manager
-headers and their interpretation. If you are unsure, discuss on
-the asterisk-dev mailing list.
-
-
-Command Syntax
---------------
-Management communication consists of tags of the form "header: value",
-terminated with an empty newline (\r\n) in the style of SMTP, HTTP, and
-other headers.
-
-
-The first tag MUST be one of the following:
-
- * Action: An action requested by the CLIENT to the Asterisk SERVER. Only one "Action" may be outstanding at any time.
- * Response: A response to an action from the Asterisk SERVER to the CLIENT.
- * Event: An event reported by the Asterisk SERVER to the CLIENT
-
-
-Manager commands
-----------------
-Output from the CLI command 'show manager' command:
-
- * Ping: Ping
- * Logoff: Logoff Manager
- * Hangup: Hangup Channel
- * Status: Status
- * Redirect: Redirect
- * Originate: Originate Call
- * MailboxStatus: Check Mailbox
- * Command: Execute Command
- * ExtensionState: Check Extension Status
- * AbsoluteTimeout: Set Absolute Timeout
- * MailboxCount: Check Mailbox Message Count
- * Monitor: Monitor a channel
- * StopMonitor: Stop monitoring a channel
- * ChangeMonitor: Change monitoring filename of a channel
- * IAXpeers: List IAX Peers (Defaults to IAX2)
- * SIPpeers: List SIP peers
- * SIPshowpeer: Show data about one SIP peer
- * Queues: Queues
- * QueueStatus: Queue Status
-
-This list depends on the version of Asterisk you are using, as
-well as which modules that are loaded.
-
-Command Summary
---------------
-
-Command: Command
-Parameters: Command
-
-Command: ExtensionState
-Parameters: Exten, Context, ActionID
-
-Command: Hangup
-Parameters: Channel
-
-Command: Logoff
-Parameters: None
-
-Command: MailboxCount
-Parameters: Mailbox, ActionID
-
-Command: MailboxStatus
-Parameters: Mailbox, ActionID
-
-Command: Originate
-Parameters: Channel, Exten, Context, Priority, Timeout,
- CallerID, Variable, Account, Application, Data, Async
-
-Command: Ping
-Parameters: None
-
-Command: Redirect
-Parameters: Channel, ExtraChannel, Exten, Context, Priority
-
-Command: Timeout
-Parameters: Channel, Timeout
-
-You can always get more information about a manager command
-with the "show manager command <command>" CLI command in Asterisk.
-
-Examples
---------
-Login - Log a user into the manager interface.
-
- Action: Login
- Username: testuser
- Secret: testsecret
-
-Originate - Originate a call from a channel to an extension.
-
- Action: Originate
- Channel: sip/12345
- Exten: 1234
- Context: default
-
-Originate - Originate a call from a channel to an extension without waiting
-for call to complete.
-
- Action: Originate
- Channel: sip/12345
- Exten: 1234
- Context: default
- Async: yes
-
-
-Redirect with ExtraChannel:
- Attempted goal:
- Have a 'robot' program Redirect both ends of an already-connected call
- to a meetme room using the ExtraChannel feature through the management interface.
-
- Action: Redirect
- Channel: Zap/1-1
- ExtraChannel: SIP/3064-7e00 (varies)
- Exten: 680
- Priority: 1
-
-Where 680 is an extension that sends you to a MeetMe room.
-
-There are a number of GUI tools that use the manager interface, please search
-the mailing list archives and the documentation page on the
-http://www.asterisk.org web site for more information.
-
-
-Some standard AMI headers:
---------------------------
-
- Account: -- Account Code (Status)
- AccountCode: -- Account Code (cdr_manager)
- ACL: <Y | N> -- Does ACL exist for object ?
- Action: <action> -- request or notification of a particular action
- Address-IP: -- IPaddress
- Address-Port: -- IP port number
- Agent: <string> -- Agent name
- AMAflags: -- AMA flag (cdr_manager, sippeers)
- AnswerTime: -- Time of answer (cdr_manager)
- Append: <bool> -- CDR userfield Append flag
- Application: -- Application to use
- Async: -- Whether or not to use fast setup
- AuthType: -- Authentication type (for login or challenge)
- "md5"
- BillableSeconds: -- Billable seconds for call (cdr_manager)
- CallerID: -- Caller id (name and number in Originate & cdr_manager)
- CallerID: -- CallerID number
- Number or "<unknown>" or "unknown"
- (should change to "<unknown>" in app_queue)
- CallerID1: -- Channel 1 CallerID (Link event)
- CallerID2: -- Channel 2 CallerID (Link event)
- CallerIDName: -- CallerID name
- Name or "<unknown>" or "unknown"
- (should change to "<unknown>" in app_queue)
- Callgroup: -- Call group for peer/user
- CallsTaken: <num> -- Queue status variable
- Cause: <value> -- Event change cause - "Expired"
- Cause: <value> -- Hangupcause (channel.c)
- CID-CallingPres: -- Caller ID calling presentation
- Channel: <channel> -- Channel specifier
- Channel: <dialstring> -- Dialstring in Originate
- Channel: <tech/[peer/username]> -- Channel in Registry events (SIP, IAX2)
- Channel: <tech> -- Technology (SIP/IAX2 etc) in Registry events
- ChannelType: -- Tech: SIP, IAX2, ZAP, MGCP etc
- Channel1: -- Link channel 1
- Channel2: -- Link channel 2
- ChanObjectType: -- "peer", "user"
- Codecs: -- Codec list
- CodecOrder: -- Codec order, separated with comma ","
- Command: -- Cli command to run
- Context: -- Context
- Count: <num> -- Number of callers in queue
- Data: -- Application data
- Default-addr-IP: -- IP address to use before registration
- Default-Username: -- Username part of URI to use before registration
- Destination: -- Destination for call (Dialstring ) (dial, cdr_manager)
- DestinationContext: -- Destination context (cdr_manager)
- DestinationChannel: -- Destination channel (cdr_manager)
- DestUniqueID: -- UniqueID of destination (dial event)
- Disposition: -- Call disposition (CDR manager)
- Domain: <domain> -- DNS domain
- Duration: <secs> -- Duration of call (cdr_manager)
- Dynamic: <Y | N> -- Device registration supported?
- Endtime: -- End time stamp of call (cdr_manager)
- EventList: <flag> -- Flag being "Start", "End", "Cancelled" or "ListObject"
- Events: <eventmask> -- Eventmask filter ("on", "off", "system", "call", "log")
- Exten: -- Extension (Redirect command)
- Extension: -- Extension (Status)
- Family: <string> -- ASTdb key family
- File: <filename> -- Filename (monitor)
- Format: <format> -- Format of sound file (monitor)
- From: <time> -- Parking time (ParkedCall event)
- Hint: -- Extension hint
- Incominglimit: -- SIP Peer incoming limit
- Key:
- Key: -- ASTdb Database key
- LastApplication: -- Last application executed (cdr_manager)
- LastCall: <num> -- Last call in queue
- LastData: -- Data for last application (cdr_manager)
- Link: -- (Status)
- ListItems: <number> -- Number of items in Eventlist (Optionally sent in "end" packet)
- Location: -- Interface (whatever that is -maybe tech/name in app_queue )
- Loginchan: -- Login channel for agent
- Logintime: <number> -- Login time for agent
- Mailbox: -- VM Mailbox (id@vmcontext) (mailboxstatus, mailboxcount)
- MD5SecretExist: <Y | N> -- Whether secret exists in MD5 format
- Membership: <string> -- "Dynamic" or "static" member in queue
- Message: <text> -- Text message in ACKs, errors (explanation)
- Mix: <bool> -- Boolean parameter (monitor)
- NewMessages: <count> -- Count of new Mailbox messages (mailboxcount)
- Newname:
- ObjectName: -- Name of object in list
- OldName: -- Something in Rename (channel.c)
- OldMessages: <count> -- Count of old mailbox messages (mailboxcount)
- Outgoinglimit: -- SIP Peer outgoing limit
- Paused: <num> -- Queue member paused status
- Peer: <tech/name> -- "channel" specifier :-)
- PeerStatus: <tech/name> -- Peer status code
- "Unregistred", "Registred", "Lagged", "Reachable"
- Penalty: <num> -- Queue penalty
- Priority: -- Extension priority
- Privilege: <privilege> -- AMI authorization class (system, call, log, verbose, command, agent, user)
- Pickupgroup: -- Pickup group for peer
- Position: <num> -- Position in Queue
- Queue: -- Queue name
- Reason: -- "Autologoff"
- Response: <response> -- response code, like "200 OK"
- "Success", "Error", "Follows"
- Restart: -- "True", "False"
- RegExpire: -- SIP registry expire
- RegExpiry: -- SIP registry expiry
- Reason: -- Originate reason code
- Seconds: -- Seconds (Status)
- Secret: <password> -- Authentication secret (for login)
- SecretExist: <Y | N> -- Whether secret exists
- Shutdown: -- "Uncleanly", "Cleanly"
- SIP-AuthInsecure:
- SIP-FromDomain: -- Peer FromDomain
- SIP-FromUser: -- Peer FromUser
- SIP-NatSupport:
- SIPLastMsg:
- Source: -- Source of call (dial event, cdr_manager)
- SrcUniqueID: -- UniqueID of source (dial event)
- StartTime: -- Start time of call (cdr_manager)
- State: -- Channel state
- Status: -- Registration status (Registry events SIP)
- Status: -- Extension status (Extensionstate)
- Status: -- Peer status (if monitored) ** Will change name **
- "unknown", "lagged", "ok"
- Status: <num> -- Queue Status
- Status: -- DND status (DNDState)
- Time: <sec> -- Roundtrip time (latency)
- Timeout: -- Parking timeout time
- Timeout: -- Timeout for call setup (Originate)
- Timeout: <seconds> -- Timout for call
- Uniqueid: -- Channel Unique ID
- Uniqueid1: -- Channel 1 Unique ID (Link event)
- Uniqueid2: -- Channel 2 Unique ID (Link event)
- User: -- Username (SIP registry)
- UserField: -- CDR userfield (cdr_manager)
- Val: -- Value to set/read in ASTdb
- Variable: -- Variable AND value to set (multiple separated with | in Originate)
- Variable: <name> -- For channel variables
- Value: <value> -- Value to set
- VoiceMailbox: -- VM Mailbox in SIPpeers
- Waiting: -- Count of mailbox messages (mailboxstatus)
-
- ** Please try to re-use existing headers to simplify manager message parsing in clients.
-
diff --git a/1.2-netsec/doc/model.txt b/1.2-netsec/doc/model.txt
deleted file mode 100644
index 10d2d0e05..000000000
--- a/1.2-netsec/doc/model.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-Description of call model:
-
-Incoming Call:
-
- Channel backend waits for a RING or equivalent on some sort of
-interface. Typically this is done in its own thread. When a RING is
-detected, the backend should create a channel structure and then call
-ast_pbx_start() on that channel, which will create a thread to monitor
-that interface. At this point, the PBX and/or applications it launches
-will manage the interface, and it need not be monitored by the
-aforementioned thread. When the applications are finished, the requisite
-hangup function will be called, at which the channel can be considered to
-be no longer valid, and the thread that controls it will imminently be
-terminated.
-
diff --git a/1.2-netsec/doc/modules.txt b/1.2-netsec/doc/modules.txt
deleted file mode 100644
index 4f6d4c67b..000000000
--- a/1.2-netsec/doc/modules.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-All modules must have at least the following functions:
-
-int load_module():
-
- Do what you need to do when you get started. This function
-returns 0 on success and non-zero on failure (it is not considered loaded
-if it fails.
-
-int unload_module():
-
- The module will soon be unloaded. If any channels are using your
-features, you should give them a softhangup in an effort to keep the
-program from crashing. Generally, unload_module is only called when the
-usecount is 0 or less, but the user can force unloading at their
-discretion, and thus a module should do its best to comply (although in
-some cases there may be no way to avoid a crash). This function should
-return 0 on success and non-zero on failure (i.e. it cannot yet be
-unloaded).
-
-char *description():
-
- Return a description of the module's functionality.
-
-int usecnt():
-
- Return the number of channels, etc that are using you.
diff --git a/1.2-netsec/doc/queuelog.txt b/1.2-netsec/doc/queuelog.txt
deleted file mode 100644
index a11812eef..000000000
--- a/1.2-netsec/doc/queuelog.txt
+++ /dev/null
@@ -1,77 +0,0 @@
-Queue Log Information
-=====================
-
-In order to properly manage ACD queues, it is important to be able to
-keep track of details of call setups and teardowns in much greater detail
-than traditional call detail records provide. In order to support this,
-extensive and detailed tracing of every queued call is stored in the
-queue log, located (by default) in /var/log/asterisk/queue_log.
-
-These are the events (and associated information) in the queue log:
-
-ABANDON(position|origposition|waittime)
-The caller abandoned their position in the queue. The position is the
-caller's position in the queue when they hungup, the origposition is
-the original position the caller was when they first entered the
-queue, and the waittime is how long the call had been waiting in the
-queue at the time of disconnect.
-
-AGENTDUMP
-The agent dumped the caller while listening to the queue announcement.
-
-AGENTLOGIN(channel)
-The agent logged in. The channel is recorded.
-
-AGENTCALLBACKLOGIN(exten@context)
-The callback agent logged in. The login extension and context is recorded.
-
-AGENTLOGOFF(channel|logintime)
-The agent logged off. The channel is recorded, along with the total time
-the agent was logged in.
-
-AGENTCALLBACKLOGOFF(exten@context|logintime|reason)
-The callback agent logged off. The last login extension and context is
-recorded, along with the total time the agent was logged in, and the
-reason for the logoff if it was not a normal logoff (e.g., Autologoff)
-
-COMPLETEAGENT(holdtime|calltime|origposition)
-The caller was connected to an agent, and the call was terminated normally
-by the *agent*. The caller's hold time and the length of the call are both
-recorded. The caller's original position in the queue is recorded in
-origposition.
-
-COMPLETECALLER(holdtime|calltime|origposition)
-The caller was connected to an agent, and the call was terminated normally
-by the *caller*. The caller's hold time and the length of the call are both
-recorded. The caller's original position in the queue is recorded in
-origposition.
-
-CONFIGRELOAD
-The configuration has been reloaded (e.g. with asterisk -rx reload)
-
-CONNECT(holdtime)
-The caller was connected to an agent. Hold time represents the amount
-of time the caller was on hold.
-
-ENTERQUEUE(url|callerid)
-A call has entered the queue. URL (if specified) and Caller*ID are placed
-in the log.
-
-EXITWITHKEY(key|position)
-The caller elected to use a menu key to exit the queue. The key and
-the caller's position in the queue are recorded.
-
-EXITWITHTIMEOUT(position)
-The caller was on hold too long and the timeout expired.
-
-QUEUESTART
-The queueing system has been started for the first time this session.
-
-SYSCOMPAT
-A call was answered by an agent, but the call was dropped because the
-channels were not compatible.
-
-TRANSFER(extension,context)
-Caller was transferred to a different extension. Context and extension
-are recorded.
-
diff --git a/1.2-netsec/dsp.c b/1.2-netsec/dsp.c
deleted file mode 100644
index e204f5360..000000000
--- a/1.2-netsec/dsp.c
+++ /dev/null
@@ -1,1724 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Goertzel routines are borrowed from Steve Underwood's tremendous work on the
- * DTMF detector.
- *
- * 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 Convenience Signal Processing routines
- *
- */
-
-/* Some routines from tone_detect.c by Steven Underwood as published under the zapata library */
-/*
- tone_detect.c - General telephony tone detection, and specific
- detection of DTMF.
-
- Copyright (C) 2001 Steve Underwood <steveu@coppice.org>
-
- Despite my general liking of the GPL, I place this code in the
- public domain for the benefit of all mankind - even the slimy
- ones who might try to proprietize my work and use it to my
- detriment.
-*/
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <math.h>
-#include <errno.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/frame.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/dsp.h"
-#include "asterisk/ulaw.h"
-#include "asterisk/alaw.h"
-
-/* Number of goertzels for progress detect */
-#define GSAMP_SIZE_NA 183 /* North America - 350, 440, 480, 620, 950, 1400, 1800 Hz */
-#define GSAMP_SIZE_CR 188 /* Costa Rica, Brazil - Only care about 425 Hz */
-#define GSAMP_SIZE_UK 160 /* UK disconnect goertzel feed - shoud trigger 400hz */
-
-#define PROG_MODE_NA 0
-#define PROG_MODE_CR 1
-#define PROG_MODE_UK 2
-
-/* For US modes */
-#define HZ_350 0
-#define HZ_440 1
-#define HZ_480 2
-#define HZ_620 3
-#define HZ_950 4
-#define HZ_1400 5
-#define HZ_1800 6
-
-/* For CR/BR modes */
-#define HZ_425 0
-
-/* For UK mode */
-#define HZ_400 0
-
-static struct progalias {
- char *name;
- int mode;
-} aliases[] = {
- { "us", PROG_MODE_NA },
- { "ca", PROG_MODE_NA },
- { "cr", PROG_MODE_CR },
- { "br", PROG_MODE_CR },
- { "uk", PROG_MODE_UK },
-};
-
-static struct progress {
- int size;
- int freqs[7];
-} modes[] = {
- { GSAMP_SIZE_NA, { 350, 440, 480, 620, 950, 1400, 1800 } }, /* North America */
- { GSAMP_SIZE_CR, { 425 } },
- { GSAMP_SIZE_UK, { 400 } },
-};
-
-#define DEFAULT_THRESHOLD 512
-
-#define BUSY_PERCENT 10 /* The percentage difference between the two last silence periods */
-#define BUSY_PAT_PERCENT 7 /* The percentage difference between measured and actual pattern */
-#define BUSY_THRESHOLD 100 /* Max number of ms difference between max and min times in busy */
-#define BUSY_MIN 75 /* Busy must be at least 80 ms in half-cadence */
-#define BUSY_MAX 3100 /* Busy can't be longer than 3100 ms in half-cadence */
-
-/* Remember last 15 units */
-#define DSP_HISTORY 15
-
-/* Define if you want the fax detector -- NOT RECOMMENDED IN -STABLE */
-#define FAX_DETECT
-
-#define TONE_THRESH 10.0 /* How much louder the tone should be than channel energy */
-#define TONE_MIN_THRESH 1e8 /* How much tone there should be at least to attempt */
-#define COUNT_THRESH 3 /* Need at least 50ms of stuff to count it */
-#define UK_HANGUP_THRESH 60 /* This is the threshold for the UK */
-
-
-#define MAX_DTMF_DIGITS 128
-
-/* Basic DTMF specs:
- *
- * Minimum tone on = 40ms
- * Minimum tone off = 50ms
- * Maximum digit rate = 10 per second
- * Normal twist <= 8dB accepted
- * Reverse twist <= 4dB accepted
- * S/N >= 15dB will detect OK
- * Attenuation <= 26dB will detect OK
- * Frequency tolerance +- 1.5% will detect, +-3.5% will reject
- */
-
-#define DTMF_THRESHOLD 8.0e7
-#define FAX_THRESHOLD 8.0e7
-#define FAX_2ND_HARMONIC 2.0 /* 4dB */
-#define DTMF_NORMAL_TWIST 6.3 /* 8dB */
-#ifdef RADIO_RELAX
-#define DTMF_REVERSE_TWIST ((digitmode & DSP_DIGITMODE_RELAXDTMF) ? 6.5 : 2.5) /* 4dB normal */
-#else
-#define DTMF_REVERSE_TWIST ((digitmode & DSP_DIGITMODE_RELAXDTMF) ? 4.0 : 2.5) /* 4dB normal */
-#endif
-#define DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */
-#define DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */
-#define DTMF_2ND_HARMONIC_ROW ((digitmode & DSP_DIGITMODE_RELAXDTMF) ? 1.7 : 2.5) /* 4dB normal */
-#define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */
-#define DTMF_TO_TOTAL_ENERGY 42.0
-
-#ifdef OLD_DSP_ROUTINES
-#define MF_THRESHOLD 8.0e7
-#define MF_NORMAL_TWIST 5.3 /* 8dB */
-#define MF_REVERSE_TWIST 4.0 /* was 2.5 */
-#define MF_RELATIVE_PEAK 5.3 /* 8dB */
-#define MF_2ND_HARMONIC 1.7 /* was 2.5 */
-#else
-#define BELL_MF_THRESHOLD 1.6e9
-#define BELL_MF_TWIST 4.0 /* 6dB */
-#define BELL_MF_RELATIVE_PEAK 12.6 /* 11dB */
-#endif
-
-#if !defined(BUSYDETECT_MARTIN) && !defined(BUSYDETECT) && !defined(BUSYDETECT_TONEONLY) && !defined(BUSYDETECT_COMPARE_TONE_AND_SILENCE)
-#define BUSYDETECT_MARTIN
-#endif
-
-typedef struct {
- float v2;
- float v3;
- float fac;
-#ifndef OLD_DSP_ROUTINES
- int samples;
-#endif
-} goertzel_state_t;
-
-typedef struct
-{
- goertzel_state_t row_out[4];
- goertzel_state_t col_out[4];
-#ifdef FAX_DETECT
- goertzel_state_t fax_tone;
-#endif
-#ifdef OLD_DSP_ROUTINES
- goertzel_state_t row_out2nd[4];
- goertzel_state_t col_out2nd[4];
-#ifdef FAX_DETECT
- goertzel_state_t fax_tone2nd;
-#endif
- int hit1;
- int hit2;
- int hit3;
- int hit4;
-#else
- int hits[3];
-#endif
- int mhit;
- float energy;
- int current_sample;
-
- char digits[MAX_DTMF_DIGITS + 1];
-
- int current_digits;
- int detected_digits;
- int lost_digits;
- int digit_hits[16];
-#ifdef FAX_DETECT
- int fax_hits;
-#endif
-} dtmf_detect_state_t;
-
-typedef struct
-{
- goertzel_state_t tone_out[6];
- int mhit;
-#ifdef OLD_DSP_ROUTINES
- int hit1;
- int hit2;
- int hit3;
- int hit4;
- goertzel_state_t tone_out2nd[6];
- float energy;
-#else
- int hits[5];
-#endif
- int current_sample;
-
- char digits[MAX_DTMF_DIGITS + 1];
-
- int current_digits;
- int detected_digits;
- int lost_digits;
-#ifdef FAX_DETECT
- int fax_hits;
-#endif
-} mf_detect_state_t;
-
-static float dtmf_row[] =
-{
- 697.0, 770.0, 852.0, 941.0
-};
-static float dtmf_col[] =
-{
- 1209.0, 1336.0, 1477.0, 1633.0
-};
-
-static float mf_tones[] =
-{
- 700.0, 900.0, 1100.0, 1300.0, 1500.0, 1700.0
-};
-
-#ifdef FAX_DETECT
-static float fax_freq = 1100.0;
-#endif
-
-static char dtmf_positions[] = "123A" "456B" "789C" "*0#D";
-
-#ifdef OLD_DSP_ROUTINES
-static char mf_hit[6][6] = {
- /* 700 + */ { 0, '1', '2', '4', '7', 'C' },
- /* 900 + */ { '1', 0, '3', '5', '8', 'A' },
- /* 1100 + */ { '2', '3', 0, '6', '9', '*' },
- /* 1300 + */ { '4', '5', '6', 0, '0', 'B' },
- /* 1500 + */ { '7', '8', '9', '0', 0, '#' },
- /* 1700 + */ { 'C', 'A', '*', 'B', '#', 0 },
-};
-#else
-static char bell_mf_positions[] = "1247C-358A--69*---0B----#";
-#endif
-
-static inline void goertzel_sample(goertzel_state_t *s, short sample)
-{
- float v1;
- float fsamp = sample;
-
- v1 = s->v2;
- s->v2 = s->v3;
- s->v3 = s->fac * s->v2 - v1 + fsamp;
-}
-
-static inline void goertzel_update(goertzel_state_t *s, short *samps, int count)
-{
- int i;
-
- for (i=0;i<count;i++)
- goertzel_sample(s, samps[i]);
-}
-
-
-static inline float goertzel_result(goertzel_state_t *s)
-{
- return s->v3 * s->v3 + s->v2 * s->v2 - s->v2 * s->v3 * s->fac;
-}
-
-static inline void goertzel_init(goertzel_state_t *s, float freq, int samples)
-{
- s->v2 = s->v3 = 0.0;
- s->fac = 2.0 * cos(2.0 * M_PI * (freq / 8000.0));
-#ifndef OLD_DSP_ROUTINES
- s->samples = samples;
-#endif
-}
-
-static inline void goertzel_reset(goertzel_state_t *s)
-{
- s->v2 = s->v3 = 0.0;
-}
-
-struct ast_dsp {
- struct ast_frame f;
- int threshold;
- int totalsilence;
- int totalnoise;
- int features;
- int busymaybe;
- int busycount;
- int busy_tonelength;
- int busy_quietlength;
- int historicnoise[DSP_HISTORY];
- int historicsilence[DSP_HISTORY];
- goertzel_state_t freqs[7];
- int freqcount;
- int gsamps;
- int gsamp_size;
- int progmode;
- int tstate;
- int tcount;
- int digitmode;
- int thinkdigit;
- float genergy;
- union {
- dtmf_detect_state_t dtmf;
- mf_detect_state_t mf;
- } td;
-};
-
-static void ast_dtmf_detect_init (dtmf_detect_state_t *s)
-{
- int i;
-
-#ifdef OLD_DSP_ROUTINES
- s->hit1 =
- s->mhit =
- s->hit3 =
- s->hit4 =
- s->hit2 = 0;
-#else
- s->hits[0] = s->hits[1] = s->hits[2] = 0;
-#endif
- for (i = 0; i < 4; i++) {
- goertzel_init (&s->row_out[i], dtmf_row[i], 102);
- goertzel_init (&s->col_out[i], dtmf_col[i], 102);
-#ifdef OLD_DSP_ROUTINES
- goertzel_init (&s->row_out2nd[i], dtmf_row[i] * 2.0, 102);
- goertzel_init (&s->col_out2nd[i], dtmf_col[i] * 2.0, 102);
-#endif
- s->energy = 0.0;
- }
-#ifdef FAX_DETECT
- /* Same for the fax dector */
- goertzel_init (&s->fax_tone, fax_freq, 102);
-
-#ifdef OLD_DSP_ROUTINES
- /* Same for the fax dector 2nd harmonic */
- goertzel_init (&s->fax_tone2nd, fax_freq * 2.0, 102);
-#endif
-#endif /* FAX_DETECT */
- s->current_sample = 0;
- s->detected_digits = 0;
- s->current_digits = 0;
- memset(&s->digits, 0, sizeof(s->digits));
- s->lost_digits = 0;
- s->digits[0] = '\0';
-}
-
-static void ast_mf_detect_init (mf_detect_state_t *s)
-{
- int i;
-#ifdef OLD_DSP_ROUTINES
- s->hit1 =
- s->hit2 = 0;
-#else
- s->hits[0] = s->hits[1] = s->hits[2] = s->hits[3] = s->hits[4] = 0;
-#endif
- for (i = 0; i < 6; i++) {
- goertzel_init (&s->tone_out[i], mf_tones[i], 160);
-#ifdef OLD_DSP_ROUTINES
- goertzel_init (&s->tone_out2nd[i], mf_tones[i] * 2.0, 160);
- s->energy = 0.0;
-#endif
- }
- s->current_digits = 0;
- memset(&s->digits, 0, sizeof(s->digits));
- s->current_sample = 0;
- s->detected_digits = 0;
- s->lost_digits = 0;
- s->digits[0] = '\0';
- s->mhit = 0;
-}
-
-static int dtmf_detect (dtmf_detect_state_t *s, int16_t amp[], int samples,
- int digitmode, int *writeback, int faxdetect)
-{
- float row_energy[4];
- float col_energy[4];
-#ifdef FAX_DETECT
- float fax_energy;
-#ifdef OLD_DSP_ROUTINES
- float fax_energy_2nd;
-#endif
-#endif /* FAX_DETECT */
- float famp;
- float v1;
- int i;
- int j;
- int sample;
- int best_row;
- int best_col;
- int hit;
- int limit;
-
- hit = 0;
- for (sample = 0; sample < samples; sample = limit) {
- /* 102 is optimised to meet the DTMF specs. */
- if ((samples - sample) >= (102 - s->current_sample))
- limit = sample + (102 - s->current_sample);
- else
- limit = samples;
-#if defined(USE_3DNOW)
- _dtmf_goertzel_update (s->row_out, amp + sample, limit - sample);
- _dtmf_goertzel_update (s->col_out, amp + sample, limit - sample);
-#ifdef OLD_DSP_ROUTINES
- _dtmf_goertzel_update (s->row_out2nd, amp + sample, limit2 - sample);
- _dtmf_goertzel_update (s->col_out2nd, amp + sample, limit2 - sample);
-#endif
- /* XXX Need to fax detect for 3dnow too XXX */
- #warning "Fax Support Broken"
-#else
- /* The following unrolled loop takes only 35% (rough estimate) of the
- time of a rolled loop on the machine on which it was developed */
- for (j=sample;j<limit;j++) {
- famp = amp[j];
- s->energy += famp*famp;
- /* With GCC 2.95, the following unrolled code seems to take about 35%
- (rough estimate) as long as a neat little 0-3 loop */
- v1 = s->row_out[0].v2;
- s->row_out[0].v2 = s->row_out[0].v3;
- s->row_out[0].v3 = s->row_out[0].fac*s->row_out[0].v2 - v1 + famp;
- v1 = s->col_out[0].v2;
- s->col_out[0].v2 = s->col_out[0].v3;
- s->col_out[0].v3 = s->col_out[0].fac*s->col_out[0].v2 - v1 + famp;
- v1 = s->row_out[1].v2;
- s->row_out[1].v2 = s->row_out[1].v3;
- s->row_out[1].v3 = s->row_out[1].fac*s->row_out[1].v2 - v1 + famp;
- v1 = s->col_out[1].v2;
- s->col_out[1].v2 = s->col_out[1].v3;
- s->col_out[1].v3 = s->col_out[1].fac*s->col_out[1].v2 - v1 + famp;
- v1 = s->row_out[2].v2;
- s->row_out[2].v2 = s->row_out[2].v3;
- s->row_out[2].v3 = s->row_out[2].fac*s->row_out[2].v2 - v1 + famp;
- v1 = s->col_out[2].v2;
- s->col_out[2].v2 = s->col_out[2].v3;
- s->col_out[2].v3 = s->col_out[2].fac*s->col_out[2].v2 - v1 + famp;
- v1 = s->row_out[3].v2;
- s->row_out[3].v2 = s->row_out[3].v3;
- s->row_out[3].v3 = s->row_out[3].fac*s->row_out[3].v2 - v1 + famp;
- v1 = s->col_out[3].v2;
- s->col_out[3].v2 = s->col_out[3].v3;
- s->col_out[3].v3 = s->col_out[3].fac*s->col_out[3].v2 - v1 + famp;
-#ifdef FAX_DETECT
- /* Update fax tone */
- v1 = s->fax_tone.v2;
- s->fax_tone.v2 = s->fax_tone.v3;
- s->fax_tone.v3 = s->fax_tone.fac*s->fax_tone.v2 - v1 + famp;
-#endif /* FAX_DETECT */
-#ifdef OLD_DSP_ROUTINES
- v1 = s->col_out2nd[0].v2;
- s->col_out2nd[0].v2 = s->col_out2nd[0].v3;
- s->col_out2nd[0].v3 = s->col_out2nd[0].fac*s->col_out2nd[0].v2 - v1 + famp;
- v1 = s->row_out2nd[0].v2;
- s->row_out2nd[0].v2 = s->row_out2nd[0].v3;
- s->row_out2nd[0].v3 = s->row_out2nd[0].fac*s->row_out2nd[0].v2 - v1 + famp;
- v1 = s->col_out2nd[1].v2;
- s->col_out2nd[1].v2 = s->col_out2nd[1].v3;
- s->col_out2nd[1].v3 = s->col_out2nd[1].fac*s->col_out2nd[1].v2 - v1 + famp;
- v1 = s->row_out2nd[1].v2;
- s->row_out2nd[1].v2 = s->row_out2nd[1].v3;
- s->row_out2nd[1].v3 = s->row_out2nd[1].fac*s->row_out2nd[1].v2 - v1 + famp;
- v1 = s->col_out2nd[2].v2;
- s->col_out2nd[2].v2 = s->col_out2nd[2].v3;
- s->col_out2nd[2].v3 = s->col_out2nd[2].fac*s->col_out2nd[2].v2 - v1 + famp;
- v1 = s->row_out2nd[2].v2;
- s->row_out2nd[2].v2 = s->row_out2nd[2].v3;
- s->row_out2nd[2].v3 = s->row_out2nd[2].fac*s->row_out2nd[2].v2 - v1 + famp;
- v1 = s->col_out2nd[3].v2;
- s->col_out2nd[3].v2 = s->col_out2nd[3].v3;
- s->col_out2nd[3].v3 = s->col_out2nd[3].fac*s->col_out2nd[3].v2 - v1 + famp;
- v1 = s->row_out2nd[3].v2;
- s->row_out2nd[3].v2 = s->row_out2nd[3].v3;
- s->row_out2nd[3].v3 = s->row_out2nd[3].fac*s->row_out2nd[3].v2 - v1 + famp;
-#ifdef FAX_DETECT
- /* Update fax tone */
- v1 = s->fax_tone.v2;
- s->fax_tone2nd.v2 = s->fax_tone2nd.v3;
- s->fax_tone2nd.v3 = s->fax_tone2nd.fac*s->fax_tone2nd.v2 - v1 + famp;
-#endif /* FAX_DETECT */
-#endif
- }
-#endif
- s->current_sample += (limit - sample);
- if (s->current_sample < 102) {
- if (hit && !((digitmode & DSP_DIGITMODE_NOQUELCH))) {
- /* If we had a hit last time, go ahead and clear this out since likely it
- will be another hit */
- for (i=sample;i<limit;i++)
- amp[i] = 0;
- *writeback = 1;
- }
- continue;
- }
-#ifdef FAX_DETECT
- /* Detect the fax energy, too */
- fax_energy = goertzel_result(&s->fax_tone);
-#endif
- /* We are at the end of a DTMF detection block */
- /* Find the peak row and the peak column */
- row_energy[0] = goertzel_result (&s->row_out[0]);
- col_energy[0] = goertzel_result (&s->col_out[0]);
-
- for (best_row = best_col = 0, i = 1; i < 4; i++) {
- row_energy[i] = goertzel_result (&s->row_out[i]);
- if (row_energy[i] > row_energy[best_row])
- best_row = i;
- col_energy[i] = goertzel_result (&s->col_out[i]);
- if (col_energy[i] > col_energy[best_col])
- best_col = i;
- }
- hit = 0;
- /* Basic signal level test and the twist test */
- if (row_energy[best_row] >= DTMF_THRESHOLD &&
- col_energy[best_col] >= DTMF_THRESHOLD &&
- col_energy[best_col] < row_energy[best_row]*DTMF_REVERSE_TWIST &&
- col_energy[best_col]*DTMF_NORMAL_TWIST > row_energy[best_row]) {
- /* Relative peak test */
- for (i = 0; i < 4; i++) {
- if ((i != best_col &&
- col_energy[i]*DTMF_RELATIVE_PEAK_COL > col_energy[best_col]) ||
- (i != best_row
- && row_energy[i]*DTMF_RELATIVE_PEAK_ROW > row_energy[best_row])) {
- break;
- }
- }
-#ifdef OLD_DSP_ROUTINES
- /* ... and second harmonic test */
- if (i >= 4 &&
- (row_energy[best_row] + col_energy[best_col]) > 42.0*s->energy &&
- goertzel_result(&s->col_out2nd[best_col])*DTMF_2ND_HARMONIC_COL < col_energy[best_col]
- && goertzel_result(&s->row_out2nd[best_row])*DTMF_2ND_HARMONIC_ROW < row_energy[best_row]) {
-#else
- /* ... and fraction of total energy test */
- if (i >= 4 &&
- (row_energy[best_row] + col_energy[best_col]) > DTMF_TO_TOTAL_ENERGY*s->energy) {
-#endif
- /* Got a hit */
- hit = dtmf_positions[(best_row << 2) + best_col];
- if (!(digitmode & DSP_DIGITMODE_NOQUELCH)) {
- /* Zero out frame data if this is part DTMF */
- for (i=sample;i<limit;i++)
- amp[i] = 0;
- *writeback = 1;
- }
- /* Look for two successive similar results */
- /* The logic in the next test is:
- We need two successive identical clean detects, with
- something different preceeding it. This can work with
- back to back differing digits. More importantly, it
- can work with nasty phones that give a very wobbly start
- to a digit */
-#ifdef OLD_DSP_ROUTINES
- if (hit == s->hit3 && s->hit3 != s->hit2) {
- s->mhit = hit;
- s->digit_hits[(best_row << 2) + best_col]++;
- s->detected_digits++;
- if (s->current_digits < MAX_DTMF_DIGITS) {
- s->digits[s->current_digits++] = hit;
- s->digits[s->current_digits] = '\0';
- } else {
- s->lost_digits++;
- }
- }
-#else
- if (hit == s->hits[2] && hit != s->hits[1] && hit != s->hits[0]) {
- s->mhit = hit;
- s->digit_hits[(best_row << 2) + best_col]++;
- s->detected_digits++;
- if (s->current_digits < MAX_DTMF_DIGITS) {
- s->digits[s->current_digits++] = hit;
- s->digits[s->current_digits] = '\0';
- } else {
- s->lost_digits++;
- }
- }
-#endif
- }
- }
-#ifdef FAX_DETECT
- if (!hit && (fax_energy >= FAX_THRESHOLD) &&
- (fax_energy >= DTMF_TO_TOTAL_ENERGY*s->energy) &&
- (faxdetect)) {
-#if 0
- printf("Fax energy/Second Harmonic: %f\n", fax_energy);
-#endif
- /* XXX Probably need better checking than just this the energy XXX */
- hit = 'f';
- s->fax_hits++;
- } else {
- if (s->fax_hits > 5) {
- hit = 'f';
- s->mhit = 'f';
- s->detected_digits++;
- if (s->current_digits < MAX_DTMF_DIGITS) {
- s->digits[s->current_digits++] = hit;
- s->digits[s->current_digits] = '\0';
- } else {
- s->lost_digits++;
- }
- }
- s->fax_hits = 0;
- }
-#endif /* FAX_DETECT */
-#ifdef OLD_DSP_ROUTINES
- s->hit1 = s->hit2;
- s->hit2 = s->hit3;
- s->hit3 = hit;
-#else
- s->hits[0] = s->hits[1];
- s->hits[1] = s->hits[2];
- s->hits[2] = hit;
-#endif
- /* Reinitialise the detector for the next block */
- for (i = 0; i < 4; i++) {
- goertzel_reset(&s->row_out[i]);
- goertzel_reset(&s->col_out[i]);
-#ifdef OLD_DSP_ROUTINES
- goertzel_reset(&s->row_out2nd[i]);
- goertzel_reset(&s->col_out2nd[i]);
-#endif
- }
-#ifdef FAX_DETECT
- goertzel_reset (&s->fax_tone);
-#ifdef OLD_DSP_ROUTINES
- goertzel_reset (&s->fax_tone2nd);
-#endif
-#endif
- s->energy = 0.0;
- s->current_sample = 0;
- }
- if ((!s->mhit) || (s->mhit != hit)) {
- s->mhit = 0;
- return(0);
- }
- return (hit);
-}
-
-/* MF goertzel size */
-#ifdef OLD_DSP_ROUTINES
-#define MF_GSIZE 160
-#else
-#define MF_GSIZE 120
-#endif
-
-static int mf_detect (mf_detect_state_t *s, int16_t amp[],
- int samples, int digitmode, int *writeback)
-{
-#ifdef OLD_DSP_ROUTINES
- float tone_energy[6];
- int best1;
- int best2;
- float max;
- int sofarsogood;
-#else
- float energy[6];
- int best;
- int second_best;
-#endif
- float famp;
- float v1;
- int i;
- int j;
- int sample;
- int hit;
- int limit;
-
- hit = 0;
- for (sample = 0; sample < samples; sample = limit) {
- /* 80 is optimised to meet the MF specs. */
- if ((samples - sample) >= (MF_GSIZE - s->current_sample))
- limit = sample + (MF_GSIZE - s->current_sample);
- else
- limit = samples;
-#if defined(USE_3DNOW)
- _dtmf_goertzel_update (s->row_out, amp + sample, limit - sample);
- _dtmf_goertzel_update (s->col_out, amp + sample, limit - sample);
-#ifdef OLD_DSP_ROUTINES
- _dtmf_goertzel_update (s->row_out2nd, amp + sample, limit2 - sample);
- _dtmf_goertzel_update (s->col_out2nd, amp + sample, limit2 - sample);
-#endif
- /* XXX Need to fax detect for 3dnow too XXX */
- #warning "Fax Support Broken"
-#else
- /* The following unrolled loop takes only 35% (rough estimate) of the
- time of a rolled loop on the machine on which it was developed */
- for (j = sample; j < limit; j++) {
- famp = amp[j];
-#ifdef OLD_DSP_ROUTINES
- s->energy += famp*famp;
-#endif
- /* With GCC 2.95, the following unrolled code seems to take about 35%
- (rough estimate) as long as a neat little 0-3 loop */
- v1 = s->tone_out[0].v2;
- s->tone_out[0].v2 = s->tone_out[0].v3;
- s->tone_out[0].v3 = s->tone_out[0].fac*s->tone_out[0].v2 - v1 + famp;
- v1 = s->tone_out[1].v2;
- s->tone_out[1].v2 = s->tone_out[1].v3;
- s->tone_out[1].v3 = s->tone_out[1].fac*s->tone_out[1].v2 - v1 + famp;
- v1 = s->tone_out[2].v2;
- s->tone_out[2].v2 = s->tone_out[2].v3;
- s->tone_out[2].v3 = s->tone_out[2].fac*s->tone_out[2].v2 - v1 + famp;
- v1 = s->tone_out[3].v2;
- s->tone_out[3].v2 = s->tone_out[3].v3;
- s->tone_out[3].v3 = s->tone_out[3].fac*s->tone_out[3].v2 - v1 + famp;
- v1 = s->tone_out[4].v2;
- s->tone_out[4].v2 = s->tone_out[4].v3;
- s->tone_out[4].v3 = s->tone_out[4].fac*s->tone_out[4].v2 - v1 + famp;
- v1 = s->tone_out[5].v2;
- s->tone_out[5].v2 = s->tone_out[5].v3;
- s->tone_out[5].v3 = s->tone_out[5].fac*s->tone_out[5].v2 - v1 + famp;
-#ifdef OLD_DSP_ROUTINES
- v1 = s->tone_out2nd[0].v2;
- s->tone_out2nd[0].v2 = s->tone_out2nd[0].v3;
- s->tone_out2nd[0].v3 = s->tone_out2nd[0].fac*s->tone_out2nd[0].v2 - v1 + famp;
- v1 = s->tone_out2nd[1].v2;
- s->tone_out2nd[1].v2 = s->tone_out2nd[1].v3;
- s->tone_out2nd[1].v3 = s->tone_out2nd[1].fac*s->tone_out2nd[1].v2 - v1 + famp;
- v1 = s->tone_out2nd[2].v2;
- s->tone_out2nd[2].v2 = s->tone_out2nd[2].v3;
- s->tone_out2nd[2].v3 = s->tone_out2nd[2].fac*s->tone_out2nd[2].v2 - v1 + famp;
- v1 = s->tone_out2nd[3].v2;
- s->tone_out2nd[3].v2 = s->tone_out2nd[3].v3;
- s->tone_out2nd[3].v3 = s->tone_out2nd[3].fac*s->tone_out2nd[3].v2 - v1 + famp;
- v1 = s->tone_out2nd[4].v2;
- s->tone_out2nd[4].v2 = s->tone_out2nd[4].v3;
- s->tone_out2nd[4].v3 = s->tone_out2nd[4].fac*s->tone_out2nd[2].v2 - v1 + famp;
- v1 = s->tone_out2nd[3].v2;
- s->tone_out2nd[5].v2 = s->tone_out2nd[6].v3;
- s->tone_out2nd[5].v3 = s->tone_out2nd[6].fac*s->tone_out2nd[3].v2 - v1 + famp;
-#endif
- }
-#endif
- s->current_sample += (limit - sample);
- if (s->current_sample < MF_GSIZE) {
- if (hit && !((digitmode & DSP_DIGITMODE_NOQUELCH))) {
- /* If we had a hit last time, go ahead and clear this out since likely it
- will be another hit */
- for (i=sample;i<limit;i++)
- amp[i] = 0;
- *writeback = 1;
- }
- continue;
- }
-#ifdef OLD_DSP_ROUTINES
- /* We're at the end of an MF detection block. Go ahead and calculate
- all the energies. */
- for (i=0;i<6;i++) {
- tone_energy[i] = goertzel_result(&s->tone_out[i]);
- }
- /* Find highest */
- best1 = 0;
- max = tone_energy[0];
- for (i=1;i<6;i++) {
- if (tone_energy[i] > max) {
- max = tone_energy[i];
- best1 = i;
- }
- }
-
- /* Find 2nd highest */
- if (best1) {
- max = tone_energy[0];
- best2 = 0;
- } else {
- max = tone_energy[1];
- best2 = 1;
- }
-
- for (i=0;i<6;i++) {
- if (i == best1) continue;
- if (tone_energy[i] > max) {
- max = tone_energy[i];
- best2 = i;
- }
- }
- hit = 0;
- if (best1 != best2)
- sofarsogood=1;
- else
- sofarsogood=0;
- /* Check for relative energies */
- for (i=0;i<6;i++) {
- if (i == best1)
- continue;
- if (i == best2)
- continue;
- if (tone_energy[best1] < tone_energy[i] * MF_RELATIVE_PEAK) {
- sofarsogood = 0;
- break;
- }
- if (tone_energy[best2] < tone_energy[i] * MF_RELATIVE_PEAK) {
- sofarsogood = 0;
- break;
- }
- }
-
- if (sofarsogood) {
- /* Check for 2nd harmonic */
- if (goertzel_result(&s->tone_out2nd[best1]) * MF_2ND_HARMONIC > tone_energy[best1])
- sofarsogood = 0;
- else if (goertzel_result(&s->tone_out2nd[best2]) * MF_2ND_HARMONIC > tone_energy[best2])
- sofarsogood = 0;
- }
- if (sofarsogood) {
- hit = mf_hit[best1][best2];
- if (!(digitmode & DSP_DIGITMODE_NOQUELCH)) {
- /* Zero out frame data if this is part DTMF */
- for (i=sample;i<limit;i++)
- amp[i] = 0;
- *writeback = 1;
- }
- /* Look for two consecutive clean hits */
- if ((hit == s->hit3) && (s->hit3 != s->hit2)) {
- s->mhit = hit;
- s->detected_digits++;
- if (s->current_digits < MAX_DTMF_DIGITS - 2) {
- s->digits[s->current_digits++] = hit;
- s->digits[s->current_digits] = '\0';
- } else {
- s->lost_digits++;
- }
- }
- }
-
- s->hit1 = s->hit2;
- s->hit2 = s->hit3;
- s->hit3 = hit;
- /* Reinitialise the detector for the next block */
- for (i = 0; i < 6; i++) {
- goertzel_reset(&s->tone_out[i]);
- goertzel_reset(&s->tone_out2nd[i]);
- }
- s->energy = 0.0;
- s->current_sample = 0;
- }
-#else
- /* We're at the end of an MF detection block. */
- /* Find the two highest energies. The spec says to look for
- two tones and two tones only. Taking this literally -ie
- only two tones pass the minimum threshold - doesn't work
- well. The sinc function mess, due to rectangular windowing
- ensure that! Find the two highest energies and ensure they
- are considerably stronger than any of the others. */
- energy[0] = goertzel_result(&s->tone_out[0]);
- energy[1] = goertzel_result(&s->tone_out[1]);
- if (energy[0] > energy[1]) {
- best = 0;
- second_best = 1;
- } else {
- best = 1;
- second_best = 0;
- }
- /*endif*/
- for (i=2;i<6;i++) {
- energy[i] = goertzel_result(&s->tone_out[i]);
- if (energy[i] >= energy[best]) {
- second_best = best;
- best = i;
- } else if (energy[i] >= energy[second_best]) {
- second_best = i;
- }
- }
- /* Basic signal level and twist tests */
- hit = 0;
- if (energy[best] >= BELL_MF_THRESHOLD && energy[second_best] >= BELL_MF_THRESHOLD
- && energy[best] < energy[second_best]*BELL_MF_TWIST
- && energy[best]*BELL_MF_TWIST > energy[second_best]) {
- /* Relative peak test */
- hit = -1;
- for (i=0;i<6;i++) {
- if (i != best && i != second_best) {
- if (energy[i]*BELL_MF_RELATIVE_PEAK >= energy[second_best]) {
- /* The best two are not clearly the best */
- hit = 0;
- break;
- }
- }
- }
- }
- if (hit) {
- /* Get the values into ascending order */
- if (second_best < best) {
- i = best;
- best = second_best;
- second_best = i;
- }
- best = best*5 + second_best - 1;
- hit = bell_mf_positions[best];
- /* Look for two successive similar results */
- /* The logic in the next test is:
- For KP we need 4 successive identical clean detects, with
- two blocks of something different preceeding it. For anything
- else we need two successive identical clean detects, with
- two blocks of something different preceeding it. */
- if (hit == s->hits[4] && hit == s->hits[3] &&
- ((hit != '*' && hit != s->hits[2] && hit != s->hits[1])||
- (hit == '*' && hit == s->hits[2] && hit != s->hits[1] &&
- hit != s->hits[0]))) {
- s->detected_digits++;
- if (s->current_digits < MAX_DTMF_DIGITS) {
- s->digits[s->current_digits++] = hit;
- s->digits[s->current_digits] = '\0';
- } else {
- s->lost_digits++;
- }
- }
- } else {
- hit = 0;
- }
- s->hits[0] = s->hits[1];
- s->hits[1] = s->hits[2];
- s->hits[2] = s->hits[3];
- s->hits[3] = s->hits[4];
- s->hits[4] = hit;
- /* Reinitialise the detector for the next block */
- for (i = 0; i < 6; i++)
- goertzel_reset(&s->tone_out[i]);
- s->current_sample = 0;
- }
-#endif
- if ((!s->mhit) || (s->mhit != hit)) {
- s->mhit = 0;
- return(0);
- }
- return (hit);
-}
-
-static int __ast_dsp_digitdetect(struct ast_dsp *dsp, short *s, int len, int *writeback)
-{
- int res;
-
- if (dsp->digitmode & DSP_DIGITMODE_MF)
- res = mf_detect(&dsp->td.mf, s, len, dsp->digitmode & DSP_DIGITMODE_RELAXDTMF, writeback);
- else
- res = dtmf_detect(&dsp->td.dtmf, s, len, dsp->digitmode & DSP_DIGITMODE_RELAXDTMF, writeback, dsp->features & DSP_FEATURE_FAX_DETECT);
- return res;
-}
-
-int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *inf)
-{
- short *s;
- int len;
- int ign=0;
-
- if (inf->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n");
- return 0;
- }
- if (inf->subclass != AST_FORMAT_SLINEAR) {
- ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n");
- return 0;
- }
- s = inf->data;
- len = inf->datalen / 2;
- return __ast_dsp_digitdetect(dsp, s, len, &ign);
-}
-
-static inline int pair_there(float p1, float p2, float i1, float i2, float e)
-{
- /* See if p1 and p2 are there, relative to i1 and i2 and total energy */
- /* Make sure absolute levels are high enough */
- if ((p1 < TONE_MIN_THRESH) || (p2 < TONE_MIN_THRESH))
- return 0;
- /* Amplify ignored stuff */
- i2 *= TONE_THRESH;
- i1 *= TONE_THRESH;
- e *= TONE_THRESH;
- /* Check first tone */
- if ((p1 < i1) || (p1 < i2) || (p1 < e))
- return 0;
- /* And second */
- if ((p2 < i1) || (p2 < i2) || (p2 < e))
- return 0;
- /* Guess it's there... */
- return 1;
-}
-
-int ast_dsp_getdigits (struct ast_dsp *dsp, char *buf, int max)
-{
- if (dsp->digitmode & DSP_DIGITMODE_MF) {
- if (max > dsp->td.mf.current_digits)
- max = dsp->td.mf.current_digits;
- if (max > 0) {
- memcpy(buf, dsp->td.mf.digits, max);
- memmove(dsp->td.mf.digits, dsp->td.mf.digits + max, dsp->td.mf.current_digits - max);
- dsp->td.mf.current_digits -= max;
- }
- buf[max] = '\0';
- return max;
- } else {
- if (max > dsp->td.dtmf.current_digits)
- max = dsp->td.dtmf.current_digits;
- if (max > 0) {
- memcpy (buf, dsp->td.dtmf.digits, max);
- memmove (dsp->td.dtmf.digits, dsp->td.dtmf.digits + max, dsp->td.dtmf.current_digits - max);
- dsp->td.dtmf.current_digits -= max;
- }
- buf[max] = '\0';
- return max;
- }
-}
-
-static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
-{
- int x;
- int y;
- int pass;
- int newstate = DSP_TONE_STATE_SILENCE;
- int res = 0;
- int thresh = (dsp->progmode == PROG_MODE_UK) ? UK_HANGUP_THRESH : COUNT_THRESH;
- while(len) {
- /* Take the lesser of the number of samples we need and what we have */
- pass = len;
- if (pass > dsp->gsamp_size - dsp->gsamps)
- pass = dsp->gsamp_size - dsp->gsamps;
- for (x=0;x<pass;x++) {
- for (y=0;y<dsp->freqcount;y++)
- goertzel_sample(&dsp->freqs[y], s[x]);
- dsp->genergy += s[x] * s[x];
- }
- s += pass;
- dsp->gsamps += pass;
- len -= pass;
- if (dsp->gsamps == dsp->gsamp_size) {
- float hz[7];
- for (y=0;y<7;y++)
- hz[y] = goertzel_result(&dsp->freqs[y]);
-#if 0
- printf("\n350: 425: 440: 480: 620: 950: 1400: 1800: Energy: \n");
- printf("%.2e %.2e %.2e %.2e %.2e %.2e %.2e %.2e %.2e\n",
- hz[HZ_350], hz[HZ_425], hz[HZ_440], hz[HZ_480], hz[HZ_620], hz[HZ_950], hz[HZ_1400], hz[HZ_1800], dsp->genergy);
-#endif
- switch(dsp->progmode) {
- case PROG_MODE_NA:
- if (pair_there(hz[HZ_480], hz[HZ_620], hz[HZ_350], hz[HZ_440], dsp->genergy)) {
- newstate = DSP_TONE_STATE_BUSY;
- } else if (pair_there(hz[HZ_440], hz[HZ_480], hz[HZ_350], hz[HZ_620], dsp->genergy)) {
- newstate = DSP_TONE_STATE_RINGING;
- } else if (pair_there(hz[HZ_350], hz[HZ_440], hz[HZ_480], hz[HZ_620], dsp->genergy)) {
- newstate = DSP_TONE_STATE_DIALTONE;
- } else if (hz[HZ_950] > TONE_MIN_THRESH * TONE_THRESH) {
- newstate = DSP_TONE_STATE_SPECIAL1;
- } else if (hz[HZ_1400] > TONE_MIN_THRESH * TONE_THRESH) {
- if (dsp->tstate == DSP_TONE_STATE_SPECIAL1)
- newstate = DSP_TONE_STATE_SPECIAL2;
- } else if (hz[HZ_1800] > TONE_MIN_THRESH * TONE_THRESH) {
- if (dsp->tstate == DSP_TONE_STATE_SPECIAL2)
- newstate = DSP_TONE_STATE_SPECIAL3;
- } else if (dsp->genergy > TONE_MIN_THRESH * TONE_THRESH) {
- newstate = DSP_TONE_STATE_TALKING;
- } else
- newstate = DSP_TONE_STATE_SILENCE;
- break;
- case PROG_MODE_CR:
- if (hz[HZ_425] > TONE_MIN_THRESH * TONE_THRESH) {
- newstate = DSP_TONE_STATE_RINGING;
- } else if (dsp->genergy > TONE_MIN_THRESH * TONE_THRESH) {
- newstate = DSP_TONE_STATE_TALKING;
- } else
- newstate = DSP_TONE_STATE_SILENCE;
- break;
- case PROG_MODE_UK:
- if (hz[HZ_400] > TONE_MIN_THRESH * TONE_THRESH) {
- newstate = DSP_TONE_STATE_HUNGUP;
- }
- break;
- default:
- ast_log(LOG_WARNING, "Can't process in unknown prog mode '%d'\n", dsp->progmode);
- }
- if (newstate == dsp->tstate) {
- dsp->tcount++;
- if (dsp->tcount == thresh) {
- if ((dsp->features & DSP_PROGRESS_BUSY) &&
- dsp->tstate == DSP_TONE_STATE_BUSY) {
- res = AST_CONTROL_BUSY;
- dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
- } else if ((dsp->features & DSP_PROGRESS_TALK) &&
- dsp->tstate == DSP_TONE_STATE_TALKING) {
- res = AST_CONTROL_ANSWER;
- dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
- } else if ((dsp->features & DSP_PROGRESS_RINGING) &&
- dsp->tstate == DSP_TONE_STATE_RINGING)
- res = AST_CONTROL_RINGING;
- else if ((dsp->features & DSP_PROGRESS_CONGESTION) &&
- dsp->tstate == DSP_TONE_STATE_SPECIAL3) {
- res = AST_CONTROL_CONGESTION;
- dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
- } else if ((dsp->features & DSP_FEATURE_CALL_PROGRESS) &&
- dsp->tstate == DSP_TONE_STATE_HUNGUP) {
- res = AST_CONTROL_HANGUP;
- dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
- }
- }
- } else {
-#if 0
- printf("Newstate: %d\n", newstate);
-#endif
- dsp->tstate = newstate;
- dsp->tcount = 1;
- }
-
- /* Reset goertzel */
- for (x=0;x<7;x++)
- dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0;
- dsp->gsamps = 0;
- dsp->genergy = 0.0;
- }
- }
-#if 0
- if (res)
- printf("Returning %d\n", res);
-#endif
- return res;
-}
-
-int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf)
-{
- if (inf->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n");
- return 0;
- }
- if (inf->subclass != AST_FORMAT_SLINEAR) {
- ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n");
- return 0;
- }
- return __ast_dsp_call_progress(dsp, inf->data, inf->datalen / 2);
-}
-
-static int __ast_dsp_silence(struct ast_dsp *dsp, short *s, int len, int *totalsilence)
-{
- int accum;
- int x;
- int res = 0;
-
- if (!len)
- return 0;
- accum = 0;
- for (x=0;x<len; x++)
- accum += abs(s[x]);
- accum /= len;
- if (accum < dsp->threshold) {
- /* Silent */
- dsp->totalsilence += len/8;
- if (dsp->totalnoise) {
- /* Move and save history */
- memmove(dsp->historicnoise + DSP_HISTORY - dsp->busycount, dsp->historicnoise + DSP_HISTORY - dsp->busycount +1, dsp->busycount*sizeof(dsp->historicnoise[0]));
- dsp->historicnoise[DSP_HISTORY - 1] = dsp->totalnoise;
-/* we don't want to check for busydetect that frequently */
-#if 0
- dsp->busymaybe = 1;
-#endif
- }
- dsp->totalnoise = 0;
- res = 1;
- } else {
- /* Not silent */
- dsp->totalnoise += len/8;
- if (dsp->totalsilence) {
- int silence1 = dsp->historicsilence[DSP_HISTORY - 1];
- int silence2 = dsp->historicsilence[DSP_HISTORY - 2];
- /* Move and save history */
- memmove(dsp->historicsilence + DSP_HISTORY - dsp->busycount, dsp->historicsilence + DSP_HISTORY - dsp->busycount + 1, dsp->busycount*sizeof(dsp->historicsilence[0]));
- dsp->historicsilence[DSP_HISTORY - 1] = dsp->totalsilence;
- /* check if the previous sample differs only by BUSY_PERCENT from the one before it */
- if (silence1 < silence2) {
- if (silence1 + silence1*BUSY_PERCENT/100 >= silence2)
- dsp->busymaybe = 1;
- else
- dsp->busymaybe = 0;
- } else {
- if (silence1 - silence1*BUSY_PERCENT/100 <= silence2)
- dsp->busymaybe = 1;
- else
- dsp->busymaybe = 0;
- }
- }
- dsp->totalsilence = 0;
- }
- if (totalsilence)
- *totalsilence = dsp->totalsilence;
- return res;
-}
-
-#ifdef BUSYDETECT_MARTIN
-int ast_dsp_busydetect(struct ast_dsp *dsp)
-{
- int res = 0, x;
-#ifndef BUSYDETECT_TONEONLY
- int avgsilence = 0, hitsilence = 0;
-#endif
- int avgtone = 0, hittone = 0;
- if (!dsp->busymaybe)
- return res;
- for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) {
-#ifndef BUSYDETECT_TONEONLY
- avgsilence += dsp->historicsilence[x];
-#endif
- avgtone += dsp->historicnoise[x];
- }
-#ifndef BUSYDETECT_TONEONLY
- avgsilence /= dsp->busycount;
-#endif
- avgtone /= dsp->busycount;
- for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) {
-#ifndef BUSYDETECT_TONEONLY
- if (avgsilence > dsp->historicsilence[x]) {
- if (avgsilence - (avgsilence*BUSY_PERCENT/100) <= dsp->historicsilence[x])
- hitsilence++;
- } else {
- if (avgsilence + (avgsilence*BUSY_PERCENT/100) >= dsp->historicsilence[x])
- hitsilence++;
- }
-#endif
- if (avgtone > dsp->historicnoise[x]) {
- if (avgtone - (avgtone*BUSY_PERCENT/100) <= dsp->historicnoise[x])
- hittone++;
- } else {
- if (avgtone + (avgtone*BUSY_PERCENT/100) >= dsp->historicnoise[x])
- hittone++;
- }
- }
-#ifndef BUSYDETECT_TONEONLY
- if ((hittone >= dsp->busycount - 1) && (hitsilence >= dsp->busycount - 1) &&
- (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX) &&
- (avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) {
-#else
- if ((hittone >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) {
-#endif
-#ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE
-#ifdef BUSYDETECT_TONEONLY
-#error You cant use BUSYDETECT_TONEONLY together with BUSYDETECT_COMPARE_TONE_AND_SILENCE
-#endif
- if (avgtone > avgsilence) {
- if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence)
- res = 1;
- } else {
- if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence)
- res = 1;
- }
-#else
- res = 1;
-#endif
- }
- /* If we know the expected busy tone length, check we are in the range */
- if (res && (dsp->busy_tonelength > 0)) {
- if (abs(avgtone - dsp->busy_tonelength) > (dsp->busy_tonelength*BUSY_PAT_PERCENT/100)) {
-#if 0
- ast_log(LOG_NOTICE, "busy detector: avgtone of %d not close enough to desired %d\n",
- avgtone, dsp->busy_tonelength);
-#endif
- res = 0;
- }
- }
- /* If we know the expected busy tone silent-period length, check we are in the range */
- if (res && (dsp->busy_quietlength > 0)) {
- if (abs(avgsilence - dsp->busy_quietlength) > (dsp->busy_quietlength*BUSY_PAT_PERCENT/100)) {
-#if 0
- ast_log(LOG_NOTICE, "busy detector: avgsilence of %d not close enough to desired %d\n",
- avgsilence, dsp->busy_quietlength);
-#endif
- res = 0;
- }
- }
-#if 1
- if (res)
- ast_log(LOG_DEBUG, "ast_dsp_busydetect detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
-#endif
- return res;
-}
-#endif
-
-#ifdef BUSYDETECT
-int ast_dsp_busydetect(struct ast_dsp *dsp)
-{
- int x;
- int res = 0;
- int max, min;
-
-#if 0
- if (dsp->busy_hits > 5);
- return 0;
-#endif
- if (dsp->busymaybe) {
-#if 0
- printf("Maybe busy!\n");
-#endif
- dsp->busymaybe = 0;
- min = 9999;
- max = 0;
- for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) {
-#if 0
- printf("Silence: %d, Noise: %d\n", dsp->historicsilence[x], dsp->historicnoise[x]);
-#endif
- if (dsp->historicsilence[x] < min)
- min = dsp->historicsilence[x];
- if (dsp->historicnoise[x] < min)
- min = dsp->historicnoise[x];
- if (dsp->historicsilence[x] > max)
- max = dsp->historicsilence[x];
- if (dsp->historicnoise[x] > max)
- max = dsp->historicnoise[x];
- }
- if ((max - min < BUSY_THRESHOLD) && (max < BUSY_MAX) && (min > BUSY_MIN)) {
-#if 0
- printf("Busy!\n");
-#endif
- res = 1;
- }
-#if 0
- printf("Min: %d, max: %d\n", min, max);
-#endif
- }
- return res;
-}
-#endif
-
-int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
-{
- short *s;
- int len;
-
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n");
- return 0;
- }
- if (f->subclass != AST_FORMAT_SLINEAR) {
- ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n");
- return 0;
- }
- s = f->data;
- len = f->datalen/2;
- return __ast_dsp_silence(dsp, s, len, totalsilence);
-}
-
-struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *af)
-{
- int silence;
- int res;
- int digit;
- int x;
- short *shortdata;
- unsigned char *odata;
- int len;
- int writeback = 0;
-
-#define FIX_INF(inf) do { \
- if (writeback) { \
- switch(inf->subclass) { \
- case AST_FORMAT_SLINEAR: \
- break; \
- case AST_FORMAT_ULAW: \
- for (x=0;x<len;x++) \
- odata[x] = AST_LIN2MU((unsigned short)shortdata[x]); \
- break; \
- case AST_FORMAT_ALAW: \
- for (x=0;x<len;x++) \
- odata[x] = AST_LIN2A((unsigned short)shortdata[x]); \
- break; \
- } \
- } \
- } while(0)
-
- if (!af)
- return NULL;
- if (af->frametype != AST_FRAME_VOICE)
- return af;
- odata = af->data;
- len = af->datalen;
- /* Make sure we have short data */
- switch(af->subclass) {
- case AST_FORMAT_SLINEAR:
- shortdata = af->data;
- len = af->datalen / 2;
- break;
- case AST_FORMAT_ULAW:
- shortdata = alloca(af->datalen * 2);
- if (!shortdata) {
- ast_log(LOG_WARNING, "Unable to allocate stack space for data: %s\n", strerror(errno));
- return af;
- }
- for (x=0;x<len;x++)
- shortdata[x] = AST_MULAW(odata[x]);
- break;
- case AST_FORMAT_ALAW:
- shortdata = alloca(af->datalen * 2);
- if (!shortdata) {
- ast_log(LOG_WARNING, "Unable to allocate stack space for data: %s\n", strerror(errno));
- return af;
- }
- for (x=0;x<len;x++)
- shortdata[x] = AST_ALAW(odata[x]);
- break;
- default:
- ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass));
- return af;
- }
- silence = __ast_dsp_silence(dsp, shortdata, len, NULL);
- if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) {
- memset(&dsp->f, 0, sizeof(dsp->f));
- dsp->f.frametype = AST_FRAME_NULL;
- return &dsp->f;
- }
- if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) {
- chan->_softhangup |= AST_SOFTHANGUP_DEV;
- memset(&dsp->f, 0, sizeof(dsp->f));
- dsp->f.frametype = AST_FRAME_CONTROL;
- dsp->f.subclass = AST_CONTROL_BUSY;
- ast_log(LOG_DEBUG, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name);
- return &dsp->f;
- }
- if ((dsp->features & DSP_FEATURE_DTMF_DETECT)) {
- digit = __ast_dsp_digitdetect(dsp, shortdata, len, &writeback);
-#if 0
- if (digit)
- printf("Performing digit detection returned %d, digitmode is %d\n", digit, dsp->digitmode);
-#endif
- if (dsp->digitmode & (DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX)) {
- if (!dsp->thinkdigit) {
- if (digit) {
- /* Looks like we might have something.
- * Request a conference mute for the moment */
- memset(&dsp->f, 0, sizeof(dsp->f));
- dsp->f.frametype = AST_FRAME_DTMF;
- dsp->f.subclass = 'm';
- dsp->thinkdigit = 'x';
- FIX_INF(af);
- if (chan)
- ast_queue_frame(chan, af);
- ast_frfree(af);
- return &dsp->f;
- }
- } else {
- if (digit) {
- /* Thought we saw one last time. Pretty sure we really have now */
- if (dsp->thinkdigit) {
- if ((dsp->thinkdigit != 'x') && (dsp->thinkdigit != digit)) {
- /* If we found a digit, and we're changing digits, go
- ahead and send this one, but DON'T stop confmute because
- we're detecting something else, too... */
- memset(&dsp->f, 0, sizeof(dsp->f));
- dsp->f.frametype = AST_FRAME_DTMF;
- dsp->f.subclass = dsp->thinkdigit;
- FIX_INF(af);
- if (chan)
- ast_queue_frame(chan, af);
- ast_frfree(af);
- }
- dsp->thinkdigit = digit;
- return &dsp->f;
- }
- dsp->thinkdigit = digit;
- } else {
- if (dsp->thinkdigit) {
- memset(&dsp->f, 0, sizeof(dsp->f));
- if (dsp->thinkdigit != 'x') {
- /* If we found a digit, send it now */
- dsp->f.frametype = AST_FRAME_DTMF;
- dsp->f.subclass = dsp->thinkdigit;
- dsp->thinkdigit = 0;
- } else {
- dsp->f.frametype = AST_FRAME_DTMF;
- dsp->f.subclass = 'u';
- dsp->thinkdigit = 0;
- }
- FIX_INF(af);
- if (chan)
- ast_queue_frame(chan, af);
- ast_frfree(af);
- return &dsp->f;
- }
- }
- }
- } else if (!digit) {
- /* Only check when there is *not* a hit... */
- if (dsp->digitmode & DSP_DIGITMODE_MF) {
- if (dsp->td.mf.current_digits) {
- memset(&dsp->f, 0, sizeof(dsp->f));
- dsp->f.frametype = AST_FRAME_DTMF;
- dsp->f.subclass = dsp->td.mf.digits[0];
- memmove(dsp->td.mf.digits, dsp->td.mf.digits + 1, dsp->td.mf.current_digits);
- dsp->td.mf.current_digits--;
- FIX_INF(af);
- if (chan)
- ast_queue_frame(chan, af);
- ast_frfree(af);
- return &dsp->f;
- }
- } else {
- if (dsp->td.dtmf.current_digits) {
- memset(&dsp->f, 0, sizeof(dsp->f));
- dsp->f.frametype = AST_FRAME_DTMF;
- dsp->f.subclass = dsp->td.dtmf.digits[0];
- memmove(dsp->td.dtmf.digits, dsp->td.dtmf.digits + 1, dsp->td.dtmf.current_digits);
- dsp->td.dtmf.current_digits--;
- FIX_INF(af);
- if (chan)
- ast_queue_frame(chan, af);
- ast_frfree(af);
- return &dsp->f;
- }
- }
- }
- }
- if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) {
- res = __ast_dsp_call_progress(dsp, shortdata, len);
- if (res) {
- switch(res) {
- case AST_CONTROL_ANSWER:
- case AST_CONTROL_BUSY:
- case AST_CONTROL_RINGING:
- case AST_CONTROL_CONGESTION:
- case AST_CONTROL_HANGUP:
- memset(&dsp->f, 0, sizeof(dsp->f));
- dsp->f.frametype = AST_FRAME_CONTROL;
- dsp->f.subclass = res;
- dsp->f.src = "dsp_progress";
- if (chan)
- ast_queue_frame(chan, &dsp->f);
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res);
- }
- }
- }
- FIX_INF(af);
- return af;
-}
-
-static void ast_dsp_prog_reset(struct ast_dsp *dsp)
-{
- int max = 0;
- int x;
-
- dsp->gsamp_size = modes[dsp->progmode].size;
- dsp->gsamps = 0;
- for (x=0;x<sizeof(modes[dsp->progmode].freqs) / sizeof(modes[dsp->progmode].freqs[0]);x++) {
- if (modes[dsp->progmode].freqs[x]) {
- goertzel_init(&dsp->freqs[x], (float)modes[dsp->progmode].freqs[x], dsp->gsamp_size);
- max = x + 1;
- }
- }
- dsp->freqcount = max;
-}
-
-struct ast_dsp *ast_dsp_new(void)
-{
- struct ast_dsp *dsp;
-
- dsp = malloc(sizeof(struct ast_dsp));
- if (dsp) {
- memset(dsp, 0, sizeof(struct ast_dsp));
- dsp->threshold = DEFAULT_THRESHOLD;
- dsp->features = DSP_FEATURE_SILENCE_SUPPRESS;
- dsp->busycount = DSP_HISTORY;
- /* Initialize DTMF detector */
- ast_dtmf_detect_init(&dsp->td.dtmf);
- /* Initialize initial DSP progress detect parameters */
- ast_dsp_prog_reset(dsp);
- }
- return dsp;
-}
-
-void ast_dsp_set_features(struct ast_dsp *dsp, int features)
-{
- dsp->features = features;
-}
-
-void ast_dsp_free(struct ast_dsp *dsp)
-{
- free(dsp);
-}
-
-void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold)
-{
- dsp->threshold = threshold;
-}
-
-void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences)
-{
- if (cadences < 4)
- cadences = 4;
- if (cadences > DSP_HISTORY)
- cadences = DSP_HISTORY;
- dsp->busycount = cadences;
-}
-
-void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, int tonelength, int quietlength)
-{
- dsp->busy_tonelength = tonelength;
- dsp->busy_quietlength = quietlength;
- ast_log(LOG_DEBUG, "dsp busy pattern set to %d,%d\n", tonelength, quietlength);
-}
-
-void ast_dsp_digitreset(struct ast_dsp *dsp)
-{
- int i;
-
- dsp->thinkdigit = 0;
- if (dsp->digitmode & DSP_DIGITMODE_MF) {
- memset(dsp->td.mf.digits, 0, sizeof(dsp->td.mf.digits));
- dsp->td.mf.current_digits = 0;
- /* Reinitialise the detector for the next block */
- for (i = 0; i < 6; i++) {
- goertzel_reset(&dsp->td.mf.tone_out[i]);
-#ifdef OLD_DSP_ROUTINES
- goertzel_reset(&dsp->td.mf.tone_out2nd[i]);
-#endif
- }
-#ifdef OLD_DSP_ROUTINES
- dsp->td.mf.energy = 0.0;
- dsp->td.mf.hit1 = dsp->td.mf.hit2 = dsp->td.mf.hit3 = dsp->td.mf.hit4 = dsp->td.mf.mhit = 0;
-#else
- dsp->td.mf.hits[4] = dsp->td.mf.hits[3] = dsp->td.mf.hits[2] = dsp->td.mf.hits[1] = dsp->td.mf.hits[0] = dsp->td.mf.mhit = 0;
-#endif
- dsp->td.mf.current_sample = 0;
- } else {
- memset(dsp->td.dtmf.digits, 0, sizeof(dsp->td.dtmf.digits));
- dsp->td.dtmf.current_digits = 0;
- /* Reinitialise the detector for the next block */
- for (i = 0; i < 4; i++) {
- goertzel_reset(&dsp->td.dtmf.row_out[i]);
- goertzel_reset(&dsp->td.dtmf.col_out[i]);
-#ifdef OLD_DSP_ROUTINES
- goertzel_reset(&dsp->td.dtmf.row_out2nd[i]);
- goertzel_reset(&dsp->td.dtmf.col_out2nd[i]);
-#endif
- }
-#ifdef FAX_DETECT
- goertzel_reset (&dsp->td.dtmf.fax_tone);
-#endif
-#ifdef OLD_DSP_ROUTINES
-#ifdef FAX_DETECT
- goertzel_reset (&dsp->td.dtmf.fax_tone2nd);
-#endif
- dsp->td.dtmf.hit1 = dsp->td.dtmf.hit2 = dsp->td.dtmf.hit3 = dsp->td.dtmf.hit4 = dsp->td.dtmf.mhit = 0;
-#else
- dsp->td.dtmf.hits[2] = dsp->td.dtmf.hits[1] = dsp->td.dtmf.hits[0] = dsp->td.dtmf.mhit = 0;
-#endif
- dsp->td.dtmf.energy = 0.0;
- dsp->td.dtmf.current_sample = 0;
- }
-}
-
-void ast_dsp_reset(struct ast_dsp *dsp)
-{
- int x;
-
- dsp->totalsilence = 0;
- dsp->gsamps = 0;
- for (x=0;x<4;x++)
- dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0;
- memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence));
- memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise));
-}
-
-int ast_dsp_digitmode(struct ast_dsp *dsp, int digitmode)
-{
- int new;
- int old;
-
- old = dsp->digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
- new = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
- if (old != new) {
- /* Must initialize structures if switching from MF to DTMF or vice-versa */
- if (new & DSP_DIGITMODE_MF)
- ast_mf_detect_init(&dsp->td.mf);
- else
- ast_dtmf_detect_init(&dsp->td.dtmf);
- }
- dsp->digitmode = digitmode;
- return 0;
-}
-
-int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone)
-{
- int x;
-
- for (x=0;x<sizeof(aliases) / sizeof(aliases[0]);x++) {
- if (!strcasecmp(aliases[x].name, zone)) {
- dsp->progmode = aliases[x].mode;
- ast_dsp_prog_reset(dsp);
- return 0;
- }
- }
- return -1;
-}
-
-int ast_dsp_get_tstate(struct ast_dsp *dsp)
-{
- return dsp->tstate;
-}
-
-int ast_dsp_get_tcount(struct ast_dsp *dsp)
-{
- return dsp->tcount;
-}
diff --git a/1.2-netsec/ecdisa.h b/1.2-netsec/ecdisa.h
deleted file mode 100644
index df6f773a0..000000000
--- a/1.2-netsec/ecdisa.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* ecdisa.h: Generated from frequency 2100
- by gentone. 80 samples */
-static unsigned char ecdisa[80] = {
- 255, 143, 58, 16, 171, 146, 34, 20,
- 156, 151, 25, 26, 149, 159, 19, 38,
- 145, 177, 16, 73, 143, 73, 16, 177,
- 145, 38, 19, 159, 149, 26, 25, 151,
- 156, 20, 34, 146, 171, 16, 58, 143,
- 255, 15, 186, 144, 43, 18, 162, 148,
- 28, 23, 153, 154, 21, 31, 147, 166,
- 17, 49, 144, 201, 15, 201, 144, 49,
- 17, 166, 147, 31, 21, 154, 153, 23,
- 28, 148, 162, 18, 43, 144, 186, 15,
-
-};
diff --git a/1.2-netsec/editline/CHANGES b/1.2-netsec/editline/CHANGES
deleted file mode 100644
index c18b56cdf..000000000
--- a/1.2-netsec/editline/CHANGES
+++ /dev/null
@@ -1,42 +0,0 @@
-2002-02-25 : Christos Zoulas <christos@netbsd.org>
- * Bring in constification fixes from NetBSD tree.
- * Use NetBSD's vis, fgetln
-
-2002-02-10 : Jason Evans <jasone@freebsd.org>
-
- * Makefile.in : Append "" arguments to for loops, to avoid syntax errors
- with some shells that occur if there are no arguments to the for
- loops.
-
-2002-02-09 : Jason Evans <jasone@freebsd.org>
-
- * Install man pages in @prefix@/man/, rather than @prefix@/share/man.
-
- * Fix the Darwin -install_name S_LDFLAGS argument to default to a prefix
- of /usr/local if --prefix is not specified.
-
-2002-02-05 : Jason Evans <jasone@freebsd.org>
-
- * Convert to using an autoconf-generated config.h, rather than passing
- -D_HAVE_<foo>=1 definitions on the command line. Include sys.h in
- config.h, and include config.h in .c files rather than sys.h.
-
- * Mangle function names for implementations in the np directory in order
- to avoid namespace collisions with other code that may provide copies
- of the same unimplemented functions. For example:
-
- #define fgetln libedit_fgetln
-
-2002-02-03 : Jason Evans <jasone@freebsd.org>
-
- * Add autoconf infrastructure, plus a generic Makefile that works with
- at least BSD make, GNU make and Sun make.
-
- * Port and/or test on FreeBSD 4.5, FreeBSD-current, NetBSD 1.5 (sparc64
- and arm32), Apple OS X 10.1.2, Solaris 2.6, and Red Hat Linux 2.6.
- Add the np directory, which contains implementations of non-portable
- functions.
-
- * Add the LIBEDIT_MAJOR and LIBEDIT_MINOR macros to histedit.h, since
- there is otherwise no straightforward method of programmatically
- detecting the library version.
diff --git a/1.2-netsec/editline/INSTALL b/1.2-netsec/editline/INSTALL
deleted file mode 100644
index 16fb6ffd1..000000000
--- a/1.2-netsec/editline/INSTALL
+++ /dev/null
@@ -1,64 +0,0 @@
-Building this distribution in many cases is as simple as typing the following
-while in the root directory of the source tree:
-
- ./configure
- make
-
-To install, do the above, then type:
-
- make install
-
-Additional build targets of finer granularity include:
-
- lib_a
- lib_s
- install_hdr
- install_lib
- install_lib_a
- install_lib_s
- install_man
- test
-
-Cleanup targets include:
-
- clean
- distclean
-
-Optionally, pass any of the following (not a definitive list) arguments to
-'configure':
-
---prefix=<install-root-dir>
- Set the base directory in which to install. For example:
-
- ./configure --prefix=/usr/local
-
- will cause files to be installed into /usr/local/bin, /usr/local/man,
- /usr/local/include, /usr/local/lib, and /usr/local/share.
-
---disable-readline
- By default, libedit is built and installed such that it works as a
- drop-in replacement for the readline library. This option turns that
- behavior off.
-
---enable-debug
- Build debugging code (for libedit development).
-
-Optionally, define environment variables, including (not exclusively):
-
-CFLAGS="?"
- Pass these flags to the compiler. You probably shouldn't define this
- unless you know what you are doing.
-
-CPPFLAGS="?"
- Pass these flags to the C preprocessor. Note that CFLAGS is not passed
- to 'cpp' when 'configure' is looking for include files, so you must use
- CPPFLAGS instead if you need to help 'configure' find header files.
-
-LD_LIBRARY_PATH="?"
- 'ld' uses this colon-separated list to find libraries.
-
-LDFLAGS="?"
- Flags passed to 'gcc', which should normally be passed on to 'ld'.
-
-PATH="?"
- 'configure' uses this to find programs.
diff --git a/1.2-netsec/editline/Makefile.in b/1.2-netsec/editline/Makefile.in
deleted file mode 100644
index 805642281..000000000
--- a/1.2-netsec/editline/Makefile.in
+++ /dev/null
@@ -1,233 +0,0 @@
-#
-# Generic Makefile for libedit.
-#
-
-OSTYPE=$(shell uname -s)
-define cyg_subst_sys
- if uname -s | grep -qi cygwin; then \
- cat $@ | sed -e s/"sys\.h"/"config.h"/g > $@.copy; \
- mv --force $@.copy $@; \
- fi
-endef
-
-SHELL = /bin/sh
-
-CC = @CC@
-AR = @AR@
-RANLIB = @RANLIB@
-CPPFLAGS = @CPPFLAGS@ -I.
-CFLAGS = @CFLAGS@
-A_CFLAGS = @A_CFLAGS@
-S_CFLAGS = @S_CFLAGS@
-LDFLAGS = @LDFLAGS@
-S_LDFLAGS = @S_LDFLAGS@
-LIBS = @LIBS@
-
-INSTALL = @INSTALL@
-PREFIX = @prefix@
-
-ifeq ($(OSTYPE),SunOS)
-CFLAGS+=-DSOLARIS -I../include/solaris-compat
-endif
-
-# .c files.
-ACSRCS = @ACSRCS@
-BCSRCS = @BCSRCS@
-CCSRCS = @CCSRCS@
-
-# Generated .c files.
-AGCSRCS = @AGCSRCS@
-BGCSRCS = @BGCSRCS@
-
-# .h files.
-HDRS = @HDRS@
-
-# Generated .h files.
-AGHDRS = @AGHDRS@
-BGHDRS = @BGHDRS@
-
-# Installed .h files.
-IHDRS = @IHDRS@
-IHDR_LINKS = @IHDR_LINKS@
-HDR_DIRS = @HDR_DIRS@
-
-# Man pages.
-MAN3 = @MAN3@
-MAN5 = @MAN5@
-MAN3_LINKS = @MAN3_LINKS@
-MAN_DIRS = @MAN_DIRS@
-
-# Library.
-LIB_DIRS = @LIB_DIRS@
-LIB_VER = @LIB_VER@
-LIB_A = @LIB_A@
-LIB_A_LINKS = @LIB_A_LINKS@
-LIB_S = @LIB_S@
-LIB_S_LINKS = @LIB_S_LINKS@
-
-# Test program.
-TEST = @TEST@
-TCSRCS = @TCSRCS@
-
-# Clear out all paths, then set just one (default path) for the main build
-# directory.
-.PATH :
-.PATH : .
-
-.SUFFIXES :
-.SUFFIXES : .c .o .o_a .o_s
-
-all : lib_a lib_s
-
-lib_a : $(LIB_A)
-lib_s : $(LIB_S)
-
-test : $(TEST)
-
-install : install_hdr install_lib install_man
-
-install_hdr :
- @for i in $(HDR_DIRS) ; do \
- echo "$(INSTALL) -d $(PREFIX)/$$i/"; \
- $(INSTALL) -d $(PREFIX)/$$i/; \
- done
- @for i in $(IHDRS); do \
- echo "$(INSTALL) -m 0444 $$i $(PREFIX)/include/`dirname $$i`/"; \
- $(INSTALL) -m 0444 $$i $(PREFIX)/include/`dirname $$i`/; \
- done
- @f=; \
- for i in $(IHDR_LINKS) ""; do \
- if test -z "$$f" ; then \
- f=$$i; \
- else \
- echo "rm -f $(PREFIX)/include/$$i"; \
- rm -f $(PREFIX)/include/$$i; \
- echo "ln -s $$f $(PREFIX)/include/$$i"; \
- ln -s $$f $(PREFIX)/include/$$i; \
- f=; \
- fi; \
- done
-
-install_lib : install_lib_a install_lib_s
-
-install_lib_common :
- @for i in $(LIB_DIRS) ; do \
- echo "$(INSTALL) -d $(PREFIX)/$$i/"; \
- $(INSTALL) -d $(PREFIX)/$$i/; \
- done
-
-install_lib_a : $(LIB_A) install_lib_common
- $(INSTALL) -m 0644 $(LIB_A) $(PREFIX)/lib/
- @f=; \
- for i in $(LIB_A_LINKS) ""; do \
- if test -z "$$f" ; then \
- f=$$i; \
- else \
- echo "rm -f $(PREFIX)/lib/$$i"; \
- rm -f $(PREFIX)/lib/$$i; \
- echo "ln -s $$f $(PREFIX)/lib/$$i"; \
- ln -s $$f $(PREFIX)/lib/$$i; \
- f=; \
- fi; \
- done
-
-install_lib_s : $(LIB_S) install_lib_common
- $(INSTALL) -m 0755 $(LIB_S) $(PREFIX)/lib/
- @f=; \
- for i in $(LIB_S_LINKS) ""; do \
- if test -z "$$f" ; then \
- f=$$i; \
- else \
- echo "rm -f $(PREFIX)/lib/$$i"; \
- rm -f $(PREFIX)/lib/$$i; \
- echo "ln -s $$f $(PREFIX)/lib/$$i"; \
- ln -s $$f $(PREFIX)/lib/$$i; \
- f=; \
- fi; \
- done
-
-install_man :
- @for i in $(MAN_DIRS) ; do \
- echo "$(INSTALL) -d $(PREFIX)/$$i/"; \
- $(INSTALL) -d $(PREFIX)/$$i/; \
- done
- @for i in $(MAN3); do \
- echo $(INSTALL) -m 0444 $$i $(PREFIX)/man/man3/; \
- $(INSTALL) -m 0444 $$i $(PREFIX)/man/man3/; \
- done
- @f=; \
- for i in $(MAN3_LINKS) ""; do \
- if test -z "$$f" ; then \
- f=$$i; \
- else \
- echo "rm -f $(PREFIX)/man/man3/$$i"; \
- rm -f $(PREFIX)/man/man3/$$i; \
- echo "ln -s $$f $(PREFIX)/man/man3/$$i"; \
- ln -s $$f $(PREFIX)/man/man3/$$i; \
- f=; \
- fi; \
- done
- @for i in $(MAN5); do\
- echo $(INSTALL) -m 0444 $$i $(PREFIX)/man/man5/; \
- $(INSTALL) -m 0444 $$i $(PREFIX)/man/man5/; \
- done
-
-clean :
- rm -f $(AGCSRCS) $(BGCSRCS) $(AGHDRS) $(BGHDRS) $(LIB_A) $(LIB_S)
- rm -f $(BGCSRCS:.c=.o_a) $(CCSRCS:.c=.o_a)
- rm -f $(BGCSRCS:.c=.o_s) $(CCSRCS:.c=.o_s)
- rm -f $(TCSRCS:.c=.o) $(TEST)
-
-distclean : clean
- rm -f config.cache config.log config.status config.h Makefile
-
-#
-# Internal targets and rules.
-#
-
-$(LIB_A) : $(BGCSRCS:.c=.o_a) $(CCSRCS:.c=.o_a)
- $(AR) cru $@ $?
- $(RANLIB) $@
-
-$(LIB_S) : $(BGCSRCS:.c=.o_s) $(CCSRCS:.c=.o_s)
- $(CC) $(S_LDFLAGS) -o $@ $(BGCSRCS:.c=.o_s) $(CCSRCS:.c=.o_s) $(LIBS)
-
-$(TEST) : $(TCSRCS:.c=.o) $(LIB_A)
- $(CC) -o $@ $(TCSRCS:.c=.o) $(LIB_A) $(LIBS)
-
-common.h : common.c
- $(SHELL) makelist -h common.c > $@
-
-emacs.h : emacs.c
- $(SHELL) makelist -h emacs.c> $@
-
-vi.h : vi.c
- $(SHELL) makelist -h vi.c > $@
-
-fcns.h : $(AGHDRS)
- $(SHELL) makelist -fh $(AGHDRS) > $@
-
-fcns.c : $(AGHDRS) fcns.h
- $(SHELL) makelist -fc $(AGHDRS) > $@
- $(cyg_subst_sys)
-
-help.h : $(ACSRCS)
- $(SHELL) makelist -bh $(ACSRCS) > $@
-
-help.c : $(ACSRCS) help.h
- $(SHELL) makelist -bc $(ACSRCS) > $@
- $(cyg_subst_sys)
-
-editline.c : $(ACSRCS) $(BCSRCS) $(AGCSRCS)
- $(SHELL) makelist -e $(ACSRCS) $(BCSRCS) $(AGCSRCS) > $@
-
-.c.o :
- $(CC) -c $(A_CFLAGS) $(CFLAGS) $(CPPFLAGS) $< -o $@
-
-.c.o_a : $(AGHDRS) $(BGHDRS)
- $(CC) -c $(A_CFLAGS) $(CFLAGS) $(CPPFLAGS) $< -o $@
-
-.c.o_s : $(AGHDRS) $(BGHDRS)
- $(CC) -c $(S_CFLAGS) $(CFLAGS) $(CPPFLAGS) $< -o $@
-
-$(CCSRCS) : $(BGHDRS)
diff --git a/1.2-netsec/editline/PLATFORMS b/1.2-netsec/editline/PLATFORMS
deleted file mode 100644
index ea7c5bb68..000000000
--- a/1.2-netsec/editline/PLATFORMS
+++ /dev/null
@@ -1,13 +0,0 @@
-This distribution of libedit is expected to work on at least the following
-platforms. It may also work on additional platforms, but no explicit support
-for them is built into the configuration system.
-
-* Apple OS X 10.1.
-
-* FreeBSD 4.x.
-
-* NetBSD 1.5.
-
-* Red Hat Linux 7.2.
-
-* Sun Solaris 2.6.
diff --git a/1.2-netsec/editline/README b/1.2-netsec/editline/README
deleted file mode 100644
index 49a2a6947..000000000
--- a/1.2-netsec/editline/README
+++ /dev/null
@@ -1,11 +0,0 @@
-libedit is a command line editing and history library. It is designed to be
-used by interactive programs that allow the user to type commands at a terminal
-prompt.
-
-The following files may be of direct interest to the user:
-
-* CHANGES - Software change log.
-
-* INSTALL - Installation information.
-
-* PLATFORMS - Supported platforms and platform-specific information.
diff --git a/1.2-netsec/editline/TEST/test.c b/1.2-netsec/editline/TEST/test.c
deleted file mode 100644
index 3169a2071..000000000
--- a/1.2-netsec/editline/TEST/test.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/* $NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
- The Regents of the University of California. All rights reserved.\n");
-#endif /* not lint */
-
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * test.c: A little test program
- */
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/wait.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <dirent.h>
-
-#include "histedit.h"
-#include "tokenizer.h"
-
-static int continuation = 0;
-static EditLine *el = NULL;
-
-static u_char complete(EditLine *, int);
- int main(int, char **);
-static char *prompt(EditLine *);
-static void sig(int);
-
-static char *
-prompt(EditLine *el)
-{
- static char a[] = "Edit$";
- static char b[] = "Edit>";
-
- return (continuation ? b : a);
-}
-
-static void
-sig(int i)
-{
-
- (void) fprintf(stderr, "Got signal %d.\n", i);
- el_reset(el);
-}
-
-static unsigned char
-complete(EditLine *el, int ch)
-{
- DIR *dd = opendir(".");
- struct dirent *dp;
- const char* ptr;
- const LineInfo *lf = el_line(el);
- int len;
-
- /*
- * Find the last word
- */
- for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
- continue;
- len = lf->cursor - ++ptr;
-
- for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
- if (len > strlen(dp->d_name))
- continue;
- if (strncmp(dp->d_name, ptr, len) == 0) {
- closedir(dd);
- if (el_insertstr(el, &dp->d_name[len]) == -1)
- return (CC_ERROR);
- else
- return (CC_REFRESH);
- }
- }
-
- closedir(dd);
- return (CC_ERROR);
-}
-
-int
-main(int argc, char *argv[])
-{
- int num;
- const char *buf;
- Tokenizer *tok;
-#if 0
- int lastevent = 0;
-#endif
- int ncontinuation;
- History *hist;
- HistEvent ev;
-
- (void) signal(SIGINT, sig);
- (void) signal(SIGQUIT, sig);
- (void) signal(SIGHUP, sig);
- (void) signal(SIGTERM, sig);
-
- hist = history_init(); /* Init the builtin history */
- /* Remember 100 events */
- history(hist, &ev, H_SETSIZE, 100);
-
- tok = tok_init(NULL); /* Initialize the tokenizer */
-
- /* Initialize editline */
- el = el_init(*argv, stdin, stdout, stderr);
-
- el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
- el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
- el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
-
- /* Tell editline to use this history interface */
- el_set(el, EL_HIST, history, hist);
-
- /* Add a user-defined function */
- el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
-
- /* Bind tab to it */
- el_set(el, EL_BIND, "^I", "ed-complete", NULL);
-
- /*
- * Bind j, k in vi command mode to previous and next line, instead
- * of previous and next history.
- */
- el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
- el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
-
- /*
- * Source the user's defaults file.
- */
- el_source(el, NULL);
-
- while ((buf = el_gets(el, &num)) != NULL && num != 0) {
- int ac;
- const char **av;
-#ifdef DEBUG
- (void) fprintf(stderr, "got %d %s", num, buf);
-#endif
- if (!continuation && num == 1)
- continue;
-
- ncontinuation = tok_line(tok, buf, &ac, &av) > 0;
-#if 0
- if (continuation) {
- /*
- * Append to the right event in case the user
- * moved around in history.
- */
- if (history(hist, &ev, H_SET, lastevent) == -1)
- err(1, "%d: %s\n", lastevent, ev.str);
- history(hist, &ev, H_ADD , buf);
- } else {
- history(hist, &ev, H_ENTER, buf);
- lastevent = ev.num;
- }
-#else
- /* Simpler */
- history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf);
-#endif
-
- continuation = ncontinuation;
- ncontinuation = 0;
-
- if (strcmp(av[0], "history") == 0) {
- int rv;
-
- switch (ac) {
- case 1:
- for (rv = history(hist, &ev, H_LAST); rv != -1;
- rv = history(hist, &ev, H_PREV))
- (void) fprintf(stdout, "%4d %s",
- ev.num, ev.str);
- break;
-
- case 2:
- if (strcmp(av[1], "clear") == 0)
- history(hist, &ev, H_CLEAR);
- else
- goto badhist;
- break;
-
- case 3:
- if (strcmp(av[1], "load") == 0)
- history(hist, &ev, H_LOAD, av[2]);
- else if (strcmp(av[1], "save") == 0)
- history(hist, &ev, H_SAVE, av[2]);
- break;
-
- badhist:
- default:
- (void) fprintf(stderr,
- "Bad history arguments\n");
- break;
- }
- } else if (el_parse(el, ac, av) == -1) {
- switch (fork()) {
- case 0:
- execvp(av[0], (char *const *)av);
- perror(av[0]);
- _exit(1);
- /*NOTREACHED*/
- break;
-
- case -1:
- perror("fork");
- break;
-
- default:
- if (wait(&num) == -1)
- perror("wait");
- (void) fprintf(stderr, "Exit %x\n", num);
- break;
- }
- }
-
- tok_reset(tok);
- }
-
- el_end(el);
- tok_end(tok);
- history_end(hist);
-
- return (0);
-}
diff --git a/1.2-netsec/editline/chared.c b/1.2-netsec/editline/chared.c
deleted file mode 100644
index 8eaeb3b54..000000000
--- a/1.2-netsec/editline/chared.c
+++ /dev/null
@@ -1,695 +0,0 @@
-/* $NetBSD: chared.c,v 1.15 2002/03/18 16:00:50 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: chared.c,v 1.15 2002/03/18 16:00:50 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * chared.c: Character editor utilities
- */
-#include <stdlib.h>
-#include "el.h"
-
-/* value to leave unused in line buffer */
-#define EL_LEAVE 2
-
-/* cv_undo():
- * Handle state for the vi undo command
- */
-protected void
-cv_undo(EditLine *el,int action, size_t size, char *ptr)
-{
- c_undo_t *vu = &el->el_chared.c_undo;
- vu->action = action;
- vu->ptr = ptr;
- vu->isize = size;
- (void) memcpy(vu->buf, vu->ptr, size);
-#ifdef DEBUG_UNDO
- (void) fprintf(el->el_errfile, "Undo buffer \"%s\" size = +%d -%d\n",
- vu->ptr, vu->isize, vu->dsize);
-#endif
-}
-
-
-/* c_insert():
- * Insert num characters
- */
-protected void
-c_insert(EditLine *el, int num)
-{
- char *cp;
-
- if (el->el_line.lastchar + num >= el->el_line.limit)
- return; /* can't go past end of buffer */
-
- if (el->el_line.cursor < el->el_line.lastchar) {
- /* if I must move chars */
- for (cp = el->el_line.lastchar; cp >= el->el_line.cursor; cp--)
- cp[num] = *cp;
- }
- el->el_line.lastchar += num;
-}
-
-
-/* c_delafter():
- * Delete num characters after the cursor
- */
-protected void
-c_delafter(EditLine *el, int num)
-{
-
- if (el->el_line.cursor + num > el->el_line.lastchar)
- num = el->el_line.lastchar - el->el_line.cursor;
-
- if (num > 0) {
- char *cp;
-
- if (el->el_map.current != el->el_map.emacs)
- cv_undo(el, INSERT, (size_t)num, el->el_line.cursor);
-
- for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
- *cp = cp[num];
-
- el->el_line.lastchar -= num;
- }
-}
-
-
-/* c_delbefore():
- * Delete num characters before the cursor
- */
-protected void
-c_delbefore(EditLine *el, int num)
-{
-
- if (el->el_line.cursor - num < el->el_line.buffer)
- num = el->el_line.cursor - el->el_line.buffer;
-
- if (num > 0) {
- char *cp;
-
- if (el->el_map.current != el->el_map.emacs)
- cv_undo(el, INSERT, (size_t)num,
- el->el_line.cursor - num);
-
- for (cp = el->el_line.cursor - num;
- cp <= el->el_line.lastchar;
- cp++)
- *cp = cp[num];
-
- el->el_line.lastchar -= num;
- }
-}
-
-
-/* ce__isword():
- * Return if p is part of a word according to emacs
- */
-protected int
-ce__isword(int p)
-{
- return (isalpha(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL);
-}
-
-
-/* cv__isword():
- * Return if p is part of a word according to vi
- */
-protected int
-cv__isword(int p)
-{
- return (!isspace(p));
-}
-
-
-/* c__prev_word():
- * Find the previous word
- */
-protected char *
-c__prev_word(char *p, char *low, int n, int (*wtest)(int))
-{
- p--;
-
- while (n--) {
- while ((p >= low) && !(*wtest)((unsigned char) *p))
- p--;
- while ((p >= low) && (*wtest)((unsigned char) *p))
- p--;
- }
-
- /* cp now points to one character before the word */
- p++;
- if (p < low)
- p = low;
- /* cp now points where we want it */
- return (p);
-}
-
-
-/* c__next_word():
- * Find the next word
- */
-protected char *
-c__next_word(char *p, char *high, int n, int (*wtest)(int))
-{
- while (n--) {
- while ((p < high) && !(*wtest)((unsigned char) *p))
- p++;
- while ((p < high) && (*wtest)((unsigned char) *p))
- p++;
- }
- if (p > high)
- p = high;
- /* p now points where we want it */
- return (p);
-}
-
-/* cv_next_word():
- * Find the next word vi style
- */
-protected char *
-cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int))
-{
- int test;
-
- while (n--) {
- test = (*wtest)((unsigned char) *p);
- while ((p < high) && (*wtest)((unsigned char) *p) == test)
- p++;
- /*
- * vi historically deletes with cw only the word preserving the
- * trailing whitespace! This is not what 'w' does..
- */
- if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
- while ((p < high) && isspace((unsigned char) *p))
- p++;
- }
-
- /* p now points where we want it */
- if (p > high)
- return (high);
- else
- return (p);
-}
-
-
-/* cv_prev_word():
- * Find the previous word vi style
- */
-protected char *
-cv_prev_word(EditLine *el, char *p, char *low, int n, int (*wtest)(int))
-{
- int test;
-
- while (n--) {
- p--;
- /*
- * vi historically deletes with cb only the word preserving the
- * leading whitespace! This is not what 'b' does..
- */
- if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
- while ((p > low) && isspace((unsigned char) *p))
- p--;
- test = (*wtest)((unsigned char) *p);
- while ((p >= low) && (*wtest)((unsigned char) *p) == test)
- p--;
- p++;
- while (isspace((unsigned char) *p))
- p++;
- }
-
- /* p now points where we want it */
- if (p < low)
- return (low);
- else
- return (p);
-}
-
-
-#ifdef notdef
-/* c__number():
- * Ignore character p points to, return number appearing after that.
- * A '$' by itself means a big number; "$-" is for negative; '^' means 1.
- * Return p pointing to last char used.
- */
-protected char *
-c__number(
- char *p, /* character position */
- int *num, /* Return value */
- int dval) /* dval is the number to subtract from like $-3 */
-{
- int i;
- int sign = 1;
-
- if (*++p == '^') {
- *num = 1;
- return (p);
- }
- if (*p == '$') {
- if (*++p != '-') {
- *num = 0x7fffffff; /* Handle $ */
- return (--p);
- }
- sign = -1; /* Handle $- */
- ++p;
- }
- for (i = 0; isdigit((unsigned char) *p); i = 10 * i + *p++ - '0')
- continue;
- *num = (sign < 0 ? dval - i : i);
- return (--p);
-}
-#endif
-
-/* cv_delfini():
- * Finish vi delete action
- */
-protected void
-cv_delfini(EditLine *el)
-{
- int size;
- int oaction;
-
- if (el->el_chared.c_vcmd.action & INSERT)
- el->el_map.current = el->el_map.key;
-
- oaction = el->el_chared.c_vcmd.action;
- el->el_chared.c_vcmd.action = NOP;
-
- if (el->el_chared.c_vcmd.pos == 0)
- return;
-
-
- if (el->el_line.cursor > el->el_chared.c_vcmd.pos) {
- size = (int) (el->el_line.cursor - el->el_chared.c_vcmd.pos);
- c_delbefore(el, size);
- el->el_line.cursor = el->el_chared.c_vcmd.pos;
- re_refresh_cursor(el);
- } else if (el->el_line.cursor < el->el_chared.c_vcmd.pos) {
- size = (int)(el->el_chared.c_vcmd.pos - el->el_line.cursor);
- c_delafter(el, size);
- } else {
- size = 1;
- c_delafter(el, size);
- }
- switch (oaction) {
- case DELETE|INSERT:
- el->el_chared.c_undo.action = DELETE|INSERT;
- break;
- case DELETE:
- el->el_chared.c_undo.action = INSERT;
- break;
- case NOP:
- case INSERT:
- default:
- EL_ABORT((el->el_errfile, "Bad oaction %d\n", oaction));
- break;
- }
-
-
- el->el_chared.c_undo.ptr = el->el_line.cursor;
- el->el_chared.c_undo.dsize = size;
-}
-
-
-#ifdef notdef
-/* ce__endword():
- * Go to the end of this word according to emacs
- */
-protected char *
-ce__endword(char *p, char *high, int n)
-{
- p++;
-
- while (n--) {
- while ((p < high) && isspace((unsigned char) *p))
- p++;
- while ((p < high) && !isspace((unsigned char) *p))
- p++;
- }
-
- p--;
- return (p);
-}
-#endif
-
-
-/* cv__endword():
- * Go to the end of this word according to vi
- */
-protected char *
-cv__endword(char *p, char *high, int n)
-{
- p++;
-
- while (n--) {
- while ((p < high) && isspace((unsigned char) *p))
- p++;
-
- if (isalnum((unsigned char) *p))
- while ((p < high) && isalnum((unsigned char) *p))
- p++;
- else
- while ((p < high) && !(isspace((unsigned char) *p) ||
- isalnum((unsigned char) *p)))
- p++;
- }
- p--;
- return (p);
-}
-
-/* ch_init():
- * Initialize the character editor
- */
-protected int
-ch_init(EditLine *el)
-{
- el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ);
- if (el->el_line.buffer == NULL)
- return (-1);
-
- (void) memset(el->el_line.buffer, 0, EL_BUFSIZ);
- el->el_line.cursor = el->el_line.buffer;
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - 2];
-
- el->el_chared.c_undo.buf = (char *) el_malloc(EL_BUFSIZ);
- if (el->el_chared.c_undo.buf == NULL)
- return (-1);
- (void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ);
- el->el_chared.c_undo.action = NOP;
- el->el_chared.c_undo.isize = 0;
- el->el_chared.c_undo.dsize = 0;
- el->el_chared.c_undo.ptr = el->el_line.buffer;
-
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_vcmd.pos = el->el_line.buffer;
- el->el_chared.c_vcmd.ins = el->el_line.buffer;
-
- el->el_chared.c_kill.buf = (char *) el_malloc(EL_BUFSIZ);
- if (el->el_chared.c_kill.buf == NULL)
- return (-1);
- (void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ);
- el->el_chared.c_kill.mark = el->el_line.buffer;
- el->el_chared.c_kill.last = el->el_chared.c_kill.buf;
-
- el->el_map.current = el->el_map.key;
-
- el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */
- el->el_state.doingarg = 0;
- el->el_state.metanext = 0;
- el->el_state.argument = 1;
- el->el_state.lastcmd = ED_UNASSIGNED;
-
- el->el_chared.c_macro.nline = NULL;
- el->el_chared.c_macro.level = -1;
- el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO *
- sizeof(char *));
- if (el->el_chared.c_macro.macro == NULL)
- return (-1);
- return (0);
-}
-
-/* ch_reset():
- * Reset the character editor
- */
-protected void
-ch_reset(EditLine *el)
-{
- el->el_line.cursor = el->el_line.buffer;
- el->el_line.lastchar = el->el_line.buffer;
-
- el->el_chared.c_undo.action = NOP;
- el->el_chared.c_undo.isize = 0;
- el->el_chared.c_undo.dsize = 0;
- el->el_chared.c_undo.ptr = el->el_line.buffer;
-
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_vcmd.pos = el->el_line.buffer;
- el->el_chared.c_vcmd.ins = el->el_line.buffer;
-
- el->el_chared.c_kill.mark = el->el_line.buffer;
-
- el->el_map.current = el->el_map.key;
-
- el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */
- el->el_state.doingarg = 0;
- el->el_state.metanext = 0;
- el->el_state.argument = 1;
- el->el_state.lastcmd = ED_UNASSIGNED;
-
- el->el_chared.c_macro.level = -1;
-
- el->el_history.eventno = 0;
-}
-
-/* ch_enlargebufs():
- * Enlarge line buffer to be able to hold twice as much characters.
- * Returns 1 if successful, 0 if not.
- */
-protected int
-ch_enlargebufs(el, addlen)
- EditLine *el;
- size_t addlen;
-{
- size_t sz, newsz;
- char *newbuffer, *oldbuf, *oldkbuf;
-
- sz = el->el_line.limit - el->el_line.buffer + EL_LEAVE;
- newsz = sz * 2;
- /*
- * If newly required length is longer than current buffer, we need
- * to make the buffer big enough to hold both old and new stuff.
- */
- if (addlen > sz) {
- while(newsz - sz < addlen)
- newsz *= 2;
- }
-
- /*
- * Reallocate line buffer.
- */
- newbuffer = el_realloc(el->el_line.buffer, newsz);
- if (!newbuffer)
- return 0;
-
- /* zero the newly added memory, leave old data in */
- (void) memset(&newbuffer[sz], 0, newsz - sz);
-
- oldbuf = el->el_line.buffer;
-
- el->el_line.buffer = newbuffer;
- el->el_line.cursor = newbuffer + (el->el_line.cursor - oldbuf);
- el->el_line.lastchar = newbuffer + (el->el_line.lastchar - oldbuf);
- el->el_line.limit = &newbuffer[newsz - EL_LEAVE];
-
- /*
- * Reallocate kill buffer.
- */
- newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz);
- if (!newbuffer)
- return 0;
-
- /* zero the newly added memory, leave old data in */
- (void) memset(&newbuffer[sz], 0, newsz - sz);
-
- oldkbuf = el->el_chared.c_kill.buf;
-
- el->el_chared.c_kill.buf = newbuffer;
- el->el_chared.c_kill.last = newbuffer +
- (el->el_chared.c_kill.last - oldkbuf);
- el->el_chared.c_kill.mark = el->el_line.buffer +
- (el->el_chared.c_kill.mark - oldbuf);
-
- /*
- * Reallocate undo buffer.
- */
- newbuffer = el_realloc(el->el_chared.c_undo.buf, newsz);
- if (!newbuffer)
- return 0;
-
- /* zero the newly added memory, leave old data in */
- (void) memset(&newbuffer[sz], 0, newsz - sz);
-
- el->el_chared.c_undo.ptr = el->el_line.buffer +
- (el->el_chared.c_undo.ptr - oldbuf);
- el->el_chared.c_undo.buf = newbuffer;
-
- if (!hist_enlargebuf(el, sz, newsz))
- return 0;
-
- return 1;
-}
-
-/* ch_end():
- * Free the data structures used by the editor
- */
-protected void
-ch_end(EditLine *el)
-{
- el_free((ptr_t) el->el_line.buffer);
- el->el_line.buffer = NULL;
- el->el_line.limit = NULL;
- el_free((ptr_t) el->el_chared.c_undo.buf);
- el->el_chared.c_undo.buf = NULL;
- el_free((ptr_t) el->el_chared.c_kill.buf);
- el->el_chared.c_kill.buf = NULL;
- el_free((ptr_t) el->el_chared.c_macro.macro);
- el->el_chared.c_macro.macro = NULL;
- ch_reset(el);
-}
-
-
-/* el_insertstr():
- * Insert string at cursorI
- */
-public int
-el_insertstr(EditLine *el, const char *s)
-{
- size_t len;
-
- if ((len = strlen(s)) == 0)
- return (-1);
- if (el->el_line.lastchar + len >= el->el_line.limit) {
- if (!ch_enlargebufs(el, len))
- return (-1);
- }
-
- c_insert(el, (int)len);
- while (*s)
- *el->el_line.cursor++ = *s++;
- return (0);
-}
-
-
-/* el_deletestr():
- * Delete num characters before the cursor
- */
-public void
-el_deletestr(EditLine *el, int n)
-{
- if (n <= 0)
- return;
-
- if (el->el_line.cursor < &el->el_line.buffer[n])
- return;
-
- c_delbefore(el, n); /* delete before dot */
- el->el_line.cursor -= n;
- if (el->el_line.cursor < el->el_line.buffer)
- el->el_line.cursor = el->el_line.buffer;
-}
-
-/* c_gets():
- * Get a string
- */
-protected int
-c_gets(EditLine *el, char *buf)
-{
- char ch;
- int len = 0;
-
- for (ch = 0; ch == 0;) {
- if (el_getc(el, &ch) != 1)
- return (ed_end_of_file(el, 0));
- switch (ch) {
- case 0010: /* Delete and backspace */
- case 0177:
- if (len > 1) {
- *el->el_line.cursor-- = '\0';
- el->el_line.lastchar = el->el_line.cursor;
- buf[len--] = '\0';
- } else {
- el->el_line.buffer[0] = '\0';
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
- return (CC_REFRESH);
- }
- re_refresh(el);
- ch = 0;
- break;
-
- case 0033: /* ESC */
- case '\r': /* Newline */
- case '\n':
- break;
-
- default:
- if (len >= EL_BUFSIZ)
- term_beep(el);
- else {
- buf[len++] = ch;
- *el->el_line.cursor++ = ch;
- el->el_line.lastchar = el->el_line.cursor;
- }
- re_refresh(el);
- ch = 0;
- break;
- }
- }
- buf[len] = ch;
- return (len);
-}
-
-
-/* c_hpos():
- * Return the current horizontal position of the cursor
- */
-protected int
-c_hpos(EditLine *el)
-{
- char *ptr;
-
- /*
- * Find how many characters till the beginning of this line.
- */
- if (el->el_line.cursor == el->el_line.buffer)
- return (0);
- else {
- for (ptr = el->el_line.cursor - 1;
- ptr >= el->el_line.buffer && *ptr != '\n';
- ptr--)
- continue;
- return (el->el_line.cursor - ptr - 1);
- }
-}
diff --git a/1.2-netsec/editline/chared.h b/1.2-netsec/editline/chared.h
deleted file mode 100644
index 403eca011..000000000
--- a/1.2-netsec/editline/chared.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/* $NetBSD: chared.h,v 1.8 2002/03/18 16:00:51 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)chared.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.chared.h: Character editor interface
- */
-#ifndef _h_el_chared
-#define _h_el_chared
-
-#include <ctype.h>
-#include <string.h>
-
-#include "histedit.h"
-
-#define EL_MAXMACRO 10
-
-/*
- * This is a issue of basic "vi" look-and-feel. Defining VI_MOVE works
- * like real vi: i.e. the transition from command<->insert modes moves
- * the cursor.
- *
- * On the other hand we really don't want to move the cursor, because
- * all the editing commands don't include the character under the cursor.
- * Probably the best fix is to make all the editing commands aware of
- * this fact.
- */
-#define VI_MOVE
-
-
-typedef struct c_macro_t {
- int level;
- char **macro;
- char *nline;
-} c_macro_t;
-
-/*
- * Undo information for both vi and emacs
- */
-typedef struct c_undo_t {
- int action;
- size_t isize;
- size_t dsize;
- char *ptr;
- char *buf;
-} c_undo_t;
-
-/*
- * Current action information for vi
- */
-typedef struct c_vcmd_t {
- int action;
- char *pos;
- char *ins;
-} c_vcmd_t;
-
-/*
- * Kill buffer for emacs
- */
-typedef struct c_kill_t {
- char *buf;
- char *last;
- char *mark;
-} c_kill_t;
-
-/*
- * Note that we use both data structures because the user can bind
- * commands from both editors!
- */
-typedef struct el_chared_t {
- c_undo_t c_undo;
- c_kill_t c_kill;
- c_vcmd_t c_vcmd;
- c_macro_t c_macro;
-} el_chared_t;
-
-
-#define STReof "^D\b\b"
-#define STRQQ "\"\""
-
-#define isglob(a) (strchr("*[]?", (a)) != NULL)
-#define isword(a) (isprint(a))
-
-#define NOP 0x00
-#define DELETE 0x01
-#define INSERT 0x02
-#define CHANGE 0x04
-
-#define CHAR_FWD 0
-#define CHAR_BACK 1
-
-#define MODE_INSERT 0
-#define MODE_REPLACE 1
-#define MODE_REPLACE_1 2
-
-#include "common.h"
-#include "vi.h"
-#include "emacs.h"
-#include "search.h"
-#include "fcns.h"
-
-
-protected int cv__isword(int);
-protected void cv_delfini(EditLine *);
-protected char *cv__endword(char *, char *, int);
-protected int ce__isword(int);
-protected void cv_undo(EditLine *, int, size_t, char *);
-protected char *cv_next_word(EditLine*, char *, char *, int, int (*)(int));
-protected char *cv_prev_word(EditLine*, char *, char *, int, int (*)(int));
-protected char *c__next_word(char *, char *, int, int (*)(int));
-protected char *c__prev_word(char *, char *, int, int (*)(int));
-protected void c_insert(EditLine *, int);
-protected void c_delbefore(EditLine *, int);
-protected void c_delafter(EditLine *, int);
-protected int c_gets(EditLine *, char *);
-protected int c_hpos(EditLine *);
-
-protected int ch_init(EditLine *);
-protected void ch_reset(EditLine *);
-protected int ch_enlargebufs(EditLine *, size_t);
-protected void ch_end(EditLine *);
-
-#endif /* _h_el_chared */
diff --git a/1.2-netsec/editline/common.c b/1.2-netsec/editline/common.c
deleted file mode 100644
index c831e79a3..000000000
--- a/1.2-netsec/editline/common.c
+++ /dev/null
@@ -1,951 +0,0 @@
-/* $NetBSD: common.c,v 1.11 2002/03/18 16:00:51 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: common.c,v 1.11 2002/03/18 16:00:51 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * common.c: Common Editor functions
- */
-#include "el.h"
-
-/* ed_end_of_file():
- * Indicate end of file
- * [^D]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_end_of_file(EditLine *el, int c)
-{
-
- re_goto_bottom(el);
- *el->el_line.lastchar = '\0';
- return (CC_EOF);
-}
-
-
-/* ed_insert():
- * Add character to the line
- * Insert a character [bound to all insert keys]
- */
-protected el_action_t
-ed_insert(EditLine *el, int c)
-{
- int i;
-
- if (c == '\0')
- return (CC_ERROR);
-
- if (el->el_line.lastchar + el->el_state.argument >=
- el->el_line.limit) {
- /* end of buffer space, try to allocate more */
- if (!ch_enlargebufs(el, (size_t) el->el_state.argument))
- return CC_ERROR; /* error allocating more */
- }
-
- if (el->el_state.argument == 1) {
- if (el->el_state.inputmode != MODE_INSERT) {
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] =
- *el->el_line.cursor;
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] =
- '\0';
- c_delafter(el, 1);
- }
- c_insert(el, 1);
-
- *el->el_line.cursor++ = c;
- el->el_state.doingarg = 0; /* just in case */
- re_fastaddc(el); /* fast refresh for one char. */
- } else {
- if (el->el_state.inputmode != MODE_INSERT) {
- for (i = 0; i < el->el_state.argument; i++)
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] =
- el->el_line.cursor[i];
-
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] =
- '\0';
- c_delafter(el, el->el_state.argument);
- }
- c_insert(el, el->el_state.argument);
-
- while (el->el_state.argument--)
- *el->el_line.cursor++ = c;
- re_refresh(el);
- }
-
- if (el->el_state.inputmode == MODE_REPLACE_1)
- (void) vi_command_mode(el, 0);
-
- return (CC_NORM);
-}
-
-
-/* ed_delete_prev_word():
- * Delete from beginning of current word to cursor
- * [M-^?] [^W]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_delete_prev_word(EditLine *el, int c)
-{
- char *cp, *p, *kp;
-
- if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
-
- cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
- el->el_state.argument, ce__isword);
-
- for (p = cp, kp = el->el_chared.c_kill.buf; p < el->el_line.cursor; p++)
- *kp++ = *p;
- el->el_chared.c_kill.last = kp;
-
- c_delbefore(el, el->el_line.cursor - cp); /* delete before dot */
- el->el_line.cursor = cp;
- if (el->el_line.cursor < el->el_line.buffer)
- el->el_line.cursor = el->el_line.buffer; /* bounds check */
- return (CC_REFRESH);
-}
-
-
-/* ed_delete_next_char():
- * Delete character under cursor
- * [^D] [x]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_delete_next_char(EditLine *el, int c)
-{
-#ifdef notdef /* XXX */
-#define EL el->el_line
- (void) fprintf(el->el_errlfile,
- "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n",
- EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar,
- EL.lastchar, EL.limit, EL.limit);
-#endif
- if (el->el_line.cursor == el->el_line.lastchar) {
- /* if I'm at the end */
- if (el->el_map.type == MAP_VI) {
- if (el->el_line.cursor == el->el_line.buffer) {
- /* if I'm also at the beginning */
-#ifdef KSHVI
- return (CC_ERROR);
-#else
- term_overwrite(el, STReof, 4);
- /* then do a EOF */
- term__flush();
- return (CC_EOF);
-#endif
- } else {
-#ifdef KSHVI
- el->el_line.cursor--;
-#else
- return (CC_ERROR);
-#endif
- }
- } else {
- if (el->el_line.cursor != el->el_line.buffer)
- el->el_line.cursor--;
- else
- return (CC_ERROR);
- }
- }
- c_delafter(el, el->el_state.argument); /* delete after dot */
- if (el->el_line.cursor >= el->el_line.lastchar &&
- el->el_line.cursor > el->el_line.buffer)
- /* bounds check */
- el->el_line.cursor = el->el_line.lastchar - 1;
- return (CC_REFRESH);
-}
-
-
-/* ed_kill_line():
- * Cut to the end of line
- * [^K] [^K]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_kill_line(EditLine *el, int c)
-{
- char *kp, *cp;
-
- cp = el->el_line.cursor;
- kp = el->el_chared.c_kill.buf;
- while (cp < el->el_line.lastchar)
- *kp++ = *cp++; /* copy it */
- el->el_chared.c_kill.last = kp;
- /* zap! -- delete to end */
- el->el_line.lastchar = el->el_line.cursor;
- return (CC_REFRESH);
-}
-
-
-/* ed_move_to_end():
- * Move cursor to the end of line
- * [^E] [^E]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_move_to_end(EditLine *el, int c)
-{
-
- el->el_line.cursor = el->el_line.lastchar;
- if (el->el_map.type == MAP_VI) {
-#ifdef VI_MOVE
- el->el_line.cursor--;
-#endif
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- }
- return (CC_CURSOR);
-}
-
-
-/* ed_move_to_beg():
- * Move cursor to the beginning of line
- * [^A] [^A]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_move_to_beg(EditLine *el, int c)
-{
-
- el->el_line.cursor = el->el_line.buffer;
-
- if (el->el_map.type == MAP_VI) {
- /* We want FIRST non space character */
- while (isspace((unsigned char) *el->el_line.cursor))
- el->el_line.cursor++;
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- }
- return (CC_CURSOR);
-}
-
-
-/* ed_transpose_chars():
- * Exchange the character to the left of the cursor with the one under it
- * [^T] [^T]
- */
-protected el_action_t
-ed_transpose_chars(EditLine *el, int c)
-{
-
- if (el->el_line.cursor < el->el_line.lastchar) {
- if (el->el_line.lastchar <= &el->el_line.buffer[1])
- return (CC_ERROR);
- else
- el->el_line.cursor++;
- }
- if (el->el_line.cursor > &el->el_line.buffer[1]) {
- /* must have at least two chars entered */
- c = el->el_line.cursor[-2];
- el->el_line.cursor[-2] = el->el_line.cursor[-1];
- el->el_line.cursor[-1] = c;
- return (CC_REFRESH);
- } else
- return (CC_ERROR);
-}
-
-
-/* ed_next_char():
- * Move to the right one character
- * [^F] [^F]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_next_char(EditLine *el, int c)
-{
-
- if (el->el_line.cursor >= el->el_line.lastchar)
- return (CC_ERROR);
-
- el->el_line.cursor += el->el_state.argument;
- if (el->el_line.cursor > el->el_line.lastchar)
- el->el_line.cursor = el->el_line.lastchar;
-
- if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* ed_prev_word():
- * Move to the beginning of the current word
- * [M-b] [b]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_prev_word(EditLine *el, int c)
-{
-
- if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
-
- el->el_line.cursor = c__prev_word(el->el_line.cursor,
- el->el_line.buffer,
- el->el_state.argument,
- ce__isword);
-
- if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* ed_prev_char():
- * Move to the left one character
- * [^B] [^B]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_prev_char(EditLine *el, int c)
-{
-
- if (el->el_line.cursor > el->el_line.buffer) {
- el->el_line.cursor -= el->el_state.argument;
- if (el->el_line.cursor < el->el_line.buffer)
- el->el_line.cursor = el->el_line.buffer;
-
- if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
- } else
- return (CC_ERROR);
-}
-
-
-/* ed_quoted_insert():
- * Add the next character typed verbatim
- * [^V] [^V]
- */
-protected el_action_t
-ed_quoted_insert(EditLine *el, int c)
-{
- int num;
- char tc;
-
- tty_quotemode(el);
- num = el_getc(el, &tc);
- c = (unsigned char) tc;
- tty_noquotemode(el);
- if (num == 1)
- return (ed_insert(el, c));
- else
- return (ed_end_of_file(el, 0));
-}
-
-
-/* ed_digit():
- * Adds to argument or enters a digit
- */
-protected el_action_t
-ed_digit(EditLine *el, int c)
-{
-
- if (!isdigit(c))
- return (CC_ERROR);
-
- if (el->el_state.doingarg) {
- /* if doing an arg, add this in... */
- if (el->el_state.lastcmd == EM_UNIVERSAL_ARGUMENT)
- el->el_state.argument = c - '0';
- else {
- if (el->el_state.argument > 1000000)
- return (CC_ERROR);
- el->el_state.argument =
- (el->el_state.argument * 10) + (c - '0');
- }
- return (CC_ARGHACK);
- } else {
- if (el->el_line.lastchar + 1 >= el->el_line.limit) {
- if (!ch_enlargebufs(el, 1))
- return (CC_ERROR);
- }
-
- if (el->el_state.inputmode != MODE_INSERT) {
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] =
- *el->el_line.cursor;
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] =
- '\0';
- c_delafter(el, 1);
- }
- c_insert(el, 1);
- *el->el_line.cursor++ = c;
- el->el_state.doingarg = 0;
- re_fastaddc(el);
- }
- return (CC_NORM);
-}
-
-
-/* ed_argument_digit():
- * Digit that starts argument
- * For ESC-n
- */
-protected el_action_t
-ed_argument_digit(EditLine *el, int c)
-{
-
- if (!isdigit(c))
- return (CC_ERROR);
-
- if (el->el_state.doingarg) {
- if (el->el_state.argument > 1000000)
- return (CC_ERROR);
- el->el_state.argument = (el->el_state.argument * 10) +
- (c - '0');
- } else { /* else starting an argument */
- el->el_state.argument = c - '0';
- el->el_state.doingarg = 1;
- }
- return (CC_ARGHACK);
-}
-
-
-/* ed_unassigned():
- * Indicates unbound character
- * Bound to keys that are not assigned
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_unassigned(EditLine *el, int c)
-{
-
- term_beep(el);
- term__flush();
- return (CC_NORM);
-}
-
-
-/**
- ** TTY key handling.
- **/
-
-/* ed_tty_sigint():
- * Tty interrupt character
- * [^C]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_sigint(EditLine *el, int c)
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_dsusp():
- * Tty delayed suspend character
- * [^Y]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_dsusp(EditLine *el, int c)
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_flush_output():
- * Tty flush output characters
- * [^O]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_flush_output(EditLine *el, int c)
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_sigquit():
- * Tty quit character
- * [^\]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_sigquit(EditLine *el, int c)
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_sigtstp():
- * Tty suspend character
- * [^Z]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_sigtstp(EditLine *el, int c)
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_stop_output():
- * Tty disallow output characters
- * [^S]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_stop_output(EditLine *el, int c)
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_start_output():
- * Tty allow output characters
- * [^Q]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_start_output(EditLine *el, int c)
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_newline():
- * Execute command
- * [^J]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_newline(EditLine *el, int c)
-{
-
- re_goto_bottom(el);
- *el->el_line.lastchar++ = '\n';
- *el->el_line.lastchar = '\0';
- if (el->el_map.type == MAP_VI)
- el->el_chared.c_vcmd.ins = el->el_line.buffer;
- return (CC_NEWLINE);
-}
-
-
-/* ed_delete_prev_char():
- * Delete the character to the left of the cursor
- * [^?]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_delete_prev_char(EditLine *el, int c)
-{
-
- if (el->el_line.cursor <= el->el_line.buffer)
- return (CC_ERROR);
-
- c_delbefore(el, el->el_state.argument);
- el->el_line.cursor -= el->el_state.argument;
- if (el->el_line.cursor < el->el_line.buffer)
- el->el_line.cursor = el->el_line.buffer;
- return (CC_REFRESH);
-}
-
-
-/* ed_clear_screen():
- * Clear screen leaving current line at the top
- * [^L]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_clear_screen(EditLine *el, int c)
-{
-
- term_clear_screen(el); /* clear the whole real screen */
- re_clear_display(el); /* reset everything */
- return (CC_REFRESH);
-}
-
-
-/* ed_redisplay():
- * Redisplay everything
- * ^R
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_redisplay(EditLine *el, int c)
-{
-
- return (CC_REDISPLAY);
-}
-
-
-/* ed_start_over():
- * Erase current line and start from scratch
- * [^G]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_start_over(EditLine *el, int c)
-{
-
- ch_reset(el);
- return (CC_REFRESH);
-}
-
-
-/* ed_sequence_lead_in():
- * First character in a bound sequence
- * Placeholder for external keys
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_sequence_lead_in(EditLine *el, int c)
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_prev_history():
- * Move to the previous history line
- * [^P] [k]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_prev_history(EditLine *el, int c)
-{
- char beep = 0;
-
- el->el_chared.c_undo.action = NOP;
- *el->el_line.lastchar = '\0'; /* just in case */
-
- if (el->el_history.eventno == 0) { /* save the current buffer
- * away */
- (void) strncpy(el->el_history.buf, el->el_line.buffer,
- EL_BUFSIZ - 1);
- el->el_history.last = el->el_history.buf +
- (el->el_line.lastchar - el->el_line.buffer);
- }
- el->el_history.eventno += el->el_state.argument;
-
- if (hist_get(el) == CC_ERROR) {
- beep = 1;
- /* el->el_history.eventno was fixed by first call */
- (void) hist_get(el);
- }
- re_refresh(el);
- if (beep)
- return (CC_ERROR);
- else
- return (CC_NORM); /* was CC_UP_HIST */
-}
-
-
-/* ed_next_history():
- * Move to the next history line
- * [^N] [j]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_next_history(EditLine *el, int c)
-{
-
- el->el_chared.c_undo.action = NOP;
- *el->el_line.lastchar = '\0'; /* just in case */
-
- el->el_history.eventno -= el->el_state.argument;
-
- if (el->el_history.eventno < 0) {
- el->el_history.eventno = 0;
- return (CC_ERROR);/* make it beep */
- }
- return (hist_get(el));
-}
-
-
-/* ed_search_prev_history():
- * Search previous in history for a line matching the current
- * next search history [M-P] [K]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_search_prev_history(EditLine *el, int c)
-{
- const char *hp;
- int h;
- bool_t found = 0;
-
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_undo.action = NOP;
- *el->el_line.lastchar = '\0'; /* just in case */
- if (el->el_history.eventno < 0) {
-#ifdef DEBUG_EDIT
- (void) fprintf(el->el_errfile,
- "e_prev_search_hist(): eventno < 0;\n");
-#endif
- el->el_history.eventno = 0;
- return (CC_ERROR);
- }
- if (el->el_history.eventno == 0) {
- (void) strncpy(el->el_history.buf, el->el_line.buffer,
- EL_BUFSIZ - 1);
- el->el_history.last = el->el_history.buf +
- (el->el_line.lastchar - el->el_line.buffer);
- }
- if (el->el_history.ref == NULL)
- return (CC_ERROR);
-
- hp = HIST_FIRST(el);
- if (hp == NULL)
- return (CC_ERROR);
-
- c_setpat(el); /* Set search pattern !! */
-
- for (h = 1; h <= el->el_history.eventno; h++)
- hp = HIST_NEXT(el);
-
- while (hp != NULL) {
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
-#endif
- if ((strncmp(hp, el->el_line.buffer, (size_t)
- (el->el_line.lastchar - el->el_line.buffer)) ||
- hp[el->el_line.lastchar - el->el_line.buffer]) &&
- c_hmatch(el, hp)) {
- found++;
- break;
- }
- h++;
- hp = HIST_NEXT(el);
- }
-
- if (!found) {
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "not found\n");
-#endif
- return (CC_ERROR);
- }
- el->el_history.eventno = h;
-
- return (hist_get(el));
-}
-
-
-/* ed_search_next_history():
- * Search next in history for a line matching the current
- * [M-N] [J]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_search_next_history(EditLine *el, int c)
-{
- const char *hp;
- int h;
- bool_t found = 0;
-
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_undo.action = NOP;
- *el->el_line.lastchar = '\0'; /* just in case */
-
- if (el->el_history.eventno == 0)
- return (CC_ERROR);
-
- if (el->el_history.ref == NULL)
- return (CC_ERROR);
-
- hp = HIST_FIRST(el);
- if (hp == NULL)
- return (CC_ERROR);
-
- c_setpat(el); /* Set search pattern !! */
-
- for (h = 1; h < el->el_history.eventno && hp; h++) {
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
-#endif
- if ((strncmp(hp, el->el_line.buffer, (size_t)
- (el->el_line.lastchar - el->el_line.buffer)) ||
- hp[el->el_line.lastchar - el->el_line.buffer]) &&
- c_hmatch(el, hp))
- found = h;
- hp = HIST_NEXT(el);
- }
-
- if (!found) { /* is it the current history number? */
- if (!c_hmatch(el, el->el_history.buf)) {
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "not found\n");
-#endif
- return (CC_ERROR);
- }
- }
- el->el_history.eventno = found;
-
- return (hist_get(el));
-}
-
-
-/* ed_prev_line():
- * Move up one line
- * Could be [k] [^p]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_prev_line(EditLine *el, int c)
-{
- char *ptr;
- int nchars = c_hpos(el);
-
- /*
- * Move to the line requested
- */
- if (*(ptr = el->el_line.cursor) == '\n')
- ptr--;
-
- for (; ptr >= el->el_line.buffer; ptr--)
- if (*ptr == '\n' && --el->el_state.argument <= 0)
- break;
-
- if (el->el_state.argument > 0)
- return (CC_ERROR);
-
- /*
- * Move to the beginning of the line
- */
- for (ptr--; ptr >= el->el_line.buffer && *ptr != '\n'; ptr--)
- continue;
-
- /*
- * Move to the character requested
- */
- for (ptr++;
- nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
- ptr++)
- continue;
-
- el->el_line.cursor = ptr;
- return (CC_CURSOR);
-}
-
-
-/* ed_next_line():
- * Move down one line
- * Could be [j] [^n]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_next_line(EditLine *el, int c)
-{
- char *ptr;
- int nchars = c_hpos(el);
-
- /*
- * Move to the line requested
- */
- for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++)
- if (*ptr == '\n' && --el->el_state.argument <= 0)
- break;
-
- if (el->el_state.argument > 0)
- return (CC_ERROR);
-
- /*
- * Move to the character requested
- */
- for (ptr++;
- nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
- ptr++)
- continue;
-
- el->el_line.cursor = ptr;
- return (CC_CURSOR);
-}
-
-
-/* ed_command():
- * Editline extended command
- * [M-X] [:]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_command(EditLine *el, int c)
-{
- char tmpbuf[EL_BUFSIZ];
- int tmplen;
-
- el->el_line.buffer[0] = '\0';
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
-
- c_insert(el, 3); /* prompt + ": " */
- *el->el_line.cursor++ = '\n';
- *el->el_line.cursor++ = ':';
- *el->el_line.cursor++ = ' ';
- re_refresh(el);
-
- tmplen = c_gets(el, tmpbuf);
- tmpbuf[tmplen] = '\0';
-
- el->el_line.buffer[0] = '\0';
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
-
- if (parse_line(el, tmpbuf) == -1)
- return (CC_ERROR);
- else
- return (CC_REFRESH);
-}
diff --git a/1.2-netsec/editline/config.guess b/1.2-netsec/editline/config.guess
deleted file mode 100755
index a6d8a945f..000000000
--- a/1.2-netsec/editline/config.guess
+++ /dev/null
@@ -1,1449 +0,0 @@
-#! /bin/sh
-# Attempt to guess a canonical system name.
-# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-# 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
-
-timestamp='2004-06-24'
-
-# This file is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# Originally written by Per Bothner <per@bothner.com>.
-# Please send patches to <config-patches@gnu.org>. Submit a context
-# diff and a properly formatted ChangeLog entry.
-#
-# This script attempts to guess a canonical system name similar to
-# config.sub. If it succeeds, it prints the system name on stdout, and
-# exits with 0. Otherwise, it exits with 1.
-#
-# The plan is that this can be called by configure scripts if you
-# don't specify an explicit build system type.
-
-me=`echo "$0" | sed -e 's,.*/,,'`
-
-usage="\
-Usage: $0 [OPTION]
-
-Output the configuration name of the system \`$me' is run on.
-
-Operation modes:
- -h, --help print this help, then exit
- -t, --time-stamp print date of last modification, then exit
- -v, --version print version number, then exit
-
-Report bugs and patches to <config-patches@gnu.org>."
-
-version="\
-GNU config.guess ($timestamp)
-
-Originally written by Per Bothner.
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
-Free Software Foundation, Inc.
-
-This is free software; see the source for copying conditions. There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
-
-help="
-Try \`$me --help' for more information."
-
-# Parse command line
-while test $# -gt 0 ; do
- case $1 in
- --time-stamp | --time* | -t )
- echo "$timestamp" ; exit 0 ;;
- --version | -v )
- echo "$version" ; exit 0 ;;
- --help | --h* | -h )
- echo "$usage"; exit 0 ;;
- -- ) # Stop option processing
- shift; break ;;
- - ) # Use stdin as input.
- break ;;
- -* )
- echo "$me: invalid option $1$help" >&2
- exit 1 ;;
- * )
- break ;;
- esac
-done
-
-if test $# != 0; then
- echo "$me: too many arguments$help" >&2
- exit 1
-fi
-
-trap 'exit 1' 1 2 15
-
-# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
-# compiler to aid in system detection is discouraged as it requires
-# temporary files to be created and, as you can see below, it is a
-# headache to deal with in a portable fashion.
-
-# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
-# use `HOST_CC' if defined, but it is deprecated.
-
-# Portable tmp directory creation inspired by the Autoconf team.
-
-set_cc_for_build='
-trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
-trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
-: ${TMPDIR=/tmp} ;
- { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
- { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
- { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
- { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
-dummy=$tmp/dummy ;
-tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
-case $CC_FOR_BUILD,$HOST_CC,$CC in
- ,,) echo "int x;" > $dummy.c ;
- for c in cc gcc c89 c99 ; do
- if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
- CC_FOR_BUILD="$c"; break ;
- fi ;
- done ;
- if test x"$CC_FOR_BUILD" = x ; then
- CC_FOR_BUILD=no_compiler_found ;
- fi
- ;;
- ,,*) CC_FOR_BUILD=$CC ;;
- ,*,*) CC_FOR_BUILD=$HOST_CC ;;
-esac ;'
-
-# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
-# (ghazi@noc.rutgers.edu 1994-08-24)
-if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
- PATH=$PATH:/.attbin ; export PATH
-fi
-
-UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
-UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
-UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
-UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
-
-# Note: order is significant - the case branches are not exclusive.
-
-case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
- *:NetBSD:*:*)
- # NetBSD (nbsd) targets should (where applicable) match one or
- # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
- # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
- # switched to ELF, *-*-netbsd* would select the old
- # object file format. This provides both forward
- # compatibility and a consistent mechanism for selecting the
- # object file format.
- #
- # Note: NetBSD doesn't particularly care about the vendor
- # portion of the name. We always set it to "unknown".
- sysctl="sysctl -n hw.machine_arch"
- UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
- /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
- case "${UNAME_MACHINE_ARCH}" in
- armeb) machine=armeb-unknown ;;
- arm*) machine=arm-unknown ;;
- sh3el) machine=shl-unknown ;;
- sh3eb) machine=sh-unknown ;;
- *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
- esac
- # The Operating System including object format, if it has switched
- # to ELF recently, or will in the future.
- case "${UNAME_MACHINE_ARCH}" in
- arm*|i386|m68k|ns32k|sh3*|sparc|vax)
- eval $set_cc_for_build
- if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
- | grep __ELF__ >/dev/null
- then
- # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
- # Return netbsd for either. FIX?
- os=netbsd
- else
- os=netbsdelf
- fi
- ;;
- *)
- os=netbsd
- ;;
- esac
- # The OS release
- # Debian GNU/NetBSD machines have a different userland, and
- # thus, need a distinct triplet. However, they do not need
- # kernel version information, so it can be replaced with a
- # suitable tag, in the style of linux-gnu.
- case "${UNAME_VERSION}" in
- Debian*)
- release='-gnu'
- ;;
- *)
- release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
- ;;
- esac
- # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
- # contains redundant information, the shorter form:
- # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
- echo "${machine}-${os}${release}"
- exit 0 ;;
- amd64:OpenBSD:*:*)
- echo x86_64-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- amiga:OpenBSD:*:*)
- echo m68k-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- arc:OpenBSD:*:*)
- echo mipsel-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- cats:OpenBSD:*:*)
- echo arm-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- hp300:OpenBSD:*:*)
- echo m68k-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- luna88k:OpenBSD:*:*)
- echo m88k-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- mac68k:OpenBSD:*:*)
- echo m68k-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- macppc:OpenBSD:*:*)
- echo powerpc-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- mvme68k:OpenBSD:*:*)
- echo m68k-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- mvme88k:OpenBSD:*:*)
- echo m88k-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- mvmeppc:OpenBSD:*:*)
- echo powerpc-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- pmax:OpenBSD:*:*)
- echo mipsel-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- sgi:OpenBSD:*:*)
- echo mipseb-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- sun3:OpenBSD:*:*)
- echo m68k-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- wgrisc:OpenBSD:*:*)
- echo mipsel-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- *:OpenBSD:*:*)
- echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
- exit 0 ;;
- *:ekkoBSD:*:*)
- echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
- exit 0 ;;
- macppc:MirBSD:*:*)
- echo powerppc-unknown-mirbsd${UNAME_RELEASE}
- exit 0 ;;
- *:MirBSD:*:*)
- echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
- exit 0 ;;
- alpha:OSF1:*:*)
- case $UNAME_RELEASE in
- *4.0)
- UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
- ;;
- *5.*)
- UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
- ;;
- esac
- # According to Compaq, /usr/sbin/psrinfo has been available on
- # OSF/1 and Tru64 systems produced since 1995. I hope that
- # covers most systems running today. This code pipes the CPU
- # types through head -n 1, so we only detect the type of CPU 0.
- ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
- case "$ALPHA_CPU_TYPE" in
- "EV4 (21064)")
- UNAME_MACHINE="alpha" ;;
- "EV4.5 (21064)")
- UNAME_MACHINE="alpha" ;;
- "LCA4 (21066/21068)")
- UNAME_MACHINE="alpha" ;;
- "EV5 (21164)")
- UNAME_MACHINE="alphaev5" ;;
- "EV5.6 (21164A)")
- UNAME_MACHINE="alphaev56" ;;
- "EV5.6 (21164PC)")
- UNAME_MACHINE="alphapca56" ;;
- "EV5.7 (21164PC)")
- UNAME_MACHINE="alphapca57" ;;
- "EV6 (21264)")
- UNAME_MACHINE="alphaev6" ;;
- "EV6.7 (21264A)")
- UNAME_MACHINE="alphaev67" ;;
- "EV6.8CB (21264C)")
- UNAME_MACHINE="alphaev68" ;;
- "EV6.8AL (21264B)")
- UNAME_MACHINE="alphaev68" ;;
- "EV6.8CX (21264D)")
- UNAME_MACHINE="alphaev68" ;;
- "EV6.9A (21264/EV69A)")
- UNAME_MACHINE="alphaev69" ;;
- "EV7 (21364)")
- UNAME_MACHINE="alphaev7" ;;
- "EV7.9 (21364A)")
- UNAME_MACHINE="alphaev79" ;;
- esac
- # A Pn.n version is a patched version.
- # A Vn.n version is a released version.
- # A Tn.n version is a released field test version.
- # A Xn.n version is an unreleased experimental baselevel.
- # 1.2 uses "1.2" for uname -r.
- echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
- exit 0 ;;
- Alpha\ *:Windows_NT*:*)
- # How do we know it's Interix rather than the generic POSIX subsystem?
- # Should we change UNAME_MACHINE based on the output of uname instead
- # of the specific Alpha model?
- echo alpha-pc-interix
- exit 0 ;;
- 21064:Windows_NT:50:3)
- echo alpha-dec-winnt3.5
- exit 0 ;;
- Amiga*:UNIX_System_V:4.0:*)
- echo m68k-unknown-sysv4
- exit 0;;
- *:[Aa]miga[Oo][Ss]:*:*)
- echo ${UNAME_MACHINE}-unknown-amigaos
- exit 0 ;;
- *:[Mm]orph[Oo][Ss]:*:*)
- echo ${UNAME_MACHINE}-unknown-morphos
- exit 0 ;;
- *:OS/390:*:*)
- echo i370-ibm-openedition
- exit 0 ;;
- *:OS400:*:*)
- echo powerpc-ibm-os400
- exit 0 ;;
- arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
- echo arm-acorn-riscix${UNAME_RELEASE}
- exit 0;;
- SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
- echo hppa1.1-hitachi-hiuxmpp
- exit 0;;
- Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
- # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
- if test "`(/bin/universe) 2>/dev/null`" = att ; then
- echo pyramid-pyramid-sysv3
- else
- echo pyramid-pyramid-bsd
- fi
- exit 0 ;;
- NILE*:*:*:dcosx)
- echo pyramid-pyramid-svr4
- exit 0 ;;
- DRS?6000:unix:4.0:6*)
- echo sparc-icl-nx6
- exit 0 ;;
- DRS?6000:UNIX_SV:4.2*:7*)
- case `/usr/bin/uname -p` in
- sparc) echo sparc-icl-nx7 && exit 0 ;;
- esac ;;
- sun4H:SunOS:5.*:*)
- echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
- exit 0 ;;
- sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
- echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
- exit 0 ;;
- i86pc:SunOS:5.*:*)
- echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
- exit 0 ;;
- sun4*:SunOS:6*:*)
- # According to config.sub, this is the proper way to canonicalize
- # SunOS6. Hard to guess exactly what SunOS6 will be like, but
- # it's likely to be more like Solaris than SunOS4.
- echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
- exit 0 ;;
- sun4*:SunOS:*:*)
- case "`/usr/bin/arch -k`" in
- Series*|S4*)
- UNAME_RELEASE=`uname -v`
- ;;
- esac
- # Japanese Language versions have a version number like `4.1.3-JL'.
- echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
- exit 0 ;;
- sun3*:SunOS:*:*)
- echo m68k-sun-sunos${UNAME_RELEASE}
- exit 0 ;;
- sun*:*:4.2BSD:*)
- UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
- test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
- case "`/bin/arch`" in
- sun3)
- echo m68k-sun-sunos${UNAME_RELEASE}
- ;;
- sun4)
- echo sparc-sun-sunos${UNAME_RELEASE}
- ;;
- esac
- exit 0 ;;
- aushp:SunOS:*:*)
- echo sparc-auspex-sunos${UNAME_RELEASE}
- exit 0 ;;
- # The situation for MiNT is a little confusing. The machine name
- # can be virtually everything (everything which is not
- # "atarist" or "atariste" at least should have a processor
- # > m68000). The system name ranges from "MiNT" over "FreeMiNT"
- # to the lowercase version "mint" (or "freemint"). Finally
- # the system name "TOS" denotes a system which is actually not
- # MiNT. But MiNT is downward compatible to TOS, so this should
- # be no problem.
- atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
- echo m68k-atari-mint${UNAME_RELEASE}
- exit 0 ;;
- atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
- echo m68k-atari-mint${UNAME_RELEASE}
- exit 0 ;;
- *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
- echo m68k-atari-mint${UNAME_RELEASE}
- exit 0 ;;
- milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
- echo m68k-milan-mint${UNAME_RELEASE}
- exit 0 ;;
- hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
- echo m68k-hades-mint${UNAME_RELEASE}
- exit 0 ;;
- *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
- echo m68k-unknown-mint${UNAME_RELEASE}
- exit 0 ;;
- m68k:machten:*:*)
- echo m68k-apple-machten${UNAME_RELEASE}
- exit 0 ;;
- powerpc:machten:*:*)
- echo powerpc-apple-machten${UNAME_RELEASE}
- exit 0 ;;
- RISC*:Mach:*:*)
- echo mips-dec-mach_bsd4.3
- exit 0 ;;
- RISC*:ULTRIX:*:*)
- echo mips-dec-ultrix${UNAME_RELEASE}
- exit 0 ;;
- VAX*:ULTRIX*:*:*)
- echo vax-dec-ultrix${UNAME_RELEASE}
- exit 0 ;;
- 2020:CLIX:*:* | 2430:CLIX:*:*)
- echo clipper-intergraph-clix${UNAME_RELEASE}
- exit 0 ;;
- mips:*:*:UMIPS | mips:*:*:RISCos)
- eval $set_cc_for_build
- sed 's/^ //' << EOF >$dummy.c
-#ifdef __cplusplus
-#include <stdio.h> /* for printf() prototype */
- int main (int argc, char *argv[]) {
-#else
- int main (argc, argv) int argc; char *argv[]; {
-#endif
- #if defined (host_mips) && defined (MIPSEB)
- #if defined (SYSTYPE_SYSV)
- printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
- #endif
- #if defined (SYSTYPE_SVR4)
- printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
- #endif
- #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
- printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
- #endif
- #endif
- exit (-1);
- }
-EOF
- $CC_FOR_BUILD -o $dummy $dummy.c \
- && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
- && exit 0
- echo mips-mips-riscos${UNAME_RELEASE}
- exit 0 ;;
- Motorola:PowerMAX_OS:*:*)
- echo powerpc-motorola-powermax
- exit 0 ;;
- Motorola:*:4.3:PL8-*)
- echo powerpc-harris-powermax
- exit 0 ;;
- Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
- echo powerpc-harris-powermax
- exit 0 ;;
- Night_Hawk:Power_UNIX:*:*)
- echo powerpc-harris-powerunix
- exit 0 ;;
- m88k:CX/UX:7*:*)
- echo m88k-harris-cxux7
- exit 0 ;;
- m88k:*:4*:R4*)
- echo m88k-motorola-sysv4
- exit 0 ;;
- m88k:*:3*:R3*)
- echo m88k-motorola-sysv3
- exit 0 ;;
- AViiON:dgux:*:*)
- # DG/UX returns AViiON for all architectures
- UNAME_PROCESSOR=`/usr/bin/uname -p`
- if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
- then
- if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
- [ ${TARGET_BINARY_INTERFACE}x = x ]
- then
- echo m88k-dg-dgux${UNAME_RELEASE}
- else
- echo m88k-dg-dguxbcs${UNAME_RELEASE}
- fi
- else
- echo i586-dg-dgux${UNAME_RELEASE}
- fi
- exit 0 ;;
- M88*:DolphinOS:*:*) # DolphinOS (SVR3)
- echo m88k-dolphin-sysv3
- exit 0 ;;
- M88*:*:R3*:*)
- # Delta 88k system running SVR3
- echo m88k-motorola-sysv3
- exit 0 ;;
- XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
- echo m88k-tektronix-sysv3
- exit 0 ;;
- Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
- echo m68k-tektronix-bsd
- exit 0 ;;
- *:IRIX*:*:*)
- echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
- exit 0 ;;
- ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
- echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
- exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX '
- i*86:AIX:*:*)
- echo i386-ibm-aix
- exit 0 ;;
- ia64:AIX:*:*)
- if [ -x /usr/bin/oslevel ] ; then
- IBM_REV=`/usr/bin/oslevel`
- else
- IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
- fi
- echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
- exit 0 ;;
- *:AIX:2:3)
- if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
- eval $set_cc_for_build
- sed 's/^ //' << EOF >$dummy.c
- #include <sys/systemcfg.h>
-
- main()
- {
- if (!__power_pc())
- exit(1);
- puts("powerpc-ibm-aix3.2.5");
- exit(0);
- }
-EOF
- $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
- echo rs6000-ibm-aix3.2.5
- elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
- echo rs6000-ibm-aix3.2.4
- else
- echo rs6000-ibm-aix3.2
- fi
- exit 0 ;;
- *:AIX:*:[45])
- IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
- if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
- IBM_ARCH=rs6000
- else
- IBM_ARCH=powerpc
- fi
- if [ -x /usr/bin/oslevel ] ; then
- IBM_REV=`/usr/bin/oslevel`
- else
- IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
- fi
- echo ${IBM_ARCH}-ibm-aix${IBM_REV}
- exit 0 ;;
- *:AIX:*:*)
- echo rs6000-ibm-aix
- exit 0 ;;
- ibmrt:4.4BSD:*|romp-ibm:BSD:*)
- echo romp-ibm-bsd4.4
- exit 0 ;;
- ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and
- echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
- exit 0 ;; # report: romp-ibm BSD 4.3
- *:BOSX:*:*)
- echo rs6000-bull-bosx
- exit 0 ;;
- DPX/2?00:B.O.S.:*:*)
- echo m68k-bull-sysv3
- exit 0 ;;
- 9000/[34]??:4.3bsd:1.*:*)
- echo m68k-hp-bsd
- exit 0 ;;
- hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
- echo m68k-hp-bsd4.4
- exit 0 ;;
- 9000/[34678]??:HP-UX:*:*)
- HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
- case "${UNAME_MACHINE}" in
- 9000/31? ) HP_ARCH=m68000 ;;
- 9000/[34]?? ) HP_ARCH=m68k ;;
- 9000/[678][0-9][0-9])
- if [ -x /usr/bin/getconf ]; then
- sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
- sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
- case "${sc_cpu_version}" in
- 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
- 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
- 532) # CPU_PA_RISC2_0
- case "${sc_kernel_bits}" in
- 32) HP_ARCH="hppa2.0n" ;;
- 64) HP_ARCH="hppa2.0w" ;;
- '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
- esac ;;
- esac
- fi
- if [ "${HP_ARCH}" = "" ]; then
- eval $set_cc_for_build
- sed 's/^ //' << EOF >$dummy.c
-
- #define _HPUX_SOURCE
- #include <stdlib.h>
- #include <unistd.h>
-
- int main ()
- {
- #if defined(_SC_KERNEL_BITS)
- long bits = sysconf(_SC_KERNEL_BITS);
- #endif
- long cpu = sysconf (_SC_CPU_VERSION);
-
- switch (cpu)
- {
- case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
- case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
- case CPU_PA_RISC2_0:
- #if defined(_SC_KERNEL_BITS)
- switch (bits)
- {
- case 64: puts ("hppa2.0w"); break;
- case 32: puts ("hppa2.0n"); break;
- default: puts ("hppa2.0"); break;
- } break;
- #else /* !defined(_SC_KERNEL_BITS) */
- puts ("hppa2.0"); break;
- #endif
- default: puts ("hppa1.0"); break;
- }
- exit (0);
- }
-EOF
- (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
- test -z "$HP_ARCH" && HP_ARCH=hppa
- fi ;;
- esac
- if [ ${HP_ARCH} = "hppa2.0w" ]
- then
- # avoid double evaluation of $set_cc_for_build
- test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
- if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null
- then
- HP_ARCH="hppa2.0w"
- else
- HP_ARCH="hppa64"
- fi
- fi
- echo ${HP_ARCH}-hp-hpux${HPUX_REV}
- exit 0 ;;
- ia64:HP-UX:*:*)
- HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
- echo ia64-hp-hpux${HPUX_REV}
- exit 0 ;;
- 3050*:HI-UX:*:*)
- eval $set_cc_for_build
- sed 's/^ //' << EOF >$dummy.c
- #include <unistd.h>
- int
- main ()
- {
- long cpu = sysconf (_SC_CPU_VERSION);
- /* The order matters, because CPU_IS_HP_MC68K erroneously returns
- true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
- results, however. */
- if (CPU_IS_PA_RISC (cpu))
- {
- switch (cpu)
- {
- case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
- case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
- case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
- default: puts ("hppa-hitachi-hiuxwe2"); break;
- }
- }
- else if (CPU_IS_HP_MC68K (cpu))
- puts ("m68k-hitachi-hiuxwe2");
- else puts ("unknown-hitachi-hiuxwe2");
- exit (0);
- }
-EOF
- $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
- echo unknown-hitachi-hiuxwe2
- exit 0 ;;
- 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
- echo hppa1.1-hp-bsd
- exit 0 ;;
- 9000/8??:4.3bsd:*:*)
- echo hppa1.0-hp-bsd
- exit 0 ;;
- *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
- echo hppa1.0-hp-mpeix
- exit 0 ;;
- hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
- echo hppa1.1-hp-osf
- exit 0 ;;
- hp8??:OSF1:*:*)
- echo hppa1.0-hp-osf
- exit 0 ;;
- i*86:OSF1:*:*)
- if [ -x /usr/sbin/sysversion ] ; then
- echo ${UNAME_MACHINE}-unknown-osf1mk
- else
- echo ${UNAME_MACHINE}-unknown-osf1
- fi
- exit 0 ;;
- parisc*:Lites*:*:*)
- echo hppa1.1-hp-lites
- exit 0 ;;
- C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
- echo c1-convex-bsd
- exit 0 ;;
- C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
- if getsysinfo -f scalar_acc
- then echo c32-convex-bsd
- else echo c2-convex-bsd
- fi
- exit 0 ;;
- C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
- echo c34-convex-bsd
- exit 0 ;;
- C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
- echo c38-convex-bsd
- exit 0 ;;
- C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
- echo c4-convex-bsd
- exit 0 ;;
- CRAY*Y-MP:*:*:*)
- echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
- exit 0 ;;
- CRAY*[A-Z]90:*:*:*)
- echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
- | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
- -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
- -e 's/\.[^.]*$/.X/'
- exit 0 ;;
- CRAY*TS:*:*:*)
- echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
- exit 0 ;;
- CRAY*T3E:*:*:*)
- echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
- exit 0 ;;
- CRAY*SV1:*:*:*)
- echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
- exit 0 ;;
- *:UNICOS/mp:*:*)
- echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
- exit 0 ;;
- F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
- FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
- FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
- FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
- echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
- exit 0 ;;
- 5000:UNIX_System_V:4.*:*)
- FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
- FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
- echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
- exit 0 ;;
- i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
- echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
- exit 0 ;;
- sparc*:BSD/OS:*:*)
- echo sparc-unknown-bsdi${UNAME_RELEASE}
- exit 0 ;;
- *:BSD/OS:*:*)
- echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
- exit 0 ;;
- *:FreeBSD:*:*)
- echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
- exit 0 ;;
- i*:CYGWIN*:*)
- echo ${UNAME_MACHINE}-pc-cygwin
- exit 0 ;;
- i*:MINGW*:*)
- echo ${UNAME_MACHINE}-pc-mingw32
- exit 0 ;;
- i*:PW*:*)
- echo ${UNAME_MACHINE}-pc-pw32
- exit 0 ;;
- x86:Interix*:[34]*)
- echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
- exit 0 ;;
- [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
- echo i${UNAME_MACHINE}-pc-mks
- exit 0 ;;
- i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
- # How do we know it's Interix rather than the generic POSIX subsystem?
- # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
- # UNAME_MACHINE based on the output of uname instead of i386?
- echo i586-pc-interix
- exit 0 ;;
- i*:UWIN*:*)
- echo ${UNAME_MACHINE}-pc-uwin
- exit 0 ;;
- p*:CYGWIN*:*)
- echo powerpcle-unknown-cygwin
- exit 0 ;;
- prep*:SunOS:5.*:*)
- echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
- exit 0 ;;
- *:GNU:*:*)
- # the GNU system
- echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
- exit 0 ;;
- *:GNU/*:*:*)
- # other systems with GNU libc and userland
- echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
- exit 0 ;;
- i*86:Minix:*:*)
- echo ${UNAME_MACHINE}-pc-minix
- exit 0 ;;
- arm*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit 0 ;;
- cris:Linux:*:*)
- echo cris-axis-linux-gnu
- exit 0 ;;
- ia64:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit 0 ;;
- m32r*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit 0 ;;
- m68*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit 0 ;;
- mips:Linux:*:*)
- eval $set_cc_for_build
- sed 's/^ //' << EOF >$dummy.c
- #undef CPU
- #undef mips
- #undef mipsel
- #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
- CPU=mipsel
- #else
- #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
- CPU=mips
- #else
- CPU=
- #endif
- #endif
-EOF
- eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
- test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
- ;;
- mips64:Linux:*:*)
- eval $set_cc_for_build
- sed 's/^ //' << EOF >$dummy.c
- #undef CPU
- #undef mips64
- #undef mips64el
- #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
- CPU=mips64el
- #else
- #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
- CPU=mips64
- #else
- CPU=
- #endif
- #endif
-EOF
- eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
- test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
- ;;
- ppc:Linux:*:*)
- echo powerpc-unknown-linux-gnu
- exit 0 ;;
- ppc64:Linux:*:*)
- echo powerpc64-unknown-linux-gnu
- exit 0 ;;
- alpha:Linux:*:*)
- case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
- EV5) UNAME_MACHINE=alphaev5 ;;
- EV56) UNAME_MACHINE=alphaev56 ;;
- PCA56) UNAME_MACHINE=alphapca56 ;;
- PCA57) UNAME_MACHINE=alphapca56 ;;
- EV6) UNAME_MACHINE=alphaev6 ;;
- EV67) UNAME_MACHINE=alphaev67 ;;
- EV68*) UNAME_MACHINE=alphaev68 ;;
- esac
- objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
- if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
- echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
- exit 0 ;;
- parisc:Linux:*:* | hppa:Linux:*:*)
- # Look for CPU level
- case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
- PA7*) echo hppa1.1-unknown-linux-gnu ;;
- PA8*) echo hppa2.0-unknown-linux-gnu ;;
- *) echo hppa-unknown-linux-gnu ;;
- esac
- exit 0 ;;
- parisc64:Linux:*:* | hppa64:Linux:*:*)
- echo hppa64-unknown-linux-gnu
- exit 0 ;;
- s390:Linux:*:* | s390x:Linux:*:*)
- echo ${UNAME_MACHINE}-ibm-linux
- exit 0 ;;
- sh64*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit 0 ;;
- sh*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit 0 ;;
- sparc:Linux:*:* | sparc64:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit 0 ;;
- x86_64:Linux:*:*)
- echo x86_64-unknown-linux-gnu
- exit 0 ;;
- i*86:Linux:*:*)
- # The BFD linker knows what the default object file format is, so
- # first see if it will tell us. cd to the root directory to prevent
- # problems with other programs or directories called `ld' in the path.
- # Set LC_ALL=C to ensure ld outputs messages in English.
- ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
- | sed -ne '/supported targets:/!d
- s/[ ][ ]*/ /g
- s/.*supported targets: *//
- s/ .*//
- p'`
- case "$ld_supported_targets" in
- elf32-i386)
- TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
- ;;
- a.out-i386-linux)
- echo "${UNAME_MACHINE}-pc-linux-gnuaout"
- exit 0 ;;
- coff-i386)
- echo "${UNAME_MACHINE}-pc-linux-gnucoff"
- exit 0 ;;
- "")
- # Either a pre-BFD a.out linker (linux-gnuoldld) or
- # one that does not give us useful --help.
- echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
- exit 0 ;;
- esac
- # Determine whether the default compiler is a.out or elf
- eval $set_cc_for_build
- sed 's/^ //' << EOF >$dummy.c
- #include <features.h>
- #ifdef __ELF__
- # ifdef __GLIBC__
- # if __GLIBC__ >= 2
- LIBC=gnu
- # else
- LIBC=gnulibc1
- # endif
- # else
- LIBC=gnulibc1
- # endif
- #else
- #ifdef __INTEL_COMPILER
- LIBC=gnu
- #else
- LIBC=gnuaout
- #endif
- #endif
- #ifdef __dietlibc__
- LIBC=dietlibc
- #endif
-EOF
- eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
- test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
- test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
- ;;
- i*86:DYNIX/ptx:4*:*)
- # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
- # earlier versions are messed up and put the nodename in both
- # sysname and nodename.
- echo i386-sequent-sysv4
- exit 0 ;;
- i*86:UNIX_SV:4.2MP:2.*)
- # Unixware is an offshoot of SVR4, but it has its own version
- # number series starting with 2...
- # I am not positive that other SVR4 systems won't match this,
- # I just have to hope. -- rms.
- # Use sysv4.2uw... so that sysv4* matches it.
- echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
- exit 0 ;;
- i*86:OS/2:*:*)
- # If we were able to find `uname', then EMX Unix compatibility
- # is probably installed.
- echo ${UNAME_MACHINE}-pc-os2-emx
- exit 0 ;;
- i*86:XTS-300:*:STOP)
- echo ${UNAME_MACHINE}-unknown-stop
- exit 0 ;;
- i*86:atheos:*:*)
- echo ${UNAME_MACHINE}-unknown-atheos
- exit 0 ;;
- i*86:syllable:*:*)
- echo ${UNAME_MACHINE}-pc-syllable
- exit 0 ;;
- i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
- echo i386-unknown-lynxos${UNAME_RELEASE}
- exit 0 ;;
- i*86:*DOS:*:*)
- echo ${UNAME_MACHINE}-pc-msdosdjgpp
- exit 0 ;;
- i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
- UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
- if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
- echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
- else
- echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
- fi
- exit 0 ;;
- i*86:*:5:[78]*)
- case `/bin/uname -X | grep "^Machine"` in
- *486*) UNAME_MACHINE=i486 ;;
- *Pentium) UNAME_MACHINE=i586 ;;
- *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
- esac
- echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
- exit 0 ;;
- i*86:*:3.2:*)
- if test -f /usr/options/cb.name; then
- UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
- echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
- elif /bin/uname -X 2>/dev/null >/dev/null ; then
- UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
- (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
- (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
- && UNAME_MACHINE=i586
- (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
- && UNAME_MACHINE=i686
- (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
- && UNAME_MACHINE=i686
- echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
- else
- echo ${UNAME_MACHINE}-pc-sysv32
- fi
- exit 0 ;;
- pc:*:*:*)
- # Left here for compatibility:
- # uname -m prints for DJGPP always 'pc', but it prints nothing about
- # the processor, so we play safe by assuming i386.
- echo i386-pc-msdosdjgpp
- exit 0 ;;
- Intel:Mach:3*:*)
- echo i386-pc-mach3
- exit 0 ;;
- paragon:*:*:*)
- echo i860-intel-osf1
- exit 0 ;;
- i860:*:4.*:*) # i860-SVR4
- if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
- echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
- else # Add other i860-SVR4 vendors below as they are discovered.
- echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
- fi
- exit 0 ;;
- mini*:CTIX:SYS*5:*)
- # "miniframe"
- echo m68010-convergent-sysv
- exit 0 ;;
- mc68k:UNIX:SYSTEM5:3.51m)
- echo m68k-convergent-sysv
- exit 0 ;;
- M680?0:D-NIX:5.3:*)
- echo m68k-diab-dnix
- exit 0 ;;
- M68*:*:R3V[5678]*:*)
- test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
- 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
- OS_REL=''
- test -r /etc/.relid \
- && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
- /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
- && echo i486-ncr-sysv4.3${OS_REL} && exit 0
- /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
- && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
- 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
- /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
- && echo i486-ncr-sysv4 && exit 0 ;;
- m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
- echo m68k-unknown-lynxos${UNAME_RELEASE}
- exit 0 ;;
- mc68030:UNIX_System_V:4.*:*)
- echo m68k-atari-sysv4
- exit 0 ;;
- TSUNAMI:LynxOS:2.*:*)
- echo sparc-unknown-lynxos${UNAME_RELEASE}
- exit 0 ;;
- rs6000:LynxOS:2.*:*)
- echo rs6000-unknown-lynxos${UNAME_RELEASE}
- exit 0 ;;
- PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
- echo powerpc-unknown-lynxos${UNAME_RELEASE}
- exit 0 ;;
- SM[BE]S:UNIX_SV:*:*)
- echo mips-dde-sysv${UNAME_RELEASE}
- exit 0 ;;
- RM*:ReliantUNIX-*:*:*)
- echo mips-sni-sysv4
- exit 0 ;;
- RM*:SINIX-*:*:*)
- echo mips-sni-sysv4
- exit 0 ;;
- *:SINIX-*:*:*)
- if uname -p 2>/dev/null >/dev/null ; then
- UNAME_MACHINE=`(uname -p) 2>/dev/null`
- echo ${UNAME_MACHINE}-sni-sysv4
- else
- echo ns32k-sni-sysv
- fi
- exit 0 ;;
- PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
- # says <Richard.M.Bartel@ccMail.Census.GOV>
- echo i586-unisys-sysv4
- exit 0 ;;
- *:UNIX_System_V:4*:FTX*)
- # From Gerald Hewes <hewes@openmarket.com>.
- # How about differentiating between stratus architectures? -djm
- echo hppa1.1-stratus-sysv4
- exit 0 ;;
- *:*:*:FTX*)
- # From seanf@swdc.stratus.com.
- echo i860-stratus-sysv4
- exit 0 ;;
- *:VOS:*:*)
- # From Paul.Green@stratus.com.
- echo hppa1.1-stratus-vos
- exit 0 ;;
- mc68*:A/UX:*:*)
- echo m68k-apple-aux${UNAME_RELEASE}
- exit 0 ;;
- news*:NEWS-OS:6*:*)
- echo mips-sony-newsos6
- exit 0 ;;
- R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
- if [ -d /usr/nec ]; then
- echo mips-nec-sysv${UNAME_RELEASE}
- else
- echo mips-unknown-sysv${UNAME_RELEASE}
- fi
- exit 0 ;;
- BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
- echo powerpc-be-beos
- exit 0 ;;
- BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
- echo powerpc-apple-beos
- exit 0 ;;
- BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
- echo i586-pc-beos
- exit 0 ;;
- SX-4:SUPER-UX:*:*)
- echo sx4-nec-superux${UNAME_RELEASE}
- exit 0 ;;
- SX-5:SUPER-UX:*:*)
- echo sx5-nec-superux${UNAME_RELEASE}
- exit 0 ;;
- SX-6:SUPER-UX:*:*)
- echo sx6-nec-superux${UNAME_RELEASE}
- exit 0 ;;
- Power*:Rhapsody:*:*)
- echo powerpc-apple-rhapsody${UNAME_RELEASE}
- exit 0 ;;
- *:Rhapsody:*:*)
- echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
- exit 0 ;;
- *:Darwin:*:*)
- case `uname -p` in
- *86) UNAME_PROCESSOR=i686 ;;
- powerpc) UNAME_PROCESSOR=powerpc ;;
- esac
- echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
- exit 0 ;;
- *:procnto*:*:* | *:QNX:[0123456789]*:*)
- UNAME_PROCESSOR=`uname -p`
- if test "$UNAME_PROCESSOR" = "x86"; then
- UNAME_PROCESSOR=i386
- UNAME_MACHINE=pc
- fi
- echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
- exit 0 ;;
- *:QNX:*:4*)
- echo i386-pc-qnx
- exit 0 ;;
- NSR-?:NONSTOP_KERNEL:*:*)
- echo nsr-tandem-nsk${UNAME_RELEASE}
- exit 0 ;;
- *:NonStop-UX:*:*)
- echo mips-compaq-nonstopux
- exit 0 ;;
- BS2000:POSIX*:*:*)
- echo bs2000-siemens-sysv
- exit 0 ;;
- DS/*:UNIX_System_V:*:*)
- echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
- exit 0 ;;
- *:Plan9:*:*)
- # "uname -m" is not consistent, so use $cputype instead. 386
- # is converted to i386 for consistency with other x86
- # operating systems.
- if test "$cputype" = "386"; then
- UNAME_MACHINE=i386
- else
- UNAME_MACHINE="$cputype"
- fi
- echo ${UNAME_MACHINE}-unknown-plan9
- exit 0 ;;
- *:TOPS-10:*:*)
- echo pdp10-unknown-tops10
- exit 0 ;;
- *:TENEX:*:*)
- echo pdp10-unknown-tenex
- exit 0 ;;
- KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
- echo pdp10-dec-tops20
- exit 0 ;;
- XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
- echo pdp10-xkl-tops20
- exit 0 ;;
- *:TOPS-20:*:*)
- echo pdp10-unknown-tops20
- exit 0 ;;
- *:ITS:*:*)
- echo pdp10-unknown-its
- exit 0 ;;
- SEI:*:*:SEIUX)
- echo mips-sei-seiux${UNAME_RELEASE}
- exit 0 ;;
- *:DragonFly:*:*)
- echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
- exit 0 ;;
- *:*VMS:*:*)
- UNAME_MACHINE=`(uname -p) 2>/dev/null`
- case "${UNAME_MACHINE}" in
- A*) echo alpha-dec-vms && exit 0 ;;
- I*) echo ia64-dec-vms && exit 0 ;;
- V*) echo vax-dec-vms && exit 0 ;;
- esac
-esac
-
-#echo '(No uname command or uname output not recognized.)' 1>&2
-#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
-
-eval $set_cc_for_build
-cat >$dummy.c <<EOF
-#ifdef _SEQUENT_
-# include <sys/types.h>
-# include <sys/utsname.h>
-#endif
-main ()
-{
-#if defined (sony)
-#if defined (MIPSEB)
- /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
- I don't know.... */
- printf ("mips-sony-bsd\n"); exit (0);
-#else
-#include <sys/param.h>
- printf ("m68k-sony-newsos%s\n",
-#ifdef NEWSOS4
- "4"
-#else
- ""
-#endif
- ); exit (0);
-#endif
-#endif
-
-#if defined (__arm) && defined (__acorn) && defined (__unix)
- printf ("arm-acorn-riscix"); exit (0);
-#endif
-
-#if defined (hp300) && !defined (hpux)
- printf ("m68k-hp-bsd\n"); exit (0);
-#endif
-
-#if defined (NeXT)
-#if !defined (__ARCHITECTURE__)
-#define __ARCHITECTURE__ "m68k"
-#endif
- int version;
- version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
- if (version < 4)
- printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
- else
- printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
- exit (0);
-#endif
-
-#if defined (MULTIMAX) || defined (n16)
-#if defined (UMAXV)
- printf ("ns32k-encore-sysv\n"); exit (0);
-#else
-#if defined (CMU)
- printf ("ns32k-encore-mach\n"); exit (0);
-#else
- printf ("ns32k-encore-bsd\n"); exit (0);
-#endif
-#endif
-#endif
-
-#if defined (__386BSD__)
- printf ("i386-pc-bsd\n"); exit (0);
-#endif
-
-#if defined (sequent)
-#if defined (i386)
- printf ("i386-sequent-dynix\n"); exit (0);
-#endif
-#if defined (ns32000)
- printf ("ns32k-sequent-dynix\n"); exit (0);
-#endif
-#endif
-
-#if defined (_SEQUENT_)
- struct utsname un;
-
- uname(&un);
-
- if (strncmp(un.version, "V2", 2) == 0) {
- printf ("i386-sequent-ptx2\n"); exit (0);
- }
- if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
- printf ("i386-sequent-ptx1\n"); exit (0);
- }
- printf ("i386-sequent-ptx\n"); exit (0);
-
-#endif
-
-#if defined (vax)
-# if !defined (ultrix)
-# include <sys/param.h>
-# if defined (BSD)
-# if BSD == 43
- printf ("vax-dec-bsd4.3\n"); exit (0);
-# else
-# if BSD == 199006
- printf ("vax-dec-bsd4.3reno\n"); exit (0);
-# else
- printf ("vax-dec-bsd\n"); exit (0);
-# endif
-# endif
-# else
- printf ("vax-dec-bsd\n"); exit (0);
-# endif
-# else
- printf ("vax-dec-ultrix\n"); exit (0);
-# endif
-#endif
-
-#if defined (alliant) && defined (i860)
- printf ("i860-alliant-bsd\n"); exit (0);
-#endif
-
- exit (1);
-}
-EOF
-
-$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0
-
-# Apollos put the system type in the environment.
-
-test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
-
-# Convex versions that predate uname can use getsysinfo(1)
-
-if [ -x /usr/convex/getsysinfo ]
-then
- case `getsysinfo -f cpu_type` in
- c1*)
- echo c1-convex-bsd
- exit 0 ;;
- c2*)
- if getsysinfo -f scalar_acc
- then echo c32-convex-bsd
- else echo c2-convex-bsd
- fi
- exit 0 ;;
- c34*)
- echo c34-convex-bsd
- exit 0 ;;
- c38*)
- echo c38-convex-bsd
- exit 0 ;;
- c4*)
- echo c4-convex-bsd
- exit 0 ;;
- esac
-fi
-
-cat >&2 <<EOF
-$0: unable to guess system type
-
-This script, last modified $timestamp, has failed to recognize
-the operating system you are using. It is advised that you
-download the most up to date version of the config scripts from
-
- ftp://ftp.gnu.org/pub/gnu/config/
-
-If the version you run ($0) is already up to date, please
-send the following data and any information you think might be
-pertinent to <config-patches@gnu.org> in order to provide the needed
-information to handle your system.
-
-config.guess timestamp = $timestamp
-
-uname -m = `(uname -m) 2>/dev/null || echo unknown`
-uname -r = `(uname -r) 2>/dev/null || echo unknown`
-uname -s = `(uname -s) 2>/dev/null || echo unknown`
-uname -v = `(uname -v) 2>/dev/null || echo unknown`
-
-/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
-/bin/uname -X = `(/bin/uname -X) 2>/dev/null`
-
-hostinfo = `(hostinfo) 2>/dev/null`
-/bin/universe = `(/bin/universe) 2>/dev/null`
-/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null`
-/bin/arch = `(/bin/arch) 2>/dev/null`
-/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null`
-/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
-
-UNAME_MACHINE = ${UNAME_MACHINE}
-UNAME_RELEASE = ${UNAME_RELEASE}
-UNAME_SYSTEM = ${UNAME_SYSTEM}
-UNAME_VERSION = ${UNAME_VERSION}
-EOF
-
-exit 1
-
-# Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "timestamp='"
-# time-stamp-format: "%:y-%02m-%02d"
-# time-stamp-end: "'"
-# End:
diff --git a/1.2-netsec/editline/config.h.in b/1.2-netsec/editline/config.h.in
deleted file mode 100644
index 151fb226d..000000000
--- a/1.2-netsec/editline/config.h.in
+++ /dev/null
@@ -1,21 +0,0 @@
-#undef SUNOS
-#undef CYGWIN
-
-#undef HAVE_SYS_CDEFS_H
-#undef HAVE_TERMCAP_H
-#undef HAVE_CURSES_H
-#undef HAVE_NCURSES_H
-#undef HAVE_TERM_H
-#undef HAVE_VIS_H
-#undef HAVE_ISSETUGID
-
-#undef HAVE_STRLCAT
-#undef HAVE_STRLCPY
-#undef HAVE_FGETLN
-#undef HAVE_STRVIS
-#undef HAVE_STRUNVIS
-
-#include "sys.h"
-#ifdef CYGWIN
-# include "cygdef.h"
-#endif
diff --git a/1.2-netsec/editline/config.sub b/1.2-netsec/editline/config.sub
deleted file mode 100755
index 838237e98..000000000
--- a/1.2-netsec/editline/config.sub
+++ /dev/null
@@ -1,1412 +0,0 @@
-#! /bin/sh
-# Configuration validation subroutine script.
-# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-# Free Software Foundation, Inc.
-
-timestamp='2001-09-14'
-
-# This file is (in principle) common to ALL GNU software.
-# The presence of a machine in this file suggests that SOME GNU software
-# can handle that machine. It does not imply ALL GNU software can.
-#
-# This file is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# Please send patches to <config-patches@gnu.org>.
-#
-# Configuration subroutine to validate and canonicalize a configuration type.
-# Supply the specified configuration type as an argument.
-# If it is invalid, we print an error message on stderr and exit with code 1.
-# Otherwise, we print the canonical config type on stdout and succeed.
-
-# This file is supposed to be the same for all GNU packages
-# and recognize all the CPU types, system types and aliases
-# that are meaningful with *any* GNU software.
-# Each package is responsible for reporting which valid configurations
-# it does not support. The user should be able to distinguish
-# a failure to support a valid configuration from a meaningless
-# configuration.
-
-# The goal of this file is to map all the various variations of a given
-# machine specification into a single specification in the form:
-# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
-# or in some cases, the newer four-part form:
-# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
-# It is wrong to echo any other type of specification.
-
-me=`echo "$0" | sed -e 's,.*/,,'`
-
-usage="\
-Usage: $0 [OPTION] CPU-MFR-OPSYS
- $0 [OPTION] ALIAS
-
-Canonicalize a configuration name.
-
-Operation modes:
- -h, --help print this help, then exit
- -t, --time-stamp print date of last modification, then exit
- -v, --version print version number, then exit
-
-Report bugs and patches to <config-patches@gnu.org>."
-
-version="\
-GNU config.sub ($timestamp)
-
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-Free Software Foundation, Inc.
-
-This is free software; see the source for copying conditions. There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
-
-help="
-Try \`$me --help' for more information."
-
-# Parse command line
-while test $# -gt 0 ; do
- case $1 in
- --time-stamp | --time* | -t )
- echo "$timestamp" ; exit 0 ;;
- --version | -v )
- echo "$version" ; exit 0 ;;
- --help | --h* | -h )
- echo "$usage"; exit 0 ;;
- -- ) # Stop option processing
- shift; break ;;
- - ) # Use stdin as input.
- break ;;
- -* )
- echo "$me: invalid option $1$help"
- exit 1 ;;
-
- *local*)
- # First pass through any local machine types.
- echo $1
- exit 0;;
-
- * )
- break ;;
- esac
-done
-
-case $# in
- 0) echo "$me: missing argument$help" >&2
- exit 1;;
- 1) ;;
- *) echo "$me: too many arguments$help" >&2
- exit 1;;
-esac
-
-# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
-# Here we must recognize all the valid KERNEL-OS combinations.
-maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
-case $maybe_os in
- nto-qnx* | linux-gnu* | storm-chaos* | os2-emx* | windows32-*)
- os=-$maybe_os
- basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
- ;;
- *)
- basic_machine=`echo $1 | sed 's/-[^-]*$//'`
- if [ $basic_machine != $1 ]
- then os=`echo $1 | sed 's/.*-/-/'`
- else os=; fi
- ;;
-esac
-
-### Let's recognize common machines as not being operating systems so
-### that things like config.sub decstation-3100 work. We also
-### recognize some manufacturers as not being operating systems, so we
-### can provide default operating systems below.
-case $os in
- -sun*os*)
- # Prevent following clause from handling this invalid input.
- ;;
- -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
- -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
- -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
- -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
- -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
- -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
- -apple | -axis)
- os=
- basic_machine=$1
- ;;
- -sim | -cisco | -oki | -wec | -winbond)
- os=
- basic_machine=$1
- ;;
- -scout)
- ;;
- -wrs)
- os=-vxworks
- basic_machine=$1
- ;;
- -chorusos*)
- os=-chorusos
- basic_machine=$1
- ;;
- -chorusrdb)
- os=-chorusrdb
- basic_machine=$1
- ;;
- -hiux*)
- os=-hiuxwe2
- ;;
- -sco5)
- os=-sco3.2v5
- basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
- ;;
- -sco4)
- os=-sco3.2v4
- basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
- ;;
- -sco3.2.[4-9]*)
- os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
- basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
- ;;
- -sco3.2v[4-9]*)
- # Don't forget version if it is 3.2v4 or newer.
- basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
- ;;
- -sco*)
- os=-sco3.2v2
- basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
- ;;
- -udk*)
- basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
- ;;
- -isc)
- os=-isc2.2
- basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
- ;;
- -clix*)
- basic_machine=clipper-intergraph
- ;;
- -isc*)
- basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
- ;;
- -lynx*)
- os=-lynxos
- ;;
- -ptx*)
- basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
- ;;
- -windowsnt*)
- os=`echo $os | sed -e 's/windowsnt/winnt/'`
- ;;
- -psos*)
- os=-psos
- ;;
- -mint | -mint[0-9]*)
- basic_machine=m68k-atari
- os=-mint
- ;;
-esac
-
-# Decode aliases for certain CPU-COMPANY combinations.
-case $basic_machine in
- # Recognize the basic CPU types without company name.
- # Some are omitted here because they have special meanings below.
- 1750a | 580 \
- | a29k \
- | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
- | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
- | c4x | clipper \
- | d10v | d30v | dsp16xx \
- | fr30 \
- | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
- | i370 | i860 | i960 | ia64 \
- | m32r | m68000 | m68k | m88k | mcore \
- | mips16 | mips64 | mips64el | mips64orion | mips64orionel \
- | mips64vr4100 | mips64vr4100el | mips64vr4300 \
- | mips64vr4300el | mips64vr5000 | mips64vr5000el \
- | mipsbe | mipseb | mipsel | mipsle | mipstx39 | mipstx39el \
- | mipsisa32 \
- | mn10200 | mn10300 \
- | ns16k | ns32k \
- | openrisc \
- | pdp10 | pdp11 | pj | pjl \
- | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
- | pyramid \
- | s390 | s390x \
- | sh | sh[34] | sh[34]eb | shbe | shle \
- | sparc | sparc64 | sparclet | sparclite | sparcv9 | sparcv9b \
- | stormy16 | strongarm \
- | tahoe | thumb | tic80 | tron \
- | v850 \
- | we32k \
- | x86 | xscale \
- | z8k)
- basic_machine=$basic_machine-unknown
- ;;
- m6811 | m68hc11 | m6812 | m68hc12)
- # Motorola 68HC11/12.
- basic_machine=$basic_machine-unknown
- os=-none
- ;;
- m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
- ;;
-
- # We use `pc' rather than `unknown'
- # because (1) that's what they normally are, and
- # (2) the word "unknown" tends to confuse beginning users.
- i*86 | x86_64)
- basic_machine=$basic_machine-pc
- ;;
- # Object if more than one company name word.
- *-*-*)
- echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
- exit 1
- ;;
- # Recognize the basic CPU types with company name.
- 580-* \
- | a29k-* \
- | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
- | alphapca5[67]-* | arc-* \
- | arm-* | armbe-* | armle-* | armv*-* \
- | avr-* \
- | bs2000-* \
- | c[123]* | c30-* | [cjt]90-* | c54x-* \
- | clipper-* | cray2-* | cydra-* \
- | d10v-* | d30v-* \
- | elxsi-* \
- | f30[01]-* | f700-* | fr30-* | fx80-* \
- | h8300-* | h8500-* \
- | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
- | i*86-* | i860-* | i960-* | ia64-* \
- | m32r-* \
- | m68000-* | m680[01234]0-* | m68360-* | m683?2-* | m68k-* \
- | m88110-* | m88k-* | mcore-* \
- | mips-* | mips16-* | mips64-* | mips64el-* | mips64orion-* \
- | mips64orionel-* | mips64vr4100-* | mips64vr4100el-* \
- | mips64vr4300-* | mips64vr4300el-* | mipsbe-* | mipseb-* \
- | mipsle-* | mipsel-* | mipstx39-* | mipstx39el-* \
- | none-* | np1-* | ns16k-* | ns32k-* \
- | orion-* \
- | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
- | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
- | pyramid-* \
- | romp-* | rs6000-* \
- | s390-* | s390x-* \
- | sh-* | sh[34]-* | sh[34]eb-* | shbe-* | shle-* \
- | sparc-* | sparc64-* | sparc86x-* | sparclite-* \
- | sparcv9-* | sparcv9b-* | stormy16-* | strongarm-* | sv1-* \
- | t3e-* | tahoe-* | thumb-* | tic30-* | tic54x-* | tic80-* | tron-* \
- | v850-* | vax-* \
- | we32k-* \
- | x86-* | x86_64-* | xmp-* | xps100-* | xscale-* \
- | ymp-* \
- | z8k-*)
- ;;
- # Recognize the various machine names and aliases which stand
- # for a CPU type and a company and sometimes even an OS.
- 386bsd)
- basic_machine=i386-unknown
- os=-bsd
- ;;
- 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
- basic_machine=m68000-att
- ;;
- 3b*)
- basic_machine=we32k-att
- ;;
- a29khif)
- basic_machine=a29k-amd
- os=-udi
- ;;
- adobe68k)
- basic_machine=m68010-adobe
- os=-scout
- ;;
- alliant | fx80)
- basic_machine=fx80-alliant
- ;;
- altos | altos3068)
- basic_machine=m68k-altos
- ;;
- am29k)
- basic_machine=a29k-none
- os=-bsd
- ;;
- amdahl)
- basic_machine=580-amdahl
- os=-sysv
- ;;
- amiga | amiga-*)
- basic_machine=m68k-unknown
- ;;
- amigaos | amigados)
- basic_machine=m68k-unknown
- os=-amigaos
- ;;
- amigaunix | amix)
- basic_machine=m68k-unknown
- os=-sysv4
- ;;
- apollo68)
- basic_machine=m68k-apollo
- os=-sysv
- ;;
- apollo68bsd)
- basic_machine=m68k-apollo
- os=-bsd
- ;;
- aux)
- basic_machine=m68k-apple
- os=-aux
- ;;
- balance)
- basic_machine=ns32k-sequent
- os=-dynix
- ;;
- convex-c1)
- basic_machine=c1-convex
- os=-bsd
- ;;
- convex-c2)
- basic_machine=c2-convex
- os=-bsd
- ;;
- convex-c32)
- basic_machine=c32-convex
- os=-bsd
- ;;
- convex-c34)
- basic_machine=c34-convex
- os=-bsd
- ;;
- convex-c38)
- basic_machine=c38-convex
- os=-bsd
- ;;
- cray | ymp)
- basic_machine=ymp-cray
- os=-unicos
- ;;
- cray2)
- basic_machine=cray2-cray
- os=-unicos
- ;;
- [cjt]90)
- basic_machine=${basic_machine}-cray
- os=-unicos
- ;;
- crds | unos)
- basic_machine=m68k-crds
- ;;
- cris | cris-* | etrax*)
- basic_machine=cris-axis
- ;;
- da30 | da30-*)
- basic_machine=m68k-da30
- ;;
- decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
- basic_machine=mips-dec
- ;;
- delta | 3300 | motorola-3300 | motorola-delta \
- | 3300-motorola | delta-motorola)
- basic_machine=m68k-motorola
- ;;
- delta88)
- basic_machine=m88k-motorola
- os=-sysv3
- ;;
- dpx20 | dpx20-*)
- basic_machine=rs6000-bull
- os=-bosx
- ;;
- dpx2* | dpx2*-bull)
- basic_machine=m68k-bull
- os=-sysv3
- ;;
- ebmon29k)
- basic_machine=a29k-amd
- os=-ebmon
- ;;
- elxsi)
- basic_machine=elxsi-elxsi
- os=-bsd
- ;;
- encore | umax | mmax)
- basic_machine=ns32k-encore
- ;;
- es1800 | OSE68k | ose68k | ose | OSE)
- basic_machine=m68k-ericsson
- os=-ose
- ;;
- fx2800)
- basic_machine=i860-alliant
- ;;
- genix)
- basic_machine=ns32k-ns
- ;;
- gmicro)
- basic_machine=tron-gmicro
- os=-sysv
- ;;
- go32)
- basic_machine=i386-pc
- os=-go32
- ;;
- h3050r* | hiux*)
- basic_machine=hppa1.1-hitachi
- os=-hiuxwe2
- ;;
- h8300hms)
- basic_machine=h8300-hitachi
- os=-hms
- ;;
- h8300xray)
- basic_machine=h8300-hitachi
- os=-xray
- ;;
- h8500hms)
- basic_machine=h8500-hitachi
- os=-hms
- ;;
- harris)
- basic_machine=m88k-harris
- os=-sysv3
- ;;
- hp300-*)
- basic_machine=m68k-hp
- ;;
- hp300bsd)
- basic_machine=m68k-hp
- os=-bsd
- ;;
- hp300hpux)
- basic_machine=m68k-hp
- os=-hpux
- ;;
- hp3k9[0-9][0-9] | hp9[0-9][0-9])
- basic_machine=hppa1.0-hp
- ;;
- hp9k2[0-9][0-9] | hp9k31[0-9])
- basic_machine=m68000-hp
- ;;
- hp9k3[2-9][0-9])
- basic_machine=m68k-hp
- ;;
- hp9k6[0-9][0-9] | hp6[0-9][0-9])
- basic_machine=hppa1.0-hp
- ;;
- hp9k7[0-79][0-9] | hp7[0-79][0-9])
- basic_machine=hppa1.1-hp
- ;;
- hp9k78[0-9] | hp78[0-9])
- # FIXME: really hppa2.0-hp
- basic_machine=hppa1.1-hp
- ;;
- hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
- # FIXME: really hppa2.0-hp
- basic_machine=hppa1.1-hp
- ;;
- hp9k8[0-9][13679] | hp8[0-9][13679])
- basic_machine=hppa1.1-hp
- ;;
- hp9k8[0-9][0-9] | hp8[0-9][0-9])
- basic_machine=hppa1.0-hp
- ;;
- hppa-next)
- os=-nextstep3
- ;;
- hppaosf)
- basic_machine=hppa1.1-hp
- os=-osf
- ;;
- hppro)
- basic_machine=hppa1.1-hp
- os=-proelf
- ;;
- i370-ibm* | ibm*)
- basic_machine=i370-ibm
- ;;
-# I'm not sure what "Sysv32" means. Should this be sysv3.2?
- i*86v32)
- basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
- os=-sysv32
- ;;
- i*86v4*)
- basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
- os=-sysv4
- ;;
- i*86v)
- basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
- os=-sysv
- ;;
- i*86sol2)
- basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
- os=-solaris2
- ;;
- i386mach)
- basic_machine=i386-mach
- os=-mach
- ;;
- i386-vsta | vsta)
- basic_machine=i386-unknown
- os=-vsta
- ;;
- iris | iris4d)
- basic_machine=mips-sgi
- case $os in
- -irix*)
- ;;
- *)
- os=-irix4
- ;;
- esac
- ;;
- isi68 | isi)
- basic_machine=m68k-isi
- os=-sysv
- ;;
- m88k-omron*)
- basic_machine=m88k-omron
- ;;
- magnum | m3230)
- basic_machine=mips-mips
- os=-sysv
- ;;
- merlin)
- basic_machine=ns32k-utek
- os=-sysv
- ;;
- mingw32)
- basic_machine=i386-pc
- os=-mingw32
- ;;
- miniframe)
- basic_machine=m68000-convergent
- ;;
- *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
- basic_machine=m68k-atari
- os=-mint
- ;;
- mipsel*-linux*)
- basic_machine=mipsel-unknown
- os=-linux-gnu
- ;;
- mips*-linux*)
- basic_machine=mips-unknown
- os=-linux-gnu
- ;;
- mips3*-*)
- basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
- ;;
- mips3*)
- basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
- ;;
- mmix*)
- basic_machine=mmix-knuth
- os=-mmixware
- ;;
- monitor)
- basic_machine=m68k-rom68k
- os=-coff
- ;;
- msdos)
- basic_machine=i386-pc
- os=-msdos
- ;;
- mvs)
- basic_machine=i370-ibm
- os=-mvs
- ;;
- ncr3000)
- basic_machine=i486-ncr
- os=-sysv4
- ;;
- netbsd386)
- basic_machine=i386-unknown
- os=-netbsd
- ;;
- netwinder)
- basic_machine=armv4l-rebel
- os=-linux
- ;;
- news | news700 | news800 | news900)
- basic_machine=m68k-sony
- os=-newsos
- ;;
- news1000)
- basic_machine=m68030-sony
- os=-newsos
- ;;
- news-3600 | risc-news)
- basic_machine=mips-sony
- os=-newsos
- ;;
- necv70)
- basic_machine=v70-nec
- os=-sysv
- ;;
- next | m*-next )
- basic_machine=m68k-next
- case $os in
- -nextstep* )
- ;;
- -ns2*)
- os=-nextstep2
- ;;
- *)
- os=-nextstep3
- ;;
- esac
- ;;
- nh3000)
- basic_machine=m68k-harris
- os=-cxux
- ;;
- nh[45]000)
- basic_machine=m88k-harris
- os=-cxux
- ;;
- nindy960)
- basic_machine=i960-intel
- os=-nindy
- ;;
- mon960)
- basic_machine=i960-intel
- os=-mon960
- ;;
- nonstopux)
- basic_machine=mips-compaq
- os=-nonstopux
- ;;
- np1)
- basic_machine=np1-gould
- ;;
- nsr-tandem)
- basic_machine=nsr-tandem
- ;;
- op50n-* | op60c-*)
- basic_machine=hppa1.1-oki
- os=-proelf
- ;;
- OSE68000 | ose68000)
- basic_machine=m68000-ericsson
- os=-ose
- ;;
- os68k)
- basic_machine=m68k-none
- os=-os68k
- ;;
- pa-hitachi)
- basic_machine=hppa1.1-hitachi
- os=-hiuxwe2
- ;;
- paragon)
- basic_machine=i860-intel
- os=-osf
- ;;
- pbd)
- basic_machine=sparc-tti
- ;;
- pbb)
- basic_machine=m68k-tti
- ;;
- pc532 | pc532-*)
- basic_machine=ns32k-pc532
- ;;
- pentium | p5 | k5 | k6 | nexgen)
- basic_machine=i586-pc
- ;;
- pentiumpro | p6 | 6x86 | athlon)
- basic_machine=i686-pc
- ;;
- pentiumii | pentium2)
- basic_machine=i686-pc
- ;;
- pentium-* | p5-* | k5-* | k6-* | nexgen-*)
- basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
- ;;
- pentiumpro-* | p6-* | 6x86-* | athlon-*)
- basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
- ;;
- pentiumii-* | pentium2-*)
- basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
- ;;
- pn)
- basic_machine=pn-gould
- ;;
- power) basic_machine=power-ibm
- ;;
- ppc) basic_machine=powerpc-unknown
- ;;
- ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
- ;;
- ppcle | powerpclittle | ppc-le | powerpc-little)
- basic_machine=powerpcle-unknown
- ;;
- ppcle-* | powerpclittle-*)
- basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
- ;;
- ppc64) basic_machine=powerpc64-unknown
- ;;
- ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
- ;;
- ppc64le | powerpc64little | ppc64-le | powerpc64-little)
- basic_machine=powerpc64le-unknown
- ;;
- ppc64le-* | powerpc64little-*)
- basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
- ;;
- ps2)
- basic_machine=i386-ibm
- ;;
- pw32)
- basic_machine=i586-unknown
- os=-pw32
- ;;
- rom68k)
- basic_machine=m68k-rom68k
- os=-coff
- ;;
- rm[46]00)
- basic_machine=mips-siemens
- ;;
- rtpc | rtpc-*)
- basic_machine=romp-ibm
- ;;
- sa29200)
- basic_machine=a29k-amd
- os=-udi
- ;;
- sequent)
- basic_machine=i386-sequent
- ;;
- sh)
- basic_machine=sh-hitachi
- os=-hms
- ;;
- sparclite-wrs)
- basic_machine=sparclite-wrs
- os=-vxworks
- ;;
- sps7)
- basic_machine=m68k-bull
- os=-sysv2
- ;;
- spur)
- basic_machine=spur-unknown
- ;;
- st2000)
- basic_machine=m68k-tandem
- ;;
- stratus)
- basic_machine=i860-stratus
- os=-sysv4
- ;;
- sun2)
- basic_machine=m68000-sun
- ;;
- sun2os3)
- basic_machine=m68000-sun
- os=-sunos3
- ;;
- sun2os4)
- basic_machine=m68000-sun
- os=-sunos4
- ;;
- sun3os3)
- basic_machine=m68k-sun
- os=-sunos3
- ;;
- sun3os4)
- basic_machine=m68k-sun
- os=-sunos4
- ;;
- sun4os3)
- basic_machine=sparc-sun
- os=-sunos3
- ;;
- sun4os4)
- basic_machine=sparc-sun
- os=-sunos4
- ;;
- sun4sol2)
- basic_machine=sparc-sun
- os=-solaris2
- ;;
- sun3 | sun3-*)
- basic_machine=m68k-sun
- ;;
- sun4)
- basic_machine=sparc-sun
- ;;
- sun386 | sun386i | roadrunner)
- basic_machine=i386-sun
- ;;
- sv1)
- basic_machine=sv1-cray
- os=-unicos
- ;;
- symmetry)
- basic_machine=i386-sequent
- os=-dynix
- ;;
- t3e)
- basic_machine=t3e-cray
- os=-unicos
- ;;
- tic54x | c54x*)
- basic_machine=tic54x-unknown
- os=-coff
- ;;
- tx39)
- basic_machine=mipstx39-unknown
- ;;
- tx39el)
- basic_machine=mipstx39el-unknown
- ;;
- tower | tower-32)
- basic_machine=m68k-ncr
- ;;
- udi29k)
- basic_machine=a29k-amd
- os=-udi
- ;;
- ultra3)
- basic_machine=a29k-nyu
- os=-sym1
- ;;
- v810 | necv810)
- basic_machine=v810-nec
- os=-none
- ;;
- vaxv)
- basic_machine=vax-dec
- os=-sysv
- ;;
- vms)
- basic_machine=vax-dec
- os=-vms
- ;;
- vpp*|vx|vx-*)
- basic_machine=f301-fujitsu
- ;;
- vxworks960)
- basic_machine=i960-wrs
- os=-vxworks
- ;;
- vxworks68)
- basic_machine=m68k-wrs
- os=-vxworks
- ;;
- vxworks29k)
- basic_machine=a29k-wrs
- os=-vxworks
- ;;
- w65*)
- basic_machine=w65-wdc
- os=-none
- ;;
- w89k-*)
- basic_machine=hppa1.1-winbond
- os=-proelf
- ;;
- windows32)
- basic_machine=i386-pc
- os=-windows32-msvcrt
- ;;
- xmp)
- basic_machine=xmp-cray
- os=-unicos
- ;;
- xps | xps100)
- basic_machine=xps100-honeywell
- ;;
- z8k-*-coff)
- basic_machine=z8k-unknown
- os=-sim
- ;;
- none)
- basic_machine=none-none
- os=-none
- ;;
-
-# Here we handle the default manufacturer of certain CPU types. It is in
-# some cases the only manufacturer, in others, it is the most popular.
- w89k)
- basic_machine=hppa1.1-winbond
- ;;
- op50n)
- basic_machine=hppa1.1-oki
- ;;
- op60c)
- basic_machine=hppa1.1-oki
- ;;
- mips)
- if [ x$os = x-linux-gnu ]; then
- basic_machine=mips-unknown
- else
- basic_machine=mips-mips
- fi
- ;;
- romp)
- basic_machine=romp-ibm
- ;;
- rs6000)
- basic_machine=rs6000-ibm
- ;;
- vax)
- basic_machine=vax-dec
- ;;
- pdp10)
- # there are many clones, so DEC is not a safe bet
- basic_machine=pdp10-unknown
- ;;
- pdp11)
- basic_machine=pdp11-dec
- ;;
- we32k)
- basic_machine=we32k-att
- ;;
- sh3 | sh4 | sh3eb | sh4eb)
- basic_machine=sh-unknown
- ;;
- sparc | sparcv9 | sparcv9b)
- basic_machine=sparc-sun
- ;;
- cydra)
- basic_machine=cydra-cydrome
- ;;
- orion)
- basic_machine=orion-highlevel
- ;;
- orion105)
- basic_machine=clipper-highlevel
- ;;
- mac | mpw | mac-mpw)
- basic_machine=m68k-apple
- ;;
- pmac | pmac-mpw)
- basic_machine=powerpc-apple
- ;;
- c4x*)
- basic_machine=c4x-none
- os=-coff
- ;;
- *-unknown)
- # Make sure to match an already-canonicalized machine name.
- ;;
- *)
- echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
- exit 1
- ;;
-esac
-
-# Here we canonicalize certain aliases for manufacturers.
-case $basic_machine in
- *-digital*)
- basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
- ;;
- *-commodore*)
- basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
- ;;
- *)
- ;;
-esac
-
-# Decode manufacturer-specific aliases for certain operating systems.
-
-if [ x"$os" != x"" ]
-then
-case $os in
- # First match some system type aliases
- # that might get confused with valid system types.
- # -solaris* is a basic system type, with this one exception.
- -solaris1 | -solaris1.*)
- os=`echo $os | sed -e 's|solaris1|sunos4|'`
- ;;
- -solaris)
- os=-solaris2
- ;;
- -svr4*)
- os=-sysv4
- ;;
- -unixware*)
- os=-sysv4.2uw
- ;;
- -gnu/linux*)
- os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
- ;;
- # First accept the basic system types.
- # The portable systems comes first.
- # Each alternative MUST END IN A *, to match a version number.
- # -sysv* is not here because it comes later, after sysvr4.
- -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
- | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
- | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
- | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
- | -aos* \
- | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
- | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
- | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
- | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
- | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
- | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
- | -chorusos* | -chorusrdb* \
- | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
- | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \
- | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \
- | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
- | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
- | -os2* | -vos*)
- # Remember, each alternative MUST END IN *, to match a version number.
- ;;
- -qnx*)
- case $basic_machine in
- x86-* | i*86-*)
- ;;
- *)
- os=-nto$os
- ;;
- esac
- ;;
- -nto*)
- os=-nto-qnx
- ;;
- -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
- | -windows* | -osx | -abug | -netware* | -os9* | -beos* \
- | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
- ;;
- -mac*)
- os=`echo $os | sed -e 's|mac|macos|'`
- ;;
- -linux*)
- os=`echo $os | sed -e 's|linux|linux-gnu|'`
- ;;
- -sunos5*)
- os=`echo $os | sed -e 's|sunos5|solaris2|'`
- ;;
- -sunos6*)
- os=`echo $os | sed -e 's|sunos6|solaris3|'`
- ;;
- -opened*)
- os=-openedition
- ;;
- -wince*)
- os=-wince
- ;;
- -osfrose*)
- os=-osfrose
- ;;
- -osf*)
- os=-osf
- ;;
- -utek*)
- os=-bsd
- ;;
- -dynix*)
- os=-bsd
- ;;
- -acis*)
- os=-aos
- ;;
- -386bsd)
- os=-bsd
- ;;
- -ctix* | -uts*)
- os=-sysv
- ;;
- -ns2 )
- os=-nextstep2
- ;;
- -nsk*)
- os=-nsk
- ;;
- # Preserve the version number of sinix5.
- -sinix5.*)
- os=`echo $os | sed -e 's|sinix|sysv|'`
- ;;
- -sinix*)
- os=-sysv4
- ;;
- -triton*)
- os=-sysv3
- ;;
- -oss*)
- os=-sysv3
- ;;
- -svr4)
- os=-sysv4
- ;;
- -svr3)
- os=-sysv3
- ;;
- -sysvr4)
- os=-sysv4
- ;;
- # This must come after -sysvr4.
- -sysv*)
- ;;
- -ose*)
- os=-ose
- ;;
- -es1800*)
- os=-ose
- ;;
- -xenix)
- os=-xenix
- ;;
- -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
- os=-mint
- ;;
- -none)
- ;;
- *)
- # Get rid of the `-' at the beginning of $os.
- os=`echo $os | sed 's/[^-]*-//'`
- echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
- exit 1
- ;;
-esac
-else
-
-# Here we handle the default operating systems that come with various machines.
-# The value should be what the vendor currently ships out the door with their
-# machine or put another way, the most popular os provided with the machine.
-
-# Note that if you're going to try to match "-MANUFACTURER" here (say,
-# "-sun"), then you have to tell the case statement up towards the top
-# that MANUFACTURER isn't an operating system. Otherwise, code above
-# will signal an error saying that MANUFACTURER isn't an operating
-# system, and we'll never get to this point.
-
-case $basic_machine in
- *-acorn)
- os=-riscix1.2
- ;;
- arm*-rebel)
- os=-linux
- ;;
- arm*-semi)
- os=-aout
- ;;
- pdp10-*)
- os=-tops20
- ;;
- pdp11-*)
- os=-none
- ;;
- *-dec | vax-*)
- os=-ultrix4.2
- ;;
- m68*-apollo)
- os=-domain
- ;;
- i386-sun)
- os=-sunos4.0.2
- ;;
- m68000-sun)
- os=-sunos3
- # This also exists in the configure program, but was not the
- # default.
- # os=-sunos4
- ;;
- m68*-cisco)
- os=-aout
- ;;
- mips*-cisco)
- os=-elf
- ;;
- mips*-*)
- os=-elf
- ;;
- *-tti) # must be before sparc entry or we get the wrong os.
- os=-sysv3
- ;;
- sparc-* | *-sun)
- os=-sunos4.1.1
- ;;
- *-be)
- os=-beos
- ;;
- *-ibm)
- os=-aix
- ;;
- *-wec)
- os=-proelf
- ;;
- *-winbond)
- os=-proelf
- ;;
- *-oki)
- os=-proelf
- ;;
- *-hp)
- os=-hpux
- ;;
- *-hitachi)
- os=-hiux
- ;;
- i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
- os=-sysv
- ;;
- *-cbm)
- os=-amigaos
- ;;
- *-dg)
- os=-dgux
- ;;
- *-dolphin)
- os=-sysv3
- ;;
- m68k-ccur)
- os=-rtu
- ;;
- m88k-omron*)
- os=-luna
- ;;
- *-next )
- os=-nextstep
- ;;
- *-sequent)
- os=-ptx
- ;;
- *-crds)
- os=-unos
- ;;
- *-ns)
- os=-genix
- ;;
- i370-*)
- os=-mvs
- ;;
- *-next)
- os=-nextstep3
- ;;
- *-gould)
- os=-sysv
- ;;
- *-highlevel)
- os=-bsd
- ;;
- *-encore)
- os=-bsd
- ;;
- *-sgi)
- os=-irix
- ;;
- *-siemens)
- os=-sysv4
- ;;
- *-masscomp)
- os=-rtu
- ;;
- f30[01]-fujitsu | f700-fujitsu)
- os=-uxpv
- ;;
- *-rom68k)
- os=-coff
- ;;
- *-*bug)
- os=-coff
- ;;
- *-apple)
- os=-macos
- ;;
- *-atari*)
- os=-mint
- ;;
- *)
- os=-none
- ;;
-esac
-fi
-
-# Here we handle the case where we know the os, and the CPU type, but not the
-# manufacturer. We pick the logical manufacturer.
-vendor=unknown
-case $basic_machine in
- *-unknown)
- case $os in
- -riscix*)
- vendor=acorn
- ;;
- -sunos*)
- vendor=sun
- ;;
- -aix*)
- vendor=ibm
- ;;
- -beos*)
- vendor=be
- ;;
- -hpux*)
- vendor=hp
- ;;
- -mpeix*)
- vendor=hp
- ;;
- -hiux*)
- vendor=hitachi
- ;;
- -unos*)
- vendor=crds
- ;;
- -dgux*)
- vendor=dg
- ;;
- -luna*)
- vendor=omron
- ;;
- -genix*)
- vendor=ns
- ;;
- -mvs* | -opened*)
- vendor=ibm
- ;;
- -ptx*)
- vendor=sequent
- ;;
- -vxsim* | -vxworks*)
- vendor=wrs
- ;;
- -aux*)
- vendor=apple
- ;;
- -hms*)
- vendor=hitachi
- ;;
- -mpw* | -macos*)
- vendor=apple
- ;;
- -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
- vendor=atari
- ;;
- -vos*)
- vendor=stratus
- ;;
- esac
- basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
- ;;
-esac
-
-echo $basic_machine$os
-exit 0
-
-# Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "timestamp='"
-# time-stamp-format: "%:y-%02m-%02d"
-# time-stamp-end: "'"
-# End:
diff --git a/1.2-netsec/editline/configure b/1.2-netsec/editline/configure
deleted file mode 100755
index 7265fe020..000000000
--- a/1.2-netsec/editline/configure
+++ /dev/null
@@ -1,2423 +0,0 @@
-#! /bin/sh
-
-# Guess values for system-dependent variables and create Makefiles.
-# Generated automatically using autoconf version 2.13
-# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
-#
-# This configure script is free software; the Free Software Foundation
-# gives unlimited permission to copy, distribute and modify it.
-
-# Defaults:
-ac_help=
-ac_default_prefix=/usr/local
-# Any additions from configure.in:
-ac_help="$ac_help
- --disable-readline Disable readline compatibility"
-ac_help="$ac_help
- --enable-debug Enable debugging code"
-
-# Initialize some variables set by options.
-# The variables have the same names as the options, with
-# dashes changed to underlines.
-build=NONE
-cache_file=./config.cache
-exec_prefix=NONE
-host=NONE
-no_create=
-nonopt=NONE
-no_recursion=
-prefix=NONE
-program_prefix=NONE
-program_suffix=NONE
-program_transform_name=s,x,x,
-silent=
-site=
-srcdir=
-target=NONE
-verbose=
-x_includes=NONE
-x_libraries=NONE
-bindir='${exec_prefix}/bin'
-sbindir='${exec_prefix}/sbin'
-libexecdir='${exec_prefix}/libexec'
-datadir='${prefix}/share'
-sysconfdir='${prefix}/etc'
-sharedstatedir='${prefix}/com'
-localstatedir='${prefix}/var'
-libdir='${exec_prefix}/lib'
-includedir='${prefix}/include'
-oldincludedir='/usr/include'
-infodir='${prefix}/info'
-mandir='${prefix}/man'
-
-# Initialize some other variables.
-subdirs=
-MFLAGS= MAKEFLAGS=
-SHELL=${CONFIG_SHELL-/bin/sh}
-# Maximum number of lines to put in a shell here document.
-ac_max_here_lines=12
-
-ac_prev=
-for ac_option
-do
-
- # If the previous option needs an argument, assign it.
- if test -n "$ac_prev"; then
- eval "$ac_prev=\$ac_option"
- ac_prev=
- continue
- fi
-
- case "$ac_option" in
- -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
- *) ac_optarg= ;;
- esac
-
- # Accept the important Cygnus configure options, so we can diagnose typos.
-
- case "$ac_option" in
-
- -bindir | --bindir | --bindi | --bind | --bin | --bi)
- ac_prev=bindir ;;
- -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
- bindir="$ac_optarg" ;;
-
- -build | --build | --buil | --bui | --bu)
- ac_prev=build ;;
- -build=* | --build=* | --buil=* | --bui=* | --bu=*)
- build="$ac_optarg" ;;
-
- -cache-file | --cache-file | --cache-fil | --cache-fi \
- | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
- ac_prev=cache_file ;;
- -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
- | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
- cache_file="$ac_optarg" ;;
-
- -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
- ac_prev=datadir ;;
- -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
- | --da=*)
- datadir="$ac_optarg" ;;
-
- -disable-* | --disable-*)
- ac_feature=`echo $ac_option|sed -e 's/-*disable-//'`
- # Reject names that are not valid shell variable names.
- if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then
- { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
- fi
- ac_feature=`echo $ac_feature| sed 's/-/_/g'`
- eval "enable_${ac_feature}=no" ;;
-
- -enable-* | --enable-*)
- ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'`
- # Reject names that are not valid shell variable names.
- if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then
- { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
- fi
- ac_feature=`echo $ac_feature| sed 's/-/_/g'`
- case "$ac_option" in
- *=*) ;;
- *) ac_optarg=yes ;;
- esac
- eval "enable_${ac_feature}='$ac_optarg'" ;;
-
- -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
- | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
- | --exec | --exe | --ex)
- ac_prev=exec_prefix ;;
- -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
- | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
- | --exec=* | --exe=* | --ex=*)
- exec_prefix="$ac_optarg" ;;
-
- -gas | --gas | --ga | --g)
- # Obsolete; use --with-gas.
- with_gas=yes ;;
-
- -help | --help | --hel | --he)
- # Omit some internal or obsolete options to make the list less imposing.
- # This message is too long to be a string in the A/UX 3.1 sh.
- cat << EOF
-Usage: configure [options] [host]
-Options: [defaults in brackets after descriptions]
-Configuration:
- --cache-file=FILE cache test results in FILE
- --help print this message
- --no-create do not create output files
- --quiet, --silent do not print \`checking...' messages
- --version print the version of autoconf that created configure
-Directory and file names:
- --prefix=PREFIX install architecture-independent files in PREFIX
- [$ac_default_prefix]
- --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
- [same as prefix]
- --bindir=DIR user executables in DIR [EPREFIX/bin]
- --sbindir=DIR system admin executables in DIR [EPREFIX/sbin]
- --libexecdir=DIR program executables in DIR [EPREFIX/libexec]
- --datadir=DIR read-only architecture-independent data in DIR
- [PREFIX/share]
- --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc]
- --sharedstatedir=DIR modifiable architecture-independent data in DIR
- [PREFIX/com]
- --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var]
- --libdir=DIR object code libraries in DIR [EPREFIX/lib]
- --includedir=DIR C header files in DIR [PREFIX/include]
- --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include]
- --infodir=DIR info documentation in DIR [PREFIX/info]
- --mandir=DIR man documentation in DIR [PREFIX/man]
- --srcdir=DIR find the sources in DIR [configure dir or ..]
- --program-prefix=PREFIX prepend PREFIX to installed program names
- --program-suffix=SUFFIX append SUFFIX to installed program names
- --program-transform-name=PROGRAM
- run sed PROGRAM on installed program names
-EOF
- cat << EOF
-Host type:
- --build=BUILD configure for building on BUILD [BUILD=HOST]
- --host=HOST configure for HOST [guessed]
- --target=TARGET configure for TARGET [TARGET=HOST]
-Features and packages:
- --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
- --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
- --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
- --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
- --x-includes=DIR X include files are in DIR
- --x-libraries=DIR X library files are in DIR
-EOF
- if test -n "$ac_help"; then
- echo "--enable and --with options recognized:$ac_help"
- fi
- exit 0 ;;
-
- -host | --host | --hos | --ho)
- ac_prev=host ;;
- -host=* | --host=* | --hos=* | --ho=*)
- host="$ac_optarg" ;;
-
- -includedir | --includedir | --includedi | --included | --include \
- | --includ | --inclu | --incl | --inc)
- ac_prev=includedir ;;
- -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
- | --includ=* | --inclu=* | --incl=* | --inc=*)
- includedir="$ac_optarg" ;;
-
- -infodir | --infodir | --infodi | --infod | --info | --inf)
- ac_prev=infodir ;;
- -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
- infodir="$ac_optarg" ;;
-
- -libdir | --libdir | --libdi | --libd)
- ac_prev=libdir ;;
- -libdir=* | --libdir=* | --libdi=* | --libd=*)
- libdir="$ac_optarg" ;;
-
- -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
- | --libexe | --libex | --libe)
- ac_prev=libexecdir ;;
- -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
- | --libexe=* | --libex=* | --libe=*)
- libexecdir="$ac_optarg" ;;
-
- -localstatedir | --localstatedir | --localstatedi | --localstated \
- | --localstate | --localstat | --localsta | --localst \
- | --locals | --local | --loca | --loc | --lo)
- ac_prev=localstatedir ;;
- -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
- | --localstate=* | --localstat=* | --localsta=* | --localst=* \
- | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
- localstatedir="$ac_optarg" ;;
-
- -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
- ac_prev=mandir ;;
- -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
- mandir="$ac_optarg" ;;
-
- -nfp | --nfp | --nf)
- # Obsolete; use --without-fp.
- with_fp=no ;;
-
- -no-create | --no-create | --no-creat | --no-crea | --no-cre \
- | --no-cr | --no-c)
- no_create=yes ;;
-
- -no-recursion | --no-recursion | --no-recursio | --no-recursi \
- | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
- no_recursion=yes ;;
-
- -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
- | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
- | --oldin | --oldi | --old | --ol | --o)
- ac_prev=oldincludedir ;;
- -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
- | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
- | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
- oldincludedir="$ac_optarg" ;;
-
- -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
- ac_prev=prefix ;;
- -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
- prefix="$ac_optarg" ;;
-
- -program-prefix | --program-prefix | --program-prefi | --program-pref \
- | --program-pre | --program-pr | --program-p)
- ac_prev=program_prefix ;;
- -program-prefix=* | --program-prefix=* | --program-prefi=* \
- | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
- program_prefix="$ac_optarg" ;;
-
- -program-suffix | --program-suffix | --program-suffi | --program-suff \
- | --program-suf | --program-su | --program-s)
- ac_prev=program_suffix ;;
- -program-suffix=* | --program-suffix=* | --program-suffi=* \
- | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
- program_suffix="$ac_optarg" ;;
-
- -program-transform-name | --program-transform-name \
- | --program-transform-nam | --program-transform-na \
- | --program-transform-n | --program-transform- \
- | --program-transform | --program-transfor \
- | --program-transfo | --program-transf \
- | --program-trans | --program-tran \
- | --progr-tra | --program-tr | --program-t)
- ac_prev=program_transform_name ;;
- -program-transform-name=* | --program-transform-name=* \
- | --program-transform-nam=* | --program-transform-na=* \
- | --program-transform-n=* | --program-transform-=* \
- | --program-transform=* | --program-transfor=* \
- | --program-transfo=* | --program-transf=* \
- | --program-trans=* | --program-tran=* \
- | --progr-tra=* | --program-tr=* | --program-t=*)
- program_transform_name="$ac_optarg" ;;
-
- -q | -quiet | --quiet | --quie | --qui | --qu | --q \
- | -silent | --silent | --silen | --sile | --sil)
- silent=yes ;;
-
- -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
- ac_prev=sbindir ;;
- -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
- | --sbi=* | --sb=*)
- sbindir="$ac_optarg" ;;
-
- -sharedstatedir | --sharedstatedir | --sharedstatedi \
- | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
- | --sharedst | --shareds | --shared | --share | --shar \
- | --sha | --sh)
- ac_prev=sharedstatedir ;;
- -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
- | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
- | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
- | --sha=* | --sh=*)
- sharedstatedir="$ac_optarg" ;;
-
- -site | --site | --sit)
- ac_prev=site ;;
- -site=* | --site=* | --sit=*)
- site="$ac_optarg" ;;
-
- -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
- ac_prev=srcdir ;;
- -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
- srcdir="$ac_optarg" ;;
-
- -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
- | --syscon | --sysco | --sysc | --sys | --sy)
- ac_prev=sysconfdir ;;
- -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
- | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
- sysconfdir="$ac_optarg" ;;
-
- -target | --target | --targe | --targ | --tar | --ta | --t)
- ac_prev=target ;;
- -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
- target="$ac_optarg" ;;
-
- -v | -verbose | --verbose | --verbos | --verbo | --verb)
- verbose=yes ;;
-
- -version | --version | --versio | --versi | --vers)
- echo "configure generated by autoconf version 2.13"
- exit 0 ;;
-
- -with-* | --with-*)
- ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
- # Reject names that are not valid shell variable names.
- if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then
- { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
- fi
- ac_package=`echo $ac_package| sed 's/-/_/g'`
- case "$ac_option" in
- *=*) ;;
- *) ac_optarg=yes ;;
- esac
- eval "with_${ac_package}='$ac_optarg'" ;;
-
- -without-* | --without-*)
- ac_package=`echo $ac_option|sed -e 's/-*without-//'`
- # Reject names that are not valid shell variable names.
- if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then
- { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
- fi
- ac_package=`echo $ac_package| sed 's/-/_/g'`
- eval "with_${ac_package}=no" ;;
-
- --x)
- # Obsolete; use --with-x.
- with_x=yes ;;
-
- -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
- | --x-incl | --x-inc | --x-in | --x-i)
- ac_prev=x_includes ;;
- -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
- | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
- x_includes="$ac_optarg" ;;
-
- -x-libraries | --x-libraries | --x-librarie | --x-librari \
- | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
- ac_prev=x_libraries ;;
- -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
- | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
- x_libraries="$ac_optarg" ;;
-
- -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; }
- ;;
-
- *)
- if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then
- echo "configure: warning: $ac_option: invalid host type" 1>&2
- fi
- if test "x$nonopt" != xNONE; then
- { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; }
- fi
- nonopt="$ac_option"
- ;;
-
- esac
-done
-
-if test -n "$ac_prev"; then
- { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; }
-fi
-
-trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
-
-# File descriptor usage:
-# 0 standard input
-# 1 file creation
-# 2 errors and warnings
-# 3 some systems may open it to /dev/tty
-# 4 used on the Kubota Titan
-# 6 checking for... messages and results
-# 5 compiler messages saved in config.log
-if test "$silent" = yes; then
- exec 6>/dev/null
-else
- exec 6>&1
-fi
-exec 5>./config.log
-
-echo "\
-This file contains any messages produced by compilers while
-running configure, to aid debugging if configure makes a mistake.
-" 1>&5
-
-# Strip out --no-create and --no-recursion so they do not pile up.
-# Also quote any args containing shell metacharacters.
-ac_configure_args=
-for ac_arg
-do
- case "$ac_arg" in
- -no-create | --no-create | --no-creat | --no-crea | --no-cre \
- | --no-cr | --no-c) ;;
- -no-recursion | --no-recursion | --no-recursio | --no-recursi \
- | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;;
- *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*)
- ac_configure_args="$ac_configure_args '$ac_arg'" ;;
- *) ac_configure_args="$ac_configure_args $ac_arg" ;;
- esac
-done
-
-# NLS nuisances.
-# Only set these to C if already set. These must not be set unconditionally
-# because not all systems understand e.g. LANG=C (notably SCO).
-# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
-# Non-C LC_CTYPE values break the ctype check.
-if test "${LANG+set}" = set; then LANG=C; export LANG; fi
-if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
-if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
-if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
-
-# confdefs.h avoids OS command line length limits that DEFS can exceed.
-rm -rf conftest* confdefs.h
-# AIX cpp loses on an empty file, so make sure it contains at least a newline.
-echo > confdefs.h
-
-# A filename unique to this package, relative to the directory that
-# configure is in, which we can look for to find out if srcdir is correct.
-ac_unique_file=Makefile.in
-
-# Find the source files, if location was not specified.
-if test -z "$srcdir"; then
- ac_srcdir_defaulted=yes
- # Try the directory containing this script, then its parent.
- ac_prog=$0
- ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'`
- test "x$ac_confdir" = "x$ac_prog" && ac_confdir=.
- srcdir=$ac_confdir
- if test ! -r $srcdir/$ac_unique_file; then
- srcdir=..
- fi
-else
- ac_srcdir_defaulted=no
-fi
-if test ! -r $srcdir/$ac_unique_file; then
- if test "$ac_srcdir_defaulted" = yes; then
- { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; }
- else
- { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; }
- fi
-fi
-srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'`
-
-# Prefer explicitly selected file to automatically selected ones.
-if test -z "$CONFIG_SITE"; then
- if test "x$prefix" != xNONE; then
- CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
- else
- CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
- fi
-fi
-for ac_site_file in $CONFIG_SITE; do
- if test -r "$ac_site_file"; then
- echo "loading site script $ac_site_file"
- . "$ac_site_file"
- fi
-done
-
-if test -r "$cache_file"; then
- echo "loading cache $cache_file"
- . $cache_file
-else
- echo "creating cache $cache_file"
- > $cache_file
-fi
-
-ac_ext=c
-# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
-ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
-cross_compiling=$ac_cv_prog_cc_cross
-
-ac_exeext=
-ac_objext=o
-if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
- # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
- if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
- ac_n= ac_c='
-' ac_t=' '
- else
- ac_n=-n ac_c= ac_t=
- fi
-else
- ac_n= ac_c='\c' ac_t=
-fi
-
-
-
-CFLAGS=$CFLAGS
-# Extract the first word of "gcc", so it can be a program name with args.
-set dummy gcc; ac_word=$2
-echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:534: checking for $ac_word" >&5
-if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- if test -n "$CC"; then
- ac_cv_prog_CC="$CC" # Let the user override the test.
-else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
- ac_dummy="$PATH"
- for ac_dir in $ac_dummy; do
- test -z "$ac_dir" && ac_dir=.
- if test -f $ac_dir/$ac_word; then
- ac_cv_prog_CC="gcc"
- break
- fi
- done
- IFS="$ac_save_ifs"
-fi
-fi
-CC="$ac_cv_prog_CC"
-if test -n "$CC"; then
- echo "$ac_t""$CC" 1>&6
-else
- echo "$ac_t""no" 1>&6
-fi
-
-if test -z "$CC"; then
- # Extract the first word of "cc", so it can be a program name with args.
-set dummy cc; ac_word=$2
-echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:564: checking for $ac_word" >&5
-if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- if test -n "$CC"; then
- ac_cv_prog_CC="$CC" # Let the user override the test.
-else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
- ac_prog_rejected=no
- ac_dummy="$PATH"
- for ac_dir in $ac_dummy; do
- test -z "$ac_dir" && ac_dir=.
- if test -f $ac_dir/$ac_word; then
- if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then
- ac_prog_rejected=yes
- continue
- fi
- ac_cv_prog_CC="cc"
- break
- fi
- done
- IFS="$ac_save_ifs"
-if test $ac_prog_rejected = yes; then
- # We found a bogon in the path, so make sure we never use it.
- set dummy $ac_cv_prog_CC
- shift
- if test $# -gt 0; then
- # We chose a different compiler from the bogus one.
- # However, it has the same basename, so the bogon will be chosen
- # first if we set CC to just the basename; use the full file name.
- shift
- set dummy "$ac_dir/$ac_word" "$@"
- shift
- ac_cv_prog_CC="$@"
- fi
-fi
-fi
-fi
-CC="$ac_cv_prog_CC"
-if test -n "$CC"; then
- echo "$ac_t""$CC" 1>&6
-else
- echo "$ac_t""no" 1>&6
-fi
-
- if test -z "$CC"; then
- case "`uname -s`" in
- *win32* | *WIN32*)
- # Extract the first word of "cl", so it can be a program name with args.
-set dummy cl; ac_word=$2
-echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:615: checking for $ac_word" >&5
-if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- if test -n "$CC"; then
- ac_cv_prog_CC="$CC" # Let the user override the test.
-else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
- ac_dummy="$PATH"
- for ac_dir in $ac_dummy; do
- test -z "$ac_dir" && ac_dir=.
- if test -f $ac_dir/$ac_word; then
- ac_cv_prog_CC="cl"
- break
- fi
- done
- IFS="$ac_save_ifs"
-fi
-fi
-CC="$ac_cv_prog_CC"
-if test -n "$CC"; then
- echo "$ac_t""$CC" 1>&6
-else
- echo "$ac_t""no" 1>&6
-fi
- ;;
- esac
- fi
- test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
-fi
-
-echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:647: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
-
-ac_ext=c
-# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
-ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
-cross_compiling=$ac_cv_prog_cc_cross
-
-cat > conftest.$ac_ext << EOF
-
-#line 658 "configure"
-#include "confdefs.h"
-
-main(){return(0);}
-EOF
-if { (eval echo configure:663: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- ac_cv_prog_cc_works=yes
- # If we can't run a trivial program, we are probably using a cross compiler.
- if (./conftest; exit) 2>/dev/null; then
- ac_cv_prog_cc_cross=no
- else
- ac_cv_prog_cc_cross=yes
- fi
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- ac_cv_prog_cc_works=no
-fi
-rm -fr conftest*
-ac_ext=c
-# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
-ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
-cross_compiling=$ac_cv_prog_cc_cross
-
-echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
-if test $ac_cv_prog_cc_works = no; then
- { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
-fi
-echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:689: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
-echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
-cross_compiling=$ac_cv_prog_cc_cross
-
-echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:694: checking whether we are using GNU C" >&5
-if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.c <<EOF
-#ifdef __GNUC__
- yes;
-#endif
-EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:703: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
- ac_cv_prog_gcc=yes
-else
- ac_cv_prog_gcc=no
-fi
-fi
-
-echo "$ac_t""$ac_cv_prog_gcc" 1>&6
-
-if test $ac_cv_prog_gcc = yes; then
- GCC=yes
-else
- GCC=
-fi
-
-ac_test_CFLAGS="${CFLAGS+set}"
-ac_save_CFLAGS="$CFLAGS"
-CFLAGS=
-echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:722: checking whether ${CC-cc} accepts -g" >&5
-if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- echo 'void f(){}' > conftest.c
-if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
- ac_cv_prog_cc_g=yes
-else
- ac_cv_prog_cc_g=no
-fi
-rm -f conftest*
-
-fi
-
-echo "$ac_t""$ac_cv_prog_cc_g" 1>&6
-if test "$ac_test_CFLAGS" = set; then
- CFLAGS="$ac_save_CFLAGS"
-elif test $ac_cv_prog_cc_g = yes; then
- if test "$GCC" = yes; then
- CFLAGS="-g -O2"
- else
- CFLAGS="-g"
- fi
-else
- if test "$GCC" = yes; then
- CFLAGS="-O2"
- else
- CFLAGS=
- fi
-fi
-
-if test "x$CFLAGS" = "x" ; then
- no_CFLAGS="yes"
-fi
-if test "x$no_CFLAGS" = "xyes" -a "x$GCC" = "xyes" ; then
- CFLAGS="-Wall -pipe -g3"
-fi
-A_CFLAGS=""
-
-S_CFLAGS="-fPIC -DPIC"
-
-echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:764: checking how to run the C preprocessor" >&5
-# On Suns, sometimes $CPP names a directory.
-if test -n "$CPP" && test -d "$CPP"; then
- CPP=
-fi
-if test -z "$CPP"; then
-if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- # This must be in double quotes, not single quotes, because CPP may get
- # substituted into the Makefile and "${CC-cc}" will confuse make.
- CPP="${CC-cc} -E"
- # On the NeXT, cc -E runs the code through the compiler's parser,
- # not just through cpp.
- cat > conftest.$ac_ext <<EOF
-#line 779 "configure"
-#include "confdefs.h"
-#include <assert.h>
-Syntax Error
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:785: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
- :
-else
- echo "$ac_err" >&5
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- CPP="${CC-cc} -E -traditional-cpp"
- cat > conftest.$ac_ext <<EOF
-#line 796 "configure"
-#include "confdefs.h"
-#include <assert.h>
-Syntax Error
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:802: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
- :
-else
- echo "$ac_err" >&5
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- CPP="${CC-cc} -nologo -E"
- cat > conftest.$ac_ext <<EOF
-#line 813 "configure"
-#include "confdefs.h"
-#include <assert.h>
-Syntax Error
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:819: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
- :
-else
- echo "$ac_err" >&5
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- CPP=/lib/cpp
-fi
-rm -f conftest*
-fi
-rm -f conftest*
-fi
-rm -f conftest*
- ac_cv_prog_CPP="$CPP"
-fi
- CPP="$ac_cv_prog_CPP"
-else
- ac_cv_prog_CPP="$CPP"
-fi
-echo "$ac_t""$CPP" 1>&6
-
-
-ac_aux_dir=
-for ac_dir in ${GNUSYSTEM_AUX_DIR} $srcdir $srcdir/.. $srcdir/../..; do
- if test -f $ac_dir/install-sh; then
- ac_aux_dir=$ac_dir
- ac_install_sh="$ac_aux_dir/install-sh -c"
- break
- elif test -f $ac_dir/install.sh; then
- ac_aux_dir=$ac_dir
- ac_install_sh="$ac_aux_dir/install.sh -c"
- break
- fi
-done
-if test -z "$ac_aux_dir"; then
- { echo "configure: error: can not find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." 1>&2; exit 1; }
-fi
-ac_config_guess=$ac_aux_dir/config.guess
-ac_config_sub=$ac_aux_dir/config.sub
-ac_configure=$ac_aux_dir/configure # This should be Cygnus configure.
-
-
-# Make sure we can run config.sub.
-if ${CONFIG_SHELL-/bin/sh} $ac_config_sub sun4 >/dev/null 2>&1; then :
-else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; }
-fi
-
-echo $ac_n "checking host system type""... $ac_c" 1>&6
-echo "configure:870: checking host system type" >&5
-
-host_alias=$host
-case "$host_alias" in
-NONE)
- case $nonopt in
- NONE)
- if host_alias=`${CONFIG_SHELL-/bin/sh} $ac_config_guess`; then :
- else { echo "configure: error: can not guess host type; you must specify one" 1>&2; exit 1; }
- fi ;;
- *) host_alias=$nonopt ;;
- esac ;;
-esac
-
-host=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $host_alias`
-host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
-host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
-host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
-echo "$ac_t""$host" 1>&6
-
-case "${host}" in
- *-*-darwin*)
- CFLAGS="$CFLAGS -fno-common -no-cpp-precomp"
- ABI="macho"
- ;;
- *-*-freebsd*)
- ABI="elf"
- ;;
- *-*-linux* | *cygwin*)
- if echo ${host} | grep -q cygwin ; then \
- echo "cygwin detected"; \
- S_CFLAGS=""; \
- echo "/* cygdef.h. Generated automatically by configure. */
-#ifndef _CYGDEF_H_
-#define _CYGDEF_H_ 1
-#include <sys/ioctl.h>
-#define __linux__ 1
-
-
-typedef void (*sig_t)(int);
-
-
-#endif /* _CYGDEF_H_ */" > cygdef.h; \
- echo "
- #define CYGWIN 1
-" > confdefs.h; \
- fi
- ABI="elf"
- ;;
- *-*-netbsd*)
- echo $ac_n "checking ABI""... $ac_c" 1>&6
-echo "configure:903: checking ABI" >&5
- cat > conftest.$ac_ext <<EOF
-#line 905 "configure"
-#include "confdefs.h"
-#ifdef __ELF__
- yes
-#endif
-
-EOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- egrep "yes" >/dev/null 2>&1; then
- rm -rf conftest*
- ABI="elf"
-else
- rm -rf conftest*
- ABI="aout"
-fi
-rm -f conftest*
-
- echo "$ac_t""$ABI" 1>&6
- ;;
- *-*-solaris2*)
- ABI="elf"
- cat >> confdefs.h <<\EOF
-#define SUNOS 1
-EOF
-
- ;;
- *)
- echo "$ac_t""Unsupported operating system: ${host}" 1>&6
- ABI="elf"
- ;;
-esac
-
-# Find a good install program. We prefer a C program (faster),
-# so one script is as good as another. But avoid the broken or
-# incompatible versions:
-# SysV /etc/install, /usr/sbin/install
-# SunOS /usr/etc/install
-# IRIX /sbin/install
-# AIX /bin/install
-# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
-# AFS /usr/afsws/bin/install, which mishandles nonexistent args
-# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
-# ./install, which can be erroneously created by make from ./install.sh.
-echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:949: checking for a BSD compatible install" >&5
-if test -z "$INSTALL"; then
-if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS=":"
- for ac_dir in $PATH; do
- # Account for people who put trailing slashes in PATH elements.
- case "$ac_dir/" in
- /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
- *)
- # OSF1 and SCO ODT 3.0 have their own names for install.
- # Don't use installbsd from OSF since it installs stuff as root
- # by default.
- for ac_prog in ginstall scoinst install; do
- if test -f $ac_dir/$ac_prog; then
- if test $ac_prog = install &&
- grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
- # AIX install. It has an incompatible calling convention.
- :
- else
- ac_cv_path_install="$ac_dir/$ac_prog -c"
- break 2
- fi
- fi
- done
- ;;
- esac
- done
- IFS="$ac_save_IFS"
-
-fi
- if test "${ac_cv_path_install+set}" = set; then
- INSTALL="$ac_cv_path_install"
- else
- # As a last resort, use the slow shell script. We don't cache a
- # path for INSTALL within a source directory, because that will
- # break other packages using the cache if that directory is
- # removed, or if the path is relative.
- INSTALL="$ac_install_sh"
- fi
-fi
-echo "$ac_t""$INSTALL" 1>&6
-
-# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
-# It thinks the first close brace ends the variable substitution.
-test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
-
-test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
-
-test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
-
-# Extract the first word of "ranlib", so it can be a program name with args.
-set dummy ranlib; ac_word=$2
-echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1004: checking for $ac_word" >&5
-if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- if test -n "$RANLIB"; then
- ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
-else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
- ac_dummy="$PATH"
- for ac_dir in $ac_dummy; do
- test -z "$ac_dir" && ac_dir=.
- if test -f $ac_dir/$ac_word; then
- ac_cv_prog_RANLIB="ranlib"
- break
- fi
- done
- IFS="$ac_save_ifs"
- test -z "$ac_cv_prog_RANLIB" && ac_cv_prog_RANLIB=":"
-fi
-fi
-RANLIB="$ac_cv_prog_RANLIB"
-if test -n "$RANLIB"; then
- echo "$ac_t""$RANLIB" 1>&6
-else
- echo "$ac_t""no" 1>&6
-fi
-
-# Extract the first word of "ar", so it can be a program name with args.
-set dummy ar; ac_word=$2
-echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1034: checking for $ac_word" >&5
-if eval "test \"`echo '$''{'ac_cv_path_AR'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- case "$AR" in
- /*)
- ac_cv_path_AR="$AR" # Let the user override the test with a path.
- ;;
- ?:/*)
- ac_cv_path_AR="$AR" # Let the user override the test with a dos path.
- ;;
- *)
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
- ac_dummy="$PATH"
- for ac_dir in $ac_dummy; do
- test -z "$ac_dir" && ac_dir=.
- if test -f $ac_dir/$ac_word; then
- ac_cv_path_AR="$ac_dir/$ac_word"
- break
- fi
- done
- IFS="$ac_save_ifs"
- ;;
-esac
-fi
-AR="$ac_cv_path_AR"
-if test -n "$AR"; then
- echo "$ac_t""$AR" 1>&6
-else
- echo "$ac_t""no" 1>&6
-fi
-
-
-echo $ac_n "checking for tgetent in -ltermcap""... $ac_c" 1>&6
-echo "configure:1068: checking for tgetent in -ltermcap" >&5
-ac_lib_var=`echo termcap'_'tgetent | sed 'y%./+-%__p_%'`
-if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- ac_save_LIBS="$LIBS"
-LIBS="-ltermcap $LIBS"
-cat > conftest.$ac_ext <<EOF
-#line 1076 "configure"
-#include "confdefs.h"
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char tgetent();
-
-int main() {
-tgetent()
-; return 0; }
-EOF
-if { (eval echo configure:1087: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_lib_$ac_lib_var=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_lib_$ac_lib_var=no"
-fi
-rm -f conftest*
-LIBS="$ac_save_LIBS"
-
-fi
-if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_lib=HAVE_LIB`echo termcap | sed -e 's/[^a-zA-Z0-9_]/_/g' \
- -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_lib 1
-EOF
-
- LIBS="-ltermcap $LIBS"
-
-else
- echo "$ac_t""no" 1>&6
-\
- echo $ac_n "checking for tgetent in -ltinfo""... $ac_c" 1>&6
-echo "configure:1114: checking for tgetent in -ltinfo" >&5
-ac_lib_var=`echo tinfo'_'tgetent | sed 'y%./+-%__p_%'`
-if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- ac_save_LIBS="$LIBS"
-LIBS="-ltinfo $LIBS"
-cat > conftest.$ac_ext <<EOF
-#line 1122 "configure"
-#include "confdefs.h"
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char tgetent();
-
-int main() {
-tgetent()
-; return 0; }
-EOF
-if { (eval echo configure:1133: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_lib_$ac_lib_var=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_lib_$ac_lib_var=no"
-fi
-rm -f conftest*
-LIBS="$ac_save_LIBS"
-
-fi
-if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_lib=HAVE_LIB`echo tinfo | sed -e 's/^a-zA-Z0-9_/_/g' \
- -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_lib 1
-EOF
-
- LIBS="-ltinfo $LIBS"
-
-else
- echo "$ac_t""no" 1>&6
-\
- echo $ac_n "checking for tgetent in -lcurses""... $ac_c" 1>&6
-echo "configure:1160: checking for tgetent in -lcurses" >&5
-ac_lib_var=`echo curses'_'tgetent | sed 'y%./+-%__p_%'`
-if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- ac_save_LIBS="$LIBS"
-LIBS="-lcurses $LIBS"
-cat > conftest.$ac_ext <<EOF
-#line 1168 "configure"
-#include "confdefs.h"
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char tgetent();
-
-int main() {
-tgetent()
-; return 0; }
-EOF
-if { (eval echo configure:1179: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_lib_$ac_lib_var=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_lib_$ac_lib_var=no"
-fi
-rm -f conftest*
-LIBS="$ac_save_LIBS"
-
-fi
-if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_lib=HAVE_LIB`echo curses | sed -e 's/^a-zA-Z0-9_/_/g' \
- -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_lib 1
-EOF
-
- LIBS="-lcurses $LIBS"
-
-else
- echo "$ac_t""no" 1>&6
-\
- echo $ac_n "checking for tgetent in -lncurses""... $ac_c" 1>&6
-echo "configure:1206: checking for tgetent in -lncurses" >&5
-ac_lib_var=`echo ncurses'_'tgetent | sed 'y%./+-%__p_%'`
-if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- ac_save_LIBS="$LIBS"
-LIBS="-lncurses $LIBS"
-cat > conftest.$ac_ext <<EOF
-#line 1214 "configure"
-#include "confdefs.h"
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char tgetent();
-
-int main() {
-tgetent()
-; return 0; }
-EOF
-if { (eval echo configure:1225: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_lib_$ac_lib_var=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_lib_$ac_lib_var=no"
-fi
-rm -f conftest*
-LIBS="$ac_save_LIBS"
-
-fi
-if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_lib=HAVE_LIB`echo ncurses | sed -e 's/^a-zA-Z0-9_/_/g' \
- -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_lib 1
-EOF
-
- LIBS="-lncurses $LIBS"
-
-else
- echo "$ac_t""no" 1>&6
-\
- { echo "configure: error: termcap support not found" 1>&2; exit 1; }
-fi
-
-fi
-
-fi
-
-fi
-
-
-for ac_hdr in termcap.h
-do
-ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
-echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1265: checking for $ac_hdr" >&5
-if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1270 "configure"
-#include "confdefs.h"
-#include <$ac_hdr>
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1275: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=yes"
-else
- echo "$ac_err" >&5
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=no"
-fi
-rm -f conftest*
-fi
-if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_hdr 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-\
- for ac_hdr in term.h
-do
-ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
-echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1303: checking for $ac_hdr" >&5
-if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1308 "configure"
-#include "confdefs.h"
-#include <$ac_hdr>
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1313: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=yes"
-else
- echo "$ac_err" >&5
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=no"
-fi
-rm -f conftest*
-fi
-if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_hdr 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-\
- echo "$ac_t""Need term.h since termcap.h is missing" 1>&6
-fi
-done
-
- for ac_hdr in curses.h
-do
-ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
-echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1345: checking for $ac_hdr" >&5
-if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1350 "configure"
-#include "confdefs.h"
-#include <$ac_hdr>
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1355: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=yes"
-else
- echo "$ac_err" >&5
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=no"
-fi
-rm -f conftest*
-fi
-if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_hdr 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-\
- for ac_hdr in ncurses.h
-do
-ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
-echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1383: checking for $ac_hdr" >&5
-if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1388 "configure"
-#include "confdefs.h"
-#include <$ac_hdr>
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1393: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=yes"
-else
- echo "$ac_err" >&5
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=no"
-fi
-rm -f conftest*
-fi
-if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_hdr 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-\
- echo "$ac_t""Need curses.h or ncurses.h" 1>&6
-fi
-done
-
-fi
-done
-
-fi
-done
-
-
-for ac_hdr in sys/cdefs.h vis.h
-do
-ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
-echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1432: checking for $ac_hdr" >&5
-if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1437 "configure"
-#include "confdefs.h"
-#include <$ac_hdr>
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1442: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=yes"
-else
- echo "$ac_err" >&5
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=no"
-fi
-rm -f conftest*
-fi
-if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_hdr 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-fi
-done
-
-
-for ac_func in issetugid
-do
-echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1472: checking for $ac_func" >&5
-if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1477 "configure"
-#include "confdefs.h"
-/* System header to define __stub macros and hopefully few prototypes,
- which can conflict with char $ac_func(); below. */
-#include <assert.h>
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char $ac_func();
-
-int main() {
-
-/* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-$ac_func();
-#endif
-
-; return 0; }
-EOF
-if { (eval echo configure:1500: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=no"
-fi
-rm -f conftest*
-fi
-
-if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_func 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-fi
-done
-
-for ac_func in strlcat
-do
-echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1527: checking for $ac_func" >&5
-if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1532 "configure"
-#include "confdefs.h"
-/* System header to define __stub macros and hopefully few prototypes,
- which can conflict with char $ac_func(); below. */
-#include <assert.h>
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char $ac_func();
-
-int main() {
-
-/* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-$ac_func();
-#endif
-
-; return 0; }
-EOF
-if { (eval echo configure:1555: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=no"
-fi
-rm -f conftest*
-fi
-
-if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_func 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-CCSRCS="$CCSRCS np/strlcat.c"
-fi
-done
-
-for ac_func in strlcpy
-do
-echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1583: checking for $ac_func" >&5
-if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1588 "configure"
-#include "confdefs.h"
-/* System header to define __stub macros and hopefully few prototypes,
- which can conflict with char $ac_func(); below. */
-#include <assert.h>
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char $ac_func();
-
-int main() {
-
-/* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-$ac_func();
-#endif
-
-; return 0; }
-EOF
-if { (eval echo configure:1611: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=no"
-fi
-rm -f conftest*
-fi
-
-if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_func 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-CCSRCS="$CCSRCS np/strlcpy.c"
-fi
-done
-
-for ac_func in fgetln
-do
-echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1639: checking for $ac_func" >&5
-if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1644 "configure"
-#include "confdefs.h"
-/* System header to define __stub macros and hopefully few prototypes,
- which can conflict with char $ac_func(); below. */
-#include <assert.h>
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char $ac_func();
-
-int main() {
-
-/* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-$ac_func();
-#endif
-
-; return 0; }
-EOF
-if { (eval echo configure:1667: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=no"
-fi
-rm -f conftest*
-fi
-
-if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_func 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-CCSRCS="$CCSRCS np/fgetln.c"
-fi
-done
-
-for ac_func in strvis
-do
-echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1695: checking for $ac_func" >&5
-if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1700 "configure"
-#include "confdefs.h"
-/* System header to define __stub macros and hopefully few prototypes,
- which can conflict with char $ac_func(); below. */
-#include <assert.h>
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char $ac_func();
-
-int main() {
-
-/* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-$ac_func();
-#endif
-
-; return 0; }
-EOF
-if { (eval echo configure:1723: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=no"
-fi
-rm -f conftest*
-fi
-
-if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_func 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-CCSRCS="$CCSRCS np/vis.c"
-fi
-done
-
-for ac_func in strunvis
-do
-echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1751: checking for $ac_func" >&5
-if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1756 "configure"
-#include "confdefs.h"
-/* System header to define __stub macros and hopefully few prototypes,
- which can conflict with char $ac_func(); below. */
-#include <assert.h>
-/* Override any gcc2 internal prototype to avoid an error. */
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char $ac_func();
-
-int main() {
-
-/* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-$ac_func();
-#endif
-
-; return 0; }
-EOF
-if { (eval echo configure:1779: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=yes"
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_func_$ac_func=no"
-fi
-rm -f conftest*
-fi
-
-if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
- cat >> confdefs.h <<EOF
-#define $ac_tr_func 1
-EOF
-
-else
- echo "$ac_t""no" 1>&6
-CCSRCS="$CCSRCS np/unvis.c"
-fi
-done
-
-
-cat > conftest.$ac_ext <<EOF
-#line 1806 "configure"
-#include "confdefs.h"
-#include <sys/cdefs.h>
-#ifdef __RCSID
- yes
-#endif
-
-EOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- egrep "yes" >/dev/null 2>&1; then
- :
-else
- rm -rf conftest*
- CPPFLAGS="$CPPFLAGS '-D__RCSID(x)='"
-fi
-rm -f conftest*
-
-
-cat > conftest.$ac_ext <<EOF
-#line 1825 "configure"
-#include "confdefs.h"
-#include <sys/cdefs.h>
-#ifdef __COPYRIGHT
- yes
-#endif
-
-EOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- egrep "yes" >/dev/null 2>&1; then
- :
-else
- rm -rf conftest*
- CPPFLAGS="$CPPFLAGS '-D__COPYRIGHT(x)='"
-fi
-rm -f conftest*
-
-
-cat > conftest.$ac_ext <<EOF
-#line 1844 "configure"
-#include "confdefs.h"
-#include <sys/cdefs.h>
-#ifdef __RENAME
- yes
-#endif
-
-EOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- egrep "yes" >/dev/null 2>&1; then
- :
-else
- rm -rf conftest*
- CPPFLAGS="$CPPFLAGS '-D__RENAME(x)='"
-fi
-rm -f conftest*
-
-
-cat > conftest.$ac_ext <<EOF
-#line 1863 "configure"
-#include "confdefs.h"
-#include <sys/cdefs.h>
-#ifdef _DIAGASSERT
- yes
-#endif
-
-EOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- egrep "yes" >/dev/null 2>&1; then
- :
-else
- rm -rf conftest*
- CPPFLAGS="$CPPFLAGS '-D_DIAGASSERT(x)='"
-fi
-rm -f conftest*
-
-
-# Check whether --enable-readline or --disable-readline was given.
-if test "${enable_readline+set}" = set; then
- enableval="$enable_readline"
- if test "x$enable_readline" != "xyes" ; then
- enable_readline="no"
-fi
-
-else
- enable_readline="yes"
-
-fi
-
-
-# Check whether --enable-debug or --disable-debug was given.
-if test "${enable_debug+set}" = set; then
- enableval="$enable_debug"
- if test "x$enable_debug" != "xyes" ; then
- enable_debug="no"
-fi
-
-else
- enable_debug="no"
-
-fi
-
-if test "x$enable_debug" = "xyes" ; then
- CPPFLAGS="$CPPFLAGS -DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG"
- CPPFLAGS="$CPPFLAGS -DDEBUG_REFRESH -DDEBUG_PASTE"
-else
- CFLAGS="$CFLAGS -O"
-fi
-
-
-
-ACSRCS="common.c emacs.c vi.c"
-BCSRCS="chared.c el.c hist.c key.c map.c parse.c prompt.c read.c refresh.c search.c sig.c term.c tty.c"
-CCSRCS="$CCSRCS history.c tokenizer.c"
-
-AGCSRCS="fcns.c help.c"
-BGCSRCS="editline.c"
-
-HDRS="chared.h el.h hist.h key.h map.h parse.h prompt.h refresh.h search.h sig.h sys.h term.h tokenizer.h tty.h"
-
-IHDRS="histedit.h"
-
-IHDR_LINKS=
-
-AGHDRS="common.h emacs.h vi.h"
-BGHDRS="fcns.h help.h"
-
-HDR_DIRS="include"
-
-MAN3="editline.3"
-MAN5="editrc.5"
-
-MAN3_LINKS=
-for i in el_init.3 el_end.3 el_reset.3 el_gets.3 el_getc.3 el_push.3 \
- el_parse.3 el_set.3 el_get.3 el_source.3 el_resize.3 el_line.3 \
- el_insertstr.3 el_deletestr.3 history_init.3 history_end.3 \
- history.3 ; do
- MAN3_LINKS="$MAN3_LINKS editline.3 $i"
-done
-
-MAN_DIRS="man/man3 man/man5"
-
-LIB_DIRS="lib"
-LIB_MAJOR="2"
-LIB_MINOR="6"
-LIB_A="libedit.a"
-LIB_A_LINKS=
-
-if test "x$ABI" = "xelf" ; then
- LIB_S="libedit.so.$LIB_MAJOR"
- LIB_S_LINK="libedit.so"
- LIB_S_LINKS="$LIB_S $LIB_S_LINK"
- S_LDFLAGS="-shared"
-elif test "x$ABI" = "xaout" ; then
- LIB_S="libedit.so.$LIB_MAJOR.$LIB_MINOR"
- LIB_S_LINKS=
- S_LDFLAGS="-shared"
-elif test "x$ABI" = "xmacho" ; then
- S_LDFLAGS="-shared"
- LIB_S="libedit.$LIB_MAJOR.dylib"
- LIB_S_LINK="libedit.dylib"
- LIB_S_LINKS="$LIB_S $LIB_S_LINK"
- if test "x$prefix" = "xNONE" ; then
- S_LDFLAGS="-undefined suppress -flat_namespace -dynamiclib -compatibility_version $LIB_MAJOR -current_version $LIB_MAJOR -install_name /usr/local/lib/$LIB_S"
- else
- S_LDFLAGS="-undefined suppress -flat_namespace -dynamiclib -compatibility_version $LIB_MAJOR -current_version $LIB_MAJOR -install_name $prefix/lib/$LIB_S"
- fi
-fi
-
-TEST="TEST/test"
-TCSRCS="TEST/test.c"
-
-if test "x$enable_readline" = "xyes" ; then
- CCSRCS="$CCSRCS readline.c"
- IHDRS="$IHDRS readline/readline.h"
- IHDR_LINKS="readline.h readline/history.h"
- HDR_DIRS="$HDR_DIRS include/readline"
- LIB_A_LINKS="$LIB_A_LINKS libedit.a libreadline.a"
- if test "x$ABI" = "xelf" ; then
- LIB_S_LINKS="$LIB_S_LINKS $LIB_S_LINK libreadline.so"
- elif test "x$ABI" = "xaout" ; then
- LIB_S_LINKS="$LIB_S_LINKS $LIB_S libreadline.so.$LIB_MAJOR.$LIB_MINOR"
- elif test "x$ABI" = "xmacho" ; then
- LIB_S_LINKS="$LIB_S_LINKS $LIB_S_LINK libreadline.dylib"
- fi
-fi
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-trap '' 1 2 15
-cat > confcache <<\EOF
-# This file is a shell script that caches the results of configure
-# tests run on this system so they can be shared between configure
-# scripts and configure runs. It is not useful on other systems.
-# If it contains results you don't want to keep, you may remove or edit it.
-#
-# By default, configure uses ./config.cache as the cache file,
-# creating it if it does not exist already. You can give configure
-# the --cache-file=FILE option to use a different cache file; that is
-# what configure does when it calls configure scripts in
-# subdirectories, so they share the cache.
-# Giving --cache-file=/dev/null disables caching, for debugging configure.
-# config.status only pays attention to the cache file if you give it the
-# --recheck option to rerun configure.
-#
-EOF
-# The following way of writing the cache mishandles newlines in values,
-# but we know of no workaround that is simple, portable, and efficient.
-# So, don't put newlines in cache variables' values.
-# Ultrix sh set writes to stderr and can't be redirected directly,
-# and sets the high bit in the cache file unless we assign to the vars.
-(set) 2>&1 |
- case `(ac_space=' '; set | grep ac_space) 2>&1` in
- *ac_space=\ *)
- # `set' does not quote correctly, so add quotes (double-quote substitution
- # turns \\\\ into \\, and sed turns \\ into \).
- sed -n \
- -e "s/'/'\\\\''/g" \
- -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p"
- ;;
- *)
- # `set' quotes correctly as required by POSIX, so do not add quotes.
- sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p'
- ;;
- esac >> confcache
-if cmp -s $cache_file confcache; then
- :
-else
- if test -w $cache_file; then
- echo "updating cache $cache_file"
- cat confcache > $cache_file
- else
- echo "not updating unwritable cache $cache_file"
- fi
-fi
-rm -f confcache
-
-trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
-
-test "x$prefix" = xNONE && prefix=$ac_default_prefix
-# Let make expand exec_prefix.
-test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-
-# Any assignment to VPATH causes Sun make to only execute
-# the first set of double-colon rules, so remove it if not needed.
-# If there is a colon in the path, we need to keep it.
-if test "x$srcdir" = x.; then
- ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d'
-fi
-
-trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15
-
-DEFS=-DHAVE_CONFIG_H
-
-# Without the "./", some shells look in PATH for config.status.
-: ${CONFIG_STATUS=./config.status}
-
-echo creating $CONFIG_STATUS
-rm -f $CONFIG_STATUS
-cat > $CONFIG_STATUS <<EOF
-#! /bin/sh
-# Generated automatically by configure.
-# Run this file to recreate the current configuration.
-# This directory was configured as follows,
-# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
-#
-# $0 $ac_configure_args
-#
-# Compiler output produced by configure, useful for debugging
-# configure, is in ./config.log if it exists.
-
-ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]"
-for ac_option
-do
- case "\$ac_option" in
- -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
- echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
- exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
- -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
- echo "$CONFIG_STATUS generated by autoconf version 2.13"
- exit 0 ;;
- -help | --help | --hel | --he | --h)
- echo "\$ac_cs_usage"; exit 0 ;;
- *) echo "\$ac_cs_usage"; exit 1 ;;
- esac
-done
-
-ac_given_srcdir=$srcdir
-ac_given_INSTALL="$INSTALL"
-
-trap 'rm -fr `echo "Makefile config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
-EOF
-cat >> $CONFIG_STATUS <<EOF
-
-# Protect against being on the right side of a sed subst in config.status.
-sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g;
- s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF
-$ac_vpsub
-$extrasub
-s%@SHELL@%$SHELL%g
-s%@CFLAGS@%$CFLAGS%g
-s%@CPPFLAGS@%$CPPFLAGS%g
-s%@CXXFLAGS@%$CXXFLAGS%g
-s%@FFLAGS@%$FFLAGS%g
-s%@DEFS@%$DEFS%g
-s%@LDFLAGS@%$LDFLAGS%g
-s%@LIBS@%$LIBS%g
-s%@exec_prefix@%$exec_prefix%g
-s%@prefix@%$prefix%g
-s%@program_transform_name@%$program_transform_name%g
-s%@bindir@%$bindir%g
-s%@sbindir@%$sbindir%g
-s%@libexecdir@%$libexecdir%g
-s%@datadir@%$datadir%g
-s%@sysconfdir@%$sysconfdir%g
-s%@sharedstatedir@%$sharedstatedir%g
-s%@localstatedir@%$localstatedir%g
-s%@libdir@%$libdir%g
-s%@includedir@%$includedir%g
-s%@oldincludedir@%$oldincludedir%g
-s%@infodir@%$infodir%g
-s%@mandir@%$mandir%g
-s%@CC@%$CC%g
-s%@A_CFLAGS@%$A_CFLAGS%g
-s%@S_CFLAGS@%$S_CFLAGS%g
-s%@CPP@%$CPP%g
-s%@host@%$host%g
-s%@host_alias@%$host_alias%g
-s%@host_cpu@%$host_cpu%g
-s%@host_vendor@%$host_vendor%g
-s%@host_os@%$host_os%g
-s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
-s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g
-s%@INSTALL_DATA@%$INSTALL_DATA%g
-s%@RANLIB@%$RANLIB%g
-s%@AR@%$AR%g
-s%@ACSRCS@%$ACSRCS%g
-s%@BCSRCS@%$BCSRCS%g
-s%@CCSRCS@%$CCSRCS%g
-s%@AGCSRCS@%$AGCSRCS%g
-s%@BGCSRCS@%$BGCSRCS%g
-s%@HDRS@%$HDRS%g
-s%@IHDRS@%$IHDRS%g
-s%@IHDR_LINKS@%$IHDR_LINKS%g
-s%@AGHDRS@%$AGHDRS%g
-s%@BGHDRS@%$BGHDRS%g
-s%@HDR_DIRS@%$HDR_DIRS%g
-s%@MAN3@%$MAN3%g
-s%@MAN5@%$MAN5%g
-s%@MAN3_LINKS@%$MAN3_LINKS%g
-s%@MAN_DIRS@%$MAN_DIRS%g
-s%@LIB_DIRS@%$LIB_DIRS%g
-s%@LIB_VER@%$LIB_VER%g
-s%@LIB_A@%$LIB_A%g
-s%@LIB_A_LINKS@%$LIB_A_LINKS%g
-s%@LIB_S@%$LIB_S%g
-s%@LIB_S_LINKS@%$LIB_S_LINKS%g
-s%@S_LDFLAGS@%$S_LDFLAGS%g
-s%@TEST@%$TEST%g
-s%@TCSRCS@%$TCSRCS%g
-
-CEOF
-EOF
-
-cat >> $CONFIG_STATUS <<\EOF
-
-# Split the substitutions into bite-sized pieces for seds with
-# small command number limits, like on Digital OSF/1 and HP-UX.
-ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script.
-ac_file=1 # Number of current file.
-ac_beg=1 # First line for current file.
-ac_end=$ac_max_sed_cmds # Line after last line for current file.
-ac_more_lines=:
-ac_sed_cmds=""
-while $ac_more_lines; do
- if test $ac_beg -gt 1; then
- sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file
- else
- sed "${ac_end}q" conftest.subs > conftest.s$ac_file
- fi
- if test ! -s conftest.s$ac_file; then
- ac_more_lines=false
- rm -f conftest.s$ac_file
- else
- if test -z "$ac_sed_cmds"; then
- ac_sed_cmds="sed -f conftest.s$ac_file"
- else
- ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file"
- fi
- ac_file=`expr $ac_file + 1`
- ac_beg=$ac_end
- ac_end=`expr $ac_end + $ac_max_sed_cmds`
- fi
-done
-if test -z "$ac_sed_cmds"; then
- ac_sed_cmds=cat
-fi
-EOF
-
-cat >> $CONFIG_STATUS <<EOF
-
-CONFIG_FILES=\${CONFIG_FILES-"Makefile"}
-EOF
-cat >> $CONFIG_STATUS <<\EOF
-for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
- # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
- case "$ac_file" in
- *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
- ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
- *) ac_file_in="${ac_file}.in" ;;
- esac
-
- # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
-
- # Remove last slash and all that follows it. Not all systems have dirname.
- ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
- if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
- # The file is in a subdirectory.
- test ! -d "$ac_dir" && mkdir "$ac_dir"
- ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`"
- # A "../" for each directory in $ac_dir_suffix.
- ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'`
- else
- ac_dir_suffix= ac_dots=
- fi
-
- case "$ac_given_srcdir" in
- .) srcdir=.
- if test -z "$ac_dots"; then top_srcdir=.
- else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;;
- /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
- *) # Relative path.
- srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
- top_srcdir="$ac_dots$ac_given_srcdir" ;;
- esac
-
- case "$ac_given_INSTALL" in
- [/$]*) INSTALL="$ac_given_INSTALL" ;;
- *) INSTALL="$ac_dots$ac_given_INSTALL" ;;
- esac
-
- echo creating "$ac_file"
- rm -f "$ac_file"
- configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure."
- case "$ac_file" in
- *Makefile*) ac_comsub="1i\\
-# $configure_input" ;;
- *) ac_comsub= ;;
- esac
-
- ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
- sed -e "$ac_comsub
-s%@configure_input@%$configure_input%g
-s%@srcdir@%$srcdir%g
-s%@top_srcdir@%$top_srcdir%g
-s%@INSTALL@%$INSTALL%g
-" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file
-fi; done
-rm -f conftest.s*
-
-# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
-# NAME is the cpp macro being defined and VALUE is the value it is being given.
-#
-# ac_d sets the value in "#define NAME VALUE" lines.
-ac_dA='s%^\([ ]*\)#\([ ]*define[ ][ ]*\)'
-ac_dB='\([ ][ ]*\)[^ ]*%\1#\2'
-ac_dC='\3'
-ac_dD='%g'
-# ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
-ac_uA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
-ac_uB='\([ ]\)%\1#\2define\3'
-ac_uC=' '
-ac_uD='\4%g'
-# ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
-ac_eA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
-ac_eB='$%\1#\2define\3'
-ac_eC=' '
-ac_eD='%g'
-
-if test "${CONFIG_HEADERS+set}" != set; then
-EOF
-cat >> $CONFIG_STATUS <<EOF
- CONFIG_HEADERS="config.h"
-EOF
-cat >> $CONFIG_STATUS <<\EOF
-fi
-for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then
- # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
- case "$ac_file" in
- *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
- ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
- *) ac_file_in="${ac_file}.in" ;;
- esac
-
- echo creating $ac_file
-
- rm -f conftest.frag conftest.in conftest.out
- ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
- cat $ac_file_inputs > conftest.in
-
-EOF
-
-# Transform confdefs.h into a sed script conftest.vals that substitutes
-# the proper values into config.h.in to produce config.h. And first:
-# Protect against being on the right side of a sed subst in config.status.
-# Protect against being in an unquoted here document in config.status.
-rm -f conftest.vals
-cat > conftest.hdr <<\EOF
-s/[\\&%]/\\&/g
-s%[\\$`]%\\&%g
-s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp
-s%ac_d%ac_u%gp
-s%ac_u%ac_e%gp
-EOF
-sed -n -f conftest.hdr confdefs.h > conftest.vals
-rm -f conftest.hdr
-
-# This sed command replaces #undef with comments. This is necessary, for
-# example, in the case of _POSIX_SOURCE, which is predefined and required
-# on some systems where configure will not decide to define it.
-cat >> conftest.vals <<\EOF
-s%^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */%
-EOF
-
-# Break up conftest.vals because some shells have a limit on
-# the size of here documents, and old seds have small limits too.
-
-rm -f conftest.tail
-while :
-do
- ac_lines=`grep -c . conftest.vals`
- # grep -c gives empty output for an empty file on some AIX systems.
- if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi
- # Write a limited-size here document to conftest.frag.
- echo ' cat > conftest.frag <<CEOF' >> $CONFIG_STATUS
- sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS
- echo 'CEOF
- sed -f conftest.frag conftest.in > conftest.out
- rm -f conftest.in
- mv conftest.out conftest.in
-' >> $CONFIG_STATUS
- sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail
- rm -f conftest.vals
- mv conftest.tail conftest.vals
-done
-rm -f conftest.vals
-
-cat >> $CONFIG_STATUS <<\EOF
- rm -f conftest.frag conftest.h
- echo "/* $ac_file. Generated automatically by configure. */" > conftest.h
- cat conftest.in >> conftest.h
- rm -f conftest.in
- if cmp -s $ac_file conftest.h 2>/dev/null; then
- echo "$ac_file is unchanged"
- rm -f conftest.h
- else
- # Remove last slash and all that follows it. Not all systems have dirname.
- ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
- if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
- # The file is in a subdirectory.
- test ! -d "$ac_dir" && mkdir "$ac_dir"
- fi
- rm -f $ac_file
- mv conftest.h $ac_file
- fi
-fi; done
-
-EOF
-cat >> $CONFIG_STATUS <<EOF
-
-EOF
-cat >> $CONFIG_STATUS <<\EOF
-
-exit 0
-EOF
-chmod +x $CONFIG_STATUS
-rm -fr confdefs* $ac_clean_files
-test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1
-
diff --git a/1.2-netsec/editline/configure.in b/1.2-netsec/editline/configure.in
deleted file mode 100644
index 2e37d6b2a..000000000
--- a/1.2-netsec/editline/configure.in
+++ /dev/null
@@ -1,276 +0,0 @@
-dnl
-dnl Process this file with autoconf to produce a configure script.
-dnl
-AC_INIT(Makefile.in)
-
-dnl If CFLAGS isn't defined and using gcc, set CFLAGS to something reasonable.
-dnl Otherwise, just prevent autoconf from molesting CFLAGS.
-CFLAGS=$CFLAGS
-AC_PROG_CC
-if test "x$CFLAGS" = "x" ; then
- no_CFLAGS="yes"
-fi
-if test "x$no_CFLAGS" = "xyes" -a "x$GCC" = "xyes" ; then
- CFLAGS="-Wall -pipe -g3"
-fi
-A_CFLAGS=""
-AC_SUBST(A_CFLAGS)
-S_CFLAGS="-fPIC -DPIC"
-AC_SUBST(S_CFLAGS)
-AC_PROG_CPP
-
-dnl Platform-specific settings. The ABI can probably be determined
-dnl programmatically, but doing so is error-prone, which makes it generally
-dnl not worth the trouble.
-AC_CANONICAL_HOST
-case "${host}" in
- *-*-darwin*)
- CFLAGS="$CFLAGS -fno-common -no-cpp-precomp"
- ABI="macho"
- ;;
- *-*-freebsd*)
- ABI="elf"
- ;;
- *-*-linux* | *cygwin*)
- if echo ${host} | grep -q cygwin ; then \
- echo "cygwin detected"; \
- S_CFLAGS=""; \
- echo "/* cygdef.h. Generated automatically by configure. */
-#ifndef _CYGDEF_H_
-#define _CYGDEF_H_ 1
-#include <sys/ioctl.h>
-#define __linux__ 1
-
-
-typedef void (*sig_t)(int);
-
-
-#endif /* _CYGDEF_H_ */" > cygdef.h; \
- echo "
- #define CYGWIN 1
-" > confdefs.h; \
- fi
- ABI="elf"
- ;;
- *-*-netbsd*)
- AC_MSG_CHECKING(ABI)
- AC_EGREP_CPP(yes,
-[#ifdef __ELF__
- yes
-#endif
-],
- ABI="elf",
- ABI="aout")
- AC_MSG_RESULT($ABI)
- ;;
- *-*-solaris2*)
- ABI="elf"
- AC_DEFINE(SUNOS)
- ;;
- *)
- AC_MSG_RESULT(Unsupported operating system: ${host})
- ABI="elf"
- ;;
-esac
-
-AC_PROG_INSTALL
-AC_PROG_RANLIB
-AC_PATH_PROG(AR, ar, , $PATH)
-
-dnl Search for termcap access routines in termcap, tinfo, curses, and ncurses.
-AC_CHECK_LIB(termcap, tgetent, , \
- AC_CHECK_LIB(tinfo, tgetent, , \
- AC_CHECK_LIB(curses, tgetent, , \
- AC_CHECK_LIB(ncurses, tgetent, , \
- AC_MSG_ERROR(termcap support not found)))))
-
-dnl Use termcap.h if it exists; otherwise we need both term.h and [n]curses.h.
-AC_CHECK_HEADERS(termcap.h, , \
- AC_CHECK_HEADERS(term.h, , \
- AC_MSG_RESULT(Need term.h since termcap.h is missing))
- AC_CHECK_HEADERS(curses.h, , \
- AC_CHECK_HEADERS(ncurses.h, , \
- AC_MSG_RESULT(Need curses.h or ncurses.h))))
-
-AC_CHECK_HEADERS(sys/cdefs.h vis.h)
-
-AC_CHECK_FUNCS(issetugid)
-AC_CHECK_FUNCS(strlcat, , CCSRCS="$CCSRCS np/strlcat.c")
-AC_CHECK_FUNCS(strlcpy, , CCSRCS="$CCSRCS np/strlcpy.c")
-AC_CHECK_FUNCS(fgetln, , CCSRCS="$CCSRCS np/fgetln.c")
-AC_CHECK_FUNCS(strvis, , CCSRCS="$CCSRCS np/vis.c")
-AC_CHECK_FUNCS(strunvis, , CCSRCS="$CCSRCS np/unvis.c")
-
-AC_EGREP_CPP(yes,
-[#include <sys/cdefs.h>
-#ifdef __RCSID
- yes
-#endif
-], , [CPPFLAGS="$CPPFLAGS '-D__RCSID(x)='"])
-
-AC_EGREP_CPP(yes,
-[#include <sys/cdefs.h>
-#ifdef __COPYRIGHT
- yes
-#endif
-], , [CPPFLAGS="$CPPFLAGS '-D__COPYRIGHT(x)='"])
-
-AC_EGREP_CPP(yes,
-[#include <sys/cdefs.h>
-#ifdef __RENAME
- yes
-#endif
-], , [CPPFLAGS="$CPPFLAGS '-D__RENAME(x)='"])
-
-AC_EGREP_CPP(yes,
-[#include <sys/cdefs.h>
-#ifdef _DIAGASSERT
- yes
-#endif
-], , [CPPFLAGS="$CPPFLAGS '-D_DIAGASSERT(x)='"])
-
-dnl Enable readline compatibility by default.
-AC_ARG_ENABLE(readline, [ --disable-readline Disable readline compatibility],
-if test "x$enable_readline" != "xyes" ; then
- enable_readline="no"
-fi
-,
-enable_readline="yes"
-)
-
-dnl Optionally enable debugging.
-AC_ARG_ENABLE(debug, [ --enable-debug Enable debugging code],
-if test "x$enable_debug" != "xyes" ; then
- enable_debug="no"
-fi
-,
-enable_debug="no"
-)
-if test "x$enable_debug" = "xyes" ; then
- CPPFLAGS="$CPPFLAGS -DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG"
- CPPFLAGS="$CPPFLAGS -DDEBUG_REFRESH -DDEBUG_PASTE"
-else
- CFLAGS="$CFLAGS -O"
-fi
-
-
-dnl
-dnl File lists. This is done here instead of in the Makefile in order to avoid
-dnl the need for conditionals.
-dnl
-
-dnl .c files.
-ACSRCS="common.c emacs.c vi.c"
-BCSRCS="chared.c el.c hist.c key.c map.c parse.c prompt.c read.c refresh.c search.c sig.c term.c tty.c"
-CCSRCS="$CCSRCS history.c tokenizer.c"
-
-dnl Generated .c files.
-AGCSRCS="fcns.c help.c"
-BGCSRCS="editline.c"
-
-dnl .h files.
-HDRS="chared.h el.h hist.h key.h map.h parse.h prompt.h refresh.h search.h sig.h sys.h term.h tokenizer.h tty.h"
-
-dnl Installed .h files.
-IHDRS="histedit.h"
-
-dnl Installed headers for readline compatibility.
-IHDR_LINKS=
-
-dnl Generated .h files.
-AGHDRS="common.h emacs.h vi.h"
-BGHDRS="fcns.h help.h"
-
-dnl Header installation directories.
-HDR_DIRS="include"
-
-dnl Man pages.
-MAN3="editline.3"
-MAN5="editrc.5"
-
-MAN3_LINKS=
-for i in el_init.3 el_end.3 el_reset.3 el_gets.3 el_getc.3 el_push.3 \
- el_parse.3 el_set.3 el_get.3 el_source.3 el_resize.3 el_line.3 \
- el_insertstr.3 el_deletestr.3 history_init.3 history_end.3 \
- history.3 ; do
- MAN3_LINKS="$MAN3_LINKS editline.3 $i"
-done
-
-dnl Man page installation directories.
-MAN_DIRS="man/man3 man/man5"
-
-dnl Library settings.
-LIB_DIRS="lib"
-LIB_MAJOR="2"
-LIB_MINOR="6"
-LIB_A="libedit.a"
-LIB_A_LINKS=
-
-if test "x$ABI" = "xelf" ; then
- LIB_S="libedit.so.$LIB_MAJOR"
- LIB_S_LINK="libedit.so"
- LIB_S_LINKS="$LIB_S $LIB_S_LINK"
- S_LDFLAGS="-shared"
-elif test "x$ABI" = "xaout" ; then
- LIB_S="libedit.so.$LIB_MAJOR.$LIB_MINOR"
- LIB_S_LINKS=
- S_LDFLAGS="-shared"
-elif test "x$ABI" = "xmacho" ; then
- S_LDFLAGS="-shared"
- LIB_S="libedit.$LIB_MAJOR.dylib"
- LIB_S_LINK="libedit.dylib"
- LIB_S_LINKS="$LIB_S $LIB_S_LINK"
- if test "x$prefix" = "xNONE" ; then
- S_LDFLAGS="-undefined suppress -flat_namespace -dynamiclib -compatibility_version $LIB_MAJOR -current_version $LIB_MAJOR -install_name /usr/local/lib/$LIB_S"
- else
- S_LDFLAGS="-undefined suppress -flat_namespace -dynamiclib -compatibility_version $LIB_MAJOR -current_version $LIB_MAJOR -install_name $prefix/lib/$LIB_S"
- fi
-fi
-
-dnl Test program.
-TEST="TEST/test"
-TCSRCS="TEST/test.c"
-
-dnl Add files to the lists if readline compatibility is enabled.
-if test "x$enable_readline" = "xyes" ; then
- CCSRCS="$CCSRCS readline.c"
- IHDRS="$IHDRS readline/readline.h"
- IHDR_LINKS="readline.h readline/history.h"
- HDR_DIRS="$HDR_DIRS include/readline"
- LIB_A_LINKS="$LIB_A_LINKS libedit.a libreadline.a"
- if test "x$ABI" = "xelf" ; then
- LIB_S_LINKS="$LIB_S_LINKS $LIB_S_LINK libreadline.so"
- elif test "x$ABI" = "xaout" ; then
- LIB_S_LINKS="$LIB_S_LINKS $LIB_S libreadline.so.$LIB_MAJOR.$LIB_MINOR"
- elif test "x$ABI" = "xmacho" ; then
- LIB_S_LINKS="$LIB_S_LINKS $LIB_S_LINK libreadline.dylib"
- fi
-fi
-
-AC_SUBST(ACSRCS)
-AC_SUBST(BCSRCS)
-AC_SUBST(CCSRCS)
-AC_SUBST(AGCSRCS)
-AC_SUBST(BGCSRCS)
-AC_SUBST(HDRS)
-AC_SUBST(IHDRS)
-AC_SUBST(IHDR_LINKS)
-AC_SUBST(AGHDRS)
-AC_SUBST(BGHDRS)
-AC_SUBST(HDR_DIRS)
-AC_SUBST(MAN3)
-AC_SUBST(MAN5)
-AC_SUBST(MAN3_LINKS)
-AC_SUBST(MAN_DIRS)
-AC_SUBST(LIB_DIRS)
-AC_SUBST(LIB_VER)
-AC_SUBST(LIB_A)
-AC_SUBST(LIB_A_LINKS)
-AC_SUBST(LIB_S)
-AC_SUBST(LIB_S_LINKS)
-AC_SUBST(S_LDFLAGS)
-AC_SUBST(TEST)
-AC_SUBST(TCSRCS)
-
-AC_CONFIG_HEADER(config.h)
-AC_OUTPUT(Makefile)
diff --git a/1.2-netsec/editline/editline.3 b/1.2-netsec/editline/editline.3
deleted file mode 100644
index 28f6ddb84..000000000
--- a/1.2-netsec/editline/editline.3
+++ /dev/null
@@ -1,646 +0,0 @@
-.\" $NetBSD: editline.3,v 1.25 2002/01/15 02:46:22 wiz Exp $
-.\"
-.\" Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
-.\" All rights reserved.
-.\"
-.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the NetBSD
-.\" Foundation, Inc. and its contributors.
-.\" 4. Neither the name of The NetBSD Foundation nor the names of its
-.\" contributors may be used to endorse or promote products derived
-.\" from this software without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-.\" POSSIBILITY OF SUCH DAMAGE.
-.\"
-.Dd November 12, 1999
-.Os
-.Dt EDITLINE 3
-.Sh NAME
-.Nm editline ,
-.Nm el_init ,
-.Nm el_end ,
-.Nm el_reset ,
-.Nm el_gets ,
-.Nm el_getc ,
-.Nm el_push ,
-.Nm el_parse ,
-.Nm el_set ,
-.Nm el_source ,
-.Nm el_resize ,
-.Nm el_line ,
-.Nm el_insertstr ,
-.Nm el_deletestr ,
-.Nm history_init ,
-.Nm history_end ,
-.Nm history
-.Nd line editor and history functions
-.Sh LIBRARY
-.Lb libedit
-.Sh SYNOPSIS
-.Fd #include <histedit.h>
-.Ft EditLine *
-.Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
-.Ft void
-.Fn el_end "EditLine *e"
-.Ft void
-.Fn el_reset "EditLine *e"
-.Ft const char *
-.Fn el_gets "EditLine *e" "int *count"
-.Ft int
-.Fn el_getc "EditLine *e" "char *ch"
-.Ft void
-.Fn el_push "EditLine *e" "const char *str"
-.Ft int
-.Fn el_parse "EditLine *e" "int argc" "char *argv[]"
-.Ft int
-.Fn el_set "EditLine *e" "int op" "..."
-.Ft int
-.Fn el_get "EditLine *e" "int op" "void *result"
-.Ft int
-.Fn el_source "EditLine *e" "const char *file"
-.Ft void
-.Fn el_resize "EditLine *e"
-.Ft const LineInfo *
-.Fn el_line "EditLine *e"
-.Ft int
-.Fn el_insertstr "EditLine *e" "const char *str"
-.Ft void
-.Fn el_deletestr "EditLine *e" "int count"
-.Ft History *
-.Fn history_init
-.Ft void
-.Fn history_end "History *h"
-.Ft int
-.Fn history "History *h" "HistEvent *ev" "int op" "..."
-.Sh DESCRIPTION
-The
-.Nm
-library provides generic line editing and history functions,
-similar to those found in
-.Xr sh 1 .
-.Pp
-These functions are available in the
-.Nm libedit
-library (which needs the
-.Nm libtermcap
-library).
-Programs should be linked with
-.Fl ledit ltermcap .
-.Sh LINE EDITING FUNCTIONS
-The line editing functions use a common data structure,
-.Fa EditLine ,
-which is created by
-.Fn el_init
-and freed by
-.Fn el_end .
-.Pp
-The following functions are available:
-.Bl -tag -width 4n
-.It Fn el_init
-Initialise the line editor, and return a data structure
-to be used by all other line editing functions.
-.Fa prog
-is the name of the invoking program, used when reading the
-.Xr editrc 5
-file to determine which settings to use.
-.Fa fin ,
-.Fa fout
-and
-.Fa ferr
-are the input, output, and error streams (respectively) to use.
-In this documentation, references to
-.Dq the tty
-are actually to this input/output stream combination.
-.It Fn el_end
-Clean up and finish with
-.Fa e ,
-assumed to have been created with
-.Fn el_init .
-.It Fn el_reset
-Reset the tty and the parser.
-This should be called after an error which may have upset the tty's
-state.
-.It Fn el_gets
-Read a line from the tty.
-.Fa count
-is modified to contain the number of characters read.
-Returns the line read if successful, or
-.Dv NULL
-if no characters were read or if an error occurred.
-.It Fn el_getc
-Read a character from the tty.
-.Fa ch
-is modified to contain the character read.
-Returns the number of characters read if successful, -1 otherwise.
-.It Fn el_push
-Pushes
-.Fa str
-back onto the input stream.
-This is used by the macro expansion mechanism.
-Refer to the description of
-.Ic bind
-.Fl s
-in
-.Xr editrc 5
-for more information.
-.It Fn el_parse
-Parses the
-.Fa argv
-array (which is
-.Fa argc
-elements in size)
-to execute builtin
-.Nm
-commands.
-If the command is prefixed with
-.Dq prog :
-then
-.Fn el_parse
-will only execute the command if
-.Dq prog
-matches the
-.Fa prog
-argument supplied to
-.Fn el_init .
-The return value is
--1 if the command is unknown,
-0 if there was no error or
-.Dq prog
-didn't match, or
-1 if the command returned an error.
-Refer to
-.Xr editrc 5
-for more information.
-.It Fn el_set
-Set
-.Nm
-parameters.
-.Fa op
-determines which parameter to set, and each operation has its
-own parameter list.
-.Pp
-The following values for
-.Fa op
-are supported, along with the required argument list:
-.Bl -tag -width 4n
-.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
-Define prompt printing function as
-.Fa f ,
-which is to return a string that contains the prompt.
-.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
-Define right side prompt printing function as
-.Fa f ,
-which is to return a string that contains the prompt.
-.It Dv EL_TERMINAL , Fa "const char *type"
-Define terminal type of the tty to be
-.Fa type ,
-or to
-.Ev TERM
-if
-.Fa type
-is
-.Dv NULL .
-.It Dv EL_EDITOR , Fa "const char *mode"
-Set editing mode to
-.Fa mode ,
-which must be one of
-.Dq emacs
-or
-.Dq vi .
-.It Dv EL_SIGNAL , Fa "int flag"
-If
-.Fa flag
-is non-zero,
-.Nm
-will install its own signal handler for the following signals when
-reading command input:
-.Dv SIGCONT ,
-.Dv SIGHUP ,
-.Dv SIGINT ,
-.Dv SIGQUIT ,
-.Dv SIGSTOP ,
-.Dv SIGTERM ,
-.Dv SIGTSTP ,
-and
-.Dv SIGWINCH .
-Otherwise, the current signal handlers will be used.
-.It Dv EL_BIND , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
-Perform the
-.Ic bind
-builtin command.
-Refer to
-.Xr editrc 5
-for more information.
-.It Dv EL_ECHOTC , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
-Perform the
-.Ic echotc
-builtin command.
-Refer to
-.Xr editrc 5
-for more information.
-.It Dv EL_SETTC , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
-Perform the
-.Ic settc
-builtin command.
-Refer to
-.Xr editrc 5
-for more information.
-.It Dv EL_SETTY , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
-Perform the
-.Ic setty
-builtin command.
-Refer to
-.Xr editrc 5
-for more information.
-.It Dv EL_TELLTC , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
-Perform the
-.Ic telltc
-builtin command.
-Refer to
-.Xr editrc 5
-for more information.
-.It Dv EL_ADDFN , Xo
-.Fa "const char *name" ,
-.Fa "const char *help" ,
-.Fa "unsigned char (*func)(EditLine *e, int ch)
-.Xc
-Add a user defined function,
-.Fn func ,
-referred to as
-.Fa name
-which is invoked when a key which is bound to
-.Fa name
-is entered.
-.Fa help
-is a description of
-.Fa name .
-At invocation time,
-.Fa ch
-is the key which caused the invocation.
-The return value of
-.Fn func
-should be one of:
-.Bl -tag -width "CC_REDISPLAY"
-.It Dv CC_NORM
-Add a normal character.
-.It Dv CC_NEWLINE
-End of line was entered.
-.It Dv CC_EOF
-EOF was entered.
-.It Dv CC_ARGHACK
-Expecting further command input as arguments, do nothing visually.
-.It Dv CC_REFRESH
-Refresh display.
-.It Dv CC_REFRESH_BEEP
-Refresh display, and beep.
-.It Dv CC_CURSOR
-Cursor moved, so update and perform
-.Dv CC_REFRESH .
-.It Dv CC_REDISPLAY
-Redisplay entire input line.
-This is useful if a key binding outputs extra information.
-.It Dv CC_ERROR
-An error occurred.
-Beep, and flush tty.
-.It Dv CC_FATAL
-Fatal error, reset tty to known state.
-.El
-.It Dv EL_HIST , Xo
-.Fa "History *(*func)(History *, int op, ...)" ,
-.Fa "const char *ptr"
-.Xc
-Defines which history function to use, which is usually
-.Fn history .
-.Fa ptr
-should be the value returned by
-.Fn history_init .
-.It Dv EL_EDITMODE , Fa "int flag"
-If
-.Fa flag
-is non-zero,
-editing is enabled (the default).
-Note that this is only an indication, and does not
-affect the operation of
-.Nm "" .
-At this time, it is the caller's responsibility to
-check this
-(using
-.Fn el_get )
-to determine if editing should be enabled or not.
-.It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
-Define the character reading function as
-.Fa f ,
-which is to return the number of characters read and store them in
-.Fa c .
-This function is called internally by
-.Fn el_gets
-and
-.Fn el_getc .
-The builtin function can be set or restored with the special function
-name ``EL_BUILTIN_GETCFN''.
-.It Dv EL_CLIENTDATA , Fa "void *data"
-Register
-.Fa data
-to be associated with this EditLine structure. It can be retrieved with
-the corresponding
-.Fn el_get
-call.
-.El
-.It Fn el_get
-Get
-.Nm
-parameters.
-.Fa op
-determines which parameter to retrieve into
-.Fa result .
-.Pp
-The following values for
-.Fa op
-are supported, along with actual type of
-.Fa result :
-.Bl -tag -width 4n
-.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
-Return a pointer to the function that displays the prompt.
-.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
-Return a pointer to the function that displays the rightside prompt.
-.It Dv EL_EDITOR , Fa "const char *"
-Return the name of the editor, which will be one of
-.Dq emacs
-or
-.Dq vi .
-.It Dv EL_SIGNAL , Fa "int *"
-Return non-zero if
-.Nm
-has installed private signal handlers (see
-.Fn el_get
-above).
-.It Dv EL_EDITMODE, Fa "int *"
-Return non-zero if editing is enabled.
-.It Dv EL_GETCFN, Fa "int (**f)(EditLine *, char *)"
-Return a pointer to the function that read characters, which is equal to
-``EL_BUILTIN_GETCFN'' in the case of the default builtin function.
-.It Dv EL_CLIENTDATA , Fa "void **data"
-Retrieve
-.Fa data
-previously registered with the corresponding
-.Fn el_set
-call.
-.El
-.It Fn el_source
-Initialise
-.Nm
-by reading the contents of
-.Fa file .
-.Fn el_parse
-is called for each line in
-.Fa file .
-If
-.Fa file
-is
-.Dv NULL ,
-try
-.Pa $PWD/.editrc
-then
-.Pa $HOME/.editrc .
-Refer to
-.Xr editrc 5
-for details on the format of
-.Fa file .
-.It Fn el_resize
-Must be called if the terminal size changes.
-If
-.Dv EL_SIGNAL
-has been set with
-.Fn el_set ,
-then this is done automatically.
-Otherwise, it's the responsibility of the application to call
-.Fn el_resize
-on the appropriate occasions.
-.It Fn el_line
-Return the editing information for the current line in a
-.Fa LineInfo
-structure, which is defined as follows:
-.Bd -literal
-typedef struct lineinfo {
- const char *buffer; /* address of buffer */
- const char *cursor; /* address of cursor */
- const char *lastchar; /* address of last character */
-} LineInfo;
-.Ed
-.It Fn el_insertstr
-Insert
-.Fa str
-into the line at the cursor.
-Returns -1 if
-.Fa str
-is empty or won't fit, and 0 otherwise.
-.It Fn el_deletestr
-Delete
-.Fa num
-characters before the cursor.
-.El
-.Sh HISTORY LIST FUNCTIONS
-The history functions use a common data structure,
-.Fa History ,
-which is created by
-.Fn history_init
-and freed by
-.Fn history_end .
-.Pp
-The following functions are available:
-.Bl -tag -width 4n
-.It Fn history_init
-Initialise the history list, and return a data structure
-to be used by all other history list functions.
-.It Fn history_end
-Clean up and finish with
-.Fa h ,
-assumed to have been created with
-.Fn history_init .
-.It Fn history
-Perform operation
-.Fa op
-on the history list, with optional arguments as needed by the
-operation.
-.Fa ev
-is changed accordingly to operation.
-The following values for
-.Fa op
-are supported, along with the required argument list:
-.Bl -tag -width 4n
-.It Dv H_SETSIZE , Fa "int size"
-Set size of history to
-.Fa size
-elements.
-.It Dv H_GETSIZE
-Get number of events currently in history.
-.It Dv H_END
-Cleans up and finishes with
-.Fa h ,
-assumed to be created with
-.Fn history_init .
-.It Dv H_CLEAR
-Clear the history.
-.It Dv H_FUNC , Xo
-.Fa "void *ptr" ,
-.Fa "history_gfun_t first" ,
-.Fa "history_gfun_t next" ,
-.Fa "history_gfun_t last" ,
-.Fa "history_gfun_t prev" ,
-.Fa "history_gfun_t curr" ,
-.Fa "history_sfun_t set" ,
-.Fa "history_vfun_t clear" ,
-.Fa "history_efun_t enter" ,
-.Fa "history_efun_t add"
-.Xc
-Define functions to perform various history operations.
-.Fa ptr
-is the argument given to a function when it's invoked.
-.It Dv H_FIRST
-Return the first element in the history.
-.It Dv H_LAST
-Return the last element in the history.
-.It Dv H_PREV
-Return the previous element in the history.
-.It Dv H_NEXT
-Return the next element in the history.
-.It Dv H_CURR
-Return the current element in the history.
-.It Dv H_SET
-Set the cursor to point to the requested element.
-.It Dv H_ADD , Fa "const char *str"
-Append
-.Fa str
-to the current element of the history, or create an element with
-.It Dv H_APPEND , Fa "const char *str"
-Append
-.Fa str
-to the last new element of the history.
-.It Dv H_ENTER , Fa "const char *str"
-Add
-.Fa str
-as a new element to the history, and, if necessary,
-removing the oldest entry to keep the list to the created size.
-.It Dv H_PREV_STR , Fa "const char *str"
-Return the closest previous event that starts with
-.Fa str .
-.It Dv H_NEXT_STR , Fa "const char *str"
-Return the closest next event that starts with
-.Fa str .
-.It Dv H_PREV_EVENT , Fa "int e"
-Return the previous event numbered
-.Fa e .
-.It Dv H_NEXT_EVENT , Fa "int e"
-Return the next event numbered
-.Fa e .
-.It Dv H_LOAD , Fa "const char *file"
-Load the history list stored in
-.Fa file .
-.It Dv H_SAVE , Fa "const char *file"
-Save the history list to
-.Fa file .
-.El
-.Pp
-.Fn history
-returns 0 if the operation
-.Fa op
-succeeds. Otherwise, -1 is returned and
-.Fa ev
-is updated to contain more details about the error.
-.El
-.\"XXX.Sh EXAMPLES
-.\"XXX: provide some examples
-.Sh SEE ALSO
-.Xr sh 1 ,
-.Xr signal 3 ,
-.Xr termcap 3 ,
-.Xr editrc 5
-.Sh HISTORY
-The
-.Nm
-library first appeared in
-.Bx 4.4 .
-.Dv CC_REDISPLAY
-appeared in
-.Nx 1.3 .
-.Dv CC_REFRESH_BEEP ,
-.Dv EL_EDITMODE
-and the readline emulation appeared in
-.Nx 1.4 .
-.Dv EL_RPROMPT
-appeared in
-.Nx 1.5 .
-.Sh AUTHORS
-The
-.Nm
-library was written by Christos Zoulas.
-Luke Mewburn wrote this manual and implemented
-.Dv CC_REDISPLAY ,
-.Dv CC_REFRESH_BEEP ,
-.Dv EL_EDITMODE ,
-and
-.Dv EL_RPROMPT .
-Jaromir Dolecek implemented the readline emulation.
-.Sh BUGS
-The tokenization functions are not publicly defined in
-.Fd <histedit.h> .
-.Pp
-At this time, it is the responsibility of the caller to
-check the result of the
-.Dv EL_EDITMODE
-operation of
-.Fn el_get
-(after an
-.Fn el_source
-or
-.Fn el_parse )
-to determine if
-.Nm
-should be used for further input.
-I.e.,
-.Dv EL_EDITMODE
-is purely an indication of the result of the most recent
-.Xr editrc 5
-.Ic edit
-command.
diff --git a/1.2-netsec/editline/editrc.5 b/1.2-netsec/editline/editrc.5
deleted file mode 100644
index ddd12897b..000000000
--- a/1.2-netsec/editline/editrc.5
+++ /dev/null
@@ -1,491 +0,0 @@
-.\" $NetBSD: editrc.5,v 1.12 2002/01/15 02:46:44 wiz Exp $
-.\"
-.\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
-.\" All rights reserved.
-.\"
-.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the NetBSD
-.\" Foundation, Inc. and its contributors.
-.\" 4. Neither the name of The NetBSD Foundation nor the names of its
-.\" contributors may be used to endorse or promote products derived
-.\" from this software without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-.\" POSSIBILITY OF SUCH DAMAGE.
-.\"
-.Dd November 8, 2000
-.Os
-.Dt EDITRC 5
-.Sh NAME
-.Nm editrc
-.Nd configuration file for editline library
-.Sh SYNOPSIS
-.Nm
-.Sh DESCRIPTION
-The
-.Nm
-file defines various settings to be used by the
-.Xr editline 3
-library.
-.Pp
-The format of each line is:
-.Dl [prog:]command [arg [...]]
-.Pp
-.Ar command
-is one of the
-.Xr editline 3
-builtin commands.
-Refer to
-.Sx BUILTIN COMMANDS
-for more information.
-.Pp
-.Ar prog
-is the program name string that a program defines when it calls
-.Xr el_init 3
-to setup
-.Xr editline 3 ,
-which is usually
-.Va argv[0] .
-.Ar command
-will be executed for any program which matches
-.Ar prog .
-.Pp
-.Ar prog
-may also be a
-.Xr regex 3
-style
-regular expression, in which case
-.Ar command
-will be executed for any program that matches the regular expression.
-.Pp
-If
-.Ar prog
-is absent,
-.Ar command
-is executed for all programs.
-.Sh BUILTIN COMMANDS
-The
-.Nm editline
-library has some builtin commands, which affect the way
-that the line editing and history functions operate.
-These are based on similar named builtins present in the
-.Xr tcsh 1
-shell.
-.Pp
-The following builtin commands are available:
-.Bl -tag -width 4n
-.It Ic bind Xo
-.Op Fl a
-.Op Fl e
-.Op Fl k
-.Op Fl l
-.Op Fl r
-.Op Fl s
-.Op Fl v
-.Op Ar key Op Ar command
-.Xc
-Without options, list all bound keys, and the editor command to which
-each is bound.
-If
-.Ar key
-is supplied, show the bindings for
-.Ar key .
-If
-.Ar key command
-is supplied, bind
-.Ar command
-to
-.Ar key .
-Options include:
-.Bl -tag -width 4n
-.It Fl e
-Bind all keys to the standard GNU Emacs-like bindings.
-.It Fl v
-Bind all keys to the standard
-.Xr vi 1 -like
-bindings.
-.It Fl a
-List or change key bindings in the
-.Xr vi 1
-mode alternate (command mode) key map.
-.It Fl k
-.Ar key
-is interpreted as a symbolic arrow key name, which may be one of
-.Sq up ,
-.Sq down ,
-.Sq left
-or
-.Sq right .
-.It Fl l
-List all editor commands and a short description of each.
-.It Fl r
-Remove a key's binding.
-.It Fl s
-.Ar command
-is taken as a literal string and treated as terminal input when
-.Ar key
-is typed.
-Bound keys in
-.Ar command
-are themselves reinterpreted, and this continues for ten levels of
-interpretation.
-.El
-.Pp
-.Ar command
-may be one of the commands documented in
-.Sx "EDITOR COMMANDS"
-below, or another key.
-.Pp
-.Ar key
-and
-.Ar command
-can contain control characters of the form
-.Sm off
-.Sq No ^ Ar character
-.Sm on
-.Po
-e.g.
-.Sq ^A
-.Pc ,
-and the following backslashed escape sequences:
-.Pp
-.Bl -tag -compact -offset indent -width 4n
-.It Ic \ea
-Bell
-.It Ic \eb
-Backspace
-.It Ic \ee
-Escape
-.It Ic \ef
-Formfeed
-.It Ic \en
-Newline
-.It Ic \er
-Carriage return
-.It Ic \et
-Horizontal tab
-.It Ic \ev
-Vertical tab
-.Sm off
-.It Sy \e Ar nnn
-.Sm on
-The ASCII character corresponding to the octal number
-.Ar nnn .
-.El
-.Pp
-.Sq \e
-nullifies the special meaning of the following character,
-if it has any, notably
-.Sq \e
-and
-.Sq ^ .
-.It Ic echotc Xo
-.Op Fl sv
-.Ar arg
-.Ar ...
-.Xc
-Exercise terminal capabilities given in
-.Ar arg Ar ... .
-If
-.Ar arg
-is
-.Sq baud ,
-.Sq cols ,
-.Sq lines ,
-.Sq rows ,
-.Sq meta or
-.Sq tabs ,
-the value of that capability is printed, with
-.Dq yes
-or
-.Dq no
-indicating that the terminal does or does not have that capability.
-.Pp
-.Fl s
-returns an emptry string for non-existent capabilities, rather than
-causing an error.
-.Fl v
-causes messages to be verbose.
-.It Ic edit Op Li on | Li off
-Enable or disable the
-.Nm editline
-functionality in a program.
-.It Ic history
-List the history.
-.It Ic telltc
-List the values of all the terminal capabilities (see
-.Xr termcap 5 ) .
-.It Ic settc Ar cap Ar val
-Set the terminal capability
-.Ar cap
-to
-.Ar val ,
-as defined in
-.Xr termcap 5 .
-No sanity checking is done.
-.It Ic setty Xo
-.Op Fl a
-.Op Fl d
-.Op Fl q
-.Op Fl x
-.Op Ar +mode
-.Op Ar -mode
-.Op Ar mode
-.Xc
-Control which tty modes that
-.Nm
-won't allow the user to change.
-.Fl d ,
-.Fl q
-or
-.Fl x
-tells
-.Ic setty
-to act on the
-.Sq edit ,
-.Sq quote
-or
-.Sq execute
-set of tty modes respectively; defaulting to
-.Fl x .
-.Pp
-Without other arguments,
-.Ic setty
-lists the modes in the chosen set which are fixed on
-.Po
-.Sq +mode
-.Pc
-or off
-.Po
-.Sq -mode
-.Pc .
-.Fl a
-lists all tty modes in the chosen set regardless of the setting.
-With
-.Ar +mode ,
-.Ar -mode
-or
-.Ar mode ,
-fixes
-.Ar mode
-on or off or removes control of
-.Ar mode
-in the chosen set.
-.El
-.Sh EDITOR COMMANDS
-The following editor commands are available for use in key bindings:
-.\" Section automatically generated with makelist
-.Bl -tag -width 4n
-.It Ic vi-paste-next
-Vi paste previous deletion to the right of the cursor.
-.It Ic vi-paste-prev
-Vi paste previous deletion to the left of the cursor.
-.It Ic vi-prev-space-word
-Vi move to the previous space delimited word.
-.It Ic vi-prev-word
-Vi move to the previous word.
-.It Ic vi-next-space-word
-Vi move to the next space delimited word.
-.It Ic vi-next-word
-Vi move to the next word.
-.It Ic vi-change-case
-Vi change case of character under the cursor and advance one character.
-.It Ic vi-change-meta
-Vi change prefix command.
-.It Ic vi-insert-at-bol
-Vi enter insert mode at the beginning of line.
-.It Ic vi-replace-char
-Vi replace character under the cursor with the next character typed.
-.It Ic vi-replace-mode
-Vi enter replace mode.
-.It Ic vi-substitute-char
-Vi replace character under the cursor and enter insert mode.
-.It Ic vi-substitute-line
-Vi substitute entire line.
-.It Ic vi-change-to-eol
-Vi change to end of line.
-.It Ic vi-insert
-Vi enter insert mode.
-.It Ic vi-add
-Vi enter insert mode after the cursor.
-.It Ic vi-add-at-eol
-Vi enter insert mode at end of line.
-.It Ic vi-delete-meta
-Vi delete prefix command.
-.It Ic vi-end-word
-Vi move to the end of the current space delimited word.
-.It Ic vi-to-end-word
-Vi move to the end of the current word.
-.It Ic vi-undo
-Vi undo last change.
-.It Ic vi-command-mode
-Vi enter command mode (use alternative key bindings).
-.It Ic vi-zero
-Vi move to the beginning of line.
-.It Ic vi-delete-prev-char
-Vi move to previous character (backspace).
-.It Ic vi-list-or-eof
-Vi list choices for completion or indicate end of file if empty line.
-.It Ic vi-kill-line-prev
-Vi cut from beginning of line to cursor.
-.It Ic vi-search-prev
-Vi search history previous.
-.It Ic vi-search-next
-Vi search history next.
-.It Ic vi-repeat-search-next
-Vi repeat current search in the same search direction.
-.It Ic vi-repeat-search-prev
-Vi repeat current search in the opposite search direction.
-.It Ic vi-next-char
-Vi move to the character specified next.
-.It Ic vi-prev-char
-Vi move to the character specified previous.
-.It Ic vi-to-next-char
-Vi move up to the character specified next.
-.It Ic vi-to-prev-char
-Vi move up to the character specified previous.
-.It Ic vi-repeat-next-char
-Vi repeat current character search in the same search direction.
-.It Ic vi-repeat-prev-char
-Vi repeat current character search in the opposite search direction.
-.It Ic em-delete-or-list
-Delete character under cursor or list completions if at end of line.
-.It Ic em-delete-next-word
-Cut from cursor to end of current word.
-.It Ic em-yank
-Paste cut buffer at cursor position.
-.It Ic em-kill-line
-Cut the entire line and save in cut buffer.
-.It Ic em-kill-region
-Cut area between mark and cursor and save in cut buffer.
-.It Ic em-copy-region
-Copy area between mark and cursor to cut buffer.
-.It Ic em-gosmacs-traspose
-Exchange the two characters before the cursor.
-.It Ic em-next-word
-Move next to end of current word.
-.It Ic em-upper-case
-Uppercase the characters from cursor to end of current word.
-.It Ic em-capitol-case
-Capitalize the characters from cursor to end of current word.
-.It Ic em-lower-case
-Lowercase the characters from cursor to end of current word.
-.It Ic em-set-mark
-Set the mark at cursor.
-.It Ic em-exchange-mark
-Exchange the cursor and mark.
-.It Ic em-universal-argument
-Universal argument (argument times 4).
-.It Ic em-meta-next
-Add 8th bit to next character typed.
-.It Ic em-toggle-overwrite
-Switch from insert to overwrite mode or vice versa.
-.It Ic em-copy-prev-word
-Copy current word to cursor.
-.It Ic em-inc-search-next
-Emacs incremental next search.
-.It Ic em-inc-search-prev
-Emacs incremental reverse search.
-.It Ic ed-end-of-file
-Indicate end of file.
-.It Ic ed-insert
-Add character to the line.
-.It Ic ed-delete-prev-word
-Delete from beginning of current word to cursor.
-.It Ic ed-delete-next-char
-Delete character under cursor.
-.It Ic ed-kill-line
-Cut to the end of line.
-.It Ic ed-move-to-end
-Move cursor to the end of line.
-.It Ic ed-move-to-beg
-Move cursor to the beginning of line.
-.It Ic ed-transpose-chars
-Exchange the character to the left of the cursor with the one under it.
-.It Ic ed-next-char
-Move to the right one character.
-.It Ic ed-prev-word
-Move to the beginning of the current word.
-.It Ic ed-prev-char
-Move to the left one character.
-.It Ic ed-quoted-insert
-Add the next character typed verbatim.
-.It Ic ed-digit
-Adds to argument or enters a digit.
-.It Ic ed-argument-digit
-Digit that starts argument.
-.It Ic ed-unassigned
-Indicates unbound character.
-.It Ic ed-tty-sigint
-Tty interrupt character.
-.It Ic ed-tty-dsusp
-Tty delayed suspend character.
-.It Ic ed-tty-flush-output
-Tty flush output characters.
-.It Ic ed-tty-sigquit
-Tty quit character.
-.It Ic ed-tty-sigtstp
-Tty suspend character.
-.It Ic ed-tty-stop-output
-Tty disallow output characters.
-.It Ic ed-tty-start-output
-Tty allow output characters.
-.It Ic ed-newline
-Execute command.
-.It Ic ed-delete-prev-char
-Delete the character to the left of the cursor.
-.It Ic ed-clear-screen
-Clear screen leaving current line at the top.
-.It Ic ed-redisplay
-Redisplay everything.
-.It Ic ed-start-over
-Erase current line and start from scratch.
-.It Ic ed-sequence-lead-in
-First character in a bound sequence.
-.It Ic ed-prev-history
-Move to the previous history line.
-.It Ic ed-next-history
-Move to the next history line.
-.It Ic ed-search-prev-history
-Search previous in history for a line matching the current.
-.It Ic ed-search-next-history
-Search next in history for a line matching the current.
-.It Ic ed-prev-line
-Move up one line.
-.It Ic ed-next-line
-Move down one line.
-.It Ic ed-command
-Editline extended command.
-.El
-.\" End of section automatically generated with makelist
-.Sh SEE ALSO
-.Xr editline 3 ,
-.Xr regex 3 ,
-.Xr termcap 5
-.Sh AUTHORS
-The
-.Nm editline
-library was written by Christos Zoulas,
-and this manual was written by Luke Mewburn,
-with some sections inspired by
-.Xr tcsh 1 .
diff --git a/1.2-netsec/editline/el.c b/1.2-netsec/editline/el.c
deleted file mode 100644
index 514316fbe..000000000
--- a/1.2-netsec/editline/el.c
+++ /dev/null
@@ -1,509 +0,0 @@
-/* $NetBSD: el.c,v 1.29 2002/03/18 16:00:52 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
-#else
-__RCSID("$NetBSD: el.c,v 1.29 2002/03/18 16:00:52 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * el.c: EditLine interface functions
- */
-#include <sys/types.h>
-#include <sys/param.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include "el.h"
-
-/* el_init():
- * Initialize editline and set default parameters.
- */
-public EditLine *
-el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
-{
-
- EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
-
- if (el == NULL)
- return (NULL);
-
- memset(el, 0, sizeof(EditLine));
-
- el->el_infd = fileno(fin);
- el->el_outfile = fout;
- el->el_errfile = ferr;
- el->el_prog = strdup(prog);
-
- /*
- * Initialize all the modules. Order is important!!!
- */
- el->el_flags = 0;
-
- if (term_init(el) == -1) {
- free(el->el_prog);
- el_free(el);
- return NULL;
- }
- (void) key_init(el);
- (void) map_init(el);
- if (tty_init(el) == -1)
- el->el_flags |= NO_TTY;
- (void) ch_init(el);
- (void) search_init(el);
- (void) hist_init(el);
- (void) prompt_init(el);
- (void) sig_init(el);
- (void) read_init(el);
-
- return (el);
-}
-
-
-/* el_end():
- * Clean up.
- */
-public void
-el_end(EditLine *el)
-{
-
- if (el == NULL)
- return;
-
- el_reset(el);
-
- term_end(el);
- key_end(el);
- map_end(el);
- tty_end(el);
- ch_end(el);
- search_end(el);
- hist_end(el);
- prompt_end(el);
- sig_end(el);
-
- if (el->el_prog)
- el_free((ptr_t) el->el_prog);
- el_free((ptr_t) el);
-}
-
-
-/* el_reset():
- * Reset the tty and the parser
- */
-public void
-el_reset(EditLine *el)
-{
-
- tty_cookedmode(el);
- ch_reset(el); /* XXX: Do we want that? */
-}
-
-
-/* el_set():
- * set the editline parameters
- */
-public int
-el_set(EditLine *el, int op, ...)
-{
- va_list va;
- int rv = 0;
-
- if (el == NULL)
- return (-1);
- va_start(va, op);
-
- switch (op) {
- case EL_PROMPT:
- case EL_RPROMPT:
- rv = prompt_set(el, va_arg(va, el_pfunc_t), op);
- break;
-
- case EL_TERMINAL:
- rv = term_set(el, va_arg(va, char *));
- break;
-
- case EL_EDITOR:
- rv = map_set_editor(el, va_arg(va, char *));
- break;
-
- case EL_SIGNAL:
- if (va_arg(va, int))
- el->el_flags |= HANDLE_SIGNALS;
- else
- el->el_flags &= ~HANDLE_SIGNALS;
- break;
-
- case EL_BIND:
- case EL_TELLTC:
- case EL_SETTC:
- case EL_ECHOTC:
- case EL_SETTY:
- {
- const char *argv[20];
- int i;
-
- for (i = 1; i < 20; i++)
- if ((argv[i] = va_arg(va, char *)) == NULL)
- break;
-
- switch (op) {
- case EL_BIND:
- argv[0] = "bind";
- rv = map_bind(el, i, argv);
- break;
-
- case EL_TELLTC:
- argv[0] = "telltc";
- rv = term_telltc(el, i, argv);
- break;
-
- case EL_SETTC:
- argv[0] = "settc";
- rv = term_settc(el, i, argv);
- break;
-
- case EL_ECHOTC:
- argv[0] = "echotc";
- rv = term_echotc(el, i, argv);
- break;
-
- case EL_SETTY:
- argv[0] = "setty";
- rv = tty_stty(el, i, argv);
- break;
-
- default:
- rv = -1;
- EL_ABORT((el->el_errfile, "Bad op %d\n", op));
- break;
- }
- break;
- }
-
- case EL_ADDFN:
- {
- char *name = va_arg(va, char *);
- char *help = va_arg(va, char *);
- el_func_t func = va_arg(va, el_func_t);
-
- rv = map_addfunc(el, name, help, func);
- break;
- }
-
- case EL_HIST:
- {
- hist_fun_t func = va_arg(va, hist_fun_t);
- ptr_t ptr = va_arg(va, char *);
-
- rv = hist_set(el, func, ptr);
- break;
- }
-
- case EL_EDITMODE:
- if (va_arg(va, int))
- el->el_flags &= ~EDIT_DISABLED;
- else
- el->el_flags |= EDIT_DISABLED;
- rv = 0;
- break;
-
- case EL_GETCFN:
- {
- el_rfunc_t rc = va_arg(va, el_rfunc_t);
- rv = el_read_setfn(el, rc);
- break;
- }
-
- case EL_CLIENTDATA:
- el->el_data = va_arg(va, void *);
- break;
-
- default:
- rv = -1;
- break;
- }
-
- va_end(va);
- return (rv);
-}
-
-
-/* el_get():
- * retrieve the editline parameters
- */
-public int
-el_get(EditLine *el, int op, void *ret)
-{
- int rv;
-
- if (el == NULL || ret == NULL)
- return (-1);
- switch (op) {
- case EL_PROMPT:
- case EL_RPROMPT:
- rv = prompt_get(el, (el_pfunc_t *) & ret, op);
- break;
-
- case EL_EDITOR:
- rv = map_get_editor(el, (const char **) &ret);
- break;
-
- case EL_SIGNAL:
- *((int *) ret) = (el->el_flags & HANDLE_SIGNALS);
- rv = 0;
- break;
-
- case EL_EDITMODE:
- *((int *) ret) = (!(el->el_flags & EDIT_DISABLED));
- rv = 0;
- break;
-
-#if 0 /* XXX */
- case EL_TERMINAL:
- rv = term_get(el, (const char *) &ret);
- break;
-
- case EL_BIND:
- case EL_TELLTC:
- case EL_SETTC:
- case EL_ECHOTC:
- case EL_SETTY:
- {
- char *argv[20];
- int i;
-
- for (i = 1; i < 20; i++)
- if ((argv[i] = va_arg(va, char *)) == NULL)
- break;
-
- switch (op) {
- case EL_BIND:
- argv[0] = "bind";
- rv = map_bind(el, i, argv);
- break;
-
- case EL_TELLTC:
- argv[0] = "telltc";
- rv = term_telltc(el, i, argv);
- break;
-
- case EL_SETTC:
- argv[0] = "settc";
- rv = term_settc(el, i, argv);
- break;
-
- case EL_ECHOTC:
- argv[0] = "echotc";
- rv = term_echotc(el, i, argv);
- break;
-
- case EL_SETTY:
- argv[0] = "setty";
- rv = tty_stty(el, i, argv);
- break;
-
- default:
- rv = -1;
- EL_ABORT((el->errfile, "Bad op %d\n", op));
- break;
- }
- break;
- }
-
- case EL_ADDFN:
- {
- char *name = va_arg(va, char *);
- char *help = va_arg(va, char *);
- el_func_t func = va_arg(va, el_func_t);
-
- rv = map_addfunc(el, name, help, func);
- break;
- }
-
- case EL_HIST:
- {
- hist_fun_t func = va_arg(va, hist_fun_t);
- ptr_t ptr = va_arg(va, char *);
- rv = hist_set(el, func, ptr);
- }
- break;
-#endif /* XXX */
-
- case EL_GETCFN:
- *((el_rfunc_t *)ret) = el_read_getfn(el);
- rv = 0;
- break;
-
- case EL_CLIENTDATA:
- *((void **)ret) = el->el_data;
- rv = 0;
- break;
-
- default:
- rv = -1;
- }
-
- return (rv);
-}
-
-
-/* el_line():
- * Return editing info
- */
-public const LineInfo *
-el_line(EditLine *el)
-{
-
- return (const LineInfo *) (void *) &el->el_line;
-}
-
-
-/* el_source():
- * Source a file
- */
-public int
-el_source(EditLine *el, const char *fname)
-{
- FILE *fp;
- size_t len;
- char *ptr;
-
- fp = NULL;
- if (fname == NULL) {
-#ifdef HAVE_ISSETUGID
- static const char elpath[] = "/.editrc";
- char path[MAXPATHLEN];
-
- if (issetugid())
- return (-1);
- if ((ptr = getenv("HOME")) == NULL)
- return (-1);
- if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
- return (-1);
- if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
- return (-1);
- fname = path;
-#else
- /*
- * If issetugid() is missing, always return an error, in order
- * to keep from inadvertently opening up the user to a security
- * hole.
- */
- return (-1);
-#endif
- }
- if (fp == NULL)
- fp = fopen(fname, "r");
- if (fp == NULL)
- return (-1);
-
- while ((ptr = fgetln(fp, &len)) != NULL) {
- if (len > 0 && ptr[len - 1] == '\n')
- --len;
- ptr[len] = '\0';
- if (parse_line(el, ptr) == -1) {
- (void) fclose(fp);
- return (-1);
- }
- }
-
- (void) fclose(fp);
- return (0);
-}
-
-
-/* el_resize():
- * Called from program when terminal is resized
- */
-public void
-el_resize(EditLine *el)
-{
- int lins, cols;
- sigset_t oset, nset;
-
- (void) sigemptyset(&nset);
- (void) sigaddset(&nset, SIGWINCH);
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
-
- /* get the correct window size */
- if (term_get_size(el, &lins, &cols))
- term_change_size(el, lins, cols);
-
- (void) sigprocmask(SIG_SETMASK, &oset, NULL);
-}
-
-
-/* el_beep():
- * Called from the program to beep
- */
-public void
-el_beep(EditLine *el)
-{
-
- term_beep(el);
-}
-
-
-/* el_editmode()
- * Set the state of EDIT_DISABLED from the `edit' command.
- */
-protected int
-/*ARGSUSED*/
-el_editmode(EditLine *el, int argc, const char **argv)
-{
- const char *how;
-
- if (argv == NULL || argc != 2 || argv[1] == NULL)
- return (-1);
-
- how = argv[1];
- if (strcmp(how, "on") == 0)
- el->el_flags &= ~EDIT_DISABLED;
- else if (strcmp(how, "off") == 0)
- el->el_flags |= EDIT_DISABLED;
- else {
- (void) fprintf(el->el_errfile, "edit: Bad value `%s'.\n", how);
- return (-1);
- }
- return (0);
-}
diff --git a/1.2-netsec/editline/el.h b/1.2-netsec/editline/el.h
deleted file mode 100644
index 641081e87..000000000
--- a/1.2-netsec/editline/el.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/* $NetBSD: el.h,v 1.11 2002/03/18 16:00:52 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)el.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.h: Internal structures.
- */
-#ifndef _h_el
-#define _h_el
-/*
- * Local defaults
- */
-#define KSHVI
-#define VIDEFAULT
-#define ANCHOR
-
-#include <stdio.h>
-#include <sys/types.h>
-
-#define EL_BUFSIZ 1024 /* Maximum line size */
-
-#define HANDLE_SIGNALS 1<<0
-#define NO_TTY 1<<1
-#define EDIT_DISABLED 1<<2
-
-typedef int bool_t; /* True or not */
-
-typedef unsigned char el_action_t; /* Index to command array */
-
-typedef struct coord_t { /* Position on the screen */
- int h;
- int v;
-} coord_t;
-
-typedef struct el_line_t {
- char *buffer; /* Input line */
- char *cursor; /* Cursor position */
- char *lastchar; /* Last character */
- const char *limit; /* Max position */
-} el_line_t;
-
-/*
- * Editor state
- */
-typedef struct el_state_t {
- int inputmode; /* What mode are we in? */
- int doingarg; /* Are we getting an argument? */
- int argument; /* Numeric argument */
- int metanext; /* Is the next char a meta char */
- el_action_t lastcmd; /* Previous command */
-} el_state_t;
-
-/*
- * Until we come up with something better...
- */
-#define el_malloc(a) malloc(a)
-#define el_realloc(a,b) realloc(a, b)
-#define el_free(a) free(a)
-
-#include "tty.h"
-#include "prompt.h"
-#include "key.h"
-#include "term.h"
-#include "refresh.h"
-#include "chared.h"
-#include "common.h"
-#include "search.h"
-#include "hist.h"
-#include "map.h"
-#include "parse.h"
-#include "sig.h"
-#include "help.h"
-#include "read.h"
-
-struct editline {
- char *el_prog; /* the program name */
- FILE *el_outfile; /* Stdio stuff */
- FILE *el_errfile; /* Stdio stuff */
- int el_infd; /* Input file descriptor */
- int el_flags; /* Various flags. */
- coord_t el_cursor; /* Cursor location */
- char **el_display; /* Real screen image = what is there */
- char **el_vdisplay; /* Virtual screen image = what we see */
- void *el_data; /* Client data */
- el_line_t el_line; /* The current line information */
- el_state_t el_state; /* Current editor state */
- el_term_t el_term; /* Terminal dependent stuff */
- el_tty_t el_tty; /* Tty dependent stuff */
- el_refresh_t el_refresh; /* Refresh stuff */
- el_prompt_t el_prompt; /* Prompt stuff */
- el_prompt_t el_rprompt; /* Prompt stuff */
- el_chared_t el_chared; /* Characted editor stuff */
- el_map_t el_map; /* Key mapping stuff */
- el_key_t el_key; /* Key binding stuff */
- el_history_t el_history; /* History stuff */
- el_search_t el_search; /* Search stuff */
- el_signal_t el_signal; /* Signal handling stuff */
- el_read_t el_read; /* Character reading stuff */
-};
-
-protected int el_editmode(EditLine *, int, const char **);
-
-#ifdef DEBUG
-#define EL_ABORT(a) (void) (fprintf(el->el_errfile, "%s, %d: ", \
- __FILE__, __LINE__), fprintf a, abort())
-#else
-#define EL_ABORT(a) abort()
-#endif
-#endif /* _h_el */
diff --git a/1.2-netsec/editline/emacs.c b/1.2-netsec/editline/emacs.c
deleted file mode 100644
index f520d024b..000000000
--- a/1.2-netsec/editline/emacs.c
+++ /dev/null
@@ -1,488 +0,0 @@
-/* $NetBSD: emacs.c,v 1.10 2002/03/18 16:00:52 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: emacs.c,v 1.10 2002/03/18 16:00:52 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * emacs.c: Emacs functions
- */
-#include "el.h"
-
-/* em_delete_or_list():
- * Delete character under cursor or list completions if at end of line
- * [^D]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_delete_or_list(EditLine *el, int c)
-{
-
- if (el->el_line.cursor == el->el_line.lastchar) {
- /* if I'm at the end */
- if (el->el_line.cursor == el->el_line.buffer) {
- /* and the beginning */
- term_overwrite(el, STReof, 4); /* then do a EOF */
- term__flush();
- return (CC_EOF);
- } else {
- /*
- * Here we could list completions, but it is an
- * error right now
- */
- term_beep(el);
- return (CC_ERROR);
- }
- } else {
- c_delafter(el, el->el_state.argument); /* delete after dot */
- if (el->el_line.cursor > el->el_line.lastchar)
- el->el_line.cursor = el->el_line.lastchar;
- /* bounds check */
- return (CC_REFRESH);
- }
-}
-
-
-/* em_delete_next_word():
- * Cut from cursor to end of current word
- * [M-d]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_delete_next_word(EditLine *el, int c)
-{
- char *cp, *p, *kp;
-
- if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
-
- cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
- el->el_state.argument, ce__isword);
-
- for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
- /* save the text */
- *kp++ = *p;
- el->el_chared.c_kill.last = kp;
-
- c_delafter(el, cp - el->el_line.cursor); /* delete after dot */
- if (el->el_line.cursor > el->el_line.lastchar)
- el->el_line.cursor = el->el_line.lastchar;
- /* bounds check */
- return (CC_REFRESH);
-}
-
-
-/* em_yank():
- * Paste cut buffer at cursor position
- * [^Y]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_yank(EditLine *el, int c)
-{
- char *kp, *cp;
-
- if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) {
- if (!ch_enlargebufs(el, 1))
- return (CC_ERROR);
- }
-
- if (el->el_line.lastchar +
- (el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
- el->el_line.limit)
- return (CC_ERROR);
-
- el->el_chared.c_kill.mark = el->el_line.cursor;
- cp = el->el_line.cursor;
-
- /* open the space, */
- c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
- /* copy the chars */
- for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
- *cp++ = *kp;
-
- /* if an arg, cursor at beginning else cursor at end */
- if (el->el_state.argument == 1)
- el->el_line.cursor = cp;
-
- return (CC_REFRESH);
-}
-
-
-/* em_kill_line():
- * Cut the entire line and save in cut buffer
- * [^U]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_kill_line(EditLine *el, int c)
-{
- char *kp, *cp;
-
- cp = el->el_line.buffer;
- kp = el->el_chared.c_kill.buf;
- while (cp < el->el_line.lastchar)
- *kp++ = *cp++; /* copy it */
- el->el_chared.c_kill.last = kp;
- /* zap! -- delete all of it */
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
- return (CC_REFRESH);
-}
-
-
-/* em_kill_region():
- * Cut area between mark and cursor and save in cut buffer
- * [^W]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_kill_region(EditLine *el, int c)
-{
- char *kp, *cp;
-
- if (!el->el_chared.c_kill.mark)
- return (CC_ERROR);
-
- if (el->el_chared.c_kill.mark > el->el_line.cursor) {
- cp = el->el_line.cursor;
- kp = el->el_chared.c_kill.buf;
- while (cp < el->el_chared.c_kill.mark)
- *kp++ = *cp++; /* copy it */
- el->el_chared.c_kill.last = kp;
- c_delafter(el, cp - el->el_line.cursor);
- } else { /* mark is before cursor */
- cp = el->el_chared.c_kill.mark;
- kp = el->el_chared.c_kill.buf;
- while (cp < el->el_line.cursor)
- *kp++ = *cp++; /* copy it */
- el->el_chared.c_kill.last = kp;
- c_delbefore(el, cp - el->el_chared.c_kill.mark);
- el->el_line.cursor = el->el_chared.c_kill.mark;
- }
- return (CC_REFRESH);
-}
-
-
-/* em_copy_region():
- * Copy area between mark and cursor to cut buffer
- * [M-W]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_copy_region(EditLine *el, int c)
-{
- char *kp, *cp;
-
- if (el->el_chared.c_kill.mark)
- return (CC_ERROR);
-
- if (el->el_chared.c_kill.mark > el->el_line.cursor) {
- cp = el->el_line.cursor;
- kp = el->el_chared.c_kill.buf;
- while (cp < el->el_chared.c_kill.mark)
- *kp++ = *cp++; /* copy it */
- el->el_chared.c_kill.last = kp;
- } else {
- cp = el->el_chared.c_kill.mark;
- kp = el->el_chared.c_kill.buf;
- while (cp < el->el_line.cursor)
- *kp++ = *cp++; /* copy it */
- el->el_chared.c_kill.last = kp;
- }
- return (CC_NORM);
-}
-
-
-/* em_gosmacs_traspose():
- * Exchange the two characters before the cursor
- * Gosling emacs transpose chars [^T]
- */
-protected el_action_t
-em_gosmacs_traspose(EditLine *el, int c)
-{
-
- if (el->el_line.cursor > &el->el_line.buffer[1]) {
- /* must have at least two chars entered */
- c = el->el_line.cursor[-2];
- el->el_line.cursor[-2] = el->el_line.cursor[-1];
- el->el_line.cursor[-1] = c;
- return (CC_REFRESH);
- } else
- return (CC_ERROR);
-}
-
-
-/* em_next_word():
- * Move next to end of current word
- * [M-f]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_next_word(EditLine *el, int c)
-{
- if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
-
- el->el_line.cursor = c__next_word(el->el_line.cursor,
- el->el_line.lastchar,
- el->el_state.argument,
- ce__isword);
-
- if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* em_upper_case():
- * Uppercase the characters from cursor to end of current word
- * [M-u]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_upper_case(EditLine *el, int c)
-{
- char *cp, *ep;
-
- ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
- el->el_state.argument, ce__isword);
-
- for (cp = el->el_line.cursor; cp < ep; cp++)
- if (islower((unsigned char) *cp))
- *cp = toupper(*cp);
-
- el->el_line.cursor = ep;
- if (el->el_line.cursor > el->el_line.lastchar)
- el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
-}
-
-
-/* em_capitol_case():
- * Capitalize the characters from cursor to end of current word
- * [M-c]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_capitol_case(EditLine *el, int c)
-{
- char *cp, *ep;
-
- ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
- el->el_state.argument, ce__isword);
-
- for (cp = el->el_line.cursor; cp < ep; cp++) {
- if (isalpha((unsigned char) *cp)) {
- if (islower((unsigned char) *cp))
- *cp = toupper(*cp);
- cp++;
- break;
- }
- }
- for (; cp < ep; cp++)
- if (isupper((unsigned char) *cp))
- *cp = tolower(*cp);
-
- el->el_line.cursor = ep;
- if (el->el_line.cursor > el->el_line.lastchar)
- el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
-}
-
-
-/* em_lower_case():
- * Lowercase the characters from cursor to end of current word
- * [M-l]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_lower_case(EditLine *el, int c)
-{
- char *cp, *ep;
-
- ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
- el->el_state.argument, ce__isword);
-
- for (cp = el->el_line.cursor; cp < ep; cp++)
- if (isupper((unsigned char) *cp))
- *cp = tolower(*cp);
-
- el->el_line.cursor = ep;
- if (el->el_line.cursor > el->el_line.lastchar)
- el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
-}
-
-
-/* em_set_mark():
- * Set the mark at cursor
- * [^@]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_set_mark(EditLine *el, int c)
-{
-
- el->el_chared.c_kill.mark = el->el_line.cursor;
- return (CC_NORM);
-}
-
-
-/* em_exchange_mark():
- * Exchange the cursor and mark
- * [^X^X]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_exchange_mark(EditLine *el, int c)
-{
- char *cp;
-
- cp = el->el_line.cursor;
- el->el_line.cursor = el->el_chared.c_kill.mark;
- el->el_chared.c_kill.mark = cp;
- return (CC_CURSOR);
-}
-
-
-/* em_universal_argument():
- * Universal argument (argument times 4)
- * [^U]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_universal_argument(EditLine *el, int c)
-{ /* multiply current argument by 4 */
-
- if (el->el_state.argument > 1000000)
- return (CC_ERROR);
- el->el_state.doingarg = 1;
- el->el_state.argument *= 4;
- return (CC_ARGHACK);
-}
-
-
-/* em_meta_next():
- * Add 8th bit to next character typed
- * [<ESC>]
- */
-protected el_action_t
-/*ARGSUSED*/
-em_meta_next(EditLine *el, int c)
-{
-
- el->el_state.metanext = 1;
- return (CC_ARGHACK);
-}
-
-
-/* em_toggle_overwrite():
- * Switch from insert to overwrite mode or vice versa
- */
-protected el_action_t
-/*ARGSUSED*/
-em_toggle_overwrite(EditLine *el, int c)
-{
-
- el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
- MODE_REPLACE : MODE_INSERT;
- return (CC_NORM);
-}
-
-
-/* em_copy_prev_word():
- * Copy current word to cursor
- */
-protected el_action_t
-/*ARGSUSED*/
-em_copy_prev_word(EditLine *el, int c)
-{
- char *cp, *oldc, *dp;
-
- if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
-
- oldc = el->el_line.cursor;
- /* does a bounds check */
- cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
- el->el_state.argument, ce__isword);
-
- c_insert(el, oldc - cp);
- for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
- *dp++ = *cp;
-
- el->el_line.cursor = dp;/* put cursor at end */
-
- return (CC_REFRESH);
-}
-
-
-/* em_inc_search_next():
- * Emacs incremental next search
- */
-protected el_action_t
-/*ARGSUSED*/
-em_inc_search_next(EditLine *el, int c)
-{
-
- el->el_search.patlen = 0;
- return (ce_inc_search(el, ED_SEARCH_NEXT_HISTORY));
-}
-
-
-/* em_inc_search_prev():
- * Emacs incremental reverse search
- */
-protected el_action_t
-/*ARGSUSED*/
-em_inc_search_prev(EditLine *el, int c)
-{
-
- el->el_search.patlen = 0;
- return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
-}
diff --git a/1.2-netsec/editline/hist.c b/1.2-netsec/editline/hist.c
deleted file mode 100644
index 11f39ae10..000000000
--- a/1.2-netsec/editline/hist.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/* $NetBSD: hist.c,v 1.10 2002/03/18 16:00:53 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: hist.c,v 1.10 2002/03/18 16:00:53 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * hist.c: History access functions
- */
-#include <stdlib.h>
-#include "el.h"
-
-/* hist_init():
- * Initialization function.
- */
-protected int
-hist_init(EditLine *el)
-{
-
- el->el_history.fun = NULL;
- el->el_history.ref = NULL;
- el->el_history.buf = (char *) el_malloc(EL_BUFSIZ);
- el->el_history.sz = EL_BUFSIZ;
- if (el->el_history.buf == NULL)
- return (-1);
- el->el_history.last = el->el_history.buf;
- return (0);
-}
-
-
-/* hist_end():
- * clean up history;
- */
-protected void
-hist_end(EditLine *el)
-{
-
- el_free((ptr_t) el->el_history.buf);
- el->el_history.buf = NULL;
-}
-
-
-/* hist_set():
- * Set new history interface
- */
-protected int
-hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
-{
-
- el->el_history.ref = ptr;
- el->el_history.fun = fun;
- return (0);
-}
-
-
-/* hist_get():
- * Get a history line and update it in the buffer.
- * eventno tells us the event to get.
- */
-protected el_action_t
-hist_get(EditLine *el)
-{
- const char *hp;
- int h;
-
- if (el->el_history.eventno == 0) { /* if really the current line */
- (void) strncpy(el->el_line.buffer, el->el_history.buf,
- el->el_history.sz - 1);
- el->el_line.lastchar = el->el_line.buffer +
- (el->el_history.last - el->el_history.buf);
-
-#ifdef KSHVI
- if (el->el_map.type == MAP_VI)
- el->el_line.cursor = el->el_line.buffer;
- else
-#endif /* KSHVI */
- el->el_line.cursor = el->el_line.lastchar;
-
- return (CC_REFRESH);
- }
- if (el->el_history.ref == NULL)
- return (CC_ERROR);
-
- hp = HIST_FIRST(el);
-
- if (hp == NULL)
- return (CC_ERROR);
-
- for (h = 1; h < el->el_history.eventno; h++)
- if ((hp = HIST_NEXT(el)) == NULL) {
- el->el_history.eventno = h;
- return (CC_ERROR);
- }
- (void) strncpy(el->el_line.buffer, hp,
- (size_t)(el->el_line.limit - el->el_line.buffer));
- el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer);
-
- if (el->el_line.lastchar > el->el_line.buffer) {
- if (el->el_line.lastchar[-1] == '\n')
- el->el_line.lastchar--;
- if ((el->el_line.lastchar > el->el_line.buffer)&&(el->el_line.lastchar[-1] == ' ')) /* bill heckel */
- el->el_line.lastchar--;
- if (el->el_line.lastchar < el->el_line.buffer)
- el->el_line.lastchar = el->el_line.buffer;
- }
-#ifdef KSHVI
- if (el->el_map.type == MAP_VI)
- el->el_line.cursor = el->el_line.buffer;
- else
-#endif /* KSHVI */
- el->el_line.cursor = el->el_line.lastchar;
-
- return (CC_REFRESH);
-}
-
-
-/* hist_list()
- * List history entries
- */
-protected int
-/*ARGSUSED*/
-hist_list(EditLine *el, int argc, const char **argv)
-{
- const char *str;
-
- if (el->el_history.ref == NULL)
- return (-1);
- for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
- (void) fprintf(el->el_outfile, "%d %s",
- el->el_history.ev.num, str);
- return (0);
-}
-
-/* hist_enlargebuf()
- * Enlarge history buffer to specified value. Called from el_enlargebufs().
- * Return 0 for failure, 1 for success.
- */
-protected int
-/*ARGSUSED*/
-hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz)
-{
- char *newbuf;
-
- newbuf = realloc(el->el_history.buf, newsz);
- if (!newbuf)
- return 0;
-
- (void) memset(&newbuf[oldsz], '\0', newsz - oldsz);
-
- el->el_history.last = newbuf +
- (el->el_history.last - el->el_history.buf);
- el->el_history.buf = newbuf;
- el->el_history.sz = newsz;
-
- return 1;
-}
diff --git a/1.2-netsec/editline/hist.h b/1.2-netsec/editline/hist.h
deleted file mode 100644
index 5fdccd08e..000000000
--- a/1.2-netsec/editline/hist.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/* $NetBSD: hist.h,v 1.7 2002/03/18 16:00:53 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)hist.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.hist.c: History functions
- */
-#ifndef _h_el_hist
-#define _h_el_hist
-
-#include "histedit.h"
-
-typedef int (*hist_fun_t)(ptr_t, HistEvent *, int, ...);
-
-typedef struct el_history_t {
- char *buf; /* The history buffer */
- size_t sz; /* Size of history buffer */
- char *last; /* The last character */
- int eventno; /* Event we are looking for */
- ptr_t ref; /* Argument for history fcns */
- hist_fun_t fun; /* Event access */
- HistEvent ev; /* Event cookie */
-} el_history_t;
-
-#define HIST_FUN(el, fn, arg) \
- ((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \
- fn, arg)) == -1) ? NULL : (el)->el_history.ev.str)
-
-#define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL)
-#define HIST_FIRST(el) HIST_FUN(el, H_FIRST, NULL)
-#define HIST_LAST(el) HIST_FUN(el, H_LAST, NULL)
-#define HIST_PREV(el) HIST_FUN(el, H_PREV, NULL)
-#define HIST_EVENT(el, num) HIST_FUN(el, H_EVENT, num)
-#define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname)
-#define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname)
-
-protected int hist_init(EditLine *);
-protected void hist_end(EditLine *);
-protected el_action_t hist_get(EditLine *);
-protected int hist_set(EditLine *, hist_fun_t, ptr_t);
-protected int hist_list(EditLine *, int, const char **);
-protected int hist_enlargebuf(EditLine *, size_t, size_t);
-
-#endif /* _h_el_hist */
diff --git a/1.2-netsec/editline/histedit.h b/1.2-netsec/editline/histedit.h
deleted file mode 100644
index e387e3b81..000000000
--- a/1.2-netsec/editline/histedit.h
+++ /dev/null
@@ -1,197 +0,0 @@
-/* $NetBSD: histedit.h,v 1.19 2002/03/18 16:00:54 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)histedit.h 8.2 (Berkeley) 1/3/94
- */
-
-/*
- * histedit.h: Line editor and history interface.
- */
-#ifndef _HISTEDIT_H_
-#define _HISTEDIT_H_
-
-#define LIBEDIT_MAJOR 2
-#define LIBEDIT_MINOR 6
-
-#include <sys/types.h>
-#include <stdio.h>
-
-/*
- * ==== Editing ====
- */
-typedef struct editline EditLine;
-
-/*
- * For user-defined function interface
- */
-typedef struct lineinfo {
- char *buffer;
- char *cursor;
- char *lastchar;
-} LineInfo;
-
-
-/*
- * EditLine editor function return codes.
- * For user-defined function interface
- */
-#define CC_NORM 0
-#define CC_NEWLINE 1
-#define CC_EOF 2
-#define CC_ARGHACK 3
-#define CC_REFRESH 4
-#define CC_CURSOR 5
-#define CC_ERROR 6
-#define CC_FATAL 7
-#define CC_REDISPLAY 8
-#define CC_REFRESH_BEEP 9
-
-/*
- * Initialization, cleanup, and resetting
- */
-EditLine *el_init(const char *, FILE *, FILE *, FILE *);
-void el_reset(EditLine *);
-void el_end(EditLine *);
-
-
-/*
- * Get a line, a character or push a string back in the input queue
- */
-const char *el_gets(EditLine *, int *);
-int el_getc(EditLine *, char *);
-void el_push(EditLine *, char *);
-
-/*
- * Beep!
- */
-void el_beep(EditLine *);
-
-/*
- * High level function internals control
- * Parses argc, argv array and executes builtin editline commands
- */
-int el_parse(EditLine *, int, const char **);
-
-/*
- * Low level editline access functions
- */
-int el_set(EditLine *, int, ...);
-int el_get(EditLine *, int, void *);
-
-/*
- * el_set/el_get parameters
- */
-#define EL_PROMPT 0 /* , el_pfunc_t); */
-#define EL_TERMINAL 1 /* , const char *); */
-#define EL_EDITOR 2 /* , const char *); */
-#define EL_SIGNAL 3 /* , int); */
-#define EL_BIND 4 /* , const char *, ..., NULL); */
-#define EL_TELLTC 5 /* , const char *, ..., NULL); */
-#define EL_SETTC 6 /* , const char *, ..., NULL); */
-#define EL_ECHOTC 7 /* , const char *, ..., NULL); */
-#define EL_SETTY 8 /* , const char *, ..., NULL); */
-#define EL_ADDFN 9 /* , const char *, const char * */
- /* , el_func_t); */
-#define EL_HIST 10 /* , hist_fun_t, const char *); */
-#define EL_EDITMODE 11 /* , int); */
-#define EL_RPROMPT 12 /* , el_pfunc_t); */
-#define EL_GETCFN 13 /* , el_rfunc_t); */
-#define EL_CLIENTDATA 14 /* , void *); */
-
-#define EL_BUILTIN_GETCFN (NULL)
-
-/*
- * Source named file or $PWD/.editrc or $HOME/.editrc
- */
-int el_source(EditLine *, const char *);
-
-/*
- * Must be called when the terminal changes size; If EL_SIGNAL
- * is set this is done automatically otherwise it is the responsibility
- * of the application
- */
-void el_resize(EditLine *);
-
-
-/*
- * User-defined function interface.
- */
-const LineInfo *el_line(EditLine *);
-int el_insertstr(EditLine *, const char *);
-void el_deletestr(EditLine *, int);
-
-/*
- * ==== History ====
- */
-
-typedef struct history History;
-
-typedef struct HistEvent {
- int num;
- const char *str;
-} HistEvent;
-
-/*
- * History access functions.
- */
-History * history_init(void);
-void history_end(History *);
-
-int history(History *, HistEvent *, int, ...);
-
-#define H_FUNC 0 /* , UTSL */
-#define H_SETSIZE 1 /* , const int); */
-#define H_GETSIZE 2 /* , void); */
-#define H_FIRST 3 /* , void); */
-#define H_LAST 4 /* , void); */
-#define H_PREV 5 /* , void); */
-#define H_NEXT 6 /* , void); */
-#define H_CURR 8 /* , const int); */
-#define H_SET 7 /* , void); */
-#define H_ADD 9 /* , const char *); */
-#define H_ENTER 10 /* , const char *); */
-#define H_APPEND 11 /* , const char *); */
-#define H_END 12 /* , void); */
-#define H_NEXT_STR 13 /* , const char *); */
-#define H_PREV_STR 14 /* , const char *); */
-#define H_NEXT_EVENT 15 /* , const int); */
-#define H_PREV_EVENT 16 /* , const int); */
-#define H_LOAD 17 /* , const char *); */
-#define H_SAVE 18 /* , const char *); */
-#define H_CLEAR 19 /* , void); */
-
-#endif /* _HISTEDIT_H_ */
diff --git a/1.2-netsec/editline/history.c b/1.2-netsec/editline/history.c
deleted file mode 100644
index f133d2eb0..000000000
--- a/1.2-netsec/editline/history.c
+++ /dev/null
@@ -1,875 +0,0 @@
-/* $NetBSD: history.c,v 1.19 2002/03/18 16:00:54 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: history.c,v 1.19 2002/03/18 16:00:54 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * hist.c: History access functions
- */
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#ifdef HAVE_VIS_H
-#include <vis.h>
-#else
-#include "np/vis.h"
-#endif
-#include <sys/stat.h>
-
-static const char hist_cookie[] = "_HiStOrY_V2_\n";
-
-#include "histedit.h"
-
-typedef int (*history_gfun_t)(ptr_t, HistEvent *);
-typedef int (*history_efun_t)(ptr_t, HistEvent *, const char *);
-typedef void (*history_vfun_t)(ptr_t, HistEvent *);
-typedef int (*history_sfun_t)(ptr_t, HistEvent *, const int);
-
-struct history {
- ptr_t h_ref; /* Argument for history fcns */
- int h_ent; /* Last entry point for history */
- history_gfun_t h_first; /* Get the first element */
- history_gfun_t h_next; /* Get the next element */
- history_gfun_t h_last; /* Get the last element */
- history_gfun_t h_prev; /* Get the previous element */
- history_gfun_t h_curr; /* Get the current element */
- history_sfun_t h_set; /* Set the current element */
- history_vfun_t h_clear; /* Clear the history list */
- history_efun_t h_enter; /* Add an element */
- history_efun_t h_add; /* Append to an element */
-};
-#define HNEXT(h, ev) (*(h)->h_next)((h)->h_ref, ev)
-#define HFIRST(h, ev) (*(h)->h_first)((h)->h_ref, ev)
-#define HPREV(h, ev) (*(h)->h_prev)((h)->h_ref, ev)
-#define HLAST(h, ev) (*(h)->h_last)((h)->h_ref, ev)
-#define HCURR(h, ev) (*(h)->h_curr)((h)->h_ref, ev)
-#define HSET(h, ev, n) (*(h)->h_set)((h)->h_ref, ev, n)
-#define HCLEAR(h, ev) (*(h)->h_clear)((h)->h_ref, ev)
-#define HENTER(h, ev, str) (*(h)->h_enter)((h)->h_ref, ev, str)
-#define HADD(h, ev, str) (*(h)->h_add)((h)->h_ref, ev, str)
-
-#define h_malloc(a) malloc(a)
-#define h_realloc(a, b) realloc((a), (b))
-#define h_free(a) free(a)
-
-typedef struct {
- int num;
- char *str;
-} HistEventPrivate;
-
-
-
-private int history_setsize(History *, HistEvent *, int);
-private int history_getsize(History *, HistEvent *);
-private int history_set_fun(History *, History *);
-private int history_load(History *, const char *);
-private int history_save(History *, const char *);
-private int history_prev_event(History *, HistEvent *, int);
-private int history_next_event(History *, HistEvent *, int);
-private int history_next_string(History *, HistEvent *, const char *);
-private int history_prev_string(History *, HistEvent *, const char *);
-
-
-/***********************************************************************/
-
-/*
- * Builtin- history implementation
- */
-typedef struct hentry_t {
- HistEvent ev; /* What we return */
- struct hentry_t *next; /* Next entry */
- struct hentry_t *prev; /* Previous entry */
-} hentry_t;
-
-typedef struct history_t {
- hentry_t list; /* Fake list header element */
- hentry_t *cursor; /* Current element in the list */
- int max; /* Maximum number of events */
- int cur; /* Current number of events */
- int eventid; /* For generation of unique event id */
-} history_t;
-
-private int history_def_first(ptr_t, HistEvent *);
-private int history_def_last(ptr_t, HistEvent *);
-private int history_def_next(ptr_t, HistEvent *);
-private int history_def_prev(ptr_t, HistEvent *);
-private int history_def_curr(ptr_t, HistEvent *);
-private int history_def_set(ptr_t, HistEvent *, const int n);
-private int history_def_enter(ptr_t, HistEvent *, const char *);
-private int history_def_add(ptr_t, HistEvent *, const char *);
-private void history_def_init(ptr_t *, HistEvent *, int);
-private void history_def_clear(ptr_t, HistEvent *);
-private int history_def_insert(history_t *, HistEvent *, const char *);
-private void history_def_delete(history_t *, HistEvent *, hentry_t *);
-
-#define history_def_setsize(p, num)(void) (((history_t *) p)->max = (num))
-#define history_def_getsize(p) (((history_t *) p)->cur)
-
-#define he_strerror(code) he_errlist[code]
-#define he_seterrev(evp, code) {\
- evp->num = code;\
- evp->str = he_strerror(code);\
- }
-
-/* error messages */
-static const char *const he_errlist[] = {
- "OK",
- "unknown error",
- "malloc() failed",
- "first event not found",
- "last event not found",
- "empty list",
- "no next event",
- "no previous event",
- "current event is invalid",
- "event not found",
- "can't read history from file",
- "can't write history",
- "required parameter(s) not supplied",
- "history size negative",
- "function not allowed with other history-functions-set the default",
- "bad parameters"
-};
-/* error codes */
-#define _HE_OK 0
-#define _HE_UNKNOWN 1
-#define _HE_MALLOC_FAILED 2
-#define _HE_FIRST_NOTFOUND 3
-#define _HE_LAST_NOTFOUND 4
-#define _HE_EMPTY_LIST 5
-#define _HE_END_REACHED 6
-#define _HE_START_REACHED 7
-#define _HE_CURR_INVALID 8
-#define _HE_NOT_FOUND 9
-#define _HE_HIST_READ 10
-#define _HE_HIST_WRITE 11
-#define _HE_PARAM_MISSING 12
-#define _HE_SIZE_NEGATIVE 13
-#define _HE_NOT_ALLOWED 14
-#define _HE_BAD_PARAM 15
-
-/* history_def_first():
- * Default function to return the first event in the history.
- */
-private int
-history_def_first(ptr_t p, HistEvent *ev)
-{
- history_t *h = (history_t *) p;
-
- h->cursor = h->list.next;
- if (h->cursor != &h->list)
- *ev = h->cursor->ev;
- else {
- he_seterrev(ev, _HE_FIRST_NOTFOUND);
- return (-1);
- }
-
- return (0);
-}
-
-
-/* history_def_last():
- * Default function to return the last event in the history.
- */
-private int
-history_def_last(ptr_t p, HistEvent *ev)
-{
- history_t *h = (history_t *) p;
-
- h->cursor = h->list.prev;
- if (h->cursor != &h->list)
- *ev = h->cursor->ev;
- else {
- he_seterrev(ev, _HE_LAST_NOTFOUND);
- return (-1);
- }
-
- return (0);
-}
-
-
-/* history_def_next():
- * Default function to return the next event in the history.
- */
-private int
-history_def_next(ptr_t p, HistEvent *ev)
-{
- history_t *h = (history_t *) p;
-
- if (h->cursor != &h->list)
- h->cursor = h->cursor->next;
- else {
- he_seterrev(ev, _HE_EMPTY_LIST);
- return (-1);
- }
-
- if (h->cursor != &h->list)
- *ev = h->cursor->ev;
- else {
- he_seterrev(ev, _HE_END_REACHED);
- return (-1);
- }
-
- return (0);
-}
-
-
-/* history_def_prev():
- * Default function to return the previous event in the history.
- */
-private int
-history_def_prev(ptr_t p, HistEvent *ev)
-{
- history_t *h = (history_t *) p;
-
- if (h->cursor != &h->list)
- h->cursor = h->cursor->prev;
- else {
- he_seterrev(ev,
- (h->cur > 0) ? _HE_END_REACHED : _HE_EMPTY_LIST);
- return (-1);
- }
-
- if (h->cursor != &h->list)
- *ev = h->cursor->ev;
- else {
- he_seterrev(ev, _HE_START_REACHED);
- return (-1);
- }
-
- return (0);
-}
-
-
-/* history_def_curr():
- * Default function to return the current event in the history.
- */
-private int
-history_def_curr(ptr_t p, HistEvent *ev)
-{
- history_t *h = (history_t *) p;
-
- if (h->cursor != &h->list)
- *ev = h->cursor->ev;
- else {
- he_seterrev(ev,
- (h->cur > 0) ? _HE_CURR_INVALID : _HE_EMPTY_LIST);
- return (-1);
- }
-
- return (0);
-}
-
-
-/* history_def_set():
- * Default function to set the current event in the history to the
- * given one.
- */
-private int
-history_def_set(ptr_t p, HistEvent *ev, const int n)
-{
- history_t *h = (history_t *) p;
-
- if (h->cur == 0) {
- he_seterrev(ev, _HE_EMPTY_LIST);
- return (-1);
- }
- if (h->cursor == &h->list || h->cursor->ev.num != n) {
- for (h->cursor = h->list.next; h->cursor != &h->list;
- h->cursor = h->cursor->next)
- if (h->cursor->ev.num == n)
- break;
- }
- if (h->cursor == &h->list) {
- he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
- }
- return (0);
-}
-
-
-/* history_def_add():
- * Append string to element
- */
-private int
-history_def_add(ptr_t p, HistEvent *ev, const char *str)
-{
- history_t *h = (history_t *) p;
- size_t len;
- char *s;
- HistEventPrivate *evp = (void *)&h->cursor->ev;
-
- if (h->cursor == &h->list)
- return (history_def_enter(p, ev, str));
- len = strlen(evp->str) + strlen(str) + 1;
- s = (char *) h_malloc(len);
- if (!s) {
- he_seterrev(ev, _HE_MALLOC_FAILED);
- return (-1);
- }
- (void) strlcpy(s, h->cursor->ev.str, len);
- (void) strlcat(s, str, len);
- h_free(evp->str);
- evp->str = s;
- *ev = h->cursor->ev;
- return (0);
-}
-
-
-/* history_def_delete():
- * Delete element hp of the h list
- */
-/* ARGSUSED */
-private void
-history_def_delete(history_t *h, HistEvent *ev, hentry_t *hp)
-{
- HistEventPrivate *evp = (void *)&hp->ev;
- if (hp == &h->list)
- abort();
- hp->prev->next = hp->next;
- hp->next->prev = hp->prev;
- h_free((ptr_t) evp->str);
- h_free(hp);
- h->cur--;
-}
-
-
-/* history_def_insert():
- * Insert element with string str in the h list
- */
-private int
-history_def_insert(history_t *h, HistEvent *ev, const char *str)
-{
-
- h->cursor = (hentry_t *) h_malloc(sizeof(hentry_t));
- if (h->cursor)
- h->cursor->ev.str = strdup(str);
- if (!h->cursor || !h->cursor->ev.str) {
- he_seterrev(ev, _HE_MALLOC_FAILED);
- return (-1);
- }
- h->cursor->ev.num = ++h->eventid;
- h->cursor->next = h->list.next;
- h->cursor->prev = &h->list;
- h->list.next->prev = h->cursor;
- h->list.next = h->cursor;
- h->cur++;
-
- *ev = h->cursor->ev;
- return (0);
-}
-
-
-/* history_def_enter():
- * Default function to enter an item in the history
- */
-private int
-history_def_enter(ptr_t p, HistEvent *ev, const char *str)
-{
- history_t *h = (history_t *) p;
-
- if (history_def_insert(h, ev, str) == -1)
- return (-1); /* error, keep error message */
-
- /*
- * Always keep at least one entry.
- * This way we don't have to check for the empty list.
- */
- while (h->cur > h->max && h->cur > 0)
- history_def_delete(h, ev, h->list.prev);
-
- return (0);
-}
-
-
-/* history_def_init():
- * Default history initialization function
- */
-/* ARGSUSED */
-private void
-history_def_init(ptr_t *p, HistEvent *ev, int n)
-{
- history_t *h = (history_t *) h_malloc(sizeof(history_t));
-
- if (n <= 0)
- n = 0;
- h->eventid = 0;
- h->cur = 0;
- h->max = n;
- h->list.next = h->list.prev = &h->list;
- h->list.ev.str = NULL;
- h->list.ev.num = 0;
- h->cursor = &h->list;
- *p = (ptr_t) h;
-}
-
-
-/* history_def_clear():
- * Default history cleanup function
- */
-private void
-history_def_clear(ptr_t p, HistEvent *ev)
-{
- history_t *h = (history_t *) p;
-
- while (h->list.prev != &h->list)
- history_def_delete(h, ev, h->list.prev);
- h->eventid = 0;
- h->cur = 0;
-}
-
-
-
-
-/************************************************************************/
-
-/* history_init():
- * Initialization function.
- */
-public History *
-history_init(void)
-{
- History *h = (History *) h_malloc(sizeof(History));
- HistEvent ev;
-
- history_def_init(&h->h_ref, &ev, 0);
- h->h_ent = -1;
- h->h_next = history_def_next;
- h->h_first = history_def_first;
- h->h_last = history_def_last;
- h->h_prev = history_def_prev;
- h->h_curr = history_def_curr;
- h->h_set = history_def_set;
- h->h_clear = history_def_clear;
- h->h_enter = history_def_enter;
- h->h_add = history_def_add;
-
- return (h);
-}
-
-
-/* history_end():
- * clean up history;
- */
-public void
-history_end(History *h)
-{
- HistEvent ev;
-
- if (h->h_next == history_def_next)
- history_def_clear(h->h_ref, &ev);
-}
-
-
-
-/* history_setsize():
- * Set history number of events
- */
-private int
-history_setsize(History *h, HistEvent *ev, int num)
-{
-
- if (h->h_next != history_def_next) {
- he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
- }
- if (num < 0) {
- he_seterrev(ev, _HE_BAD_PARAM);
- return (-1);
- }
- history_def_setsize(h->h_ref, num);
- return (0);
-}
-
-
-/* history_getsize():
- * Get number of events currently in history
- */
-private int
-history_getsize(History *h, HistEvent *ev)
-{
- int retval = 0;
-
- if (h->h_next != history_def_next) {
- he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
- }
- retval = history_def_getsize(h->h_ref);
- if (retval < -1) {
- he_seterrev(ev, _HE_SIZE_NEGATIVE);
- return (-1);
- }
- ev->num = retval;
- return (0);
-}
-
-
-/* history_set_fun():
- * Set history functions
- */
-private int
-history_set_fun(History *h, History *nh)
-{
- HistEvent ev;
-
- if (nh->h_first == NULL || nh->h_next == NULL || nh->h_last == NULL ||
- nh->h_prev == NULL || nh->h_curr == NULL || nh->h_set == NULL ||
- nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL ||
- nh->h_ref == NULL) {
- if (h->h_next != history_def_next) {
- history_def_init(&h->h_ref, &ev, 0);
- h->h_first = history_def_first;
- h->h_next = history_def_next;
- h->h_last = history_def_last;
- h->h_prev = history_def_prev;
- h->h_curr = history_def_curr;
- h->h_set = history_def_set;
- h->h_clear = history_def_clear;
- h->h_enter = history_def_enter;
- h->h_add = history_def_add;
- }
- return (-1);
- }
- if (h->h_next == history_def_next)
- history_def_clear(h->h_ref, &ev);
-
- h->h_ent = -1;
- h->h_first = nh->h_first;
- h->h_next = nh->h_next;
- h->h_last = nh->h_last;
- h->h_prev = nh->h_prev;
- h->h_curr = nh->h_curr;
- h->h_set = nh->h_set;
- h->h_clear = nh->h_clear;
- h->h_enter = nh->h_enter;
- h->h_add = nh->h_add;
-
- return (0);
-}
-
-
-/* history_load():
- * History load function
- */
-private int
-history_load(History *h, const char *fname)
-{
- FILE *fp;
- char *line;
- size_t sz, max_size;
- char *ptr;
- int i = -1;
- HistEvent ev;
-
- if ((fp = fopen(fname, "r")) == NULL)
- return (i);
-
- if ((line = fgetln(fp, &sz)) == NULL)
- goto done;
-
- if (strncmp(line, hist_cookie, sz) != 0)
- goto done;
-
- ptr = h_malloc(max_size = 1024);
- for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) {
- char c = line[sz];
-
- if (sz != 0 && line[sz - 1] == '\n')
- line[--sz] = '\0';
- else
- line[sz] = '\0';
-
- if (max_size < sz) {
- max_size = (sz + 1023) & ~1023;
- ptr = h_realloc(ptr, max_size);
- }
- (void) strunvis(ptr, line);
- line[sz] = c;
- HENTER(h, &ev, ptr);
- }
- h_free(ptr);
-
-done:
- (void) fclose(fp);
- return (i);
-}
-
-
-/* history_save():
- * History save function
- */
-private int
-history_save(History *h, const char *fname)
-{
- FILE *fp;
- HistEvent ev;
- int i = 0, retval;
- size_t len, max_size;
- char *ptr;
-
- if ((fp = fopen(fname, "w")) == NULL)
- return (-1);
-
- (void) fchmod(fileno(fp), S_IRUSR|S_IWUSR);
- (void) fputs(hist_cookie, fp);
- ptr = h_malloc(max_size = 1024);
- for (retval = HLAST(h, &ev);
- retval != -1;
- retval = HPREV(h, &ev), i++) {
- len = strlen(ev.str) * 4;
- if (len >= max_size) {
- max_size = (len + 1023) & 1023;
- ptr = h_realloc(ptr, max_size);
- }
- (void) strvis(ptr, ev.str, VIS_WHITE);
- (void) fprintf(fp, "%s\n", ev.str);
- }
- h_free(ptr);
- (void) fclose(fp);
- return (i);
-}
-
-
-/* history_prev_event():
- * Find the previous event, with number given
- */
-private int
-history_prev_event(History *h, HistEvent *ev, int num)
-{
- int retval;
-
- for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
- if (ev->num == num)
- return (0);
-
- he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
-}
-
-
-/* history_next_event():
- * Find the next event, with number given
- */
-private int
-history_next_event(History *h, HistEvent *ev, int num)
-{
- int retval;
-
- for (retval = HCURR(h, ev); retval != -1; retval = HNEXT(h, ev))
- if (ev->num == num)
- return (0);
-
- he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
-}
-
-
-/* history_prev_string():
- * Find the previous event beginning with string
- */
-private int
-history_prev_string(History *h, HistEvent *ev, const char *str)
-{
- size_t len = strlen(str);
- int retval;
-
- for (retval = HCURR(h, ev); retval != -1; retval = HNEXT(h, ev))
- if (strncmp(str, ev->str, len) == 0)
- return (0);
-
- he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
-}
-
-
-/* history_next_string():
- * Find the next event beginning with string
- */
-private int
-history_next_string(History *h, HistEvent *ev, const char *str)
-{
- size_t len = strlen(str);
- int retval;
-
- for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
- if (strncmp(str, ev->str, len) == 0)
- return (0);
-
- he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
-}
-
-
-/* history():
- * User interface to history functions.
- */
-int
-history(History *h, HistEvent *ev, int fun, ...)
-{
- va_list va;
- const char *str;
- int retval;
-
- va_start(va, fun);
-
- he_seterrev(ev, _HE_OK);
-
- switch (fun) {
- case H_GETSIZE:
- retval = history_getsize(h, ev);
- break;
-
- case H_SETSIZE:
- retval = history_setsize(h, ev, va_arg(va, int));
- break;
-
- case H_ADD:
- str = va_arg(va, const char *);
- retval = HADD(h, ev, str);
- break;
-
- case H_ENTER:
- str = va_arg(va, const char *);
- if ((retval = HENTER(h, ev, str)) != -1)
- h->h_ent = ev->num;
- break;
-
- case H_APPEND:
- str = va_arg(va, const char *);
- if ((retval = HSET(h, ev, h->h_ent)) != -1)
- retval = HADD(h, ev, str);
- break;
-
- case H_FIRST:
- retval = HFIRST(h, ev);
- break;
-
- case H_NEXT:
- retval = HNEXT(h, ev);
- break;
-
- case H_LAST:
- retval = HLAST(h, ev);
- break;
-
- case H_PREV:
- retval = HPREV(h, ev);
- break;
-
- case H_CURR:
- retval = HCURR(h, ev);
- break;
-
- case H_SET:
- retval = HSET(h, ev, va_arg(va, const int));
- break;
-
- case H_CLEAR:
- HCLEAR(h, ev);
- retval = 0;
- break;
-
- case H_LOAD:
- retval = history_load(h, va_arg(va, const char *));
- if (retval == -1)
- he_seterrev(ev, _HE_HIST_READ);
- break;
-
- case H_SAVE:
- retval = history_save(h, va_arg(va, const char *));
- if (retval == -1)
- he_seterrev(ev, _HE_HIST_WRITE);
- break;
-
- case H_PREV_EVENT:
- retval = history_prev_event(h, ev, va_arg(va, int));
- break;
-
- case H_NEXT_EVENT:
- retval = history_next_event(h, ev, va_arg(va, int));
- break;
-
- case H_PREV_STR:
- retval = history_prev_string(h, ev, va_arg(va, const char *));
- break;
-
- case H_NEXT_STR:
- retval = history_next_string(h, ev, va_arg(va, const char *));
- break;
-
- case H_FUNC:
- {
- History hf;
-
- hf.h_ref = va_arg(va, ptr_t);
- h->h_ent = -1;
- hf.h_first = va_arg(va, history_gfun_t);
- hf.h_next = va_arg(va, history_gfun_t);
- hf.h_last = va_arg(va, history_gfun_t);
- hf.h_prev = va_arg(va, history_gfun_t);
- hf.h_curr = va_arg(va, history_gfun_t);
- hf.h_set = va_arg(va, history_sfun_t);
- hf.h_clear = va_arg(va, history_vfun_t);
- hf.h_enter = va_arg(va, history_efun_t);
- hf.h_add = va_arg(va, history_efun_t);
-
- if ((retval = history_set_fun(h, &hf)) == -1)
- he_seterrev(ev, _HE_PARAM_MISSING);
- break;
- }
-
- case H_END:
- history_end(h);
- retval = 0;
- break;
-
- default:
- retval = -1;
- he_seterrev(ev, _HE_UNKNOWN);
- break;
- }
- va_end(va);
- return (retval);
-}
diff --git a/1.2-netsec/editline/install-sh b/1.2-netsec/editline/install-sh
deleted file mode 100755
index ebc66913e..000000000
--- a/1.2-netsec/editline/install-sh
+++ /dev/null
@@ -1,250 +0,0 @@
-#! /bin/sh
-#
-# install - install a program, script, or datafile
-# This comes from X11R5 (mit/util/scripts/install.sh).
-#
-# Copyright 1991 by the Massachusetts Institute of Technology
-#
-# Permission to use, copy, modify, distribute, and sell this software and its
-# documentation for any purpose is hereby granted without fee, provided that
-# the above copyright notice appear in all copies and that both that
-# copyright notice and this permission notice appear in supporting
-# documentation, and that the name of M.I.T. not be used in advertising or
-# publicity pertaining to distribution of the software without specific,
-# written prior permission. M.I.T. makes no representations about the
-# suitability of this software for any purpose. It is provided "as is"
-# without express or implied warranty.
-#
-# Calling this script install-sh is preferred over install.sh, to prevent
-# `make' implicit rules from creating a file called install from it
-# when there is no Makefile.
-#
-# This script is compatible with the BSD install script, but was written
-# from scratch. It can only install one file at a time, a restriction
-# shared with many OS's install programs.
-
-
-# set DOITPROG to echo to test this script
-
-# Don't use :- since 4.3BSD and earlier shells don't like it.
-doit="${DOITPROG-}"
-
-
-# put in absolute paths if you don't have them in your path; or use env. vars.
-
-mvprog="${MVPROG-mv}"
-cpprog="${CPPROG-cp}"
-chmodprog="${CHMODPROG-chmod}"
-chownprog="${CHOWNPROG-chown}"
-chgrpprog="${CHGRPPROG-chgrp}"
-stripprog="${STRIPPROG-strip}"
-rmprog="${RMPROG-rm}"
-mkdirprog="${MKDIRPROG-mkdir}"
-
-transformbasename=""
-transform_arg=""
-instcmd="$mvprog"
-chmodcmd="$chmodprog 0755"
-chowncmd=""
-chgrpcmd=""
-stripcmd=""
-rmcmd="$rmprog -f"
-mvcmd="$mvprog"
-src=""
-dst=""
-dir_arg=""
-
-while [ x"$1" != x ]; do
- case $1 in
- -c) instcmd="$cpprog"
- shift
- continue;;
-
- -d) dir_arg=true
- shift
- continue;;
-
- -m) chmodcmd="$chmodprog $2"
- shift
- shift
- continue;;
-
- -o) chowncmd="$chownprog $2"
- shift
- shift
- continue;;
-
- -g) chgrpcmd="$chgrpprog $2"
- shift
- shift
- continue;;
-
- -s) stripcmd="$stripprog"
- shift
- continue;;
-
- -t=*) transformarg=`echo $1 | sed 's/-t=//'`
- shift
- continue;;
-
- -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
- shift
- continue;;
-
- *) if [ x"$src" = x ]
- then
- src=$1
- else
- # this colon is to work around a 386BSD /bin/sh bug
- :
- dst=$1
- fi
- shift
- continue;;
- esac
-done
-
-if [ x"$src" = x ]
-then
- echo "install: no input file specified"
- exit 1
-else
- true
-fi
-
-if [ x"$dir_arg" != x ]; then
- dst=$src
- src=""
-
- if [ -d $dst ]; then
- instcmd=:
- else
- instcmd=mkdir
- fi
-else
-
-# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-# might cause directories to be created, which would be especially bad
-# if $src (and thus $dsttmp) contains '*'.
-
- if [ -f $src -o -d $src ]
- then
- true
- else
- echo "install: $src does not exist"
- exit 1
- fi
-
- if [ x"$dst" = x ]
- then
- echo "install: no destination specified"
- exit 1
- else
- true
- fi
-
-# If destination is a directory, append the input filename; if your system
-# does not like double slashes in filenames, you may need to add some logic
-
- if [ -d $dst ]
- then
- dst="$dst"/`basename $src`
- else
- true
- fi
-fi
-
-## this sed command emulates the dirname command
-dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-# Make sure that the destination directory exists.
-# this part is taken from Noah Friedman's mkinstalldirs script
-
-# Skip lots of stat calls in the usual case.
-if [ ! -d "$dstdir" ]; then
-defaultIFS='
-'
-IFS="${IFS-${defaultIFS}}"
-
-oIFS="${IFS}"
-# Some sh's can't handle IFS=/ for some reason.
-IFS='%'
-set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
-IFS="${oIFS}"
-
-pathcomp=''
-
-while [ $# -ne 0 ] ; do
- pathcomp="${pathcomp}${1}"
- shift
-
- if [ ! -d "${pathcomp}" ] ;
- then
- $mkdirprog "${pathcomp}"
- else
- true
- fi
-
- pathcomp="${pathcomp}/"
-done
-fi
-
-if [ x"$dir_arg" != x ]
-then
- $doit $instcmd $dst &&
-
- if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
- if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
- if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
- if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
-else
-
-# If we're going to rename the final executable, determine the name now.
-
- if [ x"$transformarg" = x ]
- then
- dstfile=`basename $dst`
- else
- dstfile=`basename $dst $transformbasename |
- sed $transformarg`$transformbasename
- fi
-
-# don't allow the sed command to completely eliminate the filename
-
- if [ x"$dstfile" = x ]
- then
- dstfile=`basename $dst`
- else
- true
- fi
-
-# Make a temp file name in the proper directory.
-
- dsttmp=$dstdir/#inst.$$#
-
-# Move or copy the file name to the temp name
-
- $doit $instcmd $src $dsttmp &&
-
- trap "rm -f ${dsttmp}" 0 &&
-
-# and set any options; do chmod last to preserve setuid bits
-
-# If any of these fail, we abort the whole thing. If we want to
-# ignore errors from any of these, just make sure not to ignore
-# errors from the above "$doit $instcmd $src $dsttmp" command.
-
- if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
- if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
- if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
- if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
-
-# Now rename the file to the real destination.
-
- $doit $rmcmd -f $dstdir/$dstfile &&
- $doit $mvcmd $dsttmp $dstdir/$dstfile
-
-fi &&
-
-
-exit 0
diff --git a/1.2-netsec/editline/key.c b/1.2-netsec/editline/key.c
deleted file mode 100644
index 0dcdf4191..000000000
--- a/1.2-netsec/editline/key.c
+++ /dev/null
@@ -1,687 +0,0 @@
-/* $NetBSD: key.c,v 1.13 2002/03/18 16:00:55 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: key.c,v 1.13 2002/03/18 16:00:55 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * key.c: This module contains the procedures for maintaining
- * the extended-key map.
- *
- * An extended-key (key) is a sequence of keystrokes introduced
- * with an sequence introducer and consisting of an arbitrary
- * number of characters. This module maintains a map (the el->el_key.map)
- * to convert these extended-key sequences into input strs
- * (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
- *
- * Warning:
- * If key is a substr of some other keys, then the longer
- * keys are lost!! That is, if the keys "abcd" and "abcef"
- * are in el->el_key.map, adding the key "abc" will cause the first two
- * definitions to be lost.
- *
- * Restrictions:
- * -------------
- * 1) It is not possible to have one key that is a
- * substr of another.
- */
-#include <string.h>
-#include <stdlib.h>
-
-#include "el.h"
-
-/*
- * The Nodes of the el->el_key.map. The el->el_key.map is a linked list
- * of these node elements
- */
-struct key_node_t {
- char ch; /* single character of key */
- int type; /* node type */
- key_value_t val; /* command code or pointer to str, */
- /* if this is a leaf */
- struct key_node_t *next; /* ptr to next char of this key */
- struct key_node_t *sibling; /* ptr to another key with same prefix*/
-};
-
-private int node_trav(EditLine *, key_node_t *, char *,
- key_value_t *);
-private int node__try(EditLine *, key_node_t *, const char *,
- key_value_t *, int);
-private key_node_t *node__get(int);
-private void node__put(EditLine *, key_node_t *);
-private int node__delete(EditLine *, key_node_t **, const char *);
-private int node_lookup(EditLine *, const char *, key_node_t *,
- int);
-private int node_enum(EditLine *, key_node_t *, int);
-private int key__decode_char(char *, int, int);
-
-#define KEY_BUFSIZ EL_BUFSIZ
-
-
-/* key_init():
- * Initialize the key maps
- */
-protected int
-key_init(EditLine *el)
-{
-
- el->el_key.buf = (char *) el_malloc(KEY_BUFSIZ);
- if (el->el_key.buf == NULL)
- return (-1);
- el->el_key.map = NULL;
- key_reset(el);
- return (0);
-}
-
-
-/* key_end():
- * Free the key maps
- */
-protected void
-key_end(EditLine *el)
-{
-
- el_free((ptr_t) el->el_key.buf);
- el->el_key.buf = NULL;
- node__put(el, el->el_key.map);
- el->el_key.map = NULL;
-}
-
-
-/* key_map_cmd():
- * Associate cmd with a key value
- */
-protected key_value_t *
-key_map_cmd(EditLine *el, int cmd)
-{
-
- el->el_key.val.cmd = (el_action_t) cmd;
- return (&el->el_key.val);
-}
-
-
-/* key_map_str():
- * Associate str with a key value
- */
-protected key_value_t *
-key_map_str(EditLine *el, char *str)
-{
-
- el->el_key.val.str = str;
- return (&el->el_key.val);
-}
-
-
-/* key_reset():
- * Takes all nodes on el->el_key.map and puts them on free list. Then
- * initializes el->el_key.map with arrow keys
- * [Always bind the ansi arrow keys?]
- */
-protected void
-key_reset(EditLine *el)
-{
-
- node__put(el, el->el_key.map);
- el->el_key.map = NULL;
- return;
-}
-
-
-/* key_get():
- * Calls the recursive function with entry point el->el_key.map
- * Looks up *ch in map and then reads characters until a
- * complete match is found or a mismatch occurs. Returns the
- * type of the match found (XK_STR, XK_CMD, or XK_EXE).
- * Returns NULL in val.str and XK_STR for no match.
- * The last character read is returned in *ch.
- */
-protected int
-key_get(EditLine *el, char *ch, key_value_t *val)
-{
-
- return (node_trav(el, el->el_key.map, ch, val));
-}
-
-
-/* key_add():
- * Adds key to the el->el_key.map and associates the value in val with it.
- * If key is already is in el->el_key.map, the new code is applied to the
- * existing key. Ntype specifies if code is a command, an
- * out str or a unix command.
- */
-protected void
-key_add(EditLine *el, const char *key, key_value_t *val, int ntype)
-{
-
- if (key[0] == '\0') {
- (void) fprintf(el->el_errfile,
- "key_add: Null extended-key not allowed.\n");
- return;
- }
- if (ntype == XK_CMD && val->cmd == ED_SEQUENCE_LEAD_IN) {
- (void) fprintf(el->el_errfile,
- "key_add: sequence-lead-in command not allowed\n");
- return;
- }
- if (el->el_key.map == NULL)
- /* tree is initially empty. Set up new node to match key[0] */
- el->el_key.map = node__get(key[0]);
- /* it is properly initialized */
-
- /* Now recurse through el->el_key.map */
- (void) node__try(el, el->el_key.map, key, val, ntype);
- return;
-}
-
-
-/* key_clear():
- *
- */
-protected void
-key_clear(EditLine *el, el_action_t *map, const char *in)
-{
-
- if ((map[(unsigned char)*in] == ED_SEQUENCE_LEAD_IN) &&
- ((map == el->el_map.key &&
- el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) ||
- (map == el->el_map.alt &&
- el->el_map.key[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN)))
- (void) key_delete(el, in);
-}
-
-
-/* key_delete():
- * Delete the key and all longer keys staring with key, if
- * they exists.
- */
-protected int
-key_delete(EditLine *el, const char *key)
-{
-
- if (key[0] == '\0') {
- (void) fprintf(el->el_errfile,
- "key_delete: Null extended-key not allowed.\n");
- return (-1);
- }
- if (el->el_key.map == NULL)
- return (0);
-
- (void) node__delete(el, &el->el_key.map, key);
- return (0);
-}
-
-
-/* key_print():
- * Print the binding associated with key key.
- * Print entire el->el_key.map if null
- */
-protected void
-key_print(EditLine *el, const char *key)
-{
-
- /* do nothing if el->el_key.map is empty and null key specified */
- if (el->el_key.map == NULL && *key == 0)
- return;
-
- el->el_key.buf[0] = '"';
- if (node_lookup(el, key, el->el_key.map, 1) <= -1)
- /* key is not bound */
- (void) fprintf(el->el_errfile, "Unbound extended key \"%s\"\n",
- key);
- return;
-}
-
-
-/* node_trav():
- * recursively traverses node in tree until match or mismatch is
- * found. May read in more characters.
- */
-private int
-node_trav(EditLine *el, key_node_t *ptr, char *ch, key_value_t *val)
-{
-
- if (ptr->ch == *ch) {
- /* match found */
- if (ptr->next) {
- /* key not complete so get next char */
- if (el_getc(el, ch) != 1) { /* if EOF or error */
- val->cmd = ED_END_OF_FILE;
- return (XK_CMD);
- /* PWP: Pretend we just read an end-of-file */
- }
- return (node_trav(el, ptr->next, ch, val));
- } else {
- *val = ptr->val;
- if (ptr->type != XK_CMD)
- *ch = '\0';
- return (ptr->type);
- }
- } else {
- /* no match found here */
- if (ptr->sibling) {
- /* try next sibling */
- return (node_trav(el, ptr->sibling, ch, val));
- } else {
- /* no next sibling -- mismatch */
- val->str = NULL;
- return (XK_STR);
- }
- }
-}
-
-
-/* node__try():
- * Find a node that matches *str or allocate a new one
- */
-private int
-node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int ntype)
-{
-
- if (ptr->ch != *str) {
- key_node_t *xm;
-
- for (xm = ptr; xm->sibling != NULL; xm = xm->sibling)
- if (xm->sibling->ch == *str)
- break;
- if (xm->sibling == NULL)
- xm->sibling = node__get(*str); /* setup new node */
- ptr = xm->sibling;
- }
- if (*++str == '\0') {
- /* we're there */
- if (ptr->next != NULL) {
- node__put(el, ptr->next);
- /* lose longer keys with this prefix */
- ptr->next = NULL;
- }
- switch (ptr->type) {
- case XK_CMD:
- case XK_NOD:
- break;
- case XK_STR:
- case XK_EXE:
- if (ptr->val.str)
- el_free((ptr_t) ptr->val.str);
- break;
- default:
- EL_ABORT((el->el_errfile, "Bad XK_ type %d\n",
- ptr->type));
- break;
- }
-
- switch (ptr->type = ntype) {
- case XK_CMD:
- ptr->val = *val;
- break;
- case XK_STR:
- case XK_EXE:
- ptr->val.str = strdup(val->str);
- break;
- default:
- EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
- break;
- }
- } else {
- /* still more chars to go */
- if (ptr->next == NULL)
- ptr->next = node__get(*str); /* setup new node */
- (void) node__try(el, ptr->next, str, val, ntype);
- }
- return (0);
-}
-
-
-/* node__delete():
- * Delete node that matches str
- */
-private int
-node__delete(EditLine *el, key_node_t **inptr, const char *str)
-{
- key_node_t *ptr;
- key_node_t *prev_ptr = NULL;
-
- ptr = *inptr;
-
- if (ptr->ch != *str) {
- key_node_t *xm;
-
- for (xm = ptr; xm->sibling != NULL; xm = xm->sibling)
- if (xm->sibling->ch == *str)
- break;
- if (xm->sibling == NULL)
- return (0);
- prev_ptr = xm;
- ptr = xm->sibling;
- }
- if (*++str == '\0') {
- /* we're there */
- if (prev_ptr == NULL)
- *inptr = ptr->sibling;
- else
- prev_ptr->sibling = ptr->sibling;
- ptr->sibling = NULL;
- node__put(el, ptr);
- return (1);
- } else if (ptr->next != NULL &&
- node__delete(el, &ptr->next, str) == 1) {
- if (ptr->next != NULL)
- return (0);
- if (prev_ptr == NULL)
- *inptr = ptr->sibling;
- else
- prev_ptr->sibling = ptr->sibling;
- ptr->sibling = NULL;
- node__put(el, ptr);
- return (1);
- } else {
- return (0);
- }
-}
-
-
-/* node__put():
- * Puts a tree of nodes onto free list using free(3).
- */
-private void
-node__put(EditLine *el, key_node_t *ptr)
-{
- if (ptr == NULL)
- return;
-
- if (ptr->next != NULL) {
- node__put(el, ptr->next);
- ptr->next = NULL;
- }
- node__put(el, ptr->sibling);
-
- switch (ptr->type) {
- case XK_CMD:
- case XK_NOD:
- break;
- case XK_EXE:
- case XK_STR:
- if (ptr->val.str != NULL)
- el_free((ptr_t) ptr->val.str);
- break;
- default:
- EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ptr->type));
- break;
- }
- el_free((ptr_t) ptr);
-}
-
-
-/* node__get():
- * Returns pointer to an key_node_t for ch.
- */
-private key_node_t *
-node__get(int ch)
-{
- key_node_t *ptr;
-
- ptr = (key_node_t *) el_malloc((size_t) sizeof(key_node_t));
- if (ptr == NULL)
- return NULL;
- ptr->ch = ch;
- ptr->type = XK_NOD;
- ptr->val.str = NULL;
- ptr->next = NULL;
- ptr->sibling = NULL;
- return (ptr);
-}
-
-
-
-/* node_lookup():
- * look for the str starting at node ptr.
- * Print if last node
- */
-private int
-node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt)
-{
- int ncnt;
-
- if (ptr == NULL)
- return (-1); /* cannot have null ptr */
-
- if (*str == 0) {
- /* no more chars in str. node_enum from here. */
- (void) node_enum(el, ptr, cnt);
- return (0);
- } else {
- /* If match put this char into el->el_key.buf. Recurse */
- if (ptr->ch == *str) {
- /* match found */
- ncnt = key__decode_char(el->el_key.buf, cnt,
- (unsigned char) ptr->ch);
- if (ptr->next != NULL)
- /* not yet at leaf */
- return (node_lookup(el, str + 1, ptr->next,
- ncnt + 1));
- else {
- /* next node is null so key should be complete */
- if (str[1] == 0) {
- el->el_key.buf[ncnt + 1] = '"';
- el->el_key.buf[ncnt + 2] = '\0';
- key_kprint(el, el->el_key.buf,
- &ptr->val, ptr->type);
- return (0);
- } else
- return (-1);
- /* mismatch -- str still has chars */
- }
- } else {
- /* no match found try sibling */
- if (ptr->sibling)
- return (node_lookup(el, str, ptr->sibling,
- cnt));
- else
- return (-1);
- }
- }
-}
-
-
-/* node_enum():
- * Traverse the node printing the characters it is bound in buffer
- */
-private int
-node_enum(EditLine *el, key_node_t *ptr, int cnt)
-{
- int ncnt;
-
- if (cnt >= KEY_BUFSIZ - 5) { /* buffer too small */
- el->el_key.buf[++cnt] = '"';
- el->el_key.buf[++cnt] = '\0';
- (void) fprintf(el->el_errfile,
- "Some extended keys too long for internal print buffer");
- (void) fprintf(el->el_errfile, " \"%s...\"\n", el->el_key.buf);
- return (0);
- }
- if (ptr == NULL) {
-#ifdef DEBUG_EDIT
- (void) fprintf(el->el_errfile,
- "node_enum: BUG!! Null ptr passed\n!");
-#endif
- return (-1);
- }
- /* put this char at end of str */
- ncnt = key__decode_char(el->el_key.buf, cnt, (unsigned char) ptr->ch);
- if (ptr->next == NULL) {
- /* print this key and function */
- el->el_key.buf[ncnt + 1] = '"';
- el->el_key.buf[ncnt + 2] = '\0';
- key_kprint(el, el->el_key.buf, &ptr->val, ptr->type);
- } else
- (void) node_enum(el, ptr->next, ncnt + 1);
-
- /* go to sibling if there is one */
- if (ptr->sibling)
- (void) node_enum(el, ptr->sibling, cnt);
- return (0);
-}
-
-
-/* key_kprint():
- * Print the specified key and its associated
- * function specified by val
- */
-protected void
-key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
-{
- el_bindings_t *fp;
- char unparsbuf[EL_BUFSIZ];
- static const char fmt[] = "%-15s-> %s\n";
-
- if (val != NULL)
- switch (ntype) {
- case XK_STR:
- case XK_EXE:
- (void) fprintf(el->el_outfile, fmt, key,
- key__decode_str(val->str, unparsbuf,
- ntype == XK_STR ? "\"\"" : "[]"));
- break;
- case XK_CMD:
- for (fp = el->el_map.help; fp->name; fp++)
- if (val->cmd == fp->func) {
- (void) fprintf(el->el_outfile, fmt,
- key, fp->name);
- break;
- }
-#ifdef DEBUG_KEY
- if (fp->name == NULL)
- (void) fprintf(el->el_outfile,
- "BUG! Command not found.\n");
-#endif
-
- break;
- default:
- EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
- break;
- }
- else
- (void) fprintf(el->el_outfile, fmt, key, "no input");
-}
-
-
-/* key__decode_char():
- * Put a printable form of char in buf.
- */
-private int
-key__decode_char(char *buf, int cnt, int ch)
-{
- if (ch == 0) {
- buf[cnt++] = '^';
- buf[cnt] = '@';
- return (cnt);
- }
- if (iscntrl(ch)) {
- buf[cnt++] = '^';
- if (ch == '\177')
- buf[cnt] = '?';
- else
- buf[cnt] = ch | 0100;
- } else if (ch == '^') {
- buf[cnt++] = '\\';
- buf[cnt] = '^';
- } else if (ch == '\\') {
- buf[cnt++] = '\\';
- buf[cnt] = '\\';
- } else if (ch == ' ' || (isprint(ch) && !isspace(ch))) {
- buf[cnt] = ch;
- } else {
- buf[cnt++] = '\\';
- buf[cnt++] = (((unsigned int) ch >> 6) & 7) + '0';
- buf[cnt++] = (((unsigned int) ch >> 3) & 7) + '0';
- buf[cnt] = (ch & 7) + '0';
- }
- return (cnt);
-}
-
-
-/* key__decode_str():
- * Make a printable version of the ey
- */
-protected char *
-key__decode_str(const char *str, char *buf, const char *sep)
-{
- char *b;
- const char *p;
-
- b = buf;
- if (sep[0] != '\0')
- *b++ = sep[0];
- if (*str == 0) {
- *b++ = '^';
- *b++ = '@';
- if (sep[0] != '\0' && sep[1] != '\0')
- *b++ = sep[1];
- *b++ = 0;
- return (buf);
- }
- for (p = str; *p != 0; p++) {
- if (iscntrl((unsigned char) *p)) {
- *b++ = '^';
- if (*p == '\177')
- *b++ = '?';
- else
- *b++ = *p | 0100;
- } else if (*p == '^' || *p == '\\') {
- *b++ = '\\';
- *b++ = *p;
- } else if (*p == ' ' || (isprint((unsigned char) *p) &&
- !isspace((unsigned char) *p))) {
- *b++ = *p;
- } else {
- *b++ = '\\';
- *b++ = (((unsigned int) *p >> 6) & 7) + '0';
- *b++ = (((unsigned int) *p >> 3) & 7) + '0';
- *b++ = (*p & 7) + '0';
- }
- }
- if (sep[0] != '\0' && sep[1] != '\0')
- *b++ = sep[1];
- *b++ = 0;
- return (buf); /* should check for overflow */
-}
diff --git a/1.2-netsec/editline/key.h b/1.2-netsec/editline/key.h
deleted file mode 100644
index 80d8626b8..000000000
--- a/1.2-netsec/editline/key.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* $NetBSD: key.h,v 1.6 2002/03/18 16:00:55 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)key.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.key.h: Key macro header
- */
-#ifndef _h_el_key
-#define _h_el_key
-
-typedef union key_value_t {
- el_action_t cmd; /* If it is a command the # */
- char *str; /* If it is a string... */
-} key_value_t;
-
-typedef struct key_node_t key_node_t;
-
-typedef struct el_key_t {
- char *buf; /* Key print buffer */
- key_node_t *map; /* Key map */
- key_value_t val; /* Local conversion buffer */
-} el_key_t;
-
-#define XK_CMD 0
-#define XK_STR 1
-#define XK_NOD 2
-#define XK_EXE 3
-
-protected int key_init(EditLine *);
-protected void key_end(EditLine *);
-protected key_value_t *key_map_cmd(EditLine *, int);
-protected key_value_t *key_map_str(EditLine *, char *);
-protected void key_reset(EditLine *);
-protected int key_get(EditLine *, char *, key_value_t *);
-protected void key_add(EditLine *, const char *, key_value_t *, int);
-protected void key_clear(EditLine *, el_action_t *, const char *);
-protected int key_delete(EditLine *, const char *);
-protected void key_print(EditLine *, const char *);
-protected void key_kprint(EditLine *, const char *, key_value_t *,
- int);
-protected char *key__decode_str(const char *, char *, const char *);
-
-#endif /* _h_el_key */
diff --git a/1.2-netsec/editline/makelist b/1.2-netsec/editline/makelist
deleted file mode 100644
index 8e9835309..000000000
--- a/1.2-netsec/editline/makelist
+++ /dev/null
@@ -1,254 +0,0 @@
-#!/bin/sh -
-# $NetBSD: makelist,v 1.7 2001/01/09 19:22:31 jdolecek Exp $
-#
-# Copyright (c) 1992, 1993
-# The Regents of the University of California. All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Christos Zoulas of Cornell University.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the University of
-# California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# @(#)makelist 5.3 (Berkeley) 6/4/93
-
-# makelist.sh: Automatically generate header files...
-
-AWK=/usr/bin/awk
-USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
-
-if [ "x$1" = "x" ]
-then
- echo $USAGE 1>&2
- exit 1
-fi
-
-FLAG="$1"
-shift
-
-FILES="$@"
-
-case $FLAG in
-
-# generate foo.h file from foo.c
-#
--h)
- set - `echo $FILES | sed -e 's/\\./_/g'`
- hdr="_h_`basename $1`"
- cat $FILES | $AWK '
- BEGIN {
- printf("/* Automatically generated file, do not edit */\n");
- printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
- }
- /\(\):/ {
- pr = substr($2, 1, 2);
- if (pr == "vi" || pr == "em" || pr == "ed") {
- name = substr($2, 1, length($2) - 3);
-#
-# XXX: need a space between name and prototype so that -fc and -fh
-# parsing is much easier
-#
- printf("protected el_action_t\t%s (EditLine *, int);\n", name);
- }
- }
- END {
- printf("#endif /* %s */\n", "'$hdr'");
- }'
- ;;
-
-# generate help.c from various .c files
-#
--bc)
- cat $FILES | $AWK '
- BEGIN {
- printf("/* Automatically generated file, do not edit */\n");
- printf("#include \"sys.h\"\n#include \"el.h\"\n");
- printf("private const struct el_bindings_t el_func_help[] = {\n");
- low = "abcdefghijklmnopqrstuvwxyz_";
- high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
- for (i = 1; i <= length(low); i++)
- tr[substr(low, i, 1)] = substr(high, i, 1);
- }
- /\(\):/ {
- pr = substr($2, 1, 2);
- if (pr == "vi" || pr == "em" || pr == "ed") {
- name = substr($2, 1, length($2) - 3);
- uname = "";
- fname = "";
- for (i = 1; i <= length(name); i++) {
- s = substr(name, i, 1);
- uname = uname tr[s];
- if (s == "_")
- s = "-";
- fname = fname s;
- }
-
- printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
- ok = 1;
- }
- }
- /^ \*/ {
- if (ok) {
- printf(" \"");
- for (i = 2; i < NF; i++)
- printf("%s ", $i);
- printf("%s\" },\n", $i);
- ok = 0;
- }
- }
- END {
- printf(" { NULL, 0, NULL }\n");
- printf("};\n");
- printf("\nprotected const el_bindings_t* help__get()");
- printf("{ return el_func_help; }\n");
- }'
- ;;
-
-# generate help.h from various .c files
-#
--bh)
- $AWK '
- BEGIN {
- printf("/* Automatically generated file, do not edit */\n");
- printf("#ifndef _h_help_c\n#define _h_help_c\n");
- printf("protected const el_bindings_t *help__get(void);\n");
- printf("#endif /* _h_help_c */\n");
- }' /dev/null
- ;;
-
-# generate fcns.h from various .h files
-#
--fh)
- cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
- sort | tr '[a-z]' '[A-Z]' | $AWK '
- BEGIN {
- printf("/* Automatically generated file, do not edit */\n");
- printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
- count = 0;
- }
- {
- printf("#define\t%-30.30s\t%3d\n", $1, count++);
- }
- END {
- printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
-
- printf("typedef el_action_t (*el_func_t)(EditLine *, int);");
- printf("\nprotected const el_func_t* func__get(void);\n");
- printf("#endif /* _h_fcns_c */\n");
- }'
- ;;
-
-# generate fcns.c from various .h files
-#
--fc)
- cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
- BEGIN {
- printf("/* Automatically generated file, do not edit */\n");
- printf("#include \"sys.h\"\n#include \"el.h\"\n");
- printf("private const el_func_t el_func[] = {");
- maxlen = 80;
- needn = 1;
- len = 0;
- }
- {
- clen = 25 + 2;
- len += clen;
- if (len >= maxlen)
- needn = 1;
- if (needn) {
- printf("\n ");
- needn = 0;
- len = 4 + clen;
- }
- s = $1 ",";
- printf("%-26.26s ", s);
- }
- END {
- printf("\n};\n");
- printf("\nprotected const el_func_t* func__get() { return el_func; }\n");
- }'
- ;;
-
-# generate editline.c from various .c files
-#
--e)
- echo "$FILES" | tr ' ' '\012' | $AWK '
- BEGIN {
- printf("/* Automatically generated file, do not edit */\n");
- printf("#define protected static\n");
- printf("#define SCCSID\n");
- }
- {
- printf("#include \"%s\"\n", $1);
- }'
- ;;
-
-# generate man page fragment from various .c files
-#
--m)
- cat $FILES | $AWK '
- BEGIN {
- printf(".\\\" Section automatically generated with makelist\n");
- printf(".Bl -tag -width 4n\n");
- }
- /\(\):/ {
- pr = substr($2, 1, 2);
- if (pr == "vi" || pr == "em" || pr == "ed") {
- name = substr($2, 1, length($2) - 3);
- fname = "";
- for (i = 1; i <= length(name); i++) {
- s = substr(name, i, 1);
- if (s == "_")
- s = "-";
- fname = fname s;
- }
-
- printf(".It Ic %s\n", fname);
- ok = 1;
- }
- }
- /^ \*/ {
- if (ok) {
- for (i = 2; i < NF; i++)
- printf("%s ", $i);
- printf("%s.\n", $i);
- ok = 0;
- }
- }
- END {
- printf(".El\n");
- printf(".\\\" End of section automatically generated with makelist\n");
- }'
- ;;
-
-*)
- echo $USAGE 1>&2
- exit 1
- ;;
-
-esac
diff --git a/1.2-netsec/editline/map.c b/1.2-netsec/editline/map.c
deleted file mode 100644
index 4187cb597..000000000
--- a/1.2-netsec/editline/map.c
+++ /dev/null
@@ -1,1418 +0,0 @@
-/* $NetBSD: map.c,v 1.15 2002/03/18 16:00:55 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: map.c,v 1.15 2002/03/18 16:00:55 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * map.c: Editor function definitions
- */
-#include <stdlib.h>
-#include "el.h"
-
-#define N_KEYS 256
-
-private void map_print_key(EditLine *, el_action_t *, const char *);
-private void map_print_some_keys(EditLine *, el_action_t *, int, int);
-private void map_print_all_keys(EditLine *);
-private void map_init_nls(EditLine *);
-private void map_init_meta(EditLine *);
-
-/* keymap tables ; should be N_KEYS*sizeof(KEYCMD) bytes long */
-
-
-private const el_action_t el_map_emacs[] = {
- /* 0 */ EM_SET_MARK, /* ^@ */
- /* 1 */ ED_MOVE_TO_BEG, /* ^A */
- /* 2 */ ED_PREV_CHAR, /* ^B */
- /* 3 */ ED_TTY_SIGINT, /* ^C */
- /* 4 */ EM_DELETE_OR_LIST, /* ^D */
- /* 5 */ ED_MOVE_TO_END, /* ^E */
- /* 6 */ ED_NEXT_CHAR, /* ^F */
- /* 7 */ ED_UNASSIGNED, /* ^G */
- /* 8 */ ED_DELETE_PREV_CHAR, /* ^H */
- /* 9 */ ED_UNASSIGNED, /* ^I */
- /* 10 */ ED_NEWLINE, /* ^J */
- /* 11 */ ED_KILL_LINE, /* ^K */
- /* 12 */ ED_CLEAR_SCREEN, /* ^L */
- /* 13 */ ED_NEWLINE, /* ^M */
- /* 14 */ ED_NEXT_HISTORY, /* ^N */
- /* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */
- /* 16 */ ED_PREV_HISTORY, /* ^P */
- /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
- /* 18 */ ED_REDISPLAY, /* ^R */
- /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
- /* 20 */ ED_TRANSPOSE_CHARS, /* ^T */
- /* 21 */ EM_KILL_LINE, /* ^U */
- /* 22 */ ED_QUOTED_INSERT, /* ^V */
- /* 23 */ EM_KILL_REGION, /* ^W */
- /* 24 */ ED_SEQUENCE_LEAD_IN, /* ^X */
- /* 25 */ EM_YANK, /* ^Y */
- /* 26 */ ED_TTY_SIGTSTP, /* ^Z */
- /* 27 */ EM_META_NEXT, /* ^[ */
- /* 28 */ ED_TTY_SIGQUIT, /* ^\ */
- /* 29 */ ED_TTY_DSUSP, /* ^] */
- /* 30 */ ED_UNASSIGNED, /* ^^ */
- /* 31 */ ED_UNASSIGNED, /* ^_ */
- /* 32 */ ED_INSERT, /* SPACE */
- /* 33 */ ED_INSERT, /* ! */
- /* 34 */ ED_INSERT, /* " */
- /* 35 */ ED_INSERT, /* # */
- /* 36 */ ED_INSERT, /* $ */
- /* 37 */ ED_INSERT, /* % */
- /* 38 */ ED_INSERT, /* & */
- /* 39 */ ED_INSERT, /* ' */
- /* 40 */ ED_INSERT, /* ( */
- /* 41 */ ED_INSERT, /* ) */
- /* 42 */ ED_INSERT, /* * */
- /* 43 */ ED_INSERT, /* + */
- /* 44 */ ED_INSERT, /* , */
- /* 45 */ ED_INSERT, /* - */
- /* 46 */ ED_INSERT, /* . */
- /* 47 */ ED_INSERT, /* / */
- /* 48 */ ED_DIGIT, /* 0 */
- /* 49 */ ED_DIGIT, /* 1 */
- /* 50 */ ED_DIGIT, /* 2 */
- /* 51 */ ED_DIGIT, /* 3 */
- /* 52 */ ED_DIGIT, /* 4 */
- /* 53 */ ED_DIGIT, /* 5 */
- /* 54 */ ED_DIGIT, /* 6 */
- /* 55 */ ED_DIGIT, /* 7 */
- /* 56 */ ED_DIGIT, /* 8 */
- /* 57 */ ED_DIGIT, /* 9 */
- /* 58 */ ED_INSERT, /* : */
- /* 59 */ ED_INSERT, /* ; */
- /* 60 */ ED_INSERT, /* < */
- /* 61 */ ED_INSERT, /* = */
- /* 62 */ ED_INSERT, /* > */
- /* 63 */ ED_INSERT, /* ? */
- /* 64 */ ED_INSERT, /* @ */
- /* 65 */ ED_INSERT, /* A */
- /* 66 */ ED_INSERT, /* B */
- /* 67 */ ED_INSERT, /* C */
- /* 68 */ ED_INSERT, /* D */
- /* 69 */ ED_INSERT, /* E */
- /* 70 */ ED_INSERT, /* F */
- /* 71 */ ED_INSERT, /* G */
- /* 72 */ ED_INSERT, /* H */
- /* 73 */ ED_INSERT, /* I */
- /* 74 */ ED_INSERT, /* J */
- /* 75 */ ED_INSERT, /* K */
- /* 76 */ ED_INSERT, /* L */
- /* 77 */ ED_INSERT, /* M */
- /* 78 */ ED_INSERT, /* N */
- /* 79 */ ED_INSERT, /* O */
- /* 80 */ ED_INSERT, /* P */
- /* 81 */ ED_INSERT, /* Q */
- /* 82 */ ED_INSERT, /* R */
- /* 83 */ ED_INSERT, /* S */
- /* 84 */ ED_INSERT, /* T */
- /* 85 */ ED_INSERT, /* U */
- /* 86 */ ED_INSERT, /* V */
- /* 87 */ ED_INSERT, /* W */
- /* 88 */ ED_INSERT, /* X */
- /* 89 */ ED_INSERT, /* Y */
- /* 90 */ ED_INSERT, /* Z */
- /* 91 */ ED_INSERT, /* [ */
- /* 92 */ ED_INSERT, /* \ */
- /* 93 */ ED_INSERT, /* ] */
- /* 94 */ ED_INSERT, /* ^ */
- /* 95 */ ED_INSERT, /* _ */
- /* 96 */ ED_INSERT, /* ` */
- /* 97 */ ED_INSERT, /* a */
- /* 98 */ ED_INSERT, /* b */
- /* 99 */ ED_INSERT, /* c */
- /* 100 */ ED_INSERT, /* d */
- /* 101 */ ED_INSERT, /* e */
- /* 102 */ ED_INSERT, /* f */
- /* 103 */ ED_INSERT, /* g */
- /* 104 */ ED_INSERT, /* h */
- /* 105 */ ED_INSERT, /* i */
- /* 106 */ ED_INSERT, /* j */
- /* 107 */ ED_INSERT, /* k */
- /* 108 */ ED_INSERT, /* l */
- /* 109 */ ED_INSERT, /* m */
- /* 110 */ ED_INSERT, /* n */
- /* 111 */ ED_INSERT, /* o */
- /* 112 */ ED_INSERT, /* p */
- /* 113 */ ED_INSERT, /* q */
- /* 114 */ ED_INSERT, /* r */
- /* 115 */ ED_INSERT, /* s */
- /* 116 */ ED_INSERT, /* t */
- /* 117 */ ED_INSERT, /* u */
- /* 118 */ ED_INSERT, /* v */
- /* 119 */ ED_INSERT, /* w */
- /* 120 */ ED_INSERT, /* x */
- /* 121 */ ED_INSERT, /* y */
- /* 122 */ ED_INSERT, /* z */
- /* 123 */ ED_INSERT, /* { */
- /* 124 */ ED_INSERT, /* | */
- /* 125 */ ED_INSERT, /* } */
- /* 126 */ ED_INSERT, /* ~ */
- /* 127 */ ED_DELETE_PREV_CHAR, /* ^? */
- /* 128 */ ED_UNASSIGNED, /* M-^@ */
- /* 129 */ ED_UNASSIGNED, /* M-^A */
- /* 130 */ ED_UNASSIGNED, /* M-^B */
- /* 131 */ ED_UNASSIGNED, /* M-^C */
- /* 132 */ ED_UNASSIGNED, /* M-^D */
- /* 133 */ ED_UNASSIGNED, /* M-^E */
- /* 134 */ ED_UNASSIGNED, /* M-^F */
- /* 135 */ ED_UNASSIGNED, /* M-^G */
- /* 136 */ ED_DELETE_PREV_WORD, /* M-^H */
- /* 137 */ ED_UNASSIGNED, /* M-^I */
- /* 138 */ ED_UNASSIGNED, /* M-^J */
- /* 139 */ ED_UNASSIGNED, /* M-^K */
- /* 140 */ ED_CLEAR_SCREEN, /* M-^L */
- /* 141 */ ED_UNASSIGNED, /* M-^M */
- /* 142 */ ED_UNASSIGNED, /* M-^N */
- /* 143 */ ED_UNASSIGNED, /* M-^O */
- /* 144 */ ED_UNASSIGNED, /* M-^P */
- /* 145 */ ED_UNASSIGNED, /* M-^Q */
- /* 146 */ ED_UNASSIGNED, /* M-^R */
- /* 147 */ ED_UNASSIGNED, /* M-^S */
- /* 148 */ ED_UNASSIGNED, /* M-^T */
- /* 149 */ ED_UNASSIGNED, /* M-^U */
- /* 150 */ ED_UNASSIGNED, /* M-^V */
- /* 151 */ ED_UNASSIGNED, /* M-^W */
- /* 152 */ ED_UNASSIGNED, /* M-^X */
- /* 153 */ ED_UNASSIGNED, /* M-^Y */
- /* 154 */ ED_UNASSIGNED, /* M-^Z */
- /* 155 */ ED_UNASSIGNED, /* M-^[ */
- /* 156 */ ED_UNASSIGNED, /* M-^\ */
- /* 157 */ ED_UNASSIGNED, /* M-^] */
- /* 158 */ ED_UNASSIGNED, /* M-^^ */
- /* 159 */ EM_COPY_PREV_WORD, /* M-^_ */
- /* 160 */ ED_UNASSIGNED, /* M-SPACE */
- /* 161 */ ED_UNASSIGNED, /* M-! */
- /* 162 */ ED_UNASSIGNED, /* M-" */
- /* 163 */ ED_UNASSIGNED, /* M-# */
- /* 164 */ ED_UNASSIGNED, /* M-$ */
- /* 165 */ ED_UNASSIGNED, /* M-% */
- /* 166 */ ED_UNASSIGNED, /* M-& */
- /* 167 */ ED_UNASSIGNED, /* M-' */
- /* 168 */ ED_UNASSIGNED, /* M-( */
- /* 169 */ ED_UNASSIGNED, /* M-) */
- /* 170 */ ED_UNASSIGNED, /* M-* */
- /* 171 */ ED_UNASSIGNED, /* M-+ */
- /* 172 */ ED_UNASSIGNED, /* M-, */
- /* 173 */ ED_UNASSIGNED, /* M-- */
- /* 174 */ ED_UNASSIGNED, /* M-. */
- /* 175 */ ED_UNASSIGNED, /* M-/ */
- /* 176 */ ED_ARGUMENT_DIGIT, /* M-0 */
- /* 177 */ ED_ARGUMENT_DIGIT, /* M-1 */
- /* 178 */ ED_ARGUMENT_DIGIT, /* M-2 */
- /* 179 */ ED_ARGUMENT_DIGIT, /* M-3 */
- /* 180 */ ED_ARGUMENT_DIGIT, /* M-4 */
- /* 181 */ ED_ARGUMENT_DIGIT, /* M-5 */
- /* 182 */ ED_ARGUMENT_DIGIT, /* M-6 */
- /* 183 */ ED_ARGUMENT_DIGIT, /* M-7 */
- /* 184 */ ED_ARGUMENT_DIGIT, /* M-8 */
- /* 185 */ ED_ARGUMENT_DIGIT, /* M-9 */
- /* 186 */ ED_UNASSIGNED, /* M-: */
- /* 187 */ ED_UNASSIGNED, /* M-; */
- /* 188 */ ED_UNASSIGNED, /* M-< */
- /* 189 */ ED_UNASSIGNED, /* M-= */
- /* 190 */ ED_UNASSIGNED, /* M-> */
- /* 191 */ ED_UNASSIGNED, /* M-? */
- /* 192 */ ED_UNASSIGNED, /* M-@ */
- /* 193 */ ED_UNASSIGNED, /* M-A */
- /* 194 */ ED_PREV_WORD, /* M-B */
- /* 195 */ EM_CAPITOL_CASE, /* M-C */
- /* 196 */ EM_DELETE_NEXT_WORD, /* M-D */
- /* 197 */ ED_UNASSIGNED, /* M-E */
- /* 198 */ EM_NEXT_WORD, /* M-F */
- /* 199 */ ED_UNASSIGNED, /* M-G */
- /* 200 */ ED_UNASSIGNED, /* M-H */
- /* 201 */ ED_UNASSIGNED, /* M-I */
- /* 202 */ ED_UNASSIGNED, /* M-J */
- /* 203 */ ED_UNASSIGNED, /* M-K */
- /* 204 */ EM_LOWER_CASE, /* M-L */
- /* 205 */ ED_UNASSIGNED, /* M-M */
- /* 206 */ ED_SEARCH_NEXT_HISTORY, /* M-N */
- /* 207 */ ED_SEQUENCE_LEAD_IN, /* M-O */
- /* 208 */ ED_SEARCH_PREV_HISTORY, /* M-P */
- /* 209 */ ED_UNASSIGNED, /* M-Q */
- /* 210 */ ED_UNASSIGNED, /* M-R */
- /* 211 */ ED_UNASSIGNED, /* M-S */
- /* 212 */ ED_UNASSIGNED, /* M-T */
- /* 213 */ EM_UPPER_CASE, /* M-U */
- /* 214 */ ED_UNASSIGNED, /* M-V */
- /* 215 */ EM_COPY_REGION, /* M-W */
- /* 216 */ ED_COMMAND, /* M-X */
- /* 217 */ ED_UNASSIGNED, /* M-Y */
- /* 218 */ ED_UNASSIGNED, /* M-Z */
- /* 219 */ ED_SEQUENCE_LEAD_IN, /* M-[ */
- /* 220 */ ED_UNASSIGNED, /* M-\ */
- /* 221 */ ED_UNASSIGNED, /* M-] */
- /* 222 */ ED_UNASSIGNED, /* M-^ */
- /* 223 */ ED_UNASSIGNED, /* M-_ */
- /* 223 */ ED_UNASSIGNED, /* M-` */
- /* 224 */ ED_UNASSIGNED, /* M-a */
- /* 225 */ ED_PREV_WORD, /* M-b */
- /* 226 */ EM_CAPITOL_CASE, /* M-c */
- /* 227 */ EM_DELETE_NEXT_WORD, /* M-d */
- /* 228 */ ED_UNASSIGNED, /* M-e */
- /* 229 */ EM_NEXT_WORD, /* M-f */
- /* 230 */ ED_UNASSIGNED, /* M-g */
- /* 231 */ ED_UNASSIGNED, /* M-h */
- /* 232 */ ED_UNASSIGNED, /* M-i */
- /* 233 */ ED_UNASSIGNED, /* M-j */
- /* 234 */ ED_UNASSIGNED, /* M-k */
- /* 235 */ EM_LOWER_CASE, /* M-l */
- /* 236 */ ED_UNASSIGNED, /* M-m */
- /* 237 */ ED_SEARCH_NEXT_HISTORY, /* M-n */
- /* 238 */ ED_UNASSIGNED, /* M-o */
- /* 239 */ ED_SEARCH_PREV_HISTORY, /* M-p */
- /* 240 */ ED_UNASSIGNED, /* M-q */
- /* 241 */ ED_UNASSIGNED, /* M-r */
- /* 242 */ ED_UNASSIGNED, /* M-s */
- /* 243 */ ED_UNASSIGNED, /* M-t */
- /* 244 */ EM_UPPER_CASE, /* M-u */
- /* 245 */ ED_UNASSIGNED, /* M-v */
- /* 246 */ EM_COPY_REGION, /* M-w */
- /* 247 */ ED_COMMAND, /* M-x */
- /* 248 */ ED_UNASSIGNED, /* M-y */
- /* 249 */ ED_UNASSIGNED, /* M-z */
- /* 250 */ ED_UNASSIGNED, /* M-{ */
- /* 251 */ ED_UNASSIGNED, /* M-| */
- /* 252 */ ED_UNASSIGNED, /* M-} */
- /* 253 */ ED_UNASSIGNED, /* M-~ */
- /* 254 */ ED_DELETE_PREV_WORD /* M-^? */
- /* 255 */
-};
-
-
-/*
- * keymap table for vi. Each index into above tbl; should be
- * N_KEYS entries long. Vi mode uses a sticky-extend to do command mode:
- * insert mode characters are in the normal keymap, and command mode
- * in the extended keymap.
- */
-private const el_action_t el_map_vi_insert[] = {
-#ifdef KSHVI
- /* 0 */ ED_UNASSIGNED, /* ^@ */
- /* 1 */ ED_INSERT, /* ^A */
- /* 2 */ ED_INSERT, /* ^B */
- /* 3 */ ED_INSERT, /* ^C */
- /* 4 */ VI_LIST_OR_EOF, /* ^D */
- /* 5 */ ED_INSERT, /* ^E */
- /* 6 */ ED_INSERT, /* ^F */
- /* 7 */ ED_INSERT, /* ^G */
- /* 8 */ VI_DELETE_PREV_CHAR, /* ^H */ /* BackSpace key */
- /* 9 */ ED_INSERT, /* ^I */ /* Tab Key */
- /* 10 */ ED_NEWLINE, /* ^J */
- /* 11 */ ED_INSERT, /* ^K */
- /* 12 */ ED_INSERT, /* ^L */
- /* 13 */ ED_NEWLINE, /* ^M */
- /* 14 */ ED_INSERT, /* ^N */
- /* 15 */ ED_INSERT, /* ^O */
- /* 16 */ ED_INSERT, /* ^P */
- /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
- /* 18 */ ED_INSERT, /* ^R */
- /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
- /* 20 */ ED_INSERT, /* ^T */
- /* 21 */ VI_KILL_LINE_PREV, /* ^U */
- /* 22 */ ED_QUOTED_INSERT, /* ^V */
- /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
- /* ED_DELETE_PREV_WORD: Only until strt edit pos */
- /* 24 */ ED_INSERT, /* ^X */
- /* 25 */ ED_INSERT, /* ^Y */
- /* 26 */ ED_INSERT, /* ^Z */
- /* 27 */ VI_COMMAND_MODE, /* ^[ */ /* [ Esc ] key */
- /* 28 */ ED_TTY_SIGQUIT, /* ^\ */
- /* 29 */ ED_INSERT, /* ^] */
- /* 30 */ ED_INSERT, /* ^^ */
- /* 31 */ ED_INSERT, /* ^_ */
-#else /* !KSHVI */
- /*
- * NOTE: These mappings do NOT Correspond well
- * to the KSH VI editing assignments.
- * On the other and they are convenient and
- * many people have have gotten used to them.
- */
- /* 0 */ ED_UNASSIGNED, /* ^@ */
- /* 1 */ ED_MOVE_TO_BEG, /* ^A */
- /* 2 */ ED_PREV_CHAR, /* ^B */
- /* 3 */ ED_TTY_SIGINT, /* ^C */
- /* 4 */ VI_LIST_OR_EOF, /* ^D */
- /* 5 */ ED_MOVE_TO_END, /* ^E */
- /* 6 */ ED_NEXT_CHAR, /* ^F */
- /* 7 */ ED_UNASSIGNED, /* ^G */
- /* 8 */ ED_DELETE_PREV_CHAR, /* ^H */ /* BackSpace key */
- /* 9 */ ED_UNASSIGNED, /* ^I */ /* Tab Key */
- /* 10 */ ED_NEWLINE, /* ^J */
- /* 11 */ ED_KILL_LINE, /* ^K */
- /* 12 */ ED_CLEAR_SCREEN, /* ^L */
- /* 13 */ ED_NEWLINE, /* ^M */
- /* 14 */ ED_NEXT_HISTORY, /* ^N */
- /* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */
- /* 16 */ ED_PREV_HISTORY, /* ^P */
- /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
- /* 18 */ ED_REDISPLAY, /* ^R */
- /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
- /* 20 */ ED_TRANSPOSE_CHARS, /* ^T */
- /* 21 */ VI_KILL_LINE_PREV, /* ^U */
- /* 22 */ ED_QUOTED_INSERT, /* ^V */
- /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
- /* 24 */ ED_UNASSIGNED, /* ^X */
- /* 25 */ ED_TTY_DSUSP, /* ^Y */
- /* 26 */ ED_TTY_SIGTSTP, /* ^Z */
- /* 27 */ VI_COMMAND_MODE, /* ^[ */
- /* 28 */ ED_TTY_SIGQUIT, /* ^\ */
- /* 29 */ ED_UNASSIGNED, /* ^] */
- /* 30 */ ED_UNASSIGNED, /* ^^ */
- /* 31 */ ED_UNASSIGNED, /* ^_ */
-#endif /* KSHVI */
- /* 32 */ ED_INSERT, /* SPACE */
- /* 33 */ ED_INSERT, /* ! */
- /* 34 */ ED_INSERT, /* " */
- /* 35 */ ED_INSERT, /* # */
- /* 36 */ ED_INSERT, /* $ */
- /* 37 */ ED_INSERT, /* % */
- /* 38 */ ED_INSERT, /* & */
- /* 39 */ ED_INSERT, /* ' */
- /* 40 */ ED_INSERT, /* ( */
- /* 41 */ ED_INSERT, /* ) */
- /* 42 */ ED_INSERT, /* * */
- /* 43 */ ED_INSERT, /* + */
- /* 44 */ ED_INSERT, /* , */
- /* 45 */ ED_INSERT, /* - */
- /* 46 */ ED_INSERT, /* . */
- /* 47 */ ED_INSERT, /* / */
- /* 48 */ ED_INSERT, /* 0 */
- /* 49 */ ED_INSERT, /* 1 */
- /* 50 */ ED_INSERT, /* 2 */
- /* 51 */ ED_INSERT, /* 3 */
- /* 52 */ ED_INSERT, /* 4 */
- /* 53 */ ED_INSERT, /* 5 */
- /* 54 */ ED_INSERT, /* 6 */
- /* 55 */ ED_INSERT, /* 7 */
- /* 56 */ ED_INSERT, /* 8 */
- /* 57 */ ED_INSERT, /* 9 */
- /* 58 */ ED_INSERT, /* : */
- /* 59 */ ED_INSERT, /* ; */
- /* 60 */ ED_INSERT, /* < */
- /* 61 */ ED_INSERT, /* = */
- /* 62 */ ED_INSERT, /* > */
- /* 63 */ ED_INSERT, /* ? */
- /* 64 */ ED_INSERT, /* @ */
- /* 65 */ ED_INSERT, /* A */
- /* 66 */ ED_INSERT, /* B */
- /* 67 */ ED_INSERT, /* C */
- /* 68 */ ED_INSERT, /* D */
- /* 69 */ ED_INSERT, /* E */
- /* 70 */ ED_INSERT, /* F */
- /* 71 */ ED_INSERT, /* G */
- /* 72 */ ED_INSERT, /* H */
- /* 73 */ ED_INSERT, /* I */
- /* 74 */ ED_INSERT, /* J */
- /* 75 */ ED_INSERT, /* K */
- /* 76 */ ED_INSERT, /* L */
- /* 77 */ ED_INSERT, /* M */
- /* 78 */ ED_INSERT, /* N */
- /* 79 */ ED_INSERT, /* O */
- /* 80 */ ED_INSERT, /* P */
- /* 81 */ ED_INSERT, /* Q */
- /* 82 */ ED_INSERT, /* R */
- /* 83 */ ED_INSERT, /* S */
- /* 84 */ ED_INSERT, /* T */
- /* 85 */ ED_INSERT, /* U */
- /* 86 */ ED_INSERT, /* V */
- /* 87 */ ED_INSERT, /* W */
- /* 88 */ ED_INSERT, /* X */
- /* 89 */ ED_INSERT, /* Y */
- /* 90 */ ED_INSERT, /* Z */
- /* 91 */ ED_INSERT, /* [ */
- /* 92 */ ED_INSERT, /* \ */
- /* 93 */ ED_INSERT, /* ] */
- /* 94 */ ED_INSERT, /* ^ */
- /* 95 */ ED_INSERT, /* _ */
- /* 96 */ ED_INSERT, /* ` */
- /* 97 */ ED_INSERT, /* a */
- /* 98 */ ED_INSERT, /* b */
- /* 99 */ ED_INSERT, /* c */
- /* 100 */ ED_INSERT, /* d */
- /* 101 */ ED_INSERT, /* e */
- /* 102 */ ED_INSERT, /* f */
- /* 103 */ ED_INSERT, /* g */
- /* 104 */ ED_INSERT, /* h */
- /* 105 */ ED_INSERT, /* i */
- /* 106 */ ED_INSERT, /* j */
- /* 107 */ ED_INSERT, /* k */
- /* 108 */ ED_INSERT, /* l */
- /* 109 */ ED_INSERT, /* m */
- /* 110 */ ED_INSERT, /* n */
- /* 111 */ ED_INSERT, /* o */
- /* 112 */ ED_INSERT, /* p */
- /* 113 */ ED_INSERT, /* q */
- /* 114 */ ED_INSERT, /* r */
- /* 115 */ ED_INSERT, /* s */
- /* 116 */ ED_INSERT, /* t */
- /* 117 */ ED_INSERT, /* u */
- /* 118 */ ED_INSERT, /* v */
- /* 119 */ ED_INSERT, /* w */
- /* 120 */ ED_INSERT, /* x */
- /* 121 */ ED_INSERT, /* y */
- /* 122 */ ED_INSERT, /* z */
- /* 123 */ ED_INSERT, /* { */
- /* 124 */ ED_INSERT, /* | */
- /* 125 */ ED_INSERT, /* } */
- /* 126 */ ED_INSERT, /* ~ */
- /* 127 */ ED_DELETE_PREV_CHAR, /* ^? */
- /* 128 */ ED_UNASSIGNED, /* M-^@ */
- /* 129 */ ED_UNASSIGNED, /* M-^A */
- /* 130 */ ED_UNASSIGNED, /* M-^B */
- /* 131 */ ED_UNASSIGNED, /* M-^C */
- /* 132 */ ED_UNASSIGNED, /* M-^D */
- /* 133 */ ED_UNASSIGNED, /* M-^E */
- /* 134 */ ED_UNASSIGNED, /* M-^F */
- /* 135 */ ED_UNASSIGNED, /* M-^G */
- /* 136 */ ED_UNASSIGNED, /* M-^H */
- /* 137 */ ED_UNASSIGNED, /* M-^I */
- /* 138 */ ED_UNASSIGNED, /* M-^J */
- /* 139 */ ED_UNASSIGNED, /* M-^K */
- /* 140 */ ED_UNASSIGNED, /* M-^L */
- /* 141 */ ED_UNASSIGNED, /* M-^M */
- /* 142 */ ED_UNASSIGNED, /* M-^N */
- /* 143 */ ED_UNASSIGNED, /* M-^O */
- /* 144 */ ED_UNASSIGNED, /* M-^P */
- /* 145 */ ED_UNASSIGNED, /* M-^Q */
- /* 146 */ ED_UNASSIGNED, /* M-^R */
- /* 147 */ ED_UNASSIGNED, /* M-^S */
- /* 148 */ ED_UNASSIGNED, /* M-^T */
- /* 149 */ ED_UNASSIGNED, /* M-^U */
- /* 150 */ ED_UNASSIGNED, /* M-^V */
- /* 151 */ ED_UNASSIGNED, /* M-^W */
- /* 152 */ ED_UNASSIGNED, /* M-^X */
- /* 153 */ ED_UNASSIGNED, /* M-^Y */
- /* 154 */ ED_UNASSIGNED, /* M-^Z */
- /* 155 */ ED_UNASSIGNED, /* M-^[ */
- /* 156 */ ED_UNASSIGNED, /* M-^\ */
- /* 157 */ ED_UNASSIGNED, /* M-^] */
- /* 158 */ ED_UNASSIGNED, /* M-^^ */
- /* 159 */ ED_UNASSIGNED, /* M-^_ */
- /* 160 */ ED_UNASSIGNED, /* M-SPACE */
- /* 161 */ ED_UNASSIGNED, /* M-! */
- /* 162 */ ED_UNASSIGNED, /* M-" */
- /* 163 */ ED_UNASSIGNED, /* M-# */
- /* 164 */ ED_UNASSIGNED, /* M-$ */
- /* 165 */ ED_UNASSIGNED, /* M-% */
- /* 166 */ ED_UNASSIGNED, /* M-& */
- /* 167 */ ED_UNASSIGNED, /* M-' */
- /* 168 */ ED_UNASSIGNED, /* M-( */
- /* 169 */ ED_UNASSIGNED, /* M-) */
- /* 170 */ ED_UNASSIGNED, /* M-* */
- /* 171 */ ED_UNASSIGNED, /* M-+ */
- /* 172 */ ED_UNASSIGNED, /* M-, */
- /* 173 */ ED_UNASSIGNED, /* M-- */
- /* 174 */ ED_UNASSIGNED, /* M-. */
- /* 175 */ ED_UNASSIGNED, /* M-/ */
- /* 176 */ ED_UNASSIGNED, /* M-0 */
- /* 177 */ ED_UNASSIGNED, /* M-1 */
- /* 178 */ ED_UNASSIGNED, /* M-2 */
- /* 179 */ ED_UNASSIGNED, /* M-3 */
- /* 180 */ ED_UNASSIGNED, /* M-4 */
- /* 181 */ ED_UNASSIGNED, /* M-5 */
- /* 182 */ ED_UNASSIGNED, /* M-6 */
- /* 183 */ ED_UNASSIGNED, /* M-7 */
- /* 184 */ ED_UNASSIGNED, /* M-8 */
- /* 185 */ ED_UNASSIGNED, /* M-9 */
- /* 186 */ ED_UNASSIGNED, /* M-: */
- /* 187 */ ED_UNASSIGNED, /* M-; */
- /* 188 */ ED_UNASSIGNED, /* M-< */
- /* 189 */ ED_UNASSIGNED, /* M-= */
- /* 190 */ ED_UNASSIGNED, /* M-> */
- /* 191 */ ED_UNASSIGNED, /* M-? */
- /* 192 */ ED_UNASSIGNED, /* M-@ */
- /* 193 */ ED_UNASSIGNED, /* M-A */
- /* 194 */ ED_UNASSIGNED, /* M-B */
- /* 195 */ ED_UNASSIGNED, /* M-C */
- /* 196 */ ED_UNASSIGNED, /* M-D */
- /* 197 */ ED_UNASSIGNED, /* M-E */
- /* 198 */ ED_UNASSIGNED, /* M-F */
- /* 199 */ ED_UNASSIGNED, /* M-G */
- /* 200 */ ED_UNASSIGNED, /* M-H */
- /* 201 */ ED_UNASSIGNED, /* M-I */
- /* 202 */ ED_UNASSIGNED, /* M-J */
- /* 203 */ ED_UNASSIGNED, /* M-K */
- /* 204 */ ED_UNASSIGNED, /* M-L */
- /* 205 */ ED_UNASSIGNED, /* M-M */
- /* 206 */ ED_UNASSIGNED, /* M-N */
- /* 207 */ ED_UNASSIGNED, /* M-O */
- /* 208 */ ED_UNASSIGNED, /* M-P */
- /* 209 */ ED_UNASSIGNED, /* M-Q */
- /* 210 */ ED_UNASSIGNED, /* M-R */
- /* 211 */ ED_UNASSIGNED, /* M-S */
- /* 212 */ ED_UNASSIGNED, /* M-T */
- /* 213 */ ED_UNASSIGNED, /* M-U */
- /* 214 */ ED_UNASSIGNED, /* M-V */
- /* 215 */ ED_UNASSIGNED, /* M-W */
- /* 216 */ ED_UNASSIGNED, /* M-X */
- /* 217 */ ED_UNASSIGNED, /* M-Y */
- /* 218 */ ED_UNASSIGNED, /* M-Z */
- /* 219 */ ED_UNASSIGNED, /* M-[ */
- /* 220 */ ED_UNASSIGNED, /* M-\ */
- /* 221 */ ED_UNASSIGNED, /* M-] */
- /* 222 */ ED_UNASSIGNED, /* M-^ */
- /* 223 */ ED_UNASSIGNED, /* M-_ */
- /* 224 */ ED_UNASSIGNED, /* M-` */
- /* 225 */ ED_UNASSIGNED, /* M-a */
- /* 226 */ ED_UNASSIGNED, /* M-b */
- /* 227 */ ED_UNASSIGNED, /* M-c */
- /* 228 */ ED_UNASSIGNED, /* M-d */
- /* 229 */ ED_UNASSIGNED, /* M-e */
- /* 230 */ ED_UNASSIGNED, /* M-f */
- /* 231 */ ED_UNASSIGNED, /* M-g */
- /* 232 */ ED_UNASSIGNED, /* M-h */
- /* 233 */ ED_UNASSIGNED, /* M-i */
- /* 234 */ ED_UNASSIGNED, /* M-j */
- /* 235 */ ED_UNASSIGNED, /* M-k */
- /* 236 */ ED_UNASSIGNED, /* M-l */
- /* 237 */ ED_UNASSIGNED, /* M-m */
- /* 238 */ ED_UNASSIGNED, /* M-n */
- /* 239 */ ED_UNASSIGNED, /* M-o */
- /* 240 */ ED_UNASSIGNED, /* M-p */
- /* 241 */ ED_UNASSIGNED, /* M-q */
- /* 242 */ ED_UNASSIGNED, /* M-r */
- /* 243 */ ED_UNASSIGNED, /* M-s */
- /* 244 */ ED_UNASSIGNED, /* M-t */
- /* 245 */ ED_UNASSIGNED, /* M-u */
- /* 246 */ ED_UNASSIGNED, /* M-v */
- /* 247 */ ED_UNASSIGNED, /* M-w */
- /* 248 */ ED_UNASSIGNED, /* M-x */
- /* 249 */ ED_UNASSIGNED, /* M-y */
- /* 250 */ ED_UNASSIGNED, /* M-z */
- /* 251 */ ED_UNASSIGNED, /* M-{ */
- /* 252 */ ED_UNASSIGNED, /* M-| */
- /* 253 */ ED_UNASSIGNED, /* M-} */
- /* 254 */ ED_UNASSIGNED, /* M-~ */
- /* 255 */ ED_UNASSIGNED /* M-^? */
-};
-
-private const el_action_t el_map_vi_command[] = {
- /* 0 */ ED_UNASSIGNED, /* ^@ */
- /* 1 */ ED_MOVE_TO_BEG, /* ^A */
- /* 2 */ ED_UNASSIGNED, /* ^B */
- /* 3 */ ED_TTY_SIGINT, /* ^C */
- /* 4 */ ED_UNASSIGNED, /* ^D */
- /* 5 */ ED_MOVE_TO_END, /* ^E */
- /* 6 */ ED_UNASSIGNED, /* ^F */
- /* 7 */ ED_UNASSIGNED, /* ^G */
- /* 8 */ ED_PREV_CHAR, /* ^H */
- /* 9 */ ED_UNASSIGNED, /* ^I */
- /* 10 */ ED_NEWLINE, /* ^J */
- /* 11 */ ED_KILL_LINE, /* ^K */
- /* 12 */ ED_CLEAR_SCREEN, /* ^L */
- /* 13 */ ED_NEWLINE, /* ^M */
- /* 14 */ ED_NEXT_HISTORY, /* ^N */
- /* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */
- /* 16 */ ED_PREV_HISTORY, /* ^P */
- /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
- /* 18 */ ED_REDISPLAY, /* ^R */
- /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
- /* 20 */ ED_UNASSIGNED, /* ^T */
- /* 21 */ VI_KILL_LINE_PREV, /* ^U */
- /* 22 */ ED_UNASSIGNED, /* ^V */
- /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
- /* 24 */ ED_UNASSIGNED, /* ^X */
- /* 25 */ ED_UNASSIGNED, /* ^Y */
- /* 26 */ ED_UNASSIGNED, /* ^Z */
- /* 27 */ EM_META_NEXT, /* ^[ */
- /* 28 */ ED_TTY_SIGQUIT, /* ^\ */
- /* 29 */ ED_UNASSIGNED, /* ^] */
- /* 30 */ ED_UNASSIGNED, /* ^^ */
- /* 31 */ ED_UNASSIGNED, /* ^_ */
- /* 32 */ ED_NEXT_CHAR, /* SPACE */
- /* 33 */ ED_UNASSIGNED, /* ! */
- /* 34 */ ED_UNASSIGNED, /* " */
- /* 35 */ ED_UNASSIGNED, /* # */
- /* 36 */ ED_MOVE_TO_END, /* $ */
- /* 37 */ ED_UNASSIGNED, /* % */
- /* 38 */ ED_UNASSIGNED, /* & */
- /* 39 */ ED_UNASSIGNED, /* ' */
- /* 40 */ ED_UNASSIGNED, /* ( */
- /* 41 */ ED_UNASSIGNED, /* ) */
- /* 42 */ ED_UNASSIGNED, /* * */
- /* 43 */ ED_NEXT_HISTORY, /* + */
- /* 44 */ VI_REPEAT_PREV_CHAR, /* , */
- /* 45 */ ED_PREV_HISTORY, /* - */
- /* 46 */ ED_UNASSIGNED, /* . */
- /* 47 */ VI_SEARCH_PREV, /* / */
- /* 48 */ VI_ZERO, /* 0 */
- /* 49 */ ED_ARGUMENT_DIGIT, /* 1 */
- /* 50 */ ED_ARGUMENT_DIGIT, /* 2 */
- /* 51 */ ED_ARGUMENT_DIGIT, /* 3 */
- /* 52 */ ED_ARGUMENT_DIGIT, /* 4 */
- /* 53 */ ED_ARGUMENT_DIGIT, /* 5 */
- /* 54 */ ED_ARGUMENT_DIGIT, /* 6 */
- /* 55 */ ED_ARGUMENT_DIGIT, /* 7 */
- /* 56 */ ED_ARGUMENT_DIGIT, /* 8 */
- /* 57 */ ED_ARGUMENT_DIGIT, /* 9 */
- /* 58 */ ED_COMMAND, /* : */
- /* 59 */ VI_REPEAT_NEXT_CHAR, /* ; */
- /* 60 */ ED_UNASSIGNED, /* < */
- /* 61 */ ED_UNASSIGNED, /* = */
- /* 62 */ ED_UNASSIGNED, /* > */
- /* 63 */ VI_SEARCH_NEXT, /* ? */
- /* 64 */ ED_UNASSIGNED, /* @ */
- /* 65 */ VI_ADD_AT_EOL, /* A */
- /* 66 */ VI_PREV_SPACE_WORD, /* B */
- /* 67 */ VI_CHANGE_TO_EOL, /* C */
- /* 68 */ ED_KILL_LINE, /* D */
- /* 69 */ VI_TO_END_WORD, /* E */
- /* 70 */ VI_PREV_CHAR, /* F */
- /* 71 */ ED_UNASSIGNED, /* G */
- /* 72 */ ED_UNASSIGNED, /* H */
- /* 73 */ VI_INSERT_AT_BOL, /* I */
- /* 74 */ ED_SEARCH_NEXT_HISTORY, /* J */
- /* 75 */ ED_SEARCH_PREV_HISTORY, /* K */
- /* 76 */ ED_UNASSIGNED, /* L */
- /* 77 */ ED_UNASSIGNED, /* M */
- /* 78 */ VI_REPEAT_SEARCH_PREV, /* N */
- /* 79 */ ED_SEQUENCE_LEAD_IN, /* O */
- /* 80 */ VI_PASTE_PREV, /* P */
- /* 81 */ ED_UNASSIGNED, /* Q */
- /* 82 */ VI_REPLACE_MODE, /* R */
- /* 83 */ VI_SUBSTITUTE_LINE, /* S */
- /* 84 */ VI_TO_PREV_CHAR, /* T */
- /* 85 */ ED_UNASSIGNED, /* U */
- /* 86 */ ED_UNASSIGNED, /* V */
- /* 87 */ VI_NEXT_SPACE_WORD, /* W */
- /* 88 */ ED_DELETE_PREV_CHAR, /* X */
- /* 89 */ ED_UNASSIGNED, /* Y */
- /* 90 */ ED_UNASSIGNED, /* Z */
- /* 91 */ ED_SEQUENCE_LEAD_IN, /* [ */
- /* 92 */ ED_UNASSIGNED, /* \ */
- /* 93 */ ED_UNASSIGNED, /* ] */
- /* 94 */ ED_MOVE_TO_BEG, /* ^ */
- /* 95 */ ED_UNASSIGNED, /* _ */
- /* 96 */ ED_UNASSIGNED, /* ` */
- /* 97 */ VI_ADD, /* a */
- /* 98 */ VI_PREV_WORD, /* b */
- /* 99 */ VI_CHANGE_META, /* c */
- /* 100 */ VI_DELETE_META, /* d */
- /* 101 */ VI_END_WORD, /* e */
- /* 102 */ VI_NEXT_CHAR, /* f */
- /* 103 */ ED_UNASSIGNED, /* g */
- /* 104 */ ED_PREV_CHAR, /* h */
- /* 105 */ VI_INSERT, /* i */
- /* 106 */ ED_NEXT_HISTORY, /* j */
- /* 107 */ ED_PREV_HISTORY, /* k */
- /* 108 */ ED_NEXT_CHAR, /* l */
- /* 109 */ ED_UNASSIGNED, /* m */
- /* 110 */ VI_REPEAT_SEARCH_NEXT, /* n */
- /* 111 */ ED_UNASSIGNED, /* o */
- /* 112 */ VI_PASTE_NEXT, /* p */
- /* 113 */ ED_UNASSIGNED, /* q */
- /* 114 */ VI_REPLACE_CHAR, /* r */
- /* 115 */ VI_SUBSTITUTE_CHAR, /* s */
- /* 116 */ VI_TO_NEXT_CHAR, /* t */
- /* 117 */ VI_UNDO, /* u */
- /* 118 */ ED_UNASSIGNED, /* v */
- /* 119 */ VI_NEXT_WORD, /* w */
- /* 120 */ ED_DELETE_NEXT_CHAR, /* x */
- /* 121 */ ED_UNASSIGNED, /* y */
- /* 122 */ ED_UNASSIGNED, /* z */
- /* 123 */ ED_UNASSIGNED, /* { */
- /* 124 */ ED_UNASSIGNED, /* | */
- /* 125 */ ED_UNASSIGNED, /* } */
- /* 126 */ VI_CHANGE_CASE, /* ~ */
- /* 127 */ ED_DELETE_PREV_CHAR, /* ^? */
- /* 128 */ ED_UNASSIGNED, /* M-^@ */
- /* 129 */ ED_UNASSIGNED, /* M-^A */
- /* 130 */ ED_UNASSIGNED, /* M-^B */
- /* 131 */ ED_UNASSIGNED, /* M-^C */
- /* 132 */ ED_UNASSIGNED, /* M-^D */
- /* 133 */ ED_UNASSIGNED, /* M-^E */
- /* 134 */ ED_UNASSIGNED, /* M-^F */
- /* 135 */ ED_UNASSIGNED, /* M-^G */
- /* 136 */ ED_UNASSIGNED, /* M-^H */
- /* 137 */ ED_UNASSIGNED, /* M-^I */
- /* 138 */ ED_UNASSIGNED, /* M-^J */
- /* 139 */ ED_UNASSIGNED, /* M-^K */
- /* 140 */ ED_UNASSIGNED, /* M-^L */
- /* 141 */ ED_UNASSIGNED, /* M-^M */
- /* 142 */ ED_UNASSIGNED, /* M-^N */
- /* 143 */ ED_UNASSIGNED, /* M-^O */
- /* 144 */ ED_UNASSIGNED, /* M-^P */
- /* 145 */ ED_UNASSIGNED, /* M-^Q */
- /* 146 */ ED_UNASSIGNED, /* M-^R */
- /* 147 */ ED_UNASSIGNED, /* M-^S */
- /* 148 */ ED_UNASSIGNED, /* M-^T */
- /* 149 */ ED_UNASSIGNED, /* M-^U */
- /* 150 */ ED_UNASSIGNED, /* M-^V */
- /* 151 */ ED_UNASSIGNED, /* M-^W */
- /* 152 */ ED_UNASSIGNED, /* M-^X */
- /* 153 */ ED_UNASSIGNED, /* M-^Y */
- /* 154 */ ED_UNASSIGNED, /* M-^Z */
- /* 155 */ ED_UNASSIGNED, /* M-^[ */
- /* 156 */ ED_UNASSIGNED, /* M-^\ */
- /* 157 */ ED_UNASSIGNED, /* M-^] */
- /* 158 */ ED_UNASSIGNED, /* M-^^ */
- /* 159 */ ED_UNASSIGNED, /* M-^_ */
- /* 160 */ ED_UNASSIGNED, /* M-SPACE */
- /* 161 */ ED_UNASSIGNED, /* M-! */
- /* 162 */ ED_UNASSIGNED, /* M-" */
- /* 163 */ ED_UNASSIGNED, /* M-# */
- /* 164 */ ED_UNASSIGNED, /* M-$ */
- /* 165 */ ED_UNASSIGNED, /* M-% */
- /* 166 */ ED_UNASSIGNED, /* M-& */
- /* 167 */ ED_UNASSIGNED, /* M-' */
- /* 168 */ ED_UNASSIGNED, /* M-( */
- /* 169 */ ED_UNASSIGNED, /* M-) */
- /* 170 */ ED_UNASSIGNED, /* M-* */
- /* 171 */ ED_UNASSIGNED, /* M-+ */
- /* 172 */ ED_UNASSIGNED, /* M-, */
- /* 173 */ ED_UNASSIGNED, /* M-- */
- /* 174 */ ED_UNASSIGNED, /* M-. */
- /* 175 */ ED_UNASSIGNED, /* M-/ */
- /* 176 */ ED_UNASSIGNED, /* M-0 */
- /* 177 */ ED_UNASSIGNED, /* M-1 */
- /* 178 */ ED_UNASSIGNED, /* M-2 */
- /* 179 */ ED_UNASSIGNED, /* M-3 */
- /* 180 */ ED_UNASSIGNED, /* M-4 */
- /* 181 */ ED_UNASSIGNED, /* M-5 */
- /* 182 */ ED_UNASSIGNED, /* M-6 */
- /* 183 */ ED_UNASSIGNED, /* M-7 */
- /* 184 */ ED_UNASSIGNED, /* M-8 */
- /* 185 */ ED_UNASSIGNED, /* M-9 */
- /* 186 */ ED_UNASSIGNED, /* M-: */
- /* 187 */ ED_UNASSIGNED, /* M-; */
- /* 188 */ ED_UNASSIGNED, /* M-< */
- /* 189 */ ED_UNASSIGNED, /* M-= */
- /* 190 */ ED_UNASSIGNED, /* M-> */
- /* 191 */ ED_UNASSIGNED, /* M-? */
- /* 192 */ ED_UNASSIGNED, /* M-@ */
- /* 193 */ ED_UNASSIGNED, /* M-A */
- /* 194 */ ED_UNASSIGNED, /* M-B */
- /* 195 */ ED_UNASSIGNED, /* M-C */
- /* 196 */ ED_UNASSIGNED, /* M-D */
- /* 197 */ ED_UNASSIGNED, /* M-E */
- /* 198 */ ED_UNASSIGNED, /* M-F */
- /* 199 */ ED_UNASSIGNED, /* M-G */
- /* 200 */ ED_UNASSIGNED, /* M-H */
- /* 201 */ ED_UNASSIGNED, /* M-I */
- /* 202 */ ED_UNASSIGNED, /* M-J */
- /* 203 */ ED_UNASSIGNED, /* M-K */
- /* 204 */ ED_UNASSIGNED, /* M-L */
- /* 205 */ ED_UNASSIGNED, /* M-M */
- /* 206 */ ED_UNASSIGNED, /* M-N */
- /* 207 */ ED_SEQUENCE_LEAD_IN, /* M-O */
- /* 208 */ ED_UNASSIGNED, /* M-P */
- /* 209 */ ED_UNASSIGNED, /* M-Q */
- /* 210 */ ED_UNASSIGNED, /* M-R */
- /* 211 */ ED_UNASSIGNED, /* M-S */
- /* 212 */ ED_UNASSIGNED, /* M-T */
- /* 213 */ ED_UNASSIGNED, /* M-U */
- /* 214 */ ED_UNASSIGNED, /* M-V */
- /* 215 */ ED_UNASSIGNED, /* M-W */
- /* 216 */ ED_UNASSIGNED, /* M-X */
- /* 217 */ ED_UNASSIGNED, /* M-Y */
- /* 218 */ ED_UNASSIGNED, /* M-Z */
- /* 219 */ ED_SEQUENCE_LEAD_IN, /* M-[ */
- /* 220 */ ED_UNASSIGNED, /* M-\ */
- /* 221 */ ED_UNASSIGNED, /* M-] */
- /* 222 */ ED_UNASSIGNED, /* M-^ */
- /* 223 */ ED_UNASSIGNED, /* M-_ */
- /* 224 */ ED_UNASSIGNED, /* M-` */
- /* 225 */ ED_UNASSIGNED, /* M-a */
- /* 226 */ ED_UNASSIGNED, /* M-b */
- /* 227 */ ED_UNASSIGNED, /* M-c */
- /* 228 */ ED_UNASSIGNED, /* M-d */
- /* 229 */ ED_UNASSIGNED, /* M-e */
- /* 230 */ ED_UNASSIGNED, /* M-f */
- /* 231 */ ED_UNASSIGNED, /* M-g */
- /* 232 */ ED_UNASSIGNED, /* M-h */
- /* 233 */ ED_UNASSIGNED, /* M-i */
- /* 234 */ ED_UNASSIGNED, /* M-j */
- /* 235 */ ED_UNASSIGNED, /* M-k */
- /* 236 */ ED_UNASSIGNED, /* M-l */
- /* 237 */ ED_UNASSIGNED, /* M-m */
- /* 238 */ ED_UNASSIGNED, /* M-n */
- /* 239 */ ED_UNASSIGNED, /* M-o */
- /* 240 */ ED_UNASSIGNED, /* M-p */
- /* 241 */ ED_UNASSIGNED, /* M-q */
- /* 242 */ ED_UNASSIGNED, /* M-r */
- /* 243 */ ED_UNASSIGNED, /* M-s */
- /* 244 */ ED_UNASSIGNED, /* M-t */
- /* 245 */ ED_UNASSIGNED, /* M-u */
- /* 246 */ ED_UNASSIGNED, /* M-v */
- /* 247 */ ED_UNASSIGNED, /* M-w */
- /* 248 */ ED_UNASSIGNED, /* M-x */
- /* 249 */ ED_UNASSIGNED, /* M-y */
- /* 250 */ ED_UNASSIGNED, /* M-z */
- /* 251 */ ED_UNASSIGNED, /* M-{ */
- /* 252 */ ED_UNASSIGNED, /* M-| */
- /* 253 */ ED_UNASSIGNED, /* M-} */
- /* 254 */ ED_UNASSIGNED, /* M-~ */
- /* 255 */ ED_UNASSIGNED /* M-^? */
-};
-
-
-/* map_init():
- * Initialize and allocate the maps
- */
-protected int
-map_init(EditLine *el)
-{
-
- /*
- * Make sure those are correct before starting.
- */
-#ifdef MAP_DEBUG
- if (sizeof(el_map_emacs) != N_KEYS * sizeof(el_action_t))
- EL_ABORT((el->errfile, "Emacs map incorrect\n"));
- if (sizeof(el_map_vi_command) != N_KEYS * sizeof(el_action_t))
- EL_ABORT((el->errfile, "Vi command map incorrect\n"));
- if (sizeof(el_map_vi_insert) != N_KEYS * sizeof(el_action_t))
- EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
-#endif
-
- el->el_map.alt = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
- if (el->el_map.alt == NULL)
- return (-1);
- el->el_map.key = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
- if (el->el_map.key == NULL)
- return (-1);
- el->el_map.emacs = el_map_emacs;
- el->el_map.vic = el_map_vi_command;
- el->el_map.vii = el_map_vi_insert;
- el->el_map.help = (el_bindings_t *) el_malloc(sizeof(el_bindings_t) *
- EL_NUM_FCNS);
- if (el->el_map.help == NULL)
- return (-1);
- (void) memcpy(el->el_map.help, help__get(),
- sizeof(el_bindings_t) * EL_NUM_FCNS);
- el->el_map.func = (el_func_t *)el_malloc(sizeof(el_func_t) *
- EL_NUM_FCNS);
- if (el->el_map.func == NULL)
- return (-1);
- memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS);
- el->el_map.nfunc = EL_NUM_FCNS;
-
-#ifdef VIDEFAULT
- map_init_vi(el);
-#else
- map_init_emacs(el);
-#endif /* VIDEFAULT */
- return (0);
-}
-
-
-/* map_end():
- * Free the space taken by the editor maps
- */
-protected void
-map_end(EditLine *el)
-{
-
- el_free((ptr_t) el->el_map.alt);
- el->el_map.alt = NULL;
- el_free((ptr_t) el->el_map.key);
- el->el_map.key = NULL;
- el->el_map.emacs = NULL;
- el->el_map.vic = NULL;
- el->el_map.vii = NULL;
- el_free((ptr_t) el->el_map.help);
- el->el_map.help = NULL;
- el_free((ptr_t) el->el_map.func);
- el->el_map.func = NULL;
-}
-
-
-/* map_init_nls():
- * Find all the printable keys and bind them to self insert
- */
-private void
-map_init_nls(EditLine *el)
-{
- int i;
-
- el_action_t *map = el->el_map.key;
-
- for (i = 0200; i <= 0377; i++)
- if (isprint(i))
- map[i] = ED_INSERT;
-}
-
-
-/* map_init_meta():
- * Bind all the meta keys to the appropriate ESC-<key> sequence
- */
-private void
-map_init_meta(EditLine *el)
-{
- char buf[3];
- int i;
- el_action_t *map = el->el_map.key;
- el_action_t *alt = el->el_map.alt;
-
- for (i = 0; i <= 0377 && map[i] != EM_META_NEXT; i++)
- continue;
-
- if (i > 0377) {
- for (i = 0; i <= 0377 && alt[i] != EM_META_NEXT; i++)
- continue;
- if (i > 0377) {
- i = 033;
- if (el->el_map.type == MAP_VI)
- map = alt;
- } else
- map = alt;
- }
- buf[0] = (char) i;
- buf[2] = 0;
- for (i = 0200; i <= 0377; i++)
- switch (map[i]) {
- case ED_INSERT:
- case ED_UNASSIGNED:
- case ED_SEQUENCE_LEAD_IN:
- break;
- default:
- buf[1] = i & 0177;
- key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD);
- break;
- }
- map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
-}
-
-
-/* map_init_vi():
- * Initialize the vi bindings
- */
-protected void
-map_init_vi(EditLine *el)
-{
- int i;
- el_action_t *key = el->el_map.key;
- el_action_t *alt = el->el_map.alt;
- const el_action_t *vii = el->el_map.vii;
- const el_action_t *vic = el->el_map.vic;
-
- el->el_map.type = MAP_VI;
- el->el_map.current = el->el_map.key;
-
- key_reset(el);
-
- for (i = 0; i < N_KEYS; i++) {
- key[i] = vii[i];
- alt[i] = vic[i];
- }
-
- map_init_meta(el);
- map_init_nls(el);
-
- tty_bind_char(el, 1);
- term_bind_arrow(el);
-}
-
-
-/* map_init_emacs():
- * Initialize the emacs bindings
- */
-protected void
-map_init_emacs(EditLine *el)
-{
- int i;
- char buf[3];
- el_action_t *key = el->el_map.key;
- el_action_t *alt = el->el_map.alt;
- const el_action_t *emacs = el->el_map.emacs;
-
- el->el_map.type = MAP_EMACS;
- el->el_map.current = el->el_map.key;
- key_reset(el);
-
- for (i = 0; i < N_KEYS; i++) {
- key[i] = emacs[i];
- alt[i] = ED_UNASSIGNED;
- }
-
- map_init_meta(el);
- map_init_nls(el);
-
- buf[0] = CONTROL('X');
- buf[1] = CONTROL('X');
- buf[2] = 0;
- key_add(el, buf, key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
-
- tty_bind_char(el, 1);
- term_bind_arrow(el);
-}
-
-
-/* map_set_editor():
- * Set the editor
- */
-protected int
-map_set_editor(EditLine *el, char *editor)
-{
-
- if (strcmp(editor, "emacs") == 0) {
- map_init_emacs(el);
- return (0);
- }
- if (strcmp(editor, "vi") == 0) {
- map_init_vi(el);
- return (0);
- }
- return (-1);
-}
-
-
-/* map_get_editor():
- * Retrieve the editor
- */
-protected int
-map_get_editor(EditLine *el, const char **editor)
-{
-
- if (editor == NULL)
- return (-1);
- switch (el->el_map.type) {
- case MAP_EMACS:
- *editor = "emacs";
- return (0);
- case MAP_VI:
- *editor = "vi";
- return (0);
- }
- return (-1);
-}
-
-
-/* map_print_key():
- * Print the function description for 1 key
- */
-private void
-map_print_key(EditLine *el, el_action_t *map, const char *in)
-{
- char outbuf[EL_BUFSIZ];
- el_bindings_t *bp;
-
- if (in[0] == '\0' || in[1] == '\0') {
- (void) key__decode_str(in, outbuf, "");
- for (bp = el->el_map.help; bp->name != NULL; bp++)
- if (bp->func == map[(unsigned char) *in]) {
- (void) fprintf(el->el_outfile,
- "%s\t->\t%s\n", outbuf, bp->name);
- return;
- }
- } else
- key_print(el, in);
-}
-
-
-/* map_print_some_keys():
- * Print keys from first to last
- */
-private void
-map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
-{
- el_bindings_t *bp;
- char firstbuf[2], lastbuf[2];
- char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ];
-
- firstbuf[0] = first;
- firstbuf[1] = 0;
- lastbuf[0] = last;
- lastbuf[1] = 0;
- if (map[first] == ED_UNASSIGNED) {
- if (first == last)
- (void) fprintf(el->el_outfile,
- "%-15s-> is undefined\n",
- key__decode_str(firstbuf, unparsbuf, STRQQ));
- return;
- }
- for (bp = el->el_map.help; bp->name != NULL; bp++) {
- if (bp->func == map[first]) {
- if (first == last) {
- (void) fprintf(el->el_outfile, "%-15s-> %s\n",
- key__decode_str(firstbuf, unparsbuf, STRQQ),
- bp->name);
- } else {
- (void) fprintf(el->el_outfile,
- "%-4s to %-7s-> %s\n",
- key__decode_str(firstbuf, unparsbuf, STRQQ),
- key__decode_str(lastbuf, extrabuf, STRQQ),
- bp->name);
- }
- return;
- }
- }
-#ifdef MAP_DEBUG
- if (map == el->el_map.key) {
- (void) fprintf(el->el_outfile,
- "BUG!!! %s isn't bound to anything.\n",
- key__decode_str(firstbuf, unparsbuf, STRQQ));
- (void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
- first, el->el_map.key[first]);
- } else {
- (void) fprintf(el->el_outfile,
- "BUG!!! %s isn't bound to anything.\n",
- key__decode_str(firstbuf, unparsbuf, STRQQ));
- (void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
- first, el->el_map.alt[first]);
- }
-#endif
- EL_ABORT((el->el_errfile, "Error printing keys\n"));
-}
-
-
-/* map_print_all_keys():
- * Print the function description for all keys.
- */
-private void
-map_print_all_keys(EditLine *el)
-{
- int prev, i;
-
- (void) fprintf(el->el_outfile, "Standard key bindings\n");
- prev = 0;
- for (i = 0; i < N_KEYS; i++) {
- if (el->el_map.key[prev] == el->el_map.key[i])
- continue;
- map_print_some_keys(el, el->el_map.key, prev, i - 1);
- prev = i;
- }
- map_print_some_keys(el, el->el_map.key, prev, i - 1);
-
- (void) fprintf(el->el_outfile, "Alternative key bindings\n");
- prev = 0;
- for (i = 0; i < N_KEYS; i++) {
- if (el->el_map.alt[prev] == el->el_map.alt[i])
- continue;
- map_print_some_keys(el, el->el_map.alt, prev, i - 1);
- prev = i;
- }
- map_print_some_keys(el, el->el_map.alt, prev, i - 1);
-
- (void) fprintf(el->el_outfile, "Multi-character bindings\n");
- key_print(el, "");
- (void) fprintf(el->el_outfile, "Arrow key bindings\n");
- term_print_arrow(el, "");
-}
-
-
-/* map_bind():
- * Add/remove/change bindings
- */
-protected int
-map_bind(EditLine *el, int argc, const char **argv)
-{
- el_action_t *map;
- int ntype, rem;
- const char *p;
- char inbuf[EL_BUFSIZ];
- char outbuf[EL_BUFSIZ];
- const char *in = NULL;
- char *out = NULL;
- el_bindings_t *bp;
- int cmd;
- int key;
-
- if (argv == NULL)
- return (-1);
-
- map = el->el_map.key;
- ntype = XK_CMD;
- key = rem = 0;
- for (argc = 1; (p = argv[argc]) != NULL; argc++)
- if (p[0] == '-')
- switch (p[1]) {
- case 'a':
- map = el->el_map.alt;
- break;
-
- case 's':
- ntype = XK_STR;
- break;
-#ifdef notyet
- case 'c':
- ntype = XK_EXE;
- break;
-#endif
- case 'k':
- key = 1;
- break;
-
- case 'r':
- rem = 1;
- break;
-
- case 'v':
- map_init_vi(el);
- return (0);
-
- case 'e':
- map_init_emacs(el);
- return (0);
-
- case 'l':
- for (bp = el->el_map.help; bp->name != NULL;
- bp++)
- (void) fprintf(el->el_outfile,
- "%s\n\t%s\n",
- bp->name, bp->description);
- return (0);
- default:
- (void) fprintf(el->el_errfile,
- "%s: Invalid switch `%c'.\n",
- argv[0], p[1]);
- }
- else
- break;
-
- if (argv[argc] == NULL) {
- map_print_all_keys(el);
- return (0);
- }
- if (key)
- in = argv[argc++];
- else if ((in = parse__string(inbuf, argv[argc++])) == NULL) {
- (void) fprintf(el->el_errfile,
- "%s: Invalid \\ or ^ in instring.\n",
- argv[0]);
- return (-1);
- }
- if (rem) {
- if (key) {
- (void) term_clear_arrow(el, in);
- return (-1);
- }
- if (in[1])
- (void) key_delete(el, in);
- else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
- (void) key_delete(el, in);
- else
- map[(unsigned char) *in] = ED_UNASSIGNED;
- return (0);
- }
- if (argv[argc] == NULL) {
- if (key)
- term_print_arrow(el, in);
- else
- map_print_key(el, map, in);
- return (0);
- }
-#ifdef notyet
- if (argv[argc + 1] != NULL) {
- bindkey_usage();
- return (-1);
- }
-#endif
-
- switch (ntype) {
- case XK_STR:
- case XK_EXE:
- if ((out = parse__string(outbuf, argv[argc])) == NULL) {
- (void) fprintf(el->el_errfile,
- "%s: Invalid \\ or ^ in outstring.\n", argv[0]);
- return (-1);
- }
- if (key)
- term_set_arrow(el, in, key_map_str(el, out), ntype);
- else
- key_add(el, in, key_map_str(el, out), ntype);
- map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
- break;
-
- case XK_CMD:
- if ((cmd = parse_cmd(el, argv[argc])) == -1) {
- (void) fprintf(el->el_errfile,
- "%s: Invalid command `%s'.\n", argv[0], argv[argc]);
- return (-1);
- }
- if (key)
- term_set_arrow(el, in, key_map_str(el, out), ntype);
- else {
- if (in[1]) {
- key_add(el, in, key_map_cmd(el, cmd), ntype);
- map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
- } else {
- key_clear(el, map, in);
- map[(unsigned char) *in] = cmd;
- }
- }
- break;
-
- default:
- EL_ABORT((el->el_errfile, "Bad XK_ type\n", ntype));
- break;
- }
- return (0);
-}
-
-
-/* map_addfunc():
- * add a user defined function
- */
-protected int
-map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func)
-{
- void *p;
- int nf = el->el_map.nfunc + 2;
-
- if (name == NULL || help == NULL || func == NULL)
- return (-1);
-
- if ((p = el_realloc(el->el_map.func, nf * sizeof(el_func_t))) == NULL)
- return (-1);
- el->el_map.func = (el_func_t *) p;
- if ((p = el_realloc(el->el_map.help, nf * sizeof(el_bindings_t)))
- == NULL)
- return (-1);
- el->el_map.help = (el_bindings_t *) p;
-
- nf = el->el_map.nfunc;
- el->el_map.func[nf] = func;
-
- el->el_map.help[nf].name = name;
- el->el_map.help[nf].func = nf;
- el->el_map.help[nf].description = help;
- el->el_map.help[++nf].name = NULL;
- el->el_map.nfunc++;
-
- return (0);
-}
diff --git a/1.2-netsec/editline/map.h b/1.2-netsec/editline/map.h
deleted file mode 100644
index 3c9948ccf..000000000
--- a/1.2-netsec/editline/map.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* $NetBSD: map.h,v 1.7 2002/03/18 16:00:56 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)map.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.map.h: Editor maps
- */
-#ifndef _h_el_map
-#define _h_el_map
-
-typedef struct el_bindings_t { /* for the "bind" shell command */
- const char *name; /* function name for bind command */
- int func; /* function numeric value */
- const char *description; /* description of function */
-} el_bindings_t;
-
-
-typedef struct el_map_t {
- el_action_t *alt; /* The current alternate key map */
- el_action_t *key; /* The current normal key map */
- el_action_t *current; /* The keymap we are using */
- const el_action_t *emacs; /* The default emacs key map */
- const el_action_t *vic; /* The vi command mode key map */
- const el_action_t *vii; /* The vi insert mode key map */
- int type; /* Emacs or vi */
- el_bindings_t *help; /* The help for the editor functions */
- el_func_t *func; /* List of available functions */
- int nfunc; /* The number of functions/help items */
-} el_map_t;
-
-#define MAP_EMACS 0
-#define MAP_VI 1
-
-protected int map_bind(EditLine *, int, const char **);
-protected int map_init(EditLine *);
-protected void map_end(EditLine *);
-protected void map_init_vi(EditLine *);
-protected void map_init_emacs(EditLine *);
-protected int map_set_editor(EditLine *, char *);
-protected int map_get_editor(EditLine *, const char **);
-protected int map_addfunc(EditLine *, const char *, const char *, el_func_t);
-
-#endif /* _h_el_map */
diff --git a/1.2-netsec/editline/np/fgetln.c b/1.2-netsec/editline/np/fgetln.c
deleted file mode 100644
index 93da9914d..000000000
--- a/1.2-netsec/editline/np/fgetln.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/* $NetBSD: fgetln.c,v 1.1.1.1 1999/04/12 07:43:21 crooksa Exp $ */
-
-/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Christos Zoulas.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-
-char *
-fgetln(fp, len)
- FILE *fp;
- size_t *len;
-{
- static char *buf = NULL;
- static size_t bufsiz = 0;
- char *ptr;
-
-
- if (buf == NULL) {
- bufsiz = BUFSIZ;
- if ((buf = malloc(bufsiz)) == NULL)
- return NULL;
- }
-
- if (fgets(buf, bufsiz, fp) == NULL)
- return NULL;
- *len = 0;
-
- while ((ptr = strchr(&buf[*len], '\n')) == NULL) {
- size_t nbufsiz = bufsiz + BUFSIZ;
- char *nbuf = realloc(buf, nbufsiz);
-
- if (nbuf == NULL) {
- int oerrno = errno;
- free(buf);
- errno = oerrno;
- buf = NULL;
- return NULL;
- } else
- buf = nbuf;
-
- *len = bufsiz;
- if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL)
- return buf;
-
- bufsiz = nbufsiz;
- }
-
- *len = (ptr - buf) + 1;
- return buf;
-}
diff --git a/1.2-netsec/editline/np/strlcat.c b/1.2-netsec/editline/np/strlcat.c
deleted file mode 100644
index 6c9f1e92d..000000000
--- a/1.2-netsec/editline/np/strlcat.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $";
-#endif /* LIBC_SCCS and not lint */
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD: src/lib/libc/string/strlcat.c,v 1.2.4.2 2001/07/09 23:30:06 obrien Exp $";
-#endif
-
-#include <sys/types.h>
-#include <string.h>
-
-/*
- * Appends src to string dst of size siz (unlike strncat, siz is the
- * full size of dst, not space left). At most siz-1 characters
- * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
- * Returns strlen(initial dst) + strlen(src); if retval >= siz,
- * truncation occurred.
- */
-size_t strlcat(dst, src, siz)
- char *dst;
- const char *src;
- size_t siz;
-{
- register char *d = dst;
- register const char *s = src;
- register size_t n = siz;
- size_t dlen;
-
- /* Find the end of dst and adjust bytes left but don't go past end */
- while (n-- != 0 && *d != '\0')
- d++;
- dlen = d - dst;
- n = siz - dlen;
-
- if (n == 0)
- return(dlen + strlen(s));
- while (*s != '\0') {
- if (n != 1) {
- *d++ = *s;
- n--;
- }
- s++;
- }
- *d = '\0';
-
- return(dlen + (s - src)); /* count does not include NUL */
-}
diff --git a/1.2-netsec/editline/np/strlcpy.c b/1.2-netsec/editline/np/strlcpy.c
deleted file mode 100644
index 1f154bcf2..000000000
--- a/1.2-netsec/editline/np/strlcpy.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */
-
-/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $";
-#endif
-#endif /* LIBC_SCCS and not lint */
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.2.4.1 2001/07/09 23:30:06 obrien Exp $";
-#endif
-
-#include <sys/types.h>
-#include <string.h>
-
-/*
- * Copy src to string dst of size siz. At most siz-1 characters
- * will be copied. Always NUL terminates (unless siz == 0).
- * Returns strlen(src); if retval >= siz, truncation occurred.
- */
-size_t strlcpy(dst, src, siz)
- char *dst;
- const char *src;
- size_t siz;
-{
- register char *d = dst;
- register const char *s = src;
- register size_t n = siz;
-
- /* Copy as many bytes as will fit */
- if (n != 0 && --n != 0) {
- do {
- if ((*d++ = *s++) == 0)
- break;
- } while (--n != 0);
- }
-
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0) {
- if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
- while (*s++)
- ;
- }
-
- return(s - src - 1); /* count does not include NUL */
-}
diff --git a/1.2-netsec/editline/np/unvis.c b/1.2-netsec/editline/np/unvis.c
deleted file mode 100644
index f43c4c749..000000000
--- a/1.2-netsec/editline/np/unvis.c
+++ /dev/null
@@ -1,322 +0,0 @@
-/* $NetBSD: unvis.c,v 1.22 2002/03/23 17:38:27 christos Exp $ */
-
-/*-
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: unvis.c,v 1.22 2002/03/23 17:38:27 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#define __LIBC12_SOURCE__
-
-#include <sys/types.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <stdio.h>
-#include "np/vis.h"
-
-#ifdef __weak_alias
-__weak_alias(strunvis,_strunvis)
-__weak_alias(unvis,_unvis)
-#endif
-
-#ifdef __warn_references
-__warn_references(unvis,
- "warning: reference to compatibility unvis(); include <vis.h> for correct reference")
-#endif
-
-#if !HAVE_VIS_H
-/*
- * decode driven by state machine
- */
-#define S_GROUND 0 /* haven't seen escape char */
-#define S_START 1 /* start decoding special sequence */
-#define S_META 2 /* metachar started (M) */
-#define S_META1 3 /* metachar more, regular char (-) */
-#define S_CTRL 4 /* control char started (^) */
-#define S_OCTAL2 5 /* octal digit 2 */
-#define S_OCTAL3 6 /* octal digit 3 */
-#define S_HEX1 7 /* hex digit */
-#define S_HEX2 8 /* hex digit 2 */
-
-#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
-#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10))
-
-int
-unvis(cp, c, astate, flag)
- char *cp;
- int c;
- int *astate, flag;
-{
- return __unvis13(cp, (int)c, astate, flag);
-}
-
-/*
- * unvis - decode characters previously encoded by vis
- */
-int
-__unvis13(cp, c, astate, flag)
- char *cp;
- int c;
- int *astate, flag;
-{
-
- _DIAGASSERT(cp != NULL);
- _DIAGASSERT(astate != NULL);
-
- if (flag & UNVIS_END) {
- if (*astate == S_OCTAL2 || *astate == S_OCTAL3
- || *astate == S_HEX2) {
- *astate = S_GROUND;
- return (UNVIS_VALID);
- }
- return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD);
- }
-
- switch (*astate) {
-
- case S_GROUND:
- *cp = 0;
- if (c == '\\') {
- *astate = S_START;
- return (0);
- }
- if ((flag & VIS_HTTPSTYLE) && c == '%') {
- *astate = S_HEX1;
- return (0);
- }
- *cp = c;
- return (UNVIS_VALID);
-
- case S_START:
- switch(c) {
- case '\\':
- *cp = c;
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- *cp = (c - '0');
- *astate = S_OCTAL2;
- return (0);
- case 'M':
- *cp = (char)0200;
- *astate = S_META;
- return (0);
- case '^':
- *astate = S_CTRL;
- return (0);
- case 'n':
- *cp = '\n';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'r':
- *cp = '\r';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'b':
- *cp = '\b';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'a':
- *cp = '\007';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'v':
- *cp = '\v';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 't':
- *cp = '\t';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'f':
- *cp = '\f';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 's':
- *cp = ' ';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'E':
- *cp = '\033';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case '\n':
- /*
- * hidden newline
- */
- *astate = S_GROUND;
- return (UNVIS_NOCHAR);
- case '$':
- /*
- * hidden marker
- */
- *astate = S_GROUND;
- return (UNVIS_NOCHAR);
- }
- *astate = S_GROUND;
- return (UNVIS_SYNBAD);
-
- case S_META:
- if (c == '-')
- *astate = S_META1;
- else if (c == '^')
- *astate = S_CTRL;
- else {
- *astate = S_GROUND;
- return (UNVIS_SYNBAD);
- }
- return (0);
-
- case S_META1:
- *astate = S_GROUND;
- *cp |= c;
- return (UNVIS_VALID);
-
- case S_CTRL:
- if (c == '?')
- *cp |= 0177;
- else
- *cp |= c & 037;
- *astate = S_GROUND;
- return (UNVIS_VALID);
-
- case S_OCTAL2: /* second possible octal digit */
- if (isoctal(c)) {
- /*
- * yes - and maybe a third
- */
- *cp = (*cp << 3) + (c - '0');
- *astate = S_OCTAL3;
- return (0);
- }
- /*
- * no - done with current sequence, push back passed char
- */
- *astate = S_GROUND;
- return (UNVIS_VALIDPUSH);
-
- case S_OCTAL3: /* third possible octal digit */
- *astate = S_GROUND;
- if (isoctal(c)) {
- *cp = (*cp << 3) + (c - '0');
- return (UNVIS_VALID);
- }
- /*
- * we were done, push back passed char
- */
- return (UNVIS_VALIDPUSH);
- case S_HEX1:
- if (isxdigit(c)) {
- *cp = xtod(c);
- *astate = S_HEX2;
- return (0);
- }
- /*
- * no - done with current sequence, push back passed char
- */
- *astate = S_GROUND;
- return (UNVIS_VALIDPUSH);
- case S_HEX2:
- *astate = S_GROUND;
- if (isxdigit(c)) {
- *cp = xtod(c) | (*cp << 4);
- return (UNVIS_VALID);
- }
- return (UNVIS_VALIDPUSH);
- default:
- /*
- * decoder in unknown state - (probably uninitialized)
- */
- *astate = S_GROUND;
- return (UNVIS_SYNBAD);
- }
-}
-
-/*
- * strunvis - decode src into dst
- *
- * Number of chars decoded into dst is returned, -1 on error.
- * Dst is null terminated.
- */
-
-int
-strunvisx(dst, src, flag)
- char *dst;
- const char *src;
- int flag;
-{
- char c;
- char *start = dst;
- int state = 0;
-
- _DIAGASSERT(src != NULL);
- _DIAGASSERT(dst != NULL);
-
- while ((c = *src++) != '\0') {
- again:
- switch (__unvis13(dst, c, &state, flag)) {
- case UNVIS_VALID:
- dst++;
- break;
- case UNVIS_VALIDPUSH:
- dst++;
- goto again;
- case 0:
- case UNVIS_NOCHAR:
- break;
- default:
- return (-1);
- }
- }
- if (__unvis13(dst, c, &state, UNVIS_END) == UNVIS_VALID)
- dst++;
- *dst = '\0';
- return (dst - start);
-}
-
-int
-strunvis(dst, src)
- char *dst;
- const char *src;
-{
- return strunvisx(dst, src, 0);
-}
-#endif
diff --git a/1.2-netsec/editline/np/vis.c b/1.2-netsec/editline/np/vis.c
deleted file mode 100644
index 97406cdf8..000000000
--- a/1.2-netsec/editline/np/vis.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/* $NetBSD: vis.c,v 1.22 2002/03/23 17:38:27 christos Exp $ */
-
-/*-
- * Copyright (c) 1999 The NetBSD Foundation, Inc.
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: vis.c,v 1.22 2002/03/23 17:38:27 christos Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <assert.h>
-#include "np/vis.h"
-#include <stdlib.h>
-
-#ifdef __weak_alias
-__weak_alias(strsvis,_strsvis)
-__weak_alias(strsvisx,_strsvisx)
-__weak_alias(strvis,_strvis)
-__weak_alias(strvisx,_strvisx)
-__weak_alias(svis,_svis)
-__weak_alias(vis,_vis)
-#endif
-
-#if !HAVE_VIS_H
-#include <ctype.h>
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-
-#undef BELL
-#if defined(__STDC__)
-#define BELL '\a'
-#else
-#define BELL '\007'
-#endif
-
-#ifdef SOLARIS
-typedef unsigned int u_int32_t;
-#endif
-
-#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
-#define iswhite(c) (c == ' ' || c == '\t' || c == '\n')
-#define issafe(c) (c == '\b' || c == BELL || c == '\r')
-#define xtoa(c) "0123456789abcdef"[c]
-
-#define MAXEXTRAS 5
-
-
-#define MAKEEXTRALIST(flag, extra, orig) \
-do { \
- const char *o = orig; \
- char *e; \
- while (*o++) \
- continue; \
- extra = alloca((size_t)((o - orig) + MAXEXTRAS)); \
- for (o = orig, e = extra; (*e++ = *o++) != '\0';) \
- continue; \
- e--; \
- if (flag & VIS_SP) *e++ = ' '; \
- if (flag & VIS_TAB) *e++ = '\t'; \
- if (flag & VIS_NL) *e++ = '\n'; \
- if ((flag & VIS_NOSLASH) == 0) *e++ = '\\'; \
- *e = '\0'; \
-} while (/*CONSTCOND*/0)
-
-
-/*
- * This is HVIS, the macro of vis used to HTTP style (RFC 1808)
- */
-#define HVIS(dst, c, flag, nextc, extra) \
-do \
- if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) { \
- *dst++ = '%'; \
- *dst++ = xtoa(((unsigned int)c >> 4) & 0xf); \
- *dst++ = xtoa((unsigned int)c & 0xf); \
- } else { \
- SVIS(dst, c, flag, nextc, extra); \
- } \
-while (/*CONSTCOND*/0)
-
-/*
- * This is SVIS, the central macro of vis.
- * dst: Pointer to the destination buffer
- * c: Character to encode
- * flag: Flag word
- * nextc: The character following 'c'
- * extra: Pointer to the list of extra characters to be
- * backslash-protected.
- */
-#define SVIS(dst, c, flag, nextc, extra) \
-do { \
- int isextra, isc; \
- isextra = strchr(extra, c) != NULL; \
- if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || \
- ((flag & VIS_SAFE) && issafe(c)))) { \
- *dst++ = c; \
- break; \
- } \
- isc = 0; \
- if (flag & VIS_CSTYLE) { \
- switch (c) { \
- case '\n': \
- isc = 1; *dst++ = '\\'; *dst++ = 'n'; \
- break; \
- case '\r': \
- isc = 1; *dst++ = '\\'; *dst++ = 'r'; \
- break; \
- case '\b': \
- isc = 1; *dst++ = '\\'; *dst++ = 'b'; \
- break; \
- case BELL: \
- isc = 1; *dst++ = '\\'; *dst++ = 'a'; \
- break; \
- case '\v': \
- isc = 1; *dst++ = '\\'; *dst++ = 'v'; \
- break; \
- case '\t': \
- isc = 1; *dst++ = '\\'; *dst++ = 't'; \
- break; \
- case '\f': \
- isc = 1; *dst++ = '\\'; *dst++ = 'f'; \
- break; \
- case ' ': \
- isc = 1; *dst++ = '\\'; *dst++ = 's'; \
- break; \
- case '\0': \
- isc = 1; *dst++ = '\\'; *dst++ = '0'; \
- if (isoctal(nextc)) { \
- *dst++ = '0'; \
- *dst++ = '0'; \
- } \
- } \
- } \
- if (isc) break; \
- if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \
- *dst++ = '\\'; \
- *dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0'; \
- *dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0'; \
- *dst++ = (c & 07) + '0'; \
- } else { \
- if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \
- if (c & 0200) { \
- c &= 0177; *dst++ = 'M'; \
- } \
- if (iscntrl(c)) { \
- *dst++ = '^'; \
- if (c == 0177) \
- *dst++ = '?'; \
- else \
- *dst++ = c + '@'; \
- } else { \
- *dst++ = '-'; *dst++ = c; \
- } \
- } \
-} while (/*CONSTCOND*/0)
-
-
-/*
- * svis - visually encode characters, also encoding the characters
- * pointed to by `extra'
- */
-char *
-svis(dst, c, flag, nextc, extra)
- char *dst;
- int c, flag, nextc;
- const char *extra;
-{
- char *nextra;
- _DIAGASSERT(dst != NULL);
- _DIAGASSERT(extra != NULL);
- MAKEEXTRALIST(flag, nextra, extra);
- if (flag & VIS_HTTPSTYLE)
- HVIS(dst, c, flag, nextc, nextra);
- else
- SVIS(dst, c, flag, nextc, nextra);
- *dst = '\0';
- return(dst);
-}
-
-
-/*
- * strsvis, strsvisx - visually encode characters from src into dst
- *
- * Extra is a pointer to a \0-terminated list of characters to
- * be encoded, too. These functions are useful e. g. to
- * encode strings in such a way so that they are not interpreted
- * by a shell.
- *
- * Dst must be 4 times the size of src to account for possible
- * expansion. The length of dst, not including the trailing NULL,
- * is returned.
- *
- * Strsvisx encodes exactly len bytes from src into dst.
- * This is useful for encoding a block of data.
- */
-int
-strsvis(dst, src, flag, extra)
- char *dst;
- const char *src;
- int flag;
- const char *extra;
-{
- char c;
- char *start;
- char *nextra;
-
- _DIAGASSERT(dst != NULL);
- _DIAGASSERT(src != NULL);
- _DIAGASSERT(extra != NULL);
- MAKEEXTRALIST(flag, nextra, extra);
- if (flag & VIS_HTTPSTYLE) {
- for (start = dst; (c = *src++) != '\0'; /* empty */)
- HVIS(dst, c, flag, *src, nextra);
- } else {
- for (start = dst; (c = *src++) != '\0'; /* empty */)
- SVIS(dst, c, flag, *src, nextra);
- }
- *dst = '\0';
- return (dst - start);
-}
-
-
-int
-strsvisx(dst, src, len, flag, extra)
- char *dst;
- const char *src;
- size_t len;
- int flag;
- const char *extra;
-{
- char c;
- char *start;
- char *nextra;
-
- _DIAGASSERT(dst != NULL);
- _DIAGASSERT(src != NULL);
- _DIAGASSERT(extra != NULL);
- MAKEEXTRALIST(flag, nextra, extra);
-
- if (flag & VIS_HTTPSTYLE) {
- for (start = dst; len > 0; len--) {
- c = *src++;
- HVIS(dst, c, flag, len ? *src : '\0', nextra);
- }
- } else {
- for (start = dst; len > 0; len--) {
- c = *src++;
- SVIS(dst, c, flag, len ? *src : '\0', nextra);
- }
- }
- *dst = '\0';
- return (dst - start);
-}
-
-
-/*
- * vis - visually encode characters
- */
-char *
-vis(dst, c, flag, nextc)
- char *dst;
- int c, flag, nextc;
-
-{
- char *extra;
-
- _DIAGASSERT(dst != NULL);
-
- MAKEEXTRALIST(flag, extra, "");
- if (flag & VIS_HTTPSTYLE)
- HVIS(dst, c, flag, nextc, extra);
- else
- SVIS(dst, c, flag, nextc, extra);
- *dst = '\0';
- return (dst);
-}
-
-
-/*
- * strvis, strvisx - visually encode characters from src into dst
- *
- * Dst must be 4 times the size of src to account for possible
- * expansion. The length of dst, not including the trailing NULL,
- * is returned.
- *
- * Strvisx encodes exactly len bytes from src into dst.
- * This is useful for encoding a block of data.
- */
-int
-strvis(dst, src, flag)
- char *dst;
- const char *src;
- int flag;
-{
- char *extra;
-
- MAKEEXTRALIST(flag, extra, "");
- return (strsvis(dst, src, flag, extra));
-}
-
-
-int
-strvisx(dst, src, len, flag)
- char *dst;
- const char *src;
- size_t len;
- int flag;
-{
- char *extra;
-
- MAKEEXTRALIST(flag, extra, "");
- return (strsvisx(dst, src, len, flag, extra));
-}
-#endif
diff --git a/1.2-netsec/editline/np/vis.h b/1.2-netsec/editline/np/vis.h
deleted file mode 100644
index 0739c1dfa..000000000
--- a/1.2-netsec/editline/np/vis.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/* $NetBSD: vis.h,v 1.12 2002/03/23 17:39:05 christos Exp $ */
-
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)vis.h 8.1 (Berkeley) 6/2/93
- */
-
-#ifndef _VIS_H_
-#define _VIS_H_
-
-/*
- * to select alternate encoding format
- */
-#define VIS_OCTAL 0x01 /* use octal \ddd format */
-#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropiate */
-
-/*
- * to alter set of characters encoded (default is to encode all
- * non-graphic except space, tab, and newline).
- */
-#define VIS_SP 0x04 /* also encode space */
-#define VIS_TAB 0x08 /* also encode tab */
-#define VIS_NL 0x10 /* also encode newline */
-#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
-#define VIS_SAFE 0x20 /* only encode "unsafe" characters */
-
-/*
- * other
- */
-#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
-#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */
-
-/*
- * unvis return codes
- */
-#define UNVIS_VALID 1 /* character valid */
-#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */
-#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */
-#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */
-#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */
-
-/*
- * unvis flags
- */
-#define UNVIS_END 1 /* no more characters */
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-char *vis __P((char *, int, int, int));
-char *svis __P((char *, int, int, int, const char *));
-int strvis __P((char *, const char *, int));
-int strsvis __P((char *, const char *, int, const char *));
-int strvisx __P((char *, const char *, size_t, int));
-int strsvisx __P((char *, const char *, size_t, int, const char *));
-int strunvis __P((char *, const char *));
-int strunvisx __P((char *, const char *, int));
-#ifdef __LIBC12_SOURCE__
-int unvis __P((char *, int, int *, int));
-int __unvis13 __P((char *, int, int *, int));
-#else
-int unvis __P((char *, int, int *, int)) __RENAME(__unvis13);
-#endif
-__END_DECLS
-
-#endif /* !_VIS_H_ */
diff --git a/1.2-netsec/editline/parse.c b/1.2-netsec/editline/parse.c
deleted file mode 100644
index 0a34f0b15..000000000
--- a/1.2-netsec/editline/parse.c
+++ /dev/null
@@ -1,259 +0,0 @@
-/* $NetBSD: parse.c,v 1.15 2002/03/18 16:00:56 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: parse.c,v 1.15 2002/03/18 16:00:56 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * parse.c: parse an editline extended command
- *
- * commands are:
- *
- * bind
- * echotc
- * edit
- * gettc
- * history
- * settc
- * setty
- */
-#include "el.h"
-#include "tokenizer.h"
-#include <stdlib.h>
-
-private const struct {
- const char *name;
- int (*func)(EditLine *, int, const char **);
-} cmds[] = {
- { "bind", map_bind },
- { "echotc", term_echotc },
- { "edit", el_editmode },
- { "history", hist_list },
- { "telltc", term_telltc },
- { "settc", term_settc },
- { "setty", tty_stty },
- { NULL, NULL }
-};
-
-
-/* parse_line():
- * Parse a line and dispatch it
- */
-protected int
-parse_line(EditLine *el, const char *line)
-{
- const char **argv;
- int argc;
- Tokenizer *tok;
-
- tok = tok_init(NULL);
- tok_line(tok, line, &argc, &argv);
- argc = el_parse(el, argc, argv);
- tok_end(tok);
- return (argc);
-}
-
-
-/* el_parse():
- * Command dispatcher
- */
-public int
-el_parse(EditLine *el, int argc, const char *argv[])
-{
- const char *ptr;
- int i;
-
- if (argc < 1)
- return (-1);
- ptr = strchr(argv[0], ':');
- if (ptr != NULL) {
- char *tprog;
- size_t l;
-
- if (ptr == argv[0])
- return (0);
- l = ptr - argv[0] - 1;
- tprog = (char *) el_malloc(l + 1);
- if (tprog == NULL)
- return (0);
- (void) strncpy(tprog, argv[0], l);
- tprog[l] = '\0';
- ptr++;
- l = el_match(el->el_prog, tprog);
- el_free(tprog);
- if (!l)
- return (0);
- } else
- ptr = argv[0];
-
- for (i = 0; cmds[i].name != NULL; i++)
- if (strcmp(cmds[i].name, ptr) == 0) {
- i = (*cmds[i].func) (el, argc, argv);
- return (-i);
- }
- return (-1);
-}
-
-
-/* parse__escape():
- * Parse a string of the form ^<char> \<odigit> \<char> and return
- * the appropriate character or -1 if the escape is not valid
- */
-protected int
-parse__escape(const char **const ptr)
-{
- const char *p;
- int c;
-
- p = *ptr;
-
- if (p[1] == 0)
- return (-1);
-
- if (*p == '\\') {
- p++;
- switch (*p) {
- case 'a':
- c = '\007'; /* Bell */
- break;
- case 'b':
- c = '\010'; /* Backspace */
- break;
- case 't':
- c = '\011'; /* Horizontal Tab */
- break;
- case 'n':
- c = '\012'; /* New Line */
- break;
- case 'v':
- c = '\013'; /* Vertical Tab */
- break;
- case 'f':
- c = '\014'; /* Form Feed */
- break;
- case 'r':
- c = '\015'; /* Carriage Return */
- break;
- case 'e':
- c = '\033'; /* Escape */
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- {
- int cnt, ch;
-
- for (cnt = 0, c = 0; cnt < 3; cnt++) {
- ch = *p++;
- if (ch < '0' || ch > '7') {
- p--;
- break;
- }
- c = (c << 3) | (ch - '0');
- }
- if ((c & 0xffffff00) != 0)
- return (-1);
- --p;
- break;
- }
- default:
- c = *p;
- break;
- }
- } else if (*p == '^' && isalpha((unsigned char) p[1])) {
- p++;
- c = (*p == '?') ? '\177' : (*p & 0237);
- } else
- c = *p;
- *ptr = ++p;
- return (c);
-}
-/* parse__string():
- * Parse the escapes from in and put the raw string out
- */
-protected char *
-parse__string(char *out, const char *in)
-{
- char *rv = out;
- int n;
-
- for (;;)
- switch (*in) {
- case '\0':
- *out = '\0';
- return (rv);
-
- case '\\':
- case '^':
- if ((n = parse__escape(&in)) == -1)
- return (NULL);
- *out++ = n;
- break;
-
- default:
- *out++ = *in++;
- break;
- }
-}
-
-
-/* parse_cmd():
- * Return the command number for the command string given
- * or -1 if one is not found
- */
-protected int
-parse_cmd(EditLine *el, const char *cmd)
-{
- el_bindings_t *b;
-
- for (b = el->el_map.help; b->name != NULL; b++)
- if (strcmp(b->name, cmd) == 0)
- return (b->func);
- return (-1);
-}
diff --git a/1.2-netsec/editline/parse.h b/1.2-netsec/editline/parse.h
deleted file mode 100644
index 4aaef2f83..000000000
--- a/1.2-netsec/editline/parse.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* $NetBSD: parse.h,v 1.4 2000/09/04 22:06:31 lukem Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)parse.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.parse.h: Parser functions
- */
-#ifndef _h_el_parse
-#define _h_el_parse
-
-protected int parse_line(EditLine *, const char *);
-protected int parse__escape(const char ** const);
-protected char *parse__string(char *, const char *);
-protected int parse_cmd(EditLine *, const char *);
-
-#endif /* _h_el_parse */
diff --git a/1.2-netsec/editline/prompt.c b/1.2-netsec/editline/prompt.c
deleted file mode 100644
index 5c069e17a..000000000
--- a/1.2-netsec/editline/prompt.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/* $NetBSD: prompt.c,v 1.9 2002/03/18 16:00:56 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: prompt.c,v 1.9 2002/03/18 16:00:56 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * prompt.c: Prompt printing functions
- */
-#include <stdio.h>
-#include "el.h"
-
-private char *prompt_default(EditLine *);
-private char *prompt_default_r(EditLine *);
-
-/* prompt_default():
- * Just a default prompt, in case the user did not provide one
- */
-private char *
-/*ARGSUSED*/
-prompt_default(EditLine *el)
-{
- static char a[3] = {'?', ' ', '\0'};
-
- return (a);
-}
-
-
-/* prompt_default_r():
- * Just a default rprompt, in case the user did not provide one
- */
-private char *
-/*ARGSUSED*/
-prompt_default_r(EditLine *el)
-{
- static char a[1] = {'\0'};
-
- return (a);
-}
-
-
-/* prompt_print():
- * Print the prompt and update the prompt position.
- * We use an array of integers in case we want to pass
- * literal escape sequences in the prompt and we want a
- * bit to flag them
- */
-protected void
-prompt_print(EditLine *el, int op)
-{
- el_prompt_t *elp;
- char *p;
-
- if (op == EL_PROMPT)
- elp = &el->el_prompt;
- else
- elp = &el->el_rprompt;
- p = (elp->p_func) (el);
- while (*p)
- re_putc(el, *p++, 1);
-
- elp->p_pos.v = el->el_refresh.r_cursor.v;
- elp->p_pos.h = el->el_refresh.r_cursor.h;
-}
-
-
-/* prompt_init():
- * Initialize the prompt stuff
- */
-protected int
-prompt_init(EditLine *el)
-{
-
- el->el_prompt.p_func = prompt_default;
- el->el_prompt.p_pos.v = 0;
- el->el_prompt.p_pos.h = 0;
- el->el_rprompt.p_func = prompt_default_r;
- el->el_rprompt.p_pos.v = 0;
- el->el_rprompt.p_pos.h = 0;
- return (0);
-}
-
-
-/* prompt_end():
- * Clean up the prompt stuff
- */
-protected void
-/*ARGSUSED*/
-prompt_end(EditLine *el)
-{
-}
-
-
-/* prompt_set():
- * Install a prompt printing function
- */
-protected int
-prompt_set(EditLine *el, el_pfunc_t prf, int op)
-{
- el_prompt_t *p;
-
- if (op == EL_PROMPT)
- p = &el->el_prompt;
- else
- p = &el->el_rprompt;
- if (prf == NULL) {
- if (op == EL_PROMPT)
- p->p_func = prompt_default;
- else
- p->p_func = prompt_default_r;
- } else
- p->p_func = prf;
- p->p_pos.v = 0;
- p->p_pos.h = 0;
- return (0);
-}
-
-
-/* prompt_get():
- * Retrieve the prompt printing function
- */
-protected int
-prompt_get(EditLine *el, el_pfunc_t *prf, int op)
-{
-
- if (prf == NULL)
- return (-1);
- if (op == EL_PROMPT)
- *prf = el->el_prompt.p_func;
- else
- *prf = el->el_rprompt.p_func;
- return (0);
-}
diff --git a/1.2-netsec/editline/prompt.h b/1.2-netsec/editline/prompt.h
deleted file mode 100644
index 08810e22a..000000000
--- a/1.2-netsec/editline/prompt.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* $NetBSD: prompt.h,v 1.5 2000/09/04 22:06:31 lukem Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)prompt.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.prompt.h: Prompt printing stuff
- */
-#ifndef _h_el_prompt
-#define _h_el_prompt
-
-#include "histedit.h"
-
-typedef char * (*el_pfunc_t)(EditLine*);
-
-typedef struct el_prompt_t {
- el_pfunc_t p_func; /* Function to return the prompt */
- coord_t p_pos; /* position in the line after prompt */
-} el_prompt_t;
-
-protected void prompt_print(EditLine *, int);
-protected int prompt_set(EditLine *, el_pfunc_t, int);
-protected int prompt_get(EditLine *, el_pfunc_t *, int);
-protected int prompt_init(EditLine *);
-protected void prompt_end(EditLine *);
-
-#endif /* _h_el_prompt */
diff --git a/1.2-netsec/editline/read.c b/1.2-netsec/editline/read.c
deleted file mode 100644
index ccd0a06e5..000000000
--- a/1.2-netsec/editline/read.c
+++ /dev/null
@@ -1,555 +0,0 @@
-/* $NetBSD: read.c,v 1.21 2002/03/18 16:00:57 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: read.c,v 1.21 2002/03/18 16:00:57 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * read.c: Clean this junk up! This is horrible code.
- * Terminal read functions
- */
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "el.h"
-
-#define OKCMD -1
-
-private int read__fixio(int, int);
-private int read_preread(EditLine *);
-private int read_char(EditLine *, char *);
-private int read_getcmd(EditLine *, el_action_t *, char *);
-
-/* read_init():
- * Initialize the read stuff
- */
-protected int
-read_init(EditLine *el)
-{
- /* builtin read_char */
- el->el_read.read_char = read_char;
- return 0;
-}
-
-
-/* el_read_setfn():
- * Set the read char function to the one provided.
- * If it is set to EL_BUILTIN_GETCFN, then reset to the builtin one.
- */
-protected int
-el_read_setfn(EditLine *el, el_rfunc_t rc)
-{
- el->el_read.read_char = (rc == EL_BUILTIN_GETCFN) ? read_char : rc;
- return 0;
-}
-
-
-/* el_read_getfn():
- * return the current read char function, or EL_BUILTIN_GETCFN
- * if it is the default one
- */
-protected el_rfunc_t
-el_read_getfn(EditLine *el)
-{
- return (el->el_read.read_char == read_char) ?
- EL_BUILTIN_GETCFN : el->el_read.read_char;
-}
-
-
-#ifdef DEBUG_EDIT
-private void
-read_debug(EditLine *el)
-{
-
- if (el->el_line.cursor > el->el_line.lastchar)
- (void) fprintf(el->el_errfile, "cursor > lastchar\r\n");
- if (el->el_line.cursor < el->el_line.buffer)
- (void) fprintf(el->el_errfile, "cursor < buffer\r\n");
- if (el->el_line.cursor > el->el_line.limit)
- (void) fprintf(el->el_errfile, "cursor > limit\r\n");
- if (el->el_line.lastchar > el->el_line.limit)
- (void) fprintf(el->el_errfile, "lastchar > limit\r\n");
- if (el->el_line.limit != &el->el_line.buffer[EL_BUFSIZ - 2])
- (void) fprintf(el->el_errfile, "limit != &buffer[EL_BUFSIZ-2]\r\n");
-}
-#endif /* DEBUG_EDIT */
-
-
-/* read__fixio():
- * Try to recover from a read error
- */
-/* ARGSUSED */
-private int
-read__fixio(int fd, int e)
-{
-
- switch (e) {
- case -1: /* Make sure that the code is reachable */
-
-#ifdef EWOULDBLOCK
- case EWOULDBLOCK:
-#ifndef TRY_AGAIN
-#define TRY_AGAIN
-#endif
-#endif /* EWOULDBLOCK */
-
-#if defined(POSIX) && defined(EAGAIN)
-#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
- case EAGAIN:
-#ifndef TRY_AGAIN
-#define TRY_AGAIN
-#endif
-#endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
-#endif /* POSIX && EAGAIN */
-
- e = 0;
-#ifdef TRY_AGAIN
-#if defined(F_SETFL) && defined(O_NDELAY)
- if ((e = fcntl(fd, F_GETFL, 0)) == -1)
- return (-1);
-
- if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
- return (-1);
- else
- e = 1;
-#endif /* F_SETFL && O_NDELAY */
-
-#ifdef FIONBIO
- {
- int zero = 0;
-
- if (ioctl(fd, FIONBIO, (ioctl_t) & zero) == -1)
- return (-1);
- else
- e = 1;
- }
-#endif /* FIONBIO */
-
-#endif /* TRY_AGAIN */
- return (e ? 0 : -1);
-
- case EINTR:
- return (0);
-
- default:
- return (-1);
- }
-}
-
-
-/* read_preread():
- * Try to read the stuff in the input queue;
- */
-private int
-read_preread(EditLine *el)
-{
- int chrs = 0;
-
- if (el->el_chared.c_macro.nline) {
- el_free((ptr_t) el->el_chared.c_macro.nline);
- el->el_chared.c_macro.nline = NULL;
- }
- if (el->el_tty.t_mode == ED_IO)
- return (0);
-
-#ifdef FIONREAD
- (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
- if (chrs > 0) {
- char buf[EL_BUFSIZ];
-
- chrs = read(el->el_infd, buf,
- (size_t) MIN(chrs, EL_BUFSIZ - 1));
- if (chrs > 0) {
- buf[chrs] = '\0';
- el->el_chared.c_macro.nline = strdup(buf);
- el_push(el, el->el_chared.c_macro.nline);
- }
- }
-#endif /* FIONREAD */
-
- return (chrs > 0);
-}
-
-
-/* el_push():
- * Push a macro
- */
-public void
-el_push(EditLine *el, char *str)
-{
- c_macro_t *ma = &el->el_chared.c_macro;
-
- if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
- ma->level++;
- ma->macro[ma->level] = str;
- } else {
- term_beep(el);
- term__flush();
- }
-}
-
-
-/* read_getcmd():
- * Return next command from the input stream.
- */
-private int
-read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
-{
- el_action_t cmd = ED_UNASSIGNED;
- int num;
-
- while (cmd == ED_UNASSIGNED || cmd == ED_SEQUENCE_LEAD_IN) {
- if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
- return (num);
-
-#ifdef KANJI
- if ((*ch & 0200)) {
- el->el_state.metanext = 0;
- cmd = CcViMap[' '];
- break;
- } else
-#endif /* KANJI */
-
- if (el->el_state.metanext) {
- el->el_state.metanext = 0;
- *ch |= 0200;
- }
- cmd = el->el_map.current[(unsigned char) *ch];
- if (cmd == ED_SEQUENCE_LEAD_IN) {
- key_value_t val;
- switch (key_get(el, ch, &val)) {
- case XK_CMD:
- cmd = val.cmd;
- break;
- case XK_STR:
- el_push(el, val.str);
- break;
-#ifdef notyet
- case XK_EXE:
- /* XXX: In the future to run a user function */
- RunCommand(val.str);
- break;
-#endif
- default:
- EL_ABORT((el->el_errfile, "Bad XK_ type \n"));
- break;
- }
- }
- if (el->el_map.alt == NULL)
- el->el_map.current = el->el_map.key;
- }
- *cmdnum = cmd;
- return (OKCMD);
-}
-
-
-/* read_char():
- * Read a character from the tty.
- */
-private int
-read_char(EditLine *el, char *cp)
-{
- int num_read;
- int tried = 0;
-
- while ((num_read = read(el->el_infd, cp, 1)) == -1)
- if (!tried && read__fixio(el->el_infd, errno) == 0)
- tried = 1;
- else {
- *cp = '\0';
- return (-1);
- }
-
- return (num_read);
-}
-
-
-/* el_getc():
- * Read a character
- */
-public int
-el_getc(EditLine *el, char *cp)
-{
- int num_read;
- c_macro_t *ma = &el->el_chared.c_macro;
-
- term__flush();
- for (;;) {
- if (ma->level < 0) {
- if (!read_preread(el))
- break;
- }
- if (ma->level < 0)
- break;
-
- if (*ma->macro[ma->level] == 0) {
- ma->level--;
- continue;
- }
- *cp = *ma->macro[ma->level]++ & 0377;
- if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode
- * On */
- ma->level--;
- }
- return (1);
- }
-
-#ifdef DEBUG_READ
- (void) fprintf(el->el_errfile, "Turning raw mode on\n");
-#endif /* DEBUG_READ */
- if (tty_rawmode(el) < 0)/* make sure the tty is set up correctly */
- return (0);
-
-#ifdef DEBUG_READ
- (void) fprintf(el->el_errfile, "Reading a character\n");
-#endif /* DEBUG_READ */
- num_read = (*el->el_read.read_char)(el, cp);
-#ifdef DEBUG_READ
- (void) fprintf(el->el_errfile, "Got it %c\n", *cp);
-#endif /* DEBUG_READ */
- return (num_read);
-}
-
-
-public const char *
-el_gets(EditLine *el, int *nread)
-{
- int retval;
- el_action_t cmdnum = 0;
- int num; /* how many chars we have read at NL */
- char ch;
-#ifdef FIONREAD
- c_macro_t *ma = &el->el_chared.c_macro;
-#endif /* FIONREAD */
-
- if (el->el_flags & HANDLE_SIGNALS)
- sig_set(el);
-
- if (el->el_flags & NO_TTY) {
- char *cp = el->el_line.buffer;
- size_t idx;
-
- while ((*el->el_read.read_char)(el, cp) == 1) {
- /* make sure there is space for next character */
- if (cp + 1 >= el->el_line.limit) {
- idx = (cp - el->el_line.buffer);
- if (!ch_enlargebufs(el, 2))
- break;
- cp = &el->el_line.buffer[idx];
- }
- cp++;
- if (cp[-1] == '\r' || cp[-1] == '\n')
- break;
- }
-
- el->el_line.cursor = el->el_line.lastchar = cp;
- *cp = '\0';
- if (nread)
- *nread = el->el_line.cursor - el->el_line.buffer;
- return (el->el_line.buffer);
- }
- re_clear_display(el); /* reset the display stuff */
- ch_reset(el);
-
-#ifdef FIONREAD
- if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
- long chrs = 0;
-
- (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
- if (chrs == 0) {
- if (tty_rawmode(el) < 0) {
- if (nread)
- *nread = 0;
- return (NULL);
- }
- }
- }
-#endif /* FIONREAD */
-
- re_refresh(el); /* print the prompt */
-
- if (el->el_flags & EDIT_DISABLED) {
- char *cp = el->el_line.buffer;
- size_t idx;
-
- term__flush();
-
- while ((*el->el_read.read_char)(el, cp) == 1) {
- /* make sure there is space next character */
- if (cp + 1 >= el->el_line.limit) {
- idx = (cp - el->el_line.buffer);
- if (!ch_enlargebufs(el, 2))
- break;
- cp = &el->el_line.buffer[idx];
- }
- cp++;
- if (cp[-1] == '\r' || cp[-1] == '\n')
- break;
- }
-
- el->el_line.cursor = el->el_line.lastchar = cp;
- *cp = '\0';
- if (nread)
- *nread = el->el_line.cursor - el->el_line.buffer;
- return (el->el_line.buffer);
- }
- for (num = OKCMD; num == OKCMD;) { /* while still editing this
- * line */
-#ifdef DEBUG_EDIT
- read_debug(el);
-#endif /* DEBUG_EDIT */
- /* if EOF or error */
- if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
-#ifdef DEBUG_READ
- (void) fprintf(el->el_errfile,
- "Returning from el_gets %d\n", num);
-#endif /* DEBUG_READ */
- break;
- }
- if ((int) cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
-#ifdef DEBUG_EDIT
- (void) fprintf(el->el_errfile,
- "ERROR: illegal command from key 0%o\r\n", ch);
-#endif /* DEBUG_EDIT */
- continue; /* try again */
- }
- /* now do the real command */
-#ifdef DEBUG_READ
- {
- el_bindings_t *b;
- for (b = el->el_map.help; b->name; b++)
- if (b->func == cmdnum)
- break;
- if (b->name)
- (void) fprintf(el->el_errfile,
- "Executing %s\n", b->name);
- else
- (void) fprintf(el->el_errfile,
- "Error command = %d\n", cmdnum);
- }
-#endif /* DEBUG_READ */
- retval = (*el->el_map.func[cmdnum]) (el, ch);
-
- /* save the last command here */
- el->el_state.lastcmd = cmdnum;
-
- /* use any return value */
- switch (retval) {
- case CC_CURSOR:
- el->el_state.argument = 1;
- el->el_state.doingarg = 0;
- re_refresh_cursor(el);
- break;
-
- case CC_REDISPLAY:
- re_clear_lines(el);
- re_clear_display(el);
- /* FALLTHROUGH */
-
- case CC_REFRESH:
- el->el_state.argument = 1;
- el->el_state.doingarg = 0;
- re_refresh(el);
- break;
-
- case CC_REFRESH_BEEP:
- el->el_state.argument = 1;
- el->el_state.doingarg = 0;
- re_refresh(el);
- term_beep(el);
- break;
-
- case CC_NORM: /* normal char */
- el->el_state.argument = 1;
- el->el_state.doingarg = 0;
- break;
-
- case CC_ARGHACK: /* Suggested by Rich Salz */
- /* <rsalz@pineapple.bbn.com> */
- break; /* keep going... */
-
- case CC_EOF: /* end of file typed */
- num = 0;
- break;
-
- case CC_NEWLINE: /* normal end of line */
- num = el->el_line.lastchar - el->el_line.buffer;
- break;
-
- case CC_FATAL: /* fatal error, reset to known state */
-#ifdef DEBUG_READ
- (void) fprintf(el->el_errfile,
- "*** editor fatal ERROR ***\r\n\n");
-#endif /* DEBUG_READ */
- /* put (real) cursor in a known place */
- re_clear_display(el); /* reset the display stuff */
- ch_reset(el); /* reset the input pointers */
- re_refresh(el); /* print the prompt again */
- el->el_state.argument = 1;
- el->el_state.doingarg = 0;
- break;
-
- case CC_ERROR:
- default: /* functions we don't know about */
-#ifdef DEBUG_READ
- (void) fprintf(el->el_errfile,
- "*** editor ERROR ***\r\n\n");
-#endif /* DEBUG_READ */
- el->el_state.argument = 1;
- el->el_state.doingarg = 0;
- term_beep(el);
- term__flush();
- break;
- }
- }
-
- /* make sure the tty is set up correctly */
- (void) tty_cookedmode(el);
- term__flush(); /* flush any buffered output */
- if (el->el_flags & HANDLE_SIGNALS)
- sig_clr(el);
- if (nread)
- *nread = num;
- return (num ? el->el_line.buffer : NULL);
-}
diff --git a/1.2-netsec/editline/read.h b/1.2-netsec/editline/read.h
deleted file mode 100644
index b01e77db2..000000000
--- a/1.2-netsec/editline/read.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* $NetBSD: read.h,v 1.1 2001/09/27 19:29:50 christos Exp $ */
-
-/*-
- * Copyright (c) 2001 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Anthony Mallet.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * el.read.h: Character reading functions
- */
-#ifndef _h_el_read
-#define _h_el_read
-
-typedef int (*el_rfunc_t)(EditLine *, char *);
-
-typedef struct el_read_t {
- el_rfunc_t read_char; /* Function to read a character */
-} el_read_t;
-
-protected int read_init(EditLine *);
-protected int el_read_setfn(EditLine *, el_rfunc_t);
-protected el_rfunc_t el_read_getfn(EditLine *);
-
-#endif /* _h_el_read */
diff --git a/1.2-netsec/editline/readline.c b/1.2-netsec/editline/readline.c
deleted file mode 100644
index 2d398e12a..000000000
--- a/1.2-netsec/editline/readline.c
+++ /dev/null
@@ -1,1664 +0,0 @@
-/* $NetBSD: readline.c,v 1.21 2002/03/18 16:20:36 christos Exp $ */
-
-/*-
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jaromir Dolecek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.21 2002/03/18 16:20:36 christos Exp $");
-#endif /* not lint && not SCCSID */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <string.h>
-#include <pwd.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <limits.h>
-#include "histedit.h"
-#include "readline/readline.h"
-#include "el.h"
-#include "fcns.h" /* for EL_NUM_FCNS */
-
-/* for rl_complete() */
-#define TAB '\r'
-
-/* see comment at the #ifdef for sense of this */
-#define GDB_411_HACK
-
-/* readline compatibility stuff - look at readline sources/documentation */
-/* to see what these variables mean */
-const char *rl_library_version = "EditLine wrapper";
-static char empty[] = { '\0' };
-static char expand_chars[] = { ' ', '\t', '\n', '=', '(', '\0' };
-static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$',
- '>', '<', '=', ';', '|', '&', '{', '(', '\0' };
-char *rl_readline_name = empty;
-FILE *rl_instream = NULL;
-FILE *rl_outstream = NULL;
-int rl_point = 0;
-int rl_end = 0;
-char *rl_line_buffer = NULL;
-
-int history_base = 1; /* probably never subject to change */
-int history_length = 0;
-int max_input_history = 0;
-char history_expansion_char = '!';
-char history_subst_char = '^';
-char *history_no_expand_chars = expand_chars;
-Function *history_inhibit_expansion_function = NULL;
-
-int rl_inhibit_completion = 0;
-int rl_attempted_completion_over = 0;
-char *rl_basic_word_break_characters = break_chars;
-char *rl_completer_word_break_characters = NULL;
-char *rl_completer_quote_characters = NULL;
-CPFunction *rl_completion_entry_function = NULL;
-CPPFunction *rl_attempted_completion_function = NULL;
-
-/*
- * This is set to character indicating type of completion being done by
- * rl_complete_internal(); this is available for application completion
- * functions.
- */
-int rl_completion_type = 0;
-
-/*
- * If more than this number of items results from query for possible
- * completions, we ask user if they are sure to really display the list.
- */
-int rl_completion_query_items = 100;
-
-/*
- * List of characters which are word break characters, but should be left
- * in the parsed text when it is passed to the completion function.
- * Shell uses this to help determine what kind of completing to do.
- */
-char *rl_special_prefixes = (char *)NULL;
-
-/*
- * This is the character appended to the completed words if at the end of
- * the line. Default is ' ' (a space).
- */
-int rl_completion_append_character = ' ';
-
-/* stuff below is used internally by libedit for readline emulation */
-
-/* if not zero, non-unique completions always show list of possible matches */
-static int _rl_complete_show_all = 0;
-
-static History *h = NULL;
-static EditLine *e = NULL;
-static int el_rl_complete_cmdnum = 0;
-
-/* internal functions */
-static unsigned char _el_rl_complete(EditLine *, int);
-static char *_get_prompt(EditLine *);
-static HIST_ENTRY *_move_history(int);
-static int _history_search_gen(const char *, int, int);
-static int _history_expand_command(const char *, size_t, char **);
-static char *_rl_compat_sub(const char *, const char *,
- const char *, int);
-static int rl_complete_internal(int);
-static int _rl_qsort_string_compare(const void *, const void *);
-
-/*
- * needed for prompt switching in readline()
- */
-static char *el_rl_prompt = NULL;
-
-
-/* ARGSUSED */
-static char *
-_get_prompt(EditLine *el)
-{
- return (el_rl_prompt);
-}
-
-
-/*
- * generic function for moving around history
- */
-static HIST_ENTRY *
-_move_history(int op)
-{
- HistEvent ev;
- static HIST_ENTRY rl_he;
-
- if (history(h, &ev, op) != 0)
- return (HIST_ENTRY *) NULL;
-
- rl_he.line = ev.str;
- rl_he.data = "";
-
- return (&rl_he);
-}
-
-
-/*
- * READLINE compatibility stuff
- */
-
-/*
- * initialize rl compat stuff
- */
-int
-rl_initialize(void)
-{
- HistEvent ev;
- const LineInfo *li;
- int i;
- int editmode = 1;
- struct termios t;
-
- if (e != NULL)
- el_end(e);
- if (h != NULL)
- history_end(h);
-
- if (!rl_instream)
- rl_instream = stdin;
- if (!rl_outstream)
- rl_outstream = stdout;
-
- /*
- * See if we don't really want to run the editor
- */
- if (tcgetattr(fileno(rl_instream), &t) != -1 && (t.c_lflag & ECHO) == 0)
- editmode = 0;
-
- e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr);
-
- if (!editmode)
- el_set(e, EL_EDITMODE, 0);
-
- h = history_init();
- if (!e || !h)
- return (-1);
-
- history(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */
- history_length = 0;
- max_input_history = INT_MAX;
- el_set(e, EL_HIST, history, h);
-
- /* for proper prompt printing in readline() */
- el_rl_prompt = strdup("");
- el_set(e, EL_PROMPT, _get_prompt);
- el_set(e, EL_SIGNAL, 1);
-
- /* set default mode to "emacs"-style and read setting afterwards */
- /* so this can be overriden */
- el_set(e, EL_EDITOR, "emacs");
-
- /*
- * Word completition - this has to go AFTER rebinding keys
- * to emacs-style.
- */
- el_set(e, EL_ADDFN, "rl_complete",
- "ReadLine compatible completition function",
- _el_rl_complete);
- el_set(e, EL_BIND, "^I", "rl_complete", NULL);
-
- /*
- * Find out where the rl_complete function was added; this is
- * used later to detect that lastcmd was also rl_complete.
- */
- for(i=EL_NUM_FCNS; i < e->el_map.nfunc; i++) {
- if (e->el_map.func[i] == _el_rl_complete) {
- el_rl_complete_cmdnum = i;
- break;
- }
- }
-
- /* read settings from configuration file */
- el_source(e, NULL);
-
- /*
- * Unfortunately, some applications really do use rl_point
- * and rl_line_buffer directly.
- */
- li = el_line(e);
- /* a cheesy way to get rid of const cast. */
- rl_line_buffer = memchr(li->buffer, *li->buffer, 1);
- rl_point = rl_end = 0;
-
- return (0);
-}
-
-
-/*
- * read one line from input stream and return it, chomping
- * trailing newline (if there is any)
- */
-char *
-readline(const char *prompt)
-{
- HistEvent ev;
- int count;
- const char *ret;
- char *buf;
-
- if (e == NULL || h == NULL)
- rl_initialize();
-
- /* update prompt accordingly to what has been passed */
- if (!prompt)
- prompt = "";
- if (strcmp(el_rl_prompt, prompt) != 0) {
- free(el_rl_prompt);
- el_rl_prompt = strdup(prompt);
- }
- /* get one line from input stream */
- ret = el_gets(e, &count);
-
- if (ret && count > 0) {
- int lastidx;
-
- buf = strdup(ret);
- lastidx = count - 1;
- if (buf[lastidx] == '\n')
- buf[lastidx] = '\0';
- } else
- buf = NULL;
-
- history(h, &ev, H_GETSIZE);
- history_length = ev.num;
-
- return buf;
-}
-
-/*
- * history functions
- */
-
-/*
- * is normally called before application starts to use
- * history expansion functions
- */
-void
-using_history(void)
-{
- if (h == NULL || e == NULL)
- rl_initialize();
-}
-
-
-/*
- * substitute ``what'' with ``with'', returning resulting string; if
- * globally == 1, substitutes all occurences of what, otherwise only the
- * first one
- */
-static char *
-_rl_compat_sub(const char *str, const char *what, const char *with,
- int globally)
-{
- char *result;
- const char *temp, *new;
- int len, with_len, what_len, add;
- size_t size, i;
-
- result = malloc((size = 16));
- temp = str;
- with_len = strlen(with);
- what_len = strlen(what);
- len = 0;
- do {
- new = strstr(temp, what);
- if (new) {
- i = new - temp;
- add = i + with_len;
- if (i + add + 1 >= size) {
- size += add + 1;
- result = realloc(result, size);
- }
- (void) strncpy(&result[len], temp, i);
- len += i;
- (void) strcpy(&result[len], with); /* safe */
- len += with_len;
- temp = new + what_len;
- } else {
- add = strlen(temp);
- if (len + add + 1 >= size) {
- size += add + 1;
- result = realloc(result, size);
- }
- (void) strcpy(&result[len], temp); /* safe */
- len += add;
- temp = NULL;
- }
- } while (temp && globally);
- result[len] = '\0';
-
- return (result);
-}
-
-
-/*
- * the real function doing history expansion - takes as argument command
- * to do and data upon which the command should be executed
- * does expansion the way I've understood readline documentation
- * word designator ``%'' isn't supported (yet ?)
- *
- * returns 0 if data was not modified, 1 if it was and 2 if the string
- * should be only printed and not executed; in case of error,
- * returns -1 and *result points to NULL
- * it's callers responsibility to free() string returned in *result
- */
-static int
-_history_expand_command(const char *command, size_t cmdlen, char **result)
-{
- char **arr, *tempcmd, *line, *search = NULL, *cmd;
- const char *event_data = NULL;
- static char *from = NULL, *to = NULL;
- int start = -1, end = -1, max, i, idx;
- int h_on = 0, t_on = 0, r_on = 0, e_on = 0, p_on = 0, g_on = 0;
- int event_num = 0, retval;
- size_t cmdsize;
-
- *result = NULL;
-
- cmd = alloca(cmdlen + 1);
- (void) strncpy(cmd, command, cmdlen);
- cmd[cmdlen] = 0;
-
- idx = 1;
- /* find out which event to take */
- if (cmd[idx] == history_expansion_char) {
- event_num = history_length;
- idx++;
- } else {
- int off, num;
- size_t len;
- off = idx;
- while (cmd[off] && !strchr(":^$*-%", cmd[off]))
- off++;
- num = atoi(&cmd[idx]);
- if (num != 0) {
- event_num = num;
- if (num < 0)
- event_num += history_length + 1;
- } else {
- int prefix = 1, curr_num;
- HistEvent ev;
-
- len = off - idx;
- if (cmd[idx] == '?') {
- idx++, len--;
- if (cmd[off - 1] == '?')
- len--;
- else if (cmd[off] != '\n' && cmd[off] != '\0')
- return (-1);
- prefix = 0;
- }
- search = alloca(len + 1);
- (void) strncpy(search, &cmd[idx], len);
- search[len] = '\0';
-
- if (history(h, &ev, H_CURR) != 0)
- return (-1);
- curr_num = ev.num;
-
- if (prefix)
- retval = history_search_prefix(search, -1);
- else
- retval = history_search(search, -1);
-
- if (retval == -1) {
- fprintf(rl_outstream, "%s: Event not found\n",
- search);
- return (-1);
- }
- if (history(h, &ev, H_CURR) != 0)
- return (-1);
- event_data = ev.str;
-
- /* roll back to original position */
- history(h, &ev, H_NEXT_EVENT, curr_num);
- }
- idx = off;
- }
-
- if (!event_data && event_num >= 0) {
- HIST_ENTRY *rl_he;
- rl_he = history_get(event_num);
- if (!rl_he)
- return (0);
- event_data = rl_he->line;
- } else
- return (-1);
-
- if (cmd[idx] != ':')
- return (-1);
- cmd += idx + 1;
-
- /* recognize cmd */
- if (*cmd == '^')
- start = end = 1, cmd++;
- else if (*cmd == '$')
- start = end = -1, cmd++;
- else if (*cmd == '*')
- start = 1, end = -1, cmd++;
- else if (isdigit((unsigned char) *cmd)) {
- const char *temp;
- int shifted = 0;
-
- start = atoi(cmd);
- temp = cmd;
- for (; isdigit((unsigned char) *cmd); cmd++);
- if (temp != cmd)
- shifted = 1;
- if (shifted && *cmd == '-') {
- if (!isdigit((unsigned char) *(cmd + 1)))
- end = -2;
- else {
- end = atoi(cmd + 1);
- for (; isdigit((unsigned char) *cmd); cmd++);
- }
- } else if (shifted && *cmd == '*')
- end = -1, cmd++;
- else if (shifted)
- end = start;
- }
- if (*cmd == ':')
- cmd++;
-
- line = strdup(event_data);
- for (; *cmd; cmd++) {
- if (*cmd == ':')
- continue;
- else if (*cmd == 'h')
- h_on = 1 | g_on, g_on = 0;
- else if (*cmd == 't')
- t_on = 1 | g_on, g_on = 0;
- else if (*cmd == 'r')
- r_on = 1 | g_on, g_on = 0;
- else if (*cmd == 'e')
- e_on = 1 | g_on, g_on = 0;
- else if (*cmd == 'p')
- p_on = 1 | g_on, g_on = 0;
- else if (*cmd == 'g')
- g_on = 2;
- else if (*cmd == 's' || *cmd == '&') {
- char *what, *with, delim;
- int len, from_len;
- size_t size;
-
- if (*cmd == '&' && (from == NULL || to == NULL))
- continue;
- else if (*cmd == 's') {
- delim = *(++cmd), cmd++;
- size = 16;
- what = realloc(from, size);
- len = 0;
- for (; *cmd && *cmd != delim; cmd++) {
- if (*cmd == '\\'
- && *(cmd + 1) == delim)
- cmd++;
- if (len >= size)
- what = realloc(what,
- (size <<= 1));
- what[len++] = *cmd;
- }
- what[len] = '\0';
- from = what;
- if (*what == '\0') {
- free(what);
- if (search)
- from = strdup(search);
- else {
- from = NULL;
- return (-1);
- }
- }
- cmd++; /* shift after delim */
- if (!*cmd)
- continue;
-
- size = 16;
- with = realloc(to, size);
- len = 0;
- from_len = strlen(from);
- for (; *cmd && *cmd != delim; cmd++) {
- if (len + from_len + 1 >= size) {
- size += from_len + 1;
- with = realloc(with, size);
- }
- if (*cmd == '&') {
- /* safe */
- (void) strcpy(&with[len], from);
- len += from_len;
- continue;
- }
- if (*cmd == '\\'
- && (*(cmd + 1) == delim
- || *(cmd + 1) == '&'))
- cmd++;
- with[len++] = *cmd;
- }
- with[len] = '\0';
- to = with;
-
- tempcmd = _rl_compat_sub(line, from, to,
- (g_on) ? 1 : 0);
- free(line);
- line = tempcmd;
- g_on = 0;
- }
- }
- }
-
- arr = history_tokenize(line);
- free(line); /* no more needed */
- if (arr && *arr == NULL)
- free(arr), arr = NULL;
- if (!arr)
- return (-1);
-
- /* find out max valid idx to array of array */
- max = 0;
- for (i = 0; arr[i]; i++)
- max++;
- max--;
-
- /* set boundaries to something relevant */
- if (start < 0)
- start = 1;
- if (end < 0)
- end = max - ((end < -1) ? 1 : 0);
-
- /* check boundaries ... */
- if (start > max || end > max || start > end)
- return (-1);
-
- for (i = 0; i <= max; i++) {
- char *temp;
- if (h_on && (i == 1 || h_on > 1) &&
- (temp = strrchr(arr[i], '/')))
- *(temp + 1) = '\0';
- if (t_on && (i == 1 || t_on > 1) &&
- (temp = strrchr(arr[i], '/')))
- (void) strcpy(arr[i], temp + 1);
- if (r_on && (i == 1 || r_on > 1) &&
- (temp = strrchr(arr[i], '.')))
- *temp = '\0';
- if (e_on && (i == 1 || e_on > 1) &&
- (temp = strrchr(arr[i], '.')))
- (void) strcpy(arr[i], temp);
- }
-
- cmdsize = 1, cmdlen = 0;
- tempcmd = malloc(cmdsize);
- for (i = start; start <= i && i <= end; i++) {
- int arr_len;
-
- arr_len = strlen(arr[i]);
- if (cmdlen + arr_len + 1 >= cmdsize) {
- cmdsize += arr_len + 1;
- tempcmd = realloc(tempcmd, cmdsize);
- }
- (void) strcpy(&tempcmd[cmdlen], arr[i]); /* safe */
- cmdlen += arr_len;
- tempcmd[cmdlen++] = ' '; /* add a space */
- }
- while (cmdlen > 0 && isspace((unsigned char) tempcmd[cmdlen - 1]))
- cmdlen--;
- tempcmd[cmdlen] = '\0';
-
- *result = tempcmd;
-
- for (i = 0; i <= max; i++)
- free(arr[i]);
- free(arr), arr = (char **) NULL;
- return (p_on) ? 2 : 1;
-}
-
-
-/*
- * csh-style history expansion
- */
-int
-history_expand(char *str, char **output)
-{
- int i, retval = 0, idx;
- size_t size;
- char *temp, *result;
-
- if (h == NULL || e == NULL)
- rl_initialize();
-
- *output = strdup(str); /* do it early */
-
- if (str[0] == history_subst_char) {
- /* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */
- temp = alloca(4 + strlen(str) + 1);
- temp[0] = temp[1] = history_expansion_char;
- temp[2] = ':';
- temp[3] = 's';
- (void) strcpy(temp + 4, str);
- str = temp;
- }
-#define ADD_STRING(what, len) \
- { \
- if (idx + len + 1 > size) \
- result = realloc(result, (size += len + 1)); \
- (void)strncpy(&result[idx], what, len); \
- idx += len; \
- result[idx] = '\0'; \
- }
-
- result = NULL;
- size = idx = 0;
- for (i = 0; str[i];) {
- int start, j, loop_again;
- size_t len;
-
- loop_again = 1;
- start = j = i;
-loop:
- for (; str[j]; j++) {
- if (str[j] == '\\' &&
- str[j + 1] == history_expansion_char) {
- (void) strcpy(&str[j], &str[j + 1]);
- continue;
- }
- if (!loop_again) {
- if (str[j] == '?') {
- while (str[j] && str[++j] != '?');
- if (str[j] == '?')
- j++;
- } else if (isspace((unsigned char) str[j]))
- break;
- }
- if (str[j] == history_expansion_char
- && !strchr(history_no_expand_chars, str[j + 1])
- && (!history_inhibit_expansion_function ||
- (*history_inhibit_expansion_function)(str, j) == 0))
- break;
- }
-
- if (str[j] && str[j + 1] != '#' && loop_again) {
- i = j;
- j++;
- if (str[j] == history_expansion_char)
- j++;
- loop_again = 0;
- goto loop;
- }
- len = i - start;
- temp = &str[start];
- ADD_STRING(temp, len);
-
- if (str[i] == '\0' || str[i] != history_expansion_char
- || str[i + 1] == '#') {
- len = j - i;
- temp = &str[i];
- ADD_STRING(temp, len);
- if (start == 0)
- retval = 0;
- else
- retval = 1;
- break;
- }
- retval = _history_expand_command(&str[i], (size_t) (j - i),
- &temp);
- if (retval != -1) {
- len = strlen(temp);
- ADD_STRING(temp, len);
- }
- i = j;
- } /* for(i ...) */
-
- if (retval == 2) {
- add_history(temp);
-#ifdef GDB_411_HACK
- /* gdb 4.11 has been shipped with readline, where */
- /* history_expand() returned -1 when the line */
- /* should not be executed; in readline 2.1+ */
- /* it should return 2 in such a case */
- retval = -1;
-#endif
- }
- free(*output);
- *output = result;
-
- return (retval);
-}
-
-
-/*
- * Parse the string into individual tokens, similarily to how shell would do it.
- */
-char **
-history_tokenize(const char *str)
-{
- int size = 1, result_idx = 0, i, start;
- size_t len;
- char **result = NULL, *temp, delim = '\0';
-
- for (i = 0; str[i]; i++) {
- while (isspace((unsigned char) str[i]))
- i++;
- start = i;
- for (; str[i]; i++) {
- if (str[i] == '\\') {
- if (str[i+1] != '\0')
- i++;
- } else if (str[i] == delim)
- delim = '\0';
- else if (!delim &&
- (isspace((unsigned char) str[i]) ||
- strchr("()<>;&|$", str[i])))
- break;
- else if (!delim && strchr("'`\"", str[i]))
- delim = str[i];
- }
-
- if (result_idx + 2 >= size) {
- size <<= 1;
- result = realloc(result, size * sizeof(char *));
- }
- len = i - start;
- temp = malloc(len + 1);
- (void) strncpy(temp, &str[start], len);
- temp[len] = '\0';
- result[result_idx++] = temp;
- result[result_idx] = NULL;
- }
-
- return (result);
-}
-
-
-/*
- * limit size of history record to ``max'' events
- */
-void
-stifle_history(int max)
-{
- HistEvent ev;
-
- if (h == NULL || e == NULL)
- rl_initialize();
-
- if (history(h, &ev, H_SETSIZE, max) == 0)
- max_input_history = max;
-}
-
-
-/*
- * "unlimit" size of history - set the limit to maximum allowed int value
- */
-int
-unstifle_history(void)
-{
- HistEvent ev;
- int omax;
-
- history(h, &ev, H_SETSIZE, INT_MAX);
- omax = max_input_history;
- max_input_history = INT_MAX;
- return (omax); /* some value _must_ be returned */
-}
-
-
-int
-history_is_stifled(void)
-{
-
- /* cannot return true answer */
- return (max_input_history != INT_MAX);
-}
-
-
-/*
- * read history from a file given
- */
-int
-read_history(const char *filename)
-{
- HistEvent ev;
-
- if (h == NULL || e == NULL)
- rl_initialize();
- return (history(h, &ev, H_LOAD, filename));
-}
-
-
-/*
- * write history to a file given
- */
-int
-write_history(const char *filename)
-{
- HistEvent ev;
-
- if (h == NULL || e == NULL)
- rl_initialize();
- return (history(h, &ev, H_SAVE, filename));
-}
-
-
-/*
- * returns history ``num''th event
- *
- * returned pointer points to static variable
- */
-HIST_ENTRY *
-history_get(int num)
-{
- static HIST_ENTRY she;
- HistEvent ev;
- int i = 1, curr_num;
-
- if (h == NULL || e == NULL)
- rl_initialize();
-
- /* rewind to beginning */
- if (history(h, &ev, H_CURR) != 0)
- return (NULL);
- curr_num = ev.num;
- if (history(h, &ev, H_LAST) != 0)
- return (NULL); /* error */
- while (i < num && history(h, &ev, H_PREV) == 0)
- i++;
- if (i != num)
- return (NULL); /* not so many entries */
-
- she.line = ev.str;
- she.data = NULL;
-
- /* rewind history to the same event it was before */
- (void) history(h, &ev, H_FIRST);
- (void) history(h, &ev, H_NEXT_EVENT, curr_num);
-
- return (&she);
-}
-
-
-/*
- * add the line to history table
- */
-int
-add_history(const char *line)
-{
- HistEvent ev;
-
- if (h == NULL || e == NULL)
- rl_initialize();
-
- (void) history(h, &ev, H_ENTER, line);
- if (history(h, &ev, H_GETSIZE) == 0)
- history_length = ev.num;
-
- return (!(history_length > 0)); /* return 0 if all is okay */
-}
-
-
-/*
- * clear the history list - delete all entries
- */
-void
-clear_history(void)
-{
- HistEvent ev;
-
- history(h, &ev, H_CLEAR);
-}
-
-
-/*
- * returns offset of the current history event
- */
-int
-where_history(void)
-{
- HistEvent ev;
- int curr_num, off;
-
- if (history(h, &ev, H_CURR) != 0)
- return (0);
- curr_num = ev.num;
-
- history(h, &ev, H_FIRST);
- off = 1;
- while (ev.num != curr_num && history(h, &ev, H_NEXT) == 0)
- off++;
-
- return (off);
-}
-
-
-/*
- * returns current history event or NULL if there is no such event
- */
-HIST_ENTRY *
-current_history(void)
-{
-
- return (_move_history(H_CURR));
-}
-
-
-/*
- * returns total number of bytes history events' data are using
- */
-int
-history_total_bytes(void)
-{
- HistEvent ev;
- int curr_num, size;
-
- if (history(h, &ev, H_CURR) != 0)
- return (-1);
- curr_num = ev.num;
-
- history(h, &ev, H_FIRST);
- size = 0;
- do
- size += strlen(ev.str);
- while (history(h, &ev, H_NEXT) == 0);
-
- /* get to the same position as before */
- history(h, &ev, H_PREV_EVENT, curr_num);
-
- return (size);
-}
-
-
-/*
- * sets the position in the history list to ``pos''
- */
-int
-history_set_pos(int pos)
-{
- HistEvent ev;
- int off, curr_num;
-
- if (pos > history_length || pos < 0)
- return (-1);
-
- history(h, &ev, H_CURR);
- curr_num = ev.num;
- history(h, &ev, H_FIRST);
- off = 0;
- while (off < pos && history(h, &ev, H_NEXT) == 0)
- off++;
-
- if (off != pos) { /* do a rollback in case of error */
- history(h, &ev, H_FIRST);
- history(h, &ev, H_NEXT_EVENT, curr_num);
- return (-1);
- }
- return (0);
-}
-
-
-/*
- * returns previous event in history and shifts pointer accordingly
- */
-HIST_ENTRY *
-previous_history(void)
-{
-
- return (_move_history(H_PREV));
-}
-
-
-/*
- * returns next event in history and shifts pointer accordingly
- */
-HIST_ENTRY *
-next_history(void)
-{
-
- return (_move_history(H_NEXT));
-}
-
-
-/*
- * generic history search function
- */
-static int
-_history_search_gen(const char *str, int direction, int pos)
-{
- HistEvent ev;
- const char *strp;
- int curr_num;
-
- if (history(h, &ev, H_CURR) != 0)
- return (-1);
- curr_num = ev.num;
-
- for (;;) {
- strp = strstr(ev.str, str);
- if (strp && (pos < 0 || &ev.str[pos] == strp))
- return (int) (strp - ev.str);
- if (history(h, &ev, direction < 0 ? H_PREV : H_NEXT) != 0)
- break;
- }
-
- history(h, &ev, direction < 0 ? H_NEXT_EVENT : H_PREV_EVENT, curr_num);
-
- return (-1);
-}
-
-
-/*
- * searches for first history event containing the str
- */
-int
-history_search(const char *str, int direction)
-{
-
- return (_history_search_gen(str, direction, -1));
-}
-
-
-/*
- * searches for first history event beginning with str
- */
-int
-history_search_prefix(const char *str, int direction)
-{
-
- return (_history_search_gen(str, direction, 0));
-}
-
-
-/*
- * search for event in history containing str, starting at offset
- * abs(pos); continue backward, if pos<0, forward otherwise
- */
-/* ARGSUSED */
-int
-history_search_pos(const char *str, int direction, int pos)
-{
- HistEvent ev;
- int curr_num, off;
-
- off = (pos > 0) ? pos : -pos;
- pos = (pos > 0) ? 1 : -1;
-
- if (history(h, &ev, H_CURR) != 0)
- return (-1);
- curr_num = ev.num;
-
- if (history_set_pos(off) != 0 || history(h, &ev, H_CURR) != 0)
- return (-1);
-
-
- for (;;) {
- if (strstr(ev.str, str))
- return (off);
- if (history(h, &ev, (pos < 0) ? H_PREV : H_NEXT) != 0)
- break;
- }
-
- /* set "current" pointer back to previous state */
- history(h, &ev, (pos < 0) ? H_NEXT_EVENT : H_PREV_EVENT, curr_num);
-
- return (-1);
-}
-
-
-/********************************/
-/* completition functions */
-
-/*
- * does tilde expansion of strings of type ``~user/foo''
- * if ``user'' isn't valid user name or ``txt'' doesn't start
- * w/ '~', returns pointer to strdup()ed copy of ``txt''
- *
- * it's callers's responsibility to free() returned string
- */
-char *
-tilde_expand(char *txt)
-{
- struct passwd *pass;
- char *temp;
- size_t len = 0;
-
- if (txt[0] != '~')
- return (strdup(txt));
-
- temp = strchr(txt + 1, '/');
- if (temp == NULL)
- temp = strdup(txt + 1);
- else {
- len = temp - txt + 1; /* text until string after slash */
- temp = malloc(len);
- (void) strncpy(temp, txt + 1, len - 2);
- temp[len - 2] = '\0';
- }
- pass = getpwnam(temp);
- free(temp); /* value no more needed */
- if (pass == NULL)
- return (strdup(txt));
-
- /* update pointer txt to point at string immedially following */
- /* first slash */
- txt += len;
-
- temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1);
- (void) sprintf(temp, "%s/%s", pass->pw_dir, txt);
-
- return (temp);
-}
-
-
-/*
- * return first found file name starting by the ``text'' or NULL if no
- * such file can be found
- * value of ``state'' is ignored
- *
- * it's caller's responsibility to free returned string
- */
-char *
-filename_completion_function(const char *text, int state)
-{
- static DIR *dir = NULL;
- static char *filename = NULL, *dirname = NULL;
- static size_t filename_len = 0;
- struct dirent *entry;
- char *temp;
- size_t len;
-
- if (state == 0 || dir == NULL) {
- if (dir != NULL) {
- closedir(dir);
- dir = NULL;
- }
- temp = strrchr(text, '/');
- if (temp) {
- temp++;
- filename = realloc(filename, strlen(temp) + 1);
- (void) strcpy(filename, temp);
- len = temp - text; /* including last slash */
- dirname = realloc(dirname, len + 1);
- (void) strncpy(dirname, text, len);
- dirname[len] = '\0';
- } else {
- filename = strdup(text);
- dirname = NULL;
- }
-
- /* support for ``~user'' syntax */
- if (dirname && *dirname == '~') {
- temp = tilde_expand(dirname);
- dirname = realloc(dirname, strlen(temp) + 1);
- (void) strcpy(dirname, temp); /* safe */
- free(temp); /* no longer needed */
- }
- /* will be used in cycle */
- filename_len = strlen(filename);
- if (filename_len == 0)
- return (NULL); /* no expansion possible */
-
- dir = opendir(dirname ? dirname : ".");
- if (!dir)
- return (NULL); /* cannot open the directory */
- }
- /* find the match */
- while ((entry = readdir(dir)) != NULL) {
- /* otherwise, get first entry where first */
- /* filename_len characters are equal */
- if (entry->d_name[0] == filename[0]
-#if defined(__SVR4) || defined(__linux__)
- && strlen(entry->d_name) >= filename_len
-#else
- && entry->d_namlen >= filename_len
-#endif
- && strncmp(entry->d_name, filename,
- filename_len) == 0)
- break;
- }
-
- if (entry) { /* match found */
-
- struct stat stbuf;
-#if defined(__SVR4) || defined(__linux__)
- len = strlen(entry->d_name) +
-#else
- len = entry->d_namlen +
-#endif
- ((dirname) ? strlen(dirname) : 0) + 1 + 1;
- temp = malloc(len);
- (void) sprintf(temp, "%s%s",
- dirname ? dirname : "", entry->d_name); /* safe */
-
- /* test, if it's directory */
- if (stat(temp, &stbuf) == 0 && S_ISDIR(stbuf.st_mode))
- strcat(temp, "/"); /* safe */
- } else
- temp = NULL;
-
- return (temp);
-}
-
-
-/*
- * a completion generator for usernames; returns _first_ username
- * which starts with supplied text
- * text contains a partial username preceded by random character
- * (usually '~'); state is ignored
- * it's callers responsibility to free returned value
- */
-char *
-username_completion_function(const char *text, int state)
-{
- struct passwd *pwd;
-
- if (text[0] == '\0')
- return (NULL);
-
- if (*text == '~')
- text++;
-
- if (state == 0)
- setpwent();
-
- while ((pwd = getpwent()) && text[0] == pwd->pw_name[0]
- && strcmp(text, pwd->pw_name) == 0);
-
- if (pwd == NULL) {
- endpwent();
- return (NULL);
- }
- return (strdup(pwd->pw_name));
-}
-
-
-/*
- * el-compatible wrapper around rl_complete; needed for key binding
- */
-/* ARGSUSED */
-static unsigned char
-_el_rl_complete(EditLine *el, int ch)
-{
- return (unsigned char) rl_complete(0, ch);
-}
-
-
-/*
- * returns list of completitions for text given
- */
-char **
-completion_matches(const char *text, CPFunction *genfunc)
-{
- char **match_list = NULL, *retstr, *prevstr;
- size_t match_list_len, max_equal, which, i;
- int matches;
-
- if (h == NULL || e == NULL)
- rl_initialize();
-
- matches = 0;
- match_list_len = 1;
- while ((retstr = (*genfunc) (text, matches)) != NULL) {
- if (matches + 1 >= match_list_len) {
- match_list_len <<= 1;
- match_list = realloc(match_list,
- match_list_len * sizeof(char *));
- }
- match_list[++matches] = retstr;
- }
-
- if (!match_list)
- return (char **) NULL; /* nothing found */
-
- /* find least denominator and insert it to match_list[0] */
- which = 2;
- prevstr = match_list[1];
- max_equal = strlen(prevstr);
- for (; which <= matches; which++) {
- for (i = 0; i < max_equal &&
- prevstr[i] == match_list[which][i]; i++)
- continue;
- max_equal = i;
- }
-
- retstr = malloc(max_equal + 1);
- (void) strncpy(retstr, match_list[1], max_equal);
- retstr[max_equal] = '\0';
- match_list[0] = retstr;
-
- /* add NULL as last pointer to the array */
- if (matches + 1 >= match_list_len)
- match_list = realloc(match_list,
- (match_list_len + 1) * sizeof(char *));
- match_list[matches + 1] = (char *) NULL;
-
- return (match_list);
-}
-
-/*
- * Sort function for qsort(). Just wrapper around strcasecmp().
- */
-static int
-_rl_qsort_string_compare(i1, i2)
- const void *i1, *i2;
-{
- /* LINTED const castaway */
- const char *s1 = ((const char **)i1)[0];
- /* LINTED const castaway */
- const char *s2 = ((const char **)i2)[0];
-
- return strcasecmp(s1, s2);
-}
-
-/*
- * Display list of strings in columnar format on readline's output stream.
- * 'matches' is list of strings, 'len' is number of strings in 'matches',
- * 'max' is maximum length of string in 'matches'.
- */
-void
-rl_display_match_list (matches, len, max)
- char **matches;
- int len, max;
-{
- int i, idx, limit, count;
- int screenwidth = e->el_term.t_size.h;
-
- /*
- * Find out how many entries can be put on one line, count
- * with two spaces between strings.
- */
- limit = screenwidth / (max + 2);
- if (limit == 0)
- limit = 1;
-
- /* how many lines of output */
- count = len / limit;
- if (count * limit < len)
- count++;
-
- /* Sort the items if they are not already sorted. */
- qsort(&matches[1], (size_t)(len - 1), sizeof(char *),
- _rl_qsort_string_compare);
-
- idx = 1;
- for(; count > 0; count--) {
- for(i=0; i < limit && matches[idx]; i++, idx++)
- fprintf(e->el_outfile, "%-*s ", max, matches[idx]);
- fprintf(e->el_outfile, "\n");
- }
-}
-
-/*
- * Complete the word at or before point, called by rl_complete()
- * 'what_to_do' says what to do with the completion.
- * `?' means list the possible completions.
- * TAB means do standard completion.
- * `*' means insert all of the possible completions.
- * `!' means to do standard completion, and list all possible completions if
- * there is more than one.
- *
- * Note: '*' support is not implemented
- */
-static int
-rl_complete_internal(int what_to_do)
-{
- CPFunction *complet_func;
- const LineInfo *li;
- char *temp, **matches;
- const char *ctemp;
- size_t len;
-
- rl_completion_type = what_to_do;
-
- if (h == NULL || e == NULL)
- rl_initialize();
-
- complet_func = rl_completion_entry_function;
- if (!complet_func)
- complet_func = filename_completion_function;
-
- /* We now look backwards for the start of a filename/variable word */
- li = el_line(e);
- ctemp = (const char *) li->cursor;
- while (ctemp > li->buffer
- && !strchr(rl_basic_word_break_characters, ctemp[-1])
- && (!rl_special_prefixes
- || !strchr(rl_special_prefixes, ctemp[-1]) ) )
- ctemp--;
-
- len = li->cursor - ctemp;
- temp = alloca(len + 1);
- (void) strncpy(temp, ctemp, len);
- temp[len] = '\0';
-
- /* these can be used by function called in completion_matches() */
- /* or (*rl_attempted_completion_function)() */
- rl_point = li->cursor - li->buffer;
- rl_end = li->lastchar - li->buffer;
-
- if (!rl_attempted_completion_function)
- matches = completion_matches(temp, complet_func);
- else {
- int end = li->cursor - li->buffer;
- matches = (*rl_attempted_completion_function) (temp, (int)
- (end - len), end);
- }
-
- if (matches) {
- int i, retval = CC_REFRESH;
- int matches_num, maxlen, match_len, match_display=1;
-
- /*
- * Only replace the completed string with common part of
- * possible matches if there is possible completion.
- */
- if (matches[0][0] != '\0') {
- el_deletestr(e, (int) len);
- el_insertstr(e, matches[0]);
- }
-
- if (what_to_do == '?')
- goto display_matches;
-
- if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) {
- /*
- * We found exact match. Add a space after
- * it, unless we do filename completition and the
- * object is a directory.
- */
- size_t alen = strlen(matches[0]);
- if ((complet_func != filename_completion_function
- || (alen > 0 && (matches[0])[alen - 1] != '/'))
- && rl_completion_append_character) {
- char buf[2];
- buf[0] = rl_completion_append_character;
- buf[1] = '\0';
- el_insertstr(e, buf);
- }
- } else if (what_to_do == '!') {
- display_matches:
- /*
- * More than one match and requested to list possible
- * matches.
- */
-
- for(i=1, maxlen=0; matches[i]; i++) {
- match_len = strlen(matches[i]);
- if (match_len > maxlen)
- maxlen = match_len;
- }
- matches_num = i - 1;
-
- /* newline to get on next line from command line */
- fprintf(e->el_outfile, "\n");
-
- /*
- * If there are too many items, ask user for display
- * confirmation.
- */
- if (matches_num > rl_completion_query_items) {
- fprintf(e->el_outfile,
- "Display all %d possibilities? (y or n) ",
- matches_num);
- fflush(e->el_outfile);
- if (getc(stdin) != 'y')
- match_display = 0;
- fprintf(e->el_outfile, "\n");
- }
-
- if (match_display)
- rl_display_match_list(matches, matches_num,
- maxlen);
- retval = CC_REDISPLAY;
- } else if (matches[0][0]) {
- /*
- * There was some common match, but the name was
- * not complete enough. Next tab will print possible
- * completions.
- */
- el_beep(e);
- } else {
- /* lcd is not a valid object - further specification */
- /* is needed */
- el_beep(e);
- retval = CC_NORM;
- }
-
- /* free elements of array and the array itself */
- for (i = 0; matches[i]; i++)
- free(matches[i]);
- free(matches), matches = NULL;
-
- return (retval);
- }
- return (CC_NORM);
-}
-
-
-/*
- * complete word at current point
- */
-int
-rl_complete(int ignore, int invoking_key)
-{
- if (h == NULL || e == NULL)
- rl_initialize();
-
- if (rl_inhibit_completion) {
- rl_insert(ignore, invoking_key);
- return (CC_REFRESH);
- } else if (e->el_state.lastcmd == el_rl_complete_cmdnum)
- return rl_complete_internal('?');
- else if (_rl_complete_show_all)
- return rl_complete_internal('!');
- else
- return (rl_complete_internal(TAB));
-}
-
-
-/*
- * misc other functions
- */
-
-/*
- * bind key c to readline-type function func
- */
-int
-rl_bind_key(int c, int func(int, int))
-{
- int retval = -1;
-
- if (h == NULL || e == NULL)
- rl_initialize();
-
- if (func == rl_insert) {
- /* XXX notice there is no range checking of ``c'' */
- e->el_map.key[c] = ED_INSERT;
- retval = 0;
- }
- return (retval);
-}
-
-
-/*
- * read one key from input - handles chars pushed back
- * to input stream also
- */
-int
-rl_read_key(void)
-{
- char fooarr[2 * sizeof(int)];
-
- if (e == NULL || h == NULL)
- rl_initialize();
-
- return (el_getc(e, fooarr));
-}
-
-
-/*
- * reset the terminal
- */
-/* ARGSUSED */
-void
-rl_reset_terminal(const char *p)
-{
-
- if (h == NULL || e == NULL)
- rl_initialize();
- el_reset(e);
-}
-
-
-/*
- * insert character ``c'' back into input stream, ``count'' times
- */
-int
-rl_insert(int count, int c)
-{
- char arr[2];
-
- if (h == NULL || e == NULL)
- rl_initialize();
-
- /* XXX - int -> char conversion can lose on multichars */
- arr[0] = c;
- arr[1] = '\0';
-
- for (; count > 0; count--)
- el_push(e, arr);
-
- return (0);
-}
diff --git a/1.2-netsec/editline/readline/readline.h b/1.2-netsec/editline/readline/readline.h
deleted file mode 100644
index 7485dde40..000000000
--- a/1.2-netsec/editline/readline/readline.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/* $NetBSD: readline.h,v 1.1 2001/01/05 21:15:50 jdolecek Exp $ */
-
-/*-
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jaromir Dolecek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef _READLINE_H_
-#define _READLINE_H_
-
-#include <sys/types.h>
-
-/* list of readline stuff supported by editline library's readline wrapper */
-
-/* typedefs */
-typedef int Function(const char *, int);
-typedef void VFunction(void);
-typedef char *CPFunction(const char *, int);
-typedef char **CPPFunction(const char *, int, int);
-
-typedef struct _hist_entry {
- const char *line;
- const char *data;
-} HIST_ENTRY;
-
-/* global variables used by readline enabled applications */
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern const char *rl_library_version;
-extern char *rl_readline_name;
-extern FILE *rl_instream;
-extern FILE *rl_outstream;
-extern char *rl_line_buffer;
-extern int rl_point, rl_end;
-extern int history_base, history_length;
-extern int max_input_history;
-extern char *rl_basic_word_break_characters;
-extern char *rl_completer_word_break_characters;
-extern char *rl_completer_quote_characters;
-extern CPFunction *rl_completion_entry_function;
-extern CPPFunction *rl_attempted_completion_function;
-extern int rl_completion_type;
-extern int rl_completion_query_items;
-extern char *rl_special_prefixes;
-extern int rl_completion_append_character;
-
-/* supported functions */
-char *readline(const char *);
-int rl_initialize(void);
-
-void using_history(void);
-int add_history(const char *);
-void clear_history(void);
-void stifle_history(int);
-int unstifle_history(void);
-int history_is_stifled(void);
-int where_history(void);
-HIST_ENTRY *current_history(void);
-HIST_ENTRY *history_get(int);
-int history_total_bytes(void);
-int history_set_pos(int);
-HIST_ENTRY *previous_history(void);
-HIST_ENTRY *next_history(void);
-int history_search(const char *, int);
-int history_search_prefix(const char *, int);
-int history_search_pos(const char *, int, int);
-int read_history(const char *);
-int write_history(const char *);
-int history_expand(char *, char **);
-char **history_tokenize(const char *);
-
-char *tilde_expand(char *);
-char *filename_completion_function(const char *, int);
-char *username_completion_function(const char *, int);
-int rl_complete(int, int);
-int rl_read_key(void);
-char **completion_matches(const char *, CPFunction *);
-void rl_display_match_list(char **, int, int);
-
-int rl_insert(int, int);
-void rl_reset_terminal(const char *);
-int rl_bind_key(int, int (*)(int, int));
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _READLINE_H_ */
diff --git a/1.2-netsec/editline/refresh.c b/1.2-netsec/editline/refresh.c
deleted file mode 100644
index 935117741..000000000
--- a/1.2-netsec/editline/refresh.c
+++ /dev/null
@@ -1,1104 +0,0 @@
-/* $NetBSD: refresh.c,v 1.18 2002/03/18 16:00:58 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: refresh.c,v 1.18 2002/03/18 16:00:58 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * refresh.c: Lower level screen refreshing functions
- */
-#include <stdio.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "el.h"
-
-private void re_addc(EditLine *, int);
-private void re_update_line(EditLine *, char *, char *, int);
-private void re_insert (EditLine *, char *, int, int, char *, int);
-private void re_delete(EditLine *, char *, int, int, int);
-private void re_fastputc(EditLine *, int);
-private void re__strncopy(char *, char *, size_t);
-private void re__copy_and_pad(char *, const char *, size_t);
-
-#ifdef DEBUG_REFRESH
-private void re_printstr(EditLine *, char *, char *, char *);
-#define __F el->el_errfile
-#define ELRE_ASSERT(a, b, c) do \
- if (a) { \
- (void) fprintf b; \
- c; \
- } \
- while (0)
-#define ELRE_DEBUG(a, b) ELRE_ASSERT(a,b,;)
-
-/* re_printstr():
- * Print a string on the debugging pty
- */
-private void
-re_printstr(EditLine *el, char *str, char *f, char *t)
-{
-
- ELRE_DEBUG(1, (__F, "%s:\"", str));
- while (f < t)
- ELRE_DEBUG(1, (__F, "%c", *f++ & 0177));
- ELRE_DEBUG(1, (__F, "\"\r\n"));
-}
-#else
-#define ELRE_ASSERT(a, b, c)
-#define ELRE_DEBUG(a, b)
-#endif
-
-
-/* re_addc():
- * Draw c, expanding tabs, control chars etc.
- */
-private void
-re_addc(EditLine *el, int c)
-{
-
- if (isprint(c)) {
- re_putc(el, c, 1);
- return;
- }
- if (c == '\n') { /* expand the newline */
- int oldv = el->el_refresh.r_cursor.v;
- re_putc(el, '\0', 0); /* assure end of line */
- if (oldv == el->el_refresh.r_cursor.v) { /* XXX */
- el->el_refresh.r_cursor.h = 0; /* reset cursor pos */
- el->el_refresh.r_cursor.v++;
- }
- return;
- }
- if (c == '\t') { /* expand the tab */
- for (;;) {
- re_putc(el, ' ', 1);
- if ((el->el_refresh.r_cursor.h & 07) == 0)
- break; /* go until tab stop */
- }
- } else if (iscntrl(c)) {
- re_putc(el, '^', 1);
- if (c == '\177')
- re_putc(el, '?', 1);
- else
- /* uncontrolify it; works only for iso8859-1 like sets */
- re_putc(el, (c | 0100), 1);
- } else {
- re_putc(el, '\\', 1);
- re_putc(el, (int) ((((unsigned int) c >> 6) & 07) + '0'), 1);
- re_putc(el, (int) ((((unsigned int) c >> 3) & 07) + '0'), 1);
- re_putc(el, (c & 07) + '0', 1);
- }
-}
-
-
-/* re_putc():
- * Draw the character given
- */
-protected void
-re_putc(EditLine *el, int c, int shift)
-{
-
- ELRE_DEBUG(1, (__F, "printing %3.3o '%c'\r\n", c, c));
-
- el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_refresh.r_cursor.h] = c;
- if (!shift)
- return;
-
- el->el_refresh.r_cursor.h++; /* advance to next place */
- if (el->el_refresh.r_cursor.h >= el->el_term.t_size.h) {
- el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h] = '\0';
- /* assure end of line */
- el->el_refresh.r_cursor.h = 0; /* reset it. */
-
- /*
- * If we would overflow (input is longer than terminal size),
- * emulate scroll by dropping first line and shuffling the rest.
- * We do this via pointer shuffling - it's safe in this case
- * and we avoid memcpy().
- */
- if (el->el_refresh.r_cursor.v + 1 >= el->el_term.t_size.v) {
- int i, lins = el->el_term.t_size.v;
- char *firstline = el->el_vdisplay[0];
-
- for(i=1; i < lins; i++)
- el->el_vdisplay[i-1] = el->el_vdisplay[i];
-
- firstline[0] = '\0'; /* empty the string */
- el->el_vdisplay[i-1] = firstline;
- } else
- el->el_refresh.r_cursor.v++;
-
- ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
- (__F, "\r\nre_putc: overflow! r_cursor.v == %d > %d\r\n",
- el->el_refresh.r_cursor.v, el->el_term.t_size.v),
- abort());
- }
-}
-
-
-/* re_refresh():
- * draws the new virtual screen image from the current input
- * line, then goes line-by-line changing the real image to the new
- * virtual image. The routine to re-draw a line can be replaced
- * easily in hopes of a smarter one being placed there.
- */
-protected void
-re_refresh(EditLine *el)
-{
- int i, rhdiff;
- char *cp, *st;
- coord_t cur;
-#ifdef notyet
- size_t termsz;
-#endif
-
- ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%s:\r\n",
- el->el_line.buffer));
-
- /* reset the Drawing cursor */
- el->el_refresh.r_cursor.h = 0;
- el->el_refresh.r_cursor.v = 0;
-
- /* temporarily draw rprompt to calculate its size */
- prompt_print(el, EL_RPROMPT);
-
- /* reset the Drawing cursor */
- el->el_refresh.r_cursor.h = 0;
- el->el_refresh.r_cursor.v = 0;
-
- cur.h = -1; /* set flag in case I'm not set */
- cur.v = 0;
-
- prompt_print(el, EL_PROMPT);
-
- /* draw the current input buffer */
-#if notyet
- termsz = el->el_term.t_size.h * el->el_term.t_size.v;
- if (el->el_line.lastchar - el->el_line.buffer > termsz) {
- /*
- * If line is longer than terminal, process only part
- * of line which would influence display.
- */
- size_t rem = (el->el_line.lastchar-el->el_line.buffer)%termsz;
-
- st = el->el_line.lastchar - rem
- - (termsz - (((rem / el->el_term.t_size.v) - 1)
- * el->el_term.t_size.v));
- } else
-#endif
- st = el->el_line.buffer;
-
- for (cp = st; cp < el->el_line.lastchar; cp++) {
- if (cp == el->el_line.cursor) {
- /* save for later */
- cur.h = el->el_refresh.r_cursor.h;
- cur.v = el->el_refresh.r_cursor.v;
- }
- re_addc(el, (unsigned char) *cp);
- }
-
- if (cur.h == -1) { /* if I haven't been set yet, I'm at the end */
- cur.h = el->el_refresh.r_cursor.h;
- cur.v = el->el_refresh.r_cursor.v;
- }
- rhdiff = el->el_term.t_size.h - el->el_refresh.r_cursor.h -
- el->el_rprompt.p_pos.h;
- if (el->el_rprompt.p_pos.h && !el->el_rprompt.p_pos.v &&
- !el->el_refresh.r_cursor.v && rhdiff > 1) {
- /*
- * have a right-hand side prompt that will fit
- * on the end of the first line with at least
- * one character gap to the input buffer.
- */
- while (--rhdiff > 0) /* pad out with spaces */
- re_putc(el, ' ', 1);
- prompt_print(el, EL_RPROMPT);
- } else {
- el->el_rprompt.p_pos.h = 0; /* flag "not using rprompt" */
- el->el_rprompt.p_pos.v = 0;
- }
-
- re_putc(el, '\0', 0); /* make line ended with NUL, no cursor shift */
-
- el->el_refresh.r_newcv = el->el_refresh.r_cursor.v;
-
- ELRE_DEBUG(1, (__F,
- "term.h=%d vcur.h=%d vcur.v=%d vdisplay[0]=\r\n:%80.80s:\r\n",
- el->el_term.t_size.h, el->el_refresh.r_cursor.h,
- el->el_refresh.r_cursor.v, el->el_vdisplay[0]));
-
- ELRE_DEBUG(1, (__F, "updating %d lines.\r\n", el->el_refresh.r_newcv));
- for (i = 0; i <= el->el_refresh.r_newcv; i++) {
- /* NOTE THAT re_update_line MAY CHANGE el_display[i] */
- re_update_line(el, el->el_display[i], el->el_vdisplay[i], i);
-
- /*
- * Copy the new line to be the current one, and pad out with
- * spaces to the full width of the terminal so that if we try
- * moving the cursor by writing the character that is at the
- * end of the screen line, it won't be a NUL or some old
- * leftover stuff.
- */
- re__copy_and_pad(el->el_display[i], el->el_vdisplay[i],
- (size_t) el->el_term.t_size.h);
- }
- ELRE_DEBUG(1, (__F,
- "\r\nel->el_refresh.r_cursor.v=%d,el->el_refresh.r_oldcv=%d i=%d\r\n",
- el->el_refresh.r_cursor.v, el->el_refresh.r_oldcv, i));
-
- if (el->el_refresh.r_oldcv > el->el_refresh.r_newcv)
- for (; i <= el->el_refresh.r_oldcv; i++) {
- term_move_to_line(el, i);
- term_move_to_char(el, 0);
- term_clear_EOL(el, (int) strlen(el->el_display[i]));
-#ifdef DEBUG_REFRESH
- term_overwrite(el, "C\b", 2);
-#endif /* DEBUG_REFRESH */
- el->el_display[i][0] = '\0';
- }
-
- el->el_refresh.r_oldcv = el->el_refresh.r_newcv; /* set for next time */
- ELRE_DEBUG(1, (__F,
- "\r\ncursor.h = %d, cursor.v = %d, cur.h = %d, cur.v = %d\r\n",
- el->el_refresh.r_cursor.h, el->el_refresh.r_cursor.v,
- cur.h, cur.v));
- term_move_to_line(el, cur.v); /* go to where the cursor is */
- term_move_to_char(el, cur.h);
-}
-
-
-/* re_goto_bottom():
- * used to go to last used screen line
- */
-protected void
-re_goto_bottom(EditLine *el)
-{
-
- term_move_to_line(el, el->el_refresh.r_oldcv);
- term__putc('\r');
- term__putc('\n');
- re_clear_display(el);
- term__flush();
-}
-
-
-/* re_insert():
- * insert num characters of s into d (in front of the character)
- * at dat, maximum length of d is dlen
- */
-private void
-/*ARGSUSED*/
-re_insert(EditLine *el, char *d, int dat, int dlen, char *s, int num)
-{
- char *a, *b;
-
- if (num <= 0)
- return;
- if (num > dlen - dat)
- num = dlen - dat;
-
- ELRE_DEBUG(1,
- (__F, "re_insert() starting: %d at %d max %d, d == \"%s\"\n",
- num, dat, dlen, d));
- ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
-
- /* open up the space for num chars */
- if (num > 0) {
- b = d + dlen - 1;
- a = b - num;
- while (a >= &d[dat])
- *b-- = *a--;
- d[dlen] = '\0'; /* just in case */
- }
- ELRE_DEBUG(1, (__F,
- "re_insert() after insert: %d at %d max %d, d == \"%s\"\n",
- num, dat, dlen, d));
- ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
-
- /* copy the characters */
- for (a = d + dat; (a < d + dlen) && (num > 0); num--)
- *a++ = *s++;
-
- ELRE_DEBUG(1,
- (__F, "re_insert() after copy: %d at %d max %d, %s == \"%s\"\n",
- num, dat, dlen, d, s));
- ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
-}
-
-
-/* re_delete():
- * delete num characters d at dat, maximum length of d is dlen
- */
-private void
-/*ARGSUSED*/
-re_delete(EditLine *el, char *d, int dat, int dlen, int num)
-{
- char *a, *b;
-
- if (num <= 0)
- return;
- if (dat + num >= dlen) {
- d[dat] = '\0';
- return;
- }
- ELRE_DEBUG(1,
- (__F, "re_delete() starting: %d at %d max %d, d == \"%s\"\n",
- num, dat, dlen, d));
-
- /* open up the space for num chars */
- if (num > 0) {
- b = d + dat;
- a = b + num;
- while (a < &d[dlen])
- *b++ = *a++;
- d[dlen] = '\0'; /* just in case */
- }
- ELRE_DEBUG(1,
- (__F, "re_delete() after delete: %d at %d max %d, d == \"%s\"\n",
- num, dat, dlen, d));
-}
-
-
-/* re__strncopy():
- * Like strncpy without padding.
- */
-private void
-re__strncopy(char *a, char *b, size_t n)
-{
-
- while (n-- && *b)
- *a++ = *b++;
-}
-
-
-/*****************************************************************
- re_update_line() is based on finding the middle difference of each line
- on the screen; vis:
-
- /old first difference
- /beginning of line | /old last same /old EOL
- v v v v
-old: eddie> Oh, my little gruntle-buggy is to me, as lurgid as
-new: eddie> Oh, my little buggy says to me, as lurgid as
- ^ ^ ^ ^
- \beginning of line | \new last same \new end of line
- \new first difference
-
- all are character pointers for the sake of speed. Special cases for
- no differences, as well as for end of line additions must be handled.
-**************************************************************** */
-
-/* Minimum at which doing an insert it "worth it". This should be about
- * half the "cost" of going into insert mode, inserting a character, and
- * going back out. This should really be calculated from the termcap
- * data... For the moment, a good number for ANSI terminals.
- */
-#define MIN_END_KEEP 4
-
-private void
-re_update_line(EditLine *el, char *old, char *new, int i)
-{
- char *o, *n, *p, c;
- char *ofd, *ols, *oe, *nfd, *nls, *ne;
- char *osb, *ose, *nsb, *nse;
- int fx, sx;
-
- /*
- * find first diff
- */
- for (o = old, n = new; *o && (*o == *n); o++, n++)
- continue;
- ofd = o;
- nfd = n;
-
- /*
- * Find the end of both old and new
- */
- while (*o)
- o++;
- /*
- * Remove any trailing blanks off of the end, being careful not to
- * back up past the beginning.
- */
- while (ofd < o) {
- if (o[-1] != ' ')
- break;
- o--;
- }
- oe = o;
- *oe = '\0';
-
- while (*n)
- n++;
-
- /* remove blanks from end of new */
- while (nfd < n) {
- if (n[-1] != ' ')
- break;
- n--;
- }
- ne = n;
- *ne = '\0';
-
- /*
- * if no diff, continue to next line of redraw
- */
- if (*ofd == '\0' && *nfd == '\0') {
- ELRE_DEBUG(1, (__F, "no difference.\r\n"));
- return;
- }
- /*
- * find last same pointer
- */
- while ((o > ofd) && (n > nfd) && (*--o == *--n))
- continue;
- ols = ++o;
- nls = ++n;
-
- /*
- * find same begining and same end
- */
- osb = ols;
- nsb = nls;
- ose = ols;
- nse = nls;
-
- /*
- * case 1: insert: scan from nfd to nls looking for *ofd
- */
- if (*ofd) {
- for (c = *ofd, n = nfd; n < nls; n++) {
- if (c == *n) {
- for (o = ofd, p = n;
- p < nls && o < ols && *o == *p;
- o++, p++)
- continue;
- /*
- * if the new match is longer and it's worth
- * keeping, then we take it
- */
- if (((nse - nsb) < (p - n)) &&
- (2 * (p - n) > n - nfd)) {
- nsb = n;
- nse = p;
- osb = ofd;
- ose = o;
- }
- }
- }
- }
- /*
- * case 2: delete: scan from ofd to ols looking for *nfd
- */
- if (*nfd) {
- for (c = *nfd, o = ofd; o < ols; o++) {
- if (c == *o) {
- for (n = nfd, p = o;
- p < ols && n < nls && *p == *n;
- p++, n++)
- continue;
- /*
- * if the new match is longer and it's worth
- * keeping, then we take it
- */
- if (((ose - osb) < (p - o)) &&
- (2 * (p - o) > o - ofd)) {
- nsb = nfd;
- nse = n;
- osb = o;
- ose = p;
- }
- }
- }
- }
- /*
- * Pragmatics I: If old trailing whitespace or not enough characters to
- * save to be worth it, then don't save the last same info.
- */
- if ((oe - ols) < MIN_END_KEEP) {
- ols = oe;
- nls = ne;
- }
- /*
- * Pragmatics II: if the terminal isn't smart enough, make the data
- * dumber so the smart update doesn't try anything fancy
- */
-
- /*
- * fx is the number of characters we need to insert/delete: in the
- * beginning to bring the two same begins together
- */
- fx = (nsb - nfd) - (osb - ofd);
- /*
- * sx is the number of characters we need to insert/delete: in the
- * end to bring the two same last parts together
- */
- sx = (nls - nse) - (ols - ose);
-
- if (!EL_CAN_INSERT) {
- if (fx > 0) {
- osb = ols;
- ose = ols;
- nsb = nls;
- nse = nls;
- }
- if (sx > 0) {
- ols = oe;
- nls = ne;
- }
- if ((ols - ofd) < (nls - nfd)) {
- ols = oe;
- nls = ne;
- }
- }
- if (!EL_CAN_DELETE) {
- if (fx < 0) {
- osb = ols;
- ose = ols;
- nsb = nls;
- nse = nls;
- }
- if (sx < 0) {
- ols = oe;
- nls = ne;
- }
- if ((ols - ofd) > (nls - nfd)) {
- ols = oe;
- nls = ne;
- }
- }
- /*
- * Pragmatics III: make sure the middle shifted pointers are correct if
- * they don't point to anything (we may have moved ols or nls).
- */
- /* if the change isn't worth it, don't bother */
- /* was: if (osb == ose) */
- if ((ose - osb) < MIN_END_KEEP) {
- osb = ols;
- ose = ols;
- nsb = nls;
- nse = nls;
- }
- /*
- * Now that we are done with pragmatics we recompute fx, sx
- */
- fx = (nsb - nfd) - (osb - ofd);
- sx = (nls - nse) - (ols - ose);
-
- ELRE_DEBUG(1, (__F, "\n"));
- ELRE_DEBUG(1, (__F, "ofd %d, osb %d, ose %d, ols %d, oe %d\n",
- ofd - old, osb - old, ose - old, ols - old, oe - old));
- ELRE_DEBUG(1, (__F, "nfd %d, nsb %d, nse %d, nls %d, ne %d\n",
- nfd - new, nsb - new, nse - new, nls - new, ne - new));
- ELRE_DEBUG(1, (__F,
- "xxx-xxx:\"00000000001111111111222222222233333333334\"\r\n"));
- ELRE_DEBUG(1, (__F,
- "xxx-xxx:\"01234567890123456789012345678901234567890\"\r\n"));
-#ifdef DEBUG_REFRESH
- re_printstr(el, "old- oe", old, oe);
- re_printstr(el, "new- ne", new, ne);
- re_printstr(el, "old-ofd", old, ofd);
- re_printstr(el, "new-nfd", new, nfd);
- re_printstr(el, "ofd-osb", ofd, osb);
- re_printstr(el, "nfd-nsb", nfd, nsb);
- re_printstr(el, "osb-ose", osb, ose);
- re_printstr(el, "nsb-nse", nsb, nse);
- re_printstr(el, "ose-ols", ose, ols);
- re_printstr(el, "nse-nls", nse, nls);
- re_printstr(el, "ols- oe", ols, oe);
- re_printstr(el, "nls- ne", nls, ne);
-#endif /* DEBUG_REFRESH */
-
- /*
- * el_cursor.v to this line i MUST be in this routine so that if we
- * don't have to change the line, we don't move to it. el_cursor.h to
- * first diff char
- */
- term_move_to_line(el, i);
-
- /*
- * at this point we have something like this:
- *
- * /old /ofd /osb /ose /ols /oe
- * v.....................v v..................v v........v
- * eddie> Oh, my fredded gruntle-buggy is to me, as foo var lurgid as
- * eddie> Oh, my fredded quiux buggy is to me, as gruntle-lurgid as
- * ^.....................^ ^..................^ ^........^
- * \new \nfd \nsb \nse \nls \ne
- *
- * fx is the difference in length between the chars between nfd and
- * nsb, and the chars between ofd and osb, and is thus the number of
- * characters to delete if < 0 (new is shorter than old, as above),
- * or insert (new is longer than short).
- *
- * sx is the same for the second differences.
- */
-
- /*
- * if we have a net insert on the first difference, AND inserting the
- * net amount ((nsb-nfd) - (osb-ofd)) won't push the last useful
- * character (which is ne if nls != ne, otherwise is nse) off the edge
- * of the screen (el->el_term.t_size.h) else we do the deletes first
- * so that we keep everything we need to.
- */
-
- /*
- * if the last same is the same like the end, there is no last same
- * part, otherwise we want to keep the last same part set p to the
- * last useful old character
- */
- p = (ols != oe) ? oe : ose;
-
- /*
- * if (There is a diffence in the beginning) && (we need to insert
- * characters) && (the number of characters to insert is less than
- * the term width)
- * We need to do an insert!
- * else if (we need to delete characters)
- * We need to delete characters!
- * else
- * No insert or delete
- */
- if ((nsb != nfd) && fx > 0 &&
- ((p - old) + fx <= el->el_term.t_size.h)) {
- ELRE_DEBUG(1,
- (__F, "first diff insert at %d...\r\n", nfd - new));
- /*
- * Move to the first char to insert, where the first diff is.
- */
- term_move_to_char(el, nfd - new);
- /*
- * Check if we have stuff to keep at end
- */
- if (nsb != ne) {
- ELRE_DEBUG(1, (__F, "with stuff to keep at end\r\n"));
- /*
- * insert fx chars of new starting at nfd
- */
- if (fx > 0) {
- ELRE_DEBUG(!EL_CAN_INSERT, (__F,
- "ERROR: cannot insert in early first diff\n"));
- term_insertwrite(el, nfd, fx);
- re_insert(el, old, ofd - old,
- el->el_term.t_size.h, nfd, fx);
- }
- /*
- * write (nsb-nfd) - fx chars of new starting at
- * (nfd + fx)
- */
- term_overwrite(el, nfd + fx, (nsb - nfd) - fx);
- re__strncopy(ofd + fx, nfd + fx,
- (size_t) ((nsb - nfd) - fx));
- } else {
- ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nfd, (nsb - nfd));
- re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
- /*
- * Done
- */
- return;
- }
- } else if (fx < 0) {
- ELRE_DEBUG(1,
- (__F, "first diff delete at %d...\r\n", ofd - old));
- /*
- * move to the first char to delete where the first diff is
- */
- term_move_to_char(el, ofd - old);
- /*
- * Check if we have stuff to save
- */
- if (osb != oe) {
- ELRE_DEBUG(1, (__F, "with stuff to save at end\r\n"));
- /*
- * fx is less than zero *always* here but we check
- * for code symmetry
- */
- if (fx < 0) {
- ELRE_DEBUG(!EL_CAN_DELETE, (__F,
- "ERROR: cannot delete in first diff\n"));
- term_deletechars(el, -fx);
- re_delete(el, old, ofd - old,
- el->el_term.t_size.h, -fx);
- }
- /*
- * write (nsb-nfd) chars of new starting at nfd
- */
- term_overwrite(el, nfd, (nsb - nfd));
- re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
-
- } else {
- ELRE_DEBUG(1, (__F,
- "but with nothing left to save\r\n"));
- /*
- * write (nsb-nfd) chars of new starting at nfd
- */
- term_overwrite(el, nfd, (nsb - nfd));
- ELRE_DEBUG(1, (__F,
- "cleareol %d\n", (oe - old) - (ne - new)));
- term_clear_EOL(el, (oe - old) - (ne - new));
- /*
- * Done
- */
- return;
- }
- } else
- fx = 0;
-
- if (sx < 0 && (ose - old) + fx < el->el_term.t_size.h) {
- ELRE_DEBUG(1, (__F,
- "second diff delete at %d...\r\n", (ose - old) + fx));
- /*
- * Check if we have stuff to delete
- */
- /*
- * fx is the number of characters inserted (+) or deleted (-)
- */
-
- term_move_to_char(el, (ose - old) + fx);
- /*
- * Check if we have stuff to save
- */
- if (ols != oe) {
- ELRE_DEBUG(1, (__F, "with stuff to save at end\r\n"));
- /*
- * Again a duplicate test.
- */
- if (sx < 0) {
- ELRE_DEBUG(!EL_CAN_DELETE, (__F,
- "ERROR: cannot delete in second diff\n"));
- term_deletechars(el, -sx);
- }
- /*
- * write (nls-nse) chars of new starting at nse
- */
- term_overwrite(el, nse, (nls - nse));
- } else {
- ELRE_DEBUG(1, (__F,
- "but with nothing left to save\r\n"));
- term_overwrite(el, nse, (nls - nse));
- ELRE_DEBUG(1, (__F,
- "cleareol %d\n", (oe - old) - (ne - new)));
- if ((oe - old) - (ne - new) != 0)
- term_clear_EOL(el, (oe - old) - (ne - new));
- }
- }
- /*
- * if we have a first insert AND WE HAVEN'T ALREADY DONE IT...
- */
- if ((nsb != nfd) && (osb - ofd) <= (nsb - nfd) && (fx == 0)) {
- ELRE_DEBUG(1, (__F, "late first diff insert at %d...\r\n",
- nfd - new));
-
- term_move_to_char(el, nfd - new);
- /*
- * Check if we have stuff to keep at the end
- */
- if (nsb != ne) {
- ELRE_DEBUG(1, (__F, "with stuff to keep at end\r\n"));
- /*
- * We have to recalculate fx here because we set it
- * to zero above as a flag saying that we hadn't done
- * an early first insert.
- */
- fx = (nsb - nfd) - (osb - ofd);
- if (fx > 0) {
- /*
- * insert fx chars of new starting at nfd
- */
- ELRE_DEBUG(!EL_CAN_INSERT, (__F,
- "ERROR: cannot insert in late first diff\n"));
- term_insertwrite(el, nfd, fx);
- re_insert(el, old, ofd - old,
- el->el_term.t_size.h, nfd, fx);
- }
- /*
- * write (nsb-nfd) - fx chars of new starting at
- * (nfd + fx)
- */
- term_overwrite(el, nfd + fx, (nsb - nfd) - fx);
- re__strncopy(ofd + fx, nfd + fx,
- (size_t) ((nsb - nfd) - fx));
- } else {
- ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nfd, (nsb - nfd));
- re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
- }
- }
- /*
- * line is now NEW up to nse
- */
- if (sx >= 0) {
- ELRE_DEBUG(1, (__F,
- "second diff insert at %d...\r\n", nse - new));
- term_move_to_char(el, nse - new);
- if (ols != oe) {
- ELRE_DEBUG(1, (__F, "with stuff to keep at end\r\n"));
- if (sx > 0) {
- /* insert sx chars of new starting at nse */
- ELRE_DEBUG(!EL_CAN_INSERT, (__F,
- "ERROR: cannot insert in second diff\n"));
- term_insertwrite(el, nse, sx);
- }
- /*
- * write (nls-nse) - sx chars of new starting at
- * (nse + sx)
- */
- term_overwrite(el, nse + sx, (nls - nse) - sx);
- } else {
- ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nse, (nls - nse));
-
- /*
- * No need to do a clear-to-end here because we were
- * doing a second insert, so we will have over
- * written all of the old string.
- */
- }
- }
- ELRE_DEBUG(1, (__F, "done.\r\n"));
-}
-
-
-/* re__copy_and_pad():
- * Copy string and pad with spaces
- */
-private void
-re__copy_and_pad(char *dst, const char *src, size_t width)
-{
- int i;
-
- for (i = 0; i < width; i++) {
- if (*src == '\0')
- break;
- *dst++ = *src++;
- }
-
- for (; i < width; i++)
- *dst++ = ' ';
-
- *dst = '\0';
-}
-
-
-/* re_refresh_cursor():
- * Move to the new cursor position
- */
-protected void
-re_refresh_cursor(EditLine *el)
-{
- char *cp, c;
- int h, v, th;
-
- /* first we must find where the cursor is... */
- h = el->el_prompt.p_pos.h;
- v = el->el_prompt.p_pos.v;
- th = el->el_term.t_size.h; /* optimize for speed */
-
- /* do input buffer to el->el_line.cursor */
- for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) {
- c = *cp;
- h++; /* all chars at least this long */
-
- if (c == '\n') {/* handle newline in data part too */
- h = 0;
- v++;
- } else {
- if (c == '\t') { /* if a tab, to next tab stop */
- while (h & 07) {
- h++;
- }
- } else if (iscntrl((unsigned char) c)) {
- /* if control char */
- h++;
- if (h > th) { /* if overflow, compensate */
- h = 1;
- v++;
- }
- } else if (!isprint((unsigned char) c)) {
- h += 3;
- if (h > th) { /* if overflow, compensate */
- h = h - th;
- v++;
- }
- }
- }
-
- if (h >= th) { /* check, extra long tabs picked up here also */
- h = 0;
- v++;
- }
- }
-
- /* now go there */
- term_move_to_line(el, v);
- term_move_to_char(el, h);
- term__flush();
-}
-
-
-/* re_fastputc():
- * Add a character fast.
- */
-private void
-re_fastputc(EditLine *el, int c)
-{
-
- term__putc(c);
- el->el_display[el->el_cursor.v][el->el_cursor.h++] = c;
- if (el->el_cursor.h >= el->el_term.t_size.h) {
- /* if we must overflow */
- el->el_cursor.h = 0;
-
- /*
- * If we would overflow (input is longer than terminal size),
- * emulate scroll by dropping first line and shuffling the rest.
- * We do this via pointer shuffling - it's safe in this case
- * and we avoid memcpy().
- */
- if (el->el_cursor.v + 1 >= el->el_term.t_size.v) {
- int i, lins = el->el_term.t_size.v;
- char *firstline = el->el_display[0];
-
- for(i=1; i < lins; i++)
- el->el_display[i-1] = el->el_display[i];
-
- re__copy_and_pad(firstline, "", 0);
- el->el_display[i-1] = firstline;
- } else {
- el->el_cursor.v++;
- el->el_refresh.r_oldcv++;
- }
- if (EL_HAS_AUTO_MARGINS) {
- if (EL_HAS_MAGIC_MARGINS) {
- term__putc(' ');
- term__putc('\b');
- }
- } else {
- term__putc('\r');
- term__putc('\n');
- }
- }
-}
-
-
-/* re_fastaddc():
- * we added just one char, handle it fast.
- * Assumes that screen cursor == real cursor
- */
-protected void
-re_fastaddc(EditLine *el)
-{
- char c;
- int rhdiff;
-
- c = el->el_line.cursor[-1];
-
- if (c == '\t' || el->el_line.cursor != el->el_line.lastchar) {
- re_refresh(el); /* too hard to handle */
- return;
- }
- rhdiff = el->el_term.t_size.h - el->el_cursor.h -
- el->el_rprompt.p_pos.h;
- if (el->el_rprompt.p_pos.h && rhdiff < 3) {
- re_refresh(el); /* clear out rprompt if less than 1 char gap */
- return;
- } /* else (only do at end of line, no TAB) */
- if (iscntrl((unsigned char) c)) { /* if control char, do caret */
- char mc = (c == '\177') ? '?' : (c | 0100);
- re_fastputc(el, '^');
- re_fastputc(el, mc);
- } else if (isprint((unsigned char) c)) { /* normal char */
- re_fastputc(el, c);
- } else {
- re_fastputc(el, '\\');
- re_fastputc(el, (int) ((((unsigned int) c >> 6) & 7) + '0'));
- re_fastputc(el, (int) ((((unsigned int) c >> 3) & 7) + '0'));
- re_fastputc(el, (c & 7) + '0');
- }
- term__flush();
-}
-
-
-/* re_clear_display():
- * clear the screen buffers so that new new prompt starts fresh.
- */
-protected void
-re_clear_display(EditLine *el)
-{
- int i;
-
- el->el_cursor.v = 0;
- el->el_cursor.h = 0;
- for (i = 0; i < el->el_term.t_size.v; i++)
- el->el_display[i][0] = '\0';
- el->el_refresh.r_oldcv = 0;
-}
-
-
-/* re_clear_lines():
- * Make sure all lines are *really* blank
- */
-protected void
-re_clear_lines(EditLine *el)
-{
-
- if (EL_CAN_CEOL) {
- int i;
- term_move_to_char(el, 0);
- for (i = 0; i <= el->el_refresh.r_oldcv; i++) {
- /* for each line on the screen */
- term_move_to_line(el, i);
- term_clear_EOL(el, el->el_term.t_size.h);
- }
- term_move_to_line(el, 0);
- } else {
- term_move_to_line(el, el->el_refresh.r_oldcv);
- /* go to last line */
- term__putc('\r'); /* go to BOL */
- term__putc('\n'); /* go to new line */
- }
-}
diff --git a/1.2-netsec/editline/refresh.h b/1.2-netsec/editline/refresh.h
deleted file mode 100644
index 33c0887c1..000000000
--- a/1.2-netsec/editline/refresh.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* $NetBSD: refresh.h,v 1.4 2001/01/10 07:45:42 jdolecek Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)refresh.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.refresh.h: Screen refresh functions
- */
-#ifndef _h_el_refresh
-#define _h_el_refresh
-
-#include "histedit.h"
-
-typedef struct {
- coord_t r_cursor; /* Refresh cursor position */
- int r_oldcv; /* Vertical locations */
- int r_newcv;
-} el_refresh_t;
-
-protected void re_putc(EditLine *, int, int);
-protected void re_clear_lines(EditLine *);
-protected void re_clear_display(EditLine *);
-protected void re_refresh(EditLine *);
-protected void re_refresh_cursor(EditLine *);
-protected void re_fastaddc(EditLine *);
-protected void re_goto_bottom(EditLine *);
-
-#endif /* _h_el_refresh */
diff --git a/1.2-netsec/editline/search.c b/1.2-netsec/editline/search.c
deleted file mode 100644
index 7c1cb84ef..000000000
--- a/1.2-netsec/editline/search.c
+++ /dev/null
@@ -1,649 +0,0 @@
-/* $NetBSD: search.c,v 1.12 2002/03/18 16:00:58 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: search.c,v 1.12 2002/03/18 16:00:58 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * search.c: History and character search functions
- */
-#include <stdlib.h>
-#if defined(REGEX)
-#include <regex.h>
-#elif defined(REGEXP)
-#include <regexp.h>
-#endif
-#include "el.h"
-
-/*
- * Adjust cursor in vi mode to include the character under it
- */
-#define EL_CURSOR(el) \
- ((el)->el_line.cursor + (((el)->el_map.type == MAP_VI) && \
- ((el)->el_map.current == (el)->el_map.alt)))
-
-/* search_init():
- * Initialize the search stuff
- */
-protected int
-search_init(EditLine *el)
-{
-
- el->el_search.patbuf = (char *) el_malloc(EL_BUFSIZ);
- if (el->el_search.patbuf == NULL)
- return (-1);
- el->el_search.patlen = 0;
- el->el_search.patdir = -1;
- el->el_search.chacha = '\0';
- el->el_search.chadir = -1;
- return (0);
-}
-
-
-/* search_end():
- * Initialize the search stuff
- */
-protected void
-search_end(EditLine *el)
-{
-
- el_free((ptr_t) el->el_search.patbuf);
- el->el_search.patbuf = NULL;
-}
-
-
-#ifdef REGEXP
-/* regerror():
- * Handle regular expression errors
- */
-public void
-/*ARGSUSED*/
-regerror(const char *msg)
-{
-}
-#endif
-
-
-/* el_match():
- * Return if string matches pattern
- */
-protected int
-el_match(const char *str, const char *pat)
-{
-#if defined (REGEX)
- regex_t re;
- int rv;
-#elif defined (REGEXP)
- regexp *rp;
- int rv;
-#else
- extern char *re_comp(const char *);
- extern int re_exec(const char *);
-#endif
-
- if (strstr(str, pat) != NULL)
- return (1);
-
-#if defined(REGEX)
- if (regcomp(&re, pat, 0) == 0) {
- rv = regexec(&re, str, 0, NULL, 0) == 0;
- regfree(&re);
- } else {
- rv = 0;
- }
- return (rv);
-#elif defined(REGEXP)
- if ((re = regcomp(pat)) != NULL) {
- rv = regexec(re, str);
- free((ptr_t) re);
- } else {
- rv = 0;
- }
- return (rv);
-#else
- if (re_comp(pat) != NULL)
- return (0);
- else
- return (re_exec(str) == 1);
-#endif
-}
-
-
-/* c_hmatch():
- * return True if the pattern matches the prefix
- */
-protected int
-c_hmatch(EditLine *el, const char *str)
-{
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "match `%s' with `%s'\n",
- el->el_search.patbuf, str);
-#endif /* SDEBUG */
-
- return (el_match(str, el->el_search.patbuf));
-}
-
-
-/* c_setpat():
- * Set the history seatch pattern
- */
-protected void
-c_setpat(EditLine *el)
-{
- if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY &&
- el->el_state.lastcmd != ED_SEARCH_NEXT_HISTORY) {
- el->el_search.patlen = EL_CURSOR(el) - el->el_line.buffer;
- if (el->el_search.patlen >= EL_BUFSIZ)
- el->el_search.patlen = EL_BUFSIZ - 1;
- if (el->el_search.patlen != 0) {
- (void) strncpy(el->el_search.patbuf, el->el_line.buffer,
- el->el_search.patlen);
- el->el_search.patbuf[el->el_search.patlen] = '\0';
- } else
- el->el_search.patlen = strlen(el->el_search.patbuf);
- }
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "\neventno = %d\n",
- el->el_history.eventno);
- (void) fprintf(el->el_errfile, "patlen = %d\n", el->el_search.patlen);
- (void) fprintf(el->el_errfile, "patbuf = \"%s\"\n",
- el->el_search.patbuf);
- (void) fprintf(el->el_errfile, "cursor %d lastchar %d\n",
- EL_CURSOR(el) - el->el_line.buffer,
- el->el_line.lastchar - el->el_line.buffer);
-#endif
-}
-
-
-/* ce_inc_search():
- * Emacs incremental search
- */
-protected el_action_t
-ce_inc_search(EditLine *el, int dir)
-{
- static const char STRfwd[] = {'f', 'w', 'd', '\0'},
- STRbck[] = {'b', 'c', 'k', '\0'};
- static char pchar = ':';/* ':' = normal, '?' = failed */
- static char endcmd[2] = {'\0', '\0'};
- char ch, *ocursor = el->el_line.cursor, oldpchar = pchar;
- const char *cp;
-
- el_action_t ret = CC_NORM;
-
- int ohisteventno = el->el_history.eventno;
- int oldpatlen = el->el_search.patlen;
- int newdir = dir;
- int done, redo;
-
- if (el->el_line.lastchar + sizeof(STRfwd) / sizeof(char) + 2 +
- el->el_search.patlen >= el->el_line.limit)
- return (CC_ERROR);
-
- for (;;) {
-
- if (el->el_search.patlen == 0) { /* first round */
- pchar = ':';
-#ifdef ANCHOR
- el->el_search.patbuf[el->el_search.patlen++] = '.';
- el->el_search.patbuf[el->el_search.patlen++] = '*';
-#endif
- }
- done = redo = 0;
- *el->el_line.lastchar++ = '\n';
- for (cp = (newdir == ED_SEARCH_PREV_HISTORY) ? STRbck : STRfwd;
- *cp; *el->el_line.lastchar++ = *cp++)
- continue;
- *el->el_line.lastchar++ = pchar;
- for (cp = &el->el_search.patbuf[1];
- cp < &el->el_search.patbuf[el->el_search.patlen];
- *el->el_line.lastchar++ = *cp++)
- continue;
- *el->el_line.lastchar = '\0';
- re_refresh(el);
-
- if (el_getc(el, &ch) != 1)
- return (ed_end_of_file(el, 0));
-
- switch (el->el_map.current[(unsigned char) ch]) {
- case ED_INSERT:
- case ED_DIGIT:
- if (el->el_search.patlen > EL_BUFSIZ - 3)
- term_beep(el);
- else {
- el->el_search.patbuf[el->el_search.patlen++] =
- ch;
- *el->el_line.lastchar++ = ch;
- *el->el_line.lastchar = '\0';
- re_refresh(el);
- }
- break;
-
- case EM_INC_SEARCH_NEXT:
- newdir = ED_SEARCH_NEXT_HISTORY;
- redo++;
- break;
-
- case EM_INC_SEARCH_PREV:
- newdir = ED_SEARCH_PREV_HISTORY;
- redo++;
- break;
-
- case ED_DELETE_PREV_CHAR:
- if (el->el_search.patlen > 1)
- done++;
- else
- term_beep(el);
- break;
-
- default:
- switch (ch) {
- case 0007: /* ^G: Abort */
- ret = CC_ERROR;
- done++;
- break;
-
- case 0027: /* ^W: Append word */
- /* No can do if globbing characters in pattern */
- for (cp = &el->el_search.patbuf[1];; cp++)
- if (cp >= &el->el_search.patbuf[el->el_search.patlen]) {
- el->el_line.cursor +=
- el->el_search.patlen - 1;
- cp = c__next_word(el->el_line.cursor,
- el->el_line.lastchar, 1,
- ce__isword);
- while (el->el_line.cursor < cp &&
- *el->el_line.cursor != '\n') {
- if (el->el_search.patlen >
- EL_BUFSIZ - 3) {
- term_beep(el);
- break;
- }
- el->el_search.patbuf[el->el_search.patlen++] =
- *el->el_line.cursor;
- *el->el_line.lastchar++ =
- *el->el_line.cursor++;
- }
- el->el_line.cursor = ocursor;
- *el->el_line.lastchar = '\0';
- re_refresh(el);
- break;
- } else if (isglob(*cp)) {
- term_beep(el);
- break;
- }
- break;
-
- default: /* Terminate and execute cmd */
- endcmd[0] = ch;
- el_push(el, endcmd);
- /* FALLTHROUGH */
-
- case 0033: /* ESC: Terminate */
- ret = CC_REFRESH;
- done++;
- break;
- }
- break;
- }
-
- while (el->el_line.lastchar > el->el_line.buffer &&
- *el->el_line.lastchar != '\n')
- *el->el_line.lastchar-- = '\0';
- *el->el_line.lastchar = '\0';
-
- if (!done) {
-
- /* Can't search if unmatched '[' */
- for (cp = &el->el_search.patbuf[el->el_search.patlen-1],
- ch = ']';
- cp > el->el_search.patbuf;
- cp--)
- if (*cp == '[' || *cp == ']') {
- ch = *cp;
- break;
- }
- if (el->el_search.patlen > 1 && ch != '[') {
- if (redo && newdir == dir) {
- if (pchar == '?') { /* wrap around */
- el->el_history.eventno =
- newdir == ED_SEARCH_PREV_HISTORY ? 0 : 0x7fffffff;
- if (hist_get(el) == CC_ERROR)
- /* el->el_history.event
- * no was fixed by
- * first call */
- (void) hist_get(el);
- el->el_line.cursor = newdir ==
- ED_SEARCH_PREV_HISTORY ?
- el->el_line.lastchar :
- el->el_line.buffer;
- } else
- el->el_line.cursor +=
- newdir ==
- ED_SEARCH_PREV_HISTORY ?
- -1 : 1;
- }
-#ifdef ANCHOR
- el->el_search.patbuf[el->el_search.patlen++] =
- '.';
- el->el_search.patbuf[el->el_search.patlen++] =
- '*';
-#endif
- el->el_search.patbuf[el->el_search.patlen] =
- '\0';
- if (el->el_line.cursor < el->el_line.buffer ||
- el->el_line.cursor > el->el_line.lastchar ||
- (ret = ce_search_line(el,
- &el->el_search.patbuf[1],
- newdir)) == CC_ERROR) {
- /* avoid c_setpat */
- el->el_state.lastcmd =
- (el_action_t) newdir;
- ret = newdir == ED_SEARCH_PREV_HISTORY ?
- ed_search_prev_history(el, 0) :
- ed_search_next_history(el, 0);
- if (ret != CC_ERROR) {
- el->el_line.cursor = newdir ==
- ED_SEARCH_PREV_HISTORY ?
- el->el_line.lastchar :
- el->el_line.buffer;
- (void) ce_search_line(el,
- &el->el_search.patbuf[1],
- newdir);
- }
- }
- el->el_search.patbuf[--el->el_search.patlen] =
- '\0';
- if (ret == CC_ERROR) {
- term_beep(el);
- if (el->el_history.eventno !=
- ohisteventno) {
- el->el_history.eventno =
- ohisteventno;
- if (hist_get(el) == CC_ERROR)
- return (CC_ERROR);
- }
- el->el_line.cursor = ocursor;
- pchar = '?';
- } else {
- pchar = ':';
- }
- }
- ret = ce_inc_search(el, newdir);
-
- if (ret == CC_ERROR && pchar == '?' && oldpchar == ':')
- /*
- * break abort of failed search at last
- * non-failed
- */
- ret = CC_NORM;
-
- }
- if (ret == CC_NORM || (ret == CC_ERROR && oldpatlen == 0)) {
- /* restore on normal return or error exit */
- pchar = oldpchar;
- el->el_search.patlen = oldpatlen;
- if (el->el_history.eventno != ohisteventno) {
- el->el_history.eventno = ohisteventno;
- if (hist_get(el) == CC_ERROR)
- return (CC_ERROR);
- }
- el->el_line.cursor = ocursor;
- if (ret == CC_ERROR)
- re_refresh(el);
- }
- if (done || ret != CC_NORM)
- return (ret);
- }
-}
-
-
-/* cv_search():
- * Vi search.
- */
-protected el_action_t
-cv_search(EditLine *el, int dir)
-{
- char ch;
- char tmpbuf[EL_BUFSIZ];
- int tmplen;
-
- tmplen = 0;
-#ifdef ANCHOR
- tmpbuf[tmplen++] = '.';
- tmpbuf[tmplen++] = '*';
-#endif
-
- el->el_line.buffer[0] = '\0';
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
- el->el_search.patdir = dir;
-
- c_insert(el, 2); /* prompt + '\n' */
- *el->el_line.cursor++ = '\n';
- *el->el_line.cursor++ = dir == ED_SEARCH_PREV_HISTORY ? '/' : '?';
- re_refresh(el);
-
-#ifdef ANCHOR
-#define LEN 2
-#else
-#define LEN 0
-#endif
-
- tmplen = c_gets(el, &tmpbuf[LEN]) + LEN;
- ch = tmpbuf[tmplen];
- tmpbuf[tmplen] = '\0';
-
- if (tmplen == LEN) {
- /*
- * Use the old pattern, but wild-card it.
- */
- if (el->el_search.patlen == 0) {
- el->el_line.buffer[0] = '\0';
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
- re_refresh(el);
- return (CC_ERROR);
- }
-#ifdef ANCHOR
- if (el->el_search.patbuf[0] != '.' &&
- el->el_search.patbuf[0] != '*') {
- (void) strncpy(tmpbuf, el->el_search.patbuf,
- sizeof(tmpbuf) - 1);
- el->el_search.patbuf[0] = '.';
- el->el_search.patbuf[1] = '*';
- (void) strncpy(&el->el_search.patbuf[2], tmpbuf,
- EL_BUFSIZ - 3);
- el->el_search.patlen++;
- el->el_search.patbuf[el->el_search.patlen++] = '.';
- el->el_search.patbuf[el->el_search.patlen++] = '*';
- el->el_search.patbuf[el->el_search.patlen] = '\0';
- }
-#endif
- } else {
-#ifdef ANCHOR
- tmpbuf[tmplen++] = '.';
- tmpbuf[tmplen++] = '*';
-#endif
- tmpbuf[tmplen] = '\0';
- (void) strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
- el->el_search.patlen = tmplen;
- }
- el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
- el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer;
- if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
- ed_search_next_history(el, 0)) == CC_ERROR) {
- re_refresh(el);
- return (CC_ERROR);
- } else {
- if (ch == 0033) {
- re_refresh(el);
- *el->el_line.lastchar++ = '\n';
- *el->el_line.lastchar = '\0';
- re_goto_bottom(el);
- return (CC_NEWLINE);
- } else
- return (CC_REFRESH);
- }
-}
-
-
-/* ce_search_line():
- * Look for a pattern inside a line
- */
-protected el_action_t
-ce_search_line(EditLine *el, char *pattern, int dir)
-{
- char *cp;
-
- if (dir == ED_SEARCH_PREV_HISTORY) {
- for (cp = el->el_line.cursor; cp >= el->el_line.buffer; cp--)
- if (el_match(cp, pattern)) {
- el->el_line.cursor = cp;
- return (CC_NORM);
- }
- return (CC_ERROR);
- } else {
- for (cp = el->el_line.cursor; *cp != '\0' &&
- cp < el->el_line.limit; cp++)
- if (el_match(cp, pattern)) {
- el->el_line.cursor = cp;
- return (CC_NORM);
- }
- return (CC_ERROR);
- }
-}
-
-
-/* cv_repeat_srch():
- * Vi repeat search
- */
-protected el_action_t
-cv_repeat_srch(EditLine *el, int c)
-{
-
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "dir %d patlen %d patbuf %s\n",
- c, el->el_search.patlen, el->el_search.patbuf);
-#endif
-
- el->el_state.lastcmd = (el_action_t) c; /* Hack to stop c_setpat */
- el->el_line.lastchar = el->el_line.buffer;
-
- switch (c) {
- case ED_SEARCH_NEXT_HISTORY:
- return (ed_search_next_history(el, 0));
- case ED_SEARCH_PREV_HISTORY:
- return (ed_search_prev_history(el, 0));
- default:
- return (CC_ERROR);
- }
-}
-
-
-/* cv_csearch_back():
- * Vi character search reverse
- */
-protected el_action_t
-cv_csearch_back(EditLine *el, int ch, int count, int tflag)
-{
- char *cp;
-
- cp = el->el_line.cursor;
- while (count--) {
- if (*cp == ch)
- cp--;
- while (cp > el->el_line.buffer && *cp != ch)
- cp--;
- }
-
- if (cp < el->el_line.buffer || (cp == el->el_line.buffer && *cp != ch))
- return (CC_ERROR);
-
- if (*cp == ch && tflag)
- cp++;
-
- el->el_line.cursor = cp;
-
- if (el->el_chared.c_vcmd.action & DELETE) {
- el->el_line.cursor++;
- cv_delfini(el);
- return (CC_REFRESH);
- }
- re_refresh_cursor(el);
- return (CC_NORM);
-}
-
-
-/* cv_csearch_fwd():
- * Vi character search forward
- */
-protected el_action_t
-cv_csearch_fwd(EditLine *el, int ch, int count, int tflag)
-{
- char *cp;
-
- cp = el->el_line.cursor;
- while (count--) {
- if (*cp == ch)
- cp++;
- while (cp < el->el_line.lastchar && *cp != ch)
- cp++;
- }
-
- if (cp >= el->el_line.lastchar)
- return (CC_ERROR);
-
- if (*cp == ch && tflag)
- cp--;
-
- el->el_line.cursor = cp;
-
- if (el->el_chared.c_vcmd.action & DELETE) {
- el->el_line.cursor++;
- cv_delfini(el);
- return (CC_REFRESH);
- }
- re_refresh_cursor(el);
- return (CC_NORM);
-}
diff --git a/1.2-netsec/editline/search.h b/1.2-netsec/editline/search.h
deleted file mode 100644
index 676bbe2e3..000000000
--- a/1.2-netsec/editline/search.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/* $NetBSD: search.h,v 1.5 2000/09/04 22:06:32 lukem Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)search.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.search.h: Line and history searching utilities
- */
-#ifndef _h_el_search
-#define _h_el_search
-
-#include "histedit.h"
-
-typedef struct el_search_t {
- char *patbuf; /* The pattern buffer */
- size_t patlen; /* Length of the pattern buffer */
- int patdir; /* Direction of the last search */
- int chadir; /* Character search direction */
- char chacha; /* Character we are looking for */
-} el_search_t;
-
-
-protected int el_match(const char *, const char *);
-protected int search_init(EditLine *);
-protected void search_end(EditLine *);
-protected int c_hmatch(EditLine *, const char *);
-protected void c_setpat(EditLine *);
-protected el_action_t ce_inc_search(EditLine *, int);
-protected el_action_t cv_search(EditLine *, int);
-protected el_action_t ce_search_line(EditLine *, char *, int);
-protected el_action_t cv_repeat_srch(EditLine *, int);
-protected el_action_t cv_csearch_back(EditLine *, int, int, int);
-protected el_action_t cv_csearch_fwd(EditLine *, int, int, int);
-
-#endif /* _h_el_search */
diff --git a/1.2-netsec/editline/sig.c b/1.2-netsec/editline/sig.c
deleted file mode 100644
index 0acba1247..000000000
--- a/1.2-netsec/editline/sig.c
+++ /dev/null
@@ -1,198 +0,0 @@
-/* $NetBSD: sig.c,v 1.9 2002/03/18 16:00:58 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: sig.c,v 1.9 2002/03/18 16:00:58 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * sig.c: Signal handling stuff.
- * our policy is to trap all signals, set a good state
- * and pass the ball to our caller.
- */
-#include "el.h"
-#include <stdlib.h>
-
-private EditLine *sel = NULL;
-
-private const int sighdl[] = {
-#define _DO(a) (a),
- ALLSIGS
-#undef _DO
- - 1
-};
-
-private void sig_handler(int);
-
-/* sig_handler():
- * This is the handler called for all signals
- * XXX: we cannot pass any data so we just store the old editline
- * state in a private variable
- */
-private void
-sig_handler(int signo)
-{
- int i;
- sigset_t nset, oset;
-
- (void) sigemptyset(&nset);
- (void) sigaddset(&nset, signo);
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
-
- switch (signo) {
- case SIGCONT:
- tty_rawmode(sel);
- if (ed_redisplay(sel, 0) == CC_REFRESH)
- re_refresh(sel);
- term__flush();
- break;
-
- case SIGWINCH:
- el_resize(sel);
- break;
-
- default:
- tty_cookedmode(sel);
- break;
- }
-
- for (i = 0; sighdl[i] != -1; i++)
- if (signo == sighdl[i])
- break;
-
- (void) signal(signo, sel->el_signal[i]);
- (void) sigprocmask(SIG_SETMASK, &oset, NULL);
- (void) kill(0, signo);
-}
-
-
-/* sig_init():
- * Initialize all signal stuff
- */
-protected int
-sig_init(EditLine *el)
-{
- int i;
- sigset_t nset, oset;
-
- (void) sigemptyset(&nset);
-#define _DO(a) (void) sigaddset(&nset, a);
- ALLSIGS
-#undef _DO
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
-
-#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(sig_t))
-
- el->el_signal = (sig_t *) el_malloc(SIGSIZE);
- if (el->el_signal == NULL)
- return (-1);
- for (i = 0; sighdl[i] != -1; i++)
- el->el_signal[i] = SIG_ERR;
-
- (void) sigprocmask(SIG_SETMASK, &oset, NULL);
-
- return (0);
-}
-
-
-/* sig_end():
- * Clear all signal stuff
- */
-protected void
-sig_end(EditLine *el)
-{
-
- el_free((ptr_t) el->el_signal);
- el->el_signal = NULL;
-}
-
-
-/* sig_set():
- * set all the signal handlers
- */
-protected void
-sig_set(EditLine *el)
-{
- int i;
- sigset_t nset, oset;
-
- (void) sigemptyset(&nset);
-#define _DO(a) (void) sigaddset(&nset, a);
- ALLSIGS
-#undef _DO
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
-
- for (i = 0; sighdl[i] != -1; i++) {
- sig_t s;
- /* This could happen if we get interrupted */
- if ((s = signal(sighdl[i], sig_handler)) != sig_handler)
- el->el_signal[i] = s;
- }
- sel = el;
- (void) sigprocmask(SIG_SETMASK, &oset, NULL);
-}
-
-
-/* sig_clr():
- * clear all the signal handlers
- */
-protected void
-sig_clr(EditLine *el)
-{
- int i;
- sigset_t nset, oset;
-
- (void) sigemptyset(&nset);
-#define _DO(a) (void) sigaddset(&nset, a);
- ALLSIGS
-#undef _DO
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
-
- for (i = 0; sighdl[i] != -1; i++)
- if (el->el_signal[i] != SIG_ERR)
- (void) signal(sighdl[i], el->el_signal[i]);
-
- sel = NULL; /* we are going to die if the handler is
- * called */
- (void) sigprocmask(SIG_SETMASK, &oset, NULL);
-}
diff --git a/1.2-netsec/editline/sig.h b/1.2-netsec/editline/sig.h
deleted file mode 100644
index e7231b65c..000000000
--- a/1.2-netsec/editline/sig.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* $NetBSD: sig.h,v 1.3 2000/09/04 22:06:32 lukem Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)sig.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.sig.h: Signal handling functions
- */
-#ifndef _h_el_sig
-#define _h_el_sig
-
-#include <signal.h>
-
-#include "histedit.h"
-
-/*
- * Define here all the signals we are going to handle
- * The _DO macro is used to iterate in the source code
- */
-#define ALLSIGS \
- _DO(SIGINT) \
- _DO(SIGTSTP) \
- _DO(SIGSTOP) \
- _DO(SIGQUIT) \
- _DO(SIGHUP) \
- _DO(SIGTERM) \
- _DO(SIGCONT) \
- _DO(SIGWINCH)
-
-typedef sig_t *el_signal_t;
-
-protected void sig_end(EditLine*);
-protected int sig_init(EditLine*);
-protected void sig_set(EditLine*);
-protected void sig_clr(EditLine*);
-
-#endif /* _h_el_sig */
diff --git a/1.2-netsec/editline/sys.h b/1.2-netsec/editline/sys.h
deleted file mode 100644
index a306d1df7..000000000
--- a/1.2-netsec/editline/sys.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/* $NetBSD: sys.h,v 1.5 2002/03/18 16:00:59 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)sys.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * sys.h: Put all the stupid compiler and system dependencies here...
- */
-#ifndef _h_sys
-#define _h_sys
-
-#ifndef public
-# define public /* Externally visible functions/variables */
-#endif
-
-#ifndef private
-# define private static /* Always hidden internals */
-#endif
-
-#ifndef protected
-# define protected /* Redefined from elsewhere to "static" */
- /* When we want to hide everything */
-#endif
-
-#ifndef _PTR_T
-# define _PTR_T
-typedef void *ptr_t;
-#endif
-
-#ifndef _IOCTL_T
-# define _IOCTL_T
-typedef void *ioctl_t;
-#endif
-
-#include <stdio.h>
-
-#ifndef HAVE_STRLCAT
-#define strlcat libedit_strlcat
-size_t strlcat(char *dst, const char *src, size_t size);
-#endif
-
-#ifndef HAVE_STRLCPY
-#define strlcpy libedit_strlcpy
-size_t strlcpy(char *dst, const char *src, size_t size);
-#endif
-
-#ifndef HAVE_FGETLN
-#define fgetln libedit_fgetln
-char *fgetln(FILE *fp, size_t *len);
-#endif
-
-#define REGEX /* Use POSIX.2 regular expression functions */
-#undef REGEXP /* Use UNIX V8 regular expression functions */
-
-#ifdef SUNOS
-# undef REGEX
-# undef REGEXP
-# include <malloc.h>
-typedef void (*sig_t)(int);
-# ifdef __GNUC__
-/*
- * Broken hdrs.
- */
-#ifndef SOLARIS
-extern int tgetent(const char *bp, char *name);
-extern int tgetflag(const char *id);
-extern int tgetnum(const char *id);
-extern char *tgetstr(const char *id, char **area);
-#endif
-extern char *tgoto(const char *cap, int col, int row);
-extern int tputs(const char *str, int affcnt, int (*putc)(int));
-extern char *getenv(const char *);
-extern int fprintf(FILE *, const char *, ...);
-extern int sigsetmask(int);
-extern int sigblock(int);
-extern int fputc(int, FILE *);
-extern int fgetc(FILE *);
-extern int fflush(FILE *);
-extern int tolower(int);
-extern int toupper(int);
-extern int errno, sys_nerr;
-extern char *sys_errlist[];
-extern void perror(const char *);
-# include <string.h>
-# define strerror(e) sys_errlist[e]
-# endif
-# ifdef SABER
-extern ptr_t memcpy(ptr_t, const ptr_t, size_t);
-extern ptr_t memset(ptr_t, int, size_t);
-# endif
-extern char *fgetline(FILE *, int *);
-#endif
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-
-#endif /* _h_sys */
diff --git a/1.2-netsec/editline/term.c b/1.2-netsec/editline/term.c
deleted file mode 100644
index 5fc5da466..000000000
--- a/1.2-netsec/editline/term.c
+++ /dev/null
@@ -1,1581 +0,0 @@
-/* $NetBSD: term.c,v 1.35 2002/03/18 16:00:59 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
-#else
-__RCSID("$NetBSD: term.c,v 1.35 2002/03/18 16:00:59 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * term.c: Editor/termcap-curses interface
- * We have to declare a static variable here, since the
- * termcap putchar routine does not take an argument!
- */
-#include <stdio.h>
-#include <signal.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#ifdef HAVE_TERMCAP_H
-#include <termcap.h>
-#endif
-#ifdef HAVE_CURSES_H
-#include <curses.h>
-#endif
-#ifdef HAVE_NCURSES_H
-#include <ncurses.h>
-#endif
-/* Solaris's term.h does horrid things. */
-#if (defined(HAVE_TERM_H) && !defined(SUNOS))
-#include <term.h>
-#endif
-#include <sys/types.h>
-#include <sys/ioctl.h>
-
-#include "el.h"
-
-/*
- * IMPORTANT NOTE: these routines are allowed to look at the current screen
- * and the current possition assuming that it is correct. If this is not
- * true, then the update will be WRONG! This is (should be) a valid
- * assumption...
- */
-
-#define TC_BUFSIZE 2048
-
-#define GoodStr(a) (el->el_term.t_str[a] != NULL && \
- el->el_term.t_str[a][0] != '\0')
-#define Str(a) el->el_term.t_str[a]
-#define Val(a) el->el_term.t_val[a]
-
-#ifdef notdef
-private const struct {
- const char *b_name;
- int b_rate;
-} baud_rate[] = {
-#ifdef B0
- { "0", B0 },
-#endif
-#ifdef B50
- { "50", B50 },
-#endif
-#ifdef B75
- { "75", B75 },
-#endif
-#ifdef B110
- { "110", B110 },
-#endif
-#ifdef B134
- { "134", B134 },
-#endif
-#ifdef B150
- { "150", B150 },
-#endif
-#ifdef B200
- { "200", B200 },
-#endif
-#ifdef B300
- { "300", B300 },
-#endif
-#ifdef B600
- { "600", B600 },
-#endif
-#ifdef B900
- { "900", B900 },
-#endif
-#ifdef B1200
- { "1200", B1200 },
-#endif
-#ifdef B1800
- { "1800", B1800 },
-#endif
-#ifdef B2400
- { "2400", B2400 },
-#endif
-#ifdef B3600
- { "3600", B3600 },
-#endif
-#ifdef B4800
- { "4800", B4800 },
-#endif
-#ifdef B7200
- { "7200", B7200 },
-#endif
-#ifdef B9600
- { "9600", B9600 },
-#endif
-#ifdef EXTA
- { "19200", EXTA },
-#endif
-#ifdef B19200
- { "19200", B19200 },
-#endif
-#ifdef EXTB
- { "38400", EXTB },
-#endif
-#ifdef B38400
- { "38400", B38400 },
-#endif
- { NULL, 0 }
-};
-#endif
-
-private const struct termcapstr {
- const char *name;
- const char *long_name;
-} tstr[] = {
-#define T_al 0
- { "al", "add new blank line" },
-#define T_bl 1
- { "bl", "audible bell" },
-#define T_cd 2
- { "cd", "clear to bottom" },
-#define T_ce 3
- { "ce", "clear to end of line" },
-#define T_ch 4
- { "ch", "cursor to horiz pos" },
-#define T_cl 5
- { "cl", "clear screen" },
-#define T_dc 6
- { "dc", "delete a character" },
-#define T_dl 7
- { "dl", "delete a line" },
-#define T_dm 8
- { "dm", "start delete mode" },
-#define T_ed 9
- { "ed", "end delete mode" },
-#define T_ei 10
- { "ei", "end insert mode" },
-#define T_fs 11
- { "fs", "cursor from status line" },
-#define T_ho 12
- { "ho", "home cursor" },
-#define T_ic 13
- { "ic", "insert character" },
-#define T_im 14
- { "im", "start insert mode" },
-#define T_ip 15
- { "ip", "insert padding" },
-#define T_kd 16
- { "kd", "sends cursor down" },
-#define T_kl 17
- { "kl", "sends cursor left" },
-#define T_kr 18
- { "kr", "sends cursor right" },
-#define T_ku 19
- { "ku", "sends cursor up" },
-#define T_md 20
- { "md", "begin bold" },
-#define T_me 21
- { "me", "end attributes" },
-#define T_nd 22
- { "nd", "non destructive space" },
-#define T_se 23
- { "se", "end standout" },
-#define T_so 24
- { "so", "begin standout" },
-#define T_ts 25
- { "ts", "cursor to status line" },
-#define T_up 26
- { "up", "cursor up one" },
-#define T_us 27
- { "us", "begin underline" },
-#define T_ue 28
- { "ue", "end underline" },
-#define T_vb 29
- { "vb", "visible bell" },
-#define T_DC 30
- { "DC", "delete multiple chars" },
-#define T_DO 31
- { "DO", "cursor down multiple" },
-#define T_IC 32
- { "IC", "insert multiple chars" },
-#define T_LE 33
- { "LE", "cursor left multiple" },
-#define T_RI 34
- { "RI", "cursor right multiple" },
-#define T_UP 35
- { "UP", "cursor up multiple" },
-#define T_kh 36
- { "kh", "send cursor home" },
-#define T_at7 37
- { "@7", "send cursor end" },
-#define T_str 38
- { NULL, NULL }
-};
-
-private const struct termcapval {
- const char *name;
- const char *long_name;
-} tval[] = {
-#define T_am 0
- { "am", "has automatic margins" },
-#define T_pt 1
- { "pt", "has physical tabs" },
-#define T_li 2
- { "li", "Number of lines" },
-#define T_co 3
- { "co", "Number of columns" },
-#define T_km 4
- { "km", "Has meta key" },
-#define T_xt 5
- { "xt", "Tab chars destructive" },
-#define T_xn 6
- { "xn", "newline ignored at right margin" },
-#define T_MT 7
- { "MT", "Has meta key" }, /* XXX? */
-#define T_val 8
- { NULL, NULL, }
-};
-/* do two or more of the attributes use me */
-
-private void term_setflags(EditLine *);
-private int term_rebuffer_display(EditLine *);
-private void term_free_display(EditLine *);
-private int term_alloc_display(EditLine *);
-private void term_alloc(EditLine *, const struct termcapstr *, const char *);
-private void term_init_arrow(EditLine *);
-private void term_reset_arrow(EditLine *);
-
-
-private FILE *term_outfile = NULL; /* XXX: How do we fix that? */
-
-
-/* term_setflags():
- * Set the terminal capability flags
- */
-private void
-term_setflags(EditLine *el)
-{
- EL_FLAGS = 0;
- if (el->el_tty.t_tabs)
- EL_FLAGS |= (Val(T_pt) && !Val(T_xt)) ? TERM_CAN_TAB : 0;
-
- EL_FLAGS |= (Val(T_km) || Val(T_MT)) ? TERM_HAS_META : 0;
- EL_FLAGS |= GoodStr(T_ce) ? TERM_CAN_CEOL : 0;
- EL_FLAGS |= (GoodStr(T_dc) || GoodStr(T_DC)) ? TERM_CAN_DELETE : 0;
- EL_FLAGS |= (GoodStr(T_im) || GoodStr(T_ic) || GoodStr(T_IC)) ?
- TERM_CAN_INSERT : 0;
- EL_FLAGS |= (GoodStr(T_up) || GoodStr(T_UP)) ? TERM_CAN_UP : 0;
- EL_FLAGS |= Val(T_am) ? TERM_HAS_AUTO_MARGINS : 0;
- EL_FLAGS |= Val(T_xn) ? TERM_HAS_MAGIC_MARGINS : 0;
-
- if (GoodStr(T_me) && GoodStr(T_ue))
- EL_FLAGS |= (strcmp(Str(T_me), Str(T_ue)) == 0) ?
- TERM_CAN_ME : 0;
- else
- EL_FLAGS &= ~TERM_CAN_ME;
- if (GoodStr(T_me) && GoodStr(T_se))
- EL_FLAGS |= (strcmp(Str(T_me), Str(T_se)) == 0) ?
- TERM_CAN_ME : 0;
-
-
-#ifdef DEBUG_SCREEN
- if (!EL_CAN_UP) {
- (void) fprintf(el->el_errfile,
- "WARNING: Your terminal cannot move up.\n");
- (void) fprintf(el->el_errfile,
- "Editing may be odd for long lines.\n");
- }
- if (!EL_CAN_CEOL)
- (void) fprintf(el->el_errfile, "no clear EOL capability.\n");
- if (!EL_CAN_DELETE)
- (void) fprintf(el->el_errfile, "no delete char capability.\n");
- if (!EL_CAN_INSERT)
- (void) fprintf(el->el_errfile, "no insert char capability.\n");
-#endif /* DEBUG_SCREEN */
-}
-
-
-/* term_init():
- * Initialize the terminal stuff
- */
-protected int
-term_init(EditLine *el)
-{
-
- el->el_term.t_buf = (char *) el_malloc(TC_BUFSIZE);
- if (el->el_term.t_buf == NULL)
- return (-1);
- el->el_term.t_cap = (char *) el_malloc(TC_BUFSIZE);
- if (el->el_term.t_cap == NULL)
- return (-1);
- el->el_term.t_fkey = (fkey_t *) el_malloc(A_K_NKEYS * sizeof(fkey_t));
- if (el->el_term.t_fkey == NULL)
- return (-1);
- el->el_term.t_loc = 0;
- el->el_term.t_str = (char **) el_malloc(T_str * sizeof(char *));
- if (el->el_term.t_str == NULL)
- return (-1);
- (void) memset(el->el_term.t_str, 0, T_str * sizeof(char *));
- el->el_term.t_val = (int *) el_malloc(T_val * sizeof(int));
- if (el->el_term.t_val == NULL)
- return (-1);
- (void) memset(el->el_term.t_val, 0, T_val * sizeof(int));
- term_outfile = el->el_outfile;
- (void) term_set(el, NULL);
- term_init_arrow(el);
- return (0);
-}
-/* term_end():
- * Clean up the terminal stuff
- */
-protected void
-term_end(EditLine *el)
-{
-
- el_free((ptr_t) el->el_term.t_buf);
- el->el_term.t_buf = NULL;
- el_free((ptr_t) el->el_term.t_cap);
- el->el_term.t_cap = NULL;
- el_free((ptr_t) el->el_term.t_fkey);
- el->el_term.t_fkey = NULL;
- el->el_term.t_loc = 0;
- el_free((ptr_t) el->el_term.t_str);
- el->el_term.t_str = NULL;
- el_free((ptr_t) el->el_term.t_val);
- el->el_term.t_val = NULL;
- term_free_display(el);
-}
-
-
-/* term_alloc():
- * Maintain a string pool for termcap strings
- */
-private void
-term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
-{
- char termbuf[TC_BUFSIZE];
- int tlen, clen;
- char **tlist = el->el_term.t_str;
- char **tmp, **str = &tlist[t - tstr];
-
- if (cap == NULL || *cap == '\0') {
- *str = NULL;
- return;
- } else
- clen = strlen(cap);
-
- tlen = *str == NULL ? 0 : strlen(*str);
-
- /*
- * New string is shorter; no need to allocate space
- */
- if (clen <= tlen) {
- (void) strcpy(*str, cap); /* XXX strcpy is safe */
- return;
- }
- /*
- * New string is longer; see if we have enough space to append
- */
- if (el->el_term.t_loc + 3 < TC_BUFSIZE) {
- /* XXX strcpy is safe */
- (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc],
- cap);
- el->el_term.t_loc += clen + 1; /* one for \0 */
- return;
- }
- /*
- * Compact our buffer; no need to check compaction, cause we know it
- * fits...
- */
- tlen = 0;
- for (tmp = tlist; tmp < &tlist[T_str]; tmp++)
- if (*tmp != NULL && *tmp != '\0' && *tmp != *str) {
- char *ptr;
-
- for (ptr = *tmp; *ptr != '\0'; termbuf[tlen++] = *ptr++)
- continue;
- termbuf[tlen++] = '\0';
- }
- memcpy(el->el_term.t_buf, termbuf, TC_BUFSIZE);
- el->el_term.t_loc = tlen;
- if (el->el_term.t_loc + 3 >= TC_BUFSIZE) {
- (void) fprintf(el->el_errfile,
- "Out of termcap string space.\n");
- return;
- }
- /* XXX strcpy is safe */
- (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap);
- el->el_term.t_loc += clen + 1; /* one for \0 */
- return;
-}
-
-
-/* term_rebuffer_display():
- * Rebuffer the display after the screen changed size
- */
-private int
-term_rebuffer_display(EditLine *el)
-{
- coord_t *c = &el->el_term.t_size;
-
- term_free_display(el);
-
- c->h = Val(T_co);
- c->v = Val(T_li);
-
- if (term_alloc_display(el) == -1)
- return (-1);
- return (0);
-}
-
-
-/* term_alloc_display():
- * Allocate a new display.
- */
-private int
-term_alloc_display(EditLine *el)
-{
- int i;
- char **b;
- coord_t *c = &el->el_term.t_size;
-
- b = (char **) el_malloc((size_t) (sizeof(char *) * (c->v + 1)));
- if (b == NULL)
- return (-1);
- for (i = 0; i < c->v; i++) {
- b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
- if (b[i] == NULL)
- return (-1);
- }
- b[c->v] = NULL;
- el->el_display = b;
-
- b = (char **) el_malloc((size_t) (sizeof(char *) * (c->v + 1)));
- if (b == NULL)
- return (-1);
- for (i = 0; i < c->v; i++) {
- b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
- if (b[i] == NULL)
- return (-1);
- }
- b[c->v] = NULL;
- el->el_vdisplay = b;
- return (0);
-}
-
-
-/* term_free_display():
- * Free the display buffers
- */
-private void
-term_free_display(EditLine *el)
-{
- char **b;
- char **bufp;
-
- b = el->el_display;
- el->el_display = NULL;
- if (b != NULL) {
- for (bufp = b; *bufp != NULL; bufp++)
- el_free((ptr_t) * bufp);
- el_free((ptr_t) b);
- }
- b = el->el_vdisplay;
- el->el_vdisplay = NULL;
- if (b != NULL) {
- for (bufp = b; *bufp != NULL; bufp++)
- el_free((ptr_t) * bufp);
- el_free((ptr_t) b);
- }
-}
-
-
-/* term_move_to_line():
- * move to line <where> (first line == 0)
- * as efficiently as possible
- */
-protected void
-term_move_to_line(EditLine *el, int where)
-{
- int del;
-
- if (where == el->el_cursor.v)
- return;
-
- if (where > el->el_term.t_size.v) {
-#ifdef DEBUG_SCREEN
- (void) fprintf(el->el_errfile,
- "term_move_to_line: where is ridiculous: %d\r\n", where);
-#endif /* DEBUG_SCREEN */
- return;
- }
- if ((del = where - el->el_cursor.v) > 0) {
- while (del > 0) {
- if (EL_HAS_AUTO_MARGINS &&
- el->el_display[el->el_cursor.v][0] != '\0') {
- /* move without newline */
- term_move_to_char(el, el->el_term.t_size.h - 1);
- term_overwrite(el,
- &el->el_display[el->el_cursor.v][el->el_cursor.h],
- 1);
- /* updates Cursor */
- del--;
- } else {
- if ((del > 1) && GoodStr(T_DO)) {
- (void) tputs(tgoto(Str(T_DO), del, del),
- del, term__putc);
- del = 0;
- } else {
- for (; del > 0; del--)
- term__putc('\n');
- /* because the \n will become \r\n */
- el->el_cursor.h = 0;
- }
- }
- }
- } else { /* del < 0 */
- if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up)))
- (void) tputs(tgoto(Str(T_UP), -del, -del), -del,
- term__putc);
- else {
- if (GoodStr(T_up))
- for (; del < 0; del++)
- (void) tputs(Str(T_up), 1, term__putc);
- }
- }
- el->el_cursor.v = where;/* now where is here */
-}
-
-
-/* term_move_to_char():
- * Move to the character position specified
- */
-protected void
-term_move_to_char(EditLine *el, int where)
-{
- int del, i;
-
-mc_again:
- if (where == el->el_cursor.h)
- return;
-
- if (where > el->el_term.t_size.h) {
-#ifdef DEBUG_SCREEN
- (void) fprintf(el->el_errfile,
- "term_move_to_char: where is riduculous: %d\r\n", where);
-#endif /* DEBUG_SCREEN */
- return;
- }
- if (!where) { /* if where is first column */
- term__putc('\r'); /* do a CR */
- el->el_cursor.h = 0;
- return;
- }
- del = where - el->el_cursor.h;
-
- if ((del < -4 || del > 4) && GoodStr(T_ch))
- /* go there directly */
- (void) tputs(tgoto(Str(T_ch), where, where), where, term__putc);
- else {
- if (del > 0) { /* moving forward */
- if ((del > 4) && GoodStr(T_RI))
- (void) tputs(tgoto(Str(T_RI), del, del),
- del, term__putc);
- else {
- /* if I can do tabs, use them */
- if (EL_CAN_TAB) {
- if ((el->el_cursor.h & 0370) !=
- (where & 0370)) {
- /* if not within tab stop */
- for (i =
- (el->el_cursor.h & 0370);
- i < (where & 0370);
- i += 8)
- term__putc('\t');
- /* then tab over */
- el->el_cursor.h = where & 0370;
- }
- }
- /*
- * it's usually cheaper to just write the
- * chars, so we do.
- */
- /*
- * NOTE THAT term_overwrite() WILL CHANGE
- * el->el_cursor.h!!!
- */
- term_overwrite(el,
- &el->el_display[el->el_cursor.v][el->el_cursor.h],
- where - el->el_cursor.h);
-
- }
- } else { /* del < 0 := moving backward */
- if ((-del > 4) && GoodStr(T_LE))
- (void) tputs(tgoto(Str(T_LE), -del, -del),
- -del, term__putc);
- else { /* can't go directly there */
- /*
- * if the "cost" is greater than the "cost"
- * from col 0
- */
- if (EL_CAN_TAB ?
- (-del > (((unsigned int) where >> 3) +
- (where & 07)))
- : (-del > where)) {
- term__putc('\r'); /* do a CR */
- el->el_cursor.h = 0;
- goto mc_again; /* and try again */
- }
- for (i = 0; i < -del; i++)
- term__putc('\b');
- }
- }
- }
- el->el_cursor.h = where; /* now where is here */
-}
-
-
-/* term_overwrite():
- * Overstrike num characters
- */
-protected void
-term_overwrite(EditLine *el, const char *cp, int n)
-{
- if (n <= 0)
- return; /* catch bugs */
-
- if (n > el->el_term.t_size.h) {
-#ifdef DEBUG_SCREEN
- (void) fprintf(el->el_errfile,
- "term_overwrite: n is riduculous: %d\r\n", n);
-#endif /* DEBUG_SCREEN */
- return;
- }
- do {
- term__putc(*cp++);
- el->el_cursor.h++;
- } while (--n);
-
- if (el->el_cursor.h >= el->el_term.t_size.h) { /* wrap? */
- if (EL_HAS_AUTO_MARGINS) { /* yes */
- el->el_cursor.h = 0;
- el->el_cursor.v++;
- if (EL_HAS_MAGIC_MARGINS) {
- /* force the wrap to avoid the "magic"
- * situation */
- char c;
- if ((c = el->el_display[el->el_cursor.v][el->el_cursor.h])
- != '\0')
- term_overwrite(el, &c, 1);
- else
- term__putc(' ');
- el->el_cursor.h = 1;
- }
- } else /* no wrap, but cursor stays on screen */
- el->el_cursor.h = el->el_term.t_size.h;
- }
-}
-
-
-/* term_deletechars():
- * Delete num characters
- */
-protected void
-term_deletechars(EditLine *el, int num)
-{
- if (num <= 0)
- return;
-
- if (!EL_CAN_DELETE) {
-#ifdef DEBUG_EDIT
- (void) fprintf(el->el_errfile, " ERROR: cannot delete \n");
-#endif /* DEBUG_EDIT */
- return;
- }
- if (num > el->el_term.t_size.h) {
-#ifdef DEBUG_SCREEN
- (void) fprintf(el->el_errfile,
- "term_deletechars: num is riduculous: %d\r\n", num);
-#endif /* DEBUG_SCREEN */
- return;
- }
- if (GoodStr(T_DC)) /* if I have multiple delete */
- if ((num > 1) || !GoodStr(T_dc)) { /* if dc would be more
- * expen. */
- (void) tputs(tgoto(Str(T_DC), num, num),
- num, term__putc);
- return;
- }
- if (GoodStr(T_dm)) /* if I have delete mode */
- (void) tputs(Str(T_dm), 1, term__putc);
-
- if (GoodStr(T_dc)) /* else do one at a time */
- while (num--)
- (void) tputs(Str(T_dc), 1, term__putc);
-
- if (GoodStr(T_ed)) /* if I have delete mode */
- (void) tputs(Str(T_ed), 1, term__putc);
-}
-
-
-/* term_insertwrite():
- * Puts terminal in insert character mode or inserts num
- * characters in the line
- */
-protected void
-term_insertwrite(EditLine *el, char *cp, int num)
-{
- if (num <= 0)
- return;
- if (!EL_CAN_INSERT) {
-#ifdef DEBUG_EDIT
- (void) fprintf(el->el_errfile, " ERROR: cannot insert \n");
-#endif /* DEBUG_EDIT */
- return;
- }
- if (num > el->el_term.t_size.h) {
-#ifdef DEBUG_SCREEN
- (void) fprintf(el->el_errfile,
- "StartInsert: num is riduculous: %d\r\n", num);
-#endif /* DEBUG_SCREEN */
- return;
- }
- if (GoodStr(T_IC)) /* if I have multiple insert */
- if ((num > 1) || !GoodStr(T_ic)) {
- /* if ic would be more expensive */
- (void) tputs(tgoto(Str(T_IC), num, num),
- num, term__putc);
- term_overwrite(el, cp, num);
- /* this updates el_cursor.h */
- return;
- }
- if (GoodStr(T_im) && GoodStr(T_ei)) { /* if I have insert mode */
- (void) tputs(Str(T_im), 1, term__putc);
-
- el->el_cursor.h += num;
- do
- term__putc(*cp++);
- while (--num);
-
- if (GoodStr(T_ip)) /* have to make num chars insert */
- (void) tputs(Str(T_ip), 1, term__putc);
-
- (void) tputs(Str(T_ei), 1, term__putc);
- return;
- }
- do {
- if (GoodStr(T_ic)) /* have to make num chars insert */
- (void) tputs(Str(T_ic), 1, term__putc);
- /* insert a char */
-
- term__putc(*cp++);
-
- el->el_cursor.h++;
-
- if (GoodStr(T_ip)) /* have to make num chars insert */
- (void) tputs(Str(T_ip), 1, term__putc);
- /* pad the inserted char */
-
- } while (--num);
-}
-
-
-/* term_clear_EOL():
- * clear to end of line. There are num characters to clear
- */
-protected void
-term_clear_EOL(EditLine *el, int num)
-{
- int i;
-
- if (EL_CAN_CEOL && GoodStr(T_ce))
- (void) tputs(Str(T_ce), 1, term__putc);
- else {
- for (i = 0; i < num; i++)
- term__putc(' ');
- el->el_cursor.h += num; /* have written num spaces */
- }
-}
-
-
-/* term_clear_screen():
- * Clear the screen
- */
-protected void
-term_clear_screen(EditLine *el)
-{ /* clear the whole screen and home */
-
- if (GoodStr(T_cl))
- /* send the clear screen code */
- (void) tputs(Str(T_cl), Val(T_li), term__putc);
- else if (GoodStr(T_ho) && GoodStr(T_cd)) {
- (void) tputs(Str(T_ho), Val(T_li), term__putc); /* home */
- /* clear to bottom of screen */
- (void) tputs(Str(T_cd), Val(T_li), term__putc);
- } else {
- term__putc('\r');
- term__putc('\n');
- }
-}
-
-
-/* term_beep():
- * Beep the way the terminal wants us
- */
-protected void
-term_beep(EditLine *el)
-{
- if (GoodStr(T_bl))
- /* what termcap says we should use */
- (void) tputs(Str(T_bl), 1, term__putc);
- else
- term__putc('\007'); /* an ASCII bell; ^G */
-}
-
-
-#ifdef notdef
-/* term_clear_to_bottom():
- * Clear to the bottom of the screen
- */
-protected void
-term_clear_to_bottom(EditLine *el)
-{
- if (GoodStr(T_cd))
- (void) tputs(Str(T_cd), Val(T_li), term__putc);
- else if (GoodStr(T_ce))
- (void) tputs(Str(T_ce), Val(T_li), term__putc);
-}
-#endif
-
-
-/* term_set():
- * Read in the terminal capabilities from the requested terminal
- */
-protected int
-term_set(EditLine *el, const char *term)
-{
- int i;
- char buf[TC_BUFSIZE];
- char *area;
- const struct termcapstr *t;
- sigset_t oset, nset;
- int lins, cols;
-
- (void) sigemptyset(&nset);
- (void) sigaddset(&nset, SIGWINCH);
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
-
- area = buf;
-
-
- if (term == NULL)
- term = getenv("TERM");
-
- if (!term || !term[0])
- term = "dumb";
-
- if (strcmp(term, "emacs") == 0)
- el->el_flags |= EDIT_DISABLED;
-
- memset(el->el_term.t_cap, 0, TC_BUFSIZE);
-
- i = tgetent(el->el_term.t_cap, term);
-
- if (i <= 0) {
- if (i == -1)
- (void) fprintf(el->el_errfile,
- "Cannot read termcap database;\n");
- else if (i == 0)
- (void) fprintf(el->el_errfile,
- "No entry for terminal type \"%s\";\n", term);
- (void) fprintf(el->el_errfile,
- "using dumb terminal settings.\n");
- Val(T_co) = 80; /* do a dumb terminal */
- Val(T_pt) = Val(T_km) = Val(T_li) = 0;
- Val(T_xt) = Val(T_MT);
- for (t = tstr; t->name != NULL; t++)
- term_alloc(el, t, NULL);
- } else {
- /* auto/magic margins */
- Val(T_am) = tgetflag("am");
- Val(T_xn) = tgetflag("xn");
- /* Can we tab */
- Val(T_pt) = tgetflag("pt");
- Val(T_xt) = tgetflag("xt");
- /* do we have a meta? */
- Val(T_km) = tgetflag("km");
- Val(T_MT) = tgetflag("MT");
- /* Get the size */
- Val(T_co) = tgetnum("co");
- Val(T_li) = tgetnum("li");
- for (t = tstr; t->name != NULL; t++)
- term_alloc(el, t, tgetstr((char *)t->name, &area));
- }
-
- if (Val(T_co) < 2)
- Val(T_co) = 80; /* just in case */
- if (Val(T_li) < 1)
- Val(T_li) = 24;
-
- el->el_term.t_size.v = Val(T_co);
- el->el_term.t_size.h = Val(T_li);
-
- term_setflags(el);
-
- /* get the correct window size */
- (void) term_get_size(el, &lins, &cols);
- if (term_change_size(el, lins, cols) == -1)
- return (-1);
- (void) sigprocmask(SIG_SETMASK, &oset, NULL);
- term_bind_arrow(el);
- return (i <= 0 ? -1 : 0);
-}
-
-
-/* term_get_size():
- * Return the new window size in lines and cols, and
- * true if the size was changed.
- */
-protected int
-term_get_size(EditLine *el, int *lins, int *cols)
-{
-
- *cols = Val(T_co);
- *lins = Val(T_li);
-
-#ifdef TIOCGWINSZ
- {
- struct winsize ws;
- if (ioctl(el->el_infd, TIOCGWINSZ, (ioctl_t) & ws) != -1) {
- if (ws.ws_col)
- *cols = ws.ws_col;
- if (ws.ws_row)
- *lins = ws.ws_row;
- }
- }
-#endif
-#ifdef TIOCGSIZE
- {
- struct ttysize ts;
- if (ioctl(el->el_infd, TIOCGSIZE, (ioctl_t) & ts) != -1) {
- if (ts.ts_cols)
- *cols = ts.ts_cols;
- if (ts.ts_lines)
- *lins = ts.ts_lines;
- }
- }
-#endif
- return (Val(T_co) != *cols || Val(T_li) != *lins);
-}
-
-
-/* term_change_size():
- * Change the size of the terminal
- */
-protected int
-term_change_size(EditLine *el, int lins, int cols)
-{
- /*
- * Just in case
- */
- Val(T_co) = (cols < 2) ? 80 : cols;
- Val(T_li) = (lins < 1) ? 24 : lins;
-
- /* re-make display buffers */
- if (term_rebuffer_display(el) == -1)
- return (-1);
- re_clear_display(el);
- return (0);
-}
-
-
-/* term_init_arrow():
- * Initialize the arrow key bindings from termcap
- */
-private void
-term_init_arrow(EditLine *el)
-{
- fkey_t *arrow = el->el_term.t_fkey;
-
- arrow[A_K_DN].name = "down";
- arrow[A_K_DN].key = T_kd;
- arrow[A_K_DN].fun.cmd = ED_NEXT_HISTORY;
- arrow[A_K_DN].type = XK_CMD;
-
- arrow[A_K_UP].name = "up";
- arrow[A_K_UP].key = T_ku;
- arrow[A_K_UP].fun.cmd = ED_PREV_HISTORY;
- arrow[A_K_UP].type = XK_CMD;
-
- arrow[A_K_LT].name = "left";
- arrow[A_K_LT].key = T_kl;
- arrow[A_K_LT].fun.cmd = ED_PREV_CHAR;
- arrow[A_K_LT].type = XK_CMD;
-
- arrow[A_K_RT].name = "right";
- arrow[A_K_RT].key = T_kr;
- arrow[A_K_RT].fun.cmd = ED_NEXT_CHAR;
- arrow[A_K_RT].type = XK_CMD;
-
- arrow[A_K_HO].name = "home";
- arrow[A_K_HO].key = T_kh;
- arrow[A_K_HO].fun.cmd = ED_MOVE_TO_BEG;
- arrow[A_K_HO].type = XK_CMD;
-
- arrow[A_K_EN].name = "end";
- arrow[A_K_EN].key = T_at7;
- arrow[A_K_EN].fun.cmd = ED_MOVE_TO_END;
- arrow[A_K_EN].type = XK_CMD;
-}
-
-
-/* term_reset_arrow():
- * Reset arrow key bindings
- */
-private void
-term_reset_arrow(EditLine *el)
-{
- fkey_t *arrow = el->el_term.t_fkey;
- static const char strA[] = {033, '[', 'A', '\0'};
- static const char strB[] = {033, '[', 'B', '\0'};
- static const char strC[] = {033, '[', 'C', '\0'};
- static const char strD[] = {033, '[', 'D', '\0'};
- static const char strH[] = {033, '[', 'H', '\0'};
- static const char strF[] = {033, '[', 'F', '\0'};
- static const char stOA[] = {033, 'O', 'A', '\0'};
- static const char stOB[] = {033, 'O', 'B', '\0'};
- static const char stOC[] = {033, 'O', 'C', '\0'};
- static const char stOD[] = {033, 'O', 'D', '\0'};
- static const char stOH[] = {033, 'O', 'H', '\0'};
- static const char stOF[] = {033, 'O', 'F', '\0'};
-
- key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- key_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
-
- if (el->el_map.type == MAP_VI) {
- key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- key_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- }
-}
-
-
-/* term_set_arrow():
- * Set an arrow key binding
- */
-protected int
-term_set_arrow(EditLine *el, const char *name, key_value_t *fun, int type)
-{
- fkey_t *arrow = el->el_term.t_fkey;
- int i;
-
- for (i = 0; i < A_K_NKEYS; i++)
- if (strcmp(name, arrow[i].name) == 0) {
- arrow[i].fun = *fun;
- arrow[i].type = type;
- return (0);
- }
- return (-1);
-}
-
-
-/* term_clear_arrow():
- * Clear an arrow key binding
- */
-protected int
-term_clear_arrow(EditLine *el, const char *name)
-{
- fkey_t *arrow = el->el_term.t_fkey;
- int i;
-
- for (i = 0; i < A_K_NKEYS; i++)
- if (strcmp(name, arrow[i].name) == 0) {
- arrow[i].type = XK_NOD;
- return (0);
- }
- return (-1);
-}
-
-
-/* term_print_arrow():
- * Print the arrow key bindings
- */
-protected void
-term_print_arrow(EditLine *el, const char *name)
-{
- int i;
- fkey_t *arrow = el->el_term.t_fkey;
-
- for (i = 0; i < A_K_NKEYS; i++)
- if (*name == '\0' || strcmp(name, arrow[i].name) == 0)
- if (arrow[i].type != XK_NOD)
- key_kprint(el, arrow[i].name, &arrow[i].fun,
- arrow[i].type);
-}
-
-
-/* term_bind_arrow():
- * Bind the arrow keys
- */
-protected void
-term_bind_arrow(EditLine *el)
-{
- el_action_t *map;
- const el_action_t *dmap;
- int i, j;
- char *p;
- fkey_t *arrow = el->el_term.t_fkey;
-
- /* Check if the components needed are initialized */
- if (el->el_term.t_buf == NULL || el->el_map.key == NULL)
- return;
-
- map = el->el_map.type == MAP_VI ? el->el_map.alt : el->el_map.key;
- dmap = el->el_map.type == MAP_VI ? el->el_map.vic : el->el_map.emacs;
-
- term_reset_arrow(el);
-
- for (i = 0; i < A_K_NKEYS; i++) {
- p = el->el_term.t_str[arrow[i].key];
- if (p && *p) {
- j = (unsigned char) *p;
- /*
- * Assign the arrow keys only if:
- *
- * 1. They are multi-character arrow keys and the user
- * has not re-assigned the leading character, or
- * has re-assigned the leading character to be
- * ED_SEQUENCE_LEAD_IN
- * 2. They are single arrow keys pointing to an
- * unassigned key.
- */
- if (arrow[i].type == XK_NOD)
- key_clear(el, map, p);
- else {
- if (p[1] && (dmap[j] == map[j] ||
- map[j] == ED_SEQUENCE_LEAD_IN)) {
- key_add(el, p, &arrow[i].fun,
- arrow[i].type);
- map[j] = ED_SEQUENCE_LEAD_IN;
- } else if (map[j] == ED_UNASSIGNED) {
- key_clear(el, map, p);
- if (arrow[i].type == XK_CMD)
- map[j] = arrow[i].fun.cmd;
- else
- key_add(el, p, &arrow[i].fun,
- arrow[i].type);
- }
- }
- }
- }
-}
-
-
-/* term__putc():
- * Add a character
- */
-protected int
-term__putc(int c)
-{
-
- return (fputc(c, term_outfile));
-}
-
-
-/* term__flush():
- * Flush output
- */
-protected void
-term__flush(void)
-{
-
- (void) fflush(term_outfile);
-}
-
-
-/* term_telltc():
- * Print the current termcap characteristics
- */
-protected int
-/*ARGSUSED*/
-term_telltc(EditLine *el, int argc, const char **argv)
-{
- const struct termcapstr *t;
- char **ts;
- char upbuf[EL_BUFSIZ];
-
- (void) fprintf(el->el_outfile, "\n\tYour terminal has the\n");
- (void) fprintf(el->el_outfile, "\tfollowing characteristics:\n\n");
- (void) fprintf(el->el_outfile, "\tIt has %d columns and %d lines\n",
- Val(T_co), Val(T_li));
- (void) fprintf(el->el_outfile,
- "\tIt has %s meta key\n", EL_HAS_META ? "a" : "no");
- (void) fprintf(el->el_outfile,
- "\tIt can%suse tabs\n", EL_CAN_TAB ? " " : "not ");
- (void) fprintf(el->el_outfile, "\tIt %s automatic margins\n",
- EL_HAS_AUTO_MARGINS ? "has" : "does not have");
- if (EL_HAS_AUTO_MARGINS)
- (void) fprintf(el->el_outfile, "\tIt %s magic margins\n",
- EL_HAS_MAGIC_MARGINS ? "has" : "does not have");
-
- for (t = tstr, ts = el->el_term.t_str; t->name != NULL; t++, ts++)
- (void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n",
- t->long_name,
- t->name, *ts && **ts ?
- key__decode_str(*ts, upbuf, "") : "(empty)");
- (void) fputc('\n', el->el_outfile);
- return (0);
-}
-
-
-/* term_settc():
- * Change the current terminal characteristics
- */
-protected int
-/*ARGSUSED*/
-term_settc(EditLine *el, int argc, const char **argv)
-{
- const struct termcapstr *ts;
- const struct termcapval *tv;
- const char *what, *how;
-
- if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
- return (-1);
-
- what = argv[1];
- how = argv[2];
-
- /*
- * Do the strings first
- */
- for (ts = tstr; ts->name != NULL; ts++)
- if (strcmp(ts->name, what) == 0)
- break;
-
- if (ts->name != NULL) {
- term_alloc(el, ts, how);
- term_setflags(el);
- return (0);
- }
- /*
- * Do the numeric ones second
- */
- for (tv = tval; tv->name != NULL; tv++)
- if (strcmp(tv->name, what) == 0)
- break;
-
- if (tv->name != NULL) {
- if (tv == &tval[T_pt] || tv == &tval[T_km] ||
- tv == &tval[T_am] || tv == &tval[T_xn]) {
- if (strcmp(how, "yes") == 0)
- el->el_term.t_val[tv - tval] = 1;
- else if (strcmp(how, "no") == 0)
- el->el_term.t_val[tv - tval] = 0;
- else {
- (void) fprintf(el->el_errfile,
- "settc: Bad value `%s'.\n", how);
- return (-1);
- }
- term_setflags(el);
- if (term_change_size(el, Val(T_li), Val(T_co)) == -1)
- return (-1);
- return (0);
- } else {
- long i;
- char *ep;
-
- i = strtol(how, &ep, 10);
- if (*ep != '\0') {
- (void) fprintf(el->el_errfile,
- "settc: Bad value `%s'.\n", how);
- return (-1);
- }
- el->el_term.t_val[tv - tval] = (int) i;
- el->el_term.t_size.v = Val(T_co);
- el->el_term.t_size.h = Val(T_li);
- if (tv == &tval[T_co] || tv == &tval[T_li])
- if (term_change_size(el, Val(T_li), Val(T_co))
- == -1)
- return (-1);
- return (0);
- }
- }
- return (-1);
-}
-
-
-/* term_echotc():
- * Print the termcap string out with variable substitution
- */
-protected int
-/*ARGSUSED*/
-term_echotc(EditLine *el, int argc, const char **argv)
-{
- char *cap, *scap, *ep;
- int arg_need, arg_cols, arg_rows;
- int verbose = 0, silent = 0;
- char *area;
- static const char fmts[] = "%s\n", fmtd[] = "%d\n";
- const struct termcapstr *t;
- char buf[TC_BUFSIZE];
- long i;
-
- area = buf;
-
- if (argv == NULL || argv[1] == NULL)
- return (-1);
- argv++;
-
- if (argv[0][0] == '-') {
- switch (argv[0][1]) {
- case 'v':
- verbose = 1;
- break;
- case 's':
- silent = 1;
- break;
- default:
- /* stderror(ERR_NAME | ERR_TCUSAGE); */
- break;
- }
- argv++;
- }
- if (!*argv || *argv[0] == '\0')
- return (0);
- if (strcmp(*argv, "tabs") == 0) {
- (void) fprintf(el->el_outfile, fmts, EL_CAN_TAB ? "yes" : "no");
- return (0);
- } else if (strcmp(*argv, "meta") == 0) {
- (void) fprintf(el->el_outfile, fmts, Val(T_km) ? "yes" : "no");
- return (0);
- } else if (strcmp(*argv, "xn") == 0) {
- (void) fprintf(el->el_outfile, fmts, EL_HAS_MAGIC_MARGINS ?
- "yes" : "no");
- return (0);
- } else if (strcmp(*argv, "am") == 0) {
- (void) fprintf(el->el_outfile, fmts, EL_HAS_AUTO_MARGINS ?
- "yes" : "no");
- return (0);
- } else if (strcmp(*argv, "baud") == 0) {
-#ifdef notdef
- int i;
-
- for (i = 0; baud_rate[i].b_name != NULL; i++)
- if (el->el_tty.t_speed == baud_rate[i].b_rate) {
- (void) fprintf(el->el_outfile, fmts,
- baud_rate[i].b_name);
- return (0);
- }
- (void) fprintf(el->el_outfile, fmtd, 0);
-#else
- (void) fprintf(el->el_outfile, fmtd, el->el_tty.t_speed);
-#endif
- return (0);
- } else if (strcmp(*argv, "rows") == 0 || strcmp(*argv, "lines") == 0) {
- (void) fprintf(el->el_outfile, fmtd, Val(T_li));
- return (0);
- } else if (strcmp(*argv, "cols") == 0) {
- (void) fprintf(el->el_outfile, fmtd, Val(T_co));
- return (0);
- }
- /*
- * Try to use our local definition first
- */
- scap = NULL;
- for (t = tstr; t->name != NULL; t++)
- if (strcmp(t->name, *argv) == 0) {
- scap = el->el_term.t_str[t - tstr];
- break;
- }
- if (t->name == NULL)
- scap = tgetstr((char *)argv, &area);
- if (!scap || scap[0] == '\0') {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Termcap parameter `%s' not found.\n",
- *argv);
- return (-1);
- }
- /*
- * Count home many values we need for this capability.
- */
- for (cap = scap, arg_need = 0; *cap; cap++)
- if (*cap == '%')
- switch (*++cap) {
- case 'd':
- case '2':
- case '3':
- case '.':
- case '+':
- arg_need++;
- break;
- case '%':
- case '>':
- case 'i':
- case 'r':
- case 'n':
- case 'B':
- case 'D':
- break;
- default:
- /*
- * hpux has lot's of them...
- */
- if (verbose)
- (void) fprintf(el->el_errfile,
- "echotc: Warning: unknown termcap %% `%c'.\n",
- *cap);
- /* This is bad, but I won't complain */
- break;
- }
-
- switch (arg_need) {
- case 0:
- argv++;
- if (*argv && *argv[0]) {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Warning: Extra argument `%s'.\n",
- *argv);
- return (-1);
- }
- (void) tputs(scap, 1, term__putc);
- break;
- case 1:
- argv++;
- if (!*argv || *argv[0] == '\0') {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Warning: Missing argument.\n");
- return (-1);
- }
- arg_cols = 0;
- i = strtol(*argv, &ep, 10);
- if (*ep != '\0' || i < 0) {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Bad value `%s' for rows.\n",
- *argv);
- return (-1);
- }
- arg_rows = (int) i;
- argv++;
- if (*argv && *argv[0]) {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Warning: Extra argument `%s'.\n",
- *argv);
- return (-1);
- }
- (void) tputs(tgoto(scap, arg_cols, arg_rows), 1, term__putc);
- break;
- default:
- /* This is wrong, but I will ignore it... */
- if (verbose)
- (void) fprintf(el->el_errfile,
- "echotc: Warning: Too many required arguments (%d).\n",
- arg_need);
- /* FALLTHROUGH */
- case 2:
- argv++;
- if (!*argv || *argv[0] == '\0') {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Warning: Missing argument.\n");
- return (-1);
- }
- i = strtol(*argv, &ep, 10);
- if (*ep != '\0' || i < 0) {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Bad value `%s' for cols.\n",
- *argv);
- return (-1);
- }
- arg_cols = (int) i;
- argv++;
- if (!*argv || *argv[0] == '\0') {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Warning: Missing argument.\n");
- return (-1);
- }
- i = strtol(*argv, &ep, 10);
- if (*ep != '\0' || i < 0) {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Bad value `%s' for rows.\n",
- *argv);
- return (-1);
- }
- arg_rows = (int) i;
- if (*ep != '\0') {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Bad value `%s'.\n", *argv);
- return (-1);
- }
- argv++;
- if (*argv && *argv[0]) {
- if (!silent)
- (void) fprintf(el->el_errfile,
- "echotc: Warning: Extra argument `%s'.\n",
- *argv);
- return (-1);
- }
- (void) tputs(tgoto(scap, arg_cols, arg_rows), arg_rows,
- term__putc);
- break;
- }
- return (0);
-}
diff --git a/1.2-netsec/editline/term.h b/1.2-netsec/editline/term.h
deleted file mode 100644
index 47e08e84b..000000000
--- a/1.2-netsec/editline/term.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/* $NetBSD: term.h,v 1.13 2002/03/18 16:01:00 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)term.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.term.h: Termcap header
- */
-#ifndef _h_el_term
-#define _h_el_term
-
-#include "histedit.h"
-
-typedef struct { /* Symbolic function key bindings */
- const char *name; /* name of the key */
- int key; /* Index in termcap table */
- key_value_t fun; /* Function bound to it */
- int type; /* Type of function */
-} fkey_t;
-
-typedef struct {
- coord_t t_size; /* # lines and cols */
- int t_flags;
-#define TERM_CAN_INSERT 0x001 /* Has insert cap */
-#define TERM_CAN_DELETE 0x002 /* Has delete cap */
-#define TERM_CAN_CEOL 0x004 /* Has CEOL cap */
-#define TERM_CAN_TAB 0x008 /* Can use tabs */
-#define TERM_CAN_ME 0x010 /* Can turn all attrs. */
-#define TERM_CAN_UP 0x020 /* Can move up */
-#define TERM_HAS_META 0x040 /* Has a meta key */
-#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
-#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
- char *t_buf; /* Termcap buffer */
- int t_loc; /* location used */
- char **t_str; /* termcap strings */
- int *t_val; /* termcap values */
- char *t_cap; /* Termcap buffer */
- fkey_t *t_fkey; /* Array of keys */
-} el_term_t;
-
-/*
- * fKey indexes
- */
-#define A_K_DN 0
-#define A_K_UP 1
-#define A_K_LT 2
-#define A_K_RT 3
-#define A_K_HO 4
-#define A_K_EN 5
-#define A_K_NKEYS 6
-
-protected void term_move_to_line(EditLine *, int);
-protected void term_move_to_char(EditLine *, int);
-protected void term_clear_EOL(EditLine *, int);
-protected void term_overwrite(EditLine *, const char *, int);
-protected void term_insertwrite(EditLine *, char *, int);
-protected void term_deletechars(EditLine *, int);
-protected void term_clear_screen(EditLine *);
-protected void term_beep(EditLine *);
-protected int term_change_size(EditLine *, int, int);
-protected int term_get_size(EditLine *, int *, int *);
-protected int term_init(EditLine *);
-protected void term_bind_arrow(EditLine *);
-protected void term_print_arrow(EditLine *, const char *);
-protected int term_clear_arrow(EditLine *, const char *);
-protected int term_set_arrow(EditLine *, const char *, key_value_t *, int);
-protected void term_end(EditLine *);
-protected int term_set(EditLine *, const char *);
-protected int term_settc(EditLine *, int, const char **);
-protected int term_telltc(EditLine *, int, const char **);
-protected int term_echotc(EditLine *, int, const char **);
-protected int term__putc(int);
-protected void term__flush(void);
-
-/*
- * Easy access macros
- */
-#define EL_FLAGS (el)->el_term.t_flags
-
-#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
-#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
-#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL)
-#define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB)
-#define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME)
-#define EL_HAS_META (EL_FLAGS & TERM_HAS_META)
-#define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS)
-#define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS)
-
-#endif /* _h_el_term */
diff --git a/1.2-netsec/editline/tokenizer.c b/1.2-netsec/editline/tokenizer.c
deleted file mode 100644
index f0de39bc9..000000000
--- a/1.2-netsec/editline/tokenizer.c
+++ /dev/null
@@ -1,397 +0,0 @@
-/* $NetBSD: tokenizer.c,v 1.10 2002/03/18 16:01:00 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: tokenizer.c,v 1.10 2002/03/18 16:01:00 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * tokenize.c: Bourne shell like tokenizer
- */
-#include <string.h>
-#include <stdlib.h>
-#include "tokenizer.h"
-
-typedef enum {
- Q_none, Q_single, Q_double, Q_one, Q_doubleone
-} quote_t;
-
-#define IFS "\t \n"
-
-#define TOK_KEEP 1
-#define TOK_EAT 2
-
-#define WINCR 20
-#define AINCR 10
-
-#define tok_malloc(a) malloc(a)
-#define tok_free(a) free(a)
-#define tok_realloc(a, b) realloc(a, b)
-
-
-struct tokenizer {
- char *ifs; /* In field separator */
- int argc, amax; /* Current and maximum number of args */
- char **argv; /* Argument list */
- char *wptr, *wmax; /* Space and limit on the word buffer */
- char *wstart; /* Beginning of next word */
- char *wspace; /* Space of word buffer */
- quote_t quote; /* Quoting state */
- int flags; /* flags; */
-};
-
-
-private void tok_finish(Tokenizer *);
-
-
-/* tok_finish():
- * Finish a word in the tokenizer.
- */
-private void
-tok_finish(Tokenizer *tok)
-{
-
- *tok->wptr = '\0';
- if ((tok->flags & TOK_KEEP) || tok->wptr != tok->wstart) {
- tok->argv[tok->argc++] = tok->wstart;
- tok->argv[tok->argc] = NULL;
- tok->wstart = ++tok->wptr;
- }
- tok->flags &= ~TOK_KEEP;
-}
-
-
-/* tok_init():
- * Initialize the tokenizer
- */
-public Tokenizer *
-tok_init(const char *ifs)
-{
- Tokenizer *tok = (Tokenizer *) tok_malloc(sizeof(Tokenizer));
-
- tok->ifs = strdup(ifs ? ifs : IFS);
- tok->argc = 0;
- tok->amax = AINCR;
- tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax);
- if (tok->argv == NULL)
- return (NULL);
- tok->argv[0] = NULL;
- tok->wspace = (char *) tok_malloc(WINCR);
- if (tok->wspace == NULL)
- return (NULL);
- tok->wmax = tok->wspace + WINCR;
- tok->wstart = tok->wspace;
- tok->wptr = tok->wspace;
- tok->flags = 0;
- tok->quote = Q_none;
-
- return (tok);
-}
-
-
-/* tok_reset():
- * Reset the tokenizer
- */
-public void
-tok_reset(Tokenizer *tok)
-{
-
- tok->argc = 0;
- tok->wstart = tok->wspace;
- tok->wptr = tok->wspace;
- tok->flags = 0;
- tok->quote = Q_none;
-}
-
-
-/* tok_end():
- * Clean up
- */
-public void
-tok_end(Tokenizer *tok)
-{
-
- tok_free((ptr_t) tok->ifs);
- tok_free((ptr_t) tok->wspace);
- tok_free((ptr_t) tok->argv);
- tok_free((ptr_t) tok);
-}
-
-
-
-/* tok_line():
- * Bourne shell like tokenizing
- * Return:
- * -1: Internal error
- * 3: Quoted return
- * 2: Unmatched double quote
- * 1: Unmatched single quote
- * 0: Ok
- */
-public int
-tok_line(Tokenizer *tok, const char *line, int *argc, const char ***argv)
-{
- const char *ptr;
-
- for (;;) {
- switch (*(ptr = line++)) {
- case '\'':
- tok->flags |= TOK_KEEP;
- tok->flags &= ~TOK_EAT;
- switch (tok->quote) {
- case Q_none:
- tok->quote = Q_single; /* Enter single quote
- * mode */
- break;
-
- case Q_single: /* Exit single quote mode */
- tok->quote = Q_none;
- break;
-
- case Q_one: /* Quote this ' */
- tok->quote = Q_none;
- *tok->wptr++ = *ptr;
- break;
-
- case Q_double: /* Stay in double quote mode */
- *tok->wptr++ = *ptr;
- break;
-
- case Q_doubleone: /* Quote this ' */
- tok->quote = Q_double;
- *tok->wptr++ = *ptr;
- break;
-
- default:
- return (-1);
- }
- break;
-
- case '"':
- tok->flags &= ~TOK_EAT;
- tok->flags |= TOK_KEEP;
- switch (tok->quote) {
- case Q_none: /* Enter double quote mode */
- tok->quote = Q_double;
- break;
-
- case Q_double: /* Exit double quote mode */
- tok->quote = Q_none;
- break;
-
- case Q_one: /* Quote this " */
- tok->quote = Q_none;
- *tok->wptr++ = *ptr;
- break;
-
- case Q_single: /* Stay in single quote mode */
- *tok->wptr++ = *ptr;
- break;
-
- case Q_doubleone: /* Quote this " */
- tok->quote = Q_double;
- *tok->wptr++ = *ptr;
- break;
-
- default:
- return (-1);
- }
- break;
-
- case '\\':
- tok->flags |= TOK_KEEP;
- tok->flags &= ~TOK_EAT;
- switch (tok->quote) {
- case Q_none: /* Quote next character */
- tok->quote = Q_one;
- break;
-
- case Q_double: /* Quote next character */
- tok->quote = Q_doubleone;
- break;
-
- case Q_one: /* Quote this, restore state */
- *tok->wptr++ = *ptr;
- tok->quote = Q_none;
- break;
-
- case Q_single: /* Stay in single quote mode */
- *tok->wptr++ = *ptr;
- break;
-
- case Q_doubleone: /* Quote this \ */
- tok->quote = Q_double;
- *tok->wptr++ = *ptr;
- break;
-
- default:
- return (-1);
- }
- break;
-
- case '\n':
- tok->flags &= ~TOK_EAT;
- switch (tok->quote) {
- case Q_none:
- tok_finish(tok);
- *argv = (const char **)tok->argv;
- *argc = tok->argc;
- return (0);
-
- case Q_single:
- case Q_double:
- *tok->wptr++ = *ptr; /* Add the return */
- break;
-
- case Q_doubleone: /* Back to double, eat the '\n' */
- tok->flags |= TOK_EAT;
- tok->quote = Q_double;
- break;
-
- case Q_one: /* No quote, more eat the '\n' */
- tok->flags |= TOK_EAT;
- tok->quote = Q_none;
- break;
-
- default:
- return (0);
- }
- break;
-
- case '\0':
- switch (tok->quote) {
- case Q_none:
- /* Finish word and return */
- if (tok->flags & TOK_EAT) {
- tok->flags &= ~TOK_EAT;
- return (3);
- }
- tok_finish(tok);
- *argv = (const char **)tok->argv;
- *argc = tok->argc;
- return (0);
-
- case Q_single:
- return (1);
-
- case Q_double:
- return (2);
-
- case Q_doubleone:
- tok->quote = Q_double;
- *tok->wptr++ = *ptr;
- break;
-
- case Q_one:
- tok->quote = Q_none;
- *tok->wptr++ = *ptr;
- break;
-
- default:
- return (-1);
- }
- break;
-
- default:
- tok->flags &= ~TOK_EAT;
- switch (tok->quote) {
- case Q_none:
- if (strchr(tok->ifs, *ptr) != NULL)
- tok_finish(tok);
- else
- *tok->wptr++ = *ptr;
- break;
-
- case Q_single:
- case Q_double:
- *tok->wptr++ = *ptr;
- break;
-
-
- case Q_doubleone:
- *tok->wptr++ = '\\';
- tok->quote = Q_double;
- *tok->wptr++ = *ptr;
- break;
-
- case Q_one:
- tok->quote = Q_none;
- *tok->wptr++ = *ptr;
- break;
-
- default:
- return (-1);
-
- }
- break;
- }
-
- if (tok->wptr >= tok->wmax - 4) {
- size_t size = tok->wmax - tok->wspace + WINCR;
- char *s = (char *) tok_realloc(tok->wspace, size);
- if (s == NULL)
- return (-1);
-
- if (s != tok->wspace) {
- int i;
- for (i = 0; i < tok->argc; i++) {
- tok->argv[i] =
- (tok->argv[i] - tok->wspace) + s;
- }
- tok->wptr = (tok->wptr - tok->wspace) + s;
- tok->wstart = (tok->wstart - tok->wspace) + s;
- tok->wspace = s;
- }
- tok->wmax = s + size;
- }
- if (tok->argc >= tok->amax - 4) {
- char **p;
- tok->amax += AINCR;
- p = (char **) tok_realloc(tok->argv,
- tok->amax * sizeof(char *));
- if (p == NULL)
- return (-1);
- tok->argv = p;
- }
- }
-}
diff --git a/1.2-netsec/editline/tokenizer.h b/1.2-netsec/editline/tokenizer.h
deleted file mode 100644
index 7cc7a3346..000000000
--- a/1.2-netsec/editline/tokenizer.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* $NetBSD: tokenizer.h,v 1.5 2002/03/18 16:01:00 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)tokenizer.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * tokenizer.h: Header file for tokenizer routines
- */
-#ifndef _h_tokenizer
-#define _h_tokenizer
-
-typedef struct tokenizer Tokenizer;
-
-Tokenizer *tok_init(const char *);
-void tok_reset(Tokenizer *);
-void tok_end(Tokenizer *);
-int tok_line(Tokenizer *, const char *, int *, const char ***);
-
-#endif /* _h_tokenizer */
diff --git a/1.2-netsec/editline/tty.c b/1.2-netsec/editline/tty.c
deleted file mode 100644
index 256cf780b..000000000
--- a/1.2-netsec/editline/tty.c
+++ /dev/null
@@ -1,1182 +0,0 @@
-/* $NetBSD: tty.c,v 1.16 2002/03/18 16:01:01 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: tty.c,v 1.16 2002/03/18 16:01:01 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * tty.c: tty interface stuff
- */
-#include "tty.h"
-#include "el.h"
-
-typedef struct ttymodes_t {
- const char *m_name;
- u_int m_value;
- int m_type;
-} ttymodes_t;
-
-typedef struct ttymap_t {
- int nch, och; /* Internal and termio rep of chars */
- el_action_t bind[3]; /* emacs, vi, and vi-cmd */
-} ttymap_t;
-
-
-private const ttyperm_t ttyperm = {
- {
- {"iflag:", ICRNL, (INLCR | IGNCR)},
- {"oflag:", (OPOST | ONLCR), ONLRET},
- {"cflag:", 0, 0},
- {"lflag:", (ISIG | ICANON | ECHO | ECHOE | ECHOCTL | IEXTEN),
- (NOFLSH | ECHONL | EXTPROC | FLUSHO)},
- {"chars:", 0, 0},
- },
- {
- {"iflag:", (INLCR | ICRNL), IGNCR},
- {"oflag:", (OPOST | ONLCR), ONLRET},
- {"cflag:", 0, 0},
- {"lflag:", ISIG,
- (NOFLSH | ICANON | ECHO | ECHOK | ECHONL | EXTPROC | IEXTEN | FLUSHO)},
- {"chars:", (C_SH(C_MIN) | C_SH(C_TIME) | C_SH(C_SWTCH) | C_SH(C_DSWTCH) |
- C_SH(C_SUSP) | C_SH(C_DSUSP) | C_SH(C_EOL) | C_SH(C_DISCARD) |
- C_SH(C_PGOFF) | C_SH(C_PAGE) | C_SH(C_STATUS)), 0}
- },
- {
- {"iflag:", 0, IXON | IXOFF | INLCR | ICRNL},
- {"oflag:", 0, 0},
- {"cflag:", 0, 0},
- {"lflag:", 0, ISIG | IEXTEN},
- {"chars:", 0, 0},
- }
-};
-
-private const ttychar_t ttychar = {
- {
- CINTR, CQUIT, CERASE, CKILL,
- CEOF, CEOL, CEOL2, CSWTCH,
- CDSWTCH, CERASE2, CSTART, CSTOP,
- CWERASE, CSUSP, CDSUSP, CREPRINT,
- CDISCARD, CLNEXT, CSTATUS, CPAGE,
- CPGOFF, CKILL2, CBRK, CMIN,
- CTIME
- },
- {
- CINTR, CQUIT, CERASE, CKILL,
- _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE,
- _POSIX_VDISABLE, CERASE2, CSTART, CSTOP,
- _POSIX_VDISABLE, CSUSP, _POSIX_VDISABLE, _POSIX_VDISABLE,
- CDISCARD, _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE,
- _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE, 1,
- 0
- },
- {
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0
- }
-};
-
-private const ttymap_t tty_map[] = {
-#ifdef VERASE
- {C_ERASE, VERASE,
- {ED_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
-#endif /* VERASE */
-#ifdef VERASE2
- {C_ERASE2, VERASE2,
- {ED_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
-#endif /* VERASE2 */
-#ifdef VKILL
- {C_KILL, VKILL,
- {EM_KILL_LINE, VI_KILL_LINE_PREV, ED_UNASSIGNED}},
-#endif /* VKILL */
-#ifdef VKILL2
- {C_KILL2, VKILL2,
- {EM_KILL_LINE, VI_KILL_LINE_PREV, ED_UNASSIGNED}},
-#endif /* VKILL2 */
-#ifdef VEOF
- {C_EOF, VEOF,
- {EM_DELETE_OR_LIST, VI_LIST_OR_EOF, ED_UNASSIGNED}},
-#endif /* VEOF */
-#ifdef VWERASE
- {C_WERASE, VWERASE,
- {ED_DELETE_PREV_WORD, ED_DELETE_PREV_WORD, ED_PREV_WORD}},
-#endif /* VWERASE */
-#ifdef VREPRINT
- {C_REPRINT, VREPRINT,
- {ED_REDISPLAY, ED_INSERT, ED_REDISPLAY}},
-#endif /* VREPRINT */
-#ifdef VLNEXT
- {C_LNEXT, VLNEXT,
- {ED_QUOTED_INSERT, ED_QUOTED_INSERT, ED_UNASSIGNED}},
-#endif /* VLNEXT */
- {-1, -1,
- {ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED}}
-};
-
-private const ttymodes_t ttymodes[] = {
-#ifdef IGNBRK
- {"ignbrk", IGNBRK, MD_INP},
-#endif /* IGNBRK */
-#ifdef BRKINT
- {"brkint", BRKINT, MD_INP},
-#endif /* BRKINT */
-#ifdef IGNPAR
- {"ignpar", IGNPAR, MD_INP},
-#endif /* IGNPAR */
-#ifdef PARMRK
- {"parmrk", PARMRK, MD_INP},
-#endif /* PARMRK */
-#ifdef INPCK
- {"inpck", INPCK, MD_INP},
-#endif /* INPCK */
-#ifdef ISTRIP
- {"istrip", ISTRIP, MD_INP},
-#endif /* ISTRIP */
-#ifdef INLCR
- {"inlcr", INLCR, MD_INP},
-#endif /* INLCR */
-#ifdef IGNCR
- {"igncr", IGNCR, MD_INP},
-#endif /* IGNCR */
-#ifdef ICRNL
- {"icrnl", ICRNL, MD_INP},
-#endif /* ICRNL */
-#ifdef IUCLC
- {"iuclc", IUCLC, MD_INP},
-#endif /* IUCLC */
-#ifdef IXON
- {"ixon", IXON, MD_INP},
-#endif /* IXON */
-#ifdef IXANY
- {"ixany", IXANY, MD_INP},
-#endif /* IXANY */
-#ifdef IXOFF
- {"ixoff", IXOFF, MD_INP},
-#endif /* IXOFF */
-#ifdef IMAXBEL
- {"imaxbel", IMAXBEL, MD_INP},
-#endif /* IMAXBEL */
-
-#ifdef OPOST
- {"opost", OPOST, MD_OUT},
-#endif /* OPOST */
-#ifdef OLCUC
- {"olcuc", OLCUC, MD_OUT},
-#endif /* OLCUC */
-#ifdef ONLCR
- {"onlcr", ONLCR, MD_OUT},
-#endif /* ONLCR */
-#ifdef OCRNL
- {"ocrnl", OCRNL, MD_OUT},
-#endif /* OCRNL */
-#ifdef ONOCR
- {"onocr", ONOCR, MD_OUT},
-#endif /* ONOCR */
-#ifdef ONOEOT
- {"onoeot", ONOEOT, MD_OUT},
-#endif /* ONOEOT */
-#ifdef ONLRET
- {"onlret", ONLRET, MD_OUT},
-#endif /* ONLRET */
-#ifdef OFILL
- {"ofill", OFILL, MD_OUT},
-#endif /* OFILL */
-#ifdef OFDEL
- {"ofdel", OFDEL, MD_OUT},
-#endif /* OFDEL */
-#ifdef NLDLY
- {"nldly", NLDLY, MD_OUT},
-#endif /* NLDLY */
-#ifdef CRDLY
- {"crdly", CRDLY, MD_OUT},
-#endif /* CRDLY */
-#ifdef TABDLY
- {"tabdly", TABDLY, MD_OUT},
-#endif /* TABDLY */
-#ifdef XTABS
- {"xtabs", XTABS, MD_OUT},
-#endif /* XTABS */
-#ifdef BSDLY
- {"bsdly", BSDLY, MD_OUT},
-#endif /* BSDLY */
-#ifdef VTDLY
- {"vtdly", VTDLY, MD_OUT},
-#endif /* VTDLY */
-#ifdef FFDLY
- {"ffdly", FFDLY, MD_OUT},
-#endif /* FFDLY */
-#ifdef PAGEOUT
- {"pageout", PAGEOUT, MD_OUT},
-#endif /* PAGEOUT */
-#ifdef WRAP
- {"wrap", WRAP, MD_OUT},
-#endif /* WRAP */
-
-#ifdef CIGNORE
- {"cignore", CIGNORE, MD_CTL},
-#endif /* CBAUD */
-#ifdef CBAUD
- {"cbaud", CBAUD, MD_CTL},
-#endif /* CBAUD */
-#ifdef CSTOPB
- {"cstopb", CSTOPB, MD_CTL},
-#endif /* CSTOPB */
-#ifdef CREAD
- {"cread", CREAD, MD_CTL},
-#endif /* CREAD */
-#ifdef PARENB
- {"parenb", PARENB, MD_CTL},
-#endif /* PARENB */
-#ifdef PARODD
- {"parodd", PARODD, MD_CTL},
-#endif /* PARODD */
-#ifdef HUPCL
- {"hupcl", HUPCL, MD_CTL},
-#endif /* HUPCL */
-#ifdef CLOCAL
- {"clocal", CLOCAL, MD_CTL},
-#endif /* CLOCAL */
-#ifdef LOBLK
- {"loblk", LOBLK, MD_CTL},
-#endif /* LOBLK */
-#ifdef CIBAUD
- {"cibaud", CIBAUD, MD_CTL},
-#endif /* CIBAUD */
-#ifdef CRTSCTS
-#ifdef CCTS_OFLOW
- {"ccts_oflow", CCTS_OFLOW, MD_CTL},
-#else
- {"crtscts", CRTSCTS, MD_CTL},
-#endif /* CCTS_OFLOW */
-#endif /* CRTSCTS */
-#ifdef CRTS_IFLOW
- {"crts_iflow", CRTS_IFLOW, MD_CTL},
-#endif /* CRTS_IFLOW */
-#ifdef CDTRCTS
- {"cdtrcts", CDTRCTS, MD_CTL},
-#endif /* CDTRCTS */
-#ifdef MDMBUF
- {"mdmbuf", MDMBUF, MD_CTL},
-#endif /* MDMBUF */
-#ifdef RCV1EN
- {"rcv1en", RCV1EN, MD_CTL},
-#endif /* RCV1EN */
-#ifdef XMT1EN
- {"xmt1en", XMT1EN, MD_CTL},
-#endif /* XMT1EN */
-
-#ifdef ISIG
- {"isig", ISIG, MD_LIN},
-#endif /* ISIG */
-#ifdef ICANON
- {"icanon", ICANON, MD_LIN},
-#endif /* ICANON */
-#ifdef XCASE
- {"xcase", XCASE, MD_LIN},
-#endif /* XCASE */
-#ifdef ECHO
- {"echo", ECHO, MD_LIN},
-#endif /* ECHO */
-#ifdef ECHOE
- {"echoe", ECHOE, MD_LIN},
-#endif /* ECHOE */
-#ifdef ECHOK
- {"echok", ECHOK, MD_LIN},
-#endif /* ECHOK */
-#ifdef ECHONL
- {"echonl", ECHONL, MD_LIN},
-#endif /* ECHONL */
-#ifdef NOFLSH
- {"noflsh", NOFLSH, MD_LIN},
-#endif /* NOFLSH */
-#ifdef TOSTOP
- {"tostop", TOSTOP, MD_LIN},
-#endif /* TOSTOP */
-#ifdef ECHOCTL
- {"echoctl", ECHOCTL, MD_LIN},
-#endif /* ECHOCTL */
-#ifdef ECHOPRT
- {"echoprt", ECHOPRT, MD_LIN},
-#endif /* ECHOPRT */
-#ifdef ECHOKE
- {"echoke", ECHOKE, MD_LIN},
-#endif /* ECHOKE */
-#ifdef DEFECHO
- {"defecho", DEFECHO, MD_LIN},
-#endif /* DEFECHO */
-#ifdef FLUSHO
- {"flusho", FLUSHO, MD_LIN},
-#endif /* FLUSHO */
-#ifdef PENDIN
- {"pendin", PENDIN, MD_LIN},
-#endif /* PENDIN */
-#ifdef IEXTEN
- {"iexten", IEXTEN, MD_LIN},
-#endif /* IEXTEN */
-#ifdef NOKERNINFO
- {"nokerninfo", NOKERNINFO, MD_LIN},
-#endif /* NOKERNINFO */
-#ifdef ALTWERASE
- {"altwerase", ALTWERASE, MD_LIN},
-#endif /* ALTWERASE */
-#ifdef EXTPROC
- {"extproc", EXTPROC, MD_LIN},
-#endif /* EXTPROC */
-
-#if defined(VINTR)
- {"intr", C_SH(C_INTR), MD_CHAR},
-#endif /* VINTR */
-#if defined(VQUIT)
- {"quit", C_SH(C_QUIT), MD_CHAR},
-#endif /* VQUIT */
-#if defined(VERASE)
- {"erase", C_SH(C_ERASE), MD_CHAR},
-#endif /* VERASE */
-#if defined(VKILL)
- {"kill", C_SH(C_KILL), MD_CHAR},
-#endif /* VKILL */
-#if defined(VEOF)
- {"eof", C_SH(C_EOF), MD_CHAR},
-#endif /* VEOF */
-#if defined(VEOL)
- {"eol", C_SH(C_EOL), MD_CHAR},
-#endif /* VEOL */
-#if defined(VEOL2)
- {"eol2", C_SH(C_EOL2), MD_CHAR},
-#endif /* VEOL2 */
-#if defined(VSWTCH)
- {"swtch", C_SH(C_SWTCH), MD_CHAR},
-#endif /* VSWTCH */
-#if defined(VDSWTCH)
- {"dswtch", C_SH(C_DSWTCH), MD_CHAR},
-#endif /* VDSWTCH */
-#if defined(VERASE2)
- {"erase2", C_SH(C_ERASE2), MD_CHAR},
-#endif /* VERASE2 */
-#if defined(VSTART)
- {"start", C_SH(C_START), MD_CHAR},
-#endif /* VSTART */
-#if defined(VSTOP)
- {"stop", C_SH(C_STOP), MD_CHAR},
-#endif /* VSTOP */
-#if defined(VWERASE)
- {"werase", C_SH(C_WERASE), MD_CHAR},
-#endif /* VWERASE */
-#if defined(VSUSP)
- {"susp", C_SH(C_SUSP), MD_CHAR},
-#endif /* VSUSP */
-#if defined(VDSUSP)
- {"dsusp", C_SH(C_DSUSP), MD_CHAR},
-#endif /* VDSUSP */
-#if defined(VREPRINT)
- {"reprint", C_SH(C_REPRINT), MD_CHAR},
-#endif /* VREPRINT */
-#if defined(VDISCARD)
- {"discard", C_SH(C_DISCARD), MD_CHAR},
-#endif /* VDISCARD */
-#if defined(VLNEXT)
- {"lnext", C_SH(C_LNEXT), MD_CHAR},
-#endif /* VLNEXT */
-#if defined(VSTATUS)
- {"status", C_SH(C_STATUS), MD_CHAR},
-#endif /* VSTATUS */
-#if defined(VPAGE)
- {"page", C_SH(C_PAGE), MD_CHAR},
-#endif /* VPAGE */
-#if defined(VPGOFF)
- {"pgoff", C_SH(C_PGOFF), MD_CHAR},
-#endif /* VPGOFF */
-#if defined(VKILL2)
- {"kill2", C_SH(C_KILL2), MD_CHAR},
-#endif /* VKILL2 */
-#if defined(VBRK)
- {"brk", C_SH(C_BRK), MD_CHAR},
-#endif /* VBRK */
-#if defined(VMIN)
- {"min", C_SH(C_MIN), MD_CHAR},
-#endif /* VMIN */
-#if defined(VTIME)
- {"time", C_SH(C_TIME), MD_CHAR},
-#endif /* VTIME */
- {NULL, 0, -1},
-};
-
-
-
-#define tty_getty(el, td) tcgetattr((el)->el_infd, (td))
-#define tty_setty(el, td) tcsetattr((el)->el_infd, TCSADRAIN, (td))
-
-#define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1)
-#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
-#define tty__cooked_mode(td) ((td)->c_lflag & ICANON)
-
-private void tty__getchar(struct termios *, unsigned char *);
-private void tty__setchar(struct termios *, unsigned char *);
-private speed_t tty__getspeed(struct termios *);
-private int tty_setup(EditLine *);
-
-#define t_qu t_ts
-
-
-/* tty_setup():
- * Get the tty parameters and initialize the editing state
- */
-private int
-tty_setup(EditLine *el)
-{
- int rst = 1;
-
- if (el->el_flags & EDIT_DISABLED)
- return (0);
-
- if (tty_getty(el, &el->el_tty.t_ed) == -1) {
-#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile,
- "tty_setup: tty_getty: %s\n", strerror(errno));
-#endif /* DEBUG_TTY */
- return (-1);
- }
- el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed;
-
- el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ex);
- el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex);
- el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ex);
-
- el->el_tty.t_ex.c_iflag &= ~el->el_tty.t_t[EX_IO][MD_INP].t_clrmask;
- el->el_tty.t_ex.c_iflag |= el->el_tty.t_t[EX_IO][MD_INP].t_setmask;
-
- el->el_tty.t_ex.c_oflag &= ~el->el_tty.t_t[EX_IO][MD_OUT].t_clrmask;
- el->el_tty.t_ex.c_oflag |= el->el_tty.t_t[EX_IO][MD_OUT].t_setmask;
-
- el->el_tty.t_ex.c_cflag &= ~el->el_tty.t_t[EX_IO][MD_CTL].t_clrmask;
- el->el_tty.t_ex.c_cflag |= el->el_tty.t_t[EX_IO][MD_CTL].t_setmask;
-
- el->el_tty.t_ex.c_lflag &= ~el->el_tty.t_t[EX_IO][MD_LIN].t_clrmask;
- el->el_tty.t_ex.c_lflag |= el->el_tty.t_t[EX_IO][MD_LIN].t_setmask;
-
- /*
- * Reset the tty chars to reasonable defaults
- * If they are disabled, then enable them.
- */
- if (rst) {
- if (tty__cooked_mode(&el->el_tty.t_ts)) {
- tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
- /*
- * Don't affect CMIN and CTIME for the editor mode
- */
- for (rst = 0; rst < C_NCC - 2; rst++)
- if (el->el_tty.t_c[TS_IO][rst] !=
- el->el_tty.t_vdisable
- && el->el_tty.t_c[ED_IO][rst] !=
- el->el_tty.t_vdisable)
- el->el_tty.t_c[ED_IO][rst] =
- el->el_tty.t_c[TS_IO][rst];
- for (rst = 0; rst < C_NCC; rst++)
- if (el->el_tty.t_c[TS_IO][rst] !=
- el->el_tty.t_vdisable)
- el->el_tty.t_c[EX_IO][rst] =
- el->el_tty.t_c[TS_IO][rst];
- }
- tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
- if (tty_setty(el, &el->el_tty.t_ex) == -1) {
-#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile,
- "tty_setup: tty_setty: %s\n",
- strerror(errno));
-#endif /* DEBUG_TTY */
- return (-1);
- }
- } else
- tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
-
- el->el_tty.t_ed.c_iflag &= ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask;
- el->el_tty.t_ed.c_iflag |= el->el_tty.t_t[ED_IO][MD_INP].t_setmask;
-
- el->el_tty.t_ed.c_oflag &= ~el->el_tty.t_t[ED_IO][MD_OUT].t_clrmask;
- el->el_tty.t_ed.c_oflag |= el->el_tty.t_t[ED_IO][MD_OUT].t_setmask;
-
- el->el_tty.t_ed.c_cflag &= ~el->el_tty.t_t[ED_IO][MD_CTL].t_clrmask;
- el->el_tty.t_ed.c_cflag |= el->el_tty.t_t[ED_IO][MD_CTL].t_setmask;
-
- el->el_tty.t_ed.c_lflag &= ~el->el_tty.t_t[ED_IO][MD_LIN].t_clrmask;
- el->el_tty.t_ed.c_lflag |= el->el_tty.t_t[ED_IO][MD_LIN].t_setmask;
-
- tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
- tty_bind_char(el, 1);
- return (0);
-}
-
-protected int
-tty_init(EditLine *el)
-{
-
- el->el_tty.t_mode = EX_IO;
- el->el_tty.t_vdisable = _POSIX_VDISABLE;
- (void) memcpy(el->el_tty.t_t, ttyperm, sizeof(ttyperm_t));
- (void) memcpy(el->el_tty.t_c, ttychar, sizeof(ttychar_t));
- return (tty_setup(el));
-}
-
-
-/* tty_end():
- * Restore the tty to its original settings
- */
-protected void
-/*ARGSUSED*/
-tty_end(EditLine *el)
-{
-
- /* XXX: Maybe reset to an initial state? */
-}
-
-
-/* tty__getspeed():
- * Get the tty speed
- */
-private speed_t
-tty__getspeed(struct termios *td)
-{
- speed_t spd;
-
- if ((spd = cfgetispeed(td)) == 0)
- spd = cfgetospeed(td);
- return (spd);
-}
-
-
-/* tty__getchar():
- * Get the tty characters
- */
-private void
-tty__getchar(struct termios *td, unsigned char *s)
-{
-
-#ifdef VINTR
- s[C_INTR] = td->c_cc[VINTR];
-#endif /* VINTR */
-#ifdef VQUIT
- s[C_QUIT] = td->c_cc[VQUIT];
-#endif /* VQUIT */
-#ifdef VERASE
- s[C_ERASE] = td->c_cc[VERASE];
-#endif /* VERASE */
-#ifdef VKILL
- s[C_KILL] = td->c_cc[VKILL];
-#endif /* VKILL */
-#ifdef VEOF
- s[C_EOF] = td->c_cc[VEOF];
-#endif /* VEOF */
-#ifdef VEOL
- s[C_EOL] = td->c_cc[VEOL];
-#endif /* VEOL */
-#ifdef VEOL2
- s[C_EOL2] = td->c_cc[VEOL2];
-#endif /* VEOL2 */
-#ifdef VSWTCH
- s[C_SWTCH] = td->c_cc[VSWTCH];
-#endif /* VSWTCH */
-#ifdef VDSWTCH
- s[C_DSWTCH] = td->c_cc[VDSWTCH];
-#endif /* VDSWTCH */
-#ifdef VERASE2
- s[C_ERASE2] = td->c_cc[VERASE2];
-#endif /* VERASE2 */
-#ifdef VSTART
- s[C_START] = td->c_cc[VSTART];
-#endif /* VSTART */
-#ifdef VSTOP
- s[C_STOP] = td->c_cc[VSTOP];
-#endif /* VSTOP */
-#ifdef VWERASE
- s[C_WERASE] = td->c_cc[VWERASE];
-#endif /* VWERASE */
-#ifdef VSUSP
- s[C_SUSP] = td->c_cc[VSUSP];
-#endif /* VSUSP */
-#ifdef VDSUSP
- s[C_DSUSP] = td->c_cc[VDSUSP];
-#endif /* VDSUSP */
-#ifdef VREPRINT
- s[C_REPRINT] = td->c_cc[VREPRINT];
-#endif /* VREPRINT */
-#ifdef VDISCARD
- s[C_DISCARD] = td->c_cc[VDISCARD];
-#endif /* VDISCARD */
-#ifdef VLNEXT
- s[C_LNEXT] = td->c_cc[VLNEXT];
-#endif /* VLNEXT */
-#ifdef VSTATUS
- s[C_STATUS] = td->c_cc[VSTATUS];
-#endif /* VSTATUS */
-#ifdef VPAGE
- s[C_PAGE] = td->c_cc[VPAGE];
-#endif /* VPAGE */
-#ifdef VPGOFF
- s[C_PGOFF] = td->c_cc[VPGOFF];
-#endif /* VPGOFF */
-#ifdef VKILL2
- s[C_KILL2] = td->c_cc[VKILL2];
-#endif /* KILL2 */
-#ifdef VMIN
- s[C_MIN] = td->c_cc[VMIN];
-#endif /* VMIN */
-#ifdef VTIME
- s[C_TIME] = td->c_cc[VTIME];
-#endif /* VTIME */
-} /* tty__getchar */
-
-
-/* tty__setchar():
- * Set the tty characters
- */
-private void
-tty__setchar(struct termios *td, unsigned char *s)
-{
-
-#ifdef VINTR
- td->c_cc[VINTR] = s[C_INTR];
-#endif /* VINTR */
-#ifdef VQUIT
- td->c_cc[VQUIT] = s[C_QUIT];
-#endif /* VQUIT */
-#ifdef VERASE
- td->c_cc[VERASE] = s[C_ERASE];
-#endif /* VERASE */
-#ifdef VKILL
- td->c_cc[VKILL] = s[C_KILL];
-#endif /* VKILL */
-#ifdef VEOF
- td->c_cc[VEOF] = s[C_EOF];
-#endif /* VEOF */
-#ifdef VEOL
- td->c_cc[VEOL] = s[C_EOL];
-#endif /* VEOL */
-#ifdef VEOL2
- td->c_cc[VEOL2] = s[C_EOL2];
-#endif /* VEOL2 */
-#ifdef VSWTCH
- td->c_cc[VSWTCH] = s[C_SWTCH];
-#endif /* VSWTCH */
-#ifdef VDSWTCH
- td->c_cc[VDSWTCH] = s[C_DSWTCH];
-#endif /* VDSWTCH */
-#ifdef VERASE2
- td->c_cc[VERASE2] = s[C_ERASE2];
-#endif /* VERASE2 */
-#ifdef VSTART
- td->c_cc[VSTART] = s[C_START];
-#endif /* VSTART */
-#ifdef VSTOP
- td->c_cc[VSTOP] = s[C_STOP];
-#endif /* VSTOP */
-#ifdef VWERASE
- td->c_cc[VWERASE] = s[C_WERASE];
-#endif /* VWERASE */
-#ifdef VSUSP
- td->c_cc[VSUSP] = s[C_SUSP];
-#endif /* VSUSP */
-#ifdef VDSUSP
- td->c_cc[VDSUSP] = s[C_DSUSP];
-#endif /* VDSUSP */
-#ifdef VREPRINT
- td->c_cc[VREPRINT] = s[C_REPRINT];
-#endif /* VREPRINT */
-#ifdef VDISCARD
- td->c_cc[VDISCARD] = s[C_DISCARD];
-#endif /* VDISCARD */
-#ifdef VLNEXT
- td->c_cc[VLNEXT] = s[C_LNEXT];
-#endif /* VLNEXT */
-#ifdef VSTATUS
- td->c_cc[VSTATUS] = s[C_STATUS];
-#endif /* VSTATUS */
-#ifdef VPAGE
- td->c_cc[VPAGE] = s[C_PAGE];
-#endif /* VPAGE */
-#ifdef VPGOFF
- td->c_cc[VPGOFF] = s[C_PGOFF];
-#endif /* VPGOFF */
-#ifdef VKILL2
- td->c_cc[VKILL2] = s[C_KILL2];
-#endif /* VKILL2 */
-#ifdef VMIN
- td->c_cc[VMIN] = s[C_MIN];
-#endif /* VMIN */
-#ifdef VTIME
- td->c_cc[VTIME] = s[C_TIME];
-#endif /* VTIME */
-} /* tty__setchar */
-
-
-/* tty_bind_char():
- * Rebind the editline functions
- */
-protected void
-tty_bind_char(EditLine *el, int force)
-{
-
- unsigned char *t_n = el->el_tty.t_c[ED_IO];
- unsigned char *t_o = el->el_tty.t_ed.c_cc;
- unsigned char new[2], old[2];
- const ttymap_t *tp;
- el_action_t *map, *alt;
- const el_action_t *dmap, *dalt;
- new[1] = old[1] = '\0';
-
- map = el->el_map.key;
- alt = el->el_map.alt;
- if (el->el_map.type == MAP_VI) {
- dmap = el->el_map.vii;
- dalt = el->el_map.vic;
- } else {
- dmap = el->el_map.emacs;
- dalt = NULL;
- }
-
- for (tp = tty_map; tp->nch != -1; tp++) {
- new[0] = t_n[tp->nch];
- old[0] = t_o[tp->och];
- if (new[0] == old[0] && !force)
- continue;
- /* Put the old default binding back, and set the new binding */
- key_clear(el, map, (char *)old);
- map[old[0]] = dmap[old[0]];
- key_clear(el, map, (char *)new);
- /* MAP_VI == 1, MAP_EMACS == 0... */
- map[new[0]] = tp->bind[el->el_map.type];
- if (dalt) {
- key_clear(el, alt, (char *)old);
- alt[old[0]] = dalt[old[0]];
- key_clear(el, alt, (char *)new);
- alt[new[0]] = tp->bind[el->el_map.type + 1];
- }
- }
-}
-
-
-/* tty_rawmode():
- * Set terminal into 1 character at a time mode.
- */
-protected int
-tty_rawmode(EditLine *el)
-{
-
- if (el->el_tty.t_mode == ED_IO || el->el_tty.t_mode == QU_IO)
- return (0);
-
- if (el->el_flags & EDIT_DISABLED)
- return (0);
-
- if (tty_getty(el, &el->el_tty.t_ts) == -1) {
-#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "tty_rawmode: tty_getty: %s\n",
- strerror(errno));
-#endif /* DEBUG_TTY */
- return (-1);
- }
- /*
- * We always keep up with the eight bit setting and the speed of the
- * tty. But only we only believe changes that are made to cooked mode!
- */
- el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ts);
- el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ts);
-
- if (tty__getspeed(&el->el_tty.t_ex) != el->el_tty.t_speed ||
- tty__getspeed(&el->el_tty.t_ed) != el->el_tty.t_speed) {
- (void) cfsetispeed(&el->el_tty.t_ex, el->el_tty.t_speed);
- (void) cfsetospeed(&el->el_tty.t_ex, el->el_tty.t_speed);
- (void) cfsetispeed(&el->el_tty.t_ed, el->el_tty.t_speed);
- (void) cfsetospeed(&el->el_tty.t_ed, el->el_tty.t_speed);
- }
- if (tty__cooked_mode(&el->el_tty.t_ts)) {
- if (el->el_tty.t_ts.c_cflag != el->el_tty.t_ex.c_cflag) {
- el->el_tty.t_ex.c_cflag =
- el->el_tty.t_ts.c_cflag;
- el->el_tty.t_ex.c_cflag &=
- ~el->el_tty.t_t[EX_IO][MD_CTL].t_clrmask;
- el->el_tty.t_ex.c_cflag |=
- el->el_tty.t_t[EX_IO][MD_CTL].t_setmask;
-
- el->el_tty.t_ed.c_cflag =
- el->el_tty.t_ts.c_cflag;
- el->el_tty.t_ed.c_cflag &=
- ~el->el_tty.t_t[ED_IO][MD_CTL].t_clrmask;
- el->el_tty.t_ed.c_cflag |=
- el->el_tty.t_t[ED_IO][MD_CTL].t_setmask;
- }
- if ((el->el_tty.t_ts.c_lflag != el->el_tty.t_ex.c_lflag) &&
- (el->el_tty.t_ts.c_lflag != el->el_tty.t_ed.c_lflag)) {
- el->el_tty.t_ex.c_lflag =
- el->el_tty.t_ts.c_lflag;
- el->el_tty.t_ex.c_lflag &=
- ~el->el_tty.t_t[EX_IO][MD_LIN].t_clrmask;
- el->el_tty.t_ex.c_lflag |=
- el->el_tty.t_t[EX_IO][MD_LIN].t_setmask;
-
- el->el_tty.t_ed.c_lflag =
- el->el_tty.t_ts.c_lflag;
- el->el_tty.t_ed.c_lflag &=
- ~el->el_tty.t_t[ED_IO][MD_LIN].t_clrmask;
- el->el_tty.t_ed.c_lflag |=
- el->el_tty.t_t[ED_IO][MD_LIN].t_setmask;
- }
- if ((el->el_tty.t_ts.c_iflag != el->el_tty.t_ex.c_iflag) &&
- (el->el_tty.t_ts.c_iflag != el->el_tty.t_ed.c_iflag)) {
- el->el_tty.t_ex.c_iflag =
- el->el_tty.t_ts.c_iflag;
- el->el_tty.t_ex.c_iflag &=
- ~el->el_tty.t_t[EX_IO][MD_INP].t_clrmask;
- el->el_tty.t_ex.c_iflag |=
- el->el_tty.t_t[EX_IO][MD_INP].t_setmask;
-
- el->el_tty.t_ed.c_iflag =
- el->el_tty.t_ts.c_iflag;
- el->el_tty.t_ed.c_iflag &=
- ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask;
- el->el_tty.t_ed.c_iflag |=
- el->el_tty.t_t[ED_IO][MD_INP].t_setmask;
- }
- if ((el->el_tty.t_ts.c_oflag != el->el_tty.t_ex.c_oflag) &&
- (el->el_tty.t_ts.c_oflag != el->el_tty.t_ed.c_oflag)) {
- el->el_tty.t_ex.c_oflag =
- el->el_tty.t_ts.c_oflag;
- el->el_tty.t_ex.c_oflag &=
- ~el->el_tty.t_t[EX_IO][MD_OUT].t_clrmask;
- el->el_tty.t_ex.c_oflag |=
- el->el_tty.t_t[EX_IO][MD_OUT].t_setmask;
-
- el->el_tty.t_ed.c_oflag =
- el->el_tty.t_ts.c_oflag;
- el->el_tty.t_ed.c_oflag &=
- ~el->el_tty.t_t[ED_IO][MD_OUT].t_clrmask;
- el->el_tty.t_ed.c_oflag |=
- el->el_tty.t_t[ED_IO][MD_OUT].t_setmask;
- }
- if (tty__gettabs(&el->el_tty.t_ex) == 0)
- el->el_tty.t_tabs = 0;
- else
- el->el_tty.t_tabs = EL_CAN_TAB ? 1 : 0;
-
- {
- int i;
-
- tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
- /*
- * Check if the user made any changes.
- * If he did, then propagate the changes to the
- * edit and execute data structures.
- */
- for (i = 0; i < C_NCC; i++)
- if (el->el_tty.t_c[TS_IO][i] !=
- el->el_tty.t_c[EX_IO][i])
- break;
-
- if (i != C_NCC) {
- /*
- * Propagate changes only to the unprotected
- * chars that have been modified just now.
- */
- for (i = 0; i < C_NCC; i++) {
- if (!((el->el_tty.t_t[ED_IO][MD_CHAR].t_setmask & C_SH(i)))
- && (el->el_tty.t_c[TS_IO][i] != el->el_tty.t_c[EX_IO][i]))
- el->el_tty.t_c[ED_IO][i] = el->el_tty.t_c[TS_IO][i];
- if (el->el_tty.t_t[ED_IO][MD_CHAR].t_clrmask & C_SH(i))
- el->el_tty.t_c[ED_IO][i] = el->el_tty.t_vdisable;
- }
- tty_bind_char(el, 0);
- tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
-
- for (i = 0; i < C_NCC; i++) {
- if (!((el->el_tty.t_t[EX_IO][MD_CHAR].t_setmask & C_SH(i)))
- && (el->el_tty.t_c[TS_IO][i] != el->el_tty.t_c[EX_IO][i]))
- el->el_tty.t_c[EX_IO][i] = el->el_tty.t_c[TS_IO][i];
- if (el->el_tty.t_t[EX_IO][MD_CHAR].t_clrmask & C_SH(i))
- el->el_tty.t_c[EX_IO][i] = el->el_tty.t_vdisable;
- }
- tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
- }
- }
- }
- if (tty_setty(el, &el->el_tty.t_ed) == -1) {
-#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
- strerror(errno));
-#endif /* DEBUG_TTY */
- return (-1);
- }
- el->el_tty.t_mode = ED_IO;
- return (0);
-}
-
-
-/* tty_cookedmode():
- * Set the tty back to normal mode
- */
-protected int
-tty_cookedmode(EditLine *el)
-{ /* set tty in normal setup */
-
- if (el->el_tty.t_mode == EX_IO)
- return (0);
-
- if (el->el_flags & EDIT_DISABLED)
- return (0);
-
- if (tty_setty(el, &el->el_tty.t_ex) == -1) {
-#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile,
- "tty_cookedmode: tty_setty: %s\n",
- strerror(errno));
-#endif /* DEBUG_TTY */
- return (-1);
- }
- el->el_tty.t_mode = EX_IO;
- return (0);
-}
-
-
-/* tty_quotemode():
- * Turn on quote mode
- */
-protected int
-tty_quotemode(EditLine *el)
-{
- if (el->el_tty.t_mode == QU_IO)
- return (0);
-
- el->el_tty.t_qu = el->el_tty.t_ed;
-
- el->el_tty.t_qu.c_iflag &= ~el->el_tty.t_t[QU_IO][MD_INP].t_clrmask;
- el->el_tty.t_qu.c_iflag |= el->el_tty.t_t[QU_IO][MD_INP].t_setmask;
-
- el->el_tty.t_qu.c_oflag &= ~el->el_tty.t_t[QU_IO][MD_OUT].t_clrmask;
- el->el_tty.t_qu.c_oflag |= el->el_tty.t_t[QU_IO][MD_OUT].t_setmask;
-
- el->el_tty.t_qu.c_cflag &= ~el->el_tty.t_t[QU_IO][MD_CTL].t_clrmask;
- el->el_tty.t_qu.c_cflag |= el->el_tty.t_t[QU_IO][MD_CTL].t_setmask;
-
- el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask;
- el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask;
-
- if (tty_setty(el, &el->el_tty.t_qu) == -1) {
-#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
- strerror(errno));
-#endif /* DEBUG_TTY */
- return (-1);
- }
- el->el_tty.t_mode = QU_IO;
- return (0);
-}
-
-
-/* tty_noquotemode():
- * Turn off quote mode
- */
-protected int
-tty_noquotemode(EditLine *el)
-{
-
- if (el->el_tty.t_mode != QU_IO)
- return (0);
- if (tty_setty(el, &el->el_tty.t_ed) == -1) {
-#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
- strerror(errno));
-#endif /* DEBUG_TTY */
- return (-1);
- }
- el->el_tty.t_mode = ED_IO;
- return (0);
-}
-
-
-/* tty_stty():
- * Stty builtin
- */
-protected int
-/*ARGSUSED*/
-tty_stty(EditLine *el, int argc, const char **argv)
-{
- const ttymodes_t *m;
- char x;
- int aflag = 0;
- const char *s, *d;
- const char *name;
- int z = EX_IO;
-
- if (argv == NULL)
- return (-1);
- name = *argv++;
-
- while (argv && *argv && argv[0][0] == '-' && argv[0][2] == '\0')
- switch (argv[0][1]) {
- case 'a':
- aflag++;
- argv++;
- break;
- case 'd':
- argv++;
- z = ED_IO;
- break;
- case 'x':
- argv++;
- z = EX_IO;
- break;
- case 'q':
- argv++;
- z = QU_IO;
- break;
- default:
- (void) fprintf(el->el_errfile,
- "%s: Unknown switch `%c'.\n",
- name, argv[0][1]);
- return (-1);
- }
-
- if (!argv || !*argv) {
- int i = -1;
- int len = 0, st = 0, cu;
- for (m = ttymodes; m->m_name; m++) {
- if (m->m_type != i) {
- (void) fprintf(el->el_outfile, "%s%s",
- i != -1 ? "\n" : "",
- el->el_tty.t_t[z][m->m_type].t_name);
- i = m->m_type;
- st = len =
- strlen(el->el_tty.t_t[z][m->m_type].t_name);
- }
- x = (el->el_tty.t_t[z][i].t_setmask & m->m_value)
- ? '+' : '\0';
- x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value)
- ? '-' : x;
-
- if (x != '\0' || aflag) {
-
- cu = strlen(m->m_name) + (x != '\0') + 1;
-
- if (len + cu >= el->el_term.t_size.h) {
- (void) fprintf(el->el_outfile, "\n%*s",
- st, "");
- len = st + cu;
- } else
- len += cu;
-
- if (x != '\0')
- (void) fprintf(el->el_outfile, "%c%s ",
- x, m->m_name);
- else
- (void) fprintf(el->el_outfile, "%s ",
- m->m_name);
- }
- }
- (void) fprintf(el->el_outfile, "\n");
- return (0);
- }
- while (argv && (s = *argv++)) {
- switch (*s) {
- case '+':
- case '-':
- x = *s++;
- break;
- default:
- x = '\0';
- break;
- }
- d = s;
- for (m = ttymodes; m->m_name; m++)
- if (strcmp(m->m_name, d) == 0)
- break;
-
- if (!m->m_name) {
- (void) fprintf(el->el_errfile,
- "%s: Invalid argument `%s'.\n", name, d);
- return (-1);
- }
- switch (x) {
- case '+':
- el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value;
- el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value;
- break;
- case '-':
- el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value;
- el->el_tty.t_t[z][m->m_type].t_clrmask |= m->m_value;
- break;
- default:
- el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value;
- el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value;
- break;
- }
- }
- return (0);
-}
-
-
-#ifdef notyet
-/* tty_printchar():
- * DEbugging routine to print the tty characters
- */
-private void
-tty_printchar(EditLine *el, unsigned char *s)
-{
- ttyperm_t *m;
- int i;
-
- for (i = 0; i < C_NCC; i++) {
- for (m = el->el_tty.t_t; m->m_name; m++)
- if (m->m_type == MD_CHAR && C_SH(i) == m->m_value)
- break;
- if (m->m_name)
- (void) fprintf(el->el_errfile, "%s ^%c ",
- m->m_name, s[i] + 'A' - 1);
- if (i % 5 == 0)
- (void) fprintf(el->el_errfile, "\n");
- }
- (void) fprintf(el->el_errfile, "\n");
-}
-#endif /* notyet */
diff --git a/1.2-netsec/editline/tty.h b/1.2-netsec/editline/tty.h
deleted file mode 100644
index e9597fceb..000000000
--- a/1.2-netsec/editline/tty.h
+++ /dev/null
@@ -1,484 +0,0 @@
-/* $NetBSD: tty.h,v 1.9 2002/03/18 16:01:01 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)tty.h 8.1 (Berkeley) 6/4/93
- */
-
-/*
- * el.tty.h: Local terminal header
- */
-#ifndef _h_el_tty
-#define _h_el_tty
-
-#include "histedit.h"
-#include <termios.h>
-#include <unistd.h>
-
-/* Define our own since everyone gets it wrong! */
-#define CONTROL(A) ((A) & 037)
-
-/*
- * Aix compatible names
- */
-# if defined(VWERSE) && !defined(VWERASE)
-# define VWERASE VWERSE
-# endif /* VWERSE && !VWERASE */
-
-# if defined(VDISCRD) && !defined(VDISCARD)
-# define VDISCARD VDISCRD
-# endif /* VDISCRD && !VDISCARD */
-
-# if defined(VFLUSHO) && !defined(VDISCARD)
-# define VDISCARD VFLUSHO
-# endif /* VFLUSHO && VDISCARD */
-
-# if defined(VSTRT) && !defined(VSTART)
-# define VSTART VSTRT
-# endif /* VSTRT && ! VSTART */
-
-# if defined(VSTAT) && !defined(VSTATUS)
-# define VSTATUS VSTAT
-# endif /* VSTAT && ! VSTATUS */
-
-# ifndef ONLRET
-# define ONLRET 0
-# endif /* ONLRET */
-
-# ifndef TAB3
-# ifdef OXTABS
-# define TAB3 OXTABS
-# else
-# define TAB3 0
-# endif /* OXTABS */
-# endif /* !TAB3 */
-
-# if defined(OXTABS) && !defined(XTABS)
-# define XTABS OXTABS
-# endif /* OXTABS && !XTABS */
-
-# ifndef ONLCR
-# define ONLCR 0
-# endif /* ONLCR */
-
-# ifndef IEXTEN
-# define IEXTEN 0
-# endif /* IEXTEN */
-
-# ifndef ECHOCTL
-# define ECHOCTL 0
-# endif /* ECHOCTL */
-
-# ifndef PARENB
-# define PARENB 0
-# endif /* PARENB */
-
-# ifndef EXTPROC
-# define EXTPROC 0
-# endif /* EXTPROC */
-
-# ifndef FLUSHO
-# define FLUSHO 0
-# endif /* FLUSHO */
-
-
-# if defined(VDISABLE) && !defined(_POSIX_VDISABLE)
-# define _POSIX_VDISABLE VDISABLE
-# endif /* VDISABLE && ! _POSIX_VDISABLE */
-
-/*
- * Work around ISC's definition of IEXTEN which is
- * XCASE!
- */
-# ifdef ISC
-# if defined(IEXTEN) && defined(XCASE)
-# if IEXTEN == XCASE
-# undef IEXTEN
-# define IEXTEN 0
-# endif /* IEXTEN == XCASE */
-# endif /* IEXTEN && XCASE */
-# if defined(IEXTEN) && !defined(XCASE)
-# define XCASE IEXTEN
-# undef IEXTEN
-# define IEXTEN 0
-# endif /* IEXTEN && !XCASE */
-# endif /* ISC */
-
-/*
- * Work around convex weirdness where turning off IEXTEN makes us
- * lose all postprocessing!
- */
-#if defined(convex) || defined(__convex__)
-# if defined(IEXTEN) && IEXTEN != 0
-# undef IEXTEN
-# define IEXTEN 0
-# endif /* IEXTEN != 0 */
-#endif /* convex || __convex__ */
-
-/*
- * So that we don't lose job control.
- */
-#ifdef __SVR4
-# undef CSWTCH
-#endif
-
-#ifndef _POSIX_VDISABLE
-# define _POSIX_VDISABLE ((unsigned char) -1)
-#endif /* _POSIX_VDISABLE */
-
-#if !defined(CREPRINT) && defined(CRPRNT)
-# define CREPRINT CRPRNT
-#endif /* !CREPRINT && CRPRNT */
-#if !defined(CDISCARD) && defined(CFLUSH)
-# define CDISCARD CFLUSH
-#endif /* !CDISCARD && CFLUSH */
-
-#ifndef CINTR
-# define CINTR CONTROL('c')
-#endif /* CINTR */
-#ifndef CQUIT
-# define CQUIT 034 /* ^\ */
-#endif /* CQUIT */
-#ifndef CERASE
-# define CERASE 0177 /* ^? */
-#endif /* CERASE */
-#ifndef CKILL
-# define CKILL CONTROL('u')
-#endif /* CKILL */
-#ifndef CEOF
-# define CEOF CONTROL('d')
-#endif /* CEOF */
-#ifndef CEOL
-# define CEOL _POSIX_VDISABLE
-#endif /* CEOL */
-#ifndef CEOL2
-# define CEOL2 _POSIX_VDISABLE
-#endif /* CEOL2 */
-#ifndef CSWTCH
-# define CSWTCH _POSIX_VDISABLE
-#endif /* CSWTCH */
-#ifndef CDSWTCH
-# define CDSWTCH _POSIX_VDISABLE
-#endif /* CDSWTCH */
-#ifndef CERASE2
-# define CERASE2 _POSIX_VDISABLE
-#endif /* CERASE2 */
-#ifndef CSTART
-# define CSTART CONTROL('q')
-#endif /* CSTART */
-#ifndef CSTOP
-# define CSTOP CONTROL('s')
-#endif /* CSTOP */
-#ifndef CSUSP
-# define CSUSP CONTROL('z')
-#endif /* CSUSP */
-#ifndef CDSUSP
-# define CDSUSP CONTROL('y')
-#endif /* CDSUSP */
-
-#ifdef hpux
-
-# ifndef CREPRINT
-# define CREPRINT _POSIX_VDISABLE
-# endif /* CREPRINT */
-# ifndef CDISCARD
-# define CDISCARD _POSIX_VDISABLE
-# endif /* CDISCARD */
-# ifndef CLNEXT
-# define CLNEXT _POSIX_VDISABLE
-# endif /* CLNEXT */
-# ifndef CWERASE
-# define CWERASE _POSIX_VDISABLE
-# endif /* CWERASE */
-
-#else /* !hpux */
-
-# ifndef CREPRINT
-# define CREPRINT CONTROL('r')
-# endif /* CREPRINT */
-# ifndef CDISCARD
-# define CDISCARD CONTROL('o')
-# endif /* CDISCARD */
-# ifndef CLNEXT
-# define CLNEXT CONTROL('v')
-# endif /* CLNEXT */
-# ifndef CWERASE
-# define CWERASE CONTROL('w')
-# endif /* CWERASE */
-
-#endif /* hpux */
-
-#ifndef CSTATUS
-# define CSTATUS CONTROL('t')
-#endif /* CSTATUS */
-#ifndef CPAGE
-# define CPAGE ' '
-#endif /* CPAGE */
-#ifndef CPGOFF
-# define CPGOFF CONTROL('m')
-#endif /* CPGOFF */
-#ifndef CKILL2
-# define CKILL2 _POSIX_VDISABLE
-#endif /* CKILL2 */
-#ifndef CBRK
-# ifndef masscomp
-# define CBRK 0377
-# else
-# define CBRK '\0'
-# endif /* masscomp */
-#endif /* CBRK */
-#ifndef CMIN
-# define CMIN CEOF
-#endif /* CMIN */
-#ifndef CTIME
-# define CTIME CEOL
-#endif /* CTIME */
-
-/*
- * Fix for sun inconsistency. On termio VSUSP and the rest of the
- * ttychars > NCC are defined. So we undefine them.
- */
-#if defined(TERMIO) || defined(POSIX)
-# if defined(POSIX) && defined(NCCS)
-# define NUMCC NCCS
-# else
-# ifdef NCC
-# define NUMCC NCC
-# endif /* NCC */
-# endif /* POSIX && NCCS */
-# ifdef NUMCC
-# ifdef VINTR
-# if NUMCC <= VINTR
-# undef VINTR
-# endif /* NUMCC <= VINTR */
-# endif /* VINTR */
-# ifdef VQUIT
-# if NUMCC <= VQUIT
-# undef VQUIT
-# endif /* NUMCC <= VQUIT */
-# endif /* VQUIT */
-# ifdef VERASE
-# if NUMCC <= VERASE
-# undef VERASE
-# endif /* NUMCC <= VERASE */
-# endif /* VERASE */
-# ifdef VKILL
-# if NUMCC <= VKILL
-# undef VKILL
-# endif /* NUMCC <= VKILL */
-# endif /* VKILL */
-# ifdef VEOF
-# if NUMCC <= VEOF
-# undef VEOF
-# endif /* NUMCC <= VEOF */
-# endif /* VEOF */
-# ifdef VEOL
-# if NUMCC <= VEOL
-# undef VEOL
-# endif /* NUMCC <= VEOL */
-# endif /* VEOL */
-# ifdef VEOL2
-# if NUMCC <= VEOL2
-# undef VEOL2
-# endif /* NUMCC <= VEOL2 */
-# endif /* VEOL2 */
-# ifdef VSWTCH
-# if NUMCC <= VSWTCH
-# undef VSWTCH
-# endif /* NUMCC <= VSWTCH */
-# endif /* VSWTCH */
-# ifdef VDSWTCH
-# if NUMCC <= VDSWTCH
-# undef VDSWTCH
-# endif /* NUMCC <= VDSWTCH */
-# endif /* VDSWTCH */
-# ifdef VERASE2
-# if NUMCC <= VERASE2
-# undef VERASE2
-# endif /* NUMCC <= VERASE2 */
-# endif /* VERASE2 */
-# ifdef VSTART
-# if NUMCC <= VSTART
-# undef VSTART
-# endif /* NUMCC <= VSTART */
-# endif /* VSTART */
-# ifdef VSTOP
-# if NUMCC <= VSTOP
-# undef VSTOP
-# endif /* NUMCC <= VSTOP */
-# endif /* VSTOP */
-# ifdef VWERASE
-# if NUMCC <= VWERASE
-# undef VWERASE
-# endif /* NUMCC <= VWERASE */
-# endif /* VWERASE */
-# ifdef VSUSP
-# if NUMCC <= VSUSP
-# undef VSUSP
-# endif /* NUMCC <= VSUSP */
-# endif /* VSUSP */
-# ifdef VDSUSP
-# if NUMCC <= VDSUSP
-# undef VDSUSP
-# endif /* NUMCC <= VDSUSP */
-# endif /* VDSUSP */
-# ifdef VREPRINT
-# if NUMCC <= VREPRINT
-# undef VREPRINT
-# endif /* NUMCC <= VREPRINT */
-# endif /* VREPRINT */
-# ifdef VDISCARD
-# if NUMCC <= VDISCARD
-# undef VDISCARD
-# endif /* NUMCC <= VDISCARD */
-# endif /* VDISCARD */
-# ifdef VLNEXT
-# if NUMCC <= VLNEXT
-# undef VLNEXT
-# endif /* NUMCC <= VLNEXT */
-# endif /* VLNEXT */
-# ifdef VSTATUS
-# if NUMCC <= VSTATUS
-# undef VSTATUS
-# endif /* NUMCC <= VSTATUS */
-# endif /* VSTATUS */
-# ifdef VPAGE
-# if NUMCC <= VPAGE
-# undef VPAGE
-# endif /* NUMCC <= VPAGE */
-# endif /* VPAGE */
-# ifdef VPGOFF
-# if NUMCC <= VPGOFF
-# undef VPGOFF
-# endif /* NUMCC <= VPGOFF */
-# endif /* VPGOFF */
-# ifdef VKILL2
-# if NUMCC <= VKILL2
-# undef VKILL2
-# endif /* NUMCC <= VKILL2 */
-# endif /* VKILL2 */
-# ifdef VBRK
-# if NUMCC <= VBRK
-# undef VBRK
-# endif /* NUMCC <= VBRK */
-# endif /* VBRK */
-# ifdef VMIN
-# if NUMCC <= VMIN
-# undef VMIN
-# endif /* NUMCC <= VMIN */
-# endif /* VMIN */
-# ifdef VTIME
-# if NUMCC <= VTIME
-# undef VTIME
-# endif /* NUMCC <= VTIME */
-# endif /* VTIME */
-# endif /* NUMCC */
-#endif /* !POSIX */
-
-#define C_INTR 0
-#define C_QUIT 1
-#define C_ERASE 2
-#define C_KILL 3
-#define C_EOF 4
-#define C_EOL 5
-#define C_EOL2 6
-#define C_SWTCH 7
-#define C_DSWTCH 8
-#define C_ERASE2 9
-#define C_START 10
-#define C_STOP 11
-#define C_WERASE 12
-#define C_SUSP 13
-#define C_DSUSP 14
-#define C_REPRINT 15
-#define C_DISCARD 16
-#define C_LNEXT 17
-#define C_STATUS 18
-#define C_PAGE 19
-#define C_PGOFF 20
-#define C_KILL2 21
-#define C_BRK 22
-#define C_MIN 23
-#define C_TIME 24
-#define C_NCC 25
-#define C_SH(A) (1 << (A))
-
-/*
- * Terminal dependend data structures
- */
-#define EX_IO 0 /* while we are executing */
-#define ED_IO 1 /* while we are editing */
-#define TS_IO 2 /* new mode from terminal */
-#define QU_IO 2 /* used only for quoted chars */
-#define NN_IO 3 /* The number of entries */
-
-#define MD_INP 0
-#define MD_OUT 1
-#define MD_CTL 2
-#define MD_LIN 3
-#define MD_CHAR 4
-#define MD_NN 5
-
-typedef struct {
- const char *t_name;
- u_int t_setmask;
- u_int t_clrmask;
-} ttyperm_t[NN_IO][MD_NN];
-
-typedef unsigned char ttychar_t[NN_IO][C_NCC];
-
-protected int tty_init(EditLine *);
-protected void tty_end(EditLine *);
-protected int tty_stty(EditLine *, int, const char **);
-protected int tty_rawmode(EditLine *);
-protected int tty_cookedmode(EditLine *);
-protected int tty_quotemode(EditLine *);
-protected int tty_noquotemode(EditLine *);
-protected void tty_bind_char(EditLine *, int);
-
-typedef struct {
- ttyperm_t t_t;
- ttychar_t t_c;
- struct termios t_ex, t_ed, t_ts;
- int t_tabs;
- int t_eight;
- speed_t t_speed;
- int t_mode;
- unsigned char t_vdisable;
-} el_tty_t;
-
-
-#endif /* _h_el_tty */
diff --git a/1.2-netsec/editline/vi.c b/1.2-netsec/editline/vi.c
deleted file mode 100644
index 5683c7de0..000000000
--- a/1.2-netsec/editline/vi.c
+++ /dev/null
@@ -1,941 +0,0 @@
-/* $NetBSD: vi.c,v 1.9 2002/03/18 16:01:01 christos Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#if !defined(lint) && !defined(SCCSID)
-#if 0
-static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: vi.c,v 1.9 2002/03/18 16:01:01 christos Exp $");
-#endif
-#endif /* not lint && not SCCSID */
-
-/*
- * vi.c: Vi mode commands.
- */
-#include "el.h"
-
-private el_action_t cv_action(EditLine *, int);
-private el_action_t cv_paste(EditLine *, int);
-
-/* cv_action():
- * Handle vi actions.
- */
-private el_action_t
-cv_action(EditLine *el, int c)
-{
- char *cp, *kp;
-
- if (el->el_chared.c_vcmd.action & DELETE) {
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_vcmd.pos = 0;
-
- el->el_chared.c_undo.isize = 0;
- el->el_chared.c_undo.dsize = 0;
- kp = el->el_chared.c_undo.buf;
- for (cp = el->el_line.buffer; cp < el->el_line.lastchar; cp++) {
- *kp++ = *cp;
- el->el_chared.c_undo.dsize++;
- }
-
- el->el_chared.c_undo.action = INSERT;
- el->el_chared.c_undo.ptr = el->el_line.buffer;
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
- if (c & INSERT)
- el->el_map.current = el->el_map.key;
-
- return (CC_REFRESH);
- }
- el->el_chared.c_vcmd.pos = el->el_line.cursor;
- el->el_chared.c_vcmd.action = c;
- return (CC_ARGHACK);
-
-#ifdef notdef
- /*
- * I don't think that this is needed. But we keep it for now
- */
- else
- if (el_chared.c_vcmd.action == NOP) {
- el->el_chared.c_vcmd.pos = el->el_line.cursor;
- el->el_chared.c_vcmd.action = c;
- return (CC_ARGHACK);
- } else {
- el->el_chared.c_vcmd.action = 0;
- el->el_chared.c_vcmd.pos = 0;
- return (CC_ERROR);
- }
-#endif
-}
-
-
-/* cv_paste():
- * Paste previous deletion before or after the cursor
- */
-private el_action_t
-cv_paste(EditLine *el, int c)
-{
- char *ptr;
- c_undo_t *un = &el->el_chared.c_undo;
-
-#ifdef DEBUG_PASTE
- (void) fprintf(el->el_errfile, "Paste: %x \"%s\" +%d -%d\n",
- un->action, un->buf, un->isize, un->dsize);
-#endif
- if (un->isize == 0)
- return (CC_ERROR);
-
- if (!c && el->el_line.cursor < el->el_line.lastchar)
- el->el_line.cursor++;
- ptr = el->el_line.cursor;
-
- c_insert(el, (int) un->isize);
- if (el->el_line.cursor + un->isize > el->el_line.lastchar)
- return (CC_ERROR);
- (void) memcpy(ptr, un->buf, un->isize);
- return (CC_REFRESH);
-}
-
-
-/* vi_paste_next():
- * Vi paste previous deletion to the right of the cursor
- * [p]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_paste_next(EditLine *el, int c)
-{
-
- return (cv_paste(el, 0));
-}
-
-
-/* vi_paste_prev():
- * Vi paste previous deletion to the left of the cursor
- * [P]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_paste_prev(EditLine *el, int c)
-{
-
- return (cv_paste(el, 1));
-}
-
-
-/* vi_prev_space_word():
- * Vi move to the previous space delimited word
- * [B]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_prev_space_word(EditLine *el, int c)
-{
-
- if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
-
- el->el_line.cursor = cv_prev_word(el, el->el_line.cursor,
- el->el_line.buffer,
- el->el_state.argument,
- cv__isword);
-
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* vi_prev_word():
- * Vi move to the previous word
- * [B]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_prev_word(EditLine *el, int c)
-{
-
- if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
-
- el->el_line.cursor = cv_prev_word(el, el->el_line.cursor,
- el->el_line.buffer,
- el->el_state.argument,
- ce__isword);
-
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* vi_next_space_word():
- * Vi move to the next space delimited word
- * [W]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_next_space_word(EditLine *el, int c)
-{
-
- if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
-
- el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
- el->el_line.lastchar,
- el->el_state.argument,
- cv__isword);
-
- if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* vi_next_word():
- * Vi move to the next word
- * [w]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_next_word(EditLine *el, int c)
-{
-
- if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
-
- el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
- el->el_line.lastchar,
- el->el_state.argument,
- ce__isword);
-
- if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* vi_change_case():
- * Vi change case of character under the cursor and advance one character
- * [~]
- */
-protected el_action_t
-vi_change_case(EditLine *el, int c)
-{
-
- if (el->el_line.cursor < el->el_line.lastchar) {
- c = *el->el_line.cursor;
- if (isupper(c))
- *el->el_line.cursor++ = tolower(c);
- else if (islower(c))
- *el->el_line.cursor++ = toupper(c);
- else
- el->el_line.cursor++;
- re_fastaddc(el);
- return (CC_NORM);
- }
- return (CC_ERROR);
-}
-
-
-/* vi_change_meta():
- * Vi change prefix command
- * [c]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_change_meta(EditLine *el, int c)
-{
-
- /*
- * Delete with insert == change: first we delete and then we leave in
- * insert mode.
- */
- return (cv_action(el, DELETE | INSERT));
-}
-
-
-/* vi_insert_at_bol():
- * Vi enter insert mode at the beginning of line
- * [I]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_insert_at_bol(EditLine *el, int c)
-{
-
- el->el_line.cursor = el->el_line.buffer;
- el->el_chared.c_vcmd.ins = el->el_line.cursor;
-
- el->el_chared.c_undo.ptr = el->el_line.cursor;
- el->el_chared.c_undo.action = DELETE;
-
- el->el_map.current = el->el_map.key;
- return (CC_CURSOR);
-}
-
-
-/* vi_replace_char():
- * Vi replace character under the cursor with the next character typed
- * [r]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_replace_char(EditLine *el, int c)
-{
-
- el->el_map.current = el->el_map.key;
- el->el_state.inputmode = MODE_REPLACE_1;
- el->el_chared.c_undo.action = CHANGE;
- el->el_chared.c_undo.ptr = el->el_line.cursor;
- el->el_chared.c_undo.isize = 0;
- el->el_chared.c_undo.dsize = 0;
- return (CC_NORM);
-}
-
-
-/* vi_replace_mode():
- * Vi enter replace mode
- * [R]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_replace_mode(EditLine *el, int c)
-{
-
- el->el_map.current = el->el_map.key;
- el->el_state.inputmode = MODE_REPLACE;
- el->el_chared.c_undo.action = CHANGE;
- el->el_chared.c_undo.ptr = el->el_line.cursor;
- el->el_chared.c_undo.isize = 0;
- el->el_chared.c_undo.dsize = 0;
- return (CC_NORM);
-}
-
-
-/* vi_substitute_char():
- * Vi replace character under the cursor and enter insert mode
- * [r]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_substitute_char(EditLine *el, int c)
-{
-
- c_delafter(el, el->el_state.argument);
- el->el_map.current = el->el_map.key;
- return (CC_REFRESH);
-}
-
-
-/* vi_substitute_line():
- * Vi substitute entire line
- * [S]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_substitute_line(EditLine *el, int c)
-{
-
- (void) em_kill_line(el, 0);
- el->el_map.current = el->el_map.key;
- return (CC_REFRESH);
-}
-
-
-/* vi_change_to_eol():
- * Vi change to end of line
- * [C]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_change_to_eol(EditLine *el, int c)
-{
-
- (void) ed_kill_line(el, 0);
- el->el_map.current = el->el_map.key;
- return (CC_REFRESH);
-}
-
-
-/* vi_insert():
- * Vi enter insert mode
- * [i]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_insert(EditLine *el, int c)
-{
-
- el->el_map.current = el->el_map.key;
-
- el->el_chared.c_vcmd.ins = el->el_line.cursor;
- el->el_chared.c_undo.ptr = el->el_line.cursor;
- el->el_chared.c_undo.action = DELETE;
-
- return (CC_NORM);
-}
-
-
-/* vi_add():
- * Vi enter insert mode after the cursor
- * [a]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_add(EditLine *el, int c)
-{
- int ret;
-
- el->el_map.current = el->el_map.key;
- if (el->el_line.cursor < el->el_line.lastchar) {
- el->el_line.cursor++;
- if (el->el_line.cursor > el->el_line.lastchar)
- el->el_line.cursor = el->el_line.lastchar;
- ret = CC_CURSOR;
- } else
- ret = CC_NORM;
-
- el->el_chared.c_vcmd.ins = el->el_line.cursor;
- el->el_chared.c_undo.ptr = el->el_line.cursor;
- el->el_chared.c_undo.action = DELETE;
-
- return (ret);
-}
-
-
-/* vi_add_at_eol():
- * Vi enter insert mode at end of line
- * [A]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_add_at_eol(EditLine *el, int c)
-{
-
- el->el_map.current = el->el_map.key;
- el->el_line.cursor = el->el_line.lastchar;
-
- /* Mark where insertion begins */
- el->el_chared.c_vcmd.ins = el->el_line.lastchar;
- el->el_chared.c_undo.ptr = el->el_line.lastchar;
- el->el_chared.c_undo.action = DELETE;
- return (CC_CURSOR);
-}
-
-
-/* vi_delete_meta():
- * Vi delete prefix command
- * [d]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_delete_meta(EditLine *el, int c)
-{
-
- return (cv_action(el, DELETE));
-}
-
-
-/* vi_end_word():
- * Vi move to the end of the current space delimited word
- * [E]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_end_word(EditLine *el, int c)
-{
-
- if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
-
- el->el_line.cursor = cv__endword(el->el_line.cursor,
- el->el_line.lastchar, el->el_state.argument);
-
- if (el->el_chared.c_vcmd.action & DELETE) {
- el->el_line.cursor++;
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* vi_to_end_word():
- * Vi move to the end of the current word
- * [e]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_to_end_word(EditLine *el, int c)
-{
-
- if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
-
- el->el_line.cursor = cv__endword(el->el_line.cursor,
- el->el_line.lastchar, el->el_state.argument);
-
- if (el->el_chared.c_vcmd.action & DELETE) {
- el->el_line.cursor++;
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* vi_undo():
- * Vi undo last change
- * [u]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_undo(EditLine *el, int c)
-{
- char *cp, *kp;
- char temp;
- int i, size;
- c_undo_t *un = &el->el_chared.c_undo;
-
-#ifdef DEBUG_UNDO
- (void) fprintf(el->el_errfile, "Undo: %x \"%s\" +%d -%d\n",
- un->action, un->buf, un->isize, un->dsize);
-#endif
- switch (un->action) {
- case DELETE:
- if (un->dsize == 0)
- return (CC_NORM);
-
- (void) memcpy(un->buf, un->ptr, un->dsize);
- for (cp = un->ptr; cp <= el->el_line.lastchar; cp++)
- *cp = cp[un->dsize];
-
- el->el_line.lastchar -= un->dsize;
- el->el_line.cursor = un->ptr;
-
- un->action = INSERT;
- un->isize = un->dsize;
- un->dsize = 0;
- break;
-
- case DELETE | INSERT:
- size = un->isize - un->dsize;
- if (size > 0)
- i = un->dsize;
- else
- i = un->isize;
- cp = un->ptr;
- kp = un->buf;
- while (i-- > 0) {
- temp = *kp;
- *kp++ = *cp;
- *cp++ = temp;
- }
- if (size > 0) {
- el->el_line.cursor = cp;
- c_insert(el, size);
- while (size-- > 0 && cp < el->el_line.lastchar) {
- temp = *kp;
- *kp++ = *cp;
- *cp++ = temp;
- }
- } else if (size < 0) {
- size = -size;
- for (; cp <= el->el_line.lastchar; cp++) {
- *kp++ = *cp;
- *cp = cp[size];
- }
- el->el_line.lastchar -= size;
- }
- el->el_line.cursor = un->ptr;
- i = un->dsize;
- un->dsize = un->isize;
- un->isize = i;
- break;
-
- case INSERT:
- if (un->isize == 0)
- return (CC_NORM);
-
- el->el_line.cursor = un->ptr;
- c_insert(el, (int) un->isize);
- (void) memcpy(un->ptr, un->buf, un->isize);
- un->action = DELETE;
- un->dsize = un->isize;
- un->isize = 0;
- break;
-
- case CHANGE:
- if (un->isize == 0)
- return (CC_NORM);
-
- el->el_line.cursor = un->ptr;
- size = (int) (el->el_line.cursor - el->el_line.lastchar);
- if (size < un->isize)
- size = un->isize;
- cp = un->ptr;
- kp = un->buf;
- for (i = 0; i < size; i++) {
- temp = *kp;
- *kp++ = *cp;
- *cp++ = temp;
- }
- un->dsize = 0;
- break;
-
- default:
- return (CC_ERROR);
- }
-
- return (CC_REFRESH);
-}
-
-
-/* vi_command_mode():
- * Vi enter command mode (use alternative key bindings)
- * [<ESC>]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_command_mode(EditLine *el, int c)
-{
- int size;
-
- /* [Esc] cancels pending action */
- el->el_chared.c_vcmd.ins = 0;
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_vcmd.pos = 0;
-
- el->el_state.doingarg = 0;
- size = el->el_chared.c_undo.ptr - el->el_line.cursor;
- if (size < 0)
- size = -size;
- if (el->el_chared.c_undo.action == (INSERT | DELETE) ||
- el->el_chared.c_undo.action == DELETE)
- el->el_chared.c_undo.dsize = size;
- else
- el->el_chared.c_undo.isize = size;
-
- el->el_state.inputmode = MODE_INSERT;
- el->el_map.current = el->el_map.alt;
-#ifdef VI_MOVE
- if (el->el_line.cursor > el->el_line.buffer)
- el->el_line.cursor--;
-#endif
- return (CC_CURSOR);
-}
-
-
-/* vi_zero():
- * Vi move to the beginning of line
- * [0]
- */
-protected el_action_t
-vi_zero(EditLine *el, int c)
-{
-
- if (el->el_state.doingarg) {
- if (el->el_state.argument > 1000000)
- return (CC_ERROR);
- el->el_state.argument =
- (el->el_state.argument * 10) + (c - '0');
- return (CC_ARGHACK);
- } else {
- el->el_line.cursor = el->el_line.buffer;
- if (el->el_chared.c_vcmd.action & DELETE) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
- }
-}
-
-
-/* vi_delete_prev_char():
- * Vi move to previous character (backspace)
- * [^H]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_delete_prev_char(EditLine *el, int c)
-{
-
- if (el->el_chared.c_vcmd.ins == 0)
- return (CC_ERROR);
-
- if (el->el_chared.c_vcmd.ins >
- el->el_line.cursor - el->el_state.argument)
- return (CC_ERROR);
-
- c_delbefore(el, el->el_state.argument);
- el->el_line.cursor -= el->el_state.argument;
-
- return (CC_REFRESH);
-}
-
-
-/* vi_list_or_eof():
- * Vi list choices for completion or indicate end of file if empty line
- * [^D]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_list_or_eof(EditLine *el, int c)
-{
-
-#ifdef notyet
- if (el->el_line.cursor == el->el_line.lastchar &&
- el->el_line.cursor == el->el_line.buffer) {
-#endif
- term_overwrite(el, STReof, 4); /* then do a EOF */
- term__flush();
- return (CC_EOF);
-#ifdef notyet
- } else {
- re_goto_bottom(el);
- *el->el_line.lastchar = '\0'; /* just in case */
- return (CC_LIST_CHOICES);
- }
-#endif
-}
-
-
-/* vi_kill_line_prev():
- * Vi cut from beginning of line to cursor
- * [^U]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_kill_line_prev(EditLine *el, int c)
-{
- char *kp, *cp;
-
- cp = el->el_line.buffer;
- kp = el->el_chared.c_kill.buf;
- while (cp < el->el_line.cursor)
- *kp++ = *cp++; /* copy it */
- el->el_chared.c_kill.last = kp;
- c_delbefore(el, el->el_line.cursor - el->el_line.buffer);
- el->el_line.cursor = el->el_line.buffer; /* zap! */
- return (CC_REFRESH);
-}
-
-
-/* vi_search_prev():
- * Vi search history previous
- * [?]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_search_prev(EditLine *el, int c)
-{
-
- return (cv_search(el, ED_SEARCH_PREV_HISTORY));
-}
-
-
-/* vi_search_next():
- * Vi search history next
- * [/]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_search_next(EditLine *el, int c)
-{
-
- return (cv_search(el, ED_SEARCH_NEXT_HISTORY));
-}
-
-
-/* vi_repeat_search_next():
- * Vi repeat current search in the same search direction
- * [n]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_repeat_search_next(EditLine *el, int c)
-{
-
- if (el->el_search.patlen == 0)
- return (CC_ERROR);
- else
- return (cv_repeat_srch(el, el->el_search.patdir));
-}
-
-
-/* vi_repeat_search_prev():
- * Vi repeat current search in the opposite search direction
- * [N]
- */
-/*ARGSUSED*/
-protected el_action_t
-vi_repeat_search_prev(EditLine *el, int c)
-{
-
- if (el->el_search.patlen == 0)
- return (CC_ERROR);
- else
- return (cv_repeat_srch(el,
- el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?
- ED_SEARCH_NEXT_HISTORY : ED_SEARCH_PREV_HISTORY));
-}
-
-
-/* vi_next_char():
- * Vi move to the character specified next
- * [f]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_next_char(EditLine *el, int c)
-{
- char ch;
-
- if (el_getc(el, &ch) != 1)
- return (ed_end_of_file(el, 0));
-
- el->el_search.chadir = CHAR_FWD;
- el->el_search.chacha = ch;
-
- return (cv_csearch_fwd(el, ch, el->el_state.argument, 0));
-
-}
-
-
-/* vi_prev_char():
- * Vi move to the character specified previous
- * [F]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_prev_char(EditLine *el, int c)
-{
- char ch;
-
- if (el_getc(el, &ch) != 1)
- return (ed_end_of_file(el, 0));
-
- el->el_search.chadir = CHAR_BACK;
- el->el_search.chacha = ch;
-
- return (cv_csearch_back(el, ch, el->el_state.argument, 0));
-}
-
-
-/* vi_to_next_char():
- * Vi move up to the character specified next
- * [t]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_to_next_char(EditLine *el, int c)
-{
- char ch;
-
- if (el_getc(el, &ch) != 1)
- return (ed_end_of_file(el, 0));
-
- return (cv_csearch_fwd(el, ch, el->el_state.argument, 1));
-
-}
-
-
-/* vi_to_prev_char():
- * Vi move up to the character specified previous
- * [T]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_to_prev_char(EditLine *el, int c)
-{
- char ch;
-
- if (el_getc(el, &ch) != 1)
- return (ed_end_of_file(el, 0));
-
- return (cv_csearch_back(el, ch, el->el_state.argument, 1));
-}
-
-
-/* vi_repeat_next_char():
- * Vi repeat current character search in the same search direction
- * [;]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_repeat_next_char(EditLine *el, int c)
-{
-
- if (el->el_search.chacha == 0)
- return (CC_ERROR);
-
- return (el->el_search.chadir == CHAR_FWD
- ? cv_csearch_fwd(el, el->el_search.chacha,
- el->el_state.argument, 0)
- : cv_csearch_back(el, el->el_search.chacha,
- el->el_state.argument, 0));
-}
-
-
-/* vi_repeat_prev_char():
- * Vi repeat current character search in the opposite search direction
- * [,]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_repeat_prev_char(EditLine *el, int c)
-{
-
- if (el->el_search.chacha == 0)
- return (CC_ERROR);
-
- return el->el_search.chadir == CHAR_BACK ?
- cv_csearch_fwd(el, el->el_search.chacha, el->el_state.argument, 0) :
- cv_csearch_back(el, el->el_search.chacha, el->el_state.argument, 0);
-}
diff --git a/1.2-netsec/enum.c b/1.2-netsec/enum.c
deleted file mode 100644
index 5e11ed906..000000000
--- a/1.2-netsec/enum.c
+++ /dev/null
@@ -1,666 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Funding provided by nic.at
- *
- * 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 ENUM Support for Asterisk
- *
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#if __APPLE_CC__ >= 1495
-#include <arpa/nameser_compat.h>
-#endif
-#include <resolv.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <regex.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/enum.h"
-#include "asterisk/dns.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/utils.h"
-
-#ifdef __APPLE__
-#undef T_NAPTR
-#define T_NAPTR 35
-#endif
-
-#ifdef __APPLE__
-#undef T_TXT
-#define T_TXT 16
-#endif
-
-/* The IETF Enum standard root, managed by the ITU */
-#define TOPLEV "e164.arpa."
-
-/* Linked list from config file */
-static struct enum_search {
- char toplev[512];
- struct enum_search *next;
-} *toplevs;
-
-static int enumver = 0;
-
-AST_MUTEX_DEFINE_STATIC(enumlock);
-
-struct naptr {
- unsigned short order;
- unsigned short pref;
-} __attribute__ ((__packed__));
-
-/*--- parse_ie: Parse NAPTR record information elements */
-static int parse_ie(char *data, int maxdatalen, char *src, int srclen)
-{
- int len, olen;
-
- len = olen = (int)src[0];
- src++;
- srclen--;
- if (len > srclen) {
- ast_log(LOG_WARNING, "Want %d, got %d\n", len, srclen);
- return -1;
- }
- if (len > maxdatalen)
- len = maxdatalen;
- memcpy(data, src, len);
- return olen + 1;
-}
-
-/*--- parse_naptr: Parse DNS NAPTR record used in ENUM ---*/
-static int parse_naptr(char *dst, int dstsize, char *tech, int techsize, char *answer, int len, char *naptrinput)
-{
-
- char tech_return[80];
- char *oanswer = answer;
- char flags[512] = "";
- char services[512] = "";
- char *p;
- char regexp[512] = "";
- char repl[512] = "";
- char temp[512] = "";
- char delim;
- char *delim2;
- char *pattern, *subst, *d;
- int res;
- int regexp_len, size, backref;
- int d_len = sizeof(temp) - 1;
- regex_t preg;
- regmatch_t pmatch[9];
-
- tech_return[0] = '\0';
-
- dst[0] = '\0';
-
- if (len < sizeof(struct naptr)) {
- ast_log(LOG_WARNING, "NAPTR record length too short\n");
- return -1;
- }
- answer += sizeof(struct naptr);
- len -= sizeof(struct naptr);
- if ((res = parse_ie(flags, sizeof(flags) - 1, answer, len)) < 0) {
- ast_log(LOG_WARNING, "Failed to get flags from NAPTR record\n");
- return -1;
- } else {
- answer += res;
- len -= res;
- }
- if ((res = parse_ie(services, sizeof(services) - 1, answer, len)) < 0) {
- ast_log(LOG_WARNING, "Failed to get services from NAPTR record\n");
- return -1;
- } else {
- answer += res;
- len -= res;
- }
- if ((res = parse_ie(regexp, sizeof(regexp) - 1, answer, len)) < 0) {
- ast_log(LOG_WARNING, "Failed to get regexp from NAPTR record\n");
- return -1;
- } else {
- answer += res;
- len -= res;
- }
-
- if ((res = dn_expand((unsigned char *)oanswer, (unsigned char *)answer + len, (unsigned char *)answer, repl, sizeof(repl) - 1)) < 0) {
- ast_log(LOG_WARNING, "Failed to expand hostname\n");
- return -1;
- }
-
- if (option_debug > 2) /* Advanced NAPTR debugging */
- ast_log(LOG_DEBUG, "NAPTR input='%s', flags='%s', services='%s', regexp='%s', repl='%s'\n",
- naptrinput, flags, services, regexp, repl);
-
- if (tolower(flags[0]) != 'u') {
- ast_log(LOG_WARNING, "NAPTR Flag must be 'U' or 'u'.\n");
- return -1;
- }
-
- p = strstr(services, "e2u+");
- if (p == NULL)
- p = strstr(services, "E2U+");
- if (p){
- p = p + 4;
- if (strchr(p, ':')){
- p = strchr(p, ':') + 1;
- }
- ast_copy_string(tech_return, p, sizeof(tech_return));
- } else {
-
- p = strstr(services, "+e2u");
- if (p == NULL)
- p = strstr(services, "+E2U");
- if (p) {
- *p = 0;
- p = strchr(services, ':');
- if (p)
- *p = 0;
- ast_copy_string(tech_return, services, sizeof(tech_return));
- }
- }
-
- /* DEDBUGGING STUB
- ast_copy_string(regexp, "!^\\+43(.*)$!\\1@bla.fasel!", sizeof(regexp) - 1);
- */
-
- regexp_len = strlen(regexp);
- if (regexp_len < 7) {
- ast_log(LOG_WARNING, "Regex too short to be meaningful.\n");
- return -1;
- }
-
-
- delim = regexp[0];
- delim2 = strchr(regexp + 1, delim);
- if ((delim2 == NULL) || (regexp[regexp_len-1] != delim)) {
- ast_log(LOG_WARNING, "Regex delimiter error (on \"%s\").\n",regexp);
- return -1;
- }
-
- pattern = regexp + 1;
- *delim2 = 0;
- subst = delim2 + 1;
- regexp[regexp_len-1] = 0;
-
-#if 0
- printf("Pattern: %s\n", pattern);
- printf("Subst: %s\n", subst);
- printf("Input: %s\n", naptrinput);
-#endif
-
-/*
- * now do the regex wizardry.
- */
-
- if (regcomp(&preg, pattern, REG_EXTENDED | REG_NEWLINE)) {
- ast_log(LOG_WARNING, "NAPTR Regex compilation error (regex = \"%s\").\n",regexp);
- return -1;
- }
-
- if (preg.re_nsub > 9) {
- ast_log(LOG_WARNING, "NAPTR Regex compilation error: too many subs.\n");
- regfree(&preg);
- return -1;
- }
-
- if (regexec(&preg, naptrinput, 9, pmatch, 0)) {
- ast_log(LOG_WARNING, "NAPTR Regex match failed.\n");
- regfree(&preg);
- return -1;
- }
- regfree(&preg);
-
- d = temp;
- d_len--;
- while (*subst && (d_len > 0)) {
- if ((subst[0] == '\\') && isdigit(subst[1]) && (pmatch[subst[1]-'0'].rm_so != -1)) {
- backref = subst[1]-'0';
- size = pmatch[backref].rm_eo - pmatch[backref].rm_so;
- if (size > d_len) {
- ast_log(LOG_WARNING, "Not enough space during NAPTR regex substitution.\n");
- return -1;
- }
- memcpy(d, naptrinput + pmatch[backref].rm_so, size);
- d += size;
- d_len -= size;
- subst += 2;
- } else if (isprint(*subst)) {
- *d++ = *subst++;
- d_len--;
- } else {
- ast_log(LOG_WARNING, "Error during regex substitution.\n");
- return -1;
- }
- }
- *d = 0;
- ast_copy_string(dst, temp, dstsize);
- dst[dstsize - 1] = '\0';
-
- if (*tech != '\0'){ /* check if it is requested NAPTR */
- if (!strncasecmp(tech, "ALL", techsize)){
- return 1; /* return or count any RR */
- }
- if (!strncasecmp(tech_return, tech, sizeof(tech_return)<techsize?sizeof(tech_return):techsize)){
- ast_copy_string(tech, tech_return, techsize);
- return 1; /* we got out RR */
- } else { /* go to the next RR in the DNS answer */
- return 0;
- }
- }
-
- /* tech was not specified, return first parsed RR */
- ast_copy_string(tech, tech_return, techsize);
-
- return 1;
-}
-
-/* do not return requested value, just count RRs and return thei number in dst */
-#define ENUMLOOKUP_OPTIONS_COUNT 1
-
-struct enum_naptr_rr {
- struct naptr naptr; /* order and preference of RR */
- char *result; /* result of naptr parsing,e.g.: tel:+5553 */
- char *tech; /* Technology (from URL scheme) */
- int sort_pos; /* sort position */
-};
-
-struct enum_context {
- char *dst; /* Destination part of URL from ENUM */
- int dstlen; /* Length */
- char *tech; /* Technology (from URL scheme) */
- int techlen; /* Length */
- char *txt; /* TXT record in TXT lookup */
- int txtlen; /* Length */
- char *naptrinput; /* The number to lookup */
- int position; /* used as counter for RRs or specifies position of required RR */
- int options; /* options , see ENUMLOOKUP_OPTIONS_* defined above */
- struct enum_naptr_rr *naptr_rrs; /* array of parsed NAPTR RRs */
- int naptr_rrs_count; /* Size of array naptr_rrs */
-};
-
-/*--- txt_callback: Callback for TXT record lookup */
-static int txt_callback(void *context, char *answer, int len, char *fullanswer)
-{
- struct enum_context *c = (struct enum_context *)context;
-#if 0
- printf("ENUMTXT Called\n");
-#endif
-
- if (answer == NULL) {
- c->txt = NULL;
- c->txtlen = 0;
- return 0;
- }
-
- /* skip over first byte, as for some reason it's a vertical tab character */
- answer += 1;
- len -= 1;
-
- /* answer is not null-terminated, but should be */
- /* this is safe to do, as answer has extra bytes on the end we can
- safely overwrite with a null */
- answer[len] = '\0';
- /* now increment len so that len includes the null, so that we can
- compare apples to apples */
- len +=1;
-
- /* finally, copy the answer into c->txt */
- ast_copy_string(c->txt, answer, len < c->txtlen ? len : (c->txtlen));
-
- /* just to be safe, let's make sure c->txt is null terminated */
- c->txt[(c->txtlen)-1] = '\0';
-
- return 1;
-}
-
-/*--- enum_callback: Callback from ENUM lookup function */
-static int enum_callback(void *context, char *answer, int len, char *fullanswer)
-{
- struct enum_context *c = (struct enum_context *)context;
- void *p = NULL;
- int res;
-
- res = parse_naptr(c->dst, c->dstlen, c->tech, c->techlen, answer, len, c->naptrinput);
-
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to parse naptr :(\n");
- return -1;
- } else if (res > 0 && !ast_strlen_zero(c->dst)){ /* ok, we got needed NAPTR */
- if (c->options & ENUMLOOKUP_OPTIONS_COUNT){ /* counting RRs */
- c->position++;
- snprintf(c->dst, c->dstlen, "%d", c->position);
- } else {
- p = realloc(c->naptr_rrs, sizeof(struct enum_naptr_rr)*(c->naptr_rrs_count+1));
- if (p) {
- c->naptr_rrs = (struct enum_naptr_rr*)p;
- memcpy(&c->naptr_rrs[c->naptr_rrs_count].naptr, answer, sizeof(struct naptr));
- /* printf("order=%d, pref=%d\n", ntohs(c->naptr_rrs[c->naptr_rrs_count].naptr.order), ntohs(c->naptr_rrs[c->naptr_rrs_count].naptr.pref)); */
- c->naptr_rrs[c->naptr_rrs_count].result = strdup(c->dst);
- c->naptr_rrs[c->naptr_rrs_count].tech = strdup(c->tech);
- c->naptr_rrs[c->naptr_rrs_count].sort_pos = c->naptr_rrs_count;
- c->naptr_rrs_count++;
- }
- c->dst[0] = 0;
- }
- return 0;
- }
-
- if (c->options & ENUMLOOKUP_OPTIONS_COUNT) { /* counting RRs */
- snprintf(c->dst, c->dstlen, "%d", c->position);
- }
-
- return 0;
-}
-
-/*--- ast_get_enum: ENUM lookup */
-int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int dstlen, char *tech, int techlen, char* suffix, char* options)
-{
- struct enum_context context;
- char tmp[259 + 512];
- char naptrinput[512];
- int pos = strlen(number) - 1;
- int newpos = 0;
- int ret = -1;
- struct enum_search *s = NULL;
- int version = -1;
- /* for ISN rewrite */
- char *p1 = NULL;
- char *p2 = NULL;
- int k = 0;
- int i = 0;
- int z = 0;
-
- if (number[0] == 'n') {
- strncpy(naptrinput, number+1, sizeof(naptrinput));
- } else {
- strncpy(naptrinput, number, sizeof(naptrinput));
- }
-
- context.naptrinput = naptrinput; /* The number */
- context.dst = dst; /* Return string */
- context.dstlen = dstlen;
- context.tech = tech;
- context.techlen = techlen;
- context.options = 0;
- context.position = 1;
- context.naptr_rrs = NULL;
- context.naptr_rrs_count = 0;
-
- if (options != NULL){
- if (*options == 'c'){
- context.options = ENUMLOOKUP_OPTIONS_COUNT;
- context.position = 0;
- } else {
- context.position = atoi(options);
- if (context.position < 1)
- context.position = 1;
- }
- }
-
- if (pos > 128)
- pos = 128;
-
- /* ISN rewrite */
- p1 = strchr(number, '*');
-
- if (number[0] == 'n') { /* do not perform ISN rewrite ('n' is testing flag) */
- p1 = NULL;
- k = 1; /* strip 'n' from number */
- }
-
- if (p1 != NULL) {
- p2 = p1+1;
- while (p1 > number){
- p1--;
- tmp[newpos++] = *p1;
- tmp[newpos++] = '.';
- }
- if (*p2) {
- while(*p2 && newpos < 128){
- tmp[newpos++] = *p2;
- p2++;
- }
- tmp[newpos++] = '.';
- }
-
- } else {
- while (pos >= k) {
- if (isdigit(number[pos])) {
- tmp[newpos++] = number[pos];
- tmp[newpos++] = '.';
- }
- pos--;
- }
- }
-
- if (chan && ast_autoservice_start(chan) < 0)
- return -1;
-
- for (;;) {
- ast_mutex_lock(&enumlock);
- if (version != enumver) {
- /* Ooh, a reload... */
- s = toplevs;
- version = enumver;
- } else {
- s = s->next;
- }
- if (suffix != NULL) {
- strncpy(tmp + newpos, suffix, sizeof(tmp) - newpos - 1);
- } else if (s) {
- strncpy(tmp + newpos, s->toplev, sizeof(tmp) - newpos - 1);
- }
- ast_mutex_unlock(&enumlock);
- if (!s)
- break;
- ret = ast_search_dns(&context, tmp, C_IN, T_NAPTR, enum_callback);
- if (ret > 0)
- break;
- if (suffix != NULL)
- break;
- }
- if (ret < 0) {
- ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno));
- ret = 0;
- }
-
- if (context.naptr_rrs_count >= context.position && ! (context.options & ENUMLOOKUP_OPTIONS_COUNT)) {
- /* sort array by NAPTR order/preference */
- for (k=0; k<context.naptr_rrs_count; k++) {
- for (i=0; i<context.naptr_rrs_count; i++) {
- /* use order first and then preference to compare */
- if ((ntohs(context.naptr_rrs[k].naptr.order) < ntohs(context.naptr_rrs[i].naptr.order)
- && context.naptr_rrs[k].sort_pos > context.naptr_rrs[i].sort_pos)
- || (ntohs(context.naptr_rrs[k].naptr.order) > ntohs(context.naptr_rrs[i].naptr.order)
- && context.naptr_rrs[k].sort_pos < context.naptr_rrs[i].sort_pos)){
- z = context.naptr_rrs[k].sort_pos;
- context.naptr_rrs[k].sort_pos = context.naptr_rrs[i].sort_pos;
- context.naptr_rrs[i].sort_pos = z;
- continue;
- }
- if (ntohs(context.naptr_rrs[k].naptr.order) == ntohs(context.naptr_rrs[i].naptr.order)) {
- if ((ntohs(context.naptr_rrs[k].naptr.pref) < ntohs(context.naptr_rrs[i].naptr.pref)
- && context.naptr_rrs[k].sort_pos > context.naptr_rrs[i].sort_pos)
- || (ntohs(context.naptr_rrs[k].naptr.pref) > ntohs(context.naptr_rrs[i].naptr.pref)
- && context.naptr_rrs[k].sort_pos < context.naptr_rrs[i].sort_pos)){
- z = context.naptr_rrs[k].sort_pos;
- context.naptr_rrs[k].sort_pos = context.naptr_rrs[i].sort_pos;
- context.naptr_rrs[i].sort_pos = z;
- }
- }
- }
- }
- for (k=0; k<context.naptr_rrs_count; k++) {
- if (context.naptr_rrs[k].sort_pos == context.position-1) {
- ast_copy_string(context.dst, context.naptr_rrs[k].result, dstlen);
- ast_copy_string(context.tech, context.naptr_rrs[k].tech, techlen);
- break;
- }
- }
- } else if (!(context.options & ENUMLOOKUP_OPTIONS_COUNT)) {
- context.dst[0] = 0;
- }
-
- if (chan)
- ret |= ast_autoservice_stop(chan);
-
- for (k=0; k<context.naptr_rrs_count; k++) {
- free(context.naptr_rrs[k].result);
- free(context.naptr_rrs[k].tech);
- }
-
- free(context.naptr_rrs);
-
- return ret;
-}
-
-/*--- ast_get_txt: Get TXT record from DNS.
- Really has nothing to do with enum, but anyway...
- */
-int ast_get_txt(struct ast_channel *chan, const char *number, char *dst, int dstlen, char *tech, int techlen, char *txt, int txtlen)
-{
- struct enum_context context;
- char tmp[259 + 512];
- char naptrinput[512] = "+";
- int pos = strlen(number) - 1;
- int newpos = 0;
- int ret = -1;
- struct enum_search *s = NULL;
- int version = -1;
-
- strncat(naptrinput, number, sizeof(naptrinput) - 2);
-
- context.naptrinput = naptrinput;
- context.dst = dst;
- context.dstlen = dstlen;
- context.tech = tech;
- context.techlen = techlen;
- context.txt = txt;
- context.txtlen = txtlen;
-
- if (pos > 128)
- pos = 128;
- while (pos >= 0) {
- tmp[newpos++] = number[pos--];
- tmp[newpos++] = '.';
- }
-
- if (chan && ast_autoservice_start(chan) < 0)
- return -1;
-
- for (;;) {
- ast_mutex_lock(&enumlock);
- if (version != enumver) {
- /* Ooh, a reload... */
- s = toplevs;
- version = enumver;
- } else {
- s = s->next;
- }
- if (s) {
- strncpy(tmp + newpos, s->toplev, sizeof(tmp) - newpos - 1);
- }
- ast_mutex_unlock(&enumlock);
- if (!s)
- break;
-
- ret = ast_search_dns(&context, tmp, C_IN, T_TXT, txt_callback);
- if (ret > 0)
- break;
- }
- if (ret < 0) {
- ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno));
- ret = 0;
- }
- if (chan)
- ret |= ast_autoservice_stop(chan);
- return ret;
-}
-
-/*--- enum_newtoplev: Add enum tree to linked list ---*/
-static struct enum_search *enum_newtoplev(char *s)
-{
- struct enum_search *tmp;
-
- tmp = malloc(sizeof(struct enum_search));
- if (tmp) {
- memset(tmp, 0, sizeof(struct enum_search));
- ast_copy_string(tmp->toplev, s, sizeof(tmp->toplev));
- }
- return tmp;
-}
-
-/*--- ast_enum_init: Initialize the ENUM support subsystem */
-int ast_enum_init(void)
-{
- struct ast_config *cfg;
- struct enum_search *s, *sl;
- struct ast_variable *v;
-
- /* Destroy existing list */
- ast_mutex_lock(&enumlock);
- s = toplevs;
- while(s) {
- sl = s;
- s = s->next;
- free(sl);
- }
- toplevs = NULL;
- cfg = ast_config_load("enum.conf");
- if (cfg) {
- sl = NULL;
- v = ast_variable_browse(cfg, "general");
- while(v) {
- if (!strcasecmp(v->name, "search")) {
- s = enum_newtoplev(v->value);
- if (s) {
- if (sl)
- sl->next = s;
- else
- toplevs = s;
- sl = s;
- }
- }
- v = v->next;
- }
- ast_config_destroy(cfg);
- } else {
- toplevs = enum_newtoplev(TOPLEV);
- }
- enumver++;
- ast_mutex_unlock(&enumlock);
- return 0;
-}
-
-int ast_enum_reload(void)
-{
- return ast_enum_init();
-}
diff --git a/1.2-netsec/file.c b/1.2-netsec/file.c
deleted file mode 100644
index 76bf9a12a..000000000
--- a/1.2-netsec/file.c
+++ /dev/null
@@ -1,1287 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Generic File Format Support.
- *
- */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/frame.h"
-#include "asterisk/file.h"
-#include "asterisk/cli.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/sched.h"
-#include "asterisk/options.h"
-#include "asterisk/translate.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-#include "asterisk/app.h"
-#include "asterisk/pbx.h"
-
-struct ast_format {
- /* Name of format */
- char name[80];
- /* Extensions (separated by | if more than one)
- this format can read. First is assumed for writing (e.g. .mp3) */
- char exts[80];
- /* Format of frames it uses/provides (one only) */
- int format;
- /* Open an input stream, and start playback */
- struct ast_filestream * (*open)(FILE * f);
- /* Open an output stream, of a given file descriptor and comment it appropriately if applicable */
- struct ast_filestream * (*rewrite)(FILE *f, const char *comment);
- /* Write a frame to a channel */
- int (*write)(struct ast_filestream *, struct ast_frame *);
- /* seek num samples into file, whence(think normal seek) */
- int (*seek)(struct ast_filestream *, long offset, int whence);
- /* trunc file to current position */
- int (*trunc)(struct ast_filestream *fs);
- /* tell current position */
- long (*tell)(struct ast_filestream *fs);
- /* Read the next frame from the filestream (if available) and report when to get next one
- (in samples) */
- struct ast_frame * (*read)(struct ast_filestream *, int *whennext);
- /* Close file, and destroy filestream structure */
- void (*close)(struct ast_filestream *);
- /* Retrieve file comment */
- char * (*getcomment)(struct ast_filestream *);
- /* Link */
- struct ast_format *next;
-};
-
-struct ast_filestream {
- /* Everybody reserves a block of AST_RESERVED_POINTERS pointers for us */
- struct ast_format *fmt;
- int flags;
- mode_t mode;
- char *filename;
- char *realfilename;
- /* Video file stream */
- struct ast_filestream *vfs;
- /* Transparently translate from another format -- just once */
- struct ast_trans_pvt *trans;
- struct ast_tranlator_pvt *tr;
- int lastwriteformat;
- int lasttimeout;
- struct ast_channel *owner;
-};
-
-AST_MUTEX_DEFINE_STATIC(formatlock);
-
-static struct ast_format *formats = NULL;
-
-int ast_format_register(const char *name, const char *exts, int format,
- struct ast_filestream * (*open)(FILE *f),
- struct ast_filestream * (*rewrite)(FILE *f, const char *comment),
- int (*write)(struct ast_filestream *, struct ast_frame *),
- int (*seek)(struct ast_filestream *, long sample_offset, int whence),
- int (*trunc)(struct ast_filestream *),
- long (*tell)(struct ast_filestream *),
- struct ast_frame * (*read)(struct ast_filestream *, int *whennext),
- void (*close)(struct ast_filestream *),
- char * (*getcomment)(struct ast_filestream *))
-{
- struct ast_format *tmp;
- if (ast_mutex_lock(&formatlock)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return -1;
- }
- tmp = formats;
- while(tmp) {
- if (!strcasecmp(name, tmp->name)) {
- ast_mutex_unlock(&formatlock);
- ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", name);
- return -1;
- }
- tmp = tmp->next;
- }
- tmp = malloc(sizeof(struct ast_format));
- if (!tmp) {
- ast_log(LOG_WARNING, "Out of memory\n");
- ast_mutex_unlock(&formatlock);
- return -1;
- }
- ast_copy_string(tmp->name, name, sizeof(tmp->name));
- ast_copy_string(tmp->exts, exts, sizeof(tmp->exts));
- tmp->open = open;
- tmp->rewrite = rewrite;
- tmp->read = read;
- tmp->write = write;
- tmp->seek = seek;
- tmp->trunc = trunc;
- tmp->tell = tell;
- tmp->close = close;
- tmp->format = format;
- tmp->getcomment = getcomment;
- tmp->next = formats;
- formats = tmp;
- ast_mutex_unlock(&formatlock);
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Registered file format %s, extension(s) %s\n", name, exts);
- return 0;
-}
-
-int ast_format_unregister(const char *name)
-{
- struct ast_format *tmp, *tmpl = NULL;
- if (ast_mutex_lock(&formatlock)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return -1;
- }
- tmp = formats;
- while(tmp) {
- if (!strcasecmp(name, tmp->name)) {
- if (tmpl)
- tmpl->next = tmp->next;
- else
- formats = tmp->next;
- free(tmp);
- ast_mutex_unlock(&formatlock);
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Unregistered format %s\n", name);
- return 0;
- }
- tmpl = tmp;
- tmp = tmp->next;
- }
- ast_mutex_unlock(&formatlock);
- ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name);
- return -1;
-}
-
-int ast_stopstream(struct ast_channel *tmp)
-{
- /* Stop a running stream if there is one */
- if (tmp->vstream)
- ast_closestream(tmp->vstream);
- if (tmp->stream) {
- ast_closestream(tmp->stream);
- if (tmp->oldwriteformat && ast_set_write_format(tmp, tmp->oldwriteformat))
- ast_log(LOG_WARNING, "Unable to restore format back to %d\n", tmp->oldwriteformat);
- }
- return 0;
-}
-
-int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
-{
- struct ast_frame *trf;
- int res = -1;
- int alt=0;
- if (f->frametype == AST_FRAME_VIDEO) {
- if (fs->fmt->format < AST_FORMAT_MAX_AUDIO) {
- /* This is the audio portion. Call the video one... */
- if (!fs->vfs && fs->filename) {
- /* XXX Support other video formats XXX */
- const char *type = "h263";
- fs->vfs = ast_writefile(fs->filename, type, NULL, fs->flags, 0, fs->mode);
- ast_log(LOG_DEBUG, "Opened video output file\n");
- }
- if (fs->vfs)
- return ast_writestream(fs->vfs, f);
- /* Ignore */
- return 0;
- } else {
- /* Might / might not have mark set */
- alt = 1;
- }
- } else if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Tried to write non-voice frame\n");
- return -1;
- }
- if (((fs->fmt->format | alt) & f->subclass) == f->subclass) {
- res = fs->fmt->write(fs, f);
- if (res < 0)
- ast_log(LOG_WARNING, "Natural write failed\n");
- if (res > 0)
- ast_log(LOG_WARNING, "Huh??\n");
- return res;
- } else {
- /* XXX If they try to send us a type of frame that isn't the normal frame, and isn't
- the one we've setup a translator for, we do the "wrong thing" XXX */
- if (fs->trans && (f->subclass != fs->lastwriteformat)) {
- ast_translator_free_path(fs->trans);
- fs->trans = NULL;
- }
- if (!fs->trans)
- fs->trans = ast_translator_build_path(fs->fmt->format, f->subclass);
- if (!fs->trans)
- ast_log(LOG_WARNING, "Unable to translate to format %s, source format %s\n", fs->fmt->name, ast_getformatname(f->subclass));
- else {
- fs->lastwriteformat = f->subclass;
- res = 0;
- /* Get the translated frame but don't consume the original in case they're using it on another stream */
- trf = ast_translate(fs->trans, f, 0);
- if (trf) {
- res = fs->fmt->write(fs, trf);
- if (res)
- ast_log(LOG_WARNING, "Translated frame write failed\n");
- } else
- res = 0;
- }
- return res;
- }
-}
-
-static int copy(const char *infile, const char *outfile)
-{
- int ifd;
- int ofd;
- int res;
- int len;
- char buf[4096];
-
- if ((ifd = open(infile, O_RDONLY)) < 0) {
- ast_log(LOG_WARNING, "Unable to open %s in read-only mode\n", infile);
- return -1;
- }
- if ((ofd = open(outfile, O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0) {
- ast_log(LOG_WARNING, "Unable to open %s in write-only mode\n", outfile);
- close(ifd);
- return -1;
- }
- do {
- len = read(ifd, buf, sizeof(buf));
- if (len < 0) {
- ast_log(LOG_WARNING, "Read failed on %s: %s\n", infile, strerror(errno));
- close(ifd);
- close(ofd);
- unlink(outfile);
- }
- if (len) {
- res = write(ofd, buf, len);
- if (res != len) {
- ast_log(LOG_WARNING, "Write failed on %s (%d of %d): %s\n", outfile, res, len, strerror(errno));
- close(ifd);
- close(ofd);
- unlink(outfile);
- }
- }
- } while(len);
- close(ifd);
- close(ofd);
- return 0;
-}
-
-static char *build_filename(const char *filename, const char *ext)
-{
- char *fn, type[16];
- int fnsize = 0;
-
- if (!strcmp(ext, "wav49")) {
- ast_copy_string(type, "WAV", sizeof(type));
- } else {
- ast_copy_string(type, ext, sizeof(type));
- }
-
- if (filename[0] == '/') {
- fnsize = strlen(filename) + strlen(type) + 2;
- fn = malloc(fnsize);
- if (fn)
- snprintf(fn, fnsize, "%s.%s", filename, type);
- } else {
- char tmp[AST_CONFIG_MAX_PATH] = "";
-
- snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_VAR_DIR, "sounds");
- fnsize = strlen(tmp) + strlen(filename) + strlen(type) + 3;
- fn = malloc(fnsize);
- if (fn)
- snprintf(fn, fnsize, "%s/%s.%s", tmp, filename, type);
- }
-
- return fn;
-}
-
-static int exts_compare(const char *exts, const char *type)
-{
- char *stringp = NULL, *ext;
- char tmp[256];
-
- ast_copy_string(tmp, exts, sizeof(tmp));
- stringp = tmp;
- while ((ext = strsep(&stringp, "|"))) {
- if (!strcmp(ext, type)) {
- return 1;
- }
- }
-
- return 0;
-}
-
-#define ACTION_EXISTS 1
-#define ACTION_DELETE 2
-#define ACTION_RENAME 3
-#define ACTION_OPEN 4
-#define ACTION_COPY 5
-
-static int ast_filehelper(const char *filename, const char *filename2, const char *fmt, int action)
-{
- struct stat st;
- struct ast_format *f;
- struct ast_filestream *s;
- int res=0, ret = 0;
- char *ext=NULL, *exts, *fn, *nfn;
- FILE *bfile;
- struct ast_channel *chan = (struct ast_channel *)filename2;
-
- /* Start with negative response */
- if (action == ACTION_EXISTS)
- res = 0;
- else
- res = -1;
- if (action == ACTION_OPEN)
- ret = -1;
- /* Check for a specific format */
- if (ast_mutex_lock(&formatlock)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- if (action == ACTION_EXISTS)
- return 0;
- else
- return -1;
- }
- f = formats;
- while(f) {
- if (!fmt || exts_compare(f->exts, fmt)) {
- char *stringp=NULL;
- exts = ast_strdupa(f->exts);
- /* Try each kind of extension */
- stringp=exts;
- ext = strsep(&stringp, "|");
- do {
- fn = build_filename(filename, ext);
- if (fn) {
- res = stat(fn, &st);
- if (!res) {
- switch(action) {
- case ACTION_EXISTS:
- ret |= f->format;
- break;
- case ACTION_DELETE:
- res = unlink(fn);
- if (res)
- ast_log(LOG_WARNING, "unlink(%s) failed: %s\n", fn, strerror(errno));
- break;
- case ACTION_RENAME:
- nfn = build_filename(filename2, ext);
- if (nfn) {
- res = rename(fn, nfn);
- if (res)
- ast_log(LOG_WARNING, "rename(%s,%s) failed: %s\n", fn, nfn, strerror(errno));
- free(nfn);
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- break;
- case ACTION_COPY:
- nfn = build_filename(filename2, ext);
- if (nfn) {
- res = copy(fn, nfn);
- if (res)
- ast_log(LOG_WARNING, "copy(%s,%s) failed: %s\n", fn, nfn, strerror(errno));
- free(nfn);
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- break;
- case ACTION_OPEN:
- if ((ret < 0) && ((chan->writeformat & f->format) ||
- ((f->format >= AST_FORMAT_MAX_AUDIO) && fmt))) {
- bfile = fopen(fn, "r");
- if (bfile) {
- ret = 1;
- s = f->open(bfile);
- if (s) {
- s->lasttimeout = -1;
- s->fmt = f;
- s->trans = NULL;
- s->filename = NULL;
- if (s->fmt->format < AST_FORMAT_MAX_AUDIO)
- chan->stream = s;
- else
- chan->vstream = s;
- } else {
- fclose(bfile);
- ast_log(LOG_WARNING, "Unable to open file on %s\n", fn);
- ret = -1;
- }
- } else{
- ast_log(LOG_WARNING, "Couldn't open file %s\n", fn);
- ret = -1;
- }
- }
- break;
- default:
- ast_log(LOG_WARNING, "Unknown helper %d\n", action);
- }
- /* Conveniently this logic is the same for all */
- if (res)
- break;
- }
- free(fn);
- }
- ext = strsep(&stringp, "|");
- } while(ext);
-
- }
- f = f->next;
- }
- ast_mutex_unlock(&formatlock);
- if ((action == ACTION_EXISTS) || (action == ACTION_OPEN))
- res = ret ? ret : -1;
- return res;
-}
-struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang)
-{
- return ast_openstream_full(chan, filename, preflang, 0);
-}
-
-struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char *filename, const char *preflang, int asis)
-{
- /* This is a fairly complex routine. Essentially we should do
- the following:
-
- 1) Find which file handlers produce our type of format.
- 2) Look for a filename which it can handle.
- 3) If we find one, then great.
- 4) If not, see what files are there
- 5) See what we can actually support
- 6) Choose the one with the least costly translator path and
- set it up.
-
- */
- int fmts = -1;
- char filename2[256]="";
- char filename3[256];
- char *endpart;
- int res;
-
- if (!asis) {
- /* do this first, otherwise we detect the wrong writeformat */
- ast_stopstream(chan);
- if (chan->generator)
- ast_deactivate_generator(chan);
- }
- if (!ast_strlen_zero(preflang)) {
- ast_copy_string(filename3, filename, sizeof(filename3));
- endpart = strrchr(filename3, '/');
- if (endpart) {
- *endpart = '\0';
- endpart++;
- snprintf(filename2, sizeof(filename2), "%s/%s/%s", filename3, preflang, endpart);
- } else
- snprintf(filename2, sizeof(filename2), "%s/%s", preflang, filename);
- fmts = ast_fileexists(filename2, NULL, NULL);
- }
- if (fmts < 1) {
- ast_copy_string(filename2, filename, sizeof(filename2));
- fmts = ast_fileexists(filename2, NULL, NULL);
- }
- if (fmts < 1) {
- ast_log(LOG_WARNING, "File %s does not exist in any format\n", filename);
- return NULL;
- }
- chan->oldwriteformat = chan->writeformat;
- /* Set the channel to a format we can work with */
- res = ast_set_write_format(chan, fmts);
-
- res = ast_filehelper(filename2, (char *)chan, NULL, ACTION_OPEN);
- if (res >= 0)
- return chan->stream;
- return NULL;
-}
-
-struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang)
-{
- /* This is a fairly complex routine. Essentially we should do
- the following:
-
- 1) Find which file handlers produce our type of format.
- 2) Look for a filename which it can handle.
- 3) If we find one, then great.
- 4) If not, see what files are there
- 5) See what we can actually support
- 6) Choose the one with the least costly translator path and
- set it up.
-
- */
- int fd = -1;
- int fmts = -1;
- char filename2[256];
- char lang2[MAX_LANGUAGE];
- /* XXX H.263 only XXX */
- char *fmt = "h263";
- if (!ast_strlen_zero(preflang)) {
- snprintf(filename2, sizeof(filename2), "%s/%s", preflang, filename);
- fmts = ast_fileexists(filename2, fmt, NULL);
- if (fmts < 1) {
- ast_copy_string(lang2, preflang, sizeof(lang2));
- snprintf(filename2, sizeof(filename2), "%s/%s", lang2, filename);
- fmts = ast_fileexists(filename2, fmt, NULL);
- }
- }
- if (fmts < 1) {
- ast_copy_string(filename2, filename, sizeof(filename2));
- fmts = ast_fileexists(filename2, fmt, NULL);
- }
- if (fmts < 1) {
- return NULL;
- }
- fd = ast_filehelper(filename2, (char *)chan, fmt, ACTION_OPEN);
- if (fd >= 0)
- return chan->vstream;
- ast_log(LOG_WARNING, "File %s has video but couldn't be opened\n", filename);
- return NULL;
-}
-
-struct ast_frame *ast_readframe(struct ast_filestream *s)
-{
- struct ast_frame *f = NULL;
- int whennext = 0;
- if (s && s->fmt)
- f = s->fmt->read(s, &whennext);
- return f;
-}
-
-static int ast_readaudio_callback(void *data)
-{
- struct ast_filestream *s = data;
- struct ast_frame *fr;
- int whennext = 0;
-
- while(!whennext) {
- fr = s->fmt->read(s, &whennext);
- if (fr) {
- if (ast_write(s->owner, fr)) {
- ast_log(LOG_WARNING, "Failed to write frame\n");
- s->owner->streamid = -1;
-#ifdef ZAPTEL_OPTIMIZATIONS
- ast_settimeout(s->owner, 0, NULL, NULL);
-#endif
- return 0;
- }
- } else {
- /* Stream has finished */
- s->owner->streamid = -1;
-#ifdef ZAPTEL_OPTIMIZATIONS
- ast_settimeout(s->owner, 0, NULL, NULL);
-#endif
- return 0;
- }
- }
- if (whennext != s->lasttimeout) {
-#ifdef ZAPTEL_OPTIMIZATIONS
- if (s->owner->timingfd > -1)
- ast_settimeout(s->owner, whennext, ast_readaudio_callback, s);
- else
-#endif
- s->owner->streamid = ast_sched_add(s->owner->sched, whennext/8, ast_readaudio_callback, s);
- s->lasttimeout = whennext;
- return 0;
- }
- return 1;
-}
-
-static int ast_readvideo_callback(void *data)
-{
- struct ast_filestream *s = data;
- struct ast_frame *fr;
- int whennext = 0;
-
- while(!whennext) {
- fr = s->fmt->read(s, &whennext);
- if (fr) {
- if (ast_write(s->owner, fr)) {
- ast_log(LOG_WARNING, "Failed to write frame\n");
- s->owner->vstreamid = -1;
- return 0;
- }
- } else {
- /* Stream has finished */
- s->owner->vstreamid = -1;
- return 0;
- }
- }
- if (whennext != s->lasttimeout) {
- s->owner->vstreamid = ast_sched_add(s->owner->sched, whennext/8, ast_readvideo_callback, s);
- s->lasttimeout = whennext;
- return 0;
- }
- return 1;
-}
-
-int ast_applystream(struct ast_channel *chan, struct ast_filestream *s)
-{
- s->owner = chan;
- return 0;
-}
-
-int ast_playstream(struct ast_filestream *s)
-{
- if (s->fmt->format < AST_FORMAT_MAX_AUDIO)
- ast_readaudio_callback(s);
- else
- ast_readvideo_callback(s);
- return 0;
-}
-
-int ast_seekstream(struct ast_filestream *fs, long sample_offset, int whence)
-{
- return fs->fmt->seek(fs, sample_offset, whence);
-}
-
-int ast_truncstream(struct ast_filestream *fs)
-{
- return fs->fmt->trunc(fs);
-}
-
-long ast_tellstream(struct ast_filestream *fs)
-{
- return fs->fmt->tell(fs);
-}
-
-int ast_stream_fastforward(struct ast_filestream *fs, long ms)
-{
- /* I think this is right, 8000 samples per second, 1000 ms a second so 8
- * samples per ms */
- long samples = ms * 8;
- return ast_seekstream(fs, samples, SEEK_CUR);
-}
-
-int ast_stream_rewind(struct ast_filestream *fs, long ms)
-{
- long samples = ms * 8;
- samples = samples * -1;
- return ast_seekstream(fs, samples, SEEK_CUR);
-}
-
-int ast_closestream(struct ast_filestream *f)
-{
- char *cmd = NULL;
- size_t size = 0;
- /* Stop a running stream if there is one */
- if (f->owner) {
- if (f->fmt->format < AST_FORMAT_MAX_AUDIO) {
- f->owner->stream = NULL;
- if (f->owner->streamid > -1)
- ast_sched_del(f->owner->sched, f->owner->streamid);
- f->owner->streamid = -1;
-#ifdef ZAPTEL_OPTIMIZATIONS
- ast_settimeout(f->owner, 0, NULL, NULL);
-#endif
- } else {
- f->owner->vstream = NULL;
- if (f->owner->vstreamid > -1)
- ast_sched_del(f->owner->sched, f->owner->vstreamid);
- f->owner->vstreamid = -1;
- }
- }
- /* destroy the translator on exit */
- if (f->trans) {
- ast_translator_free_path(f->trans);
- f->trans = NULL;
- }
-
- if (f->realfilename && f->filename) {
- size = strlen(f->filename) + strlen(f->realfilename) + 15;
- cmd = alloca(size);
- memset(cmd,0,size);
- snprintf(cmd,size,"/bin/mv -f %s %s",f->filename,f->realfilename);
- ast_safe_system(cmd);
- }
-
- if (f->filename) {
- free(f->filename);
- f->filename = NULL;
- }
- if (f->realfilename) {
- free(f->realfilename);
- f->realfilename = NULL;
- }
- f->fmt->close(f);
- return 0;
-}
-
-
-int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
-{
- char filename2[256];
- char tmp[256];
- char *postfix;
- char *prefix;
- char *c;
- char lang2[MAX_LANGUAGE];
- int res = -1;
- if (!ast_strlen_zero(preflang)) {
- /* Insert the language between the last two parts of the path */
- ast_copy_string(tmp, filename, sizeof(tmp));
- c = strrchr(tmp, '/');
- if (c) {
- *c = '\0';
- postfix = c+1;
- prefix = tmp;
- snprintf(filename2, sizeof(filename2), "%s/%s/%s", prefix, preflang, postfix);
- } else {
- postfix = tmp;
- prefix="";
- snprintf(filename2, sizeof(filename2), "%s/%s", preflang, postfix);
- }
- res = ast_filehelper(filename2, NULL, fmt, ACTION_EXISTS);
- if (res < 1) {
- char *stringp=NULL;
- ast_copy_string(lang2, preflang, sizeof(lang2));
- stringp=lang2;
- strsep(&stringp, "_");
- /* If language is a specific locality of a language (like es_MX), strip the locality and try again */
- if (strcmp(lang2, preflang)) {
- if (ast_strlen_zero(prefix)) {
- snprintf(filename2, sizeof(filename2), "%s/%s", lang2, postfix);
- } else {
- snprintf(filename2, sizeof(filename2), "%s/%s/%s", prefix, lang2, postfix);
- }
- res = ast_filehelper(filename2, NULL, fmt, ACTION_EXISTS);
- }
- }
- }
-
- /* Fallback to no language (usually winds up being American English) */
- if (res < 1) {
- res = ast_filehelper(filename, NULL, fmt, ACTION_EXISTS);
- }
- return res;
-}
-
-int ast_filedelete(const char *filename, const char *fmt)
-{
- return ast_filehelper(filename, NULL, fmt, ACTION_DELETE);
-}
-
-int ast_filerename(const char *filename, const char *filename2, const char *fmt)
-{
- return ast_filehelper(filename, filename2, fmt, ACTION_RENAME);
-}
-
-int ast_filecopy(const char *filename, const char *filename2, const char *fmt)
-{
- return ast_filehelper(filename, filename2, fmt, ACTION_COPY);
-}
-
-int ast_streamfile(struct ast_channel *chan, const char *filename, const char *preflang)
-{
- struct ast_filestream *fs;
- struct ast_filestream *vfs;
-
- fs = ast_openstream(chan, filename, preflang);
- vfs = ast_openvstream(chan, filename, preflang);
- if (vfs)
- ast_log(LOG_DEBUG, "Ooh, found a video stream, too\n");
- if (fs){
- if (ast_applystream(chan, fs))
- return -1;
- if (vfs && ast_applystream(chan, vfs))
- return -1;
- if (ast_playstream(fs))
- return -1;
- if (vfs && ast_playstream(vfs))
- return -1;
-#if 1
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Playing '%s' (language '%s')\n", filename, preflang ? preflang : "default");
-#endif
- return 0;
- }
- ast_log(LOG_WARNING, "Unable to open %s (format %s): %s\n", filename, ast_getformatname(chan->nativeformats), strerror(errno));
- return -1;
-}
-
-struct ast_filestream *ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
-{
- FILE *bfile;
- struct ast_format *f;
- struct ast_filestream *fs = NULL;
- char *fn;
-
- if (ast_mutex_lock(&formatlock)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return NULL;
- }
-
- for (f = formats; f && !fs; f = f->next) {
- if (!exts_compare(f->exts, type))
- continue;
-
- fn = build_filename(filename, type);
- bfile = fopen(fn, "r");
- if (bfile) {
- errno = 0;
-
- if (!(fs = f->open(bfile))) {
- ast_log(LOG_WARNING, "Unable to open %s\n", fn);
- fclose(bfile);
- free(fn);
- continue;
- }
-
- fs->trans = NULL;
- fs->fmt = f;
- fs->flags = flags;
- fs->mode = mode;
- fs->filename = strdup(filename);
- fs->vfs = NULL;
- } else if (errno != EEXIST)
- ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno));
- free(fn);
- }
-
- ast_mutex_unlock(&formatlock);
- if (!fs)
- ast_log(LOG_WARNING, "No such format '%s'\n", type);
-
- return fs;
-}
-
-struct ast_filestream *ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
-{
- int fd, myflags = 0;
- /* compiler claims this variable can be used before initialization... */
- FILE *bfile = NULL;
- struct ast_format *f;
- struct ast_filestream *fs = NULL;
- char *fn, *orig_fn = NULL;
- char *buf = NULL;
- size_t size = 0;
-
- if (ast_mutex_lock(&formatlock)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return NULL;
- }
-
- /* set the O_TRUNC flag if and only if there is no O_APPEND specified */
- if (flags & O_APPEND) {
- /* We really can't use O_APPEND as it will break WAV header updates */
- flags &= ~O_APPEND;
- } else {
- myflags = O_TRUNC;
- }
-
- myflags |= O_WRONLY | O_CREAT;
-
- for (f = formats; f && !fs; f = f->next) {
- if (!exts_compare(f->exts, type))
- continue;
-
- fn = build_filename(filename, type);
- fd = open(fn, flags | myflags, mode);
- if (fd > -1) {
- /* fdopen() the resulting file stream */
- bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ? "w+" : "w");
- if (!bfile) {
- ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno));
- close(fd);
- fd = -1;
- }
- }
-
- if (option_cache_record_files && (fd > -1)) {
- char *c;
-
- fclose(bfile);
- /*
- We touch orig_fn just as a place-holder so other things (like vmail) see the file is there.
- What we are really doing is writing to record_cache_dir until we are done then we will mv the file into place.
- */
- orig_fn = ast_strdupa(fn);
- for (c = fn; *c; c++)
- if (*c == '/')
- *c = '_';
-
- size = strlen(fn) + strlen(record_cache_dir) + 2;
- buf = alloca(size);
- strcpy(buf, record_cache_dir);
- strcat(buf, "/");
- strcat(buf, fn);
- free(fn);
- fn = buf;
- fd = open(fn, flags | myflags, mode);
- if (fd > -1) {
- /* fdopen() the resulting file stream */
- bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ? "w+" : "w");
- if (!bfile) {
- ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno));
- close(fd);
- fd = -1;
- }
- }
- }
- if (fd > -1) {
- errno = 0;
- if ((fs = f->rewrite(bfile, comment))) {
- fs->trans = NULL;
- fs->fmt = f;
- fs->flags = flags;
- fs->mode = mode;
- if (orig_fn) {
- fs->realfilename = strdup(orig_fn);
- fs->filename = strdup(fn);
- } else {
- fs->realfilename = NULL;
- fs->filename = strdup(filename);
- }
- fs->vfs = NULL;
- /* If truncated, we'll be at the beginning; if not truncated, then append */
- f->seek(fs, 0, SEEK_END);
- } else {
- ast_log(LOG_WARNING, "Unable to rewrite %s\n", fn);
- close(fd);
- if (orig_fn) {
- unlink(fn);
- unlink(orig_fn);
- }
- }
- } else if (errno != EEXIST) {
- ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno));
- if (orig_fn)
- unlink(orig_fn);
- }
- /* if buf != NULL then fn is already free and pointing to it */
- if (!buf)
- free(fn);
- }
-
- ast_mutex_unlock(&formatlock);
- if (!fs)
- ast_log(LOG_WARNING, "No such format '%s'\n", type);
-
- return fs;
-}
-
-int ast_waitstream(struct ast_channel *c, const char *breakon)
-{
- /* XXX Maybe I should just front-end ast_waitstream_full ? XXX */
- int res;
- struct ast_frame *fr;
- if (!breakon) breakon = "";
- while(c->stream) {
- res = ast_sched_wait(c->sched);
- if ((res < 0) && !c->timingfunc) {
- ast_stopstream(c);
- break;
- }
- if (res < 0)
- res = 1000;
- res = ast_waitfor(c, res);
- if (res < 0) {
- ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno));
- return res;
- } else if (res > 0) {
- fr = ast_read(c);
- if (!fr) {
-#if 0
- ast_log(LOG_DEBUG, "Got hung up\n");
-#endif
- return -1;
- }
-
- switch(fr->frametype) {
- case AST_FRAME_DTMF:
- res = fr->subclass;
- if (strchr(breakon, res)) {
- ast_frfree(fr);
- return res;
- }
- break;
- case AST_FRAME_CONTROL:
- switch(fr->subclass) {
- case AST_CONTROL_HANGUP:
- ast_frfree(fr);
- return -1;
- case AST_CONTROL_RINGING:
- case AST_CONTROL_ANSWER:
- case AST_CONTROL_VIDUPDATE:
- /* Unimportant */
- break;
- default:
- ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass);
- }
- }
- /* Ignore */
- ast_frfree(fr);
- }
- ast_sched_runq(c->sched);
- }
- return (c->_softhangup ? -1 : 0);
-}
-
-int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms)
-{
- int res;
- struct ast_frame *fr;
-
- if (!breakon)
- breakon = "";
- if (!forward)
- forward = "";
- if (!rewind)
- rewind = "";
-
- while(c->stream) {
- res = ast_sched_wait(c->sched);
- if ((res < 0) && !c->timingfunc) {
- ast_stopstream(c);
- break;
- }
- if (res < 0)
- res = 1000;
- res = ast_waitfor(c, res);
- if (res < 0) {
- ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno));
- return res;
- } else
- if (res > 0) {
- fr = ast_read(c);
- if (!fr) {
-#if 0
- ast_log(LOG_DEBUG, "Got hung up\n");
-#endif
- return -1;
- }
-
- switch(fr->frametype) {
- case AST_FRAME_DTMF:
- res = fr->subclass;
- if (strchr(forward,res)) {
- ast_stream_fastforward(c->stream, ms);
- } else if (strchr(rewind,res)) {
- ast_stream_rewind(c->stream, ms);
- } else if (strchr(breakon, res)) {
- ast_frfree(fr);
- return res;
- }
- break;
- case AST_FRAME_CONTROL:
- switch(fr->subclass) {
- case AST_CONTROL_HANGUP:
- ast_frfree(fr);
- return -1;
- case AST_CONTROL_RINGING:
- case AST_CONTROL_ANSWER:
- /* Unimportant */
- break;
- default:
- ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass);
- }
- }
- /* Ignore */
- ast_frfree(fr);
- } else
- ast_sched_runq(c->sched);
-
-
- }
- return (c->_softhangup ? -1 : 0);
-}
-
-int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int cmdfd)
-{
- int res;
- int ms;
- int outfd;
- struct ast_frame *fr;
- struct ast_channel *rchan;
-
- if (!breakon)
- breakon = "";
-
- while(c->stream) {
- ms = ast_sched_wait(c->sched);
- if ((ms < 0) && !c->timingfunc) {
- ast_stopstream(c);
- break;
- }
- if (ms < 0)
- ms = 1000;
- rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
- if (!rchan && (outfd < 0) && (ms)) {
- /* Continue */
- if (errno == EINTR)
- continue;
- ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
- return -1;
- } else if (outfd > -1) {
- /* The FD we were watching has something waiting */
- return 1;
- } else if (rchan) {
- fr = ast_read(c);
- if (!fr) {
-#if 0
- ast_log(LOG_DEBUG, "Got hung up\n");
-#endif
- return -1;
- }
-
- switch(fr->frametype) {
- case AST_FRAME_DTMF:
- res = fr->subclass;
- if (strchr(breakon, res)) {
- ast_frfree(fr);
- return res;
- }
- break;
- case AST_FRAME_CONTROL:
- switch(fr->subclass) {
- case AST_CONTROL_HANGUP:
- ast_frfree(fr);
- return -1;
- case AST_CONTROL_RINGING:
- case AST_CONTROL_ANSWER:
- /* Unimportant */
- break;
- default:
- ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass);
- }
- case AST_FRAME_VOICE:
- /* Write audio if appropriate */
- if (audiofd > -1)
- write(audiofd, fr->data, fr->datalen);
- }
- /* Ignore */
- ast_frfree(fr);
- }
- ast_sched_runq(c->sched);
- }
- return (c->_softhangup ? -1 : 0);
-}
-
-int ast_waitstream_exten(struct ast_channel *c, const char *context)
-{
- /* Waitstream, with return in the case of a valid 1 digit extension */
- /* in the current or specified context being pressed */
- /* XXX Maybe I should just front-end ast_waitstream_full ? XXX */
- int res;
- struct ast_frame *fr;
- char exten[AST_MAX_EXTENSION];
-
- if (!context) context = c->context;
- while(c->stream) {
- res = ast_sched_wait(c->sched);
- if ((res < 0) && !c->timingfunc) {
- ast_stopstream(c);
- break;
- }
- if (res < 0)
- res = 1000;
- res = ast_waitfor(c, res);
- if (res < 0) {
- ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno));
- return res;
- } else if (res > 0) {
- fr = ast_read(c);
- if (!fr) {
-#if 0
- ast_log(LOG_DEBUG, "Got hung up\n");
-#endif
- return -1;
- }
-
- switch(fr->frametype) {
- case AST_FRAME_DTMF:
- res = fr->subclass;
- snprintf(exten, sizeof(exten), "%c", res);
- if (ast_exists_extension(c, context, exten, 1, c->cid.cid_num)) {
- ast_frfree(fr);
- return res;
- }
- break;
- case AST_FRAME_CONTROL:
- switch(fr->subclass) {
- case AST_CONTROL_HANGUP:
- ast_frfree(fr);
- return -1;
- case AST_CONTROL_RINGING:
- case AST_CONTROL_ANSWER:
- /* Unimportant */
- break;
- default:
- ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass);
- }
- }
- /* Ignore */
- ast_frfree(fr);
- }
- ast_sched_runq(c->sched);
- }
- return (c->_softhangup ? -1 : 0);
-}
-
-static int show_file_formats(int fd, int argc, char *argv[])
-{
-#define FORMAT "%-10s %-10s %-20s\n"
-#define FORMAT2 "%-10s %-10s %-20s\n"
- struct ast_format *f;
- int count_fmt = 0;
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, FORMAT, "Format", "Name", "Extensions");
-
- if (ast_mutex_lock(&formatlock)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return -1;
- }
-
- f = formats;
- while(f) {
- ast_cli(fd, FORMAT2, ast_getformatname(f->format), f->name, f->exts);
- f = f->next;
- count_fmt++;
- };
- ast_mutex_unlock(&formatlock);
- ast_cli(fd, "%d file formats registered.\n", count_fmt);
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-
-}
-
-struct ast_cli_entry show_file =
-{
- { "show", "file", "formats" },
- show_file_formats,
- "Displays file formats",
- "Usage: show file formats\n"
- " displays currently registered file formats (if any)\n"
-};
-
-int ast_file_init(void)
-{
- ast_cli_register(&show_file);
- return 0;
-}
diff --git a/1.2-netsec/formats/Makefile b/1.2-netsec/formats/Makefile
deleted file mode 100644
index 31f973390..000000000
--- a/1.2-netsec/formats/Makefile
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Makefile for file format modules
-#
-# Copyright (C) 1999-2005, Digium
-#
-# Mark Spencer <markster@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-FORMAT_LIBS=format_gsm.so format_wav.so \
- format_wav_gsm.so format_vox.so format_pcm.so format_g729.so \
- format_pcm_alaw.so format_h263.so format_g726.so format_ilbc.so \
- format_sln.so format_au.so
-FORMAT_LIBS+=format_jpeg.so
-
-#
-# G723 simple frame is deprecated
-#
-FORMAT_LIBS+=format_g723.so
-
-#
-# OGG/Vorbis format
-#
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/vorbis/codec.h),)
- FORMAT_LIBS+=format_ogg_vorbis.so
-endif
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-GSMLIB=../codecs/gsm/lib/libgsm.a
-
-ifeq (${OSARCH},CYGWIN)
-CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
-CYGSOLIB=-L.. -L. -lasterisk.dll
-else
-CFLAGS+=-fPIC
-endif
-all: depend $(FORMAT_LIBS)
-
-clean:
- rm -f *.so *.o .depend
-
-%.so : %.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-format_mp3.so : format_mp3.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lm
-
-format_ogg_vorbis.so : format_ogg_vorbis.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -logg -lvorbis -lvorbisenc -lm
-
-install: all
- for x in $(FORMAT_LIBS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
diff --git a/1.2-netsec/formats/format_au.c b/1.2-netsec/formats/format_au.c
deleted file mode 100644
index 669fa1921..000000000
--- a/1.2-netsec/formats/format_au.c
+++ /dev/null
@@ -1,394 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Andriy Pylypenko
- * Code based on format_wav.c by 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 Work with Sun Microsystems AU format.
- *
- * signed linear
- * \arg File extension: au
- * \ingroup formats
- */
-
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-#define BUF_SIZE 160
-
-#define AU_HEADER_SIZE 24
-#define AU_HEADER(var) u_int32_t var[6]
-
-#define AU_HDR_MAGIC_OFF 0
-#define AU_HDR_HDR_SIZE_OFF 1
-#define AU_HDR_DATA_SIZE_OFF 2
-#define AU_HDR_ENCODING_OFF 3
-#define AU_HDR_SAMPLE_RATE_OFF 4
-#define AU_HDR_CHANNELS_OFF 5
-
-#define AU_ENC_8BIT_ULAW 1
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_channel *owner;
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- short buf[BUF_SIZE];
-};
-
-
-AST_MUTEX_DEFINE_STATIC(au_lock);
-static int localusecnt = 0;
-
-static char *name = "au";
-static char *desc = "Sun Microsystems AU format (signed linear)";
-static char *exts = "au";
-
-
-#define AU_MAGIC 0x2e736e64
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define htoll(b) (b)
-#define htols(b) (b)
-#define ltohl(b) (b)
-#define ltohs(b) (b)
-#else
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define htoll(b) \
- (((((b) ) & 0xFF) << 24) | \
- ((((b) >> 8) & 0xFF) << 16) | \
- ((((b) >> 16) & 0xFF) << 8) | \
- ((((b) >> 24) & 0xFF) ))
-#define htols(b) \
- (((((b) ) & 0xFF) << 8) | \
- ((((b) >> 8) & 0xFF) ))
-#define ltohl(b) htoll(b)
-#define ltohs(b) htols(b)
-#else
-#error "Endianess not defined"
-#endif
-#endif
-
-
-static int check_header(FILE *f)
-{
- AU_HEADER(header);
- u_int32_t magic;
- u_int32_t hdr_size;
- u_int32_t data_size;
- u_int32_t encoding;
- u_int32_t sample_rate;
- u_int32_t channels;
-
- if (fread(header, 1, AU_HEADER_SIZE, f) != AU_HEADER_SIZE) {
- ast_log(LOG_WARNING, "Read failed (header)\n");
- return -1;
- }
- magic = ltohl(header[AU_HDR_MAGIC_OFF]);
- if (magic != (u_int32_t) AU_MAGIC) {
- ast_log(LOG_WARNING, "Bad magic: 0x%x\n", magic);
- }
-/* hdr_size = ltohl(header[AU_HDR_HDR_SIZE_OFF]);
- if (hdr_size < AU_HEADER_SIZE)*/
- hdr_size = AU_HEADER_SIZE;
-/* data_size = ltohl(header[AU_HDR_DATA_SIZE_OFF]); */
- encoding = ltohl(header[AU_HDR_ENCODING_OFF]);
- if (encoding != AU_ENC_8BIT_ULAW) {
- ast_log(LOG_WARNING, "Unexpected format: %d. Only 8bit ULAW allowed (%d)\n", encoding, AU_ENC_8BIT_ULAW);
- return -1;
- }
- sample_rate = ltohl(header[AU_HDR_SAMPLE_RATE_OFF]);
- if (sample_rate != 8000) {
- ast_log(LOG_WARNING, "Sample rate can only be 8000 not %d\n", sample_rate);
- return -1;
- }
- channels = ltohl(header[AU_HDR_CHANNELS_OFF]);
- if (channels != 1) {
- ast_log(LOG_WARNING, "Not in mono: channels=%d\n", channels);
- return -1;
- }
- /* Skip to data */
- fseek(f, 0, SEEK_END);
- data_size = ftell(f) - hdr_size;
- if (fseek(f, hdr_size, SEEK_SET) == -1 ) {
- ast_log(LOG_WARNING, "Failed to skip to data: %d\n", hdr_size);
- return -1;
- }
- return data_size;
-}
-
-static int update_header(FILE *f)
-{
- off_t cur, end;
- u_int32_t datalen;
- int bytes;
-
- cur = ftell(f);
- fseek(f, 0, SEEK_END);
- end = ftell(f);
- /* data starts 24 bytes in */
- bytes = end - AU_HEADER_SIZE;
- datalen = htoll(bytes);
-
- if (cur < 0) {
- ast_log(LOG_WARNING, "Unable to find our position\n");
- return -1;
- }
- if (fseek(f, AU_HDR_DATA_SIZE_OFF * sizeof(u_int32_t), SEEK_SET)) {
- ast_log(LOG_WARNING, "Unable to set our position\n");
- return -1;
- }
- if (fwrite(&datalen, 1, sizeof(datalen), f) != sizeof(datalen)) {
- ast_log(LOG_WARNING, "Unable to set write file size\n");
- return -1;
- }
- if (fseek(f, cur, SEEK_SET)) {
- ast_log(LOG_WARNING, "Unable to return to position\n");
- return -1;
- }
- return 0;
-}
-
-static int write_header(FILE *f)
-{
- AU_HEADER(header);
-
- header[AU_HDR_MAGIC_OFF] = htoll((u_int32_t) AU_MAGIC);
- header[AU_HDR_HDR_SIZE_OFF] = htoll(AU_HEADER_SIZE);
- header[AU_HDR_DATA_SIZE_OFF] = 0;
- header[AU_HDR_ENCODING_OFF] = htoll(AU_ENC_8BIT_ULAW);
- header[AU_HDR_SAMPLE_RATE_OFF] = htoll(8000);
- header[AU_HDR_CHANNELS_OFF] = htoll(1);
-
- /* Write an au header, ignoring sizes which will be filled in later */
- fseek(f, 0, SEEK_SET);
- if (fwrite(header, 1, AU_HEADER_SIZE, f) != AU_HEADER_SIZE) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_filestream *au_open(FILE *f)
-{
- struct ast_filestream *tmp;
-
- if (!(tmp = malloc(sizeof(struct ast_filestream)))) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return NULL;
- }
-
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (check_header(f) < 0) {
- free(tmp);
- return NULL;
- }
- if (ast_mutex_lock(&au_lock)) {
- ast_log(LOG_WARNING, "Unable to lock au count\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->buf;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_ULAW;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- localusecnt++;
- ast_mutex_unlock(&au_lock);
- ast_update_use_count();
- return tmp;
-}
-
-static struct ast_filestream *au_rewrite(FILE *f, const char *comment)
-{
- struct ast_filestream *tmp;
-
- if ((tmp = malloc(sizeof(struct ast_filestream))) == NULL) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return NULL;
- }
-
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (write_header(f)) {
- free(tmp);
- return NULL;
- }
- if (ast_mutex_lock(&au_lock)) {
- ast_log(LOG_WARNING, "Unable to lock au count\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- localusecnt++;
- ast_mutex_unlock(&au_lock);
- ast_update_use_count();
- return tmp;
-}
-
-static void au_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&au_lock)) {
- ast_log(LOG_WARNING, "Unable to lock au count\n");
- return;
- }
- localusecnt--;
- ast_mutex_unlock(&au_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
-}
-
-static struct ast_frame *au_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- int delay;
- /* Send a frame from the file to the appropriate channel */
-
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_ULAW;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.mallocd = 0;
- s->fr.data = s->buf;
- if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
- if (res)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- s->fr.samples = res;
- s->fr.datalen = res;
- delay = s->fr.samples;
- *whennext = delay;
- return &s->fr;
-}
-
-static int au_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
-
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_ULAW) {
- ast_log(LOG_WARNING, "Asked to write non-ulaw frame (%d)!\n", f->subclass);
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
- return -1;
- }
- update_header(fs->f);
- return 0;
-}
-
-static int au_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- off_t min, max, cur;
- long offset = 0, samples;
-
- samples = sample_offset;
- min = AU_HEADER_SIZE;
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
- if (whence == SEEK_SET)
- offset = samples + min;
- else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = samples + cur;
- else if (whence == SEEK_END)
- offset = max - samples;
- if (whence != SEEK_FORCECUR) {
- offset = (offset > max) ? max : offset;
- }
- /* always protect the header space. */
- offset = (offset < min) ? min : offset;
- return fseek(fs->f, offset, SEEK_SET);
-}
-
-static int au_trunc(struct ast_filestream *fs)
-{
- if (ftruncate(fileno(fs->f), ftell(fs->f)))
- return -1;
- return update_header(fs->f);
-}
-
-static long au_tell(struct ast_filestream *fs)
-{
- off_t offset;
-
- offset = ftell(fs->f);
- return offset - AU_HEADER_SIZE;
-}
-
-static char *au_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_ULAW,
- au_open,
- au_rewrite,
- au_write,
- au_seek,
- au_trunc,
- au_tell,
- au_read,
- au_close,
- au_getcomment);
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return localusecnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_g723.c b/1.2-netsec/formats/format_g723.c
deleted file mode 100644
index 2d17d96eb..000000000
--- a/1.2-netsec/formats/format_g723.c
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*!
- * \file
- *
- * \brief Old-style G.723.1 frame/timestamp format.
- *
- * \arg Extensions: g723, g723sf
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/time.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-
-#include "../channels/adtranvofr.h"
-
-
-#define G723_MAX_SIZE 1024
-
-struct ast_filestream {
- /* First entry MUST be reserved for the channel type */
- void *reserved[AST_RESERVED_POINTERS];
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_filestream *next;
- struct ast_frame *fr; /* Frame representation of buf */
- struct timeval orig; /* Original frame time */
- char buf[G723_MAX_SIZE + AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
-};
-
-
-AST_MUTEX_DEFINE_STATIC(g723_lock);
-static int glistcnt = 0;
-
-static char *name = "g723sf";
-static char *desc = "G.723.1 Simple Timestamp File Format";
-static char *exts = "g723|g723sf";
-
-static struct ast_filestream *g723_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g723_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g723 list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr = (struct ast_frame *)tmp->buf;
- tmp->fr->data = tmp->buf + sizeof(struct ast_frame);
- tmp->fr->frametype = AST_FRAME_VOICE;
- tmp->fr->subclass = AST_FORMAT_G723_1;
- /* datalen will vary for each frame */
- tmp->fr->src = name;
- tmp->fr->mallocd = 0;
- glistcnt++;
- ast_mutex_unlock(&g723_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *g723_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g723_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g723 list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&g723_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static struct ast_frame *g723_read(struct ast_filestream *s, int *whennext)
-{
- unsigned short size;
- int res;
- int delay;
- /* Read the delay for the next packet, and schedule again if necessary */
- if (fread(&delay, 1, 4, s->f) == 4)
- delay = ntohl(delay);
- else
- delay = -1;
- if (fread(&size, 1, 2, s->f) != 2) {
- /* Out of data, or the file is no longer valid. In any case
- go ahead and stop the stream */
- return NULL;
- }
- /* Looks like we have a frame to read from here */
- size = ntohs(size);
- if (size > G723_MAX_SIZE - sizeof(struct ast_frame)) {
- ast_log(LOG_WARNING, "Size %d is invalid\n", size);
- /* The file is apparently no longer any good, as we
- shouldn't ever get frames even close to this
- size. */
- return NULL;
- }
- /* Read the data into the buffer */
- s->fr->offset = AST_FRIENDLY_OFFSET;
- s->fr->datalen = size;
- s->fr->data = s->buf + sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET;
- if ((res = fread(s->fr->data, 1, size, s->f)) != size) {
- ast_log(LOG_WARNING, "Short read (%d of %d bytes) (%s)!\n", res, size, strerror(errno));
- return NULL;
- }
-#if 0
- /* Average out frames <= 50 ms */
- if (delay < 50)
- s->fr->timelen = 30;
- else
- s->fr->timelen = delay;
-#else
- s->fr->samples = 240;
-#endif
- *whennext = s->fr->samples;
- return s->fr;
-}
-
-static void g723_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&g723_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g723 list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&g723_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-
-static int g723_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- u_int32_t delay;
- u_int16_t size;
- int res;
- if (fs->fr) {
- ast_log(LOG_WARNING, "Asked to write on a read stream??\n");
- return -1;
- }
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_G723_1) {
- ast_log(LOG_WARNING, "Asked to write non-g723 frame!\n");
- return -1;
- }
- delay = 0;
- if (f->datalen <= 0) {
- ast_log(LOG_WARNING, "Short frame ignored (%d bytes long?)\n", f->datalen);
- return 0;
- }
- if ((res = fwrite(&delay, 1, 4, fs->f)) != 4) {
- ast_log(LOG_WARNING, "Unable to write delay: res=%d (%s)\n", res, strerror(errno));
- return -1;
- }
- size = htons(f->datalen);
- if ((res = fwrite(&size, 1, 2, fs->f)) != 2) {
- ast_log(LOG_WARNING, "Unable to write size: res=%d (%s)\n", res, strerror(errno));
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Unable to write frame: res=%d (%s)\n", res, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int g723_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- return -1;
-}
-
-static int g723_trunc(struct ast_filestream *fs)
-{
- /* Truncate file to current length */
- if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0)
- return -1;
- return 0;
-}
-
-static long g723_tell(struct ast_filestream *fs)
-{
- return -1;
-}
-
-static char *g723_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_G723_1,
- g723_open,
- g723_rewrite,
- g723_write,
- g723_seek,
- g723_trunc,
- g723_tell,
- g723_read,
- g723_close,
- g723_getcomment);
-
-
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_g726.c b/1.2-netsec/formats/format_g726.c
deleted file mode 100644
index 717fdaf5b..000000000
--- a/1.2-netsec/formats/format_g726.c
+++ /dev/null
@@ -1,516 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (c) 2004 - 2005, inAccess Networks
- *
- * Michael Manousos <manousos@inaccessnetworks.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*!\file
- *
- * \brief Headerless G.726 (16/24/32/40kbps) data format for Asterisk.
- *
- * File name extensions:
- * \arg 40 kbps: g726-40
- * \arg 32 kbps: g726-32
- * \arg 24 kbps: g726-24
- * \arg 16 kbps: g726-16
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-#define RATE_40 0
-#define RATE_32 1
-#define RATE_24 2
-#define RATE_16 3
-
-/* We can only read/write chunks of FRAME_TIME ms G.726 data */
-#define FRAME_TIME 10 /* 10 ms size */
-
-/* Frame sizes in bytes */
-static int frame_size[4] = {
- FRAME_TIME * 5,
- FRAME_TIME * 4,
- FRAME_TIME * 3,
- FRAME_TIME * 2
-};
-
-struct ast_filestream {
- /* Do not place anything before "reserved" */
- void *reserved[AST_RESERVED_POINTERS];
- /* This is what a filestream means to us */
- FILE *f; /* Open file descriptor */
- int rate; /* RATE_* defines */
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char g726[FRAME_TIME * 5]; /* G.726 encoded voice */
-};
-
-AST_MUTEX_DEFINE_STATIC(g726_lock);
-static int glistcnt = 0;
-
-static char *desc = "Raw G.726 (16/24/32/40kbps) data";
-static char *name40 = "g726-40";
-static char *name32 = "g726-32";
-static char *name24 = "g726-24";
-static char *name16 = "g726-16";
-static char *exts40 = "g726-40";
-static char *exts32 = "g726-32";
-static char *exts24 = "g726-24";
-static char *exts16 = "g726-16";
-
-/*
- * Rate dependant format functions (open, rewrite)
- */
-static struct ast_filestream *g726_40_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g726_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g726 list.\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->rate = RATE_40;
- tmp->fr.data = tmp->g726;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_G726;
- /* datalen will vary for each frame */
- tmp->fr.src = name40;
- tmp->fr.mallocd = 0;
- glistcnt++;
- if (option_debug)
- ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n",
- 40 - tmp->rate * 8);
- ast_mutex_unlock(&g726_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *g726_32_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g726_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g726 list.\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->rate = RATE_32;
- tmp->fr.data = tmp->g726;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_G726;
- /* datalen will vary for each frame */
- tmp->fr.src = name32;
- tmp->fr.mallocd = 0;
- glistcnt++;
- if (option_debug)
- ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n",
- 40 - tmp->rate * 8);
- ast_mutex_unlock(&g726_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *g726_24_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g726_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g726 list.\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->rate = RATE_24;
- tmp->fr.data = tmp->g726;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_G726;
- /* datalen will vary for each frame */
- tmp->fr.src = name24;
- tmp->fr.mallocd = 0;
- glistcnt++;
- if (option_debug)
- ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n",
- 40 - tmp->rate * 8);
- ast_mutex_unlock(&g726_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *g726_16_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g726_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g726 list.\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->rate = RATE_16;
- tmp->fr.data = tmp->g726;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_G726;
- /* datalen will vary for each frame */
- tmp->fr.src = name16;
- tmp->fr.mallocd = 0;
- glistcnt++;
- if (option_debug)
- ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n",
- 40 - tmp->rate * 8);
- ast_mutex_unlock(&g726_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *g726_40_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g726_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g726 list.\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->rate = RATE_40;
- glistcnt++;
- if (option_debug)
- ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n",
- 40 - tmp->rate * 8);
- ast_mutex_unlock(&g726_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static struct ast_filestream *g726_32_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g726_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g726 list.\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->rate = RATE_32;
- glistcnt++;
- if (option_debug)
- ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n",
- 40 - tmp->rate * 8);
- ast_mutex_unlock(&g726_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static struct ast_filestream *g726_24_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g726_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g726 list.\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->rate = RATE_24;
- glistcnt++;
- if (option_debug)
- ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n",
- 40 - tmp->rate * 8);
- ast_mutex_unlock(&g726_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static struct ast_filestream *g726_16_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g726_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g726 list.\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->rate = RATE_16;
- glistcnt++;
- if (option_debug)
- ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n",
- 40 - tmp->rate * 8);
- ast_mutex_unlock(&g726_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-/*
- * Rate independent format functions (close, read, write)
- */
-static void g726_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&g726_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g726 list.\n");
- return;
- }
- glistcnt--;
- if (option_debug)
- ast_log(LOG_DEBUG, "Closed filestream G.726-%dk.\n", 40 - s->rate * 8);
- ast_mutex_unlock(&g726_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *g726_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- /* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_G726;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.samples = 8 * FRAME_TIME;
- s->fr.datalen = frame_size[s->rate];
- s->fr.mallocd = 0;
- s->fr.data = s->g726;
- if ((res = fread(s->g726, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
- if (res)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- *whennext = s->fr.samples;
- return &s->fr;
-}
-
-static int g726_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_G726) {
- ast_log(LOG_WARNING, "Asked to write non-G726 frame (%d)!\n",
- f->subclass);
- return -1;
- }
- if (f->datalen % frame_size[fs->rate]) {
- ast_log(LOG_WARNING, "Invalid data length %d, should be multiple of %d\n",
- f->datalen, frame_size[fs->rate]);
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n",
- res, frame_size[fs->rate], strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static char *g726_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-static int g726_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- return -1;
-}
-
-static int g726_trunc(struct ast_filestream *fs)
-{
- return -1;
-}
-
-static long g726_tell(struct ast_filestream *fs)
-{
- return -1;
-}
-
-/*
- * Module interface (load_module, unload_module, usecount, description, key)
- */
-int load_module()
-{
- int res;
-
- res = ast_format_register(name40, exts40, AST_FORMAT_G726,
- g726_40_open,
- g726_40_rewrite,
- g726_write,
- g726_seek,
- g726_trunc,
- g726_tell,
- g726_read,
- g726_close,
- g726_getcomment);
- if (res) {
- ast_log(LOG_WARNING, "Failed to register format %s.\n", name40);
- return(-1);
- }
- res = ast_format_register(name32, exts32, AST_FORMAT_G726,
- g726_32_open,
- g726_32_rewrite,
- g726_write,
- g726_seek,
- g726_trunc,
- g726_tell,
- g726_read,
- g726_close,
- g726_getcomment);
- if (res) {
- ast_log(LOG_WARNING, "Failed to register format %s.\n", name32);
- return(-1);
- }
- res = ast_format_register(name24, exts24, AST_FORMAT_G726,
- g726_24_open,
- g726_24_rewrite,
- g726_write,
- g726_seek,
- g726_trunc,
- g726_tell,
- g726_read,
- g726_close,
- g726_getcomment);
- if (res) {
- ast_log(LOG_WARNING, "Failed to register format %s.\n", name24);
- return(-1);
- }
- res = ast_format_register(name16, exts16, AST_FORMAT_G726,
- g726_16_open,
- g726_16_rewrite,
- g726_write,
- g726_seek,
- g726_trunc,
- g726_tell,
- g726_read,
- g726_close,
- g726_getcomment);
- if (res) {
- ast_log(LOG_WARNING, "Failed to register format %s.\n", name16);
- return(-1);
- }
- return(0);
-}
-
-int unload_module()
-{
- int res;
-
- res = ast_format_unregister(name16);
- if (res) {
- ast_log(LOG_WARNING, "Failed to unregister format %s.\n", name16);
- return(-1);
- }
- res = ast_format_unregister(name24);
- if (res) {
- ast_log(LOG_WARNING, "Failed to unregister format %s.\n", name24);
- return(-1);
- }
- res = ast_format_unregister(name32);
- if (res) {
- ast_log(LOG_WARNING, "Failed to unregister format %s.\n", name32);
- return(-1);
- }
- res = ast_format_unregister(name40);
- if (res) {
- ast_log(LOG_WARNING, "Failed to unregister format %s.\n", name40);
- return(-1);
- }
- return(0);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/formats/format_g729.c b/1.2-netsec/formats/format_g729.c
deleted file mode 100644
index 6afe539da..000000000
--- a/1.2-netsec/formats/format_g729.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Save to raw, headerless G729 data.
- * \note This is not an encoder/decoder. The codec fo g729 is only
- * available with a commercial license from Digium, due to patent
- * restrictions. Check http://www.digium.com for information.
- * \arg Extensions: g729
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-/* Some Ideas for this code came from makeg729e.c by Jeffrey Chilton */
-
-/* Portions of the conversion code are by guido@sienanet.it */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* Believe it or not, we must decode/recode to account for the
- weird MS format */
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char g729[20]; /* Two Real G729 Frames */
-};
-
-
-AST_MUTEX_DEFINE_STATIC(g729_lock);
-static int glistcnt = 0;
-
-static char *name = "g729";
-static char *desc = "Raw G729 data";
-static char *exts = "g729";
-
-static struct ast_filestream *g729_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g729_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g729 list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->g729;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_G729A;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- glistcnt++;
- ast_mutex_unlock(&g729_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *g729_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&g729_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g729 list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&g729_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void g729_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&g729_lock)) {
- ast_log(LOG_WARNING, "Unable to lock g729 list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&g729_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *g729_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- /* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_G729A;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.samples = 160;
- s->fr.datalen = 20;
- s->fr.mallocd = 0;
- s->fr.data = s->g729;
- if ((res = fread(s->g729, 1, 20, s->f)) != 20) {
- if (res && (res != 10))
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- *whennext = s->fr.samples;
- return &s->fr;
-}
-
-static int g729_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_G729A) {
- ast_log(LOG_WARNING, "Asked to write non-G729 frame (%d)!\n", f->subclass);
- return -1;
- }
- if (f->datalen % 10) {
- ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 10\n", f->datalen);
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/10): %s\n", res, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static char *g729_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-static int g729_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- long bytes;
- off_t min,cur,max,offset=0;
- min = 0;
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
-
- bytes = 20 * (sample_offset / 160);
- if (whence == SEEK_SET)
- offset = bytes;
- else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = cur + bytes;
- else if (whence == SEEK_END)
- offset = max - bytes;
- if (whence != SEEK_FORCECUR) {
- offset = (offset > max)?max:offset;
- }
- /* protect against seeking beyond begining. */
- offset = (offset < min)?min:offset;
- if (fseek(fs->f, offset, SEEK_SET) < 0)
- return -1;
- return 0;
-}
-
-static int g729_trunc(struct ast_filestream *fs)
-{
- /* Truncate file to current length */
- if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0)
- return -1;
- return 0;
-}
-
-static long g729_tell(struct ast_filestream *fs)
-{
- off_t offset;
- offset = ftell(fs->f);
- return (offset/20)*160;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_G729A,
- g729_open,
- g729_rewrite,
- g729_write,
- g729_seek,
- g729_trunc,
- g729_tell,
- g729_read,
- g729_close,
- g729_getcomment);
-
-
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_gsm.c b/1.2-netsec/formats/format_gsm.c
deleted file mode 100644
index 176c73a97..000000000
--- a/1.2-netsec/formats/format_gsm.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Save to raw, headerless GSM data.
- * \arg File name extension: gsm
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-#include "msgsm.h"
-
-/* Some Ideas for this code came from makegsme.c by Jeffrey Chilton */
-
-/* Portions of the conversion code are by guido@sienanet.it */
-
-/* silent gsm frame */
-/* begin binary data: */
-char gsm_silence[] = /* 33 */
-{0xD8,0x20,0xA2,0xE1,0x5A,0x50,0x00,0x49,0x24,0x92,0x49,0x24,0x50,0x00,0x49
-,0x24,0x92,0x49,0x24,0x50,0x00,0x49,0x24,0x92,0x49,0x24,0x50,0x00,0x49,0x24
-,0x92,0x49,0x24};
-/* end binary data. size = 33 bytes */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* Believe it or not, we must decode/recode to account for the
- weird MS format */
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char gsm[66]; /* Two Real GSM Frames */
-};
-
-
-AST_MUTEX_DEFINE_STATIC(gsm_lock);
-static int glistcnt = 0;
-
-static char *name = "gsm";
-static char *desc = "Raw GSM data";
-static char *exts = "gsm";
-
-static struct ast_filestream *gsm_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&gsm_lock)) {
- ast_log(LOG_WARNING, "Unable to lock gsm list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->gsm;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_GSM;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- glistcnt++;
- ast_mutex_unlock(&gsm_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *gsm_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&gsm_lock)) {
- ast_log(LOG_WARNING, "Unable to lock gsm list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&gsm_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void gsm_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&gsm_lock)) {
- ast_log(LOG_WARNING, "Unable to lock gsm list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&gsm_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
-}
-
-static struct ast_frame *gsm_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_GSM;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.samples = 160;
- s->fr.datalen = 33;
- s->fr.mallocd = 0;
- s->fr.data = s->gsm;
- if ((res = fread(s->gsm, 1, 33, s->f)) != 33) {
- if (res)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- *whennext = 160;
- return &s->fr;
-}
-
-static int gsm_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
- unsigned char gsm[66];
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_GSM) {
- ast_log(LOG_WARNING, "Asked to write non-GSM frame (%d)!\n", f->subclass);
- return -1;
- }
- if (!(f->datalen % 65)) {
- /* This is in MSGSM format, need to be converted */
- int len=0;
- while(len < f->datalen) {
- conv65(f->data + len, gsm);
- if ((res = fwrite(gsm, 1, 66, fs->f)) != 66) {
- ast_log(LOG_WARNING, "Bad write (%d/66): %s\n", res, strerror(errno));
- return -1;
- }
- len += 65;
- }
- } else {
- if (f->datalen % 33) {
- ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 33\n", f->datalen);
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/33): %s\n", res, strerror(errno));
- return -1;
- }
- }
- return 0;
-}
-
-static int gsm_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- off_t offset=0,min,cur,max,distance;
-
- min = 0;
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
- /* have to fudge to frame here, so not fully to sample */
- distance = (sample_offset/160) * 33;
- if(whence == SEEK_SET)
- offset = distance;
- else if(whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = distance + cur;
- else if(whence == SEEK_END)
- offset = max - distance;
- /* Always protect against seeking past the begining. */
- offset = (offset < min)?min:offset;
- if (whence != SEEK_FORCECUR) {
- offset = (offset > max)?max:offset;
- } else if (offset > max) {
- int i;
- fseek(fs->f, 0, SEEK_END);
- for (i=0; i< (offset - max) / 33; i++) {
- fwrite(gsm_silence, 1, 33, fs->f);
- }
- }
- return fseek(fs->f, offset, SEEK_SET);
-}
-
-static int gsm_trunc(struct ast_filestream *fs)
-{
- return ftruncate(fileno(fs->f), ftell(fs->f));
-}
-
-static long gsm_tell(struct ast_filestream *fs)
-{
- off_t offset;
- offset = ftell(fs->f);
- return (offset/33)*160;
-}
-
-static char *gsm_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_GSM,
- gsm_open,
- gsm_rewrite,
- gsm_write,
- gsm_seek,
- gsm_trunc,
- gsm_tell,
- gsm_read,
- gsm_close,
- gsm_getcomment);
-
-
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_h263.c b/1.2-netsec/formats/format_h263.c
deleted file mode 100644
index ccba23d6d..000000000
--- a/1.2-netsec/formats/format_h263.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Save to raw, headerless h263 data.
- * \arg File name extension: h263
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-/* Some Ideas for this code came from makeh263e.c by Jeffrey Chilton */
-
-/* Portions of the conversion code are by guido@sienanet.it */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* Believe it or not, we must decode/recode to account for the
- weird MS format */
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- unsigned int lastts;
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char h263[4096]; /* Two Real h263 Frames */
-};
-
-
-AST_MUTEX_DEFINE_STATIC(h263_lock);
-static int glistcnt = 0;
-
-static char *name = "h263";
-static char *desc = "Raw h263 data";
-static char *exts = "h263";
-
-static struct ast_filestream *h263_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- unsigned int ts;
- int res;
- if ((res = fread(&ts, 1, sizeof(ts), f)) < sizeof(ts)) {
- ast_log(LOG_WARNING, "Empty file!\n");
- return NULL;
- }
-
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&h263_lock)) {
- ast_log(LOG_WARNING, "Unable to lock h263 list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->h263;
- tmp->fr.frametype = AST_FRAME_VIDEO;
- tmp->fr.subclass = AST_FORMAT_H263;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- glistcnt++;
- ast_mutex_unlock(&h263_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *h263_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&h263_lock)) {
- ast_log(LOG_WARNING, "Unable to lock h263 list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&h263_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void h263_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&h263_lock)) {
- ast_log(LOG_WARNING, "Unable to lock h263 list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&h263_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *h263_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- int mark=0;
- unsigned short len;
- unsigned int ts;
- /* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VIDEO;
- s->fr.subclass = AST_FORMAT_H263;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.mallocd = 0;
- s->fr.data = s->h263;
- if ((res = fread(&len, 1, sizeof(len), s->f)) < 1) {
- return NULL;
- }
- len = ntohs(len);
- if (len & 0x8000) {
- mark = 1;
- }
- len &= 0x7fff;
- if (len > sizeof(s->h263)) {
- ast_log(LOG_WARNING, "Length %d is too long\n", len);
- }
- if ((res = fread(s->h263, 1, len, s->f)) != len) {
- if (res)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- s->fr.samples = s->lastts;
- s->fr.datalen = len;
- s->fr.subclass |= mark;
- s->fr.delivery.tv_sec = 0;
- s->fr.delivery.tv_usec = 0;
- if ((res = fread(&ts, 1, sizeof(ts), s->f)) == sizeof(ts)) {
- s->lastts = ntohl(ts);
- *whennext = s->lastts * 4/45;
- } else
- *whennext = 0;
- return &s->fr;
-}
-
-static int h263_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
- unsigned int ts;
- unsigned short len;
- int subclass;
- int mark=0;
- if (f->frametype != AST_FRAME_VIDEO) {
- ast_log(LOG_WARNING, "Asked to write non-video frame!\n");
- return -1;
- }
- subclass = f->subclass;
- if (subclass & 0x1)
- mark=0x8000;
- subclass &= ~0x1;
- if (subclass != AST_FORMAT_H263) {
- ast_log(LOG_WARNING, "Asked to write non-h263 frame (%d)!\n", f->subclass);
- return -1;
- }
- ts = htonl(f->samples);
- if ((res = fwrite(&ts, 1, sizeof(ts), fs->f)) != sizeof(ts)) {
- ast_log(LOG_WARNING, "Bad write (%d/4): %s\n", res, strerror(errno));
- return -1;
- }
- len = htons(f->datalen | mark);
- if ((res = fwrite(&len, 1, sizeof(len), fs->f)) != sizeof(len)) {
- ast_log(LOG_WARNING, "Bad write (%d/2): %s\n", res, strerror(errno));
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static char *h263_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-static int h263_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- /* No way Jose */
- return -1;
-}
-
-static int h263_trunc(struct ast_filestream *fs)
-{
- /* Truncate file to current length */
- if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0)
- return -1;
- return 0;
-}
-
-static long h263_tell(struct ast_filestream *fs)
-{
- /* XXX This is totally bogus XXX */
- off_t offset;
- offset = ftell(fs->f);
- return (offset/20)*160;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_H263,
- h263_open,
- h263_rewrite,
- h263_write,
- h263_seek,
- h263_trunc,
- h263_tell,
- h263_read,
- h263_close,
- h263_getcomment);
-
-
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_ilbc.c b/1.2-netsec/formats/format_ilbc.c
deleted file mode 100644
index cbe017f66..000000000
--- a/1.2-netsec/formats/format_ilbc.c
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Brian K. West <brian@bkw.org>
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Save to raw, headerless iLBC data.
- * \arg File name extension: ilbc
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-/* Some Ideas for this code came from makeg729e.c by Jeffrey Chilton */
-
-/* Portions of the conversion code are by guido@sienanet.it */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* Believe it or not, we must decode/recode to account for the
- weird MS format */
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char ilbc[50]; /* One Real iLBC Frame */
-};
-
-
-AST_MUTEX_DEFINE_STATIC(ilbc_lock);
-static int glistcnt = 0;
-
-static char *name = "iLBC";
-static char *desc = "Raw iLBC data";
-static char *exts = "ilbc";
-
-static struct ast_filestream *ilbc_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&ilbc_lock)) {
- ast_log(LOG_WARNING, "Unable to lock ilbc list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->ilbc;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_ILBC;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- glistcnt++;
- ast_mutex_unlock(&ilbc_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *ilbc_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&ilbc_lock)) {
- ast_log(LOG_WARNING, "Unable to lock ilbc list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&ilbc_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void ilbc_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&ilbc_lock)) {
- ast_log(LOG_WARNING, "Unable to lock ilbc list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&ilbc_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *ilbc_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- /* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_ILBC;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.samples = 240;
- s->fr.datalen = 50;
- s->fr.mallocd = 0;
- s->fr.data = s->ilbc;
- if ((res = fread(s->ilbc, 1, 50, s->f)) != 50) {
- if (res)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- *whennext = s->fr.samples;
- return &s->fr;
-}
-
-static int ilbc_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_ILBC) {
- ast_log(LOG_WARNING, "Asked to write non-iLBC frame (%d)!\n", f->subclass);
- return -1;
- }
- if (f->datalen % 50) {
- ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 50\n", f->datalen);
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/50): %s\n", res, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static char *ilbc_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-static int ilbc_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- long bytes;
- off_t min,cur,max,offset=0;
- min = 0;
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
-
- bytes = 50 * (sample_offset / 240);
- if (whence == SEEK_SET)
- offset = bytes;
- else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = cur + bytes;
- else if (whence == SEEK_END)
- offset = max - bytes;
- if (whence != SEEK_FORCECUR) {
- offset = (offset > max)?max:offset;
- }
- /* protect against seeking beyond begining. */
- offset = (offset < min)?min:offset;
- if (fseek(fs->f, offset, SEEK_SET) < 0)
- return -1;
- return 0;
-}
-
-static int ilbc_trunc(struct ast_filestream *fs)
-{
- /* Truncate file to current length */
- if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0)
- return -1;
- return 0;
-}
-
-static long ilbc_tell(struct ast_filestream *fs)
-{
- off_t offset;
- offset = ftell(fs->f);
- return (offset/50)*240;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_ILBC,
- ilbc_open,
- ilbc_rewrite,
- ilbc_write,
- ilbc_seek,
- ilbc_trunc,
- ilbc_tell,
- ilbc_read,
- ilbc_close,
- ilbc_getcomment);
-
-
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_jpeg.c b/1.2-netsec/formats/format_jpeg.c
deleted file mode 100644
index d71aeec80..000000000
--- a/1.2-netsec/formats/format_jpeg.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief JPEG File format support.
- *
- * \arg File name extension: jpeg, jpg
- * \ingroup formats
- */
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/image.h"
-#include "asterisk/lock.h"
-#include "asterisk/endian.h"
-
-static char *desc = "JPEG (Joint Picture Experts Group) Image Format";
-
-
-static struct ast_frame *jpeg_read_image(int fd, int len)
-{
- struct ast_frame fr;
- int res;
- char buf[65536];
- if (len > sizeof(buf)) {
- ast_log(LOG_WARNING, "JPEG image too large to read\n");
- return NULL;
- }
- res = read(fd, buf, len);
- if (res < len) {
- ast_log(LOG_WARNING, "Only read %d of %d bytes: %s\n", res, len, strerror(errno));
- }
- memset(&fr, 0, sizeof(fr));
- fr.frametype = AST_FRAME_IMAGE;
- fr.subclass = AST_FORMAT_JPEG;
- fr.data = buf;
- fr.src = "JPEG Read";
- fr.datalen = len;
- return ast_frisolate(&fr);
-}
-
-static int jpeg_identify(int fd)
-{
- char buf[10];
- int res;
- res = read(fd, buf, sizeof(buf));
- if (res < sizeof(buf))
- return 0;
- if (memcmp(buf + 6, "JFIF", 4))
- return 0;
- return 1;
-}
-
-static int jpeg_write_image(int fd, struct ast_frame *fr)
-{
- int res=0;
- if (fr->frametype != AST_FRAME_IMAGE) {
- ast_log(LOG_WARNING, "Not an image\n");
- return -1;
- }
- if (fr->subclass != AST_FORMAT_JPEG) {
- ast_log(LOG_WARNING, "Not a jpeg image\n");
- return -1;
- }
- if (fr->datalen) {
- res = write(fd, fr->data, fr->datalen);
- if (res != fr->datalen) {
- ast_log(LOG_WARNING, "Only wrote %d of %d bytes: %s\n", res, fr->datalen, strerror(errno));
- return -1;
- }
- }
- return res;
-}
-
-static struct ast_imager jpeg_format = {
- "jpg",
- "JPEG (Joint Picture Experts Group)",
- "jpg|jpeg",
- AST_FORMAT_JPEG,
- jpeg_read_image,
- jpeg_identify,
- jpeg_write_image,
-};
-
-int load_module()
-{
- return ast_image_register(&jpeg_format);
-}
-
-int unload_module()
-{
- ast_image_unregister(&jpeg_format);
- return 0;
-}
-
-int usecount()
-{
- /* We never really have any users */
- return 0;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_ogg_vorbis.c b/1.2-netsec/formats/format_ogg_vorbis.c
deleted file mode 100644
index ffee9ed76..000000000
--- a/1.2-netsec/formats/format_ogg_vorbis.c
+++ /dev/null
@@ -1,677 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Jeff Ollie
- *
- * 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 OGG/Vorbis streams.
- * \arg File name extension: ogg
- * \ingroup formats
- */
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-
-#include <vorbis/codec.h>
-#include <vorbis/vorbisenc.h>
-
-#ifdef _WIN32
-#include <io.h>
-#include <fcntl.h>
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-
-#define SAMPLES_MAX 160
-#define BLOCK_SIZE 4096
-
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
-
- FILE *f;
-
- /* structures for handling the Ogg container */
- ogg_sync_state oy;
- ogg_stream_state os;
- ogg_page og;
- ogg_packet op;
-
- /* structures for handling Vorbis audio data */
- vorbis_info vi;
- vorbis_comment vc;
- vorbis_dsp_state vd;
- vorbis_block vb;
-
- /*! \brief Indicates whether this filestream is set up for reading or writing. */
- int writing;
-
- /*! \brief Indicates whether an End of Stream condition has been detected. */
- int eos;
-
- /*! \brief Buffer to hold audio data. */
- short buffer[SAMPLES_MAX];
-
- /*! \brief Asterisk frame object. */
- struct ast_frame fr;
- char waste[AST_FRIENDLY_OFFSET];
- char empty;
-};
-
-AST_MUTEX_DEFINE_STATIC(ogg_vorbis_lock);
-static int glistcnt = 0;
-
-static char *name = "ogg_vorbis";
-static char *desc = "OGG/Vorbis audio";
-static char *exts = "ogg";
-
-/*!
- * \brief Create a new OGG/Vorbis filestream and set it up for reading.
- * \param f File that points to on disk storage of the OGG/Vorbis data.
- * \return The new filestream.
- */
-static struct ast_filestream *ogg_vorbis_open(FILE *f)
-{
- int i;
- int bytes;
- int result;
- char **ptr;
- char *buffer;
-
- struct ast_filestream *tmp;
-
- if((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
-
- tmp->writing = 0;
- tmp->f = f;
-
- ogg_sync_init(&tmp->oy);
-
- buffer = ogg_sync_buffer(&tmp->oy, BLOCK_SIZE);
- bytes = fread(buffer, 1, BLOCK_SIZE, f);
- ogg_sync_wrote(&tmp->oy, bytes);
-
- result = ogg_sync_pageout(&tmp->oy, &tmp->og);
- if(result != 1) {
- if(bytes < BLOCK_SIZE) {
- ast_log(LOG_ERROR, "Run out of data...\n");
- } else {
- ast_log(LOG_ERROR, "Input does not appear to be an Ogg bitstream.\n");
- }
- fclose(f);
- ogg_sync_clear(&tmp->oy);
- free(tmp);
- return NULL;
- }
-
- ogg_stream_init(&tmp->os, ogg_page_serialno(&tmp->og));
- vorbis_info_init(&tmp->vi);
- vorbis_comment_init(&tmp->vc);
-
- if(ogg_stream_pagein(&tmp->os, &tmp->og) < 0) {
- ast_log(LOG_ERROR, "Error reading first page of Ogg bitstream data.\n");
- fclose(f);
- ogg_stream_clear(&tmp->os);
- vorbis_comment_clear(&tmp->vc);
- vorbis_info_clear(&tmp->vi);
- ogg_sync_clear(&tmp->oy);
- free(tmp);
- return NULL;
- }
-
- if(ogg_stream_packetout(&tmp->os, &tmp->op) != 1) {
- ast_log(LOG_ERROR, "Error reading initial header packet.\n");
- fclose(f);
- ogg_stream_clear(&tmp->os);
- vorbis_comment_clear(&tmp->vc);
- vorbis_info_clear(&tmp->vi);
- ogg_sync_clear(&tmp->oy);
- free(tmp);
- return NULL;
- }
-
- if(vorbis_synthesis_headerin(&tmp->vi, &tmp->vc, &tmp->op) < 0) {
- ast_log(LOG_ERROR, "This Ogg bitstream does not contain Vorbis audio data.\n");
- fclose(f);
- ogg_stream_clear(&tmp->os);
- vorbis_comment_clear(&tmp->vc);
- vorbis_info_clear(&tmp->vi);
- ogg_sync_clear(&tmp->oy);
- free(tmp);
- return NULL;
- }
-
- i = 0;
- while(i < 2) {
- while(i < 2){
- result = ogg_sync_pageout(&tmp->oy, &tmp->og);
- if(result == 0)
- break;
- if(result == 1) {
- ogg_stream_pagein(&tmp->os, &tmp->og);
- while(i < 2) {
- result = ogg_stream_packetout(&tmp->os,&tmp->op);
- if(result == 0)
- break;
- if(result < 0) {
- ast_log(LOG_ERROR, "Corrupt secondary header. Exiting.\n");
- fclose(f);
- ogg_stream_clear(&tmp->os);
- vorbis_comment_clear(&tmp->vc);
- vorbis_info_clear(&tmp->vi);
- ogg_sync_clear(&tmp->oy);
- free(tmp);
- return NULL;
- }
- vorbis_synthesis_headerin(&tmp->vi, &tmp->vc, &tmp->op);
- i++;
- }
- }
- }
-
- buffer = ogg_sync_buffer(&tmp->oy, BLOCK_SIZE);
- bytes = fread(buffer, 1, BLOCK_SIZE, f);
- if(bytes == 0 && i < 2) {
- ast_log(LOG_ERROR, "End of file before finding all Vorbis headers!\n");
- fclose(f);
- ogg_stream_clear(&tmp->os);
- vorbis_comment_clear(&tmp->vc);
- vorbis_info_clear(&tmp->vi);
- ogg_sync_clear(&tmp->oy);
- free(tmp);
- return NULL;
- }
- ogg_sync_wrote(&tmp->oy, bytes);
- }
-
- ptr = tmp->vc.user_comments;
- while(*ptr){
- ast_log(LOG_DEBUG, "OGG/Vorbis comment: %s\n", *ptr);
- ++ptr;
- }
- ast_log(LOG_DEBUG, "OGG/Vorbis bitstream is %d channel, %ldHz\n", tmp->vi.channels, tmp->vi.rate);
- ast_log(LOG_DEBUG, "OGG/Vorbis file encoded by: %s\n", tmp->vc.vendor);
-
- if(tmp->vi.channels != 1) {
- ast_log(LOG_ERROR, "Only monophonic OGG/Vorbis files are currently supported!\n");
- ogg_stream_clear(&tmp->os);
- vorbis_comment_clear(&tmp->vc);
- vorbis_info_clear(&tmp->vi);
- ogg_sync_clear(&tmp->oy);
- free(tmp);
- return NULL;
- }
-
-
- if(tmp->vi.rate != 8000) {
- ast_log(LOG_ERROR, "Only 8000Hz OGG/Vorbis files are currently supported!\n");
- fclose(f);
- ogg_stream_clear(&tmp->os);
- vorbis_block_clear(&tmp->vb);
- vorbis_dsp_clear(&tmp->vd);
- vorbis_comment_clear(&tmp->vc);
- vorbis_info_clear(&tmp->vi);
- ogg_sync_clear(&tmp->oy);
- free(tmp);
- return NULL;
- }
-
- vorbis_synthesis_init(&tmp->vd, &tmp->vi);
- vorbis_block_init(&tmp->vd, &tmp->vb);
-
- if(ast_mutex_lock(&ogg_vorbis_lock)) {
- ast_log(LOG_WARNING, "Unable to lock ogg_vorbis list\n");
- fclose(f);
- ogg_stream_clear(&tmp->os);
- vorbis_block_clear(&tmp->vb);
- vorbis_dsp_clear(&tmp->vd);
- vorbis_comment_clear(&tmp->vc);
- vorbis_info_clear(&tmp->vi);
- ogg_sync_clear(&tmp->oy);
- free(tmp);
- return NULL;
- }
- glistcnt++;
- ast_mutex_unlock(&ogg_vorbis_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-/*!
- * \brief Create a new OGG/Vorbis filestream and set it up for writing.
- * \param f File pointer that points to on-disk storage.
- * \param comment Comment that should be embedded in the OGG/Vorbis file.
- * \return A new filestream.
- */
-static struct ast_filestream *ogg_vorbis_rewrite(FILE *f, const char *comment)
-{
- ogg_packet header;
- ogg_packet header_comm;
- ogg_packet header_code;
-
- struct ast_filestream *tmp;
-
- if((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
-
- tmp->writing = 1;
- tmp->f = f;
-
- vorbis_info_init(&tmp->vi);
-
- if(vorbis_encode_init_vbr(&tmp->vi, 1, 8000, 0.4)) {
- ast_log(LOG_ERROR, "Unable to initialize Vorbis encoder!\n");
- free(tmp);
- return NULL;
- }
-
- vorbis_comment_init(&tmp->vc);
- vorbis_comment_add_tag(&tmp->vc, "ENCODER", "Asterisk PBX");
- if(comment)
- vorbis_comment_add_tag(&tmp->vc, "COMMENT", (char *) comment);
-
- vorbis_analysis_init(&tmp->vd, &tmp->vi);
- vorbis_block_init(&tmp->vd, &tmp->vb);
-
- ogg_stream_init(&tmp->os, rand());
-
- vorbis_analysis_headerout(&tmp->vd, &tmp->vc, &header, &header_comm, &header_code);
- ogg_stream_packetin(&tmp->os, &header);
- ogg_stream_packetin(&tmp->os, &header_comm);
- ogg_stream_packetin(&tmp->os, &header_code);
-
- while(!tmp->eos) {
- if(ogg_stream_flush(&tmp->os, &tmp->og) == 0)
- break;
- fwrite(tmp->og.header, 1, tmp->og.header_len, tmp->f);
- fwrite(tmp->og.body, 1, tmp->og.body_len, tmp->f);
- if(ogg_page_eos(&tmp->og))
- tmp->eos = 1;
- }
-
- if(ast_mutex_lock(&ogg_vorbis_lock)) {
- ast_log(LOG_WARNING, "Unable to lock ogg_vorbis list\n");
- fclose(f);
- ogg_stream_clear(&tmp->os);
- vorbis_block_clear(&tmp->vb);
- vorbis_dsp_clear(&tmp->vd);
- vorbis_comment_clear(&tmp->vc);
- vorbis_info_clear(&tmp->vi);
- free(tmp);
- return NULL;
- }
- glistcnt++;
- ast_mutex_unlock(&ogg_vorbis_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-/*!
- * \brief Write out any pending encoded data.
- * \param s A OGG/Vorbis filestream.
- */
-static void write_stream(struct ast_filestream *s)
-{
- while (vorbis_analysis_blockout(&s->vd, &s->vb) == 1) {
- vorbis_analysis(&s->vb, NULL);
- vorbis_bitrate_addblock(&s->vb);
-
- while (vorbis_bitrate_flushpacket(&s->vd, &s->op)) {
- ogg_stream_packetin(&s->os, &s->op);
- while (!s->eos) {
- if(ogg_stream_pageout(&s->os, &s->og) == 0) {
- break;
- }
- fwrite(s->og.header, 1, s->og.header_len, s->f);
- fwrite(s->og.body, 1, s->og.body_len, s->f);
- if(ogg_page_eos(&s->og)) {
- s->eos = 1;
- }
- }
- }
- }
-}
-
-/*!
- * \brief Write audio data from a frame to an OGG/Vorbis filestream.
- * \param s A OGG/Vorbis filestream.
- * \param f An frame containing audio to be written to the filestream.
- * \return -1 ifthere was an error, 0 on success.
- */
-static int ogg_vorbis_write(struct ast_filestream *s, struct ast_frame *f)
-{
- int i;
- float **buffer;
- short *data;
-
- if(!s->writing) {
- ast_log(LOG_ERROR, "This stream is not set up for writing!\n");
- return -1;
- }
-
- if(f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if(f->subclass != AST_FORMAT_SLINEAR) {
- ast_log(LOG_WARNING, "Asked to write non-SLINEAR frame (%d)!\n", f->subclass);
- return -1;
- }
- if(!f->datalen)
- return -1;
-
- data = (short *) f->data;
-
- buffer = vorbis_analysis_buffer(&s->vd, f->samples);
-
- for (i = 0; i < f->samples; i++) {
- buffer[0][i] = data[i]/32768.f;
- }
-
- vorbis_analysis_wrote(&s->vd, f->samples);
-
- write_stream(s);
-
- return 0;
-}
-
-/*!
- * \brief Close a OGG/Vorbis filestream.
- * \param s A OGG/Vorbis filestream.
- */
-static void ogg_vorbis_close(struct ast_filestream *s)
-{
- if(ast_mutex_lock(&ogg_vorbis_lock)) {
- ast_log(LOG_WARNING, "Unable to lock ogg_vorbis list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&ogg_vorbis_lock);
- ast_update_use_count();
-
- if(s->writing) {
- /* Tell the Vorbis encoder that the stream is finished
- * and write out the rest of the data */
- vorbis_analysis_wrote(&s->vd, 0);
- write_stream(s);
- }
-
- ogg_stream_clear(&s->os);
- vorbis_block_clear(&s->vb);
- vorbis_dsp_clear(&s->vd);
- vorbis_comment_clear(&s->vc);
- vorbis_info_clear(&s->vi);
-
- if(s->writing) {
- ogg_sync_clear(&s->oy);
- }
-
- fclose(s->f);
- free(s);
-}
-
-/*!
- * \brief Get audio data.
- * \param s An OGG/Vorbis filestream.
- * \param pcm Pointer to a buffere to store audio data in.
- */
-
-static int read_samples(struct ast_filestream *s, float ***pcm)
-{
- int samples_in;
- int result;
- char *buffer;
- int bytes;
-
- while (1) {
- samples_in = vorbis_synthesis_pcmout(&s->vd, pcm);
- if(samples_in > 0) {
- return samples_in;
- }
-
- /* The Vorbis decoder needs more data... */
- /* See ifOGG has any packets in the current page for the Vorbis decoder. */
- result = ogg_stream_packetout(&s->os, &s->op);
- if(result > 0) {
- /* Yes OGG had some more packets for the Vorbis decoder. */
- if(vorbis_synthesis(&s->vb, &s->op) == 0) {
- vorbis_synthesis_blockin(&s->vd, &s->vb);
- }
-
- continue;
- }
-
- if(result < 0)
- ast_log(LOG_WARNING, "Corrupt or missing data at this page position; continuing...\n");
-
- /* No more packets left in the current page... */
-
- if(s->eos) {
- /* No more pages left in the stream */
- return -1;
- }
-
- while (!s->eos) {
- /* See ifOGG has any pages in it's internal buffers */
- result = ogg_sync_pageout(&s->oy, &s->og);
- if(result > 0) {
- /* Yes, OGG has more pages in it's internal buffers,
- add the page to the stream state */
- result = ogg_stream_pagein(&s->os, &s->og);
- if(result == 0) {
- /* Yes, got a new,valid page */
- if(ogg_page_eos(&s->og)) {
- s->eos = 1;
- }
- break;
- }
- ast_log(LOG_WARNING, "Invalid page in the bitstream; continuing...\n");
- }
-
- if(result < 0)
- ast_log(LOG_WARNING, "Corrupt or missing data in bitstream; continuing...\n");
-
- /* No, we need to read more data from the file descrptor */
- /* get a buffer from OGG to read the data into */
- buffer = ogg_sync_buffer(&s->oy, BLOCK_SIZE);
- /* read more data from the file descriptor */
- bytes = fread(buffer, 1, BLOCK_SIZE, s->f);
- /* Tell OGG how many bytes we actually read into the buffer */
- ogg_sync_wrote(&s->oy, bytes);
- if(bytes == 0) {
- s->eos = 1;
- }
- }
- }
-}
-
-/*!
- * \brief Read a frame full of audio data from the filestream.
- * \param s The filestream.
- * \param whennext Number of sample times to schedule the next call.
- * \return A pointer to a frame containing audio data or NULL ifthere is no more audio data.
- */
-static struct ast_frame *ogg_vorbis_read(struct ast_filestream *s, int *whennext)
-{
- int clipflag = 0;
- int i;
- int j;
- float **pcm;
- float *mono;
- double accumulator[SAMPLES_MAX];
- int val;
- int samples_in;
- int samples_out = 0;
-
- while (1) {
- /* See ifwe have filled up an audio frame yet */
- if(samples_out == SAMPLES_MAX)
- break;
-
- /* See ifVorbis decoder has some audio data for us ... */
- samples_in = read_samples(s, &pcm);
- if(samples_in <= 0)
- break;
-
- /* Got some audio data from Vorbis... */
- /* Convert the float audio data to 16-bit signed linear */
-
- clipflag = 0;
-
- samples_in = samples_in < (SAMPLES_MAX - samples_out) ? samples_in : (SAMPLES_MAX - samples_out);
-
- for(j = 0; j < samples_in; j++)
- accumulator[j] = 0.0;
-
- for(i = 0; i < s->vi.channels; i++) {
- mono = pcm[i];
- for (j = 0; j < samples_in; j++) {
- accumulator[j] += mono[j];
- }
- }
-
- for (j = 0; j < samples_in; j++) {
- val = accumulator[j] * 32767.0 / s->vi.channels;
- if(val > 32767) {
- val = 32767;
- clipflag = 1;
- }
- if(val < -32768) {
- val = -32768;
- clipflag = 1;
- }
- s->buffer[samples_out + j] = val;
- }
-
- if(clipflag)
- ast_log(LOG_WARNING, "Clipping in frame %ld\n", (long)(s->vd.sequence));
-
- /* Tell the Vorbis decoder how many samples we actually used. */
- vorbis_synthesis_read(&s->vd, samples_in);
- samples_out += samples_in;
- }
-
- if(samples_out > 0) {
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_SLINEAR;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.datalen = samples_out * 2;
- s->fr.data = s->buffer;
- s->fr.src = name;
- s->fr.mallocd = 0;
- s->fr.samples = samples_out;
- *whennext = samples_out;
-
- return &s->fr;
- } else {
- return NULL;
- }
-}
-
-/*!
- * \brief Trucate an OGG/Vorbis filestream.
- * \param s The filestream to truncate.
- * \return 0 on success, -1 on failure.
- */
-
-static int ogg_vorbis_trunc(struct ast_filestream *s)
-{
- ast_log(LOG_WARNING, "Truncation is not supported on OGG/Vorbis streams!\n");
- return -1;
-}
-
-/*!
- * \brief Seek to a specific position in an OGG/Vorbis filestream.
- * \param s The filestream to truncate.
- * \param sample_offset New position for the filestream, measured in 8KHz samples.
- * \param whence Location to measure
- * \return 0 on success, -1 on failure.
- */
-
-static int ogg_vorbis_seek(struct ast_filestream *s, long sample_offset, int whence) {
- ast_log(LOG_WARNING, "Seeking is not supported on OGG/Vorbis streams!\n");
- return -1;
-}
-
-static long ogg_vorbis_tell(struct ast_filestream *s) {
- ast_log(LOG_WARNING, "Telling is not supported on OGG/Vorbis streams!\n");
- return -1;
-}
-
-static char *ogg_vorbis_getcomment(struct ast_filestream *s) {
- ast_log(LOG_WARNING, "Getting comments is not supported on OGG/Vorbis streams!\n");
- return NULL;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_SLINEAR,
- ogg_vorbis_open,
- ogg_vorbis_rewrite,
- ogg_vorbis_write,
- ogg_vorbis_seek,
- ogg_vorbis_trunc,
- ogg_vorbis_tell,
- ogg_vorbis_read,
- ogg_vorbis_close,
- ogg_vorbis_getcomment);
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-/*
-Local Variables:
-mode: C
-c-file-style: "linux"
-indent-tabs-mode: t
-End:
-*/
diff --git a/1.2-netsec/formats/format_pcm.c b/1.2-netsec/formats/format_pcm.c
deleted file mode 100644
index 289038ced..000000000
--- a/1.2-netsec/formats/format_pcm.c
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Flat, binary, ulaw PCM file format.
- * \arg File name extension: pcm, ulaw, ul, mu
- *
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-#include "asterisk/ulaw.h"
-
-#define BUF_SIZE 160 /* 160 samples */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_channel *owner;
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char buf[BUF_SIZE]; /* Output Buffer */
- struct timeval last;
-};
-
-
-AST_MUTEX_DEFINE_STATIC(pcm_lock);
-static int glistcnt = 0;
-
-static char *name = "pcm";
-static char *desc = "Raw uLaw 8khz Audio support (PCM)";
-static char *exts = "pcm|ulaw|ul|mu";
-
-static char ulaw_silence[BUF_SIZE];
-
-static struct ast_filestream *pcm_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&pcm_lock)) {
- ast_log(LOG_WARNING, "Unable to lock pcm list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->buf;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_ULAW;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- glistcnt++;
- ast_mutex_unlock(&pcm_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *pcm_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&pcm_lock)) {
- ast_log(LOG_WARNING, "Unable to lock pcm list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&pcm_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void pcm_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&pcm_lock)) {
- ast_log(LOG_WARNING, "Unable to lock pcm list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&pcm_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- int delay;
- /* Send a frame from the file to the appropriate channel */
-
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_ULAW;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.mallocd = 0;
- s->fr.data = s->buf;
- if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
- if (res)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- s->fr.samples = res;
- s->fr.datalen = res;
- delay = s->fr.samples;
- *whennext = delay;
- return &s->fr;
-}
-
-static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_ULAW) {
- ast_log(LOG_WARNING, "Asked to write non-ulaw frame (%d)!\n", f->subclass);
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- long cur, max, offset = 0;
-
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
-
- switch (whence) {
- case SEEK_SET:
- offset = sample_offset;
- break;
- case SEEK_END:
- offset = max - sample_offset;
- break;
- case SEEK_CUR:
- case SEEK_FORCECUR:
- offset = cur + sample_offset;
- break;
- }
-
- switch (whence) {
- case SEEK_FORCECUR:
- if (offset > max) {
- size_t left = offset - max;
- size_t res;
-
- while (left) {
- res = fwrite(ulaw_silence, sizeof(ulaw_silence[0]),
- (left > BUF_SIZE) ? BUF_SIZE : left, fs->f);
- if (res == -1)
- return res;
- left -= res * sizeof(ulaw_silence[0]);
- }
- return offset;
- }
- /* fall through */
- default:
- offset = (offset > max) ? max : offset;
- offset = (offset < 0) ? 0 : offset;
- return fseek(fs->f, offset, SEEK_SET);
- }
-}
-
-static int pcm_trunc(struct ast_filestream *fs)
-{
- return ftruncate(fileno(fs->f), ftell(fs->f));
-}
-
-static long pcm_tell(struct ast_filestream *fs)
-{
- off_t offset;
- offset = ftell(fs->f);
- return offset;
-}
-
-static char *pcm_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-int load_module()
-{
- int index;
-
- for (index = 0; index < (sizeof(ulaw_silence) / sizeof(ulaw_silence[0])); index++)
- ulaw_silence[index] = AST_LIN2MU(0);
-
- return ast_format_register(name, exts, AST_FORMAT_ULAW,
- pcm_open,
- pcm_rewrite,
- pcm_write,
- pcm_seek,
- pcm_trunc,
- pcm_tell,
- pcm_read,
- pcm_close,
- pcm_getcomment);
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_pcm_alaw.c b/1.2-netsec/formats/format_pcm_alaw.c
deleted file mode 100644
index 13d7c174a..000000000
--- a/1.2-netsec/formats/format_pcm_alaw.c
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Flat, binary, alaw PCM file format.
- * \arg File name extensions: alaw, al
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-#include "asterisk/alaw.h"
-
-#define BUF_SIZE 160 /* 160 samples */
-
-/* #define REALTIME_WRITE */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* Believe it or not, we must decode/recode to account for the
- weird MS format */
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char buf[BUF_SIZE]; /* Output Buffer */
-#ifdef REALTIME_WRITE
- unsigned long start_time;
-#endif
-};
-
-
-AST_MUTEX_DEFINE_STATIC(pcm_lock);
-static int glistcnt = 0;
-
-static char *name = "alaw";
-static char *desc = "Raw aLaw 8khz PCM Audio support";
-static char *exts = "alaw|al";
-
-static char alaw_silence[BUF_SIZE];
-
-
-#if 0
-/* Returns time in msec since system boot. */
-static unsigned long get_time(void)
-{
- struct tms buf;
- clock_t cur;
-
- cur = times( &buf );
- if( cur < 0 )
- {
- ast_log( LOG_WARNING, "Cannot get current time\n" );
- return 0;
- }
- return cur * 1000 / sysconf( _SC_CLK_TCK );
-}
-#endif
-
-static struct ast_filestream *pcm_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&pcm_lock)) {
- ast_log(LOG_WARNING, "Unable to lock pcm list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->buf;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_ALAW;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
-#ifdef REALTIME_WRITE
- tmp->start_time = get_time();
-#endif
- glistcnt++;
- ast_mutex_unlock(&pcm_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *pcm_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&pcm_lock)) {
- ast_log(LOG_WARNING, "Unable to lock pcm list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
-#ifdef REALTIME_WRITE
- tmp->start_time = get_time();
-#endif
- glistcnt++;
- ast_mutex_unlock(&pcm_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void pcm_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&pcm_lock)) {
- ast_log(LOG_WARNING, "Unable to lock pcm list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&pcm_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- /* Send a frame from the file to the appropriate channel */
-
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_ALAW;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.mallocd = 0;
- s->fr.data = s->buf;
- if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
- if (res)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- s->fr.samples = res;
- s->fr.datalen = res;
- *whennext = s->fr.samples;
- return &s->fr;
-}
-
-static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
-#ifdef REALTIME_WRITE
- unsigned long cur_time;
- unsigned long fpos;
- struct stat stat_buf;
-#endif
-
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_ALAW) {
- ast_log(LOG_WARNING, "Asked to write non-alaw frame (%d)!\n", f->subclass);
- return -1;
- }
-
-#ifdef REALTIME_WRITE
- cur_time = get_time();
- fpos = ( cur_time - fs->start_time ) * 8; /* 8 bytes per msec */
- /* Check if we have written to this position yet. If we have, then increment pos by one frame
- * for some degree of protection against receiving packets in the same clock tick.
- */
-
- fstat(fileno(fs->f), &stat_buf );
- if (stat_buf.st_size > fpos ) {
- fpos += f->datalen; /* Incrementing with the size of this current frame */
- }
-
- if (stat_buf.st_size < fpos) {
- /* fill the gap with 0x55 rather than 0. */
- char buf[ 512 ];
- unsigned long cur, to_write;
-
- cur = stat_buf.st_size;
- if (fseek(fs->f, cur, SEEK_SET) < 0) {
- ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) );
- return -1;
- }
- memset(buf, 0x55, 512);
- while (cur < fpos) {
- to_write = fpos - cur;
- if (to_write > 512) {
- to_write = 512;
- }
- fwrite(buf, 1, to_write, fs->f);
- cur += to_write;
- }
- }
-
-
- if (fseek(s->f, fpos, SEEK_SET) < 0) {
- ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) );
- return -1;
- }
-#endif /* REALTIME_WRITE */
-
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- long cur, max, offset = 0;
-
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
-
- switch (whence) {
- case SEEK_SET:
- offset = sample_offset;
- break;
- case SEEK_END:
- offset = max - sample_offset;
- break;
- case SEEK_CUR:
- case SEEK_FORCECUR:
- offset = cur + sample_offset;
- break;
- }
-
- switch (whence) {
- case SEEK_FORCECUR:
- if (offset > max) {
- size_t left = offset - max;
- size_t res;
-
- while (left) {
- res = fwrite(alaw_silence, sizeof(alaw_silence[0]),
- (left > BUF_SIZE) ? BUF_SIZE : left, fs->f);
- if (res == -1)
- return res;
- left -= res * sizeof(alaw_silence[0]);
- }
- return offset;
- }
- /* fall through */
- default:
- offset = (offset > max) ? max : offset;
- offset = (offset < 0) ? 0 : offset;
- return fseek(fs->f, offset, SEEK_SET);
- }
-}
-
-static int pcm_trunc(struct ast_filestream *fs)
-{
- return ftruncate(fileno(fs->f), ftell(fs->f));
-}
-
-static long pcm_tell(struct ast_filestream *fs)
-{
- off_t offset;
- offset = ftell(fs->f);
- return offset;
-}
-
-
-static char *pcm_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-int load_module()
-{
- int index;
-
- for (index = 0; index < (sizeof(alaw_silence) / sizeof(alaw_silence[0])); index++)
- alaw_silence[index] = AST_LIN2A(0);
-
- return ast_format_register(name, exts, AST_FORMAT_ALAW,
- pcm_open,
- pcm_rewrite,
- pcm_write,
- pcm_seek,
- pcm_trunc,
- pcm_tell,
- pcm_read,
- pcm_close,
- pcm_getcomment);
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_sln.c b/1.2-netsec/formats/format_sln.c
deleted file mode 100644
index d155b09a2..000000000
--- a/1.2-netsec/formats/format_sln.c
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Anthony Minessale
- * Anthony Minessale (anthmct@yahoo.com)
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief RAW SLINEAR Format
- * \arg File name extensions: sln, raw
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-#define BUF_SIZE 320 /* 320 samples */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_channel *owner;
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char buf[BUF_SIZE]; /* Output Buffer */
- struct timeval last;
-};
-
-
-AST_MUTEX_DEFINE_STATIC(slinear_lock);
-static int glistcnt = 0;
-
-static char *name = "sln";
-static char *desc = "Raw Signed Linear Audio support (SLN)";
-static char *exts = "sln|raw";
-
-static struct ast_filestream *slinear_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&slinear_lock)) {
- ast_log(LOG_WARNING, "Unable to lock slinear list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->buf;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_SLINEAR;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- glistcnt++;
- ast_mutex_unlock(&slinear_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *slinear_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&slinear_lock)) {
- ast_log(LOG_WARNING, "Unable to lock slinear list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&slinear_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void slinear_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&slinear_lock)) {
- ast_log(LOG_WARNING, "Unable to lock slinear list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&slinear_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *slinear_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- int delay;
- /* Send a frame from the file to the appropriate channel */
-
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_SLINEAR;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.mallocd = 0;
- s->fr.data = s->buf;
- if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
- if (res)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- s->fr.samples = res/2;
- s->fr.datalen = res;
- delay = s->fr.samples;
- *whennext = delay;
- return &s->fr;
-}
-
-static int slinear_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_SLINEAR) {
- ast_log(LOG_WARNING, "Asked to write non-slinear frame (%d)!\n", f->subclass);
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int slinear_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- off_t offset=0,min,cur,max;
-
- min = 0;
- sample_offset <<= 1;
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
- if (whence == SEEK_SET)
- offset = sample_offset;
- else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = sample_offset + cur;
- else if (whence == SEEK_END)
- offset = max - sample_offset;
- if (whence != SEEK_FORCECUR) {
- offset = (offset > max)?max:offset;
- }
- /* always protect against seeking past begining. */
- offset = (offset < min)?min:offset;
- return fseek(fs->f, offset, SEEK_SET);
-}
-
-static int slinear_trunc(struct ast_filestream *fs)
-{
- return ftruncate(fileno(fs->f), ftell(fs->f));
-}
-
-static long slinear_tell(struct ast_filestream *fs)
-{
- off_t offset;
- offset = ftell(fs->f);
- return offset / 2;
-}
-
-static char *slinear_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_SLINEAR,
- slinear_open,
- slinear_rewrite,
- slinear_write,
- slinear_seek,
- slinear_trunc,
- slinear_tell,
- slinear_read,
- slinear_close,
- slinear_getcomment);
-
-
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_vox.c b/1.2-netsec/formats/format_vox.c
deleted file mode 100644
index 60d2630be..000000000
--- a/1.2-netsec/formats/format_vox.c
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Flat, binary, ADPCM vox file format.
- * \arg File name extensions: vox
- *
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-#define BUF_SIZE 80 /* 160 samples */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char buf[BUF_SIZE]; /* Output Buffer */
- int lasttimeout;
- struct timeval last;
- short signal; /* Signal level (file side) */
- short ssindex; /* Signal ssindex (file side) */
- unsigned char zero_count; /* counter of consecutive zero samples */
- unsigned char next_flag;
-};
-
-
-AST_MUTEX_DEFINE_STATIC(vox_lock);
-static int glistcnt = 0;
-
-static char *name = "vox";
-static char *desc = "Dialogic VOX (ADPCM) File Format";
-static char *exts = "vox";
-
-static struct ast_filestream *vox_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&vox_lock)) {
- ast_log(LOG_WARNING, "Unable to lock vox list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->buf;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_ADPCM;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- tmp->lasttimeout = -1;
- glistcnt++;
- ast_mutex_unlock(&vox_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *vox_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (ast_mutex_lock(&vox_lock)) {
- ast_log(LOG_WARNING, "Unable to lock vox list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&vox_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void vox_close(struct ast_filestream *s)
-{
- if (ast_mutex_lock(&vox_lock)) {
- ast_log(LOG_WARNING, "Unable to lock vox list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&vox_lock);
- ast_update_use_count();
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *vox_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- /* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_ADPCM;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.mallocd = 0;
- s->fr.data = s->buf;
- if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
- if (res)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- s->fr.samples = res * 2;
- s->fr.datalen = res;
- *whennext = s->fr.samples;
- return &s->fr;
-}
-
-static int vox_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_ADPCM) {
- ast_log(LOG_WARNING, "Asked to write non-ADPCM frame (%d)!\n", f->subclass);
- return -1;
- }
- if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
- ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static char *vox_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-static int vox_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- off_t offset=0,min,cur,max,distance;
-
- min = 0;
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
-
- /* have to fudge to frame here, so not fully to sample */
- distance = sample_offset/2;
- if(whence == SEEK_SET)
- offset = distance;
- else if(whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = distance + cur;
- else if(whence == SEEK_END)
- offset = max - distance;
- if (whence != SEEK_FORCECUR) {
- offset = (offset > max)?max:offset;
- offset = (offset < min)?min:offset;
- }
- fseek(fs->f, offset, SEEK_SET);
- return ftell(fs->f);
-}
-
-static int vox_trunc(struct ast_filestream *fs)
-{
- return ftruncate(fileno(fs->f), ftell(fs->f));
-}
-
-static long vox_tell(struct ast_filestream *fs)
-{
- off_t offset;
- offset = ftell(fs->f) << 1;
- return offset;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_ADPCM,
- vox_open,
- vox_rewrite,
- vox_write,
- vox_seek,
- vox_trunc,
- vox_tell,
- vox_read,
- vox_close,
- vox_getcomment);
-
-
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_wav.c b/1.2-netsec/formats/format_wav.c
deleted file mode 100644
index 83e6dd564..000000000
--- a/1.2-netsec/formats/format_wav.c
+++ /dev/null
@@ -1,605 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Work with WAV in the proprietary Microsoft format.
- * Microsoft WAV format (8000hz Signed Linear)
- * \arg File name extension: wav (lower case)
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-/* Some Ideas for this code came from makewave.c by Jeffrey Chilton */
-
-/* Portions of the conversion code are by guido@sienanet.it */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- int bytes;
- int needsgain;
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- short buf[160];
- int foffset;
- int lasttimeout;
- int maxlen;
- struct timeval last;
-};
-
-
-AST_MUTEX_DEFINE_STATIC(wav_lock);
-static int glistcnt = 0;
-
-static char *name = "wav";
-static char *desc = "Microsoft WAV format (8000hz Signed Linear)";
-static char *exts = "wav";
-
-#define BLOCKSIZE 160
-
-#define GAIN 2 /* 2^GAIN is the multiple to increase the volume by */
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define htoll(b) (b)
-#define htols(b) (b)
-#define ltohl(b) (b)
-#define ltohs(b) (b)
-#else
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define htoll(b) \
- (((((b) ) & 0xFF) << 24) | \
- ((((b) >> 8) & 0xFF) << 16) | \
- ((((b) >> 16) & 0xFF) << 8) | \
- ((((b) >> 24) & 0xFF) ))
-#define htols(b) \
- (((((b) ) & 0xFF) << 8) | \
- ((((b) >> 8) & 0xFF) ))
-#define ltohl(b) htoll(b)
-#define ltohs(b) htols(b)
-#else
-#error "Endianess not defined"
-#endif
-#endif
-
-
-static int check_header(FILE *f)
-{
- int type, size, formtype;
- int fmt, hsize;
- short format, chans, bysam, bisam;
- int bysec;
- int freq;
- int data;
- if (fread(&type, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (type)\n");
- return -1;
- }
- if (fread(&size, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (size)\n");
- return -1;
- }
- size = ltohl(size);
- if (fread(&formtype, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (formtype)\n");
- return -1;
- }
- if (memcmp(&type, "RIFF", 4)) {
- ast_log(LOG_WARNING, "Does not begin with RIFF\n");
- return -1;
- }
- if (memcmp(&formtype, "WAVE", 4)) {
- ast_log(LOG_WARNING, "Does not contain WAVE\n");
- return -1;
- }
- if (fread(&fmt, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (fmt)\n");
- return -1;
- }
- if (memcmp(&fmt, "fmt ", 4)) {
- ast_log(LOG_WARNING, "Does not say fmt\n");
- return -1;
- }
- if (fread(&hsize, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (formtype)\n");
- return -1;
- }
- if (ltohl(hsize) < 16) {
- ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
- return -1;
- }
- if (fread(&format, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Read failed (format)\n");
- return -1;
- }
- if (ltohs(format) != 1) {
- ast_log(LOG_WARNING, "Not a wav file %d\n", ltohs(format));
- return -1;
- }
- if (fread(&chans, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Read failed (format)\n");
- return -1;
- }
- if (ltohs(chans) != 1) {
- ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
- return -1;
- }
- if (fread(&freq, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (freq)\n");
- return -1;
- }
- if (ltohl(freq) != 8000) {
- ast_log(LOG_WARNING, "Unexpected freqency %d\n", ltohl(freq));
- return -1;
- }
- /* Ignore the byte frequency */
- if (fread(&bysec, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (BYTES_PER_SECOND)\n");
- return -1;
- }
- /* Check bytes per sample */
- if (fread(&bysam, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Read failed (BYTES_PER_SAMPLE)\n");
- return -1;
- }
- if (ltohs(bysam) != 2) {
- ast_log(LOG_WARNING, "Can only handle 16bits per sample: %d\n", ltohs(bysam));
- return -1;
- }
- if (fread(&bisam, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Read failed (Bits Per Sample): %d\n", ltohs(bisam));
- return -1;
- }
- /* Skip any additional header */
- if (fseek(f,ltohl(hsize)-16,SEEK_CUR) == -1 ) {
- ast_log(LOG_WARNING, "Failed to skip remaining header bytes: %d\n", ltohl(hsize)-16 );
- return -1;
- }
- /* Skip any facts and get the first data block */
- for(;;)
- {
- char buf[4];
-
- /* Begin data chunk */
- if (fread(&buf, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (data)\n");
- return -1;
- }
- /* Data has the actual length of data in it */
- if (fread(&data, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (data)\n");
- return -1;
- }
- data = ltohl(data);
- if(memcmp(buf, "data", 4) == 0 )
- break;
- if(memcmp(buf, "fact", 4) != 0 ) {
- ast_log(LOG_WARNING, "Unknown block - not fact or data\n");
- return -1;
- }
- if (fseek(f,data,SEEK_CUR) == -1 ) {
- ast_log(LOG_WARNING, "Failed to skip fact block: %d\n", data );
- return -1;
- }
- }
-#if 0
- curpos = lseek(fd, 0, SEEK_CUR);
- truelength = lseek(fd, 0, SEEK_END);
- lseek(fd, curpos, SEEK_SET);
- truelength -= curpos;
-#endif
- return data;
-}
-
-static int update_header(FILE *f)
-{
- off_t cur,end;
- int datalen,filelen,bytes;
-
-
- cur = ftell(f);
- fseek(f, 0, SEEK_END);
- end = ftell(f);
- /* data starts 44 bytes in */
- bytes = end - 44;
- datalen = htoll(bytes);
- /* chunk size is bytes of data plus 36 bytes of header */
- filelen = htoll(36 + bytes);
-
- if (cur < 0) {
- ast_log(LOG_WARNING, "Unable to find our position\n");
- return -1;
- }
- if (fseek(f, 4, SEEK_SET)) {
- ast_log(LOG_WARNING, "Unable to set our position\n");
- return -1;
- }
- if (fwrite(&filelen, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to set write file size\n");
- return -1;
- }
- if (fseek(f, 40, SEEK_SET)) {
- ast_log(LOG_WARNING, "Unable to set our position\n");
- return -1;
- }
- if (fwrite(&datalen, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to set write datalen\n");
- return -1;
- }
- if (fseek(f, cur, SEEK_SET)) {
- ast_log(LOG_WARNING, "Unable to return to position\n");
- return -1;
- }
- return 0;
-}
-
-static int write_header(FILE *f)
-{
- unsigned int hz=htoll(8000);
- unsigned int bhz = htoll(16000);
- unsigned int hs = htoll(16);
- unsigned short fmt = htols(1);
- unsigned short chans = htols(1);
- unsigned short bysam = htols(2);
- unsigned short bisam = htols(16);
- unsigned int size = htoll(0);
- /* Write a wav header, ignoring sizes which will be filled in later */
- fseek(f,0,SEEK_SET);
- if (fwrite("RIFF", 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&size, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite("WAVEfmt ", 1, 8, f) != 8) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&hs, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&fmt, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&chans, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&hz, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&bhz, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&bysam, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&bisam, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite("data", 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&size, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_filestream *wav_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if ((tmp->maxlen = check_header(f)) < 0) {
- free(tmp);
- return NULL;
- }
- if (ast_mutex_lock(&wav_lock)) {
- ast_log(LOG_WARNING, "Unable to lock wav list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->needsgain = 1;
- tmp->fr.data = tmp->buf;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_SLINEAR;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- tmp->bytes = 0;
- glistcnt++;
- ast_mutex_unlock(&wav_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *wav_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (write_header(f)) {
- free(tmp);
- return NULL;
- }
- if (ast_mutex_lock(&wav_lock)) {
- ast_log(LOG_WARNING, "Unable to lock wav list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&wav_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void wav_close(struct ast_filestream *s)
-{
- char zero = 0;
- if (ast_mutex_lock(&wav_lock)) {
- ast_log(LOG_WARNING, "Unable to lock wav list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&wav_lock);
- ast_update_use_count();
- /* Pad to even length */
- if (s->bytes & 0x1)
- fwrite(&zero, 1, 1, s->f);
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- int delay;
- int x;
- short tmp[sizeof(s->buf) / 2];
- int bytes = sizeof(tmp);
- off_t here;
- /* Send a frame from the file to the appropriate channel */
- here = ftell(s->f);
- if ((s->maxlen - here) < bytes)
- bytes = s->maxlen - here;
- if (bytes < 0)
- bytes = 0;
-/* ast_log(LOG_DEBUG, "here: %d, maxlen: %d, bytes: %d\n", here, s->maxlen, bytes); */
-
- if ( (res = fread(tmp, 1, bytes, s->f)) <= 0 ) {
- if (res) {
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- }
- return NULL;
- }
-
-#if __BYTE_ORDER == __BIG_ENDIAN
- for( x = 0; x < sizeof(tmp)/2; x++) tmp[x] = (tmp[x] << 8) | ((tmp[x] & 0xff00) >> 8);
-#endif
-
- if (s->needsgain) {
- for (x=0;x<sizeof(tmp)/2;x++)
- if (tmp[x] & ((1 << GAIN) - 1)) {
- /* If it has data down low, then it's not something we've artificially increased gain
- on, so we don't need to gain adjust it */
- s->needsgain = 0;
- }
- }
- if (s->needsgain) {
- for (x=0;x<sizeof(tmp)/2;x++) {
- s->buf[x] = tmp[x] >> GAIN;
- }
- } else {
- memcpy(s->buf, tmp, sizeof(s->buf));
- }
-
- delay = res / 2;
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_SLINEAR;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.datalen = res;
- s->fr.data = s->buf;
- s->fr.mallocd = 0;
- s->fr.samples = delay;
- *whennext = delay;
- return &s->fr;
-}
-
-static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res = 0;
- int x;
- short tmp[8000], *tmpi;
- float tmpf;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_SLINEAR) {
- ast_log(LOG_WARNING, "Asked to write non-SLINEAR frame (%d)!\n", f->subclass);
- return -1;
- }
- if (f->datalen > sizeof(tmp)) {
- ast_log(LOG_WARNING, "Data length is too long\n");
- return -1;
- }
- if (!f->datalen)
- return -1;
-
-#if 0
- printf("Data Length: %d\n", f->datalen);
-#endif
-
- if (fs->buf) {
- tmpi = f->data;
- /* Volume adjust here to accomodate */
- for (x=0;x<f->datalen/2;x++) {
- tmpf = ((float)tmpi[x]) * ((float)(1 << GAIN));
- if (tmpf > 32767.0)
- tmpf = 32767.0;
- if (tmpf < -32768.0)
- tmpf = -32768.0;
- tmp[x] = tmpf;
- tmp[x] &= ~((1 << GAIN) - 1);
-
-#if __BYTE_ORDER == __BIG_ENDIAN
- tmp[x] = (tmp[x] << 8) | ((tmp[x] & 0xff00) >> 8);
-#endif
-
- }
- if ((fwrite(tmp, 1, f->datalen, fs->f) != f->datalen) ) {
- ast_log(LOG_WARNING, "Bad write (%d): %s\n", res, strerror(errno));
- return -1;
- }
- } else {
- ast_log(LOG_WARNING, "Cannot write data to file.\n");
- return -1;
- }
-
- fs->bytes += f->datalen;
- update_header(fs->f);
-
- return 0;
-
-}
-
-static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- off_t min,max,cur;
- long offset=0,samples;
-
- samples = sample_offset * 2; /* SLINEAR is 16 bits mono, so sample_offset * 2 = bytes */
- min = 44; /* wav header is 44 bytes */
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
- if (whence == SEEK_SET)
- offset = samples + min;
- else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = samples + cur;
- else if (whence == SEEK_END)
- offset = max - samples;
- if (whence != SEEK_FORCECUR) {
- offset = (offset > max)?max:offset;
- }
- /* always protect the header space. */
- offset = (offset < min)?min:offset;
- return fseek(fs->f,offset,SEEK_SET);
-}
-
-static int wav_trunc(struct ast_filestream *fs)
-{
- if (ftruncate(fileno(fs->f), ftell(fs->f)))
- return -1;
- return update_header(fs->f);
-}
-
-static long wav_tell(struct ast_filestream *fs)
-{
- off_t offset;
- offset = ftell(fs->f);
- /* subtract header size to get samples, then divide by 2 for 16 bit samples */
- return (offset - 44)/2;
-}
-
-static char *wav_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_SLINEAR,
- wav_open,
- wav_rewrite,
- wav_write,
- wav_seek,
- wav_trunc,
- wav_tell,
- wav_read,
- wav_close,
- wav_getcomment);
-
-
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/format_wav_gsm.c b/1.2-netsec/formats/format_wav_gsm.c
deleted file mode 100644
index c7bc50425..000000000
--- a/1.2-netsec/formats/format_wav_gsm.c
+++ /dev/null
@@ -1,589 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Save GSM in the proprietary Microsoft format.
- *
- * Microsoft WAV format (Proprietary GSM)
- * \arg File name extension: WAV,wav49 (Upper case WAV, lower case is another format)
- * This format can be played on Windows systems, used for
- * e-mail attachments mainly.
- * \ingroup formats
- */
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
-#include "asterisk/module.h"
-#include "asterisk/endian.h"
-
-#include "msgsm.h"
-
-/* Some Ideas for this code came from makewave.c by Jeffrey Chilton */
-
-/* Portions of the conversion code are by guido@sienanet.it */
-
-/* begin binary data: */
-char msgsm_silence[] = /* 65 */
-{0x48,0x17,0xD6,0x84,0x02,0x80,0x24,0x49,0x92,0x24,0x89,0x02,0x80,0x24,0x49
-,0x92,0x24,0x89,0x02,0x80,0x24,0x49,0x92,0x24,0x89,0x02,0x80,0x24,0x49,0x92
-,0x24,0x09,0x82,0x74,0x61,0x4D,0x28,0x00,0x48,0x92,0x24,0x49,0x92,0x28,0x00
-,0x48,0x92,0x24,0x49,0x92,0x28,0x00,0x48,0x92,0x24,0x49,0x92,0x28,0x00,0x48
-,0x92,0x24,0x49,0x92,0x00};
-/* end binary data. size = 65 bytes */
-
-struct ast_filestream {
- void *reserved[AST_RESERVED_POINTERS];
- /* Believe it or not, we must decode/recode to account for the
- weird MS format */
- /* This is what a filestream means to us */
- FILE *f; /* Descriptor */
- struct ast_frame fr; /* Frame information */
- char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
- char empty; /* Empty character */
- unsigned char gsm[66]; /* Two Real GSM Frames */
- int foffset;
- int secondhalf; /* Are we on the second half */
- struct timeval last;
-};
-
-
-AST_MUTEX_DEFINE_STATIC(wav_lock);
-static int glistcnt = 0;
-
-static char *name = "wav49";
-static char *desc = "Microsoft WAV format (Proprietary GSM)";
-static char *exts = "WAV|wav49";
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define htoll(b) (b)
-#define htols(b) (b)
-#define ltohl(b) (b)
-#define ltohs(b) (b)
-#else
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define htoll(b) \
- (((((b) ) & 0xFF) << 24) | \
- ((((b) >> 8) & 0xFF) << 16) | \
- ((((b) >> 16) & 0xFF) << 8) | \
- ((((b) >> 24) & 0xFF) ))
-#define htols(b) \
- (((((b) ) & 0xFF) << 8) | \
- ((((b) >> 8) & 0xFF) ))
-#define ltohl(b) htoll(b)
-#define ltohs(b) htols(b)
-#else
-#error "Endianess not defined"
-#endif
-#endif
-
-
-static int check_header(FILE *f)
-{
- int type, size, formtype;
- int fmt, hsize, fact;
- short format, chans;
- int freq;
- int data;
- if (fread(&type, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (type)\n");
- return -1;
- }
- if (fread(&size, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (size)\n");
- return -1;
- }
- size = ltohl(size);
- if (fread(&formtype, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (formtype)\n");
- return -1;
- }
- if (memcmp(&type, "RIFF", 4)) {
- ast_log(LOG_WARNING, "Does not begin with RIFF\n");
- return -1;
- }
- if (memcmp(&formtype, "WAVE", 4)) {
- ast_log(LOG_WARNING, "Does not contain WAVE\n");
- return -1;
- }
- if (fread(&fmt, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (fmt)\n");
- return -1;
- }
- if (memcmp(&fmt, "fmt ", 4)) {
- ast_log(LOG_WARNING, "Does not say fmt\n");
- return -1;
- }
- if (fread(&hsize, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (formtype)\n");
- return -1;
- }
- if (ltohl(hsize) != 20) {
- ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
- return -1;
- }
- if (fread(&format, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Read failed (format)\n");
- return -1;
- }
- if (ltohs(format) != 49) {
- ast_log(LOG_WARNING, "Not a GSM file %d\n", ltohs(format));
- return -1;
- }
- if (fread(&chans, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Read failed (format)\n");
- return -1;
- }
- if (ltohs(chans) != 1) {
- ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
- return -1;
- }
- if (fread(&freq, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (freq)\n");
- return -1;
- }
- if (ltohl(freq) != 8000) {
- ast_log(LOG_WARNING, "Unexpected freqency %d\n", ltohl(freq));
- return -1;
- }
- /* Ignore the byte frequency */
- if (fread(&freq, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (X_1)\n");
- return -1;
- }
- /* Ignore the two weird fields */
- if (fread(&freq, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (X_2/X_3)\n");
- return -1;
- }
- /* Ignore the byte frequency */
- if (fread(&freq, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (Y_1)\n");
- return -1;
- }
- /* Check for the word fact */
- if (fread(&fact, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (fact)\n");
- return -1;
- }
- if (memcmp(&fact, "fact", 4)) {
- ast_log(LOG_WARNING, "Does not say fact\n");
- return -1;
- }
- /* Ignore the "fact value" */
- if (fread(&fact, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (fact header)\n");
- return -1;
- }
- if (fread(&fact, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (fact value)\n");
- return -1;
- }
- /* Check for the word data */
- if (fread(&data, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (data)\n");
- return -1;
- }
- if (memcmp(&data, "data", 4)) {
- ast_log(LOG_WARNING, "Does not say data\n");
- return -1;
- }
- /* Ignore the data length */
- if (fread(&data, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Read failed (data)\n");
- return -1;
- }
- return 0;
-}
-
-static int update_header(FILE *f)
-{
- off_t cur,end,bytes;
- int datalen,filelen;
-
- cur = ftell(f);
- fseek(f, 0, SEEK_END);
- end = ftell(f);
- /* in a gsm WAV, data starts 60 bytes in */
- bytes = end - 60;
- datalen = htoll((bytes + 1) & ~0x1);
- filelen = htoll(52 + ((bytes + 1) & ~0x1));
- if (cur < 0) {
- ast_log(LOG_WARNING, "Unable to find our position\n");
- return -1;
- }
- if (fseek(f, 4, SEEK_SET)) {
- ast_log(LOG_WARNING, "Unable to set our position\n");
- return -1;
- }
- if (fwrite(&filelen, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to set write file size\n");
- return -1;
- }
- if (fseek(f, 56, SEEK_SET)) {
- ast_log(LOG_WARNING, "Unable to set our position\n");
- return -1;
- }
- if (fwrite(&datalen, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to set write datalen\n");
- return -1;
- }
- if (fseek(f, cur, SEEK_SET)) {
- ast_log(LOG_WARNING, "Unable to return to position\n");
- return -1;
- }
- return 0;
-}
-
-static int write_header(FILE *f)
-{
- unsigned int hz=htoll(8000);
- unsigned int bhz = htoll(1625);
- unsigned int hs = htoll(20);
- unsigned short fmt = htols(49);
- unsigned short chans = htols(1);
- unsigned int fhs = htoll(4);
- unsigned int x_1 = htoll(65);
- unsigned short x_2 = htols(2);
- unsigned short x_3 = htols(320);
- unsigned int y_1 = htoll(20160);
- unsigned int size = htoll(0);
- /* Write a GSM header, ignoring sizes which will be filled in later */
- if (fwrite("RIFF", 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&size, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite("WAVEfmt ", 1, 8, f) != 8) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&hs, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&fmt, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&chans, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&hz, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&bhz, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&x_1, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&x_2, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&x_3, 1, 2, f) != 2) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite("fact", 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&fhs, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&y_1, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite("data", 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- if (fwrite(&size, 1, 4, f) != 4) {
- ast_log(LOG_WARNING, "Unable to write header\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_filestream *wav_open(FILE *f)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (check_header(f)) {
- free(tmp);
- return NULL;
- }
- if (ast_mutex_lock(&wav_lock)) {
- ast_log(LOG_WARNING, "Unable to lock wav list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- tmp->fr.data = tmp->gsm;
- tmp->fr.frametype = AST_FRAME_VOICE;
- tmp->fr.subclass = AST_FORMAT_GSM;
- /* datalen will vary for each frame */
- tmp->fr.src = name;
- tmp->fr.mallocd = 0;
- tmp->secondhalf = 0;
- glistcnt++;
- ast_mutex_unlock(&wav_lock);
- ast_update_use_count();
- }
- return tmp;
-}
-
-static struct ast_filestream *wav_rewrite(FILE *f, const char *comment)
-{
- /* We don't have any header to read or anything really, but
- if we did, it would go here. We also might want to check
- and be sure it's a valid file. */
- struct ast_filestream *tmp;
- if ((tmp = malloc(sizeof(struct ast_filestream)))) {
- memset(tmp, 0, sizeof(struct ast_filestream));
- if (write_header(f)) {
- free(tmp);
- return NULL;
- }
- if (ast_mutex_lock(&wav_lock)) {
- ast_log(LOG_WARNING, "Unable to lock wav list\n");
- free(tmp);
- return NULL;
- }
- tmp->f = f;
- glistcnt++;
- ast_mutex_unlock(&wav_lock);
- ast_update_use_count();
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tmp;
-}
-
-static void wav_close(struct ast_filestream *s)
-{
- char zero = 0;
- if (ast_mutex_lock(&wav_lock)) {
- ast_log(LOG_WARNING, "Unable to lock wav list\n");
- return;
- }
- glistcnt--;
- ast_mutex_unlock(&wav_lock);
- ast_update_use_count();
- /* Pad to even length */
- fseek(s->f, 0, SEEK_END);
- if (ftell(s->f) & 0x1)
- fwrite(&zero, 1, 1, s->f);
- fclose(s->f);
- free(s);
- s = NULL;
-}
-
-static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
-{
- int res;
- char msdata[66];
- /* Send a frame from the file to the appropriate channel */
-
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass = AST_FORMAT_GSM;
- s->fr.offset = AST_FRIENDLY_OFFSET;
- s->fr.samples = 160;
- s->fr.datalen = 33;
- s->fr.mallocd = 0;
- if (s->secondhalf) {
- /* Just return a frame based on the second GSM frame */
- s->fr.data = s->gsm + 33;
- } else {
- if ((res = fread(msdata, 1, 65, s->f)) != 65) {
- if (res && (res != 1))
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
- return NULL;
- }
- /* Convert from MS format to two real GSM frames */
- conv65(msdata, s->gsm);
- s->fr.data = s->gsm;
- }
- s->secondhalf = !s->secondhalf;
- *whennext = 160;
- return &s->fr;
-}
-
-static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
-{
- int res;
- char msdata[66];
- int len =0;
- int alreadyms=0;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass != AST_FORMAT_GSM) {
- ast_log(LOG_WARNING, "Asked to write non-GSM frame (%d)!\n", f->subclass);
- return -1;
- }
- if (!(f->datalen % 65))
- alreadyms = 1;
- while(len < f->datalen) {
- if (alreadyms) {
- fs->secondhalf = 0;
- if ((res = fwrite(f->data + len, 1, 65, fs->f)) != 65) {
- ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
- return -1;
- }
- update_header(fs->f);
- len += 65;
- } else {
- if (fs->secondhalf) {
- memcpy(fs->gsm + 33, f->data + len, 33);
- conv66(fs->gsm, msdata);
- if ((res = fwrite(msdata, 1, 65, fs->f)) != 65) {
- ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
- return -1;
- }
- update_header(fs->f);
- } else {
- /* Copy the data and do nothing */
- memcpy(fs->gsm, f->data + len, 33);
- }
- fs->secondhalf = !fs->secondhalf;
- len += 33;
- }
- }
- return 0;
-}
-
-static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence)
-{
- off_t offset=0,distance,cur,min,max;
- min = 60;
- cur = ftell(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftell(fs->f);
- /* I'm getting sloppy here, I'm only going to go to even splits of the 2
- * frames, if you want tighter cuts use format_gsm, format_pcm, or format_wav */
- distance = (sample_offset/320) * 65;
- if(whence == SEEK_SET)
- offset = distance + min;
- else if(whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = distance + cur;
- else if(whence == SEEK_END)
- offset = max - distance;
- /* always protect against seeking past end of header */
- offset = (offset < min)?min:offset;
- if (whence != SEEK_FORCECUR) {
- offset = (offset > max)?max:offset;
- } else if (offset > max) {
- int i;
- fseek(fs->f, 0, SEEK_END);
- for (i=0; i< (offset - max) / 65; i++) {
- fwrite(msgsm_silence, 1, 65, fs->f);
- }
- }
- fs->secondhalf = 0;
- return fseek(fs->f, offset, SEEK_SET);
-}
-
-static int wav_trunc(struct ast_filestream *fs)
-{
- if (ftruncate(fileno(fs->f), ftell(fs->f)))
- return -1;
- return update_header(fs->f);
-}
-
-static long wav_tell(struct ast_filestream *fs)
-{
- off_t offset;
- offset = ftell(fs->f);
- /* since this will most likely be used later in play or record, lets stick
- * to that level of resolution, just even frames boundaries */
- return (offset - 52)/65*320;
-}
-
-static char *wav_getcomment(struct ast_filestream *s)
-{
- return NULL;
-}
-
-int load_module()
-{
- return ast_format_register(name, exts, AST_FORMAT_GSM,
- wav_open,
- wav_rewrite,
- wav_write,
- wav_seek,
- wav_trunc,
- wav_tell,
- wav_read,
- wav_close,
- wav_getcomment);
-
-
-}
-
-int unload_module()
-{
- return ast_format_unregister(name);
-}
-
-int usecount()
-{
- return glistcnt;
-}
-
-char *description()
-{
- return desc;
-}
-
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/formats/msgsm.h b/1.2-netsec/formats/msgsm.h
deleted file mode 100644
index ec12161c1..000000000
--- a/1.2-netsec/formats/msgsm.h
+++ /dev/null
@@ -1,687 +0,0 @@
-/* Conversion routines derived from code by guido@sienanet.it */
-
-#define GSM_MAGIC 0xD
-
-#ifndef GSM_H
-typedef unsigned char gsm_byte;
-#endif
-typedef unsigned char wav_byte;
-typedef unsigned int uword;
-
-#define readGSM_33(c1) { \
- gsm_byte *c = (c1); \
- LARc[0] = (*c++ & 0xF) << 2; /* 1 */ \
- LARc[0] |= (*c >> 6) & 0x3; \
- LARc[1] = *c++ & 0x3F; \
- LARc[2] = (*c >> 3) & 0x1F; \
- LARc[3] = (*c++ & 0x7) << 2; \
- LARc[3] |= (*c >> 6) & 0x3; \
- LARc[4] = (*c >> 2) & 0xF; \
- LARc[5] = (*c++ & 0x3) << 2; \
- LARc[5] |= (*c >> 6) & 0x3; \
- LARc[6] = (*c >> 3) & 0x7; \
- LARc[7] = *c++ & 0x7; \
- Nc[0] = (*c >> 1) & 0x7F; \
- bc[0] = (*c++ & 0x1) << 1; \
- bc[0] |= (*c >> 7) & 0x1; \
- Mc[0] = (*c >> 5) & 0x3; \
- xmaxc[0] = (*c++ & 0x1F) << 1; \
- xmaxc[0] |= (*c >> 7) & 0x1; \
- xmc[0] = (*c >> 4) & 0x7; \
- xmc[1] = (*c >> 1) & 0x7; \
- xmc[2] = (*c++ & 0x1) << 2; \
- xmc[2] |= (*c >> 6) & 0x3; \
- xmc[3] = (*c >> 3) & 0x7; \
- xmc[4] = *c++ & 0x7; \
- xmc[5] = (*c >> 5) & 0x7; \
- xmc[6] = (*c >> 2) & 0x7; \
- xmc[7] = (*c++ & 0x3) << 1; /* 10 */ \
- xmc[7] |= (*c >> 7) & 0x1; \
- xmc[8] = (*c >> 4) & 0x7; \
- xmc[9] = (*c >> 1) & 0x7; \
- xmc[10] = (*c++ & 0x1) << 2; \
- xmc[10] |= (*c >> 6) & 0x3; \
- xmc[11] = (*c >> 3) & 0x7; \
- xmc[12] = *c++ & 0x7; \
- Nc[1] = (*c >> 1) & 0x7F; \
- bc[1] = (*c++ & 0x1) << 1; \
- bc[1] |= (*c >> 7) & 0x1; \
- Mc[1] = (*c >> 5) & 0x3; \
- xmaxc[1] = (*c++ & 0x1F) << 1; \
- xmaxc[1] |= (*c >> 7) & 0x1; \
- xmc[13] = (*c >> 4) & 0x7; \
- xmc[14] = (*c >> 1) & 0x7; \
- xmc[15] = (*c++ & 0x1) << 2; \
- xmc[15] |= (*c >> 6) & 0x3; \
- xmc[16] = (*c >> 3) & 0x7; \
- xmc[17] = *c++ & 0x7; \
- xmc[18] = (*c >> 5) & 0x7; \
- xmc[19] = (*c >> 2) & 0x7; \
- xmc[20] = (*c++ & 0x3) << 1; \
- xmc[20] |= (*c >> 7) & 0x1; \
- xmc[21] = (*c >> 4) & 0x7; \
- xmc[22] = (*c >> 1) & 0x7; \
- xmc[23] = (*c++ & 0x1) << 2; \
- xmc[23] |= (*c >> 6) & 0x3; \
- xmc[24] = (*c >> 3) & 0x7; \
- xmc[25] = *c++ & 0x7; \
- Nc[2] = (*c >> 1) & 0x7F; \
- bc[2] = (*c++ & 0x1) << 1; /* 20 */ \
- bc[2] |= (*c >> 7) & 0x1; \
- Mc[2] = (*c >> 5) & 0x3; \
- xmaxc[2] = (*c++ & 0x1F) << 1; \
- xmaxc[2] |= (*c >> 7) & 0x1; \
- xmc[26] = (*c >> 4) & 0x7; \
- xmc[27] = (*c >> 1) & 0x7; \
- xmc[28] = (*c++ & 0x1) << 2; \
- xmc[28] |= (*c >> 6) & 0x3; \
- xmc[29] = (*c >> 3) & 0x7; \
- xmc[30] = *c++ & 0x7; \
- xmc[31] = (*c >> 5) & 0x7; \
- xmc[32] = (*c >> 2) & 0x7; \
- xmc[33] = (*c++ & 0x3) << 1; \
- xmc[33] |= (*c >> 7) & 0x1; \
- xmc[34] = (*c >> 4) & 0x7; \
- xmc[35] = (*c >> 1) & 0x7; \
- xmc[36] = (*c++ & 0x1) << 2; \
- xmc[36] |= (*c >> 6) & 0x3; \
- xmc[37] = (*c >> 3) & 0x7; \
- xmc[38] = *c++ & 0x7; \
- Nc[3] = (*c >> 1) & 0x7F; \
- bc[3] = (*c++ & 0x1) << 1; \
- bc[3] |= (*c >> 7) & 0x1; \
- Mc[3] = (*c >> 5) & 0x3; \
- xmaxc[3] = (*c++ & 0x1F) << 1; \
- xmaxc[3] |= (*c >> 7) & 0x1; \
- xmc[39] = (*c >> 4) & 0x7; \
- xmc[40] = (*c >> 1) & 0x7; \
- xmc[41] = (*c++ & 0x1) << 2; \
- xmc[41] |= (*c >> 6) & 0x3; \
- xmc[42] = (*c >> 3) & 0x7; \
- xmc[43] = *c++ & 0x7; /* 30 */ \
- xmc[44] = (*c >> 5) & 0x7; \
- xmc[45] = (*c >> 2) & 0x7; \
- xmc[46] = (*c++ & 0x3) << 1; \
- xmc[46] |= (*c >> 7) & 0x1; \
- xmc[47] = (*c >> 4) & 0x7; \
- xmc[48] = (*c >> 1) & 0x7; \
- xmc[49] = (*c++ & 0x1) << 2; \
- xmc[49] |= (*c >> 6) & 0x3; \
- xmc[50] = (*c >> 3) & 0x7; \
- xmc[51] = *c & 0x7; /* 33 */ \
-}
-
-static inline void conv66(gsm_byte * d, wav_byte * c) {
- gsm_byte frame_chain;
- unsigned int sr;
- unsigned int LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
-
- readGSM_33(d);
- sr = 0;
- sr = (sr >> 6) | (LARc[0] << 10);
- sr = (sr >> 6) | (LARc[1] << 10);
- *c++ = sr >> 4;
- sr = (sr >> 5) | (LARc[2] << 11);
- *c++ = sr >> 7;
- sr = (sr >> 5) | (LARc[3] << 11);
- sr = (sr >> 4) | (LARc[4] << 12);
- *c++ = sr >> 6;
- sr = (sr >> 4) | (LARc[5] << 12);
- sr = (sr >> 3) | (LARc[6] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3) | (LARc[7] << 13);
- sr = (sr >> 7) | (Nc[0] << 9);
- *c++ = sr >> 5;
- sr = (sr >> 2) | (bc[0] << 14);
- sr = (sr >> 2) | (Mc[0] << 14);
- sr = (sr >> 6) | (xmaxc[0] << 10);
- *c++ = sr >> 3;
- sr = (sr >> 3 )|( xmc[0] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[1] << 13);
- sr = (sr >> 3 )|( xmc[2] << 13);
- sr = (sr >> 3 )|( xmc[3] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[4] << 13);
- sr = (sr >> 3 )|( xmc[5] << 13);
- sr = (sr >> 3 )|( xmc[6] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[7] << 13);
- sr = (sr >> 3 )|( xmc[8] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[9] << 13);
- sr = (sr >> 3 )|( xmc[10] << 13);
- sr = (sr >> 3 )|( xmc[11] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[12] << 13);
- sr = (sr >> 7 )|( Nc[1] << 9);
- *c++ = sr >> 5;
- sr = (sr >> 2 )|( bc[1] << 14);
- sr = (sr >> 2 )|( Mc[1] << 14);
- sr = (sr >> 6 )|( xmaxc[1] << 10);
- *c++ = sr >> 3;
- sr = (sr >> 3 )|( xmc[13] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[14] << 13);
- sr = (sr >> 3 )|( xmc[15] << 13);
- sr = (sr >> 3 )|( xmc[16] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[17] << 13);
- sr = (sr >> 3 )|( xmc[18] << 13);
- sr = (sr >> 3 )|( xmc[19] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[20] << 13);
- sr = (sr >> 3 )|( xmc[21] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[22] << 13);
- sr = (sr >> 3 )|( xmc[23] << 13);
- sr = (sr >> 3 )|( xmc[24] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[25] << 13);
- sr = (sr >> 7 )|( Nc[2] << 9);
- *c++ = sr >> 5;
- sr = (sr >> 2 )|( bc[2] << 14);
- sr = (sr >> 2 )|( Mc[2] << 14);
- sr = (sr >> 6 )|( xmaxc[2] << 10);
- *c++ = sr >> 3;
- sr = (sr >> 3 )|( xmc[26] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[27] << 13);
- sr = (sr >> 3 )|( xmc[28] << 13);
- sr = (sr >> 3 )|( xmc[29] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[30] << 13);
- sr = (sr >> 3 )|( xmc[31] << 13);
- sr = (sr >> 3 )|( xmc[32] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[33] << 13);
- sr = (sr >> 3 )|( xmc[34] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[35] << 13);
- sr = (sr >> 3 )|( xmc[36] << 13);
- sr = (sr >> 3 )|( xmc[37] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[38] << 13);
- sr = (sr >> 7 )|( Nc[3] << 9);
- *c++ = sr >> 5;
- sr = (sr >> 2 )|( bc[3] << 14);
- sr = (sr >> 2 )|( Mc[3] << 14);
- sr = (sr >> 6 )|( xmaxc[3] << 10);
- *c++ = sr >> 3;
- sr = (sr >> 3 )|( xmc[39] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[40] << 13);
- sr = (sr >> 3 )|( xmc[41] << 13);
- sr = (sr >> 3 )|( xmc[42] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[43] << 13);
- sr = (sr >> 3 )|( xmc[44] << 13);
- sr = (sr >> 3 )|( xmc[45] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[46] << 13);
- sr = (sr >> 3 )|( xmc[47] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[48] << 13);
- sr = (sr >> 3 )|( xmc[49] << 13);
- sr = (sr >> 3 )|( xmc[50] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[51] << 13);
- sr = sr >> 4;
- *c = sr >> 8;
- frame_chain = *c;
- readGSM_33(d+33); /* puts all the parameters into LARc etc. */
-
-
- sr = 0;
-/* sr = (sr >> 4 )|( s->frame_chain << 12); */
- sr = (sr >> 4 )|( frame_chain << 12);
-
- sr = (sr >> 6 )|( LARc[0] << 10);
- *c++ = sr >> 6;
- sr = (sr >> 6 )|( LARc[1] << 10);
- *c++ = sr >> 8;
- sr = (sr >> 5 )|( LARc[2] << 11);
- sr = (sr >> 5 )|( LARc[3] << 11);
- *c++ = sr >> 6;
- sr = (sr >> 4 )|( LARc[4] << 12);
- sr = (sr >> 4 )|( LARc[5] << 12);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( LARc[6] << 13);
- sr = (sr >> 3 )|( LARc[7] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 7 )|( Nc[0] << 9);
- sr = (sr >> 2 )|( bc[0] << 14);
- *c++ = sr >> 7;
- sr = (sr >> 2 )|( Mc[0] << 14);
- sr = (sr >> 6 )|( xmaxc[0] << 10);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[0] << 13);
- sr = (sr >> 3 )|( xmc[1] << 13);
- sr = (sr >> 3 )|( xmc[2] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[3] << 13);
- sr = (sr >> 3 )|( xmc[4] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[5] << 13);
- sr = (sr >> 3 )|( xmc[6] << 13);
- sr = (sr >> 3 )|( xmc[7] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[8] << 13);
- sr = (sr >> 3 )|( xmc[9] << 13);
- sr = (sr >> 3 )|( xmc[10] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[11] << 13);
- sr = (sr >> 3 )|( xmc[12] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 7 )|( Nc[1] << 9);
- sr = (sr >> 2 )|( bc[1] << 14);
- *c++ = sr >> 7;
- sr = (sr >> 2 )|( Mc[1] << 14);
- sr = (sr >> 6 )|( xmaxc[1] << 10);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[13] << 13);
- sr = (sr >> 3 )|( xmc[14] << 13);
- sr = (sr >> 3 )|( xmc[15] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[16] << 13);
- sr = (sr >> 3 )|( xmc[17] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[18] << 13);
- sr = (sr >> 3 )|( xmc[19] << 13);
- sr = (sr >> 3 )|( xmc[20] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[21] << 13);
- sr = (sr >> 3 )|( xmc[22] << 13);
- sr = (sr >> 3 )|( xmc[23] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[24] << 13);
- sr = (sr >> 3 )|( xmc[25] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 7 )|( Nc[2] << 9);
- sr = (sr >> 2 )|( bc[2] << 14);
- *c++ = sr >> 7;
- sr = (sr >> 2 )|( Mc[2] << 14);
- sr = (sr >> 6 )|( xmaxc[2] << 10);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[26] << 13);
- sr = (sr >> 3 )|( xmc[27] << 13);
- sr = (sr >> 3 )|( xmc[28] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[29] << 13);
- sr = (sr >> 3 )|( xmc[30] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[31] << 13);
- sr = (sr >> 3 )|( xmc[32] << 13);
- sr = (sr >> 3 )|( xmc[33] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[34] << 13);
- sr = (sr >> 3 )|( xmc[35] << 13);
- sr = (sr >> 3 )|( xmc[36] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[37] << 13);
- sr = (sr >> 3 )|( xmc[38] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 7 )|( Nc[3] << 9);
- sr = (sr >> 2 )|( bc[3] << 14);
- *c++ = sr >> 7;
- sr = (sr >> 2 )|( Mc[3] << 14);
- sr = (sr >> 6 )|( xmaxc[3] << 10);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[39] << 13);
- sr = (sr >> 3 )|( xmc[40] << 13);
- sr = (sr >> 3 )|( xmc[41] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[42] << 13);
- sr = (sr >> 3 )|( xmc[43] << 13);
- *c++ = sr >> 8;
- sr = (sr >> 3 )|( xmc[44] << 13);
- sr = (sr >> 3 )|( xmc[45] << 13);
- sr = (sr >> 3 )|( xmc[46] << 13);
- *c++ = sr >> 7;
- sr = (sr >> 3 )|( xmc[47] << 13);
- sr = (sr >> 3 )|( xmc[48] << 13);
- sr = (sr >> 3 )|( xmc[49] << 13);
- *c++ = sr >> 6;
- sr = (sr >> 3 )|( xmc[50] << 13);
- sr = (sr >> 3 )|( xmc[51] << 13);
- *c++ = sr >> 8;
-
-}
-
-#define writeGSM_33(c1) { \
- gsm_byte *c = (c1); \
- *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */ \
- | ((LARc[0] >> 2) & 0xF); \
- *c++ = ((LARc[0] & 0x3) << 6) \
- | (LARc[1] & 0x3F); \
- *c++ = ((LARc[2] & 0x1F) << 3) \
- | ((LARc[3] >> 2) & 0x7); \
- *c++ = ((LARc[3] & 0x3) << 6) \
- | ((LARc[4] & 0xF) << 2) \
- | ((LARc[5] >> 2) & 0x3); \
- *c++ = ((LARc[5] & 0x3) << 6) \
- | ((LARc[6] & 0x7) << 3) \
- | (LARc[7] & 0x7); \
- *c++ = ((Nc[0] & 0x7F) << 1) \
- | ((bc[0] >> 1) & 0x1); \
- *c++ = ((bc[0] & 0x1) << 7) \
- | ((Mc[0] & 0x3) << 5) \
- | ((xmaxc[0] >> 1) & 0x1F); \
- *c++ = ((xmaxc[0] & 0x1) << 7) \
- | ((xmc[0] & 0x7) << 4) \
- | ((xmc[1] & 0x7) << 1) \
- | ((xmc[2] >> 2) & 0x1); \
- *c++ = ((xmc[2] & 0x3) << 6) \
- | ((xmc[3] & 0x7) << 3) \
- | (xmc[4] & 0x7); \
- *c++ = ((xmc[5] & 0x7) << 5) /* 10 */ \
- | ((xmc[6] & 0x7) << 2) \
- | ((xmc[7] >> 1) & 0x3); \
- *c++ = ((xmc[7] & 0x1) << 7) \
- | ((xmc[8] & 0x7) << 4) \
- | ((xmc[9] & 0x7) << 1) \
- | ((xmc[10] >> 2) & 0x1); \
- *c++ = ((xmc[10] & 0x3) << 6) \
- | ((xmc[11] & 0x7) << 3) \
- | (xmc[12] & 0x7); \
- *c++ = ((Nc[1] & 0x7F) << 1) \
- | ((bc[1] >> 1) & 0x1); \
- *c++ = ((bc[1] & 0x1) << 7) \
- | ((Mc[1] & 0x3) << 5) \
- | ((xmaxc[1] >> 1) & 0x1F); \
- *c++ = ((xmaxc[1] & 0x1) << 7) \
- | ((xmc[13] & 0x7) << 4) \
- | ((xmc[14] & 0x7) << 1) \
- | ((xmc[15] >> 2) & 0x1); \
- *c++ = ((xmc[15] & 0x3) << 6) \
- | ((xmc[16] & 0x7) << 3) \
- | (xmc[17] & 0x7); \
- *c++ = ((xmc[18] & 0x7) << 5) \
- | ((xmc[19] & 0x7) << 2) \
- | ((xmc[20] >> 1) & 0x3); \
- *c++ = ((xmc[20] & 0x1) << 7) \
- | ((xmc[21] & 0x7) << 4) \
- | ((xmc[22] & 0x7) << 1) \
- | ((xmc[23] >> 2) & 0x1); \
- *c++ = ((xmc[23] & 0x3) << 6) \
- | ((xmc[24] & 0x7) << 3) \
- | (xmc[25] & 0x7); \
- *c++ = ((Nc[2] & 0x7F) << 1) /* 20 */ \
- | ((bc[2] >> 1) & 0x1); \
- *c++ = ((bc[2] & 0x1) << 7) \
- | ((Mc[2] & 0x3) << 5) \
- | ((xmaxc[2] >> 1) & 0x1F); \
- *c++ = ((xmaxc[2] & 0x1) << 7) \
- | ((xmc[26] & 0x7) << 4) \
- | ((xmc[27] & 0x7) << 1) \
- | ((xmc[28] >> 2) & 0x1); \
- *c++ = ((xmc[28] & 0x3) << 6) \
- | ((xmc[29] & 0x7) << 3) \
- | (xmc[30] & 0x7); \
- *c++ = ((xmc[31] & 0x7) << 5) \
- | ((xmc[32] & 0x7) << 2) \
- | ((xmc[33] >> 1) & 0x3); \
- *c++ = ((xmc[33] & 0x1) << 7) \
- | ((xmc[34] & 0x7) << 4) \
- | ((xmc[35] & 0x7) << 1) \
- | ((xmc[36] >> 2) & 0x1); \
- *c++ = ((xmc[36] & 0x3) << 6) \
- | ((xmc[37] & 0x7) << 3) \
- | (xmc[38] & 0x7); \
- *c++ = ((Nc[3] & 0x7F) << 1) \
- | ((bc[3] >> 1) & 0x1); \
- *c++ = ((bc[3] & 0x1) << 7) \
- | ((Mc[3] & 0x3) << 5) \
- | ((xmaxc[3] >> 1) & 0x1F); \
- *c++ = ((xmaxc[3] & 0x1) << 7) \
- | ((xmc[39] & 0x7) << 4) \
- | ((xmc[40] & 0x7) << 1) \
- | ((xmc[41] >> 2) & 0x1); \
- *c++ = ((xmc[41] & 0x3) << 6) /* 30 */ \
- | ((xmc[42] & 0x7) << 3) \
- | (xmc[43] & 0x7); \
- *c++ = ((xmc[44] & 0x7) << 5) \
- | ((xmc[45] & 0x7) << 2) \
- | ((xmc[46] >> 1) & 0x3); \
- *c++ = ((xmc[46] & 0x1) << 7) \
- | ((xmc[47] & 0x7) << 4) \
- | ((xmc[48] & 0x7) << 1) \
- | ((xmc[49] >> 2) & 0x1); \
- *c++ = ((xmc[49] & 0x3) << 6) \
- | ((xmc[50] & 0x7) << 3) \
- | (xmc[51] & 0x7); \
-}
-
-static inline void conv65( wav_byte * c, gsm_byte * d){
-
- unsigned int sr = 0;
- unsigned int frame_chain;
- unsigned int LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
-
- sr = *c++;
- LARc[0] = sr & 0x3f; sr >>= 6;
- sr |= (uword)*c++ << 2;
- LARc[1] = sr & 0x3f; sr >>= 6;
- sr |= (uword)*c++ << 4;
- LARc[2] = sr & 0x1f; sr >>= 5;
- LARc[3] = sr & 0x1f; sr >>= 5;
- sr |= (uword)*c++ << 2;
- LARc[4] = sr & 0xf; sr >>= 4;
- LARc[5] = sr & 0xf; sr >>= 4;
- sr |= (uword)*c++ << 2; /* 5 */
- LARc[6] = sr & 0x7; sr >>= 3;
- LARc[7] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[0] = sr & 0x7f; sr >>= 7;
- bc[0] = sr & 0x3; sr >>= 2;
- Mc[0] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[0] = sr & 0x3f; sr >>= 6;
- xmc[0] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[1] = sr & 0x7; sr >>= 3;
- xmc[2] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[3] = sr & 0x7; sr >>= 3;
- xmc[4] = sr & 0x7; sr >>= 3;
- xmc[5] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 10 */
- xmc[6] = sr & 0x7; sr >>= 3;
- xmc[7] = sr & 0x7; sr >>= 3;
- xmc[8] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[9] = sr & 0x7; sr >>= 3;
- xmc[10] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[11] = sr & 0x7; sr >>= 3;
- xmc[12] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[1] = sr & 0x7f; sr >>= 7;
- bc[1] = sr & 0x3; sr >>= 2;
- Mc[1] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[1] = sr & 0x3f; sr >>= 6;
- xmc[13] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 15 */
- xmc[14] = sr & 0x7; sr >>= 3;
- xmc[15] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[16] = sr & 0x7; sr >>= 3;
- xmc[17] = sr & 0x7; sr >>= 3;
- xmc[18] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[19] = sr & 0x7; sr >>= 3;
- xmc[20] = sr & 0x7; sr >>= 3;
- xmc[21] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[22] = sr & 0x7; sr >>= 3;
- xmc[23] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[24] = sr & 0x7; sr >>= 3;
- xmc[25] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4; /* 20 */
- Nc[2] = sr & 0x7f; sr >>= 7;
- bc[2] = sr & 0x3; sr >>= 2;
- Mc[2] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[2] = sr & 0x3f; sr >>= 6;
- xmc[26] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[27] = sr & 0x7; sr >>= 3;
- xmc[28] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[29] = sr & 0x7; sr >>= 3;
- xmc[30] = sr & 0x7; sr >>= 3;
- xmc[31] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[32] = sr & 0x7; sr >>= 3;
- xmc[33] = sr & 0x7; sr >>= 3;
- xmc[34] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 25 */
- xmc[35] = sr & 0x7; sr >>= 3;
- xmc[36] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[37] = sr & 0x7; sr >>= 3;
- xmc[38] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 4;
- Nc[3] = sr & 0x7f; sr >>= 7;
- bc[3] = sr & 0x3; sr >>= 2;
- Mc[3] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 1;
- xmaxc[3] = sr & 0x3f; sr >>= 6;
- xmc[39] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[40] = sr & 0x7; sr >>= 3;
- xmc[41] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2; /* 30 */
- xmc[42] = sr & 0x7; sr >>= 3;
- xmc[43] = sr & 0x7; sr >>= 3;
- xmc[44] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[45] = sr & 0x7; sr >>= 3;
- xmc[46] = sr & 0x7; sr >>= 3;
- xmc[47] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[49] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[50] = sr & 0x7; sr >>= 3;
- xmc[51] = sr & 0x7; sr >>= 3;
-
- frame_chain = sr & 0xf;
-
-
- writeGSM_33(d);/* LARc etc. -> array of 33 GSM bytes */
-
-
- sr = frame_chain;
- sr |= (uword)*c++ << 4; /* 1 */
- LARc[0] = sr & 0x3f; sr >>= 6;
- LARc[1] = sr & 0x3f; sr >>= 6;
- sr = *c++;
- LARc[2] = sr & 0x1f; sr >>= 5;
- sr |= (uword)*c++ << 3;
- LARc[3] = sr & 0x1f; sr >>= 5;
- LARc[4] = sr & 0xf; sr >>= 4;
- sr |= (uword)*c++ << 2;
- LARc[5] = sr & 0xf; sr >>= 4;
- LARc[6] = sr & 0x7; sr >>= 3;
- LARc[7] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 5 */
- Nc[0] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[0] = sr & 0x3; sr >>= 2;
- Mc[0] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[0] = sr & 0x3f; sr >>= 6;
- xmc[0] = sr & 0x7; sr >>= 3;
- xmc[1] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[2] = sr & 0x7; sr >>= 3;
- xmc[3] = sr & 0x7; sr >>= 3;
- xmc[4] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[5] = sr & 0x7; sr >>= 3;
- xmc[6] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2; /* 10 */
- xmc[7] = sr & 0x7; sr >>= 3;
- xmc[8] = sr & 0x7; sr >>= 3;
- xmc[9] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[10] = sr & 0x7; sr >>= 3;
- xmc[11] = sr & 0x7; sr >>= 3;
- xmc[12] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[1] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[1] = sr & 0x3; sr >>= 2;
- Mc[1] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[1] = sr & 0x3f; sr >>= 6;
- xmc[13] = sr & 0x7; sr >>= 3;
- xmc[14] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 15 */
- xmc[15] = sr & 0x7; sr >>= 3;
- xmc[16] = sr & 0x7; sr >>= 3;
- xmc[17] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[18] = sr & 0x7; sr >>= 3;
- xmc[19] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[20] = sr & 0x7; sr >>= 3;
- xmc[21] = sr & 0x7; sr >>= 3;
- xmc[22] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[23] = sr & 0x7; sr >>= 3;
- xmc[24] = sr & 0x7; sr >>= 3;
- xmc[25] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[2] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1; /* 20 */
- bc[2] = sr & 0x3; sr >>= 2;
- Mc[2] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[2] = sr & 0x3f; sr >>= 6;
- xmc[26] = sr & 0x7; sr >>= 3;
- xmc[27] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[28] = sr & 0x7; sr >>= 3;
- xmc[29] = sr & 0x7; sr >>= 3;
- xmc[30] = sr & 0x7; sr >>= 3;
- sr = *c++;
- xmc[31] = sr & 0x7; sr >>= 3;
- xmc[32] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[33] = sr & 0x7; sr >>= 3;
- xmc[34] = sr & 0x7; sr >>= 3;
- xmc[35] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1; /* 25 */
- xmc[36] = sr & 0x7; sr >>= 3;
- xmc[37] = sr & 0x7; sr >>= 3;
- xmc[38] = sr & 0x7; sr >>= 3;
- sr = *c++;
- Nc[3] = sr & 0x7f; sr >>= 7;
- sr |= (uword)*c++ << 1;
- bc[3] = sr & 0x3; sr >>= 2;
- Mc[3] = sr & 0x3; sr >>= 2;
- sr |= (uword)*c++ << 5;
- xmaxc[3] = sr & 0x3f; sr >>= 6;
- xmc[39] = sr & 0x7; sr >>= 3;
- xmc[40] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[41] = sr & 0x7; sr >>= 3;
- xmc[42] = sr & 0x7; sr >>= 3;
- xmc[43] = sr & 0x7; sr >>= 3;
- sr = *c++; /* 30 */
- xmc[44] = sr & 0x7; sr >>= 3;
- xmc[45] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 2;
- xmc[46] = sr & 0x7; sr >>= 3;
- xmc[47] = sr & 0x7; sr >>= 3;
- xmc[48] = sr & 0x7; sr >>= 3;
- sr |= (uword)*c++ << 1;
- xmc[49] = sr & 0x7; sr >>= 3;
- xmc[50] = sr & 0x7; sr >>= 3;
- xmc[51] = sr & 0x7; sr >>= 3;
- writeGSM_33(d+33);
-
-}
diff --git a/1.2-netsec/frame.c b/1.2-netsec/frame.c
deleted file mode 100644
index fa5538f36..000000000
--- a/1.2-netsec/frame.c
+++ /dev/null
@@ -1,1301 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Frame manipulation routines
- *
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/cli.h"
-#include "asterisk/term.h"
-#include "asterisk/utils.h"
-
-#ifdef TRACE_FRAMES
-static int headers = 0;
-static struct ast_frame *headerlist = NULL;
-AST_MUTEX_DEFINE_STATIC(framelock);
-#endif
-
-#define SMOOTHER_SIZE 8000
-
-#define TYPE_HIGH 0x0
-#define TYPE_LOW 0x1
-#define TYPE_SILENCE 0x2
-#define TYPE_DONTSEND 0x3
-#define TYPE_MASK 0x3
-
-struct ast_format_list {
- int visible; /*!< Can we see this entry */
- int bits; /*!< bitmask value */
- char *name; /*!< short name */
- char *desc; /*!< Description */
-};
-
-struct ast_smoother {
- int size;
- int format;
- int readdata;
- int optimizablestream;
- int flags;
- float samplesperbyte;
- struct ast_frame f;
- struct timeval delivery;
- char data[SMOOTHER_SIZE];
- char framedata[SMOOTHER_SIZE + AST_FRIENDLY_OFFSET];
- struct ast_frame *opt;
- int len;
-};
-
-/*! \brief Definition of supported media formats (codecs) */
-static struct ast_format_list AST_FORMAT_LIST[] = {
- { 1, AST_FORMAT_G723_1 , "g723" , "G.723.1"}, /*!< codec_g723_1.c */
- { 1, AST_FORMAT_GSM, "gsm" , "GSM"}, /*!< codec_gsm.c */
- { 1, AST_FORMAT_ULAW, "ulaw", "G.711 u-law" }, /*!< codec_ulaw.c */
- { 1, AST_FORMAT_ALAW, "alaw", "G.711 A-law" }, /*!< codec_alaw.c */
- { 1, AST_FORMAT_G726, "g726", "G.726" }, /*!< codec_g726.c */
- { 1, AST_FORMAT_ADPCM, "adpcm" , "ADPCM"}, /*!< codec_adpcm.c */
- { 1, AST_FORMAT_SLINEAR, "slin", "16 bit Signed Linear PCM"}, /*!< */
- { 1, AST_FORMAT_LPC10, "lpc10", "LPC10" }, /*!< codec_lpc10.c */
- { 1, AST_FORMAT_G729A, "g729", "G.729A" }, /*!< Binary commercial distribution */
- { 1, AST_FORMAT_SPEEX, "speex", "SpeeX" }, /*!< codec_speex.c */
- { 1, AST_FORMAT_ILBC, "ilbc", "iLBC"}, /*!< codec_ilbc.c */
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, AST_FORMAT_MAX_AUDIO, "maxaudio", "Maximum audio format" },
- { 1, AST_FORMAT_JPEG, "jpeg", "JPEG image"}, /*!< See format_jpeg.c */
- { 1, AST_FORMAT_PNG, "png", "PNG image"}, /*!< Image format */
- { 1, AST_FORMAT_H261, "h261", "H.261 Video" }, /*!< Passthrough */
- { 1, AST_FORMAT_H263, "h263", "H.263 Video" }, /*!< Passthrough support, see format_h263.c */
- { 1, AST_FORMAT_H263_PLUS, "h263p", "H.263+ Video" }, /*!< See format_h263.c */
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, 0, "nothing", "undefined" },
- { 0, AST_FORMAT_MAX_VIDEO, "maxvideo", "Maximum video format" },
-};
-
-void ast_smoother_reset(struct ast_smoother *s, int size)
-{
- memset(s, 0, sizeof(struct ast_smoother));
- s->size = size;
-}
-
-struct ast_smoother *ast_smoother_new(int size)
-{
- struct ast_smoother *s;
- if (size < 1)
- return NULL;
- s = malloc(sizeof(struct ast_smoother));
- if (s)
- ast_smoother_reset(s, size);
- return s;
-}
-
-int ast_smoother_get_flags(struct ast_smoother *s)
-{
- return s->flags;
-}
-
-void ast_smoother_set_flags(struct ast_smoother *s, int flags)
-{
- s->flags = flags;
-}
-
-int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap)
-{
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Huh? Can't smooth a non-voice frame!\n");
- return -1;
- }
- if (!s->format) {
- s->format = f->subclass;
- s->samplesperbyte = (float)f->samples / (float)f->datalen;
- } else if (s->format != f->subclass) {
- ast_log(LOG_WARNING, "Smoother was working on %d format frames, now trying to feed %d?\n", s->format, f->subclass);
- return -1;
- }
- if (s->len + f->datalen > SMOOTHER_SIZE) {
- ast_log(LOG_WARNING, "Out of smoother space\n");
- return -1;
- }
- if (((f->datalen == s->size) || ((f->datalen < 10) && (s->flags & AST_SMOOTHER_FLAG_G729)))
- && !s->opt && (f->offset >= AST_MIN_OFFSET)) {
- if (!s->len) {
- /* Optimize by sending the frame we just got
- on the next read, thus eliminating the douple
- copy */
- s->opt = f;
- return 0;
- } else {
- s->optimizablestream++;
- if (s->optimizablestream > 10) {
- /* For the past 10 rounds, we have input and output
- frames of the correct size for this smoother, yet
- we were unable to optimize because there was still
- some cruft left over. Lets just drop the cruft so
- we can move to a fully optimized path */
- s->len = 0;
- s->opt = f;
- return 0;
- }
- }
- } else
- s->optimizablestream = 0;
- if (s->flags & AST_SMOOTHER_FLAG_G729) {
- if (s->len % 10) {
- ast_log(LOG_NOTICE, "Dropping extra frame of G.729 since we already have a VAD frame at the end\n");
- return 0;
- }
- }
- if (swap)
- ast_swapcopy_samples(s->data+s->len, f->data, f->samples);
- else
- memcpy(s->data + s->len, f->data, f->datalen);
- /* If either side is empty, reset the delivery time */
- if (!s->len || ast_tvzero(f->delivery) || ast_tvzero(s->delivery)) /* XXX really ? */
- s->delivery = f->delivery;
- s->len += f->datalen;
- return 0;
-}
-
-struct ast_frame *ast_smoother_read(struct ast_smoother *s)
-{
- struct ast_frame *opt;
- int len;
- /* IF we have an optimization frame, send it */
- if (s->opt) {
- if (s->opt->offset < AST_FRIENDLY_OFFSET)
- ast_log(LOG_WARNING, "Returning a frame of inappropriate offset (%d).",
- s->opt->offset);
- opt = s->opt;
- s->opt = NULL;
- return opt;
- }
-
- /* Make sure we have enough data */
- if (s->len < s->size) {
- /* Or, if this is a G.729 frame with VAD on it, send it immediately anyway */
- if (!((s->flags & AST_SMOOTHER_FLAG_G729) && (s->size % 10)))
- return NULL;
- }
- len = s->size;
- if (len > s->len)
- len = s->len;
- /* Make frame */
- s->f.frametype = AST_FRAME_VOICE;
- s->f.subclass = s->format;
- s->f.data = s->framedata + AST_FRIENDLY_OFFSET;
- s->f.offset = AST_FRIENDLY_OFFSET;
- s->f.datalen = len;
- /* Samples will be improper given VAD, but with VAD the concept really doesn't even exist */
- s->f.samples = len * s->samplesperbyte; /* XXX rounding */
- s->f.delivery = s->delivery;
- /* Fill Data */
- memcpy(s->f.data, s->data, len);
- s->len -= len;
- /* Move remaining data to the front if applicable */
- if (s->len) {
- /* In principle this should all be fine because if we are sending
- G.729 VAD, the next timestamp will take over anyawy */
- memmove(s->data, s->data + len, s->len);
- if (!ast_tvzero(s->delivery)) {
- /* If we have delivery time, increment it, otherwise, leave it at 0 */
- s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, 8000));
- }
- }
- /* Return frame */
- return &s->f;
-}
-
-void ast_smoother_free(struct ast_smoother *s)
-{
- free(s);
-}
-
-static struct ast_frame *ast_frame_header_new(void)
-{
- struct ast_frame *f;
- f = malloc(sizeof(struct ast_frame));
- if (f)
- memset(f, 0, sizeof(struct ast_frame));
-#ifdef TRACE_FRAMES
- if (f) {
- headers++;
- f->prev = NULL;
- ast_mutex_lock(&framelock);
- f->next = headerlist;
- if (headerlist)
- headerlist->prev = f;
- headerlist = f;
- ast_mutex_unlock(&framelock);
- }
-#endif
- return f;
-}
-
-/*!
- * \todo Important: I should be made more efficient. Frame headers should
- * most definitely be cached
- */
-void ast_frfree(struct ast_frame *fr)
-{
- if (fr->mallocd & AST_MALLOCD_DATA) {
- if (fr->data)
- free(fr->data - fr->offset);
- }
- if (fr->mallocd & AST_MALLOCD_SRC) {
- if (fr->src)
- free((char *)fr->src);
- }
- if (fr->mallocd & AST_MALLOCD_HDR) {
-#ifdef TRACE_FRAMES
- headers--;
- ast_mutex_lock(&framelock);
- if (fr->next)
- fr->next->prev = fr->prev;
- if (fr->prev)
- fr->prev->next = fr->next;
- else
- headerlist = fr->next;
- ast_mutex_unlock(&framelock);
-#endif
- free(fr);
- }
-}
-
-/*!
- * \brief 'isolates' a frame by duplicating non-malloc'ed components
- * (header, src, data).
- * On return all components are malloc'ed
- */
-struct ast_frame *ast_frisolate(struct ast_frame *fr)
-{
- struct ast_frame *out;
- if (!(fr->mallocd & AST_MALLOCD_HDR)) {
- /* Allocate a new header if needed */
- out = ast_frame_header_new();
- if (!out) {
- ast_log(LOG_WARNING, "Out of memory\n");
- return NULL;
- }
- out->frametype = fr->frametype;
- out->subclass = fr->subclass;
- out->datalen = fr->datalen;
- out->samples = fr->samples;
- out->offset = fr->offset;
- out->src = NULL;
- out->data = fr->data;
- } else {
- out = fr;
- }
- if (!(fr->mallocd & AST_MALLOCD_SRC)) {
- if (fr->src)
- out->src = strdup(fr->src);
- } else
- out->src = fr->src;
- if (!(fr->mallocd & AST_MALLOCD_DATA)) {
- out->data = malloc(fr->datalen + AST_FRIENDLY_OFFSET);
- if (!out->data) {
- free(out);
- ast_log(LOG_WARNING, "Out of memory\n");
- return NULL;
- }
- out->data += AST_FRIENDLY_OFFSET;
- out->offset = AST_FRIENDLY_OFFSET;
- out->datalen = fr->datalen;
- memcpy(out->data, fr->data, fr->datalen);
- }
- out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA;
- return out;
-}
-
-struct ast_frame *ast_frdup(struct ast_frame *f)
-{
- struct ast_frame *out;
- int len, srclen = 0;
- void *buf;
- /* Start with standard stuff */
- len = sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET + f->datalen;
- /* If we have a source, add space for it */
- /*
- * XXX Watch out here - if we receive a src which is not terminated
- * properly, we can be easily attacked. Should limit the size we deal with.
- */
- if (f->src)
- srclen = strlen(f->src);
- if (srclen > 0)
- len += srclen + 1;
- buf = malloc(len);
- if (!buf)
- return NULL;
- out = buf;
- /* Set us as having malloc'd header only, so it will eventually
- get freed. */
- out->frametype = f->frametype;
- out->subclass = f->subclass;
- out->datalen = f->datalen;
- out->samples = f->samples;
- out->delivery = f->delivery;
- out->mallocd = AST_MALLOCD_HDR;
- out->offset = AST_FRIENDLY_OFFSET;
- out->data = buf + sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET;
- if (srclen > 0) {
- out->src = out->data + f->datalen;
- /* Must have space since we allocated for it */
- strcpy((char *)out->src, f->src);
- } else
- out->src = NULL;
- out->prev = NULL;
- out->next = NULL;
- memcpy(out->data, f->data, out->datalen);
- return out;
-}
-
-#if 0
-/*
- * XXX
- * This function is badly broken - it does not handle correctly
- * partial reads on either header or body.
- * However is it never used anywhere so we leave it commented out
- */
-struct ast_frame *ast_fr_fdread(int fd)
-{
- char buf[65536];
- int res;
- int ttl = sizeof(struct ast_frame);
- struct ast_frame *f = (struct ast_frame *)buf;
- /* Read a frame directly from there. They're always in the
- right format. */
-
- while(ttl) {
- res = read(fd, buf, ttl);
- if (res < 0) {
- ast_log(LOG_WARNING, "Bad read on %d: %s\n", fd, strerror(errno));
- return NULL;
- }
- ttl -= res;
- }
-
- /* read the frame header */
- f->mallocd = 0;
- /* Re-write data position */
- f->data = buf + sizeof(struct ast_frame);
- f->offset = 0;
- /* Forget about being mallocd */
- f->mallocd = 0;
- /* Re-write the source */
- f->src = (char *)__FUNCTION__;
- if (f->datalen > sizeof(buf) - sizeof(struct ast_frame)) {
- /* Really bad read */
- ast_log(LOG_WARNING, "Strange read (%d bytes)\n", f->datalen);
- return NULL;
- }
- if (f->datalen) {
- if ((res = read(fd, f->data, f->datalen)) != f->datalen) {
- /* Bad read */
- ast_log(LOG_WARNING, "How very strange, expected %d, got %d\n", f->datalen, res);
- return NULL;
- }
- }
- if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) {
- return NULL;
- }
- return ast_frisolate(f);
-}
-
-/* Some convenient routines for sending frames to/from stream or datagram
- sockets, pipes, etc (maybe even files) */
-
-/*
- * XXX this function is also partly broken because it does not handle
- * partial writes. We comment it out too, and also the unique
- * client it has, ast_fr_fdhangup()
- */
-int ast_fr_fdwrite(int fd, struct ast_frame *frame)
-{
- /* Write the frame exactly */
- if (write(fd, frame, sizeof(struct ast_frame)) != sizeof(struct ast_frame)) {
- ast_log(LOG_WARNING, "Write error: %s\n", strerror(errno));
- return -1;
- }
- if (write(fd, frame->data, frame->datalen) != frame->datalen) {
- ast_log(LOG_WARNING, "Write error: %s\n", strerror(errno));
- return -1;
- }
- return 0;
-}
-
-int ast_fr_fdhangup(int fd)
-{
- struct ast_frame hangup = {
- AST_FRAME_CONTROL,
- AST_CONTROL_HANGUP
- };
- return ast_fr_fdwrite(fd, &hangup);
-}
-
-#endif /* unused functions */
-void ast_swapcopy_samples(void *dst, const void *src, int samples)
-{
- int i;
- unsigned short *dst_s = dst;
- const unsigned short *src_s = src;
-
- for (i=0; i<samples; i++)
- dst_s[i] = (src_s[i]<<8) | (src_s[i]>>8);
-}
-
-
-struct ast_format_list *ast_get_format_list_index(int index)
-{
- return &AST_FORMAT_LIST[index];
-}
-
-struct ast_format_list *ast_get_format_list(size_t *size)
-{
- *size = (sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list));
- return AST_FORMAT_LIST;
-}
-
-char* ast_getformatname(int format)
-{
- int x = 0;
- char *ret = "unknown";
- for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
- if(AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == format) {
- ret = AST_FORMAT_LIST[x].name;
- break;
- }
- }
- return ret;
-}
-
-char *ast_getformatname_multiple(char *buf, size_t size, int format) {
-
- int x = 0;
- unsigned len;
- char *end = buf;
- char *start = buf;
- if (!size) return buf;
- snprintf(end, size, "0x%x (", format);
- len = strlen(end);
- end += len;
- size -= len;
- start = end;
- for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
- if (AST_FORMAT_LIST[x].visible && (AST_FORMAT_LIST[x].bits & format)) {
- snprintf(end, size,"%s|",AST_FORMAT_LIST[x].name);
- len = strlen(end);
- end += len;
- size -= len;
- }
- }
- if (start == end)
- snprintf(start, size, "nothing)");
- else if (size > 1)
- *(end -1) = ')';
- return buf;
-}
-
-static struct ast_codec_alias_table {
- char *alias;
- char *realname;
-
-} ast_codec_alias_table[] = {
- {"slinear","slin"},
- {"g723.1","g723"},
-};
-
-static char *ast_expand_codec_alias(char *in) {
- int x = 0;
-
- for (x = 0; x < sizeof(ast_codec_alias_table) / sizeof(struct ast_codec_alias_table) ; x++) {
- if(!strcmp(in,ast_codec_alias_table[x].alias))
- return ast_codec_alias_table[x].realname;
- }
- return in;
-}
-
-int ast_getformatbyname(char *name)
-{
- int x = 0, all = 0, format = 0;
-
- all = strcasecmp(name, "all") ? 0 : 1;
- for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
- if(AST_FORMAT_LIST[x].visible && (all ||
- !strcasecmp(AST_FORMAT_LIST[x].name,name) ||
- !strcasecmp(AST_FORMAT_LIST[x].name,ast_expand_codec_alias(name)))) {
- format |= AST_FORMAT_LIST[x].bits;
- if(!all)
- break;
- }
- }
-
- return format;
-}
-
-char *ast_codec2str(int codec) {
- int x = 0;
- char *ret = "unknown";
- for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
- if(AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == codec) {
- ret = AST_FORMAT_LIST[x].desc;
- break;
- }
- }
- return ret;
-}
-
-static int show_codecs(int fd, int argc, char *argv[])
-{
- int i, found=0;
- char hex[25];
-
- if ((argc < 2) || (argc > 3))
- return RESULT_SHOWUSAGE;
-
- if (!option_dontwarn)
- ast_cli(fd, "Disclaimer: this command is for informational purposes only.\n"
- "\tIt does not indicate anything about your configuration.\n");
-
- ast_cli(fd, "%11s %9s %10s TYPE %5s %s\n","INT","BINARY","HEX","NAME","DESC");
- ast_cli(fd, "--------------------------------------------------------------------------------\n");
- if ((argc == 2) || (!strcasecmp(argv[1],"audio"))) {
- found = 1;
- for (i=0;i<11;i++) {
- snprintf(hex,25,"(0x%x)",1<<i);
- ast_cli(fd, "%11u (1 << %2d) %10s audio %5s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
- }
- }
-
- if ((argc == 2) || (!strcasecmp(argv[1],"image"))) {
- found = 1;
- for (i=16;i<18;i++) {
- snprintf(hex,25,"(0x%x)",1<<i);
- ast_cli(fd, "%11u (1 << %2d) %10s image %5s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
- }
- }
-
- if ((argc == 2) || (!strcasecmp(argv[1],"video"))) {
- found = 1;
- for (i=18;i<21;i++) {
- snprintf(hex,25,"(0x%x)",1<<i);
- ast_cli(fd, "%11u (1 << %2d) %10s video %5s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
- }
- }
-
- if (! found)
- return RESULT_SHOWUSAGE;
- else
- return RESULT_SUCCESS;
-}
-
-static char frame_show_codecs_usage[] =
-"Usage: show [audio|video|image] codecs\n"
-" Displays codec mapping\n";
-
-static int show_codec_n(int fd, int argc, char *argv[])
-{
- int codec, i, found=0;
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
-
- if (sscanf(argv[2],"%d",&codec) != 1)
- return RESULT_SHOWUSAGE;
-
- for (i=0;i<32;i++)
- if (codec & (1 << i)) {
- found = 1;
- ast_cli(fd, "%11u (1 << %2d) %s\n",1 << i,i,ast_codec2str(1<<i));
- }
-
- if (! found)
- ast_cli(fd, "Codec %d not found\n", codec);
-
- return RESULT_SUCCESS;
-}
-
-static char frame_show_codec_n_usage[] =
-"Usage: show codec <number>\n"
-" Displays codec mapping\n";
-
-/*! Dump a frame for debugging purposes */
-void ast_frame_dump(char *name, struct ast_frame *f, char *prefix)
-{
- char *n = "unknown";
- char ftype[40] = "Unknown Frametype";
- char cft[80];
- char subclass[40] = "Unknown Subclass";
- char csub[80];
- char moreinfo[40] = "";
- char cn[60];
- char cp[40];
- char cmn[40];
- if (name)
- n = name;
- if (!f) {
- ast_verbose("%s [ %s (NULL) ] [%s]\n",
- term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
- term_color(cft, "HANGUP", COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
- term_color(cn, n, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
- return;
- }
- /* XXX We should probably print one each of voice and video when the format changes XXX */
- if (f->frametype == AST_FRAME_VOICE)
- return;
- if (f->frametype == AST_FRAME_VIDEO)
- return;
- switch(f->frametype) {
- case AST_FRAME_DTMF:
- strcpy(ftype, "DTMF");
- subclass[0] = f->subclass;
- subclass[1] = '\0';
- break;
- case AST_FRAME_CONTROL:
- strcpy(ftype, "Control");
- switch(f->subclass) {
- case AST_CONTROL_HANGUP:
- strcpy(subclass, "Hangup");
- break;
- case AST_CONTROL_RING:
- strcpy(subclass, "Ring");
- break;
- case AST_CONTROL_RINGING:
- strcpy(subclass, "Ringing");
- break;
- case AST_CONTROL_ANSWER:
- strcpy(subclass, "Answer");
- break;
- case AST_CONTROL_BUSY:
- strcpy(subclass, "Busy");
- break;
- case AST_CONTROL_TAKEOFFHOOK:
- strcpy(subclass, "Take Off Hook");
- break;
- case AST_CONTROL_OFFHOOK:
- strcpy(subclass, "Line Off Hook");
- break;
- case AST_CONTROL_CONGESTION:
- strcpy(subclass, "Congestion");
- break;
- case AST_CONTROL_FLASH:
- strcpy(subclass, "Flash");
- break;
- case AST_CONTROL_WINK:
- strcpy(subclass, "Wink");
- break;
- case AST_CONTROL_OPTION:
- strcpy(subclass, "Option");
- break;
- case AST_CONTROL_RADIO_KEY:
- strcpy(subclass, "Key Radio");
- break;
- case AST_CONTROL_RADIO_UNKEY:
- strcpy(subclass, "Unkey Radio");
- break;
- case -1:
- strcpy(subclass, "Stop generators");
- break;
- default:
- snprintf(subclass, sizeof(subclass), "Unknown control '%d'", f->subclass);
- }
- break;
- case AST_FRAME_NULL:
- strcpy(ftype, "Null Frame");
- strcpy(subclass, "N/A");
- break;
- case AST_FRAME_IAX:
- /* Should never happen */
- strcpy(ftype, "IAX Specific");
- snprintf(subclass, sizeof(subclass), "IAX Frametype %d", f->subclass);
- break;
- case AST_FRAME_TEXT:
- strcpy(ftype, "Text");
- strcpy(subclass, "N/A");
- ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
- break;
- case AST_FRAME_IMAGE:
- strcpy(ftype, "Image");
- snprintf(subclass, sizeof(subclass), "Image format %s\n", ast_getformatname(f->subclass));
- break;
- case AST_FRAME_HTML:
- strcpy(ftype, "HTML");
- switch(f->subclass) {
- case AST_HTML_URL:
- strcpy(subclass, "URL");
- ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
- break;
- case AST_HTML_DATA:
- strcpy(subclass, "Data");
- break;
- case AST_HTML_BEGIN:
- strcpy(subclass, "Begin");
- break;
- case AST_HTML_END:
- strcpy(subclass, "End");
- break;
- case AST_HTML_LDCOMPLETE:
- strcpy(subclass, "Load Complete");
- break;
- case AST_HTML_NOSUPPORT:
- strcpy(subclass, "No Support");
- break;
- case AST_HTML_LINKURL:
- strcpy(subclass, "Link URL");
- ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
- break;
- case AST_HTML_UNLINK:
- strcpy(subclass, "Unlink");
- break;
- case AST_HTML_LINKREJECT:
- strcpy(subclass, "Link Reject");
- break;
- default:
- snprintf(subclass, sizeof(subclass), "Unknown HTML frame '%d'\n", f->subclass);
- break;
- }
- break;
- default:
- snprintf(ftype, sizeof(ftype), "Unknown Frametype '%d'", f->frametype);
- }
- if (!ast_strlen_zero(moreinfo))
- ast_verbose("%s [ TYPE: %s (%d) SUBCLASS: %s (%d) '%s' ] [%s]\n",
- term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
- term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
- f->frametype,
- term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
- f->subclass,
- term_color(cmn, moreinfo, COLOR_BRGREEN, COLOR_BLACK, sizeof(cmn)),
- term_color(cn, n, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
- else
- ast_verbose("%s [ TYPE: %s (%d) SUBCLASS: %s (%d) ] [%s]\n",
- term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
- term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
- f->frametype,
- term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
- f->subclass,
- term_color(cn, n, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
-
-}
-
-
-#ifdef TRACE_FRAMES
-static int show_frame_stats(int fd, int argc, char *argv[])
-{
- struct ast_frame *f;
- int x=1;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, " Framer Statistics \n");
- ast_cli(fd, "---------------------------\n");
- ast_cli(fd, "Total allocated headers: %d\n", headers);
- ast_cli(fd, "Queue Dump:\n");
- ast_mutex_lock(&framelock);
- for (f=headerlist; f; f = f->next) {
- ast_cli(fd, "%d. Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>");
- }
- ast_mutex_unlock(&framelock);
- return RESULT_SUCCESS;
-}
-
-static char frame_stats_usage[] =
-"Usage: show frame stats\n"
-" Displays debugging statistics from framer\n";
-#endif
-
-/* Builtin Asterisk CLI-commands for debugging */
-static struct ast_cli_entry my_clis[] = {
-{ { "show", "codecs", NULL }, show_codecs, "Shows codecs", frame_show_codecs_usage },
-{ { "show", "audio", "codecs", NULL }, show_codecs, "Shows audio codecs", frame_show_codecs_usage },
-{ { "show", "video", "codecs", NULL }, show_codecs, "Shows video codecs", frame_show_codecs_usage },
-{ { "show", "image", "codecs", NULL }, show_codecs, "Shows image codecs", frame_show_codecs_usage },
-{ { "show", "codec", NULL }, show_codec_n, "Shows a specific codec", frame_show_codec_n_usage },
-#ifdef TRACE_FRAMES
-{ { "show", "frame", "stats", NULL }, show_frame_stats, "Shows frame statistics", frame_stats_usage },
-#endif
-};
-
-int init_framer(void)
-{
- ast_cli_register_multiple(my_clis, sizeof(my_clis)/sizeof(my_clis[0]) );
- return 0;
-}
-
-void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right)
-{
- int x = 0, differential = (int) 'A', mem = 0;
- char *from = NULL, *to = NULL;
-
- if(right) {
- from = pref->order;
- to = buf;
- mem = size;
- } else {
- to = pref->order;
- from = buf;
- mem = 32;
- }
-
- memset(to, 0, mem);
- for (x = 0; x < 32 ; x++) {
- if(!from[x])
- break;
- to[x] = right ? (from[x] + differential) : (from[x] - differential);
- }
-}
-
-int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size)
-{
- int x = 0, codec = 0;
- size_t total_len = 0, slen = 0;
- char *formatname = 0;
-
- memset(buf,0,size);
- total_len = size;
- buf[0] = '(';
- total_len--;
- for(x = 0; x < 32 ; x++) {
- if(total_len <= 0)
- break;
- if(!(codec = ast_codec_pref_index(pref,x)))
- break;
- if((formatname = ast_getformatname(codec))) {
- slen = strlen(formatname);
- if(slen > total_len)
- break;
- strncat(buf,formatname,total_len);
- total_len -= slen;
- }
- if(total_len && x < 31 && ast_codec_pref_index(pref , x + 1)) {
- strncat(buf,"|",total_len);
- total_len--;
- }
- }
- if(total_len) {
- strncat(buf,")",total_len);
- total_len--;
- }
-
- return size - total_len;
-}
-
-int ast_codec_pref_index(struct ast_codec_pref *pref, int index)
-{
- int slot = 0;
-
-
- if((index >= 0) && (index < sizeof(pref->order))) {
- slot = pref->order[index];
- }
-
- return slot ? AST_FORMAT_LIST[slot-1].bits : 0;
-}
-
-/*! \brief ast_codec_pref_remove: Remove codec from pref list ---*/
-void ast_codec_pref_remove(struct ast_codec_pref *pref, int format)
-{
- struct ast_codec_pref oldorder;
- int x=0, y=0;
- size_t size = 0;
- int slot = 0;
-
- if(!pref->order[0])
- return;
-
- size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
-
- memcpy(&oldorder,pref,sizeof(struct ast_codec_pref));
- memset(pref,0,sizeof(struct ast_codec_pref));
-
- for (x = 0; x < size; x++) {
- slot = oldorder.order[x];
- if(! slot)
- break;
- if(AST_FORMAT_LIST[slot-1].bits != format)
- pref->order[y++] = slot;
- }
-
-}
-
-/*! \brief ast_codec_pref_append: Append codec to list ---*/
-int ast_codec_pref_append(struct ast_codec_pref *pref, int format)
-{
- size_t size = 0;
- int x = 0, newindex = -1;
-
- ast_codec_pref_remove(pref, format);
- size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
-
- for (x = 0; x < size; x++) {
- if(AST_FORMAT_LIST[x].bits == format) {
- newindex = x + 1;
- break;
- }
- }
-
- if(newindex) {
- for (x = 0; x < size; x++) {
- if(!pref->order[x]) {
- pref->order[x] = newindex;
- break;
- }
- }
- }
-
- return x;
-}
-
-
-/*! \brief ast_codec_choose: Pick a codec ---*/
-int ast_codec_choose(struct ast_codec_pref *pref, int formats, int find_best)
-{
- size_t size = 0;
- int x = 0, ret = 0, slot = 0;
-
- size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
- for (x = 0; x < size; x++) {
- slot = pref->order[x];
-
- if(!slot)
- break;
- if ( formats & AST_FORMAT_LIST[slot-1].bits ) {
- ret = AST_FORMAT_LIST[slot-1].bits;
- break;
- }
- }
- if(ret)
- return ret;
-
- return find_best ? ast_best_codec(formats) : 0;
-}
-
-void ast_parse_allow_disallow(struct ast_codec_pref *pref, int *mask, const char *list, int allowing)
-{
- char *parse;
- char *this;
- int format;
-
- parse = ast_strdupa(list);
- while ((this = strsep(&parse, ","))) {
- if (!(format = ast_getformatbyname(this))) {
- ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", allowing ? "allow" : "disallow", this);
- continue;
- }
-
- if (mask) {
- if (allowing)
- *mask |= format;
- else
- *mask &= ~format;
- }
-
- if (pref) {
- if (strcasecmp(this, "all")) {
- if (allowing)
- ast_codec_pref_append(pref, format);
- else
- ast_codec_pref_remove(pref, format);
- } else if (!allowing) {
- memset(pref, 0, sizeof(*pref));
- }
- }
- }
-}
-
-static int g723_len(unsigned char buf)
-{
- switch(buf & TYPE_MASK) {
- case TYPE_DONTSEND:
- return 0;
- break;
- case TYPE_SILENCE:
- return 4;
- break;
- case TYPE_HIGH:
- return 24;
- break;
- case TYPE_LOW:
- return 20;
- break;
- default:
- ast_log(LOG_WARNING, "Badly encoded frame (%d)\n", buf & TYPE_MASK);
- }
- return -1;
-}
-
-static int g723_samples(unsigned char *buf, int maxlen)
-{
- int pos = 0;
- int samples = 0;
- int res;
- while(pos < maxlen) {
- res = g723_len(buf[pos]);
- if (res <= 0)
- break;
- samples += 240;
- pos += res;
- }
- return samples;
-}
-
-static unsigned char get_n_bits_at(unsigned char *data, int n, int bit)
-{
- int byte = bit / 8; /* byte containing first bit */
- int rem = 8 - (bit % 8); /* remaining bits in first byte */
- unsigned char ret = 0;
-
- if (n <= 0 || n > 8)
- return 0;
-
- if (rem < n) {
- ret = (data[byte] << (n - rem));
- ret |= (data[byte + 1] >> (8 - n + rem));
- } else {
- ret = (data[byte] >> (rem - n));
- }
-
- return (ret & (0xff >> (8 - n)));
-}
-
-static int speex_get_wb_sz_at(unsigned char *data, int len, int bit)
-{
- static int SpeexWBSubModeSz[] = {
- 0, 36, 112, 192,
- 352, 0, 0, 0 };
- int off = bit;
- unsigned char c;
-
- /* skip up to two wideband frames */
- if (((len * 8 - off) >= 5) &&
- get_n_bits_at(data, 1, off)) {
- c = get_n_bits_at(data, 3, off + 1);
- off += SpeexWBSubModeSz[c];
-
- if (((len * 8 - off) >= 5) &&
- get_n_bits_at(data, 1, off)) {
- c = get_n_bits_at(data, 3, off + 1);
- off += SpeexWBSubModeSz[c];
-
- if (((len * 8 - off) >= 5) &&
- get_n_bits_at(data, 1, off)) {
- ast_log(LOG_WARNING, "Encountered corrupt speex frame; too many wideband frames in a row.\n");
- return -1;
- }
- }
-
- }
- return off - bit;
-}
-
-static int speex_samples(unsigned char *data, int len)
-{
- static int SpeexSubModeSz[] = {
- 5, 43, 119, 160,
- 220, 300, 364, 492,
- 79, 0, 0, 0,
- 0, 0, 0, 0 };
- static int SpeexInBandSz[] = {
- 1, 1, 4, 4,
- 4, 4, 4, 4,
- 8, 8, 16, 16,
- 32, 32, 64, 64 };
- int bit = 0;
- int cnt = 0;
- int off = 0;
- unsigned char c;
-
- while ((len * 8 - bit) >= 5) {
- /* skip wideband frames */
- off = speex_get_wb_sz_at(data, len, bit);
- if (off < 0) {
- ast_log(LOG_WARNING, "Had error while reading wideband frames for speex samples\n");
- break;
- }
- bit += off;
-
- if ((len * 8 - bit) < 5) {
- ast_log(LOG_WARNING, "Not enough bits remaining after wide band for speex samples.\n");
- break;
- }
-
- /* get control bits */
- c = get_n_bits_at(data, 5, bit);
- bit += 5;
-
- if (c == 15) {
- /* terminator */
- break;
- } else if (c == 14) {
- /* in-band signal; next 4 bits contain signal id */
- c = get_n_bits_at(data, 4, bit);
- bit += 4;
- bit += SpeexInBandSz[c];
- } else if (c == 13) {
- /* user in-band; next 5 bits contain msg len */
- c = get_n_bits_at(data, 5, bit);
- bit += 5;
- bit += c * 8;
- } else if (c > 8) {
- /* unknown */
- break;
- } else {
- /* skip number bits for submode (less the 5 control bits) */
- bit += SpeexSubModeSz[c] - 5;
- cnt += 160; /* new frame */
- }
- }
- return cnt;
-}
-
-int ast_codec_get_samples(struct ast_frame *f)
-{
- int samples=0;
- switch(f->subclass) {
- case AST_FORMAT_SPEEX:
- samples = speex_samples(f->data, f->datalen);
- break;
- case AST_FORMAT_G723_1:
- samples = g723_samples(f->data, f->datalen);
- break;
- case AST_FORMAT_ILBC:
- samples = 240 * (f->datalen / 50);
- break;
- case AST_FORMAT_GSM:
- samples = 160 * (f->datalen / 33);
- break;
- case AST_FORMAT_G729A:
- samples = f->datalen * 8;
- break;
- case AST_FORMAT_SLINEAR:
- samples = f->datalen / 2;
- break;
- case AST_FORMAT_LPC10:
- /* assumes that the RTP packet contains one LPC10 frame */
- samples = 22 * 8;
- samples += (((char *)(f->data))[7] & 0x1) * 8;
- break;
- case AST_FORMAT_ULAW:
- case AST_FORMAT_ALAW:
- samples = f->datalen;
- break;
- case AST_FORMAT_ADPCM:
- case AST_FORMAT_G726:
- samples = f->datalen * 2;
- break;
- default:
- ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname(f->subclass));
- }
- return samples;
-}
-
-int ast_codec_get_len(int format, int samples)
-{
- int len = 0;
-
- /* XXX Still need speex, g723, and lpc10 XXX */
- switch(format) {
- case AST_FORMAT_ILBC:
- len = (samples / 240) * 50;
- break;
- case AST_FORMAT_GSM:
- len = (samples / 160) * 33;
- break;
- case AST_FORMAT_G729A:
- len = samples / 8;
- break;
- case AST_FORMAT_SLINEAR:
- len = samples * 2;
- break;
- case AST_FORMAT_ULAW:
- case AST_FORMAT_ALAW:
- len = samples;
- break;
- case AST_FORMAT_ADPCM:
- case AST_FORMAT_G726:
- len = samples / 2;
- break;
- default:
- ast_log(LOG_WARNING, "Unable to calculate sample length for format %s\n", ast_getformatname(format));
- }
-
- return len;
-}
-
-int ast_frame_adjust_volume(struct ast_frame *f, int adjustment)
-{
- int count;
- short *fdata = f->data;
- short adjust_value = abs(adjustment);
-
- if ((f->frametype != AST_FRAME_VOICE) || (f->subclass != AST_FORMAT_SLINEAR))
- return -1;
-
- if (!adjustment)
- return 0;
-
- for (count = 0; count < f->samples; count++) {
- if (adjustment > 0) {
- ast_slinear_saturated_multiply(&fdata[count], &adjust_value);
- } else if (adjustment < 0) {
- ast_slinear_saturated_divide(&fdata[count], &adjust_value);
- }
- }
-
- return 0;
-}
-
-int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2)
-{
- int count;
- short *data1, *data2;
-
- if ((f1->frametype != AST_FRAME_VOICE) || (f1->subclass != AST_FORMAT_SLINEAR))
- return -1;
-
- if ((f2->frametype != AST_FRAME_VOICE) || (f2->subclass != AST_FORMAT_SLINEAR))
- return -1;
-
- if (f1->samples != f2->samples)
- return -1;
-
- for (count = 0, data1 = f1->data, data2 = f2->data;
- count < f1->samples;
- count++, data1++, data2++)
- ast_slinear_saturated_add(data1, data2);
-
- return 0;
-}
diff --git a/1.2-netsec/fskmodem.c b/1.2-netsec/fskmodem.c
deleted file mode 100644
index 18e845c1e..000000000
--- a/1.2-netsec/fskmodem.c
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Includes code and algorithms from the Zapata library.
- *
- * 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 FSK Modulator/Demodulator
- *
- */
-
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/fskmodem.h"
-
-#define NBW 2
-#define BWLIST {75,800}
-#define NF 6
-#define FLIST {1400,1800,1200,2200,1300,2100}
-
-#define STATE_SEARCH_STARTBIT 0
-#define STATE_SEARCH_STARTBIT2 1
-#define STATE_SEARCH_STARTBIT3 2
-#define STATE_GET_BYTE 3
-
-static inline float get_sample(short **buffer, int *len)
-{
- float retval;
- retval = (float) **buffer / 256;
- (*buffer)++;
- (*len)--;
- return retval;
-}
-
-#define GET_SAMPLE get_sample(&buffer, len)
-
-/* Coeficientes para filtros de entrada */
-/* Tabla de coeficientes, generada a partir del programa "mkfilter" */
-/* Formato: coef[IDX_FREC][IDX_BW][IDX_COEF] */
-/* IDX_COEF=0 => 1/GAIN */
-/* IDX_COEF=1-6 => Coeficientes y[n] */
-
-static double coef_in[NF][NBW][8]={
-#include "coef_in.h"
-};
-
-/* Coeficientes para filtro de salida */
-/* Tabla de coeficientes, generada a partir del programa "mkfilter" */
-/* Formato: coef[IDX_BW][IDX_COEF] */
-/* IDX_COEF=0 => 1/GAIN */
-/* IDX_COEF=1-6 => Coeficientes y[n] */
-
-static double coef_out[NBW][8]={
-#include "coef_out.h"
-};
-
-
-/*! Filtro pasa-banda para frecuencia de MARCA */
-static inline float filtroM(fsk_data *fskd,float in)
-{
- int i,j;
- double s;
- double *pc;
-
- pc=&coef_in[fskd->f_mark_idx][fskd->bw][0];
- fskd->fmxv[(fskd->fmp+6)&7]=in*(*pc++);
-
- s=(fskd->fmxv[(fskd->fmp+6)&7] - fskd->fmxv[fskd->fmp]) + 3 * (fskd->fmxv[(fskd->fmp+2)&7] - fskd->fmxv[(fskd->fmp+4)&7]);
- for (i=0,j=fskd->fmp;i<6;i++,j++) s+=fskd->fmyv[j&7]*(*pc++);
- fskd->fmyv[j&7]=s;
- fskd->fmp++; fskd->fmp&=7;
- return s;
-}
-
-/*! Filtro pasa-banda para frecuencia de ESPACIO */
-static inline float filtroS(fsk_data *fskd,float in)
-{
- int i,j;
- double s;
- double *pc;
-
- pc=&coef_in[fskd->f_space_idx][fskd->bw][0];
- fskd->fsxv[(fskd->fsp+6)&7]=in*(*pc++);
-
- s=(fskd->fsxv[(fskd->fsp+6)&7] - fskd->fsxv[fskd->fsp]) + 3 * (fskd->fsxv[(fskd->fsp+2)&7] - fskd->fsxv[(fskd->fsp+4)&7]);
- for (i=0,j=fskd->fsp;i<6;i++,j++) s+=fskd->fsyv[j&7]*(*pc++);
- fskd->fsyv[j&7]=s;
- fskd->fsp++; fskd->fsp&=7;
- return s;
-}
-
-/*! Filtro pasa-bajos para datos demodulados */
-static inline float filtroL(fsk_data *fskd,float in)
-{
- int i,j;
- double s;
- double *pc;
-
- pc=&coef_out[fskd->bw][0];
- fskd->flxv[(fskd->flp + 6) & 7]=in * (*pc++);
-
- s= (fskd->flxv[fskd->flp] + fskd->flxv[(fskd->flp+6)&7]) +
- 6 * (fskd->flxv[(fskd->flp+1)&7] + fskd->flxv[(fskd->flp+5)&7]) +
- 15 * (fskd->flxv[(fskd->flp+2)&7] + fskd->flxv[(fskd->flp+4)&7]) +
- 20 * fskd->flxv[(fskd->flp+3)&7];
-
- for (i=0,j=fskd->flp;i<6;i++,j++) s+=fskd->flyv[j&7]*(*pc++);
- fskd->flyv[j&7]=s;
- fskd->flp++; fskd->flp&=7;
- return s;
-}
-
-static inline int demodulador(fsk_data *fskd, float *retval, float x)
-{
- float xS,xM;
-
- fskd->cola_in[fskd->pcola]=x;
-
- xS=filtroS(fskd,x);
- xM=filtroM(fskd,x);
-
- fskd->cola_filtro[fskd->pcola]=xM-xS;
-
- x=filtroL(fskd,xM*xM - xS*xS);
-
- fskd->cola_demod[fskd->pcola++]=x;
- fskd->pcola &= (NCOLA-1);
-
- *retval = x;
- return(0);
-}
-
-static int get_bit_raw(fsk_data *fskd, short *buffer, int *len)
-{
- /* Esta funcion implementa un DPLL para sincronizarse con los bits */
- float x,spb,spb2,ds;
- int f;
-
- spb=fskd->spb;
- if (fskd->spb == 7) spb = 8000.0 / 1200.0;
- ds=spb/32.;
- spb2=spb/2.;
-
- for (f=0;;){
- if (demodulador(fskd,&x, GET_SAMPLE)) return(-1);
- if ((x*fskd->x0)<0) { /* Transicion */
- if (!f) {
- if (fskd->cont<(spb2)) fskd->cont+=ds; else fskd->cont-=ds;
- f=1;
- }
- }
- fskd->x0=x;
- fskd->cont+=1.;
- if (fskd->cont>spb) {
- fskd->cont-=spb;
- break;
- }
- }
- f=(x>0)?0x80:0;
- return(f);
-}
-
-int fsk_serie(fsk_data *fskd, short *buffer, int *len, int *outbyte)
-{
- int a;
- int i,j,n1,r;
- int samples=0;
- int olen;
- switch(fskd->state) {
- /* Pick up where we left off */
- case STATE_SEARCH_STARTBIT2:
- goto search_startbit2;
- case STATE_SEARCH_STARTBIT3:
- goto search_startbit3;
- case STATE_GET_BYTE:
- goto getbyte;
- }
- /* Esperamos bit de start */
- do {
-/* this was jesus's nice, reasonable, working (at least with RTTY) code
-to look for the beginning of the start bit. Unfortunately, since TTY/TDD's
-just start sending a start bit with nothing preceding it at the beginning
-of a transmission (what a LOSING design), we cant do it this elegantly */
-/*
- if (demodulador(zap,&x1)) return(-1);
- for(;;) {
- if (demodulador(zap,&x2)) return(-1);
- if (x1>0 && x2<0) break;
- x1=x2;
- }
-*/
-/* this is now the imprecise, losing, but functional code to detect the
-beginning of a start bit in the TDD sceanario. It just looks for sufficient
-level to maybe, perhaps, guess, maybe that its maybe the beginning of
-a start bit, perhaps. This whole thing stinks! */
- if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1);
- samples++;
- for(;;)
- {
-search_startbit2:
- if (!*len) {
- fskd->state = STATE_SEARCH_STARTBIT2;
- return 0;
- }
- samples++;
- if (demodulador(fskd,&fskd->x2,GET_SAMPLE)) return(-1);
-#if 0
- printf("x2 = %5.5f ", fskd->x2);
-#endif
- if (fskd->x2 < -0.5) break;
- }
-search_startbit3:
- /* Esperamos 0.5 bits antes de usar DPLL */
- i=fskd->spb/2;
- if (*len < i) {
- fskd->state = STATE_SEARCH_STARTBIT3;
- return 0;
- }
- for(;i;i--) { if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1);
-#if 0
- printf("x1 = %5.5f ", fskd->x1);
-#endif
- samples++; }
-
- /* x1 debe ser negativo (confirmación del bit de start) */
-
- } while (fskd->x1>0);
- fskd->state = STATE_GET_BYTE;
-
-getbyte:
-
- /* Need at least 80 samples (for 1200) or
- 1320 (for 45.5) to be sure we'll have a byte */
- if (fskd->nbit < 8) {
- if (*len < 1320)
- return 0;
- } else {
- if (*len < 80)
- return 0;
- }
- /* Leemos ahora los bits de datos */
- j=fskd->nbit;
- for (a=n1=0;j;j--) {
- olen = *len;
- i=get_bit_raw(fskd, buffer, len);
- buffer += (olen - *len);
- if (i == -1) return(-1);
- if (i) n1++;
- a>>=1; a|=i;
- }
- j=8-fskd->nbit;
- a>>=j;
-
- /* Leemos bit de paridad (si existe) y la comprobamos */
- if (fskd->paridad) {
- olen = *len;
- i=get_bit_raw(fskd, buffer, len);
- buffer += (olen - *len);
- if (i == -1) return(-1);
- if (i) n1++;
- if (fskd->paridad==1) { /* paridad=1 (par) */
- if (n1&1) a|=0x100; /* error */
- } else { /* paridad=2 (impar) */
- if (!(n1&1)) a|=0x100; /* error */
- }
- }
-
- /* Leemos bits de STOP. Todos deben ser 1 */
-
- for (j=fskd->nstop;j;j--) {
- r = get_bit_raw(fskd, buffer, len);
- if (r == -1) return(-1);
- if (!r) a|=0x200;
- }
-
- /* Por fin retornamos */
- /* Bit 8 : Error de paridad */
- /* Bit 9 : Error de Framming */
-
- *outbyte = a;
- fskd->state = STATE_SEARCH_STARTBIT;
- return 1;
-}
diff --git a/1.2-netsec/funcs/Makefile b/1.2-netsec/funcs/Makefile
deleted file mode 100644
index 14bbd80a3..000000000
--- a/1.2-netsec/funcs/Makefile
+++ /dev/null
@@ -1,82 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Makefile for dialplan functions
-#
-# Copyright (C) 2005, Digium
-#
-# Kevin P. Fleming <kpfleming@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-FUNCS=pbx_functions.so
-
-BUILTINS=func_md5.o \
- func_math.o \
- func_groupcount.o \
- func_strings.o \
- func_cdr.o \
- func_logic.o \
- func_env.o \
- func_db.o \
- func_timeout.o \
- func_language.o \
- func_moh.o
-
-STANDALONE_FUNCS=$(filter-out $(BUILTINS),$(patsubst %.c,%.o,$(wildcard func*.c)))
-
-FUNCS+=$(STANDALONE_FUNCS:.o=.so)
-
-FUNC_SOURCES=$(BUILTINS:.o=.c)
-
-FUNC_STRUCTS=$(shell grep 'struct ast_custom_function' $(FUNC_SOURCES) | awk '{print $$3};')
-
-ifeq (${OSARCH},CYGWIN)
-CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
-CYGSOLIB=-L.. -L. -lasterisk.dll
-else
-CFLAGS+=-fPIC
-endif
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-all: $(FUNCS)
-
-clean:
- rm -f *.so *.o .depend pbx_functions.h
-
-%.so : %.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
-
-#$(BUILTINS) : CFLAGS += -DBUILTIN_FUNC
-
-pbx_functions.h: $(FUNC_SOURCES)
- @echo "/* Automatically generated - do not edit */" > $@
- @for f in $(FUNC_SOURCES); do echo "#include \"$$f\"" >> $@; done
- @echo "static struct ast_custom_function *builtins[] = {" >> $@
- @for f in $(FUNC_STRUCTS); do echo "&$$f," >> $@; done
- @echo "};" >> $@
-
-pbx_functions.o: pbx_functions.h
-
-pbx_functions.so: pbx_functions.o #$(BUILTINS)
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
-
-install: all
- for x in $(FUNCS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-depend: .depend
-
-.depend: pbx_functions.h
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
-
-env:
- env
diff --git a/1.2-netsec/funcs/func_callerid.c b/1.2-netsec/funcs/func_callerid.c
deleted file mode 100644
index 264c404dd..000000000
--- a/1.2-netsec/funcs/func_callerid.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * 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 Caller ID related dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#ifndef BUILTIN_FUNC
-#include "asterisk/module.h"
-#endif /* BUILTIN_FUNC */
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/options.h"
-#include "asterisk/callerid.h"
-
-static char *callerid_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- if (!strncasecmp("all", data, 3)) {
- snprintf(buf, len, "\"%s\" <%s>", chan->cid.cid_name ? chan->cid.cid_name : "", chan->cid.cid_num ? chan->cid.cid_num : "");
- } else if (!strncasecmp("name", data, 4)) {
- if (chan->cid.cid_name) {
- ast_copy_string(buf, chan->cid.cid_name, len);
- }
- } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) {
- if (chan->cid.cid_num) {
- ast_copy_string(buf, chan->cid.cid_num, len);
- }
- } else if (!strncasecmp("ani", data, 3)) {
- if (chan->cid.cid_ani) {
- ast_copy_string(buf, chan->cid.cid_ani, len);
- }
- } else if (!strncasecmp("dnid", data, 4)) {
- if (chan->cid.cid_dnid) {
- ast_copy_string(buf, chan->cid.cid_dnid, len);
- }
- } else if (!strncasecmp("rdnis", data, 5)) {
- if (chan->cid.cid_rdnis) {
- ast_copy_string(buf, chan->cid.cid_rdnis, len);
- }
- } else {
- ast_log(LOG_ERROR, "Unknown callerid data type.\n");
- }
-
- return buf;
-}
-
-static void callerid_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
-{
- if (!value)
- return;
-
- if (!strncasecmp("all", data, 3)) {
- char name[256];
- char num[256];
- if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num)))
- ast_set_callerid(chan, num, name, num);
- } else if (!strncasecmp("name", data, 4)) {
- ast_set_callerid(chan, NULL, value, NULL);
- } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) {
- ast_set_callerid(chan, value, NULL, NULL);
- } else if (!strncasecmp("ani", data, 3)) {
- ast_set_callerid(chan, NULL, NULL, value);
- } else if (!strncasecmp("dnid", data, 4)) {
- /* do we need to lock chan here? */
- if (chan->cid.cid_dnid)
- free(chan->cid.cid_dnid);
- chan->cid.cid_dnid = ast_strlen_zero(value) ? NULL : strdup(value);
- } else if (!strncasecmp("rdnis", data, 5)) {
- /* do we need to lock chan here? */
- if (chan->cid.cid_rdnis)
- free(chan->cid.cid_rdnis);
- chan->cid.cid_rdnis = ast_strlen_zero(value) ? NULL : strdup(value);
- } else {
- ast_log(LOG_ERROR, "Unknown callerid data type.\n");
- }
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif /* BUILTIN_FUNC */
-struct ast_custom_function callerid_function = {
- .name = "CALLERID",
- .synopsis = "Gets or sets Caller*ID data on the channel.",
- .syntax = "CALLERID(datatype)",
- .desc = "Gets or sets Caller*ID data on the channel. The allowable datatypes\n"
- "are \"all\", \"name\", \"num\", \"ANI\", \"DNID\", \"RDNIS\".\n",
- .read = callerid_read,
- .write = callerid_write,
-};
-
-#ifndef BUILTIN_FUNC
-static char *tdesc = "Caller ID related dialplan function";
-
-int unload_module(void)
-{
- return ast_custom_function_unregister(&callerid_function);
-}
-
-int load_module(void)
-{
- return ast_custom_function_register(&callerid_function);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-#endif /* BUILTIN_FUNC */
-
-/*
-Local Variables:
-mode: C
-c-file-style: "linux"
-indent-tabs-mode: nil
-End:
-*/
diff --git a/1.2-netsec/funcs/func_cdr.c b/1.2-netsec/funcs/func_cdr.c
deleted file mode 100644
index 3e4696e18..000000000
--- a/1.2-netsec/funcs/func_cdr.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Portions Copyright (C) 2005, Anthony Minessale II
- *
- * 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 Call Detail Record related dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/cdr.h"
-
-static char *builtin_function_cdr_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *ret;
- char *mydata;
- int argc;
- char *argv[2];
- int recursive = 0;
-
- if (ast_strlen_zero(data))
- return NULL;
-
- if (!chan->cdr)
- return NULL;
-
- mydata = ast_strdupa(data);
- argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
-
- /* check for a trailing flags argument */
- if (argc > 1) {
- argc--;
- if (strchr(argv[argc], 'r'))
- recursive = 1;
- }
-
- ast_cdr_getvar(chan->cdr, argv[0], &ret, buf, len, recursive);
-
- return ret;
-}
-
-static void builtin_function_cdr_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
-{
- char *mydata;
- int argc;
- char *argv[2];
- int recursive = 0;
-
- if (ast_strlen_zero(data) || !value)
- return;
-
- mydata = ast_strdupa(data);
- argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
-
- /* check for a trailing flags argument */
- if (argc > 1) {
- argc--;
- if (strchr(argv[argc], 'r'))
- recursive = 1;
- }
-
- if (!strcasecmp(argv[0], "accountcode"))
- ast_cdr_setaccount(chan, value);
- else if (!strcasecmp(argv[0], "userfield"))
- ast_cdr_setuserfield(chan, value);
- else if (chan->cdr)
- ast_cdr_setvar(chan->cdr, argv[0], value, recursive);
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function cdr_function = {
- .name = "CDR",
- .synopsis = "Gets or sets a CDR variable",
- .desc= "Option 'r' searches the entire stack of CDRs on the channel\n",
- .syntax = "CDR(<name>[|options])",
- .read = builtin_function_cdr_read,
- .write = builtin_function_cdr_write,
-};
-
diff --git a/1.2-netsec/funcs/func_db.c b/1.2-netsec/funcs/func_db.c
deleted file mode 100644
index bc135a6b3..000000000
--- a/1.2-netsec/funcs/func_db.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Russell Bryant <russelb@clemson.edu>
- *
- * func_db.c adapted from the old app_db.c, copyright by the following people
- * Copyright (C) 2005, Mark Spencer <markster@digium.com>
- * Copyright (C) 2003, Jefferson Noxon <jeff@debian.org>
- *
- * 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 Functions for interaction with the Asterisk database
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <regex.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/astdb.h"
-
-static char *function_db_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int argc;
- char *args;
- char *argv[2];
- char *family;
- char *key;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
- return buf;
- }
-
- args = ast_strdupa(data);
- argc = ast_app_separate_args(args, '/', argv, sizeof(argv) / sizeof(argv[0]));
-
- if (argc > 1) {
- family = argv[0];
- key = argv[1];
- } else {
- ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
- return buf;
- }
-
- if (ast_db_get(family, key, buf, len-1)) {
- ast_log(LOG_DEBUG, "DB: %s/%s not found in database.\n", family, key);
- } else
- pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
-
-
- return buf;
-}
-
-static void function_db_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
-{
- int argc;
- char *args;
- char *argv[2];
- char *family;
- char *key;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=<value>\n");
- return;
- }
-
- args = ast_strdupa(data);
- argc = ast_app_separate_args(args, '/', argv, sizeof(argv) / sizeof(argv[0]));
-
- if (argc > 1) {
- family = argv[0];
- key = argv[1];
- } else {
- ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=value\n");
- return;
- }
-
- if (ast_db_put(family, key, (char*)value)) {
- ast_log(LOG_WARNING, "DB: Error writing value to database.\n");
- }
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function db_function = {
- .name = "DB",
- .synopsis = "Read or Write from/to the Asterisk database",
- .syntax = "DB(<family>/<key>)",
- .desc = "This function will read or write a value from/to the Asterisk database.\n"
- "DB(...) will read a value from the database, while DB(...)=value\n"
- "will write a value to the database. On a read, this function\n"
- "returns the value from the datase, or NULL if it does not exist.\n"
- "On a write, this function will always return NULL. Reading a database value\n"
- "will also set the variable DB_RESULT.\n",
- .read = function_db_read,
- .write = function_db_write,
-};
-
-static char *function_db_exists(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int argc;
- char *args;
- char *argv[2];
- char *family;
- char *key;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
- return buf;
- }
-
- args = ast_strdupa(data);
- argc = ast_app_separate_args(args, '/', argv, sizeof(argv) / sizeof(argv[0]));
-
- if (argc > 1) {
- family = argv[0];
- key = argv[1];
- } else {
- ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
- return buf;
- }
-
- if (ast_db_get(family, key, buf, len-1))
- ast_copy_string(buf, "0", len);
- else {
- pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
- ast_copy_string(buf, "1", len);
- }
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function db_exists_function = {
- .name = "DB_EXISTS",
- .synopsis = "Check to see if a key exists in the Asterisk database",
- .syntax = "DB_EXISTS(<family>/<key>)",
- .desc = "This function will check to see if a key exists in the Asterisk\n"
- "database. If it exists, the function will return \"1\". If not,\n"
- "it will return \"0\". Checking for existence of a database key will\n"
- "also set the variable DB_RESULT to the key's value if it exists.\n",
- .read = function_db_exists,
-};
diff --git a/1.2-netsec/funcs/func_enum.c b/1.2-netsec/funcs/func_enum.c
deleted file mode 100644
index 07655a789..000000000
--- a/1.2-netsec/funcs/func_enum.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005
- *
- * Mark Spencer <markster@digium.com>
- * Oleksiy Krivoshey <oleksiyk@gmail.com>
- * Russell Bryant <russelb@clemson.edu>
- *
- * 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 ENUM Functions
- * \arg See also AstENUM
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-#ifndef BUILTIN_FUNC
-#include "asterisk/module.h"
-#endif /* BUILTIN_FUNC */
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/utils.h"
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-
-#include "asterisk/enum.h"
-
-static char* synopsis = "Syntax: ENUMLOOKUP(number[,Method-type[,options|record#[,zone-suffix]]])\n";
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static char *function_enum(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int res=0;
- char tech[80];
- char dest[256] = "";
- char *zone;
- char *options;
- struct localuser *u;
- char *params[4];
- char *p = data;
- char *s;
- int i = 0;
-
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, synopsis);
- return "";
- }
-
- do {
- if(i>3){
- ast_log(LOG_WARNING, synopsis);
- return "";
- }
- params[i++] = p;
- p = strchr(p, '|');
- if(p){
- *p = '\0';
- p++;
- }
- } while(p);
-
- if(i < 1){
- ast_log(LOG_WARNING, synopsis);
- return "";
- }
-
- if( (i > 1 && strlen(params[1]) == 0) || i < 2){
- ast_copy_string(tech, "sip", sizeof(tech));
- } else {
- ast_copy_string(tech, params[1], sizeof(tech));
- }
-
- if( (i > 3 && strlen(params[3]) == 0) || i<4){
- zone = "e164.arpa";
- } else {
- zone = params[3];
- }
-
- if( (i > 2 && strlen(params[2]) == 0) || i<3){
- options = "1";
- } else {
- options = params[2];
- }
-
- /* strip any '-' signs from number */
- p = params[0];
- /*
- while(*p == '+'){
- p++;
- }
- */
- s = p;
- i = 0;
- while(*p && *s){
- if(*s == '-'){
- s++;
- } else {
- p[i++] = *s++;
- }
- }
- p[i] = 0;
-
- LOCAL_USER_ACF_ADD(u);
-
- res = ast_get_enum(chan, p, dest, sizeof(dest), tech, sizeof(tech), zone, options);
-
- LOCAL_USER_REMOVE(u);
-
- p = strchr(dest, ':');
- if(p && strncasecmp(tech, "ALL", sizeof(tech))) {
- ast_copy_string(buf, p+1, sizeof(dest));
- } else {
- ast_copy_string(buf, dest, sizeof(dest));
- }
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function enum_function = {
- .name = "ENUMLOOKUP",
- .synopsis = "ENUMLOOKUP allows for general or specific querying of NAPTR records"
- " or counts of NAPTR types for ENUM or ENUM-like DNS pointers",
- .syntax = "ENUMLOOKUP(number[,Method-type[,options|record#[,zone-suffix]]])",
- .desc = "Option 'c' returns an integer count of the number of NAPTRs of a certain RR type.\n"
- "Combination of 'c' and Method-type of 'ALL' will return a count of all NAPTRs for the record.\n"
- "Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n"
- "For more information, see README.enum",
- .read = function_enum,
-};
-
-static char *function_txtcidname(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int res;
- char tech[80];
- char txt[256] = "";
- char dest[80];
- struct localuser *u;
-
- LOCAL_USER_ACF_ADD(u);
-
- buf[0] = '\0';
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n");
- LOCAL_USER_REMOVE(u);
- return buf;
- }
-
- res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt, sizeof(txt));
-
- if (!ast_strlen_zero(txt))
- ast_copy_string(buf, txt, len);
-
- LOCAL_USER_REMOVE(u);
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function txtcidname_function = {
- .name = "TXTCIDNAME",
- .synopsis = "TXTCIDNAME looks up a caller name via DNS",
- .syntax = "TXTCIDNAME(<number>)",
- .desc = "This function looks up the given phone number in DNS to retrieve\n"
- "the caller id name. The result will either be blank or be the value\n"
- "found in the TXT record in DNS.\n",
- .read = function_txtcidname,
-};
-
-#ifndef BUILTIN_FUNC
-
-static char *tdesc = "ENUM Related Functions";
-
-int unload_module(void)
-{
- ast_custom_function_unregister(&enum_function);
- ast_custom_function_unregister(&txtcidname_function);
-
- STANDARD_HANGUP_LOCALUSERS;
-
- return 0;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_custom_function_register(&enum_function);
- if (!res)
- ast_custom_function_register(&txtcidname_function);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
-
- STANDARD_USECOUNT(res);
-
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-#endif /* BUILTIN_FUNC */
-
diff --git a/1.2-netsec/funcs/func_env.c b/1.2-netsec/funcs/func_env.c
deleted file mode 100644
index 4906c7d11..000000000
--- a/1.2-netsec/funcs/func_env.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * 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 Environment related dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-
-static char *builtin_function_env_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *ret = "";
-
- if (data) {
- ret = getenv(data);
- if (!ret)
- ret = "";
- }
- ast_copy_string(buf, ret, len);
-
- return buf;
-}
-
-static void builtin_function_env_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
-{
- if (!ast_strlen_zero(data)) {
- if (!ast_strlen_zero(value)) {
- setenv(data, value, 1);
- } else {
- unsetenv(data);
- }
- }
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function env_function = {
- .name = "ENV",
- .synopsis = "Gets or sets the environment variable specified",
- .syntax = "ENV(<envname>)",
- .read = builtin_function_env_read,
- .write = builtin_function_env_write,
-};
diff --git a/1.2-netsec/funcs/func_groupcount.c b/1.2-netsec/funcs/func_groupcount.c
deleted file mode 100644
index 0f07d8327..000000000
--- a/1.2-netsec/funcs/func_groupcount.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * 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 Channel group related dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-
-static char *group_count_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int count;
- char group[80] = "";
- char category[80] = "";
- char *grp;
-
- ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
-
- if (ast_strlen_zero(group)) {
- if ((grp = pbx_builtin_getvar_helper(chan, category)))
- ast_copy_string(group, grp, sizeof(group));
- else
- ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name);
- }
-
- count = ast_app_group_get_count(group, category);
- snprintf(buf, len, "%d", count);
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function group_count_function = {
- .name = "GROUP_COUNT",
- .syntax = "GROUP_COUNT([groupname][@category])",
- .synopsis = "Counts the number of channels in the specified group",
- .desc = "Calculates the group count for the specified group, or uses the\n"
- "channel's current group if not specifed (and non-empty).\n",
- .read = group_count_function_read,
-};
-
-static char *group_match_count_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int count;
- char group[80] = "";
- char category[80] = "";
-
- ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
-
- if (!ast_strlen_zero(group)) {
- count = ast_app_group_match_get_count(group, category);
- snprintf(buf, len, "%d", count);
- }
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function group_match_count_function = {
- .name = "GROUP_MATCH_COUNT",
- .syntax = "GROUP_MATCH_COUNT(groupmatch[@category])",
- .synopsis = "Counts the number of channels in the groups matching the specified pattern",
- .desc = "Calculates the group count for all groups that match the specified pattern.\n"
- "Uses standard regular expression matching (see regex(7)).\n",
- .read = group_match_count_function_read,
- .write = NULL,
-};
-
-static char *group_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char varname[256];
- char *group;
-
- if (!ast_strlen_zero(data)) {
- snprintf(varname, sizeof(varname), "%s_%s", GROUP_CATEGORY_PREFIX, data);
- } else {
- ast_copy_string(varname, GROUP_CATEGORY_PREFIX, sizeof(varname));
- }
-
- group = pbx_builtin_getvar_helper(chan, varname);
- if (group)
- ast_copy_string(buf, group, len);
-
- return buf;
-}
-
-static void group_function_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
-{
- char grpcat[256];
-
- if (!ast_strlen_zero(data)) {
- snprintf(grpcat, sizeof(grpcat), "%s@%s", value, data);
- } else {
- ast_copy_string(grpcat, value, sizeof(grpcat));
- }
-
- if (ast_app_group_set_channel(chan, grpcat))
- ast_log(LOG_WARNING, "Setting a group requires an argument (group name)\n");
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function group_function = {
- .name = "GROUP",
- .syntax = "GROUP([category])",
- .synopsis = "Gets or sets the channel group.",
- .desc = "Gets or sets the channel group.\n",
- .read = group_function_read,
- .write = group_function_write,
-};
-
-static char *group_list_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- struct ast_var_t *current;
- struct varshead *headp;
- char tmp1[1024] = "";
- char tmp2[1024] = "";
-
- headp=&chan->varshead;
- AST_LIST_TRAVERSE(headp,current,entries) {
- if (!strncmp(ast_var_name(current), GROUP_CATEGORY_PREFIX "_", strlen(GROUP_CATEGORY_PREFIX) + 1)) {
- if (!ast_strlen_zero(tmp1)) {
- ast_copy_string(tmp2, tmp1, sizeof(tmp2));
- snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, ast_var_value(current), (ast_var_name(current) + strlen(GROUP_CATEGORY_PREFIX) + 1));
- } else {
- snprintf(tmp1, sizeof(tmp1), "%s@%s", ast_var_value(current), (ast_var_name(current) + strlen(GROUP_CATEGORY_PREFIX) + 1));
- }
- } else if (!strcmp(ast_var_name(current), GROUP_CATEGORY_PREFIX)) {
- if (!ast_strlen_zero(tmp1)) {
- ast_copy_string(tmp2, tmp1, sizeof(tmp2));
- snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, ast_var_value(current));
- } else {
- snprintf(tmp1, sizeof(tmp1), "%s", ast_var_value(current));
- }
- }
- }
- ast_copy_string(buf, tmp1, len);
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function group_list_function = {
- .name = "GROUP_LIST",
- .syntax = "GROUP_LIST()",
- .synopsis = "Gets a list of the groups set on a channel.",
- .desc = "Gets a list of the groups set on a channel.\n",
- .read = group_list_function_read,
- .write = NULL,
-};
-
-/*
-Local Variables:
-mode: C
-c-file-style: "linux"
-indent-tabs-mode: nil
-End:
-*/
diff --git a/1.2-netsec/funcs/func_language.c b/1.2-netsec/funcs/func_language.c
deleted file mode 100644
index ea829a2f4..000000000
--- a/1.2-netsec/funcs/func_language.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * 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 Language related dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-
-static char *builtin_function_language_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- ast_copy_string(buf, chan->language, len);
-
- return buf;
-}
-
-static void builtin_function_language_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
-{
- if (value)
- ast_copy_string(chan->language, value, sizeof(chan->language));
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function language_function = {
- .name = "LANGUAGE",
- .synopsis = "Gets or sets the channel's language.",
- .syntax = "LANGUAGE()",
- .desc = "Gets or sets the channel language. This information is used for the\n"
- "syntax in generation of numbers, and to choose a natural language file\n"
- "when available. For example, if language is set to 'fr' and the file\n"
- "'demo-congrats' is requested to be played, if the file\n"
- "'fr/demo-congrats' exists, then it will play that file, and if not\n"
- "will play the normal 'demo-congrats'. For some language codes,\n"
- "changing the language also changes the syntax of some Asterisk\n"
- "functions, like SayNumber.\n",
- .read = builtin_function_language_read,
- .write = builtin_function_language_write,
-};
-
-/*
-Local Variables:
-mode: C
-c-file-style: "linux"
-indent-tabs-mode: nil
-End:
-*/
diff --git a/1.2-netsec/funcs/func_logic.c b/1.2-netsec/funcs/func_logic.c
deleted file mode 100644
index f748ba939..000000000
--- a/1.2-netsec/funcs/func_logic.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- * Portions Copyright (C) 2005, Anthony Minessale II
- *
- * 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 Conditional logic dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/config.h" /* for ast_true */
-
-static char *builtin_function_isnull(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- return data && *data ? "0" : "1";
-}
-
-static char *builtin_function_exists(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- return data && *data ? "1" : "0";
-}
-
-static char *builtin_function_iftime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- struct ast_timing timing;
- char *ret;
- char *expr;
- char *iftrue;
- char *iffalse;
-
- if (!(data = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- return NULL;
- }
-
- data = ast_strip_quoted(data, "\"", "\"");
- expr = strsep(&data, "?");
- iftrue = strsep(&data, ":");
- iffalse = data;
-
- if (ast_strlen_zero(expr) || !(iftrue || iffalse)) {
- ast_log(LOG_WARNING, "Syntax IFTIME(<timespec>?[<true>][:<false>])\n");
- return NULL;
- }
-
- if (!ast_build_timing(&timing, expr)) {
- ast_log(LOG_WARNING, "Invalid Time Spec.\n");
- return NULL;
- }
-
- if (iftrue)
- iftrue = ast_strip_quoted(iftrue, "\"", "\"");
- if (iffalse)
- iffalse = ast_strip_quoted(iffalse, "\"", "\"");
-
- if ((ret = ast_check_timing(&timing) ? iftrue : iffalse)) {
- ast_copy_string(buf, ret, len);
- ret = buf;
- }
-
- return ret;
-}
-
-static char *builtin_function_if(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *ret;
- char *expr;
- char *iftrue;
- char *iffalse;
-
- if (!(data = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- return NULL;
- }
-
- data = ast_strip_quoted(data, "\"", "\"");
- expr = strsep(&data, "?");
- iftrue = strsep(&data, ":");
- iffalse = data;
-
- if (ast_strlen_zero(expr) || !(iftrue || iffalse)) {
- ast_log(LOG_WARNING, "Syntax IF(<expr>?[<true>][:<false>])\n");
- return NULL;
- }
-
- expr = ast_strip(expr);
- if (iftrue)
- iftrue = ast_strip_quoted(iftrue, "\"", "\"");
- if (iffalse)
- iffalse = ast_strip_quoted(iffalse, "\"", "\"");
-
- if ((ret = ast_true(expr) ? iftrue : iffalse)) {
- ast_copy_string(buf, ret, len);
- ret = buf;
- }
-
- return ret;
-}
-
-static char *builtin_function_set(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *varname;
- char *val;
-
- if (!(data = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- return NULL;
- }
-
- varname = strsep(&data, "=");
- val = data;
-
- if (ast_strlen_zero(varname) || !val) {
- ast_log(LOG_WARNING, "Syntax SET(<varname>=[<value>])\n");
- return NULL;
- }
-
- varname = ast_strip(varname);
- val = ast_strip(val);
- pbx_builtin_setvar_helper(chan, varname, val);
- ast_copy_string(buf, val, len);
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function isnull_function = {
- .name = "ISNULL",
- .synopsis = "NULL Test: Returns 1 if NULL or 0 otherwise",
- .syntax = "ISNULL(<data>)",
- .read = builtin_function_isnull,
-};
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function set_function = {
- .name = "SET",
- .synopsis = "SET assigns a value to a channel variable",
- .syntax = "SET(<varname>=[<value>])",
- .read = builtin_function_set,
-};
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function exists_function = {
- .name = "EXISTS",
- .synopsis = "Existence Test: Returns 1 if exists, 0 otherwise",
- .syntax = "EXISTS(<data>)",
- .read = builtin_function_exists,
-};
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function if_function = {
- .name = "IF",
- .synopsis = "Conditional: Returns the data following '?' if true else the data following ':'",
- .syntax = "IF(<expr>?[<true>][:<false>])",
- .read = builtin_function_if,
-};
-
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function if_time_function = {
- .name = "IFTIME",
- .synopsis = "Temporal Conditional: Returns the data following '?' if true else the data following ':'",
- .syntax = "IFTIME(<timespec>?[<true>][:<false>])",
- .read = builtin_function_iftime,
-};
diff --git a/1.2-netsec/funcs/func_math.c b/1.2-netsec/funcs/func_math.c
deleted file mode 100644
index e8a49acc8..000000000
--- a/1.2-netsec/funcs/func_math.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005, Andy Powell
- *
- * Updated by Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Maths relatad dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/config.h"
-
-enum TypeOfFunctions
-{
- ADDFUNCTION,
- DIVIDEFUNCTION,
- MULTIPLYFUNCTION,
- SUBTRACTFUNCTION,
- MODULUSFUNCTION,
-
- GTFUNCTION,
- LTFUNCTION,
- GTEFUNCTION,
- LTEFUNCTION,
- EQFUNCTION
-};
-
-enum TypeOfResult
-{
- FLOAT_RESULT,
- INT_RESULT,
- HEX_RESULT,
- CHAR_RESULT
-};
-
-
-static char *builtin_function_math(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int argc;
- char *argv[2];
- char *args;
- float fnum1;
- float fnum2;
- float ftmp = 0;
- char *op;
- int iaction=-1;
- int type_of_result=FLOAT_RESULT;
-
- /* dunno, big calulations :D */
- char user_result[30];
-
- char *mvalue1, *mvalue2=NULL, *mtype_of_result;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Syntax: Math(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
- return NULL;
- }
-
- args = ast_strdupa(data);
- argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0]));
-
- if (argc < 1) {
- ast_log(LOG_WARNING, "Syntax: Math(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
- return NULL;
- }
-
- mvalue1 = argv[0];
-
- if ((op = strchr(mvalue1, '+'))) {
- iaction = ADDFUNCTION;
- *op = '\0';
- } else if ((op = strchr(mvalue1, '-'))) {
- iaction = SUBTRACTFUNCTION;
- *op = '\0';
- } else if ((op = strchr(mvalue1, '*'))) {
- iaction = MULTIPLYFUNCTION;
- *op = '\0';
- } else if ((op = strchr(mvalue1, '/'))) {
- iaction = DIVIDEFUNCTION;
- *op = '\0';
- } else if ((op = strchr(mvalue1, '%'))) {
- iaction = MODULUSFUNCTION;
- *op = '\0';
- } else if ((op = strchr(mvalue1, '>'))) {
- iaction = GTFUNCTION;
- *op = '\0';
- if (*(op+1) == '=') {
- *++op = '\0';
- iaction = GTEFUNCTION;
- }
- } else if ((op = strchr(mvalue1, '<'))) {
- iaction = LTFUNCTION;
- *op = '\0';
- if (*(op+1) == '=') {
- *++op = '\0';
- iaction = LTEFUNCTION;
- }
- } else if ((op = strchr(mvalue1, '='))) {
- iaction = GTFUNCTION;
- *op = '\0';
- if (*(op+1) == '=') {
- *++op = '\0';
- iaction = EQFUNCTION;
- } else
- op = NULL;
- }
-
- if (op)
- mvalue2 = op + 1;
-
- /* detect wanted type of result */
- mtype_of_result = argv[1];
- if (mtype_of_result)
- {
- if (!strcasecmp(mtype_of_result,"float") || !strcasecmp(mtype_of_result,"f"))
- type_of_result=FLOAT_RESULT;
- else if (!strcasecmp(mtype_of_result,"int") || !strcasecmp(mtype_of_result,"i"))
- type_of_result=INT_RESULT;
- else if (!strcasecmp(mtype_of_result,"hex") || !strcasecmp(mtype_of_result,"h"))
- type_of_result=HEX_RESULT;
- else if (!strcasecmp(mtype_of_result,"char") || !strcasecmp(mtype_of_result,"c"))
- type_of_result=CHAR_RESULT;
- else
- {
- ast_log(LOG_WARNING, "Unknown type of result requested '%s'.\n", mtype_of_result);
- return NULL;
- }
- }
-
- if (!mvalue1 || !mvalue2) {
- ast_log(LOG_WARNING, "Supply all the parameters - just this once, please\n");
- return NULL;
- }
-
- if (sscanf(mvalue1, "%f", &fnum1) != 1) {
- ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue1);
- return NULL;
- }
-
- if (sscanf(mvalue2, "%f", &fnum2) != 1) {
- ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue2);
- return NULL;
- }
-
- switch (iaction) {
- case ADDFUNCTION :
- ftmp = fnum1 + fnum2;
- break;
- case DIVIDEFUNCTION :
- if (fnum2 <= 0)
- ftmp = 0; /* can't do a divide by 0 */
- else
- ftmp = (fnum1 / fnum2);
- break;
- case MULTIPLYFUNCTION :
- ftmp = (fnum1 * fnum2);
- break;
- case SUBTRACTFUNCTION :
- ftmp = (fnum1 - fnum2);
- break;
- case MODULUSFUNCTION :
- {
- int inum1 = fnum1;
- int inum2 = fnum2;
-
- ftmp = (inum1 % inum2);
-
- break;
- }
- case GTFUNCTION :
- ast_copy_string (user_result, (fnum1 > fnum2)?"TRUE":"FALSE", sizeof (user_result));
- break;
- case LTFUNCTION :
- ast_copy_string (user_result, (fnum1 < fnum2)?"TRUE":"FALSE", sizeof (user_result));
- break;
- case GTEFUNCTION :
- ast_copy_string (user_result, (fnum1 >= fnum2)?"TRUE":"FALSE", sizeof (user_result));
- break;
- case LTEFUNCTION :
- ast_copy_string (user_result, (fnum1 <= fnum2)?"TRUE":"FALSE", sizeof (user_result));
- break;
- case EQFUNCTION :
- ast_copy_string (user_result, (fnum1 == fnum2)?"TRUE":"FALSE", sizeof (user_result));
- break;
- default :
- ast_log(LOG_WARNING, "Something happened that neither of us should be proud of %d\n", iaction);
- return NULL;
- }
-
- if (iaction < GTFUNCTION || iaction > EQFUNCTION) {
- if (type_of_result == FLOAT_RESULT)
- snprintf(user_result, sizeof(user_result), "%f", ftmp);
- else if (type_of_result == INT_RESULT)
- snprintf(user_result, sizeof(user_result), "%i", (int) ftmp);
- else if (type_of_result == HEX_RESULT)
- snprintf(user_result, sizeof(user_result), "%x", (unsigned int) ftmp);
- else if (type_of_result == CHAR_RESULT)
- snprintf(user_result, sizeof(user_result), "%c", (unsigned char) ftmp);
- }
-
- ast_copy_string(buf, user_result, len);
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif /* BUILTIN_FUNC */
-struct ast_custom_function math_function = {
- .name = "MATH",
- .synopsis = "Performs Mathematical Functions",
- .syntax = "MATH(<number1><op><number 2>[,<type_of_result>])",
- .desc = "Perform calculation on number 1 to number 2. Valid ops are: \n"
- " +,-,/,*,%,<,>,>=,<=,==\n"
- "and behave as their C equivalents.\n"
- "<type_of_result> - wanted type of result:\n"
- " f, float - float(default)\n"
- " i, int - integer,\n"
- " h, hex - hex,\n"
- " c, char - char\n"
- "Example: Set(i=${MATH(123%16,int)}) - sets var i=11",
- .read = builtin_function_math
-};
diff --git a/1.2-netsec/funcs/func_md5.c b/1.2-netsec/funcs/func_md5.c
deleted file mode 100644
index 910e44260..000000000
--- a/1.2-netsec/funcs/func_md5.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Digium, Inc.
- * Copyright (C) 2005, Olle E. Johansson, Edvina.net
- * Copyright (C) 2005, Russell Bryant <russelb@clemson.edu>
- *
- * 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 MD5 digest related dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-
-static char *builtin_function_md5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char md5[33];
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
- return NULL;
- }
-
- ast_md5_hash(md5, data);
- ast_copy_string(buf, md5, len);
-
- return buf;
-}
-
-static char *builtin_function_checkmd5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int argc;
- char *argv[2];
- char *args;
- char newmd5[33];
-
- if (!data || ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
- return NULL;
- }
-
- args = ast_strdupa(data);
- argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0]));
-
- if (argc < 2) {
- ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
- return NULL;
- }
-
- ast_md5_hash(newmd5, argv[1]);
-
- if (!strcasecmp(newmd5, argv[0])) /* they match */
- ast_copy_string(buf, "1", len);
- else
- ast_copy_string(buf, "0", len);
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function md5_function = {
- .name = "MD5",
- .synopsis = "Computes an MD5 digest",
- .syntax = "MD5(<data>)",
- .read = builtin_function_md5,
-};
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function checkmd5_function = {
- .name = "CHECK_MD5",
- .synopsis = "Checks an MD5 digest",
- .desc = "Returns 1 on a match, 0 otherwise\n",
- .syntax = "CHECK_MD5(<digest>,<data>)",
- .read = builtin_function_checkmd5,
-};
diff --git a/1.2-netsec/funcs/func_moh.c b/1.2-netsec/funcs/func_moh.c
deleted file mode 100644
index 25aa73af7..000000000
--- a/1.2-netsec/funcs/func_moh.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Russell Bryant <russelb@clemson.edu>
- *
- * 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 Functions for reading or setting the MusicOnHold class
- *
- */
-
-#include <stdlib.h>
-
-#include "asterisk.h"
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/utils.h"
-
-static char *function_moh_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- ast_copy_string(buf, chan->musicclass, len);
-
- return buf;
-}
-
-static void function_moh_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
-{
- ast_copy_string(chan->musicclass, value, sizeof(chan->musicclass));
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function moh_function = {
- .name = "MUSICCLASS",
- .synopsis = "Read or Set the MusicOnHold class",
- .syntax = "MUSICCLASS()",
- .desc = "This function will read or set the music on hold class for a channel.\n",
- .read = function_moh_read,
- .write = function_moh_write,
-};
-
diff --git a/1.2-netsec/funcs/func_strings.c b/1.2-netsec/funcs/func_strings.c
deleted file mode 100644
index 503611bbe..000000000
--- a/1.2-netsec/funcs/func_strings.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Digium, Inc.
- * Portions Copyright (C) 2005, Tilghman Lesher. All rights reserved.
- * Portions Copyright (C) 2005, Anthony Minessale II
- *
- * 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 String manipulation dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <regex.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/localtime.h"
-
-static char *function_fieldqty(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *varname, *varval, workspace[256];
- char *delim = ast_strdupa(data);
- int fieldcount = 0;
-
- if (delim) {
- varname = strsep(&delim, "|");
- pbx_retrieve_variable(chan, varname, &varval, workspace, sizeof(workspace), NULL);
- if (delim) {
- while (strsep(&varval, delim))
- fieldcount++;
- } else if (!ast_strlen_zero(varval)) {
- fieldcount = 1;
- }
- snprintf(buf, len, "%d", fieldcount);
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- strncpy(buf, "1", len);
- }
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function fieldqty_function = {
- .name = "FIELDQTY",
- .synopsis = "Count the fields, with an arbitrary delimiter",
- .syntax = "FIELDQTY(<varname>,<delim>)",
- .read = function_fieldqty,
-};
-
-static char *builtin_function_regex(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *arg, *earg = NULL, *tmp, errstr[256] = "";
- int errcode;
- regex_t regexbuf;
-
- ast_copy_string(buf, "0", len);
-
- tmp = ast_strdupa(data);
- if (!tmp) {
- ast_log(LOG_ERROR, "Out of memory in %s(%s)\n", cmd, data);
- return buf;
- }
-
- /* Regex in quotes */
- arg = strchr(tmp, '"');
- if (arg) {
- arg++;
- earg = strrchr(arg, '"');
- if (earg) {
- *earg++ = '\0';
- /* Skip over any spaces before the data we are checking */
- while (*earg == ' ')
- earg++;
- }
- } else {
- arg = tmp;
- }
-
- if ((errcode = regcomp(&regexbuf, arg, REG_EXTENDED | REG_NOSUB))) {
- regerror(errcode, &regexbuf, errstr, sizeof(errstr));
- ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, data, errstr);
- } else {
- if (!regexec(&regexbuf, earg ? earg : "", 0, NULL, 0))
- ast_copy_string(buf, "1", len);
- }
- regfree(&regexbuf);
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function regex_function = {
- .name = "REGEX",
- .synopsis = "Regular Expression: Returns 1 if data matches regular expression.",
- .syntax = "REGEX(\"<regular expression>\" <data>)",
- .read = builtin_function_regex,
-};
-
-static char *builtin_function_len(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- int length = 0;
- if (data) {
- length = strlen(data);
- }
- snprintf(buf, len, "%d", length);
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function len_function = {
- .name = "LEN",
- .synopsis = "Returns the length of the argument given",
- .syntax = "LEN(<string>)",
- .read = builtin_function_len,
-};
-
-static char *acf_strftime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *format, *epoch, *timezone = NULL;
- long epochi;
- struct tm time;
-
- buf[0] = '\0';
-
- if (!data) {
- ast_log(LOG_ERROR, "Asterisk function STRFTIME() requires an argument.\n");
- return buf;
- }
-
- format = ast_strdupa(data);
- if (!format) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return buf;
- }
-
- epoch = strsep(&format, "|");
- timezone = strsep(&format, "|");
-
- if (ast_strlen_zero(epoch) || !sscanf(epoch, "%ld", &epochi)) {
- struct timeval tv = ast_tvnow();
- epochi = tv.tv_sec;
- }
-
- ast_localtime(&epochi, &time, timezone);
-
- if (!format) {
- format = "%c";
- }
-
- if (!strftime(buf, len, format, &time)) {
- ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
- }
- buf[len - 1] = '\0';
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function strftime_function = {
- .name = "STRFTIME",
- .synopsis = "Returns the current date/time in a specified format.",
- .syntax = "STRFTIME([<epoch>][,[timezone][,format]])",
- .read = acf_strftime,
-};
-
-static char *function_eval(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- memset(buf, 0, len);
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n");
- return buf;
- }
-
- pbx_substitute_variables_helper(chan, data, buf, len - 1);
-
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function eval_function = {
- .name = "EVAL",
- .synopsis = "Evaluate stored variables.",
- .syntax = "EVAL(<variable>)",
- .desc = "Using EVAL basically causes a string to be evaluated twice.\n"
- "When a variable or expression is in the dialplan, it will be\n"
- "evaluated at runtime. However, if the result of the evaluation\n"
- "is in fact a variable or expression, using EVAL will have it\n"
- "evaluated a second time. For example, if the variable ${MYVAR}\n"
- "contains \"${OTHERVAR}\", then the result of putting ${EVAL(${MYVAR})}\n"
- "in the dialplan will be the contents of the variable, OTHERVAR.\n"
- "Normally, by just putting ${MYVAR} in the dialplan, you would be\n"
- "left with \"${OTHERVAR}\".\n",
- .read = function_eval,
-};
-
diff --git a/1.2-netsec/funcs/func_timeout.c b/1.2-netsec/funcs/func_timeout.c
deleted file mode 100644
index 4e9256ef5..000000000
--- a/1.2-netsec/funcs/func_timeout.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Channel timeout related dialplan functions
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/options.h"
-
-static char *builtin_function_timeout_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- time_t myt;
-
- if (!data) {
- ast_log(LOG_ERROR, "Must specify type of timeout to get.");
- return NULL;
- }
-
- switch(*data) {
- case 'a':
- case 'A':
- if (chan->whentohangup == 0) {
- ast_copy_string(buf, "0", len);
- } else {
- time(&myt);
- snprintf(buf, len, "%d", (int) (chan->whentohangup - myt));
- }
- break;
-
- case 'r':
- case 'R':
- if (chan->pbx) {
- snprintf(buf, len, "%d", chan->pbx->rtimeout);
- }
- break;
-
- case 'd':
- case 'D':
- if (chan->pbx) {
- snprintf(buf, len, "%d", chan->pbx->dtimeout);
- }
- break;
-
- default:
- ast_log(LOG_ERROR, "Unknown timeout type specified.");
- break;
- }
-
- return buf;
-}
-
-static void builtin_function_timeout_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
-{
- int x;
- char timestr[64];
- struct tm myt;
-
- if (!data) {
- ast_log(LOG_ERROR, "Must specify type of timeout to set.");
- return;
- }
-
- if (!value)
- return;
-
- x = atoi(value);
-
- switch(*data) {
- case 'a':
- case 'A':
- ast_channel_setwhentohangup(chan, x);
- if (option_verbose > 2) {
- if (chan->whentohangup) {
- strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S UTC", gmtime_r(&chan->whentohangup, &myt));
- ast_verbose( VERBOSE_PREFIX_3 "Channel will hangup at %s.\n", timestr);
- } else {
- ast_verbose( VERBOSE_PREFIX_3 "Channel hangup cancelled.\n");
- }
- }
- break;
-
- case 'r':
- case 'R':
- if (chan->pbx) {
- chan->pbx->rtimeout = x;
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Response timeout set to %d\n", chan->pbx->rtimeout);
- }
- break;
-
- case 'd':
- case 'D':
- if (chan->pbx) {
- chan->pbx->dtimeout = x;
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Digit timeout set to %d\n", chan->pbx->dtimeout);
- }
- break;
-
- default:
- ast_log(LOG_ERROR, "Unknown timeout type specified.");
- break;
- }
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function timeout_function = {
- .name = "TIMEOUT",
- .synopsis = "Gets or sets timeouts on the channel.",
- .syntax = "TIMEOUT(timeouttype)",
- .desc = "Gets or sets various channel timeouts. The timeouts that can be\n"
- "manipulated are:\n"
- "\n"
- "absolute: The absolute maximum amount of time permitted for a call. A\n"
- " setting of 0 disables the timeout.\n"
- "\n"
- "digit: The maximum amount of time permitted between digits when the\n"
- " user is typing in an extension. When this timeout expires,\n"
- " after the user has started to type in an extension, the\n"
- " extension will be considered complete, and will be\n"
- " interpreted. Note that if an extension typed in is valid,\n"
- " it will not have to timeout to be tested, so typically at\n"
- " the expiry of this timeout, the extension will be considered\n"
- " invalid (and thus control would be passed to the 'i'\n"
- " extension, or if it doesn't exist the call would be\n"
- " terminated). The default timeout is 5 seconds.\n"
- "\n"
- "response: The maximum amount of time permitted after falling through a\n"
- " series of priorities for a channel in which the user may\n"
- " begin typing an extension. If the user does not type an\n"
- " extension in this amount of time, control will pass to the\n"
- " 't' extension if it exists, and if not the call would be\n"
- " terminated. The default timeout is 10 seconds.\n",
- .read = builtin_function_timeout_read,
- .write = builtin_function_timeout_write,
-};
-
-/*
-Local Variables:
-mode: C
-c-file-style: "linux"
-indent-tabs-mode: nil
-End:
-*/
diff --git a/1.2-netsec/funcs/func_uri.c b/1.2-netsec/funcs/func_uri.c
deleted file mode 100644
index f985f38c1..000000000
--- a/1.2-netsec/funcs/func_uri.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Created by Olle E. Johansson, Edvina.net
- *
- * 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 URI encoding / decoding
- *
- * \note For now this code only supports 8 bit characters, not unicode,
- which we ultimately will need to support.
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "asterisk.h"
-
-/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
-
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/app.h"
-#include "asterisk/module.h"
-
-/*! \brief builtin_function_uriencode: Encode URL according to RFC 2396 */
-static char *builtin_function_uriencode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char uri[BUFSIZ];
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Syntax: URIENCODE(<data>) - missing argument!\n");
- return NULL;
- }
-
- ast_uri_encode(data, uri, sizeof(uri), 1);
- ast_copy_string(buf, uri, len);
-
- return buf;
-}
-
-/*!\brief builtin_function_uridecode: Decode URI according to RFC 2396 */
-static char *builtin_function_uridecode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Syntax: URIDECODE(<data>) - missing argument!\n");
- return NULL;
- }
-
-
- ast_copy_string(buf, data, len);
- ast_uri_decode(buf);
- return buf;
-}
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function urldecode_function = {
- .name = "URIDECODE",
- .synopsis = "Decodes an URI-encoded string.",
- .syntax = "URIDECODE(<data>)",
- .read = builtin_function_uridecode,
-};
-
-#ifndef BUILTIN_FUNC
-static
-#endif
-struct ast_custom_function urlencode_function = {
- .name = "URIENCODE",
- .synopsis = "Encodes a string to URI-safe encoding.",
- .syntax = "URIENCODE(<data>)",
- .read = builtin_function_uriencode,
-};
-
-#ifndef BUILTIN_FUNC
-static char *tdesc = "URI encode/decode functions";
-
-int unload_module(void)
-{
- return ast_custom_function_unregister(&urldecode_function) || ast_custom_function_unregister(&urlencode_function);
-}
-
-int load_module(void)
-{
- return ast_custom_function_register(&urldecode_function) || ast_custom_function_register(&urlencode_function);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-#endif /* BUILTIN_FUNC */
diff --git a/1.2-netsec/funcs/pbx_functions.c b/1.2-netsec/funcs/pbx_functions.c
deleted file mode 100644
index 2d5c519c9..000000000
--- a/1.2-netsec/funcs/pbx_functions.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Kevin P. Fleming <kpfleming@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Builtin dialplan functions
- *
- */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "pbx_functions.h"
-
-static char *tdesc = "Builtin dialplan functions";
-
-int unload_module(void)
-{
- int x;
-
- for (x = 0; x < (sizeof(builtins) / sizeof(builtins[0])); x++) {
- ast_custom_function_unregister(builtins[x]);
- }
-
- return 0;
-}
-
-int load_module(void)
-{
- int x;
-
- for (x = 0; x < (sizeof(builtins) / sizeof(builtins[0])); x++) {
- ast_custom_function_register(builtins[x]);
- }
-
- return 0;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/image.c b/1.2-netsec/image.c
deleted file mode 100644
index 894e6605b..000000000
--- a/1.2-netsec/image.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Image Management
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/sched.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/file.h"
-#include "asterisk/image.h"
-#include "asterisk/translate.h"
-#include "asterisk/cli.h"
-#include "asterisk/lock.h"
-
-static struct ast_imager *list;
-AST_MUTEX_DEFINE_STATIC(listlock);
-
-int ast_image_register(struct ast_imager *img)
-{
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
- ast_mutex_lock(&listlock);
- img->next = list;
- list = img;
- ast_mutex_unlock(&listlock);
- return 0;
-}
-
-void ast_image_unregister(struct ast_imager *img)
-{
- struct ast_imager *i, *prev = NULL;
- ast_mutex_lock(&listlock);
- i = list;
- while(i) {
- if (i == img) {
- if (prev)
- prev->next = i->next;
- else
- list = i->next;
- break;
- }
- prev = i;
- i = i->next;
- }
- ast_mutex_unlock(&listlock);
- if (i && (option_verbose > 1))
- ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
-}
-
-int ast_supports_images(struct ast_channel *chan)
-{
- if (!chan || !chan->tech)
- return 0;
- if (!chan->tech->send_image)
- return 0;
- return 1;
-}
-
-static int file_exists(char *filename)
-{
- int res;
- struct stat st;
- res = stat(filename, &st);
- if (!res)
- return st.st_size;
- return 0;
-}
-
-static void make_filename(char *buf, int len, char *filename, char *preflang, char *ext)
-{
- if (filename[0] == '/') {
- if (preflang && strlen(preflang))
- snprintf(buf, len, "%s-%s.%s", filename, preflang, ext);
- else
- snprintf(buf, len, "%s.%s", filename, ext);
- } else {
- if (preflang && strlen(preflang))
- snprintf(buf, len, "%s/%s/%s-%s.%s", ast_config_AST_VAR_DIR, "images", filename, preflang, ext);
- else
- snprintf(buf, len, "%s/%s/%s.%s", ast_config_AST_VAR_DIR, "images", filename, ext);
- }
-}
-
-struct ast_frame *ast_read_image(char *filename, char *preflang, int format)
-{
- struct ast_imager *i;
- char buf[256];
- char tmp[80];
- char *e;
- struct ast_imager *found = NULL;
- int fd;
- int len=0;
- struct ast_frame *f = NULL;
-#if 0 /* We need to have some sort of read-only lock */
- ast_mutex_lock(&listlock);
-#endif
- i = list;
- while(!found && i) {
- if (i->format & format) {
- char *stringp=NULL;
- strncpy(tmp, i->exts, sizeof(tmp)-1);
- stringp=tmp;
- e = strsep(&stringp, "|");
- while(e) {
- make_filename(buf, sizeof(buf), filename, preflang, e);
- if ((len = file_exists(buf))) {
- found = i;
- break;
- }
- make_filename(buf, sizeof(buf), filename, NULL, e);
- if ((len = file_exists(buf))) {
- found = i;
- break;
- }
- e = strsep(&stringp, "|");
- }
- }
- i = i->next;
- }
- if (found) {
- fd = open(buf, O_RDONLY);
- if (fd > -1) {
- if (!found->identify || found->identify(fd)) {
- /* Reset file pointer */
- lseek(fd, 0, SEEK_SET);
- f = found->read_image(fd,len);
- } else
- ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, i->name);
- close(fd);
- } else
- ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno));
- } else
- ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
-#if 0
- ast_mutex_unlock(&listlock);
-#endif
- return f;
-}
-
-
-int ast_send_image(struct ast_channel *chan, char *filename)
-{
- struct ast_frame *f;
- int res = -1;
- if (chan->tech->send_image) {
- f = ast_read_image(filename, chan->language, -1);
- if (f) {
- res = chan->tech->send_image(chan, f);
- ast_frfree(f);
- }
- }
- return res;
-}
-
-static int show_image_formats(int fd, int argc, char *argv[])
-{
-#define FORMAT "%10s %10s %50s %10s\n"
-#define FORMAT2 "%10s %10s %50s %10s\n"
- struct ast_imager *i;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format");
- i = list;
- while(i) {
- ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
- i = i->next;
- };
- return RESULT_SUCCESS;
-}
-
-struct ast_cli_entry show_images =
-{
- { "show", "image", "formats" },
- show_image_formats,
- "Displays image formats",
-"Usage: show image formats\n"
-" displays currently registered image formats (if any)\n"
-};
-
-
-int ast_image_init(void)
-{
- ast_cli_register(&show_images);
- return 0;
-}
-
diff --git a/1.2-netsec/images/animlogo.gif b/1.2-netsec/images/animlogo.gif
deleted file mode 100644
index 9b75989fc..000000000
--- a/1.2-netsec/images/animlogo.gif
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/images/asterisk-intro.jpg b/1.2-netsec/images/asterisk-intro.jpg
deleted file mode 100644
index 278f018ce..000000000
--- a/1.2-netsec/images/asterisk-intro.jpg
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/images/play.gif b/1.2-netsec/images/play.gif
deleted file mode 100644
index 4d457b19d..000000000
--- a/1.2-netsec/images/play.gif
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/include/asterisk.h b/1.2-netsec/include/asterisk.h
deleted file mode 100644
index 68f17ea5f..000000000
--- a/1.2-netsec/include/asterisk.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Asterisk -- A telephony toolkit for Linux.
- *
- * General Definitions for Asterisk top level program
- *
- * Copyright (C) 1999-2005, Mark Spencer
- *
- * Mark Spencer <markster@digium.com>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-/*! \file
- * \brief Asterisk main include file. File version handling, generic pbx functions.
- */
-
-#ifndef _ASTERISK_H
-#define _ASTERISK_H
-
-#define DEFAULT_LANGUAGE "en"
-
-#define AST_CONFIG_MAX_PATH 255
-
-/* provided in asterisk.c */
-extern char ast_config_AST_CONFIG_DIR[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_CONFIG_FILE[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_MODULE_DIR[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_SPOOL_DIR[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_MONITOR_DIR[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_VAR_DIR[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_LOG_DIR[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_AGI_DIR[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_DB[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_KEY_DIR[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_PID[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_SOCKET[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_RUN_DIR[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_CTL_PERMISSIONS[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_CTL_OWNER[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_CTL_GROUP[AST_CONFIG_MAX_PATH];
-extern char ast_config_AST_CTL[AST_CONFIG_MAX_PATH];
-
-/* Provided by asterisk.c */
-int ast_set_priority(int);
-/* Provided by module.c */
-int load_modules(const int preload_only);
-/* Provided by pbx.c */
-int load_pbx(void);
-/* Provided by logger.c */
-int init_logger(void);
-void close_logger(void);
-/* Provided by frame.c */
-int init_framer(void);
-/* Provided by logger.c */
-int reload_logger(int);
-/* Provided by term.c */
-int term_init(void);
-/* Provided by db.c */
-int astdb_init(void);
-/* Provided by channel.c */
-void ast_channels_init(void);
-/* Provided by dnsmgr.c */
-int dnsmgr_init(void);
-void dnsmgr_start_refresh(void);
-void dnsmgr_reload(void);
-
-/*!
- * \brief Register the version of a source code file with the core.
- * \param file the source file name
- * \param version the version string (typically a CVS revision keyword string)
- * \return nothing
- *
- * This function should not be called directly, but instead the
- * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
- */
-void ast_register_file_version(const char *file, const char *version);
-
-/*!
- * \brief Unregister a source code file from the core.
- * \param file the source file name
- * \return nothing
- *
- * This function should not be called directly, but instead the
- * ASTERISK_FILE_VERSION macro should be used to automatically unregister
- * the file when the module is unloaded.
- */
-void ast_unregister_file_version(const char *file);
-
-/*!
- * \brief Register/unregister a source code file with the core.
- * \param file the source file name
- * \param version the version string (typically a CVS revision keyword string)
- *
- * This macro will place a file-scope constructor and destructor into the
- * source of the module using it; this will cause the version of this file
- * to registered with the Asterisk core (and unregistered) at the appropriate
- * times.
- *
- * Example:
- *
- * \code
- * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
- * \endcode
- *
- * \note The dollar signs above have been protected with backslashes to keep
- * SVN from modifying them in this file; under normal circumstances they would
- * not be present and SVN would expand the Revision keyword into the file's
- * revision number.
- */
-#if defined(__GNUC__) && !defined(LOW_MEMORY)
-#define ASTERISK_FILE_VERSION(file, version) \
- static void __attribute__((constructor)) __register_file_version(void) \
- { \
- ast_register_file_version(file, version); \
- } \
- static void __attribute__((destructor)) __unregister_file_version(void) \
- { \
- ast_unregister_file_version(file); \
- }
-#elif !defined(LOW_MEMORY) /* ! __GNUC__ && ! LOW_MEMORY*/
-#define ASTERISK_FILE_VERSION(file, x) static const char __file_version[] = x;
-#else /* LOW_MEMORY */
-#define ASTERISK_FILE_VERSION(file, x)
-#endif /* __GNUC__ */
-
-#endif /* _ASTERISK_H */
diff --git a/1.2-netsec/include/asterisk/acl.h b/1.2-netsec/include/asterisk/acl.h
deleted file mode 100644
index ad946d57e..000000000
--- a/1.2-netsec/include/asterisk/acl.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Access Control of various sorts
- */
-
-#ifndef _ASTERISK_ACL_H
-#define _ASTERISK_ACL_H
-
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#include <netinet/in.h>
-#include "asterisk/io.h"
-
-#define AST_SENSE_DENY 0
-#define AST_SENSE_ALLOW 1
-
-/* Host based access control */
-
-struct ast_ha;
-
-extern void ast_free_ha(struct ast_ha *ha);
-extern struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path);
-extern int ast_apply_ha(struct ast_ha *ha, struct sockaddr_in *sin);
-extern int ast_get_ip(struct sockaddr_in *sin, const char *value);
-extern int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *service);
-extern int ast_ouraddrfor(struct in_addr *them, struct in_addr *us);
-extern int ast_lookup_iface(char *iface, struct in_addr *address);
-extern struct ast_ha *ast_duplicate_ha_list(struct ast_ha *original);
-extern int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr);
-extern int ast_str2tos(const char *value, int *tos);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_ACL_H */
diff --git a/1.2-netsec/include/asterisk/adsi.h b/1.2-netsec/include/asterisk/adsi.h
deleted file mode 100644
index c38d2b76e..000000000
--- a/1.2-netsec/include/asterisk/adsi.h
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief ADSI Support (built upon Caller*ID)
- */
-
-#ifndef _ASTERISK_ADSI_H
-#define _ASTERISK_ADSI_H
-
-#include "asterisk/callerid.h"
-
-/* ADSI Message types */
-#define ADSI_MSG_DISPLAY 132
-#define ADSI_MSG_DOWNLOAD 133
-
-/* ADSI Parameters (display) */
-#define ADSI_LOAD_SOFTKEY 128
-#define ADSI_INIT_SOFTKEY_LINE 129
-#define ADSI_LOAD_VIRTUAL_DISP 130
-#define ADSI_LINE_CONTROL 131
-#define ADSI_INFORMATION 132
-#define ADSI_DISC_SESSION 133
-#define ADSI_SWITCH_TO_DATA 134
-#define ADSI_SWITCH_TO_VOICE 135
-#define ADSI_CLEAR_SOFTKEY 136
-#define ADSI_INPUT_CONTROL 137
-#define ADSI_INPUT_FORMAT 138
-#define ADSI_SWITCH_TO_PERIPH 139
-#define ADSI_MOVE_DATA 140
-#define ADSI_LOAD_DEFAULT 141
-#define ADSI_CONNECT_SESSION 142
-#define ADSI_CLEAR_TYPE_AHEAD 143
-#define ADSI_DISPLAY_CALL_BUF 144
-#define ADSI_CLEAR_CALL_BUF 145
-#define ADSI_SWITCH_TO_ALT 146
-#define ADSI_SWITCH_TO_GRAPHICS 147
-#define ADSI_CLEAR_SCREEN 148
-#define ADSI_QUERY_CONFIG 149
-#define ADSI_QUERY_CPEID 150
-#define ADSI_SWITCH_TO_APP 151
-
-/* Feature download messages */
-#define ADSI_LOAD_SOFTKEY_TABLE 128 /* Conveniently identical to the soft version */
-#define ADSI_LOAD_PREDEF_DISP 129 /* Load predefined display */
-#define ADSI_LOAD_SCRIPT 130
-#define ADSI_DOWNLOAD_CONNECT 131
-#define ADSI_DOWNLOAD_DISC 132
-
-/* Special return string codes */
-#define ADSI_ENCODED_DTMF 0x80 /* Transmit following chars with encoded dtmf */
-#define ADSI_ON_HOOK 0x81 /* Open switch-hook */
-#define ADSI_OFF_HOOK 0x82 /* Close switch-hook */
-#define ADSI_FLASH 0x83 /* Flash switch-hook */
-#define ADSI_DIAL_TONE_DETECT 0x84 /* Wait for dialtone */
-#define ADSI_LINE_NUMBER 0x85 /* Send current line number using DTMF/encoded DTMF */
-#define ADSI_BLANK 0x86 /* Blank (does nothing) */
-#define ADSI_SEND_CHARS 0x87 /* Send collected digits/characters */
-#define ADSI_CLEAR_CHARS 0x88 /* Clear characters/digits collected */
-#define ADSI_BACKSPACE 0x89 /* Erase last collected digit */
-#define ADSI_TAB_COLUMN 0x8A /* Display specified display column of current line */
-#define ADSI_GOTO_LINE 0x8B /* Go to given page and line number */
-#define ADSI_GOTO_LINE_REL 0x8C /* Go to given line (relative to current) */
-#define ADSI_PAGE_UP 0x8D /* Go up one page */
-#define ADSI_PAGE_DOWN 0x8E /* Go down one page */
-#define ADSI_EXTENDED_DTMF 0x8F /* Send DTMF tones for 250ms instead of 60 ms */
-#define ADSI_DELAY 0x90 /* Delay for given # (times 10) of ms */
-#define ADSI_DIAL_PULSE_ONE 0x91 /* Send a dial pulse "1" */
-#define ADSI_SWITCH_TO_DATA2 0x92 /* Switch CPE to data mode */
-#define ADSI_SWITCH_TO_VOICE2 0x93 /* Switch CPE to voice mode */
-#define ADSI_DISP_CALL_BUF 0x94 /* Display specified call buffer */
-#define ADSI_CLEAR_CALL_B 0x95 /* Clear specified call buffer */
-
-#ifdef __ADSI_CPE
-/* These messages are reserved for the ADSI CPE only */
-#define ADSI_DISPLAY_CONTROL 0x98 /* Store predefined display identified next / Display status display page */
-#define ADSI_DISPLAY_SOFT_KEYS 0x99 /* Display the script soft keys identified next */
-#define ADSI_CHANGE_STATE 0x9A /* Change state of service script */
-#define ADSI_START_CLEAR_TIMER 0x9B /* Start / Clear timer */
-#define ADSI_SET_SCRIPT_FLAG 0x9C /* Set / clear a script flag */
-#define ADSI_JUMP_TO_SUBSCRIPT 0x9D /* Jump to specified subscript */
-#define ADSI_EVENT_22_TRIGGER 0x9E /* Trigger an occurance of event 22 */
-#define ADSI_EVENT_23_TRIGGER 0x9f /* Trigger an occurance of event 23 */
-#define ADSI_EXIT 0xA0 /* Exit the service script interpreter */
-#endif
-
-/* Display pages */
-#define ADSI_INFO_PAGE 0x0
-#define ADSI_COMM_PAGE 0x1
-
-#define ADSI_KEY_APPS 16 /* 16 to 33 reserved for applications */
-
-/* Justification */
-#define ADSI_JUST_LEFT 0x2
-#define ADSI_JUST_RIGHT 0x1
-#define ADSI_JUST_CENT 0x0 /* Center */
-#define ADSI_JUST_IND 0x3 /* Indent */
-
-#define ADSI_KEY_SKT 0x80 /* Load from SKT */
-#define ADSI_KEY_HILITE 0x40 /* Highlight key */
-
-#define ADSI_DIR_FROM_LEFT (0)
-#define ADSI_DIR_FROM_RIGHT (1)
-
-/*! Perform Asterisk ADSI initialization (for channel drivers that want */
-/* to support ADSI when the handset is first lifted) */
-/*!
- * \param chan Channel to initialize for ADSI (if supported)
- *
- * Returns 0 on success (or adsi unavailable) and -1 on hangup
- *
- */
-extern int adsi_channel_init(struct ast_channel *chan);
-
-extern int adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version);
-
-extern int adsi_end_download(struct ast_channel *chan);
-
-/*! Restore ADSI initialization (for applications that play with ADSI */
-/* and want to restore it to normal. If you touch "INFO" then you */
-/* have to use the adsi_channel_init again instead. */
-/*!
- * \param chan Channel to restore
- *
- * Returns 0 on success (or adsi unavailable) and -1 on hangup
- *
- */
-extern int adsi_channel_restore(struct ast_channel *chan);
-
-/*! Display some stuff on the screen */
-/*!
- * \param chan Channel to display on
- * \param lines NULL-terminated list of things to print (no more than 4 recommended)
- * \param align list of alignments to use (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CEN, etc..)
- * \param voice whether to jump into voice mode when finished
- *
- * Return 0 on success (or adsi unavailable) and -1 on hangup
- *
- */
-extern int adsi_print(struct ast_channel *chan, char **lines, int *align, int voice);
-
-/*! Check if scripts for a given app are already loaded. Version may be -1 */
-/* if any version is okay, or 0-255 for a specific version. */
-/*!
- * \param chan Channel to test for loaded app
- * \param app Four character app name (must be unique to your application)
- * \param ver optional version number
- * \param data Non-zero if you want to be put in data mode
- *
- * Returns 0 if scripts is not loaded or not an ADSI CPE. Returns -1
- * on hangup. Returns 1 if script already loaded.
- */
-extern int adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data);
-extern int adsi_unload_session(struct ast_channel *chan);
-
-/* ADSI Layer 2 transmission functions */
-extern int adsi_transmit_messages(struct ast_channel *chan, unsigned char **msg, int *msglen, int *msgtype);
-extern int adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype);
-extern int adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait);
-/*! Read some encoded DTMF data. */
-/*!
- * Returns number of bytes received
- */
-extern int adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen);
-
-/* ADSI Layer 3 creation functions */
-
-/*! Connects an ADSI Display Session */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- * \param fdn Optional 4 byte Feature Download Number (for loading soft keys)
- * \param ver Optional version number (0-255, or -1 to omit)
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-
-extern int adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver);
-
-/*! Build Query CPE ID of equipment */
-/*!
- * Returns number of bytes added to message
- */
-extern int adsi_query_cpeid(unsigned char *buf);
-extern int adsi_query_cpeinfo(unsigned char *buf);
-
-/*! Get CPE ID from an attached ADSI compatible CPE. */
-/*!
- * Returns 1 on success, storing 4 bytes of CPE ID at buf
- * or -1 on hangup, or 0 if there was no hangup but it failed to find the
- * device ID. Returns to voice mode if "voice" is non-zero.
- */
-extern int adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice);
-
-extern int adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice);
-
-/*! Begin an ADSI script download */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- * \param service a 1-18 byte name of the feature
- * \param fdn 4 byte Feature Download Number (for loading soft keys)
- * \param sec 4 byte vendor security code
- * \param ver version number (0-255, or -1 to omit)
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-
-extern int adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver);
-
-/*! Disconnects a running session */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-extern int adsi_disconnect_session(unsigned char *buf);
-
-/*! Disconnects (and hopefully saves) a downloaded script */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-extern int adsi_download_disconnect(unsigned char *buf);
-
-/*! Puts CPE in data mode... */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-extern int adsi_data_mode(unsigned char *buf);
-extern int adsi_clear_soft_keys(unsigned char *buf);
-extern int adsi_clear_screen(unsigned char *buf);
-
-/*! Puts CPE in voice mode... */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- * \param when (a time in seconds) to make the switch
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-extern int adsi_voice_mode(unsigned char *buf, int when);
-
-/*! Returns non-zero if Channel does or might support ADSI */
-/*!
- * \param chan Channel to check
- *
- */
-extern int adsi_available(struct ast_channel *chan);
-
-/*! Loads a line of info into the display */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- * \param page Page to load (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
- * \param line Line number to load (1-4 for Comm page, 1-33 for info page)
- * \param just Line justification (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CENT, ADSI_JUST_IND)
- * \param wrap Wrap (1 = yes, 0 = no)
- * \param col1 Text to place in first column
- * \param col2 Text to place in second column
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-
-extern int adsi_display(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2);
-
-/*! Sets the current line and page */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- * \param page Which page (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
- * \param line Line number (1-33 for info page, 1-4 for comm page)
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-
-extern int adsi_set_line(unsigned char *buf, int page, int line);
-
-/*! Creates "load soft key" parameters */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- * \param key Key code from 2 to 33, for which key we are loading
- * \param llabel Long label for key (1-18 bytes)
- * \param slabel Short label for key (1-7 bytes)
- * \param ret Optional return sequence (NULL for none)
- * \param data whether to put CPE in data mode before sending digits
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-extern int adsi_load_soft_key(unsigned char *buf, int key, char *llabel, char *slabel, char *ret, int data);
-
-/*! Set which soft keys should be displayed */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- * \param keys Array of 8 unsigned chars with the key numbers, may be OR'd with ADSI_KEY_HILITE
- * But remember, the last two keys aren't real keys, they're for scrolling
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-extern int adsi_set_keys(unsigned char *buf, unsigned char *keys);
-
-/*! Set input information */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- * \param page Which page to input on (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
- * \param line Line number to input on
- * \param display Set to zero to obscure input, or 1 to leave visible
- * \param format Format number to use (0-7)
- * \param just Justification (left, right center, indent)
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-extern int adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just);
-
-/*! Set input format */
-/*!
- * \param buf Character buffer to create parameter in (must have at least 256 free)
- * \param num Which format we are setting
- * \param dir Which direction (ADSI_DIR_FROM_LEFT or ADSI_DIR_FROM_RIGHT)
- * \param wrap Set to 1 to permit line wrap, or 0 if not
- * \param format1 Format for column 1
- * \param format2 Format for column 2
- *
- * Returns number of bytes added to buffer or -1 on error.
- *
- */
-extern int adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2);
-
-#endif /* _ASTERISK_ADSI_H */
diff --git a/1.2-netsec/include/asterisk/aes.h b/1.2-netsec/include/asterisk/aes.h
deleted file mode 100644
index af648e8ee..000000000
--- a/1.2-netsec/include/asterisk/aes.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * 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.
- */
-
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 2003, Dr Brian Gladman <brg@gladman.me.uk>, 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 definitions required to use AES in C. See aesopt.h
- for optimisation details.
-*/
-
-#ifndef _AES_H
-#define _AES_H
-
-/* This include is used to find 8 & 32 bit unsigned integer types */
-#include "limits.h"
-
-#if defined(__cplusplus)
-extern "C"
-{
-#endif
-
-#define AES_128 /* define if AES with 128 bit keys is needed */
-#undef AES_192 /* define if AES with 192 bit keys is needed */
-#undef AES_256 /* define if AES with 256 bit keys is needed */
-#undef AES_VAR /* define if a variable key size is needed */
-
-/* The following must also be set in assembler files if being used */
-
-#define AES_ENCRYPT /* if support for encryption is needed */
-#define AES_DECRYPT /* if support for decryption is needed */
-#define AES_ERR_CHK /* for parameter checks & error return codes */
-
-#if UCHAR_MAX == 0xff /* an unsigned 8 bit type */
- typedef unsigned char aes_08t;
-#else
-#error Please define aes_08t as an 8-bit unsigned integer type in aes.h
-#endif
-
-#if UINT_MAX == 0xffffffff /* an unsigned 32 bit type */
- typedef unsigned int aes_32t;
-#elif ULONG_MAX == 0xffffffff
- typedef unsigned long aes_32t;
-#else
-#error Please define aes_32t as a 32-bit unsigned integer type in aes.h
-#endif
-
-#define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
-#define N_COLS 4 /* the number of columns in the state */
-
-/* a maximum of 60 32-bit words are needed for the key schedule but */
-/* 64 are claimed to allow space at the top for a CBC xor buffer. */
-/* If this is not needed, this value can be reduced to 60. A value */
-/* of 64 may also help in maintaining alignment in some situations */
-#define KS_LENGTH 64
-
-#ifdef AES_ERR_CHK
-#define aes_ret int
-#define aes_good 0
-#define aes_error -1
-#else
-#define aes_ret void
-#endif
-
-#ifndef AES_DLL /* implement normal/DLL functions */
-#define aes_rval aes_ret
-#else
-#define aes_rval aes_ret __declspec(dllexport) _stdcall
-#endif
-
-/* This routine must be called before first use if non-static */
-/* tables are being used */
-
-void gen_tabs(void);
-
-/* The key length (klen) is input in bytes when it is in the range */
-/* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */
-
-#ifdef AES_ENCRYPT
-
-typedef struct
-{ aes_32t ks[KS_LENGTH];
-} aes_encrypt_ctx;
-
-#if defined(AES_128) || defined(AES_VAR)
-aes_rval aes_encrypt_key128(const void *in_key, aes_encrypt_ctx cx[1]);
-#endif
-
-#if defined(AES_192) || defined(AES_VAR)
-aes_rval aes_encrypt_key192(const void *in_key, aes_encrypt_ctx cx[1]);
-#endif
-
-#if defined(AES_256) || defined(AES_VAR)
-aes_rval aes_encrypt_key256(const void *in_key, aes_encrypt_ctx cx[1]);
-#endif
-
-#if defined(AES_VAR)
-aes_rval aes_encrypt_key(const void *in_key, int key_len, aes_encrypt_ctx cx[1]);
-#endif
-
-aes_rval aes_encrypt(const void *in_blk, void *out_blk, const aes_encrypt_ctx cx[1]);
-#endif
-
-#ifdef AES_DECRYPT
-
-typedef struct
-{ aes_32t ks[KS_LENGTH];
-} aes_decrypt_ctx;
-
-#if defined(AES_128) || defined(AES_VAR)
-aes_rval aes_decrypt_key128(const void *in_key, aes_decrypt_ctx cx[1]);
-#endif
-
-#if defined(AES_192) || defined(AES_VAR)
-aes_rval aes_decrypt_key192(const void *in_key, aes_decrypt_ctx cx[1]);
-#endif
-
-#if defined(AES_256) || defined(AES_VAR)
-aes_rval aes_decrypt_key256(const void *in_key, aes_decrypt_ctx cx[1]);
-#endif
-
-#if defined(AES_VAR)
-aes_rval aes_decrypt_key(const void *in_key, int key_len, aes_decrypt_ctx cx[1]);
-#endif
-
-aes_rval aes_decrypt(const void *in_blk, void *out_blk, const aes_decrypt_ctx cx[1]);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif
diff --git a/1.2-netsec/include/asterisk/agi.h b/1.2-netsec/include/asterisk/agi.h
deleted file mode 100644
index 226041173..000000000
--- a/1.2-netsec/include/asterisk/agi.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief AGI Extension interfaces - Asterisk Gateway Interface
- */
-
-#ifndef _ASTERISK_AGI_H
-#define _ASTERISK_AGI_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-typedef struct agi_state {
- int fd; /* FD for general output */
- int audio; /* FD for audio output */
- int ctrl; /* FD for input control */
-} AGI;
-
-typedef struct agi_command {
- /* Null terminated list of the words of the command */
- char *cmda[AST_MAX_CMD_LEN];
- /* Handler for the command (channel, AGI state, # of arguments, argument list).
- Returns RESULT_SHOWUSAGE for improper arguments */
- int (*handler)(struct ast_channel *chan, AGI *agi, int argc, char *argv[]);
- /* Summary of the command (< 60 characters) */
- char *summary;
- /* Detailed usage information */
- char *usage;
- struct agi_command *next;
-} agi_command;
-
-int agi_register(agi_command *cmd);
-void agi_unregister(agi_command *cmd);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_AGI_H */
diff --git a/1.2-netsec/include/asterisk/alaw.h b/1.2-netsec/include/asterisk/alaw.h
deleted file mode 100644
index 6feb07aa2..000000000
--- a/1.2-netsec/include/asterisk/alaw.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief A-Law to Signed linear conversion
- */
-
-#ifndef _ASTERISK_ALAW_H
-#define _ASTERISK_ALAW_H
-
-/*! Init the ulaw conversion stuff */
-/*!
- * To init the ulaw to slinear conversion stuff, this needs to be run.
- */
-extern void ast_alaw_init(void);
-
-/*! converts signed linear to mulaw */
-/*!
- */
-extern unsigned char __ast_lin2a[8192];
-
-/*! help */
-extern short __ast_alaw[256];
-
-#define AST_LIN2A(a) (__ast_lin2a[((unsigned short)(a)) >> 3])
-#define AST_ALAW(a) (__ast_alaw[(int)(a)])
-
-#endif /* _ASTERISK_ALAW_H */
diff --git a/1.2-netsec/include/asterisk/app.h b/1.2-netsec/include/asterisk/app.h
deleted file mode 100644
index 38b1fdb73..000000000
--- a/1.2-netsec/include/asterisk/app.h
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Application convenience functions, designed to give consistent
- look and feel to Asterisk apps.
- */
-
-#ifndef _ASTERISK_APP_H
-#define _ASTERISK_APP_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/* IVR stuff */
-
-/*! \brief Callback function for IVR
- \return returns 0 on completion, -1 on hangup or digit if interrupted
- */
-typedef int (*ast_ivr_callback)(struct ast_channel *chan, char *option, void *cbdata);
-
-typedef enum {
- AST_ACTION_UPONE, /*!< adata is unused */
- AST_ACTION_EXIT, /*!< adata is the return value for ast_ivr_menu_run if channel was not hungup */
- AST_ACTION_CALLBACK, /*!< adata is an ast_ivr_callback */
- AST_ACTION_PLAYBACK, /*!< adata is file to play */
- AST_ACTION_BACKGROUND, /*!< adata is file to play */
- AST_ACTION_PLAYLIST, /*!< adata is list of files, separated by ; to play */
- AST_ACTION_MENU, /*!< adata is a pointer to an ast_ivr_menu */
- AST_ACTION_REPEAT, /*!< adata is max # of repeats, cast to a pointer */
- AST_ACTION_RESTART, /*!< adata is like repeat, but resets repeats to 0 */
- AST_ACTION_TRANSFER, /*!< adata is a string with exten[@context] */
- AST_ACTION_WAITOPTION, /*!< adata is a timeout, or 0 for defaults */
- AST_ACTION_NOOP, /*!< adata is unused */
- AST_ACTION_BACKLIST, /*!< adata is list of files separated by ; allows interruption */
-} ast_ivr_action;
-
-/*!
- Special "options" are:
- \arg "s" - "start here (one time greeting)"
- \arg "g" - "greeting/instructions"
- \arg "t" - "timeout"
- \arg "h" - "hangup"
- \arg "i" - "invalid selection"
-
-*/
-struct ast_ivr_option {
- char *option;
- ast_ivr_action action;
- void *adata;
-};
-
-struct ast_ivr_menu {
- char *title; /*!< Title of menu */
- unsigned int flags; /*!< Flags */
- struct ast_ivr_option *options; /*!< All options */
-};
-
-#define AST_IVR_FLAG_AUTORESTART (1 << 0)
-
-#define AST_IVR_DECLARE_MENU(holder, title, flags, foo...) \
- static struct ast_ivr_option __options_##holder[] = foo;\
- static struct ast_ivr_menu holder = { title, flags, __options_##holder }
-
-
-/*! \brief Runs an IVR menu
- \return returns 0 on successful completion, -1 on hangup, or -2 on user error in menu */
-extern int ast_ivr_menu_run(struct ast_channel *c, struct ast_ivr_menu *menu, void *cbdata);
-
-/*! \brief Plays a stream and gets DTMF data from a channel
- * \param c Which channel one is interacting with
- * \param prompt File to pass to ast_streamfile (the one that you wish to play)
- * \param s The location where the DTMF data will be stored
- * \param maxlen Max Length of the data
- * \param timeout Timeout length waiting for data(in milliseconds). Set to 0 for standard timeout(six seconds), or -1 for no time out.
- *
- * This function was designed for application programmers for situations where they need
- * to play a message and then get some DTMF data in response to the message. If a digit
- * is pressed during playback, it will immediately break out of the message and continue
- * execution of your code.
- */
-extern int ast_app_getdata(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout);
-
-/*! \brief Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other full functions */
-extern int ast_app_getdata_full(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd);
-
-/*! Record voice (after playing prompt if specified), waiting for silence (in ms) up to a given timeout (in s) or '#' */
-int ast_app_getvoice(struct ast_channel *c, char *dest, char *dstfmt, char *prompt, int silence, int maxsec);
-
-void ast_install_vm_functions(int (*has_voicemail_func)(const char *mailbox, const char *folder),
- int (*messagecount_func)(const char *mailbox, int *newmsgs, int *oldmsgs));
-
-void ast_uninstall_vm_functions(void);
-
-/*! Determine if a given mailbox has any voicemail */
-int ast_app_has_voicemail(const char *mailbox, const char *folder);
-
-/*! Determine number of new/old messages in a mailbox */
-int ast_app_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs);
-
-/*! Safely spawn an external program while closing file descriptors
- \note This replaces the \b system call in all Asterisk modules
-*/
-extern int ast_safe_system(const char *s);
-
-/*! Send DTMF to chan (optionally entertain peer) */
-int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, char *digits, int between);
-
-/*! Stream a filename (or file descriptor) as a generator. */
-int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, int allowoverride);
-
-/*! Stream a file with fast forward, pause, reverse, restart. */
-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);
-
-/*! Play a stream and wait for a digit, returning the digit that was pressed */
-int ast_play_and_wait(struct ast_channel *chan, const char *fn);
-
-/*! Record a file for a max amount of time (in seconds), in a given list of formats separated by '|', outputting the duration of the recording, and with a maximum
- \n
- permitted silence time in milliseconds of 'maxsilence' under 'silencethreshold' or use '-1' for either or both parameters for defaults.
- calls ast_unlock_path() on 'path' if passed */
-int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int silencethreshold, int maxsilence_ms, const char *path);
-
-/*! Record a message and prepend the message to the given record file after
- playing the optional playfile (or a beep), storing the duration in
- 'duration' and with a maximum
-\n
- permitted silence time in milliseconds of 'maxsilence' under
- 'silencethreshold' or use '-1' for either or both parameters for defaults. */
-int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime_sec, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence_ms);
-
-enum AST_LOCK_RESULT {
- AST_LOCK_SUCCESS = 0,
- AST_LOCK_TIMEOUT = -1,
- AST_LOCK_PATH_NOT_FOUND = -2,
- AST_LOCK_FAILURE = -3,
-};
-
-/*!
- * \brief Lock a filesystem path.
- * \param path the path to be locked
- * \return one of \ref AST_LOCK_RESULT values
- */
-enum AST_LOCK_RESULT ast_lock_path(const char *path);
-
-/*! Unlock a path */
-int ast_unlock_path(const char *path);
-
-/*! Read a file into asterisk*/
-char *ast_read_textfile(const char *file);
-
-#define GROUP_CATEGORY_PREFIX "GROUP"
-
-/*! Split a group string into group and category, returning a default category if none is provided. */
-int ast_app_group_split_group(char *data, char *group, int group_max, char *category, int category_max);
-
-/*! Set the group for a channel, splitting the provided data into group and category, if specified. */
-int ast_app_group_set_channel(struct ast_channel *chan, char *data);
-
-/*! Get the current channel count of the specified group and category. */
-int ast_app_group_get_count(char *group, char *category);
-
-/*! Get the current channel count of all groups that match the specified pattern and category. */
-int ast_app_group_match_get_count(char *groupmatch, char *category);
-
-/*!
- \brief Define an application argument
- \param name The name of the argument
-*/
-#define AST_APP_ARG(name) char *name
-
-/*!
- \brief Declare a structure to hold the application's arguments.
- \param name The name of the structure
- \param arglist The list of arguments, defined using AST_APP_ARG
-
- This macro defines a structure intended to be used in a call
- to ast_app_separate_args(). The structure includes all the
- arguments specified, plus an argv array that overlays them and an
- argc argument counter. The arguments must be declared using AST_APP_ARG,
- and they will all be character pointers (strings).
-
- \note The structure is <b>not</b> initialized, as the call to
- ast_app_separate_args() will perform that function before parsing
- the arguments.
- */
-#define AST_DECLARE_APP_ARGS(name, arglist) \
- struct { \
- unsigned int argc; \
- char *argv[0]; \
- arglist \
- } name
-
-/*!
- \brief Performs the 'standard' argument separation process for an application.
- \param args An argument structure defined using AST_DECLARE_APP_ARGS
- \param parse A modifiable buffer containing the input to be parsed
-
- This function will separate the input string using the standard argument
- separator character '|' and fill in the provided structure, including
- the argc argument counter field.
- */
-#define AST_STANDARD_APP_ARGS(args, parse) \
- args.argc = ast_app_separate_args(parse, '|', args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0]))
-
-/*!
- \brief Separate a string into arguments in an array
- \param buf The string to be parsed (this must be a writable copy, as it will be modified)
- \param delim The character to be used to delimit arguments
- \param array An array of 'char *' to be filled in with pointers to the found arguments
- \param arraylen The number of elements in the array (i.e. the number of arguments you will accept)
-
- Note: if there are more arguments in the string than the array will hold, the last element of
- the array will contain the remaining arguments, not separated.
-
- The array will be completely zeroed by this function before it populates any entries.
-
- \return The number of arguments found, or zero if the function arguments are not valid.
-*/
-unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen);
-
-/*!
- \brief A structure to hold the description of an application 'option'.
-
- Application 'options' are single-character flags that can be supplied
- to the application to affect its behavior; they can also optionally
- accept arguments enclosed in parenthesis.
-
- These structures are used by the ast_app_parse_options function, uses
- this data to fill in a flags structure (to indicate which options were
- supplied) and array of argument pointers (for those options that had
- arguments supplied).
- */
-struct ast_app_option {
- /*! \brief The flag bit that represents this option. */
- unsigned int flag;
- /*! \brief The index of the entry in the arguments array
- that should be used for this option's argument. */
- unsigned int arg_index;
-};
-
-/*!
- \brief Declares an array of options for an application.
- \param holder The name of the array to be created
- \param options The actual options to be placed into the array
- \sa ast_app_parse_options
-
- This macro declares a 'static const' array of \c struct \c ast_option
- elements to hold the list of available options for an application.
- Each option must be declared using either the AST_APP_OPTION()
- or AST_APP_OPTION_ARG() macros.
-
- Example usage:
- \code
- enum {
- OPT_JUMP = (1 << 0),
- OPT_BLAH = (1 << 1),
- OPT_BLORT = (1 << 2),
- } my_app_option_flags;
-
- enum {
- OPT_ARG_BLAH = 0,
- OPT_ARG_BLORT,
- !! this entry tells how many possible arguments there are,
- and must be the last entry in the list
- OPT_ARG_ARRAY_SIZE,
- } my_app_option_args;
-
- AST_APP_OPTIONS(my_app_options, {
- AST_APP_OPTION('j', OPT_JUMP),
- AST_APP_OPTION_ARG('b', OPT_BLAH, OPT_ARG_BLAH),
- AST_APP_OPTION_BLORT('B', OPT_BLORT, OPT_ARG_BLORT),
- });
-
- static int my_app_exec(struct ast_channel *chan, void *data)
- {
- char *options;
- struct ast_flags opts = { 0, };
- char *opt_args[OPT_ARG_ARRAY_SIZE];
-
- ... do any argument parsing here ...
-
- if (ast_parseoptions(my_app_options, &opts, opt_args, options)) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
- \endcode
- */
-#define AST_APP_OPTIONS(holder, options...) \
- static const struct ast_app_option holder[128] = options
-
-/*!
- \brief Declares an application option that does not accept an argument.
- \param option The single character representing the option
- \param flagno The flag index to be set if this option is present
- \sa AST_APP_OPTIONS, ast_app_parse_options
- */
-#define AST_APP_OPTION(option, flagno) \
- [option] = { .flag = flagno }
-
-/*!
- \brief Declares an application option that accepts an argument.
- \param option The single character representing the option
- \param flagno The flag index to be set if this option is present
- \param argno The index into the argument array where the argument should
- be placed
- \sa AST_APP_OPTIONS, ast_app_parse_options
- */
-#define AST_APP_OPTION_ARG(option, flagno, argno) \
- [option] = { .flag = flagno, .arg_index = argno + 1 }
-
-/*!
- \brief Parses a string containing application options and sets flags/arguments.
- \param options The array of possible options declared with AST_APP_OPTIONS
- \param flags The flag structure to have option flags set
- \param args The array of argument pointers to hold arguments found
- \param optstr The string containing the options to be parsed
- \return zero for success, non-zero if an error occurs
- \sa AST_APP_OPTIONS
- */
-int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr);
-
-/*! \brief Present a dialtone and collect a certain length extension.
- \return Returns 1 on valid extension entered, -1 on hangup, or 0 on invalid extension.
-\note Note that if 'collect' holds digits already, new digits will be appended, so be sure it's initialized properly */
-int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout);
-
-/*! Allow to record message and have a review option */
-int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_APP_H */
diff --git a/1.2-netsec/include/asterisk/ast_expr.h b/1.2-netsec/include/asterisk/ast_expr.h
deleted file mode 100644
index bc0331309..000000000
--- a/1.2-netsec/include/asterisk/ast_expr.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#ifndef _ASTERISK_EXPR_H
-#define _ASTERISK_EXPR_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-int ast_expr(char *expr, char *buf, int length);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_EXPR_H */
diff --git a/1.2-netsec/include/asterisk/astdb.h b/1.2-netsec/include/asterisk/astdb.h
deleted file mode 100644
index 828fe9725..000000000
--- a/1.2-netsec/include/asterisk/astdb.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Persistant data storage (akin to *doze registry)
- */
-
-#ifndef _ASTERISK_ASTDB_H
-#define _ASTERISK_ASTDB_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-struct ast_db_entry {
- struct ast_db_entry *next;
- char *key;
- char data[0];
-};
-
-int ast_db_get(const char *family, const char *key, char *out, int outlen);
-
-int ast_db_put(const char *family, const char *key, char *value);
-
-int ast_db_del(const char *family, const char *key);
-
-int ast_db_deltree(const char *family, const char *keytree);
-
-struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree);
-
-void ast_db_freetree(struct ast_db_entry *entry);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_ASTDB_H */
diff --git a/1.2-netsec/include/asterisk/astmm.h b/1.2-netsec/include/asterisk/astmm.h
deleted file mode 100644
index 9e70366fa..000000000
--- a/1.2-netsec/include/asterisk/astmm.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Asterisk memory usage debugging
- */
-
-#ifndef NO_AST_MM
-#ifndef _ASTERISK_ASTMM_H
-#define _ASTERISK_ASTMM_H
-
-#define __AST_DEBUG_MALLOC
-
-/* Include these now to prevent them from being needed later */
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-/* Undefine any macros */
-#undef malloc
-#undef calloc
-#undef realloc
-#undef strdup
-#undef strndup
-#undef vasprintf
-
-void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
-void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
-void __ast_free(void *ptr, const char *file, int lineno, const char *func);
-void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
-char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
-char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
-int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func);
-
-void __ast_mm_init(void);
-
-
-/* Provide our own definitions */
-#define calloc(a,b) \
- __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define malloc(a) \
- __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define free(a) \
- __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define realloc(a,b) \
- __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define strdup(a) \
- __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define strndup(a,b) \
- __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define vasprintf(a,b,c) \
- __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#else
-#error "NEVER INCLUDE astmm.h DIRECTLY!!"
-#endif /* _ASTERISK_ASTMM_H */
-#endif
diff --git a/1.2-netsec/include/asterisk/astobj.h b/1.2-netsec/include/asterisk/astobj.h
deleted file mode 100644
index 8e373c6c5..000000000
--- a/1.2-netsec/include/asterisk/astobj.h
+++ /dev/null
@@ -1,752 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
- * Object Model for Asterisk
- */
-
-#ifndef _ASTERISK_ASTOBJ_H
-#define _ASTERISK_ASTOBJ_H
-
-#include <string.h>
-
-#include "asterisk/lock.h"
-#include "asterisk/compiler.h"
-
-/*! \file
- * \brief A set of macros implementing objects and containers.
- * Macros are used for maximum performance, to support multiple inheritance,
- * and to be easily integrated into existing structures without additional
- * malloc calls, etc.
- *
- * These macros expect to operate on two different object types, ASTOBJs and
- * ASTOBJ_CONTAINERs. These are not actual types, as any struct can be
- * converted into an ASTOBJ compatible object or container using the supplied
- * macros.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_object {
- * ASTOBJ_COMPONENTS(struct sample_object);
- * };
- *
- * struct sample_container {
- * ASTOBJ_CONTAINER_COMPONENTS(struct sample_object);
- * } super_container;
- *
- * void sample_object_destroy(struct sample_object *obj)
- * {
- * free(obj);
- * }
- *
- * int init_stuff()
- * {
- * struct sample_object *obj1;
- * struct sample_object *found_obj;
- *
- * obj1 = malloc(sizeof(struct sample_object));
- *
- * ASTOBJ_CONTAINER_INIT(&super_container);
- *
- * ASTOBJ_INIT(obj1);
- * ASTOBJ_WRLOCK(obj1);
- * ast_copy_string(obj1->name, "obj1", sizeof(obj1->name));
- * ASTOBJ_UNLOCK(obj1);
- *
- * ASTOBJ_CONTAINER_LINK(&super_container, obj1);
- *
- * found_obj = ASTOBJ_CONTAINER_FIND(&super_container, "obj1");
- *
- * if(found_obj) {
- * printf("Found object: %s", found_obj->name);
- * ASTOBJ_UNREF(found_obj,sample_object_destroy);
- * }
- *
- * ASTOBJ_CONTAINER_DESTROYALL(&super_container,sample_object_destroy);
- * ASTOBJ_CONTAINER_DESTROY(&super_container);
- *
- * return 0;
- * }
- * \endcode
- */
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#define ASTOBJ_DEFAULT_NAMELEN 80
-#define ASTOBJ_DEFAULT_BUCKETS 256
-#define ASTOBJ_DEFAULT_HASH ast_strhash
-
-#define ASTOBJ_FLAG_MARKED (1 << 0) /* Object has been marked for future operation */
-
-/* C++ is simply a syntactic crutch for those who cannot think for themselves
- in an object oriented way. */
-
-/*! \brief Lock an ASTOBJ for reading.
- */
-#define ASTOBJ_RDLOCK(object) ast_mutex_lock(&(object)->_lock)
-
-/*! \brief Lock an ASTOBJ for writing.
- */
-#define ASTOBJ_WRLOCK(object) ast_mutex_lock(&(object)->_lock)
-
-/*! \brief Unlock a locked object. */
-#define ASTOBJ_UNLOCK(object) ast_mutex_unlock(&(object)->_lock)
-
-#ifdef ASTOBJ_CONTAINER_HASHMODEL
-#define __ASTOBJ_HASH(type,hashes) \
- type *next[hashes]
-#else
-#define __ASTOBJ_HASH(type,hashes) \
- type *next[1]
-#endif
-
-/*! \brief Add ASTOBJ components to a struct (without locking support).
- *
- * \param type The datatype of the object.
- * \param namelen The length to make the name char array.
- * \param hashes The number of containers the object can be present in.
- *
- * This macro adds components to a struct to make it an ASTOBJ. This macro
- * differs from ASTOBJ_COMPONENTS_FULL in that it does not create a mutex for
- * locking.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_struct {
- * ASTOBJ_COMPONENTS_NOLOCK_FULL(struct sample_struct,1,1);
- * };
- * \endcode
- */
-#define ASTOBJ_COMPONENTS_NOLOCK_FULL(type,namelen,hashes) \
- char name[namelen]; \
- unsigned int refcount; \
- unsigned int objflags; \
- __ASTOBJ_HASH(type,hashes)
-
-/*! \brief Add ASTOBJ components to a struct (without locking support).
- *
- * \param type The datatype of the object.
- *
- * This macro works like #ASTOBJ_COMPONENTS_NOLOCK_FULL() except it only accepts a
- * type and uses default values for namelen and hashes.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_struct_componets {
- * ASTOBJ_COMPONENTS_NOLOCK(struct sample_struct);
- * };
- * \endcode
- */
-#define ASTOBJ_COMPONENTS_NOLOCK(type) \
- ASTOBJ_COMPONENTS_NOLOCK_FULL(type,ASTOBJ_DEFAULT_NAMELEN,1)
-
-/*! \brief Add ASTOBJ components to a struct (with locking support).
- *
- * \param type The datatype of the object.
- *
- * This macro works like #ASTOBJ_COMPONENTS_NOLOCK() except it includes locking
- * support.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_struct {
- * ASTOBJ_COMPONENTS(struct sample_struct);
- * };
- * \endcode
- */
-#define ASTOBJ_COMPONENTS(type) \
- ASTOBJ_COMPONENTS_NOLOCK(type); \
- ast_mutex_t _lock;
-
-/*! \brief Add ASTOBJ components to a struct (with locking support).
- *
- * \param type The datatype of the object.
- * \param namelen The length to make the name char array.
- * \param hashes The number of containers the object can be present in.
- *
- * This macro adds components to a struct to make it an ASTOBJ and includes
- * support for locking.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_struct {
- * ASTOBJ_COMPONENTS_FULL(struct sample_struct,1,1);
- * };
- * \endcode
- */
-#define ASTOBJ_COMPONENTS_FULL(type,namelen,hashes) \
- ASTOBJ_COMPONENTS_NOLOCK_FULL(type,namelen,hashes); \
- ast_mutex_t _lock;
-
-/*! \brief Increment an object reference count.
- * \param object A pointer to the object to operate on.
- * \return The object.
- */
-#define ASTOBJ_REF(object) \
- ({ \
- ASTOBJ_WRLOCK(object); \
- (object)->refcount++; \
- ASTOBJ_UNLOCK(object); \
- (object); \
- })
-
-/*! \brief Decrement the reference count on an object.
- *
- * \param object A pointer the object to operate on.
- * \param destructor The destructor to call if the object is no longer referenced. It will be passed the pointer as an argument.
- *
- * This macro unreferences an object and calls the specfied destructor if the
- * object is no longer referenced. The destructor should free the object if it
- * was dynamically allocated.
- */
-#define ASTOBJ_UNREF(object,destructor) \
- do { \
- int newcount = 0; \
- ASTOBJ_WRLOCK(object); \
- if (__builtin_expect((object)->refcount > 0, 1)) \
- newcount = --((object)->refcount); \
- else \
- ast_log(LOG_WARNING, "Unreferencing unreferenced (object)!\n"); \
- ASTOBJ_UNLOCK(object); \
- if (newcount == 0) { \
- ast_mutex_destroy(&(object)->_lock); \
- destructor((object)); \
- } \
- (object) = NULL; \
- } while(0)
-
-/*! \brief Mark an ASTOBJ by adding the #ASTOBJ_FLAG_MARKED flag to its objflags mask.
- * \param object A pointer to the object to operate on.
- *
- * This macro "marks" an object. Marked objects can later be unlinked from a container using
- * #ASTOBJ_CONTAINER_PRUNE_MARKED().
- *
- */
-#define ASTOBJ_MARK(object) \
- do { \
- ASTOBJ_WRLOCK(object); \
- (object)->objflags |= ASTOBJ_FLAG_MARKED; \
- ASTOBJ_UNLOCK(object); \
- } while(0)
-
-/*! \brief Unmark an ASTOBJ by subtracting the #ASTOBJ_FLAG_MARKED flag from its objflags mask.
- * \param object A pointer to the object to operate on.
- */
-#define ASTOBJ_UNMARK(object) \
- do { \
- ASTOBJ_WRLOCK(object); \
- (object)->objflags &= ~ASTOBJ_FLAG_MARKED; \
- ASTOBJ_UNLOCK(object); \
- } while(0)
-
-/*! \brief Initialize an object.
- * \param object A pointer to the object to operate on.
- *
- * \note This should only be used on objects that support locking (objects
- * created with #ASTOBJ_COMPONENTS() or #ASTOBJ_COMPONENTS_FULL())
- */
-#define ASTOBJ_INIT(object) \
- do { \
- ast_mutex_init(&(object)->_lock); \
- object->name[0] = '\0'; \
- object->refcount = 1; \
- } while(0)
-
-/* Containers for objects -- current implementation is linked lists, but
- should be able to be converted to hashes relatively easily */
-
-/*! \brief Lock an ASTOBJ_CONTAINER for reading.
- */
-#define ASTOBJ_CONTAINER_RDLOCK(container) ast_mutex_lock(&(container)->_lock)
-
-/*! \brief Lock an ASTOBJ_CONTAINER for writing.
- */
-#define ASTOBJ_CONTAINER_WRLOCK(container) ast_mutex_lock(&(container)->_lock)
-
-/*! \brief Unlock an ASTOBJ_CONTAINER. */
-#define ASTOBJ_CONTAINER_UNLOCK(container) ast_mutex_unlock(&(container)->_lock)
-
-#ifdef ASTOBJ_CONTAINER_HASHMODEL
-#error "Hash model for object containers not yet implemented!"
-#else
-/* Linked lists */
-
-/*! \brief Create a container for ASTOBJs (without locking support).
- *
- * \param type The type of objects the container will hold.
- * \param hashes Currently unused.
- * \param buckets Currently unused.
- *
- * This macro is used to create a container for ASTOBJs without locking
- * support.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_struct_nolock_container {
- * ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL(struct sample_struct,1,1);
- * };
- * \endcode
- */
-#define ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL(type,hashes,buckets) \
- type *head
-
-/*! \brief Initialize a container.
- *
- * \param container A pointer to the container to initialize.
- * \param hashes Currently unused.
- * \param buckets Currently unused.
- *
- * This macro initializes a container. It should only be used on containers
- * that support locking.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_struct_container {
- * ASTOBJ_CONTAINER_COMPONENTS_FULL(struct sample_struct,1,1);
- * } container;
- *
- * int func()
- * {
- * ASTOBJ_CONTAINER_INIT_FULL(&container,1,1);
- * }
- * \endcode
- */
-#define ASTOBJ_CONTAINER_INIT_FULL(container,hashes,buckets) \
- do { \
- ast_mutex_init(&(container)->_lock); \
- } while(0)
-
-/*! \brief Destroy a container.
- *
- * \param container A pointer to the container to destroy.
- * \param hashes Currently unused.
- * \param buckets Currently unused.
- *
- * This macro frees up resources used by a container. It does not operate on
- * the objects in the container. To unlink the objects from the container use
- * #ASTOBJ_CONTAINER_DESTROYALL().
- *
- * \note This macro should only be used on containers with locking support.
- */
-#define ASTOBJ_CONTAINER_DESTROY_FULL(container,hashes,buckets) \
- do { \
- ast_mutex_destroy(&(container)->_lock); \
- } while(0)
-
-/*! \brief Iterate through the objects in a container.
- *
- * \param container A pointer to the container to traverse.
- * \param continue A condition to allow the traversal to continue.
- * \param eval A statement to evaluate in the iteration loop.
- *
- * This is macro is a little complicated, but it may help to think of it as a
- * loop. Basically it iterates through the specfied containter as long as the
- * condition is met. Two variables, iterator and next, are provided for use in
- * your \p eval statement. See the sample code for an example.
- *
- * <b>Sample Usage:</b>
- * \code
- * ASTOBJ_CONTAINER_TRAVERSE(&sample_container,1, {
- * ASTOBJ_RDLOCK(iterator);
- * printf("Currently iterating over '%s'\n", iterator->name);
- * ASTOBJ_UNLOCK(iterator);
- * } );
- * \endcode
- *
- * \code
- * ASTOBJ_CONTAINER_TRAVERSE(&sample_container,1, sample_func(iterator));
- * \endcode
- */
-#define ASTOBJ_CONTAINER_TRAVERSE(container,continue,eval) \
- do { \
- typeof((container)->head) iterator; \
- typeof((container)->head) next; \
- ASTOBJ_CONTAINER_RDLOCK(container); \
- next = (container)->head; \
- while((continue) && (iterator = next)) { \
- next = iterator->next[0]; \
- eval; \
- } \
- ASTOBJ_CONTAINER_UNLOCK(container); \
- } while(0)
-
-/*! \brief Find an object in a container.
- *
- * \param container A pointer to the container to search.
- * \param namestr The name to search for.
- *
- * Use this function to find an object with the specfied name in a container.
- *
- * \note When the returned object is no longer in use, #ASTOBJ_UNREF() should
- * be used to free the additional reference created by this macro.
- *
- * \return A new reference to the object located or NULL if nothing is found.
- */
-#define ASTOBJ_CONTAINER_FIND(container,namestr) \
- ({ \
- typeof((container)->head) found = NULL; \
- ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \
- if (!(strcasecmp(iterator->name, (namestr)))) \
- found = ASTOBJ_REF(iterator); \
- } while (0)); \
- found; \
- })
-
-/*! \brief Find an object in a container.
- *
- * \param container A pointer to the container to search.
- * \param data The data to search for.
- * \param field The field/member of the container's objects to search.
- * \param hashfunc The hash function to use, currently not implemented.
- * \param hashoffset The hash offset to use, currently not implemented.
- * \param comparefunc The function used to compare the field and data values.
- *
- * This macro iterates through a container passing the specified field and data
- * elements to the specified comparefunc. The function should return 0 when a match is found.
- *
- * \note When the returned object is no longer in use, #ASTOBJ_UNREF() should
- * be used to free the additional reference created by this macro.
- *
- * \return A pointer to the object located or NULL if nothing is found.
- */
-#define ASTOBJ_CONTAINER_FIND_FULL(container,data,field,hashfunc,hashoffset,comparefunc) \
- ({ \
- typeof((container)->head) found = NULL; \
- ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \
- ASTOBJ_RDLOCK(iterator); \
- if (!(comparefunc(iterator->field, (data)))) { \
- found = ASTOBJ_REF(iterator); \
- } \
- ASTOBJ_UNLOCK(iterator); \
- } while (0)); \
- found; \
- })
-
-/*! \brief Empty a container.
- *
- * \param container A pointer to the container to operate on.
- * \param destructor A destructor function to call on each object.
- *
- * This macro loops through a container removing all the items from it using
- * #ASTOBJ_UNREF(). This does not destroy the container itself, use
- * #ASTOBJ_CONTAINER_DESTROY() for that.
- *
- * \note If any object in the container is only referenced by the container,
- * the destructor will be called for that object once it has been removed.
- */
-#define ASTOBJ_CONTAINER_DESTROYALL(container,destructor) \
- do { \
- typeof((container)->head) iterator; \
- ASTOBJ_CONTAINER_WRLOCK(container); \
- while((iterator = (container)->head)) { \
- (container)->head = (iterator)->next[0]; \
- ASTOBJ_UNREF(iterator,destructor); \
- } \
- ASTOBJ_CONTAINER_UNLOCK(container); \
- } while(0)
-
-/*! \brief Remove an object from a container.
- *
- * \param container A pointer to the container to operate on.
- * \param obj A pointer to the object to remove.
- *
- * This macro iterates through a container and removes the specfied object if
- * it exists in the container.
- *
- * \note This macro does not destroy any objects, it simply unlinks
- * them from the list. No destructors are called.
- *
- * \return The container's reference to the removed object or NULL if no
- * matching object was found.
- */
-#define ASTOBJ_CONTAINER_UNLINK(container,obj) \
- ({ \
- typeof((container)->head) found = NULL; \
- typeof((container)->head) prev = NULL; \
- ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \
- if (iterator == obj) { \
- found = iterator; \
- found->next[0] = NULL; \
- ASTOBJ_CONTAINER_WRLOCK(container); \
- if (prev) \
- prev->next[0] = next; \
- else \
- (container)->head = next; \
- ASTOBJ_CONTAINER_UNLOCK(container); \
- } \
- prev = iterator; \
- } while (0)); \
- found; \
- })
-
-/*! \brief Find and remove an object from a container.
- *
- * \param container A pointer to the container to operate on.
- * \param namestr The name of the object to remove.
- *
- * This macro iterates through a container and removes the first object with
- * the specfied name from the container.
- *
- * \note This macro does not destroy any objects, it simply unlinks
- * them. No destructors are called.
- *
- * \return The container's reference to the removed object or NULL if no
- * matching object was found.
- */
-#define ASTOBJ_CONTAINER_FIND_UNLINK(container,namestr) \
- ({ \
- typeof((container)->head) found = NULL; \
- typeof((container)->head) prev = NULL; \
- ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \
- if (!(strcasecmp(iterator->name, (namestr)))) { \
- found = iterator; \
- found->next[0] = NULL; \
- ASTOBJ_CONTAINER_WRLOCK(container); \
- if (prev) \
- prev->next[0] = next; \
- else \
- (container)->head = next; \
- ASTOBJ_CONTAINER_UNLOCK(container); \
- } \
- prev = iterator; \
- } while (0)); \
- found; \
- })
-
-/*! \brief Find and remove an object in a container.
- *
- * \param container A pointer to the container to search.
- * \param data The data to search for.
- * \param field The field/member of the container's objects to search.
- * \param hashfunc The hash function to use, currently not implemented.
- * \param hashoffset The hash offset to use, currently not implemented.
- * \param comparefunc The function used to compare the field and data values.
- *
- * This macro iterates through a container passing the specified field and data
- * elements to the specified comparefunc. The function should return 0 when a match is found.
- * If a match is found it is removed from the list.
- *
- * \note This macro does not destroy any objects, it simply unlinks
- * them. No destructors are called.
- *
- * \return The container's reference to the removed object or NULL if no match
- * was found.
- */
-#define ASTOBJ_CONTAINER_FIND_UNLINK_FULL(container,data,field,hashfunc,hashoffset,comparefunc) \
- ({ \
- typeof((container)->head) found = NULL; \
- typeof((container)->head) prev = NULL; \
- ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \
- ASTOBJ_RDLOCK(iterator); \
- if (!(comparefunc(iterator->field, (data)))) { \
- found = iterator; \
- found->next[0] = NULL; \
- ASTOBJ_CONTAINER_WRLOCK(container); \
- if (prev) \
- prev->next[0] = next; \
- else \
- (container)->head = next; \
- ASTOBJ_CONTAINER_UNLOCK(container); \
- } \
- ASTOBJ_UNLOCK(iterator); \
- prev = iterator; \
- } while (0)); \
- found; \
- })
-
-/*! \brief Prune marked objects from a container.
- *
- * \param container A pointer to the container to prune.
- * \param destructor A destructor function to call on each marked object.
- *
- * This macro iterates through the specfied container and prunes any marked
- * objects executing the specfied destructor if necessary.
- */
-#define ASTOBJ_CONTAINER_PRUNE_MARKED(container,destructor) \
- do { \
- typeof((container)->head) prev = NULL; \
- ASTOBJ_CONTAINER_TRAVERSE(container, 1, do { \
- ASTOBJ_RDLOCK(iterator); \
- if (iterator->objflags & ASTOBJ_FLAG_MARKED) { \
- ASTOBJ_CONTAINER_WRLOCK(container); \
- if (prev) \
- prev->next[0] = next; \
- else \
- (container)->head = next; \
- ASTOBJ_CONTAINER_UNLOCK(container); \
- ASTOBJ_UNLOCK(iterator); \
- ASTOBJ_UNREF(iterator,destructor); \
- continue; \
- } \
- ASTOBJ_UNLOCK(iterator); \
- prev = iterator; \
- } while (0)); \
- } while(0)
-
-/*! \brief Add an object to a container.
- *
- * \param container A pointer to the container to operate on.
- * \param newobj A pointer to the object to be added.
- * \param data Currently unused.
- * \param field Currently unused.
- * \param hashfunc Currently unused.
- * \param hashoffset Currently unused.
- * \param comparefunc Currently unused.
- *
- * Currently this function adds an object to the head of the list. One day it
- * will support adding objects atthe position specified using the various
- * options this macro offers.
- */
-#define ASTOBJ_CONTAINER_LINK_FULL(container,newobj,data,field,hashfunc,hashoffset,comparefunc) \
- do { \
- ASTOBJ_CONTAINER_WRLOCK(container); \
- (newobj)->next[0] = (container)->head; \
- (container)->head = ASTOBJ_REF(newobj); \
- ASTOBJ_CONTAINER_UNLOCK(container); \
- } while(0)
-
-#endif /* List model */
-
-/* Common to hash and linked list models */
-
-/*! \brief Create a container for ASTOBJs (without locking support).
- *
- * \param type The type of objects the container will hold.
- *
- * This macro is used to create a container for ASTOBJs without locking
- * support.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_struct_nolock_container {
- * ASTOBJ_CONTAINER_COMPONENTS_NOLOCK(struct sample_struct);
- * };
- * \endcode
- */
-#define ASTOBJ_CONTAINER_COMPONENTS_NOLOCK(type) \
- ASTOBJ_CONTAINER_COMPONENTS_NOLOCK_FULL(type,1,ASTOBJ_DEFAULT_BUCKETS)
-
-
-/*! \brief Create a container for ASTOBJs (with locking support).
- *
- * \param type The type of objects the container will hold.
- *
- * This macro is used to create a container for ASTOBJs with locking support.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_struct_container {
- * ASTOBJ_CONTAINER_COMPONENTS(struct sample_struct);
- * };
- * \endcode
- */
-#define ASTOBJ_CONTAINER_COMPONENTS(type) \
- ast_mutex_t _lock; \
- ASTOBJ_CONTAINER_COMPONENTS_NOLOCK(type)
-
-/*! \brief Initialize a container.
- *
- * \param container A pointer to the container to initialize.
- *
- * This macro initializes a container. It should only be used on containers
- * that support locking.
- *
- * <b>Sample Usage:</b>
- * \code
- * struct sample_struct_container {
- * ASTOBJ_CONTAINER_COMPONENTS(struct sample_struct);
- * } container;
- *
- * int func()
- * {
- * ASTOBJ_CONTAINER_INIT(&container);
- * }
- * \endcode
- */
-#define ASTOBJ_CONTAINER_INIT(container) \
- ASTOBJ_CONTAINER_INIT_FULL(container,1,ASTOBJ_DEFAULT_BUCKETS)
-
-/*! \brief Destroy a container.
- *
- * \param container A pointer to the container to destory.
- *
- * This macro frees up resources used by a container. It does not operate on
- * the objects in the container. To unlink the objects from the container use
- * #ASTOBJ_CONTAINER_DESTROYALL().
- *
- * \note This macro should only be used on containers with locking support.
- */
-#define ASTOBJ_CONTAINER_DESTROY(container) \
- ASTOBJ_CONTAINER_DESTROY_FULL(container,1,ASTOBJ_DEFAULT_BUCKETS)
-
-/*! \brief Add an object to a container.
- *
- * \param container A pointer to the container to operate on.
- * \param newobj A pointer to the object to be added.
- *
- * Currently this macro adds an object to the head of a container. One day it
- * should add an object in alphabetical order.
- */
-#define ASTOBJ_CONTAINER_LINK(container,newobj) \
- ASTOBJ_CONTAINER_LINK_FULL(container,newobj,(newobj)->name,name,ASTOBJ_DEFAULT_HASH,0,strcasecmp)
-
-/*! \brief Mark all the objects in a container.
- * \param container A pointer to the container to operate on.
- */
-#define ASTOBJ_CONTAINER_MARKALL(container) \
- ASTOBJ_CONTAINER_TRAVERSE(container, 1, ASTOBJ_MARK(iterator))
-
-/*! \brief Unmark all the objects in a container.
- * \param container A pointer to the container to operate on.
- */
-#define ASTOBJ_CONTAINER_UNMARKALL(container) \
- ASTOBJ_CONTAINER_TRAVERSE(container, 1, ASTOBJ_UNMARK(iterator))
-
-/*! \brief Dump information about an object into a string.
- *
- * \param s A pointer to the string buffer to use.
- * \param slen The length of s.
- * \param obj A pointer to the object to dump.
- *
- * This macro dumps a text representation of the name, objectflags, and
- * refcount fields of an object to the specfied string buffer.
- */
-#define ASTOBJ_DUMP(s,slen,obj) \
- snprintf((s),(slen),"name: %s\nobjflags: %d\nrefcount: %d\n\n", (obj)->name, (obj)->objflags, (obj)->refcount);
-
-/*! \brief Dump information about all the objects in a container to a file descriptor.
- *
- * \param fd The file descriptor to write to.
- * \param s A string buffer, same as #ASTOBJ_DUMP().
- * \param slen The length of s, same as #ASTOBJ_DUMP().
- * \param container A pointer to the container to dump.
- *
- * This macro dumps a text representation of the name, objectflags, and
- * refcount fields of all the objects in a container to the specified file
- * descriptor.
- */
-#define ASTOBJ_CONTAINER_DUMP(fd,s,slen,container) \
- ASTOBJ_CONTAINER_TRAVERSE(container, 1, do { ASTOBJ_DUMP(s,slen,iterator); ast_cli(fd, s); } while(0))
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_ASTOBJ_H */
diff --git a/1.2-netsec/include/asterisk/astosp.h b/1.2-netsec/include/asterisk/astosp.h
deleted file mode 100644
index ee809bbc2..000000000
--- a/1.2-netsec/include/asterisk/astosp.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief OSP support (Open Settlement Protocol)
- */
-
-#ifndef _ASTERISK_OSP_H
-#define _ASTERISK_OSP_H
-
-#include "asterisk/channel.h"
-#include <netinet/in.h>
-#include <time.h>
-
-struct ast_osp_result {
- int handle;
- int numresults;
- char tech[20];
- char dest[256];
- char token[4096];
-};
-
-/* Note: Channel will be auto-serviced if specified. Returns -1 on hangup,
- 0 if nothing found, or 1 if something is found */
-int ast_osp_lookup(struct ast_channel *chan, char *provider, char *extension, char *callerid, struct ast_osp_result *result);
-
-int ast_osp_next(struct ast_osp_result *result, int cause);
-
-int ast_osp_terminate(int handle, int cause, time_t start, time_t duration);
-
-int ast_osp_validate(char *provider, char *token, int *handle, unsigned int *timeout, char *callerid, struct in_addr addr, char *extension);
-
-#endif /* _ASTERISK_OSP_H */
diff --git a/1.2-netsec/include/asterisk/callerid.h b/1.2-netsec/include/asterisk/callerid.h
deleted file mode 100644
index 45ff8b057..000000000
--- a/1.2-netsec/include/asterisk/callerid.h
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief CallerID (and other GR30) management and generation
- * Includes code and algorithms from the Zapata library.
- * Caller ID names are currently 8 bit characters, propably
- * ISO8859-1, depending on what your channel drivers handle.
- * \note Asterisk does not currently support SIP utf8 caller ID names or caller ID's.
- *
- * \par See also
- * \arg \ref callerid.c
- * \arg \ref Def_CallerPres
- */
-
-#ifndef _ASTERISK_CALLERID_H
-#define _ASTERISK_CALLERID_H
-
-#define MAX_CALLERID_SIZE 32000
-
-#define CID_PRIVATE_NAME (1 << 0)
-#define CID_PRIVATE_NUMBER (1 << 1)
-#define CID_UNKNOWN_NAME (1 << 2)
-#define CID_UNKNOWN_NUMBER (1 << 3)
-
-#define CID_SIG_BELL 1
-#define CID_SIG_V23 2
-#define CID_SIG_DTMF 3
-
-#define CID_START_RING 1
-#define CID_START_POLARITY 2
-
-
-#define AST_LIN2X(a) ((codec == AST_FORMAT_ALAW) ? (AST_LIN2A(a)) : (AST_LIN2MU(a)))
-#define AST_XLAW(a) ((codec == AST_FORMAT_ALAW) ? (AST_ALAW(a)) : (AST_MULAW(a)))
-
-
-struct callerid_state;
-typedef struct callerid_state CIDSTATE;
-
-/*! \brief CallerID Initialization
- * \par
- * Initializes the callerid system. Mostly stuff for inverse FFT
- */
-extern void callerid_init(void);
-
-/*! \brief Generates a CallerID FSK stream in ulaw format suitable for transmission.
- * \param buf Buffer to use. If "buf" is supplied, it will use that buffer instead of allocating its own. "buf" must be at least 32000 bytes in size of you want to be sure you don't have an overrun.
- * \param number Use NULL for no number or "P" for "private"
- * \param name name to be used
- * \param flags passed flags
- * \param callwaiting callwaiting flag
- * \param codec -- either AST_FORMAT_ULAW or AST_FORMAT_ALAW
- * This function creates a stream of callerid (a callerid spill) data in ulaw format.
- * \return It returns the size
- * (in bytes) of the data (if it returns a size of 0, there is probably an error)
-*/
-extern int callerid_generate(unsigned char *buf, char *number, char *name, int flags, int callwaiting, int codec);
-
-/*! \brief Create a callerID state machine
- * \param cid_signalling Type of signalling in use
- *
- * This function returns a malloc'd instance of the callerid_state data structure.
- * \return Returns a pointer to a malloc'd callerid_state structure, or NULL on error.
- */
-extern struct callerid_state *callerid_new(int cid_signalling);
-
-/*! \brief Read samples into the state machine.
- * \param cid Which state machine to act upon
- * \param ubuf containing your samples
- * \param samples number of samples contained within the buffer.
- * \param codec which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW)
- *
- * Send received audio to the Caller*ID demodulator.
- * \return Returns -1 on error, 0 for "needs more samples",
- * and 1 if the CallerID spill reception is complete.
- */
-extern int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int samples, int codec);
-
-/*! \brief Extract info out of callerID state machine. Flags are listed above
- * \param cid Callerid state machine to act upon
- * \param number Pass the address of a pointer-to-char (will contain the phone number)
- * \param name Pass the address of a pointer-to-char (will contain the name)
- * \param flags Pass the address of an int variable(will contain the various callerid flags)
- *
- * This function extracts a callerid string out of a callerid_state state machine.
- * If no number is found, *number will be set to NULL. Likewise for the name.
- * Flags can contain any of the following:
- *
- * \return Returns nothing.
- */
-void callerid_get(struct callerid_state *cid, char **number, char **name, int *flags);
-
-/*! Get and parse DTMF-based callerid */
-/*!
- * \param cidstring The actual transmitted string.
- * \param number The cid number is returned here.
- * \param flags The cid flags are returned here.
- * This function parses DTMF callerid.
- */
-void callerid_get_dtmf(char *cidstring, char *number, int *flags);
-
-/*! \brief Free a callerID state
- * \param cid This is the callerid_state state machine to free
- * This function frees callerid_state cid.
- */
-extern void callerid_free(struct callerid_state *cid);
-
-/*! \brief Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format)
- * \param buf buffer for output samples. See callerid_generate() for details regarding buffer.
- * \param name Caller-ID Name
- * \param number Caller-ID Number
- * \param codec Asterisk codec (either AST_FORMAT_ALAW or AST_FORMAT_ULAW)
- *
- * Acts like callerid_generate except uses an asterisk format callerid string.
- */
-extern int ast_callerid_generate(unsigned char *buf, char *name, char *number, int codec);
-
-/*! \brief Generate message waiting indicator (stutter tone) */
-extern int vmwi_generate(unsigned char *buf, int active, int mdmf, int codec);
-
-/*! \brief Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm)
- * See ast_callerid_generate() for other details
- */
-extern int ast_callerid_callwaiting_generate(unsigned char *buf, char *name, char *number, int codec);
-
-/*! \brief Destructively parse inbuf into name and location (or number)
- * Parses callerid stream from inbuf and changes into useable form, outputed in name and location.
- * \param instr buffer of callerid stream (in audio form) to be parsed. Warning, data in buffer is changed.
- * \param name address of a pointer-to-char for the name value of the stream.
- * \param location address of a pointer-to-char for the phone number value of the stream.
- * \return Returns 0 on success, -1 on failure.
- */
-extern int ast_callerid_parse(char *instr, char **name, char **location);
-
-/*! Generate a CAS (CPE Alert Signal) tone for 'n' samples */
-/*!
- * \param outbuf Allocated buffer for data. Must be at least 2400 bytes unless no SAS is desired
- * \param sas Non-zero if CAS should be preceeded by SAS
- * \param len How many samples to generate.
- * \param codec Which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW)
- * \return Returns -1 on error (if len is less than 2400), 0 on success.
- */
-extern int ast_gen_cas(unsigned char *outbuf, int sas, int len, int codec);
-
-/*! \brief Shrink a phone number in place to just digits (more accurately it just removes ()'s, .'s, and -'s... */
-/*!
- * \param n The number to be stripped/shrunk
- * \return Returns nothing important
- */
-extern void ast_shrink_phone_number(char *n);
-
-/*! \brief Check if a string consists only of digits.
- \param n number to be checked.
- \return Returns 0 if n is a number, 1 if it's not.
- */
-extern int ast_isphonenumber(char *n);
-
-extern int ast_callerid_split(const char *src, char *name, int namelen, char *num, int numlen);
-
-extern char *ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown);
-
-/*
- * Caller*ID and other GR-30 compatible generation
- * routines (used by ADSI for example)
- */
-
-extern float cid_dr[4];
-extern float cid_di[4];
-extern float clidsb;
-
-static inline float callerid_getcarrier(float *cr, float *ci, int bit)
-{
- /* Move along. There's nothing to see here... */
- float t;
- t = *cr * cid_dr[bit] - *ci * cid_di[bit];
- *ci = *cr * cid_di[bit] + *ci * cid_dr[bit];
- *cr = t;
-
- t = 2.0 - (*cr * *cr + *ci * *ci);
- *cr *= t;
- *ci *= t;
- return *cr;
-}
-
-#define PUT_BYTE(a) do { \
- *(buf++) = (a); \
- bytes++; \
-} while(0)
-
-#define PUT_AUDIO_SAMPLE(y) do { \
- int index = (short)(rint(8192.0 * (y))); \
- *(buf++) = AST_LIN2X(index); \
- bytes++; \
-} while(0)
-
-#define PUT_CLID_MARKMS do { \
- int x; \
- for (x=0;x<8;x++) \
- PUT_AUDIO_SAMPLE(callerid_getcarrier(&cr, &ci, 1)); \
-} while(0)
-
-#define PUT_CLID_BAUD(bit) do { \
- while(scont < clidsb) { \
- PUT_AUDIO_SAMPLE(callerid_getcarrier(&cr, &ci, bit)); \
- scont += 1.0; \
- } \
- scont -= clidsb; \
-} while(0)
-
-
-#define PUT_CLID(byte) do { \
- int z; \
- unsigned char b = (byte); \
- PUT_CLID_BAUD(0); /* Start bit */ \
- for (z=0;z<8;z++) { \
- PUT_CLID_BAUD(b & 1); \
- b >>= 1; \
- } \
- PUT_CLID_BAUD(1); /* Stop bit */ \
-} while(0);
-
-/* Various defines and bits for handling PRI- and SS7-type restriction */
-
-#define AST_PRES_NUMBER_TYPE 0x03
-#define AST_PRES_USER_NUMBER_UNSCREENED 0x00
-#define AST_PRES_USER_NUMBER_PASSED_SCREEN 0x01
-#define AST_PRES_USER_NUMBER_FAILED_SCREEN 0x02
-#define AST_PRES_NETWORK_NUMBER 0x03
-
-#define AST_PRES_RESTRICTION 0x60
-#define AST_PRES_ALLOWED 0x00
-#define AST_PRES_RESTRICTED 0x20
-#define AST_PRES_UNAVAILABLE 0x40
-#define AST_PRES_RESERVED 0x60
-
-#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED \
- AST_PRES_USER_NUMBER_UNSCREENED + AST_PRES_ALLOWED
-
-#define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN \
- AST_PRES_USER_NUMBER_PASSED_SCREEN + AST_PRES_ALLOWED
-
-#define AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN \
- AST_PRES_USER_NUMBER_FAILED_SCREEN + AST_PRES_ALLOWED
-
-#define AST_PRES_ALLOWED_NETWORK_NUMBER \
- AST_PRES_NETWORK_NUMBER + AST_PRES_ALLOWED
-
-#define AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED \
- AST_PRES_USER_NUMBER_UNSCREENED + AST_PRES_RESTRICTED
-
-#define AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN \
- AST_PRES_USER_NUMBER_PASSED_SCREEN + AST_PRES_RESTRICTED
-
-#define AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN \
- AST_PRES_USER_NUMBER_FAILED_SCREEN + AST_PRES_RESTRICTED
-
-#define AST_PRES_PROHIB_NETWORK_NUMBER \
- AST_PRES_NETWORK_NUMBER + AST_PRES_RESTRICTED
-
-#define AST_PRES_NUMBER_NOT_AVAILABLE \
- AST_PRES_NETWORK_NUMBER + AST_PRES_UNAVAILABLE
-
-int ast_parse_caller_presentation(const char *data);
-const char *ast_describe_caller_presentation(int data);
-
-/*! \page Def_CallerPres Caller ID Presentation
-
- Caller ID presentation values are used to set properties to a
- caller ID in PSTN networks, and as RPID value in SIP transactions.
-
- The following values are available to use:
- \arg \b Defined value, text string in config file, explanation
- .
-
- \arg \b AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, "allowed_not_screened", Presentation Allowed, Not Screened,
- \arg \b AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, "allowed_passed_screen", Presentation Allowed, Passed Screen,
- \arg \b AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, "allowed_failed_screen", Presentation Allowed, Failed Screen,
- \arg \b AST_PRES_ALLOWED_NETWORK_NUMBER, "allowed", Presentation Allowed, Network Number,
- \arg \b AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, "prohib_not_screened", Presentation Prohibited, Not Screened,
- \arg \b AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, "prohib_passed_screen", Presentation Prohibited, Passed Screen,
- \arg \b AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, "prohib_failed_screen", Presentation Prohibited, Failed Screen,
- \arg \b AST_PRES_PROHIB_NETWORK_NUMBER, "prohib", Presentation Prohibited, Network Number,
-
- \par References
- \arg \ref callerid.h Definitions
- \arg \ref callerid.c Functions
-*/
-
-
-#endif /* _ASTERISK_CALLERID_H */
diff --git a/1.2-netsec/include/asterisk/causes.h b/1.2-netsec/include/asterisk/causes.h
deleted file mode 100644
index fc27c7970..000000000
--- a/1.2-netsec/include/asterisk/causes.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Martin Pycko <martinp@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Internal Asterisk hangup causes
- */
-
-#ifndef _ASTERISK_CAUSES_H
-#define _ASTERISK_CAUSES_H
-
-/* Causes for disconnection (from Q.931) */
-#define AST_CAUSE_UNALLOCATED 1
-#define AST_CAUSE_NO_ROUTE_TRANSIT_NET 2
-#define AST_CAUSE_NO_ROUTE_DESTINATION 3
-#define AST_CAUSE_CHANNEL_UNACCEPTABLE 6
-#define AST_CAUSE_CALL_AWARDED_DELIVERED 7
-#define AST_CAUSE_NORMAL_CLEARING 16
-#define AST_CAUSE_USER_BUSY 17
-#define AST_CAUSE_NO_USER_RESPONSE 18
-#define AST_CAUSE_NO_ANSWER 19
-#define AST_CAUSE_CALL_REJECTED 21
-#define AST_CAUSE_NUMBER_CHANGED 22
-#define AST_CAUSE_DESTINATION_OUT_OF_ORDER 27
-#define AST_CAUSE_INVALID_NUMBER_FORMAT 28
-#define AST_CAUSE_FACILITY_REJECTED 29
-#define AST_CAUSE_RESPONSE_TO_STATUS_ENQUIRY 30
-#define AST_CAUSE_NORMAL_UNSPECIFIED 31
-#define AST_CAUSE_NORMAL_CIRCUIT_CONGESTION 34
-#define AST_CAUSE_NETWORK_OUT_OF_ORDER 38
-#define AST_CAUSE_NORMAL_TEMPORARY_FAILURE 41
-#define AST_CAUSE_SWITCH_CONGESTION 42
-#define AST_CAUSE_ACCESS_INFO_DISCARDED 43
-#define AST_CAUSE_REQUESTED_CHAN_UNAVAIL 44
-#define AST_CAUSE_PRE_EMPTED 45
-#define AST_CAUSE_FACILITY_NOT_SUBSCRIBED 50
-#define AST_CAUSE_OUTGOING_CALL_BARRED 52
-#define AST_CAUSE_INCOMING_CALL_BARRED 54
-#define AST_CAUSE_BEARERCAPABILITY_NOTAUTH 57
-#define AST_CAUSE_BEARERCAPABILITY_NOTAVAIL 58
-#define AST_CAUSE_BEARERCAPABILITY_NOTIMPL 65
-#define AST_CAUSE_CHAN_NOT_IMPLEMENTED 66
-#define AST_CAUSE_FACILITY_NOT_IMPLEMENTED 69
-#define AST_CAUSE_INVALID_CALL_REFERENCE 81
-#define AST_CAUSE_INCOMPATIBLE_DESTINATION 88
-#define AST_CAUSE_INVALID_MSG_UNSPECIFIED 95
-#define AST_CAUSE_MANDATORY_IE_MISSING 96
-#define AST_CAUSE_MESSAGE_TYPE_NONEXIST 97
-#define AST_CAUSE_WRONG_MESSAGE 98
-#define AST_CAUSE_IE_NONEXIST 99
-#define AST_CAUSE_INVALID_IE_CONTENTS 100
-#define AST_CAUSE_WRONG_CALL_STATE 101
-#define AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE 102
-#define AST_CAUSE_MANDATORY_IE_LENGTH_ERROR 103
-#define AST_CAUSE_PROTOCOL_ERROR 111
-#define AST_CAUSE_INTERWORKING 127
-
-/* Special Asterisk aliases */
-#define AST_CAUSE_BUSY AST_CAUSE_USER_BUSY
-#define AST_CAUSE_FAILURE AST_CAUSE_NETWORK_OUT_OF_ORDER
-#define AST_CAUSE_NORMAL AST_CAUSE_NORMAL_CLEARING
-#define AST_CAUSE_NOANSWER AST_CAUSE_NO_ANSWER
-#define AST_CAUSE_CONGESTION AST_CAUSE_NORMAL_CIRCUIT_CONGESTION
-#define AST_CAUSE_UNREGISTERED AST_CAUSE_NO_ROUTE_DESTINATION
-#define AST_CAUSE_NOTDEFINED 0
-#define AST_CAUSE_NOSUCHDRIVER AST_CAUSE_CHAN_NOT_IMPLEMENTED
-
-#endif /* _ASTERISK_CAUSES_H */
diff --git a/1.2-netsec/include/asterisk/cdr.h b/1.2-netsec/include/asterisk/cdr.h
deleted file mode 100644
index c43882946..000000000
--- a/1.2-netsec/include/asterisk/cdr.h
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Call Detail Record API
- */
-
-#ifndef _ASTERISK_CDR_H
-#define _ASTERISK_CDR_H
-
-#include <sys/time.h>
-#define AST_CDR_FLAG_KEEP_VARS (1 << 0)
-#define AST_CDR_FLAG_POSTED (1 << 1)
-#define AST_CDR_FLAG_LOCKED (1 << 2)
-#define AST_CDR_FLAG_CHILD (1 << 3)
-#define AST_CDR_FLAG_POST_DISABLED (1 << 4)
-
-#define AST_CDR_NOANSWER (1 << 0)
-#define AST_CDR_BUSY (1 << 1)
-#define AST_CDR_ANSWERED (1 << 2)
-#define AST_CDR_FAILED (1 << 3)
-
-/*! AMA Flags */
-#define AST_CDR_OMIT (1)
-#define AST_CDR_BILLING (2)
-#define AST_CDR_DOCUMENTATION (3)
-
-#define AST_MAX_USER_FIELD 256
-#define AST_MAX_ACCOUNT_CODE 20
-
-/* Include channel.h after relevant declarations it will need */
-#include "asterisk/channel.h"
-#include "asterisk/utils.h"
-
-struct ast_channel;
-
-/*! Responsible for call detail data */
-struct ast_cdr {
- /*! Caller*ID with text */
- char clid[AST_MAX_EXTENSION];
- /*! Caller*ID number */
- char src[AST_MAX_EXTENSION];
- /*! Destination extension */
- char dst[AST_MAX_EXTENSION];
- /*! Destination context */
- char dcontext[AST_MAX_EXTENSION];
-
- char channel[AST_MAX_EXTENSION];
- /*! Destination channel if appropriate */
- char dstchannel[AST_MAX_EXTENSION];
- /*! Last application if appropriate */
- char lastapp[AST_MAX_EXTENSION];
- /*! Last application data */
- char lastdata[AST_MAX_EXTENSION];
-
- struct timeval start;
-
- struct timeval answer;
-
- struct timeval end;
- /*! Total time in system, in seconds */
- long int duration;
- /*! Total time call is up, in seconds */
- long int billsec;
- /*! What happened to the call */
- long int disposition;
- /*! What flags to use */
- long int amaflags;
- /*! What account number to use */
- char accountcode[AST_MAX_ACCOUNT_CODE];
- /*! flags */
- unsigned int flags;
- /* Unique Channel Identifier */
- char uniqueid[32];
- /* User field */
- char userfield[AST_MAX_USER_FIELD];
-
- /* A linked list for variables */
- struct varshead varshead;
-
- struct ast_cdr *next;
-};
-
-extern void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur);
-extern int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur);
-extern int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur);
-extern void ast_cdr_free_vars(struct ast_cdr *cdr, int recur);
-extern int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
-
-typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
-
-/*! \brief Allocate a CDR record
- * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
- */
-extern struct ast_cdr *ast_cdr_alloc(void);
-
-/*! \brief Duplicate a record
- * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
- */
-extern struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr);
-
-/*! \brief Free a CDR record
- * \param cdr ast_cdr structure to free
- * Returns nothing important
- */
-extern void ast_cdr_free(struct ast_cdr *cdr);
-
-/*! \brief Initialize based on a channel
- * \param cdr Call Detail Record to use for channel
- * \param chan Channel to bind CDR with
- * Initializes a CDR and associates it with a particular channel
- * Return is negligible. (returns 0 by default)
- */
-extern int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
-
-/*! Initialize based on a channel */
-/*!
- * \param cdr Call Detail Record to use for channel
- * \param chan Channel to bind CDR with
- * Initializes a CDR and associates it with a particular channel
- * Return is negligible. (returns 0 by default)
- */
-extern int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *chan);
-
-/*! Register a CDR handling engine */
-/*!
- * \param name name associated with the particular CDR handler
- * \param desc description of the CDR handler
- * \param be function pointer to a CDR handler
- * Used to register a Call Detail Record handler.
- * Returns -1 on error, 0 on success.
- */
-extern int ast_cdr_register(char *name, char *desc, ast_cdrbe be);
-
-/*! Unregister a CDR handling engine */
-/*!
- * \param name name of CDR handler to unregister
- * Unregisters a CDR by it's name
- */
-extern void ast_cdr_unregister(char *name);
-
-/*! Start a call */
-/*!
- * \param cdr the cdr you wish to associate with the call
- * Starts all CDR stuff necessary for monitoring a call
- * Returns nothing important
- */
-extern void ast_cdr_start(struct ast_cdr *cdr);
-
-/*! Answer a call */
-/*!
- * \param cdr the cdr you wish to associate with the call
- * Starts all CDR stuff necessary for doing CDR when answering a call
- */
-extern void ast_cdr_answer(struct ast_cdr *cdr);
-
-/*! Busy a call */
-/*!
- * \param cdr the cdr you wish to associate with the call
- * Returns nothing important
- */
-extern void ast_cdr_busy(struct ast_cdr *cdr);
-
-/*! Fail a call */
-/*!
- * \param cdr the cdr you wish to associate with the call
- * Returns nothing important
- */
-extern void ast_cdr_failed(struct ast_cdr *cdr);
-
-/*! Save the result of the call based on the AST_CAUSE_* */
-/*!
- * \param cdr the cdr you wish to associate with the call
- * Returns nothing important
- * \param cause the AST_CAUSE_*
- */
-extern int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
-
-/*! End a call */
-/*!
- * \param cdr the cdr you have associated the call with
- * Registers the end of call time in the cdr structure.
- * Returns nothing important
- */
-extern void ast_cdr_end(struct ast_cdr *cdr);
-
-/*! Detaches the detail record for posting (and freeing) either now or at a
- * later time in bulk with other records during batch mode operation */
-/*!
- * \param cdr Which CDR to detach from the channel thread
- * Prevents the channel thread from blocking on the CDR handling
- * Returns nothing
- */
-extern void ast_cdr_detach(struct ast_cdr *cdr);
-
-/*! Spawns (possibly) a new thread to submit a batch of CDRs to the backend engines */
-/*!
- * \param shutdown Whether or not we are shutting down
- * Blocks the asterisk shutdown procedures until the CDR data is submitted.
- * Returns nothing
- */
-extern void ast_cdr_submit_batch(int shutdown);
-
-/*! Set the destination channel, if there was one */
-/*!
- * \param cdr Which cdr it's applied to
- * \param chan Channel to which dest will be
- * Sets the destination channel the CDR is applied to
- * Returns nothing
- */
-extern void ast_cdr_setdestchan(struct ast_cdr *cdr, char *chan);
-
-/*! Set the last executed application */
-/*!
- * \param cdr which cdr to act upon
- * \param app the name of the app you wish to change it to
- * \param data the data you want in the data field of app you set it to
- * Changes the value of the last executed app
- * Returns nothing
- */
-extern void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data);
-
-/*! Convert a string to a detail record AMA flag */
-/*!
- * \param flag string form of flag
- * Converts the string form of the flag to the binary form.
- * Returns the binary form of the flag
- */
-extern int ast_cdr_amaflags2int(const char *flag);
-
-/*! Disposition to a string */
-/*!
- * \param disposition input binary form
- * Converts the binary form of a disposition to string form.
- * Returns a pointer to the string form
- */
-extern char *ast_cdr_disp2str(int disposition);
-
-/*! Reset the detail record, optionally posting it first */
-/*!
- * \param cdr which cdr to act upon
- * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
- * |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
- */
-extern void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags);
-
-/*! Flags to a string */
-/*!
- * \param flags binary flag
- * Converts binary flags to string flags
- * Returns string with flag name
- */
-extern char *ast_cdr_flags2str(int flags);
-
-extern int ast_cdr_setaccount(struct ast_channel *chan, const char *account);
-extern int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags);
-
-
-extern int ast_cdr_setuserfield(struct ast_channel *chan, const char *userfield);
-extern int ast_cdr_appenduserfield(struct ast_channel *chan, const char *userfield);
-
-
-/* Update CDR on a channel */
-extern int ast_cdr_update(struct ast_channel *chan);
-
-
-extern int ast_default_amaflags;
-
-extern char ast_default_accountcode[AST_MAX_ACCOUNT_CODE];
-
-extern struct ast_cdr *ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr);
-
-/*! Reload the configuration file cdr.conf and start/stop CDR scheduling thread */
-extern void ast_cdr_engine_reload(void);
-
-/*! Load the configuration file cdr.conf and possibly start the CDR scheduling thread */
-extern int ast_cdr_engine_init(void);
-
-/*! Submit any remaining CDRs and prepare for shutdown */
-extern void ast_cdr_engine_term(void);
-
-#endif /* _ASTERISK_CDR_H */
diff --git a/1.2-netsec/include/asterisk/channel.h b/1.2-netsec/include/asterisk/channel.h
deleted file mode 100644
index 11fb0a7d0..000000000
--- a/1.2-netsec/include/asterisk/channel.h
+++ /dev/null
@@ -1,1207 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief General Asterisk PBX channel definitions.
- * \par See also:
- * \arg \ref Def_Channel
- * \arg \ref channel_drivers
- */
-
-/*! \page Def_Channel Asterisk Channels
- \par What is a Channel?
- A phone call through Asterisk consists of an incoming
- connection and an outbound connection. Each call comes
- in through a channel driver that supports one technology,
- like SIP, ZAP, IAX2 etc.
- \par
- Each channel driver, technology, has it's own private
- channel or dialog structure, that is technology-dependent.
- Each private structure is "owned" by a generic Asterisk
- channel structure, defined in channel.h and handled by
- channel.c .
- \par Call scenario
- This happens when an incoming call arrives to Asterisk
- -# Call arrives on a channel driver interface
- -# Channel driver creates a PBX channel and starts a
- pbx thread on the channel
- -# The dial plan is executed
- -# At this point at least two things can happen:
- -# The call is answered by Asterisk and
- Asterisk plays a media stream or reads media
- -# The dial plan forces Asterisk to create an outbound
- call somewhere with the dial (see \ref app_dial.c)
- application
-
- .
- \par Bridging channels
- If Asterisk dials out this happens:
- -# Dial creates an outbound PBX channel and asks one of the
- channel drivers to create a call
- -# When the call is answered, Asterisk bridges the media streams
- so the caller on the first channel can speak with the callee
- on the second, outbound channel
- -# In some cases where we have the same technology on both
- channels and compatible codecs, a native bridge is used.
- In a native bridge, the channel driver handles forwarding
- of incoming audio to the outbound stream internally, without
- sending audio frames through the PBX.
- -# In SIP, theres an "external native bridge" where Asterisk
- redirects the endpoint, so audio flows directly between the
- caller's phone and the callee's phone. Signalling stays in
- Asterisk in order to be able to provide a proper CDR record
- for the call.
-
-
- \par Masquerading channels
- In some cases, a channel can masquerade itself into another
- channel. This happens frequently in call transfers, where
- a new channel takes over a channel that is already involved
- in a call. The new channel sneaks in and takes over the bridge
- and the old channel, now a zombie, is hung up.
-
- \par Reference
- \arg channel.c - generic functions
- \arg channel.h - declarations of functions, flags and structures
- \arg \ref channel_drivers - Implemented channel drivers
- \arg \ref Def_Frame Asterisk Multimedia Frames
-
-*/
-
-#ifndef _ASTERISK_CHANNEL_H
-#define _ASTERISK_CHANNEL_H
-
-#include <unistd.h>
-#include <setjmp.h>
-#ifdef POLLCOMPAT
-#include "asterisk/poll-compat.h"
-#else
-#include <sys/poll.h>
-#endif
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/*! Max length of an extension */
-#define AST_MAX_EXTENSION 80
-
-#define AST_MAX_CONTEXT 80
-
-#define AST_CHANNEL_NAME 80
-
-#include "asterisk/compat.h"
-#include "asterisk/frame.h"
-#include "asterisk/sched.h"
-#include "asterisk/chanvars.h"
-#include "asterisk/config.h"
-#include "asterisk/lock.h"
-#include "asterisk/cdr.h"
-#include "asterisk/utils.h"
-#include "asterisk/linkedlists.h"
-
-#define MAX_LANGUAGE 20
-
-#define MAX_MUSICCLASS 20
-
-#define AST_MAX_FDS 8
-
-enum ast_bridge_result {
- AST_BRIDGE_COMPLETE = 0,
- AST_BRIDGE_FAILED = -1,
- AST_BRIDGE_FAILED_NOWARN = -2,
- AST_BRIDGE_RETRY = -3,
-};
-
-typedef unsigned long long ast_group_t;
-
-struct ast_generator {
- void *(*alloc)(struct ast_channel *chan, void *params);
- void (*release)(struct ast_channel *chan, void *data);
- int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
-};
-
-/*! Structure for all kinds of caller ID identifications */
-struct ast_callerid {
- /*! Malloc'd Dialed Number Identifier */
- char *cid_dnid;
- /*! Malloc'd Caller Number */
- char *cid_num;
- /*! Malloc'd Caller Name */
- char *cid_name;
- /*! Malloc'd ANI */
- char *cid_ani;
- /*! Malloc'd RDNIS */
- char *cid_rdnis;
- /*! Callerid presentation/screening */
- int cid_pres;
- /*! Callerid ANI 2 (Info digits) */
- int cid_ani2;
- /*! Callerid Type of Number */
- int cid_ton;
- /*! Callerid Transit Network Select */
- int cid_tns;
-};
-
-/*! Structure to describe a channel "technology", ie a channel driver
- See
- \arg chan_iax2.c - The Inter-Asterisk exchange protocol
- \arg chan_sip.c - The SIP channel driver
- \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
-
- If you develop your own channel driver, this is where you
- tell the PBX at registration of your driver what properties
- this driver supports and where different callbacks are
- implemented.
-*/
-
-
-struct ast_channel_tech {
- const char * const type;
- const char * const description;
-
- /*! Bitmap of formats this channel can handle */
- int capabilities;
-
- /*! Technology Properties */
- int properties;
-
- /*! Requester - to set up call data structures (pvt's) */
- struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause);
-
- /*! Devicestate call back */
- int (* const devicestate)(void *data);
-
- /*! Send a literal DTMF digit */
- int (* const send_digit)(struct ast_channel *chan, char digit);
-
- /*! Call a given phone number (address, etc), but don't
- take longer than timeout seconds to do so. */
- int (* const call)(struct ast_channel *chan, char *addr, int timeout);
-
- /*! Hangup (and possibly destroy) the channel */
- int (* const hangup)(struct ast_channel *chan);
-
- /*! Answer the channel */
- int (* const answer)(struct ast_channel *chan);
-
- /*! Read a frame, in standard format (see frame.h) */
- struct ast_frame * (* const read)(struct ast_channel *chan);
-
- /*! Write a frame, in standard format (see frame.h) */
- int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
-
- /*! Display or transmit text */
- int (* const send_text)(struct ast_channel *chan, const char *text);
-
- /*! Display or send an image */
- int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
-
- /*! Send HTML data */
- int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
-
- /*! Handle an exception, reading a frame */
- struct ast_frame * (* const exception)(struct ast_channel *chan);
-
- /*! Bridge two channels of the same type together */
- enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
- struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
-
- /*! Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
- int (* const indicate)(struct ast_channel *c, int condition);
-
- /*! Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */
- int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
-
- /*! Set a given option */
- int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
-
- /*! Query a given option */
- int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
-
- /*! Blind transfer other side (see app_transfer.c and ast_transfer() */
- int (* const transfer)(struct ast_channel *chan, const char *newdest);
-
- /*! Write a frame, in standard format */
- int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
-
- /*! Find bridged channel */
- struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
-};
-
-struct ast_channel_spy_list;
-
-/*! Main Channel structure associated with a channel.
- * This is the side of it mostly used by the pbx and call management.
- */
-struct ast_channel {
- /*! ASCII unique channel name */
- char name[AST_CHANNEL_NAME];
-
- /*! Technology (point to channel driver) */
- const struct ast_channel_tech *tech;
-
- /*! Private data used by the technology driver */
- void *tech_pvt;
-
- /*! Language requested for voice prompts */
- char language[MAX_LANGUAGE];
- /*! Type of channel */
- const char *type;
- /*! File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1. */
- int fds[AST_MAX_FDS];
-
- /*! Default music class */
- char musicclass[MAX_MUSICCLASS];
- /*! Music State*/
- void *music_state;
- /*! Current generator data if there is any */
- void *generatordata;
- /*! Current active data generator */
- struct ast_generator *generator;
-
- /*! Who are we bridged to, if we're bridged Do not access directly,
- use ast_bridged_channel(chan) */
- struct ast_channel *_bridge;
- /*! Channel that will masquerade as us */
- struct ast_channel *masq;
- /*! Who we are masquerading as */
- struct ast_channel *masqr;
- /*! Call Detail Record Flags */
- int cdrflags;
- /*! Whether or not we have been hung up... Do not set this value
- directly, use ast_softhangup */
- int _softhangup;
- /*! Non-zero, set to actual time when channel is to be hung up */
- time_t whentohangup;
- /*! If anyone is blocking, this is them */
- pthread_t blocker;
- /*! Lock, can be used to lock a channel for some operations */
- ast_mutex_t lock;
- /*! Procedure causing blocking */
- const char *blockproc;
-
- /*! Current application */
- char *appl;
- /*! Data passed to current application */
- char *data;
-
- /*! Which fd had an event detected on */
- int fdno;
- /*! Schedule context */
- struct sched_context *sched;
- /*! For streaming playback, the schedule ID */
- int streamid;
- /*! Stream itself. */
- struct ast_filestream *stream;
- /*! For streaming video playback, the schedule ID */
- int vstreamid;
- /*! Video Stream itself. */
- struct ast_filestream *vstream;
- /*! Original writer format */
- int oldwriteformat;
-
- /*! Timing fd */
- int timingfd;
- int (*timingfunc)(void *data);
- void *timingdata;
-
- /*! State of line -- Don't write directly, use ast_setstate */
- int _state;
- /*! Number of rings so far */
- int rings;
-
- /*! Kinds of data this channel can natively handle */
- int nativeformats;
- /*! Requested read format */
- int readformat;
- /*! Requested write format */
- int writeformat;
-
- struct ast_callerid cid;
-
- /*! Current extension context */
- char context[AST_MAX_CONTEXT];
- /*! Current non-macro context */
- char macrocontext[AST_MAX_CONTEXT];
- /*! Current non-macro extension */
- char macroexten[AST_MAX_EXTENSION];
- /*! Current non-macro priority */
- int macropriority;
- /*! Current extension number */
- char exten[AST_MAX_EXTENSION];
- /* Current extension priority */
- int priority;
- /*! Any/all queued DTMF characters */
- char dtmfq[AST_MAX_EXTENSION];
- /*! DTMF frame */
- struct ast_frame dtmff;
-
- /*! PBX private structure */
- struct ast_pbx *pbx;
- /*! Set BEFORE PBX is started to determine AMA flags */
- int amaflags;
- /*! Account code for billing */
- char accountcode[AST_MAX_ACCOUNT_CODE];
- /*! Call Detail Record */
- struct ast_cdr *cdr;
- /*! Whether or not ADSI is detected on CPE */
- int adsicpe;
- /*! Where to forward to if asked to dial on this interface */
- char call_forward[AST_MAX_EXTENSION];
-
- /*! Tone zone as set in indications.conf */
- struct tone_zone *zone;
-
- /* Channel monitoring */
- struct ast_channel_monitor *monitor;
-
- /*! Track the read/written samples for monitor use */
- unsigned long insmpl;
- unsigned long outsmpl;
-
- /* Frames in/out counters */
- unsigned int fin;
- unsigned int fout;
-
- /* Unique Channel Identifier */
- char uniqueid[32];
-
- /* Why is the channel hanged up */
- int hangupcause;
-
- /* A linked list for variables */
- struct varshead varshead;
-
- unsigned int callgroup;
- unsigned int pickupgroup;
-
- /*! channel flags of AST_FLAG_ type */
- unsigned int flags;
-
- /*! ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
- unsigned short transfercapability;
-
- struct ast_frame *readq;
- int alertpipe[2];
- /*! Write translation path */
- struct ast_trans_pvt *writetrans;
- /*! Read translation path */
- struct ast_trans_pvt *readtrans;
- /*! Raw read format */
- int rawreadformat;
- /*! Raw write format */
- int rawwriteformat;
-
- /*! Chan Spy stuff */
- struct ast_channel_spy_list *spies;
-
- /*! For easy linking */
- struct ast_channel *next;
-};
-
-/* \defgroup chanprop Channel tech properties:
- \brief Channels have this property if they can accept input with jitter; i.e. most VoIP channels */
-/* @{ */
-#define AST_CHAN_TP_WANTSJITTER (1 << 0)
-
-/* This flag has been deprecated by the transfercapbilty data member in struct ast_channel */
-/* #define AST_FLAG_DIGITAL (1 << 0) */ /* if the call is a digital ISDN call */
-#define AST_FLAG_DEFER_DTMF (1 << 1) /*!< if dtmf should be deferred */
-#define AST_FLAG_WRITE_INT (1 << 2) /*!< if write should be interrupt generator */
-#define AST_FLAG_BLOCKING (1 << 3) /*!< if we are blocking */
-#define AST_FLAG_ZOMBIE (1 << 4) /*!< if we are a zombie */
-#define AST_FLAG_EXCEPTION (1 << 5) /*!< if there is a pending exception */
-#define AST_FLAG_MOH (1 << 6) /*!< XXX anthm promises me this will disappear XXX listening to moh */
-#define AST_FLAG_SPYING (1 << 7) /*!< XXX might also go away XXX is spying on someone */
-#define AST_FLAG_NBRIDGE (1 << 8) /*!< is it in a native bridge */
-#define AST_FLAG_IN_AUTOLOOP (1 << 9) /*!< the channel is in an auto-incrementing dialplan processor,
- so when ->priority is set, it will get incremented before
- finding the next priority to run
- */
-/* @} */
-
-#define AST_FEATURE_PLAY_WARNING (1 << 0)
-#define AST_FEATURE_REDIRECT (1 << 1)
-#define AST_FEATURE_DISCONNECT (1 << 2)
-#define AST_FEATURE_ATXFER (1 << 3)
-#define AST_FEATURE_AUTOMON (1 << 4)
-
-#define AST_FEATURE_FLAG_NEEDSDTMF (1 << 0)
-#define AST_FEATURE_FLAG_CALLEE (1 << 1)
-#define AST_FEATURE_FLAG_CALLER (1 << 2)
-
-struct ast_bridge_config {
- struct ast_flags features_caller;
- struct ast_flags features_callee;
- struct timeval start_time;
- long feature_timer;
- long timelimit;
- long play_warning;
- long warning_freq;
- char *warning_sound;
- char *end_sound;
- char *start_sound;
- int firstpass;
- unsigned int flags;
-};
-
-struct chanmon;
-
-#define LOAD_OH(oh) { \
- oh.context = context; \
- oh.exten = exten; \
- oh.priority = priority; \
- oh.cid_num = cid_num; \
- oh.cid_name = cid_name; \
- oh.account = account; \
- oh.vars = vars; \
- oh.parent_channel = NULL; \
-}
-
-struct outgoing_helper {
- const char *context;
- const char *exten;
- int priority;
- const char *cid_num;
- const char *cid_name;
- const char *account;
- struct ast_variable *vars;
- struct ast_channel *parent_channel;
-};
-
-#define AST_CDR_TRANSFER (1 << 0)
-#define AST_CDR_FORWARD (1 << 1)
-#define AST_CDR_CALLWAIT (1 << 2)
-#define AST_CDR_CONFERENCE (1 << 3)
-
-#define AST_ADSI_UNKNOWN (0)
-#define AST_ADSI_AVAILABLE (1)
-#define AST_ADSI_UNAVAILABLE (2)
-#define AST_ADSI_OFFHOOKONLY (3)
-
-#define AST_SOFTHANGUP_DEV (1 << 0) /*!< Soft hangup by device */
-#define AST_SOFTHANGUP_ASYNCGOTO (1 << 1) /*!< Soft hangup for async goto */
-#define AST_SOFTHANGUP_SHUTDOWN (1 << 2)
-#define AST_SOFTHANGUP_TIMEOUT (1 << 3)
-#define AST_SOFTHANGUP_APPUNLOAD (1 << 4)
-#define AST_SOFTHANGUP_EXPLICIT (1 << 5)
-#define AST_SOFTHANGUP_UNBRIDGE (1 << 6)
-
-
-/*! \defgroup ChanState Channel states
-\brief Bits 0-15 of state are reserved for the state (up/down) of the line */
-/*! @{ */
-/*! Channel is down and available */
-#define AST_STATE_DOWN 0
-/*! Channel is down, but reserved */
-#define AST_STATE_RESERVED 1
-/*! Channel is off hook */
-#define AST_STATE_OFFHOOK 2
-/*! Digits (or equivalent) have been dialed */
-#define AST_STATE_DIALING 3
-/*! Line is ringing */
-#define AST_STATE_RING 4
-/*! Remote end is ringing */
-#define AST_STATE_RINGING 5
-/*! Line is up */
-#define AST_STATE_UP 6
-/*! Line is busy */
-#define AST_STATE_BUSY 7
-/*! Digits (or equivalent) have been dialed while offhook */
-#define AST_STATE_DIALING_OFFHOOK 8
-/*! Channel has detected an incoming call and is waiting for ring */
-#define AST_STATE_PRERING 9
-
-/* Bits 16-32 of state are reserved for flags (See \ref ChanState ) */
-/*! Do not transmit voice data */
-#define AST_STATE_MUTE (1 << 16)
-/*! @} */
-
-/*! \brief Change the state of a channel */
-int ast_setstate(struct ast_channel *chan, int state);
-
-/*! \brief Create a channel structure
- \return Returns NULL on failure to allocate.
- \note New channels are
- by default set to the "default" context and
- extension "s"
- */
-struct ast_channel *ast_channel_alloc(int needalertpipe);
-
-/*! \brief Queue an outgoing frame */
-int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
-
-/*! \brief Queue a hangup frame */
-int ast_queue_hangup(struct ast_channel *chan);
-
-/*! \brief Queue a control frame */
-int ast_queue_control(struct ast_channel *chan, int control);
-
-
-/*! \brief Change channel name */
-void ast_change_name(struct ast_channel *chan, char *newname);
-
-/*! \brief Free a channel structure */
-void ast_channel_free(struct ast_channel *);
-
-/*! \brief Requests a channel
- * \param type type of channel to request
- * \param format requested channel format
- * \param data data to pass to the channel requester
- * \param status status
- * Request a channel of a given type, with data as optional information used
- * by the low level module
- * \return Returns an ast_channel on success, NULL on failure.
- */
-struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
-
-/*!
- * \brief Request a channel of a given type, with data as optional information used
- * by the low level module and attempt to place a call on it
- * \param type type of channel to request
- * \param format requested channel format
- * \param data data to pass to the channel requester
- * \param timeout maximum amount of time to wait for an answer
- * \param reason why unsuccessful (if unsuceessful)
- * \param cidnum Caller-ID Number
- * \param cidname Caller-ID Name
- * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
- * to know if the call was answered or not.
- */
-struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname);
-
-struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname, struct outgoing_helper *oh);
-
-/*!\brief Register a channel technology (a new channel driver)
- * Called by a channel module to register the kind of channels it supports.
- * \param tech Structure defining channel technology or "type"
- * \return Returns 0 on success, -1 on failure.
- */
-int ast_channel_register(const struct ast_channel_tech *tech);
-
-/*! \brief Unregister a channel technology
- * \param tech Structure defining channel technology or "type" that was previously registered
- * \return No return value.
- */
-void ast_channel_unregister(const struct ast_channel_tech *tech);
-
-/*! \brief Get a channel technology structure by name
- * \param name name of technology to find
- * \return a pointer to the structure, or NULL if no matching technology found
- */
-const struct ast_channel_tech *ast_get_channel_tech(const char *name);
-
-/*! \brief Hang up a channel
- * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function
- * performs all stream stopping, etc, on the channel that needs to end.
- * chan is no longer valid after this call.
- * \param chan channel to hang up
- * \return Returns 0 on success, -1 on failure.
- */
-int ast_hangup(struct ast_channel *chan);
-
-/*! \brief Softly hangup up a channel
- * \param chan channel to be soft-hung-up
- * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to
- * safely hangup a channel managed by another thread.
- * \param cause Ast hangupcause for hangup
- * \return Returns 0 regardless
- */
-int ast_softhangup(struct ast_channel *chan, int cause);
-
-/*! \brief Softly hangup up a channel (no channel lock)
- * \param chan channel to be soft-hung-up
- * \param cause Ast hangupcause for hangup (see cause.h) */
-int ast_softhangup_nolock(struct ast_channel *chan, int cause);
-
-/*! \brief Check to see if a channel is needing hang up
- * \param chan channel on which to check for hang up
- * This function determines if the channel is being requested to be hung up.
- * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
- */
-int ast_check_hangup(struct ast_channel *chan);
-
-/*! \brief Compare a offset with the settings of when to hang a channel up
- * \param chan channel on which to check for hang up
- * \param offset offset in seconds from current time
- * \return 1, 0, or -1
- * This function compares a offset from current time with the absolute time
- * out on a channel (when to hang up). If the absolute time out on a channel
- * is earlier than current time plus the offset, it returns 1, if the two
- * time values are equal, it return 0, otherwise, it retturn -1.
- */
-int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset);
-
-/*! \brief Set when to hang a channel up
- * \param chan channel on which to check for hang up
- * \param offset offset in seconds from current time of when to hang up
- * This function sets the absolute time out on a channel (when to hang up).
- */
-void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset);
-
-/*! \brief Answer a ringing call
- * \param chan channel to answer
- * This function answers a channel and handles all necessary call
- * setup functions.
- * \return Returns 0 on success, -1 on failure
- */
-int ast_answer(struct ast_channel *chan);
-
-/*! \brief Make a call
- * \param chan which channel to make the call on
- * \param addr destination of the call
- * \param timeout time to wait on for connect
- * Place a call, take no longer than timeout ms.
- \return Returns -1 on failure, 0 on not enough time
- (does not automatically stop ringing), and
- the number of seconds the connect took otherwise.
- */
-int ast_call(struct ast_channel *chan, char *addr, int timeout);
-
-/*! \brief Indicates condition of channel
- * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
- * \param chan channel to change the indication
- * \param condition which condition to indicate on the channel
- * \return Returns 0 on success, -1 on failure
- */
-int ast_indicate(struct ast_channel *chan, int condition);
-
-/* Misc stuff ------------------------------------------------ */
-
-/*! \brief Wait for input on a channel
- * \param chan channel to wait on
- * \param ms length of time to wait on the channel
- * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
- \return Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
-int ast_waitfor(struct ast_channel *chan, int ms);
-
-/*! \brief Wait for a specied amount of time, looking for hangups
- * \param chan channel to wait for
- * \param ms length of time in milliseconds to sleep
- * Waits for a specified amount of time, servicing the channel as required.
- * \return returns -1 on hangup, otherwise 0.
- */
-int ast_safe_sleep(struct ast_channel *chan, int ms);
-
-/*! \brief Wait for a specied amount of time, looking for hangups and a condition argument
- * \param chan channel to wait for
- * \param ms length of time in milliseconds to sleep
- * \param cond a function pointer for testing continue condition
- * \param data argument to be passed to the condition test function
- * \return returns -1 on hangup, otherwise 0.
- * Waits for a specified amount of time, servicing the channel as required. If cond
- * returns 0, this function returns.
- */
-int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
-
-/*! \brief Waits for activity on a group of channels
- * \param chan an array of pointers to channels
- * \param n number of channels that are to be waited upon
- * \param fds an array of fds to wait upon
- * \param nfds the number of fds to wait upon
- * \param exception exception flag
- * \param outfd fd that had activity on it
- * \param ms how long the wait was
- * Big momma function here. Wait for activity on any of the n channels, or any of the nfds
- file descriptors.
- \return Returns the channel with activity, or NULL on error or if an FD
- came first. If the FD came first, it will be returned in outfd, otherwise, outfd
- will be -1 */
-struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms);
-
-/*! Waits for input on a group of channels */
-/*! Wait for input on an array of channels for a given # of milliseconds. Return channel
- with activity, or NULL if none has activity. time "ms" is modified in-place, if applicable */
-struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
-
-/*! Waits for input on an fd */
-/*! This version works on fd's only. Be careful with it. */
-int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
-
-
-/*! Reads a frame */
-/*!
- * \param chan channel to read a frame from
- * Read a frame. Returns a frame, or NULL on error. If it returns NULL, you
- best just stop reading frames and assume the channel has been
- disconnected. */
-struct ast_frame *ast_read(struct ast_channel *chan);
-
-/*! Write a frame to a channel */
-/*!
- * \param chan destination channel of the frame
- * \param frame frame that will be written
- * This function writes the given frame to the indicated channel.
- * It returns 0 on success, -1 on failure.
- */
-int ast_write(struct ast_channel *chan, struct ast_frame *frame);
-
-/*! Write video frame to a channel */
-/*!
- * \param chan destination channel of the frame
- * \param frame frame that will be written
- * This function writes the given frame to the indicated channel.
- * It returns 1 on success, 0 if not implemented, and -1 on failure.
- */
-int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
-
-/* Send empty audio to prime a channel driver */
-int ast_prod(struct ast_channel *chan);
-
-/*! Sets read format on channel chan */
-/*!
- * \param chan channel to change
- * \param format format to change to
- * Set read format for channel to whichever component of "format" is best.
- * Returns 0 on success, -1 on failure
- */
-int ast_set_read_format(struct ast_channel *chan, int format);
-
-/*! Sets write format on channel chan */
-/*!
- * \param chan channel to change
- * \param format new format for writing
- * Set write format for channel to whichever compoent of "format" is best.
- * Returns 0 on success, -1 on failure
- */
-int ast_set_write_format(struct ast_channel *chan, int format);
-
-/*! Sends text to a channel */
-/*!
- * \param chan channel to act upon
- * \param text string of text to send on the channel
- * Write text to a display on a channel
- * Returns 0 on success, -1 on failure
- */
-int ast_sendtext(struct ast_channel *chan, const char *text);
-
-/*! Receives a text character from a channel */
-/*!
- * \param chan channel to act upon
- * \param timeout timeout in milliseconds (0 for infinite wait)
- * Read a char of text from a channel
- * Returns 0 on success, -1 on failure
- */
-int ast_recvchar(struct ast_channel *chan, int timeout);
-
-/*! Send a DTMF digit to a channel */
-/*!
- * \param chan channel to act upon
- * \param digit the DTMF digit to send, encoded in ASCII
- * Send a DTMF digit to a channel.
- * Returns 0 on success, -1 on failure
- */
-int ast_senddigit(struct ast_channel *chan, char digit);
-
-/*! Receives a text string from a channel */
-/*!
- * \param chan channel to act upon
- * \param timeout timeout in milliseconds (0 for infinite wait)
- * \return the received text, or NULL to signify failure.
- * Read a string of text from a channel
- */
-char *ast_recvtext(struct ast_channel *chan, int timeout);
-
-/*! Browse channels in use */
-/*!
- * \param prev where you want to start in the channel list
- * Browse the channels currently in use
- * Returns the next channel in the list, NULL on end.
- * If it returns a channel, that channel *has been locked*!
- */
-struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev);
-
-/*! Get channel by name (locks channel) */
-struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
-
-/*! Get channel by name prefix (locks channel) */
-struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
-
-/*! Get channel by name prefix (locks channel) */
-struct ast_channel *ast_walk_channel_by_name_prefix_locked(struct ast_channel *chan, const char *name, const int namelen);
-
-/*--- ast_get_channel_by_exten_locked: Get channel by exten (and optionally context) and lock it */
-struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
-
-/*! Waits for a digit */
-/*!
- * \param c channel to wait for a digit on
- * \param ms how many milliseconds to wait
- * Wait for a digit. Returns <0 on error, 0 on no entry, and the digit on success. */
-int ast_waitfordigit(struct ast_channel *c, int ms);
-
-/* Same as above with audio fd for outputing read audio and ctrlfd to monitor for
- reading. Returns 1 if ctrlfd becomes available */
-int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
-
-/*! Reads multiple digits */
-/*!
- * \param c channel to read from
- * \param s string to read in to. Must be at least the size of your length
- * \param len how many digits to read (maximum)
- * \param timeout how long to timeout between digits
- * \param rtimeout timeout to wait on the first digit
- * \param enders digits to end the string
- * Read in a digit string "s", max length "len", maximum timeout between
- digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
- for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of
- a timeout, any digits that were read before the timeout will still be available in s.
- RETURNS 2 in full version when ctrlfd is available, NOT 1*/
-int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
-int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
-
-/*! Report DTMF on channel 0 */
-#define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0)
-/*! Report DTMF on channel 1 */
-#define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1)
-/*! Return all voice frames on channel 0 */
-#define AST_BRIDGE_REC_CHANNEL_0 (1 << 2)
-/*! Return all voice frames on channel 1 */
-#define AST_BRIDGE_REC_CHANNEL_1 (1 << 3)
-/*! Ignore all signal frames except NULL */
-#define AST_BRIDGE_IGNORE_SIGS (1 << 4)
-
-
-/*! Makes two channel formats compatible */
-/*!
- * \param c0 first channel to make compatible
- * \param c1 other channel to make compatible
- * Set two channels to compatible formats -- call before ast_channel_bridge in general . Returns 0 on success
- and -1 if it could not be done */
-int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
-
-/*! Bridge two channels together */
-/*!
- * \param c0 first channel to bridge
- * \param c1 second channel to bridge
- * \param config config for the channels
- * \param fo destination frame(?)
- * \param rc destination channel(?)
- * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in
- *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
-/* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
-int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
-
-/*! Weird function made for call transfers */
-/*!
- * \param original channel to make a copy of
- * \param clone copy of the original channel
- * This is a very strange and freaky function used primarily for transfer. Suppose that
- "original" and "clone" are two channels in random situations. This function takes
- the guts out of "clone" and puts them into the "original" channel, then alerts the
- channel driver of the change, asking it to fixup any private information (like the
- p->owner pointer) that is affected by the change. The physical layer of the original
- channel is hung up. */
-int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
-
-/*! Gives the string form of a given cause code */
-/*!
- * \param state cause to get the description of
- * Give a name to a cause code
- * Returns the text form of the binary cause code given
- */
-const char *ast_cause2str(int state);
-
-/*! Gives the string form of a given channel state */
-/*!
- * \param state state to get the name of
- * Give a name to a state
- * Returns the text form of the binary state given
- */
-char *ast_state2str(int state);
-
-/*! Gives the string form of a given transfer capability */
-/*!
- * \param transfercapability transfercapabilty to get the name of
- * Give a name to a transfercapbility
- * See above
- * Returns the text form of the binary transfer capbility
- */
-char *ast_transfercapability2str(int transfercapability);
-
-/* Options: Some low-level drivers may implement "options" allowing fine tuning of the
- low level channel. See frame.h for options. Note that many channel drivers may support
- none or a subset of those features, and you should not count on this if you want your
- asterisk application to be portable. They're mainly useful for tweaking performance */
-
-/*! Sets an option on a channel */
-/*!
- * \param channel channel to set options on
- * \param option option to change
- * \param data data specific to option
- * \param datalen length of the data
- * \param block blocking or not
- * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
- * Returns 0 on success and -1 on failure
- */
-int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
-
-/*! Pick the best codec */
-/* Choose the best codec... Uhhh... Yah. */
-extern int ast_best_codec(int fmts);
-
-
-/*! Checks the value of an option */
-/*!
- * Query the value of an option, optionally blocking until a reply is received
- * Works similarly to setoption except only reads the options.
- */
-struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
-
-/*! Checks for HTML support on a channel */
-/*! Returns 0 if channel does not support HTML or non-zero if it does */
-int ast_channel_supports_html(struct ast_channel *channel);
-
-/*! Sends HTML on given channel */
-/*! Send HTML or URL on link. Returns 0 on success or -1 on failure */
-int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
-
-/*! Sends a URL on a given link */
-/*! Send URL on link. Returns 0 on success or -1 on failure */
-int ast_channel_sendurl(struct ast_channel *channel, const char *url);
-
-/*! Defers DTMF */
-/*! Defer DTMF so that you only read things like hangups and audio. Returns
- non-zero if channel was already DTMF-deferred or 0 if channel is just now
- being DTMF-deferred */
-int ast_channel_defer_dtmf(struct ast_channel *chan);
-
-/*! Undeos a defer */
-/*! Undo defer. ast_read will return any dtmf characters that were queued */
-void ast_channel_undefer_dtmf(struct ast_channel *chan);
-
-/*! Initiate system shutdown -- prevents new channels from being allocated.
- If "hangup" is non-zero, all existing channels will receive soft
- hangups */
-void ast_begin_shutdown(int hangup);
-
-/*! Cancels an existing shutdown and returns to normal operation */
-void ast_cancel_shutdown(void);
-
-/*! Returns number of active/allocated channels */
-int ast_active_channels(void);
-
-/*! Returns non-zero if Asterisk is being shut down */
-int ast_shutting_down(void);
-
-/*! Activate a given generator */
-int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
-
-/*! Deactive an active generator */
-void ast_deactivate_generator(struct ast_channel *chan);
-
-void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani);
-
-/*! Start a tone going */
-int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
-/*! Stop a tone from playing */
-void ast_tonepair_stop(struct ast_channel *chan);
-/*! Play a tone pair for a given amount of time */
-int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
-
-/*! Automatically service a channel for us... */
-int ast_autoservice_start(struct ast_channel *chan);
-
-/*! Stop servicing a channel for us... Returns -1 on error or if channel has been hungup */
-int ast_autoservice_stop(struct ast_channel *chan);
-
-/* If built with zaptel optimizations, force a scheduled expiration on the
- timer fd, at which point we call the callback function / data */
-int ast_settimeout(struct ast_channel *c, int samples, int (*func)(void *data), void *data);
-
-/*! \brief Transfer a channel (if supported). Returns -1 on error, 0 if not supported
- and 1 if supported and requested
- \param chan current channel
- \param dest destination extension for transfer
-*/
-int ast_transfer(struct ast_channel *chan, char *dest);
-
-/*! \brief Start masquerading a channel
- XXX This is a seriously wacked out operation. We're essentially putting the guts of
- the clone channel into the original channel. Start by killing off the original
- channel's backend. I'm not sure we're going to keep this function, because
- while the features are nice, the cost is very high in terms of pure nastiness. XXX
- \param chan Channel to masquerade
-*/
-int ast_do_masquerade(struct ast_channel *chan);
-
-/*! \brief Find bridged channel
- \param chan Current channel
-*/
-struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
-
-/*!
- \brief Inherits channel variable from parent to child channel
- \param parent Parent channel
- \param child Child channel
-
- Scans all channel variables in the parent channel, looking for those
- that should be copied into the child channel.
- Variables whose names begin with a single '_' are copied into the
- child channel with the prefix removed.
- Variables whose names begin with '__' are copied into the child
- channel with their names unchanged.
-*/
-void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
-
-/*!
- \brief adds a list of channel variables to a channel
- \param chan the channel
- \param vars a linked list of variables
-
- Variable names can be for a regular channel variable or a dialplan function
- that has the ability to be written to.
-*/
-void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
-
-/*!
- \brief An opaque 'object' structure use by silence generators on channels.
- */
-struct ast_silence_generator;
-
-/*!
- \brief Starts a silence generator on the given channel.
- \param chan The channel to generate silence on
- \return An ast_silence_generator pointer, or NULL if an error occurs
-
- This function will cause SLINEAR silence to be generated on the supplied
- channel until it is disabled; if the channel cannot be put into SLINEAR
- mode then the function will fail.
-
- The pointer returned by this function must be preserved and passed to
- ast_channel_stop_silence_generator when you wish to stop the silence
- generation.
- */
-struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
-
-/*!
- \brief Stops a previously-started silence generator on the given channel.
- \param chan The channel to operate on
- \param state The ast_silence_generator pointer return by a previous call to
- ast_channel_start_silence_generator.
- \return nothing
-
- This function will stop the operating silence generator and return the channel
- to its previous write format.
- */
-void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
-
-/* Misc. functions below */
-
-/* Helper function for migrating select to poll */
-static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start)
-{
- int x;
- for (x=start ? *start : 0;x<max;x++)
- if (pfds[x].fd == fd) {
- if (start) {
- if (x==*start)
- (*start)++;
- }
- return pfds[x].revents;
- }
- return 0;
-}
-
-#ifdef SOLARIS
-static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
-{
- tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
- tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
- if (tvdiff->tv_usec < 0) {
- tvdiff->tv_sec --;
- tvdiff->tv_usec += 1000000;
- }
-
-}
-#endif
-
-/*! \brief Waits for activity on a group of channels
- * \param nfds the maximum number of file descriptors in the sets
- * \param rfds file descriptors to check for read availability
- * \param wfds file descriptors to check for write availability
- * \param efds file descriptors to check for exceptions (OOB data)
- * \param tvp timeout while waiting for events
- * This is the same as a standard select(), except it guarantees the
- * behaviour where the passed struct timeval is updated with how much
- * time was not slept while waiting for the specified events
- */
-static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
-{
-#ifdef __linux__
- return select(nfds, rfds, wfds, efds, tvp);
-#else
- if (tvp) {
- struct timeval tv, tvstart, tvend, tvlen;
- int res;
-
- tv = *tvp;
- gettimeofday(&tvstart, NULL);
- res = select(nfds, rfds, wfds, efds, tvp);
- gettimeofday(&tvend, NULL);
- timersub(&tvend, &tvstart, &tvlen);
- timersub(&tv, &tvlen, tvp);
- if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
- tvp->tv_sec = 0;
- tvp->tv_usec = 0;
- }
- return res;
- }
- else
- return select(nfds, rfds, wfds, efds, NULL);
-#endif
-}
-
-#if !defined(ast_strdupa) && defined(__GNUC__)
-# define ast_strdupa(s) \
- (__extension__ \
- ({ \
- __const char *__old = (s); \
- size_t __len = strlen (__old) + 1; \
- char *__new = (char *) __builtin_alloca (__len); \
- (char *) memcpy (__new, __old, __len); \
- }))
-#endif
-
-#ifdef DO_CRASH
-#define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0)
-#else
-#define CRASH do { } while(0)
-#endif
-
-#define CHECK_BLOCKING(c) { \
- if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
- ast_log(LOG_WARNING, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \
- CRASH; \
- } else { \
- (c)->blocker = pthread_self(); \
- (c)->blockproc = __PRETTY_FUNCTION__; \
- ast_set_flag(c, AST_FLAG_BLOCKING); \
- } }
-
-extern ast_group_t ast_get_group(char *s);
-/* print call- and pickup groups into buffer */
-extern char *ast_print_group(char *buf, int buflen, ast_group_t group);
-
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_CHANNEL_H */
diff --git a/1.2-netsec/include/asterisk/chanspy.h b/1.2-netsec/include/asterisk/chanspy.h
deleted file mode 100644
index 5b2f5df18..000000000
--- a/1.2-netsec/include/asterisk/chanspy.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Asterisk PBX channel spy definitions
- */
-
-#ifndef _ASTERISK_CHANSPY_H
-#define _ASTERISK_CHANSPY_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#include "asterisk/linkedlists.h"
-
-enum chanspy_states {
- CHANSPY_NEW = 0, /*!< spy not yet operating */
- CHANSPY_RUNNING = 1, /*!< normal operation, spy is still operating */
- CHANSPY_DONE = 2, /*!< spy is stopped and already removed from channel */
- CHANSPY_STOP = 3, /*!< spy requested to stop, still attached to channel */
-};
-
-enum chanspy_flags {
- CHANSPY_MIXAUDIO = (1 << 0),
- CHANSPY_READ_VOLADJUST = (1 << 1),
- CHANSPY_WRITE_VOLADJUST = (1 << 2),
- CHANSPY_FORMAT_AUDIO = (1 << 3),
- CHANSPY_TRIGGER_MODE = (3 << 4),
- CHANSPY_TRIGGER_READ = (1 << 4),
- CHANSPY_TRIGGER_WRITE = (2 << 4),
- CHANSPY_TRIGGER_NONE = (3 << 4),
- CHANSPY_TRIGGER_FLUSH = (1 << 6),
-};
-
-struct ast_channel_spy_queue {
- struct ast_frame *head;
- unsigned int samples;
- unsigned int format;
-};
-
-struct ast_channel_spy {
- AST_LIST_ENTRY(ast_channel_spy) list;
- ast_mutex_t lock;
- ast_cond_t trigger;
- struct ast_channel_spy_queue read_queue;
- struct ast_channel_spy_queue write_queue;
- unsigned int flags;
- enum chanspy_states status;
- const char *type;
- /* The volume adjustment values are very straightforward:
- positive values cause the samples to be multiplied by that amount
- negative values cause the samples to be divided by the absolute value of that amount
- */
- int read_vol_adjustment;
- int write_vol_adjustment;
-};
-
-/*!
- \brief Adds a spy to a channel, to begin receiving copies of the channel's audio frames.
- \param chan The channel to add the spy to.
- \param spy A pointer to ast_channel_spy structure describing how the spy is to be used.
- \return 0 for success, non-zero for failure
-
- Note: This function performs no locking; you must hold the channel's lock before
- calling this function.
- */
-int ast_channel_spy_add(struct ast_channel *chan, struct ast_channel_spy *spy);
-
-/*!
- \brief Remove a spy from a channel.
- \param chan The channel to remove the spy from
- \param spy The spy to be removed
- \return nothing
-
- Note: This function performs no locking; you must hold the channel's lock before
- calling this function.
- */
-void ast_channel_spy_remove(struct ast_channel *chan, struct ast_channel_spy *spy);
-
-/*!
- \brief Find all spies of a particular type on a channel and stop them.
- \param chan The channel to operate on
- \param type A character string identifying the type of spies to be stopped
- \return nothing
-
- Note: This function performs no locking; you must hold the channel's lock before
- calling this function.
- */
-void ast_channel_spy_stop_by_type(struct ast_channel *chan, const char *type);
-
-/*!
- \brief Read one (or more) frames of audio from a channel being spied upon.
- \param spy The spy to operate on
- \param samples The number of audio samples to read
- \return NULL for failure, one ast_frame pointer, or a chain of ast_frame pointers
-
- This function can return multiple frames if the spy structure needs to be 'flushed'
- due to mismatched queue lengths, or if the spy structure is configured to return
- unmixed audio (in which case each call to this function will return a frame of audio
- from each side of channel).
-
- Note: This function performs no locking; you must hold the spy's lock before calling
- this function. You must <b>not</b> hold the channel's lock at the same time.
- */
-struct ast_frame *ast_channel_spy_read_frame(struct ast_channel_spy *spy, unsigned int samples);
-
-/*!
- \brief Efficiently wait until audio is available for a spy, or an exception occurs.
- \param spy The spy to wait on
- \return nothing
-
- Note: The locking rules for this function are non-obvious... first, you must <b>not</b>
- hold the channel's lock when calling this function. Second, you must hold the spy's lock
- before making the function call; while the function runs the lock will be released, and
- when the trigger event occurs, the lock will be re-obtained. This means that when control
- returns to your code, you will again hold the spy's lock.
- */
-void ast_channel_spy_trigger_wait(struct ast_channel_spy *spy);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_CHANSPY_H */
diff --git a/1.2-netsec/include/asterisk/chanvars.h b/1.2-netsec/include/asterisk/chanvars.h
deleted file mode 100644
index d31c05e86..000000000
--- a/1.2-netsec/include/asterisk/chanvars.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Channel Variables
- */
-
-#ifndef _ASTERISK_CHANVARS_H
-#define _ASTERISK_CHANVARS_H
-
-#include "asterisk/linkedlists.h"
-
-struct ast_var_t {
- AST_LIST_ENTRY(ast_var_t) entries;
- char *value;
- char name[0];
-};
-
-AST_LIST_HEAD_NOLOCK(varshead, ast_var_t);
-
-struct ast_var_t *ast_var_assign(const char *name, const char *value);
-void ast_var_delete(struct ast_var_t *var);
-char *ast_var_name(struct ast_var_t *var);
-char *ast_var_full_name(struct ast_var_t *var);
-char *ast_var_value(struct ast_var_t *var);
-
-#endif /* _ASTERISK_CHANVARS_H */
diff --git a/1.2-netsec/include/asterisk/cli.h b/1.2-netsec/include/asterisk/cli.h
deleted file mode 100644
index 4dcdeab65..000000000
--- a/1.2-netsec/include/asterisk/cli.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Standard Command Line Interface
- */
-
-#ifndef _ASTERISK_CLI_H
-#define _ASTERISK_CLI_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#include <stdarg.h>
-
-extern void ast_cli(int fd, char *fmt, ...)
- __attribute__ ((format (printf, 2, 3)));
-
-#define RESULT_SUCCESS 0
-#define RESULT_SHOWUSAGE 1
-#define RESULT_FAILURE 2
-
-#define AST_MAX_CMD_LEN 16
-
-#define AST_MAX_ARGS 64
-
-#define AST_CLI_COMPLETE_EOF "_EOF_"
-
-/*! \brief A command line entry */
-struct ast_cli_entry {
- /*! Null terminated list of the words of the command */
- char *cmda[AST_MAX_CMD_LEN];
- /*! Handler for the command (fd for output, # of arguments, argument list). Returns RESULT_SHOWUSAGE for improper arguments */
- int (*handler)(int fd, int argc, char *argv[]);
- /*! Summary of the command (< 60 characters) */
- char *summary;
- /*! Detailed usage information */
- char *usage;
- /*! Generate a list of possible completions for a given word */
- char *(*generator)(char *line, char *word, int pos, int state);
- /*! For linking */
- struct ast_cli_entry *next;
- /*! For keeping track of usage */
- int inuse;
-};
-
-/*! \brief Interprets a command
- * Interpret a command s, sending output to fd
- * Returns 0 on succes, -1 on failure
- */
-extern int ast_cli_command(int fd, char *s);
-
-/*! \brief Registers a command or an array of commands
- * \param e which cli entry to register
- * Register your own command
- * Returns 0 on success, -1 on failure
- */
-extern int ast_cli_register(struct ast_cli_entry *e);
-
-/*!
- * \brief Register multiple commands
- * \param e pointer to first cli entry to register
- * \param len number of entries to register
- */
-extern void ast_cli_register_multiple(struct ast_cli_entry *e, int len);
-
-/*! \brief Unregisters a command or an array of commands
- *
- * \param e which cli entry to unregister
- * Unregister your own command. You must pass a completed ast_cli_entry structure
- * Returns 0.
- */
-extern int ast_cli_unregister(struct ast_cli_entry *e);
-
-/*!
- * \brief Unregister multiple commands
- * \param e pointer to first cli entry to unregister
- * \param len number of entries to unregister
- */
-extern void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len);
-
-/*! \brief Readline madness
- * Useful for readline, that's about it
- * Returns 0 on success, -1 on failure
- */
-extern char *ast_cli_generator(char *, char *, int);
-
-extern int ast_cli_generatornummatches(char *, char *);
-extern char **ast_cli_completion_matches(char *, char *);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_CLI_H */
diff --git a/1.2-netsec/include/asterisk/compat.h b/1.2-netsec/include/asterisk/compat.h
deleted file mode 100644
index 139f4f81b..000000000
--- a/1.2-netsec/include/asterisk/compat.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Asterisk -- A telephony toolkit for Linux.
- *
- * Copyright (C) 1999-2005, Mark Spencer
- *
- * Mark Spencer <markster@digium.com>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-/*! \file
- * \brief General Definitions for Asterisk top level program
- */
-
-#ifndef _COMPAT_H
-#define _COMPAT_H
-
-#ifdef SOLARIS
-#define __BEGIN_DECLS
-#define __END_DECLS
-
-#ifndef __P
-#define __P(p) p
-#endif
-
-#include <alloca.h>
-#include <strings.h>
-#include <string.h>
-#include <pthread.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <netinet/in.h>
-
-#ifndef BYTE_ORDER
-#define LITTLE_ENDIAN 1234
-#define BIG_ENDIAN 4321
-
-#ifdef __sparc__
-#define BYTE_ORDER BIG_ENDIAN
-#else
-#define BYTE_ORDER LITTLE_ENDIAN
-#endif
-#endif
-
-#ifndef __BYTE_ORDER
-#define __LITTLE_ENDIAN LITTLE_ENDIAN
-#define __BIG_ENDIAN BIG_ENDIAN
-#define __BYTE_ORDER BYTE_ORDER
-#endif
-
-#ifndef __BIT_TYPES_DEFINED__
-#define __BIT_TYPES_DEFINED__
-typedef unsigned char u_int8_t;
-typedef unsigned short u_int16_t;
-typedef unsigned int u_int32_t;
-#endif
-
-char* strsep(char** str, const char* delims);
-int setenv(const char *name, const char *value, int overwrite);
-int unsetenv(const char *name);
-#endif /* SOLARIS */
-
-#ifdef __CYGWIN__
-#define _WIN32_WINNT 0x0500
-#ifndef INET_ADDRSTRLEN
-#define INET_ADDRSTRLEN 16
-#endif
-#ifndef INET6_ADDRSTRLEN
-#define INET6_ADDRSTRLEN 46
-#endif
-#endif /* __CYGWIN__ */
-
-#define HAVE_VASPRINTF
-#define HAVE_STRTOQ
-
-#ifdef _BSD_SOURCE
-#define HAVE_GETLOADAVG
-#endif
-
-#ifdef __linux__
-#define HAVE_STRCASESTR
-#define HAVE_STRNDUP
-#define HAVE_STRNLEN
-#endif
-
-#ifdef SOLARIS
-#undef HAVE_VASPRINTF
-#undef HAVE_STRTOQ
-#endif
-
-#ifdef __CYGWIN__
-#undef HAVE_STRTOQ
-typedef unsigned long long uint64_t;
-#endif
-
-#endif
diff --git a/1.2-netsec/include/asterisk/compiler.h b/1.2-netsec/include/asterisk/compiler.h
deleted file mode 100644
index 24f6907d1..000000000
--- a/1.2-netsec/include/asterisk/compiler.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Compiler-specific macros and other items
- */
-
-#ifndef _ASTERISK_COMPILER_H
-#define _ASTERISK_COMPILER_H
-
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
-#define __builtin_expect(exp, c) (exp)
-#define force_inline inline
-#else
-#define force_inline inline __attribute__((always_inline))
-#endif
-
-#endif /* _ASTERISK_COMPILER_H */
diff --git a/1.2-netsec/include/asterisk/config.h b/1.2-netsec/include/asterisk/config.h
deleted file mode 100644
index aa639aaae..000000000
--- a/1.2-netsec/include/asterisk/config.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Configuration File Parser
- */
-
-#ifndef _ASTERISK_CONFIG_H
-#define _ASTERISK_CONFIG_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#include <stdarg.h>
-
-struct ast_config;
-
-struct ast_category;
-
-struct ast_variable {
- char *name;
- char *value;
- int lineno;
- int object; /*!< 0 for variable, 1 for object */
- int blanklines; /*!< Number of blanklines following entry */
- struct ast_comment *precomments;
- struct ast_comment *sameline;
- struct ast_variable *next;
- char stuff[0];
-};
-
-typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config);
-typedef struct ast_variable *realtime_var_get(const char *database, const char *table, va_list ap);
-typedef struct ast_config *realtime_multi_get(const char *database, const char *table, va_list ap);
-typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap);
-
-struct ast_config_engine {
- char *name;
- config_load_func *load_func;
- realtime_var_get *realtime_func;
- realtime_multi_get *realtime_multi_func;
- realtime_update *update_func;
- struct ast_config_engine *next;
-};
-
-/*! \brief Load a config file
- * \param filename path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR
- * Create a config structure from a given configuration file.
- *
- * Returns NULL on error, or an ast_config data structure on success
- */
-struct ast_config *ast_config_load(const char *filename);
-
-/*! \brief Destroys a config
- * \param config pointer to config data structure
- * Free memory associated with a given config
- *
- */
-void ast_config_destroy(struct ast_config *config);
-
-/*! \brief Goes through categories
- * \param config Which config structure you wish to "browse"
- * \param prev A pointer to a previous category.
- * This funtion is kind of non-intuitive in it's use. To begin, one passes NULL as the second arguement. It will return a pointer to the string of the first category in the file. From here on after, one must then pass the previous usage's return value as the second pointer, and it will return a pointer to the category name afterwards.
- *
- * Returns a category on success, or NULL on failure/no-more-categories
- */
-char *ast_category_browse(struct ast_config *config, const char *prev);
-
-/*! \brief Goes through variables
- * Somewhat similar in intent as the ast_category_browse.
- * List variables of config file category
- *
- * Returns ast_variable list on success, or NULL on failure
- */
-struct ast_variable *ast_variable_browse(const struct ast_config *config, const char *category);
-
-/*! \brief Gets a variable
- * \param config which (opened) config to use
- * \param category category under which the variable lies
- * \param variable which variable you wish to get the data for
- * Goes through a given config file in the given category and searches for the given variable
- *
- * Returns the variable value on success, or NULL if unable to find it.
- */
-char *ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable);
-
-/*! \brief Retrieve a category if it exists
- * \param config which config to use
- * \param category_name name of the category you're looking for
- * This will search through the categories within a given config file for a match.
- *
- * Returns pointer to category if found, NULL if not.
- */
-struct ast_category *ast_category_get(const struct ast_config *config, const char *category_name);
-
-/*! \brief Check for category duplicates
- * \param config which config to use
- * \param category_name name of the category you're looking for
- * This will search through the categories within a given config file for a match.
- *
- * Return non-zero if found
- */
-int ast_category_exist(const struct ast_config *config, const char *category_name);
-
-/*! \brief Retrieve realtime configuration
- * \param family which family/config to lookup
- * This will use builtin configuration backends to look up a particular
- * entity in realtime and return a variable list of its parameters. Note
- * that unlike the variables in ast_config, the resulting list of variables
- * MUST be fred with ast_free_runtime() as there is no container.
- */
-struct ast_variable *ast_load_realtime(const char *family, ...);
-
-/*! \brief Retrieve realtime configuration
- * \param family which family/config to lookup
- * This will use builtin configuration backends to look up a particular
- * entity in realtime and return a variable list of its parameters. Unlike
- * the ast_load_realtime, this function can return more than one entry and
- * is thus stored inside a taditional ast_config structure rather than
- * just returning a linked list of variables.
- */
-struct ast_config *ast_load_realtime_multientry(const char *family, ...);
-
-/*! \brief Update realtime configuration
- * \param family which family/config to be updated
- * \param keyfield which field to use as the key
- * \param lookup which value to look for in the key field to match the entry.
- * This function is used to update a parameter in realtime configuration space.
- *
- */
-int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...);
-
-/*! \brief Check if realtime engine is configured for family
- * returns 1 if family is configured in realtime and engine exists
- * \param family which family/config to be checked
-*/
-int ast_check_realtime(const char *family);
-
-/*! \brief Free variable list
- * \param var the linked list of variables to free
- * This function frees a list of variables.
- */
-void ast_variables_destroy(struct ast_variable *var);
-
-/*! \brief Register config engine */
-int ast_config_engine_register(struct ast_config_engine *newconfig);
-
-/*! \brief Deegister config engine */
-int ast_config_engine_deregister(struct ast_config_engine *del);
-
-int register_config_cli(void);
-void read_config_maps(void);
-
-struct ast_config *ast_config_new(void);
-struct ast_category *ast_config_get_current_category(const struct ast_config *cfg);
-void ast_config_set_current_category(struct ast_config *cfg, const struct ast_category *cat);
-
-struct ast_category *ast_category_new(const char *name);
-void ast_category_append(struct ast_config *config, struct ast_category *cat);
-int ast_category_delete(struct ast_config *cfg, char *category);
-void ast_category_destroy(struct ast_category *cat);
-struct ast_variable *ast_category_detach_variables(struct ast_category *cat);
-void ast_category_rename(struct ast_category *cat, const char *name);
-
-struct ast_variable *ast_variable_new(const char *name, const char *value);
-void ast_variable_append(struct ast_category *category, struct ast_variable *variable);
-int ast_variable_delete(struct ast_config *cfg, char *category, char *variable, char *value);
-
-int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
-
-struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_CONFIG_H */
diff --git a/1.2-netsec/include/asterisk/crypto.h b/1.2-netsec/include/asterisk/crypto.h
deleted file mode 100644
index d0f852caf..000000000
--- a/1.2-netsec/include/asterisk/crypto.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Provide cryptographic signature routines
- */
-
-#ifndef _ASTERISK_CRYPTO_H
-#define _ASTERISK_CRYPTO_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#define AST_KEY_PUBLIC (1 << 0)
-#define AST_KEY_PRIVATE (1 << 1)
-
-struct ast_key;
-
-/*! \brief Retrieve a key
- * \param name of the key we are retrieving
- * \param int type of key (AST_KEY_PUBLIC or AST_KEY_PRIVATE)
- *
- * Returns the key on success or NULL on failure
- */
-extern struct ast_key *(*ast_key_get)(const char *key, int type);
-
-/*! \brief Check the authenticity of a message signature using a given public key
- * \param key a public key to use to verify
- * \param msg the message that has been signed
- * \param sig the proposed valid signature in mime64-like encoding
- *
- * Returns 0 if the signature is valid, or -1 otherwise
- *
- */
-extern int (*ast_check_signature)(struct ast_key *key, const char *msg, const char *sig);
-
-/*! \brief Check the authenticity of a message signature using a given public key
- * \param key a public key to use to verify
- * \param msg the message that has been signed
- * \param sig the proposed valid signature in raw binary representation
- *
- * Returns 0 if the signature is valid, or -1 otherwise
- *
- */
-extern int (*ast_check_signature_bin)(struct ast_key *key, const char *msg, int msglen, const unsigned char *sig);
-
-/*!
- * \param key a private key to use to create the signature
- * \param msg the message to sign
- * \param sig a pointer to a buffer of at least 256 bytes in which the
- * mime64-like encoded signature will be stored
- *
- * Returns 0 on success or -1 on failure.
- *
- */
-extern int (*ast_sign)(struct ast_key *key, char *msg, char *sig);
-
-/*!
- * \param key a private key to use to create the signature
- * \param msg the message to sign
- * \param sig a pointer to a buffer of at least 128 bytes in which the
- * raw encoded signature will be stored
- *
- * Returns 0 on success or -1 on failure.
- *
- */
-extern int (*ast_sign_bin)(struct ast_key *key, const char *msg, int msglen, unsigned char *sig);
-
-/*!
- * \param key a private key to use to encrypt
- * \param src the message to encrypt
- * \param srclen the length of the message to encrypt
- * \param dst a pointer to a buffer of at least srclen * 1.5 bytes in which the encrypted
- * answer will be stored
- *
- * Returns length of encrypted data on success or -1 on failure.
- *
- */
-extern int (*ast_encrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key);
-
-/*!
- * \param key a private key to use to decrypt
- * \param src the message to decrypt
- * \param srclen the length of the message to decrypt
- * \param dst a pointer to a buffer of at least srclen bytes in which the decrypted
- * answer will be stored
- *
- * Returns length of decrypted data on success or -1 on failure.
- *
- */
-extern int (*ast_decrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key);
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_CRYPTO_H */
diff --git a/1.2-netsec/include/asterisk/devicestate.h b/1.2-netsec/include/asterisk/devicestate.h
deleted file mode 100644
index e41b9ee27..000000000
--- a/1.2-netsec/include/asterisk/devicestate.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Device state management
- */
-
-#ifndef _ASTERISK_DEVICESTATE_H
-#define _ASTERISK_DEVICESTATE_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/*! Device is valid but channel didn't know state */
-#define AST_DEVICE_UNKNOWN 0
-/*! Device is not used */
-#define AST_DEVICE_NOT_INUSE 1
-/*! Device is in use */
-#define AST_DEVICE_INUSE 2
-/*! Device is busy */
-#define AST_DEVICE_BUSY 3
-/*! Device is invalid */
-#define AST_DEVICE_INVALID 4
-/*! Device is unavailable */
-#define AST_DEVICE_UNAVAILABLE 5
-/*! Device is ringing */
-#define AST_DEVICE_RINGING 6
-
-typedef int (*ast_devstate_cb_type)(const char *dev, int state, void *data);
-
-/*! \brief Convert device state to text string for output
- * \param devstate Current device state
- */
-const char *devstate2str(int devstate);
-
-/*! \brief Search the Channels by Name
- * \param device like a dialstring
- * Search the Device in active channels by compare the channelname against
- * the devicename. Compared are only the first chars to the first '-' char.
- * Returns an AST_DEVICE_UNKNOWN if no channel found or
- * AST_DEVICE_INUSE if a channel is found
- */
-int ast_parse_device_state(const char *device);
-
-/*! \brief Asks a channel for device state
- * \param device like a dialstring
- * Asks a channel for device state, data is normaly a number from dialstring
- * used by the low level module
- * Trys the channel devicestate callback if not supported search in the
- * active channels list for the device.
- * Returns an AST_DEVICE_??? state -1 on failure
- */
-int ast_device_state(const char *device);
-
-/*! \brief Tells Asterisk the State for Device is changed
- * \param fmt devicename like a dialstring with format parameters
- * Asterisk polls the new extensionstates and calls the registered
- * callbacks for the changed extensions
- * Returns 0 on success, -1 on failure
- */
-int ast_device_state_changed(const char *fmt, ...)
- __attribute__ ((format (printf, 1, 2)));
-
-
-/*! \brief Tells Asterisk the State for Device is changed
- * \param device devicename like a dialstrin
- * Asterisk polls the new extensionstates and calls the registered
- * callbacks for the changed extensions
- * Returns 0 on success, -1 on failure
- */
-int ast_device_state_changed_literal(const char *device);
-
-/*! \brief Registers a device state change callback
- * \param callback Callback
- * \param data to pass to callback
- * The callback is called if the state for extension is changed
- * Return -1 on failure, ID on success
- */
-int ast_devstate_add(ast_devstate_cb_type callback, void *data);
-void ast_devstate_del(ast_devstate_cb_type callback, void *data);
-
-int ast_device_state_engine_init(void);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_DEVICESTATE_H */
diff --git a/1.2-netsec/include/asterisk/dlfcn-compat.h b/1.2-netsec/include/asterisk/dlfcn-compat.h
deleted file mode 100644
index 2ce827a6a..000000000
--- a/1.2-netsec/include/asterisk/dlfcn-compat.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * 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.
- */
-
-/*
-Copyright (c) 2002 Jorge Acereda <jacereda@users.sourceforge.net> &
- Peter O'Gorman <ogorman@users.sourceforge.net>
-
-Portions may be copyright others, see the AUTHORS file included with this
-distribution.
-
-Maintained by Peter O'Gorman <ogorman@users.sourceforge.net>
-
-Bug Reports and other queries should go to <ogorman@users.sourceforge.net>
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#ifndef _DLFCN_H_
-#define _DLFCN_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined (__GNUC__) && __GNUC__ > 3
-#define dl_restrict __restrict
-#else
-#define dl_restrict
-#endif
-/*
- * Structure filled in by dladdr().
- */
-
-typedef struct dl_info {
- const char *dli_fname; /* Pathname of shared object */
- void *dli_fbase; /* Base address of shared object */
- const char *dli_sname; /* Name of nearest symbol */
- void *dli_saddr; /* Address of nearest symbol */
-} Dl_info;
-
-extern void * dlopen(const char *path, int mode);
-extern void * dlsym(void * dl_restrict handle, const char * dl_restrict symbol);
-extern const char * dlerror(void);
-extern int dlclose(void * handle);
-extern int dladdr(const void * dl_restrict, Dl_info * dl_restrict);
-
-#define RTLD_LAZY 0x1
-#define RTLD_NOW 0x2
-#define RTLD_LOCAL 0x4
-#define RTLD_GLOBAL 0x8
-#define RTLD_NOLOAD 0x10
-#define RTLD_NODELETE 0x80
-
-/*
- * Special handle arguments for dlsym().
- */
-#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */
-#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _DLFCN_H_ */
diff --git a/1.2-netsec/include/asterisk/dns.h b/1.2-netsec/include/asterisk/dns.h
deleted file mode 100644
index 18ebaf585..000000000
--- a/1.2-netsec/include/asterisk/dns.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Written by Thorsten Lockert <tholo@trollphone.org>
- *
- * Funding provided by Troll Phone Networks AS
- *
- * 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 DNS support for Asterisk
- * \author Thorsten Lockert <tholo@trollphone.org>
- */
-
-#ifndef _ASTERISK_DNS_H
-#define _ASTERISK_DNS_H
-
-struct ast_channel;
-
-/*! \brief Perform DNS lookup (used by enum and SRV lookups)
- \param context
- \param dname Domain name to lookup (host, SRV domain, TXT record name)
- \param class Record Class (see "man res_search")
- \param type Record type (see "man res_search")
- \param callback Callback function for handling DNS result
-*/
-extern int ast_search_dns(void *context, const char *dname, int class, int type,
- int (*callback)(void *context, char *answer, int len, char *fullanswer));
-
-#endif /* _ASTERISK_DNS_H */
diff --git a/1.2-netsec/include/asterisk/dnsmgr.h b/1.2-netsec/include/asterisk/dnsmgr.h
deleted file mode 100644
index b5cc2a7ed..000000000
--- a/1.2-netsec/include/asterisk/dnsmgr.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Kevin P. Fleming <kpfleming@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Background DNS update manager
- */
-
-#ifndef _ASTERISK_DNSMGR_H
-#define _ASTERISK_DNSMGR_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#include <netinet/in.h>
-
-struct ast_dnsmgr_entry;
-
-struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct in_addr *result);
-
-void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry);
-
-int ast_dnsmgr_lookup(const char *name, struct in_addr *result, struct ast_dnsmgr_entry **dnsmgr);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif /* c_plusplus */
-
-#endif /* ASTERISK_DNSMGR_H */
diff --git a/1.2-netsec/include/asterisk/doxyref.h b/1.2-netsec/include/asterisk/doxyref.h
deleted file mode 100644
index 507e112b3..000000000
--- a/1.2-netsec/include/asterisk/doxyref.h
+++ /dev/null
@@ -1,449 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/* \file This file generates Doxygen pages from files in the /doc
- directory of the Asterisk source code tree
- */
-
-/* The following is for Doxygen Developer's documentation generated
- * by running "make progdocs" with doxygen installed on your
- * system.
- */
-/*! \page DevDoc Asterisk Developer's Documentation - appendices
- * \arg \ref CodeGuide : The must-read document for all developer's
- * \arg \ref AstAPI
- * \arg \ref Def_Channel : What's a channel, anyway?
- * \arg \ref channel_drivers : Existing channel drivers
- * \arg \ref AstDebug : Hints on debugging
- * \arg \ref AstAMI : The Call management socket API
- * \arg \ref AstARA : A generic data storage and retrieval API for Asterisk
- * \arg \ref AstDUNDi : A way to find phone services dynamically by using the DUNDi protocol
- * \arg \ref AstCDR
- * \arg \ref AstREADME
- * \arg \ref AstVar
- * \arg \ref AstENUM : The IETF way to redirect from phone numbers to VoIP calls
- * \arg \ref ConfigFiles
- * \arg \ref SoundFiles included in the Asterisk distribution
- * \arg \ref AstCREDITS : A Thank You to contributors
- \n\n
- * \section weblinks Web sites
- * \arg \b Main: Asterisk Developer's website http://www.asterisk.org/developers/
- * \arg \b Bugs: The Issue tracker http://bugs.digium.com
- * \arg \b Lists: List server http://lists.digium.com
- * \arg \b Wiki: The Asterisk Wiki http://www.voip-info.org
- * \arg \b Docs: The Asterisk Documentation Project http://www.asteriskdocs.org
- * \arg \b Digium: The Asterisk company http://www.digium.com
- *
- */
-
-/*! \page CodeGuide Coding Guidelines
- * \section Coding Guidelines
- * This file is in the /doc directory in your Asterisk source tree.
- * Make sure to stay up to date with the latest guidelines.
- * \verbinclude CODING-GUIDELINES
- */
-
-/*! \page AstAPI Asterisk API
- * \section Asteriskapi Asterisk API
- * Some generic documents on the Asterisk architecture
- * \subsection model_txt Generic Model
- * \verbinclude model.txt
- * \subsection channel_txt Channels
- * \arg See \link Def_Channel
- * \verbinclude channel.txt
- */
-
-/*! \page AstDebug Debugging
- * \section debug Debugging
- * \verbinclude README.backtrace
- */
-
-/*! \page AstAMI AMI - The Manager Interface
- * \section ami AMI - The manager Interface
- * \arg \link Config_ami Configuration file \endlink
- * \arg \ref manager.c
- * \verbinclude manager.txt
- */
-
-/*! \page AstARA ARA - The Asterisk Realtime Interface
- * \section realtime ARA - a generic API to storage and retrieval
- * Implemented in \ref config.c
- * Implemented in \ref pbx_realtime.c
- * \verbinclude README.realtime
- * \verbinclude README.extconfig
- */
-
-/*! \page AstDUNDi DUNDi
-DUNDi is a peer-to-peer system for locating Internet gateways to telephony services. Unlike traditional centralized services (such as the remarkably simple and concise ENUM standard), DUNDi is fully-distributed with no centralized authority whatsoever.
-
-DUNDi is not itself a Voice-over IP signaling or media protocol. Instead, it publishes routes which are in turn accessed via industry standard protocols such as IAX, SIP and H.323.
-
- \par References
- \arg DUNDi is documented at http://www.dundi.com
- \arg Implemented in \ref pbx_dundi.c and \ref dundi-parser.c
- \arg Configuration in \link Config_dun dundi.conf \endlink
- */
-
-/*! \page AstCDR CDR - Call Data Records and billing
- * \section cdr Call Data Records
- * \par See also
- * \arg \ref cdr.c
- * \arg \ref cdr_drivers
- * \arg \ref Config_cdr CDR configuration files
- *
- * \verbinclude README.cdr
- */
-
-/*! \page AstREADME README - the general administrator introduction
- * \verbinclude README
- */
-
-/*! \page AstCREDITS CREDITS
- * \verbinclude CREDITS
- */
-
-/*! \page AstVar Global channel variables
- * \section globchan Global Channel Variables
- * \verbinclude README.variables
- */
-
-/*! \page AstENUM ENUM
- * \section enumreadme ENUM
- * \arg Configuration: \ref Config_enum
- * \arg \ref enum.c
- * \arg \ref app_enumlookup.c
- *
- * \verbinclude README.enum
- */
-
-/*! \page ConfigFiles Configuration files
- * \section config Main configuration files
- * \arg \link Config_ast asterisk.conf - the main configuration file \endlink
- * \arg \link Config_ext extensions.conf - The Dial Plan \endlink
- * \arg \link Config_mod modules.conf - which modules to load and not to load \endlink
- * \arg \link Config_fea features.conf - call features (transfer, parking, etc) \endlink
- * \section chanconf Channel configuration files
- * \arg \link Config_iax IAX2 configuration \endlink
- * \arg \link Config_sip SIP configuration \endlink
- * \arg \link Config_mgcp MGCP configuration \endlink
- * \arg \link Config_rtp RTP configuration \endlink
- * \arg \link Config_zap Zaptel configuration \endlink
- * \arg \link Config_oss OSS (sound card) configuration \endlink
- * \arg \link Config_alsa ALSA (sound card) configuration \endlink
- * \arg \link Config_agent Agent (proxy channel) configuration \endlink
- * \arg \link Config_misdn MISDN Experimental ISDN BRI channel configuration \endlink
- * \arg \link Config_h323 H.323 configuration \endlink
- * \section appconf Application configuration files
- * \arg \link Config_mm Meetme (conference bridge) configuration \endlink
- * \arg \link Config_qu Queue system configuration \endlink
- * \arg \link Config_vm Voicemail configuration \endlink
- * \section cdrconf CDR configuration files
- * \arg \link Config_cdr CDR configuration \endlink
- * \arg \link cdr_custom Custom CDR driver configuration \endlink
- * \arg \link cdr_ami Manager CDR driver configuration \endlink
- * \arg \link cdr_odbc ODBC CDR driver configuration \endlink
- * \arg \link cdr_pgsql PostgreSQL CDR driver configuration \endlink
- * \arg \link cdr_sqlite SQLite CDR driver configuration \endlink
- * \arg \link cdr_tds FreeTDS CDR driver configuration (Microsoft SQL Server) \endlink
- * \section miscconf Miscellenaous configuration files
- * \arg \link Config_adsi ADSI configuration \endlink
- * \arg \link Config_ami AMI - Manager configuration \endlink
- * \arg \link Config_ara Realtime configuration \endlink
- * \arg \link Config_codec Codec configuration \endlink
- * \arg \link Config_dun DUNDi configuration \endlink
- * \arg \link Config_enum ENUM configuration \endlink
- * \arg \link Config_moh Music on Hold configuration \endlink
- * \arg \link Config_vm Voicemail configuration \endlink
- */
-
-/*! \page Config_ast Asterisk.conf
- * \verbinclude README.asterisk.conf
- */
-/*! \page Config_mod Modules configuration
- * All res_ resource modules are loaded with globals on, which means
- * that non-static functions are callable from other modules.
- *
- * If you want your non res_* module to export functions to other modules
- * you have to include it in the [global] section.
- * \verbinclude modules.conf.sample
- */
-
-/*! \page Config_fea Call features configuration
- * \par See also
- * \arg \ref res_features.c : Call feature implementation
- * \section featconf features.conf
- * \verbinclude features.conf.sample
- */
-
-/*! \page Config_ext Extensions.conf - the Dial Plan
- * \section dialplan Extensions.conf
- * \verbinclude extensions.conf.sample
- */
-
-/*! \page Config_iax IAX2 configuration
- * IAX2 is implemented in \ref chan_iax2.c
- * \arg \link Config_iax iax.conf Configuration file example \endlink
- * \section iaxreadme IAX readme file
- * \verbinclude README.iax
- * \section Config_iax IAX Configuration example
- * \verbinclude iax.conf.sample
- * \section iaxjitter IAX Jitterbuffer information
- * \verbinclude README.jitterbuffer
- */
-
-/*! \page Config_iax IAX configuration
- * \arg Implemented in \ref chan_iax2.c
- * \section iaxconf iax.conf
- * \verbinclude iax.conf.sample
- */
-
-/*! \page Config_sip SIP configuration
- * Also see \ref Config_rtp RTP configuration
- * \arg Implemented in \ref chan_sip.c
- * \section sipconf sip.conf
- * \verbinclude sip.conf.sample
- *
- * \arg \b Back \ref chanconf
- */
-
-/*! \page Config_mgcp MGCP configuration
- * Also see \ref Config_rtp RTP configuration
- * \arg Implemented in \ref chan_mgcp.c
- * \section mgcpconf mgcp.conf
- * \verbinclude mgcp.conf.sample
- */
-
-/*! \page Config_misdn MISDN configuration
- * \arg Implemented in \ref chan_misdn.c
- * \section misdnconf misdn.conf
- * \verbinclude misdn.conf.sample
- */
-
-/*! \page Config_vm VoiceMail configuration
- * \section vmconf voicemail.conf
- * \arg Implemented in \ref app_voicemail.c
- * \verbinclude voicemail.conf.sample
- */
-
-/*! \page Config_zap Zaptel configuration
- * \section zapconf zapata.conf
- * \arg Implemented in \ref chan_zap.c
- * \verbinclude zapata.conf.sample
- */
-
-/*! \page Config_h323 H.323 channel driver information
- * This is the configuration of the H.323 channel driver within the Asterisk
- * distribution. There's another one, called OH323, in asterisk-addons
- * \arg Implemented in \ref chan_h323.c
- * \section h323conf h323.conf
- * \ref chan_h323.c
- * \verbinclude README.h323
- */
-
-/*! \page Config_oss OSS configuration
- * \section ossconf oss.conf
- * \arg Implemented in \ref chan_oss.c
- * \verbinclude oss.conf.sample
- */
-
-/*! \page Config_alsa ALSA configuration
- * \section alsaconf alsa.conf
- * \arg Implemented in \ref chan_alsa.c
- * \verbinclude alsa.conf.sample
- */
-
-/*! \page Config_agent Agent configuration
- * \section agentconf agents.conf
- * The agent channel is a proxy channel for queues
- * \arg Implemented in \ref chan_agent.c
- * \verbinclude agents.conf.sample
- */
-
-/*! \page Config_rtp RTP configuration
- * \arg Implemented in \ref rtp.c
- * Used in \ref chan_sip.c and \ref chan_mgcp.c (and various H.323 channels)
- * \section rtpconf rtp.conf
- * \verbinclude rtp.conf.sample
- */
-
-/*! \page Config_dun DUNDi Configuration
- * \arg See also \ref AstDUNDi
- * \section dundiconf dundi.conf
- * \verbinclude dundi.conf.sample
- */
-
-/*! \page Config_enum ENUM Configuration
- * \section enumconf enum.conf
- * \arg See also \ref enumreadme
- * \arg Implemented in \ref app_enumlookup.c and \ref enum.c
- * \verbinclude enum.conf.sample
- */
-
-/*! \page cdr_custom Custom CDR Configuration
- * \par See also
- * \arg \ref cdrconf
- * \arg \ref cdr_custom.c
- * \verbinclude cdr_custom.conf.sample
- */
-
-/*! \page cdr_ami Manager CDR driver configuration
- * \par See also
- * \arg \ref cdrconf
- * \arg \ref AstAMI
- * \arg \ref cdr_manager.c
- * \verbinclude cdr_manager.conf.sample
- */
-
-/*! \page cdr_odbc ODBC CDR driver configuration
- * \arg See also \ref cdrconf
- * \arg \ref cdr_odbc.c
- * \verbinclude cdr_odbc.conf.sample
- * See also:
- * \arg http://www.unixodbc.org
- */
-
-/*! \page cdr_pgsql PostgreSQL CDR driver configuration
- * \arg See also \ref cdrconf
- * \arg \ref cdr_pgsql.c
- * See also:
- * \arg http://www.postgresql.org
- * \verbinclude cdr_pgsql.conf.sample
- */
-
-/*! \page cdr_sqlite SQLite CDR driver configuration
- * \arg See also \ref cdrconf
- * \arg \ref cdr_sqlite.c
- * See also:
- * \arg http://www.sqlite.org
- */
-
-/*! \page cdr_tds FreeTDS CDR driver configuration
- * \arg See also \ref cdrconf
- * See also:
- * \arg http://www.freetds.org
- * \verbinclude cdr_tds.conf.sample
- */
-
-/*! \page Config_cdr CDR configuration
- * \par See also
- * \arg \ref cdr_drivers
- * \arg \link Config_cdr CDR configuration \endlink
- * \arg \link cdr_custom Custom CDR driver configuration \endlink
- * \arg \link cdr_ami Manager CDR driver configuration \endlink
- * \arg \link cdr_odbc ODBC CDR driver configuration \endlink
- * \arg \link cdr_pgsql PostgreSQL CDR driver configuration \endlink
- * \arg \link cdr_sqlite SQLite CDR driver configuration \endlink
- * \arg \link cdr_tds FreeTDS CDR driver configuration (Microsoft SQL Server) \endlink
- * \verbinclude cdr.conf.sample
- */
-
-/*! \page Config_moh Music on Hold Configuration
- * \arg Implemented in \ref res_musiconhold.c
- * \section mohconf musiconhold.conf
- * \verbinclude musiconhold.conf.sample
- */
-
-/*! \page Config_adsi ADSI Configuration
- * \section adsiconf adsi.conf
- * \verbinclude adsi.conf.sample
- */
-
-/*! \page Config_codec CODEC Configuration
- * \section codecsconf codecs.conf
- * \verbinclude codecs.conf.sample
- */
-
-/*! \page Config_ara REALTIME Configuration
- * \arg See also: \arg \link AstARA \endlink
- * \section extconf extconfig.conf
- * \verbinclude extconfig.conf.sample
- */
-
-/*! \page Config_ami AMI configuration
- * \arg See also: \arg \link AstAMI \endlink
- * \section amiconf manager.conf
- * \verbinclude manager.conf.sample
- */
-
-/*! \page Config_qu ACD - Queue system configuration
- * \arg Implemented in \ref app_queue.c
- * \section quconf queues.conf
- * \verbinclude queues.conf.sample
- */
-
-/*! \page Config_mm Meetme - The conference bridge configuration
- * \arg Implemented in \ref app_meetme.c
- * \section mmconf meetme.conf
- * \verbinclude meetme.conf.sample
- */
-
-/*! \page SoundFiles Sound files
- * \section SecSound Asterisk Sound files
- * Asterisk includes a large amount of sound files. Many of these
- * are used by applications and demo scripts within asterisk.
- *
- * Additional sound files are available in the asterisk-addons
- * repository on cvs.digium.com
- *
- * \section SoundList List of included sound files
- * \verbinclude sounds.txt
- */
-
-/*! \addtogroup cdr_drivers Module: CDR Drivers
- * \section CDR_generic Asterisk CDR Drivers
- * \brief CDR drivers are loaded dynamically (see \ref Config_mod "Modules Configuration"). Each loaded CDR driver produce a billing record for each call.
- * \arg \ref Config_cdr "CDR Configuration"
- */
-
-
-/*! \addtogroup channel_drivers Module: Asterisk Channel Drivers
- * \section channel_generic Asterisk Channel Drivers
- * \brief Channel drivers are loaded dynamically (see \ref Config_mod "Modules Configuration").
- */
-
-/*! \addtogroup applications Module: Dial plan applications
- * \section app_generic Asterisk Dial Plan Applications
- * \brief Applications support the dialplan. They register dynamically with \ref ast_register_application() and unregister with ast_unregister_application()
- * \par See also
- * \arg \ref functions
- *
- */
-
-/*! \addtogroup functions Module: Dial plan functions
- * \section func_generic Asterisk Dial Plan Functions
- * \brief Functions support the dialplan. They do not change any property of a channel
- * or touch a channel in any way.
- * \par See also
- * \arg \ref applications
- *
- */
-
-/*! \addtogroup codecs Module: Codecs
- * \section codec_generic Asterisk Codec Modules
- * Codecs are referenced in configuration files by name
- * \par See also
- * \arg \ref formats
- *
- */
-
-/*! \addtogroup formats Module: Media File Formats
- * \section codec_generic Asterisk Format drivers
- * Formats are modules that read or write media files to disk.
- * \par See also
- * \arg \ref codecs
- */
diff --git a/1.2-netsec/include/asterisk/dsp.h b/1.2-netsec/include/asterisk/dsp.h
deleted file mode 100644
index b34701f30..000000000
--- a/1.2-netsec/include/asterisk/dsp.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Convenient Signal Processing routines
- */
-
-#ifndef _ASTERISK_DSP_H
-#define _ASTERISK_DSP_H
-
-#define DSP_FEATURE_SILENCE_SUPPRESS (1 << 0)
-#define DSP_FEATURE_BUSY_DETECT (1 << 1)
-#define DSP_FEATURE_DTMF_DETECT (1 << 3)
-#define DSP_FEATURE_FAX_DETECT (1 << 4)
-
-#define DSP_DIGITMODE_DTMF 0 /* Detect DTMF digits */
-#define DSP_DIGITMODE_MF 1 /* Detect MF digits */
-
-#define DSP_DIGITMODE_NOQUELCH (1 << 8) /* Do not quelch DTMF from in-band */
-#define DSP_DIGITMODE_MUTECONF (1 << 9) /* Mute conference */
-#define DSP_DIGITMODE_MUTEMAX (1 << 10) /* Delay audio by a frame to try to extra quelch */
-#define DSP_DIGITMODE_RELAXDTMF (1 << 11) /* "Radio" mode (relaxed DTMF) */
-
-#define DSP_PROGRESS_TALK (1 << 16) /* Enable talk detection */
-#define DSP_PROGRESS_RINGING (1 << 17) /* Enable calling tone detection */
-#define DSP_PROGRESS_BUSY (1 << 18) /* Enable busy tone detection */
-#define DSP_PROGRESS_CONGESTION (1 << 19) /* Enable congestion tone detection */
-#define DSP_FEATURE_CALL_PROGRESS (DSP_PROGRESS_TALK | DSP_PROGRESS_RINGING | DSP_PROGRESS_BUSY | DSP_PROGRESS_CONGESTION)
-
-#define DSP_TONE_STATE_SILENCE 0
-#define DSP_TONE_STATE_RINGING 1
-#define DSP_TONE_STATE_DIALTONE 2
-#define DSP_TONE_STATE_TALKING 3
-#define DSP_TONE_STATE_BUSY 4
-#define DSP_TONE_STATE_SPECIAL1 5
-#define DSP_TONE_STATE_SPECIAL2 6
-#define DSP_TONE_STATE_SPECIAL3 7
-#define DSP_TONE_STATE_HUNGUP 8
-
-struct ast_dsp;
-
-struct ast_dsp *ast_dsp_new(void);
-void ast_dsp_free(struct ast_dsp *dsp);
-
-/*! \brief Set threshold value for silence */
-void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold);
-
-/*! \brief Set number of required cadences for busy */
-void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences);
-
-/*! \brief Set expected lengths of the busy tone */
-void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, int tonelength, int quietlength);
-
-/*! \brief Scans for progress indication in audio */
-int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf);
-
-/*! \brief Set zone for doing progress detection */
-int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone);
-
-/*! \brief Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on
- busies, and call progress, all dependent upon which features are enabled */
-struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf);
-
-/*! \brief Return non-zero if this is silence. Updates "totalsilence" with the total
- number of seconds of silence */
-int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence);
-
-/*! \brief Return non-zero if historically this should be a busy, request that
- ast_dsp_silence has already been called */
-int ast_dsp_busydetect(struct ast_dsp *dsp);
-
-/*! \brief Return non-zero if DTMF hit was found */
-int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *f);
-
-/*! \brief Reset total silence count */
-void ast_dsp_reset(struct ast_dsp *dsp);
-
-/*! \brief Reset DTMF detector */
-void ast_dsp_digitreset(struct ast_dsp *dsp);
-
-/*! \brief Select feature set */
-void ast_dsp_set_features(struct ast_dsp *dsp, int features);
-
-/*! \brief Get pending DTMF/MF digits */
-int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max);
-
-/*! \brief Set digit mode */
-int ast_dsp_digitmode(struct ast_dsp *dsp, int digitmode);
-
-/*! \brief Get tstate (Tone State) */
-int ast_dsp_get_tstate(struct ast_dsp *dsp);
-
-/*! \brief Get tcount (Threshold counter) */
-int ast_dsp_get_tcount(struct ast_dsp *dsp);
-
-#endif /* _ASTERISK_DSP_H */
diff --git a/1.2-netsec/include/asterisk/dundi.h b/1.2-netsec/include/asterisk/dundi.h
deleted file mode 100644
index 9290536d6..000000000
--- a/1.2-netsec/include/asterisk/dundi.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Distributed Universal Number Discovery (DUNDi)
- * See also \ref AstDUNDi
- */
-
-#ifndef _ASTERISK_DUNDI_H
-#define _ASTERISK_DUNDI_H
-
-#include "asterisk/channel.h"
-
-#define DUNDI_PORT 4520
-
-/*!\brief A DUNDi Entity ID is essentially a MAC address, brief and unique */
-struct _dundi_eid {
- unsigned char eid[6];
-} __attribute__ ((__packed__));
-
-typedef struct _dundi_eid dundi_eid;
-
-struct dundi_hdr {
- unsigned short strans; /*!< Source transaction */
- unsigned short dtrans; /*!< Destination transaction */
- unsigned char iseqno; /*!< Next expected incoming sequence number */
- unsigned char oseqno; /*!< Outgoing sequence number */
- unsigned char cmdresp; /*!< Command / Response */
- unsigned char cmdflags; /*!< Command / Response specific flags*/
- unsigned char ies[0];
-} __attribute__ ((__packed__));
-
-struct dundi_ie_hdr {
- unsigned char ie;
- unsigned char len;
- unsigned char iedata[0];
-} __attribute__ ((__packed__));
-
-#define DUNDI_FLAG_RETRANS (1 << 16) /*!< Applies to dtrans */
-#define DUNDI_FLAG_RESERVED (1 << 16) /*!< Applies to strans */
-
-#define DUNDI_PROTO_NONE 0 /*!< No answer yet */
-#define DUNDI_PROTO_IAX 1 /*!< IAX version 2 */
-#define DUNDI_PROTO_SIP 2 /*!< Session Initiation Protocol */
-#define DUNDI_PROTO_H323 3 /*!< ITU H.323 */
-
-#define DUNDI_FLAG_NONEXISTENT (0) /*!< Isn't and can't be a valid number */
-#define DUNDI_FLAG_EXISTS (1 << 0) /*!< Is a valid number */
-#define DUNDI_FLAG_MATCHMORE (1 << 1) /*!< Might be valid if you add more digits */
-#define DUNDI_FLAG_CANMATCH (1 << 2) /*!< Might be a match */
-#define DUNDI_FLAG_IGNOREPAT (1 << 3) /*!< Keep dialtone */
-#define DUNDI_FLAG_RESIDENTIAL (1 << 4) /*!< Destination known to be residential */
-#define DUNDI_FLAG_COMMERCIAL (1 << 5) /*!< Destination known to be commercial */
-#define DUNDI_FLAG_MOBILE (1 << 6) /*!< Destination known to be cellular/mobile */
-#define DUNDI_FLAG_NOUNSOLICITED (1 << 7) /*!< No unsolicited calls of any kind through this route */
-#define DUNDI_FLAG_NOCOMUNSOLICIT (1 << 8) /*!< No commercial unsolicited calls through this route */
-
-#define DUNDI_HINT_NONE (0)
-#define DUNDI_HINT_TTL_EXPIRED (1 << 0) /*!< TTL Expired */
-#define DUNDI_HINT_DONT_ASK (1 << 1) /*!< Don't ask for anything beginning with data */
-#define DUNDI_HINT_UNAFFECTED (1 << 2) /*!< Answer not affected by entity list */
-
-struct dundi_encblock { /*!< AES-128 encrypted block */
- unsigned char iv[16]; /*!< Initialization vector of random data */
- unsigned char encdata[0]; /*!< Encrypted / compressed data */
-} __attribute__ ((__packed__));
-
-struct dundi_answer {
- dundi_eid eid; /*!< Original source of answer */
- unsigned char protocol; /*!< Protocol (DUNDI_PROTO_*) */
- unsigned short flags; /*!< Flags relating to answer */
- unsigned short weight; /*!< Weight of answers */
- unsigned char data[0]; /*!< Protocol specific URI */
-} __attribute__ ((__packed__));
-
-struct dundi_hint {
- unsigned short flags; /*!< Flags relating to answer */
- unsigned char data[0]; /*!< For data for hint */
-} __attribute__ ((__packed__));
-
-#define DUNDI_CAUSE_SUCCESS 0 /*!< Success */
-#define DUNDI_CAUSE_GENERAL 1 /*!< General unspecified failure */
-#define DUNDI_CAUSE_DYNAMIC 2 /*!< Requested entity is dynamic */
-#define DUNDI_CAUSE_NOAUTH 3 /*!< No or improper authorization */
-#define DUNDI_CAUSE_DUPLICATE 4 /*!< Duplicate request */
-#define DUNDI_CAUSE_TTL_EXPIRED 5 /*!< Expired TTL */
-#define DUNDI_CAUSE_NEEDKEY 6 /*!< Need new session key to decode */
-#define DUNDI_CAUSE_BADENCRYPT 7 /*!< Badly encrypted data */
-
-struct dundi_cause {
- unsigned char causecode; /*!< Numerical cause (DUNDI_CAUSE_*) */
- char desc[0]; /*!< Textual description */
-} __attribute__ ((__packed__));
-
-struct dundi_peer_status {
- unsigned int flags;
- unsigned short netlag;
- unsigned short querylag;
- dundi_eid peereid;
-} __attribute__ ((__packed__));
-
-#define DUNDI_PEER_PRIMARY (1 << 0)
-#define DUNDI_PEER_SECONDARY (1 << 1)
-#define DUNDI_PEER_UNAVAILABLE (1 << 2)
-#define DUNDI_PEER_REGISTERED (1 << 3)
-#define DUNDI_PEER_MOD_OUTBOUND (1 << 4)
-#define DUNDI_PEER_MOD_INBOUND (1 << 5)
-#define DUNDI_PEER_PCMOD_OUTBOUND (1 << 6)
-#define DUNDI_PEER_PCMOD_INBOUND (1 << 7)
-
-#define DUNDI_COMMAND_FINAL (0x80) /*!< Or'd with other flags */
-
-#define DUNDI_COMMAND_ACK (0 | 0x40) /*!< Ack a message */
-#define DUNDI_COMMAND_DPDISCOVER 1 /*!< Request discovery */
-#define DUNDI_COMMAND_DPRESPONSE (2 | 0x40) /*!< Respond to a discovery request */
-#define DUNDI_COMMAND_EIDQUERY 3 /*!< Request information for a peer */
-#define DUNDI_COMMAND_EIDRESPONSE (4 | 0x40) /*!< Response to a peer query */
-#define DUNDI_COMMAND_PRECACHERQ 5 /*!< Pre-cache Request */
-#define DUNDI_COMMAND_PRECACHERP (6 | 0x40) /*!< Pre-cache Response */
-#define DUNDI_COMMAND_INVALID (7 | 0x40) /*!< Invalid dialog state (does not require ack) */
-#define DUNDI_COMMAND_UNKNOWN (8 | 0x40) /*!< Unknown command */
-#define DUNDI_COMMAND_NULL 9 /*!< No-op */
-#define DUNDI_COMMAND_REGREQ (10) /*!< Register Request */
-#define DUNDI_COMMAND_REGRESPONSE (11 | 0x40) /*!< Register Response */
-#define DUNDI_COMMAND_CANCEL (12) /*!< Cancel transaction entirely */
-#define DUNDI_COMMAND_ENCRYPT (13) /*!< Send an encrypted message */
-#define DUNDI_COMMAND_ENCREJ (14 | 0x40) /*!< Reject an encrypted message */
-
-#define DUNDI_COMMAND_STATUS 15 /*!< Status command */
-
-/*
- * Remember that some information elements may occur
- * more than one time within a message
- */
-
-#define DUNDI_IE_EID 1 /*!< Entity identifier (dundi_eid) */
-#define DUNDI_IE_CALLED_CONTEXT 2 /*!< DUNDi Context (string) */
-#define DUNDI_IE_CALLED_NUMBER 3 /*!< Number of equivalent (string) */
-#define DUNDI_IE_EID_DIRECT 4 /*!< Entity identifier (dundi_eid), direct connect */
-#define DUNDI_IE_ANSWER 5 /*!< An answer (struct dundi_answer) */
-#define DUNDI_IE_TTL 6 /*!< Max TTL for this request / Remaining TTL for the response (short)*/
-#define DUNDI_IE_VERSION 10 /*!< DUNDi version (should be 1) (short) */
-#define DUNDI_IE_EXPIRATION 11 /*!< Recommended expiration (short) */
-#define DUNDI_IE_UNKNOWN 12 /*!< Unknown command (byte) */
-#define DUNDI_IE_CAUSE 14 /*!< Success or cause of failure */
-#define DUNDI_IE_REQEID 15 /*!< EID being requested for EIDQUERY*/
-#define DUNDI_IE_ENCDATA 16 /*!< AES-128 encrypted data */
-#define DUNDI_IE_SHAREDKEY 17 /*!< RSA encrypted AES-128 key */
-#define DUNDI_IE_SIGNATURE 18 /*!< RSA Signature of encrypted shared key */
-#define DUNDI_IE_KEYCRC32 19 /*!< CRC32 of encrypted key (int) */
-#define DUNDI_IE_HINT 20 /*!< Answer hints (struct ast_hint) */
-
-#define DUNDI_IE_DEPARTMENT 21 /*!< Department, for EIDQUERY (string) */
-#define DUNDI_IE_ORGANIZATION 22 /*!< Organization, for EIDQUERY (string) */
-#define DUNDI_IE_LOCALITY 23 /*!< City/Locality, for EIDQUERY (string) */
-#define DUNDI_IE_STATE_PROV 24 /*!< State/Province, for EIDQUERY (string) */
-#define DUNDI_IE_COUNTRY 25 /*!< Country, for EIDQUERY (string) */
-#define DUNDI_IE_EMAIL 26 /*!< E-mail addy, for EIDQUERY (string) */
-#define DUNDI_IE_PHONE 27 /*!< Contact Phone, for EIDQUERY (string) */
-#define DUNDI_IE_IPADDR 28 /*!< IP Address, for EIDQUERY (string) */
-#define DUNDI_IE_CACHEBYPASS 29 /*!< Bypass cache (empty) */
-
-#define DUNDI_IE_PEERSTATUS 30 /*!< Peer/peer status (struct dundi_peer_status) */
-
-#define DUNDI_FLUFF_TIME 2000 /*!< Amount of time for answer */
-#define DUNDI_TTL_TIME 200 /*!< Incremental average time */
-
-#define DUNDI_DEFAULT_RETRANS 5
-#define DUNDI_DEFAULT_RETRANS_TIMER 1000
-#define DUNDI_DEFAULT_TTL 120 /*!< In seconds/hops like TTL */
-#define DUNDI_DEFAULT_VERSION 1
-#define DUNDI_DEFAULT_CACHE_TIME 3600 /*!< In seconds */
-#define DUNDI_DEFAULT_KEY_EXPIRE 3600 /*!< Life of shared key In seconds */
-#define DUNDI_DEF_EMPTY_CACHE_TIME 60 /*!< In seconds, cache of empty answer */
-#define DUNDI_WINDOW 1 /*!< Max 1 message in window */
-
-#define DEFAULT_MAXMS 2000
-
-struct dundi_result {
- unsigned int flags;
- int weight;
- int expiration;
- int techint;
- dundi_eid eid;
- char eid_str[20];
- char tech[10];
- char dest[256];
-};
-
-struct dundi_entity_info {
- char country[80];
- char stateprov[80];
- char locality[80];
- char org[80];
- char orgunit[80];
- char email[80];
- char phone[80];
- char ipaddr[80];
-};
-
-/*! \brief Lookup the given number in the given dundi context (or e164 if unspecified) using the given callerid (if specified) and return up to maxret results in the array specified.
- returns the number of results found or -1 on a hangup of teh channel. */
-int dundi_lookup(struct dundi_result *result, int maxret, struct ast_channel *chan, const char *dcontext, const char *number, int nocache);
-
-/*! \brief Retrieve information on a specific EID */
-int dundi_query_eid(struct dundi_entity_info *dei, const char *dcontext, dundi_eid eid);
-
-/*! \brief Pre-cache to push upstream peers */
-int dundi_precache(const char *dcontext, const char *number);
-
-#endif /* _ASTERISK_DUNDI_H */
diff --git a/1.2-netsec/include/asterisk/endian.h b/1.2-netsec/include/asterisk/endian.h
deleted file mode 100644
index 55108b4e1..000000000
--- a/1.2-netsec/include/asterisk/endian.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Asterisk architecture endianess compatibility definitions
- */
-
-#ifndef _ASTERISK_ENDIAN_H
-#define _ASTERISK_ENDIAN_H
-
-/*
- * Autodetect system endianess
- */
-
-#include "asterisk/compat.h"
-
-#ifndef __BYTE_ORDER
-#ifdef __linux__
-#include <endian.h>
-#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
-#if defined(__OpenBSD__)
-#include <machine/types.h>
-#endif /* __OpenBSD__ */
-#include <machine/endian.h>
-#define __BYTE_ORDER BYTE_ORDER
-#define __LITTLE_ENDIAN LITTLE_ENDIAN
-#define __BIG_ENDIAN BIG_ENDIAN
-#else
-#ifdef __LITTLE_ENDIAN__
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#endif /* __LITTLE_ENDIAN */
-
-#if defined(i386) || defined(__i386__)
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#endif /* defined i386 */
-
-#if defined(sun) && defined(unix) && defined(sparc)
-#define __BYTE_ORDER __BIG_ENDIAN
-#endif /* sun unix sparc */
-
-#endif /* linux */
-
-#endif /* __BYTE_ORDER */
-
-#ifndef __BYTE_ORDER
-#error Need to know endianess
-#endif /* __BYTE_ORDER */
-
-#endif /* _ASTERISK_ENDIAN_H */
-
diff --git a/1.2-netsec/include/asterisk/enum.h b/1.2-netsec/include/asterisk/enum.h
deleted file mode 100644
index e36a9d910..000000000
--- a/1.2-netsec/include/asterisk/enum.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file enum.h
- \brief DNS and ENUM functions
-*/
-
-#ifndef _ASTERISK_ENUM_H
-#define _ASTERISK_ENUM_H
-
-#include "asterisk/channel.h"
-
-/*! \brief Lookup entry in ENUM Returns 1 if found, 0 if not found, -1 on hangup
- \param chan Channel
- \param number E164 number with or without the leading +
- \param location Number returned (or SIP uri)
- \param maxloc Max length
- \param technology Technology (from url scheme in response)
- You can set it to get particular answer RR, if there are many techs in DNS response, example: "sip"
- If you need any record, then set it to empty string
- \param maxtech Max length
- \param suffix Zone suffix (if is NULL then use enum.conf 'search' variable)
- \param options Options ('c' to count number of NAPTR RR, or number - the position of required RR in the answer list
-*/
-extern int ast_get_enum(struct ast_channel *chan, const char *number, char *location, int maxloc, char *technology, int maxtech, char* suffix, char* options);
-
-/*! \brief Lookup DNS TXT record (used by app TXTCIDnum
- \param chan Channel
- \param number E164 number with or without the leading +
- \param location Number returned (or SIP uri)
- \param maxloc Max length of number
- \param technology Technology (not used in TXT records)
- \param maxtech Max length
- \param txt Text string (return value)
- \param maxtxt Max length of "txt"
-*/
-extern int ast_get_txt(struct ast_channel *chan, const char *number, char *location, int maxloc, char *technology, int maxtech, char *txt, int maxtxt);
-
-extern int ast_enum_init(void);
-extern int ast_enum_reload(void);
-
-#endif /* _ASTERISK_ENUM_H */
diff --git a/1.2-netsec/include/asterisk/features.h b/1.2-netsec/include/asterisk/features.h
deleted file mode 100644
index ffea39d2a..000000000
--- a/1.2-netsec/include/asterisk/features.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Call Parking and Pickup API
- * Includes code and algorithms from the Zapata library.
- */
-
-#ifndef _AST_FEATURES_H
-#define _AST_FEATURES_H
-
-#define FEATURE_MAX_LEN 11
-#define FEATURE_APP_LEN 64
-#define FEATURE_APP_ARGS_LEN 256
-#define FEATURE_SNAME_LEN 32
-#define FEATURE_EXTEN_LEN 32
-
-/*! \brief main call feature structure */
-struct ast_call_feature {
- int feature_mask;
- char *fname;
- char sname[FEATURE_SNAME_LEN];
- char exten[FEATURE_MAX_LEN];
- char default_exten[FEATURE_MAX_LEN];
- int (*operation)(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense);
- unsigned int flags;
- char app[FEATURE_APP_LEN];
- char app_args[FEATURE_APP_ARGS_LEN];
- AST_LIST_ENTRY(ast_call_feature) feature_entry;
-};
-
-
-
-/*! \brief Park a call and read back parked location
- * \param chan the channel to actually be parked
- \param host the channel which will have the parked location read to
- Park the channel chan, and read back the parked location to the
- host. If the call is not picked up within a specified period of
- time, then the call will return to the last step that it was in
- (in terms of exten, priority and context)
- \param timeout is a timeout in milliseconds
- \param extout is a parameter to an int that will hold the parked location, or NULL if you want
-*/
-extern int ast_park_call(struct ast_channel *chan, struct ast_channel *host, int timeout, int *extout);
-
-/*! \brief Park a call via a masqueraded channel
- * \param rchan the real channel to be parked
- \param host the channel to have the parking read to
- Masquerade the channel rchan into a new, empty channel which is then
- parked with ast_park_call
- \param timeout is a timeout in milliseconds
- \param extout is a parameter to an int that will hold the parked location, or NULL if you want
-*/
-extern int ast_masq_park_call(struct ast_channel *rchan, struct ast_channel *host, int timeout, int *extout);
-
-/*! \brief Determine system parking extension
- * Returns the call parking extension for drivers that provide special
- call parking help */
-extern char *ast_parking_ext(void);
-
-/*! \brief Determine system call pickup extension */
-extern char *ast_pickup_ext(void);
-
-/*! \brief Bridge a call, optionally allowing redirection */
-extern int ast_bridge_call(struct ast_channel *chan, struct ast_channel *peer,struct ast_bridge_config *config);
-
-/*! \brief Pickup a call */
-extern int ast_pickup_call(struct ast_channel *chan);
-
-/*! \brief register new feature into feature_set
- \param feature an ast_call_feature object which contains a keysequence
- and a callback function which is called when this keysequence is pressed
- during a call. */
-extern void ast_register_feature(struct ast_call_feature *feature);
-
-/*! \brief unregister feature from feature_set
- \param feature the ast_call_feature object which was registered before*/
-extern void ast_unregister_feature(struct ast_call_feature *feature);
-
-#endif /* _AST_FEATURES_H */
diff --git a/1.2-netsec/include/asterisk/file.h b/1.2-netsec/include/asterisk/file.h
deleted file mode 100644
index e52570183..000000000
--- a/1.2-netsec/include/asterisk/file.h
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Generic File Format Support.
- */
-
-#ifndef _ASTERISK_FILE_H
-#define _ASTERISK_FILE_H
-
-#ifndef stdin
-#error You must include stdio.h before file.h!
-#endif /* !stdin */
-
-#include "asterisk/channel.h"
-#include "asterisk/frame.h"
-#include <fcntl.h>
-
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-
-/*! Convenient for waiting */
-#define AST_DIGIT_ANY "0123456789#*ABCD"
-#define AST_DIGIT_ANYNUM "0123456789"
-
-#define SEEK_FORCECUR 10
-
-/* Defined by individual formats. First item MUST be a
- pointer for use by the stream manager */
-struct ast_filestream;
-
-/*! Registers a new file format */
-/*! Register a new file format capability
- * Adds a format to asterisk's format abilities. Fill in the fields, and it will work. For examples, look at some of the various format code.
- * returns 0 on success, -1 on failure
- */
-int ast_format_register(const char *name, const char *exts, int format,
- struct ast_filestream * (*open)(FILE *f),
- struct ast_filestream * (*rewrite)(FILE *f, const char *comment),
- int (*write)(struct ast_filestream *, struct ast_frame *),
- int (*seek)(struct ast_filestream *, long offset, int whence),
- int (*trunc)(struct ast_filestream *),
- long (*tell)(struct ast_filestream *),
- struct ast_frame * (*read)(struct ast_filestream *, int *timetonext),
- void (*close)(struct ast_filestream *),
- char * (*getcomment)(struct ast_filestream *));
-
-/*! Unregisters a file format */
-/*!
- * \param name the name of the format you wish to unregister
- * Unregisters a format based on the name of the format.
- * Returns 0 on success, -1 on failure to unregister
- */
-int ast_format_unregister(const char *name);
-
-/*! Streams a file */
-/*!
- * \param c channel to stream the file to
- * \param filename the name of the file you wish to stream, minus the extension
- * \param preflang the preferred language you wish to have the file streamed to you in
- * Prepares a channel for the streaming of a file. To start the stream, afterward do a ast_waitstream() on the channel
- * Also, it will stop any existing streams on the channel.
- * Returns 0 on success, or -1 on failure.
- */
-int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang);
-
-/*! Stops a stream */
-/*!
- * \param c The channel you wish to stop playback on
- * Stop playback of a stream
- * Returns 0 regardless
- */
-int ast_stopstream(struct ast_channel *c);
-
-/*! Checks for the existence of a given file */
-/*!
- * \param filename name of the file you wish to check, minus the extension
- * \param fmt the format you wish to check (the extension)
- * \param preflang (the preferred language you wisht to find the file in)
- * See if a given file exists in a given format. If fmt is NULL, any format is accepted.
- * Returns -1 if file does not exist, non-zero positive otherwise.
- */
-int ast_fileexists(const char *filename, const char *fmt, const char *preflang);
-
-/*! Renames a file */
-/*!
- * \param oldname the name of the file you wish to act upon (minus the extension)
- * \param newname the name you wish to rename the file to (minus the extension)
- * \param fmt the format of the file
- * Rename a given file in a given format, or if fmt is NULL, then do so for all
- * Returns -1 on failure
- */
-int ast_filerename(const char *oldname, const char *newname, const char *fmt);
-
-/*! Deletes a file */
-/*!
- * \param filename name of the file you wish to delete (minus the extension)
- * \param fmt of the file
- * Delete a given file in a given format, or if fmt is NULL, then do so for all
- */
-int ast_filedelete(const char *filename, const char *fmt);
-
-/*! Copies a file */
-/*!
- * \param oldname name of the file you wish to copy (minus extension)
- * \param newname name you wish the file to be copied to (minus extension)
- * \param fmt the format of the file
- * Copy a given file in a given format, or if fmt is NULL, then do so for all
- */
-int ast_filecopy(const char *oldname, const char *newname, const char *fmt);
-
-/*! Waits for a stream to stop or digit to be pressed */
-/*!
- * \param c channel to waitstram on
- * \param breakon string of DTMF digits to break upon
- * Begins playback of a stream...
- * Wait for a stream to stop or for any one of a given digit to arrive, Returns 0
- * if the stream finishes, the character if it was interrupted, and -1 on error
- */
-int ast_waitstream(struct ast_channel *c, const char *breakon);
-
-/*! Waits for a stream to stop or digit matching a valid one digit exten to be pressed */
-/*!
- * \param c channel to waitstram on
- * \param context string of context to match digits to break upon
- * Begins playback of a stream...
- * Wait for a stream to stop or for any one of a valid extension digit to arrive, Returns 0
- * if the stream finishes, the character if it was interrupted, and -1 on error
- */
-int ast_waitstream_exten(struct ast_channel *c, const char *context);
-
-/*! Same as waitstream but allows stream to be forwarded or rewound */
-/*!
- * \param c channel to waitstram on
- * \param breakon string of DTMF digits to break upon
- * \param forward DTMF digit to fast forward upon
- * \param rewind DTMF digit to rewind upon
- * \param ms How many miliseconds to skip forward/back
- * Begins playback of a stream...
- * Wait for a stream to stop or for any one of a given digit to arrive, Returns 0
- * if the stream finishes, the character if it was interrupted, and -1 on error
- */
-int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms);
-
-/* Same as waitstream, but with audio output to fd and monitored fd checking. Returns
- 1 if monfd is ready for reading */
-int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd);
-
-/*! Starts reading from a file */
-/*!
- * \param filename the name of the file to read from
- * \param type format of file you wish to read from
- * \param comment comment to go with
- * \param flags file flags
- * \param check (unimplemented, hence negligible)
- * \param mode Open mode
- * Open an incoming file stream. flags are flags for the open() command, and
- * if check is non-zero, then it will not read a file if there are any files that
- * start with that name and have an extension
- * Please note, this is a blocking function. Program execution will not return until ast_waitstream completes it's execution.
- * Returns a struct ast_filestream on success, NULL on failure
- */
-struct ast_filestream *ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode);
-
-/*! Starts writing a file */
-/*!
- * \param filename the name of the file to write to
- * \param type format of file you wish to write out to
- * \param comment comment to go with
- * \param flags output file flags
- * \param check (unimplemented, hence negligible)
- * \param mode Open mode
- * Create an outgoing file stream. oflags are flags for the open() command, and
- * if check is non-zero, then it will not write a file if there are any files that
- * start with that name and have an extension
- * Please note, this is a blocking function. Program execution will not return until ast_waitstream completes it's execution.
- * Returns a struct ast_filestream on success, NULL on failure
- */
-struct ast_filestream *ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode);
-
-/*! Writes a frame to a stream */
-/*!
- * \param fs filestream to write to
- * \param f frame to write to the filestream
- * Send a frame to a filestream -- note: does NOT free the frame, call ast_frfree manually
- * Returns 0 on success, -1 on failure.
- */
-int ast_writestream(struct ast_filestream *fs, struct ast_frame *f);
-
-/*! Closes a stream */
-/*!
- * \param f filestream to close
- * Close a playback or recording stream
- * Returns 0 on success, -1 on failure
- */
-int ast_closestream(struct ast_filestream *f);
-
-/*! Opens stream for use in seeking, playing */
-/*!
- * \param chan channel to work with
- * \param filename to use
- * \param preflang prefered language to use
- * Returns a ast_filestream pointer if it opens the file, NULL on error
- */
-struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang);
-
-/*! Opens stream for use in seeking, playing */
-/*!
- * \param chan channel to work with
- * \param filename to use
- * \param preflang prefered language to use
- * \param asis if set, don't clear generators
- * Returns a ast_filestream pointer if it opens the file, NULL on error
- */
-struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char *filename, const char *preflang, int asis);
-/*! Opens stream for use in seeking, playing */
-/*!
- * \param chan channel to work with
- * \param filename to use
- * \param preflang prefered language to use
- * Returns a ast_filestream pointer if it opens the file, NULL on error
- */
-struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang);
-
-/*! Applys a open stream to a channel. */
-/*!
- * \param chan channel to work
- * \param s ast_filestream to apply
- * Returns 0 for success, -1 on failure
- */
-int ast_applystream(struct ast_channel *chan, struct ast_filestream *s);
-
-/*! play a open stream on a channel. */
-/*!
- * \param s filestream to play
- * Returns 0 for success, -1 on failure
- */
-int ast_playstream(struct ast_filestream *s);
-
-/*! Seeks into stream */
-/*!
- * \param fs ast_filestream to perform seek on
- * \param sample_offset numbers of samples to seek
- * \param whence SEEK_SET, SEEK_CUR, SEEK_END
- * Returns 0 for success, or -1 for error
- */
-int ast_seekstream(struct ast_filestream *fs, long sample_offset, int whence);
-
-/*! Trunc stream at current location */
-/*!
- * \param fs filestream to act on
- * Returns 0 for success, or -1 for error
- */
-int ast_truncstream(struct ast_filestream *fs);
-
-/*! Fast forward stream ms */
-/*!
- * \param fs filestream to act on
- * \param ms milliseconds to move
- * Returns 0 for success, or -1 for error
- */
-int ast_stream_fastforward(struct ast_filestream *fs, long ms);
-
-/*! Rewind stream ms */
-/*!
- * \param fs filestream to act on
- * \param ms milliseconds to move
- * Returns 0 for success, or -1 for error
- */
-int ast_stream_rewind(struct ast_filestream *fs, long ms);
-
-/*! Tell where we are in a stream */
-/*!
- * \param fs fs to act on
- * Returns a long as a sample offset into stream
- */
-long ast_tellstream(struct ast_filestream *fs);
-
-/*! Read a frame from a filestream */
-/*!
- * \param s ast_filestream to act on
- * Returns a frame or NULL if read failed
- */
-struct ast_frame *ast_readframe(struct ast_filestream *s);
-
-/*! Initialize file stuff */
-/*!
- * Initializes all the various file stuff. Basically just registers the cli stuff
- * Returns 0 all the time
- */
-extern int ast_file_init(void);
-
-
-#define AST_RESERVED_POINTERS 20
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_FILE_H */
diff --git a/1.2-netsec/include/asterisk/frame.h b/1.2-netsec/include/asterisk/frame.h
deleted file mode 100644
index ccba41539..000000000
--- a/1.2-netsec/include/asterisk/frame.h
+++ /dev/null
@@ -1,484 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Asterisk internal frame definitions.
- * \arg For an explanation of frames, see \ref Def_Frame
- * \arg Frames are send of Asterisk channels, see \ref Def_Channel
- */
-
-#ifndef _ASTERISK_FRAME_H
-#define _ASTERISK_FRAME_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include "asterisk/endian.h"
-
-struct ast_codec_pref {
- char order[32];
-};
-
-/*! \page Def_Frame AST Multimedia and signalling frames
- \section Def_AstFrame What is an ast_frame ?
- A frame of data read used to communicate between
- between channels and applications.
- Frames are divided into frame types and subclasses.
-
- \par Frame types
- \arg \b VOICE: Voice data, subclass is codec (AST_FORMAT_*)
- \arg \b VIDEO: Video data, subclass is codec (AST_FORMAT_*)
- \arg \b DTMF: A DTMF digit, subclass is the digit
- \arg \b IMAGE: Image transport, mostly used in IAX
- \arg \b TEXT: Text messages
- \arg \b HTML: URL's and web pages
- \arg \b T38: T38 Fax transport frames
- \arg \b IAX: Private frame type for the IAX protocol
- \arg \b CNG: Comfort noice frames
- \arg \b CONTROL: A control frame, subclass defined as AST_CONTROL_
- \arg \b NULL: Empty, useless frame
-
- \par Files
- \arg frame.h Definitions
- \arg frame.c Function library
- \arg \ref Def_Channel Asterisk channels
- \section Def_ControlFrame Control Frames
- Control frames send signalling information between channels
- and devices. They are prefixed with AST_CONTROL_, like AST_CONTROL_FRAME_HANGUP
- \arg \b HANGUP The other end has hungup
- \arg \b RING Local ring
- \arg \b RINGING The other end is ringing
- \arg \b ANSWER The other end has answered
- \arg \b BUSY Remote end is busy
- \arg \b TAKEOFFHOOK Make it go off hook (what's "it" ? )
- \arg \b OFFHOOK Line is off hook
- \arg \b CONGESTION Congestion (circuit is busy, not available)
- \arg \b FLASH Other end sends flash hook
- \arg \b WINK Other end sends wink
- \arg \b OPTION Send low-level option
- \arg \b RADIO_KEY Key radio (see app_rpt.c)
- \arg \b RADIO_UNKEY Un-key radio (see app_rpt.c)
- \arg \b PROGRESS Other end indicates call progress
- \arg \b PROCEEDING Indicates proceeding
- \arg \b HOLD Call is placed on hold
- \arg \b UNHOLD Call is back from hold
- \arg \b VIDUPDATE Video update requested
-
-*/
-
-/*! \brief Data structure associated with a single frame of data
- */
-struct ast_frame {
- /*! Kind of frame */
- int frametype;
- /*! Subclass, frame dependent */
- int subclass;
- /*! Length of data */
- int datalen;
- /*! Number of 8khz samples in this frame */
- int samples;
- /*! Was the data malloc'd? i.e. should we free it when we discard the frame? */
- int mallocd;
- /*! How many bytes exist _before_ "data" that can be used if needed */
- int offset;
- /*! Optional source of frame for debugging */
- const char *src;
- /*! Pointer to actual data */
- void *data;
- /*! Global delivery time */
- struct timeval delivery;
- /*! Next/Prev for linking stand alone frames */
- struct ast_frame *prev;
- /*! Next/Prev for linking stand alone frames */
- struct ast_frame *next;
-};
-
-#define AST_FRIENDLY_OFFSET 64 /*! It's polite for a a new frame to
- have this number of bytes for additional
- headers. */
-#define AST_MIN_OFFSET 32 /*! Make sure we keep at least this much handy */
-
-/*! Need the header be free'd? */
-#define AST_MALLOCD_HDR (1 << 0)
-/*! Need the data be free'd? */
-#define AST_MALLOCD_DATA (1 << 1)
-/*! Need the source be free'd? (haha!) */
-#define AST_MALLOCD_SRC (1 << 2)
-
-/* Frame types */
-/*! A DTMF digit, subclass is the digit */
-#define AST_FRAME_DTMF 1
-/*! Voice data, subclass is AST_FORMAT_* */
-#define AST_FRAME_VOICE 2
-/*! Video frame, maybe?? :) */
-#define AST_FRAME_VIDEO 3
-/*! A control frame, subclass is AST_CONTROL_* */
-#define AST_FRAME_CONTROL 4
-/*! An empty, useless frame */
-#define AST_FRAME_NULL 5
-/*! Inter Asterisk Exchange private frame type */
-#define AST_FRAME_IAX 6
-/*! Text messages */
-#define AST_FRAME_TEXT 7
-/*! Image Frames */
-#define AST_FRAME_IMAGE 8
-/*! HTML Frame */
-#define AST_FRAME_HTML 9
-/*! Comfort Noise frame (subclass is level of CNG in -dBov),
- body may include zero or more 8-bit quantization coefficients */
-#define AST_FRAME_CNG 10
-/*! T.38 Fax-over-IP data stream */
-#define AST_FRAME_T38 11
-
-/* HTML subclasses */
-/*! Sending a URL */
-#define AST_HTML_URL 1
-/*! Data frame */
-#define AST_HTML_DATA 2
-/*! Beginning frame */
-#define AST_HTML_BEGIN 4
-/*! End frame */
-#define AST_HTML_END 8
-/*! Load is complete */
-#define AST_HTML_LDCOMPLETE 16
-/*! Peer is unable to support HTML */
-#define AST_HTML_NOSUPPORT 17
-/*! Send URL, and track */
-#define AST_HTML_LINKURL 18
-/*! No more HTML linkage */
-#define AST_HTML_UNLINK 19
-/*! Reject link request */
-#define AST_HTML_LINKREJECT 20
-
-/* Data formats for capabilities and frames alike */
-/*! G.723.1 compression */
-#define AST_FORMAT_G723_1 (1 << 0)
-/*! GSM compression */
-#define AST_FORMAT_GSM (1 << 1)
-/*! Raw mu-law data (G.711) */
-#define AST_FORMAT_ULAW (1 << 2)
-/*! Raw A-law data (G.711) */
-#define AST_FORMAT_ALAW (1 << 3)
-/*! ADPCM (G.726, 32kbps) */
-#define AST_FORMAT_G726 (1 << 4)
-/*! ADPCM (IMA) */
-#define AST_FORMAT_ADPCM (1 << 5)
-/*! Raw 16-bit Signed Linear (8000 Hz) PCM */
-#define AST_FORMAT_SLINEAR (1 << 6)
-/*! LPC10, 180 samples/frame */
-#define AST_FORMAT_LPC10 (1 << 7)
-/*! G.729A audio */
-#define AST_FORMAT_G729A (1 << 8)
-/*! SpeeX Free Compression */
-#define AST_FORMAT_SPEEX (1 << 9)
-/*! iLBC Free Compression */
-#define AST_FORMAT_ILBC (1 << 10)
-/*! Maximum audio format */
-#define AST_FORMAT_MAX_AUDIO (1 << 15)
-/*! JPEG Images */
-#define AST_FORMAT_JPEG (1 << 16)
-/*! PNG Images */
-#define AST_FORMAT_PNG (1 << 17)
-/*! H.261 Video */
-#define AST_FORMAT_H261 (1 << 18)
-/*! H.263 Video */
-#define AST_FORMAT_H263 (1 << 19)
-/*! H.263+ Video */
-#define AST_FORMAT_H263_PLUS (1 << 20)
-/*! Maximum video format */
-#define AST_FORMAT_MAX_VIDEO (1 << 24)
-
-/* Control frame types */
-/*! Other end has hungup */
-#define AST_CONTROL_HANGUP 1
-/*! Local ring */
-#define AST_CONTROL_RING 2
-/*! Remote end is ringing */
-#define AST_CONTROL_RINGING 3
-/*! Remote end has answered */
-#define AST_CONTROL_ANSWER 4
-/*! Remote end is busy */
-#define AST_CONTROL_BUSY 5
-/*! Make it go off hook */
-#define AST_CONTROL_TAKEOFFHOOK 6
-/*! Line is off hook */
-#define AST_CONTROL_OFFHOOK 7
-/*! Congestion (circuits busy) */
-#define AST_CONTROL_CONGESTION 8
-/*! Flash hook */
-#define AST_CONTROL_FLASH 9
-/*! Wink */
-#define AST_CONTROL_WINK 10
-/*! Set a low-level option */
-#define AST_CONTROL_OPTION 11
-/*! Key Radio */
-#define AST_CONTROL_RADIO_KEY 12
-/*! Un-Key Radio */
-#define AST_CONTROL_RADIO_UNKEY 13
-/*! Indicate PROGRESS */
-#define AST_CONTROL_PROGRESS 14
-/*! Indicate CALL PROCEEDING */
-#define AST_CONTROL_PROCEEDING 15
-/*! Indicate call is placed on hold */
-#define AST_CONTROL_HOLD 16
-/*! Indicate call is left from hold */
-#define AST_CONTROL_UNHOLD 17
-/*! Indicate video frame update */
-#define AST_CONTROL_VIDUPDATE 18
-
-#define AST_SMOOTHER_FLAG_G729 (1 << 0)
-
-/* Option identifiers and flags */
-#define AST_OPTION_FLAG_REQUEST 0
-#define AST_OPTION_FLAG_ACCEPT 1
-#define AST_OPTION_FLAG_REJECT 2
-#define AST_OPTION_FLAG_QUERY 4
-#define AST_OPTION_FLAG_ANSWER 5
-#define AST_OPTION_FLAG_WTF 6
-
-/*! Verify touchtones by muting audio transmission
- (and reception) and verify the tone is still present */
-#define AST_OPTION_TONE_VERIFY 1
-
-/*! Put a compatible channel into TDD (TTY for the hearing-impared) mode */
-#define AST_OPTION_TDD 2
-
-/*! Relax the parameters for DTMF reception (mainly for radio use) */
-#define AST_OPTION_RELAXDTMF 3
-
-/*! Set (or clear) Audio (Not-Clear) Mode */
-#define AST_OPTION_AUDIO_MODE 4
-
-/*! Set channel transmit gain
- * Option data is a single signed char
- representing number of decibels (dB)
- to set gain to (on top of any gain
- specified in channel driver)
-*/
-#define AST_OPTION_TXGAIN 5
-
-/*! Set channel receive gain
- * Option data is a single signed char
- representing number of decibels (dB)
- to set gain to (on top of any gain
- specified in channel driver)
-*/
-#define AST_OPTION_RXGAIN 6
-
-struct ast_option_header {
- /* Always keep in network byte order */
-#if __BYTE_ORDER == __BIG_ENDIAN
- u_int16_t flag:3;
- u_int16_t option:13;
-#else
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- u_int16_t option:13;
- u_int16_t flag:3;
-#else
-#error Byte order not defined
-#endif
-#endif
- u_int8_t data[0];
-};
-
-/*! \brief Requests a frame to be allocated
- *
- * \param source
- * Request a frame be allocated. source is an optional source of the frame,
- * len is the requested length, or "0" if the caller will supply the buffer
- */
-#if 0 /* Unimplemented */
-struct ast_frame *ast_fralloc(char *source, int len);
-#endif
-
-/*! \brief Frees a frame
- * \param fr Frame to free
- * Free a frame, and the memory it used if applicable
- * \return no return.
- */
-void ast_frfree(struct ast_frame *fr);
-
-/*! \brief Copies a frame
- * \param fr frame to act upon
- * Take a frame, and if it's not been malloc'd, make a malloc'd copy
- * and if the data hasn't been malloced then make the
- * data malloc'd. If you need to store frames, say for queueing, then
- * you should call this function.
- * \return Returns a frame on success, NULL on error
- */
-struct ast_frame *ast_frisolate(struct ast_frame *fr);
-
-/*! \brief Copies a frame
- * \param fr frame to copy
- * Dupliates a frame -- should only rarely be used, typically frisolate is good enough
- * \return Returns a frame on success, NULL on error
- */
-struct ast_frame *ast_frdup(struct ast_frame *fr);
-
-/*! \brief Reads a frame from an fd
- * Read a frame from a stream or packet fd, as written by fd_write
- * \param fd an opened fd to read from
- * \return returns a frame on success, NULL on error
- */
-struct ast_frame *ast_fr_fdread(int fd);
-
-/*! Writes a frame to an fd
- * Write a frame to an fd
- * \param fd Which fd to write to
- * \param frame frame to write to the fd
- * \return Returns 0 on success, -1 on failure
- */
-int ast_fr_fdwrite(int fd, struct ast_frame *frame);
-
-/*! \brief Sends a hangup to an fd
- * Send a hangup (NULL equivalent) on an fd
- * \param fd fd to write to
- * \return Returns 0 on success, -1 on failure
- */
-int ast_fr_fdhangup(int fd);
-
-void ast_swapcopy_samples(void *dst, const void *src, int samples);
-
-/* Helpers for byteswapping native samples to/from
- little-endian and big-endian. */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define ast_frame_byteswap_le(fr) do { ; } while(0)
-#define ast_frame_byteswap_be(fr) do { struct ast_frame *__f = (fr); ast_swapcopy_samples(__f->data, __f->data, __f->samples); } while(0)
-#else
-#define ast_frame_byteswap_le(fr) do { struct ast_frame *__f = (fr); ast_swapcopy_samples(__f->data, __f->data, __f->samples); } while(0)
-#define ast_frame_byteswap_be(fr) do { ; } while(0)
-#endif
-
-
-/*! \brief Get the name of a format
- * \param format id of format
- * \return A static string containing the name of the format or "UNKN" if unknown.
- */
-extern char* ast_getformatname(int format);
-
-/*! \brief Get the names of a set of formats
- * \param buf a buffer for the output string
- * \param size size of buf (bytes)
- * \param format the format (combined IDs of codecs)
- * Prints a list of readable codec names corresponding to "format".
- * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)"
- * \return The return value is buf.
- */
-extern char* ast_getformatname_multiple(char *buf, size_t size, int format);
-
-/*!
- * \brief Gets a format from a name.
- * \param name string of format
- * \return This returns the form of the format in binary on success, 0 on error.
- */
-extern int ast_getformatbyname(char *name);
-
-/*! \brief Get a name from a format
- * Gets a name from a format
- * \param codec codec number (1,2,4,8,16,etc.)
- * \return This returns a static string identifying the format on success, 0 on error.
- */
-extern char *ast_codec2str(int codec);
-
-struct ast_smoother;
-
-extern struct ast_format_list *ast_get_format_list_index(int index);
-extern struct ast_format_list *ast_get_format_list(size_t *size);
-extern struct ast_smoother *ast_smoother_new(int bytes);
-extern void ast_smoother_set_flags(struct ast_smoother *smoother, int flags);
-extern int ast_smoother_get_flags(struct ast_smoother *smoother);
-extern void ast_smoother_free(struct ast_smoother *s);
-extern void ast_smoother_reset(struct ast_smoother *s, int bytes);
-extern int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap);
-extern struct ast_frame *ast_smoother_read(struct ast_smoother *s);
-#define ast_smoother_feed(s,f) __ast_smoother_feed(s, f, 0)
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 1)
-#define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 0)
-#else
-#define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 0)
-#define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 1)
-#endif
-
-extern void ast_frame_dump(char *name, struct ast_frame *f, char *prefix);
-
-/*! \brief Initialize a codec preference to "no preference" */
-extern void ast_codec_pref_init(struct ast_codec_pref *pref);
-
-/*! \brief Codec located at a particular place in the preference index */
-extern int ast_codec_pref_index(struct ast_codec_pref *pref, int index);
-
-/*! \brief Remove a codec from a preference list */
-extern void ast_codec_pref_remove(struct ast_codec_pref *pref, int format);
-
-/*! \brief Append a codec to a preference list, removing it first if it was already there */
-extern int ast_codec_pref_append(struct ast_codec_pref *pref, int format);
-
-/*! \brief Select the best format according to preference list from supplied options.
- If "find_best" is non-zero then if nothing is found, the "Best" format of
- the format list is selected, otherwise 0 is returned. */
-extern int ast_codec_choose(struct ast_codec_pref *pref, int formats, int find_best);
-
-/*! \brief Parse an "allow" or "deny" line and update the mask and pref if provided */
-extern void ast_parse_allow_disallow(struct ast_codec_pref *pref, int *mask, const char *list, int allowing);
-
-/*! \brief Dump codec preference list into a string */
-extern int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size);
-
-/*! \brief Shift a codec preference list up or down 65 bytes so that it becomes an ASCII string */
-extern void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right);
-
-/*! \brief Returns the number of samples contained in the frame */
-extern int ast_codec_get_samples(struct ast_frame *f);
-
-/*! \brief Returns the number of bytes for the number of samples of the given format */
-extern int ast_codec_get_len(int format, int samples);
-
-/*! \brief Gets duration in ms of interpolation frame for a format */
-static inline int ast_codec_interp_len(int format)
-{
- return (format == AST_FORMAT_ILBC) ? 30 : 20;
-}
-
-/*!
- \brief Adjusts the volume of the audio samples contained in a frame.
- \param f The frame containing the samples (must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR)
- \param adjustment The number of dB to adjust up or down.
- \return 0 for success, non-zero for an error
- */
-int ast_frame_adjust_volume(struct ast_frame *f, int adjustment);
-
-/*!
- \brief Sums two frames of audio samples.
- \param f1 The first frame (which will contain the result)
- \param f2 The second frame
- \return 0 for success, non-zero for an error
-
- The frames must be AST_FRAME_VOICE and must contain AST_FORMAT_SLINEAR samples,
- and must contain the same number of samples.
- */
-int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_FRAME_H */
diff --git a/1.2-netsec/include/asterisk/fskmodem.h b/1.2-netsec/include/asterisk/fskmodem.h
deleted file mode 100644
index ea863fc2f..000000000
--- a/1.2-netsec/include/asterisk/fskmodem.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief FSK Modem Support
- * \note Includes code and algorithms from the Zapata library.
- * \todo Translate Emiliano Zapata's spanish comments to english, please.
- */
-
-#ifndef _ASTERISK_FSKMODEM_H
-#define _ASTERISK_FSKMODEM_H
-
-#define PARITY_NONE 0
-#define PARITY_EVEN 1
-#define PARITY_ODD 2
-
-
-#define NCOLA 0x4000
-
-typedef struct {
- float spb; /*!< Samples / Bit */
- int nbit; /*!< Number of Data Bits (5,7,8) */
- float nstop; /*!< Number of Stop Bits 1,1.5,2 */
- int paridad; /*!< Parity 0=none 1=even 2=odd */
- int hdlc; /*!< Modo Packet */
- float x0;
- float x1;
- float x2;
- float cont;
- int bw; /*!< Ancho de Banda */
- double fmxv[8],fmyv[8]; /*!< filter stuff for M filter */
- int fmp; /*!< pointer for M filter */
- double fsxv[8],fsyv[8]; /*!< filter stuff for S filter */
- int fsp; /*!< pointer for S filter */
- double flxv[8],flyv[8]; /*!< filter stuff for L filter */
- int flp; /*!< pointer for L filter */
- int f_mark_idx; /*!< Indice de frecuencia de marca (f_M-500)/5 */
- int f_space_idx; /*!< Indice de frecuencia de espacio (f_S-500)/5 */
- int state;
- int pcola; /*!< Puntero de las colas de datos */
- float cola_in[NCOLA]; /*!< Cola de muestras de entrada */
- float cola_filtro[NCOLA]; /*!< Cola de muestras tras filtros */
- float cola_demod[NCOLA]; /*!< Cola de muestras demoduladas */
-} fsk_data;
-
-/* \brief Retrieve a serial byte into outbyte.
- Buffer is a pointer into a series of
- shorts and len records the number of bytes in the buffer. len will be
- overwritten with the number of bytes left that were not consumed.
- \return return value is as follows:
- \arg 0: Still looking for something...
- \arg 1: An output byte was received and stored in outbyte
- \arg -1: An error occured in the transmission
- He must be called with at least 80 bytes of buffer. */
-extern int fsk_serie(fsk_data *fskd, short *buffer, int *len, int *outbyte);
-
-#endif /* _ASTERISK_FSKMODEM_H */
diff --git a/1.2-netsec/include/asterisk/image.h b/1.2-netsec/include/asterisk/image.h
deleted file mode 100644
index 1b29b1daa..000000000
--- a/1.2-netsec/include/asterisk/image.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief General Asterisk channel definitions for image handling
- */
-
-#ifndef _ASTERISK_IMAGE_H
-#define _ASTERISK_IMAGE_H
-
-/*! \brief structure associated with registering an image format */
-struct ast_imager {
- /*! Name */
- char *name;
- /*! Description */
- char *desc;
- /*! Extension(s) (separated by '|' ) */
- char *exts;
- /*! Image format */
- int format;
- /*! Read an image from a file descriptor */
- struct ast_frame *(*read_image)(int fd, int len);
- /*! Identify if this is that type of file */
- int (*identify)(int fd);
- /*! Returns length written */
- int (*write_image)(int fd, struct ast_frame *frame);
- /*! For linked list */
- struct ast_imager *next;
-};
-
-/*! Check for image support on a channel */
-/*!
- * \param chan channel to check
- * Checks the channel to see if it supports the transmission of images
- * Returns non-zero if image transmission is supported
- */
-extern int ast_supports_images(struct ast_channel *chan);
-
-/*! Sends an image */
-/*!
- * \param chan channel to send image on
- * \param filename filename of image to send (minus extension)
- * Sends an image on the given channel.
- * Returns 0 on success, -1 on error
- */
-extern int ast_send_image(struct ast_channel *chan, char *filename);
-
-/*! Make an image */
-/*!
- * \param filename filename of image to prepare
- * \param preflang preferred language to get the image...?
- * \param format the format of the file
- * Make an image from a filename ??? No estoy positivo
- * Returns an ast_frame on success, NULL on failure
- */
-extern struct ast_frame *ast_read_image(char *filename, char *preflang, int format);
-
-/*! Register image format */
-/*!
- * \param imgdrv Populated ast_imager structure with info to register
- * Registers an image format
- * Returns 0 regardless
- */
-extern int ast_image_register(struct ast_imager *imgdrv);
-
-/*! Unregister an image format */
-/*!
- * \param imgdrv pointer to the ast_imager structure you wish to unregister
- * Unregisters the image format passed in
- * Returns nothing
- */
-extern void ast_image_unregister(struct ast_imager *imgdrv);
-
-/*! Initialize image stuff */
-/*!
- * Initializes all the various image stuff. Basically just registers the cli stuff
- * Returns 0 all the time
- */
-extern int ast_image_init(void);
-
-#endif /* _ASTERISK_IMAGE_H */
diff --git a/1.2-netsec/include/asterisk/indications.h b/1.2-netsec/include/asterisk/indications.h
deleted file mode 100644
index 6b55d90aa..000000000
--- a/1.2-netsec/include/asterisk/indications.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * 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.
- */
-
-/*! \file
- * \brief BSD Telephony Of Mexico "Tormenta" Tone Zone Support 2/22/01
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Primary Author: Pauline Middelink <middelink@polyware.nl>
- *
- */
-
-#ifndef _ASTERISK_INDICATIONS_H
-#define _ASTERISK_INDICATIONS_H
-
-#include "asterisk/lock.h"
-
-/* forward reference */
-struct ast_channel;
-
-struct tone_zone_sound {
- struct tone_zone_sound *next; /* next element */
- const char *name; /* Identifing name */
- const char *data; /* Actual zone description */
- /* Description is a series of tones of the format:
- [!]freq1[+freq2][/duration] separated by commas. There
- are no spaces. The sequence is repeated back to the
- first tone description not preceeded by !. Duration is
- specified in milliseconds */
-};
-
-struct tone_zone {
- struct tone_zone* next; /* next in list */
- char country[5]; /* Country code */
- char alias[5]; /* is this an alias? */
- char description[40]; /* Description */
- int nrringcadence; /* # registered ringcadence elements */
- int *ringcadence; /* Ring cadence */
- struct tone_zone_sound *tones; /* The known tones for this zone */
-};
-
-/* set the default tone country */
-extern int ast_set_indication_country(const char *country);
-
-/* locate tone_zone, given the country. if country == NULL, use the default country */
-extern struct tone_zone *ast_get_indication_zone(const char *country);
-/* locate a tone_zone_sound, given the tone_zone. if tone_zone == NULL, use the default tone_zone */
-extern struct tone_zone_sound *ast_get_indication_tone(const struct tone_zone *zone, const char *indication);
-
-/* add a new country, if country exists, it will be replaced. */
-extern int ast_register_indication_country(struct tone_zone *country);
-/* remove an existing country and all its indications, country must exist */
-extern int ast_unregister_indication_country(const char *country);
-/* add a new indication to a tone_zone. tone_zone must exist. if the indication already
- * exists, it will be replaced. */
-extern int ast_register_indication(struct tone_zone *zone, const char *indication, const char *tonelist);
-/* remove an existing tone_zone's indication. tone_zone must exist */
-extern int ast_unregister_indication(struct tone_zone *zone, const char *indication);
-
-/* Start a tone-list going */
-int ast_playtones_start(struct ast_channel *chan, int vol, const char* tonelist, int interruptible);
-/*! Stop the tones from playing */
-void ast_playtones_stop(struct ast_channel *chan);
-
-extern struct tone_zone *tone_zones;
-extern ast_mutex_t tzlock;
-
-#endif /* _ASTERISK_INDICATIONS_H */
diff --git a/1.2-netsec/include/asterisk/inline_api.h b/1.2-netsec/include/asterisk/inline_api.h
deleted file mode 100644
index 2347d09d7..000000000
--- a/1.2-netsec/include/asterisk/inline_api.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Kevin P. Fleming <kpfleming@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#ifndef __ASTERISK_INLINEAPI_H
-#define __ASTERISK_INLINEAPI_H
-
-/*! \file
- * \brief Inlinable API function macro
-
- Small API functions that are candidates for inlining need to be specially
- declared and defined, to ensure that the 'right thing' always happens.
- For example:
- - there must _always_ be a non-inlined version of the function
- available for modules compiled out of the tree to link to
- - references to a function that cannot be inlined (for any
- reason that the compiler deems proper) must devolve into an
- 'extern' reference, instead of 'static', so that multiple
- copies of the function body are not built in different modules
- - when LOW_MEMORY is defined, inlining should be disabled
- completely, even if the compiler is configured to support it
-
- The AST_INLINE_API macro allows this to happen automatically, when
- used to define your function. Proper usage is as follows:
- - define your function one place, in a header file, using the macro
- to wrap the function (see strings.h or time.h for examples)
- - choose a module to 'host' the function body for non-inline
- usages, and in that module _only_, define AST_API_MODULE before
- including the header file
- */
-
-#if !defined(LOW_MEMORY)
-
-#if !defined(AST_API_MODULE)
-#define AST_INLINE_API(hdr, body) hdr; extern inline hdr body
-#else
-#define AST_INLINE_API(hdr, body) hdr; hdr body
-#endif
-
-#else /* defined(LOW_MEMORY) */
-
-#if !defined(AST_API_MODULE)
-#define AST_INLINE_API(hdr, body) hdr;
-#else
-#define AST_INLINE_API(hdr, body) hdr; hdr body
-#endif
-
-#endif
-
-#undef AST_API_MODULE
-
-#endif /* __ASTERISK_INLINEAPI_H */
diff --git a/1.2-netsec/include/asterisk/io.h b/1.2-netsec/include/asterisk/io.h
deleted file mode 100644
index c33fb515b..000000000
--- a/1.2-netsec/include/asterisk/io.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief I/O Management (derived from Cheops-NG)
- */
-
-#ifndef _ASTERISK_IO_H
-#define _ASTERISK_IO_H
-
-#ifdef POLLCOMPAT
-#include "asterisk/poll-compat.h"
-#else
-#include <sys/poll.h> /* For POLL* constants */
-#endif
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/*! Input ready */
-#define AST_IO_IN POLLIN
-/*! Output ready */
-#define AST_IO_OUT POLLOUT
-/*! Priority input ready */
-#define AST_IO_PRI POLLPRI
-
-/* Implicitly polled for */
-/*! Error condition (errno or getsockopt) */
-#define AST_IO_ERR POLLERR
-/*! Hangup */
-#define AST_IO_HUP POLLHUP
-/*! Invalid fd */
-#define AST_IO_NVAL POLLNVAL
-
-/*
- * An Asterisk IO callback takes its id, a file descriptor, list of events, and
- * callback data as arguments and returns 0 if it should not be
- * run again, or non-zero if it should be run again.
- */
-
-struct io_context;
-
-/*! Creates a context */
-/*!
- * Create a context for I/O operations
- * Basically mallocs an IO structure and sets up some default values.
- * Returns an allocated io_context structure
- */
-extern struct io_context *io_context_create(void);
-
-/*! Destroys a context */
-/*
- * \param ioc structure to destroy
- * Destroy a context for I/O operations
- * Frees all memory associated with the given io_context structure along with the structure itself
- */
-extern void io_context_destroy(struct io_context *ioc);
-
-typedef int (*ast_io_cb)(int *id, int fd, short events, void *cbdata);
-#define AST_IO_CB(a) ((ast_io_cb)(a))
-
-/*! Adds an IO context */
-/*!
- * \param ioc which context to use
- * \param fd which fd to monitor
- * \param callback callback function to run
- * \param events event mask of events to wait for
- * \param data data to pass to the callback
- * Watch for any of revents activites on fd, calling callback with data as
- * callback data. Returns a pointer to ID of the IO event, or NULL on failure.
- */
-extern int *ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data);
-
-/*! Changes an IO handler */
-/*!
- * \param ioc which context to use
- * \param id
- * \param fd the fd you wish it to contain now
- * \param callback new callback function
- * \param events event mask to wait for
- * \param data data to pass to the callback function
- * Change an i/o handler, updating fd if > -1, callback if non-null, and revents
- * if >-1, and data if non-null. Returns a pointero to the ID of the IO event,
- * or NULL on failure.
- */
-extern int *ast_io_change(struct io_context *ioc, int *id, int fd, ast_io_cb callback, short events, void *data);
-
-/*! Removes an IO context */
-/*!
- * \param ioc which io_context to remove it from
- * \param id which ID to remove
- * Remove an I/O id from consideration Returns 0 on success or -1 on failure.
- */
-extern int ast_io_remove(struct io_context *ioc, int *id);
-
-/*! Waits for IO */
-/*!
- * \param ioc which context to act upon
- * \param howlong how many milliseconds to wait
- * Wait for I/O to happen, returning after
- * howlong milliseconds, and after processing
- * any necessary I/O. Returns the number of
- * I/O events which took place.
- */
-extern int ast_io_wait(struct io_context *ioc, int howlong);
-
-/*! Dumps the IO array */
-/*
- * Debugging: Dump everything in the I/O array
- */
-extern void ast_io_dump(struct io_context *ioc);
-
-/*! Set fd into non-echoing mode (if fd is a tty) */
-
-extern int ast_hide_password(int fd);
-
-/*! Restores TTY mode */
-/*
- * Call with result from previous ast_hide_password
- */
-extern int ast_restore_tty(int fd, int oldstatus);
-
-extern int ast_get_termcols(int fd);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_IO_H */
diff --git a/1.2-netsec/include/asterisk/linkedlists.h b/1.2-netsec/include/asterisk/linkedlists.h
deleted file mode 100644
index 8cf251b8b..000000000
--- a/1.2-netsec/include/asterisk/linkedlists.h
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- * Kevin P. Fleming <kpfleming@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#ifndef ASTERISK_LINKEDLISTS_H
-#define ASTERISK_LINKEDLISTS_H
-
-#include "asterisk/lock.h"
-
-/*!
- \file linkedlists.h
- \brief A set of macros to manage forward-linked lists.
-*/
-
-/*!
- \brief Attempts to lock a list.
- \param head This is a pointer to the list head structure
-
- This macro attempts to place an exclusive lock in the
- list head structure pointed to by head.
- Returns non-zero on success, 0 on failure
-*/
-#define AST_LIST_LOCK(head) \
- ast_mutex_lock(&(head)->lock)
-
-/*!
- \brief Attempts to unlock a list.
- \param head This is a pointer to the list head structure
-
- This macro attempts to remove an exclusive lock from the
- list head structure pointed to by head. If the list
- was not locked by this thread, this macro has no effect.
-*/
-#define AST_LIST_UNLOCK(head) \
- ast_mutex_unlock(&(head)->lock)
-
-/*!
- \brief Defines a structure to be used to hold a list of specified type.
- \param name This will be the name of the defined structure.
- \param type This is the type of each list entry.
-
- This macro creates a structure definition that can be used
- to hold a list of the entries of type \a type. It does not actually
- declare (allocate) a structure; to do that, either follow this
- macro with the desired name of the instance you wish to declare,
- or use the specified \a name to declare instances elsewhere.
-
- Example usage:
- \code
- static AST_LIST_HEAD(entry_list, entry) entries;
- \endcode
-
- This would define \c struct \c entry_list, and declare an instance of it named
- \a entries, all intended to hold a list of type \c struct \c entry.
-*/
-#define AST_LIST_HEAD(name, type) \
-struct name { \
- struct type *first; \
- struct type *last; \
- ast_mutex_t lock; \
-}
-
-/*!
- \brief Defines a structure to be used to hold a list of specified type (with no lock).
- \param name This will be the name of the defined structure.
- \param type This is the type of each list entry.
-
- This macro creates a structure definition that can be used
- to hold a list of the entries of type \a type. It does not actually
- declare (allocate) a structure; to do that, either follow this
- macro with the desired name of the instance you wish to declare,
- or use the specified \a name to declare instances elsewhere.
-
- Example usage:
- \code
- static AST_LIST_HEAD_NOLOCK(entry_list, entry) entries;
- \endcode
-
- This would define \c struct \c entry_list, and declare an instance of it named
- \a entries, all intended to hold a list of type \c struct \c entry.
-*/
-#define AST_LIST_HEAD_NOLOCK(name, type) \
-struct name { \
- struct type *first; \
- struct type *last; \
-}
-
-/*!
- \brief Defines a structure to be used to hold a list of specified type, statically initialized.
- \param name This will be the name of the defined structure.
- \param type This is the type of each list entry.
-
- This macro creates a structure definition that can be used
- to hold a list of the entries of type \a type, and allocates an instance
- of it, initialized to be empty.
-
- Example usage:
- \code
- static AST_LIST_HEAD_STATIC(entry_list, entry);
- \endcode
-
- This would define \c struct \c entry_list, intended to hold a list of
- type \c struct \c entry.
-*/
-#define AST_LIST_HEAD_STATIC(name, type) \
-struct name { \
- struct type *first; \
- struct type *last; \
- ast_mutex_t lock; \
-} name = { \
- .first = NULL, \
- .last = NULL, \
- .lock = AST_MUTEX_INIT_VALUE, \
-};
-
-/*!
- \brief Initializes a list head structure with a specified first entry.
- \param head This is a pointer to the list head structure
- \param entry pointer to the list entry that will become the head of the list
-
- This macro initializes a list head structure by setting the head
- entry to the supplied value and recreating the embedded lock.
-*/
-#define AST_LIST_HEAD_SET(head, entry) do { \
- (head)->first = (entry); \
- (head)->last = (entry); \
- ast_mutex_init(&(head)->lock); \
-} while (0)
-
-/*!
- \brief Initializes a list head structure with a specified first entry.
- \param head This is a pointer to the list head structure
- \param entry pointer to the list entry that will become the head of the list
-
- This macro initializes a list head structure by setting the head
- entry to the supplied value.
-*/
-#define AST_LIST_HEAD_SET_NOLOCK(head, entry) do { \
- (head)->first = (entry); \
- (head)->last = (entry); \
-} while (0)
-
-/*!
- \brief Declare a forward link structure inside a list entry.
- \param type This is the type of each list entry.
-
- This macro declares a structure to be used to link list entries together.
- It must be used inside the definition of the structure named in
- \a type, as follows:
-
- \code
- struct list_entry {
- ...
- AST_LIST_ENTRY(list_entry) list;
- }
- \endcode
-
- The field name \a list here is arbitrary, and can be anything you wish.
-*/
-#define AST_LIST_ENTRY(type) \
-struct { \
- struct type *next; \
-}
-
-/*!
- \brief Returns the first entry contained in a list.
- \param head This is a pointer to the list head structure
- */
-#define AST_LIST_FIRST(head) ((head)->first)
-
-/*!
- \brief Returns the next entry in the list after the given entry.
- \param elm This is a pointer to the current entry.
- \param field This is the name of the field (declared using AST_LIST_ENTRY())
- used to link entries of this list together.
-*/
-#define AST_LIST_NEXT(elm, field) ((elm)->field.next)
-
-/*!
- \brief Checks whether the specified list contains any entries.
- \param head This is a pointer to the list head structure
-
- Returns non-zero if the list has entries, zero if not.
- */
-#define AST_LIST_EMPTY(head) (AST_LIST_FIRST(head) == NULL)
-
-/*!
- \brief Loops over (traverses) the entries in a list.
- \param head This is a pointer to the list head structure
- \param var This is the name of the variable that will hold a pointer to the
- current list entry on each iteration. It must be declared before calling
- this macro.
- \param field This is the name of the field (declared using AST_LIST_ENTRY())
- used to link entries of this list together.
-
- This macro is use to loop over (traverse) the entries in a list. It uses a
- \a for loop, and supplies the enclosed code with a pointer to each list
- entry as it loops. It is typically used as follows:
- \code
- static AST_LIST_HEAD(entry_list, list_entry) entries;
- ...
- struct list_entry {
- ...
- AST_LIST_ENTRY(list_entry) list;
- }
- ...
- struct list_entry *current;
- ...
- AST_LIST_TRAVERSE(&entries, current, list) {
- (do something with current here)
- }
- \endcode
- \warning If you modify the forward-link pointer contained in the \a current entry while
- inside the loop, the behavior will be unpredictable. At a minimum, the following
- macros will modify the forward-link pointer, and should not be used inside
- AST_LIST_TRAVERSE() against the entry pointed to by the \a current pointer without
- careful consideration of their consequences:
- \li AST_LIST_NEXT() (when used as an lvalue)
- \li AST_LIST_INSERT_AFTER()
- \li AST_LIST_INSERT_HEAD()
- \li AST_LIST_INSERT_TAIL()
-*/
-#define AST_LIST_TRAVERSE(head,var,field) \
- for((var) = (head)->first; (var); (var) = (var)->field.next)
-
-/*!
- \brief Loops safely over (traverses) the entries in a list.
- \param head This is a pointer to the list head structure
- \param var This is the name of the variable that will hold a pointer to the
- current list entry on each iteration. It must be declared before calling
- this macro.
- \param field This is the name of the field (declared using AST_LIST_ENTRY())
- used to link entries of this list together.
-
- This macro is used to safely loop over (traverse) the entries in a list. It
- uses a \a for loop, and supplies the enclosed code with a pointer to each list
- entry as it loops. It is typically used as follows:
-
- \code
- static AST_LIST_HEAD(entry_list, list_entry) entries;
- ...
- struct list_entry {
- ...
- AST_LIST_ENTRY(list_entry) list;
- }
- ...
- struct list_entry *current;
- ...
- AST_LIST_TRAVERSE_SAFE_BEGIN(&entries, current, list) {
- (do something with current here)
- }
- AST_LIST_TRAVERSE_SAFE_END;
- \endcode
-
- It differs from AST_LIST_TRAVERSE() in that the code inside the loop can modify
- (or even free, after calling AST_LIST_REMOVE_CURRENT()) the entry pointed to by
- the \a current pointer without affecting the loop traversal.
-*/
-#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field) { \
- typeof((head)->first) __list_next; \
- typeof((head)->first) __list_prev = NULL; \
- typeof((head)->first) __new_prev = NULL; \
- for ((var) = (head)->first, __new_prev = (var), \
- __list_next = (var) ? (var)->field.next : NULL; \
- (var); \
- __list_prev = __new_prev, (var) = __list_next, \
- __list_next = (var) ? (var)->field.next : NULL \
- )
-
-/*!
- \brief Removes the \a current entry from a list during a traversal.
- \param head This is a pointer to the list head structure
- \param field This is the name of the field (declared using AST_LIST_ENTRY())
- used to link entries of this list together.
-
- \note This macro can \b only be used inside an AST_LIST_TRAVERSE_SAFE_BEGIN()
- block; it is used to unlink the current entry from the list without affecting
- the list traversal (and without having to re-traverse the list to modify the
- previous entry, if any).
- */
-#define AST_LIST_REMOVE_CURRENT(head, field) \
- __new_prev = __list_prev; \
- if (__list_prev) \
- __list_prev->field.next = __list_next; \
- else \
- (head)->first = __list_next; \
- if (!__list_next) \
- (head)->last = __list_prev;
-
-/*!
- \brief Closes a safe loop traversal block.
- */
-#define AST_LIST_TRAVERSE_SAFE_END }
-
-/*!
- \brief Initializes a list head structure.
- \param head This is a pointer to the list head structure
-
- This macro initializes a list head structure by setting the head
- entry to \a NULL (empty list) and recreating the embedded lock.
-*/
-#define AST_LIST_HEAD_INIT(head) { \
- (head)->first = NULL; \
- (head)->last = NULL; \
- ast_mutex_init(&(head)->lock); \
-}
-
-/*!
- \brief Destroys a list head structure.
- \param head This is a pointer to the list head structure
-
- This macro destroys a list head structure by setting the head
- entry to \a NULL (empty list) and destroying the embedded lock.
- It does not free the structure from memory.
-*/
-#define AST_LIST_HEAD_DESTROY(head) { \
- (head)->first = NULL; \
- (head)->last = NULL; \
- ast_mutex_destroy(&(head)->lock); \
-}
-
-/*!
- \brief Initializes a list head structure.
- \param head This is a pointer to the list head structure
-
- This macro initializes a list head structure by setting the head
- entry to \a NULL (empty list) and recreating the embedded lock.
-*/
-#define AST_LIST_HEAD_INIT_NOLOCK(head) { \
- (head)->first = NULL; \
- (head)->last = NULL; \
-}
-
-/*!
- \brief Inserts a list entry after a given entry.
- \param head This is a pointer to the list head structure
- \param listelm This is a pointer to the entry after which the new entry should
- be inserted.
- \param elm This is a pointer to the entry to be inserted.
- \param field This is the name of the field (declared using AST_LIST_ENTRY())
- used to link entries of this list together.
- */
-#define AST_LIST_INSERT_AFTER(head, listelm, elm, field) do { \
- (elm)->field.next = (listelm)->field.next; \
- (listelm)->field.next = (elm); \
- if ((head)->last == (listelm)) \
- (head)->last = (elm); \
-} while (0)
-
-/*!
- \brief Inserts a list entry at the head of a list.
- \param head This is a pointer to the list head structure
- \param elm This is a pointer to the entry to be inserted.
- \param field This is the name of the field (declared using AST_LIST_ENTRY())
- used to link entries of this list together.
- */
-#define AST_LIST_INSERT_HEAD(head, elm, field) do { \
- (elm)->field.next = (head)->first; \
- (head)->first = (elm); \
- if (!(head)->last) \
- (head)->last = (elm); \
-} while (0)
-
-/*!
- \brief Appends a list entry to the tail of a list.
- \param head This is a pointer to the list head structure
- \param elm This is a pointer to the entry to be appended.
- \param field This is the name of the field (declared using AST_LIST_ENTRY())
- used to link entries of this list together.
-
- Note: The link field in the appended entry is \b not modified, so if it is
- actually the head of a list itself, the entire list will be appended
- temporarily (until the next AST_LIST_INSERT_TAIL is performed).
- */
-#define AST_LIST_INSERT_TAIL(head, elm, field) do { \
- if (!(head)->first) { \
- (head)->first = (elm); \
- (head)->last = (elm); \
- } else { \
- (head)->last->field.next = (elm); \
- (head)->last = (elm); \
- } \
-} while (0)
-
-/*!
- \brief Removes and returns the head entry from a list.
- \param head This is a pointer to the list head structure
- \param field This is the name of the field (declared using AST_LIST_ENTRY())
- used to link entries of this list together.
-
- Removes the head entry from the list, and returns a pointer to it.
- This macro is safe to call on an empty list.
- */
-#define AST_LIST_REMOVE_HEAD(head, field) ({ \
- typeof((head)->first) cur = (head)->first; \
- if (cur) { \
- (head)->first = cur->field.next; \
- cur->field.next = NULL; \
- if ((head)->last == cur) \
- (head)->last = NULL; \
- } \
- cur; \
- })
-
-/*!
- \brief Removes a specific entry from a list.
- \param head This is a pointer to the list head structure
- \param elm This is a pointer to the entry to be removed.
- \param field This is the name of the field (declared using AST_LIST_ENTRY())
- used to link entries of this list together.
- \warning The removed entry is \b not freed nor modified in any way.
- */
-#define AST_LIST_REMOVE(head, elm, field) do { \
- if ((head)->first == (elm)) { \
- (head)->first = (elm)->field.next; \
- if ((head)->last == (elm)) \
- (head)->last = NULL; \
- } else { \
- typeof(elm) curelm = (head)->first; \
- while (curelm->field.next != (elm)) \
- curelm = curelm->field.next; \
- curelm->field.next = (elm)->field.next; \
- if ((head)->last == (elm)) \
- (head)->last = curelm; \
- } \
-} while (0)
-
-#endif /* _ASTERISK_LINKEDLISTS_H */
diff --git a/1.2-netsec/include/asterisk/localtime.h b/1.2-netsec/include/asterisk/localtime.h
deleted file mode 100644
index fac1788c0..000000000
--- a/1.2-netsec/include/asterisk/localtime.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- * Tilghman Lesher <tlesher@vcch.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Custom localtime functions for multiple timezones
- */
-
-#ifndef _ASTERISK_LOCALTIME_H
-#define _ASTERISK_LOCALTIME_H
-
-extern int ast_tzsetwall(void);
-extern void ast_tzset(const char *name);
-extern struct tm *ast_localtime(const time_t *timep, struct tm *p_tm, const char *zone);
-extern time_t ast_mktime(struct tm * const tmp, const char *zone);
-extern char *ast_ctime(const time_t * const timep);
-extern char *ast_ctime_r(const time_t * const timep, char *buf);
-
-#endif /* _ASTERISK_LOCALTIME_H */
diff --git a/1.2-netsec/include/asterisk/lock.h b/1.2-netsec/include/asterisk/lock.h
deleted file mode 100644
index 38c4e64ac..000000000
--- a/1.2-netsec/include/asterisk/lock.h
+++ /dev/null
@@ -1,660 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief General Asterisk channel locking definitions.
- */
-
-#ifndef _ASTERISK_LOCK_H
-#define _ASTERISK_LOCK_H
-
-#include <pthread.h>
-#include <netdb.h>
-#include <time.h>
-#include <sys/param.h>
-
-#include "asterisk/logger.h"
-
-#define AST_PTHREADT_NULL (pthread_t) -1
-#define AST_PTHREADT_STOP (pthread_t) -2
-
-#ifdef __APPLE__
-/* Provide the Linux initializers for MacOS X */
-#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
-#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { 0x4d555458, \
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
- 0x20 } }
-#endif
-
-#ifdef BSD
-#ifdef __GNUC__
-#define AST_MUTEX_INIT_W_CONSTRUCTORS
-#else
-#define AST_MUTEX_INIT_ON_FIRST_USE
-#endif
-#endif /* BSD */
-
-/* From now on, Asterisk REQUIRES Recursive (not error checking) mutexes
- and will not run without them. */
-#if defined(__CYGWIN__)
-#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
-#define PTHREAD_MUTEX_INIT_VALUE (ast_mutex_t)18
-#define AST_MUTEX_KIND PTHREAD_MUTEX_RECURSIVE_NP
-#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
-#define PTHREAD_MUTEX_INIT_VALUE PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
-#define AST_MUTEX_KIND PTHREAD_MUTEX_RECURSIVE_NP
-#else
-#define PTHREAD_MUTEX_INIT_VALUE PTHREAD_MUTEX_INITIALIZER
-#define AST_MUTEX_KIND PTHREAD_MUTEX_RECURSIVE
-#endif /* PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP */
-
-#ifdef SOLARIS
-#define AST_MUTEX_INIT_W_CONSTRUCTORS
-#endif
-
-#ifdef DEBUG_THREADS
-
-#define __ast_mutex_logger(...) { if (canlog) ast_log(LOG_ERROR, __VA_ARGS__); else fprintf(stderr, __VA_ARGS__); }
-
-#ifdef THREAD_CRASH
-#define DO_THREAD_CRASH do { *((int *)(0)) = 1; } while(0)
-#endif
-
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#define AST_MUTEX_INIT_VALUE { PTHREAD_MUTEX_INIT_VALUE, { NULL }, { 0 }, 0, { NULL }, { 0 } }
-
-#define AST_MAX_REENTRANCY 10
-
-struct ast_mutex_info {
- pthread_mutex_t mutex;
- const char *file[AST_MAX_REENTRANCY];
- int lineno[AST_MAX_REENTRANCY];
- int reentrancy;
- const char *func[AST_MAX_REENTRANCY];
- pthread_t thread[AST_MAX_REENTRANCY];
-};
-
-typedef struct ast_mutex_info ast_mutex_t;
-
-typedef pthread_cond_t ast_cond_t;
-
-static inline int __ast_pthread_mutex_init_attr(const char *filename, int lineno, const char *func,
- const char *mutex_name, ast_mutex_t *t,
- pthread_mutexattr_t *attr)
-{
-#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
- int canlog = strcmp(filename, "logger.c");
-
- if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is already initialized.\n",
- filename, lineno, func, mutex_name);
- __ast_mutex_logger("%s line %d (%s): Error: previously initialization of mutex '%s'.\n",
- t->file, t->lineno, t->func, mutex_name);
-#ifdef THREAD_CRASH
- DO_THREAD_CRASH;
-#endif
- return 0;
- }
-#endif
-
- t->file[0] = filename;
- t->lineno[0] = lineno;
- t->func[0] = func;
- t->thread[0] = 0;
- t->reentrancy = 0;
-
- return pthread_mutex_init(&t->mutex, attr);
-}
-
-static inline int __ast_pthread_mutex_init(const char *filename, int lineno, const char *func,
- const char *mutex_name, ast_mutex_t *t)
-{
- static pthread_mutexattr_t attr;
-
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, AST_MUTEX_KIND);
-
- return __ast_pthread_mutex_init_attr(filename, lineno, func, mutex_name, t, &attr);
-}
-
-static inline int __ast_pthread_mutex_destroy(const char *filename, int lineno, const char *func,
- const char *mutex_name, ast_mutex_t *t)
-{
- int res;
- int canlog = strcmp(filename, "logger.c");
-
-#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
- if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
- filename, lineno, func, mutex_name);
- }
-#endif
-
- res = pthread_mutex_trylock(&t->mutex);
- switch (res) {
- case 0:
- pthread_mutex_unlock(&t->mutex);
- break;
- case EINVAL:
- __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",
- filename, lineno, func, mutex_name);
- break;
- case EBUSY:
- __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",
- filename, lineno, func, mutex_name);
- __ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",
- t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
- break;
- }
-
- if ((res = pthread_mutex_destroy(&t->mutex)))
- __ast_mutex_logger("%s line %d (%s): Error destroying mutex: %s\n",
- filename, lineno, func, strerror(res));
-#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
- else
- t->mutex = PTHREAD_MUTEX_INIT_VALUE;
-#endif
- t->file[0] = filename;
- t->lineno[0] = lineno;
- t->func[0] = func;
-
- return res;
-}
-
-#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
-/* if AST_MUTEX_INIT_W_CONSTRUCTORS is defined, use file scope
- constrictors/destructors to create/destroy mutexes. */
-#define __AST_MUTEX_DEFINE(scope,mutex) \
- scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE; \
-static void __attribute__ ((constructor)) init_##mutex(void) \
-{ \
- ast_mutex_init(&mutex); \
-} \
-static void __attribute__ ((destructor)) fini_##mutex(void) \
-{ \
- ast_mutex_destroy(&mutex); \
-}
-#elif defined(AST_MUTEX_INIT_ON_FIRST_USE)
-/* if AST_MUTEX_INIT_ON_FIRST_USE is defined, mutexes are created on
- first use. The performance impact on FreeBSD should be small since
- the pthreads library does this itself to initialize errror checking
- (defaulty type) mutexes. If nither is defined, the pthreads librariy
- does the initialization itself on first use. */
-#define __AST_MUTEX_DEFINE(scope,mutex) \
- scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE
-#else /* AST_MUTEX_INIT_W_CONSTRUCTORS */
-/* By default, use static initialization of mutexes.*/
-#define __AST_MUTEX_DEFINE(scope,mutex) \
- scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE
-#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
-
-static inline int __ast_pthread_mutex_lock(const char *filename, int lineno, const char *func,
- const char* mutex_name, ast_mutex_t *t)
-{
- int res;
- int canlog = strcmp(filename, "logger.c");
-
-#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE)
- if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
-#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
- ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
- filename, lineno, func, mutex_name);
-#endif
- ast_mutex_init(t);
- }
-#endif /* defined(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE) */
-
-#ifdef DETECT_DEADLOCKS
- {
- time_t seconds = time(NULL);
- time_t current;
- do {
- res = pthread_mutex_trylock(&t->mutex);
- if (res == EBUSY) {
- current = time(NULL);
- if ((current - seconds) && (!((current - seconds) % 5))) {
- __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
- filename, lineno, func, (int)(current - seconds), mutex_name);
- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
- t->file[t->reentrancy-1], t->lineno[t->reentrancy-1],
- t->func[t->reentrancy-1], mutex_name);
- }
- usleep(200);
- }
- } while (res == EBUSY);
- }
-#else
- res = pthread_mutex_lock(&t->mutex);
-#endif /* DETECT_DEADLOCKS */
-
- if (!res) {
- if (t->reentrancy < AST_MAX_REENTRANCY) {
- t->file[t->reentrancy] = filename;
- t->lineno[t->reentrancy] = lineno;
- t->func[t->reentrancy] = func;
- t->thread[t->reentrancy] = pthread_self();
- t->reentrancy++;
- } else {
- __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
- filename, lineno, func, mutex_name);
- }
- } else {
- __ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",
- filename, lineno, func, strerror(errno));
-#ifdef THREAD_CRASH
- DO_THREAD_CRASH;
-#endif
- }
-
- return res;
-}
-
-static inline int __ast_pthread_mutex_trylock(const char *filename, int lineno, const char *func,
- const char* mutex_name, ast_mutex_t *t)
-{
- int res;
- int canlog = strcmp(filename, "logger.c");
-
-#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE)
- if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
-#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
-
- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
- filename, lineno, func, mutex_name);
-#endif
- ast_mutex_init(t);
- }
-#endif /* defined(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE) */
-
- if (!(res = pthread_mutex_trylock(&t->mutex))) {
- if (t->reentrancy < AST_MAX_REENTRANCY) {
- t->file[t->reentrancy] = filename;
- t->lineno[t->reentrancy] = lineno;
- t->func[t->reentrancy] = func;
- t->thread[t->reentrancy] = pthread_self();
- t->reentrancy++;
- } else {
- __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
- filename, lineno, func, mutex_name);
- }
- }
-
- return res;
-}
-
-static inline int __ast_pthread_mutex_unlock(const char *filename, int lineno, const char *func,
- const char *mutex_name, ast_mutex_t *t)
-{
- int res;
- int canlog = strcmp(filename, "logger.c");
-
-#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
- if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
- filename, lineno, func, mutex_name);
- }
-#endif
-
- if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
- __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
- filename, lineno, func, mutex_name);
- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
- t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
-#ifdef THREAD_CRASH
- DO_THREAD_CRASH;
-#endif
- }
-
- if (--t->reentrancy < 0) {
- __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
- filename, lineno, func, mutex_name);
- t->reentrancy = 0;
- }
-
- if (t->reentrancy < AST_MAX_REENTRANCY) {
- t->file[t->reentrancy] = NULL;
- t->lineno[t->reentrancy] = 0;
- t->func[t->reentrancy] = NULL;
- t->thread[t->reentrancy] = 0;
- }
-
- if ((res = pthread_mutex_unlock(&t->mutex))) {
- __ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n",
- filename, lineno, func, strerror(res));
-#ifdef THREAD_CRASH
- DO_THREAD_CRASH;
-#endif
- }
-
- return res;
-}
-
-static inline int __ast_cond_init(const char *filename, int lineno, const char *func,
- const char *cond_name, ast_cond_t *cond, pthread_condattr_t *cond_attr)
-{
- return pthread_cond_init(cond, cond_attr);
-}
-
-static inline int __ast_cond_signal(const char *filename, int lineno, const char *func,
- const char *cond_name, ast_cond_t *cond)
-{
- return pthread_cond_signal(cond);
-}
-
-static inline int __ast_cond_broadcast(const char *filename, int lineno, const char *func,
- const char *cond_name, ast_cond_t *cond)
-{
- return pthread_cond_broadcast(cond);
-}
-
-static inline int __ast_cond_destroy(const char *filename, int lineno, const char *func,
- const char *cond_name, ast_cond_t *cond)
-{
- return pthread_cond_destroy(cond);
-}
-
-static inline int __ast_cond_wait(const char *filename, int lineno, const char *func,
- const char *cond_name, const char *mutex_name,
- ast_cond_t *cond, ast_mutex_t *t)
-{
- int res;
- int canlog = strcmp(filename, "logger.c");
-
-#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
- if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
- filename, lineno, func, mutex_name);
- }
-#endif
-
- if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
- __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
- filename, lineno, func, mutex_name);
- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
- t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
-#ifdef THREAD_CRASH
- DO_THREAD_CRASH;
-#endif
- }
-
- if (t->reentrancy > 1)
- __ast_mutex_logger("%s line %d (%s): mutex '%s' locked more than once, cond_wait will block!\n",
- filename, lineno, func, mutex_name);
-
- if (--t->reentrancy < 0) {
- __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
- filename, lineno, func, mutex_name);
- t->reentrancy = 0;
- }
-
- if (t->reentrancy < AST_MAX_REENTRANCY) {
- t->file[t->reentrancy] = NULL;
- t->lineno[t->reentrancy] = 0;
- t->func[t->reentrancy] = NULL;
- t->thread[t->reentrancy] = 0;
- }
-
- if ((res = pthread_cond_wait(cond, &t->mutex))) {
- __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
- filename, lineno, func, strerror(res));
-#ifdef THREAD_CRASH
- DO_THREAD_CRASH;
-#endif
- } else {
- if (t->reentrancy < AST_MAX_REENTRANCY) {
- t->file[t->reentrancy] = filename;
- t->lineno[t->reentrancy] = lineno;
- t->func[t->reentrancy] = func;
- t->thread[t->reentrancy] = pthread_self();
- t->reentrancy++;
- } else {
- __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
- filename, lineno, func, mutex_name);
- }
- }
-
- return res;
-}
-
-static inline int __ast_cond_timedwait(const char *filename, int lineno, const char *func,
- const char *cond_name, const char *mutex_name, ast_cond_t *cond,
- ast_mutex_t *t, const struct timespec *abstime)
-{
- int res;
- int canlog = strcmp(filename, "logger.c");
-
-#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
- if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
- filename, lineno, func, mutex_name);
- }
-#endif
-
- if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
- __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
- filename, lineno, func, mutex_name);
- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
- t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
-#ifdef THREAD_CRASH
- DO_THREAD_CRASH;
-#endif
- }
-
- if (t->reentrancy > 1)
- __ast_mutex_logger("%s line %d (%s): mutex '%s' locked more than once, cond_timedwait will block!\n",
- filename, lineno, func, mutex_name);
-
- if (--t->reentrancy < 0) {
- __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
- filename, lineno, func, mutex_name);
- t->reentrancy = 0;
- }
-
- if (t->reentrancy < AST_MAX_REENTRANCY) {
- t->file[t->reentrancy] = NULL;
- t->lineno[t->reentrancy] = 0;
- t->func[t->reentrancy] = NULL;
- t->thread[t->reentrancy] = 0;
- }
-
- if ((res = pthread_cond_timedwait(cond, &t->mutex, abstime))) {
- __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
- filename, lineno, func, strerror(res));
-#ifdef THREAD_CRASH
- DO_THREAD_CRASH;
-#endif
- } else {
- if (t->reentrancy < AST_MAX_REENTRANCY) {
- t->file[t->reentrancy] = filename;
- t->lineno[t->reentrancy] = lineno;
- t->func[t->reentrancy] = func;
- t->thread[t->reentrancy] = pthread_self();
- t->reentrancy++;
- } else {
- __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
- filename, lineno, func, mutex_name);
- }
- }
-
- return res;
-}
-
-#define ast_mutex_init(pmutex) __ast_pthread_mutex_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex)
-#define ast_mutex_destroy(a) __ast_pthread_mutex_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
-#define ast_mutex_lock(a) __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
-#define ast_mutex_unlock(a) __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
-#define ast_mutex_trylock(a) __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
-#define ast_cond_init(cond, attr) __ast_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr)
-#define ast_cond_destroy(cond) __ast_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
-#define ast_cond_signal(cond) __ast_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
-#define ast_cond_broadcast(cond) __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
-#define ast_cond_wait(cond, mutex) __ast_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex)
-#define ast_cond_timedwait(cond, mutex, time) __ast_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time)
-
-#else /* !DEBUG_THREADS */
-
-
-#define AST_MUTEX_INIT_VALUE PTHREAD_MUTEX_INIT_VALUE
-
-
-typedef pthread_mutex_t ast_mutex_t;
-
-static inline int ast_mutex_init(ast_mutex_t *pmutex)
-{
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, AST_MUTEX_KIND);
- return pthread_mutex_init(pmutex, &attr);
-}
-
-#define ast_pthread_mutex_init(pmutex,a) pthread_mutex_init(pmutex,a)
-
-static inline int ast_mutex_unlock(ast_mutex_t *pmutex)
-{
- return pthread_mutex_unlock(pmutex);
-}
-
-static inline int ast_mutex_destroy(ast_mutex_t *pmutex)
-{
- return pthread_mutex_destroy(pmutex);
-}
-
-#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
-/* if AST_MUTEX_INIT_W_CONSTRUCTORS is defined, use file scope
- constrictors/destructors to create/destroy mutexes. */
-#define __AST_MUTEX_DEFINE(scope,mutex) \
- scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE; \
-static void __attribute__ ((constructor)) init_##mutex(void) \
-{ \
- ast_mutex_init(&mutex); \
-} \
-static void __attribute__ ((destructor)) fini_##mutex(void) \
-{ \
- ast_mutex_destroy(&mutex); \
-}
-
-static inline int ast_mutex_lock(ast_mutex_t *pmutex)
-{
- return pthread_mutex_lock(pmutex);
-}
-
-static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
-{
- return pthread_mutex_trylock(pmutex);
-}
-
-#elif defined(AST_MUTEX_INIT_ON_FIRST_USE)
-/* if AST_MUTEX_INIT_ON_FIRST_USE is defined, mutexes are created on
- first use. The performance impact on FreeBSD should be small since
- the pthreads library does this itself to initialize errror checking
- (defaulty type) mutexes.*/
-#define __AST_MUTEX_DEFINE(scope,mutex) \
- scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE
-
-static inline int ast_mutex_lock(ast_mutex_t *pmutex)
-{
- if (*pmutex == (ast_mutex_t)AST_MUTEX_KIND)
- ast_mutex_init(pmutex);
- return pthread_mutex_lock(pmutex);
-}
-static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
-{
- if (*pmutex == (ast_mutex_t)AST_MUTEX_KIND)
- ast_mutex_init(pmutex);
- return pthread_mutex_trylock(pmutex);
-}
-#else
-/* By default, use static initialization of mutexes.*/
-#define __AST_MUTEX_DEFINE(scope,mutex) \
- scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE
-
-static inline int ast_mutex_lock(ast_mutex_t *pmutex)
-{
- return pthread_mutex_lock(pmutex);
-}
-
-static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
-{
- return pthread_mutex_trylock(pmutex);
-}
-
-#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
-
-typedef pthread_cond_t ast_cond_t;
-
-static inline int ast_cond_init(ast_cond_t *cond, pthread_condattr_t *cond_attr)
-{
- return pthread_cond_init(cond, cond_attr);
-}
-
-static inline int ast_cond_signal(ast_cond_t *cond)
-{
- return pthread_cond_signal(cond);
-}
-
-static inline int ast_cond_broadcast(ast_cond_t *cond)
-{
- return pthread_cond_broadcast(cond);
-}
-
-static inline int ast_cond_destroy(ast_cond_t *cond)
-{
- return pthread_cond_destroy(cond);
-}
-
-static inline int ast_cond_wait(ast_cond_t *cond, ast_mutex_t *t)
-{
- return pthread_cond_wait(cond, t);
-}
-
-static inline int ast_cond_timedwait(ast_cond_t *cond, ast_mutex_t *t, const struct timespec *abstime)
-{
- return pthread_cond_timedwait(cond, t, abstime);
-}
-
-#endif /* !DEBUG_THREADS */
-
-#define pthread_mutex_t use_ast_mutex_t_instead_of_pthread_mutex_t
-#define pthread_mutex_lock use_ast_mutex_lock_instead_of_pthread_mutex_lock
-#define pthread_mutex_unlock use_ast_mutex_unlock_instead_of_pthread_mutex_unlock
-#define pthread_mutex_trylock use_ast_mutex_trylock_instead_of_pthread_mutex_trylock
-#define pthread_mutex_init use_ast_mutex_init_instead_of_pthread_mutex_init
-#define pthread_mutex_destroy use_ast_mutex_destroy_instead_of_pthread_mutex_destroy
-#define pthread_cond_t use_ast_cond_t_instead_of_pthread_cond_t
-#define pthread_cond_init use_ast_cond_init_instead_of_pthread_cond_init
-#define pthread_cond_destroy use_ast_cond_destroy_instead_of_pthread_cond_destroy
-#define pthread_cond_signal use_ast_cond_signal_instead_of_pthread_cond_signal
-#define pthread_cond_broadcast use_ast_cond_broadcast_instead_of_pthread_cond_broadcast
-#define pthread_cond_wait use_ast_cond_wait_instead_of_pthread_cond_wait
-#define pthread_cond_timedwait use_ast_cond_wait_instead_of_pthread_cond_timedwait
-
-#define AST_MUTEX_DEFINE_STATIC(mutex) __AST_MUTEX_DEFINE(static,mutex)
-#define AST_MUTEX_DEFINE_EXPORTED(mutex) __AST_MUTEX_DEFINE(/**/,mutex)
-
-#define AST_MUTEX_INITIALIZER __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__
-
-#define gethostbyname __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__
-#ifndef __linux__
-#define pthread_create __use_ast_pthread_create_instead__
-#endif
-
-#endif /* _ASTERISK_LOCK_H */
diff --git a/1.2-netsec/include/asterisk/logger.h b/1.2-netsec/include/asterisk/logger.h
deleted file mode 100644
index ac764baa4..000000000
--- a/1.2-netsec/include/asterisk/logger.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*!
- \file logger.h
- \brief Support for logging to various files, console and syslog
- Configuration in file logger.conf
-*/
-
-#ifndef _ASTERISK_LOGGER_H
-#define _ASTERISK_LOGGER_H
-
-#include "asterisk/compat.h"
-
-#include <stdarg.h>
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#define EVENTLOG "event_log"
-#define QUEUELOG "queue_log"
-
-#define DEBUG_M(a) { \
- a; \
-}
-
-/*! Used for sending a log message */
-/*!
- \brief This is the standard logger function. Probably the only way you will invoke it would be something like this:
- ast_log(LOG_WHATEVER, "Problem with the %s Captain. We should get some more. Will %d be enough?", "flux capacitor", 10);
- where WHATEVER is one of ERROR, DEBUG, EVENT, NOTICE, or WARNING depending
- on which log you wish to output to. These are implemented as macros, that
- will provide the function with the needed arguments.
-
- \param level Type of log event
- \param file Will be provided by the LOG_* macro
- \param line Will be provided by the LOG_* macro
- \param function Will be provided by the LOG_* macro
- \param fmt This is what is important. The format is the same as your favorite breed of printf. You know how that works, right? :-)
- */
-extern void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
- __attribute__ ((format (printf, 5, 6)));
-
-extern void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...)
- __attribute__ ((format (printf, 5, 6)));
-
-/*! Send a verbose message (based on verbose level)
- \brief This works like ast_log, but prints verbose messages to the console depending on verbosity level set.
- ast_verbose(VERBOSE_PREFIX_3 "Whatever %s is happening\n", "nothing");
- This will print the message to the console if the verbose level is set to a level >= 3
- Note the abscence of a comma after the VERBOSE_PREFIX_3. This is important.
- VERBOSE_PREFIX_1 through VERBOSE_PREFIX_3 are defined.
- */
-extern void ast_verbose(const char *fmt, ...)
- __attribute__ ((format (printf, 1, 2)));
-
-extern int ast_register_verbose(void (*verboser)(const char *string, int opos, int replacelast, int complete));
-extern int ast_unregister_verbose(void (*verboser)(const char *string, int opos, int replacelast, int complete));
-extern int ast_verbose_dmesg(void (*verboser)(const char *string, int opos, int replacelast, int complete));
-extern void ast_console_puts(const char *string);
-
-#define _A_ __FILE__, __LINE__, __PRETTY_FUNCTION__
-
-#ifdef LOG_DEBUG
-#undef LOG_DEBUG
-#endif
-#define __LOG_DEBUG 0
-#define LOG_DEBUG __LOG_DEBUG, _A_
-
-#ifdef LOG_EVENT
-#undef LOG_EVENT
-#endif
-#define __LOG_EVENT 1
-#define LOG_EVENT __LOG_EVENT, _A_
-
-#ifdef LOG_NOTICE
-#undef LOG_NOTICE
-#endif
-#define __LOG_NOTICE 2
-#define LOG_NOTICE __LOG_NOTICE, _A_
-
-#ifdef LOG_WARNING
-#undef LOG_WARNING
-#endif
-#define __LOG_WARNING 3
-#define LOG_WARNING __LOG_WARNING, _A_
-
-#ifdef LOG_ERROR
-#undef LOG_ERROR
-#endif
-#define __LOG_ERROR 4
-#define LOG_ERROR __LOG_ERROR, _A_
-
-#ifdef LOG_VERBOSE
-#undef LOG_VERBOSE
-#endif
-#define __LOG_VERBOSE 5
-#define LOG_VERBOSE __LOG_VERBOSE, _A_
-
-#ifdef LOG_DTMF
-#undef LOG_DTMF
-#endif
-#define __LOG_DTMF 6
-#define LOG_DTMF __LOG_DTMF, _A_
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_LOGGER_H */
diff --git a/1.2-netsec/include/asterisk/manager.h b/1.2-netsec/include/asterisk/manager.h
deleted file mode 100644
index dc1e30063..000000000
--- a/1.2-netsec/include/asterisk/manager.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#ifndef _ASTERISK_MANAGER_H
-#define _ASTERISK_MANAGER_H
-
-#include <stdarg.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "asterisk/lock.h"
-
-/*!
- \file
- \brief The AMI - Asterisk Manager Interface - is a TCP protocol created to
- manage Asterisk with third-party software.
-
- Manager protocol packages are text fields of the form a: b. There is
- always exactly one space after the colon.
-
- The first header type is the "Event" header. Other headers vary from
- event to event. Headers end with standard \r\n termination.
- The last line of the manager response or event is an empty line.
- (\r\n)
-
- ** Please try to re-use existing headers to simplify manager message parsing in clients.
- Don't re-use an existing header with a new meaning, please.
- You can find a reference of standard headers in doc/manager.txt
- */
-
-#define DEFAULT_MANAGER_PORT 5038 /* Default port for Asterisk management via TCP */
-
-#define EVENT_FLAG_SYSTEM (1 << 0) /* System events such as module load/unload */
-#define EVENT_FLAG_CALL (1 << 1) /* Call event, such as state change, etc */
-#define EVENT_FLAG_LOG (1 << 2) /* Log events */
-#define EVENT_FLAG_VERBOSE (1 << 3) /* Verbose messages */
-#define EVENT_FLAG_COMMAND (1 << 4) /* Ability to read/set commands */
-#define EVENT_FLAG_AGENT (1 << 5) /* Ability to read/set agent info */
-#define EVENT_FLAG_USER (1 << 6) /* Ability to read/set user info */
-
-/* Export manager structures */
-#define AST_MAX_MANHEADERS 80
-#define AST_MAX_MANHEADER_LEN 256
-
-struct eventqent {
- struct eventqent *next;
- char eventdata[1];
-};
-
-struct mansession {
- /*! Execution thread */
- pthread_t t;
- /*! Thread lock -- don't use in action callbacks, it's already taken care of */
- ast_mutex_t __lock;
- /*! socket address */
- struct sockaddr_in sin;
- /*! TCP socket */
- int fd;
- /*! Whether or not we're busy doing an action */
- int busy;
- /*! Whether or not we're "dead" */
- int dead;
- /*! Logged in username */
- char username[80];
- /*! Authentication challenge */
- char challenge[10];
- /*! Authentication status */
- int authenticated;
- /*! Authorization for reading */
- int readperm;
- /*! Authorization for writing */
- int writeperm;
- /*! Buffer */
- char inbuf[AST_MAX_MANHEADER_LEN];
- int inlen;
- int send_events;
- /* Queued events that we've not had the ability to send yet */
- struct eventqent *eventq;
- /* Timeout for ast_carefulwrite() */
- int writetimeout;
- struct mansession *next;
-};
-
-
-struct message {
- int hdrcount;
- char headers[AST_MAX_MANHEADERS][AST_MAX_MANHEADER_LEN];
-};
-
-struct manager_action {
- /*! Name of the action */
- const char *action;
- /*! Short description of the action */
- const char *synopsis;
- /*! Detailed description of the action */
- const char *description;
- /*! Permission required for action. EVENT_FLAG_* */
- int authority;
- /*! Function to be called */
- int (*func)(struct mansession *s, struct message *m);
- /*! For easy linking */
- struct manager_action *next;
-};
-
-int ast_carefulwrite(int fd, char *s, int len, int timeoutms);
-
-/* External routines may register/unregister manager callbacks this way */
-#define ast_manager_register(a, b, c, d) ast_manager_register2(a, b, c, d, NULL)
-
-/* Use ast_manager_register2 to register with help text for new manager commands */
-
-/*! Register a manager command with the manager interface */
-/*! \param action Name of the requested Action:
- \param authority Required authority for this command
- \param func Function to call for this command
- \param synopsis Help text (one line, up to 30 chars) for CLI manager show commands
- \param description Help text, several lines
-*/
-int ast_manager_register2(
- const char *action,
- int authority,
- int (*func)(struct mansession *s, struct message *m),
- const char *synopsis,
- const char *description);
-
-/*! Unregister a registred manager command */
-/*! \param action Name of registred Action:
-*/
-int ast_manager_unregister( char *action );
-
-/*! External routines may send asterisk manager events this way */
-/*! \param category Event category, matches manager authorization
- \param event Event name
- \param contents Contents of event
-*/
-extern int manager_event(int category, char *event, char *contents, ...)
- __attribute__ ((format (printf, 3,4)));
-
-/*! Get header from mananger transaction */
-extern char *astman_get_header(struct message *m, char *var);
-
-/*! Get a linked list of the Variable: headers */
-struct ast_variable *astman_get_variables(struct message *m);
-
-/*! Send error in manager transaction */
-extern void astman_send_error(struct mansession *s, struct message *m, char *error);
-extern void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg);
-extern void astman_send_ack(struct mansession *s, struct message *m, char *msg);
-
-/*! Called by Asterisk initialization */
-extern int init_manager(void);
-/*! Called by Asterisk initialization */
-extern int reload_manager(void);
-
-#endif /* _ASTERISK_MANAGER_H */
diff --git a/1.2-netsec/include/asterisk/md5.h b/1.2-netsec/include/asterisk/md5.h
deleted file mode 100644
index f738bd5b6..000000000
--- a/1.2-netsec/include/asterisk/md5.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*!\file
- * \brief MD5 digest functions
- */
-
-#ifndef _ASTERISK_MD5_H
-#define _ASTERISK_MD5_H
-
-#include <inttypes.h>
-
-struct MD5Context {
- uint32_t buf[4];
- uint32_t bits[2];
- unsigned char in[64];
-};
-
-void MD5Init(struct MD5Context *context);
-void MD5Update(struct MD5Context *context, unsigned char const *buf,
- unsigned len);
-void MD5Final(unsigned char digest[16], struct MD5Context *context);
-void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
-
-#endif /* _ASTERISK_MD5_H */
diff --git a/1.2-netsec/include/asterisk/module.h b/1.2-netsec/include/asterisk/module.h
deleted file mode 100644
index afb90ce24..000000000
--- a/1.2-netsec/include/asterisk/module.h
+++ /dev/null
@@ -1,419 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Asterisk module definitions.
- *
- * This file contains the definitons for functions Asterisk modules should
- * provide and some other module related functions.
- */
-
-#ifndef _ASTERISK_MODULE_H
-#define _ASTERISK_MODULE_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/* Every module should provide these functions */
-
-/*!
- * \brief Initialize the module.
- *
- * This function is called at module load time. Put all code in here
- * that needs to set up your module's hardware, software, registrations,
- * etc.
- *
- * \return This function should return 0 on success and non-zero on failure.
- * If the module is not loaded successfully, Asterisk will call its
- * unload_module() function.
- */
-int load_module(void);
-
-/*!
- * \brief Cleanup all module structures, sockets, etc.
- *
- * This is called at exit. Any registrations and memory allocations need to be
- * unregistered and free'd here. Nothing else will do these for you (until
- * exit).
- *
- * \return Zero on success, or non-zero on error.
- */
-int unload_module(void);
-
-/*!
- * \brief Provides a usecount.
- *
- * This function will be called by various parts of asterisk. Basically, all
- * it has to do is to return a usecount when called. You will need to maintain
- * your usecount within the module somewhere. The usecount should be how many
- * channels provided by this module are in use.
- *
- * \return The module's usecount.
- */
-int usecount(void); /* How many channels provided by this module are in use? */
-
-/*! \brief Provides a description of the module.
- *
- * \return a short description of your module
- */
-char *description(void); /* Description of this module */
-
-/*!
- * \brief Returns the ASTERISK_GPL_KEY
- *
- * This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of
- * the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does
- * not return the EXACT message:
- *
- * \code
- * char *key(void) {
- * return ASTERISK_GPL_KEY;
- * }
- * \endcode
- *
- * \return ASTERISK_GPL_KEY
- */
-char *key(void); /* Return the below mentioned key, unmodified */
-
-/*!
- * \brief Reload stuff.
- *
- * This function is where any reload routines take place. Re-read config files,
- * change signalling, whatever is appropriate on a reload.
- *
- * \return The return value is not used.
- */
-int reload(void); /* reload configs */
-
-/*! \brief The text the key() function should return. */
-#define ASTERISK_GPL_KEY \
- "This paragraph is Copyright (C) 2000, Linux Support Services, Inc. \
-In order for your module to load, it must return this key via a function \
-called \"key\". Any code which includes this paragraph must be licensed under \
-the GNU General Public License version 2 or later (at your option). Linux \
-Support Services, Inc. reserves the right to allow other parties to license \
-this paragraph under other terms as well."
-
-#define AST_MODULE_CONFIG "modules.conf" /*!< \brief Module configuration file */
-
-/*!
- * \brief Softly unload a module.
- *
- * This flag signals ast_unload_resource() to unload a module only if it is not
- * in use, according to the module's usecount.
- */
-#define AST_FORCE_SOFT 0
-
-/*!
- * \brief Firmly unload a module.
- *
- * This flag signals ast_unload_resource() to attempt to unload a module even
- * if it is in use. It will attempt to use the module's unload_module
- * function.
- */
-#define AST_FORCE_FIRM 1
-
-/*!
- * \brief Unconditionally unload a module.
- *
- * This flag signals ast_unload_resource() to first attempt to unload a module
- * using the module's unload_module function, then if that fails to unload the
- * module using dlclose. The module will be unloaded even if it is still in
- * use. Use of this flag is not recommended.
- */
-#define AST_FORCE_HARD 2
-
-/*!
- * \brief Load a module.
- * \param resource_name The filename of the module to load.
- *
- * This function is run by the PBX to load the modules. It performs
- * all loading and initilization tasks. Basically, to load a module, just
- * give it the name of the module and it will do the rest.
- *
- * \return Zero on success, -1 on error.
- */
-int ast_load_resource(const char *resource_name);
-
-/*!
- * \brief Unloads a module.
- * \param resource_name The name of the module to unload.
- * \param force The force flag. This should be set using one of the AST_FORCE*
- * flags.
- *
- * This function unloads a module. It will only unload modules that are not in
- * use (usecount not zero), unless #AST_FORCE_FIRM or #AST_FORCE_HARD is
- * specified. Setting #AST_FORCE_FIRM or #AST_FORCE_HARD will unload the
- * module regardless of consequences (NOT_RECOMMENDED).
- *
- * \return Zero on success, -1 on error.
- */
-int ast_unload_resource(const char *resource_name, int force);
-
-/*!
- * \brief Notify when usecount has been changed.
- *
- * This function calulates use counts and notifies anyone trying to keep track
- * of them. It should be called whenever your module's usecount changes.
- *
- * \note The LOCAL_USER macros take care of calling this function for you.
- */
-void ast_update_use_count(void);
-
-/*!
- * \brief Ask for a list of modules, descriptions, and use counts.
- * \param modentry A callback to an updater function.
- * \param like
- *
- * For each of the modules loaded, modentry will be executed with the resource,
- * description, and usecount values of each particular module.
- *
- * \return the number of modules loaded
- */
-int ast_update_module_list(int (*modentry)(const char *module, const char *description, int usecnt, const char *like),
- const char *like);
-
-/*!
- * \brief Add a procedure to be run when modules have been updated.
- * \param updater The function to run when modules have been updated.
- *
- * This function adds the given function to a linked list of functions to be
- * run when the modules are updated.
- *
- * \return Zero on success and -1 on failure.
- */
-int ast_loader_register(int (*updater)(void));
-
-/*!
- * \brief Remove a procedure to be run when modules are updated.
- * \param updater The updater function to unregister.
- *
- * This removes the given function from the updater list.
- *
- * \return Zero on success, -1 on failure.
- */
-int ast_loader_unregister(int (*updater)(void));
-
-/*!
- * \brief Reload asterisk modules.
- * \param name the name of the module to reload
- *
- * This function reloads the specified module, or if no modules are specified,
- * it will reload all loaded modules.
- *
- * \note Modules are reloaded using their reload() functions, not unloading
- * them and loading them again.
- *
- * \return Zero if the specified module was not found, 1 if the module was
- * found but cannot be reloaded, -1 if a reload operation is already in
- * progress, and 2 if the specfied module was found and reloaded.
- */
-int ast_module_reload(const char *name);
-
-/*!
- * \brief Match modules names for the Asterisk cli.
- * \param line Unused by this function, but this should be the line we are
- * matching.
- * \param word The partial name to match.
- * \param pos The position the word we are completing is in.
- * \param state The possible match to return.
- * \param rpos The position we should be matching. This should be the same as
- * pos.
- * \param needsreload This should be 1 if we need to reload this module and 0
- * otherwise. This function will only return modules that are reloadble
- * if this is 1.
- *
- * \return A possible completion of the partial match, or NULL if no matches
- * were found.
- */
-char *ast_module_helper(char *line, char *word, int pos, int state, int rpos, int needsreload);
-
-/*!
- * \brief Register a function to be executed before Asterisk exits.
- * \param func The callback function to use.
- *
- * \return Zero on success, -1 on error.
- */
-int ast_register_atexit(void (*func)(void));
-
-/*!
- * \brief Unregister a function registered with ast_register_atexit().
- * \param func The callback function to unregister.
- */
-void ast_unregister_atexit(void (*func)(void));
-
-/* Local user routines keep track of which channels are using a given module
- resource. They can help make removing modules safer, particularly if
- they're in use at the time they have been requested to be removed */
-
-/*!
- * \brief Standard localuser struct definition.
- *
- * This macro defines a localuser struct. The channel.h file must be included
- * to use this macro because it refrences ast_channel.
- */
-#define STANDARD_LOCAL_USER struct localuser { \
- struct ast_channel *chan; \
- struct localuser *next; \
- }
-
-/*!
- * \brief The localuser declaration.
- *
- * This macro should be used in combination with #STANDARD_LOCAL_USER. It
- * creates a localuser mutex and several other variables used for keeping the
- * use count.
- *
- * <b>Sample Usage:</b>
- * \code
- * STANDARD_LOCAL_USER;
- * LOCAL_USER_DECL;
- * \endcode
- */
-#define LOCAL_USER_DECL AST_MUTEX_DEFINE_STATIC(localuser_lock); \
- static struct localuser *localusers = NULL; \
- static int localusecnt = 0;
-
-#define STANDARD_INCREMENT_USECOUNT \
- ast_mutex_lock(&localuser_lock); \
- localusecnt++; \
- ast_mutex_unlock(&localuser_lock); \
- ast_update_use_count();
-
-#define STANDARD_DECREMENT_USECOUNT \
- ast_mutex_lock(&localuser_lock); \
- localusecnt--; \
- ast_mutex_unlock(&localuser_lock); \
- ast_update_use_count();
-
-/*!
- * \brief Add a localuser.
- * \param u a pointer to a localuser struct
- *
- * This macro adds a localuser to the list of users and increments the
- * usecount. It expects a variable named \p chan of type \p ast_channel in the
- * current scope.
- *
- * \note This function dynamically allocates memory. If this operation fails
- * it will cause your function to return -1 to the caller.
- */
-#define LOCAL_USER_ADD(u) { \
- \
- if (!(u=calloc(1,sizeof(*u)))) { \
- ast_log(LOG_WARNING, "Out of memory\n"); \
- return -1; \
- } \
- ast_mutex_lock(&localuser_lock); \
- u->chan = chan; \
- u->next = localusers; \
- localusers = u; \
- localusecnt++; \
- ast_mutex_unlock(&localuser_lock); \
- ast_update_use_count(); \
-}
-
-#define LOCAL_USER_ACF_ADD(u) { \
- \
- if (!(u=calloc(1,sizeof(*u)))) { \
- ast_log(LOG_WARNING, "Out of memory\n"); \
- return ""; \
- } \
- ast_mutex_lock(&localuser_lock); \
- u->chan = chan; \
- u->next = localusers; \
- localusers = u; \
- localusecnt++; \
- ast_mutex_unlock(&localuser_lock); \
- ast_update_use_count(); \
-}
-
-/*!
- * \brief Remove a localuser.
- * \param u the user to add, should be of type struct localuser
- *
- * This macro removes a localuser from the list of users and decrements the
- * usecount.
- */
-#define LOCAL_USER_REMOVE(u) { \
- struct localuser *uc, *ul = NULL; \
- ast_mutex_lock(&localuser_lock); \
- uc = localusers; \
- while (uc) { \
- if (uc == u) { \
- if (ul) \
- ul->next = uc->next; \
- else \
- localusers = uc->next; \
- break; \
- } \
- ul = uc; \
- uc = uc->next; \
- }\
- free(u); \
- localusecnt--; \
- ast_mutex_unlock(&localuser_lock); \
- ast_update_use_count(); \
-}
-
-/*!
- * \brief Hangup all localusers.
- *
- * This macro hangs up on all current localusers and sets the usecount to zero
- * when finished.
- */
-#define STANDARD_HANGUP_LOCALUSERS { \
- struct localuser *u, *ul; \
- ast_mutex_lock(&localuser_lock); \
- u = localusers; \
- while(u) { \
- ast_softhangup(u->chan, AST_SOFTHANGUP_APPUNLOAD); \
- ul = u; \
- u = u->next; \
- free(ul); \
- } \
- localusecnt=0; \
- ast_mutex_unlock(&localuser_lock); \
- ast_update_use_count(); \
-}
-
-/*!
- * \brief Set the specfied integer to the current usecount.
- * \param res the integer variable to set.
- *
- * This macro sets the specfied integer variable to the local usecount.
- *
- * <b>Sample Usage:</b>
- * \code
- * int usecount(void)
- * {
- * int res;
- * STANDARD_USECOUNT(res);
- * return res;
- * }
- * \endcode
- */
-#define STANDARD_USECOUNT(res) { \
- res = localusecnt; \
-}
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_MODULE_H */
diff --git a/1.2-netsec/include/asterisk/monitor.h b/1.2-netsec/include/asterisk/monitor.h
deleted file mode 100644
index ff482f847..000000000
--- a/1.2-netsec/include/asterisk/monitor.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Channel monitoring
- */
-
-#ifndef _ASTERISK_MONITOR_H
-#define _ASTERISK_MONITOR_H
-
-#include "asterisk/channel.h"
-
-struct ast_channel;
-
-/*! Responsible for channel monitoring data */
-struct ast_channel_monitor {
- struct ast_filestream *read_stream;
- struct ast_filestream *write_stream;
- char read_filename[FILENAME_MAX];
- char write_filename[FILENAME_MAX];
- char filename_base[FILENAME_MAX];
- int filename_changed;
- char *format;
- int joinfiles;
- int (*stop)(struct ast_channel *chan, int need_lock);
-};
-
-/* Start monitoring a channel */
-int ast_monitor_start(struct ast_channel *chan, const char *format_spec,
- const char *fname_base, int need_lock );
-
-/* Stop monitoring a channel */
-int ast_monitor_stop(struct ast_channel *chan, int need_lock);
-
-/* Change monitoring filename of a channel */
-int ast_monitor_change_fname(struct ast_channel *chan,
- const char *fname_base, int need_lock);
-
-void ast_monitor_setjoinfiles(struct ast_channel *chan, int turnon);
-
-#endif /* _ASTERISK_MONITOR_H */
diff --git a/1.2-netsec/include/asterisk/musiconhold.h b/1.2-netsec/include/asterisk/musiconhold.h
deleted file mode 100644
index 8a0bf6417..000000000
--- a/1.2-netsec/include/asterisk/musiconhold.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Music on hold handling
- */
-
-#ifndef _ASTERISK_MOH_H
-#define _ASTERISK_MOH_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/*! Turn on music on hold on a given channel */
-extern int ast_moh_start(struct ast_channel *chan, char *mclass);
-
-/*! Turn off music on hold on a given channel */
-extern void ast_moh_stop(struct ast_channel *chan);
-
-extern void ast_install_music_functions(int (*start_ptr)(struct ast_channel *, char *),
- void (*stop_ptr)(struct ast_channel *),
- void (*cleanup_ptr)(struct ast_channel *));
-
-extern void ast_uninstall_music_functions(void);
-void ast_moh_cleanup(struct ast_channel *chan);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_MOH_H */
diff --git a/1.2-netsec/include/asterisk/netsock.h b/1.2-netsec/include/asterisk/netsock.h
deleted file mode 100644
index 73a2dd224..000000000
--- a/1.2-netsec/include/asterisk/netsock.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- * Kevin P. Fleming <kpfleming@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Network socket handling
- */
-
-#ifndef _ASTERISK_NETSOCK_H
-#define _ASTERISK_NETSOCK_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#include <netinet/in.h>
-#include "asterisk/io.h"
-#include "asterisk/astobj.h"
-
-struct ast_netsock;
-
-struct ast_netsock_list;
-
-struct ast_netsock_list *ast_netsock_list_alloc(void);
-
-int ast_netsock_init(struct ast_netsock_list *list);
-
-struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_context *ioc,
- const char *bindinfo, int defaultport, int tos, ast_io_cb callback, void *data);
-
-struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct io_context *ioc,
- struct sockaddr_in *bindaddr, int tos, ast_io_cb callback, void *data);
-
-int ast_netsock_free(struct ast_netsock_list *list, struct ast_netsock *netsock);
-
-int ast_netsock_release(struct ast_netsock_list *list);
-
-struct ast_netsock *ast_netsock_find(struct ast_netsock_list *list,
- struct sockaddr_in *sa);
-
-int ast_netsock_sockfd(const struct ast_netsock *ns);
-
-const struct sockaddr_in *ast_netsock_boundaddr(const struct ast_netsock *ns);
-
-void *ast_netsock_data(const struct ast_netsock *ns);
-
-void ast_netsock_unref(struct ast_netsock *ns);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_NETSOCK_H */
diff --git a/1.2-netsec/include/asterisk/options.h b/1.2-netsec/include/asterisk/options.h
deleted file mode 100644
index fd8f3aadb..000000000
--- a/1.2-netsec/include/asterisk/options.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Options provided by main asterisk program
- */
-
-#ifndef _ASTERISK_OPTIONS_H
-#define _ASTERISK_OPTIONS_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#define AST_CACHE_DIR_LEN 512
-#define AST_FILENAME_MAX 80
-
-extern int option_verbose;
-extern int option_debug;
-extern int option_nofork;
-extern int option_quiet;
-extern int option_console;
-extern int option_initcrypto;
-extern int option_nocolor;
-extern int fully_booted;
-extern int option_exec_includes;
-extern int option_cache_record_files;
-extern int option_timestamp;
-extern int option_transcode_slin;
-extern int option_transmit_silence_during_record;
-extern int option_maxcalls;
-extern double option_maxload;
-extern int option_dontwarn;
-extern int option_priority_jumping;
-extern char defaultlanguage[];
-extern time_t ast_startuptime;
-extern time_t ast_lastreloadtime;
-extern int ast_mainpid;
-extern char record_cache_dir[AST_CACHE_DIR_LEN];
-extern char debug_filename[AST_FILENAME_MAX];
-
-#define VERBOSE_PREFIX_1 " "
-#define VERBOSE_PREFIX_2 " == "
-#define VERBOSE_PREFIX_3 " -- "
-#define VERBOSE_PREFIX_4 " > "
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_OPTIONS_H */
diff --git a/1.2-netsec/include/asterisk/pbx.h b/1.2-netsec/include/asterisk/pbx.h
deleted file mode 100644
index d2902002c..000000000
--- a/1.2-netsec/include/asterisk/pbx.h
+++ /dev/null
@@ -1,665 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Core PBX routines and definitions.
- */
-
-#ifndef _ASTERISK_PBX_H
-#define _ASTERISK_PBX_H
-
-#include "asterisk/sched.h"
-#include "asterisk/channel.h"
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#define AST_PBX_KEEP 0
-#define AST_PBX_REPLACE 1
-
-/*! Max length of an application */
-#define AST_MAX_APP 32
-
-/*! Special return values from applications to the PBX */
-#define AST_PBX_KEEPALIVE 10 /* Destroy the thread, but don't hang up the channel */
-#define AST_PBX_NO_HANGUP_PEER 11
-
-/*! Special Priority for an hint */
-#define PRIORITY_HINT -1
-
-/*! Extension states */
-enum ast_extension_states {
- /*! Extension removed */
- AST_EXTENSION_REMOVED = -2,
- /*! Extension hint removed */
- AST_EXTENSION_DEACTIVATED = -1,
- /*! No device INUSE or BUSY */
- AST_EXTENSION_NOT_INUSE = 0,
- /*! One or more devices INUSE */
- AST_EXTENSION_INUSE = 1 << 0,
- /*! All devices BUSY */
- AST_EXTENSION_BUSY = 1 << 1,
- /*! All devices UNAVAILABLE/UNREGISTERED */
- AST_EXTENSION_UNAVAILABLE = 1 << 2,
- /*! All devices RINGING */
- AST_EXTENSION_RINGING = 1 << 3,
-};
-
-
-static const struct cfextension_states {
- int extension_state;
- const char * const text;
-} extension_states[] = {
- { AST_EXTENSION_NOT_INUSE, "Idle" },
- { AST_EXTENSION_INUSE, "InUse" },
- { AST_EXTENSION_BUSY, "Busy" },
- { AST_EXTENSION_UNAVAILABLE, "Unavailable" },
- { AST_EXTENSION_RINGING, "Ringing" },
- { AST_EXTENSION_INUSE | AST_EXTENSION_RINGING, "InUse&Ringing" }
-};
-
-struct ast_context;
-struct ast_exten;
-struct ast_include;
-struct ast_ignorepat;
-struct ast_sw;
-
-typedef int (*ast_state_cb_type)(char *context, char* id, enum ast_extension_states state, void *data);
-
-/*! Data structure associated with a custom function */
-struct ast_custom_function {
- char *name;
- char *synopsis;
- char *desc;
- char *syntax;
- char *(*read)(struct ast_channel *, char *, char *, char *, size_t);
- void (*write)(struct ast_channel *, char *, char *, const char *);
- struct ast_custom_function *next;
-};
-
-/*! Data structure associated with an asterisk switch */
-struct ast_switch {
- /*! NULL */
- struct ast_switch *next;
- /*! Name of the switch */
- const char *name;
- /*! Description of the switch */
- const char *description;
-
- int (*exists)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
-
- int (*canmatch)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
-
- int (*exec)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data);
-
- int (*matchmore)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
-};
-
-struct ast_timing {
- int hastime; /* If time construct exists */
- unsigned int monthmask; /* Mask for month */
- unsigned int daymask; /* Mask for date */
- unsigned int dowmask; /* Mask for day of week (mon-sun) */
- unsigned int minmask[24]; /* Mask for minute */
-};
-
-extern int ast_build_timing(struct ast_timing *i, char *info);
-extern int ast_check_timing(struct ast_timing *i);
-
-struct ast_pbx {
- int dtimeout; /* Timeout between digits (seconds) */
- int rtimeout; /* Timeout for response
- (seconds) */
-};
-
-
-/*! Register an alternative switch */
-/*!
- * \param sw switch to register
- * This function registers a populated ast_switch structure with the
- * asterisk switching architecture.
- * It returns 0 on success, and other than 0 on failure
- */
-extern int ast_register_switch(struct ast_switch *sw);
-
-/*! Unregister an alternative switch */
-/*!
- * \param sw switch to unregister
- * Unregisters a switch from asterisk.
- * Returns nothing
- */
-extern void ast_unregister_switch(struct ast_switch *sw);
-
-/*! Look up an application */
-/*!
- * \param app name of the app
- * This function searches for the ast_app structure within
- * the apps that are registered for the one with the name
- * you passed in.
- * Returns the ast_app structure that matches on success, or NULL on failure
- */
-extern struct ast_app *pbx_findapp(const char *app);
-
-/*! executes an application */
-/*!
- * \param c channel to execute on
- * \param app which app to execute
- * \param data the data passed into the app
- * \param newstack stack pointer
- * This application executes an application on a given channel. It
- * saves the stack and executes the given appliation passing in
- * the given data.
- * It returns 0 on success, and -1 on failure
- */
-int pbx_exec(struct ast_channel *c, struct ast_app *app, void *data, int newstack);
-
-/*! Register a new context */
-/*!
- * \param extcontexts pointer to the ast_context structure pointer
- * \param name name of the new context
- * \param registrar registrar of the context
- * This will first search for a context with your name. If it exists already, it will not
- * create a new one. If it does not exist, it will create a new one with the given name
- * and registrar.
- * It returns NULL on failure, and an ast_context structure on success
- */
-struct ast_context *ast_context_create(struct ast_context **extcontexts, const char *name, const char *registrar);
-
-/*! Merge the temporary contexts into a global contexts list and delete from the global list the ones that are being added */
-/*!
- * \param extcontexts pointer to the ast_context structure pointer
- * \param registrar of the context; if it's set the routine will delete all contexts that belong to that registrar; if NULL only the contexts that are specified in extcontexts
- */
-void ast_merge_contexts_and_delete(struct ast_context **extcontexts, const char *registrar);
-
-/*! Destroy a context (matches the specified context (or ANY context if NULL) */
-/*!
- * \param con context to destroy
- * \param registrar who registered it
- * You can optionally leave out either parameter. It will find it
- * based on either the ast_context or the registrar name.
- * Returns nothing
- */
-void ast_context_destroy(struct ast_context *con, const char *registrar);
-
-/*! Find a context */
-/*!
- * \param name name of the context to find
- * Will search for the context with the given name.
- * Returns the ast_context on success, NULL on failure.
- */
-struct ast_context *ast_context_find(const char *name);
-
-enum ast_pbx_result {
- AST_PBX_SUCCESS = 0,
- AST_PBX_FAILED = -1,
- AST_PBX_CALL_LIMIT = -2,
-};
-
-/*! Create a new thread and start the PBX (or whatever) */
-/*!
- * \param c channel to start the pbx on
- * \return Zero on success, non-zero on failure
- */
-enum ast_pbx_result ast_pbx_start(struct ast_channel *c);
-
-/*! Execute the PBX in the current thread */
-/*!
- * \param c channel to run the pbx on
- * \return Zero on success, non-zero on failure
- * This executes the PBX on a given channel. It allocates a new
- * PBX structure for the channel, and provides all PBX functionality.
- */
-enum ast_pbx_result ast_pbx_run(struct ast_channel *c);
-
-/*!
- * \param context context to add the extension to
- * \param replace
- * \param extension extension to add
- * \param priority priority level of extension addition
- * \param label extension label
- * \param callerid callerid of extension
- * \param application application to run on the extension with that priority level
- * \param data data to pass to the application
- * \param datad
- * \param registrar who registered the extension
- * Add and extension to an extension context.
- * Callerid is a pattern to match CallerID, or NULL to match any callerid
- * Returns 0 on success, -1 on failure
- */
-int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid,
- const char *application, void *data, void (*datad)(void *), const char *registrar);
-
-/*! Add an extension to an extension context, this time with an ast_context *. CallerID is a pattern to match on callerid, or NULL to not care about callerid */
-/*!
- * For details about the arguements, check ast_add_extension()
- */
-int ast_add_extension2(struct ast_context *con,
- int replace, const char *extension, int priority, const char *label, const char *callerid,
- const char *application, void *data, void (*datad)(void *),
- const char *registrar);
-
-/*! Add an application. The function 'execute' should return non-zero if the line needs to be hung up. */
-/*!
- \param app Short name of the application
- \param execute a function callback to execute the application
- \param synopsis a short description of the application
- \param description long description of the application
- Include a one-line synopsis (e.g. 'hangs up a channel') and a more lengthy, multiline
- description with more detail, including under what conditions the application
- will return 0 or -1.
- This registers an application with asterisks internal application list. Please note:
- The individual applications themselves are responsible for registering and unregistering
- CLI commands.
- It returns 0 on success, -1 on failure.
-*/
-int ast_register_application(const char *app, int (*execute)(struct ast_channel *, void *),
- const char *synopsis, const char *description);
-
-/*! Remove an application */
-/*!
- * \param app name of the application (does not have to be the same string as the one that was registered)
- * This unregisters an application from asterisk's internal registration mechanisms.
- * It returns 0 on success, and -1 on failure.
- */
-int ast_unregister_application(const char *app);
-
-/*! Uses hint and devicestate callback to get the state of an extension */
-/*!
- * \param c this is not important
- * \param context which context to look in
- * \param exten which extension to get state
- * Returns extension state !! = AST_EXTENSION_???
- */
-int ast_extension_state(struct ast_channel *c, char *context, char *exten);
-
-/*! Return string of the state of an extension */
-/*!
- * \param extension_state is the numerical state delivered by ast_extension_state
- * Returns the state of an extension as string
- */
-const char *ast_extension_state2str(int extension_state);
-
-/*! Registers a state change callback */
-/*!
- * \param context which context to look in
- * \param exten which extension to get state
- * \param callback callback to call if state changed
- * \param data to pass to callback
- * The callback is called if the state for extension is changed
- * Return -1 on failure, ID on success
- */
-int ast_extension_state_add(const char *context, const char *exten,
- ast_state_cb_type callback, void *data);
-
-/*! Deletes a registered state change callback by ID */
-/*!
- * \param id of the callback to delete
- * \param callback callback
- * Removes the callback from list of callbacks
- * Return 0 on success, -1 on failure
- */
-int ast_extension_state_del(int id, ast_state_cb_type callback);
-
-/*! If an extension exists, return non-zero */
-/*!
- * \param hint buffer for hint
- * \param maxlen size of hint buffer
- * \param name buffer for name portion of hint
- * \param maxnamelen size of name buffer
- * \param c this is not important
- * \param context which context to look in
- * \param exten which extension to search for
- * If an extension within the given context with the priority PRIORITY_HINT
- * is found a non zero value will be returned.
- * Otherwise, 0 is returned.
- */
-int ast_get_hint(char *hint, int maxlen, char *name, int maxnamelen, struct ast_channel *c, const char *context, const char *exten);
-
-/*! If an extension exists, return non-zero */
-/* work */
-/*!
- * \param c this is not important
- * \param context which context to look in
- * \param exten which extension to search for
- * \param priority priority of the action within the extension
- * \param callerid callerid to search for
- * If an extension within the given context(or callerid) with the given priority is found a non zero value will be returned.
- * Otherwise, 0 is returned.
- */
-int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
-
-/*! If an extension exists, return non-zero */
-/* work */
-/*!
- * \param c this is not important
- * \param context which context to look in
- * \param exten which extension to search for
- * \param label label of the action within the extension to match to priority
- * \param callerid callerid to search for
- * If an priority which matches given label in extension or -1 if not found.
-\ */
-int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid);
-
-int ast_findlabel_extension2(struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid);
-
-/*! Looks for a valid matching extension */
-/*!
- \param c not really important
- \param context context to serach within
- \param exten extension to check
- \param priority priority of extension path
- \param callerid callerid of extension being searched for
- If "exten" *could be* a valid extension in this context with or without
- some more digits, return non-zero. Basically, when this returns 0, no matter
- what you add to exten, it's not going to be a valid extension anymore
-*/
-int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
-
-/*! Looks to see if adding anything to this extension might match something. (exists ^ canmatch) */
-/*!
- \param c not really important
- \param context context to serach within
- \param exten extension to check
- \param priority priority of extension path
- \param callerid callerid of extension being searched for
- If "exten" *could match* a valid extension in this context with
- some more digits, return non-zero. Does NOT return non-zero if this is
- an exact-match only. Basically, when this returns 0, no matter
- what you add to exten, it's not going to be a valid extension anymore
-*/
-int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
-
-/*! Determine if a given extension matches a given pattern (in NXX format) */
-/*!
- * \param pattern pattern to match
- * \param extension extension to check against the pattern.
- * Checks whether or not the given extension matches the given pattern.
- * Returns 1 on match, 0 on failure
- */
-int ast_extension_match(const char *pattern, const char *extension);
-int ast_extension_close(const char *pattern, const char *data, int needmore);
-/*! Launch a new extension (i.e. new stack) */
-/*!
- * \param c not important
- * \param context which context to generate the extension within
- * \param exten new extension to add
- * \param priority priority of new extension
- * \param callerid callerid of extension
- * This adds a new extension to the asterisk extension list.
- * It returns 0 on success, -1 on failure.
- */
-int ast_spawn_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
-
-/*! Execute an extension. */
-/*!
- \param c channel to execute upon
- \param context which context extension is in
- \param exten extension to execute
- \param priority priority to execute within the given extension
- \param callerid Caller-ID
- If it's not available, do whatever you should do for
- default extensions and halt the thread if necessary. This function does not
- return, except on error.
-*/
-int ast_exec_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
-
-/*! Add an include */
-/*!
- \param context context to add include to
- \param include new include to add
- \param registrar who's registering it
- Adds an include taking a char * string as the context parameter
- Returns 0 on success, -1 on error
-*/
-int ast_context_add_include(const char *context, const char *include, const char *registrar);
-
-/*! Add an include */
-/*!
- \param con context to add the include to
- \param include include to add
- \param registrar who registered the context
- Adds an include taking a struct ast_context as the first parameter
- Returns 0 on success, -1 on failure
-*/
-int ast_context_add_include2(struct ast_context *con, const char *include, const char *registrar);
-
-/*! Removes an include */
-/*!
- * See add_include
- */
-int ast_context_remove_include(const char *context, const char *include,const char *registrar);
-/*! Removes an include by an ast_context structure */
-/*!
- * See add_include2
- */
-int ast_context_remove_include2(struct ast_context *con, const char *include, const char *registrar);
-
-/*! Verifies includes in an ast_contect structure */
-/*!
- * \param con context in which to verify the includes
- * Returns 0 if no problems found, -1 if there were any missing context
- */
-int ast_context_verify_includes(struct ast_context *con);
-
-/*! Add a switch */
-/*!
- * \param context context to which to add the switch
- * \param sw switch to add
- * \param data data to pass to switch
- * \param eval whether to evaluate variables when running switch
- * \param registrar whoever registered the switch
- * This function registers a switch with the asterisk switch architecture
- * It returns 0 on success, -1 on failure
- */
-int ast_context_add_switch(const char *context, const char *sw, const char *data, int eval, const char *registrar);
-/*! Adds a switch (first param is a ast_context) */
-/*!
- * See ast_context_add_switch()
- */
-int ast_context_add_switch2(struct ast_context *con, const char *sw, const char *data, int eval, const char *registrar);
-
-/*! Remove a switch */
-/*!
- * Removes a switch with the given parameters
- * Returns 0 on success, -1 on failure
- */
-int ast_context_remove_switch(const char *context, const char *sw, const char *data, const char *registrar);
-int ast_context_remove_switch2(struct ast_context *con, const char *sw, const char *data, const char *registrar);
-
-/*! Simply remove extension from context */
-/*!
- * \param context context to remove extension from
- * \param extension which extension to remove
- * \param priority priority of extension to remove
- * \param registrar registrar of the extension
- * This function removes an extension from a given context.
- * Returns 0 on success, -1 on failure
- */
-int ast_context_remove_extension(const char *context, const char *extension, int priority,
- const char *registrar);
-int ast_context_remove_extension2(struct ast_context *con, const char *extension,
- int priority, const char *registrar);
-
-/*! Add an ignorepat */
-/*!
- * \param context which context to add the ignorpattern to
- * \param ignorepat ignorepattern to set up for the extension
- * \param registrar registrar of the ignore pattern
- * Adds an ignore pattern to a particular context.
- * Returns 0 on success, -1 on failure
- */
-int ast_context_add_ignorepat(const char *context, const char *ignorepat, const char *registrar);
-int ast_context_add_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar);
-
-/* Remove an ignorepat */
-/*!
- * \param context context from which to remove the pattern
- * \param ignorepat the pattern to remove
- * \param registrar the registrar of the ignore pattern
- * This removes the given ignorepattern
- * Returns 0 on success, -1 on failure
- */
-int ast_context_remove_ignorepat(const char *context, const char *ignorepat, const char *registrar);
-int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar);
-
-/*! Checks to see if a number should be ignored */
-/*!
- * \param context context to search within
- * \param pattern to check whether it should be ignored or not
- * Check if a number should be ignored with respect to dialtone cancellation.
- * Returns 0 if the pattern should not be ignored, or non-zero if the pattern should be ignored
- */
-int ast_ignore_pattern(const char *context, const char *pattern);
-
-/* Locking functions for outer modules, especially for completion functions */
-/*! Locks the contexts */
-/*! Locks the context list
- * Returns 0 on success, -1 on error
- */
-int ast_lock_contexts(void);
-
-/*! Unlocks contexts */
-/*!
- * Returns 0 on success, -1 on failure
- */
-int ast_unlock_contexts(void);
-
-/*! Locks a given context */
-/*!
- * \param con context to lock
- * Locks the context.
- * Returns 0 on success, -1 on failure
- */
-int ast_lock_context(struct ast_context *con);
-/*! Unlocks the given context */
-/*!
- * \param con context to unlock
- * Unlocks the given context
- * Returns 0 on success, -1 on failure
- */
-int ast_unlock_context(struct ast_context *con);
-
-
-int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
-
-int ast_async_goto_by_name(const char *chan, const char *context, const char *exten, int priority);
-
-/* Synchronously or asynchronously make an outbound call and send it to a
- particular extension */
-int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel);
-
-/* Synchronously or asynchronously make an outbound call and send it to a
- particular application with given extension */
-int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel);
-
-/* Functions for returning values from structures */
-const char *ast_get_context_name(struct ast_context *con);
-const char *ast_get_extension_name(struct ast_exten *exten);
-const char *ast_get_include_name(struct ast_include *include);
-const char *ast_get_ignorepat_name(struct ast_ignorepat *ip);
-const char *ast_get_switch_name(struct ast_sw *sw);
-const char *ast_get_switch_data(struct ast_sw *sw);
-
-/* Other extension stuff */
-int ast_get_extension_priority(struct ast_exten *exten);
-int ast_get_extension_matchcid(struct ast_exten *e);
-const char *ast_get_extension_cidmatch(struct ast_exten *e);
-const char *ast_get_extension_app(struct ast_exten *e);
-const char *ast_get_extension_label(struct ast_exten *e);
-void *ast_get_extension_app_data(struct ast_exten *e);
-
-/* Registrar info functions ... */
-const char *ast_get_context_registrar(struct ast_context *c);
-const char *ast_get_extension_registrar(struct ast_exten *e);
-const char *ast_get_include_registrar(struct ast_include *i);
-const char *ast_get_ignorepat_registrar(struct ast_ignorepat *ip);
-const char *ast_get_switch_registrar(struct ast_sw *sw);
-
-/* Walking functions ... */
-struct ast_context *ast_walk_contexts(struct ast_context *con);
-struct ast_exten *ast_walk_context_extensions(struct ast_context *con,
- struct ast_exten *priority);
-struct ast_exten *ast_walk_extension_priorities(struct ast_exten *exten,
- struct ast_exten *priority);
-struct ast_include *ast_walk_context_includes(struct ast_context *con,
- struct ast_include *inc);
-struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con,
- struct ast_ignorepat *ip);
-struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw);
-
-int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size);
-extern char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name);
-extern void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value);
-extern void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value);
-extern void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp);
-extern void pbx_builtin_clear_globals(void);
-extern int pbx_builtin_setvar(struct ast_channel *chan, void *data);
-extern void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count);
-extern void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count);
-
-int ast_extension_patmatch(const char *pattern, const char *data);
-
-/* Set "autofallthrough" flag, if newval is <0, does not acutally set. If
- set to 1, sets to auto fall through. If newval set to 0, sets to no auto
- fall through (reads extension instead). Returns previous value. */
-extern int pbx_set_autofallthrough(int newval);
-int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority);
-/* I can find neither parsable nor parseable at dictionary.com, but google gives me 169000 hits for parseable and only 49,800 for parsable */
-int ast_parseable_goto(struct ast_channel *chan, const char *goto_string);
-int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
-int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority);
-
-struct ast_custom_function* ast_custom_function_find(char *name);
-int ast_custom_function_unregister(struct ast_custom_function *acf);
-int ast_custom_function_register(struct ast_custom_function *acf);
-
-/* Number of active calls */
-int ast_active_calls(void);
-
-/*! executes a read operation on a function */
-/*!
- * \param chan Channel to execute on
- * \param in Data containing the function call string
- * \param workspace A pointer to safe memory to use for a return value
- * \param len the number of bytes in workspace
- * This application executes an function in read mode on a given channel.
- * It returns a pointer to workspace if the buffer contains any new data
- * or NULL if there was a problem.
- */
-
-char *ast_func_read(struct ast_channel *chan, const char *in, char *workspace, size_t len);
-
-/*! executes a write operation on a function */
-/*!
- * \param chan Channel to execute on
- * \param in Data containing the function call string
- * \param value A value parameter to pass for writing
- * This application executes an function in write mode on a given channel.
- * It has no return value.
- */
-void ast_func_write(struct ast_channel *chan, const char *in, const char *value);
-
-void ast_hint_state_changed(const char *device);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_PBX_H */
diff --git a/1.2-netsec/include/asterisk/plc.h b/1.2-netsec/include/asterisk/plc.h
deleted file mode 100644
index a790ca167..000000000
--- a/1.2-netsec/include/asterisk/plc.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/*! \file
- * \brief SpanDSP - a series of DSP components for telephony
- *
- * plc.h
- *
- * \author Steve Underwood <steveu@coppice.org>
- *
- * Copyright (C) 2004 Steve Underwood
- *
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * This version may be optionally licenced under the GNU LGPL licence.
- * This version is disclaimed to DIGIUM for inclusion in the Asterisk project.
- */
-
-
-#if !defined(_PLC_H_)
-#define _PLC_H_
-
-#ifdef SOLARIS
-#include <sys/int_types.h>
-#else
-#if defined(__OpenBSD__) || defined( __FreeBSD__)
-#include <inttypes.h>
-#else
-#include <stdint.h>
-#endif
-#endif
-
-/*! \page plc_page Packet loss concealment
-\section plc_page_sec_1 What does it do?
-The packet loss concealment module provides a suitable synthetic fill-in signal,
-to minimise the audible effect of lost packets in VoIP applications. It is not
-tied to any particular codec, and could be used with almost any codec which does not
-specify its own procedure for packet loss concealment.
-
-Where a codec specific concealment procedure exists, the algorithm is usually built
-around knowledge of the characteristics of the particular codec. It will, therefore,
-generally give better results for that particular codec than this generic concealer will.
-
-\section plc_page_sec_2 How does it work?
-While good packets are being received, the plc_rx() routine keeps a record of the trailing
-section of the known speech signal. If a packet is missed, plc_fillin() is called to produce
-a synthetic replacement for the real speech signal. The average mean difference function
-(AMDF) is applied to the last known good signal, to determine its effective pitch.
-Based on this, the last pitch period of signal is saved. Essentially, this cycle of speech
-will be repeated over and over until the real speech resumes. However, several refinements
-are needed to obtain smooth pleasant sounding results.
-
-- The two ends of the stored cycle of speech will not always fit together smoothly. This can
- cause roughness, or even clicks, at the joins between cycles. To soften this, the
- 1/4 pitch period of real speech preceeding the cycle to be repeated is blended with the last
- 1/4 pitch period of the cycle to be repeated, using an overlap-add (OLA) technique (i.e.
- in total, the last 5/4 pitch periods of real speech are used).
-
-- The start of the synthetic speech will not always fit together smoothly with the tail of
- real speech passed on before the erasure was identified. Ideally, we would like to modify
- the last 1/4 pitch period of the real speech, to blend it into the synthetic speech. However,
- it is too late for that. We could have delayed the real speech a little, but that would
- require more buffer manipulation, and hurt the efficiency of the no-lost-packets case
- (which we hope is the dominant case). Instead we use a degenerate form of OLA to modify
- the start of the synthetic data. The last 1/4 pitch period of real speech is time reversed,
- and OLA is used to blend it with the first 1/4 pitch period of synthetic speech. The result
- seems quite acceptable.
-
-- As we progress into the erasure, the chances of the synthetic signal being anything like
- correct steadily fall. Therefore, the volume of the synthesized signal is made to decay
- linearly, such that after 50ms of missing audio it is reduced to silence.
-
-- When real speech resumes, an extra 1/4 pitch period of sythetic speech is blended with the
- start of the real speech. If the erasure is small, this smoothes the transition. If the erasure
- is long, and the synthetic signal has faded to zero, the blending softens the start up of the
- real signal, avoiding a kind of "click" or "pop" effect that might occur with a sudden onset.
-
-\section plc_page_sec_3 How do I use it?
-Before audio is processed, call plc_init() to create an instance of the packet loss
-concealer. For each received audio packet that is acceptable (i.e. not including those being
-dropped for being too late) call plc_rx() to record the content of the packet. Note this may
-modify the packet a little after a period of packet loss, to blend real synthetic data smoothly.
-When a real packet is not available in time, call plc_fillin() to create a sythetic substitute.
-That's it!
-*/
-
-#define SAMPLE_RATE 8000
-
-/*! Minimum allowed pitch (66 Hz) */
-#define PLC_PITCH_MIN 120
-/*! Maximum allowed pitch (200 Hz) */
-#define PLC_PITCH_MAX 40
-/*! Maximum pitch OLA window */
-#define PLC_PITCH_OVERLAP_MAX (PLC_PITCH_MIN >> 2)
-/*! The length over which the AMDF function looks for similarity (20 ms) */
-#define CORRELATION_SPAN 160
-/*! History buffer length. The buffer much also be at leat 1.25 times
- PLC_PITCH_MIN, but that is much smaller than the buffer needs to be for
- the pitch assessment. */
-#define PLC_HISTORY_LEN (CORRELATION_SPAN + PLC_PITCH_MIN)
-
-typedef struct
-{
- /*! Consecutive erased samples */
- int missing_samples;
- /*! Current offset into pitch period */
- int pitch_offset;
- /*! Pitch estimate */
- int pitch;
- /*! Buffer for a cycle of speech */
- float pitchbuf[PLC_PITCH_MIN];
- /*! History buffer */
- int16_t history[PLC_HISTORY_LEN];
- /*! Current pointer into the history buffer */
- int buf_ptr;
-} plc_state_t;
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*! Process a block of received audio samples.
- \brief Process a block of received audio samples.
- \param s The packet loss concealer context.
- \param amp The audio sample buffer.
- \param len The number of samples in the buffer.
- \return The number of samples in the buffer. */
-int plc_rx(plc_state_t *s, int16_t amp[], int len);
-
-/*! Fill-in a block of missing audio samples.
- \brief Fill-in a block of missing audio samples.
- \param s The packet loss concealer context.
- \param amp The audio sample buffer.
- \param len The number of samples to be synthesised.
- \return The number of samples synthesized. */
-int plc_fillin(plc_state_t *s, int16_t amp[], int len);
-
-/*! Process a block of received V.29 modem audio samples.
- \brief Process a block of received V.29 modem audio samples.
- \param s The packet loss concealer context.
- \return A pointer to the he packet loss concealer context. */
-plc_state_t *plc_init(plc_state_t *s);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-/*- End of file ------------------------------------------------------------*/
diff --git a/1.2-netsec/include/asterisk/poll-compat.h b/1.2-netsec/include/asterisk/poll-compat.h
deleted file mode 100644
index 5f795a894..000000000
--- a/1.2-netsec/include/asterisk/poll-compat.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * 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.
- */
-
-/*---------------------------------------------------------------------------*\
- $Id$
-
- NAME
-
- poll - select(2)-based poll() emulation function for BSD systems.
-
- SYNOPSIS
- #include "poll.h"
-
- struct pollfd
- {
- int fd;
- short events;
- short revents;
- }
-
- int poll (struct pollfd *pArray, unsigned long n_fds, int timeout)
-
- DESCRIPTION
-
- This file, and the accompanying "poll.c", implement the System V
- poll(2) system call for BSD systems (which typically do not provide
- poll()). Poll() provides a method for multiplexing input and output
- on multiple open file descriptors; in traditional BSD systems, that
- capability is provided by select(). While the semantics of select()
- differ from those of poll(), poll() can be readily emulated in terms
- of select() -- which is how this function is implemented.
-
- REFERENCES
- Stevens, W. Richard. Unix Network Programming. Prentice-Hall, 1990.
-
- NOTES
- 1. This software requires an ANSI C compiler.
-
- LICENSE
-
- This software is released under the following license:
-
- Copyright (c) 1995-2002 Brian M. Clapper
- All rights reserved.
-
- Redistribution and use in source and binary forms are
- permitted provided that: (1) source distributions retain
- this entire copyright notice and comment; (2) modifications
- made to the software are prominently mentioned, and a copy
- of the original software (or a pointer to its location) are
- included; and (3) distributions including binaries display
- the following acknowledgement: "This product includes
- software developed by Brian M. Clapper <bmc@clapper.org>"
- in the documentation or other materials provided with the
- distribution. The name of the author may not be used to
- endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS
- OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE.
-
- Effectively, this means you can do what you want with the software
- except remove this notice or take advantage of the author's name.
- If you modify the software and redistribute your modified version,
- you must indicate that your version is a modification of the
- original, and you must provide either a pointer to or a copy of the
- original.
-\*---------------------------------------------------------------------------*/
-
-#ifndef _POLL_EMUL_H_
-#define _POLL_EMUL_H_
-
-#define POLLIN 0x01
-#define POLLPRI 0x02
-#define POLLOUT 0x04
-#define POLLERR 0x08
-#define POLLHUP 0x10
-#define POLLNVAL 0x20
-
-struct pollfd
-{
- int fd;
- short events;
- short revents;
-};
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#if (__STDC__ > 0) || defined(__cplusplus)
-extern int poll (struct pollfd *pArray, unsigned long n_fds, int timeout);
-#else
-extern int poll();
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _POLL_EMUL_H_ */
diff --git a/1.2-netsec/include/asterisk/privacy.h b/1.2-netsec/include/asterisk/privacy.h
deleted file mode 100644
index 686a14d75..000000000
--- a/1.2-netsec/include/asterisk/privacy.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Persistant data storage (akin to *doze registry)
- */
-
-#ifndef _ASTERISK_PRIVACY_H
-#define _ASTERISK_PRIVACY_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#define AST_PRIVACY_DENY (1 << 0) /* Don't bother ringing, send to voicemail */
-#define AST_PRIVACY_ALLOW (1 << 1) /* Pass directly to me */
-#define AST_PRIVACY_KILL (1 << 2) /* Play anti-telemarketer message and hangup */
-#define AST_PRIVACY_TORTURE (1 << 3) /* Send directly to tele-torture */
-#define AST_PRIVACY_UNKNOWN (1 << 16)
-
-int ast_privacy_check(char *dest, char *cid);
-
-int ast_privacy_set(char *dest, char *cid, int status);
-
-int ast_privacy_reset(char *dest);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_PRIVACY_H */
diff --git a/1.2-netsec/include/asterisk/res_odbc.h b/1.2-netsec/include/asterisk/res_odbc.h
deleted file mode 100644
index 9e4070beb..000000000
--- a/1.2-netsec/include/asterisk/res_odbc.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- * Copyright (C) 2004 - 2005, Anthony Minessale II
- *
- * Mark Spencer <markster@digium.com>
- * Anthony Minessale <anthmct@yahoo.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief ODBC resource manager
- */
-
-#ifndef _ASTERISK_RES_ODBC_H
-#define _ASTERISK_RES_ODBC_H
-
-#include <sql.h>
-#include <sqlext.h>
-#include <sqltypes.h>
-
-typedef struct odbc_obj odbc_obj;
-
-typedef enum { ODBC_SUCCESS=0,ODBC_FAIL=-1} odbc_status;
-
-struct odbc_obj {
- char *name;
- char *dsn;
- char *username;
- char *password;
- SQLHENV env; /* ODBC Environment */
- SQLHDBC con; /* ODBC Connection Handle */
- SQLHSTMT stmt; /* ODBC Statement Handle */
- ast_mutex_t lock;
- int up;
-
-};
-
-/* functions */
-odbc_obj *new_odbc_obj(char *name,char *dsn,char *username, char *password);
-odbc_status odbc_obj_connect(odbc_obj *obj);
-odbc_status odbc_obj_disconnect(odbc_obj *obj);
-void destroy_odbc_obj(odbc_obj **obj);
-int register_odbc_obj(char *name,odbc_obj *obj);
-odbc_obj *fetch_odbc_obj(const char *name, int check);
-int odbc_dump_fd(int fd,odbc_obj *obj);
-int odbc_sanity_check(odbc_obj *obj);
-SQLHSTMT odbc_prepare_and_execute(odbc_obj *obj, SQLHSTMT (*prepare_cb)(odbc_obj *obj, void *data), void *data);
-int odbc_smart_execute(odbc_obj *obj, SQLHSTMT stmt);
-int odbc_smart_direct_execute(odbc_obj *obj, SQLHSTMT stmt, char *sql);
-
-#endif /* _ASTERISK_RES_ODBC_H */
diff --git a/1.2-netsec/include/asterisk/rtp.h b/1.2-netsec/include/asterisk/rtp.h
deleted file mode 100644
index f1e771e34..000000000
--- a/1.2-netsec/include/asterisk/rtp.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*!
- * \file rtp.h
- * \brief Supports RTP and RTCP with Symmetric RTP support for NAT traversal.
- *
- * RTP is defined in RFC 3550.
- */
-
-#ifndef _ASTERISK_RTP_H
-#define _ASTERISK_RTP_H
-
-#include "asterisk/frame.h"
-#include "asterisk/io.h"
-#include "asterisk/sched.h"
-#include "asterisk/channel.h"
-
-#include <netinet/in.h>
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
-/*! DTMF (RFC2833) */
-#define AST_RTP_DTMF (1 << 0)
-/*! 'Comfort Noise' (RFC3389) */
-#define AST_RTP_CN (1 << 1)
-/*! DTMF (Cisco Proprietary) */
-#define AST_RTP_CISCO_DTMF (1 << 2)
-/*! Maximum RTP-specific code */
-#define AST_RTP_MAX AST_RTP_CISCO_DTMF
-
-struct ast_rtp_protocol {
- /* Get RTP struct, or NULL if unwilling to transfer */
- struct ast_rtp *(* const get_rtp_info)(struct ast_channel *chan);
- /* Get RTP struct, or NULL if unwilling to transfer */
- struct ast_rtp *(* const get_vrtp_info)(struct ast_channel *chan);
- /* Set RTP peer */
- int (* const set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, int codecs, int nat_active);
- int (* const get_codec)(struct ast_channel *chan);
- const char * const type;
- struct ast_rtp_protocol *next;
-};
-
-/*!
- * \brief Structure representing a RTP session.
- *
- * RTP session is defined on page 9 of RFC 3550: "An association among a set of participants communicating with RTP. A participant may be involved in multiple RTP sessions at the same time [...]"
- *
- */
-struct ast_rtp;
-
-typedef int (*ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void *data);
-
-/*!
- * \brief Initializate a RTP session.
- *
- * \param sched
- * \param io
- * \param rtcpenable
- * \param callbackmode
- * \returns A representation (structure) of an RTP session.
- */
-struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode);
-
-/*!
- * \brief Initializate a RTP session using an in_addr structure.
- *
- * This fuction gets called by ast_rtp_new().
- *
- * \param sched
- * \param io
- * \param rtcpenable
- * \param callbackmode
- * \param in
- * \returns A representation (structure) of an RTP session.
- */
-struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr in);
-
-void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
-
-void ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
-
-void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us);
-
-#ifdef MIDCOM
-void ast_rtp_nat_us(struct ast_rtp *rtp, struct sockaddr_in *our_nat);
-void ast_rtp_get_their_nat(struct ast_rtp *rtp, struct sockaddr_in *their_nat);
-#endif
-
-void ast_rtp_destroy(struct ast_rtp *rtp);
-
-void ast_rtp_reset(struct ast_rtp *rtp);
-
-void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback);
-
-void ast_rtp_set_data(struct ast_rtp *rtp, void *data);
-
-int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *f);
-
-struct ast_frame *ast_rtp_read(struct ast_rtp *rtp);
-
-struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp);
-
-int ast_rtp_fd(struct ast_rtp *rtp);
-
-int ast_rtcp_fd(struct ast_rtp *rtp);
-
-int ast_rtp_senddigit(struct ast_rtp *rtp, char digit);
-
-int ast_rtp_sendcng(struct ast_rtp *rtp, int level);
-
-int ast_rtp_settos(struct ast_rtp *rtp, int tos);
-
-/* Setting RTP payload types from lines in a SDP description: */
-void ast_rtp_pt_clear(struct ast_rtp* rtp);
-/* Set payload types to defaults */
-void ast_rtp_pt_default(struct ast_rtp* rtp);
-void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt);
-void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
- char* mimeType, char* mimeSubtype);
-
-/* Mapping between RTP payload format codes and Asterisk codes: */
-struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
-int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
-void ast_rtp_offered_from_local(struct ast_rtp* rtp, int local);
-
-void ast_rtp_get_current_formats(struct ast_rtp* rtp,
- int* astFormats, int* nonAstFormats);
-
-/* Mapping an Asterisk code into a MIME subtype (string): */
-char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code);
-
-/* Build a string of MIME subtype names from a capability list */
-char *ast_rtp_lookup_mime_multiple(char *buf, int size, const int capability, const int isAstFormat);
-
-void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
-
-int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
-
-int ast_rtp_proto_register(struct ast_rtp_protocol *proto);
-
-void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto);
-
-void ast_rtp_stop(struct ast_rtp *rtp);
-
-void ast_rtp_init(void);
-
-void ast_rtp_reload(void);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_RTP_H */
diff --git a/1.2-netsec/include/asterisk/say.h b/1.2-netsec/include/asterisk/say.h
deleted file mode 100644
index ac498cde2..000000000
--- a/1.2-netsec/include/asterisk/say.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Say numbers and dates (maybe words one day too)
- */
-
-#ifndef _ASTERISK_SAY_H
-#define _ASTERISK_SAY_H
-
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-
-#include <time.h>
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/* says a number
- * \param chan channel to say them number on
- * \param num number to say on the channel
- * \param ints which dtmf to interrupt on
- * \param lang language to speak the number
- * \param options set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural
- * Vocally says a number on a given channel
- * Returns 0 on success, DTMF digit on interrupt, -1 on failure
- */
-int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options);
-
-/* Same as above with audiofd for received audio and returns 1 on ctrlfd being readable */
-int ast_say_number_full(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd);
-
-/* says an enumeration
- * \param chan channel to say them enumeration on
- * \param num number to say on the channel
- * \param ints which dtmf to interrupt on
- * \param lang language to speak the enumeration
- * \param options set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural
- * Vocally says a enumeration on a given channel (first, sencond, third, forth, thirtyfirst, hundredth, ....)
- * especially useful for dates and messages. says 'last' if num equals to INT_MAX
- * Returns 0 on success, DTMF digit on interrupt, -1 on failure
- */
-int ast_say_enumeration(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options);
-int ast_say_enumeration_full(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd);
-
-/* says digits
- * \param chan channel to act upon
- * \param num number to speak
- * \param ints which dtmf to interrupt on
- * \param lang language to speak
- * Vocally says digits of a given number
- * Returns 0 on success, dtmf if interrupted, -1 on failure
- */
-int ast_say_digits(struct ast_channel *chan, int num, const char *ints, const char *lang);
-int ast_say_digits_full(struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd);
-
-/* says digits of a string
- * \param chan channel to act upon
- * \param num string to speak
- * \param ints which dtmf to interrupt on
- * \param lang language to speak in
- * Vocally says the digits of a given string
- * Returns 0 on success, dtmf if interrupted, -1 on failure
- */
-int ast_say_digit_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang);
-int ast_say_digit_str_full(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd);
-int ast_say_character_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang);
-int ast_say_character_str_full(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd);
-int ast_say_phonetic_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang);
-int ast_say_phonetic_str_full(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd);
-
-int ast_say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-
-int ast_say_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-
-int ast_say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-
-int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-
-int ast_say_date_with_format(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezone);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_SAY_H */
diff --git a/1.2-netsec/include/asterisk/sched.h b/1.2-netsec/include/asterisk/sched.h
deleted file mode 100644
index eca928ca4..000000000
--- a/1.2-netsec/include/asterisk/sched.h
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Scheduler Routines (derived from cheops)
- */
-
-#ifndef _ASTERISK_SCHED_H
-#define _ASTERISK_SCHED_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/*! Max num of schedule structs */
-/*!
- * The max number of schedule structs to keep around
- * for use. Undefine to disable schedule structure
- * caching. (Only disable this on very low memory
- * machines)
- */
-#define SCHED_MAX_CACHE 128
-
-struct sched_context;
-
-/*! New schedule context */
-/* !
- * Create a scheduling context
- * Returns a malloc'd sched_context structure, NULL on failure
- */
-extern struct sched_context *sched_context_create(void);
-
-/*! destroys a schedule context */
-/*!
- * \param c Context to free
- * Destroys (free's) the given sched_context structure
- * Returns 0 on success, -1 on failure
- */
-void sched_context_destroy(struct sched_context *c);
-
-/*! callback for a cheops scheduler */
-/*!
- * A cheops scheduler callback takes a pointer with callback data and
- * returns a 0 if it should not be run again, or non-zero if it should be
- * rescheduled to run again
- */
-typedef int (*ast_sched_cb)(void *data);
-#define AST_SCHED_CB(a) ((ast_sched_cb)(a))
-
-/*!Adds a scheduled event */
-/*!
- * \param con Schduler context to add
- * \param when how many milliseconds to wait for event to occur
- * \param callback function to call when the amount of time expires
- * \param data data to pass to the callback
- * Schedule an event to take place at some point in the future. callback
- * will be called with data as the argument, when milliseconds into the
- * future (approximately)
- * If callback returns 0, no further events will be re-scheduled
- * Returns a schedule item ID on success, -1 on failure
- */
-extern int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, void *data);
-
-/*!Adds a scheduled event */
-/*!
- * \param con Schduler context to add
- * \param when how many milliseconds to wait for event to occur
- * \param callback function to call when the amount of time expires
- * \param data data to pass to the callback
- * \param variable If true, the result value of callback function will be
- * used for rescheduling
- * Schedule an event to take place at some point in the future. callback
- * will be called with data as the argument, when milliseconds into the
- * future (approximately)
- * If callback returns 0, no further events will be re-scheduled
- * Returns a schedule item ID on success, -1 on failure
- */
-extern int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb callback, void *data, int variable);
-
-/*! Deletes a scheduled event */
-/*!
- * \param con scheduling context to delete item from
- * \param id ID of the scheduled item to delete
- * Remove this event from being run. A procedure should not remove its
- * own event, but return 0 instead.
- * Returns 0 on success, -1 on failure
- */
-extern int ast_sched_del(struct sched_context *con, int id);
-
-/*! Determines number of seconds until the next outstanding event to take place */
-/*!
- * \param con context to act upon
- * Determine the number of seconds until the next outstanding event
- * should take place, and return the number of milliseconds until
- * it needs to be run. This value is perfect for passing to the poll
- * call. Returns "-1" if there is nothing there are no scheduled events
- * (and thus the poll should not timeout)
- */
-extern int ast_sched_wait(struct sched_context *con);
-
-/*! Runs the queue */
-/*!
- * \param con Scheduling context to run
- * Run the queue, executing all callbacks which need to be performed
- * at this time. Returns the number of events processed.
- */
-extern int ast_sched_runq(struct sched_context *con);
-
-/*!Dumps the scheduler contents */
-/*!
- * \param con Context to dump
- * Debugging: Dump the contents of the scheduler to stderr
- */
-extern void ast_sched_dump(const struct sched_context *con);
-
-/*!Returns the number of seconds before an event takes place */
-/*!
- * \param con Context to use
- * \param id Id to dump
- */
-extern long ast_sched_when(struct sched_context *con,int id);
-
-/*
- *! Convenience macro for objects and reference (add)
- *
- */
-#define ast_sched_add_object(obj,con,when,callback) ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj)))
-
-/*
- *! Convenience macro for objects and reference (del)
- *
- */
-#define ast_sched_del_object(obj,destructor,con,id) do { \
- if ((id) > -1) { \
- ast_sched_del((con),(id)); \
- (id) = -1; \
- ASTOBJ_UNREF((obj),(destructor)); \
- } \
-} while(0)
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_SCHED_H */
diff --git a/1.2-netsec/include/asterisk/slinfactory.h b/1.2-netsec/include/asterisk/slinfactory.h
deleted file mode 100644
index e7403032c..000000000
--- a/1.2-netsec/include/asterisk/slinfactory.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Anthony Minessale II
- *
- * Anthony Minessale <anthmct@yahoo.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief A machine to gather up arbitrary frames and convert them
- * to raw slinear on demand.
- */
-
-#ifndef _ASTERISK_SLINFACTORY_H
-#define _ASTERISK_SLINFACTORY_H
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-struct ast_slinfactory {
- struct ast_frame *queue;
- struct ast_trans_pvt *trans;
- short hold[1280];
- short *offset;
- size_t holdlen;
- int size;
- int format;
-};
-
-void ast_slinfactory_init(struct ast_slinfactory *sf);
-void ast_slinfactory_destroy(struct ast_slinfactory *sf);
-int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f);
-int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t bytes);
-
-
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_SLINFACTORY_H */
diff --git a/1.2-netsec/include/asterisk/srv.h b/1.2-netsec/include/asterisk/srv.h
deleted file mode 100644
index 08dcac0f2..000000000
--- a/1.2-netsec/include/asterisk/srv.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
- * DNS SRV record support
- */
-
-#ifndef _ASTERISK_SRV_H
-#define _ASTERISK_SRV_H
-
-struct ast_channel;
-
-/*!
- \file srv.h
- \brief Support for DNS SRV records, used in to locate SIP services.
- \note Note: The Asterisk DNS SRV record support is broken, it only
- supports the first DNS SRV record and will give no load
- balancing or failover support.
-*/
-
-/*! Lookup entry in SRV records Returns 1 if found, 0 if not found, -1 on hangup
- Only do SRV record lookup if you get a domain without a port. If you get a port #, it's a DNS host name.
-*/
-/*! \param chan Ast channel
- \param host host name (return value)
- \param hostlen Length of string "host"
- \param port Port number (return value)
- \param service Service tag for SRV lookup (like "_sip._udp" or "_stun._udp"
-*/
-extern int ast_get_srv(struct ast_channel *chan, char *host, int hostlen, int *port, const char *service);
-
-#endif /* _ASTERISK_SRV_H */
diff --git a/1.2-netsec/include/asterisk/strings.h b/1.2-netsec/include/asterisk/strings.h
deleted file mode 100644
index 52bbc3629..000000000
--- a/1.2-netsec/include/asterisk/strings.h
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief String manipulation functions
- */
-
-#ifndef _ASTERISK_STRINGS_H
-#define _ASTERISK_STRINGS_H
-
-#include <string.h>
-#include <stdarg.h>
-
-#include "asterisk/inline_api.h"
-#include "asterisk/compiler.h"
-#include "asterisk/compat.h"
-
-static force_inline int ast_strlen_zero(const char *s)
-{
- return (!s || (*s == '\0'));
-}
-
-/*!
- \brief Gets a pointer to the first non-whitespace character in a string.
- \param ast_skip_blanks function being used
- \param str the input string
- \return a pointer to the first non-whitespace character
- */
-AST_INLINE_API(
-char *ast_skip_blanks(char *str),
-{
- while (*str && *str < 33)
- str++;
- return str;
-}
-)
-
-/*!
- \brief Trims trailing whitespace characters from a string.
- \param ast_trim_blanks function being used
- \param str the input string
- \return a pointer to the modified string
- */
-AST_INLINE_API(
-char *ast_trim_blanks(char *str),
-{
- char *work = str;
-
- if (work) {
- work += strlen(work) - 1;
- /* It's tempting to only want to erase after we exit this loop,
- but since ast_trim_blanks *could* receive a constant string
- (which we presumably wouldn't have to touch), we shouldn't
- actually set anything unless we must, and it's easier just
- to set each position to \0 than to keep track of a variable
- for it */
- while ((work >= str) && *work < 33)
- *(work--) = '\0';
- }
- return str;
-}
-)
-
-/*!
- \brief Gets a pointer to first whitespace character in a string.
- \param ast_skip_noblanks function being used
- \param str the input string
- \return a pointer to the first whitespace character
- */
-AST_INLINE_API(
-char *ast_skip_nonblanks(char *str),
-{
- while (*str && *str > 32)
- str++;
- return str;
-}
-)
-
-/*!
- \brief Strip leading/trailing whitespace from a string.
- \param s The string to be stripped (will be modified).
- \return The stripped string.
-
- This functions strips all leading and trailing whitespace
- characters from the input string, and returns a pointer to
- the resulting string. The string is modified in place.
-*/
-AST_INLINE_API(
-char *ast_strip(char *s),
-{
- s = ast_skip_blanks(s);
- if (s)
- ast_trim_blanks(s);
- return s;
-}
-)
-
-/*!
- \brief Strip leading/trailing whitespace and quotes from a string.
- \param s The string to be stripped (will be modified).
- \param beg_quotes The list of possible beginning quote characters.
- \param end_quotes The list of matching ending quote characters.
- \return The stripped string.
-
- This functions strips all leading and trailing whitespace
- characters from the input string, and returns a pointer to
- the resulting string. The string is modified in place.
-
- It can also remove beginning and ending quote (or quote-like)
- characters, in matching pairs. If the first character of the
- string matches any character in beg_quotes, and the last
- character of the string is the matching character in
- end_quotes, then they are removed from the string.
-
- Examples:
- \code
- ast_strip_quoted(buf, "\"", "\"");
- ast_strip_quoted(buf, "'", "'");
- ast_strip_quoted(buf, "[{(", "]})");
- \endcode
- */
-char *ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes);
-
-/*!
- \brief Size-limited null-terminating string copy.
- \param ast_copy_string function being used
- \param dst The destination buffer.
- \param src The source string
- \param size The size of the destination buffer
- \return Nothing.
-
- This is similar to \a strncpy, with two important differences:
- - the destination buffer will \b always be null-terminated
- - the destination buffer is not filled with zeros past the copied string length
- These differences make it slightly more efficient, and safer to use since it will
- not leave the destination buffer unterminated. There is no need to pass an artificially
- reduced buffer size to this function (unlike \a strncpy), and the buffer does not need
- to be initialized to zeroes prior to calling this function.
-*/
-AST_INLINE_API(
-void ast_copy_string(char *dst, const char *src, size_t size),
-{
- while (*src && size) {
- *dst++ = *src++;
- size--;
- }
- if (__builtin_expect(!size, 0))
- dst--;
- *dst = '\0';
-}
-)
-
-/*!
- \brief Build a string in a buffer, designed to be called repeatedly
-
- This is a wrapper for snprintf, that properly handles the buffer pointer
- and buffer space available.
-
- \param buffer current position in buffer to place string into (will be updated on return)
- \param space remaining space in buffer (will be updated on return)
- \param fmt printf-style format string
- \return 0 on success, non-zero on failure.
-*/
-int ast_build_string(char **buffer, size_t *space, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
-
-/*!
- \brief Build a string in a buffer, designed to be called repeatedly
-
- This is a wrapper for snprintf, that properly handles the buffer pointer
- and buffer space available.
-
- \return 0 on success, non-zero on failure.
- \param buffer current position in buffer to place string into (will be updated on return)
- \param space remaining space in buffer (will be updated on return)
- \param fmt printf-style format string
- \param ap varargs list of arguments for format
-*/
-int ast_build_string_va(char **buffer, size_t *space, const char *fmt, va_list ap);
-
-/*! Make sure something is true */
-/*!
- * Determine if a string containing a boolean value is "true".
- * This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
- *
- * Returns 0 if val is a NULL pointer, -1 if "true", and 0 otherwise.
- */
-int ast_true(const char *val);
-
-/*! Make sure something is false */
-/*!
- * Determine if a string containing a boolean value is "false".
- * This function checks to see whether a string passed to it is an indication of an "false" value. It checks to see if the string is "no", "false", "n", "f", "off" or "0".
- *
- * Returns 0 if val is a NULL pointer, -1 if "false", and 0 otherwise.
- */
-int ast_false(const char *val);
-
-/* The realloca lets us ast_restrdupa(), but you can't mix any other ast_strdup calls! */
-
-struct ast_realloca {
- char *ptr;
- int alloclen;
-};
-
-#define ast_restrdupa(ra, s) \
- ({ \
- if ((ra)->ptr && strlen(s) + 1 < (ra)->alloclen) { \
- strcpy((ra)->ptr, s); \
- } else { \
- (ra)->ptr = alloca(strlen(s) + 1 - (ra)->alloclen); \
- if ((ra)->ptr) (ra)->alloclen = strlen(s) + 1; \
- } \
- (ra)->ptr; \
- })
-
-#ifndef HAVE_STRCASESTR
-char *strcasestr(const char *, const char *);
-#endif
-
-#if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)
-char *strndup(const char *, size_t);
-#endif
-
-#ifndef HAVE_STRNLEN
-size_t strnlen(const char *, size_t);
-#endif
-
-#if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)
-int vasprintf(char **strp, const char *fmt, va_list ap);
-#endif
-
-#ifndef HAVE_STRTOQ
-uint64_t strtoq(const char *nptr, char **endptr, int base);
-#endif
-
-#endif /* _ASTERISK_STRINGS_H */
diff --git a/1.2-netsec/include/asterisk/tdd.h b/1.2-netsec/include/asterisk/tdd.h
deleted file mode 100644
index 66af1e52f..000000000
--- a/1.2-netsec/include/asterisk/tdd.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief TTY/TDD Generation support
- * \note Includes code and algorithms from the Zapata library.
- */
-
-#ifndef _ASTERISK_TDD_H
-#define _ASTERISK_TDD_H
-
-#define TDD_BYTES_PER_CHAR 2700
-
-struct tdd_state;
-typedef struct tdd_state TDDSTATE;
-
-/*! CallerID Initialization */
-/*!
- * Initializes the TDD system. Mostly stuff for inverse FFT
- */
-extern void tdd_init(void);
-
-/*! Generates a CallerID FSK stream in ulaw format suitable for transmission. */
-/*!
- * \param tdd tdd structure
- * \param buf Buffer to use. This needs to be large enough to accomodate all the generated samples.
- * \param string This is the string to send.
- * This function creates a stream of TDD data in ulaw format. It returns the size
- * (in bytes) of the data (if it returns a size of 0, there is probably an error)
-*/
-extern int tdd_generate(struct tdd_state *tdd, unsigned char *buf, const char *string);
-
-/*! Create a TDD state machine */
-/*!
- * This function returns a malloc'd instance of the tdd_state data structure.
- * Returns a pointer to a malloc'd tdd_state structure, or NULL on error.
- */
-extern struct tdd_state *tdd_new(void);
-
-/*! Read samples into the state machine, and return character (if any). */
-/*!
- * \param tdd Which state machine to act upon
- * \param ubuf containing your samples
- * \param samples number of samples contained within the buffer.
- *
- * Send received audio to the TDD demodulator.
- * Returns -1 on error, 0 for "needs more samples",
- * and > 0 (the character) if reception of a character is complete.
- */
-extern int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int samples);
-
-/*! Free a TDD state machine */
-/*!
- * \param tdd This is the tdd_state state machine to free
- * This function frees tdd_state tdd.
- */
-extern void tdd_free(struct tdd_state *tdd);
-
-/*! Generate Echo Canceller diable tone (2100HZ) */
-/*!
- * \param outbuf This is the buffer to receive the tone data
- * \param len This is the length (in samples) of the tone data to generate
- * Returns 0 if no error, and -1 if error.
- */
-extern int ast_tdd_gen_ecdisa(unsigned char *outbuf, int len);
-
-#endif /* _ASTERISK_TDD_H */
diff --git a/1.2-netsec/include/asterisk/term.h b/1.2-netsec/include/asterisk/term.h
deleted file mode 100644
index 499927600..000000000
--- a/1.2-netsec/include/asterisk/term.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Handy terminal functions for vt* terms
- */
-
-#ifndef _ASTERISK_TERM_H
-#define _ASTERISK_TERM_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#define ESC 0x1b
-#define ATTR_RESET 0
-#define ATTR_BRIGHT 1
-#define ATTR_DIM 2
-#define ATTR_UNDER 4
-#define ATTR_BLINK 5
-#define ATTR_REVER 7
-#define ATTR_HIDDEN 8
-
-#define COLOR_BLACK 30
-#define COLOR_GRAY 30 | 128
-#define COLOR_RED 31
-#define COLOR_BRRED 31 | 128
-#define COLOR_GREEN 32
-#define COLOR_BRGREEN 32 | 128
-#define COLOR_BROWN 33
-#define COLOR_YELLOW 33 | 128
-#define COLOR_BLUE 34
-#define COLOR_BRBLUE 34 | 128
-#define COLOR_MAGENTA 35
-#define COLOR_BRMAGENTA 35 | 128
-#define COLOR_CYAN 36
-#define COLOR_BRCYAN 36 | 128
-#define COLOR_WHITE 37
-#define COLOR_BRWHITE 37 | 128
-
-extern char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout);
-
-extern char *term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout);
-
-extern char *term_strip(char *outbuf, char *inbuf, int maxout);
-
-extern char *term_prompt(char *outbuf, const char *inbuf, int maxout);
-
-extern char *term_prep(void);
-
-extern char *term_end(void);
-
-extern char *term_quit(void);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_TERM_H */
diff --git a/1.2-netsec/include/asterisk/time.h b/1.2-netsec/include/asterisk/time.h
deleted file mode 100644
index 8132e9cd1..000000000
--- a/1.2-netsec/include/asterisk/time.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Time-related functions and macros
- */
-
-#ifndef _ASTERISK_TIME_H
-#define _ASTERISK_TIME_H
-
-#include <sys/time.h>
-
-#include "asterisk/inline_api.h"
-
-/* We have to let the compiler learn what types to use for the elements of a
- struct timeval since on linux, it's time_t and suseconds_t, but on *BSD,
- they are just a long. */
-extern struct timeval tv;
-typedef typeof(tv.tv_sec) ast_time_t;
-typedef typeof(tv.tv_usec) ast_suseconds_t;
-
-/*!
- * \brief Computes the difference (in milliseconds) between two \c struct \c timeval instances.
- * \param end the beginning of the time period
- * \param start the end of the time period
- * \return the difference in milliseconds
- */
-AST_INLINE_API(
-int ast_tvdiff_ms(struct timeval end, struct timeval start),
-{
- /* the offset by 1,000,000 below is intentional...
- it avoids differences in the way that division
- is handled for positive and negative numbers, by ensuring
- that the divisor is always positive
- */
- return ((end.tv_sec - start.tv_sec) * 1000) +
- (((1000000 + end.tv_usec - start.tv_usec) / 1000) - 1000);
-}
-)
-
-/*!
- * \brief Returns true if the argument is 0,0
- */
-AST_INLINE_API(
-int ast_tvzero(const struct timeval t),
-{
- return (t.tv_sec == 0 && t.tv_usec == 0);
-}
-)
-
-/*!
- * \brief Compres two \c struct \c timeval instances returning
- * -1, 0, 1 if the first arg is smaller, equal or greater to the second.
- */
-AST_INLINE_API(
-int ast_tvcmp(struct timeval _a, struct timeval _b),
-{
- if (_a.tv_sec < _b.tv_sec)
- return -1;
- if (_a.tv_sec > _b.tv_sec)
- return 1;
- /* now seconds are equal */
- if (_a.tv_usec < _b.tv_usec)
- return -1;
- if (_a.tv_usec > _b.tv_usec)
- return 1;
- return 0;
-}
-)
-
-/*!
- * \brief Returns true if the two \c struct \c timeval arguments are equal.
- */
-AST_INLINE_API(
-int ast_tveq(struct timeval _a, struct timeval _b),
-{
- return (_a.tv_sec == _b.tv_sec && _a.tv_usec == _b.tv_usec);
-}
-)
-
-/*!
- * \brief Returns current timeval. Meant to replace calls to gettimeofday().
- */
-AST_INLINE_API(
-struct timeval ast_tvnow(void),
-{
- struct timeval t;
- gettimeofday(&t, NULL);
- return t;
-}
-)
-
-/*!
- * \brief Returns the sum of two timevals a + b
- */
-struct timeval ast_tvadd(struct timeval a, struct timeval b);
-
-/*!
- * \brief Returns the difference of two timevals a - b
- */
-struct timeval ast_tvsub(struct timeval a, struct timeval b);
-
-/*!
- * \brief Returns a timeval from sec, usec
- */
-AST_INLINE_API(
-struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec),
-{
- struct timeval t;
- t.tv_sec = sec;
- t.tv_usec = usec;
- return t;
-}
-)
-
-/*!
- * \brief Returns a timeval corresponding to the duration of n samples at rate r.
- * Useful to convert samples to timevals, or even milliseconds to timevals
- * in the form ast_samp2tv(milliseconds, 1000)
- */
-AST_INLINE_API(
-struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate),
-{
- return ast_tv(_nsamp / _rate, (_nsamp % _rate) * (1000000 / _rate));
-}
-)
-
-#endif /* _ASTERISK_TIME_H */
diff --git a/1.2-netsec/include/asterisk/transcap.h b/1.2-netsec/include/asterisk/transcap.h
deleted file mode 100644
index 5da8329dc..000000000
--- a/1.2-netsec/include/asterisk/transcap.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Matthew Fredrickson <creslin@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief General Asterisk channel transcoding definitions.
- */
-
-#ifndef _ASTERISK_TRANSCAP_H
-#define _ASTERISK_TRANSCAP_H
-
-/* These definitions are taken directly out of libpri.h and used here.
- * DO NOT change them as it will cause unexpected behavior in channels
- * that utilize these fields.
- */
-
-#define AST_TRANS_CAP_SPEECH 0x0
-#define AST_TRANS_CAP_DIGITAL 0x08
-#define AST_TRANS_CAP_RESTRICTED_DIGITAL 0x09
-#define AST_TRANS_CAP_3_1K_AUDIO 0x10
-#define AST_TRANS_CAP_7K_AUDIO 0x11 /* Depriciated ITU Q.931 (05/1998)*/
-#define AST_TRANS_CAP_DIGITAL_W_TONES 0x11
-#define AST_TRANS_CAP_VIDEO 0x18
-
-#define IS_DIGITAL(cap)\
- (cap) & AST_TRANS_CAP_DIGITAL ? 1 : 0
-
-#endif /* _ASTERISK_TRANSCAP_H */
diff --git a/1.2-netsec/include/asterisk/translate.h b/1.2-netsec/include/asterisk/translate.h
deleted file mode 100644
index 7bb4aa441..000000000
--- a/1.2-netsec/include/asterisk/translate.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Translate via the use of pseudo channels
- */
-
-#ifndef _ASTERISK_TRANSLATE_H
-#define _ASTERISK_TRANSLATE_H
-
-#define MAX_FORMAT 32
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#include "asterisk/frame.h"
-#include "asterisk/plc.h"
-
-/* Declared by individual translators */
-struct ast_translator_pvt;
-
-/*! data structure associated with a translator */
-struct ast_translator {
- /*! Name of translator */
- char name[80];
- /*! Source format */
- int srcfmt;
- /*! Destination format */
- int dstfmt;
- /*! Private data associated with the translator */
- struct ast_translator_pvt *(*newpvt)(void);
- /*! Input frame callback */
- int (*framein)(struct ast_translator_pvt *pvt, struct ast_frame *in);
- /*! Output frame callback */
- struct ast_frame * (*frameout)(struct ast_translator_pvt *pvt);
- /*! Destroy translator callback */
- void (*destroy)(struct ast_translator_pvt *pvt);
- /* For performance measurements */
- /*! Generate an example frame */
- struct ast_frame * (*sample)(void);
- /*! Cost in milliseconds for encoding/decoding 1 second of sound */
- int cost;
- /*! For linking, not to be modified by the translator */
- struct ast_translator *next;
-};
-
-struct ast_trans_pvt;
-
-/*! Register a translator */
-/*!
- * \param t populated ast_translator structure
- * This registers a codec translator with asterisk
- * Returns 0 on success, -1 on failure
- */
-extern int ast_register_translator(struct ast_translator *t);
-
-/*! Unregister a translator */
-/*!
- * \param t translator to unregister
- * Unregisters the given tranlator
- * Returns 0 on success, -1 on failure
- */
-extern int ast_unregister_translator(struct ast_translator *t);
-
-/*! Chooses the best translation path */
-/*!
- * Given a list of sources, and a designed destination format, which should
- I choose? Returns 0 on success, -1 if no path could be found. Modifies
- dests and srcs in place
- */
-extern int ast_translator_best_choice(int *dsts, int *srcs);
-
-/*!Builds a translator path */
-/*!
- * \param dest destination format
- * \param source source format
- * Build a path (possibly NULL) from source to dest
- * Returns ast_trans_pvt on success, NULL on failure
- * */
-extern struct ast_trans_pvt *ast_translator_build_path(int dest, int source);
-
-/*! Frees a translator path */
-/*!
- * \param tr translator path to get rid of
- * Frees the given translator path structure
- */
-extern void ast_translator_free_path(struct ast_trans_pvt *tr);
-
-/*! translates one or more frames */
-/*!
- * \param tr translator structure to use for translation
- * \param f frame to translate
- * \param consume Whether or not to free the original frame
- * Apply an input frame into the translator and receive zero or one output frames. Consume
- * determines whether the original frame should be freed
- * Returns an ast_frame of the new translation format on success, NULL on failure
- */
-extern struct ast_frame *ast_translate(struct ast_trans_pvt *tr, struct ast_frame *f, int consume);
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_TRANSLATE_H */
diff --git a/1.2-netsec/include/asterisk/ulaw.h b/1.2-netsec/include/asterisk/ulaw.h
deleted file mode 100644
index b9edacb97..000000000
--- a/1.2-netsec/include/asterisk/ulaw.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief u-Law to Signed linear conversion
- */
-
-#ifndef _ASTERISK_ULAW_H
-#define _ASTERISK_ULAW_H
-
-/*! Init the ulaw conversion stuff */
-/*!
- * To init the ulaw to slinear conversion stuff, this needs to be run.
- */
-extern void ast_ulaw_init(void);
-
-/*! converts signed linear to mulaw */
-/*!
- */
-extern unsigned char __ast_lin2mu[16384];
-
-/*! help */
-extern short __ast_mulaw[256];
-
-#define AST_LIN2MU(a) (__ast_lin2mu[((unsigned short)(a)) >> 2])
-#define AST_MULAW(a) (__ast_mulaw[(a)])
-
-#endif /* _ASTERISK_ULAW_H */
diff --git a/1.2-netsec/include/asterisk/unaligned.h b/1.2-netsec/include/asterisk/unaligned.h
deleted file mode 100644
index 16791d6f0..000000000
--- a/1.2-netsec/include/asterisk/unaligned.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Handle unaligned data access
- */
-
-#ifndef _ASTERISK_UNALIGNED_H
-#define _ASTERISK_UNALIGNED_H
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-#ifdef __GNUC__
-/* If we just tell GCC what's going on, we can trust it to behave optimally */
-static inline unsigned int get_unaligned_uint32(void *p)
-{
- struct { unsigned int d; } __attribute__((packed)) *pp = (void *)p;
-
- return pp->d;
-}
-static inline unsigned short get_unaligned_uint16(void *p)
-{
- struct { unsigned short d; } __attribute__((packed)) *pp = (void *)p;
-
- return pp->d;
-}
-
-static inline void put_unaligned_uint32(void *p, unsigned int datum)
-{
- struct { unsigned int d; } __attribute__((packed)) *pp = (void *)p;
-
- pp->d = datum;
-}
-
-static inline void put_unaligned_uint16(void *p, unsigned short datum)
-{
- struct { unsigned short d; } __attribute__((packed)) *pp = (void *)p;
-
- pp->d = datum;
-}
-#elif defined(SOLARIS) && defined(__sparc__)
-static inline unsigned int get_unaligned_uint32(void *p)
-{
- unsigned char *cp = p;
-
- return (cp[0] << 24) | (cp[1] << 16) | (cp[2] << 8) | cp[3];
-}
-
-static inline unsigned short get_unaligned_uint16(void *p)
-{
- unsigned char *cp = p;
-
- return (cp[0] << 8) | cp[1] ;
-}
-
-static inline void put_unaligned_uint32(void *p, unsigned int datum)
-{
- unsigned char *cp = p;
-
- cp[0] = datum >> 24;
- cp[1] = datum >> 16;
- cp[2] = datum >> 8;
- cp[3] = datum;
-}
-
-static inline void put_unaligned_uint16(void *p, unsigned int datum)
-{
- unsigned char *cp = p;
-
- cp[0] = datum >> 8;
- cp[1] = datum;
-}
-#else /* Not GCC, not Solaris/SPARC. Assume we can handle direct load/store. */
-#define get_unaligned_uint32(p) (*((unsigned int *)(p)))
-#define get_unaligned_uint16(p) (*((unsigned short *)(p)))
-#define put_unaligned_uint32(p,d) do { unsigned int *__P = (p); *__P = d; } while(0)
-#define put_unaligned_uint16(p,d) do { unsigned short *__P = (p); *__P = d; } while(0)
-#endif
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-
-#endif /* _ASTERISK_UNALIGNED_H */
diff --git a/1.2-netsec/include/asterisk/utils.h b/1.2-netsec/include/asterisk/utils.h
deleted file mode 100644
index b6b85df4e..000000000
--- a/1.2-netsec/include/asterisk/utils.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Utility functions
- */
-
-#ifndef _ASTERISK_UTILS_H
-#define _ASTERISK_UTILS_H
-
-#include "asterisk/compat.h"
-
-#include <netinet/in.h>
-#include <arpa/inet.h> /* we want to override inet_ntoa */
-#include <netdb.h>
-#include <limits.h>
-
-#include "asterisk/lock.h"
-#include "asterisk/time.h"
-#include "asterisk/strings.h"
-
-/*! \note
- \verbatim
- Note:
- It is very important to use only unsigned variables to hold
- bit flags, as otherwise you can fall prey to the compiler's
- sign-extension antics if you try to use the top two bits in
- your variable.
-
- The flag macros below use a set of compiler tricks to verify
- that the caller is using an "unsigned int" variable to hold
- the flags, and nothing else. If the caller uses any other
- type of variable, a warning message similar to this:
-
- warning: comparison of distinct pointer types lacks cast
- will be generated.
-
- The "dummy" variable below is used to make these comparisons.
-
- Also note that at -O2 or above, this type-safety checking
- does _not_ produce any additional object code at all.
- \endverbatim
-*/
-
-extern unsigned int __unsigned_int_flags_dummy;
-
-#define ast_test_flag(p,flag) ({ \
- typeof ((p)->flags) __p = (p)->flags; \
- typeof (__unsigned_int_flags_dummy) __x = 0; \
- (void) (&__p == &__x); \
- ((p)->flags & (flag)); \
- })
-
-#define ast_set_flag(p,flag) do { \
- typeof ((p)->flags) __p = (p)->flags; \
- typeof (__unsigned_int_flags_dummy) __x = 0; \
- (void) (&__p == &__x); \
- ((p)->flags |= (flag)); \
- } while(0)
-
-#define ast_clear_flag(p,flag) do { \
- typeof ((p)->flags) __p = (p)->flags; \
- typeof (__unsigned_int_flags_dummy) __x = 0; \
- (void) (&__p == &__x); \
- ((p)->flags &= ~(flag)); \
- } while(0)
-
-#define ast_copy_flags(dest,src,flagz) do { \
- typeof ((dest)->flags) __d = (dest)->flags; \
- typeof ((src)->flags) __s = (src)->flags; \
- typeof (__unsigned_int_flags_dummy) __x = 0; \
- (void) (&__d == &__x); \
- (void) (&__s == &__x); \
- (dest)->flags &= ~(flagz); \
- (dest)->flags |= ((src)->flags & (flagz)); \
- } while (0)
-
-#define ast_set2_flag(p,value,flag) do { \
- typeof ((p)->flags) __p = (p)->flags; \
- typeof (__unsigned_int_flags_dummy) __x = 0; \
- (void) (&__p == &__x); \
- if (value) \
- (p)->flags |= (flag); \
- else \
- (p)->flags &= ~(flag); \
- } while (0)
-
-/* Non-type checking variations for non-unsigned int flags. You
- should only use non-unsigned int flags where required by
- protocol etc and if you know what you're doing :) */
-#define ast_test_flag_nonstd(p,flag) ({ \
- ((p)->flags & (flag)); \
- })
-
-#define ast_set_flag_nonstd(p,flag) do { \
- ((p)->flags |= (flag)); \
- } while(0)
-
-#define ast_clear_flag_nonstd(p,flag) do { \
- ((p)->flags &= ~(flag)); \
- } while(0)
-
-#define ast_copy_flags_nonstd(dest,src,flagz) do { \
- (dest)->flags &= ~(flagz); \
- (dest)->flags |= ((src)->flags & (flagz)); \
- } while (0)
-
-#define ast_set2_flag_nonstd(p,value,flag) do { \
- if (value) \
- (p)->flags |= (flag); \
- else \
- (p)->flags &= ~(flag); \
- } while (0)
-
-#define AST_FLAGS_ALL UINT_MAX
-
-struct ast_flags {
- unsigned int flags;
-};
-
-struct ast_hostent {
- struct hostent hp;
- char buf[1024];
-};
-
-struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp);
-
-/* ast_md5_hash
- \brief Produces MD5 hash based on input string */
-void ast_md5_hash(char *output, char *input);
-
-int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max);
-int ast_base64decode(unsigned char *dst, const char *src, int max);
-
-/*! ast_uri_encode
- \brief Turn text string to URI-encoded %XX version
- At this point, we're converting from ISO-8859-x (8-bit), not UTF8
- as in the SIP protocol spec
- If doreserved == 1 we will convert reserved characters also.
- RFC 2396, section 2.4
- outbuf needs to have more memory allocated than the instring
- to have room for the expansion. Every char that is converted
- is replaced by three ASCII characters.
- \param string String to be converted
- \param outbuf Resulting encoded string
- \param buflen Size of output buffer
- \param doreserved Convert reserved characters
-*/
-
-char *ast_uri_encode(char *string, char *outbuf, int buflen, int doreserved);
-
-/*! \brief Decode URI, URN, URL (overwrite string)
- \param s String to be decoded
- */
-void ast_uri_decode(char *s);
-
-static force_inline void ast_slinear_saturated_add(short *input, short *value)
-{
- int res;
-
- res = (int) *input + *value;
- if (res > 32767)
- *input = 32767;
- else if (res < -32767)
- *input = -32767;
- else
- *input = (short) res;
-}
-
-static force_inline void ast_slinear_saturated_multiply(short *input, short *value)
-{
- int res;
-
- res = (int) *input * *value;
- if (res > 32767)
- *input = 32767;
- else if (res < -32767)
- *input = -32767;
- else
- *input = (short) res;
-}
-
-static force_inline void ast_slinear_saturated_divide(short *input, short *value)
-{
- *input /= *value;
-}
-
-int test_for_thread_safety(void);
-
-const char *ast_inet_ntoa(char *buf, int bufsiz, struct in_addr ia);
-
-#ifdef inet_ntoa
-#undef inet_ntoa
-#endif
-#define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
-
-int ast_utils_init(void);
-int ast_wait_for_input(int fd, int ms);
-
-/*! Compares the source address and port of two sockaddr_in */
-static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
-{
- return ((sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
- || (sin1->sin_port != sin2->sin_port));
-}
-
-#define AST_STACKSIZE 256 * 1024
-#define ast_pthread_create(a,b,c,d) ast_pthread_create_stack(a,b,c,d,0)
-int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data, size_t stacksize);
-
-/*!
- \brief Process a string to find and replace characters
- \param start The string to analyze
- \param find The character to find
- \param replace_with The character that will replace the one we are looking for
-*/
-char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
-
-#ifndef HAVE_GETLOADAVG
-int getloadavg(double *list, int nelem);
-#endif
-
-#endif /* _ASTERISK_UTILS_H */
diff --git a/1.2-netsec/include/asterisk/vmodem.h b/1.2-netsec/include/asterisk/vmodem.h
deleted file mode 100644
index 8d700653b..000000000
--- a/1.2-netsec/include/asterisk/vmodem.h
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Voice Modem Definitions
- */
-
-#ifndef _ASTERISK_VMODEM_H
-#define _ASTERISK_VMODEM_H
-
-#include "asterisk/frame.h"
-#include "asterisk/channel.h"
-
-#define CHAR_DLE 0x10
-#define CHAR_ETX 0x03
-#define CHAR_DC4 0x14
-
-#define MODEM_DEV_TELCO 0
-#define MODEM_DEV_TELCO_SPK 4
-#define MODEM_DEV_SPKRPHONE 6
-#define MODEM_DEV_HANDSET 9
-
-#define MODEM_DTMF_NONE (1 << 0)
-#define MODEM_DTMF_AST (1 << 1)
-#define MODEM_DTMF_I4L (1 << 2)
-
-/* Thirty millisecond sections */
-#define MODEM_MAX_LEN 30
-#define MODEM_MAX_BUF MODEM_MAX_LEN * 16
-
-#define AST_MAX_INIT_STR 256
-
-struct ast_modem_pvt;
-
-struct ast_modem_driver {
- char *name;
- char **idents;
- int formats;
- int fullduplex;
- void (*incusecnt)(void);
- void (*decusecnt)(void);
- char * (*identify)(struct ast_modem_pvt *);
- int (*init)(struct ast_modem_pvt *);
- int (*setdev)(struct ast_modem_pvt *, int dev);
- struct ast_frame * (*read)(struct ast_modem_pvt *);
- int (*write)(struct ast_modem_pvt *, struct ast_frame *fr);
- int (*dial)(struct ast_modem_pvt *, char *);
- int (*answer)(struct ast_modem_pvt *);
- int (*hangup)(struct ast_modem_pvt *);
- int (*startrec)(struct ast_modem_pvt *);
- int (*stoprec)(struct ast_modem_pvt *);
- int (*startpb)(struct ast_modem_pvt *);
- int (*stoppb)(struct ast_modem_pvt *);
- int (*setsilence)(struct ast_modem_pvt *, int onoff);
- int (*dialdigit)(struct ast_modem_pvt *, char digit);
- struct ast_modem_driver *next;
-};
-
-#define MODEM_MODE_IMMEDIATE 0
-#define MODEM_MODE_WAIT_RING 1
-#define MODEM_MODE_WAIT_ANSWER 2
-
-/*! Private data that needs to be filled by modem driver */
-struct ast_modem_pvt {
- /*! Raw file descriptor for this device */
- int fd;
- /*! FILE * representation of device */
- FILE *f;
- /*! Channel we belong to, possibly NULL */
- struct ast_channel *owner;
- /* Device name */
- char dev[256];
- /*! Frame */
- struct ast_frame fr;
-
- char offset[AST_FRIENDLY_OFFSET];
- /*! Outgoing buffer */
- char obuf[MODEM_MAX_BUF];
-
- int tail;
- /*! Pulse or tone dialling */
- char dialtype;
- /*! Time to wait for dial timeout */
- char dialtimeout;
-
- int obuflen;
- /*! Immediate, or wait for an answer */
- int mode;
- /*! State of modem in miniature */
- int ministate;
- /*! Digits to strip on outgoing numbers */
- int stripmsd;
- /*! Is the last thing we saw an escape */
- int escape;
- /*! flag to say if has caller*id yet*/
- int gotclid;
- /* Has a fax tone already been handled? */
- int faxhandled;
- /*! ringer timeout */
- int ringt;
- /*! actual time of last ring */
- time_t lastring;
- /*! dtmf receive state/data */
- char dtmfrx;
-
- char context[AST_MAX_EXTENSION];
- /*! Multiple Subscriber Number */
- char msn[AST_MAX_EXTENSION];
- /*! Multiple Subscriber Number we listen to (; separated list) */
- char incomingmsn[AST_MAX_EXTENSION];
- /*! Multiple Subscriber Number we accept for outgoing calls (; separated list) */
- char outgoingmsn[AST_MAX_EXTENSION];
- /*! Group(s) we belong to if available */
- ast_group_t group;
- /*! Caller ID if available */
- char cid_name[AST_MAX_EXTENSION];
- /*! Caller ID if available */
- char cid_num[AST_MAX_EXTENSION];
- /*! DTMF-detection mode (i4l/asterisk) */
- int dtmfmode;
- /*! DTMF-generation mode (i4l (outband) / asterisk (inband) */
- int dtmfmodegen;
- /*! DSP for DTMF detection */
- struct ast_dsp *dsp;
- /*! Dialed Number if available */
- char dnid[AST_MAX_EXTENSION];
- /*! Modem initialization String */
- char initstr[AST_MAX_INIT_STR];
- /*! default language */
- char language[MAX_LANGUAGE];
- /*! Static response buffer */
- char response[256];
- /*! Modem Capability */
- struct ast_modem_driver *mc;
- /*! Next channel in list */
- struct ast_modem_pvt *next;
-};
-
-
-/*! Register a modem driver */
-/*! Register a driver */
-extern int ast_register_modem_driver(struct ast_modem_driver *mc);
-
-/*! Unregisters a modem driver */
-/*! Unregister a driver */
-extern int ast_unregister_modem_driver(struct ast_modem_driver *mc);
-
-/*! Sends command */
-/*! Send the command cmd (length len, or 0 if pure ascii) on modem */
-extern int ast_modem_send(struct ast_modem_pvt *p, char *cmd, int len);
-
-/*! Waits for result */
-/*! Wait for result to occur. Return non-zero if times out or error, last
- response is stored in p->response */
-extern int ast_modem_expect(struct ast_modem_pvt *p, char *result, int timeout);
-
-/*! Waits for result */
-/*! Wait for result to occur. response is stored in p->response */
-extern int ast_modem_read_response(struct ast_modem_pvt *p, int timeout);
-
-/*! Used to start up the PBX on a RING */
-/*! Used by modem drivers to start up the PBX on a RING */
-extern struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state);
-
-/*! Trim string of trailing stuff */
-/*! Trim off trailing mess */
-extern void ast_modem_trim(char *s);
-
-#endif /* _ASTERISK_VMODEM_H */
diff --git a/1.2-netsec/include/solaris-compat/compat.h b/1.2-netsec/include/solaris-compat/compat.h
deleted file mode 100644
index b34cf11f4..000000000
--- a/1.2-netsec/include/solaris-compat/compat.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef _SOLARIS_COMPAT_H
-#define _SOLARIS_COMPAT_H
-
-#define __BEGIN_DECLS
-#define __END_DECLS
-
-#ifndef __P
-#define __P(p) p
-#endif
-
-#include <alloca.h>
-#include <strings.h>
-#include <string.h>
-#include <pthread.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <netinet/in.h>
-
-#ifndef BYTE_ORDER
-#define LITTLE_ENDIAN 1234
-#define BIG_ENDIAN 4321
-
-#ifdef __sparc__
-#define BYTE_ORDER BIG_ENDIAN
-#else
-#define BYTE_ORDER LITTLE_ENDIAN
-#endif
-#endif
-
-#ifndef __BYTE_ORDER
-#define __LITTLE_ENDIAN LITTLE_ENDIAN
-#define __BIG_ENDIAN BIG_ENDIAN
-#define __BYTE_ORDER BYTE_ORDER
-#endif
-
-#ifndef __BIT_TYPES_DEFINED__
-#define __BIT_TYPES_DEFINED__
-typedef unsigned char u_int8_t;
-typedef unsigned short u_int16_t;
-typedef unsigned int u_int32_t;
-#endif
-
-char* strsep(char** str, const char* delims);
-int setenv(const char *name, const char *value, int overwrite);
-int unsetenv(const char *name);
-#endif
diff --git a/1.2-netsec/include/solaris-compat/sys/cdefs.h b/1.2-netsec/include/solaris-compat/sys/cdefs.h
deleted file mode 100644
index 40f76af87..000000000
--- a/1.2-netsec/include/solaris-compat/sys/cdefs.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef __SYS_CDEFS_H_
-#define __SYS_CDEFS_H_
-
-#define __BEGIN_DECLS
-#define __END_DECLS
-
-#define __P(p) p
-
-
-#endif
diff --git a/1.2-netsec/include/solaris-compat/sys/queue.h b/1.2-netsec/include/solaris-compat/sys/queue.h
deleted file mode 100644
index ac273dfe3..000000000
--- a/1.2-netsec/include/solaris-compat/sys/queue.h
+++ /dev/null
@@ -1,540 +0,0 @@
-/*
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)queue.h 8.5 (Berkeley) 8/20/94
- * $FreeBSD: src/sys/sys/queue.h,v 1.24.2.4 2000/05/05 01:41:41 archie Exp $
- */
-
-#ifndef _SYS_QUEUE_H_
-#define _SYS_QUEUE_H_
-
-/*
- * This file defines five types of data structures: singly-linked lists,
- * singly-linked tail queues, lists, tail queues, and circular queues.
- *
- * A singly-linked list is headed by a single forward pointer. The elements
- * are singly linked for minimum space and pointer manipulation overhead at
- * the expense of O(n) removal for arbitrary elements. New elements can be
- * added to the list after an existing element or at the head of the list.
- * Elements being removed from the head of the list should use the explicit
- * macro for this purpose for optimum efficiency. A singly-linked list may
- * only be traversed in the forward direction. Singly-linked lists are ideal
- * for applications with large datasets and few or no removals or for
- * implementing a LIFO queue.
- *
- * A singly-linked tail queue is headed by a pair of pointers, one to the
- * head of the list and the other to the tail of the list. The elements are
- * singly linked for minimum space and pointer manipulation overhead at the
- * expense of O(n) removal for arbitrary elements. New elements can be added
- * to the list after an existing element, at the head of the list, or at the
- * end of the list. Elements being removed from the head of the tail queue
- * should use the explicit macro for this purpose for optimum efficiency.
- * A singly-linked tail queue may only be traversed in the forward direction.
- * Singly-linked tail queues are ideal for applications with large datasets
- * and few or no removals or for implementing a FIFO queue.
- *
- * A list is headed by a single forward pointer (or an array of forward
- * pointers for a hash table header). The elements are doubly linked
- * so that an arbitrary element can be removed without a need to
- * traverse the list. New elements can be added to the list before
- * or after an existing element or at the head of the list. A list
- * may only be traversed in the forward direction.
- *
- * A tail queue is headed by a pair of pointers, one to the head of the
- * list and the other to the tail of the list. The elements are doubly
- * linked so that an arbitrary element can be removed without a need to
- * traverse the list. New elements can be added to the list before or
- * after an existing element, at the head of the list, or at the end of
- * the list. A tail queue may be traversed in either direction.
- *
- * A circle queue is headed by a pair of pointers, one to the head of the
- * list and the other to the tail of the list. The elements are doubly
- * linked so that an arbitrary element can be removed without a need to
- * traverse the list. New elements can be added to the list before or after
- * an existing element, at the head of the list, or at the end of the list.
- * A circle queue may be traversed in either direction, but has a more
- * complex end of list detection.
- *
- * For details on the use of these macros, see the queue(3) manual page.
- *
- *
- * SLIST LIST STAILQ TAILQ CIRCLEQ
- * _HEAD + + + + +
- * _ENTRY + + + + +
- * _INIT + + + + +
- * _EMPTY + + + + +
- * _FIRST + + + + +
- * _NEXT + + + + +
- * _PREV - - - + +
- * _LAST - - + + +
- * _FOREACH + + + + +
- * _FOREACH_REVERSE - - - + +
- * _INSERT_HEAD + + + + +
- * _INSERT_BEFORE - + - + +
- * _INSERT_AFTER + + + + +
- * _INSERT_TAIL - - + + +
- * _REMOVE_HEAD + - + - -
- * _REMOVE + + + + +
- *
- */
-
-/*
- * Singly-linked List definitions.
- */
-#define SLIST_HEAD(name, type) \
-struct name { \
- struct type *slh_first; /* first element */ \
-}
-
-#define SLIST_HEAD_INITIALIZER(head) \
- { NULL }
-
-#define SLIST_ENTRY(type) \
-struct { \
- struct type *sle_next; /* next element */ \
-}
-
-/*
- * Singly-linked List functions.
- */
-#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
-
-#define SLIST_FIRST(head) ((head)->slh_first)
-
-#define SLIST_FOREACH(var, head, field) \
- for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
-
-#define SLIST_INIT(head) { \
- (head)->slh_first = NULL; \
-}
-
-#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
- (elm)->field.sle_next = (slistelm)->field.sle_next; \
- (slistelm)->field.sle_next = (elm); \
-} while (0)
-
-#define SLIST_INSERT_HEAD(head, elm, field) do { \
- (elm)->field.sle_next = (head)->slh_first; \
- (head)->slh_first = (elm); \
-} while (0)
-
-#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
-
-#define SLIST_REMOVE_HEAD(head, field) do { \
- (head)->slh_first = (head)->slh_first->field.sle_next; \
-} while (0)
-
-#define SLIST_REMOVE(head, elm, type, field) do { \
- if ((head)->slh_first == (elm)) { \
- SLIST_REMOVE_HEAD((head), field); \
- } \
- else { \
- struct type *curelm = (head)->slh_first; \
- while( curelm->field.sle_next != (elm) ) \
- curelm = curelm->field.sle_next; \
- curelm->field.sle_next = \
- curelm->field.sle_next->field.sle_next; \
- } \
-} while (0)
-
-/*
- * Singly-linked Tail queue definitions.
- */
-#define STAILQ_HEAD(name, type) \
-struct name { \
- struct type *stqh_first;/* first element */ \
- struct type **stqh_last;/* addr of last next element */ \
-}
-
-#define STAILQ_HEAD_INITIALIZER(head) \
- { NULL, &(head).stqh_first }
-
-#define STAILQ_ENTRY(type) \
-struct { \
- struct type *stqe_next; /* next element */ \
-}
-
-/*
- * Singly-linked Tail queue functions.
- */
-#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
-
-#define STAILQ_INIT(head) do { \
- (head)->stqh_first = NULL; \
- (head)->stqh_last = &(head)->stqh_first; \
-} while (0)
-
-#define STAILQ_FIRST(head) ((head)->stqh_first)
-#define STAILQ_LAST(head) (*(head)->stqh_last)
-
-#define STAILQ_FOREACH(var, head, field) \
- for((var) = (head)->stqh_first; (var); (var) = (var)->field.stqe_next)
-
-#define STAILQ_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
- (head)->stqh_last = &(elm)->field.stqe_next; \
- (head)->stqh_first = (elm); \
-} while (0)
-
-#define STAILQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.stqe_next = NULL; \
- *(head)->stqh_last = (elm); \
- (head)->stqh_last = &(elm)->field.stqe_next; \
-} while (0)
-
-#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
- if (((elm)->field.stqe_next = (tqelm)->field.stqe_next) == NULL)\
- (head)->stqh_last = &(elm)->field.stqe_next; \
- (tqelm)->field.stqe_next = (elm); \
-} while (0)
-
-#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
-
-#define STAILQ_REMOVE_HEAD(head, field) do { \
- if (((head)->stqh_first = \
- (head)->stqh_first->field.stqe_next) == NULL) \
- (head)->stqh_last = &(head)->stqh_first; \
-} while (0)
-
-#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \
- if (((head)->stqh_first = (elm)->field.stqe_next) == NULL) \
- (head)->stqh_last = &(head)->stqh_first; \
-} while (0)
-
-#define STAILQ_REMOVE(head, elm, type, field) do { \
- if ((head)->stqh_first == (elm)) { \
- STAILQ_REMOVE_HEAD(head, field); \
- } \
- else { \
- struct type *curelm = (head)->stqh_first; \
- while( curelm->field.stqe_next != (elm) ) \
- curelm = curelm->field.stqe_next; \
- if((curelm->field.stqe_next = \
- curelm->field.stqe_next->field.stqe_next) == NULL) \
- (head)->stqh_last = &(curelm)->field.stqe_next; \
- } \
-} while (0)
-
-/*
- * List definitions.
- */
-#define LIST_HEAD(name, type) \
-struct name { \
- struct type *lh_first; /* first element */ \
-}
-
-#define LIST_HEAD_INITIALIZER(head) \
- { NULL }
-
-#define LIST_ENTRY(type) \
-struct { \
- struct type *le_next; /* next element */ \
- struct type **le_prev; /* address of previous next element */ \
-}
-
-/*
- * List functions.
- */
-
-#define LIST_EMPTY(head) ((head)->lh_first == NULL)
-
-#define LIST_FIRST(head) ((head)->lh_first)
-
-#define LIST_FOREACH(var, head, field) \
- for((var) = (head)->lh_first; (var); (var) = (var)->field.le_next)
-
-#define LIST_INIT(head) do { \
- (head)->lh_first = NULL; \
-} while (0)
-
-#define LIST_INSERT_AFTER(listelm, elm, field) do { \
- if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
- (listelm)->field.le_next->field.le_prev = \
- &(elm)->field.le_next; \
- (listelm)->field.le_next = (elm); \
- (elm)->field.le_prev = &(listelm)->field.le_next; \
-} while (0)
-
-#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
- (elm)->field.le_prev = (listelm)->field.le_prev; \
- (elm)->field.le_next = (listelm); \
- *(listelm)->field.le_prev = (elm); \
- (listelm)->field.le_prev = &(elm)->field.le_next; \
-} while (0)
-
-#define LIST_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.le_next = (head)->lh_first) != NULL) \
- (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
- (head)->lh_first = (elm); \
- (elm)->field.le_prev = &(head)->lh_first; \
-} while (0)
-
-#define LIST_NEXT(elm, field) ((elm)->field.le_next)
-
-#define LIST_REMOVE(elm, field) do { \
- if ((elm)->field.le_next != NULL) \
- (elm)->field.le_next->field.le_prev = \
- (elm)->field.le_prev; \
- *(elm)->field.le_prev = (elm)->field.le_next; \
-} while (0)
-
-/*
- * Tail queue definitions.
- */
-#define TAILQ_HEAD(name, type) \
-struct name { \
- struct type *tqh_first; /* first element */ \
- struct type **tqh_last; /* addr of last next element */ \
-}
-
-#define TAILQ_HEAD_INITIALIZER(head) \
- { NULL, &(head).tqh_first }
-
-#define TAILQ_ENTRY(type) \
-struct { \
- struct type *tqe_next; /* next element */ \
- struct type **tqe_prev; /* address of previous next element */ \
-}
-
-/*
- * Tail queue functions.
- */
-#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
-
-#define TAILQ_FOREACH(var, head, field) \
- for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field))
-
-#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
- for ((var) = TAILQ_LAST((head), headname); \
- (var); \
- (var) = TAILQ_PREV((var), headname, field))
-
-#define TAILQ_FIRST(head) ((head)->tqh_first)
-
-#define TAILQ_LAST(head, headname) \
- (*(((struct headname *)((head)->tqh_last))->tqh_last))
-
-#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
-
-#define TAILQ_PREV(elm, headname, field) \
- (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
-
-#define TAILQ_INIT(head) do { \
- (head)->tqh_first = NULL; \
- (head)->tqh_last = &(head)->tqh_first; \
-} while (0)
-
-#define TAILQ_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
- (head)->tqh_first->field.tqe_prev = \
- &(elm)->field.tqe_next; \
- else \
- (head)->tqh_last = &(elm)->field.tqe_next; \
- (head)->tqh_first = (elm); \
- (elm)->field.tqe_prev = &(head)->tqh_first; \
-} while (0)
-
-#define TAILQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.tqe_next = NULL; \
- (elm)->field.tqe_prev = (head)->tqh_last; \
- *(head)->tqh_last = (elm); \
- (head)->tqh_last = &(elm)->field.tqe_next; \
-} while (0)
-
-#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
- if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
- (elm)->field.tqe_next->field.tqe_prev = \
- &(elm)->field.tqe_next; \
- else \
- (head)->tqh_last = &(elm)->field.tqe_next; \
- (listelm)->field.tqe_next = (elm); \
- (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
-} while (0)
-
-#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
- (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
- (elm)->field.tqe_next = (listelm); \
- *(listelm)->field.tqe_prev = (elm); \
- (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
-} while (0)
-
-#define TAILQ_REMOVE(head, elm, field) do { \
- if (((elm)->field.tqe_next) != NULL) \
- (elm)->field.tqe_next->field.tqe_prev = \
- (elm)->field.tqe_prev; \
- else \
- (head)->tqh_last = (elm)->field.tqe_prev; \
- *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
-} while (0)
-
-/*
- * Circular queue definitions.
- */
-#define CIRCLEQ_HEAD(name, type) \
-struct name { \
- struct type *cqh_first; /* first element */ \
- struct type *cqh_last; /* last element */ \
-}
-
-#define CIRCLEQ_ENTRY(type) \
-struct { \
- struct type *cqe_next; /* next element */ \
- struct type *cqe_prev; /* previous element */ \
-}
-
-/*
- * Circular queue functions.
- */
-#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
-
-#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
-
-#define CIRCLEQ_FOREACH(var, head, field) \
- for((var) = (head)->cqh_first; \
- (var) != (void *)(head); \
- (var) = (var)->field.cqe_next)
-
-#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
- for((var) = (head)->cqh_last; \
- (var) != (void *)(head); \
- (var) = (var)->field.cqe_prev)
-
-#define CIRCLEQ_INIT(head) do { \
- (head)->cqh_first = (void *)(head); \
- (head)->cqh_last = (void *)(head); \
-} while (0)
-
-#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
- (elm)->field.cqe_next = (listelm)->field.cqe_next; \
- (elm)->field.cqe_prev = (listelm); \
- if ((listelm)->field.cqe_next == (void *)(head)) \
- (head)->cqh_last = (elm); \
- else \
- (listelm)->field.cqe_next->field.cqe_prev = (elm); \
- (listelm)->field.cqe_next = (elm); \
-} while (0)
-
-#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
- (elm)->field.cqe_next = (listelm); \
- (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
- if ((listelm)->field.cqe_prev == (void *)(head)) \
- (head)->cqh_first = (elm); \
- else \
- (listelm)->field.cqe_prev->field.cqe_next = (elm); \
- (listelm)->field.cqe_prev = (elm); \
-} while (0)
-
-#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
- (elm)->field.cqe_next = (head)->cqh_first; \
- (elm)->field.cqe_prev = (void *)(head); \
- if ((head)->cqh_last == (void *)(head)) \
- (head)->cqh_last = (elm); \
- else \
- (head)->cqh_first->field.cqe_prev = (elm); \
- (head)->cqh_first = (elm); \
-} while (0)
-
-#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.cqe_next = (void *)(head); \
- (elm)->field.cqe_prev = (head)->cqh_last; \
- if ((head)->cqh_first == (void *)(head)) \
- (head)->cqh_first = (elm); \
- else \
- (head)->cqh_last->field.cqe_next = (elm); \
- (head)->cqh_last = (elm); \
-} while (0)
-
-#define CIRCLEQ_LAST(head) ((head)->cqh_last)
-
-#define CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next)
-
-#define CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev)
-
-#define CIRCLEQ_REMOVE(head, elm, field) do { \
- if ((elm)->field.cqe_next == (void *)(head)) \
- (head)->cqh_last = (elm)->field.cqe_prev; \
- else \
- (elm)->field.cqe_next->field.cqe_prev = \
- (elm)->field.cqe_prev; \
- if ((elm)->field.cqe_prev == (void *)(head)) \
- (head)->cqh_first = (elm)->field.cqe_next; \
- else \
- (elm)->field.cqe_prev->field.cqe_next = \
- (elm)->field.cqe_next; \
-} while (0)
-
-#ifdef KERNEL
-
-/*
- * XXX insque() and remque() are an old way of handling certain queues.
- * They bogusly assumes that all queue heads look alike.
- */
-
-struct quehead {
- struct quehead *qh_link;
- struct quehead *qh_rlink;
-};
-
-#ifdef __GNUC__
-
-static __inline void
-insque(void *a, void *b)
-{
- struct quehead *element = a, *head = b;
-
- element->qh_link = head->qh_link;
- element->qh_rlink = head;
- head->qh_link = element;
- element->qh_link->qh_rlink = element;
-}
-
-static __inline void
-remque(void *a)
-{
- struct quehead *element = a;
-
- element->qh_link->qh_rlink = element->qh_rlink;
- element->qh_rlink->qh_link = element->qh_link;
- element->qh_rlink = 0;
-}
-
-#else /* !__GNUC__ */
-
-void insque __P((void *a, void *b));
-void remque __P((void *a));
-
-#endif /* __GNUC__ */
-
-#endif /* KERNEL */
-
-#endif /* !_SYS_QUEUE_H_ */
-
diff --git a/1.2-netsec/indications.c b/1.2-netsec/indications.c
deleted file mode 100644
index e9ca85d9c..000000000
--- a/1.2-netsec/indications.c
+++ /dev/null
@@ -1,611 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2002, Pauline Middelink
- *
- *
- * 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 Tone Management
- *
- * \author Pauline Middelink <middelink@polyware.nl>
- *
- * This set of function allow us to play a list of tones on a channel.
- * Each element has two frequencies, which are mixed together and a
- * duration. For silence both frequencies can be set to 0.
- * The playtones can be given as a comma separated string.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h> /* For PI */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/indications.h"
-#include "asterisk/frame.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-
-static int midi_tohz[128] = {
- 8,8,9,9,10,10,11,12,12,13,14,
- 15,16,17,18,19,20,21,23,24,25,
- 27,29,30,32,34,36,38,41,43,46,
- 48,51,55,58,61,65,69,73,77,82,
- 87,92,97,103,110,116,123,130,138,146,
- 155,164,174,184,195,207,220,233,246,261,
- 277,293,311,329,349,369,391,415,440,466,
- 493,523,554,587,622,659,698,739,783,830,
- 880,932,987,1046,1108,1174,1244,1318,1396,1479,
- 1567,1661,1760,1864,1975,2093,2217,2349,2489,2637,
- 2793,2959,3135,3322,3520,3729,3951,4186,4434,4698,
- 4978,5274,5587,5919,6271,6644,7040,7458,7902,8372,
- 8869,9397,9956,10548,11175,11839,12543
- };
-
-struct playtones_item {
- int fac1;
- int init_v2_1;
- int init_v3_1;
- int fac2;
- int init_v2_2;
- int init_v3_2;
- int modulate;
- int duration;
-};
-
-struct playtones_def {
- int vol;
- int reppos;
- int nitems;
- int interruptible;
- struct playtones_item *items;
-};
-
-struct playtones_state {
- int vol;
- int v1_1;
- int v2_1;
- int v3_1;
- int v1_2;
- int v2_2;
- int v3_2;
- int reppos;
- int nitems;
- struct playtones_item *items;
- int npos;
- int oldnpos;
- int pos;
- int origwfmt;
- struct ast_frame f;
- unsigned char offset[AST_FRIENDLY_OFFSET];
- short data[4000];
-};
-
-static void playtones_release(struct ast_channel *chan, void *params)
-{
- struct playtones_state *ps = params;
- if (chan) {
- ast_set_write_format(chan, ps->origwfmt);
- }
- if (ps->items) free(ps->items);
- free(ps);
-}
-
-static void * playtones_alloc(struct ast_channel *chan, void *params)
-{
- struct playtones_def *pd = params;
- struct playtones_state *ps = malloc(sizeof(struct playtones_state));
- if (!ps)
- return NULL;
- memset(ps, 0, sizeof(struct playtones_state));
- ps->origwfmt = chan->writeformat;
- if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
- ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
- playtones_release(NULL, ps);
- ps = NULL;
- } else {
- ps->vol = pd->vol;
- ps->reppos = pd->reppos;
- ps->nitems = pd->nitems;
- ps->items = pd->items;
- ps->oldnpos = -1;
- }
- /* Let interrupts interrupt :) */
- if (pd->interruptible)
- ast_set_flag(chan, AST_FLAG_WRITE_INT);
- else
- ast_clear_flag(chan, AST_FLAG_WRITE_INT);
- return ps;
-}
-
-static int playtones_generator(struct ast_channel *chan, void *data, int len, int samples)
-{
- struct playtones_state *ps = data;
- struct playtones_item *pi;
- int x;
- /* we need to prepare a frame with 16 * timelen samples as we're
- * generating SLIN audio
- */
- len = samples * 2;
- if (len > sizeof(ps->data) / 2 - 1) {
- ast_log(LOG_WARNING, "Can't generate that much data!\n");
- return -1;
- }
- memset(&ps->f, 0, sizeof(ps->f));
-
- pi = &ps->items[ps->npos];
- if (ps->oldnpos != ps->npos) {
- /* Load new parameters */
- ps->v1_1 = 0;
- ps->v2_1 = pi->init_v2_1;
- ps->v3_1 = pi->init_v3_1;
- ps->v1_2 = 0;
- ps->v2_2 = pi->init_v2_2;
- ps->v3_2 = pi->init_v3_2;
- ps->oldnpos = ps->npos;
- }
- for (x=0;x<len/2;x++) {
- ps->v1_1 = ps->v2_1;
- ps->v2_1 = ps->v3_1;
- ps->v3_1 = (pi->fac1 * ps->v2_1 >> 15) - ps->v1_1;
-
- ps->v1_2 = ps->v2_2;
- ps->v2_2 = ps->v3_2;
- ps->v3_2 = (pi->fac2 * ps->v2_2 >> 15) - ps->v1_2;
- if (pi->modulate) {
- int p;
- p = ps->v3_2 - 32768;
- if (p < 0) p = -p;
- p = ((p * 9) / 10) + 1;
- ps->data[x] = (ps->v3_1 * p) >> 15;
- } else
- ps->data[x] = ps->v3_1 + ps->v3_2;
- }
-
- ps->f.frametype = AST_FRAME_VOICE;
- ps->f.subclass = AST_FORMAT_SLINEAR;
- ps->f.datalen = len;
- ps->f.samples = samples;
- ps->f.offset = AST_FRIENDLY_OFFSET;
- ps->f.data = ps->data;
- ps->f.delivery.tv_sec = 0;
- ps->f.delivery.tv_usec = 0;
- ast_write(chan, &ps->f);
-
- ps->pos += x;
- if (pi->duration && ps->pos >= pi->duration * 8) { /* item finished? */
- ps->pos = 0; /* start new item */
- ps->npos++;
- if (ps->npos >= ps->nitems) { /* last item? */
- if (ps->reppos == -1) /* repeat set? */
- return -1;
- ps->npos = ps->reppos; /* redo from top */
- }
- }
- return 0;
-}
-
-static struct ast_generator playtones = {
- alloc: playtones_alloc,
- release: playtones_release,
- generate: playtones_generator,
-};
-
-int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst, int interruptible)
-{
- char *s, *data = ast_strdupa(playlst); /* cute */
- struct playtones_def d = { vol, -1, 0, 1, NULL};
- char *stringp=NULL;
- char *separator;
- if (!data)
- return -1;
- if (vol < 1)
- d.vol = 7219; /* Default to -8db */
-
- d.interruptible = interruptible;
-
- stringp=data;
- /* the stringp/data is not null here */
- /* check if the data is separated with '|' or with ',' by default */
- if (strchr(stringp,'|'))
- separator = "|";
- else
- separator = ",";
- s = strsep(&stringp,separator);
- while (s && *s) {
- int freq1, freq2, time, modulate=0, midinote=0;
-
- if (s[0]=='!')
- s++;
- else if (d.reppos == -1)
- d.reppos = d.nitems;
- if (sscanf(s, "%d+%d/%d", &freq1, &freq2, &time) == 3) {
- /* f1+f2/time format */
- } else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) {
- /* f1+f2 format */
- time = 0;
- } else if (sscanf(s, "%d*%d/%d", &freq1, &freq2, &time) == 3) {
- /* f1*f2/time format */
- modulate = 1;
- } else if (sscanf(s, "%d*%d", &freq1, &freq2) == 2) {
- /* f1*f2 format */
- time = 0;
- modulate = 1;
- } else if (sscanf(s, "%d/%d", &freq1, &time) == 2) {
- /* f1/time format */
- freq2 = 0;
- } else if (sscanf(s, "%d", &freq1) == 1) {
- /* f1 format */
- freq2 = 0;
- time = 0;
- } else if (sscanf(s, "M%d+M%d/%d", &freq1, &freq2, &time) == 3) {
- /* Mf1+Mf2/time format */
- midinote = 1;
- } else if (sscanf(s, "M%d+M%d", &freq1, &freq2) == 2) {
- /* Mf1+Mf2 format */
- time = 0;
- midinote = 1;
- } else if (sscanf(s, "M%d*M%d/%d", &freq1, &freq2, &time) == 3) {
- /* Mf1*Mf2/time format */
- modulate = 1;
- midinote = 1;
- } else if (sscanf(s, "M%d*M%d", &freq1, &freq2) == 2) {
- /* Mf1*Mf2 format */
- time = 0;
- modulate = 1;
- midinote = 1;
- } else if (sscanf(s, "M%d/%d", &freq1, &time) == 2) {
- /* Mf1/time format */
- freq2 = -1;
- midinote = 1;
- } else if (sscanf(s, "M%d", &freq1) == 1) {
- /* Mf1 format */
- freq2 = -1;
- time = 0;
- midinote = 1;
- } else {
- ast_log(LOG_WARNING,"%s: tone component '%s' of '%s' is no good\n",chan->name,s,playlst);
- return -1;
- }
-
- if (midinote) {
- /* midi notes must be between 0 and 127 */
- if ((freq1 >= 0) && (freq1 <= 127))
- freq1 = midi_tohz[freq1];
- else
- freq1 = 0;
-
- if ((freq2 >= 0) && (freq2 <= 127))
- freq2 = midi_tohz[freq2];
- else
- freq2 = 0;
- }
-
- d.items = realloc(d.items,(d.nitems+1)*sizeof(struct playtones_item));
- if (d.items == NULL) {
- ast_log(LOG_WARNING, "Realloc failed!\n");
- return -1;
- }
- d.items[d.nitems].fac1 = 2.0 * cos(2.0 * M_PI * (freq1 / 8000.0)) * 32768.0;
- d.items[d.nitems].init_v2_1 = sin(-4.0 * M_PI * (freq1 / 8000.0)) * d.vol;
- d.items[d.nitems].init_v3_1 = sin(-2.0 * M_PI * (freq1 / 8000.0)) * d.vol;
-
- d.items[d.nitems].fac2 = 2.0 * cos(2.0 * M_PI * (freq2 / 8000.0)) * 32768.0;
- d.items[d.nitems].init_v2_2 = sin(-4.0 * M_PI * (freq2 / 8000.0)) * d.vol;
- d.items[d.nitems].init_v3_2 = sin(-2.0 * M_PI * (freq2 / 8000.0)) * d.vol;
- d.items[d.nitems].duration = time;
- d.items[d.nitems].modulate = modulate;
- d.nitems++;
-
- s = strsep(&stringp,separator);
- }
-
- if (ast_activate_generator(chan, &playtones, &d)) {
- free(d.items);
- return -1;
- }
- return 0;
-}
-
-void ast_playtones_stop(struct ast_channel *chan)
-{
- ast_deactivate_generator(chan);
-}
-
-/*--------------------------------------------*/
-
-struct tone_zone *tone_zones;
-static struct tone_zone *current_tonezone;
-
-/* Protect the tone_zones list (highly unlikely that two things would change
- * it at the same time, but still! */
-AST_MUTEX_DEFINE_EXPORTED(tzlock);
-
-/* Set global indication country */
-int ast_set_indication_country(const char *country)
-{
- if (country) {
- struct tone_zone *z = ast_get_indication_zone(country);
- if (z) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Setting default indication country to '%s'\n",country);
- current_tonezone = z;
- return 0;
- }
- }
- return 1; /* not found */
-}
-
-/* locate tone_zone, given the country. if country == NULL, use the default country */
-struct tone_zone *ast_get_indication_zone(const char *country)
-{
- struct tone_zone *tz;
- int alias_loop = 0;
-
- /* we need some tonezone, pick the first */
- if (country == NULL && current_tonezone)
- return current_tonezone; /* default country? */
- if (country == NULL && tone_zones)
- return tone_zones; /* any country? */
- if (country == NULL)
- return 0; /* not a single country insight */
-
- if (ast_mutex_lock(&tzlock)) {
- ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
- return 0;
- }
- do {
- for (tz=tone_zones; tz; tz=tz->next) {
- if (strcasecmp(country,tz->country)==0) {
- /* tone_zone found */
- if (tz->alias && tz->alias[0]) {
- country = tz->alias;
- break;
- }
- ast_mutex_unlock(&tzlock);
- return tz;
- }
- }
- } while (++alias_loop<20 && tz);
- ast_mutex_unlock(&tzlock);
- if (alias_loop==20)
- ast_log(LOG_NOTICE,"Alias loop for '%s' forcefull broken\n",country);
- /* nothing found, sorry */
- return 0;
-}
-
-/* locate a tone_zone_sound, given the tone_zone. if tone_zone == NULL, use the default tone_zone */
-struct tone_zone_sound *ast_get_indication_tone(const struct tone_zone *zone, const char *indication)
-{
- struct tone_zone_sound *ts;
-
- /* we need some tonezone, pick the first */
- if (zone == NULL && current_tonezone)
- zone = current_tonezone; /* default country? */
- if (zone == NULL && tone_zones)
- zone = tone_zones; /* any country? */
- if (zone == NULL)
- return 0; /* not a single country insight */
-
- if (ast_mutex_lock(&tzlock)) {
- ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
- return 0;
- }
- for (ts=zone->tones; ts; ts=ts->next) {
- if (strcasecmp(indication,ts->name)==0) {
- /* found indication! */
- ast_mutex_unlock(&tzlock);
- return ts;
- }
- }
- /* nothing found, sorry */
- ast_mutex_unlock(&tzlock);
- return 0;
-}
-
-/* helper function to delete a tone_zone in its entirety */
-static inline void free_zone(struct tone_zone* zone)
-{
- while (zone->tones) {
- struct tone_zone_sound *tmp = zone->tones->next;
- free((void*)zone->tones->name);
- free((void*)zone->tones->data);
- free(zone->tones);
- zone->tones = tmp;
- }
- if (zone->ringcadence)
- free((void*)zone->ringcadence);
- free(zone);
-}
-
-/*--------------------------------------------*/
-
-/* add a new country, if country exists, it will be replaced. */
-int ast_register_indication_country(struct tone_zone *zone)
-{
- struct tone_zone *tz,*pz;
-
- if (ast_mutex_lock(&tzlock)) {
- ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
- return -1;
- }
- for (pz=NULL,tz=tone_zones; tz; pz=tz,tz=tz->next) {
- if (strcasecmp(zone->country,tz->country)==0) {
- /* tone_zone already there, replace */
- zone->next = tz->next;
- if (pz)
- pz->next = zone;
- else
- tone_zones = zone;
- /* if we are replacing the default zone, re-point it */
- if (tz == current_tonezone)
- current_tonezone = zone;
- /* now free the previous zone */
- free_zone(tz);
- ast_mutex_unlock(&tzlock);
- return 0;
- }
- }
- /* country not there, add */
- zone->next = NULL;
- if (pz)
- pz->next = zone;
- else
- tone_zones = zone;
- ast_mutex_unlock(&tzlock);
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Registered indication country '%s'\n",zone->country);
- return 0;
-}
-
-/* remove an existing country and all its indications, country must exist.
- * Also, all countries which are an alias for the specified country are removed. */
-int ast_unregister_indication_country(const char *country)
-{
- struct tone_zone *tz, *pz = NULL, *tmp;
- int res = -1;
-
- if (ast_mutex_lock(&tzlock)) {
- ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
- return -1;
- }
- tz = tone_zones;
- while (tz) {
- if (country==NULL ||
- (strcasecmp(country, tz->country)==0 ||
- strcasecmp(country, tz->alias)==0)) {
- /* tone_zone found, remove */
- tmp = tz->next;
- if (pz)
- pz->next = tmp;
- else
- tone_zones = tmp;
- /* if we are unregistering the default country, w'll notice */
- if (tz == current_tonezone) {
- ast_log(LOG_NOTICE,"Removed default indication country '%s'\n",tz->country);
- current_tonezone = NULL;
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Unregistered indication country '%s'\n",tz->country);
- free_zone(tz);
- if (tone_zones == tz)
- tone_zones = tmp;
- tz = tmp;
- res = 0;
- }
- else {
- /* next zone please */
- pz = tz;
- tz = tz->next;
- }
- }
- ast_mutex_unlock(&tzlock);
- return res;
-}
-
-/* add a new indication to a tone_zone. tone_zone must exist. if the indication already
- * exists, it will be replaced. */
-int ast_register_indication(struct tone_zone *zone, const char *indication, const char *tonelist)
-{
- struct tone_zone_sound *ts,*ps;
-
- /* is it an alias? stop */
- if (zone->alias[0])
- return -1;
-
- if (ast_mutex_lock(&tzlock)) {
- ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
- return -2;
- }
- for (ps=NULL,ts=zone->tones; ts; ps=ts,ts=ts->next) {
- if (strcasecmp(indication,ts->name)==0) {
- /* indication already there, replace */
- free((void*)ts->name);
- free((void*)ts->data);
- break;
- }
- }
- if (!ts) {
- /* not there, we have to add */
- ts = malloc(sizeof(struct tone_zone_sound));
- if (!ts) {
- ast_log(LOG_WARNING, "Out of memory\n");
- ast_mutex_unlock(&tzlock);
- return -2;
- }
- ts->next = NULL;
- }
- ts->name = strdup(indication);
- ts->data = strdup(tonelist);
- if (ts->name==NULL || ts->data==NULL) {
- ast_log(LOG_WARNING, "Out of memory\n");
- ast_mutex_unlock(&tzlock);
- return -2;
- }
- if (ps)
- ps->next = ts;
- else
- zone->tones = ts;
- ast_mutex_unlock(&tzlock);
- return 0;
-}
-
-/* remove an existing country's indication. Both country and indication must exist */
-int ast_unregister_indication(struct tone_zone *zone, const char *indication)
-{
- struct tone_zone_sound *ts,*ps = NULL, *tmp;
- int res = -1;
-
- /* is it an alias? stop */
- if (zone->alias[0])
- return -1;
-
- if (ast_mutex_lock(&tzlock)) {
- ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
- return -1;
- }
- ts = zone->tones;
- while (ts) {
- if (strcasecmp(indication,ts->name)==0) {
- /* indication found */
- tmp = ts->next;
- if (ps)
- ps->next = tmp;
- else
- zone->tones = tmp;
- free((void*)ts->name);
- free((void*)ts->data);
- free(ts);
- ts = tmp;
- res = 0;
- }
- else {
- /* next zone please */
- ps = ts;
- ts = ts->next;
- }
- }
- /* indication not found, goodbye */
- ast_mutex_unlock(&tzlock);
- return res;
-}
diff --git a/1.2-netsec/io.c b/1.2-netsec/io.c
deleted file mode 100644
index c19d222c6..000000000
--- a/1.2-netsec/io.c
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief I/O Managment (Derived from Cheops-NG)
- *
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <termios.h>
-#include <string.h> /* for memset */
-#include <sys/ioctl.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/io.h"
-#include "asterisk/logger.h"
-
-#ifdef DEBUG_IO
-#define DEBUG DEBUG_M
-#else
-#define DEBUG(a)
-#endif
-
-/*
- * Kept for each file descriptor
- */
-struct io_rec {
- ast_io_cb callback; /* What is to be called */
- void *data; /* Data to be passed */
- int *id; /* ID number */
-};
-
-/* These two arrays are keyed with
- the same index. it's too bad that
- pollfd doesn't have a callback field
- or something like that. They grow as
- needed, by GROW_SHRINK_AMOUNT structures
- at once */
-
-#define GROW_SHRINK_SIZE 512
-
-/* Global variables are now in a struct in order to be
- made threadsafe */
-struct io_context {
- /* Poll structure */
- struct pollfd *fds;
- /* Associated I/O records */
- struct io_rec *ior;
- /* First available fd */
- unsigned int fdcnt;
- /* Maximum available fd */
- unsigned int maxfdcnt;
- /* Currently used io callback */
- int current_ioc;
- /* Whether something has been deleted */
- int needshrink;
-};
-
-struct io_context *io_context_create(void)
-{
- /* Create an I/O context */
- struct io_context *tmp;
- tmp = malloc(sizeof(struct io_context));
- if (tmp) {
- tmp->needshrink = 0;
- tmp->fdcnt = 0;
- tmp->maxfdcnt = GROW_SHRINK_SIZE/2;
- tmp->current_ioc = -1;
- tmp->fds = malloc((GROW_SHRINK_SIZE/2) * sizeof(struct pollfd));
- if (!tmp->fds) {
- free(tmp);
- tmp = NULL;
- } else {
- memset(tmp->fds, 0, (GROW_SHRINK_SIZE / 2) * sizeof(struct pollfd));
- tmp->ior = malloc((GROW_SHRINK_SIZE / 2) * sizeof(struct io_rec));
- if (!tmp->ior) {
- free(tmp->fds);
- free(tmp);
- tmp = NULL;
- } else {
- memset(tmp->ior, 0, (GROW_SHRINK_SIZE / 2) * sizeof(struct io_rec));
- }
- }
- }
- return tmp;
-}
-
-void io_context_destroy(struct io_context *ioc)
-{
- /* Free associated memory with an I/O context */
- if (ioc->fds)
- free(ioc->fds);
- if (ioc->ior)
- free(ioc->ior);
- free(ioc);
-}
-
-static int io_grow(struct io_context *ioc)
-{
- /*
- * Grow the size of our arrays. Return 0 on success or
- * -1 on failure
- */
- void *tmp;
- DEBUG(ast_log(LOG_DEBUG, "io_grow()\n"));
- ioc->maxfdcnt += GROW_SHRINK_SIZE;
- tmp = realloc(ioc->ior, (ioc->maxfdcnt + 1) * sizeof(struct io_rec));
- if (tmp) {
- ioc->ior = (struct io_rec *)tmp;
- tmp = realloc(ioc->fds, (ioc->maxfdcnt + 1) * sizeof(struct pollfd));
- if (tmp) {
- ioc->fds = tmp;
- } else {
- /*
- * Not enough memory for the pollfd. Not really any need
- * to shrink back the iorec's as we'll probably want to
- * grow them again soon when more memory is available, and
- * then they'll already be the right size
- */
- ioc->maxfdcnt -= GROW_SHRINK_SIZE;
- return -1;
- }
- } else {
- /*
- * Out of memory. We return to the old size, and return a failure
- */
- ioc->maxfdcnt -= GROW_SHRINK_SIZE;
- return -1;
- }
- return 0;
-}
-
-int *ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data)
-{
- /*
- * Add a new I/O entry for this file descriptor
- * with the given event mask, to call callback with
- * data as an argument. Returns NULL on failure.
- */
- int *ret;
- DEBUG(ast_log(LOG_DEBUG, "ast_io_add()\n"));
- if (ioc->fdcnt >= ioc->maxfdcnt) {
- /*
- * We don't have enough space for this entry. We need to
- * reallocate maxfdcnt poll fd's and io_rec's, or back out now.
- */
- if (io_grow(ioc))
- return NULL;
- }
-
- /*
- * At this point, we've got sufficiently large arrays going
- * and we can make an entry for it in the pollfd and io_r
- * structures.
- */
- ioc->fds[ioc->fdcnt].fd = fd;
- ioc->fds[ioc->fdcnt].events = events;
- ioc->fds[ioc->fdcnt].revents = 0;
- ioc->ior[ioc->fdcnt].callback = callback;
- ioc->ior[ioc->fdcnt].data = data;
- ioc->ior[ioc->fdcnt].id = (int *)malloc(sizeof(int));
- /* Bonk if we couldn't allocate an int */
- if (!ioc->ior[ioc->fdcnt].id)
- return NULL;
- *(ioc->ior[ioc->fdcnt].id) = ioc->fdcnt;
- ret = ioc->ior[ioc->fdcnt].id;
- ioc->fdcnt++;
- return ret;
-}
-
-int *ast_io_change(struct io_context *ioc, int *id, int fd, ast_io_cb callback, short events, void *data)
-{
- if (*id < ioc->fdcnt) {
- if (fd > -1)
- ioc->fds[*id].fd = fd;
- if (callback)
- ioc->ior[*id].callback = callback;
- if (events)
- ioc->fds[*id].events = events;
- if (data)
- ioc->ior[*id].data = data;
- return id;
- }
- return NULL;
-}
-
-static int io_shrink(struct io_context *ioc)
-{
- int getfrom;
- int putto = 0;
- /*
- * Bring the fields from the very last entry to cover over
- * the entry we are removing, then decrease the size of the
- * arrays by one.
- */
- for (getfrom = 0; getfrom < ioc->fdcnt; getfrom++) {
- if (ioc->ior[getfrom].id) {
- /* In use, save it */
- if (getfrom != putto) {
- ioc->fds[putto] = ioc->fds[getfrom];
- ioc->ior[putto] = ioc->ior[getfrom];
- *(ioc->ior[putto].id) = putto;
- }
- putto++;
- }
- }
- ioc->fdcnt = putto;
- ioc->needshrink = 0;
- /* FIXME: We should free some memory if we have lots of unused
- io structs */
- return 0;
-}
-
-int ast_io_remove(struct io_context *ioc, int *_id)
-{
- int x;
- if (!_id) {
- ast_log(LOG_WARNING, "Asked to remove NULL?\n");
- return -1;
- }
- for (x = 0; x < ioc->fdcnt; x++) {
- if (ioc->ior[x].id == _id) {
- /* Free the int immediately and set to NULL so we know it's unused now */
- free(ioc->ior[x].id);
- ioc->ior[x].id = NULL;
- ioc->fds[x].events = 0;
- ioc->fds[x].revents = 0;
- ioc->needshrink = 1;
- if (!ioc->current_ioc)
- io_shrink(ioc);
- return 0;
- }
- }
-
- ast_log(LOG_NOTICE, "Unable to remove unknown id %p\n", _id);
- return -1;
-}
-
-int ast_io_wait(struct io_context *ioc, int howlong)
-{
- /*
- * Make the poll call, and call
- * the callbacks for anything that needs
- * to be handled
- */
- int res;
- int x;
- int origcnt;
- DEBUG(ast_log(LOG_DEBUG, "ast_io_wait()\n"));
- res = poll(ioc->fds, ioc->fdcnt, howlong);
- if (res > 0) {
- /*
- * At least one event
- */
- origcnt = ioc->fdcnt;
- for(x = 0; x < origcnt; x++) {
- /* Yes, it is possible for an entry to be deleted and still have an
- event waiting if it occurs after the original calling id */
- if (ioc->fds[x].revents && ioc->ior[x].id) {
- /* There's an event waiting */
- ioc->current_ioc = *ioc->ior[x].id;
- if (ioc->ior[x].callback) {
- if (!ioc->ior[x].callback(ioc->ior[x].id, ioc->fds[x].fd, ioc->fds[x].revents, ioc->ior[x].data)) {
- /* Time to delete them since they returned a 0 */
- ast_io_remove(ioc, ioc->ior[x].id);
- }
- }
- ioc->current_ioc = -1;
- }
- }
- if (ioc->needshrink)
- io_shrink(ioc);
- }
- return res;
-}
-
-void ast_io_dump(struct io_context *ioc)
-{
- /*
- * Print some debugging information via
- * the logger interface
- */
- int x;
- ast_log(LOG_DEBUG, "Asterisk IO Dump: %d entries, %d max entries\n", ioc->fdcnt, ioc->maxfdcnt);
- ast_log(LOG_DEBUG, "================================================\n");
- ast_log(LOG_DEBUG, "| ID FD Callback Data Events |\n");
- ast_log(LOG_DEBUG, "+------+------+-----------+-----------+--------+\n");
- for (x = 0; x < ioc->fdcnt; x++) {
- ast_log(LOG_DEBUG, "| %.4d | %.4d | %p | %p | %.6x |\n",
- *ioc->ior[x].id,
- ioc->fds[x].fd,
- ioc->ior[x].callback,
- ioc->ior[x].data,
- ioc->fds[x].events);
- }
- ast_log(LOG_DEBUG, "================================================\n");
-}
-
-/* Unrelated I/O functions */
-
-int ast_hide_password(int fd)
-{
- struct termios tios;
- int res;
- int old;
- if (!isatty(fd))
- return -1;
- res = tcgetattr(fd, &tios);
- if (res < 0)
- return -1;
- old = tios.c_lflag & (ECHO | ECHONL);
- tios.c_lflag &= ~ECHO;
- tios.c_lflag |= ECHONL;
- res = tcsetattr(fd, TCSAFLUSH, &tios);
- if (res < 0)
- return -1;
- return old;
-}
-
-int ast_restore_tty(int fd, int oldstate)
-{
- int res;
- struct termios tios;
- if (oldstate < 0)
- return 0;
- res = tcgetattr(fd, &tios);
- if (res < 0)
- return -1;
- tios.c_lflag &= ~(ECHO | ECHONL);
- tios.c_lflag |= oldstate;
- res = tcsetattr(fd, TCSAFLUSH, &tios);
- if (res < 0)
- return -1;
- return 0;
-}
-
-int ast_get_termcols(int fd)
-{
- struct winsize win;
- int cols = 0;
-
- if (!isatty(fd))
- return -1;
-
- if ( ioctl(fd, TIOCGWINSZ, &win) != -1 ) {
- if ( !cols && win.ws_col > 0 )
- cols = (int) win.ws_col;
- } else {
- /* assume 80 characters if the ioctl fails for some reason */
- cols = 80;
- }
-
- return cols;
-}
-
diff --git a/1.2-netsec/jitterbuf.c b/1.2-netsec/jitterbuf.c
deleted file mode 100644
index 2fb349764..000000000
--- a/1.2-netsec/jitterbuf.c
+++ /dev/null
@@ -1,829 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004-2005, Horizon Wimba, Inc.
- *
- * Contributors:
- * Steve Kann <stevek@stevek.com>
- *
- * Copyright on this file is disclaimed to Digium for inclusion in Asterisk
- *
- * 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 jitterbuf: an application-independent jitterbuffer
- * \author Steve Kann <stevek@stevek.com>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "jitterbuf.h"
-
-/*! define these here, just for ancient compiler systems */
-#define JB_LONGMAX 2147483647L
-#define JB_LONGMIN (-JB_LONGMAX - 1L)
-
-#define jb_warn(...) (warnf ? warnf(__VA_ARGS__) : (void)0)
-#define jb_err(...) (errf ? errf(__VA_ARGS__) : (void)0)
-#define jb_dbg(...) (dbgf ? dbgf(__VA_ARGS__) : (void)0)
-
-#ifdef DEEP_DEBUG
-#define jb_dbg2(...) (dbgf ? dbgf(__VA_ARGS__) : (void)0)
-#else
-#define jb_dbg2(...) ((void)0)
-#endif
-
-static jb_output_function_t warnf, errf, dbgf;
-
-void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg)
-{
- errf = err;
- warnf = warn;
- dbgf = dbg;
-}
-
-static void increment_losspct(jitterbuf *jb)
-{
- jb->info.losspct = (100000 + 499 * jb->info.losspct)/500;
-}
-
-static void decrement_losspct(jitterbuf *jb)
-{
- jb->info.losspct = (499 * jb->info.losspct)/500;
-}
-
-void jb_reset(jitterbuf *jb)
-{
- /* only save settings */
- jb_conf s = jb->info.conf;
- memset(jb,0,sizeof(jitterbuf));
- jb->info.conf = s;
-
- /* initialize length */
- jb->info.current = jb->info.target = JB_TARGET_EXTRA;
- jb->info.silence_begin_ts = -1;
-}
-
-jitterbuf * jb_new()
-{
- jitterbuf *jb;
-
-
- jb = malloc(sizeof(jitterbuf));
- if (!jb)
- return NULL;
-
- jb_reset(jb);
-
- jb_dbg2("jb_new() = %x\n", jb);
- return jb;
-}
-
-void jb_destroy(jitterbuf *jb)
-{
- jb_frame *frame;
- jb_dbg2("jb_destroy(%x)\n", jb);
-
- /* free all the frames on the "free list" */
- frame = jb->free;
- while (frame != NULL) {
- jb_frame *next = frame->next;
- free(frame);
- frame = next;
- }
-
- /* free ourselves! */
- free(jb);
-}
-
-
-
-#if 0
-static int longcmp(const void *a, const void *b)
-{
- return *(long *)a - *(long *)b;
-}
-#endif
-
-/*! \brief simple history manipulation
- \note maybe later we can make the history buckets variable size, or something? */
-/* drop parameter determines whether we will drop outliers to minimize
- * delay */
-static int history_put(jitterbuf *jb, long ts, long now, long ms)
-{
- long delay = now - (ts - jb->info.resync_offset);
- long threshold = 2 * jb->info.jitter + jb->info.conf.resync_threshold;
- long kicked;
-
- /* don't add special/negative times to history */
- if (ts <= 0)
- return 0;
-
- /* check for drastic change in delay */
- if (jb->info.conf.resync_threshold != -1) {
- if (abs(delay - jb->info.last_delay) > threshold) {
- jb->info.cnt_delay_discont++;
- if (jb->info.cnt_delay_discont > 3) {
- /* resync the jitterbuffer */
- jb->info.cnt_delay_discont = 0;
- jb->hist_ptr = 0;
- jb->hist_maxbuf_valid = 0;
-
- jb_warn("Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->info.last_delay, delay, threshold, ts - now);
- jb->info.resync_offset = ts - now;
- jb->info.last_delay = delay = 0; /* after resync, frame is right on time */
- } else {
- return -1;
- }
- } else {
- jb->info.last_delay = delay;
- jb->info.cnt_delay_discont = 0;
- }
- }
-
- kicked = jb->history[jb->hist_ptr % JB_HISTORY_SZ];
-
- jb->history[(jb->hist_ptr++) % JB_HISTORY_SZ] = delay;
-
- /* optimization; the max/min buffers don't need to be recalculated, if this packet's
- * entry doesn't change them. This happens if this packet is not involved, _and_ any packet
- * that got kicked out of the history is also not involved
- * We do a number of comparisons, but it's probably still worthwhile, because it will usually
- * succeed, and should be a lot faster than going through all 500 packets in history */
- if (!jb->hist_maxbuf_valid)
- return 0;
-
- /* don't do this until we've filled history
- * (reduces some edge cases below) */
- if (jb->hist_ptr < JB_HISTORY_SZ)
- goto invalidate;
-
- /* if the new delay would go into min */
- if (delay < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
- goto invalidate;
-
- /* or max.. */
- if (delay > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
- goto invalidate;
-
- /* or the kicked delay would be in min */
- if (kicked <= jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
- goto invalidate;
-
- if (kicked >= jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
- goto invalidate;
-
- /* if we got here, we don't need to invalidate, 'cause this delay didn't
- * affect things */
- return 0;
- /* end optimization */
-
-
-invalidate:
- jb->hist_maxbuf_valid = 0;
- return 0;
-}
-
-static void history_calc_maxbuf(jitterbuf *jb)
-{
- int i,j;
-
- if (jb->hist_ptr == 0)
- return;
-
-
- /* initialize maxbuf/minbuf to the latest value */
- for (i=0;i<JB_HISTORY_MAXBUF_SZ;i++) {
-/*
- * jb->hist_maxbuf[i] = jb->history[(jb->hist_ptr-1) % JB_HISTORY_SZ];
- * jb->hist_minbuf[i] = jb->history[(jb->hist_ptr-1) % JB_HISTORY_SZ];
- */
- jb->hist_maxbuf[i] = JB_LONGMIN;
- jb->hist_minbuf[i] = JB_LONGMAX;
- }
-
- /* use insertion sort to populate maxbuf */
- /* we want it to be the top "n" values, in order */
-
- /* start at the beginning, or JB_HISTORY_SZ frames ago */
- i = (jb->hist_ptr > JB_HISTORY_SZ) ? (jb->hist_ptr - JB_HISTORY_SZ) : 0;
-
- for (;i<jb->hist_ptr;i++) {
- long toins = jb->history[i % JB_HISTORY_SZ];
-
- /* if the maxbuf should get this */
- if (toins > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1]) {
-
- /* insertion-sort it into the maxbuf */
- for (j=0;j<JB_HISTORY_MAXBUF_SZ;j++) {
- /* found where it fits */
- if (toins > jb->hist_maxbuf[j]) {
- /* move over */
- memmove(jb->hist_maxbuf+j+1,jb->hist_maxbuf+j, (JB_HISTORY_MAXBUF_SZ-(j+1)) * sizeof(long));
- /* insert */
- jb->hist_maxbuf[j] = toins;
-
- break;
- }
- }
- }
-
- /* if the minbuf should get this */
- if (toins < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1]) {
-
- /* insertion-sort it into the maxbuf */
- for (j=0;j<JB_HISTORY_MAXBUF_SZ;j++) {
- /* found where it fits */
- if (toins < jb->hist_minbuf[j]) {
- /* move over */
- memmove(jb->hist_minbuf+j+1,jb->hist_minbuf+j, (JB_HISTORY_MAXBUF_SZ-(j+1)) * sizeof(long));
- /* insert */
- jb->hist_minbuf[j] = toins;
-
- break;
- }
- }
- }
-
- if (0) {
- int k;
- fprintf(stderr, "toins = %ld\n", toins);
- fprintf(stderr, "maxbuf =");
- for (k=0;k<JB_HISTORY_MAXBUF_SZ;k++)
- fprintf(stderr, "%ld ", jb->hist_maxbuf[k]);
- fprintf(stderr, "\nminbuf =");
- for (k=0;k<JB_HISTORY_MAXBUF_SZ;k++)
- fprintf(stderr, "%ld ", jb->hist_minbuf[k]);
- fprintf(stderr, "\n");
- }
- }
-
- jb->hist_maxbuf_valid = 1;
-}
-
-static void history_get(jitterbuf *jb)
-{
- long max, min, jitter;
- int index;
- int count;
-
- if (!jb->hist_maxbuf_valid)
- history_calc_maxbuf(jb);
-
- /* count is how many items in history we're examining */
- count = (jb->hist_ptr < JB_HISTORY_SZ) ? jb->hist_ptr : JB_HISTORY_SZ;
-
- /* index is the "n"ths highest/lowest that we'll look for */
- index = count * JB_HISTORY_DROPPCT / 100;
-
- /* sanity checks for index */
- if (index > (JB_HISTORY_MAXBUF_SZ - 1))
- index = JB_HISTORY_MAXBUF_SZ - 1;
-
-
- if (index < 0) {
- jb->info.min = 0;
- jb->info.jitter = 0;
- return;
- }
-
- max = jb->hist_maxbuf[index];
- min = jb->hist_minbuf[index];
-
- jitter = max - min;
-
- /* these debug stmts compare the difference between looking at the absolute jitter, and the
- * values we get by throwing away the outliers */
- /*
- fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", index, min, max, jitter);
- fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", 0, jb->hist_minbuf[0], jb->hist_maxbuf[0], jb->hist_maxbuf[0]-jb->hist_minbuf[0]);
- */
-
- jb->info.min = min;
- jb->info.jitter = jitter;
-}
-
-/* returns 1 if frame was inserted into head of queue, 0 otherwise */
-static int queue_put(jitterbuf *jb, void *data, int type, long ms, long ts)
-{
- jb_frame *frame;
- jb_frame *p;
- int head = 0;
- long resync_ts = ts - jb->info.resync_offset;
-
- frame = jb->free;
- if (frame) {
- jb->free = frame->next;
- } else {
- frame = malloc(sizeof(jb_frame));
- }
-
- if (!frame) {
- jb_err("cannot allocate frame\n");
- return 0;
- }
-
- jb->info.frames_cur++;
-
- frame->data = data;
- frame->ts = resync_ts;
- frame->ms = ms;
- frame->type = type;
-
- /*
- * frames are a circular list, jb-frames points to to the lowest ts,
- * jb->frames->prev points to the highest ts
- */
-
- if (!jb->frames) { /* queue is empty */
- jb->frames = frame;
- frame->next = frame;
- frame->prev = frame;
- head = 1;
- } else if (resync_ts < jb->frames->ts) {
- frame->next = jb->frames;
- frame->prev = jb->frames->prev;
-
- frame->next->prev = frame;
- frame->prev->next = frame;
-
- /* frame is out of order */
- jb->info.frames_ooo++;
-
- jb->frames = frame;
- head = 1;
- } else {
- p = jb->frames;
-
- /* frame is out of order */
- if (resync_ts < p->prev->ts) jb->info.frames_ooo++;
-
- while (resync_ts < p->prev->ts && p->prev != jb->frames)
- p = p->prev;
-
- frame->next = p;
- frame->prev = p->prev;
-
- frame->next->prev = frame;
- frame->prev->next = frame;
- }
- return head;
-}
-
-static long queue_next(jitterbuf *jb)
-{
- if (jb->frames)
- return jb->frames->ts;
- else
- return -1;
-}
-
-static long queue_last(jitterbuf *jb)
-{
- if (jb->frames)
- return jb->frames->prev->ts;
- else
- return -1;
-}
-
-static jb_frame *_queue_get(jitterbuf *jb, long ts, int all)
-{
- jb_frame *frame;
- frame = jb->frames;
-
- if (!frame)
- return NULL;
-
- /*jb_warn("queue_get: ASK %ld FIRST %ld\n", ts, frame->ts); */
-
- if (all || ts >= frame->ts) {
- /* remove this frame */
- frame->prev->next = frame->next;
- frame->next->prev = frame->prev;
-
- if (frame->next == frame)
- jb->frames = NULL;
- else
- jb->frames = frame->next;
-
-
- /* insert onto "free" single-linked list */
- frame->next = jb->free;
- jb->free = frame;
-
- jb->info.frames_cur--;
-
- /* we return the frame pointer, even though it's on free list,
- * but caller must copy data */
- return frame;
- }
-
- return NULL;
-}
-
-static jb_frame *queue_get(jitterbuf *jb, long ts)
-{
- return _queue_get(jb,ts,0);
-}
-
-static jb_frame *queue_getall(jitterbuf *jb)
-{
- return _queue_get(jb,0,1);
-}
-
-#if 0
-/* some diagnostics */
-static void jb_dbginfo(jitterbuf *jb)
-{
- if (dbgf == NULL)
- return;
-
- jb_dbg("\njb info: fin=%ld fout=%ld flate=%ld flost=%ld fdrop=%ld fcur=%ld\n",
- jb->info.frames_in, jb->info.frames_out, jb->info.frames_late, jb->info.frames_lost, jb->info.frames_dropped, jb->info.frames_cur);
-
- jb_dbg("jitter=%ld current=%ld target=%ld min=%ld sil=%d len=%d len/fcur=%ld\n",
- jb->info.jitter, jb->info.current, jb->info.target, jb->info.min, jb->info.silence_begin_ts, jb->info.current - jb->info.min,
- jb->info.frames_cur ? (jb->info.current - jb->info.min)/jb->info.frames_cur : -8);
- if (jb->info.frames_in > 0)
- jb_dbg("jb info: Loss PCT = %ld%%, Late PCT = %ld%%\n",
- jb->info.frames_lost * 100/(jb->info.frames_in + jb->info.frames_lost),
- jb->info.frames_late * 100/jb->info.frames_in);
- jb_dbg("jb info: queue %d -> %d. last_ts %d (queue len: %d) last_ms %d\n",
- queue_next(jb),
- queue_last(jb),
- jb->info.next_voice_ts,
- queue_last(jb) - queue_next(jb),
- jb->info.last_voice_ms);
-}
-#endif
-
-#ifdef DEEP_DEBUG
-static void jb_chkqueue(jitterbuf *jb)
-{
- int i=0;
- jb_frame *p = jb->frames;
-
- if (!p) {
- return;
- }
-
- do {
- if (p->next == NULL) {
- jb_err("Queue is BROKEN at item [%d]", i);
- }
- i++;
- p=p->next;
- } while (p->next != jb->frames);
-}
-
-static void jb_dbgqueue(jitterbuf *jb)
-{
- int i=0;
- jb_frame *p = jb->frames;
-
- jb_dbg("queue: ");
-
- if (!p) {
- jb_dbg("EMPTY\n");
- return;
- }
-
- do {
- jb_dbg("[%d]=%ld ", i++, p->ts);
- p=p->next;
- } while (p->next != jb->frames);
-
- jb_dbg("\n");
-}
-#endif
-
-int jb_put(jitterbuf *jb, void *data, int type, long ms, long ts, long now)
-{
- jb_dbg2("jb_put(%x,%x,%ld,%ld,%ld)\n", jb, data, ms, ts, now);
-
- jb->info.frames_in++;
-
- if (type == JB_TYPE_VOICE) {
- /* presently, I'm only adding VOICE frames to history and drift calculations; mostly because with the
- * IAX integrations, I'm sending retransmitted control frames with their awkward timestamps through */
- if (history_put(jb,ts,now,ms))
- return JB_DROP;
- }
-
- /* if put into head of queue, caller needs to reschedule */
- if (queue_put(jb,data,type,ms,ts)) {
- return JB_SCHED;
- }
- return JB_OK;
-}
-
-
-static int _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl)
-{
- jb_frame *frame;
- long diff;
- static int dbg_cnt = 0;
-
- /*if ((now - jb_next(jb)) > 2 * jb->info.last_voice_ms) jb_warn("SCHED: %ld", (now - jb_next(jb))); */
- /* get jitter info */
- history_get(jb);
-
- if (dbg_cnt && dbg_cnt % 50 == 0) {
- jb_dbg("\n");
- }
- dbg_cnt++;
-
- /* target */
- jb->info.target = jb->info.jitter + jb->info.min + JB_TARGET_EXTRA;
-
- /* if a hard clamp was requested, use it */
- if ((jb->info.conf.max_jitterbuf) && ((jb->info.target - jb->info.min) > jb->info.conf.max_jitterbuf)) {
- jb_dbg("clamping target from %d to %d\n", (jb->info.target - jb->info.min), jb->info.conf.max_jitterbuf);
- jb->info.target = jb->info.min + jb->info.conf.max_jitterbuf;
- }
-
- diff = jb->info.target - jb->info.current;
-
- /* jb_warn("diff = %d lms=%d last = %d now = %d\n", diff, */
- /* jb->info.last_voice_ms, jb->info.last_adjustment, now); */
-
- /* let's work on non-silent case first */
- if (!jb->info.silence_begin_ts) {
- /* we want to grow */
- if ((diff > 0) &&
- /* we haven't grown in the delay length */
- (((jb->info.last_adjustment + JB_ADJUST_DELAY) < now) ||
- /* we need to grow more than the "length" we have left */
- (diff > queue_last(jb) - queue_next(jb)) ) ) {
- /* grow by interp frame length */
- jb->info.current += interpl;
- jb->info.next_voice_ts += interpl;
- jb->info.last_voice_ms = interpl;
- jb->info.last_adjustment = now;
- jb->info.cnt_contig_interp++;
- if (jb->info.conf.max_contig_interp && jb->info.cnt_contig_interp >= jb->info.conf.max_contig_interp) {
- jb->info.silence_begin_ts = jb->info.next_voice_ts - jb->info.current;
- }
- jb_dbg("G");
- return JB_INTERP;
- }
-
- frame = queue_get(jb, jb->info.next_voice_ts - jb->info.current);
-
- /* not a voice frame; just return it. */
- if (frame && frame->type != JB_TYPE_VOICE) {
- if (frame->type == JB_TYPE_SILENCE) {
- jb->info.silence_begin_ts = frame->ts;
- jb->info.cnt_contig_interp = 0;
- }
-
- *frameout = *frame;
- jb->info.frames_out++;
- jb_dbg("o");
- return JB_OK;
- }
-
-
- /* voice frame is later than expected */
- if (frame && frame->ts + jb->info.current < jb->info.next_voice_ts) {
- if (frame->ts + jb->info.current > jb->info.next_voice_ts - jb->info.last_voice_ms) {
- /* either we interpolated past this frame in the last jb_get */
- /* or the frame is still in order, but came a little too quick */
- *frameout = *frame;
- /* reset expectation for next frame */
- jb->info.next_voice_ts = frame->ts + jb->info.current + frame->ms;
- jb->info.frames_out++;
- decrement_losspct(jb);
- jb->info.cnt_contig_interp = 0;
- jb_dbg("v");
- return JB_OK;
- } else {
- /* voice frame is late */
- *frameout = *frame;
- jb->info.frames_out++;
- decrement_losspct(jb);
- jb->info.frames_late++;
- jb->info.frames_lost--;
- jb_dbg("l");
- /*jb_warn("\nlate: wanted=%ld, this=%ld, next=%ld\n", jb->info.next_voice_ts - jb->info.current, frame->ts, queue_next(jb));
- jb_warninfo(jb); */
- return JB_DROP;
- }
- }
-
- /* keep track of frame sizes, to allow for variable sized-frames */
- if (frame && frame->ms > 0) {
- jb->info.last_voice_ms = frame->ms;
- }
-
- /* we want to shrink; shrink at 1 frame / 500ms */
- /* unless we don't have a frame, then shrink 1 frame */
- /* every 80ms (though perhaps we can shrink even faster */
- /* in this case) */
- if (diff < -JB_TARGET_EXTRA &&
- ((!frame && jb->info.last_adjustment + 80 < now) ||
- (jb->info.last_adjustment + 500 < now))) {
-
- jb->info.last_adjustment = now;
- jb->info.cnt_contig_interp = 0;
-
- if (frame) {
- *frameout = *frame;
- /* shrink by frame size we're throwing out */
- jb->info.current -= frame->ms;
- jb->info.frames_out++;
- decrement_losspct(jb);
- jb->info.frames_dropped++;
- jb_dbg("s");
- return JB_DROP;
- } else {
- /* shrink by last_voice_ms */
- jb->info.current -= jb->info.last_voice_ms;
- jb->info.frames_lost++;
- increment_losspct(jb);
- jb_dbg("S");
- return JB_NOFRAME;
- }
- }
-
- /* lost frame */
- if (!frame) {
- /* this is a bit of a hack for now, but if we're close to
- * target, and we find a missing frame, it makes sense to
- * grow, because the frame might just be a bit late;
- * otherwise, we presently get into a pattern where we return
- * INTERP for the lost frame, then it shows up next, and we
- * throw it away because it's late */
- /* I've recently only been able to replicate this using
- * iaxclient talking to app_echo on asterisk. In this case,
- * my outgoing packets go through asterisk's (old)
- * jitterbuffer, and then might get an unusual increasing delay
- * there if it decides to grow?? */
- /* Update: that might have been a different bug, that has been fixed..
- * But, this still seemed like a good idea, except that it ended up making a single actual
- * lost frame get interpolated two or more times, when there was "room" to grow, so it might
- * be a bit of a bad idea overall */
- /*if (diff > -1 * jb->info.last_voice_ms) {
- jb->info.current += jb->info.last_voice_ms;
- jb->info.last_adjustment = now;
- jb_warn("g");
- return JB_INTERP;
- } */
- jb->info.frames_lost++;
- increment_losspct(jb);
- jb->info.next_voice_ts += interpl;
- jb->info.last_voice_ms = interpl;
- jb->info.cnt_contig_interp++;
- if (jb->info.conf.max_contig_interp && jb->info.cnt_contig_interp >= jb->info.conf.max_contig_interp) {
- jb->info.silence_begin_ts = jb->info.next_voice_ts - jb->info.current;
- }
- jb_dbg("L");
- return JB_INTERP;
- }
-
- /* normal case; return the frame, increment stuff */
- *frameout = *frame;
- jb->info.next_voice_ts += frame->ms;
- jb->info.frames_out++;
- jb->info.cnt_contig_interp = 0;
- decrement_losspct(jb);
- jb_dbg("v");
- return JB_OK;
- } else {
- /* TODO: after we get the non-silent case down, we'll make the
- * silent case -- basically, we'll just grow and shrink faster
- * here, plus handle next_voice_ts a bit differently */
-
- /* to disable silent special case altogether, just uncomment this: */
- /* jb->info.silence_begin_ts = 0; */
-
- /* shrink interpl len every 10ms during silence */
- if (diff < -JB_TARGET_EXTRA &&
- jb->info.last_adjustment + 10 <= now) {
- jb->info.current -= interpl;
- jb->info.last_adjustment = now;
- }
-
- frame = queue_get(jb, now - jb->info.current);
- if (!frame) {
- return JB_NOFRAME;
- } else if (frame->type != JB_TYPE_VOICE) {
- /* normal case; in silent mode, got a non-voice frame */
- *frameout = *frame;
- jb->info.frames_out++;
- return JB_OK;
- }
- if (frame->ts < jb->info.silence_begin_ts) {
- /* voice frame is late */
- *frameout = *frame;
- jb->info.frames_out++;
- decrement_losspct(jb);
- jb->info.frames_late++;
- jb->info.frames_lost--;
- jb_dbg("l");
- /*jb_warn("\nlate: wanted=%ld, this=%ld, next=%ld\n", jb->info.next_voice_ts - jb->info.current, frame->ts, queue_next(jb));
- jb_warninfo(jb); */
- return JB_DROP;
- } else {
- /* voice frame */
- /* try setting current to target right away here */
- jb->info.current = jb->info.target;
- jb->info.silence_begin_ts = 0;
- jb->info.next_voice_ts = frame->ts + jb->info.current + frame->ms;
- jb->info.last_voice_ms = frame->ms;
- jb->info.frames_out++;
- decrement_losspct(jb);
- *frameout = *frame;
- jb_dbg("V");
- return JB_OK;
- }
- }
-}
-
-long jb_next(jitterbuf *jb)
-{
- if (jb->info.silence_begin_ts) {
- long next = queue_next(jb);
- if (next > 0) {
- history_get(jb);
- /* shrink during silence */
- if (jb->info.target - jb->info.current < -JB_TARGET_EXTRA)
- return jb->info.last_adjustment + 10;
- return next + jb->info.target;
- }
- else
- return JB_LONGMAX;
- } else {
- return jb->info.next_voice_ts;
- }
-}
-
-int jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl)
-{
- int ret = _jb_get(jb,frameout,now,interpl);
-#if 0
- static int lastts=0;
- int thists = ((ret == JB_OK) || (ret == JB_DROP)) ? frameout->ts : 0;
- jb_warn("jb_get(%x,%x,%ld) = %d (%d)\n", jb, frameout, now, ret, thists);
- if (thists && thists < lastts) jb_warn("XXXX timestamp roll-back!!!\n");
- lastts = thists;
-#endif
- if(ret == JB_INTERP)
- frameout->ms = jb->info.last_voice_ms;
-
- return ret;
-}
-
-int jb_getall(jitterbuf *jb, jb_frame *frameout)
-{
- jb_frame *frame;
- frame = queue_getall(jb);
-
- if (!frame) {
- return JB_NOFRAME;
- }
-
- *frameout = *frame;
- return JB_OK;
-}
-
-
-int jb_getinfo(jitterbuf *jb, jb_info *stats)
-{
-
- history_get(jb);
-
- *stats = jb->info;
-
- return JB_OK;
-}
-
-int jb_setconf(jitterbuf *jb, jb_conf *conf)
-{
- /* take selected settings from the struct */
-
- jb->info.conf.max_jitterbuf = conf->max_jitterbuf;
- jb->info.conf.resync_threshold = conf->resync_threshold;
- jb->info.conf.max_contig_interp = conf->max_contig_interp;
-
- return JB_OK;
-}
-
-
diff --git a/1.2-netsec/jitterbuf.h b/1.2-netsec/jitterbuf.h
deleted file mode 100644
index cd8be0d0d..000000000
--- a/1.2-netsec/jitterbuf.h
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * jitterbuf: an application-independent jitterbuffer
- *
- * Copyrights:
- * Copyright (C) 2004-2005, Horizon Wimba, Inc.
- *
- * Contributors:
- * Steve Kann <stevek@stevek.com>
- *
- * This program is free software, distributed under the terms of
- * the GNU Lesser (Library) General Public License
- *
- * Copyright on this file is disclaimed to Digium for inclusion in Asterisk
- */
-
-#ifndef _JITTERBUF_H_
-#define _JITTERBUF_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* configuration constants */
- /* Number of historical timestamps to use in calculating jitter and drift */
-#define JB_HISTORY_SZ 500
- /* what percentage of timestamps should we drop from the history when we examine it;
- * this might eventually be something made configurable */
-#define JB_HISTORY_DROPPCT 3
- /* the maximum droppct we can handle (say it was configurable). */
-#define JB_HISTORY_DROPPCT_MAX 4
- /* the size of the buffer we use to keep the top and botton timestamps for dropping */
-#define JB_HISTORY_MAXBUF_SZ JB_HISTORY_SZ * JB_HISTORY_DROPPCT_MAX / 100
- /* amount of additional jitterbuffer adjustment */
-#define JB_TARGET_EXTRA 40
- /* ms between growing and shrinking; may not be honored if jitterbuffer runs out of space */
-#define JB_ADJUST_DELAY 40
-
-
-/* return codes */
-#define JB_OK 0
-#define JB_EMPTY 1
-#define JB_NOFRAME 2
-#define JB_INTERP 3
-#define JB_DROP 4
-#define JB_SCHED 5
-
-/* frame types */
-#define JB_TYPE_CONTROL 0
-#define JB_TYPE_VOICE 1
-#define JB_TYPE_VIDEO 2 /* reserved */
-#define JB_TYPE_SILENCE 3
-
-
-typedef struct jb_conf {
- /* settings */
- long max_jitterbuf; /* defines a hard clamp to use in setting the jitter buffer delay */
- long resync_threshold; /* the jb will resync when delay increases to (2 * jitter) + this param */
- long max_contig_interp; /* the max interp frames to return in a row */
-} jb_conf;
-
-typedef struct jb_info {
- jb_conf conf;
-
- /* statistics */
- long frames_in; /* number of frames input to the jitterbuffer.*/
- long frames_out; /* number of frames output from the jitterbuffer.*/
- long frames_late; /* number of frames which were too late, and dropped.*/
- long frames_lost; /* number of missing frames.*/
- long frames_dropped; /* number of frames dropped (shrinkage) */
- long frames_ooo; /* number of frames received out-of-order */
- long frames_cur; /* number of frames presently in jb, awaiting delivery.*/
- long jitter; /* jitter measured within current history interval*/
- long min; /* minimum lateness within current history interval */
- long current; /* the present jitterbuffer adjustment */
- long target; /* the target jitterbuffer adjustment */
- long losspct; /* recent lost frame percentage (* 1000) */
- long next_voice_ts; /* the ts of the next frame to be read from the jb - in receiver's time */
- long last_voice_ms; /* the duration of the last voice frame */
- long silence_begin_ts; /* the time of the last CNG frame, when in silence */
- long last_adjustment; /* the time of the last adjustment */
- long last_delay; /* the last now added to history */
- long cnt_delay_discont; /* the count of discontinuous delays */
- long resync_offset; /* the amount to offset ts to support resyncs */
- long cnt_contig_interp; /* the number of contiguous interp frames returned */
-} jb_info;
-
-typedef struct jb_frame {
- void *data; /* the frame data */
- long ts; /* the relative delivery time expected */
- long ms; /* the time covered by this frame, in sec/8000 */
- int type; /* the type of frame */
- struct jb_frame *next, *prev;
-} jb_frame;
-
-typedef struct jitterbuf {
- jb_info info;
-
- /* history */
- long history[JB_HISTORY_SZ]; /* history */
- int hist_ptr; /* points to index in history for next entry */
- long hist_maxbuf[JB_HISTORY_MAXBUF_SZ]; /* a sorted buffer of the max delays (highest first) */
- long hist_minbuf[JB_HISTORY_MAXBUF_SZ]; /* a sorted buffer of the min delays (lowest first) */
- int hist_maxbuf_valid; /* are the "maxbuf"/minbuf valid? */
-
-
- jb_frame *frames; /* queued frames */
- jb_frame *free; /* free frames (avoid malloc?) */
-} jitterbuf;
-
-
-/* new jitterbuf */
-jitterbuf * jb_new(void);
-
-/* destroy jitterbuf */
-void jb_destroy(jitterbuf *jb);
-
-/* reset jitterbuf */
-/* NOTE: The jitterbuffer should be empty before you call this, otherwise
- * you will leak queued frames, and some internal structures */
-void jb_reset(jitterbuf *jb);
-
-/* queue a frame data=frame data, timings (in ms): ms=length of frame (for voice), ts=ts (sender's time)
- * now=now (in receiver's time) return value is one of
- * JB_OK: Frame added. Last call to jb_next() still valid
- * JB_DROP: Drop this frame immediately
- * JB_SCHED: Frame added. Call jb_next() to get a new time for the next frame
- */
-int jb_put(jitterbuf *jb, void *data, int type, long ms, long ts, long now);
-
-/* get a frame for time now (receiver's time) return value is one of
- * JB_OK: You've got frame!
- * JB_DROP: Here's an audio frame you should just drop. Ask me again for this time..
- * JB_NOFRAME: There's no frame scheduled for this time.
- * JB_INTERP: Please interpolate an interpl-length frame for this time (either we need to grow, or there was a lost frame)
- * JB_EMPTY: The jb is empty.
- */
-int jb_get(jitterbuf *jb, jb_frame *frame, long now, long interpl);
-
-/* unconditionally get frames from jitterbuf until empty */
-int jb_getall(jitterbuf *jb, jb_frame *frameout);
-
-/* when is the next frame due out, in receiver's time (0=EMPTY)
- * This value may change as frames are added (esp non-audio frames) */
-long jb_next(jitterbuf *jb);
-
-/* get jitterbuf info: only "statistics" may be valid */
-int jb_getinfo(jitterbuf *jb, jb_info *stats);
-
-/* set jitterbuf conf */
-int jb_setconf(jitterbuf *jb, jb_conf *conf);
-
-typedef void (*jb_output_function_t)(const char *fmt, ...);
-void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
diff --git a/1.2-netsec/keys/freeworlddialup.pub b/1.2-netsec/keys/freeworlddialup.pub
deleted file mode 100644
index 4ba3faf66..000000000
--- a/1.2-netsec/keys/freeworlddialup.pub
+++ /dev/null
@@ -1,6 +0,0 @@
------BEGIN PUBLIC KEY-----
-MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCcE53oHNoe3sBSkvW3JaO8v5Z1
-CC+Cm+JgocGwmUek0hlQST1NUsFWfYIMd5z/Iunnd1GziXLqDYzCQeZUtJ6Y9J4A
-cA9wNv1eYWrlH7ozKWOv592+Y5xF0kqQ1jFt+5zFTP5myL9N439Evu/BWALHw0B4
-aML+CsGHg0uIe5ZjNwIDAQAB
------END PUBLIC KEY-----
diff --git a/1.2-netsec/keys/iaxtel.pub b/1.2-netsec/keys/iaxtel.pub
deleted file mode 100644
index d7c8f6cc8..000000000
--- a/1.2-netsec/keys/iaxtel.pub
+++ /dev/null
@@ -1,6 +0,0 @@
------BEGIN PUBLIC KEY-----
-MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3+joshldCUFgjj5DeYOgRLSPS
-0t7gxTHiy1BTfynadPzgn447dy9iIQfBykE0pEdIPgaPMEt+ZPqPtln1P4dX3Ynx
-I+RYKgtjsmYYnyJRMGHfHuLXwkbFkxyiEg0KDvbdBWbz7GUNZlp49BLXewWGY9DJ
-MauE7FXVyCVDchn0YQIDAQAB
------END PUBLIC KEY-----
diff --git a/1.2-netsec/loader.c b/1.2-netsec/loader.c
deleted file mode 100644
index d9e0c88d0..000000000
--- a/1.2-netsec/loader.c
+++ /dev/null
@@ -1,646 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Module Loader
- *
- */
-
-#include <stdio.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/term.h"
-#include "asterisk/manager.h"
-#include "asterisk/cdr.h"
-#include "asterisk/enum.h"
-#include "asterisk/rtp.h"
-#include "asterisk/lock.h"
-#ifdef DLFCNCOMPAT
-#include "asterisk/dlfcn-compat.h"
-#else
-#include <dlfcn.h>
-#endif
-#include "asterisk/md5.h"
-
-#ifndef RTLD_NOW
-#define RTLD_NOW 0
-#endif
-
-AST_MUTEX_DEFINE_STATIC(modlock);
-AST_MUTEX_DEFINE_STATIC(reloadlock);
-
-static struct module *module_list=NULL;
-static int modlistver = 0;
-
-static unsigned char expected_key[] =
-{ 0x8e, 0x93, 0x22, 0x83, 0xf5, 0xc3, 0xc0, 0x75,
- 0xff, 0x8b, 0xa9, 0xbe, 0x7c, 0x43, 0x74, 0x63 };
-
-struct module {
- int (*load_module)(void);
- int (*unload_module)(void);
- int (*usecount)(void);
- char *(*description)(void);
- char *(*key)(void);
- int (*reload)(void);
- void *lib;
- char resource[256];
- struct module *next;
-};
-
-static struct loadupdate {
- int (*updater)(void);
- struct loadupdate *next;
-} *updaters = NULL;
-
-static int printdigest(unsigned char *d)
-{
- int x;
- char buf[256];
- char buf2[16];
- snprintf(buf, sizeof(buf), "Unexpected signature:");
- for (x=0; x<16; x++) {
- snprintf(buf2, sizeof(buf2), " %02x", *(d++));
- strcat(buf, buf2);
- }
- strcat(buf, "\n");
- ast_log(LOG_DEBUG, "%s", buf);
- return 0;
-}
-
-static int key_matches(unsigned char *key1, unsigned char *key2)
-{
- int match = 1;
- int x;
- for (x=0; x<16; x++) {
- match &= (key1[x] == key2[x]);
- }
- return match;
-}
-
-static int verify_key(unsigned char *key)
-{
- struct MD5Context c;
- unsigned char digest[16];
- MD5Init(&c);
- MD5Update(&c, key, strlen((char *)key));
- MD5Final(digest, &c);
- if (key_matches(expected_key, digest))
- return 0;
- printdigest(digest);
- return -1;
-}
-
-int ast_unload_resource(const char *resource_name, int force)
-{
- struct module *m, *ml = NULL;
- int res = -1;
- if (ast_mutex_lock(&modlock))
- ast_log(LOG_WARNING, "Failed to lock\n");
- m = module_list;
- while(m) {
- if (!strcasecmp(m->resource, resource_name)) {
- if ((res = m->usecount()) > 0) {
- if (force)
- ast_log(LOG_WARNING, "Warning: Forcing removal of module %s with use count %d\n", resource_name, res);
- else {
- ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name, res);
- ast_mutex_unlock(&modlock);
- return -1;
- }
- }
- res = m->unload_module();
- if (res) {
- ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name);
- if (force <= AST_FORCE_FIRM) {
- ast_mutex_unlock(&modlock);
- return -1;
- } else
- ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n");
- }
- if (ml)
- ml->next = m->next;
- else
- module_list = m->next;
- dlclose(m->lib);
- free(m);
- break;
- }
- ml = m;
- m = m->next;
- }
- modlistver = rand();
- ast_mutex_unlock(&modlock);
- ast_update_use_count();
- return res;
-}
-
-char *ast_module_helper(char *line, char *word, int pos, int state, int rpos, int needsreload)
-{
- struct module *m;
- int which=0;
- char *ret;
-
- if (pos != rpos)
- return NULL;
- ast_mutex_lock(&modlock);
- m = module_list;
- while(m) {
- if (!strncasecmp(word, m->resource, strlen(word)) && (m->reload || !needsreload)) {
- if (++which > state)
- break;
- }
- m = m->next;
- }
- if (m) {
- ret = strdup(m->resource);
- } else {
- ret = NULL;
- if (!strncasecmp(word, "extconfig", strlen(word))) {
- if (++which > state)
- ret = strdup("extconfig");
- } else if (!strncasecmp(word, "manager", strlen(word))) {
- if (++which > state)
- ret = strdup("manager");
- } else if (!strncasecmp(word, "enum", strlen(word))) {
- if (++which > state)
- ret = strdup("enum");
- } else if (!strncasecmp(word, "rtp", strlen(word))) {
- if (++which > state)
- ret = strdup("rtp");
- }
-
- }
- ast_mutex_unlock(&modlock);
- return ret;
-}
-
-int ast_module_reload(const char *name)
-{
- struct module *m;
- int reloaded = 0;
- int oldversion;
- int (*reload)(void);
- /* We'll do the logger and manager the favor of calling its reload here first */
-
- if (ast_mutex_trylock(&reloadlock)) {
- ast_verbose("The previous reload command didn't finish yet\n");
- return -1;
- }
- if (!name || !strcasecmp(name, "extconfig")) {
- read_config_maps();
- reloaded = 2;
- }
- if (!name || !strcasecmp(name, "manager")) {
- reload_manager();
- reloaded = 2;
- }
- if (!name || !strcasecmp(name, "cdr")) {
- ast_cdr_engine_reload();
- reloaded = 2;
- }
- if (!name || !strcasecmp(name, "enum")) {
- ast_enum_reload();
- reloaded = 2;
- }
- if (!name || !strcasecmp(name, "rtp")) {
- ast_rtp_reload();
- reloaded = 2;
- }
- if (!name || !strcasecmp(name, "dnsmgr")) {
- dnsmgr_reload();
- reloaded = 2;
- }
- time(&ast_lastreloadtime);
-
- ast_mutex_lock(&modlock);
- oldversion = modlistver;
- m = module_list;
- while(m) {
- if (!name || !strcasecmp(name, m->resource)) {
- if (reloaded < 1)
- reloaded = 1;
- reload = m->reload;
- ast_mutex_unlock(&modlock);
- if (reload) {
- reloaded = 2;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Reloading module '%s' (%s)\n", m->resource, m->description());
- reload();
- }
- ast_mutex_lock(&modlock);
- if (oldversion != modlistver)
- break;
- }
- m = m->next;
- }
- ast_mutex_unlock(&modlock);
- ast_mutex_unlock(&reloadlock);
- return reloaded;
-}
-
-static int __load_resource(const char *resource_name, const struct ast_config *cfg)
-{
- static char fn[256];
- int errors=0;
- int res;
- struct module *m;
- int flags=RTLD_NOW;
-#ifdef RTLD_GLOBAL
- char *val;
-#endif
- unsigned char *key;
- char tmp[80];
-
- if (strncasecmp(resource_name, "res_", 4)) {
-#ifdef RTLD_GLOBAL
- if (cfg) {
- if ((val = ast_variable_retrieve(cfg, "global", resource_name))
- && ast_true(val))
- flags |= RTLD_GLOBAL;
- }
-#endif
- } else {
- /* Resource modules are always loaded global and lazy */
-#ifdef RTLD_GLOBAL
- flags = (RTLD_GLOBAL | RTLD_LAZY);
-#else
- flags = RTLD_LAZY;
-#endif
- }
-
- if (ast_mutex_lock(&modlock))
- ast_log(LOG_WARNING, "Failed to lock\n");
- m = module_list;
- while(m) {
- if (!strcasecmp(m->resource, resource_name)) {
- ast_log(LOG_WARNING, "Module '%s' already exists\n", resource_name);
- ast_mutex_unlock(&modlock);
- return -1;
- }
- m = m->next;
- }
- m = malloc(sizeof(struct module));
- if (!m) {
- ast_log(LOG_WARNING, "Out of memory\n");
- ast_mutex_unlock(&modlock);
- return -1;
- }
- strncpy(m->resource, resource_name, sizeof(m->resource)-1);
- if (resource_name[0] == '/') {
- strncpy(fn, resource_name, sizeof(fn)-1);
- } else {
- snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_MODULE_DIR, resource_name);
- }
- m->lib = dlopen(fn, flags);
- if (!m->lib) {
- ast_log(LOG_WARNING, "%s\n", dlerror());
- free(m);
- ast_mutex_unlock(&modlock);
- return -1;
- }
- m->load_module = dlsym(m->lib, "load_module");
- if (m->load_module == NULL)
- m->load_module = dlsym(m->lib, "_load_module");
- if (!m->load_module) {
- ast_log(LOG_WARNING, "No load_module in module %s\n", fn);
- errors++;
- }
- m->unload_module = dlsym(m->lib, "unload_module");
- if (m->unload_module == NULL)
- m->unload_module = dlsym(m->lib, "_unload_module");
- if (!m->unload_module) {
- ast_log(LOG_WARNING, "No unload_module in module %s\n", fn);
- errors++;
- }
- m->usecount = dlsym(m->lib, "usecount");
- if (m->usecount == NULL)
- m->usecount = dlsym(m->lib, "_usecount");
- if (!m->usecount) {
- ast_log(LOG_WARNING, "No usecount in module %s\n", fn);
- errors++;
- }
- m->description = dlsym(m->lib, "description");
- if (m->description == NULL)
- m->description = dlsym(m->lib, "_description");
- if (!m->description) {
- ast_log(LOG_WARNING, "No description in module %s\n", fn);
- errors++;
- }
- m->key = dlsym(m->lib, "key");
- if (m->key == NULL)
- m->key = dlsym(m->lib, "_key");
- if (!m->key) {
- ast_log(LOG_WARNING, "No key routine in module %s\n", fn);
- errors++;
- }
-
- m->reload = dlsym(m->lib, "reload");
- if (m->reload == NULL)
- m->reload = dlsym(m->lib, "_reload");
-
- if (!m->key || !(key = (unsigned char *) m->key())) {
- ast_log(LOG_WARNING, "Key routine returned NULL in module %s\n", fn);
- key = NULL;
- errors++;
- }
- if (key && verify_key(key)) {
- ast_log(LOG_WARNING, "Unexpected key returned by module %s\n", fn);
- errors++;
- }
- if (errors) {
- ast_log(LOG_WARNING, "%d error%s loading module %s, aborted\n", errors, (errors != 1) ? "s" : "", fn);
- dlclose(m->lib);
- free(m);
- ast_mutex_unlock(&modlock);
- return -1;
- }
- if (!fully_booted) {
- if (option_verbose)
- ast_verbose( " => (%s)\n", term_color(tmp, m->description(), COLOR_BROWN, COLOR_BLACK, sizeof(tmp)));
- if (option_console && !option_verbose)
- ast_verbose( ".");
- } else {
- if (option_verbose)
- ast_verbose(VERBOSE_PREFIX_1 "Loaded %s => (%s)\n", fn, m->description());
- }
-
- /* add module 'm' to end of module_list chain
- so reload commands will be issued in same order modules were loaded */
- m->next = NULL;
- if (module_list == NULL) {
- /* empty list so far, add at front */
- module_list = m;
- }
- else {
- struct module *i;
- /* find end of chain, and add there */
- for (i = module_list; i->next; i = i->next)
- ;
- i->next = m;
- }
-
- modlistver = rand();
- ast_mutex_unlock(&modlock);
- if ((res = m->load_module())) {
- ast_log(LOG_WARNING, "%s: load_module failed, returning %d\n", m->resource, res);
- ast_unload_resource(resource_name, 0);
- return -1;
- }
- ast_update_use_count();
- return 0;
-}
-
-int ast_load_resource(const char *resource_name)
-{
- int o;
- struct ast_config *cfg = NULL;
- int res;
-
- /* Keep the module file parsing silent */
- o = option_verbose;
- option_verbose = 0;
- cfg = ast_config_load(AST_MODULE_CONFIG);
- option_verbose = o;
- res = __load_resource(resource_name, cfg);
- if (cfg)
- ast_config_destroy(cfg);
- return res;
-}
-
-static int ast_resource_exists(char *resource)
-{
- struct module *m;
- if (ast_mutex_lock(&modlock))
- ast_log(LOG_WARNING, "Failed to lock\n");
- m = module_list;
- while(m) {
- if (!strcasecmp(resource, m->resource))
- break;
- m = m->next;
- }
- ast_mutex_unlock(&modlock);
- if (m)
- return -1;
- else
- return 0;
-}
-
-static const char *loadorder[] =
-{
- "res_",
- "pbx_",
- "chan_",
- NULL,
-};
-
-int load_modules(const int preload_only)
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- char tmp[80];
-
- if (option_verbose) {
- if (preload_only)
- ast_verbose("Asterisk Dynamic Loader loading preload modules:\n");
- else
- ast_verbose("Asterisk Dynamic Loader Starting:\n");
- }
-
- cfg = ast_config_load(AST_MODULE_CONFIG);
- if (cfg) {
- int doload;
-
- /* Load explicitly defined modules */
- for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
- doload = 0;
-
- if (preload_only)
- doload = !strcasecmp(v->name, "preload");
- else
- doload = !strcasecmp(v->name, "load");
-
- if (doload) {
- if (option_debug && !option_verbose)
- ast_log(LOG_DEBUG, "Loading module %s\n", v->value);
- if (option_verbose) {
- ast_verbose(VERBOSE_PREFIX_1 "[%s]", term_color(tmp, v->value, COLOR_BRWHITE, 0, sizeof(tmp)));
- fflush(stdout);
- }
- if (__load_resource(v->value, cfg)) {
- ast_log(LOG_WARNING, "Loading module %s failed!\n", v->value);
- ast_config_destroy(cfg);
- return -1;
- }
- }
- }
- }
-
- if (preload_only) {
- ast_config_destroy(cfg);
- return 0;
- }
-
- if (!cfg || ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) {
- /* Load all modules */
- DIR *mods;
- struct dirent *d;
- int x;
-
- /* Loop through each order */
- for (x=0; x<sizeof(loadorder) / sizeof(loadorder[0]); x++) {
- mods = opendir((char *)ast_config_AST_MODULE_DIR);
- if (mods) {
- while((d = readdir(mods))) {
- /* Must end in .so to load it. */
- if ((strlen(d->d_name) > 3) &&
- (!loadorder[x] || !strncasecmp(d->d_name, loadorder[x], strlen(loadorder[x]))) &&
- !strcasecmp(d->d_name + strlen(d->d_name) - 3, ".so") &&
- !ast_resource_exists(d->d_name)) {
- /* It's a shared library -- Just be sure we're allowed to load it -- kinda
- an inefficient way to do it, but oh well. */
- if (cfg) {
- v = ast_variable_browse(cfg, "modules");
- while(v) {
- if (!strcasecmp(v->name, "noload") &&
- !strcasecmp(v->value, d->d_name))
- break;
- v = v->next;
- }
- if (v) {
- if (option_verbose) {
- ast_verbose( VERBOSE_PREFIX_1 "[skipping %s]\n", d->d_name);
- fflush(stdout);
- }
- continue;
- }
-
- }
- if (option_debug && !option_verbose)
- ast_log(LOG_DEBUG, "Loading module %s\n", d->d_name);
- if (option_verbose) {
- ast_verbose( VERBOSE_PREFIX_1 "[%s]", term_color(tmp, d->d_name, COLOR_BRWHITE, 0, sizeof(tmp)));
- fflush(stdout);
- }
- if (__load_resource(d->d_name, cfg)) {
- ast_log(LOG_WARNING, "Loading module %s failed!\n", d->d_name);
- if (cfg)
- ast_config_destroy(cfg);
- return -1;
- }
- }
- }
- closedir(mods);
- } else {
- if (!option_quiet)
- ast_log(LOG_WARNING, "Unable to open modules directory %s.\n", (char *)ast_config_AST_MODULE_DIR);
- }
- }
- }
- ast_config_destroy(cfg);
- return 0;
-}
-
-void ast_update_use_count(void)
-{
- /* Notify any module monitors that the use count for a
- resource has changed */
- struct loadupdate *m;
- if (ast_mutex_lock(&modlock))
- ast_log(LOG_WARNING, "Failed to lock\n");
- m = updaters;
- while(m) {
- m->updater();
- m = m->next;
- }
- ast_mutex_unlock(&modlock);
-
-}
-
-int ast_update_module_list(int (*modentry)(const char *module, const char *description, int usecnt, const char *like),
- const char *like)
-{
- struct module *m;
- int unlock = -1;
- int total_mod_loaded = 0;
-
- if (ast_mutex_trylock(&modlock))
- unlock = 0;
- m = module_list;
- while (m) {
- total_mod_loaded += modentry(m->resource, m->description(), m->usecount(), like);
- m = m->next;
- }
- if (unlock)
- ast_mutex_unlock(&modlock);
-
- return total_mod_loaded;
-}
-
-int ast_loader_register(int (*v)(void))
-{
- struct loadupdate *tmp;
- /* XXX Should be more flexible here, taking > 1 verboser XXX */
- if ((tmp = malloc(sizeof (struct loadupdate)))) {
- tmp->updater = v;
- if (ast_mutex_lock(&modlock))
- ast_log(LOG_WARNING, "Failed to lock\n");
- tmp->next = updaters;
- updaters = tmp;
- ast_mutex_unlock(&modlock);
- return 0;
- }
- return -1;
-}
-
-int ast_loader_unregister(int (*v)(void))
-{
- int res = -1;
- struct loadupdate *tmp, *tmpl=NULL;
- if (ast_mutex_lock(&modlock))
- ast_log(LOG_WARNING, "Failed to lock\n");
- tmp = updaters;
- while(tmp) {
- if (tmp->updater == v) {
- if (tmpl)
- tmpl->next = tmp->next;
- else
- updaters = tmp->next;
- break;
- }
- tmpl = tmp;
- tmp = tmp->next;
- }
- if (tmp)
- res = 0;
- ast_mutex_unlock(&modlock);
- return res;
-}
diff --git a/1.2-netsec/logger.c b/1.2-netsec/logger.c
deleted file mode 100644
index 0a397ff46..000000000
--- a/1.2-netsec/logger.c
+++ /dev/null
@@ -1,968 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Asterisk Logger
- *
- * Logging routines
- *
- */
-
-#include <signal.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <time.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/stat.h>
-
-#define SYSLOG_NAMES /* so we can map syslog facilities names to their numeric values,
- from <syslog.h> which is included by logger.h */
-#include <syslog.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-static int syslog_level_map[] = {
- LOG_DEBUG,
- LOG_INFO, /* arbitrary equivalent of LOG_EVENT */
- LOG_NOTICE,
- LOG_WARNING,
- LOG_ERR,
- LOG_DEBUG,
- LOG_DEBUG
-};
-
-#define SYSLOG_NLEVELS sizeof(syslog_level_map) / sizeof(int)
-
-#include "asterisk/logger.h"
-#include "asterisk/lock.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/term.h"
-#include "asterisk/cli.h"
-#include "asterisk/utils.h"
-#include "asterisk/manager.h"
-
-#define MAX_MSG_QUEUE 200
-
-#if defined(__linux__) && !defined(__NR_gettid)
-#include <asm/unistd.h>
-#endif
-
-#if defined(__linux__) && defined(__NR_gettid)
-#define GETTID() syscall(__NR_gettid)
-#else
-#define GETTID() getpid()
-#endif
-
-
-static char dateformat[256] = "%b %e %T"; /* Original Asterisk Format */
-
-AST_MUTEX_DEFINE_STATIC(msglist_lock);
-AST_MUTEX_DEFINE_STATIC(loglock);
-static int filesize_reload_needed = 0;
-static int global_logmask = -1;
-
-static struct {
- unsigned int queue_log:1;
- unsigned int event_log:1;
-} logfiles = { 1, 1 };
-
-static struct msglist {
- char *msg;
- struct msglist *next;
-} *list = NULL, *last = NULL;
-
-static char hostname[MAXHOSTNAMELEN];
-
-enum logtypes {
- LOGTYPE_SYSLOG,
- LOGTYPE_FILE,
- LOGTYPE_CONSOLE,
-};
-
-struct logchannel {
- int logmask; /* What to log to this channel */
- int disabled; /* If this channel is disabled or not */
- int facility; /* syslog facility */
- enum logtypes type; /* Type of log channel */
- FILE *fileptr; /* logfile logging file pointer */
- char filename[256]; /* Filename */
- struct logchannel *next; /* Next channel in chain */
-};
-
-static struct logchannel *logchannels = NULL;
-
-static int msgcnt = 0;
-
-static FILE *eventlog = NULL;
-static FILE *qlog = NULL;
-
-static char *levels[] = {
- "DEBUG",
- "EVENT",
- "NOTICE",
- "WARNING",
- "ERROR",
- "VERBOSE",
- "DTMF"
-};
-
-static int colors[] = {
- COLOR_BRGREEN,
- COLOR_BRBLUE,
- COLOR_YELLOW,
- COLOR_BRRED,
- COLOR_RED,
- COLOR_GREEN,
- COLOR_BRGREEN
-};
-
-static int make_components(char *s, int lineno)
-{
- char *w;
- int res = 0;
- char *stringp=NULL;
- stringp=s;
- w = strsep(&stringp, ",");
- while(w) {
- while(*w && (*w < 33))
- w++;
- if (!strcasecmp(w, "error"))
- res |= (1 << __LOG_ERROR);
- else if (!strcasecmp(w, "warning"))
- res |= (1 << __LOG_WARNING);
- else if (!strcasecmp(w, "notice"))
- res |= (1 << __LOG_NOTICE);
- else if (!strcasecmp(w, "event"))
- res |= (1 << __LOG_EVENT);
- else if (!strcasecmp(w, "debug"))
- res |= (1 << __LOG_DEBUG);
- else if (!strcasecmp(w, "verbose"))
- res |= (1 << __LOG_VERBOSE);
- else if (!strcasecmp(w, "dtmf"))
- res |= (1 << __LOG_DTMF);
- else {
- fprintf(stderr, "Logfile Warning: Unknown keyword '%s' at line %d of logger.conf\n", w, lineno);
- }
- w = strsep(&stringp, ",");
- }
- return res;
-}
-
-static struct logchannel *make_logchannel(char *channel, char *components, int lineno)
-{
- struct logchannel *chan;
- char *facility;
-#ifndef SOLARIS
- CODE *cptr;
-#endif
-
- if (ast_strlen_zero(channel))
- return NULL;
- chan = malloc(sizeof(struct logchannel));
-
- if (!chan) /* Can't allocate memory */
- return NULL;
-
- memset(chan, 0, sizeof(struct logchannel));
- if (!strcasecmp(channel, "console")) {
- chan->type = LOGTYPE_CONSOLE;
- } else if (!strncasecmp(channel, "syslog", 6)) {
- /*
- * syntax is:
- * syslog.facility => level,level,level
- */
- facility = strchr(channel, '.');
- if(!facility++ || !facility) {
- facility = "local0";
- }
-
-#ifndef SOLARIS
- /*
- * Walk through the list of facilitynames (defined in sys/syslog.h)
- * to see if we can find the one we have been given
- */
- chan->facility = -1;
- cptr = facilitynames;
- while (cptr->c_name) {
- if (!strcasecmp(facility, cptr->c_name)) {
- chan->facility = cptr->c_val;
- break;
- }
- cptr++;
- }
-#else
- chan->facility = -1;
- if (!strcasecmp(facility, "kern"))
- chan->facility = LOG_KERN;
- else if (!strcasecmp(facility, "USER"))
- chan->facility = LOG_USER;
- else if (!strcasecmp(facility, "MAIL"))
- chan->facility = LOG_MAIL;
- else if (!strcasecmp(facility, "DAEMON"))
- chan->facility = LOG_DAEMON;
- else if (!strcasecmp(facility, "AUTH"))
- chan->facility = LOG_AUTH;
- else if (!strcasecmp(facility, "SYSLOG"))
- chan->facility = LOG_SYSLOG;
- else if (!strcasecmp(facility, "LPR"))
- chan->facility = LOG_LPR;
- else if (!strcasecmp(facility, "NEWS"))
- chan->facility = LOG_NEWS;
- else if (!strcasecmp(facility, "UUCP"))
- chan->facility = LOG_UUCP;
- else if (!strcasecmp(facility, "CRON"))
- chan->facility = LOG_CRON;
- else if (!strcasecmp(facility, "LOCAL0"))
- chan->facility = LOG_LOCAL0;
- else if (!strcasecmp(facility, "LOCAL1"))
- chan->facility = LOG_LOCAL1;
- else if (!strcasecmp(facility, "LOCAL2"))
- chan->facility = LOG_LOCAL2;
- else if (!strcasecmp(facility, "LOCAL3"))
- chan->facility = LOG_LOCAL3;
- else if (!strcasecmp(facility, "LOCAL4"))
- chan->facility = LOG_LOCAL4;
- else if (!strcasecmp(facility, "LOCAL5"))
- chan->facility = LOG_LOCAL5;
- else if (!strcasecmp(facility, "LOCAL6"))
- chan->facility = LOG_LOCAL6;
- else if (!strcasecmp(facility, "LOCAL7"))
- chan->facility = LOG_LOCAL7;
-#endif /* Solaris */
-
- if (0 > chan->facility) {
- fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n");
- free(chan);
- return NULL;
- }
-
- chan->type = LOGTYPE_SYSLOG;
- snprintf(chan->filename, sizeof(chan->filename), "%s", channel);
- openlog("asterisk", LOG_PID, chan->facility);
- } else {
- if (channel[0] == '/') {
- if(!ast_strlen_zero(hostname)) {
- snprintf(chan->filename, sizeof(chan->filename) - 1,"%s.%s", channel, hostname);
- } else {
- ast_copy_string(chan->filename, channel, sizeof(chan->filename));
- }
- }
-
- if(!ast_strlen_zero(hostname)) {
- snprintf(chan->filename, sizeof(chan->filename), "%s/%s.%s",(char *)ast_config_AST_LOG_DIR, channel, hostname);
- } else {
- snprintf(chan->filename, sizeof(chan->filename), "%s/%s", (char *)ast_config_AST_LOG_DIR, channel);
- }
- chan->fileptr = fopen(chan->filename, "a");
- if (!chan->fileptr) {
- /* Can't log here, since we're called with a lock */
- fprintf(stderr, "Logger Warning: Unable to open log file '%s': %s\n", chan->filename, strerror(errno));
- }
- chan->type = LOGTYPE_FILE;
- }
- chan->logmask = make_components(components, lineno);
- return chan;
-}
-
-static void init_logger_chain(void)
-{
- struct logchannel *chan, *cur;
- struct ast_config *cfg;
- struct ast_variable *var;
- char *s;
-
- /* delete our list of log channels */
- ast_mutex_lock(&loglock);
- chan = logchannels;
- while (chan) {
- cur = chan->next;
- free(chan);
- chan = cur;
- }
- logchannels = NULL;
- ast_mutex_unlock(&loglock);
-
- global_logmask = 0;
- /* close syslog */
- closelog();
-
- cfg = ast_config_load("logger.conf");
-
- /* If no config file, we're fine, set default options. */
- if (!cfg) {
- fprintf(stderr, "Unable to open logger.conf: %s\n", strerror(errno));
- chan = malloc(sizeof(struct logchannel));
- memset(chan, 0, sizeof(struct logchannel));
- chan->type = LOGTYPE_CONSOLE;
- chan->logmask = 28; /*warning,notice,error */
- chan->next = logchannels;
- logchannels = chan;
- global_logmask |= chan->logmask;
- return;
- }
-
- ast_mutex_lock(&loglock);
- if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
- if(ast_true(s)) {
- if(gethostname(hostname, sizeof(hostname)-1)) {
- ast_copy_string(hostname, "unknown", sizeof(hostname));
- ast_log(LOG_WARNING, "What box has no hostname???\n");
- }
- } else
- hostname[0] = '\0';
- } else
- hostname[0] = '\0';
- if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
- ast_copy_string(dateformat, s, sizeof(dateformat));
- } else
- ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat));
- if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) {
- logfiles.queue_log = ast_true(s);
- }
- if ((s = ast_variable_retrieve(cfg, "general", "event_log"))) {
- logfiles.event_log = ast_true(s);
- }
-
- var = ast_variable_browse(cfg, "logfiles");
- while(var) {
- chan = make_logchannel(var->name, var->value, var->lineno);
- if (chan) {
- chan->next = logchannels;
- logchannels = chan;
- global_logmask |= chan->logmask;
- }
- var = var->next;
- }
-
- ast_config_destroy(cfg);
- ast_mutex_unlock(&loglock);
-}
-
-void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...)
-{
- va_list ap;
- ast_mutex_lock(&loglock);
- if (qlog) {
- va_start(ap, fmt);
- fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
- vfprintf(qlog, fmt, ap);
- fprintf(qlog, "\n");
- va_end(ap);
- fflush(qlog);
- }
- ast_mutex_unlock(&loglock);
-}
-
-int reload_logger(int rotate)
-{
- char old[AST_CONFIG_MAX_PATH] = "";
- char new[AST_CONFIG_MAX_PATH];
- int event_rotate = rotate, queue_rotate = rotate;
- struct logchannel *f;
- FILE *myf;
- int x, res = 0;
-
- ast_mutex_lock(&loglock);
- if (eventlog)
- fclose(eventlog);
- else
- event_rotate = 0;
- eventlog = NULL;
-
- if (qlog)
- fclose(qlog);
- else
- queue_rotate = 0;
- qlog = NULL;
-
- mkdir((char *)ast_config_AST_LOG_DIR, 0755);
-
- f = logchannels;
- while(f) {
- if (f->disabled) {
- f->disabled = 0; /* Re-enable logging at reload */
- manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
- }
- if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
- fclose(f->fileptr); /* Close file */
- f->fileptr = NULL;
- if(rotate) {
- ast_copy_string(old, f->filename, sizeof(old));
-
- for(x=0;;x++) {
- snprintf(new, sizeof(new), "%s.%d", f->filename, x);
- myf = fopen((char *)new, "r");
- if (myf) {
- fclose(myf);
- } else {
- break;
- }
- }
-
- /* do it */
- if (rename(old,new))
- fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
- }
- }
- f = f->next;
- }
-
- filesize_reload_needed = 0;
-
- init_logger_chain();
-
- if (logfiles.event_log) {
- snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
- if (event_rotate) {
- for (x=0;;x++) {
- snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
- myf = fopen((char *)new, "r");
- if (myf) /* File exists */
- fclose(myf);
- else
- break;
- }
-
- /* do it */
- if (rename(old,new))
- ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
- }
-
- eventlog = fopen(old, "a");
- if (eventlog) {
- ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n");
- if (option_verbose)
- ast_verbose("Asterisk Event Logger restarted\n");
- } else {
- ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
- res = -1;
- }
- }
-
- if (logfiles.queue_log) {
- snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG);
- if (queue_rotate) {
- for (x = 0; ; x++) {
- snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, QUEUELOG, x);
- myf = fopen((char *)new, "r");
- if (myf) /* File exists */
- fclose(myf);
- else
- break;
- }
-
- /* do it */
- if (rename(old, new))
- ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
- }
-
- qlog = fopen(old, "a");
- if (qlog) {
- ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
- ast_log(LOG_EVENT, "Restarted Asterisk Queue Logger\n");
- if (option_verbose)
- ast_verbose("Asterisk Queue Logger restarted\n");
- } else {
- ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
- res = -1;
- }
- }
- ast_mutex_unlock(&loglock);
-
- return res;
-}
-
-static int handle_logger_reload(int fd, int argc, char *argv[])
-{
- if(reload_logger(0)) {
- ast_cli(fd, "Failed to reload the logger\n");
- return RESULT_FAILURE;
- } else
- return RESULT_SUCCESS;
-}
-
-static int handle_logger_rotate(int fd, int argc, char *argv[])
-{
- if(reload_logger(1)) {
- ast_cli(fd, "Failed to reload the logger and rotate log files\n");
- return RESULT_FAILURE;
- } else
- return RESULT_SUCCESS;
-}
-
-/*--- handle_logger_show_channels: CLI command to show logging system
- configuration */
-static int handle_logger_show_channels(int fd, int argc, char *argv[])
-{
-#define FORMATL "%-35.35s %-8.8s %-9.9s "
- struct logchannel *chan;
-
- ast_mutex_lock(&loglock);
-
- chan = logchannels;
- ast_cli(fd,FORMATL, "Channel", "Type", "Status");
- ast_cli(fd, "Configuration\n");
- ast_cli(fd,FORMATL, "-------", "----", "------");
- ast_cli(fd, "-------------\n");
- while (chan) {
- ast_cli(fd, FORMATL, chan->filename, chan->type==LOGTYPE_CONSOLE ? "Console" : (chan->type==LOGTYPE_SYSLOG ? "Syslog" : "File"),
- chan->disabled ? "Disabled" : "Enabled");
- ast_cli(fd, " - ");
- if (chan->logmask & (1 << __LOG_DEBUG))
- ast_cli(fd, "Debug ");
- if (chan->logmask & (1 << __LOG_DTMF))
- ast_cli(fd, "DTMF ");
- if (chan->logmask & (1 << __LOG_VERBOSE))
- ast_cli(fd, "Verbose ");
- if (chan->logmask & (1 << __LOG_WARNING))
- ast_cli(fd, "Warning ");
- if (chan->logmask & (1 << __LOG_NOTICE))
- ast_cli(fd, "Notice ");
- if (chan->logmask & (1 << __LOG_ERROR))
- ast_cli(fd, "Error ");
- if (chan->logmask & (1 << __LOG_EVENT))
- ast_cli(fd, "Event ");
- ast_cli(fd, "\n");
- chan = chan->next;
- }
- ast_cli(fd, "\n");
-
- ast_mutex_unlock(&loglock);
-
- return RESULT_SUCCESS;
-}
-
-static struct verb {
- void (*verboser)(const char *string, int opos, int replacelast, int complete);
- struct verb *next;
-} *verboser = NULL;
-
-
-static char logger_reload_help[] =
-"Usage: logger reload\n"
-" Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n";
-
-static char logger_rotate_help[] =
-"Usage: logger rotate\n"
-" Rotates and Reopens the log files.\n";
-
-static char logger_show_channels_help[] =
-"Usage: logger show channels\n"
-" Show configured logger channels.\n";
-
-static struct ast_cli_entry logger_show_channels_cli =
- { { "logger", "show", "channels", NULL },
- handle_logger_show_channels, "List configured log channels",
- logger_show_channels_help };
-
-static struct ast_cli_entry reload_logger_cli =
- { { "logger", "reload", NULL },
- handle_logger_reload, "Reopens the log files",
- logger_reload_help };
-
-static struct ast_cli_entry rotate_logger_cli =
- { { "logger", "rotate", NULL },
- handle_logger_rotate, "Rotates and reopens the log files",
- logger_rotate_help };
-
-static int handle_SIGXFSZ(int sig)
-{
- /* Indicate need to reload */
- filesize_reload_needed = 1;
- return 0;
-}
-
-int init_logger(void)
-{
- char tmp[256];
- int res = 0;
-
- /* auto rotate if sig SIGXFSZ comes a-knockin */
- (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ);
-
- /* register the relaod logger cli command */
- ast_cli_register(&reload_logger_cli);
- ast_cli_register(&rotate_logger_cli);
- ast_cli_register(&logger_show_channels_cli);
-
- mkdir((char *)ast_config_AST_LOG_DIR, 0755);
-
- /* create log channels */
- init_logger_chain();
-
- /* create the eventlog */
- if (logfiles.event_log) {
- mkdir((char *)ast_config_AST_LOG_DIR, 0755);
- snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
- eventlog = fopen((char *)tmp, "a");
- if (eventlog) {
- ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
- if (option_verbose)
- ast_verbose("Asterisk Event Logger Started %s\n",(char *)tmp);
- } else {
- ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
- res = -1;
- }
- }
-
- if (logfiles.queue_log) {
- snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG);
- qlog = fopen(tmp, "a");
- ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
- }
- return res;
-}
-
-void close_logger(void)
-{
- struct msglist *m, *tmp;
-
- ast_mutex_lock(&msglist_lock);
- m = list;
- while(m) {
- if (m->msg) {
- free(m->msg);
- }
- tmp = m->next;
- free(m);
- m = tmp;
- }
- list = last = NULL;
- msgcnt = 0;
- ast_mutex_unlock(&msglist_lock);
- return;
-}
-
-static void ast_log_vsyslog(int level, const char *file, int line, const char *function, const char *fmt, va_list args)
-{
- char buf[BUFSIZ];
- char *s;
-
- if (level >= SYSLOG_NLEVELS) {
- /* we are locked here, so cannot ast_log() */
- fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", level);
- return;
- }
- if (level == __LOG_VERBOSE) {
- snprintf(buf, sizeof(buf), "VERBOSE[%ld]: ", (long)GETTID());
- level = __LOG_DEBUG;
- } else if (level == __LOG_DTMF) {
- snprintf(buf, sizeof(buf), "DTMF[%ld]: ", (long)GETTID());
- level = __LOG_DEBUG;
- } else {
- snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: ",
- levels[level], (long)GETTID(), file, line, function);
- }
- s = buf + strlen(buf);
- vsnprintf(s, sizeof(buf) - strlen(buf), fmt, args);
- term_strip(s, s, strlen(s) + 1);
- syslog(syslog_level_map[level], "%s", buf);
-}
-
-/*
- * send log messages to syslog and/or the console
- */
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
-{
- struct logchannel *chan;
- char buf[BUFSIZ];
- time_t t;
- struct tm tm;
- char date[256];
-
- va_list ap;
-
- /* don't display LOG_DEBUG messages unless option_verbose _or_ option_debug
- are non-zero; LOG_DEBUG messages can still be displayed if option_debug
- is zero, if option_verbose is non-zero (this allows for 'level zero'
- LOG_DEBUG messages to be displayed, if the logmask on any channel
- allows it)
- */
- if (!option_verbose && !option_debug && (level == __LOG_DEBUG)) {
- return;
- }
-
- /* Ignore anything that never gets logged anywhere */
- if (!(global_logmask & (1 << level)))
- return;
-
- /* Ignore anything other than the currently debugged file if there is one */
- if ((level == __LOG_DEBUG) && !ast_strlen_zero(debug_filename) && strcasecmp(debug_filename, file))
- return;
-
- /* begin critical section */
- ast_mutex_lock(&loglock);
-
- time(&t);
- localtime_r(&t, &tm);
- strftime(date, sizeof(date), dateformat, &tm);
-
- if (logfiles.event_log && level == __LOG_EVENT) {
- va_start(ap, fmt);
-
- fprintf(eventlog, "%s asterisk[%d]: ", date, getpid());
- vfprintf(eventlog, fmt, ap);
- fflush(eventlog);
-
- va_end(ap);
- ast_mutex_unlock(&loglock);
- return;
- }
-
- if (logchannels) {
- chan = logchannels;
- while(chan && !chan->disabled) {
- /* Check syslog channels */
- if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << level))) {
- va_start(ap, fmt);
- ast_log_vsyslog(level, file, line, function, fmt, ap);
- va_end(ap);
- /* Console channels */
- } else if ((chan->logmask & (1 << level)) && (chan->type == LOGTYPE_CONSOLE)) {
- char linestr[128];
- char tmp1[80], tmp2[80], tmp3[80], tmp4[80];
-
- if (level != __LOG_VERBOSE) {
- sprintf(linestr, "%d", line);
- snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: %s:%s %s: " : "%s %s[%ld]: %s:%s %s: ",
- date,
- term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
- (long)GETTID(),
- term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)),
- term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
- term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
-
- ast_console_puts(buf);
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- ast_console_puts(buf);
- }
- /* File channels */
- } else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
- int res;
- snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: " : "%s %s[%ld] %s: ", date,
- levels[level], (long)GETTID(), file);
- res = fprintf(chan->fileptr, buf);
- if (res <= 0 && buf[0] != '\0') { /* Error, no characters printed */
- fprintf(stderr,"**** Asterisk Logging Error: ***********\n");
- if (errno == ENOMEM || errno == ENOSPC) {
- fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
- } else
- fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
- manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
- chan->disabled = 1;
- } else {
- /* No error message, continue printing */
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- term_strip(buf, buf, sizeof(buf));
- fputs(buf, chan->fileptr);
- fflush(chan->fileptr);
- }
- }
- chan = chan->next;
- }
- } else {
- /*
- * we don't have the logger chain configured yet,
- * so just log to stdout
- */
- if (level != __LOG_VERBOSE) {
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- fputs(buf, stdout);
- }
- }
-
- ast_mutex_unlock(&loglock);
- /* end critical section */
- if (filesize_reload_needed) {
- reload_logger(1);
- ast_log(LOG_EVENT,"Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
- if (option_verbose)
- ast_verbose("Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
- }
-}
-
-void ast_verbose(const char *fmt, ...)
-{
- static char stuff[4096];
- static int len = 0;
- static int replacelast = 0;
-
- int complete;
- int olen;
- struct msglist *m;
- struct verb *v;
-
- va_list ap;
- va_start(ap, fmt);
-
- if (option_timestamp) {
- time_t t;
- struct tm tm;
- char date[40];
- char *datefmt;
-
- time(&t);
- localtime_r(&t, &tm);
- strftime(date, sizeof(date), dateformat, &tm);
- datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
- if (datefmt) {
- sprintf(datefmt, "[%s] %s", date, fmt);
- fmt = datefmt;
- }
- }
-
- /* this lock is also protecting against multiple threads
- being in this function at the same time, so it must be
- held before any of the static variables are accessed
- */
- ast_mutex_lock(&msglist_lock);
-
- /* there is a potential security problem here: if formatting
- the current date using 'dateformat' results in a string
- containing '%', then the vsnprintf() call below will
- probably try to access random memory
- */
- vsnprintf(stuff + len, sizeof(stuff) - len, fmt, ap);
- va_end(ap);
-
- olen = len;
- len = strlen(stuff);
-
- complete = (stuff[len - 1] == '\n') ? 1 : 0;
-
- /* If we filled up the stuff completely, then log it even without the '\n' */
- if (len >= sizeof(stuff) - 1) {
- complete = 1;
- len = 0;
- }
-
- if (complete) {
- if (msgcnt < MAX_MSG_QUEUE) {
- /* Allocate new structure */
- if ((m = malloc(sizeof(*m))))
- msgcnt++;
- } else {
- /* Recycle the oldest entry */
- m = list;
- list = list->next;
- free(m->msg);
- }
- if (m) {
- m->msg = strdup(stuff);
- if (m->msg) {
- if (last)
- last->next = m;
- else
- list = m;
- m->next = NULL;
- last = m;
- } else {
- msgcnt--;
- ast_log(LOG_ERROR, "Out of memory\n");
- free(m);
- }
- }
- }
-
- for (v = verboser; v; v = v->next)
- v->verboser(stuff, olen, replacelast, complete);
-
- ast_log(LOG_VERBOSE, "%s", stuff);
-
- if (len) {
- if (!complete)
- replacelast = 1;
- else
- replacelast = len = 0;
- }
-
- ast_mutex_unlock(&msglist_lock);
-}
-
-int ast_verbose_dmesg(void (*v)(const char *string, int opos, int replacelast, int complete))
-{
- struct msglist *m;
- ast_mutex_lock(&msglist_lock);
- m = list;
- while(m) {
- /* Send all the existing entries that we have queued (i.e. they're likely to have missed) */
- v(m->msg, 0, 0, 1);
- m = m->next;
- }
- ast_mutex_unlock(&msglist_lock);
- return 0;
-}
-
-int ast_register_verbose(void (*v)(const char *string, int opos, int replacelast, int complete))
-{
- struct msglist *m;
- struct verb *tmp;
- /* XXX Should be more flexible here, taking > 1 verboser XXX */
- if ((tmp = malloc(sizeof (struct verb)))) {
- tmp->verboser = v;
- ast_mutex_lock(&msglist_lock);
- tmp->next = verboser;
- verboser = tmp;
- m = list;
- while(m) {
- /* Send all the existing entries that we have queued (i.e. they're likely to have missed) */
- v(m->msg, 0, 0, 1);
- m = m->next;
- }
- ast_mutex_unlock(&msglist_lock);
- return 0;
- }
- return -1;
-}
-
-int ast_unregister_verbose(void (*v)(const char *string, int opos, int replacelast, int complete))
-{
- int res = -1;
- struct verb *tmp, *tmpl=NULL;
- ast_mutex_lock(&msglist_lock);
- tmp = verboser;
- while(tmp) {
- if (tmp->verboser == v) {
- if (tmpl)
- tmpl->next = tmp->next;
- else
- verboser = tmp->next;
- free(tmp);
- break;
- }
- tmpl = tmp;
- tmp = tmp->next;
- }
- if (tmp)
- res = 0;
- ast_mutex_unlock(&msglist_lock);
- return res;
-}
diff --git a/1.2-netsec/manager.c b/1.2-netsec/manager.c
deleted file mode 100644
index 5254f7749..000000000
--- a/1.2-netsec/manager.c
+++ /dev/null
@@ -1,1764 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief The Asterisk Management Interface - AMI
- *
- * Channel Management and more
- *
- * \ref amiconf
- */
-
-/*! \addtogroup Group_AMI AMI functions
-*/
-/*! @{
- Doxygen group */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/manager.h"
-#include "asterisk/config.h"
-#include "asterisk/callerid.h"
-#include "asterisk/lock.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/cli.h"
-#include "asterisk/app.h"
-#include "asterisk/pbx.h"
-#include "asterisk/md5.h"
-#include "asterisk/acl.h"
-#include "asterisk/utils.h"
-
-struct fast_originate_helper {
- char tech[AST_MAX_MANHEADER_LEN];
- char data[AST_MAX_MANHEADER_LEN];
- int timeout;
- char app[AST_MAX_APP];
- char appdata[AST_MAX_MANHEADER_LEN];
- char cid_name[AST_MAX_MANHEADER_LEN];
- char cid_num[AST_MAX_MANHEADER_LEN];
- char context[AST_MAX_CONTEXT];
- char exten[AST_MAX_EXTENSION];
- char idtext[AST_MAX_MANHEADER_LEN];
- char account[AST_MAX_ACCOUNT_CODE];
- int priority;
- struct ast_variable *vars;
-};
-
-static int enabled = 0;
-static int portno = DEFAULT_MANAGER_PORT;
-static int asock = -1;
-static int displayconnects = 1;
-
-static pthread_t t;
-AST_MUTEX_DEFINE_STATIC(sessionlock);
-static int block_sockets = 0;
-
-static struct permalias {
- int num;
- char *label;
-} perms[] = {
- { EVENT_FLAG_SYSTEM, "system" },
- { EVENT_FLAG_CALL, "call" },
- { EVENT_FLAG_LOG, "log" },
- { EVENT_FLAG_VERBOSE, "verbose" },
- { EVENT_FLAG_COMMAND, "command" },
- { EVENT_FLAG_AGENT, "agent" },
- { EVENT_FLAG_USER, "user" },
- { -1, "all" },
- { 0, "none" },
-};
-
-static struct mansession *sessions = NULL;
-static struct manager_action *first_action = NULL;
-AST_MUTEX_DEFINE_STATIC(actionlock);
-
-/*! If you are calling ast_carefulwrite, it is assumed that you are calling
- it on a file descriptor that _DOES_ have NONBLOCK set. This way,
- there is only one system call made to do a write, unless we actually
- have a need to wait. This way, we get better performance. */
-int ast_carefulwrite(int fd, char *s, int len, int timeoutms)
-{
- /* Try to write string, but wait no more than ms milliseconds
- before timing out */
- int res=0;
- struct pollfd fds[1];
- while(len) {
- res = write(fd, s, len);
- if ((res < 0) && (errno != EAGAIN)) {
- return -1;
- }
- if (res < 0) res = 0;
- len -= res;
- s += res;
- res = 0;
- if (len) {
- fds[0].fd = fd;
- fds[0].events = POLLOUT;
- /* Wait until writable again */
- res = poll(fds, 1, timeoutms);
- if (res < 1)
- return -1;
- }
- }
- return res;
-}
-
-/*! authority_to_str: Convert authority code to string with serveral options */
-static char *authority_to_str(int authority, char *res, int reslen)
-{
- int running_total = 0, i;
- memset(res, 0, reslen);
- for (i=0; i<sizeof(perms) / sizeof(perms[0]) - 1; i++) {
- if (authority & perms[i].num) {
- if (*res) {
- strncat(res, ",", (reslen > running_total) ? reslen - running_total : 0);
- running_total++;
- }
- strncat(res, perms[i].label, (reslen > running_total) ? reslen - running_total : 0);
- running_total += strlen(perms[i].label);
- }
- }
- if (ast_strlen_zero(res)) {
- ast_copy_string(res, "<none>", reslen);
- }
- return res;
-}
-
-static char *complete_show_mancmd(char *line, char *word, int pos, int state)
-{
- struct manager_action *cur = first_action;
- int which = 0;
-
- ast_mutex_lock(&actionlock);
- while (cur) { /* Walk the list of actions */
- if (!strncasecmp(word, cur->action, strlen(word))) {
- if (++which > state) {
- char *ret = strdup(cur->action);
- ast_mutex_unlock(&actionlock);
- return ret;
- }
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&actionlock);
- return NULL;
-}
-
-static int handle_showmancmd(int fd, int argc, char *argv[])
-{
- struct manager_action *cur = first_action;
- char authority[80];
- int num;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&actionlock);
- while (cur) { /* Walk the list of actions */
- for (num = 3; num < argc; num++) {
- if (!strcasecmp(cur->action, argv[num])) {
- ast_cli(fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n", cur->action, cur->synopsis, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->description ? cur->description : "");
- }
- }
- cur = cur->next;
- }
-
- ast_mutex_unlock(&actionlock);
- return RESULT_SUCCESS;
-}
-
-/*! \brief handle_showmancmds: CLI command */
-/* Should change to "manager show commands" */
-static int handle_showmancmds(int fd, int argc, char *argv[])
-{
- struct manager_action *cur = first_action;
- char authority[80];
- char *format = " %-15.15s %-15.15s %-55.55s\n";
-
- ast_mutex_lock(&actionlock);
- ast_cli(fd, format, "Action", "Privilege", "Synopsis");
- ast_cli(fd, format, "------", "---------", "--------");
- while (cur) { /* Walk the list of actions */
- ast_cli(fd, format, cur->action, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->synopsis);
- cur = cur->next;
- }
-
- ast_mutex_unlock(&actionlock);
- return RESULT_SUCCESS;
-}
-
-/*! \brief handle_showmanconn: CLI command show manager connected */
-/* Should change to "manager show connected" */
-static int handle_showmanconn(int fd, int argc, char *argv[])
-{
- struct mansession *s;
- char iabuf[INET_ADDRSTRLEN];
- char *format = " %-15.15s %-15.15s\n";
- ast_mutex_lock(&sessionlock);
- s = sessions;
- ast_cli(fd, format, "Username", "IP Address");
- while (s) {
- ast_cli(fd, format,s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
- s = s->next;
- }
-
- ast_mutex_unlock(&sessionlock);
- return RESULT_SUCCESS;
-}
-
-static char showmancmd_help[] =
-"Usage: show manager command <actionname>\n"
-" Shows the detailed description for a specific Asterisk manager interface command.\n";
-
-static char showmancmds_help[] =
-"Usage: show manager commands\n"
-" Prints a listing of all the available Asterisk manager interface commands.\n";
-
-static char showmanconn_help[] =
-"Usage: show manager connected\n"
-" Prints a listing of the users that are currently connected to the\n"
-"Asterisk manager interface.\n";
-
-static struct ast_cli_entry show_mancmd_cli =
- { { "show", "manager", "command", NULL },
- handle_showmancmd, "Show a manager interface command", showmancmd_help, complete_show_mancmd };
-
-static struct ast_cli_entry show_mancmds_cli =
- { { "show", "manager", "commands", NULL },
- handle_showmancmds, "List manager interface commands", showmancmds_help };
-
-static struct ast_cli_entry show_manconn_cli =
- { { "show", "manager", "connected", NULL },
- handle_showmanconn, "Show connected manager interface users", showmanconn_help };
-
-static void free_session(struct mansession *s)
-{
- struct eventqent *eqe;
- if (s->fd > -1)
- close(s->fd);
- ast_mutex_destroy(&s->__lock);
- while(s->eventq) {
- eqe = s->eventq;
- s->eventq = s->eventq->next;
- free(eqe);
- }
- free(s);
-}
-
-static void destroy_session(struct mansession *s)
-{
- struct mansession *cur, *prev = NULL;
- ast_mutex_lock(&sessionlock);
- cur = sessions;
- while(cur) {
- if (cur == s)
- break;
- prev = cur;
- cur = cur->next;
- }
- if (cur) {
- if (prev)
- prev->next = cur->next;
- else
- sessions = cur->next;
- free_session(s);
- } else
- ast_log(LOG_WARNING, "Trying to delete nonexistent session %p?\n", s);
- ast_mutex_unlock(&sessionlock);
-
-}
-
-char *astman_get_header(struct message *m, char *var)
-{
- char cmp[80];
- int x;
- snprintf(cmp, sizeof(cmp), "%s: ", var);
- for (x=0;x<m->hdrcount;x++)
- if (!strncasecmp(cmp, m->headers[x], strlen(cmp)))
- return m->headers[x] + strlen(cmp);
- return "";
-}
-
-struct ast_variable *astman_get_variables(struct message *m)
-{
- int varlen, x, y;
- struct ast_variable *head = NULL, *cur;
- char *var, *val;
- unsigned int var_count;
- char *vars[32];
-
- varlen = strlen("Variable: ");
-
- for (x = 0; x < m->hdrcount; x++) {
- if (strncasecmp("Variable: ", m->headers[x], varlen))
- continue;
-
- if (!(var = ast_strdupa(m->headers[x] + varlen)))
- return head;
-
- if ((var_count = ast_app_separate_args(var, '|', vars, sizeof(vars) / sizeof(vars[0])))) {
- for (y = 0; y < var_count; y++) {
- if (!vars[y])
- continue;
- var = val = ast_strdupa(vars[y]);
- strsep(&val, "=");
- if (!val || ast_strlen_zero(var))
- continue;
- cur = ast_variable_new(var, val);
- if (head) {
- cur->next = head;
- head = cur;
- } else
- head = cur;
- }
- }
- }
-
- return head;
-}
-
-/*! NOTE:
- Callers of astman_send_error(), astman_send_response() or astman_send_ack() must EITHER
- hold the session lock _or_ be running in an action callback (in which case s->busy will
- be non-zero). In either of these cases, there is no need to lock-protect the session's
- fd, since no other output will be sent (events will be queued), and no input will
- be read until either the current action finishes or get_input() obtains the session
- lock.
- */
-void astman_send_error(struct mansession *s, struct message *m, char *error)
-{
- char *id = astman_get_header(m,"ActionID");
-
- ast_cli(s->fd, "Response: Error\r\n");
- if (!ast_strlen_zero(id))
- ast_cli(s->fd, "ActionID: %s\r\n",id);
- ast_cli(s->fd, "Message: %s\r\n\r\n", error);
-}
-
-void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg)
-{
- char *id = astman_get_header(m,"ActionID");
-
- ast_cli(s->fd, "Response: %s\r\n", resp);
- if (!ast_strlen_zero(id))
- ast_cli(s->fd, "ActionID: %s\r\n",id);
- if (msg)
- ast_cli(s->fd, "Message: %s\r\n\r\n", msg);
- else
- ast_cli(s->fd, "\r\n");
-}
-
-void astman_send_ack(struct mansession *s, struct message *m, char *msg)
-{
- astman_send_response(s, m, "Success", msg);
-}
-
-/*! Tells you if smallstr exists inside bigstr
- which is delim by delim and uses no buf or stringsep
- ast_instring("this|that|more","this",',') == 1;
-
- feel free to move this to app.c -anthm */
-static int ast_instring(char *bigstr, char *smallstr, char delim)
-{
- char *val = bigstr, *next;
-
- do {
- if ((next = strchr(val, delim))) {
- if (!strncmp(val, smallstr, (next - val)))
- return 1;
- else
- continue;
- } else
- return !strcmp(smallstr, val);
-
- } while (*(val = (next + 1)));
-
- return 0;
-}
-
-static int get_perm(char *instr)
-{
- int x = 0, ret = 0;
-
- if (!instr)
- return 0;
-
- for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++)
- if (ast_instring(instr, perms[x].label, ','))
- ret |= perms[x].num;
-
- return ret;
-}
-
-static int ast_is_number(char *string)
-{
- int ret = 1, x = 0;
-
- if (!string)
- return 0;
-
- for (x=0; x < strlen(string); x++) {
- if (!(string[x] >= 48 && string[x] <= 57)) {
- ret = 0;
- break;
- }
- }
-
- return ret ? atoi(string) : 0;
-}
-
-static int ast_strings_to_mask(char *string)
-{
- int x, ret = -1;
-
- x = ast_is_number(string);
-
- if (x) {
- ret = x;
- } else if (ast_strlen_zero(string)) {
- ret = -1;
- } else if (ast_false(string)) {
- ret = 0;
- } else if (ast_true(string)) {
- ret = 0;
- for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++)
- ret |= perms[x].num;
- } else {
- ret = 0;
- for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++) {
- if (ast_instring(string, perms[x].label, ','))
- ret |= perms[x].num;
- }
- }
-
- return ret;
-}
-
-/*!
- Rather than braindead on,off this now can also accept a specific int mask value
- or a ',' delim list of mask strings (the same as manager.conf) -anthm
-*/
-
-static int set_eventmask(struct mansession *s, char *eventmask)
-{
- int maskint = ast_strings_to_mask(eventmask);
-
- ast_mutex_lock(&s->__lock);
- if (maskint >= 0)
- s->send_events = maskint;
- ast_mutex_unlock(&s->__lock);
-
- return maskint;
-}
-
-static int authenticate(struct mansession *s, struct message *m)
-{
- struct ast_config *cfg;
- char iabuf[INET_ADDRSTRLEN];
- char *cat;
- char *user = astman_get_header(m, "Username");
- char *pass = astman_get_header(m, "Secret");
- char *authtype = astman_get_header(m, "AuthType");
- char *key = astman_get_header(m, "Key");
- char *events = astman_get_header(m, "Events");
-
- cfg = ast_config_load("manager.conf");
- if (!cfg)
- return -1;
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (strcasecmp(cat, "general")) {
- /* This is a user */
- if (!strcasecmp(cat, user)) {
- struct ast_variable *v;
- struct ast_ha *ha = NULL;
- char *password = NULL;
- v = ast_variable_browse(cfg, cat);
- while (v) {
- if (!strcasecmp(v->name, "secret")) {
- password = v->value;
- } else if (!strcasecmp(v->name, "permit") ||
- !strcasecmp(v->name, "deny")) {
- ha = ast_append_ha(v->name, v->value, ha);
- } else if (!strcasecmp(v->name, "writetimeout")) {
- int val = atoi(v->value);
-
- if (val < 100)
- ast_log(LOG_WARNING, "Invalid writetimeout value '%s' at line %d\n", v->value, v->lineno);
- else
- s->writetimeout = val;
- }
-
- v = v->next;
- }
- if (ha && !ast_apply_ha(ha, &(s->sin))) {
- ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), user);
- ast_free_ha(ha);
- ast_config_destroy(cfg);
- return -1;
- } else if (ha)
- ast_free_ha(ha);
- if (!strcasecmp(authtype, "MD5")) {
- if (!ast_strlen_zero(key) && s->challenge) {
- int x;
- int len=0;
- char md5key[256] = "";
- struct MD5Context md5;
- unsigned char digest[16];
- MD5Init(&md5);
- MD5Update(&md5, (unsigned char *) s->challenge, strlen(s->challenge));
- MD5Update(&md5, (unsigned char *) password, strlen(password));
- MD5Final(digest, &md5);
- for (x=0;x<16;x++)
- len += sprintf(md5key + len, "%2.2x", digest[x]);
- if (!strcmp(md5key, key))
- break;
- else {
- ast_config_destroy(cfg);
- return -1;
- }
- }
- } else if (password && !strcasecmp(password, pass)) {
- break;
- } else {
- ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), user);
- ast_config_destroy(cfg);
- return -1;
- }
- }
- }
- cat = ast_category_browse(cfg, cat);
- }
- if (cat) {
- ast_copy_string(s->username, cat, sizeof(s->username));
- s->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
- s->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
- ast_config_destroy(cfg);
- if (events)
- set_eventmask(s, events);
- return 0;
- }
- ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), user);
- ast_config_destroy(cfg);
- return -1;
-}
-
-/*! \brief PING: Manager PING */
-static char mandescr_ping[] =
-"Description: A 'Ping' action will ellicit a 'Pong' response. Used to keep the "
-" manager connection open.\n"
-"Variables: NONE\n";
-
-static int action_ping(struct mansession *s, struct message *m)
-{
- astman_send_response(s, m, "Pong", NULL);
- return 0;
-}
-
-static char mandescr_listcommands[] =
-"Description: Returns the action name and synopsis for every\n"
-" action that is available to the user\n"
-"Variables: NONE\n";
-
-static int action_listcommands(struct mansession *s, struct message *m)
-{
- struct manager_action *cur = first_action;
- char idText[256] = "";
- char temp[BUFSIZ];
- char *id = astman_get_header(m,"ActionID");
-
- if (!ast_strlen_zero(id))
- snprintf(idText,256,"ActionID: %s\r\n",id);
- ast_cli(s->fd, "Response: Success\r\n%s", idText);
- ast_mutex_lock(&actionlock);
- while (cur) { /* Walk the list of actions */
- if ((s->writeperm & cur->authority) == cur->authority)
- ast_cli(s->fd, "%s: %s (Priv: %s)\r\n", cur->action, cur->synopsis, authority_to_str(cur->authority, temp, sizeof(temp)) );
- cur = cur->next;
- }
- ast_mutex_unlock(&actionlock);
- ast_cli(s->fd, "\r\n");
-
- return 0;
-}
-
-static char mandescr_events[] =
-"Description: Enable/Disable sending of events to this manager\n"
-" client.\n"
-"Variables:\n"
-" EventMask: 'on' if all events should be sent,\n"
-" 'off' if no events should be sent,\n"
-" 'system,call,log' to select which flags events should have to be sent.\n";
-
-static int action_events(struct mansession *s, struct message *m)
-{
- char *mask = astman_get_header(m, "EventMask");
- int res;
-
- res = set_eventmask(s, mask);
- if (res > 0)
- astman_send_response(s, m, "Events On", NULL);
- else if (res == 0)
- astman_send_response(s, m, "Events Off", NULL);
-
- return 0;
-}
-
-static char mandescr_logoff[] =
-"Description: Logoff this manager session\n"
-"Variables: NONE\n";
-
-static int action_logoff(struct mansession *s, struct message *m)
-{
- astman_send_response(s, m, "Goodbye", "Thanks for all the fish.");
- return -1;
-}
-
-static char mandescr_hangup[] =
-"Description: Hangup a channel\n"
-"Variables: \n"
-" Channel: The channel name to be hungup\n";
-
-static int action_hangup(struct mansession *s, struct message *m)
-{
- struct ast_channel *c = NULL;
- char *name = astman_get_header(m, "Channel");
- if (ast_strlen_zero(name)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
- ast_mutex_unlock(&c->lock);
- astman_send_ack(s, m, "Channel Hungup");
- return 0;
-}
-
-static char mandescr_setvar[] =
-"Description: Set a global or local channel variable.\n"
-"Variables: (Names marked with * are required)\n"
-" Channel: Channel to set variable for\n"
-" *Variable: Variable name\n"
-" *Value: Value\n";
-
-static int action_setvar(struct mansession *s, struct message *m)
-{
- struct ast_channel *c = NULL;
- char *name = astman_get_header(m, "Channel");
- char *varname = astman_get_header(m, "Variable");
- char *varval = astman_get_header(m, "Value");
-
- if (ast_strlen_zero(varname)) {
- astman_send_error(s, m, "No variable specified");
- return 0;
- }
-
- if (ast_strlen_zero(varval)) {
- astman_send_error(s, m, "No value specified");
- return 0;
- }
-
- if (!ast_strlen_zero(name)) {
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- }
-
- pbx_builtin_setvar_helper(c, varname, varval);
-
- if (c)
- ast_mutex_unlock(&c->lock);
-
- astman_send_ack(s, m, "Variable Set");
-
- return 0;
-}
-
-static char mandescr_getvar[] =
-"Description: Get the value of a global or local channel variable.\n"
-"Variables: (Names marked with * are required)\n"
-" Channel: Channel to read variable from\n"
-" *Variable: Variable name\n"
-" ActionID: Optional Action id for message matching.\n";
-
-static int action_getvar(struct mansession *s, struct message *m)
-{
- struct ast_channel *c = NULL;
- char *name = astman_get_header(m, "Channel");
- char *varname = astman_get_header(m, "Variable");
- char *id = astman_get_header(m,"ActionID");
- char *varval;
- char *varval2=NULL;
-
- if (!strlen(varname)) {
- astman_send_error(s, m, "No variable specified");
- return 0;
- }
-
- if (strlen(name)) {
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- }
-
- varval=pbx_builtin_getvar_helper(c,varname);
- if (varval)
- varval2 = ast_strdupa(varval);
- if (!varval2)
- varval2 = "";
- if (c)
- ast_mutex_unlock(&c->lock);
- ast_cli(s->fd, "Response: Success\r\n"
- "Variable: %s\r\nValue: %s\r\n" ,varname,varval2);
- if (!ast_strlen_zero(id))
- ast_cli(s->fd, "ActionID: %s\r\n",id);
- ast_cli(s->fd, "\r\n");
-
- return 0;
-}
-
-
-/*! \brief action_status: Manager "status" command to show channels */
-/* Needs documentation... */
-static int action_status(struct mansession *s, struct message *m)
-{
- char *id = astman_get_header(m,"ActionID");
- char *name = astman_get_header(m,"Channel");
- char idText[256] = "";
- struct ast_channel *c;
- char bridge[256];
- struct timeval now = ast_tvnow();
- long elapsed_seconds=0;
- int all = ast_strlen_zero(name); /* set if we want all channels */
-
- astman_send_ack(s, m, "Channel status will follow");
- if (!ast_strlen_zero(id))
- snprintf(idText,256,"ActionID: %s\r\n",id);
- if (all)
- c = ast_channel_walk_locked(NULL);
- else {
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- }
- /* if we look by name, we break after the first iteration */
- while(c) {
- if (c->_bridge)
- snprintf(bridge, sizeof(bridge), "Link: %s\r\n", c->_bridge->name);
- else
- bridge[0] = '\0';
- if (c->pbx) {
- if (c->cdr) {
- elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
- }
- ast_cli(s->fd,
- "Event: Status\r\n"
- "Privilege: Call\r\n"
- "Channel: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- "Account: %s\r\n"
- "State: %s\r\n"
- "Context: %s\r\n"
- "Extension: %s\r\n"
- "Priority: %d\r\n"
- "Seconds: %ld\r\n"
- "%s"
- "Uniqueid: %s\r\n"
- "%s"
- "\r\n",
- c->name,
- c->cid.cid_num ? c->cid.cid_num : "<unknown>",
- c->cid.cid_name ? c->cid.cid_name : "<unknown>",
- c->accountcode,
- ast_state2str(c->_state), c->context,
- c->exten, c->priority, (long)elapsed_seconds, bridge, c->uniqueid, idText);
- } else {
- ast_cli(s->fd,
- "Event: Status\r\n"
- "Privilege: Call\r\n"
- "Channel: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- "Account: %s\r\n"
- "State: %s\r\n"
- "%s"
- "Uniqueid: %s\r\n"
- "%s"
- "\r\n",
- c->name,
- c->cid.cid_num ? c->cid.cid_num : "<unknown>",
- c->cid.cid_name ? c->cid.cid_name : "<unknown>",
- c->accountcode,
- ast_state2str(c->_state), bridge, c->uniqueid, idText);
- }
- ast_mutex_unlock(&c->lock);
- if (!all)
- break;
- c = ast_channel_walk_locked(c);
- }
- ast_cli(s->fd,
- "Event: StatusComplete\r\n"
- "%s"
- "\r\n",idText);
- return 0;
-}
-
-static char mandescr_redirect[] =
-"Description: Redirect (transfer) a call.\n"
-"Variables: (Names marked with * are required)\n"
-" *Channel: Channel to redirect\n"
-" ExtraChannel: Second call leg to transfer (optional)\n"
-" *Exten: Extension to transfer to\n"
-" *Context: Context to transfer to\n"
-" *Priority: Priority to transfer to\n"
-" ActionID: Optional Action id for message matching.\n";
-
-/*! \brief action_redirect: The redirect manager command */
-static int action_redirect(struct mansession *s, struct message *m)
-{
- char *name = astman_get_header(m, "Channel");
- char *name2 = astman_get_header(m, "ExtraChannel");
- char *exten = astman_get_header(m, "Exten");
- char *context = astman_get_header(m, "Context");
- char *priority = astman_get_header(m, "Priority");
- struct ast_channel *chan, *chan2 = NULL;
- int pi = 0;
- int res;
-
- if (ast_strlen_zero(name)) {
- astman_send_error(s, m, "Channel not specified");
- return 0;
- }
- if (!ast_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
- astman_send_error(s, m, "Invalid priority\n");
- return 0;
- }
- chan = ast_get_channel_by_name_locked(name);
- if (!chan) {
- char buf[BUFSIZ];
- snprintf(buf, sizeof(buf), "Channel does not exist: %s", name);
- astman_send_error(s, m, buf);
- return 0;
- }
- if (!ast_strlen_zero(name2))
- chan2 = ast_get_channel_by_name_locked(name2);
- res = ast_async_goto(chan, context, exten, pi);
- if (!res) {
- if (!ast_strlen_zero(name2)) {
- if (chan2)
- res = ast_async_goto(chan2, context, exten, pi);
- else
- res = -1;
- if (!res)
- astman_send_ack(s, m, "Dual Redirect successful");
- else
- astman_send_error(s, m, "Secondary redirect failed");
- } else
- astman_send_ack(s, m, "Redirect successful");
- } else
- astman_send_error(s, m, "Redirect failed");
- if (chan)
- ast_mutex_unlock(&chan->lock);
- if (chan2)
- ast_mutex_unlock(&chan2->lock);
- return 0;
-}
-
-static char mandescr_command[] =
-"Description: Run a CLI command.\n"
-"Variables: (Names marked with * are required)\n"
-" *Command: Asterisk CLI command to run\n"
-" ActionID: Optional Action id for message matching.\n";
-
-/*! \brief action_command: Manager command "command" - execute CLI command */
-static int action_command(struct mansession *s, struct message *m)
-{
- char *cmd = astman_get_header(m, "Command");
- char *id = astman_get_header(m, "ActionID");
- ast_cli(s->fd, "Response: Follows\r\nPrivilege: Command\r\n");
- if (!ast_strlen_zero(id))
- ast_cli(s->fd, "ActionID: %s\r\n", id);
- /* FIXME: Wedge a ActionID response in here, waiting for later changes */
- ast_cli_command(s->fd, cmd);
- ast_cli(s->fd, "--END COMMAND--\r\n\r\n");
- return 0;
-}
-
-static void *fast_originate(void *data)
-{
- struct fast_originate_helper *in = data;
- int res;
- int reason = 0;
- struct ast_channel *chan = NULL;
-
- if (!ast_strlen_zero(in->app)) {
- res = ast_pbx_outgoing_app(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->app, in->appdata, &reason, 1,
- !ast_strlen_zero(in->cid_num) ? in->cid_num : NULL,
- !ast_strlen_zero(in->cid_name) ? in->cid_name : NULL,
- in->vars, in->account, &chan);
- } else {
- res = ast_pbx_outgoing_exten(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1,
- !ast_strlen_zero(in->cid_num) ? in->cid_num : NULL,
- !ast_strlen_zero(in->cid_name) ? in->cid_name : NULL,
- in->vars, in->account, &chan);
- }
- if (!res)
- manager_event(EVENT_FLAG_CALL,
- "OriginateSuccess",
- "%s"
- "Channel: %s/%s\r\n"
- "Context: %s\r\n"
- "Exten: %s\r\n"
- "Reason: %d\r\n"
- "Uniqueid: %s\r\n",
- in->idtext, in->tech, in->data, in->context, in->exten, reason, chan ? chan->uniqueid : "<null>");
- else
- manager_event(EVENT_FLAG_CALL,
- "OriginateFailure",
- "%s"
- "Channel: %s/%s\r\n"
- "Context: %s\r\n"
- "Exten: %s\r\n"
- "Reason: %d\r\n"
- "Uniqueid: %s\r\n",
- in->idtext, in->tech, in->data, in->context, in->exten, reason, chan ? chan->uniqueid : "<null>");
-
- /* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
- if (chan)
- ast_mutex_unlock(&chan->lock);
- free(in);
- return NULL;
-}
-
-static char mandescr_originate[] =
-"Description: Generates an outgoing call to a Extension/Context/Priority or\n"
-" Application/Data\n"
-"Variables: (Names marked with * are required)\n"
-" *Channel: Channel name to call\n"
-" Exten: Extension to use (requires 'Context' and 'Priority')\n"
-" Context: Context to use (requires 'Exten' and 'Priority')\n"
-" Priority: Priority to use (requires 'Exten' and 'Context')\n"
-" Application: Application to use\n"
-" Data: Data to use (requires 'Application')\n"
-" Timeout: How long to wait for call to be answered (in ms)\n"
-" CallerID: Caller ID to be set on the outgoing channel\n"
-" Variable: Channel variable to set, multiple Variable: headers are allowed\n"
-" Account: Account code\n"
-" Async: Set to 'true' for fast origination\n";
-
-static int action_originate(struct mansession *s, struct message *m)
-{
- char *name = astman_get_header(m, "Channel");
- char *exten = astman_get_header(m, "Exten");
- char *context = astman_get_header(m, "Context");
- char *priority = astman_get_header(m, "Priority");
- char *timeout = astman_get_header(m, "Timeout");
- char *callerid = astman_get_header(m, "CallerID");
- char *account = astman_get_header(m, "Account");
- char *app = astman_get_header(m, "Application");
- char *appdata = astman_get_header(m, "Data");
- char *async = astman_get_header(m, "Async");
- char *id = astman_get_header(m, "ActionID");
- struct ast_variable *vars = astman_get_variables(m);
- char *tech, *data;
- char *l=NULL, *n=NULL;
- int pi = 0;
- int res;
- int to = 30000;
- int reason = 0;
- char tmp[256];
- char tmp2[256];
-
- pthread_t th;
- pthread_attr_t attr;
- if (!name) {
- astman_send_error(s, m, "Channel not specified");
- return 0;
- }
- if (!ast_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
- astman_send_error(s, m, "Invalid priority\n");
- return 0;
- }
- if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%d", &to) != 1)) {
- astman_send_error(s, m, "Invalid timeout\n");
- return 0;
- }
- ast_copy_string(tmp, name, sizeof(tmp));
- tech = tmp;
- data = strchr(tmp, '/');
- if (!data) {
- astman_send_error(s, m, "Invalid channel\n");
- return 0;
- }
- *data = '\0';
- data++;
- ast_copy_string(tmp2, callerid, sizeof(tmp2));
- ast_callerid_parse(tmp2, &n, &l);
- if (n) {
- if (ast_strlen_zero(n))
- n = NULL;
- }
- if (l) {
- ast_shrink_phone_number(l);
- if (ast_strlen_zero(l))
- l = NULL;
- }
- if (ast_true(async)) {
- struct fast_originate_helper *fast = malloc(sizeof(struct fast_originate_helper));
- if (!fast) {
- res = -1;
- } else {
- memset(fast, 0, sizeof(struct fast_originate_helper));
- if (!ast_strlen_zero(id))
- snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s\r\n", id);
- ast_copy_string(fast->tech, tech, sizeof(fast->tech));
- ast_copy_string(fast->data, data, sizeof(fast->data));
- ast_copy_string(fast->app, app, sizeof(fast->app));
- ast_copy_string(fast->appdata, appdata, sizeof(fast->appdata));
- if (l)
- ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num));
- if (n)
- ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name));
- fast->vars = vars;
- ast_copy_string(fast->context, context, sizeof(fast->context));
- ast_copy_string(fast->exten, exten, sizeof(fast->exten));
- ast_copy_string(fast->account, account, sizeof(fast->account));
- fast->timeout = to;
- fast->priority = pi;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&th, &attr, fast_originate, fast)) {
- res = -1;
- } else {
- res = 0;
- }
- }
- } else if (!ast_strlen_zero(app)) {
- res = ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL);
- } else {
- if (exten && context && pi)
- res = ast_pbx_outgoing_exten(tech, AST_FORMAT_SLINEAR, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL);
- else {
- astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
- return 0;
- }
- }
- if (!res)
- astman_send_ack(s, m, "Originate successfully queued");
- else
- astman_send_error(s, m, "Originate failed");
- return 0;
-}
-
-/*! \brief Help text for manager command mailboxstatus
- */
-static char mandescr_mailboxstatus[] =
-"Description: Checks a voicemail account for status.\n"
-"Variables: (Names marked with * are required)\n"
-" *Mailbox: Full mailbox ID <mailbox>@<vm-context>\n"
-" ActionID: Optional ActionID for message matching.\n"
-"Returns number of messages.\n"
-" Message: Mailbox Status\n"
-" Mailbox: <mailboxid>\n"
-" Waiting: <count>\n"
-"\n";
-
-static int action_mailboxstatus(struct mansession *s, struct message *m)
-{
- char *mailbox = astman_get_header(m, "Mailbox");
- char *id = astman_get_header(m,"ActionID");
- char idText[256] = "";
- int ret;
- if (ast_strlen_zero(mailbox)) {
- astman_send_error(s, m, "Mailbox not specified");
- return 0;
- }
- if (!ast_strlen_zero(id))
- snprintf(idText,256,"ActionID: %s\r\n",id);
- ret = ast_app_has_voicemail(mailbox, NULL);
- ast_cli(s->fd, "Response: Success\r\n"
- "%s"
- "Message: Mailbox Status\r\n"
- "Mailbox: %s\r\n"
- "Waiting: %d\r\n\r\n", idText, mailbox, ret);
- return 0;
-}
-
-static char mandescr_mailboxcount[] =
-"Description: Checks a voicemail account for new messages.\n"
-"Variables: (Names marked with * are required)\n"
-" *Mailbox: Full mailbox ID <mailbox>@<vm-context>\n"
-" ActionID: Optional ActionID for message matching.\n"
-"Returns number of new and old messages.\n"
-" Message: Mailbox Message Count\n"
-" Mailbox: <mailboxid>\n"
-" NewMessages: <count>\n"
-" OldMessages: <count>\n"
-"\n";
-static int action_mailboxcount(struct mansession *s, struct message *m)
-{
- char *mailbox = astman_get_header(m, "Mailbox");
- char *id = astman_get_header(m,"ActionID");
- char idText[256] = "";
- int newmsgs = 0, oldmsgs = 0;
- if (ast_strlen_zero(mailbox)) {
- astman_send_error(s, m, "Mailbox not specified");
- return 0;
- }
- ast_app_messagecount(mailbox, &newmsgs, &oldmsgs);
- if (!ast_strlen_zero(id)) {
- snprintf(idText,256,"ActionID: %s\r\n",id);
- }
- ast_cli(s->fd, "Response: Success\r\n"
- "%s"
- "Message: Mailbox Message Count\r\n"
- "Mailbox: %s\r\n"
- "NewMessages: %d\r\n"
- "OldMessages: %d\r\n"
- "\r\n",
- idText,mailbox, newmsgs, oldmsgs);
- return 0;
-}
-
-static char mandescr_extensionstate[] =
-"Description: Report the extension state for given extension.\n"
-" If the extension has a hint, will use devicestate to check\n"
-" the status of the device connected to the extension.\n"
-"Variables: (Names marked with * are required)\n"
-" *Exten: Extension to check state on\n"
-" *Context: Context for extension\n"
-" ActionId: Optional ID for this transaction\n"
-"Will return an \"Extension Status\" message.\n"
-"The response will include the hint for the extension and the status.\n";
-
-static int action_extensionstate(struct mansession *s, struct message *m)
-{
- char *exten = astman_get_header(m, "Exten");
- char *context = astman_get_header(m, "Context");
- char *id = astman_get_header(m,"ActionID");
- char idText[256] = "";
- char hint[256] = "";
- int status;
- if (ast_strlen_zero(exten)) {
- astman_send_error(s, m, "Extension not specified");
- return 0;
- }
- if (ast_strlen_zero(context))
- context = "default";
- status = ast_extension_state(NULL, context, exten);
- ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten);
- if (!ast_strlen_zero(id)) {
- snprintf(idText,256,"ActionID: %s\r\n",id);
- }
- ast_cli(s->fd, "Response: Success\r\n"
- "%s"
- "Message: Extension Status\r\n"
- "Exten: %s\r\n"
- "Context: %s\r\n"
- "Hint: %s\r\n"
- "Status: %d\r\n\r\n",
- idText,exten, context, hint, status);
- return 0;
-}
-
-static char mandescr_timeout[] =
-"Description: Hangup a channel after a certain time.\n"
-"Variables: (Names marked with * are required)\n"
-" *Channel: Channel name to hangup\n"
-" *Timeout: Maximum duration of the call (sec)\n"
-"Acknowledges set time with 'Timeout Set' message\n";
-
-static int action_timeout(struct mansession *s, struct message *m)
-{
- struct ast_channel *c = NULL;
- char *name = astman_get_header(m, "Channel");
- int timeout = atoi(astman_get_header(m, "Timeout"));
- if (ast_strlen_zero(name)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- if (!timeout) {
- astman_send_error(s, m, "No timeout specified");
- return 0;
- }
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- ast_channel_setwhentohangup(c, timeout);
- ast_mutex_unlock(&c->lock);
- astman_send_ack(s, m, "Timeout Set");
- return 0;
-}
-
-static int process_message(struct mansession *s, struct message *m)
-{
- char action[80] = "";
- struct manager_action *tmp = first_action;
- char *id = astman_get_header(m,"ActionID");
- char idText[256] = "";
- char iabuf[INET_ADDRSTRLEN];
-
- ast_copy_string(action, astman_get_header(m, "Action"), sizeof(action));
- ast_log( LOG_DEBUG, "Manager received command '%s'\n", action );
-
- if (ast_strlen_zero(action)) {
- astman_send_error(s, m, "Missing action in request");
- return 0;
- }
- if (!ast_strlen_zero(id)) {
- snprintf(idText,256,"ActionID: %s\r\n",id);
- }
- if (!s->authenticated) {
- if (!strcasecmp(action, "Challenge")) {
- char *authtype;
- authtype = astman_get_header(m, "AuthType");
- if (!strcasecmp(authtype, "MD5")) {
- if (ast_strlen_zero(s->challenge))
- snprintf(s->challenge, sizeof(s->challenge), "%d", rand());
- ast_mutex_lock(&s->__lock);
- ast_cli(s->fd, "Response: Success\r\n"
- "%s"
- "Challenge: %s\r\n\r\n",
- idText,s->challenge);
- ast_mutex_unlock(&s->__lock);
- return 0;
- } else {
- astman_send_error(s, m, "Must specify AuthType");
- return 0;
- }
- } else if (!strcasecmp(action, "Login")) {
- if (authenticate(s, m)) {
- sleep(1);
- astman_send_error(s, m, "Authentication failed");
- return -1;
- } else {
- s->authenticated = 1;
- if (option_verbose > 1) {
- if ( displayconnects ) {
- ast_verbose(VERBOSE_PREFIX_2 "Manager '%s' logged on from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
- }
- }
- ast_log(LOG_EVENT, "Manager '%s' logged on from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
- astman_send_ack(s, m, "Authentication accepted");
- }
- } else if (!strcasecmp(action, "Logoff")) {
- astman_send_ack(s, m, "See ya");
- return -1;
- } else
- astman_send_error(s, m, "Authentication Required");
- } else {
- int ret=0;
- struct eventqent *eqe;
- ast_mutex_lock(&s->__lock);
- s->busy = 1;
- ast_mutex_unlock(&s->__lock);
- while( tmp ) {
- if (!strcasecmp(action, tmp->action)) {
- if ((s->writeperm & tmp->authority) == tmp->authority) {
- if (tmp->func(s, m))
- ret = -1;
- } else {
- astman_send_error(s, m, "Permission denied");
- }
- break;
- }
- tmp = tmp->next;
- }
- if (!tmp)
- astman_send_error(s, m, "Invalid/unknown command");
- ast_mutex_lock(&s->__lock);
- s->busy = 0;
- while(s->eventq) {
- if (ast_carefulwrite(s->fd, s->eventq->eventdata, strlen(s->eventq->eventdata), s->writetimeout) < 0) {
- ret = -1;
- break;
- }
- eqe = s->eventq;
- s->eventq = s->eventq->next;
- free(eqe);
- }
- ast_mutex_unlock(&s->__lock);
- return ret;
- }
- return 0;
-}
-
-static int get_input(struct mansession *s, char *output)
-{
- /* output must have at least sizeof(s->inbuf) space */
- int res;
- int x;
- struct pollfd fds[1];
- char iabuf[INET_ADDRSTRLEN];
- for (x=1;x<s->inlen;x++) {
- if ((s->inbuf[x] == '\n') && (s->inbuf[x-1] == '\r')) {
- /* Copy output data up to and including \r\n */
- memcpy(output, s->inbuf, x + 1);
- /* Add trailing \0 */
- output[x+1] = '\0';
- /* Move remaining data back to the front */
- memmove(s->inbuf, s->inbuf + x + 1, s->inlen - x);
- s->inlen -= (x + 1);
- return 1;
- }
- }
- if (s->inlen >= sizeof(s->inbuf) - 1) {
- ast_log(LOG_WARNING, "Dumping long line with no return from %s: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), s->inbuf);
- s->inlen = 0;
- }
- fds[0].fd = s->fd;
- fds[0].events = POLLIN;
- do {
- res = poll(fds, 1, -1);
- if (res < 0) {
- if (errno == EINTR) {
- if (s->dead)
- return -1;
- continue;
- }
- ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
- return -1;
- } else if (res > 0) {
- ast_mutex_lock(&s->__lock);
- res = read(s->fd, s->inbuf + s->inlen, sizeof(s->inbuf) - 1 - s->inlen);
- ast_mutex_unlock(&s->__lock);
- if (res < 1)
- return -1;
- break;
- }
- } while(1);
- s->inlen += res;
- s->inbuf[s->inlen] = '\0';
- return 0;
-}
-
-static void *session_do(void *data)
-{
- struct mansession *s = data;
- struct message m;
- char iabuf[INET_ADDRSTRLEN];
- int res;
-
- ast_mutex_lock(&s->__lock);
- ast_cli(s->fd, "Asterisk Call Manager/1.0\r\n");
- ast_mutex_unlock(&s->__lock);
- memset(&m, 0, sizeof(m));
- for (;;) {
- res = get_input(s, m.headers[m.hdrcount]);
- if (res > 0) {
- /* Strip trailing \r\n */
- if (strlen(m.headers[m.hdrcount]) < 2)
- continue;
- m.headers[m.hdrcount][strlen(m.headers[m.hdrcount]) - 2] = '\0';
- if (ast_strlen_zero(m.headers[m.hdrcount])) {
- if (process_message(s, &m))
- break;
- memset(&m, 0, sizeof(m));
- } else if (m.hdrcount < AST_MAX_MANHEADERS - 1)
- m.hdrcount++;
- } else if (res < 0)
- break;
- }
- if (s->authenticated) {
- if (option_verbose > 1) {
- if (displayconnects)
- ast_verbose(VERBOSE_PREFIX_2 "Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
- }
- ast_log(LOG_EVENT, "Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
- } else {
- if (option_verbose > 1) {
- if ( displayconnects )
- ast_verbose(VERBOSE_PREFIX_2 "Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
- }
- ast_log(LOG_EVENT, "Failed attempt from %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
- }
- destroy_session(s);
- return NULL;
-}
-
-static void *accept_thread(void *ignore)
-{
- int as;
- struct sockaddr_in sin;
- socklen_t sinlen;
- struct mansession *s;
- struct protoent *p;
- int arg = 1;
- int flags;
- pthread_attr_t attr;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- for (;;) {
- sinlen = sizeof(sin);
- as = accept(asock, (struct sockaddr *)&sin, &sinlen);
- if (as < 0) {
- ast_log(LOG_NOTICE, "Accept returned -1: %s\n", strerror(errno));
- continue;
- }
- p = getprotobyname("tcp");
- if (p) {
- if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
- ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
- }
- }
- s = malloc(sizeof(struct mansession));
- if (!s) {
- ast_log(LOG_WARNING, "Failed to allocate management session: %s\n", strerror(errno));
- continue;
- }
- memset(s, 0, sizeof(struct mansession));
- memcpy(&s->sin, &sin, sizeof(sin));
- s->writetimeout = 100;
-
- if(! block_sockets) {
- /* For safety, make sure socket is non-blocking */
- flags = fcntl(as, F_GETFL);
- fcntl(as, F_SETFL, flags | O_NONBLOCK);
- }
- ast_mutex_init(&s->__lock);
- s->fd = as;
- s->send_events = -1;
- ast_mutex_lock(&sessionlock);
- s->next = sessions;
- sessions = s;
- ast_mutex_unlock(&sessionlock);
- if (ast_pthread_create(&s->t, &attr, session_do, s))
- destroy_session(s);
- }
- pthread_attr_destroy(&attr);
- return NULL;
-}
-
-static int append_event(struct mansession *s, const char *str)
-{
- struct eventqent *tmp, *prev=NULL;
- tmp = malloc(sizeof(struct eventqent) + strlen(str));
- if (tmp) {
- tmp->next = NULL;
- strcpy(tmp->eventdata, str);
- if (s->eventq) {
- prev = s->eventq;
- while(prev->next)
- prev = prev->next;
- prev->next = tmp;
- } else {
- s->eventq = tmp;
- }
- return 0;
- }
- return -1;
-}
-
-/*! \brief manager_event: Send AMI event to client */
-int manager_event(int category, char *event, char *fmt, ...)
-{
- struct mansession *s;
- char auth[80];
- char tmp[4096] = "";
- char *tmp_next = tmp;
- size_t tmp_left = sizeof(tmp) - 2;
- va_list ap;
-
- ast_mutex_lock(&sessionlock);
- for (s = sessions; s; s = s->next) {
- if ((s->readperm & category) != category)
- continue;
-
- if ((s->send_events & category) != category)
- continue;
-
- if (ast_strlen_zero(tmp)) {
- ast_build_string(&tmp_next, &tmp_left, "Event: %s\r\nPrivilege: %s\r\n",
- event, authority_to_str(category, auth, sizeof(auth)));
- va_start(ap, fmt);
- ast_build_string_va(&tmp_next, &tmp_left, fmt, ap);
- va_end(ap);
- *tmp_next++ = '\r';
- *tmp_next++ = '\n';
- *tmp_next = '\0';
- }
-
- ast_mutex_lock(&s->__lock);
- if (s->busy) {
- append_event(s, tmp);
- } else if (!s->dead) {
- if (ast_carefulwrite(s->fd, tmp, tmp_next - tmp, s->writetimeout) < 0) {
- ast_log(LOG_WARNING, "Disconnecting slow (or gone) manager session!\n");
- s->dead = 1;
- pthread_kill(s->t, SIGURG);
- }
- }
- ast_mutex_unlock(&s->__lock);
- }
- ast_mutex_unlock(&sessionlock);
-
- return 0;
-}
-
-int ast_manager_unregister( char *action )
-{
- struct manager_action *cur = first_action, *prev = first_action;
-
- ast_mutex_lock(&actionlock);
- while( cur ) {
- if (!strcasecmp(action, cur->action)) {
- prev->next = cur->next;
- free(cur);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Manager unregistered action %s\n", action);
- ast_mutex_unlock(&actionlock);
- return 0;
- }
- prev = cur;
- cur = cur->next;
- }
- ast_mutex_unlock(&actionlock);
- return 0;
-}
-
-static int manager_state_cb(char *context, char *exten, int state, void *data)
-{
- /* Notify managers of change */
- manager_event(EVENT_FLAG_CALL, "ExtensionStatus", "Exten: %s\r\nContext: %s\r\nStatus: %d\r\n", exten, context, state);
- return 0;
-}
-
-static int ast_manager_register_struct(struct manager_action *act)
-{
- struct manager_action *cur = first_action, *prev = NULL;
- int ret;
-
- ast_mutex_lock(&actionlock);
- while(cur) { /* Walk the list of actions */
- ret = strcasecmp(cur->action, act->action);
- if (ret == 0) {
- ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->action);
- ast_mutex_unlock(&actionlock);
- return -1;
- } else if (ret > 0) {
- /* Insert these alphabetically */
- if (prev) {
- act->next = prev->next;
- prev->next = act;
- } else {
- act->next = first_action;
- first_action = act;
- }
- break;
- }
- prev = cur;
- cur = cur->next;
- }
-
- if (!cur) {
- if (prev)
- prev->next = act;
- else
- first_action = act;
- act->next = NULL;
- }
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Manager registered action %s\n", act->action);
- ast_mutex_unlock(&actionlock);
- return 0;
-}
-
-/*! \brief register a new command with manager, including online help. This is
- the preferred way to register a manager command */
-int ast_manager_register2(const char *action, int auth, int (*func)(struct mansession *s, struct message *m), const char *synopsis, const char *description)
-{
- struct manager_action *cur;
-
- cur = malloc(sizeof(struct manager_action));
- if (!cur) {
- ast_log(LOG_WARNING, "Manager: out of memory trying to register action\n");
- return -1;
- }
- cur->action = action;
- cur->authority = auth;
- cur->func = func;
- cur->synopsis = synopsis;
- cur->description = description;
- cur->next = NULL;
-
- ast_manager_register_struct(cur);
-
- return 0;
-}
-/*! @}
- END Doxygen group */
-
-static int registered = 0;
-
-int init_manager(void)
-{
- struct ast_config *cfg;
- char *val;
- int oldportno = portno;
- static struct sockaddr_in ba;
- int x = 1;
- if (!registered) {
- /* Register default actions */
- ast_manager_register2("Ping", 0, action_ping, "Keepalive command", mandescr_ping);
- ast_manager_register2("Events", 0, action_events, "Control Event Flow", mandescr_events);
- ast_manager_register2("Logoff", 0, action_logoff, "Logoff Manager", mandescr_logoff);
- ast_manager_register2("Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel", mandescr_hangup);
- ast_manager_register("Status", EVENT_FLAG_CALL, action_status, "Lists channel status" );
- ast_manager_register2("Setvar", EVENT_FLAG_CALL, action_setvar, "Set Channel Variable", mandescr_setvar );
- ast_manager_register2("Getvar", EVENT_FLAG_CALL, action_getvar, "Gets a Channel Variable", mandescr_getvar );
- ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect );
- ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate);
- ast_manager_register2("Command", EVENT_FLAG_COMMAND, action_command, "Execute Asterisk CLI Command", mandescr_command );
- ast_manager_register2("ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status", mandescr_extensionstate );
- ast_manager_register2("AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout", mandescr_timeout );
- ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus );
- ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount );
- ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands);
-
- ast_cli_register(&show_mancmd_cli);
- ast_cli_register(&show_mancmds_cli);
- ast_cli_register(&show_manconn_cli);
- ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
- registered = 1;
- }
- portno = DEFAULT_MANAGER_PORT;
- displayconnects = 1;
- cfg = ast_config_load("manager.conf");
- if (!cfg) {
- ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf. Call management disabled.\n");
- return 0;
- }
- memset(&ba, 0, sizeof(ba));
- val = ast_variable_retrieve(cfg, "general", "enabled");
- if (val)
- enabled = ast_true(val);
-
- val = ast_variable_retrieve(cfg, "general", "block-sockets");
- if(val)
- block_sockets = ast_true(val);
-
- if ((val = ast_variable_retrieve(cfg, "general", "port"))) {
- if (sscanf(val, "%d", &portno) != 1) {
- ast_log(LOG_WARNING, "Invalid port number '%s'\n", val);
- portno = DEFAULT_MANAGER_PORT;
- }
- } else if ((val = ast_variable_retrieve(cfg, "general", "portno"))) {
- if (sscanf(val, "%d", &portno) != 1) {
- ast_log(LOG_WARNING, "Invalid port number '%s'\n", val);
- portno = DEFAULT_MANAGER_PORT;
- }
- ast_log(LOG_NOTICE, "Use of portno in manager.conf deprecated. Please use 'port=%s' instead.\n", val);
- }
- /* Parsing the displayconnects */
- if ((val = ast_variable_retrieve(cfg, "general", "displayconnects"))) {
- displayconnects = ast_true(val);;
- }
-
-
- ba.sin_family = AF_INET;
- ba.sin_port = htons(portno);
- memset(&ba.sin_addr, 0, sizeof(ba.sin_addr));
-
- if ((val = ast_variable_retrieve(cfg, "general", "bindaddr"))) {
- if (!inet_aton(val, &ba.sin_addr)) {
- ast_log(LOG_WARNING, "Invalid address '%s' specified, using 0.0.0.0\n", val);
- memset(&ba.sin_addr, 0, sizeof(ba.sin_addr));
- }
- }
-
- if ((asock > -1) && ((portno != oldportno) || !enabled)) {
-#if 0
- /* Can't be done yet */
- close(asock);
- asock = -1;
-#else
- ast_log(LOG_WARNING, "Unable to change management port / enabled\n");
-#endif
- }
- ast_config_destroy(cfg);
-
- /* If not enabled, do nothing */
- if (!enabled) {
- return 0;
- }
- if (asock < 0) {
- asock = socket(AF_INET, SOCK_STREAM, 0);
- if (asock < 0) {
- ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
- return -1;
- }
- setsockopt(asock, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
- if (bind(asock, (struct sockaddr *)&ba, sizeof(ba))) {
- ast_log(LOG_WARNING, "Unable to bind socket: %s\n", strerror(errno));
- close(asock);
- asock = -1;
- return -1;
- }
- if (listen(asock, 2)) {
- ast_log(LOG_WARNING, "Unable to listen on socket: %s\n", strerror(errno));
- close(asock);
- asock = -1;
- return -1;
- }
- if (option_verbose)
- ast_verbose("Asterisk Management interface listening on port %d\n", portno);
- ast_pthread_create(&t, NULL, accept_thread, NULL);
- }
- return 0;
-}
-
-int reload_manager(void)
-{
- manager_event(EVENT_FLAG_SYSTEM, "Reload", "Message: Reload Requested\r\n");
- return init_manager();
-}
diff --git a/1.2-netsec/md5.c b/1.2-netsec/md5.c
deleted file mode 100644
index 367e8725c..000000000
--- a/1.2-netsec/md5.c
+++ /dev/null
@@ -1,266 +0,0 @@
-
-/*!\file
-\brief MD5 checksum routines used for authentication. Not covered by GPL, but
- in the public domain as per the copyright below */
-
-/*
- * This code implements the MD5 message-digest algorithm.
- * The algorithm is due to Ron Rivest. This code was
- * written by Colin Plumb in 1993, no copyright is claimed.
- * This code is in the public domain; do with it what you wish.
- *
- * Equivalent code is available from RSA Data Security, Inc.
- * This code has been tested against that, and is equivalent,
- * except that you don't need to include two pages of legalese
- * with every copy.
- *
- * To compute the message digest of a chunk of bytes, declare an
- * MD5Context structure, pass it to MD5Init, call MD5Update as
- * needed on buffers full of bytes, and then call MD5Final, which
- * will fill a supplied 16-byte array with the digest.
- */
-#include <string.h> /* for memcpy() */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/endian.h"
-#include "asterisk/md5.h"
-
-# if __BYTE_ORDER == __BIG_ENDIAN
-# define HIGHFIRST 1
-# endif
-#ifndef HIGHFIRST
-#define byteReverse(buf, len) /* Nothing */
-#else
-void byteReverse(unsigned char *buf, unsigned longs);
-
-#ifndef ASM_MD5
-/*
- * Note: this code is harmless on little-endian machines.
- */
-void byteReverse(unsigned char *buf, unsigned longs)
-{
- uint32_t t;
- do {
- t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
- ((unsigned) buf[1] << 8 | buf[0]);
- *(uint32_t *) buf = t;
- buf += 4;
- } while (--longs);
-}
-#endif
-#endif
-
-/*
- * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
- * initialization constants.
- */
-void MD5Init(struct MD5Context *ctx)
-{
- ctx->buf[0] = 0x67452301;
- ctx->buf[1] = 0xefcdab89;
- ctx->buf[2] = 0x98badcfe;
- ctx->buf[3] = 0x10325476;
-
- ctx->bits[0] = 0;
- ctx->bits[1] = 0;
-}
-
-/*
- * Update context to reflect the concatenation of another buffer full
- * of bytes.
- */
-void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
-{
- uint32_t t;
-
- /* Update bitcount */
-
- t = ctx->bits[0];
- if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
- ctx->bits[1]++; /* Carry from low to high */
- ctx->bits[1] += len >> 29;
-
- t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
-
- /* Handle any leading odd-sized chunks */
-
- if (t) {
- unsigned char *p = (unsigned char *) ctx->in + t;
-
- t = 64 - t;
- if (len < t) {
- memcpy(p, buf, len);
- return;
- }
- memcpy(p, buf, t);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
- buf += t;
- len -= t;
- }
- /* Process data in 64-byte chunks */
-
- while (len >= 64) {
- memcpy(ctx->in, buf, 64);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
- buf += 64;
- len -= 64;
- }
-
- /* Handle any remaining bytes of data. */
-
- memcpy(ctx->in, buf, len);
-}
-
-/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern
- * 1 0* (64-bit count of bits processed, MSB-first)
- */
-void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
-{
- unsigned count;
- unsigned char *p;
-
- /* Compute number of bytes mod 64 */
- count = (ctx->bits[0] >> 3) & 0x3F;
-
- /* Set the first char of padding to 0x80. This is safe since there is
- always at least one byte free */
- p = ctx->in + count;
- *p++ = 0x80;
-
- /* Bytes of padding needed to make 64 bytes */
- count = 64 - 1 - count;
-
- /* Pad out to 56 mod 64 */
- if (count < 8) {
- /* Two lots of padding: Pad the first block to 64 bytes */
- memset(p, 0, count);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
-
- /* Now fill the next block with 56 bytes */
- memset(ctx->in, 0, 56);
- } else {
- /* Pad block to 56 bytes */
- memset(p, 0, count - 8);
- }
- byteReverse(ctx->in, 14);
-
- /* Append length in bits and transform */
- ((uint32_t *) ctx->in)[14] = ctx->bits[0];
- ((uint32_t *) ctx->in)[15] = ctx->bits[1];
-
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
- byteReverse((unsigned char *) ctx->buf, 4);
- memcpy(digest, ctx->buf, 16);
- memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
-}
-
-#ifndef ASM_MD5
-
-/* The four core functions - F1 is optimized somewhat */
-
-/* #define F1(x, y, z) (x & y | ~x & z) */
-#define F1(x, y, z) (z ^ (x & (y ^ z)))
-#define F2(x, y, z) F1(z, x, y)
-#define F3(x, y, z) (x ^ y ^ z)
-#define F4(x, y, z) (y ^ (x | ~z))
-
-/* This is the central step in the MD5 algorithm. */
-#define MD5STEP(f, w, x, y, z, data, s) \
- ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
-
-/*
- * The core of the MD5 algorithm, this alters an existing MD5 hash to
- * reflect the addition of 16 longwords of new data. MD5Update blocks
- * the data and converts bytes into longwords for this routine.
- */
-void MD5Transform(uint32_t buf[4], uint32_t const in[16])
-{
- register uint32_t a, b, c, d;
-
- a = buf[0];
- b = buf[1];
- c = buf[2];
- d = buf[3];
-
- MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
- MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
- MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
- MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
- MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
- MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
- MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
- MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
- MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
- MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
- MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
- MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
- MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
- MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
- MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
- MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
-
- MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
- MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
- MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
- MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
- MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
- MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
- MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
- MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
- MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
- MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
- MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
- MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
- MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
- MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
- MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
- MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
-
- MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
- MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
- MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
- MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
- MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
- MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
- MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
- MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
- MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
- MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
- MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
- MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
- MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
- MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
- MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
- MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
-
- MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
- MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
- MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
- MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
- MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
- MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
- MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
- MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
- MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
- MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
- MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
- MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
- MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
- MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
- MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
- MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
-
- buf[0] += a;
- buf[1] += b;
- buf[2] += c;
- buf[3] += d;
-}
-
-#endif
diff --git a/1.2-netsec/mkpkgconfig b/1.2-netsec/mkpkgconfig
deleted file mode 100755
index 0ae2a24bf..000000000
--- a/1.2-netsec/mkpkgconfig
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/bash
-PPATH=$1
-## Make sure we were called from Makefile
-
-if [ "x$ASTERISKVERSIONNUM" = "x" ]; then
- echo " ** Do not call this script directly"
- exit
-fi
-
-## Create a pkgconfig spec file for 3rd party modules (pkg-config asterisk --cflags)
-
-if [ ! -d $PPATH ]; then
- exit
-fi
-
-## Clean out CFLAGS for the spec file.
-
-LOCAL_CFLAGS=`echo $CFLAGS | sed -e 's/\s*-pipe\s*//g' | sed -e 's/-[Wmp]\S*\s*//g' | \
- sed -r -e 's/-I(include|\.\.\/include) //g' | \
- sed -e 's/-DINSTALL_PREFIX=\S* //g' | \
- sed -r -e 's/-DASTERISK_VERSION=\S* //g' | \
- sed -r -e 's/-DAST(ETCDIR|LIBDIR|VARLIBDIR|VARRUNDIR|SPOOLDIR|LOGDIR|CONFPATH|MODDIR|AGIDIR)=\S* //g'`
-
-
-cat <<EOF > $PPATH/asterisk.pc
-install_prefix=$INSTALL_PREFIX
-version_number=$ASTERISKVERSIONNUM
-etcdir=$ASTETCDIR
-libdir=$ASTLIBDIR
-varlibdir=$ASTVARLIBDIR
-varrundir=$ASTVARRUNDIR
-spooldir=$ASTSPOOLDIR
-logdir=$ASTLOGDIR
-confpath=$ASTCONFPATH
-moddir=$MODULES_DIR
-agidir=$AGI_DIR
-
-Name: asterisk
-Description: Open Source PBX and telephony toolkit
-Version: $ASTERISKVERSION
-Libs: $LIBS
-Cflags: $LOCAL_CFLAGS
-EOF
diff --git a/1.2-netsec/muted.c b/1.2-netsec/muted.c
deleted file mode 100644
index 600892cad..000000000
--- a/1.2-netsec/muted.c
+++ /dev/null
@@ -1,682 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Updated for Mac OSX CoreAudio
- * by Josh Roberson <josh@asteriasgi.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- * \brief Mute Daemon
- *
- * \note Specially written for Malcolm Davenport, but I think I'll use it too
- * Connects to the Asterisk Manager Interface, AMI, and listens for events
- * on certain devices. If a phone call is connected to one of the devices (phones)
- * the local sound is muted to a lower volume during the call.
- *
- */
-
-#ifndef __Darwin__
-#include <linux/soundcard.h>
-#else
-#include <CoreAudio/AudioHardware.h>
-#endif
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-static char *config = "/etc/muted.conf";
-
-static char host[256] = "";
-static char user[256] = "";
-static char pass[256] = "";
-static int smoothfade = 0;
-static int mutelevel = 20;
-static int muted = 0;
-static int needfork = 1;
-static int debug = 0;
-static int stepsize = 3;
-#ifndef __Darwin__
-static int mixchan = SOUND_MIXER_VOLUME;
-#endif
-
-struct subchannel {
- char *name;
- struct subchannel *next;
-};
-
-static struct channel {
- char *tech;
- char *location;
- struct channel *next;
- struct subchannel *subs;
-} *channels;
-
-static void add_channel(char *tech, char *location)
-{
- struct channel *chan;
- chan = malloc(sizeof(struct channel));
- if (chan) {
- memset(chan, 0, sizeof(struct channel));
- chan->tech = strdup(tech);
- chan->location = strdup(location);
- chan->next = channels;
- channels = chan;
- }
-
-}
-
-static int load_config(void)
-{
- FILE *f;
- char buf[1024];
- char *val;
- char *val2;
- int lineno=0;
- int x;
- f = fopen(config, "r");
- if (!f) {
- fprintf(stderr, "Unable to open config file '%s': %s\n", config, strerror(errno));
- return -1;
- }
- while(!feof(f)) {
- fgets(buf, sizeof(buf), f);
- if (!feof(f)) {
- lineno++;
- val = strchr(buf, '#');
- if (val) *val = '\0';
- while(strlen(buf) && (buf[strlen(buf) - 1] < 33))
- buf[strlen(buf) - 1] = '\0';
- if (!strlen(buf))
- continue;
- val = buf;
- while(*val) {
- if (*val < 33)
- break;
- val++;
- }
- if (*val) {
- *val = '\0';
- val++;
- while(*val && (*val < 33)) val++;
- }
- if (!strcasecmp(buf, "host")) {
- if (val && strlen(val))
- strncpy(host, val, sizeof(host) - 1);
- else
- fprintf(stderr, "host needs an argument (the host) at line %d\n", lineno);
- } else if (!strcasecmp(buf, "user")) {
- if (val && strlen(val))
- strncpy(user, val, sizeof(user) - 1);
- else
- fprintf(stderr, "user needs an argument (the user) at line %d\n", lineno);
- } else if (!strcasecmp(buf, "pass")) {
- if (val && strlen(val))
- strncpy(pass, val, sizeof(pass) - 1);
- else
- fprintf(stderr, "pass needs an argument (the password) at line %d\n", lineno);
- } else if (!strcasecmp(buf, "smoothfade")) {
- smoothfade = 1;
- } else if (!strcasecmp(buf, "mutelevel")) {
- if (val && (sscanf(val, "%d", &x) == 1) && (x > -1) && (x < 101)) {
- mutelevel = x;
- } else
- fprintf(stderr, "mutelevel must be a number from 0 (most muted) to 100 (no mute) at line %d\n", lineno);
- } else if (!strcasecmp(buf, "channel")) {
- if (val && strlen(val)) {
- val2 = strchr(val, '/');
- if (val2) {
- *val2 = '\0';
- val2++;
- add_channel(val, val2);
- } else
- fprintf(stderr, "channel needs to be of the format Tech/Location at line %d\n", lineno);
- } else
- fprintf(stderr, "channel needs an argument (the channel) at line %d\n", lineno);
- } else {
- fprintf(stderr, "ignoring unknown keyword '%s'\n", buf);
- }
- }
- }
- fclose(f);
- if (!strlen(host))
- fprintf(stderr, "no 'host' specification in config file\n");
- else if (!strlen(user))
- fprintf(stderr, "no 'user' specification in config file\n");
- else if (!channels)
- fprintf(stderr, "no 'channel' specifications in config file\n");
- else
- return 0;
- return -1;
-}
-
-static FILE *astf;
-#ifndef __Darwin__
-static int mixfd;
-
-static int open_mixer(void)
-{
- mixfd = open("/dev/mixer", O_RDWR);
- if (mixfd < 0) {
- fprintf(stderr, "Unable to open /dev/mixer: %s\n", strerror(errno));
- return -1;
- }
- return 0;
-}
-#endif /* !__Darwin */
-
-/*! Connect to the asterisk manager interface */
-static int connect_asterisk(void)
-{
- int sock;
- struct hostent *hp;
- char *ports;
- int port = 5038;
- struct sockaddr_in sin;
-
- ports = strchr(host, ':');
- if (ports) {
- *ports = '\0';
- ports++;
- if ((sscanf(ports, "%d", &port) != 1) || (port < 1) || (port > 65535)) {
- fprintf(stderr, "'%s' is not a valid port number in the hostname\n", ports);
- return -1;
- }
- }
- hp = gethostbyname(host);
- if (!hp) {
- fprintf(stderr, "Can't find host '%s'\n", host);
- return -1;
- }
- sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock < 0) {
- fprintf(stderr, "Failed to create socket: %s\n", strerror(errno));
- return -1;
- }
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
- memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
- if (connect(sock, &sin, sizeof(sin))) {
- fprintf(stderr, "Failed to connect to '%s' port '%d': %s\n", host, port, strerror(errno));
- close(sock);
- return -1;
- }
- astf = fdopen(sock, "r+");
- if (!astf) {
- fprintf(stderr, "fdopen failed: %s\n", strerror(errno));
- close(sock);
- return -1;
- }
- return 0;
-}
-
-static char *get_line(void)
-{
- static char buf[1024];
- if (fgets(buf, sizeof(buf), astf)) {
- while(strlen(buf) && (buf[strlen(buf) - 1] < 33))
- buf[strlen(buf) - 1] = '\0';
- return buf;
- } else
- return NULL;
-}
-
-/*! Login to the asterisk manager interface */
-static int login_asterisk(void)
-{
- char *welcome;
- char *resp;
- if (!(welcome = get_line())) {
- fprintf(stderr, "disconnected (1)\n");
- return -1;
- }
- fprintf(astf,
- "Action: Login\r\n"
- "Username: %s\r\n"
- "Secret: %s\r\n\r\n", user, pass);
- if (!(welcome = get_line())) {
- fprintf(stderr, "disconnected (2)\n");
- return -1;
- }
- if (strcasecmp(welcome, "Response: Success")) {
- fprintf(stderr, "login failed ('%s')\n", welcome);
- return -1;
- }
- /* Eat the rest of the event */
- while((resp = get_line()) && strlen(resp));
- if (!resp) {
- fprintf(stderr, "disconnected (3)\n");
- return -1;
- }
- fprintf(astf,
- "Action: Status\r\n\r\n");
- if (!(welcome = get_line())) {
- fprintf(stderr, "disconnected (4)\n");
- return -1;
- }
- if (strcasecmp(welcome, "Response: Success")) {
- fprintf(stderr, "status failed ('%s')\n", welcome);
- return -1;
- }
- /* Eat the rest of the event */
- while((resp = get_line()) && strlen(resp));
- if (!resp) {
- fprintf(stderr, "disconnected (5)\n");
- return -1;
- }
- return 0;
-}
-
-static struct channel *find_channel(char *channel)
-{
- char tmp[256] = "";
- char *s, *t;
- struct channel *chan;
- strncpy(tmp, channel, sizeof(tmp) - 1);
- s = strchr(tmp, '/');
- if (s) {
- *s = '\0';
- s++;
- t = strrchr(s, '-');
- if (t) {
- *t = '\0';
- }
- if (debug)
- printf("Searching for '%s' tech, '%s' location\n", tmp, s);
- chan = channels;
- while(chan) {
- if (!strcasecmp(chan->tech, tmp) && !strcasecmp(chan->location, s)) {
- if (debug)
- printf("Found '%s'/'%s'\n", chan->tech, chan->location);
- break;
- }
- chan = chan->next;
- }
- } else
- chan = NULL;
- return chan;
-}
-
-#ifndef __Darwin__
-static int getvol(void)
-{
- int vol;
-
- if (ioctl(mixfd, MIXER_READ(mixchan), &vol)) {
-#else
-static float getvol(void)
-{
- float volumeL, volumeR, vol;
- OSStatus err;
- AudioDeviceID device;
- UInt32 size;
- UInt32 channels[2];
-
- size = sizeof(device);
- err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &device);
- size = sizeof(channels);
- if (!err)
- err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
- size = sizeof(vol);
- if (!err)
- err = AudioDeviceGetProperty(device, channels[0], false, kAudioDevicePropertyVolumeScalar, &size, &volumeL);
- if (!err)
- err = AudioDeviceGetProperty(device, channels[1], false, kAudioDevicePropertyVolumeScalar, &size, &volumeR);
- if (!err)
- vol = (volumeL < volumeR) ? volumeR : volumeL;
- else {
-#endif
- fprintf(stderr, "Unable to read mixer volume: %s\n", strerror(errno));
- return -1;
- }
- return vol;
-}
-
-#ifndef __Darwin__
-static int setvol(int vol)
-#else
-static int setvol(float vol)
-#endif
-{
-#ifndef __Darwin__
- if (ioctl(mixfd, MIXER_WRITE(mixchan), &vol)) {
-#else
- float volumeL = vol;
- float volumeR = vol;
- OSStatus err;
- AudioDeviceID device;
- UInt32 size;
- UInt32 channels[2];
-
- size = sizeof(device);
- err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &device);
- size = sizeof(channels);
- err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
- size = sizeof(vol);
- if (!err)
- err = AudioDeviceSetProperty(device, 0, channels[0], false, kAudioDevicePropertyVolumeScalar, size, &volumeL);
- if (!err)
- err = AudioDeviceSetProperty(device, 0, channels[1], false, kAudioDevicePropertyVolumeScalar, size, &volumeR);
- if (err) {
-#endif
-
- fprintf(stderr, "Unable to write mixer volume: %s\n", strerror(errno));
- return -1;
-
- }
- return 0;
-}
-
-#ifndef __Darwin__
-static int oldvol = 0;
-static int mutevol = 0;
-#else
-static float oldvol = 0;
-static float mutevol = 0;
-#endif
-
-#ifndef __Darwin__
-static int mutedlevel(int orig, int mutelevel)
-{
- int l = orig >> 8;
- int r = orig & 0xff;
- l = (float)(mutelevel) * (float)(l) / 100.0;
- r = (float)(mutelevel) * (float)(r) / 100.0;
-
- return (l << 8) | r;
-#else
-static float mutedlevel(float orig, float mutelevel)
-{
- float master = orig;
- master = mutelevel * master / 100.0;
- return master;
-#endif
-
-}
-
-static void mute(void)
-{
-#ifndef __Darwin__
- int vol;
- int start;
- int x;
-#else
- float vol;
- float start = 1.0;
- float x;
-#endif
- vol = getvol();
- oldvol = vol;
- if (smoothfade)
-#ifdef __Darwin__
- start = mutelevel;
-#else
- start = 100;
- else
- start = mutelevel;
-#endif
- for (x=start;x>=mutelevel;x-=stepsize) {
- mutevol = mutedlevel(vol, x);
- setvol(mutevol);
- /* Wait 0.01 sec */
- usleep(10000);
- }
- mutevol = mutedlevel(vol, mutelevel);
- setvol(mutevol);
- if (debug)
-#ifdef __Darwin__
- printf("Mute from '%f' to '%f'!\n", oldvol, mutevol);
-#else
- printf("Mute from '%04x' to '%04x'!\n", oldvol, mutevol);
-#endif
- muted = 1;
-}
-
-static void unmute(void)
-{
-#ifdef __Darwin__
- float vol;
- float start;
- float x;
-#else
- int vol;
- int start;
- int x;
-#endif
- vol = getvol();
- if (debug)
-#ifdef __Darwin__
- printf("Unmute from '%f' (should be '%f') to '%f'!\n", vol, mutevol, oldvol);
- mutevol = vol;
- if (vol == mutevol) {
-#else
- printf("Unmute from '%04x' (should be '%04x') to '%04x'!\n", vol, mutevol, oldvol);
- if ((int)vol == mutevol) {
-#endif
- if (smoothfade)
- start = mutelevel;
- else
-#ifdef __Darwin__
- start = 1.0;
-#else
- start = 100;
-#endif
- for (x=start;x<100;x+=stepsize) {
- mutevol = mutedlevel(oldvol, x);
- setvol(mutevol);
- /* Wait 0.01 sec */
- usleep(10000);
- }
- setvol(oldvol);
- } else
- printf("Whoops, it's already been changed!\n");
- muted = 0;
-}
-
-static void check_mute(void)
-{
- int offhook = 0;
- struct channel *chan;
- chan = channels;
- while(chan) {
- if (chan->subs) {
- offhook++;
- break;
- }
- chan = chan->next;
- }
- if (offhook && !muted)
- mute();
- else if (!offhook && muted)
- unmute();
-}
-
-static void delete_sub(struct channel *chan, char *name)
-{
- struct subchannel *sub, *prev;
- prev = NULL;
- sub = chan->subs;
- while(sub) {
- if (!strcasecmp(sub->name, name)) {
- if (prev)
- prev->next = sub->next;
- else
- chan->subs = sub->next;
- free(sub->name);
- free(sub);
- return;
- }
- prev = sub;
- sub = sub->next;
- }
-}
-
-static void append_sub(struct channel *chan, char *name)
-{
- struct subchannel *sub;
- sub = chan->subs;
- while(sub) {
- if (!strcasecmp(sub->name, name))
- return;
- sub = sub->next;
- }
- sub = malloc(sizeof(struct subchannel));
- if (sub) {
- memset(sub, 0, sizeof(struct subchannel));
- sub->name = strdup(name);
- sub->next = chan->subs;
- chan->subs = sub;
- }
-}
-
-static void hangup_chan(char *channel)
-{
- struct channel *chan;
- if (debug)
- printf("Hangup '%s'\n", channel);
- chan = find_channel(channel);
- if (chan)
- delete_sub(chan, channel);
- check_mute();
-}
-
-static void offhook_chan(char *channel)
-{
- struct channel *chan;
- if (debug)
- printf("Offhook '%s'\n", channel);
- chan = find_channel(channel);
- if (chan)
- append_sub(chan, channel);
- check_mute();
-}
-
-static int wait_event(void)
-{
- char *resp;
- char event[120]="";
- char channel[120]="";
- char oldname[120]="";
- char newname[120]="";
-
- resp = get_line();
- if (!resp) {
- fprintf(stderr, "disconnected (6)\n");
- return -1;
- }
- if (!strncasecmp(resp, "Event: ", strlen("Event: "))) {
- strncpy(event, resp + strlen("Event: "), sizeof(event) - 1);
- /* Consume the rest of the non-event */
- while((resp = get_line()) && strlen(resp)) {
- if (!strncasecmp(resp, "Channel: ", strlen("Channel: ")))
- strncpy(channel, resp + strlen("Channel: "), sizeof(channel) - 1);
- if (!strncasecmp(resp, "Newname: ", strlen("Newname: ")))
- strncpy(newname, resp + strlen("Newname: "), sizeof(newname) - 1);
- if (!strncasecmp(resp, "Oldname: ", strlen("Oldname: ")))
- strncpy(oldname, resp + strlen("Oldname: "), sizeof(oldname) - 1);
- }
- if (strlen(channel)) {
- if (!strcasecmp(event, "Hangup"))
- hangup_chan(channel);
- else
- offhook_chan(channel);
- }
- if (strlen(newname) && strlen(oldname)) {
- if (!strcasecmp(event, "Rename")) {
- hangup_chan(oldname);
- offhook_chan(newname);
- }
- }
- } else {
- /* Consume the rest of the non-event */
- while((resp = get_line()) && strlen(resp));
- }
- if (!resp) {
- fprintf(stderr, "disconnected (7)\n");
- return -1;
- }
- return 0;
-}
-
-static void usage(void)
-{
- printf("Usage: muted [-f] [-d]\n"
- " -f : Do not fork\n"
- " -d : Debug (implies -f)\n");
-}
-
-int main(int argc, char *argv[])
-{
- int x;
- while((x = getopt(argc, argv, "fhd")) > 0) {
- switch(x) {
- case 'd':
- debug = 1;
- needfork = 0;
- break;
- case 'f':
- needfork = 0;
- break;
- case 'h':
- /* Fall through */
- default:
- usage();
- exit(1);
- }
- }
- if (load_config())
- exit(1);
-#ifndef __Darwin__
- if (open_mixer())
- exit(1);
-#endif
- if (connect_asterisk()) {
-#ifndef __Darwin__
- close(mixfd);
-#endif
- exit(1);
- }
- if (login_asterisk()) {
-#ifndef __Darwin__
- close(mixfd);
-#endif
- fclose(astf);
- exit(1);
- }
- if (needfork)
- daemon(0,0);
- for(;;) {
- if (wait_event()) {
- fclose(astf);
- while(connect_asterisk()) {
- sleep(5);
- }
- if (login_asterisk()) {
- fclose(astf);
- exit(1);
- }
- }
- }
- exit(0);
-}
diff --git a/1.2-netsec/muted.conf.sample b/1.2-netsec/muted.conf.sample
deleted file mode 100644
index 2463d7a1c..000000000
--- a/1.2-netsec/muted.conf.sample
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# Sample muted configuration file
-#
-# Copyright (C) 2004 Digium, Inc.
-#
-# First you have the host, username, and password
-# we use to connect to the asterisk system
-#
-host localhost
-user user
-pass pass
-#
-# List each channel we're supposed to watch
-#
-channel Zap/1
-channel Zap/2
-channel SIP/mark
-#
-# Mute level is the percentage of the current volume we should
-# lower the music to.
-#
-mutelevel 20
-#
-# Smooth fade makes the fadein/fadeout nicer sounding
-#
-smoothfade
diff --git a/1.2-netsec/netsock.c b/1.2-netsec/netsock.c
deleted file mode 100644
index 386f15660..000000000
--- a/1.2-netsec/netsock.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Kevin P. Fleming <kpfleming@digium.com>
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Network socket handling
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <net/if.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <sys/ioctl.h>
-
-#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
-#include <fcntl.h>
-#include <net/route.h>
-#endif
-
-#if defined (SOLARIS)
-#include <sys/sockio.h>
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/netsock.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_netsock {
- ASTOBJ_COMPONENTS(struct ast_netsock);
- struct sockaddr_in bindaddr;
- int sockfd;
- int *ioref;
- struct io_context *ioc;
- void *data;
-};
-
-struct ast_netsock_list {
- ASTOBJ_CONTAINER_COMPONENTS(struct ast_netsock);
- struct io_context *ioc;
-};
-
-static void ast_netsock_destroy(struct ast_netsock *netsock)
-{
- ast_io_remove(netsock->ioc, netsock->ioref);
- close(netsock->sockfd);
- free(netsock);
-}
-
-struct ast_netsock_list *ast_netsock_list_alloc(void)
-{
- struct ast_netsock_list *res;
-
- res = calloc(1, sizeof(*res));
-
- return res;
-}
-
-int ast_netsock_init(struct ast_netsock_list *list)
-{
- memset(list, 0, sizeof(*list));
- ASTOBJ_CONTAINER_INIT(list);
-
- return 0;
-}
-
-int ast_netsock_release(struct ast_netsock_list *list)
-{
- ASTOBJ_CONTAINER_DESTROYALL(list, ast_netsock_destroy);
- ASTOBJ_CONTAINER_DESTROY(list);
-
- return 0;
-}
-
-struct ast_netsock *ast_netsock_find(struct ast_netsock_list *list,
- struct sockaddr_in *sa)
-{
- struct ast_netsock *sock = NULL;
-
- ASTOBJ_CONTAINER_TRAVERSE(list, !sock, {
- ASTOBJ_RDLOCK(iterator);
- if (!inaddrcmp(&iterator->bindaddr, sa))
- sock = iterator;
- ASTOBJ_UNLOCK(iterator);
- });
-
- return sock;
-}
-
-struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct io_context *ioc, struct sockaddr_in *bindaddr, int tos, ast_io_cb callback, void *data)
-{
- int netsocket = -1;
- int *ioref;
- char iabuf[INET_ADDRSTRLEN];
-
- struct ast_netsock *ns;
-
- /* Make a UDP socket */
- netsocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
-
- if (netsocket < 0) {
- ast_log(LOG_ERROR, "Unable to create network socket: %s\n", strerror(errno));
- return NULL;
- }
- if (bind(netsocket,(struct sockaddr *)bindaddr, sizeof(struct sockaddr_in))) {
- ast_log(LOG_ERROR, "Unable to bind to %s port %d: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr->sin_addr), ntohs(bindaddr->sin_port), strerror(errno));
- close(netsocket);
- return NULL;
- }
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos);
-
- if (setsockopt(netsocket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))
- ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
-
- ns = malloc(sizeof(struct ast_netsock));
- if (ns) {
- /* Establish I/O callback for socket read */
- ioref = ast_io_add(ioc, netsocket, callback, AST_IO_IN, ns);
- if (!ioref) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- close(netsocket);
- free(ns);
- return NULL;
- }
- ASTOBJ_INIT(ns);
- ns->ioref = ioref;
- ns->ioc = ioc;
- ns->sockfd = netsocket;
- ns->data = data;
- memcpy(&ns->bindaddr, bindaddr, sizeof(ns->bindaddr));
- ASTOBJ_CONTAINER_LINK(list, ns);
- } else {
- ast_log(LOG_WARNING, "Out of memory!\n");
- close(netsocket);
- }
-
- return ns;
-}
-
-struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_context *ioc, const char *bindinfo, int defaultport, int tos, ast_io_cb callback, void *data)
-{
- struct sockaddr_in sin;
- char *tmp;
- char *host;
- char *port;
- int portno;
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(defaultport);
- tmp = ast_strdupa(bindinfo);
- if (!tmp) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- return NULL;
- }
-
- host = strsep(&tmp, ":");
- port = tmp;
-
- if (port && ((portno = atoi(port)) > 0))
- sin.sin_port = htons(portno);
-
- inet_aton(host, &sin.sin_addr);
-
- return ast_netsock_bindaddr(list, ioc, &sin, tos, callback, data);
-}
-
-int ast_netsock_sockfd(const struct ast_netsock *ns)
-{
- return ns ? ns-> sockfd : -1;
-}
-
-const struct sockaddr_in *ast_netsock_boundaddr(const struct ast_netsock *ns)
-{
- return &(ns->bindaddr);
-}
-
-void *ast_netsock_data(const struct ast_netsock *ns)
-{
- return ns->data;
-}
-
-void ast_netsock_unref(struct ast_netsock *ns)
-{
- ASTOBJ_UNREF(ns, ast_netsock_destroy);
-}
diff --git a/1.2-netsec/pbx.c b/1.2-netsec/pbx.c
deleted file mode 100644
index f7d26c92a..000000000
--- a/1.2-netsec/pbx.c
+++ /dev/null
@@ -1,6487 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Core PBX routines.
- *
- */
-
-#include <sys/types.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <errno.h>
-#include <time.h>
-#include <sys/time.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/cli.h"
-#include "asterisk/pbx.h"
-#include "asterisk/channel.h"
-#include "asterisk/options.h"
-#include "asterisk/logger.h"
-#include "asterisk/file.h"
-#include "asterisk/callerid.h"
-#include "asterisk/cdr.h"
-#include "asterisk/config.h"
-#include "asterisk/term.h"
-#include "asterisk/manager.h"
-#include "asterisk/ast_expr.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/say.h"
-#include "asterisk/utils.h"
-#include "asterisk/causes.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/app.h"
-#include "asterisk/devicestate.h"
-#include "asterisk/compat.h"
-
-/*!
- * \note I M P O R T A N T :
- *
- * The speed of extension handling will likely be among the most important
- * aspects of this PBX. The switching scheme as it exists right now isn't
- * terribly bad (it's O(N+M), where N is the # of extensions and M is the avg #
- * of priorities, but a constant search time here would be great ;-)
- *
- */
-
-#ifdef LOW_MEMORY
-#define EXT_DATA_SIZE 256
-#else
-#define EXT_DATA_SIZE 8192
-#endif
-
-#define SWITCH_DATA_LENGTH 256
-
-#define VAR_BUF_SIZE 4096
-
-#define VAR_NORMAL 1
-#define VAR_SOFTTRAN 2
-#define VAR_HARDTRAN 3
-
-#define BACKGROUND_SKIP (1 << 0)
-#define BACKGROUND_NOANSWER (1 << 1)
-#define BACKGROUND_MATCHEXTEN (1 << 2)
-#define BACKGROUND_PLAYBACK (1 << 3)
-
-AST_APP_OPTIONS(background_opts, {
- AST_APP_OPTION('s', BACKGROUND_SKIP),
- AST_APP_OPTION('n', BACKGROUND_NOANSWER),
- AST_APP_OPTION('m', BACKGROUND_MATCHEXTEN),
- AST_APP_OPTION('p', BACKGROUND_PLAYBACK),
-});
-
-#define WAITEXTEN_MOH (1 << 0)
-
-AST_APP_OPTIONS(waitexten_opts, {
- AST_APP_OPTION_ARG('m', WAITEXTEN_MOH, 1),
-});
-
-struct ast_context;
-
-/*!\brief ast_exten: An extension
- The dialplan is saved as a linked list with each context
- having it's own linked list of extensions - one item per
- priority.
-*/
-struct ast_exten {
- char *exten; /* Extension name */
- int matchcid; /* Match caller id ? */
- char *cidmatch; /* Caller id to match for this extension */
- int priority; /* Priority */
- char *label; /* Label */
- struct ast_context *parent; /* The context this extension belongs to */
- char *app; /* Application to execute */
- void *data; /* Data to use (arguments) */
- void (*datad)(void *); /* Data destructor */
- struct ast_exten *peer; /* Next higher priority with our extension */
- const char *registrar; /* Registrar */
- struct ast_exten *next; /* Extension with a greater ID */
- char stuff[0];
-};
-
-/*! \brief ast_include: include= support in extensions.conf */
-struct ast_include {
- char *name;
- char *rname; /* Context to include */
- const char *registrar; /* Registrar */
- int hastime; /* If time construct exists */
- struct ast_timing timing; /* time construct */
- struct ast_include *next; /* Link them together */
- char stuff[0];
-};
-
-/*! \brief ast_sw: Switch statement in extensions.conf */
-struct ast_sw {
- char *name;
- const char *registrar; /* Registrar */
- char *data; /* Data load */
- int eval;
- struct ast_sw *next; /* Link them together */
- char *tmpdata;
- char stuff[0];
-};
-
-/*! \brief ast_ignorepat: Ignore patterns in dial plan */
-struct ast_ignorepat {
- const char *registrar;
- struct ast_ignorepat *next;
- char pattern[0];
-};
-
-/*! \brief ast_context: An extension context */
-struct ast_context {
- ast_mutex_t lock; /*!< A lock to prevent multiple threads from clobbering the context */
- struct ast_exten *root; /*!< The root of the list of extensions */
- struct ast_context *next; /*!< Link them together */
- struct ast_include *includes; /*!< Include other contexts */
- struct ast_ignorepat *ignorepats; /*!< Patterns for which to continue playing dialtone */
- const char *registrar; /*!< Registrar */
- struct ast_sw *alts; /*!< Alternative switches */
- char name[0]; /*!< Name of the context */
-};
-
-
-/*! \brief ast_app: A registered application */
-struct ast_app {
- int (*execute)(struct ast_channel *chan, void *data);
- const char *synopsis; /* Synopsis text for 'show applications' */
- const char *description; /* Description (help text) for 'show application <name>' */
- struct ast_app *next; /* Next app in list */
- char name[0]; /* Name of the application */
-};
-
-/*! \brief ast_state_cb: An extension state notify register item */
-struct ast_state_cb {
- int id;
- void *data;
- ast_state_cb_type callback;
- struct ast_state_cb *next;
-};
-
-/*! \brief Structure for dial plan hints
-
- Hints are pointers from an extension in the dialplan to one or
- more devices (tech/name) */
-struct ast_hint {
- struct ast_exten *exten; /*!< Extension */
- int laststate; /*!< Last known state */
- struct ast_state_cb *callbacks; /*!< Callback list for this extension */
- struct ast_hint *next; /*!< Pointer to next hint in list */
-};
-
-int ast_pbx_outgoing_cdr_failed(void);
-
-static int pbx_builtin_answer(struct ast_channel *, void *);
-static int pbx_builtin_goto(struct ast_channel *, void *);
-static int pbx_builtin_hangup(struct ast_channel *, void *);
-static int pbx_builtin_background(struct ast_channel *, void *);
-static int pbx_builtin_dtimeout(struct ast_channel *, void *);
-static int pbx_builtin_rtimeout(struct ast_channel *, void *);
-static int pbx_builtin_atimeout(struct ast_channel *, void *);
-static int pbx_builtin_wait(struct ast_channel *, void *);
-static int pbx_builtin_waitexten(struct ast_channel *, void *);
-static int pbx_builtin_setlanguage(struct ast_channel *, void *);
-static int pbx_builtin_resetcdr(struct ast_channel *, void *);
-static int pbx_builtin_setaccount(struct ast_channel *, void *);
-static int pbx_builtin_setamaflags(struct ast_channel *, void *);
-static int pbx_builtin_ringing(struct ast_channel *, void *);
-static int pbx_builtin_progress(struct ast_channel *, void *);
-static int pbx_builtin_congestion(struct ast_channel *, void *);
-static int pbx_builtin_busy(struct ast_channel *, void *);
-static int pbx_builtin_setglobalvar(struct ast_channel *, void *);
-static int pbx_builtin_noop(struct ast_channel *, void *);
-static int pbx_builtin_gotoif(struct ast_channel *, void *);
-static int pbx_builtin_gotoiftime(struct ast_channel *, void *);
-static int pbx_builtin_execiftime(struct ast_channel *, void *);
-static int pbx_builtin_saynumber(struct ast_channel *, void *);
-static int pbx_builtin_saydigits(struct ast_channel *, void *);
-static int pbx_builtin_saycharacters(struct ast_channel *, void *);
-static int pbx_builtin_sayphonetic(struct ast_channel *, void *);
-static int pbx_builtin_setvar_old(struct ast_channel *, void *);
-int pbx_builtin_setvar(struct ast_channel *, void *);
-static int pbx_builtin_importvar(struct ast_channel *, void *);
-
-static struct varshead globals;
-
-static int autofallthrough = 0;
-
-AST_MUTEX_DEFINE_STATIC(maxcalllock);
-static int countcalls = 0;
-
-AST_MUTEX_DEFINE_STATIC(acflock); /*!< Lock for the custom function list */
-static struct ast_custom_function *acf_root = NULL;
-
-/*! \brief Declaration of builtin applications */
-static struct pbx_builtin {
- char name[AST_MAX_APP];
- int (*execute)(struct ast_channel *chan, void *data);
- char *synopsis;
- char *description;
-} builtins[] =
-{
- /* These applications are built into the PBX core and do not
- need separate modules */
-
- { "AbsoluteTimeout", pbx_builtin_atimeout,
- "Set absolute maximum time of call",
- " AbsoluteTimeout(seconds): This application will set the absolute maximum\n"
- "amount of time permitted for a call. A setting of 0 disables the timeout.\n"
- " AbsoluteTimeout has been deprecated in favor of Set(TIMEOUT(absolute)=timeout)\n"
- },
-
- { "Answer", pbx_builtin_answer,
- "Answer a channel if ringing",
- " Answer([delay]): If the call has not been answered, this application will\n"
- "answer it. Otherwise, it has no effect on the call. If a delay is specified,\n"
- "Asterisk will wait this number of milliseconds before answering the call.\n"
- },
-
- { "BackGround", pbx_builtin_background,
- "Play a file while awaiting extension",
- " Background(filename1[&filename2...][|options[|langoverride][|context]]):\n"
- "This application will play the given list of files while waiting for an\n"
- "extension to be dialed by the calling channel. To continue waiting for digits\n"
- "after this application has finished playing files, the WaitExten application\n"
- "should be used. The 'langoverride' option explicity specifies which language\n"
- "to attempt to use for the requested sound files. If a 'context' is specified,\n"
- "this is the dialplan context that this application will use when exiting to a\n"
- "dialed extension."
- " If one of the requested sound files does not exist, call processing will be\n"
- "terminated.\n"
- " Options:\n"
- " s - causes the playback of the message to be skipped\n"
- " if the channel is not in the 'up' state (i.e. it\n"
- " hasn't been answered yet.) If this happens, the\n"
- " application will return immediately.\n"
- " n - don't answer the channel before playing the files\n"
- " m - only break if a digit hit matches a one digit\n"
- " extension in the destination context\n"
- },
-
- { "Busy", pbx_builtin_busy,
- "Indicate the Busy condition",
- " Busy([timeout]): This application will indicate the busy condition to\n"
- "the calling channel. If the optional timeout is specified, the calling channel\n"
- "will be hung up after the specified number of seconds. Otherwise, this\n"
- "application will wait until the calling channel hangs up.\n"
- },
-
- { "Congestion", pbx_builtin_congestion,
- "Indicate the Congestion condition",
- " Congestion([timeout]): This application will indicate the congenstion\n"
- "condition to the calling channel. If the optional timeout is specified, the\n"
- "calling channel will be hung up after the specified number of seconds.\n"
- "Otherwise, this application will wait until the calling channel hangs up.\n"
- },
-
- { "DigitTimeout", pbx_builtin_dtimeout,
- "Set maximum timeout between digits",
- " DigitTimeout(seconds): Set the maximum amount of time permitted between\n"
- "digits when the user is typing in an extension. When this timeout expires,\n"
- "after the user has started to type in an extension, the extension will be\n"
- "considered complete, and will be interpreted. Note that if an extension\n"
- "typed in is valid, it will not have to timeout to be tested, so typically\n"
- "at the expiry of this timeout, the extension will be considered invalid\n"
- "(and thus control would be passed to the 'i' extension, or if it doesn't\n"
- "exist the call would be terminated). The default timeout is 5 seconds.\n"
- " DigitTimeout has been deprecated in favor of Set(TIMEOUT(digit)=timeout)\n"
- },
-
- { "Goto", pbx_builtin_goto,
- "Jump to a particular priority, extension, or context",
- " Goto([[context|]extension|]priority): This application will cause the\n"
- "calling channel to continue dialplan execution at the specified priority.\n"
- "If no specific extension, or extension and context, are specified, then this\n"
- "application will jump to the specified priority of the current extension.\n"
- " If the attempt to jump to another location in the dialplan is not successful,\n"
- "then the channel will continue at the next priority of the current extension.\n"
- },
-
- { "GotoIf", pbx_builtin_gotoif,
- "Conditional goto",
- " GotoIf(Condition?[label1]:[label2]): This application will cause the calling\n"
- "channel to jump to the speicifed location in the dialplan based on the\n"
- "evaluation of the given condition. The channel will continue at 'label1' if the\n"
- "condition is true, or 'label2' if the condition is false. The labels are\n"
- "specified in the same syntax that is used with the Goto application.\n"
- },
-
- { "GotoIfTime", pbx_builtin_gotoiftime,
- "Conditional Goto based on the current time",
- " GotoIfTime(<times>|<weekdays>|<mdays>|<months>?[[context|]exten|]priority):\n"
- "This application will have the calling channel jump to the speicified location\n"
- "int the dialplan if the current time matches the given time specification.\n"
- "Further information on the time specification can be found in examples\n"
- "illustrating how to do time-based context includes in the dialplan.\n"
- },
-
- { "ExecIfTime", pbx_builtin_execiftime,
- "Conditional application execution based on the current time",
- " ExecIfTime(<times>|<weekdays>|<mdays>|<months>?appname[|appargs]):\n"
- "This application will execute the specified dialplan application, with optional\n"
- "arguments, if the current time matches the given time specification. Further\n"
- "information on the time speicification can be found in examples illustrating\n"
- "how to do time-based context includes in the dialplan.\n"
- },
-
- { "Hangup", pbx_builtin_hangup,
- "Hang up the calling channel",
- " Hangup(): This application will hang up the calling channel.\n"
- },
-
- { "NoOp", pbx_builtin_noop,
- "Do Nothing",
- " NoOp(): This applicatiion does nothing. However, it is useful for debugging\n"
- "purposes. Any text that is provided as arguments to this application can be\n"
- "viewed at the Asterisk CLI. This method can be used to see the evaluations of\n"
- "variables or functions without having any effect."
- },
-
- { "Progress", pbx_builtin_progress,
- "Indicate progress",
- " Progress(): This application will request that in-band progress information\n"
- "be provided to the calling channel.\n"
- },
-
- { "ResetCDR", pbx_builtin_resetcdr,
- "Resets the Call Data Record",
- " ResetCDR([options]): This application causes the Call Data Record to be\n"
- "reset.\n"
- " Options:\n"
- " w -- Store the current CDR record before resetting it.\n"
- " a -- Store any stacked records.\n"
- " v -- Save CDR variables.\n"
- },
-
- { "ResponseTimeout", pbx_builtin_rtimeout,
- "Set maximum timeout awaiting response",
- " ResponseTimeout(seconds): This will set the maximum amount of time permitted\n"
- "to wait for an extension to dialed (see the WaitExten application), before the\n"
- "timeout occurs. If this timeout is reached, dialplan execution will continue at\n"
- "the 't' extension, if it exists.\n"
- " ResponseTimeout has been deprecated in favor of Set(TIMEOUT(response)=timeout)\n"
- },
-
- { "Ringing", pbx_builtin_ringing,
- "Indicate ringing tone",
- " Ringing(): This application will request that the channel indicate a ringing\n"
- "tone to the user.\n"
- },
-
- { "SayNumber", pbx_builtin_saynumber,
- "Say Number",
- " SayNumber(digits[,gender]): This application will play the sounds that\n"
- "correspond to the given number. Optionally, a gender may be specified.\n"
- "This will use the language that is currently set for the channel. See the\n"
- "LANGUAGE function for more information on setting the language for the channel.\n"
- },
-
- { "SayDigits", pbx_builtin_saydigits,
- "Say Digits",
- " SayDigits(digits): This application will play the sounds that correspond\n"
- "to the digits of the given number. This will use the language that is currently\n"
- "set for the channel. See the LANGUAGE function for more information on setting\n"
- "the language for the channel.\n"
- },
-
- { "SayAlpha", pbx_builtin_saycharacters,
- "Say Alpha",
- " SayAlpha(string): This application will play the sounds that correspond to\n"
- "the letters of the given string.\n"
- },
-
- { "SayPhonetic", pbx_builtin_sayphonetic,
- "Say Phonetic",
- " SayPhonetic(string): This application will play the sounds from the phonetic\n"
- "alphabet that correspond to the letters in the given string.\n"
- },
-
- { "SetAccount", pbx_builtin_setaccount,
- "Set the CDR Account Code",
- " SetAccount([account]): This application will set the channel account code for\n"
- "billing purposes.\n"
- " SetAccount has been deprecated in favor of the Set(CDR(accountcode)=account).\n"
- },
-
- { "SetAMAFlags", pbx_builtin_setamaflags,
- "Set the AMA Flags",
- " SetAMAFlags([flag]): This channel will set the channel's AMA Flags for billing\n"
- "purposes.\n"
- },
-
- { "SetGlobalVar", pbx_builtin_setglobalvar,
- "Set a global variable to a given value",
- " SetGlobalVar(variable=value): This application sets a given global variable to\n"
- "the specified value.\n"
- },
-
- { "SetLanguage", pbx_builtin_setlanguage,
- "Set the channel's preferred language",
- " SetLanguage(language): This will set the channel language to the given value.\n"
- "This information is used for the syntax in generation of numbers, and to choose\n"
- "a sound file in the given language, when it is available.\n"
- " For example, if language is set to 'fr' and the file 'demo-congrats' is \n"
- "requested to be played, if the file 'fr/demo-congrats' exists, then\n"
- "it will play that file. If not, it will play the normal 'demo-congrats'.\n"
- "For some language codes, SetLanguage also changes the syntax of some\n"
- "Asterisk functions, like SayNumber.\n"
- " SetLanguage has been deprecated in favor of Set(LANGUAGE()=language)\n"
- },
-
- { "Set", pbx_builtin_setvar,
- "Set channel variable(s) or function value(s)",
- " Set(name1=value1|name2=value2|..[|options])\n"
- "This function can be used to set the value of channel variables or dialplan\n"
- "functions. It will accept up to 24 name/value pairs. When setting variables,\n"
- "if the variable name is prefixed with _, the variable will be inherited into\n"
- "channels created from the current channel. If the variable name is prefixed\n"
- "with __, the variable will be inherited into channels created from the current\n"
- "channel and all children channels.\n"
- " Options:\n"
- " g - Set variable globally instead of on the channel\n"
- " (applies only to variables, not functions)\n"
- },
-
- { "SetVar", pbx_builtin_setvar_old,
- "Set channel variable(s)",
- " SetVar(name1=value1|name2=value2|..[|options]): This application has been\n"
- "deprecated in favor of using the Set application.\n"
- },
-
- { "ImportVar", pbx_builtin_importvar,
- "Import a variable from a channel into a new variable",
- " ImportVar(newvar=channelname|variable): This application imports a variable\n"
- "from the specified channel (as opposed to the current one) and stores it as\n"
- "a variable in the current channel (the channel that is calling this\n"
- "application). Variables created by this application have the same inheritance\n"
- "properties as those created with the Set application. See the documentation for\n"
- "Set for more information.\n"
- },
-
- { "Wait", pbx_builtin_wait,
- "Waits for some time",
- " Wait(seconds): This application waits for a specified number of seconds.\n"
- "Then, dialplan execution will continue at the next priority.\n"
- " Note that the seconds can be passed with fractions of a second. For example,\n"
- "'1.5' will ask the application to wait for 1.5 seconds.\n"
- },
-
- { "WaitExten", pbx_builtin_waitexten,
- "Waits for an extension to be entered",
- " WaitExten([seconds][|options]): This application waits for the user to enter\n"
- "a new extension for a specified number of seconds.\n"
- " Note that the seconds can be passed with fractions of a second. For example,\n"
- "'1.5' will ask the application to wait for 1.5 seconds.\n"
- " Options:\n"
- " m[(x)] - Provide music on hold to the caller while waiting for an extension.\n"
- " Optionally, specify the class for music on hold within parenthesis.\n"
- },
-
-};
-
-static struct ast_context *contexts = NULL;
-AST_MUTEX_DEFINE_STATIC(conlock); /* Lock for the ast_context list */
-static struct ast_app *apps = NULL;
-AST_MUTEX_DEFINE_STATIC(applock); /* Lock for the application list */
-
-struct ast_switch *switches = NULL;
-AST_MUTEX_DEFINE_STATIC(switchlock); /* Lock for switches */
-
-AST_MUTEX_DEFINE_STATIC(hintlock); /* Lock for extension state notifys */
-static int stateid = 1;
-struct ast_hint *hints = NULL;
-struct ast_state_cb *statecbs = NULL;
-
-/*
- \note This function is special. It saves the stack so that no matter
- how many times it is called, it returns to the same place */
-int pbx_exec(struct ast_channel *c, /*!< Channel */
- struct ast_app *app, /*!< Application */
- void *data, /*!< Data for execution */
- int newstack) /*!< Force stack increment */
-{
- int res;
-
- char *saved_c_appl;
- char *saved_c_data;
-
- int (*execute)(struct ast_channel *chan, void *data) = app->execute;
-
- if (newstack) {
- if (c->cdr)
- ast_cdr_setapp(c->cdr, app->name, data);
-
- /* save channel values */
- saved_c_appl= c->appl;
- saved_c_data= c->data;
-
- c->appl = app->name;
- c->data = data;
- res = execute(c, data);
- /* restore channel values */
- c->appl= saved_c_appl;
- c->data= saved_c_data;
- return res;
- } else
- ast_log(LOG_WARNING, "You really didn't want to call this function with newstack set to 0\n");
- return -1;
-}
-
-
-/*! Go no deeper than this through includes (not counting loops) */
-#define AST_PBX_MAX_STACK 128
-
-#define HELPER_EXISTS 0
-#define HELPER_SPAWN 1
-#define HELPER_EXEC 2
-#define HELPER_CANMATCH 3
-#define HELPER_MATCHMORE 4
-#define HELPER_FINDLABEL 5
-
-/*! \brief Find application handle in linked list
- */
-struct ast_app *pbx_findapp(const char *app)
-{
- struct ast_app *tmp;
-
- if (ast_mutex_lock(&applock)) {
- ast_log(LOG_WARNING, "Unable to obtain application lock\n");
- return NULL;
- }
- tmp = apps;
- while(tmp) {
- if (!strcasecmp(tmp->name, app))
- break;
- tmp = tmp->next;
- }
- ast_mutex_unlock(&applock);
- return tmp;
-}
-
-static struct ast_switch *pbx_findswitch(const char *sw)
-{
- struct ast_switch *asw;
-
- if (ast_mutex_lock(&switchlock)) {
- ast_log(LOG_WARNING, "Unable to obtain application lock\n");
- return NULL;
- }
- asw = switches;
- while(asw) {
- if (!strcasecmp(asw->name, sw))
- break;
- asw = asw->next;
- }
- ast_mutex_unlock(&switchlock);
- return asw;
-}
-
-static inline int include_valid(struct ast_include *i)
-{
- if (!i->hastime)
- return 1;
-
- return ast_check_timing(&(i->timing));
-}
-
-static void pbx_destroy(struct ast_pbx *p)
-{
- free(p);
-}
-
-#define EXTENSION_MATCH_CORE(data,pattern,match) {\
- /* All patterns begin with _ */\
- if (pattern[0] != '_') \
- return 0;\
- /* Start optimistic */\
- match=1;\
- pattern++;\
- while(match && *data && *pattern && (*pattern != '/')) {\
- while (*data == '-' && (*(data+1) != '\0')) data++;\
- switch(toupper(*pattern)) {\
- case '[': \
- {\
- int i,border=0;\
- char *where;\
- match=0;\
- pattern++;\
- where=strchr(pattern,']');\
- if (where)\
- border=(int)(where-pattern);\
- if (!where || border > strlen(pattern)) {\
- ast_log(LOG_WARNING, "Wrong usage of [] in the extension\n");\
- return match;\
- }\
- for (i=0; i<border; i++) {\
- int res=0;\
- if (i+2<border)\
- if (pattern[i+1]=='-') {\
- if (*data >= pattern[i] && *data <= pattern[i+2]) {\
- res=1;\
- } else {\
- i+=2;\
- continue;\
- }\
- }\
- if (res==1 || *data==pattern[i]) {\
- match = 1;\
- break;\
- }\
- }\
- pattern+=border;\
- break;\
- }\
- case 'N':\
- if ((*data < '2') || (*data > '9'))\
- match=0;\
- break;\
- case 'X':\
- if ((*data < '0') || (*data > '9'))\
- match = 0;\
- break;\
- case 'Z':\
- if ((*data < '1') || (*data > '9'))\
- match = 0;\
- break;\
- case '.':\
- /* Must match */\
- return 1;\
- case '!':\
- /* Early match */\
- return 2;\
- case ' ':\
- case '-':\
- /* Ignore these characters */\
- data--;\
- break;\
- default:\
- if (*data != *pattern)\
- match =0;\
- }\
- data++;\
- pattern++;\
- }\
- /* If we ran off the end of the data and the pattern ends in '!', match */\
- if (match && !*data && (*pattern == '!'))\
- return 2;\
-}
-
-int ast_extension_match(const char *pattern, const char *data)
-{
- int match;
- /* If they're the same return */
- if (!strcmp(pattern, data))
- return 1;
- EXTENSION_MATCH_CORE(data,pattern,match);
- /* Must be at the end of both */
- if (*data || (*pattern && (*pattern != '/')))
- match = 0;
- return match;
-}
-
-int ast_extension_close(const char *pattern, const char *data, int needmore)
-{
- int match;
- /* If "data" is longer, it can'be a subset of pattern unless
- pattern is a pattern match */
- if ((strlen(pattern) < strlen(data)) && (pattern[0] != '_'))
- return 0;
-
- if ((ast_strlen_zero((char *)data) || !strncasecmp(pattern, data, strlen(data))) &&
- (!needmore || (strlen(pattern) > strlen(data)))) {
- return 1;
- }
- EXTENSION_MATCH_CORE(data,pattern,match);
- /* If there's more or we don't care about more, or if it's a possible early match,
- return non-zero; otherwise it's a miss */
- if (!needmore || *pattern || match == 2) {
- return match;
- } else
- return 0;
-}
-
-struct ast_context *ast_context_find(const char *name)
-{
- struct ast_context *tmp;
- ast_mutex_lock(&conlock);
- if (name) {
- tmp = contexts;
- while(tmp) {
- if (!strcasecmp(name, tmp->name))
- break;
- tmp = tmp->next;
- }
- } else
- tmp = contexts;
- ast_mutex_unlock(&conlock);
- return tmp;
-}
-
-#define STATUS_NO_CONTEXT 1
-#define STATUS_NO_EXTENSION 2
-#define STATUS_NO_PRIORITY 3
-#define STATUS_NO_LABEL 4
-#define STATUS_SUCCESS 5
-
-static int matchcid(const char *cidpattern, const char *callerid)
-{
- int failresult;
-
- /* If the Caller*ID pattern is empty, then we're matching NO Caller*ID, so
- failing to get a number should count as a match, otherwise not */
-
- if (!ast_strlen_zero(cidpattern))
- failresult = 0;
- else
- failresult = 1;
-
- if (!callerid)
- return failresult;
-
- return ast_extension_match(cidpattern, callerid);
-}
-
-static struct ast_exten *pbx_find_extension(struct ast_channel *chan, struct ast_context *bypass, const char *context, const char *exten, int priority, const char *label, const char *callerid, int action, char *incstack[], int *stacklen, int *status, struct ast_switch **swo, char **data, const char **foundcontext)
-{
- int x, res;
- struct ast_context *tmp;
- struct ast_exten *e, *eroot;
- struct ast_include *i;
- struct ast_sw *sw;
- struct ast_switch *asw;
-
- /* Initialize status if appropriate */
- if (!*stacklen) {
- *status = STATUS_NO_CONTEXT;
- *swo = NULL;
- *data = NULL;
- }
- /* Check for stack overflow */
- if (*stacklen >= AST_PBX_MAX_STACK) {
- ast_log(LOG_WARNING, "Maximum PBX stack exceeded\n");
- return NULL;
- }
- /* Check first to see if we've already been checked */
- for (x=0; x<*stacklen; x++) {
- if (!strcasecmp(incstack[x], context))
- return NULL;
- }
- if (bypass)
- tmp = bypass;
- else
- tmp = contexts;
- while(tmp) {
- /* Match context */
- if (bypass || !strcmp(tmp->name, context)) {
- struct ast_exten *earlymatch = NULL;
-
- if (*status < STATUS_NO_EXTENSION)
- *status = STATUS_NO_EXTENSION;
- for (eroot = tmp->root; eroot; eroot=eroot->next) {
- int match = 0;
- /* Match extension */
- if ((((action != HELPER_MATCHMORE) && ast_extension_match(eroot->exten, exten)) ||
- ((action == HELPER_CANMATCH) && (ast_extension_close(eroot->exten, exten, 0))) ||
- ((action == HELPER_MATCHMORE) && (match = ast_extension_close(eroot->exten, exten, 1)))) &&
- (!eroot->matchcid || matchcid(eroot->cidmatch, callerid))) {
-
- if (action == HELPER_MATCHMORE && match == 2 && !earlymatch) {
- /* It matched an extension ending in a '!' wildcard
- So ignore it for now, unless there's a better match */
- earlymatch = eroot;
- } else {
- e = eroot;
- if (*status < STATUS_NO_PRIORITY)
- *status = STATUS_NO_PRIORITY;
- while(e) {
- /* Match priority */
- if (action == HELPER_FINDLABEL) {
- if (*status < STATUS_NO_LABEL)
- *status = STATUS_NO_LABEL;
- if (label && e->label && !strcmp(label, e->label)) {
- *status = STATUS_SUCCESS;
- *foundcontext = context;
- return e;
- }
- } else if (e->priority == priority) {
- *status = STATUS_SUCCESS;
- *foundcontext = context;
- return e;
- }
- e = e->peer;
- }
- }
- }
- }
- if (earlymatch) {
- /* Bizarre logic for HELPER_MATCHMORE. We return zero to break out
- of the loop waiting for more digits, and _then_ match (normally)
- the extension we ended up with. We got an early-matching wildcard
- pattern, so return NULL to break out of the loop. */
- return NULL;
- }
- /* Check alternative switches */
- sw = tmp->alts;
- while(sw) {
- if ((asw = pbx_findswitch(sw->name))) {
- /* Substitute variables now */
- if (sw->eval)
- pbx_substitute_variables_helper(chan, sw->data, sw->tmpdata, SWITCH_DATA_LENGTH - 1);
- if (action == HELPER_CANMATCH)
- res = asw->canmatch ? asw->canmatch(chan, context, exten, priority, callerid, sw->eval ? sw->tmpdata : sw->data) : 0;
- else if (action == HELPER_MATCHMORE)
- res = asw->matchmore ? asw->matchmore(chan, context, exten, priority, callerid, sw->eval ? sw->tmpdata : sw->data) : 0;
- else
- res = asw->exists ? asw->exists(chan, context, exten, priority, callerid, sw->eval ? sw->tmpdata : sw->data) : 0;
- if (res) {
- /* Got a match */
- *swo = asw;
- *data = sw->eval ? sw->tmpdata : sw->data;
- *foundcontext = context;
- return NULL;
- }
- } else {
- ast_log(LOG_WARNING, "No such switch '%s'\n", sw->name);
- }
- sw = sw->next;
- }
- /* Setup the stack */
- incstack[*stacklen] = tmp->name;
- (*stacklen)++;
- /* Now try any includes we have in this context */
- i = tmp->includes;
- while(i) {
- if (include_valid(i)) {
- if ((e = pbx_find_extension(chan, bypass, i->rname, exten, priority, label, callerid, action, incstack, stacklen, status, swo, data, foundcontext)))
- return e;
- if (*swo)
- return NULL;
- }
- i = i->next;
- }
- break;
- }
- tmp = tmp->next;
- }
- return NULL;
-}
-
-/* Note that it's negative -- that's important later. */
-#define DONT_HAVE_LENGTH 0x80000000
-
-static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
-{
- char *varchar, *offsetchar = NULL;
- int parens=0;
-
- *offset = 0;
- *length = DONT_HAVE_LENGTH;
- *isfunc = 0;
- for (varchar=var; *varchar; varchar++) {
- switch (*varchar) {
- case '(':
- (*isfunc)++;
- parens++;
- break;
- case ')':
- parens--;
- break;
- case ':':
- if (parens == 0) {
- offsetchar = varchar + 1;
- *varchar = '\0';
- goto pvn_endfor;
- }
- }
- }
-pvn_endfor:
- if (offsetchar) {
- sscanf(offsetchar, "%d:%d", offset, length);
- return 1;
- } else {
- return 0;
- }
-}
-
-/*! \brief takes a substring. It is ok to call with value == workspace.
- *
- * offset < 0 means start from the end of the string and set the beginning
- * to be that many characters back.
- * length is the length of the substring, -1 means unlimited
- * (we take any negative value).
- * Always return a copy in workspace.
- */
-static char *substring(const char *value, int offset, int length, char *workspace, size_t workspace_len)
-{
- char *ret = workspace;
- int lr; /* length of the input string after the copy */
-
- ast_copy_string(workspace, value, workspace_len); /* always make a copy */
-
- if (offset == 0 && length < 0) /* take the whole string */
- return ret;
-
- lr = strlen(ret); /* compute length after copy, so we never go out of the workspace */
-
- if (offset < 0) { /* translate negative offset into positive ones */
- offset = lr + offset;
- if (offset < 0) /* If the negative offset was greater than the length of the string, just start at the beginning */
- offset = 0;
- }
-
- /* too large offset result in empty string so we know what to return */
- if (offset >= lr)
- return ret + lr; /* the final '\0' */
-
- ret += offset; /* move to the start position */
- if (length >= 0 && length < lr - offset) /* truncate if necessary */
- ret[length] = '\0';
-
- return ret;
-}
-
-/*! \brief pbx_retrieve_variable: Support for Asterisk built-in variables and
- functions in the dialplan
- ---*/
-void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
-{
- char tmpvar[80];
- time_t thistime;
- struct tm brokentime;
- int offset, offset2, isfunc;
- struct ast_var_t *variables;
-
- if (c)
- headp=&c->varshead;
- *ret=NULL;
- ast_copy_string(tmpvar, var, sizeof(tmpvar));
- if (parse_variable_name(tmpvar, &offset, &offset2, &isfunc)) {
- pbx_retrieve_variable(c, tmpvar, ret, workspace, workspacelen, headp);
- if (!(*ret))
- return;
- *ret = substring(*ret, offset, offset2, workspace, workspacelen);
- } else if (c && !strncmp(var, "CALL", 4)) {
- if (!strncmp(var + 4, "ER", 2)) {
- if (!strncmp(var + 6, "ID", 2)) {
- if (!var[8]) { /* CALLERID */
- if (c->cid.cid_num) {
- if (c->cid.cid_name) {
- snprintf(workspace, workspacelen, "\"%s\" <%s>", c->cid.cid_name, c->cid.cid_num);
- } else {
- ast_copy_string(workspace, c->cid.cid_num, workspacelen);
- }
- *ret = workspace;
- } else if (c->cid.cid_name) {
- ast_copy_string(workspace, c->cid.cid_name, workspacelen);
- *ret = workspace;
- } else
- *ret = NULL;
- } else if (!strcmp(var + 8, "NUM")) {
- /* CALLERIDNUM */
- if (c->cid.cid_num) {
- ast_copy_string(workspace, c->cid.cid_num, workspacelen);
- *ret = workspace;
- } else
- *ret = NULL;
- } else if (!strcmp(var + 8, "NAME")) {
- /* CALLERIDNAME */
- if (c->cid.cid_name) {
- ast_copy_string(workspace, c->cid.cid_name, workspacelen);
- *ret = workspace;
- } else
- *ret = NULL;
- }
- } else if (!strcmp(var + 6, "ANI")) {
- /* CALLERANI */
- if (c->cid.cid_ani) {
- ast_copy_string(workspace, c->cid.cid_ani, workspacelen);
- *ret = workspace;
- } else
- *ret = NULL;
- } else
- goto icky;
- } else if (!strncmp(var + 4, "ING", 3)) {
- if (!strcmp(var + 7, "PRES")) {
- /* CALLINGPRES */
- snprintf(workspace, workspacelen, "%d", c->cid.cid_pres);
- *ret = workspace;
- } else if (!strcmp(var + 7, "ANI2")) {
- /* CALLINGANI2 */
- snprintf(workspace, workspacelen, "%d", c->cid.cid_ani2);
- *ret = workspace;
- } else if (!strcmp(var + 7, "TON")) {
- /* CALLINGTON */
- snprintf(workspace, workspacelen, "%d", c->cid.cid_ton);
- *ret = workspace;
- } else if (!strcmp(var + 7, "TNS")) {
- /* CALLINGTNS */
- snprintf(workspace, workspacelen, "%d", c->cid.cid_tns);
- *ret = workspace;
- } else
- goto icky;
- } else
- goto icky;
- } else if (c && !strcmp(var, "DNID")) {
- if (c->cid.cid_dnid) {
- ast_copy_string(workspace, c->cid.cid_dnid, workspacelen);
- *ret = workspace;
- } else
- *ret = NULL;
- } else if (c && !strcmp(var, "HINT")) {
- if (!ast_get_hint(workspace, workspacelen, NULL, 0, c, c->context, c->exten))
- *ret = NULL;
- else
- *ret = workspace;
- } else if (c && !strcmp(var, "HINTNAME")) {
- if (!ast_get_hint(NULL, 0, workspace, workspacelen, c, c->context, c->exten))
- *ret = NULL;
- else
- *ret = workspace;
- } else if (c && !strcmp(var, "EXTEN")) {
- ast_copy_string(workspace, c->exten, workspacelen);
- *ret = workspace;
- } else if (c && !strcmp(var, "RDNIS")) {
- if (c->cid.cid_rdnis) {
- ast_copy_string(workspace, c->cid.cid_rdnis, workspacelen);
- *ret = workspace;
- } else
- *ret = NULL;
- } else if (c && !strcmp(var, "CONTEXT")) {
- ast_copy_string(workspace, c->context, workspacelen);
- *ret = workspace;
- } else if (c && !strcmp(var, "PRIORITY")) {
- snprintf(workspace, workspacelen, "%d", c->priority);
- *ret = workspace;
- } else if (c && !strcmp(var, "CHANNEL")) {
- ast_copy_string(workspace, c->name, workspacelen);
- *ret = workspace;
- } else if (!strcmp(var, "EPOCH")) {
- snprintf(workspace, workspacelen, "%u",(int)time(NULL));
- *ret = workspace;
- } else if (!strcmp(var, "DATETIME")) {
- thistime=time(NULL);
- localtime_r(&thistime, &brokentime);
- snprintf(workspace, workspacelen, "%02d%02d%04d-%02d:%02d:%02d",
- brokentime.tm_mday,
- brokentime.tm_mon+1,
- brokentime.tm_year+1900,
- brokentime.tm_hour,
- brokentime.tm_min,
- brokentime.tm_sec
- );
- *ret = workspace;
- } else if (!strcmp(var, "TIMESTAMP")) {
- thistime=time(NULL);
- localtime_r(&thistime, &brokentime);
- /* 20031130-150612 */
- snprintf(workspace, workspacelen, "%04d%02d%02d-%02d%02d%02d",
- brokentime.tm_year+1900,
- brokentime.tm_mon+1,
- brokentime.tm_mday,
- brokentime.tm_hour,
- brokentime.tm_min,
- brokentime.tm_sec
- );
- *ret = workspace;
- } else if (c && !strcmp(var, "UNIQUEID")) {
- snprintf(workspace, workspacelen, "%s", c->uniqueid);
- *ret = workspace;
- } else if (c && !strcmp(var, "HANGUPCAUSE")) {
- snprintf(workspace, workspacelen, "%d", c->hangupcause);
- *ret = workspace;
- } else if (c && !strcmp(var, "ACCOUNTCODE")) {
- ast_copy_string(workspace, c->accountcode, workspacelen);
- *ret = workspace;
- } else if (c && !strcmp(var, "LANGUAGE")) {
- ast_copy_string(workspace, c->language, workspacelen);
- *ret = workspace;
- } else {
-icky:
- if (headp) {
- AST_LIST_TRAVERSE(headp,variables,entries) {
-#if 0
- ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables));
-#endif
- if (strcasecmp(ast_var_name(variables),var)==0) {
- *ret=ast_var_value(variables);
- if (*ret) {
- ast_copy_string(workspace, *ret, workspacelen);
- *ret = workspace;
- }
- break;
- }
- }
- }
- if (!(*ret)) {
- /* Try globals */
- AST_LIST_TRAVERSE(&globals,variables,entries) {
-#if 0
- ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables));
-#endif
- if (strcasecmp(ast_var_name(variables),var)==0) {
- *ret = ast_var_value(variables);
- if (*ret) {
- ast_copy_string(workspace, *ret, workspacelen);
- *ret = workspace;
- }
- }
- }
- }
- }
-}
-
-/*! \brief CLI function to show installed custom functions
- \addtogroup CLI_functions
- */
-static int handle_show_functions(int fd, int argc, char *argv[])
-{
- struct ast_custom_function *acf;
- int count_acf = 0;
-
- ast_cli(fd, "Installed Custom Functions:\n--------------------------------------------------------------------------------\n");
- for (acf = acf_root ; acf; acf = acf->next) {
- ast_cli(fd, "%-20.20s %-35.35s %s\n", acf->name, acf->syntax, acf->synopsis);
- count_acf++;
- }
- ast_cli(fd, "%d custom functions installed.\n", count_acf);
- return 0;
-}
-
-static int handle_show_function(int fd, int argc, char *argv[])
-{
- struct ast_custom_function *acf;
- /* Maximum number of characters added by terminal coloring is 22 */
- char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40];
- char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL;
- char stxtitle[40], *syntax = NULL;
- int synopsis_size, description_size, syntax_size;
-
- if (argc < 3) return RESULT_SHOWUSAGE;
-
- if (!(acf = ast_custom_function_find(argv[2]))) {
- ast_cli(fd, "No function by that name registered.\n");
- return RESULT_FAILURE;
-
- }
-
- if (acf->synopsis)
- synopsis_size = strlen(acf->synopsis) + 23;
- else
- synopsis_size = strlen("Not available") + 23;
- synopsis = alloca(synopsis_size);
-
- if (acf->desc)
- description_size = strlen(acf->desc) + 23;
- else
- description_size = strlen("Not available") + 23;
- description = alloca(description_size);
-
- if (acf->syntax)
- syntax_size = strlen(acf->syntax) + 23;
- else
- syntax_size = strlen("Not available") + 23;
- syntax = alloca(syntax_size);
-
- snprintf(info, 64 + AST_MAX_APP, "\n -= Info about function '%s' =- \n\n", acf->name);
- term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22);
- term_color(stxtitle, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
- term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
- term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40);
- term_color(syntax,
- acf->syntax ? acf->syntax : "Not available",
- COLOR_CYAN, 0, syntax_size);
- term_color(synopsis,
- acf->synopsis ? acf->synopsis : "Not available",
- COLOR_CYAN, 0, synopsis_size);
- term_color(description,
- acf->desc ? acf->desc : "Not available",
- COLOR_CYAN, 0, description_size);
-
- ast_cli(fd,"%s%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, syntitle, synopsis, destitle, description);
-
- return RESULT_SUCCESS;
-}
-
-static char *complete_show_function(char *line, char *word, int pos, int state)
-{
- struct ast_custom_function *acf;
- int which = 0;
-
- /* try to lock functions list ... */
- if (ast_mutex_lock(&acflock)) {
- ast_log(LOG_ERROR, "Unable to lock function list\n");
- return NULL;
- }
-
- acf = acf_root;
- while (acf) {
- if (!strncasecmp(word, acf->name, strlen(word))) {
- if (++which > state) {
- char *ret = strdup(acf->name);
- ast_mutex_unlock(&acflock);
- return ret;
- }
- }
- acf = acf->next;
- }
-
- ast_mutex_unlock(&acflock);
- return NULL;
-}
-
-struct ast_custom_function* ast_custom_function_find(char *name)
-{
- struct ast_custom_function *acfptr;
-
- /* try to lock functions list ... */
- if (ast_mutex_lock(&acflock)) {
- ast_log(LOG_ERROR, "Unable to lock function list\n");
- return NULL;
- }
-
- for (acfptr = acf_root; acfptr; acfptr = acfptr->next) {
- if (!strcmp(name, acfptr->name)) {
- break;
- }
- }
-
- ast_mutex_unlock(&acflock);
-
- return acfptr;
-}
-
-int ast_custom_function_unregister(struct ast_custom_function *acf)
-{
- struct ast_custom_function *acfptr, *lastacf = NULL;
- int res = -1;
-
- if (!acf)
- return -1;
-
- /* try to lock functions list ... */
- if (ast_mutex_lock(&acflock)) {
- ast_log(LOG_ERROR, "Unable to lock function list\n");
- return -1;
- }
-
- for (acfptr = acf_root; acfptr; acfptr = acfptr->next) {
- if (acfptr == acf) {
- if (lastacf) {
- lastacf->next = acf->next;
- } else {
- acf_root = acf->next;
- }
- res = 0;
- break;
- }
- lastacf = acfptr;
- }
-
- ast_mutex_unlock(&acflock);
-
- if (!res && (option_verbose > 1))
- ast_verbose(VERBOSE_PREFIX_2 "Unregistered custom function %s\n", acf->name);
-
- return res;
-}
-
-int ast_custom_function_register(struct ast_custom_function *acf)
-{
- if (!acf)
- return -1;
-
- /* try to lock functions list ... */
- if (ast_mutex_lock(&acflock)) {
- ast_log(LOG_ERROR, "Unable to lock function list. Failed registering function %s\n", acf->name);
- return -1;
- }
-
- if (ast_custom_function_find(acf->name)) {
- ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name);
- ast_mutex_unlock(&acflock);
- return -1;
- }
-
- acf->next = acf_root;
- acf_root = acf;
-
- ast_mutex_unlock(&acflock);
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Registered custom function %s\n", acf->name);
-
- return 0;
-}
-
-char *ast_func_read(struct ast_channel *chan, const char *in, char *workspace, size_t len)
-{
- char *args = NULL, *function, *p;
- char *ret = "0";
- struct ast_custom_function *acfptr;
-
- function = ast_strdupa(in);
- if (!function) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return ret;
- }
- if ((args = strchr(function, '('))) {
- *args = '\0';
- args++;
- if ((p = strrchr(args, ')'))) {
- *p = '\0';
- } else {
- ast_log(LOG_WARNING, "Can't find trailing parenthesis?\n");
- }
- } else {
- ast_log(LOG_WARNING, "Function doesn't contain parentheses. Assuming null argument.\n");
- }
-
- if ((acfptr = ast_custom_function_find(function))) {
- /* run the custom function */
- if (acfptr->read) {
- return acfptr->read(chan, function, args, workspace, len);
- } else {
- ast_log(LOG_ERROR, "Function %s cannot be read\n", function);
- }
- } else {
- ast_log(LOG_ERROR, "Function %s not registered\n", function);
- }
- return ret;
-}
-
-void ast_func_write(struct ast_channel *chan, const char *in, const char *value)
-{
- char *args = NULL, *function, *p;
- struct ast_custom_function *acfptr;
-
- function = ast_strdupa(in);
- if (!function) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return;
- }
- if ((args = strchr(function, '('))) {
- *args = '\0';
- args++;
- if ((p = strrchr(args, ')'))) {
- *p = '\0';
- } else {
- ast_log(LOG_WARNING, "Can't find trailing parenthesis?\n");
- }
- } else {
- ast_log(LOG_WARNING, "Function doesn't contain parentheses. Assuming null argument.\n");
- }
-
- if ((acfptr = ast_custom_function_find(function))) {
- /* run the custom function */
- if (acfptr->write) {
- acfptr->write(chan, function, args, value);
- } else {
- ast_log(LOG_ERROR, "Function %s is read-only, it cannot be written to\n", function);
- }
- } else {
- ast_log(LOG_ERROR, "Function %s not registered\n", function);
- }
-}
-
-static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count)
-{
- char *cp4;
- const char *tmp, *whereweare;
- int length, offset, offset2, isfunction;
- char *workspace = NULL;
- char *ltmp = NULL, *var = NULL;
- char *nextvar, *nextexp, *nextthing;
- char *vars, *vare;
- int pos, brackets, needsub, len;
-
- /* Substitutes variables into cp2, based on string cp1, and assuming cp2 to be
- zero-filled */
- whereweare=tmp=cp1;
- while(!ast_strlen_zero(whereweare) && count) {
- /* Assume we're copying the whole remaining string */
- pos = strlen(whereweare);
- nextvar = NULL;
- nextexp = NULL;
- nextthing = strchr(whereweare, '$');
- if (nextthing) {
- switch(nextthing[1]) {
- case '{':
- nextvar = nextthing;
- pos = nextvar - whereweare;
- break;
- case '[':
- nextexp = nextthing;
- pos = nextexp - whereweare;
- break;
- }
- }
-
- if (pos) {
- /* Can't copy more than 'count' bytes */
- if (pos > count)
- pos = count;
-
- /* Copy that many bytes */
- memcpy(cp2, whereweare, pos);
-
- count -= pos;
- cp2 += pos;
- whereweare += pos;
- }
-
- if (nextvar) {
- /* We have a variable. Find the start and end, and determine
- if we are going to have to recursively call ourselves on the
- contents */
- vars = vare = nextvar + 2;
- brackets = 1;
- needsub = 0;
-
- /* Find the end of it */
- while(brackets && *vare) {
- if ((vare[0] == '$') && (vare[1] == '{')) {
- needsub++;
- brackets++;
- } else if (vare[0] == '}') {
- brackets--;
- } else if ((vare[0] == '$') && (vare[1] == '['))
- needsub++;
- vare++;
- }
- if (brackets)
- ast_log(LOG_NOTICE, "Error in extension logic (missing '}')\n");
- len = vare - vars - 1;
-
- /* Skip totally over variable string */
- whereweare += (len + 3);
-
- if (!var)
- var = alloca(VAR_BUF_SIZE);
-
- /* Store variable name (and truncate) */
- ast_copy_string(var, vars, len + 1);
-
- /* Substitute if necessary */
- if (needsub) {
- if (!ltmp)
- ltmp = alloca(VAR_BUF_SIZE);
-
- memset(ltmp, 0, VAR_BUF_SIZE);
- pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1);
- vars = ltmp;
- } else {
- vars = var;
- }
-
- if (!workspace)
- workspace = alloca(VAR_BUF_SIZE);
-
- workspace[0] = '\0';
-
- parse_variable_name(vars, &offset, &offset2, &isfunction);
- if (isfunction) {
- /* Evaluate function */
- cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE);
-
- ast_log(LOG_DEBUG, "Function result is '%s'\n", cp4 ? cp4 : "(null)");
- } else {
- /* Retrieve variable value */
- pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp);
- }
- if (cp4) {
- cp4 = substring(cp4, offset, offset2, workspace, VAR_BUF_SIZE);
-
- length = strlen(cp4);
- if (length > count)
- length = count;
- memcpy(cp2, cp4, length);
- count -= length;
- cp2 += length;
- }
- } else if (nextexp) {
- /* We have an expression. Find the start and end, and determine
- if we are going to have to recursively call ourselves on the
- contents */
- vars = vare = nextexp + 2;
- brackets = 1;
- needsub = 0;
-
- /* Find the end of it */
- while(brackets && *vare) {
- if ((vare[0] == '$') && (vare[1] == '[')) {
- needsub++;
- brackets++;
- vare++;
- } else if (vare[0] == '[') {
- brackets++;
- } else if (vare[0] == ']') {
- brackets--;
- } else if ((vare[0] == '$') && (vare[1] == '{')) {
- needsub++;
- vare++;
- }
- vare++;
- }
- if (brackets)
- ast_log(LOG_NOTICE, "Error in extension logic (missing ']')\n");
- len = vare - vars - 1;
-
- /* Skip totally over expression */
- whereweare += (len + 3);
-
- if (!var)
- var = alloca(VAR_BUF_SIZE);
-
- /* Store variable name (and truncate) */
- ast_copy_string(var, vars, len + 1);
-
- /* Substitute if necessary */
- if (needsub) {
- if (!ltmp)
- ltmp = alloca(VAR_BUF_SIZE);
-
- memset(ltmp, 0, VAR_BUF_SIZE);
- pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1);
- vars = ltmp;
- } else {
- vars = var;
- }
-
- length = ast_expr(vars, cp2, count);
-
- if (length) {
- ast_log(LOG_DEBUG, "Expression result is '%s'\n", cp2);
- count -= length;
- cp2 += length;
- }
- } else
- break;
- }
-}
-
-void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
-{
- pbx_substitute_variables_helper_full(c, (c) ? &c->varshead : NULL, cp1, cp2, count);
-}
-
-void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count)
-{
- pbx_substitute_variables_helper_full(NULL, headp, cp1, cp2, count);
-}
-
-static void pbx_substitute_variables(char *passdata, int datalen, struct ast_channel *c, struct ast_exten *e)
-{
- memset(passdata, 0, datalen);
-
- /* No variables or expressions in e->data, so why scan it? */
- if (!strchr(e->data, '$') && !strstr(e->data,"${") && !strstr(e->data,"$[") && !strstr(e->data,"$(")) {
- ast_copy_string(passdata, e->data, datalen);
- return;
- }
-
- pbx_substitute_variables_helper(c, e->data, passdata, datalen - 1);
-}
-
-static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con, const char *context, const char *exten, int priority, const char *label, const char *callerid, int action)
-{
- struct ast_exten *e;
- struct ast_app *app;
- struct ast_switch *sw;
- char *data;
- const char *foundcontext=NULL;
- int newstack = 0;
- int res;
- int status = 0;
- char *incstack[AST_PBX_MAX_STACK];
- char passdata[EXT_DATA_SIZE];
- int stacklen = 0;
- char tmp[80];
- char tmp2[80];
- char tmp3[EXT_DATA_SIZE];
- char atmp[80];
- char atmp2[EXT_DATA_SIZE+100];
-
- if (ast_mutex_lock(&conlock)) {
- ast_log(LOG_WARNING, "Unable to obtain lock\n");
- if ((action == HELPER_EXISTS) || (action == HELPER_CANMATCH) || (action == HELPER_MATCHMORE))
- return 0;
- else
- return -1;
- }
- e = pbx_find_extension(c, con, context, exten, priority, label, callerid, action, incstack, &stacklen, &status, &sw, &data, &foundcontext);
- if (e) {
- switch(action) {
- case HELPER_CANMATCH:
- ast_mutex_unlock(&conlock);
- return -1;
- case HELPER_EXISTS:
- ast_mutex_unlock(&conlock);
- return -1;
- case HELPER_FINDLABEL:
- res = e->priority;
- ast_mutex_unlock(&conlock);
- return res;
- case HELPER_MATCHMORE:
- ast_mutex_unlock(&conlock);
- return -1;
- case HELPER_SPAWN:
- newstack++;
- /* Fall through */
- case HELPER_EXEC:
- app = pbx_findapp(e->app);
- ast_mutex_unlock(&conlock);
- if (app) {
- if (c->context != context)
- ast_copy_string(c->context, context, sizeof(c->context));
- if (c->exten != exten)
- ast_copy_string(c->exten, exten, sizeof(c->exten));
- c->priority = priority;
- pbx_substitute_variables(passdata, sizeof(passdata), c, e);
- if (option_debug) {
- ast_log(LOG_DEBUG, "Launching '%s'\n", app->name);
- snprintf(atmp, 80, "STACK-%s-%s-%d", context, exten, priority);
- snprintf(atmp2, EXT_DATA_SIZE+100, "%s(\"%s\", \"%s\") %s", app->name, c->name, (!ast_strlen_zero(passdata) ? (char *)passdata : ""), (newstack ? "in new stack" : "in same stack"));
- pbx_builtin_setvar_helper(c, atmp, atmp2);
- }
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Executing %s(\"%s\", \"%s\") %s\n",
- term_color(tmp, app->name, COLOR_BRCYAN, 0, sizeof(tmp)),
- term_color(tmp2, c->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
- term_color(tmp3, (!ast_strlen_zero(passdata) ? (char *)passdata : ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)),
- (newstack ? "in new stack" : "in same stack"));
- manager_event(EVENT_FLAG_CALL, "Newexten",
- "Channel: %s\r\n"
- "Context: %s\r\n"
- "Extension: %s\r\n"
- "Priority: %d\r\n"
- "Application: %s\r\n"
- "AppData: %s\r\n"
- "Uniqueid: %s\r\n",
- c->name, c->context, c->exten, c->priority, app->name, passdata ? passdata : "(NULL)", c->uniqueid);
- res = pbx_exec(c, app, passdata, newstack);
- return res;
- } else {
- ast_log(LOG_WARNING, "No application '%s' for extension (%s, %s, %d)\n", e->app, context, exten, priority);
- return -1;
- }
- default:
- ast_log(LOG_WARNING, "Huh (%d)?\n", action); return -1;
- }
- } else if (sw) {
- switch(action) {
- case HELPER_CANMATCH:
- ast_mutex_unlock(&conlock);
- return -1;
- case HELPER_EXISTS:
- ast_mutex_unlock(&conlock);
- return -1;
- case HELPER_MATCHMORE:
- ast_mutex_unlock(&conlock);
- return -1;
- case HELPER_FINDLABEL:
- ast_mutex_unlock(&conlock);
- return -1;
- case HELPER_SPAWN:
- newstack++;
- /* Fall through */
- case HELPER_EXEC:
- ast_mutex_unlock(&conlock);
- if (sw->exec)
- res = sw->exec(c, foundcontext ? foundcontext : context, exten, priority, callerid, newstack, data);
- else {
- ast_log(LOG_WARNING, "No execution engine for switch %s\n", sw->name);
- res = -1;
- }
- return res;
- default:
- ast_log(LOG_WARNING, "Huh (%d)?\n", action);
- return -1;
- }
- } else {
- ast_mutex_unlock(&conlock);
- switch(status) {
- case STATUS_NO_CONTEXT:
- if ((action != HELPER_EXISTS) && (action != HELPER_MATCHMORE))
- ast_log(LOG_NOTICE, "Cannot find extension context '%s'\n", context);
- break;
- case STATUS_NO_EXTENSION:
- if ((action != HELPER_EXISTS) && (action != HELPER_CANMATCH) && (action != HELPER_MATCHMORE))
- ast_log(LOG_NOTICE, "Cannot find extension '%s' in context '%s'\n", exten, context);
- break;
- case STATUS_NO_PRIORITY:
- if ((action != HELPER_EXISTS) && (action != HELPER_CANMATCH) && (action != HELPER_MATCHMORE))
- ast_log(LOG_NOTICE, "No such priority %d in extension '%s' in context '%s'\n", priority, exten, context);
- break;
- case STATUS_NO_LABEL:
- if (context)
- ast_log(LOG_NOTICE, "No such label '%s' in extension '%s' in context '%s'\n", label, exten, context);
- break;
- default:
- ast_log(LOG_DEBUG, "Shouldn't happen!\n");
- }
-
- if ((action != HELPER_EXISTS) && (action != HELPER_CANMATCH) && (action != HELPER_MATCHMORE))
- return -1;
- else
- return 0;
- }
-
-}
-
-/*! \brief ast_hint_extension: Find hint for given extension in context */
-static struct ast_exten *ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
-{
- struct ast_exten *e;
- struct ast_switch *sw;
- char *data;
- const char *foundcontext = NULL;
- int status = 0;
- char *incstack[AST_PBX_MAX_STACK];
- int stacklen = 0;
-
- if (ast_mutex_lock(&conlock)) {
- ast_log(LOG_WARNING, "Unable to obtain lock\n");
- return NULL;
- }
- e = pbx_find_extension(c, NULL, context, exten, PRIORITY_HINT, NULL, "", HELPER_EXISTS, incstack, &stacklen, &status, &sw, &data, &foundcontext);
- ast_mutex_unlock(&conlock);
- return e;
-}
-
-/*! \brief ast_extensions_state2: Check state of extension by using hints */
-static int ast_extension_state2(struct ast_exten *e)
-{
- char hint[AST_MAX_EXTENSION] = "";
- char *cur, *rest;
- int res = -1;
- int allunavailable = 1, allbusy = 1, allfree = 1;
- int busy = 0, inuse = 0, ring = 0;
-
- if (!e)
- return -1;
-
- ast_copy_string(hint, ast_get_extension_app(e), sizeof(hint));
-
- cur = hint; /* On or more devices separated with a & character */
- do {
- rest = strchr(cur, '&');
- if (rest) {
- *rest = 0;
- rest++;
- }
-
- res = ast_device_state(cur);
- switch (res) {
- case AST_DEVICE_NOT_INUSE:
- allunavailable = 0;
- allbusy = 0;
- break;
- case AST_DEVICE_INUSE:
- inuse = 1;
- allunavailable = 0;
- allfree = 0;
- break;
- case AST_DEVICE_RINGING:
- ring = 1;
- allunavailable = 0;
- allfree = 0;
- break;
- case AST_DEVICE_BUSY:
- allunavailable = 0;
- allfree = 0;
- busy = 1;
- break;
- case AST_DEVICE_UNAVAILABLE:
- case AST_DEVICE_INVALID:
- allbusy = 0;
- allfree = 0;
- break;
- default:
- allunavailable = 0;
- allbusy = 0;
- allfree = 0;
- }
- cur = rest;
- } while (cur);
-
- if (!inuse && ring)
- return AST_EXTENSION_RINGING;
- if (inuse && ring)
- return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING);
- if (inuse)
- return AST_EXTENSION_INUSE;
- if (allfree)
- return AST_EXTENSION_NOT_INUSE;
- if (allbusy)
- return AST_EXTENSION_BUSY;
- if (allunavailable)
- return AST_EXTENSION_UNAVAILABLE;
- if (busy)
- return AST_EXTENSION_INUSE;
-
- return AST_EXTENSION_NOT_INUSE;
-}
-
-/*! \brief ast_extension_state2str: Return extension_state as string */
-const char *ast_extension_state2str(int extension_state)
-{
- int i;
-
- for (i = 0; (i < (sizeof(extension_states) / sizeof(extension_states[0]))); i++) {
- if (extension_states[i].extension_state == extension_state) {
- return extension_states[i].text;
- }
- }
- return "Unknown";
-}
-
-/*! \brief ast_extension_state: Check extension state for an extension by using hint */
-int ast_extension_state(struct ast_channel *c, char *context, char *exten)
-{
- struct ast_exten *e;
-
- e = ast_hint_extension(c, context, exten); /* Do we have a hint for this extension ? */
- if (!e)
- return -1; /* No hint, return -1 */
-
- return ast_extension_state2(e); /* Check all devices in the hint */
-}
-
-void ast_hint_state_changed(const char *device)
-{
- struct ast_hint *hint;
- struct ast_state_cb *cblist;
- char buf[AST_MAX_EXTENSION];
- char *parse;
- char *cur;
- int state;
-
- ast_mutex_lock(&hintlock);
-
- for (hint = hints; hint; hint = hint->next) {
- ast_copy_string(buf, ast_get_extension_app(hint->exten), sizeof(buf));
- parse = buf;
- for (cur = strsep(&parse, "&"); cur; cur = strsep(&parse, "&")) {
- if (strcasecmp(cur, device))
- continue;
-
- /* Get device state for this hint */
- state = ast_extension_state2(hint->exten);
-
- if ((state == -1) || (state == hint->laststate))
- continue;
-
- /* Device state changed since last check - notify the watchers */
-
- /* For general callbacks */
- for (cblist = statecbs; cblist; cblist = cblist->next)
- cblist->callback(hint->exten->parent->name, hint->exten->exten, state, cblist->data);
-
- /* For extension callbacks */
- for (cblist = hint->callbacks; cblist; cblist = cblist->next)
- cblist->callback(hint->exten->parent->name, hint->exten->exten, state, cblist->data);
-
- hint->laststate = state;
- break;
- }
- }
-
- ast_mutex_unlock(&hintlock);
-}
-
-/*! \brief ast_extension_state_add: Add watcher for extension states */
-int ast_extension_state_add(const char *context, const char *exten,
- ast_state_cb_type callback, void *data)
-{
- struct ast_hint *list;
- struct ast_state_cb *cblist;
- struct ast_exten *e;
-
- /* If there's no context and extension: add callback to statecbs list */
- if (!context && !exten) {
- ast_mutex_lock(&hintlock);
-
- cblist = statecbs;
- while (cblist) {
- if (cblist->callback == callback) {
- cblist->data = data;
- ast_mutex_unlock(&hintlock);
- return 0;
- }
- cblist = cblist->next;
- }
-
- /* Now insert the callback */
- cblist = malloc(sizeof(struct ast_state_cb));
- if (!cblist) {
- ast_mutex_unlock(&hintlock);
- return -1;
- }
- memset(cblist, 0, sizeof(struct ast_state_cb));
- cblist->id = 0;
- cblist->callback = callback;
- cblist->data = data;
-
- cblist->next = statecbs;
- statecbs = cblist;
-
- ast_mutex_unlock(&hintlock);
- return 0;
- }
-
- if (!context || !exten)
- return -1;
-
- /* This callback type is for only one hint, so get the hint */
- e = ast_hint_extension(NULL, context, exten);
- if (!e) {
- return -1;
- }
-
- /* Find the hint in the list of hints */
- ast_mutex_lock(&hintlock);
- list = hints;
-
- while (list) {
- if (list->exten == e)
- break;
- list = list->next;
- }
-
- if (!list) {
- /* We have no hint, sorry */
- ast_mutex_unlock(&hintlock);
- return -1;
- }
-
- /* Now insert the callback in the callback list */
- cblist = malloc(sizeof(struct ast_state_cb));
- if (!cblist) {
- ast_mutex_unlock(&hintlock);
- return -1;
- }
- memset(cblist, 0, sizeof(struct ast_state_cb));
- cblist->id = stateid++; /* Unique ID for this callback */
- cblist->callback = callback; /* Pointer to callback routine */
- cblist->data = data; /* Data for the callback */
-
- cblist->next = list->callbacks;
- list->callbacks = cblist;
-
- ast_mutex_unlock(&hintlock);
- return cblist->id;
-}
-
-/*! \brief ast_extension_state_del: Remove a watcher from the callback list */
-int ast_extension_state_del(int id, ast_state_cb_type callback)
-{
- struct ast_hint *list;
- struct ast_state_cb *cblist, *cbprev;
-
- if (!id && !callback)
- return -1;
-
- ast_mutex_lock(&hintlock);
-
- /* id is zero is a callback without extension */
- if (!id) {
- cbprev = NULL;
- cblist = statecbs;
- while (cblist) {
- if (cblist->callback == callback) {
- if (!cbprev)
- statecbs = cblist->next;
- else
- cbprev->next = cblist->next;
-
- free(cblist);
-
- ast_mutex_unlock(&hintlock);
- return 0;
- }
- cbprev = cblist;
- cblist = cblist->next;
- }
-
- ast_mutex_unlock(&hintlock);
- return -1;
- }
-
- /* id greater than zero is a callback with extension */
- /* Find the callback based on ID */
- list = hints;
- while (list) {
- cblist = list->callbacks;
- cbprev = NULL;
- while (cblist) {
- if (cblist->id==id) {
- if (!cbprev)
- list->callbacks = cblist->next;
- else
- cbprev->next = cblist->next;
-
- free(cblist);
-
- ast_mutex_unlock(&hintlock);
- return 0;
- }
- cbprev = cblist;
- cblist = cblist->next;
- }
- list = list->next;
- }
-
- ast_mutex_unlock(&hintlock);
- return -1;
-}
-
-/*! \brief ast_add_hint: Add hint to hint list, check initial extension state */
-static int ast_add_hint(struct ast_exten *e)
-{
- struct ast_hint *list;
-
- if (!e)
- return -1;
-
- ast_mutex_lock(&hintlock);
- list = hints;
-
- /* Search if hint exists, do nothing */
- while (list) {
- if (list->exten == e) {
- ast_mutex_unlock(&hintlock);
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "HINTS: Not re-adding existing hint %s: %s\n", ast_get_extension_name(e), ast_get_extension_app(e));
- return -1;
- }
- list = list->next;
- }
-
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "HINTS: Adding hint %s: %s\n", ast_get_extension_name(e), ast_get_extension_app(e));
-
- list = malloc(sizeof(struct ast_hint));
- if (!list) {
- ast_mutex_unlock(&hintlock);
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "HINTS: Out of memory...\n");
- return -1;
- }
- /* Initialize and insert new item at the top */
- memset(list, 0, sizeof(struct ast_hint));
- list->exten = e;
- list->laststate = ast_extension_state2(e);
- list->next = hints;
- hints = list;
-
- ast_mutex_unlock(&hintlock);
- return 0;
-}
-
-/*! \brief ast_change_hint: Change hint for an extension */
-static int ast_change_hint(struct ast_exten *oe, struct ast_exten *ne)
-{
- struct ast_hint *list;
-
- ast_mutex_lock(&hintlock);
- list = hints;
-
- while(list) {
- if (list->exten == oe) {
- list->exten = ne;
- ast_mutex_unlock(&hintlock);
- return 0;
- }
- list = list->next;
- }
- ast_mutex_unlock(&hintlock);
-
- return -1;
-}
-
-/*! \brief ast_remove_hint: Remove hint from extension */
-static int ast_remove_hint(struct ast_exten *e)
-{
- /* Cleanup the Notifys if hint is removed */
- struct ast_hint *list, *prev = NULL;
- struct ast_state_cb *cblist, *cbprev;
-
- if (!e)
- return -1;
-
- ast_mutex_lock(&hintlock);
-
- list = hints;
- while(list) {
- if (list->exten==e) {
- cbprev = NULL;
- cblist = list->callbacks;
- while (cblist) {
- /* Notify with -1 and remove all callbacks */
- cbprev = cblist;
- cblist = cblist->next;
- cbprev->callback(list->exten->parent->name, list->exten->exten, AST_EXTENSION_DEACTIVATED, cbprev->data);
- free(cbprev);
- }
- list->callbacks = NULL;
-
- if (!prev)
- hints = list->next;
- else
- prev->next = list->next;
- free(list);
-
- ast_mutex_unlock(&hintlock);
- return 0;
- } else {
- prev = list;
- list = list->next;
- }
- }
-
- ast_mutex_unlock(&hintlock);
- return -1;
-}
-
-
-/*! \brief ast_get_hint: Get hint for channel */
-int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
-{
- struct ast_exten *e;
- void *tmp;
-
- e = ast_hint_extension(c, context, exten);
- if (e) {
- if (hint)
- ast_copy_string(hint, ast_get_extension_app(e), hintsize);
- if (name) {
- tmp = ast_get_extension_app_data(e);
- if (tmp)
- ast_copy_string(name, (char *) tmp, namesize);
- }
- return -1;
- }
- return 0;
-}
-
-int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
-{
- return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_EXISTS);
-}
-
-int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
-{
- return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, HELPER_FINDLABEL);
-}
-
-int ast_findlabel_extension2(struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid)
-{
- return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, HELPER_FINDLABEL);
-}
-
-int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
-{
- return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_CANMATCH);
-}
-
-int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
-{
- return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_MATCHMORE);
-}
-
-int ast_spawn_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
-{
- return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_SPAWN);
-}
-
-int ast_exec_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
-{
- return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_EXEC);
-}
-
-static int __ast_pbx_run(struct ast_channel *c)
-{
- int firstpass = 1;
- int digit;
- char exten[256];
- int pos;
- int waittime;
- int res=0;
- int autoloopflag;
-
- /* A little initial setup here */
- if (c->pbx)
- ast_log(LOG_WARNING, "%s already has PBX structure??\n", c->name);
- c->pbx = malloc(sizeof(struct ast_pbx));
- if (!c->pbx) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
- if (c->amaflags) {
- if (!c->cdr) {
- c->cdr = ast_cdr_alloc();
- if (!c->cdr) {
- ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
- free(c->pbx);
- return -1;
- }
- ast_cdr_init(c->cdr, c);
- }
- }
- memset(c->pbx, 0, sizeof(struct ast_pbx));
- /* Set reasonable defaults */
- c->pbx->rtimeout = 10;
- c->pbx->dtimeout = 5;
-
- autoloopflag = ast_test_flag(c, AST_FLAG_IN_AUTOLOOP);
- ast_set_flag(c, AST_FLAG_IN_AUTOLOOP);
-
- /* Start by trying whatever the channel is set to */
- if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
- /* If not successful fall back to 's' */
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d failed so falling back to exten 's'\n", c->name, c->context, c->exten, c->priority);
- ast_copy_string(c->exten, "s", sizeof(c->exten));
- if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
- /* JK02: And finally back to default if everything else failed */
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d still failed so falling back to context 'default'\n", c->name, c->context, c->exten, c->priority);
- ast_copy_string(c->context, "default", sizeof(c->context));
- }
- c->priority = 1;
- }
- if (c->cdr && !c->cdr->start.tv_sec && !c->cdr->start.tv_usec)
- ast_cdr_start(c->cdr);
- for(;;) {
- pos = 0;
- digit = 0;
- while(ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
- memset(exten, 0, sizeof(exten));
- if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
- /* Something bad happened, or a hangup has been requested. */
- if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) ||
- (res == '*') || (res == '#')) {
- ast_log(LOG_DEBUG, "Oooh, got something to jump out with ('%c')!\n", res);
- memset(exten, 0, sizeof(exten));
- pos = 0;
- exten[pos++] = digit = res;
- break;
- }
- switch(res) {
- case AST_PBX_KEEPALIVE:
- if (option_debug)
- ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
- else if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
- goto out;
- break;
- default:
- if (option_debug)
- ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
- else if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
- if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
- c->_softhangup =0;
- break;
- }
- /* atimeout */
- if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
- break;
- }
-
- if (c->cdr) {
- ast_cdr_update(c);
- }
- goto out;
- }
- }
- if ((c->_softhangup == AST_SOFTHANGUP_TIMEOUT) && (ast_exists_extension(c,c->context,"T",1,c->cid.cid_num))) {
- ast_copy_string(c->exten, "T", sizeof(c->exten));
- /* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
- c->whentohangup = 0;
- c->priority = 0;
- c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
- } else if (c->_softhangup) {
- ast_log(LOG_DEBUG, "Extension %s, priority %d returned normally even though call was hung up\n",
- c->exten, c->priority);
- goto out;
- }
- firstpass = 0;
- c->priority++;
- }
- if (!ast_exists_extension(c, c->context, c->exten, 1, c->cid.cid_num)) {
- /* It's not a valid extension anymore */
- if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Sent into invalid extension '%s' in context '%s' on %s\n", c->exten, c->context, c->name);
- pbx_builtin_setvar_helper(c, "INVALID_EXTEN", c->exten);
- ast_copy_string(c->exten, "i", sizeof(c->exten));
- c->priority = 1;
- } else {
- ast_log(LOG_WARNING, "Channel '%s' sent into invalid extension '%s' in context '%s', but no invalid handler\n",
- c->name, c->exten, c->context);
- goto out;
- }
- } else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
- /* If we get this far with AST_SOFTHANGUP_TIMEOUT, then we know that the "T" extension is next. */
- c->_softhangup = 0;
- } else {
- /* Done, wait for an extension */
- waittime = 0;
- if (digit)
- waittime = c->pbx->dtimeout;
- else if (!autofallthrough)
- waittime = c->pbx->rtimeout;
- if (waittime) {
- while (ast_matchmore_extension(c, c->context, exten, 1, c->cid.cid_num)) {
- /* As long as we're willing to wait, and as long as it's not defined,
- keep reading digits until we can't possibly get a right answer anymore. */
- digit = ast_waitfordigit(c, waittime * 1000);
- if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
- c->_softhangup = 0;
- } else {
- if (!digit)
- /* No entry */
- break;
- if (digit < 0)
- /* Error, maybe a hangup */
- goto out;
- exten[pos++] = digit;
- waittime = c->pbx->dtimeout;
- }
- }
- if (ast_exists_extension(c, c->context, exten, 1, c->cid.cid_num)) {
- /* Prepare the next cycle */
- ast_copy_string(c->exten, exten, sizeof(c->exten));
- c->priority = 1;
- } else {
- /* No such extension */
- if (!ast_strlen_zero(exten)) {
- /* An invalid extension */
- if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Invalid extension '%s' in context '%s' on %s\n", exten, c->context, c->name);
- pbx_builtin_setvar_helper(c, "INVALID_EXTEN", exten);
- ast_copy_string(c->exten, "i", sizeof(c->exten));
- c->priority = 1;
- } else {
- ast_log(LOG_WARNING, "Invalid extension '%s', but no rule 'i' in context '%s'\n", exten, c->context);
- goto out;
- }
- } else {
- /* A simple timeout */
- if (ast_exists_extension(c, c->context, "t", 1, c->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Timeout on %s\n", c->name);
- ast_copy_string(c->exten, "t", sizeof(c->exten));
- c->priority = 1;
- } else {
- ast_log(LOG_WARNING, "Timeout, but no rule 't' in context '%s'\n", c->context);
- goto out;
- }
- }
- }
- if (c->cdr) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_2 "CDR updated on %s\n",c->name);
- ast_cdr_update(c);
- }
- } else {
- char *status;
-
- status = pbx_builtin_getvar_helper(c, "DIALSTATUS");
- if (!status)
- status = "UNKNOWN";
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_2 "Auto fallthrough, channel '%s' status is '%s'\n", c->name, status);
- if (!strcasecmp(status, "CONGESTION"))
- res = pbx_builtin_congestion(c, "10");
- else if (!strcasecmp(status, "CHANUNAVAIL"))
- res = pbx_builtin_congestion(c, "10");
- else if (!strcasecmp(status, "BUSY"))
- res = pbx_builtin_busy(c, "10");
- goto out;
- }
- }
- }
- if (firstpass)
- ast_log(LOG_WARNING, "Don't know what to do with '%s'\n", c->name);
-out:
- if ((res != AST_PBX_KEEPALIVE) && ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num)) {
- c->exten[0] = 'h';
- c->exten[1] = '\0';
- c->priority = 1;
- while(ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
- if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
- /* Something bad happened, or a hangup has been requested. */
- if (option_debug)
- ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
- else if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
- break;
- }
- c->priority++;
- }
- }
- ast_set2_flag(c, autoloopflag, AST_FLAG_IN_AUTOLOOP);
-
- pbx_destroy(c->pbx);
- c->pbx = NULL;
- if (res != AST_PBX_KEEPALIVE)
- ast_hangup(c);
- return 0;
-}
-
-/* Returns 0 on success, non-zero if call limit was reached */
-static int increase_call_count(const struct ast_channel *c)
-{
- int failed = 0;
- double curloadavg;
- ast_mutex_lock(&maxcalllock);
- if (option_maxcalls) {
- if (countcalls >= option_maxcalls) {
- ast_log(LOG_NOTICE, "Maximum call limit of %d calls exceeded by '%s'!\n", option_maxcalls, c->name);
- failed = -1;
- }
- }
- if (option_maxload) {
- getloadavg(&curloadavg, 1);
- if (curloadavg >= option_maxload) {
- ast_log(LOG_NOTICE, "Maximum loadavg limit of %lf load exceeded by '%s' (currently %f)!\n", option_maxload, c->name, curloadavg);
- failed = -1;
- }
- }
- if (!failed)
- countcalls++;
- ast_mutex_unlock(&maxcalllock);
-
- return failed;
-}
-
-static void decrease_call_count(void)
-{
- ast_mutex_lock(&maxcalllock);
- if (countcalls > 0)
- countcalls--;
- ast_mutex_unlock(&maxcalllock);
-}
-
-static void *pbx_thread(void *data)
-{
- /* Oh joyeous kernel, we're a new thread, with nothing to do but
- answer this channel and get it going.
- */
- /* NOTE:
- The launcher of this function _MUST_ increment 'countcalls'
- before invoking the function; it will be decremented when the
- PBX has finished running on the channel
- */
- struct ast_channel *c = data;
-
- __ast_pbx_run(c);
- decrease_call_count();
-
- pthread_exit(NULL);
-
- return NULL;
-}
-
-enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
-{
- pthread_t t;
- pthread_attr_t attr;
-
- if (!c) {
- ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
- return AST_PBX_FAILED;
- }
-
- if (increase_call_count(c))
- return AST_PBX_CALL_LIMIT;
-
- /* Start a new thread, and get something handling this channel. */
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&t, &attr, pbx_thread, c)) {
- ast_log(LOG_WARNING, "Failed to create new channel thread\n");
- return AST_PBX_FAILED;
- }
-
- return AST_PBX_SUCCESS;
-}
-
-enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
-{
- enum ast_pbx_result res = AST_PBX_SUCCESS;
-
- if (increase_call_count(c))
- return AST_PBX_CALL_LIMIT;
-
- res = __ast_pbx_run(c);
- decrease_call_count();
-
- return res;
-}
-
-int ast_active_calls(void)
-{
- return countcalls;
-}
-
-int pbx_set_autofallthrough(int newval)
-{
- int oldval;
- oldval = autofallthrough;
- if (oldval != newval)
- autofallthrough = newval;
- return oldval;
-}
-
-/*
- * This function locks contexts list by &conlist, search for the right context
- * structure, leave context list locked and call ast_context_remove_include2
- * which removes include, unlock contexts list and return ...
- */
-int ast_context_remove_include(const char *context, const char *include, const char *registrar)
-{
- struct ast_context *c;
-
- if (ast_lock_contexts()) return -1;
-
- /* walk contexts and search for the right one ...*/
- c = ast_walk_contexts(NULL);
- while (c) {
- /* we found one ... */
- if (!strcmp(ast_get_context_name(c), context)) {
- int ret;
- /* remove include from this context ... */
- ret = ast_context_remove_include2(c, include, registrar);
-
- ast_unlock_contexts();
-
- /* ... return results */
- return ret;
- }
- c = ast_walk_contexts(c);
- }
-
- /* we can't find the right one context */
- ast_unlock_contexts();
- return -1;
-}
-
-/*
- * When we call this function, &conlock lock must be locked, because when
- * we giving *con argument, some process can remove/change this context
- * and after that there can be segfault.
- *
- * This function locks given context, removes include, unlock context and
- * return.
- */
-int ast_context_remove_include2(struct ast_context *con, const char *include, const char *registrar)
-{
- struct ast_include *i, *pi = NULL;
-
- if (ast_mutex_lock(&con->lock)) return -1;
-
- /* walk includes */
- i = con->includes;
- while (i) {
- /* find our include */
- if (!strcmp(i->name, include) &&
- (!registrar || !strcmp(i->registrar, registrar))) {
- /* remove from list */
- if (pi)
- pi->next = i->next;
- else
- con->includes = i->next;
- /* free include and return */
- free(i);
- ast_mutex_unlock(&con->lock);
- return 0;
- }
- pi = i;
- i = i->next;
- }
-
- /* we can't find the right include */
- ast_mutex_unlock(&con->lock);
- return -1;
-}
-
-/*!
- * \note This function locks contexts list by &conlist, search for the rigt context
- * structure, leave context list locked and call ast_context_remove_switch2
- * which removes switch, unlock contexts list and return ...
- */
-int ast_context_remove_switch(const char *context, const char *sw, const char *data, const char *registrar)
-{
- struct ast_context *c;
-
- if (ast_lock_contexts()) return -1;
-
- /* walk contexts and search for the right one ...*/
- c = ast_walk_contexts(NULL);
- while (c) {
- /* we found one ... */
- if (!strcmp(ast_get_context_name(c), context)) {
- int ret;
- /* remove switch from this context ... */
- ret = ast_context_remove_switch2(c, sw, data, registrar);
-
- ast_unlock_contexts();
-
- /* ... return results */
- return ret;
- }
- c = ast_walk_contexts(c);
- }
-
- /* we can't find the right one context */
- ast_unlock_contexts();
- return -1;
-}
-
-/*!
- * \brief This function locks given context, removes switch, unlock context and
- * return.
- * \note When we call this function, &conlock lock must be locked, because when
- * we giving *con argument, some process can remove/change this context
- * and after that there can be segfault.
- *
- */
-int ast_context_remove_switch2(struct ast_context *con, const char *sw, const char *data, const char *registrar)
-{
- struct ast_sw *i, *pi = NULL;
-
- if (ast_mutex_lock(&con->lock)) return -1;
-
- /* walk switchs */
- i = con->alts;
- while (i) {
- /* find our switch */
- if (!strcmp(i->name, sw) && !strcmp(i->data, data) &&
- (!registrar || !strcmp(i->registrar, registrar))) {
- /* remove from list */
- if (pi)
- pi->next = i->next;
- else
- con->alts = i->next;
- /* free switch and return */
- free(i);
- ast_mutex_unlock(&con->lock);
- return 0;
- }
- pi = i;
- i = i->next;
- }
-
- /* we can't find the right switch */
- ast_mutex_unlock(&con->lock);
- return -1;
-}
-
-/*
- * \note This functions lock contexts list, search for the right context,
- * call ast_context_remove_extension2, unlock contexts list and return.
- * In this function we are using
- */
-int ast_context_remove_extension(const char *context, const char *extension, int priority, const char *registrar)
-{
- struct ast_context *c;
-
- if (ast_lock_contexts()) return -1;
-
- /* walk contexts ... */
- c = ast_walk_contexts(NULL);
- while (c) {
- /* ... search for the right one ... */
- if (!strcmp(ast_get_context_name(c), context)) {
- /* ... remove extension ... */
- int ret = ast_context_remove_extension2(c, extension, priority,
- registrar);
- /* ... unlock contexts list and return */
- ast_unlock_contexts();
- return ret;
- }
- c = ast_walk_contexts(c);
- }
-
- /* we can't find the right context */
- ast_unlock_contexts();
- return -1;
-}
-
-/*!
- * \brief This functionc locks given context, search for the right extension and
- * fires out all peer in this extensions with given priority. If priority
- * is set to 0, all peers are removed. After that, unlock context and
- * return.
- * \note When do you want to call this function, make sure that &conlock is locked,
- * because some process can handle with your *con context before you lock
- * it.
- *
- */
-int ast_context_remove_extension2(struct ast_context *con, const char *extension, int priority, const char *registrar)
-{
- struct ast_exten *exten, *prev_exten = NULL;
-
- if (ast_mutex_lock(&con->lock)) return -1;
-
- /* go through all extensions in context and search the right one ... */
- exten = con->root;
- while (exten) {
-
- /* look for right extension */
- if (!strcmp(exten->exten, extension) &&
- (!registrar || !strcmp(exten->registrar, registrar))) {
- struct ast_exten *peer;
-
- /* should we free all peers in this extension? (priority == 0)? */
- if (priority == 0) {
- /* remove this extension from context list */
- if (prev_exten)
- prev_exten->next = exten->next;
- else
- con->root = exten->next;
-
- /* fire out all peers */
- peer = exten;
- while (peer) {
- exten = peer->peer;
-
- if (!peer->priority==PRIORITY_HINT)
- ast_remove_hint(peer);
-
- peer->datad(peer->data);
- free(peer);
-
- peer = exten;
- }
-
- ast_mutex_unlock(&con->lock);
- return 0;
- } else {
- /* remove only extension with exten->priority == priority */
- struct ast_exten *previous_peer = NULL;
-
- peer = exten;
- while (peer) {
- /* is this our extension? */
- if (peer->priority == priority &&
- (!registrar || !strcmp(peer->registrar, registrar) )) {
- /* we are first priority extension? */
- if (!previous_peer) {
- /* exists previous extension here? */
- if (prev_exten) {
- /* yes, so we must change next pointer in
- * previous connection to next peer
- */
- if (peer->peer) {
- prev_exten->next = peer->peer;
- peer->peer->next = exten->next;
- } else
- prev_exten->next = exten->next;
- } else {
- /* no previous extension, we are first
- * extension, so change con->root ...
- */
- if (peer->peer)
- con->root = peer->peer;
- else
- con->root = exten->next;
- }
- } else {
- /* we are not first priority in extension */
- previous_peer->peer = peer->peer;
- }
-
- /* now, free whole priority extension */
- if (peer->priority==PRIORITY_HINT)
- ast_remove_hint(peer);
- peer->datad(peer->data);
- free(peer);
-
- ast_mutex_unlock(&con->lock);
- return 0;
- } else {
- /* this is not right extension, skip to next peer */
- previous_peer = peer;
- peer = peer->peer;
- }
- }
-
- ast_mutex_unlock(&con->lock);
- return -1;
- }
- }
-
- prev_exten = exten;
- exten = exten->next;
- }
-
- /* we can't find right extension */
- ast_mutex_unlock(&con->lock);
- return -1;
-}
-
-
-/*! \brief Dynamically register a new dial plan application */
-int ast_register_application(const char *app, int (*execute)(struct ast_channel *, void *), const char *synopsis, const char *description)
-{
- struct ast_app *tmp, *prev, *cur;
- char tmps[80];
- int length;
- length = sizeof(struct ast_app);
- length += strlen(app) + 1;
- if (ast_mutex_lock(&applock)) {
- ast_log(LOG_ERROR, "Unable to lock application list\n");
- return -1;
- }
- tmp = apps;
- while(tmp) {
- if (!strcasecmp(app, tmp->name)) {
- ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
- ast_mutex_unlock(&applock);
- return -1;
- }
- tmp = tmp->next;
- }
- tmp = malloc(length);
- if (tmp) {
- memset(tmp, 0, length);
- strcpy(tmp->name, app);
- tmp->execute = execute;
- tmp->synopsis = synopsis;
- tmp->description = description;
- /* Store in alphabetical order */
- cur = apps;
- prev = NULL;
- while(cur) {
- if (strcasecmp(tmp->name, cur->name) < 0)
- break;
- prev = cur;
- cur = cur->next;
- }
- if (prev) {
- tmp->next = prev->next;
- prev->next = tmp;
- } else {
- tmp->next = apps;
- apps = tmp;
- }
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- ast_mutex_unlock(&applock);
- return -1;
- }
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
- ast_mutex_unlock(&applock);
- return 0;
-}
-
-int ast_register_switch(struct ast_switch *sw)
-{
- struct ast_switch *tmp, *prev=NULL;
- if (ast_mutex_lock(&switchlock)) {
- ast_log(LOG_ERROR, "Unable to lock switch lock\n");
- return -1;
- }
- tmp = switches;
- while(tmp) {
- if (!strcasecmp(tmp->name, sw->name))
- break;
- prev = tmp;
- tmp = tmp->next;
- }
- if (tmp) {
- ast_mutex_unlock(&switchlock);
- ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name);
- return -1;
- }
- sw->next = NULL;
- if (prev)
- prev->next = sw;
- else
- switches = sw;
- ast_mutex_unlock(&switchlock);
- return 0;
-}
-
-void ast_unregister_switch(struct ast_switch *sw)
-{
- struct ast_switch *tmp, *prev=NULL;
- if (ast_mutex_lock(&switchlock)) {
- ast_log(LOG_ERROR, "Unable to lock switch lock\n");
- return;
- }
- tmp = switches;
- while(tmp) {
- if (tmp == sw) {
- if (prev)
- prev->next = tmp->next;
- else
- switches = tmp->next;
- tmp->next = NULL;
- break;
- }
- prev = tmp;
- tmp = tmp->next;
- }
- ast_mutex_unlock(&switchlock);
-}
-
-/*
- * Help for CLI commands ...
- */
-static char show_application_help[] =
-"Usage: show application <application> [<application> [<application> [...]]]\n"
-" Describes a particular application.\n";
-
-static char show_functions_help[] =
-"Usage: show functions\n"
-" List builtin functions accessable as $(function args)\n";
-
-static char show_function_help[] =
-"Usage: show function <function>\n"
-" Describe a particular dialplan function.\n";
-
-static char show_applications_help[] =
-"Usage: show applications [{like|describing} <text>]\n"
-" List applications which are currently available.\n"
-" If 'like', <text> will be a substring of the app name\n"
-" If 'describing', <text> will be a substring of the description\n";
-
-static char show_dialplan_help[] =
-"Usage: show dialplan [exten@][context]\n"
-" Show dialplan\n";
-
-static char show_switches_help[] =
-"Usage: show switches\n"
-" Show registered switches\n";
-
-static char show_hints_help[] =
-"Usage: show hints\n"
-" Show registered hints\n";
-
-
-/*
- * IMPLEMENTATION OF CLI FUNCTIONS IS IN THE SAME ORDER AS COMMANDS HELPS
- *
- */
-
-/*
- * \brief 'show application' CLI command implementation functions ...
- */
-
-/*
- * There is a possibility to show informations about more than one
- * application at one time. You can type 'show application Dial Echo' and
- * you will see informations about these two applications ...
- */
-static char *complete_show_application(char *line, char *word,
- int pos, int state)
-{
- struct ast_app *a;
- int which = 0;
-
- /* try to lock applications list ... */
- if (ast_mutex_lock(&applock)) {
- ast_log(LOG_ERROR, "Unable to lock application list\n");
- return NULL;
- }
-
- /* ... walk all applications ... */
- a = apps;
- while (a) {
- /* ... check if word matches this application ... */
- if (!strncasecmp(word, a->name, strlen(word))) {
- /* ... if this is right app serve it ... */
- if (++which > state) {
- char *ret = strdup(a->name);
- ast_mutex_unlock(&applock);
- return ret;
- }
- }
- a = a->next;
- }
-
- /* no application match */
- ast_mutex_unlock(&applock);
- return NULL;
-}
-
-static int handle_show_application(int fd, int argc, char *argv[])
-{
- struct ast_app *a;
- int app, no_registered_app = 1;
-
- if (argc < 3) return RESULT_SHOWUSAGE;
-
- /* try to lock applications list ... */
- if (ast_mutex_lock(&applock)) {
- ast_log(LOG_ERROR, "Unable to lock application list\n");
- return -1;
- }
-
- /* ... go through all applications ... */
- a = apps;
- while (a) {
- /* ... compare this application name with all arguments given
- * to 'show application' command ... */
- for (app = 2; app < argc; app++) {
- if (!strcasecmp(a->name, argv[app])) {
- /* Maximum number of characters added by terminal coloring is 22 */
- char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40];
- char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL;
- int synopsis_size, description_size;
-
- no_registered_app = 0;
-
- if (a->synopsis)
- synopsis_size = strlen(a->synopsis) + 23;
- else
- synopsis_size = strlen("Not available") + 23;
- synopsis = alloca(synopsis_size);
-
- if (a->description)
- description_size = strlen(a->description) + 23;
- else
- description_size = strlen("Not available") + 23;
- description = alloca(description_size);
-
- if (synopsis && description) {
- snprintf(info, 64 + AST_MAX_APP, "\n -= Info about application '%s' =- \n\n", a->name);
- term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22);
- term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
- term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40);
- term_color(synopsis,
- a->synopsis ? a->synopsis : "Not available",
- COLOR_CYAN, 0, synopsis_size);
- term_color(description,
- a->description ? a->description : "Not available",
- COLOR_CYAN, 0, description_size);
-
- ast_cli(fd,"%s%s%s\n\n%s%s\n", infotitle, syntitle, synopsis, destitle, description);
- } else {
- /* ... one of our applications, show info ...*/
- ast_cli(fd,"\n -= Info about application '%s' =- \n\n"
- "[Synopsis]\n %s\n\n"
- "[Description]\n%s\n",
- a->name,
- a->synopsis ? a->synopsis : "Not available",
- a->description ? a->description : "Not available");
- }
- }
- }
- a = a->next;
- }
-
- ast_mutex_unlock(&applock);
-
- /* we found at least one app? no? */
- if (no_registered_app) {
- ast_cli(fd, "Your application(s) is (are) not registered\n");
- return RESULT_FAILURE;
- }
-
- return RESULT_SUCCESS;
-}
-
-/*! \brief handle_show_hints: CLI support for listing registred dial plan hints */
-static int handle_show_hints(int fd, int argc, char *argv[])
-{
- struct ast_hint *hint;
- int num = 0;
- int watchers;
- struct ast_state_cb *watcher;
-
- if (!hints) {
- ast_cli(fd, "There are no registered dialplan hints\n");
- return RESULT_SUCCESS;
- }
- /* ... we have hints ... */
- ast_cli(fd, "\n -= Registered Asterisk Dial Plan Hints =-\n");
- if (ast_mutex_lock(&hintlock)) {
- ast_log(LOG_ERROR, "Unable to lock hints\n");
- return -1;
- }
- hint = hints;
- while (hint) {
- watchers = 0;
- for (watcher = hint->callbacks; watcher; watcher = watcher->next)
- watchers++;
- ast_cli(fd, " %-20.20s: %-20.20s State:%-15.15s Watchers %2d\n",
- ast_get_extension_name(hint->exten), ast_get_extension_app(hint->exten),
- ast_extension_state2str(hint->laststate), watchers);
- num++;
- hint = hint->next;
- }
- ast_cli(fd, "----------------\n");
- ast_cli(fd, "- %d hints registered\n", num);
- ast_mutex_unlock(&hintlock);
- return RESULT_SUCCESS;
-}
-
-/*! \brief handle_show_switches: CLI support for listing registred dial plan switches */
-static int handle_show_switches(int fd, int argc, char *argv[])
-{
- struct ast_switch *sw;
- if (!switches) {
- ast_cli(fd, "There are no registered alternative switches\n");
- return RESULT_SUCCESS;
- }
- /* ... we have applications ... */
- ast_cli(fd, "\n -= Registered Asterisk Alternative Switches =-\n");
- if (ast_mutex_lock(&switchlock)) {
- ast_log(LOG_ERROR, "Unable to lock switches\n");
- return -1;
- }
- sw = switches;
- while (sw) {
- ast_cli(fd, "%s: %s\n", sw->name, sw->description);
- sw = sw->next;
- }
- ast_mutex_unlock(&switchlock);
- return RESULT_SUCCESS;
-}
-
-/*
- * 'show applications' CLI command implementation functions ...
- */
-static int handle_show_applications(int fd, int argc, char *argv[])
-{
- struct ast_app *a;
- int like=0, describing=0;
- int total_match = 0; /* Number of matches in like clause */
- int total_apps = 0; /* Number of apps registered */
-
- /* try to lock applications list ... */
- if (ast_mutex_lock(&applock)) {
- ast_log(LOG_ERROR, "Unable to lock application list\n");
- return -1;
- }
-
- /* ... have we got at least one application (first)? no? */
- if (!apps) {
- ast_cli(fd, "There are no registered applications\n");
- ast_mutex_unlock(&applock);
- return -1;
- }
-
- /* show applications like <keyword> */
- if ((argc == 4) && (!strcmp(argv[2], "like"))) {
- like = 1;
- } else if ((argc > 3) && (!strcmp(argv[2], "describing"))) {
- describing = 1;
- }
-
- /* show applications describing <keyword1> [<keyword2>] [...] */
- if ((!like) && (!describing)) {
- ast_cli(fd, " -= Registered Asterisk Applications =-\n");
- } else {
- ast_cli(fd, " -= Matching Asterisk Applications =-\n");
- }
-
- /* ... go through all applications ... */
- for (a = apps; a; a = a->next) {
- /* ... show informations about applications ... */
- int printapp=0;
- total_apps++;
- if (like) {
- if (strcasestr(a->name, argv[3])) {
- printapp = 1;
- total_match++;
- }
- } else if (describing) {
- if (a->description) {
- /* Match all words on command line */
- int i;
- printapp = 1;
- for (i=3; i<argc; i++) {
- if (!strcasestr(a->description, argv[i])) {
- printapp = 0;
- } else {
- total_match++;
- }
- }
- }
- } else {
- printapp = 1;
- }
-
- if (printapp) {
- ast_cli(fd," %20s: %s\n", a->name, a->synopsis ? a->synopsis : "<Synopsis not available>");
- }
- }
- if ((!like) && (!describing)) {
- ast_cli(fd, " -= %d Applications Registered =-\n",total_apps);
- } else {
- ast_cli(fd, " -= %d Applications Matching =-\n",total_match);
- }
-
- /* ... unlock and return */
- ast_mutex_unlock(&applock);
-
- return RESULT_SUCCESS;
-}
-
-static char *complete_show_applications(char *line, char *word, int pos, int state)
-{
- if (pos == 2) {
- if (ast_strlen_zero(word)) {
- switch (state) {
- case 0:
- return strdup("like");
- case 1:
- return strdup("describing");
- default:
- return NULL;
- }
- } else if (! strncasecmp(word, "like", strlen(word))) {
- if (state == 0) {
- return strdup("like");
- } else {
- return NULL;
- }
- } else if (! strncasecmp(word, "describing", strlen(word))) {
- if (state == 0) {
- return strdup("describing");
- } else {
- return NULL;
- }
- }
- }
- return NULL;
-}
-
-/*
- * 'show dialplan' CLI command implementation functions ...
- */
-static char *complete_show_dialplan_context(char *line, char *word, int pos,
- int state)
-{
- struct ast_context *c;
- int which = 0;
-
- /* we are do completion of [exten@]context on second position only */
- if (pos != 2) return NULL;
-
- /* try to lock contexts list ... */
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Unable to lock context list\n");
- return NULL;
- }
-
- /* ... walk through all contexts ... */
- c = ast_walk_contexts(NULL);
- while(c) {
- /* ... word matches context name? yes? ... */
- if (!strncasecmp(word, ast_get_context_name(c), strlen(word))) {
- /* ... for serve? ... */
- if (++which > state) {
- /* ... yes, serve this context name ... */
- char *ret = strdup(ast_get_context_name(c));
- ast_unlock_contexts();
- return ret;
- }
- }
- c = ast_walk_contexts(c);
- }
-
- /* ... unlock and return */
- ast_unlock_contexts();
- return NULL;
-}
-
-struct dialplan_counters {
- int total_context;
- int total_exten;
- int total_prio;
- int context_existence;
- int extension_existence;
-};
-
-static int show_dialplan_helper(int fd, char *context, char *exten, struct dialplan_counters *dpc, struct ast_include *rinclude, int includecount, char *includes[])
-{
- struct ast_context *c;
- int res=0, old_total_exten = dpc->total_exten;
-
- /* try to lock contexts */
- if (ast_lock_contexts()) {
- ast_log(LOG_WARNING, "Failed to lock contexts list\n");
- return -1;
- }
-
- /* walk all contexts ... */
- for (c = ast_walk_contexts(NULL); c ; c = ast_walk_contexts(c)) {
- /* show this context? */
- if (!context ||
- !strcmp(ast_get_context_name(c), context)) {
- dpc->context_existence = 1;
-
- /* try to lock context before walking in ... */
- if (!ast_lock_context(c)) {
- struct ast_exten *e;
- struct ast_include *i;
- struct ast_ignorepat *ip;
- struct ast_sw *sw;
- char buf[256], buf2[256];
- int context_info_printed = 0;
-
- /* are we looking for exten too? if yes, we print context
- * if we our extension only
- */
- if (!exten) {
- dpc->total_context++;
- ast_cli(fd, "[ Context '%s' created by '%s' ]\n",
- ast_get_context_name(c), ast_get_context_registrar(c));
- context_info_printed = 1;
- }
-
- /* walk extensions ... */
- for (e = ast_walk_context_extensions(c, NULL); e; e = ast_walk_context_extensions(c, e)) {
- struct ast_exten *p;
- int prio;
-
- /* looking for extension? is this our extension? */
- if (exten &&
- !ast_extension_match(ast_get_extension_name(e), exten))
- {
- /* we are looking for extension and it's not our
- * extension, so skip to next extension */
- continue;
- }
-
- dpc->extension_existence = 1;
-
- /* may we print context info? */
- if (!context_info_printed) {
- dpc->total_context++;
- if (rinclude) {
- /* TODO Print more info about rinclude */
- ast_cli(fd, "[ Included context '%s' created by '%s' ]\n",
- ast_get_context_name(c),
- ast_get_context_registrar(c));
- } else {
- ast_cli(fd, "[ Context '%s' created by '%s' ]\n",
- ast_get_context_name(c),
- ast_get_context_registrar(c));
- }
- context_info_printed = 1;
- }
- dpc->total_prio++;
-
- /* write extension name and first peer */
- bzero(buf, sizeof(buf));
- snprintf(buf, sizeof(buf), "'%s' =>",
- ast_get_extension_name(e));
-
- prio = ast_get_extension_priority(e);
- if (prio == PRIORITY_HINT) {
- snprintf(buf2, sizeof(buf2),
- "hint: %s",
- ast_get_extension_app(e));
- } else {
- snprintf(buf2, sizeof(buf2),
- "%d. %s(%s)",
- prio,
- ast_get_extension_app(e),
- (char *)ast_get_extension_app_data(e));
- }
-
- ast_cli(fd, " %-17s %-45s [%s]\n", buf, buf2,
- ast_get_extension_registrar(e));
-
- dpc->total_exten++;
- /* walk next extension peers */
- for (p=ast_walk_extension_priorities(e, e); p; p=ast_walk_extension_priorities(e, p)) {
- dpc->total_prio++;
- bzero((void *)buf2, sizeof(buf2));
- bzero((void *)buf, sizeof(buf));
- if (ast_get_extension_label(p))
- snprintf(buf, sizeof(buf), " [%s]", ast_get_extension_label(p));
- prio = ast_get_extension_priority(p);
- if (prio == PRIORITY_HINT) {
- snprintf(buf2, sizeof(buf2),
- "hint: %s",
- ast_get_extension_app(p));
- } else {
- snprintf(buf2, sizeof(buf2),
- "%d. %s(%s)",
- prio,
- ast_get_extension_app(p),
- (char *)ast_get_extension_app_data(p));
- }
-
- ast_cli(fd," %-17s %-45s [%s]\n",
- buf, buf2,
- ast_get_extension_registrar(p));
- }
- }
-
- /* walk included and write info ... */
- for (i = ast_walk_context_includes(c, NULL); i; i = ast_walk_context_includes(c, i)) {
- bzero(buf, sizeof(buf));
- snprintf(buf, sizeof(buf), "'%s'",
- ast_get_include_name(i));
- if (exten) {
- /* Check all includes for the requested extension */
- if (includecount >= AST_PBX_MAX_STACK) {
- ast_log(LOG_NOTICE, "Maximum include depth exceeded!\n");
- } else {
- int dupe=0;
- int x;
- for (x=0;x<includecount;x++) {
- if (!strcasecmp(includes[x], ast_get_include_name(i))) {
- dupe++;
- break;
- }
- }
- if (!dupe) {
- includes[includecount] = (char *)ast_get_include_name(i);
- show_dialplan_helper(fd, (char *)ast_get_include_name(i), exten, dpc, i, includecount + 1, includes);
- } else {
- ast_log(LOG_WARNING, "Avoiding circular include of %s within %s\n", ast_get_include_name(i), context);
- }
- }
- } else {
- ast_cli(fd, " Include => %-45s [%s]\n",
- buf, ast_get_include_registrar(i));
- }
- }
-
- /* walk ignore patterns and write info ... */
- for (ip=ast_walk_context_ignorepats(c, NULL); ip; ip=ast_walk_context_ignorepats(c, ip)) {
- const char *ipname = ast_get_ignorepat_name(ip);
- char ignorepat[AST_MAX_EXTENSION];
- snprintf(buf, sizeof(buf), "'%s'", ipname);
- snprintf(ignorepat, sizeof(ignorepat), "_%s.", ipname);
- if ((!exten) || ast_extension_match(ignorepat, exten)) {
- ast_cli(fd, " Ignore pattern => %-45s [%s]\n",
- buf, ast_get_ignorepat_registrar(ip));
- }
- }
- if (!rinclude) {
- for (sw = ast_walk_context_switches(c, NULL); sw; sw = ast_walk_context_switches(c, sw)) {
- snprintf(buf, sizeof(buf), "'%s/%s'",
- ast_get_switch_name(sw),
- ast_get_switch_data(sw));
- ast_cli(fd, " Alt. Switch => %-45s [%s]\n",
- buf, ast_get_switch_registrar(sw));
- }
- }
-
- ast_unlock_context(c);
-
- /* if we print something in context, make an empty line */
- if (context_info_printed) ast_cli(fd, "\r\n");
- }
- }
- }
- ast_unlock_contexts();
-
- if (dpc->total_exten == old_total_exten) {
- /* Nothing new under the sun */
- return -1;
- } else {
- return res;
- }
-}
-
-static int handle_show_dialplan(int fd, int argc, char *argv[])
-{
- char *exten = NULL, *context = NULL;
- /* Variables used for different counters */
- struct dialplan_counters counters;
- char *incstack[AST_PBX_MAX_STACK];
- memset(&counters, 0, sizeof(counters));
-
- if (argc != 2 && argc != 3)
- return RESULT_SHOWUSAGE;
-
- /* we obtain [exten@]context? if yes, split them ... */
- if (argc == 3) {
- char *splitter = ast_strdupa(argv[2]);
- /* is there a '@' character? */
- if (splitter && strchr(argv[2], '@')) {
- /* yes, split into exten & context ... */
- exten = strsep(&splitter, "@");
- context = splitter;
-
- /* check for length and change to NULL if ast_strlen_zero() */
- if (ast_strlen_zero(exten))
- exten = NULL;
- if (ast_strlen_zero(context))
- context = NULL;
- show_dialplan_helper(fd, context, exten, &counters, NULL, 0, incstack);
- } else {
- /* no '@' char, only context given */
- context = argv[2];
- if (ast_strlen_zero(context))
- context = NULL;
- show_dialplan_helper(fd, context, exten, &counters, NULL, 0, incstack);
- }
- } else {
- /* Show complete dial plan */
- show_dialplan_helper(fd, NULL, NULL, &counters, NULL, 0, incstack);
- }
-
- /* check for input failure and throw some error messages */
- if (context && !counters.context_existence) {
- ast_cli(fd, "There is no existence of '%s' context\n", context);
- return RESULT_FAILURE;
- }
-
- if (exten && !counters.extension_existence) {
- if (context)
- ast_cli(fd, "There is no existence of %s@%s extension\n",
- exten, context);
- else
- ast_cli(fd,
- "There is no existence of '%s' extension in all contexts\n",
- exten);
- return RESULT_FAILURE;
- }
-
- ast_cli(fd,"-= %d %s (%d %s) in %d %s. =-\n",
- counters.total_exten, counters.total_exten == 1 ? "extension" : "extensions",
- counters.total_prio, counters.total_prio == 1 ? "priority" : "priorities",
- counters.total_context, counters.total_context == 1 ? "context" : "contexts");
-
- /* everything ok */
- return RESULT_SUCCESS;
-}
-
-/*
- * CLI entries for upper commands ...
- */
-static struct ast_cli_entry pbx_cli[] = {
- { { "show", "applications", NULL }, handle_show_applications,
- "Shows registered dialplan applications", show_applications_help, complete_show_applications },
- { { "show", "functions", NULL }, handle_show_functions,
- "Shows registered dialplan functions", show_functions_help },
- { { "show" , "function", NULL }, handle_show_function,
- "Describe a specific dialplan function", show_function_help, complete_show_function },
- { { "show", "application", NULL }, handle_show_application,
- "Describe a specific dialplan application", show_application_help, complete_show_application },
- { { "show", "dialplan", NULL }, handle_show_dialplan,
- "Show dialplan", show_dialplan_help, complete_show_dialplan_context },
- { { "show", "switches", NULL }, handle_show_switches,
- "Show alternative switches", show_switches_help },
- { { "show", "hints", NULL }, handle_show_hints,
- "Show dialplan hints", show_hints_help },
-};
-
-int ast_unregister_application(const char *app)
-{
- struct ast_app *tmp, *tmpl = NULL;
- if (ast_mutex_lock(&applock)) {
- ast_log(LOG_ERROR, "Unable to lock application list\n");
- return -1;
- }
- tmp = apps;
- while(tmp) {
- if (!strcasecmp(app, tmp->name)) {
- if (tmpl)
- tmpl->next = tmp->next;
- else
- apps = tmp->next;
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Unregistered application '%s'\n", tmp->name);
- free(tmp);
- ast_mutex_unlock(&applock);
- return 0;
- }
- tmpl = tmp;
- tmp = tmp->next;
- }
- ast_mutex_unlock(&applock);
- return -1;
-}
-
-struct ast_context *ast_context_create(struct ast_context **extcontexts, const char *name, const char *registrar)
-{
- struct ast_context *tmp, **local_contexts;
- int length;
- length = sizeof(struct ast_context);
- length += strlen(name) + 1;
- if (!extcontexts) {
- local_contexts = &contexts;
- ast_mutex_lock(&conlock);
- } else
- local_contexts = extcontexts;
-
- tmp = *local_contexts;
- while(tmp) {
- if (!strcasecmp(tmp->name, name)) {
- ast_mutex_unlock(&conlock);
- ast_log(LOG_WARNING, "Tried to register context '%s', already in use\n", name);
- if (!extcontexts)
- ast_mutex_unlock(&conlock);
- return NULL;
- }
- tmp = tmp->next;
- }
- tmp = malloc(length);
- if (tmp) {
- memset(tmp, 0, length);
- ast_mutex_init(&tmp->lock);
- strcpy(tmp->name, name);
- tmp->root = NULL;
- tmp->registrar = registrar;
- tmp->next = *local_contexts;
- tmp->includes = NULL;
- tmp->ignorepats = NULL;
- *local_contexts = tmp;
- if (option_debug)
- ast_log(LOG_DEBUG, "Registered context '%s'\n", tmp->name);
- else if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Registered extension context '%s'\n", tmp->name);
- } else
- ast_log(LOG_ERROR, "Out of memory\n");
-
- if (!extcontexts)
- ast_mutex_unlock(&conlock);
- return tmp;
-}
-
-void __ast_context_destroy(struct ast_context *con, const char *registrar);
-
-struct store_hint {
- char *context;
- char *exten;
- struct ast_state_cb *callbacks;
- int laststate;
- AST_LIST_ENTRY(store_hint) list;
- char data[1];
-};
-
-AST_LIST_HEAD(store_hints, store_hint);
-
-void ast_merge_contexts_and_delete(struct ast_context **extcontexts, const char *registrar)
-{
- struct ast_context *tmp, *lasttmp = NULL;
- struct store_hints store;
- struct store_hint *this;
- struct ast_hint *hint;
- struct ast_exten *exten;
- int length;
- struct ast_state_cb *thiscb, *prevcb;
-
- /* preserve all watchers for hints associated with this registrar */
- AST_LIST_HEAD_INIT(&store);
- ast_mutex_lock(&hintlock);
- for (hint = hints; hint; hint = hint->next) {
- if (hint->callbacks && !strcmp(registrar, hint->exten->parent->registrar)) {
- length = strlen(hint->exten->exten) + strlen(hint->exten->parent->name) + 2 + sizeof(*this);
- this = calloc(1, length);
- if (!this) {
- ast_log(LOG_WARNING, "Could not allocate memory to preserve hint\n");
- continue;
- }
- this->callbacks = hint->callbacks;
- hint->callbacks = NULL;
- this->laststate = hint->laststate;
- this->context = this->data;
- strcpy(this->data, hint->exten->parent->name);
- this->exten = this->data + strlen(this->context) + 1;
- strcpy(this->exten, hint->exten->exten);
- AST_LIST_INSERT_HEAD(&store, this, list);
- }
- }
- ast_mutex_unlock(&hintlock);
-
- tmp = *extcontexts;
- ast_mutex_lock(&conlock);
- if (registrar) {
- __ast_context_destroy(NULL,registrar);
- while (tmp) {
- lasttmp = tmp;
- tmp = tmp->next;
- }
- } else {
- while (tmp) {
- __ast_context_destroy(tmp,tmp->registrar);
- lasttmp = tmp;
- tmp = tmp->next;
- }
- }
- if (lasttmp) {
- lasttmp->next = contexts;
- contexts = *extcontexts;
- *extcontexts = NULL;
- } else
- ast_log(LOG_WARNING, "Requested contexts didn't get merged\n");
- ast_mutex_unlock(&conlock);
-
- /* restore the watchers for hints that can be found; notify those that
- cannot be restored
- */
- while ((this = AST_LIST_REMOVE_HEAD(&store, list))) {
- exten = ast_hint_extension(NULL, this->context, this->exten);
- /* Find the hint in the list of hints */
- ast_mutex_lock(&hintlock);
- for (hint = hints; hint; hint = hint->next) {
- if (hint->exten == exten)
- break;
- }
- if (!exten || !hint) {
- /* this hint has been removed, notify the watchers */
- prevcb = NULL;
- thiscb = this->callbacks;
- while (thiscb) {
- prevcb = thiscb;
- thiscb = thiscb->next;
- prevcb->callback(this->context, this->exten, AST_EXTENSION_REMOVED, prevcb->data);
- free(prevcb);
- }
- } else {
- thiscb = this->callbacks;
- while (thiscb->next)
- thiscb = thiscb->next;
- thiscb->next = hint->callbacks;
- hint->callbacks = this->callbacks;
- hint->laststate = this->laststate;
- }
- ast_mutex_unlock(&hintlock);
- free(this);
- }
-
- return;
-}
-
-/*
- * errno values
- * EBUSY - can't lock
- * ENOENT - no existence of context
- */
-int ast_context_add_include(const char *context, const char *include, const char *registrar)
-{
- struct ast_context *c;
-
- if (ast_lock_contexts()) {
- errno = EBUSY;
- return -1;
- }
-
- /* walk contexts ... */
- c = ast_walk_contexts(NULL);
- while (c) {
- /* ... search for the right one ... */
- if (!strcmp(ast_get_context_name(c), context)) {
- int ret = ast_context_add_include2(c, include, registrar);
- /* ... unlock contexts list and return */
- ast_unlock_contexts();
- return ret;
- }
- c = ast_walk_contexts(c);
- }
-
- /* we can't find the right context */
- ast_unlock_contexts();
- errno = ENOENT;
- return -1;
-}
-
-#define FIND_NEXT \
-do { \
- c = info; \
- while(*c && (*c != '|')) c++; \
- if (*c) { *c = '\0'; c++; } else c = NULL; \
-} while(0)
-
-static void get_timerange(struct ast_timing *i, char *times)
-{
- char *e;
- int x;
- int s1, s2;
- int e1, e2;
- /* int cth, ctm; */
-
- /* start disabling all times, fill the fields with 0's, as they may contain garbage */
- memset(i->minmask, 0, sizeof(i->minmask));
-
- /* Star is all times */
- if (ast_strlen_zero(times) || !strcmp(times, "*")) {
- for (x=0; x<24; x++)
- i->minmask[x] = (1 << 30) - 1;
- return;
- }
- /* Otherwise expect a range */
- e = strchr(times, '-');
- if (!e) {
- ast_log(LOG_WARNING, "Time range is not valid. Assuming no restrictions based on time.\n");
- return;
- }
- *e = '\0';
- e++;
- while(*e && !isdigit(*e))
- e++;
- if (!*e) {
- ast_log(LOG_WARNING, "Invalid time range. Assuming no restrictions based on time.\n");
- return;
- }
- if (sscanf(times, "%d:%d", &s1, &s2) != 2) {
- ast_log(LOG_WARNING, "%s isn't a time. Assuming no restrictions based on time.\n", times);
- return;
- }
- if (sscanf(e, "%d:%d", &e1, &e2) != 2) {
- ast_log(LOG_WARNING, "%s isn't a time. Assuming no restrictions based on time.\n", e);
- return;
- }
-
-#if 1
- s1 = s1 * 30 + s2/2;
- if ((s1 < 0) || (s1 >= 24*30)) {
- ast_log(LOG_WARNING, "%s isn't a valid start time. Assuming no time.\n", times);
- return;
- }
- e1 = e1 * 30 + e2/2;
- if ((e1 < 0) || (e1 >= 24*30)) {
- ast_log(LOG_WARNING, "%s isn't a valid end time. Assuming no time.\n", e);
- return;
- }
- /* Go through the time and enable each appropriate bit */
- for (x=s1;x != e1;x = (x + 1) % (24 * 30)) {
- i->minmask[x/30] |= (1 << (x % 30));
- }
- /* Do the last one */
- i->minmask[x/30] |= (1 << (x % 30));
-#else
- for (cth=0; cth<24; cth++) {
- /* Initialize masks to blank */
- i->minmask[cth] = 0;
- for (ctm=0; ctm<30; ctm++) {
- if (
- /* First hour with more than one hour */
- (((cth == s1) && (ctm >= s2)) &&
- ((cth < e1)))
- /* Only one hour */
- || (((cth == s1) && (ctm >= s2)) &&
- ((cth == e1) && (ctm <= e2)))
- /* In between first and last hours (more than 2 hours) */
- || ((cth > s1) &&
- (cth < e1))
- /* Last hour with more than one hour */
- || ((cth > s1) &&
- ((cth == e1) && (ctm <= e2)))
- )
- i->minmask[cth] |= (1 << (ctm / 2));
- }
- }
-#endif
- /* All done */
- return;
-}
-
-static char *days[] =
-{
- "sun",
- "mon",
- "tue",
- "wed",
- "thu",
- "fri",
- "sat",
-};
-
-/*! \brief get_dow: Get day of week */
-static unsigned int get_dow(char *dow)
-{
- char *c;
- /* The following line is coincidence, really! */
- int s, e, x;
- unsigned int mask;
-
- /* Check for all days */
- if (ast_strlen_zero(dow) || !strcmp(dow, "*"))
- return (1 << 7) - 1;
- /* Get start and ending days */
- c = strchr(dow, '-');
- if (c) {
- *c = '\0';
- c++;
- } else
- c = NULL;
- /* Find the start */
- s = 0;
- while((s < 7) && strcasecmp(dow, days[s])) s++;
- if (s >= 7) {
- ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", dow);
- return 0;
- }
- if (c) {
- e = 0;
- while((e < 7) && strcasecmp(c, days[e])) e++;
- if (e >= 7) {
- ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", c);
- return 0;
- }
- } else
- e = s;
- mask = 0;
- for (x=s; x != e; x = (x + 1) % 7) {
- mask |= (1 << x);
- }
- /* One last one */
- mask |= (1 << x);
- return mask;
-}
-
-static unsigned int get_day(char *day)
-{
- char *c;
- /* The following line is coincidence, really! */
- int s, e, x;
- unsigned int mask;
-
- /* Check for all days */
- if (ast_strlen_zero(day) || !strcmp(day, "*")) {
- mask = (1 << 30) + ((1 << 30) - 1);
- return mask;
- }
- /* Get start and ending days */
- c = strchr(day, '-');
- if (c) {
- *c = '\0';
- c++;
- }
- /* Find the start */
- if (sscanf(day, "%d", &s) != 1) {
- ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", day);
- return 0;
- }
- if ((s < 1) || (s > 31)) {
- ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", day);
- return 0;
- }
- s--;
- if (c) {
- if (sscanf(c, "%d", &e) != 1) {
- ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", c);
- return 0;
- }
- if ((e < 1) || (e > 31)) {
- ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", c);
- return 0;
- }
- e--;
- } else
- e = s;
- mask = 0;
- for (x=s; x!=e; x = (x + 1) % 31) {
- mask |= (1 << x);
- }
- mask |= (1 << x);
- return mask;
-}
-
-static char *months[] =
-{
- "jan",
- "feb",
- "mar",
- "apr",
- "may",
- "jun",
- "jul",
- "aug",
- "sep",
- "oct",
- "nov",
- "dec",
-};
-
-static unsigned int get_month(char *mon)
-{
- char *c;
- /* The following line is coincidence, really! */
- int s, e, x;
- unsigned int mask;
-
- /* Check for all days */
- if (ast_strlen_zero(mon) || !strcmp(mon, "*"))
- return (1 << 12) - 1;
- /* Get start and ending days */
- c = strchr(mon, '-');
- if (c) {
- *c = '\0';
- c++;
- }
- /* Find the start */
- s = 0;
- while((s < 12) && strcasecmp(mon, months[s])) s++;
- if (s >= 12) {
- ast_log(LOG_WARNING, "Invalid month '%s', assuming none\n", mon);
- return 0;
- }
- if (c) {
- e = 0;
- while((e < 12) && strcasecmp(mon, months[e])) e++;
- if (e >= 12) {
- ast_log(LOG_WARNING, "Invalid month '%s', assuming none\n", c);
- return 0;
- }
- } else
- e = s;
- mask = 0;
- for (x=s; x!=e; x = (x + 1) % 12) {
- mask |= (1 << x);
- }
- /* One last one */
- mask |= (1 << x);
- return mask;
-}
-
-int ast_build_timing(struct ast_timing *i, char *info_in)
-{
- char info_save[256];
- char *info;
- char *c;
-
- /* Check for empty just in case */
- if (ast_strlen_zero(info_in))
- return 0;
- /* make a copy just in case we were passed a static string */
- ast_copy_string(info_save, info_in, sizeof(info_save));
- info = info_save;
- /* Assume everything except time */
- i->monthmask = (1 << 12) - 1;
- i->daymask = (1 << 30) - 1 + (1 << 30);
- i->dowmask = (1 << 7) - 1;
- /* Avoid using str tok */
- FIND_NEXT;
- /* Info has the time range, start with that */
- get_timerange(i, info);
- info = c;
- if (!info)
- return 1;
- FIND_NEXT;
- /* Now check for day of week */
- i->dowmask = get_dow(info);
-
- info = c;
- if (!info)
- return 1;
- FIND_NEXT;
- /* Now check for the day of the month */
- i->daymask = get_day(info);
- info = c;
- if (!info)
- return 1;
- FIND_NEXT;
- /* And finally go for the month */
- i->monthmask = get_month(info);
-
- return 1;
-}
-
-int ast_check_timing(struct ast_timing *i)
-{
- struct tm tm;
- time_t t;
-
- time(&t);
- localtime_r(&t,&tm);
-
- /* If it's not the right month, return */
- if (!(i->monthmask & (1 << tm.tm_mon))) {
- return 0;
- }
-
- /* If it's not that time of the month.... */
- /* Warning, tm_mday has range 1..31! */
- if (!(i->daymask & (1 << (tm.tm_mday-1))))
- return 0;
-
- /* If it's not the right day of the week */
- if (!(i->dowmask & (1 << tm.tm_wday)))
- return 0;
-
- /* Sanity check the hour just to be safe */
- if ((tm.tm_hour < 0) || (tm.tm_hour > 23)) {
- ast_log(LOG_WARNING, "Insane time...\n");
- return 0;
- }
-
- /* Now the tough part, we calculate if it fits
- in the right time based on min/hour */
- if (!(i->minmask[tm.tm_hour] & (1 << (tm.tm_min / 2))))
- return 0;
-
- /* If we got this far, then we're good */
- return 1;
-}
-
-/*
- * errno values
- * ENOMEM - out of memory
- * EBUSY - can't lock
- * EEXIST - already included
- * EINVAL - there is no existence of context for inclusion
- */
-int ast_context_add_include2(struct ast_context *con, const char *value,
- const char *registrar)
-{
- struct ast_include *new_include;
- char *c;
- struct ast_include *i, *il = NULL; /* include, include_last */
- int length;
- char *p;
-
- length = sizeof(struct ast_include);
- length += 2 * (strlen(value) + 1);
-
- /* allocate new include structure ... */
- if (!(new_include = malloc(length))) {
- ast_log(LOG_ERROR, "Out of memory\n");
- errno = ENOMEM;
- return -1;
- }
-
- /* ... fill in this structure ... */
- memset(new_include, 0, length);
- p = new_include->stuff;
- new_include->name = p;
- strcpy(new_include->name, value);
- p += strlen(value) + 1;
- new_include->rname = p;
- strcpy(new_include->rname, value);
- c = new_include->rname;
- /* Strip off timing info */
- while(*c && (*c != '|'))
- c++;
- /* Process if it's there */
- if (*c) {
- new_include->hastime = ast_build_timing(&(new_include->timing), c+1);
- *c = '\0';
- }
- new_include->next = NULL;
- new_include->registrar = registrar;
-
- /* ... try to lock this context ... */
- if (ast_mutex_lock(&con->lock)) {
- free(new_include);
- errno = EBUSY;
- return -1;
- }
-
- /* ... go to last include and check if context is already included too... */
- i = con->includes;
- while (i) {
- if (!strcasecmp(i->name, new_include->name)) {
- free(new_include);
- ast_mutex_unlock(&con->lock);
- errno = EEXIST;
- return -1;
- }
- il = i;
- i = i->next;
- }
-
- /* ... include new context into context list, unlock, return */
- if (il)
- il->next = new_include;
- else
- con->includes = new_include;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Including context '%s' in context '%s'\n", new_include->name, ast_get_context_name(con));
- ast_mutex_unlock(&con->lock);
-
- return 0;
-}
-
-/*
- * errno values
- * EBUSY - can't lock
- * ENOENT - no existence of context
- */
-int ast_context_add_switch(const char *context, const char *sw, const char *data, int eval, const char *registrar)
-{
- struct ast_context *c;
-
- if (ast_lock_contexts()) {
- errno = EBUSY;
- return -1;
- }
-
- /* walk contexts ... */
- c = ast_walk_contexts(NULL);
- while (c) {
- /* ... search for the right one ... */
- if (!strcmp(ast_get_context_name(c), context)) {
- int ret = ast_context_add_switch2(c, sw, data, eval, registrar);
- /* ... unlock contexts list and return */
- ast_unlock_contexts();
- return ret;
- }
- c = ast_walk_contexts(c);
- }
-
- /* we can't find the right context */
- ast_unlock_contexts();
- errno = ENOENT;
- return -1;
-}
-
-/*
- * errno values
- * ENOMEM - out of memory
- * EBUSY - can't lock
- * EEXIST - already included
- * EINVAL - there is no existence of context for inclusion
- */
-int ast_context_add_switch2(struct ast_context *con, const char *value,
- const char *data, int eval, const char *registrar)
-{
- struct ast_sw *new_sw;
- struct ast_sw *i, *il = NULL; /* sw, sw_last */
- int length;
- char *p;
-
- length = sizeof(struct ast_sw);
- length += strlen(value) + 1;
- if (data)
- length += strlen(data);
- length++;
- if (eval) {
- /* Create buffer for evaluation of variables */
- length += SWITCH_DATA_LENGTH;
- length++;
- }
-
- /* allocate new sw structure ... */
- if (!(new_sw = malloc(length))) {
- ast_log(LOG_ERROR, "Out of memory\n");
- errno = ENOMEM;
- return -1;
- }
-
- /* ... fill in this structure ... */
- memset(new_sw, 0, length);
- p = new_sw->stuff;
- new_sw->name = p;
- strcpy(new_sw->name, value);
- p += strlen(value) + 1;
- new_sw->data = p;
- if (data) {
- strcpy(new_sw->data, data);
- p += strlen(data) + 1;
- } else {
- strcpy(new_sw->data, "");
- p++;
- }
- if (eval)
- new_sw->tmpdata = p;
- new_sw->next = NULL;
- new_sw->eval = eval;
- new_sw->registrar = registrar;
-
- /* ... try to lock this context ... */
- if (ast_mutex_lock(&con->lock)) {
- free(new_sw);
- errno = EBUSY;
- return -1;
- }
-
- /* ... go to last sw and check if context is already swd too... */
- i = con->alts;
- while (i) {
- if (!strcasecmp(i->name, new_sw->name) && !strcasecmp(i->data, new_sw->data)) {
- free(new_sw);
- ast_mutex_unlock(&con->lock);
- errno = EEXIST;
- return -1;
- }
- il = i;
- i = i->next;
- }
-
- /* ... sw new context into context list, unlock, return */
- if (il)
- il->next = new_sw;
- else
- con->alts = new_sw;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Including switch '%s/%s' in context '%s'\n", new_sw->name, new_sw->data, ast_get_context_name(con));
- ast_mutex_unlock(&con->lock);
-
- return 0;
-}
-
-/*
- * EBUSY - can't lock
- * ENOENT - there is not context existence
- */
-int ast_context_remove_ignorepat(const char *context, const char *ignorepat, const char *registrar)
-{
- struct ast_context *c;
-
- if (ast_lock_contexts()) {
- errno = EBUSY;
- return -1;
- }
-
- c = ast_walk_contexts(NULL);
- while (c) {
- if (!strcmp(ast_get_context_name(c), context)) {
- int ret = ast_context_remove_ignorepat2(c, ignorepat, registrar);
- ast_unlock_contexts();
- return ret;
- }
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
- errno = ENOENT;
- return -1;
-}
-
-int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar)
-{
- struct ast_ignorepat *ip, *ipl = NULL;
-
- if (ast_mutex_lock(&con->lock)) {
- errno = EBUSY;
- return -1;
- }
-
- ip = con->ignorepats;
- while (ip) {
- if (!strcmp(ip->pattern, ignorepat) &&
- (!registrar || (registrar == ip->registrar))) {
- if (ipl) {
- ipl->next = ip->next;
- free(ip);
- } else {
- con->ignorepats = ip->next;
- free(ip);
- }
- ast_mutex_unlock(&con->lock);
- return 0;
- }
- ipl = ip; ip = ip->next;
- }
-
- ast_mutex_unlock(&con->lock);
- errno = EINVAL;
- return -1;
-}
-
-/*
- * EBUSY - can't lock
- * ENOENT - there is no existence of context
- */
-int ast_context_add_ignorepat(const char *con, const char *value, const char *registrar)
-{
- struct ast_context *c;
-
- if (ast_lock_contexts()) {
- errno = EBUSY;
- return -1;
- }
-
- c = ast_walk_contexts(NULL);
- while (c) {
- if (!strcmp(ast_get_context_name(c), con)) {
- int ret = ast_context_add_ignorepat2(c, value, registrar);
- ast_unlock_contexts();
- return ret;
- }
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
- errno = ENOENT;
- return -1;
-}
-
-int ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar)
-{
- struct ast_ignorepat *ignorepat, *ignorepatc, *ignorepatl = NULL;
- int length;
- length = sizeof(struct ast_ignorepat);
- length += strlen(value) + 1;
- ignorepat = malloc(length);
- if (!ignorepat) {
- ast_log(LOG_ERROR, "Out of memory\n");
- errno = ENOMEM;
- return -1;
- }
- memset(ignorepat, 0, length);
- strcpy(ignorepat->pattern, value);
- ignorepat->next = NULL;
- ignorepat->registrar = registrar;
- ast_mutex_lock(&con->lock);
- ignorepatc = con->ignorepats;
- while(ignorepatc) {
- ignorepatl = ignorepatc;
- if (!strcasecmp(ignorepatc->pattern, value)) {
- /* Already there */
- ast_mutex_unlock(&con->lock);
- errno = EEXIST;
- return -1;
- }
- ignorepatc = ignorepatc->next;
- }
- if (ignorepatl)
- ignorepatl->next = ignorepat;
- else
- con->ignorepats = ignorepat;
- ast_mutex_unlock(&con->lock);
- return 0;
-
-}
-
-int ast_ignore_pattern(const char *context, const char *pattern)
-{
- struct ast_context *con;
- struct ast_ignorepat *pat;
-
- con = ast_context_find(context);
- if (con) {
- pat = con->ignorepats;
- while (pat) {
- if (ast_extension_match(pat->pattern, pattern))
- return 1;
- pat = pat->next;
- }
- }
- return 0;
-}
-
-/*
- * EBUSY - can't lock
- * ENOENT - no existence of context
- *
- */
-int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid,
- const char *application, void *data, void (*datad)(void *), const char *registrar)
-{
- struct ast_context *c;
-
- if (ast_lock_contexts()) {
- errno = EBUSY;
- return -1;
- }
-
- c = ast_walk_contexts(NULL);
- while (c) {
- if (!strcmp(context, ast_get_context_name(c))) {
- int ret = ast_add_extension2(c, replace, extension, priority, label, callerid,
- application, data, datad, registrar);
- ast_unlock_contexts();
- return ret;
- }
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
- errno = ENOENT;
- return -1;
-}
-
-int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
-{
- if (!chan)
- return -1;
-
- if (!ast_strlen_zero(context))
- ast_copy_string(chan->context, context, sizeof(chan->context));
- if (!ast_strlen_zero(exten))
- ast_copy_string(chan->exten, exten, sizeof(chan->exten));
- if (priority > -1) {
- chan->priority = priority;
- /* see flag description in channel.h for explanation */
- if (ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP))
- chan->priority--;
- }
-
- return 0;
-}
-
-int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
-{
- int res = 0;
-
- ast_mutex_lock(&chan->lock);
-
- if (chan->pbx) {
- /* This channel is currently in the PBX */
- ast_explicit_goto(chan, context, exten, priority);
- ast_softhangup_nolock(chan, AST_SOFTHANGUP_ASYNCGOTO);
- } else {
- /* In order to do it when the channel doesn't really exist within
- the PBX, we have to make a new channel, masquerade, and start the PBX
- at the new location */
- struct ast_channel *tmpchan;
- tmpchan = ast_channel_alloc(0);
- if (tmpchan) {
- snprintf(tmpchan->name, sizeof(tmpchan->name), "AsyncGoto/%s", chan->name);
- ast_setstate(tmpchan, chan->_state);
- /* Make formats okay */
- tmpchan->readformat = chan->readformat;
- tmpchan->writeformat = chan->writeformat;
- /* Setup proper location */
- ast_explicit_goto(tmpchan,
- (!ast_strlen_zero(context)) ? context : chan->context,
- (!ast_strlen_zero(exten)) ? exten : chan->exten,
- priority);
-
- /* Masquerade into temp channel */
- ast_channel_masquerade(tmpchan, chan);
-
- /* Grab the locks and get going */
- ast_mutex_lock(&tmpchan->lock);
- ast_do_masquerade(tmpchan);
- ast_mutex_unlock(&tmpchan->lock);
- /* Start the PBX going on our stolen channel */
- if (ast_pbx_start(tmpchan)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmpchan->name);
- ast_hangup(tmpchan);
- res = -1;
- }
- } else {
- res = -1;
- }
- }
- ast_mutex_unlock(&chan->lock);
- return res;
-}
-
-int ast_async_goto_by_name(const char *channame, const char *context, const char *exten, int priority)
-{
- struct ast_channel *chan;
- int res = -1;
-
- chan = ast_get_channel_by_name_locked(channame);
- if (chan) {
- res = ast_async_goto(chan, context, exten, priority);
- ast_mutex_unlock(&chan->lock);
- }
- return res;
-}
-
-static int ext_strncpy(char *dst, const char *src, int len)
-{
- int count=0;
-
- while(*src && (count < len - 1)) {
- switch(*src) {
- case ' ':
- /* otherwise exten => [a-b],1,... doesn't work */
- /* case '-': */
- /* Ignore */
- break;
- default:
- *dst = *src;
- dst++;
- }
- src++;
- count++;
- }
- *dst = '\0';
-
- return count;
-}
-
-static void null_datad(void *foo)
-{
-}
-
-/*
- * EBUSY - can't lock
- * EEXIST - extension with the same priority exist and no replace is set
- *
- */
-int ast_add_extension2(struct ast_context *con,
- int replace, const char *extension, int priority, const char *label, const char *callerid,
- const char *application, void *data, void (*datad)(void *),
- const char *registrar)
-{
-
-#define LOG do { if (option_debug) {\
- if (tmp->matchcid) { \
- ast_log(LOG_DEBUG, "Added extension '%s' priority %d (CID match '%s') to %s\n", tmp->exten, tmp->priority, tmp->cidmatch, con->name); \
- } else { \
- ast_log(LOG_DEBUG, "Added extension '%s' priority %d to %s\n", tmp->exten, tmp->priority, con->name); \
- } \
- } else if (option_verbose > 2) { \
- if (tmp->matchcid) { \
- ast_verbose( VERBOSE_PREFIX_3 "Added extension '%s' priority %d (CID match '%s')to %s\n", tmp->exten, tmp->priority, tmp->cidmatch, con->name); \
- } else { \
- ast_verbose( VERBOSE_PREFIX_3 "Added extension '%s' priority %d to %s\n", tmp->exten, tmp->priority, con->name); \
- } \
- } } while(0)
-
- /*
- * This is a fairly complex routine. Different extensions are kept
- * in order by the extension number. Then, extensions of different
- * priorities (same extension) are kept in a list, according to the
- * peer pointer.
- */
- struct ast_exten *tmp, *e, *el = NULL, *ep = NULL;
- int res;
- int length;
- char *p;
- char expand_buf[VAR_BUF_SIZE] = { 0, };
-
- /* if we are adding a hint, and there are global variables, and the hint
- contains variable references, then expand them
- */
- if ((priority == PRIORITY_HINT) && AST_LIST_FIRST(&globals) && strstr(application, "${")) {
- pbx_substitute_variables_varshead(&globals, application, expand_buf, sizeof(expand_buf));
- application = expand_buf;
- }
-
- length = sizeof(struct ast_exten);
- length += strlen(extension) + 1;
- length += strlen(application) + 1;
- if (label)
- length += strlen(label) + 1;
- if (callerid)
- length += strlen(callerid) + 1;
- else
- length ++;
-
- /* Be optimistic: Build the extension structure first */
- if (datad == NULL)
- datad = null_datad;
- tmp = malloc(length);
- if (tmp) {
- memset(tmp, 0, length);
- p = tmp->stuff;
- if (label) {
- tmp->label = p;
- strcpy(tmp->label, label);
- p += strlen(label) + 1;
- }
- tmp->exten = p;
- p += ext_strncpy(tmp->exten, extension, strlen(extension) + 1) + 1;
- tmp->priority = priority;
- tmp->cidmatch = p;
- if (callerid) {
- p += ext_strncpy(tmp->cidmatch, callerid, strlen(callerid) + 1) + 1;
- tmp->matchcid = 1;
- } else {
- tmp->cidmatch[0] = '\0';
- tmp->matchcid = 0;
- p++;
- }
- tmp->app = p;
- strcpy(tmp->app, application);
- tmp->parent = con;
- tmp->data = data;
- tmp->datad = datad;
- tmp->registrar = registrar;
- tmp->peer = NULL;
- tmp->next = NULL;
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- errno = ENOMEM;
- return -1;
- }
- if (ast_mutex_lock(&con->lock)) {
- free(tmp);
- /* And properly destroy the data */
- datad(data);
- ast_log(LOG_WARNING, "Failed to lock context '%s'\n", con->name);
- errno = EBUSY;
- return -1;
- }
- e = con->root;
- while(e) {
- /* Make sure patterns are always last! */
- if ((e->exten[0] != '_') && (extension[0] == '_'))
- res = -1;
- else if ((e->exten[0] == '_') && (extension[0] != '_'))
- res = 1;
- else
- res= strcmp(e->exten, extension);
- if (!res) {
- if (!e->matchcid && !tmp->matchcid)
- res = 0;
- else if (tmp->matchcid && !e->matchcid)
- res = 1;
- else if (e->matchcid && !tmp->matchcid)
- res = -1;
- else
- res = strcasecmp(e->cidmatch, tmp->cidmatch);
- }
- if (res == 0) {
- /* We have an exact match, now we find where we are
- and be sure there's no duplicates */
- while(e) {
- if (e->priority == tmp->priority) {
- /* Can't have something exactly the same. Is this a
- replacement? If so, replace, otherwise, bonk. */
- if (replace) {
- if (ep) {
- /* We're in the peer list, insert ourselves */
- ep->peer = tmp;
- tmp->peer = e->peer;
- } else if (el) {
- /* We're the first extension. Take over e's functions */
- el->next = tmp;
- tmp->next = e->next;
- tmp->peer = e->peer;
- } else {
- /* We're the very first extension. */
- con->root = tmp;
- tmp->next = e->next;
- tmp->peer = e->peer;
- }
- if (tmp->priority == PRIORITY_HINT)
- ast_change_hint(e,tmp);
- /* Destroy the old one */
- e->datad(e->data);
- free(e);
- ast_mutex_unlock(&con->lock);
- if (tmp->priority == PRIORITY_HINT)
- ast_change_hint(e, tmp);
- /* And immediately return success. */
- LOG;
- return 0;
- } else {
- ast_log(LOG_WARNING, "Unable to register extension '%s', priority %d in '%s', already in use\n", tmp->exten, tmp->priority, con->name);
- tmp->datad(tmp->data);
- free(tmp);
- ast_mutex_unlock(&con->lock);
- errno = EEXIST;
- return -1;
- }
- } else if (e->priority > tmp->priority) {
- /* Slip ourselves in just before e */
- if (ep) {
- /* Easy enough, we're just in the peer list */
- ep->peer = tmp;
- tmp->peer = e;
- } else if (el) {
- /* We're the first extension in this peer list */
- el->next = tmp;
- tmp->next = e->next;
- e->next = NULL;
- tmp->peer = e;
- } else {
- /* We're the very first extension altogether */
- tmp->next = con->root->next;
- /* Con->root must always exist or we couldn't get here */
- tmp->peer = con->root;
- con->root = tmp;
- }
- ast_mutex_unlock(&con->lock);
-
- /* And immediately return success. */
- if (tmp->priority == PRIORITY_HINT)
- ast_add_hint(tmp);
-
- LOG;
- return 0;
- }
- ep = e;
- e = e->peer;
- }
- /* If we make it here, then it's time for us to go at the very end.
- ep *must* be defined or we couldn't have gotten here. */
- ep->peer = tmp;
- ast_mutex_unlock(&con->lock);
- if (tmp->priority == PRIORITY_HINT)
- ast_add_hint(tmp);
-
- /* And immediately return success. */
- LOG;
- return 0;
-
- } else if (res > 0) {
- /* Insert ourselves just before 'e'. We're the first extension of
- this kind */
- tmp->next = e;
- if (el) {
- /* We're in the list somewhere */
- el->next = tmp;
- } else {
- /* We're at the top of the list */
- con->root = tmp;
- }
- ast_mutex_unlock(&con->lock);
- if (tmp->priority == PRIORITY_HINT)
- ast_add_hint(tmp);
-
- /* And immediately return success. */
- LOG;
- return 0;
- }
-
- el = e;
- e = e->next;
- }
- /* If we fall all the way through to here, then we need to be on the end. */
- if (el)
- el->next = tmp;
- else
- con->root = tmp;
- ast_mutex_unlock(&con->lock);
- if (tmp->priority == PRIORITY_HINT)
- ast_add_hint(tmp);
- LOG;
- return 0;
-}
-
-struct async_stat {
- pthread_t p;
- struct ast_channel *chan;
- char context[AST_MAX_CONTEXT];
- char exten[AST_MAX_EXTENSION];
- int priority;
- int timeout;
- char app[AST_MAX_EXTENSION];
- char appdata[1024];
-};
-
-static void *async_wait(void *data)
-{
- struct async_stat *as = data;
- struct ast_channel *chan = as->chan;
- int timeout = as->timeout;
- int res;
- struct ast_frame *f;
- struct ast_app *app;
-
- while(timeout && (chan->_state != AST_STATE_UP)) {
- res = ast_waitfor(chan, timeout);
- if (res < 1)
- break;
- if (timeout > -1)
- timeout = res;
- f = ast_read(chan);
- if (!f)
- break;
- if (f->frametype == AST_FRAME_CONTROL) {
- if ((f->subclass == AST_CONTROL_BUSY) ||
- (f->subclass == AST_CONTROL_CONGESTION) )
- break;
- }
- ast_frfree(f);
- }
- if (chan->_state == AST_STATE_UP) {
- if (!ast_strlen_zero(as->app)) {
- app = pbx_findapp(as->app);
- if (app) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Launching %s(%s) on %s\n", as->app, as->appdata, chan->name);
- pbx_exec(chan, app, as->appdata, 1);
- } else
- ast_log(LOG_WARNING, "No such application '%s'\n", as->app);
- } else {
- if (!ast_strlen_zero(as->context))
- ast_copy_string(chan->context, as->context, sizeof(chan->context));
- if (!ast_strlen_zero(as->exten))
- ast_copy_string(chan->exten, as->exten, sizeof(chan->exten));
- if (as->priority > 0)
- chan->priority = as->priority;
- /* Run the PBX */
- if (ast_pbx_run(chan)) {
- ast_log(LOG_ERROR, "Failed to start PBX on %s\n", chan->name);
- } else {
- /* PBX will have taken care of this */
- chan = NULL;
- }
- }
-
- }
- free(as);
- if (chan)
- ast_hangup(chan);
- return NULL;
-}
-
-/*! Function to update the cdr after a spool call fails.
- *
- * This function updates the cdr for a failed spool call
- * and takes the channel of the failed call as an argument.
- *
- */
-int ast_pbx_outgoing_cdr_failed(void)
-{
- /* allocate a channel */
- struct ast_channel *chan = ast_channel_alloc(0);
- if(!chan) {
- /* allocation of the channel failed, let some peeps know */
- ast_log(LOG_WARNING, "Unable to allocate channel structure for CDR record\n");
- return -1; /* failure */
- }
-
- chan->cdr = ast_cdr_alloc(); /* allocate a cdr for the channel */
-
- if(!chan->cdr) {
- /* allocation of the cdr failed */
- ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
- ast_channel_free(chan); /* free the channel */
- return -1; /* return failure */
- }
-
- /* allocation of the cdr was successful */
- ast_cdr_init(chan->cdr, chan); /* initilize our channel's cdr */
- ast_cdr_start(chan->cdr); /* record the start and stop time */
- ast_cdr_end(chan->cdr);
- ast_cdr_failed(chan->cdr); /* set the status to failed */
- ast_cdr_detach(chan->cdr); /* post and free the record */
- ast_channel_free(chan); /* free the channel */
-
- return 0; /* success */
-}
-
-int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel)
-{
- struct ast_channel *chan;
- struct async_stat *as;
- int res = -1, cdr_res = -1;
- struct outgoing_helper oh;
- pthread_attr_t attr;
-
- if (sync) {
- LOAD_OH(oh);
- chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
- if (channel) {
- *channel = chan;
- if (chan)
- ast_mutex_lock(&chan->lock);
- }
- if (chan) {
- if (chan->cdr) { /* check if the channel already has a cdr record, if not give it one */
- ast_log(LOG_WARNING, "%s already has a call record??\n", chan->name);
- } else {
- chan->cdr = ast_cdr_alloc(); /* allocate a cdr for the channel */
- if (!chan->cdr) {
- /* allocation of the cdr failed */
- ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
- free(chan->pbx);
- res = -1;
- goto outgoing_exten_cleanup;
- }
- /* allocation of the cdr was successful */
- ast_cdr_init(chan->cdr, chan); /* initilize our channel's cdr */
- ast_cdr_start(chan->cdr);
- }
- if (chan->_state == AST_STATE_UP) {
- res = 0;
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", chan->name);
-
- if (sync > 1) {
- if (channel)
- ast_mutex_unlock(&chan->lock);
- if (ast_pbx_run(chan)) {
- ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name);
- if (channel)
- *channel = NULL;
- ast_hangup(chan);
- res = -1;
- }
- } else {
- if (ast_pbx_start(chan)) {
- ast_log(LOG_ERROR, "Unable to start PBX on %s\n", chan->name);
- if (channel)
- *channel = NULL;
- ast_hangup(chan);
- res = -1;
- }
- }
- } else {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", chan->name);
-
- if(chan->cdr) { /* update the cdr */
- /* here we update the status of the call, which sould be busy.
- * if that fails then we set the status to failed */
- if (ast_cdr_disposition(chan->cdr, chan->hangupcause))
- ast_cdr_failed(chan->cdr);
- }
-
- if (channel)
- *channel = NULL;
- ast_hangup(chan);
- }
- }
-
- if(res < 0) { /* the call failed for some reason */
- if (*reason == 0) { /* if the call failed (not busy or no answer)
- * update the cdr with the failed message */
- cdr_res = ast_pbx_outgoing_cdr_failed();
- if (cdr_res != 0) {
- res = cdr_res;
- goto outgoing_exten_cleanup;
- }
- }
-
- /* create a fake channel and execute the "failed" extension (if it exists) within the requested context */
- /* check if "failed" exists */
- if (ast_exists_extension(chan, context, "failed", 1, NULL)) {
- chan = ast_channel_alloc(0);
- if (chan) {
- ast_copy_string(chan->name, "OutgoingSpoolFailed", sizeof(chan->name));
- if (!ast_strlen_zero(context))
- ast_copy_string(chan->context, context, sizeof(chan->context));
- ast_copy_string(chan->exten, "failed", sizeof(chan->exten));
- chan->priority = 1;
- ast_set_variables(chan, vars);
- if (account)
- ast_cdr_setaccount(chan, account);
- ast_pbx_run(chan);
- } else
- ast_log(LOG_WARNING, "Can't allocate the channel structure, skipping execution of extension 'failed'\n");
- }
- }
- } else {
- as = malloc(sizeof(struct async_stat));
- if (!as) {
- res = -1;
- goto outgoing_exten_cleanup;
- }
- memset(as, 0, sizeof(struct async_stat));
- chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name);
- if (channel) {
- *channel = chan;
- if (chan)
- ast_mutex_lock(&chan->lock);
- }
- if (!chan) {
- free(as);
- res = -1;
- goto outgoing_exten_cleanup;
- }
- as->chan = chan;
- ast_copy_string(as->context, context, sizeof(as->context));
- ast_copy_string(as->exten, exten, sizeof(as->exten));
- as->priority = priority;
- as->timeout = timeout;
- ast_set_variables(chan, vars);
- if (account)
- ast_cdr_setaccount(chan, account);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&as->p, &attr, async_wait, as)) {
- ast_log(LOG_WARNING, "Failed to start async wait\n");
- free(as);
- if (channel)
- *channel = NULL;
- ast_hangup(chan);
- res = -1;
- goto outgoing_exten_cleanup;
- }
- res = 0;
- }
-outgoing_exten_cleanup:
- ast_variables_destroy(vars);
- return res;
-}
-
-struct app_tmp {
- char app[256];
- char data[256];
- struct ast_channel *chan;
- pthread_t t;
-};
-
-static void *ast_pbx_run_app(void *data)
-{
- struct app_tmp *tmp = data;
- struct ast_app *app;
- app = pbx_findapp(tmp->app);
- if (app) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Launching %s(%s) on %s\n", tmp->app, tmp->data, tmp->chan->name);
- pbx_exec(tmp->chan, app, tmp->data, 1);
- } else
- ast_log(LOG_WARNING, "No such application '%s'\n", tmp->app);
- ast_hangup(tmp->chan);
- free(tmp);
- return NULL;
-}
-
-int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel)
-{
- struct ast_channel *chan;
- struct async_stat *as;
- struct app_tmp *tmp;
- int res = -1, cdr_res = -1;
- struct outgoing_helper oh;
- pthread_attr_t attr;
-
- memset(&oh, 0, sizeof(oh));
- oh.vars = vars;
- oh.account = account;
-
- if (locked_channel)
- *locked_channel = NULL;
- if (ast_strlen_zero(app)) {
- res = -1;
- goto outgoing_app_cleanup;
- }
- if (sync) {
- chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
- if (chan) {
- if (chan->cdr) { /* check if the channel already has a cdr record, if not give it one */
- ast_log(LOG_WARNING, "%s already has a call record??\n", chan->name);
- } else {
- chan->cdr = ast_cdr_alloc(); /* allocate a cdr for the channel */
- if(!chan->cdr) {
- /* allocation of the cdr failed */
- ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
- free(chan->pbx);
- res = -1;
- goto outgoing_app_cleanup;
- }
- /* allocation of the cdr was successful */
- ast_cdr_init(chan->cdr, chan); /* initilize our channel's cdr */
- ast_cdr_start(chan->cdr);
- }
- ast_set_variables(chan, vars);
- if (account)
- ast_cdr_setaccount(chan, account);
- if (chan->_state == AST_STATE_UP) {
- res = 0;
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", chan->name);
- tmp = malloc(sizeof(struct app_tmp));
- if (tmp) {
- memset(tmp, 0, sizeof(struct app_tmp));
- ast_copy_string(tmp->app, app, sizeof(tmp->app));
- if (appdata)
- ast_copy_string(tmp->data, appdata, sizeof(tmp->data));
- tmp->chan = chan;
- if (sync > 1) {
- if (locked_channel)
- ast_mutex_unlock(&chan->lock);
- ast_pbx_run_app(tmp);
- } else {
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (locked_channel)
- ast_mutex_lock(&chan->lock);
- if (ast_pthread_create(&tmp->t, &attr, ast_pbx_run_app, tmp)) {
- ast_log(LOG_WARNING, "Unable to spawn execute thread on %s: %s\n", chan->name, strerror(errno));
- free(tmp);
- if (locked_channel)
- ast_mutex_unlock(&chan->lock);
- ast_hangup(chan);
- res = -1;
- } else {
- if (locked_channel)
- *locked_channel = chan;
- }
- }
- } else {
- ast_log(LOG_ERROR, "Out of memory :(\n");
- res = -1;
- }
- } else {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", chan->name);
- if (chan->cdr) { /* update the cdr */
- /* here we update the status of the call, which sould be busy.
- * if that fails then we set the status to failed */
- if (ast_cdr_disposition(chan->cdr, chan->hangupcause))
- ast_cdr_failed(chan->cdr);
- }
- ast_hangup(chan);
- }
- }
-
- if (res < 0) { /* the call failed for some reason */
- if (*reason == 0) { /* if the call failed (not busy or no answer)
- * update the cdr with the failed message */
- cdr_res = ast_pbx_outgoing_cdr_failed();
- if (cdr_res != 0) {
- res = cdr_res;
- goto outgoing_app_cleanup;
- }
- }
- }
-
- } else {
- as = malloc(sizeof(struct async_stat));
- if (!as) {
- res = -1;
- goto outgoing_app_cleanup;
- }
- memset(as, 0, sizeof(struct async_stat));
- chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
- if (!chan) {
- free(as);
- res = -1;
- goto outgoing_app_cleanup;
- }
- as->chan = chan;
- ast_copy_string(as->app, app, sizeof(as->app));
- if (appdata)
- ast_copy_string(as->appdata, appdata, sizeof(as->appdata));
- as->timeout = timeout;
- ast_set_variables(chan, vars);
- if (account)
- ast_cdr_setaccount(chan, account);
- /* Start a new thread, and get something handling this channel. */
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (locked_channel)
- ast_mutex_lock(&chan->lock);
- if (ast_pthread_create(&as->p, &attr, async_wait, as)) {
- ast_log(LOG_WARNING, "Failed to start async wait\n");
- free(as);
- if (locked_channel)
- ast_mutex_unlock(&chan->lock);
- ast_hangup(chan);
- res = -1;
- goto outgoing_app_cleanup;
- } else {
- if (locked_channel)
- *locked_channel = chan;
- }
- res = 0;
- }
-outgoing_app_cleanup:
- ast_variables_destroy(vars);
- return res;
-}
-
-static void destroy_exten(struct ast_exten *e)
-{
- if (e->priority == PRIORITY_HINT)
- ast_remove_hint(e);
-
- if (e->datad)
- e->datad(e->data);
- free(e);
-}
-
-void __ast_context_destroy(struct ast_context *con, const char *registrar)
-{
- struct ast_context *tmp, *tmpl=NULL;
- struct ast_include *tmpi, *tmpil= NULL;
- struct ast_sw *sw, *swl= NULL;
- struct ast_exten *e, *el, *en;
- struct ast_ignorepat *ipi, *ipl = NULL;
-
- ast_mutex_lock(&conlock);
- tmp = contexts;
- while(tmp) {
- if (((tmp->name && con && con->name && !strcasecmp(tmp->name, con->name)) || !con) &&
- (!registrar || !strcasecmp(registrar, tmp->registrar))) {
- /* Okay, let's lock the structure to be sure nobody else
- is searching through it. */
- if (ast_mutex_lock(&tmp->lock)) {
- ast_log(LOG_WARNING, "Unable to lock context lock\n");
- return;
- }
- if (tmpl)
- tmpl->next = tmp->next;
- else
- contexts = tmp->next;
- /* Okay, now we're safe to let it go -- in a sense, we were
- ready to let it go as soon as we locked it. */
- ast_mutex_unlock(&tmp->lock);
- for (tmpi = tmp->includes; tmpi; ) {
- /* Free includes */
- tmpil = tmpi;
- tmpi = tmpi->next;
- free(tmpil);
- }
- for (ipi = tmp->ignorepats; ipi; ) {
- /* Free ignorepats */
- ipl = ipi;
- ipi = ipi->next;
- free(ipl);
- }
- for (sw = tmp->alts; sw; ) {
- /* Free switches */
- swl = sw;
- sw = sw->next;
- free(swl);
- swl = sw;
- }
- for (e = tmp->root; e;) {
- for (en = e->peer; en;) {
- el = en;
- en = en->peer;
- destroy_exten(el);
- }
- el = e;
- e = e->next;
- destroy_exten(el);
- }
- ast_mutex_destroy(&tmp->lock);
- free(tmp);
- if (!con) {
- /* Might need to get another one -- restart */
- tmp = contexts;
- tmpl = NULL;
- tmpil = NULL;
- continue;
- }
- ast_mutex_unlock(&conlock);
- return;
- }
- tmpl = tmp;
- tmp = tmp->next;
- }
- ast_mutex_unlock(&conlock);
-}
-
-void ast_context_destroy(struct ast_context *con, const char *registrar)
-{
- __ast_context_destroy(con,registrar);
-}
-
-static void wait_for_hangup(struct ast_channel *chan, void *data)
-{
- int res;
- struct ast_frame *f;
- int waittime;
-
- if (ast_strlen_zero(data) || (sscanf(data, "%d", &waittime) != 1) || (waittime < 0))
- waittime = -1;
- if (waittime > -1) {
- ast_safe_sleep(chan, waittime * 1000);
- } else do {
- res = ast_waitfor(chan, -1);
- if (res < 0)
- return;
- f = ast_read(chan);
- if (f)
- ast_frfree(f);
- } while(f);
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_progress(struct ast_channel *chan, void *data)
-{
- ast_indicate(chan, AST_CONTROL_PROGRESS);
- return 0;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_ringing(struct ast_channel *chan, void *data)
-{
- ast_indicate(chan, AST_CONTROL_RINGING);
- return 0;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_busy(struct ast_channel *chan, void *data)
-{
- ast_indicate(chan, AST_CONTROL_BUSY);
- ast_setstate(chan, AST_STATE_BUSY);
- wait_for_hangup(chan, data);
- return -1;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_congestion(struct ast_channel *chan, void *data)
-{
- ast_indicate(chan, AST_CONTROL_CONGESTION);
- ast_setstate(chan, AST_STATE_BUSY);
- wait_for_hangup(chan, data);
- return -1;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_answer(struct ast_channel *chan, void *data)
-{
- int delay = 0;
- int res;
-
- if (chan->_state == AST_STATE_UP)
- delay = 0;
- else if (!ast_strlen_zero(data))
- delay = atoi(data);
-
- res = ast_answer(chan);
- if (res)
- return res;
-
- if (delay)
- res = ast_safe_sleep(chan, delay);
-
- return res;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_setlanguage(struct ast_channel *chan, void *data)
-{
- static int deprecation_warning = 0;
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "SetLanguage is deprecated, please use Set(LANGUAGE()=language) instead.\n");
- deprecation_warning = 1;
- }
-
- /* Copy the language as specified */
- if (!ast_strlen_zero(data))
- ast_copy_string(chan->language, data, sizeof(chan->language));
-
- return 0;
-}
-
-AST_APP_OPTIONS(resetcdr_opts, {
- AST_APP_OPTION('w', AST_CDR_FLAG_POSTED),
- AST_APP_OPTION('a', AST_CDR_FLAG_LOCKED),
- AST_APP_OPTION('v', AST_CDR_FLAG_KEEP_VARS),
-});
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_resetcdr(struct ast_channel *chan, void *data)
-{
- char *args;
- struct ast_flags flags = { 0 };
-
- if (!ast_strlen_zero(data)) {
- args = ast_strdupa(data);
- if (!args) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- return -1;
- }
- ast_app_parse_options(resetcdr_opts, &flags, NULL, args);
- }
-
- ast_cdr_reset(chan->cdr, &flags);
-
- return 0;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_setaccount(struct ast_channel *chan, void *data)
-{
- /* Copy the account code as specified */
- if (data)
- ast_cdr_setaccount(chan, (char *)data);
- else
- ast_cdr_setaccount(chan, "");
- return 0;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_setamaflags(struct ast_channel *chan, void *data)
-{
- /* Copy the AMA Flags as specified */
- if (data)
- ast_cdr_setamaflags(chan, (char *)data);
- else
- ast_cdr_setamaflags(chan, "");
- return 0;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_hangup(struct ast_channel *chan, void *data)
-{
- /* Just return non-zero and it will hang up */
- if (!chan->hangupcause)
- chan->hangupcause = AST_CAUSE_NORMAL_CLEARING;
- return -1;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_gotoiftime(struct ast_channel *chan, void *data)
-{
- int res=0;
- char *s, *ts;
- struct ast_timing timing;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "GotoIfTime requires an argument:\n <time range>|<days of week>|<days of month>|<months>?[[context|]extension|]priority\n");
- return -1;
- }
-
- if ((s = ast_strdupa((char *) data))) {
- ts = s;
-
- /* Separate the Goto path */
- strsep(&ts,"?");
-
- /* struct ast_include include contained garbage here, fixed by zeroing it on get_timerange */
- if (ast_build_timing(&timing, s) && ast_check_timing(&timing))
- res = pbx_builtin_goto(chan, (void *)ts);
- } else {
- ast_log(LOG_ERROR, "Memory Error!\n");
- }
- return res;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
-{
- int res = 0;
- char *ptr1, *ptr2;
- struct ast_timing timing;
- struct ast_app *app;
- const char *usage = "ExecIfTime requires an argument:\n <time range>|<days of week>|<days of month>|<months>?<appname>[|<appargs>]";
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "%s\n", usage);
- return -1;
- }
-
- ptr1 = ast_strdupa(data);
-
- if (!ptr1) {
- ast_log(LOG_ERROR, "Out of Memory!\n");
- return -1;
- }
-
- ptr2 = ptr1;
- /* Separate the Application data ptr1 is the time spec ptr2 is the app|data */
- strsep(&ptr2,"?");
- if(!ast_build_timing(&timing, ptr1)) {
- ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", ptr1, usage);
- res = -1;
- }
-
- if (!res && ast_check_timing(&timing)) {
- if (!ptr2) {
- ast_log(LOG_WARNING, "%s\n", usage);
- }
-
- /* ptr2 is now the app name
- we're done with ptr1 now so recycle it and use it to point to the app args */
- if((ptr1 = strchr(ptr2, '|'))) {
- *ptr1 = '\0';
- ptr1++;
- }
-
- if ((app = pbx_findapp(ptr2))) {
- res = pbx_exec(chan, app, ptr1 ? ptr1 : "", 1);
- } else {
- ast_log(LOG_WARNING, "Cannot locate application %s\n", ptr2);
- res = -1;
- }
- }
-
- return res;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_wait(struct ast_channel *chan, void *data)
-{
- int ms;
-
- /* Wait for "n" seconds */
- if (data && atof((char *)data)) {
- ms = atof((char *)data) * 1000;
- return ast_safe_sleep(chan, ms);
- }
- return 0;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_waitexten(struct ast_channel *chan, void *data)
-{
- int ms, res, argc;
- char *args;
- char *argv[2];
- char *options = NULL;
- char *timeout = NULL;
- struct ast_flags flags = {0};
- char *opts[1] = { NULL };
-
- args = ast_strdupa(data);
-
- if ((argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
- if (argc > 0) {
- timeout = argv[0];
- if (argc > 1)
- options = argv[1];
- }
- }
-
- if (options)
- ast_app_parse_options(waitexten_opts, &flags, opts, options);
-
- if (ast_test_flag(&flags, WAITEXTEN_MOH))
- ast_moh_start(chan, opts[0]);
-
- /* Wait for "n" seconds */
- if (timeout && atof((char *)timeout))
- ms = atof((char *)timeout) * 1000;
- else if (chan->pbx)
- ms = chan->pbx->rtimeout * 1000;
- else
- ms = 10000;
- res = ast_waitfordigit(chan, ms);
- if (!res) {
- if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1, chan->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, continuing...\n", chan->name);
- } else if (ast_exists_extension(chan, chan->context, "t", 1, chan->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, going to 't'\n", chan->name);
- ast_copy_string(chan->exten, "t", sizeof(chan->exten));
- chan->priority = 0;
- } else {
- ast_log(LOG_WARNING, "Timeout but no rule 't' in context '%s'\n", chan->context);
- res = -1;
- }
- }
-
- if (ast_test_flag(&flags, WAITEXTEN_MOH))
- ast_moh_stop(chan);
-
- return res;
-}
-
-/*!
- * \ingroup applications
- */
-static int pbx_builtin_background(struct ast_channel *chan, void *data)
-{
- int res = 0;
- int argc;
- char *parse;
- char *argv[4];
- char *options = NULL;
- char *filename = NULL;
- char *front = NULL, *back = NULL;
- char *lang = NULL;
- char *context = NULL;
- struct ast_flags flags = {0};
-
- parse = ast_strdupa(data);
-
- if ((argc = ast_app_separate_args(parse, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
- switch (argc) {
- case 4:
- context = argv[3];
- case 3:
- lang = argv[2];
- case 2:
- options = argv[1];
- case 1:
- filename = argv[0];
- break;
- default:
- ast_log(LOG_WARNING, "Background requires an argument (filename)\n");
- break;
- }
- }
-
- if (!lang)
- lang = chan->language;
-
- if (!context)
- context = chan->context;
-
- if (options) {
- if (!strcasecmp(options, "skip"))
- flags.flags = BACKGROUND_SKIP;
- else if (!strcasecmp(options, "noanswer"))
- flags.flags = BACKGROUND_NOANSWER;
- else
- ast_app_parse_options(background_opts, &flags, NULL, options);
- }
-
- /* Answer if need be */
- if (chan->_state != AST_STATE_UP) {
- if (ast_test_flag(&flags, BACKGROUND_SKIP)) {
- return 0;
- } else if (!ast_test_flag(&flags, BACKGROUND_NOANSWER)) {
- res = ast_answer(chan);
- }
- }
-
- if (!res) {
- /* Stop anything playing */
- ast_stopstream(chan);
- /* Stream a file */
- front = filename;
- while(!res && front) {
- if((back = strchr(front, '&'))) {
- *back = '\0';
- back++;
- }
- res = ast_streamfile(chan, front, lang);
- if (!res) {
- if (ast_test_flag(&flags, BACKGROUND_PLAYBACK)) {
- res = ast_waitstream(chan, "");
- } else {
- if (ast_test_flag(&flags, BACKGROUND_MATCHEXTEN)) {
- res = ast_waitstream_exten(chan, context);
- } else {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- }
- }
- ast_stopstream(chan);
- } else {
- ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char*)data);
- res = 0;
- break;
- }
- front = back;
- }
- }
- if (context != chan->context && res) {
- snprintf(chan->exten, sizeof(chan->exten), "%c", res);
- ast_copy_string(chan->context, context, sizeof(chan->context));
- chan->priority = 0;
- return 0;
- } else {
- return res;
- }
-}
-
-/*! AbsoluteTimeout
- * \ingroup applications
- * \todo Remove in 1.3 dev
- */
-static int pbx_builtin_atimeout(struct ast_channel *chan, void *data)
-{
- static int deprecation_warning = 0;
- int x = atoi((char *) data);
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "AbsoluteTimeout is deprecated, please use Set(TIMEOUT(absolute)=timeout) instead.\n");
- deprecation_warning = 1;
- }
-
- /* Set the absolute maximum time how long a call can be connected */
- ast_channel_setwhentohangup(chan,x);
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Set Absolute Timeout to %d\n", x);
- return 0;
-}
-
-/*! ResponseTimeout
- * \ingroup applications
- * \todo Remove in 1.3 dev
- */
-static int pbx_builtin_rtimeout(struct ast_channel *chan, void *data)
-{
- static int deprecation_warning = 0;
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "ResponseTimeout is deprecated, please use Set(TIMEOUT(response)=timeout) instead.\n");
- deprecation_warning = 1;
- }
-
- /* If the channel is not in a PBX, return now */
- if (!chan->pbx)
- return 0;
-
- /* Set the timeout for how long to wait between digits */
- chan->pbx->rtimeout = atoi((char *)data);
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Set Response Timeout to %d\n", chan->pbx->rtimeout);
- return 0;
-}
-
-/*! DigitTimeout
- * \ingroup applications
- * \todo Remove in 1.3 dev
- */
-static int pbx_builtin_dtimeout(struct ast_channel *chan, void *data)
-{
- static int deprecation_warning = 0;
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "DigitTimeout is deprecated, please use Set(TIMEOUT(digit)=timeout) instead.\n");
- deprecation_warning = 1;
- }
-
- /* If the channel is not in a PBX, return now */
- if (!chan->pbx)
- return 0;
-
- /* Set the timeout for how long to wait between digits */
- chan->pbx->dtimeout = atoi((char *)data);
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Set Digit Timeout to %d\n", chan->pbx->dtimeout);
- return 0;
-}
-
-/*! Goto
- * \ingroup applications
- */
-static int pbx_builtin_goto(struct ast_channel *chan, void *data)
-{
- int res;
- res = ast_parseable_goto(chan, (const char *) data);
- if (!res && (option_verbose > 2))
- ast_verbose( VERBOSE_PREFIX_3 "Goto (%s,%s,%d)\n", chan->context,chan->exten, chan->priority+1);
- return res;
-}
-
-
-int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size)
-{
- struct ast_var_t *variables;
- char *var, *val;
- int total = 0;
-
- if (!chan)
- return 0;
-
- memset(buf, 0, size);
-
- AST_LIST_TRAVERSE(&chan->varshead, variables, entries) {
- if(variables &&
- (var=ast_var_name(variables)) && (val=ast_var_value(variables)) &&
- !ast_strlen_zero(var) && !ast_strlen_zero(val)) {
- if (ast_build_string(&buf, &size, "%s=%s\n", var, val)) {
- ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
- break;
- } else
- total++;
- } else
- break;
- }
-
- return total;
-}
-
-char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
-{
- struct ast_var_t *variables;
- struct varshead *headp;
-
- if (chan)
- headp=&chan->varshead;
- else
- headp=&globals;
-
- if (name) {
- AST_LIST_TRAVERSE(headp,variables,entries) {
- if (!strcmp(name, ast_var_name(variables)))
- return ast_var_value(variables);
- }
- if (headp != &globals) {
- /* Check global variables if we haven't already */
- headp = &globals;
- AST_LIST_TRAVERSE(headp,variables,entries) {
- if (!strcmp(name, ast_var_name(variables)))
- return ast_var_value(variables);
- }
- }
- }
- return NULL;
-}
-
-void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value)
-{
- struct ast_var_t *newvariable;
- struct varshead *headp;
-
- if (name[strlen(name)-1] == ')') {
- ast_log(LOG_WARNING, "Cannot push a value onto a function\n");
- return ast_func_write(chan, name, value);
- }
-
- headp = (chan) ? &chan->varshead : &globals;
-
- if (value) {
- if ((option_verbose > 1) && (headp == &globals))
- ast_verbose(VERBOSE_PREFIX_2 "Setting global variable '%s' to '%s'\n", name, value);
- newvariable = ast_var_assign(name, value);
- AST_LIST_INSERT_HEAD(headp, newvariable, entries);
- }
-}
-
-void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
-{
- struct ast_var_t *newvariable;
- struct varshead *headp;
- const char *nametail = name;
-
- if (name[strlen(name)-1] == ')')
- return ast_func_write(chan, name, value);
-
- headp = (chan) ? &chan->varshead : &globals;
-
- /* For comparison purposes, we have to strip leading underscores */
- if (*nametail == '_') {
- nametail++;
- if (*nametail == '_')
- nametail++;
- }
-
- AST_LIST_TRAVERSE (headp, newvariable, entries) {
- if (strcasecmp(ast_var_name(newvariable), nametail) == 0) {
- /* there is already such a variable, delete it */
- AST_LIST_REMOVE(headp, newvariable, entries);
- ast_var_delete(newvariable);
- break;
- }
- }
-
- if (value) {
- if ((option_verbose > 1) && (headp == &globals))
- ast_verbose(VERBOSE_PREFIX_2 "Setting global variable '%s' to '%s'\n", name, value);
- newvariable = ast_var_assign(name, value);
- AST_LIST_INSERT_HEAD(headp, newvariable, entries);
- }
-}
-
-int pbx_builtin_setvar_old(struct ast_channel *chan, void *data)
-{
- static int deprecation_warning = 0;
-
- if (!deprecation_warning) {
- ast_log(LOG_WARNING, "SetVar is deprecated, please use Set instead.\n");
- deprecation_warning = 1;
- }
-
- return pbx_builtin_setvar(chan, data);
-}
-
-int pbx_builtin_setvar(struct ast_channel *chan, void *data)
-{
- char *name, *value, *mydata;
- int argc;
- char *argv[24]; /* this will only support a maximum of 24 variables being set in a single operation */
- int global = 0;
- int x;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Set requires at least one variable name/value pair.\n");
- return 0;
- }
-
- mydata = ast_strdupa(data);
- argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
-
- /* check for a trailing flags argument */
- if ((argc > 1) && !strchr(argv[argc-1], '=')) {
- argc--;
- if (strchr(argv[argc], 'g'))
- global = 1;
- }
-
- for (x = 0; x < argc; x++) {
- name = argv[x];
- if ((value = strchr(name, '='))) {
- *value = '\0';
- value++;
- pbx_builtin_setvar_helper((global) ? NULL : chan, name, value);
- } else
- ast_log(LOG_WARNING, "Ignoring entry '%s' with no = (and not last 'options' entry)\n", name);
- }
-
- return(0);
-}
-
-int pbx_builtin_importvar(struct ast_channel *chan, void *data)
-{
- char *name;
- char *value;
- char *stringp=NULL;
- char *channel;
- struct ast_channel *chan2;
- char tmp[VAR_BUF_SIZE]="";
- char *s;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
- return 0;
- }
-
- stringp = ast_strdupa(data);
- name = strsep(&stringp,"=");
- channel = strsep(&stringp,"|");
- value = strsep(&stringp,"\0");
- if (channel && value && name) {
- chan2 = ast_get_channel_by_name_locked(channel);
- if (chan2) {
- s = alloca(strlen(value) + 4);
- if (s) {
- sprintf(s, "${%s}", value);
- pbx_substitute_variables_helper(chan2, s, tmp, sizeof(tmp) - 1);
- }
- ast_mutex_unlock(&chan2->lock);
- }
- pbx_builtin_setvar_helper(chan, name, tmp);
- }
-
- return(0);
-}
-
-static int pbx_builtin_setglobalvar(struct ast_channel *chan, void *data)
-{
- char *name;
- char *value;
- char *stringp = NULL;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
- return 0;
- }
-
- stringp = data;
- name = strsep(&stringp, "=");
- value = strsep(&stringp, "\0");
-
- pbx_builtin_setvar_helper(NULL, name, value);
-
- return(0);
-}
-
-static int pbx_builtin_noop(struct ast_channel *chan, void *data)
-{
- return 0;
-}
-
-
-void pbx_builtin_clear_globals(void)
-{
- struct ast_var_t *vardata;
- while (!AST_LIST_EMPTY(&globals)) {
- vardata = AST_LIST_REMOVE_HEAD(&globals, entries);
- ast_var_delete(vardata);
- }
-}
-
-static int pbx_checkcondition(char *condition)
-{
- if (condition) {
- if (*condition == '\0') {
- /* Empty strings are false */
- return 0;
- } else if (*condition >= '0' && *condition <= '9') {
- /* Numbers are evaluated for truth */
- return atoi(condition);
- } else {
- /* Strings are true */
- return 1;
- }
- } else {
- /* NULL is also false */
- return 0;
- }
-}
-
-static int pbx_builtin_gotoif(struct ast_channel *chan, void *data)
-{
- char *condition, *branch1, *branch2, *branch;
- char *s;
- int rc;
- char *stringp=NULL;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Ignoring, since there is no variable to check\n");
- return 0;
- }
-
- s = ast_strdupa(data);
- stringp = s;
- condition = strsep(&stringp,"?");
- branch1 = strsep(&stringp,":");
- branch2 = strsep(&stringp,"");
- branch = pbx_checkcondition(condition) ? branch1 : branch2;
-
- if (ast_strlen_zero(branch)) {
- ast_log(LOG_DEBUG, "Not taking any branch\n");
- return 0;
- }
-
- rc = pbx_builtin_goto(chan, branch);
-
- return rc;
-}
-
-static int pbx_builtin_saynumber(struct ast_channel *chan, void *data)
-{
- int res = 0;
- char tmp[256];
- char *number = (char *) NULL;
- char *options = (char *) NULL;
-
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "SayNumber requires an argument (number)\n");
- return -1;
- }
- ast_copy_string(tmp, (char *) data, sizeof(tmp));
- number=tmp;
- strsep(&number, "|");
- options = strsep(&number, "|");
- if (options) {
- if ( strcasecmp(options, "f") && strcasecmp(options,"m") &&
- strcasecmp(options, "c") && strcasecmp(options, "n") ) {
- ast_log(LOG_WARNING, "SayNumber gender option is either 'f', 'm', 'c' or 'n'\n");
- return -1;
- }
- }
- return res = ast_say_number(chan, atoi((char *) tmp), "", chan->language, options);
-}
-
-static int pbx_builtin_saydigits(struct ast_channel *chan, void *data)
-{
- int res = 0;
-
- if (data)
- res = ast_say_digit_str(chan, (char *)data, "", chan->language);
- return res;
-}
-
-static int pbx_builtin_saycharacters(struct ast_channel *chan, void *data)
-{
- int res = 0;
-
- if (data)
- res = ast_say_character_str(chan, (char *)data, "", chan->language);
- return res;
-}
-
-static int pbx_builtin_sayphonetic(struct ast_channel *chan, void *data)
-{
- int res = 0;
-
- if (data)
- res = ast_say_phonetic_str(chan, (char *)data, "", chan->language);
- return res;
-}
-
-int load_pbx(void)
-{
- int x;
-
- /* Initialize the PBX */
- if (option_verbose) {
- ast_verbose( "Asterisk PBX Core Initializing\n");
- ast_verbose( "Registering builtin applications:\n");
- }
- AST_LIST_HEAD_INIT_NOLOCK(&globals);
- ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(pbx_cli[0]));
-
- /* Register builtin applications */
- for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {
- if (option_verbose)
- ast_verbose( VERBOSE_PREFIX_1 "[%s]\n", builtins[x].name);
- if (ast_register_application(builtins[x].name, builtins[x].execute, builtins[x].synopsis, builtins[x].description)) {
- ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
- return -1;
- }
- }
- return 0;
-}
-
-/*
- * Lock context list functions ...
- */
-int ast_lock_contexts()
-{
- return ast_mutex_lock(&conlock);
-}
-
-int ast_unlock_contexts()
-{
- return ast_mutex_unlock(&conlock);
-}
-
-/*
- * Lock context ...
- */
-int ast_lock_context(struct ast_context *con)
-{
- return ast_mutex_lock(&con->lock);
-}
-
-int ast_unlock_context(struct ast_context *con)
-{
- return ast_mutex_unlock(&con->lock);
-}
-
-/*
- * Name functions ...
- */
-const char *ast_get_context_name(struct ast_context *con)
-{
- return con ? con->name : NULL;
-}
-
-const char *ast_get_extension_name(struct ast_exten *exten)
-{
- return exten ? exten->exten : NULL;
-}
-
-const char *ast_get_extension_label(struct ast_exten *exten)
-{
- return exten ? exten->label : NULL;
-}
-
-const char *ast_get_include_name(struct ast_include *inc)
-{
- return inc ? inc->name : NULL;
-}
-
-const char *ast_get_ignorepat_name(struct ast_ignorepat *ip)
-{
- return ip ? ip->pattern : NULL;
-}
-
-int ast_get_extension_priority(struct ast_exten *exten)
-{
- return exten ? exten->priority : -1;
-}
-
-/*
- * Registrar info functions ...
- */
-const char *ast_get_context_registrar(struct ast_context *c)
-{
- return c ? c->registrar : NULL;
-}
-
-const char *ast_get_extension_registrar(struct ast_exten *e)
-{
- return e ? e->registrar : NULL;
-}
-
-const char *ast_get_include_registrar(struct ast_include *i)
-{
- return i ? i->registrar : NULL;
-}
-
-const char *ast_get_ignorepat_registrar(struct ast_ignorepat *ip)
-{
- return ip ? ip->registrar : NULL;
-}
-
-int ast_get_extension_matchcid(struct ast_exten *e)
-{
- return e ? e->matchcid : 0;
-}
-
-const char *ast_get_extension_cidmatch(struct ast_exten *e)
-{
- return e ? e->cidmatch : NULL;
-}
-
-const char *ast_get_extension_app(struct ast_exten *e)
-{
- return e ? e->app : NULL;
-}
-
-void *ast_get_extension_app_data(struct ast_exten *e)
-{
- return e ? e->data : NULL;
-}
-
-const char *ast_get_switch_name(struct ast_sw *sw)
-{
- return sw ? sw->name : NULL;
-}
-
-const char *ast_get_switch_data(struct ast_sw *sw)
-{
- return sw ? sw->data : NULL;
-}
-
-const char *ast_get_switch_registrar(struct ast_sw *sw)
-{
- return sw ? sw->registrar : NULL;
-}
-
-/*
- * Walking functions ...
- */
-struct ast_context *ast_walk_contexts(struct ast_context *con)
-{
- if (!con)
- return contexts;
- else
- return con->next;
-}
-
-struct ast_exten *ast_walk_context_extensions(struct ast_context *con,
- struct ast_exten *exten)
-{
- if (!exten)
- return con ? con->root : NULL;
- else
- return exten->next;
-}
-
-struct ast_sw *ast_walk_context_switches(struct ast_context *con,
- struct ast_sw *sw)
-{
- if (!sw)
- return con ? con->alts : NULL;
- else
- return sw->next;
-}
-
-struct ast_exten *ast_walk_extension_priorities(struct ast_exten *exten,
- struct ast_exten *priority)
-{
- if (!priority)
- return exten;
- else
- return priority->peer;
-}
-
-struct ast_include *ast_walk_context_includes(struct ast_context *con,
- struct ast_include *inc)
-{
- if (!inc)
- return con ? con->includes : NULL;
- else
- return inc->next;
-}
-
-struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con,
- struct ast_ignorepat *ip)
-{
- if (!ip)
- return con ? con->ignorepats : NULL;
- else
- return ip->next;
-}
-
-int ast_context_verify_includes(struct ast_context *con)
-{
- struct ast_include *inc;
- int res = 0;
-
- for (inc = ast_walk_context_includes(con, NULL); inc; inc = ast_walk_context_includes(con, inc))
- if (!ast_context_find(inc->rname)) {
- res = -1;
- ast_log(LOG_WARNING, "Context '%s' tries includes nonexistent context '%s'\n",
- ast_get_context_name(con), inc->rname);
- }
- return res;
-}
-
-
-static int __ast_goto_if_exists(struct ast_channel *chan, char *context, char *exten, int priority, int async)
-{
- int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority);
-
- if (!chan)
- return -2;
-
- goto_func = (async) ? ast_async_goto : ast_explicit_goto;
- if (ast_exists_extension(chan, context ? context : chan->context,
- exten ? exten : chan->exten, priority,
- chan->cid.cid_num))
- return goto_func(chan, context ? context : chan->context,
- exten ? exten : chan->exten, priority);
- else
- return -3;
-}
-
-int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) {
- return __ast_goto_if_exists(chan, context, exten, priority, 0);
-}
-
-int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) {
- return __ast_goto_if_exists(chan, context, exten, priority, 1);
-}
-
-int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
-{
- char *s;
- char *exten, *pri, *context;
- char *stringp=NULL;
- int ipri;
- int mode = 0;
-
- if (ast_strlen_zero(goto_string)) {
- ast_log(LOG_WARNING, "Goto requires an argument (optional context|optional extension|priority)\n");
- return -1;
- }
- s = ast_strdupa(goto_string);
- stringp=s;
- context = strsep(&stringp, "|");
- exten = strsep(&stringp, "|");
- if (!exten) {
- /* Only a priority in this one */
- pri = context;
- exten = NULL;
- context = NULL;
- } else {
- pri = strsep(&stringp, "|");
- if (!pri) {
- /* Only an extension and priority in this one */
- pri = exten;
- exten = context;
- context = NULL;
- }
- }
- if (*pri == '+') {
- mode = 1;
- pri++;
- } else if (*pri == '-') {
- mode = -1;
- pri++;
- }
- if (sscanf(pri, "%d", &ipri) != 1) {
- if ((ipri = ast_findlabel_extension(chan, context ? context : chan->context, (exten && strcasecmp(exten, "BYEXTENSION")) ? exten : chan->exten,
- pri, chan->cid.cid_num)) < 1) {
- ast_log(LOG_WARNING, "Priority '%s' must be a number > 0, or valid label\n", pri);
- return -1;
- } else
- mode = 0;
- }
- /* At this point we have a priority and maybe an extension and a context */
-
- if (exten && !strcasecmp(exten, "BYEXTENSION"))
- exten = NULL;
-
- if (mode)
- ipri = chan->priority + (ipri * mode);
-
- ast_explicit_goto(chan, context, exten, ipri);
- ast_cdr_update(chan);
- return 0;
-
-}
diff --git a/1.2-netsec/pbx/Makefile b/1.2-netsec/pbx/Makefile
deleted file mode 100644
index f86ae4859..000000000
--- a/1.2-netsec/pbx/Makefile
+++ /dev/null
@@ -1,80 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Makefile for PBX modules
-#
-# Copyright (C) 1999-2005, Mark Spencer
-#
-# Mark Spencer <markster@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-PBX_LIBS=pbx_config.so pbx_spool.so pbx_dundi.so pbx_loopback.so pbx_realtime.so \
- pbx_ael.so
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-# Add GTK console if appropriate
-#PBX_LIBS+=$(shell $(CROSS_COMPILE_BIN)gtk-config --cflags >/dev/null 2>/dev/null && echo "pbx_gtkconsole.so")
-# Add KDE Console if appropriate
-#PBX_LIBS+=$(shell [ "$$QTDIR" != "" ] && echo "pbx_kdeconsole.so")
-
-GTK_FLAGS=`${CROSS_COMPILE_BIN}gtk-config --cflags gthread`
-GTK_LIBS=`${CROSS_COMPILE_BIN}gtk-config --libs gthread`
-MOC=$(QTDIR)/bin/moc
-KDE_FLAGS=-I$(KDEDIR)/include -I$(KDEDIR)/include/kde -I$(QTDIR)/include
-KDE_LIBS=-L$(KDEDIR)/lib -L$(QTDIR)/lib -lqt -lkdecore -lkdeui
-
-ifeq (${OSARCH},CYGWIN)
-CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
-CYGSOLIB=-L.. -L. -L../res -lasterisk.dll
-else
-CFLAGS+=-fPIC
-endif
-
-KDE_CONSOLE_OBJS=pbx_kdeconsole_main.o pbx_kdeconsole.o
-
-all: depend $(PBX_LIBS)
-
-clean:
- rm -f *.so *.o .depend
-
-pbx_gtkconsole.o: pbx_gtkconsole.c
- $(CC) $(CFLAGS) $(GTK_FLAGS) -c -o $@ $<
-
-pbx_gtkconsole.so: pbx_gtkconsole.o
- $(CC) $(SOLINK) -o $@ $< $(GTK_LIBS)
-
-pbx_kdeconsole.o: pbx_kdeconsole.cc pbx_kdeconsole.moc
- $(CXX) $(CFLAGS) $(KDE_FLAGS) -c -o $@ $<
-
-pbx_kdeconsole_main.o: pbx_kdeconsole_main.cc pbx_kdeconsole.h
- $(CXX) $(CFLAGS) $(KDE_FLAGS) -c -o $@ $<
-
-pbx_kdeconsole.so: $(KDE_CONSOLE_OBJS)
- $(CC) $(SOLINK) -o $@ $(KDE_CONSOLE_OBJS) $(KDE_LIBS)
-
-pbx_dundi.so: dundi-parser.o pbx_dundi.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} pbx_dundi.o dundi-parser.o -lz ${CYGSOLIB}
-
-%.moc : %.h
- $(MOC) $< -o $@
-
-%.so : %.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-install: all
- for x in $(PBX_LIBS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
diff --git a/1.2-netsec/pbx/dundi-parser.c b/1.2-netsec/pbx/dundi-parser.c
deleted file mode 100644
index 9b9d9d205..000000000
--- a/1.2-netsec/pbx/dundi-parser.c
+++ /dev/null
@@ -1,832 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Distributed Universal Number Discovery (DUNDi)
- *
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/frame.h"
-#include "asterisk/utils.h"
-#include "asterisk/dundi.h"
-#include "dundi-parser.h"
-#include "asterisk/dundi.h"
-
-static void internaloutput(const char *str)
-{
- fputs(str, stdout);
-}
-
-static void internalerror(const char *str)
-{
- fprintf(stderr, "WARNING: %s", str);
-}
-
-static void (*outputf)(const char *str) = internaloutput;
-static void (*errorf)(const char *str) = internalerror;
-
-char *dundi_eid_to_str(char *s, int maxlen, dundi_eid *eid)
-{
- int x;
- char *os = s;
- if (maxlen < 18) {
- if (s && (maxlen > 0))
- *s = '\0';
- } else {
- for (x=0;x<5;x++) {
- sprintf(s, "%02x:", eid->eid[x]);
- s += 3;
- }
- sprintf(s, "%02x", eid->eid[5]);
- }
- return os;
-}
-
-char *dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid)
-{
- int x;
- char *os = s;
- if (maxlen < 13) {
- if (s && (maxlen > 0))
- *s = '\0';
- } else {
- for (x=0;x<6;x++) {
- sprintf(s, "%02X", eid->eid[x]);
- s += 2;
- }
- }
- return os;
-}
-
-int dundi_str_to_eid(dundi_eid *eid, char *s)
-{
- unsigned int eid_int[6];
- int x;
- if (sscanf(s, "%x:%x:%x:%x:%x:%x", &eid_int[0], &eid_int[1], &eid_int[2],
- &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
- return -1;
- for (x=0;x<6;x++)
- eid->eid[x] = eid_int[x];
- return 0;
-}
-
-int dundi_str_short_to_eid(dundi_eid *eid, char *s)
-{
- unsigned int eid_int[6];
- int x;
- if (sscanf(s, "%2x%2x%2x%2x%2x%2x", &eid_int[0], &eid_int[1], &eid_int[2],
- &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
- return -1;
- for (x=0;x<6;x++)
- eid->eid[x] = eid_int[x];
- return 0;
-}
-
-int dundi_eid_zero(dundi_eid *eid)
-{
- int x;
- for (x=0;x<sizeof(eid->eid) / sizeof(eid->eid[0]);x++)
- if (eid->eid[x]) return 0;
- return 1;
-}
-
-int dundi_eid_cmp(dundi_eid *eid1, dundi_eid *eid2)
-{
- return memcmp(eid1, eid2, sizeof(dundi_eid));
-}
-
-static void dump_string(char *output, int maxlen, void *value, int len)
-{
- maxlen--;
- if (maxlen > len)
- maxlen = len;
- strncpy(output,value, maxlen);
- output[maxlen] = '\0';
-}
-
-static void dump_cbypass(char *output, int maxlen, void *value, int len)
-{
- maxlen--;
- strncpy(output, "Bypass Caches", maxlen);
- output[maxlen] = '\0';
-}
-
-static void dump_eid(char *output, int maxlen, void *value, int len)
-{
- if (len == 6)
- dundi_eid_to_str(output, maxlen, (dundi_eid *)value);
- else
- snprintf(output, maxlen, "Invalid EID len %d", len);
-}
-
-char *dundi_hint2str(char *buf, int bufsiz, int flags)
-{
- strcpy(buf, "");
- buf[bufsiz-1] = '\0';
- if (flags & DUNDI_HINT_TTL_EXPIRED) {
- strncat(buf, "TTLEXPIRED|", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_HINT_DONT_ASK) {
- strncat(buf, "DONTASK|", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_HINT_UNAFFECTED) {
- strncat(buf, "UNAFFECTED|", bufsiz - strlen(buf) - 1);
- }
- /* Get rid of trailing | */
- if (ast_strlen_zero(buf))
- strcpy(buf, "NONE|");
- buf[strlen(buf)-1] = '\0';
- return buf;
-}
-
-static void dump_hint(char *output, int maxlen, void *value, int len)
-{
- unsigned short flags;
- char tmp[512];
- char tmp2[256];
- if (len < 2) {
- strncpy(output, "<invalid contents>", maxlen);
- return;
- }
- memcpy(&flags, value, sizeof(flags));
- flags = ntohs(flags);
- memset(tmp, 0, sizeof(tmp));
- dundi_hint2str(tmp2, sizeof(tmp2), flags);
- snprintf(tmp, sizeof(tmp), "[%s] ", tmp2);
- memcpy(tmp + strlen(tmp), value + 2, len - 2);
- strncpy(output, tmp, maxlen - 1);
-}
-
-static void dump_cause(char *output, int maxlen, void *value, int len)
-{
- static char *causes[] = {
- "SUCCESS",
- "GENERAL",
- "DYNAMIC",
- "NOAUTH" ,
- };
- char tmp[256];
- char tmp2[256];
- int mlen;
- unsigned char cause;
- if (len < 1) {
- strncpy(output, "<invalid contents>", maxlen);
- return;
- }
- cause = *((unsigned char *)value);
- memset(tmp2, 0, sizeof(tmp2));
- mlen = len - 1;
- if (mlen > 255)
- mlen = 255;
- memcpy(tmp2, value + 1, mlen);
- if (cause < sizeof(causes) / sizeof(causes[0])) {
- if (len > 1)
- snprintf(tmp, sizeof(tmp), "%s: %s", causes[cause], tmp2);
- else
- snprintf(tmp, sizeof(tmp), "%s", causes[cause]);
- } else {
- if (len > 1)
- snprintf(tmp, sizeof(tmp), "%d: %s", cause, tmp2);
- else
- snprintf(tmp, sizeof(tmp), "%d", cause);
- }
-
- strncpy(output,tmp, maxlen);
- output[maxlen] = '\0';
-}
-
-static void dump_int(char *output, int maxlen, void *value, int len)
-{
- if (len == (int)sizeof(unsigned int))
- snprintf(output, maxlen, "%lu", (unsigned long)ntohl(*((unsigned int *)value)));
- else
- snprintf(output, maxlen, "Invalid INT");
-}
-
-static void dump_short(char *output, int maxlen, void *value, int len)
-{
- if (len == (int)sizeof(unsigned short))
- snprintf(output, maxlen, "%d", ntohs(*((unsigned short *)value)));
- else
- snprintf(output, maxlen, "Invalid SHORT");
-}
-
-static void dump_byte(char *output, int maxlen, void *value, int len)
-{
- if (len == (int)sizeof(unsigned char))
- snprintf(output, maxlen, "%d", *((unsigned char *)value));
- else
- snprintf(output, maxlen, "Invalid BYTE");
-}
-
-static char *proto2str(int proto, char *buf, int bufsiz)
-{
- switch(proto) {
- case DUNDI_PROTO_NONE:
- strncpy(buf, "None", bufsiz - 1);
- break;
- case DUNDI_PROTO_IAX:
- strncpy(buf, "IAX", bufsiz - 1);
- break;
- case DUNDI_PROTO_SIP:
- strncpy(buf, "SIP", bufsiz - 1);
- break;
- case DUNDI_PROTO_H323:
- strncpy(buf, "H.323", bufsiz - 1);
- break;
- default:
- snprintf(buf, bufsiz, "Unknown Proto(%d)", proto);
- }
- buf[bufsiz-1] = '\0';
- return buf;
-}
-
-char *dundi_flags2str(char *buf, int bufsiz, int flags)
-{
- strcpy(buf, "");
- buf[bufsiz-1] = '\0';
- if (flags & DUNDI_FLAG_EXISTS) {
- strncat(buf, "EXISTS|", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_FLAG_MATCHMORE) {
- strncat(buf, "MATCHMORE|", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_FLAG_CANMATCH) {
- strncat(buf, "CANMATCH|", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_FLAG_IGNOREPAT) {
- strncat(buf, "IGNOREPAT|", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_FLAG_RESIDENTIAL) {
- strncat(buf, "RESIDENCE|", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_FLAG_COMMERCIAL) {
- strncat(buf, "COMMERCIAL|", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_FLAG_MOBILE) {
- strncat(buf, "MOBILE", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_FLAG_NOUNSOLICITED) {
- strncat(buf, "NOUNSLCTD|", bufsiz - strlen(buf) - 1);
- }
- if (flags & DUNDI_FLAG_NOCOMUNSOLICIT) {
- strncat(buf, "NOCOMUNSLTD|", bufsiz - strlen(buf) - 1);
- }
- /* Get rid of trailing | */
- if (ast_strlen_zero(buf))
- strcpy(buf, "NONE|");
- buf[strlen(buf)-1] = '\0';
- return buf;
-}
-
-static void dump_answer(char *output, int maxlen, void *value, int len)
-{
- struct dundi_answer *answer;
- char proto[40];
- char flags[40];
- char eid_str[40];
- char tmp[512]="";
- if (len >= 10) {
- answer = (struct dundi_answer *)(value);
- memcpy(tmp, answer->data, (len >= 500) ? 500 : len - 10);
- dundi_eid_to_str(eid_str, sizeof(eid_str), &answer->eid);
- snprintf(output, maxlen, "[%s] %d <%s/%s> from [%s]",
- dundi_flags2str(flags, sizeof(flags), ntohs(answer->flags)),
- ntohs(answer->weight),
- proto2str(answer->protocol, proto, sizeof(proto)),
- tmp, eid_str);
- } else
- strncpy(output, "Invalid Answer", maxlen - 1);
-}
-
-static void dump_encrypted(char *output, int maxlen, void *value, int len)
-{
- char iv[33];
- int x;
- if ((len > 16) && !(len % 16)) {
- /* Build up IV */
- for (x=0;x<16;x++) {
- snprintf(iv + (x << 1), 3, "%02x", ((unsigned char *)value)[x]);
- }
- snprintf(output, maxlen, "[IV %s] %d encrypted blocks\n", iv, len / 16);
- } else
- snprintf(output, maxlen, "Invalid Encrypted Datalen %d", len);
-}
-
-static void dump_raw(char *output, int maxlen, void *value, int len)
-{
- int x;
- unsigned char *u = value;
- output[maxlen - 1] = '\0';
- strcpy(output, "[ ");
- for (x=0;x<len;x++) {
- snprintf(output + strlen(output), maxlen - strlen(output) - 1, "%02x ", u[x]);
- }
- strncat(output + strlen(output), "]", maxlen - strlen(output) - 1);
-}
-
-static struct dundi_ie {
- int ie;
- char *name;
- void (*dump)(char *output, int maxlen, void *value, int len);
-} ies[] = {
- { DUNDI_IE_EID, "ENTITY IDENT", dump_eid },
- { DUNDI_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string },
- { DUNDI_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string },
- { DUNDI_IE_EID_DIRECT, "DIRECT EID", dump_eid },
- { DUNDI_IE_ANSWER, "ANSWER", dump_answer },
- { DUNDI_IE_TTL, "TTL", dump_short },
- { DUNDI_IE_VERSION, "VERSION", dump_short },
- { DUNDI_IE_EXPIRATION, "EXPIRATION", dump_short },
- { DUNDI_IE_UNKNOWN, "UKWN DUNDI CMD", dump_byte },
- { DUNDI_IE_CAUSE, "CAUSE", dump_cause },
- { DUNDI_IE_REQEID, "REQUEST EID", dump_eid },
- { DUNDI_IE_ENCDATA, "ENCDATA", dump_encrypted },
- { DUNDI_IE_SHAREDKEY, "SHAREDKEY", dump_raw },
- { DUNDI_IE_SIGNATURE, "SIGNATURE", dump_raw },
- { DUNDI_IE_KEYCRC32, "KEYCRC32", dump_int },
- { DUNDI_IE_HINT, "HINT", dump_hint },
- { DUNDI_IE_DEPARTMENT, "DEPARTMENT", dump_string },
- { DUNDI_IE_ORGANIZATION, "ORGANIZTN", dump_string },
- { DUNDI_IE_LOCALITY, "LOCALITY", dump_string },
- { DUNDI_IE_STATE_PROV, "STATEPROV", dump_string },
- { DUNDI_IE_COUNTRY, "COUNTRY", dump_string },
- { DUNDI_IE_EMAIL, "EMAIL", dump_string },
- { DUNDI_IE_PHONE, "PHONE", dump_string },
- { DUNDI_IE_IPADDR, "ADDRESS", dump_string },
- { DUNDI_IE_CACHEBYPASS, "CBYPASS", dump_cbypass },
-};
-
-const char *dundi_ie2str(int ie)
-{
- int x;
- for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
- if (ies[x].ie == ie)
- return ies[x].name;
- }
- return "Unknown IE";
-}
-
-static void dump_ies(unsigned char *iedata, int spaces, int len)
-{
- int ielen;
- int ie;
- int x;
- int found;
- char interp[1024];
- char tmp[1024];
- if (len < 2)
- return;
- while(len >= 2) {
- ie = iedata[0];
- ielen = iedata[1];
- /* Encrypted data is the remainder */
- if (ie == DUNDI_IE_ENCDATA)
- ielen = len - 2;
- if (ielen + 2> len) {
- snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
- outputf(tmp);
- return;
- }
- found = 0;
- for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
- if (ies[x].ie == ie) {
- if (ies[x].dump) {
- ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
- snprintf(tmp, (int)sizeof(tmp), " %s%-15.15s : %s\n", (spaces ? " " : "" ), ies[x].name, interp);
- outputf(tmp);
- } else {
- if (ielen)
- snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
- else
- strcpy(interp, "Present");
- snprintf(tmp, (int)sizeof(tmp), " %s%-15.15s : %s\n", (spaces ? " " : "" ), ies[x].name, interp);
- outputf(tmp);
- }
- found++;
- }
- }
- if (!found) {
- snprintf(tmp, (int)sizeof(tmp), " %sUnknown IE %03d : Present\n", (spaces ? " " : "" ), ie);
- outputf(tmp);
- }
- iedata += (2 + ielen);
- len -= (2 + ielen);
- }
- outputf("\n");
-}
-
-void dundi_showframe(struct dundi_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen)
-{
- char *pref[] = {
- "Tx",
- "Rx",
- " ETx",
- " Erx" };
- char *commands[] = {
- "ACK ",
- "DPDISCOVER ",
- "DPRESPONSE ",
- "EIDQUERY ",
- "EIDRESPONSE ",
- "PRECACHERQ ",
- "PRECACHERP ",
- "INVALID ",
- "UNKNOWN CMD ",
- "NULL ",
- "REQREQ ",
- "REGRESPONSE ",
- "CANCEL ",
- "ENCRYPT ",
- "ENCREJ " };
- char class2[20];
- char *class;
- char subclass2[20];
- char *subclass;
- char tmp[256];
- char retries[20];
- char iabuf[INET_ADDRSTRLEN];
- if (ntohs(fhi->dtrans) & DUNDI_FLAG_RETRANS)
- strcpy(retries, "Yes");
- else
- strcpy(retries, "No");
- if ((ntohs(fhi->strans) & DUNDI_FLAG_RESERVED)) {
- /* Ignore frames with high bit set to 1 */
- return;
- }
- if ((fhi->cmdresp & 0x3f) > (int)sizeof(commands)/(int)sizeof(char *)) {
- snprintf(class2, (int)sizeof(class2), "(%d?)", fhi->cmdresp);
- class = class2;
- } else {
- class = commands[(int)(fhi->cmdresp & 0x3f)];
- }
- snprintf(subclass2, (int)sizeof(subclass2), "%02x", fhi->cmdflags);
- subclass = subclass2;
- snprintf(tmp, (int)sizeof(tmp),
- "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s (%s)\n",
- pref[rx],
- retries, fhi->oseqno, fhi->iseqno, class, fhi->cmdresp & 0x40 ? "Response" : "Command");
- outputf(tmp);
- snprintf(tmp, (int)sizeof(tmp),
- "%s Flags: %s STrans: %5.5d DTrans: %5.5d [%s:%d]%s\n", (rx > 1) ? " " : "",
- subclass, ntohs(fhi->strans) & ~DUNDI_FLAG_RESERVED, ntohs(fhi->dtrans) & ~DUNDI_FLAG_RETRANS,
- ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port),
- fhi->cmdresp & 0x80 ? " (Final)" : "");
- outputf(tmp);
- dump_ies(fhi->ies, rx > 1, datalen);
-}
-
-int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
-{
- char tmp[256];
- if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
- snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
- errorf(tmp);
- return -1;
- }
- ied->buf[ied->pos++] = ie;
- ied->buf[ied->pos++] = datalen;
- memcpy(ied->buf + ied->pos, data, datalen);
- ied->pos += datalen;
- return 0;
-}
-
-int dundi_ie_append_cause(struct dundi_ie_data *ied, unsigned char ie, unsigned char cause, char *data)
-{
- char tmp[256];
- int datalen = data ? strlen(data) + 1 : 1;
- if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
- snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
- errorf(tmp);
- return -1;
- }
- ied->buf[ied->pos++] = ie;
- ied->buf[ied->pos++] = datalen;
- ied->buf[ied->pos++] = cause;
- memcpy(ied->buf + ied->pos, data, datalen-1);
- ied->pos += datalen-1;
- return 0;
-}
-
-int dundi_ie_append_hint(struct dundi_ie_data *ied, unsigned char ie, unsigned short flags, char *data)
-{
- char tmp[256];
- int datalen = data ? strlen(data) + 2 : 2;
- if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
- snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
- errorf(tmp);
- return -1;
- }
- ied->buf[ied->pos++] = ie;
- ied->buf[ied->pos++] = datalen;
- flags = htons(flags);
- memcpy(ied->buf + ied->pos, &flags, sizeof(flags));
- ied->pos += 2;
- memcpy(ied->buf + ied->pos, data, datalen-1);
- ied->pos += datalen-2;
- return 0;
-}
-
-int dundi_ie_append_encdata(struct dundi_ie_data *ied, unsigned char ie, unsigned char *iv, void *data, int datalen)
-{
- char tmp[256];
- datalen += 16;
- if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
- snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
- errorf(tmp);
- return -1;
- }
- ied->buf[ied->pos++] = ie;
- ied->buf[ied->pos++] = datalen;
- memcpy(ied->buf + ied->pos, iv, 16);
- ied->pos += 16;
- if (data) {
- memcpy(ied->buf + ied->pos, data, datalen-16);
- ied->pos += datalen-16;
- }
- return 0;
-}
-
-int dundi_ie_append_answer(struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid, unsigned char protocol, unsigned short flags, unsigned short weight, char *data)
-{
- char tmp[256];
- int datalen = data ? strlen(data) + 11 : 11;
- int x;
- unsigned short myw;
- if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
- snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
- errorf(tmp);
- return -1;
- }
- ied->buf[ied->pos++] = ie;
- ied->buf[ied->pos++] = datalen;
- for (x=0;x<6;x++)
- ied->buf[ied->pos++] = eid->eid[x];
- ied->buf[ied->pos++] = protocol;
- myw = htons(flags);
- memcpy(ied->buf + ied->pos, &myw, 2);
- ied->pos += 2;
- myw = htons(weight);
- memcpy(ied->buf + ied->pos, &myw, 2);
- ied->pos += 2;
- memcpy(ied->buf + ied->pos, data, datalen-11);
- ied->pos += datalen-11;
- return 0;
-}
-
-int dundi_ie_append_addr(struct dundi_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
-{
- return dundi_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
-}
-
-int dundi_ie_append_int(struct dundi_ie_data *ied, unsigned char ie, unsigned int value)
-{
- unsigned int newval;
- newval = htonl(value);
- return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
-}
-
-int dundi_ie_append_short(struct dundi_ie_data *ied, unsigned char ie, unsigned short value)
-{
- unsigned short newval;
- newval = htons(value);
- return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
-}
-
-int dundi_ie_append_str(struct dundi_ie_data *ied, unsigned char ie, char *str)
-{
- return dundi_ie_append_raw(ied, ie, str, strlen(str));
-}
-
-int dundi_ie_append_eid(struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid)
-{
- return dundi_ie_append_raw(ied, ie, (unsigned char *)eid, sizeof(dundi_eid));
-}
-
-int dundi_ie_append_byte(struct dundi_ie_data *ied, unsigned char ie, unsigned char dat)
-{
- return dundi_ie_append_raw(ied, ie, &dat, 1);
-}
-
-int dundi_ie_append(struct dundi_ie_data *ied, unsigned char ie)
-{
- return dundi_ie_append_raw(ied, ie, NULL, 0);
-}
-
-void dundi_set_output(void (*func)(const char *))
-{
- outputf = func;
-}
-
-void dundi_set_error(void (*func)(const char *))
-{
- errorf = func;
-}
-
-int dundi_parse_ies(struct dundi_ies *ies, unsigned char *data, int datalen)
-{
- /* Parse data into information elements */
- int len;
- int ie;
- char tmp[256];
- memset(ies, 0, (int)sizeof(struct dundi_ies));
- ies->ttl = -1;
- ies->expiration = -1;
- ies->unknowncmd = -1;
- ies->cause = -1;
- while(datalen >= 2) {
- ie = data[0];
- len = data[1];
- if (len > datalen - 2) {
- errorf("Information element length exceeds message size\n");
- return -1;
- }
- switch(ie) {
- case DUNDI_IE_EID:
- case DUNDI_IE_EID_DIRECT:
- if (len != (int)sizeof(dundi_eid)) {
- errorf("Improper entity identifer, expecting 6 bytes!\n");
- } else if (ies->eidcount < DUNDI_MAX_STACK) {
- ies->eids[ies->eidcount] = (dundi_eid *)(data + 2);
- ies->eid_direct[ies->eidcount] = (ie == DUNDI_IE_EID_DIRECT);
- ies->eidcount++;
- } else
- errorf("Too many entities in stack!\n");
- break;
- case DUNDI_IE_REQEID:
- if (len != (int)sizeof(dundi_eid)) {
- errorf("Improper requested entity identifer, expecting 6 bytes!\n");
- } else
- ies->reqeid = (dundi_eid *)(data + 2);
- break;
- case DUNDI_IE_CALLED_CONTEXT:
- ies->called_context = (char *)data + 2;
- break;
- case DUNDI_IE_CALLED_NUMBER:
- ies->called_number = (char *)data + 2;
- break;
- case DUNDI_IE_ANSWER:
- if (len < sizeof(struct dundi_answer)) {
- snprintf(tmp, (int)sizeof(tmp), "Answer expected to be >=%d bytes long but was %d\n", (int)sizeof(struct dundi_answer), len);
- errorf(tmp);
- } else {
- if (ies->anscount < DUNDI_MAX_ANSWERS)
- ies->answers[ies->anscount++]= (struct dundi_answer *)(data + 2);
- else
- errorf("Ignoring extra answers!\n");
- }
- break;
- case DUNDI_IE_TTL:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting ttl to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->ttl = ntohs(*((unsigned short *)(data + 2)));
- break;
- case DUNDI_IE_VERSION:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->version = ntohs(*((unsigned short *)(data + 2)));
- break;
- case DUNDI_IE_EXPIRATION:
- if (len != (int)sizeof(unsigned short)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting expiration to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
- errorf(tmp);
- } else
- ies->expiration = ntohs(*((unsigned short *)(data + 2)));
- break;
- case DUNDI_IE_KEYCRC32:
- if (len != (int)sizeof(unsigned int)) {
- snprintf(tmp, (int)sizeof(tmp), "Expecting expiration to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
- errorf(tmp);
- } else
- ies->keycrc32 = ntohl(*((unsigned int *)(data + 2)));
- break;
- case DUNDI_IE_UNKNOWN:
- if (len == 1)
- ies->unknowncmd = data[2];
- else {
- snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
- errorf(tmp);
- }
- break;
- case DUNDI_IE_CAUSE:
- if (len >= 1) {
- ies->cause = data[2];
- ies->causestr = (char *)data + 3;
- } else {
- snprintf(tmp, (int)sizeof(tmp), "Expected at least one byte cause, but was %d long\n", len);
- errorf(tmp);
- }
- break;
- case DUNDI_IE_HINT:
- if (len >= 2) {
- ies->hint = (struct dundi_hint *)(data + 2);
- } else {
- snprintf(tmp, (int)sizeof(tmp), "Expected at least two byte hint, but was %d long\n", len);
- errorf(tmp);
- }
- break;
- case DUNDI_IE_DEPARTMENT:
- ies->q_dept = (char *)data + 2;
- break;
- case DUNDI_IE_ORGANIZATION:
- ies->q_org = (char *)data + 2;
- break;
- case DUNDI_IE_LOCALITY:
- ies->q_locality = (char *)data + 2;
- break;
- case DUNDI_IE_STATE_PROV:
- ies->q_stateprov = (char *)data + 2;
- break;
- case DUNDI_IE_COUNTRY:
- ies->q_country = (char *)data + 2;
- break;
- case DUNDI_IE_EMAIL:
- ies->q_email = (char *)data + 2;
- break;
- case DUNDI_IE_PHONE:
- ies->q_phone = (char *)data + 2;
- break;
- case DUNDI_IE_IPADDR:
- ies->q_ipaddr = (char *)data + 2;
- break;
- case DUNDI_IE_ENCDATA:
- /* Recalculate len as the remainder of the message, regardless of
- theoretical length */
- len = datalen - 2;
- if ((len > 16) && !(len % 16)) {
- ies->encblock = (struct dundi_encblock *)(data + 2);
- ies->enclen = len - 16;
- } else {
- snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted data length %d\n", len);
- errorf(tmp);
- }
- break;
- case DUNDI_IE_SHAREDKEY:
- if (len == 128) {
- ies->encsharedkey = (unsigned char *)(data + 2);
- } else {
- snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted shared key length %d\n", len);
- errorf(tmp);
- }
- break;
- case DUNDI_IE_SIGNATURE:
- if (len == 128) {
- ies->encsig = (unsigned char *)(data + 2);
- } else {
- snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted signature length %d\n", len);
- errorf(tmp);
- }
- break;
- case DUNDI_IE_CACHEBYPASS:
- ies->cbypass = 1;
- break;
- default:
- snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", dundi_ie2str(ie), ie, len);
- outputf(tmp);
- }
- /* Overwrite information element with 0, to null terminate previous portion */
- data[0] = 0;
- datalen -= (len + 2);
- data += (len + 2);
- }
- /* Null-terminate last field */
- *data = '\0';
- if (datalen) {
- errorf("Invalid information element contents, strange boundary\n");
- return -1;
- }
- return 0;
-}
diff --git a/1.2-netsec/pbx/dundi-parser.h b/1.2-netsec/pbx/dundi-parser.h
deleted file mode 100644
index 62bbf4384..000000000
--- a/1.2-netsec/pbx/dundi-parser.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Distributed Universal Number Discovery (DUNDi)
- *
- * Copyright (C) 2004 - 2005, Digium Inc.
- *
- * Written by Mark Spencer <markster@digium.com>
- *
- * This program is Free Software distributed under the terms of
- * of the GNU General Public License.
- */
-
-#ifndef _DUNDI_PARSER_H
-#define _DUNDI_PARSER_H
-
-#include "asterisk/dundi.h"
-#include "asterisk/aes.h"
-
-#define DUNDI_MAX_STACK 512
-#define DUNDI_MAX_ANSWERS 100
-
-struct dundi_ies {
- dundi_eid *eids[DUNDI_MAX_STACK + 1];
- int eid_direct[DUNDI_MAX_STACK + 1];
- dundi_eid *reqeid;
- int eidcount;
- char *called_context;
- char *called_number;
- struct dundi_answer *answers[DUNDI_MAX_ANSWERS + 1];
- struct dundi_hint *hint;
- int anscount;
- int ttl;
- int version;
- int expiration;
- int unknowncmd;
- unsigned char *pubkey;
- int cause;
- char *q_dept;
- char *q_org;
- char *q_locality;
- char *q_stateprov;
- char *q_country;
- char *q_email;
- char *q_phone;
- char *q_ipaddr;
- char *causestr;
- unsigned char *encsharedkey;
- unsigned char *encsig;
- unsigned long keycrc32;
- struct dundi_encblock *encblock;
- int enclen;
- int cbypass;
-};
-
-struct dundi_ie_data {
- int pos;
- unsigned char buf[8192];
-};
-
-/* Choose a different function for output */
-extern void dundi_set_output(void (*output)(const char *data));
-/* Choose a different function for errors */
-extern void dundi_set_error(void (*output)(const char *data));
-extern void dundi_showframe(struct dundi_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen);
-
-extern const char *dundi_ie2str(int ie);
-
-extern int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen);
-extern int dundi_ie_append_addr(struct dundi_ie_data *ied, unsigned char ie, struct sockaddr_in *sin);
-extern int dundi_ie_append_int(struct dundi_ie_data *ied, unsigned char ie, unsigned int value);
-extern int dundi_ie_append_short(struct dundi_ie_data *ied, unsigned char ie, unsigned short value);
-extern int dundi_ie_append_str(struct dundi_ie_data *ied, unsigned char ie, char *str);
-extern int dundi_ie_append_eid(struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid);
-extern int dundi_ie_append_cause(struct dundi_ie_data *ied, unsigned char ie, unsigned char cause, char *desc);
-extern int dundi_ie_append_hint(struct dundi_ie_data *ied, unsigned char ie, unsigned short flags, char *data);
-extern int dundi_ie_append_answer(struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid, unsigned char protocol, unsigned short flags, unsigned short weight, char *desc);
-extern int dundi_ie_append_encdata(struct dundi_ie_data *ied, unsigned char ie, unsigned char *iv, void *data, int datalen);
-extern int dundi_ie_append_byte(struct dundi_ie_data *ied, unsigned char ie, unsigned char dat);
-extern int dundi_ie_append(struct dundi_ie_data *ied, unsigned char ie);
-extern int dundi_parse_ies(struct dundi_ies *ies, unsigned char *data, int datalen);
-extern char *dundi_eid_to_str(char *s, int maxlen, dundi_eid *eid);
-extern char *dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid);
-extern int dundi_str_to_eid(dundi_eid *eid, char *s);
-extern int dundi_str_short_to_eid(dundi_eid *eid, char *s);
-extern int dundi_eid_zero(dundi_eid *eid);
-extern int dundi_eid_cmp(dundi_eid *eid1, dundi_eid *eid2);
-extern char *dundi_flags2str(char *s, int maxlen, int flags);
-extern char *dundi_hint2str(char *s, int maxlen, int flags);
-#endif
diff --git a/1.2-netsec/pbx/pbx_ael.c b/1.2-netsec/pbx/pbx_ael.c
deleted file mode 100644
index 4b758a61b..000000000
--- a/1.2-netsec/pbx/pbx_ael.c
+++ /dev/null
@@ -1,1284 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Compile symbolic Asterisk Extension Logic into Asterisk extensions
- *
- */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/pbx.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/cli.h"
-#include "asterisk/callerid.h"
-
-struct stringlink {
- struct stringlink *next;
- char data[0];
-};
-
-#define FILLIN_BREAK 1
-#define FILLIN_CONTINUE 2
-
-struct fillin {
- struct fillin *next;
- char exten[AST_MAX_EXTENSION];
- int priority;
- int type;
-};
-
-#ifdef __AST_DEBUG_MALLOC
-static void FREE(void *ptr)
-{
- free(ptr);
-}
-#else
-#define FREE free
-#endif
-
-#define DEBUG_READ (1 << 0)
-#define DEBUG_TOKENS (1 << 1)
-#define DEBUG_MACROS (1 << 2)
-#define DEBUG_CONTEXTS (1 << 3)
-
-static int aeldebug = 0;
-
-static char *dtext = "Asterisk Extension Language Compiler";
-static char *config = "extensions.ael";
-static char *registrar = "pbx_ael";
-
-static char *__grab_token(char *src, const char *filename, int lineno, int link)
-{
- char *c;
- char *b;
- char *a;
- int level = 0;
- char *ret;
-#if 0
- if (aeldebug || DEBUG_TOKENS)
- ast_verbose("Searching for token in '%s'!\n", src);
-#endif
- c = src;
- while(*c) {
- if ((*c == '\\')) {
- c++;
- if (!*c)
- c--;
- } else {
- if ((*c == '{') || (*c == '(')) {
- level++;
- } else if ((*c == '}') || (*c == ')')) {
- if (level)
- level--;
- else
- ast_log(LOG_WARNING, "Syntax error at line %d of '%s', too many closing braces!\n", lineno, filename);
- } else if ((*c == ';') && !level) {
- /* Got a token! */
- *c = '\0';
- b = c;
- b--;
- c++;
- while((b > src) && (*b < 33)) {
- *b = '\0';
- b--;
- }
- a = ast_skip_blanks(src);
- if (link) {
- ret = malloc(strlen(a) + sizeof(struct stringlink) + 1);
- if (ret)
- strcpy(ret + sizeof(struct stringlink), a);
- } else
- ret = strdup(a);
- /* Save remainder */
- memmove(src, c, strlen(c) + 1);
- return ret;
- }
- }
- c++;
- }
- return NULL;
-}
-
-static char *grab_token(char *src, const char *filename, int lineno)
-{
- return __grab_token(src, filename, lineno, 0);
-}
-
-static struct stringlink *arg_parse(char *args, const char *filename, int lineno)
-{
- struct stringlink *cur, *prev=NULL, *root=NULL;
- if (args) {
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("Parsing args '%s'!\n", args);
- if (args[0] == '{') {
- /* Strip mandatory '}' from end */
- args[strlen(args) - 1] = '\0';
- while ((cur = (struct stringlink *)__grab_token(args + 1, filename, lineno, 1))) {
- cur->next = NULL;
- if (prev)
- prev->next = cur;
- else
- root = cur;
- prev = cur;
- }
- } else if (*args) {
- root = malloc(sizeof(struct stringlink) + strlen(args) + 1);
- if (root) {
- strcpy(root->data, args);
- root->next = NULL;
- }
- }
- }
- return root;
-}
-
-static char *grab_else(char *args, const char *filename, int lineno)
-{
- char *ret = NULL;
- int level=0;
- char *c;
- if (args) {
- if (args[0] == '{') {
- c = args;
- while(*c) {
- if (*c == '{')
- level++;
- else if (*c == '}') {
- level--;
- if (!level) {
- c++;
- while(*c && (*c < 33)) { *c = '\0'; c++; };
- if (!strncasecmp(c, "else", 4) &&
- ((c[4] == '{') || (c[4] < 33))) {
- /* Ladies and gentlemen, we have an else clause */
- *c = '\0';
- c += 4;
- c = ast_skip_blanks(c);
- ret = c;
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("Returning else clause '%s'\n", c);
- }
- break;
- }
- }
- c++;
- }
- }
- }
- return ret;
-}
-
-static struct stringlink *param_parse(char *parms, const char *macro, const char *filename, int lineno)
-{
- char *s, *e;
- struct stringlink *root = NULL, *prev=NULL, *cur;
- if (!parms || !*parms)
- return NULL;
- if (*parms != '(') {
- ast_log(LOG_NOTICE, "Syntax error in parameter list for macro '%s' at about line %d of %s: Expecting '(' but got '%c'\n", macro, lineno, filename, *parms);
- return NULL;
- }
- s = parms + 1;
- while(*s) {
- s = ast_skip_blanks(s);
- e = s;
- while(*e && (*e != ')') && (*e != ',')) {
- if (*e < 33)
- *e = '\0';
- e++;
- }
- if (*e) {
- /* Strip token */
- *e = '\0';
- e++;
- /* Skip over whitespace */
- e = ast_skip_blanks(e);
- /* Link */
- cur = malloc(strlen(s) + sizeof(struct stringlink) + 1);
- if (cur) {
- cur->next = NULL;
- strcpy(cur->data, s);
- if (prev)
- prev->next = cur;
- else
- root = cur;
- prev = cur;
- }
- s = e;
- }
- }
- return root;
-}
-
-static void arg_free(struct stringlink *cur)
-{
- struct stringlink *last;
- while(cur) {
- last = cur;
- cur = cur->next;
- free(last);
- }
-}
-
-static void handle_globals(struct stringlink *vars)
-{
- while(vars) {
- pbx_builtin_setvar(NULL, vars->data);
- vars = vars->next;
- }
-}
-
-static struct stringlink *split_token(char *token, const char *filename, int lineno)
-{
- char *args, *p;
- struct stringlink *argv;
- args = token;
- while (*args && (*args > 32) && (*args != '{') && (*args != '(')) args++;
- if (*args) {
- p = args;
- args = ast_skip_blanks(args);
- if (*args != '(') {
- *p = '\0';
- } else {
- while (*args && (*args != ')')) args++;
- if (*args == ')') {
- args++;
- args = ast_skip_blanks(args);
- }
- }
- if (!*args)
- args = NULL;
- } else args = NULL;
- argv = arg_parse(args, filename, lineno);
- if (args)
- *args = '\0';
- return argv;
-}
-
-static int matches_keyword(const char *data, const char *keyword)
-{
- char c;
- if (!strncasecmp(data, keyword, strlen(keyword))) {
- c = data[strlen(keyword)];
- if ((c < 33) || (c == '(') || (c == '{'))
- return 1;
- }
- return 0;
-}
-
-static struct stringlink *split_params(char *token, const char *filename, int lineno)
-{
- char *params;
- struct stringlink *paramv;
- params = token;
- while(*params && (*params > 32) && (*params != '(')) params++;
- if (*params) {
- if (*params != '(') {
- *params = '\0';
- params++;
- params = ast_skip_blanks(params);
- }
- if (!*params)
- params = NULL;
- } else params = NULL;
- paramv = param_parse(params, token, filename, lineno);
- if (params)
- *params = '\0';
- return paramv;
-}
-
-static const char *get_case(char *s, char **restout, int *pattern)
-{
- char *newcase=NULL;
- char *rest=NULL;
- if (!strncasecmp(s, "case", 4) && s[4] && ((s[4] < 33) || (s[4] == ':'))) {
- newcase = s + 4;
- newcase = ast_skip_blanks(newcase);
- rest = newcase;
- *pattern = 0;
- } else if (!strncasecmp(s, "pattern", 7) && s[7] && ((s[7] < 33) || (s[7] == ':'))) {
- newcase = s + 8;
- newcase = ast_skip_blanks(newcase);
- rest = newcase;
- *pattern = 1;
- } else if (!strncasecmp(s, "default", 7) && ((s[7] < 33) || (s[7] == ':'))) {
- newcase = ".";
- rest = s + 7;
- rest = ast_skip_blanks(rest);
- *pattern = 1;
- }
-
- if (rest) {
- while (*rest && (*rest > 32) && (*rest != ':')) rest++;
- if (*rest) {
- *rest = 0;
- rest++;
- while (*rest && ((*rest == ':') || (*rest < 33))) rest++;
- *restout = rest;
- } else {
- *restout = "";
- }
- } else
- *restout = s;
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("GETCASE: newcase is '%s', rest = '%s'\n", newcase, *restout);
- return newcase;
-}
-
-static void fillin_free(struct fillin *fillin)
-{
- struct fillin *cur, *next;
- cur = fillin;
- while(cur) {
- next = cur->next;
- free(cur);
- cur = next;
- }
-}
-
-static void fillin_process(struct ast_context *con, struct fillin *fillin, const char *filename, int lineno, const char *breakexten, int breakprio, const char *contexten, int contprio)
-{
- struct fillin *cur;
- char *app;
- char mdata[AST_MAX_EXTENSION + 20];
- cur = fillin;
- while(cur) {
- if (cur->type == FILLIN_BREAK) {
- if (breakexten && breakprio) {
- app = "Goto";
- snprintf(mdata, sizeof(mdata), "%s|%d", breakexten, breakprio);
- } else {
- app = "NoOp";
- snprintf(mdata, sizeof(mdata), "Invalid break");
- ast_log(LOG_NOTICE, "Ignoring inappropriate break around line %d of %s\n", lineno, filename);
- }
- if (ast_add_extension2(con, 0, cur->exten, cur->priority, NULL, NULL, app, strdup(mdata), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of break '%s'\n", cur->priority, cur->exten);
- } else if (cur->type == FILLIN_CONTINUE) {
- if (contexten && contprio) {
- app = "Goto";
- snprintf(mdata, sizeof(mdata), "%s|%d", contexten, contprio);
- } else {
- app = "NoOp";
- snprintf(mdata, sizeof(mdata), "Invalid continue");
- ast_log(LOG_NOTICE, "Ignoring inappropriate continue around line %d of %s\n", lineno, filename);
- }
- if (ast_add_extension2(con, 0, cur->exten, cur->priority, NULL, NULL, app, strdup(mdata), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of continue '%s'\n", cur->priority, cur->exten);
- } else {
- ast_log(LOG_WARNING, "Whoa, unknown fillin type '%d'\n", cur->type);
- }
- cur = cur->next;
- }
-}
-
-static int match_assignment(char *variable, char **value)
-{
- char *c;
- char *ws;
- int inpar = 0;
- c = variable;
-
- while (*c) {
- if(*c == ')' && (inpar > 0)) {
- inpar--;
- } else if(*c == '(' && (inpar >= 0)) {
- inpar++;
- } else if(*c == '=' && (inpar == 0)) {
- break;
- }
- c++;
- }
- ws = c;
- c = ast_skip_blanks(c);
- if (*c == '=') {
- *ws = '\0';
- *c = '\0';
- c++;
- c = ast_skip_blanks(c);
- *value = c;
- return 1;
- }
- return 0;
-}
-
-static int matches_label(char *data, char **rest)
-{
- char last = 0;
- char *start = data;
- while (*data > 32) {
- last = *data;
- data++;
- }
- if (last != ':') {
- data = ast_skip_blanks(data);
- last = *data;
- data++;
- }
- if (last == ':') {
- *rest = data;
- /* Go back and trim up the label */
- while(*start && ((*start > 32) && (*start != ':'))) start++;
- *start = '\0';
- return 1;
- }
- return 0;
-}
-
-static char *argument_end(char *str)
-{
- int level=0;
- while(*++str) {
- switch(*str) {
- case '(':
- level++;
- break;
- case ')':
- if(level)
- level--;
- else
- return str;
- break;
- default:
- break;
- }
- }
- return NULL;
-}
-
-static int build_step(const char *what, const char *name, const char *filename, int lineno, struct ast_context *con, char *exten, int *pos, char *data, struct fillin **fillout, char **label);
-static int __build_step(const char *what, const char *name, const char *filename, int lineno, struct ast_context *con, char *exten, int *pos, char *data, struct fillin **fillout, char **label)
-{
- char *app;
- char *args;
- char *c;
- char *margs=NULL;
- char *oargs;
- char *rest;
- const char *curcase, *newcase;
- struct stringlink *swargs, *cur;
- int cpos;
- int mlen;
- int pattern = 0;
- struct fillin *fillin;
-
- data = ast_skip_blanks(data);
- if (matches_label(data, &c)) {
- *label = data;
- data = c;
- data = ast_skip_blanks(data);
- }
- if (ast_strlen_zero(data))
- return 0;
- if (matches_keyword(data, "switch")) {
- fillin = NULL;
- /* Switch */
- args = data + strlen("switch");
- while ((*args < 33) && (*args != '(')) args++;
- if ((*args == '(') && (c = argument_end(args))) {
- args++;
- *c = '\0';
- c++;
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("--SWITCH on : %s\n", args);
- mlen = strlen(exten) + 128 + strlen(args) + strlen(name);
- margs = alloca(mlen);
- app = "Goto";
- sprintf(margs, "sw-%d-%s|1", *pos, args);
- ast_process_quotes_and_slashes(margs, ',', '|');
- oargs = args;
- args = margs;
- if (ast_add_extension2(con, 0, exten, *pos, *label, NULL, app, strdup(args), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- else {
- *label = NULL;
- (*pos)++;
- }
- app = "NoOp";
- sprintf(margs, "Finish switch-%d", *pos - 1);
- if (ast_add_extension2(con, 0, exten, *pos, *label, NULL, app, strdup(args), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- else {
- *label = NULL;
- (*pos)++;
- }
- c = ast_skip_blanks(c);
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("ARG Parsing '%s'\n", c);
- swargs = arg_parse(c, filename, lineno);
- cur = swargs;
- curcase = NULL;
- while(cur) {
- if ((newcase = get_case(cur->data, &rest, &pattern))) {
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("--NEWCASE: '%s'!\n", newcase);
- if (curcase) {
- /* Handle fall through */
- char tmp[strlen(newcase) + strlen(name) + 40];
- sprintf(tmp, "sw-%d-%s|%d", *pos - 2, newcase, 1);
- ast_add_extension2(con, 0, margs, cpos, NULL, NULL, "Goto", strdup(tmp), FREE, registrar);
- }
- curcase = newcase;
- cpos = 1;
- if (pattern)
- snprintf(margs, mlen, "_sw-%d-%s", *pos - 2, curcase);
- else
- snprintf(margs, mlen, "sw-%d-%s", *pos - 2, curcase);
- if (!strcasecmp(rest, "break")) {
- char tmp[strlen(exten) + 10];
- sprintf(tmp, "%s|%d", exten, *pos - 1);
- ast_add_extension2(con, 0, exten, cpos, *label, NULL, "Goto", strdup(tmp), FREE, registrar);
- curcase = NULL;
- *label = NULL;
- } else
- build_step("switch", margs, filename, lineno, con, margs, &cpos, rest, &fillin, label);
- } else if (curcase) {
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("Building statement from '%s'\n", rest);
- if (!strcasecmp(rest, "break")) {
- char tmp[strlen(exten) + 10];
- sprintf(tmp, "%s|%d", exten, *pos - 1);
- ast_add_extension2(con, 0, margs, cpos, *label, NULL, "Goto", strdup(tmp), FREE, registrar);
- curcase = NULL;
- *label = NULL;
- } else
- build_step("switch", margs, filename, lineno, con, margs, &cpos, rest, &fillin, label);
- } else
- ast_log(LOG_WARNING, "Unreachable code in switch at about line %d of %s\n", lineno, filename);
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("--SWARG: %s\n", cur->data);
- cur = cur->next;
- }
- /* Can't do anything with these */
- fillin_process(con, fillin, filename, lineno, NULL, 0, NULL, 0);
- fillin_free(fillin);
- arg_free(swargs);
- } else
- ast_log(LOG_WARNING, "Syntax error in switch declaration in %s around line %d!\n", filename, lineno);
-
- } else if (matches_keyword(data, "if")) {
- /* If... */
- args = data + strlen("if");
- while ((*args < 33) && (*args != '(')) args++;
- if ((*args == '(') && (c = argument_end(args))) {
- int ifblock;
- int ifstart;
- int elsestart;
- int ifend;
- int ifskip;
- char *elses;
- char *iflabel;
- args++;
- *c = '\0';
- c++;
- c = ast_skip_blanks(c);
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("--IF on : '%s' : '%s'\n", args, c);
- mlen = strlen(exten) + 128 + strlen(args) + strlen(name);
- margs = alloca(mlen);
- /* Remember where the ifblock starts, and skip over */
- ifblock = (*pos)++;
- iflabel = *label;
- *label = NULL;
- /* Remember where the start of the ifblock is */
- ifstart = *pos;
- snprintf(margs, mlen, "if-%s-%d", name, ifblock);
- /* Now process the block of the if */
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("Searching for elses in '%s'\n", c);
- elses = grab_else(c, filename, lineno);
- build_step("if", margs, filename, lineno, con, exten, pos, c, fillout, label);
- if (elses) {
- /* Reserve a goto to exit the if */
- ifskip = *pos;
- (*pos)++;
- elsestart = *pos;
- build_step("else", margs, filename, lineno, con, exten, pos, elses, fillout, label);
- } else {
- elsestart = *pos;
- ifskip = 0;
- }
- ifend = *pos;
- (*pos)++;
- app = "NoOp";
- snprintf(margs, mlen, "Finish if-%s-%d", name, ifblock);
- if (ast_add_extension2(con, 0, exten, ifend, *label, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- *label = NULL;
- app = "GotoIf";
- snprintf(margs, mlen, "$[ %s ]?%d:%d", args, ifstart, elsestart);
- if (ast_add_extension2(con, 0, exten, ifblock, iflabel, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- if (ifskip) {
- /* Skip as appropriate around else clause */
- snprintf(margs, mlen, "%d", ifend);
- if (ast_add_extension2(con, 0, exten, ifskip, NULL, NULL, "Goto", strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- }
- } else
- ast_log(LOG_WARNING, "Syntax error in if declaration in %s around line %d!\n", filename, lineno);
- } else if (matches_keyword(data, "while")) {
- /* While... */
- fillin = NULL;
- args = data + strlen("while");
- while ((*args < 33) && (*args != '(')) args++;
- if ((*args == '(') && (c = argument_end(args))) {
- int whileblock;
- int whilestart;
- int whileend;
- char *whilelabel;
- args++;
- *c = '\0';
- c++;
- c = ast_skip_blanks(c);
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("--WHILE on : '%s' : '%s'\n", args, c);
- mlen = strlen(exten) + 128 + strlen(args) + strlen(name);
- margs = alloca(mlen);
- /* Remember where to put the conditional, and keep its position */
- whilestart = (*pos);
- whilelabel = *label;
- *label = NULL;
- (*pos)++;
- /* Remember where the whileblock starts */
- whileblock = (*pos);
- snprintf(margs, mlen, "while-%s-%d", name, whilestart);
- build_step("while", margs, filename, lineno, con, exten, pos, c, &fillin, label);
- /* Close the loop */
- app = "Goto";
- snprintf(margs, mlen, "%d", whilestart);
- if (ast_add_extension2(con, 0, exten, (*pos)++, *label, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- *label = NULL;
- whileend = (*pos);
- /* Place trailer */
- app = "NoOp";
- snprintf(margs, mlen, "Finish while-%s-%d", name, whilestart);
- if (ast_add_extension2(con, 0, exten, (*pos)++, *label, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- *label = NULL;
- app = "GotoIf";
- snprintf(margs, mlen, "$[ %s ]?%d:%d", args, whileblock, whileend);
- if (ast_add_extension2(con, 0, exten, whilestart, whilelabel, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- fillin_process(con, fillin, filename, lineno, exten, whileend, exten, whilestart);
- fillin_free(fillin);
- } else
- ast_log(LOG_WARNING, "Syntax error in while declaration in %s around line %d!\n", filename, lineno);
- } else if (matches_keyword(data, "jump")) {
- char *p;
- /* Jump... */
- fillin = NULL;
- args = data + strlen("jump");
- args = ast_skip_blanks(args);
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("--JUMP to : '%s'\n", args);
- p = strchr(args, ',');
- if (p) {
- *p = '\0';
- p++;
- } else
- p = "1";
- c = strchr(args, '@');
- if (c) {
- *c = '\0';
- c++;
- }
- mlen = strlen(exten) + 128 + strlen(args) + strlen(name) + (c ? strlen(c) : 0);
- margs = alloca(mlen);
- if (c)
- snprintf(margs, mlen, "%s|%s|%s", c,args, p);
- else
- snprintf(margs, mlen, "%s|%s", args, p);
- app = "Goto";
- if (ast_add_extension2(con, 0, exten, (*pos)++, *label, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- *label = NULL;
- } else if (matches_keyword(data, "goto")) {
- /* Jump... */
- fillin = NULL;
- args = data + strlen("goto");
- args = ast_skip_blanks(args);
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("--GOTO to : '%s'\n", args);
- app = "Goto";
- if (args[0] == '(' && args[strlen(args) - 1] == ')') {
- args[0] = '\0';
- args++;
- args[strlen(args) - 1] = '\0';
- }
- if (ast_add_extension2(con, 0, exten, (*pos)++, *label, NULL, app, strdup(args), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- *label = NULL;
- } else if (matches_keyword(data, "for")) {
- /* While... */
- fillin = NULL;
- args = data + strlen("for");
- while ((*args < 33) && (*args != '(')) args++;
- if ((*args == '(') && (c = argument_end(args))) {
- int forblock;
- int forprep;
- int forstart;
- int forend;
- struct stringlink *fields;
- char *tmp;
- char *forlabel = NULL;
- args++;
- *c = '\0';
- c++;
- c = ast_skip_blanks(c);
- /* Parse arguments first */
- tmp = alloca(strlen(args) + 10);
- if (tmp) {
- snprintf(tmp, strlen(args) + 10, "{%s;}", args);
- fields = arg_parse(tmp, filename, lineno);
- } else
- fields = NULL;
- if (fields && fields->next && fields->next->next) {
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("--FOR ('%s' ; '%s' ; '%s') : '%s'\n", fields->data, fields->next->data, fields->next->next->data, c);
- mlen = strlen(exten) + 128 + strlen(args) + strlen(name);
- margs = alloca(mlen);
- forprep = *pos;
- snprintf(margs, mlen, "for-%s-%d", name, forprep);
- fillin = NULL;
- build_step("while", margs, filename, lineno, con, exten, pos, fields->data, &fillin, label);
- /* Remember where to put the conditional, and keep its position */
- forstart = (*pos);
- forlabel = *label;
- (*pos)++;
- *label = NULL;
- /* Remember where the whileblock starts */
- forblock = (*pos);
- build_step("for", margs, filename, lineno, con, exten, pos, fields->next->next->data, &fillin, label);
- build_step("for", margs, filename, lineno, con, exten, pos, c, &fillin, label);
- /* Close the loop */
- app = "Goto";
- snprintf(margs, mlen, "%d", forstart);
- if (ast_add_extension2(con, 0, exten, (*pos)++, *label, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- *label = NULL;
- forend = (*pos);
- /* Place trailer */
- app = "NoOp";
- snprintf(margs, mlen, "Finish for-%s-%d", name, forprep);
- if (ast_add_extension2(con, 0, exten, (*pos)++, *label, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- *label = NULL;
- app = "GotoIf";
- snprintf(margs, mlen, "$[ %s ]?%d:%d", fields->next->data, forblock, forend);
- if (ast_add_extension2(con, 0, exten, forstart, forlabel, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", forstart, what, name);
- fillin_process(con, fillin, filename, lineno, exten, forend, exten, forstart);
- fillin_free(fillin);
- } else
- ast_log(LOG_NOTICE, "Improper for declaration in %s around line %d!\n", filename, lineno);
- arg_free(fields);
- } else
- ast_log(LOG_WARNING, "Syntax error in for declaration in %s around line %d!\n", filename, lineno);
-
- } else if (!strcasecmp(data, "break") || !strcasecmp(data, "continue")) {
- struct fillin *fi;
- fi = malloc(sizeof(struct fillin));
- if (fi) {
- memset(fi, 0, sizeof(struct fillin));
- if (!strcasecmp(data, "break"))
- fi->type = FILLIN_BREAK;
- else
- fi->type = FILLIN_CONTINUE;
- ast_copy_string(fi->exten, exten, sizeof(fi->exten));
- fi->priority = (*pos)++;
- fi->next = *fillout;
- *fillout = fi;
- }
- } else if (match_assignment(data, &rest)) {
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("ASSIGN '%s' = '%s'\n", data, rest);
- mlen = strlen(rest) + strlen(data) + 20;
- margs = alloca(mlen);
- snprintf(margs, mlen, "%s=$[ %s ]", data, rest);
- app = "Set";
- if (ast_add_extension2(con, 0, exten, *pos, *label, NULL, app, strdup(margs), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add assignment at priority '%d' of %s '%s'\n", *pos, what, name);
- else {
- *label = NULL;
- (*pos)++;
- }
- } else {
- app = data;
- args = app;
- while (*args && (*args > 32) && (*args != '(')) args++;
- if (*args != '(') {
- while(*args && (*args != '(')) { *args = '\0'; args++; };
- }
- if (*args == '(') {
- *args = '\0';
- args++;
- /* Got arguments, trim trailing ')' */
- c = args + strlen(args) - 1;
- while((c >= args) && (*c < 33) && (*c != ')')) { *c = '\0'; c--; };
- if ((c >= args) && (*c == ')')) *c = '\0';
- } else
- args = "";
- ast_process_quotes_and_slashes(args, ',', '|');
- if (app[0] == '&') {
- app++;
- margs = alloca(strlen(args) + strlen(app) + 10);
- sprintf(margs, "%s|%s", app, args);
- args = margs;
- app = "Macro";
- }
- if (aeldebug & DEBUG_TOKENS)
- ast_verbose("-- APP: '%s', ARGS: '%s'\n", app, args);
- if (ast_add_extension2(con, 0, exten, *pos, *label, NULL, app, strdup(args), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of %s '%s'\n", *pos, what, name);
- else {
- (*pos)++;
- *label = NULL;
- }
- }
- return 0;
-}
-
-static int build_step(const char *what, const char *name, const char *filename, int lineno, struct ast_context *con, char *exten, int *pos, char *data, struct fillin **fillout, char **label)
-{
- struct stringlink *args, *cur;
- int res=0;
- struct fillin *fillin=NULL;
- int dropfill = 0;
- char *labelin = NULL;
- if (!fillout) {
- fillout = &fillin;
- dropfill = 1;
- }
- if (!label) {
- label = &labelin;
- };
- args = arg_parse(data, filename, lineno);
- cur = args;
- while(cur) {
- res |= __build_step(what, name, filename, lineno, con, exten, pos, cur->data, fillout, label);
- cur = cur->next;
- }
- arg_free(args);
- if (dropfill) {
- fillin_process(con, fillin, filename, lineno, NULL, 0, NULL, 0);
- fillin_free(fillin);
- }
- return res;
-}
-
-static int parse_catch(char *data, char **catch, char **rest)
-{
- /* Skip the word 'catch' */
- data += 5;
- data = ast_skip_blanks(data);
- /* Here's the extension */
- *catch = data;
- if (!*data)
- return 0;
- while (*data && (*data > 32)) data++;
- if (!*data)
- return 0;
- /* Trim any trailing spaces */
- *data = '\0';
- data++;
- data = ast_skip_blanks(data);
- if (!*data)
- return 0;
- *rest = data;
- return 1;
-}
-
-static void handle_macro(struct ast_context **local_contexts, struct stringlink *vars, const char *filename, int lineno)
-{
- struct stringlink *argv;
- struct stringlink *paramv;
- struct stringlink *cur;
- struct ast_context *con;
- struct fillin *fillin;
- char *catch, *rest;
- char name[256];
- int pos;
- int cpos;
-
- if (aeldebug & DEBUG_MACROS)
- ast_verbose("Root macro def is '%s'\n", vars->data);
- argv = split_token(vars->data, filename, lineno);
- paramv = split_params(vars->data, filename, lineno);
- if (aeldebug & DEBUG_MACROS)
- ast_verbose("Found macro '%s'\n", vars->data);
- snprintf(name, sizeof(name), "macro-%s", vars->data);
- con = ast_context_create(local_contexts, name, registrar);
- if (con) {
- pos = 1;
- cur = paramv;
- while(cur) {
- if (aeldebug & DEBUG_MACROS)
- ast_verbose(" PARAM => '%s'\n", cur->data);
- snprintf(name, sizeof(name), "%s=${ARG%d}", cur->data, pos);
- if (ast_add_extension2(con, 0, "s", pos, NULL, NULL, "Set", strdup(name), FREE, registrar))
- ast_log(LOG_WARNING, "Unable to add step at priority '%d' of macro '%s'\n", pos, vars->data);
- else
- pos++;
- cur = cur->next;
- }
- cur = argv;
- while(cur) {
- if (aeldebug & DEBUG_MACROS)
- ast_verbose(" STEP => '%s'\n", cur->data);
- if (matches_keyword(cur->data, "catch")) {
- if (aeldebug & DEBUG_MACROS)
- ast_verbose("--CATCH: '%s'\n", cur->data);
- if (parse_catch(cur->data, &catch, &rest)) {
- cpos = 1;
- build_step("catch", catch, filename, lineno, con, catch, &cpos, rest, NULL, NULL);
- } else
- ast_log(LOG_NOTICE, "Parse error for catch at about line %d of %s\n", lineno, filename);
- } else {
- fillin = NULL;
- build_step("macro", vars->data, filename, lineno, con, "s", &pos, cur->data, NULL, NULL);
- }
- cur = cur->next;
- }
- } else
- ast_log(LOG_WARNING, "Unable to create context '%s'\n", name);
- arg_free(paramv);
- arg_free(argv);
- if (vars->next)
- ast_log(LOG_NOTICE, "Ignoring excess tokens in macro definition around line %d of %s!\n", lineno, filename);
-}
-
-static int matches_extension(char *exten, char **extout)
-{
- char *c;
- *extout = NULL;
- c = exten;
- while(*c && (*c > 32)) c++;
- if (*c) {
- *c = '\0';
- c++;
- c = ast_skip_blanks(c);
- if (*c) {
- if (*c == '=') {
- *c = '\0';
- c++;
- if (*c == '>')
- c++;
- c = ast_skip_blanks(c);
- *extout = c;
- return 1;
- }
- }
- }
- return 0;
-}
-
-static void parse_keyword(char *s, char **o)
-{
- char *c;
- c = s;
- while((*c) && (*c > 32)) c++;
- if (*c) {
- *c = '\0';
- c++;
- c = ast_skip_blanks(c);
- *o = c;
- } else
- *o = NULL;
-}
-
-static void handle_context(struct ast_context **local_contexts, struct stringlink *vars, const char *filename, int lineno)
-{
- struct stringlink *argv;
- struct stringlink *cur2;
- struct stringlink *argv2;
- struct stringlink *cur;
- struct ast_context *con;
- char *rest;
- char *c;
- char name[256];
- int pos;
-
- if (aeldebug & DEBUG_CONTEXTS)
- ast_verbose("Root context def is '%s'\n", vars->data);
- argv = split_token(vars->data, filename, lineno);
- if (aeldebug & DEBUG_CONTEXTS)
- ast_verbose("Found context '%s'\n", vars->data);
- snprintf(name, sizeof(name), "%s", vars->data);
- con = ast_context_create(local_contexts, name, registrar);
- if (con) {
- cur = argv;
- while(cur) {
- if (matches_keyword(cur->data, "includes")) {
- if (aeldebug & DEBUG_CONTEXTS)
- ast_verbose("--INCLUDES: '%s'\n", cur->data);
- parse_keyword(cur->data, &rest);
- if (rest) {
- argv2 = arg_parse(rest, filename, lineno);
- cur2 = argv2;
- while(cur2) {
- ast_context_add_include2(con, cur2->data, registrar);
- cur2 = cur2->next;
- }
- arg_free(argv2);
- }
- } else if (matches_keyword(cur->data, "ignorepat")) {
- if (aeldebug & DEBUG_CONTEXTS)
- ast_verbose("--IGNOREPAT: '%s'\n", cur->data);
- parse_keyword(cur->data, &rest);
- if (rest) {
- argv2 = arg_parse(rest, filename, lineno);
- cur2 = argv2;
- while(cur2) {
- ast_context_add_ignorepat2(con, cur2->data, registrar);
- cur2 = cur2->next;
- }
- arg_free(argv2);
- }
- } else if (matches_keyword(cur->data, "switches") || matches_keyword(cur->data, "eswitches")) {
- if (aeldebug & DEBUG_CONTEXTS)
- ast_verbose("--[E]SWITCH: '%s'\n", cur->data);
- parse_keyword(cur->data, &rest);
- if (rest) {
- argv2 = arg_parse(rest, filename, lineno);
- cur2 = argv2;
- while(cur2) {
- c = strchr(cur2->data, '/');
- if (c) {
- *c = '\0';
- c++;
- } else
- c = "";
- ast_context_add_switch2(con, cur2->data, c, (cur->data[0] == 'e'), registrar);
- cur2 = cur2->next;
- }
- arg_free(argv2);
- }
- } else if (matches_extension(cur->data, &rest)) {
- if (aeldebug & DEBUG_CONTEXTS)
- ast_verbose("Extension: '%s' => '%s'\n", cur->data, rest);
- pos = 1;
- build_step("extension", cur->data, filename, lineno, con, cur->data, &pos, rest, NULL, NULL);
- }
- cur = cur->next;
- }
- } else
- ast_log(LOG_WARNING, "Unable to create context '%s'\n", name);
- arg_free(argv);
- if (vars->next)
- ast_log(LOG_NOTICE, "Ignoring excess tokens in macro definition around line %d of %s!\n", lineno, filename);
-}
-
-static int handle_root_token(struct ast_context **local_contexts, char *token, int level, const char *filename, int lineno)
-{
- struct stringlink *argv, *cur;
- argv = split_token(token, filename, lineno);
- if (aeldebug & DEBUG_TOKENS) {
- ast_verbose("Found root token '%s' at level %d (%s:%d)!\n", token, level, filename, lineno);
- cur = argv;
- while(cur) {
- ast_verbose(" ARG => '%s'\n", cur->data);
- cur = cur->next;
- }
- }
- if (!strcasecmp(token, "globals")) {
- handle_globals(argv);
- } else if (!strcasecmp(token, "macro")) {
- handle_macro(local_contexts, argv, filename, lineno);
- } else if (!strcasecmp(token, "context")) {
- handle_context(local_contexts, argv, filename, lineno);
- } else {
- ast_log(LOG_NOTICE, "Unknown root token '%s'\n", token);
- }
- arg_free(argv);
- return 0;
-}
-
-
-static int ast_ael_compile(struct ast_context **local_contexts, const char *filename)
-{
- char *rfilename;
- char *buf, *tbuf;
- int bufsiz;
- FILE *f;
- char *c;
- char *token;
- int lineno=0;
-
- if (filename[0] == '/')
- rfilename = (char *)filename;
- else {
- rfilename = alloca(strlen(filename) + strlen(ast_config_AST_CONFIG_DIR) + 2);
- sprintf(rfilename, "%s/%s", ast_config_AST_CONFIG_DIR, filename);
- }
-
- f = fopen(rfilename, "r");
- if (!f) {
- ast_log(LOG_WARNING, "Unable to open '%s': %s\n", rfilename, strerror(errno));
- return -1;
- }
- buf = malloc(4096);
- if (!buf) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- fclose(f);
- return -1;
- }
- buf[0] = 0;
- bufsiz = 4096;
- while(!feof(f)) {
- if (bufsiz - strlen(buf) < 2048) {
- bufsiz += 4096;
- tbuf = realloc(buf, bufsiz);
- if (tbuf) {
- buf = tbuf;
- } else {
- free(buf);
- ast_log(LOG_WARNING, "Out of memory!\n");
- fclose(f);
- }
- }
- if (fgets(buf + strlen(buf), bufsiz - strlen(buf), f)) {
- lineno++;
- while(*buf && buf[strlen(buf) - 1] < 33)
- buf[strlen(buf) - 1] = '\0';
- c = strstr(buf, "//");
- if (c)
- *c = '\0';
- if (*buf) {
- if (aeldebug & DEBUG_READ)
- ast_verbose("Newly composed line '%s'\n", buf);
- while((token = grab_token(buf, filename, lineno))) {
- handle_root_token(local_contexts, token, 0, filename, lineno);
- free(token);
- }
- }
- }
- };
- free(buf);
- fclose(f);
- return 0;
-}
-
-static int pbx_load_module(void)
-{
- struct ast_context *local_contexts=NULL, *con;
- ast_ael_compile(&local_contexts, config);
- ast_merge_contexts_and_delete(&local_contexts, registrar);
- for (con = ast_walk_contexts(NULL); con; con = ast_walk_contexts(con))
- ast_context_verify_includes(con);
-
- return 0;
-}
-
-/* CLI interface */
-static int ael_debug_read(int fd, int argc, char *argv[])
-{
- aeldebug |= DEBUG_READ;
- return 0;
-}
-
-static int ael_debug_tokens(int fd, int argc, char *argv[])
-{
- aeldebug |= DEBUG_TOKENS;
- return 0;
-}
-
-static int ael_debug_macros(int fd, int argc, char *argv[])
-{
- aeldebug |= DEBUG_MACROS;
- return 0;
-}
-
-static int ael_debug_contexts(int fd, int argc, char *argv[])
-{
- aeldebug |= DEBUG_CONTEXTS;
- return 0;
-}
-
-static int ael_no_debug(int fd, int argc, char *argv[])
-{
- aeldebug = 0;
- return 0;
-}
-
-static int ael_reload(int fd, int argc, char *argv[])
-{
- ast_context_destroy(NULL, registrar);
- return (pbx_load_module());
-}
-
-static struct ast_cli_entry ael_cli[] = {
- { { "ael", "reload", NULL }, ael_reload, "Reload AEL configuration"},
- { { "ael", "debug", "read", NULL }, ael_debug_read, "Enable AEL read debug"},
- { { "ael", "debug", "tokens", NULL }, ael_debug_tokens, "Enable AEL tokens debug"},
- { { "ael", "debug", "macros", NULL }, ael_debug_macros, "Enable AEL macros debug"},
- { { "ael", "debug", "contexts", NULL }, ael_debug_contexts, "Enable AEL contexts debug"},
- { { "ael", "no", "debug", NULL }, ael_no_debug, "Disable AEL debug messages"},
-};
-
-/*
- * Standard module functions ...
- */
-int unload_module(void)
-{
- ast_context_destroy(NULL, registrar);
- ast_cli_unregister_multiple(ael_cli, sizeof(ael_cli)/ sizeof(ael_cli[0]));
- return 0;
-}
-
-
-int load_module(void)
-{
- ast_cli_register_multiple(ael_cli, sizeof(ael_cli)/ sizeof(ael_cli[0]));
- return (pbx_load_module());
-}
-
-int reload(void)
-{
- ast_context_destroy(NULL, registrar);
- return pbx_load_module();
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *description(void)
-{
- return dtext;
-}
-
-char *key(void)
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/pbx/pbx_config.c b/1.2-netsec/pbx/pbx_config.c
deleted file mode 100644
index 42e43470a..000000000
--- a/1.2-netsec/pbx/pbx_config.c
+++ /dev/null
@@ -1,1831 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Populate and remember extensions from static config file
- *
- *
- */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/pbx.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/cli.h"
-#include "asterisk/callerid.h"
-
-#ifdef __AST_DEBUG_MALLOC
-static void FREE(void *ptr)
-{
- free(ptr);
-}
-#else
-#define FREE free
-#endif
-
-static char *dtext = "Text Extension Configuration";
-static char *config = "extensions.conf";
-static char *registrar = "pbx_config";
-
-static int static_config = 0;
-static int write_protect_config = 1;
-static int autofallthrough_config = 0;
-static int clearglobalvars_config = 0;
-
-AST_MUTEX_DEFINE_STATIC(save_dialplan_lock);
-
-static struct ast_context *local_contexts = NULL;
-
-/*
- * Help for commands provided by this module ...
- */
-static char context_dont_include_help[] =
-"Usage: dont include <context> in <context>\n"
-" Remove an included context from another context.\n";
-
-static char context_remove_extension_help[] =
-"Usage: remove extension exten@context [priority]\n"
-" Remove an extension from a given context. If a priority\n"
-" is given, only that specific priority from the given extension\n"
-" will be removed.\n";
-
-static char context_add_include_help[] =
-"Usage: include <context> in <context>\n"
-" Include a context in another context.\n";
-
-static char save_dialplan_help[] =
-"Usage: save dialplan [/path/to/extension/file]\n"
-" Save dialplan created by pbx_config module.\n"
-"\n"
-"Example: save dialplan (/etc/asterisk/extensions.conf)\n"
-" save dialplan /home/markster (/home/markster/extensions.conf)\n";
-
-static char context_add_extension_help[] =
-"Usage: add extension <exten>,<priority>,<app>,<app-data> into <context>\n"
-" [replace]\n\n"
-" This command will add new extension into <context>. If there is an\n"
-" existence of extension with the same priority and last 'replace'\n"
-" arguments is given here we simply replace this extension.\n"
-"\n"
-"Example: add extension 6123,1,Dial,IAX/216.207.245.56/6123 into local\n"
-" Now, you can dial 6123 and talk to Markster :)\n";
-
-static char context_add_ignorepat_help[] =
-"Usage: add ignorepat <pattern> into <context>\n"
-" This command adds a new ignore pattern into context <context>\n"
-"\n"
-"Example: add ignorepat _3XX into local\n";
-
-static char context_remove_ignorepat_help[] =
-"Usage: remove ignorepat <pattern> from <context>\n"
-" This command removes an ignore pattern from context <context>\n"
-"\n"
-"Example: remove ignorepat _3XX from local\n";
-
-static char reload_extensions_help[] =
-"Usage: reload extensions.conf without reloading any other modules\n"
-" This command does not delete global variables unless\n"
-" clearglobalvars is set to yes in extensions.conf\n"
-"\n"
-"Example: extensions reload\n";
-
-/*
- * Implementation of functions provided by this module
- */
-
-/*!
- * REMOVE INCLUDE command stuff
- */
-static int handle_context_dont_include(int fd, int argc, char *argv[])
-{
- if (argc != 5)
- return RESULT_SHOWUSAGE;
-
- if (strcmp(argv[3], "in"))
- return RESULT_SHOWUSAGE;
-
- if (!ast_context_remove_include(argv[4], argv[2], registrar)) {
- ast_cli(fd, "We are not including '%s' in '%s' now\n",
- argv[2], argv[4]);
- return RESULT_SUCCESS;
- }
-
- ast_cli(fd, "Failed to remove '%s' include from '%s' context\n",
- argv[2], argv[4]);
- return RESULT_FAILURE;
-}
-
-static char *complete_context_dont_include(char *line, char *word,
- int pos, int state)
-{
- int which = 0;
-
- /*
- * Context completion ...
- */
- if (pos == 2) {
- struct ast_context *c;
-
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Failed to lock context list\n");
- return NULL;
- }
-
- /* walk pbx_get_contexts ... */
- c = ast_walk_contexts(NULL);
- while (c) {
- struct ast_include *i;
-
- if (ast_lock_context(c)) {
- c = ast_walk_contexts(c);
- continue;
- }
-
- i = ast_walk_context_includes(c, NULL);
- while (i) {
- if (!strlen(word) ||
- !strncmp(ast_get_include_name(i), word, strlen(word))) {
- struct ast_context *nc;
- int already_served = 0;
-
- /* check if this include is already served or not */
-
- /* go through all contexts again till we reach actuall
- * context or already_served = 1
- */
- nc = ast_walk_contexts(NULL);
- while (nc && nc != c && !already_served) {
- if (!ast_lock_context(nc)) {
- struct ast_include *ni;
-
- ni = ast_walk_context_includes(nc, NULL);
- while (ni && !already_served) {
- if (!strcmp(ast_get_include_name(i),
- ast_get_include_name(ni)))
- already_served = 1;
- ni = ast_walk_context_includes(nc, ni);
- }
-
- ast_unlock_context(nc);
- }
- nc = ast_walk_contexts(nc);
- }
-
- if (!already_served) {
- if (++which > state) {
- char *res =
- strdup(ast_get_include_name(i));
- ast_unlock_context(c);
- ast_unlock_contexts();
- return res;
- }
- }
- }
- i = ast_walk_context_includes(c, i);
- }
-
- ast_unlock_context(c);
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
- return NULL;
- }
-
- /*
- * 'in' completion ... (complete only if previous context is really
- * included somewhere)
- */
- if (pos == 3) {
- struct ast_context *c;
- char *context, *dupline, *duplinet;
-
- if (state > 0) return NULL;
-
- /* take 'context' from line ... */
- if (!(dupline = strdup(line))) {
- ast_log(LOG_ERROR, "Out of free memory\n");
- return NULL;
- }
-
- duplinet = dupline;
- strsep(&duplinet, " "); /* skip 'dont' */
- strsep(&duplinet, " "); /* skip 'include' */
- context = strsep(&duplinet, " ");
-
- if (!context) {
- free(dupline);
- return NULL;
- }
-
- if (ast_lock_contexts()) {
- ast_log(LOG_WARNING, "Failed to lock contexts list\n");
- free(dupline);
- return NULL;
- }
-
- /* go through all contexts and check if is included ... */
- c = ast_walk_contexts(NULL);
- while (c) {
- struct ast_include *i;
- if (ast_lock_context(c)) {
- free(dupline);
- ast_unlock_contexts();
- return NULL;
- }
-
- i = ast_walk_context_includes(c, NULL);
- while (i) {
- /* is it our context? */
- if (!strcmp(ast_get_include_name(i), context)) {
- /* yes, it is, context is really included, so
- * complete "in" command
- */
- free(dupline);
- ast_unlock_context(c);
- ast_unlock_contexts();
- return strdup("in");
- }
- i = ast_walk_context_includes(c, i);
- }
- ast_unlock_context(c);
- c = ast_walk_contexts(c);
- }
- free(dupline);
- ast_unlock_contexts();
- return NULL;
- }
-
- /*
- * Context from which we removing include ...
- */
- if (pos == 4) {
- struct ast_context *c;
- char *context, *dupline, *duplinet, *in;
-
- if (!(dupline = strdup(line))) {
- ast_log(LOG_ERROR, "Out of free memory\n");
- return NULL;
- }
-
- duplinet = dupline;
-
- strsep(&duplinet, " "); /* skip 'dont' */
- strsep(&duplinet, " "); /* skip 'include' */
-
- if (!(context = strsep(&duplinet, " "))) {
- free(dupline);
- return NULL;
- }
-
- /* third word must be in */
- in = strsep(&duplinet, " ");
- if (!in ||
- strcmp(in, "in")) {
- free(dupline);
- return NULL;
- }
-
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Failed to lock context list\n");
- free(dupline);
- return NULL;
- }
-
- /* walk through all contexts ... */
- c = ast_walk_contexts(NULL);
- while (c) {
- struct ast_include *i;
- if (ast_lock_context(c)) {
- free(dupline);
- return NULL;
- }
-
- /* walk through all includes and check if it is our context */
- i = ast_walk_context_includes(c, NULL);
- while (i) {
- /* is in this context included another on which we want to
- * remove?
- */
- if (!strcmp(context, ast_get_include_name(i))) {
- /* yes, it's included, is matching our word too? */
- if (!strncmp(ast_get_context_name(c),
- word, strlen(word))) {
- /* check state for completion */
- if (++which > state) {
- char *res = strdup(ast_get_context_name(c));
- free(dupline);
- ast_unlock_context(c);
- ast_unlock_contexts();
- return res;
- }
- }
- break;
- }
- i = ast_walk_context_includes(c, i);
- }
- ast_unlock_context(c);
- c = ast_walk_contexts(c);
- }
-
- free(dupline);
- ast_unlock_contexts();
- return NULL;
- }
-
- return NULL;
-}
-
-/*!
- * REMOVE EXTENSION command stuff
- */
-static int handle_context_remove_extension(int fd, int argc, char *argv[])
-{
- int removing_priority = 0;
- char *exten, *context;
-
- if (argc != 4 && argc != 3) return RESULT_SHOWUSAGE;
-
- /*
- * Priority input checking ...
- */
- if (argc == 4) {
- char *c = argv[3];
-
- /* check for digits in whole parameter for right priority ...
- * why? because atoi (strtol) returns 0 if any characters in
- * string and whole extension will be removed, it's not good
- */
- if (strcmp("hint", c)) {
- while (*c != '\0') {
- if (!isdigit(*c++)) {
- ast_cli(fd, "Invalid priority '%s'\n", argv[3]);
- return RESULT_FAILURE;
- }
- }
- removing_priority = atoi(argv[3]);
- } else
- removing_priority = PRIORITY_HINT;
-
- if (removing_priority == 0) {
- ast_cli(fd, "If you want to remove whole extension, please " \
- "omit priority argument\n");
- return RESULT_FAILURE;
- }
- }
-
- /*
- * Format exten@context checking ...
- */
- if (!(context = strchr(argv[2], (int)'@'))) {
- ast_cli(fd, "First argument must be in exten@context format\n");
- return RESULT_FAILURE;
- }
-
- *context++ = '\0';
- exten = argv[2];
- if ((!strlen(exten)) || (!(strlen(context)))) {
- ast_cli(fd, "Missing extension or context name in second argument '%s@%s'\n",
- exten == NULL ? "?" : exten, context == NULL ? "?" : context);
- return RESULT_FAILURE;
- }
-
- if (!ast_context_remove_extension(context, exten, removing_priority, registrar)) {
- if (!removing_priority)
- ast_cli(fd, "Whole extension %s@%s removed\n",
- exten, context);
- else
- ast_cli(fd, "Extension %s@%s with priority %d removed\n",
- exten, context, removing_priority);
-
- return RESULT_SUCCESS;
- }
-
- ast_cli(fd, "Failed to remove extension %s@%s\n", exten, context);
-
- return RESULT_FAILURE;
-}
-
-#define BROKEN_READLINE 1
-
-#ifdef BROKEN_READLINE
-/*
- * There is one funny thing, when you have word like 300@ and you hit
- * <tab>, you arguments will like as your word is '300 ', so it '@'
- * characters acts sometimes as word delimiter and sometimes as a part
- * of word
- *
- * This fix function, allocates new word variable and store here every
- * time xxx@yyy always as one word and correct pos is set too
- *
- * It's ugly, I know, but I'm waiting for Mark suggestion if upper is
- * bug or feature ...
- */
-static int fix_complete_args(char *line, char **word, int *pos)
-{
- char *_line, *_strsep_line, *_previous_word = NULL, *_word = NULL;
- int words = 0;
-
- _line = strdup(line);
-
- _strsep_line = _line;
- while (_strsep_line) {
- _previous_word = _word;
- _word = strsep(&_strsep_line, " ");
-
- if (_word && strlen(_word)) words++;
- }
-
-
- if (_word || _previous_word) {
- if (_word) {
- if (!strlen(_word)) words++;
- *word = strdup(_word);
- } else
- *word = strdup(_previous_word);
- *pos = words - 1;
- free(_line);
- return 0;
- }
-
- free(_line);
- return -1;
-}
-#endif /* BROKEN_READLINE */
-
-static char *complete_context_remove_extension(char *line, char *word, int pos,
- int state)
-{
- char *ret = NULL;
- int which = 0;
-
-#ifdef BROKEN_READLINE
- /*
- * Fix arguments, *word is a new allocated structure, REMEMBER to
- * free *word when you want to return from this function ...
- */
- if (fix_complete_args(line, &word, &pos)) {
- ast_log(LOG_ERROR, "Out of free memory\n");
- return NULL;
- }
-#endif
-
- /*
- * exten@context completion ...
- */
- if (pos == 2) {
- struct ast_context *c;
- struct ast_exten *e;
- char *context = NULL, *exten = NULL, *delim = NULL;
-
- /* now, parse values from word = exten@context */
- if ((delim = strchr(word, (int)'@'))) {
- /* check for duplicity ... */
- if (delim != strrchr(word, (int)'@')) {
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- return NULL;
- }
-
- *delim = '\0';
- exten = strdup(word);
- context = strdup(delim + 1);
- *delim = '@';
- } else {
- exten = strdup(word);
- }
-#ifdef BROKEN_READLINE
- free(word);
-#endif
-
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Failed to lock context list\n");
- free(context); free(exten);
- return NULL;
- }
-
- /* find our context ... */
- c = ast_walk_contexts(NULL);
- while (c) {
- /* our context? */
- if ( (!context || !strlen(context)) || /* if no input, all contexts ... */
- (context && !strncmp(ast_get_context_name(c),
- context, strlen(context))) ) { /* if input, compare ... */
- /* try to complete extensions ... */
- e = ast_walk_context_extensions(c, NULL);
- while (e) {
- /* our extension? */
- if ( (!exten || !strlen(exten)) || /* if not input, all extensions ... */
- (exten && !strncmp(ast_get_extension_name(e), exten,
- strlen(exten))) ) { /* if input, compare ... */
- if (++which > state) {
- /* If there is an extension then return
- * exten@context.
- */
- if (exten) {
- ret = malloc(strlen(ast_get_extension_name(e)) +
- strlen(ast_get_context_name(c)) + 2);
- if (ret)
- sprintf(ret, "%s@%s", ast_get_extension_name(e),
- ast_get_context_name(c));
- }
- free(exten); free(context);
-
- ast_unlock_contexts();
-
- return ret;
- }
- }
- e = ast_walk_context_extensions(c, e);
- }
- }
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
-
- free(exten); free(context);
-
- return NULL;
- }
-
- /*
- * Complete priority ...
- */
- if (pos == 3) {
- char *delim, *exten, *context, *dupline, *duplinet, *ec;
- struct ast_context *c;
-
- dupline = strdup(line);
- if (!dupline) {
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- return NULL;
- }
- duplinet = dupline;
-
- strsep(&duplinet, " "); /* skip 'remove' */
- strsep(&duplinet, " "); /* skip 'extension */
-
- if (!(ec = strsep(&duplinet, " "))) {
- free(dupline);
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- return NULL;
- }
-
- /* wrong exten@context format? */
- if (!(delim = strchr(ec, (int)'@')) ||
- (strchr(ec, (int)'@') != strrchr(ec, (int)'@'))) {
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- free(dupline);
- return NULL;
- }
-
- /* check if there is exten and context too ... */
- *delim = '\0';
- if ((!strlen(ec)) || (!strlen(delim + 1))) {
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- free(dupline);
- return NULL;
- }
-
- exten = strdup(ec);
- context = strdup(delim + 1);
- free(dupline);
-
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Failed to lock context list\n");
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- free(exten); free(context);
- return NULL;
- }
-
- /* walk contexts */
- c = ast_walk_contexts(NULL);
- while (c) {
- if (!strcmp(ast_get_context_name(c), context)) {
- struct ast_exten *e;
-
- /* walk extensions */
- free(context);
- e = ast_walk_context_extensions(c, NULL);
- while (e) {
- if (!strcmp(ast_get_extension_name(e), exten)) {
- struct ast_exten *priority;
- char buffer[10];
-
- free(exten);
- priority = ast_walk_extension_priorities(e, NULL);
- /* serve priorities */
- do {
- snprintf(buffer, 10, "%u",
- ast_get_extension_priority(priority));
- if (!strncmp(word, buffer, strlen(word))) {
- if (++which > state) {
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- ast_unlock_contexts();
- return strdup(buffer);
- }
- }
- priority = ast_walk_extension_priorities(e,
- priority);
- } while (priority);
-
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- ast_unlock_contexts();
- return NULL;
- }
- e = ast_walk_context_extensions(c, e);
- }
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- free(exten);
- ast_unlock_contexts();
- return NULL;
- }
- c = ast_walk_contexts(c);
- }
-
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- free(exten); free(context);
-
- ast_unlock_contexts();
- return NULL;
- }
-
-#ifdef BROKEN_READLINE
- free(word);
-#endif
- return NULL;
-}
-
-/*!
- * Include context ...
- */
-static int handle_context_add_include(int fd, int argc, char *argv[])
-{
- if (argc != 5) return RESULT_SHOWUSAGE;
-
- /* third arg must be 'in' ... */
- if (strcmp(argv[3], "in") && strcmp(argv[3], "into")) return RESULT_SHOWUSAGE;
-
- if (ast_context_add_include(argv[4], argv[2], registrar)) {
- switch (errno) {
- case ENOMEM:
- ast_cli(fd, "Out of memory for context addition\n"); break;
-
- case EBUSY:
- ast_cli(fd, "Failed to lock context(s) list, please try again later\n"); break;
-
- case EEXIST:
- ast_cli(fd, "Context '%s' already included in '%s' context\n",
- argv[2], argv[4]); break;
-
- case ENOENT:
- case EINVAL:
- ast_cli(fd, "There is no existence of context '%s'\n",
- errno == ENOENT ? argv[4] : argv[2]); break;
-
- default:
- ast_cli(fd, "Failed to include '%s' in '%s' context\n",
- argv[2], argv[4]); break;
- }
- return RESULT_FAILURE;
- }
-
- /* show some info ... */
- ast_cli(fd, "Context '%s' included in '%s' context\n",
- argv[2], argv[4]);
-
- return RESULT_SUCCESS;
-}
-
-static char *complete_context_add_include(char *line, char *word, int pos,
- int state)
-{
- struct ast_context *c;
- int which = 0;
-
- /* server context for inclusion ... */
- if (pos == 1)
- {
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Failed to lock context list\n");
- return NULL;
- }
-
- /* server all contexts */
- c = ast_walk_contexts(NULL);
- while (c) {
- if ((!strlen(word) ||
- !strncmp(ast_get_context_name(c), word, strlen(word))) &&
- ++which > state)
- {
- char *context = strdup(ast_get_context_name(c));
- ast_unlock_contexts();
- return context;
- }
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
- }
-
- /* complete 'in' only if context exist ... */
- if (pos == 2)
- {
- char *context, *dupline, *duplinet;
-
- if (state != 0) return NULL;
-
- /* parse context from line ... */
- if (!(dupline = strdup(line))) {
- ast_log(LOG_ERROR, "Out of free memory\n");
- if (state == 0) return strdup("in");
- return NULL;
- }
-
- duplinet = dupline;
-
- strsep(&duplinet, " ");
- context = strsep(&duplinet, " ");
- if (context) {
- struct ast_context *c;
- int context_existence = 0;
-
- /* check for context existence ... */
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Failed to lock context list\n");
- free(dupline);
- /* our fault, we can't check, so complete 'in' ... */
- return strdup("in");
- }
-
- c = ast_walk_contexts(NULL);
- while (c && !context_existence) {
- if (!strcmp(context, ast_get_context_name(c))) {
- context_existence = 1;
- continue;
- }
- c = ast_walk_contexts(c);
- }
-
- /* if context exists, return 'into' ... */
- if (context_existence) {
- free(dupline);
- ast_unlock_contexts();
- return strdup("into");
- }
-
- ast_unlock_contexts();
- }
-
- free(dupline);
- return NULL;
- }
-
- /* serve context into which we include another context */
- if (pos == 3)
- {
- char *context, *dupline, *duplinet, *in;
- int context_existence = 0;
-
- if (!(dupline = strdup(line))) {
- ast_log(LOG_ERROR, "Out of free memory\n");
- return NULL;
- }
-
- duplinet = dupline;
-
- strsep(&duplinet, " "); /* skip 'include' */
- context = strsep(&duplinet, " ");
- in = strsep(&duplinet, " ");
-
- /* given some context and third word is in? */
- if (!strlen(context) || strcmp(in, "in")) {
- free(dupline);
- return NULL;
- }
-
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Failed to lock context list\n");
- free(dupline);
- return NULL;
- }
-
- /* check for context existence ... */
- c = ast_walk_contexts(NULL);
- while (c && !context_existence) {
- if (!strcmp(context, ast_get_context_name(c))) {
- context_existence = 1;
- continue;
- }
- c = ast_walk_contexts(c);
- }
-
- if (!context_existence) {
- free(dupline);
- ast_unlock_contexts();
- return NULL;
- }
-
- /* go through all contexts ... */
- c = ast_walk_contexts(NULL);
- while (c) {
- /* must be different contexts ... */
- if (strcmp(context, ast_get_context_name(c))) {
- if (!ast_lock_context(c)) {
- struct ast_include *i;
- int included = 0;
-
- /* check for duplicity inclusion ... */
- i = ast_walk_context_includes(c, NULL);
- while (i && !included) {
- if (!strcmp(ast_get_include_name(i), context))
- included = 1;
- i = ast_walk_context_includes(c, i);
- }
- ast_unlock_context(c);
-
- /* not included yet, so show possibility ... */
- if (!included &&
- !strncmp(ast_get_context_name(c), word, strlen(word))){
-
- if (++which > state) {
- char *res = strdup(ast_get_context_name(c));
- free(dupline);
- ast_unlock_contexts();
- return res;
- }
- }
- }
- }
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
- free(dupline);
- return NULL;
- }
-
- return NULL;
-}
-
-/*!
- * \brief 'save dialplan' CLI command implementation functions ...
- */
-static int handle_save_dialplan(int fd, int argc, char *argv[])
-{
- char filename[256];
- struct ast_context *c;
- struct ast_config *cfg;
- struct ast_variable *v;
- int context_header_written;
- int incomplete = 0; /* incomplete config write? */
- FILE *output;
-
- if (! (static_config && !write_protect_config)) {
- ast_cli(fd,
- "I can't save dialplan now, see '%s' example file.\n",
- config);
- return RESULT_FAILURE;
- }
-
- if (argc != 2 && argc != 3) return RESULT_SHOWUSAGE;
-
- if (ast_mutex_lock(&save_dialplan_lock)) {
- ast_cli(fd,
- "Failed to lock dialplan saving (another proccess saving?)\n");
- return RESULT_FAILURE;
- }
-
- /* have config path? */
- if (argc == 3) {
- /* is there extension.conf too? */
- if (!strstr(argv[2], ".conf")) {
- /* no, only directory path, check for last '/' occurence */
- if (*(argv[2] + strlen(argv[2]) -1) == '/')
- snprintf(filename, sizeof(filename), "%s%s",
- argv[2], config);
- else
- /* without config extensions.conf, add it */
- snprintf(filename, sizeof(filename), "%s/%s",
- argv[2], config);
- } else
- /* there is an .conf */
- snprintf(filename, sizeof(filename), argv[2]);
- } else
- /* no config file, default one */
- snprintf(filename, sizeof(filename), "%s/%s",
- (char *)ast_config_AST_CONFIG_DIR, config);
-
- cfg = ast_config_load("extensions.conf");
-
- /* try to lock contexts list */
- if (ast_lock_contexts()) {
- ast_cli(fd, "Failed to lock contexts list\n");
- ast_mutex_unlock(&save_dialplan_lock);
- ast_config_destroy(cfg);
- return RESULT_FAILURE;
- }
-
- /* create new file ... */
- if (!(output = fopen(filename, "wt"))) {
- ast_cli(fd, "Failed to create file '%s'\n",
- filename);
- ast_unlock_contexts();
- ast_mutex_unlock(&save_dialplan_lock);
- ast_config_destroy(cfg);
- return RESULT_FAILURE;
- }
-
- /* fireout general info */
- fprintf(output, "[general]\nstatic=%s\nwriteprotect=%s\n\n",
- static_config ? "yes" : "no",
- write_protect_config ? "yes" : "no");
-
- if ((v = ast_variable_browse(cfg, "globals"))) {
- fprintf(output, "[globals]\n");
- while(v) {
- fprintf(output, "%s => %s\n", v->name, v->value);
- v = v->next;
- }
- fprintf(output, "\n");
- }
-
- ast_config_destroy(cfg);
-
- /* walk all contexts */
- c = ast_walk_contexts(NULL);
- while (c) {
- context_header_written = 0;
-
- /* try to lock context and fireout all info */
- if (!ast_lock_context(c)) {
- struct ast_exten *e, *last_written_e = NULL;
- struct ast_include *i;
- struct ast_ignorepat *ip;
- struct ast_sw *sw;
-
- /* registered by this module? */
- if (!strcmp(ast_get_context_registrar(c), registrar)) {
- fprintf(output, "[%s]\n", ast_get_context_name(c));
- context_header_written = 1;
- }
-
- /* walk extensions ... */
- e = ast_walk_context_extensions(c, NULL);
- while (e) {
- struct ast_exten *p;
-
- /* fireout priorities */
- p = ast_walk_extension_priorities(e, NULL);
- while (p) {
- if (!strcmp(ast_get_extension_registrar(p),
- registrar)) {
-
- /* make empty line between different extensions */
- if (last_written_e != NULL &&
- strcmp(ast_get_extension_name(last_written_e),
- ast_get_extension_name(p)))
- fprintf(output, "\n");
- last_written_e = p;
-
- if (!context_header_written) {
- fprintf(output, "[%s]\n", ast_get_context_name(c));
- context_header_written = 1;
- }
-
- if (ast_get_extension_priority(p)!=PRIORITY_HINT) {
- char *tempdata = NULL, *startdata;
- tempdata = strdup((char *)ast_get_extension_app_data(p));
- if (tempdata) {
- startdata = tempdata;
- while (*tempdata) {
- if (*tempdata == '|')
- *tempdata = ',';
- tempdata++;
- }
- tempdata = startdata;
- }
- if (ast_get_extension_matchcid(p))
- fprintf(output, "exten => %s/%s,%d,%s(%s)\n",
- ast_get_extension_name(p),
- ast_get_extension_cidmatch(p),
- ast_get_extension_priority(p),
- ast_get_extension_app(p),
- tempdata);
- else
- fprintf(output, "exten => %s,%d,%s(%s)\n",
- ast_get_extension_name(p),
- ast_get_extension_priority(p),
- ast_get_extension_app(p),
- tempdata);
- if (tempdata)
- free(tempdata);
- } else
- fprintf(output, "exten => %s,hint,%s\n",
- ast_get_extension_name(p),
- ast_get_extension_app(p));
-
- }
- p = ast_walk_extension_priorities(e, p);
- }
-
- e = ast_walk_context_extensions(c, e);
- }
-
- /* written any extensions? ok, write space between exten & inc */
- if (last_written_e) fprintf(output, "\n");
-
- /* walk through includes */
- i = ast_walk_context_includes(c, NULL);
- while (i) {
- if (!strcmp(ast_get_include_registrar(i), registrar)) {
- if (!context_header_written) {
- fprintf(output, "[%s]\n", ast_get_context_name(c));
- context_header_written = 1;
- }
- fprintf(output, "include => %s\n",
- ast_get_include_name(i));
- }
- i = ast_walk_context_includes(c, i);
- }
-
- if (ast_walk_context_includes(c, NULL))
- fprintf(output, "\n");
-
- /* walk through switches */
- sw = ast_walk_context_switches(c, NULL);
- while (sw) {
- if (!strcmp(ast_get_switch_registrar(sw), registrar)) {
- if (!context_header_written) {
- fprintf(output, "[%s]\n", ast_get_context_name(c));
- context_header_written = 1;
- }
- fprintf(output, "switch => %s/%s\n",
- ast_get_switch_name(sw),
- ast_get_switch_data(sw));
- }
- sw = ast_walk_context_switches(c, sw);
- }
-
- if (ast_walk_context_switches(c, NULL))
- fprintf(output, "\n");
-
- /* fireout ignorepats ... */
- ip = ast_walk_context_ignorepats(c, NULL);
- while (ip) {
- if (!strcmp(ast_get_ignorepat_registrar(ip), registrar)) {
- if (!context_header_written) {
- fprintf(output, "[%s]\n", ast_get_context_name(c));
- context_header_written = 1;
- }
-
- fprintf(output, "ignorepat => %s\n",
- ast_get_ignorepat_name(ip));
- }
- ip = ast_walk_context_ignorepats(c, ip);
- }
-
- ast_unlock_context(c);
- } else
- incomplete = 1;
-
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
- ast_mutex_unlock(&save_dialplan_lock);
- fclose(output);
-
- if (incomplete) {
- ast_cli(fd, "Saved dialplan is incomplete\n");
- return RESULT_FAILURE;
- }
-
- ast_cli(fd, "Dialplan successfully saved into '%s'\n",
- filename);
- return RESULT_SUCCESS;
-}
-
-/*!
- * \brief ADD EXTENSION command stuff
- */
-static int handle_context_add_extension(int fd, int argc, char *argv[])
-{
- char *whole_exten;
- char *exten, *prior;
- int iprior = -2;
- char *cidmatch, *app, *app_data;
- char *start, *end;
-
- /* check for arguments at first */
- if (argc != 5 && argc != 6) return RESULT_SHOWUSAGE;
- if (strcmp(argv[3], "into")) return RESULT_SHOWUSAGE;
- if (argc == 6) if (strcmp(argv[5], "replace")) return RESULT_SHOWUSAGE;
-
- whole_exten = argv[2];
- exten = strsep(&whole_exten,",");
- if (strchr(exten, '/')) {
- cidmatch = exten;
- strsep(&cidmatch,"/");
- } else {
- cidmatch = NULL;
- }
- prior = strsep(&whole_exten,",");
- if (prior) {
- if (!strcmp(prior, "hint")) {
- iprior = PRIORITY_HINT;
- } else {
- if (sscanf(prior, "%d", &iprior) != 1) {
- ast_cli(fd, "'%s' is not a valid priority\n", prior);
- prior = NULL;
- }
- }
- }
- app = whole_exten;
- if (app && (start = strchr(app, '(')) && (end = strrchr(app, ')'))) {
- *start = *end = '\0';
- app_data = start + 1;
- ast_process_quotes_and_slashes(app_data, ',', '|');
- } else {
- if (app) {
- app_data = strchr(app, ',');
- if (app_data) {
- *app_data = '\0';
- app_data++;
- }
- } else
- app_data = NULL;
- }
-
- if (!exten || !prior || !app || (!app_data && iprior != PRIORITY_HINT)) return RESULT_SHOWUSAGE;
-
- if (!app_data)
- app_data="";
- if (ast_add_extension(argv[4], argc == 6 ? 1 : 0, exten, iprior, NULL, cidmatch, app,
- (void *)strdup(app_data), free, registrar)) {
- switch (errno) {
- case ENOMEM:
- ast_cli(fd, "Out of free memory\n"); break;
-
- case EBUSY:
- ast_cli(fd, "Failed to lock context(s) list, please try again later\n"); break;
-
- case ENOENT:
- ast_cli(fd, "No existence of '%s' context\n", argv[4]); break;
-
- case EEXIST:
- ast_cli(fd, "Extension %s@%s with priority %s already exists\n",
- exten, argv[4], prior); break;
-
- default:
- ast_cli(fd, "Failed to add '%s,%s,%s,%s' extension into '%s' context\n",
- exten, prior, app, app_data, argv[4]); break;
- }
- return RESULT_FAILURE;
- }
-
- if (argc == 6)
- ast_cli(fd, "Extension %s@%s (%s) replace by '%s,%s,%s,%s'\n",
- exten, argv[4], prior, exten, prior, app, app_data);
- else
- ast_cli(fd, "Extension '%s,%s,%s,%s' added into '%s' context\n",
- exten, prior, app, app_data, argv[4]);
-
- return RESULT_SUCCESS;
-}
-
-/*! add extension 6123,1,Dial,IAX/212.71.138.13/6123 into local */
-static char *complete_context_add_extension(char *line, char *word,
- int pos, int state)
-{
- int which = 0;
-
- /* complete 'into' word ... */
- if (pos == 3) {
- if (state == 0) return strdup("into");
- return NULL;
- }
-
- /* complete context */
- if (pos == 4) {
- struct ast_context *c;
-
- /* try to lock contexts list ... */
- if (ast_lock_contexts()) {
- ast_log(LOG_WARNING, "Failed to lock contexts list\n");
- return NULL;
- }
-
- /* walk through all contexts */
- c = ast_walk_contexts(NULL);
- while (c) {
- /* matching context? */
- if (!strncmp(ast_get_context_name(c), word, strlen(word))) {
- if (++which > state) {
- char *res = strdup(ast_get_context_name(c));
- ast_unlock_contexts();
- return res;
- }
- }
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
- return NULL;
- }
-
- if (pos == 5) return state == 0 ? strdup("replace") : NULL;
-
- return NULL;
-}
-
-/*!
- * IGNOREPAT CLI stuff
- */
-static int handle_context_add_ignorepat(int fd, int argc, char *argv[])
-{
- if (argc != 5) return RESULT_SHOWUSAGE;
- if (strcmp(argv[3], "into")) return RESULT_SHOWUSAGE;
-
- if (ast_context_add_ignorepat(argv[4], argv[2], registrar)) {
- switch (errno) {
- case ENOMEM:
- ast_cli(fd, "Out of free memory\n"); break;
-
- case ENOENT:
- ast_cli(fd, "There is no existence of '%s' context\n", argv[4]);
- break;
-
- case EEXIST:
- ast_cli(fd, "Ignore pattern '%s' already included in '%s' context\n",
- argv[2], argv[4]);
- break;
-
- case EBUSY:
- ast_cli(fd, "Failed to lock context(s) list, please, try again later\n");
- break;
-
- default:
- ast_cli(fd, "Failed to add ingore pattern '%s' into '%s' context\n",
- argv[2], argv[4]);
- break;
- }
- return RESULT_FAILURE;
- }
-
- ast_cli(fd, "Ignore pattern '%s' added into '%s' context\n",
- argv[2], argv[4]);
- return RESULT_SUCCESS;
-}
-
-static char *complete_context_add_ignorepat(char *line, char *word,
- int pos, int state)
-{
- if (pos == 3) return state == 0 ? strdup("into") : NULL;
-
- if (pos == 4) {
- struct ast_context *c;
- int which = 0;
- char *dupline, *duplinet, *ignorepat = NULL;
-
- dupline = strdup(line);
- duplinet = dupline;
-
- if (duplinet) {
- strsep(&duplinet, " "); /* skip 'add' */
- strsep(&duplinet, " "); /* skip 'ignorepat' */
- ignorepat = strsep(&duplinet, " ");
- }
-
- if (ast_lock_contexts()) {
- ast_log(LOG_ERROR, "Failed to lock contexts list\n");
- return NULL;
- }
-
- c = ast_walk_contexts(NULL);
- while (c) {
- if (!strncmp(ast_get_context_name(c), word, strlen(word))) {
- int serve_context = 1;
- if (ignorepat) {
- if (!ast_lock_context(c)) {
- struct ast_ignorepat *ip;
- ip = ast_walk_context_ignorepats(c, NULL);
- while (ip && serve_context) {
- if (!strcmp(ast_get_ignorepat_name(ip), ignorepat))
- serve_context = 0;
- ip = ast_walk_context_ignorepats(c, ip);
- }
- ast_unlock_context(c);
- }
- }
- if (serve_context) {
- if (++which > state) {
- char *context = strdup(ast_get_context_name(c));
- if (dupline) free(dupline);
- ast_unlock_contexts();
- return context;
- }
- }
- }
- c = ast_walk_contexts(c);
- }
-
- if (dupline) free(dupline);
- ast_unlock_contexts();
- return NULL;
- }
-
- return NULL;
-}
-
-static int handle_context_remove_ignorepat(int fd, int argc, char *argv[])
-{
- if (argc != 5) return RESULT_SHOWUSAGE;
- if (strcmp(argv[3], "from")) return RESULT_SHOWUSAGE;
-
- if (ast_context_remove_ignorepat(argv[4], argv[2], registrar)) {
- switch (errno) {
- case EBUSY:
- ast_cli(fd, "Failed to lock context(s) list, please try again later\n");
- break;
-
- case ENOENT:
- ast_cli(fd, "There is no existence of '%s' context\n", argv[4]);
- break;
-
- case EINVAL:
- ast_cli(fd, "There is no existence of '%s' ignore pattern in '%s' context\n",
- argv[2], argv[4]);
- break;
-
- default:
- ast_cli(fd, "Failed to remove ignore pattern '%s' from '%s' context\n", argv[2], argv[4]);
- break;
- }
- return RESULT_FAILURE;
- }
-
- ast_cli(fd, "Ignore pattern '%s' removed from '%s' context\n",
- argv[2], argv[4]);
- return RESULT_SUCCESS;
-}
-
-static int pbx_load_module(void);
-
-static int handle_reload_extensions(int fd, int argc, char *argv[])
-{
- if (argc!=2) return RESULT_SHOWUSAGE;
- pbx_load_module();
- return RESULT_SUCCESS;
-}
-
-static char *complete_context_remove_ignorepat(char *line, char *word,
- int pos, int state)
-{
- struct ast_context *c;
- int which = 0;
-
- if (pos == 2) {
- if (ast_lock_contexts()) {
- ast_log(LOG_WARNING, "Failed to lock contexts list\n");
- return NULL;
- }
-
- c = ast_walk_contexts(NULL);
- while (c) {
- if (!ast_lock_context(c)) {
- struct ast_ignorepat *ip;
-
- ip = ast_walk_context_ignorepats(c, NULL);
- while (ip) {
- if (!strncmp(ast_get_ignorepat_name(ip), word, strlen(word))) {
- if (which + 1 > state) {
- struct ast_context *cw;
- int already_served = 0;
- cw = ast_walk_contexts(NULL);
- while (cw && cw != c && !already_served) {
- if (!ast_lock_context(cw)) {
- struct ast_ignorepat *ipw;
- ipw = ast_walk_context_ignorepats(cw, NULL);
- while (ipw) {
- if (!strcmp(ast_get_ignorepat_name(ipw),
- ast_get_ignorepat_name(ip))) already_served = 1;
- ipw = ast_walk_context_ignorepats(cw, ipw);
- }
- ast_unlock_context(cw);
- }
- cw = ast_walk_contexts(cw);
- }
- if (!already_served) {
- char *ret = strdup(ast_get_ignorepat_name(ip));
- ast_unlock_context(c);
- ast_unlock_contexts();
- return ret;
- }
- } else
- which++;
- }
- ip = ast_walk_context_ignorepats(c, ip);
- }
-
- ast_unlock_context(c);
- }
- c = ast_walk_contexts(c);
- }
-
- ast_unlock_contexts();
- return NULL;
- }
-
- if (pos == 3) return state == 0 ? strdup("from") : NULL;
-
- if (pos == 4) {
- char *dupline, *duplinet, *ignorepat;
-
- dupline = strdup(line);
- if (!dupline) {
- ast_log(LOG_WARNING, "Out of free memory\n");
- return NULL;
- }
-
- duplinet = dupline;
- strsep(&duplinet, " ");
- strsep(&duplinet, " ");
- ignorepat = strsep(&duplinet, " ");
-
- if (!ignorepat) {
- free(dupline);
- return NULL;
- }
-
- if (ast_lock_contexts()) {
- ast_log(LOG_WARNING, "Failed to lock contexts list\n");
- free(dupline);
- return NULL;
- }
-
- c = ast_walk_contexts(NULL);
- while (c) {
- if (!ast_lock_context(c)) {
- struct ast_ignorepat *ip;
- ip = ast_walk_context_ignorepats(c, NULL);
- while (ip) {
- if (!strcmp(ast_get_ignorepat_name(ip), ignorepat)) {
- if (!strncmp(ast_get_context_name(c), word, strlen(word))) {
- if (++which > state) {
- char *ret = strdup(ast_get_context_name(c));
- free(dupline);
- ast_unlock_context(c);
- ast_unlock_contexts();
- return ret;
- }
- }
- }
- ip = ast_walk_context_ignorepats(c, ip);
- }
-
- ast_unlock_context(c);
- }
- c = ast_walk_contexts(c);
- }
-
- free(dupline);
- ast_unlock_contexts();
- return NULL;
- }
-
- return NULL;
-}
-
-/*!
- * CLI entries for commands provided by this module
- */
-static struct ast_cli_entry context_dont_include_cli =
- { { "dont", "include", NULL }, handle_context_dont_include,
- "Remove a specified include from context", context_dont_include_help,
- complete_context_dont_include };
-
-static struct ast_cli_entry context_remove_extension_cli =
- { { "remove", "extension", NULL }, handle_context_remove_extension,
- "Remove a specified extension", context_remove_extension_help,
- complete_context_remove_extension };
-
-static struct ast_cli_entry context_add_include_cli =
- { { "include", "context", NULL }, handle_context_add_include,
- "Include context in other context", context_add_include_help,
- complete_context_add_include };
-
-static struct ast_cli_entry save_dialplan_cli =
- { { "save", "dialplan", NULL }, handle_save_dialplan,
- "Save dialplan", save_dialplan_help };
-
-static struct ast_cli_entry context_add_extension_cli =
- { { "add", "extension", NULL }, handle_context_add_extension,
- "Add new extension into context", context_add_extension_help,
- complete_context_add_extension };
-
-static struct ast_cli_entry context_add_ignorepat_cli =
- { { "add", "ignorepat", NULL }, handle_context_add_ignorepat,
- "Add new ignore pattern", context_add_ignorepat_help,
- complete_context_add_ignorepat };
-
-static struct ast_cli_entry context_remove_ignorepat_cli =
- { { "remove", "ignorepat", NULL }, handle_context_remove_ignorepat,
- "Remove ignore pattern from context", context_remove_ignorepat_help,
- complete_context_remove_ignorepat };
-
-static struct ast_cli_entry reload_extensions_cli =
- { { "extensions", "reload", NULL}, handle_reload_extensions,
- "Reload extensions and *only* extensions", reload_extensions_help };
-
-/*!
- * Standard module functions ...
- */
-int unload_module(void)
-{
- ast_cli_unregister(&context_add_extension_cli);
- if (static_config && !write_protect_config)
- ast_cli_unregister(&save_dialplan_cli);
- ast_cli_unregister(&context_add_include_cli);
- ast_cli_unregister(&context_dont_include_cli);
- ast_cli_unregister(&context_remove_extension_cli);
- ast_cli_unregister(&context_remove_ignorepat_cli);
- ast_cli_unregister(&context_add_ignorepat_cli);
- ast_cli_unregister(&reload_extensions_cli);
- ast_context_destroy(NULL, registrar);
- return 0;
-}
-
-static int pbx_load_module(void)
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- char *cxt, *ext, *pri, *appl, *data, *tc, *cidmatch;
- struct ast_context *con;
- char *end;
- char *label;
- char realvalue[256];
- int lastpri = -2;
-
- cfg = ast_config_load(config);
- if (cfg) {
- /* Use existing config to populate the PBX table */
- static_config = ast_true(ast_variable_retrieve(cfg, "general",
- "static"));
- write_protect_config = ast_true(ast_variable_retrieve(cfg, "general",
- "writeprotect"));
- autofallthrough_config = ast_true(ast_variable_retrieve(cfg, "general",
- "autofallthrough"));
- clearglobalvars_config = ast_true(ast_variable_retrieve(cfg, "general",
- "clearglobalvars"));
- option_priority_jumping = !ast_false(ast_variable_retrieve(cfg, "general",
- "priorityjumping"));
-
- v = ast_variable_browse(cfg, "globals");
- while(v) {
- memset(realvalue, 0, sizeof(realvalue));
- pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
- pbx_builtin_setvar_helper(NULL, v->name, realvalue);
- v = v->next;
- }
- cxt = ast_category_browse(cfg, NULL);
- while(cxt) {
- /* All categories but "general" or "globals" are considered contexts */
- if (!strcasecmp(cxt, "general") || !strcasecmp(cxt, "globals")) {
- cxt = ast_category_browse(cfg, cxt);
- continue;
- }
- if ((con=ast_context_create(&local_contexts,cxt, registrar))) {
- v = ast_variable_browse(cfg, cxt);
- while(v) {
- if (!strcasecmp(v->name, "exten")) {
- char *stringp=NULL;
- int ipri = -2;
- char realext[256]="";
- char *plus, *firstp, *firstc;
- tc = strdup(v->value);
- if(tc!=NULL){
- stringp=tc;
- ext = strsep(&stringp, ",");
- if (!ext)
- ext="";
- pbx_substitute_variables_helper(NULL, ext, realext, sizeof(realext) - 1);
- cidmatch = strchr(realext, '/');
- if (cidmatch) {
- *cidmatch = '\0';
- cidmatch++;
- ast_shrink_phone_number(cidmatch);
- }
- pri = strsep(&stringp, ",");
- if (!pri)
- pri="";
- label = strchr(pri, '(');
- if (label) {
- *label = '\0';
- label++;
- end = strchr(label, ')');
- if (end)
- *end = '\0';
- else
- ast_log(LOG_WARNING, "Label missing trailing ')' at line %d\n", v->lineno);
- }
- plus = strchr(pri, '+');
- if (plus) {
- *plus = '\0';
- plus++;
- }
- if (!strcmp(pri,"hint"))
- ipri=PRIORITY_HINT;
- else if (!strcmp(pri, "next") || !strcmp(pri, "n")) {
- if (lastpri > -2)
- ipri = lastpri + 1;
- else
- ast_log(LOG_WARNING, "Can't use 'next' priority on the first entry!\n");
- } else if (!strcmp(pri, "same") || !strcmp(pri, "s")) {
- if (lastpri > -2)
- ipri = lastpri;
- else
- ast_log(LOG_WARNING, "Can't use 'same' priority on the first entry!\n");
- } else {
- if (sscanf(pri, "%d", &ipri) != 1) {
- if ((ipri = ast_findlabel_extension2(NULL, con, realext, pri, cidmatch)) < 1) {
- ast_log(LOG_WARNING, "Invalid priority/label '%s' at line %d\n", pri, v->lineno);
- ipri = 0;
- }
- }
- }
- appl = stringp;
- if (!appl)
- appl="";
- /* Find the first occurrence of either '(' or ',' */
- firstc = strchr(appl, ',');
- firstp = strchr(appl, '(');
- if (firstc && ((!firstp) || (firstc < firstp))) {
- /* comma found, no parenthesis */
- /* or both found, but comma found first */
- appl = strsep(&stringp, ",");
- data = stringp;
- } else if ((!firstc) && (!firstp)) {
- /* Neither found */
- data = "";
- } else {
- /* Final remaining case is parenthesis found first */
- appl = strsep(&stringp, "(");
- data = stringp;
- end = strrchr(data, ')');
- if ((end = strrchr(data, ')'))) {
- *end = '\0';
- } else {
- ast_log(LOG_WARNING, "No closing parenthesis found? '%s(%s'\n", appl, data);
- }
- ast_process_quotes_and_slashes(data, ',', '|');
- }
-
- if (!data)
- data="";
- while(*appl && (*appl < 33)) appl++;
- if (ipri) {
- if (plus)
- ipri += atoi(plus);
- lastpri = ipri;
- if(!option_dontwarn) {
- if (!strcmp(realext, "_."))
- ast_log(LOG_WARNING, "The use of '_.' for an extension is strongly discouraged and can have unexpected behavior. Please use '_X.' instead at line %d\n", v->lineno);
- }
- if (ast_add_extension2(con, 0, realext, ipri, label, cidmatch, appl, strdup(data), FREE, registrar)) {
- ast_log(LOG_WARNING, "Unable to register extension at line %d\n", v->lineno);
- }
- }
- free(tc);
- } else fprintf(stderr,"Error strdup returned NULL in %s\n",__PRETTY_FUNCTION__);
- } else if(!strcasecmp(v->name, "include")) {
- memset(realvalue, 0, sizeof(realvalue));
- pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
- if (ast_context_add_include2(con, realvalue, registrar))
- ast_log(LOG_WARNING, "Unable to include context '%s' in context '%s'\n", v->value, cxt);
- } else if(!strcasecmp(v->name, "ignorepat")) {
- memset(realvalue, 0, sizeof(realvalue));
- pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
- if (ast_context_add_ignorepat2(con, realvalue, registrar))
- ast_log(LOG_WARNING, "Unable to include ignorepat '%s' in context '%s'\n", v->value, cxt);
- } else if (!strcasecmp(v->name, "switch") || !strcasecmp(v->name, "lswitch") || !strcasecmp(v->name, "eswitch")) {
- char *stringp=NULL;
- memset(realvalue, 0, sizeof(realvalue));
- if (!strcasecmp(v->name, "switch"))
- pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
- else
- strncpy(realvalue, v->value, sizeof(realvalue) - 1);
- tc = realvalue;
- stringp=tc;
- appl = strsep(&stringp, "/");
- data = strsep(&stringp, "");
- if (!data)
- data = "";
- if (ast_context_add_switch2(con, appl, data, !strcasecmp(v->name, "eswitch"), registrar))
- ast_log(LOG_WARNING, "Unable to include switch '%s' in context '%s'\n", v->value, cxt);
- }
- v = v->next;
- }
- }
- cxt = ast_category_browse(cfg, cxt);
- }
- ast_config_destroy(cfg);
- }
- ast_merge_contexts_and_delete(&local_contexts,registrar);
-
- for (con = ast_walk_contexts(NULL); con; con = ast_walk_contexts(con))
- ast_context_verify_includes(con);
-
- pbx_set_autofallthrough(autofallthrough_config);
-
- return 0;
-}
-
-int load_module(void)
-{
- if (pbx_load_module()) return -1;
-
- ast_cli_register(&context_remove_extension_cli);
- ast_cli_register(&context_dont_include_cli);
- ast_cli_register(&context_add_include_cli);
- if (static_config && !write_protect_config)
- ast_cli_register(&save_dialplan_cli);
- ast_cli_register(&context_add_extension_cli);
- ast_cli_register(&context_add_ignorepat_cli);
- ast_cli_register(&context_remove_ignorepat_cli);
- ast_cli_register(&reload_extensions_cli);
-
- return 0;
-}
-
-int reload(void)
-{
- ast_context_destroy(NULL, registrar);
- if (clearglobalvars_config)
- pbx_builtin_clear_globals();
- pbx_load_module();
- return 0;
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *description(void)
-{
- return dtext;
-}
-
-char *key(void)
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/pbx/pbx_dundi.c b/1.2-netsec/pbx/pbx_dundi.c
deleted file mode 100644
index 8f0457296..000000000
--- a/1.2-netsec/pbx/pbx_dundi.c
+++ /dev/null
@@ -1,4831 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Distributed Universal Number Discovery (DUNDi)
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <errno.h>
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(SOLARIS) || defined(__Darwin__)
-#include <sys/types.h>
-#include <netinet/in_systm.h>
-#endif
-#include <netinet/ip.h>
-#include <sys/ioctl.h>
-#include <netinet/in.h>
-#include <net/if.h>
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__)
-#include <net/if_dl.h>
-#include <ifaddrs.h>
-#endif
-#include <zlib.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/frame.h"
-#include "asterisk/file.h"
-#include "asterisk/cli.h"
-#include "asterisk/lock.h"
-#include "asterisk/md5.h"
-#include "asterisk/dundi.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/utils.h"
-#include "asterisk/crypto.h"
-#include "asterisk/astdb.h"
-#include "asterisk/acl.h"
-#include "asterisk/aes.h"
-
-#include "dundi-parser.h"
-
-#define MAX_RESULTS 64
-
-#define MAX_PACKET_SIZE 8192
-
-extern char ast_config_AST_KEY_DIR[];
-
-static char *tdesc = "Distributed Universal Number Discovery (DUNDi)";
-
-static char *app = "DUNDiLookup";
-static char *synopsis = "Look up a number with DUNDi";
-static char *descrip =
-"DUNDiLookup(number[|context[|options]])\n"
-" Looks up a given number in the global context specified or in\n"
-"the reserved 'e164' context if not specified. Returns -1 if the channel\n"
-"is hungup during the lookup or 0 otherwise. On completion, the variable\n"
-"${DUNDTECH} and ${DUNDDEST} will contain the technology and destination\n"
-"of the appropriate technology and destination to access the number. If no\n"
-"answer was found, and the priority n + 101 exists, execution will continue\n"
-"at that location. Note that this will only occur if the global priority\n"
-"jumping option is enabled in extensions.conf. If the 'b' option is specified,\n"
-"the internal DUNDi cache will by bypassed.\n";
-
-#define DUNDI_MODEL_INBOUND (1 << 0)
-#define DUNDI_MODEL_OUTBOUND (1 << 1)
-#define DUNDI_MODEL_SYMMETRIC (DUNDI_MODEL_INBOUND | DUNDI_MODEL_OUTBOUND)
-
-/* Keep times of last 10 lookups */
-#define DUNDI_TIMING_HISTORY 10
-
-#define FLAG_ISREG (1 << 0) /* Transaction is register request */
-#define FLAG_DEAD (1 << 1) /* Transaction is dead */
-#define FLAG_FINAL (1 << 2) /* Transaction has final message sent */
-#define FLAG_ISQUAL (1 << 3) /* Transaction is a qualification */
-#define FLAG_ENCRYPT (1 << 4) /* Transaction is encrypted wiht ECX/DCX */
-#define FLAG_SENDFULLKEY (1 << 5) /* Send full key on transaction */
-#define FLAG_STOREHIST (1 << 6) /* Record historic performance */
-
-#define DUNDI_FLAG_INTERNAL_NOPARTIAL (1 << 17)
-
-#if 0
-#define DUNDI_SECRET_TIME 15 /* Testing only */
-#else
-#define DUNDI_SECRET_TIME DUNDI_DEFAULT_CACHE_TIME
-#endif
-
-#define KEY_OUT 0
-#define KEY_IN 1
-
-static struct io_context *io;
-static struct sched_context *sched;
-static int netsocket = -1;
-static pthread_t netthreadid = AST_PTHREADT_NULL;
-static pthread_t precachethreadid = AST_PTHREADT_NULL;
-static int tos = 0;
-static int dundidebug = 0;
-static int authdebug = 0;
-static int dundi_ttl = DUNDI_DEFAULT_TTL;
-static int dundi_key_ttl = DUNDI_DEFAULT_KEY_EXPIRE;
-static int dundi_cache_time = DUNDI_DEFAULT_CACHE_TIME;
-static int global_autokilltimeout = 0;
-static dundi_eid global_eid;
-static int default_expiration = 60;
-static int global_storehistory = 0;
-static char dept[80];
-static char org[80];
-static char locality[80];
-static char stateprov[80];
-static char country[80];
-static char email[80];
-static char phone[80];
-static char secretpath[80];
-static char cursecret[80];
-static char ipaddr[80];
-static time_t rotatetime;
-static dundi_eid empty_eid = { { 0, 0, 0, 0, 0, 0 } };
-struct permission {
- struct permission *next;
- int allow;
- char name[0];
-};
-
-struct dundi_packet {
- struct dundi_hdr *h;
- struct dundi_packet *next;
- int datalen;
- struct dundi_transaction *parent;
- int retransid;
- int retrans;
- unsigned char data[0];
-};
-
-struct dundi_hint_metadata {
- unsigned short flags;
- char exten[AST_MAX_EXTENSION];
-};
-
-struct dundi_precache_queue {
- struct dundi_precache_queue *next;
- char *context;
- time_t expiration;
- char number[0];
-};
-
-struct dundi_request;
-
-struct dundi_transaction {
- struct sockaddr_in addr; /* Other end of transaction */
- struct timeval start; /* When this transaction was created */
- dundi_eid eids[DUNDI_MAX_STACK + 1];
- int eidcount; /* Number of eids in eids */
- dundi_eid us_eid; /* Our EID, to them */
- dundi_eid them_eid; /* Their EID, to us */
- aes_encrypt_ctx ecx; /* AES 128 Encryption context */
- aes_decrypt_ctx dcx; /* AES 128 Decryption context */
- unsigned int flags; /* Has final packet been sent */
- int ttl; /* Remaining TTL for queries on this one */
- int thread; /* We have a calling thread */
- int retranstimer; /* How long to wait before retransmissions */
- int autokillid; /* ID to kill connection if answer doesn't come back fast enough */
- int autokilltimeout; /* Recommended timeout for autokill */
- unsigned short strans; /* Our transaction identifier */
- unsigned short dtrans; /* Their transaction identifer */
- unsigned char iseqno; /* Next expected received seqno */
- unsigned char oiseqno; /* Last received incoming seqno */
- unsigned char oseqno; /* Next transmitted seqno */
- unsigned char aseqno; /* Last acknowledge seqno */
- struct dundi_packet *packets; /* Packets to be retransmitted */
- struct dundi_packet *lasttrans; /* Last transmitted / ACK'd packet */
- struct dundi_transaction *next; /* Next with respect to the parent */
- struct dundi_request *parent; /* Parent request (if there is one) */
- struct dundi_transaction *allnext; /* Next with respect to all DUNDi transactions */
-} *alltrans;
-
-struct dundi_request {
- char dcontext[AST_MAX_EXTENSION];
- char number[AST_MAX_EXTENSION];
- dundi_eid query_eid;
- dundi_eid root_eid;
- struct dundi_result *dr;
- struct dundi_entity_info *dei;
- struct dundi_hint_metadata *hmd;
- int maxcount;
- int respcount;
- int expiration;
- int cbypass;
- int pfds[2];
- unsigned long crc32; /* CRC-32 of all but root EID's in avoid list */
- struct dundi_transaction *trans; /* Transactions */
- struct dundi_request *next;
-} *requests;
-
-static struct dundi_mapping {
- char dcontext[AST_MAX_EXTENSION];
- char lcontext[AST_MAX_EXTENSION];
- int weight;
- int options;
- int tech;
- int dead;
- char dest[AST_MAX_EXTENSION];
- struct dundi_mapping *next;
-} *mappings = NULL;
-
-static struct dundi_peer {
- dundi_eid eid;
- struct sockaddr_in addr; /* Address of DUNDi peer */
- struct permission *permit;
- struct permission *include;
- struct permission *precachesend;
- struct permission *precachereceive;
- dundi_eid us_eid;
- char inkey[80];
- char outkey[80];
- int dead;
- int registerid;
- int qualifyid;
- int sentfullkey;
- int order;
- unsigned char txenckey[256]; /* Transmitted encrypted key + sig */
- unsigned char rxenckey[256]; /* Cache received encrypted key + sig */
- unsigned long us_keycrc32; /* CRC-32 of our key */
- aes_encrypt_ctx us_ecx; /* Cached AES 128 Encryption context */
- aes_decrypt_ctx us_dcx; /* Cached AES 128 Decryption context */
- unsigned long them_keycrc32;/* CRC-32 of our key */
- aes_encrypt_ctx them_ecx; /* Cached AES 128 Encryption context */
- aes_decrypt_ctx them_dcx; /* Cached AES 128 Decryption context */
- time_t keyexpire; /* When to expire/recreate key */
- int registerexpire;
- int lookuptimes[DUNDI_TIMING_HISTORY];
- char *lookups[DUNDI_TIMING_HISTORY];
- int avgms;
- struct dundi_transaction *regtrans; /* Registration transaction */
- struct dundi_transaction *qualtrans; /* Qualify transaction */
- struct dundi_transaction *keypending;
- int model; /* Pull model */
- int pcmodel; /* Push/precache model */
- int dynamic; /* Are we dynamic? */
- int lastms; /* Last measured latency */
- int maxms; /* Max permissible latency */
- struct timeval qualtx; /* Time of transmit */
- struct dundi_peer *next;
-} *peers;
-
-static struct dundi_precache_queue *pcq;
-
-AST_MUTEX_DEFINE_STATIC(peerlock);
-AST_MUTEX_DEFINE_STATIC(pclock);
-
-static int dundi_xmit(struct dundi_packet *pack);
-
-static void dundi_debug_output(const char *data)
-{
- if (dundidebug)
- ast_verbose("%s", data);
-}
-
-static void dundi_error_output(const char *data)
-{
- ast_log(LOG_WARNING, "%s", data);
-}
-
-static int has_permission(struct permission *ps, char *cont)
-{
- int res=0;
- while(ps) {
- if (!strcasecmp(ps->name, "all") || !strcasecmp(ps->name, cont))
- res = ps->allow;
- ps = ps->next;
- }
- return res;
-}
-
-static char *tech2str(int tech)
-{
- switch(tech) {
- case DUNDI_PROTO_NONE:
- return "None";
- case DUNDI_PROTO_IAX:
- return "IAX2";
- case DUNDI_PROTO_SIP:
- return "SIP";
- case DUNDI_PROTO_H323:
- return "H323";
- default:
- return "Unknown";
- }
-}
-
-static int str2tech(char *str)
-{
- if (!strcasecmp(str, "IAX") || !strcasecmp(str, "IAX2"))
- return DUNDI_PROTO_IAX;
- else if (!strcasecmp(str, "SIP"))
- return DUNDI_PROTO_SIP;
- else if (!strcasecmp(str, "H323"))
- return DUNDI_PROTO_H323;
- else
- return -1;
-}
-
-static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct ast_channel *chan, const char *dcontext, const char *number, int ttl, int blockempty, struct dundi_hint_metadata *md, int *expiration, int cybpass, int modeselect, dundi_eid *skip, dundi_eid *avoid[], int direct[]);
-static int dundi_precache_internal(const char *context, const char *number, int ttl, dundi_eid *avoids[]);
-static struct dundi_transaction *create_transaction(struct dundi_peer *p);
-static struct dundi_transaction *find_transaction(struct dundi_hdr *hdr, struct sockaddr_in *sin)
-{
- /* Look for an exact match first */
- struct dundi_transaction *trans;
- trans = alltrans;
- while(trans) {
- if (!inaddrcmp(&trans->addr, sin) &&
- ((trans->strans == (ntohs(hdr->dtrans) & 32767)) /* Matches our destination */ ||
- ((trans->dtrans == (ntohs(hdr->strans) & 32767)) && (!hdr->dtrans))) /* We match their destination */) {
- if (hdr->strans)
- trans->dtrans = ntohs(hdr->strans) & 32767;
- break;
- }
- trans = trans->allnext;
- }
- if (!trans) {
- switch(hdr->cmdresp & 0x7f) {
- case DUNDI_COMMAND_DPDISCOVER:
- case DUNDI_COMMAND_EIDQUERY:
- case DUNDI_COMMAND_PRECACHERQ:
- case DUNDI_COMMAND_REGREQ:
- case DUNDI_COMMAND_NULL:
- case DUNDI_COMMAND_ENCRYPT:
- if (hdr->strans) {
- /* Create new transaction */
- trans = create_transaction(NULL);
- if (trans) {
- memcpy(&trans->addr, sin, sizeof(trans->addr));
- trans->dtrans = ntohs(hdr->strans) & 32767;
- } else
- ast_log(LOG_WARNING, "Out of memory!\n");
- }
- break;
- default:
- break;
- }
- }
- return trans;
-}
-
-static int dundi_send(struct dundi_transaction *trans, int cmdresp, int flags, int final, struct dundi_ie_data *ied);
-
-static int dundi_ack(struct dundi_transaction *trans, int final)
-{
- return dundi_send(trans, DUNDI_COMMAND_ACK, 0, final, NULL);
-}
-static void dundi_reject(struct dundi_hdr *h, struct sockaddr_in *sin)
-{
- struct {
- struct dundi_packet pack;
- struct dundi_hdr hdr;
- } tmp;
- struct dundi_transaction trans;
- /* Never respond to an INVALID with another INVALID */
- if (h->cmdresp == DUNDI_COMMAND_INVALID)
- return;
- memset(&tmp, 0, sizeof(tmp));
- memset(&trans, 0, sizeof(trans));
- memcpy(&trans.addr, sin, sizeof(trans.addr));
- tmp.hdr.strans = h->dtrans;
- tmp.hdr.dtrans = h->strans;
- tmp.hdr.iseqno = h->oseqno;
- tmp.hdr.oseqno = h->iseqno;
- tmp.hdr.cmdresp = DUNDI_COMMAND_INVALID;
- tmp.hdr.cmdflags = 0;
- tmp.pack.h = (struct dundi_hdr *)tmp.pack.data;
- tmp.pack.datalen = sizeof(struct dundi_hdr);
- tmp.pack.parent = &trans;
- dundi_xmit(&tmp.pack);
-}
-
-static void reset_global_eid(void)
-{
-#if defined(SIOCGIFHWADDR)
- int x,s;
- char eid_str[20];
- struct ifreq ifr;
-
- s = socket(AF_INET, SOCK_STREAM, 0);
- if (s > 0) {
- x = 0;
- for(x=0;x<10;x++) {
- memset(&ifr, 0, sizeof(ifr));
- snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth%d", x);
- if (!ioctl(s, SIOCGIFHWADDR, &ifr)) {
- memcpy(&global_eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(global_eid));
- ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid), ifr.ifr_name);
- close(s);
- return;
- }
- }
- close(s);
- }
-#else
-#if defined(ifa_broadaddr) && !defined(SOLARIS)
- char eid_str[20];
- struct ifaddrs *ifap;
-
- if (getifaddrs(&ifap) == 0) {
- struct ifaddrs *p;
- for (p = ifap; p; p = p->ifa_next) {
- if (p->ifa_addr->sa_family == AF_LINK) {
- struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr;
- memcpy(
- &(global_eid.eid),
- sdp->sdl_data + sdp->sdl_nlen, 6);
- ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid), ifap->ifa_name);
- freeifaddrs(ifap);
- return;
- }
- }
- freeifaddrs(ifap);
- }
-#endif
-#endif
- ast_log(LOG_NOTICE, "No ethernet interface found for seeding global EID You will have to set it manually.\n");
-}
-
-static int get_trans_id(void)
-{
- struct dundi_transaction *t;
- int stid = (rand() % 32766) + 1;
- int tid = stid;
- do {
- t = alltrans;
- while(t) {
- if (t->strans == tid)
- break;
- t = t->allnext;
- }
- if (!t)
- return tid;
- tid = (tid % 32766) + 1;
- } while (tid != stid);
- return 0;
-}
-
-static int reset_transaction(struct dundi_transaction *trans)
-{
- int tid;
- tid = get_trans_id();
- if (tid < 1)
- return -1;
- trans->strans = tid;
- trans->dtrans = 0;
- trans->iseqno = 0;
- trans->oiseqno = 0;
- trans->oseqno = 0;
- trans->aseqno = 0;
- ast_clear_flag(trans, FLAG_FINAL);
- return 0;
-}
-
-static struct dundi_peer *find_peer(dundi_eid *eid)
-{
- struct dundi_peer *cur;
- if (!eid)
- eid = &empty_eid;
- cur = peers;
- while(cur) {
- if (!dundi_eid_cmp(&cur->eid,eid))
- return cur;
- cur = cur->next;
- }
- return NULL;
-}
-
-static void build_iv(unsigned char *iv)
-{
- /* XXX Would be nice to be more random XXX */
- unsigned int *fluffy;
- int x;
- fluffy = (unsigned int *)(iv);
- for (x=0;x<4;x++)
- fluffy[x] = rand();
-}
-
-struct dundi_query_state {
- dundi_eid *eids[DUNDI_MAX_STACK + 1];
- int directs[DUNDI_MAX_STACK + 1];
- dundi_eid reqeid;
- char called_context[AST_MAX_EXTENSION];
- char called_number[AST_MAX_EXTENSION];
- struct dundi_mapping *maps;
- int nummaps;
- int nocache;
- struct dundi_transaction *trans;
- void *chal;
- int challen;
- int ttl;
- char fluffy[0];
-};
-
-static int dundi_lookup_local(struct dundi_result *dr, struct dundi_mapping *map, char *called_number, dundi_eid *us_eid, int anscnt, struct dundi_hint_metadata *hmd)
-{
- struct ast_flags flags = {0};
- int x;
- if (!ast_strlen_zero(map->lcontext)) {
- if (ast_exists_extension(NULL, map->lcontext, called_number, 1, NULL))
- ast_set_flag(&flags, DUNDI_FLAG_EXISTS);
- if (ast_canmatch_extension(NULL, map->lcontext, called_number, 1, NULL))
- ast_set_flag(&flags, DUNDI_FLAG_CANMATCH);
- if (ast_matchmore_extension(NULL, map->lcontext, called_number, 1, NULL))
- ast_set_flag(&flags, DUNDI_FLAG_MATCHMORE);
- if (ast_ignore_pattern(map->lcontext, called_number))
- ast_set_flag(&flags, DUNDI_FLAG_IGNOREPAT);
-
- /* Clearly we can't say 'don't ask' anymore if we found anything... */
- if (ast_test_flag(&flags, AST_FLAGS_ALL))
- ast_clear_flag_nonstd(hmd, DUNDI_HINT_DONT_ASK);
-
- if (map->options & DUNDI_FLAG_INTERNAL_NOPARTIAL) {
- /* Skip partial answers */
- ast_clear_flag(&flags, DUNDI_FLAG_MATCHMORE|DUNDI_FLAG_CANMATCH);
- }
- if (ast_test_flag(&flags, AST_FLAGS_ALL)) {
- struct varshead headp;
- struct ast_var_t *newvariable;
- ast_set_flag(&flags, map->options & 0xffff);
- ast_copy_flags(dr + anscnt, &flags, AST_FLAGS_ALL);
- dr[anscnt].techint = map->tech;
- dr[anscnt].weight = map->weight;
- dr[anscnt].expiration = dundi_cache_time;
- ast_copy_string(dr[anscnt].tech, tech2str(map->tech), sizeof(dr[anscnt].tech));
- dr[anscnt].eid = *us_eid;
- dundi_eid_to_str(dr[anscnt].eid_str, sizeof(dr[anscnt].eid_str), &dr[anscnt].eid);
- if (ast_test_flag(&flags, DUNDI_FLAG_EXISTS)) {
- AST_LIST_HEAD_INIT_NOLOCK(&headp);
- newvariable = ast_var_assign("NUMBER", called_number);
- AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
- newvariable = ast_var_assign("EID", dr[anscnt].eid_str);
- AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
- newvariable = ast_var_assign("SECRET", cursecret);
- AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
- newvariable = ast_var_assign("IPADDR", ipaddr);
- AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
- pbx_substitute_variables_varshead(&headp, map->dest, dr[anscnt].dest, sizeof(dr[anscnt].dest));
- while (!AST_LIST_EMPTY(&headp)) { /* List Deletion. */
- newvariable = AST_LIST_REMOVE_HEAD(&headp, entries);
- ast_var_delete(newvariable);
- }
- } else
- dr[anscnt].dest[0] = '\0';
- anscnt++;
- } else {
- /* No answers... Find the fewest number of digits from the
- number for which we have no answer. */
- char tmp[AST_MAX_EXTENSION];
- for (x=0;x<AST_MAX_EXTENSION;x++) {
- tmp[x] = called_number[x];
- if (!tmp[x])
- break;
- if (!ast_canmatch_extension(NULL, map->lcontext, tmp, 1, NULL)) {
- /* Oops found something we can't match. If this is longer
- than the running hint, we have to consider it */
- if (strlen(tmp) > strlen(hmd->exten)) {
- ast_copy_string(hmd->exten, tmp, sizeof(hmd->exten));
- }
- break;
- }
- }
- }
- }
- return anscnt;
-}
-
-static void destroy_trans(struct dundi_transaction *trans, int fromtimeout);
-
-static void *dundi_lookup_thread(void *data)
-{
- struct dundi_query_state *st = data;
- struct dundi_result dr[MAX_RESULTS];
- struct dundi_ie_data ied;
- struct dundi_hint_metadata hmd;
- char eid_str[20];
- int res, x;
- int ouranswers=0;
- int max = 999999;
- int expiration = dundi_cache_time;
-
- ast_log(LOG_DEBUG, "Whee, looking up '%s@%s' for '%s'\n", st->called_number, st->called_context,
- st->eids[0] ? dundi_eid_to_str(eid_str, sizeof(eid_str), st->eids[0]) : "ourselves");
- memset(&ied, 0, sizeof(ied));
- memset(&dr, 0, sizeof(dr));
- memset(&hmd, 0, sizeof(hmd));
- /* Assume 'don't ask for anything' and 'unaffected', no TTL expired */
- hmd.flags = DUNDI_HINT_DONT_ASK | DUNDI_HINT_UNAFFECTED;
- for (x=0;x<st->nummaps;x++)
- ouranswers = dundi_lookup_local(dr, st->maps + x, st->called_number, &st->trans->us_eid, ouranswers, &hmd);
- if (ouranswers < 0)
- ouranswers = 0;
- for (x=0;x<ouranswers;x++) {
- if (dr[x].weight < max)
- max = dr[x].weight;
- }
-
- if (max) {
- /* If we do not have a canonical result, keep looking */
- res = dundi_lookup_internal(dr + ouranswers, MAX_RESULTS - ouranswers, NULL, st->called_context, st->called_number, st->ttl, 1, &hmd, &expiration, st->nocache, 0, NULL, st->eids, st->directs);
- if (res > 0) {
- /* Append answer in result */
- ouranswers += res;
- } else {
- if ((res < -1) && (!ouranswers))
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_DUPLICATE, "Duplicate Request Pending");
- }
- }
- ast_mutex_lock(&peerlock);
- /* Truncate if "don't ask" isn't present */
- if (!ast_test_flag_nonstd(&hmd, DUNDI_HINT_DONT_ASK))
- hmd.exten[0] = '\0';
- if (ast_test_flag(st->trans, FLAG_DEAD)) {
- ast_log(LOG_DEBUG, "Our transaction went away!\n");
- st->trans->thread = 0;
- destroy_trans(st->trans, 0);
- } else {
- for (x=0;x<ouranswers;x++) {
- /* Add answers */
- if (dr[x].expiration && (expiration > dr[x].expiration))
- expiration = dr[x].expiration;
- dundi_ie_append_answer(&ied, DUNDI_IE_ANSWER, &dr[x].eid, dr[x].techint, dr[x].flags, dr[x].weight, dr[x].dest);
- }
- dundi_ie_append_hint(&ied, DUNDI_IE_HINT, hmd.flags, hmd.exten);
- dundi_ie_append_short(&ied, DUNDI_IE_EXPIRATION, expiration);
- dundi_send(st->trans, DUNDI_COMMAND_DPRESPONSE, 0, 1, &ied);
- st->trans->thread = 0;
- }
- ast_mutex_unlock(&peerlock);
- free(st);
- return NULL;
-}
-
-static void *dundi_precache_thread(void *data)
-{
- struct dundi_query_state *st = data;
- struct dundi_ie_data ied;
- struct dundi_hint_metadata hmd;
- char eid_str[20];
-
- ast_log(LOG_DEBUG, "Whee, precaching '%s@%s' for '%s'\n", st->called_number, st->called_context,
- st->eids[0] ? dundi_eid_to_str(eid_str, sizeof(eid_str), st->eids[0]) : "ourselves");
- memset(&ied, 0, sizeof(ied));
-
- /* Now produce precache */
- dundi_precache_internal(st->called_context, st->called_number, st->ttl, st->eids);
-
- ast_mutex_lock(&peerlock);
- /* Truncate if "don't ask" isn't present */
- if (!ast_test_flag_nonstd(&hmd, DUNDI_HINT_DONT_ASK))
- hmd.exten[0] = '\0';
- if (ast_test_flag(st->trans, FLAG_DEAD)) {
- ast_log(LOG_DEBUG, "Our transaction went away!\n");
- st->trans->thread = 0;
- destroy_trans(st->trans, 0);
- } else {
- dundi_send(st->trans, DUNDI_COMMAND_PRECACHERP, 0, 1, &ied);
- st->trans->thread = 0;
- }
- ast_mutex_unlock(&peerlock);
- free(st);
- return NULL;
-}
-
-static int dundi_query_eid_internal(struct dundi_entity_info *dei, const char *dcontext, dundi_eid *eid, struct dundi_hint_metadata *hmd, int ttl, int blockempty, dundi_eid *avoid[]);
-
-static void *dundi_query_thread(void *data)
-{
- struct dundi_query_state *st = data;
- struct dundi_entity_info dei;
- struct dundi_ie_data ied;
- struct dundi_hint_metadata hmd;
- char eid_str[20];
- int res;
- ast_log(LOG_DEBUG, "Whee, looking up '%s@%s' for '%s'\n", st->called_number, st->called_context,
- st->eids[0] ? dundi_eid_to_str(eid_str, sizeof(eid_str), st->eids[0]) : "ourselves");
- memset(&ied, 0, sizeof(ied));
- memset(&dei, 0, sizeof(dei));
- memset(&hmd, 0, sizeof(hmd));
- if (!dundi_eid_cmp(&st->trans->us_eid, &st->reqeid)) {
- /* Ooh, it's us! */
- ast_log(LOG_DEBUG, "Neat, someone look for us!\n");
- ast_copy_string(dei.orgunit, dept, sizeof(dei.orgunit));
- ast_copy_string(dei.org, org, sizeof(dei.org));
- ast_copy_string(dei.locality, locality, sizeof(dei.locality));
- ast_copy_string(dei.stateprov, stateprov, sizeof(dei.stateprov));
- ast_copy_string(dei.country, country, sizeof(dei.country));
- ast_copy_string(dei.email, email, sizeof(dei.email));
- ast_copy_string(dei.phone, phone, sizeof(dei.phone));
- res = 1;
- } else {
- /* If we do not have a canonical result, keep looking */
- res = dundi_query_eid_internal(&dei, st->called_context, &st->reqeid, &hmd, st->ttl, 1, st->eids);
- }
- ast_mutex_lock(&peerlock);
- if (ast_test_flag(st->trans, FLAG_DEAD)) {
- ast_log(LOG_DEBUG, "Our transaction went away!\n");
- st->trans->thread = 0;
- destroy_trans(st->trans, 0);
- } else {
- if (res) {
- dundi_ie_append_str(&ied, DUNDI_IE_DEPARTMENT, dei.orgunit);
- dundi_ie_append_str(&ied, DUNDI_IE_ORGANIZATION, dei.org);
- dundi_ie_append_str(&ied, DUNDI_IE_LOCALITY, dei.locality);
- dundi_ie_append_str(&ied, DUNDI_IE_STATE_PROV, dei.stateprov);
- dundi_ie_append_str(&ied, DUNDI_IE_COUNTRY, dei.country);
- dundi_ie_append_str(&ied, DUNDI_IE_EMAIL, dei.email);
- dundi_ie_append_str(&ied, DUNDI_IE_PHONE, dei.phone);
- if (!ast_strlen_zero(dei.ipaddr))
- dundi_ie_append_str(&ied, DUNDI_IE_IPADDR, dei.ipaddr);
- }
- dundi_ie_append_hint(&ied, DUNDI_IE_HINT, hmd.flags, hmd.exten);
- dundi_send(st->trans, DUNDI_COMMAND_EIDRESPONSE, 0, 1, &ied);
- st->trans->thread = 0;
- }
- ast_mutex_unlock(&peerlock);
- free(st);
- return NULL;
-}
-
-static int dundi_answer_entity(struct dundi_transaction *trans, struct dundi_ies *ies, char *ccontext)
-{
- struct dundi_query_state *st;
- int totallen;
- int x;
- int skipfirst=0;
- struct dundi_ie_data ied;
- char eid_str[20];
- char *s;
- pthread_t lookupthread;
- pthread_attr_t attr;
- if (ies->eidcount > 1) {
- /* Since it is a requirement that the first EID is the authenticating host
- and the last EID is the root, it is permissible that the first and last EID
- could be the same. In that case, we should go ahead copy only the "root" section
- since we will not need it for authentication. */
- if (!dundi_eid_cmp(ies->eids[0], ies->eids[ies->eidcount - 1]))
- skipfirst = 1;
- }
- totallen = sizeof(struct dundi_query_state);
- totallen += (ies->eidcount - skipfirst) * sizeof(dundi_eid);
- st = malloc(totallen);
- if (st) {
- memset(st, 0, totallen);
- ast_copy_string(st->called_context, ies->called_context, sizeof(st->called_context));
- memcpy(&st->reqeid, ies->reqeid, sizeof(st->reqeid));
- st->trans = trans;
- st->ttl = ies->ttl - 1;
- if (st->ttl < 0)
- st->ttl = 0;
- s = st->fluffy;
- for (x=skipfirst;ies->eids[x];x++) {
- st->eids[x-skipfirst] = (dundi_eid *)s;
- *st->eids[x-skipfirst] = *ies->eids[x];
- s += sizeof(dundi_eid);
- }
- ast_log(LOG_DEBUG, "Answering EID query for '%s@%s'!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), ies->reqeid), ies->called_context);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- trans->thread = 1;
- if (ast_pthread_create(&lookupthread, &attr, dundi_query_thread, st)) {
- trans->thread = 0;
- ast_log(LOG_WARNING, "Unable to create thread!\n");
- free(st);
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of threads");
- dundi_send(trans, DUNDI_COMMAND_EIDRESPONSE, 0, 1, &ied);
- return -1;
- }
- } else {
- ast_log(LOG_WARNING, "Out of memory!\n");
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of memory");
- dundi_send(trans, DUNDI_COMMAND_EIDRESPONSE, 0, 1, &ied);
- return -1;
- }
- return 0;
-}
-
-static int cache_save_hint(dundi_eid *eidpeer, struct dundi_request *req, struct dundi_hint *hint, int expiration)
-{
- int unaffected;
- char key1[256];
- char key2[256];
- char eidpeer_str[20];
- char eidroot_str[20];
- char data[80];
- time_t timeout;
-
- if (expiration < 0)
- expiration = dundi_cache_time;
-
- /* Only cache hint if "don't ask" is there... */
- if (!ast_test_flag_nonstd(hint, htons(DUNDI_HINT_DONT_ASK)))
- return 0;
-
- unaffected = ast_test_flag_nonstd(hint, htons(DUNDI_HINT_UNAFFECTED));
-
- dundi_eid_to_str_short(eidpeer_str, sizeof(eidpeer_str), eidpeer);
- dundi_eid_to_str_short(eidroot_str, sizeof(eidroot_str), &req->root_eid);
- snprintf(key1, sizeof(key1), "hint/%s/%s/%s/e%08lx", eidpeer_str, hint->data, req->dcontext, unaffected ? 0 : req->crc32);
- snprintf(key2, sizeof(key2), "hint/%s/%s/%s/r%s", eidpeer_str, hint->data, req->dcontext, eidroot_str);
-
- time(&timeout);
- timeout += expiration;
- snprintf(data, sizeof(data), "%ld|", (long)(timeout));
-
- ast_db_put("dundi/cache", key1, data);
- ast_log(LOG_DEBUG, "Caching hint at '%s'\n", key1);
- ast_db_put("dundi/cache", key2, data);
- ast_log(LOG_DEBUG, "Caching hint at '%s'\n", key2);
- return 0;
-}
-
-static int cache_save(dundi_eid *eidpeer, struct dundi_request *req, int start, int unaffected, int expiration, int push)
-{
- int x;
- char key1[256];
- char key2[256];
- char data[1024];
- char eidpeer_str[20];
- char eidroot_str[20];
- time_t timeout;
-
- if (expiration < 1)
- expiration = dundi_cache_time;
-
- /* Keep pushes a little longer, cut pulls a little short */
- if (push)
- expiration += 10;
- else
- expiration -= 10;
- if (expiration < 1)
- expiration = 1;
- dundi_eid_to_str_short(eidpeer_str, sizeof(eidpeer_str), eidpeer);
- dundi_eid_to_str_short(eidroot_str, sizeof(eidroot_str), &req->root_eid);
- snprintf(key1, sizeof(key1), "%s/%s/%s/e%08lx", eidpeer_str, req->number, req->dcontext, unaffected ? 0 : req->crc32);
- snprintf(key2, sizeof(key2), "%s/%s/%s/r%s", eidpeer_str, req->number, req->dcontext, eidroot_str);
- /* Build request string */
- time(&timeout);
- timeout += expiration;
- snprintf(data, sizeof(data), "%ld|", (long)(timeout));
- for (x=start;x<req->respcount;x++) {
- /* Skip anything with an illegal pipe in it */
- if (strchr(req->dr[x].dest, '|'))
- continue;
- snprintf(data + strlen(data), sizeof(data) - strlen(data), "%d/%d/%d/%s/%s|",
- req->dr[x].flags, req->dr[x].weight, req->dr[x].techint, req->dr[x].dest,
- dundi_eid_to_str_short(eidpeer_str, sizeof(eidpeer_str), &req->dr[x].eid));
- }
- ast_db_put("dundi/cache", key1, data);
- ast_db_put("dundi/cache", key2, data);
- return 0;
-}
-
-static int dundi_prop_precache(struct dundi_transaction *trans, struct dundi_ies *ies, char *ccontext)
-{
- struct dundi_query_state *st;
- int totallen;
- int x,z;
- struct dundi_ie_data ied;
- char *s;
- struct dundi_result dr2[MAX_RESULTS];
- struct dundi_request dr;
- struct dundi_hint_metadata hmd;
-
- struct dundi_mapping *cur;
- int mapcount;
- int skipfirst = 0;
-
- pthread_t lookupthread;
- pthread_attr_t attr;
-
- memset(&dr2, 0, sizeof(dr2));
- memset(&dr, 0, sizeof(dr));
- memset(&hmd, 0, sizeof(hmd));
-
- /* Forge request structure to hold answers for cache */
- hmd.flags = DUNDI_HINT_DONT_ASK | DUNDI_HINT_UNAFFECTED;
- dr.dr = dr2;
- dr.maxcount = MAX_RESULTS;
- dr.expiration = dundi_cache_time;
- dr.hmd = &hmd;
- dr.pfds[0] = dr.pfds[1] = -1;
- trans->parent = &dr;
- ast_copy_string(dr.dcontext, ies->called_context ? ies->called_context : "e164", sizeof(dr.dcontext));
- ast_copy_string(dr.number, ies->called_number, sizeof(dr.number));
-
- for (x=0;x<ies->anscount;x++) {
- if (trans->parent->respcount < trans->parent->maxcount) {
- /* Make sure it's not already there */
- for (z=0;z<trans->parent->respcount;z++) {
- if ((trans->parent->dr[z].techint == ies->answers[x]->protocol) &&
- !strcmp(trans->parent->dr[z].dest, (char *)ies->answers[x]->data))
- break;
- }
- if (z == trans->parent->respcount) {
- /* Copy into parent responses */
- trans->parent->dr[trans->parent->respcount].flags = ntohs(ies->answers[x]->flags);
- trans->parent->dr[trans->parent->respcount].techint = ies->answers[x]->protocol;
- trans->parent->dr[trans->parent->respcount].weight = ntohs(ies->answers[x]->weight);
- trans->parent->dr[trans->parent->respcount].eid = ies->answers[x]->eid;
- if (ies->expiration > 0)
- trans->parent->dr[trans->parent->respcount].expiration = ies->expiration;
- else
- trans->parent->dr[trans->parent->respcount].expiration = dundi_cache_time;
- dundi_eid_to_str(trans->parent->dr[trans->parent->respcount].eid_str,
- sizeof(trans->parent->dr[trans->parent->respcount].eid_str),
- &ies->answers[x]->eid);
- ast_copy_string(trans->parent->dr[trans->parent->respcount].dest, (char *)ies->answers[x]->data,
- sizeof(trans->parent->dr[trans->parent->respcount].dest));
- ast_copy_string(trans->parent->dr[trans->parent->respcount].tech, tech2str(ies->answers[x]->protocol),
- sizeof(trans->parent->dr[trans->parent->respcount].tech));
- trans->parent->respcount++;
- ast_clear_flag_nonstd(trans->parent->hmd, DUNDI_HINT_DONT_ASK);
- } else if (trans->parent->dr[z].weight > ies->answers[x]->weight) {
- /* Update weight if appropriate */
- trans->parent->dr[z].weight = ies->answers[x]->weight;
- }
- } else
- ast_log(LOG_NOTICE, "Dropping excessive answers in precache for %s@%s\n",
- trans->parent->number, trans->parent->dcontext);
-
- }
- /* Save all the results (if any) we had. Even if no results, still cache lookup. */
- cache_save(&trans->them_eid, trans->parent, 0, 0, ies->expiration, 1);
- if (ies->hint)
- cache_save_hint(&trans->them_eid, trans->parent, ies->hint, ies->expiration);
-
- totallen = sizeof(struct dundi_query_state);
- /* Count matching map entries */
- mapcount = 0;
- cur = mappings;
- while(cur) {
- if (!strcasecmp(cur->dcontext, ccontext))
- mapcount++;
- cur = cur->next;
- }
-
- /* If no maps, return -1 immediately */
- if (!mapcount)
- return -1;
-
- if (ies->eidcount > 1) {
- /* Since it is a requirement that the first EID is the authenticating host
- and the last EID is the root, it is permissible that the first and last EID
- could be the same. In that case, we should go ahead copy only the "root" section
- since we will not need it for authentication. */
- if (!dundi_eid_cmp(ies->eids[0], ies->eids[ies->eidcount - 1]))
- skipfirst = 1;
- }
-
- /* Prepare to run a query and then propagate that as necessary */
- totallen += mapcount * sizeof(struct dundi_mapping);
- totallen += (ies->eidcount - skipfirst) * sizeof(dundi_eid);
- st = malloc(totallen);
- if (st) {
- memset(st, 0, totallen);
- ast_copy_string(st->called_context, ies->called_context, sizeof(st->called_context));
- ast_copy_string(st->called_number, ies->called_number, sizeof(st->called_number));
- st->trans = trans;
- st->ttl = ies->ttl - 1;
- st->nocache = ies->cbypass;
- if (st->ttl < 0)
- st->ttl = 0;
- s = st->fluffy;
- for (x=skipfirst;ies->eids[x];x++) {
- st->eids[x-skipfirst] = (dundi_eid *)s;
- *st->eids[x-skipfirst] = *ies->eids[x];
- st->directs[x-skipfirst] = ies->eid_direct[x];
- s += sizeof(dundi_eid);
- }
- /* Append mappings */
- x = 0;
- st->maps = (struct dundi_mapping *)s;
- cur = mappings;
- while(cur) {
- if (!strcasecmp(cur->dcontext, ccontext)) {
- if (x < mapcount) {
- st->maps[x] = *cur;
- st->maps[x].next = NULL;
- x++;
- }
- }
- cur = cur->next;
- }
- st->nummaps = mapcount;
- ast_log(LOG_DEBUG, "Forwarding precache for '%s@%s'!\n", ies->called_number, ies->called_context);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- trans->thread = 1;
- if (ast_pthread_create(&lookupthread, &attr, dundi_precache_thread, st)) {
- trans->thread = 0;
- ast_log(LOG_WARNING, "Unable to create thread!\n");
- free(st);
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of threads");
- dundi_send(trans, DUNDI_COMMAND_PRECACHERP, 0, 1, &ied);
- return -1;
- }
- } else {
- ast_log(LOG_WARNING, "Out of memory!\n");
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of memory");
- dundi_send(trans, DUNDI_COMMAND_PRECACHERP, 0, 1, &ied);
- return -1;
- }
- return 0;
-}
-
-static int dundi_answer_query(struct dundi_transaction *trans, struct dundi_ies *ies, char *ccontext)
-{
- struct dundi_query_state *st;
- int totallen;
- int x;
- struct dundi_ie_data ied;
- char *s;
- struct dundi_mapping *cur;
- int mapcount;
- int skipfirst = 0;
-
- pthread_t lookupthread;
- pthread_attr_t attr;
- totallen = sizeof(struct dundi_query_state);
- /* Count matching map entries */
- mapcount = 0;
- cur = mappings;
- while(cur) {
- if (!strcasecmp(cur->dcontext, ccontext))
- mapcount++;
- cur = cur->next;
- }
- /* If no maps, return -1 immediately */
- if (!mapcount)
- return -1;
-
- if (ies->eidcount > 1) {
- /* Since it is a requirement that the first EID is the authenticating host
- and the last EID is the root, it is permissible that the first and last EID
- could be the same. In that case, we should go ahead copy only the "root" section
- since we will not need it for authentication. */
- if (!dundi_eid_cmp(ies->eids[0], ies->eids[ies->eidcount - 1]))
- skipfirst = 1;
- }
-
- totallen += mapcount * sizeof(struct dundi_mapping);
- totallen += (ies->eidcount - skipfirst) * sizeof(dundi_eid);
- st = malloc(totallen);
- if (st) {
- memset(st, 0, totallen);
- ast_copy_string(st->called_context, ies->called_context, sizeof(st->called_context));
- ast_copy_string(st->called_number, ies->called_number, sizeof(st->called_number));
- st->trans = trans;
- st->ttl = ies->ttl - 1;
- st->nocache = ies->cbypass;
- if (st->ttl < 0)
- st->ttl = 0;
- s = st->fluffy;
- for (x=skipfirst;ies->eids[x];x++) {
- st->eids[x-skipfirst] = (dundi_eid *)s;
- *st->eids[x-skipfirst] = *ies->eids[x];
- st->directs[x-skipfirst] = ies->eid_direct[x];
- s += sizeof(dundi_eid);
- }
- /* Append mappings */
- x = 0;
- st->maps = (struct dundi_mapping *)s;
- cur = mappings;
- while(cur) {
- if (!strcasecmp(cur->dcontext, ccontext)) {
- if (x < mapcount) {
- st->maps[x] = *cur;
- st->maps[x].next = NULL;
- x++;
- }
- }
- cur = cur->next;
- }
- st->nummaps = mapcount;
- ast_log(LOG_DEBUG, "Answering query for '%s@%s'!\n", ies->called_number, ies->called_context);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- trans->thread = 1;
- if (ast_pthread_create(&lookupthread, &attr, dundi_lookup_thread, st)) {
- trans->thread = 0;
- ast_log(LOG_WARNING, "Unable to create thread!\n");
- free(st);
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of threads");
- dundi_send(trans, DUNDI_COMMAND_DPRESPONSE, 0, 1, &ied);
- return -1;
- }
- } else {
- ast_log(LOG_WARNING, "Out of memory!\n");
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of memory");
- dundi_send(trans, DUNDI_COMMAND_DPRESPONSE, 0, 1, &ied);
- return -1;
- }
- return 0;
-}
-
-static int cache_lookup_internal(time_t now, struct dundi_request *req, char *key, char *eid_str_full, int *lowexpiration)
-{
- char data[1024];
- char *ptr, *term, *src;
- int tech;
- struct ast_flags flags;
- int weight;
- int length;
- int z;
- int expiration;
- char fs[256];
- time_t timeout;
- /* Build request string */
- if (!ast_db_get("dundi/cache", key, data, sizeof(data))) {
- ptr = data;
- if (sscanf(ptr, "%d|%n", (int *)&timeout, &length) == 1) {
- expiration = timeout - now;
- if (expiration > 0) {
- ast_log(LOG_DEBUG, "Found cache expiring in %d seconds!\n", (int)(timeout - now));
- ptr += length;
- while((sscanf(ptr, "%d/%d/%d/%n", &(flags.flags), &weight, &tech, &length) == 3)) {
- ptr += length;
- term = strchr(ptr, '|');
- if (term) {
- *term = '\0';
- src = strrchr(ptr, '/');
- if (src) {
- *src = '\0';
- src++;
- } else
- src = "";
- ast_log(LOG_DEBUG, "Found cached answer '%s/%s' originally from '%s' with flags '%s' on behalf of '%s'\n",
- tech2str(tech), ptr, src, dundi_flags2str(fs, sizeof(fs), flags.flags), eid_str_full);
- /* Make sure it's not already there */
- for (z=0;z<req->respcount;z++) {
- if ((req->dr[z].techint == tech) &&
- !strcmp(req->dr[z].dest, ptr))
- break;
- }
- if (z == req->respcount) {
- /* Copy into parent responses */
- ast_copy_flags(&(req->dr[req->respcount]), &flags, AST_FLAGS_ALL);
- req->dr[req->respcount].weight = weight;
- req->dr[req->respcount].techint = tech;
- req->dr[req->respcount].expiration = expiration;
- dundi_str_short_to_eid(&req->dr[req->respcount].eid, src);
- dundi_eid_to_str(req->dr[req->respcount].eid_str,
- sizeof(req->dr[req->respcount].eid_str), &req->dr[req->respcount].eid);
- ast_copy_string(req->dr[req->respcount].dest, ptr,
- sizeof(req->dr[req->respcount].dest));
- ast_copy_string(req->dr[req->respcount].tech, tech2str(tech),
- sizeof(req->dr[req->respcount].tech));
- req->respcount++;
- ast_clear_flag_nonstd(req->hmd, DUNDI_HINT_DONT_ASK);
- } else if (req->dr[z].weight > weight)
- req->dr[z].weight = weight;
- ptr = term + 1;
- }
- }
- /* We found *something* cached */
- if (expiration < *lowexpiration)
- *lowexpiration = expiration;
- return 1;
- } else
- ast_db_del("dundi/cache", key);
- } else
- ast_db_del("dundi/cache", key);
- }
-
- return 0;
-}
-
-static int cache_lookup(struct dundi_request *req, dundi_eid *peer_eid, unsigned long crc32, int *lowexpiration)
-{
- char key[256];
- char eid_str[20];
- char eidroot_str[20];
- time_t now;
- int res=0;
- int res2=0;
- char eid_str_full[20];
- char tmp[256]="";
- int x;
-
- time(&now);
- dundi_eid_to_str_short(eid_str, sizeof(eid_str), peer_eid);
- dundi_eid_to_str_short(eidroot_str, sizeof(eidroot_str), &req->root_eid);
- dundi_eid_to_str(eid_str_full, sizeof(eid_str_full), peer_eid);
- snprintf(key, sizeof(key), "%s/%s/%s/e%08lx", eid_str, req->number, req->dcontext, crc32);
- res |= cache_lookup_internal(now, req, key, eid_str_full, lowexpiration);
- snprintf(key, sizeof(key), "%s/%s/%s/e%08lx", eid_str, req->number, req->dcontext, 0L);
- res |= cache_lookup_internal(now, req, key, eid_str_full, lowexpiration);
- snprintf(key, sizeof(key), "%s/%s/%s/r%s", eid_str, req->number, req->dcontext, eidroot_str);
- res |= cache_lookup_internal(now, req, key, eid_str_full, lowexpiration);
- x = 0;
- if (!req->respcount) {
- while(!res2) {
- /* Look and see if we have a hint that would preclude us from looking at this
- peer for this number. */
- if (!(tmp[x] = req->number[x]))
- break;
- x++;
- /* Check for hints */
- snprintf(key, sizeof(key), "hint/%s/%s/%s/e%08lx", eid_str, tmp, req->dcontext, crc32);
- res2 |= cache_lookup_internal(now, req, key, eid_str_full, lowexpiration);
- snprintf(key, sizeof(key), "hint/%s/%s/%s/e%08lx", eid_str, tmp, req->dcontext, 0L);
- res2 |= cache_lookup_internal(now, req, key, eid_str_full, lowexpiration);
- snprintf(key, sizeof(key), "hint/%s/%s/%s/r%s", eid_str, tmp, req->dcontext, eidroot_str);
- res2 |= cache_lookup_internal(now, req, key, eid_str_full, lowexpiration);
- if (res2) {
- if (strlen(tmp) > strlen(req->hmd->exten)) {
- /* Update meta data if appropriate */
- ast_copy_string(req->hmd->exten, tmp, sizeof(req->hmd->exten));
- }
- }
- }
- res |= res2;
- }
-
- return res;
-}
-
-static void qualify_peer(struct dundi_peer *peer, int schedonly);
-
-static void apply_peer(struct dundi_transaction *trans, struct dundi_peer *p)
-{
- if (!trans->addr.sin_addr.s_addr)
- memcpy(&trans->addr, &p->addr, sizeof(trans->addr));
- trans->us_eid = p->us_eid;
- trans->them_eid = p->eid;
- /* Enable encryption if appropriate */
- if (!ast_strlen_zero(p->inkey))
- ast_set_flag(trans, FLAG_ENCRYPT);
- if (p->maxms) {
- trans->autokilltimeout = p->maxms;
- trans->retranstimer = DUNDI_DEFAULT_RETRANS_TIMER;
- if (p->lastms > 1) {
- trans->retranstimer = p->lastms * 2;
- /* Keep it from being silly */
- if (trans->retranstimer < 150)
- trans->retranstimer = 150;
- }
- if (trans->retranstimer > DUNDI_DEFAULT_RETRANS_TIMER)
- trans->retranstimer = DUNDI_DEFAULT_RETRANS_TIMER;
- } else
- trans->autokilltimeout = global_autokilltimeout;
-}
-
-static int do_register_expire(void *data)
-{
- struct dundi_peer *peer = data;
- char eid_str[20];
- /* Called with peerlock already held */
- ast_log(LOG_DEBUG, "Register expired for '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- peer->registerexpire = -1;
- peer->lastms = 0;
- memset(&peer->addr, 0, sizeof(peer->addr));
- return 0;
-}
-
-static int update_key(struct dundi_peer *peer)
-{
- unsigned char key[16];
- struct ast_key *ekey, *skey;
- char eid_str[20];
- int res;
- if (!peer->keyexpire || (peer->keyexpire < time(NULL))) {
- build_iv(key);
- aes_encrypt_key128(key, &peer->us_ecx);
- aes_decrypt_key128(key, &peer->us_dcx);
- ekey = ast_key_get(peer->inkey, AST_KEY_PUBLIC);
- if (!ekey) {
- ast_log(LOG_NOTICE, "No such key '%s' for creating RSA encrypted shared key for '%s'!\n",
- peer->inkey, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- return -1;
- }
- skey = ast_key_get(peer->outkey, AST_KEY_PRIVATE);
- if (!skey) {
- ast_log(LOG_NOTICE, "No such key '%s' for signing RSA encrypted shared key for '%s'!\n",
- peer->outkey, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- return -1;
- }
- if ((res = ast_encrypt_bin(peer->txenckey, key, sizeof(key), ekey)) != 128) {
- ast_log(LOG_NOTICE, "Whoa, got a weird encrypt size (%d != %d)!\n", res, 128);
- return -1;
- }
- if ((res = ast_sign_bin(skey, (char *)peer->txenckey, 128, peer->txenckey + 128))) {
- ast_log(LOG_NOTICE, "Failed to sign key (%d)!\n", res);
- return -1;
- }
- peer->us_keycrc32 = crc32(0L, peer->txenckey, 128);
- peer->sentfullkey = 0;
- /* Looks good */
- time(&peer->keyexpire);
- peer->keyexpire += dundi_key_ttl;
- }
- return 0;
-}
-
-static int encrypt_memcpy(unsigned char *dst, unsigned char *src, int len, unsigned char *iv, aes_encrypt_ctx *ecx)
-{
- unsigned char curblock[16];
- int x;
- memcpy(curblock, iv, sizeof(curblock));
- while(len > 0) {
- for (x=0;x<16;x++)
- curblock[x] ^= src[x];
- aes_encrypt(curblock, dst, ecx);
- memcpy(curblock, dst, sizeof(curblock));
- dst += 16;
- src += 16;
- len -= 16;
- }
- return 0;
-}
-static int decrypt_memcpy(unsigned char *dst, unsigned char *src, int len, unsigned char *iv, aes_decrypt_ctx *dcx)
-{
- unsigned char lastblock[16];
- int x;
- memcpy(lastblock, iv, sizeof(lastblock));
- while(len > 0) {
- aes_decrypt(src, dst, dcx);
- for (x=0;x<16;x++)
- dst[x] ^= lastblock[x];
- memcpy(lastblock, src, sizeof(lastblock));
- dst += 16;
- src += 16;
- len -= 16;
- }
- return 0;
-}
-
-static struct dundi_hdr *dundi_decrypt(struct dundi_transaction *trans, unsigned char *dst, int *dstlen, struct dundi_hdr *ohdr, struct dundi_encblock *src, int srclen)
-{
- int space = *dstlen;
- unsigned long bytes;
- struct dundi_hdr *h;
- unsigned char *decrypt_space;
- decrypt_space = alloca(srclen);
- if (!decrypt_space)
- return NULL;
- decrypt_memcpy(decrypt_space, src->encdata, srclen, src->iv, &trans->dcx);
- /* Setup header */
- h = (struct dundi_hdr *)dst;
- *h = *ohdr;
- bytes = space - 6;
- if (uncompress(dst + 6, &bytes, decrypt_space, srclen) != Z_OK) {
- ast_log(LOG_DEBUG, "Ouch, uncompress failed :(\n");
- return NULL;
- }
- /* Update length */
- *dstlen = bytes + 6;
- /* Return new header */
- return h;
-}
-
-static int dundi_encrypt(struct dundi_transaction *trans, struct dundi_packet *pack)
-{
- unsigned char *compress_space;
- int len;
- int res;
- unsigned long bytes;
- struct dundi_ie_data ied;
- struct dundi_peer *peer;
- unsigned char iv[16];
- len = pack->datalen + pack->datalen / 100 + 42;
- compress_space = alloca(len);
- if (compress_space) {
- memset(compress_space, 0, len);
- /* We care about everthing save the first 6 bytes of header */
- bytes = len;
- res = compress(compress_space, &bytes, pack->data + 6, pack->datalen - 6);
- if (res != Z_OK) {
- ast_log(LOG_DEBUG, "Ouch, compression failed!\n");
- return -1;
- }
- memset(&ied, 0, sizeof(ied));
- /* Say who we are */
- if (!pack->h->iseqno && !pack->h->oseqno) {
- /* Need the key in the first copy */
- if (!(peer = find_peer(&trans->them_eid)))
- return -1;
- if (update_key(peer))
- return -1;
- if (!peer->sentfullkey)
- ast_set_flag(trans, FLAG_SENDFULLKEY);
- /* Append key data */
- dundi_ie_append_eid(&ied, DUNDI_IE_EID, &trans->us_eid);
- if (ast_test_flag(trans, FLAG_SENDFULLKEY)) {
- dundi_ie_append_raw(&ied, DUNDI_IE_SHAREDKEY, peer->txenckey, 128);
- dundi_ie_append_raw(&ied, DUNDI_IE_SIGNATURE, peer->txenckey + 128, 128);
- } else {
- dundi_ie_append_int(&ied, DUNDI_IE_KEYCRC32, peer->us_keycrc32);
- }
- /* Setup contexts */
- trans->ecx = peer->us_ecx;
- trans->dcx = peer->us_dcx;
-
- /* We've sent the full key */
- peer->sentfullkey = 1;
- }
- /* Build initialization vector */
- build_iv(iv);
- /* Add the field, rounded up to 16 bytes */
- dundi_ie_append_encdata(&ied, DUNDI_IE_ENCDATA, iv, NULL, ((bytes + 15) / 16) * 16);
- /* Copy the data */
- if ((ied.pos + bytes) >= sizeof(ied.buf)) {
- ast_log(LOG_NOTICE, "Final packet too large!\n");
- return -1;
- }
- encrypt_memcpy(ied.buf + ied.pos, compress_space, bytes, iv, &trans->ecx);
- ied.pos += ((bytes + 15) / 16) * 16;
- /* Reconstruct header */
- pack->datalen = sizeof(struct dundi_hdr);
- pack->h->cmdresp = DUNDI_COMMAND_ENCRYPT;
- pack->h->cmdflags = 0;
- memcpy(pack->h->ies, ied.buf, ied.pos);
- pack->datalen += ied.pos;
- return 0;
- }
- return -1;
-}
-
-static int check_key(struct dundi_peer *peer, unsigned char *newkey, unsigned char *newsig, unsigned long keycrc32)
-{
- unsigned char dst[128];
- int res;
- struct ast_key *key, *skey;
- char eid_str[20];
- if (option_debug)
- ast_log(LOG_DEBUG, "Expected '%08lx' got '%08lx'\n", peer->them_keycrc32, keycrc32);
- if (peer->them_keycrc32 && (peer->them_keycrc32 == keycrc32)) {
- /* A match */
- return 1;
- } else if (!newkey || !newsig)
- return 0;
- if (!memcmp(peer->rxenckey, newkey, 128) &&
- !memcmp(peer->rxenckey + 128, newsig, 128)) {
- /* By definition, a match */
- return 1;
- }
- /* Decrypt key */
- key = ast_key_get(peer->outkey, AST_KEY_PRIVATE);
- if (!key) {
- ast_log(LOG_NOTICE, "Unable to find key '%s' to decode shared key from '%s'\n",
- peer->outkey, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- return -1;
- }
-
- skey = ast_key_get(peer->inkey, AST_KEY_PUBLIC);
- if (!skey) {
- ast_log(LOG_NOTICE, "Unable to find key '%s' to verify shared key from '%s'\n",
- peer->inkey, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- return -1;
- }
-
- /* First check signature */
- res = ast_check_signature_bin(skey, (char *)newkey, 128, newsig);
- if (res)
- return 0;
-
- res = ast_decrypt_bin(dst, newkey, sizeof(dst), key);
- if (res != 16) {
- if (res >= 0)
- ast_log(LOG_NOTICE, "Weird, key decoded to the wrong size (%d)\n", res);
- return 0;
- }
- /* Decrypted, passes signature */
- ast_log(LOG_DEBUG, "Wow, new key combo passed signature and decrypt!\n");
- memcpy(peer->rxenckey, newkey, 128);
- memcpy(peer->rxenckey + 128, newsig, 128);
- peer->them_keycrc32 = crc32(0L, peer->rxenckey, 128);
- aes_decrypt_key128(dst, &peer->them_dcx);
- aes_encrypt_key128(dst, &peer->them_ecx);
- return 1;
-}
-
-static int handle_command_response(struct dundi_transaction *trans, struct dundi_hdr *hdr, int datalen, int encrypted)
-{
- /* Handle canonical command / response */
- int final = hdr->cmdresp & 0x80;
- int cmd = hdr->cmdresp & 0x7f;
- int x,y,z;
- int resp;
- int res;
- int authpass=0;
- unsigned char *bufcpy;
- struct dundi_ie_data ied;
- struct dundi_ies ies;
- struct dundi_peer *peer;
- char eid_str[20];
- char eid_str2[20];
- memset(&ied, 0, sizeof(ied));
- memset(&ies, 0, sizeof(ies));
- if (datalen) {
- bufcpy = alloca(datalen);
- if (!bufcpy)
- return -1;
- /* Make a copy for parsing */
- memcpy(bufcpy, hdr->ies, datalen);
- ast_log(LOG_DEBUG, "Got canonical message %d (%d), %d bytes data%s\n", cmd, hdr->oseqno, datalen, final ? " (Final)" : "");
- if (dundi_parse_ies(&ies, bufcpy, datalen) < 0) {
- ast_log(LOG_WARNING, "Failed to parse DUNDI information elements!\n");
- return -1;
- }
- }
- switch(cmd) {
- case DUNDI_COMMAND_DPDISCOVER:
- case DUNDI_COMMAND_EIDQUERY:
- case DUNDI_COMMAND_PRECACHERQ:
- if (cmd == DUNDI_COMMAND_EIDQUERY)
- resp = DUNDI_COMMAND_EIDRESPONSE;
- else if (cmd == DUNDI_COMMAND_PRECACHERQ)
- resp = DUNDI_COMMAND_PRECACHERP;
- else
- resp = DUNDI_COMMAND_DPRESPONSE;
- /* A dialplan or entity discover -- qualify by highest level entity */
- peer = find_peer(ies.eids[0]);
- if (!peer) {
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_NOAUTH, NULL);
- dundi_send(trans, resp, 0, 1, &ied);
- } else {
- int hasauth = 0;
- trans->us_eid = peer->us_eid;
- if (strlen(peer->inkey)) {
- hasauth = encrypted;
- } else
- hasauth = 1;
- if (hasauth) {
- /* Okay we're authentiated and all, now we check if they're authorized */
- if (!ies.called_context)
- ies.called_context = "e164";
- if (cmd == DUNDI_COMMAND_EIDQUERY) {
- res = dundi_answer_entity(trans, &ies, ies.called_context);
- } else {
- if (ast_strlen_zero(ies.called_number)) {
- /* They're not permitted to access that context */
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Invalid or missing number/entity");
- dundi_send(trans, resp, 0, 1, &ied);
- } else if ((cmd == DUNDI_COMMAND_DPDISCOVER) &&
- (peer->model & DUNDI_MODEL_INBOUND) &&
- has_permission(peer->permit, ies.called_context)) {
- res = dundi_answer_query(trans, &ies, ies.called_context);
- if (res < 0) {
- /* There is no such dundi context */
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_NOAUTH, "Unsupported DUNDI Context");
- dundi_send(trans, resp, 0, 1, &ied);
- }
- } else if ((cmd = DUNDI_COMMAND_PRECACHERQ) &&
- (peer->pcmodel & DUNDI_MODEL_INBOUND) &&
- has_permission(peer->include, ies.called_context)) {
- res = dundi_prop_precache(trans, &ies, ies.called_context);
- if (res < 0) {
- /* There is no such dundi context */
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_NOAUTH, "Unsupported DUNDI Context");
- dundi_send(trans, resp, 0, 1, &ied);
- }
- } else {
- /* They're not permitted to access that context */
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_NOAUTH, "Permission to context denied");
- dundi_send(trans, resp, 0, 1, &ied);
- }
- }
- } else {
- /* They're not permitted to access that context */
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_NOAUTH, "Unencrypted responses not permitted");
- dundi_send(trans, resp, 0, 1, &ied);
- }
- }
- break;
- case DUNDI_COMMAND_REGREQ:
- /* A register request -- should only have one entity */
- peer = find_peer(ies.eids[0]);
- if (!peer || !peer->dynamic) {
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_NOAUTH, NULL);
- dundi_send(trans, DUNDI_COMMAND_REGRESPONSE, 0, 1, &ied);
- } else {
- int hasauth = 0;
- trans->us_eid = peer->us_eid;
- if (!ast_strlen_zero(peer->inkey)) {
- hasauth = encrypted;
- } else
- hasauth = 1;
- if (hasauth) {
- int expire = default_expiration;
- char iabuf[INET_ADDRSTRLEN];
- char data[256];
- int needqual = 0;
- if (peer->registerexpire > -1)
- ast_sched_del(sched, peer->registerexpire);
- peer->registerexpire = ast_sched_add(sched, (expire + 10) * 1000, do_register_expire, peer);
- ast_inet_ntoa(iabuf, sizeof(iabuf), trans->addr.sin_addr);
- snprintf(data, sizeof(data), "%s:%d:%d", iabuf, ntohs(trans->addr.sin_port), expire);
- ast_db_put("dundi/dpeers", dundi_eid_to_str_short(eid_str, sizeof(eid_str), &peer->eid), data);
- if (inaddrcmp(&peer->addr, &trans->addr)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Registered DUNDi peer '%s' at '%s:%d'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), iabuf, ntohs(trans->addr.sin_port));
- needqual = 1;
- }
-
- memcpy(&peer->addr, &trans->addr, sizeof(peer->addr));
- dundi_ie_append_short(&ied, DUNDI_IE_EXPIRATION, default_expiration);
- dundi_send(trans, DUNDI_COMMAND_REGRESPONSE, 0, 1, &ied);
- if (needqual)
- qualify_peer(peer, 1);
- }
- }
- break;
- case DUNDI_COMMAND_DPRESPONSE:
- /* A dialplan response, lets see what we got... */
- if (ies.cause < 1) {
- /* Success of some sort */
- ast_log(LOG_DEBUG, "Looks like success of some sort (%d), %d answers\n", ies.cause, ies.anscount);
- if (ast_test_flag(trans, FLAG_ENCRYPT)) {
- authpass = encrypted;
- } else
- authpass = 1;
- if (authpass) {
- /* Pass back up answers */
- if (trans->parent && trans->parent->dr) {
- y = trans->parent->respcount;
- for (x=0;x<ies.anscount;x++) {
- if (trans->parent->respcount < trans->parent->maxcount) {
- /* Make sure it's not already there */
- for (z=0;z<trans->parent->respcount;z++) {
- if ((trans->parent->dr[z].techint == ies.answers[x]->protocol) &&
- !strcmp(trans->parent->dr[z].dest, (char *)ies.answers[x]->data))
- break;
- }
- if (z == trans->parent->respcount) {
- /* Copy into parent responses */
- trans->parent->dr[trans->parent->respcount].flags = ntohs(ies.answers[x]->flags);
- trans->parent->dr[trans->parent->respcount].techint = ies.answers[x]->protocol;
- trans->parent->dr[trans->parent->respcount].weight = ntohs(ies.answers[x]->weight);
- trans->parent->dr[trans->parent->respcount].eid = ies.answers[x]->eid;
- if (ies.expiration > 0)
- trans->parent->dr[trans->parent->respcount].expiration = ies.expiration;
- else
- trans->parent->dr[trans->parent->respcount].expiration = dundi_cache_time;
- dundi_eid_to_str(trans->parent->dr[trans->parent->respcount].eid_str,
- sizeof(trans->parent->dr[trans->parent->respcount].eid_str),
- &ies.answers[x]->eid);
- ast_copy_string(trans->parent->dr[trans->parent->respcount].dest, (char *)ies.answers[x]->data,
- sizeof(trans->parent->dr[trans->parent->respcount].dest));
- ast_copy_string(trans->parent->dr[trans->parent->respcount].tech, tech2str(ies.answers[x]->protocol),
- sizeof(trans->parent->dr[trans->parent->respcount].tech));
- trans->parent->respcount++;
- ast_clear_flag_nonstd(trans->parent->hmd, DUNDI_HINT_DONT_ASK);
- } else if (trans->parent->dr[z].weight > ies.answers[x]->weight) {
- /* Update weight if appropriate */
- trans->parent->dr[z].weight = ies.answers[x]->weight;
- }
- } else
- ast_log(LOG_NOTICE, "Dropping excessive answers to request for %s@%s\n",
- trans->parent->number, trans->parent->dcontext);
- }
- /* Save all the results (if any) we had. Even if no results, still cache lookup. Let
- the cache know if this request was unaffected by our entity list. */
- cache_save(&trans->them_eid, trans->parent, y,
- ies.hint ? ast_test_flag_nonstd(ies.hint, htons(DUNDI_HINT_UNAFFECTED)) : 0, ies.expiration, 0);
- if (ies.hint) {
- cache_save_hint(&trans->them_eid, trans->parent, ies.hint, ies.expiration);
- if (ast_test_flag_nonstd(ies.hint, htons(DUNDI_HINT_TTL_EXPIRED)))
- ast_set_flag_nonstd(trans->parent->hmd, DUNDI_HINT_TTL_EXPIRED);
- if (ast_test_flag_nonstd(ies.hint, htons(DUNDI_HINT_DONT_ASK))) {
- if (strlen((char *)ies.hint->data) > strlen(trans->parent->hmd->exten)) {
- ast_copy_string(trans->parent->hmd->exten, (char *)ies.hint->data,
- sizeof(trans->parent->hmd->exten));
- }
- } else {
- ast_clear_flag_nonstd(trans->parent->hmd, DUNDI_HINT_DONT_ASK);
- }
- }
- if (ies.expiration > 0) {
- if (trans->parent->expiration > ies.expiration) {
- trans->parent->expiration = ies.expiration;
- }
- }
- }
- /* Close connection if not final */
- if (!final)
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
- }
-
- } else {
- /* Auth failure, check for data */
- if (!final) {
- /* Cancel if they didn't already */
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
- }
- }
- break;
- case DUNDI_COMMAND_EIDRESPONSE:
- /* A dialplan response, lets see what we got... */
- if (ies.cause < 1) {
- /* Success of some sort */
- ast_log(LOG_DEBUG, "Looks like success of some sort (%d)\n", ies.cause);
- if (ast_test_flag(trans, FLAG_ENCRYPT)) {
- authpass = encrypted;
- } else
- authpass = 1;
- if (authpass) {
- /* Pass back up answers */
- if (trans->parent && trans->parent->dei && ies.q_org) {
- if (!trans->parent->respcount) {
- trans->parent->respcount++;
- if (ies.q_dept)
- ast_copy_string(trans->parent->dei->orgunit, ies.q_dept, sizeof(trans->parent->dei->orgunit));
- if (ies.q_org)
- ast_copy_string(trans->parent->dei->org, ies.q_org, sizeof(trans->parent->dei->org));
- if (ies.q_locality)
- ast_copy_string(trans->parent->dei->locality, ies.q_locality, sizeof(trans->parent->dei->locality));
- if (ies.q_stateprov)
- ast_copy_string(trans->parent->dei->stateprov, ies.q_stateprov, sizeof(trans->parent->dei->stateprov));
- if (ies.q_country)
- ast_copy_string(trans->parent->dei->country, ies.q_country, sizeof(trans->parent->dei->country));
- if (ies.q_email)
- ast_copy_string(trans->parent->dei->email, ies.q_email, sizeof(trans->parent->dei->email));
- if (ies.q_phone)
- ast_copy_string(trans->parent->dei->phone, ies.q_phone, sizeof(trans->parent->dei->phone));
- if (ies.q_ipaddr)
- ast_copy_string(trans->parent->dei->ipaddr, ies.q_ipaddr, sizeof(trans->parent->dei->ipaddr));
- if (!dundi_eid_cmp(&trans->them_eid, &trans->parent->query_eid)) {
- /* If it's them, update our address */
- ast_inet_ntoa(trans->parent->dei->ipaddr, sizeof(trans->parent->dei->ipaddr),
- trans->addr.sin_addr);
- }
- }
- if (ies.hint) {
- if (ast_test_flag_nonstd(ies.hint, htons(DUNDI_HINT_TTL_EXPIRED)))
- ast_set_flag_nonstd(trans->parent->hmd, DUNDI_HINT_TTL_EXPIRED);
- }
- }
- /* Close connection if not final */
- if (!final)
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
- }
-
- } else {
- /* Auth failure, check for data */
- if (!final) {
- /* Cancel if they didn't already */
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
- }
- }
- break;
- case DUNDI_COMMAND_REGRESPONSE:
- /* A dialplan response, lets see what we got... */
- if (ies.cause < 1) {
- int hasauth;
- /* Success of some sort */
- if (ast_test_flag(trans, FLAG_ENCRYPT)) {
- hasauth = encrypted;
- } else
- hasauth = 1;
-
- if (!hasauth) {
- ast_log(LOG_NOTICE, "Reponse to register not authorized!\n");
- if (!final) {
- dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_NOAUTH, "Improper signature in answer");
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, &ied);
- }
- } else {
- ast_log(LOG_DEBUG, "Yay, we've registered as '%s' to '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &trans->us_eid),
- dundi_eid_to_str(eid_str2, sizeof(eid_str2), &trans->them_eid));
- /* Close connection if not final */
- if (!final)
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
- }
- } else {
- /* Auth failure, cancel if they didn't for some reason */
- if (!final) {
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
- }
- }
- break;
- case DUNDI_COMMAND_INVALID:
- case DUNDI_COMMAND_NULL:
- case DUNDI_COMMAND_PRECACHERP:
- /* Do nothing special */
- if (!final)
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
- break;
- case DUNDI_COMMAND_ENCREJ:
- if ((ast_test_flag(trans, FLAG_SENDFULLKEY)) || !trans->lasttrans || !(peer = find_peer(&trans->them_eid))) {
- /* No really, it's over at this point */
- if (!final)
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
- } else {
- /* Send with full key */
- ast_set_flag(trans, FLAG_SENDFULLKEY);
- if (final) {
- /* Ooops, we got a final message, start by sending ACK... */
- dundi_ack(trans, hdr->cmdresp & 0x80);
- trans->aseqno = trans->iseqno;
- /* Now, we gotta create a new transaction */
- if (!reset_transaction(trans)) {
- /* Make sure handle_frame doesn't destroy us */
- hdr->cmdresp &= 0x7f;
- /* Parse the message we transmitted */
- memset(&ies, 0, sizeof(ies));
- dundi_parse_ies(&ies, trans->lasttrans->h->ies, trans->lasttrans->datalen - sizeof(struct dundi_hdr));
- /* Reconstruct outgoing encrypted packet */
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_eid(&ied, DUNDI_IE_EID, &trans->us_eid);
- dundi_ie_append_raw(&ied, DUNDI_IE_SHAREDKEY, peer->txenckey, 128);
- dundi_ie_append_raw(&ied, DUNDI_IE_SIGNATURE, peer->txenckey + 128, 128);
- if (ies.encblock)
- dundi_ie_append_encdata(&ied, DUNDI_IE_ENCDATA, ies.encblock->iv, ies.encblock->encdata, ies.enclen);
- dundi_send(trans, DUNDI_COMMAND_ENCRYPT, 0, trans->lasttrans->h->cmdresp & 0x80, &ied);
- peer->sentfullkey = 1;
- }
- }
- }
- break;
- case DUNDI_COMMAND_ENCRYPT:
- if (!encrypted) {
- /* No nested encryption! */
- if ((trans->iseqno == 1) && !trans->oseqno) {
- if (!ies.eids[0] || !(peer = find_peer(ies.eids[0])) ||
- ((!ies.encsharedkey || !ies.encsig) && !ies.keycrc32) ||
- (check_key(peer, ies.encsharedkey, ies.encsig, ies.keycrc32) < 1)) {
- if (!final) {
- dundi_send(trans, DUNDI_COMMAND_ENCREJ, 0, 1, NULL);
- }
- break;
- }
- apply_peer(trans, peer);
- /* Key passed, use new contexts for this session */
- trans->ecx = peer->them_ecx;
- trans->dcx = peer->them_dcx;
- }
- if (ast_test_flag(trans, FLAG_ENCRYPT) && ies.encblock && ies.enclen) {
- struct dundi_hdr *dhdr;
- unsigned char decoded[MAX_PACKET_SIZE];
- int ddatalen;
- ddatalen = sizeof(decoded);
- dhdr = dundi_decrypt(trans, decoded, &ddatalen, hdr, ies.encblock, ies.enclen);
- if (dhdr) {
- /* Handle decrypted response */
- if (dundidebug)
- dundi_showframe(dhdr, 3, &trans->addr, ddatalen - sizeof(struct dundi_hdr));
- handle_command_response(trans, dhdr, ddatalen - sizeof(struct dundi_hdr), 1);
- /* Carry back final flag */
- hdr->cmdresp |= dhdr->cmdresp & 0x80;
- break;
- } else
- ast_log(LOG_DEBUG, "Ouch, decrypt failed :(\n");
- }
- }
- if (!final) {
- /* Turn off encryption */
- ast_clear_flag(trans, FLAG_ENCRYPT);
- dundi_send(trans, DUNDI_COMMAND_ENCREJ, 0, 1, NULL);
- }
- break;
- default:
- /* Send unknown command if we don't know it, with final flag IFF it's the
- first command in the dialog and only if we haven't recieved final notification */
- if (!final) {
- dundi_ie_append_byte(&ied, DUNDI_IE_UNKNOWN, cmd);
- dundi_send(trans, DUNDI_COMMAND_UNKNOWN, 0, !hdr->oseqno, &ied);
- }
- }
- return 0;
-}
-
-static void destroy_packet(struct dundi_packet *pack, int needfree);
-static void destroy_packets(struct dundi_packet *p)
-{
- struct dundi_packet *prev;
- while(p) {
- prev = p;
- p = p->next;
- if (prev->retransid > -1)
- ast_sched_del(sched, prev->retransid);
- free(prev);
- }
-}
-
-
-static int ack_trans(struct dundi_transaction *trans, int iseqno)
-{
- /* Ack transmitted packet corresponding to iseqno */
- struct dundi_packet *pack;
- pack = trans->packets;
- while(pack) {
- if ((pack->h->oseqno + 1) % 255 == iseqno) {
- destroy_packet(pack, 0);
- if (trans->lasttrans) {
- ast_log(LOG_WARNING, "Whoa, there was still a last trans?\n");
- destroy_packets(trans->lasttrans);
- }
- trans->lasttrans = pack;
- if (trans->autokillid > -1)
- ast_sched_del(sched, trans->autokillid);
- trans->autokillid = -1;
- return 1;
- }
- pack = pack->next;
- }
- return 0;
-}
-
-static int handle_frame(struct dundi_hdr *h, struct sockaddr_in *sin, int datalen)
-{
- struct dundi_transaction *trans;
- trans = find_transaction(h, sin);
- if (!trans) {
- dundi_reject(h, sin);
- return 0;
- }
- /* Got a transaction, see where this header fits in */
- if (h->oseqno == trans->iseqno) {
- /* Just what we were looking for... Anything but ack increments iseqno */
- if (ack_trans(trans, h->iseqno) && ast_test_flag(trans, FLAG_FINAL)) {
- /* If final, we're done */
- destroy_trans(trans, 0);
- return 0;
- }
- if (h->cmdresp != DUNDI_COMMAND_ACK) {
- trans->oiseqno = trans->iseqno;
- trans->iseqno++;
- handle_command_response(trans, h, datalen, 0);
- }
- if (trans->aseqno != trans->iseqno) {
- dundi_ack(trans, h->cmdresp & 0x80);
- trans->aseqno = trans->iseqno;
- }
- /* Delete any saved last transmissions */
- destroy_packets(trans->lasttrans);
- trans->lasttrans = NULL;
- if (h->cmdresp & 0x80) {
- /* Final -- destroy now */
- destroy_trans(trans, 0);
- }
- } else if (h->oseqno == trans->oiseqno) {
- /* Last incoming sequence number -- send ACK without processing */
- dundi_ack(trans, 0);
- } else {
- /* Out of window -- simply drop */
- ast_log(LOG_DEBUG, "Dropping packet out of window!\n");
- }
- return 0;
-}
-
-static int socket_read(int *id, int fd, short events, void *cbdata)
-{
- struct sockaddr_in sin;
- int res;
- struct dundi_hdr *h;
- char buf[MAX_PACKET_SIZE];
- socklen_t len;
- len = sizeof(sin);
- res = recvfrom(netsocket, buf, sizeof(buf) - 1, 0,(struct sockaddr *) &sin, &len);
- if (res < 0) {
- if (errno != ECONNREFUSED)
- ast_log(LOG_WARNING, "Error: %s\n", strerror(errno));
- return 1;
- }
- if (res < sizeof(struct dundi_hdr)) {
- ast_log(LOG_WARNING, "midget packet received (%d of %d min)\n", res, (int)sizeof(struct dundi_hdr));
- return 1;
- }
- buf[res] = '\0';
- h = (struct dundi_hdr *)buf;
- if (dundidebug)
- dundi_showframe(h, 1, &sin, res - sizeof(struct dundi_hdr));
- ast_mutex_lock(&peerlock);
- handle_frame(h, &sin, res - sizeof(struct dundi_hdr));
- ast_mutex_unlock(&peerlock);
- return 1;
-}
-
-static void build_secret(char *secret, int seclen)
-{
- unsigned char tmp[16];
- char *s;
- build_iv(tmp);
- secret[0] = '\0';
- ast_base64encode(secret, tmp, sizeof(tmp), seclen);
- /* Eliminate potential bad characters */
- while((s = strchr(secret, ';'))) *s = '+';
- while((s = strchr(secret, '/'))) *s = '+';
- while((s = strchr(secret, ':'))) *s = '+';
- while((s = strchr(secret, '@'))) *s = '+';
-}
-
-
-static void save_secret(const char *newkey, const char *oldkey)
-{
- char tmp[256];
- if (oldkey)
- snprintf(tmp, sizeof(tmp), "%s;%s", oldkey, newkey);
- else
- snprintf(tmp, sizeof(tmp), "%s", newkey);
- rotatetime = time(NULL) + DUNDI_SECRET_TIME;
- ast_db_put(secretpath, "secret", tmp);
- snprintf(tmp, sizeof(tmp), "%d", (int)rotatetime);
- ast_db_put(secretpath, "secretexpiry", tmp);
-}
-
-static void load_password(void)
-{
- char *current=NULL;
- char *last=NULL;
- char tmp[256];
- time_t expired;
-
- ast_db_get(secretpath, "secretexpiry", tmp, sizeof(tmp));
- if (sscanf(tmp, "%d", (int *)&expired) == 1) {
- ast_db_get(secretpath, "secret", tmp, sizeof(tmp));
- current = strchr(tmp, ';');
- if (!current)
- current = tmp;
- else {
- *current = '\0';
- current++;
- };
- if ((time(NULL) - expired) < 0) {
- if ((expired - time(NULL)) > DUNDI_SECRET_TIME)
- expired = time(NULL) + DUNDI_SECRET_TIME;
- } else if ((time(NULL) - (expired + DUNDI_SECRET_TIME)) < 0) {
- last = current;
- current = NULL;
- } else {
- last = NULL;
- current = NULL;
- }
- }
- if (current) {
- /* Current key is still valid, just setup rotatation properly */
- ast_copy_string(cursecret, current, sizeof(cursecret));
- rotatetime = expired;
- } else {
- /* Current key is out of date, rotate or eliminate all together */
- build_secret(cursecret, sizeof(cursecret));
- save_secret(cursecret, last);
- }
-}
-
-static void check_password(void)
-{
- char oldsecret[80];
- time_t now;
-
- time(&now);
-#if 0
- printf("%ld/%ld\n", now, rotatetime);
-#endif
- if ((now - rotatetime) >= 0) {
- /* Time to rotate keys */
- ast_copy_string(oldsecret, cursecret, sizeof(oldsecret));
- build_secret(cursecret, sizeof(cursecret));
- save_secret(cursecret, oldsecret);
- }
-}
-
-static void *network_thread(void *ignore)
-{
- /* Our job is simple: Send queued messages, retrying if necessary. Read frames
- from the network, and queue them for delivery to the channels */
- int res;
- /* Establish I/O callback for socket read */
- ast_io_add(io, netsocket, socket_read, AST_IO_IN, NULL);
- for(;;) {
- res = ast_sched_wait(sched);
- if ((res > 1000) || (res < 0))
- res = 1000;
- res = ast_io_wait(io, res);
- if (res >= 0) {
- ast_mutex_lock(&peerlock);
- ast_sched_runq(sched);
- ast_mutex_unlock(&peerlock);
- }
- check_password();
- }
- return NULL;
-}
-
-static void *process_precache(void *ign)
-{
- struct dundi_precache_queue *qe;
- time_t now;
- char context[256];
- char number[256];
- int run;
- for (;;) {
- time(&now);
- run = 0;
- ast_mutex_lock(&pclock);
- if (pcq) {
- if (!pcq->expiration) {
- /* Gone... Remove... */
- qe = pcq;
- pcq = pcq->next;
- free(qe);
- } else if (pcq->expiration < now) {
- /* Process this entry */
- pcq->expiration = 0;
- ast_copy_string(context, pcq->context, sizeof(context));
- ast_copy_string(number, pcq->number, sizeof(number));
- run = 1;
- }
- }
- ast_mutex_unlock(&pclock);
- if (run) {
- dundi_precache(context, number);
- } else
- sleep(1);
- }
- return NULL;
-}
-
-static int start_network_thread(void)
-{
- ast_pthread_create(&netthreadid, NULL, network_thread, NULL);
- ast_pthread_create(&precachethreadid, NULL, process_precache, NULL);
- return 0;
-}
-
-static int dundi_do_debug(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- dundidebug = 1;
- ast_cli(fd, "DUNDi Debugging Enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int dundi_do_store_history(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- global_storehistory = 1;
- ast_cli(fd, "DUNDi History Storage Enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int dundi_flush(int fd, int argc, char *argv[])
-{
- int stats=0;
- if ((argc < 2) || (argc > 3))
- return RESULT_SHOWUSAGE;
- if (argc > 2) {
- if (!strcasecmp(argv[2], "stats"))
- stats = 1;
- else
- return RESULT_SHOWUSAGE;
- }
- if (stats) {
- /* Flush statistics */
- struct dundi_peer *p;
- int x;
- ast_mutex_lock(&peerlock);
- p = peers;
- while(p) {
- for (x=0;x<DUNDI_TIMING_HISTORY;x++) {
- if (p->lookups[x])
- free(p->lookups[x]);
- p->lookups[x] = NULL;
- p->lookuptimes[x] = 0;
- }
- p->avgms = 0;
- p = p->next;
- }
- ast_mutex_unlock(&peerlock);
- } else {
- ast_db_deltree("dundi/cache", NULL);
- ast_cli(fd, "DUNDi Cache Flushed\n");
- }
- return RESULT_SUCCESS;
-}
-
-static int dundi_no_debug(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- dundidebug = 0;
- ast_cli(fd, "DUNDi Debugging Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static int dundi_no_store_history(int fd, int argc, char *argv[])
-{
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- global_storehistory = 0;
- ast_cli(fd, "DUNDi History Storage Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static char *model2str(int model)
-{
- switch(model) {
- case DUNDI_MODEL_INBOUND:
- return "Inbound";
- case DUNDI_MODEL_OUTBOUND:
- return "Outbound";
- case DUNDI_MODEL_SYMMETRIC:
- return "Symmetric";
- default:
- return "Unknown";
- }
-}
-
-static char *complete_peer_helper(char *line, char *word, int pos, int state, int rpos)
-{
- int which=0;
- char *ret;
- struct dundi_peer *p;
- char eid_str[20];
- if (pos != rpos)
- return NULL;
- ast_mutex_lock(&peerlock);
- p = peers;
- while(p) {
- if (!strncasecmp(word, dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid), strlen(word))) {
- if (++which > state)
- break;
- }
- p = p->next;
- }
- if (p) {
- ret = strdup(dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid));
- } else
- ret = NULL;
- ast_mutex_unlock(&peerlock);
- return ret;
-}
-
-static char *complete_peer_4(char *line, char *word, int pos, int state)
-{
- return complete_peer_helper(line, word, pos, state, 3);
-}
-
-static int rescomp(const void *a, const void *b)
-{
- const struct dundi_result *resa, *resb;
- resa = a;
- resb = b;
- if (resa->weight < resb->weight)
- return -1;
- if (resa->weight > resb->weight)
- return 1;
- return 0;
-}
-
-static void sort_results(struct dundi_result *results, int count)
-{
- qsort(results, count, sizeof(results[0]), rescomp);
-}
-
-static int dundi_do_lookup(int fd, int argc, char *argv[])
-{
- int res;
- char tmp[256];
- char fs[80] = "";
- char *context;
- int x;
- int bypass = 0;
- struct dundi_result dr[MAX_RESULTS];
- struct timeval start;
- if ((argc < 3) || (argc > 4))
- return RESULT_SHOWUSAGE;
- if (argc > 3) {
- if (!strcasecmp(argv[3], "bypass"))
- bypass=1;
- else
- return RESULT_SHOWUSAGE;
- }
- ast_copy_string(tmp, argv[2], sizeof(tmp));
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- }
- start = ast_tvnow();
- res = dundi_lookup(dr, MAX_RESULTS, NULL, context, tmp, bypass);
-
- if (res < 0)
- ast_cli(fd, "DUNDi lookup returned error.\n");
- else if (!res)
- ast_cli(fd, "DUNDi lookup returned no results.\n");
- else
- sort_results(dr, res);
- for (x=0;x<res;x++) {
- ast_cli(fd, "%3d. %5d %s/%s (%s)\n", x + 1, dr[x].weight, dr[x].tech, dr[x].dest, dundi_flags2str(fs, sizeof(fs), dr[x].flags));
- ast_cli(fd, " from %s, expires in %d s\n", dr[x].eid_str, dr[x].expiration);
- }
- ast_cli(fd, "DUNDi lookup completed in %d ms\n", ast_tvdiff_ms(ast_tvnow(), start));
- return RESULT_SUCCESS;
-}
-
-static int dundi_do_precache(int fd, int argc, char *argv[])
-{
- int res;
- char tmp[256];
- char *context;
- struct timeval start;
- if ((argc < 3) || (argc > 3))
- return RESULT_SHOWUSAGE;
- ast_copy_string(tmp, argv[2], sizeof(tmp));
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- }
- start = ast_tvnow();
- res = dundi_precache(context, tmp);
-
- if (res < 0)
- ast_cli(fd, "DUNDi precache returned error.\n");
- else if (!res)
- ast_cli(fd, "DUNDi precache returned no error.\n");
- ast_cli(fd, "DUNDi lookup completed in %d ms\n", ast_tvdiff_ms(ast_tvnow(), start));
- return RESULT_SUCCESS;
-}
-
-static int dundi_do_query(int fd, int argc, char *argv[])
-{
- int res;
- char tmp[256];
- char *context;
- dundi_eid eid;
- struct dundi_entity_info dei;
- if ((argc < 3) || (argc > 3))
- return RESULT_SHOWUSAGE;
- if (dundi_str_to_eid(&eid, argv[2])) {
- ast_cli(fd, "'%s' is not a valid EID!\n", argv[2]);
- return RESULT_SHOWUSAGE;
- }
- ast_copy_string(tmp, argv[2], sizeof(tmp));
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- }
- res = dundi_query_eid(&dei, context, eid);
- if (res < 0)
- ast_cli(fd, "DUNDi Query EID returned error.\n");
- else if (!res)
- ast_cli(fd, "DUNDi Query EID returned no results.\n");
- else {
- ast_cli(fd, "DUNDi Query EID succeeded:\n");
- ast_cli(fd, "Department: %s\n", dei.orgunit);
- ast_cli(fd, "Organization: %s\n", dei.org);
- ast_cli(fd, "City/Locality: %s\n", dei.locality);
- ast_cli(fd, "State/Province: %s\n", dei.stateprov);
- ast_cli(fd, "Country: %s\n", dei.country);
- ast_cli(fd, "E-mail: %s\n", dei.email);
- ast_cli(fd, "Phone: %s\n", dei.phone);
- ast_cli(fd, "IP Address: %s\n", dei.ipaddr);
- }
- return RESULT_SUCCESS;
-}
-
-static int dundi_show_peer(int fd, int argc, char *argv[])
-{
- struct dundi_peer *peer;
- struct permission *p;
- char *order;
- char iabuf[INET_ADDRSTRLEN];
- char eid_str[20];
- int x, cnt;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&peerlock);
- peer = peers;
- while(peer) {
- if (!strcasecmp(dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), argv[3]))
- break;
- peer = peer->next;
- }
- if (peer) {
- switch(peer->order) {
- case 0:
- order = "Primary";
- break;
- case 1:
- order = "Secondary";
- break;
- case 2:
- order = "Tertiary";
- break;
- case 3:
- order = "Quartiary";
- break;
- default:
- order = "Unknown";
- }
- ast_cli(fd, "Peer: %s\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- ast_cli(fd, "Model: %s\n", model2str(peer->model));
- ast_cli(fd, "Host: %s\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "<Unspecified>");
- ast_cli(fd, "Dynamic: %s\n", peer->dynamic ? "yes" : "no");
- ast_cli(fd, "KeyPend: %s\n", peer->keypending ? "yes" : "no");
- ast_cli(fd, "Reg: %s\n", peer->registerid < 0 ? "No" : "Yes");
- ast_cli(fd, "In Key: %s\n", ast_strlen_zero(peer->inkey) ? "<None>" : peer->inkey);
- ast_cli(fd, "Out Key: %s\n", ast_strlen_zero(peer->outkey) ? "<None>" : peer->outkey);
- if (peer->include) {
- ast_cli(fd, "Include logic%s:\n", peer->model & DUNDI_MODEL_OUTBOUND ? "" : " (IGNORED)");
- }
- p = peer->include;
- while(p) {
- ast_cli(fd, "-- %s %s\n", p->allow ? "include" : "do not include", p->name);
- p = p->next;
- }
- if (peer->permit) {
- ast_cli(fd, "Query logic%s:\n", peer->model & DUNDI_MODEL_INBOUND ? "" : " (IGNORED)");
- }
- p = peer->permit;
- while(p) {
- ast_cli(fd, "-- %s %s\n", p->allow ? "permit" : "deny", p->name);
- p = p->next;
- }
- cnt = 0;
- for (x=0;x<DUNDI_TIMING_HISTORY;x++) {
- if (peer->lookups[x]) {
- if (!cnt)
- ast_cli(fd, "Last few query times:\n");
- ast_cli(fd, "-- %d. %s (%d ms)\n", x + 1, peer->lookups[x], peer->lookuptimes[x]);
- cnt++;
- }
- }
- if (cnt)
- ast_cli(fd, "Average query time: %d ms\n", peer->avgms);
- } else
- ast_cli(fd, "No such peer '%s'\n", argv[3]);
- ast_mutex_unlock(&peerlock);
- return RESULT_SUCCESS;
-}
-
-static int dundi_show_peers(int fd, int argc, char *argv[])
-{
-#define FORMAT2 "%-20.20s %-15.15s %-10.10s %-8.8s %-15.15s\n"
-#define FORMAT "%-20.20s %-15.15s %s %-10.10s %-8.8s %-15.15s\n"
- struct dundi_peer *peer;
- char iabuf[INET_ADDRSTRLEN];
- int registeredonly=0;
- char avgms[20];
- char eid_str[20];
- int online_peers = 0;
- int offline_peers = 0;
- int unmonitored_peers = 0;
- int total_peers = 0;
-
- if ((argc != 3) && (argc != 4) && (argc != 5))
- return RESULT_SHOWUSAGE;
- if ((argc == 4)) {
- if (!strcasecmp(argv[3], "registered")) {
- registeredonly = 1;
- } else
- return RESULT_SHOWUSAGE;
- }
- ast_mutex_lock(&peerlock);
- ast_cli(fd, FORMAT2, "EID", "Host", "Model", "AvgTime", "Status");
- for (peer = peers;peer;peer = peer->next) {
- char status[20];
- int print_line = -1;
- char srch[2000];
- total_peers++;
- if (registeredonly && !peer->addr.sin_addr.s_addr)
- continue;
- if (peer->maxms) {
- if (peer->lastms < 0) {
- strcpy(status, "UNREACHABLE");
- offline_peers++;
- }
- else if (peer->lastms > peer->maxms) {
- snprintf(status, sizeof(status), "LAGGED (%d ms)", peer->lastms);
- offline_peers++;
- }
- else if (peer->lastms) {
- snprintf(status, sizeof(status), "OK (%d ms)", peer->lastms);
- online_peers++;
- }
- else {
- strcpy(status, "UNKNOWN");
- offline_peers++;
- }
- } else {
- strcpy(status, "Unmonitored");
- unmonitored_peers++;
- }
- if (peer->avgms)
- snprintf(avgms, sizeof(avgms), "%d ms", peer->avgms);
- else
- strcpy(avgms, "Unavail");
- snprintf(srch, sizeof(srch), FORMAT, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
- peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)",
- peer->dynamic ? "(D)" : "(S)", model2str(peer->model), avgms, status);
-
- if (argc == 5) {
- if (!strcasecmp(argv[3],"include") && strstr(srch,argv[4])) {
- print_line = -1;
- } else if (!strcasecmp(argv[3],"exclude") && !strstr(srch,argv[4])) {
- print_line = 1;
- } else if (!strcasecmp(argv[3],"begin") && !strncasecmp(srch,argv[4],strlen(argv[4]))) {
- print_line = -1;
- } else {
- print_line = 0;
- }
- }
-
- if (print_line) {
- ast_cli(fd, FORMAT, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
- peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)",
- peer->dynamic ? "(D)" : "(S)", model2str(peer->model), avgms, status);
- }
- }
- ast_cli(fd, "%d dundi peers [%d online, %d offline, %d unmonitored]\n", total_peers, online_peers, offline_peers, unmonitored_peers);
- ast_mutex_unlock(&peerlock);
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-static int dundi_show_trans(int fd, int argc, char *argv[])
-{
-#define FORMAT2 "%-22.22s %-5.5s %-5.5s %-3.3s %-3.3s %-3.3s\n"
-#define FORMAT "%-16.16s:%5d %-5.5d %-5.5d %-3.3d %-3.3d %-3.3d\n"
- struct dundi_transaction *trans;
- char iabuf[INET_ADDRSTRLEN];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&peerlock);
- ast_cli(fd, FORMAT2, "Remote", "Src", "Dst", "Tx", "Rx", "Ack");
- for (trans = alltrans;trans;trans = trans->allnext) {
- ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), trans->addr.sin_addr),
- ntohs(trans->addr.sin_port), trans->strans, trans->dtrans, trans->oseqno, trans->iseqno, trans->aseqno);
- }
- ast_mutex_unlock(&peerlock);
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-static int dundi_show_entityid(int fd, int argc, char *argv[])
-{
- char eid_str[20];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&peerlock);
- dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid);
- ast_mutex_unlock(&peerlock);
- ast_cli(fd, "Global EID for this system is '%s'\n", eid_str);
- return RESULT_SUCCESS;
-}
-
-static int dundi_show_requests(int fd, int argc, char *argv[])
-{
-#define FORMAT2 "%-15s %-15s %-15s %-3.3s %-3.3s\n"
-#define FORMAT "%-15s %-15s %-15s %-3.3d %-3.3d\n"
- struct dundi_request *req;
- char eidstr[20];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&peerlock);
- ast_cli(fd, FORMAT2, "Number", "Context", "Root", "Max", "Rsp");
- for (req = requests;req;req = req->next) {
- ast_cli(fd, FORMAT, req->number, req->dcontext,
- dundi_eid_zero(&req->root_eid) ? "<unspecified>" : dundi_eid_to_str(eidstr, sizeof(eidstr), &req->root_eid), req->maxcount, req->respcount);
- }
- ast_mutex_unlock(&peerlock);
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-/* Grok-a-dial DUNDi */
-
-static int dundi_show_mappings(int fd, int argc, char *argv[])
-{
-#define FORMAT2 "%-12.12s %-7.7s %-12.12s %-10.10s %-5.5s %-25.25s\n"
-#define FORMAT "%-12.12s %-7d %-12.12s %-10.10s %-5.5s %-25.25s\n"
- struct dundi_mapping *map;
- char fs[256];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_mutex_lock(&peerlock);
- ast_cli(fd, FORMAT2, "DUNDi Cntxt", "Weight", "Local Cntxt", "Options", "Tech", "Destination");
- for (map = mappings;map;map = map->next) {
- ast_cli(fd, FORMAT, map->dcontext, map->weight,
- ast_strlen_zero(map->lcontext) ? "<none>" : map->lcontext,
- dundi_flags2str(fs, sizeof(fs), map->options), tech2str(map->tech), map->dest);
- }
- ast_mutex_unlock(&peerlock);
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-static int dundi_show_precache(int fd, int argc, char *argv[])
-{
-#define FORMAT2 "%-12.12s %-12.12s %-10.10s\n"
-#define FORMAT "%-12.12s %-12.12s %02d:%02d:%02d\n"
- struct dundi_precache_queue *qe;
- int h,m,s;
- time_t now;
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- time(&now);
- ast_mutex_lock(&pclock);
- ast_cli(fd, FORMAT2, "Number", "Context", "Expiration");
- for (qe = pcq;qe;qe = qe->next) {
- s = qe->expiration - now;
- h = s / 3600;
- s = s % 3600;
- m = s / 60;
- s = s % 60;
- ast_cli(fd, FORMAT, qe->number, qe->context, h,m,s);
- }
- ast_mutex_unlock(&pclock);
- return RESULT_SUCCESS;
-#undef FORMAT
-#undef FORMAT2
-}
-
-static char debug_usage[] =
-"Usage: dundi debug\n"
-" Enables dumping of DUNDi packets for debugging purposes\n";
-
-static char no_debug_usage[] =
-"Usage: dundi no debug\n"
-" Disables dumping of DUNDi packets for debugging purposes\n";
-
-static char store_history_usage[] =
-"Usage: dundi store history\n"
-" Enables storing of DUNDi requests and times for debugging\n"
-"purposes\n";
-
-static char no_store_history_usage[] =
-"Usage: dundi no store history\n"
-" Disables storing of DUNDi requests and times for debugging\n"
-"purposes\n";
-
-static char show_peers_usage[] =
-"Usage: dundi show peers\n"
-" Lists all known DUNDi peers.\n";
-
-static char show_trans_usage[] =
-"Usage: dundi show trans\n"
-" Lists all known DUNDi transactions.\n";
-
-static char show_mappings_usage[] =
-"Usage: dundi show mappings\n"
-" Lists all known DUNDi mappings.\n";
-
-static char show_precache_usage[] =
-"Usage: dundi show precache\n"
-" Lists all known DUNDi scheduled precache updates.\n";
-
-static char show_entityid_usage[] =
-"Usage: dundi show entityid\n"
-" Displays the global entityid for this host.\n";
-
-static char show_peer_usage[] =
-"Usage: dundi show peer [peer]\n"
-" Provide a detailed description of a specifid DUNDi peer.\n";
-
-static char show_requests_usage[] =
-"Usage: dundi show requests\n"
-" Lists all known pending DUNDi requests.\n";
-
-static char lookup_usage[] =
-"Usage: dundi lookup <number>[@context] [bypass]\n"
-" Lookup the given number within the given DUNDi context\n"
-"(or e164 if none is specified). Bypasses cache if 'bypass'\n"
-"keyword is specified.\n";
-
-static char precache_usage[] =
-"Usage: dundi precache <number>[@context]\n"
-" Lookup the given number within the given DUNDi context\n"
-"(or e164 if none is specified) and precaches the results to any\n"
-"upstream DUNDi push servers.\n";
-
-static char query_usage[] =
-"Usage: dundi query <entity>[@context]\n"
-" Attempts to retrieve contact information for a specific\n"
-"DUNDi entity identifier (EID) within a given DUNDi context (or\n"
-"e164 if none is specified).\n";
-
-static char flush_usage[] =
-"Usage: dundi flush [stats]\n"
-" Flushes DUNDi answer cache, used primarily for debug. If\n"
-"'stats' is present, clears timer statistics instead of normal\n"
-"operation.\n";
-
-static struct ast_cli_entry cli_debug =
- { { "dundi", "debug", NULL }, dundi_do_debug, "Enable DUNDi debugging", debug_usage };
-
-static struct ast_cli_entry cli_store_history =
- { { "dundi", "store", "history", NULL }, dundi_do_store_history, "Enable DUNDi historic records", store_history_usage };
-
-static struct ast_cli_entry cli_no_store_history =
- { { "dundi", "no", "store", "history", NULL }, dundi_no_store_history, "Disable DUNDi historic records", no_store_history_usage };
-
-static struct ast_cli_entry cli_flush =
- { { "dundi", "flush", NULL }, dundi_flush, "Flush DUNDi cache", flush_usage };
-
-static struct ast_cli_entry cli_no_debug =
- { { "dundi", "no", "debug", NULL }, dundi_no_debug, "Disable DUNDi debugging", no_debug_usage };
-
-static struct ast_cli_entry cli_show_peers =
- { { "dundi", "show", "peers", NULL }, dundi_show_peers, "Show defined DUNDi peers", show_peers_usage };
-
-static struct ast_cli_entry cli_show_trans =
- { { "dundi", "show", "trans", NULL }, dundi_show_trans, "Show active DUNDi transactions", show_trans_usage };
-
-static struct ast_cli_entry cli_show_entityid =
- { { "dundi", "show", "entityid", NULL }, dundi_show_entityid, "Display Global Entity ID", show_entityid_usage };
-
-static struct ast_cli_entry cli_show_mappings =
- { { "dundi", "show", "mappings", NULL }, dundi_show_mappings, "Show DUNDi mappings", show_mappings_usage };
-
-static struct ast_cli_entry cli_show_precache =
- { { "dundi", "show", "precache", NULL }, dundi_show_precache, "Show DUNDi precache", show_precache_usage };
-
-static struct ast_cli_entry cli_show_requests =
- { { "dundi", "show", "requests", NULL }, dundi_show_requests, "Show DUNDi requests", show_requests_usage };
-
-static struct ast_cli_entry cli_show_peer =
- { { "dundi", "show", "peer", NULL }, dundi_show_peer, "Show info on a specific DUNDi peer", show_peer_usage, complete_peer_4 };
-
-static struct ast_cli_entry cli_lookup =
- { { "dundi", "lookup", NULL }, dundi_do_lookup, "Lookup a number in DUNDi", lookup_usage };
-
-static struct ast_cli_entry cli_precache =
- { { "dundi", "precache", NULL }, dundi_do_precache, "Precache a number in DUNDi", precache_usage };
-
-static struct ast_cli_entry cli_queryeid =
- { { "dundi", "query", NULL }, dundi_do_query, "Query a DUNDi EID", query_usage };
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static struct dundi_transaction *create_transaction(struct dundi_peer *p)
-{
- struct dundi_transaction *trans;
- int tid;
-
- /* Don't allow creation of transactions to non-registered peers */
- if (p && !p->addr.sin_addr.s_addr)
- return NULL;
- tid = get_trans_id();
- if (tid < 1)
- return NULL;
- trans = malloc(sizeof(struct dundi_transaction));
- if (trans) {
- memset(trans, 0, sizeof(struct dundi_transaction));
- if (global_storehistory) {
- trans->start = ast_tvnow();
- ast_set_flag(trans, FLAG_STOREHIST);
- }
- trans->retranstimer = DUNDI_DEFAULT_RETRANS_TIMER;
- trans->autokillid = -1;
- if (p) {
- apply_peer(trans, p);
- if (!p->sentfullkey)
- ast_set_flag(trans, FLAG_SENDFULLKEY);
- }
- trans->strans = tid;
- trans->allnext = alltrans;
- alltrans = trans;
- }
- return trans;
-}
-
-static int dundi_xmit(struct dundi_packet *pack)
-{
- int res;
- char iabuf[INET_ADDRSTRLEN];
- if (dundidebug)
- dundi_showframe(pack->h, 0, &pack->parent->addr, pack->datalen - sizeof(struct dundi_hdr));
- res = sendto(netsocket, pack->data, pack->datalen, 0, (struct sockaddr *)&pack->parent->addr, sizeof(pack->parent->addr));
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to transmit to '%s:%d': %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), pack->parent->addr.sin_addr),
- ntohs(pack->parent->addr.sin_port), strerror(errno));
- }
- if (res > 0)
- res = 0;
- return res;
-}
-
-static void destroy_packet(struct dundi_packet *pack, int needfree)
-{
- struct dundi_packet *prev, *cur;
- if (pack->parent) {
- prev = NULL;
- cur = pack->parent->packets;
- while(cur) {
- if (cur == pack) {
- if (prev)
- prev->next = cur->next;
- else
- pack->parent->packets = cur->next;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- }
- if (pack->retransid > -1)
- ast_sched_del(sched, pack->retransid);
- if (needfree)
- free(pack);
- else {
- pack->retransid = -1;
- pack->next = NULL;
- }
-}
-
-static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
-{
- struct dundi_transaction *cur, *prev;
- struct dundi_peer *peer;
- int ms;
- int x;
- int cnt;
- char eid_str[20];
- if (ast_test_flag(trans, FLAG_ISREG | FLAG_ISQUAL | FLAG_STOREHIST)) {
- peer = peers;
- while (peer) {
- if (peer->regtrans == trans)
- peer->regtrans = NULL;
- if (peer->keypending == trans)
- peer->keypending = NULL;
- if (peer->qualtrans == trans) {
- if (fromtimeout) {
- if (peer->lastms > -1)
- ast_log(LOG_NOTICE, "Peer '%s' has become UNREACHABLE!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- peer->lastms = -1;
- } else {
- ms = ast_tvdiff_ms(ast_tvnow(), peer->qualtx);
- if (ms < 1)
- ms = 1;
- if (ms < peer->maxms) {
- if ((peer->lastms >= peer->maxms) || (peer->lastms < 0))
- ast_log(LOG_NOTICE, "Peer '%s' has become REACHABLE!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- } else if (peer->lastms < peer->maxms) {
- ast_log(LOG_NOTICE, "Peer '%s' has become TOO LAGGED (%d ms)\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), ms);
- }
- peer->lastms = ms;
- }
- peer->qualtrans = NULL;
- }
- if (ast_test_flag(trans, FLAG_STOREHIST)) {
- if (trans->parent && !ast_strlen_zero(trans->parent->number)) {
- if (!dundi_eid_cmp(&trans->them_eid, &peer->eid)) {
- peer->avgms = 0;
- cnt = 0;
- if (peer->lookups[DUNDI_TIMING_HISTORY-1])
- free(peer->lookups[DUNDI_TIMING_HISTORY-1]);
- for (x=DUNDI_TIMING_HISTORY-1;x>0;x--) {
- peer->lookuptimes[x] = peer->lookuptimes[x-1];
- peer->lookups[x] = peer->lookups[x-1];
- if (peer->lookups[x]) {
- peer->avgms += peer->lookuptimes[x];
- cnt++;
- }
- }
- peer->lookuptimes[0] = ast_tvdiff_ms(ast_tvnow(), trans->start);
- peer->lookups[0] = malloc(strlen(trans->parent->number) + strlen(trans->parent->dcontext) + 2);
- if (peer->lookups[0]) {
- sprintf(peer->lookups[0], "%s@%s", trans->parent->number, trans->parent->dcontext);
- peer->avgms += peer->lookuptimes[0];
- cnt++;
- }
- if (cnt)
- peer->avgms /= cnt;
- }
- }
- }
- peer = peer->next;
- }
- }
- if (trans->parent) {
- /* Unlink from parent if appropriate */
- prev = NULL;
- cur = trans->parent->trans;
- while(cur) {
- if (cur == trans) {
- if (prev)
- prev->next = trans->next;
- else
- trans->parent->trans = trans->next;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- if (!trans->parent->trans) {
- /* Wake up sleeper */
- if (trans->parent->pfds[1] > -1) {
- write(trans->parent->pfds[1], "killa!", 6);
- }
- }
- }
- /* Unlink from all trans */
- prev = NULL;
- cur = alltrans;
- while(cur) {
- if (cur == trans) {
- if (prev)
- prev->allnext = trans->allnext;
- else
- alltrans = trans->allnext;
- break;
- }
- prev = cur;
- cur = cur->allnext;
- }
- destroy_packets(trans->packets);
- destroy_packets(trans->lasttrans);
- trans->packets = NULL;
- trans->lasttrans = NULL;
- if (trans->autokillid > -1)
- ast_sched_del(sched, trans->autokillid);
- trans->autokillid = -1;
- if (trans->thread) {
- /* If used by a thread, mark as dead and be done */
- ast_set_flag(trans, FLAG_DEAD);
- } else
- free(trans);
-}
-
-static int dundi_rexmit(void *data)
-{
- struct dundi_packet *pack;
- char iabuf[INET_ADDRSTRLEN];
- int res;
- ast_mutex_lock(&peerlock);
- pack = data;
- if (pack->retrans < 1) {
- pack->retransid = -1;
- if (!ast_test_flag(pack->parent, FLAG_ISQUAL))
- ast_log(LOG_NOTICE, "Max retries exceeded to host '%s:%d' msg %d on call %d\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), pack->parent->addr.sin_addr),
- ntohs(pack->parent->addr.sin_port), pack->h->oseqno, ntohs(pack->h->strans));
- destroy_trans(pack->parent, 1);
- res = 0;
- } else {
- /* Decrement retransmission, try again */
- pack->retrans--;
- dundi_xmit(pack);
- res = 1;
- }
- ast_mutex_unlock(&peerlock);
- return res;
-}
-
-static int dundi_send(struct dundi_transaction *trans, int cmdresp, int flags, int final, struct dundi_ie_data *ied)
-{
- struct dundi_packet *pack;
- int res;
- int len;
- char eid_str[20];
- len = sizeof(struct dundi_packet) + sizeof(struct dundi_hdr) + (ied ? ied->pos : 0);
- /* Reserve enough space for encryption */
- if (ast_test_flag(trans, FLAG_ENCRYPT))
- len += 384;
- pack = malloc(len);
- if (pack) {
- memset(pack, 0, len);
- pack->h = (struct dundi_hdr *)(pack->data);
- if (cmdresp != DUNDI_COMMAND_ACK) {
- pack->retransid = ast_sched_add(sched, trans->retranstimer, dundi_rexmit, pack);
- pack->retrans = DUNDI_DEFAULT_RETRANS - 1;
- pack->next = trans->packets;
- trans->packets = pack;
- }
- pack->parent = trans;
- pack->h->strans = htons(trans->strans);
- pack->h->dtrans = htons(trans->dtrans);
- pack->h->iseqno = trans->iseqno;
- pack->h->oseqno = trans->oseqno;
- pack->h->cmdresp = cmdresp;
- pack->datalen = sizeof(struct dundi_hdr);
- if (ied) {
- memcpy(pack->h->ies, ied->buf, ied->pos);
- pack->datalen += ied->pos;
- }
- if (final) {
- pack->h->cmdresp |= DUNDI_COMMAND_FINAL;
- ast_set_flag(trans, FLAG_FINAL);
- }
- pack->h->cmdflags = flags;
- if (cmdresp != DUNDI_COMMAND_ACK) {
- trans->oseqno++;
- trans->oseqno = trans->oseqno % 256;
- }
- trans->aseqno = trans->iseqno;
- /* If we have their public key, encrypt */
- if (ast_test_flag(trans, FLAG_ENCRYPT)) {
- switch(cmdresp) {
- case DUNDI_COMMAND_REGREQ:
- case DUNDI_COMMAND_REGRESPONSE:
- case DUNDI_COMMAND_DPDISCOVER:
- case DUNDI_COMMAND_DPRESPONSE:
- case DUNDI_COMMAND_EIDQUERY:
- case DUNDI_COMMAND_EIDRESPONSE:
- case DUNDI_COMMAND_PRECACHERQ:
- case DUNDI_COMMAND_PRECACHERP:
- if (dundidebug)
- dundi_showframe(pack->h, 2, &trans->addr, pack->datalen - sizeof(struct dundi_hdr));
- res = dundi_encrypt(trans, pack);
- break;
- default:
- res = 0;
- }
- } else
- res = 0;
- if (!res)
- res = dundi_xmit(pack);
- if (res)
- ast_log(LOG_NOTICE, "Failed to send packet to '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &trans->them_eid));
-
- if (cmdresp == DUNDI_COMMAND_ACK)
- free(pack);
- return res;
- }
- return -1;
-}
-
-static int do_autokill(void *data)
-{
- struct dundi_transaction *trans = data;
- char eid_str[20];
- ast_log(LOG_NOTICE, "Transaction to '%s' took too long to ACK, destroying\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &trans->them_eid));
- trans->autokillid = -1;
- destroy_trans(trans, 0); /* We could actually set it to 1 instead of 0, but we won't ;-) */
- return 0;
-}
-
-static void dundi_ie_append_eid_appropriately(struct dundi_ie_data *ied, char *context, dundi_eid *eid, dundi_eid *us)
-{
- struct dundi_peer *p;
- if (!dundi_eid_cmp(eid, us)) {
- dundi_ie_append_eid(ied, DUNDI_IE_EID_DIRECT, eid);
- return;
- }
- ast_mutex_lock(&peerlock);
- p = peers;
- while(p) {
- if (!dundi_eid_cmp(&p->eid, eid)) {
- if (has_permission(p->include, context))
- dundi_ie_append_eid(ied, DUNDI_IE_EID_DIRECT, eid);
- else
- dundi_ie_append_eid(ied, DUNDI_IE_EID, eid);
- break;
- }
- p = p->next;
- }
- if (!p)
- dundi_ie_append_eid(ied, DUNDI_IE_EID, eid);
- ast_mutex_unlock(&peerlock);
-}
-
-static int dundi_discover(struct dundi_transaction *trans)
-{
- struct dundi_ie_data ied;
- int x;
- if (!trans->parent) {
- ast_log(LOG_WARNING, "Tried to discover a transaction with no parent?!?\n");
- return -1;
- }
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_short(&ied, DUNDI_IE_VERSION, DUNDI_DEFAULT_VERSION);
- if (!dundi_eid_zero(&trans->us_eid))
- dundi_ie_append_eid(&ied, DUNDI_IE_EID_DIRECT, &trans->us_eid);
- for (x=0;x<trans->eidcount;x++)
- dundi_ie_append_eid_appropriately(&ied, trans->parent->dcontext, &trans->eids[x], &trans->us_eid);
- dundi_ie_append_str(&ied, DUNDI_IE_CALLED_NUMBER, trans->parent->number);
- dundi_ie_append_str(&ied, DUNDI_IE_CALLED_CONTEXT, trans->parent->dcontext);
- dundi_ie_append_short(&ied, DUNDI_IE_TTL, trans->ttl);
- if (trans->parent->cbypass)
- dundi_ie_append(&ied, DUNDI_IE_CACHEBYPASS);
- if (trans->autokilltimeout)
- trans->autokillid = ast_sched_add(sched, trans->autokilltimeout, do_autokill, trans);
- return dundi_send(trans, DUNDI_COMMAND_DPDISCOVER, 0, 0, &ied);
-}
-
-static int precache_trans(struct dundi_transaction *trans, struct dundi_mapping *maps, int mapcount, int *minexp, int *foundanswers)
-{
- struct dundi_ie_data ied;
- int x, res;
- int max = 999999;
- int expiration = dundi_cache_time;
- int ouranswers=0;
- dundi_eid *avoid[1] = { NULL, };
- int direct[1] = { 0, };
- struct dundi_result dr[MAX_RESULTS];
- struct dundi_hint_metadata hmd;
- if (!trans->parent) {
- ast_log(LOG_WARNING, "Tried to discover a transaction with no parent?!?\n");
- return -1;
- }
- memset(&hmd, 0, sizeof(hmd));
- memset(&dr, 0, sizeof(dr));
- /* Look up the answers we're going to include */
- for (x=0;x<mapcount;x++)
- ouranswers = dundi_lookup_local(dr, maps + x, trans->parent->number, &trans->us_eid, ouranswers, &hmd);
- if (ouranswers < 0)
- ouranswers = 0;
- for (x=0;x<ouranswers;x++) {
- if (dr[x].weight < max)
- max = dr[x].weight;
- }
- if (max) {
- /* If we do not have a canonical result, keep looking */
- res = dundi_lookup_internal(dr + ouranswers, MAX_RESULTS - ouranswers, NULL, trans->parent->dcontext, trans->parent->number, trans->ttl, 1, &hmd, &expiration, 0, 1, &trans->them_eid, avoid, direct);
- if (res > 0) {
- /* Append answer in result */
- ouranswers += res;
- }
- }
-
- if (ouranswers > 0) {
- *foundanswers += ouranswers;
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_short(&ied, DUNDI_IE_VERSION, DUNDI_DEFAULT_VERSION);
- if (!dundi_eid_zero(&trans->us_eid))
- dundi_ie_append_eid(&ied, DUNDI_IE_EID, &trans->us_eid);
- for (x=0;x<trans->eidcount;x++)
- dundi_ie_append_eid(&ied, DUNDI_IE_EID, &trans->eids[x]);
- dundi_ie_append_str(&ied, DUNDI_IE_CALLED_NUMBER, trans->parent->number);
- dundi_ie_append_str(&ied, DUNDI_IE_CALLED_CONTEXT, trans->parent->dcontext);
- dundi_ie_append_short(&ied, DUNDI_IE_TTL, trans->ttl);
- for (x=0;x<ouranswers;x++) {
- /* Add answers */
- if (dr[x].expiration && (expiration > dr[x].expiration))
- expiration = dr[x].expiration;
- dundi_ie_append_answer(&ied, DUNDI_IE_ANSWER, &dr[x].eid, dr[x].techint, dr[x].flags, dr[x].weight, dr[x].dest);
- }
- dundi_ie_append_hint(&ied, DUNDI_IE_HINT, hmd.flags, hmd.exten);
- dundi_ie_append_short(&ied, DUNDI_IE_EXPIRATION, expiration);
- if (trans->autokilltimeout)
- trans->autokillid = ast_sched_add(sched, trans->autokilltimeout, do_autokill, trans);
- if (expiration < *minexp)
- *minexp = expiration;
- return dundi_send(trans, DUNDI_COMMAND_PRECACHERQ, 0, 0, &ied);
- } else {
- /* Oops, nothing to send... */
- destroy_trans(trans, 0);
- return 0;
- }
-}
-
-static int dundi_query(struct dundi_transaction *trans)
-{
- struct dundi_ie_data ied;
- int x;
- if (!trans->parent) {
- ast_log(LOG_WARNING, "Tried to query a transaction with no parent?!?\n");
- return -1;
- }
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_short(&ied, DUNDI_IE_VERSION, DUNDI_DEFAULT_VERSION);
- if (!dundi_eid_zero(&trans->us_eid))
- dundi_ie_append_eid(&ied, DUNDI_IE_EID, &trans->us_eid);
- for (x=0;x<trans->eidcount;x++)
- dundi_ie_append_eid(&ied, DUNDI_IE_EID, &trans->eids[x]);
- dundi_ie_append_eid(&ied, DUNDI_IE_REQEID, &trans->parent->query_eid);
- dundi_ie_append_str(&ied, DUNDI_IE_CALLED_CONTEXT, trans->parent->dcontext);
- dundi_ie_append_short(&ied, DUNDI_IE_TTL, trans->ttl);
- if (trans->autokilltimeout)
- trans->autokillid = ast_sched_add(sched, trans->autokilltimeout, do_autokill, trans);
- return dundi_send(trans, DUNDI_COMMAND_EIDQUERY, 0, 0, &ied);
-}
-
-static int discover_transactions(struct dundi_request *dr)
-{
- struct dundi_transaction *trans;
- ast_mutex_lock(&peerlock);
- trans = dr->trans;
- while(trans) {
- dundi_discover(trans);
- trans = trans->next;
- }
- ast_mutex_unlock(&peerlock);
- return 0;
-}
-
-static int precache_transactions(struct dundi_request *dr, struct dundi_mapping *maps, int mapcount, int *expiration, int *foundanswers)
-{
- struct dundi_transaction *trans, *transn;
- /* Mark all as "in thread" so they don't disappear */
- ast_mutex_lock(&peerlock);
- trans = dr->trans;
- while(trans) {
- if (trans->thread)
- ast_log(LOG_WARNING, "This shouldn't happen, really...\n");
- trans->thread = 1;
- trans = trans->next;
- }
- ast_mutex_unlock(&peerlock);
-
- trans = dr->trans;
- while(trans) {
- if (!ast_test_flag(trans, FLAG_DEAD))
- precache_trans(trans, maps, mapcount, expiration, foundanswers);
- trans = trans->next;
- }
-
- /* Cleanup any that got destroyed in the mean time */
- ast_mutex_lock(&peerlock);
- trans = dr->trans;
- while(trans) {
- transn = trans->next;
- trans->thread = 0;
- if (ast_test_flag(trans, FLAG_DEAD)) {
- ast_log(LOG_DEBUG, "Our transaction went away!\n");
- destroy_trans(trans, 0);
- }
- trans = transn;
- }
- ast_mutex_unlock(&peerlock);
- return 0;
-}
-
-static int query_transactions(struct dundi_request *dr)
-{
- struct dundi_transaction *trans;
- ast_mutex_lock(&peerlock);
- trans = dr->trans;
- while(trans) {
- dundi_query(trans);
- trans = trans->next;
- }
- ast_mutex_unlock(&peerlock);
- return 0;
-}
-
-static int optimize_transactions(struct dundi_request *dr, int order)
-{
- /* Minimize the message propagation through DUNDi by
- alerting the network to hops which should be not be considered */
- struct dundi_transaction *trans;
- struct dundi_peer *peer;
- dundi_eid tmp;
- int x;
- int needpush;
- ast_mutex_lock(&peerlock);
- trans = dr->trans;
- while(trans) {
- /* Pop off the true root */
- if (trans->eidcount) {
- tmp = trans->eids[--trans->eidcount];
- needpush = 1;
- } else {
- tmp = trans->us_eid;
- needpush = 0;
- }
-
- peer = peers;
- while(peer) {
- if (has_permission(peer->include, dr->dcontext) &&
- dundi_eid_cmp(&peer->eid, &trans->them_eid) &&
- (peer->order <= order)) {
- /* For each other transaction, make sure we don't
- ask this EID about the others if they're not
- already in the list */
- if (!dundi_eid_cmp(&tmp, &peer->eid))
- x = -1;
- else {
- for (x=0;x<trans->eidcount;x++) {
- if (!dundi_eid_cmp(&trans->eids[x], &peer->eid))
- break;
- }
- }
- if (x == trans->eidcount) {
- /* Nope not in the list, if needed, add us at the end since we're the source */
- if (trans->eidcount < DUNDI_MAX_STACK - needpush) {
- trans->eids[trans->eidcount++] = peer->eid;
- /* Need to insert the real root (or us) at the bottom now as
- a requirement now. */
- needpush = 1;
- }
- }
- }
- peer = peer->next;
- }
- /* If necessary, push the true root back on the end */
- if (needpush)
- trans->eids[trans->eidcount++] = tmp;
- trans = trans->next;
- }
- ast_mutex_unlock(&peerlock);
- return 0;
-}
-
-static int append_transaction(struct dundi_request *dr, struct dundi_peer *p, int ttl, dundi_eid *avoid[])
-{
- struct dundi_transaction *trans;
- int x;
- char eid_str[20];
- char eid_str2[20];
- /* Ignore if not registered */
- if (!p->addr.sin_addr.s_addr)
- return 0;
- if (p->maxms && ((p->lastms < 0) || (p->lastms >= p->maxms)))
- return 0;
- if (ast_strlen_zero(dr->number))
- ast_log(LOG_DEBUG, "Will query peer '%s' for '%s' (context '%s')\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid), dundi_eid_to_str(eid_str2, sizeof(eid_str2), &dr->query_eid), dr->dcontext);
- else
- ast_log(LOG_DEBUG, "Will query peer '%s' for '%s@%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid), dr->number, dr->dcontext);
- trans = create_transaction(p);
- if (!trans)
- return -1;
- trans->next = dr->trans;
- trans->parent = dr;
- trans->ttl = ttl;
- for (x=0;avoid[x] && (x <DUNDI_MAX_STACK);x++)
- trans->eids[x] = *avoid[x];
- trans->eidcount = x;
- dr->trans = trans;
- return 0;
-}
-
-static void cancel_request(struct dundi_request *dr)
-{
- struct dundi_transaction *trans, *next;
-
- ast_mutex_lock(&peerlock);
- trans = dr->trans;
-
- while(trans) {
- next = trans->next;
- /* Orphan transaction from request */
- trans->parent = NULL;
- trans->next = NULL;
- /* Send final cancel */
- dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
- trans = next;
- }
- ast_mutex_unlock(&peerlock);
-}
-
-static void abort_request(struct dundi_request *dr)
-{
- ast_mutex_lock(&peerlock);
- while(dr->trans)
- destroy_trans(dr->trans, 0);
- ast_mutex_unlock(&peerlock);
-}
-
-static void build_transactions(struct dundi_request *dr, int ttl, int order, int *foundcache, int *skipped, int blockempty, int nocache, int modeselect, dundi_eid *skip, dundi_eid *avoid[], int directs[])
-{
- struct dundi_peer *p;
- int x;
- int res;
- int pass;
- int allowconnect;
- char eid_str[20];
- ast_mutex_lock(&peerlock);
- p = peers;
- while(p) {
- if (modeselect == 1) {
- /* Send the precache to push upstreams only! */
- pass = has_permission(p->permit, dr->dcontext) && (p->pcmodel & DUNDI_MODEL_OUTBOUND);
- allowconnect = 1;
- } else {
- /* Normal lookup / EID query */
- pass = has_permission(p->include, dr->dcontext);
- allowconnect = p->model & DUNDI_MODEL_OUTBOUND;
- }
- if (skip) {
- if (!dundi_eid_cmp(skip, &p->eid))
- pass = 0;
- }
- if (pass) {
- if (p->order <= order) {
- /* Check order first, then check cache, regardless of
- omissions, this gets us more likely to not have an
- affected answer. */
- if((nocache || !(res = cache_lookup(dr, &p->eid, dr->crc32, &dr->expiration)))) {
- res = 0;
- /* Make sure we haven't already seen it and that it won't
- affect our answer */
- for (x=0;avoid[x];x++) {
- if (!dundi_eid_cmp(avoid[x], &p->eid) || !dundi_eid_cmp(avoid[x], &p->us_eid)) {
- /* If not a direct connection, it affects our answer */
- if (directs && !directs[x])
- ast_clear_flag_nonstd(dr->hmd, DUNDI_HINT_UNAFFECTED);
- break;
- }
- }
- /* Make sure we can ask */
- if (allowconnect) {
- if (!avoid[x] && (!blockempty || !dundi_eid_zero(&p->us_eid))) {
- /* Check for a matching or 0 cache entry */
- append_transaction(dr, p, ttl, avoid);
- } else
- ast_log(LOG_DEBUG, "Avoiding '%s' in transaction\n", dundi_eid_to_str(eid_str, sizeof(eid_str), avoid[x]));
- }
- }
- *foundcache |= res;
- } else if (!*skipped || (p->order < *skipped))
- *skipped = p->order;
- }
- p = p->next;
- }
- ast_mutex_unlock(&peerlock);
-}
-
-static int register_request(struct dundi_request *dr, struct dundi_request **pending)
-{
- struct dundi_request *cur;
- int res=0;
- char eid_str[20];
- ast_mutex_lock(&peerlock);
- cur = requests;
- while(cur) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Checking '%s@%s' vs '%s@%s'\n", cur->dcontext, cur->number,
- dr->dcontext, dr->number);
- if (!strcasecmp(cur->dcontext, dr->dcontext) &&
- !strcasecmp(cur->number, dr->number) &&
- (!dundi_eid_cmp(&cur->root_eid, &dr->root_eid) || (cur->crc32 == dr->crc32))) {
- ast_log(LOG_DEBUG, "Found existing query for '%s@%s' for '%s' crc '%08lx'\n",
- cur->dcontext, cur->number, dundi_eid_to_str(eid_str, sizeof(eid_str), &cur->root_eid), cur->crc32);
- *pending = cur;
- res = 1;
- break;
- }
- cur = cur->next;
- }
- if (!res) {
- ast_log(LOG_DEBUG, "Registering request for '%s@%s' on behalf of '%s' crc '%08lx'\n",
- dr->number, dr->dcontext, dundi_eid_to_str(eid_str, sizeof(eid_str), &dr->root_eid), dr->crc32);
- /* Go ahead and link us in since nobody else is searching for this */
- dr->next = requests;
- requests = dr;
- *pending = NULL;
- }
- ast_mutex_unlock(&peerlock);
- return res;
-}
-
-static void unregister_request(struct dundi_request *dr)
-{
- struct dundi_request *cur, *prev;
- ast_mutex_lock(&peerlock);
- prev = NULL;
- cur = requests;
- while(cur) {
- if (cur == dr) {
- if (prev)
- prev->next = cur->next;
- else
- requests = cur->next;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- ast_mutex_unlock(&peerlock);
-}
-
-static int check_request(struct dundi_request *dr)
-{
- struct dundi_request *cur;
- int res = 0;
- ast_mutex_lock(&peerlock);
- cur = requests;
- while(cur) {
- if (cur == dr) {
- res = 1;
- break;
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&peerlock);
- return res;
-}
-
-static unsigned long avoid_crc32(dundi_eid *avoid[])
-{
- /* Idea is that we're calculating a checksum which is independent of
- the order that the EID's are listed in */
- unsigned long acrc32 = 0;
- int x;
- for (x=0;avoid[x];x++) {
- /* Order doesn't matter */
- if (avoid[x+1]) {
- acrc32 ^= crc32(0L, (unsigned char *)avoid[x], sizeof(dundi_eid));
- }
- }
- return acrc32;
-}
-
-static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct ast_channel *chan, const char *dcontext, const char *number, int ttl, int blockempty, struct dundi_hint_metadata *hmd, int *expiration, int cbypass, int modeselect, dundi_eid *skip, dundi_eid *avoid[], int direct[])
-{
- int res;
- struct dundi_request dr, *pending;
- dundi_eid *rooteid=NULL;
- int x;
- int ttlms;
- int ms;
- int foundcache;
- int skipped=0;
- int order=0;
- char eid_str[20];
- struct timeval start;
-
- /* Don't do anthing for a hungup channel */
- if (chan && chan->_softhangup)
- return 0;
-
- ttlms = DUNDI_FLUFF_TIME + ttl * DUNDI_TTL_TIME;
-
- for (x=0;avoid[x];x++)
- rooteid = avoid[x];
- /* Now perform real check */
- memset(&dr, 0, sizeof(dr));
- if (pipe(dr.pfds)) {
- ast_log(LOG_WARNING, "pipe failed: %s\n" , strerror(errno));
- return -1;
- }
- dr.dr = result;
- dr.hmd = hmd;
- dr.maxcount = maxret;
- dr.expiration = *expiration;
- dr.cbypass = cbypass;
- dr.crc32 = avoid_crc32(avoid);
- ast_copy_string(dr.dcontext, dcontext ? dcontext : "e164", sizeof(dr.dcontext));
- ast_copy_string(dr.number, number, sizeof(dr.number));
- if (rooteid)
- dr.root_eid = *rooteid;
- res = register_request(&dr, &pending);
- if (res) {
- /* Already a request */
- if (rooteid && !dundi_eid_cmp(&dr.root_eid, &pending->root_eid)) {
- /* This is on behalf of someone else. Go ahead and close this out since
- they'll get their answer anyway. */
- ast_log(LOG_DEBUG, "Oooh, duplicate request for '%s@%s' for '%s'\n",
- dr.number,dr.dcontext,dundi_eid_to_str(eid_str, sizeof(eid_str), &dr.root_eid));
- close(dr.pfds[0]);
- close(dr.pfds[1]);
- return -2;
- } else {
- /* Wait for the cache to populate */
- ast_log(LOG_DEBUG, "Waiting for similar request for '%s@%s' for '%s'\n",
- dr.number,dr.dcontext,dundi_eid_to_str(eid_str, sizeof(eid_str), &pending->root_eid));
- start = ast_tvnow();
- while(check_request(pending) && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms) && (!chan || !chan->_softhangup)) {
- /* XXX Would be nice to have a way to poll/select here XXX */
- /* XXX this is a busy wait loop!!! */
- usleep(1);
- }
- /* Continue on as normal, our cache should kick in */
- }
- }
- /* Create transactions */
- do {
- order = skipped;
- skipped = 0;
- foundcache = 0;
- build_transactions(&dr, ttl, order, &foundcache, &skipped, blockempty, cbypass, modeselect, skip, avoid, direct);
- } while (skipped && !foundcache && !dr.trans);
- /* If no TTL, abort and return 0 now after setting TTL expired hint. Couldn't
- do this earlier because we didn't know if we were going to have transactions
- or not. */
- if (!ttl) {
- ast_set_flag_nonstd(hmd, DUNDI_HINT_TTL_EXPIRED);
- abort_request(&dr);
- unregister_request(&dr);
- close(dr.pfds[0]);
- close(dr.pfds[1]);
- return 0;
- }
-
- /* Optimize transactions */
- optimize_transactions(&dr, order);
- /* Actually perform transactions */
- discover_transactions(&dr);
- /* Wait for transaction to come back */
- start = ast_tvnow();
- while(dr.trans && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms) && (!chan || !chan->_softhangup)) {
- ms = 100;
- ast_waitfor_n_fd(dr.pfds, 1, &ms, NULL);
- }
- if (chan && chan->_softhangup)
- ast_log(LOG_DEBUG, "Hrm, '%s' hungup before their query for %s@%s finished\n", chan->name, dr.number, dr.dcontext);
- cancel_request(&dr);
- unregister_request(&dr);
- res = dr.respcount;
- *expiration = dr.expiration;
- close(dr.pfds[0]);
- close(dr.pfds[1]);
- return res;
-}
-
-int dundi_lookup(struct dundi_result *result, int maxret, struct ast_channel *chan, const char *dcontext, const char *number, int cbypass)
-{
- struct dundi_hint_metadata hmd;
- dundi_eid *avoid[1] = { NULL, };
- int direct[1] = { 0, };
- int expiration = dundi_cache_time;
- memset(&hmd, 0, sizeof(hmd));
- hmd.flags = DUNDI_HINT_DONT_ASK | DUNDI_HINT_UNAFFECTED;
- return dundi_lookup_internal(result, maxret, chan, dcontext, number, dundi_ttl, 0, &hmd, &expiration, cbypass, 0, NULL, avoid, direct);
-}
-
-static void reschedule_precache(const char *number, const char *context, int expiration)
-{
- int len;
- struct dundi_precache_queue *qe, *prev=NULL;
- ast_mutex_lock(&pclock);
- qe = pcq;
- while(qe) {
- if (!strcmp(number, qe->number) && !strcasecmp(context, qe->context)) {
- if (prev)
- prev->next = qe->next;
- else
- pcq = qe->next;
- qe->next = NULL;
- break;
- }
- prev = qe;
- qe = qe->next;
- };
- if (!qe) {
- len = sizeof(struct dundi_precache_queue);
- len += strlen(number) + 1;
- len += strlen(context) + 1;
- qe = malloc(len);
- if (qe) {
- memset(qe, 0, len);
- strcpy(qe->number, number);
- qe->context = qe->number + strlen(number) + 1;
- strcpy(qe->context, context);
- }
- }
- time(&qe->expiration);
- qe->expiration += expiration;
- prev = pcq;
- if (prev) {
- while(prev->next && (prev->next->expiration <= qe->expiration))
- prev = prev->next;
- qe->next = prev->next;
- prev->next = qe;
- } else
- pcq = qe;
- ast_mutex_unlock(&pclock);
-
-}
-
-static void dundi_precache_full(void)
-{
- struct dundi_mapping *cur;
- struct ast_context *con;
- struct ast_exten *e;
- cur = mappings;
- while(cur) {
- ast_log(LOG_NOTICE, "Should precache context '%s'\n", cur->dcontext);
- ast_lock_contexts();
- con = ast_walk_contexts(NULL);
- while(con) {
- if (!strcasecmp(cur->lcontext, ast_get_context_name(con))) {
- /* Found the match, now queue them all up */
- ast_lock_context(con);
- e = ast_walk_context_extensions(con, NULL);
- while(e) {
- reschedule_precache(ast_get_extension_name(e), cur->dcontext, 0);
- e = ast_walk_context_extensions(con, e);
- }
- ast_unlock_context(con);
- }
- con = ast_walk_contexts(con);
- }
- ast_unlock_contexts();
- cur = cur->next;
- }
-}
-
-static int dundi_precache_internal(const char *context, const char *number, int ttl, dundi_eid *avoids[])
-{
- struct dundi_request dr;
- struct dundi_hint_metadata hmd;
- struct dundi_result dr2[MAX_RESULTS];
- struct timeval start;
- struct dundi_mapping *maps=NULL, *cur;
- int nummaps;
- int foundanswers;
- int foundcache, skipped, ttlms, ms;
- if (!context)
- context = "e164";
- ast_log(LOG_DEBUG, "Precache internal (%s@%s)!\n", number, context);
-
- ast_mutex_lock(&peerlock);
- nummaps = 0;
- cur = mappings;
- while(cur) {
- if (!strcasecmp(cur->dcontext, context))
- nummaps++;
- cur = cur->next;
- }
- if (nummaps) {
- maps = alloca(nummaps * sizeof(struct dundi_mapping));
- nummaps = 0;
- if (maps) {
- cur = mappings;
- while(cur) {
- if (!strcasecmp(cur->dcontext, context))
- maps[nummaps++] = *cur;
- cur = cur->next;
- }
- }
- }
- ast_mutex_unlock(&peerlock);
- if (!nummaps || !maps)
- return -1;
- ttlms = DUNDI_FLUFF_TIME + ttl * DUNDI_TTL_TIME;
- memset(&dr2, 0, sizeof(dr2));
- memset(&dr, 0, sizeof(dr));
- memset(&hmd, 0, sizeof(hmd));
- dr.dr = dr2;
- ast_copy_string(dr.number, number, sizeof(dr.number));
- ast_copy_string(dr.dcontext, context ? context : "e164", sizeof(dr.dcontext));
- dr.maxcount = MAX_RESULTS;
- dr.expiration = dundi_cache_time;
- dr.hmd = &hmd;
- dr.pfds[0] = dr.pfds[1] = -1;
- pipe(dr.pfds);
- build_transactions(&dr, ttl, 0, &foundcache, &skipped, 0, 1, 1, NULL, avoids, NULL);
- optimize_transactions(&dr, 0);
- foundanswers = 0;
- precache_transactions(&dr, maps, nummaps, &dr.expiration, &foundanswers);
- if (foundanswers) {
- if (dr.expiration > 0)
- reschedule_precache(dr.number, dr.dcontext, dr.expiration);
- else
- ast_log(LOG_NOTICE, "Weird, expiration = %d, but need to precache for %s@%s?!\n", dr.expiration, dr.number, dr.dcontext);
- }
- start = ast_tvnow();
- while(dr.trans && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms)) {
- if (dr.pfds[0] > -1) {
- ms = 100;
- ast_waitfor_n_fd(dr.pfds, 1, &ms, NULL);
- } else
- usleep(1);
- }
- cancel_request(&dr);
- if (dr.pfds[0] > -1) {
- close(dr.pfds[0]);
- close(dr.pfds[1]);
- }
- return 0;
-}
-
-int dundi_precache(const char *context, const char *number)
-{
- dundi_eid *avoid[1] = { NULL, };
- return dundi_precache_internal(context, number, dundi_ttl, avoid);
-}
-
-static int dundi_query_eid_internal(struct dundi_entity_info *dei, const char *dcontext, dundi_eid *eid, struct dundi_hint_metadata *hmd, int ttl, int blockempty, dundi_eid *avoid[])
-{
- int res;
- struct dundi_request dr;
- dundi_eid *rooteid=NULL;
- int x;
- int ttlms;
- int skipped=0;
- int foundcache=0;
- struct timeval start;
-
- ttlms = DUNDI_FLUFF_TIME + ttl * DUNDI_TTL_TIME;
-
- for (x=0;avoid[x];x++)
- rooteid = avoid[x];
- /* Now perform real check */
- memset(&dr, 0, sizeof(dr));
- dr.hmd = hmd;
- dr.dei = dei;
- dr.pfds[0] = dr.pfds[1] = -1;
- ast_copy_string(dr.dcontext, dcontext ? dcontext : "e164", sizeof(dr.dcontext));
- memcpy(&dr.query_eid, eid, sizeof(dr.query_eid));
- if (rooteid)
- dr.root_eid = *rooteid;
- /* Create transactions */
- build_transactions(&dr, ttl, 9999, &foundcache, &skipped, blockempty, 0, 0, NULL, avoid, NULL);
-
- /* If no TTL, abort and return 0 now after setting TTL expired hint. Couldn't
- do this earlier because we didn't know if we were going to have transactions
- or not. */
- if (!ttl) {
- ast_set_flag_nonstd(hmd, DUNDI_HINT_TTL_EXPIRED);
- return 0;
- }
-
- /* Optimize transactions */
- optimize_transactions(&dr, 9999);
- /* Actually perform transactions */
- query_transactions(&dr);
- /* Wait for transaction to come back */
- start = ast_tvnow();
- while(dr.trans && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms))
- usleep(1);
- res = dr.respcount;
- return res;
-}
-
-int dundi_query_eid(struct dundi_entity_info *dei, const char *dcontext, dundi_eid eid)
-{
- dundi_eid *avoid[1] = { NULL, };
- struct dundi_hint_metadata hmd;
- memset(&hmd, 0, sizeof(hmd));
- return dundi_query_eid_internal(dei, dcontext, &eid, &hmd, dundi_ttl, 0, avoid);
-}
-
-/*!
- * \ingroup applications
- */
-static int dundi_lookup_exec(struct ast_channel *chan, void *data)
-{
- char *num;
- char *context;
- char *opts;
- int results;
- int x;
- int bypass = 0;
- struct localuser *u;
- struct dundi_result dr[MAX_RESULTS];
- static int dep_warning = 0;
-
- LOCAL_USER_ADD(u);
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "This application has been deprecated in favor of the DUNDILOOKUP dialplan function.\n");
- dep_warning = 1;
- }
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "DUNDiLookup requires an argument (number)\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- num = ast_strdupa(data);
- if (!num) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return 0;
- }
-
- context = strchr(num, '|');
- if (context) {
- *context = '\0';
- context++;
- opts = strchr(context, '|');
- if (opts) {
- *opts = '\0';
- opts++;
- if (strchr(opts, 'b'))
- bypass = 1;
- }
- }
-
- if (ast_strlen_zero(context))
- context = "e164";
-
- results = dundi_lookup(dr, MAX_RESULTS, NULL, context, num, bypass);
- if (results > 0) {
- sort_results(dr, results);
- for (x = 0; x < results; x++) {
- if (ast_test_flag(dr + x, DUNDI_FLAG_EXISTS)) {
- pbx_builtin_setvar_helper(chan, "DUNDTECH", dr[x].tech);
- pbx_builtin_setvar_helper(chan, "DUNDDEST", dr[x].dest);
- break;
- }
- }
- } else if (option_priority_jumping)
- ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
-
- LOCAL_USER_REMOVE(u);
-
- return 0;
-}
-
-static char *dundifunc_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
-{
- char *num;
- char *context;
- char *opts;
- int results;
- int x;
- int bypass = 0;
- struct localuser *u;
- struct dundi_result dr[MAX_RESULTS];
-
- LOCAL_USER_ACF_ADD(u);
-
- buf[0] = '\0';
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "DUNDILOOKUP requires an argument (number)\n");
- LOCAL_USER_REMOVE(u);
- return buf;
- }
-
- num = ast_strdupa(data);
- if (!num) {
- ast_log(LOG_ERROR, "Out of memory!\n");
- LOCAL_USER_REMOVE(u);
- return buf;
- }
-
- context = strchr(num, '|');
- if (context) {
- *context = '\0';
- context++;
- opts = strchr(context, '|');
- if (opts) {
- *opts = '\0';
- opts++;
- if (strchr(opts, 'b'))
- bypass = 1;
- }
- }
-
- if (ast_strlen_zero(context))
- context = "e164";
-
- results = dundi_lookup(dr, MAX_RESULTS, NULL, context, num, bypass);
- if (results > 0) {
- sort_results(dr, results);
- for (x = 0; x < results; x++) {
- if (ast_test_flag(dr + x, DUNDI_FLAG_EXISTS)) {
- snprintf(buf, len, "%s/%s", dr[x].tech, dr[x].dest);
- break;
- }
- }
- }
-
- LOCAL_USER_REMOVE(u);
-
- return buf;
-}
-
-/*! DUNDILOOKUP
- * \ingroup functions
-*/
-
-static struct ast_custom_function dundi_function = {
- .name = "DUNDILOOKUP",
- .synopsis = "Do a DUNDi lookup of a phone number.",
- .syntax = "DUNDILOOKUP(number[|context[|options]])",
- .desc = "This will do a DUNDi lookup of the given phone number.\n"
- "If no context is given, the default will be e164. The result of\n"
- "this function will the Technology/Resource found in the DUNDi\n"
- "lookup. If no results were found, the result will be blank.\n"
- "If the 'b' option is specified, the internal DUNDi cache will\n"
- "be bypassed.\n",
- .read = dundifunc_read,
-};
-
-static void mark_peers(void)
-{
- struct dundi_peer *peer;
- ast_mutex_lock(&peerlock);
- peer = peers;
- while(peer) {
- peer->dead = 1;
- peer = peer->next;
- }
- ast_mutex_unlock(&peerlock);
-}
-
-static void mark_mappings(void)
-{
- struct dundi_mapping *map;
- ast_mutex_lock(&peerlock);
- map = mappings;
- while(map) {
- map->dead = 1;
- map = map->next;
- }
- ast_mutex_unlock(&peerlock);
-}
-
-static void destroy_permissions(struct permission *p)
-{
- struct permission *prev;
- while(p) {
- prev = p;
- p = p->next;
- free(prev);
- }
-}
-
-static void destroy_peer(struct dundi_peer *peer)
-{
- if (peer->registerid > -1)
- ast_sched_del(sched, peer->registerid);
- if (peer->regtrans)
- destroy_trans(peer->regtrans, 0);
- if (peer->keypending)
- destroy_trans(peer->keypending, 0);
- if (peer->qualifyid > -1)
- ast_sched_del(sched, peer->qualifyid);
- destroy_permissions(peer->permit);
- destroy_permissions(peer->include);
- free(peer);
-}
-
-static void destroy_map(struct dundi_mapping *map)
-{
- free(map);
-}
-
-static void prune_peers(void)
-{
- struct dundi_peer *peer, *prev, *next;
- ast_mutex_lock(&peerlock);
- peer = peers;
- prev = NULL;
- while(peer) {
- next = peer->next;
- if (peer->dead) {
- if (prev)
- prev->next = peer->next;
- else
- peers = peer->next;
- destroy_peer(peer);
- } else
- prev = peer;
- peer = next;
- }
- ast_mutex_unlock(&peerlock);
-}
-
-static void prune_mappings(void)
-{
- struct dundi_mapping *map, *prev, *next;
- ast_mutex_lock(&peerlock);
- map = mappings;
- prev = NULL;
- while(map) {
- next = map->next;
- if (map->dead) {
- if (prev)
- prev->next = map->next;
- else
- mappings = map->next;
- destroy_map(map);
- } else
- prev = map;
- map = next;
- }
- ast_mutex_unlock(&peerlock);
-}
-
-static struct permission *append_permission(struct permission *p, char *s, int allow)
-{
- struct permission *start;
- start = p;
- if (p) {
- while(p->next)
- p = p->next;
- }
- if (p) {
- p->next = malloc(sizeof(struct permission) + strlen(s) + 1);
- p = p->next;
- } else {
- p = malloc(sizeof(struct permission) + strlen(s) + 1);
- }
- if (p) {
- memset(p, 0, sizeof(struct permission));
- memcpy(p->name, s, strlen(s) + 1);
- p->allow = allow;
- }
- return start ? start : p;
-}
-
-#define MAX_OPTS 128
-
-static void build_mapping(char *name, char *value)
-{
- char *t, *fields[MAX_OPTS];
- struct dundi_mapping *map;
- int x;
- int y;
- t = ast_strdupa(value);
- if (t) {
- map = mappings;
- while(map) {
- /* Find a double match */
- if (!strcasecmp(map->dcontext, name) &&
- (!strncasecmp(map->lcontext, value, strlen(map->lcontext)) &&
- (!value[strlen(map->lcontext)] ||
- (value[strlen(map->lcontext)] == ','))))
- break;
- map = map->next;
- }
- if (!map) {
- map = malloc(sizeof(struct dundi_mapping));
- if (map) {
- memset(map, 0, sizeof(struct dundi_mapping));
- map->next = mappings;
- mappings = map;
- map->dead = 1;
- }
- }
- if (map) {
- map->options = 0;
- memset(fields, 0, sizeof(fields));
- x = 0;
- while(t && x < MAX_OPTS) {
- fields[x++] = t;
- t = strchr(t, ',');
- if (t) {
- *t = '\0';
- t++;
- }
- } /* Russell was here, arrrr! */
- if ((x == 1) && ast_strlen_zero(fields[0])) {
- /* Placeholder mapping */
- ast_copy_string(map->dcontext, name, sizeof(map->dcontext));
- map->dead = 0;
- } else if (x >= 4) {
- ast_copy_string(map->dcontext, name, sizeof(map->dcontext));
- ast_copy_string(map->lcontext, fields[0], sizeof(map->lcontext));
- if ((sscanf(fields[1], "%d", &map->weight) == 1) && (map->weight >= 0) && (map->weight < 60000)) {
- ast_copy_string(map->dest, fields[3], sizeof(map->dest));
- if ((map->tech = str2tech(fields[2]))) {
- map->dead = 0;
- }
- } else {
- ast_log(LOG_WARNING, "Invalid weight '%s' specified, deleting entry '%s/%s'\n", fields[1], map->dcontext, map->lcontext);
- }
- for (y=4;y<x;y++) {
- if (!strcasecmp(fields[y], "nounsolicited"))
- map->options |= DUNDI_FLAG_NOUNSOLICITED;
- else if (!strcasecmp(fields[y], "nocomunsolicit"))
- map->options |= DUNDI_FLAG_NOCOMUNSOLICIT;
- else if (!strcasecmp(fields[y], "residential"))
- map->options |= DUNDI_FLAG_RESIDENTIAL;
- else if (!strcasecmp(fields[y], "commercial"))
- map->options |= DUNDI_FLAG_COMMERCIAL;
- else if (!strcasecmp(fields[y], "mobile"))
- map->options |= DUNDI_FLAG_MOBILE;
- else if (!strcasecmp(fields[y], "nopartial"))
- map->options |= DUNDI_FLAG_INTERNAL_NOPARTIAL;
- else
- ast_log(LOG_WARNING, "Don't know anything about option '%s'\n", fields[y]);
- }
- } else
- ast_log(LOG_WARNING, "Expected at least %d arguments in map, but got only %d\n", 4, x);
- }
- }
-}
-
-static int do_register(void *data)
-{
- struct dundi_ie_data ied;
- struct dundi_peer *peer = data;
- char eid_str[20];
- char eid_str2[20];
- /* Called with peerlock already held */
- ast_log(LOG_DEBUG, "Register us as '%s' to '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->us_eid), dundi_eid_to_str(eid_str2, sizeof(eid_str2), &peer->eid));
- peer->registerid = ast_sched_add(sched, default_expiration * 1000, do_register, data);
- /* Destroy old transaction if there is one */
- if (peer->regtrans)
- destroy_trans(peer->regtrans, 0);
- peer->regtrans = create_transaction(peer);
- if (peer->regtrans) {
- ast_set_flag(peer->regtrans, FLAG_ISREG);
- memset(&ied, 0, sizeof(ied));
- dundi_ie_append_short(&ied, DUNDI_IE_VERSION, DUNDI_DEFAULT_VERSION);
- dundi_ie_append_eid(&ied, DUNDI_IE_EID, &peer->regtrans->us_eid);
- dundi_ie_append_short(&ied, DUNDI_IE_EXPIRATION, default_expiration);
- dundi_send(peer->regtrans, DUNDI_COMMAND_REGREQ, 0, 0, &ied);
-
- } else
- ast_log(LOG_NOTICE, "Unable to create new transaction for registering to '%s'!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
-
- return 0;
-}
-
-static int do_qualify(void *data)
-{
- struct dundi_peer *peer;
- peer = data;
- peer->qualifyid = -1;
- qualify_peer(peer, 0);
- return 0;
-}
-
-static void qualify_peer(struct dundi_peer *peer, int schedonly)
-{
- int when;
- if (peer->qualifyid > -1)
- ast_sched_del(sched, peer->qualifyid);
- peer->qualifyid = -1;
- if (peer->qualtrans)
- destroy_trans(peer->qualtrans, 0);
- peer->qualtrans = NULL;
- if (peer->maxms > 0) {
- when = 60000;
- if (peer->lastms < 0)
- when = 10000;
- if (schedonly)
- when = 5000;
- peer->qualifyid = ast_sched_add(sched, when, do_qualify, peer);
- if (!schedonly)
- peer->qualtrans = create_transaction(peer);
- if (peer->qualtrans) {
- peer->qualtx = ast_tvnow();
- ast_set_flag(peer->qualtrans, FLAG_ISQUAL);
- dundi_send(peer->qualtrans, DUNDI_COMMAND_NULL, 0, 1, NULL);
- }
- }
-}
-static void populate_addr(struct dundi_peer *peer, dundi_eid *eid)
-{
- char data[256];
- char *c;
- int port, expire;
- char eid_str[20];
- dundi_eid_to_str(eid_str, sizeof(eid_str), eid);
- if (!ast_db_get("dundi/dpeers", eid_str, data, sizeof(data))) {
- c = strchr(data, ':');
- if (c) {
- *c = '\0';
- c++;
- if (sscanf(c, "%d:%d", &port, &expire) == 2) {
- /* Got it! */
- inet_aton(data, &peer->addr.sin_addr);
- peer->addr.sin_family = AF_INET;
- peer->addr.sin_port = htons(port);
- peer->registerexpire = ast_sched_add(sched, (expire + 10) * 1000, do_register_expire, peer);
- }
- }
- }
-}
-
-
-static void build_peer(dundi_eid *eid, struct ast_variable *v, int *globalpcmode)
-{
- struct dundi_peer *peer;
- struct ast_hostent he;
- struct hostent *hp;
- dundi_eid testeid;
- int needregister=0;
- char eid_str[20];
-
- ast_mutex_lock(&peerlock);
- peer = peers;
- while(peer) {
- if (!dundi_eid_cmp(&peer->eid, eid)) {
- break;
- }
- peer = peer->next;
- }
- if (!peer) {
- /* Add us into the list */
- peer = malloc(sizeof(struct dundi_peer));
- if (peer) {
- memset(peer, 0, sizeof(struct dundi_peer));
- peer->registerid = -1;
- peer->registerexpire = -1;
- peer->qualifyid = -1;
- peer->addr.sin_family = AF_INET;
- peer->addr.sin_port = htons(DUNDI_PORT);
- populate_addr(peer, eid);
- peer->next = peers;
- peers = peer;
- }
- }
- if (peer) {
- peer->dead = 0;
- peer->eid = *eid;
- peer->us_eid = global_eid;
- destroy_permissions(peer->permit);
- destroy_permissions(peer->include);
- peer->permit = NULL;
- peer->include = NULL;
- if (peer->registerid > -1)
- ast_sched_del(sched, peer->registerid);
- peer->registerid = -1;
- while(v) {
- if (!strcasecmp(v->name, "inkey")) {
- ast_copy_string(peer->inkey, v->value, sizeof(peer->inkey));
- } else if (!strcasecmp(v->name, "outkey")) {
- ast_copy_string(peer->outkey, v->value, sizeof(peer->outkey));
- } else if (!strcasecmp(v->name, "host")) {
- if (!strcasecmp(v->value, "dynamic")) {
- peer->dynamic = 1;
- } else {
- hp = ast_gethostbyname(v->value, &he);
- if (hp) {
- memcpy(&peer->addr.sin_addr, hp->h_addr, sizeof(peer->addr.sin_addr));
- peer->dynamic = 0;
- } else {
- ast_log(LOG_WARNING, "Unable to find host '%s' at line %d\n", v->value, v->lineno);
- peer->dead = 1;
- }
- }
- } else if (!strcasecmp(v->name, "ustothem")) {
- if (!dundi_str_to_eid(&testeid, v->value))
- peer->us_eid = testeid;
- else
- ast_log(LOG_WARNING, "'%s' is not a valid DUNDi Entity Identifier at line %d\n", v->value, v->lineno);
- } else if (!strcasecmp(v->name, "include")) {
- peer->include = append_permission(peer->include, v->value, 1);
- } else if (!strcasecmp(v->name, "permit")) {
- peer->permit = append_permission(peer->permit, v->value, 1);
- } else if (!strcasecmp(v->name, "noinclude")) {
- peer->include = append_permission(peer->include, v->value, 0);
- } else if (!strcasecmp(v->name, "deny")) {
- peer->permit = append_permission(peer->permit, v->value, 0);
- } else if (!strcasecmp(v->name, "register")) {
- needregister = ast_true(v->value);
- } else if (!strcasecmp(v->name, "order")) {
- if (!strcasecmp(v->value, "primary"))
- peer->order = 0;
- else if (!strcasecmp(v->value, "secondary"))
- peer->order = 1;
- else if (!strcasecmp(v->value, "tertiary"))
- peer->order = 2;
- else if (!strcasecmp(v->value, "quartiary"))
- peer->order = 3;
- else {
- ast_log(LOG_WARNING, "'%s' is not a valid order, should be primary, secondary, tertiary or quartiary at line %d\n", v->value, v->lineno);
- }
- } else if (!strcasecmp(v->name, "qualify")) {
- if (!strcasecmp(v->value, "no")) {
- peer->maxms = 0;
- } else if (!strcasecmp(v->value, "yes")) {
- peer->maxms = DEFAULT_MAXMS;
- } else if (sscanf(v->value, "%d", &peer->maxms) != 1) {
- ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of dundi.conf\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), v->lineno);
- peer->maxms = 0;
- }
- } else if (!strcasecmp(v->name, "model")) {
- if (!strcasecmp(v->value, "inbound"))
- peer->model = DUNDI_MODEL_INBOUND;
- else if (!strcasecmp(v->value, "outbound"))
- peer->model = DUNDI_MODEL_OUTBOUND;
- else if (!strcasecmp(v->value, "symmetric"))
- peer->model = DUNDI_MODEL_SYMMETRIC;
- else if (!strcasecmp(v->value, "none"))
- peer->model = 0;
- else {
- ast_log(LOG_WARNING, "Unknown model '%s', should be 'none', 'outbound', 'inbound', or 'symmetric' at line %d\n",
- v->value, v->lineno);
- }
- } else if (!strcasecmp(v->name, "precache")) {
- if (!strcasecmp(v->value, "inbound"))
- peer->pcmodel = DUNDI_MODEL_INBOUND;
- else if (!strcasecmp(v->value, "outbound"))
- peer->pcmodel = DUNDI_MODEL_OUTBOUND;
- else if (!strcasecmp(v->value, "symmetric"))
- peer->pcmodel = DUNDI_MODEL_SYMMETRIC;
- else if (!strcasecmp(v->value, "none"))
- peer->pcmodel = 0;
- else {
- ast_log(LOG_WARNING, "Unknown pcmodel '%s', should be 'none', 'outbound', 'inbound', or 'symmetric' at line %d\n",
- v->value, v->lineno);
- }
- }
- v = v->next;
- }
- (*globalpcmode) |= peer->pcmodel;
- if (!peer->model && !peer->pcmodel) {
- ast_log(LOG_WARNING, "Peer '%s' lacks a model or pcmodel, discarding!\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- peer->dead = 1;
- } else if ((peer->model & DUNDI_MODEL_INBOUND) && (peer->pcmodel & DUNDI_MODEL_OUTBOUND)) {
- ast_log(LOG_WARNING, "Peer '%s' may not be both inbound/symmetric model and outbound/symmetric precache model, discarding!\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- peer->dead = 1;
- } else if ((peer->model & DUNDI_MODEL_OUTBOUND) && (peer->pcmodel & DUNDI_MODEL_INBOUND)) {
- ast_log(LOG_WARNING, "Peer '%s' may not be both outbound/symmetric model and inbound/symmetric precache model, discarding!\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- peer->dead = 1;
- } else if (peer->include && !(peer->model & DUNDI_MODEL_OUTBOUND) && !(peer->pcmodel & DUNDI_MODEL_INBOUND)) {
- ast_log(LOG_WARNING, "Peer '%s' is supposed to be included in outbound searches but isn't an outbound peer or inbound precache!\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- } else if (peer->permit && !(peer->model & DUNDI_MODEL_INBOUND) && !(peer->pcmodel & DUNDI_MODEL_OUTBOUND)) {
- ast_log(LOG_WARNING, "Peer '%s' is supposed to have permission for some inbound searches but isn't an inbound peer or outbound precache!\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- } else {
- if (needregister) {
- peer->registerid = ast_sched_add(sched, 2000, do_register, peer);
- }
- qualify_peer(peer, 1);
- }
- }
- ast_mutex_unlock(&peerlock);
-}
-
-static int dundi_helper(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *data, int flag)
-{
- struct dundi_result results[MAX_RESULTS];
- int res;
- int x;
- int found = 0;
- if (!strncasecmp(context, "macro-", 6)) {
- if (!chan) {
- ast_log(LOG_NOTICE, "Can't use macro mode without a channel!\n");
- return -1;
- }
- /* If done as a macro, use macro extension */
- if (!strcasecmp(exten, "s")) {
- exten = pbx_builtin_getvar_helper(chan, "ARG1");
- if (ast_strlen_zero(exten))
- exten = chan->macroexten;
- if (ast_strlen_zero(exten))
- exten = chan->exten;
- if (ast_strlen_zero(exten)) {
- ast_log(LOG_WARNING, "Called in Macro mode with no ARG1 or MACRO_EXTEN?\n");
- return -1;
- }
- }
- if (ast_strlen_zero(data))
- data = "e164";
- } else {
- if (ast_strlen_zero(data))
- data = context;
- }
- res = dundi_lookup(results, MAX_RESULTS, chan, data, exten, 0);
- for (x=0;x<res;x++) {
- if (ast_test_flag(results + x, flag))
- found++;
- }
- if (found >= priority)
- return 1;
- return 0;
-}
-
-static int dundi_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- return dundi_helper(chan, context, exten, priority, data, DUNDI_FLAG_EXISTS);
-}
-
-static int dundi_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- return dundi_helper(chan, context, exten, priority, data, DUNDI_FLAG_CANMATCH);
-}
-
-static int dundi_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data)
-{
- struct dundi_result results[MAX_RESULTS];
- int res;
- int x=0;
- char req[1024];
- struct ast_app *dial;
-
- if (!strncasecmp(context, "macro-", 6)) {
- if (!chan) {
- ast_log(LOG_NOTICE, "Can't use macro mode without a channel!\n");
- return -1;
- }
- /* If done as a macro, use macro extension */
- if (!strcasecmp(exten, "s")) {
- exten = pbx_builtin_getvar_helper(chan, "ARG1");
- if (ast_strlen_zero(exten))
- exten = chan->macroexten;
- if (ast_strlen_zero(exten))
- exten = chan->exten;
- if (ast_strlen_zero(exten)) {
- ast_log(LOG_WARNING, "Called in Macro mode with no ARG1 or MACRO_EXTEN?\n");
- return -1;
- }
- }
- if (ast_strlen_zero(data))
- data = "e164";
- } else {
- if (ast_strlen_zero(data))
- data = context;
- }
- res = dundi_lookup(results, MAX_RESULTS, chan, data, exten, 0);
- if (res > 0) {
- sort_results(results, res);
- for (x=0;x<res;x++) {
- if (ast_test_flag(results + x, DUNDI_FLAG_EXISTS)) {
- if (!--priority)
- break;
- }
- }
- }
- if (x < res) {
- /* Got a hit! */
- snprintf(req, sizeof(req), "%s/%s", results[x].tech, results[x].dest);
- dial = pbx_findapp("Dial");
- if (dial)
- res = pbx_exec(chan, dial, req, newstack);
- } else
- res = -1;
- return res;
-}
-
-static int dundi_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- return dundi_helper(chan, context, exten, priority, data, DUNDI_FLAG_MATCHMORE);
-}
-
-static struct ast_switch dundi_switch =
-{
- name: "DUNDi",
- description: "DUNDi Discovered Dialplan Switch",
- exists: dundi_exists,
- canmatch: dundi_canmatch,
- exec: dundi_exec,
- matchmore: dundi_matchmore,
-};
-
-static int set_config(char *config_file, struct sockaddr_in* sin)
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- char *cat;
- int format;
- int x;
- char hn[MAXHOSTNAMELEN] = "";
- struct ast_hostent he;
- struct hostent *hp;
- struct sockaddr_in sin2;
- static int last_port = 0;
- int globalpcmodel = 0;
- dundi_eid testeid;
-
- dundi_ttl = DUNDI_DEFAULT_TTL;
- dundi_cache_time = DUNDI_DEFAULT_CACHE_TIME;
- cfg = ast_config_load(config_file);
-
-
- if (!cfg) {
- ast_log(LOG_ERROR, "Unable to load config %s\n", config_file);
- return -1;
- }
- ipaddr[0] = '\0';
- if (!gethostname(hn, sizeof(hn)-1)) {
- hp = ast_gethostbyname(hn, &he);
- if (hp) {
- memcpy(&sin2.sin_addr, hp->h_addr, sizeof(sin2.sin_addr));
- ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin2.sin_addr);
- } else
- ast_log(LOG_WARNING, "Unable to look up host '%s'\n", hn);
- } else
- ast_log(LOG_WARNING, "Unable to get host name!\n");
- ast_mutex_lock(&peerlock);
- reset_global_eid();
- global_storehistory = 0;
- ast_copy_string(secretpath, "dundi", sizeof(secretpath));
- v = ast_variable_browse(cfg, "general");
- while(v) {
- if (!strcasecmp(v->name, "port")){
- sin->sin_port = ntohs(atoi(v->value));
- if(last_port==0){
- last_port=sin->sin_port;
- } else if(sin->sin_port != last_port)
- ast_log(LOG_WARNING, "change to port ignored until next asterisk re-start\n");
- } else if (!strcasecmp(v->name, "bindaddr")) {
- struct hostent *hp;
- struct ast_hostent he;
- hp = ast_gethostbyname(v->value, &he);
- if (hp) {
- memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr));
- } else
- ast_log(LOG_WARNING, "Invalid host/IP '%s'\n", v->value);
- } else if (!strcasecmp(v->name, "authdebug")) {
- authdebug = ast_true(v->value);
- } else if (!strcasecmp(v->name, "ttl")) {
- if ((sscanf(v->value, "%d", &x) == 1) && (x > 0) && (x < DUNDI_DEFAULT_TTL)) {
- dundi_ttl = x;
- } else {
- ast_log(LOG_WARNING, "'%s' is not a valid TTL at line %d, must be number from 1 to %d\n",
- v->value, v->lineno, DUNDI_DEFAULT_TTL);
- }
- } else if (!strcasecmp(v->name, "autokill")) {
- if (sscanf(v->value, "%d", &x) == 1) {
- if (x >= 0)
- global_autokilltimeout = x;
- else
- ast_log(LOG_NOTICE, "Nice try, but autokill has to be >0 or 'yes' or 'no' at line %d\n", v->lineno);
- } else if (ast_true(v->value)) {
- global_autokilltimeout = DEFAULT_MAXMS;
- } else {
- global_autokilltimeout = 0;
- }
- } else if (!strcasecmp(v->name, "entityid")) {
- if (!dundi_str_to_eid(&testeid, v->value))
- global_eid = testeid;
- else
- ast_log(LOG_WARNING, "Invalid global endpoint identifier '%s' at line %d\n", v->value, v->lineno);
- } else if (!strcasecmp(v->name, "tos")) {
- if (sscanf(v->value, "%d", &format) == 1)
- tos = format & 0xff;
- else if (!strcasecmp(v->value, "lowdelay"))
- tos = IPTOS_LOWDELAY;
- else if (!strcasecmp(v->value, "throughput"))
- tos = IPTOS_THROUGHPUT;
- else if (!strcasecmp(v->value, "reliability"))
- tos = IPTOS_RELIABILITY;
-#if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(SOLARIS)
- else if (!strcasecmp(v->value, "mincost"))
- tos = IPTOS_MINCOST;
-#endif
- else if (!strcasecmp(v->value, "none"))
- tos = 0;
- else
-#if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(SOLARIS)
- ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
-#else
- ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', or 'none'\n", v->lineno);
-#endif
- } else if (!strcasecmp(v->name, "department")) {
- ast_copy_string(dept, v->value, sizeof(dept));
- } else if (!strcasecmp(v->name, "organization")) {
- ast_copy_string(org, v->value, sizeof(org));
- } else if (!strcasecmp(v->name, "locality")) {
- ast_copy_string(locality, v->value, sizeof(locality));
- } else if (!strcasecmp(v->name, "stateprov")) {
- ast_copy_string(stateprov, v->value, sizeof(stateprov));
- } else if (!strcasecmp(v->name, "country")) {
- ast_copy_string(country, v->value, sizeof(country));
- } else if (!strcasecmp(v->name, "email")) {
- ast_copy_string(email, v->value, sizeof(email));
- } else if (!strcasecmp(v->name, "phone")) {
- ast_copy_string(phone, v->value, sizeof(phone));
- } else if (!strcasecmp(v->name, "storehistory")) {
- global_storehistory = ast_true(v->value);
- } else if (!strcasecmp(v->name, "cachetime")) {
- if ((sscanf(v->value, "%d", &x) == 1)) {
- dundi_cache_time = x;
- } else {
- ast_log(LOG_WARNING, "'%s' is not a valid cache time at line %d. Using default value '%d'.\n",
- v->value, v->lineno, DUNDI_DEFAULT_CACHE_TIME);
- }
- }
- v = v->next;
- }
- ast_mutex_unlock(&peerlock);
- mark_mappings();
- v = ast_variable_browse(cfg, "mappings");
- while(v) {
- build_mapping(v->name, v->value);
- v = v->next;
- }
- prune_mappings();
- mark_peers();
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (strcasecmp(cat, "general") && strcasecmp(cat, "mappings")) {
- /* Entries */
- if (!dundi_str_to_eid(&testeid, cat))
- build_peer(&testeid, ast_variable_browse(cfg, cat), &globalpcmodel);
- else
- ast_log(LOG_NOTICE, "Ignoring invalid EID entry '%s'\n", cat);
- }
- cat = ast_category_browse(cfg, cat);
- }
- prune_peers();
- ast_config_destroy(cfg);
- load_password();
- if (globalpcmodel & DUNDI_MODEL_OUTBOUND)
- dundi_precache_full();
- return 0;
-}
-
-int unload_module(void)
-{
- int res;
- STANDARD_HANGUP_LOCALUSERS;
- ast_cli_unregister(&cli_debug);
- ast_cli_unregister(&cli_store_history);
- ast_cli_unregister(&cli_flush);
- ast_cli_unregister(&cli_no_debug);
- ast_cli_unregister(&cli_no_store_history);
- ast_cli_unregister(&cli_show_peers);
- ast_cli_unregister(&cli_show_entityid);
- ast_cli_unregister(&cli_show_trans);
- ast_cli_unregister(&cli_show_requests);
- ast_cli_unregister(&cli_show_mappings);
- ast_cli_unregister(&cli_show_precache);
- ast_cli_unregister(&cli_show_peer);
- ast_cli_unregister(&cli_lookup);
- ast_cli_unregister(&cli_precache);
- ast_cli_unregister(&cli_queryeid);
- ast_unregister_switch(&dundi_switch);
- ast_custom_function_unregister(&dundi_function);
- res = ast_unregister_application(app);
- sched_context_destroy(sched);
- return res;
-}
-
-int reload(void)
-{
- struct sockaddr_in sin;
- set_config("dundi.conf",&sin);
- return 0;
-}
-
-int load_module(void)
-{
- int res = 0;
- struct sockaddr_in sin;
- char iabuf[INET_ADDRSTRLEN];
-
- dundi_set_output(dundi_debug_output);
- dundi_set_error(dundi_error_output);
-
- sin.sin_family = AF_INET;
- sin.sin_port = ntohs(DUNDI_PORT);
- sin.sin_addr.s_addr = INADDR_ANY;
-
- /* Make a UDP socket */
- io = io_context_create();
- sched = sched_context_create();
-
- if (!io || !sched) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
-
- set_config("dundi.conf",&sin);
-
- netsocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
-
- if (netsocket < 0) {
- ast_log(LOG_ERROR, "Unable to create network socket: %s\n", strerror(errno));
- return -1;
- }
- if (bind(netsocket,(struct sockaddr *)&sin, sizeof(sin))) {
- ast_log(LOG_ERROR, "Unable to bind to %s port %d: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port), strerror(errno));
- return -1;
- }
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos);
-
- if (setsockopt(netsocket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))
- ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
-
- res = start_network_thread();
- if (res) {
- ast_log(LOG_ERROR, "Unable to start network thread\n");
- close(netsocket);
- return -1;
- }
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "DUNDi Ready and Listening on %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
-
- ast_cli_register(&cli_debug);
- ast_cli_register(&cli_store_history);
- ast_cli_register(&cli_flush);
- ast_cli_register(&cli_no_debug);
- ast_cli_register(&cli_no_store_history);
- ast_cli_register(&cli_show_peers);
- ast_cli_register(&cli_show_entityid);
- ast_cli_register(&cli_show_trans);
- ast_cli_register(&cli_show_requests);
- ast_cli_register(&cli_show_mappings);
- ast_cli_register(&cli_show_precache);
- ast_cli_register(&cli_show_peer);
- ast_cli_register(&cli_lookup);
- ast_cli_register(&cli_precache);
- ast_cli_register(&cli_queryeid);
- if (ast_register_switch(&dundi_switch))
- ast_log(LOG_ERROR, "Unable to register DUNDi switch\n");
- ast_register_application(app, dundi_lookup_exec, synopsis, descrip);
- ast_custom_function_register(&dundi_function);
-
- return res;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- /* XXX DUNDi cannot be unloaded XXX */
- return 1;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/pbx/pbx_gtkconsole.c b/1.2-netsec/pbx/pbx_gtkconsole.c
deleted file mode 100644
index f0d118b89..000000000
--- a/1.2-netsec/pbx/pbx_gtkconsole.c
+++ /dev/null
@@ -1,518 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief GTK Console monitor -- very kludgy right now
- *
- */
-
-/*
- * I know this might seem somewhat pointless in its current phase, but one
- * of the most important parts of this module is demonstrate that modules
- * can require other external libraries and still be loaded (in this
- * case, a host of libraries involving gtk), so long as they are properly
- * linked (see the Makefile)
- */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <sys/time.h>
-
-#include <gtk/gtk.h>
-#include <glib.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/pbx.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/cli.h"
-#include "asterisk/utils.h"
-
-AST_MUTEX_DEFINE_STATIC(verb_lock);
-
-static pthread_t console_thread;
-
-static int inuse=0;
-static int clipipe[2];
-static int cleanupid = -1;
-
-static char *dtext = "Asterisk PBX Console (GTK Version)";
-
-static GtkWidget *window;
-static GtkWidget *quit;
-static GtkWidget *closew;
-static GtkWidget *verb;
-static GtkWidget *modules;
-static GtkWidget *statusbar;
-static GtkWidget *cli;
-
-static struct timeval last;
-
-static void update_statusbar(char *msg)
-{
- gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 1);
- gtk_statusbar_push(GTK_STATUSBAR(statusbar), 1, msg);
-}
-
-int unload_module(void)
-{
- if (inuse) {
- /* Kill off the main thread */
- pthread_cancel(console_thread);
- gdk_threads_enter();
- gtk_widget_destroy(window);
- gdk_threads_leave();
- close(clipipe[0]);
- close(clipipe[1]);
- }
- return 0;
-}
-
-static int cleanup(void *useless)
-{
- gdk_threads_enter();
- gtk_clist_thaw(GTK_CLIST(verb));
- gtk_widget_queue_resize(verb->parent);
- gtk_clist_moveto(GTK_CLIST(verb), GTK_CLIST(verb)->rows - 1, 0, 0, 0);
- cleanupid = -1;
- gdk_threads_leave();
- return 0;
-}
-
-
-static void __verboser(const char *stuff, int opos, int replacelast, int complete)
-{
- char *s2[2];
- struct timeval tv;
- int ms;
- s2[0] = (char *)stuff;
- s2[1] = NULL;
- gtk_clist_freeze(GTK_CLIST(verb));
- if (replacelast)
- gtk_clist_remove(GTK_CLIST(verb), GTK_CLIST(verb)->rows - 1);
- gtk_clist_append(GTK_CLIST(verb), s2);
- if (!ast_tvzero(last)) {
- gdk_threads_leave();
- gettimeofday(&tv, NULL);
- if (cleanupid > -1)
- gtk_timeout_remove(cleanupid);
- ms = ast_tvdiff_ms(tv, last);
- if (ms < 100) {
- /* We just got a message within 100ms, so just schedule an update
- in the near future */
- cleanupid = gtk_timeout_add(200, cleanup, NULL);
- } else {
- cleanup(&cleanupid);
- }
- last = tv;
- } else {
- gettimeofday(&last, NULL);
- }
-}
-
-static void verboser(const char *stuff, int opos, int replacelast, int complete)
-{
- ast_mutex_lock(&verb_lock);
- /* Lock appropriately if we're really being called in verbose mode */
- __verboser(stuff, opos, replacelast, complete);
- ast_mutex_unlock(&verb_lock);
-}
-
-static void cliinput(void *data, int source, GdkInputCondition ic)
-{
- static char buf[256];
- static int offset = 0;
- int res;
- char *c;
- char *l;
- char n;
- /* Read as much stuff is there */
- res = read(source, buf + offset, sizeof(buf) - 1 - offset);
- if (res > -1)
- buf[res + offset] = '\0';
- /* make sure we've null terminated whatever we have so far */
- c = buf;
- l = buf;
- while(*c) {
- if (*c == '\n') {
- /* Keep the trailing \n */
- c++;
- n = *c;
- *c = '\0';
- __verboser(l, 0, 0, 1);
- *(c - 1) = '\0';
- *c = n;
- l = c;
- } else
- c++;
- }
- if (strlen(l)) {
- /* We have some left over */
- memmove(buf, l, strlen(l) + 1);
- offset = strlen(buf);
- } else {
- offset = 0;
- }
-
-}
-
-
-static void remove_module(void)
-{
- int res;
- char *module;
- char buf[256];
- if (GTK_CLIST(modules)->selection) {
- module= (char *)gtk_clist_get_row_data(GTK_CLIST(modules), (int) GTK_CLIST(modules)->selection->data);
- gdk_threads_leave();
- res = ast_unload_resource(module, 0);
- gdk_threads_enter();
- if (res) {
- snprintf(buf, sizeof(buf), "Module '%s' is in use", module);
- update_statusbar(buf);
- } else {
- snprintf(buf, sizeof(buf), "Module '%s' removed", module);
- update_statusbar(buf);
- }
- }
-}
-static void reload_module(void)
-{
- int res, x;
- char *module;
- char buf[256];
- if (GTK_CLIST(modules)->selection) {
- module= (char *)gtk_clist_get_row_data(GTK_CLIST(modules), (int) GTK_CLIST(modules)->selection->data);
- module = strdup(module);
- if (module) {
- gdk_threads_leave();
- res = ast_unload_resource(module, 0);
- gdk_threads_enter();
- if (res) {
- snprintf(buf, sizeof(buf), "Module '%s' is in use", module);
- update_statusbar(buf);
- } else {
- gdk_threads_leave();
- res = ast_load_resource(module);
- gdk_threads_enter();
- if (res) {
- snprintf(buf, sizeof(buf), "Error reloading module '%s'", module);
- } else {
- snprintf(buf, sizeof(buf), "Module '%s' reloaded", module);
- }
- for (x=0; x < GTK_CLIST(modules)->rows; x++) {
- if (!strcmp((char *)gtk_clist_get_row_data(GTK_CLIST(modules), x), module)) {
- gtk_clist_select_row(GTK_CLIST(modules), x, -1);
- break;
- }
- }
- update_statusbar(buf);
-
- }
- free(module);
- }
- }
-}
-
-static void file_ok_sel(GtkWidget *w, GtkFileSelection *fs)
-{
- char tmp[AST_CONFIG_MAX_PATH];
- char *module = gtk_file_selection_get_filename(fs);
- char buf[256];
- snprintf(tmp, sizeof(tmp), "%s/", ast_config_AST_MODULE_DIR);
- if (!strncmp(module, (char *)tmp, strlen(tmp)))
- module += strlen(tmp);
- gdk_threads_leave();
- if (ast_load_resource(module)) {
- snprintf(buf, sizeof(buf), "Error loading module '%s'.", module);
- update_statusbar(buf);
- } else {
- snprintf(buf, sizeof(buf), "Module '%s' loaded", module);
- update_statusbar(buf);
- }
- gdk_threads_enter();
- gtk_widget_destroy(GTK_WIDGET(fs));
-}
-
-static void add_module(void)
-{
- char tmp[AST_CONFIG_MAX_PATH];
- GtkWidget *filew;
- snprintf(tmp, sizeof(tmp), "%s/*.so", ast_config_AST_MODULE_DIR);
- filew = gtk_file_selection_new("Load Module");
- gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION(filew)->ok_button),
- "clicked", GTK_SIGNAL_FUNC(file_ok_sel), filew);
- gtk_signal_connect_object(GTK_OBJECT (GTK_FILE_SELECTION(filew)->cancel_button),
- "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(filew));
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(filew), (char *)tmp);
- gtk_widget_show(filew);
-}
-
-static int add_mod(const char *module, const char *description, int usecount, const char *like)
-{
- char use[10];
- char *pass[4];
- int row;
- snprintf(use, sizeof(use), "%d", usecount);
- pass[0] = module;
- pass[1] = description;
- pass[2] = use;
- pass[3] = NULL;
- row = gtk_clist_append(GTK_CLIST(modules), pass);
- gtk_clist_set_row_data(GTK_CLIST(modules), row, module);
- return 0;
-}
-
-static int mod_update(void)
-{
- char *module= NULL;
- /* Update the mod stuff */
- if (GTK_CLIST(modules)->selection) {
- module= (char *)gtk_clist_get_row_data(GTK_CLIST(modules), (int) GTK_CLIST(modules)->selection->data);
- }
- gtk_clist_freeze(GTK_CLIST(modules));
- gtk_clist_clear(GTK_CLIST(modules));
- ast_update_module_list(add_mod, NULL);
- if (module)
- gtk_clist_select_row(GTK_CLIST(modules), gtk_clist_find_row_from_data(GTK_CLIST(modules), module), -1);
- gtk_clist_thaw(GTK_CLIST(modules));
- return 1;
-}
-
-static void exit_now(GtkWidget *widget, gpointer data)
-{
- ast_loader_unregister(mod_update);
- gtk_main_quit();
- inuse--;
- ast_update_use_count();
- ast_unregister_verbose(verboser);
- ast_unload_resource("pbx_gtkconsole", 0);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "GTK Console Monitor Exiting\n");
- /* XXX Trying to quit after calling this makes asterisk segfault XXX */
-}
-
-static void exit_completely(GtkWidget *widget, gpointer data)
-{
-#if 0
- /* Clever... */
- ast_cli_command(clipipe[1], "quit");
-#else
- kill(getpid(), SIGTERM);
-#endif
-}
-
-static void exit_nicely(GtkWidget *widget, gpointer data)
-{
- fflush(stdout);
- gtk_widget_destroy(window);
-}
-
-static void *consolethread(void *data)
-{
- gtk_widget_show(window);
- gdk_threads_enter();
- gtk_main();
- gdk_threads_leave();
- return NULL;
-}
-
-static int cli_activate(void)
-{
- char buf[256] = "";
- strncpy(buf, gtk_entry_get_text(GTK_ENTRY(cli)), sizeof(buf) - 1);
- gtk_entry_set_text(GTK_ENTRY(cli), "");
- if (strlen(buf)) {
- ast_cli_command(clipipe[1], buf);
- }
- return TRUE;
-}
-
-static int show_console(void)
-{
- GtkWidget *hbox;
- GtkWidget *wbox;
- GtkWidget *notebook;
- GtkWidget *sw;
- GtkWidget *bbox, *hbbox, *add, *removew, *reloadw;
- char *modtitles[3] = { "Module", "Description", "Use Count" };
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
- statusbar = gtk_statusbar_new();
- gtk_widget_show(statusbar);
-
- gtk_signal_connect(GTK_OBJECT(window), "delete_event",
- GTK_SIGNAL_FUNC (exit_nicely), window);
- gtk_signal_connect(GTK_OBJECT(window), "destroy",
- GTK_SIGNAL_FUNC (exit_now), window);
- gtk_container_set_border_width(GTK_CONTAINER(window), 10);
-
- quit = gtk_button_new_with_label("Quit Asterisk");
- gtk_signal_connect(GTK_OBJECT(quit), "clicked",
- GTK_SIGNAL_FUNC (exit_completely), window);
- gtk_widget_show(quit);
-
- closew = gtk_button_new_with_label("Close Window");
- gtk_signal_connect(GTK_OBJECT(closew), "clicked",
- GTK_SIGNAL_FUNC (exit_nicely), window);
- gtk_widget_show(closew);
-
- notebook = gtk_notebook_new();
- verb = gtk_clist_new(1);
- gtk_clist_columns_autosize(GTK_CLIST(verb));
- sw = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
- gtk_container_add(GTK_CONTAINER(sw), verb);
- gtk_widget_show(verb);
- gtk_widget_show(sw);
- gtk_widget_set_usize(verb, 640, 400);
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, gtk_label_new("Verbose Status"));
-
-
- modules = gtk_clist_new_with_titles(3, modtitles);
- gtk_clist_columns_autosize(GTK_CLIST(modules));
- gtk_clist_set_column_auto_resize(GTK_CLIST(modules), 0, TRUE);
- gtk_clist_set_column_auto_resize(GTK_CLIST(modules), 1, TRUE);
- gtk_clist_set_column_auto_resize(GTK_CLIST(modules), 2, TRUE);
- gtk_clist_set_sort_column(GTK_CLIST(modules), 0);
- gtk_clist_set_auto_sort(GTK_CLIST(modules), TRUE);
- gtk_clist_column_titles_passive(GTK_CLIST(modules));
- sw = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
- gtk_container_add(GTK_CONTAINER(sw), modules);
- gtk_clist_set_selection_mode(GTK_CLIST(modules), GTK_SELECTION_BROWSE);
- gtk_widget_show(modules);
- gtk_widget_show(sw);
-
- add = gtk_button_new_with_label("Load...");
- gtk_widget_show(add);
- removew = gtk_button_new_with_label("Unload");
- gtk_widget_show(removew);
- reloadw = gtk_button_new_with_label("Reload");
- gtk_widget_show(reloadw);
- gtk_signal_connect(GTK_OBJECT(removew), "clicked",
- GTK_SIGNAL_FUNC (remove_module), window);
- gtk_signal_connect(GTK_OBJECT(add), "clicked",
- GTK_SIGNAL_FUNC (add_module), window);
- gtk_signal_connect(GTK_OBJECT(reloadw), "clicked",
- GTK_SIGNAL_FUNC (reload_module), window);
-
- bbox = gtk_vbox_new(FALSE, 5);
- gtk_widget_show(bbox);
-
- gtk_widget_set_usize(bbox, 100, -1);
- gtk_box_pack_start(GTK_BOX(bbox), add, FALSE, FALSE, 5);
- gtk_box_pack_start(GTK_BOX(bbox), removew, FALSE, FALSE, 5);
- gtk_box_pack_start(GTK_BOX(bbox), reloadw, FALSE, FALSE, 5);
-
- hbbox = gtk_hbox_new(FALSE, 5);
- gtk_widget_show(hbbox);
-
- gtk_box_pack_start(GTK_BOX(hbbox), sw, TRUE, TRUE, 5);
- gtk_box_pack_start(GTK_BOX(hbbox), bbox, FALSE, FALSE, 5);
-
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), hbbox, gtk_label_new("Module Information"));
-
- gtk_widget_show(notebook);
-
- wbox = gtk_hbox_new(FALSE, 5);
- gtk_widget_show(wbox);
- gtk_box_pack_end(GTK_BOX(wbox), quit, FALSE, FALSE, 5);
- gtk_box_pack_end(GTK_BOX(wbox), closew, FALSE, FALSE, 5);
-
- hbox = gtk_vbox_new(FALSE, 0);
- gtk_widget_show(hbox);
-
- /* Command line */
- cli = gtk_entry_new();
- gtk_widget_show(cli);
-
- gtk_signal_connect(GTK_OBJECT(cli), "activate",
- GTK_SIGNAL_FUNC (cli_activate), NULL);
-
- gtk_box_pack_start(GTK_BOX(hbox), notebook, TRUE, TRUE, 5);
- gtk_box_pack_start(GTK_BOX(hbox), wbox, FALSE, FALSE, 5);
- gtk_box_pack_start(GTK_BOX(hbox), cli, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), statusbar, FALSE, FALSE, 0);
- gtk_container_add(GTK_CONTAINER(window), hbox);
- gtk_window_set_title(GTK_WINDOW(window), "Asterisk Console");
- gtk_widget_grab_focus(cli);
- ast_pthread_create(&console_thread, NULL, consolethread, NULL);
- /* XXX Okay, seriously fix me! XXX */
- usleep(100000);
- ast_register_verbose(verboser);
- gtk_clist_freeze(GTK_CLIST(verb));
- ast_loader_register(mod_update);
- gtk_clist_thaw(GTK_CLIST(verb));
- gdk_input_add(clipipe[0], GDK_INPUT_READ, cliinput, NULL);
- mod_update();
- update_statusbar("Asterisk Console Ready");
- return 0;
-}
-
-
-int load_module(void)
-{
- if (pipe(clipipe)) {
- ast_log(LOG_WARNING, "Unable to create CLI pipe\n");
- return -1;
- }
- g_thread_init(NULL);
- if (gtk_init_check(NULL, NULL)) {
- if (!show_console()) {
- inuse++;
- ast_update_use_count();
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Launched GTK Console monitor\n");
- } else
- ast_log(LOG_WARNING, "Unable to start GTK console\n");
- } else {
- if (option_debug)
- ast_log(LOG_DEBUG, "Unable to start GTK console monitor -- ignoring\n");
- else if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "GTK is not available -- skipping monitor\n");
- }
- return 0;
-}
-
-int usecount(void)
-{
- return inuse;
-}
-
-char *description(void)
-{
- return dtext;
-}
-
-char *key(void)
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/pbx/pbx_kdeconsole.cc b/1.2-netsec/pbx/pbx_kdeconsole.cc
deleted file mode 100644
index 6c2817366..000000000
--- a/1.2-netsec/pbx/pbx_kdeconsole.cc
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Asterisk -- A telephony toolkit for Linux.
- *
- * KDE Console monitor -- Class implmementation
- *
- * Copyright (C) 1999, Mark Spencer
- *
- * Mark Spencer <markster@linux-support.net>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-#include "pbx_kdeconsole.moc"
-
-KAsteriskConsole::KAsteriskConsole() : KTMainWindow()
-{
- QVBoxLayout *box;
- QFrame *f;
-
- f = new QFrame(this);
-
- setGeometry(100,100,600,400);
- /* Menus */
- file = new QPopupMenu();
- file->insertItem("&Exit", this, SLOT(slotExit()));
-
- help = kapp->getHelpMenu(TRUE, "KDE Asterisk Console\nby Mark Spencer");
-
- setCaption("Asterisk Console");
-
- /* Box */
- box = new QVBoxLayout(f, 20, 5);
-
- /* Menu bar creation */
- menu = new KMenuBar(this);
- menu->insertItem("&File", file);
- menu->insertItem("&Help", help);
- /* Verbose stuff */
- verbose = new QListBox(f, "verbose");
- /* Exit button */
- btnExit = new QPushButton("Exit", f, "exit");
- btnExit->show();
- connect(btnExit, SIGNAL(clicked()), this, SLOT(slotExit()));
-
- box->addWidget(verbose, 1);
- box->addWidget(btnExit, 0);
- setView(f, TRUE);
- statusBar()->message("Ready", 2000);
-}
-
-void KAsteriskConsole::slotExit()
-{
- close();
-}
-
-void KAsteriskConsole::closeEvent(QCloseEvent *)
-{
- kapp->quit();
-}
-
diff --git a/1.2-netsec/pbx/pbx_kdeconsole.h b/1.2-netsec/pbx/pbx_kdeconsole.h
deleted file mode 100644
index df73ab38e..000000000
--- a/1.2-netsec/pbx/pbx_kdeconsole.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Asterisk -- A telephony toolkit for Linux.
- *
- * KDE Console monitor -- Header file
- *
- * Copyright (C) 1999, Mark Spencer
- *
- * Mark Spencer <markster@linux-support.net>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-#include <kapp.h>
-#include <ktmainwindow.h>
-#include <qpushbutton.h>
-#include <kmenubar.h>
-#include <qpopupmenu.h>
-#include <qlistbox.h>
-#include <qlayout.h>
-#include <qframe.h>
-
-class KAsteriskConsole : public KTMainWindow
-{
- Q_OBJECT
-public:
- KAsteriskConsole();
- void closeEvent(QCloseEvent *);
- QListBox *verbose;
-public slots:
- void slotExit();
-private:
- void KAsteriskConsole::verboser(char *stuff, int opos, int replacelast, int complete);
- QPushButton *btnExit;
- KMenuBar *menu;
- QPopupMenu *file, *help;
-};
diff --git a/1.2-netsec/pbx/pbx_kdeconsole_main.cc b/1.2-netsec/pbx/pbx_kdeconsole_main.cc
deleted file mode 100644
index 0bb2d73e2..000000000
--- a/1.2-netsec/pbx/pbx_kdeconsole_main.cc
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Asterisk -- A telephony toolkit for Linux.
- *
- * KDE Console monitor -- Mostly glue code
- *
- * Copyright (C) 1999, Mark Spencer
- *
- * Mark Spencer <markster@linux-support.net>
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
- */
-
-#include "asterisk/module.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/lock.h"
-#include "pbx_kdeconsole.h"
-
-static char *dtext = "KDE Console Monitor";
-
-static int inuse = 0;
-
-static KAsteriskConsole *w;
-
-static void verboser(char *stuff, int opos, int replacelast, int complete)
-{
- const char *s2[2];
- s2[0] = stuff;
- s2[1] = NULL;
- if (replacelast) {
- printf("Removing %d\n", w->verbose->count());
- w->verbose->removeItem(w->verbose->count());
- }
- w->verbose->insertStrList(s2, 1, -1);
- w->verbose->setBottomItem(w->verbose->count());
-}
-
-static int kde_main(int argc, char *argv[])
-{
- KApplication a ( argc, argv );
- w = new KAsteriskConsole();
- a.setMainWidget(w);
- w->show();
- ast_register_verbose(verboser);
- return a.exec();
-}
-
-static void *kdemain(void *data)
-{
- /* It would appear kde really wants to be main */;
- char *argv[1] = { "asteriskconsole" };
- kde_main(1, argv);
- return NULL;
-}
-
-extern "C" {
-
-int unload_module(void)
-{
- return inuse;
-}
-
-int load_module(void)
-{
- pthread_t t;
- pthread_create(&t, NULL, kdemain, NULL);
- return 0;
-}
-
-int usecount(void)
-{
- return inuse;
-}
-
-char *description(void)
-{
- return dtext;
-}
-
-}
diff --git a/1.2-netsec/pbx/pbx_loopback.c b/1.2-netsec/pbx/pbx_loopback.c
deleted file mode 100644
index 5522e9b09..000000000
--- a/1.2-netsec/pbx/pbx_loopback.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Loopback PBX Module
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/frame.h"
-#include "asterisk/file.h"
-#include "asterisk/cli.h"
-#include "asterisk/lock.h"
-#include "asterisk/md5.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/chanvars.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/utils.h"
-#include "asterisk/crypto.h"
-#include "asterisk/astdb.h"
-
-static char *tdesc = "Loopback Switch";
-
-/* Loopback switch substitutes ${EXTEN}, ${CONTEXT}, and ${PRIORITY} into
- the data passed to it to try to get a string of the form:
-
- [exten]@context[:priority][/extramatch]
-
- Where exten, context, and priority are another extension, context, and priority
- to lookup and "extramatch" is an extra match restriction the *original* number
- must fit if specified. The "extramatch" begins with _ like an exten pattern
- if it is specified. Note that the search context MUST be a different context
- from the current context or the search will not succeed in an effort to reduce
- the likelihood of loops (they're still possible if you try hard, so be careful!)
-
-*/
-
-
-#define LOOPBACK_COMMON \
- char buf[1024]; \
- int res; \
- char *newexten=(char *)exten, *newcontext=(char *)context; \
- int newpriority=priority; \
- char *newpattern=NULL; \
- loopback_helper(buf, sizeof(buf), exten, context, priority, data); \
- loopback_subst(&newexten, &newcontext, &newpriority, &newpattern, buf); \
- ast_log(LOG_DEBUG, "Parsed into %s @ %s priority %d\n", newexten, newcontext, newpriority); \
- if (!strcasecmp(newcontext, context)) return -1
-
-
-static char *loopback_helper(char *buf, int buflen, const char *exten, const char *context, int priority, const char *data)
-{
- struct ast_var_t *newvariable;
- struct varshead headp;
- char tmp[80];
-
- snprintf(tmp, sizeof(tmp), "%d", priority);
- memset(buf, 0, buflen);
- AST_LIST_HEAD_INIT_NOLOCK(&headp);
- newvariable = ast_var_assign("EXTEN", exten);
- AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
- newvariable = ast_var_assign("CONTEXT", context);
- AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
- newvariable = ast_var_assign("PRIORITY", tmp);
- AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
- pbx_substitute_variables_varshead(&headp, data, buf, buflen);
- /* Substitute variables */
- while (!AST_LIST_EMPTY(&headp)) { /* List Deletion. */
- newvariable = AST_LIST_REMOVE_HEAD(&headp, entries);
- ast_var_delete(newvariable);
- }
- return buf;
-}
-
-static void loopback_subst(char **newexten, char **newcontext, int *priority, char **newpattern, char *buf)
-{
- char *con;
- char *pri;
- *newpattern = strchr(buf, '/');
- if (*newpattern) {
- *(*newpattern) = '\0';
- (*newpattern)++;
- }
- con = strchr(buf, '@');
- if (con) {
- *con = '\0';
- con++;
- pri = strchr(con, ':');
- } else
- pri = strchr(buf, ':');
- if (!ast_strlen_zero(buf))
- *newexten = buf;
- if (!ast_strlen_zero(con))
- *newcontext = con;
- if (!ast_strlen_zero(pri))
- sscanf(pri, "%d", priority);
-}
-
-static int loopback_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- LOOPBACK_COMMON;
- res = ast_exists_extension(chan, newcontext, newexten, newpriority, callerid);
- if (newpattern && !ast_extension_match(newpattern, exten))
- res = 0;
- return res;
-}
-
-static int loopback_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- LOOPBACK_COMMON;
- res = ast_canmatch_extension(chan, newcontext, newexten, newpriority, callerid);
- if (newpattern && !ast_extension_match(newpattern, exten))
- res = 0;
- return res;
-}
-
-static int loopback_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data)
-{
- LOOPBACK_COMMON;
- if (newstack)
- res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid);
- else
- res = ast_exec_extension(chan, newcontext, newexten, newpriority, callerid);
- if (newpattern && !ast_extension_match(newpattern, exten))
- res = -1;
- return res;
-}
-
-static int loopback_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- LOOPBACK_COMMON;
- res = ast_matchmore_extension(chan, newcontext, newexten, newpriority, callerid);
- if (newpattern && !ast_extension_match(newpattern, exten))
- res = 0;
- return res;
-}
-
-static struct ast_switch loopback_switch =
-{
- name: "Loopback",
- description: "Loopback Dialplan Switch",
- exists: loopback_exists,
- canmatch: loopback_canmatch,
- exec: loopback_exec,
- matchmore: loopback_matchmore,
-};
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- return 1;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-int unload_module(void)
-{
- ast_unregister_switch(&loopback_switch);
- return 0;
-}
-
-int load_module(void)
-{
- ast_register_switch(&loopback_switch);
- return 0;
-}
-
diff --git a/1.2-netsec/pbx/pbx_realtime.c b/1.2-netsec/pbx/pbx_realtime.c
deleted file mode 100644
index 4e9aba1fe..000000000
--- a/1.2-netsec/pbx/pbx_realtime.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Realtime PBX Module
- *
- * \arg See also: \ref AstARA
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/frame.h"
-#include "asterisk/term.h"
-#include "asterisk/manager.h"
-#include "asterisk/file.h"
-#include "asterisk/cli.h"
-#include "asterisk/lock.h"
-#include "asterisk/md5.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/chanvars.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/utils.h"
-#include "asterisk/crypto.h"
-#include "asterisk/astdb.h"
-
-#define MODE_MATCH 0
-#define MODE_MATCHMORE 1
-#define MODE_CANMATCH 2
-
-#define EXT_DATA_SIZE 256
-
-static char *tdesc = "Realtime Switch";
-
-/* Realtime switch looks up extensions in the supplied realtime table.
-
- [context@][realtimetable][/options]
-
- If the realtimetable is omitted it is assumed to be "extensions". If no context is
- specified the context is assumed to be whatever is the container.
-
- The realtime table should have entries for context,exten,priority,app,args
-
- The realtime table currently does not support callerid fields.
-
-*/
-
-
-#define REALTIME_COMMON(mode) \
- char *buf; \
- char *opts; \
- const char *cxt; \
- char *table; \
- int res=-1; \
- struct ast_variable *var=NULL; \
- buf = ast_strdupa(data); \
- if (buf) { \
- opts = strchr(buf, '/'); \
- if (opts) { \
- *opts='\0'; \
- opts++; \
- } else \
- opts=""; \
- table = strchr(buf, '@'); \
- if (table) { \
- *table = '\0'; \
- table++;\
- cxt = buf; \
- } else cxt = NULL; \
- if (ast_strlen_zero(cxt)) \
- cxt = context;\
- if (ast_strlen_zero(table)) \
- table = "extensions"; \
- var = realtime_switch_common(table, cxt, exten, priority, mode); \
- } else \
- res = -1;
-
-static struct ast_variable *realtime_switch_common(const char *table, const char *context, const char *exten, int priority, int mode)
-{
- struct ast_variable *var;
- struct ast_config *cfg;
- char pri[20];
- char *ematch;
- char rexten[AST_MAX_EXTENSION + 20]="";
- int match;
- snprintf(pri, sizeof(pri), "%d", priority);
- switch(mode) {
- case MODE_MATCHMORE:
- ematch = "exten LIKE";
- snprintf(rexten, sizeof(rexten), "%s_%%", exten);
- break;
- case MODE_CANMATCH:
- ematch = "exten LIKE";
- snprintf(rexten, sizeof(rexten), "%s%%", exten);
- break;
- case MODE_MATCH:
- default:
- ematch = "exten";
- strncpy(rexten, exten, sizeof(rexten) - 1);
- }
- var = ast_load_realtime(table, ematch, rexten, "context", context, "priority", pri, NULL);
- if (!var) {
- cfg = ast_load_realtime_multientry(table, "exten LIKE", "\\_%", "context", context, "priority", pri, NULL);
- if (cfg) {
- char *cat = ast_category_browse(cfg, NULL);
-
- while(cat) {
- switch(mode) {
- case MODE_MATCHMORE:
- match = ast_extension_close(cat, exten, 1);
- break;
- case MODE_CANMATCH:
- match = ast_extension_close(cat, exten, 0);
- break;
- case MODE_MATCH:
- default:
- match = ast_extension_match(cat, exten);
- }
- if (match) {
- var = ast_category_detach_variables(ast_category_get(cfg, cat));
- break;
- }
- cat = ast_category_browse(cfg, cat);
- }
- ast_config_destroy(cfg);
- }
- }
- return var;
-}
-
-static int realtime_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- REALTIME_COMMON(MODE_MATCH);
- if (var) ast_variables_destroy(var);
- if (var)
- res = 1;
- return res > 0 ? res : 0;
-}
-
-static int realtime_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- REALTIME_COMMON(MODE_CANMATCH);
- if (var) ast_variables_destroy(var);
- if (var)
- res = 1;
- return res > 0 ? res : 0;
-}
-
-static int realtime_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data)
-{
- char app[256];
- char appdata[512]="";
- char *tmp="";
- char tmp1[80];
- char tmp2[80];
- char tmp3[EXT_DATA_SIZE];
- struct ast_app *a;
- struct ast_variable *v;
- REALTIME_COMMON(MODE_MATCH);
- if (var) {
- v = var;
- while(v) {
- if (!strcasecmp(v->name, "app"))
- strncpy(app, v->value, sizeof(app) -1 );
- else if (!strcasecmp(v->name, "appdata"))
- tmp = ast_strdupa(v->value);
- v = v->next;
- }
- ast_variables_destroy(var);
- if (!ast_strlen_zero(app)) {
- a = pbx_findapp(app);
- if (a) {
- if(!ast_strlen_zero(tmp))
- pbx_substitute_variables_helper(chan, tmp, appdata, sizeof(appdata) - 1);
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Executing %s(\"%s\", \"%s\")\n",
- term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)),
- term_color(tmp2, chan->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
- term_color(tmp3, (!ast_strlen_zero(appdata) ? (char *)appdata : ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));
- manager_event(EVENT_FLAG_CALL, "Newexten",
- "Channel: %s\r\n"
- "Context: %s\r\n"
- "Extension: %s\r\n"
- "Priority: %d\r\n"
- "Application: %s\r\n"
- "AppData: %s\r\n"
- "Uniqueid: %s\r\n",
- chan->name, chan->context, chan->exten, chan->priority, app, appdata ? appdata : "(NULL)", chan->uniqueid);
-
- res = pbx_exec(chan, a, appdata, newstack);
- } else
- ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context);
- }
- }
- return res;
-}
-
-static int realtime_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
-{
- REALTIME_COMMON(MODE_MATCHMORE);
- if (var) ast_variables_destroy(var);
- if (var)
- res = 1;
- return res > 0 ? res : 0;
-}
-
-static struct ast_switch realtime_switch =
-{
- name: "Realtime",
- description: "Realtime Dialplan Switch",
- exists: realtime_exists,
- canmatch: realtime_canmatch,
- exec: realtime_exec,
- matchmore: realtime_matchmore,
-};
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- return 1;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
-int unload_module(void)
-{
- ast_unregister_switch(&realtime_switch);
- return 0;
-}
-
-int load_module(void)
-{
- ast_register_switch(&realtime_switch);
- return 0;
-}
-
diff --git a/1.2-netsec/pbx/pbx_spool.c b/1.2-netsec/pbx/pbx_spool.c
deleted file mode 100644
index a91a7e255..000000000
--- a/1.2-netsec/pbx/pbx_spool.c
+++ /dev/null
@@ -1,445 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Full-featured outgoing call spool support
- *
- */
-
-#include <sys/stat.h>
-#include <errno.h>
-#include <time.h>
-#include <utime.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <string.h>
-#include <string.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/callerid.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-
-/*
- * pbx_spool is similar in spirit to qcall, but with substantially enhanced functionality...
- * The spool file contains a header
- */
-
-static char *tdesc = "Outgoing Spool Support";
-static char qdir[255];
-
-struct outgoing {
- char fn[256];
- /* Current number of retries */
- int retries;
- /* Maximum number of retries permitted */
- int maxretries;
- /* How long to wait between retries (in seconds) */
- int retrytime;
- /* How long to wait for an answer */
- int waittime;
- /* PID which is currently calling */
- int callingpid;
-
- /* What to connect to outgoing */
- char tech[256];
- char dest[256];
-
- /* If application */
- char app[256];
- char data[256];
-
- /* If extension/context/priority */
- char exten[256];
- char context[256];
- int priority;
-
- /* CallerID Information */
- char cid_num[256];
- char cid_name[256];
-
- /* account code */
- char account[AST_MAX_ACCOUNT_CODE];
-
- /* Variables and Functions */
- struct ast_variable *vars;
-
- /* Maximum length of call */
- int maxlen;
-};
-
-static void init_outgoing(struct outgoing *o)
-{
- memset(o, 0, sizeof(struct outgoing));
- o->priority = 1;
- o->retrytime = 300;
- o->waittime = 45;
-}
-
-static void free_outgoing(struct outgoing *o)
-{
- free(o);
-}
-
-static int apply_outgoing(struct outgoing *o, char *fn, FILE *f)
-{
- char buf[256];
- char *c, *c2;
- int lineno = 0;
- struct ast_variable *var;
-
- while(fgets(buf, sizeof(buf), f)) {
- lineno++;
- /* Trim comments */
- c = buf;
- while ((c = strchr(c, '#'))) {
- if ((c == buf) || (*(c-1) == ' ') || (*(c-1) == '\t'))
- *c = '\0';
- else
- c++;
- }
-
- c = buf;
- while ((c = strchr(c, ';'))) {
- if ((c > buf) && (c[-1] == '\\')) {
- memmove(c - 1, c, strlen(c) + 1);
- c++;
- } else {
- *c = '\0';
- break;
- }
- }
-
- /* Trim trailing white space */
- while(!ast_strlen_zero(buf) && buf[strlen(buf) - 1] < 33)
- buf[strlen(buf) - 1] = '\0';
- if (!ast_strlen_zero(buf)) {
- c = strchr(buf, ':');
- if (c) {
- *c = '\0';
- c++;
- while ((*c) && (*c < 33))
- c++;
-#if 0
- printf("'%s' is '%s' at line %d\n", buf, c, lineno);
-#endif
- if (!strcasecmp(buf, "channel")) {
- strncpy(o->tech, c, sizeof(o->tech) - 1);
- if ((c2 = strchr(o->tech, '/'))) {
- *c2 = '\0';
- c2++;
- strncpy(o->dest, c2, sizeof(o->dest) - 1);
- } else {
- ast_log(LOG_NOTICE, "Channel should be in form Tech/Dest at line %d of %s\n", lineno, fn);
- o->tech[0] = '\0';
- }
- } else if (!strcasecmp(buf, "callerid")) {
- ast_callerid_split(c, o->cid_name, sizeof(o->cid_name), o->cid_num, sizeof(o->cid_num));
- } else if (!strcasecmp(buf, "application")) {
- strncpy(o->app, c, sizeof(o->app) - 1);
- } else if (!strcasecmp(buf, "data")) {
- strncpy(o->data, c, sizeof(o->data) - 1);
- } else if (!strcasecmp(buf, "maxretries")) {
- if (sscanf(c, "%d", &o->maxretries) != 1) {
- ast_log(LOG_WARNING, "Invalid max retries at line %d of %s\n", lineno, fn);
- o->maxretries = 0;
- }
- } else if (!strcasecmp(buf, "context")) {
- strncpy(o->context, c, sizeof(o->context) - 1);
- } else if (!strcasecmp(buf, "extension")) {
- strncpy(o->exten, c, sizeof(o->exten) - 1);
- } else if (!strcasecmp(buf, "priority")) {
- if ((sscanf(c, "%d", &o->priority) != 1) || (o->priority < 1)) {
- ast_log(LOG_WARNING, "Invalid priority at line %d of %s\n", lineno, fn);
- o->priority = 1;
- }
- } else if (!strcasecmp(buf, "retrytime")) {
- if ((sscanf(c, "%d", &o->retrytime) != 1) || (o->retrytime < 1)) {
- ast_log(LOG_WARNING, "Invalid retrytime at line %d of %s\n", lineno, fn);
- o->retrytime = 300;
- }
- } else if (!strcasecmp(buf, "waittime")) {
- if ((sscanf(c, "%d", &o->waittime) != 1) || (o->waittime < 1)) {
- ast_log(LOG_WARNING, "Invalid retrytime at line %d of %s\n", lineno, fn);
- o->waittime = 45;
- }
- } else if (!strcasecmp(buf, "retry")) {
- o->retries++;
- } else if (!strcasecmp(buf, "startretry")) {
- if (sscanf(c, "%d", &o->callingpid) != 1) {
- ast_log(LOG_WARNING, "Unable to retrieve calling PID!\n");
- o->callingpid = 0;
- }
- } else if (!strcasecmp(buf, "endretry") || !strcasecmp(buf, "abortretry")) {
- o->callingpid = 0;
- o->retries++;
- } else if (!strcasecmp(buf, "delayedretry")) {
- } else if (!strcasecmp(buf, "setvar") || !strcasecmp(buf, "set")) {
- c2 = c;
- strsep(&c2, "=");
- if (c2) {
- var = ast_variable_new(c, c2);
- if (var) {
- var->next = o->vars;
- o->vars = var;
- }
- } else {
- ast_log(LOG_WARNING, "Malformed Set: argument! Should be Set: Variable=value\n");
- }
- } else if (!strcasecmp(buf, "account")) {
- ast_copy_string(o->account, c, sizeof(o->account));
- } else {
- ast_log(LOG_WARNING, "Unknown keyword '%s' at line %d of %s\n", buf, lineno, fn);
- }
- } else
- ast_log(LOG_NOTICE, "Syntax error at line %d of %s\n", lineno, fn);
- }
- }
- strncpy(o->fn, fn, sizeof(o->fn) - 1);
- if (ast_strlen_zero(o->tech) || ast_strlen_zero(o->dest) || (ast_strlen_zero(o->app) && ast_strlen_zero(o->exten))) {
- ast_log(LOG_WARNING, "At least one of app or extension must be specified, along with tech and dest in file %s\n", fn);
- return -1;
- }
- return 0;
-}
-
-static void safe_append(struct outgoing *o, time_t now, char *s)
-{
- int fd;
- FILE *f;
- struct utimbuf tbuf;
- fd = open(o->fn, O_WRONLY|O_APPEND);
- if (fd > -1) {
- f = fdopen(fd, "a");
- if (f) {
- fprintf(f, "%s: %ld %d (%ld)\n", s, (long)ast_mainpid, o->retries, (long) now);
- fclose(f);
- } else
- close(fd);
- /* Update the file time */
- tbuf.actime = now;
- tbuf.modtime = now + o->retrytime;
- if (utime(o->fn, &tbuf))
- ast_log(LOG_WARNING, "Unable to set utime on %s: %s\n", o->fn, strerror(errno));
- }
-}
-
-static void *attempt_thread(void *data)
-{
- struct outgoing *o = data;
- int res, reason;
- if (!ast_strlen_zero(o->app)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for application %s(%s) (Retry %d)\n", o->tech, o->dest, o->app, o->data, o->retries);
- res = ast_pbx_outgoing_app(o->tech, AST_FORMAT_SLINEAR, o->dest, o->waittime * 1000, o->app, o->data, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL);
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for %s@%s:%d (Retry %d)\n", o->tech, o->dest, o->exten, o->context,o->priority, o->retries);
- res = ast_pbx_outgoing_exten(o->tech, AST_FORMAT_SLINEAR, o->dest, o->waittime * 1000, o->context, o->exten, o->priority, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL);
- }
- if (res) {
- ast_log(LOG_NOTICE, "Call failed to go through, reason %d\n", reason);
- if (o->retries >= o->maxretries + 1) {
- /* Max retries exceeded */
- ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt%s\n", o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : "");
- unlink(o->fn);
- } else {
- /* Notate that the call is still active */
- safe_append(o, time(NULL), "EndRetry");
- }
- } else {
- ast_log(LOG_NOTICE, "Call completed to %s/%s\n", o->tech, o->dest);
- ast_log(LOG_EVENT, "Queued call to %s/%s completed\n", o->tech, o->dest);
- unlink(o->fn);
- }
- free_outgoing(o);
- return NULL;
-}
-
-static void launch_service(struct outgoing *o)
-{
- pthread_t t;
- pthread_attr_t attr;
- int ret;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if ((ret = ast_pthread_create(&t,&attr,attempt_thread, o)) != 0) {
- ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
- free_outgoing(o);
- }
-}
-
-static int scan_service(char *fn, time_t now, time_t atime)
-{
- struct outgoing *o;
- FILE *f;
- o = malloc(sizeof(struct outgoing));
- if (o) {
- init_outgoing(o);
- f = fopen(fn, "r+");
- if (f) {
- if (!apply_outgoing(o, fn, f)) {
-#if 0
- printf("Filename: %s, Retries: %d, max: %d\n", fn, o->retries, o->maxretries);
-#endif
- fclose(f);
- if (o->retries <= o->maxretries) {
- now += o->retrytime;
- if (o->callingpid && (o->callingpid == ast_mainpid)) {
- safe_append(o, time(NULL), "DelayedRetry");
- free_outgoing(o);
- ast_log(LOG_DEBUG, "Delaying retry since we're currently running '%s'\n", o->fn);
- } else {
- /* Increment retries */
- o->retries++;
- /* If someone else was calling, they're presumably gone now
- so abort their retry and continue as we were... */
- if (o->callingpid)
- safe_append(o, time(NULL), "AbortRetry");
-
- safe_append(o, now, "StartRetry");
- launch_service(o);
- }
- return now;
- } else {
- ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt%s\n", o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : "");
- free_outgoing(o);
- unlink(fn);
- return 0;
- }
- } else {
- free_outgoing(o);
- ast_log(LOG_WARNING, "Invalid file contents in %s, deleting\n", fn);
- fclose(f);
- unlink(fn);
- }
- } else {
- free_outgoing(o);
- ast_log(LOG_WARNING, "Unable to open %s: %s, deleting\n", fn, strerror(errno));
- unlink(fn);
- }
- } else
- ast_log(LOG_WARNING, "Out of memory :(\n");
- return -1;
-}
-
-static void *scan_thread(void *unused)
-{
- struct stat st;
- DIR *dir;
- struct dirent *de;
- char fn[256];
- int res;
- time_t last = 0, next = 0, now;
- for(;;) {
- /* Wait a sec */
- sleep(1);
- time(&now);
- if (!stat(qdir, &st)) {
- if ((st.st_mtime != last) || (next && (now > next))) {
-#if 0
- printf("atime: %ld, mtime: %ld, ctime: %ld\n", st.st_atime, st.st_mtime, st.st_ctime);
- printf("Ooh, something changed / timeout\n");
-#endif
- next = 0;
- last = st.st_mtime;
- dir = opendir(qdir);
- if (dir) {
- while((de = readdir(dir))) {
- snprintf(fn, sizeof(fn), "%s/%s", qdir, de->d_name);
- if (!stat(fn, &st)) {
- if (S_ISREG(st.st_mode)) {
- if (st.st_mtime <= now) {
- res = scan_service(fn, now, st.st_atime);
- if (res > 0) {
- /* Update next service time */
- if (!next || (res < next)) {
- next = res;
- }
- } else if (res)
- ast_log(LOG_WARNING, "Failed to scan service '%s'\n", fn);
- } else {
- /* Update "next" update if necessary */
- if (!next || (st.st_mtime < next))
- next = st.st_mtime;
- }
- }
- } else
- ast_log(LOG_WARNING, "Unable to stat %s: %s\n", fn, strerror(errno));
- }
- closedir(dir);
- } else
- ast_log(LOG_WARNING, "Unable to open directory %s: %s\n", qdir, strerror(errno));
- }
- } else
- ast_log(LOG_WARNING, "Unable to stat %s\n", qdir);
- }
- return NULL;
-}
-
-int unload_module(void)
-{
- return -1;
-}
-
-int load_module(void)
-{
- pthread_t thread;
- pthread_attr_t attr;
- int ret;
- snprintf(qdir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing");
- if (mkdir(qdir, 0700) && (errno != EEXIST)) {
- ast_log(LOG_WARNING, "Unable to create queue directory %s -- outgoing spool disabled\n", qdir);
- return 0;
- }
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if ((ret = ast_pthread_create(&thread,&attr,scan_thread, NULL)) != 0) {
- ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
- return -1;
- }
- return 0;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- return 1;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/plc.c b/1.2-netsec/plc.c
deleted file mode 100644
index f0ad46eeb..000000000
--- a/1.2-netsec/plc.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Written by Steve Underwood <steveu@coppice.org>
- *
- * Copyright (C) 2004 Steve Underwood
- *
- * All rights reserved.
- *
- * 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.
- *
- * This version may be optionally licenced under the GNU LGPL licence.
- *
- * This version is disclaimed to DIGIUM for inclusion in the Asterisk project.
- */
-
-/*! \file
- *
- * \brief SpanDSP - a series of DSP components for telephony
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <limits.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/plc.h"
-
-#if !defined(FALSE)
-#define FALSE 0
-#endif
-#if !defined(TRUE)
-#define TRUE (!FALSE)
-#endif
-
-#if !defined(INT16_MAX)
-#define INT16_MAX (32767)
-#define INT16_MIN (-32767-1)
-#endif
-
-/* We do a straight line fade to zero volume in 50ms when we are filling in for missing data. */
-#define ATTENUATION_INCREMENT 0.0025 /* Attenuation per sample */
-
-#define ms_to_samples(t) (((t)*SAMPLE_RATE)/1000)
-
-static inline int16_t fsaturate(double damp)
-{
- if (damp > 32767.0)
- return INT16_MAX;
- if (damp < -32768.0)
- return INT16_MIN;
- return (int16_t) rint(damp);
-}
-
-static void save_history(plc_state_t *s, int16_t *buf, int len)
-{
- if (len >= PLC_HISTORY_LEN) {
- /* Just keep the last part of the new data, starting at the beginning of the buffer */
- memcpy(s->history, buf + len - PLC_HISTORY_LEN, sizeof(int16_t)*PLC_HISTORY_LEN);
- s->buf_ptr = 0;
- return;
- }
- if (s->buf_ptr + len > PLC_HISTORY_LEN) {
- /* Wraps around - must break into two sections */
- memcpy(s->history + s->buf_ptr, buf, sizeof(int16_t)*(PLC_HISTORY_LEN - s->buf_ptr));
- len -= (PLC_HISTORY_LEN - s->buf_ptr);
- memcpy(s->history, buf + (PLC_HISTORY_LEN - s->buf_ptr), sizeof(int16_t)*len);
- s->buf_ptr = len;
- return;
- }
- /* Can use just one section */
- memcpy(s->history + s->buf_ptr, buf, sizeof(int16_t)*len);
- s->buf_ptr += len;
-}
-
-/*- End of function --------------------------------------------------------*/
-
-static void normalise_history(plc_state_t *s)
-{
- int16_t tmp[PLC_HISTORY_LEN];
-
- if (s->buf_ptr == 0)
- return;
- memcpy(tmp, s->history, sizeof(int16_t)*s->buf_ptr);
- memcpy(s->history, s->history + s->buf_ptr, sizeof(int16_t)*(PLC_HISTORY_LEN - s->buf_ptr));
- memcpy(s->history + PLC_HISTORY_LEN - s->buf_ptr, tmp, sizeof(int16_t)*s->buf_ptr);
- s->buf_ptr = 0;
-}
-
-/*- End of function --------------------------------------------------------*/
-
-static int __inline__ amdf_pitch(int min_pitch, int max_pitch, int16_t amp[], int len)
-{
- int i;
- int j;
- int acc;
- int min_acc;
- int pitch;
-
- pitch = min_pitch;
- min_acc = INT_MAX;
- for (i = max_pitch; i <= min_pitch; i++) {
- acc = 0;
- for (j = 0; j < len; j++)
- acc += abs(amp[i + j] - amp[j]);
- if (acc < min_acc) {
- min_acc = acc;
- pitch = i;
- }
- }
- return pitch;
-}
-
-/*- End of function --------------------------------------------------------*/
-
-int plc_rx(plc_state_t *s, int16_t amp[], int len)
-{
- int i;
- int pitch_overlap;
- float old_step;
- float new_step;
- float old_weight;
- float new_weight;
- float gain;
-
- if (s->missing_samples) {
- /* Although we have a real signal, we need to smooth it to fit well
- with the synthetic signal we used for the previous block */
-
- /* The start of the real data is overlapped with the next 1/4 cycle
- of the synthetic data. */
- pitch_overlap = s->pitch >> 2;
- if (pitch_overlap > len)
- pitch_overlap = len;
- gain = 1.0 - s->missing_samples*ATTENUATION_INCREMENT;
- if (gain < 0.0)
- gain = 0.0;
- new_step = 1.0/pitch_overlap;
- old_step = new_step*gain;
- new_weight = new_step;
- old_weight = (1.0 - new_step)*gain;
- for (i = 0; i < pitch_overlap; i++) {
- amp[i] = fsaturate(old_weight*s->pitchbuf[s->pitch_offset] + new_weight*amp[i]);
- if (++s->pitch_offset >= s->pitch)
- s->pitch_offset = 0;
- new_weight += new_step;
- old_weight -= old_step;
- if (old_weight < 0.0)
- old_weight = 0.0;
- }
- s->missing_samples = 0;
- }
- save_history(s, amp, len);
- return len;
-}
-
-/*- End of function --------------------------------------------------------*/
-
-int plc_fillin(plc_state_t *s, int16_t amp[], int len)
-{
- int i;
- int pitch_overlap;
- float old_step;
- float new_step;
- float old_weight;
- float new_weight;
- float gain;
- int16_t *orig_amp;
- int orig_len;
-
- orig_amp = amp;
- orig_len = len;
- if (s->missing_samples == 0) {
- /* As the gap in real speech starts we need to assess the last known pitch,
- and prepare the synthetic data we will use for fill-in */
- normalise_history(s);
- s->pitch = amdf_pitch(PLC_PITCH_MIN, PLC_PITCH_MAX, s->history + PLC_HISTORY_LEN - CORRELATION_SPAN - PLC_PITCH_MIN, CORRELATION_SPAN);
- /* We overlap a 1/4 wavelength */
- pitch_overlap = s->pitch >> 2;
- /* Cook up a single cycle of pitch, using a single of the real signal with 1/4
- cycle OLA'ed to make the ends join up nicely */
- /* The first 3/4 of the cycle is a simple copy */
- for (i = 0; i < s->pitch - pitch_overlap; i++)
- s->pitchbuf[i] = s->history[PLC_HISTORY_LEN - s->pitch + i];
- /* The last 1/4 of the cycle is overlapped with the end of the previous cycle */
- new_step = 1.0/pitch_overlap;
- new_weight = new_step;
- for ( ; i < s->pitch; i++) {
- s->pitchbuf[i] = s->history[PLC_HISTORY_LEN - s->pitch + i]*(1.0 - new_weight) + s->history[PLC_HISTORY_LEN - 2*s->pitch + i]*new_weight;
- new_weight += new_step;
- }
- /* We should now be ready to fill in the gap with repeated, decaying cycles
- of what is in pitchbuf */
-
- /* We need to OLA the first 1/4 wavelength of the synthetic data, to smooth
- it into the previous real data. To avoid the need to introduce a delay
- in the stream, reverse the last 1/4 wavelength, and OLA with that. */
- gain = 1.0;
- new_step = 1.0/pitch_overlap;
- old_step = new_step;
- new_weight = new_step;
- old_weight = 1.0 - new_step;
- for (i = 0; i < pitch_overlap; i++) {
- amp[i] = fsaturate(old_weight*s->history[PLC_HISTORY_LEN - 1 - i] + new_weight*s->pitchbuf[i]);
- new_weight += new_step;
- old_weight -= old_step;
- if (old_weight < 0.0)
- old_weight = 0.0;
- }
- s->pitch_offset = i;
- } else {
- gain = 1.0 - s->missing_samples*ATTENUATION_INCREMENT;
- i = 0;
- }
- for ( ; gain > 0.0 && i < len; i++) {
- amp[i] = s->pitchbuf[s->pitch_offset]*gain;
- gain -= ATTENUATION_INCREMENT;
- if (++s->pitch_offset >= s->pitch)
- s->pitch_offset = 0;
- }
- for ( ; i < len; i++)
- amp[i] = 0;
- s->missing_samples += orig_len;
- save_history(s, amp, len);
- return len;
-}
-
-/*- End of function --------------------------------------------------------*/
-
-plc_state_t *plc_init(plc_state_t *s)
-{
- memset(s, 0, sizeof(*s));
- return s;
-}
-/*- End of function --------------------------------------------------------*/
-/*- End of file ------------------------------------------------------------*/
diff --git a/1.2-netsec/poll.c b/1.2-netsec/poll.c
deleted file mode 100644
index bd283866d..000000000
--- a/1.2-netsec/poll.c
+++ /dev/null
@@ -1,306 +0,0 @@
-/*---------------------------------------------------------------------------*\
- $Id$
-
- NAME
-
- poll - select(2)-based poll() emulation function for BSD systems.
-
- SYNOPSIS
- #include "poll.h"
-
- struct pollfd
- {
- int fd;
- short events;
- short revents;
- }
-
- int poll (struct pollfd *pArray, unsigned long n_fds, int timeout)
-
- DESCRIPTION
-
- This file, and the accompanying "poll.h", implement the System V
- poll(2) system call for BSD systems (which typically do not provide
- poll()). Poll() provides a method for multiplexing input and output
- on multiple open file descriptors; in traditional BSD systems, that
- capability is provided by select(). While the semantics of select()
- differ from those of poll(), poll() can be readily emulated in terms
- of select() -- which is how this function is implemented.
-
- REFERENCES
- Stevens, W. Richard. Unix Network Programming. Prentice-Hall, 1990.
-
- NOTES
- 1. This software requires an ANSI C compiler.
-
- LICENSE
-
- This software is released under the following license:
-
- Copyright (c) 1995-2002 Brian M. Clapper
- All rights reserved.
-
- Redistribution and use in source and binary forms are
- permitted provided that: (1) source distributions retain
- this entire copyright notice and comment; (2) modifications
- made to the software are prominently mentioned, and a copy
- of the original software (or a pointer to its location) are
- included; and (3) distributions including binaries display
- the following acknowledgement: "This product includes
- software developed by Brian M. Clapper <bmc@clapper.org>"
- in the documentation or other materials provided with the
- distribution. The name of the author may not be used to
- endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS
- OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE.
-
- Effectively, this means you can do what you want with the software
- except remove this notice or take advantage of the author's name.
- If you modify the software and redistribute your modified version,
- you must indicate that your version is a modification of the
- original, and you must provide either a pointer to or a copy of the
- original.
-\*---------------------------------------------------------------------------*/
-
-
-/*---------------------------------------------------------------------------*\
- Includes
-\*---------------------------------------------------------------------------*/
-
-#include <unistd.h> /* standard Unix definitions */
-#include <sys/types.h> /* system types */
-#include <sys/time.h> /* time definitions */
-#include <assert.h> /* assertion macros */
-#include <string.h> /* string functions */
-
-#include "asterisk/poll-compat.h" /* this package */
-
-/*---------------------------------------------------------------------------*\
- Macros
-\*---------------------------------------------------------------------------*/
-
-#ifndef MAX
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-
-/*---------------------------------------------------------------------------*\
- Private Functions
-\*---------------------------------------------------------------------------*/
-
-static int map_poll_spec
-#if __STDC__ > 0
- (struct pollfd *pArray,
- unsigned long n_fds,
- fd_set *pReadSet,
- fd_set *pWriteSet,
- fd_set *pExceptSet)
-#else
- (pArray, n_fds, pReadSet, pWriteSet, pExceptSet)
- struct pollfd *pArray;
- unsigned long n_fds;
- fd_set *pReadSet;
- fd_set *pWriteSet;
- fd_set *pExceptSet;
-#endif
-{
- register unsigned long i; /* loop control */
- register struct pollfd *pCur; /* current array element */
- register int max_fd = -1; /* return value */
-
- /*
- Map the poll() structures into the file descriptor sets required
- by select().
- */
- for (i = 0, pCur = pArray; i < n_fds; i++, pCur++)
- {
- /* Skip any bad FDs in the array. */
-
- if (pCur->fd < 0)
- continue;
-
- if (pCur->events & POLLIN)
- {
- /* "Input Ready" notification desired. */
- FD_SET (pCur->fd, pReadSet);
- }
-
- if (pCur->events & POLLOUT)
- {
- /* "Output Possible" notification desired. */
- FD_SET (pCur->fd, pWriteSet);
- }
-
- if (pCur->events & POLLPRI)
- {
- /*
- "Exception Occurred" notification desired. (Exceptions
- include out of band data.
- */
- FD_SET (pCur->fd, pExceptSet);
- }
-
- max_fd = MAX (max_fd, pCur->fd);
- }
-
- return max_fd;
-}
-
-static struct timeval *map_timeout
-#if __STDC__ > 0
- (int poll_timeout, struct timeval *pSelTimeout)
-#else
- (poll_timeout, pSelTimeout)
- int poll_timeout;
- struct timeval *pSelTimeout;
-#endif
-{
- struct timeval *pResult;
-
- /*
- Map the poll() timeout value into a select() timeout. The possible
- values of the poll() timeout value, and their meanings, are:
-
- VALUE MEANING
-
- -1 wait indefinitely (until signal occurs)
- 0 return immediately, don't block
- >0 wait specified number of milliseconds
-
- select() uses a "struct timeval", which specifies the timeout in
- seconds and microseconds, so the milliseconds value has to be mapped
- accordingly.
- */
-
- assert (pSelTimeout != (struct timeval *) NULL);
-
- switch (poll_timeout)
- {
- case -1:
- /*
- A NULL timeout structure tells select() to wait indefinitely.
- */
- pResult = (struct timeval *) NULL;
- break;
-
- case 0:
- /*
- "Return immediately" (test) is specified by all zeros in
- a timeval structure.
- */
- pSelTimeout->tv_sec = 0;
- pSelTimeout->tv_usec = 0;
- pResult = pSelTimeout;
- break;
-
- default:
- /* Wait the specified number of milliseconds. */
- pSelTimeout->tv_sec = poll_timeout / 1000; /* get seconds */
- poll_timeout %= 1000; /* remove seconds */
- pSelTimeout->tv_usec = poll_timeout * 1000; /* get microseconds */
- pResult = pSelTimeout;
- break;
- }
-
-
- return pResult;
-}
-
-static void map_select_results
-#if __STDC__ > 0
- (struct pollfd *pArray,
- unsigned long n_fds,
- fd_set *pReadSet,
- fd_set *pWriteSet,
- fd_set *pExceptSet)
-#else
- (pArray, n_fds, pReadSet, pWriteSet, pExceptSet)
- struct pollfd *pArray;
- unsigned long n_fds;
- fd_set *pReadSet;
- fd_set *pWriteSet;
- fd_set *pExceptSet;
-#endif
-{
- register unsigned long i; /* loop control */
- register struct pollfd *pCur; /* current array element */
-
- for (i = 0, pCur = pArray; i < n_fds; i++, pCur++)
- {
- /* Skip any bad FDs in the array. */
-
- if (pCur->fd < 0)
- continue;
-
- /* Exception events take priority over input events. */
-
- pCur->revents = 0;
- if (FD_ISSET (pCur->fd, pExceptSet))
- pCur->revents |= POLLPRI;
-
- else if (FD_ISSET (pCur->fd, pReadSet))
- pCur->revents |= POLLIN;
-
- if (FD_ISSET (pCur->fd, pWriteSet))
- pCur->revents |= POLLOUT;
- }
-
- return;
-}
-
-/*---------------------------------------------------------------------------*\
- Public Functions
-\*---------------------------------------------------------------------------*/
-
-int poll
-
-#if __STDC__ > 0
- (struct pollfd *pArray, unsigned long n_fds, int timeout)
-#else
- (pArray, n_fds, timeout)
- struct pollfd *pArray;
- unsigned long n_fds;
- int timeout;
-#endif
-
-{
- fd_set read_descs; /* input file descs */
- fd_set write_descs; /* output file descs */
- fd_set except_descs; /* exception descs */
- struct timeval stime; /* select() timeout value */
- int ready_descriptors; /* function result */
- int max_fd; /* maximum fd value */
- struct timeval *pTimeout; /* actually passed */
-
- FD_ZERO (&read_descs);
- FD_ZERO (&write_descs);
- FD_ZERO (&except_descs);
-
- assert (pArray != (struct pollfd *) NULL);
-
- /* Map the poll() file descriptor list in the select() data structures. */
-
- max_fd = map_poll_spec (pArray, n_fds,
- &read_descs, &write_descs, &except_descs);
-
- /* Map the poll() timeout value in the select() timeout structure. */
-
- pTimeout = map_timeout (timeout, &stime);
-
- /* Make the select() call. */
-
- ready_descriptors = select (max_fd + 1, &read_descs, &write_descs,
- &except_descs, pTimeout);
-
- if (ready_descriptors >= 0)
- {
- map_select_results (pArray, n_fds,
- &read_descs, &write_descs, &except_descs);
- }
-
- return ready_descriptors;
-}
diff --git a/1.2-netsec/privacy.c b/1.2-netsec/privacy.c
deleted file mode 100644
index a3ffec3e3..000000000
--- a/1.2-netsec/privacy.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Privacy Routines
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <dirent.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/app.h"
-#include "asterisk/dsp.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/astdb.h"
-#include "asterisk/callerid.h"
-#include "asterisk/privacy.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-
-int ast_privacy_check(char *dest, char *cid)
-{
- char tmp[256] = "";
- char *trimcid = "";
- char *n, *l;
- int res;
- char key[256], result[256];
- if (cid)
- ast_copy_string(tmp, cid, sizeof(tmp));
- ast_callerid_parse(tmp, &n, &l);
- if (l) {
- ast_shrink_phone_number(l);
- trimcid = l;
- }
- snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
- res = ast_db_get("privacy", key, result, sizeof(result));
- if (!res) {
- if (!strcasecmp(result, "allow"))
- return AST_PRIVACY_ALLOW;
- if (!strcasecmp(result, "deny"))
- return AST_PRIVACY_DENY;
- if (!strcasecmp(result, "kill"))
- return AST_PRIVACY_KILL;
- if (!strcasecmp(result, "torture"))
- return AST_PRIVACY_TORTURE;
- }
- return AST_PRIVACY_UNKNOWN;
-}
-
-int ast_privacy_reset(char *dest)
-{
- if (!dest)
- return -1;
- return ast_db_deltree("privacy", dest);
-}
-
-int ast_privacy_set(char *dest, char *cid, int status)
-{
- char tmp[256] = "";
- char *trimcid = "";
- char *n, *l;
- int res;
- char key[256];
- if (cid)
- ast_copy_string(tmp, cid, sizeof(tmp));
- ast_callerid_parse(tmp, &n, &l);
- if (l) {
- ast_shrink_phone_number(l);
- trimcid = l;
- }
- if (ast_strlen_zero(trimcid)) {
- /* Don't store anything for empty Caller*ID */
- return 0;
- }
- snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
- if (status == AST_PRIVACY_UNKNOWN)
- res = ast_db_del("privacy", key);
- else if (status == AST_PRIVACY_ALLOW)
- res = ast_db_put("privacy", key, "allow");
- else if (status == AST_PRIVACY_DENY)
- res = ast_db_put("privacy", key, "deny");
- else if (status == AST_PRIVACY_KILL)
- res = ast_db_put("privacy", key, "kill");
- else if (status == AST_PRIVACY_TORTURE)
- res = ast_db_put("privacy", key, "torture");
- else
- res = -1;
- return res;
-}
diff --git a/1.2-netsec/redhat/asterisk.spec b/1.2-netsec/redhat/asterisk.spec
deleted file mode 100644
index 8842ef989..000000000
--- a/1.2-netsec/redhat/asterisk.spec
+++ /dev/null
@@ -1,127 +0,0 @@
-Summary: Asterisk PBX
-Name: asterisk
-Distribution: RedHat
-Version: CVS
-Release: 1
-Copyright: Linux Support Services, inc.
-Group: Utilities/System
-Vendor: Linux Support Services, inc.
-Packager: Robert Vojta <vojta@ipex.cz>
-BuildRoot: /tmp/asterisk
-
-%description
-Asterisk is an Open Source PBX and telephony development platform that
-can both replace a conventional PBX and act as a platform for developing
-custom telephony applications for delivering dynamic content over a
-telephone similarly to how one can deliver dynamic content through a
-web browser using CGI and a web server.
-
-Asterisk talks to a variety of telephony hardware including BRI, PRI,
-POTS, and IP telephony clients using the Inter-Asterisk eXchange
-protocol (e.g. gnophone or miniphone). For more information and a
-current list of supported hardware, see www.asteriskpbx.com.
-
-%package devel
-Summary: Header files for building Asterisk modules
-Group: Development/Libraries
-
-%description devel
-This package contains the development header files that are needed
-to compile 3rd party modules.
-
-%post
-ln -sf /var/spool/asterisk/vm /var/lib/asterisk/sounds/vm
-
-%files
-#
-# Configuration files
-#
-%attr(0755,root,root) %dir /etc/asterisk
-%config(noreplace) %attr(0640,root,root) /etc/asterisk/*.conf
-%config(noreplace) %attr(0640,root,root) /etc/asterisk/*.adsi
-
-#
-# RedHat specific init script file
-#
-%attr(0755,root,root) /etc/rc.d/init.d/asterisk
-
-#
-# Modules
-#
-%attr(0755,root,root) %dir /usr/lib/asterisk
-%attr(0755,root,root) %dir /usr/lib/asterisk/modules
-%attr(0755,root,root) /usr/lib/asterisk/modules/*.so
-
-#
-# Asterisk
-#
-%attr(0755,root,root) /usr/sbin/asterisk
-%attr(0755,root,root) /usr/sbin/safe_asterisk
-%attr(0755,root,root) /usr/sbin/astgenkey
-%attr(0755,root,root) /usr/sbin/astman
-%attr(0755,root,root) /usr/sbin/autosupport
-%attr(0755,root,root) /usr/sbin/smsq
-%attr(0755,root,root) /usr/sbin/stereorize
-
-#
-# CDR Locations
-#
-%attr(0755,root,root) %dir /var/log/asterisk
-%attr(0755,root,root) %dir /var/log/asterisk/cdr-csv
-#
-# Running directories
-#
-%attr(0755,root,root) %dir /var/run
-#
-# Sound files
-#
-%attr(0755,root,root) %dir /var/lib/asterisk
-%attr(0755,root,root) %dir /var/lib/asterisk/sounds
-%attr(0644,root,root) /var/lib/asterisk/sounds/*.gsm
-%attr(0755,root,root) %dir /var/lib/asterisk/sounds/digits
-%attr(0644,root,root) /var/lib/asterisk/sounds/digits/*.gsm
-%attr(0755,root,root) %dir /var/lib/asterisk/sounds/letters
-%attr(0644,root,root) /var/lib/asterisk/sounds/letters/*.gsm
-%attr(0755,root,root) %dir /var/lib/asterisk/sounds/phonetic
-%attr(0644,root,root) /var/lib/asterisk/sounds/phonetic/*.gsm
-%attr(0755,root,root) %dir /var/lib/asterisk/mohmp3
-%attr(0644,root,root) /var/lib/asterisk/mohmp3/*
-%attr(0755,root,root) %dir /var/lib/asterisk/images
-%attr(0644,root,root) /var/lib/asterisk/images/*
-%attr(0755,root,root) %dir /var/lib/asterisk/keys
-%attr(0644,root,root) /var/lib/asterisk/keys/*
-%attr(0755,root,root) %dir /var/lib/asterisk/agi-bin
-%attr(0755,root,root) %dir /var/lib/asterisk/agi-bin/*
-#
-# Man page
-#
-%attr(0644,root,root) /usr/share/man/man8/asterisk.8.gz
-#
-# Firmware
-#
-%attr(0755,root,root) %dir /var/lib/asterisk/firmware
-%attr(0755,root,root) %dir /var/lib/asterisk/firmware/iax
-%attr(0755,root,root) /var/lib/asterisk/firmware/iax/*.bin
-
-#
-# Example voicemail files
-#
-%attr(0755,root,root) %dir /var/spool/asterisk
-%attr(0755,root,root) %dir /var/spool/asterisk/voicemail
-%attr(0755,root,root) %dir /var/spool/asterisk/voicemail/default
-%attr(0755,root,root) %dir /var/spool/asterisk/voicemail/default/1234
-%attr(0755,root,root) %dir /var/spool/asterisk/voicemail/default/1234/INBOX
-%attr(0644,root,root) /var/spool/asterisk/voicemail/default/1234/*.gsm
-
-#
-# Misc other spool
-#
-%attr(0755,root,root) %dir /var/spool/asterisk/system
-%attr(0755,root,root) %dir /var/spool/asterisk/tmp
-
-%files devel
-#
-# Include files
-#
-%attr(0755,root,root) %dir %{_includedir}/asterisk
-%attr(0644,root,root) %{_includedir}/asterisk/*.h
diff --git a/1.2-netsec/redhat/rpmmacros b/1.2-netsec/redhat/rpmmacros
deleted file mode 100644
index fbf2ee3ed..000000000
--- a/1.2-netsec/redhat/rpmmacros
+++ /dev/null
@@ -1,3 +0,0 @@
-%_tmppath /tmp/asterisk
-%_topdir %{_tmppath}/redhat
-%_rpmfilename %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm
diff --git a/1.2-netsec/redhat/rpmrc b/1.2-netsec/redhat/rpmrc
deleted file mode 100644
index 88c57d10b..000000000
--- a/1.2-netsec/redhat/rpmrc
+++ /dev/null
@@ -1,3 +0,0 @@
-#############################################################
-macrofiles: /usr/lib/rpm/macros:/usr/lib/rpm/%{_target}/macros:/etc/rpm/macros:/etc/rpm/%{_target}/macros:~/.rpmmacros:/tmp/asterisk/rpmmacros
-#############################################################
diff --git a/1.2-netsec/res/Makefile b/1.2-netsec/res/Makefile
deleted file mode 100644
index a32465282..000000000
--- a/1.2-netsec/res/Makefile
+++ /dev/null
@@ -1,122 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Makefile for resource modules
-#
-# Copyright (C) 1999-2005, Digium
-#
-# Mark Spencer <markster@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-MODS=res_indications.so res_monitor.so res_adsi.so res_agi.so res_features.so
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),)
- ifneq (${OSARCH},FreeBSD)
- MODS+=res_config_odbc.so
- else
- MODS+=$(shell if test ${BSDVERSION} -ge 500000 ; then echo "res_config_odbc.so"; fi)
- endif
- MODS+=res_odbc.so
-endif
-
-ifneq ($(NOCRYPTO),yes)
- MODS+=res_crypto.so
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/lib/libosptk.a),)
- MODS+=res_osp.so
- OSPLIB=$(CROSS_COMPILE_TARGET)/usr/lib/libosptk.a
-else
- ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/lib/libosptk.a),)
- MODS+=res_osp.so
- OSPLIB=$(CROSS_COMPILE_TARGET)/usr/local/lib/libosptk.a
- endif
-endif
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include
- SOLINK+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-ifeq (${OSARCH},CYGWIN)
-CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
-CYGSOLIB=-L.. -L. -lasterisk.dll
-CYG_RES_CONFIG_ODBC_LIB=-lres_odbc.so
-CYG_RES_FEATURES_LIB=-lres_adsi.so -lres_monitor.so
-else
-MODS+=res_musiconhold.so
-endif
-
-CRYPTO_LIBS=-lssl -lcrypto
-
-CFLAGS+=
-
-ifndef WITHOUT_ZAPTEL
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/linux/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/zaptel.h),)
- CFLAGS+=-DZAPATA_MOH
-endif
-endif # WITHOUT_ZAPTEL
-
-#
-# Work around buggy RedHat 9.0
-#
-ifeq (${OSARCH},CYGWIN)
-CFLAGS+=-DOPENSSL_NO_KRB5
-else
-CFLAGS+=-DOPENSSL_NO_KRB5 -fPIC
-endif
-
-all: depend $(MODS)
-
-install: all
- rm -f $(DESTDIR)$(ASTHEADERDIR)/parking.h
- rm -f $(DESTDIR)$(MODULES_DIR)/app_agi.so
- rm -f $(DESTDIR)$(MODULES_DIR)/res_parking.so
- for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
- @if [ x`which mpg123 2>/dev/null | grep -v '^no'` != x ] ; then \
- if mpg123 --longhelp 2>&1 | grep -q .59r 2>&1 >/dev/null ; then echo ; else \
- echo "*************************************************************";\
- echo "*** You have the WRONG version of mpg123... you need .59r ***";\
- echo "*** Use 'make mpg123' to get the right verison ***";\
- echo "*************************************************************";\
- fi ;\
- else \
- echo "*** You don't have mpg123 installed. You may need ***";\
- echo "*** it if you want to use MusicOnHold ***";\
- fi
-
-res_crypto.so: res_crypto.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(CRYPTO_LIBS)
-
-clean:
- rm -f *.so *.o .depend
-
-res_odbc.so: res_odbc.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc
-
-res_osp.so: res_osp.o $(OSPLIB)
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(OSPLIB)
-
-%.so : %.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
-
-res_features.so: res_features.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} ${CYG_RES_FEATURES_LIB}
-
-res_config_odbc.so: res_config_odbc.o
- $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} ${CYG_RES_CONFIG_ODBC_LIB}
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
-
-env:
- env
diff --git a/1.2-netsec/res/res_adsi.c b/1.2-netsec/res/res_adsi.c
deleted file mode 100644
index 18e7849f3..000000000
--- a/1.2-netsec/res/res_adsi.c
+++ /dev/null
@@ -1,1141 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Includes code and algorithms from the Zapata library.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief ADSI support
- *
- */
-
-#include <time.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <math.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/ulaw.h"
-#include "asterisk/alaw.h"
-#include "asterisk/callerid.h"
-#include "asterisk/logger.h"
-#include "asterisk/fskmodem.h"
-#include "asterisk/channel.h"
-#include "asterisk/adsi.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/file.h"
-
-#define DEFAULT_ADSI_MAX_RETRIES 3
-
-#define ADSI_MAX_INTRO 20
-#define ADSI_MAX_SPEED_DIAL 6
-
-#define ADSI_FLAG_DATAMODE (1 << 8)
-
-static int maxretries = DEFAULT_ADSI_MAX_RETRIES;
-
-/* Asterisk ADSI button definitions */
-#define ADSI_SPEED_DIAL 10 /* 10-15 are reserved for speed dial */
-
-static char intro[ADSI_MAX_INTRO][20];
-static int aligns[ADSI_MAX_INTRO];
-
-static char speeddial[ADSI_MAX_SPEED_DIAL][3][20];
-
-static int alignment = 0;
-
-static int adsi_generate(unsigned char *buf, int msgtype, unsigned char *msg, int msglen, int msgnum, int last, int codec)
-{
- int sum;
- int x;
- int bytes=0;
- /* Initial carrier (imaginary) */
- float cr = 1.0;
- float ci = 0.0;
- float scont = 0.0;
-
- if (msglen > 255)
- msglen = 255;
-
- /* If first message, Send 150ms of MARK's */
- if (msgnum == 1) {
- for (x=0;x<150;x++) /* was 150 */
- PUT_CLID_MARKMS;
- }
- /* Put message type */
- PUT_CLID(msgtype);
- sum = msgtype;
-
- /* Put message length (plus one for the message number) */
- PUT_CLID(msglen + 1);
- sum += msglen + 1;
-
- /* Put message number */
- PUT_CLID(msgnum);
- sum += msgnum;
-
- /* Put actual message */
- for (x=0;x<msglen;x++) {
- PUT_CLID(msg[x]);
- sum += msg[x];
- }
-
- /* Put 2's compliment of sum */
- PUT_CLID(256-(sum & 0xff));
-
-#if 0
- if (last) {
- /* Put trailing marks */
- for (x=0;x<50;x++)
- PUT_CLID_MARKMS;
- }
-#endif
- return bytes;
-
-}
-
-static int adsi_careful_send(struct ast_channel *chan, unsigned char *buf, int len, int *remainder)
-{
- /* Sends carefully on a full duplex channel by using reading for
- timing */
- struct ast_frame *inf, outf;
- int amt;
-
- /* Zero out our outgoing frame */
- memset(&outf, 0, sizeof(outf));
-
- if (remainder && *remainder) {
- amt = len;
-
- /* Send remainder if provided */
- if (amt > *remainder)
- amt = *remainder;
- else
- *remainder = *remainder - amt;
- outf.frametype = AST_FRAME_VOICE;
- outf.subclass = AST_FORMAT_ULAW;
- outf.data = buf;
- outf.datalen = amt;
- outf.samples = amt;
- if (ast_write(chan, &outf)) {
- ast_log(LOG_WARNING, "Failed to carefully write frame\n");
- return -1;
- }
- /* Update pointers and lengths */
- buf += amt;
- len -= amt;
- }
-
- while(len) {
- amt = len;
- /* If we don't get anything at all back in a second, forget
- about it */
- if (ast_waitfor(chan, 1000) < 1)
- return -1;
- inf = ast_read(chan);
- /* Detect hangup */
- if (!inf)
- return -1;
- if (inf->frametype == AST_FRAME_VOICE) {
- /* Read a voice frame */
- if (inf->subclass != AST_FORMAT_ULAW) {
- ast_log(LOG_WARNING, "Channel not in ulaw?\n");
- return -1;
- }
- /* Send no more than they sent us */
- if (amt > inf->datalen)
- amt = inf->datalen;
- else if (remainder)
- *remainder = inf->datalen - amt;
- outf.frametype = AST_FRAME_VOICE;
- outf.subclass = AST_FORMAT_ULAW;
- outf.data = buf;
- outf.datalen = amt;
- outf.samples = amt;
- if (ast_write(chan, &outf)) {
- ast_log(LOG_WARNING, "Failed to carefully write frame\n");
- return -1;
- }
- /* Update pointers and lengths */
- buf += amt;
- len -= amt;
- }
- ast_frfree(inf);
- }
- return 0;
-}
-
-static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **msg, int *msglen, int *msgtype)
-{
- /* msglen must be no more than 256 bits, each */
- unsigned char buf[24000 * 5];
- int pos = 0, res;
- int x;
- int start=0;
- int retries = 0;
-
- char ack[3];
-
- /* Wait up to 500 ms for initial ACK */
- int waittime;
- struct ast_frame *f;
- int rem = 0;
- int def;
-
- if (chan->adsicpe == AST_ADSI_UNAVAILABLE) {
- /* Don't bother if we know they don't support ADSI */
- errno = ENOSYS;
- return -1;
- }
-
- while(retries < maxretries) {
- if (!(chan->adsicpe & ADSI_FLAG_DATAMODE)) {
- /* Generate CAS (no SAS) */
- ast_gen_cas(buf, 0, 680, AST_FORMAT_ULAW);
-
- /* Send CAS */
- if (adsi_careful_send(chan, buf, 680, NULL)) {
- ast_log(LOG_WARNING, "Unable to send CAS\n");
- }
- /* Wait For DTMF result */
- waittime = 500;
- for(;;) {
- if (((res = ast_waitfor(chan, waittime)) < 1)) {
- /* Didn't get back DTMF A in time */
- ast_log(LOG_DEBUG, "No ADSI CPE detected (%d)\n", res);
- if (!chan->adsicpe)
- chan->adsicpe = AST_ADSI_UNAVAILABLE;
- errno = ENOSYS;
- return -1;
- }
- waittime = res;
- f = ast_read(chan);
- if (!f) {
- ast_log(LOG_DEBUG, "Hangup in ADSI\n");
- return -1;
- }
- if (f->frametype == AST_FRAME_DTMF) {
- if (f->subclass == 'A') {
- /* Okay, this is an ADSI CPE. Note this for future reference, too */
- if (!chan->adsicpe)
- chan->adsicpe = AST_ADSI_AVAILABLE;
- break;
- } else {
- if (f->subclass == 'D') {
- ast_log(LOG_DEBUG, "Off-hook capable CPE only, not ADSI\n");
- } else
- ast_log(LOG_WARNING, "Unknown ADSI response '%c'\n", f->subclass);
- if (!chan->adsicpe)
- chan->adsicpe = AST_ADSI_UNAVAILABLE;
- errno = ENOSYS;
- return -1;
- }
- }
- ast_frfree(f);
- }
-
- ast_log(LOG_DEBUG, "ADSI Compatible CPE Detected\n");
- } else
- ast_log(LOG_DEBUG, "Already in data mode\n");
-
- x = 0;
- pos = 0;
-#if 1
- def= ast_channel_defer_dtmf(chan);
-#endif
- while((x < 6) && msg[x]) {
- res = adsi_generate(buf + pos, msgtype[x], msg[x], msglen[x], x+1 - start, (x == 5) || !msg[x+1], AST_FORMAT_ULAW);
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to generate ADSI message %d on channel %s\n", x + 1, chan->name);
- return -1;
- }
- ast_log(LOG_DEBUG, "Message %d, of %d input bytes, %d output bytes\n",
- x + 1, msglen[x], res);
- pos += res;
- x++;
- }
-
-
- rem = 0;
- res = adsi_careful_send(chan, buf, pos, &rem);
- if (!def)
- ast_channel_undefer_dtmf(chan);
- if (res)
- return -1;
-
- ast_log(LOG_DEBUG, "Sent total spill of %d bytes\n", pos);
-
- memset(ack, 0, sizeof(ack));
- /* Get real result */
- res = ast_readstring(chan, ack, 2, 1000, 1000, "");
- /* Check for hangup */
- if (res < 0)
- return -1;
- if (ack[0] == 'D') {
- ast_log(LOG_DEBUG, "Acked up to message %d\n", atoi(ack + 1));
- start += atoi(ack + 1);
- if (start >= x)
- break;
- else {
- retries++;
- ast_log(LOG_DEBUG, "Retransmitting (%d), from %d\n", retries, start + 1);
- }
- } else {
- retries++;
- ast_log(LOG_WARNING, "Unexpected response to ack: %s (retry %d)\n", ack, retries);
- }
- }
- if (retries >= maxretries) {
- ast_log(LOG_WARNING, "Maximum ADSI Retries (%d) exceeded\n", maxretries);
- errno = ETIMEDOUT;
- return -1;
- }
- return 0;
-
-}
-
-int adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
-{
- int bytes;
- unsigned char buf[256];
- char ack[2];
- bytes = 0;
- /* Setup the resident soft key stuff, a piece at a time */
- /* Upload what scripts we can for voicemail ahead of time */
- bytes += adsi_download_connect(buf + bytes, service, fdn, sec, version);
- if (adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0))
- return -1;
- if (ast_readstring(chan, ack, 1, 10000, 10000, ""))
- return -1;
- if (ack[0] == 'B')
- return 0;
- ast_log(LOG_DEBUG, "Download was denied by CPE\n");
- return -1;
-}
-
-int adsi_end_download(struct ast_channel *chan)
-{
- int bytes;
- unsigned char buf[256];
- bytes = 0;
- /* Setup the resident soft key stuff, a piece at a time */
- /* Upload what scripts we can for voicemail ahead of time */
- bytes += adsi_download_disconnect(buf + bytes);
- if (adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0))
- return -1;
- return 0;
-}
-
-int adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
-{
- unsigned char *msgs[5] = { NULL, NULL, NULL, NULL, NULL };
- int msglens[5];
- int msgtypes[5];
- int newdatamode;
- int res;
- int x;
- int writeformat, readformat;
- int waitforswitch = 0;
-
- writeformat = chan->writeformat;
- readformat = chan->readformat;
-
- newdatamode = chan->adsicpe & ADSI_FLAG_DATAMODE;
-
- for (x=0;x<msglen;x+=(msg[x+1]+2)) {
- if (msg[x] == ADSI_SWITCH_TO_DATA) {
- ast_log(LOG_DEBUG, "Switch to data is sent!\n");
- waitforswitch++;
- newdatamode = ADSI_FLAG_DATAMODE;
- }
-
- if (msg[x] == ADSI_SWITCH_TO_VOICE) {
- ast_log(LOG_DEBUG, "Switch to voice is sent!\n");
- waitforswitch++;
- newdatamode = 0;
- }
- }
- msgs[0] = msg;
-
- msglens[0] = msglen;
- msgtypes[0] = msgtype;
-
- if (msglen > 253) {
- ast_log(LOG_WARNING, "Can't send ADSI message of %d bytes, too large\n", msglen);
- return -1;
- }
-
- ast_stopstream(chan);
-
- if (ast_set_write_format(chan, AST_FORMAT_ULAW)) {
- ast_log(LOG_WARNING, "Unable to set write format to ULAW\n");
- return -1;
- }
-
- if (ast_set_read_format(chan, AST_FORMAT_ULAW)) {
- ast_log(LOG_WARNING, "Unable to set read format to ULAW\n");
- if (writeformat) {
- if (ast_set_write_format(chan, writeformat))
- ast_log(LOG_WARNING, "Unable to restore write format to %d\n", writeformat);
- }
- return -1;
- }
- res = __adsi_transmit_messages(chan, msgs, msglens, msgtypes);
-
- if (dowait) {
- ast_log(LOG_DEBUG, "Wait for switch is '%d'\n", waitforswitch);
- while(waitforswitch-- && ((res = ast_waitfordigit(chan, 1000)) > 0)) { res = 0; ast_log(LOG_DEBUG, "Waiting for 'B'...\n"); }
- }
-
- if (!res)
- chan->adsicpe = (chan->adsicpe & ~ADSI_FLAG_DATAMODE) | newdatamode;
-
- if (writeformat)
- ast_set_write_format(chan, writeformat);
- if (readformat)
- ast_set_read_format(chan, readformat);
-
- if (!res)
- res = ast_safe_sleep(chan, 100 );
- return res;
-}
-
-int adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
-{
- return adsi_transmit_message_full(chan, msg, msglen, msgtype, 1);
-}
-
-static inline int ccopy(unsigned char *dst, unsigned char *src, int max)
-{
- int x=0;
- /* Carefully copy the requested data */
- while ((x < max) && src[x] && (src[x] != 0xff)) {
- dst[x] = src[x];
- x++;
- }
- return x;
-}
-
-int adsi_load_soft_key(unsigned char *buf, int key, char *llabel, char *slabel, char *ret, int data)
-{
- int bytes=0;
-
- /* Abort if invalid key specified */
- if ((key < 2) || (key > 33))
- return -1;
- buf[bytes++] = ADSI_LOAD_SOFTKEY;
- /* Reserve for length */
- bytes++;
- /* Which key */
- buf[bytes++] = key;
-
- /* Carefully copy long label */
- bytes += ccopy(buf + bytes, (unsigned char *)llabel, 18);
-
- /* Place delimiter */
- buf[bytes++] = 0xff;
-
- /* Short label */
- bytes += ccopy(buf + bytes, (unsigned char *)slabel, 7);
-
-
- /* If specified, copy return string */
- if (ret) {
- /* Place delimiter */
- buf[bytes++] = 0xff;
- if (data)
- buf[bytes++] = ADSI_SWITCH_TO_DATA2;
- /* Carefully copy return string */
- bytes += ccopy(buf + bytes, (unsigned char *)ret, 20);
-
- }
- /* Replace parameter length */
- buf[1] = bytes - 2;
- return bytes;
-
-}
-
-int adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver)
-{
- int bytes=0;
- int x;
-
- /* Message type */
- buf[bytes++] = ADSI_CONNECT_SESSION;
-
- /* Reserve space for length */
- bytes++;
-
- if (fdn) {
- for (x=0;x<4;x++)
- buf[bytes++] = fdn[x];
- if (ver > -1)
- buf[bytes++] = ver & 0xff;
- }
-
- buf[1] = bytes - 2;
- return bytes;
-
-}
-
-int adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
-{
- int bytes=0;
- int x;
-
- /* Message type */
- buf[bytes++] = ADSI_DOWNLOAD_CONNECT;
-
- /* Reserve space for length */
- bytes++;
-
- /* Primary column */
- bytes+= ccopy(buf + bytes, (unsigned char *)service, 18);
-
- /* Delimiter */
- buf[bytes++] = 0xff;
-
- for (x=0;x<4;x++) {
- buf[bytes++] = fdn[x];
- }
- for (x=0;x<4;x++)
- buf[bytes++] = sec[x];
- buf[bytes++] = ver & 0xff;
-
- buf[1] = bytes - 2;
-
- return bytes;
-
-}
-
-int adsi_disconnect_session(unsigned char *buf)
-{
- int bytes=0;
-
- /* Message type */
- buf[bytes++] = ADSI_DISC_SESSION;
-
- /* Reserve space for length */
- bytes++;
-
- buf[1] = bytes - 2;
- return bytes;
-
-}
-
-int adsi_query_cpeid(unsigned char *buf)
-{
- int bytes = 0;
- buf[bytes++] = ADSI_QUERY_CPEID;
- /* Reserve space for length */
- bytes++;
- buf[1] = bytes - 2;
- return bytes;
-}
-
-int adsi_query_cpeinfo(unsigned char *buf)
-{
- int bytes = 0;
- buf[bytes++] = ADSI_QUERY_CONFIG;
- /* Reserve space for length */
- bytes++;
- buf[1] = bytes - 2;
- return bytes;
-}
-
-int adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen)
-{
- int bytes = 0;
- int res;
- unsigned char current = 0;
- int gotstar = 0;
- int pos = 0;
- memset(buf, 0, sizeof(buf));
- while(bytes <= maxlen) {
- /* Wait up to a second for a digit */
- res = ast_waitfordigit(chan, 1000);
- if (!res)
- break;
- if (res == '*') {
- gotstar = 1;
- continue;
- }
- /* Ignore anything other than a digit */
- if ((res < '0') || (res > '9'))
- continue;
- res -= '0';
- if (gotstar)
- res += 9;
- if (pos) {
- pos = 0;
- buf[bytes++] = (res << 4) | current;
- } else {
- pos = 1;
- current = res;
- }
- gotstar = 0;
- }
- return bytes;
-}
-
-int adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
-{
- unsigned char buf[256];
- int bytes = 0;
- int res;
- bytes += adsi_data_mode(buf);
- adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
-
- bytes = 0;
- bytes += adsi_query_cpeid(buf);
- adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
-
- /* Get response */
- memset(buf, 0, sizeof(buf));
- res = adsi_read_encoded_dtmf(chan, cpeid, 4);
- if (res != 4) {
- ast_log(LOG_WARNING, "Got %d bytes back of encoded DTMF, expecting 4\n", res);
- res = 0;
- } else {
- res = 1;
- }
-
- if (voice) {
- bytes = 0;
- bytes += adsi_voice_mode(buf, 0);
- adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
- /* Ignore the resulting DTMF B announcing it's in voice mode */
- ast_waitfordigit(chan, 1000);
- }
- return res;
-}
-
-int adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
-{
- unsigned char buf[256];
- int bytes = 0;
- int res;
- bytes += adsi_data_mode(buf);
- adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
-
- bytes = 0;
- bytes += adsi_query_cpeinfo(buf);
- adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
-
- /* Get width */
- memset(buf, 0, sizeof(buf));
- res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "");
- if (res < 0)
- return res;
- if (strlen((char *)buf) != 2) {
- ast_log(LOG_WARNING, "Got %d bytes of width, expecting 2\n", res);
- res = 0;
- } else {
- res = 1;
- }
- if (width)
- *width = atoi((char *)buf);
- /* Get height */
- memset(buf, 0, sizeof(buf));
- if (res) {
- res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "");
- if (res < 0)
- return res;
- if (strlen((char *)buf) != 2) {
- ast_log(LOG_WARNING, "Got %d bytes of height, expecting 2\n", res);
- res = 0;
- } else {
- res = 1;
- }
- if (height)
- *height= atoi((char *)buf);
- }
- /* Get buttons */
- memset(buf, 0, sizeof(buf));
- if (res) {
- res = ast_readstring(chan, (char *)buf, 1, 1000, 500, "");
- if (res < 0)
- return res;
- if (strlen((char *)buf) != 1) {
- ast_log(LOG_WARNING, "Got %d bytes of buttons, expecting 1\n", res);
- res = 0;
- } else {
- res = 1;
- }
- if (buttons)
- *buttons = atoi((char *)buf);
- }
- if (voice) {
- bytes = 0;
- bytes += adsi_voice_mode(buf, 0);
- adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
- /* Ignore the resulting DTMF B announcing it's in voice mode */
- ast_waitfordigit(chan, 1000);
- }
- return res;
-}
-
-int adsi_data_mode(unsigned char *buf)
-{
- int bytes=0;
-
- /* Message type */
- buf[bytes++] = ADSI_SWITCH_TO_DATA;
-
- /* Reserve space for length */
- bytes++;
-
- buf[1] = bytes - 2;
- return bytes;
-
-}
-
-int adsi_clear_soft_keys(unsigned char *buf)
-{
- int bytes=0;
-
- /* Message type */
- buf[bytes++] = ADSI_CLEAR_SOFTKEY;
-
- /* Reserve space for length */
- bytes++;
-
- buf[1] = bytes - 2;
- return bytes;
-
-}
-
-int adsi_clear_screen(unsigned char *buf)
-{
- int bytes=0;
-
- /* Message type */
- buf[bytes++] = ADSI_CLEAR_SCREEN;
-
- /* Reserve space for length */
- bytes++;
-
- buf[1] = bytes - 2;
- return bytes;
-
-}
-
-int adsi_voice_mode(unsigned char *buf, int when)
-{
- int bytes=0;
-
- /* Message type */
- buf[bytes++] = ADSI_SWITCH_TO_VOICE;
-
- /* Reserve space for length */
- bytes++;
-
- buf[bytes++] = when & 0x7f;
-
- buf[1] = bytes - 2;
- return bytes;
-
-}
-
-int adsi_available(struct ast_channel *chan)
-{
- int cpe = chan->adsicpe & 0xff;
- if ((cpe == AST_ADSI_AVAILABLE) ||
- (cpe == AST_ADSI_UNKNOWN))
- return 1;
- return 0;
-}
-
-int adsi_download_disconnect(unsigned char *buf)
-{
- int bytes=0;
-
- /* Message type */
- buf[bytes++] = ADSI_DOWNLOAD_DISC;
-
- /* Reserve space for length */
- bytes++;
-
- buf[1] = bytes - 2;
- return bytes;
-
-}
-
-int adsi_display(unsigned char *buf, int page, int line, int just, int wrap,
- char *col1, char *col2)
-{
- int bytes=0;
-
- /* Sanity check line number */
-
- if (page) {
- if (line > 4) return -1;
- } else {
- if (line > 33) return -1;
- }
-
- if (line < 1)
- return -1;
- /* Parameter type */
- buf[bytes++] = ADSI_LOAD_VIRTUAL_DISP;
-
- /* Reserve space for size */
- bytes++;
-
- /* Page and wrap indicator */
- buf[bytes++] = ((page & 0x1) << 7) | ((wrap & 0x1) << 6) | (line & 0x3f);
-
- /* Justification */
- buf[bytes++] = (just & 0x3) << 5;
-
- /* Omit highlight mode definition */
- buf[bytes++] = 0xff;
-
- /* Primary column */
- bytes+= ccopy(buf + bytes, (unsigned char *)col1, 20);
-
- /* Delimiter */
- buf[bytes++] = 0xff;
-
- /* Secondary column */
- bytes += ccopy(buf + bytes, (unsigned char *)col2, 20);
-
- /* Update length */
- buf[1] = bytes - 2;
-
- return bytes;
-
-}
-
-int adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just)
-{
- int bytes=0;
-
- if (page) {
- if (line > 4) return -1;
- } else {
- if (line > 33) return -1;
- }
-
- if (line < 1)
- return -1;
-
- buf[bytes++] = ADSI_INPUT_CONTROL;
- bytes++;
- buf[bytes++] = ((page & 1) << 7) | (line & 0x3f);
- buf[bytes++] = ((display & 1) << 7) | ((just & 0x3) << 4) | (format & 0x7);
-
- buf[1] = bytes - 2;
- return bytes;
-
-}
-
-int adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
-{
- int bytes = 0;
-
- if (!strlen((char *)format1))
- return -1;
-
- buf[bytes++] = ADSI_INPUT_FORMAT;
- bytes++;
- buf[bytes++] = ((dir & 1) << 7) | ((wrap & 1) << 6) | (num & 0x7);
- bytes += ccopy(buf + bytes, (unsigned char *)format1, 20);
- buf[bytes++] = 0xff;
- if (format2 && strlen((char *)format2)) {
- bytes += ccopy(buf + bytes, (unsigned char *)format2, 20);
- }
- buf[1] = bytes - 2;
- return bytes;
-}
-
-int adsi_set_keys(unsigned char *buf, unsigned char *keys)
-{
- int bytes=0;
- int x;
- /* Message type */
- buf[bytes++] = ADSI_INIT_SOFTKEY_LINE;
- /* Space for size */
- bytes++;
- /* Key definitions */
- for (x=0;x<6;x++)
- buf[bytes++] = (keys[x] & 0x3f) ? keys[x] : (keys[x] | 0x1);
- buf[1] = bytes - 2;
- return bytes;
-}
-
-int adsi_set_line(unsigned char *buf, int page, int line)
-{
- int bytes=0;
-
- /* Sanity check line number */
-
- if (page) {
- if (line > 4) return -1;
- } else {
- if (line > 33) return -1;
- }
-
- if (line < 1)
- return -1;
- /* Parameter type */
- buf[bytes++] = ADSI_LINE_CONTROL;
-
- /* Reserve space for size */
- bytes++;
-
- /* Page and line */
- buf[bytes++] = ((page & 0x1) << 7) | (line & 0x3f);
-
- buf[1] = bytes - 2;
- return bytes;
-
-};
-
-static int total = 0;
-static int speeds = 0;
-
-int adsi_channel_restore(struct ast_channel *chan)
-{
- unsigned char dsp[256];
- int bytes;
- int x;
- unsigned char keyd[6];
-
- memset(dsp, 0, sizeof(dsp));
-
- /* Start with initial display setup */
- bytes = 0;
- bytes += adsi_set_line(dsp + bytes, ADSI_INFO_PAGE, 1);
-
- /* Prepare key setup messages */
-
- if (speeds) {
- memset(keyd, 0, sizeof(keyd));
- for (x=0;x<speeds;x++) {
- keyd[x] = ADSI_SPEED_DIAL + x;
- }
- bytes += adsi_set_keys(dsp + bytes, keyd);
- }
- adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0);
- return 0;
-
-}
-
-int adsi_print(struct ast_channel *chan, char **lines, int *aligns, int voice)
-{
- unsigned char buf[4096];
- int bytes=0;
- int res;
- int x;
- for(x=0;lines[x];x++)
- bytes += adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, aligns[x], 0, lines[x], "");
- bytes += adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1);
- if (voice) {
- bytes += adsi_voice_mode(buf + bytes, 0);
- }
- res = adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
- if (voice) {
- /* Ignore the resulting DTMF B announcing it's in voice mode */
- ast_waitfordigit(chan, 1000);
- }
- return res;
-}
-
-int adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
-{
- unsigned char dsp[256];
- int bytes;
- int res;
- char resp[2];
-
- memset(dsp, 0, sizeof(dsp));
-
- /* Connect to session */
- bytes = 0;
- bytes += adsi_connect_session(dsp + bytes, app, ver);
-
- if (data)
- bytes += adsi_data_mode(dsp + bytes);
-
- /* Prepare key setup messages */
- if (adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0))
- return -1;
- if (app) {
- res = ast_readstring(chan, resp, 1, 1200, 1200, "");
- if (res < 0)
- return -1;
- if (res) {
- ast_log(LOG_DEBUG, "No response from CPE about version. Assuming not there.\n");
- return 0;
- }
- if (!strcmp(resp, "B")) {
- ast_log(LOG_DEBUG, "CPE has script '%s' version %d already loaded\n", app, ver);
- return 1;
- } else if (!strcmp(resp, "A")) {
- ast_log(LOG_DEBUG, "CPE hasn't script '%s' version %d already loaded\n", app, ver);
- } else {
- ast_log(LOG_WARNING, "Unexpected CPE response to script query: %s\n", resp);
- }
- } else
- return 1;
- return 0;
-
-}
-
-int adsi_unload_session(struct ast_channel *chan)
-{
- unsigned char dsp[256];
- int bytes;
-
- memset(dsp, 0, sizeof(dsp));
-
- /* Connect to session */
- bytes = 0;
- bytes += adsi_disconnect_session(dsp + bytes);
- bytes += adsi_voice_mode(dsp + bytes, 0);
-
- /* Prepare key setup messages */
- if (adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0))
- return -1;
- return 0;
-}
-
-static int str2align(char *s)
-{
- if (!strncasecmp(s, "l", 1))
- return ADSI_JUST_LEFT;
- else if (!strncasecmp(s, "r", 1))
- return ADSI_JUST_RIGHT;
- else if (!strncasecmp(s, "i", 1))
- return ADSI_JUST_IND;
- else
- return ADSI_JUST_CENT;
-}
-
-static void init_state(void)
-{
- int x;
-
- for (x=0;x<ADSI_MAX_INTRO;x++)
- aligns[x] = ADSI_JUST_CENT;
- strncpy(intro[0], "Welcome to the", sizeof(intro[0]) - 1);
- strncpy(intro[1], "Asterisk", sizeof(intro[1]) - 1);
- strncpy(intro[2], "Open Source PBX", sizeof(intro[2]) - 1);
- total = 3;
- speeds = 0;
- for (x=3;x<ADSI_MAX_INTRO;x++)
- intro[x][0] = '\0';
- memset(speeddial, 0, sizeof(speeddial));
- alignment = ADSI_JUST_CENT;
-}
-
-static void adsi_load(void)
-{
- int x;
- struct ast_config *conf;
- struct ast_variable *v;
- char *name, *sname;
- init_state();
- conf = ast_config_load("adsi.conf");
- if (conf) {
- x=0;
- v = ast_variable_browse(conf, "intro");
- while(v) {
- if (!strcasecmp(v->name, "alignment"))
- alignment = str2align(v->value);
- else if (!strcasecmp(v->name, "greeting")) {
- if (x < ADSI_MAX_INTRO) {
- aligns[x] = alignment;
- strncpy(intro[x], v->value, sizeof(intro[x]) - 1);
- intro[x][sizeof(intro[x]) - 1] = '\0';
- x++;
- }
- } else if (!strcasecmp(v->name, "maxretries")) {
- if (atoi(v->value) > 0)
- maxretries = atoi(v->value);
- }
- v = v->next;
- }
- v = ast_variable_browse(conf, "speeddial");
- if (x)
- total = x;
- x = 0;
- while(v) {
- char *stringp=NULL;
- stringp=v->value;
- name = strsep(&stringp, ",");
- sname = strsep(&stringp, ",");
- if (!sname)
- sname = name;
- if (x < ADSI_MAX_SPEED_DIAL) {
- /* Up to 20 digits */
- strncpy(speeddial[x][0], v->name, sizeof(speeddial[x][0]) - 1);
- strncpy(speeddial[x][1], name, 18);
- strncpy(speeddial[x][2], sname, 7);
- x++;
- }
- v = v->next;
-
- }
- if (x)
- speeds = x;
- ast_config_destroy(conf);
- }
-}
-
-int reload(void)
-{
- adsi_load();
- return 0;
-}
-
-int load_module(void)
-{
- adsi_load();
- return 0;
-}
-
-int unload_module(void)
-{
- /* Can't unload this once we're loaded */
- return -1;
-}
-
-char *description(void)
-{
- return "ADSI Resource";
-}
-
-int usecount(void)
-{
- /* We should never be unloaded */
- return 1;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/res/res_agi.c b/1.2-netsec/res/res_agi.c
deleted file mode 100644
index 8f9654443..000000000
--- a/1.2-netsec/res/res_agi.c
+++ /dev/null
@@ -1,2142 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief AGI - the Asterisk Gateway Interface
- *
- */
-
-#include <sys/types.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <math.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/astdb.h"
-#include "asterisk/callerid.h"
-#include "asterisk/cli.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/image.h"
-#include "asterisk/say.h"
-#include "asterisk/app.h"
-#include "asterisk/dsp.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/manager.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-#include "asterisk/strings.h"
-#include "asterisk/agi.h"
-
-#define MAX_ARGS 128
-#define MAX_COMMANDS 128
-
-/* Recycle some stuff from the CLI interface */
-#define fdprintf agi_debug_cli
-
-static char *tdesc = "Asterisk Gateway Interface (AGI)";
-
-static char *app = "AGI";
-
-static char *eapp = "EAGI";
-
-static char *deadapp = "DeadAGI";
-
-static char *synopsis = "Executes an AGI compliant application";
-static char *esynopsis = "Executes an EAGI compliant application";
-static char *deadsynopsis = "Executes AGI on a hungup channel";
-
-static char *descrip =
-" [E|Dead]AGI(command|args): Executes an Asterisk Gateway Interface compliant\n"
-"program on a channel. AGI allows Asterisk to launch external programs\n"
-"written in any language to control a telephony channel, play audio,\n"
-"read DTMF digits, etc. by communicating with the AGI protocol on stdin\n"
-"and stdout.\n"
-"Returns -1 on hangup (except for DeadAGI) or if application requested\n"
-" hangup, or 0 on non-hangup exit. \n"
-"Using 'EAGI' provides enhanced AGI, with incoming audio available out of band\n"
-"on file descriptor 3\n\n"
-"Use the CLI command 'show agi' to list available agi commands\n";
-
-static int agidebug = 0;
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-
-#define TONE_BLOCK_SIZE 200
-
-/* Max time to connect to an AGI remote host */
-#define MAX_AGI_CONNECT 2000
-
-#define AGI_PORT 4573
-
-static void agi_debug_cli(int fd, char *fmt, ...)
-{
- char *stuff;
- int res = 0;
-
- va_list ap;
- va_start(ap, fmt);
- res = vasprintf(&stuff, fmt, ap);
- va_end(ap);
- if (res == -1) {
- ast_log(LOG_ERROR, "Out of memory\n");
- } else {
- if (agidebug)
- ast_verbose("AGI Tx >> %s", stuff);
- ast_carefulwrite(fd, stuff, strlen(stuff), 100);
- free(stuff);
- }
-}
-
-/* launch_netscript: The fastagi handler.
- FastAGI defaults to port 4573 */
-static int launch_netscript(char *agiurl, char *argv[], int *fds, int *efd, int *opid)
-{
- int s;
- int flags;
- struct pollfd pfds[1];
- char *host;
- char *c; int port = AGI_PORT;
- char *script="";
- struct sockaddr_in sin;
- struct hostent *hp;
- struct ast_hostent ahp;
-
- host = ast_strdupa(agiurl + 6); /* Remove agi:// */
- if (!host)
- return -1;
- /* Strip off any script name */
- if ((c = strchr(host, '/'))) {
- *c = '\0';
- c++;
- script = c;
- }
- if ((c = strchr(host, ':'))) {
- *c = '\0';
- c++;
- port = atoi(c);
- }
- if (efd) {
- ast_log(LOG_WARNING, "AGI URI's don't support Enhanced AGI yet\n");
- return -1;
- }
- hp = ast_gethostbyname(host, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "Unable to locate host '%s'\n", host);
- return -1;
- }
- s = socket(AF_INET, SOCK_STREAM, 0);
- if (s < 0) {
- ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
- return -1;
- }
- flags = fcntl(s, F_GETFL);
- if (flags < 0) {
- ast_log(LOG_WARNING, "Fcntl(F_GETFL) failed: %s\n", strerror(errno));
- close(s);
- return -1;
- }
- if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0) {
- ast_log(LOG_WARNING, "Fnctl(F_SETFL) failed: %s\n", strerror(errno));
- close(s);
- return -1;
- }
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
- memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
- if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) && (errno != EINPROGRESS)) {
- ast_log(LOG_WARNING, "Connect failed with unexpected error: %s\n", strerror(errno));
- close(s);
- return -1;
- }
-
- pfds[0].fd = s;
- pfds[0].events = POLLOUT;
- while (poll(pfds, 1, MAX_AGI_CONNECT) != 1) {
- if (errno != EINTR) {
- ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
- close(s);
- return -1;
- }
- }
-
- while (write(s, "agi_network: yes\n", strlen("agi_network: yes\n")) < 0) {
- if (errno != EINTR) {
- ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
- close(s);
- return -1;
- }
- }
-
- /* If we have a script parameter, relay it to the fastagi server */
- if (!ast_strlen_zero(script))
- fdprintf(s, "agi_network_script: %s\n", script);
-
- if (option_debug > 3)
- ast_log(LOG_DEBUG, "Wow, connected!\n");
- fds[0] = s;
- fds[1] = s;
- *opid = -1;
- return 0;
-}
-
-static int launch_script(char *script, char *argv[], int *fds, int *efd, int *opid)
-{
- char tmp[256];
- int pid;
- int toast[2];
- int fromast[2];
- int audio[2];
- int x;
- int res;
- sigset_t signal_set;
-
- if (!strncasecmp(script, "agi://", 6))
- return launch_netscript(script, argv, fds, efd, opid);
-
- if (script[0] != '/') {
- snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_AGI_DIR, script);
- script = tmp;
- }
- if (pipe(toast)) {
- ast_log(LOG_WARNING, "Unable to create toast pipe: %s\n",strerror(errno));
- return -1;
- }
- if (pipe(fromast)) {
- ast_log(LOG_WARNING, "unable to create fromast pipe: %s\n", strerror(errno));
- close(toast[0]);
- close(toast[1]);
- return -1;
- }
- if (efd) {
- if (pipe(audio)) {
- ast_log(LOG_WARNING, "unable to create audio pipe: %s\n", strerror(errno));
- close(fromast[0]);
- close(fromast[1]);
- close(toast[0]);
- close(toast[1]);
- return -1;
- }
- res = fcntl(audio[1], F_GETFL);
- if (res > -1)
- res = fcntl(audio[1], F_SETFL, res | O_NONBLOCK);
- if (res < 0) {
- ast_log(LOG_WARNING, "unable to set audio pipe parameters: %s\n", strerror(errno));
- close(fromast[0]);
- close(fromast[1]);
- close(toast[0]);
- close(toast[1]);
- close(audio[0]);
- close(audio[1]);
- return -1;
- }
- }
- pid = fork();
- if (pid < 0) {
- ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno));
- return -1;
- }
- if (!pid) {
- /* Redirect stdin and out, provide enhanced audio channel if desired */
- dup2(fromast[0], STDIN_FILENO);
- dup2(toast[1], STDOUT_FILENO);
- if (efd) {
- dup2(audio[0], STDERR_FILENO + 1);
- } else {
- close(STDERR_FILENO + 1);
- }
-
- /* unblock important signal handlers */
- if (sigfillset(&signal_set) || pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) {
- ast_log(LOG_WARNING, "unable to unblock signals for AGI script: %s\n", strerror(errno));
- exit(1);
- }
-
- /* Close everything but stdin/out/error */
- for (x=STDERR_FILENO + 2;x<1024;x++)
- close(x);
-
- /* Don't run AGI scripts with realtime priority -- it causes audio stutter */
- ast_set_priority(0);
-
- /* Execute script */
- execv(script, argv);
- /* Can't use ast_log since FD's are closed */
- fprintf(stderr, "Failed to execute '%s': %s\n", script, strerror(errno));
- exit(1);
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Launched AGI Script %s\n", script);
- fds[0] = toast[0];
- fds[1] = fromast[1];
- if (efd) {
- *efd = audio[1];
- }
- /* close what we're not using in the parent */
- close(toast[1]);
- close(fromast[0]);
-
- if (efd) {
- /* [PHM 12/18/03] */
- close(audio[0]);
- }
-
- *opid = pid;
- return 0;
-
-}
-
-static void setup_env(struct ast_channel *chan, char *request, int fd, int enhanced)
-{
- /* Print initial environment, with agi_request always being the first
- thing */
- fdprintf(fd, "agi_request: %s\n", request);
- fdprintf(fd, "agi_channel: %s\n", chan->name);
- fdprintf(fd, "agi_language: %s\n", chan->language);
- fdprintf(fd, "agi_type: %s\n", chan->type);
- fdprintf(fd, "agi_uniqueid: %s\n", chan->uniqueid);
-
- /* ANI/DNIS */
- fdprintf(fd, "agi_callerid: %s\n", chan->cid.cid_num ? chan->cid.cid_num : "unknown");
- fdprintf(fd, "agi_calleridname: %s\n", chan->cid.cid_name ? chan->cid.cid_name : "unknown");
- fdprintf(fd, "agi_callingpres: %d\n", chan->cid.cid_pres);
- fdprintf(fd, "agi_callingani2: %d\n", chan->cid.cid_ani2);
- fdprintf(fd, "agi_callington: %d\n", chan->cid.cid_ton);
- fdprintf(fd, "agi_callingtns: %d\n", chan->cid.cid_tns);
- fdprintf(fd, "agi_dnid: %s\n", chan->cid.cid_dnid ? chan->cid.cid_dnid : "unknown");
- fdprintf(fd, "agi_rdnis: %s\n", chan->cid.cid_rdnis ? chan->cid.cid_rdnis : "unknown");
-
- /* Context information */
- fdprintf(fd, "agi_context: %s\n", chan->context);
- fdprintf(fd, "agi_extension: %s\n", chan->exten);
- fdprintf(fd, "agi_priority: %d\n", chan->priority);
- fdprintf(fd, "agi_enhanced: %s\n", enhanced ? "1.0" : "0.0");
-
- /* User information */
- fdprintf(fd, "agi_accountcode: %s\n", chan->accountcode ? chan->accountcode : "");
-
- /* End with empty return */
- fdprintf(fd, "\n");
-}
-
-static int handle_answer(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- res = 0;
- if (chan->_state != AST_STATE_UP) {
- /* Answer the chan */
- res = ast_answer(chan);
- }
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_waitfordigit(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- int to;
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- if (sscanf(argv[3], "%d", &to) != 1)
- return RESULT_SHOWUSAGE;
- res = ast_waitfordigit_full(chan, to, agi->audio, agi->ctrl);
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_sendtext(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- /* At the moment, the parser (perhaps broken) returns with
- the last argument PLUS the newline at the end of the input
- buffer. This probably needs to be fixed, but I wont do that
- because other stuff may break as a result. The right way
- would probably be to strip off the trailing newline before
- parsing, then here, add a newline at the end of the string
- before sending it to ast_sendtext --DUDE */
- res = ast_sendtext(chan, argv[2]);
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_recvchar(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- res = ast_recvchar(chan,atoi(argv[2]));
- if (res == 0) {
- fdprintf(agi->fd, "200 result=%d (timeout)\n", res);
- return RESULT_SUCCESS;
- }
- if (res > 0) {
- fdprintf(agi->fd, "200 result=%d\n", res);
- return RESULT_SUCCESS;
- }
- else {
- fdprintf(agi->fd, "200 result=%d (hangup)\n", res);
- return RESULT_FAILURE;
- }
-}
-
-static int handle_recvtext(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- char *buf;
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- buf = ast_recvtext(chan,atoi(argv[2]));
- if (buf) {
- fdprintf(agi->fd, "200 result=1 (%s)\n", buf);
- free(buf);
- } else {
- fdprintf(agi->fd, "200 result=-1\n");
- }
- return RESULT_SUCCESS;
-}
-
-static int handle_tddmode(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res,x;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- if (!strncasecmp(argv[2],"on",2))
- x = 1;
- else
- x = 0;
- if (!strncasecmp(argv[2],"mate",4))
- x = 2;
- if (!strncasecmp(argv[2],"tdd",3))
- x = 1;
- res = ast_channel_setoption(chan, AST_OPTION_TDD, &x, sizeof(char), 0);
- if (res != RESULT_SUCCESS)
- fdprintf(agi->fd, "200 result=0\n");
- else
- fdprintf(agi->fd, "200 result=1\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_sendimage(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- res = ast_send_image(chan, argv[2]);
- if (!ast_check_hangup(chan))
- res = 0;
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_controlstreamfile(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res = 0;
- int skipms = 3000;
- char *fwd = NULL;
- char *rev = NULL;
- char *pause = NULL;
- char *stop = NULL;
-
- if (argc < 5 || argc > 9)
- return RESULT_SHOWUSAGE;
-
- if (!ast_strlen_zero(argv[4]))
- stop = argv[4];
- else
- stop = NULL;
-
- if ((argc > 5) && (sscanf(argv[5], "%d", &skipms) != 1))
- return RESULT_SHOWUSAGE;
-
- if (argc > 6 && !ast_strlen_zero(argv[8]))
- fwd = argv[6];
- else
- fwd = "#";
-
- if (argc > 7 && !ast_strlen_zero(argv[8]))
- rev = argv[7];
- else
- rev = "*";
-
- if (argc > 8 && !ast_strlen_zero(argv[8]))
- pause = argv[8];
- else
- pause = NULL;
-
- res = ast_control_streamfile(chan, argv[3], fwd, rev, stop, pause, NULL, skipms);
-
- fdprintf(agi->fd, "200 result=%d\n", res);
-
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- struct ast_filestream *fs;
- long sample_offset = 0;
- long max_length;
-
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- if (argc > 5)
- return RESULT_SHOWUSAGE;
- if ((argc > 4) && (sscanf(argv[4], "%ld", &sample_offset) != 1))
- return RESULT_SHOWUSAGE;
-
- fs = ast_openstream(chan, argv[2], chan->language);
- if (!fs){
- fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
- return RESULT_SUCCESS;
- }
- ast_seekstream(fs, 0, SEEK_END);
- max_length = ast_tellstream(fs);
- ast_seekstream(fs, sample_offset, SEEK_SET);
- res = ast_applystream(chan, fs);
- res = ast_playstream(fs);
- if (res) {
- fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
- if (res >= 0)
- return RESULT_SHOWUSAGE;
- else
- return RESULT_FAILURE;
- }
- res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl);
- /* this is to check for if ast_waitstream closed the stream, we probably are at
- * the end of the stream, return that amount, else check for the amount */
- sample_offset = (chan->stream) ? ast_tellstream(fs) : max_length;
- ast_stopstream(chan);
- if (res == 1) {
- /* Stop this command, don't print a result line, as there is a new command */
- return RESULT_SUCCESS;
- }
- fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-/* get option - really similar to the handle_streamfile, but with a timeout */
-static int handle_getoption(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- struct ast_filestream *fs;
- long sample_offset = 0;
- long max_length;
- int timeout = 0;
- char *edigits = NULL;
-
- if ( argc < 4 || argc > 5 )
- return RESULT_SHOWUSAGE;
-
- if ( argv[3] )
- edigits = argv[3];
-
- if ( argc == 5 )
- timeout = atoi(argv[4]);
- else if (chan->pbx->dtimeout) {
- /* by default dtimeout is set to 5sec */
- timeout = chan->pbx->dtimeout * 1000; /* in msec */
- }
-
- fs = ast_openstream(chan, argv[2], chan->language);
- if (!fs){
- fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
- ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]);
- return RESULT_SUCCESS;
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Playing '%s' (escape_digits=%s) (timeout %d)\n", argv[2], edigits, timeout);
-
- ast_seekstream(fs, 0, SEEK_END);
- max_length = ast_tellstream(fs);
- ast_seekstream(fs, sample_offset, SEEK_SET);
- res = ast_applystream(chan, fs);
- res = ast_playstream(fs);
- if (res) {
- fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
- if (res >= 0)
- return RESULT_SHOWUSAGE;
- else
- return RESULT_FAILURE;
- }
- res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl);
- /* this is to check for if ast_waitstream closed the stream, we probably are at
- * the end of the stream, return that amount, else check for the amount */
- sample_offset = (chan->stream)?ast_tellstream(fs):max_length;
- ast_stopstream(chan);
- if (res == 1) {
- /* Stop this command, don't print a result line, as there is a new command */
- return RESULT_SUCCESS;
- }
-
- /* If the user didnt press a key, wait for digitTimeout*/
- if (res == 0 ) {
- res = ast_waitfordigit_full(chan, timeout, agi->audio, agi->ctrl);
- /* Make sure the new result is in the escape digits of the GET OPTION */
- if ( !strchr(edigits,res) )
- res=0;
- }
-
- fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-
-
-
-/*--- handle_saynumber: Say number in various language syntaxes ---*/
-/* Need to add option for gender here as well. Coders wanted */
-/* While waiting, we're sending a (char *) NULL. */
-static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- int num;
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- if (sscanf(argv[2], "%d", &num) != 1)
- return RESULT_SHOWUSAGE;
- res = ast_say_number_full(chan, num, argv[3], chan->language, (char *) NULL, agi->audio, agi->ctrl);
- if (res == 1)
- return RESULT_SUCCESS;
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_saydigits(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- int num;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- if (sscanf(argv[2], "%d", &num) != 1)
- return RESULT_SHOWUSAGE;
-
- res = ast_say_digit_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
- if (res == 1) /* New command */
- return RESULT_SUCCESS;
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_sayalpha(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- res = ast_say_character_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
- if (res == 1) /* New command */
- return RESULT_SUCCESS;
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_saydate(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- int num;
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- if (sscanf(argv[2], "%d", &num) != 1)
- return RESULT_SHOWUSAGE;
- res = ast_say_date(chan, num, argv[3], chan->language);
- if (res == 1)
- return RESULT_SUCCESS;
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_saytime(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- int num;
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- if (sscanf(argv[2], "%d", &num) != 1)
- return RESULT_SHOWUSAGE;
- res = ast_say_time(chan, num, argv[3], chan->language);
- if (res == 1)
- return RESULT_SUCCESS;
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_saydatetime(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res=0;
- long unixtime;
- char *format, *zone=NULL;
-
- if (argc < 4)
- return RESULT_SHOWUSAGE;
-
- if (argc > 4) {
- format = argv[4];
- } else {
- if (!strcasecmp(chan->language, "de")) {
- format = "A dBY HMS";
- } else {
- format = "ABdY 'digits/at' IMp";
- }
- }
-
- if (argc > 5 && !ast_strlen_zero(argv[5]))
- zone = argv[5];
-
- if (sscanf(argv[2], "%ld", &unixtime) != 1)
- return RESULT_SHOWUSAGE;
-
- res = ast_say_date_with_format(chan, (time_t) unixtime, argv[3], chan->language, format, zone);
- if (res == 1)
- return RESULT_SUCCESS;
-
- fdprintf(agi->fd, "200 result=%d\n", res);
-
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_sayphonetic(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- res = ast_say_phonetic_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
- if (res == 1) /* New command */
- return RESULT_SUCCESS;
- fdprintf(agi->fd, "200 result=%d\n", res);
- if (res >= 0)
- return RESULT_SUCCESS;
- else
- return RESULT_FAILURE;
-}
-
-static int handle_getdata(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int res;
- char data[1024];
- int max;
- int timeout;
-
- if (argc < 3)
- return RESULT_SHOWUSAGE;
- if (argc >= 4)
- timeout = atoi(argv[3]);
- else
- timeout = 0;
- if (argc >= 5)
- max = atoi(argv[4]);
- else
- max = 1024;
- res = ast_app_getdata_full(chan, argv[2], data, max, timeout, agi->audio, agi->ctrl);
- if (res == 2) /* New command */
- return RESULT_SUCCESS;
- else if (res == 1)
- fdprintf(agi->fd, "200 result=%s (timeout)\n", data);
- else if (res < 0 )
- fdprintf(agi->fd, "200 result=-1\n");
- else
- fdprintf(agi->fd, "200 result=%s\n", data);
- return RESULT_SUCCESS;
-}
-
-static int handle_setcontext(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_copy_string(chan->context, argv[2], sizeof(chan->context));
- fdprintf(agi->fd, "200 result=0\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_setextension(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_copy_string(chan->exten, argv[2], sizeof(chan->exten));
- fdprintf(agi->fd, "200 result=0\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_setpriority(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- int pri;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
-
- if (sscanf(argv[2], "%d", &pri) != 1) {
- if ((pri = ast_findlabel_extension(chan, chan->context, chan->exten, argv[2], chan->cid.cid_num)) < 1)
- return RESULT_SHOWUSAGE;
- }
-
- ast_explicit_goto(chan, NULL, NULL, pri);
- fdprintf(agi->fd, "200 result=0\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_recordfile(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- struct ast_filestream *fs;
- struct ast_frame *f;
- struct timeval start;
- long sample_offset = 0;
- int res = 0;
- int ms;
-
- struct ast_dsp *sildet=NULL; /* silence detector dsp */
- int totalsilence = 0;
- int dspsilence = 0;
- int silence = 0; /* amount of silence to allow */
- int gotsilence = 0; /* did we timeout for silence? */
- char *silencestr=NULL;
- int rfmt=0;
-
-
- /* XXX EAGI FIXME XXX */
-
- if (argc < 6)
- return RESULT_SHOWUSAGE;
- if (sscanf(argv[5], "%d", &ms) != 1)
- return RESULT_SHOWUSAGE;
-
- if (argc > 6)
- silencestr = strchr(argv[6],'s');
- if ((argc > 7) && (!silencestr))
- silencestr = strchr(argv[7],'s');
- if ((argc > 8) && (!silencestr))
- silencestr = strchr(argv[8],'s');
-
- if (silencestr) {
- if (strlen(silencestr) > 2) {
- if ((silencestr[0] == 's') && (silencestr[1] == '=')) {
- silencestr++;
- silencestr++;
- if (silencestr)
- silence = atoi(silencestr);
- if (silence > 0)
- silence *= 1000;
- }
- }
- }
-
- if (silence > 0) {
- 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");
- return -1;
- }
- sildet = ast_dsp_new();
- if (!sildet) {
- ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
- return -1;
- }
- ast_dsp_set_threshold(sildet, 256);
- }
-
- /* backward compatibility, if no offset given, arg[6] would have been
- * caught below and taken to be a beep, else if it is a digit then it is a
- * offset */
- if ((argc >6) && (sscanf(argv[6], "%ld", &sample_offset) != 1) && (!strchr(argv[6], '=')))
- res = ast_streamfile(chan, "beep", chan->language);
-
- if ((argc > 7) && (!strchr(argv[7], '=')))
- res = ast_streamfile(chan, "beep", chan->language);
-
- if (!res)
- res = ast_waitstream(chan, argv[4]);
- if (res) {
- fdprintf(agi->fd, "200 result=%d (randomerror) endpos=%ld\n", res, sample_offset);
- } else {
- fs = ast_writefile(argv[2], argv[3], NULL, O_CREAT | O_WRONLY | (sample_offset ? O_APPEND : 0), 0, 0644);
- if (!fs) {
- res = -1;
- fdprintf(agi->fd, "200 result=%d (writefile)\n", res);
- if (sildet)
- ast_dsp_free(sildet);
- return RESULT_FAILURE;
- }
-
- chan->stream = fs;
- ast_applystream(chan,fs);
- /* really should have checks */
- ast_seekstream(fs, sample_offset, SEEK_SET);
- ast_truncstream(fs);
-
- start = ast_tvnow();
- while ((ms < 0) || ast_tvdiff_ms(ast_tvnow(), start) < ms) {
- res = ast_waitfor(chan, -1);
- if (res < 0) {
- ast_closestream(fs);
- fdprintf(agi->fd, "200 result=%d (waitfor) endpos=%ld\n", res,sample_offset);
- if (sildet)
- ast_dsp_free(sildet);
- return RESULT_FAILURE;
- }
- f = ast_read(chan);
- if (!f) {
- fdprintf(agi->fd, "200 result=%d (hangup) endpos=%ld\n", 0, sample_offset);
- ast_closestream(fs);
- if (sildet)
- ast_dsp_free(sildet);
- return RESULT_FAILURE;
- }
- switch(f->frametype) {
- case AST_FRAME_DTMF:
- if (strchr(argv[4], f->subclass)) {
- /* This is an interrupting chracter, so rewind to chop off any small
- amount of DTMF that may have been recorded
- */
- ast_stream_rewind(fs, 200);
- ast_truncstream(fs);
- sample_offset = ast_tellstream(fs);
- fdprintf(agi->fd, "200 result=%d (dtmf) endpos=%ld\n", f->subclass, sample_offset);
- ast_closestream(fs);
- ast_frfree(f);
- if (sildet)
- ast_dsp_free(sildet);
- return RESULT_SUCCESS;
- }
- break;
- case AST_FRAME_VOICE:
- ast_writestream(fs, f);
- /* this is a safe place to check progress since we know that fs
- * is valid after a write, and it will then have our current
- * location */
- sample_offset = ast_tellstream(fs);
- if (silence > 0) {
- dspsilence = 0;
- ast_dsp_silence(sildet, f, &dspsilence);
- if (dspsilence) {
- totalsilence = dspsilence;
- } else {
- totalsilence = 0;
- }
- if (totalsilence > silence) {
- /* Ended happily with silence */
- ast_frfree(f);
- gotsilence = 1;
- break;
- }
- }
- break;
- }
- ast_frfree(f);
- if (gotsilence)
- break;
- }
-
- if (gotsilence) {
- ast_stream_rewind(fs, silence-1000);
- ast_truncstream(fs);
- sample_offset = ast_tellstream(fs);
- }
- fdprintf(agi->fd, "200 result=%d (timeout) endpos=%ld\n", res, sample_offset);
- ast_closestream(fs);
- }
-
- if (silence > 0) {
- res = ast_set_read_format(chan, rfmt);
- if (res)
- ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
- ast_dsp_free(sildet);
- }
- return RESULT_SUCCESS;
-}
-
-static int handle_autohangup(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- int timeout;
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- if (sscanf(argv[2], "%d", &timeout) != 1)
- return RESULT_SHOWUSAGE;
- if (timeout < 0)
- timeout = 0;
- if (timeout)
- chan->whentohangup = time(NULL) + timeout;
- else
- chan->whentohangup = 0;
- fdprintf(agi->fd, "200 result=0\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_hangup(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- struct ast_channel *c;
- if (argc == 1) {
- /* no argument: hangup the current channel */
- ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT);
- fdprintf(agi->fd, "200 result=1\n");
- return RESULT_SUCCESS;
- } else if (argc == 2) {
- /* one argument: look for info on the specified channel */
- c = ast_get_channel_by_name_locked(argv[1]);
- if (c) {
- /* we have a matching channel */
- ast_softhangup(c,AST_SOFTHANGUP_EXPLICIT);
- fdprintf(agi->fd, "200 result=1\n");
- ast_mutex_unlock(&c->lock);
- return RESULT_SUCCESS;
- }
- /* if we get this far no channel name matched the argument given */
- fdprintf(agi->fd, "200 result=-1\n");
- return RESULT_SUCCESS;
- } else {
- return RESULT_SHOWUSAGE;
- }
-}
-
-static int handle_exec(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- int res;
- struct ast_app *app;
-
- if (argc < 2)
- return RESULT_SHOWUSAGE;
-
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "AGI Script Executing Application: (%s) Options: (%s)\n", argv[1], argv[2]);
-
- app = pbx_findapp(argv[1]);
-
- if (app) {
- res = pbx_exec(chan, app, argv[2], 1);
- } else {
- ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]);
- res = -2;
- }
- fdprintf(agi->fd, "200 result=%d\n", res);
-
- return res;
-}
-
-static int handle_setcallerid(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- char tmp[256]="";
- char *l = NULL, *n = NULL;
-
- if (argv[2]) {
- ast_copy_string(tmp, argv[2], sizeof(tmp));
- ast_callerid_parse(tmp, &n, &l);
- if (l)
- ast_shrink_phone_number(l);
- else
- l = "";
- if (!n)
- n = "";
- ast_set_callerid(chan, l, n, NULL);
- }
-
- fdprintf(agi->fd, "200 result=1\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_channelstatus(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- struct ast_channel *c;
- if (argc == 2) {
- /* no argument: supply info on the current channel */
- fdprintf(agi->fd, "200 result=%d\n", chan->_state);
- return RESULT_SUCCESS;
- } else if (argc == 3) {
- /* one argument: look for info on the specified channel */
- c = ast_get_channel_by_name_locked(argv[2]);
- if (c) {
- fdprintf(agi->fd, "200 result=%d\n", c->_state);
- ast_mutex_unlock(&c->lock);
- return RESULT_SUCCESS;
- }
- /* if we get this far no channel name matched the argument given */
- fdprintf(agi->fd, "200 result=-1\n");
- return RESULT_SUCCESS;
- } else {
- return RESULT_SHOWUSAGE;
- }
-}
-
-static int handle_setvariable(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- if (argv[3])
- pbx_builtin_setvar_helper(chan, argv[2], argv[3]);
-
- fdprintf(agi->fd, "200 result=1\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_getvariable(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- char *ret;
- char tempstr[1024];
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
-
- /* check if we want to execute an ast_custom_function */
- if (!ast_strlen_zero(argv[2]) && (argv[2][strlen(argv[2]) - 1] == ')')) {
- ret = ast_func_read(chan, argv[2], tempstr, sizeof(tempstr));
- } else {
- pbx_retrieve_variable(chan, argv[2], &ret, tempstr, sizeof(tempstr), NULL);
- }
-
- if (ret)
- fdprintf(agi->fd, "200 result=1 (%s)\n", ret);
- else
- fdprintf(agi->fd, "200 result=0\n");
-
- return RESULT_SUCCESS;
-}
-
-static int handle_getvariablefull(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- char tmp[4096] = "";
- struct ast_channel *chan2=NULL;
-
- if ((argc != 4) && (argc != 5))
- return RESULT_SHOWUSAGE;
- if (argc == 5) {
- chan2 = ast_get_channel_by_name_locked(argv[4]);
- } else {
- chan2 = chan;
- }
- if (chan) { /* XXX isn't this chan2 ? */
- pbx_substitute_variables_helper(chan2, argv[3], tmp, sizeof(tmp) - 1);
- fdprintf(agi->fd, "200 result=1 (%s)\n", tmp);
- } else {
- fdprintf(agi->fd, "200 result=0\n");
- }
- if (chan2 && (chan2 != chan))
- ast_mutex_unlock(&chan2->lock);
- return RESULT_SUCCESS;
-}
-
-static int handle_verbose(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- int level = 0;
- char *prefix;
-
- if (argc < 2)
- return RESULT_SHOWUSAGE;
-
- if (argv[2])
- sscanf(argv[2], "%d", &level);
-
- switch (level) {
- case 4:
- prefix = VERBOSE_PREFIX_4;
- break;
- case 3:
- prefix = VERBOSE_PREFIX_3;
- break;
- case 2:
- prefix = VERBOSE_PREFIX_2;
- break;
- case 1:
- default:
- prefix = VERBOSE_PREFIX_1;
- break;
- }
-
- if (level <= option_verbose)
- ast_verbose("%s %s: %s\n", prefix, chan->data, argv[1]);
-
- fdprintf(agi->fd, "200 result=1\n");
-
- return RESULT_SUCCESS;
-}
-
-static int handle_dbget(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- int res;
- char tmp[256];
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- res = ast_db_get(argv[2], argv[3], tmp, sizeof(tmp));
- if (res)
- fdprintf(agi->fd, "200 result=0\n");
- else
- fdprintf(agi->fd, "200 result=1 (%s)\n", tmp);
-
- return RESULT_SUCCESS;
-}
-
-static int handle_dbput(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- int res;
-
- if (argc != 5)
- return RESULT_SHOWUSAGE;
- res = ast_db_put(argv[2], argv[3], argv[4]);
- if (res)
- fdprintf(agi->fd, "200 result=0\n");
- else
- fdprintf(agi->fd, "200 result=1\n");
-
- return RESULT_SUCCESS;
-}
-
-static int handle_dbdel(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- int res;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- res = ast_db_del(argv[2], argv[3]);
- if (res)
- fdprintf(agi->fd, "200 result=0\n");
- else
- fdprintf(agi->fd, "200 result=1\n");
-
- return RESULT_SUCCESS;
-}
-
-static int handle_dbdeltree(struct ast_channel *chan, AGI *agi, int argc, char **argv)
-{
- int res;
- if ((argc < 3) || (argc > 4))
- return RESULT_SHOWUSAGE;
- if (argc == 4)
- res = ast_db_deltree(argv[2], argv[3]);
- else
- res = ast_db_deltree(argv[2], NULL);
-
- if (res)
- fdprintf(agi->fd, "200 result=0\n");
- else
- fdprintf(agi->fd, "200 result=1\n");
- return RESULT_SUCCESS;
-}
-
-static char debug_usage[] =
-"Usage: agi debug\n"
-" Enables dumping of AGI transactions for debugging purposes\n";
-
-static char no_debug_usage[] =
-"Usage: agi no debug\n"
-" Disables dumping of AGI transactions for debugging purposes\n";
-
-static int agi_do_debug(int fd, int argc, char *argv[])
-{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- agidebug = 1;
- ast_cli(fd, "AGI Debugging Enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int agi_no_debug(int fd, int argc, char *argv[])
-{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- agidebug = 0;
- ast_cli(fd, "AGI Debugging Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static struct ast_cli_entry cli_debug =
- { { "agi", "debug", NULL }, agi_do_debug, "Enable AGI debugging", debug_usage };
-
-static struct ast_cli_entry cli_no_debug =
- { { "agi", "no", "debug", NULL }, agi_no_debug, "Disable AGI debugging", no_debug_usage };
-
-static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, char *argv[])
-{
- fdprintf(agi->fd, "200 result=0\n");
- return RESULT_SUCCESS;
-}
-
-static int handle_setmusic(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
-{
- if (!strncasecmp(argv[2],"on",2)) {
- if (argc > 3)
- ast_moh_start(chan, argv[3]);
- else
- ast_moh_start(chan, NULL);
- }
- if (!strncasecmp(argv[2],"off",3)) {
- ast_moh_stop(chan);
- }
- fdprintf(agi->fd, "200 result=0\n");
- return RESULT_SUCCESS;
-}
-
-static char usage_setmusic[] =
-" Usage: SET MUSIC ON <on|off> <class>\n"
-" Enables/Disables the music on hold generator. If <class> is\n"
-" not specified, then the default music on hold class will be used.\n"
-" Always returns 0.\n";
-
-static char usage_dbput[] =
-" Usage: DATABASE PUT <family> <key> <value>\n"
-" Adds or updates an entry in the Asterisk database for a\n"
-" given family, key, and value.\n"
-" Returns 1 if successful, 0 otherwise.\n";
-
-static char usage_dbget[] =
-" Usage: DATABASE GET <family> <key>\n"
-" Retrieves an entry in the Asterisk database for a\n"
-" given family and key.\n"
-" Returns 0 if <key> is not set. Returns 1 if <key>\n"
-" is set and returns the variable in parentheses.\n"
-" Example return code: 200 result=1 (testvariable)\n";
-
-static char usage_dbdel[] =
-" Usage: DATABASE DEL <family> <key>\n"
-" Deletes an entry in the Asterisk database for a\n"
-" given family and key.\n"
-" Returns 1 if successful, 0 otherwise.\n";
-
-static char usage_dbdeltree[] =
-" Usage: DATABASE DELTREE <family> [keytree]\n"
-" Deletes a family or specific keytree within a family\n"
-" in the Asterisk database.\n"
-" Returns 1 if successful, 0 otherwise.\n";
-
-static char usage_verbose[] =
-" Usage: VERBOSE <message> <level>\n"
-" Sends <message> to the console via verbose message system.\n"
-" <level> is the the verbose level (1-4)\n"
-" Always returns 1.\n";
-
-static char usage_getvariable[] =
-" Usage: GET VARIABLE <variablename>\n"
-" Returns 0 if <variablename> is not set. Returns 1 if <variablename>\n"
-" is set and returns the variable in parentheses.\n"
-" example return code: 200 result=1 (testvariable)\n";
-
-static char usage_getvariablefull[] =
-" Usage: GET FULL VARIABLE <variablename> [<channel name>]\n"
-" Returns 0 if <variablename> is not set or channel does not exist. Returns 1\n"
-"if <variablename> is set and returns the variable in parenthesis. Understands\n"
-"complex variable names and builtin variables, unlike GET VARIABLE.\n"
-" example return code: 200 result=1 (testvariable)\n";
-
-static char usage_setvariable[] =
-" Usage: SET VARIABLE <variablename> <value>\n";
-
-static char usage_channelstatus[] =
-" Usage: CHANNEL STATUS [<channelname>]\n"
-" Returns the status of the specified channel.\n"
-" If no channel name is given the returns the status of the\n"
-" current channel. Return values:\n"
-" 0 Channel is down and available\n"
-" 1 Channel is down, but reserved\n"
-" 2 Channel is off hook\n"
-" 3 Digits (or equivalent) have been dialed\n"
-" 4 Line is ringing\n"
-" 5 Remote end is ringing\n"
-" 6 Line is up\n"
-" 7 Line is busy\n";
-
-static char usage_setcallerid[] =
-" Usage: SET CALLERID <number>\n"
-" Changes the callerid of the current channel.\n";
-
-static char usage_exec[] =
-" Usage: EXEC <application> <options>\n"
-" Executes <application> with given <options>.\n"
-" Returns whatever the application returns, or -2 on failure to find application\n";
-
-static char usage_hangup[] =
-" Usage: HANGUP [<channelname>]\n"
-" Hangs up the specified channel.\n"
-" If no channel name is given, hangs up the current channel\n";
-
-static char usage_answer[] =
-" Usage: ANSWER\n"
-" Answers channel if not already in answer state. Returns -1 on\n"
-" channel failure, or 0 if successful.\n";
-
-static char usage_waitfordigit[] =
-" Usage: WAIT FOR DIGIT <timeout>\n"
-" Waits up to 'timeout' milliseconds for channel to receive a DTMF digit.\n"
-" Returns -1 on channel failure, 0 if no digit is received in the timeout, or\n"
-" the numerical value of the ascii of the digit if one is received. Use -1\n"
-" for the timeout value if you desire the call to block indefinitely.\n";
-
-static char usage_sendtext[] =
-" Usage: SEND TEXT \"<text to send>\"\n"
-" Sends the given text on a channel. Most channels do not support the\n"
-" transmission of text. Returns 0 if text is sent, or if the channel does not\n"
-" support text transmission. Returns -1 only on error/hangup. Text\n"
-" consisting of greater than one word should be placed in quotes since the\n"
-" command only accepts a single argument.\n";
-
-static char usage_recvchar[] =
-" Usage: RECEIVE CHAR <timeout>\n"
-" Receives a character of text on a channel. Specify timeout to be the\n"
-" maximum time to wait for input in milliseconds, or 0 for infinite. Most channels\n"
-" do not support the reception of text. Returns the decimal value of the character\n"
-" if one is received, or 0 if the channel does not support text reception. Returns\n"
-" -1 only on error/hangup.\n";
-
-static char usage_recvtext[] =
-" Usage: RECEIVE TEXT <timeout>\n"
-" Receives a string of text on a channel. Specify timeout to be the\n"
-" maximum time to wait for input in milliseconds, or 0 for infinite. Most channels\n"
-" do not support the reception of text. Returns -1 for failure or 1 for success, and the string in parentheses.\n";
-
-static char usage_tddmode[] =
-" Usage: TDD MODE <on|off>\n"
-" Enable/Disable TDD transmission/reception on a channel. Returns 1 if\n"
-" successful, or 0 if channel is not TDD-capable.\n";
-
-static char usage_sendimage[] =
-" Usage: SEND IMAGE <image>\n"
-" Sends the given image on a channel. Most channels do not support the\n"
-" transmission of images. Returns 0 if image is sent, or if the channel does not\n"
-" support image transmission. Returns -1 only on error/hangup. Image names\n"
-" should not include extensions.\n";
-
-static char usage_streamfile[] =
-" Usage: STREAM FILE <filename> <escape digits> [sample offset]\n"
-" Send the given file, allowing playback to be interrupted by the given\n"
-" digits, if any. Use double quotes for the digits if you wish none to be\n"
-" permitted. If sample offset is provided then the audio will seek to sample\n"
-" offset before play starts. Returns 0 if playback completes without a digit\n"
-" being pressed, or the ASCII numerical value of the digit if one was pressed,\n"
-" or -1 on error or if the channel was disconnected. Remember, the file\n"
-" extension must not be included in the filename.\n";
-
-static char usage_controlstreamfile[] =
-" Usage: CONTROL STREAM FILE <filename> <escape digits> [skipms] [ffchar] [rewchr] [pausechr]\n"
-" Send the given file, allowing playback to be controled by the given\n"
-" digits, if any. Use double quotes for the digits if you wish none to be\n"
-" permitted. Returns 0 if playback completes without a digit\n"
-" being pressed, or the ASCII numerical value of the digit if one was pressed,\n"
-" or -1 on error or if the channel was disconnected. Remember, the file\n"
-" extension must not be included in the filename.\n\n"
-" Note: ffchar and rewchar default to * and # respectively.\n";
-
-static char usage_getoption[] =
-" Usage: GET OPTION <filename> <escape_digits> [timeout]\n"
-" Behaves similar to STREAM FILE but used with a timeout option.\n";
-
-static char usage_saynumber[] =
-" Usage: SAY NUMBER <number> <escape digits>\n"
-" Say a given number, returning early if any of the given DTMF digits\n"
-" are received on the channel. Returns 0 if playback completes without a digit\n"
-" being pressed, or the ASCII numerical value of the digit if one was pressed or\n"
-" -1 on error/hangup.\n";
-
-static char usage_saydigits[] =
-" Usage: SAY DIGITS <number> <escape digits>\n"
-" Say a given digit string, returning early if any of the given DTMF digits\n"
-" are received on the channel. Returns 0 if playback completes without a digit\n"
-" being pressed, or the ASCII numerical value of the digit if one was pressed or\n"
-" -1 on error/hangup.\n";
-
-static char usage_sayalpha[] =
-" Usage: SAY ALPHA <number> <escape digits>\n"
-" Say a given character string, returning early if any of the given DTMF digits\n"
-" are received on the channel. Returns 0 if playback completes without a digit\n"
-" being pressed, or the ASCII numerical value of the digit if one was pressed or\n"
-" -1 on error/hangup.\n";
-
-static char usage_saydate[] =
-" Usage: SAY DATE <date> <escape digits>\n"
-" Say a given date, returning early if any of the given DTMF digits are\n"
-" received on the channel. <date> is number of seconds elapsed since 00:00:00\n"
-" on January 1, 1970, Coordinated Universal Time (UTC). Returns 0 if playback\n"
-" completes without a digit being pressed, or the ASCII numerical value of the\n"
-" digit if one was pressed or -1 on error/hangup.\n";
-
-static char usage_saytime[] =
-" Usage: SAY TIME <time> <escape digits>\n"
-" Say a given time, returning early if any of the given DTMF digits are\n"
-" received on the channel. <time> is number of seconds elapsed since 00:00:00\n"
-" on January 1, 1970, Coordinated Universal Time (UTC). Returns 0 if playback\n"
-" completes without a digit being pressed, or the ASCII numerical value of the\n"
-" digit if one was pressed or -1 on error/hangup.\n";
-
-static char usage_saydatetime[] =
-" Usage: SAY DATETIME <time> <escape digits> [format] [timezone]\n"
-" Say a given time, returning early if any of the given DTMF digits are\n"
-" received on the channel. <time> is number of seconds elapsed since 00:00:00\n"
-" on January 1, 1970, Coordinated Universal Time (UTC). [format] is the format\n"
-" the time should be said in. See voicemail.conf (defaults to \"ABdY\n"
-" 'digits/at' IMp\"). Acceptable values for [timezone] can be found in\n"
-" /usr/share/zoneinfo. Defaults to machine default. Returns 0 if playback\n"
-" completes without a digit being pressed, or the ASCII numerical value of the\n"
-" digit if one was pressed or -1 on error/hangup.\n";
-
-static char usage_sayphonetic[] =
-" Usage: SAY PHONETIC <string> <escape digits>\n"
-" Say a given character string with phonetics, returning early if any of the\n"
-" given DTMF digits are received on the channel. Returns 0 if playback\n"
-" completes without a digit pressed, the ASCII numerical value of the digit\n"
-" if one was pressed, or -1 on error/hangup.\n";
-
-static char usage_getdata[] =
-" Usage: GET DATA <file to be streamed> [timeout] [max digits]\n"
-" Stream the given file, and recieve DTMF data. Returns the digits received\n"
-"from the channel at the other end.\n";
-
-static char usage_setcontext[] =
-" Usage: SET CONTEXT <desired context>\n"
-" Sets the context for continuation upon exiting the application.\n";
-
-static char usage_setextension[] =
-" Usage: SET EXTENSION <new extension>\n"
-" Changes the extension for continuation upon exiting the application.\n";
-
-static char usage_setpriority[] =
-" Usage: SET PRIORITY <priority>\n"
-" Changes the priority for continuation upon exiting the application.\n"
-" The priority must be a valid priority or label.\n";
-
-static char usage_recordfile[] =
-" Usage: RECORD FILE <filename> <format> <escape digits> <timeout> \\\n"
-" [offset samples] [BEEP] [s=silence]\n"
-" Record to a file until a given dtmf digit in the sequence is received\n"
-" Returns -1 on hangup or error. The format will specify what kind of file\n"
-" will be recorded. The timeout is the maximum record time in milliseconds, or\n"
-" -1 for no timeout. \"Offset samples\" is optional, and, if provided, will seek\n"
-" to the offset without exceeding the end of the file. \"silence\" is the number\n"
-" of seconds of silence allowed before the function returns despite the\n"
-" lack of dtmf digits or reaching timeout. Silence value must be\n"
-" preceeded by \"s=\" and is also optional.\n";
-
-static char usage_autohangup[] =
-" Usage: SET AUTOHANGUP <time>\n"
-" Cause the channel to automatically hangup at <time> seconds in the\n"
-" future. Of course it can be hungup before then as well. Setting to 0 will\n"
-" cause the autohangup feature to be disabled on this channel.\n";
-
-static char usage_noop[] =
-" Usage: NoOp\n"
-" Does nothing.\n";
-
-static agi_command commands[MAX_COMMANDS] = {
- { { "answer", NULL }, handle_answer, "Answer channel", usage_answer },
- { { "channel", "status", NULL }, handle_channelstatus, "Returns status of the connected channel", usage_channelstatus },
- { { "database", "del", NULL }, handle_dbdel, "Removes database key/value", usage_dbdel },
- { { "database", "deltree", NULL }, handle_dbdeltree, "Removes database keytree/value", usage_dbdeltree },
- { { "database", "get", NULL }, handle_dbget, "Gets database value", usage_dbget },
- { { "database", "put", NULL }, handle_dbput, "Adds/updates database value", usage_dbput },
- { { "exec", NULL }, handle_exec, "Executes a given Application", usage_exec },
- { { "get", "data", NULL }, handle_getdata, "Prompts for DTMF on a channel", usage_getdata },
- { { "get", "full", "variable", NULL }, handle_getvariablefull, "Evaluates a channel expression", usage_getvariablefull },
- { { "get", "option", NULL }, handle_getoption, "Stream file, prompt for DTMF, with timeout", usage_getoption },
- { { "get", "variable", NULL }, handle_getvariable, "Gets a channel variable", usage_getvariable },
- { { "hangup", NULL }, handle_hangup, "Hangup the current channel", usage_hangup },
- { { "noop", NULL }, handle_noop, "Does nothing", usage_noop },
- { { "receive", "char", NULL }, handle_recvchar, "Receives one character from channels supporting it", usage_recvchar },
- { { "receive", "text", NULL }, handle_recvtext, "Receives text from channels supporting it", usage_recvtext },
- { { "record", "file", NULL }, handle_recordfile, "Records to a given file", usage_recordfile },
- { { "say", "alpha", NULL }, handle_sayalpha, "Says a given character string", usage_sayalpha },
- { { "say", "digits", NULL }, handle_saydigits, "Says a given digit string", usage_saydigits },
- { { "say", "number", NULL }, handle_saynumber, "Says a given number", usage_saynumber },
- { { "say", "phonetic", NULL }, handle_sayphonetic, "Says a given character string with phonetics", usage_sayphonetic },
- { { "say", "date", NULL }, handle_saydate, "Says a given date", usage_saydate },
- { { "say", "time", NULL }, handle_saytime, "Says a given time", usage_saytime },
- { { "say", "datetime", NULL }, handle_saydatetime, "Says a given time as specfied by the format given", usage_saydatetime },
- { { "send", "image", NULL }, handle_sendimage, "Sends images to channels supporting it", usage_sendimage },
- { { "send", "text", NULL }, handle_sendtext, "Sends text to channels supporting it", usage_sendtext },
- { { "set", "autohangup", NULL }, handle_autohangup, "Autohangup channel in some time", usage_autohangup },
- { { "set", "callerid", NULL }, handle_setcallerid, "Sets callerid for the current channel", usage_setcallerid },
- { { "set", "context", NULL }, handle_setcontext, "Sets channel context", usage_setcontext },
- { { "set", "extension", NULL }, handle_setextension, "Changes channel extension", usage_setextension },
- { { "set", "music", NULL }, handle_setmusic, "Enable/Disable Music on hold generator", usage_setmusic },
- { { "set", "priority", NULL }, handle_setpriority, "Set channel dialplan priority", usage_setpriority },
- { { "set", "variable", NULL }, handle_setvariable, "Sets a channel variable", usage_setvariable },
- { { "stream", "file", NULL }, handle_streamfile, "Sends audio file on channel", usage_streamfile },
- { { "control", "stream", "file", NULL }, handle_controlstreamfile, "Sends audio file on channel and allows the listner to control the stream", usage_controlstreamfile },
- { { "tdd", "mode", NULL }, handle_tddmode, "Toggles TDD mode (for the deaf)", usage_tddmode },
- { { "verbose", NULL }, handle_verbose, "Logs a message to the asterisk verbose log", usage_verbose },
- { { "wait", "for", "digit", NULL }, handle_waitfordigit, "Waits for a digit to be pressed", usage_waitfordigit },
-};
-
-static void join(char *s, size_t len, char *w[])
-{
- int x;
-
- /* Join words into a string */
- if (!s) {
- return;
- }
- s[0] = '\0';
- for (x=0; w[x]; x++) {
- if (x)
- strncat(s, " ", len - strlen(s) - 1);
- strncat(s, w[x], len - strlen(s) - 1);
- }
-}
-
-static int help_workhorse(int fd, char *match[])
-{
- char fullcmd[80];
- char matchstr[80];
- int x;
- struct agi_command *e;
- if (match)
- join(matchstr, sizeof(matchstr), match);
- for (x=0;x<sizeof(commands)/sizeof(commands[0]);x++) {
- if (!commands[x].cmda[0]) break;
- e = &commands[x];
- if (e)
- join(fullcmd, sizeof(fullcmd), e->cmda);
- /* Hide commands that start with '_' */
- if (fullcmd[0] == '_')
- continue;
- if (match) {
- if (strncasecmp(matchstr, fullcmd, strlen(matchstr))) {
- continue;
- }
- }
- ast_cli(fd, "%20.20s %s\n", fullcmd, e->summary);
- }
- return 0;
-}
-
-int agi_register(agi_command *agi)
-{
- int x;
- for (x=0; x<MAX_COMMANDS - 1; x++) {
- if (commands[x].cmda[0] == agi->cmda[0]) {
- ast_log(LOG_WARNING, "Command already registered!\n");
- return -1;
- }
- }
- for (x=0; x<MAX_COMMANDS - 1; x++) {
- if (!commands[x].cmda[0]) {
- commands[x] = *agi;
- return 0;
- }
- }
- ast_log(LOG_WARNING, "No more room for new commands!\n");
- return -1;
-}
-
-void agi_unregister(agi_command *agi)
-{
- int x;
- for (x=0; x<MAX_COMMANDS - 1; x++) {
- if (commands[x].cmda[0] == agi->cmda[0]) {
- memset(&commands[x], 0, sizeof(agi_command));
- }
- }
-}
-
-static agi_command *find_command(char *cmds[], int exact)
-{
- int x;
- int y;
- int match;
-
- for (x=0; x < sizeof(commands) / sizeof(commands[0]); x++) {
- if (!commands[x].cmda[0])
- break;
- /* start optimistic */
- match = 1;
- for (y=0; match && cmds[y]; y++) {
- /* If there are no more words in the command (and we're looking for
- an exact match) or there is a difference between the two words,
- then this is not a match */
- if (!commands[x].cmda[y] && !exact)
- break;
- /* don't segfault if the next part of a command doesn't exist */
- if (!commands[x].cmda[y])
- return NULL;
- if (strcasecmp(commands[x].cmda[y], cmds[y]))
- match = 0;
- }
- /* If more words are needed to complete the command then this is not
- a candidate (unless we're looking for a really inexact answer */
- if ((exact > -1) && commands[x].cmda[y])
- match = 0;
- if (match)
- return &commands[x];
- }
- return NULL;
-}
-
-
-static int parse_args(char *s, int *max, char *argv[])
-{
- int x=0;
- int quoted=0;
- int escaped=0;
- int whitespace=1;
- char *cur;
-
- cur = s;
- while(*s) {
- switch(*s) {
- case '"':
- /* If it's escaped, put a literal quote */
- if (escaped)
- goto normal;
- else
- quoted = !quoted;
- if (quoted && whitespace) {
- /* If we're starting a quote, coming off white space start a new word, too */
- argv[x++] = cur;
- whitespace=0;
- }
- escaped = 0;
- break;
- case ' ':
- case '\t':
- if (!quoted && !escaped) {
- /* If we're not quoted, mark this as whitespace, and
- end the previous argument */
- whitespace = 1;
- *(cur++) = '\0';
- } else
- /* Otherwise, just treat it as anything else */
- goto normal;
- break;
- case '\\':
- /* If we're escaped, print a literal, otherwise enable escaping */
- if (escaped) {
- goto normal;
- } else {
- escaped=1;
- }
- break;
- default:
-normal:
- if (whitespace) {
- if (x >= MAX_ARGS -1) {
- ast_log(LOG_WARNING, "Too many arguments, truncating\n");
- break;
- }
- /* Coming off of whitespace, start the next argument */
- argv[x++] = cur;
- whitespace=0;
- }
- *(cur++) = *s;
- escaped=0;
- }
- s++;
- }
- /* Null terminate */
- *(cur++) = '\0';
- argv[x] = NULL;
- *max = x;
- return 0;
-}
-
-static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf)
-{
- char *argv[MAX_ARGS];
- int argc = 0;
- int res;
- agi_command *c;
- argc = MAX_ARGS;
-
- parse_args(buf, &argc, argv);
-#if 0
- { int x;
- for (x=0; x<argc; x++)
- fprintf(stderr, "Got Arg%d: %s\n", x, argv[x]); }
-#endif
- c = find_command(argv, 0);
- if (c) {
- res = c->handler(chan, agi, argc, argv);
- switch(res) {
- case RESULT_SHOWUSAGE:
- fdprintf(agi->fd, "520-Invalid command syntax. Proper usage follows:\n");
- fdprintf(agi->fd, c->usage);
- fdprintf(agi->fd, "520 End of proper usage.\n");
- break;
- case AST_PBX_KEEPALIVE:
- /* We've been asked to keep alive, so do so */
- return AST_PBX_KEEPALIVE;
- break;
- case RESULT_FAILURE:
- /* They've already given the failure. We've been hung up on so handle this
- appropriately */
- return -1;
- }
- } else {
- fdprintf(agi->fd, "510 Invalid or unknown command\n");
- }
- return 0;
-}
-#define RETRY 3
-static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int dead)
-{
- struct ast_channel *c;
- int outfd;
- int ms;
- int returnstatus = 0;
- struct ast_frame *f;
- char buf[2048];
- FILE *readf;
- /* how many times we'll retry if ast_waitfor_nandfs will return without either
- channel or file descriptor in case select is interrupted by a system call (EINTR) */
- int retry = RETRY;
-
- if (!(readf = fdopen(agi->ctrl, "r"))) {
- ast_log(LOG_WARNING, "Unable to fdopen file descriptor\n");
- if (pid > -1)
- kill(pid, SIGHUP);
- close(agi->ctrl);
- return -1;
- }
- setlinebuf(readf);
- setup_env(chan, request, agi->fd, (agi->audio > -1));
- for (;;) {
- ms = -1;
- c = ast_waitfor_nandfds(&chan, dead ? 0 : 1, &agi->ctrl, 1, NULL, &outfd, &ms);
- if (c) {
- retry = RETRY;
- /* Idle the channel until we get a command */
- f = ast_read(c);
- if (!f) {
- ast_log(LOG_DEBUG, "%s hungup\n", chan->name);
- returnstatus = -1;
- break;
- } else {
- /* If it's voice, write it to the audio pipe */
- if ((agi->audio > -1) && (f->frametype == AST_FRAME_VOICE)) {
- /* Write, ignoring errors */
- write(agi->audio, f->data, f->datalen);
- }
- ast_frfree(f);
- }
- } else if (outfd > -1) {
- retry = RETRY;
- if (!fgets(buf, sizeof(buf), readf)) {
- /* Program terminated */
- if (returnstatus)
- returnstatus = -1;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "AGI Script %s completed, returning %d\n", request, returnstatus);
- /* No need to kill the pid anymore, since they closed us */
- pid = -1;
- break;
- }
- /* get rid of trailing newline, if any */
- if (*buf && buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = 0;
- if (agidebug)
- ast_verbose("AGI Rx << %s\n", buf);
- returnstatus |= agi_handle_command(chan, agi, buf);
- /* If the handle_command returns -1, we need to stop */
- if ((returnstatus < 0) || (returnstatus == AST_PBX_KEEPALIVE)) {
- break;
- }
- } else {
- if (--retry <= 0) {
- ast_log(LOG_WARNING, "No channel, no fd?\n");
- returnstatus = -1;
- break;
- }
- }
- }
- /* Notify process */
- if (pid > -1) {
- if (kill(pid, SIGHUP))
- ast_log(LOG_WARNING, "unable to send SIGHUP to AGI process %d: %s\n", pid, strerror(errno));
- }
- fclose(readf);
- return returnstatus;
-}
-
-static int handle_showagi(int fd, int argc, char *argv[]) {
- struct agi_command *e;
- char fullcmd[80];
- if ((argc < 2))
- return RESULT_SHOWUSAGE;
- if (argc > 2) {
- e = find_command(argv + 2, 1);
- if (e)
- ast_cli(fd, e->usage);
- else {
- if (find_command(argv + 2, -1)) {
- return help_workhorse(fd, argv + 1);
- } else {
- join(fullcmd, sizeof(fullcmd), argv+1);
- ast_cli(fd, "No such command '%s'.\n", fullcmd);
- }
- }
- } else {
- return help_workhorse(fd, NULL);
- }
- return RESULT_SUCCESS;
-}
-
-static int handle_dumpagihtml(int fd, int argc, char *argv[]) {
- struct agi_command *e;
- char fullcmd[80];
- char *tempstr;
- int x;
- FILE *htmlfile;
-
- if ((argc < 3))
- return RESULT_SHOWUSAGE;
-
- if (!(htmlfile = fopen(argv[2], "wt"))) {
- ast_cli(fd, "Could not create file '%s'\n", argv[2]);
- return RESULT_SHOWUSAGE;
- }
-
- fprintf(htmlfile, "<HTML>\n<HEAD>\n<TITLE>AGI Commands</TITLE>\n</HEAD>\n");
- fprintf(htmlfile, "<BODY>\n<CENTER><B><H1>AGI Commands</H1></B></CENTER>\n\n");
-
-
- fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n");
-
- for (x=0;x<sizeof(commands)/sizeof(commands[0]);x++) {
- char *stringp=NULL;
- if (!commands[x].cmda[0]) break;
- e = &commands[x];
- if (e)
- join(fullcmd, sizeof(fullcmd), e->cmda);
- /* Hide commands that start with '_' */
- if (fullcmd[0] == '_')
- continue;
-
- fprintf(htmlfile, "<TR><TD><TABLE BORDER=\"1\" CELLPADDING=\"5\" WIDTH=\"100%%\">\n");
- fprintf(htmlfile, "<TR><TH ALIGN=\"CENTER\"><B>%s - %s</B></TD></TR>\n", fullcmd,e->summary);
-
-
- stringp=e->usage;
- tempstr = strsep(&stringp, "\n");
-
- fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">%s</TD></TR>\n", tempstr);
-
- fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">\n");
- while ((tempstr = strsep(&stringp, "\n")) != NULL) {
- fprintf(htmlfile, "%s<BR>\n",tempstr);
-
- }
- fprintf(htmlfile, "</TD></TR>\n");
- fprintf(htmlfile, "</TABLE></TD></TR>\n\n");
-
- }
-
- fprintf(htmlfile, "</TABLE>\n</BODY>\n</HTML>\n");
- fclose(htmlfile);
- ast_cli(fd, "AGI HTML Commands Dumped to: %s\n", argv[2]);
- return RESULT_SUCCESS;
-}
-
-static int agi_exec_full(struct ast_channel *chan, void *data, int enhanced, int dead)
-{
- int res=0;
- struct localuser *u;
- char *argv[MAX_ARGS];
- char buf[2048]="";
- char *tmp = (char *)buf;
- int argc = 0;
- int fds[2];
- int efd = -1;
- int pid;
- char *stringp;
- AGI agi;
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "AGI requires an argument (script)\n");
- return -1;
- }
- ast_copy_string(buf, data, sizeof(buf));
-
- memset(&agi, 0, sizeof(agi));
- while ((stringp = strsep(&tmp, "|")) && argc < MAX_ARGS - 1)
- argv[argc++] = stringp;
- argv[argc] = NULL;
-
- LOCAL_USER_ADD(u);
-#if 0
- /* Answer if need be */
- if (chan->_state != AST_STATE_UP) {
- if (ast_answer(chan)) {
- LOCAL_USER_REMOVE(u);
- return -1;
- }
- }
-#endif
- res = launch_script(argv[0], argv, fds, enhanced ? &efd : NULL, &pid);
- if (!res) {
- agi.fd = fds[1];
- agi.ctrl = fds[0];
- agi.audio = efd;
- res = run_agi(chan, argv[0], &agi, pid, dead);
- close(fds[1]);
- if (efd > -1)
- close(efd);
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int agi_exec(struct ast_channel *chan, void *data)
-{
- if (chan->_softhangup)
- ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n");
- return agi_exec_full(chan, data, 0, 0);
-}
-
-static int eagi_exec(struct ast_channel *chan, void *data)
-{
- int readformat;
- int res;
-
- if (chan->_softhangup)
- ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n");
- readformat = chan->readformat;
- if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
- ast_log(LOG_WARNING, "Unable to set channel '%s' to linear mode\n", chan->name);
- return -1;
- }
- res = agi_exec_full(chan, data, 1, 0);
- if (!res) {
- if (ast_set_read_format(chan, readformat)) {
- ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", chan->name, ast_getformatname(readformat));
- }
- }
- return res;
-}
-
-static int deadagi_exec(struct ast_channel *chan, void *data)
-{
- return agi_exec_full(chan, data, 0, 1);
-}
-
-static char showagi_help[] =
-"Usage: show agi [topic]\n"
-" When called with a topic as an argument, displays usage\n"
-" information on the given command. If called without a\n"
-" topic, it provides a list of AGI commands.\n";
-
-
-static char dumpagihtml_help[] =
-"Usage: dump agihtml <filename>\n"
-" Dumps the agi command list in html format to given filename\n";
-
-static struct ast_cli_entry showagi =
-{ { "show", "agi", NULL }, handle_showagi, "Show AGI commands or specific help", showagi_help };
-
-static struct ast_cli_entry dumpagihtml =
-{ { "dump", "agihtml", NULL }, handle_dumpagihtml, "Dumps a list of agi command in html format", dumpagihtml_help };
-
-int unload_module(void)
-{
- STANDARD_HANGUP_LOCALUSERS;
- ast_cli_unregister(&showagi);
- ast_cli_unregister(&dumpagihtml);
- ast_cli_unregister(&cli_debug);
- ast_cli_unregister(&cli_no_debug);
- ast_unregister_application(eapp);
- ast_unregister_application(deadapp);
- return ast_unregister_application(app);
-}
-
-int load_module(void)
-{
- ast_cli_register(&showagi);
- ast_cli_register(&dumpagihtml);
- ast_cli_register(&cli_debug);
- ast_cli_register(&cli_no_debug);
- ast_register_application(deadapp, deadagi_exec, deadsynopsis, descrip);
- ast_register_application(eapp, eagi_exec, esynopsis, descrip);
- return ast_register_application(app, agi_exec, synopsis, descrip);
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/1.2-netsec/res/res_config_odbc.c b/1.2-netsec/res/res_config_odbc.c
deleted file mode 100644
index e10f4ff7f..000000000
--- a/1.2-netsec/res/res_config_odbc.c
+++ /dev/null
@@ -1,540 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Copyright (C) 2004 - 2005 Anthony Minessale II <anthmct@yahoo.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief odbc+odbc plugin for portable configuration engine
- *
- * http://www.unixodbc.org
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/options.h"
-#include "asterisk/res_odbc.h"
-#include "asterisk/utils.h"
-
-static char *tdesc = "ODBC Configuration";
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-static struct ast_variable *realtime_odbc(const char *database, const char *table, va_list ap)
-{
- odbc_obj *obj;
- SQLHSTMT stmt;
- char sql[1024];
- char coltitle[256];
- char rowdata[2048];
- char *op;
- const char *newparam, *newval;
- char *stringp;
- char *chunk;
- SQLSMALLINT collen;
- int res;
- int x;
- struct ast_variable *var=NULL, *prev=NULL;
- SQLULEN colsize;
- SQLSMALLINT colcount=0;
- SQLSMALLINT datatype;
- SQLSMALLINT decimaldigits;
- SQLSMALLINT nullable;
- SQLINTEGER indicator;
- va_list aq;
-
- va_copy(aq, ap);
-
-
- if (!table)
- return NULL;
-
- obj = fetch_odbc_obj(database, 0);
- if (!obj)
- return NULL;
-
- res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- return NULL;
- }
-
- newparam = va_arg(aq, const char *);
- if (!newparam) {
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
- newval = va_arg(aq, const char *);
- if (!strchr(newparam, ' ')) op = " ="; else op = "";
- snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s ?", table, newparam, op);
- while((newparam = va_arg(aq, const char *))) {
- if (!strchr(newparam, ' ')) op = " ="; else op = "";
- snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s ?", newparam, op);
- newval = va_arg(aq, const char *);
- }
- va_end(aq);
- res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
-
- /* Now bind the parameters */
- x = 1;
-
- while((newparam = va_arg(ap, const char *))) {
- newval = va_arg(ap, const char *);
- SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(newval), 0, (void *)newval, 0, NULL);
- }
-
- res = odbc_smart_execute(obj, stmt);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
-
- res = SQLNumResultCols(stmt, &colcount);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
-
- res = SQLFetch(stmt);
- if (res == SQL_NO_DATA) {
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
- for (x=0;x<colcount;x++) {
- rowdata[0] = '\0';
- collen = sizeof(coltitle);
- res = SQLDescribeCol(stmt, x + 1, (unsigned char *)coltitle, sizeof(coltitle), &collen,
- &datatype, &colsize, &decimaldigits, &nullable);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
- if (var)
- ast_variables_destroy(var);
- return NULL;
- }
-
- indicator = 0;
- res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), &indicator);
- if (indicator == SQL_NULL_DATA)
- continue;
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- if (var)
- ast_variables_destroy(var);
- return NULL;
- }
- stringp = rowdata;
- while(stringp) {
- chunk = strsep(&stringp, ";");
- if (!ast_strlen_zero(ast_strip(chunk))) {
- if (prev) {
- prev->next = ast_variable_new(coltitle, chunk);
- if (prev->next)
- prev = prev->next;
- } else
- prev = var = ast_variable_new(coltitle, chunk);
-
- }
- }
- }
-
-
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return var;
-}
-
-static struct ast_config *realtime_multi_odbc(const char *database, const char *table, va_list ap)
-{
- odbc_obj *obj;
- SQLHSTMT stmt;
- char sql[1024];
- char coltitle[256];
- char rowdata[2048];
- const char *initfield=NULL;
- char *op;
- const char *newparam, *newval;
- char *stringp;
- char *chunk;
- SQLSMALLINT collen;
- int res;
- int x;
- struct ast_variable *var=NULL;
- struct ast_config *cfg=NULL;
- struct ast_category *cat=NULL;
- struct ast_realloca ra;
- SQLULEN colsize;
- SQLSMALLINT colcount=0;
- SQLSMALLINT datatype;
- SQLSMALLINT decimaldigits;
- SQLSMALLINT nullable;
- SQLINTEGER indicator;
-
- va_list aq;
- va_copy(aq, ap);
-
-
- if (!table)
- return NULL;
- memset(&ra, 0, sizeof(ra));
-
- obj = fetch_odbc_obj(database, 0);
- if (!obj)
- return NULL;
-
- res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- return NULL;
- }
-
- newparam = va_arg(aq, const char *);
- if (!newparam) {
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
- initfield = ast_strdupa(newparam);
- if (initfield && (op = strchr(initfield, ' ')))
- *op = '\0';
- newval = va_arg(aq, const char *);
- if (!strchr(newparam, ' ')) op = " ="; else op = "";
- snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s ?", table, newparam, op);
- while((newparam = va_arg(aq, const char *))) {
- if (!strchr(newparam, ' ')) op = " ="; else op = "";
- snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s ?", newparam, op);
- newval = va_arg(aq, const char *);
- }
- if (initfield)
- snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " ORDER BY %s", initfield);
- va_end(aq);
- res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
-
- /* Now bind the parameters */
- x = 1;
-
- while((newparam = va_arg(ap, const char *))) {
- newval = va_arg(ap, const char *);
- SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(newval), 0, (void *)newval, 0, NULL);
- }
-
- res = odbc_smart_execute(obj, stmt);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
-
- res = SQLNumResultCols(stmt, &colcount);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
-
- cfg = ast_config_new();
- if (!cfg) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
-
- while ((res=SQLFetch(stmt)) != SQL_NO_DATA) {
- var = NULL;
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
- continue;
- }
- cat = ast_category_new("");
- if (!cat) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- continue;
- }
- for (x=0;x<colcount;x++) {
- rowdata[0] = '\0';
- collen = sizeof(coltitle);
- res = SQLDescribeCol(stmt, x + 1, (unsigned char *)coltitle, sizeof(coltitle), &collen,
- &datatype, &colsize, &decimaldigits, &nullable);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
- ast_category_destroy(cat);
- continue;
- }
-
- indicator = 0;
- res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), &indicator);
- if (indicator == SQL_NULL_DATA)
- continue;
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- ast_category_destroy(cat);
- continue;
- }
- stringp = rowdata;
- while(stringp) {
- chunk = strsep(&stringp, ";");
- if (!ast_strlen_zero(ast_strip(chunk))) {
- if (initfield && !strcmp(initfield, coltitle))
- ast_category_rename(cat, chunk);
- var = ast_variable_new(coltitle, chunk);
- ast_variable_append(cat, var);
- }
- }
- }
- ast_category_append(cfg, cat);
- }
-
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return cfg;
-}
-
-static int update_odbc(const char *database, const char *table, const char *keyfield, const char *lookup, va_list ap)
-{
- odbc_obj *obj;
- SQLHSTMT stmt;
- char sql[256];
- SQLLEN rowcount=0;
- const char *newparam, *newval;
- int res;
- int x;
- va_list aq;
-
- va_copy(aq, ap);
-
- if (!table)
- return -1;
-
- obj = fetch_odbc_obj (database, 0);
- if (!obj)
- return -1;
-
- res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- return -1;
- }
-
- newparam = va_arg(aq, const char *);
- if (!newparam) {
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return -1;
- }
- newval = va_arg(aq, const char *);
- snprintf(sql, sizeof(sql), "UPDATE %s SET %s=?", table, newparam);
- while((newparam = va_arg(aq, const char *))) {
- snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), ", %s=?", newparam);
- newval = va_arg(aq, const char *);
- }
- va_end(aq);
- snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " WHERE %s=?", keyfield);
-
- res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return -1;
- }
-
- /* Now bind the parameters */
- x = 1;
-
- while((newparam = va_arg(ap, const char *))) {
- newval = va_arg(ap, const char *);
- SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(newval), 0, (void *)newval, 0, NULL);
- }
-
- SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(lookup), 0, (void *)lookup, 0, NULL);
-
- res = odbc_smart_execute(obj, stmt);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return -1;
- }
-
- res = SQLRowCount(stmt, &rowcount);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
- return -1;
- }
-
- if (rowcount >= 0)
- return (int)rowcount;
-
- return -1;
-}
-
-static struct ast_config *config_odbc(const char *database, const char *table, const char *file, struct ast_config *cfg)
-{
- struct ast_variable *new_v;
- struct ast_category *cur_cat;
- int res = 0;
- odbc_obj *obj;
- SQLINTEGER err=0, commented=0, cat_metric=0, var_metric=0, last_cat_metric=0;
- SQLBIGINT id;
- char sql[255] = "", filename[128], category[128], var_name[128], var_val[512];
- SQLSMALLINT rowcount=0;
- SQLHSTMT stmt;
- char last[128] = "";
-
- if (!file || !strcmp (file, "res_config_odbc.conf"))
- return NULL; /* cant configure myself with myself ! */
-
- obj = fetch_odbc_obj(database, 0);
- if (!obj)
- return NULL;
-
- res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
-
- SQLBindCol (stmt, 1, SQL_C_ULONG, &id, sizeof (id), &err);
- SQLBindCol (stmt, 2, SQL_C_ULONG, &cat_metric, sizeof (cat_metric), &err);
- SQLBindCol (stmt, 3, SQL_C_ULONG, &var_metric, sizeof (var_metric), &err);
- SQLBindCol (stmt, 4, SQL_C_ULONG, &commented, sizeof (commented), &err);
- SQLBindCol (stmt, 5, SQL_C_CHAR, &filename, sizeof (filename), &err);
- SQLBindCol (stmt, 6, SQL_C_CHAR, &category, sizeof (category), &err);
- SQLBindCol (stmt, 7, SQL_C_CHAR, &var_name, sizeof (var_name), &err);
- SQLBindCol (stmt, 8, SQL_C_CHAR, &var_val, sizeof (var_val), &err);
-
- snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE filename='%s' and commented=0 ORDER BY filename,cat_metric desc,var_metric asc,category,var_name,var_val,id", table, file);
-
- res = odbc_smart_direct_execute(obj, stmt, sql);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log (LOG_WARNING, "SQL select error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
-
- res = SQLNumResultCols (stmt, &rowcount);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log (LOG_WARNING, "SQL NumResultCols error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
-
- if (!rowcount) {
- ast_log (LOG_NOTICE, "found nothing\n");
- return cfg;
- }
-
- cur_cat = ast_config_get_current_category(cfg);
-
- while ((res = SQLFetch(stmt)) != SQL_NO_DATA) {
- if (!strcmp (var_name, "#include")) {
- if (!ast_config_internal_load(var_val, cfg)) {
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return NULL;
- }
- continue;
- }
- if (strcmp(last, category) || last_cat_metric != cat_metric) {
- cur_cat = ast_category_new(category);
- if (!cur_cat) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- break;
- }
- strcpy(last, category);
- last_cat_metric = cat_metric;
- ast_category_append(cfg, cur_cat);
- }
-
- new_v = ast_variable_new(var_name, var_val);
- ast_variable_append(cur_cat, new_v);
- }
-
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- return cfg;
-}
-
-static struct ast_config_engine odbc_engine = {
- .name = "odbc",
- .load_func = config_odbc,
- .realtime_func = realtime_odbc,
- .realtime_multi_func = realtime_multi_odbc,
- .update_func = update_odbc
-};
-
-int unload_module (void)
-{
- ast_config_engine_deregister(&odbc_engine);
- if (option_verbose)
- ast_verbose("res_config_odbc unloaded.\n");
- STANDARD_HANGUP_LOCALUSERS;
- return 0;
-}
-
-int load_module (void)
-{
- ast_config_engine_register(&odbc_engine);
- if (option_verbose)
- ast_verbose("res_config_odbc loaded.\n");
- return 0;
-}
-
-char *description (void)
-{
- return tdesc;
-}
-
-int usecount (void)
-{
- /* never unload a config module */
- return 1;
-}
-
-char *key ()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/res/res_crypto.c b/1.2-netsec/res/res_crypto.c
deleted file mode 100644
index 037ff8e79..000000000
--- a/1.2-netsec/res/res_crypto.c
+++ /dev/null
@@ -1,622 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Provide Cryptographic Signature capability
- *
- */
-
-#include <sys/types.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/say.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/crypto.h"
-#include "asterisk/md5.h"
-#include "asterisk/cli.h"
-#include "asterisk/io.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-
-/*
- * Asterisk uses RSA keys with SHA-1 message digests for its
- * digital signatures. The choice of RSA is due to its higher
- * throughput on verification, and the choice of SHA-1 based
- * on the recently discovered collisions in MD5's compression
- * algorithm and recommendations of avoiding MD5 in new schemes
- * from various industry experts.
- *
- * We use OpenSSL to provide our crypto routines, although we never
- * actually use full-up SSL
- *
- */
-
-/*
- * XXX This module is not very thread-safe. It is for everyday stuff
- * like reading keys and stuff, but there are all kinds of weird
- * races with people running reload and key init at the same time
- * for example
- *
- * XXXX
- */
-
-AST_MUTEX_DEFINE_STATIC(keylock);
-
-#define KEY_NEEDS_PASSCODE (1 << 16)
-
-struct ast_key {
- /* Name of entity */
- char name[80];
- /* File name */
- char fn[256];
- /* Key type (AST_KEY_PUB or AST_KEY_PRIV, along with flags from above) */
- int ktype;
- /* RSA structure (if successfully loaded) */
- RSA *rsa;
- /* Whether we should be deleted */
- int delme;
- /* FD for input (or -1 if no input allowed, or -2 if we needed input) */
- int infd;
- /* FD for output */
- int outfd;
- /* Last MD5 Digest */
- unsigned char digest[16];
- struct ast_key *next;
-};
-
-static struct ast_key *keys = NULL;
-
-
-#if 0
-static int fdprint(int fd, char *s)
-{
- return write(fd, s, strlen(s) + 1);
-}
-#endif
-static int pw_cb(char *buf, int size, int rwflag, void *userdata)
-{
- struct ast_key *key = (struct ast_key *)userdata;
- char prompt[256];
- int res;
- int tmp;
- if (key->infd > -1) {
- snprintf(prompt, sizeof(prompt), ">>>> passcode for %s key '%s': ",
- key->ktype == AST_KEY_PRIVATE ? "PRIVATE" : "PUBLIC", key->name);
- write(key->outfd, prompt, strlen(prompt));
- memset(buf, 0, sizeof(buf));
- tmp = ast_hide_password(key->infd);
- memset(buf, 0, size);
- res = read(key->infd, buf, size);
- ast_restore_tty(key->infd, tmp);
- if (buf[strlen(buf) -1] == '\n')
- buf[strlen(buf) - 1] = '\0';
- return strlen(buf);
- } else {
- /* Note that we were at least called */
- key->infd = -2;
- }
- return -1;
-}
-
-static struct ast_key *__ast_key_get(const char *kname, int ktype)
-{
- struct ast_key *key;
- ast_mutex_lock(&keylock);
- key = keys;
- while(key) {
- if (!strcmp(kname, key->name) &&
- (ktype == key->ktype))
- break;
- key = key->next;
- }
- ast_mutex_unlock(&keylock);
- return key;
-}
-
-static struct ast_key *try_load_key (char *dir, char *fname, int ifd, int ofd, int *not2)
-{
- int ktype = 0;
- char *c = NULL;
- char ffname[256];
- unsigned char digest[16];
- FILE *f;
- struct MD5Context md5;
- struct ast_key *key;
- static int notice = 0;
- int found = 0;
-
- /* Make sure its name is a public or private key */
-
- if ((c = strstr(fname, ".pub")) && !strcmp(c, ".pub")) {
- ktype = AST_KEY_PUBLIC;
- } else if ((c = strstr(fname, ".key")) && !strcmp(c, ".key")) {
- ktype = AST_KEY_PRIVATE;
- } else
- return NULL;
-
- /* Get actual filename */
- snprintf(ffname, sizeof(ffname), "%s/%s", dir, fname);
-
- ast_mutex_lock(&keylock);
- key = keys;
- while(key) {
- /* Look for an existing version already */
- if (!strcasecmp(key->fn, ffname))
- break;
- key = key->next;
- }
- ast_mutex_unlock(&keylock);
-
- /* Open file */
- f = fopen(ffname, "r");
- if (!f) {
- ast_log(LOG_WARNING, "Unable to open key file %s: %s\n", ffname, strerror(errno));
- return NULL;
- }
- MD5Init(&md5);
- while(!feof(f)) {
- /* Calculate a "whatever" quality md5sum of the key */
- char buf[256];
- memset(buf, 0, 256);
- fgets(buf, sizeof(buf), f);
- if (!feof(f)) {
- MD5Update(&md5, (unsigned char *) buf, strlen(buf));
- }
- }
- MD5Final(digest, &md5);
- if (key) {
- /* If the MD5 sum is the same, and it isn't awaiting a passcode
- then this is far enough */
- if (!memcmp(digest, key->digest, 16) &&
- !(key->ktype & KEY_NEEDS_PASSCODE)) {
- fclose(f);
- key->delme = 0;
- return NULL;
- } else {
- /* Preserve keytype */
- ktype = key->ktype;
- /* Recycle the same structure */
- found++;
- }
- }
-
- /* Make fname just be the normal name now */
- *c = '\0';
- if (!key) {
- key = (struct ast_key *)malloc(sizeof(struct ast_key));
- if (!key) {
- ast_log(LOG_WARNING, "Out of memory\n");
- fclose(f);
- return NULL;
- }
- memset(key, 0, sizeof(struct ast_key));
- }
- /* At this point we have a key structure (old or new). Time to
- fill it with what we know */
- /* Gotta lock if this one already exists */
- if (found)
- ast_mutex_lock(&keylock);
- /* First the filename */
- ast_copy_string(key->fn, ffname, sizeof(key->fn));
- /* Then the name */
- ast_copy_string(key->name, fname, sizeof(key->name));
- key->ktype = ktype;
- /* Yes, assume we're going to be deleted */
- key->delme = 1;
- /* Keep the key type */
- memcpy(key->digest, digest, 16);
- /* Can I/O takes the FD we're given */
- key->infd = ifd;
- key->outfd = ofd;
- /* Reset the file back to the beginning */
- rewind(f);
- /* Now load the key with the right method */
- if (ktype == AST_KEY_PUBLIC)
- key->rsa = PEM_read_RSA_PUBKEY(f, NULL, pw_cb, key);
- else
- key->rsa = PEM_read_RSAPrivateKey(f, NULL, pw_cb, key);
- fclose(f);
- if (key->rsa) {
- if (RSA_size(key->rsa) == 128) {
- /* Key loaded okay */
- key->ktype &= ~KEY_NEEDS_PASSCODE;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Loaded %s key '%s'\n", key->ktype == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->name);
- if (option_debug)
- ast_log(LOG_DEBUG, "Key '%s' loaded OK\n", key->name);
- key->delme = 0;
- } else
- ast_log(LOG_NOTICE, "Key '%s' is not expected size.\n", key->name);
- } else if (key->infd != -2) {
- ast_log(LOG_WARNING, "Key load %s '%s' failed\n",key->ktype == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->name);
- if (ofd > -1) {
- ERR_print_errors_fp(stderr);
- } else
- ERR_print_errors_fp(stderr);
- } else {
- ast_log(LOG_NOTICE, "Key '%s' needs passcode.\n", key->name);
- key->ktype |= KEY_NEEDS_PASSCODE;
- if (!notice) {
- if (!option_initcrypto)
- ast_log(LOG_NOTICE, "Add the '-i' flag to the asterisk command line if you want to automatically initialize passcodes at launch.\n");
- notice++;
- }
- /* Keep it anyway */
- key->delme = 0;
- /* Print final notice about "init keys" when done */
- *not2 = 1;
- }
- if (found)
- ast_mutex_unlock(&keylock);
- if (!found) {
- ast_mutex_lock(&keylock);
- key->next = keys;
- keys = key;
- ast_mutex_unlock(&keylock);
- }
- return key;
-}
-
-#if 0
-
-static void dump(unsigned char *src, int len)
-{
- int x;
- for (x=0;x<len;x++)
- printf("%02x", *(src++));
- printf("\n");
-}
-
-static char *binary(int y, int len)
-{
- static char res[80];
- int x;
- memset(res, 0, sizeof(res));
- for (x=0;x<len;x++) {
- if (y & (1 << x))
- res[(len - x - 1)] = '1';
- else
- res[(len - x - 1)] = '0';
- }
- return res;
-}
-
-#endif
-
-static int __ast_sign_bin(struct ast_key *key, const char *msg, int msglen, unsigned char *dsig)
-{
- unsigned char digest[20];
- unsigned int siglen = 128;
- int res;
-
- if (key->ktype != AST_KEY_PRIVATE) {
- ast_log(LOG_WARNING, "Cannot sign with a public key\n");
- return -1;
- }
-
- /* Calculate digest of message */
- SHA1((unsigned char *)msg, msglen, digest);
-
- /* Verify signature */
- res = RSA_sign(NID_sha1, digest, sizeof(digest), dsig, &siglen, key->rsa);
-
- if (!res) {
- ast_log(LOG_WARNING, "RSA Signature (key %s) failed\n", key->name);
- return -1;
- }
-
- if (siglen != 128) {
- ast_log(LOG_WARNING, "Unexpected signature length %d, expecting %d\n", (int)siglen, (int)128);
- return -1;
- }
-
- return 0;
-
-}
-
-static int __ast_decrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key)
-{
- int res;
- int pos = 0;
- if (key->ktype != AST_KEY_PRIVATE) {
- ast_log(LOG_WARNING, "Cannot decrypt with a public key\n");
- return -1;
- }
-
- if (srclen % 128) {
- ast_log(LOG_NOTICE, "Tried to decrypt something not a multiple of 128 bytes\n");
- return -1;
- }
- while(srclen) {
- /* Process chunks 128 bytes at a time */
- res = RSA_private_decrypt(128, src, dst, key->rsa, RSA_PKCS1_OAEP_PADDING);
- if (res < 0)
- return -1;
- pos += res;
- src += 128;
- srclen -= 128;
- dst += res;
- }
- return pos;
-}
-
-static int __ast_encrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key)
-{
- int res;
- int bytes;
- int pos = 0;
- if (key->ktype != AST_KEY_PUBLIC) {
- ast_log(LOG_WARNING, "Cannot encrypt with a private key\n");
- return -1;
- }
-
- while(srclen) {
- bytes = srclen;
- if (bytes > 128 - 41)
- bytes = 128 - 41;
- /* Process chunks 128-41 bytes at a time */
- res = RSA_public_encrypt(bytes, src, dst, key->rsa, RSA_PKCS1_OAEP_PADDING);
- if (res != 128) {
- ast_log(LOG_NOTICE, "How odd, encrypted size is %d\n", res);
- return -1;
- }
- src += bytes;
- srclen -= bytes;
- pos += res;
- dst += res;
- }
- return pos;
-}
-
-static int __ast_sign(struct ast_key *key, char *msg, char *sig)
-{
- unsigned char dsig[128];
- int siglen = sizeof(dsig);
- int res;
- res = ast_sign_bin(key, msg, strlen(msg), dsig);
- if (!res)
- /* Success -- encode (256 bytes max as documented) */
- ast_base64encode(sig, dsig, siglen, 256);
- return res;
-
-}
-
-static int __ast_check_signature_bin(struct ast_key *key, const char *msg, int msglen, const unsigned char *dsig)
-{
- unsigned char digest[20];
- int res;
-
- if (key->ktype != AST_KEY_PUBLIC) {
- /* Okay, so of course you really *can* but for our purposes
- we're going to say you can't */
- ast_log(LOG_WARNING, "Cannot check message signature with a private key\n");
- return -1;
- }
-
- /* Calculate digest of message */
- SHA1((unsigned char *)msg, msglen, digest);
-
- /* Verify signature */
- res = RSA_verify(NID_sha1, digest, sizeof(digest), (unsigned char *)dsig, 128, key->rsa);
-
- if (!res) {
- ast_log(LOG_DEBUG, "Key failed verification: %s\n", key->name);
- return -1;
- }
- /* Pass */
- return 0;
-}
-
-static int __ast_check_signature(struct ast_key *key, const char *msg, const char *sig)
-{
- unsigned char dsig[128];
- int res;
-
- /* Decode signature */
- res = ast_base64decode(dsig, sig, sizeof(dsig));
- if (res != sizeof(dsig)) {
- ast_log(LOG_WARNING, "Signature improper length (expect %d, got %d)\n", (int)sizeof(dsig), (int)res);
- return -1;
- }
- res = ast_check_signature_bin(key, msg, strlen(msg), dsig);
- return res;
-}
-
-static void crypto_load(int ifd, int ofd)
-{
- struct ast_key *key, *nkey, *last;
- DIR *dir = NULL;
- struct dirent *ent;
- int note = 0;
- /* Mark all keys for deletion */
- ast_mutex_lock(&keylock);
- key = keys;
- while(key) {
- key->delme = 1;
- key = key->next;
- }
- ast_mutex_unlock(&keylock);
- /* Load new keys */
- dir = opendir((char *)ast_config_AST_KEY_DIR);
- if (dir) {
- while((ent = readdir(dir))) {
- try_load_key((char *)ast_config_AST_KEY_DIR, ent->d_name, ifd, ofd, &note);
- }
- closedir(dir);
- } else
- ast_log(LOG_WARNING, "Unable to open key directory '%s'\n", (char *)ast_config_AST_KEY_DIR);
- if (note) {
- ast_log(LOG_NOTICE, "Please run the command 'init keys' to enter the passcodes for the keys\n");
- }
- ast_mutex_lock(&keylock);
- key = keys;
- last = NULL;
- while(key) {
- nkey = key->next;
- if (key->delme) {
- ast_log(LOG_DEBUG, "Deleting key %s type %d\n", key->name, key->ktype);
- /* Do the delete */
- if (last)
- last->next = nkey;
- else
- keys = nkey;
- if (key->rsa)
- RSA_free(key->rsa);
- free(key);
- } else
- last = key;
- key = nkey;
- }
- ast_mutex_unlock(&keylock);
-}
-
-static void md52sum(char *sum, unsigned char *md5)
-{
- int x;
- for (x=0;x<16;x++)
- sum += sprintf(sum, "%02x", *(md5++));
-}
-
-static int show_keys(int fd, int argc, char *argv[])
-{
- struct ast_key *key;
- char sum[16 * 2 + 1];
- int count_keys = 0;
-
- ast_mutex_lock(&keylock);
- key = keys;
- ast_cli(fd, "%-18s %-8s %-16s %-33s\n", "Key Name", "Type", "Status", "Sum");
- while(key) {
- md52sum(sum, key->digest);
- ast_cli(fd, "%-18s %-8s %-16s %-33s\n", key->name,
- (key->ktype & 0xf) == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE",
- key->ktype & KEY_NEEDS_PASSCODE ? "[Needs Passcode]" : "[Loaded]", sum);
-
- key = key->next;
- count_keys++;
- }
- ast_mutex_unlock(&keylock);
- ast_cli(fd, "%d known RSA keys.\n", count_keys);
- return RESULT_SUCCESS;
-}
-
-static int init_keys(int fd, int argc, char *argv[])
-{
- struct ast_key *key;
- int ign;
- char *kn;
- char tmp[256] = "";
-
- key = keys;
- while(key) {
- /* Reload keys that need pass codes now */
- if (key->ktype & KEY_NEEDS_PASSCODE) {
- kn = key->fn + strlen(ast_config_AST_KEY_DIR) + 1;
- ast_copy_string(tmp, kn, sizeof(tmp));
- try_load_key((char *)ast_config_AST_KEY_DIR, tmp, fd, fd, &ign);
- }
- key = key->next;
- }
- return RESULT_SUCCESS;
-}
-
-static char show_key_usage[] =
-"Usage: show keys\n"
-" Displays information about RSA keys known by Asterisk\n";
-
-static char init_keys_usage[] =
-"Usage: init keys\n"
-" Initializes private keys (by reading in pass code from the user)\n";
-
-static struct ast_cli_entry cli_show_keys =
-{ { "show", "keys", NULL }, show_keys, "Displays RSA key information", show_key_usage };
-
-static struct ast_cli_entry cli_init_keys =
-{ { "init", "keys", NULL }, init_keys, "Initialize RSA key passcodes", init_keys_usage };
-
-static int crypto_init(void)
-{
- SSL_library_init();
- ERR_load_crypto_strings();
- ast_cli_register(&cli_show_keys);
- ast_cli_register(&cli_init_keys);
-
- /* Install ourselves into stubs */
- ast_key_get = __ast_key_get;
- ast_check_signature = __ast_check_signature;
- ast_check_signature_bin = __ast_check_signature_bin;
- ast_sign = __ast_sign;
- ast_sign_bin = __ast_sign_bin;
- ast_encrypt_bin = __ast_encrypt_bin;
- ast_decrypt_bin = __ast_decrypt_bin;
- return 0;
-}
-
-int reload(void)
-{
- crypto_load(-1, -1);
- return 0;
-}
-
-int load_module(void)
-{
- crypto_init();
- if (option_initcrypto)
- crypto_load(STDIN_FILENO, STDOUT_FILENO);
- else
- crypto_load(-1, -1);
- return 0;
-}
-
-int unload_module(void)
-{
- /* Can't unload this once we're loaded */
- return -1;
-}
-
-char *description(void)
-{
- return "Cryptographic Digital Signatures";
-}
-
-int usecount(void)
-{
- /* We should never be unloaded */
- return 1;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/res/res_features.c b/1.2-netsec/res/res_features.c
deleted file mode 100644
index bf23129ae..000000000
--- a/1.2-netsec/res/res_features.c
+++ /dev/null
@@ -1,2187 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2006, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Routines implementing call parking
- *
- */
-
-#include <pthread.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/signal.h>
-#include <netinet/in.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/causes.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/app.h"
-#include "asterisk/say.h"
-#include "asterisk/features.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/config.h"
-#include "asterisk/cli.h"
-#include "asterisk/manager.h"
-#include "asterisk/utils.h"
-#include "asterisk/adsi.h"
-#include "asterisk/monitor.h"
-
-#ifdef __AST_DEBUG_MALLOC
-static void FREE(void *ptr)
-{
- free(ptr);
-}
-#else
-#define FREE free
-#endif
-
-#define DEFAULT_PARK_TIME 45000
-#define DEFAULT_TRANSFER_DIGIT_TIMEOUT 3000
-#define DEFAULT_FEATURE_DIGIT_TIMEOUT 500
-
-#define AST_MAX_WATCHERS 256
-
-static char *parkedcall = "ParkedCall";
-
-/* No more than 45 seconds parked before you do something with them */
-static int parkingtime = DEFAULT_PARK_TIME;
-
-/* Context for which parking is made accessible */
-static char parking_con[AST_MAX_EXTENSION];
-
-/* Context for dialback for parking (KLUDGE) */
-static char parking_con_dial[AST_MAX_EXTENSION];
-
-/* Extension you type to park the call */
-static char parking_ext[AST_MAX_EXTENSION];
-
-static char pickup_ext[AST_MAX_EXTENSION];
-
-/* Default sounds */
-static char courtesytone[256];
-static char xfersound[256];
-static char xferfailsound[256];
-
-/* First available extension for parking */
-static int parking_start;
-
-/* Last available extension for parking */
-static int parking_stop;
-
-static int parking_offset;
-
-static int parkfindnext;
-
-static int adsipark;
-
-static int transferdigittimeout;
-static int featuredigittimeout;
-
-/* Default courtesy tone played when party joins conference */
-
-/* Registrar for operations */
-static char *registrar = "res_features";
-
-static char *synopsis = "Answer a parked call";
-
-static char *descrip = "ParkedCall(exten):"
-"Used to connect to a parked call. This application is always\n"
-"registered internally and does not need to be explicitly added\n"
-"into the dialplan, although you should include the 'parkedcalls'\n"
-"context.\n";
-
-static char *parkcall = "Park";
-
-static char *synopsis2 = "Park yourself";
-
-static char *descrip2 = "Park(exten):"
-"Used to park yourself (typically in combination with a supervised\n"
-"transfer to know the parking space). This application is always\n"
-"registered internally and does not need to be explicitly added\n"
-"into the dialplan, although you should include the 'parkedcalls'\n"
-"context.\n";
-
-static struct ast_app *monitor_app=NULL;
-static int monitor_ok=1;
-
-struct parkeduser {
- struct ast_channel *chan;
- struct timeval start;
- int parkingnum;
- /* Where to go if our parking time expires */
- char context[AST_MAX_CONTEXT];
- char exten[AST_MAX_EXTENSION];
- int priority;
- int parkingtime;
- int notquiteyet;
- char peername[1024];
- unsigned char moh_trys;
- struct parkeduser *next;
-};
-
-static struct parkeduser *parkinglot;
-
-AST_MUTEX_DEFINE_STATIC(parking_lock);
-
-static pthread_t parking_thread;
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-char *ast_parking_ext(void)
-{
- return parking_ext;
-}
-
-char *ast_pickup_ext(void)
-{
- return pickup_ext;
-}
-
-struct ast_bridge_thread_obj
-{
- struct ast_bridge_config bconfig;
- struct ast_channel *chan;
- struct ast_channel *peer;
-};
-
-static void check_goto_on_transfer(struct ast_channel *chan)
-{
- struct ast_channel *xferchan;
- char *goto_on_transfer;
-
- goto_on_transfer = pbx_builtin_getvar_helper(chan, "GOTO_ON_BLINDXFR");
-
- if (!ast_strlen_zero(goto_on_transfer) && (xferchan = ast_channel_alloc(0))) {
- char *x;
- struct ast_frame *f;
-
- for (x = goto_on_transfer; x && *x; x++)
- if (*x == '^')
- *x = '|';
-
- strcpy(xferchan->name, chan->name);
- /* Make formats okay */
- xferchan->readformat = chan->readformat;
- xferchan->writeformat = chan->writeformat;
- ast_channel_masquerade(xferchan, chan);
- ast_parseable_goto(xferchan, goto_on_transfer);
- xferchan->_state = AST_STATE_UP;
- ast_clear_flag(xferchan, AST_FLAGS_ALL);
- xferchan->_softhangup = 0;
- if ((f = ast_read(xferchan))) {
- ast_frfree(f);
- f = NULL;
- ast_pbx_start(xferchan);
- } else {
- ast_hangup(xferchan);
- }
- }
-}
-
-static struct ast_channel *ast_feature_request_and_dial(struct ast_channel *caller, const char *type, int format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name);
-
-
-static void *ast_bridge_call_thread(void *data)
-{
- struct ast_bridge_thread_obj *tobj = data;
-
- tobj->chan->appl = "Transferred Call";
- tobj->chan->data = tobj->peer->name;
- tobj->peer->appl = "Transferred Call";
- tobj->peer->data = tobj->chan->name;
- if (tobj->chan->cdr) {
- ast_cdr_reset(tobj->chan->cdr, NULL);
- ast_cdr_setdestchan(tobj->chan->cdr, tobj->peer->name);
- }
- if (tobj->peer->cdr) {
- ast_cdr_reset(tobj->peer->cdr, NULL);
- ast_cdr_setdestchan(tobj->peer->cdr, tobj->chan->name);
- }
-
- ast_bridge_call(tobj->peer, tobj->chan, &tobj->bconfig);
- ast_hangup(tobj->chan);
- ast_hangup(tobj->peer);
- tobj->chan = tobj->peer = NULL;
- free(tobj);
- tobj=NULL;
- return NULL;
-}
-
-static void ast_bridge_call_thread_launch(void *data)
-{
- pthread_t thread;
- pthread_attr_t attr;
- struct sched_param sched;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&thread, &attr,ast_bridge_call_thread, data);
- pthread_attr_destroy(&attr);
- memset(&sched, 0, sizeof(sched));
- pthread_setschedparam(thread, SCHED_RR, &sched);
-}
-
-
-
-static int adsi_announce_park(struct ast_channel *chan, int parkingnum)
-{
- int res;
- int justify[5] = {ADSI_JUST_CENT, ADSI_JUST_CENT, ADSI_JUST_CENT, ADSI_JUST_CENT};
- char tmp[256];
- char *message[5] = {NULL, NULL, NULL, NULL, NULL};
-
- snprintf(tmp, sizeof(tmp), "Parked on %d", parkingnum);
- message[0] = tmp;
- res = adsi_load_session(chan, NULL, 0, 1);
- if (res == -1) {
- return res;
- }
- return adsi_print(chan, message, justify, 1);
-}
-
-/*--- ast_park_call: Park a call */
-/* We put the user in the parking list, then wake up the parking thread to be sure it looks
- after these channels too */
-int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeout, int *extout)
-{
- struct parkeduser *pu, *cur;
- int i,x,parking_range;
- char exten[AST_MAX_EXTENSION];
- struct ast_context *con;
-
- pu = malloc(sizeof(struct parkeduser));
- if (!pu) {
- ast_log(LOG_WARNING, "Out of memory\n");
- return -1;
- }
- memset(pu, 0, sizeof(struct parkeduser));
- ast_mutex_lock(&parking_lock);
- parking_range = parking_stop - parking_start+1;
- for (i = 0; i < parking_range; i++) {
- x = (i + parking_offset) % parking_range + parking_start;
- cur = parkinglot;
- while(cur) {
- if (cur->parkingnum == x)
- break;
- cur = cur->next;
- }
- if (!cur)
- break;
- }
-
- if (!(i < parking_range)) {
- ast_log(LOG_WARNING, "No more parking spaces\n");
- free(pu);
- ast_mutex_unlock(&parking_lock);
- return -1;
- }
- if (parkfindnext)
- parking_offset = x - parking_start + 1;
- chan->appl = "Parked Call";
- chan->data = NULL;
-
- pu->chan = chan;
- /* Start music on hold */
- if (chan != peer) {
- ast_indicate(pu->chan, AST_CONTROL_HOLD);
- ast_moh_start(pu->chan, NULL);
- }
- pu->start = ast_tvnow();
- pu->parkingnum = x;
- if (timeout > 0)
- pu->parkingtime = timeout;
- else
- pu->parkingtime = parkingtime;
- if (extout)
- *extout = x;
- if (peer)
- ast_copy_string(pu->peername, peer->name, sizeof(pu->peername));
-
- /* Remember what had been dialed, so that if the parking
- expires, we try to come back to the same place */
- if (!ast_strlen_zero(chan->macrocontext))
- ast_copy_string(pu->context, chan->macrocontext, sizeof(pu->context));
- else
- ast_copy_string(pu->context, chan->context, sizeof(pu->context));
- if (!ast_strlen_zero(chan->macroexten))
- ast_copy_string(pu->exten, chan->macroexten, sizeof(pu->exten));
- else
- ast_copy_string(pu->exten, chan->exten, sizeof(pu->exten));
- if (chan->macropriority)
- pu->priority = chan->macropriority;
- else
- pu->priority = chan->priority;
- pu->next = parkinglot;
- parkinglot = pu;
- /* If parking a channel directly, don't quiet yet get parking running on it */
- if (peer == chan)
- pu->notquiteyet = 1;
- ast_mutex_unlock(&parking_lock);
- /* Wake up the (presumably select()ing) thread */
- pthread_kill(parking_thread, SIGURG);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Parked %s on %d. Will timeout back to extension [%s] %s, %d in %d seconds\n", pu->chan->name, pu->parkingnum, pu->context, pu->exten, pu->priority, (pu->parkingtime/1000));
-
- manager_event(EVENT_FLAG_CALL, "ParkedCall",
- "Exten: %d\r\n"
- "Channel: %s\r\n"
- "From: %s\r\n"
- "Timeout: %ld\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- ,pu->parkingnum, pu->chan->name, peer->name
- ,(long)pu->start.tv_sec + (long)(pu->parkingtime/1000) - (long)time(NULL)
- ,(pu->chan->cid.cid_num ? pu->chan->cid.cid_num : "<unknown>")
- ,(pu->chan->cid.cid_name ? pu->chan->cid.cid_name : "<unknown>")
- );
-
- if (peer) {
- if (adsipark && adsi_available(peer)) {
- adsi_announce_park(peer, pu->parkingnum);
- }
- if (adsipark && adsi_available(peer)) {
- adsi_unload_session(peer);
- }
- }
- con = ast_context_find(parking_con);
- if (!con) {
- con = ast_context_create(NULL, parking_con, registrar);
- if (!con) {
- ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", parking_con);
- }
- }
- if (con) {
- snprintf(exten, sizeof(exten), "%d", x);
- ast_add_extension2(con, 1, exten, 1, NULL, NULL, parkedcall, strdup(exten), FREE, registrar);
- }
- if (peer)
- ast_say_digits(peer, pu->parkingnum, "", peer->language);
- if (pu->notquiteyet) {
- /* Wake up parking thread if we're really done */
- ast_moh_start(pu->chan, NULL);
- pu->notquiteyet = 0;
- pthread_kill(parking_thread, SIGURG);
- }
- return 0;
-}
-
-int ast_masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout)
-{
- struct ast_channel *chan;
- struct ast_frame *f;
-
- /* Make a new, fake channel that we'll use to masquerade in the real one */
- chan = ast_channel_alloc(0);
- if (chan) {
- /* Let us keep track of the channel name */
- snprintf(chan->name, sizeof (chan->name), "Parked/%s",rchan->name);
-
- /* Make formats okay */
- chan->readformat = rchan->readformat;
- chan->writeformat = rchan->writeformat;
- ast_channel_masquerade(chan, rchan);
-
- /* Setup the extensions and such */
- ast_copy_string(chan->context, rchan->context, sizeof(chan->context));
- ast_copy_string(chan->exten, rchan->exten, sizeof(chan->exten));
- chan->priority = rchan->priority;
-
- /* Make the masq execute */
- f = ast_read(chan);
- if (f)
- ast_frfree(f);
- ast_park_call(chan, peer, timeout, extout);
- } else {
- ast_log(LOG_WARNING, "Unable to create parked channel\n");
- return -1;
- }
- return 0;
-}
-
-
-#define FEATURE_RETURN_HANGUP -1
-#define FEATURE_RETURN_SUCCESSBREAK 0
-#define FEATURE_RETURN_PBX_KEEPALIVE AST_PBX_KEEPALIVE
-#define FEATURE_RETURN_NO_HANGUP_PEER AST_PBX_NO_HANGUP_PEER
-#define FEATURE_RETURN_PASSDIGITS 21
-#define FEATURE_RETURN_STOREDIGITS 22
-#define FEATURE_RETURN_SUCCESS 23
-
-#define FEATURE_SENSE_CHAN (1 << 0)
-#define FEATURE_SENSE_PEER (1 << 1)
-
-
-static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense)
-{
- char *touch_monitor = NULL, *caller_chan_id = NULL, *callee_chan_id = NULL, *args = NULL, *touch_format = NULL;
- int x = 0;
- size_t len;
- struct ast_channel *caller_chan = NULL, *callee_chan = NULL;
-
-
- if(sense == 2) {
- caller_chan = peer;
- callee_chan = chan;
- } else {
- callee_chan = peer;
- caller_chan = chan;
- }
-
- if (!monitor_ok) {
- ast_log(LOG_ERROR,"Cannot record the call. The monitor application is disabled.\n");
- return -1;
- }
-
- if (!monitor_app) {
- if (!(monitor_app = pbx_findapp("Monitor"))) {
- monitor_ok=0;
- ast_log(LOG_ERROR,"Cannot record the call. The monitor application is disabled.\n");
- return -1;
- }
- }
- if (!ast_strlen_zero(courtesytone)) {
- if (ast_autoservice_start(callee_chan))
- return -1;
- if (!ast_streamfile(caller_chan, courtesytone, caller_chan->language)) {
- if (ast_waitstream(caller_chan, "") < 0) {
- ast_log(LOG_WARNING, "Failed to play courtesy tone!\n");
- ast_autoservice_stop(callee_chan);
- return -1;
- }
- }
- if (ast_autoservice_stop(callee_chan))
- return -1;
- }
-
- if (callee_chan->monitor) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "User hit '%s' to stop recording call.\n", code);
- ast_monitor_stop(callee_chan, 1);
- return FEATURE_RETURN_SUCCESS;
- }
-
- if (caller_chan && callee_chan) {
- touch_format = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR_FORMAT");
- if (!touch_format)
- touch_format = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR_FORMAT");
-
- touch_monitor = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR");
- if (!touch_monitor)
- touch_monitor = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR");
-
- if (touch_monitor) {
- len = strlen(touch_monitor) + 50;
- args = alloca(len);
- snprintf(args, len, "%s|auto-%ld-%s|m", (touch_format) ? touch_format : "wav", time(NULL), touch_monitor);
- } else {
- caller_chan_id = ast_strdupa(caller_chan->cid.cid_num ? caller_chan->cid.cid_num : caller_chan->name);
- callee_chan_id = ast_strdupa(callee_chan->cid.cid_num ? callee_chan->cid.cid_num : callee_chan->name);
- len = strlen(caller_chan_id) + strlen(callee_chan_id) + 50;
- args = alloca(len);
- snprintf(args, len, "%s|auto-%ld-%s-%s|m", (touch_format) ? touch_format : "wav", time(NULL), caller_chan_id, callee_chan_id);
- }
-
- for( x = 0; x < strlen(args); x++)
- if (args[x] == '/')
- args[x] = '-';
-
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "User hit '%s' to record call. filename: %s\n", code, args);
-
- pbx_exec(callee_chan, monitor_app, args, 1);
-
- return FEATURE_RETURN_SUCCESS;
- }
-
- ast_log(LOG_NOTICE,"Cannot record the call. One or both channels have gone away.\n");
- return -1;
-}
-
-static int builtin_disconnect(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense)
-{
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_3 "User hit '%s' to disconnect call.\n", code);
- return FEATURE_RETURN_HANGUP;
-}
-
-static int builtin_blindtransfer(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense)
-{
- struct ast_channel *transferer;
- struct ast_channel *transferee;
- char *transferer_real_context;
- char newext[256];
- int res;
-
- if (sense == FEATURE_SENSE_PEER) {
- transferer = peer;
- transferee = chan;
- } else {
- transferer = chan;
- transferee = peer;
- }
- if (!(transferer_real_context = pbx_builtin_getvar_helper(transferee, "TRANSFER_CONTEXT")) &&
- !(transferer_real_context = pbx_builtin_getvar_helper(transferer, "TRANSFER_CONTEXT"))) {
- /* Use the non-macro context to transfer the call */
- if (!ast_strlen_zero(transferer->macrocontext))
- transferer_real_context = transferer->macrocontext;
- else
- transferer_real_context = transferer->context;
- }
- /* Start autoservice on chan while we talk
- to the originator */
- ast_indicate(transferee, AST_CONTROL_HOLD);
- ast_autoservice_start(transferee);
- ast_moh_start(transferee, NULL);
-
- memset(newext, 0, sizeof(newext));
-
- /* Transfer */
- if ((res=ast_streamfile(transferer, "pbx-transfer", transferer->language))) {
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- return res;
- }
- if ((res=ast_waitstream(transferer, AST_DIGIT_ANY)) < 0) {
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- return res;
- } else if (res > 0) {
- /* If they've typed a digit already, handle it */
- newext[0] = (char) res;
- }
-
- ast_stopstream(transferer);
- res = ast_app_dtget(transferer, transferer_real_context, newext, sizeof(newext), 100, transferdigittimeout);
- if (res < 0) {
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- return res;
- }
- if (!strcmp(newext, ast_parking_ext())) {
- ast_moh_stop(transferee);
-
- res = ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- if (res)
- res = -1;
- else if (!ast_park_call(transferee, transferer, 0, NULL)) {
- /* We return non-zero, but tell the PBX not to hang the channel when
- the thread dies -- We have to be careful now though. We are responsible for
- hanging up the channel, else it will never be hung up! */
-
- if (transferer == peer)
- res = AST_PBX_KEEPALIVE;
- else
- res = AST_PBX_NO_HANGUP_PEER;
- return res;
- } else {
- ast_log(LOG_WARNING, "Unable to park call %s\n", transferee->name);
- }
- /* XXX Maybe we should have another message here instead of invalid extension XXX */
- } else if (ast_exists_extension(transferee, transferer_real_context, newext, 1, transferer->cid.cid_num)) {
- pbx_builtin_setvar_helper(peer, "BLINDTRANSFER", chan->name);
- pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", peer->name);
- ast_moh_stop(transferee);
- res=ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- if (!transferee->pbx) {
- /* Doh! Use our handy async_goto functions */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Transferring %s to '%s' (context %s) priority 1\n"
- ,transferee->name, newext, transferer_real_context);
- if (ast_async_goto(transferee, transferer_real_context, newext, 1))
- ast_log(LOG_WARNING, "Async goto failed :-(\n");
- res = -1;
- } else {
- /* Set the channel's new extension, since it exists, using transferer context */
- ast_copy_string(transferee->exten, newext, sizeof(transferee->exten));
- ast_copy_string(transferee->context, transferer_real_context, sizeof(transferee->context));
- transferee->priority = 0;
- }
- check_goto_on_transfer(transferer);
- return res;
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Unable to find extension '%s' in context '%s'\n", newext, transferer_real_context);
- }
- if (!ast_strlen_zero(xferfailsound))
- res = ast_streamfile(transferer, xferfailsound, transferee->language);
- else
- res = 0;
- if (res) {
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- return res;
- }
- res = ast_waitstream(transferer, AST_DIGIT_ANY);
- ast_stopstream(transferer);
- ast_moh_stop(transferee);
- res = ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- if (res) {
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Hungup during autoservice stop on '%s'\n", transferee->name);
- return res;
- }
- return FEATURE_RETURN_SUCCESS;
-}
-
-static int builtin_atxfer(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense)
-{
- struct ast_channel *transferer;
- struct ast_channel *transferee;
- struct ast_channel *newchan, *xferchan=NULL;
- int outstate=0;
- struct ast_bridge_config bconfig;
- char *transferer_real_context;
- char xferto[256],dialstr[265];
- char *cid_num;
- char *cid_name;
- int res;
- struct ast_frame *f = NULL;
- struct ast_bridge_thread_obj *tobj;
-
- ast_log(LOG_DEBUG, "Executing Attended Transfer %s, %s (sense=%d) XXX\n", chan->name, peer->name, sense);
- if (sense == FEATURE_SENSE_PEER) {
- transferer = peer;
- transferee = chan;
- } else {
- transferer = chan;
- transferee = peer;
- }
- if (!(transferer_real_context=pbx_builtin_getvar_helper(transferee, "TRANSFER_CONTEXT")) &&
- !(transferer_real_context=pbx_builtin_getvar_helper(transferer, "TRANSFER_CONTEXT"))) {
- /* Use the non-macro context to transfer the call */
- if (!ast_strlen_zero(transferer->macrocontext))
- transferer_real_context = transferer->macrocontext;
- else
- transferer_real_context = transferer->context;
- }
- /* Start autoservice on chan while we talk
- to the originator */
- ast_indicate(transferee, AST_CONTROL_HOLD);
- ast_autoservice_start(transferee);
- ast_moh_start(transferee, NULL);
- memset(xferto, 0, sizeof(xferto));
- /* Transfer */
- if ((res = ast_streamfile(transferer, "pbx-transfer", transferer->language))) {
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- return res;
- }
- if ((res=ast_waitstream(transferer, AST_DIGIT_ANY)) < 0) {
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- return res;
- } else if(res > 0) {
- /* If they've typed a digit already, handle it */
- xferto[0] = (char) res;
- }
- if ((ast_app_dtget(transferer, transferer_real_context, xferto, sizeof(xferto), 100, transferdigittimeout))) {
- cid_num = transferer->cid.cid_num;
- cid_name = transferer->cid.cid_name;
- if (ast_exists_extension(transferer, transferer_real_context,xferto, 1, cid_num)) {
- snprintf(dialstr, sizeof(dialstr), "%s@%s/n", xferto, transferer_real_context);
- newchan = ast_feature_request_and_dial(transferer, "Local", ast_best_codec(transferer->nativeformats), dialstr, 15000, &outstate, cid_num, cid_name);
- ast_indicate(transferer, -1);
- if (newchan) {
- res = ast_channel_make_compatible(transferer, newchan);
- if (res < 0) {
- ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", transferer->name, newchan->name);
- ast_hangup(newchan);
- return -1;
- }
- memset(&bconfig,0,sizeof(struct ast_bridge_config));
- ast_set_flag(&(bconfig.features_caller), AST_FEATURE_DISCONNECT);
- ast_set_flag(&(bconfig.features_callee), AST_FEATURE_DISCONNECT);
- res = ast_bridge_call(transferer,newchan,&bconfig);
- if (newchan->_softhangup || newchan->_state != AST_STATE_UP || !transferer->_softhangup) {
- ast_hangup(newchan);
- if (f) {
- ast_frfree(f);
- f = NULL;
- }
- if (!ast_strlen_zero(xfersound) && !ast_streamfile(transferer, xfersound, transferer->language)) {
- if (ast_waitstream(transferer, "") < 0) {
- ast_log(LOG_WARNING, "Failed to play courtesy tone!\n");
- }
- }
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- transferer->_softhangup = 0;
- return FEATURE_RETURN_SUCCESS;
- }
-
- res = ast_channel_make_compatible(transferee, newchan);
- if (res < 0) {
- ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", transferee->name, newchan->name);
- ast_hangup(newchan);
- return -1;
- }
-
-
- ast_moh_stop(transferee);
-
- if ((ast_autoservice_stop(transferee) < 0)
- || (ast_waitfordigit(transferee, 100) < 0)
- || (ast_waitfordigit(newchan, 100) < 0)
- || ast_check_hangup(transferee)
- || ast_check_hangup(newchan)) {
- ast_hangup(newchan);
- res = -1;
- return -1;
- }
-
- if ((xferchan = ast_channel_alloc(0))) {
- snprintf(xferchan->name, sizeof (xferchan->name), "Transfered/%s",transferee->name);
- /* Make formats okay */
- xferchan->readformat = transferee->readformat;
- xferchan->writeformat = transferee->writeformat;
- ast_channel_masquerade(xferchan, transferee);
- ast_explicit_goto(xferchan, transferee->context, transferee->exten, transferee->priority);
- xferchan->_state = AST_STATE_UP;
- ast_clear_flag(xferchan, AST_FLAGS_ALL);
- xferchan->_softhangup = 0;
-
- if ((f = ast_read(xferchan))) {
- ast_frfree(f);
- f = NULL;
- }
-
- } else {
- ast_hangup(newchan);
- return -1;
- }
-
- newchan->_state = AST_STATE_UP;
- ast_clear_flag(newchan, AST_FLAGS_ALL);
- newchan->_softhangup = 0;
-
- tobj = malloc(sizeof(struct ast_bridge_thread_obj));
- if (tobj) {
- memset(tobj,0,sizeof(struct ast_bridge_thread_obj));
- tobj->chan = xferchan;
- tobj->peer = newchan;
- tobj->bconfig = *config;
-
- if (!ast_strlen_zero(xfersound) && !ast_streamfile(newchan, xfersound, newchan->language)) {
- if (ast_waitstream(newchan, "") < 0) {
- ast_log(LOG_WARNING, "Failed to play courtesy tone!\n");
- }
- }
- ast_bridge_call_thread_launch(tobj);
- } else {
- ast_log(LOG_WARNING, "Out of memory!\n");
- ast_hangup(xferchan);
- ast_hangup(newchan);
- }
- return -1;
-
- } else {
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- /* any reason besides user requested cancel and busy triggers the failed sound */
- if (outstate != AST_CONTROL_UNHOLD && outstate != AST_CONTROL_BUSY && !ast_strlen_zero(xferfailsound)) {
- res = ast_streamfile(transferer, xferfailsound, transferer->language);
- if (!res && (ast_waitstream(transferer, "") < 0)) {
- return -1;
- }
- }
- return FEATURE_RETURN_SUCCESS;
- }
- } else {
- ast_log(LOG_WARNING, "Extension %s does not exist in context %s\n",xferto,transferer_real_context);
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
- res = ast_streamfile(transferer, "beeperr", transferer->language);
- if (!res && (ast_waitstream(transferer, "") < 0)) {
- return -1;
- }
- }
- } else {
- ast_log(LOG_WARNING, "Did not read data.\n");
- res = ast_streamfile(transferer, "beeperr", transferer->language);
- if (ast_waitstream(transferer, "") < 0) {
- return -1;
- }
- }
- ast_moh_stop(transferee);
- ast_autoservice_stop(transferee);
- ast_indicate(transferee, AST_CONTROL_UNHOLD);
-
- return FEATURE_RETURN_SUCCESS;
-}
-
-
-/* add atxfer and automon as undefined so you can only use em if you configure them */
-#define FEATURES_COUNT (sizeof(builtin_features) / sizeof(builtin_features[0]))
-struct ast_call_feature builtin_features[] =
- {
- { AST_FEATURE_REDIRECT, "Blind Transfer", "blindxfer", "#", "#", builtin_blindtransfer, AST_FEATURE_FLAG_NEEDSDTMF },
- { AST_FEATURE_REDIRECT, "Attended Transfer", "atxfer", "", "", builtin_atxfer, AST_FEATURE_FLAG_NEEDSDTMF },
- { AST_FEATURE_AUTOMON, "One Touch Monitor", "automon", "", "", builtin_automonitor, AST_FEATURE_FLAG_NEEDSDTMF },
- { AST_FEATURE_DISCONNECT, "Disconnect Call", "disconnect", "*", "*", builtin_disconnect, AST_FEATURE_FLAG_NEEDSDTMF },
-};
-
-
-static AST_LIST_HEAD(feature_list,ast_call_feature) feature_list;
-
-/* register new feature into feature_list*/
-void ast_register_feature(struct ast_call_feature *feature)
-{
- if (!feature) {
- ast_log(LOG_NOTICE,"You didn't pass a feature!\n");
- return;
- }
-
- AST_LIST_LOCK(&feature_list);
- AST_LIST_INSERT_HEAD(&feature_list,feature,feature_entry);
- AST_LIST_UNLOCK(&feature_list);
-
- if (option_verbose >= 2)
- ast_verbose(VERBOSE_PREFIX_2 "Registered Feature '%s'\n",feature->sname);
-}
-
-/* unregister feature from feature_list */
-void ast_unregister_feature(struct ast_call_feature *feature)
-{
- if (!feature) return;
-
- AST_LIST_LOCK(&feature_list);
- AST_LIST_REMOVE(&feature_list,feature,feature_entry);
- AST_LIST_UNLOCK(&feature_list);
- free(feature);
-}
-
-static void ast_unregister_features(void)
-{
- struct ast_call_feature *feature;
-
- AST_LIST_LOCK(&feature_list);
- while ((feature = AST_LIST_REMOVE_HEAD(&feature_list,feature_entry)))
- free(feature);
- AST_LIST_UNLOCK(&feature_list);
-}
-
-/* find a feature by name */
-static struct ast_call_feature *find_feature(char *name)
-{
- struct ast_call_feature *tmp;
-
- AST_LIST_LOCK(&feature_list);
- AST_LIST_TRAVERSE(&feature_list, tmp, feature_entry) {
- if (!strcasecmp(tmp->sname, name))
- break;
- }
- AST_LIST_UNLOCK(&feature_list);
-
- return tmp;
-}
-
-/* exec an app by feature */
-static int feature_exec_app(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense)
-{
- struct ast_app *app;
- struct ast_call_feature *feature;
- int res;
-
- AST_LIST_LOCK(&feature_list);
- AST_LIST_TRAVERSE(&feature_list,feature,feature_entry) {
- if (!strcasecmp(feature->exten,code)) break;
- }
- AST_LIST_UNLOCK(&feature_list);
-
- if (!feature) { /* shouldn't ever happen! */
- ast_log(LOG_NOTICE, "Found feature before, but at execing we've lost it??\n");
- return -1;
- }
-
- app = pbx_findapp(feature->app);
- if (app) {
- struct ast_channel *work = chan;
- if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLEE))
- work = peer;
- res = pbx_exec(work, app, feature->app_args, 1);
- if (res < 0)
- return res;
- } else {
- ast_log(LOG_WARNING, "Could not find application (%s)\n", feature->app);
- return -2;
- }
-
- return FEATURE_RETURN_SUCCESS;
-}
-
-static void unmap_features(void)
-{
- int x;
- for (x = 0; x < FEATURES_COUNT; x++)
- strcpy(builtin_features[x].exten, builtin_features[x].default_exten);
-}
-
-static int remap_feature(const char *name, const char *value)
-{
- int x;
- int res = -1;
- for (x = 0; x < FEATURES_COUNT; x++) {
- if (!strcasecmp(name, builtin_features[x].sname)) {
- ast_copy_string(builtin_features[x].exten, value, sizeof(builtin_features[x].exten));
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Remapping feature %s (%s) to sequence '%s'\n", builtin_features[x].fname, builtin_features[x].sname, builtin_features[x].exten);
- res = 0;
- } else if (!strcmp(value, builtin_features[x].exten))
- ast_log(LOG_WARNING, "Sequence '%s' already mapped to function %s (%s) while assigning to %s\n", value, builtin_features[x].fname, builtin_features[x].sname, name);
- }
- return res;
-}
-
-static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense)
-{
- int x;
- struct ast_flags features;
- int res = FEATURE_RETURN_PASSDIGITS;
- struct ast_call_feature *feature;
- char *dynamic_features=pbx_builtin_getvar_helper(chan,"DYNAMIC_FEATURES");
-
- if (sense == FEATURE_SENSE_CHAN)
- ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL);
- else
- ast_copy_flags(&features, &(config->features_callee), AST_FLAGS_ALL);
- ast_log(LOG_DEBUG, "Feature interpret: chan=%s, peer=%s, sense=%d, features=%d\n", chan->name, peer->name, sense, features.flags);
-
- for (x=0; x < FEATURES_COUNT; x++) {
- if ((ast_test_flag(&features, builtin_features[x].feature_mask)) &&
- !ast_strlen_zero(builtin_features[x].exten)) {
- /* Feature is up for consideration */
- if (!strcmp(builtin_features[x].exten, code)) {
- res = builtin_features[x].operation(chan, peer, config, code, sense);
- break;
- } else if (!strncmp(builtin_features[x].exten, code, strlen(code))) {
- if (res == FEATURE_RETURN_PASSDIGITS)
- res = FEATURE_RETURN_STOREDIGITS;
- }
- }
- }
-
-
- if (!ast_strlen_zero(dynamic_features)) {
- char *tmp = ast_strdupa(dynamic_features);
- char *tok;
-
- if (!tmp)
- return res;
-
- while ((tok = strsep(&tmp, "#")) != NULL) {
- feature = find_feature(tok);
-
- if (feature) {
- /* Feature is up for consideration */
- if (!strcmp(feature->exten, code)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 " Feature Found: %s exten: %s\n",feature->sname, tok);
- res = feature->operation(chan, peer, config, code, sense);
- break;
- } else if (!strncmp(feature->exten, code, strlen(code))) {
- res = FEATURE_RETURN_STOREDIGITS;
- }
- }
- }
- }
-
- return res;
-}
-
-static void set_config_flags(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config)
-{
- int x;
-
- ast_clear_flag(config, AST_FLAGS_ALL);
- for (x = 0; x < FEATURES_COUNT; x++) {
- if (ast_test_flag(builtin_features + x, AST_FEATURE_FLAG_NEEDSDTMF)) {
- if (ast_test_flag(&(config->features_caller), builtin_features[x].feature_mask))
- ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0);
-
- if (ast_test_flag(&(config->features_callee), builtin_features[x].feature_mask))
- ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1);
- }
- }
-
- if (chan && peer && !(ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_0) && ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_1))) {
- char *dynamic_features;
-
- dynamic_features = pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES");
-
- if (dynamic_features) {
- char *tmp = ast_strdupa(dynamic_features);
- char *tok;
- struct ast_call_feature *feature;
-
- if (!tmp) {
- return;
- }
-
- /* while we have a feature */
- while (NULL != (tok = strsep(&tmp, "#"))) {
- if ((feature = find_feature(tok))) {
- if (ast_test_flag(feature, AST_FEATURE_FLAG_NEEDSDTMF)) {
- if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLER))
- ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0);
- if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLEE))
- ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1);
- }
- }
- }
- }
- }
-}
-
-
-static struct ast_channel *ast_feature_request_and_dial(struct ast_channel *caller, const char *type, int format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name)
-{
- int state = 0;
- int cause = 0;
- int to;
- struct ast_channel *chan;
- struct ast_channel *monitor_chans[2];
- struct ast_channel *active_channel;
- struct ast_frame *f = NULL;
- int res = 0, ready = 0;
-
- if ((chan = ast_request(type, format, data, &cause))) {
- ast_set_callerid(chan, cid_num, cid_name, cid_num);
- ast_channel_inherit_variables(caller, chan);
- if (!ast_call(chan, data, timeout)) {
- struct timeval started;
- int x, len = 0;
- char *disconnect_code = NULL, *dialed_code = NULL;
-
- ast_indicate(caller, AST_CONTROL_RINGING);
- /* support dialing of the featuremap disconnect code while performing an attended tranfer */
- for (x=0; x < FEATURES_COUNT; x++) {
- if (strcasecmp(builtin_features[x].sname, "disconnect"))
- continue;
-
- disconnect_code = builtin_features[x].exten;
- len = strlen(disconnect_code) + 1;
- dialed_code = alloca(len);
- memset(dialed_code, 0, len);
- break;
- }
- x = 0;
- started = ast_tvnow();
- to = timeout;
- while (!ast_check_hangup(caller) && timeout && (chan->_state != AST_STATE_UP)) {
- monitor_chans[0] = caller;
- monitor_chans[1] = chan;
- active_channel = ast_waitfor_n(monitor_chans, 2, &to);
-
- /* see if the timeout has been violated */
- if(ast_tvdiff_ms(ast_tvnow(), started) > timeout) {
- state = AST_CONTROL_UNHOLD;
- ast_log(LOG_NOTICE, "We exceeded our AT-timeout\n");
- break; /*doh! timeout*/
- }
-
- if (!active_channel) {
- continue;
- }
-
- if (chan && (chan == active_channel)){
- f = ast_read(chan);
- if (f == NULL) { /*doh! where'd he go?*/
- state = AST_CONTROL_HANGUP;
- res = 0;
- break;
- }
-
- if (f->frametype == AST_FRAME_CONTROL || f->frametype == AST_FRAME_DTMF || f->frametype == AST_FRAME_TEXT) {
- if (f->subclass == AST_CONTROL_RINGING) {
- state = f->subclass;
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "%s is ringing\n", chan->name);
- ast_indicate(caller, AST_CONTROL_RINGING);
- } else if ((f->subclass == AST_CONTROL_BUSY) || (f->subclass == AST_CONTROL_CONGESTION)) {
- state = f->subclass;
- ast_frfree(f);
- f = NULL;
- break;
- } else if (f->subclass == AST_CONTROL_ANSWER) {
- /* This is what we are hoping for */
- state = f->subclass;
- ast_frfree(f);
- f = NULL;
- ready=1;
- break;
- } else {
- ast_log(LOG_NOTICE, "Don't know what to do about control frame: %d\n", f->subclass);
- }
- /* else who cares */
- }
-
- } else if (caller && (active_channel == caller)) {
- f = ast_read(caller);
- if (f == NULL) { /*doh! where'd he go?*/
- if (caller->_softhangup && !chan->_softhangup) {
- /* make this a blind transfer */
- ready = 1;
- break;
- }
- state = AST_CONTROL_HANGUP;
- res = 0;
- break;
- }
-
- if (f->frametype == AST_FRAME_DTMF) {
- dialed_code[x++] = f->subclass;
- dialed_code[x] = '\0';
- if (strlen(dialed_code) == len) {
- x = 0;
- } else if (x && strncmp(dialed_code, disconnect_code, x)) {
- x = 0;
- dialed_code[x] = '\0';
- }
- if (*dialed_code && !strcmp(dialed_code, disconnect_code)) {
- /* Caller Canceled the call */
- state = AST_CONTROL_UNHOLD;
- ast_frfree(f);
- f = NULL;
- break;
- }
- }
- }
- if (f) {
- ast_frfree(f);
- }
- }
- } else
- ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
- } else {
- ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
- switch(cause) {
- case AST_CAUSE_BUSY:
- state = AST_CONTROL_BUSY;
- break;
- case AST_CAUSE_CONGESTION:
- state = AST_CONTROL_CONGESTION;
- break;
- }
- }
-
- ast_indicate(caller, -1);
- if (chan && ready) {
- if (chan->_state == AST_STATE_UP)
- state = AST_CONTROL_ANSWER;
- res = 0;
- } else if(chan) {
- res = -1;
- ast_hangup(chan);
- chan = NULL;
- } else {
- res = -1;
- }
-
- if (outstate)
- *outstate = state;
-
- if (chan && res <= 0) {
- if (!chan->cdr) {
- chan->cdr = ast_cdr_alloc();
- }
- if (chan->cdr) {
- char tmp[256];
- ast_cdr_init(chan->cdr, chan);
- snprintf(tmp, 256, "%s/%s", type, (char *)data);
- ast_cdr_setapp(chan->cdr,"Dial",tmp);
- ast_cdr_update(chan);
- ast_cdr_start(chan->cdr);
- ast_cdr_end(chan->cdr);
- /* If the cause wasn't handled properly */
- if (ast_cdr_disposition(chan->cdr,chan->hangupcause))
- ast_cdr_failed(chan->cdr);
- } else {
- ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
- }
- }
-
- return chan;
-}
-
-int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast_bridge_config *config)
-{
- /* Copy voice back and forth between the two channels. Give the peer
- the ability to transfer calls with '#<extension' syntax. */
- struct ast_frame *f;
- struct ast_channel *who;
- char chan_featurecode[FEATURE_MAX_LEN + 1]="";
- char peer_featurecode[FEATURE_MAX_LEN + 1]="";
- int res;
- int diff;
- int hasfeatures=0;
- int hadfeatures=0;
- struct ast_option_header *aoh;
- struct timeval start = { 0 , 0 };
- struct ast_bridge_config backup_config;
- char *monitor_exec;
-
- memset(&backup_config, 0, sizeof(backup_config));
-
- config->start_time = ast_tvnow();
-
- if (chan && peer) {
- pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name);
- pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name);
- } else if (chan)
- pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
-
- if (monitor_ok) {
- if (!monitor_app) {
- if (!(monitor_app = pbx_findapp("Monitor")))
- monitor_ok=0;
- }
- if (monitor_app) {
- if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR")))
- pbx_exec(chan, monitor_app, monitor_exec, 1);
- else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
- pbx_exec(peer, monitor_app, monitor_exec, 1);
- }
- }
-
- set_config_flags(chan, peer, config);
- config->firstpass = 1;
-
- /* Answer if need be */
- if (ast_answer(chan))
- return -1;
- peer->appl = "Bridged Call";
- peer->data = chan->name;
-
- /* copy the userfield from the B-leg to A-leg if applicable */
- if (chan->cdr && peer->cdr && !ast_strlen_zero(peer->cdr->userfield)) {
- char tmp[256];
- if (!ast_strlen_zero(chan->cdr->userfield)) {
- snprintf(tmp, sizeof(tmp), "%s;%s", chan->cdr->userfield, peer->cdr->userfield);
- ast_cdr_appenduserfield(chan, tmp);
- } else
- ast_cdr_setuserfield(chan, peer->cdr->userfield);
- /* free the peer's cdr without ast_cdr_free complaining */
- free(peer->cdr);
- peer->cdr = NULL;
- }
- for (;;) {
- if (config->feature_timer)
- start = ast_tvnow();
-
- res = ast_channel_bridge(chan, peer, config, &f, &who);
-
- if (config->feature_timer) {
- /* Update time limit for next pass */
- diff = ast_tvdiff_ms(ast_tvnow(), start);
- config->feature_timer -= diff;
- if (hasfeatures) {
- /* Running on backup config, meaning a feature might be being
- activated, but that's no excuse to keep things going
- indefinitely! */
- if (backup_config.feature_timer && ((backup_config.feature_timer -= diff) <= 0)) {
- ast_log(LOG_DEBUG, "Timed out, realtime this time!\n");
- config->feature_timer = 0;
- who = chan;
- if (f)
- ast_frfree(f);
- f = NULL;
- res = 0;
- } else if (config->feature_timer <= 0) {
- /* Not *really* out of time, just out of time for
- digits to come in for features. */
- ast_log(LOG_DEBUG, "Timed out for feature!\n");
- if (!ast_strlen_zero(peer_featurecode)) {
- ast_dtmf_stream(chan, peer, peer_featurecode, 0);
- memset(peer_featurecode, 0, sizeof(peer_featurecode));
- }
- if (!ast_strlen_zero(chan_featurecode)) {
- ast_dtmf_stream(peer, chan, chan_featurecode, 0);
- memset(chan_featurecode, 0, sizeof(chan_featurecode));
- }
- if (f)
- ast_frfree(f);
- hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
- if (!hasfeatures) {
- /* Restore original (possibly time modified) bridge config */
- memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
- memset(&backup_config, 0, sizeof(backup_config));
- }
- hadfeatures = hasfeatures;
- /* Continue as we were */
- continue;
- }
- } else {
- if (config->feature_timer <=0) {
- /* We ran out of time */
- config->feature_timer = 0;
- who = chan;
- if (f)
- ast_frfree(f);
- f = NULL;
- res = 0;
- }
- }
- }
- if (res < 0) {
- ast_log(LOG_WARNING, "Bridge failed on channels %s and %s\n", chan->name, peer->name);
- return -1;
- }
-
- if (!f || ((f->frametype == AST_FRAME_CONTROL) && ((f->subclass == AST_CONTROL_HANGUP) || (f->subclass == AST_CONTROL_BUSY) ||
- (f->subclass == AST_CONTROL_CONGESTION)))) {
- res = -1;
- break;
- }
- if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RINGING)) {
- if (who == chan)
- ast_indicate(peer, AST_CONTROL_RINGING);
- else
- ast_indicate(chan, AST_CONTROL_RINGING);
- }
- if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == -1)) {
- if (who == chan)
- ast_indicate(peer, -1);
- else
- ast_indicate(chan, -1);
- }
- if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_FLASH)) {
- if (who == chan)
- ast_indicate(peer, AST_CONTROL_FLASH);
- else
- ast_indicate(chan, AST_CONTROL_FLASH);
- }
- if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_OPTION)) {
- aoh = f->data;
- /* Forward option Requests */
- if (aoh && (aoh->flag == AST_OPTION_FLAG_REQUEST)) {
- if (who == chan)
- ast_channel_setoption(peer, ntohs(aoh->option), aoh->data, f->datalen - sizeof(struct ast_option_header), 0);
- else
- ast_channel_setoption(chan, ntohs(aoh->option), aoh->data, f->datalen - sizeof(struct ast_option_header), 0);
- }
- }
- /* check for '*', if we find it it's time to disconnect */
- if (f && (f->frametype == AST_FRAME_DTMF)) {
- char *featurecode;
- int sense;
- struct ast_channel *other;
-
- hadfeatures = hasfeatures;
- /* This cannot overrun because the longest feature is one shorter than our buffer */
- if (who == chan) {
- other = peer;
- sense = FEATURE_SENSE_CHAN;
- featurecode = chan_featurecode;
- } else {
- other = chan;
- sense = FEATURE_SENSE_PEER;
- featurecode = peer_featurecode;
- }
- featurecode[strlen(featurecode)] = f->subclass;
- config->feature_timer = backup_config.feature_timer;
- res = ast_feature_interpret(chan, peer, config, featurecode, sense);
- switch(res) {
- case FEATURE_RETURN_PASSDIGITS:
- ast_dtmf_stream(other, who, featurecode, 0);
- /* Fall through */
- case FEATURE_RETURN_SUCCESS:
- memset(featurecode, 0, sizeof(chan_featurecode));
- break;
- }
- if (res >= FEATURE_RETURN_PASSDIGITS) {
- res = 0;
- } else {
- ast_frfree(f);
- break;
- }
- hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
- if (hadfeatures && !hasfeatures) {
- /* Restore backup */
- memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
- memset(&backup_config, 0, sizeof(struct ast_bridge_config));
- } else if (hasfeatures) {
- if (!hadfeatures) {
- /* Backup configuration */
- memcpy(&backup_config, config, sizeof(struct ast_bridge_config));
- /* Setup temporary config options */
- config->play_warning = 0;
- ast_clear_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING);
- ast_clear_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING);
- config->warning_freq = 0;
- config->warning_sound = NULL;
- config->end_sound = NULL;
- config->start_sound = NULL;
- config->firstpass = 0;
- }
- config->feature_timer = featuredigittimeout;
- ast_log(LOG_DEBUG, "Set time limit to %ld\n", config->feature_timer);
- }
- }
- if (f)
- ast_frfree(f);
- }
- return res;
-}
-
-static void *do_parking_thread(void *ignore)
-{
- int ms, tms, max;
- struct parkeduser *pu, *pl, *pt = NULL;
- struct timeval tv;
- struct ast_frame *f;
- char exten[AST_MAX_EXTENSION];
- char *peername,*cp;
- char returnexten[AST_MAX_EXTENSION];
- struct ast_context *con;
- int x;
- fd_set rfds, efds;
- fd_set nrfds, nefds;
- FD_ZERO(&rfds);
- FD_ZERO(&efds);
-
- for (;;) {
- ms = -1;
- max = -1;
- ast_mutex_lock(&parking_lock);
- pl = NULL;
- pu = parkinglot;
- FD_ZERO(&nrfds);
- FD_ZERO(&nefds);
- while(pu) {
- if (pu->notquiteyet) {
- /* Pretend this one isn't here yet */
- pl = pu;
- pu = pu->next;
- continue;
- }
- tms = ast_tvdiff_ms(ast_tvnow(), pu->start);
- if (tms > pu->parkingtime) {
- /* Stop music on hold */
- ast_moh_stop(pu->chan);
- ast_indicate(pu->chan, AST_CONTROL_UNHOLD);
- /* Get chan, exten from derived kludge */
- if (pu->peername[0]) {
- peername = ast_strdupa(pu->peername);
- cp = strrchr(peername, '-');
- if (cp)
- *cp = 0;
- con = ast_context_find(parking_con_dial);
- if (!con) {
- con = ast_context_create(NULL, parking_con_dial, registrar);
- if (!con) {
- ast_log(LOG_ERROR, "Parking dial context '%s' does not exist and unable to create\n", parking_con_dial);
- }
- }
- if (con) {
- snprintf(returnexten, sizeof(returnexten), "%s||t", peername);
- ast_add_extension2(con, 1, peername, 1, NULL, NULL, "Dial", strdup(returnexten), FREE, registrar);
- }
- ast_copy_string(pu->chan->exten, peername, sizeof(pu->chan->exten));
- ast_copy_string(pu->chan->context, parking_con_dial, sizeof(pu->chan->context));
- pu->chan->priority = 1;
-
- } else {
- /* They've been waiting too long, send them back to where they came. Theoretically they
- should have their original extensions and such, but we copy to be on the safe side */
- ast_copy_string(pu->chan->exten, pu->exten, sizeof(pu->chan->exten));
- ast_copy_string(pu->chan->context, pu->context, sizeof(pu->chan->context));
- pu->chan->priority = pu->priority;
- }
-
- manager_event(EVENT_FLAG_CALL, "ParkedCallTimeOut",
- "Exten: %d\r\n"
- "Channel: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- ,pu->parkingnum, pu->chan->name
- ,(pu->chan->cid.cid_num ? pu->chan->cid.cid_num : "<unknown>")
- ,(pu->chan->cid.cid_name ? pu->chan->cid.cid_name : "<unknown>")
- );
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Timeout for %s parked on %d. Returning to %s,%s,%d\n", pu->chan->name, pu->parkingnum, pu->chan->context, pu->chan->exten, pu->chan->priority);
- /* Start up the PBX, or hang them up */
- if (ast_pbx_start(pu->chan)) {
- ast_log(LOG_WARNING, "Unable to restart the PBX for user on '%s', hanging them up...\n", pu->chan->name);
- ast_hangup(pu->chan);
- }
- /* And take them out of the parking lot */
- if (pl)
- pl->next = pu->next;
- else
- parkinglot = pu->next;
- pt = pu;
- pu = pu->next;
- con = ast_context_find(parking_con);
- if (con) {
- snprintf(exten, sizeof(exten), "%d", pt->parkingnum);
- if (ast_context_remove_extension2(con, exten, 1, NULL))
- ast_log(LOG_WARNING, "Whoa, failed to remove the extension!\n");
- } else
- ast_log(LOG_WARNING, "Whoa, no parking context?\n");
- free(pt);
- } else {
- for (x = 0; x < AST_MAX_FDS; x++) {
- if ((pu->chan->fds[x] > -1) && (FD_ISSET(pu->chan->fds[x], &rfds) || FD_ISSET(pu->chan->fds[x], &efds))) {
- if (FD_ISSET(pu->chan->fds[x], &efds))
- ast_set_flag(pu->chan, AST_FLAG_EXCEPTION);
- else
- ast_clear_flag(pu->chan, AST_FLAG_EXCEPTION);
- pu->chan->fdno = x;
- /* See if they need servicing */
- f = ast_read(pu->chan);
- if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP))) {
- if (f)
- ast_frfree(f);
- manager_event(EVENT_FLAG_CALL, "ParkedCallGiveUp",
- "Exten: %d\r\n"
- "Channel: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- ,pu->parkingnum, pu->chan->name
- ,(pu->chan->cid.cid_num ? pu->chan->cid.cid_num : "<unknown>")
- ,(pu->chan->cid.cid_name ? pu->chan->cid.cid_name : "<unknown>")
- );
-
- /* There's a problem, hang them up*/
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "%s got tired of being parked\n", pu->chan->name);
- ast_hangup(pu->chan);
- /* And take them out of the parking lot */
- if (pl)
- pl->next = pu->next;
- else
- parkinglot = pu->next;
- pt = pu;
- pu = pu->next;
- con = ast_context_find(parking_con);
- if (con) {
- snprintf(exten, sizeof(exten), "%d", pt->parkingnum);
- if (ast_context_remove_extension2(con, exten, 1, NULL))
- ast_log(LOG_WARNING, "Whoa, failed to remove the extension!\n");
- } else
- ast_log(LOG_WARNING, "Whoa, no parking context?\n");
- free(pt);
- break;
- } else {
- /* XXX Maybe we could do something with packets, like dial "0" for operator or something XXX */
- ast_frfree(f);
- if (pu->moh_trys < 3 && !pu->chan->generatordata) {
- ast_log(LOG_DEBUG, "MOH on parked call stopped by outside source. Restarting.\n");
- ast_moh_start(pu->chan, NULL);
- pu->moh_trys++;
- }
- goto std; /* XXX Ick: jumping into an else statement??? XXX */
- }
- }
- }
- if (x >= AST_MAX_FDS) {
-std: for (x=0; x<AST_MAX_FDS; x++) {
- /* Keep this one for next one */
- if (pu->chan->fds[x] > -1) {
- FD_SET(pu->chan->fds[x], &nrfds);
- FD_SET(pu->chan->fds[x], &nefds);
- if (pu->chan->fds[x] > max)
- max = pu->chan->fds[x];
- }
- }
- /* Keep track of our longest wait */
- if ((tms < ms) || (ms < 0))
- ms = tms;
- pl = pu;
- pu = pu->next;
- }
- }
- }
- ast_mutex_unlock(&parking_lock);
- rfds = nrfds;
- efds = nefds;
- tv = ast_samp2tv(ms, 1000);
- /* Wait for something to happen */
- ast_select(max + 1, &rfds, NULL, &efds, (ms > -1) ? &tv : NULL);
- pthread_testcancel();
- }
- return NULL; /* Never reached */
-}
-
-static int park_call_exec(struct ast_channel *chan, void *data)
-{
- /* Data is unused at the moment but could contain a parking
- lot context eventually */
- int res=0;
- struct localuser *u;
- LOCAL_USER_ADD(u);
- /* Setup the exten/priority to be s/1 since we don't know
- where this call should return */
- strcpy(chan->exten, "s");
- chan->priority = 1;
- if (chan->_state != AST_STATE_UP)
- res = ast_answer(chan);
- if (!res)
- res = ast_safe_sleep(chan, 1000);
- if (!res)
- res = ast_park_call(chan, chan, 0, NULL);
- LOCAL_USER_REMOVE(u);
- if (!res)
- res = AST_PBX_KEEPALIVE;
- return res;
-}
-
-static int park_exec(struct ast_channel *chan, void *data)
-{
- int res=0;
- struct localuser *u;
- struct ast_channel *peer=NULL;
- struct parkeduser *pu, *pl=NULL;
- char exten[AST_MAX_EXTENSION];
- struct ast_context *con;
- int park;
- int dres;
- struct ast_bridge_config config;
-
- if (!data) {
- ast_log(LOG_WARNING, "Park requires an argument (extension number)\n");
- return -1;
- }
- LOCAL_USER_ADD(u);
- park = atoi((char *)data);
- ast_mutex_lock(&parking_lock);
- pu = parkinglot;
- while(pu) {
- if (pu->parkingnum == park) {
- if (pl)
- pl->next = pu->next;
- else
- parkinglot = pu->next;
- break;
- }
- pl = pu;
- pu = pu->next;
- }
- ast_mutex_unlock(&parking_lock);
- if (pu) {
- peer = pu->chan;
- con = ast_context_find(parking_con);
- if (con) {
- snprintf(exten, sizeof(exten), "%d", pu->parkingnum);
- if (ast_context_remove_extension2(con, exten, 1, NULL))
- ast_log(LOG_WARNING, "Whoa, failed to remove the extension!\n");
- } else
- ast_log(LOG_WARNING, "Whoa, no parking context?\n");
-
- manager_event(EVENT_FLAG_CALL, "UnParkedCall",
- "Exten: %d\r\n"
- "Channel: %s\r\n"
- "From: %s\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- ,pu->parkingnum, pu->chan->name, chan->name
- ,(pu->chan->cid.cid_num ? pu->chan->cid.cid_num : "<unknown>")
- ,(pu->chan->cid.cid_name ? pu->chan->cid.cid_name : "<unknown>")
- );
-
- free(pu);
- }
- /* JK02: it helps to answer the channel if not already up */
- if (chan->_state != AST_STATE_UP) {
- ast_answer(chan);
- }
-
- if (peer) {
- /* Play a courtesy beep in the calling channel to prefix the bridge connecting */
- if (!ast_strlen_zero(courtesytone)) {
- if (!ast_streamfile(chan, courtesytone, chan->language)) {
- if (ast_waitstream(chan, "") < 0) {
- ast_log(LOG_WARNING, "Failed to play courtesy tone!\n");
- ast_hangup(peer);
- return -1;
- }
- }
- }
-
- ast_moh_stop(peer);
- ast_indicate(peer, AST_CONTROL_UNHOLD);
- res = ast_channel_make_compatible(chan, peer);
- if (res < 0) {
- ast_log(LOG_WARNING, "Could not make channels %s and %s compatible for bridge\n", chan->name, peer->name);
- ast_hangup(peer);
- return -1;
- }
- /* This runs sorta backwards, since we give the incoming channel control, as if it
- were the person called. */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %s connected to parked call %d\n", chan->name, park);
-
- memset(&config, 0, sizeof(struct ast_bridge_config));
- ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
- ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
- config.timelimit = 0;
- config.play_warning = 0;
- config.warning_freq = 0;
- config.warning_sound=NULL;
- res = ast_bridge_call(chan, peer, &config);
-
- /* Simulate the PBX hanging up */
- if (res != AST_PBX_NO_HANGUP_PEER)
- ast_hangup(peer);
- return res;
- } else {
- /* XXX Play a message XXX */
- dres = ast_streamfile(chan, "pbx-invalidpark", chan->language);
- if (!dres)
- dres = ast_waitstream(chan, "");
- else {
- ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", "pbx-invalidpark", chan->name);
- dres = 0;
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %s tried to talk to nonexistent parked call %d\n", chan->name, park);
- res = -1;
- }
- LOCAL_USER_REMOVE(u);
- return res;
-}
-
-static int handle_showfeatures(int fd, int argc, char *argv[])
-{
- int i;
- int fcount;
- struct ast_call_feature *feature;
- char format[] = "%-25s %-7s %-7s\n";
-
- ast_cli(fd, format, "Builtin Feature", "Default", "Current");
- ast_cli(fd, format, "---------------", "-------", "-------");
-
- ast_cli(fd, format, "Pickup", "*8", ast_pickup_ext()); /* default hardcoded above, so we'll hardcode it here */
-
- fcount = sizeof(builtin_features) / sizeof(builtin_features[0]);
-
- for (i = 0; i < fcount; i++)
- {
- ast_cli(fd, format, builtin_features[i].fname, builtin_features[i].default_exten, builtin_features[i].exten);
- }
- ast_cli(fd, "\n");
- ast_cli(fd, format, "Dynamic Feature", "Default", "Current");
- ast_cli(fd, format, "---------------", "-------", "-------");
- if (AST_LIST_EMPTY(&feature_list)) {
- ast_cli(fd, "(none)\n");
- }
- else {
- AST_LIST_LOCK(&feature_list);
- AST_LIST_TRAVERSE(&feature_list, feature, feature_entry) {
- ast_cli(fd, format, feature->sname, "no def", feature->exten);
- }
- AST_LIST_UNLOCK(&feature_list);
- }
- ast_cli(fd, "\nCall parking\n");
- ast_cli(fd, "------------\n");
- ast_cli(fd,"%-20s: %s\n", "Parking extension", parking_ext);
- ast_cli(fd,"%-20s: %s\n", "Parking context", parking_con);
- ast_cli(fd,"%-20s: %d-%d\n", "Parked call extensions", parking_start, parking_stop);
- ast_cli(fd,"\n");
-
- return RESULT_SUCCESS;
-}
-
-static char showfeatures_help[] =
-"Usage: show features\n"
-" Lists currently configured features.\n";
-
-static struct ast_cli_entry showfeatures =
-{ { "show", "features", NULL }, handle_showfeatures, "Lists configured features", showfeatures_help };
-
-static int handle_parkedcalls(int fd, int argc, char *argv[])
-{
- struct parkeduser *cur;
- int numparked = 0;
-
- ast_cli(fd, "%4s %25s (%-15s %-12s %-4s) %-6s \n", "Num", "Channel"
- , "Context", "Extension", "Pri", "Timeout");
-
- ast_mutex_lock(&parking_lock);
-
- cur = parkinglot;
- while(cur) {
- ast_cli(fd, "%4d %25s (%-15s %-12s %-4d) %6lds\n"
- ,cur->parkingnum, cur->chan->name, cur->context, cur->exten
- ,cur->priority, cur->start.tv_sec + (cur->parkingtime/1000) - time(NULL));
-
- cur = cur->next;
- numparked++;
- }
- ast_cli(fd, "%d parked call%s.\n", numparked, (numparked != 1) ? "s" : "");
-
- ast_mutex_unlock(&parking_lock);
-
- return RESULT_SUCCESS;
-}
-
-static char showparked_help[] =
-"Usage: show parkedcalls\n"
-" Lists currently parked calls.\n";
-
-static struct ast_cli_entry showparked =
-{ { "show", "parkedcalls", NULL }, handle_parkedcalls, "Lists parked calls", showparked_help };
-
-/* Dump lot status */
-static int manager_parking_status( struct mansession *s, struct message *m )
-{
- struct parkeduser *cur;
- char *id = astman_get_header(m,"ActionID");
- char idText[256] = "";
-
- if (!ast_strlen_zero(id))
- snprintf(idText,256,"ActionID: %s\r\n",id);
-
- astman_send_ack(s, m, "Parked calls will follow");
-
- ast_mutex_lock(&parking_lock);
-
- cur=parkinglot;
- while(cur) {
- ast_cli(s->fd, "Event: ParkedCall\r\n"
- "Exten: %d\r\n"
- "Channel: %s\r\n"
- "Timeout: %ld\r\n"
- "CallerID: %s\r\n"
- "CallerIDName: %s\r\n"
- "%s"
- "\r\n"
- ,cur->parkingnum, cur->chan->name
- ,(long)cur->start.tv_sec + (long)(cur->parkingtime/1000) - (long)time(NULL)
- ,(cur->chan->cid.cid_num ? cur->chan->cid.cid_num : "")
- ,(cur->chan->cid.cid_name ? cur->chan->cid.cid_name : "")
- ,idText);
-
- cur = cur->next;
- }
-
- ast_cli(s->fd,
- "Event: ParkedCallsComplete\r\n"
- "%s"
- "\r\n",idText);
-
- ast_mutex_unlock(&parking_lock);
-
- return RESULT_SUCCESS;
-}
-
-
-int ast_pickup_call(struct ast_channel *chan)
-{
- struct ast_channel *cur = NULL;
- int res = -1;
-
- while ( (cur = ast_channel_walk_locked(cur)) != NULL) {
- if (!cur->pbx &&
- (cur != chan) &&
- (chan->pickupgroup & cur->callgroup) &&
- ((cur->_state == AST_STATE_RINGING) ||
- (cur->_state == AST_STATE_RING))) {
- break;
- }
- ast_mutex_unlock(&cur->lock);
- }
- if (cur) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Call pickup on chan '%s' by '%s'\n",cur->name, chan->name);
- res = ast_answer(chan);
- if (res)
- ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
- res = ast_queue_control(chan, AST_CONTROL_ANSWER);
- if (res)
- ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name);
- res = ast_channel_masquerade(cur, chan);
- if (res)
- ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, cur->name); /* Done */
- ast_mutex_unlock(&cur->lock);
- } else {
- if (option_debug)
- ast_log(LOG_DEBUG, "No call pickup possible...\n");
- }
- return res;
-}
-
-static int load_config(void)
-{
- int start = 0, end = 0;
- struct ast_context *con = NULL;
- struct ast_config *cfg = NULL;
- struct ast_variable *var = NULL;
- char old_parking_ext[AST_MAX_EXTENSION];
- char old_parking_con[AST_MAX_EXTENSION] = "";
-
- if (!ast_strlen_zero(parking_con)) {
- strcpy(old_parking_ext, parking_ext);
- strcpy(old_parking_con, parking_con);
- }
-
- /* Reset to defaults */
- strcpy(parking_con, "parkedcalls");
- strcpy(parking_con_dial, "park-dial");
- strcpy(parking_ext, "700");
- strcpy(pickup_ext, "*8");
- courtesytone[0] = '\0';
- strcpy(xfersound, "beep");
- strcpy(xferfailsound, "pbx-invalid");
- parking_start = 701;
- parking_stop = 750;
- parkfindnext = 0;
-
- transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT;
- featuredigittimeout = DEFAULT_FEATURE_DIGIT_TIMEOUT;
-
- cfg = ast_config_load("features.conf");
- if (!cfg) {
- cfg = ast_config_load("parking.conf");
- if (cfg)
- ast_log(LOG_NOTICE, "parking.conf is deprecated in favor of 'features.conf'. Please rename it.\n");
- }
- if (cfg) {
- var = ast_variable_browse(cfg, "general");
- while(var) {
- if (!strcasecmp(var->name, "parkext")) {
- ast_copy_string(parking_ext, var->value, sizeof(parking_ext));
- } else if (!strcasecmp(var->name, "context")) {
- ast_copy_string(parking_con, var->value, sizeof(parking_con));
- } else if (!strcasecmp(var->name, "parkingtime")) {
- if ((sscanf(var->value, "%d", &parkingtime) != 1) || (parkingtime < 1)) {
- ast_log(LOG_WARNING, "%s is not a valid parkingtime\n", var->value);
- parkingtime = DEFAULT_PARK_TIME;
- } else
- parkingtime = parkingtime * 1000;
- } else if (!strcasecmp(var->name, "parkpos")) {
- if (sscanf(var->value, "%d-%d", &start, &end) != 2) {
- ast_log(LOG_WARNING, "Format for parking positions is a-b, where a and b are numbers at line %d of parking.conf\n", var->lineno);
- } else {
- parking_start = start;
- parking_stop = end;
- }
- } else if (!strcasecmp(var->name, "findslot")) {
- parkfindnext = (!strcasecmp(var->value, "next"));
- } else if (!strcasecmp(var->name, "adsipark")) {
- adsipark = ast_true(var->value);
- } else if (!strcasecmp(var->name, "transferdigittimeout")) {
- if ((sscanf(var->value, "%d", &transferdigittimeout) != 1) || (transferdigittimeout < 1)) {
- ast_log(LOG_WARNING, "%s is not a valid transferdigittimeout\n", var->value);
- transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT;
- } else
- transferdigittimeout = transferdigittimeout * 1000;
- } else if (!strcasecmp(var->name, "featuredigittimeout")) {
- if ((sscanf(var->value, "%d", &featuredigittimeout) != 1) || (featuredigittimeout < 1)) {
- ast_log(LOG_WARNING, "%s is not a valid featuredigittimeout\n", var->value);
- featuredigittimeout = DEFAULT_FEATURE_DIGIT_TIMEOUT;
- }
- } else if (!strcasecmp(var->name, "courtesytone")) {
- ast_copy_string(courtesytone, var->value, sizeof(courtesytone));
- } else if (!strcasecmp(var->name, "xfersound")) {
- ast_copy_string(xfersound, var->value, sizeof(xfersound));
- } else if (!strcasecmp(var->name, "xferfailsound")) {
- ast_copy_string(xferfailsound, var->value, sizeof(xferfailsound));
- } else if (!strcasecmp(var->name, "pickupexten")) {
- ast_copy_string(pickup_ext, var->value, sizeof(pickup_ext));
- }
- var = var->next;
- }
-
- unmap_features();
- var = ast_variable_browse(cfg, "featuremap");
- while(var) {
- if (remap_feature(var->name, var->value))
- ast_log(LOG_NOTICE, "Unknown feature '%s'\n", var->name);
- var = var->next;
- }
-
- /* Map a key combination to an application*/
- ast_unregister_features();
- var = ast_variable_browse(cfg, "applicationmap");
- while(var) {
- char *tmp_val=strdup(var->value);
- char *exten, *party=NULL, *app=NULL, *app_args=NULL;
-
- if (!tmp_val) {
- ast_log(LOG_ERROR, "res_features: strdup failed");
- continue;
- }
-
-
- exten=strsep(&tmp_val,",");
- if (exten) party=strsep(&tmp_val,",");
- if (party) app=strsep(&tmp_val,",");
-
- if (app) app_args=strsep(&tmp_val,",");
-
- if (!(app && strlen(app)) || !(exten && strlen(exten)) || !(party && strlen(party)) || !(var->name && strlen(var->name))) {
- ast_log(LOG_NOTICE, "Please check the feature Mapping Syntax, either extension, name, or app aren't provided %s %s %s %s\n",app,exten,party,var->name);
- free(tmp_val);
- var = var->next;
- continue;
- }
-
- {
- struct ast_call_feature *feature=find_feature(var->name);
- int mallocd=0;
-
- if (!feature) {
- feature=malloc(sizeof(struct ast_call_feature));
- mallocd=1;
- }
- if (!feature) {
- ast_log(LOG_NOTICE, "Malloc failed at feature mapping\n");
- free(tmp_val);
- var = var->next;
- continue;
- }
-
- memset(feature,0,sizeof(struct ast_call_feature));
- ast_copy_string(feature->sname,var->name,FEATURE_SNAME_LEN);
- ast_copy_string(feature->app,app,FEATURE_APP_LEN);
- ast_copy_string(feature->exten, exten,FEATURE_EXTEN_LEN);
- free(tmp_val);
-
- if (app_args)
- ast_copy_string(feature->app_args,app_args,FEATURE_APP_ARGS_LEN);
-
- ast_copy_string(feature->exten, exten,sizeof(feature->exten));
- feature->operation=feature_exec_app;
- ast_set_flag(feature,AST_FEATURE_FLAG_NEEDSDTMF);
-
- if (!strcasecmp(party,"caller"))
- ast_set_flag(feature,AST_FEATURE_FLAG_CALLER);
- else if (!strcasecmp(party, "callee"))
- ast_set_flag(feature,AST_FEATURE_FLAG_CALLEE);
- else {
- ast_log(LOG_NOTICE, "Invalid party specification for feature '%s', must be caller, or callee\n", var->name);
- var = var->next;
- continue;
- }
-
- ast_register_feature(feature);
-
- if (option_verbose >=1) ast_verbose(VERBOSE_PREFIX_2 "Mapping Feature '%s' to app '%s' with code '%s'\n", var->name, app, exten);
- }
- var = var->next;
- }
- }
- ast_config_destroy(cfg);
-
- /* Remove the old parking extension */
- if (!ast_strlen_zero(old_parking_con) && (con = ast_context_find(old_parking_con))) {
- ast_context_remove_extension2(con, old_parking_ext, 1, registrar);
- ast_log(LOG_DEBUG, "Removed old parking extension %s@%s\n", old_parking_ext, old_parking_con);
- }
-
- if (!(con = ast_context_find(parking_con))) {
- if (!(con = ast_context_create(NULL, parking_con, registrar))) {
- ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", parking_con);
- return -1;
- }
- }
- return ast_add_extension2(con, 1, ast_parking_ext(), 1, NULL, NULL, parkcall, strdup(""), FREE, registrar);
-}
-
-int reload(void) {
- return load_config();
-}
-
-int load_module(void)
-{
- int res;
-
- AST_LIST_HEAD_INIT(&feature_list);
- memset(parking_ext, 0, sizeof(parking_ext));
- memset(parking_con, 0, sizeof(parking_con));
-
- if ((res = load_config()))
- return res;
- ast_cli_register(&showparked);
- ast_cli_register(&showfeatures);
- ast_pthread_create(&parking_thread, NULL, do_parking_thread, NULL);
- res = ast_register_application(parkedcall, park_exec, synopsis, descrip);
- if (!res)
- res = ast_register_application(parkcall, park_call_exec, synopsis2, descrip2);
- if (!res) {
- ast_manager_register("ParkedCalls", 0, manager_parking_status, "List parked calls" );
- }
- return res;
-}
-
-
-int unload_module(void)
-{
- STANDARD_HANGUP_LOCALUSERS;
-
- ast_manager_unregister("ParkedCalls");
- ast_cli_unregister(&showfeatures);
- ast_cli_unregister(&showparked);
- ast_unregister_application(parkcall);
- return ast_unregister_application(parkedcall);
-}
-
-char *description(void)
-{
- return "Call Features Resource";
-}
-
-int usecount(void)
-{
- /* Never allow parking to be unloaded because it will
- unresolve needed symbols in the dialer */
-#if 0
- int res;
- STANDARD_USECOUNT(res);
- return res;
-#else
- return 1;
-#endif
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/res/res_indications.c b/1.2-netsec/res/res_indications.c
deleted file mode 100644
index 65ac3a9ba..000000000
--- a/1.2-netsec/res/res_indications.c
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2002, Pauline Middelink
- *
- *
- * 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 res_indications.c
- *
- * \brief Load the indications
- *
- * \author Pauline Middelink <middelink@polyware.nl>
- *
- * Load the country specific dialtones into the asterisk PBX.
- */
-
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/cli.h"
-#include "asterisk/logger.h"
-#include "asterisk/config.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/indications.h"
-
-
-/* Globals */
-static const char dtext[] = "Indications Configuration";
-static const char config[] = "indications.conf";
-
-/*
- * Help for commands provided by this module ...
- */
-static char help_add_indication[] =
-"Usage: indication add <country> <indication> \"<tonelist>\"\n"
-" Add the given indication to the country.\n";
-
-static char help_remove_indication[] =
-"Usage: indication remove <country> <indication>\n"
-" Remove the given indication from the country.\n";
-
-static char help_show_indications[] =
-"Usage: show indications [<country> ...]\n"
-" Show either a condensed for of all country/indications, or the\n"
-" indications for the specified countries.\n";
-
-char *playtones_desc=
-"PlayTones(arg): Plays a tone list. Execution will continue with the next step immediately,\n"
-"while the tones continue to play.\n"
-"Arg is either the tone name defined in the indications.conf configuration file, or a directly\n"
-"specified list of frequencies and durations.\n"
-"See the sample indications.conf for a description of the specification of a tonelist.\n\n"
-"Use the StopPlayTones application to stop the tones playing. \n";
-
-/*
- * Implementation of functions provided by this module
- */
-
-/*
- * ADD INDICATION command stuff
- */
-static int handle_add_indication(int fd, int argc, char *argv[])
-{
- struct tone_zone *tz;
- int created_country = 0;
- if (argc != 5) return RESULT_SHOWUSAGE;
-
- tz = ast_get_indication_zone(argv[2]);
- if (!tz) {
- /* country does not exist, create it */
- ast_log(LOG_NOTICE, "Country '%s' does not exist, creating it.\n",argv[2]);
-
- tz = malloc(sizeof(struct tone_zone));
- if (!tz) {
- ast_log(LOG_WARNING, "Out of memory\n");
- return -1;
- }
- memset(tz,0,sizeof(struct tone_zone));
- ast_copy_string(tz->country,argv[2],sizeof(tz->country));
- if (ast_register_indication_country(tz)) {
- ast_log(LOG_WARNING, "Unable to register new country\n");
- free(tz);
- return -1;
- }
- created_country = 1;
- }
- if (ast_register_indication(tz,argv[3],argv[4])) {
- ast_log(LOG_WARNING, "Unable to register indication %s/%s\n",argv[2],argv[3]);
- if (created_country)
- ast_unregister_indication_country(argv[2]);
- return -1;
- }
- return 0;
-}
-
-/*
- * REMOVE INDICATION command stuff
- */
-static int handle_remove_indication(int fd, int argc, char *argv[])
-{
- struct tone_zone *tz;
- if (argc != 3 && argc != 4) return RESULT_SHOWUSAGE;
-
- if (argc == 3) {
- /* remove entiry country */
- if (ast_unregister_indication_country(argv[2])) {
- ast_log(LOG_WARNING, "Unable to unregister indication country %s\n",argv[2]);
- return -1;
- }
- return 0;
- }
-
- tz = ast_get_indication_zone(argv[2]);
- if (!tz) {
- ast_log(LOG_WARNING, "Unable to unregister indication %s/%s, country does not exists\n",argv[2],argv[3]);
- return -1;
- }
- if (ast_unregister_indication(tz,argv[3])) {
- ast_log(LOG_WARNING, "Unable to unregister indication %s/%s\n",argv[2],argv[3]);
- return -1;
- }
- return 0;
-}
-
-/*
- * SHOW INDICATIONS command stuff
- */
-static int handle_show_indications(int fd, int argc, char *argv[])
-{
- struct tone_zone *tz;
- char buf[256];
- int found_country = 0;
-
- if (ast_mutex_lock(&tzlock)) {
- ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
- return 0;
- }
- if (argc == 2) {
- /* no arguments, show a list of countries */
- ast_cli(fd,"Country Alias Description\n"
- "===========================\n");
- for (tz=tone_zones; tz; tz=tz->next) {
- ast_cli(fd,"%-7.7s %-7.7s %s\n", tz->country, tz->alias, tz->description);
- }
- ast_mutex_unlock(&tzlock);
- return 0;
- }
- /* there was a request for specific country(ies), lets humor them */
- for (tz=tone_zones; tz; tz=tz->next) {
- int i,j;
- for (i=2; i<argc; i++) {
- if (strcasecmp(tz->country,argv[i])==0 &&
- !tz->alias[0]) {
- struct tone_zone_sound* ts;
- if (!found_country) {
- found_country = 1;
- ast_cli(fd,"Country Indication PlayList\n"
- "=====================================\n");
- }
- j = snprintf(buf,sizeof(buf),"%-7.7s %-15.15s ",tz->country,"<ringcadence>");
- for (i=0; i<tz->nrringcadence; i++) {
- j += snprintf(buf+j,sizeof(buf)-j,"%d,",tz->ringcadence[i]);
- }
- if (tz->nrringcadence) j--;
- ast_copy_string(buf+j,"\n",sizeof(buf)-j);
- ast_cli(fd,buf);
- for (ts=tz->tones; ts; ts=ts->next)
- ast_cli(fd,"%-7.7s %-15.15s %s\n",tz->country,ts->name,ts->data);
- break;
- }
- }
- }
- if (!found_country)
- ast_cli(fd,"No countries matched your criteria.\n");
- ast_mutex_unlock(&tzlock);
- return -1;
-}
-
-/*
- * Playtones command stuff
- */
-static int handle_playtones(struct ast_channel *chan, void *data)
-{
- struct tone_zone_sound *ts;
- int res;
-
- if (!data || !((char*)data)[0]) {
- ast_log(LOG_NOTICE,"Nothing to play\n");
- return -1;
- }
- ts = ast_get_indication_tone(chan->zone, (const char*)data);
- if (ts && ts->data[0])
- res = ast_playtones_start(chan, 0, ts->data, 0);
- else
- res = ast_playtones_start(chan, 0, (const char*)data, 0);
- if (res)
- ast_log(LOG_NOTICE,"Unable to start playtones\n");
- return res;
-}
-
-/*
- * StopPlaylist command stuff
- */
-static int handle_stopplaytones(struct ast_channel *chan, void *data)
-{
- ast_playtones_stop(chan);
- return 0;
-}
-
-/*
- * Load module stuff
- */
-static int ind_load_module(void)
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- char *cxt;
- char *c;
- struct tone_zone *tones;
- const char *country = NULL;
-
- /* that the following cast is needed, is yuk! */
- /* yup, checked it out. It is NOT written to. */
- cfg = ast_config_load((char *)config);
- if (!cfg)
- return 0;
-
- /* Use existing config to populate the Indication table */
- cxt = ast_category_browse(cfg, NULL);
- while(cxt) {
- /* All categories but "general" are considered countries */
- if (!strcasecmp(cxt, "general")) {
- cxt = ast_category_browse(cfg, cxt);
- continue;
- }
- tones = malloc(sizeof(struct tone_zone));
- if (!tones) {
- ast_log(LOG_WARNING,"Out of memory\n");
- ast_config_destroy(cfg);
- return -1;
- }
- memset(tones,0,sizeof(struct tone_zone));
- ast_copy_string(tones->country,cxt,sizeof(tones->country));
-
- v = ast_variable_browse(cfg, cxt);
- while(v) {
- if (!strcasecmp(v->name, "description")) {
- ast_copy_string(tones->description, v->value, sizeof(tones->description));
- } else if ((!strcasecmp(v->name,"ringcadence"))||(!strcasecmp(v->name,"ringcadance"))) {
- char *ring,*rings = ast_strdupa(v->value);
- c = rings;
- ring = strsep(&c,",");
- while (ring) {
- int *tmp, val;
- if (!isdigit(ring[0]) || (val=atoi(ring))==-1) {
- ast_log(LOG_WARNING,"Invalid ringcadence given '%s' at line %d.\n",ring,v->lineno);
- ring = strsep(&c,",");
- continue;
- }
- tmp = realloc(tones->ringcadence,(tones->nrringcadence+1)*sizeof(int));
- if (!tmp) {
- ast_log(LOG_WARNING, "Out of memory\n");
- ast_config_destroy(cfg);
- return -1;
- }
- tones->ringcadence = tmp;
- tmp[tones->nrringcadence] = val;
- tones->nrringcadence++;
- /* next item */
- ring = strsep(&c,",");
- }
- } else if (!strcasecmp(v->name,"alias")) {
- char *countries = ast_strdupa(v->value);
- c = countries;
- country = strsep(&c,",");
- while (country) {
- struct tone_zone* azone = malloc(sizeof(struct tone_zone));
- if (!azone) {
- ast_log(LOG_WARNING,"Out of memory\n");
- ast_config_destroy(cfg);
- return -1;
- }
- memset(azone,0,sizeof(struct tone_zone));
- ast_copy_string(azone->country, country, sizeof(azone->country));
- ast_copy_string(azone->alias, cxt, sizeof(azone->alias));
- if (ast_register_indication_country(azone)) {
- ast_log(LOG_WARNING, "Unable to register indication alias at line %d.\n",v->lineno);
- free(tones);
- }
- /* next item */
- country = strsep(&c,",");
- }
- } else {
- /* add tone to country */
- struct tone_zone_sound *ps,*ts;
- for (ps=NULL,ts=tones->tones; ts; ps=ts, ts=ts->next) {
- if (strcasecmp(v->name,ts->name)==0) {
- /* already there */
- ast_log(LOG_NOTICE,"Duplicate entry '%s', skipped.\n",v->name);
- goto out;
- }
- }
- /* not there, add it to the back */
- ts = malloc(sizeof(struct tone_zone_sound));
- if (!ts) {
- ast_log(LOG_WARNING, "Out of memory\n");
- ast_config_destroy(cfg);
- return -1;
- }
- ts->next = NULL;
- ts->name = strdup(v->name);
- ts->data = strdup(v->value);
- if (ps)
- ps->next = ts;
- else
- tones->tones = ts;
- }
-out: v = v->next;
- }
- if (tones->description[0] || tones->alias[0] || tones->tones) {
- if (ast_register_indication_country(tones)) {
- ast_log(LOG_WARNING, "Unable to register indication at line %d.\n",v->lineno);
- free(tones);
- }
- } else free(tones);
-
- cxt = ast_category_browse(cfg, cxt);
- }
-
- /* determine which country is the default */
- country = ast_variable_retrieve(cfg,"general","country");
- if (!country || !*country || ast_set_indication_country(country))
- ast_log(LOG_WARNING,"Unable to set the default country (for indication tones)\n");
-
- ast_config_destroy(cfg);
- return 0;
-}
-
-/*
- * CLI entries for commands provided by this module
- */
-static struct ast_cli_entry add_indication_cli =
- { { "indication", "add", NULL }, handle_add_indication,
- "Add the given indication to the country", help_add_indication,
- NULL };
-
-static struct ast_cli_entry remove_indication_cli =
- { { "indication", "remove", NULL }, handle_remove_indication,
- "Remove the given indication from the country", help_remove_indication,
- NULL };
-
-static struct ast_cli_entry show_indications_cli =
- { { "show", "indications", NULL }, handle_show_indications,
- "Show a list of all country/indications", help_show_indications,
- NULL };
-
-/*
- * Standard module functions ...
- */
-int unload_module(void)
-{
- /* remove the registed indications... */
- ast_unregister_indication_country(NULL);
-
- /* and the functions */
- ast_cli_unregister(&add_indication_cli);
- ast_cli_unregister(&remove_indication_cli);
- ast_cli_unregister(&show_indications_cli);
- ast_unregister_application("PlayTones");
- ast_unregister_application("StopPlayTones");
- return 0;
-}
-
-
-int load_module(void)
-{
- if (ind_load_module()) return -1;
-
- ast_cli_register(&add_indication_cli);
- ast_cli_register(&remove_indication_cli);
- ast_cli_register(&show_indications_cli);
- ast_register_application("PlayTones", handle_playtones, "Play a tone list", playtones_desc);
- ast_register_application("StopPlayTones", handle_stopplaytones, "Stop playing a tone list","Stop playing a tone list");
-
- return 0;
-}
-
-int reload(void)
-{
- /* remove the registed indications... */
- ast_unregister_indication_country(NULL);
-
- return ind_load_module();
-}
-
-char *description(void)
-{
- /* that the following cast is needed, is yuk! */
- return (char*)dtext;
-}
-
-int usecount(void)
-{
- return 0;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/res/res_monitor.c b/1.2-netsec/res/res_monitor.c
deleted file mode 100644
index adc6144b5..000000000
--- a/1.2-netsec/res/res_monitor.c
+++ /dev/null
@@ -1,592 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief PBX channel monitoring
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <libgen.h> /* dirname() */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/file.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/manager.h"
-#include "asterisk/cli.h"
-#include "asterisk/monitor.h"
-#include "asterisk/app.h"
-#include "asterisk/utils.h"
-#include "asterisk/config.h"
-
-AST_MUTEX_DEFINE_STATIC(monitorlock);
-
-static unsigned long seq = 0;
-
-static char *monitor_synopsis = "Monitor a channel";
-
-static char *monitor_descrip = "Monitor([file_format[:urlbase]|[fname_base]|[options]]):\n"
-"Used to start monitoring a channel. The channel's input and output\n"
-"voice packets are logged to files until the channel hangs up or\n"
-"monitoring is stopped by the StopMonitor application.\n"
-" file_format optional, if not set, defaults to \"wav\"\n"
-" fname_base if set, changes the filename used to the one specified.\n"
-" options:\n"
-" m - when the recording ends mix the two leg files into one and\n"
-" delete the two leg files. If the variable MONITOR_EXEC is set, the\n"
-" application referenced in it will be executed instead of\n"
-" soxmix and the raw leg files will NOT be deleted automatically.\n"
-" soxmix or MONITOR_EXEC is handed 3 arguments, the two leg files\n"
-" and a target mixed file name which is the same as the leg file names\n"
-" only without the in/out designator.\n"
-" If MONITOR_EXEC_ARGS is set, the contents will be passed on as\n"
-" additional arguements to MONITOR_EXEC\n"
-" Both MONITOR_EXEC and the Mix flag can be set from the\n"
-" administrator interface\n"
-"\n"
-" b - Don't begin recording unless a call is bridged to another channel\n"
-"\nReturns -1 if monitor files can't be opened or if the channel is already\n"
-"monitored, otherwise 0.\n"
-;
-
-static char *stopmonitor_synopsis = "Stop monitoring a channel";
-
-static char *stopmonitor_descrip = "StopMonitor\n"
- "Stops monitoring a channel. Has no effect if the channel is not monitored\n";
-
-static char *changemonitor_synopsis = "Change monitoring filename of a channel";
-
-static char *changemonitor_descrip = "ChangeMonitor(filename_base)\n"
- "Changes monitoring filename of a channel. Has no effect if the channel is not monitored\n"
- "The argument is the new filename base to use for monitoring this channel.\n";
-
-/* Start monitoring a channel */
-int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
- const char *fname_base, int need_lock)
-{
- int res = 0;
- char tmp[256];
-
- if (need_lock) {
- if (ast_mutex_lock(&chan->lock)) {
- ast_log(LOG_WARNING, "Unable to lock channel\n");
- return -1;
- }
- }
-
- if (!(chan->monitor)) {
- struct ast_channel_monitor *monitor;
- char *channel_name, *p;
-
- /* Create monitoring directory if needed */
- if (mkdir(ast_config_AST_MONITOR_DIR, 0770) < 0) {
- if (errno != EEXIST) {
- ast_log(LOG_WARNING, "Unable to create audio monitor directory: %s\n",
- strerror(errno));
- }
- }
-
- monitor = malloc(sizeof(struct ast_channel_monitor));
- if (!monitor) {
- if (need_lock)
- ast_mutex_unlock(&chan->lock);
- return -1;
- }
- memset(monitor, 0, sizeof(struct ast_channel_monitor));
-
- /* Determine file names */
- if (!ast_strlen_zero(fname_base)) {
- int directory = strchr(fname_base, '/') ? 1 : 0;
- /* try creating the directory just in case it doesn't exist */
- if (directory) {
- char *name = strdup(fname_base);
- snprintf(tmp, sizeof(tmp), "mkdir -p \"%s\"",dirname(name));
- free(name);
- ast_safe_system(tmp);
- }
- snprintf(monitor->read_filename, FILENAME_MAX, "%s/%s-in",
- directory ? "" : ast_config_AST_MONITOR_DIR, fname_base);
- snprintf(monitor->write_filename, FILENAME_MAX, "%s/%s-out",
- directory ? "" : ast_config_AST_MONITOR_DIR, fname_base);
- ast_copy_string(monitor->filename_base, fname_base, sizeof(monitor->filename_base));
- } else {
- ast_mutex_lock(&monitorlock);
- snprintf(monitor->read_filename, FILENAME_MAX, "%s/audio-in-%ld",
- ast_config_AST_MONITOR_DIR, seq);
- snprintf(monitor->write_filename, FILENAME_MAX, "%s/audio-out-%ld",
- ast_config_AST_MONITOR_DIR, seq);
- seq++;
- ast_mutex_unlock(&monitorlock);
-
- if((channel_name = ast_strdupa(chan->name))) {
- while((p = strchr(channel_name, '/'))) {
- *p = '-';
- }
- snprintf(monitor->filename_base, FILENAME_MAX, "%s/%d-%s",
- ast_config_AST_MONITOR_DIR, (int)time(NULL),channel_name);
- monitor->filename_changed = 1;
- } else {
- ast_log(LOG_ERROR,"Failed to allocate Memory\n");
- return -1;
- }
- }
-
- monitor->stop = ast_monitor_stop;
-
- /* Determine file format */
- if (!ast_strlen_zero(format_spec)) {
- monitor->format = strdup(format_spec);
- } else {
- monitor->format = strdup("wav");
- }
-
- /* open files */
- if (ast_fileexists(monitor->read_filename, NULL, NULL) > 0) {
- ast_filedelete(monitor->read_filename, NULL);
- }
- if (!(monitor->read_stream = ast_writefile(monitor->read_filename,
- monitor->format, NULL,
- O_CREAT|O_TRUNC|O_WRONLY, 0, 0644))) {
- ast_log(LOG_WARNING, "Could not create file %s\n",
- monitor->read_filename);
- free(monitor);
- ast_mutex_unlock(&chan->lock);
- return -1;
- }
- if (ast_fileexists(monitor->write_filename, NULL, NULL) > 0) {
- ast_filedelete(monitor->write_filename, NULL);
- }
- if (!(monitor->write_stream = ast_writefile(monitor->write_filename,
- monitor->format, NULL,
- O_CREAT|O_TRUNC|O_WRONLY, 0, 0644))) {
- ast_log(LOG_WARNING, "Could not create file %s\n",
- monitor->write_filename);
- ast_closestream(monitor->read_stream);
- free(monitor);
- ast_mutex_unlock(&chan->lock);
- return -1;
- }
- chan->monitor = monitor;
- /* so we know this call has been monitored in case we need to bill for it or something */
- pbx_builtin_setvar_helper(chan, "__MONITORED","true");
- } else {
- ast_log(LOG_DEBUG,"Cannot start monitoring %s, already monitored\n",
- chan->name);
- res = -1;
- }
-
- if (need_lock) {
- ast_mutex_unlock(&chan->lock);
- }
- return res;
-}
-
-/* Stop monitoring a channel */
-int ast_monitor_stop(struct ast_channel *chan, int need_lock)
-{
- char *execute, *execute_args;
- int delfiles = 0;
-
- if (need_lock) {
- if (ast_mutex_lock(&chan->lock)) {
- ast_log(LOG_WARNING, "Unable to lock channel\n");
- return -1;
- }
- }
-
- if (chan->monitor) {
- char filename[ FILENAME_MAX ];
-
- if (chan->monitor->read_stream) {
- ast_closestream(chan->monitor->read_stream);
- }
- if (chan->monitor->write_stream) {
- ast_closestream(chan->monitor->write_stream);
- }
-
- if (chan->monitor->filename_changed && !ast_strlen_zero(chan->monitor->filename_base)) {
- if (ast_fileexists(chan->monitor->read_filename,NULL,NULL) > 0) {
- snprintf(filename, FILENAME_MAX, "%s-in", chan->monitor->filename_base);
- if (ast_fileexists(filename, NULL, NULL) > 0) {
- ast_filedelete(filename, NULL);
- }
- ast_filerename(chan->monitor->read_filename, filename, chan->monitor->format);
- } else {
- ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->read_filename);
- }
-
- if (ast_fileexists(chan->monitor->write_filename,NULL,NULL) > 0) {
- snprintf(filename, FILENAME_MAX, "%s-out", chan->monitor->filename_base);
- if (ast_fileexists(filename, NULL, NULL) > 0) {
- ast_filedelete(filename, NULL);
- }
- ast_filerename(chan->monitor->write_filename, filename, chan->monitor->format);
- } else {
- ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->write_filename);
- }
- }
-
- if (chan->monitor->joinfiles && !ast_strlen_zero(chan->monitor->filename_base)) {
- char tmp[1024];
- char tmp2[1024];
- char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format;
- char *name = chan->monitor->filename_base;
- int directory = strchr(name, '/') ? 1 : 0;
- char *dir = directory ? "" : ast_config_AST_MONITOR_DIR;
-
- /* Set the execute application */
- execute = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC");
- if (ast_strlen_zero(execute)) {
- execute = "nice -n 19 soxmix";
- delfiles = 1;
- }
- execute_args = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC_ARGS");
- if (ast_strlen_zero(execute_args)) {
- execute_args = "";
- }
-
- snprintf(tmp, sizeof(tmp), "%s \"%s/%s-in.%s\" \"%s/%s-out.%s\" \"%s/%s.%s\" %s &", execute, dir, name, format, dir, name, format, dir, name, format,execute_args);
- if (delfiles) {
- snprintf(tmp2,sizeof(tmp2), "( %s& rm -f \"%s/%s-\"* ) &",tmp, dir ,name); /* remove legs when done mixing */
- ast_copy_string(tmp, tmp2, sizeof(tmp));
- }
- ast_log(LOG_DEBUG,"monitor executing %s\n",tmp);
- if (ast_safe_system(tmp) == -1)
- ast_log(LOG_WARNING, "Execute of %s failed.\n",tmp);
- }
-
- free(chan->monitor->format);
- free(chan->monitor);
- chan->monitor = NULL;
- }
-
- if (need_lock)
- ast_mutex_unlock(&chan->lock);
- return 0;
-}
-
-/* Change monitoring filename of a channel */
-int ast_monitor_change_fname(struct ast_channel *chan, const char *fname_base, int need_lock)
-{
- char tmp[256];
- if (ast_strlen_zero(fname_base)) {
- ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to null", chan->name);
- return -1;
- }
-
- if (need_lock) {
- if (ast_mutex_lock(&chan->lock)) {
- ast_log(LOG_WARNING, "Unable to lock channel\n");
- return -1;
- }
- }
-
- if (chan->monitor) {
- int directory = strchr(fname_base, '/') ? 1 : 0;
- /* try creating the directory just in case it doesn't exist */
- if (directory) {
- char *name = strdup(fname_base);
- snprintf(tmp, sizeof(tmp), "mkdir -p %s",dirname(name));
- free(name);
- ast_safe_system(tmp);
- }
-
- snprintf(chan->monitor->filename_base, FILENAME_MAX, "%s/%s", directory ? "" : ast_config_AST_MONITOR_DIR, fname_base);
- } else {
- ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to %s, monitoring not started\n", chan->name, fname_base);
- }
-
- if (need_lock)
- ast_mutex_unlock(&chan->lock);
-
- return 0;
-}
-
-static int start_monitor_exec(struct ast_channel *chan, void *data)
-{
- char *arg = NULL;
- char *format = NULL;
- char *fname_base = NULL;
- char *options = NULL;
- char *delay = NULL;
- char *urlprefix = NULL;
- char tmp[256];
- int joinfiles = 0;
- int waitforbridge = 0;
- int res = 0;
-
- /* Parse arguments. */
- if (!ast_strlen_zero((char*)data)) {
- arg = ast_strdupa((char*)data);
- format = arg;
- fname_base = strchr(arg, '|');
- if (fname_base) {
- *fname_base = 0;
- fname_base++;
- if ((options = strchr(fname_base, '|'))) {
- *options = 0;
- options++;
- if (strchr(options, 'm'))
- joinfiles = 1;
- if (strchr(options, 'b'))
- waitforbridge = 1;
- }
- }
- arg = strchr(format,':');
- if (arg) {
- *arg++ = 0;
- urlprefix = arg;
- }
- }
- if (urlprefix) {
- snprintf(tmp,sizeof(tmp) - 1,"%s/%s.%s",urlprefix,fname_base,
- ((strcmp(format,"gsm")) ? "wav" : "gsm"));
- if (!chan->cdr)
- chan->cdr = ast_cdr_alloc();
- ast_cdr_setuserfield(chan, tmp);
- }
- if (waitforbridge) {
- /* We must remove the "b" option if listed. In principle none of
- the following could give NULL results, but we check just to
- be pedantic. Reconstructing with checks for 'm' option does not
- work if we end up adding more options than 'm' in the future. */
- delay = ast_strdupa((char*)data);
- if (delay) {
- options = strrchr(delay, '|');
- if (options) {
- arg = strchr(options, 'b');
- if (arg) {
- *arg = 'X';
- pbx_builtin_setvar_helper(chan,"AUTO_MONITOR",delay);
- }
- }
- }
- return 0;
- }
-
- res = ast_monitor_start(chan, format, fname_base, 1);
- if (res < 0)
- res = ast_monitor_change_fname(chan, fname_base, 1);
- ast_monitor_setjoinfiles(chan, joinfiles);
-
- return res;
-}
-
-static int stop_monitor_exec(struct ast_channel *chan, void *data)
-{
- return ast_monitor_stop(chan, 1);
-}
-
-static int change_monitor_exec(struct ast_channel *chan, void *data)
-{
- return ast_monitor_change_fname(chan, (const char*)data, 1);
-}
-
-static char start_monitor_action_help[] =
-"Description: The 'Monitor' action may be used to record the audio on a\n"
-" specified channel. The following parameters may be used to control\n"
-" this:\n"
-" Channel - Required. Used to specify the channel to record.\n"
-" File - Optional. Is the name of the file created in the\n"
-" monitor spool directory. Defaults to the same name\n"
-" as the channel (with slashes replaced with dashes).\n"
-" Format - Optional. Is the audio recording format. Defaults\n"
-" to \"wav\".\n"
-" Mix - Optional. Boolean parameter as to whether to mix\n"
-" the input and output channels together after the\n"
-" recording is finished.\n";
-
-static int start_monitor_action(struct mansession *s, struct message *m)
-{
- struct ast_channel *c = NULL;
- char *name = astman_get_header(m, "Channel");
- char *fname = astman_get_header(m, "File");
- char *format = astman_get_header(m, "Format");
- char *mix = astman_get_header(m, "Mix");
- char *d;
-
- if (ast_strlen_zero(name)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
-
- if (ast_strlen_zero(fname)) {
- /* No filename base specified, default to channel name as per CLI */
- fname = malloc (FILENAME_MAX);
- if (!fname) {
- astman_send_error(s, m, "Could not start monitoring channel");
- ast_mutex_unlock(&c->lock);
- return 0;
- }
- memset(fname, 0, FILENAME_MAX);
- ast_copy_string(fname, c->name, FILENAME_MAX);
- /* Channels have the format technology/channel_name - have to replace that / */
- if ((d=strchr(fname, '/'))) *d='-';
- }
-
- if (ast_monitor_start(c, format, fname, 1)) {
- if (ast_monitor_change_fname(c, fname, 1)) {
- astman_send_error(s, m, "Could not start monitoring channel");
- ast_mutex_unlock(&c->lock);
- return 0;
- }
- }
-
- if (ast_true(mix)) {
- ast_monitor_setjoinfiles(c, 1);
- }
-
- ast_mutex_unlock(&c->lock);
- astman_send_ack(s, m, "Started monitoring channel");
- return 0;
-}
-
-static char stop_monitor_action_help[] =
-"Description: The 'StopMonitor' action may be used to end a previously\n"
-" started 'Monitor' action. The only parameter is 'Channel', the name\n"
-" of the channel monitored.\n";
-
-static int stop_monitor_action(struct mansession *s, struct message *m)
-{
- struct ast_channel *c = NULL;
- char *name = astman_get_header(m, "Channel");
- int res;
- if (ast_strlen_zero(name)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- res = ast_monitor_stop(c, 1);
- ast_mutex_unlock(&c->lock);
- if (res) {
- astman_send_error(s, m, "Could not stop monitoring channel");
- return 0;
- }
- astman_send_ack(s, m, "Stopped monitoring channel");
- return 0;
-}
-
-static char change_monitor_action_help[] =
-"Description: The 'ChangeMonitor' action may be used to change the file\n"
-" started by a previous 'Monitor' action. The following parameters may\n"
-" be used to control this:\n"
-" Channel - Required. Used to specify the channel to record.\n"
-" File - Required. Is the new name of the file created in the\n"
-" monitor spool directory.\n";
-
-static int change_monitor_action(struct mansession *s, struct message *m)
-{
- struct ast_channel *c = NULL;
- char *name = astman_get_header(m, "Channel");
- char *fname = astman_get_header(m, "File");
- if (ast_strlen_zero(name)) {
- astman_send_error(s, m, "No channel specified");
- return 0;
- }
- if (ast_strlen_zero(fname)) {
- astman_send_error(s, m, "No filename specified");
- return 0;
- }
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
- astman_send_error(s, m, "No such channel");
- return 0;
- }
- if (ast_monitor_change_fname(c, fname, 1)) {
- astman_send_error(s, m, "Could not change monitored filename of channel");
- ast_mutex_unlock(&c->lock);
- return 0;
- }
- ast_mutex_unlock(&c->lock);
- astman_send_ack(s, m, "Changed monitor filename");
- return 0;
-}
-
-void ast_monitor_setjoinfiles(struct ast_channel *chan, int turnon)
-{
- if (chan->monitor)
- chan->monitor->joinfiles = turnon;
-}
-
-int load_module(void)
-{
- ast_register_application("Monitor", start_monitor_exec, monitor_synopsis, monitor_descrip);
- ast_register_application("StopMonitor", stop_monitor_exec, stopmonitor_synopsis, stopmonitor_descrip);
- ast_register_application("ChangeMonitor", change_monitor_exec, changemonitor_synopsis, changemonitor_descrip);
- ast_manager_register2("Monitor", EVENT_FLAG_CALL, start_monitor_action, monitor_synopsis, start_monitor_action_help);
- ast_manager_register2("StopMonitor", EVENT_FLAG_CALL, stop_monitor_action, stopmonitor_synopsis, stop_monitor_action_help);
- ast_manager_register2("ChangeMonitor", EVENT_FLAG_CALL, change_monitor_action, changemonitor_synopsis, change_monitor_action_help);
-
- return 0;
-}
-
-int unload_module(void)
-{
- ast_unregister_application("Monitor");
- ast_unregister_application("StopMonitor");
- ast_unregister_application("ChangeMonitor");
- ast_manager_unregister("Monitor");
- ast_manager_unregister("StopMonitor");
- ast_manager_unregister("ChangeMonitor");
- return 0;
-}
-
-char *description(void)
-{
- return "Call Monitoring Resource";
-}
-
-int usecount(void)
-{
- /* Never allow monitor to be unloaded because it will
- unresolve needed symbols in the channel */
-#if 0
- int res;
- STANDARD_USECOUNT(res);
- return res;
-#else
- return 1;
-#endif
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/res/res_musiconhold.c b/1.2-netsec/res/res_musiconhold.c
deleted file mode 100644
index 2a27dcec8..000000000
--- a/1.2-netsec/res/res_musiconhold.c
+++ /dev/null
@@ -1,1237 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Routines implementing music on hold
- *
- * \arg See also \ref Config_moh
- *
- */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/signal.h>
-#include <netinet/in.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#ifdef ZAPATA_MOH
-#ifdef __linux__
-#include <linux/zaptel.h>
-#else
-#include <zaptel.h>
-#endif /* __linux__ */
-#endif
-#include <unistd.h>
-#include <sys/ioctl.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/module.h"
-#include "asterisk/translate.h"
-#include "asterisk/say.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/config.h"
-#include "asterisk/utils.h"
-#include "asterisk/cli.h"
-
-#define MAX_MOHFILES 512
-#define MAX_MOHFILE_LEN 128
-
-static char *app0 = "MusicOnHold";
-static char *app1 = "WaitMusicOnHold";
-static char *app2 = "SetMusicOnHold";
-static char *app3 = "StartMusicOnHold";
-static char *app4 = "StopMusicOnHold";
-
-static char *synopsis0 = "Play Music On Hold indefinitely";
-static char *synopsis1 = "Wait, playing Music On Hold";
-static char *synopsis2 = "Set default Music On Hold class";
-static char *synopsis3 = "Play Music On Hold";
-static char *synopsis4 = "Stop Playing Music On Hold";
-
-static char *descrip0 = "MusicOnHold(class): "
-"Plays hold music specified by class. If omitted, the default\n"
-"music source for the channel will be used. Set the default \n"
-"class with the SetMusicOnHold() application.\n"
-"Returns -1 on hangup.\n"
-"Never returns otherwise.\n";
-
-static char *descrip1 = "WaitMusicOnHold(delay): "
-"Plays hold music specified number of seconds. Returns 0 when\n"
-"done, or -1 on hangup. If no hold music is available, the delay will\n"
-"still occur with no sound.\n";
-
-static char *descrip2 = "SetMusicOnHold(class): "
-"Sets the default class for music on hold for a given channel. When\n"
-"music on hold is activated, this class will be used to select which\n"
-"music is played.\n";
-
-static char *descrip3 = "StartMusicOnHold(class): "
-"Starts playing music on hold, uses default music class for channel.\n"
-"Starts playing music specified by class. If omitted, the default\n"
-"music source for the channel will be used. Always returns 0.\n";
-
-static char *descrip4 = "StopMusicOnHold: "
-"Stops playing music on hold.\n";
-
-static int respawn_time = 20;
-
-struct moh_files_state {
- struct mohclass *class;
- int origwfmt;
- int samples;
- int sample_queue;
- unsigned char pos;
- unsigned char save_pos;
-};
-
-#define MOH_QUIET (1 << 0)
-#define MOH_SINGLE (1 << 1)
-#define MOH_CUSTOM (1 << 2)
-#define MOH_RANDOMIZE (1 << 3)
-
-struct mohclass {
- char name[MAX_MUSICCLASS];
- char dir[256];
- char args[256];
- char mode[80];
- char filearray[MAX_MOHFILES][MAX_MOHFILE_LEN];
- unsigned int flags;
- int total_files;
- int format;
- int pid; /* PID of mpg123 */
- time_t start;
- pthread_t thread;
- struct mohdata *members;
- /* Source of audio */
- int srcfd;
- /* FD for timing source */
- int pseudofd;
- struct mohclass *next;
-};
-
-struct mohdata {
- int pipe[2];
- int origwfmt;
- struct mohclass *parent;
- struct mohdata *next;
-};
-
-static struct mohclass *mohclasses;
-
-AST_MUTEX_DEFINE_STATIC(moh_lock);
-
-#define LOCAL_MPG_123 "/usr/local/bin/mpg123"
-#define MPG_123 "/usr/bin/mpg123"
-#define MAX_MP3S 256
-
-
-static void ast_moh_free_class(struct mohclass **class)
-{
- struct mohdata *members, *mtmp;
-
- members = (*class)->members;
- while(members) {
- mtmp = members;
- members = members->next;
- free(mtmp);
- }
- free(*class);
- *class = NULL;
-}
-
-
-static void moh_files_release(struct ast_channel *chan, void *data)
-{
- struct moh_files_state *state = chan->music_state;
-
- if (chan && state) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Stopped music on hold on %s\n", chan->name);
-
- if (state->origwfmt && ast_set_write_format(chan, state->origwfmt)) {
- ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, state->origwfmt);
- }
- state->save_pos = state->pos + 1;
- }
-}
-
-
-static int ast_moh_files_next(struct ast_channel *chan)
-{
- struct moh_files_state *state = chan->music_state;
- int tries;
-
- if (state->save_pos) {
- state->pos = state->save_pos - 1;
- state->save_pos = 0;
- } else {
- /* Try 20 times to find something good */
- for (tries=0;tries < 20;tries++) {
- state->samples = 0;
- if (chan->stream) {
- ast_closestream(chan->stream);
- chan->stream = NULL;
- state->pos++;
- }
-
- if (ast_test_flag(state->class, MOH_RANDOMIZE))
- state->pos = rand();
-
- /* check to see if this file's format can be opened */
- if (ast_fileexists(state->class->filearray[state->pos], NULL, NULL) != -1)
- break;
-
- }
- }
-
- state->pos = state->pos % state->class->total_files;
-
- if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
- ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name);
- return -1;
- }
- if (!ast_openstream_full(chan, state->class->filearray[state->pos], chan->language, 1)) {
- ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", state->class->filearray[state->pos], strerror(errno));
- state->pos++;
- return -1;
- }
-
- if (option_debug)
- ast_log(LOG_DEBUG, "%s Opened file %d '%s'\n", chan->name, state->pos, state->class->filearray[state->pos]);
-
- if (state->samples)
- ast_seekstream(chan->stream, state->samples, SEEK_SET);
-
- return 0;
-}
-
-
-static struct ast_frame *moh_files_readframe(struct ast_channel *chan)
-{
- struct ast_frame *f = NULL;
-
- if (!(chan->stream && (f = ast_readframe(chan->stream)))) {
- if (!ast_moh_files_next(chan))
- f = ast_readframe(chan->stream);
- }
-
- return f;
-}
-
-static int moh_files_generator(struct ast_channel *chan, void *data, int len, int samples)
-{
- struct moh_files_state *state = chan->music_state;
- struct ast_frame *f = NULL;
- int res = 0;
-
- state->sample_queue += samples;
-
- while (state->sample_queue > 0) {
- if ((f = moh_files_readframe(chan))) {
- state->samples += f->samples;
- res = ast_write(chan, f);
- state->sample_queue -= f->samples;
- ast_frfree(f);
- if (res < 0) {
- ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror(errno));
- return -1;
- }
- } else
- return -1;
- }
- return res;
-}
-
-
-static void *moh_files_alloc(struct ast_channel *chan, void *params)
-{
- struct moh_files_state *state;
- struct mohclass *class = params;
- int allocated = 0;
-
- if (!chan->music_state && (state = malloc(sizeof(struct moh_files_state)))) {
- chan->music_state = state;
- allocated = 1;
- } else
- state = chan->music_state;
-
- if (state) {
- if (allocated || state->class != class) {
- /* initialize */
- memset(state, 0, sizeof(struct moh_files_state));
- state->class = class;
- }
-
- state->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(chan->music_state);
- chan->music_state = NULL;
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Started music on hold, class '%s', on %s\n", class->name, chan->name);
- }
- }
-
- return chan->music_state;
-}
-
-static struct ast_generator moh_file_stream =
-{
- alloc: moh_files_alloc,
- release: moh_files_release,
- generate: moh_files_generator,
-};
-
-static int spawn_mp3(struct mohclass *class)
-{
- int fds[2];
- int files = 0;
- char fns[MAX_MP3S][80];
- char *argv[MAX_MP3S + 50];
- char xargs[256];
- char *argptr;
- int argc = 0;
- DIR *dir = NULL;
- struct dirent *de;
-
-
- if (!strcasecmp(class->dir, "nodir")) {
- files = 1;
- } else {
- dir = opendir(class->dir);
- if (!dir && !strstr(class->dir,"http://") && !strstr(class->dir,"HTTP://")) {
- ast_log(LOG_WARNING, "%s is not a valid directory\n", class->dir);
- return -1;
- }
- }
-
- if (!ast_test_flag(class, MOH_CUSTOM)) {
- argv[argc++] = "mpg123";
- argv[argc++] = "-q";
- argv[argc++] = "-s";
- argv[argc++] = "--mono";
- argv[argc++] = "-r";
- argv[argc++] = "8000";
-
- if (!ast_test_flag(class, MOH_SINGLE)) {
- argv[argc++] = "-b";
- argv[argc++] = "2048";
- }
-
- argv[argc++] = "-f";
-
- if (ast_test_flag(class, MOH_QUIET))
- argv[argc++] = "4096";
- else
- argv[argc++] = "8192";
-
- /* Look for extra arguments and add them to the list */
- strncpy(xargs, class->args, sizeof(xargs) - 1);
- argptr = xargs;
- while (!ast_strlen_zero(argptr)) {
- argv[argc++] = argptr;
- argptr = strchr(argptr, ',');
- if (argptr) {
- *argptr = '\0';
- argptr++;
- }
- }
- } else {
- /* Format arguments for argv vector */
- strncpy(xargs, class->args, sizeof(xargs) - 1);
- argptr = xargs;
- while (!ast_strlen_zero(argptr)) {
- argv[argc++] = argptr;
- argptr = strchr(argptr, ' ');
- if (argptr) {
- *argptr = '\0';
- argptr++;
- }
- }
- }
-
-
- if (strstr(class->dir,"http://") || strstr(class->dir,"HTTP://")) {
- strncpy(fns[files], class->dir, sizeof(fns[files]) - 1);
- argv[argc++] = fns[files];
- files++;
- } else if (dir) {
- while ((de = readdir(dir)) && (files < MAX_MP3S)) {
- if ((strlen(de->d_name) > 3) &&
- ((ast_test_flag(class, MOH_CUSTOM) &&
- (!strcasecmp(de->d_name + strlen(de->d_name) - 4, ".raw") ||
- !strcasecmp(de->d_name + strlen(de->d_name) - 4, ".sln"))) ||
- !strcasecmp(de->d_name + strlen(de->d_name) - 4, ".mp3"))) {
- strncpy(fns[files], de->d_name, sizeof(fns[files]) - 1);
- argv[argc++] = fns[files];
- files++;
- }
- }
- }
- argv[argc] = NULL;
- if (dir) {
- closedir(dir);
- }
- if (pipe(fds)) {
- ast_log(LOG_WARNING, "Pipe failed\n");
- return -1;
- }
-#if 0
- printf("%d files total, %d args total\n", files, argc);
- {
- int x;
- for (x=0;argv[x];x++)
- printf("arg%d: %s\n", x, argv[x]);
- }
-#endif
- if (!files) {
- ast_log(LOG_WARNING, "Found no files in '%s'\n", class->dir);
- close(fds[0]);
- close(fds[1]);
- return -1;
- }
- if (time(NULL) - class->start < respawn_time) {
- sleep(respawn_time - (time(NULL) - class->start));
- }
- time(&class->start);
- class->pid = fork();
- if (class->pid < 0) {
- close(fds[0]);
- close(fds[1]);
- ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
- return -1;
- }
- if (!class->pid) {
- int x;
- close(fds[0]);
- /* Stdout goes to pipe */
- dup2(fds[1], STDOUT_FILENO);
- /* Close unused file descriptors */
- for (x=3;x<8192;x++) {
- if (-1 != fcntl(x, F_GETFL)) {
- close(x);
- }
- }
- /* Child */
- chdir(class->dir);
- if (ast_test_flag(class, MOH_CUSTOM)) {
- execv(argv[0], argv);
- } else {
- /* Default install is /usr/local/bin */
- execv(LOCAL_MPG_123, argv);
- /* Many places have it in /usr/bin */
- execv(MPG_123, argv);
- /* Check PATH as a last-ditch effort */
- execvp("mpg123", argv);
- }
- ast_log(LOG_WARNING, "Exec failed: %s\n", strerror(errno));
- close(fds[1]);
- exit(1);
- } else {
- /* Parent */
- close(fds[1]);
- }
- return fds[0];
-}
-
-static void *monmp3thread(void *data)
-{
-#define MOH_MS_INTERVAL 100
-
- struct mohclass *class = data;
- struct mohdata *moh;
- char buf[8192];
- short sbuf[8192];
- int res, res2;
- int len;
- struct timeval tv, tv_tmp;
-
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- for(;/* ever */;) {
- /* Spawn mp3 player if it's not there */
- if (class->srcfd < 0) {
- if ((class->srcfd = spawn_mp3(class)) < 0) {
- ast_log(LOG_WARNING, "Unable to spawn mp3player\n");
- /* Try again later */
- sleep(500);
- }
- }
- if (class->pseudofd > -1) {
- /* Pause some amount of time */
- res = read(class->pseudofd, buf, sizeof(buf));
- } else {
- long delta;
- /* Reliable sleep */
- tv_tmp = ast_tvnow();
- if (ast_tvzero(tv))
- tv = tv_tmp;
- delta = ast_tvdiff_ms(tv_tmp, tv);
- if (delta < MOH_MS_INTERVAL) { /* too early */
- tv = ast_tvadd(tv, ast_samp2tv(MOH_MS_INTERVAL, 1000)); /* next deadline */
- usleep(1000 * (MOH_MS_INTERVAL - delta));
- } else {
- ast_log(LOG_NOTICE, "Request to schedule in the past?!?!\n");
- tv = tv_tmp;
- }
- res = 8 * MOH_MS_INTERVAL; /* 8 samples per millisecond */
- }
- if (!class->members)
- continue;
- /* Read mp3 audio */
- len = ast_codec_get_len(class->format, res);
-
- if ((res2 = read(class->srcfd, sbuf, len)) != len) {
- if (!res2) {
- close(class->srcfd);
- class->srcfd = -1;
- if (class->pid) {
- kill(class->pid, SIGKILL);
- class->pid = 0;
- }
- } else
- ast_log(LOG_DEBUG, "Read %d bytes of audio while expecting %d\n", res2, len);
- continue;
- }
- ast_mutex_lock(&moh_lock);
- moh = class->members;
- while (moh) {
- /* Write data */
- if ((res = write(moh->pipe[1], sbuf, res2)) != res2)
- if (option_debug)
- ast_log(LOG_DEBUG, "Only wrote %d of %d bytes to pipe\n", res, res2);
- moh = moh->next;
- }
- ast_mutex_unlock(&moh_lock);
- }
- return NULL;
-}
-
-static int moh0_exec(struct ast_channel *chan, void *data)
-{
- if (ast_moh_start(chan, data)) {
- ast_log(LOG_WARNING, "Unable to start music on hold (class '%s') on channel %s\n", (char *)data, chan->name);
- return -1;
- }
- while (!ast_safe_sleep(chan, 10000));
- ast_moh_stop(chan);
- return -1;
-}
-
-static int moh1_exec(struct ast_channel *chan, void *data)
-{
- int res;
- if (!data || !atoi(data)) {
- ast_log(LOG_WARNING, "WaitMusicOnHold requires an argument (number of seconds to wait)\n");
- return -1;
- }
- if (ast_moh_start(chan, NULL)) {
- ast_log(LOG_WARNING, "Unable to start music on hold for %d seconds on channel %s\n", atoi(data), chan->name);
- return -1;
- }
- res = ast_safe_sleep(chan, atoi(data) * 1000);
- ast_moh_stop(chan);
- return res;
-}
-
-static int moh2_exec(struct ast_channel *chan, void *data)
-{
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "SetMusicOnHold requires an argument (class)\n");
- return -1;
- }
- strncpy(chan->musicclass, data, sizeof(chan->musicclass) - 1);
- return 0;
-}
-
-static int moh3_exec(struct ast_channel *chan, void *data)
-{
- char *class = NULL;
- if (data && strlen(data))
- class = data;
- if (ast_moh_start(chan, class))
- ast_log(LOG_NOTICE, "Unable to start music on hold class '%s' on channel %s\n", class ? class : "default", chan->name);
-
- return 0;
-}
-
-static int moh4_exec(struct ast_channel *chan, void *data)
-{
- ast_moh_stop(chan);
-
- return 0;
-}
-
-static struct mohclass *get_mohbyname(char *name)
-{
- struct mohclass *moh;
- moh = mohclasses;
- while (moh) {
- if (!strcasecmp(name, moh->name))
- return moh;
- moh = moh->next;
- }
- return NULL;
-}
-
-static struct mohdata *mohalloc(struct mohclass *cl)
-{
- struct mohdata *moh;
- long flags;
- moh = malloc(sizeof(struct mohdata));
- if (!moh)
- return NULL;
- memset(moh, 0, sizeof(struct mohdata));
- if (pipe(moh->pipe)) {
- ast_log(LOG_WARNING, "Failed to create pipe: %s\n", strerror(errno));
- free(moh);
- return NULL;
- }
- /* Make entirely non-blocking */
- flags = fcntl(moh->pipe[0], F_GETFL);
- fcntl(moh->pipe[0], F_SETFL, flags | O_NONBLOCK);
- flags = fcntl(moh->pipe[1], F_GETFL);
- fcntl(moh->pipe[1], F_SETFL, flags | O_NONBLOCK);
- moh->parent = cl;
- moh->next = cl->members;
- cl->members = moh;
- return moh;
-}
-
-static void moh_release(struct ast_channel *chan, void *data)
-{
- struct mohdata *moh = data, *prev, *cur;
- int oldwfmt;
- ast_mutex_lock(&moh_lock);
- /* Unlink */
- prev = NULL;
- cur = moh->parent->members;
- while (cur) {
- if (cur == moh) {
- if (prev)
- prev->next = cur->next;
- else
- moh->parent->members = cur->next;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- ast_mutex_unlock(&moh_lock);
- close(moh->pipe[0]);
- close(moh->pipe[1]);
- oldwfmt = moh->origwfmt;
- free(moh);
- if (chan) {
- if (oldwfmt && ast_set_write_format(chan, oldwfmt))
- ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", chan->name, ast_getformatname(oldwfmt));
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Stopped music on hold on %s\n", chan->name);
- }
-}
-
-static void *moh_alloc(struct ast_channel *chan, void *params)
-{
- struct mohdata *res;
- struct mohclass *class = params;
-
- res = mohalloc(class);
- if (res) {
- res->origwfmt = chan->writeformat;
- if (ast_set_write_format(chan, class->format)) {
- ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", chan->name, ast_codec2str(class->format));
- moh_release(NULL, res);
- res = NULL;
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Started music on hold, class '%s', on channel '%s'\n", class->name, chan->name);
- }
- return res;
-}
-
-static int moh_generate(struct ast_channel *chan, void *data, int len, int samples)
-{
- struct ast_frame f;
- struct mohdata *moh = data;
- short buf[1280 + AST_FRIENDLY_OFFSET / 2];
- int res;
-
- if (!moh->parent->pid)
- return -1;
-
- len = ast_codec_get_len(moh->parent->format, samples);
-
- if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
- ast_log(LOG_WARNING, "Only doing %d of %d requested bytes on %s\n", (int)sizeof(buf), len, chan->name);
- len = sizeof(buf) - AST_FRIENDLY_OFFSET;
- }
- res = read(moh->pipe[0], buf + AST_FRIENDLY_OFFSET/2, len);
-#if 0
- if (res != len) {
- ast_log(LOG_WARNING, "Read only %d of %d bytes: %s\n", res, len, strerror(errno));
- }
-#endif
- if (res <= 0)
- return 0;
-
- memset(&f, 0, sizeof(f));
-
- f.frametype = AST_FRAME_VOICE;
- f.subclass = moh->parent->format;
- f.mallocd = 0;
- f.datalen = res;
- f.data = buf + AST_FRIENDLY_OFFSET / 2;
- f.offset = AST_FRIENDLY_OFFSET;
- f.samples = ast_codec_get_samples(&f);
-
- if (ast_write(chan, &f) < 0) {
- ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-static struct ast_generator mohgen =
-{
- alloc: moh_alloc,
- release: moh_release,
- generate: moh_generate,
-};
-
-static int moh_scan_files(struct mohclass *class) {
-
- DIR *files_DIR;
- struct dirent *files_dirent;
- char path[512];
- char filepath[MAX_MOHFILE_LEN];
- char *ext;
- struct stat statbuf;
- int dirnamelen;
- int i;
-
- files_DIR = opendir(class->dir);
- if (!files_DIR) {
- ast_log(LOG_WARNING, "Cannot open dir %s or dir does not exist", class->dir);
- return -1;
- }
-
- class->total_files = 0;
- dirnamelen = strlen(class->dir) + 2;
- getcwd(path, 512);
- chdir(class->dir);
- memset(class->filearray, 0, MAX_MOHFILES*MAX_MOHFILE_LEN);
- while ((files_dirent = readdir(files_DIR))) {
- if ((strlen(files_dirent->d_name) < 4) || ((strlen(files_dirent->d_name) + dirnamelen) >= MAX_MOHFILE_LEN))
- continue;
-
- snprintf(filepath, MAX_MOHFILE_LEN, "%s/%s", class->dir, files_dirent->d_name);
-
- if (stat(filepath, &statbuf))
- continue;
-
- if (!S_ISREG(statbuf.st_mode))
- continue;
-
- if ((ext = strrchr(filepath, '.'))) {
- *ext = '\0';
- ext++;
- }
-
- /* if the file is present in multiple formats, ensure we only put it into the list once */
- for (i = 0; i < class->total_files; i++)
- if (!strcmp(filepath, class->filearray[i]))
- break;
-
- if (i == class->total_files)
- strcpy(class->filearray[class->total_files++], filepath);
- }
-
- closedir(files_DIR);
- chdir(path);
- return class->total_files;
-}
-
-static int moh_register(struct mohclass *moh, int reload)
-{
-#ifdef ZAPATA_MOH
- int x;
-#endif
- ast_mutex_lock(&moh_lock);
- if (get_mohbyname(moh->name)) {
- if (reload) {
- ast_log(LOG_DEBUG, "Music on Hold class '%s' left alone from initial load.\n", moh->name);
- } else {
- ast_log(LOG_WARNING, "Music on Hold class '%s' already exists\n", moh->name);
- }
- free(moh);
- ast_mutex_unlock(&moh_lock);
- return -1;
- }
- ast_mutex_unlock(&moh_lock);
-
- time(&moh->start);
- moh->start -= respawn_time;
-
- if (!strcasecmp(moh->mode, "files")) {
- if (!moh_scan_files(moh)) {
- ast_moh_free_class(&moh);
- return -1;
- }
- if (strchr(moh->args, 'r'))
- ast_set_flag(moh, MOH_RANDOMIZE);
- } else if (!strcasecmp(moh->mode, "mp3") || !strcasecmp(moh->mode, "mp3nb") || !strcasecmp(moh->mode, "quietmp3") || !strcasecmp(moh->mode, "quietmp3nb") || !strcasecmp(moh->mode, "httpmp3") || !strcasecmp(moh->mode, "custom")) {
-
- if (!strcasecmp(moh->mode, "custom"))
- ast_set_flag(moh, MOH_CUSTOM);
- else if (!strcasecmp(moh->mode, "mp3nb"))
- ast_set_flag(moh, MOH_SINGLE);
- else if (!strcasecmp(moh->mode, "quietmp3nb"))
- ast_set_flag(moh, MOH_SINGLE | MOH_QUIET);
- else if (!strcasecmp(moh->mode, "quietmp3"))
- ast_set_flag(moh, MOH_QUIET);
-
- moh->srcfd = -1;
-#ifdef ZAPATA_MOH
- /* Open /dev/zap/pseudo for timing... Is
- there a better, yet reliable way to do this? */
- moh->pseudofd = open("/dev/zap/pseudo", O_RDONLY);
- if (moh->pseudofd < 0) {
- ast_log(LOG_WARNING, "Unable to open pseudo channel for timing... Sound may be choppy.\n");
- } else {
- x = 320;
- ioctl(moh->pseudofd, ZT_SET_BLOCKSIZE, &x);
- }
-#else
- moh->pseudofd = -1;
-#endif
- if (ast_pthread_create(&moh->thread, NULL, monmp3thread, moh)) {
- ast_log(LOG_WARNING, "Unable to create moh...\n");
- if (moh->pseudofd > -1)
- close(moh->pseudofd);
- ast_moh_free_class(&moh);
- return -1;
- }
- } else {
- ast_log(LOG_WARNING, "Don't know how to do a mode '%s' music on hold\n", moh->mode);
- ast_moh_free_class(&moh);
- return -1;
- }
- ast_mutex_lock(&moh_lock);
- moh->next = mohclasses;
- mohclasses = moh;
- ast_mutex_unlock(&moh_lock);
- return 0;
-}
-
-static void local_ast_moh_cleanup(struct ast_channel *chan)
-{
- if (chan->music_state) {
- free(chan->music_state);
- chan->music_state = NULL;
- }
-}
-
-static int local_ast_moh_start(struct ast_channel *chan, char *class)
-{
- struct mohclass *mohclass;
-
- if (ast_strlen_zero(class))
- class = chan->musicclass;
- if (ast_strlen_zero(class))
- class = "default";
- ast_mutex_lock(&moh_lock);
- mohclass = get_mohbyname(class);
- ast_mutex_unlock(&moh_lock);
-
- if (!mohclass) {
- ast_log(LOG_WARNING, "No class: %s\n", (char *)class);
- return -1;
- }
-
- ast_set_flag(chan, AST_FLAG_MOH);
- if (mohclass->total_files) {
- return ast_activate_generator(chan, &moh_file_stream, mohclass);
- } else
- return ast_activate_generator(chan, &mohgen, mohclass);
-}
-
-static void local_ast_moh_stop(struct ast_channel *chan)
-{
- ast_clear_flag(chan, AST_FLAG_MOH);
- ast_deactivate_generator(chan);
-
- if (chan->music_state) {
- if (chan->stream) {
- ast_closestream(chan->stream);
- chan->stream = NULL;
- }
- }
-}
-
-static struct mohclass *moh_class_malloc(void)
-{
- struct mohclass *class;
-
- class = malloc(sizeof(struct mohclass));
-
- if (!class)
- return NULL;
-
- memset(class, 0, sizeof(struct mohclass));
-
- class->format = AST_FORMAT_SLINEAR;
-
- return class;
-}
-
-static int load_moh_classes(int reload)
-{
- struct ast_config *cfg;
- struct ast_variable *var;
- struct mohclass *class;
- char *data;
- char *args;
- char *cat;
- int numclasses = 0;
- static int dep_warning = 0;
-
- cfg = ast_config_load("musiconhold.conf");
-
- if (!cfg)
- return 0;
-
- cat = ast_category_browse(cfg, NULL);
- for (; cat; cat = ast_category_browse(cfg, cat)) {
- if (strcasecmp(cat, "classes") && strcasecmp(cat, "moh_files")) {
- class = moh_class_malloc();
- if (!class) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- break;
- }
- ast_copy_string(class->name, cat, sizeof(class->name));
- var = ast_variable_browse(cfg, cat);
- while (var) {
- if (!strcasecmp(var->name, "mode"))
- ast_copy_string(class->mode, var->value, sizeof(class->mode));
- else if (!strcasecmp(var->name, "directory"))
- ast_copy_string(class->dir, var->value, sizeof(class->dir));
- else if (!strcasecmp(var->name, "application"))
- ast_copy_string(class->args, var->value, sizeof(class->args));
- else if (!strcasecmp(var->name, "random"))
- ast_set2_flag(class, ast_true(var->value), MOH_RANDOMIZE);
- else if (!strcasecmp(var->name, "format")) {
- class->format = ast_getformatbyname(var->value);
- if (!class->format) {
- ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", var->value);
- class->format = AST_FORMAT_SLINEAR;
- }
- }
- var = var->next;
- }
-
- if (ast_strlen_zero(class->dir)) {
- if (!strcasecmp(class->mode, "custom")) {
- strcpy(class->dir, "nodir");
- } else {
- ast_log(LOG_WARNING, "A directory must be specified for class '%s'!\n", class->name);
- free(class);
- continue;
- }
- }
- if (ast_strlen_zero(class->mode)) {
- ast_log(LOG_WARNING, "A mode must be specified for class '%s'!\n", class->name);
- free(class);
- continue;
- }
- if (ast_strlen_zero(class->args) && !strcasecmp(class->mode, "custom")) {
- ast_log(LOG_WARNING, "An application must be specified for class '%s'!\n", class->name);
- free(class);
- continue;
- }
-
- /* Don't leak a class when it's already registered */
- moh_register(class, reload);
-
- numclasses++;
- }
- }
-
-
- /* Deprecated Old-School Configuration */
- var = ast_variable_browse(cfg, "classes");
- while (var) {
- if (!dep_warning) {
- ast_log(LOG_WARNING, "The old musiconhold.conf syntax has been deprecated! Please refer to the sample configuration for information on the new syntax.\n");
- dep_warning = 1;
- }
- data = strchr(var->value, ':');
- if (data) {
- *data++ = '\0';
- args = strchr(data, ',');
- if (args)
- *args++ = '\0';
- if (!(get_mohbyname(var->name))) {
- class = moh_class_malloc();
- if (!class) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- return numclasses;
- }
-
- ast_copy_string(class->name, var->name, sizeof(class->name));
- ast_copy_string(class->dir, data, sizeof(class->dir));
- ast_copy_string(class->mode, var->value, sizeof(class->mode));
- if (args)
- ast_copy_string(class->args, args, sizeof(class->args));
-
- moh_register(class, reload);
- numclasses++;
- }
- }
- var = var->next;
- }
- var = ast_variable_browse(cfg, "moh_files");
- while (var) {
- if (!dep_warning) {
- ast_log(LOG_WARNING, "The old musiconhold.conf syntax has been deprecated! Please refer to the sample configuration for information on the new syntax.\n");
- dep_warning = 1;
- }
- if (!(get_mohbyname(var->name))) {
- args = strchr(var->value, ',');
- if (args)
- *args++ = '\0';
- class = moh_class_malloc();
- if (!class) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- return numclasses;
- }
-
- ast_copy_string(class->name, var->name, sizeof(class->name));
- ast_copy_string(class->dir, var->value, sizeof(class->dir));
- strcpy(class->mode, "files");
- if (args)
- ast_copy_string(class->args, args, sizeof(class->args));
-
- moh_register(class, reload);
- numclasses++;
- }
- var = var->next;
- }
-
- ast_config_destroy(cfg);
-
- return numclasses;
-}
-
-static void ast_moh_destroy(void)
-{
- struct mohclass *moh, *tmp;
- char buff[8192];
- int bytes, tbytes=0, stime = 0, pid = 0;
-
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Destroying musiconhold processes\n");
- ast_mutex_lock(&moh_lock);
- moh = mohclasses;
-
- while (moh) {
- if (moh->pid) {
- ast_log(LOG_DEBUG, "killing %d!\n", moh->pid);
- stime = time(NULL) + 2;
- pid = moh->pid;
- moh->pid = 0;
- kill(pid, SIGKILL);
- while ((ast_wait_for_input(moh->srcfd, 100) > 0) && (bytes = read(moh->srcfd, buff, 8192)) && time(NULL) < stime) {
- tbytes = tbytes + bytes;
- }
- ast_log(LOG_DEBUG, "mpg123 pid %d and child died after %d bytes read\n", pid, tbytes);
- close(moh->srcfd);
- }
- tmp = moh;
- moh = moh->next;
- ast_moh_free_class(&tmp);
- }
- mohclasses = NULL;
- ast_mutex_unlock(&moh_lock);
-}
-
-static void moh_on_off(int on)
-{
- struct ast_channel *chan = NULL;
-
- while ( (chan = ast_channel_walk_locked(chan)) != NULL) {
- if (ast_test_flag(chan, AST_FLAG_MOH)) {
- if (on)
- local_ast_moh_start(chan, NULL);
- else
- ast_deactivate_generator(chan);
- }
- ast_mutex_unlock(&chan->lock);
- }
-}
-
-static int moh_cli(int fd, int argc, char *argv[])
-{
- int x;
-
- moh_on_off(0);
- ast_moh_destroy();
- x = load_moh_classes(1);
- moh_on_off(1);
- ast_cli(fd, "\n%d class%s reloaded.\n", x, x == 1 ? "" : "es");
- return 0;
-}
-
-static int cli_files_show(int fd, int argc, char *argv[])
-{
- int i;
- struct mohclass *class;
-
- ast_mutex_lock(&moh_lock);
- for (class = mohclasses; class; class = class->next) {
- if (!class->total_files)
- continue;
-
- ast_cli(fd, "Class: %s\n", class->name);
- for (i = 0; i < class->total_files; i++)
- ast_cli(fd, "\tFile: %s\n", class->filearray[i]);
- }
- ast_mutex_unlock(&moh_lock);
-
- return 0;
-}
-
-static int moh_classes_show(int fd, int argc, char *argv[])
-{
- struct mohclass *class;
-
- ast_mutex_lock(&moh_lock);
- for (class = mohclasses; class; class = class->next) {
- ast_cli(fd, "Class: %s\n", class->name);
- ast_cli(fd, "\tMode: %s\n", ast_strlen_zero(class->mode) ? "<none>" : class->mode);
- ast_cli(fd, "\tDirectory: %s\n", ast_strlen_zero(class->dir) ? "<none>" : class->dir);
- if (ast_test_flag(class, MOH_CUSTOM))
- ast_cli(fd, "\tApplication: %s\n", ast_strlen_zero(class->args) ? "<none>" : class->args);
- ast_cli(fd, "\tFormat: %s\n", ast_getformatname(class->format));
- }
- ast_mutex_unlock(&moh_lock);
-
- return 0;
-}
-
-static struct ast_cli_entry cli_moh = { { "moh", "reload"}, moh_cli, "Music On Hold", "Music On Hold", NULL};
-
-static struct ast_cli_entry cli_moh_classes_show = { { "moh", "classes", "show"}, moh_classes_show, "List MOH classes", "Lists all MOH classes", NULL};
-
-static struct ast_cli_entry cli_moh_files_show = { { "moh", "files", "show"}, cli_files_show, "List MOH file-based classes", "Lists all loaded file-based MOH classes and their files", NULL};
-
-static int init_classes(int reload)
-{
- struct mohclass *moh;
-
- if (!load_moh_classes(reload)) /* Load classes from config */
- return 0; /* Return if nothing is found */
- moh = mohclasses;
- while (moh) {
- if (moh->total_files)
- moh_scan_files(moh);
- moh = moh->next;
- }
- return 1;
-}
-
-int load_module(void)
-{
- int res;
-
- res = ast_register_application(app0, moh0_exec, synopsis0, descrip0);
- ast_register_atexit(ast_moh_destroy);
- ast_cli_register(&cli_moh);
- ast_cli_register(&cli_moh_files_show);
- ast_cli_register(&cli_moh_classes_show);
- if (!res)
- res = ast_register_application(app1, moh1_exec, synopsis1, descrip1);
- if (!res)
- res = ast_register_application(app2, moh2_exec, synopsis2, descrip2);
- if (!res)
- res = ast_register_application(app3, moh3_exec, synopsis3, descrip3);
- if (!res)
- res = ast_register_application(app4, moh4_exec, synopsis4, descrip4);
-
- if (!init_classes(0)) { /* No music classes configured, so skip it */
- ast_log(LOG_WARNING, "No music on hold classes configured, disabling music on hold.");
- } else {
- ast_install_music_functions(local_ast_moh_start, local_ast_moh_stop, local_ast_moh_cleanup);
- }
-
- return 0;
-}
-
-int reload(void)
-{
- if (init_classes(1))
- ast_install_music_functions(local_ast_moh_start, local_ast_moh_stop, local_ast_moh_cleanup);
-
- return 0;
-}
-
-int unload_module(void)
-{
- return -1;
-}
-
-char *description(void)
-{
- return "Music On Hold Resource";
-}
-
-int usecount(void)
-{
- /* Never allow Music On Hold to be unloaded
- unresolve needed symbols in the dialer */
-#if 0
- int res;
- STANDARD_USECOUNT(res);
- return res;
-#else
- return 1;
-#endif
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/res/res_odbc.c b/1.2-netsec/res/res_odbc.c
deleted file mode 100644
index cc4b61f2d..000000000
--- a/1.2-netsec/res/res_odbc.c
+++ /dev/null
@@ -1,618 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * res_odbc.c <ODBC resource manager>
- * Copyright (C) 2004 - 2005 Anthony Minessale II <anthmct@yahoo.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-
-/*! \file
- *
- * \brief ODBC resource manager
- *
- * \arg See also: \ref cdr_odbc
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/options.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/cli.h"
-#include "asterisk/lock.h"
-#include "asterisk/res_odbc.h"
-#define MAX_ODBC_HANDLES 25
-
-struct odbc_list
-{
- char name[80];
- odbc_obj *obj;
- int used;
-};
-
-static struct odbc_list ODBC_REGISTRY[MAX_ODBC_HANDLES];
-
-
-static void odbc_destroy(void)
-{
- int x = 0;
-
- for (x = 0; x < MAX_ODBC_HANDLES; x++) {
- if (ODBC_REGISTRY[x].obj) {
- destroy_odbc_obj(&ODBC_REGISTRY[x].obj);
- ODBC_REGISTRY[x].obj = NULL;
- }
- }
-}
-
-static odbc_obj *odbc_read(struct odbc_list *registry, const char *name)
-{
- int x = 0;
- for (x = 0; x < MAX_ODBC_HANDLES; x++) {
- if (registry[x].used && !strcmp(registry[x].name, name)) {
- return registry[x].obj;
- }
- }
- return NULL;
-}
-
-static int odbc_write(struct odbc_list *registry, char *name, odbc_obj *obj)
-{
- int x = 0;
- for (x = 0; x < MAX_ODBC_HANDLES; x++) {
- if (!registry[x].used) {
- ast_copy_string(registry[x].name, name, sizeof(registry[x].name));
- registry[x].obj = obj;
- registry[x].used = 1;
- return 1;
- }
- }
- return 0;
-}
-
-static void odbc_init(void)
-{
- int x = 0;
- for (x = 0; x < MAX_ODBC_HANDLES; x++) {
- memset(&ODBC_REGISTRY[x], 0, sizeof(struct odbc_list));
- }
-}
-
-static char *tdesc = "ODBC Resource";
-/* internal stuff */
-
-SQLHSTMT odbc_prepare_and_execute(odbc_obj *obj, SQLHSTMT (*prepare_cb)(odbc_obj *obj, void *data), void *data)
-{
- int res = 0, i, attempt;
- SQLINTEGER nativeerror=0, numfields=0;
- SQLSMALLINT diagbytes=0;
- unsigned char state[10], diagnostic[256];
- SQLHSTMT stmt;
-
- for (attempt = 0; attempt < 2; attempt++) {
- /* This prepare callback may do more than just prepare -- it may also
- * bind parameters, bind results, etc. The real key, here, is that
- * when we disconnect, all handles become invalid for most databases.
- * We must therefore redo everything when we establish a new
- * connection. */
- stmt = prepare_cb(obj, data);
-
- if (stmt) {
- res = SQLExecute(stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
- if (res == SQL_ERROR) {
- SQLGetDiagField(SQL_HANDLE_STMT, stmt, 1, SQL_DIAG_NUMBER, &numfields, SQL_IS_INTEGER, &diagbytes);
- for (i=0; i< numfields + 1; i++) {
- SQLGetDiagRec(SQL_HANDLE_STMT, stmt, i + 1, state, &nativeerror, diagnostic, sizeof(diagnostic), &diagbytes);
- ast_log(LOG_WARNING, "SQL Execute returned an error %d: %s: %s (%d)\n", res, state, diagnostic, diagbytes);
- if (i > 10) {
- ast_log(LOG_WARNING, "Oh, that was good. There are really %d diagnostics?\n", (int)numfields);
- break;
- }
- }
- }
-
- ast_log(LOG_WARNING, "SQL Execute error %d! Attempting a reconnect...\n", res);
- SQLFreeHandle(SQL_HANDLE_STMT, stmt);
-
- ast_mutex_lock(&obj->lock);
- obj->up = 0;
- ast_mutex_unlock(&obj->lock);
- odbc_obj_disconnect(obj);
- odbc_obj_connect(obj);
- continue;
- }
- break;
- }
- }
-
- return stmt;
-}
-
-int odbc_smart_execute(odbc_obj *obj, SQLHSTMT stmt)
-{
- int res = 0, i;
- SQLINTEGER nativeerror=0, numfields=0;
- SQLSMALLINT diagbytes=0;
- unsigned char state[10], diagnostic[256];
-
- res = SQLExecute(stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
- if (res == SQL_ERROR) {
- SQLGetDiagField(SQL_HANDLE_STMT, stmt, 1, SQL_DIAG_NUMBER, &numfields, SQL_IS_INTEGER, &diagbytes);
- for (i=0; i< numfields + 1; i++) {
- SQLGetDiagRec(SQL_HANDLE_STMT, stmt, i + 1, state, &nativeerror, diagnostic, sizeof(diagnostic), &diagbytes);
- ast_log(LOG_WARNING, "SQL Execute returned an error %d: %s: %s (%d)\n", res, state, diagnostic, diagbytes);
- if (i > 10) {
- ast_log(LOG_WARNING, "Oh, that was good. There are really %d diagnostics?\n", (int)numfields);
- break;
- }
- }
- }
-/*
- ast_log(LOG_WARNING, "SQL Execute error %d! Attempting a reconnect...\n", res);
- ast_mutex_lock(&obj->lock);
- obj->up = 0;
- ast_mutex_unlock(&obj->lock);
- odbc_obj_disconnect(obj);
- odbc_obj_connect(obj);
- res = SQLExecute(stmt);
-*/
- }
-
- return res;
-}
-
-
-int odbc_smart_direct_execute(odbc_obj *obj, SQLHSTMT stmt, char *sql)
-{
- int res = 0;
-
- res = SQLExecDirect (stmt, (unsigned char *)sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Execute error! Attempting a reconnect...\n");
- ast_mutex_lock(&obj->lock);
- obj->up = 0;
- ast_mutex_unlock(&obj->lock);
- odbc_obj_disconnect(obj);
- odbc_obj_connect(obj);
- res = SQLExecDirect (stmt, (unsigned char *)sql, SQL_NTS);
- }
-
- return res;
-}
-
-int odbc_sanity_check(odbc_obj *obj)
-{
- char *test_sql = "select 1";
- SQLHSTMT stmt;
- int res = 0;
-
- ast_mutex_lock(&obj->lock);
- if(obj->up) { /* so you say... let's make sure */
- res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- obj->up = 0; /* Liar!*/
- } else {
- res = SQLPrepare(stmt, (unsigned char *)test_sql, SQL_NTS);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- obj->up = 0; /* Liar!*/
- } else {
- res = SQLExecute(stmt);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- obj->up = 0; /* Liar!*/
- }
- }
- }
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- }
- ast_mutex_unlock(&obj->lock);
-
- if(!obj->up) { /* Try to reconnect! */
- ast_log(LOG_WARNING, "Connection is down attempting to reconnect...\n");
- odbc_obj_disconnect(obj);
- odbc_obj_connect(obj);
- }
- return obj->up;
-}
-
-static int load_odbc_config(void)
-{
- static char *cfg = "res_odbc.conf";
- struct ast_config *config;
- struct ast_variable *v;
- char *cat, *dsn, *username, *password;
- int enabled;
- int connect = 0;
- char *env_var;
-
- odbc_obj *obj;
-
- config = ast_config_load(cfg);
- if (config) {
- for (cat = ast_category_browse(config, NULL); cat; cat=ast_category_browse(config, cat)) {
- if (!strcmp(cat, "ENV")) {
- for (v = ast_variable_browse(config, cat); v; v = v->next) {
- env_var = malloc(strlen(v->name) + strlen(v->value) + 2);
- if (env_var) {
- sprintf(env_var, "%s=%s", v->name, v->value);
- ast_log(LOG_NOTICE, "Adding ENV var: %s=%s\n", v->name, v->value);
- putenv(env_var);
- free(env_var);
- }
- }
-
- cat = ast_category_browse(config, cat);
- }
-
- dsn = username = password = NULL;
- enabled = 1;
- connect = 0;
- for (v = ast_variable_browse(config, cat); v; v = v->next) {
- if (!strcmp(v->name, "enabled"))
- enabled = ast_true(v->value);
- if (!strcmp(v->name, "pre-connect"))
- connect = ast_true(v->value);
- if (!strcmp(v->name, "dsn"))
- dsn = v->value;
- if (!strcmp(v->name, "username"))
- username = v->value;
- if (!strcmp(v->name, "password"))
- password = v->value;
- }
-
- if (enabled && dsn) {
- obj = new_odbc_obj(cat, dsn, username, password);
- if (obj) {
- register_odbc_obj(cat, obj);
- ast_log(LOG_NOTICE, "registered database handle '%s' dsn->[%s]\n", cat, obj->dsn);
- if (connect) {
- odbc_obj_connect(obj);
- }
- } else {
- ast_log(LOG_WARNING, "Addition of obj %s failed.\n", cat);
- }
-
- }
- }
- ast_config_destroy(config);
- }
- return 0;
-}
-
-int odbc_dump_fd(int fd, odbc_obj *obj)
-{
- /* make sure the connection is up before we lie to our master.*/
- odbc_sanity_check(obj);
- ast_cli(fd, "Name: %s\nDSN: %s\nConnected: %s\n\n", obj->name, obj->dsn, obj->up ? "yes" : "no");
- return 0;
-}
-
-static int odbc_connect_usage(int fd)
-{
- ast_cli(fd, "usage odbc connect <DSN>\n");
- return 0;
-}
-
-static int odbc_disconnect_usage(int fd)
-{
- ast_cli(fd, "usage odbc disconnect <DSN>\n");
- return 0;
-}
-
-static int odbc_show_command(int fd, int argc, char **argv)
-{
- odbc_obj *obj;
- int x = 0;
-
- if (!strcmp(argv[1], "show")) {
- if (!argv[2] || (argv[2] && !strcmp(argv[2], "all"))) {
- for (x = 0; x < MAX_ODBC_HANDLES; x++) {
- if (!ODBC_REGISTRY[x].used)
- break;
- if (ODBC_REGISTRY[x].obj)
- odbc_dump_fd(fd, ODBC_REGISTRY[x].obj);
- }
- } else {
- obj = odbc_read(ODBC_REGISTRY, argv[2]);
- if (obj)
- odbc_dump_fd(fd, obj);
- }
- }
- return 0;
-}
-
-static int odbc_disconnect_command(int fd, int argc, char **argv)
-{
- odbc_obj *obj;
- if (!strcmp(argv[1], "disconnect")) {
- if (!argv[2])
- return odbc_disconnect_usage(fd);
-
- obj = odbc_read(ODBC_REGISTRY, argv[2]);
- if (obj) {
- odbc_obj_disconnect(obj);
- }
- }
- return 0;
-}
-
-static int odbc_connect_command(int fd, int argc, char **argv)
-{
- odbc_obj *obj;
- if (!argv[1])
- return odbc_connect_usage(fd);
-
- if (!strcmp(argv[1], "connect") || !strcmp(argv[1], "disconnect")) {
- if (!argv[2])
- return odbc_connect_usage(fd);
-
- obj = odbc_read(ODBC_REGISTRY, argv[2]);
- if (obj) {
- odbc_obj_connect(obj);
- }
- }
- return 0;
-}
-
-
-static char connect_usage[] =
-"Usage: odbc connect <DSN>\n"
-" Connect to ODBC DSN\n";
-
-static char disconnect_usage[] =
-"Usage: odbc connect <DSN>\n"
-" Disconnect from ODBC DSN\n";
-
-static char show_usage[] =
-"Usage: odbc show {DSN}\n"
-" Show ODBC {DSN}\n"
-" Specifying DSN will show that DSN else, all DSNs are shown\n";
-
-static struct ast_cli_entry odbc_connect_struct =
- { { "odbc", "connect", NULL }, odbc_connect_command, "Connect to ODBC DSN", connect_usage };
-
-
-static struct ast_cli_entry odbc_disconnect_struct =
- { { "odbc", "disconnect", NULL }, odbc_disconnect_command, "Disconnect from ODBC DSN", disconnect_usage };
-
-static struct ast_cli_entry odbc_show_struct =
- { { "odbc", "show", NULL }, odbc_show_command, "Show ODBC DSN(s)", show_usage };
-
-/* api calls */
-
-int register_odbc_obj(char *name, odbc_obj *obj)
-{
- if (obj != NULL)
- return odbc_write(ODBC_REGISTRY, name, obj);
- return 0;
-}
-
-odbc_obj *fetch_odbc_obj(const char *name, int check)
-{
- odbc_obj *obj = NULL;
- if((obj = (odbc_obj *) odbc_read(ODBC_REGISTRY, name))) {
- if(check)
- odbc_sanity_check(obj);
- }
- return obj;
-}
-
-odbc_obj *new_odbc_obj(char *name, char *dsn, char *username, char *password)
-{
- static odbc_obj *new;
-
- if (!(new = calloc(1, sizeof(*new))) ||
- !(new->name = malloc(strlen(name) + 1)) ||
- !(new->dsn = malloc(strlen(dsn) + 1)))
- goto cleanup;
-
- if (username) {
- if (!(new->username = malloc(strlen(username) + 1)))
- goto cleanup;
- strcpy(new->username, username);
- }
-
- if (password) {
- if (!(new->password = malloc(strlen(password) + 1)))
- goto cleanup;
- strcpy(new->password, password);
- }
-
- strcpy(new->name, name);
- strcpy(new->dsn, dsn);
- new->env = SQL_NULL_HANDLE;
- new->up = 0;
- ast_mutex_init(&new->lock);
- return new;
-
-cleanup:
- if (new) {
- free(new->name);
- free(new->dsn);
- free(new->username);
- free(new->password);
-
- free(new);
- }
-
- return NULL;
-}
-
-void destroy_odbc_obj(odbc_obj **obj)
-{
- odbc_obj_disconnect(*obj);
-
- ast_mutex_lock(&(*obj)->lock);
- SQLFreeHandle(SQL_HANDLE_STMT, (*obj)->stmt);
- SQLFreeHandle(SQL_HANDLE_DBC, (*obj)->con);
- SQLFreeHandle(SQL_HANDLE_ENV, (*obj)->env);
-
- free((*obj)->name);
- free((*obj)->dsn);
- if ((*obj)->username)
- free((*obj)->username);
- if ((*obj)->password)
- free((*obj)->password);
- ast_mutex_unlock(&(*obj)->lock);
- ast_mutex_destroy(&(*obj)->lock);
- free(*obj);
-}
-
-odbc_status odbc_obj_disconnect(odbc_obj *obj)
-{
- int res;
- ast_mutex_lock(&obj->lock);
-
- res = SQLDisconnect(obj->con);
-
-
- if (res == ODBC_SUCCESS) {
- ast_log(LOG_WARNING, "res_odbc: disconnected %d from %s [%s]\n", res, obj->name, obj->dsn);
- } else {
- ast_log(LOG_WARNING, "res_odbc: %s [%s] already disconnected\n",
- obj->name, obj->dsn);
- }
- obj->up = 0;
- ast_mutex_unlock(&obj->lock);
- return ODBC_SUCCESS;
-}
-
-odbc_status odbc_obj_connect(odbc_obj *obj)
-{
- int res;
- SQLINTEGER err;
- short int mlen;
- unsigned char msg[200], stat[10];
-
- ast_mutex_lock(&obj->lock);
-
- if (obj->env == SQL_NULL_HANDLE) {
- res = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &obj->env);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 3)
- ast_log(LOG_WARNING, "res_odbc: Error AllocHandle\n");
- ast_mutex_unlock(&obj->lock);
- return ODBC_FAIL;
- }
-
- res = SQLSetEnvAttr(obj->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 3)
- ast_log(LOG_WARNING, "res_odbc: Error SetEnv\n");
- SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
- ast_mutex_unlock(&obj->lock);
- return ODBC_FAIL;
- }
-
- res = SQLAllocHandle(SQL_HANDLE_DBC, obj->env, &obj->con);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-
- if (option_verbose > 3)
- ast_log(LOG_WARNING, "res_odbc: Error AllocHDB %d\n", res);
- SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
-
- ast_mutex_unlock(&obj->lock);
- return ODBC_FAIL;
- }
- SQLSetConnectAttr(obj->con, SQL_LOGIN_TIMEOUT, (SQLPOINTER *) 10, 0);
- }
- if(obj->up) {
- odbc_obj_disconnect(obj);
- ast_log(LOG_NOTICE,"Re-connecting %s\n", obj->name);
- }
-
- ast_log(LOG_NOTICE, "Connecting %s\n", obj->name);
-
- res = SQLConnect(obj->con,
- (SQLCHAR *) obj->dsn, SQL_NTS,
- (SQLCHAR *) obj->username, SQL_NTS,
- (SQLCHAR *) obj->password, SQL_NTS);
-
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- SQLGetDiagRec(SQL_HANDLE_DBC, obj->con, 1, stat, &err, msg, 100, &mlen);
- SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
- ast_mutex_unlock(&obj->lock);
- ast_log(LOG_WARNING, "res_odbc: Error SQLConnect=%d errno=%d %s\n", res, (int)err, msg);
- return ODBC_FAIL;
- } else {
-
- ast_log(LOG_NOTICE, "res_odbc: Connected to %s [%s]\n", obj->name, obj->dsn);
- obj->up = 1;
- }
-
- ast_mutex_unlock(&obj->lock);
- return ODBC_SUCCESS;
-}
-
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
-int unload_module(void)
-{
- STANDARD_HANGUP_LOCALUSERS;
- odbc_destroy();
- ast_cli_unregister(&odbc_disconnect_struct);
- ast_cli_unregister(&odbc_connect_struct);
- ast_cli_unregister(&odbc_show_struct);
- ast_log(LOG_NOTICE, "res_odbc unloaded.\n");
- return 0;
-}
-
-int load_module(void)
-{
- odbc_init();
- load_odbc_config();
- ast_cli_register(&odbc_disconnect_struct);
- ast_cli_register(&odbc_connect_struct);
- ast_cli_register(&odbc_show_struct);
- ast_log(LOG_NOTICE, "res_odbc loaded.\n");
- return 0;
-}
-
-char *description(void)
-{
- return tdesc;
-}
-
-int usecount(void)
-{
- int res;
- STANDARD_USECOUNT(res);
- return res;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/res/res_osp.c b/1.2-netsec/res/res_osp.c
deleted file mode 100644
index 41ca8c0cf..000000000
--- a/1.2-netsec/res/res_osp.c
+++ /dev/null
@@ -1,886 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Provide Open Settlement Protocol capability
- *
- * \arg See also: \ref chan_sip.c
- */
-
-#include <sys/types.h>
-#include <osp.h>
-#include <openssl/err.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <openssl/bio.h>
-#include <openssl/pem.h>
-#include <openssl/evp.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/say.h"
-#include "asterisk/module.h"
-#include "asterisk/options.h"
-#include "asterisk/crypto.h"
-#include "asterisk/md5.h"
-#include "asterisk/cli.h"
-#include "asterisk/io.h"
-#include "asterisk/lock.h"
-#include "asterisk/astosp.h"
-#include "asterisk/config.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-#include "asterisk/causes.h"
-#include "asterisk/callerid.h"
-#include "asterisk/pbx.h"
-
-#define MAX_CERTS 10
-#define MAX_SERVICEPOINTS 10
-#define OSP_MAX 256
-
-#define OSP_DEFAULT_MAX_CONNECTIONS 20
-#define OSP_DEFAULT_RETRY_DELAY 0
-#define OSP_DEFAULT_RETRY_LIMIT 2
-#define OSP_DEFAULT_TIMEOUT 500
-
-static int loadPemCert(unsigned char *FileName, unsigned char *buffer, int *len);
-static int loadPemPrivateKey(unsigned char *FileName, unsigned char *buffer, int *len);
-
-AST_MUTEX_DEFINE_STATIC(osplock);
-
-static int initialized = 0;
-static int hardware = 0;
-static unsigned tokenformat = TOKEN_ALGO_SIGNED;
-
-struct osp_provider {
- char name[OSP_MAX];
- char localpvtkey[OSP_MAX];
- char localcert[OSP_MAX];
- char cacerts[MAX_CERTS][OSP_MAX];
- int cacount;
- char servicepoints[MAX_SERVICEPOINTS][OSP_MAX];
- char source[OSP_MAX];
- int spcount;
- int dead;
- int maxconnections;
- int retrydelay;
- int retrylimit;
- int timeout;
- OSPTPROVHANDLE handle;
- struct osp_provider *next;
-};
-static struct osp_provider *providers;
-
-static int osp_build(struct ast_config *cfg, char *cat)
-{
- OSPTCERT TheAuthCert[MAX_CERTS];
- unsigned char Reqbuf[4096],LocalBuf[4096],AuthBuf[MAX_CERTS][4096];
- struct ast_variable *v;
- struct osp_provider *osp;
- int x,length,errorcode=0;
- int mallocd=0,i;
- char *cacerts[MAX_CERTS];
- const char *servicepoints[MAX_SERVICEPOINTS];
- OSPTPRIVATEKEY privatekey;
- OSPTCERT localcert;
- OSPTCERT *authCerts[MAX_CERTS];
-
-
-
- ast_mutex_lock(&osplock);
- osp = providers;
- while(osp) {
- if (!strcasecmp(osp->name, cat))
- break;
- osp = osp->next;
- }
- ast_mutex_unlock(&osplock);
- if (!osp) {
- mallocd = 1;
- osp = malloc(sizeof(struct osp_provider));
- if (!osp) {
- ast_log(LOG_WARNING, "Out of memory!\n");
- return -1;
- }
- memset(osp, 0, sizeof(struct osp_provider));
- osp->handle = -1;
- }
- ast_copy_string(osp->name, cat, sizeof(osp->name));
- snprintf(osp->localpvtkey, sizeof(osp->localpvtkey) ,"%s/%s-privatekey.pem", ast_config_AST_KEY_DIR, cat);
- snprintf(osp->localcert, sizeof(osp->localpvtkey), "%s/%s-localcert.pem", ast_config_AST_KEY_DIR, cat);
- osp->maxconnections=OSP_DEFAULT_MAX_CONNECTIONS;
- osp->retrydelay = OSP_DEFAULT_RETRY_DELAY;
- osp->retrylimit = OSP_DEFAULT_RETRY_LIMIT;
- osp->timeout = OSP_DEFAULT_TIMEOUT;
- osp->source[0] = '\0';
- ast_log(LOG_DEBUG, "Building OSP Provider '%s'\n", cat);
- v = ast_variable_browse(cfg, cat);
- while(v) {
- if (!strcasecmp(v->name, "privatekey")) {
- if (v->value[0] == '/')
- ast_copy_string(osp->localpvtkey, v->value, sizeof(osp->localpvtkey));
- else
- snprintf(osp->localpvtkey, sizeof(osp->localpvtkey), "%s/%s", ast_config_AST_KEY_DIR , v->value);
- } else if (!strcasecmp(v->name, "localcert")) {
- if (v->value[0] == '/')
- ast_copy_string(osp->localcert, v->value, sizeof(osp->localcert));
- else
- snprintf(osp->localcert, sizeof(osp->localcert), "%s/%s", ast_config_AST_KEY_DIR, v->value);
- } else if (!strcasecmp(v->name, "cacert")) {
- if (osp->cacount < MAX_CERTS) {
- if (v->value[0] == '/')
- ast_copy_string(osp->cacerts[osp->cacount], v->value, sizeof(osp->cacerts[0]));
- else
- snprintf(osp->cacerts[osp->cacount], sizeof(osp->cacerts[0]), "%s/%s", ast_config_AST_KEY_DIR, v->value);
- osp->cacount++;
- } else
- ast_log(LOG_WARNING, "Too many CA Certificates at line %d\n", v->lineno);
- } else if (!strcasecmp(v->name, "servicepoint")) {
- if (osp->spcount < MAX_SERVICEPOINTS) {
- ast_copy_string(osp->servicepoints[osp->spcount], v->value, sizeof(osp->servicepoints[0]));
- osp->spcount++;
- } else
- ast_log(LOG_WARNING, "Too many Service points at line %d\n", v->lineno);
- } else if (!strcasecmp(v->name, "maxconnections")) {
- if ((sscanf(v->value, "%d", &x) == 1) && (x > 0) && (x <= 1000)) {
- osp->maxconnections = x;
- } else
- ast_log(LOG_WARNING, "maxconnections should be an integer from 1 to 1000, not '%s' at line %d\n", v->value, v->lineno);
- } else if (!strcasecmp(v->name, "retrydelay")) {
- if ((sscanf(v->value, "%d", &x) == 1) && (x >= 0) && (x <= 10)) {
- osp->retrydelay = x;
- } else
- ast_log(LOG_WARNING, "retrydelay should be an integer from 0 to 10, not '%s' at line %d\n", v->value, v->lineno);
- } else if (!strcasecmp(v->name, "retrylimit")) {
- if ((sscanf(v->value, "%d", &x) == 1) && (x >= 0) && (x <= 100)) {
- osp->retrylimit = x;
- } else
- ast_log(LOG_WARNING, "retrylimit should be an integer from 0 to 100, not '%s' at line %d\n", v->value, v->lineno);
- } else if (!strcasecmp(v->name, "timeout")) {
- if ((sscanf(v->value, "%d", &x) == 1) && (x >= 200) && (x <= 10000)) {
- osp->timeout = x;
- } else
- ast_log(LOG_WARNING, "timeout should be an integer from 200 to 10000, not '%s' at line %d\n", v->value, v->lineno);
- } else if (!strcasecmp(v->name, "source")) {
- ast_copy_string(osp->source, v->value, sizeof(osp->source));
- }
- v = v->next;
- }
- if (osp->cacount < 1) {
- snprintf(osp->cacerts[osp->cacount], sizeof(osp->cacerts[0]), "%s/%s-cacert.pem", ast_config_AST_KEY_DIR, cat);
- osp->cacount++;
- }
- for (x=0;x<osp->cacount;x++)
- cacerts[x] = osp->cacerts[x];
- for (x=0;x<osp->spcount;x++)
- servicepoints[x] = osp->servicepoints[x];
-
- ast_mutex_lock(&osplock);
- osp->dead = 0;
- if (osp->handle > -1) {
- ast_log(LOG_DEBUG, "Deleting old handle for '%s'\n", osp->name);
- OSPPProviderDelete(osp->handle, 0);
- }
-
-
- length = 0;
- ast_log(LOG_DEBUG, "Loading private key for '%s' (%s)\n", osp->name, osp->localpvtkey);
- errorcode = loadPemPrivateKey(osp->localpvtkey,Reqbuf,&length);
- if (errorcode == 0)
- {
- privatekey.PrivateKeyData = Reqbuf;
- privatekey.PrivateKeyLength = length;
- }
- else
- {
- return -1;
- }
-
- length = 0;
- ast_log(LOG_DEBUG, "Loading local cert for '%s' (%s)\n", osp->name, osp->localcert);
- errorcode = loadPemCert(osp->localcert,LocalBuf,&length);
- if (errorcode == 0)
- {
- localcert.CertData = LocalBuf;
- localcert.CertDataLength = length;
- }
- else
- {
- return -1;
- }
-
- for (i=0;i<osp->cacount;i++)
- {
- length = 0;
- ast_log(LOG_DEBUG, "Loading CA cert %d for '%s' (%s)\n", i + 1, osp->name, osp->cacerts[i]);
- errorcode = loadPemCert(osp->cacerts[i],AuthBuf[i],&length);
- if (errorcode == 0)
- {
- TheAuthCert[i].CertData = AuthBuf[i];
- TheAuthCert[i].CertDataLength = length;
- authCerts[i] = &(TheAuthCert[i]);
- }
- else
- {
- return -1;
- }
- }
-
- ast_log(LOG_DEBUG, "Creating provider handle for '%s'\n", osp->name);
-
- ast_log(LOG_DEBUG, "Service point '%s %d'\n", servicepoints[0], osp->spcount);
-
- if (OSPPProviderNew(osp->spcount,
- servicepoints,
- NULL,
- "localhost",
- &privatekey,
- &localcert,
- osp->cacount,
- (const OSPTCERT **)authCerts,
- 1,
- 300,
- osp->maxconnections,
- 1,
- osp->retrydelay,
- osp->retrylimit,
- osp->timeout,
- "",
- "",
- &osp->handle)) {
- ast_log(LOG_WARNING, "Unable to initialize provider '%s'\n", cat);
- osp->dead = 1;
- }
-
- if (mallocd) {
- osp->next = providers;
- providers = osp;
- }
- ast_mutex_unlock(&osplock);
- return 0;
-}
-
-static int show_osp(int fd, int argc, char *argv[])
-{
- struct osp_provider *osp;
- char *search = NULL;
- int x;
- int found = 0;
- char *tokenalgo;
-
- if ((argc < 2) || (argc > 3))
- return RESULT_SHOWUSAGE;
- if (argc > 2)
- search = argv[2];
- if (!search) {
- switch (tokenformat) {
- case TOKEN_ALGO_BOTH:
- tokenalgo = "Both";
- break;
- case TOKEN_ALGO_UNSIGNED:
- tokenalgo = "Unsigned";
- break;
- case TOKEN_ALGO_SIGNED:
- default:
- tokenalgo = "Signed";
- break;
- }
- ast_cli(fd, "OSP: %s %s %s\n", initialized ? "Initialized" : "Uninitialized", hardware ? "Accelerated" : "Normal", tokenalgo);
- }
-
- ast_mutex_lock(&osplock);
- osp = providers;
- while(osp) {
- if (!search || !strcasecmp(osp->name, search)) {
- if (found)
- ast_cli(fd, "\n");
- ast_cli(fd, " == OSP Provider '%s' ==\n", osp->name);
- ast_cli(fd, "Local Private Key: %s\n", osp->localpvtkey);
- ast_cli(fd, "Local Certificate: %s\n", osp->localcert);
- for (x=0;x<osp->cacount;x++)
- ast_cli(fd, "CA Certificate %d: %s\n", x + 1, osp->cacerts[x]);
- for (x=0;x<osp->spcount;x++)
- ast_cli(fd, "Service Point %d: %s\n", x + 1, osp->servicepoints[x]);
- ast_cli(fd, "Max Connections: %d\n", osp->maxconnections);
- ast_cli(fd, "Retry Delay: %d seconds\n", osp->retrydelay);
- ast_cli(fd, "Retry Limit: %d\n", osp->retrylimit);
- ast_cli(fd, "Timeout: %d milliseconds\n", osp->timeout);
- ast_cli(fd, "Source: %s\n", strlen(osp->source) ? osp->source : "<unspecified>");
- ast_cli(fd, "OSP Handle: %d\n", osp->handle);
- found++;
- }
- osp = osp->next;
- }
- ast_mutex_unlock(&osplock);
- if (!found) {
- if (search)
- ast_cli(fd, "Unable to find OSP provider '%s'\n", search);
- else
- ast_cli(fd, "No OSP providers configured\n");
- }
- return RESULT_SUCCESS;
-}
-
-
-/*----------------------------------------------*
- * Loads the Certificate *
- *----------------------------------------------*/
-static int loadPemCert(unsigned char *FileName, unsigned char *buffer, int *len)
-{
- int length = 0;
- unsigned char *temp;
- BIO *bioIn = NULL;
- X509 *cert=NULL;
- int retVal = OSPC_ERR_NO_ERROR;
-
- temp = buffer;
- bioIn = BIO_new_file((const char*)FileName,"r");
- if (bioIn == NULL)
- {
- ast_log(LOG_WARNING,"Failed to find the File - %s \n",FileName);
- return -1;
- }
- else
- {
- cert = PEM_read_bio_X509(bioIn,NULL,NULL,NULL);
- if (cert == NULL)
- {
- ast_log(LOG_WARNING,"Failed to parse the Certificate from the File - %s \n",FileName);
- return -1;
- }
- else
- {
- length = i2d_X509(cert,&temp);
- if (cert == 0)
- {
- ast_log(LOG_WARNING,"Failed to parse the Certificate from the File - %s, Length=0 \n",FileName);
- return -1;
- }
- else
- {
- *len = length;
- }
- }
- }
-
- if (bioIn != NULL)
- {
- BIO_free(bioIn);
- }
-
- if (cert != NULL)
- {
- X509_free(cert);
- }
- return retVal;
-}
-
-/*----------------------------------------------*
- * Loads the Private Key *
- *----------------------------------------------*/
-static int loadPemPrivateKey(unsigned char *FileName, unsigned char *buffer, int *len)
-{
- int length = 0;
- unsigned char *temp;
- BIO *bioIn = NULL;
- RSA *pKey = NULL;
- int retVal = OSPC_ERR_NO_ERROR;
-
- temp = buffer;
-
- bioIn = BIO_new_file((const char*)FileName,"r");
- if (bioIn == NULL)
- {
- ast_log(LOG_WARNING,"Failed to find the File - %s \n",FileName);
- return -1;
- }
- else
- {
- pKey = PEM_read_bio_RSAPrivateKey(bioIn,NULL,NULL,NULL);
- if (pKey == NULL)
- {
- ast_log(LOG_WARNING,"Failed to parse the Private Key from the File - %s \n",FileName);
- return -1;
- }
- else
- {
- length = i2d_RSAPrivateKey(pKey,&temp);
- if (length == 0)
- {
- ast_log(LOG_WARNING,"Failed to parse the Private Key from the File - %s, Length=0 \n",FileName);
- return -1;
- }
- else
- {
- *len = length;
- }
- }
- }
- if (bioIn != NULL)
- {
- BIO_free(bioIn);
- }
-
- if (pKey != NULL)
- {
- RSA_free(pKey);
- }
- return retVal;
-}
-
-int ast_osp_validate(char *provider, char *token, int *handle, unsigned int *timelimit, char *callerid, struct in_addr addr, char *extension)
-{
- char tmp[256]="", *l, *n;
- char iabuf[INET_ADDRSTRLEN];
- char source[OSP_MAX] = ""; /* Same length as osp->source */
- char *token2;
- int tokenlen;
- struct osp_provider *osp;
- int res = 0;
- unsigned int authorised, dummy;
-
- if (!provider || !strlen(provider))
- provider = "default";
-
- token2 = ast_strdupa(token);
- if (!token2)
- return -1;
- tokenlen = ast_base64decode(token2, token, strlen(token));
- *handle = -1;
- if (!callerid)
- callerid = "";
- ast_copy_string(tmp, callerid, sizeof(tmp));
- ast_callerid_parse(tmp, &n, &l);
- if (!l)
- l = "";
- else {
- ast_shrink_phone_number(l);
- if (!ast_isphonenumber(l))
- l = "";
- }
- callerid = l;
- ast_mutex_lock(&osplock);
- ast_inet_ntoa(iabuf, sizeof(iabuf), addr);
- osp = providers;
- while(osp) {
- if (!strcasecmp(osp->name, provider)) {
- if (OSPPTransactionNew(osp->handle, handle)) {
- ast_log(LOG_WARNING, "Unable to create OSP Transaction handle!\n");
- } else {
- ast_copy_string(source, osp->source, sizeof(source));
- res = 1;
- }
- break;
- }
- osp = osp->next;
- }
- ast_mutex_unlock(&osplock);
- if (res) {
- res = 0;
- dummy = 0;
- if (!OSPPTransactionValidateAuthorisation(*handle, iabuf, source, NULL, NULL,
- callerid, OSPC_E164, extension, OSPC_E164, 0, "", tokenlen, token2, &authorised, timelimit, &dummy, NULL, tokenformat)) {
- if (authorised) {
- ast_log(LOG_DEBUG, "Validated token for '%s' from '%s@%s'\n", extension, callerid, iabuf);
- res = 1;
- }
- }
- }
- return res;
-}
-
-int ast_osp_lookup(struct ast_channel *chan, char *provider, char *extension, char *callerid, struct ast_osp_result *result)
-{
- int cres;
- int res = 0;
- int counts;
- int tokenlen;
- unsigned int dummy=0;
- unsigned int timelimit;
- unsigned int callidlen;
- char callidstr[OSPC_CALLID_MAXSIZE] = "";
- struct osp_provider *osp;
- char source[OSP_MAX] = ""; /* Same length as osp->source */
- char callednum[2048]="";
- char callingnum[2048]="";
- char destination[2048]="";
- char token[2000];
- char tmp[256]="", *l, *n;
- OSPE_DEST_PROT prot;
- OSPE_DEST_OSP_ENABLED ospenabled;
- char *devinfo = NULL;
-
- result->handle = -1;
- result->numresults = 0;
- result->tech[0] = '\0';
- result->dest[0] = '\0';
- result->token[0] = '\0';
-
- if (!provider || !strlen(provider))
- provider = "default";
-
- if (!callerid)
- callerid = "";
- ast_copy_string(tmp, callerid, sizeof(tmp));
- ast_callerid_parse(tmp, &n, &l);
- if (!l)
- l = "";
- else {
- ast_shrink_phone_number(l);
- if (!ast_isphonenumber(l))
- l = "";
- }
- callerid = l;
-
- if (chan) {
- cres = ast_autoservice_start(chan);
- if (cres < 0)
- return cres;
- }
- ast_mutex_lock(&osplock);
- osp = providers;
- while(osp) {
- if (!strcasecmp(osp->name, provider)) {
- if (OSPPTransactionNew(osp->handle, &result->handle)) {
- ast_log(LOG_WARNING, "Unable to create OSP Transaction handle!\n");
- } else {
- ast_copy_string(source, osp->source, sizeof(source));
- res = 1;
- }
- break;
- }
- osp = osp->next;
- }
- ast_mutex_unlock(&osplock);
- if (res) {
- res = 0;
- /* No more than 10 back */
- counts = 10;
- dummy = 0;
- devinfo = pbx_builtin_getvar_helper (chan, "OSPPEER");
- if (!devinfo) {
- devinfo = "";
- }
- if (!OSPPTransactionRequestAuthorisation(result->handle, source, devinfo,
- callerid,OSPC_E164, extension, OSPC_E164, NULL, 0, NULL, NULL, &counts, &dummy, NULL)) {
- if (counts) {
- tokenlen = sizeof(token);
- result->numresults = counts - 1;
- callidlen = sizeof(callidstr);
- if (!OSPPTransactionGetFirstDestination(result->handle, 0, NULL, NULL, &timelimit, &callidlen, callidstr,
- sizeof(callednum), callednum, sizeof(callingnum), callingnum, sizeof(destination), destination, 0, NULL, &tokenlen, token)) {
- ast_log(LOG_DEBUG, "Got destination '%s' and called: '%s' calling: '%s' for '%s' (provider '%s')\n",
- destination, callednum, callingnum, extension, provider);
- /* Only support OSP server with only one duration limit */
- if (ast_channel_cmpwhentohangup (chan, timelimit) < 0) {
- ast_channel_setwhentohangup (chan, timelimit);
- }
- do {
- if (!OSPPTransactionIsDestOSPEnabled (result->handle, &ospenabled) && (ospenabled == OSPE_OSP_FALSE)) {
- result->token[0] = 0;
- }
- else {
- ast_base64encode(result->token, token, tokenlen, sizeof(result->token) - 1);
- }
- if ((strlen(destination) > 2) && !OSPPTransactionGetDestProtocol(result->handle, &prot)) {
- res = 1;
- /* Strip leading and trailing brackets */
- destination[strlen(destination) - 1] = '\0';
- switch(prot) {
- case OSPE_DEST_PROT_H323_SETUP:
- ast_copy_string(result->tech, "H323", sizeof(result->tech));
- snprintf(result->dest, sizeof(result->dest), "%s@%s", callednum, destination + 1);
- break;
- case OSPE_DEST_PROT_SIP:
- ast_copy_string(result->tech, "SIP", sizeof(result->tech));
- snprintf(result->dest, sizeof(result->dest), "%s@%s", callednum, destination + 1);
- break;
- case OSPE_DEST_PROT_IAX:
- ast_copy_string(result->tech, "IAX", sizeof(result->tech));
- snprintf(result->dest, sizeof(result->dest), "%s@%s", callednum, destination + 1);
- break;
- default:
- ast_log(LOG_DEBUG, "Unknown destination protocol '%d', skipping...\n", prot);
- res = 0;
- }
- if (!res && result->numresults) {
- result->numresults--;
- callidlen = sizeof(callidstr);
- if (OSPPTransactionGetNextDestination(result->handle, OSPC_FAIL_INCOMPATIBLE_DEST, 0, NULL, NULL, &timelimit, &callidlen, callidstr,
- sizeof(callednum), callednum, sizeof(callingnum), callingnum, sizeof(destination), destination, 0, NULL, &tokenlen, token)) {
- break;
- }
- }
- } else {
- ast_log(LOG_DEBUG, "Missing destination protocol\n");
- break;
- }
- } while(!res && result->numresults);
- }
- }
-
- }
- if (!res) {
- OSPPTransactionDelete(result->handle);
- result->handle = -1;
- }
-
- }
- if (!osp)
- ast_log(LOG_NOTICE, "OSP Provider '%s' does not exist!\n", provider);
- if (chan) {
- cres = ast_autoservice_stop(chan);
- if (cres < 0)
- return cres;
- }
- return res;
-}
-
-int ast_osp_next(struct ast_osp_result *result, int cause)
-{
- int res = 0;
- int tokenlen;
- unsigned int dummy=0;
- unsigned int timelimit;
- unsigned int callidlen;
- char callidstr[OSPC_CALLID_MAXSIZE] = "";
- char callednum[2048]="";
- char callingnum[2048]="";
- char destination[2048]="";
- char token[2000];
- OSPE_DEST_PROT prot;
- OSPE_DEST_OSP_ENABLED ospenabled;
-
- result->tech[0] = '\0';
- result->dest[0] = '\0';
- result->token[0] = '\0';
-
- if (result->handle > -1) {
- dummy = 0;
- if (result->numresults) {
- tokenlen = sizeof(token);
- while(!res && result->numresults) {
- result->numresults--;
- callidlen = sizeof(callidstr);
- if (!OSPPTransactionGetNextDestination(result->handle, OSPC_FAIL_INCOMPATIBLE_DEST, 0, NULL, NULL, &timelimit, &callidlen, callidstr,
- sizeof(callednum), callednum, sizeof(callingnum), callingnum, sizeof(destination), destination, 0, NULL, &tokenlen, token)) {
- if (!OSPPTransactionIsDestOSPEnabled (result->handle, &ospenabled) && (ospenabled == OSPE_OSP_FALSE)) {
- result->token[0] = 0;
- }
- else {
- ast_base64encode(result->token, token, tokenlen, sizeof(result->token) - 1);
- }
- if ((strlen(destination) > 2) && !OSPPTransactionGetDestProtocol(result->handle, &prot)) {
- res = 1;
- /* Strip leading and trailing brackets */
- destination[strlen(destination) - 1] = '\0';
- switch(prot) {
- case OSPE_DEST_PROT_H323_SETUP:
- ast_copy_string(result->tech, "H323", sizeof(result->tech));
- snprintf(result->dest, sizeof(result->dest), "%s@%s", callednum, destination + 1);
- break;
- case OSPE_DEST_PROT_SIP:
- ast_copy_string(result->tech, "SIP", sizeof(result->tech));
- snprintf(result->dest, sizeof(result->dest), "%s@%s", callednum, destination + 1);
- break;
- case OSPE_DEST_PROT_IAX:
- ast_copy_string(result->tech, "IAX", sizeof(result->tech));
- snprintf(result->dest, sizeof(result->dest), "%s@%s", callednum, destination + 1);
- break;
- default:
- ast_log(LOG_DEBUG, "Unknown destination protocol '%d', skipping...\n", prot);
- res = 0;
- }
- } else {
- ast_log(LOG_DEBUG, "Missing destination protocol\n");
- break;
- }
- }
- }
-
- }
- if (!res) {
- OSPPTransactionDelete(result->handle);
- result->handle = -1;
- }
-
- }
- return res;
-}
-
-static enum OSPEFAILREASON cause2reason(int cause)
-{
- switch(cause) {
- case AST_CAUSE_BUSY:
- return OSPC_FAIL_USER_BUSY;
- case AST_CAUSE_CONGESTION:
- return OSPC_FAIL_SWITCHING_EQUIPMENT_CONGESTION;
- case AST_CAUSE_UNALLOCATED:
- return OSPC_FAIL_UNALLOC_NUMBER;
- case AST_CAUSE_NOTDEFINED:
- return OSPC_FAIL_NORMAL_UNSPECIFIED;
- case AST_CAUSE_NOANSWER:
- return OSPC_FAIL_NO_ANSWER_FROM_USER;
- case AST_CAUSE_NORMAL:
- default:
- return OSPC_FAIL_NORMAL_CALL_CLEARING;
- }
-}
-
-int ast_osp_terminate(int handle, int cause, time_t start, time_t duration)
-{
- unsigned int dummy = 0;
- int res = -1;
- enum OSPEFAILREASON reason;
-
- time_t endTime = 0;
- time_t alertTime = 0;
- time_t connectTime = 0;
- unsigned isPddInfoPresent = 0;
- unsigned pdd = 0;
- unsigned releaseSource = 0;
- unsigned char *confId = "";
-
- reason = cause2reason(cause);
- if (OSPPTransactionRecordFailure(handle, reason))
- ast_log(LOG_WARNING, "Failed to record call termination for handle %d\n", handle);
- else if (OSPPTransactionReportUsage(handle, duration, start,
- endTime,alertTime,connectTime,isPddInfoPresent,pdd,releaseSource,confId,
- 0, 0, 0, 0, &dummy, NULL))
- ast_log(LOG_WARNING, "Failed to report duration for handle %d\n", handle);
- else {
- ast_log(LOG_DEBUG, "Completed recording handle %d\n", handle);
- OSPPTransactionDelete(handle);
- res = 0;
- }
- return res;
-}
-
-static int config_load(void)
-{
- struct ast_config *cfg;
- char *cat;
- struct osp_provider *osp, *prev = NULL, *next;
- ast_mutex_lock(&osplock);
- osp = providers;
- while(osp) {
- osp->dead = 1;
- osp = osp->next;
- }
- ast_mutex_unlock(&osplock);
- cfg = ast_config_load("osp.conf");
- if (cfg) {
- if (!initialized) {
- cat = ast_variable_retrieve(cfg, "general", "accelerate");
- if (cat && ast_true(cat))
- if (OSPPInit(1)) {
- ast_log(LOG_WARNING, "Failed to enable hardware accelleration, falling back to software mode\n");
- OSPPInit(0);
- } else
- hardware = 1;
- else
- OSPPInit(0);
- initialized = 1;
- }
- cat = ast_variable_retrieve(cfg, "general", "tokenformat");
- if (cat) {
- if ((sscanf(cat, "%d", &tokenformat) != 1) || (tokenformat < TOKEN_ALGO_SIGNED) || (tokenformat > TOKEN_ALGO_BOTH)) {
- tokenformat = TOKEN_ALGO_SIGNED;
- ast_log(LOG_WARNING, "tokenformat should be an integer from 0 to 2, not '%s'\n", cat);
- }
- }
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (strcasecmp(cat, "general"))
- osp_build(cfg, cat);
- cat = ast_category_browse(cfg, cat);
- }
- ast_config_destroy(cfg);
- } else
- ast_log(LOG_NOTICE, "No OSP configuration found. OSP support disabled\n");
- ast_mutex_lock(&osplock);
- osp = providers;
- while(osp) {
- next = osp->next;
- if (osp->dead) {
- if (prev)
- prev->next = next;
- else
- providers = next;
- /* XXX Cleanup OSP structure first XXX */
- free(osp);
- } else
- prev = osp;
- osp = next;
- }
- ast_mutex_unlock(&osplock);
- return 0;
-}
-
-static char show_osp_usage[] =
-"Usage: show osp\n"
-" Displays information on Open Settlement Protocol\n";
-
-static struct ast_cli_entry cli_show_osp =
-{ { "show", "osp", NULL }, show_osp, "Displays OSP information", show_osp_usage };
-
-int reload(void)
-{
- config_load();
- ast_log(LOG_NOTICE, "XXX Should reload OSP config XXX\n");
- return 0;
-}
-
-int load_module(void)
-{
- config_load();
- ast_cli_register(&cli_show_osp);
- return 0;
-}
-
-int unload_module(void)
-{
- /* Can't unload this once we're loaded */
- return -1;
-}
-
-char *description(void)
-{
- return "Open Settlement Protocol Support";
-}
-
-int usecount(void)
-{
- /* We should never be unloaded */
- return 1;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/1.2-netsec/rtp.c b/1.2-netsec/rtp.c
deleted file mode 100644
index 2df27e287..000000000
--- a/1.2-netsec/rtp.c
+++ /dev/null
@@ -1,1896 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*!
- * \file
- * \brief Supports RTP and RTCP with Symmetric RTP support for NAT traversal.
- *
- * RTP is deffined in RFC 3550.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <fcntl.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/rtp.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/acl.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-#include "asterisk/cli.h"
-#include "asterisk/unaligned.h"
-#include "asterisk/utils.h"
-
-#define MAX_TIMESTAMP_SKEW 640
-
-#define RTP_MTU 1200
-
-#define DEFAULT_DTMF_TIMEOUT 3000 /* samples */
-
-static int dtmftimeout = DEFAULT_DTMF_TIMEOUT;
-
-static int rtpstart = 0;
-static int rtpend = 0;
-static int rtpdebug = 0; /* Are we debugging? */
-static struct sockaddr_in rtpdebugaddr; /* Debug packets to/from this host */
-#ifdef SO_NO_CHECK
-static int nochecksums = 0;
-#endif
-
-/* The value of each payload format mapping: */
-struct rtpPayloadType {
- int isAstFormat; /* whether the following code is an AST_FORMAT */
- int code;
-};
-
-#define MAX_RTP_PT 256
-
-#define FLAG_3389_WARNING (1 << 0)
-#define FLAG_NAT_ACTIVE (3 << 1)
-#define FLAG_NAT_INACTIVE (0 << 1)
-#define FLAG_NAT_INACTIVE_NOWARN (1 << 1)
-
-struct ast_rtp {
- int s;
- char resp;
- struct ast_frame f;
- unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET];
- /*! Synchronization source, RFC 3550, page 10. */
- unsigned int ssrc;
- unsigned int lastts;
- unsigned int lastdigitts;
- unsigned int lastrxts;
- unsigned int lastividtimestamp;
- unsigned int lastovidtimestamp;
- unsigned int lasteventseqn;
- unsigned int lasteventendseqn;
- int lasttxformat;
- int lastrxformat;
- int dtmfcount;
- unsigned int dtmfduration;
- int nat;
- unsigned int flags;
- /*! Socket representation of the local endpoint. */
- struct sockaddr_in us;
- /*! Socket representation of the remote endpoint. */
- struct sockaddr_in them;
- struct timeval rxcore;
- struct timeval txcore;
- struct timeval dtmfmute;
- struct ast_smoother *smoother;
- int *ioid;
- /*! Sequence number, RFC 3550, page 13. */
- unsigned short seqno;
- unsigned short rxseqno;
- struct sched_context *sched;
- struct io_context *io;
- void *data;
- ast_rtp_callback callback;
- struct rtpPayloadType current_RTP_PT[MAX_RTP_PT];
- /*! a cache for the result of rtp_lookup_code(): */
- int rtp_lookup_code_cache_isAstFormat;
- int rtp_lookup_code_cache_code;
- int rtp_lookup_code_cache_result;
- int rtp_offered_from_local;
-
-#ifdef MIDCOM
- struct sockaddr_in them_midcom_nat;
-#endif
- struct ast_rtcp *rtcp;
-};
-
-/*!
- * \brief Structure defining an RTCP session.
- *
- * The concept "RTCP session" is not defined in RFC 3550, but since
- * this structure is analogous to ast_rtp, which tracks a RTP session,
- * it is logical to think of this as a RTCP session.
- *
- * RTCP packet is defined on page 9 of RFC 3550.
- *
- */
-struct ast_rtcp {
- /*! Socket */
- int s;
- /*! Socket representation of the local endpoint. */
- struct sockaddr_in us;
- /*! Socket representation of the remote endpoint. */
- struct sockaddr_in them;
-};
-
-static struct ast_rtp_protocol *protos = NULL;
-
-int ast_rtp_fd(struct ast_rtp *rtp)
-{
- return rtp->s;
-}
-
-int ast_rtcp_fd(struct ast_rtp *rtp)
-{
- if (rtp->rtcp)
- return rtp->rtcp->s;
- return -1;
-}
-
-void ast_rtp_set_data(struct ast_rtp *rtp, void *data)
-{
- rtp->data = data;
-}
-
-void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback)
-{
- rtp->callback = callback;
-}
-
-void ast_rtp_setnat(struct ast_rtp *rtp, int nat)
-{
- rtp->nat = nat;
-}
-
-static struct ast_frame *send_dtmf(struct ast_rtp *rtp)
-{
- static struct ast_frame null_frame = { AST_FRAME_NULL, };
- char iabuf[INET_ADDRSTRLEN];
-
- if (ast_tvcmp(ast_tvnow(), rtp->dtmfmute) < 0) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Ignore potential DTMF echo from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr));
- rtp->resp = 0;
- rtp->dtmfduration = 0;
- return &null_frame;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Sending dtmf: %d (%c), at %s\n", rtp->resp, rtp->resp, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr));
- if (rtp->resp == 'X') {
- rtp->f.frametype = AST_FRAME_CONTROL;
- rtp->f.subclass = AST_CONTROL_FLASH;
- } else {
- rtp->f.frametype = AST_FRAME_DTMF;
- rtp->f.subclass = rtp->resp;
- }
- rtp->f.datalen = 0;
- rtp->f.samples = 0;
- rtp->f.mallocd = 0;
- rtp->f.src = "RTP";
- rtp->resp = 0;
- rtp->dtmfduration = 0;
- return &rtp->f;
-
-}
-
-static inline int rtp_debug_test_addr(struct sockaddr_in *addr)
-{
- if (rtpdebug == 0)
- return 0;
- if (rtpdebugaddr.sin_addr.s_addr) {
- if (((ntohs(rtpdebugaddr.sin_port) != 0)
- && (rtpdebugaddr.sin_port != addr->sin_port))
- || (rtpdebugaddr.sin_addr.s_addr != addr->sin_addr.s_addr))
- return 0;
- }
- return 1;
-}
-
-static struct ast_frame *process_cisco_dtmf(struct ast_rtp *rtp, unsigned char *data, int len)
-{
- unsigned int event;
- char resp = 0;
- struct ast_frame *f = NULL;
- event = ntohl(*((unsigned int *)(data)));
- event &= 0x001F;
-#if 0
- printf("Cisco Digit: %08x (len = %d)\n", event, len);
-#endif
- if (event < 10) {
- resp = '0' + event;
- } else if (event < 11) {
- resp = '*';
- } else if (event < 12) {
- resp = '#';
- } else if (event < 16) {
- resp = 'A' + (event - 12);
- } else if (event < 17) {
- resp = 'X';
- }
- if (rtp->resp && (rtp->resp != resp)) {
- f = send_dtmf(rtp);
- }
- rtp->resp = resp;
- rtp->dtmfcount = dtmftimeout;
- return f;
-}
-
-/*!
- * \brief Process RTP DTMF and events according to RFC 2833.
- *
- * RFC 2833 is "RTP Payload for DTMF Digits, Telephony Tones and Telephony Signals".
- *
- * \param rtp
- * \param data
- * \param len
- * \param seqno
- * \returns
- */
-static struct ast_frame *process_rfc2833(struct ast_rtp *rtp, unsigned char *data, int len, unsigned int seqno)
-{
- unsigned int event;
- unsigned int event_end;
- unsigned int duration;
- char resp = 0;
- struct ast_frame *f = NULL;
- event = ntohl(*((unsigned int *)(data)));
- event >>= 24;
- event_end = ntohl(*((unsigned int *)(data)));
- event_end <<= 8;
- event_end >>= 24;
- duration = ntohl(*((unsigned int *)(data)));
- duration &= 0xFFFF;
- if (rtpdebug)
- ast_log(LOG_DEBUG, "- RTP 2833 Event: %08x (len = %d)\n", event, len);
- if (event < 10) {
- resp = '0' + event;
- } else if (event < 11) {
- resp = '*';
- } else if (event < 12) {
- resp = '#';
- } else if (event < 16) {
- resp = 'A' + (event - 12);
- } else if (event < 17) { /* Event 16: Hook flash */
- resp = 'X';
- }
- if (rtp->resp && (rtp->resp != resp)) {
- f = send_dtmf(rtp);
- } else if(event_end & 0x80) {
- if (rtp->resp) {
- if(rtp->lasteventendseqn != seqno) {
- f = send_dtmf(rtp);
- rtp->lasteventendseqn = seqno;
- }
- rtp->resp = 0;
- }
- resp = 0;
- duration = 0;
- } else if (rtp->resp && rtp->dtmfduration && (duration < rtp->dtmfduration)) {
- f = send_dtmf(rtp);
- }
- if (!(event_end & 0x80))
- rtp->resp = resp;
- rtp->dtmfcount = dtmftimeout;
- rtp->dtmfduration = duration;
- return f;
-}
-
-/*!
- * \brief Process Comfort Noise RTP.
- *
- * This is incomplete at the moment.
- *
-*/
-static struct ast_frame *process_rfc3389(struct ast_rtp *rtp, unsigned char *data, int len)
-{
- struct ast_frame *f = NULL;
- /* Convert comfort noise into audio with various codecs. Unfortunately this doesn't
- totally help us out becuase we don't have an engine to keep it going and we are not
- guaranteed to have it every 20ms or anything */
- if (rtpdebug)
- ast_log(LOG_DEBUG, "- RTP 3389 Comfort noise event: Level %d (len = %d)\n", rtp->lastrxformat, len);
-
- if (!(ast_test_flag(rtp, FLAG_3389_WARNING))) {
- char iabuf[INET_ADDRSTRLEN];
-
- ast_log(LOG_NOTICE, "Comfort noise support incomplete in Asterisk (RFC 3389). Please turn off on client if possible. Client IP: %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr));
- ast_set_flag(rtp, FLAG_3389_WARNING);
- }
-
- /* Must have at least one byte */
- if (!len)
- return NULL;
- if (len < 24) {
- rtp->f.data = rtp->rawdata + AST_FRIENDLY_OFFSET;
- rtp->f.datalen = len - 1;
- rtp->f.offset = AST_FRIENDLY_OFFSET;
- memcpy(rtp->f.data, data + 1, len - 1);
- } else {
- rtp->f.data = NULL;
- rtp->f.offset = 0;
- rtp->f.datalen = 0;
- }
- rtp->f.frametype = AST_FRAME_CNG;
- rtp->f.subclass = data[0] & 0x7f;
- rtp->f.datalen = len - 1;
- rtp->f.samples = 0;
- rtp->f.delivery.tv_usec = rtp->f.delivery.tv_sec = 0;
- f = &rtp->f;
- return f;
-}
-
-static int rtpread(int *id, int fd, short events, void *cbdata)
-{
- struct ast_rtp *rtp = cbdata;
- struct ast_frame *f;
- f = ast_rtp_read(rtp);
- if (f) {
- if (rtp->callback)
- rtp->callback(rtp, f, rtp->data);
- }
- return 1;
-}
-
-struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp)
-{
- static struct ast_frame null_frame = { AST_FRAME_NULL, };
- socklen_t len;
- int hdrlen = 8;
- int res;
- struct sockaddr_in sin;
- unsigned int rtcpdata[1024];
- char iabuf[INET_ADDRSTRLEN];
-
- if (!rtp || !rtp->rtcp)
- return &null_frame;
-
- len = sizeof(sin);
-
- res = recvfrom(rtp->rtcp->s, rtcpdata, sizeof(rtcpdata),
- 0, (struct sockaddr *)&sin, &len);
-
- if (res < 0) {
- if (errno != EAGAIN)
- ast_log(LOG_WARNING, "RTP Read error: %s\n", strerror(errno));
- if (errno == EBADF)
- CRASH;
- return &null_frame;
- }
-
- if (res < hdrlen) {
- ast_log(LOG_WARNING, "RTP Read too short\n");
- return &null_frame;
- }
-
- if (rtp->nat) {
- /* Send to whoever sent to us */
- if ((rtp->rtcp->them.sin_addr.s_addr != sin.sin_addr.s_addr) ||
- (rtp->rtcp->them.sin_port != sin.sin_port)) {
- memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them));
- if (option_debug || rtpdebug)
- ast_log(LOG_DEBUG, "RTCP NAT: Got RTCP from other end. Now sending to address %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port));
- }
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Got RTCP report of %d bytes\n", res);
- return &null_frame;
-}
-
-static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark)
-{
- struct timeval ts = ast_samp2tv( timestamp, 8000);
- if (ast_tvzero(rtp->rxcore) || mark) {
- rtp->rxcore = ast_tvsub(ast_tvnow(), ts);
- /* Round to 20ms for nice, pretty timestamps */
- rtp->rxcore.tv_usec -= rtp->rxcore.tv_usec % 20000;
- }
- *tv = ast_tvadd(rtp->rxcore, ts);
-}
-
-struct ast_frame *ast_rtp_read(struct ast_rtp *rtp)
-{
- int res;
- struct sockaddr_in sin;
- socklen_t len;
- unsigned int seqno;
- int version;
- int payloadtype;
- int hdrlen = 12;
- int padding;
- int mark;
- int ext;
- int x;
- char iabuf[INET_ADDRSTRLEN];
- unsigned int timestamp;
- unsigned int *rtpheader;
- static struct ast_frame *f, null_frame = { AST_FRAME_NULL, };
- struct rtpPayloadType rtpPT;
-
- len = sizeof(sin);
-
- /* Cache where the header will go */
- res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET,
- 0, (struct sockaddr *)&sin, &len);
-
-
- rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET);
- if (res < 0) {
- if (errno != EAGAIN)
- ast_log(LOG_WARNING, "RTP Read error: %s\n", strerror(errno));
- if (errno == EBADF)
- CRASH;
- return &null_frame;
- }
- if (res < hdrlen) {
- ast_log(LOG_WARNING, "RTP Read too short\n");
- return &null_frame;
- }
-
- /* Ignore if the other side hasn't been given an address
- yet. */
- if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port)
- return &null_frame;
-
- if (rtp->nat) {
- /* Send to whoever sent to us */
- if ((rtp->them.sin_addr.s_addr != sin.sin_addr.s_addr) ||
- (rtp->them.sin_port != sin.sin_port)) {
- memcpy(&rtp->them, &sin, sizeof(rtp->them));
- rtp->rxseqno = 0;
- ast_set_flag(rtp, FLAG_NAT_ACTIVE);
- if (option_debug || rtpdebug)
- ast_log(LOG_DEBUG, "RTP NAT: Got audio from other end. Now sending to address %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port));
- }
- }
-
- /* Get fields */
- seqno = ntohl(rtpheader[0]);
-
- /* Check RTP version */
- version = (seqno & 0xC0000000) >> 30;
- if (version != 2)
- return &null_frame;
-
- payloadtype = (seqno & 0x7f0000) >> 16;
- padding = seqno & (1 << 29);
- mark = seqno & (1 << 23);
- ext = seqno & (1 << 28);
- seqno &= 0xffff;
- timestamp = ntohl(rtpheader[1]);
-
- if (padding) {
- /* Remove padding bytes */
- res -= rtp->rawdata[AST_FRIENDLY_OFFSET + res - 1];
- }
-
- if (ext) {
- /* RTP Extension present */
- hdrlen += 4;
- hdrlen += (ntohl(rtpheader[3]) & 0xffff) << 2;
- }
-
- if (res < hdrlen) {
- ast_log(LOG_WARNING, "RTP Read too short (%d, expecting %d)\n", res, hdrlen);
- return &null_frame;
- }
-
- if(rtp_debug_test_addr(&sin))
- ast_verbose("Got RTP packet from %s:%d (type %d, seq %d, ts %d, len %d)\n"
- , ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen);
-
- rtpPT = ast_rtp_lookup_pt(rtp, payloadtype);
- if (!rtpPT.isAstFormat) {
- /* This is special in-band data that's not one of our codecs */
- if (rtpPT.code == AST_RTP_DTMF) {
- /* It's special -- rfc2833 process it */
- if(rtp_debug_test_addr(&sin)) {
- unsigned char *data;
- unsigned int event;
- unsigned int event_end;
- unsigned int duration;
- data = rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen;
- event = ntohl(*((unsigned int *)(data)));
- event >>= 24;
- event_end = ntohl(*((unsigned int *)(data)));
- event_end <<= 8;
- event_end >>= 24;
- duration = ntohl(*((unsigned int *)(data)));
- duration &= 0xFFFF;
- ast_verbose("Got rfc2833 RTP packet from %s:%d (type %d, seq %d, ts %d, len %d, mark %d, event %08x, end %d, duration %d) \n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp, res - hdrlen, (mark?1:0), event, ((event_end & 0x80)?1:0), duration);
- }
- if (rtp->lasteventseqn <= seqno || rtp->resp == 0 || (rtp->lasteventseqn >= 65530 && seqno <= 6)) {
- f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno);
- rtp->lasteventseqn = seqno;
- } else
- f = NULL;
- if (f)
- return f;
- else
- return &null_frame;
- } else if (rtpPT.code == AST_RTP_CISCO_DTMF) {
- /* It's really special -- process it the Cisco way */
- if (rtp->lasteventseqn <= seqno || rtp->resp == 0 || (rtp->lasteventseqn >= 65530 && seqno <= 6)) {
- f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
- rtp->lasteventseqn = seqno;
- } else
- f = NULL;
- if (f)
- return f;
- else
- return &null_frame;
- } else if (rtpPT.code == AST_RTP_CN) {
- /* Comfort Noise */
- f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
- if (f)
- return f;
- else
- return &null_frame;
- } else {
- ast_log(LOG_NOTICE, "Unknown RTP codec %d received\n", payloadtype);
- return &null_frame;
- }
- }
- rtp->f.subclass = rtpPT.code;
- if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO)
- rtp->f.frametype = AST_FRAME_VOICE;
- else
- rtp->f.frametype = AST_FRAME_VIDEO;
- rtp->lastrxformat = rtp->f.subclass;
-
- if (!rtp->lastrxts)
- rtp->lastrxts = timestamp;
-
- if (rtp->rxseqno) {
- for (x=rtp->rxseqno + 1; x < seqno; x++) {
- /* Queue empty frames */
- rtp->f.mallocd = 0;
- rtp->f.datalen = 0;
- rtp->f.data = NULL;
- rtp->f.offset = 0;
- rtp->f.samples = 0;
- rtp->f.src = "RTPMissedFrame";
- }
- }
- rtp->rxseqno = seqno;
-
- if (rtp->dtmfcount) {
-#if 0
- printf("dtmfcount was %d\n", rtp->dtmfcount);
-#endif
- rtp->dtmfcount -= (timestamp - rtp->lastrxts);
- if (rtp->dtmfcount < 0)
- rtp->dtmfcount = 0;
-#if 0
- if (dtmftimeout != rtp->dtmfcount)
- printf("dtmfcount is %d\n", rtp->dtmfcount);
-#endif
- }
- rtp->lastrxts = timestamp;
-
- /* Send any pending DTMF */
- if (rtp->resp && !rtp->dtmfcount) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Sending pending DTMF\n");
- return send_dtmf(rtp);
- }
- rtp->f.mallocd = 0;
- rtp->f.datalen = res - hdrlen;
- rtp->f.data = rtp->rawdata + hdrlen + AST_FRIENDLY_OFFSET;
- rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET;
- if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) {
- rtp->f.samples = ast_codec_get_samples(&rtp->f);
- if (rtp->f.subclass == AST_FORMAT_SLINEAR)
- ast_frame_byteswap_be(&rtp->f);
- calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark);
- } else {
- /* Video -- samples is # of samples vs. 90000 */
- if (!rtp->lastividtimestamp)
- rtp->lastividtimestamp = timestamp;
- rtp->f.samples = timestamp - rtp->lastividtimestamp;
- rtp->lastividtimestamp = timestamp;
- rtp->f.delivery.tv_sec = 0;
- rtp->f.delivery.tv_usec = 0;
- if (mark)
- rtp->f.subclass |= 0x1;
-
- }
- rtp->f.src = "RTP";
- return &rtp->f;
-}
-
-/* The following array defines the MIME Media type (and subtype) for each
- of our codecs, or RTP-specific data type. */
-static struct {
- struct rtpPayloadType payloadType;
- char* type;
- char* subtype;
-} mimeTypes[] = {
- {{1, AST_FORMAT_G723_1}, "audio", "G723"},
- {{1, AST_FORMAT_GSM}, "audio", "GSM"},
- {{1, AST_FORMAT_ULAW}, "audio", "PCMU"},
- {{1, AST_FORMAT_ALAW}, "audio", "PCMA"},
- {{1, AST_FORMAT_G726}, "audio", "G726-32"},
- {{1, AST_FORMAT_ADPCM}, "audio", "DVI4"},
- {{1, AST_FORMAT_SLINEAR}, "audio", "L16"},
- {{1, AST_FORMAT_LPC10}, "audio", "LPC"},
- {{1, AST_FORMAT_G729A}, "audio", "G729"},
- {{1, AST_FORMAT_SPEEX}, "audio", "speex"},
- {{1, AST_FORMAT_ILBC}, "audio", "iLBC"},
- {{0, AST_RTP_DTMF}, "audio", "telephone-event"},
- {{0, AST_RTP_CISCO_DTMF}, "audio", "cisco-telephone-event"},
- {{0, AST_RTP_CN}, "audio", "CN"},
- {{1, AST_FORMAT_JPEG}, "video", "JPEG"},
- {{1, AST_FORMAT_PNG}, "video", "PNG"},
- {{1, AST_FORMAT_H261}, "video", "H261"},
- {{1, AST_FORMAT_H263}, "video", "H263"},
- {{1, AST_FORMAT_H263_PLUS}, "video", "h263-1998"},
-};
-
-/* Static (i.e., well-known) RTP payload types for our "AST_FORMAT..."s:
- also, our own choices for dynamic payload types. This is our master
- table for transmission */
-static struct rtpPayloadType static_RTP_PT[MAX_RTP_PT] = {
- [0] = {1, AST_FORMAT_ULAW},
-#ifdef USE_DEPRECATED_G726
- [2] = {1, AST_FORMAT_G726}, /* Technically this is G.721, but if Cisco can do it, so can we... */
-#endif
- [3] = {1, AST_FORMAT_GSM},
- [4] = {1, AST_FORMAT_G723_1},
- [5] = {1, AST_FORMAT_ADPCM}, /* 8 kHz */
- [6] = {1, AST_FORMAT_ADPCM}, /* 16 kHz */
- [7] = {1, AST_FORMAT_LPC10},
- [8] = {1, AST_FORMAT_ALAW},
- [10] = {1, AST_FORMAT_SLINEAR}, /* 2 channels */
- [11] = {1, AST_FORMAT_SLINEAR}, /* 1 channel */
- [13] = {0, AST_RTP_CN},
- [16] = {1, AST_FORMAT_ADPCM}, /* 11.025 kHz */
- [17] = {1, AST_FORMAT_ADPCM}, /* 22.050 kHz */
- [18] = {1, AST_FORMAT_G729A},
- [19] = {0, AST_RTP_CN}, /* Also used for CN */
- [26] = {1, AST_FORMAT_JPEG},
- [31] = {1, AST_FORMAT_H261},
- [34] = {1, AST_FORMAT_H263},
- [103] = {1, AST_FORMAT_H263_PLUS},
- [97] = {1, AST_FORMAT_ILBC},
- [101] = {0, AST_RTP_DTMF},
- [110] = {1, AST_FORMAT_SPEEX},
- [111] = {1, AST_FORMAT_G726},
- [121] = {0, AST_RTP_CISCO_DTMF}, /* Must be type 121 */
-};
-
-void ast_rtp_pt_clear(struct ast_rtp* rtp)
-{
- int i;
- if (!rtp)
- return;
-
- for (i = 0; i < MAX_RTP_PT; ++i) {
- rtp->current_RTP_PT[i].isAstFormat = 0;
- rtp->current_RTP_PT[i].code = 0;
- }
-
- rtp->rtp_lookup_code_cache_isAstFormat = 0;
- rtp->rtp_lookup_code_cache_code = 0;
- rtp->rtp_lookup_code_cache_result = 0;
-}
-
-void ast_rtp_pt_default(struct ast_rtp* rtp)
-{
- int i;
-
- /* Initialize to default payload types */
- for (i = 0; i < MAX_RTP_PT; ++i) {
- rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat;
- rtp->current_RTP_PT[i].code = static_RTP_PT[i].code;
- }
-
- rtp->rtp_lookup_code_cache_isAstFormat = 0;
- rtp->rtp_lookup_code_cache_code = 0;
- rtp->rtp_lookup_code_cache_result = 0;
-}
-
-/* Make a note of a RTP paymoad type that was seen in a SDP "m=" line. */
-/* By default, use the well-known value for this type (although it may */
-/* still be set to a different value by a subsequent "a=rtpmap:" line): */
-void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt) {
- if (pt < 0 || pt > MAX_RTP_PT)
- return; /* bogus payload type */
-
- if (static_RTP_PT[pt].code != 0) {
- rtp->current_RTP_PT[pt] = static_RTP_PT[pt];
- }
-}
-
-/* Make a note of a RTP payload type (with MIME type) that was seen in */
-/* a SDP "a=rtpmap:" line. */
-void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
- char* mimeType, char* mimeSubtype) {
- int i;
-
- if (pt < 0 || pt > MAX_RTP_PT)
- return; /* bogus payload type */
-
- for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
- if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 &&
- strcasecmp(mimeType, mimeTypes[i].type) == 0) {
- rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType;
- return;
- }
- }
-}
-
-/* Return the union of all of the codecs that were set by rtp_set...() calls */
-/* They're returned as two distinct sets: AST_FORMATs, and AST_RTPs */
-void ast_rtp_get_current_formats(struct ast_rtp* rtp,
- int* astFormats, int* nonAstFormats) {
- int pt;
-
- *astFormats = *nonAstFormats = 0;
- for (pt = 0; pt < MAX_RTP_PT; ++pt) {
- if (rtp->current_RTP_PT[pt].isAstFormat) {
- *astFormats |= rtp->current_RTP_PT[pt].code;
- } else {
- *nonAstFormats |= rtp->current_RTP_PT[pt].code;
- }
- }
-}
-
-void ast_rtp_offered_from_local(struct ast_rtp* rtp, int local) {
- if (rtp)
- rtp->rtp_offered_from_local = local;
- else
- ast_log(LOG_WARNING, "rtp structure is null\n");
-}
-
-struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt)
-{
- struct rtpPayloadType result;
-
- result.isAstFormat = result.code = 0;
- if (pt < 0 || pt > MAX_RTP_PT)
- return result; /* bogus payload type */
-
- /* Start with the negotiated codecs */
- if (!rtp->rtp_offered_from_local)
- result = rtp->current_RTP_PT[pt];
-
- /* If it doesn't exist, check our static RTP type list, just in case */
- if (!result.code)
- result = static_RTP_PT[pt];
- return result;
-}
-
-/* Looks up an RTP code out of our *static* outbound list */
-int ast_rtp_lookup_code(struct ast_rtp* rtp, const int isAstFormat, const int code) {
-
- int pt;
-
- if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat &&
- code == rtp->rtp_lookup_code_cache_code) {
-
- /* Use our cached mapping, to avoid the overhead of the loop below */
- return rtp->rtp_lookup_code_cache_result;
- }
-
- /* Check the dynamic list first */
- for (pt = 0; pt < MAX_RTP_PT; ++pt) {
- if (rtp->current_RTP_PT[pt].code == code && rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) {
- rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat;
- rtp->rtp_lookup_code_cache_code = code;
- rtp->rtp_lookup_code_cache_result = pt;
- return pt;
- }
- }
-
- /* Then the static list */
- for (pt = 0; pt < MAX_RTP_PT; ++pt) {
- if (static_RTP_PT[pt].code == code && static_RTP_PT[pt].isAstFormat == isAstFormat) {
- rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat;
- rtp->rtp_lookup_code_cache_code = code;
- rtp->rtp_lookup_code_cache_result = pt;
- return pt;
- }
- }
- return -1;
-}
-
-char* ast_rtp_lookup_mime_subtype(const int isAstFormat, const int code) {
-
- int i;
-
- for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
- if (mimeTypes[i].payloadType.code == code && mimeTypes[i].payloadType.isAstFormat == isAstFormat) {
- return mimeTypes[i].subtype;
- }
- }
- return "";
-}
-
-char *ast_rtp_lookup_mime_multiple(char *buf, int size, const int capability, const int isAstFormat)
-{
- int format;
- unsigned len;
- char *end = buf;
- char *start = buf;
-
- if (!buf || !size)
- return NULL;
-
- snprintf(end, size, "0x%x (", capability);
-
- len = strlen(end);
- end += len;
- size -= len;
- start = end;
-
- for (format = 1; format < AST_RTP_MAX; format <<= 1) {
- if (capability & format) {
- const char *name = ast_rtp_lookup_mime_subtype(isAstFormat, format);
- snprintf(end, size, "%s|", name);
- len = strlen(end);
- end += len;
- size -= len;
- }
- }
-
- if (start == end)
- snprintf(start, size, "nothing)");
- else if (size > 1)
- *(end -1) = ')';
-
- return buf;
-}
-
-static int rtp_socket(void)
-{
- int s;
- long flags;
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s > -1) {
- flags = fcntl(s, F_GETFL);
- fcntl(s, F_SETFL, flags | O_NONBLOCK);
-#ifdef SO_NO_CHECK
- if (nochecksums)
- setsockopt(s, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
-#endif
- }
- return s;
-}
-
-/*!
- * \brief Initialize a new RTCP session.
- *
- * \returns The newly initialized RTCP session.
- */
-static struct ast_rtcp *ast_rtcp_new(void)
-{
- struct ast_rtcp *rtcp;
- rtcp = malloc(sizeof(struct ast_rtcp));
- if (!rtcp)
- return NULL;
- memset(rtcp, 0, sizeof(struct ast_rtcp));
- rtcp->s = rtp_socket();
- rtcp->us.sin_family = AF_INET;
- if (rtcp->s < 0) {
- free(rtcp);
- ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
- return NULL;
- }
- return rtcp;
-}
-
-struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr addr)
-{
- struct ast_rtp *rtp;
- int x;
- int first;
- int startplace;
- rtp = malloc(sizeof(struct ast_rtp));
- if (!rtp)
- return NULL;
- memset(rtp, 0, sizeof(struct ast_rtp));
- rtp->them.sin_family = AF_INET;
- rtp->us.sin_family = AF_INET;
- rtp->s = rtp_socket();
- rtp->ssrc = rand();
- rtp->seqno = rand() & 0xffff;
- if (rtp->s < 0) {
- free(rtp);
- ast_log(LOG_ERROR, "Unable to allocate socket: %s\n", strerror(errno));
- return NULL;
- }
- if (sched && rtcpenable) {
- rtp->sched = sched;
- rtp->rtcp = ast_rtcp_new();
- }
-
- /* Select a random port number in the range of possible RTP */
- x = (rand() % (rtpend-rtpstart)) + rtpstart;
- x = x & ~1;
- /* Save it for future references. */
- startplace = x;
- /* Iterate tring to bind that port and incrementing it otherwise untill a port was found or no ports are available. */
- for (;;) {
- /* Must be an even port number by RTP spec */
- rtp->us.sin_port = htons(x);
- rtp->us.sin_addr = addr;
- /* If there's rtcp, initialize it as well. */
- if (rtp->rtcp)
- rtp->rtcp->us.sin_port = htons(x + 1);
- /* Try to bind it/them. */
- if (!(first = bind(rtp->s, (struct sockaddr *)&rtp->us, sizeof(rtp->us))) &&
- (!rtp->rtcp || !bind(rtp->rtcp->s, (struct sockaddr *)&rtp->rtcp->us, sizeof(rtp->rtcp->us))))
- break;
- if (!first) {
- /* Primary bind succeeded! Gotta recreate it */
- close(rtp->s);
- rtp->s = rtp_socket();
- }
- if (errno != EADDRINUSE) {
- /* We got an error that wasn't expected, abort! */
- ast_log(LOG_ERROR, "Unexpected bind error: %s\n", strerror(errno));
- close(rtp->s);
- if (rtp->rtcp) {
- close(rtp->rtcp->s);
- free(rtp->rtcp);
- }
- free(rtp);
- return NULL;
- }
- /* The port was used, increment it (by two). */
- x += 2;
- /* Did we go over the limit ? */
- if (x > rtpend)
- /* then, start from the begingig. */
- x = (rtpstart + 1) & ~1;
- /* Check if we reached the place were we started. */
- if (x == startplace) {
- /* If so, there's no ports available. */
- ast_log(LOG_ERROR, "No RTP ports remaining. Can't setup media stream for this call.\n");
- close(rtp->s);
- if (rtp->rtcp) {
- close(rtp->rtcp->s);
- free(rtp->rtcp);
- }
- free(rtp);
- return NULL;
- }
- }
- if (io && sched && callbackmode) {
- /* Operate this one in a callback mode */
- rtp->sched = sched;
- rtp->io = io;
- rtp->ioid = ast_io_add(rtp->io, rtp->s, rtpread, AST_IO_IN, rtp);
- }
- ast_rtp_pt_default(rtp);
- return rtp;
-}
-
-struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode)
-{
- struct in_addr ia;
-
- memset(&ia, 0, sizeof(ia));
- return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia);
-}
-
-int ast_rtp_settos(struct ast_rtp *rtp, int tos)
-{
- int res;
-
- if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))))
- ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
- return res;
-}
-
-void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them)
-{
- rtp->them.sin_port = them->sin_port;
- rtp->them.sin_addr = them->sin_addr;
- if (rtp->rtcp) {
- rtp->rtcp->them.sin_port = htons(ntohs(them->sin_port) + 1);
- rtp->rtcp->them.sin_addr = them->sin_addr;
- }
- rtp->rxseqno = 0;
-}
-
-void ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them)
-{
- them->sin_family = AF_INET;
- them->sin_port = rtp->them.sin_port;
- them->sin_addr = rtp->them.sin_addr;
-}
-
-void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us)
-{
- memcpy(us, &rtp->us, sizeof(rtp->us));
-}
-
-#ifdef MIDCOM /* RANCH */
-void ast_rtp_nat_us(struct ast_rtp *rtp, struct sockaddr_in *our_nat)
-{
- memcpy(&rtp->them_midcom_nat, our_nat, sizeof(rtp->them_midcom_nat));
-}
-
-void ast_rtp_get_their_nat(struct ast_rtp *rtp, struct sockaddr_in *their_nat)
-{
- their_nat->sin_family = AF_INET;
- their_nat->sin_port = rtp->them_midcom_nat.sin_port;
- their_nat->sin_addr = rtp->them_midcom_nat.sin_addr;
-}
-#endif
-
-void ast_rtp_stop(struct ast_rtp *rtp)
-{
- memset(&rtp->them.sin_addr, 0, sizeof(rtp->them.sin_addr));
- memset(&rtp->them.sin_port, 0, sizeof(rtp->them.sin_port));
- if (rtp->rtcp) {
- memset(&rtp->rtcp->them.sin_addr, 0, sizeof(rtp->them.sin_addr));
- memset(&rtp->rtcp->them.sin_port, 0, sizeof(rtp->them.sin_port));
- }
-}
-
-void ast_rtp_reset(struct ast_rtp *rtp)
-{
- memset(&rtp->rxcore, 0, sizeof(rtp->rxcore));
- memset(&rtp->txcore, 0, sizeof(rtp->txcore));
- memset(&rtp->dtmfmute, 0, sizeof(rtp->dtmfmute));
- rtp->lastts = 0;
- rtp->lastdigitts = 0;
- rtp->lastrxts = 0;
- rtp->lastividtimestamp = 0;
- rtp->lastovidtimestamp = 0;
- rtp->lasteventseqn = 0;
- rtp->lasteventendseqn = 0;
- rtp->lasttxformat = 0;
- rtp->lastrxformat = 0;
- rtp->dtmfcount = 0;
- rtp->dtmfduration = 0;
- rtp->seqno = 0;
- rtp->rxseqno = 0;
-}
-
-void ast_rtp_destroy(struct ast_rtp *rtp)
-{
- if (rtp->smoother)
- ast_smoother_free(rtp->smoother);
- if (rtp->ioid)
- ast_io_remove(rtp->io, rtp->ioid);
- if (rtp->s > -1)
- close(rtp->s);
- if (rtp->rtcp) {
- close(rtp->rtcp->s);
- free(rtp->rtcp);
- }
- free(rtp);
-}
-
-static unsigned int calc_txstamp(struct ast_rtp *rtp, struct timeval *delivery)
-{
- struct timeval t;
- long ms;
- if (ast_tvzero(rtp->txcore)) {
- rtp->txcore = ast_tvnow();
- /* Round to 20ms for nice, pretty timestamps */
- rtp->txcore.tv_usec -= rtp->txcore.tv_usec % 20000;
- }
- /* Use previous txcore if available */
- t = (delivery && !ast_tvzero(*delivery)) ? *delivery : ast_tvnow();
- ms = ast_tvdiff_ms(t, rtp->txcore);
- if (ms < 0)
- ms = 0;
- /* Use what we just got for next time */
- rtp->txcore = t;
- return (unsigned int) ms;
-}
-
-int ast_rtp_senddigit(struct ast_rtp *rtp, char digit)
-{
- unsigned int *rtpheader;
- int hdrlen = 12;
- int res;
- int x;
- int payload;
- char data[256];
- char iabuf[INET_ADDRSTRLEN];
-
- if ((digit <= '9') && (digit >= '0'))
- digit -= '0';
- else if (digit == '*')
- digit = 10;
- else if (digit == '#')
- digit = 11;
- else if ((digit >= 'A') && (digit <= 'D'))
- digit = digit - 'A' + 12;
- else if ((digit >= 'a') && (digit <= 'd'))
- digit = digit - 'a' + 12;
- else {
- ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit);
- return -1;
- }
- payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_DTMF);
-
- /* If we have no peer, return immediately */
- if (!rtp->them.sin_addr.s_addr)
- return 0;
-
- rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000));
-
- /* Get a pointer to the header */
- rtpheader = (unsigned int *)data;
- rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno));
- rtpheader[1] = htonl(rtp->lastdigitts);
- rtpheader[2] = htonl(rtp->ssrc);
- rtpheader[3] = htonl((digit << 24) | (0xa << 16) | (0));
- for (x = 0; x < 6; x++) {
- if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) {
- res = sendto(rtp->s, (void *) rtpheader, hdrlen + 4, 0, (struct sockaddr *) &rtp->them, sizeof(rtp->them));
- if (res < 0)
- ast_log(LOG_ERROR, "RTP Transmission error to %s:%d: %s\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr),
- ntohs(rtp->them.sin_port), strerror(errno));
- if (rtp_debug_test_addr(&rtp->them))
- ast_verbose("Sent RTP packet to %s:%d (type %d, seq %u, ts %u, len %u)\n",
- ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr),
- ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, res - hdrlen);
- }
- /* Sequence number of last two end packets does not get incremented */
- if (x < 3)
- rtp->seqno++;
- /* Clear marker bit and set seqno */
- rtpheader[0] = htonl((2 << 30) | (payload << 16) | (rtp->seqno));
- /* For the last three packets, set the duration and the end bit */
- if (x == 2) {
-#if 0
- /* No, this is wrong... Do not increment lastdigitts, that's not according
- to the RFC, as best we can determine */
- rtp->lastdigitts++; /* or else the SPA3000 will click instead of beeping... */
- rtpheader[1] = htonl(rtp->lastdigitts);
-#endif
- /* Make duration 800 (100ms) */
- rtpheader[3] |= htonl((800));
- /* Set the End bit */
- rtpheader[3] |= htonl((1 << 23));
- }
- }
- /* Increment the digit timestamp by 120ms, to ensure that digits
- sent sequentially with no intervening non-digit packets do not
- get sent with the same timestamp, and that sequential digits
- have some 'dead air' in between them
- */
- rtp->lastdigitts += 960;
- /* Increment the sequence number to reflect the last packet
- that was sent
- */
- rtp->seqno++;
- return 0;
-}
-
-int ast_rtp_sendcng(struct ast_rtp *rtp, int level)
-{
- unsigned int *rtpheader;
- int hdrlen = 12;
- int res;
- int payload;
- char data[256];
- char iabuf[INET_ADDRSTRLEN];
- level = 127 - (level & 0x7f);
- payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_CN);
-
- /* If we have no peer, return immediately */
- if (!rtp->them.sin_addr.s_addr)
- return 0;
-
- rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000));
-
- /* Get a pointer to the header */
- rtpheader = (unsigned int *)data;
- rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno++));
- rtpheader[1] = htonl(rtp->lastts);
- rtpheader[2] = htonl(rtp->ssrc);
- data[12] = level;
- if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) {
- res = sendto(rtp->s, (void *)rtpheader, hdrlen + 1, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them));
- if (res <0)
- ast_log(LOG_ERROR, "RTP Comfort Noise Transmission error to %s:%d: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno));
- if(rtp_debug_test_addr(&rtp->them))
- ast_verbose("Sent Comfort Noise RTP packet to %s:%d (type %d, seq %d, ts %d, len %d)\n"
- , ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastts,res - hdrlen);
-
- }
- return 0;
-}
-
-static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec)
-{
- unsigned char *rtpheader;
- char iabuf[INET_ADDRSTRLEN];
- int hdrlen = 12;
- int res;
- unsigned int ms;
- int pred;
- int mark = 0;
-
- ms = calc_txstamp(rtp, &f->delivery);
- /* Default prediction */
- if (f->subclass < AST_FORMAT_MAX_AUDIO) {
- pred = rtp->lastts + f->samples;
-
- /* Re-calculate last TS */
- rtp->lastts = rtp->lastts + ms * 8;
- if (ast_tvzero(f->delivery)) {
- /* If this isn't an absolute delivery time, Check if it is close to our prediction,
- and if so, go with our prediction */
- if (abs(rtp->lastts - pred) < MAX_TIMESTAMP_SKEW)
- rtp->lastts = pred;
- else {
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Difference is %d, ms is %d\n", abs(rtp->lastts - pred), ms);
- mark = 1;
- }
- }
- } else {
- mark = f->subclass & 0x1;
- pred = rtp->lastovidtimestamp + f->samples;
- /* Re-calculate last TS */
- rtp->lastts = rtp->lastts + ms * 90;
- /* If it's close to our prediction, go for it */
- if (ast_tvzero(f->delivery)) {
- if (abs(rtp->lastts - pred) < 7200) {
- rtp->lastts = pred;
- rtp->lastovidtimestamp += f->samples;
- } else {
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Difference is %d, ms is %d (%d), pred/ts/samples %d/%d/%d\n", abs(rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, f->samples);
- rtp->lastovidtimestamp = rtp->lastts;
- }
- }
- }
- /* If the timestamp for non-digit packets has moved beyond the timestamp
- for digits, update the digit timestamp.
- */
- if (rtp->lastts > rtp->lastdigitts)
- rtp->lastdigitts = rtp->lastts;
-
- /* Get a pointer to the header */
- rtpheader = (unsigned char *)(f->data - hdrlen);
-
- put_unaligned_uint32(rtpheader, htonl((2 << 30) | (codec << 16) | (rtp->seqno) | (mark << 23)));
- put_unaligned_uint32(rtpheader + 4, htonl(rtp->lastts));
- put_unaligned_uint32(rtpheader + 8, htonl(rtp->ssrc));
-
- if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) {
- res = sendto(rtp->s, (void *)rtpheader, f->datalen + hdrlen, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them));
- if (res <0) {
- if (!rtp->nat || (rtp->nat && (ast_test_flag(rtp, FLAG_NAT_ACTIVE) == FLAG_NAT_ACTIVE))) {
- ast_log(LOG_DEBUG, "RTP Transmission error of packet %d to %s:%d: %s\n", rtp->seqno, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno));
- } else if ((ast_test_flag(rtp, FLAG_NAT_ACTIVE) == FLAG_NAT_INACTIVE) || rtpdebug) {
- /* Only give this error message once if we are not RTP debugging */
- if (option_debug || rtpdebug)
- ast_log(LOG_DEBUG, "RTP NAT: Can't write RTP to private address %s:%d, waiting for other end to send audio...\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port));
- ast_set_flag(rtp, FLAG_NAT_INACTIVE_NOWARN);
- }
- }
-
- if(rtp_debug_test_addr(&rtp->them))
- ast_verbose("Sent RTP packet to %s:%d (type %d, seq %u, ts %u, len %u)\n"
- , ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), codec, rtp->seqno, rtp->lastts,res - hdrlen);
- }
-
- rtp->seqno++;
-
- return 0;
-}
-
-int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
-{
- struct ast_frame *f;
- int codec;
- int hdrlen = 12;
- int subclass;
-
-
- /* If we have no peer, return immediately */
- if (!rtp->them.sin_addr.s_addr)
- return 0;
-
- /* If there is no data length, return immediately */
- if (!_f->datalen)
- return 0;
-
- /* Make sure we have enough space for RTP header */
- if ((_f->frametype != AST_FRAME_VOICE) && (_f->frametype != AST_FRAME_VIDEO)) {
- ast_log(LOG_WARNING, "RTP can only send voice\n");
- return -1;
- }
-
- subclass = _f->subclass;
- if (_f->frametype == AST_FRAME_VIDEO)
- subclass &= ~0x1;
-
- codec = ast_rtp_lookup_code(rtp, 1, subclass);
- if (codec < 0) {
- ast_log(LOG_WARNING, "Don't know how to send format %s packets with RTP\n", ast_getformatname(_f->subclass));
- return -1;
- }
-
- if (rtp->lasttxformat != subclass) {
- /* New format, reset the smoother */
- if (option_debug)
- ast_log(LOG_DEBUG, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass));
- rtp->lasttxformat = subclass;
- if (rtp->smoother)
- ast_smoother_free(rtp->smoother);
- rtp->smoother = NULL;
- }
-
-
- switch(subclass) {
- case AST_FORMAT_SLINEAR:
- if (!rtp->smoother) {
- rtp->smoother = ast_smoother_new(320);
- }
- if (!rtp->smoother) {
- ast_log(LOG_WARNING, "Unable to create smoother :(\n");
- return -1;
- }
- ast_smoother_feed_be(rtp->smoother, _f);
-
- while((f = ast_smoother_read(rtp->smoother)))
- ast_rtp_raw_write(rtp, f, codec);
- break;
- case AST_FORMAT_ULAW:
- case AST_FORMAT_ALAW:
- if (!rtp->smoother) {
- rtp->smoother = ast_smoother_new(160);
- }
- if (!rtp->smoother) {
- ast_log(LOG_WARNING, "Unable to create smoother :(\n");
- return -1;
- }
- ast_smoother_feed(rtp->smoother, _f);
-
- while((f = ast_smoother_read(rtp->smoother)))
- ast_rtp_raw_write(rtp, f, codec);
- break;
- case AST_FORMAT_ADPCM:
- case AST_FORMAT_G726:
- if (!rtp->smoother) {
- rtp->smoother = ast_smoother_new(80);
- }
- if (!rtp->smoother) {
- ast_log(LOG_WARNING, "Unable to create smoother :(\n");
- return -1;
- }
- ast_smoother_feed(rtp->smoother, _f);
-
- while((f = ast_smoother_read(rtp->smoother)))
- ast_rtp_raw_write(rtp, f, codec);
- break;
- case AST_FORMAT_G729A:
- if (!rtp->smoother) {
- rtp->smoother = ast_smoother_new(20);
- if (rtp->smoother)
- ast_smoother_set_flags(rtp->smoother, AST_SMOOTHER_FLAG_G729);
- }
- if (!rtp->smoother) {
- ast_log(LOG_WARNING, "Unable to create g729 smoother :(\n");
- return -1;
- }
- ast_smoother_feed(rtp->smoother, _f);
-
- while((f = ast_smoother_read(rtp->smoother)))
- ast_rtp_raw_write(rtp, f, codec);
- break;
- case AST_FORMAT_GSM:
- if (!rtp->smoother) {
- rtp->smoother = ast_smoother_new(33);
- }
- if (!rtp->smoother) {
- ast_log(LOG_WARNING, "Unable to create GSM smoother :(\n");
- return -1;
- }
- ast_smoother_feed(rtp->smoother, _f);
- while((f = ast_smoother_read(rtp->smoother)))
- ast_rtp_raw_write(rtp, f, codec);
- break;
- case AST_FORMAT_ILBC:
- if (!rtp->smoother) {
- rtp->smoother = ast_smoother_new(50);
- }
- if (!rtp->smoother) {
- ast_log(LOG_WARNING, "Unable to create ILBC smoother :(\n");
- return -1;
- }
- ast_smoother_feed(rtp->smoother, _f);
- while((f = ast_smoother_read(rtp->smoother)))
- ast_rtp_raw_write(rtp, f, codec);
- break;
- default:
- ast_log(LOG_WARNING, "Not sure about sending format %s packets\n", ast_getformatname(subclass));
- /* fall through to... */
- case AST_FORMAT_H261:
- case AST_FORMAT_H263:
- case AST_FORMAT_H263_PLUS:
- case AST_FORMAT_G723_1:
- case AST_FORMAT_LPC10:
- case AST_FORMAT_SPEEX:
- /* Don't buffer outgoing frames; send them one-per-packet: */
- if (_f->offset < hdrlen) {
- f = ast_frdup(_f);
- } else {
- f = _f;
- }
- ast_rtp_raw_write(rtp, f, codec);
- }
-
- return 0;
-}
-
-/*--- ast_rtp_proto_unregister: Unregister interface to channel driver */
-void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto)
-{
- struct ast_rtp_protocol *cur, *prev;
-
- cur = protos;
- prev = NULL;
- while(cur) {
- if (cur == proto) {
- if (prev)
- prev->next = proto->next;
- else
- protos = proto->next;
- return;
- }
- prev = cur;
- cur = cur->next;
- }
-}
-
-/*--- ast_rtp_proto_register: Register interface to channel driver */
-int ast_rtp_proto_register(struct ast_rtp_protocol *proto)
-{
- struct ast_rtp_protocol *cur;
- cur = protos;
- while(cur) {
- if (cur->type == proto->type) {
- ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
- return -1;
- }
- cur = cur->next;
- }
- proto->next = protos;
- protos = proto;
- return 0;
-}
-
-/*--- get_proto: Get channel driver interface structure */
-static struct ast_rtp_protocol *get_proto(struct ast_channel *chan)
-{
- struct ast_rtp_protocol *cur;
-
- cur = protos;
- while(cur) {
- if (cur->type == chan->type) {
- return cur;
- }
- cur = cur->next;
- }
- return NULL;
-}
-
-/* ast_rtp_bridge: Bridge calls. If possible and allowed, initiate
- re-invite so the peers exchange media directly outside
- of Asterisk. */
-enum ast_bridge_result ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms)
-{
- struct ast_frame *f;
- struct ast_channel *who, *cs[3];
- struct ast_rtp *p0, *p1; /* Audio RTP Channels */
- struct ast_rtp *vp0, *vp1; /* Video RTP channels */
- struct ast_rtp_protocol *pr0, *pr1;
- struct sockaddr_in ac0, ac1;
- struct sockaddr_in vac0, vac1;
- struct sockaddr_in t0, t1;
- struct sockaddr_in vt0, vt1;
- char iabuf[INET_ADDRSTRLEN];
- void *pvt0, *pvt1;
- int codec0,codec1, oldcodec0, oldcodec1;
-
- memset(&vt0, 0, sizeof(vt0));
- memset(&vt1, 0, sizeof(vt1));
- memset(&vac0, 0, sizeof(vac0));
- memset(&vac1, 0, sizeof(vac1));
-
- /* if need DTMF, cant native bridge */
- if (flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1))
- return AST_BRIDGE_FAILED_NOWARN;
-
- /* Lock channels */
- ast_mutex_lock(&c0->lock);
- while(ast_mutex_trylock(&c1->lock)) {
- ast_mutex_unlock(&c0->lock);
- usleep(1);
- ast_mutex_lock(&c0->lock);
- }
-
- /* Find channel driver interfaces */
- pr0 = get_proto(c0);
- pr1 = get_proto(c1);
- if (!pr0) {
- ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name);
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
- return AST_BRIDGE_FAILED;
- }
- if (!pr1) {
- ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name);
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
- return AST_BRIDGE_FAILED;
- }
-
- /* Get channel specific interface structures */
- pvt0 = c0->tech_pvt;
- pvt1 = c1->tech_pvt;
-
- /* Get audio and video interface (if native bridge is possible) */
- p0 = pr0->get_rtp_info(c0);
- if (pr0->get_vrtp_info)
- vp0 = pr0->get_vrtp_info(c0);
- else
- vp0 = NULL;
- p1 = pr1->get_rtp_info(c1);
- if (pr1->get_vrtp_info)
- vp1 = pr1->get_vrtp_info(c1);
- else
- vp1 = NULL;
-
- /* Check if bridge is still possible (In SIP canreinvite=no stops this, like NAT) */
- if (!p0 || !p1) {
- /* Somebody doesn't want to play... */
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
- return AST_BRIDGE_FAILED_NOWARN;
- }
- /* Get codecs from both sides */
- if (pr0->get_codec)
- codec0 = pr0->get_codec(c0);
- else
- codec0 = 0;
- if (pr1->get_codec)
- codec1 = pr1->get_codec(c1);
- else
- codec1 = 0;
- if (pr0->get_codec && pr1->get_codec) {
- /* Hey, we can't do reinvite if both parties speak different codecs */
- if (!(codec0 & codec1)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Channel codec0 = %d is not codec1 = %d, cannot native bridge in RTP.\n", codec0, codec1);
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
- return AST_BRIDGE_FAILED_NOWARN;
- }
- }
-
- /* Ok, we should be able to redirect the media. Start with one channel */
- if (pr0->set_rtp_peer(c0, p1, vp1, codec1, ast_test_flag(p1, FLAG_NAT_ACTIVE)))
- ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name);
- else {
- /* Store RTP peer */
- ast_rtp_get_peer(p1, &ac1);
- if (vp1)
- ast_rtp_get_peer(vp1, &vac1);
- }
- /* Then test the other channel */
- if (pr1->set_rtp_peer(c1, p0, vp0, codec0, ast_test_flag(p0, FLAG_NAT_ACTIVE)))
- ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name);
- else {
- /* Store RTP peer */
- ast_rtp_get_peer(p0, &ac0);
- if (vp0)
- ast_rtp_get_peer(vp0, &vac0);
- }
- ast_mutex_unlock(&c0->lock);
- ast_mutex_unlock(&c1->lock);
- /* External RTP Bridge up, now loop and see if something happes that force us to take the
- media back to Asterisk */
- cs[0] = c0;
- cs[1] = c1;
- cs[2] = NULL;
- oldcodec0 = codec0;
- oldcodec1 = codec1;
- for (;;) {
- /* Check if something changed... */
- if ((c0->tech_pvt != pvt0) ||
- (c1->tech_pvt != pvt1) ||
- (c0->masq || c0->masqr || c1->masq || c1->masqr)) {
- ast_log(LOG_DEBUG, "Oooh, something is weird, backing out\n");
- if (c0->tech_pvt == pvt0) {
- if (pr0->set_rtp_peer(c0, NULL, NULL, 0, 0))
- ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", c0->name);
- }
- if (c1->tech_pvt == pvt1) {
- if (pr1->set_rtp_peer(c1, NULL, NULL, 0, 0))
- ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", c1->name);
- }
- return AST_BRIDGE_RETRY;
- }
- /* Now check if they have changed address */
- ast_rtp_get_peer(p1, &t1);
- ast_rtp_get_peer(p0, &t0);
- if (pr0->get_codec)
- codec0 = pr0->get_codec(c0);
- if (pr1->get_codec)
- codec1 = pr1->get_codec(c1);
- if (vp1)
- ast_rtp_get_peer(vp1, &vt1);
- if (vp0)
- ast_rtp_get_peer(vp0, &vt0);
- if (inaddrcmp(&t1, &ac1) || (vp1 && inaddrcmp(&vt1, &vac1)) || (codec1 != oldcodec1)) {
- if (option_debug > 1) {
- ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
- c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), t1.sin_addr), ntohs(t1.sin_port), codec1);
- ast_log(LOG_DEBUG, "Oooh, '%s' changed end vaddress to %s:%d (format %d)\n",
- c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), vt1.sin_addr), ntohs(vt1.sin_port), codec1);
- ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
- c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), ac1.sin_addr), ntohs(ac1.sin_port), oldcodec1);
- ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
- c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), vac1.sin_addr), ntohs(vac1.sin_port), oldcodec1);
- }
- if (pr0->set_rtp_peer(c0, t1.sin_addr.s_addr ? p1 : NULL, vt1.sin_addr.s_addr ? vp1 : NULL, codec1, ast_test_flag(p1, FLAG_NAT_ACTIVE)))
- ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c0->name, c1->name);
- memcpy(&ac1, &t1, sizeof(ac1));
- memcpy(&vac1, &vt1, sizeof(vac1));
- oldcodec1 = codec1;
- }
- if (inaddrcmp(&t0, &ac0) || (vp0 && inaddrcmp(&vt0, &vac0))) {
- if (option_debug) {
- ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
- c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), t0.sin_addr), ntohs(t0.sin_port), codec0);
- ast_log(LOG_DEBUG, "Oooh, '%s' changed end vaddress to %s:%d (format %d)\n",
- c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), vt0.sin_addr), ntohs(vt0.sin_port), codec0);
- ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
- c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), ac0.sin_addr), ntohs(ac0.sin_port), oldcodec0);
- ast_log(LOG_DEBUG, "Oooh, '%s' wasv %s:%d/(format %d)\n",
- c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), vac0.sin_addr), ntohs(vac0.sin_port), oldcodec0);
- }
- if (pr1->set_rtp_peer(c1, t0.sin_addr.s_addr ? p0 : NULL, vt0.sin_addr.s_addr ? vp0 : NULL, codec0, ast_test_flag(p0, FLAG_NAT_ACTIVE)))
- ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c1->name, c0->name);
- memcpy(&ac0, &t0, sizeof(ac0));
- memcpy(&vac0, &vt0, sizeof(vac0));
- oldcodec0 = codec0;
- }
- who = ast_waitfor_n(cs, 2, &timeoutms);
- if (!who) {
- if (!timeoutms)
- return AST_BRIDGE_RETRY;
- if (option_debug)
- ast_log(LOG_DEBUG, "Ooh, empty read...\n");
- /* check for hangup / whentohangup */
- if (ast_check_hangup(c0) || ast_check_hangup(c1))
- break;
- continue;
- }
- f = ast_read(who);
- if (!f || ((f->frametype == AST_FRAME_DTMF) &&
- (((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) ||
- ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1))))) {
- *fo = f;
- *rc = who;
- if (option_debug)
- ast_log(LOG_DEBUG, "Oooh, got a %s\n", f ? "digit" : "hangup");
- if ((c0->tech_pvt == pvt0) && (!c0->_softhangup)) {
- if (pr0->set_rtp_peer(c0, NULL, NULL, 0, 0))
- ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", c0->name);
- }
- if ((c1->tech_pvt == pvt1) && (!c1->_softhangup)) {
- if (pr1->set_rtp_peer(c1, NULL, NULL, 0, 0))
- ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", c1->name);
- }
- return AST_BRIDGE_COMPLETE;
- } else if ((f->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
- if ((f->subclass == AST_CONTROL_HOLD) || (f->subclass == AST_CONTROL_UNHOLD) ||
- (f->subclass == AST_CONTROL_VIDUPDATE)) {
- ast_indicate(who == c0 ? c1 : c0, f->subclass);
- ast_frfree(f);
- } else {
- *fo = f;
- *rc = who;
- ast_log(LOG_DEBUG, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass, who->name);
- return AST_BRIDGE_COMPLETE;
- }
- } else {
- if ((f->frametype == AST_FRAME_DTMF) ||
- (f->frametype == AST_FRAME_VOICE) ||
- (f->frametype == AST_FRAME_VIDEO)) {
- /* Forward voice or DTMF frames if they happen upon us */
- if (who == c0) {
- ast_write(c1, f);
- } else if (who == c1) {
- ast_write(c0, f);
- }
- }
- ast_frfree(f);
- }
- /* Swap priority not that it's a big deal at this point */
- cs[2] = cs[0];
- cs[0] = cs[1];
- cs[1] = cs[2];
-
- }
- return AST_BRIDGE_FAILED;
-}
-
-static int rtp_do_debug_ip(int fd, int argc, char *argv[])
-{
- struct hostent *hp;
- struct ast_hostent ahp;
- char iabuf[INET_ADDRSTRLEN];
- int port = 0;
- char *p, *arg;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
- arg = argv[3];
- p = strstr(arg, ":");
- if (p) {
- *p = '\0';
- p++;
- port = atoi(p);
- }
- hp = ast_gethostbyname(arg, &ahp);
- if (hp == NULL)
- return RESULT_SHOWUSAGE;
- rtpdebugaddr.sin_family = AF_INET;
- memcpy(&rtpdebugaddr.sin_addr, hp->h_addr, sizeof(rtpdebugaddr.sin_addr));
- rtpdebugaddr.sin_port = htons(port);
- if (port == 0)
- ast_cli(fd, "RTP Debugging Enabled for IP: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtpdebugaddr.sin_addr));
- else
- ast_cli(fd, "RTP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtpdebugaddr.sin_addr), port);
- rtpdebug = 1;
- return RESULT_SUCCESS;
-}
-
-static int rtp_do_debug(int fd, int argc, char *argv[])
-{
- if(argc != 2) {
- if(argc != 4)
- return RESULT_SHOWUSAGE;
- return rtp_do_debug_ip(fd, argc, argv);
- }
- rtpdebug = 1;
- memset(&rtpdebugaddr,0,sizeof(rtpdebugaddr));
- ast_cli(fd, "RTP Debugging Enabled\n");
- return RESULT_SUCCESS;
-}
-
-static int rtp_no_debug(int fd, int argc, char *argv[])
-{
- if(argc !=3)
- return RESULT_SHOWUSAGE;
- rtpdebug = 0;
- ast_cli(fd,"RTP Debugging Disabled\n");
- return RESULT_SUCCESS;
-}
-
-static char debug_usage[] =
- "Usage: rtp debug [ip host[:port]]\n"
- " Enable dumping of all RTP packets to and from host.\n";
-
-static char no_debug_usage[] =
- "Usage: rtp no debug\n"
- " Disable all RTP debugging\n";
-
-static struct ast_cli_entry cli_debug_ip =
-{{ "rtp", "debug", "ip", NULL } , rtp_do_debug, "Enable RTP debugging on IP", debug_usage };
-
-static struct ast_cli_entry cli_debug =
-{{ "rtp", "debug", NULL } , rtp_do_debug, "Enable RTP debugging", debug_usage };
-
-static struct ast_cli_entry cli_no_debug =
-{{ "rtp", "no", "debug", NULL } , rtp_no_debug, "Disable RTP debugging", no_debug_usage };
-
-void ast_rtp_reload(void)
-{
- struct ast_config *cfg;
- char *s;
-
- rtpstart = 5000;
- rtpend = 31000;
- dtmftimeout = DEFAULT_DTMF_TIMEOUT;
- cfg = ast_config_load("rtp.conf");
- if (cfg) {
- if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) {
- rtpstart = atoi(s);
- if (rtpstart < 1024)
- rtpstart = 1024;
- if (rtpstart > 65535)
- rtpstart = 65535;
- }
- if ((s = ast_variable_retrieve(cfg, "general", "rtpend"))) {
- rtpend = atoi(s);
- if (rtpend < 1024)
- rtpend = 1024;
- if (rtpend > 65535)
- rtpend = 65535;
- }
- if ((s = ast_variable_retrieve(cfg, "general", "rtpchecksums"))) {
-#ifdef SO_NO_CHECK
- if (ast_false(s))
- nochecksums = 1;
- else
- nochecksums = 0;
-#else
- if (ast_false(s))
- ast_log(LOG_WARNING, "Disabling RTP checksums is not supported on this operating system!\n");
-#endif
- }
- if ((s = ast_variable_retrieve(cfg, "general", "dtmftimeout"))) {
- dtmftimeout = atoi(s);
- if ((dtmftimeout < 0) || (dtmftimeout > 20000)) {
- ast_log(LOG_WARNING, "DTMF timeout of '%d' outside range, using default of '%d' instead\n",
- dtmftimeout, DEFAULT_DTMF_TIMEOUT);
- dtmftimeout = DEFAULT_DTMF_TIMEOUT;
- };
- }
- ast_config_destroy(cfg);
- }
- if (rtpstart >= rtpend) {
- ast_log(LOG_WARNING, "Unreasonable values for RTP start/end port in rtp.conf\n");
- rtpstart = 5000;
- rtpend = 31000;
- }
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "RTP Allocating from port range %d -> %d\n", rtpstart, rtpend);
-
-}
-
-/*--- ast_rtp_init: Initialize the RTP system in Asterisk */
-void ast_rtp_init(void)
-{
- ast_cli_register(&cli_debug);
- ast_cli_register(&cli_debug_ip);
- ast_cli_register(&cli_no_debug);
- ast_rtp_reload();
-}
diff --git a/1.2-netsec/sample.call b/1.2-netsec/sample.call
deleted file mode 100644
index 750ef4ddf..000000000
--- a/1.2-netsec/sample.call
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-# This is a sample file that can be dumped in /var/spool/asterisk/outgoing
-# to generate a call.
-#
-# Comments are indicated by a '#' character that begins a line, or follows
-# a space or tab character. To be consistent with the configuration files
-# in Asterisk, comments can also be indicated by a semicolon. However, the
-# multiline comments (;-- --;) used in Asterisk configuration files are not
-# supported. Semicolons can be escaped by a backslash.
-#
-
-# Obviously, you MUST specify at least a channel in the same format as you
-# would for the "Dial" application. Only one channel name is permitted.
-#
-Channel: Zap/1
-#
-# You may also specify a wait time (default is 45 seconds) for how long to
-# wait for the channel to be answered, a retry time (default is 5 mins)
-# for how soon to retry this call, and a maximum number of retries (default
-# is 0) for how many times to retry this call.
-#
-MaxRetries: 2
-RetryTime: 60
-WaitTime: 30
-
-#
-# Once the call is answered, you must provide either an application/data
-# combination, or a context/extension/priority in which to start the PBX.
-#
-Context: default
-Extension: s
-Priority: 1
-
-#
-# Alternatively you can specify just an application
-# and its arguments to be run, instead of a context
-# extension and priority
-#
-#Application: VoiceMailMain
-#Data: 1234
-
-#
-# You can set the callerid that will be used for the outgoing call
-#
-#Callerid: Wakeup Call Service <(555) 555-5555>
-
-#
-# You can set channel variables that will be passed to the channel.
-# This includes writable dialplan functions.
-#
-#Set: file1=/tmp/to
-#Set: file2=/tmp/msg
-#Set: timestamp=20021023104500
-#Set: CDR(accountcode|r)=blort
-#Set: CDR(userfield|r)=42
diff --git a/1.2-netsec/say.c b/1.2-netsec/say.c
deleted file mode 100644
index 4e9f23703..000000000
--- a/1.2-netsec/say.c
+++ /dev/null
@@ -1,6116 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- * George Konstantoulakis <gkon@inaccessnetworks.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Say numbers and dates (maybe words one day too)
- *
- * \note 12-16-2004 : Support for Greek added by InAccess Networks (work funded by HOL, www.hol.gr)
- * George Konstantoulakis <gkon@inaccessnetworks.com>
- */
-
-#include <sys/types.h>
-#include <string.h>
-#include <stdlib.h>
-#include <netinet/in.h>
-#include <time.h>
-#include <ctype.h>
-#include <math.h>
-#include <stdio.h>
-
-#ifdef SOLARIS
-#include <iso/limits_iso.h>
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/say.h"
-#include "asterisk/lock.h"
-#include "asterisk/localtime.h"
-#include "asterisk/utils.h"
-
-/* Forward declaration */
-static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang);
-
-int ast_say_character_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
-{
- const char *fn;
- char fnbuf[256];
- char ltr;
- int num = 0;
- int res = 0;
-
- while (str[num]) {
- fn = NULL;
- switch (str[num]) {
- case ('*'):
- fn = "digits/star";
- break;
- case ('#'):
- fn = "digits/pound";
- break;
- case ('!'):
- fn = "letters/exclaimation-point";
- break;
- case ('@'):
- fn = "letters/at";
- break;
- case ('$'):
- fn = "letters/dollar";
- break;
- case ('-'):
- fn = "letters/dash";
- break;
- case ('.'):
- fn = "letters/dot";
- break;
- case ('='):
- fn = "letters/equals";
- break;
- case ('+'):
- fn = "letters/plus";
- break;
- case ('/'):
- fn = "letters/slash";
- break;
- case (' '):
- fn = "letters/space";
- break;
- case ('0'):
- case ('1'):
- case ('2'):
- case ('3'):
- case ('4'):
- case ('5'):
- case ('6'):
- case ('7'):
- case ('8'):
- case ('9'):
- strcpy(fnbuf, "digits/X");
- fnbuf[7] = str[num];
- fn = fnbuf;
- break;
- default:
- ltr = str[num];
- if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A'; /* file names are all lower-case */
- strcpy(fnbuf, "letters/X");
- fnbuf[8] = ltr;
- fn = fnbuf;
- }
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- ast_stopstream(chan);
- num++;
- }
-
- return res;
-}
-
-int ast_say_character_str(struct ast_channel *chan, const char *str, const char *ints, const char *lang)
-{
- return ast_say_character_str_full(chan, str, ints, lang, -1, -1);
-}
-
-int ast_say_phonetic_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
-{
- const char *fn;
- char fnbuf[256];
- char ltr;
- int num = 0;
- int res = 0;
-
- while (str[num]) {
- fn = NULL;
- switch (str[num]) {
- case ('*'):
- fn = "digits/star";
- break;
- case ('#'):
- fn = "digits/pound";
- break;
- case ('!'):
- fn = "letters/exclaimation-point";
- break;
- case ('@'):
- fn = "letters/at";
- break;
- case ('$'):
- fn = "letters/dollar";
- break;
- case ('-'):
- fn = "letters/dash";
- break;
- case ('.'):
- fn = "letters/dot";
- break;
- case ('='):
- fn = "letters/equals";
- break;
- case ('+'):
- fn = "letters/plus";
- break;
- case ('/'):
- fn = "letters/slash";
- break;
- case (' '):
- fn = "letters/space";
- break;
- case ('0'):
- case ('1'):
- case ('2'):
- case ('3'):
- case ('4'):
- case ('5'):
- case ('6'):
- case ('7'):
- case ('8'):
- strcpy(fnbuf, "digits/X");
- fnbuf[7] = str[num];
- fn = fnbuf;
- break;
- default: /* '9' falls here... */
- ltr = str[num];
- if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A'; /* file names are all lower-case */
- strcpy(fnbuf, "phonetic/X_p");
- fnbuf[9] = ltr;
- fn = fnbuf;
- }
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- ast_stopstream(chan);
- num++;
- }
-
- return res;
-}
-
-int ast_say_phonetic_str(struct ast_channel *chan, const char *str, const char *ints, const char *lang)
-{
- return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1);
-}
-
-int ast_say_digit_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
-{
- const char *fn;
- char fnbuf[256];
- int num = 0;
- int res = 0;
-
- while (str[num] && !res) {
- fn = NULL;
- switch (str[num]) {
- case ('*'):
- fn = "digits/star";
- break;
- case ('#'):
- fn = "digits/pound";
- break;
- case ('-'):
- fn = "digits/minus";
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- strcpy(fnbuf, "digits/X");
- fnbuf[7] = str[num];
- fn = fnbuf;
- break;
- }
- if (fn) {
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- ast_stopstream(chan);
- }
- num++;
- }
-
- return res;
-}
-
-int ast_say_digit_str(struct ast_channel *chan, const char *str, const char *ints, const char *lang)
-{
- return ast_say_digit_str_full(chan, str, ints, lang, -1, -1);
-}
-
-int ast_say_digits_full(struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd)
-{
- char fn2[256];
-
- snprintf(fn2, sizeof(fn2), "%d", num);
- return ast_say_digit_str_full(chan, fn2, ints, lang, audiofd, ctrlfd);
-}
-
-int ast_say_digits(struct ast_channel *chan, int num, const char *ints, const char *lang)
-{
- return ast_say_digits_full(chan, num, ints, lang, -1, -1);
-}
-
-/* Forward declarations */
-/*! \page Def_syntaxlang Asterisk Language Syntaxes supported
- \not Not really language codes.
- For these language codes, Asterisk will change the syntax when
- saying numbers (and in some cases dates and voicemail messages
- as well)
- \arg \b da - Danish
- \arg \b de - German
- \arg \b en - English (US)
- \arg \b en_GB - English (British)
- \arg \b es - Spanish, Mexican
- \arg \b fr - French
- \arg \b he - Hebrew
- \arg \b it - Italian
- \arg \b nl - Dutch
- \arg \b no - Norwegian
- \arg \b pl - Polish
- \arg \b pt - Portuguese
- \arg \b se - Swedish
- \arg \b tw - Taiwanese
- \arg \b ru - Russian
-
- \par Gender:
- For Some languages the numbers differ for gender and plural.
- \arg Use the option argument 'f' for female, 'm' for male and 'n' for neuter in languages like Portuguese, French, Spanish and German.
- \arg use the option argument 'c' is for commune and 'n' for neuter gender in nordic languages like Danish, Swedish and Norwegian.
- use the option argument 'p' for plural enumerations like in German
-
- Date/Time functions currently have less languages supported than saynumber().
-
- \todo Note that in future, we need to move to a model where we can differentiate further - e.g. between en_US & en_UK
-
- See contrib/i18n.testsuite.conf for some examples of the different syntaxes
-
- \par Portuguese
- Portuguese sound files needed for Time/Date functions:
- pt-ah
- pt-ao
- pt-de
- pt-e
- pt-ora
- pt-meianoite
- pt-meiodia
- pt-sss
-
- \par Spanish
- Spanish sound files needed for Time/Date functions:
- es-de
- es-el
-
- \par Italian
- Italian sound files needed for Time/Date functions:
- ore-una
- ore-mezzanotte
-
-*/
-
-/* Forward declarations of language specific variants of ast_say_number_full */
-static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
-static int ast_say_number_full_cz(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
-static int ast_say_number_full_es(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_fr(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_it(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
-static int ast_say_number_full_nl(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
-static int ast_say_number_full_no(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_pl(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_pt(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_se(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_number_full_tw(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
-static int ast_say_number_full_gr(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
-static int ast_say_number_full_ru(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-
-/* Forward declarations of language specific variants of ast_say_enumeration_full */
-static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
-static int ast_say_enumeration_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
-
-/* Forward declarations of ast_say_date, ast_say_datetime and ast_say_time functions */
-static int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-
-static int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_da(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_he(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
-
-static int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_time_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-
-static int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_datetime_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-
-static int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-static int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
-
-static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang)
-{
- int res;
- if ((res = ast_streamfile(chan, file, lang)))
- ast_log(LOG_WARNING, "Unable to play message %s\n", file);
- if (!res)
- res = ast_waitstream(chan, ints);
- return res;
-}
-
-/*! \brief ast_say_number_full: call language-specific functions */
-/* Called from AGI */
-int ast_say_number_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- if (!strcasecmp(language,"en") ) { /* English syntax */
- return(ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "cz") ) { /* Czech syntax */
- return(ast_say_number_full_cz(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "da") ) { /* Danish syntax */
- return(ast_say_number_full_da(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "de") ) { /* German syntax */
- return(ast_say_number_full_de(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "en_GB") ) { /* British syntax */
- return(ast_say_number_full_en_GB(chan, num, ints, language, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "no") ) { /* Norwegian syntax */
- return(ast_say_number_full_no(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "es") || !strcasecmp(language, "mx")) { /* Spanish syntax */
- return(ast_say_number_full_es(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "fr") ) { /* French syntax */
- return(ast_say_number_full_fr(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "he") ) { /* Hebrew syntax */
- return(ast_say_number_full_he(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "it") ) { /* Italian syntax */
- return(ast_say_number_full_it(chan, num, ints, language, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "nl") ) { /* Dutch syntax */
- return(ast_say_number_full_nl(chan, num, ints, language, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "pl") ) { /* Polish syntax */
- return(ast_say_number_full_pl(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "pt") ) { /* Portuguese syntax */
- return(ast_say_number_full_pt(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "se") ) { /* Swedish syntax */
- return(ast_say_number_full_se(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "tw")) { /* Taiwanese syntax */
- return(ast_say_number_full_tw(chan, num, ints, language, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "gr") ) { /* Greek syntax */
- return(ast_say_number_full_gr(chan, num, ints, language, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "ru") ) { /* Russian syntax */
- return(ast_say_number_full_ru(chan, num, ints, language, options, audiofd, ctrlfd));
- }
-
- /* Default to english */
- return(ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd));
-}
-
-/*! \brief ast_say_number: call language-specific functions without file descriptors */
-int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
-{
- return(ast_say_number_full(chan, num, ints, language, options, -1, -1));
-}
-
-/*! \brief ast_say_number_full_en: English syntax */
-/* This is the default syntax, if no other syntax defined in this file is used */
-static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- char fn[256] = "";
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- while(!res && (num || playh)) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playh) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- playh = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
- num -= ((num / 10) * 10);
- } else {
- if (num < 1000){
- snprintf(fn, sizeof(fn), "digits/%d", (num/100));
- playh++;
- num -= ((num / 100) * 100);
- } else {
- if (num < 1000000) { /* 1,000,000 */
- res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000;
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- if (num < 1000000000) { /* 1,000,000,000 */
- res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000000;
- snprintf(fn, sizeof(fn), "digits/million");
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- }
- }
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-static int exp10_int(int power)
-{
- int x, res= 1;
- for (x=0;x<power;x++)
- res *= 10;
- return res;
-}
-
-/*! \brief ast_say_number_full_cz: Czech syntax */
-/* files needed:
- * 1m,2m - gender male
- * 1w,2w - gender female
- * 3,4,...,20
- * 30,40,...,90
- *
- * hundereds - 100 - sto, 200 - 2ste, 300,400 3,4sta, 500,600,...,900 5,6,...9set
- *
- * for each number 10^(3n + 3) exist 3 files represented as:
- * 1 tousand = jeden tisic = 1_E3
- * 2,3,4 tousands = dva,tri,ctyri tisice = 2-3_E3
- * 5,6,... tousands = pet,sest,... tisic = 5_E3
- *
- * million = _E6
- * miliard = _E9
- * etc...
- *
- * tousand, milion are gender male, so 1 and 2 is 1m 2m
- * miliard is gender female, so 1 and 2 is 1w 2w
- */
-static int ast_say_number_full_cz(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- char fn[256] = "";
-
- int hundered = 0;
- int left = 0;
- int length = 0;
-
- /* options - w = woman, m = man, n = neutral. Defaultl is woman */
- if (!options)
- options = "w";
-
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- while(!res && (num || playh)) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (num < 3 ) {
- snprintf(fn, sizeof(fn), "digits/%d%c",num,options[0]);
- playh = 0;
- num = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/%d",num);
- playh = 0;
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
- num -= ((num / 10) * 10);
- } else if (num < 1000) {
- hundered = num / 100;
- if ( hundered == 1 ) {
- snprintf(fn, sizeof(fn), "digits/1sto");
- } else if ( hundered == 2 ) {
- snprintf(fn, sizeof(fn), "digits/2ste");
- } else {
- res = ast_say_number_full_cz(chan,hundered,ints,language,options,audiofd,ctrlfd);
- if (res)
- return res;
- if (hundered == 3 || hundered == 4) {
- snprintf(fn, sizeof(fn), "digits/sta");
- } else if ( hundered > 4 ) {
- snprintf(fn, sizeof(fn), "digits/set");
- }
- }
- num -= (hundered * 100);
- } else { /* num > 1000 */
- length = (int)log10(num)+1;
- while ( (length % 3 ) != 1 ) {
- length--;
- }
- left = num / (exp10_int(length-1));
- if ( left == 2 ) {
- switch (length-1) {
- case 9: options = "w"; /* 1,000,000,000 gender female */
- break;
- default : options = "m"; /* others are male */
- }
- }
- if ( left > 1 ) { /* we dont say "one thousand" but only thousand */
- res = ast_say_number_full_cz(chan,left,ints,language,options,audiofd,ctrlfd);
- if (res)
- return res;
- }
- if ( left >= 5 ) { /* >= 5 have the same declesion */
- snprintf(fn, sizeof(fn), "digits/5_E%d",length-1);
- } else if ( left >= 2 && left <= 4 ) {
- snprintf(fn, sizeof(fn), "digits/2-4_E%d",length-1);
- } else { /* left == 1 */
- snprintf(fn, sizeof(fn), "digits/1_E%d",length-1);
- }
- num -= left * (exp10_int(length-1));
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1)) {
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- } else {
- res = ast_waitstream(chan, ints);
- }
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_da: Danish syntax */
-/* New files:
- In addition to English, the following sounds are required: "1N", "millions", "and" and "1-and" through "9-and"
- */
-static int ast_say_number_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- int playa = 0;
- int cn = 1; /* +1 = commune; -1 = neuter */
- char fn[256] = "";
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- if (options && !strncasecmp(options, "n",1)) cn = -1;
-
- while(!res && (num || playh || playa )) {
- /* The grammar for Danish numbers is the same as for English except
- * for the following:
- * - 1 exists in both commune ("en", file "1N") and neuter ("et", file "1")
- * - numbers 20 through 99 are said in reverse order, i.e. 21 is
- * "one-and twenty" and 68 is "eight-and sixty".
- * - "million" is different in singular and plural form
- * - numbers > 1000 with zero as the third digit from last have an
- * "and" before the last two digits, i.e. 2034 is "two thousand and
- * four-and thirty" and 1000012 is "one million and twelve".
- */
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playh) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- playh = 0;
- } else if (playa) {
- snprintf(fn, sizeof(fn), "digits/and");
- playa = 0;
- } else if (num == 1 && cn == -1) {
- snprintf(fn, sizeof(fn), "digits/1N");
- num = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- int ones = num % 10;
- if (ones) {
- snprintf(fn, sizeof(fn), "digits/%d-and", ones);
- num -= ones;
- } else {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- }
- } else {
- if (num < 1000) {
- int hundreds = num / 100;
- if (hundreds == 1)
- snprintf(fn, sizeof(fn), "digits/1N");
- else
- snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
-
- playh++;
- num -= 100 * hundreds;
- if (num)
- playa++;
-
- } else {
- if (num < 1000000) {
- res = ast_say_number_full_da(chan, num / 1000, ints, language, "n", audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000;
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- if (num < 1000000000) {
- int millions = num / 1000000;
- res = ast_say_number_full_da(chan, millions, ints, language, "c", audiofd, ctrlfd);
- if (res)
- return res;
- if (millions == 1)
- snprintf(fn, sizeof(fn), "digits/million");
- else
- snprintf(fn, sizeof(fn), "digits/millions");
- num = num % 1000000;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- }
- if (num && num < 100)
- playa++;
- }
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_de: German syntax */
-/* New files:
- In addition to English, the following sounds are required:
- "millions"
- "1-and" through "9-and"
- "1F" (eine)
- "1N" (ein)
- NB "1" is recorded as 'eins'
- */
-static int ast_say_number_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- int res = 0, t = 0;
- int mf = 1; /* +1 = male and neuter; -1 = female */
- char fn[256] = "";
- char fna[256] = "";
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- if (options && (!strncasecmp(options, "f",1)))
- mf = -1;
-
- while(!res && num) {
- /* The grammar for German numbers is the same as for English except
- * for the following:
- * - numbers 20 through 99 are said in reverse order, i.e. 21 is
- * "one-and twenty" and 68 is "eight-and sixty".
- * - "one" varies according to gender
- * - 100 is 'hundert', however all other instances are 'ein hundert'
- * - 1000 is 'tausend', however all other instances are 'ein tausend'
- * - 1000000 is always 'eine million'
- * - "million" is different in singular and plural form
- */
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (num < 100 && t) {
- snprintf(fn, sizeof(fn), "digits/and");
- t = 0;
- } else if (num == 1 && mf == -1) {
- snprintf(fn, sizeof(fn), "digits/%dF", num);
- num = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- int ones = num % 10;
- if (ones) {
- snprintf(fn, sizeof(fn), "digits/%d-and", ones);
- num -= ones;
- } else {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- }
- } else if (num == 100 && t == 0) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- num = 0;
- } else if (num < 1000) {
- int hundreds = num / 100;
- num = num % 100;
- if (hundreds == 1) {
- snprintf(fn, sizeof(fn), "digits/1N");
- } else {
- snprintf(fn, sizeof(fn), "digits/%d", hundreds);
- }
- snprintf(fna, sizeof(fna), "digits/hundred");
- t = 1;
- } else if (num == 1000 && t == 0) {
- snprintf(fn, sizeof(fn), "digits/thousand");
- num = 0;
- } else if (num < 1000000) {
- int thousands = num / 1000;
- num = num % 1000;
- t = 1;
- if (thousands == 1) {
- snprintf(fn, sizeof(fn), "digits/1N");
- snprintf(fna, sizeof(fna), "digits/thousand");
- } else {
- res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/thousand");
- }
- } else if (num < 1000000000) {
- int millions = num / 1000000;
- num = num % 1000000;
- t = 1;
- if (millions == 1) {
- snprintf(fn, sizeof(fn), "digits/1F");
- snprintf(fna, sizeof(fna), "digits/million");
- } else {
- res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/millions");
- }
- } else if (num <= INT_MAX) {
- int billions = num / 1000000000;
- num = num % 1000000000;
- t = 1;
- if (billions == 1) {
- snprintf(fn, sizeof(fn), "digits/1F");
- snprintf(fna, sizeof(fna), "digits/milliard");
- } else {
- res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
- if (res) {
- return res;
- }
- snprintf(fn, sizeof(fn), "digits/milliards");
- }
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- if (!res) {
- if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- strcpy(fna, "");
- }
- }
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_en_GB: British and Norwegian syntax */
-/* New files:
- In addition to American English, the following sounds are required: "and"
- */
-static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- int playa = 0;
- char fn[256] = "";
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- while(!res && (num || playh || playa )) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playh) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- playh = 0;
- } else if (playa) {
- snprintf(fn, sizeof(fn), "digits/and");
- playa = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
- num -= ((num / 10) * 10);
- } else if (num < 1000) {
- int hundreds = num / 100;
- snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
-
- playh++;
- num -= 100 * hundreds;
- if (num)
- playa++;
- } else if (num < 1000000) {
- res = ast_say_number_full_en_GB(chan, num / 1000, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/thousand");
- num = num % 1000;
- if (num && num < 100)
- playa++;
- } else if (num < 1000000000) {
- int millions = num / 1000000;
- res = ast_say_number_full_en_GB(chan, millions, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/million");
- num = num % 1000000;
- if (num && num < 100)
- playa++;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
-
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_es: Spanish syntax */
-/* New files:
- Requires a few new audios:
- 1F.gsm: feminine 'una'
- 21.gsm thru 29.gsm, cien.gsm, mil.gsm, millon.gsm, millones.gsm, 100.gsm, 200.gsm, 300.gsm, 400.gsm, 500.gsm, 600.gsm, 700.gsm, 800.gsm, 900.gsm, y.gsm
- */
-static int ast_say_number_full_es(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playa = 0;
- int mf = 0; /* +1 = male; -1 = female */
- char fn[256] = "";
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- if (options) {
- if (!strncasecmp(options, "f",1))
- mf = -1;
- else if (!strncasecmp(options, "m", 1))
- mf = 1;
- }
-
- while (!res && num) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playa) {
- snprintf(fn, sizeof(fn), "digits/and");
- playa = 0;
- } else if (num == 1) {
- if (mf < 0)
- snprintf(fn, sizeof(fn), "digits/%dF", num);
- else if (mf > 0)
- snprintf(fn, sizeof(fn), "digits/%dM", num);
- else
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 31) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
- num -= ((num/10)*10);
- if (num)
- playa++;
- } else if (num == 100) {
- snprintf(fn, sizeof(fn), "digits/100");
- num = 0;
- } else if (num < 200) {
- snprintf(fn, sizeof(fn), "digits/100-and");
- num -= 100;
- } else {
- if (num < 1000) {
- snprintf(fn, sizeof(fn), "digits/%d", (num/100)*100);
- num -= ((num/100)*100);
- } else if (num < 2000) {
- num = num % 1000;
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- if (num < 1000000) {
- res = ast_say_number_full_es(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000;
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- if (num < 2147483640) {
- if ((num/1000000) == 1) {
- res = ast_say_number_full_es(chan, num / 1000000, ints, language, "M", audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/million");
- } else {
- res = ast_say_number_full_es(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/millions");
- }
- num = num % 1000000;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- }
- }
- }
-
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
-
- }
-
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_fr: French syntax */
-/* Extra sounds needed:
- 1F: feminin 'une'
- et: 'and' */
-static int ast_say_number_full_fr(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- int playa = 0;
- int mf = 1; /* +1 = male; -1 = female */
- char fn[256] = "";
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- if (options && !strncasecmp(options, "f",1))
- mf = -1;
-
- while(!res && (num || playh || playa)) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playh) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- playh = 0;
- } else if (playa) {
- snprintf(fn, sizeof(fn), "digits/et");
- playa = 0;
- } else if (num == 1) {
- if (mf < 0)
- snprintf(fn, sizeof(fn), "digits/%dF", num);
- else
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 21) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 70) {
- snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
- if ((num % 10) == 1) playa++;
- num = num % 10;
- } else if (num < 80) {
- snprintf(fn, sizeof(fn), "digits/60");
- if ((num % 10) == 1) playa++;
- num = num - 60;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/80");
- num = num - 80;
- } else if (num < 200) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- num = num - 100;
- } else if (num < 1000) {
- snprintf(fn, sizeof(fn), "digits/%d", (num/100));
- playh++;
- num = num % 100;
- } else if (num < 2000) {
- snprintf(fn, sizeof(fn), "digits/thousand");
- num = num - 1000;
- } else if (num < 1000000) {
- res = ast_say_number_full_fr(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/thousand");
- num = num % 1000;
- } else if (num < 1000000000) {
- res = ast_say_number_full_fr(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/million");
- num = num % 1000000;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-
-
-/*! \brief ast_say_number_full_he: Hebrew syntax */
-/* Extra sounds needed:
- 1F: feminin 'one'
- ve: 'and'
- 2hundred: 2 hundred
- 2thousands: 2 thousand
- thousands: plural of 'thousand'
- 3sF 'Smichut forms (female)
- 4sF
- 5sF
- 6sF
- 7sF
- 8sF
- 9sF
- 3s 'Smichut' forms (male)
- 4s
- 5s
- 6s
- 7s
- 9s
- 10s
- 11s
- 12s
- 13s
- 14s
- 15s
- 16s
- 17s
- 18s
- 19s
-
-TODO: 've' should sometimed be 'hu':
-* before 'shtaym' (2, F)
-* before 'shnaym' (2, M)
-* before 'shlosha' (3, M)
-* before 'shmone' (8, M)
-* before 'shlosim' (30)
-* before 'shmonim' (80)
-
-What about:
-'sheva' (7, F)?
-'tesha' (9, F)?
-*/
-#define SAY_NUM_BUF_SIZE 256
-static int ast_say_number_full_he(struct ast_channel *chan, int num,
- const char *ints, const char *language, const char *options,
- int audiofd, int ctrlfd)
-{
- int res = 0;
- int state = 0; /* no need to save anything */
- int mf = 1; /* +1 = Masculin; -1 = Feminin */
- char fn[SAY_NUM_BUF_SIZE] = "";
- ast_verbose(VERBOSE_PREFIX_3 "ast_say_digits_full: started. "
- "num: %d, options=\"%s\"\n",
- num, options
- );
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- if (options && !strncasecmp(options, "f",1))
- mf = -1;
-
- /* Do we have work to do? */
- while(!res && (num || (state>0) )) {
- /* first type of work: play a second sound. In this loop
- * we can only play one sound file at a time. Thus playing
- * a second one requires repeating the loop just for the
- * second file. The variable 'state' remembers where we were.
- * state==0 is the normal mode and it means that we continue
- * to check if the number num has yet anything left.
- */
- ast_verbose(VERBOSE_PREFIX_3 "ast_say_digits_full: num: %d, "
- "state=%d, options=\"%s\", mf=%d\n",
- num, state, options, mf
- );
- if (state==1) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- state = 0;
- } else if (state==2) {
- snprintf(fn, sizeof(fn), "digits/ve");
- state = 0;
- } else if (state==3) {
- snprintf(fn, sizeof(fn), "digits/thousands");
- state=0;
- } else if (num <21) {
- if (mf < 0)
- snprintf(fn, sizeof(fn), "digits/%dF", num);
- else
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
- num = num % 10;
- if (num>0) state=2;
- } else if (num < 200) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- num = num - 100;
- } else if (num < 300) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- num = num - 100;
- } else if (num < 1000) {
- snprintf(fn, sizeof(fn), "digits/%d", (num/100));
- state=1;
- num = num % 100;
- } else if (num < 2000) {
- snprintf(fn, sizeof(fn), "digits/thousand");
- num = num - 1000;
- } else if (num < 3000) {
- snprintf(fn, sizeof(fn), "digits/2thousand");
- num = num - 2000;
- if (num>0) state=2;
- } else if (num < 20000) {
- snprintf(fn, sizeof(fn), "digits/%ds",(num/1000));
- num = num % 1000;
- state=3;
- } else if (num < 1000000) {
- res = ast_say_number_full_he(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/thousand");
- num = num % 1000;
- } else if (num < 1000000000) {
- res = ast_say_number_full_he(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/million");
- num = num % 1000000;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_it: Italian */
-static int ast_say_number_full_it(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- int tempnum = 0;
- char fn[256] = "";
-
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- /*
- Italian support
-
- Like english, numbers up to 20 are a single 'word', and others
- compound, but with exceptions.
- For example 21 is not twenty-one, but there is a single word in 'it'.
- Idem for 28 (ie when a the 2nd part of a compund number
- starts with a vowel)
-
- There are exceptions also for hundred, thousand and million.
- In english 100 = one hundred, 200 is two hundred.
- In italian 100 = cento , like to say hundred (without one),
- 200 and more are like english.
-
- Same applies for thousand:
- 1000 is one thousand in en, 2000 is two thousand.
- In it we have 1000 = mille , 2000 = 2 mila
-
- For million(s) we use the plural, if more than one
- Also, one million is abbreviated in it, like on-million,
- or 'un milione', not 'uno milione'.
- So the right file is provided.
- */
-
- while(!res && (num || playh)) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playh) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- playh = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 21) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 28) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 31) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 38) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 41) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 48) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 51) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 58) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 61) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 68) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 71) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 78) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 81) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 88) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 91) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num == 98) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
- num -= ((num / 10) * 10);
- } else {
- if (num < 1000) {
- if ((num / 100) > 1) {
- snprintf(fn, sizeof(fn), "digits/%d", (num/100));
- playh++;
- } else {
- snprintf(fn, sizeof(fn), "digits/hundred");
- }
- num -= ((num / 100) * 100);
- } else {
- if (num < 1000000) { /* 1,000,000 */
- if ((num/1000) > 1)
- res = ast_say_number_full_it(chan, num / 1000, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- tempnum = num;
- num = num % 1000;
- if ((tempnum / 1000) < 2)
- snprintf(fn, sizeof(fn), "digits/thousand");
- else /* for 1000 it says mille, for >1000 (eg 2000) says mila */
- snprintf(fn, sizeof(fn), "digits/thousands");
- } else {
- if (num < 1000000000) { /* 1,000,000,000 */
- if ((num / 1000000) > 1)
- res = ast_say_number_full_it(chan, num / 1000000, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- tempnum = num;
- num = num % 1000000;
- if ((tempnum / 1000000) < 2)
- snprintf(fn, sizeof(fn), "digits/million");
- else
- snprintf(fn, sizeof(fn), "digits/millions");
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- }
- }
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_nl: dutch syntax */
-/* New files: digits/nl-en
- */
-static int ast_say_number_full_nl(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- int units = 0;
- char fn[256] = "";
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
- while (!res && (num || playh )) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playh) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- playh = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- units = num % 10;
- if (units > 0) {
- res = ast_say_number_full_nl(chan, units, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- num = num - units;
- snprintf(fn, sizeof(fn), "digits/nl-en");
- } else {
- snprintf(fn, sizeof(fn), "digits/%d", num - units);
- num = 0;
- }
- } else {
- if (num < 1000) {
- snprintf(fn, sizeof(fn), "digits/%d", (num/100));
- playh++;
- num -= ((num / 100) * 100);
- } else {
- if (num < 1000000) { /* 1,000,000 */
- res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000;
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- if (num < 1000000000) { /* 1,000,000,000 */
- res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000000;
- snprintf(fn, sizeof(fn), "digits/million");
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- }
- }
- }
-
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_no: Norwegian syntax */
-/* New files:
- In addition to American English, the following sounds are required: "and", "1N"
- */
-static int ast_say_number_full_no(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- int playa = 0;
- int cn = 1; /* +1 = commune; -1 = neuter */
- char fn[256] = "";
-
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- if (options && !strncasecmp(options, "n",1)) cn = -1;
-
- while(!res && (num || playh || playa )) {
- /* The grammar for Norwegian numbers is the same as for English except
- * for the following:
- * - 1 exists in both commune ("en", file "1") and neuter ("ett", file "1N")
- * "and" before the last two digits, i.e. 2034 is "two thousand and
- * thirty-four" and 1000012 is "one million and twelve".
- */
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playh) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- playh = 0;
- } else if (playa) {
- snprintf(fn, sizeof(fn), "digits/and");
- playa = 0;
- } else if (num == 1 && cn == -1) {
- snprintf(fn, sizeof(fn), "digits/1N");
- num = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
- num -= ((num / 10) * 10);
- } else if (num < 1000) {
- int hundreds = num / 100;
- if (hundreds == 1)
- snprintf(fn, sizeof(fn), "digits/1N");
- else
- snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
-
- playh++;
- num -= 100 * hundreds;
- if (num)
- playa++;
- } else if (num < 1000000) {
- res = ast_say_number_full_no(chan, num / 1000, ints, language, "n", audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/thousand");
- num = num % 1000;
- if (num && num < 100)
- playa++;
- } else if (num < 1000000000) {
- int millions = num / 1000000;
- res = ast_say_number_full_no(chan, millions, ints, language, "c", audiofd, ctrlfd);
- if (res)
- return res;
- snprintf(fn, sizeof(fn), "digits/million");
- num = num % 1000000;
- if (num && num < 100)
- playa++;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
-
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-typedef struct {
- char *separator_dziesiatek;
- char *cyfry[10];
- char *cyfry2[10];
- char *setki[10];
- char *dziesiatki[10];
- char *nastki[10];
- char *rzedy[3][3];
-} odmiana;
-
-static char *pl_rzad_na_tekst(odmiana *odm, int i, int rzad)
-{
- if (rzad==0)
- return "";
-
- if (i==1)
- return odm->rzedy[rzad - 1][0];
- if ((i > 21 || i < 11) && i%10 > 1 && i%10 < 5)
- return odm->rzedy[rzad - 1][1];
- else
- return odm->rzedy[rzad - 1][2];
-}
-
-static char* pl_append(char* buffer, char* str)
-{
- strcpy(buffer, str);
- buffer += strlen(str);
- return buffer;
-}
-
-static void pl_odtworz_plik(struct ast_channel *chan, const char *language, int audiofd, int ctrlfd, const char *ints, char *fn)
-{
- char file_name[255] = "digits/";
- strcat(file_name, fn);
- ast_log(LOG_DEBUG, "Trying to play: %s\n", file_name);
- if (!ast_streamfile(chan, file_name, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
-}
-
-static void powiedz(struct ast_channel *chan, const char *language, int audiofd, int ctrlfd, const char *ints, odmiana *odm, int rzad, int i)
-{
- /* Initialise variables to allow compilation on Debian-stable, etc */
- int m1000E6 = 0;
- int i1000E6 = 0;
- int m1000E3 = 0;
- int i1000E3 = 0;
- int m1000 = 0;
- int i1000 = 0;
- int m100 = 0;
- int i100 = 0;
-
- if (i == 0 && rzad > 0) {
- return;
- }
- if (i == 0) {
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry[0]);
- }
-
- m1000E6 = i % 1000000000;
- i1000E6 = i / 1000000000;
-
- powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+3, i1000E6);
-
- m1000E3 = m1000E6 % 1000000;
- i1000E3 = m1000E6 / 1000000;
-
- powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+2, i1000E3);
-
- m1000 = m1000E3 % 1000;
- i1000 = m1000E3 / 1000;
-
- powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+1, i1000);
-
- m100 = m1000 % 100;
- i100 = m1000 / 100;
-
- if (i100>0)
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->setki[i100]);
-
- if ( m100 > 0 && m100 <=9 ) {
- if (m1000>0)
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry2[m100]);
- else
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry[m100]);
- } else if (m100 % 10 == 0) {
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->dziesiatki[m100 / 10]);
- } else if (m100 <= 19 ) {
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->nastki[m100 % 10]);
- } else if (m100 != 0) {
- if (odm->separator_dziesiatek[0]==' ') {
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->dziesiatki[m100 / 10]);
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry2[m100 % 10]);
- } else {
- char buf[10];
- char *b = buf;
- b = pl_append(b, odm->dziesiatki[m100 / 10]);
- b = pl_append(b, odm->separator_dziesiatek);
- b = pl_append(b, odm->cyfry2[m100 % 10]);
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, buf);
- }
- }
-
- if (rzad > 0) {
- pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, pl_rzad_na_tekst(odm, i, rzad));
- }
-}
-
-/* ast_say_number_full_pl: Polish syntax */
-static int ast_say_number_full_pl(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-/*
-Sounds needed:
-0 zero
-1 jeden
-10 dziesiec
-100 sto
-1000 tysiac
-1000000 milion
-1000000000 miliard
-1000000000.2 miliardy
-1000000000.5 miliardow
-1000000.2 miliony
-1000000.5 milionow
-1000.2 tysiace
-1000.5 tysiecy
-100m stu
-10m dziesieciu
-11 jedenascie
-11m jedenastu
-12 dwanascie
-12m dwunastu
-13 trzynascie
-13m trzynastu
-14 czternascie
-14m czternastu
-15 pietnascie
-15m pietnastu
-16 szesnascie
-16m szesnastu
-17 siedemnascie
-17m siedemnastu
-18 osiemnascie
-18m osiemnastu
-19 dziewietnascie
-19m dziewietnastu
-1z jedna
-2 dwie
-20 dwadziescia
-200 dwiescie
-200m dwustu
-20m dwudziestu
-2-1m dwaj
-2-2m dwoch
-2z dwie
-3 trzy
-30 trzydziesci
-300 trzysta
-300m trzystu
-30m trzydziestu
-3-1m trzej
-3-2m trzech
-4 cztery
-40 czterdziesci
-400 czterysta
-400m czterystu
-40m czterdziestu
-4-1m czterej
-4-2m czterech
-5 piec
-50 piecdziesiat
-500 piecset
-500m pieciuset
-50m piedziesieciu
-5m pieciu
-6 szesc
-60 szescdziesiat
-600 szescset
-600m szesciuset
-60m szescdziesieciu
-6m szesciu
-7 siedem
-70 siedemdziesiat
-700 siedemset
-700m siedmiuset
-70m siedemdziesieciu
-7m siedmiu
-8 osiem
-80 osiemdziesiat
-800 osiemset
-800m osmiuset
-80m osiemdziesieciu
-8m osmiu
-9 dziewiec
-90 dziewiecdziesiat
-900 dziewiecset
-900m dziewieciuset
-90m dziewiedziesieciu
-9m dziewieciu
-and combinations of eg.: 20_1, 30m_3m, etc...
-
-*/
-{
- char *zenski_cyfry[] = {"0","1z", "2z", "3", "4", "5", "6", "7", "8", "9"};
-
- char *zenski_cyfry2[] = {"0","1", "2z", "3", "4", "5", "6", "7", "8", "9"};
-
- char *meski_cyfry[] = {"0","1", "2-1m", "3-1m", "4-1m", "5m", /*"2-1mdwaj"*/ "6m", "7m", "8m", "9m"};
-
- char *meski_cyfry2[] = {"0","1", "2-2m", "3-2m", "4-2m", "5m", "6m", "7m", "8m", "9m"};
-
- char *meski_setki[] = {"", "100m", "200m", "300m", "400m", "500m", "600m", "700m", "800m", "900m"};
-
- char *meski_dziesiatki[] = {"", "10m", "20m", "30m", "40m", "50m", "60m", "70m", "80m", "90m"};
-
- char *meski_nastki[] = {"", "11m", "12m", "13m", "14m", "15m", "16m", "17m", "18m", "19m"};
-
- char *nijaki_cyfry[] = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"};
-
- char *nijaki_cyfry2[] = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"};
-
- char *nijaki_setki[] = {"", "100", "200", "300", "400", "500", "600", "700", "800", "900"};
-
- char *nijaki_dziesiatki[] = {"", "10", "20", "30", "40", "50", "60", "70", "80", "90"};
-
- char *nijaki_nastki[] = {"", "11", "12", "13", "14", "15", "16", "17", "18", "19"};
-
- char *rzedy[][3] = { {"1000", "1000.2", "1000.5"}, {"1000000", "1000000.2", "1000000.5"}, {"1000000000", "1000000000.2", "1000000000.5"}};
-
- /* Initialise variables to allow compilation on Debian-stable, etc */
- odmiana *o;
-
- static odmiana *odmiana_nieosobowa = NULL;
- static odmiana *odmiana_meska = NULL;
- static odmiana *odmiana_zenska = NULL;
-
- if (odmiana_nieosobowa == NULL) {
- odmiana_nieosobowa = (odmiana *) malloc(sizeof(odmiana));
-
- odmiana_nieosobowa->separator_dziesiatek = "_";
-
- memcpy(odmiana_nieosobowa->cyfry, nijaki_cyfry, sizeof(odmiana_nieosobowa->cyfry));
- memcpy(odmiana_nieosobowa->cyfry2, nijaki_cyfry2, sizeof(odmiana_nieosobowa->cyfry));
- memcpy(odmiana_nieosobowa->setki, nijaki_setki, sizeof(odmiana_nieosobowa->setki));
- memcpy(odmiana_nieosobowa->dziesiatki, nijaki_dziesiatki, sizeof(odmiana_nieosobowa->dziesiatki));
- memcpy(odmiana_nieosobowa->nastki, nijaki_nastki, sizeof(odmiana_nieosobowa->nastki));
- memcpy(odmiana_nieosobowa->rzedy, rzedy, sizeof(odmiana_nieosobowa->rzedy));
- }
-
- if (odmiana_zenska == NULL) {
- odmiana_zenska = (odmiana *) malloc(sizeof(odmiana));
-
- odmiana_zenska->separator_dziesiatek = " ";
-
- memcpy(odmiana_zenska->cyfry, zenski_cyfry, sizeof(odmiana_zenska->cyfry));
- memcpy(odmiana_zenska->cyfry2, zenski_cyfry2, sizeof(odmiana_zenska->cyfry));
- memcpy(odmiana_zenska->setki, nijaki_setki, sizeof(odmiana_zenska->setki));
- memcpy(odmiana_zenska->dziesiatki, nijaki_dziesiatki, sizeof(odmiana_zenska->dziesiatki));
- memcpy(odmiana_zenska->nastki, nijaki_nastki, sizeof(odmiana_zenska->nastki));
- memcpy(odmiana_zenska->rzedy, rzedy, sizeof(odmiana_zenska->rzedy));
- }
-
- if (odmiana_meska == NULL) {
- odmiana_meska = (odmiana *) malloc(sizeof(odmiana));
-
- odmiana_meska->separator_dziesiatek = " ";
-
- memcpy(odmiana_meska->cyfry, meski_cyfry, sizeof(odmiana_meska->cyfry));
- memcpy(odmiana_meska->cyfry2, meski_cyfry2, sizeof(odmiana_meska->cyfry));
- memcpy(odmiana_meska->setki, meski_setki, sizeof(odmiana_meska->setki));
- memcpy(odmiana_meska->dziesiatki, meski_dziesiatki, sizeof(odmiana_meska->dziesiatki));
- memcpy(odmiana_meska->nastki, meski_nastki, sizeof(odmiana_meska->nastki));
- memcpy(odmiana_meska->rzedy, rzedy, sizeof(odmiana_meska->rzedy));
- }
-
- if (options) {
- if (strncasecmp(options, "f", 1) == 0)
- o = odmiana_zenska;
- else if (strncasecmp(options, "m", 1) == 0)
- o = odmiana_meska;
- else
- o = odmiana_nieosobowa;
- } else
- o = odmiana_nieosobowa;
-
- powiedz(chan, language, audiofd, ctrlfd, ints, o, 0, num);
- return 0;
-}
-
-/* ast_say_number_full_pt: Portuguese syntax */
-/* Extra sounds needed: */
-/* For feminin all sound files end with F */
-/* 100E for 100+ something */
-/* 1000000S for plural */
-/* pt-e for 'and' */
-static int ast_say_number_full_pt(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- int mf = 1; /* +1 = male; -1 = female */
- char fn[256] = "";
-
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- if (options && !strncasecmp(options, "f",1))
- mf = -1;
-
- while(!res && num ) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (num < 20) {
- if ((num == 1 || num == 2) && (mf < 0))
- snprintf(fn, sizeof(fn), "digits/%dF", num);
- else
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
- if (num % 10)
- playh = 1;
- num = num % 10;
- } else if (num < 1000) {
- if (num == 100)
- snprintf(fn, sizeof(fn), "digits/100");
- else if (num < 200)
- snprintf(fn, sizeof(fn), "digits/100E");
- else {
- if (mf < 0 && num > 199)
- snprintf(fn, sizeof(fn), "digits/%dF", (num / 100) * 100);
- else
- snprintf(fn, sizeof(fn), "digits/%d", (num / 100) * 100);
- if (num % 100)
- playh = 1;
- }
- num = num % 100;
- } else if (num < 1000000) {
- if (num > 1999) {
- res = ast_say_number_full_pt(chan, (num / 1000) * mf, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- }
- snprintf(fn, sizeof(fn), "digits/1000");
- if ((num % 1000) && ((num % 1000) < 100 || !(num % 100)))
- playh = 1;
- num = num % 1000;
- } else if (num < 1000000000) {
- res = ast_say_number_full_pt(chan, (num / 1000000), ints, language, options, audiofd, ctrlfd );
- if (res)
- return res;
- if (num < 2000000)
- snprintf(fn, sizeof(fn), "digits/1000000");
- else
- snprintf(fn, sizeof(fn), "digits/1000000S");
-
- if ((num % 1000000) &&
- /* no thousands */
- ((!((num / 1000) % 1000) && ((num % 1000) < 100 || !(num % 100))) ||
- /* no hundreds and below */
- (!(num % 1000) && (((num / 1000) % 1000) < 100 || !((num / 1000) % 100))) ) )
- playh = 1;
- num = num % 1000000;
- }
- if (!res) {
- if (!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- if (!res && playh) {
- res = wait_file(chan, ints, "digits/pt-e", language);
- ast_stopstream(chan);
- playh = 0;
- }
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_se: Swedish syntax */
-static int ast_say_number_full_se(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- char fn[256] = "";
- int cn = 1; /* +1 = commune; -1 = neuter */
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
- if (options && !strncasecmp(options, "n",1)) cn = -1;
-
- while(!res && (num || playh)) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playh) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- playh = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
- num -= ((num / 10) * 10);
- } else if (num == 1 && cn == -1) { /* En eller ett? */
- snprintf(fn, sizeof(fn), "digits/1N");
- num = 0;
- } else {
- if (num < 1000){
- snprintf(fn, sizeof(fn), "digits/%d", (num/100));
- playh++;
- num -= ((num / 100) * 100);
- } else {
- if (num < 1000000) { /* 1,000,000 */
- res = ast_say_number_full_se(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
- if (res) {
- return res;
- }
- num = num % 1000;
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- if (num < 1000000000) { /* 1,000,000,000 */
- res = ast_say_number_full_se(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
- if (res) {
- return res;
- }
- num = num % 1000000;
- snprintf(fn, sizeof(fn), "digits/million");
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- }
- }
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- ast_stopstream(chan);
- }
- }
- }
- return res;
-}
-
-/*! \brief ast_say_number_full_tw: Taiwanese syntax */
-static int ast_say_number_full_tw(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
-{
- int res = 0;
- int playh = 0;
- char fn[256] = "";
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- while(!res && (num || playh)) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (playh) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- playh = 0;
- } else if (num < 10) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
- num -= ((num / 10) * 10);
- } else {
- if (num < 1000){
- snprintf(fn, sizeof(fn), "digits/%d", (num/100));
- playh++;
- num -= ((num / 100) * 100);
- } else {
- if (num < 1000000) { /* 1,000,000 */
- res = ast_say_number_full_tw(chan, num / 1000, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000;
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- if (num < 1000000000) { /* 1,000,000,000 */
- res = ast_say_number_full_tw(chan, num / 1000000, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000000;
- snprintf(fn, sizeof(fn), "digits/million");
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- }
- }
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-
-/*! \brief determine last digits for thousands/millions (ru) */
-static int get_lastdigits_ru(int num) {
- if (num < 20) {
- return num;
- } else if (num < 100) {
- return get_lastdigits_ru(num % 10);
- } else if (num < 1000) {
- return get_lastdigits_ru(num % 100);
- }
- return 0; /* number too big */
-}
-
-
-/*! \brief ast_say_number_full_ru: Russian syntax */
-/*! \brief additional files:
- n00.gsm (one hundred, two hundred, ...)
- thousand.gsm
- million.gsm
- thousands-i.gsm (tisyachi)
- million-a.gsm (milliona)
- thousands.gsm
- millions.gsm
- 1f.gsm (odna)
- 2f.gsm (dve)
-
- where 'n' from 1 to 9
-*/
-static int ast_say_number_full_ru(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- int res = 0;
- int lastdigits = 0;
- char fn[256] = "";
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- while(!res && (num)) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus");
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (num < 20) {
- if(options && strlen(options) == 1 && num < 3) {
- snprintf(fn, sizeof(fn), "digits/%d%s", num, options);
- } else {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- }
- num = 0;
- } else if (num < 100) {
- snprintf(fn, sizeof(fn), "digits/%d", num - (num % 10));
- num %= 10;
- } else if (num < 1000){
- snprintf(fn, sizeof(fn), "digits/%d", num - (num % 100));
- num %= 100;
- } else if (num < 1000000) { /* 1,000,000 */
- lastdigits = get_lastdigits_ru(num / 1000);
- /* say thousands */
- if (lastdigits < 3) {
- res = ast_say_number_full_ru(chan, num / 1000, ints, language, "f", audiofd, ctrlfd);
- } else {
- res = ast_say_number_full_ru(chan, num / 1000, ints, language, NULL, audiofd, ctrlfd);
- }
- if (res)
- return res;
- if (lastdigits == 1) {
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else if (lastdigits > 1 && lastdigits < 5) {
- snprintf(fn, sizeof(fn), "digits/thousands-i");
- } else {
- snprintf(fn, sizeof(fn), "digits/thousands");
- }
- num %= 1000;
- } else if (num < 1000000000) { /* 1,000,000,000 */
- lastdigits = get_lastdigits_ru(num / 1000000);
- /* say millions */
- res = ast_say_number_full_ru(chan, num / 1000000, ints, language, NULL, audiofd, ctrlfd);
- if (res)
- return res;
- if (lastdigits == 1) {
- snprintf(fn, sizeof(fn), "digits/million");
- } else if (lastdigits > 1 && lastdigits < 5) {
- snprintf(fn, sizeof(fn), "digits/million-a");
- } else {
- snprintf(fn, sizeof(fn), "digits/millions");
- }
- num %= 1000000;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- if (!res) {
- if (!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-
-/*! \brief ast_say_enumeration_full: call language-specific functions */
-/* Called from AGI */
-int ast_say_enumeration_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- if (!strcasecmp(language,"en") ) { /* English syntax */
- return(ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "da") ) { /* Danish syntax */
- return(ast_say_enumeration_full_da(chan, num, ints, language, options, audiofd, ctrlfd));
- } else if (!strcasecmp(language, "de") ) { /* German syntax */
- return(ast_say_enumeration_full_de(chan, num, ints, language, options, audiofd, ctrlfd));
- }
-
- /* Default to english */
- return(ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd));
-}
-
-/*! \brief ast_say_enumeration: call language-specific functions without file descriptors */
-int ast_say_enumeration(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
-{
- return(ast_say_enumeration_full(chan, num, ints, language, options, -1, -1));
-}
-
-/*! \brief ast_say_enumeration_full_en: English syntax */
-/* This is the default syntax, if no other syntax defined in this file is used */
-static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
-{
- int res = 0, t = 0;
- char fn[256] = "";
-
- while(!res && num) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/h-%d", num);
- num = 0;
- } else if (num < 100) {
- int tens = num / 10;
- num = num % 10;
- if (num == 0) {
- snprintf(fn, sizeof(fn), "digits/h-%d", (tens * 10));
- } else {
- snprintf(fn, sizeof(fn), "digits/%d", (tens * 10));
- }
- } else if (num < 1000) {
- int hundreds = num / 100;
- num = num % 100;
- if (hundreds > 1 || t == 1) {
- res = ast_say_number_full_en(chan, hundreds, ints, language, audiofd, ctrlfd);
- }
- if (res)
- return res;
- if (num) {
- snprintf(fn, sizeof(fn), "digits/hundred");
- } else {
- snprintf(fn, sizeof(fn), "digits/h-hundred");
- }
- } else if (num < 1000000) {
- int thousands = num / 1000;
- num = num % 1000;
- if (thousands > 1 || t == 1) {
- res = ast_say_number_full_en(chan, thousands, ints, language, audiofd, ctrlfd);
- }
- if (res)
- return res;
- if (num) {
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- snprintf(fn, sizeof(fn), "digits/h-thousand");
- }
- t = 1;
- } else if (num < 1000000000) {
- int millions = num / 1000000;
- num = num % 1000000;
- t = 1;
- res = ast_say_number_full_en(chan, millions, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- if (num) {
- snprintf(fn, sizeof(fn), "digits/million");
- } else {
- snprintf(fn, sizeof(fn), "digits/h-million");
- }
- } else if (num < INT_MAX) {
- int billions = num / 1000000000;
- num = num % 1000000000;
- t = 1;
- res = ast_say_number_full_en(chan, billions, ints, language, audiofd, ctrlfd);
- if (res)
- return res;
- if (num) {
- snprintf(fn, sizeof(fn), "digits/billion");
- } else {
- snprintf(fn, sizeof(fn), "digits/h-billion");
- }
- } else if (num == INT_MAX) {
- snprintf(fn, sizeof(fn), "digits/h-last");
- num = 0;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
-
- if (!res) {
- if (!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1)) {
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- } else {
- res = ast_waitstream(chan, ints);
- }
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-/*! \brief ast_say_enumeration_full_da: Danish syntax */
-static int ast_say_enumeration_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- /* options can be: '' or 'm' male gender; 'f' female gender; 'n' neuter gender; 'p' plural */
- int res = 0, t = 0;
- char fn[256] = "", fna[256] = "";
- char *gender;
-
- if (options && !strncasecmp(options, "f",1)) {
- gender = "F";
- } else if (options && !strncasecmp(options, "n",1)) {
- gender = "N";
- } else {
- gender = "";
- }
-
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- while(!res && num) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (num < 100 && t) {
- snprintf(fn, sizeof(fn), "digits/and");
- t = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
- num = 0;
- } else if (num < 100) {
- int ones = num % 10;
- if (ones) {
- snprintf(fn, sizeof(fn), "digits/%d-and", ones);
- num -= ones;
- } else {
- snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
- num = 0;
- }
- } else if (num == 100 && t == 0) {
- snprintf(fn, sizeof(fn), "digits/h-hundred%s", gender);
- num = 0;
- } else if (num < 1000) {
- int hundreds = num / 100;
- num = num % 100;
- if (hundreds == 1) {
- snprintf(fn, sizeof(fn), "digits/1N");
- } else {
- snprintf(fn, sizeof(fn), "digits/%d", hundreds);
- }
- if (num) {
- snprintf(fna, sizeof(fna), "digits/hundred");
- } else {
- snprintf(fna, sizeof(fna), "digits/h-hundred%s", gender);
- }
- t = 1;
- } else if (num < 1000000) {
- int thousands = num / 1000;
- num = num % 1000;
- if (thousands == 1) {
- if (num) {
- snprintf(fn, sizeof(fn), "digits/1N");
- snprintf(fna, sizeof(fna), "digits/thousand");
- } else {
- if (t) {
- snprintf(fn, sizeof(fn), "digits/1N");
- snprintf(fna, sizeof(fna), "digits/h-thousand%s", gender);
- } else {
- snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
- }
- }
- } else {
- res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
- if (res) {
- return res;
- }
- if (num) {
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
- }
- }
- t = 1;
- } else if (num < 1000000000) {
- int millions = num / 1000000;
- num = num % 1000000;
- if (millions == 1) {
- if (num) {
- snprintf(fn, sizeof(fn), "digits/1F");
- snprintf(fna, sizeof(fna), "digits/million");
- } else {
- snprintf(fn, sizeof(fn), "digits/1N");
- snprintf(fna, sizeof(fna), "digits/h-million%s", gender);
- }
- } else {
- res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
- if (res) {
- return res;
- }
- if (num) {
- snprintf(fn, sizeof(fn), "digits/millions");
- } else {
- snprintf(fn, sizeof(fn), "digits/h-million%s", gender);
- }
- }
- t = 1;
- } else if (num < INT_MAX) {
- int billions = num / 1000000000;
- num = num % 1000000000;
- if (billions == 1) {
- if (num) {
- snprintf(fn, sizeof(fn), "digits/1F");
- snprintf(fna, sizeof(fna), "digits/milliard");
- } else {
- snprintf(fn, sizeof(fn), "digits/1N");
- snprintf(fna, sizeof(fna), "digits/h-milliard%s", gender);
- }
- } else {
- res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- if (num) {
- snprintf(fn, sizeof(fna), "digits/milliards");
- } else {
- snprintf(fn, sizeof(fna), "digits/h-milliard%s", gender);
- }
- }
- t = 1;
- } else if (num == INT_MAX) {
- snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
- num = 0;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
-
- if (!res) {
- if (!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- if (!res) {
- if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
- if ((audiofd > -1) && (ctrlfd > -1)) {
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- } else {
- res = ast_waitstream(chan, ints);
- }
- }
- ast_stopstream(chan);
- strcpy(fna, "");
- }
- }
- }
- return res;
-}
-
-/*! \brief ast_say_enumeration_full_de: German syntax */
-static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
-{
- /* options can be: '' or 'm' male gender; 'f' female gender; 'n' neuter gender; 'p' plural */
- int res = 0, t = 0;
- char fn[256] = "", fna[256] = "";
- char *gender;
-
- if (options && !strncasecmp(options, "f",1)) {
- gender = "F";
- } else if (options && !strncasecmp(options, "n",1)) {
- gender = "N";
- } else {
- gender = "";
- }
-
- if (!num)
- return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
-
- while(!res && num) {
- if (num < 0) {
- snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */
- if ( num > INT_MIN ) {
- num = -num;
- } else {
- num = 0;
- }
- } else if (num < 100 && t) {
- snprintf(fn, sizeof(fn), "digits/and");
- t = 0;
- } else if (num < 20) {
- snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
- num = 0;
- } else if (num < 100) {
- int ones = num % 10;
- if (ones) {
- snprintf(fn, sizeof(fn), "digits/%d-and", ones);
- num -= ones;
- } else {
- snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
- num = 0;
- }
- } else if (num == 100 && t == 0) {
- snprintf(fn, sizeof(fn), "digits/h-hundred%s", gender);
- num = 0;
- } else if (num < 1000) {
- int hundreds = num / 100;
- num = num % 100;
- if (hundreds == 1) {
- snprintf(fn, sizeof(fn), "digits/1N");
- } else {
- snprintf(fn, sizeof(fn), "digits/%d", hundreds);
- }
- if (num) {
- snprintf(fna, sizeof(fna), "digits/hundred");
- } else {
- snprintf(fna, sizeof(fna), "digits/h-hundred%s", gender);
- }
- t = 1;
- } else if (num < 1000000) {
- int thousands = num / 1000;
- num = num % 1000;
- if (thousands == 1) {
- if (num) {
- snprintf(fn, sizeof(fn), "digits/1N");
- snprintf(fna, sizeof(fna), "digits/thousand");
- } else {
- if (t) {
- snprintf(fn, sizeof(fn), "digits/1N");
- snprintf(fna, sizeof(fna), "digits/h-thousand%s", gender);
- } else {
- snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
- }
- }
- } else {
- res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
- if (res) {
- return res;
- }
- if (num) {
- snprintf(fn, sizeof(fn), "digits/thousand");
- } else {
- snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
- }
- }
- t = 1;
- } else if (num < 1000000000) {
- int millions = num / 1000000;
- num = num % 1000000;
- if (millions == 1) {
- if (num) {
- snprintf(fn, sizeof(fn), "digits/1F");
- snprintf(fna, sizeof(fna), "digits/million");
- } else {
- snprintf(fn, sizeof(fn), "digits/1N");
- snprintf(fna, sizeof(fna), "digits/h-million%s", gender);
- }
- } else {
- res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
- if (res) {
- return res;
- }
- if (num) {
- snprintf(fn, sizeof(fn), "digits/millions");
- } else {
- snprintf(fn, sizeof(fn), "digits/h-million%s", gender);
- }
- }
- t = 1;
- } else if (num < INT_MAX) {
- int billions = num / 1000000000;
- num = num % 1000000000;
- if (billions == 1) {
- if (num) {
- snprintf(fn, sizeof(fn), "digits/1F");
- snprintf(fna, sizeof(fna), "digits/milliard");
- } else {
- snprintf(fn, sizeof(fn), "digits/1N");
- snprintf(fna, sizeof(fna), "digits/h-milliard%s", gender);
- }
- } else {
- res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
- if (res)
- return res;
- if (num) {
- snprintf(fn, sizeof(fna), "digits/milliards");
- } else {
- snprintf(fn, sizeof(fna), "digits/h-milliard%s", gender);
- }
- }
- t = 1;
- } else if (num == INT_MAX) {
- snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
- num = 0;
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
-
- if (!res) {
- if (!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- if (!res) {
- if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
- if ((audiofd > -1) && (ctrlfd > -1)) {
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- } else {
- res = ast_waitstream(chan, ints);
- }
- }
- ast_stopstream(chan);
- strcpy(fna, "");
- }
- }
- }
- return res;
-}
-
-int ast_say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- if (!strcasecmp(lang, "en") ) { /* English syntax */
- return(ast_say_date_en(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "da") ) { /* Danish syntax */
- return(ast_say_date_da(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "de") ) { /* German syntax */
- return(ast_say_date_de(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "fr") ) { /* French syntax */
- return(ast_say_date_fr(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
- return(ast_say_date_nl(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
- return(ast_say_date_pt(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "gr") ) { /* Greek syntax */
- return(ast_say_date_gr(chan, t, ints, lang));
- }
-
- /* Default to English */
- return(ast_say_date_en(chan, t, ints, lang));
-}
-
-/* English syntax */
-int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- ast_localtime(&t,&tm,NULL);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- return res;
-}
-
-/* Danish syntax */
-int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- ast_localtime(&t,&tm,NULL);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res) {
- /* Year */
- int year = tm.tm_year + 1900;
- if (year > 1999) { /* year 2000 and later */
- res = ast_say_number(chan, year, ints, lang, (char *) NULL);
- } else {
- if (year < 1100) {
- /* I'm not going to handle 1100 and prior */
- /* We'll just be silent on the year, instead of bombing out. */
- } else {
- /* year 1100 to 1999. will anybody need this?!? */
- snprintf(fn,sizeof(fn), "digits/%d", (year / 100) );
- res = wait_file(chan, ints, fn, lang);
- if (!res) {
- res = wait_file(chan,ints, "digits/hundred", lang);
- if (!res && year % 100 != 0) {
- res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
- }
- }
- }
- }
- }
- return res;
-}
-
-/* German syntax */
-int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- ast_localtime(&t,&tm,NULL);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res) {
- /* Year */
- int year = tm.tm_year + 1900;
- if (year > 1999) { /* year 2000 and later */
- res = ast_say_number(chan, year, ints, lang, (char *) NULL);
- } else {
- if (year < 1100) {
- /* I'm not going to handle 1100 and prior */
- /* We'll just be silent on the year, instead of bombing out. */
- } else {
- /* year 1100 to 1999. will anybody need this?!? */
- /* say 1967 as 'neunzehn hundert sieben und sechzig' */
- snprintf(fn,sizeof(fn), "digits/%d", (year / 100) );
- res = wait_file(chan, ints, fn, lang);
- if (!res) {
- res = wait_file(chan,ints, "digits/hundred", lang);
- if (!res && year % 100 != 0) {
- res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
- }
- }
- }
- }
- }
- return res;
-}
-
-/* French syntax */
-int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- ast_localtime(&t,&tm,NULL);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- return res;
-}
-
-/* Dutch syntax */
-int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- ast_localtime(&t,&tm,NULL);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- return res;
-}
-
-/* Portuguese syntax */
-int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- ast_localtime(&t,&tm,NULL);
- localtime_r(&t,&tm);
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- if (!res)
- res = wait_file(chan, ints, fn, lang);
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
- if (!res)
- res = wait_file(chan, ints, "digits/pt-de", lang);
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- if (!res)
- res = wait_file(chan, ints, fn, lang);
- if (!res)
- res = wait_file(chan, ints, "digits/pt-de", lang);
- if (!res)
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
-
- return res;
-}
-
-int ast_say_date_with_format(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- if (!strcasecmp(lang, "en") ) { /* English syntax */
- return(ast_say_date_with_format_en(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "da") ) { /* Danish syntax */
- return(ast_say_date_with_format_da(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "de") ) { /* German syntax */
- return(ast_say_date_with_format_de(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "es") || !strcasecmp(lang, "mx")) { /* Spanish syntax */
- return(ast_say_date_with_format_es(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "he")) { /* Hebrew syntax */
- return(ast_say_date_with_format_he(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "fr") ) { /* French syntax */
- return(ast_say_date_with_format_fr(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "it") ) { /* Italian syntax */
- return(ast_say_date_with_format_it(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
- return(ast_say_date_with_format_nl(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
- return(ast_say_date_with_format_pt(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */
- return(ast_say_date_with_format_tw(chan, time, ints, lang, format, timezone));
- } else if (!strcasecmp(lang, "gr") ) { /* Greek syntax */
- return(ast_say_date_with_format_gr(chan, time, ints, lang, format, timezone));
- }
-
- /* Default to English */
- return(ast_say_date_with_format_en(chan, time, ints, lang, format, timezone));
-}
-
-/* English syntax */
-int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- res = wait_file(chan,ints,sndfile,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'm':
- /* Month enumerated */
- res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL);
- break;
- case 'd':
- case 'e':
- /* First - Thirtyfirst */
- res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char *) NULL);
- break;
- case 'Y':
- /* Year */
- if (tm.tm_year > 99) {
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- } else {
- if (tm.tm_year < 1) {
- /* I'm not going to handle 1900 and prior */
- /* We'll just be silent on the year, instead of bombing out. */
- } else {
- res = wait_file(chan,ints, "digits/19",lang);
- if (!res) {
- if (tm.tm_year <= 9) {
- /* 1901 - 1909 */
- res = wait_file(chan,ints, "digits/oh",lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- } else if (tm.tm_year <= 20) {
- /* 1910 - 1920 */
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- /* 1921 - 1999 */
- int ten, one;
- ten = tm.tm_year / 10;
- one = tm.tm_year % 10;
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- if (one != 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- }
- }
- }
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- if (tm.tm_hour == 0)
- snprintf(nextmsg,sizeof(nextmsg), "digits/12");
- else if (tm.tm_hour > 12)
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'H':
- case 'k':
- /* 24-Hour */
- if (format[offset] == 'H') {
- /* e.g. oh-eight */
- if (tm.tm_hour < 10) {
- res = wait_file(chan,ints, "digits/oh",lang);
- }
- } else {
- /* e.g. eight */
- if (tm.tm_hour == 0) {
- res = wait_file(chan,ints, "digits/oh",lang);
- }
- }
- if (!res) {
- if (tm.tm_hour != 0) {
- int remainder = tm.tm_hour;
- if (tm.tm_hour > 20) {
- res = wait_file(chan,ints, "digits/20",lang);
- remainder -= 20;
- }
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- break;
- case 'M':
- case 'N':
- /* Minute */
- if (tm.tm_min == 0) {
- if (format[offset] == 'M') {
- res = wait_file(chan, ints, "digits/oclock", lang);
- } else {
- res = wait_file(chan, ints, "digits/hundred", lang);
- }
- } else if (tm.tm_min < 10) {
- res = wait_file(chan,ints, "digits/oh",lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- } else {
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- }
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 11)
- snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
- break;
- case 'S':
- /* Seconds */
- if (tm.tm_sec == 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else if (tm.tm_sec < 10) {
- res = wait_file(chan,ints, "digits/oh",lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- } else {
- res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
- }
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-/* Danish syntax */
-int ast_say_date_with_format_da(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- res = wait_file(chan,ints,sndfile,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'm':
- /* Month enumerated */
- res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m");
- break;
- case 'd':
- case 'e':
- /* First - Thirtyfirst */
- res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m");
- break;
- case 'Y':
- /* Year */
- {
- int year = tm.tm_year + 1900;
- if (year > 1999) { /* year 2000 and later */
- res = ast_say_number(chan, year, ints, lang, (char *) NULL);
- } else {
- if (year < 1100) {
- /* I'm not going to handle 1100 and prior */
- /* We'll just be silent on the year, instead of bombing out. */
- } else {
- /* year 1100 to 1999. will anybody need this?!? */
- /* say 1967 as 'nineteen hundred seven and sixty' */
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (year / 100) );
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- res = wait_file(chan,ints, "digits/hundred",lang);
- if (!res && year % 100 != 0) {
- res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
- }
- }
- }
- }
- }
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- res = wait_file(chan,ints,"digits/oclock",lang);
- if (tm.tm_hour == 0)
- snprintf(nextmsg,sizeof(nextmsg), "digits/12");
- else if (tm.tm_hour > 12)
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
- if (!res) {
- res = wait_file(chan,ints,nextmsg,lang);
- }
- break;
- case 'H':
- /* 24-Hour, single digit hours preceeded by "oh" (0) */
- if (tm.tm_hour < 10 && tm.tm_hour > 0) {
- res = wait_file(chan,ints, "digits/0",lang);
- }
- /* FALLTRHU */
- case 'k':
- /* 24-Hour */
- res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
- break;
- case 'M':
- /* Minute */
- if (tm.tm_min > 0 || format[offset+ 1 ] == 'S' ) { /* zero 'digits/0' only if seconds follow (kind of a hack) */
- res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
- }
- if ( !res && format[offset + 1] == 'S' ) { /* minutes only if seconds follow (kind of a hack) */
- if (tm.tm_min == 1) {
- res = wait_file(chan,ints,"digits/minute",lang);
- } else {
- res = wait_file(chan,ints,"digits/minutes",lang);
- }
- }
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 11)
- snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or AdBY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
- break;
- case 'S':
- /* Seconds */
- res = wait_file(chan,ints, "digits/and",lang);
- if (!res) {
- res = ast_say_number(chan, tm.tm_sec, ints, lang, "f");
- if (!res) {
- res = wait_file(chan,ints, "digits/seconds",lang);
- }
- }
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-/* German syntax */
-int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- res = wait_file(chan,ints,sndfile,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'm':
- /* Month enumerated */
- res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m");
- break;
- case 'd':
- case 'e':
- /* First - Thirtyfirst */
- res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m");
- break;
- case 'Y':
- /* Year */
- {
- int year = tm.tm_year + 1900;
- if (year > 1999) { /* year 2000 and later */
- res = ast_say_number(chan, year, ints, lang, (char *) NULL);
- } else {
- if (year < 1100) {
- /* I'm not going to handle 1100 and prior */
- /* We'll just be silent on the year, instead of bombing out. */
- } else {
- /* year 1100 to 1999. will anybody need this?!? */
- /* say 1967 as 'neunzehn hundert sieben und sechzig' */
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (year / 100) );
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- res = wait_file(chan,ints, "digits/hundred",lang);
- if (!res && year % 100 != 0) {
- res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
- }
- }
- }
- }
- }
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- if (tm.tm_hour == 0)
- snprintf(nextmsg,sizeof(nextmsg), "digits/12");
- else if (tm.tm_hour > 12)
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- res = wait_file(chan,ints,"digits/oclock",lang);
- }
- break;
- case 'H':
- case 'k':
- /* 24-Hour */
- res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
- if (!res) {
- res = wait_file(chan,ints,"digits/oclock",lang);
- }
- break;
- case 'M':
- /* Minute */
- if (tm.tm_min > 0 || format[offset+ 1 ] == 'S' ) { /* zero 'digits/0' only if seconds follow (kind of a hack) */
- res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
- }
- if ( !res && format[offset + 1] == 'S' ) { /* minutes only if seconds follow (kind of a hack) */
- if (tm.tm_min == 1) {
- res = wait_file(chan,ints,"digits/minute",lang);
- } else {
- res = wait_file(chan,ints,"digits/minutes",lang);
- }
- }
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 11)
- snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or AdBY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
- break;
- case 'S':
- /* Seconds */
- res = wait_file(chan,ints, "digits/and",lang);
- if (!res) {
- res = ast_say_number(chan, tm.tm_sec, ints, lang, "f");
- if (!res) {
- res = wait_file(chan,ints, "digits/seconds",lang);
- }
- }
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-/* TODO: this probably is not the correct format for doxygen remarks */
-
-/** ast_say_date_with_format_he Say formmated date in Hebrew
- *
- * \ref ast_say_date_with_format_en for the details of the options
- *
- * Changes from the English version:
- *
- * * don't replicate in here the logic of ast_say_number_full_he
- *
- * * year is always 4-digit (because it's simpler)
- *
- * * added c, x, and X. Mainly for my tests
- *
- * * The standard "long" format used in Hebrew is AdBY, rather than ABdY
- *
- * TODO:
- * * A "ha" is missing in the standard date format, before the 'd'.
- * * The numbers of 3000--19000 are not handled well
- **/
-#define IL_DATE_STR "AdBY"
-#define IL_TIME_STR "IMp"
-#define IL_DATE_STR_FULL IL_DATE_STR " 'digits/at' " IL_TIME_STR
-int ast_say_date_with_format_he(struct ast_channel *chan, time_t time,
- const char *ints, const char *lang, const char *format,
- const char *timezone)
-{
- /* TODO: This whole function is cut&paste from
- * ast_say_date_with_format_en . Is that considered acceptable?
- **/
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- res = wait_file(chan,ints,sndfile,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'd':
- case 'e': /* Day of the month */
- /* I'm not sure exactly what the parameters
- * audiofd and ctrlfd to
- * ast_say_number_full_he mean, but it seems
- * safe to pass -1 there.
- *
- * At least in one of the pathes :-(
- */
- res = ast_say_number_full_he(chan, tm.tm_mday,
- ints, lang, "m", -1, -1
- );
- break;
- case 'Y': /* Year */
- res = ast_say_number_full_he(chan, tm.tm_year+1900,
- ints, lang, "f", -1, -1
- );
- break;
- case 'I':
- case 'l': /* 12-Hour */
- {
- int hour = tm.tm_hour;
- hour = hour%12;
- if (hour == 0) hour=12;
-
- res = ast_say_number_full_he(chan, hour,
- ints, lang, "f", -1, -1
- );
- }
- break;
- case 'H':
- case 'k': /* 24-Hour */
- /* With 'H' there is an 'oh' after a single-
- * digit hour */
- if ((format[offset] == 'H') &&
- (tm.tm_hour <10)&&(tm.tm_hour>0)
- ) { /* e.g. oh-eight */
- res = wait_file(chan,ints, "digits/oh",lang);
- }
-
- res = ast_say_number_full_he(chan, tm.tm_hour,
- ints, lang, "f", -1, -1
- );
- break;
- case 'M': /* Minute */
- res = ast_say_number_full_he(chan, tm.tm_min,
- ints, lang,"f", -1, -1
- );
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 11)
- snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or "date" */
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A
- * (weekday), or "date" */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
- char todo = format[offset]; /* The letter to format*/
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- if (todo == 'Q') {
- res = wait_file(chan,
- ints,
- "digits/today",
- lang);
- }
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if ((todo != 'Q') &&
- (beg_today - 86400 * 6 < time))
- {
- /* Within the last week */
- res = ast_say_date_with_format_he(chan,
- time, ints, lang,
- "A", timezone);
- } else {
- res = ast_say_date_with_format_he(chan,
- time, ints, lang,
- IL_DATE_STR, timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
- break;
- case 'S': /* Seconds */
- res = ast_say_number_full_he(chan, tm.tm_sec,
- ints, lang, "f", -1, -1
- );
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- /* c, x, and X seem useful for testing. Not sure
- * if thiey're good for the general public */
- case 'c':
- res = ast_say_date_with_format_he(chan, time,
- ints, lang, IL_DATE_STR_FULL, timezone);
- break;
- case 'x':
- res = ast_say_date_with_format_he(chan, time,
- ints, lang, IL_DATE_STR, timezone);
- break;
- case 'X': /* Currently not locale-dependent...*/
- res = ast_say_date_with_format_he(chan, time,
- ints, lang, IL_TIME_STR, timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-
-/* Spanish syntax */
-int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'm':
- /* First - Twelfth */
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'd':
- case 'e':
- /* First - Thirtyfirst */
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
- break;
- case 'Y':
- /* Year */
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- if (tm.tm_hour == 0)
- snprintf(nextmsg,sizeof(nextmsg), "digits/12");
- else if (tm.tm_hour > 12)
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'H':
- case 'k':
- /* 24-Hour */
- res = ast_say_number(chan, tm.tm_hour, ints, lang, NULL);
- break;
- case 'M':
- /* Minute */
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 12)
- res = wait_file(chan, ints, "digits/p-m", lang);
- else if (tm.tm_hour && tm.tm_hour < 12)
- res = wait_file(chan, ints, "digits/a-m", lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/y' M", timezone);
- break;
- case 'S':
- /* Seconds */
- if (tm.tm_sec == 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else if (tm.tm_sec < 10) {
- res = wait_file(chan,ints, "digits/oh",lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- int ten, one;
- ten = (tm.tm_sec / 10) * 10;
- one = (tm.tm_sec % 10);
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- /* Fifty, not fifty-zero */
- if (one != 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-/* French syntax
-oclock = heure
-*/
-int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- res = wait_file(chan,ints,sndfile,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'm':
- /* First - Twelfth */
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'd':
- case 'e':
- /* First */
- if (tm.tm_mday == 1) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
- }
- break;
- case 'Y':
- /* Year */
- if (tm.tm_year > 99) {
- res = wait_file(chan,ints, "digits/2",lang);
- if (!res) {
- res = wait_file(chan,ints, "digits/thousand",lang);
- }
- if (tm.tm_year > 100) {
- if (!res) {
- res = ast_say_number(chan, tm.tm_year - 100, ints, lang, (char * ) NULL);
- }
- }
- } else {
- if (tm.tm_year < 1) {
- /* I'm not going to handle 1900 and prior */
- /* We'll just be silent on the year, instead of bombing out. */
- } else {
- res = wait_file(chan,ints, "digits/thousand",lang);
- if (!res) {
- wait_file(chan,ints, "digits/9",lang);
- wait_file(chan,ints, "digits/hundred",lang);
- res = ast_say_number(chan, tm.tm_year, ints, lang, (char * ) NULL);
- }
- }
- }
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- if (tm.tm_hour == 0)
- snprintf(nextmsg,sizeof(nextmsg), "digits/12");
- else if (tm.tm_hour > 12)
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res)
- res = wait_file(chan,ints, "digits/oclock",lang);
- break;
- case 'H':
- case 'k':
- /* 24-Hour */
- res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL);
- if (!res) {
- if (format[offset] == 'H') {
- res = wait_file(chan,ints, "digits/oclock",lang);
- }
- }
- if (!res)
- res = wait_file(chan,ints, "digits/oclock",lang);
- break;
- case 'M':
- /* Minute */
- if (tm.tm_min == 0) {
- break;
- }
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char * ) NULL);
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 11)
- snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or AdBY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
- break;
- case 'S':
- /* Seconds */
- res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL);
- if (!res) {
- res = wait_file(chan,ints, "digits/second",lang);
- }
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- res = wait_file(chan,ints,sndfile,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'm':
- /* First - Twelfth */
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'd':
- case 'e':
- /* First day of the month is spelled as ordinal */
- if (tm.tm_mday == 1) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- if (!res) {
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
- }
- }
- break;
- case 'Y':
- /* Year */
- if (tm.tm_year > 99) {
- res = wait_file(chan,ints, "digits/ore-2000",lang);
- if (tm.tm_year > 100) {
- if (!res) {
- /* This works until the end of 2021 */
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- } else {
- if (tm.tm_year < 1) {
- /* I'm not going to handle 1900 and prior */
- /* We'll just be silent on the year, instead of bombing out. */
- } else {
- res = wait_file(chan,ints, "digits/ore-1900",lang);
- if ((!res) && (tm.tm_year != 0)) {
- if (tm.tm_year <= 21) {
- /* 1910 - 1921 */
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- /* 1922 - 1999, but sounds badly in 1928, 1931, 1938, etc... */
- int ten, one;
- ten = tm.tm_year / 10;
- one = tm.tm_year % 10;
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- if (one != 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- }
- }
- }
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- if (tm.tm_hour == 0)
- snprintf(nextmsg,sizeof(nextmsg), "digits/12");
- else if (tm.tm_hour > 12)
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'H':
- case 'k':
- /* 24-Hour */
- if (tm.tm_hour == 0) {
- res = wait_file(chan,ints, "digits/ore-mezzanotte",lang);
- } else if (tm.tm_hour == 1) {
- res = wait_file(chan,ints, "digits/ore-una",lang);
- } else {
- res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
- }
- break;
- case 'M':
- /* Minute */
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 11)
- snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
- break;
- case 'S':
- /* Seconds */
- if (tm.tm_sec == 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else if (tm.tm_sec < 10) {
- res = wait_file(chan,ints, "digits/oh",lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- int ten, one;
- ten = (tm.tm_sec / 10) * 10;
- one = (tm.tm_sec % 10);
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- /* Fifty, not fifty-zero */
- if (one != 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-/* Dutch syntax */
-int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- res = wait_file(chan,ints,sndfile,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'm':
- /* First - Twelfth */
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'd':
- case 'e':
- /* First - Thirtyfirst */
- res = ast_say_number(chan, tm.tm_mday, ints, lang, NULL);
- break;
- case 'Y':
- /* Year */
- if (tm.tm_year > 99) {
- res = wait_file(chan,ints, "digits/2",lang);
- if (!res) {
- res = wait_file(chan,ints, "digits/thousand",lang);
- }
- if (tm.tm_year > 100) {
- if (!res) {
- /* This works until the end of 2020 */
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- } else {
- if (tm.tm_year < 1) {
- /* I'm not going to handle 1900 and prior */
- /* We'll just be silent on the year, instead of bombing out. */
- } else {
- res = wait_file(chan,ints, "digits/19",lang);
- if (!res) {
- if (tm.tm_year <= 9) {
- /* 1901 - 1909 */
- res = wait_file(chan,ints, "digits/oh",lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- } else if (tm.tm_year <= 20) {
- /* 1910 - 1920 */
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- /* 1921 - 1999 */
- int ten, one;
- ten = tm.tm_year / 10;
- one = tm.tm_year % 10;
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- if (one != 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- }
- }
- }
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- if (tm.tm_hour == 0)
- snprintf(nextmsg,sizeof(nextmsg), "digits/12");
- else if (tm.tm_hour > 12)
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'H':
- case 'k':
- /* 24-Hour */
- res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
- if (!res) {
- res = wait_file(chan,ints, "digits/nl-uur",lang);
- }
- break;
- case 'M':
- /* Minute */
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 11)
- snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
- break;
- case 'S':
- /* Seconds */
- if (tm.tm_sec == 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else if (tm.tm_sec < 10) {
- res = wait_file(chan,ints, "digits/oh",lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- int ten, one;
- ten = (tm.tm_sec / 10) * 10;
- one = (tm.tm_sec % 10);
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- /* Fifty, not fifty-zero */
- if (one != 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-/* Portuguese syntax */
-int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'm':
- /* First - Twelfth */
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'd':
- case 'e':
- /* First - Thirtyfirst */
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
- break;
- case 'Y':
- /* Year */
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- if (tm.tm_hour == 0) {
- if (format[offset] == 'I')
- res = wait_file(chan, ints, "digits/pt-ah", lang);
- if (!res)
- res = wait_file(chan, ints, "digits/pt-meianoite", lang);
- }
- else if (tm.tm_hour == 12) {
- if (format[offset] == 'I')
- res = wait_file(chan, ints, "digits/pt-ao", lang);
- if (!res)
- res = wait_file(chan, ints, "digits/pt-meiodia", lang);
- }
- else {
- if (format[offset] == 'I') {
- res = wait_file(chan, ints, "digits/pt-ah", lang);
- if ((tm.tm_hour % 12) != 1)
- if (!res)
- res = wait_file(chan, ints, "digits/pt-sss", lang);
- }
- if (!res)
- res = ast_say_number(chan, (tm.tm_hour % 12), ints, lang, "f");
- }
- break;
- case 'H':
- case 'k':
- /* 24-Hour */
- res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL);
- if (!res) {
- if (tm.tm_hour != 0) {
- int remainder = tm.tm_hour;
- if (tm.tm_hour > 20) {
- res = wait_file(chan,ints, "digits/20",lang);
- remainder -= 20;
- }
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- break;
- case 'M':
- /* Minute */
- if (tm.tm_min == 0) {
- res = wait_file(chan, ints, "digits/pt-hora", lang);
- if (tm.tm_hour != 1)
- if (!res)
- res = wait_file(chan, ints, "digits/pt-sss", lang); } else {
- res = wait_file(chan,ints,"digits/pt-e",lang);
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- }
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 12)
- res = wait_file(chan, ints, "digits/p-m", lang);
- else if (tm.tm_hour && tm.tm_hour < 12)
- res = wait_file(chan, ints, "digits/a-m", lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "Ad 'digits/pt-de' B 'digits/pt-de' Y", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "Ad 'digits/pt-de' B 'digits/pt-de' Y", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/pt-e' M", timezone);
- break;
- case 'S':
- /* Seconds */
- if (tm.tm_sec == 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else if (tm.tm_sec < 10) {
- res = wait_file(chan,ints, "digits/oh",lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- int ten, one;
- ten = (tm.tm_sec / 10) * 10;
- one = (tm.tm_sec % 10);
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- /* Fifty, not fifty-zero */
- if (one != 0) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-/* Taiwanese syntax */
-int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- res = wait_file(chan,ints,sndfile,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'm':
- /* First - Twelfth */
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'd':
- case 'e':
- /* First - Thirtyfirst */
- if (!(tm.tm_mday % 10) || (tm.tm_mday < 10)) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%dh", tm.tm_mday - (tm.tm_mday % 10));
- res = wait_file(chan,ints,nextmsg,lang);
- if(!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday % 10);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- break;
- case 'Y':
- /* Year */
- if (tm.tm_year > 99) {
- res = wait_file(chan,ints, "digits/2",lang);
- if (!res) {
- res = wait_file(chan,ints, "digits/thousand",lang);
- }
- if (tm.tm_year > 100) {
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) / 10);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) % 10);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- if (!res) {
- res = wait_file(chan,ints, "digits/year",lang);
- }
- } else {
- if (tm.tm_year < 1) {
- /* I'm not going to handle 1900 and prior */
- /* We'll just be silent on the year, instead of bombing out. */
- } else {
- res = wait_file(chan,ints, "digits/1",lang);
- if (!res) {
- res = wait_file(chan,ints, "digits/9",lang);
- }
- if (!res) {
- if (tm.tm_year <= 9) {
- /* 1901 - 1909 */
- res = wait_file(chan,ints, "digits/0",lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- } else {
- /* 1910 - 1999 */
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year / 10);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year % 10);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- }
- }
- if (!res) {
- res = wait_file(chan,ints, "digits/year",lang);
- }
- }
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- if (tm.tm_hour == 0)
- snprintf(nextmsg,sizeof(nextmsg), "digits/12");
- else if (tm.tm_hour > 12)
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- res = wait_file(chan,ints, "digits/oclock",lang);
- }
- break;
- case 'H':
- case 'k':
- /* 24-Hour */
- if (!(tm.tm_hour % 10) || tm.tm_hour < 10) {
- if (tm.tm_hour < 10) {
- res = wait_file(chan, ints, "digits/0", lang);
- }
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - (tm.tm_hour % 10));
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour % 10);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- if (!res) {
- res = wait_file(chan,ints, "digits/oclock",lang);
- }
- break;
- case 'M':
- /* Minute */
- if (!(tm.tm_min % 10) || tm.tm_min < 10) {
- if (tm.tm_min < 10) {
- res = wait_file(chan, ints, "digits/0", lang);
- }
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min - (tm.tm_min % 10));
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min % 10);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- if (!res) {
- res = wait_file(chan,ints, "digits/minute",lang);
- }
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 11)
- snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
- break;
- case 'S':
- /* Seconds */
- if (!(tm.tm_sec % 10) || tm.tm_sec < 10) {
- if (tm.tm_sec < 10) {
- res = wait_file(chan, ints, "digits/0", lang);
- }
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
- res = wait_file(chan,ints,nextmsg,lang);
- } else {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec - (tm.tm_sec % 10));
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res) {
- snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec % 10);
- res = wait_file(chan,ints,nextmsg,lang);
- }
- }
- if (!res) {
- res = wait_file(chan,ints, "digits/second",lang);
- }
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
-
-int ast_say_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- if (!strcasecmp(lang, "en") ) { /* English syntax */
- return(ast_say_time_en(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "de") ) { /* German syntax */
- return(ast_say_time_de(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "fr") ) { /* French syntax */
- return(ast_say_time_fr(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
- return(ast_say_time_nl(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
- return(ast_say_time_pt(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */
- return(ast_say_time_tw(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "gr") ) { /* Greek syntax */
- return(ast_say_time_gr(chan, t, ints, lang));
- }
-
- /* Default to English */
- return(ast_say_time_en(chan, t, ints, lang));
-}
-
-/* English syntax */
-int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- int res = 0;
- int hour, pm=0;
- localtime_r(&t,&tm);
- hour = tm.tm_hour;
- if (!hour)
- hour = 12;
- else if (hour == 12)
- pm = 1;
- else if (hour > 12) {
- hour -= 12;
- pm = 1;
- }
- if (!res)
- res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
-
- if (tm.tm_min > 9) {
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- } else if (tm.tm_min) {
- if (!res)
- res = ast_streamfile(chan, "digits/oh", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/oclock", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (pm) {
- if (!res)
- res = ast_streamfile(chan, "digits/p-m", lang);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/a-m", lang);
- }
- if (!res)
- res = ast_waitstream(chan, ints);
- return res;
-}
-
-/* German syntax */
-int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- int res = 0;
- localtime_r(&t,&tm);
- if (!res)
- res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
- if (!res)
- res = ast_streamfile(chan, "digits/oclock", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- if (tm.tm_min > 0)
- res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
- return res;
-}
-
-/* French syntax */
-int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- int res = 0;
- localtime_r(&t,&tm);
-
- res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
- if (!res)
- res = ast_streamfile(chan, "digits/oclock", lang);
- if (tm.tm_min) {
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- }
- return res;
-}
-
-/* Dutch syntax */
-int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- int res = 0;
- localtime_r(&t,&tm);
- if (!res)
- res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
- if (!res)
- res = ast_streamfile(chan, "digits/nl-uur", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- if (tm.tm_min > 0)
- res = ast_say_number(chan, tm.tm_min, ints, lang, NULL);
- return res;
-}
-
-/* Portuguese syntax */
-int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- int res = 0;
- int hour;
- localtime_r(&t,&tm);
- hour = tm.tm_hour;
- if (!res)
- res = ast_say_number(chan, hour, ints, lang, "f");
- if (tm.tm_min) {
- if (!res)
- res = wait_file(chan, ints, "digits/pt-e", lang);
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- } else {
- if (!res)
- res = wait_file(chan, ints, "digits/pt-hora", lang);
- if (tm.tm_hour != 1)
- if (!res)
- res = wait_file(chan, ints, "digits/pt-sss", lang);
- }
- if (!res)
- res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
- return res;
-}
-
-/* Taiwanese syntax */
-int ast_say_time_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- int res = 0;
- int hour, pm=0;
- localtime_r(&t,&tm);
- hour = tm.tm_hour;
- if (!hour)
- hour = 12;
- else if (hour == 12)
- pm = 1;
- else if (hour > 12) {
- hour -= 12;
- pm = 1;
- }
- if (pm) {
- if (!res)
- res = ast_streamfile(chan, "digits/p-m", lang);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/a-m", lang);
- }
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
- if (!res)
- res = ast_streamfile(chan, "digits/oclock", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- if (!res)
- res = ast_streamfile(chan, "digits/minute", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- return res;
-}
-
-int ast_say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- if (!strcasecmp(lang, "en") ) { /* English syntax */
- return(ast_say_datetime_en(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "de") ) { /* German syntax */
- return(ast_say_datetime_de(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "fr") ) { /* French syntax */
- return(ast_say_datetime_fr(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
- return(ast_say_datetime_nl(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
- return(ast_say_datetime_pt(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */
- return(ast_say_datetime_tw(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "gr") ) { /* Greek syntax */
- return(ast_say_datetime_gr(chan, t, ints, lang));
- }
-
- /* Default to English */
- return(ast_say_datetime_en(chan, t, ints, lang));
-}
-
-/* English syntax */
-int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- int hour, pm=0;
- localtime_r(&t,&tm);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
-
- hour = tm.tm_hour;
- if (!hour)
- hour = 12;
- else if (hour == 12)
- pm = 1;
- else if (hour > 12) {
- hour -= 12;
- pm = 1;
- }
- if (!res)
- res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
-
- if (tm.tm_min > 9) {
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- } else if (tm.tm_min) {
- if (!res)
- res = ast_streamfile(chan, "digits/oh", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/oclock", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (pm) {
- if (!res)
- res = ast_streamfile(chan, "digits/p-m", lang);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/a-m", lang);
- }
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- return res;
-}
-
-/* German syntax */
-int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- int res = 0;
- localtime_r(&t,&tm);
- res = ast_say_date(chan, t, ints, lang);
- if (!res)
- ast_say_time(chan, t, ints, lang);
- return res;
-
-}
-
-/* French syntax */
-int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- localtime_r(&t,&tm);
-
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
-
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
-
- if (!res)
- res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
- if (!res)
- res = ast_streamfile(chan, "digits/oclock", lang);
- if (tm.tm_min > 0) {
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- }
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- return res;
-}
-
-/* Dutch syntax */
-int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- int res = 0;
- localtime_r(&t,&tm);
- res = ast_say_date(chan, t, ints, lang);
- if (!res) {
- res = ast_streamfile(chan, "digits/nl-om", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- ast_say_time(chan, t, ints, lang);
- return res;
-}
-
-/* Portuguese syntax */
-int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- int hour, pm=0;
- localtime_r(&t,&tm);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
-
- hour = tm.tm_hour;
- if (!hour)
- hour = 12;
- else if (hour == 12)
- pm = 1;
- else if (hour > 12) {
- hour -= 12;
- pm = 1;
- }
- if (!res)
- res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
-
- if (tm.tm_min > 9) {
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- } else if (tm.tm_min) {
- if (!res)
- res = ast_streamfile(chan, "digits/oh", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/oclock", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (pm) {
- if (!res)
- res = ast_streamfile(chan, "digits/p-m", lang);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/a-m", lang);
- }
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- return res;
-}
-
-/* Taiwanese syntax */
-int ast_say_datetime_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- int hour, pm=0;
- localtime_r(&t,&tm);
- if (!res)
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
-
- hour = tm.tm_hour;
- if (!hour)
- hour = 12;
- else if (hour == 12)
- pm = 1;
- else if (hour > 12) {
- hour -= 12;
- pm = 1;
- }
- if (pm) {
- if (!res)
- res = ast_streamfile(chan, "digits/p-m", lang);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/a-m", lang);
- }
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
- if (!res)
- res = ast_streamfile(chan, "digits/oclock", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- if (!res)
- res = ast_streamfile(chan, "digits/minute", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- return res;
-}
-
-int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- if (!strcasecmp(lang, "en") ) { /* English syntax */
- return(ast_say_datetime_from_now_en(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "fr") ) { /* French syntax */
- return(ast_say_datetime_from_now_fr(chan, t, ints, lang));
- } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
- return(ast_say_datetime_from_now_pt(chan, t, ints, lang));
- }
-
- /* Default to English */
- return(ast_say_datetime_from_now_en(chan, t, ints, lang));
-}
-
-/* English syntax */
-int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- int res=0;
- time_t nowt;
- int daydiff;
- struct tm tm;
- struct tm now;
- char fn[256];
-
- time(&nowt);
-
- localtime_r(&t,&tm);
- localtime_r(&nowt,&now);
- daydiff = now.tm_yday - tm.tm_yday;
- if ((daydiff < 0) || (daydiff > 6)) {
- /* Day of month and month */
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
-
- } else if (daydiff) {
- /* Just what day of the week */
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- } /* Otherwise, it was today */
- if (!res)
- res = ast_say_time(chan, t, ints, lang);
- return res;
-}
-
-/* French syntax */
-int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- int res=0;
- time_t nowt;
- int daydiff;
- struct tm tm;
- struct tm now;
- char fn[256];
-
- time(&nowt);
-
- localtime_r(&t,&tm);
- localtime_r(&nowt,&now);
- daydiff = now.tm_yday - tm.tm_yday;
- if ((daydiff < 0) || (daydiff > 6)) {
- /* Day of month and month */
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
-
- } else if (daydiff) {
- /* Just what day of the week */
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- } /* Otherwise, it was today */
- if (!res)
- res = ast_say_time(chan, t, ints, lang);
- return res;
-}
-
-/* Portuguese syntax */
-int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- int res=0;
- time_t nowt;
- int daydiff;
- struct tm tm;
- struct tm now;
- char fn[256];
-
- time(&nowt);
-
- localtime_r(&t,&tm);
- localtime_r(&nowt,&now);
- daydiff = now.tm_yday - tm.tm_yday;
- if ((daydiff < 0) || (daydiff > 6)) {
- /* Day of month and month */
- if (!res)
- res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
- if (!res)
- res = wait_file(chan, ints, "digits/pt-de", lang);
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- if (!res)
- res = wait_file(chan, ints, fn, lang);
-
- } else if (daydiff) {
- /* Just what day of the week */
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- if (!res)
- res = wait_file(chan, ints, fn, lang);
- } /* Otherwise, it was today */
- snprintf(fn, sizeof(fn), "digits/pt-ah");
- if (!res)
- res = wait_file(chan, ints, fn, lang);
- if (tm.tm_hour != 1)
- if (!res)
- res = wait_file(chan, ints, "digits/pt-sss", lang);
- if (!res)
- res = ast_say_time(chan, t, ints, lang);
- return res;
-}
-
-
-/*********************************** GREEK SUPPORT ***************************************/
-
-
-/*
- * digits/female-[1..4] : "Mia, dyo , treis, tessereis"
- */
-static int gr_say_number_female(int num, struct ast_channel *chan, const char *ints, const char *lang){
- int tmp;
- int left;
- int res;
- char fn[256] = "";
-
- /* ast_log(LOG_DEBUG, "\n\n Saying number female %s %d \n\n",lang, num); */
- if (num < 5) {
- snprintf(fn, sizeof(fn), "digits/female-%d", num);
- res = wait_file(chan, ints, fn, lang);
- } else if (num < 13) {
- res = ast_say_number(chan, num, ints, lang, (char *) NULL);
- } else if (num <100 ) {
- tmp = (num/10) * 10;
- left = num - tmp;
- snprintf(fn, sizeof(fn), "digits/%d", tmp);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (left)
- gr_say_number_female(left, chan, ints, lang);
-
- } else {
- return -1;
- }
- return res;
-}
-
-
-
-/*
- * A list of the files that you need to create
- -> digits/xilia = "xilia"
- -> digits/myrio = "ekatomyrio"
- -> digits/thousands = "xiliades"
- -> digits/millions = "ektatomyria"
- -> digits/[1..12] :: A pronunciation of th digits form 1 to 12 e.g. "tria"
- -> digits/[10..100] :: A pronunciation of the tens from 10 to 90
- e,g 80 = "ogdonta"
- Here we must note that we use digits/tens/100 to utter "ekato"
- and digits/hundred-100 to utter "ekaton"
- -> digits/hundred-[100...1000] :: A pronunciation of hundreds from 100 to 1000 e.g 400 =
- "terakosia". Here again we use hundreds/1000 for "xilia"
- and digits/thousnds for "xiliades"
-*/
-
-static int ast_say_number_full_gr(struct ast_channel *chan, int num, const char *ints, const char *language,int audiofd, int ctrlfd)
-{
- int res = 0;
- char fn[256] = "";
- int i=0;
-
-
- if (!num) {
- snprintf(fn, sizeof(fn), "digits/0");
- res = ast_streamfile(chan, fn, chan->language);
- if (!res)
- return ast_waitstream(chan, ints);
- }
-
- while(!res && num ) {
- i++;
- if (num < 13) {
- snprintf(fn, sizeof(fn), "digits/%d", num);
- num = 0;
- } else if (num <= 100) {
- /* 13 < num <= 100 */
- snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
- num -= ((num / 10) * 10);
- } else if (num < 200) {
- /* 100 < num < 200 */
- snprintf(fn, sizeof(fn), "digits/hundred-100");
- num -= ((num / 100) * 100);
- }else if (num < 1000) {
- /* 200 < num < 1000 */
- snprintf(fn, sizeof(fn), "digits/hundred-%d", (num/100)*100);
- num -= ((num / 100) * 100);
- }else if (num < 2000){
- snprintf(fn, sizeof(fn), "digits/xilia");
- num -= ((num / 1000) * 1000);
- }
- else {
- /* num > 1000 */
- if (num < 1000000) {
- res = ast_say_number_full_gr(chan, (num / 1000), ints, chan->language, audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000;
- snprintf(fn, sizeof(fn), "digits/thousands");
- } else {
- if (num < 1000000000) { /* 1,000,000,000 */
- res = ast_say_number_full_gr(chan, (num / 1000000), ints, chan->language ,audiofd, ctrlfd);
- if (res)
- return res;
- num = num % 1000000;
- snprintf(fn, sizeof(fn), "digits/millions");
- } else {
- ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
- res = -1;
- }
- }
- }
- if (!res) {
- if(!ast_streamfile(chan, fn, language)) {
- if ((audiofd > -1) && (ctrlfd > -1))
- res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
- else
- res = ast_waitstream(chan, ints);
- }
- ast_stopstream(chan);
- }
- }
- return res;
-}
-
-
-/*
- * The format is weekday - day - month -year
- *
- * A list of the files that you need to create
- * digits/day-[1..7] : "Deytera .. Paraskeyh"
- * digits/months/1..12 : "Ianouariou .. Dekembriou"
- Attention the months are in
- "gekinh klhsh"
- */
-
-
-static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
-
- char fn[256];
- int res = 0;
-
-
- ast_localtime(&t,&tm,NULL);
- /* W E E K - D A Y */
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- /* D A Y */
- if (!res) {
- gr_say_number_female(tm.tm_mday, chan, ints, lang);
- }
- /* M O N T H */
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- /* Y E A R */
- if (!res)
- res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
- return res;
-}
-
-
-
-/* A list of the files that you need to create
- * digits/female/1..4 : "Mia, dyo , treis, tesseris "
- * digits/kai : "KAI"
- * didgits : "h wra"
- * digits/p-m : "meta meshmbrias"
- * digits/a-m : "pro meshmbrias"
- */
-
-static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
-
- struct tm tm;
- int res = 0;
- int hour, pm=0;
-
- localtime_r(&t,&tm);
- hour = tm.tm_hour;
-
- if (!hour)
- hour = 12;
- else if (hour == 12)
- pm = 1;
- else if (hour > 12) {
- hour -= 12;
- pm = 1;
- }
-
- res = gr_say_number_female(hour, chan, ints, lang);
- if (tm.tm_min) {
- if (!res)
- res = ast_streamfile(chan, "digits/kai", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/hwra", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- if (pm) {
- if (!res)
- res = ast_streamfile(chan, "digits/p-m", lang);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/a-m", lang);
- }
- if (!res)
- res = ast_waitstream(chan, ints);
- return res;
-}
-
-
-
-static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
-{
- struct tm tm;
- char fn[256];
- int res = 0;
- localtime_r(&t,&tm);
-
-
- /* W E E K - D A Y */
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- /* D A Y */
- if (!res) {
- gr_say_number_female(tm.tm_mday, chan, ints, lang);
- }
- /* M O N T H */
- if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
- res = ast_streamfile(chan, fn, lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
-
- res = ast_say_time_gr(chan, t, ints, lang);
- return res;
-}
-
-static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
-{
-
- struct tm tm;
- int res=0, offset, sndoffset;
- char sndfile[256], nextmsg[256];
-
- ast_localtime(&time,&tm,timezone);
-
- for (offset=0 ; format[offset] != '\0' ; offset++) {
- ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
- switch (format[offset]) {
- /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
- case '\'':
- /* Literal name of a sound file */
- sndoffset=0;
- for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
- sndfile[sndoffset] = '\0';
- res = wait_file(chan,ints,sndfile,lang);
- break;
- case 'A':
- case 'a':
- /* Sunday - Saturday */
- snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'B':
- case 'b':
- case 'h':
- /* January - December */
- snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'd':
- case 'e':
- /* first - thirtyfirst */
- gr_say_number_female(tm.tm_mday, chan, ints, lang);
- break;
- case 'Y':
- /* Year */
-
- ast_say_number_full_gr(chan, 1900+tm.tm_year, ints, chan->language, -1, -1);
- break;
- case 'I':
- case 'l':
- /* 12-Hour */
- if (tm.tm_hour == 0)
- gr_say_number_female(12, chan, ints, lang);
- else if (tm.tm_hour > 12)
- gr_say_number_female(tm.tm_hour - 12, chan, ints, lang);
- else
- gr_say_number_female(tm.tm_hour, chan, ints, lang);
- break;
- case 'H':
- case 'k':
- /* 24-Hour */
- gr_say_number_female(tm.tm_hour, chan, ints, lang);
- break;
- case 'M':
- /* Minute */
- if (tm.tm_min) {
- if (!res)
- res = ast_streamfile(chan, "digits/kai", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- if (!res)
- res = ast_say_number_full_gr(chan, tm.tm_min, ints, lang, -1, -1);
- } else {
- if (!res)
- res = ast_streamfile(chan, "digits/oclock", lang);
- if (!res)
- res = ast_waitstream(chan, ints);
- }
- break;
- case 'P':
- case 'p':
- /* AM/PM */
- if (tm.tm_hour > 11)
- snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
- else
- snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'Q':
- /* Shorthand for "Today", "Yesterday", or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- res = wait_file(chan,ints, "digits/today",lang);
- } else if (beg_today - 86400 < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
- }
- }
- break;
- case 'q':
- /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
- {
- struct timeval now;
- struct tm tmnow;
- time_t beg_today;
-
- gettimeofday(&now,NULL);
- ast_localtime(&now.tv_sec,&tmnow,timezone);
- /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
- /* In any case, it saves not having to do ast_mktime() */
- beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
- if (beg_today < time) {
- /* Today */
- } else if ((beg_today - 86400) < time) {
- /* Yesterday */
- res = wait_file(chan,ints, "digits/yesterday",lang);
- } else if (beg_today - 86400 * 6 < time) {
- /* Within the last week */
- res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
- } else {
- res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
- }
- }
- break;
- case 'R':
- res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
- break;
- case 'S':
- /* Seconds */
- snprintf(nextmsg,sizeof(nextmsg), "digits/kai");
- res = wait_file(chan,ints,nextmsg,lang);
- if (!res)
- res = ast_say_number_full_gr(chan, tm.tm_sec, ints, lang, -1, -1);
- if (!res)
- snprintf(nextmsg,sizeof(nextmsg), "digits/seconds");
- res = wait_file(chan,ints,nextmsg,lang);
- break;
- case 'T':
- res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
- break;
- case ' ':
- case ' ':
- /* Just ignore spaces and tabs */
- break;
- default:
- /* Unknown character */
- ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
- }
- /* Jump out on DTMF */
- if (res) {
- break;
- }
- }
- return res;
-}
diff --git a/1.2-netsec/sched.c b/1.2-netsec/sched.c
deleted file mode 100644
index 27dc68bee..000000000
--- a/1.2-netsec/sched.c
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Scheduler Routines (from cheops-NG)
- *
- */
-
-#ifdef DEBUG_SCHEDULER
-#define DEBUG(a) DEBUG_M(a)
-#else
-#define DEBUG(a)
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/sched.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-
-/* Determine if a is sooner than b */
-#define SOONER(a,b) (((b).tv_sec > (a).tv_sec) || \
- (((b).tv_sec == (a).tv_sec) && ((b).tv_usec > (a).tv_usec)))
-
-struct sched {
- struct sched *next; /* Next event in the list */
- int id; /* ID number of event */
- struct timeval when; /* Absolute time event should take place */
- int resched; /* When to reschedule */
- int variable; /* Use return value from callback to reschedule */
- void *data; /* Data */
- ast_sched_cb callback; /* Callback */
-};
-
-struct sched_context {
- ast_mutex_t lock;
- /* Number of events processed */
- int eventcnt;
-
- /* Number of outstanding schedule events */
- int schedcnt;
-
- /* Schedule entry and main queue */
- struct sched *schedq;
-
-#ifdef SCHED_MAX_CACHE
- /* Cache of unused schedule structures and how many */
- struct sched *schedc;
- int schedccnt;
-#endif
-};
-
-struct sched_context *sched_context_create(void)
-{
- struct sched_context *tmp;
- tmp = malloc(sizeof(struct sched_context));
- if (tmp) {
- memset(tmp, 0, sizeof(struct sched_context));
- ast_mutex_init(&tmp->lock);
- tmp->eventcnt = 1;
- tmp->schedcnt = 0;
- tmp->schedq = NULL;
-#ifdef SCHED_MAX_CACHE
- tmp->schedc = NULL;
- tmp->schedccnt = 0;
-#endif
- }
- return tmp;
-}
-
-void sched_context_destroy(struct sched_context *con)
-{
- struct sched *s, *sl;
- ast_mutex_lock(&con->lock);
-#ifdef SCHED_MAX_CACHE
- /* Eliminate the cache */
- s = con->schedc;
- while(s) {
- sl = s;
- s = s->next;
- free(sl);
- }
-#endif
- /* And the queue */
- s = con->schedq;
- while(s) {
- sl = s;
- s = s->next;
- free(sl);
- }
- /* And the context */
- ast_mutex_unlock(&con->lock);
- ast_mutex_destroy(&con->lock);
- free(con);
-}
-
-static struct sched *sched_alloc(struct sched_context *con)
-{
- /*
- * We keep a small cache of schedule entries
- * to minimize the number of necessary malloc()'s
- */
- struct sched *tmp;
-#ifdef SCHED_MAX_CACHE
- if (con->schedc) {
- tmp = con->schedc;
- con->schedc = con->schedc->next;
- con->schedccnt--;
- } else
-#endif
- tmp = malloc(sizeof(struct sched));
- return tmp;
-}
-
-static void sched_release(struct sched_context *con, struct sched *tmp)
-{
- /*
- * Add to the cache, or just free() if we
- * already have too many cache entries
- */
-
-#ifdef SCHED_MAX_CACHE
- if (con->schedccnt < SCHED_MAX_CACHE) {
- tmp->next = con->schedc;
- con->schedc = tmp;
- con->schedccnt++;
- } else
-#endif
- free(tmp);
-}
-
-int ast_sched_wait(struct sched_context *con)
-{
- /*
- * Return the number of milliseconds
- * until the next scheduled event
- */
- int ms;
- DEBUG(ast_log(LOG_DEBUG, "ast_sched_wait()\n"));
- ast_mutex_lock(&con->lock);
- if (!con->schedq) {
- ms = -1;
- } else {
- ms = ast_tvdiff_ms(con->schedq->when, ast_tvnow());
- if (ms < 0)
- ms = 0;
- }
- ast_mutex_unlock(&con->lock);
- return ms;
-
-}
-
-
-static void schedule(struct sched_context *con, struct sched *s)
-{
- /*
- * Take a sched structure and put it in the
- * queue, such that the soonest event is
- * first in the list.
- */
-
- struct sched *last=NULL;
- struct sched *current=con->schedq;
- while(current) {
- if (SOONER(s->when, current->when))
- break;
- last = current;
- current = current->next;
- }
- /* Insert this event into the schedule */
- s->next = current;
- if (last)
- last->next = s;
- else
- con->schedq = s;
- con->schedcnt++;
-}
-
-/*
- * given the last event *tv and the offset in milliseconds 'when',
- * computes the next value,
- */
-static int sched_settime(struct timeval *tv, int when)
-{
- struct timeval now = ast_tvnow();
-
- /*ast_log(LOG_DEBUG, "TV -> %lu,%lu\n", tv->tv_sec, tv->tv_usec);*/
- if (ast_tvzero(*tv)) /* not supplied, default to now */
- *tv = now;
- *tv = ast_tvadd(*tv, ast_samp2tv(when, 1000));
- if (ast_tvcmp(*tv, now) < 0) {
- ast_log(LOG_DEBUG, "Request to schedule in the past?!?!\n");
- *tv = now;
- }
- return 0;
-}
-
-
-int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb callback, void *data, int variable)
-{
- /*
- * Schedule callback(data) to happen when ms into the future
- */
- struct sched *tmp;
- int res = -1;
- DEBUG(ast_log(LOG_DEBUG, "ast_sched_add()\n"));
- if (!when) {
- ast_log(LOG_NOTICE, "Scheduled event in 0 ms?\n");
- return -1;
- }
- ast_mutex_lock(&con->lock);
- if ((tmp = sched_alloc(con))) {
- tmp->id = con->eventcnt++;
- tmp->callback = callback;
- tmp->data = data;
- tmp->resched = when;
- tmp->variable = variable;
- tmp->when = ast_tv(0, 0);
- if (sched_settime(&tmp->when, when)) {
- sched_release(con, tmp);
- } else {
- schedule(con, tmp);
- res = tmp->id;
- }
- }
-#ifdef DUMP_SCHEDULER
- /* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */
- ast_sched_dump(con);
-#endif
- ast_mutex_unlock(&con->lock);
- return res;
-}
-
-int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, void *data)
-{
- return ast_sched_add_variable(con, when, callback, data, 0);
-}
-
-int ast_sched_del(struct sched_context *con, int id)
-{
- /*
- * Delete the schedule entry with number
- * "id". It's nearly impossible that there
- * would be two or more in the list with that
- * id.
- */
- struct sched *last=NULL, *s;
- DEBUG(ast_log(LOG_DEBUG, "ast_sched_del()\n"));
- ast_mutex_lock(&con->lock);
- s = con->schedq;
- while(s) {
- if (s->id == id) {
- if (last)
- last->next = s->next;
- else
- con->schedq = s->next;
- con->schedcnt--;
- sched_release(con, s);
- break;
- }
- last = s;
- s = s->next;
- }
-#ifdef DUMP_SCHEDULER
- /* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */
- ast_sched_dump(con);
-#endif
- ast_mutex_unlock(&con->lock);
- if (!s) {
- ast_log(LOG_NOTICE, "Attempted to delete nonexistent schedule entry %d!\n", id);
-#ifdef DO_CRASH
- CRASH;
-#endif
- return -1;
- } else
- return 0;
-}
-
-void ast_sched_dump(const struct sched_context *con)
-{
- /*
- * Dump the contents of the scheduler to
- * stderr
- */
- struct sched *q;
- struct timeval tv = ast_tvnow();
-#ifdef SCHED_MAX_CACHE
- ast_log(LOG_DEBUG, "Asterisk Schedule Dump (%d in Q, %d Total, %d Cache)\n", con->schedcnt, con->eventcnt - 1, con->schedccnt);
-#else
- ast_log(LOG_DEBUG, "Asterisk Schedule Dump (%d in Q, %d Total)\n", con->schedcnt, con->eventcnt - 1);
-#endif
-
- ast_log(LOG_DEBUG, "=============================================================\n");
- ast_log(LOG_DEBUG, "|ID Callback Data Time (sec:ms) |\n");
- ast_log(LOG_DEBUG, "+-----+-----------------+-----------------+-----------------+\n");
- for (q = con->schedq; q; q = q->next) {
- struct timeval delta = ast_tvsub(q->when, tv);
-
- ast_log(LOG_DEBUG, "|%.4d | %-15p | %-15p | %.6ld : %.6ld |\n",
- q->id,
- q->callback,
- q->data,
- delta.tv_sec,
- (long int)delta.tv_usec);
- }
- ast_log(LOG_DEBUG, "=============================================================\n");
-
-}
-
-int ast_sched_runq(struct sched_context *con)
-{
- /*
- * Launch all events which need to be run at this time.
- */
- struct sched *current;
- struct timeval tv;
- int x=0;
- int res;
- DEBUG(ast_log(LOG_DEBUG, "ast_sched_runq()\n"));
-
- ast_mutex_lock(&con->lock);
- for(;;) {
- if (!con->schedq)
- break;
-
- /* schedule all events which are going to expire within 1ms.
- * We only care about millisecond accuracy anyway, so this will
- * help us get more than one event at one time if they are very
- * close together.
- */
- tv = ast_tvadd(ast_tvnow(), ast_tv(0, 1000));
- if (SOONER(con->schedq->when, tv)) {
- current = con->schedq;
- con->schedq = con->schedq->next;
- con->schedcnt--;
-
- /*
- * At this point, the schedule queue is still intact. We
- * have removed the first event and the rest is still there,
- * so it's permissible for the callback to add new events, but
- * trying to delete itself won't work because it isn't in
- * the schedule queue. If that's what it wants to do, it
- * should return 0.
- */
-
- ast_mutex_unlock(&con->lock);
- res = current->callback(current->data);
- ast_mutex_lock(&con->lock);
-
- if (res) {
- /*
- * If they return non-zero, we should schedule them to be
- * run again.
- */
- if (sched_settime(&current->when, current->variable? res : current->resched)) {
- sched_release(con, current);
- } else
- schedule(con, current);
- } else {
- /* No longer needed, so release it */
- sched_release(con, current);
- }
- x++;
- } else
- break;
- }
- ast_mutex_unlock(&con->lock);
- return x;
-}
-
-long ast_sched_when(struct sched_context *con,int id)
-{
- struct sched *s;
- long secs;
- DEBUG(ast_log(LOG_DEBUG, "ast_sched_when()\n"));
-
- ast_mutex_lock(&con->lock);
- s=con->schedq;
- while (s!=NULL) {
- if (s->id==id) break;
- s=s->next;
- }
- secs=-1;
- if (s!=NULL) {
- struct timeval now = ast_tvnow();
- secs=s->when.tv_sec-now.tv_sec;
- }
- ast_mutex_unlock(&con->lock);
- return secs;
-}
diff --git a/1.2-netsec/slinfactory.c b/1.2-netsec/slinfactory.c
deleted file mode 100644
index 7985ecdc6..000000000
--- a/1.2-netsec/slinfactory.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2005, Anthony Minessale II.
- *
- * Anthony Minessale <anthmct@yahoo.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief A machine to gather up arbitrary frames and convert them
- * to raw slinear on demand.
- *
- */
-
-#include <string.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/slinfactory.h"
-#include "asterisk/logger.h"
-#include "asterisk/translate.h"
-
-
-void ast_slinfactory_init(struct ast_slinfactory *sf)
-{
- memset(sf, 0, sizeof(struct ast_slinfactory));
- sf->offset = sf->hold;
- sf->queue = NULL;
-}
-
-void ast_slinfactory_destroy(struct ast_slinfactory *sf)
-{
- struct ast_frame *f;
-
- if (sf->trans) {
- ast_translator_free_path(sf->trans);
- sf->trans = NULL;
- }
-
- while((f = sf->queue)) {
- sf->queue = f->next;
- ast_frfree(f);
- }
-}
-
-int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
-{
- struct ast_frame *frame, *frame_ptr;
-
- if (!f) {
- return 0;
- }
-
- if (f->subclass != AST_FORMAT_SLINEAR) {
- if (sf->trans && f->subclass != sf->format) {
- ast_translator_free_path(sf->trans);
- sf->trans = NULL;
- }
- if (!sf->trans) {
- if ((sf->trans = ast_translator_build_path(AST_FORMAT_SLINEAR, f->subclass)) == NULL) {
- ast_log(LOG_WARNING, "Cannot build a path from %s to slin\n", ast_getformatname(f->subclass));
- return 0;
- } else {
- sf->format = f->subclass;
- }
- }
- }
-
- if (sf->trans) {
- frame = ast_translate(sf->trans, f, 0);
- } else {
- frame = ast_frdup(f);
- }
-
- if (frame) {
- int x = 0;
- for (frame_ptr = sf->queue; frame_ptr && frame_ptr->next; frame_ptr=frame_ptr->next) {
- x++;
- }
- if (frame_ptr) {
- frame_ptr->next = frame;
- } else {
- sf->queue = frame;
- }
- frame->next = NULL;
- sf->size += frame->datalen;
- return x;
- }
-
- return 0;
-
-}
-
-int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t bytes)
-{
- struct ast_frame *frame_ptr;
- int sofar = 0, ineed, remain;
- short *frame_data, *offset = buf;
-
- while (sofar < bytes) {
- ineed = bytes - sofar;
-
- if (sf->holdlen) {
- if ((sofar + sf->holdlen) <= ineed) {
- memcpy(offset, sf->hold, sf->holdlen);
- sofar += sf->holdlen;
- offset += (sf->holdlen / sizeof(short));
- sf->holdlen = 0;
- sf->offset = sf->hold;
- } else {
- remain = sf->holdlen - ineed;
- memcpy(offset, sf->offset, ineed);
- sofar += ineed;
- sf->offset += (ineed / sizeof(short));
- sf->holdlen = remain;
- }
- continue;
- }
-
- if ((frame_ptr = sf->queue)) {
- sf->queue = frame_ptr->next;
- frame_data = frame_ptr->data;
-
- if ((sofar + frame_ptr->datalen) <= ineed) {
- memcpy(offset, frame_data, frame_ptr->datalen);
- sofar += frame_ptr->datalen;
- offset += (frame_ptr->datalen / sizeof(short));
- } else {
- remain = frame_ptr->datalen - ineed;
- memcpy(offset, frame_data, ineed);
- sofar += ineed;
- frame_data += (ineed / sizeof(short));
- memcpy(sf->hold, frame_data, remain);
- sf->holdlen = remain;
- }
- ast_frfree(frame_ptr);
- } else {
- break;
- }
- }
-
- sf->size -= sofar;
- return sofar;
-}
-
-
-
-
diff --git a/1.2-netsec/sounds.txt b/1.2-netsec/sounds.txt
deleted file mode 100644
index b5fb7af07..000000000
--- a/1.2-netsec/sounds.txt
+++ /dev/null
@@ -1,729 +0,0 @@
-;Sound Files and Sound Scripts
-
-;Note: All .gsm files are in the following format: 8.000 kHz, Mono 1 kb/sec
-
-;sounds directory - File Name Sound File Script
-
-%agent-alreadyon.gsm%That agent is already logged on. Please enter your agent number followed by the pound key.
-
-%agent-incorrect.gsm%Login incorrect. Please enter your agent number followed by the pound key.
-
-%agent-newlocation.gsm%Please enter new extension followed by pound, or just press pound for immediate service.
-
-%agent-loggedoff.gsm%Agent Logged off.
-
-%agent-loginok.gsm%Agent logged in.
-
-%agent-pass.gsm%Please enter your password followed by the pound key.
-
-%agent-user.gsm%Agent login. Please enter your agent number followed by the pound key.
-
-%auth-incorrect.gsm%Login incorrect. Please enter your password followed by the pound key.
-
-%auth-thankyou.gsm%Thank you.
-
-%beep.gsm%[this is a simple beep tone]
-
-%beeperr.gsm%[this is an error beep tone]
-
-%conf-hasleft.gsm%has left the conference.
-
-%conf-hasjoin.gsm%has joined the conference.
-
-%conf-getconfno.gsm%Please enter your conference number followed by the pound key.
-
-%conf-getchannel.gsm%Please enter your channel number followed by the pound key.
-
-%conf-getpin.gsm%Please enter the conference pin number.
-
-%conf-invalid.gsm%That is not a valid conference number. Please try again.
-
-%conf-invalidpin.gsm%That pin is invalid for this conference.
-
-%conf-onlyperson.gsm%You are currently the only person in this conference.
-
-%conf-noempty.gsm%No empty conferences currently exist.
-
-%conf-enteringno.gsm%You are entering conference number
-
-%demo-abouttotry.gsm%I am about to attempt an Inter-Asterisk Exchange connection to a demonstration server located at Digium. In order for this to work you must already be connected to the Internet. Please wait a moment while I attempt to make the connection.
-
-%demo-congrats.gsm%Congratulations. You have successfully installed and executed the Asterisk open source PBX. You have also installed a set of sample sounds and configuration files that should help you to get started. Like a normal PBX you will navigate this demonstration by dialing digits. If you are using a console channel driver instead of a real phone you can use the dial, answer, and hang up commands to simulate the actions of a standard telephone.
-
-%demo-echodone.gsm%The echo test has been completed.
-
-%demo-echotest.gsm%You are about to enter an echo test. In this mode everything you say will be repeated back to you just as soon as it is received. The purpose of this test is to give you an audible sense of the latency between you and the machine that is running the echo test application. You may end the test by hanging up or by pressing the pound key.
-
-%demo-enterkeywords.gsm%Please enter one or more keywords separated by * and then press the pound key.
-
-%demo-nomatch.gsm%I'm sorry there are no matches for those keywords
-
-%demo-instruct.gsm%If you would like to learn more technical information about Asterisk dial 2 now. If you'd like to test out the voice over IP capabilities of Asterisk you can dial 500 to attempt an Inter-Asterisk Exchange or IAX connection to a demonstration server at Digium. In order for this test to work you will need to be connected to the Internet and have at least a 28.8 kilobit modem. To execute an echo test dial 600. This test is most useful when you have connected to this Asterisk server from a remote location. The sample configuration also has a single user with extension 1234 and password 4242. That user is configured to ring the console when their extension is dialed. If you dial 1234 you can try to ring the console. If the console is busy or unavailable you will be given the option to leave voicemail. To check voice mail for the user dial extension 8500 to enter the voicemail system. Finally, you can press the pound key to disconnect from the PBX.
-
-%demo-moreinfo.gsm%This message has not yet been written.
-
-%demo-nogo.gsm%I am afraid I was unable to create a connection to the Digium demonstration Asterisk server. You may find some helpful debugging information on the Asterisk console.
-
-%demo-thanks.gsm%Goodbye. Thank you for trying out the Asterisk Open Source PBX.
-
-%dir-instr.gsm%If this is the person you are looking for press 1 now, otherwise please press star now.
-
-%dir-intro.gsm%Welcome to the Asterisk directory. Please enter the first three letters of your parties last name using your touch tone keypad. Use the 7 key for Q and the 9 key for Z.
-
-%dir-intro-fn.gsm%Welcome to the Asterisk directory. Please enter the first three letters of your parties first name using your touch tone keypad. Use the 7 key for Q and the 9 key for Z.
-
-%dir-nomatch.gsm%No directory entries match your search.
-
-%dir-nomore.gsm%There are no more compatible entries in the directory.
-
-%hello-world.gsm%Hello world.
-
-%invalid.gsm%I am sorry, that's not a valid extension. Please try again.
-
-%pbx-invalid.gsm%I am sorry, that's not a valid extension. Please try again.
-
-%pbx-invalidpark.gsm%I am sorry, there is no call parked on that extension. Please try again.
-
-%pbx-transfer.gsm%Transfer.
-
-%queue-periodic-announce.gsm%All of our represenatives are currently busy. Please stay on the line and your call will be answered by the next available representative.
-
-%queue-callswaiting.gsm%Waiting to speak with a representative
-
-%queue-holdtime.gsm%The estimated hold time is currently
-
-%queue-reporthold.gsm%Hold time
-
-%queue-minutes.gsm%Minutes
-
-%queue-seconds.gsm%Seconds
-
-%queue-thankyou.gsm%Thank you for your patience
-
-%queue-thereare.gsm%You are currently caller number
-
-%queue-youarenext.gsm%Your call is now first in line and will be answered by the next available representative.
-
-%ss-noservice.gsm%The number you have dialed is not in service. Please check the number and try again.
-
-%transfer.gsm%Please hold while I try that extension.
-
-%vm-forward.gsm%Press 1 to enter an extension, press 2 to use the directory
-
-%vm-Cust1.gsm%folder 5
-
-%vm-Cust2.gsm%folder 6
-
-%vm-Cust3.gsm%folder 7
-
-%vm-Cust4.gsm%folder 8
-
-%vm-Cust5.gsm%folder 9
-
-%vm-and.gsm%and
-
-%vm-changeto.gsm%Change to which folder?
-
-%vm-delete.gsm%Press 7 to delete this message.
-
-%vm-deleted.gsm%Message deleted.
-
-%vm-extension.gsm%extension
-
-%vm-Family.gsm%family
-
-%vm-first.gsm%first
-
-%vm-for.gsm%for
-
-%vm-Friends.gsm%friends
-
-%vm-goodbye.gsm%Goodbye
-
-%vm-helpexit.gsm%Press star for help or pound to exit.
-
-%vm-INBOX.gsm%new
-
-%vm-minutes.gsm%minutes
-
-%vm-incorrect-mailbox.gsm%Login incorrect. Mailbox?
-
-%vm-incorrect.gsm%Login incorrect.
-
-%vm-instructions.gsm%To look into your messages press 1 now. You may quit voicemail at any time by pressing the pound key.
-
-%vm-intro.gsm%Please leave your message after the tone. When done hang up or press the pound key. (simple tone sound plays)
-
-%vm-isonphone.gsm%is on the phone
-
-%vm-isunavail.gsm%is unavailable
-
-%vm-last.gsm%last
-
-%vm-login.gsm%Asterisk Mail. Mailbox?
-
-%vm-message.gsm%message
-
-%vm-messages.gsm%messages
-
-%vm-mismatch.gsm%The passwords you entered and re-entered did not match. Please try again.
-
-%vm-msginstruct.gsm%To hear the next message press 6, to repeat this message press 5, to hear the previous message press 4, to delete or undelete this message press seven, to quite voicemail press pound. During message playback, you may press * to rewind, and # to fast forward.
-
-%vm-msgsaved.gsm%Your message has been saved.
-
-%vm-newpassword.gsm%Please enter your new password followed by the pound key?
-
-%vm-next.gsm%Press 6 to play the next message.
-
-%vm-no.gsm%no
-
-%vm-nobodyavail.gsm%Nobody is available to take your call at the moment
-
-%vm-nomore.gsm%No more messages.
-
-%vm-Old.gsm%old
-
-%vm-onefor.gsm%Press 1 for
-
-%vm-options.gsm%Press 1 to record your unavailable message, press 2 to record your busy message, press 3 to record your name, press 4 to record your temporary message, press 5 to change your password, press star to return to the main menu.
-
-%vm-opts.gsm%Press 2 to change folders, press 3 for advanced options, press zero for mailbox options.
-
-%vm-passchanged.gsm%Your passwords have been changed.
-
-%vm-password.gsm%password
-
-%vm-press.gsm%press
-
-%vm-prev.gsm%Press 4 for the previous message
-
-%vm-rec-busy.gsm%After the tone say your busy message and then press the pound key.
-
-%vm-rec-name.gsm%After the tone say your name and then press the pound key.
-
-%vm-rec-unv.gsm%After the tone say your unavailable message and then press the pound key.
-
-%vm-rec-temp.gsm%After the tone, say your temporary message, and then press the pound key.
-
-%vm-reenterpassword.gsm%Please re-enter your password followed by the pound key.
-
-%vm-repeat.gsm%Press 5 to repeat the current message.
-
-%vm-saved.gsm%saved
-
-%vm-savedto.gsm%saved to
-
-%vm-savefolder.gsm%Which folder should I save the message to?
-
-%vm-savemessage.gsm%or 9 to save this message
-
-%vm-sorry.gsm%I'm sorry I did not understand your response.
-
-%vm-tempgreeting.gsm%press 1 to record your temporary greeting
-
-%vm-tempgreeting2.gsm%press 1 to record your temporary greeting, or press 2 to erase your temporary greeting
-
-%vm-tempremoved.gsm%Your temporary greeting has been removed
-
-%vm-theperson.gsm%The person at extension
-
-%vm-tocancel.gsm%or pound to cancel.
-
-%vm-toforward.gsm%Press 8 to forward the message to another user
-
-%vm-undelete.gsm%Press 7 to undelete this message
-
-%vm-undeleted.gsm%Message undeleted.
-
-%vm-whichbox.gsm%To leave a message, please enter a mailbox number.
-
-%vm-Work.gsm%work
-
-%vm-youhave.gsm%you have
-
-%vm-newuser.gsm%Welcome to Comedian Mail. First, I will guide you through a short setup process.
-
-%priv-sayname.gsm%After the tone, please say your name or the company you represent.
-
-%priv-trying.gsm%Please hold while I attempt to contact your party.
-
-%priv-callfrom.gsm%You have a call from
-
-%priv-at.gsm%at
-
-%priv-instruct.gsm%Press 1 to accept this call. Press 2 to not accept this call. Press 3 to always accept calls from this number. Press 4 to never accept calls from this number. Press 5 to reject calls from this number and request that they add you to their do not call list.
-
-%priv-callee-options.gsm%Dial 1 if you wish this caller to reach you directly now, and in the future. Dial 2 if you wish to send this caller to voicemail now and forevermore. Dial 3 to send this caller to the torture menus, now and forevermore. Dial 4 to send this caller to a polite "don't call" menu, now and forevermore. Dial 5 to allow this caller to come straight thru to you in the future, but just this once, send them to voicemail.
-
-%screen-callee-options.gsm%You have these options: Dial 1 if you wish to immediately connect to the incoming call. Dial 2 if you wish to send this caller to voicemail. Dial 3 to send this callerr to the torture menus. Dial 4 to send this caller to a polite "don't call" menu.
-
-%priv-introsaved.gsm%Thank you. Please hold, while I attempt to connect you with your party!
-
-%priv-recordintro.gsm%At the tone, please say your name.
-
-%priv-callpending.gsm%I have a caller waiting, who introduces themselves as:
-
-%privacy-unident.gsm%The party you are trying to reach does not accept unidentified calls.
-
-%privacy-prompt.gsm%Please enter your phone number, starting with the area code.
-
-%privacy-incorrect.gsm%I'm sorry, that number is not valid.
-
-%privacy-thankyou.gsm%Thank you.
-
-%tt-allbusy.gsm%All representatives of the household are currently assisting other telemarketers. Please hold and your call will be answered in the order it was received.
-
-%tt-monkeysintro.gsm%They have been carried away by monkeys
-
-%tt-monkeys.gsm%[sound of monkeys screaming]
-
-%tt-somethingwrong.gsm%Something is terribly wrong
-
-%tt-weasels.gsm%Weasels have eaten our phone system
-
-;dictate directory - app_dictate
-
-%both_help.gsm%press * to toggle pause, press # to enter a new dictation filename
-
-%enter_filename.gsm%Enter a numeric dictation filename followed by # or just # to exit
-
-%forhelp.gsm%press 0 for help
-
-%inithelp.gsm%1 to switch to playback mode
-
-%pause.gsm%pause
-
-%paused.gsm%paused
-
-%play_help.gsm%press 1 to switch to record mode, press 2 to toggle fast playback, press 7 to jump backwards, press 8 to jump forwards
-
-%playback.gsm%playback
-
-%playback_mode.gsm%playback mode
-
-%record.gsm%record
-
-%record_help.gsm%press 1 to switch to playback mode, press 8 to truncate the file and start over
-
-%record_mode.gsm%record mode
-
-%truncating_audio.gsm%truncating audio
-
-;digits directory - File Name Sound File Script
-
-%minus.gsm%minus
-
-%0.gsm%zero
-
-%1.gsm%one
-
-%2.gsm%two
-
-%3.gsm%three
-
-%4.gsm%four
-
-%5.gsm%five
-
-%6.gsm%six
-
-%7.gsm%seven
-
-%8.gsm%eight
-
-%9.gsm%nine
-
-%10.gsm%ten
-
-%11.gsm%eleven
-
-%12.gsm%twelve
-
-%13.gsm%thirteen
-
-%14.gsm%fourteen
-
-%15.gsm%fifteen
-
-%16.gsm%sixteen
-
-%17.gsm%seventeen
-
-%18.gsm%eighteen
-
-%19.gsm%nineteen
-
-%20.gsm%twenty
-
-%30.gsm%thirty
-
-%40.gsm%forty
-
-%50.gsm%fifty
-
-%60.gsm%sixty
-
-%70.gsm%seventy
-
-%80.gsm%eighty
-
-%90.gsm%ninety
-
-%a-m.gsm%A.M.
-
-%day-0.gsm%Sunday
-
-%day-1.gsm%Monday
-
-%day-2.gsm%Tuesday
-
-%day-3.gsm%Wednesday
-
-%day-4.gsm%Thursday
-
-%day-5.gsm%Friday
-
-%day-6.gsm%Saturday
-
-%dollars.gsm%dollars
-
-%hundred.gsm%hundred
-
-%million.gsm%million
-
-%mon-0.gsm%January
-
-%mon-1.gsm%February
-
-%mon-2.gsm%March
-
-%mon-3.gsm%April
-
-%mon-4.gsm%May
-
-%mon-5.gsm%June
-
-%mon-6.gsm%July
-
-%mon-7.gsm%August
-
-%mon-8.gsm%September
-
-%mon-9.gsm%October
-
-%mon-10.gsm%November
-
-%mon-11.gsm%December
-
-%oclock.gsm%o'clock
-
-%oh.gsm%oh
-
-%p-m.gsm%P.M.
-
-%pound.gsm%pound
-
-%seconds.gsm%seconds
-
-%star.gsm%star
-
-%thousand.gsm%thousand
-
-%h-1.gsm%first
-
-%h-2.gsm%second
-
-%h-3.gsm%third
-
-%h-4.gsm%fourth
-
-%h-5.gsm%fifth
-
-%h-6.gsm%sixth
-
-%h-7.gsm%seventh
-
-%h-8.gsm%eighth
-
-%h-9.gsm%ninth
-
-%h-10.gsm%tenth
-
-%h-11.gsm%eleventh
-
-%h-12.gsm%twelfth
-
-%h-13.gsm%thirteenth
-
-%h-14.gsm%fourteenth
-
-%h-15.gsm%fifteenth
-
-%h-16.gsm%sixteenth
-
-%h-17.gsm%seventeenth
-
-%h-18.gsm%eighteenth
-
-%h-19.gsm%nineteenth
-
-%h-20.gsm%twentieth
-
-%h-30.gsm%thirtieth
-
-%today.gsm%today
-
-%tomorrow.gsm%tomorrow
-
-%yesterday.gsm%yesterday
-
-%vm-received.gsm%received
-
-%hours.gsm%hours
-
-%minutes.gsm%minutes
-
-%vm-forwardoptions.gsm%press 1 to prepend a message or 2 to forward the
- message without prepending
-
-%vm-mailboxfull.gsm%sorry but the users mail box can't accept more messages
-
-%vm-tocancelmsg.gsm%press star to cancel this message
-
-%vm-from.gsm%from
-
-%vm-from-extension.gsm%from extension
-
-%vm-from-phonenumber.gsm%from phone number
-
-%vm-unknown-caller.gsm%from an unknown caller
-
-%vm-advopts.gsm%press 3 for advanced options
-
-%vm-saveoper.gsm%press 1 to accept this recording, or continue to hold
-
-%vm-toreply.gsm%press 1 to send a reply
-
-%vm-tocallback.gsm%press 2 to call the person who sent this message
-
-%vm-tohearenv.gsm%press 3 to hear the message envelope
-
-%vm-tomakecall.gsm%press 4 to place an outgoing call
-
-%vm-starmain.gsm%press star to return to the main menu
-
-%vm-dialout.gsm%please wait while i connect your call
-
-%vm-enter-num-to-call.gsm%please enter the number you wish to call
-
-%vm-then-pound.gsm%then press pound
-
-%vm-star-cancel.gsm%press star to cancel
-
-%vm-num-i-have.gsm%the number i have is
-
-%vm-tocallnum.gsm%press 1 to call this number
-
-%vm-calldiffnum.gsm%press 2 to enter a different number
-
-%vm-nonumber.gsm%i'm afraid i don't know who sent this message
-
-%vm-toenternumber.gsm%press 1 to enter a number
-
-%vm-nobox.gsm%you cannot reply to this message because the sender does not have a mailbox
-
-%vm-review.gsm%press 1 to accept this recording press 2 to listen to it press 3 to rerecord your message
-
-%vm-torerecord.gsm%press 3 to rerecord your message
-
-%vm-reachoper.gsm%press 0 to reach an operator
-
-%vm-tooshort.gsm%your message is too short
-
-%9_p.gsm%niner
-
-%a.gsm%a
-
-%b.gsm%b
-
-%c.gsm%c
-
-%d.gsm%d
-
-%e.gsm%e
-
-%f.gsm%f
-
-%g.gsm%g
-
-%h.gsm%h
-
-%i.gsm%i
-
-%j.gsm%j
-
-%k.gsm%k
-
-%l.gsm%l
-
-%m.gsm%m
-
-%n.gsm%n
-
-%o.gsm%o
-
-%p.gsm%p
-
-%q.gsm%q
-
-%r.gsm%r
-
-%s.gsm%s
-
-%t.gsm%t
-
-%u.gsm%u
-
-%v.gsm%v
-
-%w.gsm%w
-
-%x.gsm%x
-
-%y.gsm%y
-
-%z.gsm%z
-
-%zed.gsm%zed
-
-%a_p.gsm%alpha
-
-%b_p.gsm%bravo
-
-%c_p.gsm%charlie
-
-%d_p.gsm%delta
-
-%e_p.gsm%echo
-
-%f_p.gsm%foxtrot
-
-%g_p.gsm%golf
-
-%h_p.gsm%hotel
-
-%i_p.gsm%india
-
-%j_p.gsm%juliet
-
-%k_p.gsm%kilo
-
-%l_p.gsm%lima
-
-%m_p.gsm%mike
-
-%n_p.gsm%november
-
-%o_p.gsm%oscar
-
-%p_p.gsm%papa
-
-%q_p.gsm%quebec
-
-%r_p.gsm%romeo
-
-%s_p.gsm%sierra
-
-%t_p.gsm%tango
-
-%u_p.gsm%uniform
-
-%v_p.gsm%victor
-
-%w_p.gsm%wiskey
-
-%x_p.gsm%xray
-
-%y_p.gsm%yankee
-
-%z_p.gsm%zulu
-
-%niner.gsm%niner
-
-; Misc
-
-%percent.gsm%percent [%]
-
-%plus.gsm%plus [+]
-
-%exclaimation-point.gsm%exclaimation-point [!]
-
-%at.gsm%at [@]
-
-%dollar.gsm%dollar [$]
-
-%dash.gsm%dash [-]
-
-%dot.gsm%dot [.]
-
-%slash.gsm%slash [/]
-
-%space.gsm%space [ ]
-
-%equals.gsm%equals [=]
-
-%conf-locked.gsm%This conference is locked!
-
-%conf-kicked.gsm%You have been kicked from this conference
-
-%conf-adminmenu.gsm%Please press 1 to mute or unmute yourself, 2 to lock or unlock the conference, 3 to eject the last user, 4 or 6 to decrease or increase the conference volume, 7 or 9 to decrease or increase your volume, or 8 to exit
-
-%conf-usermenu.gsm%Please press 1 to mute or unmute yourself, 4 or 6 to decrease or increase the conference volume, 7 or 9 to decrease or increase your volume, or 8 to exit
-
-%conf-errormenu.gsm%Invalid Choice
-
-%conf-muted.gsm%You are now muted
-
-%conf-unmuted.gsm%You are now unmuted
-
-%conf-lockednow.gsm%The conference is now locked
-
-%conf-unlockednow.gsm%The conference is now unlocked
-
-%vm-leavemsg.gsm% Press 5 to send a voicemail message
-
-%queue-less-than.gsm%less than
-
-%conf-waitforleader.gsm%The conference will begin when the leader arrives.
-
-%conf-userwilljoin.gsm%user will join the conference.
-
-%conf-userswilljoin.gsm%users will join the conference.
-
-%conf-leaderhasleft.gsm%The leader has left the conference.
-
-%conf-placeintoconf.gsm%You will now be placed into the conference.
-
-%conf-thereare.gsm%There are currently
-
-%conf-otherinparty.gsm%other participants in the conference
-
-%conf-onlyone.gsm%There is currently only one other participant in the conference.
-
-
-%spy-agent.gsm%Agent
-
-%spy-h323.gsm%H.323
-
-%spy-iax.gsm%IAX
-
-%spy-iax2.gsm%IAX (note: does not say "2")
-
-%spy-mgcp.gsm%MGCP
-
-%spy-sip.gsm%SIP
-
-%spy-skinny.gsm%Skinny
-
-%spy-zap.gsm%Zap
diff --git a/1.2-netsec/sounds/agent-alreadyon.gsm b/1.2-netsec/sounds/agent-alreadyon.gsm
deleted file mode 100644
index 5d24dfa21..000000000
--- a/1.2-netsec/sounds/agent-alreadyon.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/agent-incorrect.gsm b/1.2-netsec/sounds/agent-incorrect.gsm
deleted file mode 100644
index 87ddee149..000000000
--- a/1.2-netsec/sounds/agent-incorrect.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/agent-loggedoff.gsm b/1.2-netsec/sounds/agent-loggedoff.gsm
deleted file mode 100644
index ef50c1bb1..000000000
--- a/1.2-netsec/sounds/agent-loggedoff.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/agent-loginok.gsm b/1.2-netsec/sounds/agent-loginok.gsm
deleted file mode 100644
index 9bf94b3fa..000000000
--- a/1.2-netsec/sounds/agent-loginok.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/agent-newlocation.gsm b/1.2-netsec/sounds/agent-newlocation.gsm
deleted file mode 100644
index b3925aca0..000000000
--- a/1.2-netsec/sounds/agent-newlocation.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/agent-pass.gsm b/1.2-netsec/sounds/agent-pass.gsm
deleted file mode 100644
index 5115c88f4..000000000
--- a/1.2-netsec/sounds/agent-pass.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/agent-user.gsm b/1.2-netsec/sounds/agent-user.gsm
deleted file mode 100644
index 6149226e0..000000000
--- a/1.2-netsec/sounds/agent-user.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/auth-incorrect.gsm b/1.2-netsec/sounds/auth-incorrect.gsm
deleted file mode 100644
index d8ef6e156..000000000
--- a/1.2-netsec/sounds/auth-incorrect.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/auth-thankyou.gsm b/1.2-netsec/sounds/auth-thankyou.gsm
deleted file mode 100644
index 45e7104e2..000000000
--- a/1.2-netsec/sounds/auth-thankyou.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/beep.gsm b/1.2-netsec/sounds/beep.gsm
deleted file mode 100644
index 5a0467a6c..000000000
--- a/1.2-netsec/sounds/beep.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/beeperr.gsm b/1.2-netsec/sounds/beeperr.gsm
deleted file mode 100644
index 60fb9235d..000000000
--- a/1.2-netsec/sounds/beeperr.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-adminmenu.gsm b/1.2-netsec/sounds/conf-adminmenu.gsm
deleted file mode 100644
index a9d053215..000000000
--- a/1.2-netsec/sounds/conf-adminmenu.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-enteringno.gsm b/1.2-netsec/sounds/conf-enteringno.gsm
deleted file mode 100644
index 3b5b454df..000000000
--- a/1.2-netsec/sounds/conf-enteringno.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-errormenu.gsm b/1.2-netsec/sounds/conf-errormenu.gsm
deleted file mode 100644
index 6388c1c52..000000000
--- a/1.2-netsec/sounds/conf-errormenu.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-getchannel.gsm b/1.2-netsec/sounds/conf-getchannel.gsm
deleted file mode 100644
index 6f91db8ff..000000000
--- a/1.2-netsec/sounds/conf-getchannel.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-getconfno.gsm b/1.2-netsec/sounds/conf-getconfno.gsm
deleted file mode 100644
index 10e2e9f75..000000000
--- a/1.2-netsec/sounds/conf-getconfno.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-getpin.gsm b/1.2-netsec/sounds/conf-getpin.gsm
deleted file mode 100644
index c8d6337e5..000000000
--- a/1.2-netsec/sounds/conf-getpin.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-hasjoin.gsm b/1.2-netsec/sounds/conf-hasjoin.gsm
deleted file mode 100644
index 8891fcd47..000000000
--- a/1.2-netsec/sounds/conf-hasjoin.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-hasleft.gsm b/1.2-netsec/sounds/conf-hasleft.gsm
deleted file mode 100644
index 5515baff0..000000000
--- a/1.2-netsec/sounds/conf-hasleft.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-invalid.gsm b/1.2-netsec/sounds/conf-invalid.gsm
deleted file mode 100644
index 519c036ea..000000000
--- a/1.2-netsec/sounds/conf-invalid.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-invalidpin.gsm b/1.2-netsec/sounds/conf-invalidpin.gsm
deleted file mode 100644
index 85a6b309b..000000000
--- a/1.2-netsec/sounds/conf-invalidpin.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-kicked.gsm b/1.2-netsec/sounds/conf-kicked.gsm
deleted file mode 100644
index 33ef20cd6..000000000
--- a/1.2-netsec/sounds/conf-kicked.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-leaderhasleft.gsm b/1.2-netsec/sounds/conf-leaderhasleft.gsm
deleted file mode 100644
index 8bb11c1a8..000000000
--- a/1.2-netsec/sounds/conf-leaderhasleft.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-locked.gsm b/1.2-netsec/sounds/conf-locked.gsm
deleted file mode 100644
index 82b59be5d..000000000
--- a/1.2-netsec/sounds/conf-locked.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-lockednow.gsm b/1.2-netsec/sounds/conf-lockednow.gsm
deleted file mode 100644
index 0288ff62b..000000000
--- a/1.2-netsec/sounds/conf-lockednow.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-muted.gsm b/1.2-netsec/sounds/conf-muted.gsm
deleted file mode 100644
index 014a58998..000000000
--- a/1.2-netsec/sounds/conf-muted.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-noempty.gsm b/1.2-netsec/sounds/conf-noempty.gsm
deleted file mode 100644
index 14727a326..000000000
--- a/1.2-netsec/sounds/conf-noempty.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-onlyone.gsm b/1.2-netsec/sounds/conf-onlyone.gsm
deleted file mode 100644
index 3584f00f9..000000000
--- a/1.2-netsec/sounds/conf-onlyone.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-onlyperson.gsm b/1.2-netsec/sounds/conf-onlyperson.gsm
deleted file mode 100644
index 15c01a3eb..000000000
--- a/1.2-netsec/sounds/conf-onlyperson.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-otherinparty.gsm b/1.2-netsec/sounds/conf-otherinparty.gsm
deleted file mode 100644
index 811263d8c..000000000
--- a/1.2-netsec/sounds/conf-otherinparty.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-placeintoconf.gsm b/1.2-netsec/sounds/conf-placeintoconf.gsm
deleted file mode 100644
index 0d570da93..000000000
--- a/1.2-netsec/sounds/conf-placeintoconf.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-thereare.gsm b/1.2-netsec/sounds/conf-thereare.gsm
deleted file mode 100644
index c810b170f..000000000
--- a/1.2-netsec/sounds/conf-thereare.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-unlockednow.gsm b/1.2-netsec/sounds/conf-unlockednow.gsm
deleted file mode 100644
index a9cfe0077..000000000
--- a/1.2-netsec/sounds/conf-unlockednow.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-unmuted.gsm b/1.2-netsec/sounds/conf-unmuted.gsm
deleted file mode 100644
index 44c26b935..000000000
--- a/1.2-netsec/sounds/conf-unmuted.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-usermenu.gsm b/1.2-netsec/sounds/conf-usermenu.gsm
deleted file mode 100644
index 4176d7cc1..000000000
--- a/1.2-netsec/sounds/conf-usermenu.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-userswilljoin.gsm b/1.2-netsec/sounds/conf-userswilljoin.gsm
deleted file mode 100644
index 549a7033a..000000000
--- a/1.2-netsec/sounds/conf-userswilljoin.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-userwilljoin.gsm b/1.2-netsec/sounds/conf-userwilljoin.gsm
deleted file mode 100644
index 484f75fe9..000000000
--- a/1.2-netsec/sounds/conf-userwilljoin.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/conf-waitforleader.gsm b/1.2-netsec/sounds/conf-waitforleader.gsm
deleted file mode 100644
index 05b2e2e1f..000000000
--- a/1.2-netsec/sounds/conf-waitforleader.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-abouttotry.gsm b/1.2-netsec/sounds/demo-abouttotry.gsm
deleted file mode 100644
index a4809e38f..000000000
--- a/1.2-netsec/sounds/demo-abouttotry.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-congrats.gsm b/1.2-netsec/sounds/demo-congrats.gsm
deleted file mode 100644
index dd49382e5..000000000
--- a/1.2-netsec/sounds/demo-congrats.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-echodone.gsm b/1.2-netsec/sounds/demo-echodone.gsm
deleted file mode 100644
index 817a221ab..000000000
--- a/1.2-netsec/sounds/demo-echodone.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-echotest.gsm b/1.2-netsec/sounds/demo-echotest.gsm
deleted file mode 100644
index 2e5b659a7..000000000
--- a/1.2-netsec/sounds/demo-echotest.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-enterkeywords.gsm b/1.2-netsec/sounds/demo-enterkeywords.gsm
deleted file mode 100644
index dafd7a7d9..000000000
--- a/1.2-netsec/sounds/demo-enterkeywords.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-instruct.gsm b/1.2-netsec/sounds/demo-instruct.gsm
deleted file mode 100644
index 459dacb40..000000000
--- a/1.2-netsec/sounds/demo-instruct.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-moreinfo.gsm b/1.2-netsec/sounds/demo-moreinfo.gsm
deleted file mode 100644
index ffb7f56c4..000000000
--- a/1.2-netsec/sounds/demo-moreinfo.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-nogo.gsm b/1.2-netsec/sounds/demo-nogo.gsm
deleted file mode 100644
index 552629fd2..000000000
--- a/1.2-netsec/sounds/demo-nogo.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-nomatch.gsm b/1.2-netsec/sounds/demo-nomatch.gsm
deleted file mode 100644
index a869457e5..000000000
--- a/1.2-netsec/sounds/demo-nomatch.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/demo-thanks.gsm b/1.2-netsec/sounds/demo-thanks.gsm
deleted file mode 100644
index 878cbc10b..000000000
--- a/1.2-netsec/sounds/demo-thanks.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/both_help.gsm b/1.2-netsec/sounds/dictate/both_help.gsm
deleted file mode 100644
index 6416c5855..000000000
--- a/1.2-netsec/sounds/dictate/both_help.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/enter_filename.gsm b/1.2-netsec/sounds/dictate/enter_filename.gsm
deleted file mode 100644
index 9de823758..000000000
--- a/1.2-netsec/sounds/dictate/enter_filename.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/forhelp.gsm b/1.2-netsec/sounds/dictate/forhelp.gsm
deleted file mode 100644
index 3824a3308..000000000
--- a/1.2-netsec/sounds/dictate/forhelp.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/pause.gsm b/1.2-netsec/sounds/dictate/pause.gsm
deleted file mode 100644
index 55fb96f85..000000000
--- a/1.2-netsec/sounds/dictate/pause.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/paused.gsm b/1.2-netsec/sounds/dictate/paused.gsm
deleted file mode 100644
index b48f394b1..000000000
--- a/1.2-netsec/sounds/dictate/paused.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/play_help.gsm b/1.2-netsec/sounds/dictate/play_help.gsm
deleted file mode 100644
index 5f854ac98..000000000
--- a/1.2-netsec/sounds/dictate/play_help.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/playback.gsm b/1.2-netsec/sounds/dictate/playback.gsm
deleted file mode 100644
index 48c16c186..000000000
--- a/1.2-netsec/sounds/dictate/playback.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/playback_mode.gsm b/1.2-netsec/sounds/dictate/playback_mode.gsm
deleted file mode 100644
index 98fd711fc..000000000
--- a/1.2-netsec/sounds/dictate/playback_mode.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/record.gsm b/1.2-netsec/sounds/dictate/record.gsm
deleted file mode 100644
index fe3cee8c6..000000000
--- a/1.2-netsec/sounds/dictate/record.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/record_help.gsm b/1.2-netsec/sounds/dictate/record_help.gsm
deleted file mode 100644
index daf49ba5c..000000000
--- a/1.2-netsec/sounds/dictate/record_help.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/record_mode.gsm b/1.2-netsec/sounds/dictate/record_mode.gsm
deleted file mode 100644
index 52203a951..000000000
--- a/1.2-netsec/sounds/dictate/record_mode.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dictate/truncating_audio.gsm b/1.2-netsec/sounds/dictate/truncating_audio.gsm
deleted file mode 100644
index 90db78679..000000000
--- a/1.2-netsec/sounds/dictate/truncating_audio.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/0.gsm b/1.2-netsec/sounds/digits/0.gsm
deleted file mode 100644
index 692840955..000000000
--- a/1.2-netsec/sounds/digits/0.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/1.gsm b/1.2-netsec/sounds/digits/1.gsm
deleted file mode 100644
index 7cc5f2ba4..000000000
--- a/1.2-netsec/sounds/digits/1.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/10.gsm b/1.2-netsec/sounds/digits/10.gsm
deleted file mode 100644
index 0977d4434..000000000
--- a/1.2-netsec/sounds/digits/10.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/11.gsm b/1.2-netsec/sounds/digits/11.gsm
deleted file mode 100644
index af9661d48..000000000
--- a/1.2-netsec/sounds/digits/11.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/12.gsm b/1.2-netsec/sounds/digits/12.gsm
deleted file mode 100644
index 929d40540..000000000
--- a/1.2-netsec/sounds/digits/12.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/13.gsm b/1.2-netsec/sounds/digits/13.gsm
deleted file mode 100644
index b4842dba4..000000000
--- a/1.2-netsec/sounds/digits/13.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/14.gsm b/1.2-netsec/sounds/digits/14.gsm
deleted file mode 100644
index d87e0a0fd..000000000
--- a/1.2-netsec/sounds/digits/14.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/15.gsm b/1.2-netsec/sounds/digits/15.gsm
deleted file mode 100644
index 8fa57e178..000000000
--- a/1.2-netsec/sounds/digits/15.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/16.gsm b/1.2-netsec/sounds/digits/16.gsm
deleted file mode 100644
index b1f8a2b24..000000000
--- a/1.2-netsec/sounds/digits/16.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/17.gsm b/1.2-netsec/sounds/digits/17.gsm
deleted file mode 100644
index 26b09841f..000000000
--- a/1.2-netsec/sounds/digits/17.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/18.gsm b/1.2-netsec/sounds/digits/18.gsm
deleted file mode 100644
index c649e4a4d..000000000
--- a/1.2-netsec/sounds/digits/18.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/19.gsm b/1.2-netsec/sounds/digits/19.gsm
deleted file mode 100644
index 1822987db..000000000
--- a/1.2-netsec/sounds/digits/19.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/2.gsm b/1.2-netsec/sounds/digits/2.gsm
deleted file mode 100644
index 389c3c2e7..000000000
--- a/1.2-netsec/sounds/digits/2.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/20.gsm b/1.2-netsec/sounds/digits/20.gsm
deleted file mode 100644
index b8a48ff78..000000000
--- a/1.2-netsec/sounds/digits/20.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/3.gsm b/1.2-netsec/sounds/digits/3.gsm
deleted file mode 100644
index cbb43eeb6..000000000
--- a/1.2-netsec/sounds/digits/3.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/30.gsm b/1.2-netsec/sounds/digits/30.gsm
deleted file mode 100644
index 370f5d351..000000000
--- a/1.2-netsec/sounds/digits/30.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/4.gsm b/1.2-netsec/sounds/digits/4.gsm
deleted file mode 100644
index c531a0678..000000000
--- a/1.2-netsec/sounds/digits/4.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/40.gsm b/1.2-netsec/sounds/digits/40.gsm
deleted file mode 100644
index 19db53fcf..000000000
--- a/1.2-netsec/sounds/digits/40.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/5.gsm b/1.2-netsec/sounds/digits/5.gsm
deleted file mode 100644
index 8b8ab3bf5..000000000
--- a/1.2-netsec/sounds/digits/5.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/50.gsm b/1.2-netsec/sounds/digits/50.gsm
deleted file mode 100644
index c3c0fd6e7..000000000
--- a/1.2-netsec/sounds/digits/50.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/6.gsm b/1.2-netsec/sounds/digits/6.gsm
deleted file mode 100644
index 63d8e9dd2..000000000
--- a/1.2-netsec/sounds/digits/6.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/60.gsm b/1.2-netsec/sounds/digits/60.gsm
deleted file mode 100644
index ca1e88397..000000000
--- a/1.2-netsec/sounds/digits/60.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/7.gsm b/1.2-netsec/sounds/digits/7.gsm
deleted file mode 100644
index 5a7f83cf2..000000000
--- a/1.2-netsec/sounds/digits/7.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/70.gsm b/1.2-netsec/sounds/digits/70.gsm
deleted file mode 100644
index 3f4aca356..000000000
--- a/1.2-netsec/sounds/digits/70.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/8.gsm b/1.2-netsec/sounds/digits/8.gsm
deleted file mode 100644
index 9b4fff3ba..000000000
--- a/1.2-netsec/sounds/digits/8.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/80.gsm b/1.2-netsec/sounds/digits/80.gsm
deleted file mode 100644
index 936bed9a8..000000000
--- a/1.2-netsec/sounds/digits/80.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/9.gsm b/1.2-netsec/sounds/digits/9.gsm
deleted file mode 100644
index 09afbbb68..000000000
--- a/1.2-netsec/sounds/digits/9.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/90.gsm b/1.2-netsec/sounds/digits/90.gsm
deleted file mode 100644
index dc98cacb2..000000000
--- a/1.2-netsec/sounds/digits/90.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/a-m.gsm b/1.2-netsec/sounds/digits/a-m.gsm
deleted file mode 100644
index 42a08b32f..000000000
--- a/1.2-netsec/sounds/digits/a-m.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/at.gsm b/1.2-netsec/sounds/digits/at.gsm
deleted file mode 100644
index 76227229b..000000000
--- a/1.2-netsec/sounds/digits/at.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/day-0.gsm b/1.2-netsec/sounds/digits/day-0.gsm
deleted file mode 100644
index 98eb38171..000000000
--- a/1.2-netsec/sounds/digits/day-0.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/day-1.gsm b/1.2-netsec/sounds/digits/day-1.gsm
deleted file mode 100644
index 6459d45b0..000000000
--- a/1.2-netsec/sounds/digits/day-1.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/day-2.gsm b/1.2-netsec/sounds/digits/day-2.gsm
deleted file mode 100644
index 436c55d0b..000000000
--- a/1.2-netsec/sounds/digits/day-2.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/day-3.gsm b/1.2-netsec/sounds/digits/day-3.gsm
deleted file mode 100644
index 77012fe63..000000000
--- a/1.2-netsec/sounds/digits/day-3.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/day-4.gsm b/1.2-netsec/sounds/digits/day-4.gsm
deleted file mode 100644
index 866b5aa12..000000000
--- a/1.2-netsec/sounds/digits/day-4.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/day-5.gsm b/1.2-netsec/sounds/digits/day-5.gsm
deleted file mode 100644
index e019421dd..000000000
--- a/1.2-netsec/sounds/digits/day-5.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/day-6.gsm b/1.2-netsec/sounds/digits/day-6.gsm
deleted file mode 100644
index c1db39845..000000000
--- a/1.2-netsec/sounds/digits/day-6.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/dollars.gsm b/1.2-netsec/sounds/digits/dollars.gsm
deleted file mode 100644
index 2a0a67f5d..000000000
--- a/1.2-netsec/sounds/digits/dollars.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-1.gsm b/1.2-netsec/sounds/digits/h-1.gsm
deleted file mode 100644
index 947eaf900..000000000
--- a/1.2-netsec/sounds/digits/h-1.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-10.gsm b/1.2-netsec/sounds/digits/h-10.gsm
deleted file mode 100644
index 387db3af5..000000000
--- a/1.2-netsec/sounds/digits/h-10.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-11.gsm b/1.2-netsec/sounds/digits/h-11.gsm
deleted file mode 100644
index 5ba803fca..000000000
--- a/1.2-netsec/sounds/digits/h-11.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-12.gsm b/1.2-netsec/sounds/digits/h-12.gsm
deleted file mode 100644
index 5e53b05f0..000000000
--- a/1.2-netsec/sounds/digits/h-12.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-13.gsm b/1.2-netsec/sounds/digits/h-13.gsm
deleted file mode 100644
index e79259d82..000000000
--- a/1.2-netsec/sounds/digits/h-13.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-14.gsm b/1.2-netsec/sounds/digits/h-14.gsm
deleted file mode 100644
index e9c3ed31d..000000000
--- a/1.2-netsec/sounds/digits/h-14.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-15.gsm b/1.2-netsec/sounds/digits/h-15.gsm
deleted file mode 100644
index 658d15479..000000000
--- a/1.2-netsec/sounds/digits/h-15.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-16.gsm b/1.2-netsec/sounds/digits/h-16.gsm
deleted file mode 100644
index 4e416a7c3..000000000
--- a/1.2-netsec/sounds/digits/h-16.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-17.gsm b/1.2-netsec/sounds/digits/h-17.gsm
deleted file mode 100644
index 745d528ce..000000000
--- a/1.2-netsec/sounds/digits/h-17.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-18.gsm b/1.2-netsec/sounds/digits/h-18.gsm
deleted file mode 100644
index 80bcaed4e..000000000
--- a/1.2-netsec/sounds/digits/h-18.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-19.gsm b/1.2-netsec/sounds/digits/h-19.gsm
deleted file mode 100644
index edf6476b1..000000000
--- a/1.2-netsec/sounds/digits/h-19.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-2.gsm b/1.2-netsec/sounds/digits/h-2.gsm
deleted file mode 100644
index d521e6c82..000000000
--- a/1.2-netsec/sounds/digits/h-2.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-20.gsm b/1.2-netsec/sounds/digits/h-20.gsm
deleted file mode 100644
index b591539c5..000000000
--- a/1.2-netsec/sounds/digits/h-20.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-3.gsm b/1.2-netsec/sounds/digits/h-3.gsm
deleted file mode 100644
index 5688d0652..000000000
--- a/1.2-netsec/sounds/digits/h-3.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-30.gsm b/1.2-netsec/sounds/digits/h-30.gsm
deleted file mode 100644
index f78bfa1f7..000000000
--- a/1.2-netsec/sounds/digits/h-30.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-4.gsm b/1.2-netsec/sounds/digits/h-4.gsm
deleted file mode 100644
index af35ff043..000000000
--- a/1.2-netsec/sounds/digits/h-4.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-5.gsm b/1.2-netsec/sounds/digits/h-5.gsm
deleted file mode 100644
index 546bd0d96..000000000
--- a/1.2-netsec/sounds/digits/h-5.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-6.gsm b/1.2-netsec/sounds/digits/h-6.gsm
deleted file mode 100644
index 1796cdf3c..000000000
--- a/1.2-netsec/sounds/digits/h-6.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-7.gsm b/1.2-netsec/sounds/digits/h-7.gsm
deleted file mode 100644
index 20618b476..000000000
--- a/1.2-netsec/sounds/digits/h-7.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-8.gsm b/1.2-netsec/sounds/digits/h-8.gsm
deleted file mode 100644
index 75deb4869..000000000
--- a/1.2-netsec/sounds/digits/h-8.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/h-9.gsm b/1.2-netsec/sounds/digits/h-9.gsm
deleted file mode 100644
index 3731f997f..000000000
--- a/1.2-netsec/sounds/digits/h-9.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/hundred.gsm b/1.2-netsec/sounds/digits/hundred.gsm
deleted file mode 100644
index beb7ddfe1..000000000
--- a/1.2-netsec/sounds/digits/hundred.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/million.gsm b/1.2-netsec/sounds/digits/million.gsm
deleted file mode 100644
index bab5dd536..000000000
--- a/1.2-netsec/sounds/digits/million.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/minus.gsm b/1.2-netsec/sounds/digits/minus.gsm
deleted file mode 100644
index c413e1a1f..000000000
--- a/1.2-netsec/sounds/digits/minus.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-0.gsm b/1.2-netsec/sounds/digits/mon-0.gsm
deleted file mode 100644
index 92302f4ea..000000000
--- a/1.2-netsec/sounds/digits/mon-0.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-1.gsm b/1.2-netsec/sounds/digits/mon-1.gsm
deleted file mode 100644
index d142fb4f9..000000000
--- a/1.2-netsec/sounds/digits/mon-1.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-10.gsm b/1.2-netsec/sounds/digits/mon-10.gsm
deleted file mode 100644
index 063cf4f06..000000000
--- a/1.2-netsec/sounds/digits/mon-10.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-11.gsm b/1.2-netsec/sounds/digits/mon-11.gsm
deleted file mode 100644
index ff89587ac..000000000
--- a/1.2-netsec/sounds/digits/mon-11.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-2.gsm b/1.2-netsec/sounds/digits/mon-2.gsm
deleted file mode 100644
index ce6d96b66..000000000
--- a/1.2-netsec/sounds/digits/mon-2.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-3.gsm b/1.2-netsec/sounds/digits/mon-3.gsm
deleted file mode 100644
index a93e653f8..000000000
--- a/1.2-netsec/sounds/digits/mon-3.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-4.gsm b/1.2-netsec/sounds/digits/mon-4.gsm
deleted file mode 100644
index ca3d1f853..000000000
--- a/1.2-netsec/sounds/digits/mon-4.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-5.gsm b/1.2-netsec/sounds/digits/mon-5.gsm
deleted file mode 100644
index 84a2c98a3..000000000
--- a/1.2-netsec/sounds/digits/mon-5.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-6.gsm b/1.2-netsec/sounds/digits/mon-6.gsm
deleted file mode 100644
index 608c722a0..000000000
--- a/1.2-netsec/sounds/digits/mon-6.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-7.gsm b/1.2-netsec/sounds/digits/mon-7.gsm
deleted file mode 100644
index eb94a2814..000000000
--- a/1.2-netsec/sounds/digits/mon-7.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-8.gsm b/1.2-netsec/sounds/digits/mon-8.gsm
deleted file mode 100644
index fda37b7b0..000000000
--- a/1.2-netsec/sounds/digits/mon-8.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/mon-9.gsm b/1.2-netsec/sounds/digits/mon-9.gsm
deleted file mode 100644
index 234684797..000000000
--- a/1.2-netsec/sounds/digits/mon-9.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/oclock.gsm b/1.2-netsec/sounds/digits/oclock.gsm
deleted file mode 100644
index 8b3a60479..000000000
--- a/1.2-netsec/sounds/digits/oclock.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/oh.gsm b/1.2-netsec/sounds/digits/oh.gsm
deleted file mode 100644
index 126f78ed7..000000000
--- a/1.2-netsec/sounds/digits/oh.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/p-m.gsm b/1.2-netsec/sounds/digits/p-m.gsm
deleted file mode 100644
index 46517a8b9..000000000
--- a/1.2-netsec/sounds/digits/p-m.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/pound.gsm b/1.2-netsec/sounds/digits/pound.gsm
deleted file mode 100644
index a09fb0f6d..000000000
--- a/1.2-netsec/sounds/digits/pound.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/star.gsm b/1.2-netsec/sounds/digits/star.gsm
deleted file mode 100644
index fcc426212..000000000
--- a/1.2-netsec/sounds/digits/star.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/thousand.gsm b/1.2-netsec/sounds/digits/thousand.gsm
deleted file mode 100644
index bf4d3554e..000000000
--- a/1.2-netsec/sounds/digits/thousand.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/today.gsm b/1.2-netsec/sounds/digits/today.gsm
deleted file mode 100644
index 37bf88b67..000000000
--- a/1.2-netsec/sounds/digits/today.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/tomorrow.gsm b/1.2-netsec/sounds/digits/tomorrow.gsm
deleted file mode 100644
index 847f8e2e1..000000000
--- a/1.2-netsec/sounds/digits/tomorrow.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/digits/yesterday.gsm b/1.2-netsec/sounds/digits/yesterday.gsm
deleted file mode 100644
index 0f3795ab9..000000000
--- a/1.2-netsec/sounds/digits/yesterday.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dir-instr.gsm b/1.2-netsec/sounds/dir-instr.gsm
deleted file mode 100644
index 7865939c9..000000000
--- a/1.2-netsec/sounds/dir-instr.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dir-intro-fn.gsm b/1.2-netsec/sounds/dir-intro-fn.gsm
deleted file mode 100644
index c399ee5ff..000000000
--- a/1.2-netsec/sounds/dir-intro-fn.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dir-intro.gsm b/1.2-netsec/sounds/dir-intro.gsm
deleted file mode 100644
index 75152d6a0..000000000
--- a/1.2-netsec/sounds/dir-intro.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dir-nomatch.gsm b/1.2-netsec/sounds/dir-nomatch.gsm
deleted file mode 100644
index 21a8935a7..000000000
--- a/1.2-netsec/sounds/dir-nomatch.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/dir-nomore.gsm b/1.2-netsec/sounds/dir-nomore.gsm
deleted file mode 100644
index c2a133132..000000000
--- a/1.2-netsec/sounds/dir-nomore.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/fpm-calm-river.mp3 b/1.2-netsec/sounds/fpm-calm-river.mp3
deleted file mode 100644
index 8d93b2900..000000000
--- a/1.2-netsec/sounds/fpm-calm-river.mp3
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/fpm-sunshine.mp3 b/1.2-netsec/sounds/fpm-sunshine.mp3
deleted file mode 100644
index 106953307..000000000
--- a/1.2-netsec/sounds/fpm-sunshine.mp3
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/fpm-world-mix.mp3 b/1.2-netsec/sounds/fpm-world-mix.mp3
deleted file mode 100644
index 7d1e76d9f..000000000
--- a/1.2-netsec/sounds/fpm-world-mix.mp3
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/hello-world.gsm b/1.2-netsec/sounds/hello-world.gsm
deleted file mode 100644
index b437ad872..000000000
--- a/1.2-netsec/sounds/hello-world.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/hours.gsm b/1.2-netsec/sounds/hours.gsm
deleted file mode 100644
index b6d3c293d..000000000
--- a/1.2-netsec/sounds/hours.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/invalid.gsm b/1.2-netsec/sounds/invalid.gsm
deleted file mode 100644
index 2d0e0c879..000000000
--- a/1.2-netsec/sounds/invalid.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/a.gsm b/1.2-netsec/sounds/letters/a.gsm
deleted file mode 100644
index 88171a2d8..000000000
--- a/1.2-netsec/sounds/letters/a.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/at.gsm b/1.2-netsec/sounds/letters/at.gsm
deleted file mode 100644
index 76227229b..000000000
--- a/1.2-netsec/sounds/letters/at.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/b.gsm b/1.2-netsec/sounds/letters/b.gsm
deleted file mode 100644
index d97f14fd7..000000000
--- a/1.2-netsec/sounds/letters/b.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/c.gsm b/1.2-netsec/sounds/letters/c.gsm
deleted file mode 100644
index e631c3e8c..000000000
--- a/1.2-netsec/sounds/letters/c.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/d.gsm b/1.2-netsec/sounds/letters/d.gsm
deleted file mode 100644
index 9d26a00ee..000000000
--- a/1.2-netsec/sounds/letters/d.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/dash.gsm b/1.2-netsec/sounds/letters/dash.gsm
deleted file mode 100644
index b3649e38d..000000000
--- a/1.2-netsec/sounds/letters/dash.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/dollar.gsm b/1.2-netsec/sounds/letters/dollar.gsm
deleted file mode 100644
index 1d515d166..000000000
--- a/1.2-netsec/sounds/letters/dollar.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/dot.gsm b/1.2-netsec/sounds/letters/dot.gsm
deleted file mode 100644
index 0fca6d9cb..000000000
--- a/1.2-netsec/sounds/letters/dot.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/e.gsm b/1.2-netsec/sounds/letters/e.gsm
deleted file mode 100644
index bedfb456e..000000000
--- a/1.2-netsec/sounds/letters/e.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/equals.gsm b/1.2-netsec/sounds/letters/equals.gsm
deleted file mode 100644
index 4822469ce..000000000
--- a/1.2-netsec/sounds/letters/equals.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/exclaimation-point.gsm b/1.2-netsec/sounds/letters/exclaimation-point.gsm
deleted file mode 100644
index 87e49f2ed..000000000
--- a/1.2-netsec/sounds/letters/exclaimation-point.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/f.gsm b/1.2-netsec/sounds/letters/f.gsm
deleted file mode 100644
index 27fba4507..000000000
--- a/1.2-netsec/sounds/letters/f.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/g.gsm b/1.2-netsec/sounds/letters/g.gsm
deleted file mode 100644
index 42b9e60b9..000000000
--- a/1.2-netsec/sounds/letters/g.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/h.gsm b/1.2-netsec/sounds/letters/h.gsm
deleted file mode 100644
index c64b2f9c9..000000000
--- a/1.2-netsec/sounds/letters/h.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/i.gsm b/1.2-netsec/sounds/letters/i.gsm
deleted file mode 100644
index 7f80d8ca7..000000000
--- a/1.2-netsec/sounds/letters/i.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/j.gsm b/1.2-netsec/sounds/letters/j.gsm
deleted file mode 100644
index 45057ea96..000000000
--- a/1.2-netsec/sounds/letters/j.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/k.gsm b/1.2-netsec/sounds/letters/k.gsm
deleted file mode 100644
index 104dae10e..000000000
--- a/1.2-netsec/sounds/letters/k.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/l.gsm b/1.2-netsec/sounds/letters/l.gsm
deleted file mode 100644
index df4957f16..000000000
--- a/1.2-netsec/sounds/letters/l.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/m.gsm b/1.2-netsec/sounds/letters/m.gsm
deleted file mode 100644
index 97643d131..000000000
--- a/1.2-netsec/sounds/letters/m.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/n.gsm b/1.2-netsec/sounds/letters/n.gsm
deleted file mode 100644
index 92d853406..000000000
--- a/1.2-netsec/sounds/letters/n.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/o.gsm b/1.2-netsec/sounds/letters/o.gsm
deleted file mode 100644
index 4d1235051..000000000
--- a/1.2-netsec/sounds/letters/o.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/p.gsm b/1.2-netsec/sounds/letters/p.gsm
deleted file mode 100644
index d0851e768..000000000
--- a/1.2-netsec/sounds/letters/p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/plus.gsm b/1.2-netsec/sounds/letters/plus.gsm
deleted file mode 100644
index f4d72d637..000000000
--- a/1.2-netsec/sounds/letters/plus.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/q.gsm b/1.2-netsec/sounds/letters/q.gsm
deleted file mode 100644
index a86ed189c..000000000
--- a/1.2-netsec/sounds/letters/q.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/r.gsm b/1.2-netsec/sounds/letters/r.gsm
deleted file mode 100644
index 6ac4db989..000000000
--- a/1.2-netsec/sounds/letters/r.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/s.gsm b/1.2-netsec/sounds/letters/s.gsm
deleted file mode 100644
index 6f9cdc367..000000000
--- a/1.2-netsec/sounds/letters/s.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/slash.gsm b/1.2-netsec/sounds/letters/slash.gsm
deleted file mode 100644
index 51138a4a6..000000000
--- a/1.2-netsec/sounds/letters/slash.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/space.gsm b/1.2-netsec/sounds/letters/space.gsm
deleted file mode 100644
index 46b281d91..000000000
--- a/1.2-netsec/sounds/letters/space.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/t.gsm b/1.2-netsec/sounds/letters/t.gsm
deleted file mode 100644
index 3f8904d28..000000000
--- a/1.2-netsec/sounds/letters/t.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/u.gsm b/1.2-netsec/sounds/letters/u.gsm
deleted file mode 100644
index 9fdc9a851..000000000
--- a/1.2-netsec/sounds/letters/u.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/v.gsm b/1.2-netsec/sounds/letters/v.gsm
deleted file mode 100644
index e7ded5bd0..000000000
--- a/1.2-netsec/sounds/letters/v.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/w.gsm b/1.2-netsec/sounds/letters/w.gsm
deleted file mode 100644
index 6b0df9169..000000000
--- a/1.2-netsec/sounds/letters/w.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/x.gsm b/1.2-netsec/sounds/letters/x.gsm
deleted file mode 100644
index 70c47e521..000000000
--- a/1.2-netsec/sounds/letters/x.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/y.gsm b/1.2-netsec/sounds/letters/y.gsm
deleted file mode 100644
index 19ffa007e..000000000
--- a/1.2-netsec/sounds/letters/y.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/z.gsm b/1.2-netsec/sounds/letters/z.gsm
deleted file mode 100644
index 919382337..000000000
--- a/1.2-netsec/sounds/letters/z.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/letters/zed.gsm b/1.2-netsec/sounds/letters/zed.gsm
deleted file mode 100644
index 39782f734..000000000
--- a/1.2-netsec/sounds/letters/zed.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/minutes.gsm b/1.2-netsec/sounds/minutes.gsm
deleted file mode 100644
index 8e5f59147..000000000
--- a/1.2-netsec/sounds/minutes.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/pbx-invalid.gsm b/1.2-netsec/sounds/pbx-invalid.gsm
deleted file mode 100644
index ee3ff3f7f..000000000
--- a/1.2-netsec/sounds/pbx-invalid.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/pbx-invalidpark.gsm b/1.2-netsec/sounds/pbx-invalidpark.gsm
deleted file mode 100644
index 1f498a7c6..000000000
--- a/1.2-netsec/sounds/pbx-invalidpark.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/pbx-transfer.gsm b/1.2-netsec/sounds/pbx-transfer.gsm
deleted file mode 100644
index 3693146f7..000000000
--- a/1.2-netsec/sounds/pbx-transfer.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/9_p.gsm b/1.2-netsec/sounds/phonetic/9_p.gsm
deleted file mode 100644
index d42bec688..000000000
--- a/1.2-netsec/sounds/phonetic/9_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/a_p.gsm b/1.2-netsec/sounds/phonetic/a_p.gsm
deleted file mode 100644
index fa6edfe8f..000000000
--- a/1.2-netsec/sounds/phonetic/a_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/b_p.gsm b/1.2-netsec/sounds/phonetic/b_p.gsm
deleted file mode 100644
index 187f0dd1b..000000000
--- a/1.2-netsec/sounds/phonetic/b_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/c_p.gsm b/1.2-netsec/sounds/phonetic/c_p.gsm
deleted file mode 100644
index 2c168ec55..000000000
--- a/1.2-netsec/sounds/phonetic/c_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/d_p.gsm b/1.2-netsec/sounds/phonetic/d_p.gsm
deleted file mode 100644
index 5550bfc1b..000000000
--- a/1.2-netsec/sounds/phonetic/d_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/e_p.gsm b/1.2-netsec/sounds/phonetic/e_p.gsm
deleted file mode 100644
index 46ae8b6f5..000000000
--- a/1.2-netsec/sounds/phonetic/e_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/f_p.gsm b/1.2-netsec/sounds/phonetic/f_p.gsm
deleted file mode 100644
index 6b4f30dca..000000000
--- a/1.2-netsec/sounds/phonetic/f_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/g_p.gsm b/1.2-netsec/sounds/phonetic/g_p.gsm
deleted file mode 100644
index 38aae4fdb..000000000
--- a/1.2-netsec/sounds/phonetic/g_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/h_p.gsm b/1.2-netsec/sounds/phonetic/h_p.gsm
deleted file mode 100644
index fea0828b4..000000000
--- a/1.2-netsec/sounds/phonetic/h_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/i_p.gsm b/1.2-netsec/sounds/phonetic/i_p.gsm
deleted file mode 100644
index 24abc33f9..000000000
--- a/1.2-netsec/sounds/phonetic/i_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/j_p.gsm b/1.2-netsec/sounds/phonetic/j_p.gsm
deleted file mode 100644
index 32c1311ee..000000000
--- a/1.2-netsec/sounds/phonetic/j_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/k_p.gsm b/1.2-netsec/sounds/phonetic/k_p.gsm
deleted file mode 100644
index c26d96685..000000000
--- a/1.2-netsec/sounds/phonetic/k_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/l_p.gsm b/1.2-netsec/sounds/phonetic/l_p.gsm
deleted file mode 100644
index 0775e96e3..000000000
--- a/1.2-netsec/sounds/phonetic/l_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/m_p.gsm b/1.2-netsec/sounds/phonetic/m_p.gsm
deleted file mode 100644
index 7d3c66f03..000000000
--- a/1.2-netsec/sounds/phonetic/m_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/n_p.gsm b/1.2-netsec/sounds/phonetic/n_p.gsm
deleted file mode 100644
index f399f3702..000000000
--- a/1.2-netsec/sounds/phonetic/n_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/o_p.gsm b/1.2-netsec/sounds/phonetic/o_p.gsm
deleted file mode 100644
index d9de39c73..000000000
--- a/1.2-netsec/sounds/phonetic/o_p.gsm
+++ /dev/null
@@ -1,2 +0,0 @@
-Ô÷ƒs’P VìµéeUñÉ$dyeVѹ[#[#P²JäBÉ#Ôx\zIâ®ØãØܘÌFÐËVëäŠTçÖóç 6rÕÛÔ·j©ÐçI"³v.Õ›*¤{u¬£›ÆL3:I“j1]–ÙÔ7Z¥IŸ¦dÛkˆÓQF‡¤¶ºÕñEÖz—ñ:ï»#Ô¶<,ƒ¡§H1Š˜êQ=ÎÜ¡#!]iñ²Ý^[TÓóCá
-ñC€ìò¼¡£fÏ‘ÇQD‚ùîZ£¡À-=ÊÛÓ±KeCñd‚±îY#£D”¹ÒL«QæÊ3YISD0;¾K%Ó­RiÂSe¦5’¬ÚSÂ2„«²pSd˜ÓÙ\¥f¶Ð¹æäÓ*j^™U(8¢]JÞSFÇ©[¦ÅÔ¨ ó¬Væt›&OÓæjÖ™¨ÇKŒ¥ÜXÅÕ±QW^äNufF)ºÃ»Öµdâ×ç‹I ½öÚ»'S馄V‡.Dë¬Âqy©S0Øê¥ ÛÖB‰Sáœâ"sµ¾ÐàÂèãî÷»n³zîÙ¯¤ÕJªâ(M“N³Z´i>*‘dƒÂIŠS`qD Ø1é]ØîÅ™‹h㎣V[}®Æ/͹q&_iG24bÆ×qJ¼×²Í’a‹e6"Âã>1’¤“°A£ 2š˜A¹6²ÝþÖëa…ÚÜo·ºÙ,ì@|=.“lÚ@²êm²âä@HéfBÛÕ¢QÐÙ¸ J܉ÀbÆàZãQÉ%„ I3–<å¸@7cn&ÜسÖÕÛåÈãm·qèÆ’}4¥h†IrÆ#¸$𤌢š×©b†îE'ÍæBµ£r.d¯Âçy£kzÄ´·þËÔ ]—ÒYj"Ö)$PÈ6×2·»¨§ÆÛHŸ[E! hþsÔ¢UY·Ixc-Ÿd]¥dmB×]'¸ßqTŠ¹.’9+ÔäEa¿(¥8uêžcHFLÐôùÇ& …)¹Ôƨ¹[éÂœÔçE È‡õb•NÓgz­º£ÎǦ™oÉmh)"¶úÕ(Ké©kdFµSÄàkÅ„lÒG"o'¸âMf»mÄúo2òÕª:eêl£½ âþLmG5×2I›ÛDpcs\¥ÚĮ۩4PÔç4¥aÜÆxëqÇ"Ý#Åhr¸œàƒÙcm*5bÂÈnSåÖ,àèåD¼±¹+yCXÒJÖwB6©vÒxå3z±HäÖk:¥àvÃØ’M íñc©TÒQñ$D:ñ®­vä ¤Î¯Ö«B!©šÂªÛ¾ñCk”óz‚È(4´ƒb­w¢‹×2NÚðÄ&¼’-xáÖ؈Yð k¯Çð¢6œ£·×q3M©€ÂFÓ‰Dü~Á¥“T›|¡%º«ðá7Ùm4ž×´KiîÀ©'^£ÈØ5%rWœnÁ(ÂQ:¤Ø ZÔ¸BR×µsPêÎ@ÊÞrÉ#ð`ePl· Ð@$ã+ v@'¢¶Û \ No newline at end of file
diff --git a/1.2-netsec/sounds/phonetic/p_p.gsm b/1.2-netsec/sounds/phonetic/p_p.gsm
deleted file mode 100644
index bb5ce8631..000000000
--- a/1.2-netsec/sounds/phonetic/p_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/q_p.gsm b/1.2-netsec/sounds/phonetic/q_p.gsm
deleted file mode 100644
index 8dfdb5e05..000000000
--- a/1.2-netsec/sounds/phonetic/q_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/r_p.gsm b/1.2-netsec/sounds/phonetic/r_p.gsm
deleted file mode 100644
index 47d554651..000000000
--- a/1.2-netsec/sounds/phonetic/r_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/s_p.gsm b/1.2-netsec/sounds/phonetic/s_p.gsm
deleted file mode 100644
index 8a85860a5..000000000
--- a/1.2-netsec/sounds/phonetic/s_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/t_p.gsm b/1.2-netsec/sounds/phonetic/t_p.gsm
deleted file mode 100644
index 3701e08c6..000000000
--- a/1.2-netsec/sounds/phonetic/t_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/u_p.gsm b/1.2-netsec/sounds/phonetic/u_p.gsm
deleted file mode 100644
index 39b388834..000000000
--- a/1.2-netsec/sounds/phonetic/u_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/v_p.gsm b/1.2-netsec/sounds/phonetic/v_p.gsm
deleted file mode 100644
index ad9073501..000000000
--- a/1.2-netsec/sounds/phonetic/v_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/w_p.gsm b/1.2-netsec/sounds/phonetic/w_p.gsm
deleted file mode 100644
index 9d2199c10..000000000
--- a/1.2-netsec/sounds/phonetic/w_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/x_p.gsm b/1.2-netsec/sounds/phonetic/x_p.gsm
deleted file mode 100644
index 86269a9be..000000000
--- a/1.2-netsec/sounds/phonetic/x_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/y_p.gsm b/1.2-netsec/sounds/phonetic/y_p.gsm
deleted file mode 100644
index ce70b0609..000000000
--- a/1.2-netsec/sounds/phonetic/y_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/phonetic/z_p.gsm b/1.2-netsec/sounds/phonetic/z_p.gsm
deleted file mode 100644
index e7165c1e9..000000000
--- a/1.2-netsec/sounds/phonetic/z_p.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/priv-callee-options.gsm b/1.2-netsec/sounds/priv-callee-options.gsm
deleted file mode 100644
index 8f6d8d9a7..000000000
--- a/1.2-netsec/sounds/priv-callee-options.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/priv-callpending.gsm b/1.2-netsec/sounds/priv-callpending.gsm
deleted file mode 100644
index bf44fa6fc..000000000
--- a/1.2-netsec/sounds/priv-callpending.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/priv-introsaved.gsm b/1.2-netsec/sounds/priv-introsaved.gsm
deleted file mode 100644
index a86b9d140..000000000
--- a/1.2-netsec/sounds/priv-introsaved.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/priv-recordintro.gsm b/1.2-netsec/sounds/priv-recordintro.gsm
deleted file mode 100644
index a287f5488..000000000
--- a/1.2-netsec/sounds/priv-recordintro.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/privacy-incorrect.gsm b/1.2-netsec/sounds/privacy-incorrect.gsm
deleted file mode 100644
index e4cac90ff..000000000
--- a/1.2-netsec/sounds/privacy-incorrect.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/privacy-prompt.gsm b/1.2-netsec/sounds/privacy-prompt.gsm
deleted file mode 100644
index 24fdf83a1..000000000
--- a/1.2-netsec/sounds/privacy-prompt.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/privacy-thankyou.gsm b/1.2-netsec/sounds/privacy-thankyou.gsm
deleted file mode 100644
index 45e7104e2..000000000
--- a/1.2-netsec/sounds/privacy-thankyou.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/privacy-unident.gsm b/1.2-netsec/sounds/privacy-unident.gsm
deleted file mode 100644
index 33d838459..000000000
--- a/1.2-netsec/sounds/privacy-unident.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-callswaiting.gsm b/1.2-netsec/sounds/queue-callswaiting.gsm
deleted file mode 100644
index 60596fd8b..000000000
--- a/1.2-netsec/sounds/queue-callswaiting.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-holdtime.gsm b/1.2-netsec/sounds/queue-holdtime.gsm
deleted file mode 100644
index fd3e03cc6..000000000
--- a/1.2-netsec/sounds/queue-holdtime.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-less-than.gsm b/1.2-netsec/sounds/queue-less-than.gsm
deleted file mode 100644
index 38875ed66..000000000
--- a/1.2-netsec/sounds/queue-less-than.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-minutes.gsm b/1.2-netsec/sounds/queue-minutes.gsm
deleted file mode 100644
index e7053f7de..000000000
--- a/1.2-netsec/sounds/queue-minutes.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-periodic-announce.gsm b/1.2-netsec/sounds/queue-periodic-announce.gsm
deleted file mode 100644
index b06bedcb9..000000000
--- a/1.2-netsec/sounds/queue-periodic-announce.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-reporthold.gsm b/1.2-netsec/sounds/queue-reporthold.gsm
deleted file mode 100644
index 8b0254ba0..000000000
--- a/1.2-netsec/sounds/queue-reporthold.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-seconds.gsm b/1.2-netsec/sounds/queue-seconds.gsm
deleted file mode 100644
index a2d55d5bc..000000000
--- a/1.2-netsec/sounds/queue-seconds.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-thankyou.gsm b/1.2-netsec/sounds/queue-thankyou.gsm
deleted file mode 100644
index c611f5b78..000000000
--- a/1.2-netsec/sounds/queue-thankyou.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-thereare.gsm b/1.2-netsec/sounds/queue-thereare.gsm
deleted file mode 100644
index cb6cdd44c..000000000
--- a/1.2-netsec/sounds/queue-thereare.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/queue-youarenext.gsm b/1.2-netsec/sounds/queue-youarenext.gsm
deleted file mode 100644
index 3d543965a..000000000
--- a/1.2-netsec/sounds/queue-youarenext.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/screen-callee-options.gsm b/1.2-netsec/sounds/screen-callee-options.gsm
deleted file mode 100644
index 52b8b5768..000000000
--- a/1.2-netsec/sounds/screen-callee-options.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/seconds.gsm b/1.2-netsec/sounds/seconds.gsm
deleted file mode 100644
index a2d55d5bc..000000000
--- a/1.2-netsec/sounds/seconds.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/spy-agent.gsm b/1.2-netsec/sounds/spy-agent.gsm
deleted file mode 100644
index ab065e9c0..000000000
--- a/1.2-netsec/sounds/spy-agent.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/spy-h323.gsm b/1.2-netsec/sounds/spy-h323.gsm
deleted file mode 100644
index 6ba105472..000000000
--- a/1.2-netsec/sounds/spy-h323.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/spy-iax.gsm b/1.2-netsec/sounds/spy-iax.gsm
deleted file mode 100644
index a84220ee3..000000000
--- a/1.2-netsec/sounds/spy-iax.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/spy-iax2.gsm b/1.2-netsec/sounds/spy-iax2.gsm
deleted file mode 100644
index a84220ee3..000000000
--- a/1.2-netsec/sounds/spy-iax2.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/spy-mgcp.gsm b/1.2-netsec/sounds/spy-mgcp.gsm
deleted file mode 100644
index 7a7751258..000000000
--- a/1.2-netsec/sounds/spy-mgcp.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/spy-sip.gsm b/1.2-netsec/sounds/spy-sip.gsm
deleted file mode 100644
index 70750667d..000000000
--- a/1.2-netsec/sounds/spy-sip.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/spy-skinny.gsm b/1.2-netsec/sounds/spy-skinny.gsm
deleted file mode 100644
index 734dd043d..000000000
--- a/1.2-netsec/sounds/spy-skinny.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/spy-zap.gsm b/1.2-netsec/sounds/spy-zap.gsm
deleted file mode 100644
index 22d95ed63..000000000
--- a/1.2-netsec/sounds/spy-zap.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/ss-noservice.gsm b/1.2-netsec/sounds/ss-noservice.gsm
deleted file mode 100644
index 2d4f7e410..000000000
--- a/1.2-netsec/sounds/ss-noservice.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/transfer.gsm b/1.2-netsec/sounds/transfer.gsm
deleted file mode 100644
index 5177bef76..000000000
--- a/1.2-netsec/sounds/transfer.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/tt-allbusy.gsm b/1.2-netsec/sounds/tt-allbusy.gsm
deleted file mode 100644
index cbc745912..000000000
--- a/1.2-netsec/sounds/tt-allbusy.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/tt-monkeys.gsm b/1.2-netsec/sounds/tt-monkeys.gsm
deleted file mode 100644
index a28d4e131..000000000
--- a/1.2-netsec/sounds/tt-monkeys.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/tt-monkeysintro.gsm b/1.2-netsec/sounds/tt-monkeysintro.gsm
deleted file mode 100644
index 46d129134..000000000
--- a/1.2-netsec/sounds/tt-monkeysintro.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/tt-somethingwrong.gsm b/1.2-netsec/sounds/tt-somethingwrong.gsm
deleted file mode 100644
index d0bfc2f25..000000000
--- a/1.2-netsec/sounds/tt-somethingwrong.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/tt-weasels.gsm b/1.2-netsec/sounds/tt-weasels.gsm
deleted file mode 100644
index e43ecd26c..000000000
--- a/1.2-netsec/sounds/tt-weasels.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-Cust1.gsm b/1.2-netsec/sounds/vm-Cust1.gsm
deleted file mode 100644
index 2b8305538..000000000
--- a/1.2-netsec/sounds/vm-Cust1.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-Cust2.gsm b/1.2-netsec/sounds/vm-Cust2.gsm
deleted file mode 100644
index a65aa34a8..000000000
--- a/1.2-netsec/sounds/vm-Cust2.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-Cust3.gsm b/1.2-netsec/sounds/vm-Cust3.gsm
deleted file mode 100644
index 3ca4d20a5..000000000
--- a/1.2-netsec/sounds/vm-Cust3.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-Cust4.gsm b/1.2-netsec/sounds/vm-Cust4.gsm
deleted file mode 100644
index 9dc618044..000000000
--- a/1.2-netsec/sounds/vm-Cust4.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-Cust5.gsm b/1.2-netsec/sounds/vm-Cust5.gsm
deleted file mode 100644
index 10f2f3431..000000000
--- a/1.2-netsec/sounds/vm-Cust5.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-Family.gsm b/1.2-netsec/sounds/vm-Family.gsm
deleted file mode 100644
index 6e28ee98b..000000000
--- a/1.2-netsec/sounds/vm-Family.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-Friends.gsm b/1.2-netsec/sounds/vm-Friends.gsm
deleted file mode 100644
index 9f3c540bc..000000000
--- a/1.2-netsec/sounds/vm-Friends.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-INBOX.gsm b/1.2-netsec/sounds/vm-INBOX.gsm
deleted file mode 100644
index baeeb88ab..000000000
--- a/1.2-netsec/sounds/vm-INBOX.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-Old.gsm b/1.2-netsec/sounds/vm-Old.gsm
deleted file mode 100644
index e5eeb3586..000000000
--- a/1.2-netsec/sounds/vm-Old.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-Work.gsm b/1.2-netsec/sounds/vm-Work.gsm
deleted file mode 100644
index 0edb4242a..000000000
--- a/1.2-netsec/sounds/vm-Work.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-advopts.gsm b/1.2-netsec/sounds/vm-advopts.gsm
deleted file mode 100644
index 8211503d7..000000000
--- a/1.2-netsec/sounds/vm-advopts.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-and.gsm b/1.2-netsec/sounds/vm-and.gsm
deleted file mode 100644
index cf3b8f4ae..000000000
--- a/1.2-netsec/sounds/vm-and.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-calldiffnum.gsm b/1.2-netsec/sounds/vm-calldiffnum.gsm
deleted file mode 100644
index b874d5893..000000000
--- a/1.2-netsec/sounds/vm-calldiffnum.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-changeto.gsm b/1.2-netsec/sounds/vm-changeto.gsm
deleted file mode 100644
index 5f06edf9b..000000000
--- a/1.2-netsec/sounds/vm-changeto.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-delete.gsm b/1.2-netsec/sounds/vm-delete.gsm
deleted file mode 100644
index 47235e58b..000000000
--- a/1.2-netsec/sounds/vm-delete.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-deleted.gsm b/1.2-netsec/sounds/vm-deleted.gsm
deleted file mode 100644
index aa63596ab..000000000
--- a/1.2-netsec/sounds/vm-deleted.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-dialout.gsm b/1.2-netsec/sounds/vm-dialout.gsm
deleted file mode 100644
index 406215e2f..000000000
--- a/1.2-netsec/sounds/vm-dialout.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-enter-num-to-call.gsm b/1.2-netsec/sounds/vm-enter-num-to-call.gsm
deleted file mode 100644
index 30292703f..000000000
--- a/1.2-netsec/sounds/vm-enter-num-to-call.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-extension.gsm b/1.2-netsec/sounds/vm-extension.gsm
deleted file mode 100644
index c17a45456..000000000
--- a/1.2-netsec/sounds/vm-extension.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-first.gsm b/1.2-netsec/sounds/vm-first.gsm
deleted file mode 100644
index 3990d6e63..000000000
--- a/1.2-netsec/sounds/vm-first.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-for.gsm b/1.2-netsec/sounds/vm-for.gsm
deleted file mode 100644
index 685781895..000000000
--- a/1.2-netsec/sounds/vm-for.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-forward.gsm b/1.2-netsec/sounds/vm-forward.gsm
deleted file mode 100644
index af5367eb6..000000000
--- a/1.2-netsec/sounds/vm-forward.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-forwardoptions.gsm b/1.2-netsec/sounds/vm-forwardoptions.gsm
deleted file mode 100644
index b9ccb7f98..000000000
--- a/1.2-netsec/sounds/vm-forwardoptions.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-from-extension.gsm b/1.2-netsec/sounds/vm-from-extension.gsm
deleted file mode 100644
index 6414b63a5..000000000
--- a/1.2-netsec/sounds/vm-from-extension.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-from-phonenumber.gsm b/1.2-netsec/sounds/vm-from-phonenumber.gsm
deleted file mode 100644
index 9f3b68486..000000000
--- a/1.2-netsec/sounds/vm-from-phonenumber.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-from.gsm b/1.2-netsec/sounds/vm-from.gsm
deleted file mode 100644
index 1f396327f..000000000
--- a/1.2-netsec/sounds/vm-from.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-goodbye.gsm b/1.2-netsec/sounds/vm-goodbye.gsm
deleted file mode 100644
index 33adce903..000000000
--- a/1.2-netsec/sounds/vm-goodbye.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-helpexit.gsm b/1.2-netsec/sounds/vm-helpexit.gsm
deleted file mode 100644
index 47ff02245..000000000
--- a/1.2-netsec/sounds/vm-helpexit.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-incorrect-mailbox.gsm b/1.2-netsec/sounds/vm-incorrect-mailbox.gsm
deleted file mode 100644
index 899340758..000000000
--- a/1.2-netsec/sounds/vm-incorrect-mailbox.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-incorrect.gsm b/1.2-netsec/sounds/vm-incorrect.gsm
deleted file mode 100644
index fd42267cf..000000000
--- a/1.2-netsec/sounds/vm-incorrect.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-instructions.gsm b/1.2-netsec/sounds/vm-instructions.gsm
deleted file mode 100644
index 163cfc1a5..000000000
--- a/1.2-netsec/sounds/vm-instructions.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-intro.gsm b/1.2-netsec/sounds/vm-intro.gsm
deleted file mode 100644
index 4793ee1b9..000000000
--- a/1.2-netsec/sounds/vm-intro.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-isonphone.gsm b/1.2-netsec/sounds/vm-isonphone.gsm
deleted file mode 100644
index 374f26f1c..000000000
--- a/1.2-netsec/sounds/vm-isonphone.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-isunavail.gsm b/1.2-netsec/sounds/vm-isunavail.gsm
deleted file mode 100644
index 6f6643b02..000000000
--- a/1.2-netsec/sounds/vm-isunavail.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-last.gsm b/1.2-netsec/sounds/vm-last.gsm
deleted file mode 100644
index bda297fdb..000000000
--- a/1.2-netsec/sounds/vm-last.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-leavemsg.gsm b/1.2-netsec/sounds/vm-leavemsg.gsm
deleted file mode 100644
index 864cdde17..000000000
--- a/1.2-netsec/sounds/vm-leavemsg.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-login.gsm b/1.2-netsec/sounds/vm-login.gsm
deleted file mode 100644
index 57132275d..000000000
--- a/1.2-netsec/sounds/vm-login.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-mailboxfull.gsm b/1.2-netsec/sounds/vm-mailboxfull.gsm
deleted file mode 100644
index cd897fedd..000000000
--- a/1.2-netsec/sounds/vm-mailboxfull.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-message.gsm b/1.2-netsec/sounds/vm-message.gsm
deleted file mode 100644
index 97ab57276..000000000
--- a/1.2-netsec/sounds/vm-message.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-messages.gsm b/1.2-netsec/sounds/vm-messages.gsm
deleted file mode 100644
index 3b46e6e39..000000000
--- a/1.2-netsec/sounds/vm-messages.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-minutes.gsm b/1.2-netsec/sounds/vm-minutes.gsm
deleted file mode 100644
index e7053f7de..000000000
--- a/1.2-netsec/sounds/vm-minutes.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-mismatch.gsm b/1.2-netsec/sounds/vm-mismatch.gsm
deleted file mode 100644
index 7421af0d0..000000000
--- a/1.2-netsec/sounds/vm-mismatch.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-msginstruct.gsm b/1.2-netsec/sounds/vm-msginstruct.gsm
deleted file mode 100644
index 6cef12dd3..000000000
--- a/1.2-netsec/sounds/vm-msginstruct.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-msgsaved.gsm b/1.2-netsec/sounds/vm-msgsaved.gsm
deleted file mode 100644
index cbf4e6536..000000000
--- a/1.2-netsec/sounds/vm-msgsaved.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-newpassword.gsm b/1.2-netsec/sounds/vm-newpassword.gsm
deleted file mode 100644
index 057bff51d..000000000
--- a/1.2-netsec/sounds/vm-newpassword.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-newuser.gsm b/1.2-netsec/sounds/vm-newuser.gsm
deleted file mode 100644
index 64e4a5396..000000000
--- a/1.2-netsec/sounds/vm-newuser.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-next.gsm b/1.2-netsec/sounds/vm-next.gsm
deleted file mode 100644
index ed4ce2347..000000000
--- a/1.2-netsec/sounds/vm-next.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-no.gsm b/1.2-netsec/sounds/vm-no.gsm
deleted file mode 100644
index 4c49822c3..000000000
--- a/1.2-netsec/sounds/vm-no.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-nobodyavail.gsm b/1.2-netsec/sounds/vm-nobodyavail.gsm
deleted file mode 100644
index 31f43148f..000000000
--- a/1.2-netsec/sounds/vm-nobodyavail.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-nobox.gsm b/1.2-netsec/sounds/vm-nobox.gsm
deleted file mode 100644
index e4c69372f..000000000
--- a/1.2-netsec/sounds/vm-nobox.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-nomore.gsm b/1.2-netsec/sounds/vm-nomore.gsm
deleted file mode 100644
index 40f876c49..000000000
--- a/1.2-netsec/sounds/vm-nomore.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-nonumber.gsm b/1.2-netsec/sounds/vm-nonumber.gsm
deleted file mode 100644
index 7c99e6d5c..000000000
--- a/1.2-netsec/sounds/vm-nonumber.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-num-i-have.gsm b/1.2-netsec/sounds/vm-num-i-have.gsm
deleted file mode 100644
index 9ba87bc6a..000000000
--- a/1.2-netsec/sounds/vm-num-i-have.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-onefor.gsm b/1.2-netsec/sounds/vm-onefor.gsm
deleted file mode 100644
index 12aac1734..000000000
--- a/1.2-netsec/sounds/vm-onefor.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-options.gsm b/1.2-netsec/sounds/vm-options.gsm
deleted file mode 100644
index a563527d9..000000000
--- a/1.2-netsec/sounds/vm-options.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-opts.gsm b/1.2-netsec/sounds/vm-opts.gsm
deleted file mode 100644
index ad36f3e2b..000000000
--- a/1.2-netsec/sounds/vm-opts.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-passchanged.gsm b/1.2-netsec/sounds/vm-passchanged.gsm
deleted file mode 100644
index 7bb2510a4..000000000
--- a/1.2-netsec/sounds/vm-passchanged.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-password.gsm b/1.2-netsec/sounds/vm-password.gsm
deleted file mode 100644
index f9049d2f2..000000000
--- a/1.2-netsec/sounds/vm-password.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-press.gsm b/1.2-netsec/sounds/vm-press.gsm
deleted file mode 100644
index 8a44766ad..000000000
--- a/1.2-netsec/sounds/vm-press.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-prev.gsm b/1.2-netsec/sounds/vm-prev.gsm
deleted file mode 100644
index c0251cdd2..000000000
--- a/1.2-netsec/sounds/vm-prev.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-reachoper.gsm b/1.2-netsec/sounds/vm-reachoper.gsm
deleted file mode 100644
index 208daa591..000000000
--- a/1.2-netsec/sounds/vm-reachoper.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-rec-busy.gsm b/1.2-netsec/sounds/vm-rec-busy.gsm
deleted file mode 100644
index a17593a08..000000000
--- a/1.2-netsec/sounds/vm-rec-busy.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-rec-name.gsm b/1.2-netsec/sounds/vm-rec-name.gsm
deleted file mode 100644
index f583e87b1..000000000
--- a/1.2-netsec/sounds/vm-rec-name.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-rec-temp.gsm b/1.2-netsec/sounds/vm-rec-temp.gsm
deleted file mode 100644
index 53614ab52..000000000
--- a/1.2-netsec/sounds/vm-rec-temp.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-rec-unv.gsm b/1.2-netsec/sounds/vm-rec-unv.gsm
deleted file mode 100644
index 06955f19f..000000000
--- a/1.2-netsec/sounds/vm-rec-unv.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-received.gsm b/1.2-netsec/sounds/vm-received.gsm
deleted file mode 100644
index 9439ae88a..000000000
--- a/1.2-netsec/sounds/vm-received.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-reenterpassword.gsm b/1.2-netsec/sounds/vm-reenterpassword.gsm
deleted file mode 100644
index 41344cb06..000000000
--- a/1.2-netsec/sounds/vm-reenterpassword.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-repeat.gsm b/1.2-netsec/sounds/vm-repeat.gsm
deleted file mode 100644
index 26479e0b4..000000000
--- a/1.2-netsec/sounds/vm-repeat.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-review.gsm b/1.2-netsec/sounds/vm-review.gsm
deleted file mode 100644
index e49768d62..000000000
--- a/1.2-netsec/sounds/vm-review.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-saved.gsm b/1.2-netsec/sounds/vm-saved.gsm
deleted file mode 100644
index 918f48b5a..000000000
--- a/1.2-netsec/sounds/vm-saved.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-savedto.gsm b/1.2-netsec/sounds/vm-savedto.gsm
deleted file mode 100644
index 96452a124..000000000
--- a/1.2-netsec/sounds/vm-savedto.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-savefolder.gsm b/1.2-netsec/sounds/vm-savefolder.gsm
deleted file mode 100644
index 06359d02c..000000000
--- a/1.2-netsec/sounds/vm-savefolder.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-savemessage.gsm b/1.2-netsec/sounds/vm-savemessage.gsm
deleted file mode 100644
index 6e7c41e7c..000000000
--- a/1.2-netsec/sounds/vm-savemessage.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-saveoper.gsm b/1.2-netsec/sounds/vm-saveoper.gsm
deleted file mode 100644
index 1fa92a22a..000000000
--- a/1.2-netsec/sounds/vm-saveoper.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-sorry.gsm b/1.2-netsec/sounds/vm-sorry.gsm
deleted file mode 100644
index 14363f35f..000000000
--- a/1.2-netsec/sounds/vm-sorry.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-star-cancel.gsm b/1.2-netsec/sounds/vm-star-cancel.gsm
deleted file mode 100644
index 0b7cfd603..000000000
--- a/1.2-netsec/sounds/vm-star-cancel.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-starmain.gsm b/1.2-netsec/sounds/vm-starmain.gsm
deleted file mode 100644
index 71461eade..000000000
--- a/1.2-netsec/sounds/vm-starmain.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tempgreeting.gsm b/1.2-netsec/sounds/vm-tempgreeting.gsm
deleted file mode 100644
index 16c07edf3..000000000
--- a/1.2-netsec/sounds/vm-tempgreeting.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tempgreeting2.gsm b/1.2-netsec/sounds/vm-tempgreeting2.gsm
deleted file mode 100644
index fc0438de5..000000000
--- a/1.2-netsec/sounds/vm-tempgreeting2.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tempremoved.gsm b/1.2-netsec/sounds/vm-tempremoved.gsm
deleted file mode 100644
index 897233aa7..000000000
--- a/1.2-netsec/sounds/vm-tempremoved.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-then-pound.gsm b/1.2-netsec/sounds/vm-then-pound.gsm
deleted file mode 100644
index 2261fb6b3..000000000
--- a/1.2-netsec/sounds/vm-then-pound.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-theperson.gsm b/1.2-netsec/sounds/vm-theperson.gsm
deleted file mode 100644
index 73fbb20b3..000000000
--- a/1.2-netsec/sounds/vm-theperson.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tocallback.gsm b/1.2-netsec/sounds/vm-tocallback.gsm
deleted file mode 100644
index ec5f1f813..000000000
--- a/1.2-netsec/sounds/vm-tocallback.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tocallnum.gsm b/1.2-netsec/sounds/vm-tocallnum.gsm
deleted file mode 100644
index ae07c3da1..000000000
--- a/1.2-netsec/sounds/vm-tocallnum.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tocancel.gsm b/1.2-netsec/sounds/vm-tocancel.gsm
deleted file mode 100644
index 04c34a61e..000000000
--- a/1.2-netsec/sounds/vm-tocancel.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tocancelmsg.gsm b/1.2-netsec/sounds/vm-tocancelmsg.gsm
deleted file mode 100644
index 5c7d80a5a..000000000
--- a/1.2-netsec/sounds/vm-tocancelmsg.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-toenternumber.gsm b/1.2-netsec/sounds/vm-toenternumber.gsm
deleted file mode 100644
index 44f3e5f1f..000000000
--- a/1.2-netsec/sounds/vm-toenternumber.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-toforward.gsm b/1.2-netsec/sounds/vm-toforward.gsm
deleted file mode 100644
index be9ba5510..000000000
--- a/1.2-netsec/sounds/vm-toforward.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tohearenv.gsm b/1.2-netsec/sounds/vm-tohearenv.gsm
deleted file mode 100644
index 5ddef223d..000000000
--- a/1.2-netsec/sounds/vm-tohearenv.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tomakecall.gsm b/1.2-netsec/sounds/vm-tomakecall.gsm
deleted file mode 100644
index 5449e9a7a..000000000
--- a/1.2-netsec/sounds/vm-tomakecall.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-tooshort.gsm b/1.2-netsec/sounds/vm-tooshort.gsm
deleted file mode 100644
index 4038c2bed..000000000
--- a/1.2-netsec/sounds/vm-tooshort.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-toreply.gsm b/1.2-netsec/sounds/vm-toreply.gsm
deleted file mode 100644
index e770846b6..000000000
--- a/1.2-netsec/sounds/vm-toreply.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-torerecord.gsm b/1.2-netsec/sounds/vm-torerecord.gsm
deleted file mode 100644
index e48397e44..000000000
--- a/1.2-netsec/sounds/vm-torerecord.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-undelete.gsm b/1.2-netsec/sounds/vm-undelete.gsm
deleted file mode 100644
index a591d3b74..000000000
--- a/1.2-netsec/sounds/vm-undelete.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-undeleted.gsm b/1.2-netsec/sounds/vm-undeleted.gsm
deleted file mode 100644
index 9a0d7aa64..000000000
--- a/1.2-netsec/sounds/vm-undeleted.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-unknown-caller.gsm b/1.2-netsec/sounds/vm-unknown-caller.gsm
deleted file mode 100644
index 693664d7c..000000000
--- a/1.2-netsec/sounds/vm-unknown-caller.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-whichbox.gsm b/1.2-netsec/sounds/vm-whichbox.gsm
deleted file mode 100644
index ea7ef7a46..000000000
--- a/1.2-netsec/sounds/vm-whichbox.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/sounds/vm-youhave.gsm b/1.2-netsec/sounds/vm-youhave.gsm
deleted file mode 100644
index 78e4d8d12..000000000
--- a/1.2-netsec/sounds/vm-youhave.gsm
+++ /dev/null
Binary files differ
diff --git a/1.2-netsec/srv.c b/1.2-netsec/srv.c
deleted file mode 100644
index 9e04d84e4..000000000
--- a/1.2-netsec/srv.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Funding provided by nic.at
- *
- * 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 DNS SRV Record Lookup Support for Asterisk
- *
- * \arg See also \ref AstENUM
- *
- */
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#if __APPLE_CC__ >= 1495
-#include <arpa/nameser_compat.h>
-#endif
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/srv.h"
-#include "asterisk/dns.h"
-#include "asterisk/options.h"
-#include "asterisk/utils.h"
-
-#ifdef __APPLE__
-#undef T_SRV
-#define T_SRV 33
-#endif
-
-struct srv {
- unsigned short priority;
- unsigned short weight;
- unsigned short portnum;
-} __attribute__ ((__packed__));
-
-static int parse_srv(char *host, int hostlen, int *portno, char *answer, int len, char *msg)
-{
- int res = 0;
- struct srv *srv = (struct srv *)answer;
- char repl[256] = "";
-
- if (len < sizeof(struct srv)) {
- printf("Length too short\n");
- return -1;
- }
- answer += sizeof(struct srv);
- len -= sizeof(struct srv);
-
- if ((res = dn_expand((unsigned char *)msg, (unsigned char *)answer + len, (unsigned char *)answer, repl, sizeof(repl) - 1)) < 0) {
- ast_log(LOG_WARNING, "Failed to expand hostname\n");
- return -1;
- }
- if (res && strcmp(repl, ".")) {
- if (option_verbose > 3)
- ast_verbose( VERBOSE_PREFIX_3 "parse_srv: SRV mapped to host %s, port %d\n", repl, ntohs(srv->portnum));
- if (host) {
- ast_copy_string(host, repl, hostlen);
- host[hostlen-1] = '\0';
- }
- if (portno)
- *portno = ntohs(srv->portnum);
- return 0;
- }
- return -1;
-}
-
-struct srv_context {
- char *host;
- int hostlen;
- int *port;
-};
-
-static int srv_callback(void *context, char *answer, int len, char *fullanswer)
-{
- struct srv_context *c = (struct srv_context *)context;
-
- if (parse_srv(c->host, c->hostlen, c->port, answer, len, fullanswer)) {
- ast_log(LOG_WARNING, "Failed to parse srv\n");
- return -1;
- }
-
- if (!ast_strlen_zero(c->host))
- return 1;
-
- return 0;
-}
-
-int ast_get_srv(struct ast_channel *chan, char *host, int hostlen, int *port, const char *service)
-{
- struct srv_context context;
- int ret;
-
- context.host = host;
- context.hostlen = hostlen;
- context.port = port;
-
- if (chan && ast_autoservice_start(chan) < 0)
- return -1;
-
- ret = ast_search_dns(&context, service, C_IN, T_SRV, srv_callback);
-
- if (chan)
- ret |= ast_autoservice_stop(chan);
-
- if (ret <= 0) {
- host[0] = '\0';
- *port = -1;
- return ret;
- }
- return ret;
-}
diff --git a/1.2-netsec/stdtime/Makefile b/1.2-netsec/stdtime/Makefile
deleted file mode 100644
index e97010f0f..000000000
--- a/1.2-netsec/stdtime/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
-OBJS=localtime.o
-
-all: libtime.a
-
-libtime.a: $(OBJS)
- ar rv $@ $(OBJS)
- ranlib $@
-
-install:
-
-clean:
- rm -f libtime.a *.o test .depend
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) *.c
-
-test: test.c
- ${CC} ${CFLAGS} -o test test.c
-
-ifneq ($(wildcard .depend),)
-include .depend
-endif
diff --git a/1.2-netsec/stdtime/localtime.c b/1.2-netsec/stdtime/localtime.c
deleted file mode 100644
index db125d9e6..000000000
--- a/1.2-netsec/stdtime/localtime.c
+++ /dev/null
@@ -1,1505 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Most of this code is in the public domain, so clarified as of
- * June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
- *
- * All modifications to this code to abstract timezones away from
- * the environment are by Tilghman Lesher, <tlesher@vcch.com>, with
- * the copyright assigned to Digium.
- *
- * 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
- *
- * Multi-timezone Localtime code
- *
- * \author Leap second handling Bradley White (bww@k.gp.cs.cmu.edu).
- * \author POSIX-style TZ environment variable handling from Guy Harris (guy@auspex.com).
- *
- */
-
-/*
- * Asterisk defines
- *
- * Don't mess with these unless you're really sure you know what you're doing.
- */
-#ifndef _THREAD_SAFE
-#define _THREAD_SAFE
-#endif
-#define TZ_STRLEN_MAX 255
-/* #define DEBUG */
-
-
-/*LINTLIBRARY*/
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#ifdef DEBUG
-#include <stdio.h>
-#endif
-#include "private.h"
-#include "tzfile.h"
-#include "asterisk/lock.h"
-#include "asterisk/localtime.h"
-
-
-#ifndef lint
-#ifndef NOID
-static const char elsieid[] = "@(#)localtime.c 7.57";
-#endif /* !defined NOID */
-#endif /* !defined lint */
-
-
-
-/*
-** SunOS 4.1.1 headers lack O_BINARY.
-*/
-
-#ifdef O_BINARY
-#define OPEN_MODE (O_RDONLY | O_BINARY)
-#endif /* defined O_BINARY */
-#ifndef O_BINARY
-#define OPEN_MODE O_RDONLY
-#endif /* !defined O_BINARY */
-
-#ifdef SOLARIS
-#undef TM_ZONE
-#undef TM_GMTOFF
-#endif
-
-#ifdef TM_ZONE
-#ifndef WILDABBR
-/*! \note
- * Someone might make incorrect use of a time zone abbreviation:
- * 1. They might reference tzname[0] before calling ast_tzset (explicitly
- * or implicitly).
- * 2. They might reference tzname[1] before calling ast_tzset (explicitly
- * or implicitly).
- * 3. They might reference tzname[1] after setting to a time zone
- * in which Daylight Saving Time is never observed.
- * 4. They might reference tzname[0] after setting to a time zone
- * in which Standard Time is never observed.
- * 5. They might reference tm.TM_ZONE after calling offtime.
- * What's best to do in the above cases is open to debate;
- * for now, we just set things up so that in any of the five cases
- * WILDABBR is used. Another possibility: initialize tzname[0] to the
- * string "tzname[0] used before set", and similarly for the other cases.
- * And another: initialize tzname[0] to "ERA", with an explanation in the
- * manual page of what this "time zone abbreviation" means (doing this so
- * that tzname[0] has the "normal" length of three characters).
- */
-#define WILDABBR " "
-#endif /* !defined WILDABBR */
-
-static char wildabbr[] = "WILDABBR";
-#endif /* TM_ZONE */
-
-/*! \brief FreeBSD defines 'zone' in 'struct tm' as non-const, so don't declare this
- string as const. */
-static char gmt[] = "GMT";
-
-/*!< \brief time type information */
-struct ttinfo {
- long tt_gmtoff; /*!< GMT offset in seconds */
- int tt_isdst; /*!< used to set tm_isdst */
- int tt_abbrind; /*!< abbreviation list index */
- int tt_ttisstd; /*!< TRUE if transition is std time */
- int tt_ttisgmt; /*!< TRUE if transition is GMT */
-};
-
-/*! \brief leap second information */
-struct lsinfo {
- time_t ls_trans; /*!< transition time */
- long ls_corr; /*!< correction to apply */
-};
-
-#define BIGGEST(a, b) (((a) > (b)) ? (a) : (b))
-
-#ifdef TZNAME_MAX
-#define MY_TZNAME_MAX TZNAME_MAX
-#endif /* defined TZNAME_MAX */
-#ifndef TZNAME_MAX
-#define MY_TZNAME_MAX 255
-#endif /* !defined TZNAME_MAX */
-
-struct state {
- char name[TZ_STRLEN_MAX + 1];
- int leapcnt;
- int timecnt;
- int typecnt;
- int charcnt;
- time_t ats[TZ_MAX_TIMES];
- unsigned char types[TZ_MAX_TIMES];
- struct ttinfo ttis[TZ_MAX_TYPES];
- char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt),
- (2 * (MY_TZNAME_MAX + 1)))];
- struct lsinfo lsis[TZ_MAX_LEAPS];
- struct state *next;
-};
-
-struct rule {
- int r_type; /*!< type of rule--see below */
- int r_day; /*!< day number of rule */
- int r_week; /*!< week number of rule */
- int r_mon; /*!< month number of rule */
- long r_time; /*!< transition time of rule */
-};
-
-#define JULIAN_DAY 0 /*!< Jn - Julian day */
-#define DAY_OF_YEAR 1 /*!< n - day of year */
-#define MONTH_NTH_DAY_OF_WEEK 2 /*!< Mm.n.d - month, week, day of week */
-
-/*
-** Prototypes for static functions.
-*/
-
-static long detzcode P((const char * codep));
-static const char * getnum P((const char * strp, int * nump, int min,
- int max));
-static const char * getsecs P((const char * strp, long * secsp));
-static const char * getoffset P((const char * strp, long * offsetp));
-static const char * getrule P((const char * strp, struct rule * rulep));
-static void gmtload P((struct state * sp));
-static void gmtsub P((const time_t * timep, long offset,
- struct tm * tmp, const char * zone));
-static void localsub P((const time_t * timep, long offset,
- struct tm * tmp, const char * zone));
-static int increment_overflow P((int * number, int delta));
-static int normalize_overflow P((int * tensptr, int * unitsptr,
- int base));
-static time_t time1 P((struct tm * tmp,
- void(*funcp) P((const time_t *,
- long, struct tm *, const char*)),
- long offset, const char * zone));
-static time_t time2 P((struct tm *tmp,
- void(*funcp) P((const time_t *,
- long, struct tm*, const char*)),
- long offset, int * okayp, const char * zone));
-static void timesub P((const time_t * timep, long offset,
- const struct state * sp, struct tm * tmp));
-static int tmcomp P((const struct tm * atmp,
- const struct tm * btmp));
-static time_t transtime P((time_t janfirst, int year,
- const struct rule * rulep, long offset));
-static int tzload P((const char * name, struct state * sp));
-static int tzparse P((const char * name, struct state * sp,
- int lastditch));
-
-static struct state * lclptr = NULL;
-static struct state * last_lclptr = NULL;
-static struct state * gmtptr = NULL;
-
-#ifndef TZ_STRLEN_MAX
-#define TZ_STRLEN_MAX 255
-#endif /* !defined TZ_STRLEN_MAX */
-
-static int gmt_is_set;
-#ifdef _THREAD_SAFE
-AST_MUTEX_DEFINE_STATIC(lcl_mutex);
-AST_MUTEX_DEFINE_STATIC(tzset_mutex);
-AST_MUTEX_DEFINE_STATIC(tzsetwall_mutex);
-AST_MUTEX_DEFINE_STATIC(gmt_mutex);
-#endif
-
-/*
-** Section 4.12.3 of X3.159-1989 requires that
-** Except for the strftime function, these functions [asctime,
-** ctime, gmtime, localtime] return values in one of two static
-** objects: a broken-down time structure and an array of char.
-** Thanks to Paul Eggert (eggert@twinsun.com) for noting this.
-*/
-
-static long detzcode(const char * const codep)
-{
- register long result;
- register int i;
-
- result = (codep[0] & 0x80) ? ~0L : 0L;
- for (i = 0; i < 4; ++i)
- result = (result << 8) | (codep[i] & 0xff);
- return result;
-}
-
-static int tzload(register const char *name, register struct state *const sp)
-{
- register const char * p;
- register int i;
- register int fid;
-
-#ifdef DEBUG
- fprintf(stderr,"tzload called with name=%s, sp=%d\n", name, sp);
-#endif
- if (name == NULL && (name = TZDEFAULT) == NULL)
- return -1;
- {
- register int doaccess;
- struct stat stab;
- /*
- ** Section 4.9.1 of the C standard says that
- ** "FILENAME_MAX expands to an integral constant expression
- ** that is the size needed for an array of char large enough
- ** to hold the longest file name string that the implementation
- ** guarantees can be opened."
- */
- char fullname[FILENAME_MAX + 1] = "";
-
- if (name[0] == ':')
- ++name;
- doaccess = name[0] == '/';
- if (!doaccess) {
- if ((p = TZDIR) == NULL)
- return -1;
- if ((strlen(p) + 1 + strlen(name) + 1) >= sizeof fullname)
- return -1;
- (void) strncpy(fullname, p, sizeof(fullname) - 1);
- (void) strncat(fullname, "/", sizeof(fullname) - strlen(fullname) - 1);
- (void) strncat(fullname, name, sizeof(fullname) - strlen(fullname) - 1);
- /*
- ** Set doaccess if '.' (as in "../") shows up in name.
- */
- if (strchr(name, '.') != NULL)
- doaccess = TRUE;
- name = fullname;
- }
- if (doaccess && access(name, R_OK) != 0)
- return -1;
- if ((fid = open(name, OPEN_MODE)) == -1)
- return -1;
- if ((fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode)) {
- close(fid);
- return -1;
- }
- }
- {
- struct tzhead * tzhp;
- char buf[sizeof *sp + sizeof *tzhp];
- int ttisstdcnt;
- int ttisgmtcnt;
-
- i = read(fid, buf, sizeof buf);
- if (close(fid) != 0)
- return -1;
- p = buf;
- p += (sizeof tzhp->tzh_magic) + (sizeof tzhp->tzh_reserved);
- ttisstdcnt = (int) detzcode(p);
- p += 4;
- ttisgmtcnt = (int) detzcode(p);
- p += 4;
- sp->leapcnt = (int) detzcode(p);
- p += 4;
- sp->timecnt = (int) detzcode(p);
- p += 4;
- sp->typecnt = (int) detzcode(p);
- p += 4;
- sp->charcnt = (int) detzcode(p);
- p += 4;
- if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS ||
- sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES ||
- sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES ||
- sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS ||
- (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) ||
- (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
- return -1;
- if (i - (p - buf) < sp->timecnt * 4 + /* ats */
- sp->timecnt + /* types */
- sp->typecnt * (4 + 2) + /* ttinfos */
- sp->charcnt + /* chars */
- sp->leapcnt * (4 + 4) + /* lsinfos */
- ttisstdcnt + /* ttisstds */
- ttisgmtcnt) /* ttisgmts */
- return -1;
- for (i = 0; i < sp->timecnt; ++i) {
- sp->ats[i] = detzcode(p);
- p += 4;
- }
- for (i = 0; i < sp->timecnt; ++i) {
- sp->types[i] = (unsigned char) *p++;
- if (sp->types[i] >= sp->typecnt)
- return -1;
- }
- for (i = 0; i < sp->typecnt; ++i) {
- register struct ttinfo * ttisp;
-
- ttisp = &sp->ttis[i];
- ttisp->tt_gmtoff = detzcode(p);
- p += 4;
- ttisp->tt_isdst = (unsigned char) *p++;
- if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)
- return -1;
- ttisp->tt_abbrind = (unsigned char) *p++;
- if (ttisp->tt_abbrind < 0 ||
- ttisp->tt_abbrind > sp->charcnt)
- return -1;
- }
- for (i = 0; i < sp->charcnt; ++i)
- sp->chars[i] = *p++;
- sp->chars[i] = '\0'; /* ensure '\0' at end */
- for (i = 0; i < sp->leapcnt; ++i) {
- register struct lsinfo * lsisp;
-
- lsisp = &sp->lsis[i];
- lsisp->ls_trans = detzcode(p);
- p += 4;
- lsisp->ls_corr = detzcode(p);
- p += 4;
- }
- for (i = 0; i < sp->typecnt; ++i) {
- register struct ttinfo * ttisp;
-
- ttisp = &sp->ttis[i];
- if (ttisstdcnt == 0)
- ttisp->tt_ttisstd = FALSE;
- else {
- ttisp->tt_ttisstd = *p++;
- if (ttisp->tt_ttisstd != TRUE &&
- ttisp->tt_ttisstd != FALSE)
- return -1;
- }
- }
- for (i = 0; i < sp->typecnt; ++i) {
- register struct ttinfo * ttisp;
-
- ttisp = &sp->ttis[i];
- if (ttisgmtcnt == 0)
- ttisp->tt_ttisgmt = FALSE;
- else {
- ttisp->tt_ttisgmt = *p++;
- if (ttisp->tt_ttisgmt != TRUE &&
- ttisp->tt_ttisgmt != FALSE)
- return -1;
- }
- }
- }
- return 0;
-}
-
-static const int mon_lengths[2][MONSPERYEAR] = {
- { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
- { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
-};
-
-static const int year_lengths[2] = {
- DAYSPERNYEAR, DAYSPERLYEAR
-};
-
-/*! \brief
- * Given a pointer into a time zone string, extract a number from that string.
- * \return Check that the number is within a specified range; if it is not, return
- * NULL.
- * Otherwise, return a pointer to the first character not part of the number.
-*/
-
-static const char *getnum(register const char *strp, int * const nump, const int min, const int max)
-{
- register char c;
- register int num;
-
- if (strp == NULL || !is_digit(c = *strp))
- return NULL;
- num = 0;
- do {
- num = num * 10 + (c - '0');
- if (num > max)
- return NULL; /* illegal value */
- c = *++strp;
- } while (is_digit(c));
- if (num < min)
- return NULL; /* illegal value */
- *nump = num;
- return strp;
-}
-
-/*! \brief
- * Given a pointer into a time zone string, extract a number of seconds,
- * in hh[:mm[:ss]] form, from the string.
- * \return If any error occurs, return NULL.
- * Otherwise, return a pointer to the first character not part of the number
- * of seconds.
-*/
-
-static const char *getsecs(register const char *strp, long * const secsp)
-{
- int num;
-
- /*
- ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
- ** "M10.4.6/26", which does not conform to Posix,
- ** but which specifies the equivalent of
- ** ``02:00 on the first Sunday on or after 23 Oct''.
- */
- strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
- if (strp == NULL)
- return NULL;
- *secsp = num * (long) SECSPERHOUR;
- if (*strp == ':') {
- ++strp;
- strp = getnum(strp, &num, 0, MINSPERHOUR - 1);
- if (strp == NULL)
- return NULL;
- *secsp += num * SECSPERMIN;
- if (*strp == ':') {
- ++strp;
- /* `SECSPERMIN' allows for leap seconds. */
- strp = getnum(strp, &num, 0, SECSPERMIN);
- if (strp == NULL)
- return NULL;
- *secsp += num;
- }
- }
- return strp;
-}
-
-/*! \brief
- * Given a pointer into a time zone string, extract an offset, in
- * [+-]hh[:mm[:ss]] form, from the string.
- * \return If any error occurs, return NULL.
- * Otherwise, return a pointer to the first character not part of the time.
-*/
-
-static const char * getoffset(register const char *strp, long * const offsetp)
-{
- register int neg = 0;
-
- if (*strp == '-') {
- neg = 1;
- ++strp;
- } else if (*strp == '+')
- ++strp;
- strp = getsecs(strp, offsetp);
- if (strp == NULL)
- return NULL; /* illegal time */
- if (neg)
- *offsetp = -*offsetp;
- return strp;
-}
-
-/*! \brief
- * Given a pointer into a time zone string, extract a rule in the form
- * date[/time]. See POSIX section 8 for the format of "date" and "time".
- * \return If a valid rule is not found, return NULL.
- * Otherwise, return a pointer to the first character not part of the rule.
-*/
-
-static const char *getrule(const char *strp, register struct rule * const rulep)
-{
- if (*strp == 'J') {
- /*
- ** Julian day.
- */
- rulep->r_type = JULIAN_DAY;
- ++strp;
- strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
- } else if (*strp == 'M') {
- /*
- ** Month, week, day.
- */
- rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
- ++strp;
- strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
- if (strp == NULL)
- return NULL;
- if (*strp++ != '.')
- return NULL;
- strp = getnum(strp, &rulep->r_week, 1, 5);
- if (strp == NULL)
- return NULL;
- if (*strp++ != '.')
- return NULL;
- strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
- } else if (is_digit(*strp)) {
- /*
- ** Day of year.
- */
- rulep->r_type = DAY_OF_YEAR;
- strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
- } else return NULL; /* invalid format */
- if (strp == NULL)
- return NULL;
- if (*strp == '/') {
- /*
- ** Time specified.
- */
- ++strp;
- strp = getsecs(strp, &rulep->r_time);
- } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
- return strp;
-}
-
-/*! \brief
- * Given the Epoch-relative time of January 1, 00:00:00 GMT, in a year, the
- * year, a rule, and the offset from GMT at the time that rule takes effect,
- * calculate the Epoch-relative time that rule takes effect.
-*/
-
-static time_t transtime(janfirst, year, rulep, offset)
-const time_t janfirst;
-const int year;
-register const struct rule * const rulep;
-const long offset;
-{
- register int leapyear;
- register time_t value = 0;
- register int i;
- int d, m1, yy0, yy1, yy2, dow;
-
- leapyear = isleap(year);
- switch (rulep->r_type) {
-
- case JULIAN_DAY:
- /*
- ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
- ** years.
- ** In non-leap years, or if the day number is 59 or less, just
- ** add SECSPERDAY times the day number-1 to the time of
- ** January 1, midnight, to get the day.
- */
- value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
- if (leapyear && rulep->r_day >= 60)
- value += SECSPERDAY;
- break;
-
- case DAY_OF_YEAR:
- /*
- ** n - day of year.
- ** Just add SECSPERDAY times the day number to the time of
- ** January 1, midnight, to get the day.
- */
- value = janfirst + rulep->r_day * SECSPERDAY;
- break;
-
- case MONTH_NTH_DAY_OF_WEEK:
- /*
- ** Mm.n.d - nth "dth day" of month m.
- */
- value = janfirst;
- for (i = 0; i < rulep->r_mon - 1; ++i)
- value += mon_lengths[leapyear][i] * SECSPERDAY;
-
- /*
- ** Use Zeller's Congruence to get day-of-week of first day of
- ** month.
- */
- m1 = (rulep->r_mon + 9) % 12 + 1;
- yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
- yy1 = yy0 / 100;
- yy2 = yy0 % 100;
- dow = ((26 * m1 - 2) / 10 +
- 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
- if (dow < 0)
- dow += DAYSPERWEEK;
-
- /*
- ** "dow" is the day-of-week of the first day of the month. Get
- ** the day-of-month (zero-origin) of the first "dow" day of the
- ** month.
- */
- d = rulep->r_day - dow;
- if (d < 0)
- d += DAYSPERWEEK;
- for (i = 1; i < rulep->r_week; ++i) {
- if (d + DAYSPERWEEK >=
- mon_lengths[leapyear][rulep->r_mon - 1])
- break;
- d += DAYSPERWEEK;
- }
-
- /*
- ** "d" is the day-of-month (zero-origin) of the day we want.
- */
- value += d * SECSPERDAY;
- break;
- }
-
- /*
- ** "value" is the Epoch-relative time of 00:00:00 GMT on the day in
- ** question. To get the Epoch-relative time of the specified local
- ** time on that day, add the transition time and the current offset
- ** from GMT.
- */
- return value + rulep->r_time + offset;
-}
-
-/*
-** Given a POSIX section 8-style TZ string, fill in the rule tables as
-** appropriate.
-*/
-
-static int
-tzparse(name, sp, lastditch)
-const char * name;
-register struct state * const sp;
-const int lastditch;
-{
- const char * stdname;
- const char * dstname = NULL;
- size_t stdlen = 0;
- size_t dstlen = 0;
- long stdoffset = 0L;
- long dstoffset = 0L;
- register time_t * atp;
- register unsigned char * typep;
- register char * cp;
- register int load_result;
-
- stdname = name;
-#ifdef DEBUG
- fprintf(stderr, "tzparse(): loading default rules\n");
-#endif
- load_result = tzload(TZDEFRULES, sp);
- if (load_result != 0)
- sp->leapcnt = 0; /* so, we're off a little */
- if (*name != '\0') {
- if (*name != '\0' && *name != ',' && *name != ';') {
- name = getoffset(name, &dstoffset);
- if (name == NULL)
- return -1;
- } else dstoffset = stdoffset - SECSPERHOUR;
- if (*name == ',' || *name == ';') {
- struct rule start;
- struct rule end;
- register int year;
- register time_t janfirst;
- time_t starttime;
- time_t endtime;
-
- ++name;
- if ((name = getrule(name, &start)) == NULL)
- return -1;
- if (*name++ != ',')
- return -1;
- if ((name = getrule(name, &end)) == NULL)
- return -1;
- if (*name != '\0')
- return -1;
- sp->typecnt = 2; /* standard time and DST */
- /*
- ** Two transitions per year, from EPOCH_YEAR to 2037.
- */
- sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1);
- if (sp->timecnt > TZ_MAX_TIMES)
- return -1;
- sp->ttis[0].tt_gmtoff = -dstoffset;
- sp->ttis[0].tt_isdst = 1;
- sp->ttis[0].tt_abbrind = stdlen + 1;
- sp->ttis[1].tt_gmtoff = -stdoffset;
- sp->ttis[1].tt_isdst = 0;
- sp->ttis[1].tt_abbrind = 0;
- atp = sp->ats;
- typep = sp->types;
- janfirst = 0;
- for (year = EPOCH_YEAR; year <= 2037; ++year) {
- starttime = transtime(janfirst, year, &start,
- stdoffset);
- endtime = transtime(janfirst, year, &end,
- dstoffset);
- if (starttime > endtime) {
- *atp++ = endtime;
- *typep++ = 1; /* DST ends */
- *atp++ = starttime;
- *typep++ = 0; /* DST begins */
- } else {
- *atp++ = starttime;
- *typep++ = 0; /* DST begins */
- *atp++ = endtime;
- *typep++ = 1; /* DST ends */
- }
- janfirst += year_lengths[isleap(year)] *
- SECSPERDAY;
- }
- } else {
- register long theirstdoffset;
- register long theirdstoffset;
- register long theiroffset;
- register int isdst;
- register int i;
- register int j;
-
- if (*name != '\0')
- return -1;
- if (load_result != 0)
- return -1;
- /*
- ** Initial values of theirstdoffset and theirdstoffset.
- */
- theirstdoffset = 0;
- for (i = 0; i < sp->timecnt; ++i) {
- j = sp->types[i];
- if (!sp->ttis[j].tt_isdst) {
- theirstdoffset =
- -sp->ttis[j].tt_gmtoff;
- break;
- }
- }
- theirdstoffset = 0;
- for (i = 0; i < sp->timecnt; ++i) {
- j = sp->types[i];
- if (sp->ttis[j].tt_isdst) {
- theirdstoffset =
- -sp->ttis[j].tt_gmtoff;
- break;
- }
- }
- /*
- ** Initially we're assumed to be in standard time.
- */
- isdst = FALSE;
- theiroffset = theirstdoffset;
- /*
- ** Now juggle transition times and types
- ** tracking offsets as you do.
- */
- for (i = 0; i < sp->timecnt; ++i) {
- j = sp->types[i];
- sp->types[i] = sp->ttis[j].tt_isdst;
- if (sp->ttis[j].tt_ttisgmt) {
- /* No adjustment to transition time */
- } else {
- /*
- ** If summer time is in effect, and the
- ** transition time was not specified as
- ** standard time, add the summer time
- ** offset to the transition time;
- ** otherwise, add the standard time
- ** offset to the transition time.
- */
- /*
- ** Transitions from DST to DDST
- ** will effectively disappear since
- ** POSIX provides for only one DST
- ** offset.
- */
- if (isdst && !sp->ttis[j].tt_ttisstd) {
- sp->ats[i] += dstoffset -
- theirdstoffset;
- } else {
- sp->ats[i] += stdoffset -
- theirstdoffset;
- }
- }
- theiroffset = -sp->ttis[j].tt_gmtoff;
- if (sp->ttis[j].tt_isdst)
- theirdstoffset = theiroffset;
- else theirstdoffset = theiroffset;
- }
- /*
- ** Finally, fill in ttis.
- ** ttisstd and ttisgmt need not be handled.
- */
- sp->ttis[0].tt_gmtoff = -stdoffset;
- sp->ttis[0].tt_isdst = FALSE;
- sp->ttis[0].tt_abbrind = 0;
- sp->ttis[1].tt_gmtoff = -dstoffset;
- sp->ttis[1].tt_isdst = TRUE;
- sp->ttis[1].tt_abbrind = stdlen + 1;
- }
- } else {
- dstlen = 0;
- sp->typecnt = 1; /* only standard time */
- sp->timecnt = 0;
- sp->ttis[0].tt_gmtoff = -stdoffset;
- sp->ttis[0].tt_isdst = 0;
- sp->ttis[0].tt_abbrind = 0;
- }
- sp->charcnt = stdlen + 1;
- if (dstlen != 0)
- sp->charcnt += dstlen + 1;
- if (sp->charcnt > sizeof sp->chars)
- return -1;
- cp = sp->chars;
- (void) strncpy(cp, stdname, stdlen);
- cp += stdlen;
- *cp++ = '\0';
- if (dstlen != 0) {
- (void) strncpy(cp, dstname, dstlen);
- *(cp + dstlen) = '\0';
- }
- return 0;
-}
-
-static void
-gmtload(sp)
-struct state * const sp;
-{
- if (tzload(gmt, sp) != 0)
- (void) tzparse(gmt, sp, TRUE);
-}
-
-/*
-** A non-static declaration of ast_tzsetwall in a system header file
-** may cause a warning about this upcoming static declaration...
-*/
-static
-#ifdef _THREAD_SAFE
-int
-ast_tzsetwall_basic P((void))
-#else
-int
-ast_tzsetwall P((void))
-#endif
-{
- struct state *cur_state = lclptr;
-
- /* Find the appropriate structure, if already parsed */
- while (cur_state != NULL) {
- if (cur_state->name[0] == '\0')
- break;
- cur_state = cur_state->next;
- }
- if (cur_state != NULL)
- return 0;
- cur_state = malloc(sizeof(struct state));
- if (cur_state == NULL) {
- return -1;
- }
- memset(cur_state,0,sizeof(struct state));
- if (tzload((char *) NULL, cur_state) != 0)
-#ifdef DEBUG
- {
- fprintf(stderr, "ast_tzsetwall: calling gmtload()\n");
-#endif
- gmtload(cur_state);
-#ifdef DEBUG
- }
-#endif
-
- if (last_lclptr)
- last_lclptr->next = cur_state;
- else
- lclptr = cur_state;
- last_lclptr = cur_state;
- return 0;
-}
-
-#ifdef _THREAD_SAFE
-int
-ast_tzsetwall P((void))
-{
- ast_mutex_lock(&tzsetwall_mutex);
- ast_tzsetwall_basic();
- ast_mutex_unlock(&tzsetwall_mutex);
- return 0;
-}
-#endif
-
-#ifdef _THREAD_SAFE
-static int
-ast_tzset_basic P((const char *name))
-#else
-int
-ast_tzset P((const char *name))
-#endif
-{
- struct state *cur_state = lclptr;
-
- /* Not set at all */
- if (name == NULL) {
- return ast_tzsetwall();
- }
-
- /* Find the appropriate structure, if already parsed */
- while (cur_state != NULL) {
- if (!strcmp(cur_state->name,name))
- break;
- cur_state = cur_state->next;
- }
- if (cur_state != NULL)
- return 0;
-
- cur_state = malloc(sizeof(struct state));
- if (cur_state == NULL) {
- return -1;
- }
- memset(cur_state,0,sizeof(*cur_state));
-
- /* Name is set, but set to the empty string == no adjustments */
- if (name[0] == '\0') {
- /*
- ** User wants it fast rather than right.
- */
- cur_state->leapcnt = 0; /* so, we're off a little */
- cur_state->timecnt = 0;
- cur_state->ttis[0].tt_gmtoff = 0;
- cur_state->ttis[0].tt_abbrind = 0;
- (void) strncpy(cur_state->chars, gmt, sizeof(cur_state->chars) - 1);
- } else if (tzload(name, cur_state) != 0) {
- if (name[0] == ':') {
- (void) gmtload(cur_state);
- } else if (tzparse(name, cur_state, FALSE) != 0) {
- /* If not found, load localtime */
- if (tzload("/etc/localtime", cur_state) != 0)
- /* Last ditch, get GMT */
- (void) gmtload(cur_state);
- }
- }
- strncpy(cur_state->name, name, sizeof(cur_state->name) - 1);
- if (last_lclptr)
- last_lclptr->next = cur_state;
- else
- lclptr = cur_state;
- last_lclptr = cur_state;
- return 0;
-}
-
-#ifdef _THREAD_SAFE
-void
-ast_tzset P((const char *name))
-{
- ast_mutex_lock(&tzset_mutex);
- ast_tzset_basic(name);
- ast_mutex_unlock(&tzset_mutex);
-}
-#endif
-
-/*
-** The easy way to behave "as if no library function calls" localtime
-** is to not call it--so we drop its guts into "localsub", which can be
-** freely called. (And no, the PANS doesn't require the above behavior--
-** but it *is* desirable.)
-**
-** The unused offset argument is for the benefit of mktime variants.
-*/
-
-/*ARGSUSED*/
-static void
-localsub(timep, offset, tmp, zone)
-const time_t * const timep;
-const long offset;
-struct tm * const tmp;
-const char * const zone;
-{
- register struct state * sp;
- register const struct ttinfo * ttisp;
- register int i;
- const time_t t = *timep;
-
- sp = lclptr;
- /* Find the right zone record */
- if (zone == NULL)
- sp = NULL;
- else
- while (sp != NULL) {
- if (!strcmp(sp->name,zone))
- break;
- sp = sp->next;
- }
-
- if (sp == NULL) {
- ast_tzsetwall();
- sp = lclptr;
- /* Find the default zone record */
- while (sp != NULL) {
- if (sp->name[0] == '\0')
- break;
- sp = sp->next;
- }
- }
-
- /* Last ditch effort, use GMT */
- if (sp == NULL) {
- gmtsub(timep, offset, tmp, zone);
- return;
- }
- if (sp->timecnt == 0 || t < sp->ats[0]) {
- i = 0;
- while (sp->ttis[i].tt_isdst)
- if (++i >= sp->typecnt) {
- i = 0;
- break;
- }
- } else {
- for (i = 1; i < sp->timecnt; ++i)
- if (t < sp->ats[i])
- break;
- i = sp->types[i - 1];
- }
- ttisp = &sp->ttis[i];
- /*
- ** To get (wrong) behavior that's compatible with System V Release 2.0
- ** you'd replace the statement below with
- ** t += ttisp->tt_gmtoff;
- ** timesub(&t, 0L, sp, tmp);
- */
- timesub(&t, ttisp->tt_gmtoff, sp, tmp);
- tmp->tm_isdst = ttisp->tt_isdst;
- tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
-#ifdef TM_ZONE
- tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];
-#endif /* defined TM_ZONE */
-}
-
-struct tm *
-ast_localtime(timep, p_tm, zone)
-const time_t * const timep;
-struct tm *p_tm;
-const char * const zone;
-{
-#ifdef _THREAD_SAFE
- ast_mutex_lock(&lcl_mutex);
-#endif
- ast_tzset(zone);
- localsub(timep, 0L, p_tm, zone);
-#ifdef _THREAD_SAFE
- ast_mutex_unlock(&lcl_mutex);
-#endif
- return(p_tm);
-}
-
-/*
-** gmtsub is to gmtime as localsub is to localtime.
-*/
-
-static void
-gmtsub(timep, offset, tmp, zone)
-const time_t * const timep;
-const long offset;
-struct tm * const tmp;
-const char * const zone;
-{
-#ifdef _THREAD_SAFE
- ast_mutex_lock(&gmt_mutex);
-#endif
- if (!gmt_is_set) {
- gmt_is_set = TRUE;
- gmtptr = (struct state *) malloc(sizeof *gmtptr);
- if (gmtptr != NULL)
- gmtload(gmtptr);
- }
- ast_mutex_unlock(&gmt_mutex);
- timesub(timep, offset, gmtptr, tmp);
-#ifdef TM_ZONE
- /*
- ** Could get fancy here and deliver something such as
- ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero,
- ** but this is no time for a treasure hunt.
- */
- if (offset != 0)
- tmp->TM_ZONE = wildabbr;
- else {
- if (gmtptr == NULL)
- tmp->TM_ZONE = gmt;
- else tmp->TM_ZONE = gmtptr->chars;
- }
-#endif /* defined TM_ZONE */
-}
-
-static void
-timesub(timep, offset, sp, tmp)
-const time_t * const timep;
-const long offset;
-register const struct state * const sp;
-register struct tm * const tmp;
-{
- register const struct lsinfo * lp;
- register long days;
- register long rem;
- register int y;
- register int yleap;
- register const int * ip;
- register long corr;
- register int hit;
- register int i;
-
- corr = 0;
- hit = 0;
- i = (sp == NULL) ? 0 : sp->leapcnt;
- while (--i >= 0) {
- lp = &sp->lsis[i];
- if (*timep >= lp->ls_trans) {
- if (*timep == lp->ls_trans) {
- hit = ((i == 0 && lp->ls_corr > 0) ||
- lp->ls_corr > sp->lsis[i - 1].ls_corr);
- if (hit)
- while (i > 0 &&
- sp->lsis[i].ls_trans ==
- sp->lsis[i - 1].ls_trans + 1 &&
- sp->lsis[i].ls_corr ==
- sp->lsis[i - 1].ls_corr + 1) {
- ++hit;
- --i;
- }
- }
- corr = lp->ls_corr;
- break;
- }
- }
- days = *timep / SECSPERDAY;
- rem = *timep % SECSPERDAY;
-#ifdef mc68k
- if (*timep == 0x80000000) {
- /*
- ** A 3B1 muffs the division on the most negative number.
- */
- days = -24855;
- rem = -11648;
- }
-#endif /* defined mc68k */
- rem += (offset - corr);
- while (rem < 0) {
- rem += SECSPERDAY;
- --days;
- }
- while (rem >= SECSPERDAY) {
- rem -= SECSPERDAY;
- ++days;
- }
- tmp->tm_hour = (int) (rem / SECSPERHOUR);
- rem = rem % SECSPERHOUR;
- tmp->tm_min = (int) (rem / SECSPERMIN);
- /*
- ** A positive leap second requires a special
- ** representation. This uses "... ??:59:60" et seq.
- */
- tmp->tm_sec = (int) (rem % SECSPERMIN) + hit;
- tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);
- if (tmp->tm_wday < 0)
- tmp->tm_wday += DAYSPERWEEK;
- y = EPOCH_YEAR;
-#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
- while (days < 0 || days >= (long) year_lengths[yleap = isleap(y)]) {
- register int newy;
-
- newy = y + days / DAYSPERNYEAR;
- if (days < 0)
- --newy;
- days -= (newy - y) * DAYSPERNYEAR +
- LEAPS_THRU_END_OF(newy - 1) -
- LEAPS_THRU_END_OF(y - 1);
- y = newy;
- }
- tmp->tm_year = y - TM_YEAR_BASE;
- tmp->tm_yday = (int) days;
- ip = mon_lengths[yleap];
- for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon))
- days = days - (long) ip[tmp->tm_mon];
- tmp->tm_mday = (int) (days + 1);
- tmp->tm_isdst = 0;
-#ifdef TM_GMTOFF
- tmp->TM_GMTOFF = offset;
-#endif /* defined TM_GMTOFF */
-}
-
-char *
-ast_ctime(timep)
-const time_t * const timep;
-{
-/*
-** Section 4.12.3.2 of X3.159-1989 requires that
-** The ctime funciton converts the calendar time pointed to by timer
-** to local time in the form of a string. It is equivalent to
-** asctime(localtime(timer))
-*/
- return asctime(localtime(timep));
-}
-
-char *
-ast_ctime_r(timep, buf)
-const time_t * const timep;
-char *buf;
-{
- struct tm tm;
-#ifdef SOLARIS
- return asctime_r(localtime_r(timep, &tm), buf, 256);
-#else
- return asctime_r(localtime_r(timep, &tm), buf);
-#endif
-}
-
-/*
-** Adapted from code provided by Robert Elz, who writes:
-** The "best" way to do mktime I think is based on an idea of Bob
-** Kridle's (so its said...) from a long time ago.
-** [kridle@xinet.com as of 1996-01-16.]
-** It does a binary search of the time_t space. Since time_t's are
-** just 32 bits, its a max of 32 iterations (even at 64 bits it
-** would still be very reasonable).
-*/
-
-#ifndef WRONG
-#define WRONG (-1)
-#endif /* !defined WRONG */
-
-/*
-** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com).
-*/
-
-static int
-increment_overflow(number, delta)
-int * number;
-int delta;
-{
- int number0;
-
- number0 = *number;
- *number += delta;
- return (*number < number0) != (delta < 0);
-}
-
-static int
-normalize_overflow(tensptr, unitsptr, base)
-int * const tensptr;
-int * const unitsptr;
-const int base;
-{
- register int tensdelta;
-
- tensdelta = (*unitsptr >= 0) ?
- (*unitsptr / base) :
- (-1 - (-1 - *unitsptr) / base);
- *unitsptr -= tensdelta * base;
- return increment_overflow(tensptr, tensdelta);
-}
-
-static int
-tmcomp(atmp, btmp)
-register const struct tm * const atmp;
-register const struct tm * const btmp;
-{
- register int result;
-
- if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
- (result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
- (result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
- (result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
- (result = (atmp->tm_min - btmp->tm_min)) == 0)
- result = atmp->tm_sec - btmp->tm_sec;
- return result;
-}
-
-static time_t
-time2(tmp, funcp, offset, okayp, zone)
-struct tm * const tmp;
-void (* const funcp) P((const time_t*, long, struct tm*, const char*));
-const long offset;
-int * const okayp;
-const char * const zone;
-{
- register const struct state * sp;
- register int dir;
- register int bits;
- register int i, j ;
- register int saved_seconds;
- time_t newt;
- time_t t;
- struct tm yourtm, mytm;
-
- *okayp = FALSE;
- yourtm = *tmp;
- if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR))
- return WRONG;
- if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY))
- return WRONG;
- if (normalize_overflow(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR))
- return WRONG;
- /*
- ** Turn yourtm.tm_year into an actual year number for now.
- ** It is converted back to an offset from TM_YEAR_BASE later.
- */
- if (increment_overflow(&yourtm.tm_year, TM_YEAR_BASE))
- return WRONG;
- while (yourtm.tm_mday <= 0) {
- if (increment_overflow(&yourtm.tm_year, -1))
- return WRONG;
- i = yourtm.tm_year + (1 < yourtm.tm_mon);
- yourtm.tm_mday += year_lengths[isleap(i)];
- }
- while (yourtm.tm_mday > DAYSPERLYEAR) {
- i = yourtm.tm_year + (1 < yourtm.tm_mon);
- yourtm.tm_mday -= year_lengths[isleap(i)];
- if (increment_overflow(&yourtm.tm_year, 1))
- return WRONG;
- }
- for ( ; ; ) {
- i = mon_lengths[isleap(yourtm.tm_year)][yourtm.tm_mon];
- if (yourtm.tm_mday <= i)
- break;
- yourtm.tm_mday -= i;
- if (++yourtm.tm_mon >= MONSPERYEAR) {
- yourtm.tm_mon = 0;
- if (increment_overflow(&yourtm.tm_year, 1))
- return WRONG;
- }
- }
- if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE))
- return WRONG;
- if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) {
- /*
- ** We can't set tm_sec to 0, because that might push the
- ** time below the minimum representable time.
- ** Set tm_sec to 59 instead.
- ** This assumes that the minimum representable time is
- ** not in the same minute that a leap second was deleted from,
- ** which is a safer assumption than using 58 would be.
- */
- if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN))
- return WRONG;
- saved_seconds = yourtm.tm_sec;
- yourtm.tm_sec = SECSPERMIN - 1;
- } else {
- saved_seconds = yourtm.tm_sec;
- yourtm.tm_sec = 0;
- }
- /*
- ** Divide the search space in half
- ** (this works whether time_t is signed or unsigned).
- */
- bits = TYPE_BIT(time_t) - 1;
- /*
- ** If time_t is signed, then 0 is just above the median,
- ** assuming two's complement arithmetic.
- ** If time_t is unsigned, then (1 << bits) is just above the median.
- */
- t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits);
- for ( ; ; ) {
- (*funcp)(&t, offset, &mytm, zone);
- dir = tmcomp(&mytm, &yourtm);
- if (dir != 0) {
- if (bits-- < 0)
- return WRONG;
- if (bits < 0)
- --t; /* may be needed if new t is minimal */
- else if (dir > 0)
- t -= ((time_t) 1) << bits;
- else t += ((time_t) 1) << bits;
- continue;
- }
- if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
- break;
- /*
- ** Right time, wrong type.
- ** Hunt for right time, right type.
- ** It's okay to guess wrong since the guess
- ** gets checked.
- */
- /*
- ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
- */
- sp = (const struct state *)
- (((void *) funcp == (void *) localsub) ?
- lclptr : gmtptr);
- if (sp == NULL)
- return WRONG;
- for (i = sp->typecnt - 1; i >= 0; --i) {
- if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
- continue;
- for (j = sp->typecnt - 1; j >= 0; --j) {
- if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
- continue;
- newt = t + sp->ttis[j].tt_gmtoff -
- sp->ttis[i].tt_gmtoff;
- (*funcp)(&newt, offset, &mytm, zone);
- if (tmcomp(&mytm, &yourtm) != 0)
- continue;
- if (mytm.tm_isdst != yourtm.tm_isdst)
- continue;
- /*
- ** We have a match.
- */
- t = newt;
- goto label;
- }
- }
- return WRONG;
- }
-label:
- newt = t + saved_seconds;
- if ((newt < t) != (saved_seconds < 0))
- return WRONG;
- t = newt;
- (*funcp)(&t, offset, tmp, zone);
- *okayp = TRUE;
- return t;
-}
-
-static time_t
-time1(tmp, funcp, offset, zone)
-struct tm * const tmp;
-void (* const funcp) P((const time_t *, long, struct tm *, const char*));
-const long offset;
-const char * const zone;
-{
- register time_t t;
- register const struct state * sp;
- register int samei, otheri;
- int okay;
-
- if (tmp->tm_isdst > 1)
- tmp->tm_isdst = 1;
- t = time2(tmp, funcp, offset, &okay, zone);
-#ifdef PCTS
- /*
- ** PCTS code courtesy Grant Sullivan (grant@osf.org).
- */
- if (okay)
- return t;
- if (tmp->tm_isdst < 0)
- tmp->tm_isdst = 0; /* reset to std and try again */
-#endif /* defined PCTS */
-#ifndef PCTS
- if (okay || tmp->tm_isdst < 0)
- return t;
-#endif /* !defined PCTS */
- /*
- ** We're supposed to assume that somebody took a time of one type
- ** and did some math on it that yielded a "struct tm" that's bad.
- ** We try to divine the type they started from and adjust to the
- ** type they need.
- */
- /*
- ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
- */
- sp = (const struct state *) (((void *) funcp == (void *) localsub) ?
- lclptr : gmtptr);
- if (sp == NULL)
- return WRONG;
- for (samei = sp->typecnt - 1; samei >= 0; --samei) {
- if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
- continue;
- for (otheri = sp->typecnt - 1; otheri >= 0; --otheri) {
- if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
- continue;
- tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
- sp->ttis[samei].tt_gmtoff;
- tmp->tm_isdst = !tmp->tm_isdst;
- t = time2(tmp, funcp, offset, &okay, zone);
- if (okay)
- return t;
- tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff -
- sp->ttis[samei].tt_gmtoff;
- tmp->tm_isdst = !tmp->tm_isdst;
- }
- }
- return WRONG;
-}
-
-time_t
-ast_mktime(tmp,zone)
-struct tm * const tmp;
-const char * const zone;
-{
- time_t mktime_return_value;
-#ifdef _THREAD_SAFE
- ast_mutex_lock(&lcl_mutex);
-#endif
- ast_tzset(zone);
- mktime_return_value = time1(tmp, localsub, 0L, zone);
-#ifdef _THREAD_SAFE
- ast_mutex_unlock(&lcl_mutex);
-#endif
- return(mktime_return_value);
-}
-
diff --git a/1.2-netsec/stdtime/private.h b/1.2-netsec/stdtime/private.h
deleted file mode 100644
index 60479d787..000000000
--- a/1.2-netsec/stdtime/private.h
+++ /dev/null
@@ -1,222 +0,0 @@
-/* $FreeBSD: src/lib/libc/stdtime/private.h,v 1.6.8.1 2000/08/23 00:19:15 jhb Exp $ */
-
-#ifndef PRIVATE_H
-
-#define PRIVATE_H
-/*
-** This file is in the public domain, so clarified as of
-** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
-*/
-
-/* Stuff moved from Makefile.inc to reduce clutter */
-#ifndef __CYGWIN__
-#ifndef TM_GMTOFF
-#define TM_GMTOFF tm_gmtoff
-#define TM_ZONE tm_zone
-#endif
-#define STD_INSPIRED 1
-#define PCTS 1
-#define HAVE_LONG_DOUBLE 1
-#define HAVE_STRERROR 1
-#define HAVE_UNISTD_H 1
-#define LOCALE_HOME _PATH_LOCALE
-#define TZDIR "/usr/share/zoneinfo"
-#endif /* ndef TM_GMTOFF */
-
-/*
-** This header is for use ONLY with the time conversion code.
-** There is no guarantee that it will remain unchanged,
-** or that it will remain at all.
-** Do NOT copy it to any system include directory.
-** Thank you!
-*/
-
-/*
-** ID
-*/
-
-#ifndef lint
-#ifndef NOID
-/*
-static char privatehid[] = "@(#)private.h 7.43";
-*/
-#endif /* !defined NOID */
-#endif /* !defined lint */
-
-/*
-** Defaults for preprocessor symbols.
-** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
-*/
-
-#ifndef HAVE_ADJTIME
-#define HAVE_ADJTIME 1
-#endif /* !defined HAVE_ADJTIME */
-
-#ifndef HAVE_GETTEXT
-#define HAVE_GETTEXT 0
-#endif /* !defined HAVE_GETTEXT */
-
-#ifndef HAVE_SETTIMEOFDAY
-#define HAVE_SETTIMEOFDAY 3
-#endif /* !defined HAVE_SETTIMEOFDAY */
-
-#ifndef HAVE_STRERROR
-#define HAVE_STRERROR 0
-#endif /* !defined HAVE_STRERROR */
-
-#ifndef HAVE_UNISTD_H
-#define HAVE_UNISTD_H 1
-#endif /* !defined HAVE_UNISTD_H */
-
-#ifndef HAVE_UTMPX_H
-#define HAVE_UTMPX_H 0
-#endif /* !defined HAVE_UTMPX_H */
-
-#ifndef LOCALE_HOME
-#define LOCALE_HOME "/usr/lib/locale"
-#endif /* !defined LOCALE_HOME */
-
-/*
-** Nested includes
-*/
-
-#include "sys/types.h" /* for time_t */
-#include "stdio.h"
-#include "errno.h"
-#include "string.h"
-#include "limits.h" /* for CHAR_BIT */
-#include "time.h"
-#include "stdlib.h"
-
-#if HAVE_GETTEXT - 0
-#include "libintl.h"
-#endif /* HAVE_GETTEXT - 0 */
-
-#if HAVE_UNISTD_H - 0
-#include "unistd.h" /* for F_OK and R_OK */
-#endif /* HAVE_UNISTD_H - 0 */
-
-#if !(HAVE_UNISTD_H - 0)
-#ifndef F_OK
-#define F_OK 0
-#endif /* !defined F_OK */
-#ifndef R_OK
-#define R_OK 4
-#endif /* !defined R_OK */
-#endif /* !(HAVE_UNISTD_H - 0) */
-
-/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
-#define is_digit(c) ((unsigned)(c) - '0' <= 9)
-
-/*
-** Workarounds for compilers/systems.
-*/
-
-#ifndef P
-#ifdef __STDC__
-#define P(x) x
-#endif /* defined __STDC__ */
-#ifndef __STDC__
-#define P(x) ()
-#endif /* !defined __STDC__ */
-#endif /* !defined P */
-
-/*
-** SunOS 4.1.1 headers lack FILENAME_MAX.
-*/
-
-#ifndef FILENAME_MAX
-
-#ifndef MAXPATHLEN
-#ifdef unix
-#include "sys/param.h"
-#endif /* defined unix */
-#endif /* !defined MAXPATHLEN */
-
-#ifdef MAXPATHLEN
-#define FILENAME_MAX MAXPATHLEN
-#endif /* defined MAXPATHLEN */
-#ifndef MAXPATHLEN
-#define FILENAME_MAX 1024 /* Pure guesswork */
-#endif /* !defined MAXPATHLEN */
-
-#endif /* !defined FILENAME_MAX */
-
-/*
-** Finally, some convenience items.
-*/
-
-#ifndef TRUE
-#define TRUE 1
-#endif /* !defined TRUE */
-
-#ifndef FALSE
-#define FALSE 0
-#endif /* !defined FALSE */
-
-#ifndef TYPE_BIT
-#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
-#endif /* !defined TYPE_BIT */
-
-#ifndef TYPE_SIGNED
-#define TYPE_SIGNED(type) (((type) -1) < 0)
-#endif /* !defined TYPE_SIGNED */
-
-#ifndef INT_STRLEN_MAXIMUM
-/*
-** 302 / 1000 is log10(2.0) rounded up.
-** Subtract one for the sign bit if the type is signed;
-** add one for integer division truncation;
-** add one more for a minus sign if the type is signed.
-*/
-#define INT_STRLEN_MAXIMUM(type) \
- ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))
-#endif /* !defined INT_STRLEN_MAXIMUM */
-
-/*
-** INITIALIZE(x)
-*/
-
-#ifndef GNUC_or_lint
-#ifdef lint
-#define GNUC_or_lint
-#endif /* defined lint */
-#ifndef lint
-#ifdef __GNUC__
-#define GNUC_or_lint
-#endif /* defined __GNUC__ */
-#endif /* !defined lint */
-#endif /* !defined GNUC_or_lint */
-
-#ifndef INITIALIZE
-#ifdef GNUC_or_lint
-#define INITIALIZE(x) ((x) = 0)
-#endif /* defined GNUC_or_lint */
-#ifndef GNUC_or_lint
-#define INITIALIZE(x)
-#endif /* !defined GNUC_or_lint */
-#endif /* !defined INITIALIZE */
-
-/*
-** For the benefit of GNU folk...
-** `_(MSGID)' uses the current locale's message library string for MSGID.
-** The default is to use gettext if available, and use MSGID otherwise.
-*/
-
-#ifndef _
-#if HAVE_GETTEXT - 0
-#define _(msgid) gettext(msgid)
-#else /* !(HAVE_GETTEXT - 0) */
-#define _(msgid) msgid
-#endif /* !(HAVE_GETTEXT - 0) */
-#endif /* !defined _ */
-
-#ifndef TZ_DOMAIN
-#define TZ_DOMAIN "tz"
-#endif /* !defined TZ_DOMAIN */
-
-/*
-** UNIX was a registered trademark of UNIX System Laboratories in 1993.
-*/
-
-#endif /* !defined PRIVATE_H */
diff --git a/1.2-netsec/stdtime/test.c b/1.2-netsec/stdtime/test.c
deleted file mode 100644
index 9e8ce45da..000000000
--- a/1.2-netsec/stdtime/test.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*! \file
- \brief Testing localtime functionality */
-
-#include "localtime.c"
-#include <sys/time.h>
-#include <stdio.h>
-
-int main(int argc, char **argv) {
- struct timeval tv;
- struct tm tm;
- char *zone[4] = { "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles" };
- int i;
-
- gettimeofday(&tv,NULL);
-
- for (i=0;i<4;i++) {
- ast_localtime(&tv.tv_sec,&tm,zone[i]);
- printf("Localtime at %s is %04d/%02d/%02d %02d:%02d:%02d\n",zone[i],tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
- }
- return 0;
-}
diff --git a/1.2-netsec/stdtime/tzfile.h b/1.2-netsec/stdtime/tzfile.h
deleted file mode 100644
index f16d5a05c..000000000
--- a/1.2-netsec/stdtime/tzfile.h
+++ /dev/null
@@ -1,189 +0,0 @@
-#ifndef TZFILE_H
-
-#define TZFILE_H
-
-/*! \brief
- * This file is in the public domain, so clarified as of
- * 1996-06-05 by
- * \author Arthur David Olson (arthur_david_olson@nih.gov).
- *
- * \note This header is for use ONLY with the time conversion code.
- * There is no guarantee that it will remain unchanged,
- * or that it will remain at all.
- * Do NOT copy it to any system include directory.
- * Thank you!
- */
-
-/*
-** ID
-*/
-
-#ifndef lint
-#ifndef NOID
-/*
-static char tzfilehid[] = "@(#)tzfile.h 7.14";
-*/
-#endif /* !defined NOID */
-#endif /* !defined lint */
-
-/*
-** Information about time zone files.
-*/
-
-#ifndef TZDIR
-#define TZDIR "/usr/share/zoneinfo" /*!< Time zone object file directory */
-#endif /* !defined TZDIR */
-
-#ifndef TZDEFAULT
-#define TZDEFAULT "/etc/localtime"
-#endif /* !defined TZDEFAULT */
-
-#ifndef TZDEFRULES
-#define TZDEFRULES "posixrules"
-#endif /* !defined TZDEFRULES */
-
-/*
-** Each file begins with. . .
-*/
-
-#define TZ_MAGIC "TZif"
-
-struct tzhead {
- char tzh_magic[4]; /* TZ_MAGIC */
- char tzh_reserved[16]; /* reserved for future use */
- char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
- char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
- char tzh_leapcnt[4]; /* coded number of leap seconds */
- char tzh_timecnt[4]; /* coded number of transition times */
- char tzh_typecnt[4]; /* coded number of local time types */
- char tzh_charcnt[4]; /* coded number of abbr. chars */
-};
-
-/*
-** . . .followed by. . .
-**
-** tzh_timecnt (char [4])s coded transition times a la time(2)
-** tzh_timecnt (unsigned char)s types of local time starting at above
-** tzh_typecnt repetitions of
-** one (char [4]) coded UTC offset in seconds
-** one (unsigned char) used to set tm_isdst
-** one (unsigned char) that's an abbreviation list index
-** tzh_charcnt (char)s '\0'-terminated zone abbreviations
-** tzh_leapcnt repetitions of
-** one (char [4]) coded leap second transition times
-** one (char [4]) total correction after above
-** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
-** time is standard time, if FALSE,
-** transition time is wall clock time
-** if absent, transition times are
-** assumed to be wall clock time
-** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition
-** time is UTC, if FALSE,
-** transition time is local time
-** if absent, transition times are
-** assumed to be local time
-*/
-
-/*
-** In the current implementation, "tzset()" refuses to deal with files that
-** exceed any of the limits below.
-*/
-
-#ifndef TZ_MAX_TIMES
-/*
-** The TZ_MAX_TIMES value below is enough to handle a bit more than a
-** year's worth of solar time (corrected daily to the nearest second) or
-** 138 years of Pacific Presidential Election time
-** (where there are three time zone transitions every fourth year).
-*/
-#define TZ_MAX_TIMES 370
-#endif /* !defined TZ_MAX_TIMES */
-
-#ifndef TZ_MAX_TYPES
-#ifndef NOSOLAR
-#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
-#endif /* !defined NOSOLAR */
-#ifdef NOSOLAR
-/*
-** Must be at least 14 for Europe/Riga as of Jan 12 1995,
-** as noted by Earl Chew <earl@hpato.aus.hp.com>.
-*/
-#define TZ_MAX_TYPES 20 /* Maximum number of local time types */
-#endif /* !defined NOSOLAR */
-#endif /* !defined TZ_MAX_TYPES */
-
-#ifndef TZ_MAX_CHARS
-#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
- /* (limited by what unsigned chars can hold) */
-#endif /* !defined TZ_MAX_CHARS */
-
-#ifndef TZ_MAX_LEAPS
-#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
-#endif /* !defined TZ_MAX_LEAPS */
-
-#define SECSPERMIN 60
-#define MINSPERHOUR 60
-#define HOURSPERDAY 24
-#define DAYSPERWEEK 7
-#define DAYSPERNYEAR 365
-#define DAYSPERLYEAR 366
-#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
-#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
-#define MONSPERYEAR 12
-
-#define TM_SUNDAY 0
-#define TM_MONDAY 1
-#define TM_TUESDAY 2
-#define TM_WEDNESDAY 3
-#define TM_THURSDAY 4
-#define TM_FRIDAY 5
-#define TM_SATURDAY 6
-
-#define TM_JANUARY 0
-#define TM_FEBRUARY 1
-#define TM_MARCH 2
-#define TM_APRIL 3
-#define TM_MAY 4
-#define TM_JUNE 5
-#define TM_JULY 6
-#define TM_AUGUST 7
-#define TM_SEPTEMBER 8
-#define TM_OCTOBER 9
-#define TM_NOVEMBER 10
-#define TM_DECEMBER 11
-
-#define TM_YEAR_BASE 1900
-
-#define EPOCH_YEAR 1970
-#define EPOCH_WDAY TM_THURSDAY
-
-/*
-** Accurate only for the past couple of centuries;
-** that will probably do.
-*/
-
-#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
-
-#ifndef USG
-
-/*
-** Use of the underscored variants may cause problems if you move your code to
-** certain System-V-based systems; for maximum portability, use the
-** underscore-free variants. The underscored variants are provided for
-** backward compatibility only; they may disappear from future versions of
-** this file.
-*/
-
-#define SECS_PER_MIN SECSPERMIN
-#define MINS_PER_HOUR MINSPERHOUR
-#define HOURS_PER_DAY HOURSPERDAY
-#define DAYS_PER_WEEK DAYSPERWEEK
-#define DAYS_PER_NYEAR DAYSPERNYEAR
-#define DAYS_PER_LYEAR DAYSPERLYEAR
-#define SECS_PER_HOUR SECSPERHOUR
-#define SECS_PER_DAY SECSPERDAY
-#define MONS_PER_YEAR MONSPERYEAR
-
-#endif /* !defined USG */
-
-#endif /* !defined TZFILE_H */
diff --git a/1.2-netsec/strcompat.c b/1.2-netsec/strcompat.c
deleted file mode 100644
index 38615ac5d..000000000
--- a/1.2-netsec/strcompat.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Compatibility functions for strsep and strtoq missing on Solaris */
-
-#include <sys/types.h>
-#include <stdio.h>
-
-#include "asterisk/compat.h"
-
-char* strsep(char** str, const char* delims)
-{
- char* token;
-
- if (*str==NULL) {
- /* No more tokens */
- return NULL;
- }
-
- token=*str;
- while (**str!='\0') {
- if (strchr(delims,**str)!=NULL) {
- **str='\0';
- (*str)++;
- return token;
- }
- (*str)++;
- }
- /* There is no other token */
- *str=NULL;
- return token;
-}
-
-
-
-int setenv(const char *name, const char *value, int overwrite)
-{
- unsigned char *buf;
- int buflen, ret;
-
- buflen = strlen(name) + strlen(value) + 2;
- if ((buf = malloc(buflen)) == NULL)
- return -1;
-
- if (!overwrite && getenv(name))
- return 0;
-
- snprintf(buf, buflen, "%s=%s", name, value);
- ret = putenv(buf);
-
- free(buf);
-
- return ret;
-}
-
-int unsetenv(const char *name)
-{
- setenv(name,"",0);
-}
-
diff --git a/1.2-netsec/tdd.c b/1.2-netsec/tdd.c
deleted file mode 100644
index df6c9f0a3..000000000
--- a/1.2-netsec/tdd.c
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Includes code and algorithms from the Zapata library.
- *
- * 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 TTY/TDD Generation support
- *
- */
-
-#include <time.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <math.h>
-#include <ctype.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/ulaw.h"
-#include "asterisk/tdd.h"
-#include "asterisk/logger.h"
-#include "asterisk/fskmodem.h"
-#include "ecdisa.h"
-
-struct tdd_state {
- fsk_data fskd;
- char rawdata[256];
- short oldstuff[4096];
- int oldlen;
- int pos;
- int modo;
- int mode;
-};
-
-static float dr[4], di[4];
-static float tddsb = 176.0; /* 45.5 baud */
-
-#define TDD_SPACE 1800.0 /* 1800 hz for "0" */
-#define TDD_MARK 1400.0 /* 1400 hz for "1" */
-
-static int tdd_decode_baudot(struct tdd_state *tdd,unsigned char data) /* covert baudot into ASCII */
-{
- static char ltrs[32]={'<','E','\n','A',' ','S','I','U',
- '\n','D','R','J','N','F','C','K',
- 'T','Z','L','W','H','Y','P','Q',
- 'O','B','G','^','M','X','V','^'};
- static char figs[32]={'<','3','\n','-',' ',',','8','7',
- '\n','$','4','\'',',','·',':','(',
- '5','+',')','2','·','6','0','1',
- '9','7','·','^','.','/','=','^'};
- int d;
- d=0; /* return 0 if not decodeable */
- switch (data) {
- case 0x1f : tdd->modo=0; break;
- case 0x1b : tdd->modo=1; break;
- default: if (tdd->modo==0) d=ltrs[data]; else d=figs[data]; break;
- }
- return d;
-}
-
-void tdd_init(void)
-{
- /* Initialize stuff for inverse FFT */
- dr[0] = cos(TDD_SPACE * 2.0 * M_PI / 8000.0);
- di[0] = sin(TDD_SPACE * 2.0 * M_PI / 8000.0);
- dr[1] = cos(TDD_MARK * 2.0 * M_PI / 8000.0);
- di[1] = sin(TDD_MARK * 2.0 * M_PI / 8000.0);
-}
-
-struct tdd_state *tdd_new(void)
-{
- struct tdd_state *tdd;
- tdd = malloc(sizeof(struct tdd_state));
- if (tdd) {
- memset(tdd, 0, sizeof(struct tdd_state));
- tdd->fskd.spb = 176; /* 45.5 baud */
- tdd->fskd.hdlc = 0; /* Async */
- tdd->fskd.nbit = 5; /* 5 bits */
- tdd->fskd.nstop = 1.5; /* 1.5 stop bits */
- tdd->fskd.paridad = 0; /* No parity */
- tdd->fskd.bw=0; /* Filter 75 Hz */
- tdd->fskd.f_mark_idx = 0; /* 1400 Hz */
- tdd->fskd.f_space_idx = 1; /* 1800 Hz */
- tdd->fskd.pcola = 0; /* No clue */
- tdd->fskd.cont = 0; /* Digital PLL reset */
- tdd->fskd.x0 = 0.0;
- tdd->fskd.state = 0;
- tdd->pos = 0;
- tdd->mode = 2;
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
- return tdd;
-}
-
-int ast_tdd_gen_ecdisa(unsigned char *outbuf, int len)
-{
- int pos = 0;
- int cnt;
- while(len) {
- cnt = len;
- if (cnt > sizeof(ecdisa))
- cnt = sizeof(ecdisa);
- memcpy(outbuf + pos, ecdisa, cnt);
- pos += cnt;
- len -= cnt;
- }
- return 0;
-}
-
-int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
-{
- int mylen = len;
- int olen;
- int b = 'X';
- int res;
- int c,x;
- short *buf = malloc(2 * len + tdd->oldlen);
- short *obuf = buf;
- if (!buf) {
- ast_log(LOG_WARNING, "Out of memory\n");
- return -1;
- }
- memset(buf, 0, 2 * len + tdd->oldlen);
- memcpy(buf, tdd->oldstuff, tdd->oldlen);
- mylen += tdd->oldlen/2;
- for (x=0;x<len;x++)
- buf[x+tdd->oldlen/2] = AST_MULAW(ubuf[x]);
- c = res = 0;
- while(mylen >= 1320) { /* has to have enough to work on */
- olen = mylen;
- res = fsk_serie(&tdd->fskd, buf, &mylen, &b);
- if (mylen < 0) {
- ast_log(LOG_ERROR, "fsk_serie made mylen < 0 (%d) (olen was %d)\n", mylen,olen);
- free(obuf);
- return -1;
- }
- buf += (olen - mylen);
- if (res < 0) {
- ast_log(LOG_NOTICE, "fsk_serie failed\n");
- free(obuf);
- return -1;
- }
- if (res == 1) {
- /* Ignore invalid bytes */
- if (b > 0x7f)
- continue;
- c = tdd_decode_baudot(tdd,b);
- if ((c < 1) || (c > 126)) continue; /* if not valid */
- break;
- }
- }
- if (mylen) {
- memcpy(tdd->oldstuff, buf, mylen * 2);
- tdd->oldlen = mylen * 2;
- } else
- tdd->oldlen = 0;
- free(obuf);
- if (res) {
- tdd->mode = 2; /* put it in mode where it
- reliably puts teleprinter in correct shift mode */
- return(c);
- }
- return 0;
-}
-
-void tdd_free(struct tdd_state *tdd)
-{
- free(tdd);
-}
-
-static inline float tdd_getcarrier(float *cr, float *ci, int bit)
-{
- /* Move along. There's nothing to see here... */
- float t;
- t = *cr * dr[bit] - *ci * di[bit];
- *ci = *cr * di[bit] + *ci * dr[bit];
- *cr = t;
-
- t = 2.0 - (*cr * *cr + *ci * *ci);
- *cr *= t;
- *ci *= t;
- return *cr;
-}
-
-#define PUT_BYTE(a) do { \
- *(buf++) = (a); \
- bytes++; \
-} while(0)
-
-#define PUT_AUDIO_SAMPLE(y) do { \
- int index = (short)(rint(8192.0 * (y))); \
- *(buf++) = AST_LIN2MU(index); \
- bytes++; \
-} while(0)
-
-#define PUT_TDD_MARKMS do { \
- int x; \
- for (x=0;x<8;x++) \
- PUT_AUDIO_SAMPLE(tdd_getcarrier(&cr, &ci, 1)); \
-} while(0)
-
-#define PUT_TDD_BAUD(bit) do { \
- while(scont < tddsb) { \
- PUT_AUDIO_SAMPLE(tdd_getcarrier(&cr, &ci, bit)); \
- scont += 1.0; \
- } \
- scont -= tddsb; \
-} while(0)
-
-#define PUT_TDD_STOP do { \
- while(scont < (tddsb * 1.5)) { \
- PUT_AUDIO_SAMPLE(tdd_getcarrier(&cr, &ci, 1)); \
- scont += 1.0; \
- } \
- scont -= (tddsb * 1.5); \
-} while(0)
-
-
-#define PUT_TDD(byte) do { \
- int z; \
- unsigned char b = (byte); \
- PUT_TDD_BAUD(0); /* Start bit */ \
- for (z=0;z<5;z++) { \
- PUT_TDD_BAUD(b & 1); \
- b >>= 1; \
- } \
- PUT_TDD_STOP; /* Stop bit */ \
-} while(0);
-
-int tdd_generate(struct tdd_state *tdd, unsigned char *buf, const char *str)
-{
- int bytes=0;
- int i,x;
- char c;
- static unsigned char lstr[31] = "\000E\nA SIU\rDRJNFCKTZLWHYPQOBG\000MXV";
- static unsigned char fstr[31] = "\0003\n- \00787\r$4',!:(5\")2\0006019?&\000./;";
- /* Initial carriers (real/imaginary) */
- float cr = 1.0;
- float ci = 0.0;
- float scont = 0.0;
-
- for(x = 0; str[x]; x++) {
- c = toupper(str[x]);
-#if 0
- printf("%c",c); fflush(stdout);
-#endif
- if (c == 0) /* send null */
- {
- PUT_TDD(0);
- continue;
- }
- if (c == '\r') /* send c/r */
- {
- PUT_TDD(8);
- continue;
- }
- if (c == '\n') /* send c/r and l/f */
- {
- PUT_TDD(8);
- PUT_TDD(2);
- continue;
- }
- if (c == ' ') /* send space */
- {
- PUT_TDD(4);
- continue;
- }
- for(i = 0; i < 31; i++)
- {
- if (lstr[i] == c) break;
- }
- if (i < 31) /* if we found it */
- {
- if (tdd->mode) /* if in figs mode, change it */
- {
- PUT_TDD(31); /* Send LTRS */
- tdd->mode = 0;
- }
- PUT_TDD(i);
- continue;
- }
- for(i = 0; i < 31; i++)
- {
- if (fstr[i] == c) break;
- }
- if (i < 31) /* if we found it */
- {
- if (tdd->mode != 1) /* if in ltrs mode, change it */
- {
- PUT_TDD(27); /* send FIGS */
- tdd->mode = 1;
- }
- PUT_TDD(i); /* send byte */
- continue;
- }
- }
- return bytes;
-}
-
-
diff --git a/1.2-netsec/term.c b/1.2-netsec/term.c
deleted file mode 100644
index 582adb0af..000000000
--- a/1.2-netsec/term.c
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Terminal Routines
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/term.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-
-static int vt100compat = 0;
-
-static char prepdata[80] = "";
-static char enddata[80] = "";
-static char quitdata[80] = "";
-
-static const char *termpath[] = {
- "/usr/share/terminfo",
- "/usr/local/share/misc/terminfo",
- "/usr/lib/terminfo",
- NULL
- };
-
-/* Ripped off from Ross Ridge, but it's public domain code (libmytinfo) */
-static short convshort(char *s)
-{
- register int a,b;
-
- a = (int) s[0] & 0377;
- b = (int) s[1] & 0377;
-
- if (a == 0377 && b == 0377)
- return -1;
- if (a == 0376 && b == 0377)
- return -2;
-
- return a + b * 256;
-}
-
-int term_init(void)
-{
- char *term = getenv("TERM");
- char termfile[256] = "";
- char buffer[512] = "";
- int termfd = -1, parseokay = 0, i;
-
- if (!term)
- return 0;
- if (!option_console || option_nocolor || !option_nofork)
- return 0;
-
- for (i=0 ;; i++) {
- if (termpath[i] == NULL) {
- break;
- }
- snprintf(termfile, sizeof(termfile), "%s/%c/%s", termpath[i], *term, term);
- termfd = open(termfile, O_RDONLY);
- if (termfd > -1) {
- break;
- }
- }
- if (termfd > -1) {
- int actsize = read(termfd, buffer, sizeof(buffer) - 1);
- short sz_names = convshort(buffer + 2);
- short sz_bools = convshort(buffer + 4);
- short n_nums = convshort(buffer + 6);
-
- /* if ((sz_names + sz_bools) & 1)
- sz_bools++; */
-
- if (sz_names + sz_bools + n_nums < actsize) {
- /* Offset 13 is defined in /usr/include/term.h, though we do not
- * include it here, as it conflicts with include/asterisk/term.h */
- short max_colors = convshort(buffer + 12 + sz_names + sz_bools + 13 * 2);
- if (max_colors > 0) {
- vt100compat = 1;
- }
- parseokay = 1;
- }
- close(termfd);
- }
-
- if (!parseokay) {
- /* These comparisons should not be substrings nor case-insensitive, as
- * terminal types are very particular about how they treat suffixes and
- * capitalization. For example, terminal type 'linux-m' does NOT
- * support color, while 'linux' does. Not even all vt100* terminals
- * support color, either (e.g. 'vt100+fnkeys'). */
- if (!strcmp(term, "linux")) {
- vt100compat = 1;
- } else if (!strcmp(term, "xterm")) {
- vt100compat = 1;
- } else if (!strcmp(term, "xterm-color")) {
- vt100compat = 1;
- } else if (!strncmp(term, "Eterm", 5)) {
- /* Both entries which start with Eterm support color */
- vt100compat = 1;
- } else if (!strcmp(term, "vt100")) {
- vt100compat = 1;
- } else if (!strncmp(term, "crt", 3)) {
- /* Both crt terminals support color */
- vt100compat = 1;
- }
- }
-
- if (vt100compat) {
- /* Make commands show up in nice colors */
- snprintf(prepdata, sizeof(prepdata), "%c[%d;%d;%dm", ESC, ATTR_BRIGHT, COLOR_BROWN, COLOR_BLACK + 10);
- snprintf(enddata, sizeof(enddata), "%c[%d;%d;%dm", ESC, ATTR_RESET, COLOR_WHITE, COLOR_BLACK + 10);
- snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
- }
- return 0;
-}
-
-char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
-{
- int attr=0;
- char tmp[40];
- if (!vt100compat) {
- ast_copy_string(outbuf, inbuf, maxout);
- return outbuf;
- }
- if (!fgcolor && !bgcolor) {
- ast_copy_string(outbuf, inbuf, maxout);
- return outbuf;
- }
- if ((fgcolor & 128) && (bgcolor & 128)) {
- /* Can't both be highlighted */
- ast_copy_string(outbuf, inbuf, maxout);
- return outbuf;
- }
- if (!bgcolor)
- bgcolor = COLOR_BLACK;
-
- if (bgcolor) {
- bgcolor &= ~128;
- bgcolor += 10;
- }
- if (fgcolor & 128) {
- attr = ATTR_BRIGHT;
- fgcolor &= ~128;
- }
- if (fgcolor && bgcolor) {
- snprintf(tmp, sizeof(tmp), "%d;%d", fgcolor, bgcolor);
- } else if (bgcolor) {
- snprintf(tmp, sizeof(tmp), "%d", bgcolor);
- } else if (fgcolor) {
- snprintf(tmp, sizeof(tmp), "%d", fgcolor);
- }
- if (attr) {
- snprintf(outbuf, maxout, "%c[%d;%sm%s%c[0;%d;%dm", ESC, attr, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10);
- } else {
- snprintf(outbuf, maxout, "%c[%sm%s%c[0;%d;%dm", ESC, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10);
- }
- return outbuf;
-}
-
-char *term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout)
-{
- int attr=0;
- char tmp[40];
- if ((!vt100compat) || (!fgcolor && !bgcolor)) {
- *outbuf = '\0';
- return outbuf;
- }
- if ((fgcolor & 128) && (bgcolor & 128)) {
- /* Can't both be highlighted */
- *outbuf = '\0';
- return outbuf;
- }
- if (!bgcolor)
- bgcolor = COLOR_BLACK;
-
- if (bgcolor) {
- bgcolor &= ~128;
- bgcolor += 10;
- }
- if (fgcolor & 128) {
- attr = ATTR_BRIGHT;
- fgcolor &= ~128;
- }
- if (fgcolor && bgcolor) {
- snprintf(tmp, sizeof(tmp), "%d;%d", fgcolor, bgcolor);
- } else if (bgcolor) {
- snprintf(tmp, sizeof(tmp), "%d", bgcolor);
- } else if (fgcolor) {
- snprintf(tmp, sizeof(tmp), "%d", fgcolor);
- }
- if (attr) {
- snprintf(outbuf, maxout, "%c[%d;%sm", ESC, attr, tmp);
- } else {
- snprintf(outbuf, maxout, "%c[%sm", ESC, tmp);
- }
- return outbuf;
-}
-
-char *term_strip(char *outbuf, char *inbuf, int maxout)
-{
- char *outbuf_ptr = outbuf, *inbuf_ptr = inbuf;
-
- while (outbuf_ptr < outbuf + maxout) {
- switch (*inbuf_ptr) {
- case ESC:
- while (*inbuf_ptr && (*inbuf_ptr != 'm'))
- inbuf_ptr++;
- break;
- default:
- *outbuf_ptr = *inbuf_ptr;
- outbuf_ptr++;
- }
- if (! *inbuf_ptr)
- break;
- inbuf_ptr++;
- }
- return outbuf;
-}
-
-char *term_prompt(char *outbuf, const char *inbuf, int maxout)
-{
- if (!vt100compat) {
- ast_copy_string(outbuf, inbuf, maxout);
- return outbuf;
- }
- snprintf(outbuf, maxout, "%c[%d;%d;%dm%c%c[%d;%d;%dm%s",
- ESC, ATTR_BRIGHT, COLOR_BLUE, COLOR_BLACK + 10,
- inbuf[0],
- ESC, 0, COLOR_WHITE, COLOR_BLACK + 10,
- inbuf + 1);
- return outbuf;
-}
-
-char *term_prep(void)
-{
- return prepdata;
-}
-
-char *term_end(void)
-{
- return enddata;
-}
-
-char *term_quit(void)
-{
- return quitdata;
-}
diff --git a/1.2-netsec/translate.c b/1.2-netsec/translate.c
deleted file mode 100644
index 799a4440d..000000000
--- a/1.2-netsec/translate.c
+++ /dev/null
@@ -1,509 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief Translate via the use of pseudo channels
- *
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/logger.h"
-#include "asterisk/translate.h"
-#include "asterisk/options.h"
-#include "asterisk/frame.h"
-#include "asterisk/sched.h"
-#include "asterisk/cli.h"
-#include "asterisk/term.h"
-
-#define MAX_RECALC 200 /* max sample recalc */
-
-/*! \note
- This could all be done more efficiently *IF* we chained packets together
- by default, but it would also complicate virtually every application. */
-
-AST_MUTEX_DEFINE_STATIC(list_lock);
-static struct ast_translator *list = NULL;
-
-struct ast_translator_dir {
- struct ast_translator *step; /*!< Next step translator */
- unsigned int cost; /*!< Complete cost to destination */
- unsigned int multistep; /*!< Multiple conversions required for this translation */
-};
-
-struct ast_frame_delivery {
- struct ast_frame *f;
- struct ast_channel *chan;
- int fd;
- struct translator_pvt *owner;
- struct ast_frame_delivery *prev;
- struct ast_frame_delivery *next;
-};
-
-static struct ast_translator_dir tr_matrix[MAX_FORMAT][MAX_FORMAT];
-
-struct ast_trans_pvt {
- struct ast_translator *step;
- struct ast_translator_pvt *state;
- struct ast_trans_pvt *next;
- struct timeval nextin;
- struct timeval nextout;
-};
-
-
-static int powerof(int d)
-{
- int x;
- for (x = 0; x < 32; x++)
- if ((1 << x) & d)
- return x;
- ast_log(LOG_WARNING, "Powerof %d: No power??\n", d);
- return -1;
-}
-
-void ast_translator_free_path(struct ast_trans_pvt *p)
-{
- struct ast_trans_pvt *pl, *pn;
- pn = p;
- while(pn) {
- pl = pn;
- pn = pn->next;
- if (pl->state && pl->step->destroy)
- pl->step->destroy(pl->state);
- free(pl);
- }
-}
-
-/*! Build a set of translators based upon the given source and destination formats */
-struct ast_trans_pvt *ast_translator_build_path(int dest, int source)
-{
- struct ast_trans_pvt *tmpr = NULL, *tmp = NULL;
-
- source = powerof(source);
- dest = powerof(dest);
-
- while(source != dest) {
- if (!tr_matrix[source][dest].step) {
- /* We shouldn't have allocated any memory */
- ast_log(LOG_WARNING, "No translator path from %s to %s\n",
- ast_getformatname(source), ast_getformatname(dest));
- return NULL;
- }
-
- if (tmp) {
- tmp->next = malloc(sizeof(*tmp));
- tmp = tmp->next;
- } else
- tmp = malloc(sizeof(*tmp));
-
- if (!tmp) {
- ast_log(LOG_WARNING, "Out of memory\n");
- if (tmpr)
- ast_translator_free_path(tmpr);
- return NULL;
- }
-
- /* Set the root, if it doesn't exist yet... */
- if (!tmpr)
- tmpr = tmp;
-
- tmp->next = NULL;
- tmp->nextin = tmp->nextout = ast_tv(0, 0);
- tmp->step = tr_matrix[source][dest].step;
- tmp->state = tmp->step->newpvt();
-
- if (!tmp->state) {
- ast_log(LOG_WARNING, "Failed to build translator step from %d to %d\n", source, dest);
- ast_translator_free_path(tmpr);
- return NULL;
- }
-
- /* Keep going if this isn't the final destination */
- source = tmp->step->dstfmt;
- }
- return tmpr;
-}
-
-struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f, int consume)
-{
- struct ast_trans_pvt *p;
- struct ast_frame *out;
- struct timeval delivery;
- p = path;
- /* Feed the first frame into the first translator */
- p->step->framein(p->state, f);
- if (!ast_tvzero(f->delivery)) {
- if (!ast_tvzero(path->nextin)) {
- /* Make sure this is in line with what we were expecting */
- if (!ast_tveq(path->nextin, f->delivery)) {
- /* The time has changed between what we expected and this
- most recent time on the new packet. If we have a
- valid prediction adjust our output time appropriately */
- if (!ast_tvzero(path->nextout)) {
- path->nextout = ast_tvadd(path->nextout,
- ast_tvsub(f->delivery, path->nextin));
- }
- path->nextin = f->delivery;
- }
- } else {
- /* This is our first pass. Make sure the timing looks good */
- path->nextin = f->delivery;
- path->nextout = f->delivery;
- }
- /* Predict next incoming sample */
- path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, 8000));
- }
- delivery = f->delivery;
- if (consume)
- ast_frfree(f);
- while(p) {
- out = p->step->frameout(p->state);
- /* If we get nothing out, return NULL */
- if (!out)
- return NULL;
- /* If there is a next state, feed it in there. If not,
- return this frame */
- if (p->next)
- p->next->step->framein(p->next->state, out);
- else {
- if (!ast_tvzero(delivery)) {
- /* Regenerate prediction after a discontinuity */
- if (ast_tvzero(path->nextout))
- path->nextout = ast_tvnow();
-
- /* Use next predicted outgoing timestamp */
- out->delivery = path->nextout;
-
- /* Predict next outgoing timestamp from samples in this
- frame. */
- path->nextout = ast_tvadd(path->nextout, ast_samp2tv( out->samples, 8000));
- } else {
- out->delivery = ast_tv(0, 0);
- }
- /* Invalidate prediction if we're entering a silence period */
- if (out->frametype == AST_FRAME_CNG)
- path->nextout = ast_tv(0, 0);
- return out;
- }
- p = p->next;
- }
- ast_log(LOG_WARNING, "I should never get here...\n");
- return NULL;
-}
-
-
-static void calc_cost(struct ast_translator *t, int samples)
-{
- int sofar=0;
- struct ast_translator_pvt *pvt;
- struct ast_frame *f, *out;
- struct timeval start;
- int cost;
-
- if(!samples)
- samples = 1;
-
- /* If they don't make samples, give them a terrible score */
- if (!t->sample) {
- ast_log(LOG_WARNING, "Translator '%s' does not produce sample frames.\n", t->name);
- t->cost = 99999;
- return;
- }
- pvt = t->newpvt();
- if (!pvt) {
- ast_log(LOG_WARNING, "Translator '%s' appears to be broken and will probably fail.\n", t->name);
- t->cost = 99999;
- return;
- }
- start = ast_tvnow();
- /* Call the encoder until we've processed one second of time */
- while(sofar < samples * 8000) {
- f = t->sample();
- if (!f) {
- ast_log(LOG_WARNING, "Translator '%s' failed to produce a sample frame.\n", t->name);
- t->destroy(pvt);
- t->cost = 99999;
- return;
- }
- t->framein(pvt, f);
- ast_frfree(f);
- while((out = t->frameout(pvt))) {
- sofar += out->samples;
- ast_frfree(out);
- }
- }
- cost = ast_tvdiff_ms(ast_tvnow(), start);
- t->destroy(pvt);
- t->cost = cost / samples;
- if (!t->cost)
- t->cost = 1;
-}
-
-/*! \brief Use the list of translators to build a translation matrix */
-static void rebuild_matrix(int samples)
-{
- struct ast_translator *t;
- int changed;
- int x, y, z;
-
- if (option_debug)
- ast_log(LOG_DEBUG, "Resetting translation matrix\n");
-
- bzero(tr_matrix, sizeof(tr_matrix));
-
- for (t = list; t; t = t->next) {
- if (samples)
- calc_cost(t, samples);
-
- if (!tr_matrix[t->srcfmt][t->dstfmt].step ||
- tr_matrix[t->srcfmt][t->dstfmt].cost > t->cost) {
- tr_matrix[t->srcfmt][t->dstfmt].step = t;
- tr_matrix[t->srcfmt][t->dstfmt].cost = t->cost;
- }
- }
-
- do {
- changed = 0;
-
- /* Don't you just love O(N^3) operations? */
- for (x = 0; x< MAX_FORMAT; x++) { /* For each source format */
- for (y = 0; y < MAX_FORMAT; y++) { /* And each destination format */
- if (x == y) /* Except ourselves, of course */
- continue;
-
- for (z=0; z < MAX_FORMAT; z++) { /* And each format it might convert to */
- if ((x == z) || (y == z)) /* Don't ever convert back to us */
- continue;
-
- if (tr_matrix[x][y].step && /* We can convert from x to y */
- tr_matrix[y][z].step && /* And from y to z and... */
- (!tr_matrix[x][z].step || /* Either there isn't an x->z conversion */
- (tr_matrix[x][y].cost +
- tr_matrix[y][z].cost < /* Or we're cheaper than the existing */
- tr_matrix[x][z].cost) /* solution */
- )) {
- /* We can get from x to z via y with a cost that
- is the sum of the transition from x to y and
- from y to z */
-
- tr_matrix[x][z].step = tr_matrix[x][y].step;
- tr_matrix[x][z].cost = tr_matrix[x][y].cost +
- tr_matrix[y][z].cost;
- tr_matrix[x][z].multistep = 1;
- if (option_debug)
- ast_log(LOG_DEBUG, "Discovered %d cost path from %s to %s, via %d\n", tr_matrix[x][z].cost, ast_getformatname(x), ast_getformatname(z), y);
- changed++;
- }
- }
- }
- }
- } while (changed);
-}
-
-
-/*! \brief CLI "show translation" command handler */
-static int show_translation(int fd, int argc, char *argv[])
-{
-#define SHOW_TRANS 11
- int x, y, z;
- char line[80];
- if (argc > 4)
- return RESULT_SHOWUSAGE;
-
- ast_mutex_lock(&list_lock);
- if (argv[2] && !strcasecmp(argv[2],"recalc")) {
- z = argv[3] ? atoi(argv[3]) : 1;
-
- if (z <= 0) {
- ast_cli(fd," C'mon let's be serious here... defaulting to 1.\n");
- z = 1;
- }
-
- if (z > MAX_RECALC) {
- ast_cli(fd," Maximum limit of recalc exceeded by %d, truncating value to %d\n",z-MAX_RECALC,MAX_RECALC);
- z = MAX_RECALC;
- }
- ast_cli(fd," Recalculating Codec Translation (number of sample seconds: %d)\n\n",z);
- rebuild_matrix(z);
- }
-
- ast_cli(fd, " Translation times between formats (in milliseconds)\n");
- ast_cli(fd, " Source Format (Rows) Destination Format(Columns)\n\n");
- for (x = -1; x < SHOW_TRANS; x++) {
- /* next 2 lines run faster than using strcpy() */
- line[0] = ' ';
- line[1] = '\0';
- for (y=-1;y<SHOW_TRANS;y++) {
- if (x >= 0 && y >= 0 && tr_matrix[x][y].step)
- snprintf(line + strlen(line), sizeof(line) - strlen(line), " %5d", tr_matrix[x][y].cost >= 99999 ? tr_matrix[x][y].cost-99999 : tr_matrix[x][y].cost);
- else
- if (((x == -1 && y >= 0) || (y == -1 && x >= 0))) {
- snprintf(line + strlen(line), sizeof(line) - strlen(line),
- " %5s", ast_getformatname(1<<(x+y+1)) );
- } else if (x != -1 && y != -1) {
- snprintf(line + strlen(line), sizeof(line) - strlen(line), " -");
- } else {
- snprintf(line + strlen(line), sizeof(line) - strlen(line), " ");
- }
- }
- snprintf(line + strlen(line), sizeof(line) - strlen(line), "\n");
- ast_cli(fd, line);
- }
- ast_mutex_unlock(&list_lock);
- return RESULT_SUCCESS;
-}
-
-static int added_cli = 0;
-
-static char show_trans_usage[] =
-"Usage: show translation [recalc] [<recalc seconds>]\n"
-" Displays known codec translators and the cost associated\n"
-"with each conversion. If the argument 'recalc' is supplied along\n"
-"with optional number of seconds to test a new test will be performed\n"
-"as the chart is being displayed.\n";
-
-static struct ast_cli_entry show_trans =
-{ { "show", "translation", NULL }, show_translation, "Display translation matrix", show_trans_usage };
-
-int ast_register_translator(struct ast_translator *t)
-{
- char tmp[80];
- t->srcfmt = powerof(t->srcfmt);
- t->dstfmt = powerof(t->dstfmt);
- if (t->srcfmt >= MAX_FORMAT) {
- ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt));
- return -1;
- }
- if (t->dstfmt >= MAX_FORMAT) {
- ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt));
- return -1;
- }
- calc_cost(t,1);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Registered translator '%s' from format %s to %s, cost %d\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
- ast_mutex_lock(&list_lock);
- if (!added_cli) {
- ast_cli_register(&show_trans);
- added_cli++;
- }
- t->next = list;
- list = t;
- rebuild_matrix(0);
- ast_mutex_unlock(&list_lock);
- return 0;
-}
-
-/*! \brief unregister codec translator */
-int ast_unregister_translator(struct ast_translator *t)
-{
- char tmp[80];
- struct ast_translator *u, *ul = NULL;
- ast_mutex_lock(&list_lock);
- u = list;
- while(u) {
- if (u == t) {
- if (ul)
- ul->next = u->next;
- else
- list = u->next;
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Unregistered translator '%s' from format %s to %s\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt));
- break;
- }
- ul = u;
- u = u->next;
- }
- rebuild_matrix(0);
- ast_mutex_unlock(&list_lock);
- return (u ? 0 : -1);
-}
-
-/*! \brief Calculate our best translator source format, given costs, and a desired destination */
-int ast_translator_best_choice(int *dst, int *srcs)
-{
- int x,y;
- int best = -1;
- int bestdst = 0;
- int cur = 1;
- int besttime = INT_MAX;
- int beststeps = INT_MAX;
- int common;
-
- if ((common = (*dst) & (*srcs))) {
- /* We have a format in common */
- for (y = 0; y < MAX_FORMAT; y++) {
- if (cur & common) {
- /* This is a common format to both. Pick it if we don't have one already */
- bestdst = cur;
- best = cur;
- }
- cur = cur << 1;
- }
- } else {
- /* We will need to translate */
- ast_mutex_lock(&list_lock);
- for (y = 0; y < MAX_FORMAT; y++) {
- if (!(cur & *dst)) {
- cur = cur << 1;
- continue;
- }
-
- for (x = 0; x < MAX_FORMAT; x++) {
- if ((*srcs & (1 << x)) && /* x is a valid source format */
- tr_matrix[x][y].step) { /* There's a step */
- if (tr_matrix[x][y].cost > besttime)
- continue; /* It's more expensive, skip it */
-
- if (tr_matrix[x][y].cost == besttime &&
- tr_matrix[x][y].multistep >= beststeps)
- continue; /* It requires the same (or more) steps,
- skip it */
-
- /* It's better than what we have so far */
- best = 1 << x;
- bestdst = cur;
- besttime = tr_matrix[x][y].cost;
- beststeps = tr_matrix[x][y].multistep;
- }
- }
- cur = cur << 1;
- }
- ast_mutex_unlock(&list_lock);
- }
-
- if (best > -1) {
- *srcs = best;
- *dst = bestdst;
- best = 0;
- }
-
- return best;
-}
diff --git a/1.2-netsec/ulaw.c b/1.2-netsec/ulaw.c
deleted file mode 100644
index 618118d6c..000000000
--- a/1.2-netsec/ulaw.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief u-Law to Signed linear conversion
- *
- */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/ulaw.h"
-
-#define ZEROTRAP /*!< turn on the trap as per the MIL-STD */
-#define BIAS 0x84 /*!< define the add-in bias for 16 bit samples */
-#define CLIP 32635
-
-unsigned char __ast_lin2mu[16384];
-short __ast_mulaw[256];
-
-
-static unsigned char linear2ulaw(short sample)
-{
- static int exp_lut[256] = {
- 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
- 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 };
- int sign, exponent, mantissa;
- unsigned char ulawbyte;
-
- /* Get the sample into sign-magnitude. */
- sign = (sample >> 8) & 0x80; /* set aside the sign */
- if (sign != 0)
- sample = -sample; /* get magnitude */
- if (sample > CLIP)
- sample = CLIP; /* clip the magnitude */
-
- /* Convert from 16 bit linear to ulaw. */
- sample = sample + BIAS;
- exponent = exp_lut[(sample >> 7) & 0xFF];
- mantissa = (sample >> (exponent + 3)) & 0x0F;
- ulawbyte = ~(sign | (exponent << 4) | mantissa);
-#ifdef ZEROTRAP
- if (ulawbyte == 0)
- ulawbyte = 0x02; /* optional CCITT trap */
-#endif
-
- return ulawbyte;
-}
-
-/*!
- * \brief Set up mu-law conversion table
- */
-void ast_ulaw_init(void)
-{
- int i;
- for(i = 0;i < 256;i++) {
- short mu,e,f,y;
- static short etab[]={0,132,396,924,1980,4092,8316,16764};
-
- mu = 255-i;
- e = (mu & 0x70)/16;
- f = mu & 0x0f;
- y = f * (1 << (e + 3));
- y += etab[e];
- if (mu & 0x80) y = -y;
- __ast_mulaw[i] = y;
- }
- /* set up the reverse (mu-law) conversion table */
- for(i = -32768; i < 32768; i++) {
- __ast_lin2mu[((unsigned short)i) >> 2] = linear2ulaw(i);
- }
-
-}
-
diff --git a/1.2-netsec/utils.c b/1.2-netsec/utils.c
deleted file mode 100644
index f10441050..000000000
--- a/1.2-netsec/utils.c
+++ /dev/null
@@ -1,905 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * 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 Utility functions
- *
- * \note These are important for portability and security,
- * so please use them in favour of other routines.
- * Please consult the CODING GUIDELINES for more information.
- */
-
-#include <ctype.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/io.h"
-#include "asterisk/logger.h"
-#include "asterisk/md5.h"
-#include "asterisk/options.h"
-#include "asterisk/compat.h"
-
-#define AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */
-#include "asterisk/strings.h"
-
-#define AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */
-#include "asterisk/time.h"
-
-#define AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */
-#include "asterisk/utils.h"
-
-static char base64[64];
-static char b2a[256];
-
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__) || defined(__CYGWIN__)
-
-/* duh? ERANGE value copied from web... */
-#define ERANGE 34
-#undef gethostbyname
-
-AST_MUTEX_DEFINE_STATIC(__mutex);
-
-/* Recursive replacement for gethostbyname for BSD-based systems. This
-routine is derived from code originally written and placed in the public
-domain by Enzo Michelangeli <em@em.no-ip.com> */
-
-static int gethostbyname_r (const char *name, struct hostent *ret, char *buf,
- size_t buflen, struct hostent **result,
- int *h_errnop)
-{
- int hsave;
- struct hostent *ph;
- ast_mutex_lock(&__mutex); /* begin critical area */
- hsave = h_errno;
-
- ph = gethostbyname(name);
- *h_errnop = h_errno; /* copy h_errno to *h_herrnop */
- if (ph == NULL) {
- *result = NULL;
- } else {
- char **p, **q;
- char *pbuf;
- int nbytes=0;
- int naddr=0, naliases=0;
- /* determine if we have enough space in buf */
-
- /* count how many addresses */
- for (p = ph->h_addr_list; *p != 0; p++) {
- nbytes += ph->h_length; /* addresses */
- nbytes += sizeof(*p); /* pointers */
- naddr++;
- }
- nbytes += sizeof(*p); /* one more for the terminating NULL */
-
- /* count how many aliases, and total length of strings */
- for (p = ph->h_aliases; *p != 0; p++) {
- nbytes += (strlen(*p)+1); /* aliases */
- nbytes += sizeof(*p); /* pointers */
- naliases++;
- }
- nbytes += sizeof(*p); /* one more for the terminating NULL */
-
- /* here nbytes is the number of bytes required in buffer */
- /* as a terminator must be there, the minimum value is ph->h_length */
- if(nbytes > buflen) {
- *result = NULL;
- ast_mutex_unlock(&__mutex); /* end critical area */
- return ERANGE; /* not enough space in buf!! */
- }
-
- /* There is enough space. Now we need to do a deep copy! */
- /* Allocation in buffer:
- from [0] to [(naddr-1) * sizeof(*p)]:
- pointers to addresses
- at [naddr * sizeof(*p)]:
- NULL
- from [(naddr+1) * sizeof(*p)] to [(naddr+naliases) * sizeof(*p)] :
- pointers to aliases
- at [(naddr+naliases+1) * sizeof(*p)]:
- NULL
- then naddr addresses (fixed length), and naliases aliases (asciiz).
- */
-
- *ret = *ph; /* copy whole structure (not its address!) */
-
- /* copy addresses */
- q = (char **)buf; /* pointer to pointers area (type: char **) */
- ret->h_addr_list = q; /* update pointer to address list */
- pbuf = buf + ((naddr+naliases+2)*sizeof(*p)); /* skip that area */
- for (p = ph->h_addr_list; *p != 0; p++) {
- memcpy(pbuf, *p, ph->h_length); /* copy address bytes */
- *q++ = pbuf; /* the pointer is the one inside buf... */
- pbuf += ph->h_length; /* advance pbuf */
- }
- *q++ = NULL; /* address list terminator */
-
- /* copy aliases */
- ret->h_aliases = q; /* update pointer to aliases list */
- for (p = ph->h_aliases; *p != 0; p++) {
- strcpy(pbuf, *p); /* copy alias strings */
- *q++ = pbuf; /* the pointer is the one inside buf... */
- pbuf += strlen(*p); /* advance pbuf */
- *pbuf++ = 0; /* string terminator */
- }
- *q++ = NULL; /* terminator */
-
- strcpy(pbuf, ph->h_name); /* copy alias strings */
- ret->h_name = pbuf;
- pbuf += strlen(ph->h_name); /* advance pbuf */
- *pbuf++ = 0; /* string terminator */
-
- *result = ret; /* and let *result point to structure */
-
- }
- h_errno = hsave; /* restore h_errno */
- ast_mutex_unlock(&__mutex); /* end critical area */
-
- return (*result == NULL); /* return 0 on success, non-zero on error */
-}
-
-
-#endif
-
-/*! \brief Re-entrant (thread safe) version of gethostbyname that replaces the
- standard gethostbyname (which is not thread safe)
-*/
-struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp)
-{
- int res;
- int herrno;
- int dots=0;
- const char *s;
- struct hostent *result = NULL;
- /* Although it is perfectly legitimate to lookup a pure integer, for
- the sake of the sanity of people who like to name their peers as
- integers, we break with tradition and refuse to look up a
- pure integer */
- s = host;
- res = 0;
- while(s && *s) {
- if (*s == '.')
- dots++;
- else if (!isdigit(*s))
- break;
- s++;
- }
- if (!s || !*s) {
- /* Forge a reply for IP's to avoid octal IP's being interpreted as octal */
- if (dots != 3)
- return NULL;
- memset(hp, 0, sizeof(struct ast_hostent));
- hp->hp.h_addr_list = (void *) hp->buf;
- hp->hp.h_addr = hp->buf + sizeof(void *);
- if (inet_pton(AF_INET, host, hp->hp.h_addr) > 0)
- return &hp->hp;
- return NULL;
-
- }
-#ifdef SOLARIS
- result = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &herrno);
-
- if (!result || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0])
- return NULL;
-#else
- res = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &result, &herrno);
-
- if (res || !result || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0])
- return NULL;
-#endif
- return &hp->hp;
-}
-
-
-
-AST_MUTEX_DEFINE_STATIC(test_lock);
-AST_MUTEX_DEFINE_STATIC(test_lock2);
-static pthread_t test_thread;
-static int lock_count = 0;
-static int test_errors = 0;
-
-/*! \brief This is a regression test for recursive mutexes.
- test_for_thread_safety() will return 0 if recursive mutex locks are
- working properly, and non-zero if they are not working properly. */
-static void *test_thread_body(void *data)
-{
- ast_mutex_lock(&test_lock);
- lock_count += 10;
- if (lock_count != 10)
- test_errors++;
- ast_mutex_lock(&test_lock);
- lock_count += 10;
- if (lock_count != 20)
- test_errors++;
- ast_mutex_lock(&test_lock2);
- ast_mutex_unlock(&test_lock);
- lock_count -= 10;
- if (lock_count != 10)
- test_errors++;
- ast_mutex_unlock(&test_lock);
- lock_count -= 10;
- ast_mutex_unlock(&test_lock2);
- if (lock_count != 0)
- test_errors++;
- return NULL;
-}
-
-int test_for_thread_safety(void)
-{
- ast_mutex_lock(&test_lock2);
- ast_mutex_lock(&test_lock);
- lock_count += 1;
- ast_mutex_lock(&test_lock);
- lock_count += 1;
- ast_pthread_create(&test_thread, NULL, test_thread_body, NULL);
- usleep(100);
- if (lock_count != 2)
- test_errors++;
- ast_mutex_unlock(&test_lock);
- lock_count -= 1;
- usleep(100);
- if (lock_count != 1)
- test_errors++;
- ast_mutex_unlock(&test_lock);
- lock_count -= 1;
- if (lock_count != 0)
- test_errors++;
- ast_mutex_unlock(&test_lock2);
- usleep(100);
- if (lock_count != 0)
- test_errors++;
- pthread_join(test_thread, NULL);
- return(test_errors); /* return 0 on success. */
-}
-
-/*! \brief ast_md5_hash: Produce 16 char MD5 hash of value. ---*/
-void ast_md5_hash(char *output, char *input)
-{
- struct MD5Context md5;
- unsigned char digest[16];
- char *ptr;
- int x;
-
- MD5Init(&md5);
- MD5Update(&md5, (unsigned char *)input, strlen(input));
- MD5Final(digest, &md5);
- ptr = output;
- for (x=0; x<16; x++)
- ptr += sprintf(ptr, "%2.2x", digest[x]);
-}
-
-int ast_base64decode(unsigned char *dst, const char *src, int max)
-{
- int cnt = 0;
- unsigned int byte = 0;
- unsigned int bits = 0;
- int incnt = 0;
-#if 0
- unsigned char *odst = dst;
-#endif
- while(*src && (cnt < max)) {
- /* Shift in 6 bits of input */
- byte <<= 6;
- byte |= (b2a[(int)(*src)]) & 0x3f;
- bits += 6;
-#if 0
- printf("Add: %c %s\n", *src, binary(b2a[(int)(*src)] & 0x3f, 6));
-#endif
- src++;
- incnt++;
- /* If we have at least 8 bits left over, take that character
- off the top */
- if (bits >= 8) {
- bits -= 8;
- *dst = (byte >> bits) & 0xff;
-#if 0
- printf("Remove: %02x %s\n", *dst, binary(*dst, 8));
-#endif
- dst++;
- cnt++;
- }
- }
-#if 0
- dump(odst, cnt);
-#endif
- /* Dont worry about left over bits, they're extra anyway */
- return cnt;
-}
-
-int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
-{
- int cnt = 0;
- unsigned int byte = 0;
- int bits = 0;
- int index;
- int cntin = 0;
-#if 0
- char *odst = dst;
- dump(src, srclen);
-#endif
- /* Reserve one bit for end */
- max--;
- while((cntin < srclen) && (cnt < max)) {
- byte <<= 8;
-#if 0
- printf("Add: %02x %s\n", *src, binary(*src, 8));
-#endif
- byte |= *(src++);
- bits += 8;
- cntin++;
- while((bits >= 6) && (cnt < max)) {
- bits -= 6;
- /* We want only the top */
- index = (byte >> bits) & 0x3f;
- *dst = base64[index];
-#if 0
- printf("Remove: %c %s\n", *dst, binary(index, 6));
-#endif
- dst++;
- cnt++;
- }
- }
- if (bits && (cnt < max)) {
- /* Add one last character for the remaining bits,
- padding the rest with 0 */
- byte <<= (6 - bits);
- index = (byte) & 0x3f;
- *(dst++) = base64[index];
- cnt++;
- }
- *dst = '\0';
- return cnt;
-}
-
-static void base64_init(void)
-{
- int x;
- memset(b2a, -1, sizeof(b2a));
- /* Initialize base-64 Conversion table */
- for (x=0;x<26;x++) {
- /* A-Z */
- base64[x] = 'A' + x;
- b2a['A' + x] = x;
- /* a-z */
- base64[x + 26] = 'a' + x;
- b2a['a' + x] = x + 26;
- /* 0-9 */
- if (x < 10) {
- base64[x + 52] = '0' + x;
- b2a['0' + x] = x + 52;
- }
- }
- base64[62] = '+';
- base64[63] = '/';
- b2a[(int)'+'] = 62;
- b2a[(int)'/'] = 63;
-#if 0
- for (x=0;x<64;x++) {
- if (b2a[(int)base64[x]] != x) {
- fprintf(stderr, "!!! %d failed\n", x);
- } else
- fprintf(stderr, "--- %d passed\n", x);
- }
-#endif
-}
-
-/*! \brief ast_uri_encode: Turn text string to URI-encoded %XX version ---*/
-/* At this point, we're converting from ISO-8859-x (8-bit), not UTF8
- as in the SIP protocol spec
- If doreserved == 1 we will convert reserved characters also.
- RFC 2396, section 2.4
- outbuf needs to have more memory allocated than the instring
- to have room for the expansion. Every char that is converted
- is replaced by three ASCII characters.
-
- Note: The doreserved option is needed for replaces header in
- SIP transfers.
-*/
-char *ast_uri_encode(char *string, char *outbuf, int buflen, int doreserved)
-{
- char *reserved = ";/?:@&=+$, "; /* Reserved chars */
-
- char *ptr = string; /* Start with the string */
- char *out = NULL;
- char *buf = NULL;
-
- strncpy(outbuf, string, buflen);
-
- /* If there's no characters to convert, just go through and don't do anything */
- while (*ptr) {
- if (((unsigned char) *ptr) > 127 || (doreserved && strchr(reserved, *ptr)) ) {
- /* Oops, we need to start working here */
- if (!buf) {
- buf = outbuf;
- out = buf + (ptr - string) ; /* Set output ptr */
- }
- out += sprintf(out, "%%%02x", (unsigned char) *ptr);
- } else if (buf) {
- *out = *ptr; /* Continue copying the string */
- out++;
- }
- ptr++;
- }
- if (buf)
- *out = '\0';
- return outbuf;
-}
-
-/*! \brief ast_uri_decode: Decode SIP URI, URN, URL (overwrite the string) ---*/
-void ast_uri_decode(char *s)
-{
- char *o;
- unsigned int tmp;
-
- for (o = s; *s; s++, o++) {
- if (*s == '%' && strlen(s) > 2 && sscanf(s + 1, "%2x", &tmp) == 1) {
- /* have '%', two chars and correct parsing */
- *o = tmp;
- s += 2; /* Will be incremented once more when we break out */
- } else /* all other cases, just copy */
- *o = *s;
- }
- *o = '\0';
-}
-
-/*! \brief ast_inet_ntoa: Recursive thread safe replacement of inet_ntoa */
-const char *ast_inet_ntoa(char *buf, int bufsiz, struct in_addr ia)
-{
- return inet_ntop(AF_INET, &ia, buf, bufsiz);
-}
-
-int ast_utils_init(void)
-{
- base64_init();
- return 0;
-}
-
-#ifndef __linux__
-#undef pthread_create /* For ast_pthread_create function only */
-#endif /* !__linux__ */
-
-int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data, size_t stacksize)
-{
- pthread_attr_t lattr;
- if (!attr) {
- pthread_attr_init(&lattr);
- attr = &lattr;
- }
-#ifdef __linux__
- /* On Linux, pthread_attr_init() defaults to PTHREAD_EXPLICIT_SCHED,
- which is kind of useless. Change this here to
- PTHREAD_INHERIT_SCHED; that way the -p option to set realtime
- priority will propagate down to new threads by default.
- This does mean that callers cannot set a different priority using
- PTHREAD_EXPLICIT_SCHED in the attr argument; instead they must set
- the priority afterwards with pthread_setschedparam(). */
- errno = pthread_attr_setinheritsched(attr, PTHREAD_INHERIT_SCHED);
- if (errno)
- ast_log(LOG_WARNING, "pthread_attr_setinheritsched returned non-zero: %s\n", strerror(errno));
-#endif
-
- if (!stacksize)
- stacksize = AST_STACKSIZE;
- errno = pthread_attr_setstacksize(attr, stacksize);
- if (errno)
- ast_log(LOG_WARNING, "pthread_attr_setstacksize returned non-zero: %s\n", strerror(errno));
- return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */
-}
-
-int ast_wait_for_input(int fd, int ms)
-{
- struct pollfd pfd[1];
- memset(pfd, 0, sizeof(pfd));
- pfd[0].fd = fd;
- pfd[0].events = POLLIN|POLLPRI;
- return poll(pfd, 1, ms);
-}
-
-char *ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
-{
- char *e;
- char *q;
-
- s = ast_strip(s);
- if ((q = strchr(beg_quotes, *s))) {
- e = s + strlen(s) - 1;
- if (*e == *(end_quotes + (q - beg_quotes))) {
- s++;
- *e = '\0';
- }
- }
-
- return s;
-}
-
-int ast_build_string_va(char **buffer, size_t *space, const char *fmt, va_list ap)
-{
- int result;
-
- if (!buffer || !*buffer || !space || !*space)
- return -1;
-
- result = vsnprintf(*buffer, *space, fmt, ap);
-
- if (result < 0)
- return -1;
- else if (result > *space)
- result = *space;
-
- *buffer += result;
- *space -= result;
- return 0;
-}
-
-int ast_build_string(char **buffer, size_t *space, const char *fmt, ...)
-{
- va_list ap;
- int result;
-
- va_start(ap, fmt);
- result = ast_build_string_va(buffer, space, fmt, ap);
- va_end(ap);
-
- return result;
-}
-
-int ast_true(const char *s)
-{
- if (ast_strlen_zero(s))
- return 0;
-
- /* Determine if this is a true value */
- if (!strcasecmp(s, "yes") ||
- !strcasecmp(s, "true") ||
- !strcasecmp(s, "y") ||
- !strcasecmp(s, "t") ||
- !strcasecmp(s, "1") ||
- !strcasecmp(s, "on"))
- return -1;
-
- return 0;
-}
-
-int ast_false(const char *s)
-{
- if (ast_strlen_zero(s))
- return 0;
-
- /* Determine if this is a false value */
- if (!strcasecmp(s, "no") ||
- !strcasecmp(s, "false") ||
- !strcasecmp(s, "n") ||
- !strcasecmp(s, "f") ||
- !strcasecmp(s, "0") ||
- !strcasecmp(s, "off"))
- return -1;
-
- return 0;
-}
-
-#define ONE_MILLION 1000000
-/*
- * put timeval in a valid range. usec is 0..999999
- * negative values are not allowed and truncated.
- */
-static struct timeval tvfix(struct timeval a)
-{
- if (a.tv_usec >= ONE_MILLION) {
- ast_log(LOG_WARNING, "warning too large timestamp %ld.%ld\n",
- a.tv_sec, (long int) a.tv_usec);
- a.tv_sec += a.tv_usec / ONE_MILLION;
- a.tv_usec %= ONE_MILLION;
- } else if (a.tv_usec < 0) {
- ast_log(LOG_WARNING, "warning negative timestamp %ld.%ld\n",
- a.tv_sec, (long int) a.tv_usec);
- a.tv_usec = 0;
- }
- return a;
-}
-
-struct timeval ast_tvadd(struct timeval a, struct timeval b)
-{
- /* consistency checks to guarantee usec in 0..999999 */
- a = tvfix(a);
- b = tvfix(b);
- a.tv_sec += b.tv_sec;
- a.tv_usec += b.tv_usec;
- if (a.tv_usec >= ONE_MILLION) {
- a.tv_sec++;
- a.tv_usec -= ONE_MILLION;
- }
- return a;
-}
-
-struct timeval ast_tvsub(struct timeval a, struct timeval b)
-{
- /* consistency checks to guarantee usec in 0..999999 */
- a = tvfix(a);
- b = tvfix(b);
- a.tv_sec -= b.tv_sec;
- a.tv_usec -= b.tv_usec;
- if (a.tv_usec < 0) {
- a.tv_sec-- ;
- a.tv_usec += ONE_MILLION;
- }
- return a;
-}
-#undef ONE_MILLION
-
-#ifndef HAVE_STRCASESTR
-static char *upper(const char *orig, char *buf, int bufsize)
-{
- int i = 0;
-
- while (i < (bufsize - 1) && orig[i]) {
- buf[i] = toupper(orig[i]);
- i++;
- }
-
- buf[i] = '\0';
-
- return buf;
-}
-
-char *strcasestr(const char *haystack, const char *needle)
-{
- char *u1, *u2;
- int u1len = strlen(haystack) + 1, u2len = strlen(needle) + 1;
-
- u1 = alloca(u1len);
- u2 = alloca(u2len);
- if (u1 && u2) {
- char *offset;
- if (u2len > u1len) {
- /* Needle bigger than haystack */
- return NULL;
- }
- offset = strstr(upper(haystack, u1, u1len), upper(needle, u2, u2len));
- if (offset) {
- /* Return the offset into the original string */
- return ((char *)((unsigned long)haystack + (unsigned long)(offset - u1)));
- } else {
- return NULL;
- }
- } else {
- ast_log(LOG_ERROR, "Out of memory\n");
- return NULL;
- }
-}
-#endif /* !HAVE_STRCASESTR */
-
-#ifndef HAVE_STRNLEN
-size_t strnlen(const char *s, size_t n)
-{
- size_t len;
-
- for (len=0; len < n; len++)
- if (s[len] == '\0')
- break;
-
- return len;
-}
-#endif /* !HAVE_STRNLEN */
-
-#if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)
-char *strndup(const char *s, size_t n)
-{
- size_t len = strnlen(s, n);
- char *new = malloc(len + 1);
-
- if (!new)
- return NULL;
-
- new[len] = '\0';
- return memcpy(new, s, len);
-}
-#endif /* !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC) */
-
-#if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)
-int vasprintf(char **strp, const char *fmt, va_list ap)
-{
- int size;
- va_list ap2;
- char s;
-
- *strp = NULL;
- va_copy(ap2, ap);
- size = vsnprintf(&s, 1, fmt, ap2);
- va_end(ap2);
- *strp = malloc(size + 1);
- if (!*strp)
- return -1;
- vsnprintf(*strp, size + 1, fmt, ap);
-
- return size;
-}
-#endif /* !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC) */
-
-#ifndef HAVE_STRTOQ
-#ifndef LONG_MIN
-#define LONG_MIN (-9223372036854775807L-1L)
- /* min value of a "long int" */
-#endif
-#ifndef LONG_MAX
-#define LONG_MAX 9223372036854775807L
- /* max value of a "long int" */
-#endif
-
-/*
- * Convert a string to a quad integer.
- *
- * Ignores `locale' stuff. Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-uint64_t strtoq(const char *nptr, char **endptr, int base)
-{
- const char *s;
- uint64_t acc;
- unsigned char c;
- uint64_t qbase, cutoff;
- int neg, any, cutlim;
-
- /*
- * Skip white space and pick up leading +/- sign if any.
- * If base is 0, allow 0x for hex and 0 for octal, else
- * assume decimal; if base is already 16, allow 0x.
- */
- s = nptr;
- do {
- c = *s++;
- } while (isspace(c));
- if (c == '-') {
- neg = 1;
- c = *s++;
- } else {
- neg = 0;
- if (c == '+')
- c = *s++;
- }
- if ((base == 0 || base == 16) &&
- c == '\0' && (*s == 'x' || *s == 'X')) {
- c = s[1];
- s += 2;
- base = 16;
- }
- if (base == 0)
- base = c == '\0' ? 8 : 10;
-
- /*
- * Compute the cutoff value between legal numbers and illegal
- * numbers. That is the largest legal value, divided by the
- * base. An input number that is greater than this value, if
- * followed by a legal input character, is too big. One that
- * is equal to this value may be valid or not; the limit
- * between valid and invalid numbers is then based on the last
- * digit. For instance, if the range for quads is
- * [-9223372036854775808..9223372036854775807] and the input base
- * is 10, cutoff will be set to 922337203685477580 and cutlim to
- * either 7 (neg==0) or 8 (neg==1), meaning that if we have
- * accumulated a value > 922337203685477580, or equal but the
- * next digit is > 7 (or 8), the number is too big, and we will
- * return a range error.
- *
- * Set any if any `digits' consumed; make it negative to indicate
- * overflow.
- */
- qbase = (unsigned)base;
- cutoff = neg ? (uint64_t)-(LONG_MIN + LONG_MAX) + LONG_MAX : LONG_MAX;
- cutlim = cutoff % qbase;
- cutoff /= qbase;
- for (acc = 0, any = 0;; c = *s++) {
- if (!isascii(c))
- break;
- if (isdigit(c))
- c -= '\0';
- else if (isalpha(c))
- c -= isupper(c) ? 'A' - 10 : 'a' - 10;
- else
- break;
- if (c >= base)
- break;
- if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
- any = -1;
- else {
- any = 1;
- acc *= qbase;
- acc += c;
- }
- }
- if (any < 0) {
- acc = neg ? LONG_MIN : LONG_MAX;
- } else if (neg)
- acc = -acc;
- if (endptr != 0)
- *((const char **)endptr) = any ? s - 1 : nptr;
- return acc;
-}
-#endif /* !HAVE_STRTOQ */
-
-#ifndef HAVE_GETLOADAVG
-#ifdef linux
-/* Alternative method of getting load avg on Linux only */
-int getloadavg(double *list, int nelem)
-{
- FILE *LOADAVG;
- double avg[3] = { 0.0, 0.0, 0.0 };
- int i, res = -1;
-
- if ((LOADAVG = fopen("/proc/loadavg", "r"))) {
- fscanf(LOADAVG, "%lf %lf %lf", &avg[0], &avg[1], &avg[2]);
- res = 0;
- fclose(LOADAVG);
- }
-
- for (i = 0; (i < nelem) && (i < 3); i++) {
- list[i] = avg[i];
- }
-
- return res;
-}
-#else /* !linux */
-/* Return something that won't cancel the call, but still return -1, in case
- * we correct the implementation to check return value */
-int getloadavg(double *list, int nelem)
-{
- int i;
-
- for (i = 0; i < nelem; i++) {
- list[i] = 0.1;
- }
- return -1;
-}
-#endif /* linux */
-#endif /* !defined(_BSD_SOURCE) */
-
-char *ast_process_quotes_and_slashes(char *start, char find, char replace_with)
-{
- char *dataPut = start;
- int inEscape = 0;
- int inQuotes = 0;
-
- for (; *start; start++) {
- if (inEscape) {
- *dataPut++ = *start; /* Always goes verbatim */
- inEscape = 0;
- } else {
- if (*start == '\\') {
- inEscape = 1; /* Do not copy \ into the data */
- } else if (*start == '\'') {
- inQuotes = 1-inQuotes; /* Do not copy ' into the data */
- } else {
- /* Replace , with |, unless in quotes */
- *dataPut++ = inQuotes ? *start : ((*start==find) ? replace_with : *start);
- }
- }
- }
- if (start != dataPut)
- *dataPut = 0;
- return dataPut;
-}
diff --git a/1.2-netsec/utils/Makefile b/1.2-netsec/utils/Makefile
deleted file mode 100644
index a07a39da7..000000000
--- a/1.2-netsec/utils/Makefile
+++ /dev/null
@@ -1,80 +0,0 @@
-#
-# Asterisk -- A telephony toolkit for Linux.
-#
-# Various utilities
-#
-# Copyright (C) 1999-2005, Digium
-#
-# Mark Spencer <markster@digium.com>
-#
-# This program is free software, distributed under the terms of
-# the GNU General Public License
-#
-
-#
-# Don't use ast mm routines
-#
-CFLAGS+=-DNO_AST_MM
-
-ifeq ($(findstring BSD,${OSARCH}),BSD)
- CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
-endif
-
-TARGET=stereorize streamplayer
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/popt.h)$(wildcard -f $(CROSS_COMPILE_TARGET)/usr/local/include/popt.h),)
- TARGET+=smsq
-endif
-
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/newt.h)$(wildcard -f $(CROSS_COMPILE_TARGET)/usr/local/include/newt.h),)
- TARGET+=astman
-endif
-
-ifeq (${OSARCH},SunOS)
- SOL=../strcompat.o
- SOLLIBS=-lsocket -lnsl
-endif
-
-all: depend $(TARGET)
-
-install:
- for x in $(TARGET); do \
- if [ "$$x" != "none" ]; then \
- $(INSTALL) -m 755 $$x $(DESTDIR)$(ASTSBINDIR)/$$x; \
- fi; \
- done
-
-clean:
- rm -f *.o astman smsq stereorize streamplayer check_expr .depend
- rm -f ast_expr2.o ast_expr2f.o
-
-astman: astman.o ../md5.o
- $(CC) $(CFLAGS) -o astman astman.o ../md5.o -lnewt
-
-stereorize: stereorize.o frame.o
- $(CC) $(CFLAGS) -o stereorize stereorize.o frame.o -lm
-
-ast_expr2.o: ../ast_expr2.c
- gcc -g -c -o $@ $<
-
-ast_expr2f.o: ../ast_expr2f.c
- gcc -g -c -DSTANDALONE -o $@ $<
-
-check_expr: check_expr.c ast_expr2.o ast_expr2f.o
- $(CC) $(CFLAGS) -o $@ $^
-
-smsq: smsq.o
- $(CC) $(CFLAGS) -o smsq ${SOL} smsq.o -lpopt
-
-streamplayer: streamplayer.o
- $(CC) $(CFLAGS) -o streamplayer ${SOL} streamplayer.o ${SOLLIBS}
-
-ifneq ($(wildcard .depend),)
- include .depend
-endif
-
-depend: .depend
-
-.depend:
- ../build_tools/mkdep $(CFLAGS) `ls *.c`
-
diff --git a/1.2-netsec/utils/astman.1 b/1.2-netsec/utils/astman.1
deleted file mode 100644
index 6a36ca4da..000000000
--- a/1.2-netsec/utils/astman.1
+++ /dev/null
@@ -1,102 +0,0 @@
-.\" $Header$
-.\"
-.\" transcript compatibility for postscript use.
-.\"
-.\" synopsis: .P! <file.ps>
-.\"
-.de P!
-.fl
-\!!1 setgray
-.fl
-\\&.\"
-.fl
-\!!0 setgray
-.fl \" force out current output buffer
-\!!save /psv exch def currentpoint translate 0 0 moveto
-\!!/showpage{}def
-.fl \" prolog
-.sy sed \-e 's/^/!/' \\$1\" bring in postscript file
-\!!psv restore
-.
-.de pF
-.ie \\*(f1 .ds f1 \\n(.f
-.el .ie \\*(f2 .ds f2 \\n(.f
-.el .ie \\*(f3 .ds f3 \\n(.f
-.el .ie \\*(f4 .ds f4 \\n(.f
-.el .tm ? font overflow
-.ft \\$1
-..
-.de fP
-.ie !\\*(f4 \{\
-. ft \\*(f4
-. ds f4\"
-' br \}
-.el .ie !\\*(f3 \{\
-. ft \\*(f3
-. ds f3\"
-' br \}
-.el .ie !\\*(f2 \{\
-. ft \\*(f2
-. ds f2\"
-' br \}
-.el .ie !\\*(f1 \{\
-. ft \\*(f1
-. ds f1\"
-' br \}
-.el .tm ? font underflow
-..
-.ds f1\"
-.ds f2\"
-.ds f3\"
-.ds f4\"
-'\" t
-.ta 8n 16n 24n 32n 40n 48n 56n 64n 72n
-.TH ASTMAN 1 "Jun 12th, 2005" "astman" "Linux Programmer's Manual"
-.SH NAME
-.B astman
--- a client to asterisk's manager interface
-.SH SYNOPSIS
-.PP
-.B astman
-.I hostname
-
-.SH DESCRIPTION
-.B astman
-This program is a full-screen (terminal) client for Asterisk's manager
-interface.
-
-.SH OPTIONS
-.B hostname
-
-The host name or IP address to connect to (TCP port 5038). If astman
-fails to connect it will exit immidiately.
-
-.SH USAGE
-If \fBastman\fR has successfully cunnected to the manager port it will
-prompt the user for a username and a secret (password) for the manager
-interface on the remote Asterisk manager interface. It will then be able
-to report existing channels (calls). You will then be able to redirect
-calls to or terminate them.
-
-.SH "SEE ALSO"
-asterisk(8)
-
-http://www.voip-info.org/wiki-Asterisk+astman
-
-.SH BUGS
-The hostname does not default to localhost.
-
-Impossible to use a port other than 5038.
-
-The username and password cannot be defined from the command-line.
-
-I mean, what's the point in a man page if the syntax is so simple?
-
-.SH "AUTHOR"
-This manual page was written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
-Permission is granted to copy, distribute and/or modify this document under
-the terms of the GNU General Public License, Version 2 any
-later version published by the Free Software Foundation.
-
-On Debian systems, the complete text of the GNU General Public
-License can be found in /usr/share/common-licenses/GPL.
diff --git a/1.2-netsec/utils/astman.c b/1.2-netsec/utils/astman.c
deleted file mode 100644
index 1cb2ebab7..000000000
--- a/1.2-netsec/utils/astman.c
+++ /dev/null
@@ -1,720 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
- *
- * ASTerisk MANager
- *
- */
-
-#include <newt.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include "asterisk/md5.h"
-#include "asterisk/manager.h"
-
-#undef gethostbyname
-
-#define MAX_HEADERS 80
-#define MAX_LEN 256
-
-/*
- * 2005.05.27 - different versions of newt define the type of the buffer
- * for the 5th argument to newtEntry() as char ** or const char ** . To
- * let the code compile cleanly with -Werror, we cast it to void * through
- * _NEWT_CAST.
- */
-#define _NEWT_CAST (void *)
-
-static struct ast_mansession {
- struct sockaddr_in sin;
- int fd;
- char inbuf[MAX_LEN];
- int inlen;
-} session;
-
-static struct ast_chan {
- char name[80];
- char exten[20];
- char context[20];
- char priority[20];
- char callerid[40];
- char state[10];
- struct ast_chan *next;
-} *chans;
-
-/* dummy functions to be compatible with the Asterisk core for md5.c */
-void ast_register_file_version(const char *file, const char *version);
-void ast_register_file_version(const char *file, const char *version)
-{
-}
-
-void ast_unregister_file_version(const char *file);
-void ast_unregister_file_version(const char *file)
-{
-}
-
-static struct ast_chan *find_chan(char *name)
-{
- struct ast_chan *prev = NULL, *chan = chans;
- while(chan) {
- if (!strcmp(name, chan->name))
- return chan;
- prev = chan;
- chan = chan->next;
- }
- chan = malloc(sizeof(struct ast_chan));
- if (chan) {
- memset(chan, 0, sizeof(struct ast_chan));
- strncpy(chan->name, name, sizeof(chan->name) - 1);
- if (prev)
- prev->next = chan;
- else
- chans = chan;
- }
- return chan;
-}
-
-static void del_chan(char *name)
-{
- struct ast_chan *prev = NULL, *chan = chans;
- while(chan) {
- if (!strcmp(name, chan->name)) {
- if (prev)
- prev->next = chan->next;
- else
- chans = chan->next;
- free(chan);
- return;
- }
- prev = chan;
- chan = chan->next;
- }
-}
-
-static void fdprintf(int fd, char *fmt, ...)
-{
- char stuff[4096];
- va_list ap;
- va_start(ap, fmt);
- vsnprintf(stuff, sizeof(stuff), fmt, ap);
- va_end(ap);
- write(fd, stuff, strlen(stuff));
-}
-
-static char *get_header(struct message *m, char *var)
-{
- char cmp[80];
- int x;
- snprintf(cmp, sizeof(cmp), "%s: ", var);
- for (x=0;x<m->hdrcount;x++)
- if (!strncasecmp(cmp, m->headers[x], strlen(cmp)))
- return m->headers[x] + strlen(cmp);
- return "";
-}
-
-static int event_newstate(struct ast_mansession *s, struct message *m)
-{
- struct ast_chan *chan;
- chan = find_chan(get_header(m, "Channel"));
- strncpy(chan->state, get_header(m, "State"), sizeof(chan->state) - 1);
- return 0;
-}
-
-static int event_newexten(struct ast_mansession *s, struct message *m)
-{
- struct ast_chan *chan;
- chan = find_chan(get_header(m, "Channel"));
- strncpy(chan->exten, get_header(m, "Extension"), sizeof(chan->exten) - 1);
- strncpy(chan->context, get_header(m, "Context"), sizeof(chan->context) - 1);
- strncpy(chan->priority, get_header(m, "Priority"), sizeof(chan->priority) - 1);
- return 0;
-}
-
-static int event_newchannel(struct ast_mansession *s, struct message *m)
-{
- struct ast_chan *chan;
- chan = find_chan(get_header(m, "Channel"));
- strncpy(chan->state, get_header(m, "State"), sizeof(chan->state) - 1);
- strncpy(chan->callerid, get_header(m, "Callerid"), sizeof(chan->callerid) - 1);
- return 0;
-}
-
-static int event_status(struct ast_mansession *s, struct message *m)
-{
- struct ast_chan *chan;
- chan = find_chan(get_header(m, "Channel"));
- strncpy(chan->state, get_header(m, "State"), sizeof(chan->state) - 1);
- strncpy(chan->callerid, get_header(m, "Callerid"), sizeof(chan->callerid) - 1);
- strncpy(chan->exten, get_header(m, "Extension"), sizeof(chan->exten) - 1);
- strncpy(chan->context, get_header(m, "Context"), sizeof(chan->context) - 1);
- strncpy(chan->priority, get_header(m, "Priority"), sizeof(chan->priority) - 1);
- return 0;
-}
-
-static int event_hangup(struct ast_mansession *s, struct message *m)
-{
- del_chan(get_header(m, "Channel"));
- return 0;
-}
-
-static int event_ignore(struct ast_mansession *s, struct message *m)
-{
- return 0;
-}
-
-static int event_rename(struct ast_mansession *s, struct message *m)
-{
- struct ast_chan *chan;
- chan = find_chan(get_header(m, "Oldname"));
- strncpy(chan->name, get_header(m, "Newname"), sizeof(chan->name) - 1);
- return 0;
-}
-static struct event {
- char *event;
- int (*func)(struct ast_mansession *s, struct message *m);
-} events[] = {
- { "Newstate", event_newstate },
- { "Newchannel", event_newchannel },
- { "Newexten", event_newexten },
- { "Hangup", event_hangup },
- { "Rename", event_rename },
- { "Status", event_status },
- { "Link", event_ignore },
- { "Unlink", event_ignore },
- { "StatusComplete", event_ignore }
-};
-
-static int process_message(struct ast_mansession *s, struct message *m)
-{
- int x;
- char event[80] = "";
- strncpy(event, get_header(m, "Event"), sizeof(event) - 1);
- if (!strlen(event)) {
- fprintf(stderr, "Missing event in request");
- return 0;
- }
- for (x=0;x<sizeof(events) / sizeof(events[0]);x++) {
- if (!strcasecmp(event, events[x].event)) {
- if (events[x].func(s, m))
- return -1;
- break;
- }
- }
- if (x >= sizeof(events) / sizeof(events[0]))
- fprintf(stderr, "Ignoring unknown event '%s'", event);
-#if 0
- for (x=0;x<m->hdrcount;x++) {
- printf("Header: %s\n", m->headers[x]);
- }
-#endif
- return 0;
-}
-
-static void rebuild_channels(newtComponent c)
-{
- void *prev = NULL;
- struct ast_chan *chan;
- char tmpn[42];
- char tmp[256];
- int x=0;
- prev = newtListboxGetCurrent(c);
- newtListboxClear(c);
- chan = chans;
- while(chan) {
- snprintf(tmpn, sizeof(tmpn), "%s (%s)", chan->name, chan->callerid);
- if (strlen(chan->exten))
- snprintf(tmp, sizeof(tmp), "%-30s %8s -> %s@%s:%s",
- tmpn, chan->state,
- chan->exten, chan->context, chan->priority);
- else
- snprintf(tmp, sizeof(tmp), "%-30s %8s",
- tmpn, chan->state);
- newtListboxAppendEntry(c, tmp, chan);
- x++;
- chan = chan->next;
- }
- if (!x)
- newtListboxAppendEntry(c, " << No Active Channels >> ", NULL);
- newtListboxSetCurrentByKey(c, prev);
-}
-
-static int has_input(struct ast_mansession *s)
-{
- int x;
- for (x=1;x<s->inlen;x++)
- if ((s->inbuf[x] == '\n') && (s->inbuf[x-1] == '\r'))
- return 1;
- return 0;
-}
-
-static int get_input(struct ast_mansession *s, char *output)
-{
- /* output must have at least sizeof(s->inbuf) space */
- int res;
- int x;
- struct timeval tv = {0, 0};
- fd_set fds;
- for (x=1;x<s->inlen;x++) {
- if ((s->inbuf[x] == '\n') && (s->inbuf[x-1] == '\r')) {
- /* Copy output data up to and including \r\n */
- memcpy(output, s->inbuf, x + 1);
- /* Add trailing \0 */
- output[x+1] = '\0';
- /* Move remaining data back to the front */
- memmove(s->inbuf, s->inbuf + x + 1, s->inlen - x);
- s->inlen -= (x + 1);
- return 1;
- }
- }
- if (s->inlen >= sizeof(s->inbuf) - 1) {
- fprintf(stderr, "Dumping long line with no return from %s: %s\n", inet_ntoa(s->sin.sin_addr), s->inbuf);
- s->inlen = 0;
- }
- FD_ZERO(&fds);
- FD_SET(s->fd, &fds);
- res = select(s->fd + 1, &fds, NULL, NULL, &tv);
- if (res < 0) {
- fprintf(stderr, "Select returned error: %s\n", strerror(errno));
- } else if (res > 0) {
- res = read(s->fd, s->inbuf + s->inlen, sizeof(s->inbuf) - 1 - s->inlen);
- if (res < 1)
- return -1;
- s->inlen += res;
- s->inbuf[s->inlen] = '\0';
- } else {
- return 2;
- }
- return 0;
-}
-
-static int input_check(struct ast_mansession *s, struct message **mout)
-{
- static struct message m;
- int res;
-
- if (mout)
- *mout = NULL;
-
- for(;;) {
- res = get_input(s, m.headers[m.hdrcount]);
- if (res == 1) {
-#if 0
- fprintf(stderr, "Got header: %s", m.headers[m.hdrcount]);
- fgetc(stdin);
-#endif
- /* Strip trailing \r\n */
- if (strlen(m.headers[m.hdrcount]) < 2)
- continue;
- m.headers[m.hdrcount][strlen(m.headers[m.hdrcount]) - 2] = '\0';
- if (!strlen(m.headers[m.hdrcount])) {
- if (mout && strlen(get_header(&m, "Response"))) {
- *mout = &m;
- return 0;
- }
- if (process_message(s, &m))
- break;
- memset(&m, 0, sizeof(&m));
- } else if (m.hdrcount < MAX_HEADERS - 1)
- m.hdrcount++;
- } else if (res < 0) {
- return -1;
- } else if (res == 2)
- return 0;
- }
- return -1;
-}
-
-static struct message *wait_for_response(int timeout)
-{
- struct message *m;
- struct timeval tv;
- int res;
- fd_set fds;
- for (;;) {
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
- FD_SET(session.fd, &fds);
- res = select(session.fd + 1, &fds, NULL, NULL, &tv);
- if (res < 1)
- break;
- if (input_check(&session, &m) < 0) {
- return NULL;
- }
- if (m)
- return m;
- }
- return NULL;
-}
-
-static int manager_action(char *action, char *fmt, ...)
-{
- struct ast_mansession *s;
- char tmp[4096];
- va_list ap;
-
- s = &session;
- fdprintf(s->fd, "Action: %s\r\n", action);
- va_start(ap, fmt);
- vsnprintf(tmp, sizeof(tmp), fmt, ap);
- va_end(ap);
- write(s->fd, tmp, strlen(tmp));
- fdprintf(s->fd, "\r\n");
- return 0;
-}
-
-static int show_message(char *title, char *msg)
-{
- newtComponent form;
- newtComponent label;
- newtComponent ok;
- struct newtExitStruct es;
-
- newtCenteredWindow(60,7, title);
-
- label = newtLabel(4,1,msg);
- ok = newtButton(27, 3, "OK");
- form = newtForm(NULL, NULL, 0);
- newtFormAddComponents(form, label, ok, NULL);
- newtFormRun(form, &es);
- newtPopWindow();
- newtFormDestroy(form);
- return 0;
-}
-
-static newtComponent showform;
-static int show_doing(char *title, char *tmp)
-{
- struct newtExitStruct es;
- newtComponent label;
- showform = newtForm(NULL, NULL, 0);
- newtCenteredWindow(70,4, title);
- label = newtLabel(3,1,tmp);
- newtFormAddComponents(showform,label, NULL);
- newtFormSetTimer(showform, 200);
- newtFormRun(showform, &es);
- return 0;
-}
-
-static int hide_doing(void)
-{
- newtPopWindow();
- newtFormDestroy(showform);
- return 0;
-}
-
-static void try_status(void)
-{
- struct message *m;
- manager_action("Status", "");
- m = wait_for_response(10000);
- if (!m) {
- show_message("Status Failed", "Timeout waiting for response");
- } else if (strcasecmp(get_header(m, "Response"), "Success")) {
- show_message("Status Failed Failed", get_header(m, "Message"));
- }
-}
-
-
-static void try_hangup(newtComponent c)
-{
- struct ast_chan *chan;
- struct message *m;
-
- chan = newtListboxGetCurrent(c);
- if (chan) {
- manager_action("Hangup", "Channel: %s\r\n", chan->name);
- m = wait_for_response(10000);
- if (!m) {
- show_message("Hangup Failed", "Timeout waiting for response");
- } else if (strcasecmp(get_header(m, "Response"), "Success")) {
- show_message("Hangup Failed", get_header(m, "Message"));
- }
- }
-
-}
-
-static int get_user_input(char *msg, char *buf, int buflen)
-{
- newtComponent form;
- newtComponent ok;
- newtComponent cancel;
- newtComponent inpfield;
- const char *input;
- int res = -1;
- struct newtExitStruct es;
-
- newtCenteredWindow(60,7, msg);
-
- inpfield = newtEntry(5, 2, "", 50, _NEWT_CAST &input, 0);
- ok = newtButton(22, 3, "OK");
- cancel = newtButton(32, 3, "Cancel");
- form = newtForm(NULL, NULL, 0);
- newtFormAddComponents(form, inpfield, ok, cancel, NULL);
- newtFormRun(form, &es);
- strncpy(buf, input, buflen - 1);
- if (es.u.co == ok)
- res = 0;
- else
- res = -1;
- newtPopWindow();
- newtFormDestroy(form);
- return res;
-}
-
-static void try_redirect(newtComponent c)
-{
- struct ast_chan *chan;
- char dest[256];
- struct message *m;
- char channame[256];
- char tmp[80];
- char *context;
-
- chan = newtListboxGetCurrent(c);
- if (chan) {
- strncpy(channame, chan->name, sizeof(channame) - 1);
- snprintf(tmp, sizeof(tmp), "Enter new extension for %s", channame);
- if (get_user_input(tmp, dest, sizeof(dest)))
- return;
- if ((context = strchr(dest, '@'))) {
- *context = '\0';
- context++;
- manager_action("Redirect", "Channel: %s\r\nContext: %s\r\nExten: %s\r\nPriority: 1\r\n", chan->name,context,dest);
- } else {
- manager_action("Redirect", "Channel: %s\r\nExten: %s\r\nPriority: 1\r\n", chan->name, dest);
- }
- m = wait_for_response(10000);
- if (!m) {
- show_message("Hangup Failed", "Timeout waiting for response");
- } else if (strcasecmp(get_header(m, "Response"), "Success")) {
- show_message("Hangup Failed", get_header(m, "Message"));
- }
- }
-
-}
-
-static int manage_calls(char *host)
-{
- newtComponent form;
- newtComponent quit;
- newtComponent hangup;
- newtComponent redirect;
- newtComponent channels;
- struct newtExitStruct es;
- char tmp[80];
-
- /* If there's one thing you learn from this code, it is this...
- Never, ever fly Air France. Their customer service is absolutely
- the worst. I've never heard the words "That's not my problem" as
- many times as I have from their staff -- It should, without doubt
- be their corporate motto if it isn't already. Don't bother giving
- them business because you're just a pain in their side and they
- will be sure to let you know the first time you speak to them.
-
- If you ever want to make me happy just tell me that you, too, will
- never fly Air France again either (in spite of their excellent
- cuisine). */
- snprintf(tmp, sizeof(tmp), "Asterisk Manager at %s", host);
- newtCenteredWindow(74, 20, tmp);
- form = newtForm(NULL, NULL, 0);
- newtFormWatchFd(form, session.fd, NEWT_FD_READ);
- newtFormSetTimer(form, 100);
- quit = newtButton(62, 16, "Quit");
- redirect = newtButton(35, 16, "Redirect");
- hangup = newtButton(50, 16, "Hangup");
- channels = newtListbox(1,1,14, NEWT_FLAG_SCROLL);
- newtFormAddComponents(form, channels, redirect, hangup, quit, NULL);
- newtListboxSetWidth(channels, 72);
-
- show_doing("Getting Status", "Retrieving system status...");
- try_status();
- hide_doing();
-
- for(;;) {
- newtFormRun(form, &es);
- if (has_input(&session) || (es.reason == NEWT_EXIT_FDREADY)) {
- if (input_check(&session, NULL)) {
- show_message("Disconnected", "Disconnected from remote host");
- break;
- }
- } else if (es.reason == NEWT_EXIT_COMPONENT) {
- if (es.u.co == quit)
- break;
- if (es.u.co == hangup) {
- try_hangup(channels);
- } else if (es.u.co == redirect) {
- try_redirect(channels);
- }
- }
- rebuild_channels(channels);
- }
- newtFormDestroy(form);
- return 0;
-}
-
-static int login(char *hostname)
-{
- newtComponent form;
- newtComponent cancel;
- newtComponent login;
- newtComponent username;
- newtComponent password;
- newtComponent label;
- newtComponent ulabel;
- newtComponent plabel;
- const char *user;
- const char *pass;
- struct message *m;
- struct newtExitStruct es;
- char tmp[55];
- struct hostent *hp;
- int res = -1;
-
- session.fd = socket(AF_INET, SOCK_STREAM, 0);
- if (session.fd < 0) {
- snprintf(tmp, sizeof(tmp), "socket() failed: %s\n", strerror(errno));
- show_message("Socket failed", tmp);
- return -1;
- }
-
- snprintf(tmp, sizeof(tmp), "Looking up %s\n", hostname);
- show_doing("Connecting....", tmp);
-
-
- hp = gethostbyname(hostname);
- if (!hp) {
- snprintf(tmp, sizeof(tmp), "No such address: %s\n", hostname);
- show_message("Host lookup failed", tmp);
- return -1;
- }
- hide_doing();
- snprintf(tmp, sizeof(tmp), "Connecting to %s", hostname);
- show_doing("Connecting...", tmp);
-
- session.sin.sin_family = AF_INET;
- session.sin.sin_port = htons(DEFAULT_MANAGER_PORT);
- memcpy(&session.sin.sin_addr, hp->h_addr, sizeof(session.sin.sin_addr));
-
- if (connect(session.fd,(struct sockaddr*)&session.sin, sizeof(session.sin))) {
- snprintf(tmp, sizeof(tmp), "%s failed: %s\n", hostname, strerror(errno));
- show_message("Connect Failed", tmp);
- return -1;
- }
-
- hide_doing();
-
- login = newtButton(5, 6, "Login");
- cancel = newtButton(25, 6, "Cancel");
- newtCenteredWindow(40, 10, "Asterisk Manager Login");
- snprintf(tmp, sizeof(tmp), "Host: %s", hostname);
- label = newtLabel(4,1, tmp);
-
- ulabel = newtLabel(4,2,"Username:");
- plabel = newtLabel(4,3,"Password:");
-
- username = newtEntry(14, 2, "", 20, _NEWT_CAST &user, 0);
- password = newtEntry(14, 3, "", 20, _NEWT_CAST &pass, NEWT_FLAG_HIDDEN);
-
- form = newtForm(NULL, NULL, 0);
- newtFormAddComponents(form, username, password, login, cancel, label, ulabel, plabel,NULL);
- newtFormRun(form, &es);
- if (es.reason == NEWT_EXIT_COMPONENT) {
- if (es.u.co == login) {
- snprintf(tmp, sizeof(tmp), "Logging in '%s'...", user);
- show_doing("Logging in", tmp);
- /* Check to see if the remote host supports MD5 Authentication */
- manager_action("Challenge", "AuthType: MD5\r\n");
- m = wait_for_response(10000);
- if (m && !strcasecmp(get_header(m, "Response"), "Success")) {
- char *challenge = get_header(m, "Challenge");
- int x;
- int len = 0;
- char md5key[256] = "";
- struct MD5Context md5;
- unsigned char digest[16];
- MD5Init(&md5);
- MD5Update(&md5, (unsigned char *)challenge, strlen(challenge));
- MD5Update(&md5, (unsigned char *)pass, strlen(pass));
- MD5Final(digest, &md5);
- for (x=0; x<16; x++)
- len += sprintf(md5key + len, "%2.2x", digest[x]);
- manager_action("Login",
- "AuthType: MD5\r\n"
- "Username: %s\r\n"
- "Key: %s\r\n",
- user, md5key);
- m = wait_for_response(10000);
- hide_doing();
- if (!strcasecmp(get_header(m, "Response"), "Success")) {
- res = 0;
- } else {
- show_message("Login Failed", get_header(m, "Message"));
- }
- } else {
- memset(m, 0, sizeof(m));
- manager_action("Login",
- "Username: %s\r\n"
- "Secret: %s\r\n",
- user, pass);
- m = wait_for_response(10000);
- hide_doing();
- if (m) {
- if (!strcasecmp(get_header(m, "Response"), "Success")) {
- res = 0;
- } else {
- show_message("Login Failed", get_header(m, "Message"));
- }
- }
- }
- }
- }
- newtFormDestroy(form);
- return res;
-}
-
-int main(int argc, char *argv[])
-{
- if (argc < 2) {
- fprintf(stderr, "Usage: astman <host>\n");
- exit(1);
- }
- newtInit();
- newtCls();
- newtDrawRootText(0, 0, "Asterisk Manager (C)2002, Linux Support Services, Inc.");
- newtPushHelpLine("Welcome to the Asterisk Manager!");
- if (login(argv[1])) {
- newtFinished();
- exit(1);
- }
- manage_calls(argv[1]);
- newtFinished();
- return 0;
-}
diff --git a/1.2-netsec/utils/check_expr.c b/1.2-netsec/utils/check_expr.c
deleted file mode 100644
index 531af49c0..000000000
--- a/1.2-netsec/utils/check_expr.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#include <stdio.h>
-#include <stddef.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdlib.h>
-#include <../include/asterisk/ast_expr.h>
-
-int global_lineno = 1;
-int global_expr_count = 0;
-int global_expr_max_size = 0;
-int global_expr_tot_size = 0;
-int global_warn_count = 0;
-int global_OK_count = 0;
-
-struct varz
-{
- char varname[100]; /* a really ultra-simple, space-wasting linked list of var=val data */
- char varval[1000]; /* if any varname is bigger than 100 chars, or val greater than 1000, then **CRASH** */
- struct varz *next;
-};
-
-struct varz *global_varlist;
-
-/* Our own version of ast_log, since the expr parser uses it. */
-
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
-
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
-{
- va_list vars;
- va_start(vars,fmt);
-
- printf("LOG: lev:%d file:%s line:%d func: %s ",
- level, file, line, function);
- vprintf(fmt, vars);
- fflush(stdout);
- va_end(vars);
-}
-
-char *find_var(const char *varname) /* the list should be pretty short, if there's any list at all */
-{
- struct varz *t;
- for (t= global_varlist; t; t = t->next) {
- if (!strcmp(t->varname, varname)) {
- return t->varval;
- }
- }
- return 0;
-}
-
-void set_var(const char *varname, const char *varval)
-{
- struct varz *t = calloc(1,sizeof(struct varz));
- strcpy(t->varname, varname);
- strcpy(t->varval, varval);
- t->next = global_varlist;
- global_varlist = t;
-}
-
-int check_expr(char *buffer, char *error_report)
-{
- char *cp;
- int oplen = 0;
- int warn_found = 0;
-
- error_report[0] = 0;
-
- for (cp=buffer;*cp;cp++) {
-
- if (*cp == '|'
- || *cp == '&'
- || *cp == '='
- || *cp == '>'
- || *cp == '<'
- || *cp == '+'
- || *cp == '-'
- || *cp == '*'
- || *cp == '/'
- || *cp == '%'
- || *cp == '?'
- || *cp == ':'
- /* || *cp == '('
- || *cp == ')' These are pretty hard to track, as they are in funcalls, etc. */
- || *cp == '"') {
- if (*cp == '"') {
- /* skip to the other end */
- cp++;
- while (*cp && *cp != '"')
- cp++;
- if (*cp == 0) {
- fprintf(stderr,"Trouble? Unterminated double quote found at line %d\n",
- global_lineno);
- }
- }
- else {
- if ((*cp == '>'||*cp == '<' ||*cp=='!') && (*(cp+1) == '=')) {
- oplen = 2;
- }
- else {
- oplen = 1;
- }
-
- if ((cp > buffer && *(cp-1) != ' ') || *(cp+oplen) != ' ') {
- char tbuf[1000];
- if (oplen == 1)
- sprintf(tbuf,"WARNING: line %d, '%c' operator not separated by spaces. This may lead to confusion. You may wish to use double quotes to quote the grouping it is in. Please check!\n",
- global_lineno, *cp);
- else
- sprintf(tbuf,"WARNING: line %d, '%c%c' operator not separated by spaces. This may lead to confusion. You may wish to use double quotes to quote the grouping it is in. Please check!\n",
- global_lineno, *cp, *(cp+1));
- strcat(error_report,tbuf);
-
- global_warn_count++;
- warn_found++;
- }
- }
- }
- }
- return warn_found;
-}
-
-int check_eval(char *buffer, char *error_report)
-{
- char *cp, *ep, *xp;
- char s[4096];
- char evalbuf[80000];
- int oplen = 0;
- int warn_found = 0;
- int result;
-
- error_report[0] = 0;
- ep = evalbuf;
-
- for (cp=buffer;*cp;cp++) {
- if (*cp == '$' && *(cp+1) == '{') {
- int brack_lev = 1;
- char *xp= cp+2;
-
- while (*xp) {
- if (*xp == '{')
- brack_lev++;
- else if (*xp == '}')
- brack_lev--;
-
- if (brack_lev == 0)
- break;
- xp++;
- }
- if (*xp == '}') {
- char varname[200];
- char *val;
-
- strncpy(varname,cp+2, xp-cp-2);
- varname[xp-cp-2] = 0;
- cp = xp;
- val = find_var(varname);
- if (val) {
- char *z = val;
- while (*z)
- *ep++ = *z++;
- }
- else {
- *ep++ = '5'; /* why not */
- *ep++ = '5';
- *ep++ = '5';
- }
- }
- else {
- printf("Unterminated variable reference at line %d\n", global_lineno);
- *ep++ = *cp;
- }
- }
- else if (*cp == '\\') {
- /* braindead simple elim of backslash */
- cp++;
- *ep++ = *cp;
- }
- else
- *ep++ = *cp;
- }
- *ep++ = 0;
-
- /* now, run the test */
- result = ast_expr(evalbuf, s, sizeof(s));
- if (result) {
- sprintf(error_report,"line %d, evaluation of $[ %s ] result: %s\n", global_lineno, evalbuf, s);
- return 1;
- } else {
- sprintf(error_report,"line %d, evaluation of $[ %s ] result: ****SYNTAX ERROR****\n", global_lineno, evalbuf);
- return 1;
- }
-}
-
-
-void parse_file(const char *fname)
-{
- FILE *f = fopen(fname,"r");
- FILE *l = fopen("expr2_log","w");
- int c1;
- char last_char= 0;
- char buffer[30000]; /* I sure hope no expr gets this big! */
-
- if (!f) {
- fprintf(stderr,"Couldn't open %s for reading... need an extensions.conf file to parse!\n");
- exit(20);
- }
- if (!l) {
- fprintf(stderr,"Couldn't open 'expr2_log' file for writing... please fix and re-run!\n");
- exit(21);
- }
-
- global_lineno = 1;
-
- while ((c1 = fgetc(f)) != EOF) {
- if (c1 == '\n')
- global_lineno++;
- else if (c1 == '[') {
- if (last_char == '$') {
- /* bingo, an expr */
- int bracklev = 1;
- int bufcount = 0;
- int retval;
- char error_report[30000];
-
- while ((c1 = fgetc(f)) != EOF) {
- if (c1 == '[')
- bracklev++;
- else if (c1 == ']')
- bracklev--;
- if (c1 == '\n') {
- fprintf(l, "ERROR-- A newline in an expression? Weird! ...at line %d\n", global_lineno);
- fclose(f);
- fclose(l);
- printf("--- ERROR --- A newline in the middle of an expression at line %d!\n", global_lineno);
- }
-
- if (bracklev == 0)
- break;
- buffer[bufcount++] = c1;
- }
- if (c1 == EOF) {
- fprintf(l, "ERROR-- End of File Reached in the middle of an Expr at line %d\n", global_lineno);
- fclose(f);
- fclose(l);
- printf("--- ERROR --- EOF reached in middle of an expression at line %d!\n", global_lineno);
- exit(22);
- }
-
- buffer[bufcount] = 0;
- /* update stats */
- global_expr_tot_size += bufcount;
- global_expr_count++;
- if (bufcount > global_expr_max_size)
- global_expr_max_size = bufcount;
-
- retval = check_expr(buffer, error_report); /* check_expr should bump the warning counter */
- if (retval != 0) {
- /* print error report */
- printf("Warning(s) at line %d, expression: $[%s]; see expr2_log file for details\n",
- global_lineno, buffer);
- fprintf(l, "%s", error_report);
- }
- else {
- printf("OK -- $[%s] at line %d\n", buffer, global_lineno);
- global_OK_count++;
- }
- error_report[0] = 0;
- retval = check_eval(buffer, error_report);
- fprintf(l, "%s", error_report);
- }
- }
- last_char = c1;
- }
- printf("Summary:\n Expressions detected: %d\n Expressions OK: %d\n Total # Warnings: %d\n Longest Expr: %d chars\n Ave expr len: %d chars\n",
- global_expr_count,
- global_OK_count,
- global_warn_count,
- global_expr_max_size,
- (global_expr_count) ? global_expr_tot_size/global_expr_count : 0);
-
- fclose(f);
- fclose(l);
-}
-
-
-main(int argc,char **argv)
-{
- int argc1;
- char *eq;
-
- if (argc < 2) {
- printf("Hey-- give me a path to an extensions.conf file!\n");
- exit(19);
- }
- global_varlist = 0;
- for (argc1=2;argc1 < argc; argc1++) {
- if ((eq = strchr(argv[argc1],'='))) {
- *eq = 0;
- set_var(argv[argc1],eq+1);
- }
- }
-
- /* parse command args for x=y and set varz */
-
- parse_file(argv[1]);
-}
diff --git a/1.2-netsec/utils/frame.c b/1.2-netsec/utils/frame.c
deleted file mode 100644
index 7fdb1637d..000000000
--- a/1.2-netsec/utils/frame.c
+++ /dev/null
@@ -1,1034 +0,0 @@
-/****************************************************************************
- *
- * Programs for processing sound files in raw- or WAV-format.
- * -- Useful functions for parsing command line options and
- * issuing errors, warnings, and chit chat.
- *
- * Name: frame.c
- * Version: see static char *standardversion, below.
- * Author: Mark Roberts <mark@manumark.de>
- * Michael Labuschke <michael@labuschke.de> sys_errlist fixes
- *
- ****************************************************************************/
-/****************************************************************************
- * These are useful functions that all DSP programs might find handy
- ****************************************************************************/
-
-#include <stdio.h>
-#include <math.h>
-#include <stdlib.h> /* for exit and malloc */
-#include <string.h>
-#include <time.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <assert.h>
-#include "frame.h"
-
-time_t stopwatch; /* will hold time at start of calculation */
-int samplefrequency;
-unsigned short samplewidth;
-unsigned short channels;
-int wavout; /* TRUE iff out file should be a .WAV file */
-int iswav; /* TRUE iff in file was found to be a .WAV file */
-FILE *in, *out;
-char *infilename, *outfilename;
-int verboselevel;
-char *version = "";
-char *usage = "";
-static int test_usage;
-
-static char *standardversion = "frame version 1.3, June 13th 2001";
-static char *standardusage =
-"\nOptions common to all mark-dsp programs:\n"
-
-"-h \t\t create a WAV-header on output files.\n"
-"-c#\t\t set number of channels to # (1 or 2). Default: like input.\n"
-"-w#\t\t set number of bits per sample (width) to # (only 16)\n"
-"-f#\t\t set sample frequency to #. Default: like input.\n"
-"-V \t\t verbose: talk a lot.\n"
-"-Q \t\t quiet: talk as little as possible.\n\n"
-"In most cases, a filename of '-' means stdin or stdout.\n\n"
-"Bug-reports: mark@manumark.de\n"
-;
-
-/* -----------------------------------------------------------------------
- Writes the number of samples to result that are yet to be read from anyin.
- Return values are TRUE on success, FALSE on failure.
- -----------------------------------------------------------------------*/
-int getremainingfilelength( FILE *anyin, long *result)
-{
- long i;
-
- i = ftell (anyin);
- if (i == -1) return FALSE;
- if (fseek (anyin, 0, SEEK_END) == -1) return FALSE;
- *result = ftell (anyin);
- if (*result == -1) return FALSE;
- (*result) -= i;
- (*result) /= samplewidth;
- if (fseek (anyin, i, SEEK_SET) == -1) return FALSE;
- return TRUE;
-}
-
-/* -----------------------------------------------------------------------
- Read a .pk-header from 'anyin'.
- -----------------------------------------------------------------------*/
-void readpkheader( FILE *anyin)
-{
- unsigned short tempushort;
- int tempint, i, x;
- unsigned char blood[8];
-
- for (i = 0; i < 11; i++)
- {
- fread( &tempint, 4, 1, anyin);
- printf( "%d: %d, ", i, tempint);
- }
- printf( "\n");
- fread( blood, 1, 8, anyin);
- for (i = 0; i < 8; i++)
- printf( "%d ", blood[i]);
- printf( "\n");
- for (i = 0; i < 8; i++)
- {
- for (x = 128; x > 0; x /= 2)
- printf((blood[i] & x) == 0? "0 ":"1 ");
- printf(i%4==3? "\n":"| ");
- }
- printf( "\n");
- for (i = 0; i < 2; i++)
- {
- fread( &tempint, 4, 1, anyin);
- printf( "%d: %d, ", i, tempint);
- }
- printf( "\n");
- for (i = 0; i < 2; i++)
- {
- fread( &tempushort, 2, 1, anyin);
- printf( "%d: %d, ", i, tempushort);
- }
- printf( "\n");
-}
-
-
-
-/* -----------------------------------------------------------------------
- Read a .WAV header from 'anyin'. See header for details.
- -----------------------------------------------------------------------*/
-void readwavheader( FILE *anyin)
-{
- unsigned int tempuint, sf;
- unsigned short tempushort, cn;
- char str[9];
- int nowav = FALSE;
-
- iswav = FALSE;
-
- if (ftell(anyin) == -1) /* If we cannot seek this file */
- {
- nowav = TRUE; /* -> Pretend this is no wav-file */
- chat("File not seekable: not checking for WAV-header.\n");
- }
- else
- {
- /* Expect four bytes "RIFF" and four bytes filelength */
- fread (str, 1, 8, anyin); /* 0 */
- str[4] = '\0';
- if (strcmp(str, "RIFF") != 0) nowav = TRUE;
- /* Expect eight bytes "WAVEfmt " */
- fread (str, 1, 8, anyin); /* 8 */
- str[8] = '\0';
- if (strcmp(str, "WAVEfmt ") != 0) nowav = TRUE;
- /* Expect length of fmt data, which should be 16 */
- fread (&tempuint, 4, 1, anyin); /* 16 */
- if (tempuint != 16) nowav = TRUE;
- /* Expect format tag, which should be 1 for pcm */
- fread (&tempushort, 2, 1, anyin); /* 20 */
- if (tempushort != 1)
- nowav = TRUE;
- /* Expect number of channels */
- fread (&cn, 2, 1, anyin); /* 20 */
- if (cn != 1 && cn != 2) nowav = TRUE;
- /* Read samplefrequency */
- fread (&sf, 4, 1, anyin); /* 24 */
- /* Read bytes per second: Should be samplefreq * channels * 2 */
- fread (&tempuint, 4, 1, anyin); /* 28 */
- if (tempuint != sf * cn * 2) nowav = TRUE;
- /* read bytes per frame: Should be channels * 2 */
- fread (&tempushort, 2, 1, anyin); /* 32 */
- if (tempushort != cn * 2) nowav = TRUE;
- /* Read bits per sample: Should be 16 */
- fread (&tempushort, 2, 1, anyin); /* 34 */
- if (tempushort != 16) nowav = TRUE;
- fread (str, 4, 1, anyin); /* 36 */
- str[4] = '\0';
- if (strcmp(str, "data") != 0) nowav = TRUE;
- fread (&tempuint, 4, 1, anyin); /* 40 */
- if (nowav)
- {
- fseek (anyin, 0, SEEK_SET); /* Back to beginning of file */
- chat("File has no WAV header.\n");
- }
- else
- {
- samplefrequency = sf;
- channels = cn;
- chat ("Read WAV header: %d channels, samplefrequency %d.\n",
- channels, samplefrequency);
- iswav = TRUE;
- }
- }
- return;
-}
-
-
-
-/* -----------------------------------------------------------------------
- Write a .WAV header to 'out'. See header for details.
- -----------------------------------------------------------------------*/
-void makewavheader( void)
-{
- unsigned int tempuint, filelength;
- unsigned short tempushort;
-
- /* If fseek fails, don't create the header. */
- if (fseek (out, 0, SEEK_END) != -1)
- {
- filelength = ftell (out);
- chat ("filelength %d, ", filelength);
- fseek (out, 0, SEEK_SET);
- fwrite ("RIFF", 1, 4, out); /* 0 */
- tempuint = filelength - 8; fwrite (&tempuint, 4, 1, out); /* 4 */
- fwrite ("WAVEfmt ", 1, 8, out); /* 8 */
- /* length of fmt data 16 bytes */
- tempuint = 16;
- fwrite (&tempuint, 4, 1, out); /* 16 */
- /* Format tag: 1 for pcm */
- tempushort = 1;
- fwrite (&tempushort, 2, 1, out); /* 20 */
- chat ("%d channels\n", channels);
- fwrite (&channels, 2, 1, out);
- chat ("samplefrequency %d\n", samplefrequency);
- fwrite (&samplefrequency, 4, 1, out); /* 24 */
- /* Bytes per second */
- tempuint = channels * samplefrequency * 2;
- fwrite (&tempuint, 4, 1, out); /* 28 */
- /* Block align */
- tempushort = 2 * channels;
- fwrite (&tempushort, 2, 1, out); /* 32 */
- /* Bits per sample */
- tempushort = 16;
- fwrite (&tempushort, 2, 1, out); /* 34 */
- fwrite ("data", 4, 1, out); /* 36 */
- tempuint = filelength - 44; fwrite (&tempuint, 4, 1, out); /* 40 */
- }
- return;
-}
-
-/* -----------------------------------------------------------------------
- After all is read and done, inform the inclined user of the elapsed time
- -----------------------------------------------------------------------*/
-static void statistics( void)
-{
- int temp;
-
- temp = time(NULL) - stopwatch;
- if (temp != 1)
- {
- inform ("\nTime: %d seconds\n", temp);
- }
- else
- {
- inform ("\nTime: 1 second\n");
- }
- return;
-}
-
-
-/* -----------------------------------------------------------------------
- Start the stopwatch and make sure the user is informed at end of program.
- -----------------------------------------------------------------------*/
-void startstopwatch(void)
-{
- stopwatch = time(NULL); /* Remember time 'now' */
- atexit(statistics); /* Call function statistics() at exit. */
-
- return;
-}
-
-/* --------------------------------------------------------------------
- Tests the character 'coal' for being a command line option character,
- momentarrily '-'.
- -------------------------------------------------------------------- */
-int isoptionchar (char coal)
-{
- return (coal =='-');
-}
-
-/* -----------------------------------------------------------------------
- Reads through the arguments on the lookout for an option starting
- with 'string'. The rest of the option is read as a time and passed
- to *result, where the result is meant to mean 'number of samples' in
- that time.
- On failure, *result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -----------------------------------------------------------------------*/
-int parsetimearg( int argcount, char *args[], char *string, int *result)
-{
- int i;
-
- if ((i = findoption( argcount, args, string)) > 0)
- {
- if (parsetime(args[i] + 1 + strlen( string), result))
- return TRUE;
- argerrornum(args[i]+1, ME_NOTIME);
- }
- return FALSE;
-}
-
-/* -----------------------------------------------------------------------
- The string argument is read as a time and passed
- to *result, where the result is meant to mean 'number of samples' in
- that time.
- On failure, *result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -----------------------------------------------------------------------*/
-int parsetime(char *string, int *result)
-{
- int k;
- double temp;
- char m, s, end;
-
- k = sscanf(string, "%lf%c%c%c", &temp, &m, &s, &end);
- switch (k)
- {
- case 0: case EOF: case 4:
- return FALSE;
- case 1:
- *result = temp;
- break;
- case 2:
- if (m == 's')
- *result = temp * samplefrequency;
- else
- return FALSE;
- break;
- case 3:
- if (m == 'm' && s == 's')
- *result = temp * samplefrequency / 1000;
- else if (m == 'H' && s == 'z')
- *result = samplefrequency / temp;
- else
- return FALSE;
- break;
- default:
- argerrornum(NULL, ME_THISCANTHAPPEN);
- }
- return TRUE;
-}
-
-/* -----------------------------------------------------------------------
- The string argument is read as a frequency and passed
- to *result, where the result is meant to mean 'number of samples' in
- one cycle of that frequency.
- On failure, *result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -----------------------------------------------------------------------*/
-int parsefreq(char *string, double *result)
-{
- int k;
- double temp;
- char m, s, end;
-
- k = sscanf(string, "%lf%c%c%c", &temp, &m, &s, &end);
- switch (k)
- {
- case 0: case EOF: case 2: case 4:
- return FALSE;
- case 1:
- *result = temp;
- break;
- case 3:
- if (m == 'H' && s == 'z')
- *result = samplefrequency / temp;
- else
- return FALSE;
- break;
- default:
- argerrornum(NULL, ME_THISCANTHAPPEN);
- }
- return TRUE;
-}
-
-char *parsefilearg( int argcount, char *args[])
-{
- int i;
- char *result = NULL;
-
- for (i = 1; i < argcount; i++)
- {
- if (args[i][0] != '\0' &&
- (!isoptionchar (args[i][0]) || args[i][1] == '\0' ))
- {
- /*---------------------------------------------*
- * The argument is a filename: *
- * it is either no dash followed by something, *
- * or it is a dash following by nothing. *
- *---------------------------------------------*/
- result = malloc( strlen( args[i]) + 1);
- if (result == NULL)
- fatalperror( "Couldn't allocate memory for filename\n");
- strcpy( result, args[i]);
- args[i][0] = '\0'; /* Mark as used up */
- break;
- }
- }
- return result;
-}
-
-int parseswitch( char *found, char *wanted)
-{
- if (strncmp( found, wanted, strlen( wanted)) == 0)
- {
- if (found[strlen( wanted)] == '\0')
- return TRUE;
- else
- argerrornum( found, ME_NOSWITCH);
- }
- return FALSE;
-}
-
-int parseswitcharg( int argcount, char *args[], char *string)
-{
- int i;
-
- if ((i = findoption( argcount, args, string)) > 0)
- {
- if (args[i][strlen( string) + 1] == '\0')
- return TRUE;
- else
- argerrornum( args[i] + 1, ME_NOSWITCH);
- }
- return FALSE;
-}
-
-int parseintarg( int argcount, char *args[], char *string, int *result)
-{
- int i, temp;
- char c;
-
- if ((i = findoption( argcount, args, string)) > 0)
- {
- switch (sscanf(args[i] + 1 + strlen( string),
- "%d%c", &temp, &c))
- {
- case 0: case EOF: case 2:
- argerrornum(args[i]+1, ME_NOINT);
- return FALSE;
- case 1:
- *result = temp;
- break;
- default:
- say("frame.c: This can't happen\n");
- }
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-/* --------------------------------------------------------------------
- Reads through the arguments on the lookout for an option starting
- with 'string'. The rest of the option is read as a double and
- passed to *result.
- On failure, *result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -------------------------------------------------------------------- */
-int parsedoublearg( int argcount, char *args[], char *string, double *result)
-{
- int i;
- double temp;
- char end;
-
- if ((i = findoption( argcount, args, string)) > 0)
- {
- switch (sscanf(args[i] + 1 + strlen( string), "%lf%c", &temp, &end))
- {
- case 0: case EOF: case 2:
- argerrornum(args[i]+1, ME_NODOUBLE);
- return FALSE;
- case 1:
- *result = temp;
- break;
- default:
- say("frame.c: This can't happen\n");
- }
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-/* --------------------------------------------------------------------
- Reads through the arguments on the lookout for an option starting
- with 'string'. The rest of the option is read as a volume, i.e.
- absolute, percent or db. The result is passed to *result.
- On failure, *result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -------------------------------------------------------------------- */
-int parsevolarg( int argcount, char *args[], char *string, double *result)
-{
- double vol = 1.0;
- char sbd, sbb, end;
- int i, weird = FALSE;
-
- if ((i = findoption( argcount, args, string)) > 0)
- {
- switch (sscanf(args[i] + 1 + strlen( string),
- "%lf%c%c%c", &vol, &sbd, &sbb, &end))
- {
- case 0: case EOF: case 4:
- weird = TRUE;
- break; /* No number: error */
- case 1:
- *result = vol;
- break;
- case 2:
- if (sbd == '%')
- *result = vol / 100;
- else
- weird = TRUE; /* One char but no percent: error */
- break;
- case 3:
- if (sbd =='d' && sbb == 'b')
- *result = pow(2, vol / 6.02);
- else
- weird = TRUE; /* Two chars but not db: error */
- break;
- default:
- say("frame.c: This can't happen.\n");
- }
- if (weird)
- argerrornum( args[i] + 1, ME_NOVOL);
- /* ("Weird option: couldn't parse volume '%s'\n", args[i]+2); */
- return !weird;
- }
- else
- {
- return FALSE;
- }
-}
-
-
-/* --------------------------------------------------------------------
- Reads the specified string 's' and interprets it as a volume. The string
- would be of the form 1.8 or 180% or 5db.
- On success, the return value TRUE and *result is given result
- (i.e. the relative volume, i.e. 1.8). On failure, FALSE is returned and
- result is given value 1.0.
- -------------------------------------------------------------------- */
-int parsevolume(char *s, double *result)
-{
- int k;
- char sbd, sbb, end;
-
- *result = 1.0;
- k = sscanf(s, "%lf%c%c%c", result, &sbd, &sbb, &end);
- switch (k)
- {
- case 0:
- case EOF:
- case 4:
- return FALSE;
- case 1:
- break;
- case 2:
- if (sbd != '%')
- return FALSE;
- (*result) /=100;
- break;
- case 3:
- if (sbd !='d' || sbb != 'b')
- return FALSE;
- (*result) = pow(2, (*result) / 6.02);
- break;
- default:
- say("parsevolume: This can't happen (%d).\n", k);
- }
- return TRUE;
-}
-
-/* --------------------------------------------------------------------
- Reports an error due to parsing the string 's' encountered on the
- command line.
- -------------------------------------------------------------------- */
-void argerror(char *s)
-{
- error ("Error parsing command line. Unrecognized option:\n\t-%s\n", s);
- fatalerror("\nTry --help for help.\n");
-}
-
-/* --------------------------------------------------------------------
- Reports an error due to parsing the string 's' encountered on the
- command line. 'code' indicates the type of error.
- -------------------------------------------------------------------- */
-void argerrornum(char *s, Errornum code)
-{
- char *message;
-
- if (code == ME_TOOMANYFILES)
- {
- error("Too many files on command line: '%s'.\n", s);
- }
- else
- {
- if (s != NULL)
- error ("Error parsing option -%s:\n\t", s);
- switch( code)
- {
- case ME_NOINT:
- message = "Integer expected";
- break;
- case ME_NODOUBLE:
- message = "Floating point number expected";
- break;
- case ME_NOTIME:
- message = "Time argument expected";
- break;
- case ME_NOVOL:
- message = "Volume argument expected";
- break;
- case ME_NOSWITCH:
- message = "Garbage after switch-type option";
- break;
- case ME_HEADERONTEXTFILE:
- message = "Option -h is not useful for text-output";
- break;
- case ME_NOINFILE:
- message = "No input file specified";
- break;
- case ME_NOOUTFILE:
- message = "No output file specified";
- break;
- case ME_NOIOFILE:
- message = "No input/output file specified";
- break;
- case ME_NOSTDIN:
- message = "Standard in not supported here";
- break;
- case ME_NOSTDOUT:
- message = "Standard out not supported here";
- break;
- case ME_NOSTDIO:
- message = "Standard in/out not supported here";
- break;
- case ME_NOTENOUGHFILES:
- message = "Not enough files specified";
- break;
- case ME_THISCANTHAPPEN:
- fatalerror("\nThis can't happen. Report this as a bug\n");
- /* fatalerror does not return */
- default:
- error("Error code %d not implemented. Fix me!\n", code);
- message = "Error message not implemented. Fix me!";
- }
- error("%s\n", message);
- }
- fatalerror("\nTry --help for help.\n");
-}
-
-/* --------------------------------------------------------------------
- Reports an error due to parsing the string 's' encountered on the
- command line. 'message' explains the type of error.
- -------------------------------------------------------------------- */
-void argerrortxt(char *s, char *message)
-{
- if (s != NULL)
- error ("Error parsing option -%s:\n\t", s);
- else
- error ("Error parsing command line:\n\t");
- error ("%s\n", message);
- fatalerror("\nTry --help for help.\n");
-}
-
-/* --------------------------------------------------------------------
- Check for any remaining arguments and complain about their existence
- -------------------------------------------------------------------- */
-void checknoargs( int argcount, char *args[])
-{
- int i, errorcount = 0;
-
- for (i = 1; i < argcount; i++)
- {
- if (args[i][0] != '\0') /* An unused argument! */
- {
- errorcount++;
- if (errorcount == 1)
- error("The following arguments were not recognized:\n");
- error("\t%s\n", args[i]);
- }
- }
- if (errorcount > 0) /* Errors are fatal */
- fatalerror("\nTry --help for help.\n");
-
- return; /* No errors? Return. */
-}
-
-/* --------------------------------------------------------------------
- Parses the command line arguments as represented by the function
- arguments. Sets the global variables 'in', 'out', 'samplefrequency'
- and 'samplewidth' accordingly. Also verboselevel.
- The files 'in' and 'out' are even opened according to 'fileswitch'.
- See headerfile for details
- -------------------------------------------------------------------- */
-void parseargs( int argcount, char *args[], int fileswitch)
-{
- char *filename;
- int tempint;
-
- if ((fileswitch & 1) != 0) /* If getting infile */
- in = NULL;
- if ((fileswitch & 4) != 0) /* If getting outfile */
- out = NULL;
- wavout = FALSE;
- verboselevel = 5;
- samplefrequency = DEFAULTFREQ;
- samplewidth = 2;
- channels = 1;
-
- /*-----------------------------------------------*
- * First first check testcase, usage and version *
- *-----------------------------------------------*/
- test_usage = parseswitcharg( argcount, args, "-test-usage");
- if (parseswitcharg( argcount, args, "-help"))
- {
- printf("%s%s", usage, standardusage);
- exit(0);
- }
- if (parseswitcharg( argcount, args, "-version"))
- {
- printf("%s\n(%s)\n", version, standardversion);
- exit(0);
- }
- /*--------------------------------------*
- * Set verboselevel *
- *--------------------------------------*/
- while (parseswitcharg( argcount, args, "V"))
- verboselevel = 10;
- while (parseswitcharg( argcount, args, "Q"))
- verboselevel = 1;
- /*-------------------------------------------------*
- * Get filenames and open files *
- *-------------------------------------------------*/
- if ((fileswitch & 1) != 0) /* Infile wanted */
- {
- infilename = parsefilearg( argcount, args);
- if (infilename == NULL)
- argerrornum( NULL, ME_NOINFILE);
- if (strcmp( infilename, "-") == 0)
- {
- infilename = "<stdin>";
- in = stdin;
- if ((fileswitch & 2) != 0) /* Binfile wanted */
- readwavheader( in);
- }
- else
- {
- if ((fileswitch & 2) == 0) /* Textfile wanted */
- in = fopen(infilename, "rt");
- else /* Binfile wanted */
- if ((in = fopen(infilename, "rb")) != NULL)
- readwavheader( in);
- }
- if (in == NULL)
- fatalerror("Error opening input file '%s': %s\n", infilename,strerror(errno));
- else
- inform("Using file '%s' as input\n", infilename);
- }
- if ((fileswitch & 4) != 0) /* Outfile wanted */
- {
- outfilename = parsefilearg( argcount, args);
- if (outfilename == NULL)
- argerrornum( NULL, ME_NOOUTFILE);
- if (strcmp( outfilename, "-") == 0)
- {
- outfilename = "<stdout>";
- out = stdout;
- }
- else
- {
-
- if ((fileswitch & 8) == 0) /* Textfile wanted */
- out = fopen(outfilename, "wt");
- else /* Binfile wanted */
- out = fopen(outfilename, "wb");
- }
- if (out == NULL)
- fatalerror("Error opening output file '%s': %s\n", outfilename,strerror(errno));
- else
- inform("Using file '%s' as output\n", outfilename);
- }
- if ((fileswitch & 32) != 0) /* In-/Outfile wanted */
- {
- assert (in == NULL && out == NULL);
- infilename = outfilename = parsefilearg( argcount, args);
- if (outfilename == NULL)
- argerrornum( NULL, ME_NOIOFILE);
- if (strcmp( infilename, "-") == 0)
- argerrornum( infilename, ME_NOSTDIN);
- inform("Using file '%s' as input/output\n", outfilename);
- in = out = fopen(outfilename, "r+");
- if (out == NULL)
- fatalerror("Error opening input/output file '%s': %s\n", outfilename,strerror(errno));
-
- readwavheader( in);
- }
- if ((fileswitch & 16) == 0) /* No additional files wanted */
- {
- if ((filename = parsefilearg( argcount, args)) != NULL)
- argerrornum( filename, ME_TOOMANYFILES);
- }
-
- /*-------------------------------------------------*
- * Set samplefrequency, width, wavout,
- *-------------------------------------------------*/
- parseintarg( argcount, args, "f", &samplefrequency);
- wavout = parseswitcharg( argcount, args, "h");
- if (parseintarg( argcount, args, "w", &tempint))
- {
- if (tempint != 16)
- argerrortxt(NULL, "Option -w is only valid "
- "with value 16. Sorry.");
- else
- samplewidth = tempint;
- }
- if (parseintarg( argcount, args, "c", &tempint))
- {
- if (tempint != 1 && tempint != 2)
- argerrortxt(NULL, "Option -c is only valid "
- "with values 1 or 2. Sorry.");
- else
- channels = tempint;
- }
- /*-------------------------------------------------*
- * Create WAV-header on output if wanted. *
- *-------------------------------------------------*/
- if (wavout)
- switch (fileswitch & (12))
- {
- case 4: /* User wants header on textfile */
- argerrornum( NULL, ME_HEADERONTEXTFILE);
- case 12: /* User wants header on binfile */
- makewavheader();
- break;
- case 0: /* User wants header, but there is no outfile */
- /* Problem: what about i/o-file, 32? You might want a header
- on that? Better ignore this case. */
- break;
- case 8: /* An application musn't ask for this */
- default: /* This can't happen */
- assert( FALSE);
- }
- return;
-}
-
-/* --------------------------------------------------------------------
- Returns the index 'i' of the first argument that IS an option, and
- which begins with the label 's'. If there is none, -1.
- We also mark that option as done with, i.e. we cross it out.
- -------------------------------------------------------------------- */
-int findoption( int argcount, char *args[], char *s)
-{
- int i;
-
- if (test_usage)
- printf("Checking for option -%s\n", s);
-
- for (i=1; i<argcount; i++)
- {
- if (isoptionchar (args[i][0]) &&
- strncmp( args[i] + 1, s, strlen( s)) == 0)
- {
- args[i][0] = '\0';
- return i;
- }
- }
- return -1;
-}
-
-/* --------------------------------------------------------------------
- Finishes off the .WAV header (if any) and exits correctly and formerly.
- -------------------------------------------------------------------- */
-int myexit (int value)
-{
- switch (value)
- {
- case 0:
- if (wavout)
- makewavheader(); /* Writes a fully informed .WAV header */
- chat ("Success!\n");
- break;
- default:
- chat ("Failure.\n");
- break;
- }
- exit (value);
-}
-
-/* --------------------------------------------------------------------
- Reads the stated input file bufferwise, calls the function 'work'
- with the proper values, and writes the result to the stated output file.
- Return value: TRUE on success, FALSE otherwise.
- -------------------------------------------------------------------- */
-int workloop( FILE *theinfile, FILE *theoutfile,
- int (*work)( short *buffer, int length) )
-{
- short *buffer;
- int length, nowlength;
-
- length = BUFFSIZE;
- if ((buffer = malloc( sizeof(short) * length)) == NULL)
- fatalperror ("");
- while (TRUE)
- {
- nowlength = fread(buffer, sizeof(short), length, theinfile);
- if (ferror( theinfile) != 0)
- fatalperror("Error reading input file");
- if (nowlength == 0) /* Reached end of input file */
- break;
- /* Call the routine that does the work */
- if (!work (buffer, nowlength)) /* On error, stop. */
- return FALSE;
- fwrite(buffer, sizeof(short), nowlength, theoutfile);
- if (ferror( theoutfile) != 0)
- fatalperror("Error writing to output file");
- }
- return TRUE; /* Input file done with, no errors. */
-}
-
-int chat( const char *format, ...)
-{
- va_list ap;
- int result = 0;
-
- if (verboselevel > 5)
- {
- va_start( ap, format);
- result = vfprintf( stderr, format, ap);
- va_end( ap);
- }
- return result;
-}
-
-
-int inform( const char *format, ...)
-{
- va_list ap;
- int result = 0;
-
- if (verboselevel > 1)
- {
- va_start( ap, format);
- result = vfprintf( stderr, format, ap);
- va_end( ap);
- }
- return result;
-}
-
-int error( const char *format, ...)
-{
- va_list ap;
- int result;
-
- va_start( ap, format);
- result = vfprintf( stderr, format, ap);
- va_end( ap);
- return result;
-}
-
-void fatalerror( const char *format, ...)
-{
- va_list ap;
-
- va_start( ap, format);
- vfprintf( stderr, format, ap);
- va_end( ap);
- myexit(1);
-}
-
-void fatalperror( const char *string)
-{
- perror( string);
- myexit( 1);
-}
-
-int say( const char *format, ...)
-{
- va_list ap;
- int result;
-
- va_start( ap, format);
- result = vfprintf( stdout, format, ap);
- va_end( ap);
- return result;
-}
-
-
-char *malloccopy( char *string)
-{
- char *result;
-
- result = malloc( strlen( string) + 1);
- if (result != NULL)
- strcpy( result, string);
- return result;
-}
-
-
-char *mallocconcat( char *one, char *two)
-{
- char *result;
-
- result = malloc( strlen( one) + strlen( two) + 1);
- if (result != NULL)
- {
- strcpy( result, one);
- strcat( result, two);
- }
- return result;
-}
-
-double double2db( double value)
-{
- if (value < 0)
- value = -value;
- return 6.0 * log( value / 32767) / log( 2);
-}
-
-void readawaysamples( FILE *in, size_t size)
-{
- short *buffer;
- int samplesread, count;
-
- buffer = malloc( sizeof( *buffer) * BUFFSIZE);
- if (buffer == NULL) fatalperror("Couldn't allocate buffer");
-
- while (size > 0)
- {
- if (size > BUFFSIZE)
- count = BUFFSIZE;
- else
- count = size;
-
- samplesread = fread( buffer, sizeof(*buffer), count, in);
- if (ferror( in) != 0)
- fatalperror("Error reading input file");
- size -= samplesread;
- }
- free( buffer);
-}
-
diff --git a/1.2-netsec/utils/frame.h b/1.2-netsec/utils/frame.h
deleted file mode 100644
index a07c605ec..000000000
--- a/1.2-netsec/utils/frame.h
+++ /dev/null
@@ -1,300 +0,0 @@
-/****************************************************************************
- *
- * Programs for processing sound files in raw- or WAV-format.
- * -- Useful functions for parsing command line options and
- * issuing errors, warnings, and chit chat.
- *
- * Name: frame.h
- * Version: see frame.c
- * Author: Mark Roberts <mark@manumark.de>
- *
- ****************************************************************************/
-/****************************************************************************
- * These are useful functions that all DSP programs might find handy
- ****************************************************************************/
-
-/* fileswitch for parseargs:
-
- The following are masks for several different ways of opening files.
- --------------------------------------------------------------------
- Bit 0: Open infile?
- Bit 1: Open infile as binary (as opposed to text)
- Bit 2: Open outfile?
- Bit 3: Open outfile as binary (as opposed to text)
- Bit 4: Do not complain about too many file arguments
- Bit 5: Open one file for input AND output, binary.
-*/
-#define INTEXT (1+0)
-#define INBIN (1+2)
-#define OUTTEXT (4)
-#define OUTBIN (4+8)
-#define NOFILES (0)
-#define NOCOMPLAIN (16)
-#define IOBIN (32)
-
-#ifndef FALSE
- #define FALSE (0==1)
- #define TRUE (0==0)
-#endif
-
-extern int samplefrequency;
-extern unsigned short samplewidth;
-extern unsigned short channels;
-extern int wavout; /* TRUE iff out file is .WAV file */
-extern int iswav; /* TRUE iff in file was found to be a .WAV file */
-extern FILE *in, *out;
-extern char *infilename, *outfilename;
-extern int verboselevel;
-extern char *version; /* String to be issued as version string. Should
- be set by application. */
-extern char *usage; /* String to be issued as usage string. Should be
- set by application. */
-
-#define DEFAULTFREQ 44100
-#define BUFFSIZE 50000 /* How many samples to read in one go (preferred) */
-#define MINBUFFSIZE 5000 /* How many samples to read in one go (minimum) */
-
-/*************************************************
- * Types of errors handled by argerrornum() *
- *************************************************/
-typedef enum
-{
- ME_NOINT,
- ME_NODOUBLE,
- ME_NOTIME,
- ME_NOVOL,
- ME_NOSWITCH,
- ME_TOOMANYFILES,
- ME_HEADERONTEXTFILE,
- ME_NOINFILE,
- ME_NOOUTFILE,
- ME_NOIOFILE,
- ME_NOSTDIN,
- ME_NOSTDOUT,
- ME_NOSTDIO,
- ME_NOTENOUGHFILES,
- ME_THISCANTHAPPEN
-} Errornum;
-
-
-/* -----------------------------------------------------------------------
- Create memory and copy 'string', returning a pointer to the copy.
- NULL is returned if malloc fails.
- -----------------------------------------------------------------------*/
-extern char *malloccopy( char *string);
-
-/* -----------------------------------------------------------------------
- Start the stopwatch and make sure the user is informed at end of program.
- -----------------------------------------------------------------------*/
-extern void startstopwatch(void);
-
-/* -----------------------------------------------------------------------
- Writes the number of samples to result that are yet to be read from anyin.
- I.e. the number of remaining bytes is divided by the number of bytes per
- sample value, but not by the number of channels.
- Return values are TRUE on success, FALSE on failure.
- -----------------------------------------------------------------------*/
-extern int getremainingfilelength( FILE *anyin, long *result);
-
-/* -----------------------------------------------------------------------
- Read a .pk-header from 'anyin' and printf the entries.
- -----------------------------------------------------------------------*/
-void readpkheader( FILE *anyin);
-
-/* -----------------------------------------------------------------------
- Read a .WAV header from 'anyin'.
- If it is recognised, the data is used.
- Otherwise, we assume it's PCM-data and ignore the header.
- The global variable 'iswav' is set on success, otherwise cleared.
- -----------------------------------------------------------------------*/
-extern void readwavheader( FILE *anyin);
-
-/* -----------------------------------------------------------------------
- Write a .WAV header to 'out'.
- The filepointer is placed at the end of 'out' before operation.
- This should be called before any data is
- written, and again, when ALL the data has been written.
- First time, this positions the file pointer correctly; second time, the
- missing data can be inserted that wasn't known the first time round.
- -----------------------------------------------------------------------*/
-extern void makewavheader( void);
-
-/* --------------------------------------------------------------------
- Tests the character 'coal' for being a command line option character,
- momentarrily '/' or '-'.
- -------------------------------------------------------------------- */
-extern int isoptionchar (char coal);
-
-/* -----------------------------------------------------------------------
- Reads through the arguments on the lookout for an option starting
- with 'string'. The rest of the option is read as a time and passed
- to *result, where the result is meant to mean 'number of samples' in
- that time.
- On failure, *result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -----------------------------------------------------------------------*/
-extern int parsetimearg( int argcount, char *args[], char *string,
- int *result);
-
-/* -----------------------------------------------------------------------
- The string argument is read as a time and passed to *result, where
- the result is meant to mean 'number of samples' in that time. On
- failure, *result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -----------------------------------------------------------------------*/
-int parsetime(char *string, int *result);
-
-/* -----------------------------------------------------------------------
- The string argument is read as a frequency and passed
- to *result, where the result is meant to mean 'number of samples' in
- one cycle of that frequency.
- On failure, *result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -----------------------------------------------------------------------*/
-int parsefreq(char *string, double *result);
-
-/* --------------------------------------------------------------------
- Reads through the arguments on the lookout for a switch -'string'.
- return value is TRUE if one exists, FALSE otherwise.
- If characters remain after the switch, a fatal error is issued.
- -------------------------------------------------------------------- */
-extern int parseswitcharg( int argcount, char *args[], char *string);
-
-/* --------------------------------------------------------------------
- Reads through the arguments on the lookout for an option starting
- with 'string'. The rest of the option is read as an integer and
- passed to &result.
- On failure, &result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -------------------------------------------------------------------- */
-extern int parseintarg( int argcount, char *args[], char *string,
- int *result);
-
-/* --------------------------------------------------------------------
- Reads through the arguments on the lookout for a filename, i.e. anything
- that does not start with the optionchar. The filename is copied to
- newly allocated memory, a pointer to which is returned.
- The argument is marked as used. Therefore repeated use of this function
- will yield a complete list of filenames on the commandline.
- If malloc() fails, the function does not return.
- -------------------------------------------------------------------- */
-extern char *parsefilearg( int argcount, char *args[]);
-
-/* --------------------------------------------------------------------
- Reads through the arguments on the lookout for an option starting
- with 'string'. The rest of the option is read as a double and
- passed to *result.
- On failure, *result is unchanged.
- return value is TRUE on success, FALSE otherwise.
- -------------------------------------------------------------------- */
-extern int parsedoublearg( int argcount, char *args[], char *string,
- double *result);
-
-/* --------------------------------------------------------------------
- Reads through the arguments on the lookout for an option starting
- with 'string'. The rest of the option is read as a volume, i.e.
- absolute, percent or db. The result is passed to *result.
- On failure, *result is unchanged.
- -------------------------------------------------------------------- */
-extern int parsevolarg( int argcount, char *args[], char *string,
- double *result);
-
-/* --------------------------------------------------------------------
- Reads the specified string and interprets it as a volume. The string
- would be of the form 1.8 or 180% or 5db.
- On success, the return value is the relative volume, i.e. 1.8
- On failure, -1 is returned.
- -------------------------------------------------------------------- */
-extern int parsevolume(char *s, double *result);
-
-/* --------------------------------------------------------------------
- Reads through the arguments on the lookout for a switch -'string'.
- return value is TRUE if one exists, FALSE otherwise.
- If characters remain after the switch, a fatal error is issued.
- -------------------------------------------------------------------- */
-extern int parseswitch( char *found, char *wanted);
-
-/* --------------------------------------------------------------------
- Reports an error due to parsing the string 's' encountered on the
- command line.
- -------------------------------------------------------------------- */
-extern void argerror(char *s);
-
-/* --------------------------------------------------------------------
- Reports an error due to parsing the string 's' encountered on the
- command line. 'code' indicates the type of error.
- -------------------------------------------------------------------- */
-extern void argerrornum(char *s, Errornum code);
-
-/* --------------------------------------------------------------------
- Reports an error due to parsing the string 's' encountered on the
- command line. 'message' explains the type of error.
- -------------------------------------------------------------------- */
-extern void argerrortxt(char *s, char *message);
-
-/* --------------------------------------------------------------------
- Check for any remaining arguments and complain about their existence.
- If arguments are found, this function does not return.
- -------------------------------------------------------------------- */
-extern void checknoargs( int argcount, char *args[]);
-
-/* --------------------------------------------------------------------
- Parses the command line arguments as represented by the function
- arguments. Sets the global variables 'in', 'out', 'samplefrequency'
- and 'samplewidth' accordingly.
- According to 'fileswitch', in and out files are opened or not. See
- above for an explanation of 'fileswitch'.
- -------------------------------------------------------------------- */
-extern void parseargs( int argcount, char *args[], int fileswitch);
-
-/* --------------------------------------------------------------------
- Returns the index 'i' of the first argument that IS an option, and
- which begins with the label 's'. If there is none, -1.
- We also mark that option as done with, i.e. we cross it out.
- -------------------------------------------------------------------- */
-extern int findoption( int argcount, char *args[], char *s);
-
-/* --------------------------------------------------------------------
- Finishes off the .WAV header (if any) and exits correctly and formerly.
- -------------------------------------------------------------------- */
-extern int myexit (int value);
-
-/* --------------------------------------------------------------------
- Reads the stated input file bufferwise, calls the function 'work'
- with the proper values, and writes the result to the stated output file.
- Return value: TRUE on success, FALSE otherwise.
- -------------------------------------------------------------------- */
-extern int workloop( FILE *theinfile, FILE *theoutfile,
- int (*work)( short *buffer, int length) );
-
-/* --------------------------------------------------------------------
- Five functions for printing to stderr. Depending on the level of verbose,
- output may be supressed. fatalerror() is like error() but does not return.
- fatalperror() is like the standard function perror() but does not return.
- -------------------------------------------------------------------- */
-extern int chat( const char *format, ...);
-extern int inform( const char *format, ...);
-extern int error( const char *format, ...);
-extern void fatalerror( const char *format, ...);
-extern void fatalperror( const char *string);
-
-/* --------------------------------------------------------------------
- And one functions for printing to stdout.
- -------------------------------------------------------------------- */
-extern int say( const char *format, ...);
-
-/* --------------------------------------------------------------------
- Allocate memory for it and return a pointer to a string made up of
- the two argument strings.
- -------------------------------------------------------------------- */
-extern char *mallocconcat( char *one, char *two);
-
-/* --------------------------------------------------------------------
- Convert a sample value to decibel.
- -------------------------------------------------------------------- */
-extern double double2db( double value);
-
-/* --------------------------------------------------------------------
- Read 'size' samples from file 'in' and lose them.
- -------------------------------------------------------------------- */
-extern void readawaysamples( FILE *in, size_t size);
diff --git a/1.2-netsec/utils/smsq.c b/1.2-netsec/utils/smsq.c
deleted file mode 100644
index 361fc2679..000000000
--- a/1.2-netsec/utils/smsq.c
+++ /dev/null
@@ -1,763 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004 - 2005
- *
- * SMS queuing application for use with asterisk app_sms
- * by Adrian Kennard
- *
- * 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.
- */
-
-#include <stdio.h>
-#include <popt.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <asterisk/compat.h>
-#ifdef SOLARIS
-#define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000
-#endif
-#if !defined(POPT_ARGFLAG_SHOW_DEFAULT)
-#define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000
-#endif
-
-
-/* reads next USC character from null terminated UTF-8 string and advanced pointer */
-/* for non valid UTF-8 sequences, returns character as is */
-/* Does not advance pointer for null termination */
-static int utf8decode (unsigned char **pp)
-{
- unsigned char *p = *pp;
- if (!*p)
- return 0; /* null termination of string */
- (*pp)++;
- if (*p < 0xC0)
- return *p; /* ascii or continuation character */
- if (*p < 0xE0)
- {
- if (*p < 0xC2 || (p[1] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp)++;
- return ((*p & 0x1F) << 6) + (p[1] & 0x3F);
- }
- if (*p < 0xF0)
- {
- if ((*p == 0xE0 && p[1] < 0xA0) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp) += 2;
- return ((*p & 0x0F) << 12) + ((p[1] & 0x3F) << 6) + (p[2] & 0x3F);
- }
- if (*p < 0xF8)
- {
- if ((*p == 0xF0 && p[1] < 0x90) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp) += 3;
- return ((*p & 0x07) << 18) + ((p[1] & 0x3F) << 12) + ((p[2] & 0x3F) << 6) + (p[3] & 0x3F);
- }
- if (*p < 0xFC)
- {
- if ((*p == 0xF8 && p[1] < 0x88) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80
- || (p[4] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp) += 4;
- return ((*p & 0x03) << 24) + ((p[1] & 0x3F) << 18) + ((p[2] & 0x3F) << 12) + ((p[3] & 0x3F) << 6) + (p[4] & 0x3F);
- }
- if (*p < 0xFE)
- {
- if ((*p == 0xFC && p[1] < 0x84) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80
- || (p[4] & 0xC0) != 0x80 || (p[5] & 0xC0) != 0x80)
- return *p; /* not valid UTF-8 */
- (*pp) += 5;
- return ((*p & 0x01) << 30) + ((p[1] & 0x3F) << 24) + ((p[2] & 0x3F) << 18) + ((p[3] & 0x3F) << 12) + ((p[4] & 0x3F) << 6) +
- (p[5] & 0x3F);
- }
- return *p; /* not sensible */
-}
-
-/* check for any queued messages in specific queue (queue="" means any queue) */
-/* returns 0 if nothing queued, 1 if queued and outgoing set up OK, 2 of outgoing exists */
-static char txqcheck (char *dir, char *queue, char subaddress, char *channel, char *callerid, int wait, int delay, int retries, int concurrent)
-{
- char ogname[100],
- temp[100],
- dirname[100],
- *p=NULL;
- FILE *f;
- DIR *d;
- int ql = strlen (queue), qfl = ql;
- struct dirent *fn;
- snprintf (dirname, sizeof(dirname), "sms/%s", dir);
- d = opendir (dirname);
- if (!d)
- return 0;
- while ((fn = readdir (d))
- && !(*fn->d_name != '.'
- && ((!ql && (p = strchr (fn->d_name, '.'))) || (ql && !strncmp (fn->d_name, queue, ql) && fn->d_name[ql] == '.'))));
- if (!fn)
- {
- closedir (d);
- return 0;
- }
- if (!ql)
- { /* not searching any specific queue, so use whatr we found as the queue */
- queue = fn->d_name;
- qfl = ql = p - queue;
- }
- p = strchr (queue, '-');
- if (p && p < queue + ql)
- {
- ql = p - queue;
- subaddress = p[1];
- }
- snprintf (temp, sizeof(temp), "sms/.smsq-%d", getpid ());
- f = fopen (temp, "w");
- if (!f)
- {
- perror (temp);
- closedir (d);
- return 0;
- }
- fprintf (f, "Channel: ");
- if (!channel)
- fprintf (f, "Local/%.*s\n", ql, queue);
- else
- {
- p = strchr (channel, '/');
- if (!p)
- p = channel;
- p = strchr (p, 'X');
- if (p)
- fprintf (f, "%.*s%c%s\n", p - channel, channel, subaddress, p + 1);
- else
- fprintf (f, "%s\n", channel);
- }
- fprintf (f, "Callerid: SMS <");
- if (!callerid)
- fprintf (f, "%.*s", ql, queue);
- else
- {
- p = strchr (callerid, 'X');
- if (p)
- fprintf (f, "%.*s%c%s", p - callerid, callerid, subaddress, p + 1);
- else
- fprintf (f, "%s", callerid);
- }
- fprintf (f, ">\n");
- fprintf (f, "Application: SMS\n");
- fprintf (f, "Data: %.*s", qfl, queue);
- if (dir[1] == 't')
- fprintf (f, "|s");
- fprintf (f, "\nMaxRetries: %d\n", retries);
- fprintf (f, "RetryTime: %d\n", delay);
- fprintf (f, "WaitTime: %d\n", wait);
- fclose (f);
- closedir (d);
- {
- int try = 0;
- while (try < concurrent)
- {
- try++;
- snprintf(ogname, sizeof(ogname), "outgoing/smsq.%s.%s.%d", dir, queue, try);
- if (!link (temp, ogname))
- { /* queued OK */
- unlink (temp);
- return 1;
- }
- }
- }
- /* failed to create call queue */
- unlink (temp);
- return 2;
-}
-
-/* Process received queue entries and run through a process, setting environment variables */
-static void rxqcheck (char *dir, char *queue, char *process)
-{
- unsigned char *p;
- char dirname[100],
- temp[100];
- DIR *d;
- int ql = strlen (queue);
- struct dirent *fn;
- snprintf(temp, sizeof(temp), "sms/.smsq-%d", getpid ());
- snprintf(dirname, sizeof(dirname), "sms/%s", dir);
- d = opendir (dirname);
- if (!d)
- return;
- while ((fn = readdir (d)))
- if ((*fn->d_name != '.'
- && ((!ql && (p = strchr (fn->d_name, '.'))) || (ql && !strncmp (fn->d_name, queue, ql) && fn->d_name[ql] == '.'))))
- { /* process file */
- char filename[1010];
- char line[1000];
- unsigned short ud[160];
- unsigned char udl = 0;
- FILE *f;
- snprintf (filename, sizeof(filename), "sms/%s/%s", dir, fn->d_name);
- if (rename (filename, temp))
- continue; /* cannot access file */
- f = fopen (temp, "r");
- unlink (temp);
- if (!f)
- {
- perror (temp);
- continue;
- }
- unsetenv ("oa");
- unsetenv ("da");
- unsetenv ("scts");
- unsetenv ("pid");
- unsetenv ("dcs");
- unsetenv ("mr");
- unsetenv ("srr");
- unsetenv ("rp");
- unsetenv ("vp");
- unsetenv ("udh");
- unsetenv ("ud");
- unsetenv ("ude");
- unsetenv ("ud8");
- unsetenv ("ud16");
- unsetenv ("morx");
- unsetenv ("motx");
- unsetenv ("queue");
- if (*queue)
- setenv ("queue", queue, 1);
- setenv (dir, "", 1);
- while (fgets (line, sizeof (line), f))
- {
- for (p = line; *p && *p != '\n' && *p != '\r'; p++);
- *p = 0; /* strip eoln */
- p = line;
- if (!*p || *p == ';')
- continue; /* blank line or comment, ignore */
- while (isalnum (*p))
- {
- *p = tolower (*p);
- p++;
- }
- while (isspace (*p))
- *p++ = 0;
- if (*p == '=')
- { /* = */
- *p++ = 0;
- if (!strcmp (line, "oa") || !strcmp (line, "da") || !strcmp (line, "scts") || !strcmp (line, "pid")
- || !strcmp (line, "dcs") || !strcmp (line, "mr") || !strcmp (line, "vp"))
- setenv (line, p, 1);
- else if ((!strcmp (line, "srr") || !strcmp (line, "rp")) && atoi (p))
- setenv (line, "", 1);
- else if (!strcmp (line, "ud"))
- { /* read the user data as UTF-8 */
- long v;
- udl = 0;
- while ((v = utf8decode (&p)) && udl < 160)
- if (v && v <= 0xFFFF)
- ud[udl++] = v;
- }
- } else if (*p == '#')
- {
- *p++ = 0;
- if (*p == '#')
- { /* ## */
- p++;
- if (!strcmp (line, "udh"))
- setenv (line, p, 1);
- else if (!strcmp (line, "ud"))
- { /* read user data UCS-2 */
- udl = 0;
- while (*p && udl < 160)
- {
- if (isxdigit (*p) && isxdigit (p[1]) && isxdigit (p[2]) && isxdigit (p[3]))
- {
- ud[udl++] =
- (((isalpha (*p) ? 9 : 0) + (*p & 0xF)) << 12) +
- (((isalpha (p[1]) ? 9 : 0) + (p[1] & 0xF)) << 8) +
- (((isalpha (p[2]) ? 9 : 0) + (p[2] & 0xF)) << 4) + ((isalpha (p[3]) ? 9 : 0) + (p[3] & 0xF));
- p += 4;
- } else
- break;
- }
- }
- } else
- { /* # */
- if (!strcmp (line, "ud"))
- { /* read user data UCS-1 */
- udl = 0;
- while (*p && udl < 160)
- {
- if (isxdigit (*p) && isxdigit (p[1]))
- {
- ud[udl++] = (((isalpha (*p) ? 9 : 0) + (*p & 0xF)) << 4) + ((isalpha (p[1]) ? 9 : 0) + (p[1] & 0xF));
- p += 2;
- } else
- break;
- }
- }
- }
- }
- }
- fclose (f);
- /* set up user data variables */
- {
- char temp[481];
- int n,
- p;
- for (n = 0, p = 0; p < udl; p++)
- {
- unsigned short v = ud[p];
- if (v)
- {
- if (v < 0x80)
- temp[n++] = v;
- else if (v < 0x800)
- {
- temp[n++] = (0xC0 + (v >> 6));
- temp[n++] = (0x80 + (v & 0x3F));
- } else
- {
- temp[n++] = (0xE0 + (v >> 12));
- temp[n++] = (0x80 + ((v >> 6) & 0x3F));
- temp[n++] = (0x80 + (v & 0x3F));
- }
- }
- }
- temp[n] = 0;
- setenv ("ud", temp, 1);
- for (n = 0, p = 0; p < udl; p++)
- {
- unsigned short v = ud[p];
- if (v < ' ' || v == '\\')
- {
- temp[n++] = '\\';
- if (v == '\\')
- temp[n++] = '\\';
- else if (v == '\n')
- temp[n++] = 'n';
- else if (v == '\r')
- temp[n++] = 'r';
- else if (v == '\t')
- temp[n++] = 't';
- else if (v == '\f')
- temp[n++] = 'f';
- else
- {
- temp[n++] = '0' + (v >> 6);
- temp[n++] = '0' + ((v >> 3) & 7);
- temp[n++] = '0' + (v & 7);
- }
- } else if (v < 0x80)
- temp[n++] = v;
- else if (v < 0x800)
- {
- temp[n++] = (0xC0 + (v >> 6));
- temp[n++] = (0x80 + (v & 0x3F));
- } else
- {
- temp[n++] = (0xE0 + (v >> 12));
- temp[n++] = (0x80 + ((v >> 6) & 0x3F));
- temp[n++] = (0x80 + (v & 0x3F));
- }
- }
- temp[n] = 0;
- setenv ("ude", temp, 1);
- for (p = 0; p < udl && ud[p] < 0x100; p++);
- if (p == udl)
- {
- for (n = 0, p = 0; p < udl; p++)
- {
- sprintf (temp + n, "%02X", ud[p]);
- n += 2;
- }
- setenv ("ud8", temp, 1);
- }
- for (n = 0, p = 0; p < udl; p++)
- {
- sprintf (temp + n, "%04X", ud[p]);
- n += 4;
- }
- setenv ("ud16", temp, 1);
- }
- /* run the command */
- system (process);
- }
- closedir (d);
-}
-
-/* Main app */
-int
-main (int argc, const char *argv[])
-{
- char c;
- int mt = 0,
- mo = 0,
- tx = 0,
- rx = 0,
- nodial = 0,
- nowait = 0,
- concurrent = 1,
- motxwait = 10,
- motxdelay = 1,
- motxretries = 10,
- mttxwait = 10,
- mttxdelay = 30,
- mttxretries = 100,
- mr = -1,
- pid = -1,
- dcs = -1,
- srr = 0,
- rp = 0,
- vp = 0,
- udl = 0,
- utf8 = 0,
- ucs1 = 0,
- ucs2 = 0;
- unsigned short ud[160];
- unsigned char *uds = 0,
- *udh = 0;
- char *da = 0,
- *oa = 0,
- *queue = "",
- *udfile = 0,
- *process = 0,
- *spooldir = "/var/spool/asterisk",
- *motxchannel = "Local/1709400X",
- *motxcallerid = 0,
- *mttxchannel = 0,
- *mttxcallerid = "080058752X0",
- *defaultsubaddress = "9",
- subaddress = 0,
- *scts = 0;
- poptContext optCon; /* context for parsing command-line options */
- const struct poptOption optionsTable[] = {
- {"queue", 'q', POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &queue, 0, "Queue [inc sub address]", "number[-X]"},
- {"da", 'd', POPT_ARG_STRING, &da, 0, "Destination address", "number"},
- {"oa", 'o', POPT_ARG_STRING, &oa, 0, "Origination address", "number"},
- {"ud", 'm', POPT_ARG_STRING, &uds, 0, "Message", "text"},
- {"ud-file", 'f', POPT_ARG_STRING, &udfile, 0, "Message file", "filename"},
- {"UTF-8", 0, POPT_ARG_NONE, &utf8, 0, "File treated as null terminated UTF-8 (default)", 0},
- {"UCS-1", 0, POPT_ARG_NONE, &ucs1, 0, "File treated as UCS-1", 0},
- {"UCS-2", 0, POPT_ARG_NONE, &ucs2, 0, "File treated as UCS-2", 0},
- {"mt", 't', POPT_ARG_NONE, &mt, 0, "Mobile Terminated", 0},
- {"mo", 0, POPT_ARG_NONE, &mo, 0, "Mobile Originated", 0},
- {"tx", 0, POPT_ARG_NONE, &tx, 0, "Send message", 0},
- {"rx", 'r', POPT_ARG_NONE, &rx, 0, "Queue for receipt", 0},
- {"process", 'e', POPT_ARG_STRING, &process, 0, "Rx queue process command", "command"},
- {"no-dial", 'x', POPT_ARG_NONE, &nodial, 0, "Do not dial", 0},
- {"no-wait", 0, POPT_ARG_NONE, &nowait, 0, "Do not wait if already calling", 0},
- {"concurrent", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &concurrent, 0, "Number of concurrent calls to allow", "n"},
- {"motx-channel", 0, POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &motxchannel, 0, "Channel for motx calls", "channel"},
- {"motx-callerid", 0, POPT_ARG_STRING, &motxcallerid, 0,
- "Caller ID for motx calls (default is queue name without sub address)", "number"},
- {"motx-wait", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &motxwait, 0, "Time to wait for motx call to answer",
- "seconds"},
- {"motx-delay", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &motxdelay, 0, "Time between motx call retries", "seconds"},
- {"motx-retries", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &motxretries, 0, "Number of retries for motx call", "n"},
- {"mttx-channel", 0, POPT_ARG_STRING, &mttxchannel, 0,
- "Channel for mttx calls (default is Local/ and queue name without sub address)", "channel"},
- {"mttx-callerid", 0, POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &mttxcallerid, 0,
- "Caller ID for mttx calls (default is queue name without sub address)", "number"},
- {"mttx-wait", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &mttxwait, 0, "Time to wait for mttx call to answer",
- "seconds"},
- {"mttx-delay", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &mttxdelay, 0, "Time between mttx call retries", "seconds"},
- {"mttx-retries", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &mttxretries, 0, "Number of retries for mttx call", "n"},
- {"mr", 'n', POPT_ARG_INT, &mr, 0, "Message reference", "n"},
- {"pid", 'p', POPT_ARG_INT, &pid, 0, "Protocol ID", "n"},
- {"dcs", 'c', POPT_ARG_INT, &dcs, 0, "Data Coding Scheme", "n"},
- {"udh", 0, POPT_ARG_STRING, &udh, 0, "User data header", "hex"},
- {"srr", 0, POPT_ARG_NONE, &srr, 0, "Status Report Request", 0},
- {"rp", 0, POPT_ARG_NONE, &rp, 0, "Return Path request", 0},
- {"v", 0, POPT_ARG_INT, &vp, 0, "Validity Period", "seconds"},
- {"scts", 0, POPT_ARG_STRING, &scts, 0, "Timestamp", "YYYY-MM-SSTHH:MM:SS"},
- {"default-sub-address", 0, POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &defaultsubaddress, 0, "Default sub address", "X"},
- {"spool-dir", 0, POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &spooldir, 0, "Asterisk spool dir", "dirname"},
- POPT_AUTOHELP {NULL, 0, 0, NULL, 0}
- };
-
- optCon = poptGetContext (NULL, argc, argv, optionsTable, 0);
- poptSetOtherOptionHelp (optCon, "<oa/da> <message>");
-
- /* Now do options processing, get portname */
- if ((c = poptGetNextOpt (optCon)) < -1)
- {
- /* an error occurred during option processing */
- fprintf (stderr, "%s: %s\n", poptBadOption (optCon, POPT_BADOPTION_NOALIAS), poptStrerror (c));
- return 1;
- }
- if (!ucs1 && !ucs2)
- utf8 = 1;
- if (utf8 + ucs1 + ucs2 > 1)
- {
- fprintf (stderr, "Pick one of UTF-8, UCS-1 or UCS-2 only\n");
- return 1;
- }
- if (!udfile && (ucs1 || ucs2))
- {
- fprintf (stderr, "Command line arguments always treated as UTF-8\n");
- return 1;
- }
- /* if (!where && poptPeekArg (optCon)) where = (char *) poptGetArg (optCon); */
- if (!mt && !mo && process)
- mt = 1;
- if (!mt && !mo && oa)
- mt = 1;
- if (!mt)
- mo = 1;
- if (mt && mo)
- {
- fprintf (stderr, "Cannot be --mt and --mo\n");
- return 1;
- }
- if (!rx && !tx && process)
- rx = 1;
- if (!rx)
- tx = 1;
- if (tx && rx)
- {
- fprintf (stderr, "Cannot be --tx and --rx\n");
- return 1;
- }
- if (rx)
- nodial = 1;
- if (uds && udfile)
- {
- fprintf (stderr, "Cannot have --ud and --ud-file\n");
- return 1;
- }
- if (mo && !da && poptPeekArg (optCon))
- da = (char *) poptGetArg (optCon);
- if (mt && !oa && poptPeekArg (optCon))
- oa = (char *) poptGetArg (optCon);
- if (tx && oa && mo)
- {
- fprintf (stderr, "--oa makes no sense with --mo as CLI is used (i.e. queue name)\n");
- return 1;
- }
- if (tx && da && mt)
- {
- fprintf (stderr, "--da makes no sense with --mt as called number is used (i.e. queue name)\n");
- return 1;
- }
- if (da && strlen (da) > 20)
- {
- fprintf (stderr, "--da too long\n");
- return 1;
- }
- if (oa && strlen (oa) > 20)
- {
- fprintf (stderr, "--oa too long\n");
- return 1;
- }
- if (queue && strlen (queue) > 20)
- {
- fprintf (stderr, "--queue name too long\n");
- return 1;
- }
- if (mo && scts)
- {
- fprintf (stderr, "scts is set my service centre\n");
- return 1;
- }
- if (uds)
- { /* simple user data command line option in \UTF-8 */
- while (udl < 160 && *uds)
- {
- int v = utf8decode (&uds);
- if (v > 0xFFFF)
- {
- fprintf (stderr, "Invalid character U+%X at %d\n", v, udl);
- return 1;
- }
- ud[udl++] = v;
- }
- }
- if (!uds && !udfile && poptPeekArg (optCon))
- { /* multiple command line arguments in UTF-8 */
- while (poptPeekArg (optCon) && udl < 160)
- {
- unsigned char *a = (char *) poptGetArg (optCon);
- if (udl && udl < 160)
- ud[udl++] = ' '; /* space between arguments */
- while (udl < 160 && *a)
- {
- int v = utf8decode (&a);
- if (v > 0xFFFF)
- {
- fprintf (stderr, "Invalid character U+%X at %d\n", v, udl);
- return 1;
- }
- ud[udl++] = v;
- }
- }
- }
- if (poptPeekArg (optCon))
- {
- fprintf (stderr, "Unknown argument %s\n", poptGetArg (optCon));
- return 1;
- }
- if (udfile)
- { /* get message from file */
- unsigned char dat[1204],
- *p = dat,
- *e;
- int f,
- n;
- if (*udfile)
- f = open (udfile, O_RDONLY);
- else
- f = fileno (stdin);
- if (f < 0)
- {
- perror (udfile);
- return 1;
- }
- n = read (f, dat, sizeof (dat));
- if (n < 0)
- {
- perror (udfile);
- return 1;
- }
- if (*udfile)
- close (f);
- e = dat + n;
- if (utf8)
- { /* UTF-8 */
- while (p < e && udl < 160 && *p)
- ud[udl++] = utf8decode (&p);
- } else if (ucs1)
- { /* UCS-1 */
- while (p < e && udl < 160)
- ud[udl++] = *p++;
- } else
- { /* UCS-2 */
- while (p + 1 < e && udl < 160)
- {
- ud[udl++] = (*p << 8) + p[1];
- p += 2;
- }
- }
- }
- if (queue)
- {
- char *d = strrchr (queue, '-');
- if (d && d[1])
- subaddress = d[1];
- else
- subaddress = *defaultsubaddress;
- }
-
- if (chdir (spooldir))
- {
- perror (spooldir);
- return 1;
- }
-
- if (oa || da)
- { /* send message */
- char temp[100],
- queuename[100],
- *dir = (mo ? rx ? "sms/morx" : "sms/motx" : rx ? "sms/mtrx" : "sms/mttx");
- FILE *f;
- snprintf (temp, sizeof(temp), "sms/.smsq-%d", getpid ());
- mkdir ("sms", 0777); /* ensure directory exists */
- mkdir (dir, 0777); /* ensure directory exists */
- snprintf (queuename, sizeof(queuename), "%s/%s.%ld-%d", dir, *queue ? queue : "0", (long)time (0), getpid ());
- f = fopen (temp, "w");
- if (!f)
- {
- perror (temp);
- return 1;
- }
- if (oa)
- fprintf (f, "oa=%s\n", oa);
- if (da)
- fprintf (f, "da=%s\n", da);
- if (scts)
- fprintf (f, "scts=%s\n", scts);
- if (pid >= 0)
- fprintf (f, "pid=%d\n", pid);
- if (dcs >= 0)
- fprintf (f, "dcs=%d\n", dcs);
- if (mr >= 0)
- fprintf (f, "mr=%d\n", mr);
- if (srr)
- fprintf (f, "srr=1\n");
- if (rp)
- fprintf (f, "rp=1\n");
- if (udh)
- fprintf (f, "udh#%s\n", udh);
- if (vp > 0)
- fprintf (f, "vp=%d\n", vp);
- if (udl)
- {
- int p;
- for (p = 0; p < udl && ud[p] < 0x100; p++);
- if (p == udl)
- {
- for (p = 0; p < udl && ud[p] < 0x80 && ud[p] >= 0x20; p++);
- if (p == udl)
- { /* use text */
- fprintf (f, "ud=");
- for (p = 0; p < udl; p++)
- fputc (ud[p], f);
- } else
- { /* use one byte hex */
- fprintf (f, "ud#");
- for (p = 0; p < udl; p++)
- fprintf (f, "%02X", ud[p]);
- }
- } else
- { /* use two byte hex */
- fprintf (f, "ud##");
- for (p = 0; p < udl; p++)
- fprintf (f, "%04X", ud[p]);
- }
- fprintf (f, "\n");
- }
- fclose (f);
- if (rename (temp, queuename))
- {
- perror (queuename);
- unlink (temp);
- return 1;
- }
- }
-
- if (!nodial && tx && !process)
- { /* dial to send messages */
- char ret=0,
- try = 3;
- if (nowait)
- try = 1;
- while (try--)
- {
- if (mo)
- ret = txqcheck ("motx", queue, subaddress, motxchannel, motxcallerid, motxwait, motxdelay, motxretries, concurrent);
- else
- ret = txqcheck ("mttx", queue, subaddress, mttxchannel, mttxcallerid, mttxwait, mttxdelay, mttxretries, concurrent);
- if (ret < 2)
- break; /* sent, or queued OK */
- if (try)
- sleep (1);
- }
- if (ret == 2 && !nowait)
- fprintf (stderr, "No call scheduled as already sending\n");
- }
- if (process)
- rxqcheck (mo ? rx ? "morx" : "motx" : rx ? "mtrx" : "mttx", queue, process);
-
- return 0;
-}
diff --git a/1.2-netsec/utils/stereorize.c b/1.2-netsec/utils/stereorize.c
deleted file mode 100644
index 7d72cbdbf..000000000
--- a/1.2-netsec/utils/stereorize.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/****************************************************************************
- *
- * Programs for processing sound files in raw- or WAV-format.
- * -- Merge two mono WAV-files to one stereo WAV-file.
- *
- * Name: stereorize.c
- * Version: 1.1
- * Author: Mark Roberts <mark@manumark.de>
- * Michael Labuschke <michael@labuschke.de>
- *
- ****************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <assert.h>
-#include "frame.h"
-
-static char *Version = "stereorize 1.1, November 5th 2000";
-static char *Usage =
-"Usage: stereorize [options] infile-left infile-right outfile\n\n"
-
-"Example:\n"
-" stereorize left.wav right.wav stereo.wav -h\n\n"
-
-"Creates stereo.wav (with WAV-header, option -h) from data in mono files\n"
-"left.wav and right.wav.\n"
-;
-
-int main( int argcount, char *args[])
-{
- int i, k[2], maxk, stdin_in_use=FALSE;
- short *leftsample, *rightsample, *stereosample;
- FILE *channel[2];
- char *filename[2], *tempname;
-
- version = Version;
- usage = Usage;
-
- channel[0] = NULL;
- channel[1] = NULL;
-
- parseargs( argcount, args, NOFILES | NOCOMPLAIN);
-
- for (i = 0; i < 2; i++)
- {
- filename[i] = parsefilearg( argcount, args);
- if (filename[i] == NULL)
- argerrornum( NULL, ME_NOTENOUGHFILES);
- if (strcmp (filename[i], "-") == 0)
- {
- if (stdin_in_use)
- argerrortxt( filename[i] + 1,
- "Cannot use <stdin> for both input files");
- filename[i] = "<stdin>";
- channel[i] = stdin;
- stdin_in_use = TRUE;
- }
- else
- {
- channel[i] = fopen(filename[i], "rb");
- }
- if (channel[i] == NULL)
- fatalerror( "Error opening input file '%s': %s\n", filename[i],strerror(errno));
- else
- inform("Using file '%s' as input\n", filename[i]);
- }
- for (i = 0; i < 2; i++)
- {
- assert ( channel[i] != NULL);
- readwavheader( channel[i]);
- if (iswav && channels != 1)
- inform("Warning: '%s' is no mono file\n", filename[i]);
- }
-
- outfilename = parsefilearg( argcount, args);
- if (outfilename == NULL) argerrornum( NULL, ME_NOOUTFILE);
- if (strcmp (outfilename, "-") == 0)
- {
- outfilename = "<stdout>";
- out = stdout;
- }
- else
- {
- out = fopen(outfilename, "wb");
- }
- if (out == NULL)
- fatalerror( "Error opening output file '%s': %s\n", outfilename,strerror(errno));
- else
- inform("Using file '%s' as output\n", outfilename);
-
- if ((tempname = parsefilearg( argcount, args)) != NULL)
- argerrornum( tempname, ME_TOOMANYFILES);
-
- checknoargs(argcount, args); /* Check that no arguments are left */
-
- leftsample = malloc( sizeof(*leftsample) * BUFFSIZE);
- rightsample = malloc( sizeof(*leftsample) * BUFFSIZE);
- stereosample = malloc( sizeof(*leftsample) * 2 * BUFFSIZE);
- if (leftsample == NULL || rightsample == NULL || stereosample == NULL)
- fatalperror ("");
-
- channels = 2; /* Output files are stereo */
- if (wavout)
- {
- if ((strcmp(outfilename,"<stdout>")!=0) && (fseek( out, 0, SEEK_SET) != 0))
- fatalerror("Couldn't navigate output file '%s': %s\n",outfilename, strerror(errno));
- makewavheader();
- }
-
- startstopwatch();
- while (TRUE)
- {
- maxk = 0;
- for (i = 0; i < 2; i++)
- {
- k[i] = fread(i==0? leftsample : rightsample,
- sizeof(*leftsample),
- BUFFSIZE,
- channel[i]);
- if (k[i] == -1)
- fatalerror("Error reading file '%s': %s\n", filename[i],strerror(errno));
- if (k[i] > maxk)
- maxk = k[i];
- }
- if (maxk == 0)
- myexit (0);
-
- /*-------------------------------------------------*
- * First the left channel as far as it goes ... *
- *-------------------------------------------------*/
- for (i = 0; i < k[0]; i++)
- stereosample[2 * i] = leftsample[i];
- /*-------------------------------------------------*
- * ... and fill up till the end of this buffer. *
- *-------------------------------------------------*/
- for (; i < maxk; i++)
- stereosample[2 * i] = 0;
-
- /*-------------------------------------------------*
- * Next the right channel as far as it goes ... *
- *-------------------------------------------------*/
- for (i = 0; i < k[1]; i++)
- stereosample[2 * i + 1] = rightsample[i];
- /*-------------------------------------------------*
- * ... and fill up till the end of this buffer. *
- *-------------------------------------------------*/
- for (; i < maxk; i++)
- stereosample[2 * i + 1] = 0;
-
- fwrite(stereosample, sizeof(*leftsample), 2 * maxk, out);
- if (ferror( out) != 0)
- fatalerror("Error writing to file '%s': %s\n",
- outfilename, strerror(errno));
- }
- /* That was an endless loop. This point is never reached. */
-}
diff --git a/1.2-netsec/utils/streamplayer.c b/1.2-netsec/utils/streamplayer.c
deleted file mode 100644
index 24f3142b8..000000000
--- a/1.2-netsec/utils/streamplayer.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Russell Bryant <russell@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
-*
-* streamplayer.c
-*
-* A utility for reading from a stream
-*
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__) || defined(__CYGWIN__)
-#include <netinet/in.h>
-#endif
-#include <sys/time.h>
-
-
-int main(int argc, char *argv[])
-{
- struct sockaddr_in sin;
- struct hostent *hp;
- int s;
- int res;
- char buf[2048];
- fd_set wfds;
- struct timeval tv;
-
- if (argc != 3) {
- fprintf(stderr, "streamplayer -- A utility for reading from a stream.\n");
- fprintf(stderr, "Written for use with Asterisk (http://www.asterisk.org)\n");
- fprintf(stderr, "Copyright (C) 2005 -- Russell Bryant -- Digium, Inc.\n\n");
- fprintf(stderr, "Usage: ./streamplayer <ip> <port>\n");
- exit(1);
- }
-
- hp = gethostbyname(argv[1]);
- if (!hp) {
- fprintf(stderr, "Unable to lookup IP for host '%s'\n", argv[1]);
- exit(1);
- }
-
- memset(&sin, 0, sizeof(sin));
-
- sin.sin_family = AF_INET;
- sin.sin_port = htons(atoi(argv[2]));
- memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
-
- s = socket(AF_INET, SOCK_STREAM, 0);
-
- if (s < 0) {
- fprintf(stderr, "Unable to allocate socket!\n");
- exit(1);
- }
-
- res = connect(s, (struct sockaddr *)&sin, sizeof(sin));
-
- if (res) {
- fprintf(stderr, "Unable to connect to host!\n");
- close(s);
- exit(1);
- }
-
- while (1) {
- res = read(s, buf, sizeof(buf));
-
- if (res < 1)
- break;
-
- memset(&tv, 0, sizeof(tv));
- FD_ZERO(&wfds);
- FD_SET(1, &wfds);
-
- select(2, NULL, &wfds, NULL, &tv);
-
- if (FD_ISSET(1, &wfds))
- write(1, buf, res);
- }
-
- close(s);
- exit(res);
-}